@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,14 @@
1
+ /**
2
+ * Barrel of the public type surface (design section 12.2), split by concern across columns.ts
3
+ * (scalars, typed-array aliases, columns, tables, metadata, masks), snapshot.ts (id map, flags,
4
+ * arena, views, derived graphs, the snapshot contract, factory inputs), builder.ts (builder options,
5
+ * freeze report, handles, GraphSink, the builder contract) and wire.ts (the wire form). internal.ts
6
+ * is deliberately absent: its construction contracts are shared by the implementation modules only.
7
+ *
8
+ * Later modules import types from here: `import { type U32, type Column } from "../types/index.js"`.
9
+ */
10
+
11
+ export type * from "./builder.js";
12
+ export type * from "./columns.js";
13
+ export type * from "./snapshot.js";
14
+ export type * from "./wire.js";
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Construction contracts shared by the builder, columns, snapshot, populate and wire modules
3
+ * (derived from design sections 3, 5, 6.3 and 7). NOT part of the public surface: src/types/index.ts
4
+ * does not re-export this file, and nothing here is named in design section 12.2.
5
+ *
6
+ * The file exists so that the modules can be written in sequence without renegotiating names:
7
+ * freeze() (design section 6.3 step 12), fromCsr() and fromWire() / fromBytes() build a
8
+ * SnapshotParts and hand it to the snapshot constructor; freeze() step 10, AttributeTable.set() and
9
+ * the wire reader build one MutableColumnParts per column and hand it to the column factory of
10
+ * src/columns/column.ts; the snapshot keeps one ViewCache per instance.
11
+ */
12
+
13
+ import {
14
+ type AttributeTable,
15
+ type Column,
16
+ type ColumnDomain,
17
+ type ColumnMeta,
18
+ type F32,
19
+ type F64,
20
+ type GraphMeta,
21
+ type TypedArrayData,
22
+ type U8,
23
+ type U32,
24
+ } from "./columns.js";
25
+ import {
26
+ type ArenaLayout,
27
+ type CooView,
28
+ type DegreeOrderView,
29
+ type EdgeListView,
30
+ type NodeIdMap,
31
+ type ReverseView,
32
+ type SnapshotFlags,
33
+ type ViewName,
34
+ } from "./snapshot.js";
35
+
36
+ /**
37
+ * Everything the snapshot constructor needs (design sections 3.1 and 6.3 step 12). The producer has
38
+ * already established invariants I1-I13 (the builder by construction, fromCsr / fromWire by
39
+ * validation); the constructor freezes the object, records checksums when asked and allocates the
40
+ * per-instance view cache. No array here may alias memory a builder can still write (I18).
41
+ */
42
+ export interface SnapshotParts {
43
+ /** Debugging label supplied at freeze, or null. */
44
+ readonly label: string | null;
45
+ /**
46
+ * null: allocate a fresh process-unique serial; a number: share the core identity (withColumns(), design section
47
+ * 5.8).
48
+ */
49
+ readonly serial: number | null;
50
+ /** Whether the graph is directed. */
51
+ readonly directed: boolean;
52
+ /** n (invariant I3). */
53
+ readonly nodeCount: number;
54
+ /** Logical edge count. */
55
+ readonly edgeCount: number;
56
+ /** colIdx.length (invariants I1, I6, I7). */
57
+ readonly arcCount: number;
58
+ /** Logical edges with source === target. */
59
+ readonly selfLoopCount: number;
60
+ /** nodeCount + 1 row offsets. */
61
+ readonly rowPtr: U32;
62
+ /** arcCount targets, sorted within rows (I4); length 0 when arcCount === 0. */
63
+ readonly colIdx: U32;
64
+ /** arcCount f32 weights, or null when unweighted. */
65
+ readonly weights: F32 | null;
66
+ /**
67
+ * arcCount entries, or null exactly when flags.arcToEdgeIsIdentity (the snapshot materialises the identity on first
68
+ * access, outside the arena).
69
+ */
70
+ readonly arcToEdge: U32 | null;
71
+ /** edgeCount entries, or null exactly when flags.arcToEdgeIsIdentity. */
72
+ readonly edgeToArc: U32 | null;
73
+ /** Truthful flags computed by the producer (invariant I9). */
74
+ readonly flags: SnapshotFlags;
75
+ /** The id map, size === nodeCount (invariant I11). */
76
+ readonly ids: NodeIdMap;
77
+ /** Node table, rowCount === nodeCount (invariant I12). */
78
+ readonly nodes: AttributeTable;
79
+ /** Edge table, rowCount === edgeCount. */
80
+ readonly edges: AttributeTable;
81
+ /** Graph table, rowCount === 1. */
82
+ readonly graph: AttributeTable;
83
+ /** Extension tables keyed by name; may be empty. */
84
+ readonly extensions: ReadonlyMap<string, AttributeTable>;
85
+ /** Graph metadata, every field present. */
86
+ readonly meta: GraphMeta;
87
+ /** The arena the core arrays are views into, or null when they are separate buffers (design section 10.3). */
88
+ readonly arena: ArenaLayout | null;
89
+ /**
90
+ * Record FNV-1a checksums of the core arrays, immutable columns and views for validate({ checksum: true }) (design
91
+ * section 5.8).
92
+ */
93
+ readonly checksum: boolean;
94
+ }
95
+
96
+ /**
97
+ * The raw storage of one column before it is wrapped in a Column object (design sections 5.1, 5.3
98
+ * and 5.7). Every slot a dtype does not use is null. The column factory switches on meta.dtype and
99
+ * checks the length rules of design section 5.7; the producer (freeze step 10, AttributeTable.set,
100
+ * the wire reader) fills the slots and may keep mutating them until the wrap.
101
+ *
102
+ * Slot use per dtype: f32 / f64 / i32 / u32 / u8 -> data (rows * components values); bool -> data
103
+ * (ceil(rows / 32) packed U32 words); dict -> data (U32 codes) + dictionary; string -> offsets
104
+ * (rows + 1) + utf8, optionally strings (decoded cache, sparse); list -> offsets (rows + 1) + child;
105
+ * json -> values (rows entries).
106
+ */
107
+ export interface MutableColumnParts {
108
+ /** Resolved metadata; every field present. */
109
+ meta: ColumnMeta;
110
+ /** Number of rows. */
111
+ length: number;
112
+ /** Numeric values, packed bool words or dict codes; null for string / list / json. */
113
+ data: TypedArrayData | null;
114
+ /** Validity words, ceil(length / 32); null when every row is set. */
115
+ validity: U32 | null;
116
+ /** Number of unset rows; must agree with validity. */
117
+ nullCount: number;
118
+ /** dict only: the dictionary in code order. */
119
+ dictionary: string[] | null;
120
+ /** string / list only: rows + 1 non-decreasing offsets. */
121
+ offsets: U32 | null;
122
+ /** string only: the concatenated UTF-8 bytes. */
123
+ utf8: U8 | null;
124
+ /** string only: decoded rows, sparse (undefined = not yet decoded); null when none decoded. */
125
+ strings: (string | undefined)[] | null;
126
+ /** list only: the already wrapped, non-nullable, non-list child column. */
127
+ child: Column | null;
128
+ /** json only: one value per row, undefined in unset rows. */
129
+ values: unknown[] | null;
130
+ }
131
+
132
+ /**
133
+ * What the AttributeTable constructor takes: the domain, the fixed row count and the wrapped columns in declaration
134
+ * order.
135
+ */
136
+ export interface TableParts {
137
+ /** The table's domain. */
138
+ readonly domain: ColumnDomain;
139
+ /** Row count of every column; fixed for the life of the table. */
140
+ readonly rowCount: number;
141
+ /** The columns in declaration order; names unique, at most one column per role. */
142
+ readonly columns: readonly Column[];
143
+ }
144
+
145
+ /**
146
+ * The value each view name resolves to (design section 7.2). Keyed exactly by ViewName so that
147
+ * ViewCache, prepare(), cachedViews() and the wire includeViews option agree on the vocabulary
148
+ * (test/types/internal.test-d.ts asserts the key set).
149
+ */
150
+ export interface ViewValues {
151
+ /** In-adjacency (the forward arrays themselves when undirected). */
152
+ readonly reverse: ReverseView;
153
+ /** Per-arc COO. */
154
+ readonly coo: CooView;
155
+ /** Every logical edge once. */
156
+ readonly edgeList: EdgeListView;
157
+ /** Out-arc counts. */
158
+ readonly outDegree: U32;
159
+ /** In-arc counts (the outDegree object when undirected). */
160
+ readonly inDegree: U32;
161
+ /** Graph-theoretic degree. */
162
+ readonly degree: U32;
163
+ /** Row weight sums. */
164
+ readonly weightedOutDegree: F64;
165
+ /** Incoming weight sums. */
166
+ readonly weightedInDegree: F64;
167
+ /** NetworkX weighted degree. */
168
+ readonly weightedDegree: F64;
169
+ /** Self-loop weight per node. */
170
+ readonly selfLoopWeight: F64;
171
+ /** Sum of weights over logical edges. */
172
+ readonly totalWeight: number;
173
+ /** Arcs a with colIdx[a] === row(a). */
174
+ readonly selfLoopArcs: U32;
175
+ /** Self-loop arcs per node. */
176
+ readonly selfLoopsPerNode: U32;
177
+ /** Opposite-orientation arc per arc (undirected only). */
178
+ readonly mate: U32;
179
+ /** degreeOrder({ of: "forward" }). */
180
+ readonly degreeOrder: DegreeOrderView;
181
+ /** degreeOrder({ of: "reverse" }). */
182
+ readonly reverseDegreeOrder: DegreeOrderView;
183
+ /** isSymmetric(). */
184
+ readonly symmetric: boolean;
185
+ }
186
+
187
+ /**
188
+ * The per-instance, per-realm cache of lazily computed views (design section 7.2, invariant I17):
189
+ * one writable slot per ViewName, null until first materialisation. Every slot holds the object the
190
+ * public method returns (SHARED, never copied); dropCaches() nulls every slot; cachedViews() lists
191
+ * the non-null ones. Views are pure functions of the core, so a slot is never invalidated, only
192
+ * dropped. The lazily materialised identity permutations of design section 3.1 are not views and
193
+ * are kept by the snapshot separately.
194
+ */
195
+ export type ViewCache = { -readonly [K in ViewName]: ViewValues[K] | null };