@graphty/graphty-element 2.5.2 → 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,209 @@
1
+ /**
2
+ * @file The five set operations as pure functions over the current records (design/sets/sets-design.md
3
+ * sections 4.6, 12.5, 13.2).
4
+ *
5
+ * Each `prepare*` takes the records and one concrete command -- everything minted (id, order) and
6
+ * everything resolved (stable edge members) already in it -- and returns the record to write, or
7
+ * null for a no-op. It validates, clones, canonicalises and deep-freezes, and carries any top-level
8
+ * record field it does not know through unchanged. It never writes: the store does, so a future
9
+ * command dispatcher can call the same functions and record their output.
10
+ *
11
+ * Also here, because every record is built here: the compact form of a fixed set's edge members
12
+ * (typed arrays over an interned id table, materialised as `definition.edges` on first read), the
13
+ * member summaries a member delta updates in O(delta), and the memoised revision.
14
+ *
15
+ * Pure and Node-safe.
16
+ */
17
+ import type { EdgeMember, NodeId, SetCreatedFrom, SetDefinition, SetId } from "../../catalog/types";
18
+ import type { ElementSet } from "./types";
19
+ /**
20
+ * The most edge members a member edit may touch. A step of undo history keeps the prior and next
21
+ * record whole, about 24 bytes per edge member, so edits above this wait for a per-member op log.
22
+ */
23
+ export declare const MAX_EDGE_MEMBER_EDIT = 1000000;
24
+ /**
25
+ * Invocation counts the complexity tests read (design/sets plan 1.4). Internal; never reset here.
26
+ * - `interns`: ids looked up in or added to an edge-column id table, three or fewer a member.
27
+ */
28
+ export declare const prepareCounters: {
29
+ interns: number;
30
+ };
31
+ /** What the prepare functions read: the live records. */
32
+ export interface RecordView {
33
+ /**
34
+ * One live record.
35
+ * @param id - Its id.
36
+ * @returns The record, or undefined.
37
+ */
38
+ get(id: SetId): ElementSet | undefined;
39
+ /**
40
+ * Every live record, in any order.
41
+ * @returns The records.
42
+ */
43
+ values(): Iterable<ElementSet>;
44
+ }
45
+ /**
46
+ * The name the element picks when none is given: "Set N" for the smallest free N.
47
+ * @param records - The records.
48
+ * @returns The name.
49
+ */
50
+ export declare function defaultName(records: RecordView): string;
51
+ /**
52
+ * Edge members read one at a time, without materialising them all: an array, or a fixed set's
53
+ * compact columns, which build each member only when it is read. Internal.
54
+ */
55
+ export interface EdgeMemberList {
56
+ readonly length: number;
57
+ /**
58
+ * One member.
59
+ * @param index - Its position.
60
+ * @returns The member, or undefined past the end.
61
+ */
62
+ at(index: number): EdgeMember | undefined;
63
+ }
64
+ /**
65
+ * The first kind or field of a definition this element does not know, or null. A definition a
66
+ * door built is known to be null; any other (a restored one) is checked once and remembered.
67
+ * @param definition - The definition.
68
+ * @returns The name, or null.
69
+ */
70
+ export declare function opaqueName(definition: SetDefinition): string | null;
71
+ /**
72
+ * A listed fixed definition built from members the element read off a snapshot, canonical and
73
+ * frozen in the compact column form. The work a caller's definition needs at the synchronous
74
+ * commit (validating, canonicalising, sorting, interning) happens here instead, so a materialising
75
+ * door does it in its asynchronous step. Internal.
76
+ * @param nodes - Node ids, any order.
77
+ * @param members - Stable edge members with their ends already canonical, any order.
78
+ * @returns The frozen definition, which `set.create` stores as it is.
79
+ */
80
+ export declare function prebuiltListed(nodes: readonly NodeId[], members: readonly EdgeMember[]): SetDefinition;
81
+ /**
82
+ * Whether a value is a definition {@link prebuiltListed} built. Internal.
83
+ * @param definition - The value.
84
+ * @returns True when it is.
85
+ */
86
+ export declare function isPrebuilt(definition: unknown): definition is SetDefinition;
87
+ /**
88
+ * A record restored from stored state (a file, an undo step): validated in load mode, so an
89
+ * unknown kind or field is kept and the definition is opaque. Unknown top-level fields are kept.
90
+ * @param value - The stored record `{ id, name, order, definition, createdFrom, ... }`.
91
+ * @returns The frozen record, ready for the store's `put`.
92
+ * @throws `E_BAD_COMMAND` for a record missing a field or holding a malformed known node.
93
+ */
94
+ export declare function loadRecord(value: unknown): ElementSet;
95
+ /** `set.create`, concrete: everything minted and resolved. */
96
+ interface CreateCommand {
97
+ readonly id: SetId;
98
+ readonly name: string;
99
+ readonly order: number;
100
+ /** Edge members in stable form. */
101
+ readonly definition: unknown;
102
+ readonly createdFrom: SetCreatedFrom;
103
+ }
104
+ /**
105
+ * `set.create`.
106
+ * @param records - The records.
107
+ * @param command - The concrete command.
108
+ * @returns The new record.
109
+ * @throws `E_BAD_COMMAND` for a bad name, a live id or a malformed definition; `E_DUPLICATE_ID`
110
+ * for a taken name.
111
+ */
112
+ export declare function prepareCreate(records: RecordView, command: CreateCommand): ElementSet;
113
+ /**
114
+ * `set.rename`. Keeps the id, the definition (so the revision) and every unknown field.
115
+ * @param records - The records.
116
+ * @param command - The set and its new name.
117
+ * @param command.id - The set.
118
+ * @param command.name - The new name.
119
+ * @returns The new record, or null when the trimmed name is the current one.
120
+ * @throws `E_BAD_COMMAND` for an unknown id or an empty name; `E_DUPLICATE_ID` for a taken name.
121
+ */
122
+ export declare function prepareRename(records: RecordView, command: {
123
+ readonly id: SetId;
124
+ readonly name: string;
125
+ }): ElementSet | null;
126
+ /**
127
+ * `set.redefine`. A redefine that changes only a fixed set's reading shares the prior member
128
+ * arrays, so history copies nothing.
129
+ * @param records - The records.
130
+ * @param command - The set and its new definition, edge members stable.
131
+ * @param command.id - The set.
132
+ * @param command.definition - The new definition.
133
+ * @returns The new record, or null when the canonical definition is unchanged.
134
+ * @throws `E_BAD_COMMAND` for an unknown id or a malformed definition; `E_UNSUPPORTED` for an
135
+ * opaque prior definition.
136
+ */
137
+ export declare function prepareRedefine(records: RecordView, command: {
138
+ readonly id: SetId;
139
+ readonly definition: unknown;
140
+ }): ElementSet | null;
141
+ /** `set.members`, concrete: members in stable form. */
142
+ interface MembersCommand {
143
+ readonly id: SetId;
144
+ readonly add?: {
145
+ readonly nodes?: readonly NodeId[];
146
+ readonly edges?: readonly EdgeMember[];
147
+ };
148
+ readonly remove?: {
149
+ readonly nodes?: readonly NodeId[];
150
+ readonly edges?: readonly EdgeMember[];
151
+ };
152
+ }
153
+ /**
154
+ * `set.members`: remove, then add. Fixed sets only. Removing a node also removes every edge
155
+ * member incident to it. The revision's member sums move by exactly the members that changed.
156
+ * @param records - The records.
157
+ * @param command - The set and its delta.
158
+ * @param limit - The most edge members an edit may touch.
159
+ * @returns The new record, or null when every added member was present and every removed one absent.
160
+ * @throws `E_BAD_COMMAND` for an unknown id, a set that is not fixed or a malformed member;
161
+ * `E_UNSUPPORTED` for opaque content; `E_TOO_LARGE` above the edge-member limit.
162
+ */
163
+ export declare function prepareMembers(records: RecordView, command: MembersCommand, limit?: number): ElementSet | null;
164
+ /**
165
+ * `set.remove`: checks the set exists.
166
+ * @param records - The records.
167
+ * @param command - The set.
168
+ * @param command.id - Its id.
169
+ * @returns The id to delete.
170
+ * @throws `E_BAD_COMMAND` for an unknown id.
171
+ */
172
+ export declare function prepareRemove(records: RecordView, command: {
173
+ readonly id: SetId;
174
+ }): SetId;
175
+ /**
176
+ * A fixed definition's listed edge members, read through its compact columns when it has them, so
177
+ * a resolution never materialises `definition.edges`.
178
+ * @param definition - A fixed definition.
179
+ * @returns The members.
180
+ */
181
+ export declare function listedEdgesOf(definition: Extract<SetDefinition, {
182
+ kind: "fixed";
183
+ }>): EdgeMemberList;
184
+ /**
185
+ * Door-mode edge members in the compact column form a fixed set holds them in: about 20 bytes a
186
+ * member plus the interned ids, instead of an object each.
187
+ * @param members - Members with an id, or an ordinal with among.
188
+ * @returns The members, and the bytes they hold by the columns' accounting.
189
+ */
190
+ export declare function compactEdgeMembers(members: readonly EdgeMember[]): EdgeMemberList & {
191
+ readonly bytes: number;
192
+ };
193
+ /**
194
+ * A record's size by this module's own accounting, which the scale tests hold to a budget: 64 bytes of
195
+ * fields plus two a name character, 8 a node member plus the edge columns for a fixed set, two a
196
+ * JSON character of the definition for anything else.
197
+ * @param record - The record.
198
+ * @returns The byte count.
199
+ */
200
+ export declare function recordBytes(record: ElementSet): number;
201
+ /**
202
+ * Whether a definition holds an edge member: a binary search over a fixed set's edge columns, a
203
+ * scan of anything else's edges (a path's steps, a restored fixed set).
204
+ * @param definition - The definition.
205
+ * @param member - A canonical member.
206
+ * @returns True when some edge member equals it.
207
+ */
208
+ export declare function holdsEdgeMember(definition: SetDefinition, member: EdgeMember): boolean;
209
+ export {};
@@ -0,0 +1,311 @@
1
+ /**
2
+ * @file Synchronous bitmap resolution of every `Scope` form and of fixed definitions, and the
3
+ * edge-member binding a listed set and a path share (design/sets/sets-design.md sections 4.1,
4
+ * 4.2, 6.1, 6.3, 6.4 and 12.3).
5
+ *
6
+ * A resolution is two packed bitmaps in graph-format's mask layout, one over the context
7
+ * snapshot's nodes and one over its edges, tagged with the snapshot serial and the store it was
8
+ * resolved against. It is synchronous because the style and visibility passes need an answer
9
+ * inside the pass; the doors that resolve asynchronously wrap it.
10
+ *
11
+ * Every resolution satisfies the ENDPOINT INVARIANT: an edge bit is set only when both of its
12
+ * endpoints' node bits are. Readings are applied once, at the root: a chain of saved scopes
13
+ * resolves to a node half (plus the visible scope's edge constraint), and the root derives the
14
+ * edges from it.
15
+ *
16
+ * Nothing here reaches Babylon.js, Lit or the DOM.
17
+ */
18
+ import { type GraphSnapshot, type U32 } from "@graphty/graph-format";
19
+ import type { EdgeId, EdgeMember, NodeId, Path, Query, RunId, Scope, ScopeId, SetDefinition, SetId } from "../../catalog/types";
20
+ import { GraphtyError } from "../../errors";
21
+ import type { AttributeRevisions, InputTick } from "../attributes";
22
+ import type { ElementMask } from "../scope/ElementMask";
23
+ import { type CompiledHalves, type FilterSources, type FilterValueSource, type ScopeLeaf } from "../visibility/filter";
24
+ import type { SetsCache } from "./cache";
25
+ import { type EdgeMemberList } from "./prepare";
26
+ /**
27
+ * Invocation counts the complexity tests read (design/sets plan 1.4). Internal; never reset here.
28
+ * - `edgePasses`: full passes over the edge list; `edgeRowVisits`: edge rows those passes read.
29
+ * - `maskPacks`: byte masks packed into bitmaps.
30
+ * - `digestSums`: masked sums over the hash columns.
31
+ * - `idSetBuilds`: id `Set`s materialised from a bitmap.
32
+ */
33
+ export declare const resolveCounters: {
34
+ edgePasses: number;
35
+ edgeRowVisits: number;
36
+ maskPacks: number;
37
+ digestSums: number;
38
+ idSetBuilds: number;
39
+ /** Binding plans built: one per definition and seed version. */
40
+ bindingPlans: number;
41
+ /** Edge-id column scans that merged against the sorted seeded counters. */
42
+ bindMerges: number;
43
+ /** Edge-id column scans that binary-searched them, because the column was not monotonic. */
44
+ bindSearches: number;
45
+ /** Edge passes matching unseeded members by stable identity. */
46
+ identityPasses: number;
47
+ };
48
+ /** One resolution: what a scope or a definition covers in one snapshot. */
49
+ export interface Resolution {
50
+ /** Node bitmap over the context snapshot's nodes. */
51
+ readonly nodes: U32;
52
+ /** Edge bitmap over the context snapshot's edges. Every set edge has both endpoints set. */
53
+ readonly edges: U32;
54
+ /** How many node bits are set. */
55
+ readonly nodeCount: number;
56
+ /** How many edge bits are set. */
57
+ readonly edgeCount: number;
58
+ /** The serial of the snapshot this was resolved against. */
59
+ readonly serial: number;
60
+ /** The store instance this was resolved against, or null when the context named none. */
61
+ readonly store: object | null;
62
+ /** Named node ids the graph does not hold, one per unresolved entry. */
63
+ readonly missingNodes: number;
64
+ /**
65
+ * Named edge members no edge matches; for a path, the steps none of whose edges are there.
66
+ */
67
+ readonly missingEdges: number;
68
+ /**
69
+ * Of the unmatched edge members, those more than one edge carries (`ambiguous-parallel-edge`):
70
+ * two loads gave two edges the same pair, ordinal and among, and neither is bound.
71
+ */
72
+ readonly ambiguousEdges: number;
73
+ /**
74
+ * Why this resolution is empty when its definition could not be evaluated (a cycle, a missing
75
+ * referent, a capability the session lacks). Only a quiet resolution carries one; a door throws
76
+ * the same error instead.
77
+ */
78
+ readonly problem?: GraphtyError;
79
+ }
80
+ /** Which connected component each node belongs to. */
81
+ export interface ComponentLabels {
82
+ /** One component number per dense node index. */
83
+ readonly labels: ArrayLike<number>;
84
+ /** How many components there are, so the labels are `[0, count)`. */
85
+ readonly count: number;
86
+ }
87
+ /** Everything a resolution reads that it does not compute. */
88
+ export interface ResolveContext {
89
+ /** The context snapshot: the full graph today; a rule's future `scope` evaluates here. */
90
+ readonly snapshot: GraphSnapshot;
91
+ /** The node id map; the snapshot's own unless a caller (a counting test) wraps it. */
92
+ readonly ids?: {
93
+ indexOf(id: NodeId): number;
94
+ };
95
+ /** The store instance the resolution is tagged with. */
96
+ readonly store?: object | null;
97
+ /** What is visible. Absent means nothing hides anything. */
98
+ readonly visibility?: {
99
+ nodes(): ElementMask<NodeId>;
100
+ edges(): ElementMask<EdgeId>;
101
+ };
102
+ /** What is selected. Absent refuses `"selection"`. */
103
+ readonly selection?: {
104
+ nodes(): ElementMask<NodeId>;
105
+ };
106
+ /** The connected components. Absent refuses `"largest-component"`. */
107
+ readonly components?: () => ComponentLabels;
108
+ /** The nodes a predicate matches. Absent refuses `{ where }`. */
109
+ readonly match?: (where: Query) => Iterable<NodeId>;
110
+ /** The edges a predicate matches. Absent refuses a rule's `edges` leaf. */
111
+ readonly matchEdges?: (where: Query) => Iterable<EdgeId>;
112
+ /** Attribute values. Absent refuses a rule's `range` and `categories` leaves. */
113
+ readonly values?: FilterValueSource;
114
+ /** A run's current result. Absent refuses a rule's `item` leaf and a `threshold` over `results.*`. */
115
+ readonly result?: FilterSources["result"];
116
+ /** What a held item's re-run captured (`./captures`). Absent: nothing was captured. */
117
+ readonly captured?: FilterSources["captured"];
118
+ /**
119
+ * The saved scopes `{ set }` names. Absent: no scope is saved. Replaced, never mutated, on
120
+ * every write, so its identity says whether it moved.
121
+ */
122
+ readonly saved?: ReadonlyMap<ScopeId, {
123
+ readonly spec: Scope;
124
+ }>;
125
+ /** The kept sets, and the seeds their edge members bind through. */
126
+ readonly sets?: {
127
+ list(): readonly unknown[];
128
+ get(id: SetId): unknown;
129
+ seedsOf(id: SetId): EdgeSeeds | undefined;
130
+ /**
131
+ * A removed id's tombstone: the name it had, and its record while anything names it, which
132
+ * a reference to the removed set resolves through.
133
+ */
134
+ tombstone?(id: SetId): {
135
+ readonly name: string;
136
+ readonly record?: {
137
+ readonly definition: SetDefinition;
138
+ };
139
+ } | undefined;
140
+ };
141
+ /**
142
+ * The paths a query's compiled expression reads.
143
+ * @param where - The query.
144
+ * @returns The paths.
145
+ */
146
+ readonly pathsOf?: (where: Query) => readonly Path[];
147
+ /** The node attribute revisions. */
148
+ readonly revisions?: AttributeRevisions;
149
+ /** The edge attribute revisions, which a rule's `edges` leaf is keyed on. */
150
+ readonly edgeRevisions?: AttributeRevisions;
151
+ /**
152
+ * The token of a run's current result, or undefined when it has none.
153
+ * @param run - The run.
154
+ * @returns The token.
155
+ */
156
+ readonly executionOf?: (run: RunId) => string | undefined;
157
+ /** The session input tick, which scopes the signature memo. Absent: nothing is memoised. */
158
+ readonly tick?: InputTick;
159
+ /** The resolution cache. Absent: every resolution is computed. */
160
+ readonly cache?: SetsCache;
161
+ /**
162
+ * Which halves carry a value path. Absent: an `item` or `threshold` leaf is not known to
163
+ * speak edges.
164
+ * @param path - The path.
165
+ * @returns `"node"`, `"edge"`, or both.
166
+ */
167
+ readonly fieldKinds?: (path: Path) => readonly string[];
168
+ }
169
+ /** The node half of a resolution, before the root applies the reading. */
170
+ export interface NodeHalf {
171
+ /** The node bitmap. */
172
+ readonly nodes: U32;
173
+ /** The edges the specification allows beyond the induced rule (the visible edges), or null. */
174
+ readonly constraint: U32 | null;
175
+ /** True when the node half is every node and there is no constraint: every edge is in. */
176
+ readonly all: boolean;
177
+ /** Unresolved node entries. */
178
+ readonly missingNodes: number;
179
+ }
180
+ /**
181
+ * The node half of one `Scope`, following saved scopes to what they hold.
182
+ * @param scope - The specification.
183
+ * @param context - What the resolution reads.
184
+ * @param seen - The saved ids already followed, which is how a cycle is caught.
185
+ * @returns The node half.
186
+ * @throws A `GraphtyError` when the specification needs a capability the context lacks, names an
187
+ * unknown saved scope, or a ring of saved scopes.
188
+ */
189
+ export declare function resolveNodeHalf(scope: Scope, context: ResolveContext, seen?: Set<ScopeId>): NodeHalf;
190
+ /**
191
+ * Resolve without throwing: a definition that cannot be evaluated resolves to nothing, carrying
192
+ * the refusal as its `problem`. What a pass (the visibility filter, a kept set counted in a panel)
193
+ * uses, because inside a pass nothing throws.
194
+ * @param resolve - The resolution to attempt.
195
+ * @param context - What the resolution reads.
196
+ * @returns The resolution, or an empty one with its problem.
197
+ */
198
+ export declare function resolveQuietly(resolve: () => Resolution, context: ResolveContext): Resolution;
199
+ /**
200
+ * What a `member` leaf speaks: the referenced set's nodes, and its edges when its reading is
201
+ * `listed` or `clipped`.
202
+ * @param scope - The referenced set.
203
+ * @param context - What the resolution reads.
204
+ * @param seen - The sets followed so far.
205
+ * @returns The leaf.
206
+ * @throws A `GraphtyError` as the scope's resolution does.
207
+ */
208
+ export declare function scopeLeafIn(scope: Scope, context: ResolveContext, seen?: readonly SetId[]): ScopeLeaf;
209
+ /**
210
+ * A rule's compiled halves, before the reading is applied: a node test and an edge test by dense
211
+ * index, null where the tree is silent.
212
+ * @param definition - A canonical rule.
213
+ * @param context - What the tests read.
214
+ * @param seen - The sets followed so far.
215
+ * @returns The halves.
216
+ * @throws A `GraphtyError` when a leaf needs a capability the context lacks.
217
+ */
218
+ export declare function ruleHalves(definition: Extract<SetDefinition, {
219
+ kind: "rule";
220
+ }>, context: ResolveContext, seen?: readonly SetId[]): CompiledHalves;
221
+ /**
222
+ * What a definition covers. Opaque content resolves to nothing (design 12.5).
223
+ * @param definition - A canonical definition.
224
+ * @param context - What the resolution reads.
225
+ * @param seen - The kept sets followed so far, this one last when it is kept.
226
+ * @param id - The kept set, whose seeds its edge members bind through; absent for an inline one.
227
+ * @returns The resolution.
228
+ * @throws A `GraphtyError` when a rule cannot be evaluated: a cycle, a missing referent, a
229
+ * capability the context lacks.
230
+ */
231
+ export declare function resolveDefinitionIn(definition: SetDefinition, context: ResolveContext, seen?: readonly SetId[], id?: SetId): Resolution;
232
+ /**
233
+ * The induced (or, with a constraint, clipped) edges of a node half: one pass over the edge list.
234
+ * @param half - The node half.
235
+ * @param snapshot - The context snapshot.
236
+ * @returns The edge bitmap.
237
+ */
238
+ export declare function deriveEdges(half: NodeHalf, snapshot: GraphSnapshot): U32;
239
+ /**
240
+ * Dress a node half and its edges as a resolution.
241
+ * @param half - The node half.
242
+ * @param edges - The edge bitmap.
243
+ * @param context - What was resolved against.
244
+ * @param missingEdges - Unmatched edge members.
245
+ * @param ambiguousEdges - Of those, the ones more than one edge carries.
246
+ * @returns The resolution.
247
+ */
248
+ export declare function resolutionOf(half: NodeHalf, edges: U32, context: ResolveContext, missingEdges: number, ambiguousEdges?: number): Resolution;
249
+ /**
250
+ * What one `Scope` covers, synchronously. Its edges are the ones with both endpoints in its
251
+ * nodes, narrowed by the visible edges for `"visible"` (the clipped reading). Served from
252
+ * `context.cache` while the scope's input signature holds.
253
+ * @param scope - The specification.
254
+ * @param context - What the resolution reads.
255
+ * @returns The resolution.
256
+ * @throws A `GraphtyError` as {@link resolveNodeHalf} does.
257
+ */
258
+ export declare function resolveScope(scope: Scope, context: ResolveContext): Resolution;
259
+ /** A member more than one edge carries. */
260
+ export declare const EDGE_AMBIGUOUS = -2;
261
+ /**
262
+ * One set's seeds: member key to the session edge counter the member entered the set through.
263
+ * `version` moves on every write, so a binding plan built from an older version is rebuilt.
264
+ */
265
+ export interface EdgeSeeds {
266
+ readonly counters: ReadonlyMap<string, number>;
267
+ readonly version: number;
268
+ }
269
+ /**
270
+ * The key a seed is filed under: the member's fields, types kept, so `1` and `"1"` differ.
271
+ * @param member - The member.
272
+ * @returns The key.
273
+ */
274
+ export declare function edgeMemberKey(member: EdgeMember): string;
275
+ /**
276
+ * The row each edge member binds in the context snapshot: seeded first, then by identity.
277
+ * @param key - The frozen definition the members belong to; the binding table is keyed by it.
278
+ * @param members - The members.
279
+ * @param context - What the resolution reads.
280
+ * @param seeds - The set's seeds, if any.
281
+ * @returns One entry per member: its row, {@link EDGE_MISSING} or {@link EDGE_AMBIGUOUS}.
282
+ */
283
+ export declare function bindEdgeMembers(key: object, members: EdgeMemberList, context: ResolveContext, seeds?: EdgeSeeds): Int32Array;
284
+ /**
285
+ * Set a row's edge bit and its endpoints' node bits.
286
+ * @param row - The edge row.
287
+ * @param snapshot - The context snapshot.
288
+ * @param nodes - The node bitmap.
289
+ * @param edges - The edge bitmap.
290
+ */
291
+ export declare function addEdgeRow(row: number, snapshot: GraphSnapshot, nodes: U32, edges: U32): void;
292
+ /**
293
+ * What a fixed definition covers. `induced`: its nodes and the edges between them, its edge
294
+ * members inert. `listed`: its nodes plus its bound edge members and their ends.
295
+ * @param definition - A canonical fixed definition.
296
+ * @param context - What the resolution reads.
297
+ * @param seeds - The set's seeds, for a kept set.
298
+ * @returns The resolution.
299
+ */
300
+ export declare function resolveFixed(definition: Extract<SetDefinition, {
301
+ kind: "fixed";
302
+ }>, context: ResolveContext, seeds?: EdgeSeeds): Resolution;
303
+ /**
304
+ * A resolution's `d1:` membership digest: one masked sum over each hash column, computed on first
305
+ * read and memoised on the resolution.
306
+ * @param resolution - The resolution.
307
+ * @param snapshot - The snapshot it was resolved against.
308
+ * @returns The digest.
309
+ * @throws An Error when the snapshot is not the one the resolution was resolved against.
310
+ */
311
+ export declare function digestOf(resolution: Resolution, snapshot: GraphSnapshot): string;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @file Input signatures: a string built only from what one definition reads, so a resolution is
3
+ * served again exactly while none of those inputs moved (design/sets/sets-design.md sections 5.2
4
+ * and 6.2).
5
+ *
6
+ * A signature is `<store>|<serial>|<parts>`. The store and the snapshot serial are in every one.
7
+ * The parts name the other inputs the definition reads, and nothing else:
8
+ *
9
+ * - `"visible"` and `"selection"`: the mask objects and their versions;
10
+ * - `{ where }` and a rule over a query: the attribute revision of every top-level field its
11
+ * compiled paths read, and the execution token of every run whose results they read;
12
+ * - `{ set }`: the identity of the saved record it names, or an explicit absent marker, and the
13
+ * parts of what that record holds, recursively;
14
+ * - a kept fixed or path set with edge members: the identity and version of its seeds.
15
+ *
16
+ * Records and definitions are frozen and replaced on every write, so their identity is exact: a
17
+ * rename keeps the definition object and moves nothing, an undo that restores the identical
18
+ * record matches again.
19
+ *
20
+ * A definition whose inputs the context cannot enumerate (a query with no path reader, say) has
21
+ * no signature: `null`, and it is never cached.
22
+ *
23
+ * Signatures are memoised per read epoch -- the store, the serial, the session input tick and
24
+ * the identity of the saved-scope map and the kept-set list -- so a chain of sets naming one
25
+ * base walks the base once. Without a tick the context cannot tell when an attribute or a token
26
+ * moved, so nothing is memoised.
27
+ *
28
+ * Nothing here reaches Babylon.js, Lit or the DOM.
29
+ */
30
+ import type { Scope, SetDefinition, SetId } from "../../catalog/types";
31
+ import type { ResolveContext } from "./resolve";
32
+ /**
33
+ * The definition of the kept set an id names, when the context holds one: the live set's, else
34
+ * the removed set's kept record, so a reference to a removed set reads what it read before the
35
+ * removal (design/sets 15.3, item 33).
36
+ * @param id - The id.
37
+ * @param context - What the resolution reads.
38
+ * @returns The definition, or undefined.
39
+ */
40
+ export declare function keptDefinition(id: SetId, context: ResolveContext): SetDefinition | undefined;
41
+ /** Invocation counts the complexity tests read. `walks`: saved-scope and kept-set parts computed, not memoised. */
42
+ export declare const signatureCounters: {
43
+ walks: number;
44
+ };
45
+ /**
46
+ * A small number standing for an object's identity, stable for the object's life.
47
+ * @param value - The object.
48
+ * @returns Its number.
49
+ */
50
+ export declare function identityOf(value: object): number;
51
+ /** One read epoch's memo: signature parts by set id or target key. */
52
+ export interface SignatureMemo {
53
+ epoch: string;
54
+ readonly parts: Map<unknown, string | null>;
55
+ }
56
+ /**
57
+ * A fresh memo.
58
+ * @returns It.
59
+ */
60
+ export declare function createSignatureMemo(): SignatureMemo;
61
+ /**
62
+ * The input signature of one `Scope`.
63
+ * @param scope - The specification.
64
+ * @param context - What the resolution reads.
65
+ * @param memo - The epoch memo, when the caller keeps one.
66
+ * @returns The signature, or null when the scope must not be cached.
67
+ */
68
+ export declare function scopeSignature(scope: Scope, context: ResolveContext, memo?: SignatureMemo): string | null;
69
+ /**
70
+ * The input signature of a kept set's definition.
71
+ * @param id - The set's id, which its seeds are filed under.
72
+ * @param definition - Its frozen definition.
73
+ * @param context - What the resolution reads.
74
+ * @param memo - The epoch memo, when the caller keeps one.
75
+ * @returns The signature, or null when it must not be cached.
76
+ */
77
+ export declare function definitionSignature(id: SetId, definition: SetDefinition, context: ResolveContext, memo?: SignatureMemo): string | null;