@graphty/graphty-element 2.5.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/dist/ai.js +3 -3
  2. package/dist/catalog.d.ts +16 -0
  3. package/dist/catalog.js +34 -32
  4. package/dist/chunks/{AiManager-CrbvKdEK.js → AiManager-4iQpsJW1.js} +4 -4
  5. package/dist/chunks/{DataSource-qU-nLhXN.js → DataSource-BL2UzPff.js} +2 -2
  6. package/dist/chunks/GraphSession-BhuHSXIo.js +12819 -0
  7. package/dist/chunks/{GraphtyLogger-DOTwCiMR.js → GraphtyLogger-B_O67a6c.js} +1 -1
  8. package/dist/chunks/{VoiceInputAdapter-D4NrRL_1.js → VoiceInputAdapter-Cc6mHXTI.js} +1 -1
  9. package/dist/chunks/{XRPivotCameraController-Uqa47vmo.js → XRPivotCameraController-BLa89LXn.js} +2 -2
  10. package/dist/chunks/{algorithms-D-ab-Auu.js → algorithms-BJ6DQMOe.js} +931 -781
  11. package/dist/chunks/{capability-check-Vw3IcqiE.js → capability-check-Am2zliFj.js} +1 -1
  12. package/dist/chunks/{detect-B4Qrw976.js → detect-fyuVnlCT.js} +1 -1
  13. package/dist/chunks/{format-detection-r2IfNFXO.js → format-detection-BHwrAVzW.js} +1 -1
  14. package/dist/chunks/{index-J9MgLio9.js → index-BkBLbvui.js} +2691 -2434
  15. package/dist/chunks/optionsFromZod-CKMYSwTz.js +3636 -0
  16. package/dist/chunks/{paletteRegistry-Kt-6CeoN.js → paletteRegistry-BCFSwJGK.js} +224 -189
  17. package/dist/chunks/parse-BMTqt4SS.js +3658 -0
  18. package/dist/chunks/{types-C_c53VgR.js → types-DFchv4Ny.js} +4 -1
  19. package/dist/custom-elements.json +1 -1
  20. package/dist/extend.d.ts +10 -8
  21. package/dist/extend.js +6 -6
  22. package/dist/graphty-catalog.json +75 -38
  23. package/dist/graphty.bundle.js +55368 -48970
  24. package/dist/graphty.js +19 -19
  25. package/dist/index.d.ts +1 -1
  26. package/dist/logging.js +2 -2
  27. package/dist/schema.d.ts +15 -1
  28. package/dist/schema.js +1 -1
  29. package/dist/session.d.ts +30 -7
  30. package/dist/session.js +40 -37
  31. package/dist/src/Graph.d.ts +35 -7
  32. package/dist/src/acceleration/types.d.ts +79 -43
  33. package/dist/src/algorithms/Algorithm.d.ts +52 -4
  34. package/dist/src/algorithms/BFSAlgorithm.d.ts +3 -0
  35. package/dist/src/algorithms/BellmanFordAlgorithm.d.ts +3 -0
  36. package/dist/src/algorithms/BetweennessCentralityAlgorithm.d.ts +3 -0
  37. package/dist/src/algorithms/BipartiteMatchingAlgorithm.d.ts +3 -0
  38. package/dist/src/algorithms/ClosenessCentralityAlgorithm.d.ts +3 -0
  39. package/dist/src/algorithms/ConnectedComponentsAlgorithm.d.ts +4 -1
  40. package/dist/src/algorithms/DFSAlgorithm.d.ts +3 -0
  41. package/dist/src/algorithms/DegreeAlgorithm.d.ts +3 -0
  42. package/dist/src/algorithms/DijkstraAlgorithm.d.ts +6 -0
  43. package/dist/src/algorithms/EigenvectorCentralityAlgorithm.d.ts +2 -0
  44. package/dist/src/algorithms/FloydWarshallAlgorithm.d.ts +3 -0
  45. package/dist/src/algorithms/GirvanNewmanAlgorithm.d.ts +3 -0
  46. package/dist/src/algorithms/HITSAlgorithm.d.ts +3 -0
  47. package/dist/src/algorithms/KCoreAlgorithm.d.ts +3 -0
  48. package/dist/src/algorithms/KatzCentralityAlgorithm.d.ts +3 -0
  49. package/dist/src/algorithms/KruskalAlgorithm.d.ts +4 -1
  50. package/dist/src/algorithms/LabelPropagationAlgorithm.d.ts +3 -0
  51. package/dist/src/algorithms/LeidenAlgorithm.d.ts +3 -0
  52. package/dist/src/algorithms/LinkPredictionAlgorithm.d.ts +4 -1
  53. package/dist/src/algorithms/LouvainAlgorithm.d.ts +3 -0
  54. package/dist/src/algorithms/MaxFlowAlgorithm.d.ts +3 -0
  55. package/dist/src/algorithms/MinCutAlgorithm.d.ts +3 -0
  56. package/dist/src/algorithms/PageRankAlgorithm.d.ts +3 -0
  57. package/dist/src/algorithms/PrimAlgorithm.d.ts +3 -0
  58. package/dist/src/algorithms/StronglyConnectedComponentsAlgorithm.d.ts +3 -0
  59. package/dist/src/algorithms/input/ScopedInput.d.ts +185 -0
  60. package/dist/src/algorithms/input/derivedInputs.d.ts +199 -0
  61. package/dist/src/algorithms/input/maskBack.d.ts +37 -0
  62. package/dist/src/algorithms/metrics/MetricAlgorithm.d.ts +3 -3
  63. package/dist/src/algorithms/results/DeclaredAlgorithm.d.ts +4 -3
  64. package/dist/src/algorithms/results/types.d.ts +28 -6
  65. package/dist/src/algorithms/utils/communityUtils.d.ts +0 -48
  66. package/dist/src/algorithms/utils/graphUtils.d.ts +2 -68
  67. package/dist/src/algorithms/utils/snapshotGraph.d.ts +3 -1
  68. package/dist/src/catalog/algorithms.d.ts +3 -0
  69. package/dist/src/catalog/layouts.d.ts +2 -0
  70. package/dist/src/catalog/sets/canonical.d.ts +68 -0
  71. package/dist/src/catalog/sets/hash.d.ts +126 -0
  72. package/dist/src/catalog/sets/parse.d.ts +115 -0
  73. package/dist/src/catalog/types.d.ts +329 -8
  74. package/dist/src/data/GraphStore.d.ts +73 -1
  75. package/dist/src/data/edgeIdentity.d.ts +202 -1
  76. package/dist/src/data/ingest.d.ts +3 -1
  77. package/dist/src/data/report.d.ts +20 -0
  78. package/dist/src/graphty-element.d.ts +42 -6
  79. package/dist/src/layout/D3GraphLayoutEngine.d.ts +11 -0
  80. package/dist/src/layout/LayoutEngine.d.ts +56 -0
  81. package/dist/src/layout/NGraphLayoutEngine.d.ts +10 -0
  82. package/dist/src/layout/SimulationLayoutEngine.d.ts +11 -0
  83. package/dist/src/managers/AlgorithmManager.d.ts +8 -0
  84. package/dist/src/managers/DataManager.d.ts +11 -0
  85. package/dist/src/managers/LayoutManager.d.ts +126 -2
  86. package/dist/src/managers/StatsManager.d.ts +1 -0
  87. package/dist/src/session/GraphSession.d.ts +48 -0
  88. package/dist/src/session/attributes.d.ts +121 -1
  89. package/dist/src/session/cost/estimate.d.ts +20 -0
  90. package/dist/src/session/cost/index.d.ts +1 -1
  91. package/dist/src/session/planning.d.ts +32 -2
  92. package/dist/src/session/query.d.ts +7 -0
  93. package/dist/src/session/results/ResultsApi.d.ts +14 -1
  94. package/dist/src/session/runs/Run.d.ts +65 -4
  95. package/dist/src/session/runs/RunsApi.d.ts +58 -2
  96. package/dist/src/session/runs/runId.d.ts +55 -6
  97. package/dist/src/session/runs/types.d.ts +36 -8
  98. package/dist/src/session/scope/ElementMask.d.ts +14 -1
  99. package/dist/src/session/scope/ScopeApi.d.ts +160 -31
  100. package/dist/src/session/scope/index.d.ts +1 -1
  101. package/dist/src/session/selection/SelectionApi.d.ts +15 -10
  102. package/dist/src/session/selection/index.d.ts +1 -1
  103. package/dist/src/session/selection/targets.d.ts +6 -7
  104. package/dist/src/session/sets/SetsApi.d.ts +110 -0
  105. package/dist/src/session/sets/algebra.d.ts +124 -0
  106. package/dist/src/session/sets/cache.d.ts +197 -0
  107. package/dist/src/session/sets/captures.d.ts +83 -0
  108. package/dist/src/session/sets/dependencies.d.ts +167 -0
  109. package/dist/src/session/sets/layers.d.ts +101 -0
  110. package/dist/src/session/sets/notify.d.ts +122 -0
  111. package/dist/src/session/sets/offers.d.ts +103 -0
  112. package/dist/src/session/sets/path.d.ts +37 -0
  113. package/dist/src/session/sets/prepare.d.ts +209 -0
  114. package/dist/src/session/sets/resolve.d.ts +311 -0
  115. package/dist/src/session/sets/signature.d.ts +77 -0
  116. package/dist/src/session/sets/status.d.ts +98 -0
  117. package/dist/src/session/sets/store.d.ts +196 -0
  118. package/dist/src/session/sets/types.d.ts +386 -0
  119. package/dist/src/session/styles/Layer.d.ts +9 -2
  120. package/dist/src/session/styles/StylesApi.d.ts +5 -2
  121. package/dist/src/session/styles/explain.d.ts +5 -2
  122. package/dist/src/session/styles/predicate.d.ts +41 -2
  123. package/dist/src/session/styles/repaint.d.ts +19 -0
  124. package/dist/src/session/styles/selector.d.ts +16 -5
  125. package/dist/src/session/types.d.ts +18 -0
  126. package/dist/src/session/visibility/VisibilityApi.d.ts +47 -3
  127. package/dist/src/session/visibility/filter.d.ts +86 -51
  128. package/dist/src/session/visibility/index.d.ts +1 -1
  129. package/dist/src/testing/fakeAccelerator.d.ts +5 -0
  130. package/dist/src/utils/queue-migration.d.ts +17 -0
  131. package/package.json +15 -9
  132. package/dist/chunks/GraphSession-DuAhRgCd.js +0 -8622
  133. package/dist/chunks/optionsFromZod-B9RncoTX.js +0 -2578
  134. package/dist/chunks/scales-CJCRwi2J.js +0 -3220
  135. package/dist/src/algorithms/utils/index.d.ts +0 -6
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @file A set's status, derived on read (design/sets/sets-design.md sections 3.4, 5.2 and 5.3).
3
+ *
4
+ * Status is computed from what the definition reads (`./dependencies`), the runs and sets it
5
+ * names, the captures its held items have, and the outcome the last pass over it recorded (the
6
+ * summary in `./cache`). It never resolves, so a panel may ask for every row.
7
+ *
8
+ * | Found | Freshness | Reason |
9
+ * |------------------------------------------------|------------------------------|-------------------------|
10
+ * | a named set or run that is gone | `detached` | `missing-set`, `missing-run` |
11
+ * | a named set that is not current | as that set | `input` |
12
+ * | a run whose declared inputs changed | `out-of-date` | `run-out-of-date` |
13
+ * | the same, its algorithm no longer registered | `cannot-rerun` | `missing-capability` |
14
+ * | a run's algorithm no longer registered | (unchanged) | `missing-capability` |
15
+ * | a run that recorded another revision scheme | (unchanged) | `revision-unknown` |
16
+ * | a held execution that is no longer current | (unchanged); `earlierRuns` | `values-not-kept` without a capture |
17
+ * | a ring of references, an unknown kind, a rule that cannot compile | `unresolvable` | `cycle`, `missing-capability`, `invalid` |
18
+ * | edge members two edges carry, at the last pass | (unchanged) | `ambiguous-parallel-edge` |
19
+ *
20
+ * The worst freshness wins, in the order current, out-of-date, cannot-rerun, detached,
21
+ * unresolvable.
22
+ *
23
+ * WHEN A RUN IS OUT OF DATE, for sets: only when a declared input changed. A run over a kept set is
24
+ * out of date when the set's revision moved since the run recorded it (unknown, never "changed",
25
+ * when the two revisions are of different scheme versions) or when its membership moved, as for an
26
+ * inline scope; a run over a frozen scope (`{ nodes }`,
27
+ * `{ where }`, `{ define }`, `"graph"`, `"largest-component"`) when that scope's membership moved.
28
+ * A change of `"visible"` or `"selection"` never counts: the run froze its scope when it started.
29
+ *
30
+ * Nothing here reaches Babylon.js, Lit or the DOM.
31
+ */
32
+ import type { RunId, Scope, SetId } from "../../catalog/types";
33
+ import { type HeldCaptures } from "./captures";
34
+ import { type DependencySources } from "./dependencies";
35
+ import type { Resolution } from "./resolve";
36
+ import type { ElementSet, SetStatus } from "./types";
37
+ /** What status reads about one run. */
38
+ export interface StatusRun {
39
+ readonly id: RunId;
40
+ /** What the run is called now. */
41
+ readonly label: string;
42
+ readonly algorithm: string;
43
+ /** Whether the algorithm is still registered, so the run could be re-run. */
44
+ readonly registered: boolean;
45
+ /** The token of the run's current result, or undefined while it has none. */
46
+ readonly execution: string | undefined;
47
+ /** What the run recorded about its scope when it ran. */
48
+ readonly scope: {
49
+ readonly spec: Scope;
50
+ readonly set?: {
51
+ readonly id: SetId;
52
+ readonly revision: string;
53
+ };
54
+ };
55
+ /**
56
+ * Whether the membership of the run's scope moved since it ran. Read for a frozen scope and a
57
+ * kept set, never for `"visible"` or `"selection"`.
58
+ * @returns True when it moved.
59
+ */
60
+ scopeMoved(): boolean;
61
+ /** The captures the run keeps for held items. */
62
+ readonly captures: HeldCaptures;
63
+ }
64
+ /** What status reads. */
65
+ export interface StatusSources {
66
+ /** The kept sets, their tombstones and the issued-id register. */
67
+ readonly sets: {
68
+ get(id: SetId): ElementSet | undefined;
69
+ tombstone(id: SetId): {
70
+ readonly name: string;
71
+ } | undefined;
72
+ };
73
+ /** Where references are looked up, for cycles, readings and a query's paths. */
74
+ readonly dependencies: DependencySources;
75
+ /**
76
+ * One run. Absent: no run exists.
77
+ * @param id - The run.
78
+ * @returns The run, or undefined when there is none.
79
+ */
80
+ readonly run?: (id: RunId) => StatusRun | undefined;
81
+ /**
82
+ * What the last pass over a kept set found, when it resolved the set's current definition.
83
+ * @param record - The set.
84
+ * @returns The outcome, or undefined when no pass has.
85
+ */
86
+ readonly outcome?: (record: ElementSet) => {
87
+ readonly problem?: Resolution["problem"];
88
+ readonly ambiguousEdges: number;
89
+ } | undefined;
90
+ }
91
+ /**
92
+ * Status of any scope: a kept set by `{ set }`, an inline definition, a query, or a keyword (always
93
+ * current).
94
+ * @param scope - The canonical scope.
95
+ * @param sources - What status reads.
96
+ * @returns The status.
97
+ */
98
+ export declare function statusOf(scope: Scope, sources: StatusSources): SetStatus;
@@ -0,0 +1,196 @@
1
+ /**
2
+ * @file The kept-set slice: one keyed map of frozen records, written only through `put` and
3
+ * `delete` inside a write group (design/sets/sets-design.md sections 3.1, 12.4, 13).
4
+ *
5
+ * Beside the slice, never in it:
6
+ *
7
+ * - the ISSUED-ID REGISTER, every id ever minted. Monotonic: appended when a group commits,
8
+ * never written by `put` or `delete`, never rewound. Minting skips it, the live ids and the ids
9
+ * pending in the open group, so an id is never issued twice even when a group creates, removes
10
+ * and re-creates one name.
11
+ * - the TOMBSTONES, `{ id, name, record? }` for each removed id, rewritten at every commit that
12
+ * removes it. A tombstone is authoritative only while its id is absent from the slice. Its
13
+ * record is kept while anything still names the id -- a reference to a removed set resolves
14
+ * through it, and `sets.restore` brings it back -- and dropped by {@link SetsStore.forget} once
15
+ * nothing does, id and name kept. There is no byte cap: a cap could drop the one record a
16
+ * visible Detached mark needs.
17
+ * - the SEEDS, per set id: for each edge member a door added from a session edge id, the counter
18
+ * it came through (design 4.2). A binding cache, not state a command writes: never in a record,
19
+ * never rolled back, kept after a removal so an undo that restores the record binds the same
20
+ * edges. Counters are never reissued in a session, so a seed can only ever name its own edge.
21
+ * - the ORDER high-water mark: a new set's order is one past the highest order the store has
22
+ * held, so a restored record can never share its order with a set created after it was removed.
23
+ *
24
+ * A committed group tells its listeners one {@link SetChange} per touched key, from the key's
25
+ * before and after values; a group that throws is rolled back and tells nobody.
26
+ *
27
+ * Only `session/sets/` may import this module (a static test enforces it): nothing else writes
28
+ * set state.
29
+ */
30
+ import type { SetId } from "../../catalog/types";
31
+ import { type RecordView } from "./prepare";
32
+ import type { EdgeSeeds } from "./resolve";
33
+ import type { ElementSet, SetChange } from "./types";
34
+ /** A removed set's id and last name, and its last record while anything names the id. */
35
+ interface Tombstone {
36
+ readonly id: SetId;
37
+ readonly name: string;
38
+ readonly record?: ElementSet;
39
+ }
40
+ /**
41
+ * The slice and what sits beside it, as stored: the one serialised form a project file or an undo
42
+ * slice uses (design 12, 12.4). Plain JSON once stringified: a record's `revision` is not an own
43
+ * enumerable field, a fixed set's edge members are, and unknown top-level fields are kept. Seeds
44
+ * and every derived value are left out; the order high-water mark is recovered from the records
45
+ * and the tombstones.
46
+ */
47
+ interface LogicalSets {
48
+ /** The live records, by order. */
49
+ readonly records: readonly ElementSet[];
50
+ /** Every id ever issued. */
51
+ readonly register: readonly SetId[];
52
+ /** Removed ids, oldest first, with their last name and, while anything named them, record. */
53
+ readonly tombstones: readonly Tombstone[];
54
+ }
55
+ /** The kept-set slice and the state beside it. */
56
+ export declare class SetsStore implements RecordView {
57
+ private readonly records;
58
+ private readonly issued;
59
+ private readonly tombstones;
60
+ private readonly listeners;
61
+ private readonly commitListeners;
62
+ private readonly seeds;
63
+ private highestOrder;
64
+ private group;
65
+ private listed;
66
+ /**
67
+ * One live record.
68
+ * @param id - Its id.
69
+ * @returns The record, or undefined.
70
+ */
71
+ get(id: SetId): ElementSet | undefined;
72
+ /**
73
+ * Every live record, in insertion order.
74
+ * @returns The records.
75
+ */
76
+ values(): Iterable<ElementSet>;
77
+ /**
78
+ * Every live record by order, ties by id: the same frozen array until a write.
79
+ * @returns The records.
80
+ */
81
+ list(): readonly ElementSet[];
82
+ /**
83
+ * Every id ever issued and committed.
84
+ * @returns The register.
85
+ */
86
+ register(): ReadonlySet<SetId>;
87
+ /**
88
+ * A removed id's tombstone, while the id is not live.
89
+ * @param id - The id.
90
+ * @returns The tombstone, or undefined when the id is live or was never removed.
91
+ */
92
+ tombstone(id: SetId): Tombstone | undefined;
93
+ /**
94
+ * A set's seeds.
95
+ * @param id - The set.
96
+ * @returns The seeds, or undefined when no door has seeded the set.
97
+ */
98
+ seedsOf(id: SetId): EdgeSeeds | undefined;
99
+ /**
100
+ * Record the counters edge members entered a set through, replacing earlier ones for the same
101
+ * members. Moves the seeds' version, so a binding plan built before is rebuilt.
102
+ * @param id - The set.
103
+ * @param entries - Member key and counter pairs. A Map given for a set with no seeds yet is
104
+ * adopted, not copied, so the caller must not touch it afterwards.
105
+ */
106
+ seed(id: SetId, entries: Iterable<readonly [key: string, counter: number]>): void;
107
+ /**
108
+ * Drop the kept record of every removed id nothing names any more, keeping its id and name.
109
+ * @param named - Whether anything live still names an id.
110
+ */
111
+ forget(named: (id: SetId) => boolean): void;
112
+ /**
113
+ * Mint an id for a name: `set_<slug>`, then `_2`, `_3` and on, skipping the register, the
114
+ * live ids and the ids already minted in the open group. Only inside a write group.
115
+ * @param name - The trimmed name.
116
+ * @returns The id, pending until the group commits.
117
+ */
118
+ mint(name: string): SetId;
119
+ /**
120
+ * The order a new set takes: one past the highest the store has held.
121
+ * @returns The order.
122
+ */
123
+ nextOrder(): number;
124
+ /**
125
+ * Write one record. Only inside a write group.
126
+ * @param record - A frozen record from `prepare`, or restored.
127
+ */
128
+ put(record: ElementSet): void;
129
+ /**
130
+ * Remove one record. Only inside a write group.
131
+ * @param id - Its id.
132
+ */
133
+ delete(id: SetId): void;
134
+ /**
135
+ * Run one write group: every `mint`, `put` and `delete` inside commits together, or, when
136
+ * `write` throws, none of them does. A nested call joins the open group as a savepoint: when
137
+ * it throws, its own writes and mints are undone and the group goes on.
138
+ * @param write - The writes.
139
+ * @param cause - What the listeners are told caused it, for an outermost group.
140
+ * @returns What `write` returned.
141
+ */
142
+ transact<T>(write: () => T, cause?: SetChange["cause"]): T;
143
+ /**
144
+ * The slice as stored. Internal: the one serialiser a project file or an undo slice uses.
145
+ * @returns The records, the register and the tombstones.
146
+ */
147
+ toLogicalRecords(): LogicalSets;
148
+ /**
149
+ * Load a stored slice into this empty store: every record validated in load mode and `put`,
150
+ * the register and the tombstones restored. One write group, told as `load`. Internal.
151
+ * @param stored - What {@link toLogicalRecords} returned, after any JSON round trip.
152
+ *
153
+ * A record's `createdFrom` of a kind this version does not know is kept as given and written
154
+ * back unchanged, as an unknown definition kind is (design 12.5). A tombstone whose id is also
155
+ * a live record is dropped: a tombstone speaks only for an absent id.
156
+ * @throws `E_BAD_COMMAND` for a malformed slice, record or tombstone, or two records with one
157
+ * id; an Error for a non-empty store.
158
+ */
159
+ loadLogicalRecords(stored: unknown): void;
160
+ /**
161
+ * Listen to committed changes: one call per touched key per group.
162
+ * @param listener - The listener.
163
+ * @returns A function that stops listening.
164
+ */
165
+ onChange(listener: (change: SetChange) => void): () => void;
166
+ /**
167
+ * Hear each committed group whole, before any per-key listener: the change notification
168
+ * (`./notify`) re-resolves live sets here, ahead of `set:changed`.
169
+ * @param listener - The listener, handed every change of the group.
170
+ * @returns A function that stops listening.
171
+ */
172
+ onCommit(listener: (changes: readonly SetChange[]) => void): () => void;
173
+ /**
174
+ * The open group.
175
+ * @param verb - What needs it, for the message.
176
+ * @returns The group.
177
+ * @throws An Error outside a write group.
178
+ */
179
+ private requireGroup;
180
+ /**
181
+ * Remember a key's value before the group first touched it.
182
+ * @param id - The key.
183
+ */
184
+ private touch;
185
+ /**
186
+ * Commit a group: register its ids, tombstone what it removed, tell the listeners.
187
+ * @param group - The group.
188
+ */
189
+ private commit;
190
+ /**
191
+ * Tombstone a removed record, newest last.
192
+ * @param record - The record removed.
193
+ */
194
+ private bury;
195
+ }
196
+ export {};
@@ -0,0 +1,386 @@
1
+ /**
2
+ * @file The shapes of kept sets as the session hands them out, the change a write produces, and
3
+ * the synchronous half of `session.sets` (design/sets/sets-design.md sections 4.6, 14, 15.2).
4
+ *
5
+ * `session.sets` publishes these; the definition types they name live in `catalog/types.ts`.
6
+ */
7
+ import type { EdgeId, EdgeReading, EdgeRef, NodeId, PathKind, ResultItem, RunId, ScopeInput, SetCombine, SetCreatedFrom, SetDefinition, SetDefinitionInput, SetId } from "../../catalog/types";
8
+ /**
9
+ * A kept set as the session hands it out: plain, frozen, structured-cloneable.
10
+ *
11
+ * `get` and `list` return the same frozen object until the record changes, so reference equality
12
+ * is a valid change test. The stored record is every field but `revision`, plus any top-level
13
+ * field a newer element wrote, carried through every write unchanged.
14
+ */
15
+ export interface ElementSet {
16
+ /** Element-minted, `set_` then opaque; never reissued within a project. */
17
+ readonly id: SetId;
18
+ /** Trimmed, never empty; unique among live sets at the doors. */
19
+ readonly name: string;
20
+ /** Listing position. Undoing a removal puts the set back where it was. */
21
+ readonly order: number;
22
+ /** The canonical definition. Edge members are always in stable form. */
23
+ readonly definition: SetDefinition;
24
+ /** How the set came to exist. Written once, at create. */
25
+ readonly createdFrom: SetCreatedFrom;
26
+ /**
27
+ * `r1:<hex>`, a digest of the canonical definition. Derived: computed on first read and
28
+ * memoised, never stored. Rename does not change it.
29
+ */
30
+ readonly revision: string;
31
+ }
32
+ /** One kept set's committed change. One per touched key per write. */
33
+ export interface SetChange {
34
+ /** The set that changed. */
35
+ readonly id: SetId;
36
+ /** OPEN UNION. */
37
+ readonly change: "created" | "updated" | "removed";
38
+ /** Which fields an `updated` change touched; empty otherwise. OPEN UNION. */
39
+ readonly fields: readonly ("name" | "definition" | "order")[];
40
+ /** The frozen record after the change; null after removal. */
41
+ readonly set: ElementSet | null;
42
+ /** What caused it. OPEN UNION: `command`, or `load` for a stored slice; undo and redo are added later. */
43
+ readonly cause: "command" | "load";
44
+ }
45
+ /**
46
+ * Whether a set still means what it meant, derived on read from what its definition reads and the
47
+ * last pass over it. Never resolves.
48
+ */
49
+ export interface SetStatus {
50
+ /**
51
+ * OPEN UNION: values may be added in a minor release; handle unknown values. The screen never
52
+ * says "stale". `out-of-date`: a run it reads has inputs that changed (verb "Re-run").
53
+ * `cannot-rerun`: the same, but the run's algorithm is no longer registered. `detached`: a
54
+ * referent was removed (verb "Restore"). `unresolvable`: nothing was removed, but the
55
+ * definition cannot be evaluated -- a cycle, a failed compile, a capability this element lacks
56
+ * (verbs "Edit rule" or "Update graphty-element").
57
+ */
58
+ readonly freshness: "current" | "out-of-date" | "cannot-rerun" | "detached" | "unresolvable";
59
+ /**
60
+ * Why it is not current, or why it resolves to less than its definition names. May be
61
+ * non-empty when current: render reasons whatever the freshness.
62
+ */
63
+ readonly reasons: readonly SetStatusReason[];
64
+ /**
65
+ * Runs whose held execution (in the definition or in what the set was created from) is no
66
+ * longer the run's current one: "Earlier run". Empty otherwise.
67
+ */
68
+ readonly earlierRuns: readonly RunId[];
69
+ }
70
+ /** Why a set is not current. OPEN UNION on `kind`: kinds may be added in a minor release. */
71
+ export type SetStatusReason = {
72
+ readonly kind: "run-out-of-date";
73
+ readonly run: RunId;
74
+ } | {
75
+ readonly kind: "missing-run";
76
+ readonly run: RunId;
77
+ } | {
78
+ readonly kind: "missing-set";
79
+ readonly id: SetId;
80
+ readonly name: string;
81
+ } | {
82
+ readonly kind: "cycle";
83
+ readonly through: readonly string[];
84
+ }
85
+ /** `name` is a kind, field or algorithm; a plugin's is spelled `<package>:<kind>`, naming what to install. */
86
+ | {
87
+ readonly kind: "missing-capability";
88
+ readonly name: string;
89
+ }
90
+ /** A held execution's values were not kept: the set resolves to nothing. */
91
+ | {
92
+ readonly kind: "values-not-kept";
93
+ readonly run: RunId;
94
+ }
95
+ /** Edge members more than one edge carries, which bind neither. */
96
+ | {
97
+ readonly kind: "ambiguous-parallel-edge";
98
+ readonly count: number;
99
+ } | {
100
+ readonly kind: "invalid";
101
+ readonly message: string;
102
+ }
103
+ /** A run recorded a revision of another scheme version; its freshness is unknown until re-run. */
104
+ | {
105
+ readonly kind: "revision-unknown";
106
+ readonly run: RunId;
107
+ }
108
+ /** A set this one reads is not current. */
109
+ | {
110
+ readonly kind: "input";
111
+ readonly id: SetId;
112
+ readonly freshness: Exclude<SetStatus["freshness"], "current">;
113
+ };
114
+ /**
115
+ * One thing that names a set: "Used by". OPEN UNION on `kind`: kinds may be added in a minor
116
+ * release; render `label` for a kind you do not know.
117
+ */
118
+ export interface SetUser {
119
+ /** What kind of thing names the set. OPEN UNION. */
120
+ readonly kind: "set" | "layer" | "filter" | "layout" | "run";
121
+ /** Its id: a set id, a layer id, a run id or a layout type. Absent for the visibility filter. */
122
+ readonly id?: string;
123
+ /** What to show for it: a layer's or set's name, "Visibility filter", "Layout (ngraph)". */
124
+ readonly label: string;
125
+ }
126
+ /**
127
+ * A set a finished run's result offers: community 3, level 2, the path. Using it as a scope,
128
+ * `{ define: offer.definition }`, writes nothing; `createFrom` or `createPath` keeps it.
129
+ *
130
+ * Offers come from the result's shape, never from the algorithm, so a registered algorithm's
131
+ * result offers what a built-in one of the same shape does.
132
+ */
133
+ export interface SetOffer {
134
+ /** The item, with the execution it was read from. */
135
+ readonly item: ResultItem;
136
+ /** "Community 3 (1,204 nodes)", "On path", "Level 2". */
137
+ readonly label: string;
138
+ /**
139
+ * How many nodes it holds. Present for an offer read `induced`, counted from the result's own
140
+ * values. For an offer read `listed` (an edge set, a path), whose nodes include its edges'
141
+ * endpoints, filled only once the edge-count pass is cached.
142
+ */
143
+ readonly nodes?: number;
144
+ /** Filled only when this execution's edge-count pass is already cached; `offers` never runs it. */
145
+ readonly edges?: number;
146
+ /** Which edges come with its nodes: `induced` for a group, `listed` for an edge set or a path. */
147
+ readonly reading: EdgeReading;
148
+ /** A path offer: `createPath` accepts it and keeps its order. */
149
+ readonly path: boolean;
150
+ /** The item may be followed across re-runs (not a partition group). */
151
+ readonly followable: boolean;
152
+ /** Usable at once as a scope, `{ define: offer.definition }`: a rule over the one held item. */
153
+ readonly definition: SetDefinition;
154
+ }
155
+ /** What holds one element: the inspector's "Memberships". OPEN: may gain members in a minor release. */
156
+ export interface Memberships {
157
+ /** Kept sets holding the element, in listing order. */
158
+ readonly sets: readonly SetId[];
159
+ /** The partition items holding it: "Louvain: community 4 of 212". */
160
+ readonly items: readonly {
161
+ /** The item, with the execution it was read from. */
162
+ readonly item: ResultItem;
163
+ /** "Louvain: community 4". */
164
+ readonly label: string;
165
+ /** How many items the result's partition has. */
166
+ readonly of: number;
167
+ }[];
168
+ }
169
+ /** Members to add to or remove from a fixed set. Edges by session id or stable identity. Internal name. */
170
+ export interface SetMemberDelta {
171
+ readonly nodes?: readonly NodeId[];
172
+ readonly edges?: readonly EdgeRef[];
173
+ }
174
+ /**
175
+ * Kept sets: the reads that only look at records and the writes that resolve nothing. Every write
176
+ * is one operation (`set.create`, `set.rename`, `set.redefine`, `set.members`, `set.remove`) and
177
+ * a no-op records and emits nothing.
178
+ */
179
+ export interface SetsApi {
180
+ /**
181
+ * Every kept set, by `order`, ties by id. The same frozen objects until a record changes.
182
+ * @returns The sets.
183
+ */
184
+ list(): readonly ElementSet[];
185
+ /**
186
+ * One kept set.
187
+ * @param id - Its id.
188
+ * @returns The record, or undefined when no live set has that id.
189
+ */
190
+ get(id: SetId): ElementSet | undefined;
191
+ /**
192
+ * Whether a set, or any scope, still means what it meant: from what it reads and the last pass
193
+ * over it. Never resolves, so a panel may call it for every row.
194
+ * @param ref - The set, as `{ set: id }`, or any scope.
195
+ * @returns The status.
196
+ * @throws `E_BAD_COMMAND` for a malformed scope or an id that was never issued.
197
+ */
198
+ status(ref: ScopeInput): SetStatus;
199
+ /**
200
+ * A path set's kind. Derived from its definition; never resolves.
201
+ * @param id - The set.
202
+ * @returns The kind, or undefined for a set that is not a path or not live.
203
+ */
204
+ pathKind(id: SetId): PathKind | undefined;
205
+ /**
206
+ * What names a set: the kept sets whose definitions name it and the runs whose scope names it.
207
+ * @param id - The set.
208
+ * @returns The users, sets first, each group in listing order.
209
+ */
210
+ usedBy(id: SetId): readonly SetUser[];
211
+ /**
212
+ * The sets a finished run's result offers, largest first, from its shape: one per group of a
213
+ * partition (a components run's first is the largest component), one per level, one per
214
+ * category, one for a node or edge set, one for a path. Metrics, temporal results and
215
+ * candidate pairs offer none. Never resolves and never runs the edge-count pass.
216
+ * @param run - The run.
217
+ * @param options - How many to return.
218
+ * @param options.limit - The most offers returned; 100 by default.
219
+ * @returns The largest `limit` offers and how many were left out.
220
+ * @throws `E_UNKNOWN_RUN` for a run this session does not hold; `E_BAD_COMMAND` for a limit that
221
+ * is not a whole number of at least 0.
222
+ */
223
+ offers(run: RunId, options?: {
224
+ readonly limit?: number;
225
+ }): {
226
+ /** The largest `limit` offers, largest first. */
227
+ readonly offers: readonly SetOffer[];
228
+ /** How many offers were left out. */
229
+ readonly more: number;
230
+ };
231
+ /**
232
+ * What holds one element: the kept sets, and the partition items of every finished run. A
233
+ * cached resolution is tested when present; else a fixed set of nodes alone is a binary
234
+ * search of them, and a rule whose leaves are all element-local is tested at this element.
235
+ * Anything else is resolved once and cached.
236
+ * @param element - The node or edge.
237
+ * @param element.node - A node id.
238
+ * @param element.edge - A session edge id.
239
+ * @returns The memberships.
240
+ * @throws `E_BAD_COMMAND` for an element the graph does not hold.
241
+ */
242
+ containing(element: {
243
+ readonly node: NodeId;
244
+ } | {
245
+ readonly edge: EdgeId;
246
+ }): Promise<Memberships>;
247
+ /**
248
+ * Keep a definition as given; created from `user`. Edge members may be given as session edge
249
+ * ids and are stored in stable form.
250
+ * @param definition - The definition.
251
+ * @param options - How to keep it.
252
+ * @param options.name - The name; "Set N" (the smallest free N) when absent. At most 256
253
+ * characters, because the id is minted from it.
254
+ * @returns The minted id.
255
+ */
256
+ create(definition: SetDefinitionInput, options?: {
257
+ readonly name?: string;
258
+ }): SetId;
259
+ /**
260
+ * Create set: keep a scope's current members as a fixed set, created from `selection` or from
261
+ * the scope. Resolves first, then mints the id and names the set in one step, so two calls in
262
+ * flight never share an id: the second with a taken name is refused `E_DUPLICATE_ID`.
263
+ *
264
+ * The reading, unless `options.reading` says otherwise: a selection holding nodes keeps the
265
+ * selected nodes and edges and reads `induced`; a selection of edges alone reads `listed`;
266
+ * any other scope keeps the reading it resolves with, and `clipped` (such as `"visible"`)
267
+ * freezes to `listed`, which holds the same members. A defaulted `listed` result whose edges
268
+ * are exactly those its nodes induce is stored `induced` with no edges, so it GAINS an edge
269
+ * added later between two of its members; an explicit `listed` never does.
270
+ * `"largest-component"` stores its nodes alone.
271
+ *
272
+ * An offer keeps its own reading and is created from `result`, holding its execution. With
273
+ * `follow`, it is kept instead as a rule over the item without the execution, so it follows
274
+ * the run's re-runs; a partition group cannot be followed, because a group number means
275
+ * nothing in another run.
276
+ *
277
+ * The members are read when the asynchronous step resolves the source, not when the call is
278
+ * made: a set the source names that is redefined synchronously after this call is frozen as
279
+ * redefined. Await the call before changing what it reads to freeze the membership as it was.
280
+ * @param source - The scope; `"selection"` for the current selection with its edges; or an offer.
281
+ * @param options - How to keep it.
282
+ * @param options.name - The name; "Set N" (the smallest free N) when absent.
283
+ * @param options.reading - The reading to store instead of the default.
284
+ * @param options.follow - Keep an offer as a rule that follows its run.
285
+ * @returns The minted id.
286
+ * @throws `E_SCOPE_EMPTY` when the source holds nothing; `E_BAD_COMMAND` for a malformed scope,
287
+ * an unknown set or a bad reading; `E_DUPLICATE_ID` for a taken name; `E_BAD_COMMAND` with
288
+ * `details.reason: "stale-offer"` for an offer whose execution is no longer its run's current
289
+ * one, checked before resolving and again at commit, and `"follow-group"` for following a
290
+ * partition group.
291
+ */
292
+ createFrom(source: ScopeInput | SetOffer, options?: {
293
+ readonly name?: string;
294
+ readonly reading?: EdgeReading;
295
+ readonly follow?: boolean;
296
+ }): Promise<SetId>;
297
+ /**
298
+ * Create path: order the selected edges into a walk, created from `selection`. Parallel and
299
+ * reciprocal edges between one pair become one step. The walk starts at the end from which
300
+ * every step follows a declared edge direction when only one end allows that, else at the end
301
+ * whose id sorts first. One selected node and no edges is a zero-length path.
302
+ *
303
+ * A path offer is kept in its result's `order`, each step naming the on-path edges between its
304
+ * pair, created from `result`; a stale one is refused as `createFrom` refuses it.
305
+ * @param source - `"selection"`, or a path offer.
306
+ * @param options - How to keep it.
307
+ * @param options.name - The name; "Set N" when absent.
308
+ * @returns The minted id.
309
+ * @throws `E_BAD_COMMAND` with `details.reason: "ambiguous-path"` and `details.why` (`no-edges`,
310
+ * `self-loop`, `branch`, `cycle`, `disconnected`, `off-path-nodes`) when the selection is not
311
+ * one open chain.
312
+ */
313
+ createPath(source: SetOffer | "selection", options?: {
314
+ readonly name?: string;
315
+ }): Promise<SetId>;
316
+ /**
317
+ * Combine two or more sets into one fixed set of their current members, created from
318
+ * `combine`. `difference` is the first minus the union of the rest; `symmetric-difference`
319
+ * keeps what an odd number of them hold. Every operand read `induced` gives an induced result;
320
+ * otherwise edges are combined first and the result keeps their endpoints, so "edges in the
321
+ * Kruskal tree but not the Prim tree" keeps the differing edges and the nodes they join. An
322
+ * empty result is kept.
323
+ * @param op - The combination.
324
+ * @param of - Two or more scopes.
325
+ * @param options - How to keep it.
326
+ * @param options.name - The name; "Set N" when absent.
327
+ * @param options.reading - The reading to store instead of the default.
328
+ * @returns The minted id.
329
+ */
330
+ combine(op: SetCombine, of: readonly ScopeInput[], options?: {
331
+ readonly name?: string;
332
+ readonly reading?: EdgeReading;
333
+ }): Promise<SetId>;
334
+ /**
335
+ * Rename a set. Keeps its id and its revision.
336
+ * @param id - The set.
337
+ * @param name - The new name, trimmed; unique among live sets.
338
+ */
339
+ rename(id: SetId, name: string): void;
340
+ /**
341
+ * Replace a set's definition.
342
+ * @param id - The set.
343
+ * @param definition - The new definition.
344
+ */
345
+ redefine(id: SetId, definition: SetDefinitionInput): void;
346
+ /**
347
+ * Add members to a fixed set.
348
+ * @param id - The set.
349
+ * @param members - The nodes and edges to add.
350
+ * @param members.nodes - The node ids.
351
+ * @param members.edges - The edges, by session id or stable identity.
352
+ */
353
+ addMembers(id: SetId, members: {
354
+ readonly nodes?: readonly NodeId[];
355
+ readonly edges?: readonly EdgeRef[];
356
+ }): void;
357
+ /**
358
+ * Remove members from a fixed set. Removing a node also removes its incident edge members.
359
+ * @param id - The set.
360
+ * @param members - The nodes and edges to remove.
361
+ * @param members.nodes - The node ids.
362
+ * @param members.edges - The edges, by session id or stable identity.
363
+ */
364
+ removeMembers(id: SetId, members: {
365
+ readonly nodes?: readonly NodeId[];
366
+ readonly edges?: readonly EdgeRef[];
367
+ }): void;
368
+ /**
369
+ * Remove the set itself. Anything that names it becomes detached, and keeps working: a style
370
+ * layer, filter or rule that names a removed set reads it from the set's kept record, so
371
+ * removing a set never blanks a layer or changes what a filter shows. New work over a removed
372
+ * set -- a run, an explicit layout scope -- is refused. The record is kept while anything
373
+ * names the set, and dropped once nothing does.
374
+ * @param id - The set.
375
+ */
376
+ remove(id: SetId): void;
377
+ /**
378
+ * Bring a removed set back from its kept record, under the same id, name and definition.
379
+ * Tells one `set:changed` with change `"created"`.
380
+ * @param id - The removed set.
381
+ * @throws `E_BAD_COMMAND` when the id names a live set (`details.reason: "live"`), was never
382
+ * issued (`"unknown-id"`), or its record was dropped because nothing named it any more
383
+ * (`"record-dropped"`).
384
+ */
385
+ restore(id: SetId): void;
386
+ }