@nomux-sh/extension 0.0.0-stage → 0.1.3
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/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +22 -0
- package/README.md +144 -2
- package/dist/api-version.d.ts +22 -0
- package/dist/api-version.js +48 -0
- package/dist/call.d.ts +12 -0
- package/dist/call.js +1 -0
- package/dist/codec.d.ts +22 -0
- package/dist/codec.js +5 -0
- package/dist/connection.d.ts +57 -0
- package/dist/connection.js +183 -0
- package/dist/error.d.ts +41 -0
- package/dist/error.js +61 -0
- package/dist/extension.d.ts +90 -0
- package/dist/extension.js +153 -0
- package/dist/frame.d.ts +32 -0
- package/dist/frame.js +99 -0
- package/dist/generated/nomux/extension/v1/call.d.ts +29 -0
- package/dist/generated/nomux/extension/v1/call.js +103 -0
- package/dist/generated/nomux/extension/v1/envelope.d.ts +176 -0
- package/dist/generated/nomux/extension/v1/envelope.js +476 -0
- package/dist/generated/nomux/extension/v1/handshake.d.ts +66 -0
- package/dist/generated/nomux/extension/v1/handshake.js +269 -0
- package/dist/generated/nomux/extension/v1/lifecycle.d.ts +36 -0
- package/dist/generated/nomux/extension/v1/lifecycle.js +205 -0
- package/dist/handshake.d.ts +21 -0
- package/dist/handshake.js +36 -0
- package/dist/host.d.ts +37 -0
- package/dist/host.js +73 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +16 -0
- package/dist/outbound.d.ts +16 -0
- package/dist/outbound.js +30 -0
- package/dist/pending-calls.d.ts +20 -0
- package/dist/pending-calls.js +43 -0
- package/package.json +53 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The nomux extension SDK for the daemon part of an extension.
|
|
3
|
+
*
|
|
4
|
+
* The daemon part of an extension is a separate process. The nomux daemon
|
|
5
|
+
* (the host) starts it when a client needs it and stops it when it is idle.
|
|
6
|
+
* The host and the extension exchange protobuf messages on the standard
|
|
7
|
+
* input and the standard output of the process.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
export { API_VERSION, MINIMUM_API_VERSION, isCompatible } from "./api-version.js";
|
|
12
|
+
export type { ApiVersion } from "./api-version.js";
|
|
13
|
+
export type { Call } from "./call.js";
|
|
14
|
+
export { bytes } from "./codec.js";
|
|
15
|
+
export type { Codec, MethodCodecs } from "./codec.js";
|
|
16
|
+
export { CallError, ErrorCode, RunError } from "./error.js";
|
|
17
|
+
export type { RunErrorKind } from "./error.js";
|
|
18
|
+
export { Extension } from "./extension.js";
|
|
19
|
+
export type { Method } from "./extension.js";
|
|
20
|
+
export { MAX_ENVELOPE_LENGTH } from "./frame.js";
|
|
21
|
+
export { Host } from "./host.js";
|
|
22
|
+
export type { Permissions } from "./host.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The nomux extension SDK for the daemon part of an extension.
|
|
3
|
+
*
|
|
4
|
+
* The daemon part of an extension is a separate process. The nomux daemon
|
|
5
|
+
* (the host) starts it when a client needs it and stops it when it is idle.
|
|
6
|
+
* The host and the extension exchange protobuf messages on the standard
|
|
7
|
+
* input and the standard output of the process.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
export { API_VERSION, MINIMUM_API_VERSION, isCompatible } from "./api-version.js";
|
|
12
|
+
export { bytes } from "./codec.js";
|
|
13
|
+
export { CallError, ErrorCode, RunError } from "./error.js";
|
|
14
|
+
export { Extension } from "./extension.js";
|
|
15
|
+
export { MAX_ENVELOPE_LENGTH } from "./frame.js";
|
|
16
|
+
export { Host } from "./host.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Writable } from "node:stream";
|
|
2
|
+
import type { Envelope } from "./generated/nomux/extension/v1/envelope.js";
|
|
3
|
+
/** The stream to the host. */
|
|
4
|
+
export declare class Outbound {
|
|
5
|
+
private readonly output;
|
|
6
|
+
private written;
|
|
7
|
+
private failure;
|
|
8
|
+
constructor(output: Writable);
|
|
9
|
+
/**
|
|
10
|
+
* Writes one envelope. Throws `FrameError` if the envelope is larger than
|
|
11
|
+
* the limit; then nothing is written.
|
|
12
|
+
*/
|
|
13
|
+
send(kind: Envelope["kind"]): void;
|
|
14
|
+
/** Waits until the stream took each envelope that was sent. */
|
|
15
|
+
flush(): Promise<void>;
|
|
16
|
+
}
|
package/dist/outbound.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { encodeFrame } from "./frame.js";
|
|
2
|
+
/** The stream to the host. */
|
|
3
|
+
export class Outbound {
|
|
4
|
+
output;
|
|
5
|
+
written = Promise.resolve();
|
|
6
|
+
failure;
|
|
7
|
+
constructor(output) {
|
|
8
|
+
this.output = output;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Writes one envelope. Throws `FrameError` if the envelope is larger than
|
|
12
|
+
* the limit; then nothing is written.
|
|
13
|
+
*/
|
|
14
|
+
send(kind) {
|
|
15
|
+
const frame = encodeFrame({ kind });
|
|
16
|
+
this.written = new Promise((resolve) => {
|
|
17
|
+
this.output.write(frame, (error) => {
|
|
18
|
+
this.failure ??= error ?? undefined;
|
|
19
|
+
resolve();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** Waits until the stream took each envelope that was sent. */
|
|
24
|
+
async flush() {
|
|
25
|
+
await this.written;
|
|
26
|
+
if (this.failure !== undefined) {
|
|
27
|
+
throw this.failure;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Response } from "./generated/nomux/extension/v1/envelope.js";
|
|
2
|
+
/** The calls of host services that have no response yet. */
|
|
3
|
+
export declare class PendingCalls {
|
|
4
|
+
private lastId;
|
|
5
|
+
/** `undefined` after the stream from the host ended. */
|
|
6
|
+
private waiting;
|
|
7
|
+
/**
|
|
8
|
+
* Reserves a request number. The promise gets the response. Throws after
|
|
9
|
+
* {@link close}.
|
|
10
|
+
*/
|
|
11
|
+
register(): {
|
|
12
|
+
id: bigint;
|
|
13
|
+
response: Promise<Response>;
|
|
14
|
+
};
|
|
15
|
+
forget(id: bigint): void;
|
|
16
|
+
/** Gives a response to the call that waits for it. Other responses are dropped. */
|
|
17
|
+
resolve(response: Response): void;
|
|
18
|
+
/** Fails each call that waits and each subsequent call. */
|
|
19
|
+
close(): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CallError } from "./error.js";
|
|
2
|
+
/** The calls of host services that have no response yet. */
|
|
3
|
+
export class PendingCalls {
|
|
4
|
+
lastId = 0n;
|
|
5
|
+
/** `undefined` after the stream from the host ended. */
|
|
6
|
+
waiting = new Map();
|
|
7
|
+
/**
|
|
8
|
+
* Reserves a request number. The promise gets the response. Throws after
|
|
9
|
+
* {@link close}.
|
|
10
|
+
*/
|
|
11
|
+
register() {
|
|
12
|
+
const waiting = this.waiting;
|
|
13
|
+
if (waiting === undefined) {
|
|
14
|
+
throw disconnected();
|
|
15
|
+
}
|
|
16
|
+
this.lastId += 1n;
|
|
17
|
+
const id = this.lastId;
|
|
18
|
+
const response = new Promise((resolve, reject) => {
|
|
19
|
+
waiting.set(id, { resolve, reject });
|
|
20
|
+
});
|
|
21
|
+
return { id, response };
|
|
22
|
+
}
|
|
23
|
+
forget(id) {
|
|
24
|
+
this.waiting?.delete(id);
|
|
25
|
+
}
|
|
26
|
+
/** Gives a response to the call that waits for it. Other responses are dropped. */
|
|
27
|
+
resolve(response) {
|
|
28
|
+
const waiting = this.waiting?.get(response.id);
|
|
29
|
+
this.waiting?.delete(response.id);
|
|
30
|
+
waiting?.resolve(response);
|
|
31
|
+
}
|
|
32
|
+
/** Fails each call that waits and each subsequent call. */
|
|
33
|
+
close() {
|
|
34
|
+
const waiting = this.waiting;
|
|
35
|
+
this.waiting = undefined;
|
|
36
|
+
for (const call of waiting?.values() ?? []) {
|
|
37
|
+
call.reject(disconnected());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function disconnected() {
|
|
42
|
+
return CallError.failed("the host closed the connection");
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomux-sh/extension",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "The nomux extension SDK for TypeScript: the daemon part of an extension",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nomux",
|
|
7
|
+
"extension",
|
|
8
|
+
"sdk",
|
|
9
|
+
"protobuf",
|
|
10
|
+
"plugin"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT OR Apache-2.0",
|
|
13
|
+
"author": "The nomux Authors",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/nomux-sh/extension-api.git",
|
|
17
|
+
"directory": "sdk/typescript"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/nomux-sh/extension-api/tree/main/sdk/typescript#readme",
|
|
20
|
+
"bugs": "https://github.com/nomux-sh/extension-api/issues",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE-APACHE",
|
|
33
|
+
"LICENSE-MIT"
|
|
34
|
+
],
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=22"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"prepack": "npm run build",
|
|
42
|
+
"test": "tsc -p tsconfig.test.json && node --test --test-timeout=10000 '.test-build/test/*.test.js'"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@bufbuild/protobuf": "^2.17.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "22.20.5",
|
|
49
|
+
"ts-proto": "2.18.5",
|
|
50
|
+
"typescript": "7.0.2"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
}
|
|
55
|
+
}
|