@dxos/app-graph 0.16.0 → 0.17.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/dist/lib/chunk-AppGraph.mjs +62 -19
- package/dist/lib/chunk-AppGraph.mjs.map +1 -1
- package/dist/lib/chunk-atoms.mjs +1 -1
- package/dist/types/src/AppGraph.bench.d.ts +2 -0
- package/dist/types/src/AppGraph.bench.d.ts.map +1 -0
- package/dist/types/src/AppGraph.d.ts.map +1 -1
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +27 -23
- package/src/AppGraph.bench.ts +111 -0
- package/src/AppGraph.test.ts +170 -0
- package/src/AppGraph.ts +83 -7
- package/src/expansion.test.ts +19 -0
- package/src/util.test.ts +16 -0
- package/src/util.ts +2 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
-
import { a as action, g as relation, i as RootType, s as child } from "./chunk-AppGraphNode.mjs";
|
|
2
|
+
import { a as action, g as relation, i as RootType, l as isAction, s as child } from "./chunk-AppGraphNode.mjs";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Equal from "effect/Equal";
|
|
4
5
|
import * as Function from "effect/Function";
|
|
6
|
+
import * as Hash from "effect/Hash";
|
|
5
7
|
import * as Option from "effect/Option";
|
|
6
8
|
import * as Pipeable from "effect/Pipeable";
|
|
7
9
|
import * as Atom from "effect/reactivity/Atom";
|
|
@@ -38,7 +40,7 @@ var nodeArgsUnchanged = (prev, next) => {
|
|
|
38
40
|
if (prev.length !== next.length) return false;
|
|
39
41
|
return prev.every((prevNode, idx) => {
|
|
40
42
|
const nextNode = next[idx];
|
|
41
|
-
return prevNode.id === nextNode.id && prevNode.type === nextNode.type && shallowEqual(prevNode.data, nextNode.data) &&
|
|
43
|
+
return prevNode.id === nextNode.id && prevNode.type === nextNode.type && shallowEqual(prevNode.data, nextNode.data) && Equal.equals(prevNode.properties ?? {}, nextNode.properties ?? {}) && nodeArgsUnchanged(prevNode.nodes ?? [], nextNode.nodes ?? []) && nodeArgsUnchanged(prevNode.actions ?? [], nextNode.actions ?? []);
|
|
42
44
|
});
|
|
43
45
|
};
|
|
44
46
|
//#endregion
|
|
@@ -101,7 +103,7 @@ var relationFromKey = (encoded) => {
|
|
|
101
103
|
invariant(parts.length === 2 && parts[0].length > 0 && parts[1].length > 0, `Invalid relation key: ${encoded}`, {
|
|
102
104
|
"~LogMeta": "~LogMeta",
|
|
103
105
|
F: __dxlog_file,
|
|
104
|
-
L:
|
|
106
|
+
L: 158,
|
|
105
107
|
S: void 0,
|
|
106
108
|
A: ["parts.length === 2 && parts[0].length > 0 && parts[1].length > 0", "`Invalid relation key: ${encoded}`"]
|
|
107
109
|
});
|
|
@@ -109,7 +111,7 @@ var relationFromKey = (encoded) => {
|
|
|
109
111
|
invariant(directionRaw === "outbound" || directionRaw === "inbound", `Invalid relation direction: ${directionRaw}`, {
|
|
110
112
|
"~LogMeta": "~LogMeta",
|
|
111
113
|
F: __dxlog_file,
|
|
112
|
-
L:
|
|
114
|
+
L: 160,
|
|
113
115
|
S: void 0,
|
|
114
116
|
A: ["directionRaw === 'outbound' || directionRaw === 'inbound'", "`Invalid relation direction: ${directionRaw}`"]
|
|
115
117
|
});
|
|
@@ -121,7 +123,7 @@ var relationFromConnectionKey = (key) => {
|
|
|
121
123
|
invariant(id && encodedRelation, `Invalid connection key: ${key}`, {
|
|
122
124
|
"~LogMeta": "~LogMeta",
|
|
123
125
|
F: __dxlog_file,
|
|
124
|
-
L:
|
|
126
|
+
L: 169,
|
|
125
127
|
S: void 0,
|
|
126
128
|
A: ["id && encodedRelation", "`Invalid connection key: ${key}`"]
|
|
127
129
|
});
|
|
@@ -166,12 +168,15 @@ var getGraph = (node) => {
|
|
|
166
168
|
invariant(graph, "Node is not associated with a graph.", {
|
|
167
169
|
"~LogMeta": "~LogMeta",
|
|
168
170
|
F: __dxlog_file,
|
|
169
|
-
L:
|
|
171
|
+
L: 214,
|
|
170
172
|
S: void 0,
|
|
171
173
|
A: ["graph", "'Node is not associated with a graph.'"]
|
|
172
174
|
});
|
|
173
175
|
return graph;
|
|
174
176
|
};
|
|
177
|
+
/** Carried by each forwarder {@link stableData} makes, so any graph recognizes one without a lookup table. */
|
|
178
|
+
var ForwardedKey = Symbol("app-graph/forwarded");
|
|
179
|
+
var isForwarder = (value) => typeof value === "function" && ForwardedKey in value;
|
|
175
180
|
/**
|
|
176
181
|
* The Graph represents the user interface information architecture of the application constructed via plugins.
|
|
177
182
|
* @internal
|
|
@@ -182,6 +187,12 @@ var GraphImpl = class {
|
|
|
182
187
|
pipe() {
|
|
183
188
|
return Pipeable.pipeArguments(this, arguments);
|
|
184
189
|
}
|
|
190
|
+
[Hash.symbol]() {
|
|
191
|
+
return Hash.random(this);
|
|
192
|
+
}
|
|
193
|
+
[Equal.symbol](that) {
|
|
194
|
+
return this === that;
|
|
195
|
+
}
|
|
185
196
|
onNodeChanged = new Event();
|
|
186
197
|
_onExpand;
|
|
187
198
|
_onRemoveNode;
|
|
@@ -273,7 +284,10 @@ var GraphImpl = class {
|
|
|
273
284
|
type: RootType,
|
|
274
285
|
data: null
|
|
275
286
|
}));
|
|
276
|
-
nodes?.forEach((node) => this._setNode(node.id, this._constructNode(node
|
|
287
|
+
nodes?.forEach((node) => this._setNode(node.id, this._constructNode(typeof node.data === "function" ? {
|
|
288
|
+
...node,
|
|
289
|
+
data: stableData(this, node.id, node.type, void 0, node.data)
|
|
290
|
+
} : node)));
|
|
277
291
|
Object.entries(edges ?? {}).forEach(([source, relations]) => {
|
|
278
292
|
Object.entries(relations).forEach(([relation, targets]) => {
|
|
279
293
|
targets.forEach((target) => this._setEdge(source, target, relation));
|
|
@@ -321,7 +335,7 @@ var GraphImpl = class {
|
|
|
321
335
|
invariant(!this._pins, "Graph is already retained.", {
|
|
322
336
|
"~LogMeta": "~LogMeta",
|
|
323
337
|
F: __dxlog_file,
|
|
324
|
-
L:
|
|
338
|
+
L: 456,
|
|
325
339
|
S: this,
|
|
326
340
|
A: ["!this._pins", "'Graph is already retained.'"]
|
|
327
341
|
});
|
|
@@ -523,7 +537,7 @@ var expandSync = (graph, id, relation) => {
|
|
|
523
537
|
}, {
|
|
524
538
|
"~LogMeta": "~LogMeta",
|
|
525
539
|
F: __dxlog_file,
|
|
526
|
-
L:
|
|
540
|
+
L: 717,
|
|
527
541
|
S: void 0
|
|
528
542
|
});
|
|
529
543
|
return graph;
|
|
@@ -535,7 +549,7 @@ var expandSync = (graph, id, relation) => {
|
|
|
535
549
|
}, {
|
|
536
550
|
"~LogMeta": "~LogMeta",
|
|
537
551
|
F: __dxlog_file,
|
|
538
|
-
L:
|
|
552
|
+
L: 722,
|
|
539
553
|
S: void 0
|
|
540
554
|
});
|
|
541
555
|
if (!expanded) {
|
|
@@ -635,6 +649,28 @@ var addNodes = (graph, nodes) => {
|
|
|
635
649
|
return graph;
|
|
636
650
|
};
|
|
637
651
|
/**
|
|
652
|
+
* Builders recreate an action's closure on every run, so an action's `data` is held behind a stable
|
|
653
|
+
* forwarder per node whose target is swapped: a re-offer that changes nothing else emits nothing,
|
|
654
|
+
* and invoking the node still runs the latest closure. Only actions: other function data (a type
|
|
655
|
+
* node's schema class) is read for its statics, which a forwarder does not carry.
|
|
656
|
+
*/
|
|
657
|
+
var stableData = (graph, id, type, existing, data) => {
|
|
658
|
+
if (type !== "org.dxos.type.graphAction" || typeof data !== "function") return data;
|
|
659
|
+
const owned = (forwarder) => forwarder[ForwardedKey].graph === graph && forwarder[ForwardedKey].id === id;
|
|
660
|
+
if (isForwarder(data) && owned(data)) return data;
|
|
661
|
+
const target = isForwarder(data) ? data[ForwardedKey].target : data;
|
|
662
|
+
if (isForwarder(existing) && owned(existing)) {
|
|
663
|
+
existing[ForwardedKey].target = target;
|
|
664
|
+
return existing;
|
|
665
|
+
}
|
|
666
|
+
const cell = {
|
|
667
|
+
target,
|
|
668
|
+
graph,
|
|
669
|
+
id
|
|
670
|
+
};
|
|
671
|
+
return Object.assign((...args) => cell.target(...args), { [ForwardedKey]: cell });
|
|
672
|
+
};
|
|
673
|
+
/**
|
|
638
674
|
* Add a node to the graph.
|
|
639
675
|
*/
|
|
640
676
|
var addNode = (graph, nodeArg) => {
|
|
@@ -644,19 +680,22 @@ var addNode = (graph, nodeArg) => {
|
|
|
644
680
|
Option.match(existingNode, {
|
|
645
681
|
onSome: (existing) => {
|
|
646
682
|
const typeChanged = existing.type !== type;
|
|
647
|
-
const
|
|
648
|
-
const
|
|
649
|
-
const
|
|
683
|
+
const nextData = stableData(internal, id, type, existing.data, data);
|
|
684
|
+
const dataChanged = !shallowEqual(existing.data, nextData);
|
|
685
|
+
const propertiesChanged = Object.keys(properties).some((key) => !Equal.equals(existing.properties[key], properties[key]));
|
|
686
|
+
const contextChanged = rest._actionContext !== void 0 && (isAction(existing) ? existing._actionContext : void 0) !== rest._actionContext;
|
|
687
|
+
const changed = typeChanged || dataChanged || propertiesChanged || contextChanged;
|
|
650
688
|
log("existing node", {
|
|
651
689
|
id,
|
|
652
690
|
changed,
|
|
653
691
|
typeChanged,
|
|
654
692
|
dataChanged,
|
|
655
|
-
propertiesChanged
|
|
693
|
+
propertiesChanged,
|
|
694
|
+
contextChanged
|
|
656
695
|
}, {
|
|
657
696
|
"~LogMeta": "~LogMeta",
|
|
658
697
|
F: __dxlog_file,
|
|
659
|
-
L:
|
|
698
|
+
L: 925,
|
|
660
699
|
S: void 0
|
|
661
700
|
});
|
|
662
701
|
if (changed) {
|
|
@@ -668,14 +707,14 @@ var addNode = (graph, nodeArg) => {
|
|
|
668
707
|
}, {
|
|
669
708
|
"~LogMeta": "~LogMeta",
|
|
670
709
|
F: __dxlog_file,
|
|
671
|
-
L:
|
|
710
|
+
L: 934,
|
|
672
711
|
S: void 0
|
|
673
712
|
});
|
|
674
713
|
const newNode = Option.some({
|
|
675
714
|
...existing,
|
|
676
715
|
...rest,
|
|
677
716
|
type,
|
|
678
|
-
data,
|
|
717
|
+
data: nextData,
|
|
679
718
|
properties: {
|
|
680
719
|
...existing.properties,
|
|
681
720
|
...properties
|
|
@@ -697,13 +736,13 @@ var addNode = (graph, nodeArg) => {
|
|
|
697
736
|
}, {
|
|
698
737
|
"~LogMeta": "~LogMeta",
|
|
699
738
|
F: __dxlog_file,
|
|
700
|
-
L:
|
|
739
|
+
L: 950,
|
|
701
740
|
S: void 0
|
|
702
741
|
});
|
|
703
742
|
const newNode = internal._constructNode({
|
|
704
743
|
id,
|
|
705
744
|
type,
|
|
706
|
-
data,
|
|
745
|
+
data: stableData(internal, id, type, void 0, data),
|
|
707
746
|
properties,
|
|
708
747
|
...rest
|
|
709
748
|
});
|
|
@@ -761,6 +800,10 @@ var removeNode = (graph, id, edges = false) => {
|
|
|
761
800
|
id,
|
|
762
801
|
node: Option.none()
|
|
763
802
|
});
|
|
803
|
+
for (const key of internal._expanded) if (primaryParts(key)[0] === id) {
|
|
804
|
+
internal._expanded.delete(key);
|
|
805
|
+
internal._pendingExpands.add(key);
|
|
806
|
+
}
|
|
764
807
|
if (edges) {
|
|
765
808
|
const nodeEdges = internal._currentEdges(id);
|
|
766
809
|
const edgesToRemove = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-AppGraph.mjs","names":["relation","Node.child","Node.relation","Node.relation","relation","Node.action","Node.RootType"],"sources":["../../src/util.ts","../../src/AppGraph.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Atom from 'effect/reactivity/Atom';\n\nimport { shallowEqual } from '@dxos/util';\n\nimport * as Node from './AppGraphNode.ts';\n\n/**\n * `Atom.withLabel` captures and formats a stack trace on every call, and the graph labels an atom per node,\n * per connection key, and per extension, so one expansion costs hundreds of captures on the main thread —\n * hence opt-in, and only under the dev server.\n */\nconst ATOM_LABELS = Boolean(import.meta.env?.DEV) && import.meta.env?.VITE_ATOM_LABELS === 'true';\n\n/** {@link Atom.withLabel}, reduced to a pass-through wherever labels are not collected. */\nexport const withLabel: (name: string) => <A extends Atom.Atom<any>>(self: A) => A = ATOM_LABELS\n ? Atom.withLabel\n : () => (self) => self;\n\n// PRIMARY separates top-level components (e.g., node ID from relation) in compound string keys used within the app-graph package.\nconst PRIMARY = '\\u0001';\n\n// SECONDARY separates sub-components within an encoded value (e.g., relation kind from direction) in the same context.\nconst SECONDARY = '\\u0002';\n\n/** Join parts with the primary separator. */\nexport const primaryKey = (...parts: string[]): string => parts.join(PRIMARY);\n\n/** Split a key on the primary separator. */\nexport const primaryParts = (key: string): string[] => key.split(PRIMARY);\n\n/** Join parts with the secondary separator. */\nexport const secondaryKey = (...parts: string[]): string => parts.join(SECONDARY);\n\n/** Split a key on the secondary separator. */\nexport const secondaryParts = (key: string): string[] => key.split(SECONDARY);\n\n/**\n * Normalize a relation input to a full Relation object.\n */\nexport const normalizeRelation = (relation?: Node.RelationInput): Node.Relation =>\n relation == null ? Node.child : typeof relation === 'string' ? Node.relation(relation) : relation;\n\n/**\n * Returns true if two NodeArg arrays are semantically identical (same id, type, data, properties per index).\n * Inline child nodes (the `nodes` field) are compared recursively.\n */\nexport const nodeArgsUnchanged = (prev: readonly Node.NodeArg<any>[], next: readonly Node.NodeArg<any>[]): boolean => {\n if (prev.length !== next.length) {\n return false;\n }\n\n return prev.every((prevNode, idx) => {\n const nextNode = next[idx];\n return (\n prevNode.id === nextNode.id &&\n prevNode.type === nextNode.type &&\n shallowEqual(prevNode.data, nextNode.data) &&\n shallowEqual(prevNode.properties, nextNode.properties) &&\n nodeArgsUnchanged(prevNode.nodes ?? [], nextNode.nodes ?? []) &&\n nodeArgsUnchanged(prevNode.actions ?? [], nextNode.actions ?? [])\n );\n });\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Pipeable from 'effect/Pipeable';\nimport * as Atom from 'effect/reactivity/Atom';\nimport * as Registry from 'effect/reactivity/AtomRegistry';\n\nimport { type CleanupFn, Event, Trigger } from '@dxos/async';\nimport { todo } from '@dxos/debug';\nimport * as AtomEx from '@dxos/effect/AtomEx';\nimport * as GraphModel from '@dxos/graph/GraphModel';\nimport * as GraphNode from '@dxos/graph/GraphNode';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { type MakeOptional, shallowEqual } from '@dxos/util';\n\nimport { scheduleTask } from '#scheduler';\n\nimport * as Node from './AppGraphNode.ts';\nimport { normalizeRelation, primaryKey, primaryParts, secondaryKey, secondaryParts, withLabel } from './util.ts';\n\n//\n// The app graph: the vocabulary, the store that holds it, and the operations over it. One module\n// because the store stamps the brand symbols at class-definition time and the operations reach into\n// the store — split across files those are mutually recursive imports, and the class body runs\n// against an uninitialized binding.\n//\n\n//\n// Vocabulary.\n//\n\n/**\n * Identifier denoting a Graph.\n */\nexport const GraphTypeId: unique symbol = Symbol.for('@dxos/app-graph/Graph');\nexport type GraphTypeId = typeof GraphTypeId;\n\n/**\n * Identifier for the graph kind discriminator.\n */\nexport const GraphKind: unique symbol = Symbol.for('@dxos/app-graph/GraphKind');\nexport type GraphKind = typeof GraphKind;\n\nexport type GraphTraversalOptions = {\n /**\n * A callback which is called for each node visited during traversal.\n *\n * If the callback returns `false`, traversal is stops recursing.\n */\n visitor: (node: Node.Node, path: string[]) => boolean | void;\n\n /**\n * The node to start traversing from.\n *\n * @default ROOT_ID\n */\n source?: string;\n\n /** The relation(s) to traverse graph edges. */\n relation: Node.RelationInput | Node.RelationInput[];\n};\n\nexport type GraphProps = {\n registry?: Registry.AtomRegistry;\n nodes?: MakeOptional<Node.Node, 'data' | 'cacheable'>[];\n edges?: Record<string, Edges>;\n onExpand?: (id: string, relation: Node.Relation) => void;\n onRemoveNode?: (id: string) => void;\n};\n\nexport type Edge = { source: string; target: string; relation: Node.RelationInput };\nexport type Edges = Record<string, string[]>;\n\nexport type GraphKindType = 'readable' | 'expandable' | 'writable';\n\n/**\n * While the graph is retained, a node's atom stays mounted as long as the node is in it. The other accessors are views that a\n * bare `registry.subscribe` never computes, so it never fires: pass `{ immediate: true }`.\n */\nexport interface BaseGraph extends Pipeable.Pipeable {\n readonly [GraphTypeId]: GraphTypeId;\n readonly [GraphKind]: GraphKindType;\n /**\n * Event emitted when a node is changed.\n */\n readonly onNodeChanged: Event<{ id: string; node: Option.Option<Node.Node> }>;\n /**\n * Get the atom key for the JSON representation of the graph.\n */\n json(id?: string): Atom.Atom<any>;\n /**\n * Get the atom key for the node with the given id.\n */\n node(id: string): Atom.Atom<Option.Option<Node.Node>>;\n /**\n * Get the atom key for the connections of the node with the given id.\n */\n connections(id: string, relation: Node.RelationInput): Atom.Atom<Node.Node[]>;\n /**\n * Get the atom key for the actions of the node with the given id.\n */\n actions(id: string): Atom.Atom<(Node.Action | Node.ActionGroup)[]>;\n /**\n * Get the atom key for the edges of the node with the given id.\n */\n edges(id: string): Atom.Atom<Edges>;\n /**\n * Upsert a node directly, bypassing expansion.\n * @internal\n */\n _setNode(id: string, node: Option.Option<Node.Node>): void;\n /**\n * Materialize a node argument into a node without adding it to the graph.\n * @internal\n */\n _constructNode(node: Node.NodeArg<any>): Option.Option<Node.Node>;\n}\n\nexport type ReadableGraph = BaseGraph & { readonly [GraphKind]: 'readable' | 'expandable' | 'writable' };\nexport type ExpandableGraph = BaseGraph & { readonly [GraphKind]: 'expandable' | 'writable' };\nexport type WritableGraph = BaseGraph & { readonly [GraphKind]: 'writable' };\n\n/**\n * Graph interface.\n */\nexport type Graph = WritableGraph;\n\n//\n// The store: the model handle, the derived atom families and the expansion bookkeeping.\n//\n\nconst graphSymbol = Symbol('graph');\n\ntype DeepWriteable<T> = {\n -readonly [K in keyof T]: T[K] extends object ? DeepWriteable<T[K]> : T[K];\n};\n\ntype NodeInternal = DeepWriteable<Node.Node> & { [graphSymbol]: GraphImpl };\n\n//\n// Utilities\n//\n\nexport const relationKey = (relation: Node.RelationInput): string => {\n const normalized = normalizeRelation(relation);\n return secondaryKey(normalized.kind, normalized.direction);\n};\n\nexport const relationFromKey = (encoded: string): Node.Relation => {\n const parts = secondaryParts(encoded);\n invariant(parts.length === 2 && parts[0].length > 0 && parts[1].length > 0, `Invalid relation key: ${encoded}`);\n const [kind, directionRaw] = parts;\n invariant(directionRaw === 'outbound' || directionRaw === 'inbound', `Invalid relation direction: ${directionRaw}`);\n return Node.relation(kind, directionRaw);\n};\n\nexport const connectionKey = (id: string, relation: Node.RelationInput): string =>\n primaryKey(id, relationKey(relation));\n\nconst relationFromConnectionKey = (key: string): { id: string; relation: Node.Relation } => {\n const [id, encodedRelation] = primaryParts(key);\n invariant(id && encodedRelation, `Invalid connection key: ${key}`);\n return { id, relation: relationFromKey(encodedRelation) };\n};\n\nexport const inverseRelation = (relation: Node.RelationInput): Node.Relation => {\n const normalized = normalizeRelation(relation);\n return Node.relation(normalized.kind, normalized.direction === 'outbound' ? 'inbound' : 'outbound');\n};\n\n/** Node payload; `data` is undefined for a placeholder the graph has not been given yet. */\ntype ModelNode = { id: string; data?: Node.Node };\n\n/** Relation lives in `type`; `order` carries the caller's sort position. */\ntype GraphEdge = { id: string; type: string; source: string; target: string };\n\n/**\n * Every edge is held in its outbound form, so an inbound relation is the same edge read backwards.\n * Without this a relation would have two storage encodings and reads would have to try both.\n */\nconst storedEdge = (source: string, target: string, relation: string): GraphEdge => {\n const { kind, direction } = relationFromKey(relation);\n const outbound = relationKey(Node.relation(kind, 'outbound'));\n const [from, to] = direction === 'inbound' ? [target, source] : [source, target];\n return { id: primaryKey(from, secondaryKey(outbound, to)), type: outbound, source: from, target: to };\n};\n\nconst inverseKey = (relation: string): string => relationKey(inverseRelation(relationFromKey(relation)));\n\nconst edgesEqual = (a: Edges, b: Edges): boolean => {\n const keys = Object.keys(a);\n return (\n keys.length === Object.keys(b).length &&\n keys.every((key) => {\n const left = a[key];\n const right = b[key];\n return right !== undefined && left.length === right.length && left.every((id, index) => id === right[index]);\n })\n );\n};\n\n/**\n * Get the Graph a Node is currently associated with.\n */\nexport const getGraph = (node: Node.Node): Graph => {\n const graph = (node as NodeInternal)[graphSymbol];\n invariant(graph, 'Node is not associated with a graph.');\n return graph as Graph;\n};\n\n/**\n * The Graph represents the user interface information architecture of the application constructed via plugins.\n * @internal\n */\nexport class GraphImpl implements WritableGraph {\n readonly [GraphTypeId]: GraphTypeId = GraphTypeId;\n readonly [GraphKind] = 'writable' as const;\n\n pipe() {\n // eslint-disable-next-line prefer-rest-params\n return Pipeable.pipeArguments(this, arguments);\n }\n\n readonly onNodeChanged = new Event<{\n id: string;\n node: Option.Option<Node.Node>;\n }>();\n\n readonly _onExpand?: GraphProps['onExpand'];\n readonly _onRemoveNode?: GraphProps['onRemoveNode'];\n\n readonly _registry: Registry.AtomRegistry;\n\n /**\n * One mount per node while the graph is retained, so a node's atom keeps one identity and its\n * dependents stay wired. Undefined while nothing retains the graph; see {@link retain}.\n * @internal\n */\n _pins?: Map<string, CleanupFn>;\n readonly _expanded = new Set<string>();\n /** Relation keys a node has held, so an emptied relation still reports an empty list. */\n readonly _relations = new Map<string, Set<string>>();\n readonly _pendingExpands = new Set<string>();\n\n /**\n * Canonical store. Nodes an edge references before they are contributed sit in it as\n * placeholders, and a removed node leaves one behind, so arrival order is free.\n */\n readonly _model: GraphModel.GraphModel<ModelNode, GraphEdge>;\n\n /** @internal */\n readonly _node = Atom.family<string, Atom.Atom<Option.Option<Node.Node>>>((id) => {\n return Atom.make((get) => Option.fromUndefinedOr(get(this._model.nodeAtom(id))?.data)).pipe(\n // Cut off on the payload: `Option.some` allocates a fresh wrapper on every recompute, so\n // without this a version bump notifies subscribers of nodes it did not touch.\n Atom.withEquality(\n (a: Option.Option<Node.Node>, b: Option.Option<Node.Node>) =>\n Option.getOrUndefined(a) === Option.getOrUndefined(b),\n ),\n withLabel(`graph:node:${id}`),\n );\n });\n\n /**\n * The node as the model holds it right now.\n *\n * A flush applies its writes inside {@link batch}, which bumps the version once at the end, so\n * reading {@link Graph._node} from a write path yields the value from before the batch — and\n * `addNode` merges onto what it reads, so that would silently undo an earlier write in the\n * same flush.\n * @internal\n */\n _currentNode(id: string): Option.Option<Node.Node> {\n return Option.fromUndefinedOr(this._model.findNode(id)?.data);\n }\n\n /** The outgoing and inbound edges as the model holds them right now; see {@link Graph._currentNode}. @internal */\n _currentEdges(id: string): Edges {\n return this._computeEdges(id);\n }\n\n /** {@link Graph._currentEdges}; separate so the `_edges` atom body reads it without indirection. */\n _computeEdges(id: string): Edges {\n const edges: Edges = {};\n for (const relation of this._relations.get(id) ?? []) {\n edges[relation] = [];\n }\n for (const edge of this._model.outgoing(id)) {\n (edges[edge.type] ??= []).push(edge.target);\n }\n for (const edge of this._model.incoming(id)) {\n (edges[inverseKey(edge.type)] ??= []).push(edge.source);\n }\n return edges;\n }\n\n readonly _edges = Atom.family<string, Atom.Atom<Edges>>((id) => {\n return Atom.make((get) => {\n get(this._model.version);\n return this._computeEdges(id);\n }).pipe(Atom.withEquality(edgesEqual), withLabel(`graph:edges:${id}`));\n });\n\n // NOTE: Currently the argument to the family needs to be referentially stable for the atom to be referentially stable.\n // TODO(wittjosiah): Atom feature request, support for something akin to `ComplexMap` to allow for complex arguments.\n readonly _connections = Atom.family<string, Atom.Atom<Node.Node[]>>((key) => {\n const parts = key ? primaryParts(key) : [];\n // An empty id (e.g. `useConnections(graph, undefined, ...)`) yields a key with two parts but no\n // id — treat that as no connections rather than throwing.\n if (parts.length < 2 || !parts[0]) {\n return Atom.make((): Node.Node[] => []);\n }\n\n const { id, relation } = relationFromConnectionKey(key);\n return Atom.make((get) =>\n (get(this._edges(id))[relationKey(relation)] ?? [])\n .map((childId) => get(this._node(childId)))\n .filter(Option.isSome)\n .map((node) => node.value),\n ).pipe(\n // Depend on each child's own atom so a child's change invalidates this view, but cut off on the\n // resolved list: without this a no-op re-add re-allocates the Options and notifies spuriously.\n Atom.withEquality(\n (a: Node.Node[], b: Node.Node[]) => a.length === b.length && a.every((node, index) => node === b[index]),\n ),\n withLabel(`graph:connections:${key}`),\n );\n });\n\n readonly _actions = Atom.family<string, Atom.Atom<(Node.Action | Node.ActionGroup)[]>>((id) => {\n return Atom.make((get) => {\n if (!id) {\n return [];\n }\n return get(this._connections(connectionKey(id, Node.action))) as (Node.Action | Node.ActionGroup)[];\n }).pipe(withLabel(`graph:actions:${id}`));\n });\n\n readonly _json = Atom.family<string, Atom.Atom<any>>((id) => {\n return Atom.make((get) => {\n get(this._model.version);\n return this._model.toTree(\n id,\n (node, children: any[]) => {\n const data = node.data;\n if (!data) {\n return undefined;\n }\n return {\n id: data.id,\n type: data.type,\n ...(data.properties.label ? { label: data.properties.label } : {}),\n ...(children.length ? { nodes: children } : {}),\n };\n },\n relationKey('child'),\n );\n }).pipe(withLabel(`graph:json:${id}`));\n });\n\n constructor({ registry, nodes, edges, onExpand, onRemoveNode }: GraphProps = {}) {\n this._registry = registry ?? AtomEx.makeRegistry();\n this._onExpand = onExpand;\n this._onRemoveNode = onRemoveNode;\n this._model = new GraphModel.GraphModel<ModelNode, GraphEdge>({ registry: this._registry });\n\n this._model.batch(() => {\n this._setNode(GraphNode.RootId, this._constructNode({ id: GraphNode.RootId, type: Node.RootType, data: null }));\n nodes?.forEach((node) => this._setNode(node.id, this._constructNode(node)));\n Object.entries(edges ?? {}).forEach(([source, relations]) => {\n Object.entries(relations).forEach(([relation, targets]) => {\n targets.forEach((target) => this._setEdge(source, target, relation));\n });\n });\n });\n }\n\n json(id = GraphNode.RootId): Atom.Atom<any> {\n return this._json(id);\n }\n\n node(id: string): Atom.Atom<Option.Option<Node.Node>> {\n return this._node(id);\n }\n\n connections(id: string, relation: Node.RelationInput): Atom.Atom<Node.Node[]> {\n return this._connections(connectionKey(id, relation));\n }\n\n actions(id: string): Atom.Atom<(Node.Action | Node.ActionGroup)[]> {\n return this._actions(id);\n }\n\n edges(id: string): Atom.Atom<Edges> {\n return this._edges(id);\n }\n\n /** @internal */\n _constructNode(node: Node.NodeArg<any>): Option.Option<Node.Node> {\n return Option.some({\n [graphSymbol]: this,\n data: null,\n properties: {},\n ...node,\n });\n }\n\n /**\n * Writes the node payload, materializing a placeholder slot when the id is new.\n * @internal\n */\n _setNode(id: string, node: Option.Option<Node.Node>): void {\n this._model.setNode({ id, data: Option.getOrUndefined(node) });\n // After the write, so the atom is computed with the value rather than with `none`.\n if (this._pins && !this._pins.has(id)) {\n this._pins.set(id, this._registry.mount(this._node(id)));\n }\n }\n\n /** @internal */\n _retain(): CleanupFn {\n invariant(!this._pins, 'Graph is already retained.');\n const pins = new Map<string, CleanupFn>();\n for (const { id } of this._model.nodes) {\n pins.set(id, this._registry.mount(this._node(id)));\n }\n this._pins = pins;\n return () => {\n if (this._pins !== pins) {\n return;\n }\n pins.forEach((unpin) => unpin());\n this._pins = undefined;\n };\n }\n\n /** @internal */\n _setEdge(source: string, target: string, relation: string): void {\n this._trackRelation(source, relation);\n this._trackRelation(target, inverseKey(relation));\n const stored = storedEdge(source, target, relation);\n if (this._model.findEdge(stored.id)) {\n return;\n }\n\n this._model.addEdge(stored);\n }\n\n /** @internal */\n _removeEdge(source: string, target: string, relation: string): void {\n // `detachEdge`, not `removeEdge`: the latter hands back the removed edge as a graph, and nothing\n // here reads it.\n this._model.detachEdge(storedEdge(source, target, relation).id);\n }\n\n /** @internal */\n _trackRelation(id: string, relation: string): void {\n const relations = this._relations.get(id) ?? new Set<string>();\n relations.add(relation);\n this._relations.set(id, relations);\n }\n}\n\n/**\n * The implementation behind a graph handle. Exported for this package's tests, which assert against\n * the model and expansion bookkeeping; not part of the public surface.\n * @internal\n */\nexport const getInternal = (graph: BaseGraph): GraphImpl => {\n return graph as unknown as GraphImpl;\n};\n\n/**\n * Creates a new Graph instance.\n */\nexport const make = (params?: GraphProps): Graph => {\n return new GraphImpl(params);\n};\n\n/**\n * Pins the graph's nodes in its registry, including nodes added later, until the returned function\n * is called. A graph has one holder at a time.\n */\nexport const retain = (graph: BaseGraph): CleanupFn => getInternal(graph)._retain();\n\n/**\n * Convert the graph to a JSON object.\n */\nexport const toJSON = (graph: BaseGraph, id = GraphNode.RootId): object => {\n const internal = getInternal(graph);\n return internal._registry.get(internal._json(id));\n};\n\n/**\n * Get the node with the given id from the graph's registry.\n */\nexport const getNode = (graph: BaseGraph, id: string): Option.Option<Node.Node> => {\n const internal = getInternal(graph);\n return internal._registry.get(internal._node(id));\n};\n\n/**\n * Get the node with the given id from the graph's registry.\n *\n * @throws {GraphNode.NotFoundError} If the graph has no node with the id.\n */\nexport const getNodeOrThrow = (graph: BaseGraph, id: string): Node.Node => {\n const internal = getInternal(graph);\n return Option.getOrThrowWith(internal._registry.get(internal._node(id)), () => new GraphNode.NotFoundError(id));\n};\n\n/**\n * Get the root node of the graph.\n * This is an alias for `getNodeOrThrow(graph, ROOT_ID)`.\n */\nexport function getRoot(graph: BaseGraph): Node.Node {\n return getNodeOrThrow(graph, GraphNode.RootId);\n}\n\n/**\n * Get all nodes connected to the node with the given id by the given relation from the graph's registry.\n */\nexport const getConnections = (graph: BaseGraph, id: string, relation: Node.RelationInput): Node.Node[] => {\n const internal = getInternal(graph);\n return internal._registry.get(internal._connections(connectionKey(id, relation)));\n};\n\n/**\n * Get all actions connected to the node with the given id from the graph's registry.\n */\nexport const getActions = (graph: BaseGraph, id: string): Node.Node[] => {\n const internal = getInternal(graph);\n return internal._registry.get(internal._actions(id));\n};\n\n/**\n * Get the edges from the node with the given id from the graph's registry.\n */\nexport const getEdges = (graph: BaseGraph, id: string): Edges => {\n const internal = getInternal(graph);\n return internal._registry.get(internal._edges(id));\n};\n\n/**\n * Recursive depth-first traversal of the graph.\n */\nexport const traverse = (graph: BaseGraph, options: GraphTraversalOptions, path: string[] = []): void => {\n const { visitor, source = GraphNode.RootId, relation } = options;\n // Break cycles.\n if (path.includes(source)) {\n return;\n }\n\n const node = getNodeOrThrow(graph, source);\n const shouldContinue = visitor(node, [...path, source]);\n if (shouldContinue === false) {\n return;\n }\n\n const relations = Array.isArray(relation) ? relation : [relation];\n const seen = new Set<string>();\n for (const rel of relations) {\n for (const connected of getConnections(graph, source, rel)) {\n if (!seen.has(connected.id)) {\n seen.add(connected.id);\n traverse(graph, { source: connected.id, relation, visitor }, [...path, source]);\n }\n }\n }\n};\n\n/**\n * Get the path between two nodes in the graph.\n */\nexport const getPath = (graph: BaseGraph, params: { source?: string; target: string }): Option.Option<string[]> => {\n return Function.pipe(\n getNode(graph, params.source ?? 'root'),\n Option.flatMap((node) => {\n let found: Option.Option<string[]> = Option.none();\n traverse(graph, {\n source: node.id,\n relation: 'child',\n visitor: (node, path) => {\n if (Option.isSome(found)) {\n return false;\n }\n\n if (node.id === params.target) {\n found = Option.some(path);\n }\n },\n });\n\n return found;\n }),\n );\n};\n\n/**\n * Wait for the path between two nodes in the graph to be established.\n */\nexport const waitForPath = (\n graph: BaseGraph,\n params: { source?: string; target: string },\n options?: { timeout?: number; interval?: number },\n): Promise<string[]> => {\n const { timeout = 5_000, interval = 500 } = options ?? {};\n const path = getPath(graph, params);\n if (Option.isSome(path)) {\n return Promise.resolve(path.value);\n }\n\n const trigger = new Trigger<string[]>();\n const i = setInterval(() => {\n const path = getPath(graph, params);\n if (Option.isSome(path)) {\n trigger.wake(path.value);\n }\n }, interval);\n\n return trigger.wait({ timeout }).finally(() => clearInterval(i));\n};\n\n/**\n * Resolves when the node exists in the graph; immediately if it already does.\n *\n * The graph is populated asynchronously — connectors expand a level at a time and the objects\n * behind them load out of band — and {@link expandSync} is fire-and-forget, so a consumer that needs\n * a specific node has no completion to await and would otherwise poll for it.\n *\n * Deliberately unbounded: whether a node is merely late or will never arrive is the caller's\n * question, so the deadline belongs at the call site (`Effect.timeout`). Interrupting is safe —\n * the subscription is released on interruption.\n */\nexport const waitFor = (graph: BaseGraph, id: string): Effect.Effect<Node.Node> =>\n Effect.suspend(() => {\n const current = getNode(graph, id);\n if (Option.isSome(current)) {\n return Effect.succeed(current.value);\n }\n\n return Effect.callback<Node.Node>((resume) => {\n const unsubscribe = graph.onNodeChanged.on(({ id: changed, node }) => {\n if (changed === id && Option.isSome(node)) {\n unsubscribe();\n resume(Effect.succeed(node.value));\n }\n });\n\n // Re-read after subscribing: a node added between the read above and the subscription\n // emits nothing further, and the wait would hang on an event that already happened.\n const raced = getNode(graph, id);\n if (Option.isSome(raced)) {\n unsubscribe();\n resume(Effect.succeed(raced.value));\n }\n\n return Effect.sync(() => unsubscribe());\n });\n });\n\n/**\n * Implementation helper for expandSync.\n * If the node does not exist yet, the expand is recorded as pending and applied when the node is added.\n *\n * Fires the `onExpand` callback to add connections to the node. The builder only marks the relation's\n * connectors dirty; they run, and their output reaches the graph, on its next flush.\n *\n * Expanding a node that is already expanded for the same relation is a no-op.\n */\nexport const expandSync = <T extends ExpandableGraph | WritableGraph>(\n graph: T,\n id: string,\n relation: Node.RelationInput,\n): T => {\n const internal = getInternal(graph);\n const normalizedRelation = normalizeRelation(relation);\n const key = primaryKey(id, relationKey(normalizedRelation));\n const nodeOpt = internal._currentNode(id);\n if (Option.isNone(nodeOpt)) {\n // Node not yet in graph: record expand to run when the node is added.\n internal._pendingExpands.add(key);\n log('expand', { key, deferred: true });\n return graph;\n }\n\n const expanded = internal._expanded.has(key);\n log('expand', { key, expanded });\n if (!expanded) {\n internal._expanded.add(key);\n internal._onExpand?.(id, normalizedRelation);\n }\n return graph;\n};\n\n/**\n * {@link expandSync} the `child` relation of every ancestor of a qualified id, and of the id itself.\n * A missing ancestor's expand is deferred until it arrives, so a single call populates the whole path.\n */\nexport const expandPath = <T extends ExpandableGraph | WritableGraph>(graph: T, qualifiedId: string): T => {\n const segments = qualifiedId.split('/');\n for (let index = 1; index <= segments.length; index++) {\n expandSync(graph, segments.slice(0, index).join('/'), 'child');\n }\n return graph;\n};\n\n/**\n * Expand a node in the graph, off the paint-critical path.\n *\n * Yields to the main thread before running {@link expandSync}, so a caller reacting to input does not\n * block the frame. Interrupting the effect cancels a still-pending expansion, which makes rescheduling\n * (e.g. superseding a hover with the next one) a matter of interrupting the previous fiber.\n */\nexport const expand = <T extends ExpandableGraph | WritableGraph>(\n graph: T,\n id: string,\n relation: Node.RelationInput,\n): Effect.Effect<void> =>\n Effect.promise((signal) =>\n scheduleTask(\n () => {\n expandSync(graph, id, relation);\n },\n { strategy: 'idle', signal },\n ),\n );\n\n/**\n * Sort the edges of the node with the given id.\n */\nexport const sortEdges = <T extends ExpandableGraph | WritableGraph>(\n graph: T,\n id: string,\n relation: Node.RelationInput,\n order: string[],\n): T => {\n const internal = getInternal(graph);\n const edges = internal._currentEdges(id);\n const relationId = relationKey(relation);\n const current = edges[relationId] ?? [];\n // Set membership, not `includes`: both filters run over the whole relation, and a connector\n // sorting its output makes an array scan here quadratic in the number of siblings.\n const ordered = new Set(order);\n const existing = new Set(current);\n const unsorted = current.filter((id) => !ordered.has(id));\n const sorted = order.filter((id) => existing.has(id));\n const newOrder = [...sorted, ...unsorted];\n if (newOrder.length === current.length && newOrder.every((id, i) => id === current[i])) {\n return graph;\n }\n // Insertion order carries the sort, so reordering means re-adding the relation's edges.\n internal._model.batch(() => {\n current.forEach((target) => internal._removeEdge(id, target, relationId));\n newOrder.forEach((target) => internal._setEdge(id, target, relationId));\n });\n return graph;\n};\n\n/**\n * Applies `fn`'s writes as a single observable change: the model bumps its version once, so derived\n * views recompute and notify once for the whole group.\n */\nexport const batch = <T extends WritableGraph, A>(graph: T, fn: () => A): A => getInternal(graph)._model.batch(fn);\n\n/**\n * Unloads the nodes: they leave the model outright, along with the expansion bookkeeping that would\n * otherwise keep the graph remembering ids it will never be asked about again.\n *\n * Unlike {@link removeNodes} this leaves no tombstone, so a subsequent read of a released relation\n * expands it afresh rather than resolving to an emptied node.\n */\nexport const release = <T extends WritableGraph>(graph: T, ids: readonly string[]): T => {\n const internal = getInternal(graph);\n internal._model.batch(() => {\n for (const id of ids) {\n internal._pins?.get(id)?.();\n internal._pins?.delete(id);\n internal._relations.delete(id);\n }\n\n releaseExpansions(internal, new Set(ids));\n internal._model.release(ids);\n });\n\n return graph;\n};\n\nconst releaseExpansions = (internal: GraphImpl, ids: ReadonlySet<string>): void => {\n for (const set of [internal._expanded, internal._pendingExpands]) {\n for (const key of set) {\n if (ids.has(primaryParts(key)[0])) {\n set.delete(key);\n }\n }\n }\n};\n\n/**\n * Forgets that `relation` of `id` was expanded. Paired with the builder tearing down the matching\n * connector subscription, so a relation whose contents were released re-expands rather than\n * resolving to the emptied list it had before.\n */\nexport const releaseRelation = <T extends ExpandableGraph | WritableGraph>(\n graph: T,\n id: string,\n relation: string,\n): T => {\n const internal = getInternal(graph);\n const key = primaryKey(id, relation);\n internal._expanded.delete(key);\n internal._pendingExpands.delete(key);\n return graph;\n};\n\n/**\n * Add nodes to the graph.\n */\nexport const addNodes = <T extends WritableGraph>(graph: T, nodes: Node.NodeArg<any, Record<string, any>>[]): T => {\n // The model's own depth counter, not `Atom.batch`: these calls nest (a node applies its inline\n // children and edges), and a nested `Atom.batch` leaves the registry in its collect phase after\n // the inner call returns, so invalidations raised afterwards are gathered and then discarded\n // without ever being rebuilt. The version atom still bumps once for the whole group.\n getInternal(graph)._model.batch(() => {\n nodes.map((node) => addNode(graph, node));\n });\n return graph;\n};\n\n/**\n * Add a node to the graph.\n */\nexport const addNode = <T extends WritableGraph>(graph: T, nodeArg: Node.NodeArg<any, Record<string, any>>): T => {\n const internal = getInternal(graph);\n // Extract known NodeArg fields, preserve any extra fields (like _actionContext) in rest.\n const {\n nodes,\n actions,\n edges,\n id,\n type,\n data = null,\n properties = {},\n ...rest\n } = nodeArg as Node.NodeArg<any> & {\n _actionContext?: Node.ActionContext;\n };\n const existingNode = internal._currentNode(id);\n Option.match(existingNode, {\n onSome: (existing) => {\n const typeChanged = existing.type !== type;\n const dataChanged = !shallowEqual(existing.data, data);\n const propertiesChanged = Object.keys(properties).some((key) => existing.properties[key] !== properties[key]);\n // `changed` is on the visit log because counting `existing node` lines alone measures how often a\n // node was re-offered, not how often it actually changed — two very different costs.\n const changed = typeChanged || dataChanged || propertiesChanged;\n log('existing node', {\n id,\n changed,\n typeChanged,\n dataChanged,\n propertiesChanged,\n });\n if (changed) {\n log('updating node', { id, type, data, properties });\n const newNode = Option.some({\n ...existing,\n ...rest,\n type,\n data,\n // Merged, not replaced, so several extensions can each contribute properties to one node —\n // which makes a key one generation sets and the next omits impossible to clear. A builder\n // that varies a property must emit it on every generation, `false`/`undefined` included.\n properties: { ...existing.properties, ...properties },\n });\n internal._setNode(id, newNode);\n graph.onNodeChanged.emit({ id, node: newNode });\n }\n },\n onNone: () => {\n log('new node', { id, type, data, properties });\n const newNode = internal._constructNode({ id, type, data, properties, ...rest });\n internal._setNode(id, newNode);\n graph.onNodeChanged.emit({ id, node: newNode });\n\n // Apply any expands that were deferred because this node did not exist yet.\n const toApply = [...internal._pendingExpands].filter((k) => primaryParts(k)[0] === id);\n for (const pendingKey of toApply) {\n internal._pendingExpands.delete(pendingKey);\n const relation = relationFromKey(primaryParts(pendingKey)[1]);\n internal._expanded.add(pendingKey);\n internal._onExpand?.(id, relation);\n }\n },\n });\n\n if (nodes) {\n addNodes(graph, nodes);\n const _edges = nodes.map((node) => ({ source: id, target: node.id, relation: 'child' as const }));\n addEdges(graph, _edges);\n sortEdges(\n graph,\n id,\n 'child',\n nodes.map((n) => n.id),\n );\n }\n\n if (actions) {\n addNodes(graph, actions);\n const _edges = actions.map((node) => ({ source: id, target: node.id, relation: Node.action }));\n addEdges(graph, _edges);\n sortEdges(\n graph,\n id,\n Node.action,\n actions.map((node) => node.id),\n );\n }\n\n if (edges) {\n todo();\n }\n return graph;\n};\n\n/**\n * Remove nodes from the graph.\n */\nexport const removeNodes = <T extends WritableGraph>(graph: T, ids: string[], edges = false): T => {\n getInternal(graph)._model.batch(() => {\n ids.map((id) => removeNode(graph, id, edges));\n });\n return graph;\n};\n\n/**\n * Remove a node from the graph.\n */\nexport const removeNode = <T extends WritableGraph>(graph: T, id: string, edges = false): T => {\n const internal = getInternal(graph);\n internal._setNode(id, Option.none());\n graph.onNodeChanged.emit({ id, node: Option.none() });\n // TODO(wittjosiah): Reset expanded and initialized flags?\n\n if (edges) {\n const nodeEdges = internal._currentEdges(id);\n const edgesToRemove: Edge[] = [];\n for (const [relationKeyValue, relatedIds] of Object.entries(nodeEdges)) {\n const relation = relationFromKey(relationKeyValue);\n const isInboundRelation = relation.direction === 'inbound';\n for (const relatedId of relatedIds) {\n if (isInboundRelation) {\n // Inbound edge lists store source node IDs; reconstruct the canonical outbound edge.\n edgesToRemove.push({ source: relatedId, target: id, relation: inverseRelation(relation) });\n } else {\n edgesToRemove.push({ source: id, target: relatedId, relation });\n }\n }\n }\n removeEdges(graph, edgesToRemove);\n }\n\n internal._onRemoveNode?.(id);\n return graph;\n};\n\n/**\n * Add edges to the graph.\n */\nexport const addEdges = <T extends WritableGraph>(graph: T, edges: Edge[]): T => {\n getInternal(graph)._model.batch(() => {\n edges.map((edge) => addEdge(graph, edge));\n });\n return graph;\n};\n\n/**\n * Add an edge to the graph.\n */\nexport const addEdge = <T extends WritableGraph>(graph: T, edgeArg: Edge): T => {\n const relationId = relationKey(normalizeRelation(edgeArg.relation));\n const internal = getInternal(graph);\n // Deduping is `_setEdge`'s job and it does it by edge id in O(1); the membership check that used\n // to guard this built the source's whole edge record per edge, which is quadratic on a wide fan-out.\n // No log line here — it runs per edge of every flush, and building the entry costs more than the write.\n internal._setEdge(edgeArg.source, edgeArg.target, relationId);\n return graph;\n};\n\n/**\n * Remove edges from the graph.\n */\nexport const removeEdges = <T extends WritableGraph>(graph: T, edges: Edge[], removeOrphans = false): T => {\n getInternal(graph)._model.batch(() => {\n edges.map((edge) => removeEdge(graph, edge, removeOrphans));\n });\n return graph;\n};\n\n/**\n * Remove an edge from the graph.\n */\nexport const removeEdge = <T extends WritableGraph>(graph: T, edgeArg: Edge, removeOrphans = false): T => {\n const relation = normalizeRelation(edgeArg.relation);\n const relationId = relationKey(relation);\n const inverse = inverseRelation(relation);\n const inverseId = relationKey(inverse);\n const internal = getInternal(graph);\n\n internal._removeEdge(edgeArg.source, edgeArg.target, relationId);\n\n if (removeOrphans) {\n // Asked of the model directly rather than through `_edges`, whose adjacency read rebuilds an\n // O(E) index on every version bump — quadratic when a connector drops all of its nodes at once.\n for (const endpoint of [edgeArg.source, edgeArg.target]) {\n if (endpoint !== GraphNode.RootId && !internal._model.hasEdges(endpoint)) {\n removeNodes(graph, [endpoint]);\n }\n }\n }\n return graph;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,IAAa,mBAEF,SAAS;AAGpB,IAAM,UAAU;AAGhB,IAAM,YAAY;;AAGlB,IAAa,cAAc,GAAG,UAA4B,MAAM,KAAK,OAAO;;AAG5E,IAAa,gBAAgB,QAA0B,IAAI,MAAM,OAAO;;AAGxE,IAAa,gBAAgB,GAAG,UAA4B,MAAM,KAAK,SAAS;;AAGhF,IAAa,kBAAkB,QAA0B,IAAI,MAAM,SAAS;;;;AAK5E,IAAa,qBAAqB,eAChCA,cAAY,OAAOC,QAAa,OAAOD,eAAa,WAAWE,SAAcF,UAAQ,IAAIA;;;;;AAM3F,IAAa,qBAAqB,MAAoC,SAAgD;CACpH,IAAI,KAAK,WAAW,KAAK,QACvB,OAAO;CAGT,OAAO,KAAK,OAAO,UAAU,QAAQ;EACnC,MAAM,WAAW,KAAK;EACtB,OACE,SAAS,OAAO,SAAS,MACzB,SAAS,SAAS,SAAS,QAC3B,aAAa,SAAS,MAAM,SAAS,IAAI,KACzC,aAAa,SAAS,YAAY,SAAS,UAAU,KACrD,kBAAkB,SAAS,SAAS,CAAC,GAAG,SAAS,SAAS,CAAC,CAAC,KAC5D,kBAAkB,SAAS,WAAW,CAAC,GAAG,SAAS,WAAW,CAAC,CAAC;CAEpE,CAAC;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC3BA,IAAa,cAA6B,OAAO,IAAI,uBAAuB;;;;AAM5E,IAAa,YAA2B,OAAO,IAAI,2BAA2B;AA2F9E,IAAM,cAAc,OAAO,OAAO;AAYlC,IAAa,eAAe,aAAyC;CACnE,MAAM,aAAa,kBAAkB,Q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Aa,YAAY,QAAQ;CAErB,YADF,gBAAgB,QACF,CAAO;CACrC,MAAM,WAAW,YAAY,KAAK;CAElC,SAAS,YAAY,QAAQ,QAAQ,QAAQ,QAAQ,UAAU;CAE/D,IAAI,eAGG;OAAA,MAAM,YAAY,CAAC,QAAQ,QAAQ,QAAQ,MAAM,GACpD,IAAI,aAAa,UAAU,UAAU,CAAC,SAAS,OAAO,SAAS,QAAQ,GACrE,YAAY,OAAO,CAAC,QAAQ,CAAC;CAAA;CAInC,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"chunk-AppGraph.mjs","names":["relation","Node.child","Node.relation","Node.relation","relation","Node.action","Node.RootType","Node.isAction"],"sources":["../../src/util.ts","../../src/AppGraph.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Equal from 'effect/Equal';\nimport * as Atom from 'effect/reactivity/Atom';\n\nimport { shallowEqual } from '@dxos/util';\n\nimport * as Node from './AppGraphNode.ts';\n\n/**\n * `Atom.withLabel` captures and formats a stack trace on every call, and the graph labels an atom per node,\n * per connection key, and per extension, so one expansion costs hundreds of captures on the main thread —\n * hence opt-in, and only under the dev server.\n */\nconst ATOM_LABELS = Boolean(import.meta.env?.DEV) && import.meta.env?.VITE_ATOM_LABELS === 'true';\n\n/** {@link Atom.withLabel}, reduced to a pass-through wherever labels are not collected. */\nexport const withLabel: (name: string) => <A extends Atom.Atom<any>>(self: A) => A = ATOM_LABELS\n ? Atom.withLabel\n : () => (self) => self;\n\n// PRIMARY separates top-level components (e.g., node ID from relation) in compound string keys used within the app-graph package.\nconst PRIMARY = '\\u0001';\n\n// SECONDARY separates sub-components within an encoded value (e.g., relation kind from direction) in the same context.\nconst SECONDARY = '\\u0002';\n\n/** Join parts with the primary separator. */\nexport const primaryKey = (...parts: string[]): string => parts.join(PRIMARY);\n\n/** Split a key on the primary separator. */\nexport const primaryParts = (key: string): string[] => key.split(PRIMARY);\n\n/** Join parts with the secondary separator. */\nexport const secondaryKey = (...parts: string[]): string => parts.join(SECONDARY);\n\n/** Split a key on the secondary separator. */\nexport const secondaryParts = (key: string): string[] => key.split(SECONDARY);\n\n/**\n * Normalize a relation input to a full Relation object.\n */\nexport const normalizeRelation = (relation?: Node.RelationInput): Node.Relation =>\n relation == null ? Node.child : typeof relation === 'string' ? Node.relation(relation) : relation;\n\n/**\n * Returns true if two NodeArg arrays are semantically identical (same id, type, data, properties per index).\n * Inline child nodes (the `nodes` field) are compared recursively.\n */\nexport const nodeArgsUnchanged = (prev: readonly Node.NodeArg<any>[], next: readonly Node.NodeArg<any>[]): boolean => {\n if (prev.length !== next.length) {\n return false;\n }\n\n return prev.every((prevNode, idx) => {\n const nextNode = next[idx];\n return (\n prevNode.id === nextNode.id &&\n prevNode.type === nextNode.type &&\n shallowEqual(prevNode.data, nextNode.data) &&\n Equal.equals(prevNode.properties ?? {}, nextNode.properties ?? {}) &&\n nodeArgsUnchanged(prevNode.nodes ?? [], nextNode.nodes ?? []) &&\n nodeArgsUnchanged(prevNode.actions ?? [], nextNode.actions ?? [])\n );\n });\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Equal from 'effect/Equal';\nimport * as Function from 'effect/Function';\nimport * as Hash from 'effect/Hash';\nimport * as Option from 'effect/Option';\nimport * as Pipeable from 'effect/Pipeable';\nimport * as Atom from 'effect/reactivity/Atom';\nimport * as Registry from 'effect/reactivity/AtomRegistry';\n\nimport { type CleanupFn, Event, Trigger } from '@dxos/async';\nimport { todo } from '@dxos/debug';\nimport * as AtomEx from '@dxos/effect/AtomEx';\nimport * as GraphModel from '@dxos/graph/GraphModel';\nimport * as GraphNode from '@dxos/graph/GraphNode';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { type MakeOptional, shallowEqual } from '@dxos/util';\n\nimport { scheduleTask } from '#scheduler';\n\nimport * as Node from './AppGraphNode.ts';\nimport { normalizeRelation, primaryKey, primaryParts, secondaryKey, secondaryParts, withLabel } from './util.ts';\n\n//\n// The app graph: the vocabulary, the store that holds it, and the operations over it. One module\n// because the store stamps the brand symbols at class-definition time and the operations reach into\n// the store — split across files those are mutually recursive imports, and the class body runs\n// against an uninitialized binding.\n//\n\n//\n// Vocabulary.\n//\n\n/**\n * Identifier denoting a Graph.\n */\nexport const GraphTypeId: unique symbol = Symbol.for('@dxos/app-graph/Graph');\nexport type GraphTypeId = typeof GraphTypeId;\n\n/**\n * Identifier for the graph kind discriminator.\n */\nexport const GraphKind: unique symbol = Symbol.for('@dxos/app-graph/GraphKind');\nexport type GraphKind = typeof GraphKind;\n\nexport type GraphTraversalOptions = {\n /**\n * A callback which is called for each node visited during traversal.\n *\n * If the callback returns `false`, traversal is stops recursing.\n */\n visitor: (node: Node.Node, path: string[]) => boolean | void;\n\n /**\n * The node to start traversing from.\n *\n * @default ROOT_ID\n */\n source?: string;\n\n /** The relation(s) to traverse graph edges. */\n relation: Node.RelationInput | Node.RelationInput[];\n};\n\nexport type GraphProps = {\n registry?: Registry.AtomRegistry;\n nodes?: MakeOptional<Node.Node, 'data' | 'cacheable'>[];\n edges?: Record<string, Edges>;\n onExpand?: (id: string, relation: Node.Relation) => void;\n onRemoveNode?: (id: string) => void;\n};\n\nexport type Edge = { source: string; target: string; relation: Node.RelationInput };\nexport type Edges = Record<string, string[]>;\n\nexport type GraphKindType = 'readable' | 'expandable' | 'writable';\n\n/**\n * While the graph is retained, a node's atom stays mounted as long as the node is in it. The other accessors are views that a\n * bare `registry.subscribe` never computes, so it never fires: pass `{ immediate: true }`.\n */\nexport interface BaseGraph extends Pipeable.Pipeable {\n readonly [GraphTypeId]: GraphTypeId;\n readonly [GraphKind]: GraphKindType;\n /**\n * Event emitted when a node is changed.\n */\n readonly onNodeChanged: Event<{ id: string; node: Option.Option<Node.Node> }>;\n /**\n * Get the atom key for the JSON representation of the graph.\n */\n json(id?: string): Atom.Atom<any>;\n /**\n * Get the atom key for the node with the given id.\n */\n node(id: string): Atom.Atom<Option.Option<Node.Node>>;\n /**\n * Get the atom key for the connections of the node with the given id.\n */\n connections(id: string, relation: Node.RelationInput): Atom.Atom<Node.Node[]>;\n /**\n * Get the atom key for the actions of the node with the given id.\n */\n actions(id: string): Atom.Atom<(Node.Action | Node.ActionGroup)[]>;\n /**\n * Get the atom key for the edges of the node with the given id.\n */\n edges(id: string): Atom.Atom<Edges>;\n /**\n * Upsert a node directly, bypassing expansion.\n * @internal\n */\n _setNode(id: string, node: Option.Option<Node.Node>): void;\n /**\n * Materialize a node argument into a node without adding it to the graph.\n * @internal\n */\n _constructNode(node: Node.NodeArg<any>): Option.Option<Node.Node>;\n}\n\nexport type ReadableGraph = BaseGraph & { readonly [GraphKind]: 'readable' | 'expandable' | 'writable' };\nexport type ExpandableGraph = BaseGraph & { readonly [GraphKind]: 'expandable' | 'writable' };\nexport type WritableGraph = BaseGraph & { readonly [GraphKind]: 'writable' };\n\n/**\n * Graph interface.\n */\nexport type Graph = WritableGraph;\n\n//\n// The store: the model handle, the derived atom families and the expansion bookkeeping.\n//\n\nconst graphSymbol = Symbol('graph');\n\ntype DeepWriteable<T> = {\n -readonly [K in keyof T]: T[K] extends object ? DeepWriteable<T[K]> : T[K];\n};\n\ntype NodeInternal = DeepWriteable<Node.Node> & { [graphSymbol]: GraphImpl };\n\n//\n// Utilities\n//\n\nexport const relationKey = (relation: Node.RelationInput): string => {\n const normalized = normalizeRelation(relation);\n return secondaryKey(normalized.kind, normalized.direction);\n};\n\nexport const relationFromKey = (encoded: string): Node.Relation => {\n const parts = secondaryParts(encoded);\n invariant(parts.length === 2 && parts[0].length > 0 && parts[1].length > 0, `Invalid relation key: ${encoded}`);\n const [kind, directionRaw] = parts;\n invariant(directionRaw === 'outbound' || directionRaw === 'inbound', `Invalid relation direction: ${directionRaw}`);\n return Node.relation(kind, directionRaw);\n};\n\nexport const connectionKey = (id: string, relation: Node.RelationInput): string =>\n primaryKey(id, relationKey(relation));\n\nconst relationFromConnectionKey = (key: string): { id: string; relation: Node.Relation } => {\n const [id, encodedRelation] = primaryParts(key);\n invariant(id && encodedRelation, `Invalid connection key: ${key}`);\n return { id, relation: relationFromKey(encodedRelation) };\n};\n\nexport const inverseRelation = (relation: Node.RelationInput): Node.Relation => {\n const normalized = normalizeRelation(relation);\n return Node.relation(normalized.kind, normalized.direction === 'outbound' ? 'inbound' : 'outbound');\n};\n\n/** Node payload; `data` is undefined for a placeholder the graph has not been given yet. */\ntype ModelNode = { id: string; data?: Node.Node };\n\n/** Relation lives in `type`; `order` carries the caller's sort position. */\ntype GraphEdge = { id: string; type: string; source: string; target: string };\n\n/**\n * Every edge is held in its outbound form, so an inbound relation is the same edge read backwards.\n * Without this a relation would have two storage encodings and reads would have to try both.\n */\nconst storedEdge = (source: string, target: string, relation: string): GraphEdge => {\n const { kind, direction } = relationFromKey(relation);\n const outbound = relationKey(Node.relation(kind, 'outbound'));\n const [from, to] = direction === 'inbound' ? [target, source] : [source, target];\n return { id: primaryKey(from, secondaryKey(outbound, to)), type: outbound, source: from, target: to };\n};\n\nconst inverseKey = (relation: string): string => relationKey(inverseRelation(relationFromKey(relation)));\n\nconst edgesEqual = (a: Edges, b: Edges): boolean => {\n const keys = Object.keys(a);\n return (\n keys.length === Object.keys(b).length &&\n keys.every((key) => {\n const left = a[key];\n const right = b[key];\n return right !== undefined && left.length === right.length && left.every((id, index) => id === right[index]);\n })\n );\n};\n\n/**\n * Get the Graph a Node is currently associated with.\n */\nexport const getGraph = (node: Node.Node): Graph => {\n const graph = (node as NodeInternal)[graphSymbol];\n invariant(graph, 'Node is not associated with a graph.');\n return graph as Graph;\n};\n\n/** Carried by each forwarder {@link stableData} makes, so any graph recognizes one without a lookup table. */\nconst ForwardedKey = Symbol('app-graph/forwarded');\n\n/** The closure a forwarder calls, never itself a forwarder, and the graph node it belongs to. */\ntype Forwarded = { target: (...args: unknown[]) => unknown; readonly graph: object; readonly id: string };\n\ntype Forwarder = ((...args: unknown[]) => unknown) & { readonly [ForwardedKey]: Forwarded };\n\nconst isForwarder = (value: unknown): value is Forwarder => typeof value === 'function' && ForwardedKey in value;\n\n/**\n * The Graph represents the user interface information architecture of the application constructed via plugins.\n * @internal\n */\nexport class GraphImpl implements WritableGraph {\n readonly [GraphTypeId]: GraphTypeId = GraphTypeId;\n readonly [GraphKind] = 'writable' as const;\n\n pipe() {\n // eslint-disable-next-line prefer-rest-params\n return Pipeable.pipeArguments(this, arguments);\n }\n\n [Hash.symbol](): number {\n return Hash.random(this);\n }\n\n [Equal.symbol](that: unknown): boolean {\n return this === that;\n }\n\n readonly onNodeChanged = new Event<{\n id: string;\n node: Option.Option<Node.Node>;\n }>();\n\n readonly _onExpand?: GraphProps['onExpand'];\n readonly _onRemoveNode?: GraphProps['onRemoveNode'];\n\n readonly _registry: Registry.AtomRegistry;\n\n /**\n * One mount per node while the graph is retained, so a node's atom keeps one identity and its\n * dependents stay wired. Undefined while nothing retains the graph; see {@link retain}.\n * @internal\n */\n _pins?: Map<string, CleanupFn>;\n readonly _expanded = new Set<string>();\n /** Relation keys a node has held, so an emptied relation still reports an empty list. */\n readonly _relations = new Map<string, Set<string>>();\n readonly _pendingExpands = new Set<string>();\n\n /**\n * Canonical store. Nodes an edge references before they are contributed sit in it as\n * placeholders, and a removed node leaves one behind, so arrival order is free.\n */\n readonly _model: GraphModel.GraphModel<ModelNode, GraphEdge>;\n\n /** @internal */\n readonly _node = Atom.family<string, Atom.Atom<Option.Option<Node.Node>>>((id) => {\n return Atom.make((get) => Option.fromUndefinedOr(get(this._model.nodeAtom(id))?.data)).pipe(\n // Cut off on the payload: `Option.some` allocates a fresh wrapper on every recompute, so\n // without this a version bump notifies subscribers of nodes it did not touch.\n Atom.withEquality(\n (a: Option.Option<Node.Node>, b: Option.Option<Node.Node>) =>\n Option.getOrUndefined(a) === Option.getOrUndefined(b),\n ),\n withLabel(`graph:node:${id}`),\n );\n });\n\n /**\n * The node as the model holds it right now.\n *\n * A flush applies its writes inside {@link batch}, which bumps the version once at the end, so\n * reading {@link Graph._node} from a write path yields the value from before the batch — and\n * `addNode` merges onto what it reads, so that would silently undo an earlier write in the\n * same flush.\n * @internal\n */\n _currentNode(id: string): Option.Option<Node.Node> {\n return Option.fromUndefinedOr(this._model.findNode(id)?.data);\n }\n\n /** The outgoing and inbound edges as the model holds them right now; see {@link Graph._currentNode}. @internal */\n _currentEdges(id: string): Edges {\n return this._computeEdges(id);\n }\n\n /** {@link Graph._currentEdges}; separate so the `_edges` atom body reads it without indirection. */\n _computeEdges(id: string): Edges {\n const edges: Edges = {};\n for (const relation of this._relations.get(id) ?? []) {\n edges[relation] = [];\n }\n for (const edge of this._model.outgoing(id)) {\n (edges[edge.type] ??= []).push(edge.target);\n }\n for (const edge of this._model.incoming(id)) {\n (edges[inverseKey(edge.type)] ??= []).push(edge.source);\n }\n return edges;\n }\n\n readonly _edges = Atom.family<string, Atom.Atom<Edges>>((id) => {\n return Atom.make((get) => {\n get(this._model.version);\n return this._computeEdges(id);\n }).pipe(Atom.withEquality(edgesEqual), withLabel(`graph:edges:${id}`));\n });\n\n // NOTE: Currently the argument to the family needs to be referentially stable for the atom to be referentially stable.\n // TODO(wittjosiah): Atom feature request, support for something akin to `ComplexMap` to allow for complex arguments.\n readonly _connections = Atom.family<string, Atom.Atom<Node.Node[]>>((key) => {\n const parts = key ? primaryParts(key) : [];\n // An empty id (e.g. `useConnections(graph, undefined, ...)`) yields a key with two parts but no\n // id — treat that as no connections rather than throwing.\n if (parts.length < 2 || !parts[0]) {\n return Atom.make((): Node.Node[] => []);\n }\n\n const { id, relation } = relationFromConnectionKey(key);\n return Atom.make((get) =>\n (get(this._edges(id))[relationKey(relation)] ?? [])\n .map((childId) => get(this._node(childId)))\n .filter(Option.isSome)\n .map((node) => node.value),\n ).pipe(\n // Depend on each child's own atom so a child's change invalidates this view, but cut off on the\n // resolved list: without this a no-op re-add re-allocates the Options and notifies spuriously.\n Atom.withEquality(\n (a: Node.Node[], b: Node.Node[]) => a.length === b.length && a.every((node, index) => node === b[index]),\n ),\n withLabel(`graph:connections:${key}`),\n );\n });\n\n readonly _actions = Atom.family<string, Atom.Atom<(Node.Action | Node.ActionGroup)[]>>((id) => {\n return Atom.make((get) => {\n if (!id) {\n return [];\n }\n return get(this._connections(connectionKey(id, Node.action))) as (Node.Action | Node.ActionGroup)[];\n }).pipe(withLabel(`graph:actions:${id}`));\n });\n\n readonly _json = Atom.family<string, Atom.Atom<any>>((id) => {\n return Atom.make((get) => {\n get(this._model.version);\n return this._model.toTree(\n id,\n (node, children: any[]) => {\n const data = node.data;\n if (!data) {\n return undefined;\n }\n return {\n id: data.id,\n type: data.type,\n ...(data.properties.label ? { label: data.properties.label } : {}),\n ...(children.length ? { nodes: children } : {}),\n };\n },\n relationKey('child'),\n );\n }).pipe(withLabel(`graph:json:${id}`));\n });\n\n constructor({ registry, nodes, edges, onExpand, onRemoveNode }: GraphProps = {}) {\n this._registry = registry ?? AtomEx.makeRegistry();\n this._onExpand = onExpand;\n this._onRemoveNode = onRemoveNode;\n this._model = new GraphModel.GraphModel<ModelNode, GraphEdge>({ registry: this._registry });\n\n this._model.batch(() => {\n this._setNode(GraphNode.RootId, this._constructNode({ id: GraphNode.RootId, type: Node.RootType, data: null }));\n nodes?.forEach((node) =>\n this._setNode(\n node.id,\n this._constructNode(\n typeof node.data === 'function'\n ? { ...node, data: stableData(this, node.id, node.type, undefined, node.data) }\n : node,\n ),\n ),\n );\n Object.entries(edges ?? {}).forEach(([source, relations]) => {\n Object.entries(relations).forEach(([relation, targets]) => {\n targets.forEach((target) => this._setEdge(source, target, relation));\n });\n });\n });\n }\n\n json(id = GraphNode.RootId): Atom.Atom<any> {\n return this._json(id);\n }\n\n node(id: string): Atom.Atom<Option.Option<Node.Node>> {\n return this._node(id);\n }\n\n connections(id: string, relation: Node.RelationInput): Atom.Atom<Node.Node[]> {\n return this._connections(connectionKey(id, relation));\n }\n\n actions(id: string): Atom.Atom<(Node.Action | Node.ActionGroup)[]> {\n return this._actions(id);\n }\n\n edges(id: string): Atom.Atom<Edges> {\n return this._edges(id);\n }\n\n /** @internal */\n _constructNode(node: Node.NodeArg<any>): Option.Option<Node.Node> {\n return Option.some({\n [graphSymbol]: this,\n data: null,\n properties: {},\n ...node,\n });\n }\n\n /**\n * Writes the node payload, materializing a placeholder slot when the id is new.\n * @internal\n */\n _setNode(id: string, node: Option.Option<Node.Node>): void {\n this._model.setNode({ id, data: Option.getOrUndefined(node) });\n // After the write, so the atom is computed with the value rather than with `none`.\n if (this._pins && !this._pins.has(id)) {\n this._pins.set(id, this._registry.mount(this._node(id)));\n }\n }\n\n /** @internal */\n _retain(): CleanupFn {\n invariant(!this._pins, 'Graph is already retained.');\n const pins = new Map<string, CleanupFn>();\n for (const { id } of this._model.nodes) {\n pins.set(id, this._registry.mount(this._node(id)));\n }\n this._pins = pins;\n return () => {\n if (this._pins !== pins) {\n return;\n }\n pins.forEach((unpin) => unpin());\n this._pins = undefined;\n };\n }\n\n /** @internal */\n _setEdge(source: string, target: string, relation: string): void {\n this._trackRelation(source, relation);\n this._trackRelation(target, inverseKey(relation));\n const stored = storedEdge(source, target, relation);\n if (this._model.findEdge(stored.id)) {\n return;\n }\n\n this._model.addEdge(stored);\n }\n\n /** @internal */\n _removeEdge(source: string, target: string, relation: string): void {\n // `detachEdge`, not `removeEdge`: the latter hands back the removed edge as a graph, and nothing\n // here reads it.\n this._model.detachEdge(storedEdge(source, target, relation).id);\n }\n\n /** @internal */\n _trackRelation(id: string, relation: string): void {\n const relations = this._relations.get(id) ?? new Set<string>();\n relations.add(relation);\n this._relations.set(id, relations);\n }\n}\n\n/**\n * The implementation behind a graph handle. Exported for this package's tests, which assert against\n * the model and expansion bookkeeping; not part of the public surface.\n * @internal\n */\nexport const getInternal = (graph: BaseGraph): GraphImpl => {\n return graph as unknown as GraphImpl;\n};\n\n/**\n * Creates a new Graph instance.\n */\nexport const make = (params?: GraphProps): Graph => {\n return new GraphImpl(params);\n};\n\n/**\n * Pins the graph's nodes in its registry, including nodes added later, until the returned function\n * is called. A graph has one holder at a time.\n */\nexport const retain = (graph: BaseGraph): CleanupFn => getInternal(graph)._retain();\n\n/**\n * Convert the graph to a JSON object.\n */\nexport const toJSON = (graph: BaseGraph, id = GraphNode.RootId): object => {\n const internal = getInternal(graph);\n return internal._registry.get(internal._json(id));\n};\n\n/**\n * Get the node with the given id from the graph's registry.\n */\nexport const getNode = (graph: BaseGraph, id: string): Option.Option<Node.Node> => {\n const internal = getInternal(graph);\n return internal._registry.get(internal._node(id));\n};\n\n/**\n * Get the node with the given id from the graph's registry.\n *\n * @throws {GraphNode.NotFoundError} If the graph has no node with the id.\n */\nexport const getNodeOrThrow = (graph: BaseGraph, id: string): Node.Node => {\n const internal = getInternal(graph);\n return Option.getOrThrowWith(internal._registry.get(internal._node(id)), () => new GraphNode.NotFoundError(id));\n};\n\n/**\n * Get the root node of the graph.\n * This is an alias for `getNodeOrThrow(graph, ROOT_ID)`.\n */\nexport function getRoot(graph: BaseGraph): Node.Node {\n return getNodeOrThrow(graph, GraphNode.RootId);\n}\n\n/**\n * Get all nodes connected to the node with the given id by the given relation from the graph's registry.\n */\nexport const getConnections = (graph: BaseGraph, id: string, relation: Node.RelationInput): Node.Node[] => {\n const internal = getInternal(graph);\n return internal._registry.get(internal._connections(connectionKey(id, relation)));\n};\n\n/**\n * Get all actions connected to the node with the given id from the graph's registry.\n */\nexport const getActions = (graph: BaseGraph, id: string): Node.Node[] => {\n const internal = getInternal(graph);\n return internal._registry.get(internal._actions(id));\n};\n\n/**\n * Get the edges from the node with the given id from the graph's registry.\n */\nexport const getEdges = (graph: BaseGraph, id: string): Edges => {\n const internal = getInternal(graph);\n return internal._registry.get(internal._edges(id));\n};\n\n/**\n * Recursive depth-first traversal of the graph.\n */\nexport const traverse = (graph: BaseGraph, options: GraphTraversalOptions, path: string[] = []): void => {\n const { visitor, source = GraphNode.RootId, relation } = options;\n // Break cycles.\n if (path.includes(source)) {\n return;\n }\n\n const node = getNodeOrThrow(graph, source);\n const shouldContinue = visitor(node, [...path, source]);\n if (shouldContinue === false) {\n return;\n }\n\n const relations = Array.isArray(relation) ? relation : [relation];\n const seen = new Set<string>();\n for (const rel of relations) {\n for (const connected of getConnections(graph, source, rel)) {\n if (!seen.has(connected.id)) {\n seen.add(connected.id);\n traverse(graph, { source: connected.id, relation, visitor }, [...path, source]);\n }\n }\n }\n};\n\n/**\n * Get the path between two nodes in the graph.\n */\nexport const getPath = (graph: BaseGraph, params: { source?: string; target: string }): Option.Option<string[]> => {\n return Function.pipe(\n getNode(graph, params.source ?? 'root'),\n Option.flatMap((node) => {\n let found: Option.Option<string[]> = Option.none();\n traverse(graph, {\n source: node.id,\n relation: 'child',\n visitor: (node, path) => {\n if (Option.isSome(found)) {\n return false;\n }\n\n if (node.id === params.target) {\n found = Option.some(path);\n }\n },\n });\n\n return found;\n }),\n );\n};\n\n/**\n * Wait for the path between two nodes in the graph to be established.\n */\nexport const waitForPath = (\n graph: BaseGraph,\n params: { source?: string; target: string },\n options?: { timeout?: number; interval?: number },\n): Promise<string[]> => {\n const { timeout = 5_000, interval = 500 } = options ?? {};\n const path = getPath(graph, params);\n if (Option.isSome(path)) {\n return Promise.resolve(path.value);\n }\n\n const trigger = new Trigger<string[]>();\n const i = setInterval(() => {\n const path = getPath(graph, params);\n if (Option.isSome(path)) {\n trigger.wake(path.value);\n }\n }, interval);\n\n return trigger.wait({ timeout }).finally(() => clearInterval(i));\n};\n\n/**\n * Resolves when the node exists in the graph; immediately if it already does.\n *\n * The graph is populated asynchronously — connectors expand a level at a time and the objects\n * behind them load out of band — and {@link expandSync} is fire-and-forget, so a consumer that needs\n * a specific node has no completion to await and would otherwise poll for it.\n *\n * Deliberately unbounded: whether a node is merely late or will never arrive is the caller's\n * question, so the deadline belongs at the call site (`Effect.timeout`). Interrupting is safe —\n * the subscription is released on interruption.\n */\nexport const waitFor = (graph: BaseGraph, id: string): Effect.Effect<Node.Node> =>\n Effect.suspend(() => {\n const current = getNode(graph, id);\n if (Option.isSome(current)) {\n return Effect.succeed(current.value);\n }\n\n return Effect.callback<Node.Node>((resume) => {\n const unsubscribe = graph.onNodeChanged.on(({ id: changed, node }) => {\n if (changed === id && Option.isSome(node)) {\n unsubscribe();\n resume(Effect.succeed(node.value));\n }\n });\n\n // Re-read after subscribing: a node added between the read above and the subscription\n // emits nothing further, and the wait would hang on an event that already happened.\n const raced = getNode(graph, id);\n if (Option.isSome(raced)) {\n unsubscribe();\n resume(Effect.succeed(raced.value));\n }\n\n return Effect.sync(() => unsubscribe());\n });\n });\n\n/**\n * Implementation helper for expandSync.\n * If the node does not exist yet, the expand is recorded as pending and applied when the node is added.\n *\n * Fires the `onExpand` callback to add connections to the node. The builder only marks the relation's\n * connectors dirty; they run, and their output reaches the graph, on its next flush.\n *\n * Expanding a node that is already expanded for the same relation is a no-op.\n */\nexport const expandSync = <T extends ExpandableGraph | WritableGraph>(\n graph: T,\n id: string,\n relation: Node.RelationInput,\n): T => {\n const internal = getInternal(graph);\n const normalizedRelation = normalizeRelation(relation);\n const key = primaryKey(id, relationKey(normalizedRelation));\n const nodeOpt = internal._currentNode(id);\n if (Option.isNone(nodeOpt)) {\n // Node not yet in graph: record expand to run when the node is added.\n internal._pendingExpands.add(key);\n log('expand', { key, deferred: true });\n return graph;\n }\n\n const expanded = internal._expanded.has(key);\n log('expand', { key, expanded });\n if (!expanded) {\n internal._expanded.add(key);\n internal._onExpand?.(id, normalizedRelation);\n }\n return graph;\n};\n\n/**\n * {@link expandSync} the `child` relation of every ancestor of a qualified id, and of the id itself.\n * A missing ancestor's expand is deferred until it arrives, so a single call populates the whole path.\n */\nexport const expandPath = <T extends ExpandableGraph | WritableGraph>(graph: T, qualifiedId: string): T => {\n const segments = qualifiedId.split('/');\n for (let index = 1; index <= segments.length; index++) {\n expandSync(graph, segments.slice(0, index).join('/'), 'child');\n }\n return graph;\n};\n\n/**\n * Expand a node in the graph, off the paint-critical path.\n *\n * Yields to the main thread before running {@link expandSync}, so a caller reacting to input does not\n * block the frame. Interrupting the effect cancels a still-pending expansion, which makes rescheduling\n * (e.g. superseding a hover with the next one) a matter of interrupting the previous fiber.\n */\nexport const expand = <T extends ExpandableGraph | WritableGraph>(\n graph: T,\n id: string,\n relation: Node.RelationInput,\n): Effect.Effect<void> =>\n Effect.promise((signal) =>\n scheduleTask(\n () => {\n expandSync(graph, id, relation);\n },\n { strategy: 'idle', signal },\n ),\n );\n\n/**\n * Sort the edges of the node with the given id.\n */\nexport const sortEdges = <T extends ExpandableGraph | WritableGraph>(\n graph: T,\n id: string,\n relation: Node.RelationInput,\n order: string[],\n): T => {\n const internal = getInternal(graph);\n const edges = internal._currentEdges(id);\n const relationId = relationKey(relation);\n const current = edges[relationId] ?? [];\n // Set membership, not `includes`: both filters run over the whole relation, and a connector\n // sorting its output makes an array scan here quadratic in the number of siblings.\n const ordered = new Set(order);\n const existing = new Set(current);\n const unsorted = current.filter((id) => !ordered.has(id));\n const sorted = order.filter((id) => existing.has(id));\n const newOrder = [...sorted, ...unsorted];\n if (newOrder.length === current.length && newOrder.every((id, i) => id === current[i])) {\n return graph;\n }\n // Insertion order carries the sort, so reordering means re-adding the relation's edges.\n internal._model.batch(() => {\n current.forEach((target) => internal._removeEdge(id, target, relationId));\n newOrder.forEach((target) => internal._setEdge(id, target, relationId));\n });\n return graph;\n};\n\n/**\n * Applies `fn`'s writes as a single observable change: the model bumps its version once, so derived\n * views recompute and notify once for the whole group.\n */\nexport const batch = <T extends WritableGraph, A>(graph: T, fn: () => A): A => getInternal(graph)._model.batch(fn);\n\n/**\n * Unloads the nodes: they leave the model outright, along with the expansion bookkeeping that would\n * otherwise keep the graph remembering ids it will never be asked about again.\n *\n * Unlike {@link removeNodes} this leaves no tombstone, so a subsequent read of a released relation\n * expands it afresh rather than resolving to an emptied node.\n */\nexport const release = <T extends WritableGraph>(graph: T, ids: readonly string[]): T => {\n const internal = getInternal(graph);\n internal._model.batch(() => {\n for (const id of ids) {\n internal._pins?.get(id)?.();\n internal._pins?.delete(id);\n internal._relations.delete(id);\n }\n\n releaseExpansions(internal, new Set(ids));\n internal._model.release(ids);\n });\n\n return graph;\n};\n\nconst releaseExpansions = (internal: GraphImpl, ids: ReadonlySet<string>): void => {\n for (const set of [internal._expanded, internal._pendingExpands]) {\n for (const key of set) {\n if (ids.has(primaryParts(key)[0])) {\n set.delete(key);\n }\n }\n }\n};\n\n/**\n * Forgets that `relation` of `id` was expanded. Paired with the builder tearing down the matching\n * connector subscription, so a relation whose contents were released re-expands rather than\n * resolving to the emptied list it had before.\n */\nexport const releaseRelation = <T extends ExpandableGraph | WritableGraph>(\n graph: T,\n id: string,\n relation: string,\n): T => {\n const internal = getInternal(graph);\n const key = primaryKey(id, relation);\n internal._expanded.delete(key);\n internal._pendingExpands.delete(key);\n return graph;\n};\n\n/**\n * Add nodes to the graph.\n */\nexport const addNodes = <T extends WritableGraph>(graph: T, nodes: Node.NodeArg<any, Record<string, any>>[]): T => {\n // The model's own depth counter, not `Atom.batch`: these calls nest (a node applies its inline\n // children and edges), and a nested `Atom.batch` leaves the registry in its collect phase after\n // the inner call returns, so invalidations raised afterwards are gathered and then discarded\n // without ever being rebuilt. The version atom still bumps once for the whole group.\n getInternal(graph)._model.batch(() => {\n nodes.map((node) => addNode(graph, node));\n });\n return graph;\n};\n\n/**\n * Builders recreate an action's closure on every run, so an action's `data` is held behind a stable\n * forwarder per node whose target is swapped: a re-offer that changes nothing else emits nothing,\n * and invoking the node still runs the latest closure. Only actions: other function data (a type\n * node's schema class) is read for its statics, which a forwarder does not carry.\n */\nconst stableData = (graph: GraphImpl, id: string, type: string, existing: unknown, data: any): any => {\n if (type !== Node.ActionType || typeof data !== 'function') {\n return data;\n }\n const owned = (forwarder: Forwarder) => forwarder[ForwardedKey].graph === graph && forwarder[ForwardedKey].id === id;\n // This node's own forwarder read back and re-added is kept: retargeting it at itself would recurse.\n if (isForwarder(data) && owned(data)) {\n return data;\n }\n // Any other forwarder, from another node or graph, is unwrapped: a target is never a forwarder, so none can cycle.\n const target = isForwarder(data) ? data[ForwardedKey].target : data;\n if (isForwarder(existing) && owned(existing)) {\n existing[ForwardedKey].target = target;\n return existing;\n }\n const cell: Forwarded = { target, graph, id };\n const forwarder: Forwarder = Object.assign((...args: unknown[]) => cell.target(...args), { [ForwardedKey]: cell });\n return forwarder;\n};\n\n/**\n * Add a node to the graph.\n */\nexport const addNode = <T extends WritableGraph>(graph: T, nodeArg: Node.NodeArg<any, Record<string, any>>): T => {\n const internal = getInternal(graph);\n // Extract known NodeArg fields, preserve any extra fields (like _actionContext) in rest.\n const {\n nodes,\n actions,\n edges,\n id,\n type,\n data = null,\n properties = {},\n ...rest\n } = nodeArg as Node.NodeArg<any> & {\n _actionContext?: Node.ActionContext;\n };\n const existingNode = internal._currentNode(id);\n Option.match(existingNode, {\n onSome: (existing) => {\n const typeChanged = existing.type !== type;\n const nextData = stableData(internal, id, type, existing.data, data);\n const dataChanged = !shallowEqual(existing.data, nextData);\n const propertiesChanged = Object.keys(properties).some(\n (key) => !Equal.equals(existing.properties[key], properties[key]),\n );\n // The forwarder keeps `data` stable, so the context an action runs with is compared on its own; an\n // offer without one keeps the stored context, since the update spreads the existing node.\n const contextChanged =\n rest._actionContext !== undefined &&\n (Node.isAction(existing) ? existing._actionContext : undefined) !== rest._actionContext;\n // `changed` is on the visit log because counting `existing node` lines alone measures how often a\n // node was re-offered, not how often it actually changed — two very different costs.\n const changed = typeChanged || dataChanged || propertiesChanged || contextChanged;\n log('existing node', {\n id,\n changed,\n typeChanged,\n dataChanged,\n propertiesChanged,\n contextChanged,\n });\n if (changed) {\n log('updating node', { id, type, data, properties });\n const newNode = Option.some({\n ...existing,\n ...rest,\n type,\n data: nextData,\n // Merged, not replaced, so several extensions can each contribute properties to one node —\n // which makes a key one generation sets and the next omits impossible to clear. A builder\n // that varies a property must emit it on every generation, `false`/`undefined` included.\n properties: { ...existing.properties, ...properties },\n });\n internal._setNode(id, newNode);\n graph.onNodeChanged.emit({ id, node: newNode });\n }\n },\n onNone: () => {\n log('new node', { id, type, data, properties });\n const newNode = internal._constructNode({\n id,\n type,\n data: stableData(internal, id, type, undefined, data),\n properties,\n ...rest,\n });\n internal._setNode(id, newNode);\n graph.onNodeChanged.emit({ id, node: newNode });\n\n // Apply any expands that were deferred because this node did not exist yet.\n const toApply = [...internal._pendingExpands].filter((k) => primaryParts(k)[0] === id);\n for (const pendingKey of toApply) {\n internal._pendingExpands.delete(pendingKey);\n const relation = relationFromKey(primaryParts(pendingKey)[1]);\n internal._expanded.add(pendingKey);\n internal._onExpand?.(id, relation);\n }\n },\n });\n\n if (nodes) {\n addNodes(graph, nodes);\n const _edges = nodes.map((node) => ({ source: id, target: node.id, relation: 'child' as const }));\n addEdges(graph, _edges);\n sortEdges(\n graph,\n id,\n 'child',\n nodes.map((n) => n.id),\n );\n }\n\n if (actions) {\n addNodes(graph, actions);\n const _edges = actions.map((node) => ({ source: id, target: node.id, relation: Node.action }));\n addEdges(graph, _edges);\n sortEdges(\n graph,\n id,\n Node.action,\n actions.map((node) => node.id),\n );\n }\n\n if (edges) {\n todo();\n }\n return graph;\n};\n\n/**\n * Remove nodes from the graph.\n */\nexport const removeNodes = <T extends WritableGraph>(graph: T, ids: string[], edges = false): T => {\n getInternal(graph)._model.batch(() => {\n ids.map((id) => removeNode(graph, id, edges));\n });\n return graph;\n};\n\n/**\n * Remove a node from the graph.\n */\nexport const removeNode = <T extends WritableGraph>(graph: T, id: string, edges = false): T => {\n const internal = getInternal(graph);\n internal._setNode(id, Option.none());\n graph.onNodeChanged.emit({ id, node: Option.none() });\n // The builder drops the node's connectors with it, so its expansions wait to re-run when it comes back.\n for (const key of internal._expanded) {\n if (primaryParts(key)[0] === id) {\n internal._expanded.delete(key);\n internal._pendingExpands.add(key);\n }\n }\n\n if (edges) {\n const nodeEdges = internal._currentEdges(id);\n const edgesToRemove: Edge[] = [];\n for (const [relationKeyValue, relatedIds] of Object.entries(nodeEdges)) {\n const relation = relationFromKey(relationKeyValue);\n const isInboundRelation = relation.direction === 'inbound';\n for (const relatedId of relatedIds) {\n if (isInboundRelation) {\n // Inbound edge lists store source node IDs; reconstruct the canonical outbound edge.\n edgesToRemove.push({ source: relatedId, target: id, relation: inverseRelation(relation) });\n } else {\n edgesToRemove.push({ source: id, target: relatedId, relation });\n }\n }\n }\n removeEdges(graph, edgesToRemove);\n }\n\n internal._onRemoveNode?.(id);\n return graph;\n};\n\n/**\n * Add edges to the graph.\n */\nexport const addEdges = <T extends WritableGraph>(graph: T, edges: Edge[]): T => {\n getInternal(graph)._model.batch(() => {\n edges.map((edge) => addEdge(graph, edge));\n });\n return graph;\n};\n\n/**\n * Add an edge to the graph.\n */\nexport const addEdge = <T extends WritableGraph>(graph: T, edgeArg: Edge): T => {\n const relationId = relationKey(normalizeRelation(edgeArg.relation));\n const internal = getInternal(graph);\n // Deduping is `_setEdge`'s job and it does it by edge id in O(1); the membership check that used\n // to guard this built the source's whole edge record per edge, which is quadratic on a wide fan-out.\n // No log line here — it runs per edge of every flush, and building the entry costs more than the write.\n internal._setEdge(edgeArg.source, edgeArg.target, relationId);\n return graph;\n};\n\n/**\n * Remove edges from the graph.\n */\nexport const removeEdges = <T extends WritableGraph>(graph: T, edges: Edge[], removeOrphans = false): T => {\n getInternal(graph)._model.batch(() => {\n edges.map((edge) => removeEdge(graph, edge, removeOrphans));\n });\n return graph;\n};\n\n/**\n * Remove an edge from the graph.\n */\nexport const removeEdge = <T extends WritableGraph>(graph: T, edgeArg: Edge, removeOrphans = false): T => {\n const relation = normalizeRelation(edgeArg.relation);\n const relationId = relationKey(relation);\n const inverse = inverseRelation(relation);\n const inverseId = relationKey(inverse);\n const internal = getInternal(graph);\n\n internal._removeEdge(edgeArg.source, edgeArg.target, relationId);\n\n if (removeOrphans) {\n // Asked of the model directly rather than through `_edges`, whose adjacency read rebuilds an\n // O(E) index on every version bump — quadratic when a connector drops all of its nodes at once.\n for (const endpoint of [edgeArg.source, edgeArg.target]) {\n if (endpoint !== GraphNode.RootId && !internal._model.hasEdges(endpoint)) {\n removeNodes(graph, [endpoint]);\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,UAAU;CAE/D,IAAI,eAGG;OAAA,MAAM,YAAY,CAAC,QAAQ,QAAQ,QAAQ,MAAM,GACpD,IAAI,aAAa,UAAU,UAAU,CAAC,SAAS,OAAO,SAAS,QAAQ,GACrE,YAAY,OAAO,CAAC,QAAQ,CAAC;CAAA;CAInC,OAAO;AACT"}
|
package/dist/lib/chunk-atoms.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
-
import * as Atom from "effect/reactivity/Atom";
|
|
3
2
|
import * as Equal from "effect/Equal";
|
|
3
|
+
import * as Atom from "effect/reactivity/Atom";
|
|
4
4
|
//#region src/atoms.ts
|
|
5
5
|
var atoms_exports = /* @__PURE__ */ __exportAll({ fromObservable: () => fromObservable });
|
|
6
6
|
var observableFamily = Atom.family((observable) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppGraph.bench.d.ts","sourceRoot":"","sources":["../../../src/AppGraph.bench.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppGraph.d.ts","sourceRoot":"","sources":["../../../src/AppGraph.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"AppGraph.d.ts","sourceRoot":"","sources":["../../../src/AppGraph.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAIxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,QAAQ,MAAM,gCAAgC,CAAC;AAE3D,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,EAAW,MAAM,aAAa,CAAC;AAO7D,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,YAAY,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eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,aAAa,SAAS,CAAC,SAAS,IAAI,EAAE,KAAG,CAK3E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,aAAa,SAAS,CAAC,WAAW,IAAI,KAAG,CAQ1E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,aAAa,SAAS,CAAC,SAAS,IAAI,EAAE,8BAA0B,CAKrG,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,aAAa,SAAS,CAAC,WAAW,IAAI,8BAA0B,CAmBpG,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAI/C,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAC;AAS1C,2FAA2F;AAC3F,eAAO,MAAM,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAEzD,CAAC;AAQzB,6CAA6C;AAC7C,eAAO,MAAM,UAAU,aAAc,MAAM,EAAE,KAAG,MAA6B,CAAC;AAE9E,4CAA4C;AAC5C,eAAO,MAAM,YAAY,QAAS,MAAM,KAAG,MAAM,EAAwB,CAAC;AAE1E,+CAA+C;AAC/C,eAAO,MAAM,YAAY,aAAc,MAAM,EAAE,KAAG,MAA+B,CAAC;AAElF,8CAA8C;AAC9C,eAAO,MAAM,cAAc,QAAS,MAAM,KAAG,MAAM,EAA0B,CAAC;AAE9E;;GAEG;AACH,eAAO,MAAM,iBAAiB,cAAe,IAAI,CAAC,aAAa,KAAG,IAAI,CAAC,QAC4B,CAAC;AAEpG;;;GAGG;AACH,eAAO,MAAM,iBAAiB,SAAU,SAAS,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,QAAQ,SAAS,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,KAAG,OAgB1G,CAAC"}
|