@lvce-editor/extension-management-worker 3.1.0 → 3.2.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.
|
@@ -1,3 +1,58 @@
|
|
|
1
|
+
class AssertionError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = 'AssertionError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
const Object$1 = 1;
|
|
8
|
+
const Number = 2;
|
|
9
|
+
const Array$1 = 3;
|
|
10
|
+
const String = 4;
|
|
11
|
+
const Boolean$1 = 5;
|
|
12
|
+
const Function = 6;
|
|
13
|
+
const Null = 7;
|
|
14
|
+
const Unknown = 8;
|
|
15
|
+
const getType = value => {
|
|
16
|
+
switch (typeof value) {
|
|
17
|
+
case 'number':
|
|
18
|
+
return Number;
|
|
19
|
+
case 'function':
|
|
20
|
+
return Function;
|
|
21
|
+
case 'string':
|
|
22
|
+
return String;
|
|
23
|
+
case 'object':
|
|
24
|
+
if (value === null) {
|
|
25
|
+
return Null;
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(value)) {
|
|
28
|
+
return Array$1;
|
|
29
|
+
}
|
|
30
|
+
return Object$1;
|
|
31
|
+
case 'boolean':
|
|
32
|
+
return Boolean$1;
|
|
33
|
+
default:
|
|
34
|
+
return Unknown;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const object = value => {
|
|
38
|
+
const type = getType(value);
|
|
39
|
+
if (type !== Object$1) {
|
|
40
|
+
throw new AssertionError('expected value to be of type object');
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const number = value => {
|
|
44
|
+
const type = getType(value);
|
|
45
|
+
if (type !== Number) {
|
|
46
|
+
throw new AssertionError('expected value to be of type number');
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const string = value => {
|
|
50
|
+
const type = getType(value);
|
|
51
|
+
if (type !== String) {
|
|
52
|
+
throw new AssertionError('expected value to be of type string');
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
1
56
|
const normalizeLine = line => {
|
|
2
57
|
if (line.startsWith('Error: ')) {
|
|
3
58
|
return line.slice('Error: '.length);
|
|
@@ -54,61 +109,6 @@ class VError extends Error {
|
|
|
54
109
|
}
|
|
55
110
|
}
|
|
56
111
|
|
|
57
|
-
class AssertionError extends Error {
|
|
58
|
-
constructor(message) {
|
|
59
|
-
super(message);
|
|
60
|
-
this.name = 'AssertionError';
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const Object$1 = 1;
|
|
64
|
-
const Number = 2;
|
|
65
|
-
const Array$1 = 3;
|
|
66
|
-
const String = 4;
|
|
67
|
-
const Boolean$1 = 5;
|
|
68
|
-
const Function = 6;
|
|
69
|
-
const Null = 7;
|
|
70
|
-
const Unknown = 8;
|
|
71
|
-
const getType = value => {
|
|
72
|
-
switch (typeof value) {
|
|
73
|
-
case 'number':
|
|
74
|
-
return Number;
|
|
75
|
-
case 'function':
|
|
76
|
-
return Function;
|
|
77
|
-
case 'string':
|
|
78
|
-
return String;
|
|
79
|
-
case 'object':
|
|
80
|
-
if (value === null) {
|
|
81
|
-
return Null;
|
|
82
|
-
}
|
|
83
|
-
if (Array.isArray(value)) {
|
|
84
|
-
return Array$1;
|
|
85
|
-
}
|
|
86
|
-
return Object$1;
|
|
87
|
-
case 'boolean':
|
|
88
|
-
return Boolean$1;
|
|
89
|
-
default:
|
|
90
|
-
return Unknown;
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const object = value => {
|
|
94
|
-
const type = getType(value);
|
|
95
|
-
if (type !== Object$1) {
|
|
96
|
-
throw new AssertionError('expected value to be of type object');
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const number = value => {
|
|
100
|
-
const type = getType(value);
|
|
101
|
-
if (type !== Number) {
|
|
102
|
-
throw new AssertionError('expected value to be of type number');
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
const string = value => {
|
|
106
|
-
const type = getType(value);
|
|
107
|
-
if (type !== String) {
|
|
108
|
-
throw new AssertionError('expected value to be of type string');
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
112
|
const isMessagePort = value => {
|
|
113
113
|
return value && value instanceof MessagePort;
|
|
114
114
|
};
|
|
@@ -540,7 +540,7 @@ const waitForWebSocketToBeOpen = webSocket => {
|
|
|
540
540
|
open: Open
|
|
541
541
|
});
|
|
542
542
|
};
|
|
543
|
-
const create$
|
|
543
|
+
const create$d = async ({
|
|
544
544
|
webSocket
|
|
545
545
|
}) => {
|
|
546
546
|
const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
|
|
@@ -577,7 +577,7 @@ const wrap = webSocket => {
|
|
|
577
577
|
};
|
|
578
578
|
const IpcParentWithWebSocket$1 = {
|
|
579
579
|
__proto__: null,
|
|
580
|
-
create: create$
|
|
580
|
+
create: create$d,
|
|
581
581
|
wrap
|
|
582
582
|
};
|
|
583
583
|
|
|
@@ -816,7 +816,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
816
816
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
817
817
|
return create$1$1(id, errorProperty);
|
|
818
818
|
};
|
|
819
|
-
const create$
|
|
819
|
+
const create$c = (message, result) => {
|
|
820
820
|
return {
|
|
821
821
|
id: message.id,
|
|
822
822
|
jsonrpc: Two$1,
|
|
@@ -825,7 +825,7 @@ const create$b = (message, result) => {
|
|
|
825
825
|
};
|
|
826
826
|
const getSuccessResponse = (message, result) => {
|
|
827
827
|
const resultProperty = result ?? null;
|
|
828
|
-
return create$
|
|
828
|
+
return create$c(message, resultProperty);
|
|
829
829
|
};
|
|
830
830
|
const getErrorResponseSimple = (id, error) => {
|
|
831
831
|
return {
|
|
@@ -919,7 +919,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
919
919
|
|
|
920
920
|
const Two = '2.0';
|
|
921
921
|
|
|
922
|
-
const create$
|
|
922
|
+
const create$b = (method, params) => {
|
|
923
923
|
return {
|
|
924
924
|
jsonrpc: Two,
|
|
925
925
|
method,
|
|
@@ -927,7 +927,7 @@ const create$a = (method, params) => {
|
|
|
927
927
|
};
|
|
928
928
|
};
|
|
929
929
|
|
|
930
|
-
const create$
|
|
930
|
+
const create$a = (id, method, params) => {
|
|
931
931
|
const message = {
|
|
932
932
|
id,
|
|
933
933
|
jsonrpc: Two,
|
|
@@ -938,12 +938,12 @@ const create$9 = (id, method, params) => {
|
|
|
938
938
|
};
|
|
939
939
|
|
|
940
940
|
let id$1 = 0;
|
|
941
|
-
const create$
|
|
941
|
+
const create$9 = () => {
|
|
942
942
|
return ++id$1;
|
|
943
943
|
};
|
|
944
944
|
|
|
945
945
|
const registerPromise = map => {
|
|
946
|
-
const id = create$
|
|
946
|
+
const id = create$9();
|
|
947
947
|
const {
|
|
948
948
|
promise,
|
|
949
949
|
resolve
|
|
@@ -960,7 +960,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
960
960
|
id,
|
|
961
961
|
promise
|
|
962
962
|
} = registerPromise(callbacks);
|
|
963
|
-
const message = create$
|
|
963
|
+
const message = create$a(id, method, params);
|
|
964
964
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
965
965
|
ipc.sendAndTransfer(message);
|
|
966
966
|
} else {
|
|
@@ -996,7 +996,7 @@ const createRpc = ipc => {
|
|
|
996
996
|
* @deprecated
|
|
997
997
|
*/
|
|
998
998
|
send(method, ...params) {
|
|
999
|
-
const message = create$
|
|
999
|
+
const message = create$b(method, params);
|
|
1000
1000
|
ipc.send(message);
|
|
1001
1001
|
}
|
|
1002
1002
|
};
|
|
@@ -1036,7 +1036,7 @@ const listen$1 = async (module, options) => {
|
|
|
1036
1036
|
return ipc;
|
|
1037
1037
|
};
|
|
1038
1038
|
|
|
1039
|
-
const create$
|
|
1039
|
+
const create$8 = async ({
|
|
1040
1040
|
commandMap,
|
|
1041
1041
|
isMessagePortOpen = true,
|
|
1042
1042
|
messagePort
|
|
@@ -1054,7 +1054,7 @@ const create$7 = async ({
|
|
|
1054
1054
|
return rpc;
|
|
1055
1055
|
};
|
|
1056
1056
|
|
|
1057
|
-
const create$
|
|
1057
|
+
const create$7 = async ({
|
|
1058
1058
|
commandMap,
|
|
1059
1059
|
isMessagePortOpen,
|
|
1060
1060
|
send
|
|
@@ -1064,13 +1064,55 @@ const create$6 = async ({
|
|
|
1064
1064
|
port2
|
|
1065
1065
|
} = new MessageChannel();
|
|
1066
1066
|
await send(port1);
|
|
1067
|
-
return create$
|
|
1067
|
+
return create$8({
|
|
1068
1068
|
commandMap,
|
|
1069
1069
|
isMessagePortOpen,
|
|
1070
1070
|
messagePort: port2
|
|
1071
1071
|
});
|
|
1072
1072
|
};
|
|
1073
1073
|
|
|
1074
|
+
const createSharedLazyRpc = factory => {
|
|
1075
|
+
let rpcPromise;
|
|
1076
|
+
const getOrCreate = () => {
|
|
1077
|
+
if (!rpcPromise) {
|
|
1078
|
+
rpcPromise = factory();
|
|
1079
|
+
}
|
|
1080
|
+
return rpcPromise;
|
|
1081
|
+
};
|
|
1082
|
+
return {
|
|
1083
|
+
async dispose() {
|
|
1084
|
+
const rpc = await getOrCreate();
|
|
1085
|
+
await rpc.dispose();
|
|
1086
|
+
},
|
|
1087
|
+
async invoke(method, ...params) {
|
|
1088
|
+
const rpc = await getOrCreate();
|
|
1089
|
+
return rpc.invoke(method, ...params);
|
|
1090
|
+
},
|
|
1091
|
+
async invokeAndTransfer(method, ...params) {
|
|
1092
|
+
const rpc = await getOrCreate();
|
|
1093
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1094
|
+
},
|
|
1095
|
+
async send(method, ...params) {
|
|
1096
|
+
const rpc = await getOrCreate();
|
|
1097
|
+
rpc.send(method, ...params);
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
const create$6 = async ({
|
|
1103
|
+
commandMap,
|
|
1104
|
+
isMessagePortOpen,
|
|
1105
|
+
send
|
|
1106
|
+
}) => {
|
|
1107
|
+
return createSharedLazyRpc(() => {
|
|
1108
|
+
return create$7({
|
|
1109
|
+
commandMap,
|
|
1110
|
+
isMessagePortOpen,
|
|
1111
|
+
send
|
|
1112
|
+
});
|
|
1113
|
+
});
|
|
1114
|
+
};
|
|
1115
|
+
|
|
1074
1116
|
const Https = 'https:';
|
|
1075
1117
|
const Ws = 'ws:';
|
|
1076
1118
|
const Wss = 'wss:';
|
|
@@ -2125,7 +2167,7 @@ const getRuntimeStatus = extensionId => {
|
|
|
2125
2167
|
const commandMapRef = {};
|
|
2126
2168
|
|
|
2127
2169
|
const handleMessagePort = async port => {
|
|
2128
|
-
await create$
|
|
2170
|
+
await create$8({
|
|
2129
2171
|
commandMap: commandMapRef,
|
|
2130
2172
|
messagePort: port
|
|
2131
2173
|
});
|
|
@@ -2151,23 +2193,29 @@ const initializeFileSystemWorker = async () => {
|
|
|
2151
2193
|
set$5(rpc);
|
|
2152
2194
|
};
|
|
2153
2195
|
|
|
2196
|
+
const getRpcRemote = async () => {
|
|
2197
|
+
const rpc = await create$4({
|
|
2198
|
+
commandMap: commandMapRef,
|
|
2199
|
+
type: 'shared-process'
|
|
2200
|
+
});
|
|
2201
|
+
return rpc;
|
|
2202
|
+
};
|
|
2203
|
+
const getRpcElectron = async () => {
|
|
2204
|
+
const rpc = create$7({
|
|
2205
|
+
commandMap: commandMapRef,
|
|
2206
|
+
async send(port) {
|
|
2207
|
+
await sendMessagePortToSharedProcess(port);
|
|
2208
|
+
}
|
|
2209
|
+
});
|
|
2210
|
+
return rpc;
|
|
2211
|
+
};
|
|
2154
2212
|
const getRpc = async platform => {
|
|
2155
2213
|
// TODO create connection to shared process
|
|
2156
2214
|
if (platform === Remote) {
|
|
2157
|
-
|
|
2158
|
-
commandMap: commandMapRef,
|
|
2159
|
-
type: 'shared-process'
|
|
2160
|
-
});
|
|
2161
|
-
return rpc;
|
|
2215
|
+
return getRpcRemote();
|
|
2162
2216
|
}
|
|
2163
2217
|
if (platform === Electron) {
|
|
2164
|
-
|
|
2165
|
-
commandMap: commandMapRef,
|
|
2166
|
-
async send(port) {
|
|
2167
|
-
await sendMessagePortToSharedProcess(port);
|
|
2168
|
-
}
|
|
2169
|
-
});
|
|
2170
|
-
return rpc;
|
|
2218
|
+
return getRpcElectron();
|
|
2171
2219
|
}
|
|
2172
2220
|
return undefined;
|
|
2173
2221
|
};
|
|
@@ -2275,14 +2323,18 @@ const commandMap = {
|
|
|
2275
2323
|
'Extensions.uninstall': uninstallExtension
|
|
2276
2324
|
};
|
|
2277
2325
|
|
|
2278
|
-
const
|
|
2279
|
-
Object.assign(commandMapRef, commandMap);
|
|
2326
|
+
const initializeRendererWorker = async () => {
|
|
2280
2327
|
const rpc = await create$2({
|
|
2281
2328
|
commandMap: commandMap
|
|
2282
2329
|
});
|
|
2283
2330
|
set$4(rpc);
|
|
2284
2331
|
};
|
|
2285
2332
|
|
|
2333
|
+
const listen = async () => {
|
|
2334
|
+
Object.assign(commandMapRef, commandMap);
|
|
2335
|
+
await initializeRendererWorker();
|
|
2336
|
+
};
|
|
2337
|
+
|
|
2286
2338
|
const main = async () => {
|
|
2287
2339
|
await listen();
|
|
2288
2340
|
};
|