@malloy-publisher/server 0.0.162 → 0.0.167
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 +185 -0
- package/dist/app/assets/HomePage-D76UaGFV.js +1 -0
- package/dist/app/assets/{MainPage-CzAy2LSX.js → MainPage-C9Fr5IN8.js} +1 -1
- package/dist/app/assets/{ModelPage-uZf0eDBu.js → ModelPage-BkU6HAHA.js} +1 -1
- package/dist/app/assets/PackagePage-BhE9Wi7b.js +1 -0
- package/dist/app/assets/ProjectPage-BatZLVap.js +1 -0
- package/dist/app/assets/RouteError-Bo5zJ8Xa.js +1 -0
- package/dist/app/assets/{WorkbookPage-CBJ0x84n.js → WorkbookPage-D3rUQZj6.js} +1 -1
- package/dist/app/assets/{index-BoduKqUa.js → index-BLxl0XLH.js} +104 -104
- package/dist/app/assets/{index-Bl1fe3A7.js → index-hkABoiMV.js} +1 -1
- package/dist/app/assets/{index-D_8e14NE.js → index-lhDwptrQ.js} +1 -1
- package/dist/app/assets/{index.umd-DRsjT6d4.js → index.umd-BkXQ-YAe.js} +1 -1
- package/dist/app/index.html +1 -1
- package/dist/instrumentation.js +90007 -92610
- package/dist/server.js +197328 -106265
- package/k6-tests/load-test/load-test.ts +30 -0
- package/package.json +2 -1
- package/src/controller/compile.controller.ts +35 -0
- package/src/controller/model.controller.ts +20 -9
- package/src/health.ts +189 -0
- package/src/instrumentation.ts +123 -34
- package/src/logger.ts +9 -1
- package/src/server.ts +86 -3
- package/src/service/connection.spec.ts +1226 -0
- package/src/service/connection.ts +114 -12
- package/src/service/db_utils.ts +19 -41
- package/src/service/gcs_s3_utils.ts +115 -40
- package/src/service/model.spec.ts +5 -5
- package/src/service/model.ts +61 -24
- package/src/service/project.ts +120 -1
- package/src/service/project_compile.spec.ts +197 -0
- package/src/service/project_store.ts +54 -21
- package/src/storage/StorageManager.ts +4 -3
- package/src/storage/duckdb/schema.ts +6 -5
- package/tests/harness/e2e.ts +4 -0
- package/tests/harness/mcp_test_setup.ts +6 -2
- package/dist/app/assets/HomePage-CgSTNEQW.js +0 -1
- package/dist/app/assets/PackagePage-BHvPFsmZ.js +0 -1
- package/dist/app/assets/ProjectPage-ndnv5nGp.js +0 -1
- package/dist/app/assets/RouteError-CZC9OOKh.js +0 -1
package/src/service/project.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { LogMessage } from "@malloydata/malloy";
|
|
2
|
+
import { FixedConnectionMap, MalloyError, Runtime } from "@malloydata/malloy";
|
|
1
3
|
import { BaseConnection } from "@malloydata/malloy/connection";
|
|
2
4
|
import { Mutex } from "async-mutex";
|
|
3
5
|
import * as fs from "fs";
|
|
@@ -10,6 +12,7 @@ import {
|
|
|
10
12
|
ProjectNotFoundError,
|
|
11
13
|
} from "../errors";
|
|
12
14
|
import { logger } from "../logger";
|
|
15
|
+
import { URL_READER } from "../utils";
|
|
13
16
|
import { createProjectConnections, InternalConnection } from "./connection";
|
|
14
17
|
import { ApiConnection } from "./model";
|
|
15
18
|
import { Package } from "./package";
|
|
@@ -159,6 +162,71 @@ export class Project {
|
|
|
159
162
|
return this.metadata;
|
|
160
163
|
}
|
|
161
164
|
|
|
165
|
+
public async compileSource(
|
|
166
|
+
packageName: string,
|
|
167
|
+
modelName: string,
|
|
168
|
+
source: string,
|
|
169
|
+
includeSql: boolean = false,
|
|
170
|
+
): Promise<{ problems: LogMessage[]; sql?: string }> {
|
|
171
|
+
// Place the virtual file in the model's directory so relative imports resolve correctly.
|
|
172
|
+
const modelDir = path.dirname(
|
|
173
|
+
path.join(this.projectPath, packageName, modelName),
|
|
174
|
+
);
|
|
175
|
+
const virtualUri = `file://${path.join(modelDir, "__compile_check.malloy")}`;
|
|
176
|
+
const virtualUrl = new URL(virtualUri);
|
|
177
|
+
|
|
178
|
+
// Read the model file and extract its preamble (pragmas + imports) so that
|
|
179
|
+
// the user's query inherits the model's import context.
|
|
180
|
+
const modelPath = path.join(this.projectPath, packageName, modelName);
|
|
181
|
+
const preamble = await extractPreamble(modelPath);
|
|
182
|
+
const fullSource = preamble ? `${preamble}\n${source}` : source;
|
|
183
|
+
|
|
184
|
+
// Create a URL Reader that serves the source string for the virtual file,
|
|
185
|
+
// but falls back to the disk for everything else (imports).
|
|
186
|
+
const interceptingReader = {
|
|
187
|
+
readURL: async (url: URL) => {
|
|
188
|
+
if (url.toString() === virtualUri) {
|
|
189
|
+
return fullSource;
|
|
190
|
+
}
|
|
191
|
+
return URL_READER.readURL(url);
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// Initialize Runtime with the project's active connections
|
|
196
|
+
const runtime = new Runtime({
|
|
197
|
+
urlReader: interceptingReader,
|
|
198
|
+
connections: new FixedConnectionMap(this.malloyConnections, "duckdb"),
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Attempt to compile
|
|
202
|
+
try {
|
|
203
|
+
const modelMaterializer = runtime.loadModel(virtualUrl);
|
|
204
|
+
const model = await modelMaterializer.getModel();
|
|
205
|
+
|
|
206
|
+
// If includeSql is requested and compilation succeeded, attempt to extract SQL
|
|
207
|
+
let sql: string | undefined;
|
|
208
|
+
if (includeSql) {
|
|
209
|
+
try {
|
|
210
|
+
const queryMaterializer = modelMaterializer.loadFinalQuery();
|
|
211
|
+
sql = await queryMaterializer.getSQL();
|
|
212
|
+
} catch {
|
|
213
|
+
// Source may not contain a runnable query (e.g. only source definitions),
|
|
214
|
+
// in which case we simply omit the sql field.
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// If successful, return any non-fatal warnings
|
|
219
|
+
return { problems: model.problems, sql };
|
|
220
|
+
} catch (error) {
|
|
221
|
+
// If parsing/compilation fails, return the errors
|
|
222
|
+
if (error instanceof MalloyError) {
|
|
223
|
+
return { problems: error.problems };
|
|
224
|
+
}
|
|
225
|
+
// If it's a system error (e.g. file not found), throw it up
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
162
230
|
public listApiConnections(): ApiConnection[] {
|
|
163
231
|
return this.apiConnections;
|
|
164
232
|
}
|
|
@@ -244,11 +312,18 @@ export class Project {
|
|
|
244
312
|
// package multiple times.
|
|
245
313
|
let packageMutex = this.packageMutexes.get(packageName);
|
|
246
314
|
if (packageMutex?.isLocked()) {
|
|
315
|
+
logger.debug(
|
|
316
|
+
`Package ${packageName} is being loaded, waiting for unlock...`,
|
|
317
|
+
);
|
|
247
318
|
await packageMutex.waitForUnlock();
|
|
319
|
+
logger.debug(`Package ${packageName} unlocked`);
|
|
248
320
|
const existingPackage = this.packages.get(packageName);
|
|
249
321
|
if (existingPackage) {
|
|
322
|
+
logger.debug(`Package ${packageName} loaded by another request`);
|
|
250
323
|
return existingPackage;
|
|
251
324
|
}
|
|
325
|
+
// If package still doesn't exist after unlock, it might have failed to load
|
|
326
|
+
// Continue to try loading it ourselves
|
|
252
327
|
}
|
|
253
328
|
packageMutex = new Mutex();
|
|
254
329
|
this.packageMutexes.set(packageName, packageMutex);
|
|
@@ -264,19 +339,23 @@ export class Project {
|
|
|
264
339
|
this.setPackageStatus(packageName, PackageStatus.LOADING);
|
|
265
340
|
|
|
266
341
|
try {
|
|
342
|
+
logger.debug(`Loading package ${packageName}...`);
|
|
343
|
+
const packagePath = path.join(this.projectPath, packageName);
|
|
267
344
|
const _package = await Package.create(
|
|
268
345
|
this.projectName,
|
|
269
346
|
packageName,
|
|
270
|
-
|
|
347
|
+
packagePath,
|
|
271
348
|
this.malloyConnections,
|
|
272
349
|
);
|
|
273
350
|
this.packages.set(packageName, _package);
|
|
274
351
|
|
|
275
352
|
// Set package status to serving
|
|
276
353
|
this.setPackageStatus(packageName, PackageStatus.SERVING);
|
|
354
|
+
logger.debug(`Successfully loaded package ${packageName}`);
|
|
277
355
|
|
|
278
356
|
return _package;
|
|
279
357
|
} catch (error) {
|
|
358
|
+
logger.error(`Failed to load package ${packageName}`, { error });
|
|
280
359
|
// Clean up on error - mutex will be automatically released by runExclusive
|
|
281
360
|
this.packages.delete(packageName);
|
|
282
361
|
this.packageStatuses.delete(packageName);
|
|
@@ -537,3 +616,43 @@ export class Project {
|
|
|
537
616
|
});
|
|
538
617
|
}
|
|
539
618
|
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Extracts the preamble from a Malloy model file — the leading block of
|
|
622
|
+
* `##!` pragmas, `import` statements, blank lines, and comments that appear
|
|
623
|
+
* before any `source:`, `query:`, or `run:` definition. This allows a
|
|
624
|
+
* submitted query to inherit the model's import context.
|
|
625
|
+
*/
|
|
626
|
+
export async function extractPreamble(modelPath: string): Promise<string> {
|
|
627
|
+
try {
|
|
628
|
+
const content = await fs.promises.readFile(modelPath, "utf8");
|
|
629
|
+
return extractPreambleFromSource(content);
|
|
630
|
+
} catch {
|
|
631
|
+
// If the model file can't be read, return empty preamble
|
|
632
|
+
// and let the compilation surface any import errors naturally.
|
|
633
|
+
return "";
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Extracts the preamble from Malloy source text. Exported for testing.
|
|
639
|
+
*/
|
|
640
|
+
export function extractPreambleFromSource(content: string): string {
|
|
641
|
+
const lines = content.split("\n");
|
|
642
|
+
const preambleLines: string[] = [];
|
|
643
|
+
|
|
644
|
+
for (const line of lines) {
|
|
645
|
+
const trimmed = line.trim();
|
|
646
|
+
// Stop at the first source/query/run definition
|
|
647
|
+
if (
|
|
648
|
+
trimmed.startsWith("source:") ||
|
|
649
|
+
trimmed.startsWith("query:") ||
|
|
650
|
+
trimmed.startsWith("run:")
|
|
651
|
+
) {
|
|
652
|
+
break;
|
|
653
|
+
}
|
|
654
|
+
preambleLines.push(line);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
return preambleLines.join("\n").trimEnd();
|
|
658
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { extractPreamble, extractPreambleFromSource } from "./project";
|
|
5
|
+
|
|
6
|
+
describe("extractPreambleFromSource", () => {
|
|
7
|
+
it("should extract pragmas and imports before a source definition", () => {
|
|
8
|
+
const content = [
|
|
9
|
+
"##! experimental.parameters",
|
|
10
|
+
'import "utils.malloy"',
|
|
11
|
+
'import { revenue } from "metrics.malloy"',
|
|
12
|
+
"",
|
|
13
|
+
'source: my_source is duckdb.table("data.parquet")',
|
|
14
|
+
' dimension: name is "test"',
|
|
15
|
+
].join("\n");
|
|
16
|
+
|
|
17
|
+
const result = extractPreambleFromSource(content);
|
|
18
|
+
expect(result).toBe(
|
|
19
|
+
[
|
|
20
|
+
"##! experimental.parameters",
|
|
21
|
+
'import "utils.malloy"',
|
|
22
|
+
'import { revenue } from "metrics.malloy"',
|
|
23
|
+
].join("\n"),
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should extract pragmas and imports before a run statement", () => {
|
|
28
|
+
const content = [
|
|
29
|
+
'import { my_source } from "model.malloy"',
|
|
30
|
+
"",
|
|
31
|
+
"run: my_source -> { aggregate: count() }",
|
|
32
|
+
].join("\n");
|
|
33
|
+
|
|
34
|
+
const result = extractPreambleFromSource(content);
|
|
35
|
+
expect(result).toBe('import { my_source } from "model.malloy"');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should extract pragmas and imports before a query definition", () => {
|
|
39
|
+
const content = [
|
|
40
|
+
'import { my_source } from "model.malloy"',
|
|
41
|
+
"",
|
|
42
|
+
"query: top_items is my_source -> { limit: 10 }",
|
|
43
|
+
].join("\n");
|
|
44
|
+
|
|
45
|
+
const result = extractPreambleFromSource(content);
|
|
46
|
+
expect(result).toBe('import { my_source } from "model.malloy"');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should return empty string when file starts with source:", () => {
|
|
50
|
+
const content = 'source: my_source is duckdb.table("data.parquet")';
|
|
51
|
+
|
|
52
|
+
const result = extractPreambleFromSource(content);
|
|
53
|
+
expect(result).toBe("");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should return empty string when file starts with run:", () => {
|
|
57
|
+
const content = 'run: duckdb.sql("SELECT 1")';
|
|
58
|
+
|
|
59
|
+
const result = extractPreambleFromSource(content);
|
|
60
|
+
expect(result).toBe("");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should return empty string when file starts with query:", () => {
|
|
64
|
+
const content = 'query: q is duckdb.sql("SELECT 1")';
|
|
65
|
+
|
|
66
|
+
const result = extractPreambleFromSource(content);
|
|
67
|
+
expect(result).toBe("");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should preserve comments in the preamble", () => {
|
|
71
|
+
const content = [
|
|
72
|
+
"##! experimental.parameters",
|
|
73
|
+
"// This model defines revenue metrics",
|
|
74
|
+
'import { revenue } from "metrics.malloy"',
|
|
75
|
+
"// Main source below",
|
|
76
|
+
'source: my_source is duckdb.table("data.parquet")',
|
|
77
|
+
].join("\n");
|
|
78
|
+
|
|
79
|
+
const result = extractPreambleFromSource(content);
|
|
80
|
+
expect(result).toBe(
|
|
81
|
+
[
|
|
82
|
+
"##! experimental.parameters",
|
|
83
|
+
"// This model defines revenue metrics",
|
|
84
|
+
'import { revenue } from "metrics.malloy"',
|
|
85
|
+
"// Main source below",
|
|
86
|
+
].join("\n"),
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should handle multiple import blocks", () => {
|
|
91
|
+
const content = [
|
|
92
|
+
'import { a } from "file_a.malloy"',
|
|
93
|
+
'import { b } from "file_b.malloy"',
|
|
94
|
+
'import { c, d } from "file_c.malloy"',
|
|
95
|
+
"",
|
|
96
|
+
"source: combined is a {",
|
|
97
|
+
" join_one: b on b.id = a.b_id",
|
|
98
|
+
"}",
|
|
99
|
+
].join("\n");
|
|
100
|
+
|
|
101
|
+
const result = extractPreambleFromSource(content);
|
|
102
|
+
expect(result).toBe(
|
|
103
|
+
[
|
|
104
|
+
'import { a } from "file_a.malloy"',
|
|
105
|
+
'import { b } from "file_b.malloy"',
|
|
106
|
+
'import { c, d } from "file_c.malloy"',
|
|
107
|
+
].join("\n"),
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("should return all content when there are no source/query/run definitions", () => {
|
|
112
|
+
const content = [
|
|
113
|
+
"##! experimental.parameters",
|
|
114
|
+
'import { revenue } from "metrics.malloy"',
|
|
115
|
+
"",
|
|
116
|
+
"// no definitions yet",
|
|
117
|
+
].join("\n");
|
|
118
|
+
|
|
119
|
+
const result = extractPreambleFromSource(content);
|
|
120
|
+
expect(result).toBe(
|
|
121
|
+
[
|
|
122
|
+
"##! experimental.parameters",
|
|
123
|
+
'import { revenue } from "metrics.malloy"',
|
|
124
|
+
"",
|
|
125
|
+
"// no definitions yet",
|
|
126
|
+
].join("\n"),
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("should return empty string for empty input", () => {
|
|
131
|
+
expect(extractPreambleFromSource("")).toBe("");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("should handle indented source/query/run definitions", () => {
|
|
135
|
+
const content = [
|
|
136
|
+
'import "model.malloy"',
|
|
137
|
+
"",
|
|
138
|
+
' source: indented is duckdb.table("data.parquet")',
|
|
139
|
+
].join("\n");
|
|
140
|
+
|
|
141
|
+
// Indented definitions should still be detected (trimmed before check)
|
|
142
|
+
const result = extractPreambleFromSource(content);
|
|
143
|
+
expect(result).toBe('import "model.malloy"');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("should not stop on 'source' appearing in comments or strings", () => {
|
|
147
|
+
const content = [
|
|
148
|
+
"// This file defines the source of truth",
|
|
149
|
+
'import "model.malloy"',
|
|
150
|
+
'source: my_source is duckdb.table("data.parquet")',
|
|
151
|
+
].join("\n");
|
|
152
|
+
|
|
153
|
+
const result = extractPreambleFromSource(content);
|
|
154
|
+
expect(result).toBe(
|
|
155
|
+
[
|
|
156
|
+
"// This file defines the source of truth",
|
|
157
|
+
'import "model.malloy"',
|
|
158
|
+
].join("\n"),
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("extractPreamble (file-based)", () => {
|
|
164
|
+
const testDir = path.join(process.cwd(), "test-temp-preamble");
|
|
165
|
+
const testModelPath = path.join(testDir, "test_model.malloy");
|
|
166
|
+
|
|
167
|
+
beforeEach(() => {
|
|
168
|
+
if (!fs.existsSync(testDir)) {
|
|
169
|
+
fs.mkdirSync(testDir, { recursive: true });
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
afterEach(() => {
|
|
174
|
+
if (fs.existsSync(testDir)) {
|
|
175
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("should read and extract preamble from a file", async () => {
|
|
180
|
+
const content = [
|
|
181
|
+
'import { revenue } from "metrics.malloy"',
|
|
182
|
+
"",
|
|
183
|
+
'source: my_source is duckdb.table("data.parquet")',
|
|
184
|
+
].join("\n");
|
|
185
|
+
fs.writeFileSync(testModelPath, content);
|
|
186
|
+
|
|
187
|
+
const result = await extractPreamble(testModelPath);
|
|
188
|
+
expect(result).toBe('import { revenue } from "metrics.malloy"');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("should return empty string when file does not exist", async () => {
|
|
192
|
+
const result = await extractPreamble(
|
|
193
|
+
path.join(testDir, "nonexistent.malloy"),
|
|
194
|
+
);
|
|
195
|
+
expect(result).toBe("");
|
|
196
|
+
});
|
|
197
|
+
});
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
PackageNotFoundError,
|
|
25
25
|
ProjectNotFoundError,
|
|
26
26
|
} from "../errors";
|
|
27
|
+
import { getOperationalState, markNotReady, markReady } from "../health";
|
|
27
28
|
import { formatDuration, logger } from "../logger";
|
|
28
29
|
import { Connection } from "../storage/DatabaseInterface";
|
|
29
30
|
import { StorageConfig, StorageManager } from "../storage/StorageManager";
|
|
@@ -188,12 +189,15 @@ export class ProjectStore {
|
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
this.isInitialized = true;
|
|
192
|
+
markReady();
|
|
191
193
|
const initializationDuration = performance.now() - initialTime;
|
|
192
194
|
logger.info(
|
|
193
195
|
`Project store successfully initialized in ${formatDuration(initializationDuration)}`,
|
|
194
196
|
);
|
|
195
197
|
} catch (error) {
|
|
196
|
-
|
|
198
|
+
markNotReady();
|
|
199
|
+
const errorData = this.extractErrorDataFromError(error);
|
|
200
|
+
logger.error("Error initializing project store", errorData);
|
|
197
201
|
process.exit(1);
|
|
198
202
|
}
|
|
199
203
|
}
|
|
@@ -530,7 +534,7 @@ export class ProjectStore {
|
|
|
530
534
|
PUBLISHER_DATA_DIR,
|
|
531
535
|
);
|
|
532
536
|
logger.info(
|
|
533
|
-
`
|
|
537
|
+
`Reinitialization mode: Cleaning up upload documents path ${uploadDocsPath}`,
|
|
534
538
|
);
|
|
535
539
|
try {
|
|
536
540
|
await fs.promises.rm(uploadDocsPath, {
|
|
@@ -572,6 +576,8 @@ export class ProjectStore {
|
|
|
572
576
|
projects: [] as Array<components["schemas"]["Project"]>,
|
|
573
577
|
initialized: this.isInitialized,
|
|
574
578
|
frozenConfig: isPublisherConfigFrozen(this.serverRootPath),
|
|
579
|
+
operationalState:
|
|
580
|
+
getOperationalState() as components["schemas"]["ServerStatus"]["operationalState"],
|
|
575
581
|
};
|
|
576
582
|
|
|
577
583
|
const projects = await this.listProjects(true);
|
|
@@ -1020,11 +1026,10 @@ export class ProjectStore {
|
|
|
1020
1026
|
}
|
|
1021
1027
|
}
|
|
1022
1028
|
} catch (error) {
|
|
1029
|
+
const errorData = this.extractErrorDataFromError(error);
|
|
1023
1030
|
logger.error(
|
|
1024
1031
|
`Failed to download or mount location "${groupedLocation}"`,
|
|
1025
|
-
|
|
1026
|
-
error,
|
|
1027
|
-
},
|
|
1032
|
+
errorData,
|
|
1028
1033
|
);
|
|
1029
1034
|
throw new PackageNotFoundError(
|
|
1030
1035
|
`Failed to download or mount location: ${groupedLocation}`,
|
|
@@ -1070,9 +1075,11 @@ export class ProjectStore {
|
|
|
1070
1075
|
);
|
|
1071
1076
|
return;
|
|
1072
1077
|
} catch (error) {
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1078
|
+
const errorData = this.extractErrorDataFromError(error);
|
|
1079
|
+
logger.error(
|
|
1080
|
+
`Failed to download GCS directory "${location}"`,
|
|
1081
|
+
errorData,
|
|
1082
|
+
);
|
|
1076
1083
|
throw new PackageNotFoundError(
|
|
1077
1084
|
`Failed to download GCS directory: ${location}`,
|
|
1078
1085
|
);
|
|
@@ -1088,9 +1095,11 @@ export class ProjectStore {
|
|
|
1088
1095
|
await this.downloadGitHubDirectory(location, targetPath);
|
|
1089
1096
|
return;
|
|
1090
1097
|
} catch (error) {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1098
|
+
const errorData = this.extractErrorDataFromError(error);
|
|
1099
|
+
logger.error(
|
|
1100
|
+
`Failed to clone GitHub repository "${location}"`,
|
|
1101
|
+
errorData,
|
|
1102
|
+
);
|
|
1094
1103
|
throw new PackageNotFoundError(
|
|
1095
1104
|
`Failed to clone GitHub repository: ${location}`,
|
|
1096
1105
|
);
|
|
@@ -1106,9 +1115,11 @@ export class ProjectStore {
|
|
|
1106
1115
|
await this.downloadS3Directory(location, projectName, targetPath);
|
|
1107
1116
|
return;
|
|
1108
1117
|
} catch (error) {
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1118
|
+
const errorData = this.extractErrorDataFromError(error);
|
|
1119
|
+
logger.error(
|
|
1120
|
+
`Failed to download S3 directory "${location}"`,
|
|
1121
|
+
errorData,
|
|
1122
|
+
);
|
|
1112
1123
|
throw new PackageNotFoundError(
|
|
1113
1124
|
`Failed to download S3 directory: ${location}`,
|
|
1114
1125
|
);
|
|
@@ -1132,9 +1143,11 @@ export class ProjectStore {
|
|
|
1132
1143
|
);
|
|
1133
1144
|
return;
|
|
1134
1145
|
} catch (error) {
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1146
|
+
const errorData = this.extractErrorDataFromError(error);
|
|
1147
|
+
logger.error(
|
|
1148
|
+
`Failed to mount local directory "${packagePath}"`,
|
|
1149
|
+
errorData,
|
|
1150
|
+
);
|
|
1138
1151
|
throw new PackageNotFoundError(
|
|
1139
1152
|
`Failed to mount local directory: ${packagePath}`,
|
|
1140
1153
|
);
|
|
@@ -1327,10 +1340,11 @@ export class ProjectStore {
|
|
|
1327
1340
|
await new Promise<void>((resolve, reject) => {
|
|
1328
1341
|
simpleGit().clone(repoUrl, absoluteDirPath, {}, (err) => {
|
|
1329
1342
|
if (err) {
|
|
1330
|
-
|
|
1331
|
-
logger.error(
|
|
1332
|
-
|
|
1333
|
-
|
|
1343
|
+
const errorData = this.extractErrorDataFromError(err);
|
|
1344
|
+
logger.error(
|
|
1345
|
+
`Failed to clone GitHub repository "${repoUrl}"`,
|
|
1346
|
+
errorData,
|
|
1347
|
+
);
|
|
1334
1348
|
reject(err);
|
|
1335
1349
|
}
|
|
1336
1350
|
resolve();
|
|
@@ -1391,4 +1405,23 @@ export class ProjectStore {
|
|
|
1391
1405
|
|
|
1392
1406
|
// https://github.com/credibledata/malloy-samples/imdb/publisher.json -> ${absoluteDirPath}/publisher.json
|
|
1393
1407
|
}
|
|
1408
|
+
|
|
1409
|
+
private extractErrorDataFromError(error: unknown): {
|
|
1410
|
+
error: string;
|
|
1411
|
+
stack?: string;
|
|
1412
|
+
task?: unknown;
|
|
1413
|
+
} {
|
|
1414
|
+
const errorMessage =
|
|
1415
|
+
error instanceof Error ? error.message : String(error);
|
|
1416
|
+
const errorData: { error: string; stack?: string; task?: unknown } = {
|
|
1417
|
+
error: errorMessage,
|
|
1418
|
+
};
|
|
1419
|
+
if (error instanceof Error && logger.level === "debug") {
|
|
1420
|
+
errorData.stack = error.stack;
|
|
1421
|
+
}
|
|
1422
|
+
if (error && typeof error === "object" && "task" in error) {
|
|
1423
|
+
errorData.task = (error as { task?: unknown }).task;
|
|
1424
|
+
}
|
|
1425
|
+
return errorData;
|
|
1426
|
+
}
|
|
1394
1427
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { logger } from "../logger";
|
|
1
2
|
import { DatabaseConnection, ResourceRepository } from "./DatabaseInterface";
|
|
2
3
|
import { DuckDBConnection } from "./duckdb/DuckDBConnection";
|
|
3
4
|
import { DuckDBRepository } from "./duckdb/DuckDBRepository";
|
|
@@ -37,11 +38,11 @@ export class StorageManager {
|
|
|
37
38
|
|
|
38
39
|
async initialize(reinit: boolean = false): Promise<void> {
|
|
39
40
|
if (reinit) {
|
|
40
|
-
|
|
41
|
-
"
|
|
41
|
+
logger.info(
|
|
42
|
+
"Reinitialization mode: Database will be dropped and recreated",
|
|
42
43
|
);
|
|
43
44
|
} else {
|
|
44
|
-
|
|
45
|
+
logger.info("Normal mode: Loading from existing database");
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
switch (this.config.type) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { logger } from "../../logger";
|
|
1
2
|
import { DuckDBConnection } from "./DuckDBConnection";
|
|
2
3
|
|
|
3
4
|
export async function initializeSchema(
|
|
@@ -11,12 +12,12 @@ export async function initializeSchema(
|
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
if (force) {
|
|
14
|
-
|
|
15
|
+
logger.info(
|
|
15
16
|
"Reinitializing database schema dropping and recreating all tables",
|
|
16
17
|
);
|
|
17
18
|
await dropAllTables(db);
|
|
18
19
|
} else {
|
|
19
|
-
|
|
20
|
+
logger.info("Creating database schema for the first time...");
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
// Projects table
|
|
@@ -75,14 +76,14 @@ export async function initializeSchema(
|
|
|
75
76
|
async function dropAllTables(db: DuckDBConnection): Promise<void> {
|
|
76
77
|
const tables = ["packages", "connections", "projects"];
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
logger.info("Dropping tables:", tables.join(", "));
|
|
79
80
|
|
|
80
81
|
for (const table of tables) {
|
|
81
82
|
try {
|
|
82
83
|
await db.run(`DROP TABLE IF EXISTS ${table} `);
|
|
83
|
-
|
|
84
|
+
logger.info(`Dropped table: ${table}`);
|
|
84
85
|
} catch (err) {
|
|
85
|
-
|
|
86
|
+
logger.warn(` Warning: Could not drop table ${table}:`, err);
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
}
|
package/tests/harness/e2e.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
8
8
|
import http from "http";
|
|
9
9
|
import path from "path";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
10
11
|
import { URL } from "url";
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -30,6 +31,9 @@ export async function startE2E(): Promise<E2EEnv & { stop(): Promise<void> }> {
|
|
|
30
31
|
// 1. Set SERVER_ROOT so ProjectStore loader finds publisher.config.json
|
|
31
32
|
//--------------------------------------------------------------------------
|
|
32
33
|
originalServerRoot = process.env.SERVER_ROOT;
|
|
34
|
+
// Use import.meta.url for cross-platform compatibility (works on Windows)
|
|
35
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
36
|
+
const __dirname = path.dirname(__filename);
|
|
33
37
|
const serverPackageDir = path.resolve(__dirname, "../../../"); // packages/server
|
|
34
38
|
process.env.SERVER_ROOT = serverPackageDir;
|
|
35
39
|
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import http from "http";
|
|
9
9
|
import { AddressInfo } from "net";
|
|
10
10
|
import path from "path";
|
|
11
|
+
import { fileURLToPath } from "url";
|
|
11
12
|
import { URL } from "url";
|
|
12
13
|
|
|
13
14
|
// --- Real Server Import ---
|
|
@@ -31,8 +32,11 @@ export async function setupE2ETestEnvironment(): Promise<McpE2ETestEnvironment>
|
|
|
31
32
|
// --- Store and Set SERVER_ROOT Env Var ---
|
|
32
33
|
// The ProjectStore relies on SERVER_ROOT to find publisher.config.json.
|
|
33
34
|
originalServerRoot = process.env.SERVER_ROOT; // Store original value
|
|
34
|
-
// Resolve the path to 'packages/server' based on the location of this file
|
|
35
|
-
|
|
35
|
+
// Resolve the path to 'packages/server' based on the location of this file
|
|
36
|
+
// Use import.meta.url for cross-platform compatibility (works on Windows)
|
|
37
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
38
|
+
const __dirname = path.dirname(__filename);
|
|
39
|
+
const serverPackageDir = path.resolve(__dirname, "../../"); // Go up two levels from .../packages/server/tests/harness
|
|
36
40
|
process.env.SERVER_ROOT = serverPackageDir;
|
|
37
41
|
console.log(
|
|
38
42
|
`[E2E Test Setup] Temporarily set SERVER_ROOT=${process.env.SERVER_ROOT}`,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as o,j as a,Q as e}from"./index-BoduKqUa.js";function n(){const t=o();return a.jsx(e,{onClickProject:t})}export{n as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{p as n,t,j as e,A as c,J as o}from"./index-BoduKqUa.js";function l(){const{projectName:s,packageName:a}=n(),r=t();if(s)if(a){const i=c({projectName:s,packageName:a});return e.jsx(o,{onClickPackageFile:r,resourceUri:i})}else return e.jsx("div",{children:e.jsx("h2",{children:"Missing package name"})});else return e.jsx("div",{children:e.jsx("h2",{children:"Missing project name"})})}export{l as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as a,p as n,j as e,A as c,E as o}from"./index-BoduKqUa.js";function j(){const t=a(),{projectName:s}=n();if(s){const r=c({projectName:s});return e.jsx(o,{onSelectPackage:t,resourceUri:r})}else return e.jsx("div",{children:e.jsx("h2",{children:"Missing project name"})})}export{j as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{F as o,j as r,z as s,S as n,q as t,T as a}from"./index-BoduKqUa.js";function x(){const e=o();return console.error(e),r.jsx(s,{maxWidth:"lg",component:"main",sx:{display:"flex",flexDirection:"column",my:2,gap:0},children:r.jsxs(n,{sx:{m:"auto",flexDirection:"column"},children:[r.jsx(t,{sx:{height:"300px"}}),r.jsx("img",{src:"/error.png"}),r.jsx(a,{variant:"subtitle1",children:"An unexpected error occurred"})]})})}export{x as default};
|