@modernrelay/orbit-data 0.19.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,265 @@
1
- import { coerceNumeric } from '@modernrelay/orbit-core';
1
+ import { nextSynthesizedEdgeId, coerceNumeric } from '@modernrelay/orbit-core';
2
+
3
+ // src/sources.ts
4
+ function throwIfAborted(signal) {
5
+ if (signal?.aborted) {
6
+ if (signal.reason instanceof Error && signal.reason.name === "AbortError") throw signal.reason;
7
+ throw new DOMException("prepareGraphData: aborted", "AbortError");
8
+ }
9
+ }
10
+ async function abortable(pending, signal) {
11
+ if (signal === void 0) return pending;
12
+ return new Promise((resolve, reject) => {
13
+ const cancel = () => {
14
+ signal.removeEventListener("abort", cancel);
15
+ try {
16
+ throwIfAborted(signal);
17
+ } catch (error) {
18
+ reject(error);
19
+ }
20
+ };
21
+ signal.addEventListener("abort", cancel, { once: true });
22
+ Promise.resolve(pending).then(
23
+ (value) => {
24
+ signal.removeEventListener("abort", cancel);
25
+ resolve(value);
26
+ },
27
+ (error) => {
28
+ signal.removeEventListener("abort", cancel);
29
+ reject(error);
30
+ }
31
+ );
32
+ if (signal.aborted) cancel();
33
+ });
34
+ }
35
+ async function closeAfterFailure(close, signal) {
36
+ if (signal?.aborted) {
37
+ void close().catch(() => {
38
+ });
39
+ } else await close();
40
+ }
41
+ function isBlob(value) {
42
+ return typeof Blob !== "undefined" && value instanceof Blob;
43
+ }
44
+ function isAsyncIterable(value) {
45
+ return typeof value === "object" && value !== null && typeof value[Symbol.asyncIterator] === "function";
46
+ }
47
+ function iteratorCloseOnce(iterator) {
48
+ let closePromise;
49
+ return () => {
50
+ closePromise ??= (async () => {
51
+ await iterator.return?.();
52
+ })();
53
+ return closePromise;
54
+ };
55
+ }
56
+ async function* closingIterable(source, signal) {
57
+ const iterator = source[Symbol.asyncIterator]();
58
+ const close = iteratorCloseOnce(iterator);
59
+ let exhausted = false;
60
+ let failed = false;
61
+ try {
62
+ while (true) {
63
+ throwIfAborted(signal);
64
+ const next = await abortable(iterator.next(), signal);
65
+ if (next.done) {
66
+ exhausted = true;
67
+ return;
68
+ }
69
+ yield next.value;
70
+ }
71
+ } catch (cause) {
72
+ failed = true;
73
+ throw cause;
74
+ } finally {
75
+ if (!exhausted) {
76
+ try {
77
+ await closeAfterFailure(close, signal);
78
+ } catch (closeCause) {
79
+ if (!failed) throw closeCause;
80
+ }
81
+ }
82
+ }
83
+ }
84
+ async function peekAsyncIterable(source, signal) {
85
+ const iterator = source[Symbol.asyncIterator]();
86
+ const close = iteratorCloseOnce(iterator);
87
+ let head;
88
+ try {
89
+ throwIfAborted(signal);
90
+ head = await abortable(iterator.next(), signal);
91
+ } catch (cause) {
92
+ try {
93
+ await closeAfterFailure(close, signal);
94
+ } catch {
95
+ }
96
+ throw cause;
97
+ }
98
+ const first = head.done ? void 0 : head.value;
99
+ async function* replay() {
100
+ let exhausted = head.done === true;
101
+ let failed = false;
102
+ try {
103
+ if (!head.done) yield head.value;
104
+ while (true) {
105
+ throwIfAborted(signal);
106
+ const next = await abortable(iterator.next(), signal);
107
+ if (next.done) {
108
+ exhausted = true;
109
+ return;
110
+ }
111
+ yield next.value;
112
+ }
113
+ } catch (cause) {
114
+ failed = true;
115
+ throw cause;
116
+ } finally {
117
+ if (!exhausted) {
118
+ try {
119
+ await closeAfterFailure(close, signal);
120
+ } catch (closeCause) {
121
+ if (!failed) throw closeCause;
122
+ }
123
+ }
124
+ }
125
+ }
126
+ return {
127
+ first,
128
+ done: head.done === true,
129
+ rest: replay(),
130
+ close
131
+ };
132
+ }
133
+ function byteChunks(source, signal, control) {
134
+ async function* rawChunks() {
135
+ throwIfAborted(signal);
136
+ if (source instanceof ArrayBuffer) {
137
+ yield new Uint8Array(source);
138
+ return;
139
+ }
140
+ const stream = isBlob(source) ? source.stream() : source;
141
+ yield* closingIterable(stream, signal);
142
+ }
143
+ return (async function* () {
144
+ for await (const chunk of rawChunks()) {
145
+ throwIfAborted(signal);
146
+ if (!(chunk instanceof Uint8Array)) throw new TypeError("prepareGraphData: byte sources must yield Uint8Array chunks");
147
+ for (let offset = 0; offset < chunk.byteLength; offset += 64 * 1024) {
148
+ throwIfAborted(signal);
149
+ const slice = chunk.subarray(offset, Math.min(chunk.byteLength, offset + 64 * 1024));
150
+ control?.read(slice.byteLength);
151
+ yield slice;
152
+ await control?.checkpoint();
153
+ }
154
+ }
155
+ throwIfAborted(signal);
156
+ })();
157
+ }
158
+ async function collectBytes(source, signal, control) {
159
+ const chunks = [];
160
+ let total = 0;
161
+ for await (const chunk of byteChunks(source, signal, control)) {
162
+ chunks.push(chunk);
163
+ total += chunk.byteLength;
164
+ }
165
+ throwIfAborted(signal);
166
+ const out = new Uint8Array(total);
167
+ let offset = 0;
168
+ for (const chunk of chunks) {
169
+ out.set(chunk, offset);
170
+ offset += chunk.byteLength;
171
+ }
172
+ return out;
173
+ }
174
+ function rowStream(source, signal) {
175
+ if (Array.isArray(source)) {
176
+ const rows = source;
177
+ return (async function* () {
178
+ for (let i = 0; i < rows.length; i++) {
179
+ if ((i & 255) === 0) throwIfAborted(signal);
180
+ yield rows[i];
181
+ }
182
+ })();
183
+ }
184
+ if (isAsyncIterable(source)) {
185
+ return (async function* () {
186
+ for await (const row of closingIterable(source, signal)) {
187
+ throwIfAborted(signal);
188
+ yield row;
189
+ }
190
+ })();
191
+ }
192
+ throw new TypeError(
193
+ "prepareGraphData: row sources must be an array or an AsyncIterable of row objects"
194
+ );
195
+ }
196
+
197
+ // src/control.ts
198
+ var PreparationControl = class {
199
+ constructor(options) {
200
+ this.options = options;
201
+ if (typeof options.datasetKey !== "string" || options.datasetKey === "") {
202
+ throw new TypeError("prepareGraphData: options.datasetKey must be a non-empty string");
203
+ }
204
+ if (typeof options.sourceRevision !== "string" && typeof options.sourceRevision !== "number" || typeof options.sourceRevision === "number" && !Number.isFinite(options.sourceRevision)) {
205
+ throw new TypeError("prepareGraphData: options.sourceRevision must be a string or finite number");
206
+ }
207
+ for (const key of ["maxBytes", "maxNodes", "maxEdges"]) {
208
+ const limit = options[key];
209
+ if (limit !== void 0 && (!Number.isSafeInteger(limit) || limit <= 0)) {
210
+ throw new TypeError(`prepareGraphData: ${key} must be a positive safe integer`);
211
+ }
212
+ }
213
+ if (options.output !== void 0 && options.output !== "object" && options.output !== "columnar") {
214
+ throw new TypeError("prepareGraphData: output must be object or columnar");
215
+ }
216
+ this.check();
217
+ }
218
+ options;
219
+ bytes = 0;
220
+ nodes = 0;
221
+ edges = 0;
222
+ lastProgress = -Infinity;
223
+ lastYield = Date.now();
224
+ work = 0;
225
+ check() {
226
+ throwIfAborted(this.options.signal);
227
+ }
228
+ bounded(next, key) {
229
+ this.check();
230
+ const limit = this.options[key];
231
+ if (!Number.isSafeInteger(next) || limit !== void 0 && next > limit) {
232
+ throw new RangeError(`prepareGraphData: ${key} limit ${limit ?? Number.MAX_SAFE_INTEGER} exceeded (${next})`);
233
+ }
234
+ return next;
235
+ }
236
+ read(bytes) {
237
+ this.bytes = this.bounded(this.bytes + bytes, "maxBytes");
238
+ this.report("reading");
239
+ }
240
+ admit(role) {
241
+ if (role === "nodes") this.nodes = this.bounded(this.nodes + 1, "maxNodes");
242
+ else this.edges = this.bounded(this.edges + 1, "maxEdges");
243
+ this.report("preparing");
244
+ }
245
+ /** Yield a task, not only a microtask, so browser cancellation can run. */
246
+ async checkpoint() {
247
+ this.check();
248
+ if ((++this.work & 255) === 0 && Date.now() - this.lastYield >= 8) {
249
+ await new Promise((resolve) => setTimeout(resolve, 0));
250
+ this.lastYield = Date.now();
251
+ this.check();
252
+ }
253
+ }
254
+ report(phase) {
255
+ this.check();
256
+ const now = Date.now();
257
+ if (phase !== "complete" && now - this.lastProgress < 100) return;
258
+ this.lastProgress = now;
259
+ this.options.onProgress?.({ phase, bytes: this.bytes, nodes: this.nodes, edges: this.edges });
260
+ this.check();
261
+ }
262
+ };
2
263
 
