@northtalk/ts 0.6.0 → 0.8.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 (57) hide show
  1. package/{binary-value-C4ZiXVjv.d.ts → binary-value-B93hEK7l.d.ts} +1 -1
  2. package/{checker-CUhn2XaM.js → checker-Q4w7rLXk.js} +600 -85
  3. package/{core-egHbNmve.d.ts → core-BBPI6EhG.d.ts} +1 -1
  4. package/{debug--Of4MSLw.d.ts → debug-s6QIovKS.d.ts} +142 -10
  5. package/debug.d.ts +1 -1
  6. package/debug.js +1 -1
  7. package/{driver-BIm1mL77.d.ts → driver-D5yrK3Nu.d.ts} +1 -1
  8. package/driver.d.ts +1 -1
  9. package/driver.js +1 -1
  10. package/encoding-B7MCQ4ii.js +338 -0
  11. package/{engine-DbDcopGM.d.ts → engine-Dy-BCoiw.d.ts} +2 -2
  12. package/{engine-CXf5FCwi.js → engine-OL1BveVZ.js} +6 -6
  13. package/{errors-D11zizZg.js → errors-VuwK669R.js} +157 -23
  14. package/{group-BpzTo0k4.js → group-Ccuqwq12.js} +477 -110
  15. package/{http-fetch-DFwVIOQg.js → http-fetch--O27xjSW.js} +2 -2
  16. package/http.d.ts +1 -1
  17. package/http.js +4 -4
  18. package/index.d.ts +6 -6
  19. package/index.js +15 -14
  20. package/{inline-grants-XbX9HL_w.js → inline-grants-DmOdgSoK.js} +4 -5
  21. package/{lean-aCvN6y52.js → lean-BjhQvHyr.js} +13 -8
  22. package/{lean-DiS9rUcn.d.ts → lean-D6DQfbqH.d.ts} +42 -7
  23. package/lean.d.ts +6 -6
  24. package/lean.js +15 -14
  25. package/{manifest-CCfpn0kC.js → manifest-BeViDIoy.js} +4 -3
  26. package/{manifest-mpivREn-.d.ts → manifest-l07K7nW-.d.ts} +4 -2
  27. package/message-layer.d.ts +2 -2
  28. package/message-layer.js +2 -2
  29. package/notify.d.ts +1 -1
  30. package/notify.js +1 -1
  31. package/{objects-DmUc0lha.js → objects-TarIKBL8.js} +1 -1
  32. package/{objects-DYq_YvaQ.d.ts → objects-q0lnCK-4.d.ts} +8 -3
  33. package/{operations-DnCcztkZ.js → operations-BAELnqwf.js} +133 -58
  34. package/package.json +5 -1
  35. package/peer-capability-B8eKbljR.js +151 -0
  36. package/peer.d.ts +180 -0
  37. package/peer.js +559 -0
  38. package/{readers-8WCimMop.d.ts → readers-AeB1bJ--.d.ts} +1 -1
  39. package/{readers-CsvlahLi.js → readers-BG8g59qS.js} +1 -1
  40. package/{request-pump-binary-oqjWFqZA.js → request-pump-binary-87klb6sX.js} +9 -4
  41. package/{router-BZ-aYeXA.js → router-DXmPA-qi.js} +4 -4
  42. package/{router-BQsO8aPV.d.ts → router-DXoJ_2Z4.d.ts} +2 -2
  43. package/session.d.ts +2 -2
  44. package/session.js +64 -16
  45. package/setup.d.ts +3 -2
  46. package/setup.js +14 -16
  47. package/sqlite.d.ts +2 -2
  48. package/sqlite.js +5 -5
  49. package/{store-DHlo6fP5.js → store-DzpyWjt2.js} +2 -2
  50. package/store-capability-CxQJ_Huz.js +187 -0
  51. package/store.d.ts +2 -2
  52. package/store.js +2 -2
  53. package/{user-capability-BcRQyyEw.js → user-capability-ClYd8Vln.js} +3 -4
  54. package/wasm.d.ts +13 -6
  55. package/wasm.js +47 -19
  56. package/encoding-RUuES_e4.js +0 -99
  57. package/store-capability-BrUUAwVS.js +0 -389
