@deltachat/stdio-rpc-server 2.48.0 → 2.49.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/README.md +1 -1
- package/index.d.ts +10 -3
- package/index.js +42 -34
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ import { startDeltaChat } from "@deltachat/stdio-rpc-server";
|
|
|
18
18
|
import { C } from "@deltachat/jsonrpc-client";
|
|
19
19
|
|
|
20
20
|
async function main() {
|
|
21
|
-
const dc =
|
|
21
|
+
const dc = startDeltaChat("deltachat-data");
|
|
22
22
|
console.log(await dc.rpc.getSystemInfo());
|
|
23
23
|
dc.close()
|
|
24
24
|
}
|
package/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface SearchOptions {
|
|
|
15
15
|
*/
|
|
16
16
|
export function getRPCServerPath(
|
|
17
17
|
options?: Partial<SearchOptions>
|
|
18
|
-
):
|
|
18
|
+
): string;
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
@@ -33,8 +33,15 @@ export interface StartOptions {
|
|
|
33
33
|
* @param directory directory for accounts folder
|
|
34
34
|
* @param options
|
|
35
35
|
*/
|
|
36
|
-
export function startDeltaChat(directory: string, options?: Partial<SearchOptions & StartOptions> ):
|
|
37
|
-
|
|
36
|
+
export function startDeltaChat(directory: string, options?: Partial<SearchOptions & StartOptions> ): DeltaChatOverJsonRpcServer
|
|
37
|
+
|
|
38
|
+
export class DeltaChatOverJsonRpc extends StdioDeltaChat {
|
|
39
|
+
constructor(
|
|
40
|
+
directory: string,
|
|
41
|
+
options?: Partial<SearchOptions & StartOptions>
|
|
42
|
+
);
|
|
43
|
+
readonly pathToServerBinary: string;
|
|
44
|
+
}
|
|
38
45
|
|
|
39
46
|
export namespace FnTypes {
|
|
40
47
|
export type getRPCServerPath = typeof getRPCServerPath
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//@ts-check
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
|
-
import {
|
|
3
|
+
import { statSync } from "node:fs";
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { ENV_VAR_NAME, PATH_EXECUTABLE_NAME } from "./src/const.js";
|
|
@@ -36,7 +36,7 @@ function findRPCServerInNodeModules() {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/** @type {import("./index").FnTypes.getRPCServerPath} */
|
|
39
|
-
export
|
|
39
|
+
export function getRPCServerPath(options = {}) {
|
|
40
40
|
const { takeVersionFromPATH, disableEnvPath } = {
|
|
41
41
|
takeVersionFromPATH: false,
|
|
42
42
|
disableEnvPath: false,
|
|
@@ -45,7 +45,7 @@ export async function getRPCServerPath(options = {}) {
|
|
|
45
45
|
// 1. check if it is set as env var
|
|
46
46
|
if (process.env[ENV_VAR_NAME] && !disableEnvPath) {
|
|
47
47
|
try {
|
|
48
|
-
if (!(
|
|
48
|
+
if (!statSync(process.env[ENV_VAR_NAME]).isFile()) {
|
|
49
49
|
throw new Error(
|
|
50
50
|
`expected ${ENV_VAR_NAME} to point to the deltachat-rpc-server executable`
|
|
51
51
|
);
|
|
@@ -68,41 +68,49 @@ export async function getRPCServerPath(options = {}) {
|
|
|
68
68
|
import { StdioDeltaChat } from "@deltachat/jsonrpc-client";
|
|
69
69
|
|
|
70
70
|
/** @type {import("./index").FnTypes.startDeltaChat} */
|
|
71
|
-
export
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
env: {
|
|
75
|
-
RUST_LOG: process.env.RUST_LOG,
|
|
76
|
-
DC_ACCOUNTS_PATH: directory,
|
|
77
|
-
},
|
|
78
|
-
stdio: ["pipe", "pipe", options.muteStdErr ? "ignore" : "inherit"],
|
|
79
|
-
});
|
|
71
|
+
export function startDeltaChat(directory, options = {}) {
|
|
72
|
+
return new DeltaChatOverJsonRpc(directory, options);
|
|
73
|
+
}
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
export class DeltaChatOverJsonRpc extends StdioDeltaChat {
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* @param {string} directory
|
|
79
|
+
* @param {Partial<import("./index").SearchOptions & import("./index").StartOptions>} options
|
|
80
|
+
*/
|
|
81
|
+
constructor(directory, options = {}) {
|
|
82
|
+
const pathToServerBinary = getRPCServerPath(options);
|
|
83
|
+
const server = spawn(pathToServerBinary, {
|
|
84
|
+
env: {
|
|
85
|
+
RUST_LOG: process.env.RUST_LOG,
|
|
86
|
+
DC_ACCOUNTS_PATH: directory,
|
|
87
|
+
},
|
|
88
|
+
stdio: ["pipe", "pipe", options.muteStdErr ? "ignore" : "inherit"],
|
|
89
|
+
});
|
|
85
90
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
server.on("error", (err) => {
|
|
92
|
+
throw new Error(
|
|
93
|
+
FAILED_TO_START_SERVER_EXECUTABLE(pathToServerBinary, err)
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
let shouldClose = false;
|
|
92
97
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
server.on("exit", () => {
|
|
99
|
+
if (shouldClose) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
throw new Error("Server quit");
|
|
103
|
+
});
|
|
96
104
|
|
|
97
|
-
|
|
98
|
-
shouldClose = true;
|
|
99
|
-
if (!server.kill()) {
|
|
100
|
-
console.log("server termination failed");
|
|
101
|
-
}
|
|
102
|
-
};
|
|
105
|
+
super(server.stdin, server.stdout, true);
|
|
103
106
|
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
this.close = () => {
|
|
108
|
+
shouldClose = true;
|
|
109
|
+
if (!server.kill()) {
|
|
110
|
+
console.log("server termination failed");
|
|
111
|
+
}
|
|
112
|
+
};
|
|
106
113
|
|
|
107
|
-
|
|
114
|
+
this.pathToServerBinary = pathToServerBinary;
|
|
115
|
+
}
|
|
108
116
|
}
|
package/package.json
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
"main": "index.js",
|
|
4
4
|
"name": "@deltachat/stdio-rpc-server",
|
|
5
5
|
"optionalDependencies": {
|
|
6
|
-
"@deltachat/stdio-rpc-server-darwin-arm64": "2.
|
|
7
|
-
"@deltachat/stdio-rpc-server-android-arm64": "2.
|
|
8
|
-
"@deltachat/stdio-rpc-server-linux-arm64": "2.
|
|
9
|
-
"@deltachat/stdio-rpc-server-linux-arm": "2.
|
|
10
|
-
"@deltachat/stdio-rpc-server-android-arm": "2.
|
|
11
|
-
"@deltachat/stdio-rpc-server-win32-ia32": "2.
|
|
12
|
-
"@deltachat/stdio-rpc-server-linux-ia32": "2.
|
|
13
|
-
"@deltachat/stdio-rpc-server-darwin-x64": "2.
|
|
14
|
-
"@deltachat/stdio-rpc-server-win32-x64": "2.
|
|
15
|
-
"@deltachat/stdio-rpc-server-linux-x64": "2.
|
|
6
|
+
"@deltachat/stdio-rpc-server-darwin-arm64": "2.49.0",
|
|
7
|
+
"@deltachat/stdio-rpc-server-android-arm64": "2.49.0",
|
|
8
|
+
"@deltachat/stdio-rpc-server-linux-arm64": "2.49.0",
|
|
9
|
+
"@deltachat/stdio-rpc-server-linux-arm": "2.49.0",
|
|
10
|
+
"@deltachat/stdio-rpc-server-android-arm": "2.49.0",
|
|
11
|
+
"@deltachat/stdio-rpc-server-win32-ia32": "2.49.0",
|
|
12
|
+
"@deltachat/stdio-rpc-server-linux-ia32": "2.49.0",
|
|
13
|
+
"@deltachat/stdio-rpc-server-darwin-x64": "2.49.0",
|
|
14
|
+
"@deltachat/stdio-rpc-server-win32-x64": "2.49.0",
|
|
15
|
+
"@deltachat/stdio-rpc-server-linux-x64": "2.49.0"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"@deltachat/jsonrpc-client": "*"
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
},
|
|
27
27
|
"type": "module",
|
|
28
28
|
"types": "index.d.ts",
|
|
29
|
-
"version": "2.
|
|
29
|
+
"version": "2.49.0"
|
|
30
30
|
}
|