@malloydata/malloyyo 0.2.27 → 0.2.29

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.
@@ -0,0 +1,46 @@
1
+ // Copyright (c) The Malloy Foundation
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ // MIRROR of packages/mcp-engine/src/rows.ts — read that file for the full
5
+ // rationale (malloyyo#137: Malloy's toJSON() renders every `numberType:
6
+ // 'bigint'` as a decimal string regardless of magnitude, so Vega-Lite and
7
+ // friends sort "1","10","11","2").
8
+ //
9
+ // Why a copy instead of an import: this file belongs to the frame source set
10
+ // that `dashboard bundle` ships AS SOURCE inside dist/ and re-bundles on the
11
+ // user's machine, resolving imports against their model repo. It therefore
12
+ // cannot reference a workspace package. The copy is small and pinned to the
13
+ // engine's behaviour by packages/cli/test/json-rows.test.ts, which runs both
14
+ // implementations over the same result and asserts they agree.
15
+
16
+ /** Largest bigint that survives a round trip through a JS number. */
17
+ const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
18
+ const MIN_SAFE = -MAX_SAFE;
19
+
20
+ /** Recursively JSON-ify one value out of toObject() (bigints, Dates, nests). */
21
+ function jsonValue(value: unknown): unknown {
22
+ if (typeof value === "bigint") {
23
+ return value <= MAX_SAFE && value >= MIN_SAFE ? Number(value) : value.toString();
24
+ }
25
+ if (value instanceof Date) return value.toISOString();
26
+ if (Array.isArray(value)) return value.map(jsonValue);
27
+ if (value !== null && typeof value === "object" && value.constructor === Object) {
28
+ const out: Record<string, unknown> = {};
29
+ for (const [k, v] of Object.entries(value)) out[k] = jsonValue(v);
30
+ return out;
31
+ }
32
+ return value;
33
+ }
34
+
35
+ /**
36
+ * The JSON-safe rows for a Malloy result — identical to
37
+ * `result.data.toJSON()`, except BIGINT values within ±MAX_SAFE_INTEGER come
38
+ * back as JSON numbers rather than strings. Typed loosely (`any`) because the
39
+ * frame set is bundled without the Malloy type packages on the resolve path.
40
+ */
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
+ export function jsonRows(result: any): Record<string, unknown>[] {
43
+ // DDL statements carry no schema — mirror Result.toJSON()'s own guard.
44
+ if (!result.hasSchema) return result.toJSON().queryResult.result;
45
+ return result.data.toObject().map((row: unknown) => jsonValue(row) as Record<string, unknown>);
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloyyo",
3
- "version": "0.2.27",
3
+ "version": "0.2.29",
4
4
  "description": "Publish Malloy models to a Malloyyo instance",
5
5
  "license": "MIT",
6
6
  "repository": {