@lvce-editor/test-worker 1.7.0 → 1.8.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,23 @@
1
+ const commands = Object.create(null);
2
+ const registerCommand = (key, fn) => {
3
+ commands[key] = fn;
4
+ };
5
+ const register = commandMap => {
6
+ for (const [key, value] of Object.entries(commandMap)) {
7
+ registerCommand(key, value);
8
+ }
9
+ };
10
+ const getCommand = key => {
11
+ return commands[key];
12
+ };
13
+ const execute$3 = (command, ...args) => {
14
+ const fn = getCommand(command);
15
+ if (!fn) {
16
+ throw new Error(`command not found ${command}`);
17
+ }
18
+ return fn(...args);
19
+ };
20
+
1
21
  const state$3 = {
2
22
  /**
3
23
  * @type {any}
@@ -46,17 +66,17 @@ const number = value => {
46
66
  throw new AssertionError$1('expected value to be of type number');
47
67
  }
48
68
  };
49
- const state$1$1 = {
69
+ const state$1 = {
50
70
  callbacks: Object.create(null)
51
71
  };
52
72
  const set = (id, fn) => {
53
- state$1$1.callbacks[id] = fn;
73
+ state$1.callbacks[id] = fn;
54
74
  };
55
75
  const get = id => {
56
- return state$1$1.callbacks[id];
76
+ return state$1.callbacks[id];
57
77
  };
58
78
  const remove = id => {
59
- delete state$1$1.callbacks[id];
79
+ delete state$1.callbacks[id];
60
80
  };
61
81
  const state$2 = {
62
82
  id: 0
@@ -250,14 +270,16 @@ const unwrapJsonRpcResult = responseMessage => {
250
270
  }
251
271
  throw new JsonRpcError('unexpected response message');
252
272
  };
253
- const create$1 = (message, error) => {
254
- return {
255
- jsonrpc: Two,
256
- id: message.id,
257
- error
258
- };
259
- };
260
273
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
274
+ const getType$2 = prettyError => {
275
+ if (prettyError && prettyError.type) {
276
+ return prettyError.type;
277
+ }
278
+ if (prettyError && prettyError.constructor && prettyError.constructor.name) {
279
+ return prettyError.constructor.name;
280
+ }
281
+ return undefined;
282
+ };
261
283
  const getErrorProperty = (error, prettyError) => {
262
284
  if (error && error.code === E_COMMAND_NOT_FOUND) {
263
285
  return {
@@ -272,11 +294,19 @@ const getErrorProperty = (error, prettyError) => {
272
294
  data: {
273
295
  stack: prettyError.stack,
274
296
  codeFrame: prettyError.codeFrame,
275
- type: prettyError.type,
276
- code: prettyError.code
297
+ type: getType$2(prettyError),
298
+ code: prettyError.code,
299
+ name: prettyError.name
277
300
  }
278
301
  };
279
302
  };
303
+ const create$1 = (message, error) => {
304
+ return {
305
+ jsonrpc: Two,
306
+ id: message.id,
307
+ error
308
+ };
309
+ };
280
310
  const getErrorResponse = (message, error, preparePrettyError, logError) => {
281
311
  const prettyError = preparePrettyError(error);
282
312
  logError(error, prettyError);
@@ -681,7 +711,7 @@ const string = value => {
681
711
 
682
712
  // @ts-nocheck
683
713
 
684
- const state$1 = {
714
+ const state = {
685
715
  /**
686
716
  * @type {any[]}
687
717
  */
@@ -689,20 +719,20 @@ const state$1 = {
689
719
  mockRpcs: Object.create(null)
690
720
  };
691
721
  const addTest = (name, fn) => {
692
- state$1.pendingTests.push({
722
+ state.pendingTests.push({
693
723
  name,
694
724
  fn
695
725
  });
696
726
  };
697
727
  const getTests = () => {
698
- const tests = state$1.pendingTests;
699
- state$1.pendingTests = [];
728
+ const tests = state.pendingTests;
729
+ state.pendingTests = [];
700
730
  return tests;
701
731
  };
702
732
  const setMockRpc = mockRpc => {
703
733
  object(mockRpc);
704
734
  string(mockRpc.name);
705
- state$1.mockRpcs[mockRpc.name] = mockRpc;
735
+ state.mockRpcs[mockRpc.name] = mockRpc;
706
736
  };
707
737
 
708
738
  // @ts-nocheck
@@ -887,13 +917,13 @@ const TestFrameWorkComponentBaseUrl = {
887
917
  getBaseUrl
888
918
  };
889
919
 
890
- const execute$3 = async (id, ...args) => {
920
+ const execute$2 = async (id, ...args) => {
891
921
  return invoke(id, ...args);
892
922
  };
893
923
 
894
924
  const TestFrameWorkComponentCommand = {
895
925
  __proto__: null,
896
- execute: execute$3
926
+ execute: execute$2
897
927
  };
898
928
 
899
929
  const selectItem$1 = async text => {
@@ -1487,7 +1517,7 @@ const preparePrettyError$1 = error => {
1487
1517
  const logError$1 = () => {
1488
1518
  // ignore
1489
1519
  };
1490
- const execute$2 = () => {};
1520
+ const execute$1 = () => {};
1491
1521
  const requiresSocket$1 = () => {
1492
1522
  return false;
1493
1523
  };
@@ -1507,7 +1537,7 @@ const createPortIpc = async webViewId => {
1507
1537
  }
1508
1538
  const handleOtherMessage = async event => {
1509
1539
  // @ts-ignore
1510
- await handleJsonRpcMessage(ipc, event.data, resolve, preparePrettyError$1, execute$2, logError$1, requiresSocket$1);
1540
+ await handleJsonRpcMessage(ipc, event.data, resolve, preparePrettyError$1, execute$1, logError$1, requiresSocket$1);
1511
1541
  };
1512
1542
  port1.onmessage = handleOtherMessage;
1513
1543
  const ipc = {
@@ -1582,7 +1612,7 @@ const TestFrameWorkComponent = {
1582
1612
  Workspace: TestFrameWorkComponentWorkspace
1583
1613
  };
1584
1614
 
1585
- const execute$1 = async href => {
1615
+ const execute = async href => {
1586
1616
  const globals = {
1587
1617
  ...TestFrameWorkComponent,
1588
1618
  ...TestFrameWork
@@ -1617,32 +1647,7 @@ const execute$1 = async href => {
1617
1647
  };
1618
1648
 
1619
1649
  const commandMap = {
1620
- 'Test.execute': execute$1
1621
- };
1622
-
1623
- const state = {
1624
- commands: Object.create(null)
1625
- };
1626
- const registerCommand = (key, fn) => {
1627
- state.commands[key] = fn;
1628
- };
1629
- const registerCommands = commandMap => {
1630
- for (const [key, value] of Object.entries(commandMap)) {
1631
- registerCommand(key, value);
1632
- }
1633
- };
1634
- const getCommand = key => {
1635
- return state.commands[key];
1636
- };
1637
-
1638
- const processName = 'embeds-worker';
1639
-
1640
- const execute = (command, ...args) => {
1641
- const fn = getCommand(command);
1642
- if (!fn) {
1643
- throw new Error(`[${processName}] command not found ${command}`);
1644
- }
1645
- return fn(...args);
1650
+ 'Test.execute': execute
1646
1651
  };
1647
1652
 
1648
1653
  const requiresSocket = () => {
@@ -1655,7 +1660,7 @@ const logError = error => {
1655
1660
  console.error(error);
1656
1661
  };
1657
1662
  const handleMessage = event => {
1658
- return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError, logError, requiresSocket);
1663
+ return handleJsonRpcMessage(event.target, event.data, execute$3, resolve, preparePrettyError, logError, requiresSocket);
1659
1664
  };
1660
1665
 
1661
1666
  const handleIpc = ipc => {
@@ -2091,7 +2096,7 @@ const listen$1 = async ({
2091
2096
  };
2092
2097
 
2093
2098
  const listen = async () => {
2094
- registerCommands(commandMap);
2099
+ register(commandMap);
2095
2100
  const ipc = await listen$1({
2096
2101
  method: Auto()
2097
2102
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/test-worker",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "",
5
5
  "main": "dist/testWorkerMain.js",
6
6
  "type": "module",