@graphty/graphty-element 2.5.2 → 2.6.1
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/ai.js +3 -3
- package/dist/catalog.d.ts +16 -0
- package/dist/catalog.js +34 -32
- package/dist/chunks/{AiManager-CrbvKdEK.js → AiManager-4iQpsJW1.js} +4 -4
- package/dist/chunks/{DataSource-qU-nLhXN.js → DataSource-BL2UzPff.js} +2 -2
- package/dist/chunks/GraphSession-BhuHSXIo.js +12819 -0
- package/dist/chunks/{GraphtyLogger-DOTwCiMR.js → GraphtyLogger-B_O67a6c.js} +1 -1
- package/dist/chunks/{VoiceInputAdapter-D4NrRL_1.js → VoiceInputAdapter-Cc6mHXTI.js} +1 -1
- package/dist/chunks/{XRPivotCameraController-Uqa47vmo.js → XRPivotCameraController-BLa89LXn.js} +2 -2
- package/dist/chunks/{algorithms-D-ab-Auu.js → algorithms-BJ6DQMOe.js} +931 -781
- package/dist/chunks/{capability-check-Vw3IcqiE.js → capability-check-Am2zliFj.js} +1 -1
- package/dist/chunks/{detect-B4Qrw976.js → detect-fyuVnlCT.js} +1 -1
- package/dist/chunks/{format-detection-r2IfNFXO.js → format-detection-BHwrAVzW.js} +1 -1
- package/dist/chunks/{index-J9MgLio9.js → index-BkBLbvui.js} +2691 -2434
- package/dist/chunks/optionsFromZod-CKMYSwTz.js +3636 -0
- package/dist/chunks/{paletteRegistry-Kt-6CeoN.js → paletteRegistry-BCFSwJGK.js} +224 -189
- package/dist/chunks/parse-BMTqt4SS.js +3658 -0
- package/dist/chunks/{types-C_c53VgR.js → types-DFchv4Ny.js} +4 -1
- package/dist/custom-elements.json +1 -1
- package/dist/extend.d.ts +10 -8
- package/dist/extend.js +6 -6
- package/dist/graphty-catalog.json +75 -38
- package/dist/graphty.bundle.js +55368 -48970
- package/dist/graphty.js +19 -19
- package/dist/index.d.ts +1 -1
- package/dist/logging.js +2 -2
- package/dist/schema.d.ts +15 -1
- package/dist/schema.js +1 -1
- package/dist/session.d.ts +30 -7
- package/dist/session.js +40 -37
- package/dist/src/Graph.d.ts +35 -7
- package/dist/src/acceleration/types.d.ts +79 -43
- package/dist/src/algorithms/Algorithm.d.ts +52 -4
- package/dist/src/algorithms/BFSAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/BellmanFordAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/BetweennessCentralityAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/BipartiteMatchingAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/ClosenessCentralityAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/ConnectedComponentsAlgorithm.d.ts +4 -1
- package/dist/src/algorithms/DFSAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/DegreeAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/DijkstraAlgorithm.d.ts +6 -0
- package/dist/src/algorithms/EigenvectorCentralityAlgorithm.d.ts +2 -0
- package/dist/src/algorithms/FloydWarshallAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/GirvanNewmanAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/HITSAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/KCoreAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/KatzCentralityAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/KruskalAlgorithm.d.ts +4 -1
- package/dist/src/algorithms/LabelPropagationAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/LeidenAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/LinkPredictionAlgorithm.d.ts +4 -1
- package/dist/src/algorithms/LouvainAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/MaxFlowAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/MinCutAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/PageRankAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/PrimAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/StronglyConnectedComponentsAlgorithm.d.ts +3 -0
- package/dist/src/algorithms/input/ScopedInput.d.ts +185 -0
- package/dist/src/algorithms/input/derivedInputs.d.ts +199 -0
- package/dist/src/algorithms/input/maskBack.d.ts +37 -0
- package/dist/src/algorithms/metrics/MetricAlgorithm.d.ts +3 -3
- package/dist/src/algorithms/results/DeclaredAlgorithm.d.ts +4 -3
- package/dist/src/algorithms/results/types.d.ts +28 -6
- package/dist/src/algorithms/utils/communityUtils.d.ts +0 -48
- package/dist/src/algorithms/utils/graphUtils.d.ts +2 -68
- package/dist/src/algorithms/utils/snapshotGraph.d.ts +3 -1
- package/dist/src/catalog/algorithms.d.ts +3 -0
- package/dist/src/catalog/layouts.d.ts +2 -0
- package/dist/src/catalog/sets/canonical.d.ts +68 -0
- package/dist/src/catalog/sets/hash.d.ts +126 -0
- package/dist/src/catalog/sets/parse.d.ts +115 -0
- package/dist/src/catalog/types.d.ts +329 -8
- package/dist/src/data/GraphStore.d.ts +73 -1
- package/dist/src/data/edgeIdentity.d.ts +202 -1
- package/dist/src/data/ingest.d.ts +3 -1
- package/dist/src/data/report.d.ts +20 -0
- package/dist/src/graphty-element.d.ts +42 -6
- package/dist/src/layout/D3GraphLayoutEngine.d.ts +11 -0
- package/dist/src/layout/LayoutEngine.d.ts +56 -0
- package/dist/src/layout/NGraphLayoutEngine.d.ts +10 -0
- package/dist/src/layout/SimulationLayoutEngine.d.ts +11 -0
- package/dist/src/managers/AlgorithmManager.d.ts +8 -0
- package/dist/src/managers/DataManager.d.ts +11 -0
- package/dist/src/managers/LayoutManager.d.ts +126 -2
- package/dist/src/managers/StatsManager.d.ts +1 -0
- package/dist/src/session/GraphSession.d.ts +48 -0
- package/dist/src/session/attributes.d.ts +121 -1
- package/dist/src/session/cost/estimate.d.ts +20 -0
- package/dist/src/session/cost/index.d.ts +1 -1
- package/dist/src/session/planning.d.ts +32 -2
- package/dist/src/session/query.d.ts +7 -0
- package/dist/src/session/results/ResultsApi.d.ts +14 -1
- package/dist/src/session/runs/Run.d.ts +65 -4
- package/dist/src/session/runs/RunsApi.d.ts +58 -2
- package/dist/src/session/runs/runId.d.ts +55 -6
- package/dist/src/session/runs/types.d.ts +36 -8
- package/dist/src/session/scope/ElementMask.d.ts +14 -1
- package/dist/src/session/scope/ScopeApi.d.ts +160 -31
- package/dist/src/session/scope/index.d.ts +1 -1
- package/dist/src/session/selection/SelectionApi.d.ts +15 -10
- package/dist/src/session/selection/index.d.ts +1 -1
- package/dist/src/session/selection/targets.d.ts +6 -7
- package/dist/src/session/sets/SetsApi.d.ts +110 -0
- package/dist/src/session/sets/algebra.d.ts +124 -0
- package/dist/src/session/sets/cache.d.ts +197 -0
- package/dist/src/session/sets/captures.d.ts +83 -0
- package/dist/src/session/sets/dependencies.d.ts +167 -0
- package/dist/src/session/sets/layers.d.ts +101 -0
- package/dist/src/session/sets/notify.d.ts +122 -0
- package/dist/src/session/sets/offers.d.ts +103 -0
- package/dist/src/session/sets/path.d.ts +37 -0
- package/dist/src/session/sets/prepare.d.ts +209 -0
- package/dist/src/session/sets/resolve.d.ts +311 -0
- package/dist/src/session/sets/signature.d.ts +77 -0
- package/dist/src/session/sets/status.d.ts +98 -0
- package/dist/src/session/sets/store.d.ts +196 -0
- package/dist/src/session/sets/types.d.ts +386 -0
- package/dist/src/session/styles/Layer.d.ts +9 -2
- package/dist/src/session/styles/StylesApi.d.ts +5 -2
- package/dist/src/session/styles/explain.d.ts +5 -2
- package/dist/src/session/styles/predicate.d.ts +41 -2
- package/dist/src/session/styles/repaint.d.ts +19 -0
- package/dist/src/session/styles/selector.d.ts +16 -5
- package/dist/src/session/types.d.ts +18 -0
- package/dist/src/session/visibility/VisibilityApi.d.ts +47 -3
- package/dist/src/session/visibility/filter.d.ts +86 -51
- package/dist/src/session/visibility/index.d.ts +1 -1
- package/dist/src/testing/fakeAccelerator.d.ts +5 -0
- package/dist/src/utils/queue-migration.d.ts +17 -0
- package/package.json +15 -9
- package/dist/chunks/GraphSession-DuAhRgCd.js +0 -8622
- package/dist/chunks/optionsFromZod-B9RncoTX.js +0 -2578
- package/dist/chunks/scales-CJCRwi2J.js +0 -3220
- package/dist/src/algorithms/utils/index.d.ts +0 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
2
|
+
* @file Helpers the adapters share: matching an `@graphty/algorithms` answer back onto an edge,
|
|
3
|
+
* and refusing a node option that names no node.
|
|
3
4
|
*/
|
|
4
5
|
/**
|
|
5
6
|
* The key an `@graphty/algorithms` result is matched back onto the element's edges by: the two
|
|
@@ -28,70 +29,3 @@ export declare function edgePairKey(source: string | number, target: string | nu
|
|
|
28
29
|
* @throws A `GraphtyError` coded `E_OPTION_RANGE` when no node has that id.
|
|
29
30
|
*/
|
|
30
31
|
export declare function requireNodeOption(algorithm: string, option: string, value: string | number, nodeIds: readonly (string | number)[]): string;
|
|
31
|
-
/**
|
|
32
|
-
* Minimal edge data interface required by graph utilities
|
|
33
|
-
*/
|
|
34
|
-
export interface MinimalEdge {
|
|
35
|
-
srcId: string | number;
|
|
36
|
-
dstId: string | number;
|
|
37
|
-
data?: Record<string, unknown>;
|
|
38
|
-
[key: string]: unknown;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Minimal interface for graph-like objects
|
|
42
|
-
* This allows the utilities to work with both real Graph instances and mock graphs in tests
|
|
43
|
-
*/
|
|
44
|
-
export interface GraphLike {
|
|
45
|
-
getDataManager: () => {
|
|
46
|
-
nodes: Map<string | number, unknown>;
|
|
47
|
-
edges: Map<string | number, MinimalEdge>;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Options for building adjacency lists
|
|
52
|
-
*/
|
|
53
|
-
interface AdjacencyOptions {
|
|
54
|
-
/** Whether to treat the graph as directed (default: false for undirected) */
|
|
55
|
-
directed?: boolean;
|
|
56
|
-
/** Weight attribute name on edges (default: "value") */
|
|
57
|
-
weightAttribute?: string;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Build an unweighted adjacency list from graph edges.
|
|
61
|
-
*
|
|
62
|
-
* Returns a Map where keys are node IDs (as strings) and values are Sets of neighbor node IDs.
|
|
63
|
-
* For undirected graphs, both directions are added automatically.
|
|
64
|
-
* @param graph - The graphty-element Graph instance
|
|
65
|
-
* @param options - Configuration options
|
|
66
|
-
* @returns Map of node ID to Set of neighbor IDs
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* // Undirected graph
|
|
70
|
-
* const adj = buildAdjacencyList(graph);
|
|
71
|
-
* adj.get("A")?.has("B"); // true if A-B edge exists
|
|
72
|
-
*
|
|
73
|
-
* // Directed graph
|
|
74
|
-
* const directedAdj = buildAdjacencyList(graph, { directed: true });
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export declare function buildAdjacencyList(graph: GraphLike, options?: AdjacencyOptions): Map<string, Set<string>>;
|
|
78
|
-
/**
|
|
79
|
-
* Build a weighted adjacency list from graph edges.
|
|
80
|
-
*
|
|
81
|
-
* Returns a Map where keys are node IDs (as strings) and values are Maps of neighbor ID to edge weight.
|
|
82
|
-
* For undirected graphs, both directions are added automatically with the same weight.
|
|
83
|
-
* @param graph - The graphty-element Graph instance
|
|
84
|
-
* @param options - Configuration options
|
|
85
|
-
* @returns Map of node ID to Map of neighbor ID to weight
|
|
86
|
-
* @example
|
|
87
|
-
* ```typescript
|
|
88
|
-
* // Get weighted adjacency (weights from 'value' attribute)
|
|
89
|
-
* const adj = buildWeightedAdjacencyList(graph);
|
|
90
|
-
* const weight = adj.get("A")?.get("B"); // edge weight from A to B
|
|
91
|
-
*
|
|
92
|
-
* // Use custom weight attribute
|
|
93
|
-
* const adj = buildWeightedAdjacencyList(graph, { weightAttribute: "weight" });
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
export declare function buildWeightedAdjacencyList(graph: GraphLike, options?: AdjacencyOptions): Map<string, Map<string, number>>;
|
|
97
|
-
export {};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Graph as AlgorithmGraph } from "@graphty/algorithms";
|
|
6
6
|
import type { DataManager } from "../../managers/DataManager";
|
|
7
|
+
import { type ScopedInput } from "../input/ScopedInput";
|
|
7
8
|
/**
|
|
8
9
|
* How an algorithm wants the reader's graph presented to `@graphty/algorithms`.
|
|
9
10
|
*
|
|
@@ -39,9 +40,10 @@ export type AlgorithmGraphView = AlgorithmGraph;
|
|
|
39
40
|
* than the part of it the scene has caught up with.
|
|
40
41
|
* @param data - the element's data manager, which owns the one snapshot
|
|
41
42
|
* @param mode - the shape this algorithm needs; see {@link AlgorithmGraphMode}
|
|
43
|
+
* @param input - what the run reads, from `Algorithm.input`; the whole graph when absent
|
|
42
44
|
* @returns a freshly built Graph for `@graphty/algorithms`
|
|
43
45
|
*/
|
|
44
|
-
export declare function toAlgorithmGraph(data: DataManager, mode: AlgorithmGraphMode): AlgorithmGraph;
|
|
46
|
+
export declare function toAlgorithmGraph(data: DataManager, mode: AlgorithmGraphMode, input?: ScopedInput): AlgorithmGraph;
|
|
45
47
|
/**
|
|
46
48
|
* How many parallel edges an algorithm run over this graph merges before it can run.
|
|
47
49
|
*
|
|
@@ -74,6 +74,9 @@ export interface BuiltInAlgorithmDescriptor extends AlgorithmDescriptor {
|
|
|
74
74
|
* shortest-path engines are one key with a `method` parameter, and the two component algorithms
|
|
75
75
|
* are one key with a `strength` parameter. Each descriptor's `legacyKeys` names the 1.10 keys it
|
|
76
76
|
* replaces and the parameters that reproduce them.
|
|
77
|
+
*
|
|
78
|
+
* `scopeInput` is read from the classes rather than written here, so it cannot disagree with what
|
|
79
|
+
* a run computes over: a folded key computes over its scope only when every class behind it does.
|
|
77
80
|
*/
|
|
78
81
|
export declare const BUILT_IN_ALGORITHMS: readonly BuiltInAlgorithmDescriptor[];
|
|
79
82
|
/**
|
|
@@ -47,6 +47,8 @@ export interface LayoutImplementation {
|
|
|
47
47
|
* catalogue cannot claim a weight channel an engine does not have.
|
|
48
48
|
*/
|
|
49
49
|
honoursWeights: boolean;
|
|
50
|
+
/** Whether this engine accepts a scope, read off the engine class's own `static scoped`. */
|
|
51
|
+
scoped: boolean;
|
|
50
52
|
/**
|
|
51
53
|
* What has to be true before this engine can run at all, in the same shape an algorithm
|
|
52
54
|
* declares it.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The canonical form of a set definition: one spelling for every definition that means the
|
|
3
|
+
* same thing.
|
|
4
|
+
*
|
|
5
|
+
* Every door, the loader and the revision hash go through this one function, so two definitions
|
|
6
|
+
* that hold the same members compare equal as JSON and hash to the same revision. The rules
|
|
7
|
+
* (design/sets/sets-design.md section 12.1):
|
|
8
|
+
*
|
|
9
|
+
* - Object keys sorted by UTF-16 code unit. Absent optional fields omitted, never `null`, except
|
|
10
|
+
* a path step's `null`, which means "every edge between that pair". An empty edge list and a
|
|
11
|
+
* path's `directed: false` are the defaults, so they are omitted too.
|
|
12
|
+
* - Member arrays (a fixed set's nodes and edges, a path step's edge group) sorted by one
|
|
13
|
+
* comparator and de-duplicated: numbers before strings, numbers by value, strings by code unit.
|
|
14
|
+
* The number `1` and the string `"1"` are different ids. `-0` is stored as `0`.
|
|
15
|
+
* - Path nodes and steps keep their order; `all` and `any` keep their operand order, because the
|
|
16
|
+
* user wrote it.
|
|
17
|
+
* - A rule whose tree is one expression leaf becomes the bare query; a fixed `clipped` becomes
|
|
18
|
+
* `listed`, which holds the same members.
|
|
19
|
+
* - Unknown kinds are left exactly as they are. A known node carrying a field this element does
|
|
20
|
+
* not know keeps that field's value; a fixed set carrying one also keeps its member order, so a
|
|
21
|
+
* newer element's parallel array (such as `weights`) is never left misaligned.
|
|
22
|
+
*
|
|
23
|
+
* Pure and Node-safe: nothing here reaches a graph, a renderer or the DOM.
|
|
24
|
+
*/
|
|
25
|
+
import type { EdgeMember, NodeId, SetDefinition } from "../types";
|
|
26
|
+
/** The fields each definition kind defines; anything else is unknown to this element. */
|
|
27
|
+
export declare const DEFINITION_FIELDS: {
|
|
28
|
+
readonly fixed: readonly ["kind", "nodes", "edges", "reading"];
|
|
29
|
+
readonly rule: readonly ["kind", "where", "reading"];
|
|
30
|
+
readonly path: readonly ["kind", "nodes", "edges", "directed"];
|
|
31
|
+
};
|
|
32
|
+
/** The fields an edge member defines, in its sort order after the endpoints. */
|
|
33
|
+
export declare const EDGE_MEMBER_FIELDS: readonly ["source", "target", "id", "key", "ordinal", "among"];
|
|
34
|
+
/**
|
|
35
|
+
* The member comparator: numbers before strings, numbers by value, strings by UTF-16 code unit.
|
|
36
|
+
* @param a - One id.
|
|
37
|
+
* @param b - The other.
|
|
38
|
+
* @returns Negative, zero or positive.
|
|
39
|
+
*/
|
|
40
|
+
export declare function compareIds(a: unknown, b: unknown): number;
|
|
41
|
+
/**
|
|
42
|
+
* Members the element built itself from a snapshot (known fields only, integers, no `-0`) in the
|
|
43
|
+
* canonical order, de-duplicated, without the per-member key sort a caller's members need.
|
|
44
|
+
* Internal: for the materialising doors.
|
|
45
|
+
* @param members - Element-built members.
|
|
46
|
+
* @returns A fresh sorted array.
|
|
47
|
+
*/
|
|
48
|
+
export declare function sortElementEdgeMembers(members: readonly EdgeMember[]): EdgeMember[];
|
|
49
|
+
/**
|
|
50
|
+
* Node ids in the canonical order, de-duplicated. Internal: for the materialising doors.
|
|
51
|
+
* @param ids - Element-built ids.
|
|
52
|
+
* @returns A fresh sorted array.
|
|
53
|
+
*/
|
|
54
|
+
export declare function sortElementNodeIds(ids: readonly NodeId[]): NodeId[];
|
|
55
|
+
/**
|
|
56
|
+
* The run id a result item names: the id itself, or the id of a `Run` or `RunResult` handle a
|
|
57
|
+
* door was passed, so every stored item holds a plain id.
|
|
58
|
+
* @param run - The item's `result`.
|
|
59
|
+
* @returns The id, or the value as it was when it is neither.
|
|
60
|
+
*/
|
|
61
|
+
export declare function runIdOfRef(run: unknown): unknown;
|
|
62
|
+
/**
|
|
63
|
+
* The canonical form of a set definition. Never modifies its input. Accepts a definition holding
|
|
64
|
+
* content this element does not know and keeps that content exactly.
|
|
65
|
+
* @param definition - The definition, already validated or loaded.
|
|
66
|
+
* @returns A fresh canonical definition.
|
|
67
|
+
*/
|
|
68
|
+
export declare function canonicalSetDefinition(definition: SetDefinition): SetDefinition;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Member hashes, the member sum and the `r1:` revision of a set definition.
|
|
3
|
+
*
|
|
4
|
+
* The rules are persisted contract (design/sets/sets-design.md section 12.2); a change to any of
|
|
5
|
+
* them bumps the revision prefix to `r2`:
|
|
6
|
+
*
|
|
7
|
+
* - `H` is two independent 32-bit FNV-1a lanes. Lane A starts at 0x811c9dc5 and multiplies by
|
|
8
|
+
* 0x01000193, lane B starts at 0x1b873593 and multiplies by 0x85ebca6b. Each step is
|
|
9
|
+
* `lane = Math.imul(lane ^ unit, multiplier) >>> 0` on both lanes, and each lane ends with the
|
|
10
|
+
* MurmurHash3 32-bit finaliser, so member hashes can be summed without inheriting FNV's
|
|
11
|
+
* near-linear structure.
|
|
12
|
+
* - A string part is the unit 0x24 then each UTF-16 code unit as one step. A numeric part is the
|
|
13
|
+
* unit 0x23 then the eight little-endian bytes of its float64 value, `-0` fed as `+0`. No string
|
|
14
|
+
* is ever built for a number, so `1` and `"1"` differ and `1e21` is never "1e+21".
|
|
15
|
+
* - An edge member combines its endpoint hashes (a lane-wise sum when undirected, so the order of
|
|
16
|
+
* the ends cannot matter; an ordered hash when the graph was directed at ingest) with the hash of
|
|
17
|
+
* its one discriminator.
|
|
18
|
+
* - The member sum is the lane-wise sum of member hashes mod 2^32, order-free, so a member delta
|
|
19
|
+
* updates it by one add or subtract per member.
|
|
20
|
+
*
|
|
21
|
+
* Pure and Node-safe.
|
|
22
|
+
*/
|
|
23
|
+
import type { EdgeMember, NodeId, SetDefinition } from "../types";
|
|
24
|
+
/** A 64-bit hash as its two 32-bit lanes, each an unsigned integer. */
|
|
25
|
+
export interface LanePair {
|
|
26
|
+
readonly a: number;
|
|
27
|
+
readonly b: number;
|
|
28
|
+
}
|
|
29
|
+
/** The sum of no members. */
|
|
30
|
+
export declare const EMPTY_SUM: LanePair;
|
|
31
|
+
/**
|
|
32
|
+
* Invocation counts the complexity tests read: member hashes computed, and member hashes added to
|
|
33
|
+
* a sum. Internal; never reset by this module.
|
|
34
|
+
*/
|
|
35
|
+
export declare const hashCounters: {
|
|
36
|
+
memberHashes: number;
|
|
37
|
+
sums: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* A node member's hash.
|
|
41
|
+
* @param id - The node id.
|
|
42
|
+
* @returns `H` of its one part.
|
|
43
|
+
*/
|
|
44
|
+
export declare function hashNodeId(id: NodeId): LanePair;
|
|
45
|
+
/**
|
|
46
|
+
* An edge member's hash. Undirected, the endpoints combine by a lane-wise sum, so swapping them
|
|
47
|
+
* changes nothing; directed at ingest, they are hashed in order.
|
|
48
|
+
* @param member - The member, with exactly one discriminator.
|
|
49
|
+
* @param directed - Whether the graph was declared directed at ingest.
|
|
50
|
+
* @returns The member hash.
|
|
51
|
+
*/
|
|
52
|
+
export declare function hashEdgeMember(member: EdgeMember, directed: boolean): LanePair;
|
|
53
|
+
/**
|
|
54
|
+
* An edge member's hash from its endpoints' node hashes, equal to {@link hashEdgeMember} of the
|
|
55
|
+
* member those ends and that discriminator spell. The completion pass calls it with hashes it
|
|
56
|
+
* has already computed, so no member object is built and no endpoint id is hashed twice.
|
|
57
|
+
* @param source - `hashNodeId` of the source (or lower end)
|
|
58
|
+
* @param target - `hashNodeId` of the target (or upper end)
|
|
59
|
+
* @param directed - Whether the graph was declared directed at ingest.
|
|
60
|
+
* @param id - The file or minted id; when undefined, `ordinal` and `among` discriminate.
|
|
61
|
+
* @param ordinal - The edge's position among its pair's edges.
|
|
62
|
+
* @param among - Its pair's edge count.
|
|
63
|
+
* @returns The member hash.
|
|
64
|
+
*/
|
|
65
|
+
export declare function hashEdgeEnds(source: LanePair, target: LanePair, directed: boolean, id: string | number | undefined, ordinal: number, among: number): LanePair;
|
|
66
|
+
/**
|
|
67
|
+
* Add a member hash to a sum.
|
|
68
|
+
* @param sum - The sum.
|
|
69
|
+
* @param hash - The member hash.
|
|
70
|
+
* @returns The new sum, each lane mod 2^32.
|
|
71
|
+
*/
|
|
72
|
+
export declare function addToSum(sum: LanePair, hash: LanePair): LanePair;
|
|
73
|
+
/**
|
|
74
|
+
* Take a member hash out of a sum.
|
|
75
|
+
* @param sum - The sum.
|
|
76
|
+
* @param hash - A member hash the sum holds.
|
|
77
|
+
* @returns The new sum, each lane mod 2^32.
|
|
78
|
+
*/
|
|
79
|
+
export declare function subtractFromSum(sum: LanePair, hash: LanePair): LanePair;
|
|
80
|
+
/**
|
|
81
|
+
* The order-free sum of member hashes.
|
|
82
|
+
* @param hashes - The member hashes.
|
|
83
|
+
* @returns Their lane-wise sum.
|
|
84
|
+
*/
|
|
85
|
+
export declare function memberSum(hashes: Iterable<LanePair>): LanePair;
|
|
86
|
+
/**
|
|
87
|
+
* A hash as 16 lower-case hex digits, lane A first.
|
|
88
|
+
* @param hash - The hash.
|
|
89
|
+
* @returns The hex text.
|
|
90
|
+
*/
|
|
91
|
+
export declare function hashHex(hash: LanePair): string;
|
|
92
|
+
/** A member array as the revision sees it: how many members, and the sum of their hashes. */
|
|
93
|
+
export interface MemberSummary {
|
|
94
|
+
readonly count: number;
|
|
95
|
+
readonly sum: LanePair;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The revision of a fixed definition that carries no field this element does not know, from its
|
|
99
|
+
* member summaries alone, so a member delta can re-derive it without touching the other members.
|
|
100
|
+
* Equal to {@link revisionOf} of the same definition.
|
|
101
|
+
* @param reading - The stored reading, `induced` or `listed`.
|
|
102
|
+
* @param nodes - The node members' summary.
|
|
103
|
+
* @param edges - The edge members' summary; absent or empty when no edge is listed.
|
|
104
|
+
* @returns `r1:` and 16 hex digits.
|
|
105
|
+
*/
|
|
106
|
+
export declare function fixedRevision(reading: string, nodes: MemberSummary, edges?: MemberSummary): string;
|
|
107
|
+
/**
|
|
108
|
+
* The revision of a definition: `r1:` and `H` of its canonical JSON as one string part, in which a fixed set's
|
|
109
|
+
* member arrays are replaced by `{"count":k,"sum":"<hex>"}`. A fixed set's edge members are hashed
|
|
110
|
+
* in the order they are written (the directed rule): the revision digests the definition, and
|
|
111
|
+
* the definition's JSON tells `a -> b` from `b -> a`. Unknown kinds hash as their JSON.
|
|
112
|
+
* @param definition - A validated or loaded definition.
|
|
113
|
+
* @returns `r1:` and 16 hex digits.
|
|
114
|
+
*/
|
|
115
|
+
export declare function revisionOf(definition: SetDefinition): string;
|
|
116
|
+
/**
|
|
117
|
+
* The `d1:` membership digest (design section 6.4): `H` of six numeric parts, the node count, the
|
|
118
|
+
* node sum's lanes A and B, the edge count, the edge sum's lanes A and B, where each sum is the
|
|
119
|
+
* member sum of the resolved members' column hashes (`graphty.nodeHash`, `graphty.edgeHash`, the
|
|
120
|
+
* undirected rule while pairs are unordered). The counts keep a node half and an edge half apart
|
|
121
|
+
* even when their sums happen to agree. Comparable only within one session and store.
|
|
122
|
+
* @param nodes - The resolved nodes' count and member sum.
|
|
123
|
+
* @param edges - The resolved edges' count and member sum.
|
|
124
|
+
* @returns `d1:` and 16 hex digits.
|
|
125
|
+
*/
|
|
126
|
+
export declare function membershipDigestOf(nodes: MemberSummary, edges: MemberSummary): string;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The one validator for set definitions, in two modes.
|
|
3
|
+
*
|
|
4
|
+
* DOOR MODE (`parseSetDefinition`, published) refuses anything malformed, unknown or reserved
|
|
5
|
+
* with `E_BAD_COMMAND`, and returns the canonical definition. Every write door, and any caller
|
|
6
|
+
* that wants to check a definition before handing it over, uses it.
|
|
7
|
+
*
|
|
8
|
+
* LOAD MODE (`loadSetDefinition`, internal) is what reading stored state uses. It still refuses
|
|
9
|
+
* a malformed node of a kind this element knows, but an unknown kind, an unknown field or a
|
|
10
|
+
* reserved field is kept instead of refused, and the definition is flagged OPAQUE with the first
|
|
11
|
+
* such name. Ignoring it instead would be wrong in both directions: an older element that
|
|
12
|
+
* dropped a rule's `scope` or an item key's `op` would resolve silently wrong members, and would
|
|
13
|
+
* lose the field on the next save. The whole definition is the opaque unit
|
|
14
|
+
* (design/sets/sets-design.md section 12.5): it round-trips value-identical, resolves to nothing
|
|
15
|
+
* and reads `unresolvable`.
|
|
16
|
+
*
|
|
17
|
+
* One walker serves both modes, so the two can never disagree about what a known node is.
|
|
18
|
+
*
|
|
19
|
+
* Reserved fields -- names a later release will give a meaning, refused at the doors until then:
|
|
20
|
+
* `weights` on a fixed set, `scope` on a rule, `key` and `dataSource` on an edge member, `graph` on
|
|
21
|
+
* `{ set }`, `percentile`, `z` and `population` on a threshold, `op` on an item key. Reserved kinds:
|
|
22
|
+
* the scope keyword `"search"`, and the item key forms `{ smallestNode }`, `{ edges }`, `{ binds }`.
|
|
23
|
+
*
|
|
24
|
+
* `parseScope` is the same validator for a `Scope`, which may carry a definition inline.
|
|
25
|
+
*
|
|
26
|
+
* Pure and Node-safe: nothing here reaches a graph, a renderer or the DOM.
|
|
27
|
+
*/
|
|
28
|
+
import { GraphtyError } from "../../errors/GraphtyError";
|
|
29
|
+
import type { EdgeReading, Scope, SetDefinition } from "../types";
|
|
30
|
+
/** Every edge reading this element knows. */
|
|
31
|
+
export declare const EDGE_READINGS: readonly EdgeReading[];
|
|
32
|
+
/**
|
|
33
|
+
* How a scope reads, as far as the scope itself says: `"visible"` is clipped, an inline definition
|
|
34
|
+
* reads as it is stored (a path `listed`), and every other form is node-induced. A `{ set }` names
|
|
35
|
+
* a set this module cannot see: `referent` answers for it, and without one it reads induced.
|
|
36
|
+
* @param scope - A validated scope.
|
|
37
|
+
* @param referent - The reading of the set an id names, when the caller can look it up.
|
|
38
|
+
* @returns The reading.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readingOfScope(scope: unknown, referent?: (id: string) => string | undefined): string;
|
|
41
|
+
/**
|
|
42
|
+
* Whether a rule tree holds a leaf that speaks about edges: an `edges` leaf, a `member` leaf whose
|
|
43
|
+
* set is read `listed` or `clipped`, or an `item` or `threshold` leaf over a field edges carry.
|
|
44
|
+
* @param node - A validated tree node, or a query.
|
|
45
|
+
* @param referent - The reading of the set an id names, when the caller can look it up.
|
|
46
|
+
* @param fieldKinds - Which halves carry a value path (`results.<run>.<field>` or `data.<field>`),
|
|
47
|
+
* when the caller can look it up; without it an `item` or `threshold` leaf is not known to.
|
|
48
|
+
* @returns True when some leaf speaks the edge half.
|
|
49
|
+
*/
|
|
50
|
+
export declare function speaksEdges(node: unknown, referent?: (id: string) => string | undefined, fieldKinds?: (path: string) => readonly string[]): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* The refusal of a rule read `induced` that holds an edge-speaking leaf.
|
|
53
|
+
* @returns The error to throw.
|
|
54
|
+
*/
|
|
55
|
+
export declare function inducedEdgeLeaf(): GraphtyError;
|
|
56
|
+
/**
|
|
57
|
+
* Check a set definition and return its canonical form.
|
|
58
|
+
*
|
|
59
|
+
* Door mode: anything malformed, and any kind or field this element does not know or has only
|
|
60
|
+
* reserved, is refused. Edge members must be in stable form; a write door that accepts a session
|
|
61
|
+
* edge id converts it before calling this.
|
|
62
|
+
* @param value - The candidate definition, from any source.
|
|
63
|
+
* @returns The canonical definition.
|
|
64
|
+
* @throws A `GraphtyError` with code `E_BAD_COMMAND`. `details.reason` is `"induced-edge-leaf"`
|
|
65
|
+
* for a rule read `induced` that holds an edge leaf; a reserved field is named in `details.field`.
|
|
66
|
+
*/
|
|
67
|
+
export declare function parseSetDefinition(value: unknown): SetDefinition;
|
|
68
|
+
/**
|
|
69
|
+
* Check a stored set definition, keeping what this element does not know.
|
|
70
|
+
*
|
|
71
|
+
* Internal: the loader's mode. A malformed node of a known kind is still refused.
|
|
72
|
+
* @param value - The stored definition.
|
|
73
|
+
* @returns The canonical definition, and when it holds anything unknown or reserved, the first
|
|
74
|
+
* such kind or field (`<node>.<field>` for a field).
|
|
75
|
+
* @throws A `GraphtyError` with code `E_BAD_COMMAND` for a malformed known node.
|
|
76
|
+
*/
|
|
77
|
+
export declare function loadSetDefinition(value: unknown): {
|
|
78
|
+
definition: SetDefinition;
|
|
79
|
+
opaque?: {
|
|
80
|
+
first: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Check a rule tree in door mode, as the visibility filter's door does for the leaves it shares
|
|
85
|
+
* with rule sets. Internal.
|
|
86
|
+
* @param value - The candidate tree.
|
|
87
|
+
* @throws A `GraphtyError` with code `E_BAD_COMMAND`.
|
|
88
|
+
*/
|
|
89
|
+
export declare function assertRuleTree(value: unknown): void;
|
|
90
|
+
/**
|
|
91
|
+
* Check a scope and return its canonical form: an inline definition canonical, every other form
|
|
92
|
+
* as given.
|
|
93
|
+
*
|
|
94
|
+
* Door mode: anything malformed, unknown or reserved (the keyword `"search"`) is refused. Edge
|
|
95
|
+
* members inside `{ define }` must be in stable form; a write door that accepts session edge ids
|
|
96
|
+
* converts them first.
|
|
97
|
+
* @param value - The candidate scope, from any source.
|
|
98
|
+
* @returns The scope.
|
|
99
|
+
* @throws A `GraphtyError` with code `E_BAD_COMMAND`, with `details.reason` as
|
|
100
|
+
* {@link parseSetDefinition} gives it for an inline definition.
|
|
101
|
+
*/
|
|
102
|
+
export declare function parseScope(value: unknown): Scope;
|
|
103
|
+
/**
|
|
104
|
+
* A write door's value with every edge reference inside an inline definition passed through
|
|
105
|
+
* `stable` (a session edge id becomes its stable member; an object member is handed over as
|
|
106
|
+
* given, for the door to canonicalise), at any depth: a scope's `{ define }`, a fixed or path definition's edges, a
|
|
107
|
+
* rule's tree, the `member` leaves of a rule tree and a `{ match: "member" }` selector. Everything
|
|
108
|
+
* else is returned as given for the validator to judge, and a value `stable` changes nothing in is
|
|
109
|
+
* returned unchanged (the same object).
|
|
110
|
+
* @param value - A scope, a set definition, a rule tree or a selector, as given.
|
|
111
|
+
* @param stable - The stable member of a session edge id or an object member; throws for an edge
|
|
112
|
+
* the graph lacks.
|
|
113
|
+
* @returns The value, stable.
|
|
114
|
+
*/
|
|
115
|
+
export declare function stabiliseEdgeRefs<T>(value: T, stable: (ref: string) => unknown): T;
|