@macula-io/ts 0.17.0 → 0.18.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 +109 -272
- package/dist/binding.d.ts +47 -45
- package/dist/binding.js +8 -125
- package/dist/binding.js.map +1 -1
- package/dist/content.js +7 -6
- package/dist/content.js.map +1 -1
- package/dist/directdial.d.ts +3 -3
- package/dist/directdial.js +3 -3
- package/dist/index.d.ts +4 -9
- package/dist/index.js +5 -8
- package/dist/index.js.map +1 -1
- package/dist/key.d.ts +31 -0
- package/dist/key.js +72 -0
- package/dist/key.js.map +1 -0
- package/dist/pool.d.ts +167 -131
- package/dist/pool.js +200 -579
- package/dist/pool.js.map +1 -1
- package/dist/session.d.ts +58 -50
- package/dist/session.js +104 -85
- package/dist/session.js.map +1 -1
- package/dist/stream.d.ts +63 -0
- package/dist/stream.js +93 -0
- package/dist/stream.js.map +1 -0
- package/dist/wire.d.ts +53 -0
- package/dist/wire.js +79 -0
- package/dist/wire.js.map +1 -0
- package/package.json +5 -4
- package/prebuilds/darwin-arm64/@macula-io+ts.node +0 -0
- package/prebuilds/darwin-x64/@macula-io+ts.node +0 -0
- package/prebuilds/linux-arm64/@macula-io+ts.node +0 -0
- package/prebuilds/linux-x64/@macula-io+ts.node +0 -0
- package/prebuilds/win32-x64/@macula-io+ts.node +0 -0
package/dist/wire.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** A payload, restricted to what macula's wire CBOR carries: no boolean and
|
|
2
|
+
* no undefined. Encode true/false as 1/0 yourself; a JS boolean reaching the
|
|
3
|
+
* wire is exactly the mistake this type makes impossible at compile time.
|
|
4
|
+
*
|
|
5
|
+
* Bytes have no native JSON shape. Going IN, write them as an object whose
|
|
6
|
+
* ONLY key is "$bytes", holding standard padded base64: `{"$bytes": "AQID"}`
|
|
7
|
+
* is the three bytes 01 02 03. A plain string is always text. Coming OUT,
|
|
8
|
+
* bytes are a "0x"-prefixed lowercase hex string by default, or the same
|
|
9
|
+
* tagged object when you ask for `bytes: "tagged"` (see BytesOutput). */
|
|
10
|
+
export type JsonValue = string | number | null | JsonValue[] | {
|
|
11
|
+
[key: string]: JsonValue;
|
|
12
|
+
};
|
|
13
|
+
/** How bytes in a result, a request, an event or a record reach JavaScript:
|
|
14
|
+
* "hex" (the default) or "tagged" ({"$bytes": "<base64>"}). */
|
|
15
|
+
export type BytesOutput = "hex" | "tagged";
|
|
16
|
+
/** BytesOutput as the integer the native layer takes. */
|
|
17
|
+
export declare function bytesModeFor(bytes: BytesOutput | undefined): number;
|
|
18
|
+
/** A 32-byte id (a node_id, a realm id, a record key): 64 hex characters or
|
|
19
|
+
* 32 bytes. */
|
|
20
|
+
export type Id = string | Uint8Array;
|
|
21
|
+
/** An Id as the 32 bytes the native layer takes. */
|
|
22
|
+
export declare function id32(id: Id, what?: string): Uint8Array;
|
|
23
|
+
/** 32 bytes as lowercase hex. */
|
|
24
|
+
export declare function hex(bytes: Uint8Array): string;
|
|
25
|
+
/** A provider's own ERROR for a call: `handler_error` with the handler's
|
|
26
|
+
* text, `temporary_relay_failure` for a handler that crashed,
|
|
27
|
+
* `unknown_next_peer` for a procedure it does not serve, or an admission
|
|
28
|
+
* refusal (`expired`, `request_copy`, `caller_quota`, ...). */
|
|
29
|
+
export declare class ProviderError extends Error {
|
|
30
|
+
readonly code: string;
|
|
31
|
+
readonly detail: string;
|
|
32
|
+
constructor(code: string, detail: string);
|
|
33
|
+
}
|
|
34
|
+
/** A station's signed relay error for a call: it could not relay it, e.g.
|
|
35
|
+
* `unknown_next_peer` for a provider it cannot reach. */
|
|
36
|
+
export declare class RelayError extends Error {
|
|
37
|
+
readonly code: string;
|
|
38
|
+
constructor(code: string);
|
|
39
|
+
}
|
|
40
|
+
/** A stream ended by a STREAM_ERROR: the peer's, a relay error from the
|
|
41
|
+
* station (`relay`), or this side's own (e.g. `resource_exhausted`). */
|
|
42
|
+
export declare class StreamError extends Error {
|
|
43
|
+
readonly code: string;
|
|
44
|
+
readonly detail: string;
|
|
45
|
+
readonly relay: boolean;
|
|
46
|
+
constructor(code: string, detail: string, relay: boolean);
|
|
47
|
+
}
|
|
48
|
+
/** The error the native layer rejects a call with, as the class it names:
|
|
49
|
+
* "provider_error:<code>:<detail>" and "relay_error:<code>" (cabi's
|
|
50
|
+
* callError), any other text as a plain Error. */
|
|
51
|
+
export declare function callError(e: unknown): Error;
|
|
52
|
+
/** How long a call waits, in milliseconds, when not told: macula's 5 s. */
|
|
53
|
+
export declare const DEFAULT_CALL_TIMEOUT_MS = 5000;
|
package/dist/wire.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// The shapes every part of the API shares: payload values, ids, and the
|
|
2
|
+
// errors a call or a stream ends with.
|
|
3
|
+
/** BytesOutput as the integer the native layer takes. */
|
|
4
|
+
export function bytesModeFor(bytes) {
|
|
5
|
+
if (bytes === undefined || bytes === "hex")
|
|
6
|
+
return 0;
|
|
7
|
+
if (bytes === "tagged")
|
|
8
|
+
return 1;
|
|
9
|
+
throw new Error(`macula-ts: bytes must be "hex" or "tagged", got ${JSON.stringify(bytes)}`);
|
|
10
|
+
}
|
|
11
|
+
/** An Id as the 32 bytes the native layer takes. */
|
|
12
|
+
export function id32(id, what = "id") {
|
|
13
|
+
if (typeof id === "string") {
|
|
14
|
+
if (!/^[0-9a-fA-F]{64}$/.test(id))
|
|
15
|
+
throw new Error(`macula-ts: ${what} must be 64 hex characters`);
|
|
16
|
+
return Uint8Array.from(Buffer.from(id, "hex"));
|
|
17
|
+
}
|
|
18
|
+
if (id.length !== 32)
|
|
19
|
+
throw new Error(`macula-ts: ${what} must be 32 bytes, got ${id.length}`);
|
|
20
|
+
return id;
|
|
21
|
+
}
|
|
22
|
+
/** 32 bytes as lowercase hex. */
|
|
23
|
+
export function hex(bytes) {
|
|
24
|
+
return Buffer.from(bytes).toString("hex");
|
|
25
|
+
}
|
|
26
|
+
/** A provider's own ERROR for a call: `handler_error` with the handler's
|
|
27
|
+
* text, `temporary_relay_failure` for a handler that crashed,
|
|
28
|
+
* `unknown_next_peer` for a procedure it does not serve, or an admission
|
|
29
|
+
* refusal (`expired`, `request_copy`, `caller_quota`, ...). */
|
|
30
|
+
export class ProviderError extends Error {
|
|
31
|
+
code;
|
|
32
|
+
detail;
|
|
33
|
+
constructor(code, detail) {
|
|
34
|
+
super(`macula-ts: the provider answered ${code}${detail ? `: ${detail}` : ""}`);
|
|
35
|
+
this.code = code;
|
|
36
|
+
this.detail = detail;
|
|
37
|
+
this.name = "ProviderError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** A station's signed relay error for a call: it could not relay it, e.g.
|
|
41
|
+
* `unknown_next_peer` for a provider it cannot reach. */
|
|
42
|
+
export class RelayError extends Error {
|
|
43
|
+
code;
|
|
44
|
+
constructor(code) {
|
|
45
|
+
super(`macula-ts: the station could not relay the call: ${code}`);
|
|
46
|
+
this.code = code;
|
|
47
|
+
this.name = "RelayError";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** A stream ended by a STREAM_ERROR: the peer's, a relay error from the
|
|
51
|
+
* station (`relay`), or this side's own (e.g. `resource_exhausted`). */
|
|
52
|
+
export class StreamError extends Error {
|
|
53
|
+
code;
|
|
54
|
+
detail;
|
|
55
|
+
relay;
|
|
56
|
+
constructor(code, detail, relay) {
|
|
57
|
+
super(`macula-ts: stream error ${code}${detail ? `: ${detail}` : ""}`);
|
|
58
|
+
this.code = code;
|
|
59
|
+
this.detail = detail;
|
|
60
|
+
this.relay = relay;
|
|
61
|
+
this.name = "StreamError";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** The error the native layer rejects a call with, as the class it names:
|
|
65
|
+
* "provider_error:<code>:<detail>" and "relay_error:<code>" (cabi's
|
|
66
|
+
* callError), any other text as a plain Error. */
|
|
67
|
+
export function callError(e) {
|
|
68
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
69
|
+
const provider = /^provider_error:([^:]*):([\s\S]*)$/.exec(message);
|
|
70
|
+
if (provider)
|
|
71
|
+
return new ProviderError(provider[1] ?? "", provider[2] ?? "");
|
|
72
|
+
const relay = /^relay_error:(.*)$/.exec(message);
|
|
73
|
+
if (relay)
|
|
74
|
+
return new RelayError(relay[1] ?? "");
|
|
75
|
+
return e instanceof Error ? e : new Error(message);
|
|
76
|
+
}
|
|
77
|
+
/** How long a call waits, in milliseconds, when not told: macula's 5 s. */
|
|
78
|
+
export const DEFAULT_CALL_TIMEOUT_MS = 5_000;
|
|
79
|
+
//# sourceMappingURL=wire.js.map
|
package/dist/wire.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,uCAAuC;AAiBvC,yDAAyD;AACzD,MAAM,UAAU,YAAY,CAAC,KAA8B;IACzD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,CAAC,CAAC;IACrD,IAAI,KAAK,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IACjC,MAAM,IAAI,KAAK,CAAC,mDAAmD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAC9F,CAAC;AAMD,oDAAoD;AACpD,MAAM,UAAU,IAAI,CAAC,EAAM,EAAE,IAAI,GAAG,IAAI;IACtC,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;QAC3B,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,cAAc,IAAI,4BAA4B,CAAC,CAAC;QACnG,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,IAAI,EAAE,CAAC,MAAM,KAAK,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,cAAc,IAAI,0BA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,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3D,MAAM,QAAQ,GAAG,oCAAoC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpE,IAAI,QAAQ;QAAE,OAAO,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7E,MAAM,KAAK,GAAG,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjD,IAAI,KAAK;QAAE,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACjD,OAAO,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AACrD,CAAC;AAED,2EAA2E;AAC3E,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@macula-io/ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "TypeScript SDK for the Macula mesh (FFI over macula-go)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -45,9 +45,10 @@
|
|
|
45
45
|
"build:addon:dev": "npm run build:go && node-gyp rebuild",
|
|
46
46
|
"build:prebuilds": "npm run build:go && prebuildify --napi --strip && npm pkg delete scripts.install",
|
|
47
47
|
"build": "npm run build:addon:dev && tsc",
|
|
48
|
-
"test": "vitest run",
|
|
49
|
-
"test:live": "MACULA_TS_LIVE=1 vitest run src/
|
|
50
|
-
"typecheck": "tsc --noEmit"
|
|
48
|
+
"test": "npm run build:teststation && vitest run",
|
|
49
|
+
"test:live": "MACULA_TS_LIVE=1 vitest run src/fleet.live.test.ts",
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"build:teststation": "cd cabi && go build -trimpath -buildvcs=false -o ../build/teststation ./cmd/teststation"
|
|
51
52
|
},
|
|
52
53
|
"dependencies": {
|
|
53
54
|
"node-addon-api": "^8.9.2",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|