@malloy-publisher/server 0.0.229 → 0.0.231
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/dist/app/api-doc.yaml +18 -9
- package/dist/app/assets/{EnvironmentPage-QOoHiVeJ.js → EnvironmentPage-wa_EPkwK.js} +1 -1
- package/dist/app/assets/{HomePage-C71GOfVW.js → HomePage-jnCrupQp.js} +1 -1
- package/dist/app/assets/{LightMode-CrgCAwLe.js → LightMode-DYbwNULZ.js} +1 -1
- package/dist/app/assets/{MainPage-BG5__FN3.js → MainPage-CuJLrPNI.js} +1 -1
- package/dist/app/assets/{MaterializationsPage-DE6PnrDR.js → MaterializationsPage-D_67x2ee.js} +1 -1
- package/dist/app/assets/{ModelPage-CcBjcbLm.js → ModelPage-D5JtAWqR.js} +1 -1
- package/dist/app/assets/{PackagePage-JTy3ztkB.js → PackagePage-BRwtqUSG.js} +1 -1
- package/dist/app/assets/{RouteError-Cymbp47a.js → RouteError-CBNNrnSD.js} +1 -1
- package/dist/app/assets/{ThemeEditorPage-C_nMnHr8.js → ThemeEditorPage-CTCeBneA.js} +1 -1
- package/dist/app/assets/{WorkbookPage-CPQu-DQx.js → WorkbookPage-SN6f1RBm.js} +1 -1
- package/dist/app/assets/{core-Coi3caGs.es-CSOmajHS.js → core-Dp3q5Ieu.es-CD5FvM2s.js} +1 -1
- package/dist/app/assets/{index-DlWCXghy.js → index-B3Nn8Vm2.js} +459 -446
- package/dist/app/assets/index-BLCx1EdC.js +18 -0
- package/dist/app/assets/{index-DxArlgRD.js → index-C_tJstcx.js} +4 -4
- package/dist/app/assets/{index-CcuuST2X.js → index-CfmBVB6M.js} +1 -1
- package/dist/app/assets/{index-CkmABCAw.js → index-DU4r7GdU.js} +435 -422
- package/dist/app/index.html +1 -1
- package/dist/package_load_worker.mjs +108 -7
- package/dist/server.mjs +576 -50
- package/package.json +12 -12
- package/scripts/bake-duckdb-extensions.js +5 -2
- package/src/config.ts +40 -0
- package/src/ducklake_version.spec.ts +163 -0
- package/src/ducklake_version.ts +153 -0
- package/src/errors.ts +12 -0
- package/src/malloy_pin_prereqs.spec.ts +25 -0
- package/src/mcp/skills/skills_bundle.json +1 -1
- package/src/server.ts +7 -0
- package/src/service/authorize.spec.ts +22 -0
- package/src/service/authorize.ts +267 -10
- package/src/service/authorize_integration.spec.ts +1068 -26
- package/src/service/connection.spec.ts +71 -0
- package/src/service/connection.ts +312 -25
- package/src/service/connection_config.spec.ts +21 -0
- package/src/service/connection_config.ts +15 -1
- package/src/service/ducklake_lazy_attach.spec.ts +110 -0
- package/src/service/environment.ts +43 -9
- package/src/service/environment_store.spec.ts +197 -12
- package/src/service/environment_store.ts +88 -14
- package/src/service/extension_fetch_policy.spec.ts +256 -0
- package/src/service/materialization_scheduler.spec.ts +29 -0
- package/src/service/materialization_service.spec.ts +119 -1
- package/src/service/model.spec.ts +67 -0
- package/src/service/model.ts +656 -31
- package/src/service/package.spec.ts +38 -0
- package/src/service/package.ts +12 -1
- package/src/storage/duckdb/MaterializationRepository.spec.ts +39 -2
- package/src/storage/duckdb/MaterializationRepository.ts +12 -0
- package/tests/integration/materialization/scheduler_transitions.integration.spec.ts +256 -0
- package/dist/app/assets/index-CM2qhQCI.js +0 -18
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloy-publisher/server",
|
|
3
3
|
"description": "Malloy Publisher Server",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.231",
|
|
5
5
|
"main": "dist/server.mjs",
|
|
6
6
|
"bin": {
|
|
7
7
|
"malloy-publisher": "dist/server.mjs"
|
|
@@ -36,17 +36,17 @@
|
|
|
36
36
|
"@azure/storage-blob": "^12.26.0",
|
|
37
37
|
"@duckdb/node-api": "1.5.3-r.2",
|
|
38
38
|
"@google-cloud/storage": "^7.16.0",
|
|
39
|
-
"@malloydata/db-bigquery": "^0.0.
|
|
40
|
-
"@malloydata/db-databricks": "^0.0.
|
|
41
|
-
"@malloydata/db-duckdb": "^0.0.
|
|
42
|
-
"@malloydata/db-mysql": "^0.0.
|
|
43
|
-
"@malloydata/db-postgres": "^0.0.
|
|
44
|
-
"@malloydata/db-publisher": "^0.0.
|
|
45
|
-
"@malloydata/db-snowflake": "^0.0.
|
|
46
|
-
"@malloydata/db-trino": "^0.0.
|
|
47
|
-
"@malloydata/malloy": "^0.0.
|
|
48
|
-
"@malloydata/malloy-sql": "^0.0.
|
|
49
|
-
"@malloydata/render-validator": "^0.0.
|
|
39
|
+
"@malloydata/db-bigquery": "^0.0.423",
|
|
40
|
+
"@malloydata/db-databricks": "^0.0.423",
|
|
41
|
+
"@malloydata/db-duckdb": "^0.0.423",
|
|
42
|
+
"@malloydata/db-mysql": "^0.0.423",
|
|
43
|
+
"@malloydata/db-postgres": "^0.0.423",
|
|
44
|
+
"@malloydata/db-publisher": "^0.0.423",
|
|
45
|
+
"@malloydata/db-snowflake": "^0.0.423",
|
|
46
|
+
"@malloydata/db-trino": "^0.0.423",
|
|
47
|
+
"@malloydata/malloy": "^0.0.423",
|
|
48
|
+
"@malloydata/malloy-sql": "^0.0.423",
|
|
49
|
+
"@malloydata/render-validator": "^0.0.423",
|
|
50
50
|
"@modelcontextprotocol/sdk": "^1.13.2",
|
|
51
51
|
"@opentelemetry/api": "^1.9.0",
|
|
52
52
|
"@opentelemetry/auto-instrumentations-node": "^0.57.0",
|
|
@@ -27,8 +27,11 @@ import { DuckDBInstance } from "@duckdb/node-api";
|
|
|
27
27
|
// sandbox, federated-database attach, and the materialization catalog. Keep this
|
|
28
28
|
// in sync with the install sites in those files.
|
|
29
29
|
//
|
|
30
|
-
// `community: true`
|
|
31
|
-
//
|
|
30
|
+
// `community: true` marks the community-repo extensions (bigquery, snowflake);
|
|
31
|
+
// the rest are core extensions installed by name. The bake deliberately uses
|
|
32
|
+
// `FORCE INSTALL ... FROM community` to (re)populate the build cache from the
|
|
33
|
+
// CDN at build time; the *runtime* install (connection.ts) uses a plain,
|
|
34
|
+
// local-first `INSTALL` that no-ops against this baked cache.
|
|
32
35
|
// `registered` is the name the extension reports in duckdb_extensions() when it
|
|
33
36
|
// differs from the INSTALL name (only postgres -> postgres_scanner).
|
|
34
37
|
const EXTENSIONS = [
|
package/src/config.ts
CHANGED
|
@@ -440,6 +440,46 @@ export const getMaxConcurrentQueries = (): number => {
|
|
|
440
440
|
return raw;
|
|
441
441
|
};
|
|
442
442
|
|
|
443
|
+
/**
|
|
444
|
+
* DuckDB extension-fetch policy. Governs whether Publisher's explicit extension
|
|
445
|
+
* INSTALL step (see `installAndLoadExtension` in service/connection.ts) may
|
|
446
|
+
* reach the DuckDB extension network.
|
|
447
|
+
*/
|
|
448
|
+
export type ExtensionFetchPolicy = "on-demand" | "local-only";
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Resolve the DuckDB extension-fetch policy from `EXTENSION_FETCH_POLICY`;
|
|
452
|
+
* falls back to `on-demand` when unset or empty.
|
|
453
|
+
*
|
|
454
|
+
* - `on-demand` (default): preserves prior behaviour. Publisher runs `INSTALL`
|
|
455
|
+
* for a missing extension on first use, which fetches it from the DuckDB
|
|
456
|
+
* extension network when it is not already present on disk (baked into the
|
|
457
|
+
* image). Extensions already baked are used as-is.
|
|
458
|
+
* - `local-only`: Publisher never runs `INSTALL`, and turns DuckDB's own
|
|
459
|
+
* implicit auto-install off on its build/serve sessions
|
|
460
|
+
* (`autoinstall_known_extensions=false`), so no code path reaches the
|
|
461
|
+
* network. Auto-LOAD stays on, so an extension already present on disk still
|
|
462
|
+
* lazy-loads; a genuinely missing extension surfaces as a loud, actionable
|
|
463
|
+
* error instead of a silent fetch. For air-gapped / pinned-image deployments.
|
|
464
|
+
*
|
|
465
|
+
* Throws on an unrecognised value. Validated at server startup (server.ts calls
|
|
466
|
+
* this during boot) so a typo in a k8s manifest fails the boot loudly rather
|
|
467
|
+
* than surfacing on the first query that resolves a DuckDB connection — which,
|
|
468
|
+
* for a DuckLake-only deployment, could be well after `serving`. Also read on
|
|
469
|
+
* each connection resolve, so the value is honoured without a restart.
|
|
470
|
+
*/
|
|
471
|
+
export const getExtensionFetchPolicy = (): ExtensionFetchPolicy => {
|
|
472
|
+
const raw = process.env.EXTENSION_FETCH_POLICY;
|
|
473
|
+
if (raw === undefined || raw.trim() === "") return "on-demand";
|
|
474
|
+
const normalised = raw.trim().toLowerCase();
|
|
475
|
+
if (normalised === "on-demand" || normalised === "local-only") {
|
|
476
|
+
return normalised;
|
|
477
|
+
}
|
|
478
|
+
throw new Error(
|
|
479
|
+
`Invalid value for EXTENSION_FETCH_POLICY: expected "on-demand" or "local-only", got "${raw}"`,
|
|
480
|
+
);
|
|
481
|
+
};
|
|
482
|
+
|
|
443
483
|
function substituteEnvVars(value: string): string {
|
|
444
484
|
const envVarPattern = /\$\{([A-Z_][A-Z0-9_]*)\}/g;
|
|
445
485
|
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import {
|
|
5
|
+
catalogFormatRangeForEngine,
|
|
6
|
+
compareCatalogFormat,
|
|
7
|
+
ENGINE_MAX_FORMAT,
|
|
8
|
+
isCatalogFormatInRange,
|
|
9
|
+
isCatalogFormatSupportedByEngine,
|
|
10
|
+
MIN_CATALOG_FORMAT,
|
|
11
|
+
parseCatalogFormat,
|
|
12
|
+
parseEngineMajorMinor,
|
|
13
|
+
} from "./ducklake_version";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolve the pinned `@duckdb/node-api` engine version from bun.lock, the same
|
|
17
|
+
* source `scripts/duckdb-version.js` reads (mirrored here rather than imported
|
|
18
|
+
* because the server tsconfig has `allowJs: false`). Prefers the version nested
|
|
19
|
+
* under `@malloydata/db-duckdb` — the engine Malloy actually runs on — and
|
|
20
|
+
* falls back to the deduped top-level entry.
|
|
21
|
+
*/
|
|
22
|
+
function resolvePinnedDuckDBVersion(): string {
|
|
23
|
+
const lock = readFileSync(
|
|
24
|
+
fileURLToPath(new URL("../../../bun.lock", import.meta.url)),
|
|
25
|
+
"utf8",
|
|
26
|
+
);
|
|
27
|
+
const nested = lock.match(
|
|
28
|
+
/"@malloydata\/db-duckdb\/@duckdb\/node-api":\s*\["@duckdb\/node-api@(\d+\.\d+\.\d+[^"]*)"/,
|
|
29
|
+
);
|
|
30
|
+
const plain = lock.match(
|
|
31
|
+
/"@duckdb\/node-api":\s*\["@duckdb\/node-api@(\d+\.\d+\.\d+[^"]*)"/,
|
|
32
|
+
);
|
|
33
|
+
const match = nested ?? plain;
|
|
34
|
+
if (!match) throw new Error("@duckdb/node-api not found in bun.lock");
|
|
35
|
+
return match[1];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe("ducklake_version", () => {
|
|
39
|
+
describe("parseCatalogFormat", () => {
|
|
40
|
+
it("parses two-part and pre-release formats", () => {
|
|
41
|
+
expect(parseCatalogFormat("1.0")).toEqual({ major: 1, minor: 0 });
|
|
42
|
+
expect(parseCatalogFormat("0.3-dev1")).toEqual({
|
|
43
|
+
major: 0,
|
|
44
|
+
minor: 3,
|
|
45
|
+
prerelease: "dev1",
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("rejects malformed input without throwing", () => {
|
|
50
|
+
// Three-part strings are malformed for a catalog format, not a newer
|
|
51
|
+
// version -- they must not parse as a bigger number.
|
|
52
|
+
expect(parseCatalogFormat("1.0.0")).toBeNull();
|
|
53
|
+
expect(parseCatalogFormat("1.1.0")).toBeNull();
|
|
54
|
+
expect(parseCatalogFormat("")).toBeNull();
|
|
55
|
+
expect(parseCatalogFormat("not a version")).toBeNull();
|
|
56
|
+
expect(parseCatalogFormat("0.3 ")).toBeNull();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("compareCatalogFormat", () => {
|
|
61
|
+
const p = (s: string) => parseCatalogFormat(s)!;
|
|
62
|
+
it("orders by major, then minor", () => {
|
|
63
|
+
expect(compareCatalogFormat(p("0.3"), p("1.0"))).toBe(-1);
|
|
64
|
+
expect(compareCatalogFormat(p("1.1"), p("1.0"))).toBe(1);
|
|
65
|
+
expect(compareCatalogFormat(p("1.0"), p("1.0"))).toBe(0);
|
|
66
|
+
});
|
|
67
|
+
it("sorts a release above its own pre-releases", () => {
|
|
68
|
+
expect(compareCatalogFormat(p("1.0"), p("1.0-dev1"))).toBe(1);
|
|
69
|
+
expect(compareCatalogFormat(p("0.3-dev1"), p("0.3"))).toBe(-1);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("parseEngineMajorMinor", () => {
|
|
74
|
+
it("extracts the minor line from assorted engine spec forms", () => {
|
|
75
|
+
expect(parseEngineMajorMinor("1.5.3")).toEqual({ major: 1, minor: 5 });
|
|
76
|
+
expect(parseEngineMajorMinor("1.5.3-r.2")).toEqual({
|
|
77
|
+
major: 1,
|
|
78
|
+
minor: 5,
|
|
79
|
+
});
|
|
80
|
+
expect(parseEngineMajorMinor("v1.5.3")).toEqual({
|
|
81
|
+
major: 1,
|
|
82
|
+
minor: 5,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
it("returns null when no version is present", () => {
|
|
86
|
+
expect(parseEngineMajorMinor("nope")).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("catalogFormatRangeForEngine", () => {
|
|
91
|
+
it("derives [1.0, maxFormat] for a covered engine (all patch levels)", () => {
|
|
92
|
+
expect(catalogFormatRangeForEngine("1.5.3")).toEqual({
|
|
93
|
+
min: "1.0",
|
|
94
|
+
max: "1.0",
|
|
95
|
+
engineVersion: "1.5",
|
|
96
|
+
});
|
|
97
|
+
// Any patch of a known minor line resolves to the same range.
|
|
98
|
+
expect(catalogFormatRangeForEngine("1.5.9")).toEqual({
|
|
99
|
+
min: "1.0",
|
|
100
|
+
max: "1.0",
|
|
101
|
+
engineVersion: "1.5",
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
it("returns null (drift signal) for an engine with no matrix row", () => {
|
|
105
|
+
expect(catalogFormatRangeForEngine("1.6.0")).toBeNull();
|
|
106
|
+
expect(catalogFormatRangeForEngine("2.0.0")).toBeNull();
|
|
107
|
+
expect(catalogFormatRangeForEngine("garbage")).toBeNull();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// These reproduce the accept/reject set the prior enumerated-list work
|
|
112
|
+
// asserted, now expressed as a RANGE derived from the 1.5.x engine.
|
|
113
|
+
describe("isCatalogFormatSupportedByEngine (engine 1.5.x)", () => {
|
|
114
|
+
const engine = "1.5.3";
|
|
115
|
+
it("accepts the 1.0 catalog format produced by the 1.5.x engine", () => {
|
|
116
|
+
expect(isCatalogFormatSupportedByEngine("1.0", engine)).toBe(true);
|
|
117
|
+
});
|
|
118
|
+
it("rejects the 0.3-line formats (attach only via migration)", () => {
|
|
119
|
+
for (const v of ["0.1", "0.2", "0.3-dev1", "0.3"]) {
|
|
120
|
+
expect(isCatalogFormatSupportedByEngine(v, engine)).toBe(false);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
it("rejects formats newer than the supported max", () => {
|
|
124
|
+
for (const v of ["1.1", "2.0", "0.4", "0.3-dev2"]) {
|
|
125
|
+
expect(isCatalogFormatSupportedByEngine(v, engine)).toBe(false);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
it("rejects malformed / three-part input without throwing", () => {
|
|
129
|
+
for (const v of ["1.0.0", "1.1.0", "", "not a version", "0.3 "]) {
|
|
130
|
+
expect(isCatalogFormatSupportedByEngine(v, engine)).toBe(false);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
it("rejects everything when the engine is unknown (no matrix row)", () => {
|
|
134
|
+
expect(isCatalogFormatSupportedByEngine("1.0", "1.6.0")).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("isCatalogFormatInRange", () => {
|
|
139
|
+
const range = catalogFormatRangeForEngine("1.5.3")!;
|
|
140
|
+
it("is inclusive at both ends", () => {
|
|
141
|
+
expect(isCatalogFormatInRange("1.0", range)).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
it("rejects below min and above max", () => {
|
|
144
|
+
expect(isCatalogFormatInRange("0.9", range)).toBe(false);
|
|
145
|
+
expect(isCatalogFormatInRange("1.1", range)).toBe(false);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// The version-contract: the ENGINE_MAX_FORMAT matrix MUST cover the DuckDB
|
|
150
|
+
// engine this repo is pinned to. This is the same drift guard the CI script
|
|
151
|
+
// enforces (scripts/validate-ducklake-catalog-range.ts); asserting it here
|
|
152
|
+
// fails `bun test` the moment a Malloy bump moves the engine past the matrix.
|
|
153
|
+
describe("pinned-engine drift contract", () => {
|
|
154
|
+
it("has a matrix row covering the pinned @duckdb/node-api engine", () => {
|
|
155
|
+
const engineVersion = resolvePinnedDuckDBVersion();
|
|
156
|
+
const range = catalogFormatRangeForEngine(engineVersion);
|
|
157
|
+
expect(range).not.toBeNull();
|
|
158
|
+
expect(range!.min).toBe(MIN_CATALOG_FORMAT);
|
|
159
|
+
// The matrix must not be empty and its rows must be well-formed.
|
|
160
|
+
expect(ENGINE_MAX_FORMAT.length).toBeGreaterThan(0);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// DuckLake catalog-format version contract.
|
|
2
|
+
//
|
|
3
|
+
// A DuckLake catalog records the on-disk format version it was written at. The
|
|
4
|
+
// DuckLake extension bundled with a given DuckDB engine attaches only a bounded
|
|
5
|
+
// RANGE of catalog formats without migration; a catalog outside that range
|
|
6
|
+
// fails deep inside DuckDB with an opaque error. This module derives the
|
|
7
|
+
// supported range purely from the pinned DuckDB engine version, so it never has
|
|
8
|
+
// to enumerate an allow-list of "known good" catalog versions (which drifts
|
|
9
|
+
// silently on an engine bump and is easy to forget to update). Both the runtime
|
|
10
|
+
// attach preflight (`service/connection.ts`) and the CI version-contract check
|
|
11
|
+
// (`scripts/validate-ducklake-catalog-range.ts`) consume this one source.
|
|
12
|
+
//
|
|
13
|
+
// Lower bound: fixed at "1.0". The 1.x DuckLake line does not attach the older
|
|
14
|
+
// 0.x formats without AUTOMATIC_MIGRATION, and the Publisher attach paths never
|
|
15
|
+
// pass that flag, so 1.0 is the floor. Upper bound: the maximum format the
|
|
16
|
+
// engine's bundled extension writes/attaches, looked up in the migration matrix
|
|
17
|
+
// below and keyed by engine (major, minor).
|
|
18
|
+
|
|
19
|
+
/** A parsed DuckLake catalog format version, e.g. `1.0` or `0.3-dev1`. */
|
|
20
|
+
export interface CatalogFormat {
|
|
21
|
+
major: number;
|
|
22
|
+
minor: number;
|
|
23
|
+
/** e.g. `dev1` in `0.3-dev1`; a pre-release sorts BELOW the same release. */
|
|
24
|
+
prerelease?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The inclusive `[min, max]` catalog-format range for a given engine. */
|
|
28
|
+
export interface CatalogFormatRange {
|
|
29
|
+
min: string;
|
|
30
|
+
max: string;
|
|
31
|
+
/** The engine minor line the range was derived from (for error messages). */
|
|
32
|
+
engineVersion: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Fixed lower bound of the supported range (see file header). */
|
|
36
|
+
export const MIN_CATALOG_FORMAT = "1.0";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Migration matrix: DuckDB engine minor line -> the maximum DuckLake catalog
|
|
40
|
+
* format its bundled DuckLake extension attaches WITHOUT migration. This is NOT
|
|
41
|
+
* an allow-list of catalog versions -- it is the single fact, per engine minor
|
|
42
|
+
* line, from which the `[MIN_CATALOG_FORMAT, maxFormat]` range is derived.
|
|
43
|
+
*
|
|
44
|
+
* Verified against the baked extension: DuckDB 1.5.x's DuckLake extension writes
|
|
45
|
+
* and attaches the "1.0" catalog format (the older 0.x formats require
|
|
46
|
+
* AUTOMATIC_MIGRATION, which Publisher never passes). When a Malloy bump moves
|
|
47
|
+
* `@duckdb/node-api` to a new minor line, add its row here after verifying the
|
|
48
|
+
* extension's max attach-without-migration format -- the CI version-contract
|
|
49
|
+
* check FAILS THE BUILD until a row covers the pinned engine, so this never
|
|
50
|
+
* drifts silently.
|
|
51
|
+
*/
|
|
52
|
+
export const ENGINE_MAX_FORMAT: ReadonlyArray<{
|
|
53
|
+
engine: { major: number; minor: number };
|
|
54
|
+
maxFormat: string;
|
|
55
|
+
}> = [{ engine: { major: 1, minor: 5 }, maxFormat: "1.0" }];
|
|
56
|
+
|
|
57
|
+
const CATALOG_FORMAT_RE = /^(\d+)\.(\d+)(?:-([0-9A-Za-z.]+))?$/;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Parse a catalog format string into its components, or `null` if it is not a
|
|
61
|
+
* valid `<major>.<minor>[-<prerelease>]` format. A three-part version like
|
|
62
|
+
* `1.0.0` is intentionally rejected: catalog formats are two-part, and a
|
|
63
|
+
* three-part string is a malformed input, not a newer format.
|
|
64
|
+
*/
|
|
65
|
+
export function parseCatalogFormat(raw: string): CatalogFormat | null {
|
|
66
|
+
if (typeof raw !== "string") return null;
|
|
67
|
+
const m = CATALOG_FORMAT_RE.exec(raw);
|
|
68
|
+
if (!m) return null;
|
|
69
|
+
const format: CatalogFormat = { major: Number(m[1]), minor: Number(m[2]) };
|
|
70
|
+
if (m[3] !== undefined) format.prerelease = m[3];
|
|
71
|
+
return format;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Compare two parsed catalog formats: -1 if `a < b`, 0 if equal, 1 if `a > b`.
|
|
76
|
+
* A release sorts ABOVE its own pre-releases (`1.0` > `1.0-dev1`), matching
|
|
77
|
+
* semver ordering.
|
|
78
|
+
*/
|
|
79
|
+
export function compareCatalogFormat(
|
|
80
|
+
a: CatalogFormat,
|
|
81
|
+
b: CatalogFormat,
|
|
82
|
+
): number {
|
|
83
|
+
if (a.major !== b.major) return a.major < b.major ? -1 : 1;
|
|
84
|
+
if (a.minor !== b.minor) return a.minor < b.minor ? -1 : 1;
|
|
85
|
+
if (a.prerelease === b.prerelease) return 0;
|
|
86
|
+
if (a.prerelease === undefined) return 1; // release > pre-release
|
|
87
|
+
if (b.prerelease === undefined) return -1;
|
|
88
|
+
return a.prerelease < b.prerelease ? -1 : 1;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Extract the `{ major, minor }` line from a DuckDB engine version string
|
|
93
|
+
* (`1.5.3`, `1.5.3-r.2`, `v1.5.3` all parse to `{1, 5}`), or `null` if none is
|
|
94
|
+
* present.
|
|
95
|
+
*/
|
|
96
|
+
export function parseEngineMajorMinor(
|
|
97
|
+
raw: string,
|
|
98
|
+
): { major: number; minor: number } | null {
|
|
99
|
+
const m = /(\d+)\.(\d+)\.(\d+)/.exec(String(raw));
|
|
100
|
+
if (!m) return null;
|
|
101
|
+
return { major: Number(m[1]), minor: Number(m[2]) };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The supported catalog-format range for a DuckDB engine version, or `null`
|
|
106
|
+
* when the engine's minor line has no row in {@link ENGINE_MAX_FORMAT}. A
|
|
107
|
+
* `null` return is the DRIFT signal: the CI version-contract check fails the
|
|
108
|
+
* build on it, and the runtime preflight treats it as "unknown, skip" (the
|
|
109
|
+
* preflight is non-load-bearing). The match is by `(major, minor)` so any patch
|
|
110
|
+
* release of a known minor line resolves.
|
|
111
|
+
*/
|
|
112
|
+
export function catalogFormatRangeForEngine(
|
|
113
|
+
engineVersion: string,
|
|
114
|
+
): CatalogFormatRange | null {
|
|
115
|
+
const e = parseEngineMajorMinor(engineVersion);
|
|
116
|
+
if (!e) return null;
|
|
117
|
+
const entry = ENGINE_MAX_FORMAT.find(
|
|
118
|
+
(r) => r.engine.major === e.major && r.engine.minor === e.minor,
|
|
119
|
+
);
|
|
120
|
+
if (!entry) return null;
|
|
121
|
+
return {
|
|
122
|
+
min: MIN_CATALOG_FORMAT,
|
|
123
|
+
max: entry.maxFormat,
|
|
124
|
+
engineVersion: `${e.major}.${e.minor}`,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Whether `format` falls within the inclusive range (invalid input -> false). */
|
|
129
|
+
export function isCatalogFormatInRange(
|
|
130
|
+
format: string,
|
|
131
|
+
range: CatalogFormatRange,
|
|
132
|
+
): boolean {
|
|
133
|
+
const f = parseCatalogFormat(format);
|
|
134
|
+
const min = parseCatalogFormat(range.min);
|
|
135
|
+
const max = parseCatalogFormat(range.max);
|
|
136
|
+
if (!f || !min || !max) return false;
|
|
137
|
+
return (
|
|
138
|
+
compareCatalogFormat(f, min) >= 0 && compareCatalogFormat(f, max) <= 0
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Whether a catalog `format` is supported by the DuckLake extension bundled
|
|
144
|
+
* with `engineVersion`. Returns `false` for an unknown engine (no matrix row)
|
|
145
|
+
* or a malformed format.
|
|
146
|
+
*/
|
|
147
|
+
export function isCatalogFormatSupportedByEngine(
|
|
148
|
+
format: string,
|
|
149
|
+
engineVersion: string,
|
|
150
|
+
): boolean {
|
|
151
|
+
const range = catalogFormatRangeForEngine(engineVersion);
|
|
152
|
+
return range ? isCatalogFormatInRange(format, range) : false;
|
|
153
|
+
}
|
package/src/errors.ts
CHANGED
|
@@ -22,6 +22,8 @@ export function internalErrorToHttpError(error: Error) {
|
|
|
22
22
|
return httpError(404, error.message);
|
|
23
23
|
} else if (error instanceof ConnectionAuthError) {
|
|
24
24
|
return httpError(422, error.message);
|
|
25
|
+
} else if (error instanceof UnsupportedCatalogFormatError) {
|
|
26
|
+
return httpError(422, error.message);
|
|
25
27
|
} else if (error instanceof ModelCompilationError) {
|
|
26
28
|
return httpError(424, error.message);
|
|
27
29
|
} else if (error instanceof ConnectionError) {
|
|
@@ -101,6 +103,16 @@ export class ConnectionAuthError extends Error {
|
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
105
|
|
|
106
|
+
// A catalog was reached and authenticated fine, but its on-disk format is
|
|
107
|
+
// outside the range the pinned engine's extension can attach (see
|
|
108
|
+
// ducklake_version.ts). Distinct from ConnectionAuthError so the 422 doesn't
|
|
109
|
+
// read as a credentials problem. Maps to HTTP 422.
|
|
110
|
+
export class UnsupportedCatalogFormatError extends Error {
|
|
111
|
+
constructor(message: string) {
|
|
112
|
+
super(message);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
104
116
|
export class ModelCompilationError extends Error {
|
|
105
117
|
// Accepts a MalloyError or any message-bearing object, so callers that add
|
|
106
118
|
// context around a compile failure (e.g. naming the source whose authorize
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import type { VirtualMap } from "@malloydata/malloy";
|
|
3
|
+
|
|
4
|
+
// Prerequisite guard for the DuckLake materialization tier's build path.
|
|
5
|
+
//
|
|
6
|
+
// The tier resolves persist/virtual sources by handing the Malloy compile a
|
|
7
|
+
// `virtualMap` (connectionName → virtualName → tablePath). This asserts the
|
|
8
|
+
// pinned `@malloydata/malloy` still exports that public `VirtualMap` type, so a
|
|
9
|
+
// pin bump that drops or renames it fails CI typecheck here — turning a
|
|
10
|
+
// point-in-time manual confirm into a durable guard. Confirmed present in the
|
|
11
|
+
// shipped pin (^0.0.422): `VirtualMap = Map<string, Map<string, string>>` is
|
|
12
|
+
// exported from the package root and rides `PrepareResultOptions.virtualMap`.
|
|
13
|
+
describe("malloy pin prerequisites (DuckLake tier)", () => {
|
|
14
|
+
it("exposes the VirtualMap substitution type in the pinned malloy", () => {
|
|
15
|
+
// Compile-time guard: this type reference fails typecheck if `VirtualMap`
|
|
16
|
+
// is removed/renamed in a future pin. The runtime assertions below double
|
|
17
|
+
// as a shape check on the nested Map<string, Map<string, string>>.
|
|
18
|
+
const virtualMap: VirtualMap = new Map([
|
|
19
|
+
["main_pg", new Map([["orders", "catalog.public.orders"]])],
|
|
20
|
+
]);
|
|
21
|
+
expect(virtualMap.get("main_pg")?.get("orders")).toBe(
|
|
22
|
+
"catalog.public.orders",
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
});
|