@macula-io/ts 0.17.0 → 0.19.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 +106 -272
- package/dist/binding.d.ts +50 -45
- package/dist/binding.js +8 -125
- package/dist/binding.js.map +1 -1
- package/dist/content.d.ts +32 -13
- package/dist/content.js +43 -41
- package/dist/content.js.map +1 -1
- package/dist/index.d.ts +5 -9
- package/dist/index.js +6 -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 +185 -131
- package/dist/pool.js +223 -576
- package/dist/pool.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 +7 -5
- 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/dht.d.ts +0 -55
- package/dist/dht.js +0 -25
- package/dist/dht.js.map +0 -1
- package/dist/directdial.d.ts +0 -79
- package/dist/directdial.js +0 -76
- package/dist/directdial.js.map +0 -1
- package/dist/identity.d.ts +0 -43
- package/dist/identity.js +0 -83
- package/dist/identity.js.map +0 -1
- package/dist/pubsub.d.ts +0 -60
- package/dist/pubsub.js +0 -8
- package/dist/pubsub.js.map +0 -1
- package/dist/rpc.d.ts +0 -86
- package/dist/rpc.js +0 -57
- package/dist/rpc.js.map +0 -1
- package/dist/session.d.ts +0 -481
- package/dist/session.js +0 -810
- package/dist/session.js.map +0 -1
- package/dist/ucan.d.ts +0 -110
- package/dist/ucan.js +0 -140
- package/dist/ucan.js.map +0 -1
package/dist/pool.d.ts
CHANGED
|
@@ -1,146 +1,200 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { type Handle } from "./binding.js";
|
|
2
|
+
import { NodeKey } from "./key.js";
|
|
3
|
+
import { Stream, StreamMode, type StreamRequest } from "./stream.js";
|
|
4
|
+
import { type ContentOptions, type Mcid } from "./content.js";
|
|
5
|
+
import { type BytesOutput, type Id, type JsonValue } from "./wire.js";
|
|
6
|
+
/** A station to link to, pinned by the node_id it must prove. */
|
|
5
7
|
export interface Seed {
|
|
6
|
-
host: string;
|
|
7
|
-
port: number;
|
|
8
|
+
readonly host: string;
|
|
9
|
+
readonly port: number;
|
|
10
|
+
readonly nodeId: Id;
|
|
8
11
|
}
|
|
9
12
|
export interface PoolOptions {
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* as a duplicate before it ages out. Default 60_000, matching the
|
|
23
|
-
* Erlang reference's own `dedup_window_ms` default. */
|
|
24
|
-
dedupWindowMs?: number;
|
|
25
|
-
/** How often the dedup table is swept for expired entries. Default
|
|
26
|
-
* 30_000, matching the Erlang reference's own `dedup_sweep_ms`. */
|
|
27
|
-
dedupSweepMs?: number;
|
|
28
|
-
/** How often a live control link is health-checked (see
|
|
29
|
-
* #armHealthCheck's own doc for why publish() alone can't be trusted
|
|
30
|
-
* to ever notice a dead connection). Default 10_000. */
|
|
31
|
-
healthCheckIntervalMs?: number;
|
|
13
|
+
/** Each realm's key as carried (hex or bytes), by realm id: an
|
|
14
|
+
* advertisement in a realm is trusted only when its authorization verifies
|
|
15
|
+
* against it, and a procedure is served only in a realm it names. */
|
|
16
|
+
readonly realmTrust?: ReadonlyArray<{
|
|
17
|
+
readonly realm: Id;
|
|
18
|
+
readonly key: string | Uint8Array;
|
|
19
|
+
}>;
|
|
20
|
+
readonly replicationFactor?: number;
|
|
21
|
+
readonly maxDirectLinks?: number;
|
|
22
|
+
readonly respawnDelayMs?: number;
|
|
23
|
+
/** How long connect waits for a first link, 30 s by default. */
|
|
24
|
+
readonly timeoutMs?: number;
|
|
32
25
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
failedLinks: number;
|
|
26
|
+
/** One of the pool's links. */
|
|
27
|
+
export interface LinkStatus {
|
|
28
|
+
readonly station: string;
|
|
29
|
+
readonly host: string;
|
|
30
|
+
readonly port: number;
|
|
31
|
+
readonly direct: boolean;
|
|
32
|
+
readonly up: boolean;
|
|
41
33
|
}
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
/** A trusted provider of a procedure and the station it serves from. */
|
|
35
|
+
export interface Provider {
|
|
36
|
+
readonly node: string;
|
|
37
|
+
readonly station: string;
|
|
38
|
+
}
|
|
39
|
+
/** An event a subscription heard, verified. */
|
|
40
|
+
export interface Event {
|
|
41
|
+
readonly publisher: string;
|
|
42
|
+
readonly realm: string;
|
|
43
|
+
readonly topic: string;
|
|
44
|
+
readonly seq: number;
|
|
45
|
+
readonly publishedAt: number;
|
|
46
|
+
readonly payload: JsonValue;
|
|
47
|
+
readonly deliveredVia: string;
|
|
48
|
+
}
|
|
49
|
+
/** A served call's request. */
|
|
50
|
+
export interface Request {
|
|
51
|
+
readonly caller: string;
|
|
52
|
+
readonly realm: string;
|
|
53
|
+
readonly procedure: string;
|
|
54
|
+
readonly payload: JsonValue;
|
|
55
|
+
readonly deadlineMs: number;
|
|
56
|
+
}
|
|
57
|
+
/** A verified DHT record: its type, signer's key id, times, payload, and wire
|
|
58
|
+
* bytes (tagged). */
|
|
59
|
+
export interface DhtRecord {
|
|
60
|
+
readonly type: number;
|
|
61
|
+
readonly keyId: string;
|
|
62
|
+
readonly createdAt: number;
|
|
63
|
+
readonly expiresAt: number;
|
|
64
|
+
readonly payload: JsonValue;
|
|
65
|
+
readonly wire: JsonValue;
|
|
66
|
+
}
|
|
67
|
+
/** macula 12's record types. */
|
|
68
|
+
export declare enum RecordType {
|
|
69
|
+
NodeRecord = 1,
|
|
70
|
+
ProcedureAdvertisement = 6,
|
|
71
|
+
Tombstone = 12,
|
|
72
|
+
ContentAnnouncement = 17,
|
|
73
|
+
StationEndpoint = 18,
|
|
74
|
+
OrgDirectory = 21,
|
|
75
|
+
ProcedureDelegation = 22
|
|
76
|
+
}
|
|
77
|
+
/** A subscription, until stop() or the pool closes. */
|
|
78
|
+
export declare class Subscription {
|
|
79
|
+
private readonly handle;
|
|
80
|
+
readonly closed: Promise<string | null>;
|
|
81
|
+
/** @internal */
|
|
82
|
+
constructor(handle: Handle, closed: Promise<string | null>);
|
|
83
|
+
/** Ends the subscription on every link. */
|
|
84
|
+
stop(): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
/** A served procedure, until stop(). */
|
|
87
|
+
export declare class Served {
|
|
88
|
+
private readonly handle;
|
|
89
|
+
private stopped;
|
|
90
|
+
/** @internal */
|
|
91
|
+
constructor(handle: Handle);
|
|
92
|
+
/** Withdraws the procedure on every link. */
|
|
93
|
+
stop(): Promise<void>;
|
|
48
94
|
}
|
|
49
|
-
/**
|
|
50
|
-
* A resilient multi-station client: live connections to every configured
|
|
51
|
-
* seed held concurrently, each independently monitored and respawned
|
|
52
|
-
* with backoff on disconnect, every tracked subscription re-established
|
|
53
|
-
* automatically when its own link reconnects. See this module's own
|
|
54
|
-
* header doc for the full design, why a "link" is a small role-scoped
|
|
55
|
-
* session set rather than one Session, and its one deliberate deviation
|
|
56
|
-
* from the Erlang reference (topic-scoped dedup).
|
|
57
|
-
*/
|
|
58
95
|
export declare class Pool {
|
|
59
|
-
|
|
96
|
+
private readonly handle;
|
|
97
|
+
private closed;
|
|
60
98
|
private constructor();
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
/** Links the key's node to every seed, and resolves once one link is up. */
|
|
100
|
+
static connect(key: NodeKey, seeds: readonly Seed[], options?: PoolOptions): Promise<Pool>;
|
|
101
|
+
/** The node_id the pool links as. */
|
|
102
|
+
nodeId(): string;
|
|
103
|
+
/** name in this node's own namespace, `~<node_id>/<name>`: a procedure it
|
|
104
|
+
* serves with no org and no realm key, authorized by its advertisement's
|
|
105
|
+
* signature alone, and that any node calls with no realm key pinned. */
|
|
106
|
+
ownProcedure(name: string): string;
|
|
107
|
+
/** Every link the pool holds. */
|
|
108
|
+
status(): LinkStatus[];
|
|
109
|
+
/** Calls procedure in realm at a provider (any trusted one unless
|
|
110
|
+
* `provider` names one) by direct dial. A provider's ERROR is thrown as a
|
|
111
|
+
* ProviderError, a station's relay error as a RelayError. */
|
|
112
|
+
call(realm: Id, procedure: string, payload?: JsonValue, options?: {
|
|
113
|
+
provider?: Id;
|
|
114
|
+
timeoutMs?: number;
|
|
115
|
+
bytes?: BytesOutput;
|
|
116
|
+
}): Promise<JsonValue>;
|
|
117
|
+
/** The procedure's trusted providers, freshest first. */
|
|
118
|
+
providers(realm: Id, procedure: string, options?: {
|
|
119
|
+
timeoutMs?: number;
|
|
120
|
+
}): Promise<Provider[]>;
|
|
121
|
+
/** Publishes payload on topic in realm. Topics name a kind of fact; ids go
|
|
122
|
+
* in the payload. */
|
|
123
|
+
publish(realm: Id, topic: string, payload: JsonValue, options?: {
|
|
84
124
|
ttlMs?: number;
|
|
85
125
|
}): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
*
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
* link in turn as call() moved through them re-trying the same call.
|
|
111
|
-
* #probeLiveness's own dedicated liveness call is the tiebreaker --
|
|
112
|
-
* only a link that ALSO fails to get a wire-level answer on that
|
|
113
|
-
* fresh probe is scheduled for reconnect. Each link's own `session`
|
|
114
|
-
* reference is re-checked both before probing and before scheduling a
|
|
115
|
-
* reconnect, in case a concurrent operation already superseded it. */
|
|
116
|
-
call(realm: string | undefined, procedure: string, payload: JsonValue, opts?: {
|
|
126
|
+
/** Subscribes to topic in realm: onEvent hears each verified event once,
|
|
127
|
+
* however many links deliver it. `closed` resolves when the subscription
|
|
128
|
+
* ends, with why or null. */
|
|
129
|
+
subscribe(realm: Id, topic: string, onEvent: (event: Event) => void, options?: {
|
|
130
|
+
bytes?: BytesOutput;
|
|
131
|
+
}): Promise<Subscription>;
|
|
132
|
+
/** Serves procedure in realm: handler answers each call, and its thrown
|
|
133
|
+
* error goes back as a handler_error with its message. An org procedure
|
|
134
|
+
* needs the realm's key pinned and the org's delegation to this node in the
|
|
135
|
+
* DHT; a procedure in this node's own namespace (ownProcedure) needs
|
|
136
|
+
* neither, and another node's namespace is refused. */
|
|
137
|
+
serve(realm: Id, procedure: string, handler: (request: Request) => JsonValue | Promise<JsonValue>, options?: {
|
|
138
|
+
bytes?: BytesOutput;
|
|
139
|
+
}): Promise<Served>;
|
|
140
|
+
/** Serves procedure in realm as a stream of mode: handler drives each
|
|
141
|
+
* session. The stream is closed when the handler returns without ending
|
|
142
|
+
* it, aborted with code error when it throws, and released either way. */
|
|
143
|
+
serveStream(realm: Id, procedure: string, mode: StreamMode, handler: (stream: Stream, request: StreamRequest) => void | Promise<void>, options?: {
|
|
144
|
+
bytes?: BytesOutput;
|
|
145
|
+
}): Promise<Served>;
|
|
146
|
+
/** Opens a stream of mode on procedure in realm at a provider, by direct
|
|
147
|
+
* dial. A refusal arrives on its first recv(). */
|
|
148
|
+
openStream(realm: Id, procedure: string, mode: StreamMode, payload?: JsonValue, options?: {
|
|
149
|
+
provider?: Id;
|
|
117
150
|
deadlineMs?: number;
|
|
151
|
+
timeoutMs?: number;
|
|
118
152
|
bytes?: BytesOutput;
|
|
119
|
-
}): Promise<
|
|
120
|
-
/**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
* default (disposed on unsubscribe); pass `identity` to supply the
|
|
124
|
-
* pool's own instead (e.g. for a stable, caller-controlled identity
|
|
125
|
-
* across restarts, matching macula-mcp's own observeRoomIdentityPath
|
|
126
|
-
* pattern) -- the pool never disposes an identity it didn't mint.
|
|
127
|
-
* `opts.bytes` picks how bytes in each event's payload reach `handler`
|
|
128
|
-
* (rpc.ts's BytesOutput), on every seed and after every respawn.
|
|
129
|
-
* Returns an unsubscribe function. */
|
|
130
|
-
subscribe(realm: string | undefined, topic: string, handler: (evt: PubsubEvent) => void, identity?: Identity, opts?: {
|
|
153
|
+
}): Promise<Stream>;
|
|
154
|
+
/** The verified record under key, or null when there is none. */
|
|
155
|
+
findRecord(key: Id, options?: {
|
|
156
|
+
timeoutMs?: number;
|
|
131
157
|
bytes?: BytesOutput;
|
|
132
|
-
}): Promise<
|
|
133
|
-
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
158
|
+
}): Promise<DhtRecord | null>;
|
|
159
|
+
/** Every verified record under key, and how many did not verify. */
|
|
160
|
+
findRecords(key: Id, options?: {
|
|
161
|
+
timeoutMs?: number;
|
|
162
|
+
bytes?: BytesOutput;
|
|
163
|
+
}): Promise<{
|
|
164
|
+
records: DhtRecord[];
|
|
165
|
+
dropped: number;
|
|
166
|
+
}>;
|
|
167
|
+
/** Every verified record of type the station holds, and how many did not
|
|
168
|
+
* verify. */
|
|
169
|
+
findRecordsByType(type: RecordType | number, options?: {
|
|
170
|
+
timeoutMs?: number;
|
|
171
|
+
bytes?: BytesOutput;
|
|
172
|
+
}): Promise<{
|
|
173
|
+
records: DhtRecord[];
|
|
174
|
+
dropped: number;
|
|
175
|
+
}>;
|
|
176
|
+
/** Shares data in realm: this node keeps it, serves it on its own
|
|
177
|
+
* `~<node_id>/content_v1` and announces it, renewing the announcement until
|
|
178
|
+
* unshareContent or close. Data of at most 256 KiB is one raw block; larger
|
|
179
|
+
* data a manifest over 256 KiB chunks, named name. Resolves to the content
|
|
180
|
+
* id as hex. Serving needs stations that admit a node's own namespace. */
|
|
181
|
+
shareContent(realm: Id, data: Uint8Array, name?: string, options?: {
|
|
182
|
+
timeoutMs?: number;
|
|
183
|
+
}): Promise<string>;
|
|
184
|
+
/** Stops sharing mcid in realm and withdraws its announcement. */
|
|
185
|
+
unshareContent(realm: Id, mcid: Mcid, options?: {
|
|
186
|
+
timeoutMs?: number;
|
|
187
|
+
}): Promise<void>;
|
|
188
|
+
/** Fetches the content mcid names in realm from a node that shares it,
|
|
189
|
+
* checked against mcid; no realm key is needed. Content nobody announces is
|
|
190
|
+
* a NotSharedError, content every sharer failed to give a
|
|
191
|
+
* ContentUnavailableError. */
|
|
192
|
+
getContent(realm: Id, mcid: Mcid, options?: ContentOptions): Promise<Uint8Array>;
|
|
193
|
+
/** Puts a signed record's wire bytes in the DHT. */
|
|
194
|
+
putRecord(wire: Uint8Array, options?: {
|
|
195
|
+
timeoutMs?: number;
|
|
196
|
+
}): Promise<void>;
|
|
197
|
+
/** Closes every link and subscription. */
|
|
145
198
|
close(): Promise<void>;
|
|
199
|
+
private live;
|
|
146
200
|
}
|