@modernrelay/orbit-data 0.13.6 → 0.15.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.
- package/dist/arrow.d.ts +4 -4
- package/dist/arrow.js +8 -3
- package/dist/arrow.js.map +1 -1
- package/dist/{chunk-BMWDY6DA.js → chunk-JWGHZW7P.js} +2 -2
- package/dist/chunk-JWGHZW7P.js.map +1 -0
- package/dist/{chunk-YOKSBVNI.js → chunk-XXC2CUXZ.js} +183 -89
- package/dist/chunk-XXC2CUXZ.js.map +1 -0
- package/dist/index.d.ts +18 -18
- package/dist/index.js +151 -64
- package/dist/index.js.map +1 -1
- package/dist/parquet.d.ts +3 -3
- package/dist/parquet.js +8 -3
- package/dist/parquet.js.map +1 -1
- package/dist/{types-Bf3sle3D.d.ts → types-D4HC4ECy.d.ts} +4 -4
- package/package.json +2 -2
- package/dist/chunk-BMWDY6DA.js.map +0 -1
- package/dist/chunk-YOKSBVNI.js.map +0 -1
package/dist/arrow.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { G as GraphByteSource, a as GraphColumnMapping, b as GraphPrepareOptions, P as PreparedGraph } from './types-
|
|
1
|
+
import { G as GraphByteSource, a as GraphColumnMapping, b as GraphPrepareOptions, P as PreparedGraph } from './types-D4HC4ECy.js';
|
|
2
2
|
import '@modernrelay/orbit-core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Arrow format entry
|
|
5
|
+
* Arrow format entry — `@modernrelay/orbit-data/arrow`.
|
|
6
6
|
*
|
|
7
|
-
* NEVER imported by the root entry
|
|
7
|
+
* NEVER imported by the root entry: the
|
|
8
8
|
* 'apache-arrow' optional peer is loaded with a DYNAMIC import inside the
|
|
9
9
|
* call, so this module is import-safe without it (the clear install-hint
|
|
10
10
|
* error fires only when preparation actually runs), and root-entry bundles
|
|
11
11
|
* carry no arrow code.
|
|
12
12
|
*
|
|
13
|
-
* Sources per role are Arrow IPC bytes (file or stream framing
|
|
13
|
+
* Sources per role are Arrow IPC bytes (file or stream framing
|
|
14
14
|
* Blob/ArrayBuffer/AsyncIterable<Uint8Array>) or an already-constructed
|
|
15
15
|
* arrow Table (duck-typed via `schema.fields`). Tables become row objects
|
|
16
16
|
* through `getChild` vectors and feed the shared builder; columns come from
|
package/dist/arrow.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { normalizeJsonSafeValue } from './chunk-
|
|
2
|
-
import { buildPrepared, collectBytes, EMPTY_ROW_TABLE } from './chunk-
|
|
1
|
+
import { normalizeJsonSafeValue } from './chunk-JWGHZW7P.js';
|
|
2
|
+
import { buildPrepared, collectBytes, EMPTY_ROW_TABLE } from './chunk-XXC2CUXZ.js';
|
|
3
3
|
|
|
4
4
|
// src/arrow.ts
|
|
5
5
|
var _internals = {
|
|
@@ -53,7 +53,12 @@ async function arrowRowTable(source, arrow, signal) {
|
|
|
53
53
|
for (let j = 0; j < columns.length; j++) {
|
|
54
54
|
const value = vectors[j]?.get(i);
|
|
55
55
|
if (value === null || value === void 0) continue;
|
|
56
|
-
row
|
|
56
|
+
Object.defineProperty(row, columns[j], {
|
|
57
|
+
value: normalizeArrowValue(value),
|
|
58
|
+
enumerable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
configurable: true
|
|
61
|
+
});
|
|
57
62
|
}
|
|
58
63
|
yield row;
|
|
59
64
|
}
|
package/dist/arrow.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/arrow.ts"],"names":[],"mappings":";;;;AA4CO,IAAM,UAAA,GAAa;AAAA,EACxB,WAAA,EAAa,MAAwB,OAAO,cAAc;AAC5D;AAEA,eAAe,eAAA,GAEZ;AACD,EAAA,IAAI,GAAA;AACJ,EAAA,IAAI;AACF,IAAA,GAAA,GAAM,MAAM,WAAW,WAAA,EAAY;AAAA,EACrC,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,6JAAA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,GAAU,MAAM,MAAA,CAAO,MAAA,CAAO,IAAI,CAAC,CAAA,KAAM,EAAE,IAAI,CAAA;AACrD,EAAA,IAAI,QAAQ,MAAA,KAAW,CAAA,IAAK,KAAA,CAAM,OAAA,KAAY,GAAG,OAAO,eAAA;AACxD,EAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,CAAC,SAAS,KAAA,CAAM,QAAA,CAAS,IAAI,CAAC,CAAA;AAC1D,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,OAAO,mBAAmB;AACxB,MAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,KAAA,CAAM,SAAS,CAAA,EAAA,EAAK;AACtC,QAAA,MAAM,MAA+B,EAAC;AACtC,QAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,OAAA,CAAQ,QAAQ,CAAA,EAAA,EAAK;AACvC,UAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,CAAC,CAAA,EAAG,IAAI,CAAC,CAAA;AAC/B,UAAA,IAAI,KAAA,KAAU,IAAA,IAAQ,KAAA,KAAU,MAAA,EAAW;AAG3C,UAAA,MAAA,CAAO,cAAA,CAAe,GAAA,EAAK,OAAA,CAAQ,CAAC,CAAA,EAAI;AAAA,YACtC,KAAA,EAAO,oBAAoB,KAAK,CAAA;AAAA,YAChC,UAAA,EAAY,IAAA;AAAA,YACZ,QAAA,EAAU,IAAA;AAAA,YACV,YAAA,EAAc;AAAA,WACf,CAAA;AAAA,QACH;AACA,QAAA,MAAM,GAAA;AAAA,MACR;AAAA,IACF,CAAA;AAAG,GACL;AACF;AAEA,IAAM,mBAAA,GAAsB,sBAAA","file":"arrow.js","sourcesContent":["/**\n * Arrow format entry — `@modernrelay/orbit-data/arrow`.\n *\n * NEVER imported by the root entry: the\n * 'apache-arrow' optional peer is loaded with a DYNAMIC import inside the\n * call, so this module is import-safe without it (the clear install-hint\n * error fires only when preparation actually runs), and root-entry bundles\n * carry no arrow code.\n *\n * Sources per role are Arrow IPC bytes (file or stream framing\n * Blob/ArrayBuffer/AsyncIterable<Uint8Array>) or an already-constructed\n * arrow Table (duck-typed via `schema.fields`). Tables become row objects\n * through `getChild` vectors and feed the shared builder; columns come from\n * the SCHEMA (exact, not sampled). Value normalization for the object lane:\n * arrow nulls → absent keys, bigints → number when safely representable else\n * decimal string (JSON-safe artifacts), everything else passes through.\n */\n\nimport { normalizeJsonSafeValue } from './jsonSafe';\n\nimport { buildPrepared } from './builder';\nimport { EMPTY_ROW_TABLE, type RowTable } from './rowTable';\nimport { collectBytes } from './sources';\nimport type {\n GraphByteSource,\n GraphColumnMapping,\n GraphPrepareOptions,\n PreparedGraph,\n} from './types';\n\n/** Structural subset of an apache-arrow Table (any supported major). */\nexport interface ArrowTableLike {\n readonly numRows: number;\n readonly schema: { readonly fields: ReadonlyArray<{ readonly name: string }> };\n getChild(name: string): { get(index: number): unknown } | null;\n}\n\nexport type ArrowGraphSource = GraphByteSource | ArrowTableLike;\n\nexport type ArrowGraphPrepareInput =\n | { nodes: ArrowGraphSource; edges: ArrowGraphSource }\n | { edges: ArrowGraphSource; deriveNodes: true };\n\n/** Test seam: lets suites simulate the missing-optional-dependency path. */\nexport const _internals = {\n importArrow: (): Promise<unknown> => import('apache-arrow'),\n};\n\nasync function loadArrowModule(): Promise<{\n tableFromIPC(bytes: Uint8Array): ArrowTableLike;\n}> {\n let mod: unknown;\n try {\n mod = await _internals.importArrow();\n } catch (cause) {\n throw new Error(\n \"@modernrelay/orbit-data/arrow requires the optional peer dependency 'apache-arrow'. \" +\n 'Install it (e.g. `pnpm add apache-arrow`) to use prepareArrowGraphData.',\n { cause },\n );\n }\n const tableFromIPC = (mod as Record<string, unknown>)['tableFromIPC'];\n if (typeof tableFromIPC !== 'function') {\n throw new Error(\n \"@modernrelay/orbit-data/arrow: the installed 'apache-arrow' does not expose tableFromIPC \" +\n '(unsupported version?)',\n );\n }\n return { tableFromIPC: tableFromIPC as (bytes: Uint8Array) => ArrowTableLike };\n}\n\nexport async function prepareArrowGraphData<\n N = Record<string, unknown>,\n E = Record<string, unknown>,\n>(\n input: ArrowGraphPrepareInput,\n mapping: GraphColumnMapping,\n options: Omit<GraphPrepareOptions, 'format'>,\n): Promise<PreparedGraph<N, E>> {\n const arrow = await loadArrowModule();\n const signal = options.signal;\n const deriveNodes = 'deriveNodes' in input && input.deriveNodes === true;\n const edgeTable = await arrowRowTable(input.edges, arrow, signal);\n const nodeTable = deriveNodes\n ? null\n : await arrowRowTable((input as { nodes: ArrowGraphSource }).nodes, arrow, signal);\n return (await buildPrepared({\n nodeTable,\n edgeTable,\n mapping,\n format: 'arrow',\n options: { ...options, format: 'arrow' },\n })) as PreparedGraph<N, E>;\n}\n\nfunction isArrowTable(source: ArrowGraphSource): source is ArrowTableLike {\n return (\n typeof source === 'object' &&\n source !== null &&\n 'schema' in source &&\n typeof (source as ArrowTableLike).getChild === 'function' &&\n Array.isArray((source as ArrowTableLike).schema?.fields)\n );\n}\n\nasync function arrowRowTable(\n source: ArrowGraphSource,\n arrow: { tableFromIPC(bytes: Uint8Array): ArrowTableLike },\n signal: AbortSignal | undefined,\n): Promise<RowTable> {\n const table = isArrowTable(source)\n ? source\n : arrow.tableFromIPC(await collectBytes(source as GraphByteSource, signal));\n const columns = table.schema.fields.map((f) => f.name);\n if (columns.length === 0 && table.numRows === 0) return EMPTY_ROW_TABLE;\n const vectors = columns.map((name) => table.getChild(name));\n return {\n columns,\n rows: (async function* () {\n for (let i = 0; i < table.numRows; i++) {\n const row: Record<string, unknown> = {};\n for (let j = 0; j < columns.length; j++) {\n const value = vectors[j]?.get(i);\n if (value === null || value === undefined) continue; // arrow null → absent\n // Arrow schemas may legally contain a `__proto__` column. Plain\n // assignment would invoke the legacy prototype setter and lose it.\n Object.defineProperty(row, columns[j]!, {\n value: normalizeArrowValue(value),\n enumerable: true,\n writable: true,\n configurable: true,\n });\n }\n yield row;\n }\n })(),\n };\n}\n\nconst normalizeArrowValue = normalizeJsonSafeValue;\n"]}
|
|
@@ -20,5 +20,5 @@ function normalizeJsonSafeValue(value) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export { normalizeJsonSafeValue };
|
|
23
|
-
//# sourceMappingURL=chunk-
|
|
24
|
-
//# sourceMappingURL=chunk-
|
|
23
|
+
//# sourceMappingURL=chunk-JWGHZW7P.js.map
|
|
24
|
+
//# sourceMappingURL=chunk-JWGHZW7P.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/jsonSafe.ts"],"names":[],"mappings":";AAQO,SAAS,uBAAuB,KAAA,EAAyB;AAC9D,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,KAAA,IAAS,MAAA,CAAO,MAAA,CAAO,gBAAgB,KAAK,KAAA,IAAS,MAAA,CAAO,MAAA,CAAO,gBAAgB,CAAA,GACtF,MAAA,CAAO,KAAK,CAAA,GACZ,MAAM,QAAA,EAAS;AAAA,EACrB;AACA,EAAA,IAAI,MAAM,OAAA,CAAQ,KAAK,GAAG,OAAO,KAAA,CAAM,IAAI,sBAAsB,CAAA;AACjE,EAAA,IAAI,UAAU,IAAA,IAAQ,OAAO,UAAU,QAAA,IAAY,KAAA,CAAM,gBAAgB,MAAA,EAAQ;AAC/E,IAAA,MAAM,MAA+B,EAAC;AACtC,IAAA,KAAA,MAAW,CAAC,CAAA,EAAG,CAAC,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAC1C,MAAA,MAAA,CAAO,cAAA,CAAe,KAAK,CAAA,EAAG;AAAA,QAC5B,KAAA,EAAO,uBAAuB,CAAC,CAAA;AAAA,QAC/B,UAAA,EAAY,IAAA;AAAA,QACZ,QAAA,EAAU,IAAA;AAAA,QACV,YAAA,EAAc;AAAA,OACf,CAAA;AAAA,IACH;AACA,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA;AACT","file":"chunk-JWGHZW7P.js","sourcesContent":["/**\n * Shared JSON-safe value normalization for the optional format parsers:\n * Arrow/Parquet scalar decoding surfaces BigInt, and LIST/\n * STRUCT columns surface arrays/objects whose LEAVES can be BigInt — a\n * shallow pass broke the promised JSON-safe `serializePrepared` path.\n * Safe integers become numbers, the rest become strings, containers\n * recurse; '__proto__' keys land as own properties (never the setter).\n */\nexport function normalizeJsonSafeValue(value: unknown): unknown {\n if (typeof value === 'bigint') {\n return value >= BigInt(Number.MIN_SAFE_INTEGER) && value <= BigInt(Number.MAX_SAFE_INTEGER)\n ? Number(value)\n : value.toString();\n }\n if (Array.isArray(value)) return value.map(normalizeJsonSafeValue);\n if (value !== null && typeof value === 'object' && value.constructor === Object) {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(value)) {\n Object.defineProperty(out, k, {\n value: normalizeJsonSafeValue(v),\n enumerable: true,\n writable: true,\n configurable: true,\n });\n }\n return out;\n }\n return value;\n}\n"]}
|
|
@@ -208,104 +208,140 @@ function formatColumns(columns) {
|
|
|
208
208
|
// src/builder.ts
|
|
209
209
|
async function buildPrepared(args) {
|
|
210
210
|
const { nodeTable, edgeTable, mapping, format, options } = args;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
211
|
+
let failed = false;
|
|
212
|
+
try {
|
|
213
|
+
validateOptions(options);
|
|
214
|
+
validateMapping({
|
|
215
|
+
mapping,
|
|
216
|
+
nodeColumns: nodeTable === null ? null : nodeTable.columns,
|
|
217
|
+
edgeColumns: edgeTable.columns,
|
|
218
|
+
deriveNodes: nodeTable === null
|
|
219
|
+
});
|
|
220
|
+
const nodeSummarizer = new TableSummarizer();
|
|
221
|
+
const edgeSummarizer = new TableSummarizer();
|
|
222
|
+
const edgeIdentity = new Set(
|
|
223
|
+
[mapping.edges.id, mapping.edges.source, mapping.edges.target].filter(
|
|
224
|
+
(c) => c !== void 0
|
|
225
|
+
)
|
|
226
|
+
);
|
|
227
|
+
const edgeAttrPick = attrPicker(edgeTable.columns, edgeIdentity, mapping.edges.includeFields);
|
|
228
|
+
if (edgeTable.columns !== null) {
|
|
229
|
+
edgeSummarizer.seed(edgeAttrPick.seedColumns);
|
|
230
|
+
for (const column of edgeAttrPick.seedColumns) edgeAttrPick.admitted.add(column);
|
|
231
|
+
}
|
|
232
|
+
const edges = [];
|
|
233
|
+
const endpointOrder = /* @__PURE__ */ new Set();
|
|
234
|
+
let edgeOrdinal = 0;
|
|
235
|
+
for await (const row of edgeTable.rows) {
|
|
236
|
+
const source = identityString(
|
|
237
|
+
row[mapping.edges.source],
|
|
238
|
+
"edge source",
|
|
239
|
+
edgeOrdinal,
|
|
240
|
+
mapping.edges.source,
|
|
241
|
+
true
|
|
242
|
+
);
|
|
243
|
+
const target = identityString(
|
|
244
|
+
row[mapping.edges.target],
|
|
245
|
+
"edge target",
|
|
246
|
+
edgeOrdinal,
|
|
247
|
+
mapping.edges.target,
|
|
248
|
+
true
|
|
249
|
+
);
|
|
250
|
+
const edge = { source, target };
|
|
251
|
+
if (mapping.edges.id !== void 0) {
|
|
252
|
+
const raw = row[mapping.edges.id];
|
|
253
|
+
if (raw !== void 0 && raw !== null) {
|
|
254
|
+
edge.id = identityString(raw, "edge id", edgeOrdinal, mapping.edges.id, true);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const attrs = edgeAttrPick.pick(row);
|
|
258
|
+
if (attrs !== void 0) edge.attrs = attrs;
|
|
259
|
+
edgeSummarizer.addRow(attrs);
|
|
260
|
+
edges.push(edge);
|
|
261
|
+
if (nodeTable === null) {
|
|
262
|
+
endpointOrder.add(source);
|
|
263
|
+
endpointOrder.add(target);
|
|
241
264
|
}
|
|
265
|
+
edgeOrdinal++;
|
|
242
266
|
}
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
edgeSummarizer.addRow(attrs);
|
|
246
|
-
edges.push(edge);
|
|
267
|
+
const nodes = [];
|
|
268
|
+
let nodeAdmitted = /* @__PURE__ */ new Set();
|
|
247
269
|
if (nodeTable === null) {
|
|
248
|
-
endpointOrder.
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
270
|
+
for (const id of endpointOrder) nodes.push({ id });
|
|
271
|
+
} else {
|
|
272
|
+
const nodeMapping = mapping.nodes;
|
|
273
|
+
const nodeIdentity = /* @__PURE__ */ new Set([nodeMapping.id]);
|
|
274
|
+
const nodeAttrPick = attrPicker(nodeTable.columns, nodeIdentity, nodeMapping.includeFields);
|
|
275
|
+
nodeAdmitted = nodeAttrPick.admitted;
|
|
276
|
+
if (nodeTable.columns !== null) {
|
|
277
|
+
nodeSummarizer.seed(nodeAttrPick.seedColumns);
|
|
278
|
+
for (const column of nodeAttrPick.seedColumns) nodeAttrPick.admitted.add(column);
|
|
279
|
+
}
|
|
280
|
+
let nodeOrdinal = 0;
|
|
281
|
+
for await (const row of nodeTable.rows) {
|
|
282
|
+
const id = identityString(row[nodeMapping.id], "node id", nodeOrdinal, nodeMapping.id, true);
|
|
283
|
+
const node = { id };
|
|
284
|
+
const attrs = nodeAttrPick.pick(row);
|
|
285
|
+
if (attrs !== void 0) node.attrs = attrs;
|
|
286
|
+
nodeSummarizer.addRow(attrs);
|
|
287
|
+
nodes.push(node);
|
|
288
|
+
nodeOrdinal++;
|
|
289
|
+
}
|
|
265
290
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
nodes
|
|
274
|
-
|
|
291
|
+
const mappingFingerprint = computeMappingFingerprint(mapping, format, {
|
|
292
|
+
nodes: [...nodeAdmitted],
|
|
293
|
+
edges: [...edgeAttrPick.admitted]
|
|
294
|
+
});
|
|
295
|
+
const snapshot = {
|
|
296
|
+
datasetKey: options.datasetKey,
|
|
297
|
+
sourceRevision: options.sourceRevision,
|
|
298
|
+
nodes,
|
|
299
|
+
edges
|
|
300
|
+
};
|
|
301
|
+
return {
|
|
302
|
+
snapshot,
|
|
303
|
+
summaries: { nodes: nodeSummarizer.finalize(), edges: edgeSummarizer.finalize() },
|
|
304
|
+
mappingFingerprint
|
|
305
|
+
};
|
|
306
|
+
} catch (cause) {
|
|
307
|
+
failed = true;
|
|
308
|
+
throw cause;
|
|
309
|
+
} finally {
|
|
310
|
+
const closes = await Promise.allSettled([
|
|
311
|
+
Promise.resolve().then(() => edgeTable.close?.()),
|
|
312
|
+
Promise.resolve().then(() => nodeTable?.close?.())
|
|
313
|
+
]);
|
|
314
|
+
if (!failed) {
|
|
315
|
+
const rejected = closes.find(
|
|
316
|
+
(result) => result.status === "rejected"
|
|
317
|
+
);
|
|
318
|
+
if (rejected !== void 0) throw rejected.reason;
|
|
275
319
|
}
|
|
276
320
|
}
|
|
277
|
-
const mappingFingerprint = computeMappingFingerprint(mapping, format, {
|
|
278
|
-
nodes: [...nodeAdmitted],
|
|
279
|
-
edges: [...edgeAttrPick.admitted]
|
|
280
|
-
});
|
|
281
|
-
const snapshot = {
|
|
282
|
-
datasetKey: options.datasetKey,
|
|
283
|
-
sourceRevision: options.sourceRevision,
|
|
284
|
-
nodes,
|
|
285
|
-
edges
|
|
286
|
-
};
|
|
287
|
-
return {
|
|
288
|
-
snapshot,
|
|
289
|
-
summaries: { nodes: nodeSummarizer.finalize(), edges: edgeSummarizer.finalize() },
|
|
290
|
-
mappingFingerprint
|
|
291
|
-
};
|
|
292
321
|
}
|
|
293
322
|
function validateOptions(options) {
|
|
294
323
|
if (typeof options.datasetKey !== "string" || options.datasetKey === "") {
|
|
295
324
|
throw new TypeError("prepareGraphData: options.datasetKey must be a non-empty string");
|
|
296
325
|
}
|
|
297
326
|
const rev = options.sourceRevision;
|
|
298
|
-
if (typeof rev !== "string" && typeof rev !== "number") {
|
|
299
|
-
throw new TypeError(
|
|
327
|
+
if (typeof rev !== "string" && typeof rev !== "number" || typeof rev === "number" && !Number.isFinite(rev)) {
|
|
328
|
+
throw new TypeError(
|
|
329
|
+
"prepareGraphData: options.sourceRevision must be a string or finite number"
|
|
330
|
+
);
|
|
300
331
|
}
|
|
301
332
|
}
|
|
302
|
-
function identityString(value, role, ordinal, column) {
|
|
333
|
+
function identityString(value, role, ordinal, column, rejectNul = false) {
|
|
303
334
|
if (typeof value === "string") {
|
|
304
335
|
if (value === "") {
|
|
305
336
|
throw new TypeError(
|
|
306
337
|
`prepareGraphData: ${role} in column ${JSON.stringify(column)} is empty at row ${ordinal}`
|
|
307
338
|
);
|
|
308
339
|
}
|
|
340
|
+
if (rejectNul && value.includes("\0")) {
|
|
341
|
+
throw new TypeError(
|
|
342
|
+
`prepareGraphData: ${role} in column ${JSON.stringify(column)} contains reserved NUL at row ${ordinal}`
|
|
343
|
+
);
|
|
344
|
+
}
|
|
309
345
|
return value;
|
|
310
346
|
}
|
|
311
347
|
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
@@ -386,29 +422,87 @@ function isBlob(value) {
|
|
|
386
422
|
function isAsyncIterable(value) {
|
|
387
423
|
return typeof value === "object" && value !== null && typeof value[Symbol.asyncIterator] === "function";
|
|
388
424
|
}
|
|
425
|
+
function iteratorCloseOnce(iterator) {
|
|
426
|
+
let closePromise;
|
|
427
|
+
return () => {
|
|
428
|
+
closePromise ??= (async () => {
|
|
429
|
+
await iterator.return?.();
|
|
430
|
+
})();
|
|
431
|
+
return closePromise;
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
async function* closingIterable(source) {
|
|
435
|
+
const iterator = source[Symbol.asyncIterator]();
|
|
436
|
+
const close = iteratorCloseOnce(iterator);
|
|
437
|
+
let exhausted = false;
|
|
438
|
+
let failed = false;
|
|
439
|
+
try {
|
|
440
|
+
while (true) {
|
|
441
|
+
const next = await iterator.next();
|
|
442
|
+
if (next.done) {
|
|
443
|
+
exhausted = true;
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
yield next.value;
|
|
447
|
+
}
|
|
448
|
+
} catch (cause) {
|
|
449
|
+
failed = true;
|
|
450
|
+
throw cause;
|
|
451
|
+
} finally {
|
|
452
|
+
if (!exhausted) {
|
|
453
|
+
try {
|
|
454
|
+
await close();
|
|
455
|
+
} catch (closeCause) {
|
|
456
|
+
if (!failed) throw closeCause;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
389
461
|
async function peekAsyncIterable(source) {
|
|
390
462
|
const iterator = source[Symbol.asyncIterator]();
|
|
391
|
-
const
|
|
463
|
+
const close = iteratorCloseOnce(iterator);
|
|
464
|
+
let head;
|
|
465
|
+
try {
|
|
466
|
+
head = await iterator.next();
|
|
467
|
+
} catch (cause) {
|
|
468
|
+
try {
|
|
469
|
+
await close();
|
|
470
|
+
} catch {
|
|
471
|
+
}
|
|
472
|
+
throw cause;
|
|
473
|
+
}
|
|
392
474
|
const first = head.done ? void 0 : head.value;
|
|
393
475
|
async function* replay() {
|
|
476
|
+
let exhausted = head.done === true;
|
|
477
|
+
let failed = false;
|
|
394
478
|
try {
|
|
395
479
|
if (!head.done) yield head.value;
|
|
396
480
|
while (true) {
|
|
397
481
|
const next = await iterator.next();
|
|
398
|
-
if (next.done)
|
|
482
|
+
if (next.done) {
|
|
483
|
+
exhausted = true;
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
399
486
|
yield next.value;
|
|
400
487
|
}
|
|
488
|
+
} catch (cause) {
|
|
489
|
+
failed = true;
|
|
490
|
+
throw cause;
|
|
401
491
|
} finally {
|
|
402
|
-
|
|
492
|
+
if (!exhausted) {
|
|
493
|
+
try {
|
|
494
|
+
await close();
|
|
495
|
+
} catch (closeCause) {
|
|
496
|
+
if (!failed) throw closeCause;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
403
499
|
}
|
|
404
500
|
}
|
|
405
501
|
return {
|
|
406
502
|
first,
|
|
407
503
|
done: head.done === true,
|
|
408
504
|
rest: replay(),
|
|
409
|
-
close
|
|
410
|
-
await iterator.return?.();
|
|
411
|
-
}
|
|
505
|
+
close
|
|
412
506
|
};
|
|
413
507
|
}
|
|
414
508
|
function byteChunks(source, signal) {
|
|
@@ -422,14 +516,14 @@ function byteChunks(source, signal) {
|
|
|
422
516
|
if (isBlob(source)) {
|
|
423
517
|
return (async function* () {
|
|
424
518
|
const stream = source.stream();
|
|
425
|
-
for await (const chunk of stream) {
|
|
519
|
+
for await (const chunk of closingIterable(stream)) {
|
|
426
520
|
throwIfAborted(signal);
|
|
427
521
|
yield chunk;
|
|
428
522
|
}
|
|
429
523
|
})();
|
|
430
524
|
}
|
|
431
525
|
return (async function* () {
|
|
432
|
-
for await (const chunk of source) {
|
|
526
|
+
for await (const chunk of closingIterable(source)) {
|
|
433
527
|
throwIfAborted(signal);
|
|
434
528
|
if (!(chunk instanceof Uint8Array)) {
|
|
435
529
|
throw new TypeError(
|
|
@@ -467,7 +561,7 @@ function rowStream(source, signal) {
|
|
|
467
561
|
}
|
|
468
562
|
if (isAsyncIterable(source)) {
|
|
469
563
|
return (async function* () {
|
|
470
|
-
for await (const row of source) {
|
|
564
|
+
for await (const row of closingIterable(source)) {
|
|
471
565
|
throwIfAborted(signal);
|
|
472
566
|
yield row;
|
|
473
567
|
}
|
|
@@ -479,5 +573,5 @@ function rowStream(source, signal) {
|
|
|
479
573
|
}
|
|
480
574
|
|
|
481
575
|
export { EMPTY_ROW_TABLE, buildPrepared, byteChunks, canonicalJson, collectBytes, computeMappingFingerprint, fnv1a64Hex, isAsyncIterable, isBlob, isPlainRowObject, peekAsyncIterable, rowStream, throwIfAborted };
|
|
482
|
-
//# sourceMappingURL=chunk-
|
|
483
|
-
//# sourceMappingURL=chunk-
|
|
576
|
+
//# sourceMappingURL=chunk-XXC2CUXZ.js.map
|
|
577
|
+
//# sourceMappingURL=chunk-XXC2CUXZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fingerprint.ts","../src/summaries.ts","../src/validate.ts","../src/builder.ts","../src/rowTable.ts","../src/sources.ts"],"names":[],"mappings":";;;AAmBO,SAAS,cAAc,KAAA,EAAwB;AACpD,EAAA,IAAI,KAAA,KAAU,IAAA,IAAQ,OAAO,KAAA,KAAU,QAAA,EAAU;AAC/C,IAAA,OAAO,IAAA,CAAK,SAAA,CAAU,KAAK,CAAA,IAAK,MAAA;AAAA,EAClC;AACA,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,GAAA,GAAM,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,KAAM,aAAA,CAAc,CAAC,CAAC,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA,GAAI,GAAA;AAAA,EAC9D;AACA,EAAA,MAAM,MAAA,GAAS,KAAA;AACf,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,CAC5B,MAAA,CAAO,CAAC,CAAA,KAAM,MAAA,CAAO,CAAC,CAAA,KAAM,MAAS,EACrC,IAAA,EAAK;AACR,EAAA,OACE,MAAM,IAAA,CAAK,GAAA,CAAI,CAAC,CAAA,KAAM,IAAA,CAAK,UAAU,CAAC,CAAA,GAAI,GAAA,GAAM,aAAA,CAAc,OAAO,CAAC,CAAC,CAAC,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA,GAAI,GAAA;AAE1F;AAEA,IAAM,UAAA,GAAa,mBAA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ACxB,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,EAAG;AACzB,IAAA,MAAM,IAAA,GAAO,MAAA;AACb,IAAA,OAAA,CAAQ,mBAAmB;AACzB,MAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,IAAA,CAAK,QAAQ,CAAA,EAAA,EAAK;AACpC,QAAA,IAAA,CAAK,CAAA,GAAI,GAAA,MAAS,CAAA,EAAG,cAAA,CAAe,MAAM,CAAA;AAC1C,QAAA,MAAM,KAAK,CAAC,CAAA;AAAA,MACd;AAAA,IACF,CAAA,GAAG;AAAA,EACL;AACA,EAAA,IAAI,eAAA,CAAgB,MAAM,CAAA,EAAG;AAC3B,IAAA,OAAA,CAAQ,mBAAmB;AACzB,MAAA,WAAA,MAAiB,GAAA,IAAO,eAAA,CAAgB,MAAM,CAAA,EAAG;AAC/C,QAAA,cAAA,CAAe,MAAM,CAAA;AACrB,QAAA,MAAM,GAAA;AAAA,MACR;AAAA,IACF,CAAA,GAAG;AAAA,EACL;AACA,EAAA,MAAM,IAAI,SAAA;AAAA,IACR;AAAA,GACF;AACF","file":"chunk-XXC2CUXZ.js","sourcesContent":["/**\n * Stable mapping/schema fingerprint.\n *\n * `mappingFingerprint = fnv1a64Hex(canonicalJson(mapping) + '\\n' + format +\n * '\\n' + canonicalJson(columns))` where `columns` is, per role, the ADMITTED\n * attr-field union (invariant I4, semantic fingerprint completeness): the\n * seeded schema columns (CSV header / Arrow-Parquet schema / first-row keys,\n * minus identity, filtered by `includeFields`) UNIONED with every field any\n * row actually materialized into attrs — collected by builder.ts during the\n * single materialization pass. The lists are sorted here, so field discovery\n * order never moves the fingerprint; canonical JSON sorts object keys\n * recursively so key-order-insensitive equal mappings fingerprint\n * identically.\n */\n\nimport type { GraphColumnMapping, GraphPrepareFormat } from './types';\n\n/** Recursively key-sorted JSON. Only JSON-safe values are expected (mappings\n * and column lists are plain strings/arrays/objects). */\nexport function canonicalJson(value: unknown): string {\n if (value === null || typeof value !== 'object') {\n return JSON.stringify(value) ?? 'null';\n }\n if (Array.isArray(value)) {\n return '[' + value.map((v) => canonicalJson(v)).join(',') + ']';\n }\n const record = value as Record<string, unknown>;\n const keys = Object.keys(record)\n .filter((k) => record[k] !== undefined)\n .sort();\n return (\n '{' + keys.map((k) => JSON.stringify(k) + ':' + canonicalJson(record[k])).join(',') + '}'\n );\n}\n\nconst FNV_OFFSET = 0xcbf29ce484222325n;\nconst FNV_PRIME = 0x100000001b3n;\nconst MASK_64 = 0xffffffffffffffffn;\n\n/** FNV-1a 64-bit over the UTF-8 bytes of `text`, as a 16-char lowercase hex string. */\nexport function fnv1a64Hex(text: string): string {\n const bytes = new TextEncoder().encode(text);\n let hash = FNV_OFFSET;\n for (const byte of bytes) {\n hash ^= BigInt(byte);\n hash = (hash * FNV_PRIME) & MASK_64;\n }\n return hash.toString(16).padStart(16, '0');\n}\n\nexport function computeMappingFingerprint(\n mapping: GraphColumnMapping,\n format: GraphPrepareFormat,\n columns: { nodes: readonly string[]; edges: readonly string[] },\n): string {\n const columnList = {\n nodes: [...columns.nodes].sort(),\n edges: [...columns.edges].sort(),\n };\n return fnv1a64Hex(\n canonicalJson(mapping) + '\\n' + format + '\\n' + canonicalJson(columnList),\n );\n}\n","/**\n * Streaming per-column summaries for prepared artifacts, using the\n * `ColumnSummary` shape defined locally in types.ts.\n *\n * Accumulation rules (single pass, bounded memory):\n * - `count` — total rows of the owning table; identical across the\n * table's summaries.\n * - `nullCount` — rows with no usable value for the column: key absent,\n * `null`/`undefined`, or a number that fails core's\n * `coerceNumeric` hygiene (NaN/±Infinity → null through the single\n * coercion layer).\n * - numeric lane — finite numbers feed min/max (over ALL values) and\n * quantiles [0.25, 0.5, 0.75] from a retained sample:\n * Algorithm-R reservoir capped at RESERVOIR_CAP = 10 000.\n * While the value count is ≤ the cap the sample is the whole\n * column, so quantiles are EXACT (type-7 linear\n * interpolation, the common statistical default); beyond the\n * cap they are reservoir-approximate (and, because Algorithm\n * R draws from Math.random, nondeterministic — acceptable\n * for a profile, documented here).\n * - categorical lane — strings and booleans feed a value→count map capped at\n * CATEGORY_CAP = 10 000 distinct keys: once full, unseen\n * values stop being tracked (existing keys still count) and\n * the summary is marked truncated. `categories` reports the\n * top TOP_CATEGORIES = 20 by count (ties broken by first\n * occurrence); `categoriesTruncated` is set when the map\n * overflowed OR more than 20 distinct values were tracked.\n * - `approximateUnique` — all primitive values (numbers, strings, booleans;\n * type-tagged so `1` and `'1'` stay distinct) in a Set\n * capped at UNIQUE_CAP = 10 000; once capped the reported\n * value is the cap itself (a lower bound).\n * - other types — objects/arrays/dates/bigints/functions/symbols count as\n * present (not null) but contribute to no value statistic;\n * this profile tier only characterizes primitives.\n */\n\nimport { coerceNumeric } from '@modernrelay/orbit-core';\nimport type { ColumnSummary } from './types';\n\nexport const RESERVOIR_CAP = 10_000;\nexport const UNIQUE_CAP = 10_000;\nexport const CATEGORY_CAP = 10_000;\nexport const TOP_CATEGORIES = 20;\nexport const QUANTILE_PROBS = [0.25, 0.5, 0.75] as const;\n\nclass ColumnAccumulator {\n /** Values with a usable value; `nullCount` falls out as rows − present. */\n presentCount = 0;\n\n numericCount = 0;\n min = Infinity;\n max = -Infinity;\n /** Algorithm-R reservoir of numeric values (exact sample while ≤ cap). */\n reservoir: number[] = [];\n numericSeen = 0;\n\n categories = new Map<string, number>();\n categoriesOverflowed = false;\n hasCategorical = false;\n\n uniques = new Set<string>();\n uniquesOverflowed = false;\n\n add(value: unknown): void {\n if (value === null || value === undefined) {\n return; // counts as null via rows − presentCount\n }\n if (typeof value === 'number') {\n const coerced = coerceNumeric(value);\n if (coerced === null) {\n // NaN/±Infinity: hygiene says no usable value.\n return;\n }\n this.presentCount++;\n this.numericCount++;\n if (coerced < this.min) this.min = coerced;\n if (coerced > this.max) this.max = coerced;\n this.numericSeen++;\n if (this.reservoir.length < RESERVOIR_CAP) {\n this.reservoir.push(coerced);\n } else {\n const j = Math.floor(Math.random() * this.numericSeen);\n if (j < RESERVOIR_CAP) this.reservoir[j] = coerced;\n }\n this.addUnique('n:' + coerced);\n return;\n }\n if (typeof value === 'string' || typeof value === 'boolean') {\n this.presentCount++;\n this.hasCategorical = true;\n const key = String(value);\n const existing = this.categories.get(key);\n if (existing !== undefined) {\n this.categories.set(key, existing + 1);\n } else if (this.categories.size < CATEGORY_CAP) {\n this.categories.set(key, 1);\n } else {\n this.categoriesOverflowed = true;\n }\n this.addUnique((typeof value === 'string' ? 's:' : 'b:') + key);\n return;\n }\n // Opaque non-primitive: present, but no value statistics.\n this.presentCount++;\n }\n\n private addUnique(key: string): void {\n if (this.uniques.size < UNIQUE_CAP) {\n this.uniques.add(key);\n } else if (!this.uniques.has(key)) {\n this.uniquesOverflowed = true;\n }\n }\n\n finalize(totalRows: number): ColumnSummary {\n const summary: ColumnSummary = {\n count: totalRows,\n nullCount: totalRows - this.presentCount,\n };\n if (this.numericCount > 0) {\n summary.min = this.min;\n summary.max = this.max;\n summary.quantiles = computeQuantiles(this.reservoir);\n }\n if (this.presentCount > 0 && (this.numericCount > 0 || this.hasCategorical)) {\n summary.approximateUnique = this.uniquesOverflowed ? UNIQUE_CAP : this.uniques.size;\n }\n if (this.hasCategorical) {\n // Top-N by count; ties keep first-occurrence (Map iteration) order via\n // a stable sort over insertion-ordered entries.\n const entries = [...this.categories.entries()];\n entries.sort((a, b) => b[1] - a[1]);\n summary.categories = entries\n .slice(0, TOP_CATEGORIES)\n .map(([value, count]) => ({ value, count }));\n if (this.categoriesOverflowed || this.categories.size > TOP_CATEGORIES) {\n summary.categoriesTruncated = true;\n }\n }\n return summary;\n }\n}\n\n/** Type-7 (linear interpolation between closest ranks) quantiles over a sample. */\nexport function computeQuantiles(sample: readonly number[]): readonly number[] {\n const sorted = [...sample].sort((a, b) => a - b);\n const n = sorted.length;\n return QUANTILE_PROBS.map((p) => {\n if (n === 1) return sorted[0]!;\n const idx = (n - 1) * p;\n const lo = Math.floor(idx);\n const hi = Math.ceil(idx);\n const loV = sorted[lo]!;\n const hiV = sorted[hi]!;\n return lo === hi ? loV : loV + (hiV - loV) * (idx - lo);\n });\n}\n\n/**\n * Summarizes one table's attr columns. Columns known up front (CSV header,\n * Arrow/Parquet schema) are seeded so an all-empty column still reports\n * `{count, nullCount: count}`; row-object lanes discover columns as they\n * appear (rows before a column's first appearance count as null via\n * `count - presentCount`).\n */\nexport class TableSummarizer {\n private readonly columns = new Map<string, ColumnAccumulator>();\n private rows = 0;\n\n seed(columnNames: Iterable<string>): void {\n for (const name of columnNames) {\n if (!this.columns.has(name)) this.columns.set(name, new ColumnAccumulator());\n }\n }\n\n addRow(attrs: Readonly<Record<string, unknown>> | undefined): void {\n this.rows++;\n if (attrs === undefined) return;\n for (const key of Object.keys(attrs)) {\n let acc = this.columns.get(key);\n if (acc === undefined) {\n acc = new ColumnAccumulator();\n this.columns.set(key, acc);\n }\n acc.add(attrs[key]);\n }\n }\n\n finalize(): Readonly<Record<string, ColumnSummary>> {\n const out: Record<string, ColumnSummary> = {};\n for (const [name, acc] of this.columns) {\n // A column literally named '__proto__' must land as an own\n // property, not invoke the prototype setter.\n Object.defineProperty(out, name, {\n value: acc.finalize(this.rows),\n enumerable: true,\n writable: true,\n configurable: true,\n });\n }\n return out;\n }\n}\n","/**\n * Mapping validation — runs BEFORE any row work.\n *\n * `mapping.nodes.id` and `mapping.edges.source`/`target` must exist in the\n * discovered input columns (see rowTable.ts for how each lane discovers\n * them). Failures throw ONE TypeError listing EVERY missing column at once,\n * so a caller fixes the whole mapping in a single round trip.\n *\n * Deliberately lenient by design:\n * - `mapping.edges.id` and `includeFields` entries are NOT required to exist\n * (optional column; absent fields simply never materialize);\n * - an empty source (`columns === null`) is vacuously valid — there is no\n * schema to check and no rows to mis-map.\n */\n\nimport type { GraphColumnMapping } from './types';\n\nexport interface MappingValidationInput {\n mapping: GraphColumnMapping;\n /** Discovered node columns (null = empty source or derived nodes). */\n nodeColumns: readonly string[] | null;\n /** Discovered edge columns (null = empty source). */\n edgeColumns: readonly string[] | null;\n /** True for the `{edges, deriveNodes: true}` input variant. */\n deriveNodes: boolean;\n}\n\nexport function validateMapping(input: MappingValidationInput): void {\n const { mapping, nodeColumns, edgeColumns, deriveNodes } = input;\n const problems: string[] = [];\n\n if (!deriveNodes) {\n if (mapping.nodes === undefined) {\n problems.push('mapping.nodes is required when a node source is supplied');\n } else if (nodeColumns !== null && !nodeColumns.includes(mapping.nodes.id)) {\n problems.push(\n `node id column ${JSON.stringify(mapping.nodes.id)} not found ` +\n `(available: ${formatColumns(nodeColumns)})`,\n );\n }\n }\n\n if (edgeColumns !== null) {\n const missing: string[] = [];\n if (!edgeColumns.includes(mapping.edges.source)) missing.push('source');\n if (!edgeColumns.includes(mapping.edges.target)) missing.push('target');\n for (const role of missing) {\n const column = role === 'source' ? mapping.edges.source : mapping.edges.target;\n problems.push(\n `edge ${role} column ${JSON.stringify(column)} not found ` +\n `(available: ${formatColumns(edgeColumns)})`,\n );\n }\n }\n\n if (problems.length > 0) {\n throw new TypeError(\n `prepareGraphData: mapping validation failed — ${problems.join('; ')}`,\n );\n }\n}\n\nfunction formatColumns(columns: readonly string[]): string {\n if (columns.length === 0) return 'none';\n return columns.map((c) => JSON.stringify(c)).join(', ');\n}\n","/**\n * Shared prepared-graph builder: every lane (rows/CSV/JSON/Arrow/\n * Parquet) funnels normalized RowTables through here.\n *\n * Order of operations: mapping validation FIRST (before any row\n * work, against the discovered columns), then a single streaming pass per\n * table building snapshot rows and column summaries, then the fingerprint.\n * The fingerprint is FINALIZED only after materialization (invariant I4,\n * semantic fingerprint completeness): it covers the union of ADMITTED attr\n * fields across ALL rows — seeded columns plus every field a row actually\n * materialized — not the header/first-row projection used for validation.\n * Late-appearing fields flow into attrs and summaries, so they must move the\n * fingerprint too, or artifact revalidation skipping (artifact.ts) could\n * serve stale structure.\n *\n * Attr selection: identity columns (node id; edge id/source/target) are\n * consumed for identity and excluded from attrs — unless `includeFields`\n * names them explicitly. When `includeFields` is present it is the exact\n * attr allowlist; otherwise attrs = all non-identity columns. Rows with no\n * attrs omit the `attrs` key entirely (exactOptionalPropertyTypes-friendly).\n *\n * Identity values must be strings, finite numbers, or bigints (stringified);\n * a row with a missing/unusable id/source/target throws a TypeError with the\n * row ordinal — prepared data must be well-keyed, and silent row drops would\n * corrupt summaries.\n */\n\nimport type { GraphEdge, GraphNode, GraphSnapshot } from '@modernrelay/orbit-core';\nimport { computeMappingFingerprint } from './fingerprint';\nimport type { RowTable } from './rowTable';\nimport { TableSummarizer } from './summaries';\nimport type {\n GraphColumnMapping,\n GraphPrepareFormat,\n GraphPrepareOptions,\n PreparedGraph,\n} from './types';\nimport { validateMapping } from './validate';\n\ntype Row = Readonly<Record<string, unknown>>;\ntype Attrs = Record<string, unknown>;\n\nexport interface BuildArgs {\n /** null = `{edges, deriveNodes: true}` — nodes synthesized from endpoints. */\n nodeTable: RowTable | null;\n edgeTable: RowTable;\n mapping: GraphColumnMapping;\n /** Resolved lane label; part of the fingerprint. */\n format: GraphPrepareFormat;\n options: GraphPrepareOptions;\n}\n\nexport async function buildPrepared(args: BuildArgs): Promise<PreparedGraph> {\n const { nodeTable, edgeTable, mapping, format, options } = args;\n let failed = false;\n try {\n validateOptions(options);\n validateMapping({\n mapping,\n nodeColumns: nodeTable === null ? null : nodeTable.columns,\n edgeColumns: edgeTable.columns,\n deriveNodes: nodeTable === null,\n });\n const nodeSummarizer = new TableSummarizer();\n const edgeSummarizer = new TableSummarizer();\n\n // --- edges (first, so deriveNodes sees endpoint order) ----------------\n const edgeIdentity = new Set<string>(\n [mapping.edges.id, mapping.edges.source, mapping.edges.target].filter(\n (c): c is string => c !== undefined,\n ),\n );\n const edgeAttrPick = attrPicker(edgeTable.columns, edgeIdentity, mapping.edges.includeFields);\n if (edgeTable.columns !== null) {\n edgeSummarizer.seed(edgeAttrPick.seedColumns);\n for (const column of edgeAttrPick.seedColumns) edgeAttrPick.admitted.add(column);\n }\n const edges: GraphEdge[] = [];\n const endpointOrder = new Set<string>();\n let edgeOrdinal = 0;\n for await (const row of edgeTable.rows) {\n const source = identityString(\n row[mapping.edges.source],\n 'edge source',\n edgeOrdinal,\n mapping.edges.source,\n true,\n );\n const target = identityString(\n row[mapping.edges.target],\n 'edge target',\n edgeOrdinal,\n mapping.edges.target,\n true,\n );\n const edge: GraphEdge = { source, target };\n if (mapping.edges.id !== undefined) {\n const raw = row[mapping.edges.id];\n if (raw !== undefined && raw !== null) {\n edge.id = identityString(raw, 'edge id', edgeOrdinal, mapping.edges.id, true);\n }\n }\n const attrs = edgeAttrPick.pick(row);\n if (attrs !== undefined) edge.attrs = attrs;\n edgeSummarizer.addRow(attrs);\n edges.push(edge);\n if (nodeTable === null) {\n endpointOrder.add(source);\n endpointOrder.add(target);\n }\n edgeOrdinal++;\n }\n\n // --- nodes -------------------------------------------------------------\n const nodes: GraphNode[] = [];\n let nodeAdmitted: ReadonlySet<string> = new Set<string>();\n if (nodeTable === null) {\n // deriveNodes: ids only, first-occurrence order over edge endpoints.\n for (const id of endpointOrder) nodes.push({ id });\n } else {\n const nodeMapping = mapping.nodes!; // validated above\n const nodeIdentity = new Set<string>([nodeMapping.id]);\n const nodeAttrPick = attrPicker(nodeTable.columns, nodeIdentity, nodeMapping.includeFields);\n nodeAdmitted = nodeAttrPick.admitted;\n if (nodeTable.columns !== null) {\n nodeSummarizer.seed(nodeAttrPick.seedColumns);\n for (const column of nodeAttrPick.seedColumns) nodeAttrPick.admitted.add(column);\n }\n let nodeOrdinal = 0;\n for await (const row of nodeTable.rows) {\n const id = identityString(row[nodeMapping.id], 'node id', nodeOrdinal, nodeMapping.id, true);\n const node: GraphNode = { id };\n const attrs = nodeAttrPick.pick(row);\n if (attrs !== undefined) node.attrs = attrs;\n nodeSummarizer.addRow(attrs);\n nodes.push(node);\n nodeOrdinal++;\n }\n }\n\n // Fingerprint AFTER materialization (I4): the admitted union is only\n // known once every row has streamed through. computeMappingFingerprint\n // sorts the lists, so field DISCOVERY order can never move it.\n const mappingFingerprint = computeMappingFingerprint(mapping, format, {\n nodes: [...nodeAdmitted],\n edges: [...edgeAttrPick.admitted],\n });\n\n const snapshot: GraphSnapshot = {\n datasetKey: options.datasetKey,\n sourceRevision: options.sourceRevision,\n nodes,\n edges,\n };\n return {\n snapshot,\n summaries: { nodes: nodeSummarizer.finalize(), edges: edgeSummarizer.finalize() },\n mappingFingerprint,\n };\n } catch (cause) {\n failed = true;\n throw cause;\n } finally {\n // Column discovery peeks async sources before validation. Always release\n // both tables so mapping errors, an error in either materialization pass,\n // and successful exhaustion all settle caller-owned iterators. Both\n // closes run even if one rejects. A teardown failure is surfaced after a\n // successful build, but must never replace the useful validation/read\n // failure already escaping the try block.\n const closes = await Promise.allSettled([\n Promise.resolve().then(() => edgeTable.close?.()),\n Promise.resolve().then(() => nodeTable?.close?.()),\n ]);\n if (!failed) {\n const rejected = closes.find(\n (result): result is PromiseRejectedResult => result.status === 'rejected',\n );\n if (rejected !== undefined) throw rejected.reason;\n }\n }\n}\n\nfunction validateOptions(options: GraphPrepareOptions): void {\n if (typeof options.datasetKey !== 'string' || options.datasetKey === '') {\n throw new TypeError('prepareGraphData: options.datasetKey must be a non-empty string');\n }\n const rev = options.sourceRevision;\n if (\n (typeof rev !== 'string' && typeof rev !== 'number') ||\n (typeof rev === 'number' && !Number.isFinite(rev))\n ) {\n throw new TypeError(\n 'prepareGraphData: options.sourceRevision must be a string or finite number',\n );\n }\n}\n\nfunction identityString(\n value: unknown,\n role: string,\n ordinal: number,\n column: string,\n rejectNul = false,\n): string {\n if (typeof value === 'string') {\n if (value === '') {\n throw new TypeError(\n `prepareGraphData: ${role} in column ${JSON.stringify(column)} is empty at row ${ordinal}`,\n );\n }\n if (rejectNul && value.includes('\\u0000')) {\n throw new TypeError(\n `prepareGraphData: ${role} in column ${JSON.stringify(column)} contains reserved NUL ` +\n `at row ${ordinal}`,\n );\n }\n return value;\n }\n if (typeof value === 'number' && Number.isFinite(value)) return String(value);\n if (typeof value === 'bigint') return String(value);\n throw new TypeError(\n `prepareGraphData: ${role} in column ${JSON.stringify(column)} is missing or unusable ` +\n `at row ${ordinal} (got ${value === null ? 'null' : typeof value})`,\n );\n}\n\ninterface AttrPicker {\n /** Columns to pre-seed summaries with (known-schema lanes). */\n seedColumns: readonly string[];\n /**\n * Union of admitted attr field names (I4 fingerprint input): every key\n * `pick` materialized into attrs, plus — added by the builder alongside\n * summary seeding — the seeded columns. Mirrors the summary key set\n * exactly; identity columns and allowlist-excluded fields never enter.\n */\n admitted: Set<string>;\n /** Row → attrs object, or undefined when the row has no attr values. */\n pick(row: Row): Attrs | undefined;\n}\n\nfunction attrPicker(\n columns: readonly string[] | null,\n identity: ReadonlySet<string>,\n includeFields: readonly string[] | undefined,\n): AttrPicker {\n const admitted = new Set<string>();\n if (includeFields !== undefined) {\n const allow = new Set(includeFields);\n return {\n seedColumns: columns === null ? [...allow] : columns.filter((c) => allow.has(c)),\n admitted,\n pick: (row) => {\n let attrs: Attrs | undefined;\n for (const key of Object.keys(row)) {\n if (!allow.has(key)) continue;\n const value = row[key];\n if (value === undefined) continue;\n admitted.add(key);\n // JSON.parse rows carry '__proto__' as an own key;\n // plain assignment would invoke the legacy prototype setter\n // (field lost, prototype swapped). defineProperty writes the own\n // property regardless of the key.\n attrs ??= {};\n Object.defineProperty(attrs, key, {\n value,\n enumerable: true,\n writable: true,\n configurable: true,\n });\n }\n return attrs;\n },\n };\n }\n return {\n seedColumns: columns === null ? [] : columns.filter((c) => !identity.has(c)),\n admitted,\n pick: (row) => {\n let attrs: Attrs | undefined;\n for (const key of Object.keys(row)) {\n if (identity.has(key)) continue;\n const value = row[key];\n if (value === undefined) continue;\n admitted.add(key);\n // Same guard as the includeFields branch above.\n attrs ??= {};\n Object.defineProperty(attrs, key, {\n value,\n enumerable: true,\n writable: true,\n configurable: true,\n });\n }\n return attrs;\n },\n };\n}\n","/**\n * Internal adapter contract: every input lane (rows, CSV, JSON document,\n * Arrow, Parquet) normalizes to a `RowTable` — the discovered column list\n * (available BEFORE any row work, so mapping validation can run first) plus a\n * single-pass stream of plain row objects.\n *\n * Column discovery per lane:\n * - row objects → keys of the FIRST row (sampled; later rows may add keys,\n * which flow into attrs/summaries but not validation);\n * - CSV → the header row;\n * - JSON document → keys of the first element of each resolved path array;\n * - Arrow/Parquet → the file schema (exact, not sampled).\n *\n * `columns: null` means the source was empty — nothing to validate against\n * (vacuously valid) and nothing to stream.\n */\n\nexport interface RowTable {\n /** Discovered columns, or null when the source has no rows at all. */\n readonly columns: readonly string[] | null;\n readonly rows: AsyncIterable<Readonly<Record<string, unknown>>>;\n /**\n * Release a source whose column-discovery peek opened an iterator before\n * materialization began. Implementations must be safe to close after\n * normal exhaustion and more than once.\n */\n readonly close?: () => Promise<void>;\n}\n\nexport const EMPTY_ROW_TABLE: RowTable = {\n columns: null,\n rows: (async function* () {})(),\n};\n\nexport function isPlainRowObject(row: unknown): row is Record<string, unknown> {\n return typeof row === 'object' && row !== null && !Array.isArray(row);\n}\n","/**\n * Source-kind detection and byte/row stream normalization.\n *\n * The package accepts exactly these source shapes:\n * GraphRowSource = readonly unknown[] | AsyncIterable<unknown>\n * GraphByteSource = Blob | ArrayBuffer | AsyncIterable<Uint8Array>\n *\n * An `AsyncIterable` is ambiguous between the two — when the caller supplies\n * no explicit `format`, the first element is peeked: `Uint8Array` chunks mean\n * bytes (CSV lane), anything else means row objects. The peeked element is\n * pushed back, so adapters observe the full stream.\n */\n\nexport function throwIfAborted(signal: AbortSignal | undefined): void {\n if (signal?.aborted) {\n if (typeof signal.throwIfAborted === 'function') signal.throwIfAborted();\n throw new Error('prepareGraphData: aborted');\n }\n}\n\nexport function isBlob(value: unknown): value is Blob {\n return typeof Blob !== 'undefined' && value instanceof Blob;\n}\n\nexport function isAsyncIterable(value: unknown): value is AsyncIterable<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as Record<PropertyKey, unknown>)[Symbol.asyncIterator] === 'function'\n );\n}\n\n/**\n * Iterator teardown is caller-owned protocol, not necessarily an idempotent\n * async-generator method. Memoize the first close so nested replay/adapter\n * wrappers can all settle without invoking an arbitrary `return()` twice.\n */\nfunction iteratorCloseOnce<T>(iterator: AsyncIterator<T>): () => Promise<void> {\n let closePromise: Promise<void> | undefined;\n return () => {\n closePromise ??= (async () => {\n await iterator.return?.();\n })();\n return closePromise;\n };\n}\n\n/**\n * Drive an arbitrary async iterator behind an async-generator boundary that\n * guarantees `return()` on early exit *and* when `next()` rejects. Native\n * `for await` does not close an iterator whose own `next()` rejects.\n */\nasync function* closingIterable<T>(source: AsyncIterable<T>): AsyncGenerator<T> {\n const iterator = source[Symbol.asyncIterator]();\n const close = iteratorCloseOnce(iterator);\n let exhausted = false;\n let failed = false;\n try {\n while (true) {\n const next = await iterator.next();\n if (next.done) {\n exhausted = true;\n return;\n }\n yield next.value;\n }\n } catch (cause) {\n failed = true;\n throw cause;\n } finally {\n if (!exhausted) {\n try {\n await close();\n } catch (closeCause) {\n // A failed read/consumer operation is the useful outcome. Teardown\n // failure is surfaced only when there is no earlier failure to mask.\n if (!failed) throw closeCause;\n }\n }\n }\n}\n\n/** An async iterable with its first element already consumed and re-yielded.\n * `done` distinguishes a completed source from one whose first yield was\n * `undefined`; conflating them silently discarded the whole source instead\n * of reporting malformed row zero. */\nexport async function peekAsyncIterable(\n source: AsyncIterable<unknown>,\n): Promise<{\n first: unknown | undefined;\n done: boolean;\n rest: AsyncIterable<unknown>;\n /** Close the underlying iterator directly: calling return\n * on the un-started replay generator completes without entering its body,\n * so its finally cannot forward — validation-failure paths close here. */\n close: () => Promise<void>;\n}> {\n const iterator = source[Symbol.asyncIterator]();\n const close = iteratorCloseOnce(iterator);\n let head: IteratorResult<unknown>;\n try {\n head = await iterator.next();\n } catch (cause) {\n try {\n await close();\n } catch {\n // Preserve the iterator's read failure; teardown is best-effort here.\n }\n throw cause;\n }\n const first = head.done ? undefined : head.value;\n async function* replay(): AsyncGenerator<unknown> {\n let exhausted = head.done === true;\n let failed = false;\n try {\n if (!head.done) yield head.value;\n // Delegate to the original iterator (not the iterable) so nothing is lost.\n while (true) {\n const next = await iterator.next();\n if (next.done) {\n exhausted = true;\n return;\n }\n yield next.value;\n }\n } catch (cause) {\n failed = true;\n throw cause;\n } finally {\n // Early exit or a downstream throw must close the source;\n // file handles, network bodies, and generator finally-blocks hang off\n // return. A rejected next() also needs explicit teardown.\n if (!exhausted) {\n try {\n await close();\n } catch (closeCause) {\n if (!failed) throw closeCause;\n }\n }\n }\n }\n return {\n first,\n done: head.done === true,\n rest: replay(),\n close,\n };\n}\n\n/** Normalize any GraphByteSource to an async chunk stream. */\nexport function byteChunks(\n source: Blob | ArrayBuffer | AsyncIterable<Uint8Array>,\n signal: AbortSignal | undefined,\n): AsyncIterable<Uint8Array> {\n if (source instanceof ArrayBuffer) {\n const chunk = new Uint8Array(source);\n return (async function* () {\n throwIfAborted(signal);\n yield chunk;\n })();\n }\n if (isBlob(source)) {\n return (async function* () {\n // Blob.stream is a web ReadableStream; async-iterable in Node ≥18.\n const stream = source.stream() as unknown as AsyncIterable<Uint8Array>;\n for await (const chunk of closingIterable(stream)) {\n throwIfAborted(signal);\n yield chunk;\n }\n })();\n }\n return (async function* () {\n for await (const chunk of closingIterable(source)) {\n throwIfAborted(signal);\n if (!(chunk instanceof Uint8Array)) {\n throw new TypeError(\n 'prepareGraphData: byte sources must yield Uint8Array chunks',\n );\n }\n yield chunk;\n }\n })();\n}\n\n/** Collect a full byte source into one Uint8Array (JSON/Arrow/Parquet lanes). */\nexport async function collectBytes(\n source: Blob | ArrayBuffer | AsyncIterable<Uint8Array>,\n signal: AbortSignal | undefined,\n): Promise<Uint8Array> {\n const chunks: Uint8Array[] = [];\n let total = 0;\n for await (const chunk of byteChunks(source, signal)) {\n chunks.push(chunk);\n total += chunk.byteLength;\n }\n const out = new Uint8Array(total);\n let offset = 0;\n for (const chunk of chunks) {\n out.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return out;\n}\n\n/** Normalize a row source (array or async iterable of rows) to a stream. */\nexport function rowStream(\n source: readonly unknown[] | AsyncIterable<unknown>,\n signal: AbortSignal | undefined,\n): AsyncIterable<unknown> {\n if (Array.isArray(source)) {\n const rows = source as readonly unknown[];\n return (async function* () {\n for (let i = 0; i < rows.length; i++) {\n if ((i & 255) === 0) throwIfAborted(signal);\n yield rows[i];\n }\n })();\n }\n if (isAsyncIterable(source)) {\n return (async function* () {\n for await (const row of closingIterable(source)) {\n throwIfAborted(signal);\n yield row;\n }\n })();\n }\n throw new TypeError(\n 'prepareGraphData: row sources must be an array or an AsyncIterable of row objects',\n );\n}\n"]}
|