@graphrefly/ts 0.0.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/LICENSE +21 -0
- package/dist/adapters/index.cjs +9015 -0
- package/dist/adapters/index.cjs.map +1 -0
- package/dist/adapters/index.d.cts +678 -0
- package/dist/adapters/index.d.ts +678 -0
- package/dist/adapters/index.js +2894 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/observe-storage.cjs +260 -0
- package/dist/adapters/observe-storage.cjs.map +1 -0
- package/dist/adapters/observe-storage.d.cts +77 -0
- package/dist/adapters/observe-storage.d.ts +77 -0
- package/dist/adapters/observe-storage.js +161 -0
- package/dist/adapters/observe-storage.js.map +1 -0
- package/dist/append-log-DisvEReb.d.cts +189 -0
- package/dist/append-log-DzKMmjxx.d.ts +189 -0
- package/dist/chunk-2ILL7HQI.js +1189 -0
- package/dist/chunk-2ILL7HQI.js.map +1 -0
- package/dist/chunk-4VLAQHZI.js +330 -0
- package/dist/chunk-4VLAQHZI.js.map +1 -0
- package/dist/chunk-6PHB5CJS.js +229 -0
- package/dist/chunk-6PHB5CJS.js.map +1 -0
- package/dist/chunk-COHO25CZ.js +2449 -0
- package/dist/chunk-COHO25CZ.js.map +1 -0
- package/dist/chunk-D6BG7U6A.js +161 -0
- package/dist/chunk-D6BG7U6A.js.map +1 -0
- package/dist/chunk-DJC4CHLQ.js +818 -0
- package/dist/chunk-DJC4CHLQ.js.map +1 -0
- package/dist/chunk-DK554R7P.js +67 -0
- package/dist/chunk-DK554R7P.js.map +1 -0
- package/dist/chunk-DKP56CSW.js +322 -0
- package/dist/chunk-DKP56CSW.js.map +1 -0
- package/dist/chunk-G4M3NHRJ.js +688 -0
- package/dist/chunk-G4M3NHRJ.js.map +1 -0
- package/dist/chunk-GAJW5I5P.js +1 -0
- package/dist/chunk-GAJW5I5P.js.map +1 -0
- package/dist/chunk-GDL26N2T.js +282 -0
- package/dist/chunk-GDL26N2T.js.map +1 -0
- package/dist/chunk-GTPCOEOZ.js +741 -0
- package/dist/chunk-GTPCOEOZ.js.map +1 -0
- package/dist/chunk-H2HTHFVN.js +1 -0
- package/dist/chunk-H2HTHFVN.js.map +1 -0
- package/dist/chunk-HDRL4VQQ.js +218 -0
- package/dist/chunk-HDRL4VQQ.js.map +1 -0
- package/dist/chunk-I3IHOHCJ.js +2267 -0
- package/dist/chunk-I3IHOHCJ.js.map +1 -0
- package/dist/chunk-JIMUDQN3.js +965 -0
- package/dist/chunk-JIMUDQN3.js.map +1 -0
- package/dist/chunk-JR4IKCR2.js +462 -0
- package/dist/chunk-JR4IKCR2.js.map +1 -0
- package/dist/chunk-K3FXTC3I.js +165 -0
- package/dist/chunk-K3FXTC3I.js.map +1 -0
- package/dist/chunk-OOEN33FB.js +65 -0
- package/dist/chunk-OOEN33FB.js.map +1 -0
- package/dist/chunk-PKVBHGBM.js +554 -0
- package/dist/chunk-PKVBHGBM.js.map +1 -0
- package/dist/chunk-RIIOUTGM.js +1857 -0
- package/dist/chunk-RIIOUTGM.js.map +1 -0
- package/dist/chunk-SCRFRCGR.js +33 -0
- package/dist/chunk-SCRFRCGR.js.map +1 -0
- package/dist/chunk-SWTLEQL6.js +53 -0
- package/dist/chunk-SWTLEQL6.js.map +1 -0
- package/dist/chunk-SZAETNNA.js +1 -0
- package/dist/chunk-SZAETNNA.js.map +1 -0
- package/dist/chunk-TEW47IVR.js +49 -0
- package/dist/chunk-TEW47IVR.js.map +1 -0
- package/dist/chunk-Y3ZLRGHC.js +1482 -0
- package/dist/chunk-Y3ZLRGHC.js.map +1 -0
- package/dist/chunk-Z2ANQ6JW.js +149 -0
- package/dist/chunk-Z2ANQ6JW.js.map +1 -0
- package/dist/codec-BB7p8fJc.d.cts +38 -0
- package/dist/codec-BB7p8fJc.d.ts +38 -0
- package/dist/composition/index.cjs +2505 -0
- package/dist/composition/index.cjs.map +1 -0
- package/dist/composition/index.d.cts +95 -0
- package/dist/composition/index.d.ts +95 -0
- package/dist/composition/index.js +19 -0
- package/dist/composition/index.js.map +1 -0
- package/dist/core/index.cjs +2475 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +25 -0
- package/dist/core/index.d.ts +25 -0
- package/dist/core/index.js +74 -0
- package/dist/core/index.js.map +1 -0
- package/dist/cqrs/index.cjs +595 -0
- package/dist/cqrs/index.cjs.map +1 -0
- package/dist/cqrs/index.d.cts +200 -0
- package/dist/cqrs/index.d.ts +200 -0
- package/dist/cqrs/index.js +557 -0
- package/dist/cqrs/index.js.map +1 -0
- package/dist/data-structures/index.cjs +4277 -0
- package/dist/data-structures/index.cjs.map +1 -0
- package/dist/data-structures/index.d.cts +22 -0
- package/dist/data-structures/index.d.ts +22 -0
- package/dist/data-structures/index.js +31 -0
- package/dist/data-structures/index.js.map +1 -0
- package/dist/describe-BZb7AS2y.d.ts +57 -0
- package/dist/describe-Ciu8SUnN.d.cts +57 -0
- package/dist/graph/index.cjs +7832 -0
- package/dist/graph/index.cjs.map +1 -0
- package/dist/graph/index.d.cts +251 -0
- package/dist/graph/index.d.ts +251 -0
- package/dist/graph/index.js +131 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph-DfdF9zy4.d.ts +666 -0
- package/dist/graph-s23RbbFO.d.cts +666 -0
- package/dist/index-CAEmLCYF.d.cts +166 -0
- package/dist/index-SnzZu3x7.d.ts +166 -0
- package/dist/index.cjs +15409 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +582 -0
- package/dist/index.js.map +1 -0
- package/dist/messages-BZqrGGm1.d.cts +55 -0
- package/dist/messages-BZqrGGm1.d.ts +55 -0
- package/dist/messaging/index.cjs +818 -0
- package/dist/messaging/index.cjs.map +1 -0
- package/dist/messaging/index.d.cts +235 -0
- package/dist/messaging/index.d.ts +235 -0
- package/dist/messaging/index.js +767 -0
- package/dist/messaging/index.js.map +1 -0
- package/dist/observe-event-log-0SVsx7JG.d.cts +88 -0
- package/dist/observe-event-log-Dnm76owp.d.ts +88 -0
- package/dist/operators/index.cjs +3774 -0
- package/dist/operators/index.cjs.map +1 -0
- package/dist/operators/index.d.cts +308 -0
- package/dist/operators/index.d.ts +308 -0
- package/dist/operators/index.js +112 -0
- package/dist/operators/index.js.map +1 -0
- package/dist/orchestration/index.cjs +3541 -0
- package/dist/orchestration/index.cjs.map +1 -0
- package/dist/orchestration/index.d.cts +302 -0
- package/dist/orchestration/index.d.ts +302 -0
- package/dist/orchestration/index.js +1004 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/patterns/index.cjs +1045 -0
- package/dist/patterns/index.cjs.map +1 -0
- package/dist/patterns/index.d.cts +39 -0
- package/dist/patterns/index.d.ts +39 -0
- package/dist/patterns/index.js +33 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/reactive-collection-BxBqtIOE.d.cts +344 -0
- package/dist/reactive-collection-Cb1II1Fi.d.ts +344 -0
- package/dist/reactive-collection-storage-BNiEc-Gd.d.ts +217 -0
- package/dist/reactive-collection-storage-D-KmjE0J.d.cts +217 -0
- package/dist/reactive-map-BcB4KsQR.d.ts +256 -0
- package/dist/reactive-map-D-g3dv8I.d.cts +256 -0
- package/dist/read-through-B1CYPfq_.d.cts +82 -0
- package/dist/read-through-DwyJhGs1.d.ts +82 -0
- package/dist/render/index.cjs +250 -0
- package/dist/render/index.cjs.map +1 -0
- package/dist/render/index.d.cts +58 -0
- package/dist/render/index.d.ts +58 -0
- package/dist/render/index.js +20 -0
- package/dist/render/index.js.map +1 -0
- package/dist/resilience-Dig3Q7n0.d.cts +45 -0
- package/dist/resilience-Dig3Q7n0.d.ts +45 -0
- package/dist/semantic-memory-graph-BYoIlP35.d.cts +356 -0
- package/dist/semantic-memory-graph-CxyXLms3.d.ts +356 -0
- package/dist/solutions/index.cjs +3249 -0
- package/dist/solutions/index.cjs.map +1 -0
- package/dist/solutions/index.d.cts +520 -0
- package/dist/solutions/index.d.ts +520 -0
- package/dist/solutions/index.js +31 -0
- package/dist/solutions/index.js.map +1 -0
- package/dist/sources/browser.cjs +3095 -0
- package/dist/sources/browser.cjs.map +1 -0
- package/dist/sources/browser.d.cts +39 -0
- package/dist/sources/browser.d.ts +39 -0
- package/dist/sources/browser.js +137 -0
- package/dist/sources/browser.js.map +1 -0
- package/dist/sources/index.cjs +3021 -0
- package/dist/sources/index.cjs.map +1 -0
- package/dist/sources/index.d.cts +7 -0
- package/dist/sources/index.d.ts +7 -0
- package/dist/sources/index.js +63 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/node.cjs +675 -0
- package/dist/sources/node.cjs.map +1 -0
- package/dist/sources/node.d.cts +109 -0
- package/dist/sources/node.d.ts +109 -0
- package/dist/sources/node.js +639 -0
- package/dist/sources/node.js.map +1 -0
- package/dist/storage/browser.cjs +777 -0
- package/dist/storage/browser.cjs.map +1 -0
- package/dist/storage/browser.d.cts +40 -0
- package/dist/storage/browser.d.ts +40 -0
- package/dist/storage/browser.js +275 -0
- package/dist/storage/browser.js.map +1 -0
- package/dist/storage/index.cjs +1989 -0
- package/dist/storage/index.cjs.map +1 -0
- package/dist/storage/index.d.cts +92 -0
- package/dist/storage/index.d.ts +92 -0
- package/dist/storage/index.js +161 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/node.cjs +898 -0
- package/dist/storage/node.cjs.map +1 -0
- package/dist/storage/node.d.cts +66 -0
- package/dist/storage/node.d.ts +66 -0
- package/dist/storage/node.js +402 -0
- package/dist/storage/node.js.map +1 -0
- package/dist/testing/index.cjs +95 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +20 -0
- package/dist/testing/index.d.ts +20 -0
- package/dist/testing/index.js +8 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/types-bNMSWKqF.d.cts +732 -0
- package/dist/types-h12mNYbq.d.ts +732 -0
- package/package.json +250 -0
|
@@ -0,0 +1,732 @@
|
|
|
1
|
+
import { L as LockId, W as Wave, M as Message } from './messages-BZqrGGm1.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dispatcher, pools, and the pure-data Handle.
|
|
5
|
+
*
|
|
6
|
+
* Canonical authority: ~/src/graphrefly/spec/rules.jsonl
|
|
7
|
+
* R-handle (D7), R-dispatch-all (D21), R-sync-core (D20/D21).
|
|
8
|
+
*
|
|
9
|
+
* Lifted from the validated handle-dispatch PoC (packages/pure-ts r8-poc, R8/R9):
|
|
10
|
+
* fn lives in an external pool, indexed by handle; `dispatcher.invoke` is uniformly
|
|
11
|
+
* SYNC void — async/remote behavior lives in the fn body (it kicks off async work
|
|
12
|
+
* and emits later via `ctx.down`), not in a different call mechanism.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** A pool kind label. LocalSync + LocalAsync ship in 1.0 (D20). */
|
|
16
|
+
type PoolKind = "sync" | "async";
|
|
17
|
+
/**
|
|
18
|
+
* Handle = pure data `(poolId, handleId)`, NO methods (R-handle / D7). A serializable
|
|
19
|
+
* index into a pool's dispatch table. node != handle.
|
|
20
|
+
*/
|
|
21
|
+
interface Handle {
|
|
22
|
+
readonly poolId: number;
|
|
23
|
+
readonly handleId: number;
|
|
24
|
+
}
|
|
25
|
+
/** A dispatch pool: a flat fn table + an array-indexed sync invoke. */
|
|
26
|
+
interface Pool {
|
|
27
|
+
readonly kind: PoolKind;
|
|
28
|
+
register(fn: NodeFn): number;
|
|
29
|
+
/** Free a handle's slot so its fn closure is GC'd and the id is reused (B15). */
|
|
30
|
+
unregister(handleId: number): void;
|
|
31
|
+
invoke(handleId: number, ctx: Ctx): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* First-class dispatcher (D21). Owns pools; graph binds to one (default = process-global,
|
|
35
|
+
* D26 — the only global singleton). Pool trait is pluggable for WorkerPool/RemotePool (D20).
|
|
36
|
+
*/
|
|
37
|
+
/** Per-handle profiling counters (D39 / R-profile). Lives on the dispatcher — the invoke
|
|
38
|
+
* funnel (F-DISPATCH-ALL) — NEVER on the thin node (R-node-thin). */
|
|
39
|
+
interface HandleStat {
|
|
40
|
+
invokes: number;
|
|
41
|
+
totalDurationNs: number;
|
|
42
|
+
lastDurationNs: number;
|
|
43
|
+
}
|
|
44
|
+
declare class Dispatcher {
|
|
45
|
+
private pools;
|
|
46
|
+
readonly syncPoolId: number;
|
|
47
|
+
readonly asyncPoolId: number;
|
|
48
|
+
private _recording;
|
|
49
|
+
private _stats;
|
|
50
|
+
private _totalInvokes;
|
|
51
|
+
constructor();
|
|
52
|
+
/** Turn the profile recorder on/off (D39). Off = zero overhead on invoke. */
|
|
53
|
+
setRecording(on: boolean): void;
|
|
54
|
+
/** Reset accumulated profiling counters. */
|
|
55
|
+
clearStats(): void;
|
|
56
|
+
/** Read a handle's accumulated counters (undefined if it never ran while recording). */
|
|
57
|
+
statFor(handle: Handle): HandleStat | undefined;
|
|
58
|
+
/** Total fn invocations recorded across the dispatcher. */
|
|
59
|
+
get totalInvokes(): number;
|
|
60
|
+
addPool(pool: Pool): number;
|
|
61
|
+
/** Register a fn in a pool, returning its Handle. Default pool = sync (R-sync-core). */
|
|
62
|
+
register(fn: NodeFn, pool?: PoolKind | number): Handle;
|
|
63
|
+
/**
|
|
64
|
+
* Release a handle (B15): frees the pool slot (closure GC'd, id reusable) and drops any
|
|
65
|
+
* accumulated profile stat so a reused id never inherits the previous tenant's counters.
|
|
66
|
+
* Called on rewire fn-swap (node._rewire) — the old handle is dropped before the node
|
|
67
|
+
* adopts the new one. Idempotent. NOT called on deactivate (a node's handle survives
|
|
68
|
+
* activate↔deactivate and is reused on reactivation; only a rewire swaps it).
|
|
69
|
+
*/
|
|
70
|
+
unregister(handle: Handle): void;
|
|
71
|
+
/** Uniform sync-void invoke (R-sync-core / R-dispatch-all). */
|
|
72
|
+
invoke(handle: Handle, ctx: Ctx): void;
|
|
73
|
+
poolKind(poolId: number): PoolKind;
|
|
74
|
+
}
|
|
75
|
+
/** The only global singleton (D26). Overridable by passing an explicit dispatcher. */
|
|
76
|
+
declare const defaultDispatcher: Dispatcher;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Graph-owned environment driver bag (D130/D131).
|
|
80
|
+
*
|
|
81
|
+
* Drivers host process/network/messaging/runtime boundary work outside the synchronous wave core.
|
|
82
|
+
* The bag is graph-local and is read from ctx by source/adapter bodies.
|
|
83
|
+
*/
|
|
84
|
+
type DriverCancel = () => void;
|
|
85
|
+
type DriverResult<T> = {
|
|
86
|
+
readonly ok: true;
|
|
87
|
+
readonly value: T;
|
|
88
|
+
} | {
|
|
89
|
+
readonly ok: false;
|
|
90
|
+
readonly error: unknown;
|
|
91
|
+
};
|
|
92
|
+
interface ProcessCommand {
|
|
93
|
+
readonly program: string;
|
|
94
|
+
readonly args: readonly string[];
|
|
95
|
+
readonly cwd?: string;
|
|
96
|
+
readonly env?: readonly (readonly [string, string])[];
|
|
97
|
+
}
|
|
98
|
+
interface ProcessResult {
|
|
99
|
+
readonly stdout: string;
|
|
100
|
+
readonly stderr: string;
|
|
101
|
+
readonly exitCode: number | null;
|
|
102
|
+
readonly signal: string | null;
|
|
103
|
+
}
|
|
104
|
+
interface HttpRequest {
|
|
105
|
+
readonly method: string;
|
|
106
|
+
readonly url: string;
|
|
107
|
+
readonly headers?: readonly (readonly [string, string])[];
|
|
108
|
+
readonly body?: Uint8Array | string;
|
|
109
|
+
}
|
|
110
|
+
interface HttpResponse {
|
|
111
|
+
readonly status: number;
|
|
112
|
+
readonly headers: readonly (readonly [string, string])[];
|
|
113
|
+
readonly body: Uint8Array;
|
|
114
|
+
}
|
|
115
|
+
interface SseRequest {
|
|
116
|
+
readonly url: string;
|
|
117
|
+
readonly headers?: readonly (readonly [string, string])[];
|
|
118
|
+
}
|
|
119
|
+
interface SseEvent {
|
|
120
|
+
readonly event?: string;
|
|
121
|
+
readonly data: string;
|
|
122
|
+
readonly id?: string;
|
|
123
|
+
readonly retryMs?: number;
|
|
124
|
+
}
|
|
125
|
+
type SseDriverEvent = {
|
|
126
|
+
readonly kind: "event";
|
|
127
|
+
readonly event: SseEvent;
|
|
128
|
+
} | {
|
|
129
|
+
readonly kind: "error";
|
|
130
|
+
readonly error: unknown;
|
|
131
|
+
} | {
|
|
132
|
+
readonly kind: "complete";
|
|
133
|
+
};
|
|
134
|
+
interface WebSocketRequest {
|
|
135
|
+
readonly url: string;
|
|
136
|
+
readonly headers?: readonly (readonly [string, string])[];
|
|
137
|
+
}
|
|
138
|
+
type WebSocketEvent = {
|
|
139
|
+
readonly kind: "open";
|
|
140
|
+
} | {
|
|
141
|
+
readonly kind: "text";
|
|
142
|
+
readonly data: string;
|
|
143
|
+
} | {
|
|
144
|
+
readonly kind: "binary";
|
|
145
|
+
readonly data: Uint8Array;
|
|
146
|
+
} | {
|
|
147
|
+
readonly kind: "close";
|
|
148
|
+
readonly code?: number;
|
|
149
|
+
readonly reason?: string;
|
|
150
|
+
};
|
|
151
|
+
interface WebSocketSend {
|
|
152
|
+
readonly data: string | Uint8Array;
|
|
153
|
+
}
|
|
154
|
+
interface WebSocketSendResult {
|
|
155
|
+
readonly sent: true;
|
|
156
|
+
}
|
|
157
|
+
/** Live WebSocket session handle for D133 SessionBundle adapters. */
|
|
158
|
+
interface WebSocketSessionHandle {
|
|
159
|
+
send(message: WebSocketSend, callback: (result: DriverResult<WebSocketSendResult>) => void): DriverCancel;
|
|
160
|
+
close(code?: number, reason?: string): void;
|
|
161
|
+
cancel(): void;
|
|
162
|
+
}
|
|
163
|
+
type WebSocketDriverEvent = {
|
|
164
|
+
readonly kind: "event";
|
|
165
|
+
readonly event: WebSocketEvent;
|
|
166
|
+
} | {
|
|
167
|
+
readonly kind: "error";
|
|
168
|
+
readonly error: unknown;
|
|
169
|
+
} | {
|
|
170
|
+
readonly kind: "complete";
|
|
171
|
+
};
|
|
172
|
+
interface WebhookRegistration {
|
|
173
|
+
readonly id: string;
|
|
174
|
+
readonly method?: string;
|
|
175
|
+
readonly path?: string;
|
|
176
|
+
}
|
|
177
|
+
interface WebhookEvent {
|
|
178
|
+
readonly registrationId: string;
|
|
179
|
+
readonly method: string;
|
|
180
|
+
readonly path: string;
|
|
181
|
+
readonly headers: readonly (readonly [string, string])[];
|
|
182
|
+
readonly query: readonly (readonly [string, string])[];
|
|
183
|
+
readonly body: Uint8Array;
|
|
184
|
+
}
|
|
185
|
+
type WebhookDriverEvent = {
|
|
186
|
+
readonly kind: "event";
|
|
187
|
+
readonly event: WebhookEvent;
|
|
188
|
+
} | {
|
|
189
|
+
readonly kind: "error";
|
|
190
|
+
readonly error: unknown;
|
|
191
|
+
} | {
|
|
192
|
+
readonly kind: "complete";
|
|
193
|
+
};
|
|
194
|
+
interface LocalProcessDriver {
|
|
195
|
+
run(command: ProcessCommand, callback: (result: DriverResult<ProcessResult>) => void): DriverCancel;
|
|
196
|
+
}
|
|
197
|
+
interface LocalHttpDriver {
|
|
198
|
+
request(request: HttpRequest, callback: (result: DriverResult<HttpResponse>) => void): DriverCancel;
|
|
199
|
+
}
|
|
200
|
+
interface LocalSseDriver {
|
|
201
|
+
connect(request: SseRequest, callback: (event: SseDriverEvent) => void): DriverCancel;
|
|
202
|
+
}
|
|
203
|
+
interface LocalWebSocketDriver {
|
|
204
|
+
connect(request: WebSocketRequest, callback: (event: WebSocketDriverEvent) => void): DriverCancel;
|
|
205
|
+
send?(request: WebSocketRequest, message: WebSocketSend, callback: (result: DriverResult<WebSocketSendResult>) => void): DriverCancel;
|
|
206
|
+
/** Open a live bidirectional session; unlike send(), outbound messages use this same connection. */
|
|
207
|
+
connectSession?(request: WebSocketRequest, callback: (event: WebSocketDriverEvent) => void): WebSocketSessionHandle;
|
|
208
|
+
}
|
|
209
|
+
interface LocalWebhookDriver {
|
|
210
|
+
register(registration: WebhookRegistration, callback: (event: WebhookDriverEvent) => void): DriverCancel;
|
|
211
|
+
}
|
|
212
|
+
interface FetchResponseLike {
|
|
213
|
+
readonly status: number;
|
|
214
|
+
readonly headers?: {
|
|
215
|
+
forEach?(fn: (value: string, key: string) => void): void;
|
|
216
|
+
};
|
|
217
|
+
arrayBuffer(): PromiseLike<ArrayBuffer>;
|
|
218
|
+
}
|
|
219
|
+
type FetchLike = (url: string, init?: {
|
|
220
|
+
readonly method?: string;
|
|
221
|
+
readonly headers?: readonly (readonly [string, string])[];
|
|
222
|
+
readonly body?: Uint8Array | string;
|
|
223
|
+
readonly signal?: AbortSignal;
|
|
224
|
+
}) => PromiseLike<FetchResponseLike>;
|
|
225
|
+
interface WebSocketLike {
|
|
226
|
+
send(data: string | Uint8Array): void;
|
|
227
|
+
close(code?: number, reason?: string): void;
|
|
228
|
+
addEventListener(type: "open" | "message" | "error" | "close", listener: (event: unknown) => void): void;
|
|
229
|
+
removeEventListener(type: "open" | "message" | "error" | "close", listener: (event: unknown) => void): void;
|
|
230
|
+
}
|
|
231
|
+
type WebSocketConstructorLike = new (url: string) => WebSocketLike;
|
|
232
|
+
interface EnvironmentDriversInit {
|
|
233
|
+
readonly process?: LocalProcessDriver;
|
|
234
|
+
readonly http?: LocalHttpDriver;
|
|
235
|
+
readonly sse?: LocalSseDriver;
|
|
236
|
+
readonly websocket?: LocalWebSocketDriver;
|
|
237
|
+
readonly webhook?: LocalWebhookDriver;
|
|
238
|
+
}
|
|
239
|
+
declare class EnvironmentDrivers {
|
|
240
|
+
readonly process?: LocalProcessDriver;
|
|
241
|
+
readonly http?: LocalHttpDriver;
|
|
242
|
+
readonly sse?: LocalSseDriver;
|
|
243
|
+
readonly websocket?: LocalWebSocketDriver;
|
|
244
|
+
readonly webhook?: LocalWebhookDriver;
|
|
245
|
+
constructor(init?: EnvironmentDriversInit);
|
|
246
|
+
static empty(): EnvironmentDrivers;
|
|
247
|
+
withProcess(driver: LocalProcessDriver): EnvironmentDrivers;
|
|
248
|
+
withHttp(driver: LocalHttpDriver): EnvironmentDrivers;
|
|
249
|
+
withSse(driver: LocalSseDriver): EnvironmentDrivers;
|
|
250
|
+
withWebSocket(driver: LocalWebSocketDriver): EnvironmentDrivers;
|
|
251
|
+
withWebhook(driver: LocalWebhookDriver): EnvironmentDrivers;
|
|
252
|
+
processDriver(): LocalProcessDriver | undefined;
|
|
253
|
+
httpDriver(): LocalHttpDriver | undefined;
|
|
254
|
+
sseDriver(): LocalSseDriver | undefined;
|
|
255
|
+
webSocketDriver(): LocalWebSocketDriver | undefined;
|
|
256
|
+
webhookDriver(): LocalWebhookDriver | undefined;
|
|
257
|
+
}
|
|
258
|
+
declare function fetchHttpDriver(fetchFn?: FetchLike): LocalHttpDriver;
|
|
259
|
+
declare function domWebSocketDriver(WebSocketCtor?: WebSocketConstructorLike): LocalWebSocketDriver;
|
|
260
|
+
|
|
261
|
+
type NodeVersioningLevel = 0 | 1;
|
|
262
|
+
/**
|
|
263
|
+
* D112 V1 node-version hash callback.
|
|
264
|
+
*
|
|
265
|
+
* The callback receives strict canonical JSON UTF-8 DATA bytes, not the raw host value.
|
|
266
|
+
* Runtime V1 versioning encodes DATA with `strictCanonicalJsonBytes(value)` before calling hash.
|
|
267
|
+
*/
|
|
268
|
+
type NodeVersionHashFn = (bytes: Uint8Array) => string;
|
|
269
|
+
type NodeVersioningPolicy = false | 0 | 1 | {
|
|
270
|
+
level: NodeVersioningLevel;
|
|
271
|
+
hash?: NodeVersionHashFn;
|
|
272
|
+
};
|
|
273
|
+
type NodeVersionV0 = {
|
|
274
|
+
readonly level: 0;
|
|
275
|
+
readonly counter: number;
|
|
276
|
+
};
|
|
277
|
+
type NodeVersionV1 = {
|
|
278
|
+
readonly level: 1;
|
|
279
|
+
readonly counter: number;
|
|
280
|
+
readonly cid: string;
|
|
281
|
+
readonly prev: string | null;
|
|
282
|
+
};
|
|
283
|
+
type NodeVersion = NodeVersionV0 | NodeVersionV1;
|
|
284
|
+
type NodeVersionJson = NodeVersion;
|
|
285
|
+
/**
|
|
286
|
+
* Default synchronous D112 V1 node-version hash over strict canonical JSON UTF-8 bytes.
|
|
287
|
+
*
|
|
288
|
+
* When hashing a host value directly, encode first:
|
|
289
|
+
* `defaultNodeVersionHash(strictCanonicalJsonBytes(value))`.
|
|
290
|
+
*/
|
|
291
|
+
declare function defaultNodeVersionHash(bytes: Uint8Array): string;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* The node primitive — the thinnest substrate object (R-node-thin / D5).
|
|
295
|
+
*
|
|
296
|
+
* Holds a fn handle + deps + the wave state machine; ZERO inspection cruft
|
|
297
|
+
* (naming/find/describe are the graph layer, CSP-2). Canonical authority:
|
|
298
|
+
* ~/src/graphrefly/spec/rules.jsonl (R-node-*, R-two-phase, R-diamond, R-resolved-undirty,
|
|
299
|
+
* R-first-run-gate, R-push-subscribe, R-rom-ram, R-fn-contract, R-initial, R-ctx-up).
|
|
300
|
+
*
|
|
301
|
+
* Slice 1 = core wave: state node, compute node, two-phase DIRTY->DATA, diamond
|
|
302
|
+
* pending-counter join, first-run gate, substrate-synthesized undirty RESOLVED
|
|
303
|
+
* (R-resolved-undirty / D49 — no equals-substitution; every occurrence is DATA),
|
|
304
|
+
* push-on-subscribe, lazy activation, ROM/RAM. Lifecycle (terminal/INVALIDATE/cleanup),
|
|
305
|
+
* control (PAUSE/async), batch, and dynamicNode land in later slices.
|
|
306
|
+
*/
|
|
307
|
+
|
|
308
|
+
type Status = "sentinel" | "pending" | "dirty" | "settled" | "resolved" | "completed" | "errored";
|
|
309
|
+
interface NodeOptions<T = unknown> {
|
|
310
|
+
/** Pre-populate cache; source pushes [DATA, initial] on subscribe (R-initial). `null` is valid. */
|
|
311
|
+
initial?: T | null;
|
|
312
|
+
/** First-run gate off when true; fn body must guard SENTINEL per dep (R-first-run-gate). */
|
|
313
|
+
partial?: boolean;
|
|
314
|
+
/** A dep terminal also settles the first-run gate (Reduce-class, R-first-run-gate). */
|
|
315
|
+
terminalAsRealInput?: boolean;
|
|
316
|
+
/** Auto-emit COMPLETE when ALL deps complete (R-deps-terminal). Default true. */
|
|
317
|
+
completeWhenDepsComplete?: boolean;
|
|
318
|
+
/** Auto-emit ERROR when any dep errors (R-deps-terminal). Default true. */
|
|
319
|
+
errorWhenDepsError?: boolean;
|
|
320
|
+
/** Allow re-activation after terminal; late subscribe resets the lifecycle (R-terminal). Default false. */
|
|
321
|
+
resubscribable?: boolean;
|
|
322
|
+
/** Clear cached value on TEARDOWN. Default false. */
|
|
323
|
+
resetOnTeardown?: boolean;
|
|
324
|
+
/** PAUSE/RESUME behavior (R-pause-modes). Default true. */
|
|
325
|
+
pausable?: boolean | "resumeAll";
|
|
326
|
+
/**
|
|
327
|
+
* Pull-mode node (R-pull / D55,D59): a quiet-until-demanded source, identified by this
|
|
328
|
+
* author-supplied `pullId` (a unique LockId — a `Symbol` recommended; NOT the node name, NOT a
|
|
329
|
+
* bare string which collides with a same-string pause lock). The node self-holds the pullId as
|
|
330
|
+
* its demand lock. QUIET by default: it ABSORBS an upstream DIRTY WITHOUT relaying it downstream
|
|
331
|
+
* (the wedge fix) and does NOT push-on-subscribe its cached value (START only). A DEMAND = a
|
|
332
|
+
* cone-routed `RESUME` of this pullId (R-up-routing — NO new message type): a downstream consumer
|
|
333
|
+
* issues `ctx.up([[RESUME, pullId]])` (broadcast up the declared cone) or `ctx.up(msgs, towardDep)`
|
|
334
|
+
* (directed) WITHOUT holding this node's reference; the RESUME travels up to the pullId-holder,
|
|
335
|
+
* which fires EXACTLY ONE delivery (DIRTY-before-DATA) then RE-QUIETS (1:1). Delivery content =
|
|
336
|
+
* the orthogonal `pausable` mode: `true` → coalesced LATEST (one DATA); `'resumeAll'` → buffered
|
|
337
|
+
* BACKLOG. `pullId` + `pausable:false` is REJECTED at construction. A SELF-triggered demand (a
|
|
338
|
+
* consumer demanding a dep it ALSO reads) must defer via {@link Ctx.upNext} (R-rewire-deferred /
|
|
339
|
+
* D37). Author the pullId as a shared module const used at both this node and the demander's fn.
|
|
340
|
+
*/
|
|
341
|
+
pullId?: LockId;
|
|
342
|
+
/** Buffer the last N outgoing DATA for late subscribers (R-replay-buffer). */
|
|
343
|
+
replayBuffer?: number;
|
|
344
|
+
/**
|
|
345
|
+
* D109 node runtime versioning policy. Default is nodev0 (`{level:0,counter}`); `false`
|
|
346
|
+
* disables runtime version metadata for this node.
|
|
347
|
+
*/
|
|
348
|
+
versioning?: NodeVersioningPolicy;
|
|
349
|
+
/** Mark this as a dynamicNode — fn gets ctx.track(i) for read-selection (R-dynamic-node / D35). */
|
|
350
|
+
dynamic?: boolean;
|
|
351
|
+
/** Dispatch pool for the fn (R-sync-core). Default sync. */
|
|
352
|
+
pool?: "sync" | "async";
|
|
353
|
+
/** Dispatcher to register/invoke against. Default = process-global (D26). */
|
|
354
|
+
dispatcher?: Dispatcher;
|
|
355
|
+
/** Optional debug name (graph layer owns real naming/inspection). */
|
|
356
|
+
name?: string;
|
|
357
|
+
/**
|
|
358
|
+
* Real operator/source factory name for a STANDALONE graph-less node (D43-reserved; D51).
|
|
359
|
+
* The graph index (`_entries`) carries the factory for g.*-registered nodes, so this is only
|
|
360
|
+
* read for a node NOT in any graph index — a runtime *Map inner (bare `fromAny`/`initNode`
|
|
361
|
+
* node) auto-discovered by `describe` (R-describe / R-edges-derived / D51). Off the canonical
|
|
362
|
+
* wave path (R-node-thin intact — a pure annotation, never touched by the wave machinery).
|
|
363
|
+
*/
|
|
364
|
+
factory?: string;
|
|
365
|
+
}
|
|
366
|
+
declare class Node<T = unknown> {
|
|
367
|
+
private readonly _core;
|
|
368
|
+
private readonly _id;
|
|
369
|
+
private readonly _slot;
|
|
370
|
+
private readonly _dep;
|
|
371
|
+
private readonly _value;
|
|
372
|
+
private readonly _wave;
|
|
373
|
+
private readonly _control;
|
|
374
|
+
private readonly _lifecycle;
|
|
375
|
+
private readonly _privateState;
|
|
376
|
+
private readonly _hooks;
|
|
377
|
+
private readonly _syncCtxState;
|
|
378
|
+
private readonly _version;
|
|
379
|
+
private _restoredActivationPending;
|
|
380
|
+
private _released;
|
|
381
|
+
private get _syncCtx();
|
|
382
|
+
private set _syncCtx(value);
|
|
383
|
+
constructor(deps: Node<unknown>[], handleOrFn: Handle | NodeFn | null, opts?: NodeOptions<T>);
|
|
384
|
+
/** R-pull (D55): true while a pull node is quiet (holds its own pullId/demand lock). */
|
|
385
|
+
private _isPullQuiet;
|
|
386
|
+
/**
|
|
387
|
+
* R-pull (D55/D59): this pull node's pullId (pure data, like {@link cache}/{@link handle} — never
|
|
388
|
+
* triggers computation). A consumer demands one delivery by cone-routing a RESUME of it (no node
|
|
389
|
+
* reference): `ctx.up([["RESUME", pullId]])` (immediate; loops back → D37 for a self-read dep) or
|
|
390
|
+
* `ctx.upNext([["RESUME", pullId]])` (boundary-deferred self-demand, R-up-routing/R-rewire-deferred).
|
|
391
|
+
* Undefined for a non-pull node. The author writes the pullId verbatim, so this getter is mainly
|
|
392
|
+
* for inspection/describe; routing matches by the pullId value carried in the RESUME, by identity.
|
|
393
|
+
*/
|
|
394
|
+
get pullId(): LockId | undefined;
|
|
395
|
+
get cache(): T | undefined;
|
|
396
|
+
get status(): Status;
|
|
397
|
+
get version(): NodeVersion | undefined;
|
|
398
|
+
get name(): string | undefined;
|
|
399
|
+
/** R-describe/D51: real factory name for a standalone graph-less node (a runtime *Map inner). */
|
|
400
|
+
get factory(): string | undefined;
|
|
401
|
+
/**
|
|
402
|
+
* The node's CURRENT/LIVE deps (R-describe / R-edges-derived / D51) — readonly view of the
|
|
403
|
+
* live `_deps`, which a rewire (C-8 / C-11) mutates. The graph's describe() reads this (NOT a
|
|
404
|
+
* construction-time snapshot) so every edge corresponds to a real current subscription (D3).
|
|
405
|
+
* Inspection-only, like cache/status; never triggers computation.
|
|
406
|
+
*/
|
|
407
|
+
get deps(): readonly Node<unknown>[];
|
|
408
|
+
/**
|
|
409
|
+
* The fn handle (pure data `(poolId, handleId)`, D7) or null for state/passthrough
|
|
410
|
+
* nodes. Inspection-only (L1.6 handle is referenceable/inspectable) — lets the graph
|
|
411
|
+
* layer key a dispatcher-backed profile recorder WITHOUT putting counters on the node
|
|
412
|
+
* (R-node-thin / D39).
|
|
413
|
+
*/
|
|
414
|
+
get handle(): Handle | null;
|
|
415
|
+
/** R-push-subscribe: a new sink receives START, then cached DATA (or DIRTY if dirty). */
|
|
416
|
+
subscribe(sink: Sink): () => void;
|
|
417
|
+
/** External emission toward sinks (state-node push, or async late-emit). One call = one wave. */
|
|
418
|
+
down(msgs: Wave): void;
|
|
419
|
+
/**
|
|
420
|
+
* Emit upstream toward deps — control tiers only (R-ctx-up). `towardDep` (a dep index) routes up
|
|
421
|
+
* ONE declared edge (R-up-routing directed-up); omitted = broadcast up all deps.
|
|
422
|
+
*/
|
|
423
|
+
up(msgs: Wave, towardDep?: number): void;
|
|
424
|
+
/**
|
|
425
|
+
* Enqueue a deferred self-rewire op (issued from this node's fn via `ctx.rewireNext`).
|
|
426
|
+
* Applied at the committed wave boundary (boundary.ts drain), never in place — the in-fn
|
|
427
|
+
* immediate path (`subscribeDep`/`replaceDeps`/`unsubscribeDep`) still throws mid-run (D37/R-reentrancy).
|
|
428
|
+
*/
|
|
429
|
+
private _requestRewireNext;
|
|
430
|
+
/**
|
|
431
|
+
* Enqueue a deferred up-going control wave (R-up-routing / R-pull / D59): at the committed wave
|
|
432
|
+
* boundary, route `msgs` up from THIS node (broadcast, or up the single `towardDep` edge). The
|
|
433
|
+
* deferred form of `ctx.up` — the SELF-demand path: a consumer issues `ctx.upNext([[RESUME,
|
|
434
|
+
* pullId]])` to demand a dep it ALSO reads; the demand applies at the boundary (not mid-fn), so
|
|
435
|
+
* the pull node's delivery loops back as a FRESH wave rather than re-entering the consumer (D37 /
|
|
436
|
+
* R-reentrancy). Rides the same R-rewire-deferred (D47) drain as ctx.rewireNext.
|
|
437
|
+
*/
|
|
438
|
+
private _requestUpNext;
|
|
439
|
+
/** Apply one queued self-rewire at the boundary (drain thunk). */
|
|
440
|
+
private _applyRewireNext;
|
|
441
|
+
/**
|
|
442
|
+
* Replace this node's deps atomically (surgical, Option-C). Requires an explicit
|
|
443
|
+
* `fn` (SD-1 fn-deps pairing — user fns read dep input positionally). Kept deps
|
|
444
|
+
* keep their subscription + per-dep state; only removed deps unsubscribe and only
|
|
445
|
+
* added deps fresh-subscribe (push-on-subscribe for an added cached dep). The
|
|
446
|
+
* first-run gate and cache are PRESERVED (R-rewire Q2/Q7). Intra-graph only (D22).
|
|
447
|
+
*/
|
|
448
|
+
replaceDeps(newDeps: Node<unknown>[], fn: NodeFn): void;
|
|
449
|
+
/** Subscribe to one dep (special case of replaceDeps); returns its index. fn required (SD-1). */
|
|
450
|
+
subscribeDep(depNode: Node<unknown>, fn: NodeFn): number;
|
|
451
|
+
/** Unsubscribe from one dep (special case of replaceDeps); idempotent if absent (fn swap still applies). */
|
|
452
|
+
unsubscribeDep(depNode: Node<unknown>, fn: NodeFn): void;
|
|
453
|
+
private _dedupDeps;
|
|
454
|
+
/** Is `target` reachable upstream from `from` (following deps)? Cycle-prevention DFS. */
|
|
455
|
+
private _reachableUpstream;
|
|
456
|
+
private _assertRewireDepOwner;
|
|
457
|
+
private _rewire;
|
|
458
|
+
private _activate;
|
|
459
|
+
/**
|
|
460
|
+
* Subscribe to a dep. The dispatch callback reads the dep's CURRENT index from a
|
|
461
|
+
* mutable box (O(1)); a surgical rewire that reorders kept deps just updates the box
|
|
462
|
+
* (R-rewire Option-C / D42) — no re-subscribe, no per-message indexOf scan. A removed
|
|
463
|
+
* dep's box is set to -1 so any stale in-flight callback drops (drain).
|
|
464
|
+
*/
|
|
465
|
+
private _subscribeDepAt;
|
|
466
|
+
private _seedRestoredDepAt;
|
|
467
|
+
private _deactivate;
|
|
468
|
+
private _assertNotReleased;
|
|
469
|
+
private _subscriberCount;
|
|
470
|
+
private _isRuntimeQuiescentForRelease;
|
|
471
|
+
private _releaseRuntime;
|
|
472
|
+
private _resetDepState;
|
|
473
|
+
private _recordDepProjection;
|
|
474
|
+
private _depProjectionHasData;
|
|
475
|
+
private _receiveFromDep;
|
|
476
|
+
/**
|
|
477
|
+
* R-terminal-settles-dirty (B35): release a dep's outstanding in-wave DIRTY contribution.
|
|
478
|
+
* A settle-class event for that dep (DATA/RESOLVED inline above, INVALIDATE, and now
|
|
479
|
+
* COMPLETE/ERROR) clears its dirty flag + decrements _pending. No-op if the dep already
|
|
480
|
+
* settled this wave (DATA/RESOLVED ran first) — so the normal DATA-then-COMPLETE flow is
|
|
481
|
+
* unaffected. This makes the exactly-one-settle invariant a single, shared step.
|
|
482
|
+
*/
|
|
483
|
+
private _releaseDepDirty;
|
|
484
|
+
/**
|
|
485
|
+
* R-terminal-settles-dirty (B35): settle a node whose dirtied dep was released by an ABSORBED
|
|
486
|
+
* terminal that is NOT a real input (a plain derived/effect — the common default-node case when
|
|
487
|
+
* one of several deps completes while others stay live). Runs only when the release drained
|
|
488
|
+
* _pending while the node still owes a downstream settle (it broadcast DIRTY this wave):
|
|
489
|
+
* - if some OTHER dep delivered real DATA this wave (a value occurred) → recompute (→ DATA);
|
|
490
|
+
* - else the terminal's signalled change did not materialise (no value) → one undirty RESOLVED
|
|
491
|
+
* (R-resolved-undirty), keeping the cache (a terminal, unlike INVALIDATE, leaves the value).
|
|
492
|
+
* A terminalAsRealInput node instead recomputes unconditionally (its fn reads the terminal).
|
|
493
|
+
*/
|
|
494
|
+
private _settleAfterAbsorbedTerminal;
|
|
495
|
+
private _markDirty;
|
|
496
|
+
private _maybeRun;
|
|
497
|
+
/**
|
|
498
|
+
* R-rewire atomic settle (after a rewire that warrants a recompute): emit a proper
|
|
499
|
+
* two-phase DIRTY→DATA wave (R-dirty-before-data — a rewire-triggered settle is a wave),
|
|
500
|
+
* once, with every added dep already wired. Mirrors _maybeRun/_tryRun's pause + gate +
|
|
501
|
+
* pending guards, then injects the phase-1 DIRTY the added dep's [START,DATA] handshake
|
|
502
|
+
* did not carry.
|
|
503
|
+
*/
|
|
504
|
+
private _settleRewire;
|
|
505
|
+
private _tryRun;
|
|
506
|
+
private _allDepsSettled;
|
|
507
|
+
private _passthroughEmit;
|
|
508
|
+
private _runWave;
|
|
509
|
+
private _buildCtx;
|
|
510
|
+
private _makeCtx;
|
|
511
|
+
private _refreshCtx;
|
|
512
|
+
private _makeState;
|
|
513
|
+
private _down;
|
|
514
|
+
private _up;
|
|
515
|
+
private _markDemandRouted;
|
|
516
|
+
/**
|
|
517
|
+
* Forward one up-going control message toward deps (R-up-routing): up the single declared edge
|
|
518
|
+
* `towardDep` (directed — prunes other branches; only meaningful on the issuer's FIRST hop) or
|
|
519
|
+
* broadcast up ALL deps. A depless source has no deps → the message DROPS here (the terminus —
|
|
520
|
+
* e.g. a cone-routed RESUME whose pullId no node up this cone holds, R-up-at-source). Recursive
|
|
521
|
+
* forwarding carries the same per-wave route state and no `towardDep` → broadcast beyond the
|
|
522
|
+
* first hop.
|
|
523
|
+
*/
|
|
524
|
+
private _forwardUp;
|
|
525
|
+
private _isPaused;
|
|
526
|
+
private _hasBoundaryPauseLock;
|
|
527
|
+
private _isAsyncPool;
|
|
528
|
+
private _pauseAcquire;
|
|
529
|
+
private _pauseRelease;
|
|
530
|
+
private _onResume;
|
|
531
|
+
/**
|
|
532
|
+
* R-pull (D59): can this pull node fire a demand NOW? — not terminal, settle-ready (_pending===0),
|
|
533
|
+
* and no OTHER (non-pullId) lock holds it paused. The gate that decides fire-now vs OWE.
|
|
534
|
+
*/
|
|
535
|
+
private _canFireDemand;
|
|
536
|
+
/**
|
|
537
|
+
* R-pull (D59): deliver ONE demand pulse — release the pullId so the demand wave RELAYS (not
|
|
538
|
+
* absorbed), fire it, then RE-QUIET (1:1). The pullId re-add + the re-entrancy flag are in a
|
|
539
|
+
* `finally` so a throwing pull fn (graph-less node, no D30 catch) cannot leave the node
|
|
540
|
+
* permanently non-quiet (the wedge-fix silently disabled) — QA-found robustness fix.
|
|
541
|
+
*/
|
|
542
|
+
private _deliverPullDemand;
|
|
543
|
+
/**
|
|
544
|
+
* R-pull (D59): a cone-routed RESUME of THIS node's pullId arrived (R-up-routing) = a DEMAND.
|
|
545
|
+
* Fire immediately if able; else OWE it — pin-5 (a dep DIRTY in flight, _pending>0) or F4/F5 (an
|
|
546
|
+
* external PAUSE lock co-holds the node) — and fire when the node next becomes able. A demand
|
|
547
|
+
* arriving WHILE a delivery is in flight (synchronous re-entry) is DROPPED (1:1, QA guard).
|
|
548
|
+
*/
|
|
549
|
+
private _onDemand;
|
|
550
|
+
/**
|
|
551
|
+
* R-pull (D55): service ONE demand. Delivery content = the orthogonal pausable mode:
|
|
552
|
+
* - 'resumeAll' → drain the buffered BACKLOG (each `_down` re-synthesizes a leading DIRTY, so
|
|
553
|
+
* the per-entry replay is DIRTY-before-DATA — R-pause-modes per-entry arrival order);
|
|
554
|
+
* - true → deliver the coalesced LATEST as ONE DIRTY-before-DATA wave (pin 2: the quiet absorb
|
|
555
|
+
* suppressed the dep's original DIRTY, so the demand wave restores it before the value).
|
|
556
|
+
* Neither branch fires when nothing changed since the last demand → the demand is SILENT.
|
|
557
|
+
* Called by `_deliverPullDemand` only when settle-ready; the caller has released the pullId, so
|
|
558
|
+
* `_markDirty` relays the leading DIRTY (not absorbed).
|
|
559
|
+
*/
|
|
560
|
+
private _firePullDemand;
|
|
561
|
+
/**
|
|
562
|
+
* R-pull (D55/D59): fire a demand that was OWED (deferred at demand time) once the node becomes
|
|
563
|
+
* able — called from the dep-settle arms (DATA/RESOLVED/INVALIDATE/terminal drain _pending, pin-5
|
|
564
|
+
* + B1/F6) and from `_pauseRelease` (an external PAUSE lock releases, F4/F5).
|
|
565
|
+
*/
|
|
566
|
+
private _fireOwedDemandIfReady;
|
|
567
|
+
/** Should an outgoing settle slice be deferred into the pause buffer? */
|
|
568
|
+
private _shouldBufferOnPause;
|
|
569
|
+
/** R-invalidate-idempotent: clear cache + flush + cascade; no-op if nothing cached. */
|
|
570
|
+
private _invalidate;
|
|
571
|
+
private _allDepsTerminal;
|
|
572
|
+
/** R-terminal: resubscribable reset clears terminal + dep state + re-arms the gate. */
|
|
573
|
+
private _resetLifecycle;
|
|
574
|
+
private _emitToSubs;
|
|
575
|
+
/** Batch commit (R-batch-coalesce): deliver the deferred tier-3 wave now. */
|
|
576
|
+
__commitBatchedWave(wave: Wave): void;
|
|
577
|
+
/** Batch rollback: balance the immediate DIRTY with a RESOLVED so downstream un-dirties. */
|
|
578
|
+
__rollbackBatched(): void;
|
|
579
|
+
/** B49: enqueue a committed-boundary task on this node's graph-local core. */
|
|
580
|
+
__deferBoundary(fn: () => void, batchToken?: object): void;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Construct a node (R-node-iface / D5 / L1.9 deps-first).
|
|
584
|
+
* node([], null, { initial }) — state node (manual source; emit via .down)
|
|
585
|
+
* node([], fn) — producer (runs on activation)
|
|
586
|
+
* node([a, b], fn) — compute / derived
|
|
587
|
+
* node([dep]) — passthrough wire
|
|
588
|
+
*/
|
|
589
|
+
declare function node<T = unknown>(deps?: Node<unknown>[], handleOrFn?: Handle | NodeFn | null, opts?: NodeOptions<T>): Node<T>;
|
|
590
|
+
/**
|
|
591
|
+
* Construct a dynamicNode (R-dynamic-node / D35) — a node variant whose fn reads a
|
|
592
|
+
* subset of a fixed superset of deps per invocation via `ctx.track(i)`. All declared
|
|
593
|
+
* deps participate in wave tracking; an unread dep's change re-runs the fn, which re-emits
|
|
594
|
+
* its current value as DATA (D49 removed equals-absorption — dedup is opt-in via
|
|
595
|
+
* distinctUntilChanged). Intra-graph only (D22).
|
|
596
|
+
*/
|
|
597
|
+
declare function dynamicNode<T = unknown>(deps: Node<unknown>[], fn: NodeFn, opts?: NodeOptions<T>): Node<T>;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* The fn-invocation context and per-dep input shapes.
|
|
601
|
+
*
|
|
602
|
+
* Canonical authority: ~/src/graphrefly/spec/rules.jsonl
|
|
603
|
+
* R-fn-contract (D8/D27), R-ctx-state (D23/D29), R-cleanup-hooks (D28), R-ctx-up.
|
|
604
|
+
*/
|
|
605
|
+
|
|
606
|
+
/** A downstream sink callback (the only way to connect to a node's output). */
|
|
607
|
+
type Sink = (msg: Message, delivery?: DeliveryMeta) => void;
|
|
608
|
+
/** Internal delivery metadata used to preserve the upstream `ctx.down(msgs)` wave boundary. */
|
|
609
|
+
interface DeliveryMeta {
|
|
610
|
+
readonly wave: object;
|
|
611
|
+
readonly last: boolean;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Internal current-value reader. It is deliberately a symbol-backed implementation detail:
|
|
615
|
+
* raw ctx exposes `waveData` + `terminal`; helpers below derive from that plus this dep cache.
|
|
616
|
+
*/
|
|
617
|
+
declare const CTX_DEP_CACHE: unique symbol;
|
|
618
|
+
interface CtxDepCache {
|
|
619
|
+
readonly latest: readonly unknown[];
|
|
620
|
+
}
|
|
621
|
+
/** Internal node-construction binding for graph-local helper-created deps. */
|
|
622
|
+
declare const CTX_NODE_BINDING: unique symbol;
|
|
623
|
+
interface CtxNodeBinding {
|
|
624
|
+
readonly dispatcher: Dispatcher;
|
|
625
|
+
create<T>(factory: () => Node<T>): Node<T>;
|
|
626
|
+
}
|
|
627
|
+
/** Per-dep wave projections: dep -> waves -> values/SENTINEL markers. */
|
|
628
|
+
type WaveData = readonly (readonly (readonly unknown[])[])[];
|
|
629
|
+
/** Terminal metadata parallel to `waveData`: false = none, true = COMPLETE, otherwise ERROR payload. */
|
|
630
|
+
type TerminalData = readonly unknown[];
|
|
631
|
+
declare function isTerminalNone(t: unknown): boolean;
|
|
632
|
+
declare function isTerminalComplete(t: unknown): t is true;
|
|
633
|
+
declare function isTerminalError(t: unknown): boolean;
|
|
634
|
+
declare function terminalErrorValue(t: unknown): unknown;
|
|
635
|
+
/**
|
|
636
|
+
* Per-node private cross-wave state (R-ctx-state / D23,D29). Default fresh-lifecycle
|
|
637
|
+
* wipe; `persist(true)` keeps it across lifecycle transitions.
|
|
638
|
+
*/
|
|
639
|
+
interface CtxState {
|
|
640
|
+
get<S = unknown>(): S | undefined;
|
|
641
|
+
set<S = unknown>(v: S): void;
|
|
642
|
+
persist(on?: boolean): void;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Deferred SELF-rewire (R-rewire-deferred / D47). A node fn may, DURING its run, request a
|
|
646
|
+
* mutation of its OWN dep set; the request is QUEUED and applied at the committed wave boundary
|
|
647
|
+
* (after the current wave settles / batch commit / final-lock RESUME) as a fresh wave, reusing
|
|
648
|
+
* R-rewire surgical/Option-C semantics (D42). This is the ONLY legal self-triggered rewire — an
|
|
649
|
+
* IMMEDIATE in-fn `node.subscribeDep/unsubscribeDep/replaceDeps` is the D37 mid-fn feedback-cycle ERROR. An
|
|
650
|
+
* added cached dep pushes `[DIRTY,DATA]` on the boundary wave (R-push-subscribe); a removed dep
|
|
651
|
+
* is drained and, if it loses its last subscriber, `_deactivate`s + fires `onDeactivation`
|
|
652
|
+
* (input-side teardown — the basis for higher-order operator cancellation / abortInFlight).
|
|
653
|
+
*/
|
|
654
|
+
interface RewireNext {
|
|
655
|
+
/** Defer subscribing to a dep (paired with the re-supplied fn — positional fn-deps lock, SD-1). */
|
|
656
|
+
subscribeDep(dep: Node<unknown>, fn: NodeFn): void;
|
|
657
|
+
/** Defer unsubscribing from a dep (its source is torn down if it loses its last subscriber). */
|
|
658
|
+
unsubscribeDep(dep: Node<unknown>, fn: NodeFn): void;
|
|
659
|
+
/** Defer replacing the whole dep set (surgical: kept deps untouched, removed drained, added fresh-subscribe). */
|
|
660
|
+
replaceDeps(deps: Node<unknown>[], fn: NodeFn): void;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* The single argument to a node fn: `(ctx) => void` (R-fn-contract / D8). All emission
|
|
664
|
+
* is explicit via `ctx.down`; there is no return-value framing.
|
|
665
|
+
*/
|
|
666
|
+
interface Ctx {
|
|
667
|
+
/**
|
|
668
|
+
* Emit upstream toward deps — control tiers only (R-ctx-up). IMMEDIATE. `towardDep` (a dep index)
|
|
669
|
+
* routes the wave up ONE declared edge (R-up-routing directed-up); omitted = broadcast up all deps.
|
|
670
|
+
* A pull DEMAND is `up([[RESUME, pullId]])` — but for a SELF-demand (demanding a dep this fn also
|
|
671
|
+
* reads) use {@link Ctx.upNext} instead, since an immediate demand whose delivery loops back
|
|
672
|
+
* re-enters this fn mid-wave (D37 / R-reentrancy).
|
|
673
|
+
*/
|
|
674
|
+
up(msgs: Wave, towardDep?: number): void;
|
|
675
|
+
/** Emit downstream toward sinks. */
|
|
676
|
+
down(msgs: Wave): void;
|
|
677
|
+
/**
|
|
678
|
+
* The single raw dep-value input surface (R-ctx-wave-data / D77): dep -> upstream waves ->
|
|
679
|
+
* per-wave DATA payloads and INVALIDATE/SENTINEL markers. `waveData[i] = []` means dep i
|
|
680
|
+
* delivered no wave to this invocation; `waveData[i] = [[]]` means RESOLVED-only.
|
|
681
|
+
*/
|
|
682
|
+
waveData: WaveData;
|
|
683
|
+
/** Terminal metadata for the same invocation; terminal values never enter `waveData`. */
|
|
684
|
+
terminal: TerminalData;
|
|
685
|
+
state: CtxState;
|
|
686
|
+
/** Release external resources on deactivation (R-cleanup-hooks). */
|
|
687
|
+
onDeactivation(fn: () => void): void;
|
|
688
|
+
/** Flush on INVALIDATE (R-cleanup-hooks). */
|
|
689
|
+
onInvalidate(fn: () => void): void;
|
|
690
|
+
/** Graph-owned environment drivers for source/adapter boundaries (D130/D131). */
|
|
691
|
+
environment(): EnvironmentDrivers;
|
|
692
|
+
/**
|
|
693
|
+
* Deferred SELF-rewire (R-rewire-deferred / D47) — the substrate affordance higher-order
|
|
694
|
+
* operators (switchMap/mergeMap/concatMap/exhaustMap/flatMap) use to grow/shrink their own
|
|
695
|
+
* inner-source dep set in response to their own data. Always present; see {@link RewireNext}.
|
|
696
|
+
*/
|
|
697
|
+
rewireNext: RewireNext;
|
|
698
|
+
/**
|
|
699
|
+
* Deferred up — the boundary-deferred form of {@link Ctx.up} (R-up-routing / R-pull / D59). Routes
|
|
700
|
+
* `msgs` up from this node at the COMMITTED wave boundary (broadcast, or up the single `towardDep`
|
|
701
|
+
* edge), riding the same R-rewire-deferred (D47) drain as {@link RewireNext}. This is the
|
|
702
|
+
* SELF-DEMAND path: a consumer issues `ctx.upNext([[RESUME, pullId]])` to demand a pull dep it
|
|
703
|
+
* ALSO reads — the cone-routed RESUME reaches the pullId-holder, whose delivery loops back as a
|
|
704
|
+
* FRESH wave (not a mid-fn re-entry → no D37). The consumer accepts one-wave latency (the
|
|
705
|
+
* HTTP-request model). No node reference needed: the author writes the pullId verbatim.
|
|
706
|
+
*/
|
|
707
|
+
upNext(msgs: Wave, towardDep?: number): void;
|
|
708
|
+
/**
|
|
709
|
+
* Read a dep's latest value by index (dynamicNode only, R-dynamic-node / D35).
|
|
710
|
+
* Present only on dynamicNode fns; all declared deps still participate in wave
|
|
711
|
+
* tracking. Under D49/R-resolved-undirty an unread dep's change still fires the fn,
|
|
712
|
+
* which re-emits its (unchanged) output as a DATA occurrence — there is NO equals-
|
|
713
|
+
* absorption; pair with distinctUntilChanged to suppress unchanged re-emits (opt-in).
|
|
714
|
+
*/
|
|
715
|
+
track?(depIndex: number): unknown;
|
|
716
|
+
[CTX_DEP_CACHE]?: CtxDepCache;
|
|
717
|
+
[CTX_NODE_BINDING]?: CtxNodeBinding;
|
|
718
|
+
}
|
|
719
|
+
/** A node fn (R-fn-contract). Registered in a dispatcher pool, indexed by Handle. */
|
|
720
|
+
type NodeFn = (ctx: Ctx) => void;
|
|
721
|
+
/** Number of declared dep slots visible in this invocation. */
|
|
722
|
+
declare function depCount(ctx: Ctx): number;
|
|
723
|
+
/** DATA/SENTINEL projection batches delivered by one dep in this invocation. */
|
|
724
|
+
declare function depWaves(ctx: Ctx, depIndex: number): readonly (readonly unknown[])[];
|
|
725
|
+
/** Flattened DATA projection for old event-counting operator bodies; null = no wave. */
|
|
726
|
+
declare function depBatch(ctx: Ctx, depIndex: number): readonly unknown[] | null;
|
|
727
|
+
/** Latest cached DATA for a dep, derived from implementation-owned dep cache. */
|
|
728
|
+
declare function depLatest(ctx: Ctx, depIndex: number): unknown;
|
|
729
|
+
/** Terminal metadata for one dep: false = none, true = COMPLETE, otherwise ERROR payload. */
|
|
730
|
+
declare function depTerminal(ctx: Ctx, depIndex: number): unknown;
|
|
731
|
+
|
|
732
|
+
export { depBatch as $, type SseRequest as A, type Status as B, type Ctx as C, Dispatcher as D, EnvironmentDrivers as E, type FetchLike as F, type WebSocketConstructorLike as G, type Handle as H, type WebSocketDriverEvent as I, type WebSocketEvent as J, type WebSocketLike as K, type LocalHttpDriver as L, type WebSocketRequest as M, Node as N, type WebSocketSend as O, type Pool as P, type WebSocketSendResult as Q, type RewireNext as R, type Sink as S, type TerminalData as T, type WebSocketSessionHandle as U, type WebhookDriverEvent as V, type WaveData as W, type WebhookEvent as X, type WebhookRegistration as Y, defaultDispatcher as Z, defaultNodeVersionHash as _, type CtxState as a, depCount as a0, depLatest as a1, depTerminal as a2, depWaves as a3, domWebSocketDriver as a4, dynamicNode as a5, fetchHttpDriver as a6, isTerminalComplete as a7, isTerminalError as a8, isTerminalNone as a9, node as aa, terminalErrorValue as ab, type DriverCancel as b, type DriverResult as c, type EnvironmentDriversInit as d, type FetchResponseLike as e, type HandleStat as f, type HttpRequest as g, type HttpResponse as h, type LocalProcessDriver as i, type LocalSseDriver as j, type LocalWebSocketDriver as k, type LocalWebhookDriver as l, type NodeFn as m, type NodeOptions as n, type NodeVersion as o, type NodeVersionHashFn as p, type NodeVersionJson as q, type NodeVersionV0 as r, type NodeVersionV1 as s, type NodeVersioningLevel as t, type NodeVersioningPolicy as u, type PoolKind as v, type ProcessCommand as w, type ProcessResult as x, type SseDriverEvent as y, type SseEvent as z };
|