@malloy-publisher/server 0.0.232 → 0.0.234
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/README.docker.md +1 -0
- package/dist/app/api-doc.yaml +269 -10
- package/dist/app/assets/{EnvironmentPage-DXEaZIPx.js → EnvironmentPage-DTZQ4Gxc.js} +1 -1
- package/dist/app/assets/{HomePage-kofsqpZt.js → HomePage-C5mlDPXK.js} +1 -1
- package/dist/app/assets/{LightMode-CNhIlIlJ.js → LightMode-DGNmhG0u.js} +1 -1
- package/dist/app/assets/{MainPage-Bgqo8jCy.js → MainPage-CVL_wmP4.js} +1 -1
- package/dist/app/assets/{MaterializationsPage-CgBlgGz2.js → MaterializationsPage-DmzMBCpy.js} +1 -1
- package/dist/app/assets/{ModelPage-B0TjoDtf.js → ModelPage-Dbvf4QbB.js} +1 -1
- package/dist/app/assets/{PackagePage-BL8vnFj1.js → PackagePage-DxdHc2Qs.js} +1 -1
- package/dist/app/assets/{RouteError-BzPby0X2.js → RouteError-OJdT4tCd.js} +1 -1
- package/dist/app/assets/{ThemeEditorPage-CTEP_9r3.js → ThemeEditorPage-Bk7s0KXY.js} +1 -1
- package/dist/app/assets/{WorkbookPage-BwM3BmKw.js → WorkbookPage-j_vCWdN3.js} +1 -1
- package/dist/app/assets/{core-CK68iv6w.es-CpRxXBt7.js → core-Rj_4rRnA.es-DoIfLxDJ.js} +1 -1
- package/dist/app/assets/{index-B33zGctF.js → index-B_jKMR35.js} +4 -4
- package/dist/app/assets/{index-CmkW1MiE.js → index-D-rDyK11.js} +1 -1
- package/dist/app/assets/{index-tXJXwdyj.js → index-DWIe_hK0.js} +1 -1
- package/dist/app/assets/{index-BkiWKaAF.js → index-hw-xn0X7.js} +1 -1
- package/dist/app/index.html +1 -1
- package/dist/package_load_worker.mjs +53 -3
- package/dist/server.mjs +20277 -925
- package/package.json +1 -1
- package/src/config.ts +35 -1
- package/src/controller/connection.controller.spec.ts +46 -0
- package/src/controller/connection.controller.ts +105 -2
- package/src/controller/materialization.controller.spec.ts +25 -0
- package/src/controller/materialization.controller.ts +60 -0
- package/src/controller/model.controller.ts +24 -0
- package/src/controller/query.controller.ts +83 -10
- package/src/json_utils.spec.ts +51 -0
- package/src/json_utils.ts +33 -0
- package/src/mcp/handler_utils.ts +10 -2
- package/src/mcp/query_envelope.spec.ts +229 -0
- package/src/mcp/query_envelope.ts +240 -0
- package/src/mcp/server.protocol.spec.ts +128 -16
- package/src/mcp/skills/build_skills_bundle.ts +94 -4
- package/src/mcp/skills/skills_bundle.json +1 -1
- package/src/mcp/skills/skills_bundle.spec.ts +113 -4
- package/src/mcp/tool_response.spec.ts +108 -0
- package/src/mcp/tool_response.ts +138 -0
- package/src/mcp/tools/compile_tool.spec.ts +112 -4
- package/src/mcp/tools/compile_tool.ts +61 -30
- package/src/mcp/tools/docs_search_tool.ts +6 -16
- package/src/mcp/tools/execute_query_tool.spec.ts +154 -3
- package/src/mcp/tools/execute_query_tool.ts +131 -155
- package/src/mcp/tools/get_context_tool.spec.ts +63 -3
- package/src/mcp/tools/get_context_tool.ts +43 -46
- package/src/mcp/tools/reload_package_tool.ts +3 -29
- package/src/mcp_config.spec.ts +919 -0
- package/src/mcp_config.ts +425 -0
- package/src/oom_guards.integration.spec.ts +11 -3
- package/src/package_load/package_load_pool.ts +2 -0
- package/src/package_load/package_load_worker.ts +17 -5
- package/src/package_load/protocol.ts +6 -0
- package/src/query_metadata_metrics.ts +49 -0
- package/src/server.ts +99 -3
- package/src/service/build_plan.spec.ts +125 -0
- package/src/service/build_plan.ts +108 -7
- package/src/service/compile_fragment_techniques.spec.ts +156 -0
- package/src/service/connection.spec.ts +371 -1
- package/src/service/connection.ts +77 -14
- package/src/service/connection_config.spec.ts +60 -0
- package/src/service/connection_config.ts +75 -0
- package/src/service/duckdb_instance_isolation.spec.ts +137 -0
- package/src/service/environment.ts +57 -3
- package/src/service/materialization_config_validation.spec.ts +99 -0
- package/src/service/materialization_config_validation.ts +120 -0
- package/src/service/materialization_schedule_surface.spec.ts +124 -0
- package/src/service/materialization_service.spec.ts +119 -0
- package/src/service/materialization_service.ts +186 -3
- package/src/service/materialization_test_fixtures.ts +86 -21
- package/src/service/model.spec.ts +45 -1
- package/src/service/model.ts +171 -23
- package/src/service/model_limits.spec.ts +28 -0
- package/src/service/model_limits.ts +21 -0
- package/src/service/package.ts +24 -1
- package/src/service/package_manifest.spec.ts +137 -4
- package/src/service/package_manifest.ts +140 -5
- package/src/service/persist_annotation_validation.spec.ts +12 -0
- package/src/service/persist_annotation_validation.ts +9 -4
- package/src/service/query_metadata.spec.ts +408 -0
- package/src/service/query_metadata.ts +492 -0
- package/src/service/query_metadata_identity.spec.ts +149 -0
- package/tests/integration/mcp/mcp_execute_query_tool.integration.spec.ts +37 -12
|
@@ -1,10 +1,63 @@
|
|
|
1
1
|
import { describe, expect, it } from "bun:test";
|
|
2
2
|
import {
|
|
3
|
+
packageMaterializationWarnings,
|
|
3
4
|
parsePackageMaterialization,
|
|
4
5
|
parsePackageScope,
|
|
6
|
+
resolvePackageScope,
|
|
5
7
|
} from "./package_manifest";
|
|
6
8
|
|
|
7
9
|
describe("service/package_manifest", () => {
|
|
10
|
+
describe("resolvePackageScope", () => {
|
|
11
|
+
it("reads the canonical materialization.scope with no warning", () => {
|
|
12
|
+
expect(resolvePackageScope(undefined, { scope: "version" })).toEqual({
|
|
13
|
+
scope: "version",
|
|
14
|
+
warnings: [],
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("defaults to 'package' when neither home declares it", () => {
|
|
19
|
+
expect(resolvePackageScope(undefined, undefined)).toEqual({
|
|
20
|
+
scope: "package",
|
|
21
|
+
warnings: [],
|
|
22
|
+
});
|
|
23
|
+
expect(resolvePackageScope(undefined, { freshness: {} })).toEqual({
|
|
24
|
+
scope: "package",
|
|
25
|
+
warnings: [],
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("still honors a root scope, with a deprecation warning", () => {
|
|
30
|
+
const resolved = resolvePackageScope("version", undefined);
|
|
31
|
+
expect(resolved.scope).toBe("version");
|
|
32
|
+
expect(resolved.warnings).toHaveLength(1);
|
|
33
|
+
expect(resolved.warnings[0]).toMatch(/deprecated/i);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("accepts both homes agreeing without a warning", () => {
|
|
37
|
+
// The transition state the server writes: envelope for this build, root
|
|
38
|
+
// for an older publisher. Warning would blame the operator for it.
|
|
39
|
+
expect(resolvePackageScope("version", { scope: "version" })).toEqual({
|
|
40
|
+
scope: "version",
|
|
41
|
+
warnings: [],
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("throws when the two homes disagree rather than guessing", () => {
|
|
46
|
+
expect(() =>
|
|
47
|
+
resolvePackageScope("package", { scope: "version" }),
|
|
48
|
+
).toThrow(/conflicting/i);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("reports an invalid value as invalid, not as a conflict", () => {
|
|
52
|
+
expect(() =>
|
|
53
|
+
resolvePackageScope(undefined, { scope: "shared" }),
|
|
54
|
+
).toThrow(/expected "version" or "package"/i);
|
|
55
|
+
expect(() =>
|
|
56
|
+
resolvePackageScope("shared", { scope: "version" }),
|
|
57
|
+
).toThrow(/expected "version" or "package"/i);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
8
61
|
describe("parsePackageScope", () => {
|
|
9
62
|
it("defaults to 'package' when absent", () => {
|
|
10
63
|
expect(parsePackageScope(undefined)).toBe("package");
|
|
@@ -26,7 +79,7 @@ describe("service/package_manifest", () => {
|
|
|
26
79
|
describe("parsePackageMaterialization", () => {
|
|
27
80
|
it("extracts a string schedule", () => {
|
|
28
81
|
expect(parsePackageMaterialization({ schedule: "0 6 * * *" })).toEqual(
|
|
29
|
-
{ schedule: "0 6 * * *", freshness: null },
|
|
82
|
+
{ schedule: "0 6 * * *", freshness: null, queryMetadata: null },
|
|
30
83
|
);
|
|
31
84
|
});
|
|
32
85
|
|
|
@@ -41,17 +94,23 @@ describe("service/package_manifest", () => {
|
|
|
41
94
|
schedule: "*/15 * * * *",
|
|
42
95
|
retries: 3,
|
|
43
96
|
}),
|
|
44
|
-
).toEqual({
|
|
97
|
+
).toEqual({
|
|
98
|
+
schedule: "*/15 * * * *",
|
|
99
|
+
freshness: null,
|
|
100
|
+
queryMetadata: null,
|
|
101
|
+
});
|
|
45
102
|
});
|
|
46
103
|
|
|
47
104
|
it("degrades a non-string schedule to null", () => {
|
|
48
105
|
expect(parsePackageMaterialization({ schedule: 42 })).toEqual({
|
|
49
106
|
schedule: null,
|
|
50
107
|
freshness: null,
|
|
108
|
+
queryMetadata: null,
|
|
51
109
|
});
|
|
52
110
|
expect(parsePackageMaterialization({})).toEqual({
|
|
53
111
|
schedule: null,
|
|
54
112
|
freshness: null,
|
|
113
|
+
queryMetadata: null,
|
|
55
114
|
});
|
|
56
115
|
});
|
|
57
116
|
|
|
@@ -68,13 +127,18 @@ describe("service/package_manifest", () => {
|
|
|
68
127
|
).toEqual({
|
|
69
128
|
schedule: null,
|
|
70
129
|
freshness: { window: "24h", fallback: "stale_ok" },
|
|
130
|
+
queryMetadata: null,
|
|
71
131
|
});
|
|
72
132
|
});
|
|
73
133
|
|
|
74
134
|
it("keeps a partial freshness block (window only)", () => {
|
|
75
135
|
expect(
|
|
76
136
|
parsePackageMaterialization({ freshness: { window: "1h" } }),
|
|
77
|
-
).toEqual({
|
|
137
|
+
).toEqual({
|
|
138
|
+
schedule: null,
|
|
139
|
+
freshness: { window: "1h" },
|
|
140
|
+
queryMetadata: null,
|
|
141
|
+
});
|
|
78
142
|
});
|
|
79
143
|
|
|
80
144
|
it("drops invalid freshness fields rather than defaulting them", () => {
|
|
@@ -84,14 +148,83 @@ describe("service/package_manifest", () => {
|
|
|
84
148
|
parsePackageMaterialization({
|
|
85
149
|
freshness: { window: 24, fallback: "retry" },
|
|
86
150
|
}),
|
|
87
|
-
).toEqual({ schedule: null, freshness: {} });
|
|
151
|
+
).toEqual({ schedule: null, freshness: {}, queryMetadata: null });
|
|
88
152
|
});
|
|
89
153
|
|
|
90
154
|
it("degrades a non-object freshness to null", () => {
|
|
91
155
|
expect(parsePackageMaterialization({ freshness: "24h" })).toEqual({
|
|
92
156
|
schedule: null,
|
|
93
157
|
freshness: null,
|
|
158
|
+
queryMetadata: null,
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("keeps queryMetadata properties verbatim", () => {
|
|
163
|
+
expect(
|
|
164
|
+
parsePackageMaterialization({
|
|
165
|
+
queryMetadata: { team: "finance", workload: "marts" },
|
|
166
|
+
}),
|
|
167
|
+
).toEqual({
|
|
168
|
+
schedule: null,
|
|
169
|
+
freshness: null,
|
|
170
|
+
queryMetadata: { team: "finance", workload: "marts" },
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("keeps a contract-violating property so publish can report it", () => {
|
|
175
|
+
// Filtering here would make the author's typo disappear with nothing
|
|
176
|
+
// to point at; the validator warns and the runtime clamps instead.
|
|
177
|
+
expect(
|
|
178
|
+
parsePackageMaterialization({
|
|
179
|
+
queryMetadata: { "team.name": "finance" },
|
|
180
|
+
}),
|
|
181
|
+
).toEqual({
|
|
182
|
+
schedule: null,
|
|
183
|
+
freshness: null,
|
|
184
|
+
queryMetadata: { "team.name": "finance" },
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("drops non-string values and empties to null", () => {
|
|
189
|
+
expect(
|
|
190
|
+
parsePackageMaterialization({
|
|
191
|
+
queryMetadata: { team: "finance", retries: 3 },
|
|
192
|
+
}),
|
|
193
|
+
).toEqual({
|
|
194
|
+
schedule: null,
|
|
195
|
+
freshness: null,
|
|
196
|
+
queryMetadata: { team: "finance" },
|
|
94
197
|
});
|
|
198
|
+
expect(
|
|
199
|
+
parsePackageMaterialization({ queryMetadata: { retries: 3 } }),
|
|
200
|
+
).toEqual({ schedule: null, freshness: null, queryMetadata: null });
|
|
201
|
+
expect(
|
|
202
|
+
parsePackageMaterialization({ queryMetadata: "team=finance" }),
|
|
203
|
+
).toEqual({ schedule: null, freshness: null, queryMetadata: null });
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe("packageMaterializationWarnings", () => {
|
|
208
|
+
it("names a dropped non-string value", () => {
|
|
209
|
+
// The drop happens before the config validation that would otherwise
|
|
210
|
+
// report it, so without this an unquoted `"team": 123` — a plausible
|
|
211
|
+
// hand-edit — vanishes with nothing anywhere to point at.
|
|
212
|
+
const warnings = packageMaterializationWarnings({
|
|
213
|
+
queryMetadata: { team: "finance", retries: 3 },
|
|
214
|
+
});
|
|
215
|
+
expect(warnings).toHaveLength(1);
|
|
216
|
+
expect(warnings[0]).toContain("'retries'");
|
|
217
|
+
expect(warnings[0]).toContain("got number");
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("says nothing about a block that parses cleanly", () => {
|
|
221
|
+
expect(
|
|
222
|
+
packageMaterializationWarnings({
|
|
223
|
+
schedule: "0 6 * * *",
|
|
224
|
+
queryMetadata: { team: "finance" },
|
|
225
|
+
}),
|
|
226
|
+
).toEqual([]);
|
|
227
|
+
expect(packageMaterializationWarnings(undefined)).toEqual([]);
|
|
95
228
|
});
|
|
96
229
|
});
|
|
97
230
|
});
|
|
@@ -18,10 +18,10 @@ export const PACKAGE_SCOPES = ["version", "package"] as const;
|
|
|
18
18
|
export type PackageScope = (typeof PACKAGE_SCOPES)[number];
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Read
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
21
|
+
* Read a `scope` value, defaulting to `"package"` when absent or null. Any other
|
|
22
|
+
* value is a manifest error: scope is load-bearing (it decides version-owned vs
|
|
23
|
+
* cross-version reuse), so a typo must fail loudly rather than silently pick a
|
|
24
|
+
* default. Throws on an invalid value.
|
|
25
25
|
*/
|
|
26
26
|
export function parsePackageScope(raw: unknown): PackageScope {
|
|
27
27
|
if (raw === undefined || raw === null) {
|
|
@@ -36,6 +36,69 @@ export function parsePackageScope(raw: unknown): PackageScope {
|
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Resolve the package's scope from its two possible homes: `materialization.scope`
|
|
41
|
+
* (canonical — every other build-behavioral knob lives in that block) and the
|
|
42
|
+
* manifest root (the original home, deprecated).
|
|
43
|
+
*
|
|
44
|
+
* The root form keeps working because scope rides the published artifact: a
|
|
45
|
+
* package published before the move must keep parsing until it is republished.
|
|
46
|
+
* Declaring DIFFERENT values in the two homes throws, because scope decides
|
|
47
|
+
* whether an artifact is version-owned and guessing which one the author meant
|
|
48
|
+
* could reuse a table across versions that was never supposed to be shared.
|
|
49
|
+
*
|
|
50
|
+
* Only a root-ONLY declaration is deprecated. Both homes agreeing is the
|
|
51
|
+
* transition state the server itself writes (see `writePackageManifest`): the
|
|
52
|
+
* envelope for this build, the root for an older publisher that would otherwise
|
|
53
|
+
* silently default to `package`. Warning about that would be warning an operator
|
|
54
|
+
* about something the server did on their behalf and they cannot fix.
|
|
55
|
+
*/
|
|
56
|
+
export function resolvePackageScope(
|
|
57
|
+
rootRaw: unknown,
|
|
58
|
+
materializationRaw: unknown,
|
|
59
|
+
): { scope: PackageScope; warnings: string[] } {
|
|
60
|
+
const envelopeRaw =
|
|
61
|
+
materializationRaw && typeof materializationRaw === "object"
|
|
62
|
+
? (materializationRaw as { scope?: unknown }).scope
|
|
63
|
+
: undefined;
|
|
64
|
+
const rootDeclared = rootRaw !== undefined && rootRaw !== null;
|
|
65
|
+
const envelopeDeclared = envelopeRaw !== undefined && envelopeRaw !== null;
|
|
66
|
+
|
|
67
|
+
// Validate both homes before comparing, so a typo is reported as a typo
|
|
68
|
+
// rather than as a conflict.
|
|
69
|
+
const rootScope = parsePackageScope(rootRaw);
|
|
70
|
+
const envelopeScope = parsePackageScope(envelopeRaw);
|
|
71
|
+
|
|
72
|
+
if (rootDeclared && envelopeDeclared) {
|
|
73
|
+
if (rootScope !== envelopeScope) {
|
|
74
|
+
// Names the fix, because this throw fails the package LOAD: the
|
|
75
|
+
// package is skipped and its only trace is /status loadErrors, so the
|
|
76
|
+
// message is the whole diagnosis. Guessing instead would be worse —
|
|
77
|
+
// picking the wrong one reuses a table across versions that was never
|
|
78
|
+
// meant to be shared, silently.
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Conflicting "scope" in publisher.json: root "${rootScope}" vs ` +
|
|
81
|
+
`"materialization.scope" "${envelopeScope}". The package cannot ` +
|
|
82
|
+
`load until they agree. Edit "materialization": { "scope": ... } ` +
|
|
83
|
+
`to the value you want and delete the root-level "scope" (the ` +
|
|
84
|
+
`server rewrites both homes on its next manifest write).`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return { scope: envelopeScope, warnings: [] };
|
|
88
|
+
}
|
|
89
|
+
if (rootDeclared) {
|
|
90
|
+
return { scope: rootScope, warnings: [SCOPE_ROOT_DEPRECATION] };
|
|
91
|
+
}
|
|
92
|
+
return { scope: envelopeScope, warnings: [] };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const SCOPE_ROOT_DEPRECATION =
|
|
96
|
+
`"scope" at the manifest root is deprecated: declare it as ` +
|
|
97
|
+
`"materialization": { "scope": ... } alongside the other build knobs. The ` +
|
|
98
|
+
`root form still works and will be removed in a future release; until then ` +
|
|
99
|
+
`the server keeps both homes in sync when it writes the manifest, so an ` +
|
|
100
|
+
`older publisher still reads the right value.`;
|
|
101
|
+
|
|
39
102
|
/**
|
|
40
103
|
* The manifest's `materialization.freshness` block, surfaced verbatim for the
|
|
41
104
|
* control plane (which owns the scheduling and query-time gating logic).
|
|
@@ -63,6 +126,18 @@ export interface PackageMaterializationConfig {
|
|
|
63
126
|
* "no policy" from "policy with no valid fields".
|
|
64
127
|
*/
|
|
65
128
|
freshness: PackageFreshnessConfig | null;
|
|
129
|
+
/**
|
|
130
|
+
* Package-level per-query metadata: the least specific model-side layer,
|
|
131
|
+
* overridden per property by a model-file, source or per-request declaration.
|
|
132
|
+
* Null when the manifest declares none.
|
|
133
|
+
*
|
|
134
|
+
* Kept VERBATIM (every string-valued property, conforming or not) rather than
|
|
135
|
+
* filtered to what Malloy will accept. A property that violates the contract
|
|
136
|
+
* has to be visible somewhere to be fixable: publish reports it as a warning
|
|
137
|
+
* from this block, and the runtime clamps it with a metric. Filtering here
|
|
138
|
+
* would make an author's typo disappear with nothing to point at.
|
|
139
|
+
*/
|
|
140
|
+
queryMetadata: Record<string, string> | null;
|
|
66
141
|
}
|
|
67
142
|
|
|
68
143
|
function parseFreshness(raw: unknown): PackageFreshnessConfig | null {
|
|
@@ -83,11 +158,55 @@ function parseFreshness(raw: unknown): PackageFreshnessConfig | null {
|
|
|
83
158
|
return freshness;
|
|
84
159
|
}
|
|
85
160
|
|
|
161
|
+
/**
|
|
162
|
+
* The `materialization.queryMetadata` block: string-valued properties verbatim.
|
|
163
|
+
* A non-object block, or one with no string values, degrades to null so absence
|
|
164
|
+
* on the wire always means "declared nothing usable". A non-string value is
|
|
165
|
+
* dropped here because it cannot round-trip as a property at all; contract
|
|
166
|
+
* violations of the string values are deliberately NOT dropped (see
|
|
167
|
+
* {@link PackageMaterializationConfig.queryMetadata}).
|
|
168
|
+
*
|
|
169
|
+
* Each dropped value is reported, because the drop happens BEFORE the config
|
|
170
|
+
* validation that would otherwise name it: an unquoted `"team": 123` is a
|
|
171
|
+
* plausible hand-edit, and without this it disappears with nothing anywhere to
|
|
172
|
+
* point at.
|
|
173
|
+
*/
|
|
174
|
+
function parseQueryMetadata(raw: unknown): {
|
|
175
|
+
metadata: Record<string, string> | null;
|
|
176
|
+
warnings: string[];
|
|
177
|
+
} {
|
|
178
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
179
|
+
return { metadata: null, warnings: [] };
|
|
180
|
+
}
|
|
181
|
+
const out: Record<string, string> = {};
|
|
182
|
+
const warnings: string[] = [];
|
|
183
|
+
for (const [name, value] of Object.entries(raw as Record<string, unknown>)) {
|
|
184
|
+
if (typeof value === "string") {
|
|
185
|
+
out[name] = value;
|
|
186
|
+
} else {
|
|
187
|
+
warnings.push(
|
|
188
|
+
`materialization.queryMetadata: property '${name}' must be a ` +
|
|
189
|
+
`string (got ${value === null ? "null" : typeof value}); it is ` +
|
|
190
|
+
`not attached to any statement`,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
metadata: Object.keys(out).length > 0 ? out : null,
|
|
196
|
+
warnings,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
86
200
|
/**
|
|
87
201
|
* Read the manifest's `materialization` object, keeping only recognized fields.
|
|
88
202
|
* Returns null when the block is absent so the API field is null rather than an
|
|
89
203
|
* empty object; a non-string schedule degrades to null, and an absent or
|
|
90
204
|
* non-object freshness degrades to null.
|
|
205
|
+
*
|
|
206
|
+
* `materialization.scope` is deliberately NOT read here: scope is a package-level
|
|
207
|
+
* mode rather than a layered knob, and it has two possible homes to reconcile —
|
|
208
|
+
* see {@link resolvePackageScope}, which owns that read and surfaces the
|
|
209
|
+
* resolved value on the package itself.
|
|
91
210
|
*/
|
|
92
211
|
export function parsePackageMaterialization(
|
|
93
212
|
raw: unknown,
|
|
@@ -95,12 +214,28 @@ export function parsePackageMaterialization(
|
|
|
95
214
|
if (!raw || typeof raw !== "object") {
|
|
96
215
|
return null;
|
|
97
216
|
}
|
|
98
|
-
const { schedule, freshness } = raw as {
|
|
217
|
+
const { schedule, freshness, queryMetadata } = raw as {
|
|
99
218
|
schedule?: unknown;
|
|
100
219
|
freshness?: unknown;
|
|
220
|
+
queryMetadata?: unknown;
|
|
101
221
|
};
|
|
102
222
|
return {
|
|
103
223
|
schedule: typeof schedule === "string" ? schedule : null,
|
|
104
224
|
freshness: parseFreshness(freshness),
|
|
225
|
+
queryMetadata: parseQueryMetadata(queryMetadata).metadata,
|
|
105
226
|
};
|
|
106
227
|
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* What the `materialization` parse tolerated but could not keep, for the
|
|
231
|
+
* operator warnings array. Reads the same parse as
|
|
232
|
+
* {@link parsePackageMaterialization} rather than re-deriving it, so the two
|
|
233
|
+
* cannot disagree about what was dropped.
|
|
234
|
+
*/
|
|
235
|
+
export function packageMaterializationWarnings(raw: unknown): string[] {
|
|
236
|
+
if (!raw || typeof raw !== "object") {
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
const { queryMetadata } = raw as { queryMetadata?: unknown };
|
|
240
|
+
return parseQueryMetadata(queryMetadata).warnings;
|
|
241
|
+
}
|
|
@@ -66,6 +66,18 @@ describe("assertPersistNamesQuoted", () => {
|
|
|
66
66
|
).not.toThrow();
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
+
it("does not mistake a DOTTED key for the name field", () => {
|
|
70
|
+
// `.` is a word boundary, so a `\b`-anchored pattern reads
|
|
71
|
+
// `queryMetadata.name=` as the persist name and fails the whole model
|
|
72
|
+
// load with a 424 about quoting a name the author never declared.
|
|
73
|
+
expect(() =>
|
|
74
|
+
assertPersistNamesQuoted(
|
|
75
|
+
`#@ persist name="bar" queryMetadata.name=finance`,
|
|
76
|
+
"m.malloy",
|
|
77
|
+
),
|
|
78
|
+
).not.toThrow();
|
|
79
|
+
});
|
|
80
|
+
|
|
69
81
|
it("reports every offending annotation in the message", () => {
|
|
70
82
|
expect(() =>
|
|
71
83
|
assertPersistNamesQuoted(
|
|
@@ -5,11 +5,16 @@ const PERSIST_LINE_PATTERN = /^\s*#@\s+persist\b/;
|
|
|
5
5
|
/**
|
|
6
6
|
* A `name=` key whose value is NOT immediately opened by a single or double
|
|
7
7
|
* quote — i.e. a bare `name=engaged_events` (whitespace around `=` tolerated).
|
|
8
|
-
* `name="..."` and `name='...'` pass.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* `name="..."` and `name='...'` pass.
|
|
9
|
+
*
|
|
10
|
+
* The lookbehind requires a standalone key: neither an `_`-joined neighbour
|
|
11
|
+
* (`tablename=`, `realization_name=`) nor a DOTTED one (`queryMetadata.name=`)
|
|
12
|
+
* is the persist name. A `\b` word boundary would catch the underscore case but
|
|
13
|
+
* not the dotted one, because `.` is itself a boundary — so a legitimate
|
|
14
|
+
* `#@ persist queryMetadata.name=finance` would fail the load with a 424 about
|
|
15
|
+
* quoting a persist name it never declared.
|
|
11
16
|
*/
|
|
12
|
-
const UNQUOTED_NAME_PATTERN =
|
|
17
|
+
const UNQUOTED_NAME_PATTERN = /(?<![.\w])name\s*=\s*(?!["'])/;
|
|
13
18
|
|
|
14
19
|
/**
|
|
15
20
|
* Reject `#@ persist name=<value>` annotations whose name is unquoted.
|