@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.
Files changed (4) hide show
  1. package/README.md +1 -1
  2. package/index.d.ts +10 -3
  3. package/index.js +42 -34
  4. 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 = await startDeltaChat("deltachat-data");
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
- ): Promise<string>;
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> ): Promise<DeltaChatOverJsonRpcServer>
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 { stat } from "node:fs/promises";
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 async function getRPCServerPath(options = {}) {
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 (!(await stat(process.env[ENV_VAR_NAME])).isFile()) {
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 async function startDeltaChat(directory, options = {}) {
72
- const pathToServerBinary = await getRPCServerPath(options);
73
- const server = spawn(pathToServerBinary, {
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
- server.on("error", (err) => {
82
- throw new Error(FAILED_TO_START_SERVER_EXECUTABLE(pathToServerBinary, err));
83
- });
84
- let shouldClose = false;
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
- server.on("exit", () => {
87
- if (shouldClose) {
88
- return;
89
- }
90
- throw new Error("Server quit");
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
- /** @type {import('./index').DeltaChatOverJsonRpcServer} */
94
- //@ts-expect-error
95
- const dc = new StdioDeltaChat(server.stdin, server.stdout, true);
98
+ server.on("exit", () => {
99
+ if (shouldClose) {
100
+ return;
101
+ }
102
+ throw new Error("Server quit");
103
+ });
96
104
 
97
- dc.close = () => {
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
- //@ts-expect-error
105
- dc.pathToServerBinary = pathToServerBinary;
107
+ this.close = () => {
108
+ shouldClose = true;
109
+ if (!server.kill()) {
110
+ console.log("server termination failed");
111
+ }
112
+ };
106
113
 
107
- return dc;
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.48.0",
7
- "@deltachat/stdio-rpc-server-android-arm64": "2.48.0",
8
- "@deltachat/stdio-rpc-server-linux-arm64": "2.48.0",
9
- "@deltachat/stdio-rpc-server-linux-arm": "2.48.0",
10
- "@deltachat/stdio-rpc-server-android-arm": "2.48.0",
11
- "@deltachat/stdio-rpc-server-win32-ia32": "2.48.0",
12
- "@deltachat/stdio-rpc-server-linux-ia32": "2.48.0",
13
- "@deltachat/stdio-rpc-server-darwin-x64": "2.48.0",
14
- "@deltachat/stdio-rpc-server-win32-x64": "2.48.0",
15
- "@deltachat/stdio-rpc-server-linux-x64": "2.48.0"
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.48.0"
29
+ "version": "2.49.0"
30
30
  }