3
264
  // src/fingerprint.ts
4
265
  function canonicalJson(value) {
@@ -33,6 +294,151 @@ function computeMappingFingerprint(mapping, format, columns) {
33
294
  canonicalJson(mapping) + "\n" + format + "\n" + canonicalJson(columnList)
34
295
  );
35
296
  }
297
+ var Values = class {
298
+ constructor(name) {
299
+ this.name = name;
300
+ }
301
+ name;
302
+ kind;
303
+ data = new Float64Array(0);
304
+ nulls = new Uint8Array(0);
305
+ dictionary = [];
306
+ codes = /* @__PURE__ */ new Map();
307
+ set(index, raw) {
308
+ const value = typeof raw === "number" && !Number.isFinite(raw) ? null : raw;
309
+ if (value === null || value === void 0) return;
310
+ const kind = typeof value;
311
+ if (kind !== "number" && kind !== "boolean" && kind !== "string") {
312
+ throw new TypeError(`prepareGraphData: columnar ${this.name} at row ${index} cannot represent ${kind}; use output:'object' for nested or non-primitive attributes`);
313
+ }
314
+ if (this.kind !== void 0 && this.kind !== kind) {
315
+ throw new TypeError(`prepareGraphData: columnar ${this.name} mixes ${this.kind} and ${kind} at row ${index}; use output:'object'`);
316
+ }
317
+ this.kind = kind;
318
+ this.grow(index + 1);
319
+ this.nulls[index] = 0;
320
+ if (typeof value === "string") {
321
+ let code = this.codes.get(value);
322
+ if (code === void 0) {
323
+ code = this.dictionary.length;
324
+ this.codes.set(value, code);
325
+ this.dictionary.push(value);
326
+ }
327
+ this.data[index] = code;
328
+ } else this.data[index] = typeof value === "boolean" ? Number(value) : value;
329
+ }
330
+ grow(length) {
331
+ if (length <= this.data.length) return;
332
+ const capacity = Math.max(length, this.data.length * 2, 16);
333
+ const data = new Float64Array(capacity);
334
+ data.set(this.data);
335
+ const nulls = new Uint8Array(capacity).fill(1);
336
+ nulls.set(this.nulls);
337
+ this.data = data;
338
+ this.nulls = nulls;
339
+ }
340
+ finish(length) {
341
+ this.grow(length);
342
+ const mask = this.nulls.slice(0, length);
343
+ const nullable = mask.includes(1) ? { nulls: mask } : {};
344
+ if (this.kind === "string") {
345
+ return { kind: "string", dictionary: this.dictionary, codes: Uint32Array.from(this.data.subarray(0, length)), ...nullable };
346
+ }
347
+ if (this.kind === "boolean") return { kind: "bool", data: Uint8Array.from(this.data.subarray(0, length)), ...nullable };
348
+ return { kind: "f64", data: this.data.slice(0, length), ...nullable };
349
+ }
350
+ };
351
+ var Attributes = class {
352
+ constructor(role) {
353
+ this.role = role;
354
+ }
355
+ role;
356
+ columns = /* @__PURE__ */ new Map();
357
+ seed(names) {
358
+ for (const name of names) this.column(name);
359
+ }
360
+ column(name) {
361
+ if (name === "__proto__") throw new TypeError("prepareGraphData: columnar __proto__ attributes require output:'object'");
362
+ let column = this.columns.get(name);
363
+ if (column === void 0) {
364
+ column = new Values(`${this.role}.${name}`);
365
+ this.columns.set(name, column);
366
+ }
367
+ return column;
368
+ }
369
+ add(attrs, row) {
370
+ if (attrs === void 0) return;
371
+ for (const name of Object.keys(attrs)) this.column(name).set(row, attrs[name]);
372
+ }
373
+ finish(length) {
374
+ return Object.fromEntries([...this.columns].map(([name, column]) => [name, column.finish(length)]));
375
+ }
376
+ };
377
+ function ids(values) {
378
+ const dictionary = [];
379
+ const index = /* @__PURE__ */ new Map();
380
+ const codes = new Uint32Array(values.length);
381
+ for (let i = 0; i < values.length; i++) {
382
+ const value = values[i];
383
+ let code = index.get(value);
384
+ if (code === void 0) {
385
+ code = dictionary.length;
386
+ dictionary.push(value);
387
+ index.set(value, code);
388
+ }
389
+ codes[i] = code;
390
+ }
391
+ return { kind: "string", dictionary, codes };
392
+ }
393
+ var ColumnarBuilder = class {
394
+ nodeIds = [];
395
+ edgeIds = [];
396
+ sources = [];
397
+ targets = [];
398
+ nodeAttributes = new Attributes("nodes");
399
+ edgeAttributes = new Attributes("edges");
400
+ node(id, attrs) {
401
+ this.nodeAttributes.add(attrs, this.nodeIds.length);
402
+ this.nodeIds.push(id);
403
+ }
404
+ edge(source, target, id, attrs) {
405
+ this.edgeAttributes.add(attrs, this.edgeIds.length);
406
+ this.edgeIds.push(id);
407
+ this.sources.push(source);
408
+ this.targets.push(target);
409
+ }
410
+ async finish(control) {
411
+ const nodeIndex = /* @__PURE__ */ new Map();
412
+ for (let i = 0; i < this.nodeIds.length; i++) {
413
+ if (!nodeIndex.has(this.nodeIds[i])) nodeIndex.set(this.nodeIds[i], i);
414
+ }
415
+ const source = new Uint32Array(this.edgeIds.length);
416
+ const target = new Uint32Array(this.edgeIds.length);
417
+ const edgeIds = [];
418
+ const counters = /* @__PURE__ */ new Map();
419
+ for (let i = 0; i < this.edgeIds.length; i++) {
420
+ await control.checkpoint();
421
+ const from = this.sources[i];
422
+ const to = this.targets[i];
423
+ const s = nodeIndex.get(from);
424
+ const t = nodeIndex.get(to);
425
+ if (s === void 0 || t === void 0) {
426
+ throw new TypeError(`prepareGraphData: columnar edge ${i} has an unknown endpoint ${JSON.stringify(s === void 0 ? from : to)}; supply its node or use output:'object' for core's dangling-edge diagnostics`);
427
+ }
428
+ source[i] = s;
429
+ target[i] = t;
430
+ edgeIds.push(this.edgeIds[i] ?? nextSynthesizedEdgeId(counters, from, to));
431
+ }
432
+ return {
433
+ kind: "columnar",
434
+ datasetKey: control.options.datasetKey,
435
+ sourceRevision: control.options.sourceRevision,
436
+ bufferOwnership: "borrowed",
437
+ nodes: { ids: ids(this.nodeIds), columns: this.nodeAttributes.finish(this.nodeIds.length), length: this.nodeIds.length },
438
+ edges: { ids: ids(edgeIds), source, target, columns: this.edgeAttributes.finish(edgeIds.length), length: edgeIds.length }
439
+ };
440
+ }
441
+ };
36
442
  var RESERVOIR_CAP = 1e4;
