@lvce-editor/json-rpc 2.1.0 → 4.0.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/dist/index.d.ts +5 -6
- package/dist/index.js +2 -83
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -6,12 +6,11 @@ export const invoke: (
|
|
|
6
6
|
...params: any[]
|
|
7
7
|
) => Promise<any>
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const invokeAndTransfer: InvokeAndTransfer
|
|
9
|
+
export const invokeAndTransfer: (
|
|
10
|
+
ipc: any,
|
|
11
|
+
method: string,
|
|
12
|
+
...params: any[]
|
|
13
|
+
) => Promise<any>
|
|
15
14
|
|
|
16
15
|
export const resolve: (id: number, message: any) => void
|
|
17
16
|
|
package/dist/index.js
CHANGED
|
@@ -275,78 +275,6 @@ const unwrapJsonRpcResult = responseMessage => {
|
|
|
275
275
|
throw new JsonRpcError('unexpected response message');
|
|
276
276
|
};
|
|
277
277
|
|
|
278
|
-
const isMessagePort = value => {
|
|
279
|
-
return typeof MessagePort !== 'undefined' && value instanceof MessagePort;
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
const isInstanceOf = (value, constructorName) => {
|
|
283
|
-
return value?.constructor?.name === constructorName;
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
const isMessagePortMain = value => {
|
|
287
|
-
return isInstanceOf(value, 'MessagePortMain');
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
const isOffscreenCanvas = value => {
|
|
291
|
-
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
const isSocket = value => {
|
|
295
|
-
return isInstanceOf(value, 'Socket');
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
299
|
-
|
|
300
|
-
const isTransferrable = value => {
|
|
301
|
-
for (const fn of transferrables) {
|
|
302
|
-
if (fn(value)) {
|
|
303
|
-
return true;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
return false;
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
const walkValue = (value, transferrables) => {
|
|
310
|
-
if (!value) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
if (isTransferrable(value)) {
|
|
314
|
-
transferrables.push(value);
|
|
315
|
-
}
|
|
316
|
-
if (Array.isArray(value)) {
|
|
317
|
-
for (const item of value) {
|
|
318
|
-
walkValue(item, transferrables);
|
|
319
|
-
}
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
if (typeof value === 'object') {
|
|
323
|
-
for (const property of Object.values(value)) {
|
|
324
|
-
walkValue(property, transferrables);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
const getTransferrables = value => {
|
|
330
|
-
const transferrables = [];
|
|
331
|
-
walkValue(value, transferrables);
|
|
332
|
-
return transferrables;
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
const isSingleTransferrable = value => {
|
|
336
|
-
return isSocket(value);
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
const getTransferrableParams = value => {
|
|
340
|
-
const transferrables = getTransferrables(value);
|
|
341
|
-
if (transferrables.length === 0) {
|
|
342
|
-
return undefined;
|
|
343
|
-
}
|
|
344
|
-
if (isSingleTransferrable(transferrables[0])) {
|
|
345
|
-
return transferrables[0];
|
|
346
|
-
}
|
|
347
|
-
return transferrables;
|
|
348
|
-
};
|
|
349
|
-
|
|
350
278
|
const create$1 = (message, error) => {
|
|
351
279
|
return {
|
|
352
280
|
jsonrpc: Two,
|
|
@@ -476,21 +404,12 @@ const invoke = async (ipc, method, ...params) => {
|
|
|
476
404
|
const result = unwrapJsonRpcResult(responseMessage);
|
|
477
405
|
return result;
|
|
478
406
|
};
|
|
479
|
-
|
|
480
|
-
// TODO deprecated old typings,
|
|
481
|
-
// always use automatic transferrable detection
|
|
482
|
-
const invokeAndTransfer = async (ipc, handle, method, ...params) => {
|
|
483
|
-
let transfer = handle;
|
|
484
|
-
if (typeof handle === 'string') {
|
|
485
|
-
params = [method, ...params];
|
|
486
|
-
method = handle;
|
|
487
|
-
transfer = getTransferrableParams(params);
|
|
488
|
-
}
|
|
407
|
+
const invokeAndTransfer = async (ipc, method, ...params) => {
|
|
489
408
|
const {
|
|
490
409
|
message,
|
|
491
410
|
promise
|
|
492
411
|
} = create$2(method, params);
|
|
493
|
-
ipc.sendAndTransfer(message
|
|
412
|
+
ipc.sendAndTransfer(message);
|
|
494
413
|
const responseMessage = await promise;
|
|
495
414
|
const result = unwrapJsonRpcResult(responseMessage);
|
|
496
415
|
return result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/json-rpc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "JsonRpc implementation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
"author": "Lvce Editor",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@lvce-editor/assert": "^1.
|
|
14
|
+
"@lvce-editor/assert": "^1.3.0"
|
|
15
15
|
}
|
|
16
16
|
}
|