@lvce-editor/file-search-worker 2.2.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.
@@ -1,4 +1,11 @@
1
1
  const Two = '2.0';
2
+ const create$4 = (method, params) => {
3
+ return {
4
+ jsonrpc: Two,
5
+ method,
6
+ params
7
+ };
8
+ };
2
9
  const state$3 = {
3
10
  callbacks: Object.create(null)
4
11
  };
@@ -217,7 +224,7 @@ const getErrorProperty = (error, prettyError) => {
217
224
  }
218
225
  };
219
226
  };
220
- const create$1 = (message, error) => {
227
+ const create$1$1 = (message, error) => {
221
228
  return {
222
229
  jsonrpc: Two,
223
230
  id: message.id,
@@ -228,9 +235,9 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
228
235
  const prettyError = preparePrettyError(error);
229
236
  logError(error, prettyError);
230
237
  const errorProperty = getErrorProperty(error, prettyError);
231
- return create$1(message, errorProperty);
238
+ return create$1$1(message, errorProperty);
232
239
  };
233
- const create$4 = (message, result) => {
240
+ const create = (message, result) => {
234
241
  return {
235
242
  jsonrpc: Two,
236
243
  id: message.id,
@@ -239,7 +246,7 @@ const create$4 = (message, result) => {
239
246
  };
240
247
  const getSuccessResponse = (message, result) => {
241
248
  const resultProperty = result ?? null;
242
- return create$4(message, resultProperty);
249
+ return create(message, resultProperty);
243
250
  };
244
251
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
245
252
  try {
@@ -320,14 +327,23 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
320
327
  message,
321
328
  promise
322
329
  } = create$2(method, params);
323
- {
330
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
331
+ ipc.sendAndTransfer(message);
332
+ } else {
324
333
  ipc.send(message);
325
334
  }
326
335
  const responseMessage = await promise;
327
336
  return unwrapJsonRpcResult(responseMessage);
328
337
  };
338
+ const send = (transport, method, ...params) => {
339
+ const message = create$4(method, params);
340
+ transport.send(message);
341
+ };
329
342
  const invoke$2 = (ipc, method, ...params) => {
330
- return invokeHelper(ipc, method, params);
343
+ return invokeHelper(ipc, method, params, false);
344
+ };
345
+ const invokeAndTransfer = (ipc, method, ...params) => {
346
+ return invokeHelper(ipc, method, params, true);
331
347
  };
332
348
 
333
349
  const commands = Object.create(null);
@@ -348,6 +364,27 @@ const execute = (command, ...args) => {
348
364
  const getData$1 = event => {
349
365
  return event.data;
350
366
  };
367
+ const attachEvents = that => {
368
+ const handleMessage = (...args) => {
369
+ const data = that.getData(...args);
370
+ that.dispatchEvent(new MessageEvent('message', {
371
+ data
372
+ }));
373
+ };
374
+ that.onMessage(handleMessage);
375
+ const handleClose = event => {
376
+ that.dispatchEvent(new Event('close'));
377
+ };
378
+ that.onClose(handleClose);
379
+ };
380
+ class Ipc extends EventTarget {
381
+ constructor(rawIpc) {
382
+ super();
383
+ this._rawIpc = rawIpc;
384
+ attachEvents(this);
385
+ }
386
+ }
387
+ const readyMessage = 'ready';
351
388
  const walkValue = (value, transferrables, isTransferrable) => {
352
389
  if (!value) {
353
390
  return;
@@ -398,35 +435,14 @@ const getTransferrables = value => {
398
435
  walkValue(value, transferrables, isTransferrable);
399
436
  return transferrables;
400
437
  };
401
- const attachEvents = that => {
402
- const handleMessage = (...args) => {
403
- const data = that.getData(...args);
404
- that.dispatchEvent(new MessageEvent('message', {
405
- data
406
- }));
407
- };
408
- that.onMessage(handleMessage);
409
- const handleClose = event => {
410
- that.dispatchEvent(new Event('close'));
411
- };
412
- that.onClose(handleClose);
413
- };
414
- class Ipc extends EventTarget {
415
- constructor(rawIpc) {
416
- super();
417
- this._rawIpc = rawIpc;
418
- attachEvents(this);
419
- }
420
- }
421
- const readyMessage = 'ready';
422
- const listen$4 = () => {
438
+ const listen$2 = () => {
423
439
  // @ts-ignore
424
440
  if (typeof WorkerGlobalScope === 'undefined') {
425
441
  throw new TypeError('module is not in web worker scope');
426
442
  }
427
443
  return globalThis;
428
444
  };
429
- const signal$3 = global => {
445
+ const signal$2 = global => {
430
446
  global.postMessage(readyMessage);
431
447
  };
432
448
  class IpcChildWithModuleWorker extends Ipc {
@@ -452,7 +468,7 @@ class IpcChildWithModuleWorker extends Ipc {
452
468
  this._rawIpc.addEventListener('message', callback);
453
469
  }
454
470
  }
455
- const wrap$6 = global => {
471
+ const wrap$5 = global => {
456
472
  return new IpcChildWithModuleWorker(global);
457
473
  };
458
474
  const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
@@ -570,10 +586,10 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
570
586
  };
571
587
  const normalizeLine$1 = line => {
572
588
  if (line.startsWith('Error: ')) {
573
- return line.slice(`Error: `.length);
589
+ return line.slice('Error: '.length);
574
590
  }
575
591
  if (line.startsWith('VError: ')) {
576
- return line.slice(`VError: `.length);
592
+ return line.slice('VError: '.length);
577
593
  }
578
594
  return line;
579
595
  };
@@ -671,10 +687,10 @@ const waitForFirstMessage = async port => {
671
687
  // @ts-ignore
672
688
  return event.data;
673
689
  };
674
- const listen$3 = async () => {
675
- const parentIpcRaw = listen$4();
676
- signal$3(parentIpcRaw);
677
- const parentIpc = wrap$6(parentIpcRaw);
690
+ const listen$1$1 = async () => {
691
+ const parentIpcRaw = listen$2();
692
+ signal$2(parentIpcRaw);
693
+ const parentIpc = wrap$5(parentIpcRaw);
678
694
  const firstMessage = await waitForFirstMessage(parentIpc);
679
695
  if (firstMessage.method !== 'initialize') {
680
696
  throw new IpcError('unexpected first message');
@@ -719,19 +735,28 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
719
735
  this._rawIpc.start();
720
736
  }
721
737
  }
722
- const wrap$5 = port => {
738
+ const wrap$4 = port => {
723
739
  return new IpcChildWithModuleWorkerAndMessagePort(port);
724
740
  };
725
741
  const IpcChildWithModuleWorkerAndMessagePort$1 = {
726
742
  __proto__: null,
727
- listen: listen$3,
728
- wrap: wrap$5
743
+ listen: listen$1$1,
744
+ wrap: wrap$4
729
745
  };
730
746
 
731
747
  const createRpc = ipc => {
732
748
  const rpc = {
749
+ /**
750
+ * @deprecated
751
+ */
752
+ send(method, ...params) {
753
+ send(ipc, method, ...params);
754
+ },
733
755
  invoke(method, ...params) {
734
756
  return invoke$2(ipc, method, ...params);
757
+ },
758
+ invokeAndTransfer(method, ...params) {
759
+ return invokeAndTransfer(ipc, method, ...params);
735
760
  }
736
761
  };
737
762
  return rpc;
@@ -759,7 +784,7 @@ const listen$1 = async () => {
759
784
  const ipc = module.wrap(rawIpc);
760
785
  return ipc;
761
786
  };
762
- const create = async ({
787
+ const create$1 = async ({
763
788
  commandMap
764
789
  }) => {
765
790
  // TODO create a commandMap per rpc instance
@@ -771,7 +796,7 @@ const create = async ({
771
796
  };
772
797
  const WebWorkerRpcClient = {
773
798
  __proto__: null,
774
- create
799
+ create: create$1
775
800
  };
776
801
 
777
802
  const assetDir = '';
@@ -1431,7 +1456,11 @@ replaceTraps(oldTraps => ({
1431
1456
  }));
1432
1457
 
1433
1458
  const state$1 = {
1434
- dbVersion: 1};
1459
+ databases: Object.create(null),
1460
+ eventId: 0,
1461
+ dbVersion: 1,
1462
+ cachedDb: undefined
1463
+ };
1435
1464
 
1436
1465
  // TODO high memory usage in idb because of transactionDoneMap
1437
1466
 
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-search-worker",
3
- "version": "2.2.0",
3
+ "version": "3.0.0",
4
4
  "description": "",
5
5
  "main": "dist/fileSearchWorkerMain.js",
6
6
  "type": "module",
7
- "keywords": [],
8
- "author": "",
9
- "license": "MIT"
7
+ "keywords": [
8
+ "text-search"
9
+ ],
10
+ "author": "Lvce Editor",
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/lvce-editor/file-search-worker.git"
15
+ }
10
16
  }