37
443
  var UNIQUE_CAP = 1e4;
38
444
  var CATEGORY_CAP = 1e4;
@@ -207,10 +613,11 @@ function formatColumns(columns) {
207
613
 
208
614
  // src/builder.ts
209
615
  async function buildPrepared(args) {
210
- const { nodeTable, edgeTable, mapping, format, options } = args;
616
+ const { nodeTable, edgeTable, mapping, format, options, control } = args;
211
617
  let failed = false;
212
618
  try {
213
- validateOptions(options);
619
+ control.check();
620
+ const columnar = options.output === "columnar" ? new ColumnarBuilder() : void 0;
214
621
  validateMapping({
215
622
  mapping,
216
623
  nodeColumns: nodeTable === null ? null : nodeTable.columns,
@@ -229,10 +636,13 @@ async function buildPrepared(args) {
229
636
  edgeSummarizer.seed(edgeAttrPick.seedColumns);
230
637
  for (const column of edgeAttrPick.seedColumns) edgeAttrPick.admitted.add(column);
231
638
  }
639
+ columnar?.edgeAttributes.seed(edgeAttrPick.seedColumns);
232
640
  const edges = [];
233
641
  const endpointOrder = /* @__PURE__ */ new Set();
234
642
  let edgeOrdinal = 0;
235
643
  for await (const row of edgeTable.rows) {
644
+ await control.checkpoint();
645
+ control.admit("edges");
236
646
  const source = identityString(
237
647
  row[mapping.edges.source],
238
648
  "edge source",
@@ -247,27 +657,35 @@ async function buildPrepared(args) {
247
657
  mapping.edges.target,
248
658
  true
249
659
  );
250
- const edge = { source, target };
660
+ let edgeId;
251
661
  if (mapping.edges.id !== void 0) {
252
662
  const raw = row[mapping.edges.id];
253
663
  if (raw !== void 0 && raw !== null) {
254
- edge.id = identityString(raw, "edge id", edgeOrdinal, mapping.edges.id, true);
664
+ edgeId = identityString(raw, "edge id", edgeOrdinal, mapping.edges.id, true);
255
665
  }
256
666
  }
257
667
  const attrs = edgeAttrPick.pick(row);
258
- if (attrs !== void 0) edge.attrs = attrs;
259
668
  edgeSummarizer.addRow(attrs);
260
- edges.push(edge);
669
+ if (columnar !== void 0) columnar.edge(source, target, edgeId, attrs);
670
+ else edges.push({ source, target, ...edgeId === void 0 ? {} : { id: edgeId }, ...attrs === void 0 ? {} : { attrs } });
261
671
  if (nodeTable === null) {
262
- endpointOrder.add(source);
263
- endpointOrder.add(target);
672
+ for (const endpoint of [source, target]) {
673
+ if (!endpointOrder.has(endpoint)) {
674
+ control.admit("nodes");
675
+ endpointOrder.add(endpoint);
676
+ }
677
+ }
264
678
  }
265
679
  edgeOrdinal++;
266
680
  }
267
681
  const nodes = [];
268
682
  let nodeAdmitted = /* @__PURE__ */ new Set();
269
683
  if (nodeTable === null) {
270
- for (const id of endpointOrder) nodes.push({ id });
684
+ for (const id of endpointOrder) {
685
+ await control.checkpoint();
686
+ if (columnar !== void 0) columnar.node(id);
687
+ else nodes.push({ id });
688
+ }
271
689
  } else {
272
690
  const nodeMapping = mapping.nodes;
273
691
  const nodeIdentity = /* @__PURE__ */ new Set([nodeMapping.id]);
@@ -277,14 +695,16 @@ async function buildPrepared(args) {
277
695
  nodeSummarizer.seed(nodeAttrPick.seedColumns);
278
696
  for (const column of nodeAttrPick.seedColumns) nodeAttrPick.admitted.add(column);
279
697
  }
698
+ columnar?.nodeAttributes.seed(nodeAttrPick.seedColumns);
280
699
  let nodeOrdinal = 0;
281
700
  for await (const row of nodeTable.rows) {
701
+ await control.checkpoint();
702
+ control.admit("nodes");
282
703
  const id = identityString(row[nodeMapping.id], "node id", nodeOrdinal, nodeMapping.id, true);
283
- const node = { id };
284
704
  const attrs = nodeAttrPick.pick(row);
285
- if (attrs !== void 0) node.attrs = attrs;
286
705
  nodeSummarizer.addRow(attrs);
287
- nodes.push(node);
706
+ if (columnar !== void 0) columnar.node(id, attrs);
707
+ else nodes.push({ id, ...attrs === void 0 ? {} : { attrs } });
288
708
  nodeOrdinal++;
289
709
  }
290
710
  }
@@ -292,12 +712,13 @@ async function buildPrepared(args) {
292
712
  nodes: [...nodeAdmitted],
293
713
  edges: [...edgeAttrPick.admitted]
294
714
  });
295
- const snapshot = {
715
+ const snapshot = columnar !== void 0 ? await columnar.finish(control) : {
296
716
  datasetKey: options.datasetKey,
297
717
  sourceRevision: options.sourceRevision,
298
718
  nodes,
299
719
  edges
300
720
  };
721
+ control.report("complete");
301
722
  return {
302
723
  snapshot,
303
724
  summaries: { nodes: nodeSummarizer.finalize(), edges: edgeSummarizer.finalize() },
@@ -319,17 +740,6 @@ async function buildPrepared(args) {
319
740
  }
320
741
  }
321
742
  }
322
- function validateOptions(options) {
323
- if (typeof options.datasetKey !== "string" || options.datasetKey === "") {
324
- throw new TypeError("prepareGraphData: options.datasetKey must be a non-empty string");
325
- }
326
- const rev = options.sourceRevision;
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
- );
331
- }
332
- }
333
743
  function identityString(value, role, ordinal, column, rejectNul = false) {
334
744
  if (typeof value === "string") {
335
745
  if (value === "") {
@@ -409,169 +819,6 @@ function isPlainRowObject(row) {
409
819
  return typeof row === "object" && row !== null && !Array.isArray(row);
410
820
  }
411
821
 
412
- // src/sources.ts
413
- function throwIfAborted(signal) {
414
- if (signal?.aborted) {
415
- if (typeof signal.throwIfAborted === "function") signal.throwIfAborted();
416
- throw new Error("prepareGraphData: aborted");
417
- }
418
- }
419
- function isBlob(value) {
420
- return typeof Blob !== "undefined" && value instanceof Blob;
421
- }
422
- function isAsyncIterable(value) {
423
- return typeof value === "object" && value !== null && typeof value[Symbol.asyncIterator] === "function";
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
- }
461
- async function peekAsyncIterable(source) {
462
- const iterator = source[Symbol.asyncIterator]();
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
- }
474
- const first = head.done ? void 0 : head.value;
475
- async function* replay() {
476
- let exhausted = head.done === true;
477
- let failed = false;
478
- try {
479
- if (!head.done) yield head.value;
480
- while (true) {
481
- const next = await iterator.next();
482
- if (next.done) {
483
- exhausted = true;
484
- return;
485
- }
486
- yield next.value;
487
- }
488
- } catch (cause) {
489
- failed = true;
490
- throw cause;
491
- } finally {
492
- if (!exhausted) {
493
- try {
494
- await close();
495
- } catch (closeCause) {
496
- if (!failed) throw closeCause;
497
- }
498
- }
499
- }
500
- }
501
- return {
502
- first,
503
- done: head.done === true,
504
- rest: replay(),
505
- close
506
- };
507
- }
508
- function byteChunks(source, signal) {
509
- if (source instanceof ArrayBuffer) {
510
- const chunk = new Uint8Array(source);
511
- return (async function* () {
512
- throwIfAborted(signal);
513
- yield chunk;
514
- })();
515
- }
516
- if (isBlob(source)) {
517
- return (async function* () {
518
- const stream = source.stream();
519
- for await (const chunk of closingIterable(stream)) {
520
- throwIfAborted(signal);
521
- yield chunk;
522
- }
523
- })();
524
- }
525
- return (async function* () {
526
- for await (const chunk of closingIterable(source)) {
527
- throwIfAborted(signal);
528
- if (!(chunk instanceof Uint8Array)) {
529
- throw new TypeError(
530
- "prepareGraphData: byte sources must yield Uint8Array chunks"
531
- );
532
- }
533
- yield chunk;
534
- }
535
- })();
536
- }
537
- async function collectBytes(source, signal) {
538
- const chunks = [];
539
- let total = 0;
540
- for await (const chunk of byteChunks(source, signal)) {
541
- chunks.push(chunk);
542
- total += chunk.byteLength;
543
- }
544
- const out = new Uint8Array(total);
545
- let offset = 0;
546
- for (const chunk of chunks) {
547
- out.set(chunk, offset);
548
- offset += chunk.byteLength;
549
- }
550
- return out;
551
- }
552
- function rowStream(source, signal) {
553
- if (Array.isArray(source)) {
554
- const rows = source;
555
- return (async function* () {
556
- for (let i = 0; i < rows.length; i++) {
557
- if ((i & 255) === 0) throwIfAborted(signal);
558
- yield rows[i];
559
- }
560
- })();
561
- }
562
- if (isAsyncIterable(source)) {
563
- return (async function* () {
564
- for await (const row of closingIterable(source)) {
565
- throwIfAborted(signal);
566
- yield row;
567
- }
568
- })();
569
- }
570
- throw new TypeError(
571
- "prepareGraphData: row sources must be an array or an AsyncIterable of row objects"
572
- );
573
- }
574
-
575
- export { EMPTY_ROW_TABLE, buildPrepared, byteChunks, canonicalJson, collectBytes, computeMappingFingerprint, fnv1a64Hex, isAsyncIterable, isBlob, isPlainRowObject, peekAsyncIterable, rowStream, throwIfAborted };
576
- //# sourceMappingURL=chunk-XXC2CUXZ.js.map
577
- //# sourceMappingURL=chunk-XXC2CUXZ.js.map
822
+ export { EMPTY_ROW_TABLE, PreparationControl, abortable, buildPrepared, byteChunks, canonicalJson, collectBytes, computeMappingFingerprint, fnv1a64Hex, isAsyncIterable, isBlob, isPlainRowObject, peekAsyncIterable, rowStream, throwIfAborted };
823
+ //# sourceMappingURL=chunk-5RVIGNTM.js.map
824
+ //# sourceMappingURL=chunk-5RVIGNTM.js.map