@lvce-editor/extension-host-worker 8.12.0 → 8.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.
@@ -59,7 +59,7 @@ const Boolean$2 = 5;
59
59
  const Function = 6;
60
60
  const Null = 7;
61
61
  const Unknown = 8;
62
- const getType$1 = value => {
62
+ const getType$2 = value => {
63
63
  switch (typeof value) {
64
64
  case 'number':
65
65
  return Number$1;
@@ -82,31 +82,31 @@ const getType$1 = value => {
82
82
  }
83
83
  };
84
84
  const object = value => {
85
- const type = getType$1(value);
85
+ const type = getType$2(value);
86
86
  if (type !== Object$1$1) {
87
87
  throw new AssertionError('expected value to be of type object');
88
88
  }
89
89
  };
90
90
  const number = value => {
91
- const type = getType$1(value);
91
+ const type = getType$2(value);
92
92
  if (type !== Number$1) {
93
93
  throw new AssertionError('expected value to be of type number');
94
94
  }
95
95
  };
96
96
  const array = value => {
97
- const type = getType$1(value);
97
+ const type = getType$2(value);
98
98
  if (type !== Array$1$1) {
99
99
  throw new AssertionError('expected value to be of type array');
100
100
  }
101
101
  };
102
102
  const string = value => {
103
- const type = getType$1(value);
103
+ const type = getType$2(value);
104
104
  if (type !== String$2) {
105
105
  throw new AssertionError('expected value to be of type string');
106
106
  }
107
107
  };
108
108
  const fn = value => {
109
- const type = getType$1(value);
109
+ const type = getType$2(value);
110
110
  if (type !== Function) {
111
111
  throw new AssertionError('expected value to be of type function');
112
112
  }
@@ -351,7 +351,7 @@ class NoProviderFoundError extends Error {
351
351
  }
352
352
  }
353
353
 
354
- const getType = value => {
354
+ const getType$1 = value => {
355
355
  switch (typeof value) {
356
356
  case 'boolean':
357
357
  return 'boolean';
@@ -383,7 +383,7 @@ const validateResultObject = (result, resultShape) => {
383
383
  for (const [key, value] of Object.entries(resultShape.properties)) {
384
384
  // @ts-ignore
385
385
  const expectedType = value.type;
386
- const actualType = getType(result[key]);
386
+ const actualType = getType$1(result[key]);
387
387
  if (expectedType !== actualType) {
388
388
  return `item.${key} must be of type ${expectedType}`;
389
389
  }
@@ -392,7 +392,7 @@ const validateResultObject = (result, resultShape) => {
392
392
  };
393
393
  const validateResultArray = (result, resultShape) => {
394
394
  for (const item of result) {
395
- const actualType = getType(item);
395
+ const actualType = getType$1(item);
396
396
  const expectedType = resultShape.items.type;
397
397
  if (actualType !== expectedType) {
398
398
  return `expected result to be of type ${expectedType} but was of type ${actualType}`;
@@ -413,7 +413,7 @@ const getPreviewString = item => {
413
413
  return `"${item}"`;
414
414
  };
415
415
  const getPreview = item => {
416
- const type = getType(item);
416
+ const type = getType$1(item);
417
417
  switch (type) {
418
418
  case 'array':
419
419
  return getPreviewArray(item);
@@ -429,7 +429,7 @@ const validate = (item, schema) => {
429
429
  if (typeof schema === 'function') {
430
430
  return schema(item);
431
431
  }
432
- const actualType = getType(item);
432
+ const actualType = getType$1(item);
433
433
  const expectedType = schema.type;
434
434
  if (actualType !== expectedType) {
435
435
  if (schema.allowUndefined && (item === undefined || item === null)) {
@@ -3309,8 +3309,8 @@ const getStatusBarItems2 = async () => {
3309
3309
  }
3310
3310
  const values = Object.values(providers);
3311
3311
  for (const provider of values) {
3312
- if (provider && provider.getStatusBarItem) {
3313
- const item = provider.getStatusBarItem();
3312
+ if (provider) {
3313
+ const item = getValidatedStatusBarItem(provider);
3314
3314
  if (item) {
3315
3315
  statusBarItems.push(item);
3316
3316
  }
@@ -3334,9 +3334,53 @@ const getStatusBarItemProviderDisplay = provider => {
3334
3334
  const notifyChange = async id => {
3335
3335
  await invoke$1('StatusBar.handleChange', id);
3336
3336
  };
3337
+ const getType = value => {
3338
+ if (value === null) {
3339
+ return 'null';
3340
+ }
3341
+ if (Array.isArray(value)) {
3342
+ return 'array';
3343
+ }
3344
+ return typeof value;
3345
+ };
3346
+ const validateStatusBarItem = item => {
3347
+ if (!item || typeof item !== 'object') {
3348
+ throw new Error(`status bar item must be an object, got ${getType(item)}`);
3349
+ }
3350
+ if ('text' in item && typeof item.text !== 'string') {
3351
+ throw new Error(`status bar item.text must be a string, got ${getType(item.text)}`);
3352
+ }
3353
+ if ('name' in item && typeof item.name !== 'string') {
3354
+ throw new Error(`status bar item.name must be a string, got ${getType(item.name)}`);
3355
+ }
3356
+ };
3357
+ const getErrorStatusBarItem = title => {
3358
+ return {
3359
+ icon: '',
3360
+ name: 'error',
3361
+ onClick: '',
3362
+ text: 'error',
3363
+ title
3364
+ };
3365
+ };
3366
+ const getValidatedStatusBarItem = provider => {
3367
+ try {
3368
+ const item = provider.getStatusBarItem();
3369
+ if (!item) {
3370
+ return item;
3371
+ }
3372
+ validateStatusBarItem(item);
3373
+ return item;
3374
+ } catch (error) {
3375
+ const providerDisplay = getStatusBarItemProviderDisplay(provider);
3376
+ const wrappedError = new VError(error, `Failed to execute status bar item provider${providerDisplay}`);
3377
+ console.error(wrappedError);
3378
+ return getErrorStatusBarItem(wrappedError.message);
3379
+ }
3380
+ };
3337
3381
  const executeStatusBarItemProvider = id => {
3338
3382
  const provider = providers[id];
3339
- return provider.getStatusBarItem();
3383
+ return getValidatedStatusBarItem(provider);
3340
3384
  };
3341
3385
  const registerStatuBarItemProvider = provider => {
3342
3386
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-host-worker",
3
- "version": "8.12.0",
3
+ "version": "8.13.0",
4
4
  "description": "Webworker for the extension host functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"