@kumiai/rpc 0.9.1 → 0.10.1
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 +120 -13
- package/lib/app-aad.d.ts +8 -0
- package/lib/app-aad.js +28 -0
- package/lib/app-lane.d.ts +37 -20
- package/lib/app-lane.js +404 -67
- package/lib/commit-frame.js +3 -0
- package/lib/crypto.d.ts +106 -31
- package/lib/crypto.js +49 -7
- package/lib/cursor.d.ts +4 -0
- package/lib/cursor.js +10 -0
- package/lib/directed.d.ts +3 -4
- package/lib/directed.js +9 -3
- package/lib/handlers.d.ts +12 -1
- package/lib/handlers.js +6 -2
- package/lib/handshake.d.ts +3 -6
- package/lib/handshake.js +13 -6
- package/lib/host-notice.d.ts +1 -0
- package/lib/host-notice.js +12 -0
- package/lib/index.d.ts +5 -2
- package/lib/index.js +3 -2
- package/lib/open-once.d.ts +11 -9
- package/lib/open-once.js +18 -12
- package/lib/peer.d.ts +49 -4
- package/lib/peer.js +796 -305
- package/package.json +13 -13
package/lib/open-once.js
CHANGED
|
@@ -13,22 +13,29 @@
|
|
|
13
13
|
* path, not its bus view, because only the raw path carries the frame's log position. The
|
|
14
14
|
* subscription is released with the last consumer, so a rotation's teardown leaves nothing behind.
|
|
15
15
|
*/ export function createOpenOncePath(params) {
|
|
16
|
-
const { mux, topicID, unwrap, project, note, retainOnFailure } = params;
|
|
16
|
+
const { mux, topicID, unwrap, project, note, wakeup, retainOnFailure } = params;
|
|
17
17
|
const listeners = new Set();
|
|
18
18
|
let unsubscribe;
|
|
19
19
|
let opening = Promise.resolve();
|
|
20
20
|
return (onOpened)=>{
|
|
21
21
|
listeners.add(onOpened);
|
|
22
22
|
unsubscribe ??= mux.onInbound(topicID, (message, ack)=>{
|
|
23
|
-
|
|
23
|
+
if (wakeup?.(message) === true) {
|
|
24
|
+
ack();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
24
27
|
// Every outcome is HANDLED — opened, or permanently unopenable — except a failure
|
|
25
28
|
// `retainOnFailure` says is not yet reachable, which flips this false to withhold the ack.
|
|
26
29
|
let handled = true;
|
|
27
30
|
opening = opening.then(async ()=>{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
payload
|
|
31
|
-
}
|
|
31
|
+
let opened;
|
|
32
|
+
try {
|
|
33
|
+
opened = await unwrap(message.payload);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
note?.(message, error);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
note?.(message, undefined);
|
|
32
39
|
const value = project(message, opened);
|
|
33
40
|
if (value === undefined) return;
|
|
34
41
|
// Snapshot: a consumer disposing from inside its own delivery must not perturb the
|
|
@@ -36,13 +43,12 @@
|
|
|
36
43
|
for (const listener of [
|
|
37
44
|
...listeners
|
|
38
45
|
])listener(value);
|
|
39
|
-
}).catch(()=>{
|
|
46
|
+
}).catch((error)=>{
|
|
40
47
|
// A frame this handle cannot open — another epoch's, another group's, or not a frame at
|
|
41
|
-
// all — is ordinary on a shared log; one failure must not break the chain.
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
if (retainOnFailure?.(message) === true) handled = false;
|
|
48
|
+
// all — is ordinary on a shared log; one failure must not break the chain. A frame sealed
|
|
49
|
+
// ahead will open once the handle catches up, so acking it would reclaim a frame never
|
|
50
|
+
// handled; `retainOnFailure` reads that from the open's own refusal.
|
|
51
|
+
if (retainOnFailure?.(message, error) === true) handled = false;
|
|
46
52
|
}).finally(()=>{
|
|
47
53
|
// Acked once the frame's link settles, unless `handled` was flipped false. Acking on
|
|
48
54
|
// arrival would release it before the open that consumes its ratchet key ran.
|
package/lib/peer.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { Client } from '@enkaku/client';
|
|
2
2
|
import type { DataOf, EventProcedureDefinition, ProtocolDefinition, RequestProcedureDefinition, ReturnOf } from '@enkaku/protocol';
|
|
3
|
-
import type { ProcedureHandlers } from '@enkaku/server';
|
|
4
3
|
import { type GatheredReply, type GatherOptions, type RequestOptions, type SuppressConfig } from '@kumiai/broadcast';
|
|
5
4
|
import type { LogHub } from '@kumiai/hub-tunnel';
|
|
6
5
|
import { type Runtime } from '@sozai/runtime';
|
|
7
6
|
import type { AnchorStore } from './anchor.js';
|
|
8
7
|
import type { AppCursorStore, AppWindowPruned } from './app-cursor.js';
|
|
8
|
+
import { type AppDeliveryResumed, type AppDeliveryStalled } from './app-lane.js';
|
|
9
9
|
import { type CommitJournal, type LaneResult, type PendingCommit } from './commit.js';
|
|
10
10
|
import { type GroupCrypto, type GroupMLS } from './crypto.js';
|
|
11
|
+
import { type GroupProcedureHandlers } from './handlers.js';
|
|
11
12
|
import { type ReceiveLaneEnded, type SubscribeFailure } from './hub-mux.js';
|
|
12
13
|
import { type GroupProtocolDefinition } from './protocol.js';
|
|
13
14
|
/**
|
|
@@ -64,13 +65,49 @@ export type GroupPeerMLSParams = {
|
|
|
64
65
|
*/
|
|
65
66
|
adoptJournalled: (journal: Uint8Array) => Promise<void>;
|
|
66
67
|
};
|
|
68
|
+
export type StrandKind = 'own-unmerged' | 'fork-losing' | 'ahead' | 'unknown-version';
|
|
69
|
+
/**
|
|
70
|
+
* For `own-unmerged`, `authenticated` means this device sealed a commit at this epoch that the
|
|
71
|
+
* hub now places in the log. `readCommitHeader` identifies its leaf from PrivateMessage sender
|
|
72
|
+
* data, AEAD-opened with this epoch's `sender_data_secret` and a ciphertext sample. Commit content
|
|
73
|
+
* is unverified; a hub can tamper past the sample and serve a captured, rejected frame.
|
|
74
|
+
*/
|
|
75
|
+
export type StrandConfidence = 'authenticated' | 'observed' | 'claimed';
|
|
76
|
+
/** A stranded-frame notice. `own-unmerged` does not prove commit content or hub acceptance; heal. */
|
|
77
|
+
export type StrandObservation = {
|
|
78
|
+
groupID: string;
|
|
79
|
+
position: string;
|
|
80
|
+
commitDigest: string | null;
|
|
81
|
+
localEpoch: number;
|
|
82
|
+
claimedEpoch: number | null;
|
|
83
|
+
kind: StrandKind;
|
|
84
|
+
confidence: StrandConfidence;
|
|
85
|
+
};
|
|
86
|
+
export type RecoveryTrigger = 'automatic' | 'consumer';
|
|
87
|
+
export type RecoveryFailureReason = 'no-responder' | 'bootstrap-failed' | 'deadline' | 'disposed' | 'error';
|
|
88
|
+
type RecoveryEventBase = {
|
|
89
|
+
groupID: string;
|
|
90
|
+
attemptID: string;
|
|
91
|
+
trigger: RecoveryTrigger;
|
|
92
|
+
};
|
|
93
|
+
export type RecoveryEvent = (RecoveryEventBase & {
|
|
94
|
+
phase: 'started';
|
|
95
|
+
}) | (RecoveryEventBase & {
|
|
96
|
+
phase: 'succeeded';
|
|
97
|
+
}) | (RecoveryEventBase & {
|
|
98
|
+
phase: 'failed';
|
|
99
|
+
reason: RecoveryFailureReason;
|
|
100
|
+
error?: unknown;
|
|
101
|
+
}) | (RecoveryEventBase & {
|
|
102
|
+
phase: 'bootstrapped';
|
|
103
|
+
});
|
|
67
104
|
export type GroupPeerParams<Protocols extends Record<string, GroupProtocolDefinition>> = {
|
|
68
105
|
hub: LogHub;
|
|
69
106
|
crypto: GroupCrypto;
|
|
70
107
|
localDID: string;
|
|
71
108
|
protocols: Protocols;
|
|
72
109
|
handlers: {
|
|
73
|
-
[K in keyof Protocols]:
|
|
110
|
+
[K in keyof Protocols]: GroupProcedureHandlers<Protocols[K]>;
|
|
74
111
|
};
|
|
75
112
|
suppress?: SuppressConfig;
|
|
76
113
|
/** Runtime providing platform primitives. Defaults to `createRuntime()`. */
|
|
@@ -112,6 +149,10 @@ export type GroupPeerParams<Protocols extends Record<string, GroupProtocolDefini
|
|
|
112
149
|
* Fire-and-forget: a throw is swallowed and the drain carries on.
|
|
113
150
|
*/
|
|
114
151
|
onAppWindowPruned?: (event: AppWindowPruned) => void | Promise<void>;
|
|
152
|
+
onStrand?: (observation: StrandObservation) => void | Promise<void>;
|
|
153
|
+
onRecovery?: (event: RecoveryEvent) => void | Promise<void>;
|
|
154
|
+
onAppDeliveryStalled?: (event: AppDeliveryStalled) => void | Promise<void>;
|
|
155
|
+
onAppDeliveryResumed?: (event: AppDeliveryResumed) => void | Promise<void>;
|
|
115
156
|
/**
|
|
116
157
|
* Called when the hub definitively refuses to subscribe this peer to a topic — most plausibly a
|
|
117
158
|
* retention setting above the operator's own cap, which a hub refuses rather than clamps.
|
|
@@ -169,9 +210,9 @@ type ProtocolSurfaceOf<Protocol extends GroupProtocolDefinition, Events extends
|
|
|
169
210
|
} & RequestOptions]) => Promise<T['Result']>;
|
|
170
211
|
gather: <P extends keyof Requests & string, T extends Requests[P] = Requests[P]>(prc: P, ...args: T['Param'] extends never ? [config?: {
|
|
171
212
|
param?: never;
|
|
172
|
-
} & GatherOptions] : [config: {
|
|
213
|
+
} & GatherOptions<T['Result']>] : [config: {
|
|
173
214
|
param: T['Param'];
|
|
174
|
-
} & GatherOptions]) => Promise<Array<GatheredReply<T['Result']>>>;
|
|
215
|
+
} & GatherOptions<T['Result']>]) => Promise<Array<GatheredReply<T['Result']>>>;
|
|
175
216
|
to: (memberDID: string) => Promise<Client<Protocol>>;
|
|
176
217
|
};
|
|
177
218
|
export type InternalSurface = {
|
|
@@ -188,6 +229,10 @@ export type InternalSurface = {
|
|
|
188
229
|
};
|
|
189
230
|
export type GroupPeer<Protocols extends Record<string, GroupProtocolDefinition>> = {
|
|
190
231
|
protocol: <K extends keyof Protocols>(name: K) => ProtocolSurface<Protocols[K]>;
|
|
232
|
+
/** Accept loss of one buffered sealed app frame, then resume the journal-first walk. */
|
|
233
|
+
dropAppFrame: (topicID: string, position: string) => Promise<void>;
|
|
234
|
+
/** Schedule an immediate app pull and wake matching delivery workers. No-op after disposal. */
|
|
235
|
+
retryAppDelivery: (topicID?: string) => Promise<void>;
|
|
191
236
|
/**
|
|
192
237
|
* Commit to the group, rebasing until it lands.
|
|
193
238
|
*
|