@lvce-editor/extension-host-worker 1.11.0 → 1.13.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.
@@ -30,13 +30,13 @@ const getJson = async url => {
30
30
  throw new DepecratedError(`vscode.getJson is deprecated, use createNodeRpc instead`);
31
31
  };
32
32
 
33
- let AssertionError$1 = class AssertionError extends Error {
33
+ class AssertionError extends Error {
34
34
  constructor(message) {
35
35
  super(message);
36
36
  this.name = 'AssertionError';
37
37
  }
38
- };
39
- const getType$2 = value => {
38
+ }
39
+ const getType$1 = value => {
40
40
  switch (typeof value) {
41
41
  case 'number':
42
42
  return 'number';
@@ -59,33 +59,33 @@ const getType$2 = value => {
59
59
  }
60
60
  };
61
61
  const object = value => {
62
- const type = getType$2(value);
62
+ const type = getType$1(value);
63
63
  if (type !== 'object') {
64
- throw new AssertionError$1('expected value to be of type object');
64
+ throw new AssertionError('expected value to be of type object');
65
65
  }
66
66
  };
67
- const number$1 = value => {
68
- const type = getType$2(value);
67
+ const number = value => {
68
+ const type = getType$1(value);
69
69
  if (type !== 'number') {
70
- throw new AssertionError$1('expected value to be of type number');
70
+ throw new AssertionError('expected value to be of type number');
71
71
  }
72
72
  };
73
73
  const array = value => {
74
- const type = getType$2(value);
74
+ const type = getType$1(value);
75
75
  if (type !== 'array') {
76
- throw new AssertionError$1('expected value to be of type array');
76
+ throw new AssertionError('expected value to be of type array');
77
77
  }
78
78
  };
79
79
  const string = value => {
80
- const type = getType$2(value);
80
+ const type = getType$1(value);
81
81
  if (type !== 'string') {
82
- throw new AssertionError$1('expected value to be of type string');
82
+ throw new AssertionError('expected value to be of type string');
83
83
  }
84
84
  };
85
85
  const fn = value => {
86
- const type = getType$2(value);
86
+ const type = getType$1(value);
87
87
  if (type !== 'function') {
88
- throw new AssertionError$1('expected value to be of type function');
88
+ throw new AssertionError('expected value to be of type function');
89
89
  }
90
90
  };
91
91
 
@@ -287,7 +287,7 @@ const getSyntheticChanges = (textDocument, changes) => {
287
287
  return syntheticChanges;
288
288
  };
289
289
  const syncIncremental = (textDocumentId, changes) => {
290
- number$1(textDocumentId);
290
+ number(textDocumentId);
291
291
  array(changes);
292
292
  const textDocument = getDocument(textDocumentId);
293
293
  if (!textDocument) {
@@ -332,10 +332,10 @@ class NoProviderFoundError extends Error {
332
332
 
333
333
  const normalizeLine$1 = line => {
334
334
  if (line.startsWith('Error: ')) {
335
- return line.slice(`Error: `.length);
335
+ return line.slice('Error: '.length);
336
336
  }
337
337
  if (line.startsWith('VError: ')) {
338
- return line.slice(`VError: `.length);
338
+ return line.slice('VError: '.length);
339
339
  }
340
340
  return line;
341
341
  };
@@ -386,7 +386,7 @@ let VError$1 = class VError extends Error {
386
386
  }
387
387
  };
388
388
 
389
- const getType$1 = value => {
389
+ const getType = value => {
390
390
  switch (typeof value) {
391
391
  case 'number':
392
392
  return 'number';
@@ -417,7 +417,7 @@ const validateResultObject = (result, resultShape) => {
417
417
  for (const [key, value] of Object.entries(resultShape.properties)) {
418
418
  // @ts-ignore
419
419
  const expectedType = value.type;
420
- const actualType = getType$1(result[key]);
420
+ const actualType = getType(result[key]);
421
421
  if (expectedType !== actualType) {
422
422
  return `item.${key} must be of type ${expectedType}`;
423
423
  }
@@ -426,7 +426,7 @@ const validateResultObject = (result, resultShape) => {
426
426
  };
427
427
  const validateResultArray = (result, resultShape) => {
428
428
  for (const item of result) {
429
- const actualType = getType$1(item);
429
+ const actualType = getType(item);
430
430
  const expectedType = resultShape.items.type;
431
431
  if (actualType !== expectedType) {
432
432
  return `expected result to be of type ${expectedType} but was of type ${actualType}`;
@@ -447,7 +447,7 @@ const getPreviewString = item => {
447
447
  return `"${item}"`;
448
448
  };
449
449
  const getPreview = item => {
450
- const type = getType$1(item);
450
+ const type = getType(item);
451
451
  switch (type) {
452
452
  case 'object':
453
453
  return getPreviewObject();
@@ -460,7 +460,7 @@ const getPreview = item => {
460
460
  }
461
461
  };
462
462
  const validate = (item, schema) => {
463
- const actualType = getType$1(item);
463
+ const actualType = getType(item);
464
464
  const expectedType = schema.type;
465
465
  if (actualType !== expectedType) {
466
466
  if (schema.allowUndefined && (item === undefined || item === null)) {
@@ -684,7 +684,7 @@ const getCommandDisplay = command => {
684
684
  }
685
685
  return '';
686
686
  };
687
- const registerCommand$1 = command => {
687
+ const registerCommand = command => {
688
688
  try {
689
689
  if (!command) {
690
690
  if (command === null) {
@@ -766,57 +766,19 @@ const create$4$1 = (method, params) => {
766
766
  params
767
767
  };
768
768
  };
769
- class AssertionError extends Error {
770
- constructor(message) {
771
- super(message);
772
- this.name = 'AssertionError';
773
- }
774
- }
775
- const getType = value => {
776
- switch (typeof value) {
777
- case 'number':
778
- return 'number';
779
- case 'function':
780
- return 'function';
781
- case 'string':
782
- return 'string';
783
- case 'object':
784
- if (value === null) {
785
- return 'null';
786
- }
787
- if (Array.isArray(value)) {
788
- return 'array';
789
- }
790
- return 'object';
791
- case 'boolean':
792
- return 'boolean';
793
- default:
794
- return 'unknown';
795
- }
796
- };
797
- const number = value => {
798
- const type = getType(value);
799
- if (type !== 'number') {
800
- throw new AssertionError('expected value to be of type number');
801
- }
802
- };
803
- const state$1$1 = {
804
- callbacks: Object.create(null)
805
- };
769
+ const callbacks = Object.create(null);
806
770
  const set$4 = (id, fn) => {
807
- state$1$1.callbacks[id] = fn;
771
+ callbacks[id] = fn;
808
772
  };
809
773
  const get$4 = id => {
810
- return state$1$1.callbacks[id];
774
+ return callbacks[id];
811
775
  };
812
776
  const remove = id => {
813
- delete state$1$1.callbacks[id];
814
- };
815
- const state$6 = {
816
- id: 0
777
+ delete callbacks[id];
817
778
  };
779
+ let id = 0;
818
780
  const create$3$1 = () => {
819
- return ++state$6.id;
781
+ return ++id;
820
782
  };
821
783
  const warn = (...args) => {
822
784
  console.warn(...args);
@@ -833,15 +795,14 @@ const registerPromise = () => {
833
795
  promise
834
796
  };
835
797
  };
836
- const resolve = (id, args) => {
837
- number(id);
798
+ const resolve = (id, response) => {
838
799
  const fn = get$4(id);
839
800
  if (!fn) {
840
- console.log(args);
801
+ console.log(response);
841
802
  warn(`callback ${id} may already be disposed`);
842
803
  return;
843
804
  }
844
- fn(args);
805
+ fn(response);
845
806
  remove(id);
846
807
  };
847
808
  const create$2$1 = (method, params) => {
@@ -1063,32 +1024,42 @@ const defaultRequiresSocket = () => {
1063
1024
  return false;
1064
1025
  };
1065
1026
  const defaultResolve = resolve;
1066
- const handleJsonRpcMessage = async (...args) => {
1067
- let message;
1068
- let ipc;
1069
- let execute;
1070
- let preparePrettyError;
1071
- let logError;
1072
- let resolve;
1073
- let requiresSocket;
1027
+
1028
+ // TODO maybe remove this in v6 or v7, only accept options object to simplify the code
1029
+ const normalizeParams = args => {
1074
1030
  if (args.length === 1) {
1075
- const arg = args[0];
1076
- message = arg.message;
1077
- ipc = arg.ipc;
1078
- execute = arg.execute;
1079
- preparePrettyError = arg.preparePrettyError || defaultPreparePrettyError;
1080
- logError = arg.logError || defaultLogError;
1081
- requiresSocket = arg.requiresSocket || defaultRequiresSocket;
1082
- resolve = arg.resolve || defaultResolve;
1083
- } else {
1084
- ipc = args[0];
1085
- message = args[1];
1086
- execute = args[2];
1087
- resolve = args[3];
1088
- preparePrettyError = args[4];
1089
- logError = args[5];
1090
- requiresSocket = args[6];
1031
+ const options = args[0];
1032
+ return {
1033
+ ipc: options.ipc,
1034
+ message: options.message,
1035
+ execute: options.execute,
1036
+ resolve: options.resolve || defaultResolve,
1037
+ preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
1038
+ logError: options.logError || defaultLogError,
1039
+ requiresSocket: options.requiresSocket || defaultRequiresSocket
1040
+ };
1091
1041
  }
1042
+ return {
1043
+ ipc: args[0],
1044
+ message: args[1],
1045
+ execute: args[2],
1046
+ resolve: args[3],
1047
+ preparePrettyError: args[4],
1048
+ logError: args[5],
1049
+ requiresSocket: args[6]
1050
+ };
1051
+ };
1052
+ const handleJsonRpcMessage = async (...args) => {
1053
+ const options = normalizeParams(args);
1054
+ const {
1055
+ message,
1056
+ ipc,
1057
+ execute,
1058
+ resolve,
1059
+ preparePrettyError,
1060
+ logError,
1061
+ requiresSocket
1062
+ } = options;
1092
1063
  if ('id' in message) {
1093
1064
  if ('method' in message) {
1094
1065
  const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
@@ -1109,39 +1080,33 @@ const handleJsonRpcMessage = async (...args) => {
1109
1080
  }
1110
1081
  throw new JsonRpcError('unexpected message');
1111
1082
  };
1112
- const send$1 = (transport, method, ...params) => {
1113
- const message = create$4$1(method, params);
1114
- transport.send(message);
1115
- };
1116
- const invoke$1 = async (ipc, method, ...params) => {
1083
+ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
1117
1084
  const {
1118
1085
  message,
1119
1086
  promise
1120
1087
  } = create$2$1(method, params);
1121
- ipc.send(message);
1088
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
1089
+ ipc.sendAndTransfer(message);
1090
+ } else {
1091
+ ipc.send(message);
1092
+ }
1122
1093
  const responseMessage = await promise;
1123
- const result = unwrapJsonRpcResult(responseMessage);
1124
- return result;
1094
+ return unwrapJsonRpcResult(responseMessage);
1125
1095
  };
1126
- const invokeAndTransfer$1 = async (ipc, method, ...params) => {
1127
- const {
1128
- message,
1129
- promise
1130
- } = create$2$1(method, params);
1131
- ipc.sendAndTransfer(message);
1132
- const responseMessage = await promise;
1133
- const result = unwrapJsonRpcResult(responseMessage);
1134
- return result;
1096
+ const send$1 = (transport, method, ...params) => {
1097
+ const message = create$4$1(method, params);
1098
+ transport.send(message);
1099
+ };
1100
+ const invoke$1 = (ipc, method, ...params) => {
1101
+ return invokeHelper(ipc, method, params, false);
1102
+ };
1103
+ const invokeAndTransfer$1 = (ipc, method, ...params) => {
1104
+ return invokeHelper(ipc, method, params, true);
1135
1105
  };
1136
1106
 
1137
1107
  const commands = Object.create(null);
1138
- const registerCommand = (key, fn) => {
1139
- commands[key] = fn;
1140
- };
1141
1108
  const register$1 = commandMap => {
1142
- for (const [key, value] of Object.entries(commandMap)) {
1143
- registerCommand(key, value);
1144
- }
1109
+ Object.assign(commands, commandMap);
1145
1110
  };
1146
1111
  const getCommand = key => {
1147
1112
  return commands[key];
@@ -1171,17 +1136,17 @@ const handleIpc = ipc => {
1171
1136
  ipc.addEventListener('message', handleMessage);
1172
1137
  };
1173
1138
 
1174
- const state$5 = {
1139
+ const state$6 = {
1175
1140
  /**
1176
1141
  * @type {any}
1177
1142
  */
1178
1143
  ipc: undefined
1179
1144
  };
1180
1145
  const get$3 = () => {
1181
- return state$5.ipc;
1146
+ return state$6.ipc;
1182
1147
  };
1183
1148
  const set$3 = ipc => {
1184
- state$5.ipc = ipc;
1149
+ state$6.ipc = ipc;
1185
1150
  };
1186
1151
 
1187
1152
  const send = (method, ...params) => {
@@ -1196,16 +1161,16 @@ const invokeAndTransfer = (method, ...params) => {
1196
1161
  const ipc = get$3();
1197
1162
  return invokeAndTransfer$1(ipc, method, ...params);
1198
1163
  };
1199
- const listen$2 = ipc => {
1164
+ const listen$4 = ipc => {
1200
1165
  handleIpc(ipc);
1201
1166
  set$3(ipc);
1202
1167
  };
1203
1168
 
1204
- const state$4 = {
1169
+ const state$5 = {
1205
1170
  debugProviderMap: Object.create(null)
1206
1171
  };
1207
1172
  const getDebugProvider = id => {
1208
- const provider = state$4.debugProviderMap[id];
1173
+ const provider = state$5.debugProviderMap[id];
1209
1174
  if (!provider) {
1210
1175
  // @ts-ignore
1211
1176
  throw new VError$1(`no debug provider "${id}" found`);
@@ -1216,7 +1181,7 @@ const registerDebugProvider = debugProvider => {
1216
1181
  if (!debugProvider.id) {
1217
1182
  throw new Error('Failed to register debug system provider: missing id');
1218
1183
  }
1219
- state$4.debugProviderMap[debugProvider.id] = debugProvider;
1184
+ state$5.debugProviderMap[debugProvider.id] = debugProvider;
1220
1185
  };
1221
1186
  const start = async (protocol, path) => {
1222
1187
  try {
@@ -1836,17 +1801,17 @@ const {
1836
1801
  }
1837
1802
  });
1838
1803
 
1839
- const state$3 = {
1804
+ const state$4 = {
1840
1805
  providers: Object.create(null)
1841
1806
  };
1842
1807
  const registerSourceControlProvider = provider => {
1843
- state$3.providers[provider.id] = provider;
1808
+ state$4.providers[provider.id] = provider;
1844
1809
  };
1845
1810
  const getFilesFromProvider = provider => {
1846
1811
  return provider.getChangedFiles();
1847
1812
  };
1848
1813
  const getChangedFiles = async providerId => {
1849
- const provider = state$3.providers[providerId];
1814
+ const provider = state$4.providers[providerId];
1850
1815
  if (!provider) {
1851
1816
  throw new Error('no source control provider found');
1852
1817
  }
@@ -1857,7 +1822,7 @@ const getChangedFiles = async providerId => {
1857
1822
  const getFileBefore = async (providerId, uri) => {
1858
1823
  string(providerId);
1859
1824
  string(uri);
1860
- const provider = state$3.providers[providerId];
1825
+ const provider = state$4.providers[providerId];
1861
1826
  if (!provider) {
1862
1827
  throw new Error('no source control provider found');
1863
1828
  }
@@ -1879,7 +1844,7 @@ const getGroupsFromProvider = async (provider, cwd) => {
1879
1844
  throw new Error('source control provider is missing required function getGroups');
1880
1845
  };
1881
1846
  const getGroups = async (providerId, cwd) => {
1882
- const provider = state$3.providers[providerId];
1847
+ const provider = state$4.providers[providerId];
1883
1848
  if (!provider) {
1884
1849
  throw new Error('no source control provider found');
1885
1850
  }
@@ -1887,14 +1852,14 @@ const getGroups = async (providerId, cwd) => {
1887
1852
  return groups;
1888
1853
  };
1889
1854
  const acceptInput = async (providerId, value) => {
1890
- const provider = state$3.providers[providerId];
1855
+ const provider = state$4.providers[providerId];
1891
1856
  if (!provider) {
1892
1857
  throw new Error('no source control provider found');
1893
1858
  }
1894
1859
  await provider.acceptInput(value);
1895
1860
  };
1896
1861
  const add = async path => {
1897
- const provider = Object.values(state$3.providers)[0];
1862
+ const provider = Object.values(state$4.providers)[0];
1898
1863
  if (!provider) {
1899
1864
  return;
1900
1865
  }
@@ -1902,7 +1867,7 @@ const add = async path => {
1902
1867
  await provider.add(path);
1903
1868
  };
1904
1869
  const discard = async path => {
1905
- const provider = Object.values(state$3.providers)[0];
1870
+ const provider = Object.values(state$4.providers)[0];
1906
1871
  if (!provider) {
1907
1872
  return;
1908
1873
  }
@@ -1912,7 +1877,7 @@ const discard = async path => {
1912
1877
  const getEnabledProviderIds = async (scheme, root) => {
1913
1878
  string(scheme);
1914
1879
  string(root);
1915
- const providers = Object.values(state$3.providers);
1880
+ const providers = Object.values(state$4.providers);
1916
1881
  const enabledIds = [];
1917
1882
  for (const provider of providers) {
1918
1883
  // @ts-ignore
@@ -1941,7 +1906,7 @@ const {
1941
1906
  }
1942
1907
  });
1943
1908
 
1944
- const state$2 = {
1909
+ const state$3 = {
1945
1910
  textSearchProviders: Object.create(null)
1946
1911
  };
1947
1912
  const registerTextSearchProvider = textSearchProvider => {
@@ -1952,16 +1917,16 @@ const registerTextSearchProvider = textSearchProvider => {
1952
1917
  if (!textSearchProvider.scheme) {
1953
1918
  throw new Error('textSearchProvider is missing scheme');
1954
1919
  }
1955
- state$2.textSearchProviders[textSearchProvider.scheme] = textSearchProvider;
1920
+ state$3.textSearchProviders[textSearchProvider.scheme] = textSearchProvider;
1956
1921
  } catch (error) {
1957
1922
  throw new VError$1(error, 'Failed to register text search provider');
1958
1923
  }
1959
1924
  };
1960
1925
  const executeTextSearchProvider = async (scheme, query) => {
1961
1926
  try {
1962
- const textSearchProvider = state$2.textSearchProviders[scheme];
1927
+ const textSearchProvider = state$3.textSearchProviders[scheme];
1963
1928
  if (!textSearchProvider) {
1964
- throw new Error(`no text search provider for ${scheme} found`);
1929
+ throw new Error(`No text search provider for ${scheme} found`);
1965
1930
  }
1966
1931
  const results = await textSearchProvider.provideTextSearchResults(query);
1967
1932
  return results;
@@ -2216,14 +2181,14 @@ const createWorker = async ({
2216
2181
  return ipc;
2217
2182
  };
2218
2183
 
2219
- const state$1 = {
2184
+ const state$2 = {
2220
2185
  workspacePath: ''
2221
2186
  };
2222
2187
  const setWorkspacePath = path => {
2223
- state$1.workspacePath = path;
2188
+ state$2.workspacePath = path;
2224
2189
  };
2225
2190
  const getWorkspaceFolder = path => {
2226
- return state$1.workspacePath;
2191
+ return state$2.workspacePath;
2227
2192
  };
2228
2193
 
2229
2194
  class FormattingError extends Error {
@@ -2256,7 +2221,7 @@ const api = {
2256
2221
  // Code Action
2257
2222
  registerCodeActionsProvider: registerCodeActionProvider,
2258
2223
  // Command
2259
- registerCommand: registerCommand$1,
2224
+ registerCommand: registerCommand,
2260
2225
  executeCommand: executeCommand,
2261
2226
  // Completion
2262
2227
  registerCompletionProvider: registerCompletionProvider,
@@ -2453,7 +2418,7 @@ class ContentSecurityPolicyError extends Error {
2453
2418
  }
2454
2419
  }
2455
2420
 
2456
- const state = {
2421
+ const state$1 = {
2457
2422
  /**
2458
2423
  * @type {any[]}
2459
2424
  */
@@ -2461,13 +2426,13 @@ const state = {
2461
2426
  };
2462
2427
  const addError = error => {
2463
2428
  // @ts-ignore
2464
- state.errors.push(error);
2429
+ state$1.errors.push(error);
2465
2430
  };
2466
2431
  const hasRecentErrors = () => {
2467
- return state.errors.length > 0;
2432
+ return state$1.errors.length > 0;
2468
2433
  };
2469
2434
  const getRecentError = () => {
2470
- return state.errors.at(-1);
2435
+ return state$1.errors.at(-1);
2471
2436
  };
2472
2437
 
2473
2438
  const isImportErrorChrome = error => {
@@ -2893,7 +2858,7 @@ const mockRpc = () => {
2893
2858
  };
2894
2859
 
2895
2860
  const getStatusBarItems = async () => {
2896
- const providers = Object.values(state$3.providers);
2861
+ const providers = Object.values(state$4.providers);
2897
2862
  const statusBarItems = [];
2898
2863
  for (const provider of providers) {
2899
2864
  // @ts-ignore
@@ -2927,6 +2892,27 @@ const Auto = () => {
2927
2892
  const getData$1 = event => {
2928
2893
  return event.data;
2929
2894
  };
2895
+ const attachEvents = that => {
2896
+ const handleMessage = (...args) => {
2897
+ const data = that.getData(...args);
2898
+ that.dispatchEvent(new MessageEvent('message', {
2899
+ data
2900
+ }));
2901
+ };
2902
+ that.onMessage(handleMessage);
2903
+ const handleClose = event => {
2904
+ that.dispatchEvent(new Event('close'));
2905
+ };
2906
+ that.onClose(handleClose);
2907
+ };
2908
+ class Ipc extends EventTarget {
2909
+ constructor(rawIpc) {
2910
+ super();
2911
+ this._rawIpc = rawIpc;
2912
+ attachEvents(this);
2913
+ }
2914
+ }
2915
+ const readyMessage = 'ready';
2930
2916
  const walkValue = (value, transferrables, isTransferrable) => {
2931
2917
  if (!value) {
2932
2918
  return;
@@ -2977,35 +2963,56 @@ const getTransferrables = value => {
2977
2963
  walkValue(value, transferrables, isTransferrable);
2978
2964
  return transferrables;
2979
2965
  };
2980
- const attachEvents = that => {
2981
- const handleMessage = (...args) => {
2982
- const data = that.getData(...args);
2983
- that.dispatchEvent(new MessageEvent('message', {
2984
- data
2985
- }));
2986
- };
2987
- that.onMessage(handleMessage);
2988
- const handleClose = event => {
2989
- that.dispatchEvent(new Event('close'));
2990
- };
2991
- that.onClose(handleClose);
2966
+ const listen$3 = ({
2967
+ port
2968
+ }) => {
2969
+ return port;
2992
2970
  };
2993
- class Ipc extends EventTarget {
2994
- constructor(rawIpc) {
2995
- super();
2996
- this._rawIpc = rawIpc;
2997
- attachEvents(this);
2971
+ const signal$3 = port => {
2972
+ port.postMessage(readyMessage);
2973
+ };
2974
+ class IpcChildWithMessagePort extends Ipc {
2975
+ constructor(port) {
2976
+ super(port);
2977
+ }
2978
+ getData(event) {
2979
+ return getData$1(event);
2980
+ }
2981
+ send(message) {
2982
+ this._rawIpc.postMessage(message);
2983
+ }
2984
+ sendAndTransfer(message) {
2985
+ const transfer = getTransferrables(message);
2986
+ this._rawIpc.postMessage(message, transfer);
2987
+ }
2988
+ dispose() {
2989
+ // ignore
2990
+ }
2991
+ onClose(callback) {
2992
+ // ignore
2993
+ }
2994
+ onMessage(callback) {
2995
+ this._rawIpc.addEventListener('message', callback);
2996
+ this._rawIpc.start();
2998
2997
  }
2999
2998
  }
3000
- const readyMessage = 'ready';
3001
- const listen$4 = () => {
2999
+ const wrap$6 = port => {
3000
+ return new IpcChildWithMessagePort(port);
3001
+ };
3002
+ const IpcChildWithMessagePort$1 = {
3003
+ __proto__: null,
3004
+ listen: listen$3,
3005
+ signal: signal$3,
3006
+ wrap: wrap$6
3007
+ };
3008
+ const listen$2 = () => {
3002
3009
  // @ts-ignore
3003
3010
  if (typeof WorkerGlobalScope === 'undefined') {
3004
3011
  throw new TypeError('module is not in web worker scope');
3005
3012
  }
3006
3013
  return globalThis;
3007
3014
  };
3008
- const signal$3 = global => {
3015
+ const signal$2 = global => {
3009
3016
  global.postMessage(readyMessage);
3010
3017
  };
3011
3018
  class IpcChildWithModuleWorker extends Ipc {
@@ -3031,14 +3038,14 @@ class IpcChildWithModuleWorker extends Ipc {
3031
3038
  this._rawIpc.addEventListener('message', callback);
3032
3039
  }
3033
3040
  }
3034
- const wrap$6 = global => {
3041
+ const wrap$5 = global => {
3035
3042
  return new IpcChildWithModuleWorker(global);
3036
3043
  };
3037
3044
  const IpcChildWithModuleWorker$1 = {
3038
3045
  __proto__: null,
3039
- listen: listen$4,
3040
- signal: signal$3,
3041
- wrap: wrap$6
3046
+ listen: listen$2,
3047
+ signal: signal$2,
3048
+ wrap: wrap$5
3042
3049
  };
3043
3050
  const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
3044
3051
  const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
@@ -3155,10 +3162,10 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
3155
3162
  };
3156
3163
  const normalizeLine = line => {
3157
3164
  if (line.startsWith('Error: ')) {
3158
- return line.slice(`Error: `.length);
3165
+ return line.slice('Error: '.length);
3159
3166
  }
3160
3167
  if (line.startsWith('VError: ')) {
3161
- return line.slice(`VError: `.length);
3168
+ return line.slice('VError: '.length);
3162
3169
  }
3163
3170
  return line;
3164
3171
  };
@@ -3256,10 +3263,10 @@ const waitForFirstMessage = async port => {
3256
3263
  // @ts-ignore
3257
3264
  return event.data;
3258
3265
  };
3259
- const listen$3 = async () => {
3260
- const parentIpcRaw = listen$4();
3261
- signal$3(parentIpcRaw);
3262
- const parentIpc = wrap$6(parentIpcRaw);
3266
+ const listen$1 = async () => {
3267
+ const parentIpcRaw = listen$2();
3268
+ signal$2(parentIpcRaw);
3269
+ const parentIpc = wrap$5(parentIpcRaw);
3263
3270
  const firstMessage = await waitForFirstMessage(parentIpc);
3264
3271
  if (firstMessage.method !== 'initialize') {
3265
3272
  throw new IpcError$1('unexpected first message');
@@ -3304,55 +3311,13 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
3304
3311
  this._rawIpc.start();
3305
3312
  }
3306
3313
  }
3307
- const wrap$5 = port => {
3314
+ const wrap$4$1 = port => {
3308
3315
  return new IpcChildWithModuleWorkerAndMessagePort(port);
3309
3316
  };
3310
3317
  const IpcChildWithModuleWorkerAndMessagePort$1 = {
3311
- __proto__: null,
3312
- listen: listen$3,
3313
- wrap: wrap$5
3314
- };
3315
- const listen$1 = ({
3316
- port
3317
- }) => {
3318
- return port;
3319
- };
3320
- const signal = port => {
3321
- port.postMessage(readyMessage);
3322
- };
3323
- class IpcChildWithMessagePort extends Ipc {
3324
- constructor(port) {
3325
- super(port);
3326
- }
3327
- getData(event) {
3328
- return getData$1(event);
3329
- }
3330
- send(message) {
3331
- this._rawIpc.postMessage(message);
3332
- }
3333
- sendAndTransfer(message) {
3334
- const transfer = getTransferrables(message);
3335
- this._rawIpc.postMessage(message, transfer);
3336
- }
3337
- dispose() {
3338
- // ignore
3339
- }
3340
- onClose(callback) {
3341
- // ignore
3342
- }
3343
- onMessage(callback) {
3344
- this._rawIpc.addEventListener('message', callback);
3345
- this._rawIpc.start();
3346
- }
3347
- }
3348
- const wrap$2$1 = port => {
3349
- return new IpcChildWithMessagePort(port);
3350
- };
3351
- const IpcChildWithMessagePort$1 = {
3352
3318
  __proto__: null,
3353
3319
  listen: listen$1,
3354
- signal,
3355
- wrap: wrap$2$1
3320
+ wrap: wrap$4$1
3356
3321
  };
3357
3322
 
3358
3323
  const getModule$1 = method => {
@@ -3404,9 +3369,361 @@ const saveState = async () => {
3404
3369
  return serialized;
3405
3370
  };
3406
3371
 
3372
+ const instanceOfAny = (object, constructors) => constructors.some(c => object instanceof c);
3373
+ let idbProxyableTypes;
3374
+ let cursorAdvanceMethods;
3375
+ // This is a function to prevent it throwing up in node environments.
3376
+ function getIdbProxyableTypes() {
3377
+ return idbProxyableTypes || (idbProxyableTypes = [IDBDatabase, IDBObjectStore, IDBIndex, IDBCursor, IDBTransaction]);
3378
+ }
3379
+ // This is a function to prevent it throwing up in node environments.
3380
+ function getCursorAdvanceMethods() {
3381
+ return cursorAdvanceMethods || (cursorAdvanceMethods = [IDBCursor.prototype.advance, IDBCursor.prototype.continue, IDBCursor.prototype.continuePrimaryKey]);
3382
+ }
3383
+ const transactionDoneMap = new WeakMap();
3384
+ const transformCache = new WeakMap();
3385
+ const reverseTransformCache = new WeakMap();
3386
+ function promisifyRequest(request) {
3387
+ const promise = new Promise((resolve, reject) => {
3388
+ const unlisten = () => {
3389
+ request.removeEventListener('success', success);
3390
+ request.removeEventListener('error', error);
3391
+ };
3392
+ const success = () => {
3393
+ resolve(wrap$4(request.result));
3394
+ unlisten();
3395
+ };
3396
+ const error = () => {
3397
+ reject(request.error);
3398
+ unlisten();
3399
+ };
3400
+ request.addEventListener('success', success);
3401
+ request.addEventListener('error', error);
3402
+ });
3403
+ // This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This
3404
+ // is because we create many promises from a single IDBRequest.
3405
+ reverseTransformCache.set(promise, request);
3406
+ return promise;
3407
+ }
3408
+ function cacheDonePromiseForTransaction(tx) {
3409
+ // Early bail if we've already created a done promise for this transaction.
3410
+ if (transactionDoneMap.has(tx)) return;
3411
+ const done = new Promise((resolve, reject) => {
3412
+ const unlisten = () => {
3413
+ tx.removeEventListener('complete', complete);
3414
+ tx.removeEventListener('error', error);
3415
+ tx.removeEventListener('abort', error);
3416
+ };
3417
+ const complete = () => {
3418
+ resolve();
3419
+ unlisten();
3420
+ };
3421
+ const error = () => {
3422
+ reject(tx.error || new DOMException('AbortError', 'AbortError'));
3423
+ unlisten();
3424
+ };
3425
+ tx.addEventListener('complete', complete);
3426
+ tx.addEventListener('error', error);
3427
+ tx.addEventListener('abort', error);
3428
+ });
3429
+ // Cache it for later retrieval.
3430
+ transactionDoneMap.set(tx, done);
3431
+ }
3432
+ let idbProxyTraps = {
3433
+ get(target, prop, receiver) {
3434
+ if (target instanceof IDBTransaction) {
3435
+ // Special handling for transaction.done.
3436
+ if (prop === 'done') return transactionDoneMap.get(target);
3437
+ // Make tx.store return the only store in the transaction, or undefined if there are many.
3438
+ if (prop === 'store') {
3439
+ return receiver.objectStoreNames[1] ? undefined : receiver.objectStore(receiver.objectStoreNames[0]);
3440
+ }
3441
+ }
3442
+ // Else transform whatever we get back.
3443
+ return wrap$4(target[prop]);
3444
+ },
3445
+ set(target, prop, value) {
3446
+ target[prop] = value;
3447
+ return true;
3448
+ },
3449
+ has(target, prop) {
3450
+ if (target instanceof IDBTransaction && (prop === 'done' || prop === 'store')) {
3451
+ return true;
3452
+ }
3453
+ return prop in target;
3454
+ }
3455
+ };
3456
+ function replaceTraps(callback) {
3457
+ idbProxyTraps = callback(idbProxyTraps);
3458
+ }
3459
+ function wrapFunction(func) {
3460
+ // Due to expected object equality (which is enforced by the caching in `wrap`), we
3461
+ // only create one new func per func.
3462
+ // Cursor methods are special, as the behaviour is a little more different to standard IDB. In
3463
+ // IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
3464
+ // cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
3465
+ // with real promises, so each advance methods returns a new promise for the cursor object, or
3466
+ // undefined if the end of the cursor has been reached.
3467
+ if (getCursorAdvanceMethods().includes(func)) {
3468
+ return function (...args) {
3469
+ // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
3470
+ // the original object.
3471
+ func.apply(unwrap(this), args);
3472
+ return wrap$4(this.request);
3473
+ };
3474
+ }
3475
+ return function (...args) {
3476
+ // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
3477
+ // the original object.
3478
+ return wrap$4(func.apply(unwrap(this), args));
3479
+ };
3480
+ }
3481
+ function transformCachableValue(value) {
3482
+ if (typeof value === 'function') return wrapFunction(value);
3483
+ // This doesn't return, it just creates a 'done' promise for the transaction,
3484
+ // which is later returned for transaction.done (see idbObjectHandler).
3485
+ if (value instanceof IDBTransaction) cacheDonePromiseForTransaction(value);
3486
+ if (instanceOfAny(value, getIdbProxyableTypes())) return new Proxy(value, idbProxyTraps);
3487
+ // Return the same value back if we're not going to transform it.
3488
+ return value;
3489
+ }
3490
+ function wrap$4(value) {
3491
+ // We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
3492
+ // IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
3493
+ if (value instanceof IDBRequest) return promisifyRequest(value);
3494
+ // If we've already transformed this value before, reuse the transformed value.
3495
+ // This is faster, but it also provides object equality.
3496
+ if (transformCache.has(value)) return transformCache.get(value);
3497
+ const newValue = transformCachableValue(value);
3498
+ // Not all types are transformed.
3499
+ // These may be primitive types, so they can't be WeakMap keys.
3500
+ if (newValue !== value) {
3501
+ transformCache.set(value, newValue);
3502
+ reverseTransformCache.set(newValue, value);
3503
+ }
3504
+ return newValue;
3505
+ }
3506
+ const unwrap = value => reverseTransformCache.get(value);
3507
+
3508
+ /**
3509
+ * Open a database.
3510
+ *
3511
+ * @param name Name of the database.
3512
+ * @param version Schema version.
3513
+ * @param callbacks Additional callbacks.
3514
+ */
3515
+ function openDB(name, version, {
3516
+ blocked,
3517
+ upgrade,
3518
+ blocking,
3519
+ terminated
3520
+ } = {}) {
3521
+ const request = indexedDB.open(name, version);
3522
+ const openPromise = wrap$4(request);
3523
+ if (upgrade) {
3524
+ request.addEventListener('upgradeneeded', event => {
3525
+ upgrade(wrap$4(request.result), event.oldVersion, event.newVersion, wrap$4(request.transaction), event);
3526
+ });
3527
+ }
3528
+ if (blocked) {
3529
+ request.addEventListener('blocked', event => blocked(
3530
+ // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
3531
+ event.oldVersion, event.newVersion, event));
3532
+ }
3533
+ openPromise.then(db => {
3534
+ if (terminated) db.addEventListener('close', () => terminated());
3535
+ if (blocking) {
3536
+ db.addEventListener('versionchange', event => blocking(event.oldVersion, event.newVersion, event));
3537
+ }
3538
+ }).catch(() => {});
3539
+ return openPromise;
3540
+ }
3541
+ const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
3542
+ const writeMethods = ['put', 'add', 'delete', 'clear'];
3543
+ const cachedMethods = new Map();
3544
+ function getMethod(target, prop) {
3545
+ if (!(target instanceof IDBDatabase && !(prop in target) && typeof prop === 'string')) {
3546
+ return;
3547
+ }
3548
+ if (cachedMethods.get(prop)) return cachedMethods.get(prop);
3549
+ const targetFuncName = prop.replace(/FromIndex$/, '');
3550
+ const useIndex = prop !== targetFuncName;
3551
+ const isWrite = writeMethods.includes(targetFuncName);
3552
+ if (
3553
+ // Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
3554
+ !(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) || !(isWrite || readMethods.includes(targetFuncName))) {
3555
+ return;
3556
+ }
3557
+ const method = async function (storeName, ...args) {
3558
+ // isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
3559
+ const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
3560
+ let target = tx.store;
3561
+ if (useIndex) target = target.index(args.shift());
3562
+ // Must reject if op rejects.
3563
+ // If it's a write operation, must reject if tx.done rejects.
3564
+ // Must reject with op rejection first.
3565
+ // Must resolve with op value.
3566
+ // Must handle both promises (no unhandled rejections)
3567
+ return (await Promise.all([target[targetFuncName](...args), isWrite && tx.done]))[0];
3568
+ };
3569
+ cachedMethods.set(prop, method);
3570
+ return method;
3571
+ }
3572
+ replaceTraps(oldTraps => ({
3573
+ ...oldTraps,
3574
+ get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
3575
+ has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop)
3576
+ }));
3577
+ const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];
3578
+ const methodMap = {};
3579
+ const advanceResults = new WeakMap();
3580
+ const ittrProxiedCursorToOriginalProxy = new WeakMap();
3581
+ const cursorIteratorTraps = {
3582
+ get(target, prop) {
3583
+ if (!advanceMethodProps.includes(prop)) return target[prop];
3584
+ let cachedFunc = methodMap[prop];
3585
+ if (!cachedFunc) {
3586
+ cachedFunc = methodMap[prop] = function (...args) {
3587
+ advanceResults.set(this, ittrProxiedCursorToOriginalProxy.get(this)[prop](...args));
3588
+ };
3589
+ }
3590
+ return cachedFunc;
3591
+ }
3592
+ };
3593
+ async function* iterate(...args) {
3594
+ // tslint:disable-next-line:no-this-assignment
3595
+ let cursor = this;
3596
+ if (!(cursor instanceof IDBCursor)) {
3597
+ cursor = await cursor.openCursor(...args);
3598
+ }
3599
+ if (!cursor) return;
3600
+ cursor = cursor;
3601
+ const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
3602
+ ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
3603
+ // Map this double-proxy back to the original, so other cursor methods work.
3604
+ reverseTransformCache.set(proxiedCursor, unwrap(cursor));
3605
+ while (cursor) {
3606
+ yield proxiedCursor;
3607
+ // If one of the advancing methods was not called, call continue().
3608
+ cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
3609
+ advanceResults.delete(proxiedCursor);
3610
+ }
3611
+ }
3612
+ function isIteratorProp(target, prop) {
3613
+ return prop === Symbol.asyncIterator && instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor]) || prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore]);
3614
+ }
3615
+ replaceTraps(oldTraps => ({
3616
+ ...oldTraps,
3617
+ get(target, prop, receiver) {
3618
+ if (isIteratorProp(target, prop)) return iterate;
3619
+ return oldTraps.get(target, prop, receiver);
3620
+ },
3621
+ has(target, prop) {
3622
+ return isIteratorProp(target, prop) || oldTraps.has(target, prop);
3623
+ }
3624
+ }));
3625
+
3626
+ const state = {
3627
+ databases: Object.create(null),
3628
+ eventId: 0,
3629
+ dbVersion: 1,
3630
+ /**
3631
+ * @type {any}
3632
+ */
3633
+ cachedDb: undefined
3634
+ };
3635
+
3636
+ const isDataCloneError = error => {
3637
+ return error && error.name === 'DataCloneError';
3638
+ };
3639
+
3640
+ // TODO high memory usage in idb because of transactionDoneMap
3641
+
3642
+ const getDb = async () => {
3643
+ // @ts-ignore
3644
+ const db = await openDB('session', state.dbVersion, {
3645
+ async upgrade(db, oldVersion) {
3646
+ if (!db.objectStoreNames.contains('session')) {
3647
+ const objectStore = await db.createObjectStore('session', {
3648
+ autoIncrement: true
3649
+ });
3650
+ objectStore.createIndex('sessionId', 'sessionId', {
3651
+ unique: false
3652
+ });
3653
+ }
3654
+ }
3655
+ });
3656
+ return db;
3657
+ };
3658
+ const getDbMemoized = async () => {
3659
+ state.cachedDb ||= await getDb();
3660
+ return state.cachedDb;
3661
+ };
3662
+ const saveValue = async (storeId, value) => {
3663
+ try {
3664
+ const db = await getDbMemoized();
3665
+ await db.add('session', value);
3666
+ } catch (error) {
3667
+ if (isDataCloneError(error)) {
3668
+ // TODO
3669
+ return;
3670
+ }
3671
+ throw new VError$1(error, 'Failed to save value to indexed db');
3672
+ }
3673
+ };
3674
+ const getValues = async storeId => {
3675
+ try {
3676
+ const db = await getDbMemoized();
3677
+ const tx = db.transaction(storeId, 'readwrite');
3678
+ const [objects] = await Promise.all([tx.store.getAll(), tx.done]);
3679
+ console.log({
3680
+ objects
3681
+ });
3682
+ return objects;
3683
+ } catch (error) {
3684
+ throw new VError$1(error, 'Failed to get values from indexed db');
3685
+ }
3686
+ };
3687
+ const getValuesByIndexName = async (storeId, indexName, only) => {
3688
+ const db = await getDbMemoized();
3689
+ const transaction = db.transaction(storeId);
3690
+ const index = transaction.store.index(indexName);
3691
+ const iterator = index.iterate(only);
3692
+ const objects = [];
3693
+ for await (const cursor of iterator) {
3694
+ objects.push(cursor.value);
3695
+ }
3696
+ return objects;
3697
+ };
3698
+ const getHandleDb = async () => {
3699
+ const db = await openDB('handle', state.dbVersion, {
3700
+ async upgrade(db, oldVersion) {
3701
+ if (!db.objectStoreNames.contains('file-handles-store')) {
3702
+ // @ts-ignore
3703
+ await db.createObjectStore('file-handles-store', {});
3704
+ }
3705
+ }
3706
+ });
3707
+ return db;
3708
+ };
3709
+ const addHandle = async (uri, handle) => {
3710
+ const handleDb = await getHandleDb();
3711
+ await handleDb.put('file-handles-store', handle, uri);
3712
+ };
3713
+ const getHandle = async uri => {
3714
+ const handleDb = await getHandleDb();
3715
+ const handle = await handleDb.get('file-handles-store', uri);
3716
+ return handle;
3717
+ };
3718
+
3407
3719
  const commandMap = {
3408
- 'ExtensionHostRename.executeRenameProvider': executeRenameProvider,
3409
3720
  'ExtensionHostRename.executeprepareRenameProvider': executeprepareRenameProvider,
3721
+ 'ExtensionHostRename.executeRenameProvider': executeRenameProvider,
3722
+ 'IndexedDb.addHandle': addHandle,
3723
+ 'IndexedDb.getHandle': getHandle,
3724
+ 'IndexedDb.getValues': getValues,
3725
+ 'IndexedDb.getValuesByIndexName': getValuesByIndexName,
3726
+ 'IndexedDb.saveValue': saveValue,
3410
3727
  ['ExtensionHostDebug.evaluate']: evaluate,
3411
3728
  ['ExtensionHostDebug.getProperties']: getProperties,
3412
3729
  ['ExtensionHostDebug.listProcesses']: listProcesses,
@@ -3539,7 +3856,7 @@ const main = async () => {
3539
3856
  const ipc = await listen({
3540
3857
  method: Auto()
3541
3858
  });
3542
- listen$2(ipc);
3859
+ listen$4(ipc);
3543
3860
  };
3544
3861
 
3545
3862
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
5
  "main": "dist/extensionHostWorkerMain.js",
6
6
  "type": "module",