@pronto-tools-and-more/schema-process 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +27 -0
- package/src/parts/Callback/Callback.js +1 -0
- package/src/parts/Command/Command.js +9 -0
- package/src/parts/CommandMap/CommandMap.js +5 -0
- package/src/parts/CommandState/CommandState.js +17 -0
- package/src/parts/HandleIpc/HandleIpc.js +10 -0
- package/src/parts/HandleMessage/HandleMessage.js +27 -0
- package/src/parts/IpcChild/IpcChild.js +15 -0
- package/src/parts/IpcChildModule/IpcChildModule.js +25 -0
- package/src/parts/IpcChildType/IpcChildType.js +19 -0
- package/src/parts/JsonRpc/JsonRpc.js +1 -0
- package/src/parts/Listen/Listen.js +8 -0
- package/src/parts/Main/Main.js +8 -0
- package/src/parts/ValidateSchema/ValidateSchema.js +14 -0
- package/src/schemaProcessMain.js +3 -0
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pronto-tools-and-more/schema-process",
|
|
3
|
+
"version": "5.6.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "src/schemaProcessMain.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "node --unhandled-rejections=warn --experimental-vm-modules ./node_modules/jest/bin/jest.js --detectOpenHandles --forceExit",
|
|
9
|
+
"test:watch": "node --unhandled-rejections=warn --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch",
|
|
10
|
+
"type-check": "tsc"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@lvce-editor/ipc": "^10.2.1",
|
|
17
|
+
"@lvce-editor/json-rpc": "^3.0.0",
|
|
18
|
+
"ajv": "^8.17.1"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^22.5.0",
|
|
22
|
+
"jest": "^29.7.0"
|
|
23
|
+
},
|
|
24
|
+
"jest": {
|
|
25
|
+
"injectGlobals": false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolve } from "@lvce-editor/json-rpc";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const state = {
|
|
2
|
+
commands: Object.create(null),
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
const registerCommand = (key, fn) => {
|
|
6
|
+
state.commands[key] = fn;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const registerCommands = (commandMap) => {
|
|
10
|
+
for (const [key, value] of Object.entries(commandMap)) {
|
|
11
|
+
registerCommand(key, value);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const getCommand = (key) => {
|
|
16
|
+
return state.commands[key];
|
|
17
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as HandleMessage from "../HandleMessage/HandleMessage.js";
|
|
2
|
+
|
|
3
|
+
export const handleIpc = (ipc) => {
|
|
4
|
+
if ("addEventListener" in ipc) {
|
|
5
|
+
ipc.addEventListener("message", HandleMessage.handleMessage);
|
|
6
|
+
} else if ("on" in ipc) {
|
|
7
|
+
// deprecated
|
|
8
|
+
ipc.on("message", HandleMessage.handleMessage);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as Callback from "../Callback/Callback.js";
|
|
2
|
+
import * as Command from "../Command/Command.js";
|
|
3
|
+
import * as JsonRpc from "../JsonRpc/JsonRpc.js";
|
|
4
|
+
|
|
5
|
+
const prepare = (error) => {
|
|
6
|
+
return error;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const requiresSocket = (method) => {
|
|
10
|
+
return false;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const logError = (error, prettyError) => {
|
|
14
|
+
console.error(error);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const handleMessage = (event) => {
|
|
18
|
+
return JsonRpc.handleJsonRpcMessage(
|
|
19
|
+
event.target,
|
|
20
|
+
event.data,
|
|
21
|
+
Command.execute,
|
|
22
|
+
Callback.resolve,
|
|
23
|
+
prepare,
|
|
24
|
+
logError,
|
|
25
|
+
requiresSocket,
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as IpcChildModule from "../IpcChildModule/IpcChildModule.js";
|
|
2
|
+
|
|
3
|
+
export const listen = async ({ method, ...params }) => {
|
|
4
|
+
const module = await IpcChildModule.getModule(method);
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const rawIpc = await module.listen(params);
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
if (module.signal) {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
module.signal(rawIpc);
|
|
11
|
+
}
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
const ipc = module.wrap(rawIpc);
|
|
14
|
+
return ipc;
|
|
15
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IpcChildWithElectronMessagePort,
|
|
3
|
+
IpcChildWithElectronUtilityProcess,
|
|
4
|
+
IpcChildWithNodeForkedProcess,
|
|
5
|
+
IpcChildWithNodeWorker,
|
|
6
|
+
IpcChildWithWebSocket,
|
|
7
|
+
} from "@lvce-editor/ipc";
|
|
8
|
+
import * as IpcChildType from "../IpcChildType/IpcChildType.js";
|
|
9
|
+
|
|
10
|
+
export const getModule = (method) => {
|
|
11
|
+
switch (method) {
|
|
12
|
+
case IpcChildType.NodeForkedProcess:
|
|
13
|
+
return IpcChildWithNodeForkedProcess;
|
|
14
|
+
case IpcChildType.NodeWorker:
|
|
15
|
+
return IpcChildWithNodeWorker;
|
|
16
|
+
case IpcChildType.ElectronUtilityProcess:
|
|
17
|
+
return IpcChildWithElectronUtilityProcess;
|
|
18
|
+
case IpcChildType.ElectronMessagePort:
|
|
19
|
+
return IpcChildWithElectronMessagePort;
|
|
20
|
+
case IpcChildType.WebSocket:
|
|
21
|
+
return IpcChildWithWebSocket;
|
|
22
|
+
default:
|
|
23
|
+
throw new Error("unexpected ipc type");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const NodeWorker = 1;
|
|
2
|
+
export const NodeForkedProcess = 2;
|
|
3
|
+
export const ElectronUtilityProcess = 3;
|
|
4
|
+
export const ElectronMessagePort = 4;
|
|
5
|
+
export const WebSocket = 6;
|
|
6
|
+
|
|
7
|
+
export const Auto = () => {
|
|
8
|
+
const { argv } = process;
|
|
9
|
+
if (argv.includes("--ipc-type=node-worker")) {
|
|
10
|
+
return NodeWorker;
|
|
11
|
+
}
|
|
12
|
+
if (argv.includes("--ipc-type=node-forked-process")) {
|
|
13
|
+
return NodeForkedProcess;
|
|
14
|
+
}
|
|
15
|
+
if (argv.includes("--ipc-type=electron-utility-process")) {
|
|
16
|
+
return ElectronUtilityProcess;
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`[shared-process] unknown ipc type`);
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@lvce-editor/json-rpc";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as HandleIpc from "../HandleIpc/HandleIpc.js";
|
|
2
|
+
import * as IpcChild from "../IpcChild/IpcChild.js";
|
|
3
|
+
import * as IpcChildType from "../IpcChildType/IpcChildType.js";
|
|
4
|
+
|
|
5
|
+
export const listen = async () => {
|
|
6
|
+
const ipc = await IpcChild.listen({ method: IpcChildType.Auto() });
|
|
7
|
+
HandleIpc.handleIpc(ipc);
|
|
8
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as CommandMap from "../CommandMap/CommandMap.js";
|
|
2
|
+
import * as CommandState from "../CommandState/CommandState.js";
|
|
3
|
+
import * as Listen from "../Listen/Listen.js";
|
|
4
|
+
|
|
5
|
+
export const main = async () => {
|
|
6
|
+
CommandState.registerCommands(CommandMap.commandMap);
|
|
7
|
+
await Listen.listen();
|
|
8
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as Ajv from "ajv";
|
|
2
|
+
|
|
3
|
+
const ajv = new Ajv.Ajv({
|
|
4
|
+
strict: false,
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
export const validateSchema = (schema, data) => {
|
|
8
|
+
const valid = ajv.validate(schema, data);
|
|
9
|
+
const errors = valid ? [] : ajv.errors;
|
|
10
|
+
return {
|
|
11
|
+
valid,
|
|
12
|
+
errors,
|
|
13
|
+
};
|
|
14
|
+
};
|