@casoon/opengrid 0.20.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.
package/CHANGELOG.md CHANGED
@@ -19,6 +19,35 @@ Two things belong in every release entry and are easy to leave out:
19
19
 
20
20
  ## [Unreleased]
21
21
 
22
+ ## [0.20.1] - 2026-11-23
23
+
24
+ Not yet verified by a screen reader: no pass with assistive technology has been recorded for this
25
+ release ([#5](https://github.com/casoon/opengrid/issues/5)). The keyboard and `axe-core` checks run on
26
+ every change.
27
+
28
+ **What breaks:** nothing; two functions are added to `loader.js`.
29
+
30
+ ### Added
31
+
32
+ - **Loader:** `fromRows(host, rows)` puts rows the page holds into a grid in one call, without a
33
+ schema; `inferSchema(rows)` reads the types from the rows and hands back the schema JSON
34
+ `loadRows` takes. Details:
35
+ [Data you already have](https://casoon.github.io/opengrid/docs/guides/data-you-have/)
36
+ ([#460](https://github.com/casoon/opengrid/issues/460)).
37
+
38
+ ### Changed
39
+
40
+ - **Pages:** the project site uses the current shared theme (0.16.4).
41
+ - **Contributors:** two WebKit specs wait for the focus scroll to land before they scroll on, and no
42
+ longer fail now and then ([#420](https://github.com/casoon/opengrid/issues/420)).
43
+
44
+ ### Security
45
+
46
+ - **Server:** the lockfile takes `url` 2.5.9 (from 2.5.8, through `mysql_async`), which fixes a
47
+ stack overflow in `Url::origin()` on nested `blob:` URLs
48
+ ([RUSTSEC-2026-0592](https://rustsec.org/advisories/RUSTSEC-2026-0592)). opengrid does not call
49
+ `origin()`; `cargo install opengrid-serve --locked` gets the fixed version.
50
+
22
51
  ## [0.20.0] - 2026-11-19
23
52
 
24
53
  Not yet verified by a screen reader: no pass with assistive technology has been recorded for this
@@ -1879,7 +1908,8 @@ tested.
1879
1908
  tested: React 18 rendering on the server, SvelteKit, Nuxt, Next.js and Astro
1880
1909
  as real applications. A Vite production build needs `loadOpengrid({ moduleUrl })`.
1881
1910
 
1882
- [Unreleased]: https://github.com/casoon/opengrid/compare/v0.20.0...HEAD
1911
+ [Unreleased]: https://github.com/casoon/opengrid/compare/v0.20.1...HEAD
1912
+ [0.20.1]: https://github.com/casoon/opengrid/compare/v0.20.0...v0.20.1
1883
1913
  [0.20.0]: https://github.com/casoon/opengrid/compare/v0.19.0...v0.20.0
1884
1914
  [0.19.0]: https://github.com/casoon/opengrid/compare/v0.18.1...v0.19.0
1885
1915
  [0.18.1]: https://github.com/casoon/opengrid/compare/v0.18.0...v0.18.1
package/README.md CHANGED
@@ -67,7 +67,20 @@ While the version is 0.x, a minor bump may break the Rust API
67
67
 
68
68
  ## Data in the browser
69
69
 
70
- The engine reads a CSV against a schema — it never guesses types.
70
+ Rows the page already holds become a grid in one call; the types are read from the rows:
71
+
72
+ ```html
73
+ <opengrid-grid label="Orders"></opengrid-grid>
74
+
75
+ <script type="module">
76
+ import { fromRows } from "@casoon/opengrid";
77
+ const rows = [{ id: 1, customer: "Ada", amount: 120 }, { id: 2, customer: "Grace", amount: 80 }];
78
+ await fromRows(document.querySelector("opengrid-grid"), rows);
79
+ </script>
80
+ ```
81
+
82
+ When you need exact types — a decimal for money, a CSV file — the engine reads against a schema;
83
+ it never guesses them itself.
71
84
 
72
85
  ```html
73
86
  <opengrid-grid label="Orders" datasource="orders" columns="id,customer,amount"></opengrid-grid>
@@ -528,14 +528,14 @@ function __wbg_get_imports() {
528
528
  __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
529
529
  throw new Error(getStringFromWasm0(arg0, arg1));
530
530
  },
531
- __wbg_call_917e74a3a91ee2cd: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) {
531
+ __wbg_call_ff181de0cf4aac15: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) {
532
532
  const ret = arg1.call(arg2, getStringFromWasm0(arg3, arg4), getArrayU8FromWasm0(arg5, arg6), getArrayU32FromWasm0(arg7, arg8));
533
533
  const ptr1 = passArray8ToWasm0(ret, wasm.__wbindgen_malloc);
534
534
  const len1 = WASM_VECTOR_LEN;
535
535
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
536
536
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
537
537
  }, arguments); },
538
- __wbg_message_e4fec75b4feaf7f7: function(arg0) {
538
+ __wbg_message_6f2fc50a4dccc7a2: function(arg0) {
539
539
  const ret = arg0.message;
540
540
  return ret;
541
541
  },
Binary file
package/loader.d.ts CHANGED
@@ -258,6 +258,48 @@ export function connect(
258
258
  options: PivotConnectOptions,
259
259
  ): Connection<PivotConnectOptions>;
260
260
 
261
+ // ---------------------------------------------------------------------------
262
+ // From plain rows (issue #460)
263
+ // ---------------------------------------------------------------------------
264
+
265
+ /**
266
+ * The schema JSON of `rows`, read from every row, as `loadRows` takes it: a
267
+ * boolean is `bool`; a number `int64` when every value of the field is an
268
+ * integer, else `float64` (with a warning: money wants a `decimal`); a string
269
+ * `date` when every value is a `YYYY-MM-DD` day, else `utf8`; a field `null` or
270
+ * missing in a row is nullable. Throws a {@link CodedError} with code `"cannot_infer"`,
271
+ * naming row and field, for values of two kinds in one field, an integer
272
+ * beyond 2^53, a number that is not finite, a bigint, an object, a list, or a
273
+ * field with no value in any row.
274
+ */
275
+ export function inferSchema(rows: readonly Record<string, unknown>[]): string;
276
+
277
+ export interface FromRowsOptions {
278
+ /** The schema JSON; wins over inference. */
279
+ schema?: string;
280
+ /** Where the rows go; a new `createWorkerProvider()` by default. */
281
+ provider?: EngineProvider;
282
+ }
283
+
284
+ export interface FromRowsResult {
285
+ /** The schema the rows were loaded with — given or inferred. */
286
+ schema: string;
287
+ provider: EngineProvider;
288
+ connection: Connection;
289
+ }
290
+
291
+ /**
292
+ * Rows to a table in one call: the schema (given, or {@link inferSchema}), a
293
+ * provider, the rows loaded into it and the element connected. `datasource`
294
+ * becomes `rows` and `columns` every field where the element has none. For
295
+ * `<opengrid-grid>` and `<opengrid-table>`.
296
+ */
297
+ export function fromRows(
298
+ host: HTMLElement,
299
+ rows: readonly Record<string, unknown>[],
300
+ options?: FromRowsOptions,
301
+ ): Promise<FromRowsResult>;
302
+
261
303
  // ---------------------------------------------------------------------------
262
304
  // Providers
263
305
  // ---------------------------------------------------------------------------
@@ -641,7 +683,8 @@ export type ErrorCode =
641
683
  | "data"
642
684
  | "too_many_rows"
643
685
  | "source_changed"
644
- | "module_not_loaded";
686
+ | "module_not_loaded"
687
+ | "cannot_infer";
645
688
 
646
689
  /**
647
690
  * What the REST and pivot providers and `exportRows` reject with: a plain
package/loader.js CHANGED
@@ -1988,6 +1988,150 @@ export function connect(host, options = {}) {
1988
1988
  };
1989
1989
  }
1990
1990
 
1991
+ // ---------------------------------------------------------------------------------------------
1992
+ // From plain rows to a table (issue #460)
1993
+ //
1994
+ // The engine never guesses a type; the package may, for a page that has `[{…}, {…}]` and no
1995
+ // schema. What it guesses is an ordinary schema JSON, handed back to the caller, so the guess is
1996
+ // visible, can be saved, and can be passed to `loadRows` unchanged.
1997
+ // ---------------------------------------------------------------------------------------------
1998
+
1999
+ const DATE_TEXT = /^(\d{4})-(\d{2})-(\d{2})$/;
2000
+
2001
+ /** A `YYYY-MM-DD` that is a day of the calendar: `2026-02-30` is text, not a date. */
2002
+ function isDateText(text) {
2003
+ const parts = DATE_TEXT.exec(text);
2004
+ if (!parts) {
2005
+ return false;
2006
+ }
2007
+ const [year, month, day] = [Number(parts[1]), Number(parts[2]) - 1, Number(parts[3])];
2008
+ const date = new Date(0);
2009
+ date.setUTCFullYear(year, month, day);
2010
+ return date.getUTCFullYear() === year && date.getUTCMonth() === month && date.getUTCDate() === day;
2011
+ }
2012
+
2013
+ /** What a value is, in the words of a refusal. */
2014
+ function shapeOf(value) {
2015
+ if (Array.isArray(value)) {
2016
+ return "a list";
2017
+ }
2018
+ return { bigint: "a bigint", object: "an object" }[typeof value] ?? `a ${typeof value}`;
2019
+ }
2020
+
2021
+ function refuseField(row, name, why) {
2022
+ throw coded("cannot_infer", `inferSchema: row ${row}, field ${name}: ${why}; give a schema`);
2023
+ }
2024
+
2025
+ /**
2026
+ * The schema JSON of `rows`, read from every row: a boolean is `bool`; a number `int64` when every
2027
+ * value of the field is an integer, else `float64`; a string `date` when every value is a
2028
+ * `YYYY-MM-DD` day, else `utf8`; a field that is `null` or missing in a row is nullable. The
2029
+ * fields are in the order they first appear.
2030
+ *
2031
+ * It refuses — an `Error` with `code: "cannot_infer"`, naming row and field — what it cannot type without
2032
+ * guessing: values of two kinds in one field, an integer beyond 2^53, a number that is not finite,
2033
+ * a bigint, an object or a list, a field with no value in any row. A field with fractions becomes
2034
+ * `float64` and is named in a warning: money wants a `decimal` in a schema of its own.
2035
+ *
2036
+ * @param {Record<string, unknown>[]} rows
2037
+ * @returns {string} the schema JSON `loadRows` takes.
2038
+ */
2039
+ export function inferSchema(rows) {
2040
+ if (!Array.isArray(rows) || rows.length === 0) {
2041
+ throw coded("cannot_infer", "inferSchema: no rows to read the types from; give a schema");
2042
+ }
2043
+ /** Per field, in order: the kind of its values, where it was seen first, and what it held. */
2044
+ const fields = new Map();
2045
+ rows.forEach((row, index) => {
2046
+ if (row === null || typeof row !== "object" || Object.getPrototypeOf(row) !== Object.prototype) {
2047
+ throw coded("cannot_infer", `inferSchema: row ${index} is ${row === null ? "null" : shapeOf(row)}, not an object of fields`);
2048
+ }
2049
+ for (const [name, value] of Object.entries(row)) {
2050
+ let field = fields.get(name);
2051
+ if (!field) {
2052
+ field = { kind: null, row: index, values: 0, fraction: false, dates: true };
2053
+ fields.set(name, field);
2054
+ }
2055
+ if (value === null || value === undefined) {
2056
+ continue;
2057
+ }
2058
+ let kind;
2059
+ if (typeof value === "boolean") {
2060
+ kind = "bool";
2061
+ } else if (typeof value === "number") {
2062
+ if (!Number.isFinite(value)) {
2063
+ refuseField(index, name, `${value} is not a finite number`);
2064
+ }
2065
+ if (Number.isInteger(value) && !Number.isSafeInteger(value)) {
2066
+ refuseField(index, name, `${value} is beyond 2^53 and not exact in JavaScript`);
2067
+ }
2068
+ kind = "number";
2069
+ field.fraction ||= !Number.isInteger(value);
2070
+ } else if (typeof value === "string") {
2071
+ kind = "string";
2072
+ field.dates &&= isDateText(value);
2073
+ } else {
2074
+ refuseField(index, name, `${shapeOf(value)} cannot be typed`);
2075
+ }
2076
+ if (field.kind === null) {
2077
+ field.kind = kind;
2078
+ field.row = index;
2079
+ } else if (field.kind !== kind) {
2080
+ refuseField(index, name, `a ${kind} where row ${field.row} has a ${field.kind}`);
2081
+ }
2082
+ field.values += 1;
2083
+ }
2084
+ });
2085
+ const schema = [];
2086
+ for (const [name, field] of fields) {
2087
+ if (field.kind === null) {
2088
+ throw coded("cannot_infer", `inferSchema: field ${name} is null or missing in every row; give a schema`);
2089
+ }
2090
+ const type = {
2091
+ bool: "bool",
2092
+ number: field.fraction ? "float64" : "int64",
2093
+ string: field.dates ? "date" : "utf8",
2094
+ }[field.kind];
2095
+ if (field.fraction) {
2096
+ console.warn(
2097
+ `[opengrid] inferSchema: field ${name} has fractions and becomes float64. ` +
2098
+ "For money, give it a decimal in a schema: " +
2099
+ `{ "name": "${name}", "type": { "decimal": { "precision": 12, "scale": 2 } } }`,
2100
+ );
2101
+ }
2102
+ schema.push({ name, type, nullable: field.values < rows.length });
2103
+ }
2104
+ return JSON.stringify({ fields: schema });
2105
+ }
2106
+
2107
+ /**
2108
+ * Rows to a table in one call: the schema (`schema`, or `inferSchema(rows)`), a provider (the
2109
+ * worker, unless `provider` is given), the rows loaded into it, and the element connected.
2110
+ * `datasource` becomes `rows` and `columns` every field, where the element has none. For
2111
+ * `<opengrid-grid>` and `<opengrid-table>`; a pivot's `columns` are its own.
2112
+ *
2113
+ * @param {HTMLElement} host
2114
+ * @param {Record<string, unknown>[]} rows
2115
+ * @param {{schema?: string, provider?: object}} [options]
2116
+ * @returns {Promise<{schema: string, provider: object, connection: object}>}
2117
+ */
2118
+ export async function fromRows(host, rows, { schema, provider } = {}) {
2119
+ const used = schema ?? inferSchema(rows);
2120
+ const target = provider ?? createWorkerProvider();
2121
+ if (!host.getAttribute("datasource")) {
2122
+ host.setAttribute("datasource", "rows");
2123
+ }
2124
+ if (!host.getAttribute("columns")) {
2125
+ const names = JSON.parse(used).fields.filter((field) => field.from == null).map((field) => field.name);
2126
+ host.setAttribute("columns", names.join(","));
2127
+ }
2128
+ // The module loads while the rows go in; the provider is set once they are there.
2129
+ await Promise.all([target.loadRows(host.getAttribute("datasource"), rows, used), loadOpengrid()]);
2130
+ const connection = connect(host, { provider: target });
2131
+ await connection.ready;
2132
+ return { schema: used, provider: target, connection };
2133
+ }
2134
+
1991
2135
  /**
1992
2136
  * A JSON key that does not depend on the order an object's keys were written
1993
2137
  * in; `each` may stand in for a value first.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@casoon/opengrid",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
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": [
@@ -1,12 +1,12 @@
1
1
  /* @ts-self-types="./opengrid_web_components.d.ts" */
2
- import { __opengrid_numbers } from './snippets/opengrid-web-components-25af30e209691150/inline0.js';
3
- import { __opengrid_intl_formatter, __opengrid_page_lang } from './snippets/opengrid-web-components-25af30e209691150/inline1.js';
4
- import { __opengrid_define_element } from './snippets/opengrid-web-core-a8478162475cb80f/inline1.js';
5
- import { __opengrid_apply_frame, __opengrid_remove_attribute, __opengrid_set_attribute, __opengrid_set_text } from './snippets/opengrid-web-core-a8478162475cb80f/inline2.js';
6
- import * as import1 from "./snippets/opengrid-web-components-25af30e209691150/inline1.js"
7
- import * as import2 from "./snippets/opengrid-web-core-a8478162475cb80f/inline0.js"
8
- import * as import3 from "./snippets/opengrid-web-core-a8478162475cb80f/inline0.js"
9
- import * as import4 from "./snippets/opengrid-web-core-a8478162475cb80f/inline0.js"
2
+ import { __opengrid_numbers } from './snippets/opengrid-web-components-75269052febb3de2/inline0.js';
3
+ import { __opengrid_intl_formatter, __opengrid_page_lang } from './snippets/opengrid-web-components-75269052febb3de2/inline1.js';
4
+ import { __opengrid_define_element } from './snippets/opengrid-web-core-d95b346530aeec64/inline1.js';
5
+ import { __opengrid_apply_frame, __opengrid_remove_attribute, __opengrid_set_attribute, __opengrid_set_text } from './snippets/opengrid-web-core-d95b346530aeec64/inline2.js';
6
+ import * as import1 from "./snippets/opengrid-web-components-75269052febb3de2/inline1.js"
7
+ import * as import2 from "./snippets/opengrid-web-core-d95b346530aeec64/inline0.js"
8
+ import * as import3 from "./snippets/opengrid-web-core-d95b346530aeec64/inline0.js"
9
+ import * as import4 from "./snippets/opengrid-web-core-d95b346530aeec64/inline0.js"
10
10
 
11
11
 
12
12
  /**
@@ -454,34 +454,34 @@ function __wbg_get_imports() {
454
454
  const ret = Error(getStringFromWasm0(arg0, arg1));
455
455
  return ret;
456
456
  },
457
- __wbg___opengrid_apply_frame_85879b018ab2e7cb: function(arg0, arg1, arg2, arg3, arg4, arg5) {
457
+ __wbg___opengrid_apply_frame_06dd239da6b6ba6e: function(arg0, arg1, arg2, arg3, arg4, arg5) {
458
458
  __opengrid_apply_frame(arg0, arg1, getArrayU32FromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
459
459
  },
460
- __wbg___opengrid_define_element_9704a787890ca028: function(arg0, arg1, arg2, arg3, arg4, arg5) {
460
+ __wbg___opengrid_define_element_13decd10cb213d6e: function(arg0, arg1, arg2, arg3, arg4, arg5) {
461
461
  __opengrid_define_element(getStringFromWasm0(arg0, arg1), arg2, arg3, arg4, arg5);
462
462
  },
463
- __wbg___opengrid_intl_formatter_792e7cdcfdb83fbe: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
463
+ __wbg___opengrid_intl_formatter_c9bc684fa5eb7748: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
464
464
  const ret = __opengrid_intl_formatter(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), arg4);
465
465
  return ret;
466
466
  }, arguments); },
467
- __wbg___opengrid_numbers_3f967ba8e4c00ed0: function(arg0, arg1) {
467
+ __wbg___opengrid_numbers_ac18e7a8fea04af5: function(arg0, arg1) {
468
468
  const ret = __opengrid_numbers(getArrayF64FromWasm0(arg0, arg1));
469
469
  return ret;
470
470
  },
471
- __wbg___opengrid_page_lang_aff5a9f00d903227: function(arg0, arg1) {
471
+ __wbg___opengrid_page_lang_6fcce0a0ddc6f7db: function(arg0, arg1) {
472
472
  const ret = __opengrid_page_lang(arg1);
473
473
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
474
474
  const len1 = WASM_VECTOR_LEN;
475
475
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
476
476
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
477
477
  },
478
- __wbg___opengrid_remove_attribute_fe41162f7dc5517c: function(arg0, arg1, arg2) {
478
+ __wbg___opengrid_remove_attribute_5351d90d2c41d413: function(arg0, arg1, arg2) {
479
479
  __opengrid_remove_attribute(arg0, getStringFromWasm0(arg1, arg2));
480
480
  },
481
- __wbg___opengrid_set_attribute_b3b571020c7ef4dd: function(arg0, arg1, arg2, arg3, arg4) {
481
+ __wbg___opengrid_set_attribute_30638c401c40428a: function(arg0, arg1, arg2, arg3, arg4) {
482
482
  __opengrid_set_attribute(arg0, getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));
483
483
  },
484
- __wbg___opengrid_set_text_1741df9b3567bacc: function(arg0, arg1, arg2) {
484
+ __wbg___opengrid_set_text_6d4ee74a47a9b36e: function(arg0, arg1, arg2) {
485
485
  __opengrid_set_text(arg0, getStringFromWasm0(arg1, arg2));
486
486
  },
487
487
  __wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(arg0) {
@@ -1508,10 +1508,10 @@ function __wbg_get_imports() {
1508
1508
  return {
1509
1509
  __proto__: null,
1510
1510
  "./opengrid_web_components_bg.js": import0,
1511
- "./snippets/opengrid-web-components-25af30e209691150/inline1.js": import1,
1512
- "./snippets/opengrid-web-core-a8478162475cb80f/inline0.js": import2,
1513
- "./snippets/opengrid-web-core-a8478162475cb80f/inline0.js": import3,
1514
- "./snippets/opengrid-web-core-a8478162475cb80f/inline0.js": import4,
1511
+ "./snippets/opengrid-web-components-75269052febb3de2/inline1.js": import1,
1512
+ "./snippets/opengrid-web-core-d95b346530aeec64/inline0.js": import2,
1513
+ "./snippets/opengrid-web-core-d95b346530aeec64/inline0.js": import3,
1514
+ "./snippets/opengrid-web-core-d95b346530aeec64/inline0.js": import4,
1515
1515
  };
1516
1516
  }
1517
1517
 
Binary file
Binary file