@casoon/opengrid 0.16.0 → 0.18.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/CHANGELOG.md +171 -1
- package/README.md +3 -3
- package/collation/opengrid_collation.d.ts +47 -0
- package/collation/opengrid_collation.js +256 -0
- package/collation/opengrid_collation_bg.wasm +0 -0
- package/collation/opengrid_collation_bg.wasm.d.ts +10 -0
- package/collation.js +48 -0
- package/engine/opengrid_wasm.d.ts +77 -1
- package/engine/opengrid_wasm.js +187 -0
- package/engine/opengrid_wasm_bg.wasm +0 -0
- package/engine/opengrid_wasm_bg.wasm.d.ts +14 -1
- package/loader.d.ts +45 -0
- package/loader.js +452 -8
- package/package.json +4 -1
- package/pkg/opengrid_web_components.d.ts +10 -10
- package/pkg/opengrid_web_components.js +50 -50
- package/pkg/opengrid_web_components_bg.wasm +0 -0
- package/pkg/opengrid_web_components_bg.wasm.d.ts +10 -10
- package/react/index.d.ts +2 -0
- package/react/index.js +1 -0
- package/svelte/OpengridGrid.svelte +2 -0
- package/svelte/index.d.ts +2 -0
- package/vue/index.d.ts +2 -0
- package/vue/index.js +1 -0
- package/worker.js +84 -1
- package/xlsx/opengrid_xlsx_bg.wasm +0 -0
- /package/pkg/snippets/{opengrid-web-components-35ed06b453a9b215 → opengrid-web-components-bcd23b5e2228bf0e}/inline0.js +0 -0
- /package/pkg/snippets/{opengrid-web-components-35ed06b453a9b215 → opengrid-web-components-bcd23b5e2228bf0e}/inline1.js +0 -0
- /package/pkg/snippets/{opengrid-web-core-b41714d4e7311909 → opengrid-web-core-5e04e9ab83050ad3}/inline0.js +0 -0
- /package/pkg/snippets/{opengrid-web-core-b41714d4e7311909 → opengrid-web-core-5e04e9ab83050ad3}/inline1.js +0 -0
- /package/pkg/snippets/{opengrid-web-core-b41714d4e7311909 → opengrid-web-core-5e04e9ab83050ad3}/inline2.js +0 -0
package/loader.js
CHANGED
|
@@ -193,6 +193,25 @@ export function createWorkerProvider({
|
|
|
193
193
|
|
|
194
194
|
const watchers = createWatchers();
|
|
195
195
|
|
|
196
|
+
// Rows as packs of columns (issue #445): to the worker, which owns the engine.
|
|
197
|
+
let started = Promise.resolve();
|
|
198
|
+
const loadRowsAsColumns = columnLoader({
|
|
199
|
+
all: async (name, schema, rows, pack) => {
|
|
200
|
+
await started;
|
|
201
|
+
return request({ type: "columns", name, schema, rows, pack }, [pack]);
|
|
202
|
+
},
|
|
203
|
+
begin: async (name, schema, rows) => {
|
|
204
|
+
await started;
|
|
205
|
+
return request({ type: "columns_begin", name, schema, rows });
|
|
206
|
+
},
|
|
207
|
+
push: (pack) => request({ type: "columns_chunk", pack }, [pack]),
|
|
208
|
+
end: () => request({ type: "columns_end" }),
|
|
209
|
+
abort: async () => {
|
|
210
|
+
await started;
|
|
211
|
+
return request({ type: "columns_abort" });
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
|
|
196
215
|
function start() {
|
|
197
216
|
if (!worker) {
|
|
198
217
|
// Written out in full: the `new Worker(new URL(…, import.meta.url), …)` form
|
|
@@ -217,14 +236,40 @@ export function createWorkerProvider({
|
|
|
217
236
|
watchers.loaded(name);
|
|
218
237
|
},
|
|
219
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Loads a CSV file piece by piece (issue #427): a `File`/`Blob`, a
|
|
241
|
+
* `ReadableStream` of bytes or an async iterable of them. Only a piece and
|
|
242
|
+
* the columns are in the engine's memory, not the whole file as well. A
|
|
243
|
+
* name already loaded is replaced, all or nothing; a file that cannot be
|
|
244
|
+
* read leaves the old source and rejects with the line.
|
|
245
|
+
*/
|
|
246
|
+
async loadStream(name, source, schema, options = {}) {
|
|
247
|
+
await start();
|
|
248
|
+
await request({ type: "load_begin", name, schema, size: sizeOf(source) });
|
|
249
|
+
try {
|
|
250
|
+
for await (const buffer of piecesOf(source, options.chunkSize)) {
|
|
251
|
+
await request({ type: "load_chunk", bytes: buffer }, [buffer]);
|
|
252
|
+
}
|
|
253
|
+
await request({ type: "load_end" });
|
|
254
|
+
} catch (error) {
|
|
255
|
+
await request({ type: "load_abort" });
|
|
256
|
+
throw error;
|
|
257
|
+
}
|
|
258
|
+
watchers.loaded(name);
|
|
259
|
+
},
|
|
260
|
+
|
|
220
261
|
/**
|
|
221
262
|
* Loads rows the page already holds — an array of objects keyed by field
|
|
222
263
|
* name (or that array as JSON text) — against a schema (issue #182). A
|
|
223
264
|
* name already loaded is replaced, all or nothing.
|
|
224
265
|
*/
|
|
225
266
|
async loadRows(name, rows, schema) {
|
|
226
|
-
|
|
227
|
-
|
|
267
|
+
// The worker starts while the rows are made into columns, which is most of the wait.
|
|
268
|
+
started = start();
|
|
269
|
+
if (!(await loadRowsAsColumns(name, rows, schema))) {
|
|
270
|
+
await started;
|
|
271
|
+
await request({ type: "rows", name, rows: rowsJson(rows), schema });
|
|
272
|
+
}
|
|
228
273
|
watchers.loaded(name);
|
|
229
274
|
},
|
|
230
275
|
|
|
@@ -239,6 +284,17 @@ export function createWorkerProvider({
|
|
|
239
284
|
return request({ type: "query", query: queryJson });
|
|
240
285
|
},
|
|
241
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Frees the source `name` (issue #459); resolves with whether there was
|
|
289
|
+
* one. The worker's memory does not shrink, but the next load takes the
|
|
290
|
+
* room the table had. A grid on the name answers its next query with an
|
|
291
|
+
* unknown source.
|
|
292
|
+
*/
|
|
293
|
+
async unload(name) {
|
|
294
|
+
await start();
|
|
295
|
+
return request({ type: "unload", name });
|
|
296
|
+
},
|
|
297
|
+
|
|
242
298
|
/**
|
|
243
299
|
* What the engine in the worker holds (issue #70): its WASM memory and,
|
|
244
300
|
* per source, rows, columns and bytes.
|
|
@@ -423,6 +479,280 @@ function rowsJson(rows) {
|
|
|
423
479
|
return typeof rows === "string" ? rows : JSON.stringify(rows);
|
|
424
480
|
}
|
|
425
481
|
|
|
482
|
+
// ---------------------------------------------------------------------------------------------
|
|
483
|
+
// Rows as columns (issue #445)
|
|
484
|
+
//
|
|
485
|
+
// An array of objects is handed to the engine as packs of typed columns, not as one JSON text:
|
|
486
|
+
// no text of the whole table on the main thread, in the worker and in the module, and no second
|
|
487
|
+
// reading of it. The format of a pack is in `crates/opengrid-engine/src/ingest/columns.rs`.
|
|
488
|
+
//
|
|
489
|
+
// The table has to be the table the JSON route makes of the same rows, so only what is plain is
|
|
490
|
+
// sent this way. A value that is not, an unknown key, a column the engine does not read from
|
|
491
|
+
// columns, or any error of the engine ends it, the engine drops what it had, and `loadRows` runs
|
|
492
|
+
// the JSON route, which owns every message.
|
|
493
|
+
// ---------------------------------------------------------------------------------------------
|
|
494
|
+
|
|
495
|
+
/** Rows per pack: a bound on what is in flight at once, as the pieces of `loadStream` are. */
|
|
496
|
+
const PACK_ROWS = 65536;
|
|
497
|
+
const textEncoder = new TextEncoder();
|
|
498
|
+
|
|
499
|
+
/** What the columns of `schema` are, or `null` when this way is not for these rows. */
|
|
500
|
+
function columnPlan(rows, schema) {
|
|
501
|
+
// A text that is not well formed is not what `JSON.stringify` and the JSON reader would make of
|
|
502
|
+
// it; a browser that cannot say takes the JSON route.
|
|
503
|
+
if (!Array.isArray(rows) || rows.length === 0 || typeof "".isWellFormed !== "function") {
|
|
504
|
+
return null;
|
|
505
|
+
}
|
|
506
|
+
let fields;
|
|
507
|
+
try {
|
|
508
|
+
fields = JSON.parse(schema)?.fields;
|
|
509
|
+
} catch {
|
|
510
|
+
return null;
|
|
511
|
+
}
|
|
512
|
+
if (!Array.isArray(fields)) {
|
|
513
|
+
return null;
|
|
514
|
+
}
|
|
515
|
+
const kinds = { bool: "bool", int64: "int", float64: "float", utf8: "utf8", date: "date", timestamp: "timestamp" };
|
|
516
|
+
const stored = [];
|
|
517
|
+
for (const field of fields) {
|
|
518
|
+
if (field?.from !== undefined && field?.from !== null) {
|
|
519
|
+
continue; // derived: computed by the engine, never sent
|
|
520
|
+
}
|
|
521
|
+
const kind = field?.type?.decimal ? "decimal" : kinds[field?.type];
|
|
522
|
+
if (typeof field?.name !== "string" || kind === undefined) {
|
|
523
|
+
return null; // a list column, or a schema the engine will explain
|
|
524
|
+
}
|
|
525
|
+
stored.push({ name: field.name, kind });
|
|
526
|
+
}
|
|
527
|
+
return stored.length > 0 ? stored : null;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* One pack: rows `from` to `to` as typed columns, or `null` when a value is not plain.
|
|
532
|
+
* Plain is what the JSON route reads the same way: a boolean in a bool column, a safe integer
|
|
533
|
+
* in an int64, a finite number in a float64, a string in a text, date or timestamp column, a
|
|
534
|
+
* string or an integer in a decimal; `null` and a missing key are NULL.
|
|
535
|
+
*/
|
|
536
|
+
function packOf(rows, from, to, stored) {
|
|
537
|
+
const n = to - from;
|
|
538
|
+
const pad = (size) => (size + 7) & ~7;
|
|
539
|
+
const bitsLength = Math.ceil(n / 8);
|
|
540
|
+
const sections = [];
|
|
541
|
+
// The keys of a row against the keys the schema has: a row with a key it does not know is the
|
|
542
|
+
// JSON route's, which names the key. `present` counts the keys of the schema a row has.
|
|
543
|
+
const present = new Uint16Array(n);
|
|
544
|
+
const plain = Object.prototype;
|
|
545
|
+
for (let i = 0; i < n; i += 1) {
|
|
546
|
+
const row = rows[from + i];
|
|
547
|
+
if (row === null || typeof row !== "object" || Object.getPrototypeOf(row) !== plain) {
|
|
548
|
+
return null;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
for (const { name, kind } of stored) {
|
|
552
|
+
let bits = null; // the validity bitmap, made at the first NULL
|
|
553
|
+
const missing = (i) => {
|
|
554
|
+
bits ??= new Uint8Array(bitsLength).fill(255);
|
|
555
|
+
bits[i >> 3] &= ~(1 << (i & 7));
|
|
556
|
+
};
|
|
557
|
+
if (kind === "bool") {
|
|
558
|
+
const values = new Uint8Array(n);
|
|
559
|
+
for (let i = 0; i < n; i += 1) {
|
|
560
|
+
const value = rows[from + i][name];
|
|
561
|
+
if (value === undefined) {
|
|
562
|
+
missing(i);
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
present[i] += 1;
|
|
566
|
+
if (value === null) {
|
|
567
|
+
missing(i);
|
|
568
|
+
} else if (typeof value === "boolean") {
|
|
569
|
+
values[i] = value ? 1 : 0;
|
|
570
|
+
} else {
|
|
571
|
+
return null;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
sections.push({ bits, payload: values, text: null });
|
|
575
|
+
} else if (kind === "int" || kind === "float") {
|
|
576
|
+
const values = new Float64Array(n);
|
|
577
|
+
for (let i = 0; i < n; i += 1) {
|
|
578
|
+
const value = rows[from + i][name];
|
|
579
|
+
if (value === undefined) {
|
|
580
|
+
missing(i);
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
present[i] += 1;
|
|
584
|
+
if (value === null) {
|
|
585
|
+
missing(i);
|
|
586
|
+
} else if (
|
|
587
|
+
typeof value === "number" &&
|
|
588
|
+
(kind === "int" ? Number.isSafeInteger(value) : Number.isFinite(value))
|
|
589
|
+
) {
|
|
590
|
+
// JSON writes -0 as 0.
|
|
591
|
+
values[i] = value === 0 ? 0 : value;
|
|
592
|
+
} else {
|
|
593
|
+
return null;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
sections.push({ bits, payload: new Uint8Array(values.buffer), text: null });
|
|
597
|
+
} else {
|
|
598
|
+
// Text, and what the engine reads from text: a decimal, a date, a timestamp.
|
|
599
|
+
const offsets = new Uint32Array(n + 1);
|
|
600
|
+
let bytes = new Uint8Array(Math.max(256, n * 12));
|
|
601
|
+
let at = 0;
|
|
602
|
+
for (let i = 0; i < n; i += 1) {
|
|
603
|
+
let value = rows[from + i][name];
|
|
604
|
+
if (value === undefined) {
|
|
605
|
+
missing(i);
|
|
606
|
+
offsets[i + 1] = at;
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
present[i] += 1;
|
|
610
|
+
if (value === null) {
|
|
611
|
+
missing(i);
|
|
612
|
+
offsets[i + 1] = at;
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
if (kind === "decimal" && typeof value === "number" && Number.isSafeInteger(value)) {
|
|
616
|
+
value = String(value);
|
|
617
|
+
}
|
|
618
|
+
if (typeof value !== "string") {
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
const length = value.length;
|
|
622
|
+
if (at + length * 3 > bytes.length) {
|
|
623
|
+
const grown = new Uint8Array(Math.max(bytes.length * 2, at + length * 3));
|
|
624
|
+
grown.set(bytes.subarray(0, at));
|
|
625
|
+
bytes = grown;
|
|
626
|
+
}
|
|
627
|
+
// ASCII, which most text is, is copied as it is; the rest is encoded, if it is well formed.
|
|
628
|
+
let ascii = true;
|
|
629
|
+
for (let j = 0; j < length; j += 1) {
|
|
630
|
+
const code = value.charCodeAt(j);
|
|
631
|
+
if (code > 127) {
|
|
632
|
+
ascii = false;
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
bytes[at + j] = code;
|
|
636
|
+
}
|
|
637
|
+
if (ascii) {
|
|
638
|
+
at += length;
|
|
639
|
+
} else if (value.isWellFormed()) {
|
|
640
|
+
at += textEncoder.encodeInto(value, bytes.subarray(at)).written;
|
|
641
|
+
} else {
|
|
642
|
+
return null;
|
|
643
|
+
}
|
|
644
|
+
offsets[i + 1] = at;
|
|
645
|
+
}
|
|
646
|
+
sections.push({ bits, payload: new Uint8Array(offsets.buffer), text: bytes.subarray(0, at) });
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
for (let i = 0; i < n; i += 1) {
|
|
650
|
+
let keys = 0;
|
|
651
|
+
for (const _key in rows[from + i]) {
|
|
652
|
+
keys += 1;
|
|
653
|
+
}
|
|
654
|
+
if (keys !== present[i]) {
|
|
655
|
+
return null;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
// The pack: the header, then each column's section from a multiple of 8.
|
|
659
|
+
let total = pad(4 + 8 * stored.length);
|
|
660
|
+
const starts = sections.map((section) => {
|
|
661
|
+
const start = total;
|
|
662
|
+
total += pad((section.bits ? pad(bitsLength) : 0) + section.payload.length + (section.text?.length ?? 0));
|
|
663
|
+
return start;
|
|
664
|
+
});
|
|
665
|
+
const pack = new ArrayBuffer(total);
|
|
666
|
+
const view = new DataView(pack);
|
|
667
|
+
const all = new Uint8Array(pack);
|
|
668
|
+
view.setUint32(0, n, true);
|
|
669
|
+
sections.forEach((section, index) => {
|
|
670
|
+
view.setUint32(4 + 8 * index, section.bits ? 1 : 0, true);
|
|
671
|
+
view.setUint32(8 + 8 * index, section.text?.length ?? 0, true);
|
|
672
|
+
let at = starts[index];
|
|
673
|
+
if (section.bits) {
|
|
674
|
+
all.set(section.bits, at);
|
|
675
|
+
at += pad(bitsLength);
|
|
676
|
+
}
|
|
677
|
+
all.set(section.payload, at);
|
|
678
|
+
if (section.text) {
|
|
679
|
+
all.set(section.text, at + section.payload.length);
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
return pack;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Loads `rows` as packs of columns through `io`, or says that it did not (`false`): the rows are
|
|
687
|
+
* not plain, or the engine refused them or does not know the calls. The engine holds nothing of
|
|
688
|
+
* them then, and the caller takes the JSON route.
|
|
689
|
+
*/
|
|
690
|
+
async function loadColumns(name, rows, schema, io) {
|
|
691
|
+
const stored = columnPlan(rows, schema);
|
|
692
|
+
if (!stored) {
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
try {
|
|
696
|
+
if (rows.length <= PACK_ROWS) {
|
|
697
|
+
const pack = packOf(rows, 0, rows.length, stored);
|
|
698
|
+
if (!pack) {
|
|
699
|
+
return false;
|
|
700
|
+
}
|
|
701
|
+
await io.all(name, schema, rows.length, pack);
|
|
702
|
+
return true;
|
|
703
|
+
}
|
|
704
|
+
// The next pack is made while the engine takes the one before: a pack waits for the one two
|
|
705
|
+
// before it, not for the one before (which would leave the engine idle while a pack is made),
|
|
706
|
+
// and the page gets the thread back between packs. The first is made before `begin` is asked,
|
|
707
|
+
// so that a worker still starting does its start while that is done.
|
|
708
|
+
let pack = packOf(rows, 0, PACK_ROWS, stored);
|
|
709
|
+
if (!pack) {
|
|
710
|
+
return false;
|
|
711
|
+
}
|
|
712
|
+
await io.begin(name, schema, rows.length);
|
|
713
|
+
const sent = [];
|
|
714
|
+
let refused = null;
|
|
715
|
+
for (let from = 0; from < rows.length && !refused; from += PACK_ROWS) {
|
|
716
|
+
pack ??= packOf(rows, from, Math.min(rows.length, from + PACK_ROWS), stored);
|
|
717
|
+
if (!pack) {
|
|
718
|
+
refused = new Error("rows that are not plain");
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
sent.push(io.push(pack).catch((error) => (refused ??= error)));
|
|
722
|
+
pack = null;
|
|
723
|
+
if (sent.length >= 2) {
|
|
724
|
+
await sent[sent.length - 2];
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
await Promise.all(sent);
|
|
728
|
+
if (refused) {
|
|
729
|
+
throw refused;
|
|
730
|
+
}
|
|
731
|
+
await io.end();
|
|
732
|
+
return true;
|
|
733
|
+
} catch {
|
|
734
|
+
try {
|
|
735
|
+
await io.abort();
|
|
736
|
+
} catch {
|
|
737
|
+
// Nothing to drop, or no engine to ask: the JSON route is next either way.
|
|
738
|
+
}
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* [`loadColumns`] one at a time: the engine keeps one set of rows in the making, so two loads
|
|
745
|
+
* must not interleave their packs.
|
|
746
|
+
*/
|
|
747
|
+
function columnLoader(io) {
|
|
748
|
+
let queue = Promise.resolve();
|
|
749
|
+
return (name, rows, schema) => {
|
|
750
|
+
const run = queue.then(() => loadColumns(name, rows, schema, io));
|
|
751
|
+
queue = run.catch(() => {});
|
|
752
|
+
return run;
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
|
|
426
756
|
/**
|
|
427
757
|
* A provider over an engine that is already initialised on the main thread.
|
|
428
758
|
*
|
|
@@ -434,6 +764,18 @@ function rowsJson(rows) {
|
|
|
434
764
|
*/
|
|
435
765
|
export function createLocalProvider(engine) {
|
|
436
766
|
const watchers = createWatchers();
|
|
767
|
+
// Rows as packs of columns (issue #445); an engine module without the calls takes the JSON route.
|
|
768
|
+
const loadRowsAsColumns = columnLoader({
|
|
769
|
+
all: async (name, schema, rows, pack) => {
|
|
770
|
+
engine.begin_columns(name, schema, rows);
|
|
771
|
+
engine.push_columns(new Uint8Array(pack));
|
|
772
|
+
engine.end_columns();
|
|
773
|
+
},
|
|
774
|
+
begin: async (name, schema, rows) => engine.begin_columns(name, schema, rows),
|
|
775
|
+
push: async (pack) => engine.push_columns(new Uint8Array(pack)),
|
|
776
|
+
end: async () => engine.end_columns(),
|
|
777
|
+
abort: async () => engine.abort_columns(),
|
|
778
|
+
});
|
|
437
779
|
return {
|
|
438
780
|
/** Where the queries run; the grid names it in its footer (issue #33). */
|
|
439
781
|
kind: "local",
|
|
@@ -445,15 +787,35 @@ export function createLocalProvider(engine) {
|
|
|
445
787
|
);
|
|
446
788
|
watchers.loaded(name);
|
|
447
789
|
},
|
|
790
|
+
async loadStream(name, source, schema, options = {}) {
|
|
791
|
+
engine.begin_csv(name, schema, sizeOf(source));
|
|
792
|
+
try {
|
|
793
|
+
for await (const buffer of piecesOf(source, options.chunkSize)) {
|
|
794
|
+
engine.push_csv(new Uint8Array(buffer));
|
|
795
|
+
}
|
|
796
|
+
engine.end_csv();
|
|
797
|
+
} catch (error) {
|
|
798
|
+
engine.abort_csv();
|
|
799
|
+
throw error;
|
|
800
|
+
}
|
|
801
|
+
watchers.loaded(name);
|
|
802
|
+
},
|
|
448
803
|
async loadRows(name, rows, schema) {
|
|
449
|
-
|
|
804
|
+
if (!(await loadRowsAsColumns(name, rows, schema))) {
|
|
805
|
+
engine.load_rows(name, rowsJson(rows), schema);
|
|
806
|
+
}
|
|
450
807
|
watchers.loaded(name);
|
|
451
808
|
},
|
|
452
809
|
watch(host) {
|
|
453
810
|
watchers.watch(host);
|
|
454
811
|
},
|
|
812
|
+
/** The answer itself, or a promise of it while the collator loads (S4a). */
|
|
455
813
|
execute(queryJson) {
|
|
456
|
-
return engine.execute_columns(queryJson);
|
|
814
|
+
return withCollator(engine, queryJson, () => engine.execute_columns(queryJson));
|
|
815
|
+
},
|
|
816
|
+
/** Frees the source `name` (issue #459), as the worker provider does. */
|
|
817
|
+
async unload(name) {
|
|
818
|
+
return engine.unload(name);
|
|
457
819
|
},
|
|
458
820
|
/** What the engine holds (issue #70), as the worker provider says it. */
|
|
459
821
|
async stats() {
|
|
@@ -768,6 +1130,39 @@ function coded(code, message) {
|
|
|
768
1130
|
return error;
|
|
769
1131
|
}
|
|
770
1132
|
|
|
1133
|
+
// The collator of the engine (rule S4a): `collation.js` and the module behind it are fetched
|
|
1134
|
+
// by the first query that names a locale, and never otherwise — so a page that serves the
|
|
1135
|
+
// package's files itself and leaves them out loses locale sorts, not the grid. The same test
|
|
1136
|
+
// is in `worker.js`; the two must agree.
|
|
1137
|
+
const NAMES_A_LOCALE = /"collation"\s*:\s*"(?!binary")/;
|
|
1138
|
+
/** The engines and planners that were given their collator. */
|
|
1139
|
+
const withCollation = new WeakSet();
|
|
1140
|
+
|
|
1141
|
+
async function giveCollation(engine) {
|
|
1142
|
+
let collation;
|
|
1143
|
+
try {
|
|
1144
|
+
collation = await import("./collation.js");
|
|
1145
|
+
} catch (error) {
|
|
1146
|
+
throw coded(
|
|
1147
|
+
"module_not_loaded",
|
|
1148
|
+
`a sort by a locale needs collation.js, and it did not load (${error?.message ?? error})`,
|
|
1149
|
+
);
|
|
1150
|
+
}
|
|
1151
|
+
await collation.giveCollator(engine);
|
|
1152
|
+
withCollation.add(engine);
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Runs `run`, the answer itself — or, for a query that names a locale and an engine that has
|
|
1157
|
+
* no collator yet, a promise of it once the collation module is loaded.
|
|
1158
|
+
*/
|
|
1159
|
+
function withCollator(engine, json, run) {
|
|
1160
|
+
if (withCollation.has(engine) || !NAMES_A_LOCALE.test(json)) {
|
|
1161
|
+
return run();
|
|
1162
|
+
}
|
|
1163
|
+
return giveCollation(engine).then(run);
|
|
1164
|
+
}
|
|
1165
|
+
|
|
771
1166
|
/**
|
|
772
1167
|
* A provider that asks an `opengrid-server` for a whole **pivot**.
|
|
773
1168
|
*
|
|
@@ -863,10 +1258,14 @@ export function createHybridProvider({ remote, planner, mode = "auto", onPlan }
|
|
|
863
1258
|
if (!plan.client) {
|
|
864
1259
|
return partial;
|
|
865
1260
|
}
|
|
866
|
-
// The engine finishes in the form the source answered in
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
1261
|
+
// The engine finishes in the form the source answered in — with its
|
|
1262
|
+
// collator, when the client's half sorts by a locale (S4a).
|
|
1263
|
+
const client = JSON.stringify(plan.client);
|
|
1264
|
+
return withCollator(planner, client, () =>
|
|
1265
|
+
typeof partial === "string"
|
|
1266
|
+
? planner.finish(client, partial)
|
|
1267
|
+
: planner.finish_columns(client, partial),
|
|
1268
|
+
);
|
|
870
1269
|
},
|
|
871
1270
|
};
|
|
872
1271
|
}
|
|
@@ -1621,6 +2020,51 @@ function identityKey(value) {
|
|
|
1621
2020
|
});
|
|
1622
2021
|
}
|
|
1623
2022
|
|
|
2023
|
+
/** The bytes of a stream source when it says how many there are, else 0 (a hint, not a promise). */
|
|
2024
|
+
function sizeOf(source) {
|
|
2025
|
+
return typeof source?.size === "number" ? source.size : 0;
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
/**
|
|
2029
|
+
* The pieces of a CSV source: a `Blob` is read a slice at a time, a stream or an
|
|
2030
|
+
* async iterable as it delivers. Each piece is an `ArrayBuffer` the caller may transfer.
|
|
2031
|
+
*/
|
|
2032
|
+
async function* piecesOf(source, chunkSize = 4 * 1024 * 1024) {
|
|
2033
|
+
for await (const [piece, owned] of piecesAndOwners(source, chunkSize)) {
|
|
2034
|
+
// A piece the loader made, or a stream's chunk, is the loader's to hand on; the bytes an async
|
|
2035
|
+
// iterable yields may be reused by it, so they are copied.
|
|
2036
|
+
yield owned && piece.byteOffset === 0 && piece.byteLength === piece.buffer.byteLength
|
|
2037
|
+
? piece.buffer
|
|
2038
|
+
: toTransferable(piece);
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
|
|
2042
|
+
async function* piecesAndOwners(source, chunkSize) {
|
|
2043
|
+
if (typeof Blob !== "undefined" && source instanceof Blob) {
|
|
2044
|
+
for (let at = 0; at < source.size; at += chunkSize) {
|
|
2045
|
+
yield [new Uint8Array(await source.slice(at, at + chunkSize).arrayBuffer()), true];
|
|
2046
|
+
}
|
|
2047
|
+
return;
|
|
2048
|
+
}
|
|
2049
|
+
if (typeof source?.getReader === "function") {
|
|
2050
|
+
const reader = source.getReader();
|
|
2051
|
+
try {
|
|
2052
|
+
for (;;) {
|
|
2053
|
+
const { done, value } = await reader.read();
|
|
2054
|
+
if (done) return;
|
|
2055
|
+
yield [value, true];
|
|
2056
|
+
}
|
|
2057
|
+
} finally {
|
|
2058
|
+
reader.releaseLock();
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
if (typeof source?.[Symbol.asyncIterator] === "function") {
|
|
2062
|
+
for await (const piece of source) yield [piece, false];
|
|
2063
|
+
return;
|
|
2064
|
+
}
|
|
2065
|
+
throw new TypeError("a CSV source must be a Blob, a ReadableStream or an async iterable of bytes");
|
|
2066
|
+
}
|
|
2067
|
+
|
|
1624
2068
|
/**
|
|
1625
2069
|
* The CSV bytes as a transferable `ArrayBuffer`.
|
|
1626
2070
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@casoon/opengrid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Accessible data grid, table and pivot as web components, driven by a portable Rust/WASM query engine — with React, Vue and Svelte components.",
|
|
6
6
|
"keywords": [
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"./pkg/*": "./pkg/*",
|
|
53
53
|
"./engine/*": "./engine/*",
|
|
54
54
|
"./xlsx/*": "./xlsx/*",
|
|
55
|
+
"./collation/*": "./collation/*",
|
|
55
56
|
"./package.json": "./package.json"
|
|
56
57
|
},
|
|
57
58
|
"main": "./loader.js",
|
|
@@ -63,6 +64,7 @@
|
|
|
63
64
|
"loader.js",
|
|
64
65
|
"loader.d.ts",
|
|
65
66
|
"worker.js",
|
|
67
|
+
"collation.js",
|
|
66
68
|
"react/",
|
|
67
69
|
"vue/",
|
|
68
70
|
"svelte/",
|
|
@@ -70,6 +72,7 @@
|
|
|
70
72
|
"pkg/",
|
|
71
73
|
"engine/",
|
|
72
74
|
"xlsx/",
|
|
75
|
+
"collation/",
|
|
73
76
|
"LICENSE-MIT",
|
|
74
77
|
"LICENSE-APACHE",
|
|
75
78
|
"README.md",
|
|
@@ -313,16 +313,16 @@ export interface InitOutput {
|
|
|
313
313
|
readonly set_validators: (a: any, b: any) => void;
|
|
314
314
|
readonly set_values: (a: any, b: any) => void;
|
|
315
315
|
readonly set_view: (a: any, b: any, c: any) => void;
|
|
316
|
-
readonly
|
|
317
|
-
readonly
|
|
318
|
-
readonly
|
|
319
|
-
readonly
|
|
320
|
-
readonly
|
|
321
|
-
readonly
|
|
322
|
-
readonly
|
|
323
|
-
readonly
|
|
324
|
-
readonly
|
|
325
|
-
readonly
|
|
316
|
+
readonly wasm_bindgen_f2793286032f204f___convert__closures_____invoke___web_sys_d90b8ce3fc65d21___features__gen_HtmlElement__HtmlElement__alloc_98d089680bbbc9df___string__String__core_d941ad8722425d2e___option__Option_alloc_98d089680bbbc9df___string__String___core_d941ad8722425d2e___option__Option_alloc_98d089680bbbc9df___string__String_______true_: (a: number, b: number, c: any, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
317
|
+
readonly wasm_bindgen_f2793286032f204f___convert__closures_____invoke___wasm_bindgen_f2793286032f204f___JsValue__core_d941ad8722425d2e___result__Result_____wasm_bindgen_f2793286032f204f___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
318
|
+
readonly wasm_bindgen_f2793286032f204f___convert__closures_____invoke___js_sys_3247ddf4d7647dab___Function_fn_wasm_bindgen_f2793286032f204f___JsValue_____wasm_bindgen_f2793286032f204f___sys__Undefined___js_sys_3247ddf4d7647dab___Function_fn_wasm_bindgen_f2793286032f204f___JsValue_____wasm_bindgen_f2793286032f204f___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
|
|
319
|
+
readonly wasm_bindgen_f2793286032f204f___convert__closures_____invoke___wasm_bindgen_f2793286032f204f___JsValue______true_: (a: number, b: number, c: any) => void;
|
|
320
|
+
readonly wasm_bindgen_f2793286032f204f___convert__closures_____invoke___wasm_bindgen_f2793286032f204f___JsValue______true__2: (a: number, b: number, c: any) => void;
|
|
321
|
+
readonly wasm_bindgen_f2793286032f204f___convert__closures_____invoke___wasm_bindgen_f2793286032f204f___JsValue______true__3: (a: number, b: number, c: any) => void;
|
|
322
|
+
readonly wasm_bindgen_f2793286032f204f___convert__closures_____invoke___wasm_bindgen_f2793286032f204f___JsValue______true__5: (a: number, b: number, c: any) => void;
|
|
323
|
+
readonly wasm_bindgen_f2793286032f204f___convert__closures_____invoke___wasm_bindgen_f2793286032f204f___JsValue______true__6: (a: number, b: number, c: any) => void;
|
|
324
|
+
readonly wasm_bindgen_f2793286032f204f___convert__closures_____invoke___u32______true_: (a: number, b: number, c: number) => void;
|
|
325
|
+
readonly wasm_bindgen_f2793286032f204f___convert__closures_____invoke_______true_: (a: number, b: number) => void;
|
|
326
326
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
327
327
|
readonly __externref_table_alloc: () => number;
|
|
328
328
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|