@graphty/graph-format 0.0.0 → 0.2.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 (224) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +216 -43
  3. package/dist/graph-format.d.ts +1 -0
  4. package/dist/graph-format.d.ts.map +1 -0
  5. package/dist/graph-format.js +15798 -0
  6. package/dist/graph-format.js.map +1 -0
  7. package/dist/src/builder/arena.d.ts +85 -0
  8. package/dist/src/builder/arena.d.ts.map +1 -0
  9. package/dist/src/builder/arena.js +154 -0
  10. package/dist/src/builder/arena.js.map +1 -0
  11. package/dist/src/builder/compact.d.ts +515 -0
  12. package/dist/src/builder/compact.d.ts.map +1 -0
  13. package/dist/src/builder/compact.js +1553 -0
  14. package/dist/src/builder/compact.js.map +1 -0
  15. package/dist/src/builder/counting-sort.d.ts +96 -0
  16. package/dist/src/builder/counting-sort.d.ts.map +1 -0
  17. package/dist/src/builder/counting-sort.js +430 -0
  18. package/dist/src/builder/counting-sort.js.map +1 -0
  19. package/dist/src/builder/freeze.d.ts +72 -0
  20. package/dist/src/builder/freeze.d.ts.map +1 -0
  21. package/dist/src/builder/freeze.js +548 -0
  22. package/dist/src/builder/freeze.js.map +1 -0
  23. package/dist/src/builder/graph-builder.d.ts +602 -0
  24. package/dist/src/builder/graph-builder.d.ts.map +1 -0
  25. package/dist/src/builder/graph-builder.js +1940 -0
  26. package/dist/src/builder/graph-builder.js.map +1 -0
  27. package/dist/src/builder/options.d.ts +16 -0
  28. package/dist/src/builder/options.d.ts.map +1 -0
  29. package/dist/src/builder/options.js +21 -0
  30. package/dist/src/builder/options.js.map +1 -0
  31. package/dist/src/columns/bitmap.d.ts +96 -0
  32. package/dist/src/columns/bitmap.d.ts.map +1 -0
  33. package/dist/src/columns/bitmap.js +184 -0
  34. package/dist/src/columns/bitmap.js.map +1 -0
  35. package/dist/src/columns/column.d.ts +220 -0
  36. package/dist/src/columns/column.d.ts.map +1 -0
  37. package/dist/src/columns/column.js +2109 -0
  38. package/dist/src/columns/column.js.map +1 -0
  39. package/dist/src/columns/dictionary.d.ts +60 -0
  40. package/dist/src/columns/dictionary.d.ts.map +1 -0
  41. package/dist/src/columns/dictionary.js +102 -0
  42. package/dist/src/columns/dictionary.js.map +1 -0
  43. package/dist/src/columns/growable.d.ts +198 -0
  44. package/dist/src/columns/growable.d.ts.map +1 -0
  45. package/dist/src/columns/growable.js +296 -0
  46. package/dist/src/columns/growable.js.map +1 -0
  47. package/dist/src/columns/infer.d.ts +121 -0
  48. package/dist/src/columns/infer.d.ts.map +1 -0
  49. package/dist/src/columns/infer.js +268 -0
  50. package/dist/src/columns/infer.js.map +1 -0
  51. package/dist/src/columns/remap.d.ts +143 -0
  52. package/dist/src/columns/remap.d.ts.map +1 -0
  53. package/dist/src/columns/remap.js +588 -0
  54. package/dist/src/columns/remap.js.map +1 -0
  55. package/dist/src/columns/table.d.ts +184 -0
  56. package/dist/src/columns/table.d.ts.map +1 -0
  57. package/dist/src/columns/table.js +485 -0
  58. package/dist/src/columns/table.js.map +1 -0
  59. package/dist/src/constants.d.ts +34 -0
  60. package/dist/src/constants.d.ts.map +1 -0
  61. package/dist/src/constants.js +79 -0
  62. package/dist/src/constants.js.map +1 -0
  63. package/dist/src/errors.d.ts +76 -0
  64. package/dist/src/errors.d.ts.map +1 -0
  65. package/dist/src/errors.js +32 -0
  66. package/dist/src/errors.js.map +1 -0
  67. package/dist/src/ids/edge-id-index.d.ts +77 -0
  68. package/dist/src/ids/edge-id-index.d.ts.map +1 -0
  69. package/dist/src/ids/edge-id-index.js +155 -0
  70. package/dist/src/ids/edge-id-index.js.map +1 -0
  71. package/dist/src/ids/node-id-map.d.ts +280 -0
  72. package/dist/src/ids/node-id-map.d.ts.map +1 -0
  73. package/dist/src/ids/node-id-map.js +1139 -0
  74. package/dist/src/ids/node-id-map.js.map +1 -0
  75. package/dist/src/ids/string-store.d.ts +219 -0
  76. package/dist/src/ids/string-store.d.ts.map +1 -0
  77. package/dist/src/ids/string-store.js +526 -0
  78. package/dist/src/ids/string-store.js.map +1 -0
  79. package/dist/src/index.d.ts +30 -0
  80. package/dist/src/index.d.ts.map +1 -0
  81. package/dist/src/index.js +29 -0
  82. package/dist/src/index.js.map +1 -0
  83. package/dist/src/populate/from-csr.d.ts +61 -0
  84. package/dist/src/populate/from-csr.d.ts.map +1 -0
  85. package/dist/src/populate/from-csr.js +706 -0
  86. package/dist/src/populate/from-csr.js.map +1 -0
  87. package/dist/src/populate/from-edge-arrays.d.ts +51 -0
  88. package/dist/src/populate/from-edge-arrays.d.ts.map +1 -0
  89. package/dist/src/populate/from-edge-arrays.js +217 -0
  90. package/dist/src/populate/from-edge-arrays.js.map +1 -0
  91. package/dist/src/populate/from-records.d.ts +51 -0
  92. package/dist/src/populate/from-records.d.ts.map +1 -0
  93. package/dist/src/populate/from-records.js +447 -0
  94. package/dist/src/populate/from-records.js.map +1 -0
  95. package/dist/src/snapshot/derived.d.ts +211 -0
  96. package/dist/src/snapshot/derived.d.ts.map +1 -0
  97. package/dist/src/snapshot/derived.js +1254 -0
  98. package/dist/src/snapshot/derived.js.map +1 -0
  99. package/dist/src/snapshot/graph-meta.d.ts +23 -0
  100. package/dist/src/snapshot/graph-meta.d.ts.map +1 -0
  101. package/dist/src/snapshot/graph-meta.js +159 -0
  102. package/dist/src/snapshot/graph-meta.js.map +1 -0
  103. package/dist/src/snapshot/graph-snapshot.d.ts +509 -0
  104. package/dist/src/snapshot/graph-snapshot.d.ts.map +1 -0
  105. package/dist/src/snapshot/graph-snapshot.js +1247 -0
  106. package/dist/src/snapshot/graph-snapshot.js.map +1 -0
  107. package/dist/src/snapshot/hash.d.ts +90 -0
  108. package/dist/src/snapshot/hash.d.ts.map +1 -0
  109. package/dist/src/snapshot/hash.js +228 -0
  110. package/dist/src/snapshot/hash.js.map +1 -0
  111. package/dist/src/snapshot/queries.d.ts +74 -0
  112. package/dist/src/snapshot/queries.d.ts.map +1 -0
  113. package/dist/src/snapshot/queries.js +131 -0
  114. package/dist/src/snapshot/queries.js.map +1 -0
  115. package/dist/src/snapshot/validate.d.ts +192 -0
  116. package/dist/src/snapshot/validate.d.ts.map +1 -0
  117. package/dist/src/snapshot/validate.js +990 -0
  118. package/dist/src/snapshot/validate.js.map +1 -0
  119. package/dist/src/snapshot/views.d.ts +274 -0
  120. package/dist/src/snapshot/views.d.ts.map +1 -0
  121. package/dist/src/snapshot/views.js +856 -0
  122. package/dist/src/snapshot/views.js.map +1 -0
  123. package/dist/src/types/builder.d.ts +456 -0
  124. package/dist/src/types/builder.d.ts.map +1 -0
  125. package/dist/src/types/builder.js +11 -0
  126. package/dist/src/types/builder.js.map +1 -0
  127. package/dist/src/types/columns.d.ts +615 -0
  128. package/dist/src/types/columns.d.ts.map +1 -0
  129. package/dist/src/types/columns.js +14 -0
  130. package/dist/src/types/columns.js.map +1 -0
  131. package/dist/src/types/index.d.ts +14 -0
  132. package/dist/src/types/index.d.ts.map +1 -0
  133. package/dist/src/types/index.js +11 -0
  134. package/dist/src/types/index.js.map +1 -0
  135. package/dist/src/types/internal.d.ts +172 -0
  136. package/dist/src/types/internal.d.ts.map +1 -0
  137. package/dist/src/types/internal.js +13 -0
  138. package/dist/src/types/internal.js.map +1 -0
  139. package/dist/src/types/snapshot.d.ts +801 -0
  140. package/dist/src/types/snapshot.d.ts.map +1 -0
  141. package/dist/src/types/snapshot.js +14 -0
  142. package/dist/src/types/snapshot.js.map +1 -0
  143. package/dist/src/types/wire.d.ts +196 -0
  144. package/dist/src/types/wire.d.ts.map +1 -0
  145. package/dist/src/types/wire.js +8 -0
  146. package/dist/src/types/wire.js.map +1 -0
  147. package/dist/src/util/mask.d.ts +55 -0
  148. package/dist/src/util/mask.d.ts.map +1 -0
  149. package/dist/src/util/mask.js +71 -0
  150. package/dist/src/util/mask.js.map +1 -0
  151. package/dist/src/util/options.d.ts +22 -0
  152. package/dist/src/util/options.d.ts.map +1 -0
  153. package/dist/src/util/options.js +49 -0
  154. package/dist/src/util/options.js.map +1 -0
  155. package/dist/src/util/shared-buffers.d.ts +42 -0
  156. package/dist/src/util/shared-buffers.d.ts.map +1 -0
  157. package/dist/src/util/shared-buffers.js +52 -0
  158. package/dist/src/util/shared-buffers.js.map +1 -0
  159. package/dist/src/util/typed-array.d.ts +205 -0
  160. package/dist/src/util/typed-array.d.ts.map +1 -0
  161. package/dist/src/util/typed-array.js +289 -0
  162. package/dist/src/util/typed-array.js.map +1 -0
  163. package/dist/src/wire/bytes.d.ts +69 -0
  164. package/dist/src/wire/bytes.d.ts.map +1 -0
  165. package/dist/src/wire/bytes.js +361 -0
  166. package/dist/src/wire/bytes.js.map +1 -0
  167. package/dist/src/wire/carried-views.d.ts +111 -0
  168. package/dist/src/wire/carried-views.d.ts.map +1 -0
  169. package/dist/src/wire/carried-views.js +286 -0
  170. package/dist/src/wire/carried-views.js.map +1 -0
  171. package/dist/src/wire/from-wire.d.ts +144 -0
  172. package/dist/src/wire/from-wire.d.ts.map +1 -0
  173. package/dist/src/wire/from-wire.js +1425 -0
  174. package/dist/src/wire/from-wire.js.map +1 -0
  175. package/dist/src/wire/to-wire.d.ts +171 -0
  176. package/dist/src/wire/to-wire.d.ts.map +1 -0
  177. package/dist/src/wire/to-wire.js +652 -0
  178. package/dist/src/wire/to-wire.js.map +1 -0
  179. package/dist/tsconfig.build.tsbuildinfo +1 -0
  180. package/package.json +72 -7
  181. package/src/builder/arena.ts +192 -0
  182. package/src/builder/compact.ts +1811 -0
  183. package/src/builder/counting-sort.ts +506 -0
  184. package/src/builder/freeze.ts +689 -0
  185. package/src/builder/graph-builder.ts +2264 -0
  186. package/src/builder/options.ts +29 -0
  187. package/src/columns/bitmap.ts +196 -0
  188. package/src/columns/column.ts +2574 -0
  189. package/src/columns/dictionary.ts +114 -0
  190. package/src/columns/growable.ts +350 -0
  191. package/src/columns/infer.ts +285 -0
  192. package/src/columns/remap.ts +663 -0
  193. package/src/columns/table.ts +568 -0
  194. package/src/constants.ts +89 -0
  195. package/src/errors.ts +115 -0
  196. package/src/ids/edge-id-index.ts +179 -0
  197. package/src/ids/node-id-map.ts +1340 -0
  198. package/src/ids/string-store.ts +589 -0
  199. package/src/index.ts +139 -0
  200. package/src/lib-resizable-array-buffer.d.ts +34 -0
  201. package/src/populate/from-csr.ts +802 -0
  202. package/src/populate/from-edge-arrays.ts +257 -0
  203. package/src/populate/from-records.ts +536 -0
  204. package/src/snapshot/derived.ts +1486 -0
  205. package/src/snapshot/graph-meta.ts +167 -0
  206. package/src/snapshot/graph-snapshot.ts +1503 -0
  207. package/src/snapshot/hash.ts +241 -0
  208. package/src/snapshot/queries.ts +136 -0
  209. package/src/snapshot/validate.ts +1108 -0
  210. package/src/snapshot/views.ts +943 -0
  211. package/src/types/builder.ts +480 -0
  212. package/src/types/columns.ts +727 -0
  213. package/src/types/index.ts +14 -0
  214. package/src/types/internal.ts +195 -0
  215. package/src/types/snapshot.ts +886 -0
  216. package/src/types/wire.ts +207 -0
  217. package/src/util/mask.ts +89 -0
  218. package/src/util/options.ts +57 -0
  219. package/src/util/shared-buffers.ts +56 -0
  220. package/src/util/typed-array.ts +371 -0
  221. package/src/wire/bytes.ts +440 -0
  222. package/src/wire/carried-views.ts +327 -0
  223. package/src/wire/from-wire.ts +1690 -0
  224. package/src/wire/to-wire.ts +755 -0
