@lvce-editor/pty-host 0.20.10 → 0.20.12
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 +2 -1
- package/src/parts/Callback/Callback.js +1 -42
- package/src/parts/HandleIpc/HandleIpc.js +12 -2
- package/src/parts/JsonRpc/JsonRpc.js +1 -0
- package/src/parts/Promises/Promises.js +19 -0
- package/src/parts/PtyController/PtyController.js +1 -1
- package/src/parts/GetErrorResponse/GetErrorResponse.js +0 -56
- package/src/parts/GetResponse/GetResponse.js +0 -14
- package/src/parts/GetSuccessResponse/GetSuccessResponse.js +0 -12
- package/src/parts/HandleJsonRpcMessage/HandleJsonRpcMessage.js +0 -12
- package/src/parts/JsonRpcErrorCode/JsonRpcErrorCode.js +0 -2
- package/src/parts/JsonRpcEvent/JsonRpcEvent.js +0 -9
- package/src/parts/JsonRpcRequest/JsonRpcRequest.js +0 -16
- package/src/parts/JsonRpcVersion/JsonRpcVersion.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/pty-host",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"node": ">=16"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"@lvce-editor/json-rpc": "^0.3.0",
|
|
19
20
|
"@lvce-editor/pretty-error": "^1.2.2",
|
|
20
21
|
"@lvce-editor/verror": "^1.1.2",
|
|
21
22
|
"debug": "^4.3.4",
|
|
@@ -1,42 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import * as Id from '../Id/Id.js'
|
|
3
|
-
|
|
4
|
-
export const state = {
|
|
5
|
-
callbacks: Object.create(null),
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const registerPromise = () => {
|
|
9
|
-
const id = Id.create()
|
|
10
|
-
const promise = new Promise((resolve, reject) => {
|
|
11
|
-
state.callbacks[id] = {
|
|
12
|
-
resolve,
|
|
13
|
-
reject,
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
return { id, promise }
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const unregister = (id) => {
|
|
20
|
-
delete state.callbacks[id]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const resolve = (id, args) => {
|
|
24
|
-
Assert.number(id)
|
|
25
|
-
if (!(id in state.callbacks)) {
|
|
26
|
-
console.log(args)
|
|
27
|
-
console.warn(`callback ${id} may already be disposed`)
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
state.callbacks[id].resolve(args)
|
|
31
|
-
delete state.callbacks[id]
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const reject = (id, error) => {
|
|
35
|
-
Assert.number(id)
|
|
36
|
-
if (!(id in state.callbacks)) {
|
|
37
|
-
console.warn(`callback ${id} may already be disposed`)
|
|
38
|
-
return
|
|
39
|
-
}
|
|
40
|
-
state.callbacks[id].reject(error)
|
|
41
|
-
delete state.callbacks[id]
|
|
42
|
-
}
|
|
1
|
+
export { resolve } from '@lvce-editor/json-rpc'
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import * as Assert from '../Assert/Assert.js'
|
|
2
2
|
import * as Callback from '../Callback/Callback.js'
|
|
3
3
|
import * as Command from '../Command/Command.js'
|
|
4
|
-
import * as
|
|
4
|
+
import * as JsonRpc from '../JsonRpc/JsonRpc.js'
|
|
5
|
+
import * as PrettyError from '../PrettyError/PrettyError.js'
|
|
6
|
+
import * as PrintPrettyError from '../PrintPrettyError/PrintPrettyError.js'
|
|
7
|
+
import * as RequiresSocket from '../RequiresSocket/RequiresSocket.js'
|
|
8
|
+
|
|
9
|
+
const preparePrettyError = PrettyError.prepare
|
|
10
|
+
|
|
11
|
+
const logError = (error, prettyError) => {
|
|
12
|
+
PrintPrettyError.printPrettyError(prettyError, `[terminal-process] `)
|
|
13
|
+
}
|
|
5
14
|
|
|
6
15
|
export const handleIpc = (ipc) => {
|
|
7
16
|
Assert.object(ipc)
|
|
8
17
|
const handleMessage = (message) => {
|
|
9
|
-
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
return JsonRpc.handleJsonRpcMessage(ipc, message, Command.execute, Callback.resolve, preparePrettyError, logError, RequiresSocket.requiresSocket)
|
|
10
20
|
}
|
|
11
21
|
ipc.on('message', handleMessage)
|
|
12
22
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@lvce-editor/json-rpc'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const withResolvers = () => {
|
|
2
|
+
/**
|
|
3
|
+
* @type {any}
|
|
4
|
+
*/
|
|
5
|
+
let _resolve
|
|
6
|
+
/**
|
|
7
|
+
* @type {any}
|
|
8
|
+
*/
|
|
9
|
+
let _reject
|
|
10
|
+
const promise = new Promise((resolve, reject) => {
|
|
11
|
+
_resolve = resolve
|
|
12
|
+
_reject = reject
|
|
13
|
+
})
|
|
14
|
+
return {
|
|
15
|
+
resolve: _resolve,
|
|
16
|
+
reject: _reject,
|
|
17
|
+
promise,
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,56 +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 JsonRpcVersion from '../JsonRpcVersion/JsonRpcVersion.js'
|
|
5
|
-
import * as PrettyError from '../PrettyError/PrettyError.js'
|
|
6
|
-
import * as PrintPrettyError from '../PrintPrettyError/PrintPrettyError.js'
|
|
7
|
-
|
|
8
|
-
const shouldLogError = (error) => {
|
|
9
|
-
if (error && error.code === ErrorCodes.ENOENT) {
|
|
10
|
-
return false
|
|
11
|
-
}
|
|
12
|
-
return true
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const getErrorResponse = (message, error) => {
|
|
16
|
-
if (error && error instanceof CommandNotFoundError) {
|
|
17
|
-
return {
|
|
18
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
19
|
-
id: message.id,
|
|
20
|
-
error: {
|
|
21
|
-
code: JsonRpcErrorCode.MethodNotFound,
|
|
22
|
-
message: error.message,
|
|
23
|
-
data: error.stack,
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (!shouldLogError(error)) {
|
|
28
|
-
return {
|
|
29
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
30
|
-
id: message.id,
|
|
31
|
-
error: {
|
|
32
|
-
code: JsonRpcErrorCode.Custom,
|
|
33
|
-
message: `${error}`,
|
|
34
|
-
data: {
|
|
35
|
-
code: error.code,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const prettyError = PrettyError.prepare(error)
|
|
41
|
-
PrintPrettyError.printPrettyError(prettyError, `[terminal-process] `)
|
|
42
|
-
return {
|
|
43
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
44
|
-
id: message.id,
|
|
45
|
-
error: {
|
|
46
|
-
code: JsonRpcErrorCode.Custom,
|
|
47
|
-
message: prettyError.message,
|
|
48
|
-
data: {
|
|
49
|
-
stack: prettyError.stack,
|
|
50
|
-
codeFrame: prettyError.codeFrame,
|
|
51
|
-
type: prettyError.type,
|
|
52
|
-
code: prettyError.code,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as GetErrorResponse from '../GetErrorResponse/GetErrorResponse.js'
|
|
2
|
-
import * as GetSuccessResponse from '../GetSuccessResponse/GetSuccessResponse.js'
|
|
3
|
-
import * as RequiresSocket from '../RequiresSocket/RequiresSocket.js'
|
|
4
|
-
|
|
5
|
-
export const getResponse = async (message, execute, handle) => {
|
|
6
|
-
try {
|
|
7
|
-
const result = RequiresSocket.requiresSocket(message.method)
|
|
8
|
-
? await execute(message.method, ...message.params, handle)
|
|
9
|
-
: await execute(message.method, ...message.params)
|
|
10
|
-
return GetSuccessResponse.getSuccessResponse(message, result)
|
|
11
|
-
} catch (error) {
|
|
12
|
-
return GetErrorResponse.getErrorResponse(message, error)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as JsonRpcVersion from '../JsonRpcVersion/JsonRpcVersion.js'
|
|
2
|
-
|
|
3
|
-
export const getSuccessResponse = (message, result) => {
|
|
4
|
-
if (!message.id) {
|
|
5
|
-
return undefined
|
|
6
|
-
}
|
|
7
|
-
return {
|
|
8
|
-
jsonrpc: JsonRpcVersion.Two,
|
|
9
|
-
id: message.id,
|
|
10
|
-
result: result ?? null,
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as GetResponse from '../GetResponse/GetResponse.js'
|
|
2
|
-
|
|
3
|
-
export const handleJsonRpcMessage = async (ipc, message, execute, resolve) => {
|
|
4
|
-
if ('result' in message || 'error' in message) {
|
|
5
|
-
resolve(message.id, message)
|
|
6
|
-
return
|
|
7
|
-
}
|
|
8
|
-
const response = await GetResponse.getResponse(message, execute, ipc)
|
|
9
|
-
if ('id' in message) {
|
|
10
|
-
ipc.send(response)
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -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 +0,0 @@
|
|
|
1
|
-
export const Two = '2.0'
|