@lvce-editor/json-rpc 4.2.0 → 5.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.
- package/dist/index.js +6 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ class AssertionError extends Error {
|
|
|
19
19
|
this.name = 'AssertionError';
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
const getType
|
|
22
|
+
const getType = value => {
|
|
23
23
|
switch (typeof value) {
|
|
24
24
|
case 'number':
|
|
25
25
|
return 'number';
|
|
@@ -42,7 +42,7 @@ const getType$1 = value => {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
const number = value => {
|
|
45
|
-
const type = getType
|
|
45
|
+
const type = getType(value);
|
|
46
46
|
if (type !== 'number') {
|
|
47
47
|
throw new AssertionError('expected value to be of type number');
|
|
48
48
|
}
|
|
@@ -72,26 +72,12 @@ const warn = (...args) => {
|
|
|
72
72
|
console.warn(...args);
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
-
const withResolvers = () => {
|
|
76
|
-
/**
|
|
77
|
-
* @type {any}
|
|
78
|
-
*/
|
|
79
|
-
let _resolve;
|
|
80
|
-
const promise = new Promise(resolve => {
|
|
81
|
-
_resolve = resolve;
|
|
82
|
-
});
|
|
83
|
-
return {
|
|
84
|
-
resolve: _resolve,
|
|
85
|
-
promise
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
|
|
89
75
|
const registerPromise = () => {
|
|
90
76
|
const id = create$3();
|
|
91
77
|
const {
|
|
92
78
|
resolve,
|
|
93
79
|
promise
|
|
94
|
-
} = withResolvers();
|
|
80
|
+
} = Promise.withResolvers();
|
|
95
81
|
set(id, resolve);
|
|
96
82
|
return {
|
|
97
83
|
id,
|
|
@@ -277,7 +263,7 @@ const unwrapJsonRpcResult = responseMessage => {
|
|
|
277
263
|
|
|
278
264
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
279
265
|
|
|
280
|
-
const
|
|
266
|
+
const getErrorType = prettyError => {
|
|
281
267
|
if (prettyError && prettyError.type) {
|
|
282
268
|
return prettyError.type;
|
|
283
269
|
}
|
|
@@ -286,6 +272,7 @@ const getType = prettyError => {
|
|
|
286
272
|
}
|
|
287
273
|
return undefined;
|
|
288
274
|
};
|
|
275
|
+
|
|
289
276
|
const getErrorProperty = (error, prettyError) => {
|
|
290
277
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
291
278
|
return {
|
|
@@ -300,7 +287,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
300
287
|
data: {
|
|
301
288
|
stack: prettyError.stack,
|
|
302
289
|
codeFrame: prettyError.codeFrame,
|
|
303
|
-
type:
|
|
290
|
+
type: getErrorType(prettyError),
|
|
304
291
|
code: prettyError.code,
|
|
305
292
|
name: prettyError.name
|
|
306
293
|
}
|