@lvce-editor/json-rpc 3.0.0 → 4.1.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.d.ts +5 -6
- package/dist/index.js +24 -20
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -6,12 +6,11 @@ export const invoke: (
|
|
|
6
6
|
...params: any[]
|
|
7
7
|
) => Promise<any>
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const invokeAndTransfer: InvokeAndTransfer
|
|
9
|
+
export const invokeAndTransfer: (
|
|
10
|
+
ipc: any,
|
|
11
|
+
method: string,
|
|
12
|
+
...params: any[]
|
|
13
|
+
) => Promise<any>
|
|
15
14
|
|
|
16
15
|
export const resolve: (id: number, message: any) => void
|
|
17
16
|
|
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 = value => {
|
|
22
|
+
const getType$1 = value => {
|
|
23
23
|
switch (typeof value) {
|
|
24
24
|
case 'number':
|
|
25
25
|
return 'number';
|
|
@@ -42,7 +42,7 @@ const getType = value => {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
const number = value => {
|
|
45
|
-
const type = getType(value);
|
|
45
|
+
const type = getType$1(value);
|
|
46
46
|
if (type !== 'number') {
|
|
47
47
|
throw new AssertionError('expected value to be of type number');
|
|
48
48
|
}
|
|
@@ -275,16 +275,17 @@ const unwrapJsonRpcResult = responseMessage => {
|
|
|
275
275
|
throw new JsonRpcError('unexpected response message');
|
|
276
276
|
};
|
|
277
277
|
|
|
278
|
-
const create$1 = (message, error) => {
|
|
279
|
-
return {
|
|
280
|
-
jsonrpc: Two,
|
|
281
|
-
id: message.id,
|
|
282
|
-
error
|
|
283
|
-
};
|
|
284
|
-
};
|
|
285
|
-
|
|
286
278
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
287
279
|
|
|
280
|
+
const getType = prettyError => {
|
|
281
|
+
if (prettyError && prettyError.type) {
|
|
282
|
+
return prettyError.type;
|
|
283
|
+
}
|
|
284
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
285
|
+
return prettyError.constructor.name;
|
|
286
|
+
}
|
|
287
|
+
return undefined;
|
|
288
|
+
};
|
|
288
289
|
const getErrorProperty = (error, prettyError) => {
|
|
289
290
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
290
291
|
return {
|
|
@@ -299,11 +300,21 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
299
300
|
data: {
|
|
300
301
|
stack: prettyError.stack,
|
|
301
302
|
codeFrame: prettyError.codeFrame,
|
|
302
|
-
type: prettyError
|
|
303
|
-
code: prettyError.code
|
|
303
|
+
type: getType(prettyError),
|
|
304
|
+
code: prettyError.code,
|
|
305
|
+
name: prettyError.name
|
|
304
306
|
}
|
|
305
307
|
};
|
|
306
308
|
};
|
|
309
|
+
|
|
310
|
+
const create$1 = (message, error) => {
|
|
311
|
+
return {
|
|
312
|
+
jsonrpc: Two,
|
|
313
|
+
id: message.id,
|
|
314
|
+
error
|
|
315
|
+
};
|
|
316
|
+
};
|
|
317
|
+
|
|
307
318
|
const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
308
319
|
const prettyError = preparePrettyError(error);
|
|
309
320
|
logError(error, prettyError);
|
|
@@ -404,14 +415,7 @@ const invoke = async (ipc, method, ...params) => {
|
|
|
404
415
|
const result = unwrapJsonRpcResult(responseMessage);
|
|
405
416
|
return result;
|
|
406
417
|
};
|
|
407
|
-
|
|
408
|
-
// TODO deprecated old typings,
|
|
409
|
-
// always use automatic transferrable detection
|
|
410
|
-
const invokeAndTransfer = async (ipc, handle, method, ...params) => {
|
|
411
|
-
if (typeof handle === 'string') {
|
|
412
|
-
params = [method, ...params];
|
|
413
|
-
method = handle;
|
|
414
|
-
}
|
|
418
|
+
const invokeAndTransfer = async (ipc, method, ...params) => {
|
|
415
419
|
const {
|
|
416
420
|
message,
|
|
417
421
|
promise
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/json-rpc",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "JsonRpc implementation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
"author": "Lvce Editor",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@lvce-editor/assert": "^1.
|
|
14
|
+
"@lvce-editor/assert": "^1.3.0"
|
|
15
15
|
}
|
|
16
16
|
}
|