@malloy-publisher/server 0.0.205 → 0.0.206

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 (69) hide show
  1. package/dist/app/api-doc.yaml +363 -395
  2. package/dist/app/assets/{EnvironmentPage-CAge6UHD.js → EnvironmentPage-BYwBeC2F.js} +1 -1
  3. package/dist/app/assets/{HomePage-DhTe8qpa.js → HomePage-ivu4vdpj.js} +1 -1
  4. package/dist/app/assets/{MainPage-CeTxxGex.js → MainPage-B2DnHEDU.js} +2 -2
  5. package/dist/app/assets/{MaterializationsPage-CpDHB70t.js → MaterializationsPage-BZEuwF9P.js} +1 -1
  6. package/dist/app/assets/{ModelPage-D9sSMb75.js → ModelPage-Dpu3bfPg.js} +1 -1
  7. package/dist/app/assets/{PackagePage-LRqQWrFY.js → PackagePage-B8PwcRHt.js} +1 -1
  8. package/dist/app/assets/{RouteError-xT6kuCNw.js → RouteError-BhbywAeC.js} +1 -1
  9. package/dist/app/assets/{WorkbookPage-DsIh9svZ.js → WorkbookPage-C-JXsJG0.js} +1 -1
  10. package/dist/app/assets/{core-C2sQrwVu.es-Bjem0hym.js → core-pPlPr7jK.es-CNEOlxKB.js} +1 -1
  11. package/dist/app/assets/{index-BdOZDcce.js → index-BHEm8Egc.js} +1 -1
  12. package/dist/app/assets/{index-DHHAcY5o.js → index-BsvDrV14.js} +1 -1
  13. package/dist/app/assets/{index-RX3QOTde.js → index-ChR1fKR2.js} +127 -127
  14. package/dist/app/assets/{index.umd-D2WH3D-f.js → index.umd-BVLPYNuj.js} +1 -1
  15. package/dist/app/index.html +1 -1
  16. package/dist/instrumentation.mjs +18 -8
  17. package/dist/package_load_worker.mjs +19 -2
  18. package/dist/server.mjs +1151 -1264
  19. package/package.json +1 -1
  20. package/src/constants.ts +12 -0
  21. package/src/controller/materialization.controller.ts +79 -35
  22. package/src/controller/package.controller.spec.ts +179 -0
  23. package/src/controller/package.controller.ts +60 -73
  24. package/src/dto/package.dto.ts +16 -1
  25. package/src/errors.spec.ts +12 -0
  26. package/src/errors.ts +18 -0
  27. package/src/health.spec.ts +34 -1
  28. package/src/instrumentation.ts +33 -17
  29. package/src/materialization_metrics.ts +66 -0
  30. package/src/package_load/package_load_pool.ts +7 -1
  31. package/src/package_load/package_load_worker.ts +44 -4
  32. package/src/package_load/protocol.ts +7 -1
  33. package/src/server-old.ts +7 -149
  34. package/src/server.ts +9 -188
  35. package/src/service/authorize_integration.spec.ts +67 -0
  36. package/src/service/environment.ts +212 -12
  37. package/src/service/environment_store.spec.ts +0 -81
  38. package/src/service/environment_store.ts +0 -23
  39. package/src/service/explore_visibility.spec.ts +434 -0
  40. package/src/service/exports_probe.spec.ts +107 -0
  41. package/src/service/manifest_loader.spec.ts +99 -0
  42. package/src/service/manifest_loader.ts +95 -0
  43. package/src/service/materialization_service.spec.ts +324 -512
  44. package/src/service/materialization_service.ts +816 -656
  45. package/src/service/model.ts +400 -13
  46. package/src/service/package.spec.ts +14 -2
  47. package/src/service/package.ts +254 -14
  48. package/src/service/package_rollback.spec.ts +190 -0
  49. package/src/service/package_worker_path.spec.ts +223 -0
  50. package/src/service/query_boundary.spec.ts +470 -0
  51. package/src/storage/DatabaseInterface.ts +35 -57
  52. package/src/storage/StorageManager.mock.ts +0 -9
  53. package/src/storage/StorageManager.ts +7 -290
  54. package/src/storage/duckdb/DuckDBRepository.ts +2 -35
  55. package/src/storage/duckdb/MaterializationRepository.ts +52 -27
  56. package/src/storage/duckdb/schema.ts +4 -20
  57. package/tests/integration/materialization/manifest_binding.integration.spec.ts +175 -0
  58. package/tests/integration/materialization/materialization_lifecycle.integration.spec.ts +277 -266
  59. package/tests/unit/duckdb/legacy_schema_migration.test.ts +7 -4
  60. package/src/controller/manifest.controller.ts +0 -38
  61. package/src/service/manifest_service.spec.ts +0 -206
  62. package/src/service/manifest_service.ts +0 -117
  63. package/src/service/materialized_table_gc.spec.ts +0 -384
  64. package/src/service/materialized_table_gc.ts +0 -231
  65. package/src/storage/duckdb/DuckDBManifestStore.ts +0 -70
  66. package/src/storage/duckdb/ManifestRepository.ts +0 -120
  67. package/src/storage/duckdb/manifest_store.spec.ts +0 -133
  68. package/src/storage/ducklake/DuckLakeManifestStore.ts +0 -155
  69. package/tests/unit/storage/StorageManager.test.ts +0 -166
