vastgrid-js 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +211 -2
  3. package/dist/aggregate.d.ts +45 -0
  4. package/dist/aggregate.d.ts.map +1 -0
  5. package/dist/aggregate.js +305 -0
  6. package/dist/aggregate.js.map +1 -0
  7. package/dist/arrow.d.ts +7 -0
  8. package/dist/arrow.d.ts.map +1 -0
  9. package/dist/arrow.js +25 -0
  10. package/dist/arrow.js.map +1 -0
  11. package/dist/engine.d.ts +40 -0
  12. package/dist/engine.d.ts.map +1 -0
  13. package/dist/engine.js +1022 -0
  14. package/dist/engine.js.map +1 -0
  15. package/dist/evaluate.d.ts +37 -0
  16. package/dist/evaluate.d.ts.map +1 -0
  17. package/dist/evaluate.js +774 -0
  18. package/dist/evaluate.js.map +1 -0
  19. package/dist/export.d.ts +23 -0
  20. package/dist/export.d.ts.map +1 -0
  21. package/dist/export.js +48 -0
  22. package/dist/export.js.map +1 -0
  23. package/dist/index.d.ts +3 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +2 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/lazy.d.ts +65 -0
  28. package/dist/lazy.d.ts.map +1 -0
  29. package/dist/lazy.js +177 -0
  30. package/dist/lazy.js.map +1 -0
  31. package/dist/numbers.d.ts +20 -0
  32. package/dist/numbers.d.ts.map +1 -0
  33. package/dist/numbers.js +129 -0
  34. package/dist/numbers.js.map +1 -0
  35. package/dist/order.d.ts +67 -0
  36. package/dist/order.d.ts.map +1 -0
  37. package/dist/order.js +561 -0
  38. package/dist/order.js.map +1 -0
  39. package/dist/parquet.d.ts +38 -0
  40. package/dist/parquet.d.ts.map +1 -0
  41. package/dist/parquet.js +673 -0
  42. package/dist/parquet.js.map +1 -0
  43. package/dist/plan.d.ts +37 -0
  44. package/dist/plan.d.ts.map +1 -0
  45. package/dist/plan.js +51 -0
  46. package/dist/plan.js.map +1 -0
  47. package/dist/summary.d.ts +37 -0
  48. package/dist/summary.d.ts.map +1 -0
  49. package/dist/summary.js +175 -0
  50. package/dist/summary.js.map +1 -0
  51. package/dist/table.d.ts +172 -0
  52. package/dist/table.d.ts.map +1 -0
  53. package/dist/table.js +154 -0
  54. package/dist/table.js.map +1 -0
  55. package/dist/text.d.ts +18 -0
  56. package/dist/text.d.ts.map +1 -0
  57. package/dist/text.js +1204 -0
  58. package/dist/text.js.map +1 -0
  59. package/dist/workbook.d.ts +6 -0
  60. package/dist/workbook.d.ts.map +1 -0
  61. package/dist/workbook.js +35 -0
  62. package/dist/workbook.js.map +1 -0
  63. package/package.json +46 -4
  64. package/src/aggregate.ts +358 -0
  65. package/src/arrow.ts +24 -0
  66. package/src/engine.ts +1163 -0
  67. package/src/evaluate.ts +764 -0
  68. package/src/export.ts +73 -0
  69. package/src/index.ts +2 -0
  70. package/src/lazy.ts +185 -0
  71. package/src/numbers.ts +128 -0
  72. package/src/order.ts +594 -0
  73. package/src/parquet.ts +801 -0
  74. package/src/plan.ts +99 -0
  75. package/src/summary.ts +180 -0
  76. package/src/table.ts +297 -0
  77. package/src/text.ts +1285 -0
  78. package/src/workbook.ts +48 -0
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Excel workbooks as tables: a sheet is read with `vastgrid-spec/workbook` into lines of CSV kept as a `Blob`, which
3
+ * `readFile` of text.ts then reads as it reads a CSV file, within `maxBytes`, with the columns and types that the
4
+ * DuckDB engine reads the sheet with.
5
+ */
6
+ import type { Column } from "vastgrid-spec";
7
+ import { blobSource, convertSheet, type ReadOptions, WorkbookError } from "vastgrid-spec/workbook";
8
+
9
+ export { readOptionsOf } from "vastgrid-spec/workbook";
10
+
11
+ import { type CheckedTable, type FileTable, TableProblem, type TextFile } from "./table.js";
12
+ import { readFile } from "./text.js";
13
+
14
+ /** The platform's `Blob`, which keeps the sheet's lines out of the heap where it can (in a page, on disk). */
15
+ declare const Blob: new (parts: (string | TextFile)[]) => TextFile;
16
+
17
+ /** Reads the sheet of a workbook that `read` chooses, the first visible one by default. */
18
+ export async function readSheet(table: FileTable, read: ReadOptions): Promise<CheckedTable> {
19
+ const { file } = table;
20
+ if (
21
+ file === null ||
22
+ typeof file !== "object" ||
23
+ typeof file.size !== "number" ||
24
+ typeof (file as { slice?: unknown }).slice !== "function"
25
+ ) {
26
+ throw new TableProblem("/file", "file is a Blob or a File.");
27
+ }
28
+ const parts: TextFile[] = [];
29
+ let sheet: Awaited<ReturnType<typeof convertSheet>>;
30
+ try {
31
+ sheet = await convertSheet(
32
+ blobSource(file),
33
+ (text) => {
34
+ parts.push(new Blob([text]));
35
+ },
36
+ read,
37
+ );
38
+ } catch (error) {
39
+ if (error instanceof WorkbookError) throw new TableProblem("/file", error.message);
40
+ throw error;
41
+ }
42
+ const fields: (Column | null)[] = new Array(sheet.fields).fill(null);
43
+ for (const column of sheet.columns) fields[column.field] = { name: column.name, type: column.type };
44
+ const lines: FileTable = { file: new Blob(parts), format: "csv", delimiter: ",", header: false };
45
+ if (table.maxBytes !== undefined) lines.maxBytes = table.maxBytes;
46
+ const checked = await readFile(lines, undefined, fields);
47
+ return { ...checked, workbook: { sheets: sheet.sheets, sheet: sheet.sheet, notes: sheet.notes } };
48
+ }