@lvce-editor/shared-process 0.20.11 → 0.20.13
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/package.json +5 -4
- package/src/parts/Callback/Callback.js +1 -26
- package/src/parts/GetResponse/GetResponse.js +2 -2
- package/src/parts/HandleIpc/HandleIpc.js +15 -2
- package/src/parts/JsonRpc/JsonRpc.js +1 -24
- package/src/parts/OutputChannel/OutputChannel.ipc.js +1 -1
- package/src/parts/Platform/Platform.js +3 -3
- package/src/parts/Terminal/Terminal.js +1 -1
- package/src/parts/GetErrorResponse/GetErrorResponse.js +0 -48
- package/src/parts/HandleJsonRpcMessage/HandleJsonRpcMessage.js +0 -25
- package/src/parts/JsonRpcError/JsonRpcError.js +0 -6
- package/src/parts/JsonRpcErrorCode/JsonRpcErrorCode.js +0 -2
- package/src/parts/JsonRpcErrorResponse/JsonRpcErrorResponse.js +0 -9
- package/src/parts/JsonRpcEvent/JsonRpcEvent.js +0 -9
- package/src/parts/JsonRpcRequest/JsonRpcRequest.js +0 -16
- package/src/parts/JsonRpcSuccessResponse/JsonSuccessResponse.js +0 -9
- package/src/parts/RestoreJsonRpcError/RestoreJsonRpcError.js +0 -79
- package/src/parts/UnwrapJsonRpcResult/UnwrapJsonRpcResult.js +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/shared-process",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.13",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/code-frame": "^7.23.5",
|
|
21
|
-
"@lvce-editor/extension-host": "0.20.
|
|
22
|
-
"@lvce-editor/extension-host-helper-process": "0.20.
|
|
21
|
+
"@lvce-editor/extension-host": "0.20.13",
|
|
22
|
+
"@lvce-editor/extension-host-helper-process": "0.20.13",
|
|
23
|
+
"@lvce-editor/json-rpc": "^0.4.0",
|
|
23
24
|
"@lvce-editor/jsonc-parser": "^1.1.0",
|
|
24
25
|
"@lvce-editor/pretty-error": "^1.2.2",
|
|
25
|
-
"@lvce-editor/pty-host": "0.20.
|
|
26
|
+
"@lvce-editor/pty-host": "0.20.13",
|
|
26
27
|
"@lvce-editor/verror": "^1.1.2",
|
|
27
28
|
"debug": "^4.3.4",
|
|
28
29
|
"execa": "^8.0.1",
|
|
@@ -1,26 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import * as Id from '../Id/Id.js'
|
|
3
|
-
import * as Logger from '../Logger/Logger.js'
|
|
4
|
-
import * as Promises from '../Promises/Promises.js'
|
|
5
|
-
|
|
6
|
-
export const state = {
|
|
7
|
-
callbacks: Object.create(null),
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const registerPromise = () => {
|
|
11
|
-
const id = Id.create()
|
|
12
|
-
const { resolve, promise } = Promises.withResolvers()
|
|
13
|
-
state.callbacks[id] = resolve
|
|
14
|
-
return { id, promise }
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const resolve = (id, args) => {
|
|
18
|
-
Assert.number(id)
|
|
19
|
-
if (!(id in state.callbacks)) {
|
|
20
|
-
console.log(args)
|
|
21
|
-
Logger.warn(`callback ${id} may already be disposed`)
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
state.callbacks[id](args)
|
|
25
|
-
delete state.callbacks[id]
|
|
26
|
-
}
|
|
1
|
+
export { resolve } from '@lvce-editor/json-rpc'
|
|
@@ -2,13 +2,13 @@ import * as GetErrorResponse from '../GetErrorResponse/GetErrorResponse.js'
|
|
|
2
2
|
import * as GetSuccessResponse from '../GetSuccessResponse/GetSuccessResponse.js'
|
|
3
3
|
import * as RequiresSocket from '../RequiresSocket/RequiresSocket.js'
|
|
4
4
|
|
|
5
|
-
export const getResponse = async (message, ipc, execute) => {
|
|
5
|
+
export const getResponse = async (message, ipc, execute, preparePrettyError, logError) => {
|
|
6
6
|
try {
|
|
7
7
|
const result = RequiresSocket.requiresSocket(message.method)
|
|
8
8
|
? await execute(message.method, ipc, ...message.params)
|
|
9
9
|
: await execute(message.method, ...message.params)
|
|
10
10
|
return GetSuccessResponse.getSuccessResponse(message, result)
|
|
11
11
|
} catch (error) {
|
|
12
|
-
return GetErrorResponse.getErrorResponse(message, error, ipc)
|
|
12
|
+
return GetErrorResponse.getErrorResponse(message, error, ipc, preparePrettyError, logError)
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import * as Callback from '../Callback/Callback.js'
|
|
2
2
|
import * as Command from '../Command/Command.js'
|
|
3
|
-
import * as
|
|
3
|
+
import * as JsonRpc from '../JsonRpc/JsonRpc.js'
|
|
4
|
+
import * as PrettyError from '../PrettyError/PrettyError.js'
|
|
5
|
+
import * as PrintPrettyError from '../PrintPrettyError/PrintPrettyError.js'
|
|
6
|
+
import * as RequiresSocket from '../RequiresSocket/RequiresSocket.js'
|
|
7
|
+
import * as ShouldLogError from '../ShouldLogError/ShouldLogError.js'
|
|
8
|
+
|
|
9
|
+
const preparePrettyError = PrettyError.prepare
|
|
10
|
+
|
|
11
|
+
const logError = (error, prettyError) => {
|
|
12
|
+
if (ShouldLogError.shouldLogError(error)) {
|
|
13
|
+
PrintPrettyError.printPrettyError(prettyError, `[shared-process] `)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
4
16
|
|
|
5
17
|
export const handleIpc = (ipc) => {
|
|
6
18
|
const handleMessage = (message) => {
|
|
7
|
-
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
return JsonRpc.handleJsonRpcMessage(ipc, message, Command.execute, Callback.resolve, preparePrettyError, logError, RequiresSocket.requiresSocket)
|
|
8
21
|
}
|
|
9
22
|
ipc.on('message', handleMessage)
|
|
10
23
|
}
|
|
@@ -1,24 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import * as JsonRpcRequest from '../JsonRpcRequest/JsonRpcRequest.js'
|
|
3
|
-
import * as UnwrapJsonRpcResult from '../UnwrapJsonRpcResult/UnwrapJsonRpcResult.js'
|
|
4
|
-
|
|
5
|
-
export const send = (transport, method, ...params) => {
|
|
6
|
-
const message = JsonRpcEvent.create(method, params)
|
|
7
|
-
transport.send(message)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const invoke = async (ipc, method, ...params) => {
|
|
11
|
-
const { message, promise } = JsonRpcRequest.create(method, params)
|
|
12
|
-
ipc.send(message)
|
|
13
|
-
const responseMessage = await promise
|
|
14
|
-
const result = UnwrapJsonRpcResult.unwrapJsonRpcResult(responseMessage)
|
|
15
|
-
return result
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const invokeAndTransfer = async (ipc, handle, method, ...params) => {
|
|
19
|
-
const { message, promise } = JsonRpcRequest.create(method, params)
|
|
20
|
-
ipc.sendAndTransfer(message, handle)
|
|
21
|
-
const responseMessage = await promise
|
|
22
|
-
const result = UnwrapJsonRpcResult.unwrapJsonRpcResult(responseMessage)
|
|
23
|
-
return result
|
|
24
|
-
}
|
|
1
|
+
export * from '@lvce-editor/json-rpc'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Assert from '../Assert/Assert.js'
|
|
2
|
-
import
|
|
2
|
+
import { JsonRpcEvent } from '../JsonRpc/JsonRpc.js'
|
|
3
3
|
import * as OutputChannelState from '../OutputChannelState/OutputChannelState.js'
|
|
4
4
|
import * as OutputChannel from './OutputChannel.js'
|
|
5
5
|
|
|
@@ -51,11 +51,11 @@ export const getSetupName = () => {
|
|
|
51
51
|
return 'Lvce-Setup'
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
export const version = '0.20.
|
|
54
|
+
export const version = '0.20.13'
|
|
55
55
|
|
|
56
|
-
export const commit = '
|
|
56
|
+
export const commit = '82b9796'
|
|
57
57
|
|
|
58
|
-
export const date = '2023-12-
|
|
58
|
+
export const date = '2023-12-04T22:27:58.000Z'
|
|
59
59
|
|
|
60
60
|
export const getVersion = () => {
|
|
61
61
|
return version
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Assert from '../Assert/Assert.js'
|
|
2
|
-
import
|
|
2
|
+
import { JsonRpcEvent } from '../JsonRpc/JsonRpc.js'
|
|
3
3
|
import * as PtyHost from '../PtyHost/PtyHost.js'
|
|
4
4
|
import * as TerminalState from '../TerminalState/TerminalState.js'
|
|
5
5
|
import { VError } from '../VError/VError.js'
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { CommandNotFoundError } from '../CommandNotFoundError/CommandNotFoundError.js'
|
|
2
|
-
import * as ErrorCodes from '../ErrorCodes/ErrorCodes.js'
|
|
3
|
-
import * as JsonRpcErrorCode from '../JsonRpcErrorCode/JsonRpcErrorCode.js'
|
|
4
|
-
import * as JsonRpcErrorResponse from '../JsonRpcErrorResponse/JsonRpcErrorResponse.js'
|
|
5
|
-
import * as PrettyError from '../PrettyError/PrettyError.js'
|
|
6
|
-
import * as PrintPrettyError from '../PrintPrettyError/PrintPrettyError.js'
|
|
7
|
-
import * as ShouldLogError from '../ShouldLogError/ShouldLogError.js'
|
|
8
|
-
|
|
9
|
-
const getErrorProperty = (error, prettyError) => {
|
|
10
|
-
if (error && error instanceof CommandNotFoundError) {
|
|
11
|
-
return {
|
|
12
|
-
code: JsonRpcErrorCode.MethodNotFound,
|
|
13
|
-
message: error.message,
|
|
14
|
-
data: error.stack,
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (!ShouldLogError.shouldLogError(error)) {
|
|
18
|
-
return {
|
|
19
|
-
code: JsonRpcErrorCode.Custom,
|
|
20
|
-
message: `${error}`,
|
|
21
|
-
data: {
|
|
22
|
-
stack: prettyError.stack,
|
|
23
|
-
codeFrame: prettyError.codeFrame,
|
|
24
|
-
type: prettyError.type,
|
|
25
|
-
code: prettyError.code,
|
|
26
|
-
},
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
code: JsonRpcErrorCode.Custom,
|
|
31
|
-
message: prettyError.message,
|
|
32
|
-
data: {
|
|
33
|
-
stack: prettyError.stack,
|
|
34
|
-
codeFrame: prettyError.codeFrame,
|
|
35
|
-
type: prettyError.type,
|
|
36
|
-
code: prettyError.code,
|
|
37
|
-
},
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const getErrorResponse = (message, error, ipc) => {
|
|
42
|
-
const prettyError = PrettyError.prepare(error)
|
|
43
|
-
if (ShouldLogError.shouldLogError(error)) {
|
|
44
|
-
PrintPrettyError.printPrettyError(prettyError, `[shared-process] `)
|
|
45
|
-
}
|
|
46
|
-
const errorProperty = getErrorProperty(error, prettyError)
|
|
47
|
-
return JsonRpcErrorResponse.create(message, errorProperty)
|
|
48
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as GetErrorResponse from '../GetErrorResponse/GetErrorResponse.js'
|
|
2
|
-
import * as GetResponse from '../GetResponse/GetResponse.js'
|
|
3
|
-
import { JsonRpcError } from '../JsonRpcError/JsonRpcError.js'
|
|
4
|
-
|
|
5
|
-
export const handleJsonRpcMessage = async (ipc, message, execute, resolve) => {
|
|
6
|
-
if ('id' in message) {
|
|
7
|
-
if ('method' in message) {
|
|
8
|
-
const response = await GetResponse.getResponse(message, ipc, execute)
|
|
9
|
-
try {
|
|
10
|
-
ipc.send(response)
|
|
11
|
-
} catch (error) {
|
|
12
|
-
const errorResponse = GetErrorResponse.getErrorResponse(message, error)
|
|
13
|
-
ipc.send(errorResponse)
|
|
14
|
-
}
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
resolve(message.id, message)
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
if ('method' in message) {
|
|
21
|
-
await GetResponse.getResponse(message, ipc, execute)
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
throw new JsonRpcError('unexpected message')
|
|
25
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as Callback from '../Callback/Callback.js'
|
|
2
|
-
import * as JsonRpcVersion from '../JsonRpcVersion/JsonRpcVersion.js'
|
|
3
|
-
|
|
4
|
-
export const create = (method, params) => {
|
|
5
|
-
const { id, promise } = Callback.registerPromise()
|
|
6
|
-
const message = {
|
|
7
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
8
|
-
method,
|
|
9
|
-
params,
|
|
10
|
-
id,
|
|
11
|
-
}
|
|
12
|
-
return {
|
|
13
|
-
message,
|
|
14
|
-
promise,
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import * as Character from '../Character/Character.js'
|
|
2
|
-
import * as GetErrorConstructor from '../GetErrorConstructor/GetErrorConstructor.js'
|
|
3
|
-
import * as JoinLines from '../JoinLines/JoinLines.js'
|
|
4
|
-
import { JsonRpcError } from '../JsonRpcError/JsonRpcError.js'
|
|
5
|
-
import * as JsonRpcErrorCode from '../JsonRpcErrorCode/JsonRpcErrorCode.js'
|
|
6
|
-
import * as SplitLines from '../SplitLines/SplitLines.js'
|
|
7
|
-
|
|
8
|
-
const constructError = (message, type, name) => {
|
|
9
|
-
const ErrorConstructor = GetErrorConstructor.getErrorConstructor(message, type)
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
if (ErrorConstructor === DOMException && name) {
|
|
12
|
-
return new ErrorConstructor(message, name)
|
|
13
|
-
}
|
|
14
|
-
if (ErrorConstructor === Error) {
|
|
15
|
-
const error = new Error(message)
|
|
16
|
-
if (name && name !== 'VError') {
|
|
17
|
-
error.name = name
|
|
18
|
-
}
|
|
19
|
-
return error
|
|
20
|
-
}
|
|
21
|
-
return new ErrorConstructor(message)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const recreateStack = (message, stack) => {
|
|
25
|
-
if (message && !stack.includes(message)) {
|
|
26
|
-
return message + Character.NewLine + stack
|
|
27
|
-
}
|
|
28
|
-
return stack
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const getErrorType = (error) => {
|
|
32
|
-
if (error && error.type) {
|
|
33
|
-
return error.type
|
|
34
|
-
}
|
|
35
|
-
if (error && error.data && error.data.type) {
|
|
36
|
-
return error.data.type
|
|
37
|
-
}
|
|
38
|
-
return ''
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const restoreJsonRpcError = (error) => {
|
|
42
|
-
if (error && error instanceof Error) {
|
|
43
|
-
return error
|
|
44
|
-
}
|
|
45
|
-
if (error && error.code && error.code === JsonRpcErrorCode.MethodNotFound) {
|
|
46
|
-
const restoredError = new JsonRpcError(error.message)
|
|
47
|
-
restoredError.stack = error.stack || error.data || ''
|
|
48
|
-
return restoredError
|
|
49
|
-
}
|
|
50
|
-
if (error && error.message) {
|
|
51
|
-
const type = getErrorType(error)
|
|
52
|
-
const restoredError = constructError(error.message, type, error.name)
|
|
53
|
-
const currentStack = JoinLines.joinLines(SplitLines.splitLines(new Error().stack).slice(1))
|
|
54
|
-
if (error.data) {
|
|
55
|
-
if (error.data.stack && type && error.message) {
|
|
56
|
-
restoredError.stack = type + ': ' + error.message + Character.NewLine + error.data.stack + Character.NewLine + currentStack
|
|
57
|
-
} else if (error.data.stack) {
|
|
58
|
-
restoredError.stack = recreateStack(error.message, error.data.stack) + Character.NewLine + currentStack
|
|
59
|
-
}
|
|
60
|
-
if (error.data.codeFrame) {
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
restoredError.codeFrame = error.data.codeFrame
|
|
63
|
-
}
|
|
64
|
-
if (error.data.code) {
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
restoredError.code = error.data.code
|
|
67
|
-
}
|
|
68
|
-
} else if (error.stack) {
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
restoredError.stack = recreateStack(error.message, error.stack) + Character.NewLine + currentStack
|
|
71
|
-
}
|
|
72
|
-
return restoredError
|
|
73
|
-
}
|
|
74
|
-
if (typeof error === 'string') {
|
|
75
|
-
return new Error(`JsonRpc Error: ${error}`)
|
|
76
|
-
}
|
|
77
|
-
console.log({ error })
|
|
78
|
-
return new Error(`JsonRpc Error: Unknown Error`)
|
|
79
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { JsonRpcError } from '../JsonRpcError/JsonRpcError.js'
|
|
2
|
-
import * as RestoreJsonRpcError from '../RestoreJsonRpcError/RestoreJsonRpcError.js'
|
|
3
|
-
|
|
4
|
-
export const unwrapJsonRpcResult = (responseMessage) => {
|
|
5
|
-
if ('error' in responseMessage) {
|
|
6
|
-
const restoredError = RestoreJsonRpcError.restoreJsonRpcError(responseMessage.error)
|
|
7
|
-
throw restoredError
|
|
8
|
-
}
|
|
9
|
-
if ('result' in responseMessage) {
|
|
10
|
-
return responseMessage.result
|
|
11
|
-
}
|
|
12
|
-
throw new JsonRpcError('unexpected response message')
|
|
13
|
-
}
|