@@ -0,0 +1,175 @@
1
+ /// <reference types="bun-types" />
2
+
3
+ import { afterAll, beforeAll, describe, expect, it } from "bun:test";
4
+ import * as fsp from "fs/promises";
5
+ import os from "os";
6
+ import path from "path";
7
+ import { fileURLToPath } from "url";
8
+ import { RestE2EEnv, startRestE2E } from "../../harness/rest_e2e";
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+
13
+ const PROJECT_NAME = "manifest-bind-project";
14
+ const PACKAGE_NAME = "persist-test";
15
+ const MODEL_PATH = "persist_test.malloy";
16
+ const API = `/api/v0/environments/${PROJECT_NAME}/packages/${PACKAGE_NAME}`;
17
+
18
+ /**
19
+ * Covers the publisher's manifestLocation plumbing: create/update accepts a
20
+ * manifest URI, it is persisted to publisher.json (so it survives a reload),
21
+ * the package loader fetches + binds it through the existing reloadAllModels
22
+ * primitive on every (re)load, an unreachable manifest degrades to serving
23
+ * live, and clearing it reverts.
24
+ *
25
+ * The build-time rewrite of upstream persist references to physical tables is
26
+ * Malloy's reloadAllModels behavior, exercised by the materialization lifecycle
27
+ * spec; here we assert the publisher-owned fetch/persist/bind wiring.
28
+ */
29
+ describe("Manifest binding via Package.manifestLocation (E2E)", () => {
30
+ let env: (RestE2EEnv & { stop(): Promise<void> }) | null = null;
31
+ let baseUrl: string;
32
+ let tmpDir: string;
33
+
34
+ beforeAll(async () => {
35
+ env = await startRestE2E();
36
+ baseUrl = env.baseUrl;
37
+ tmpDir = await fsp.mkdtemp(path.join(os.tmpdir(), "manifest-bind-"));
38
+
39
+ const fixtureDir = path.resolve(__dirname, "../../fixtures/persist-test");
40
+ const createRes = await fetch(`${baseUrl}/api/v0/environments`, {
41
+ method: "POST",
42
+ headers: { "Content-Type": "application/json" },
43
+ body: JSON.stringify({
44
+ name: PROJECT_NAME,
45
+ packages: [{ name: PACKAGE_NAME, location: fixtureDir }],
46
+ connections: [],
47
+ }),
48
+ });
49
+ if (!createRes.ok) {
50
+ throw new Error(
51
+ `Failed to create test project (${createRes.status}): ${await createRes.text()}`,
52
+ );
53
+ }
54
+
55
+ const deadline = Date.now() + 30_000;
56
+ while (Date.now() < deadline) {
57
+ const res = await fetch(`${baseUrl}${API}`);
58
+ if (res.ok) break;
59
+ await new Promise((r) => setTimeout(r, 500));
60
+ }
61
+ });
62
+
63
+ afterAll(async () => {
64
+ if (baseUrl) {
65
+ await fetch(`${baseUrl}/api/v0/environments/${PROJECT_NAME}`, {
66
+ method: "DELETE",
67
+ }).catch(() => {});
68
+ }
69
+ await env?.stop();
70
+ await fsp.rm(tmpDir, { recursive: true, force: true }).catch(() => {});
71
+ env = null;
72
+ });
73
+
74
+ function url(p: string): string {
75
+ return `${baseUrl}${API}${p}`;
76
+ }
77
+
78
+ async function getPackage(reload = false): Promise<Record<string, unknown>> {
79
+ const res = await fetch(url(reload ? "?reload=true" : ""));
80
+ expect(res.status).toBe(200);
81
+ return (await res.json()) as Record<string, unknown>;
82
+ }
83
+
84
+ async function patchPackage(
85
+ body: Record<string, unknown>,
86
+ ): Promise<Response> {
87
+ return fetch(url(""), {
88
+ method: "PATCH",
89
+ headers: { "Content-Type": "application/json" },
90
+ body: JSON.stringify({ name: PACKAGE_NAME, ...body }),
91
+ });
92
+ }
93
+
94
+ async function queryOrderSummaryStatus(): Promise<number> {
95
+ const res = await fetch(`${baseUrl}${API}/models/${MODEL_PATH}/query`, {
96
+ method: "POST",
97
+ headers: { "Content-Type": "application/json" },
98
+ body: JSON.stringify({
99
+ query: "run: order_summary -> { aggregate: c is count() }",
100
+ }),
101
+ });
102
+ return res.status;
103
+ }
104
+
105
+ async function writeManifest(): Promise<string> {
106
+ const file = path.join(tmpDir, `manifest-${Date.now()}.json`);
107
+ await fsp.writeFile(
108
+ file,
109
+ JSON.stringify({
110
+ builtAt: new Date().toISOString(),
111
+ strict: false,
112
+ entries: {
113
+ build123: {
114
+ buildId: "build123",
115
+ sourceName: "order_summary",
116
+ physicalTableName: "main.order_summary_mz",
117
+ connectionName: "duckdb",
118
+ },
119
+ },
120
+ }),
121
+ "utf8",
122
+ );
123
+ return file;
124
+ }
125
+
126
+ it("starts with no manifestLocation and serves live", async () => {
127
+ expect((await getPackage()).manifestLocation ?? null).toBeNull();
128
+ expect(await queryOrderSummaryStatus()).toBe(200);
129
+ });
130
+
131
+ it(
132
+ "accepts, persists, reloads, and clears a manifestLocation",
133
+ async () => {
134
+ const manifestFile = await writeManifest();
135
+
136
+ // Accept on update; the response echoes the bound location.
137
+ const patchRes = await patchPackage({
138
+ manifestLocation: manifestFile,
139
+ });
140
+ expect(patchRes.status).toBe(200);
141
+ expect((await patchRes.json()).manifestLocation).toBe(manifestFile);
142
+
143
+ // In-memory metadata reflects it; binding did not break serving.
144
+ expect((await getPackage()).manifestLocation).toBe(manifestFile);
145
+ expect(await queryOrderSummaryStatus()).toBe(200);
146
+
147
+ // Persisted to publisher.json: a reload re-reads and re-binds it.
148
+ expect((await getPackage(true)).manifestLocation).toBe(manifestFile);
149
+ expect(await queryOrderSummaryStatus()).toBe(200);
150
+
151
+ // Clearing reverts to live and survives a reload.
152
+ const clearRes = await patchPackage({ manifestLocation: null });
153
+ expect(clearRes.status).toBe(200);
154
+ expect((await clearRes.json()).manifestLocation ?? null).toBeNull();
155
+ expect((await getPackage(true)).manifestLocation ?? null).toBeNull();
156
+ expect(await queryOrderSummaryStatus()).toBe(200);
157
+ },
158
+ { timeout: 60_000 },
159
+ );
160
+
161
+ it("degrades to serving live when the manifest is unreachable", async () => {
162
+ const missing = path.join(tmpDir, "does-not-exist.json");
163
+
164
+ const patchRes = await patchPackage({ manifestLocation: missing });
165
+ expect(patchRes.status).toBe(200);
166
+ expect((await patchRes.json()).manifestLocation).toBe(missing);
167
+
168
+ // A fetch failure must not brick the package — it still serves live.
169
+ expect(await queryOrderSummaryStatus()).toBe(200);
170
+ expect((await getPackage(true)).manifestLocation).toBe(missing);
171
+ expect(await queryOrderSummaryStatus()).toBe(200);
172
+
173
+ await patchPackage({ manifestLocation: null });
174
+ });
175
+ });