package/peer.d.ts ADDED
@@ -0,0 +1,180 @@
1
+ /// <reference lib="esnext.disposable" />
2
+ import { J as Value, P as TsGroup, an as PeerImpl } from "./debug-s6QIovKS.js";
3
+ //#region src/peer-message-port.d.ts
4
+ /** What the link needs of a `MessagePort`, a `Worker` or a worker's `self`. */
5
+ type PortEndpoint = {
6
+ addEventListener(type: string, listener: (event: MessageEvent) => void): void;
7
+ postMessage(message: unknown): void;
8
+ removeEventListener(type: string, listener: (event: MessageEvent) => void): void;
9
+ };
10
+ type MessagePortLinkOptions = {
11
+ /**
12
+ * The other end's name: `reach` uses it as the address, and it joins the
13
+ * Caller Identity.
14
+ */
15
+ name?: string;
16
+ };
17
+ /**
18
+ * A link to the Host at the other end of a `MessagePort`, or of a `Worker`
19
+ * from the page, or of the page from a worker's `self`. Closing a port ends
20
+ * the link at both ends. A worker that is terminated sends no word, so the
21
+ * page closes the link itself, as `WorkerSupervisor.closeOnTerminate` does.
22
+ */
23
+ export declare const messagePortLink: (port: PortEndpoint, options?: MessagePortLinkOptions) => PeerLink;
24
+ //#endregion
25
+ //#region src/peer-websocket.d.ts
26
+ /** What the link needs of a WHATWG `WebSocket`, or of a server's socket adapted to one. */
27
+ type WebSocketEndpoint = {
28
+ addEventListener(type: string, listener: (event: Event) => void): void;
29
+ close(code?: number, reason?: string): void;
30
+ /** 0 while connecting, 1 when open, 2 closing, 3 closed. */
31
+ readonly readyState: number;
32
+ removeEventListener(type: string, listener: (event: Event) => void): void;
33
+ send(data: string): void;
34
+ /** The address dialled, whose origin joins the Caller Identity. */
35
+ readonly url?: string;
36
+ };
37
+ type WebSocketLinkOptions = {
38
+ /** The name `reach` finds this link by, as for a MessagePort link. */
39
+ name?: string;
40
+ /**
41
+ * The server's key fingerprint, checked against the key it proves. An
42
+ * address `wss://HOST/PATH#FINGERPRINT` pins it too.
43
+ */
44
+ pin?: string;
45
+ /** Sent in the `hello` for the server's `authenticate`. */
46
+ token?: string;
47
+ };
48
+ /** Caller Identity data, merged into `{key, via: "ws"}`. */
49
+ type WebSocketCaller = Readonly<Record<string, Value | string>>;
50
+ type AcceptWebSocketOptions = {
51
+ /**
52
+ * Checks the `hello`'s token, undefined when it has none: the data it gives
53
+ * joins the Caller Identity, and undefined or a throw refuses the
54
+ * connection, which closes before any Remote Send.
55
+ */
56
+ authenticate?: (token: string | undefined) => WebSocketCaller | undefined | Promise<WebSocketCaller | undefined>;
57
+ /** The name `reach` finds this link by. */
58
+ name?: string;
59
+ };
60
+ /**
61
+ * A link to the server at the other end of a WebSocket the caller opened,
62
+ * as a browser does. The server's key is proved, and checked against the
63
+ * pin when one is given.
64
+ */
65
+ export declare const webSocketLink: (socket: WebSocketEndpoint, options?: WebSocketLinkOptions) => PeerLink;
66
+ /**
67
+ * A link to the Host that opened a WebSocket to this server, from the
68
+ * server's socket adapted to a `WebSocketEndpoint`. The other key is proved,
69
+ * and `authenticate` checks the token before any Remote Send arrives.
70
+ */
71
+ export declare const acceptWebSocket: (socket: WebSocketEndpoint, options?: AcceptWebSocketOptions) => PeerLink;
72
+ //#endregion
73
+ //#region src/peer.d.ts
74
+ /**
75
+ * What a link tells the router: each whole frame it receives, its close, and
76
+ * when it has learned the other Host's key, for a link that starts without it.
77
+ */
78
+ export type PeerLinkEvents = {
79
+ close(): void;
80
+ frame(text: string): void;
81
+ keyed(): void;
82
+ };
83
+ /**
84
+ * One connection to another Host. It moves whole frames, each the Value
85
+ * Encoding's JSON text, and says who the other Host is. A link hands the
86
+ * router frames only once `open` gives it somewhere to put them.
87
+ */
88
+ export type PeerLink = {
89
+ /** The address `reach` names this link by, such as a port's name. */
90
+ readonly address?: string;
91
+ close(): void;
92
+ /** Whether the link has closed: it sends nothing more. */
93
+ readonly closed: boolean;
94
+ /**
95
+ * The Caller Identity data for what arrives on this link: what this Host
96
+ * vouches for about the other one, or Nothing when it vouches for nobody.
97
+ */
98
+ readonly identity: Value;
99
+ /**
100
+ * The other Host's key fingerprint, or empty until the link learns it and
101
+ * calls `keyed`. It hands the router no frame before then.
102
+ */
103
+ readonly key: string;
104
+ /**
105
+ * Starts the link; `own` is this Host's key, for a link that sends it, and
106
+ * `signer` proves it, for a link that must.
107
+ */
108
+ open(events: PeerLinkEvents, own: string, signer?: HostSigner): void;
109
+ /** Sends one frame; false when it can't, as when closed or too large. */
110
+ send(frame: string): boolean;
111
+ };
112
+ /**
113
+ * What proves a Host holds its key: the key's DER SubjectPublicKeyInfo, and
114
+ * its ECDSA P-256 SHA-256 signature over some bytes, as the 64 bytes of `r`
115
+ * then `s`, as WebCrypto gives it.
116
+ */
117
+ export type HostSigner = {
118
+ sign(data: Uint8Array): Promise<Uint8Array>;
119
+ readonly spki: Uint8Array;
120
+ };
121
+ export type PeerRouterOptions = {
122
+ /** For a Peer naming a key with no open link: the address that dials it. */
123
+ addressOf?: (key: string) => string | undefined;
124
+ /** A link to the Host an address names, for `reach`; undefined when none. */
125
+ dial?: (address: string) => Promise<PeerLink | undefined>;
126
+ /** This Host's key fingerprint. */
127
+ key: string;
128
+ /** Proves this Host holds that key, for a link that asks, as a WebSocket does. */
129
+ signer?: HostSigner;
130
+ };
131
+ /** A key fingerprint: lowercase hex SHA-256 of the DER SubjectPublicKeyInfo. */
132
+ export declare const fingerprintOf: (spki: BufferSource) => Promise<string>;
133
+ /** A new ECDSA P-256 Host key and its fingerprint. */
134
+ export declare const newHostKey: () => Promise<{
135
+ fingerprint: string;
136
+ keys: CryptoKeyPair;
137
+ signer: HostSigner;
138
+ }>;
139
+ /** A Host's side of `peer`: its exposures and the links to other Hosts. */
140
+ export declare class PeerRouter {
141
+ private readonly o;
142
+ readonly key: string;
143
+ private group;
144
+ private readonly exposures;
145
+ private readonly names;
146
+ private readonly peers;
147
+ private readonly wires;
148
+ private readonly byKey;
149
+ private readonly callers;
150
+ constructor(o: PeerRouterOptions);
151
+ /** A router for the Group, with a new Host key unless the options give one. */
152
+ static create(group: TsGroup, options?: Partial<PeerRouterOptions>): Promise<PeerRouter>;
153
+ /** Gives the router its Group, whose Scripts its exposures name. */
154
+ bind(group: TsGroup): void;
155
+ /** Carries Remote Sends over a link. The newest link to a key carries what this Host sends there. */
156
+ connect(link: PeerLink): void;
157
+ /** Closes every link. */
158
+ close(): void;
159
+ /**
160
+ * The wire for a dialled link, or undefined when there is none: the dial
161
+ * found nothing, rejected, or gave a closed link. Only the dial's own
162
+ * rejection is caught, so a fault in what uses the wire still surfaces.
163
+ */
164
+ private wireFor;
165
+ /** A link to the Host with this key, dialled if the Host knows its address. */
166
+ private wireTo;
167
+ /** This Group's one Peer for an exposure id. */
168
+ private peerFor;
169
+ private local;
170
+ private arrive;
171
+ /** The `peerCapability` implementation. */
172
+ readonly impl: PeerImpl;
173
+ private withdraw;
174
+ private release;
175
+ private expose;
176
+ private reach;
177
+ private send;
178
+ }
179
+ //#endregion
180
+ export type { AcceptWebSocketOptions, MessagePortLinkOptions, PortEndpoint, WebSocketEndpoint, WebSocketLinkOptions };