@lvce-editor/extension-management-worker 4.84.0 → 4.86.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.
@@ -79,7 +79,7 @@ const get$7 = applicationId => {
79
79
  }
80
80
  return state$4.extensionsState;
81
81
  };
82
- const set$d = newState => {
82
+ const set$e = newState => {
83
83
  if (newState.applicationId !== undefined) {
84
84
  const currentState = get$7(newState.applicationId);
85
85
  if (newState.applicationGeneration !== currentState.applicationGeneration) {
@@ -97,7 +97,7 @@ const update = (newState, applicationId) => {
97
97
  throw new Error('Cannot change extension application identity');
98
98
  }
99
99
  const current = get$7(applicationId);
100
- set$d({
100
+ set$e({
101
101
  ...current,
102
102
  ...newState
103
103
  });
@@ -921,6 +921,9 @@ const restoreExistingError = (error, currentStack) => {
921
921
  };
922
922
  const restoreMethodNotFoundError = (error, currentStack) => {
923
923
  const restoredError = new JsonRpcError(error.message);
924
+ Object.assign(restoredError, {
925
+ code: error.code
926
+ });
924
927
  const parentStack = getParentStack(error);
925
928
  setStack(restoredError, `${parentStack}${NewLine$1}${currentStack}`);
926
929
  return restoredError;
@@ -940,9 +943,13 @@ const applyDataProperties = (restoredError, error) => {
940
943
  // @ts-ignore
941
944
  restoredError.codeFrame = error.data.codeFrame;
942
945
  }
943
- if (error.data.code) {
946
+ if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
944
947
  // @ts-ignore
945
- restoredError.code = error.data.code;
948
+ Object.defineProperty(restoredError, 'code', {
949
+ configurable: true,
950
+ value: error.data.code,
951
+ writable: true
952
+ });
946
953
  }
947
954
  if (error.data.type) {
948
955
  // @ts-ignore
@@ -963,7 +970,14 @@ const applyDirectProperties = (restoredError, error) => {
963
970
  }
964
971
  };
965
972
  const restoreMessageError = (error, _currentStack) => {
966
- const restoredError = constructError(error.message, error.type, error.name);
973
+ const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
974
+ if (typeof error.code === 'string' || typeof error.code === 'number') {
975
+ Object.defineProperty(restoredError, 'code', {
976
+ configurable: true,
977
+ value: error.code,
978
+ writable: true
979
+ });
980
+ }
967
981
  if (error.data) {
968
982
  applyDataProperties(restoredError, error);
969
983
  } else {
@@ -971,6 +985,23 @@ const restoreMessageError = (error, _currentStack) => {
971
985
  }
972
986
  return restoredError;
973
987
  };
988
+ const getFallbackMessage = error => {
989
+ if (error && typeof error.message === 'string' && error.message) {
990
+ return error.message;
991
+ }
992
+ if (error && error.data) {
993
+ return getFallbackMessage(error.data);
994
+ }
995
+ const stringified = String(error);
996
+ if (stringified !== '[object Object]') {
997
+ return stringified;
998
+ }
999
+ try {
1000
+ return JSON.stringify(error);
1001
+ } catch {
1002
+ return stringified;
1003
+ }
1004
+ };
974
1005
  const restoreJsonRpcError = error => {
975
1006
  const currentStack = getCurrentStack();
976
1007
  if (error && error instanceof Error) {
@@ -979,13 +1010,13 @@ const restoreJsonRpcError = error => {
979
1010
  if (error && error.code && error.code === MethodNotFound) {
980
1011
  return restoreMethodNotFoundError(error, currentStack);
981
1012
  }
1013
+ if (error && error.error) {
1014
+ return restoreJsonRpcError(error.error);
1015
+ }
982
1016
  if (error && error.message) {
983
1017
  return restoreMessageError(error);
984
1018
  }
985
- if (typeof error === 'string') {
986
- return new Error(`JsonRpc Error: ${error}`);
987
- }
988
- return new Error(`JsonRpc Error: ${error}`);
1019
+ return new Error(`JsonRpc Error: ${getFallbackMessage(error)}`);
989
1020
  };
990
1021
  const unwrapJsonRpcResult = responseMessage => {
991
1022
  if ('error' in responseMessage) {
@@ -1042,9 +1073,9 @@ const getErrorProperty = (error, prettyError) => {
1042
1073
  return {
1043
1074
  code: Custom,
1044
1075
  data: {
1045
- code: prettyError.code,
1076
+ code: prettyError.code ?? error?.code,
1046
1077
  codeFrame: prettyError.codeFrame,
1047
- name: prettyError.name,
1078
+ name: prettyError.name ?? error?.name,
1048
1079
  stack: getStack(prettyError),
1049
1080
  type: getErrorType(prettyError)
1050
1081
  },
@@ -1079,7 +1110,12 @@ const getErrorResponseSimple = (id, error) => {
1079
1110
  return {
1080
1111
  error: {
1081
1112
  code: Custom,
1082
- data: error,
1113
+ data: error instanceof Error ? {
1114
+ ...error,
1115
+ code: 'code' in error ? error.code : undefined,
1116
+ stack: error.stack,
1117
+ type: error.name
1118
+ } : error,
1083
1119
  // @ts-ignore
1084
1120
  message: error.message
1085
1121
  },
@@ -1518,7 +1554,7 @@ const RendererWorker = 1;
1518
1554
  const SharedProcess = 1492;
1519
1555
 
1520
1556
  const rpcs$2 = Object.create(null);
1521
- const set$c = (id, rpc) => {
1557
+ const set$d = (id, rpc) => {
1522
1558
  rpcs$2[id] = rpc;
1523
1559
  };
1524
1560
  const get$5 = id => {
@@ -1551,7 +1587,7 @@ const create = rpcId => {
1551
1587
  const mockRpc = createMockRpc({
1552
1588
  commandMap
1553
1589
  });
1554
- set$c(rpcId, mockRpc);
1590
+ set$d(rpcId, mockRpc);
1555
1591
  // @ts-ignore
1556
1592
  mockRpc[Symbol.dispose] = () => {
1557
1593
  remove$2(rpcId);
@@ -1560,15 +1596,29 @@ const create = rpcId => {
1560
1596
  return mockRpc;
1561
1597
  },
1562
1598
  set(rpc) {
1563
- set$c(rpcId, rpc);
1599
+ set$d(rpcId, rpc);
1564
1600
  }
1565
1601
  };
1566
1602
  };
1567
1603
 
1604
+ const {
1605
+ invoke: invoke$9,
1606
+ set: set$c
1607
+ } = create(6010);
1608
+
1568
1609
  const {
1569
1610
  invoke: invoke$8,
1570
1611
  set: set$b
1571
- } = create(6010);
1612
+ } = create(19_001);
1613
+ const getCacheStorageItem = async (request, cacheName, bucketName, bucketOptions) => {
1614
+ return invoke$8('Cache.getCacheStorageItem', request, cacheName, bucketName, bucketOptions);
1615
+ };
1616
+ const removeCacheStorageItem = async (request, cacheName, bucketName, bucketOptions) => {
1617
+ return invoke$8('Cache.removeCacheStorageItem', request, cacheName, bucketName, bucketOptions);
1618
+ };
1619
+ const setCacheStorageItem = async (request, value, cacheName, headers, bucketName, bucketOptions) => {
1620
+ return invoke$8('Cache.setCacheStorageItem', request, value, cacheName, headers, bucketName, bucketOptions);
1621
+ };
1572
1622
 
1573
1623
  const {
1574
1624
  invoke: invoke$7,
@@ -1668,20 +1718,22 @@ const createResponseFromData = data => {
1668
1718
  const cacheName$1 = 'Extensions'; // TODO
1669
1719
 
1670
1720
  const getJson$1 = async cacheKey => {
1671
- const response = await caches.match(cacheKey, {
1672
- cacheName: cacheName$1
1673
- });
1674
- if (!response) {
1721
+ const item = await getCacheStorageItem(cacheKey, cacheName$1);
1722
+ if (!item) {
1675
1723
  return undefined;
1676
1724
  }
1677
- const json = await response.json();
1678
- return json;
1725
+ const body = item.body;
1726
+ const json = typeof body === 'string' ? body : new TextDecoder().decode(body);
1727
+ return JSON.parse(json);
1679
1728
  };
1680
1729
  const setJson = async (cacheKey, data) => {
1681
1730
  try {
1682
- const cache = await caches.open(cacheName$1);
1683
1731
  const response = createResponseFromData(data);
1684
- await cache.put(cacheKey, response);
1732
+ const headers = Object.fromEntries(response.headers.entries());
1733
+ const result = await setCacheStorageItem(cacheKey, await response.arrayBuffer(), cacheName$1, headers);
1734
+ if (!result.success) {
1735
+ throw new Error(result.errorMessage);
1736
+ }
1685
1737
  } catch (error) {
1686
1738
  throw new VError(error, `Failed to add to cache`);
1687
1739
  }
@@ -2780,6 +2832,12 @@ const reset = applicationId => {
2780
2832
  }
2781
2833
  };
2782
2834
 
2835
+ const getCacheFileHandle = async (extensionId, name) => {
2836
+ const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(extensionId));
2837
+ const hash = Array.from(new Uint8Array(digest), byte => byte.toString(16).padStart(2, '0')).join('');
2838
+ return invoke$8('Opfs.getCacheFileHandle', `extension-${hash}`, name);
2839
+ };
2840
+
2783
2841
  const prefix = '[Extension] Uncaught Error: ';
2784
2842
  const handleUncaughtExtensionError = async error => {
2785
2843
  const prettyError = await invoke$7('Errors.prepare', error);
@@ -2918,8 +2976,7 @@ const deleteSecret = async (extensionId, key) => {
2918
2976
  await invoke$5('SecretStorage.delete', extensionId, key);
2919
2977
  return;
2920
2978
  }
2921
- const cache = await caches.open(cacheName);
2922
- await cache.delete(getRequestUrl(extensionId, key));
2979
+ await removeCacheStorageItem(getRequestUrl(extensionId, key), cacheName);
2923
2980
  };
2924
2981
  const getSecret = async (extensionId, key) => {
2925
2982
  string(extensionId);
@@ -2927,9 +2984,12 @@ const getSecret = async (extensionId, key) => {
2927
2984
  if (isElectron()) {
2928
2985
  return invoke$5('SecretStorage.get', extensionId, key);
2929
2986
  }
2930
- const cache = await caches.open(cacheName);
2931
- const response = await cache.match(getRequestUrl(extensionId, key));
2932
- return response?.text();
2987
+ const item = await getCacheStorageItem(getRequestUrl(extensionId, key), cacheName);
2988
+ if (!item) {
2989
+ return undefined;
2990
+ }
2991
+ const body = item.body;
2992
+ return typeof body === 'string' ? body : new TextDecoder().decode(body);
2933
2993
  };
2934
2994
  const storeSecret = async (extensionId, key, value) => {
2935
2995
  string(extensionId);
@@ -2939,8 +2999,10 @@ const storeSecret = async (extensionId, key, value) => {
2939
2999
  await invoke$5('SecretStorage.store', extensionId, key, value);
2940
3000
  return;
2941
3001
  }
2942
- const cache = await caches.open(cacheName);
2943
- await cache.put(getRequestUrl(extensionId, key), new Response(value));
3002
+ const result = await setCacheStorageItem(getRequestUrl(extensionId, key), value, cacheName);
3003
+ if (!result.success) {
3004
+ throw new Error(result.errorMessage);
3005
+ }
2944
3006
  };
2945
3007
 
2946
3008
  class CommandNotFoundError extends Error {
@@ -2988,6 +3050,7 @@ const createExtensionCommandMap = (extensionId, invokeCommand = invokeGlobalComm
2988
3050
  return {
2989
3051
  ...inheritedCommands,
2990
3052
  'Extensions.executeCommand': (id, ...args) => executeCommand$1(invokeCommand, id, ...args),
3053
+ 'Extensions.getCacheFileHandle': name => invokeCommand('Extensions.getCacheFileHandle', name),
2991
3054
  'Extensions.registerFileChangeHandler': () => invokeCommand('Extensions.registerFileChangeHandler'),
2992
3055
  'Extensions.unregisterFileChangeHandler': () => invokeCommand('Extensions.unregisterFileChangeHandler')
2993
3056
  };
@@ -3006,6 +3069,9 @@ const createExtensionCommandMap = (extensionId, invokeCommand = invokeGlobalComm
3006
3069
  'Extensions.executeCommand'(id, ...args) {
3007
3070
  return executeCommand$1(invokeCommand, id, ...args);
3008
3071
  },
3072
+ 'Extensions.getCacheFileHandle'(name) {
3073
+ return getCacheFileHandle(extensionId, name);
3074
+ },
3009
3075
  'Extensions.getSecret'(key) {
3010
3076
  return getSecret(extensionId, key);
3011
3077
  },
@@ -3061,6 +3127,9 @@ const createIsolatedExtensionHostWorker = async (extensionId, absolutePath, work
3061
3127
  const runtimeId = getRuntimeId(extensionId, application);
3062
3128
  const invokeCommand = application === undefined ? undefined : (method, ...args) => {
3063
3129
  assertCurrentApplication(application);
3130
+ if (method === 'Extensions.getCacheFileHandle') {
3131
+ return getCacheFileHandle(extensionId, args[0]);
3132
+ }
3064
3133
  if (method === 'Extensions.registerFileChangeHandler') {
3065
3134
  return register(extensionId, application.applicationId);
3066
3135
  }
@@ -3491,7 +3560,7 @@ const disableExtension2$1 = async (id, platform) => {
3491
3560
  ...oldState,
3492
3561
  disabledIds: [...oldState.disabledIds, id]
3493
3562
  };
3494
- set$d(newState);
3563
+ set$e(newState);
3495
3564
  } else if (isWeb) {
3496
3565
  const cached = await getJson$1(disabledExtensionsCacheKey);
3497
3566
  const oldDisabled = getStringArray(cached?.disabledExtensions);
@@ -3516,7 +3585,7 @@ const enableExtension2$1 = async (id, platform) => {
3516
3585
  ...oldState,
3517
3586
  disabledIds: oldState.disabledIds.filter(existing => existing !== id)
3518
3587
  };
3519
- set$d(newState);
3588
+ set$e(newState);
3520
3589
  } else if (isWeb) {
3521
3590
  const cached = await getJson$1(disabledExtensionsCacheKey);
3522
3591
  const oldDisabled = getStringArray(cached?.disabledExtensions);
@@ -5161,7 +5230,7 @@ const saveViewInstanceState = async (viewId, uid, assetDir, platform) => {
5161
5230
  };
5162
5231
 
5163
5232
  const getAccessToken = (options = {}) => {
5164
- return invoke$8('Auth.getAccessToken', options);
5233
+ return invoke$9('Auth.getAccessToken', options);
5165
5234
  };
5166
5235
 
5167
5236
  const transparent = (color, factor) => {
@@ -6476,6 +6545,16 @@ const initializeAuthWorker = async () => {
6476
6545
  await sendMessagePortToAuthWorker(port, 0);
6477
6546
  }
6478
6547
  });
6548
+ set$c(rpc);
6549
+ };
6550
+
6551
+ const initializeCacheWorker = async () => {
6552
+ const rpc = await create$5({
6553
+ commandMap: commandMapRef,
6554
+ async send(port) {
6555
+ await invokeAndTransfer$1('SendMessagePortToExtensionHostWorker.sendMessagePortToCacheWorker', port);
6556
+ }
6557
+ });
6479
6558
  set$b(rpc);
6480
6559
  };
6481
6560
 
@@ -6518,7 +6597,7 @@ const initializeRendererWorker = async () => {
6518
6597
 
6519
6598
  const listen = async () => {
6520
6599
  Object.assign(commandMapRef, commandMap);
6521
- await Promise.all([initializeRendererWorker(), initializeAuthWorker(), initializeErrorWorker(), initializeFileSystemWorker(), initializeIframeWorker()]);
6600
+ await Promise.all([initializeRendererWorker(), initializeAuthWorker(), initializeCacheWorker(), initializeErrorWorker(), initializeFileSystemWorker(), initializeIframeWorker()]);
6522
6601
  };
6523
6602
 
6524
6603
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.84.0",
3
+ "version": "4.86.0",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"