@lvce-editor/json-rpc 2.1.0 → 3.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.
Files changed (2) hide show
  1. package/dist/index.js +1 -75
  2. package/package.json +1 -1
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,
@@ -480,17 +408,15 @@ const invoke = async (ipc, method, ...params) => {
480
408
  // TODO deprecated old typings,
481
409
  // always use automatic transferrable detection
482
410
  const invokeAndTransfer = async (ipc, handle, method, ...params) => {
483
- let transfer = handle;
484
411
  if (typeof handle === 'string') {
485
412
  params = [method, ...params];
486
413
  method = handle;
487
- transfer = getTransferrableParams(params);
488
414
  }
489
415
  const {
490
416
  message,
491
417
  promise
492
418
  } = create$2(method, params);
493
- ipc.sendAndTransfer(message, transfer);
419
+ ipc.sendAndTransfer(message);
494
420
  const responseMessage = await promise;
495
421
  const result = unwrapJsonRpcResult(responseMessage);
496
422
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/json-rpc",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "JsonRpc implementation",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",