@@ -0,0 +1,727 @@
1
+ /**
2
+ * Scalars, typed-array aliases and the attribute column model of @graphty/graph-format (design
3
+ * sections 2, 5 and 12.2).
4
+ *
5
+ * This is the base layer of the type surface: the scalar aliases and the typed-array aliases live
6
+ * here because every other types file depends on them, and the column model depends on nothing
7
+ * outside this file. Every declaration is transcribed verbatim from design section 12.2; the
8
+ * AttributeTableContract declared here is the instance contract of the AttributeTable class
9
+ * implemented in src/columns/table.ts (design section 12.1 makes it a class so the JSDoc-on-method
10
+ * lint applies). The public name AttributeTable is the class itself, re-exported type-only below so
11
+ * every type on this surface names the class the barrel exports.
12
+ */
13
+
14
+ import { type AttributeTable } from "../columns/table.js";
15
+
16
+ export type { AttributeTable };
17
+
18
+ // ============================================================ scalars, sentinels, typed-array aliases
19
+
20
+ /**
21
+ * External identity of a node: a string or a number, never coerced by the core (design section 4.1).
22
+ * Equality is SameValueZero, so 1 and "1" are two different nodes and -0 is stored as 0. NaN,
23
+ * non-finite numbers, bigints, objects, null, undefined and strings with lone surrogates are rejected
24
+ * with E_INVALID_ID.
25
+ */
26
+ export type NodeId = string | number;
27
+
28
+ /**
29
+ * Optional external identity of a logical edge, carried by an edge column with role "id" (design
30
+ * section 4.6). Never part of the CSR structure.
31
+ */
32
+ export type EdgeId = string | number;
33
+
34
+ /**
35
+ * Dense node index, 0 <= i < nodeCount, assigned in insertion order (invariant I14). A plain number
36
+ * alias for documentation: typed-array reads produce numbers, so a brand would cost a cast per read.
37
+ */
38
+ export type NodeIndex = number;
39
+
40
+ /**
41
+ * Logical edge index, 0 <= e < edgeCount, in addEdge order minus removals (invariant I14). Edge
42
+ * attribute columns are indexed by it, never by arc (invariant I13).
43
+ */
44
+ export type EdgeIndex = number;
45
+
46
+ /**
47
+ * Arc index, 0 <= a < arcCount, in CSR order: one entry of colIdx. A directed edge is one arc; an
48
+ * undirected edge with distinct endpoints is two arcs; an undirected self-loop is one arc (invariant
49
+ * I7). Arc indices may exceed 2^31, so consumers never apply JS bitwise operators to them (I3).
50
+ */
51
+ export type ArcIndex = number;
52
+
53
+ /**
54
+ * Uint32Array over a plain ArrayBuffer (design section 12.1). The buffer type parameter is what makes
55
+ * the array a BufferSource for GPUQueue.writeBuffer without a cast; a bare Uint32Array (whose default
56
+ * parameter is ArrayBufferLike) is rejected there. subarray(), slice(), fill() and `new Uint32Array(n)`
57
+ * all preserve or produce this type.
58
+ */
59
+ export type U32 = Uint32Array<ArrayBuffer>;
60
+
61
+ /** Int32Array over a plain ArrayBuffer; see U32 for why the buffer parameter is fixed. */
62
+ export type I32 = Int32Array<ArrayBuffer>;
63
+
64
+ /** Float32Array over a plain ArrayBuffer; see U32 for why the buffer parameter is fixed. */
65
+ export type F32 = Float32Array<ArrayBuffer>;
66
+
67
+ /** Float64Array over a plain ArrayBuffer; see U32 for why the buffer parameter is fixed. */
68
+ export type F64 = Float64Array<ArrayBuffer>;
69
+
70
+ /** Uint8Array over a plain ArrayBuffer; see U32 for why the buffer parameter is fixed. */
71
+ export type U8 = Uint8Array<ArrayBuffer>;
72
+
73
+ /** Any typed array a column can be built from or adopted as (design section 5.7). */
74
+ export type TypedArrayData = U32 | I32 | F32 | F64 | U8;
75
+
76
+ /**
77
+ * An index-aligned numeric result vector: CPU results are F64, GPU results F32, labels and parents
78
+ * U32 or I32. The boundary helpers foldArcs / expandEdges are generic over it (decision C11).
79
+ */
80
+ export type NumericVector = F32 | F64 | U32 | I32;
81
+
82
+ /**
83
+ * Patch shape: every field optional AND accepting an explicit undefined (design section 12.1).
84
+ * TypeScript's Partial adds `?` but not `| undefined`, so a consumer compiled with
85
+ * exactOptionalPropertyTypes could not spread a partial object into it; Loose can be spread under
86
+ * either setting.
87
+ */
88
+ export type Loose<T> = { [K in keyof T]?: T[K] | undefined };
89
+
90
+ /**
91
+ * How much of an untrusted snapshot is checked (design section 9.5): "none" is manifest shape only,
92
+ * "structure" checks lengths, ranges and counts in O(n + m), "full" adds sortedness, pairing, NaN,
93
+ * flag recomputation and the id bijection in O(m log d).
94
+ */
95
+ export type ValidationLevel = "none" | "structure" | "full";
96
+
97
+ /**
98
+ * What freeze() does with parallel edges (design section 6.5): "keep" stores them (the default),
99
+ * "error" throws E_DUPLICATE_EDGE, and the merge policies keep one edge per (u, v) with the weight
100
+ * of the first or last edge or the sum / min / max over the group. A merge policy rewrites the
101
+ * builder's edge set.
102
+ */
103
+ export type DuplicatePolicy = "keep" | "error" | "first" | "last" | "sum" | "min" | "max";
104
+
105
+ /** How the weights of merged edges combine in a derived graph or a merging freeze (design section 7.3). */
106
+ export type WeightReducer = "first" | "last" | "sum" | "min" | "max";
107
+
108
+ /**
109
+ * How an attribute column of merged rows combines in simplified() / contract(): a WeightReducer,
110
+ * the mean, the group size, or "drop" to omit the column (design section 7.3).
111
+ */
112
+ export type ColumnReducer = WeightReducer | "mean" | "count" | "drop";
113
+
114
+ /**
115
+ * Id coercion rule applied by importers before an id reaches the builder (design section 4.1):
116
+ * "keep" leaves typed values alone, "canonical" turns canonical integer text into a number and keeps
117
+ * everything else a string (injective on text), "string" and "number" force one type.
118
+ */
119
+ export type IdCoercion = "keep" | "canonical" | "string" | "number";
120
+
121
+ // ============================================================ columns
122
+
123
+ /**
124
+ * Column data types (design section 5.1). f32 / f64 / i32 / u32 / u8 are flat numeric buffers with
125
+ * an optional stride; bool is bit-packed u32 words (the Arrow boolean layout, shared with validity
126
+ * bitmaps and masks); dict is u32 codes plus a string dictionary; string is an Arrow Utf8 store; list
127
+ * is offsets plus one non-list child column; json is one JS value per row.
128
+ */
129
+ export type Dtype = "f32" | "f64" | "i32" | "u32" | "u8" | "bool" | "dict" | "string" | "list" | "json";
130
+
131
+ /** Every dtype a list column's child may have: lists nest one level only (design section 5.1). */
132
+ export type ScalarDtype = Exclude<Dtype, "list">;
133
+
134
+ /**
135
+ * The table a column belongs to: nodes (nodeCount rows), edges (edgeCount rows), graph (1 row) or an
136
+ * extension table with its own row count (design section 5.10).
137
+ */
138
+ export type ColumnDomain = "node" | "edge" | "graph" | "extension";
139
+
140
+ /**
141
+ * How a column reaches the GPU (design section 10.4): "direct" binds its data as is, "packed" binds
142
+ * u8 lanes or bool bits inside u32 words, "convert" binds a cached f32 copy of an f64 column, and
143
+ * "none" throws E_GPU_INELIGIBLE.
144
+ */
145
+ export type GpuEligibility = "direct" | "packed" | "convert" | "none";
146
+
147
+ /**
148
+ * The format-neutral roles the package and its importers recognise (design section 5.5): what a
149
+ * column means, independent of its name, so consumers find "the position column" without per-format
150
+ * knowledge and exporters map roles back to reserved fields. At most one column per role per table.
151
+ */
152
+ export type KnownColumnRole =
153
+ | "id"
154
+ | "label"
155
+ | "weight"
156
+ | "capacity"
157
+ | "position"
158
+ | "color"
159
+ | "size"
160
+ | "shape"
161
+ | "thickness"
162
+ | "parent"
163
+ | "parents"
164
+ | "kind"
165
+ | "labels"
166
+ | "classes"
167
+ | "start"
168
+ | "end"
169
+ | "timestamp"
170
+ | "timestamps"
171
+ | "spells"
172
+ | "open"
173
+ | "timeText"
174
+ | "key"
175
+ | "directed"
176
+ | "pair"
177
+ | "mutual"
178
+ | "originalId"
179
+ | "sourcePort"
180
+ | "targetPort"
181
+ | "idSpace"
182
+ | "fixed"
183
+ | "mass"
184
+ | "subset"
185
+ | "hidden"
186
+ | "component"
187
+ | "community"
188
+ | "rank";
189
+
190
+ /**
191
+ * A column role: the known roles plus any other string. The `(string & {})` intersection is the
192
+ * deliberate lint-clean spelling that keeps the literals alive for autocomplete (design section
193
+ * 12.1).
194
+ */
195
+ export type ColumnRole = KnownColumnRole | (string & {});
196
+
197
+ /**
198
+ * Where a column came from, so an exporter can restore the source declaration (design section 5.5).
199
+ * Every field is null when unknown.
200
+ */
201
+ export interface ColumnOrigin {
202
+ /** Source format name: "gexf", "graphml", "gml", "csv", ... */
203
+ readonly format: string | null;
204
+ /** GEXF attribute id or GraphML key id. */
205
+ readonly id: string | null;
206
+ /** GEXF title / GraphML attr.name when it differs from the column name. */
207
+ readonly title: string | null;
208
+ /** Declared source type text: "liststring", "anyURI", "long", "date", "int", "real", "yfiles". */
209
+ readonly type: string | null;
210
+ /** Declaring namespace: "viz", "yfiles", "neo4j". */
211
+ readonly namespace: string | null;
212
+ }
213
+
214
+ /** Input form of ColumnOrigin: every field optional and accepting an explicit undefined. */
215
+ export type ColumnOriginInput = Loose<ColumnOrigin>;
216
+
217
+ /**
218
+ * Input shape for declaring a column through declareNodeColumn / declareEdgeColumn / set() (design
219
+ * section 5.5). Optional fields take their documented defaults; ColumnMeta is the resolved output.
220
+ */
221
+ export interface ColumnDecl {
222
+ /** Unique within its table; case-sensitive; dotted names allowed (design section 5.6). */
223
+ name: string;
224
+ /** The column dtype (design section 5.1). */
225
+ dtype: Dtype;
226
+ /** Values per row for f32 / f64 / i32 / u32 / u8, 1..16; default 1 (design section 5.2). */
227
+ components?: number | undefined;
228
+ /** list only: the child dtype. */
229
+ itemDtype?: ScalarDtype | undefined;
230
+ /** list only: the child's components (spells: 2). */
231
+ itemComponents?: number | undefined;
232
+ /** Whether a validity bitmap may exist; default true for declared columns, false for typed bulk sets. */
233
+ nullable?: boolean | undefined;
234
+ /** Whether contents may be written in place on a snapshot (design section 5.8); default false. */
235
+ mutable?: boolean | undefined;
236
+ /** The column's role (design section 5.5); at most one column per role per table. */
237
+ role?: ColumnRole | undefined;
238
+ /** Marks a u32 column (or a list of u32) as holding indices that every remap rewrites (design section 5.11). */
239
+ refersTo?: "node" | "edge" | undefined;
240
+ /** Enforced at freeze over set rows (E_DUPLICATE_EDGE_ID / E_DUPLICATE_ID). */
241
+ unique?: boolean | undefined;
242
+ /** Declared default, a JSON value; non-finite numbers are allowed (design section 5.9). */
243
+ default?: unknown;
244
+ /** Value physically stored in unset rows; default: the declared default when representable, else 0 / "" / false. */
245
+ fill?: number | string | boolean | undefined;
246
+ /** Declared enumeration (GEXF options); for dict the initial dictionary. */
247
+ options?: readonly unknown[] | undefined;
248
+ /** Source declaration for exporters. */
249
+ origin?: ColumnOriginInput | undefined;
250
+ /** GEXF dynamic attribute: values live in a temporal extension table (design section 5.10). */
251
+ dynamic?: boolean | undefined;
252
+ /** Anything an importer wants to survive; must be JSON-serialisable. */
253
+ extra?: Readonly<Record<string, unknown>> | undefined;
254
+ }
255
+
256
+ /** Patch form of ColumnDecl: every field, including name and dtype, optional. */
257
+ export type ColumnDeclPatch = Loose<ColumnDecl>;
258
+
259
+ /**
260
+ * Output shape on every column: every field present, null for "none", never an optional property
261
+ * (design sections 5.5 and 12.1), so it reads identically under every compiler flag.
262
+ */
263
+ export interface ColumnMeta {
264
+ /** Unique within its table; case-sensitive. */
265
+ readonly name: string;
266
+ /** The table the column belongs to. */
267
+ readonly domain: ColumnDomain;
268
+ /** The column dtype. */
269
+ readonly dtype: Dtype;
270
+ /** Values per row; > 1 only for f32 / f64 / i32 / u32 / u8. */
271
+ readonly components: number;
272
+ /** list only: the child dtype; null otherwise. */
273
+ readonly itemDtype: ScalarDtype | null;
274
+ /** list only: the child's components; null otherwise. */
275
+ readonly itemComponents: number | null;
276
+ /** Whether a validity bitmap may exist. */
277
+ readonly nullable: boolean;
278
+ /** Whether contents may be written in place on a snapshot (design section 5.8). */
279
+ readonly mutable: boolean;
280
+ /** The column's role, or null. */
281
+ readonly role: ColumnRole | null;
282
+ /** Which index space the values reference, or null. */
283
+ readonly refersTo: "node" | "edge" | null;
284
+ /** Whether uniqueness over set rows is enforced at freeze. */
285
+ readonly unique: boolean;
286
+ /** The declared default; undefined when none was declared (returned by value() for unset rows). */
287
+ readonly default: unknown;
288
+ /** The value physically stored in unset rows. */
289
+ readonly fill: number | string | boolean;
290
+ /** The declared enumeration, or null. */
291
+ readonly options: readonly unknown[] | null;
292
+ /** The source declaration, or null. */
293
+ readonly origin: ColumnOrigin | null;
294
+ /** Whether the column is a GEXF dynamic attribute. */
295
+ readonly dynamic: boolean;
296
+ /** Importer-owned JSON-serialisable extras; an empty object when none. */
297
+ readonly extra: Readonly<Record<string, unknown>>;
298
+ }
299
+
300
+ /**
301
+ * Column data plus a declaration patch, the long form of a column value in *Input.nodeColumns / edgeColumns and
302
+ * withColumns().
303
+ */
304
+ export interface ColumnInput {
305
+ /** The values: a typed array for the numeric / bool dtypes, a JS array for string / list / json. */
306
+ readonly data: TypedArrayData | readonly unknown[];
307
+ /** The declaration; name and dtype may be omitted and inferred. */
308
+ readonly decl: ColumnDeclPatch;
309
+ }
310
+
311
+ /**
312
+ * Options of AttributeTable.set() (design section 5.7): replaceRole removes the previous holder of
313
+ * the role instead of throwing E_DUPLICATE_ROLE; adopt "strict" throws E_COLUMN_ALIGNMENT instead of
314
+ * copying a u8 array from which no zero-copy padded u32 view is constructible.
315
+ */
316
+ export interface SetOptions {
317
+ /** Remove the previous holder of the declared role instead of throwing E_DUPLICATE_ROLE. */
318
+ readonly replaceRole?: boolean | undefined;
319
+ /** "copy" (default) copies an unadoptable u8 array; "strict" throws E_COLUMN_ALIGNMENT instead. */
320
+ readonly adopt?: "copy" | "strict" | undefined;
321
+ }
322
+
323
+ /**
324
+ * What value(row) returns for a set row of each dtype (design section 5.3): a number (or a subarray
325
+ * when components > 1) for the numeric dtypes, a boolean for bool, a string for dict and string, a
326
+ * read-only array for list, and anything for json.
327
+ */
328
+ export type DtypeValue<D extends Dtype> = D extends "f32" | "f64" | "i32" | "u32" | "u8"
329
+ ? number | ArrayLike<number>
330
+ : D extends "bool"
331
+ ? boolean
332
+ : D extends "dict" | "string"
333
+ ? string
334
+ : D extends "list"
335
+ ? readonly unknown[]
336
+ : unknown;
337
+
338
+ /**
339
+ * Members shared by every column (design sections 5.3, 5.7 and 5.8). A column is immutable unless
340
+ * meta.mutable is true; the column SET of a table is always a mutable side table.
341
+ */
342
+ export interface ColumnBase<D extends Dtype> {
343
+ /** The dtype discriminator; narrowing on it selects the concrete column interface. */
344
+ readonly dtype: D;
345
+ /** Resolved metadata; every field present, null for none. */
346
+ readonly meta: ColumnMeta;
347
+ /** Number of rows. */
348
+ readonly length: number;
349
+ /** Validity bitmap: LSB-first words, ceil(length / 32); null means every row is set (design section 5.3). */
350
+ readonly validity: U32 | null;
351
+ /** Number of unset rows; kept exact by the setters. */
352
+ readonly nullCount: number;
353
+ /** GPU eligibility derived from the dtype (design section 10.4). */
354
+ readonly gpu: GpuEligibility;
355
+ /** Bytes of data plus validity. */
356
+ readonly byteLength: number;
357
+ /** byteLength, or roundUp(byteLength, 4) for u8: the size of paddedU32View() (design section 5.7). */
358
+ readonly paddedByteLength: number;
359
+ /** Bumped by markDirty(); lets a consumer cache derived data per column contents. */
360
+ readonly version: number;
361
+ /**
362
+ * Whether row `row` holds a value.
363
+ * @param row - the row index
364
+ * @returns true when the row is set (validity null or bit set)
365
+ */
366
+ isSet(row: number): boolean;
367
+ /**
368
+ * Typed read honouring meta.default; components > 1 returns a subarray view.
369
+ * @param row - the row index; E_INDEX_RANGE when out of range
370
+ * @returns the value, the declared default for an unset row, or undefined for an unset row without a default
371
+ */
372
+ value(row: number): DtypeValue<D> | undefined;
373
+ /**
374
+ * This column when fill equals the default; otherwise a cached copy with the default written into
375
+ * unset rows (invalidated by markDirty()).
376
+ * @returns a column whose data holds the default in every unset row; E_NO_DEFAULT when none is declared
377
+ */
378
+ materializeDefault(): ColumnOf<D>;
379
+ /**
380
+ * The u32 words a GPU binds: for u8 a zero-copy padded view over the column's byte range, for u32
381
+ * and bool the data itself.
382
+ * @returns the padded u32 view; E_GPU_INELIGIBLE for the other dtypes
383
+ */
384
+ paddedU32View(): U32;
385
+ /**
386
+ * Invalidate the cached gpuView() f32 copy and materializeDefault() copy after in-place writes and
387
+ * bump `version` (design section 5.8). Mutable columns only; E_COLUMN_IMMUTABLE otherwise.
388
+ */
389
+ markDirty(): void;
390
+ /**
391
+ * The validity bitmap itself, for owners that set rows one at a time. Mutable columns only.
392
+ * @returns the bitmap words, or null when every row is set
393
+ */
394
+ mutableValidity(): U32 | null;
395
+ /** Mark every row set: drops the bitmap and sets nullCount to 0. Mutable columns only. */
396
+ setAll(): void;
397
+ /**
398
+ * A column over the row range [start, end): zero-copy except packed stores at unaligned starts
399
+ * (design section 5.7).
400
+ * @param start - first row
401
+ * @param end - one past the last row
402
+ * @returns a column of the same dtype over the range
403
+ */
404
+ slice(start: number, end: number): ColumnOf<D>;
405
+ /**
406
+ * A deep copy of the column.
407
+ * @returns a new column of the same dtype with copied buffers
408
+ */
409
+ clone(): ColumnOf<D>;
410
+ }
411
+
412
+ /** f32 column: Float32Array(rows * components); GPU eligibility "direct". */
413
+ export interface F32Column extends ColumnBase<"f32"> {
414
+ /** The values, row-major, components interleaved. */
415
+ readonly data: F32;
416
+ /**
417
+ * The data array for in-place writes; mutable columns only (E_COLUMN_IMMUTABLE otherwise).
418
+ * @returns the same typed array as `data`
419
+ */
420
+ mutableData(): F32;
421
+ }
422
+
423
+ /** f64 column: Float64Array(rows * components); GPU eligibility "convert" (cached f32 copy). */
424
+ export interface F64Column extends ColumnBase<"f64"> {
425
+ /** The values, row-major, components interleaved. */
426
+ readonly data: F64;
427
+ /**
428
+ * The data array for in-place writes; mutable columns only (E_COLUMN_IMMUTABLE otherwise).
429
+ * @returns the same typed array as `data`
430
+ */
431
+ mutableData(): F64;
432
+ }
433
+
434
+ /** i32 column: Int32Array(rows * components); GPU eligibility "direct". */
435
+ export interface I32Column extends ColumnBase<"i32"> {
436
+ /** The values, row-major, components interleaved. */
437
+ readonly data: I32;
438
+ /**
439
+ * The data array for in-place writes; mutable columns only (E_COLUMN_IMMUTABLE otherwise).
440
+ * @returns the same typed array as `data`
441
+ */
442
+ mutableData(): I32;
443
+ }
444
+
445
+ /** u32 column: Uint32Array(rows * components); index references, labels, partitions; GPU eligibility "direct". */
446
+ export interface U32Column extends ColumnBase<"u32"> {
447
+ /** The values, row-major, components interleaved; INVALID_INDEX marks an unset refersTo entry. */
448
+ readonly data: U32;
449
+ /**
450
+ * The data array for in-place writes; mutable columns only (E_COLUMN_IMMUTABLE otherwise).
451
+ * @returns the same typed array as `data`
452
+ */
453
+ mutableData(): U32;
454
+ }
455
+
456
+ /**
457
+ * u8 column: Uint8Array(rows * components) over a store with a constructible padded u32 view; GPU eligibility "packed".
458
+ */
459
+ export interface U8Column extends ColumnBase<"u8"> {
460
+ /** The values, row-major, components interleaved. */
461
+ readonly data: U8;
462
+ /**
463
+ * The data array for in-place writes; mutable columns only (E_COLUMN_IMMUTABLE otherwise).
464
+ * @returns the same typed array as `data`
465
+ */
466
+ mutableData(): U8;
467
+ }
468
+
469
+ /** bool column: bit-packed, ceil(rows / 32) u32 words, LSB-first (the validity layout); GPU eligibility "packed". */
470
+ export interface BoolColumn extends ColumnBase<"bool"> {
471
+ /** The packed words; row r is `(data[r >>> 5] >>> (r & 31)) & 1`. */
472
+ readonly data: U32;
473
+ /**
474
+ * The packed words for in-place writes; mutable columns only (E_COLUMN_IMMUTABLE otherwise).
475
+ * @returns the same typed array as `data`
476
+ */
477
+ mutableData(): U32;
478
+ }
479
+
480
+ /** dict column: u32 codes into a string dictionary in first-seen (or declared) order (design section 5.4). */
481
+ export interface DictColumn extends ColumnBase<"dict"> {
482
+ /** One code per row, `< dictionary.length` for every set row. */
483
+ readonly codes: U32;
484
+ /** The dictionary; codes are dense 0..length-1. */
485
+ readonly dictionary: readonly string[];
486
+ /**
487
+ * The code of a dictionary value, via a lazily built reverse map.
488
+ * @param value - the string to look up
489
+ * @returns its code, or INVALID_INDEX when absent
490
+ */
491
+ codeOf(value: string): number;
492
+ /**
493
+ * The codes for in-place writes; mutable columns only (E_COLUMN_IMMUTABLE otherwise).
494
+ * @returns the same typed array as `codes`
495
+ */
496
+ mutableData(): U32;
497
+ }
498
+
499
+ /** string column: an Arrow Utf8 store (offsets + utf8) with a lazily decoded per-row cache (design section 5.1). */
500
+ export interface StringColumn extends ColumnBase<"string"> {
501
+ /** rows + 1 offsets into utf8, non-decreasing; materialised lazily from the decoded cache when needed. */
502
+ readonly offsets: U32;
503
+ /** The UTF-8 bytes of every row, concatenated. */
504
+ readonly utf8: U8;
505
+ /**
506
+ * The decoded string of one row, cached per row.
507
+ * @param row - the row index
508
+ * @returns the string (empty for an unset row)
509
+ */
510
+ valueAt(row: number): string;
511
+ /**
512
+ * Decode every row in one pass; not cached.
513
+ * @returns a fresh array of rows strings
514
+ */
515
+ decodeAll(): string[];
516
+ }
517
+
518
+ /** list column: rows + 1 offsets into one non-nullable child column of any dtype except list (design section 5.1). */
519
+ export interface ListColumn extends ColumnBase<"list"> {
520
+ /** rows + 1 offsets into the child, non-decreasing; unset and empty rows both have equal offsets. */
521
+ readonly offsets: U32;
522
+ /** The child column holding every item of every row; never nullable, never a list. */
523
+ readonly child: Exclude<Column, ListColumn>;
524
+ /**
525
+ * The items of one row, read through the child.
526
+ * @param row - the row index
527
+ * @returns the row's items; narrow the element type through child.dtype
528
+ */
529
+ sliceOf(row: number): readonly unknown[];
530
+ }
531
+
532
+ /** json column: one JS value per row, serialised as JSON text on the wire (design section 5.1). */
533
+ export interface JsonColumn extends ColumnBase<"json"> {
534
+ /** One value per row; undefined in unset rows. */
535
+ readonly values: readonly unknown[];
536
+ }
537
+
538
+ /** Every column shape, discriminated by `dtype`. */
539
+ export type Column =
540
+ | F32Column
541
+ | F64Column
542
+ | I32Column
543
+ | U32Column
544
+ | U8Column
545
+ | BoolColumn
546
+ | DictColumn
547
+ | StringColumn
548
+ | ListColumn
549
+ | JsonColumn;
550
+
551
+ /** The column interface of one dtype: `ColumnOf<"f32">` is F32Column. */
552
+ export type ColumnOf<D extends Dtype> = Extract<Column, { dtype: D }>;
553
+
554
+ /**
555
+ * A set of columns with a fixed row count (design section 5.7): `nodes` (nodeCount rows), `edges`
556
+ * (edgeCount rows), `graph` (1 row) and extension tables. The column SET is a mutable side table of
557
+ * the snapshot (set / remove / rename at any time); the row count is fixed (invariant I17). "Absent"
558
+ * is always null on this surface; undefined only ever means "unset row" from value(). Iteration
559
+ * yields columns in declaration order.
560
+ *
561
+ * Instance contract of the AttributeTable class in src/columns/table.ts, which implements it; the
562
+ * public barrel exports the class and every public type names the class.
563
+ */
564
+ export interface AttributeTableContract extends Iterable<Column> {
565
+ /** The table the columns belong to. */
566
+ readonly domain: ColumnDomain;
567
+ /** Number of rows of every column; fixed for the life of the table. */
568
+ readonly rowCount: number;
569
+ /**
570
+ * Column names in declaration order.
571
+ * @returns the names
572
+ */
573
+ names(): readonly string[];
574
+ /**
575
+ * Whether a column exists.
576
+ * @param name - the column name
577
+ * @returns true when present
578
+ */
579
+ has(name: string): boolean;
580
+ /**
581
+ * Total lookup by name.
582
+ * @param name - the column name
583
+ * @returns the column, or null when absent
584
+ */
585
+ get(name: string): Column | null;
586
+ /**
587
+ * Checked lookup by name.
588
+ * @param name - the column name
589
+ * @returns the column; E_UNKNOWN_COLUMN when absent
590
+ */
591
+ require(name: string): Column;
592
+ /**
593
+ * Total lookup by name and dtype.
594
+ * @param name - the column name
595
+ * @param dtype - the expected dtype
596
+ * @returns the column, or null when absent or of another dtype
597
+ */
598
+ typed<D extends Dtype>(name: string, dtype: D): ColumnOf<D> | null;
599
+ /**
600
+ * Checked lookup by name and dtype.
601
+ * @param name - the column name
602
+ * @param dtype - the expected dtype
603
+ * @returns the column; E_UNKNOWN_COLUMN when absent, E_COLUMN_TYPE when of another dtype
604
+ */
605
+ requireTyped<D extends Dtype>(name: string, dtype: D): ColumnOf<D>;
606
+ /**
607
+ * The column holding a role (at most one per table).
608
+ * @param role - the role
609
+ * @returns the column, or null when no column has the role
610
+ */
611
+ byRole(role: ColumnRole): Column | null;
612
+ /**
613
+ * Typed read of one cell honouring the column's declared default.
614
+ * @param name - the column name
615
+ * @param row - the row index; E_INDEX_RANGE when out of range
616
+ * @returns the value, the default for an unset row, or undefined for an unset row without a default
617
+ */
618
+ value(name: string, row: number): unknown;
619
+ /**
620
+ * Whether one cell holds a value.
621
+ * @param name - the column name
622
+ * @param row - the row index
623
+ * @returns true when set
624
+ */
625
+ isSet(name: string, row: number): boolean;
626
+ /**
627
+ * Attach a column, adopting a typed array by reference after validating its length
628
+ * (E_COLUMN_LENGTH), or move an existing Column object in. Replaces a column of the same name;
629
+ * E_DUPLICATE_ROLE when the role is taken and replaceRole is not set (design section 5.7).
630
+ * @param name - the column name
631
+ * @param data - a Column, a typed array, or a JS array for string / list / json
632
+ * @param decl - declaration fields to apply
633
+ * @param opts - role replacement and u8 adoption options
634
+ * @returns the attached column (`column.data !== data` only when a u8 array was copied)
635
+ */
636
+ set(
637
+ name: string,
638
+ data: Column | TypedArrayData | readonly unknown[],
639
+ decl?: ColumnDeclPatch,
640
+ opts?: SetOptions,
641
+ ): Column;
642
+ /**
643
+ * Remove a column.
644
+ * @param name - the column name
645
+ * @returns true when a column was removed
646
+ */
647
+ remove(name: string): boolean;
648
+ /**
649
+ * Rename a column in place.
650
+ * @param from - the current name; E_UNKNOWN_COLUMN when absent
651
+ * @param to - the new name
652
+ */
653
+ rename(from: string, to: string): void;
654
+ /**
655
+ * The array a GPU binds for a column (design section 10.4): its own data for the direct dtypes,
656
+ * the padded u32 view for u8, the packed words for bool, the codes for dict, and a cached f32 copy
657
+ * for f64.
658
+ * @param name - the column name
659
+ * @returns the bindable array; E_GPU_INELIGIBLE for string / list / json
660
+ */
661
+ gpuView(name: string): U32 | I32 | F32;
662
+ /**
663
+ * A new table with the same columns (the Column objects are shared, the set is independent).
664
+ * @returns the cloned table
665
+ */
666
+ clone(): AttributeTable;
667
+ /**
668
+ * Iterate the columns in declaration order.
669
+ * @returns an iterator over the columns
670
+ */
671
+ [Symbol.iterator](): IterableIterator<Column>;
672
+ }
673
+
674
+ /**
675
+ * Graph-level metadata (design section 5.9): what a file header declares, kept so exporters can
676
+ * re-emit it. Every field is null when unknown; `extra` must hold JSON values (non-finite numbers are
677
+ * carried on the wire through the tagged encoding of section 5.9).
678
+ */
679
+ export interface GraphMeta {
680
+ /** Graph name. */
681
+ readonly name: string | null;
682
+ /** Free-text description. */
683
+ readonly description: string | null;
684
+ /** Creator (GEXF meta creator). */
685
+ readonly creator: string | null;
686
+ /** Creation time, ISO-8601. */
687
+ readonly created: string | null;
688
+ /** Modification time, ISO-8601. */
689
+ readonly modified: string | null;
690
+ /** Keywords. */
691
+ readonly keywords: readonly string[];
692
+ /** Source format name, e.g. "gexf". */
693
+ readonly sourceFormat: string | null;
694
+ /** Source format version, e.g. "1.3". */
695
+ readonly sourceVersion: string | null;
696
+ /** GEXF idtype, for exporters. */
697
+ readonly idType: "string" | "integer" | "mixed" | null;
698
+ /** GEXF timeformat. */
699
+ readonly timeFormat: "integer" | "double" | "date" | "dateTime" | null;
700
+ /** GEXF 1.3 timerepresentation. */
701
+ readonly timeRepresentation: "interval" | "timestamp" | null;
702
+ /** GEXF graph mode. */
703
+ readonly mode: "static" | "dynamic" | "slice" | null;
704
+ /** The node-link / graphology "multigraph" flag as declared, independent of flags.multigraph. */
705
+ readonly declaredMultigraph: boolean | null;
706
+ /** Declared source type of the weight (design section 3.7). */
707
+ readonly weightOrigin: ColumnOrigin | null;
708
+ /** JSON-serialisable extras; reserved per-format keys in design section 8.5. */
709
+ readonly extra: Readonly<Record<string, unknown>>;
710
+ }
711
+
712
+ /** Patch form of GraphMeta for setMeta() and the *Input.meta fields. */
713
+ export type GraphMetaPatch = Loose<GraphMeta>;
714
+
715
+ // ============================================================ masks (packed bitmaps; not a snapshot contract)
716
+
717
+ /**
718
+ * Packed node bitmap: ceil(n / 32) words, bit i set means node i is included; the same layout as
719
+ * validity bitmaps and bool columns (design section 7.4). No kernel or algorithm is required to
720
+ * honour a mask; it is an input to inducedSubgraph() and an algorithm-internal scratch shape.
721
+ */
722
+ export type NodeMask = U32;
723
+
724
+ /**
725
+ * Packed edge bitmap over LOGICAL edges, ceil(edgeCount / 32) words; the input of filterEdges() (design section 7.4).
726
+ */
727
+ export type EdgeMask = U32;