init project

This commit is contained in:
root
2026-07-31 13:12:54 -04:00
parent 0da92d5e02
commit f3863f760c
7215 changed files with 1860260 additions and 1 deletions
+50
View File
@@ -0,0 +1,50 @@
import {serialize} from 'node:v8';
import {sendMessage} from './send.js';
// Validate the `ipcInput` option
export const validateIpcInputOption = ({ipcInput, ipc, serialization}) => {
if (ipcInput === undefined) {
return;
}
if (!ipc) {
throw new Error('The `ipcInput` option cannot be set unless the `ipc` option is `true`.');
}
validateIpcInput[serialization](ipcInput);
};
const validateAdvancedInput = ipcInput => {
try {
serialize(ipcInput);
} catch (error) {
throw new Error('The `ipcInput` option is not serializable with a structured clone.', {cause: error});
}
};
const validateJsonInput = ipcInput => {
try {
JSON.stringify(ipcInput);
} catch (error) {
throw new Error('The `ipcInput` option is not serializable with JSON.', {cause: error});
}
};
const validateIpcInput = {
advanced: validateAdvancedInput,
json: validateJsonInput,
};
// When the `ipcInput` option is set, it is sent as an initial IPC message to the subprocess
export const sendIpcInput = async (subprocess, ipcInput, ipc) => {
if (ipcInput === undefined) {
return;
}
await sendMessage({
anyProcess: subprocess,
channel: subprocess.channel,
isSubprocess: false,
ipc,
}, ipcInput);
};