@graphrefly/graphrefly 0.1.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/README.md +234 -0
- package/dist/chunk-5X3LAO3B.js +1571 -0
- package/dist/chunk-5X3LAO3B.js.map +1 -0
- package/dist/chunk-6W5SGIGB.js +1793 -0
- package/dist/chunk-6W5SGIGB.js.map +1 -0
- package/dist/chunk-CP6MNKAA.js +97 -0
- package/dist/chunk-CP6MNKAA.js.map +1 -0
- package/dist/chunk-HP7OKEOE.js +107 -0
- package/dist/chunk-HP7OKEOE.js.map +1 -0
- package/dist/chunk-KWXPDASV.js +781 -0
- package/dist/chunk-KWXPDASV.js.map +1 -0
- package/dist/chunk-O3PI7W45.js +68 -0
- package/dist/chunk-O3PI7W45.js.map +1 -0
- package/dist/chunk-QW7H3ICI.js +1372 -0
- package/dist/chunk-QW7H3ICI.js.map +1 -0
- package/dist/chunk-VPS7L64N.js +4785 -0
- package/dist/chunk-VPS7L64N.js.map +1 -0
- package/dist/chunk-Z4Y4FMQN.js +1097 -0
- package/dist/chunk-Z4Y4FMQN.js.map +1 -0
- package/dist/compat/nestjs/index.cjs +4883 -0
- package/dist/compat/nestjs/index.cjs.map +1 -0
- package/dist/compat/nestjs/index.d.cts +7 -0
- package/dist/compat/nestjs/index.d.ts +7 -0
- package/dist/compat/nestjs/index.js +84 -0
- package/dist/compat/nestjs/index.js.map +1 -0
- package/dist/core/index.cjs +1632 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +2 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +90 -0
- package/dist/core/index.js.map +1 -0
- package/dist/extra/index.cjs +6885 -0
- package/dist/extra/index.cjs.map +1 -0
- package/dist/extra/index.d.cts +5 -0
- package/dist/extra/index.d.ts +5 -0
- package/dist/extra/index.js +290 -0
- package/dist/extra/index.js.map +1 -0
- package/dist/graph/index.cjs +3225 -0
- package/dist/graph/index.cjs.map +1 -0
- package/dist/graph/index.d.cts +3 -0
- package/dist/graph/index.d.ts +3 -0
- package/dist/graph/index.js +25 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph-CL_ZDAj9.d.cts +605 -0
- package/dist/graph-D18qmsNm.d.ts +605 -0
- package/dist/index-B6SsZs2h.d.cts +3463 -0
- package/dist/index-B7eOdgEx.d.ts +449 -0
- package/dist/index-BHUvlQ3v.d.ts +3463 -0
- package/dist/index-BtK55IE2.d.ts +231 -0
- package/dist/index-BvhgZRHK.d.cts +231 -0
- package/dist/index-Bvy_6CaN.d.ts +452 -0
- package/dist/index-C3BMRmmp.d.cts +449 -0
- package/dist/index-C5mqLhMX.d.cts +452 -0
- package/dist/index-CP_QvbWu.d.ts +940 -0
- package/dist/index-D_geH2Bm.d.cts +940 -0
- package/dist/index.cjs +14843 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1517 -0
- package/dist/index.d.ts +1517 -0
- package/dist/index.js +3649 -0
- package/dist/index.js.map +1 -0
- package/dist/meta-BsF6Sag9.d.cts +607 -0
- package/dist/meta-BsF6Sag9.d.ts +607 -0
- package/dist/patterns/reactive-layout/index.cjs +4143 -0
- package/dist/patterns/reactive-layout/index.cjs.map +1 -0
- package/dist/patterns/reactive-layout/index.d.cts +3 -0
- package/dist/patterns/reactive-layout/index.d.ts +3 -0
- package/dist/patterns/reactive-layout/index.js +38 -0
- package/dist/patterns/reactive-layout/index.js.map +1 -0
- package/dist/reactive-log-BfvfNWQh.d.cts +137 -0
- package/dist/reactive-log-ohLmTXoZ.d.ts +137 -0
- package/package.json +256 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { D as DeltaCheckpoint, E as EvictedSubgraphInfo, a as EvictionPolicy, G as GraphCodec, J as JsonCodec, L as LazyGraphCodec, W as WALEntry, c as createDagCborCodec, b as createDagCborZstdCodec, n as negotiateCodec, r as replayWAL } from '../index-BvhgZRHK.cjs';
|
|
2
|
+
export { A as AutoCheckpointAdapter, D as DescribeFilter, d as GRAPH_META_SEGMENT, G as Graph, e as GraphActorOptions, b as GraphAutoCheckpointHandle, c as GraphAutoCheckpointOptions, f as GraphCheckpointRecord, g as GraphDescribeOutput, h as GraphDiagramDirection, i as GraphDiagramOptions, j as GraphDiffChange, k as GraphDiffResult, l as GraphDumpOptions, m as GraphFactoryContext, n as GraphNodeFactory, o as GraphObserveAll, p as GraphObserveOne, a as GraphOptions, q as GraphPersistSnapshot, r as GraphSpyHandle, s as GraphSpyOptions, t as GraphSpyTheme, u as GraphSpyThemeName, O as ObserveEvent, v as ObserveOptions, w as ObserveResult, R as ReachableDirection, x as ReachableOptions, T as TraceEntry, y as reachable } from '../graph-CL_ZDAj9.cjs';
|
|
3
|
+
import '../meta-BsF6Sag9.cjs';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { D as DeltaCheckpoint, E as EvictedSubgraphInfo, a as EvictionPolicy, G as GraphCodec, J as JsonCodec, L as LazyGraphCodec, W as WALEntry, c as createDagCborCodec, b as createDagCborZstdCodec, n as negotiateCodec, r as replayWAL } from '../index-BtK55IE2.js';
|
|
2
|
+
export { A as AutoCheckpointAdapter, D as DescribeFilter, d as GRAPH_META_SEGMENT, G as Graph, e as GraphActorOptions, b as GraphAutoCheckpointHandle, c as GraphAutoCheckpointOptions, f as GraphCheckpointRecord, g as GraphDescribeOutput, h as GraphDiagramDirection, i as GraphDiagramOptions, j as GraphDiffChange, k as GraphDiffResult, l as GraphDumpOptions, m as GraphFactoryContext, n as GraphNodeFactory, o as GraphObserveAll, p as GraphObserveOne, a as GraphOptions, q as GraphPersistSnapshot, r as GraphSpyHandle, s as GraphSpyOptions, t as GraphSpyTheme, u as GraphSpyThemeName, O as ObserveEvent, v as ObserveOptions, w as ObserveResult, R as ReachableDirection, x as ReachableOptions, T as TraceEntry, y as reachable } from '../graph-D18qmsNm.js';
|
|
3
|
+
import '../meta-BsF6Sag9.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JsonCodec,
|
|
3
|
+
createDagCborCodec,
|
|
4
|
+
createDagCborZstdCodec,
|
|
5
|
+
negotiateCodec,
|
|
6
|
+
replayWAL
|
|
7
|
+
} from "../chunk-HP7OKEOE.js";
|
|
8
|
+
import {
|
|
9
|
+
GRAPH_META_SEGMENT,
|
|
10
|
+
Graph,
|
|
11
|
+
reachable
|
|
12
|
+
} from "../chunk-6W5SGIGB.js";
|
|
13
|
+
import "../chunk-O3PI7W45.js";
|
|
14
|
+
import "../chunk-5X3LAO3B.js";
|
|
15
|
+
export {
|
|
16
|
+
GRAPH_META_SEGMENT,
|
|
17
|
+
Graph,
|
|
18
|
+
JsonCodec,
|
|
19
|
+
createDagCborCodec,
|
|
20
|
+
createDagCborZstdCodec,
|
|
21
|
+
negotiateCodec,
|
|
22
|
+
reachable,
|
|
23
|
+
replayWAL
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
import { f as DescribeNodeOutput, N as Node, u as VersioningLevel, A as Actor, i as Messages, l as NodeSink } from './meta-BsF6Sag9.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reserved segment for meta companion paths: `nodeName::__meta__::metaKey` (GRAPHREFLY-SPEC §3.6).
|
|
5
|
+
* Forbidden as a local node or mount name.
|
|
6
|
+
*/
|
|
7
|
+
declare const GRAPH_META_SEGMENT = "__meta__";
|
|
8
|
+
/** Options for {@link Graph} (reserved for future hooks). */
|
|
9
|
+
type GraphOptions = Record<string, unknown>;
|
|
10
|
+
/** Filter for {@link Graph.describe} — object-style partial match or predicate. */
|
|
11
|
+
type DescribeFilter = Partial<Pick<DescribeNodeOutput, "type" | "status">> | {
|
|
12
|
+
type?: DescribeNodeOutput["type"];
|
|
13
|
+
status?: DescribeNodeOutput["status"];
|
|
14
|
+
/** Keep nodes whose `deps` includes this qualified path. */
|
|
15
|
+
depsIncludes?: string;
|
|
16
|
+
/** Snake-case alias for `depsIncludes` (Python parity). */
|
|
17
|
+
deps_includes?: string;
|
|
18
|
+
/** Keep nodes whose `meta` contains this key. */
|
|
19
|
+
metaHas?: string;
|
|
20
|
+
/** Snake-case alias for `metaHas` (Python parity). */
|
|
21
|
+
meta_has?: string;
|
|
22
|
+
} | ((node: DescribeNodeOutput) => boolean) | ((nodePath: string, node: DescribeNodeOutput) => boolean);
|
|
23
|
+
/** Options for {@link Graph.signal} and {@link Graph.set} (actor context, internal lifecycle). */
|
|
24
|
+
type GraphActorOptions = {
|
|
25
|
+
actor?: Actor;
|
|
26
|
+
/**
|
|
27
|
+
* When `true`, skips node guards (graph lifecycle TEARDOWN, unmount teardown, etc.).
|
|
28
|
+
*/
|
|
29
|
+
internal?: boolean;
|
|
30
|
+
};
|
|
31
|
+
/** JSON snapshot from {@link Graph.describe} (GRAPHREFLY-SPEC §3.6, Appendix B). */
|
|
32
|
+
type GraphDescribeOutput = {
|
|
33
|
+
name: string;
|
|
34
|
+
nodes: Record<string, DescribeNodeOutput>;
|
|
35
|
+
edges: ReadonlyArray<{
|
|
36
|
+
from: string;
|
|
37
|
+
to: string;
|
|
38
|
+
}>;
|
|
39
|
+
subgraphs: string[];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Persisted graph snapshot: {@link GraphDescribeOutput} plus optional format version
|
|
43
|
+
* ({@link Graph.snapshot}, {@link Graph.restore}, {@link Graph.fromSnapshot}, {@link Graph.toJSON},
|
|
44
|
+
* {@link Graph.toJSONString} — §3.8).
|
|
45
|
+
*/
|
|
46
|
+
type GraphPersistSnapshot = GraphDescribeOutput & {
|
|
47
|
+
version?: number;
|
|
48
|
+
};
|
|
49
|
+
type GraphFactoryContext = {
|
|
50
|
+
path: string;
|
|
51
|
+
type: DescribeNodeOutput["type"];
|
|
52
|
+
value: unknown;
|
|
53
|
+
meta: Record<string, unknown>;
|
|
54
|
+
deps: readonly string[];
|
|
55
|
+
resolvedDeps: readonly Node[];
|
|
56
|
+
};
|
|
57
|
+
type GraphNodeFactory = (name: string, context: GraphFactoryContext) => Node;
|
|
58
|
+
type AutoCheckpointAdapter = {
|
|
59
|
+
save(data: unknown): void;
|
|
60
|
+
};
|
|
61
|
+
type GraphCheckpointRecord = {
|
|
62
|
+
mode: "full";
|
|
63
|
+
snapshot: GraphPersistSnapshot;
|
|
64
|
+
seq: number;
|
|
65
|
+
} | {
|
|
66
|
+
mode: "diff";
|
|
67
|
+
diff: GraphDiffResult;
|
|
68
|
+
snapshot: GraphPersistSnapshot;
|
|
69
|
+
seq: number;
|
|
70
|
+
};
|
|
71
|
+
type GraphAutoCheckpointOptions = {
|
|
72
|
+
debounceMs?: number;
|
|
73
|
+
compactEvery?: number;
|
|
74
|
+
filter?: (name: string, described: DescribeNodeOutput) => boolean;
|
|
75
|
+
onError?: (error: unknown) => void;
|
|
76
|
+
};
|
|
77
|
+
type GraphAutoCheckpointHandle = {
|
|
78
|
+
dispose(): void;
|
|
79
|
+
};
|
|
80
|
+
/** Direction options for diagram export helpers. */
|
|
81
|
+
type GraphDiagramDirection = "TD" | "LR" | "BT" | "RL";
|
|
82
|
+
/** Options for {@link Graph.toMermaid} / {@link Graph.toD2}. */
|
|
83
|
+
type GraphDiagramOptions = {
|
|
84
|
+
/**
|
|
85
|
+
* Diagram flow direction.
|
|
86
|
+
* - `TD`: top-down
|
|
87
|
+
* - `LR`: left-right (default)
|
|
88
|
+
* - `BT`: bottom-top
|
|
89
|
+
* - `RL`: right-left
|
|
90
|
+
*/
|
|
91
|
+
direction?: GraphDiagramDirection;
|
|
92
|
+
};
|
|
93
|
+
/** {@link Graph.observe} on a single node or meta path — sink receives plain message batches. */
|
|
94
|
+
type GraphObserveOne = {
|
|
95
|
+
subscribe(sink: NodeSink): () => void;
|
|
96
|
+
/** Send messages upstream toward the observed node's sources (e.g. PAUSE/RESUME). */
|
|
97
|
+
up(messages: Messages): void;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* {@link Graph.observe} on the whole graph — sink receives each batch with the qualified source path.
|
|
101
|
+
* Subscription order follows code-point sort on paths (mounts-first walk, then sorted locals/meta).
|
|
102
|
+
*/
|
|
103
|
+
type GraphObserveAll = {
|
|
104
|
+
subscribe(sink: (nodePath: string, messages: Messages) => void): () => void;
|
|
105
|
+
/** Send messages upstream toward a specific observed node's sources (e.g. PAUSE/RESUME). */
|
|
106
|
+
up(path: string, messages: Messages): void;
|
|
107
|
+
};
|
|
108
|
+
/** Options for structured observation modes on {@link Graph.observe}. */
|
|
109
|
+
type ObserveOptions = {
|
|
110
|
+
actor?: Actor;
|
|
111
|
+
/** Return an {@link ObserveResult} accumulator instead of a raw stream. */
|
|
112
|
+
structured?: boolean;
|
|
113
|
+
/** Include causal trace info (which dep triggered each recomputation). */
|
|
114
|
+
causal?: boolean;
|
|
115
|
+
/** Include timestamps and batch context on each event. */
|
|
116
|
+
timeline?: boolean;
|
|
117
|
+
/** Include per-evaluation dep snapshots for compute/derived nodes. */
|
|
118
|
+
derived?: boolean;
|
|
119
|
+
};
|
|
120
|
+
/** Accumulated observation result (structured mode). */
|
|
121
|
+
type ObserveResult<T = unknown> = {
|
|
122
|
+
/** Latest DATA value by observed path. */
|
|
123
|
+
readonly values: Record<string, T>;
|
|
124
|
+
/** Number of DIRTY messages received. */
|
|
125
|
+
readonly dirtyCount: number;
|
|
126
|
+
/** Number of RESOLVED messages received. */
|
|
127
|
+
readonly resolvedCount: number;
|
|
128
|
+
/** All events in order. */
|
|
129
|
+
readonly events: ObserveEvent[];
|
|
130
|
+
/** True if COMPLETE received without prior ERROR. */
|
|
131
|
+
readonly completedCleanly: boolean;
|
|
132
|
+
/** True if ERROR received. */
|
|
133
|
+
readonly errored: boolean;
|
|
134
|
+
/** Stop observing. */
|
|
135
|
+
dispose(): void;
|
|
136
|
+
};
|
|
137
|
+
/** A single event in the structured observation log. */
|
|
138
|
+
type ObserveEvent = {
|
|
139
|
+
type: "data" | "dirty" | "resolved" | "complete" | "error" | "derived";
|
|
140
|
+
path?: string;
|
|
141
|
+
data?: unknown;
|
|
142
|
+
timestamp_ns?: number;
|
|
143
|
+
in_batch?: boolean;
|
|
144
|
+
trigger_dep_index?: number;
|
|
145
|
+
trigger_dep_name?: string;
|
|
146
|
+
/**
|
|
147
|
+
* V0 version of the triggering dep at observation time (§6.0b).
|
|
148
|
+
* This is the dep's post-emission version (after its own `advanceVersion`),
|
|
149
|
+
* not the pre-emission version that caused this node's recomputation.
|
|
150
|
+
*/
|
|
151
|
+
trigger_version?: {
|
|
152
|
+
id: string;
|
|
153
|
+
version: number;
|
|
154
|
+
};
|
|
155
|
+
dep_values?: unknown[];
|
|
156
|
+
};
|
|
157
|
+
/** Built-in color presets for {@link Graph.spy}. */
|
|
158
|
+
type GraphSpyThemeName = "none" | "ansi";
|
|
159
|
+
/** ANSI/style overrides for {@link Graph.spy} event rendering. */
|
|
160
|
+
type GraphSpyTheme = Partial<Record<ObserveEvent["type"] | "path" | "reset", string>>;
|
|
161
|
+
/** Options for {@link Graph.spy}. */
|
|
162
|
+
type GraphSpyOptions = ObserveOptions & {
|
|
163
|
+
/** Observe one path; omit for graph-wide mode. */
|
|
164
|
+
path?: string;
|
|
165
|
+
/** Keep only these event types in spy output. */
|
|
166
|
+
includeTypes?: ObserveEvent["type"][];
|
|
167
|
+
/** Exclude these event types from spy output. */
|
|
168
|
+
excludeTypes?: ObserveEvent["type"][];
|
|
169
|
+
/** Built-in color preset (`ansi` default) or explicit color tokens. */
|
|
170
|
+
theme?: GraphSpyThemeName | GraphSpyTheme;
|
|
171
|
+
/** One-line `pretty` output (default) or JSON-per-event. */
|
|
172
|
+
format?: "pretty" | "json";
|
|
173
|
+
/** Optional sink for rendered lines (`console.log` by default). */
|
|
174
|
+
logger?: (line: string, event: ObserveEvent) => void;
|
|
175
|
+
};
|
|
176
|
+
/** Handle returned by {@link Graph.spy}. */
|
|
177
|
+
type GraphSpyHandle = {
|
|
178
|
+
readonly result: ObserveResult;
|
|
179
|
+
dispose(): void;
|
|
180
|
+
};
|
|
181
|
+
/** Options for {@link Graph.dumpGraph}. */
|
|
182
|
+
type GraphDumpOptions = {
|
|
183
|
+
actor?: Actor;
|
|
184
|
+
filter?: DescribeFilter;
|
|
185
|
+
format?: "pretty" | "json";
|
|
186
|
+
indent?: number;
|
|
187
|
+
includeEdges?: boolean;
|
|
188
|
+
includeSubgraphs?: boolean;
|
|
189
|
+
logger?: (text: string) => void;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Named container for nodes and explicit edges (GRAPHREFLY-SPEC §3.1–§3.7).
|
|
193
|
+
*
|
|
194
|
+
* Qualified paths use `::` as the segment separator (for example `parent::child::node`).
|
|
195
|
+
*
|
|
196
|
+
* Edges are pure wires: `connect` only validates wiring — the target must already list the source in
|
|
197
|
+
* its dependency array; no transforms run on the edge.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* import { Graph, state } from "@graphrefly/graphrefly-ts";
|
|
202
|
+
*
|
|
203
|
+
* const g = new Graph("app");
|
|
204
|
+
* g.add("counter", state(0));
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @category graph
|
|
208
|
+
*/
|
|
209
|
+
declare class Graph {
|
|
210
|
+
private static readonly _factories;
|
|
211
|
+
readonly name: string;
|
|
212
|
+
readonly opts: Readonly<GraphOptions>;
|
|
213
|
+
/** @internal — exposed for {@link teardownMountedGraph} and cross-graph helpers. */
|
|
214
|
+
readonly _nodes: Map<string, Node<unknown>>;
|
|
215
|
+
private readonly _edges;
|
|
216
|
+
/** @internal — exposed for {@link teardownMountedGraph}. */
|
|
217
|
+
readonly _mounts: Map<string, Graph>;
|
|
218
|
+
private readonly _autoCheckpointDisposers;
|
|
219
|
+
private _defaultVersioningLevel;
|
|
220
|
+
static registerFactory(pattern: string, factory: GraphNodeFactory): void;
|
|
221
|
+
static unregisterFactory(pattern: string): void;
|
|
222
|
+
/**
|
|
223
|
+
* @param name - Non-empty graph id (must not contain `::`).
|
|
224
|
+
* @param opts - Reserved for future hooks; currently unused.
|
|
225
|
+
*/
|
|
226
|
+
constructor(name: string, opts?: GraphOptions);
|
|
227
|
+
private static _factoryForPath;
|
|
228
|
+
private static _ownerForPath;
|
|
229
|
+
/**
|
|
230
|
+
* Graphs reachable from this instance via nested {@link Graph.mount} (includes `this`).
|
|
231
|
+
*/
|
|
232
|
+
private _graphsReachableViaMounts;
|
|
233
|
+
/**
|
|
234
|
+
* Resolve an endpoint: returns `[owningGraph, localName, node]`.
|
|
235
|
+
* Accepts both local names and `::` qualified paths.
|
|
236
|
+
*/
|
|
237
|
+
private _resolveEndpoint;
|
|
238
|
+
private _resolveEndpointFromSegments;
|
|
239
|
+
/**
|
|
240
|
+
* Registers a node under a local name. Fails if the name is already used,
|
|
241
|
+
* reserved by a mount, or the same node instance is already registered.
|
|
242
|
+
*
|
|
243
|
+
* @param name - Local key (no `::`).
|
|
244
|
+
* @param node - Node instance to own.
|
|
245
|
+
*/
|
|
246
|
+
add(name: string, node: Node): void;
|
|
247
|
+
/**
|
|
248
|
+
* Set a default versioning level for all nodes added to this graph (roadmap §6.0).
|
|
249
|
+
*
|
|
250
|
+
* Nodes already registered are retroactively upgraded. Nodes added later via
|
|
251
|
+
* {@link add} will inherit this level unless they already have versioning.
|
|
252
|
+
*
|
|
253
|
+
* **Scope:** Does not propagate to mounted subgraphs. Call `setVersioning`
|
|
254
|
+
* on each child graph separately if needed.
|
|
255
|
+
*
|
|
256
|
+
* @param level - `0` for V0, `1` for V1, or `undefined` to clear.
|
|
257
|
+
*/
|
|
258
|
+
setVersioning(level: VersioningLevel | undefined): void;
|
|
259
|
+
/**
|
|
260
|
+
* Unregisters a node or unmounts a subgraph, drops incident edges, and sends
|
|
261
|
+
* `[[TEARDOWN]]` to the removed node or recursively through the mounted subtree (§3.2).
|
|
262
|
+
*
|
|
263
|
+
* @param name - Local mount or node name.
|
|
264
|
+
*/
|
|
265
|
+
remove(name: string): void;
|
|
266
|
+
/**
|
|
267
|
+
* Returns a node by local name or `::` qualified path.
|
|
268
|
+
* Local names are looked up directly; paths with `::` delegate to {@link resolve}.
|
|
269
|
+
*
|
|
270
|
+
* @param name - Local name or qualified path.
|
|
271
|
+
*/
|
|
272
|
+
node(name: string): Node;
|
|
273
|
+
/**
|
|
274
|
+
* Reads `graph.node(name).get()` — accepts `::` qualified paths (§3.2).
|
|
275
|
+
*
|
|
276
|
+
* @param name - Local name or qualified path.
|
|
277
|
+
* @returns Cached value or `undefined`.
|
|
278
|
+
*/
|
|
279
|
+
get(name: string): unknown;
|
|
280
|
+
/**
|
|
281
|
+
* Shorthand for `graph.node(name).down([[DATA, value]], { actor })` — accepts `::` qualified paths (§3.2).
|
|
282
|
+
*
|
|
283
|
+
* @param name - Local name or qualified path.
|
|
284
|
+
* @param value - Next `DATA` payload.
|
|
285
|
+
* @param options - Optional `actor` and `internal` guard bypass.
|
|
286
|
+
*/
|
|
287
|
+
set(name: string, value: unknown, options?: GraphActorOptions): void;
|
|
288
|
+
/**
|
|
289
|
+
* Record a wire from `fromPath` → `toPath` (§3.3). Accepts local names or
|
|
290
|
+
* `::` qualified paths. The target must be a {@link NodeImpl} whose `_deps`
|
|
291
|
+
* includes the source node (same reference). Idempotent.
|
|
292
|
+
*
|
|
293
|
+
* Same-owner edges are stored on the owning child graph; cross-subgraph edges
|
|
294
|
+
* are stored on this (parent) graph's registry.
|
|
295
|
+
*
|
|
296
|
+
* @param fromPath - Source endpoint (local or qualified).
|
|
297
|
+
* @param toPath - Target endpoint whose deps already include the source node.
|
|
298
|
+
*/
|
|
299
|
+
connect(fromPath: string, toPath: string): void;
|
|
300
|
+
/**
|
|
301
|
+
* Remove a registered edge (§3.3). Accepts local names or `::` qualified paths.
|
|
302
|
+
*
|
|
303
|
+
* **Registry-only (§C resolved):** This drops the edge from the graph's edge
|
|
304
|
+
* registry only. It does **not** mutate the target node's constructor-time
|
|
305
|
+
* dependency list, bitmasks, or upstream subscriptions. Message flow follows
|
|
306
|
+
* constructor-time deps, not the edge registry. For runtime dep rewiring, use
|
|
307
|
+
* {@link dynamicNode}.
|
|
308
|
+
*
|
|
309
|
+
* @param fromPath - Registered edge tail.
|
|
310
|
+
* @param toPath - Registered edge head.
|
|
311
|
+
*/
|
|
312
|
+
disconnect(fromPath: string, toPath: string): void;
|
|
313
|
+
/**
|
|
314
|
+
* Returns registered `[from, to]` edge pairs (read-only snapshot).
|
|
315
|
+
*
|
|
316
|
+
* @returns Edge pairs recorded on this graph instance’s local `_edges` set.
|
|
317
|
+
*/
|
|
318
|
+
edges(): ReadonlyArray<[string, string]>;
|
|
319
|
+
/**
|
|
320
|
+
* Embed a child graph at a local mount name (§3.4). Child nodes are reachable via
|
|
321
|
+
* {@link Graph.resolve} using `::` delimited paths (§3.5). Lifecycle
|
|
322
|
+
* {@link Graph.signal} visits mounted subgraphs recursively.
|
|
323
|
+
*
|
|
324
|
+
* Rejects: same name as existing node or mount, self-mount, mount cycles,
|
|
325
|
+
* and the same child graph instance mounted twice on one parent.
|
|
326
|
+
*
|
|
327
|
+
* @param name - Local mount point.
|
|
328
|
+
* @param child - Nested `Graph` instance.
|
|
329
|
+
*/
|
|
330
|
+
mount(name: string, child: Graph): void;
|
|
331
|
+
/**
|
|
332
|
+
* Look up a node by qualified path (§3.5). Segments are separated by `::`.
|
|
333
|
+
*
|
|
334
|
+
* If the first segment equals this graph's {@link Graph.name}, it is stripped
|
|
335
|
+
* (so `root.resolve("app::a")` works when `root.name === "app"`).
|
|
336
|
+
*
|
|
337
|
+
* @param path - Qualified `::` path or local name.
|
|
338
|
+
* @returns The resolved `Node`.
|
|
339
|
+
*/
|
|
340
|
+
resolve(path: string): Node;
|
|
341
|
+
private _resolveFromSegments;
|
|
342
|
+
/**
|
|
343
|
+
* Resolve `::__meta__::key` segments from a registered primary node (possibly chained).
|
|
344
|
+
*/
|
|
345
|
+
private _resolveMetaChainFromNode;
|
|
346
|
+
private _resolveMetaEndpointKeys;
|
|
347
|
+
/**
|
|
348
|
+
* Deliver a message batch to every registered node in this graph and, recursively,
|
|
349
|
+
* in mounted child graphs (§3.7). Recurses into mounts first, then delivers to
|
|
350
|
+
* local nodes (sorted by name). Each {@link Node} receives at most one delivery
|
|
351
|
+
* per call (deduped by reference).
|
|
352
|
+
*
|
|
353
|
+
* Companion `meta` nodes receive the same batch for control-plane types (e.g.
|
|
354
|
+
* PAUSE) that the primary does not forward. **TEARDOWN-only** batches skip the
|
|
355
|
+
* extra meta pass — the primary’s `down()` already cascades TEARDOWN to meta.
|
|
356
|
+
*
|
|
357
|
+
* @param messages - Batch to deliver to every registered node (and mounts, recursively).
|
|
358
|
+
* @param options - Optional `actor` / `internal` for transport.
|
|
359
|
+
*/
|
|
360
|
+
signal(messages: Messages, options?: GraphActorOptions): void;
|
|
361
|
+
private _signalDeliver;
|
|
362
|
+
private _signalMetaSubtree;
|
|
363
|
+
/**
|
|
364
|
+
* Static structure snapshot: qualified node keys, edges, mount names (GRAPHREFLY-SPEC §3.6, Appendix B).
|
|
365
|
+
*
|
|
366
|
+
* @param options - Optional `actor` for guard-scoped visibility and/or `filter` for selective output.
|
|
367
|
+
* @returns JSON-shaped describe payload for this graph tree.
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```ts
|
|
371
|
+
* graph.describe() // full snapshot
|
|
372
|
+
* graph.describe({ actor: llm }) // guard-scoped
|
|
373
|
+
* graph.describe({ filter: { status: "errored" } }) // only errored nodes
|
|
374
|
+
* graph.describe({ filter: (n) => n.type === "state" }) // predicate filter
|
|
375
|
+
* ```
|
|
376
|
+
*/
|
|
377
|
+
describe(options?: {
|
|
378
|
+
actor?: Actor;
|
|
379
|
+
filter?: DescribeFilter;
|
|
380
|
+
}): GraphDescribeOutput;
|
|
381
|
+
private _collectSubgraphs;
|
|
382
|
+
private _collectAllEdges;
|
|
383
|
+
private _qualifyEdgeEndpoint;
|
|
384
|
+
private _collectObserveTargets;
|
|
385
|
+
private _appendMetaObserveTargets;
|
|
386
|
+
/**
|
|
387
|
+
* Live message stream from one node (or meta path), or from the whole graph (§3.6).
|
|
388
|
+
*
|
|
389
|
+
* Overloads: `(path, options?)` for one node; `(options?)` for all nodes. Whole-graph mode
|
|
390
|
+
* subscribes in **sorted path order** (code-point order). With structured options
|
|
391
|
+
* (`structured`, `timeline`, `causal`, `derived`), returns an {@link ObserveResult}.
|
|
392
|
+
* Inspector-gated extras (`causal` / `derived`) require {@link Graph.inspectorEnabled}.
|
|
393
|
+
*
|
|
394
|
+
* @param pathOrOpts - Qualified `path` string, or omit and pass only `options` for graph-wide observation.
|
|
395
|
+
* @param options - Optional `actor`, `structured`, `causal`, `timeline` (inspector-gated).
|
|
396
|
+
* @returns `GraphObserveOne`, `GraphObserveAll`, or `ObserveResult` depending on overload/options.
|
|
397
|
+
*/
|
|
398
|
+
observe(path: string, options?: ObserveOptions & {
|
|
399
|
+
structured?: true;
|
|
400
|
+
timeline?: true;
|
|
401
|
+
causal?: true;
|
|
402
|
+
derived?: true;
|
|
403
|
+
}): ObserveResult;
|
|
404
|
+
observe(path: string, options?: ObserveOptions): GraphObserveOne;
|
|
405
|
+
observe(options: ObserveOptions & {
|
|
406
|
+
structured?: true;
|
|
407
|
+
timeline?: true;
|
|
408
|
+
causal?: true;
|
|
409
|
+
derived?: true;
|
|
410
|
+
}): ObserveResult;
|
|
411
|
+
observe(options?: ObserveOptions): GraphObserveAll;
|
|
412
|
+
private _createObserveResult;
|
|
413
|
+
private _createObserveResultForAll;
|
|
414
|
+
/**
|
|
415
|
+
* Convenience live debugger over {@link Graph.observe}. Logs protocol events as they flow.
|
|
416
|
+
*
|
|
417
|
+
* Supports one-node (`path`) and graph-wide modes, event filtering, and JSON/pretty rendering.
|
|
418
|
+
* Color themes are built in (`ansi` / `none`) to avoid external dependencies.
|
|
419
|
+
*
|
|
420
|
+
* @param options - Spy configuration.
|
|
421
|
+
* @returns Disposable handle plus a structured observation accumulator.
|
|
422
|
+
*/
|
|
423
|
+
spy(options?: GraphSpyOptions): GraphSpyHandle;
|
|
424
|
+
/**
|
|
425
|
+
* CLI/debug-friendly graph dump built on {@link Graph.describe}.
|
|
426
|
+
*
|
|
427
|
+
* @param options - Optional actor/filter/format toggles.
|
|
428
|
+
* @returns Rendered graph text.
|
|
429
|
+
*/
|
|
430
|
+
dumpGraph(options?: GraphDumpOptions): string;
|
|
431
|
+
/**
|
|
432
|
+
* Sends `[[TEARDOWN]]` to all nodes, then clears registries on this graph and every
|
|
433
|
+
* mounted subgraph (§3.7). The instance is left empty and may be reused with {@link Graph.add}.
|
|
434
|
+
*/
|
|
435
|
+
destroy(): void;
|
|
436
|
+
/** Clear structure after parent already signaled TEARDOWN through this subtree. */
|
|
437
|
+
private _destroyClearOnly;
|
|
438
|
+
/**
|
|
439
|
+
* Serializes structure and current values to JSON-shaped data (§3.8). Same information
|
|
440
|
+
* as {@link Graph.describe} plus a `version` field for format evolution.
|
|
441
|
+
*
|
|
442
|
+
* @returns Persistable snapshot with sorted keys.
|
|
443
|
+
*/
|
|
444
|
+
snapshot(): GraphPersistSnapshot;
|
|
445
|
+
/**
|
|
446
|
+
* Apply persisted values onto an existing graph whose topology matches the snapshot
|
|
447
|
+
* (§3.8). Only {@link DescribeNodeOutput.type} `state` and `producer` entries with a
|
|
448
|
+
* `value` field are written; `derived` / `operator` / `effect` are skipped so deps
|
|
449
|
+
* drive recomputation. Unknown paths are ignored.
|
|
450
|
+
*
|
|
451
|
+
* @param data - Snapshot envelope with matching `name` and node slices.
|
|
452
|
+
* @throws If `data.name` does not equal {@link Graph.name}.
|
|
453
|
+
*/
|
|
454
|
+
restore(data: GraphPersistSnapshot, options?: {
|
|
455
|
+
only?: string | readonly string[];
|
|
456
|
+
}): void;
|
|
457
|
+
/**
|
|
458
|
+
* Creates a graph named from the snapshot, optionally runs `build` to register nodes
|
|
459
|
+
* and mounts, then {@link Graph.restore} values (§3.8).
|
|
460
|
+
*
|
|
461
|
+
* @param data - Snapshot envelope (`version` checked).
|
|
462
|
+
* @param build - Optional callback to construct topology before values are applied.
|
|
463
|
+
* @returns Hydrated `Graph` instance.
|
|
464
|
+
*/
|
|
465
|
+
static fromSnapshot(data: GraphPersistSnapshot, build?: (g: Graph) => void): Graph;
|
|
466
|
+
/**
|
|
467
|
+
* Plain snapshot with **recursively sorted object keys** for deterministic serialization (§3.8).
|
|
468
|
+
*
|
|
469
|
+
* @remarks
|
|
470
|
+
* ECMAScript `JSON.stringify(graph)` invokes this method; it must return a plain object, not an
|
|
471
|
+
* already-stringified JSON string (otherwise the graph would be double-encoded).
|
|
472
|
+
* For a single UTF-8 string with a trailing newline (convenient for git), use {@link Graph.toJSONString}.
|
|
473
|
+
*
|
|
474
|
+
* @returns Same object as {@link Graph.snapshot}.
|
|
475
|
+
*/
|
|
476
|
+
toJSON(): GraphPersistSnapshot;
|
|
477
|
+
/**
|
|
478
|
+
* Deterministic JSON **text**: `JSON.stringify` of {@link Graph.toJSON} plus a trailing newline (§3.8).
|
|
479
|
+
*
|
|
480
|
+
* @returns Stable string suitable for diffs.
|
|
481
|
+
*/
|
|
482
|
+
toJSONString(): string;
|
|
483
|
+
/**
|
|
484
|
+
* Debounced persistence wired to graph-wide observe stream (spec §3.8 auto-checkpoint).
|
|
485
|
+
*
|
|
486
|
+
* Checkpoint trigger uses {@link messageTier}: only batches containing tier >= 2 messages
|
|
487
|
+
* schedule a save (`DATA`/`RESOLVED`/terminal/destruction), never pure tier-0/1 control waves.
|
|
488
|
+
*/
|
|
489
|
+
autoCheckpoint(adapter: AutoCheckpointAdapter, options?: GraphAutoCheckpointOptions): GraphAutoCheckpointHandle;
|
|
490
|
+
/**
|
|
491
|
+
* Export the current graph topology as Mermaid flowchart text.
|
|
492
|
+
*
|
|
493
|
+
* Renders qualified node paths and registered edges from {@link Graph.describe}.
|
|
494
|
+
*
|
|
495
|
+
* @param options - Optional diagram direction (`LR` by default).
|
|
496
|
+
* @returns Mermaid flowchart source.
|
|
497
|
+
*/
|
|
498
|
+
toMermaid(options?: GraphDiagramOptions): string;
|
|
499
|
+
/**
|
|
500
|
+
* Export the current graph topology as D2 diagram text.
|
|
501
|
+
*
|
|
502
|
+
* Renders qualified node paths, constructor deps, and registered edges from {@link Graph.describe}.
|
|
503
|
+
*
|
|
504
|
+
* @param options - Optional diagram direction (`LR` by default).
|
|
505
|
+
* @returns D2 source text.
|
|
506
|
+
*/
|
|
507
|
+
toD2(options?: GraphDiagramOptions): string;
|
|
508
|
+
/**
|
|
509
|
+
* When `false`, structured observation options (`causal`, `timeline`),
|
|
510
|
+
* `annotate()`, and `traceLog()` are no-ops. Raw `observe()` always works.
|
|
511
|
+
*
|
|
512
|
+
* Default: `true` outside production (`process.env.NODE_ENV !== "production"`).
|
|
513
|
+
*/
|
|
514
|
+
static inspectorEnabled: boolean;
|
|
515
|
+
private _annotations;
|
|
516
|
+
private _traceRing;
|
|
517
|
+
/**
|
|
518
|
+
* Attaches a reasoning annotation to a node — captures *why* an AI agent set a value.
|
|
519
|
+
*
|
|
520
|
+
* No-op when {@link Graph.inspectorEnabled} is `false`.
|
|
521
|
+
*
|
|
522
|
+
* @param path - Qualified node path.
|
|
523
|
+
* @param reason - Free-text note stored in the trace ring buffer.
|
|
524
|
+
*/
|
|
525
|
+
annotate(path: string, reason: string): void;
|
|
526
|
+
/**
|
|
527
|
+
* Returns a chronological log of all reasoning annotations (ring buffer).
|
|
528
|
+
*
|
|
529
|
+
* @returns `[]` when {@link Graph.inspectorEnabled} is `false`.
|
|
530
|
+
*/
|
|
531
|
+
traceLog(): readonly TraceEntry[];
|
|
532
|
+
/**
|
|
533
|
+
* Computes structural + value diff between two {@link Graph.describe} snapshots.
|
|
534
|
+
*
|
|
535
|
+
* @param a - Earlier describe output.
|
|
536
|
+
* @param b - Later describe output.
|
|
537
|
+
* @returns Added/removed nodes, changed fields, and edge deltas.
|
|
538
|
+
*/
|
|
539
|
+
static diff(a: GraphDescribeOutput, b: GraphDescribeOutput): GraphDiffResult;
|
|
540
|
+
}
|
|
541
|
+
/** Entry in the reasoning trace ring buffer (roadmap 3.3). */
|
|
542
|
+
type TraceEntry = {
|
|
543
|
+
path: string;
|
|
544
|
+
reason: string;
|
|
545
|
+
timestamp_ns: number;
|
|
546
|
+
};
|
|
547
|
+
/** Result of {@link Graph.diff}. */
|
|
548
|
+
type GraphDiffResult = {
|
|
549
|
+
nodesAdded: string[];
|
|
550
|
+
nodesRemoved: string[];
|
|
551
|
+
nodesChanged: GraphDiffChange[];
|
|
552
|
+
edgesAdded: Array<{
|
|
553
|
+
from: string;
|
|
554
|
+
to: string;
|
|
555
|
+
}>;
|
|
556
|
+
edgesRemoved: Array<{
|
|
557
|
+
from: string;
|
|
558
|
+
to: string;
|
|
559
|
+
}>;
|
|
560
|
+
subgraphsAdded: string[];
|
|
561
|
+
subgraphsRemoved: string[];
|
|
562
|
+
};
|
|
563
|
+
/** A single field change within a diff. */
|
|
564
|
+
type GraphDiffChange = {
|
|
565
|
+
path: string;
|
|
566
|
+
field: string;
|
|
567
|
+
from: unknown;
|
|
568
|
+
to: unknown;
|
|
569
|
+
};
|
|
570
|
+
/** Direction for {@link reachable} graph traversal. */
|
|
571
|
+
type ReachableDirection = "upstream" | "downstream";
|
|
572
|
+
/** Options for {@link reachable}. */
|
|
573
|
+
type ReachableOptions = {
|
|
574
|
+
/** Maximum hop depth from `from` (0 returns `[]`). Omit for unbounded traversal. */
|
|
575
|
+
maxDepth?: number;
|
|
576
|
+
};
|
|
577
|
+
/**
|
|
578
|
+
* Reachability query over a {@link Graph.describe} snapshot.
|
|
579
|
+
*
|
|
580
|
+
* Traversal combines dependency links (`deps`) and explicit graph edges (`edges`):
|
|
581
|
+
* - `upstream`: follows `deps` plus incoming edges.
|
|
582
|
+
* - `downstream`: follows reverse-`deps` plus outgoing edges.
|
|
583
|
+
*
|
|
584
|
+
* @param described - `graph.describe()` output to traverse.
|
|
585
|
+
* @param from - Start path (qualified node path).
|
|
586
|
+
* @param direction - Traversal direction.
|
|
587
|
+
* @param options - Optional max depth bound.
|
|
588
|
+
* @returns Sorted list of reachable paths (excluding `from`).
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```ts
|
|
592
|
+
* import { Graph, reachable } from "@graphrefly/graphrefly-ts";
|
|
593
|
+
*
|
|
594
|
+
* const g = new Graph("app");
|
|
595
|
+
* const a = g.register("a");
|
|
596
|
+
* const b = g.register("b", [a]);
|
|
597
|
+
* const described = g.describe();
|
|
598
|
+
*
|
|
599
|
+
* reachable(described, "app.a", "downstream"); // ["app.b"]
|
|
600
|
+
* reachable(described, "app.b", "upstream"); // ["app.a"]
|
|
601
|
+
* ```
|
|
602
|
+
*/
|
|
603
|
+
declare function reachable(described: GraphDescribeOutput, from: string, direction: ReachableDirection, options?: ReachableOptions): string[];
|
|
604
|
+
|
|
605
|
+
export { type AutoCheckpointAdapter as A, type DescribeFilter as D, Graph as G, type ObserveEvent as O, type ReachableDirection as R, type TraceEntry as T, type GraphOptions as a, type GraphAutoCheckpointHandle as b, type GraphAutoCheckpointOptions as c, GRAPH_META_SEGMENT as d, type GraphActorOptions as e, type GraphCheckpointRecord as f, type GraphDescribeOutput as g, type GraphDiagramDirection as h, type GraphDiagramOptions as i, type GraphDiffChange as j, type GraphDiffResult as k, type GraphDumpOptions as l, type GraphFactoryContext as m, type GraphNodeFactory as n, type GraphObserveAll as o, type GraphObserveOne as p, type GraphPersistSnapshot as q, type GraphSpyHandle as r, type GraphSpyOptions as s, type GraphSpyTheme as t, type GraphSpyThemeName as u, type ObserveOptions as v, type ObserveResult as w, type ReachableOptions as x, reachable as y };
|