@malloy-publisher/server 0.0.382-dev → 0.2.0
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 +145 -20
- package/README.md +65 -12
- package/dist/app/api-doc.html +5 -0
- package/dist/app/api-doc.yaml +3903 -583
- package/dist/app/assets/EnvironmentPage-DiUgLuCH.js +1 -0
- package/dist/app/assets/HomePage-MhhjhnFj.js +1 -0
- package/dist/app/assets/LightMode-BEyvNUzT.js +1 -0
- package/dist/app/assets/MainPage-D4Cfee9o.js +2 -0
- package/dist/app/assets/MaterializationsPage-nGgGqwSN.js +1 -0
- package/dist/app/assets/ModelPage-DLAcEw-F.js +1 -0
- package/dist/app/assets/PackagePage-Df0ikH7w.js +1 -0
- package/dist/app/assets/RouteError-BFQwtroH.js +1 -0
- package/dist/app/assets/ThemeEditorPage-OoskoQYN.js +1 -0
- package/dist/app/assets/WorkbookPage-CpFgvUDC.js +1 -0
- package/dist/app/assets/{core-CjeTkq8O.es-BqRc6yhC.js → core-lb28vQkR.es-BoVSOc75.js} +1 -1
- package/dist/app/assets/github-dark-DenFmJkN.es-DHJKELXO.js +1 -0
- package/dist/app/assets/index-5eLCcNmP.css +1 -0
- package/dist/app/assets/index-6ypuFH6g.js +1774 -0
- package/dist/app/assets/index-B8pnU_V_.js +615 -0
- package/dist/app/assets/index-BImcHmVP.js +1 -0
- package/dist/app/assets/index-DSoCUF-f.js +2725 -0
- package/dist/app/assets/index-DfqzSItA.js +2 -0
- package/dist/app/assets/index-w_0OQJgZ.js +23 -0
- package/dist/app/index.html +8 -4
- package/dist/cpufeatures-1yrn0vtw.node +0 -0
- package/dist/default-publisher.config.json +23 -0
- package/dist/{instrumentation.js → instrumentation.mjs} +10631 -10573
- package/dist/package_load_worker.mjs +15219 -0
- package/dist/runtime/publisher.js +331 -0
- package/dist/{server.js → server.mjs} +115548 -49590
- package/dist/sshcrypto-vd2k5hq9.node +0 -0
- package/package.json +41 -28
- package/publisher.config.example.bigquery.json +33 -0
- package/publisher.config.example.duckdb.json +23 -0
- package/.eslintrc.json +0 -44
- package/.prettierignore +0 -1
- package/.prettierrc +0 -4
- package/build.ts +0 -38
- package/dist/app/assets/HomePage-Dn3E4CuB.js +0 -1
- package/dist/app/assets/MainPage-BzB3yoqi.js +0 -2
- package/dist/app/assets/ModelPage-C9O_sAXT.js +0 -1
- package/dist/app/assets/PackagePage-DcxKEjBX.js +0 -1
- package/dist/app/assets/ProjectPage-BDj307rF.js +0 -1
- package/dist/app/assets/RouteError-DAShbVCG.js +0 -1
- package/dist/app/assets/WorkbookPage-Cs_XYEaB.js +0 -1
- package/dist/app/assets/index-15BOvhp0.js +0 -456
- package/dist/app/assets/index-Bb2jqquW.js +0 -676
- package/dist/app/assets/index-CMlGQMcl.css +0 -1
- package/dist/app/assets/index-D68X76-7.js +0 -1276
- package/dist/app/assets/index.umd-DGBekgSu.js +0 -1145
- package/dxt/malloy_bridge.py +0 -354
- package/dxt/manifest.json +0 -22
- package/eslint.config.mjs +0 -76
- package/k6-tests/README.md +0 -144
- package/k6-tests/bun.lock +0 -797
- package/k6-tests/load-test/load-test-crud-connections.ts +0 -263
- package/k6-tests/load-test/load-test-crud-packages.ts +0 -461
- package/k6-tests/load-test/load-test-crud-projects.ts +0 -160
- package/k6-tests/load-test/load-test-crud.ts +0 -142
- package/k6-tests/load-test/load-test.ts +0 -784
- package/k6-tests/package.json +0 -27
- package/k6-tests/scripts/run-with-otel.sh +0 -50
- package/k6-tests/smoke-test/smoke-test.ts +0 -158
- package/k6-tests/tsconfig.json +0 -29
- package/k6-tests/utils/client_factory.ts +0 -128
- package/k6-tests/utils/common.ts +0 -489
- package/k6-tests/utils/logger.ts +0 -62
- package/k6-tests/utils/types.d.ts +0 -35
- package/malloy_mcp.dxt +0 -0
- package/publisher.config.json +0 -33
- package/src/config.spec.ts +0 -850
- package/src/config.ts +0 -305
- package/src/constants.ts +0 -10
- package/src/controller/compile.controller.ts +0 -35
- package/src/controller/connection.controller.ts +0 -515
- package/src/controller/database.controller.ts +0 -21
- package/src/controller/manifest.controller.ts +0 -29
- package/src/controller/materialization.controller.ts +0 -125
- package/src/controller/model.controller.ts +0 -107
- package/src/controller/package.controller.ts +0 -182
- package/src/controller/query.controller.ts +0 -60
- package/src/controller/watch-mode.controller.ts +0 -98
- package/src/data_styles.ts +0 -71
- package/src/dto/connection.dto.spec.ts +0 -131
- package/src/dto/connection.dto.ts +0 -174
- package/src/dto/index.ts +0 -2
- package/src/dto/package.dto.spec.ts +0 -42
- package/src/dto/package.dto.ts +0 -12
- package/src/dto/validate.spec.ts +0 -76
- package/src/dto/validate.ts +0 -31
- package/src/errors.ts +0 -116
- package/src/health.ts +0 -189
- package/src/instrumentation.ts +0 -148
- package/src/logger.ts +0 -154
- package/src/mcp/error_messages.ts +0 -199
- package/src/mcp/handler_utils.ts +0 -239
- package/src/mcp/mcp_constants.ts +0 -22
- package/src/mcp/prompts/handlers.ts +0 -84
- package/src/mcp/prompts/index.ts +0 -11
- package/src/mcp/prompts/prompt_definitions.ts +0 -160
- package/src/mcp/prompts/prompt_service.ts +0 -67
- package/src/mcp/prompts/utils.ts +0 -62
- package/src/mcp/resource_metadata.ts +0 -47
- package/src/mcp/resources/model_resource.ts +0 -153
- package/src/mcp/resources/notebook_resource.ts +0 -137
- package/src/mcp/resources/package_resource.ts +0 -370
- package/src/mcp/resources/project_resource.ts +0 -184
- package/src/mcp/resources/query_resource.ts +0 -117
- package/src/mcp/resources/source_resource.ts +0 -141
- package/src/mcp/resources/view_resource.ts +0 -136
- package/src/mcp/server.ts +0 -62
- package/src/mcp/tools/discovery_tools.ts +0 -258
- package/src/mcp/tools/execute_query_tool.ts +0 -265
- package/src/server.ts +0 -1195
- package/src/service/connection.spec.ts +0 -1331
- package/src/service/connection.ts +0 -1511
- package/src/service/connection_service.spec.ts +0 -641
- package/src/service/connection_service.ts +0 -181
- package/src/service/db_utils.spec.ts +0 -714
- package/src/service/db_utils.ts +0 -1227
- package/src/service/filter.spec.ts +0 -447
- package/src/service/filter.ts +0 -337
- package/src/service/filter_integration.spec.ts +0 -825
- package/src/service/gcs_s3_utils.ts +0 -427
- package/src/service/manifest_service.spec.ts +0 -201
- package/src/service/manifest_service.ts +0 -106
- package/src/service/materialization_service.spec.ts +0 -648
- package/src/service/materialization_service.ts +0 -929
- package/src/service/materialized_table_gc.spec.ts +0 -383
- package/src/service/materialized_table_gc.ts +0 -279
- package/src/service/model.spec.ts +0 -257
- package/src/service/model.ts +0 -1069
- package/src/service/package.spec.ts +0 -236
- package/src/service/package.ts +0 -463
- package/src/service/project.ts +0 -681
- package/src/service/project_compile.spec.ts +0 -197
- package/src/service/project_store.spec.ts +0 -859
- package/src/service/project_store.ts +0 -1531
- package/src/service/quoting.ts +0 -41
- package/src/service/resolve_project.ts +0 -13
- package/src/storage/BaseRepository.ts +0 -31
- package/src/storage/DatabaseInterface.ts +0 -180
- package/src/storage/StorageManager.mock.ts +0 -59
- package/src/storage/StorageManager.ts +0 -210
- package/src/storage/duckdb/ConnectionRepository.ts +0 -141
- package/src/storage/duckdb/DuckDBConnection.ts +0 -177
- package/src/storage/duckdb/DuckDBManifestStore.ts +0 -70
- package/src/storage/duckdb/DuckDBRepository.ts +0 -224
- package/src/storage/duckdb/ManifestRepository.ts +0 -119
- package/src/storage/duckdb/MaterializationRepository.ts +0 -249
- package/src/storage/duckdb/PackageRepository.ts +0 -135
- package/src/storage/duckdb/ProjectRepository.ts +0 -148
- package/src/storage/duckdb/manifest_store.spec.ts +0 -133
- package/src/storage/duckdb/schema.ts +0 -147
- package/src/storage/ducklake/DuckLakeManifestStore.ts +0 -146
- package/src/utils.ts +0 -13
- package/tests/fixtures/persist-test/data/orders.csv +0 -5
- package/tests/fixtures/persist-test/persist_test.malloy +0 -11
- package/tests/fixtures/persist-test/publisher.json +0 -5
- package/tests/fixtures/publisher.config.json +0 -15
- package/tests/harness/e2e.ts +0 -96
- package/tests/harness/mcp_test_setup.ts +0 -344
- package/tests/harness/mocks.ts +0 -37
- package/tests/harness/rest_e2e.ts +0 -68
- package/tests/harness/uris.ts +0 -31
- package/tests/integration/materialization/materialization_lifecycle.integration.spec.ts +0 -470
- package/tests/integration/mcp/mcp_execute_query_tool.integration.spec.ts +0 -434
- package/tests/integration/mcp/mcp_resource.integration.spec.ts +0 -663
- package/tests/integration/mcp/mcp_transport.integration.spec.ts +0 -122
- package/tests/integration/mcp/setup.spec.ts +0 -5
- package/tests/unit/duckdb/attached_databases.test.ts +0 -1132
- package/tests/unit/ducklake/ducklake.test.ts +0 -950
- package/tests/unit/mcp/prompt_definitions.test.ts +0 -102
- package/tests/unit/mcp/prompt_happy.test.ts +0 -51
- package/tsconfig.json +0 -32
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ListBucketsCommand,
|
|
3
|
-
ListObjectsV2Command,
|
|
4
|
-
S3Client,
|
|
5
|
-
} from "@aws-sdk/client-s3";
|
|
6
|
-
import { Connection } from "@malloydata/malloy";
|
|
7
|
-
import { components } from "../api";
|
|
8
|
-
import { logger } from "../logger";
|
|
9
|
-
|
|
10
|
-
type ApiTable = components["schemas"]["Table"];
|
|
11
|
-
type CloudStorageType = "gcs" | "s3";
|
|
12
|
-
|
|
13
|
-
export interface CloudStorageCredentials {
|
|
14
|
-
type: CloudStorageType;
|
|
15
|
-
accessKeyId: string;
|
|
16
|
-
secretAccessKey: string;
|
|
17
|
-
region?: string;
|
|
18
|
-
endpoint?: string;
|
|
19
|
-
sessionToken?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface CloudStorageBucket {
|
|
23
|
-
name: string;
|
|
24
|
-
creationDate?: Date;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface CloudStorageObject {
|
|
28
|
-
key: string;
|
|
29
|
-
size?: number;
|
|
30
|
-
lastModified?: Date;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function gcsConnectionToCredentials(gcsConnection: {
|
|
34
|
-
keyId?: string;
|
|
35
|
-
secret?: string;
|
|
36
|
-
}): CloudStorageCredentials {
|
|
37
|
-
return {
|
|
38
|
-
type: "gcs",
|
|
39
|
-
accessKeyId: gcsConnection.keyId || "",
|
|
40
|
-
secretAccessKey: gcsConnection.secret || "",
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function s3ConnectionToCredentials(s3Connection: {
|
|
45
|
-
accessKeyId?: string;
|
|
46
|
-
secretAccessKey?: string;
|
|
47
|
-
region?: string;
|
|
48
|
-
endpoint?: string;
|
|
49
|
-
sessionToken?: string;
|
|
50
|
-
}): CloudStorageCredentials {
|
|
51
|
-
return {
|
|
52
|
-
type: "s3",
|
|
53
|
-
accessKeyId: s3Connection.accessKeyId || "",
|
|
54
|
-
secretAccessKey: s3Connection.secretAccessKey || "",
|
|
55
|
-
region: s3Connection.region,
|
|
56
|
-
endpoint: s3Connection.endpoint,
|
|
57
|
-
sessionToken: s3Connection.sessionToken,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function createCloudStorageClient(
|
|
62
|
-
credentials: CloudStorageCredentials,
|
|
63
|
-
): S3Client {
|
|
64
|
-
const isGCS = credentials.type === "gcs";
|
|
65
|
-
|
|
66
|
-
const client = new S3Client({
|
|
67
|
-
endpoint: isGCS ? "https://storage.googleapis.com" : credentials.endpoint,
|
|
68
|
-
region: isGCS ? "auto" : credentials.region || "us-east-1",
|
|
69
|
-
credentials: {
|
|
70
|
-
accessKeyId: credentials.accessKeyId,
|
|
71
|
-
secretAccessKey: credentials.secretAccessKey,
|
|
72
|
-
sessionToken: credentials.sessionToken,
|
|
73
|
-
},
|
|
74
|
-
forcePathStyle: isGCS || !!credentials.endpoint,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
if (isGCS) {
|
|
78
|
-
client.middlewareStack.add(
|
|
79
|
-
(next) => async (args) => {
|
|
80
|
-
const request = args.request as { query?: Record<string, string> };
|
|
81
|
-
if (request.query) {
|
|
82
|
-
delete request.query["x-id"];
|
|
83
|
-
}
|
|
84
|
-
return next(args);
|
|
85
|
-
},
|
|
86
|
-
{ step: "build", name: "removeXIdParam" },
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return client;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function listCloudBuckets(
|
|
94
|
-
credentials: CloudStorageCredentials,
|
|
95
|
-
): Promise<CloudStorageBucket[]> {
|
|
96
|
-
const client = createCloudStorageClient(credentials);
|
|
97
|
-
const storageType = credentials.type.toUpperCase();
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
const response = await client.send(new ListBucketsCommand({}));
|
|
101
|
-
return (response.Buckets || []).map((bucket) => ({
|
|
102
|
-
name: bucket.Name || "",
|
|
103
|
-
creationDate: bucket.CreationDate,
|
|
104
|
-
}));
|
|
105
|
-
} catch (error) {
|
|
106
|
-
logger.error(`Failed to list ${storageType} buckets`, { error });
|
|
107
|
-
throw new Error(
|
|
108
|
-
`Failed to list ${storageType} buckets: ${error instanceof Error ? error.message : String(error)}`,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Flat listing with pagination - much faster than recursive DFS
|
|
114
|
-
// Makes only O(total_files / 1000) API calls instead of O(num_folders)
|
|
115
|
-
async function listAllCloudFiles(
|
|
116
|
-
credentials: CloudStorageCredentials,
|
|
117
|
-
bucket: string,
|
|
118
|
-
prefix: string = "",
|
|
119
|
-
): Promise<CloudStorageObject[]> {
|
|
120
|
-
const client = createCloudStorageClient(credentials);
|
|
121
|
-
const storageType = credentials.type.toUpperCase();
|
|
122
|
-
const allFiles: CloudStorageObject[] = [];
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
let continuationToken: string | undefined;
|
|
126
|
-
|
|
127
|
-
// Paginate through all objects (1000 per page)
|
|
128
|
-
do {
|
|
129
|
-
const response = await client.send(
|
|
130
|
-
new ListObjectsV2Command({
|
|
131
|
-
Bucket: bucket,
|
|
132
|
-
Prefix: prefix,
|
|
133
|
-
ContinuationToken: continuationToken,
|
|
134
|
-
// No Delimiter = flat listing of ALL objects
|
|
135
|
-
}),
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
for (const content of response.Contents || []) {
|
|
139
|
-
if (content.Key) {
|
|
140
|
-
allFiles.push({
|
|
141
|
-
key: content.Key,
|
|
142
|
-
size: content.Size,
|
|
143
|
-
lastModified: content.LastModified,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
continuationToken = response.IsTruncated
|
|
149
|
-
? response.NextContinuationToken
|
|
150
|
-
: undefined;
|
|
151
|
-
} while (continuationToken);
|
|
152
|
-
|
|
153
|
-
logger.info(
|
|
154
|
-
`Listed ${allFiles.length} files in ${storageType} bucket ${bucket}`,
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
return allFiles;
|
|
158
|
-
} catch (error) {
|
|
159
|
-
logger.error(
|
|
160
|
-
`Failed to list ${storageType} objects in bucket ${bucket}`,
|
|
161
|
-
{
|
|
162
|
-
error,
|
|
163
|
-
},
|
|
164
|
-
);
|
|
165
|
-
throw new Error(
|
|
166
|
-
`Failed to list objects in ${storageType} bucket ${bucket}: ${error instanceof Error ? error.message : String(error)}`,
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function isDataFile(key: string): boolean {
|
|
172
|
-
const lowerKey = key.toLowerCase();
|
|
173
|
-
return (
|
|
174
|
-
lowerKey.endsWith(".csv") ||
|
|
175
|
-
lowerKey.endsWith(".parquet") ||
|
|
176
|
-
lowerKey.endsWith(".json") ||
|
|
177
|
-
lowerKey.endsWith(".jsonl") ||
|
|
178
|
-
lowerKey.endsWith(".ndjson")
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function buildCloudUri(
|
|
183
|
-
type: CloudStorageType,
|
|
184
|
-
bucket: string,
|
|
185
|
-
key: string,
|
|
186
|
-
): string {
|
|
187
|
-
const scheme = type === "gcs" ? "gs" : "s3";
|
|
188
|
-
return `${scheme}://${bucket}/${key}`;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function getFileType(key: string): string {
|
|
192
|
-
const lowerKey = key.toLowerCase();
|
|
193
|
-
if (lowerKey.endsWith(".csv")) return "csv";
|
|
194
|
-
if (lowerKey.endsWith(".parquet")) return "parquet";
|
|
195
|
-
if (lowerKey.endsWith(".json")) return "json";
|
|
196
|
-
if (lowerKey.endsWith(".jsonl") || lowerKey.endsWith(".ndjson"))
|
|
197
|
-
return "jsonl";
|
|
198
|
-
return "unknown";
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function standardizeRunSQLResult(result: unknown): unknown[] {
|
|
202
|
-
return Array.isArray(result)
|
|
203
|
-
? result
|
|
204
|
-
: (result as { rows?: unknown[] }).rows || [];
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const SCHEMA_FETCH_BATCH_SIZE = 10;
|
|
208
|
-
const BUCKET_SCAN_BATCH_SIZE = 3;
|
|
209
|
-
|
|
210
|
-
async function getTableSchema(
|
|
211
|
-
malloyConnection: Connection,
|
|
212
|
-
credentials: CloudStorageCredentials,
|
|
213
|
-
bucketName: string,
|
|
214
|
-
fileKey: string,
|
|
215
|
-
): Promise<ApiTable> {
|
|
216
|
-
const uri = buildCloudUri(credentials.type, bucketName, fileKey);
|
|
217
|
-
const fileType = getFileType(fileKey);
|
|
218
|
-
|
|
219
|
-
try {
|
|
220
|
-
let describeQuery: string;
|
|
221
|
-
|
|
222
|
-
switch (fileType) {
|
|
223
|
-
case "csv":
|
|
224
|
-
describeQuery = `DESCRIBE SELECT * FROM read_csv('${uri}', auto_detect=true) LIMIT 1`;
|
|
225
|
-
break;
|
|
226
|
-
case "parquet":
|
|
227
|
-
describeQuery = `DESCRIBE SELECT * FROM read_parquet('${uri}') LIMIT 1`;
|
|
228
|
-
break;
|
|
229
|
-
case "json":
|
|
230
|
-
describeQuery = `DESCRIBE SELECT * FROM read_json('${uri}', auto_detect=true) LIMIT 1`;
|
|
231
|
-
break;
|
|
232
|
-
case "jsonl":
|
|
233
|
-
describeQuery = `DESCRIBE SELECT * FROM read_json('${uri}', format='newline_delimited', auto_detect=true) LIMIT 1`;
|
|
234
|
-
break;
|
|
235
|
-
default:
|
|
236
|
-
logger.warn(`Unsupported file type for ${fileKey}`);
|
|
237
|
-
return { resource: uri, columns: [] };
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const result = await malloyConnection.runSQL(describeQuery);
|
|
241
|
-
const rows = standardizeRunSQLResult(result);
|
|
242
|
-
const columns = rows.map((row: unknown) => {
|
|
243
|
-
const typedRow = row as Record<string, unknown>;
|
|
244
|
-
return {
|
|
245
|
-
name: (typedRow.column_name || typedRow.name) as string,
|
|
246
|
-
type: (typedRow.column_type || typedRow.type) as string,
|
|
247
|
-
};
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
return { resource: uri, columns };
|
|
251
|
-
} catch (error) {
|
|
252
|
-
logger.warn(
|
|
253
|
-
`Failed to get schema for ${credentials.type.toUpperCase()} file: ${uri}`,
|
|
254
|
-
{ error },
|
|
255
|
-
);
|
|
256
|
-
return { resource: uri, columns: [] };
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export async function getCloudTablesWithColumns(
|
|
261
|
-
malloyConnection: Connection,
|
|
262
|
-
credentials: CloudStorageCredentials,
|
|
263
|
-
bucketName: string,
|
|
264
|
-
fileKeys: string[],
|
|
265
|
-
): Promise<ApiTable[]> {
|
|
266
|
-
const allTables: ApiTable[] = [];
|
|
267
|
-
|
|
268
|
-
for (let i = 0; i < fileKeys.length; i += SCHEMA_FETCH_BATCH_SIZE) {
|
|
269
|
-
const batch = fileKeys.slice(i, i + SCHEMA_FETCH_BATCH_SIZE);
|
|
270
|
-
|
|
271
|
-
const batchResults = await Promise.all(
|
|
272
|
-
batch.map((fileKey) =>
|
|
273
|
-
getTableSchema(malloyConnection, credentials, bucketName, fileKey),
|
|
274
|
-
),
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
allTables.push(...batchResults);
|
|
278
|
-
|
|
279
|
-
logger.info(
|
|
280
|
-
`Processed batch ${Math.floor(i / SCHEMA_FETCH_BATCH_SIZE) + 1}/${Math.ceil(fileKeys.length / SCHEMA_FETCH_BATCH_SIZE)} (${allTables.length}/${fileKeys.length} files)`,
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return allTables;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
export function parseCloudUri(uri: string): {
|
|
288
|
-
type: CloudStorageType;
|
|
289
|
-
bucket: string;
|
|
290
|
-
path: string;
|
|
291
|
-
} | null {
|
|
292
|
-
const gsMatch = uri.match(/^gs:\/\/([^/]+)(?:\/(.*))?$/);
|
|
293
|
-
if (gsMatch) {
|
|
294
|
-
return {
|
|
295
|
-
type: "gcs",
|
|
296
|
-
bucket: gsMatch[1],
|
|
297
|
-
path: gsMatch[2] || "",
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const s3Match = uri.match(/^s3:\/\/([^/]+)(?:\/(.*))?$/);
|
|
302
|
-
if (s3Match) {
|
|
303
|
-
return {
|
|
304
|
-
type: "s3",
|
|
305
|
-
bucket: s3Match[1],
|
|
306
|
-
path: s3Match[2] || "",
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return null;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
export async function listDataFilesInDirectory(
|
|
314
|
-
credentials: CloudStorageCredentials,
|
|
315
|
-
bucketName: string,
|
|
316
|
-
directoryPath: string,
|
|
317
|
-
): Promise<string[]> {
|
|
318
|
-
const prefix = directoryPath ? `${directoryPath}/` : "";
|
|
319
|
-
const client = createCloudStorageClient(credentials);
|
|
320
|
-
const storageType = credentials.type.toUpperCase();
|
|
321
|
-
const dataFiles: string[] = [];
|
|
322
|
-
|
|
323
|
-
try {
|
|
324
|
-
let continuationToken: string | undefined;
|
|
325
|
-
|
|
326
|
-
do {
|
|
327
|
-
const response = await client.send(
|
|
328
|
-
new ListObjectsV2Command({
|
|
329
|
-
Bucket: bucketName,
|
|
330
|
-
Prefix: prefix,
|
|
331
|
-
Delimiter: "/",
|
|
332
|
-
ContinuationToken: continuationToken,
|
|
333
|
-
}),
|
|
334
|
-
);
|
|
335
|
-
|
|
336
|
-
for (const content of response.Contents || []) {
|
|
337
|
-
if (content.Key && isDataFile(content.Key)) {
|
|
338
|
-
dataFiles.push(content.Key);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
continuationToken = response.IsTruncated
|
|
343
|
-
? response.NextContinuationToken
|
|
344
|
-
: undefined;
|
|
345
|
-
} while (continuationToken);
|
|
346
|
-
|
|
347
|
-
logger.info(
|
|
348
|
-
`Listed ${dataFiles.length} data files in ${storageType} ${bucketName}/${directoryPath}`,
|
|
349
|
-
);
|
|
350
|
-
return dataFiles;
|
|
351
|
-
} catch (error) {
|
|
352
|
-
logger.error(
|
|
353
|
-
`Failed to list files in ${storageType} ${bucketName}/${directoryPath}`,
|
|
354
|
-
{ error },
|
|
355
|
-
);
|
|
356
|
-
throw new Error(
|
|
357
|
-
`Failed to list files in ${storageType} ${bucketName}/${directoryPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Scans an entire bucket and returns unique directory paths that contain data files.
|
|
364
|
-
* Uses flat listing for efficiency — O(total_files / 1000) API calls.
|
|
365
|
-
*/
|
|
366
|
-
async function listDirectorySchemas(
|
|
367
|
-
credentials: CloudStorageCredentials,
|
|
368
|
-
bucketName: string,
|
|
369
|
-
): Promise<string[]> {
|
|
370
|
-
const allFiles = await listAllCloudFiles(credentials, bucketName);
|
|
371
|
-
const directories = new Set<string>();
|
|
372
|
-
|
|
373
|
-
for (const file of allFiles) {
|
|
374
|
-
if (!isDataFile(file.key)) continue;
|
|
375
|
-
|
|
376
|
-
const lastSlashIndex = file.key.lastIndexOf("/");
|
|
377
|
-
const dir =
|
|
378
|
-
lastSlashIndex > 0 ? file.key.substring(0, lastSlashIndex) : "";
|
|
379
|
-
directories.add(dir);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
const scheme = credentials.type === "gcs" ? "gs" : "s3";
|
|
383
|
-
const sortedDirs = Array.from(directories).sort();
|
|
384
|
-
|
|
385
|
-
logger.info(
|
|
386
|
-
`Found ${sortedDirs.length} directories with data files in ${credentials.type.toUpperCase()} bucket ${bucketName}`,
|
|
387
|
-
);
|
|
388
|
-
|
|
389
|
-
return sortedDirs.map((dir) =>
|
|
390
|
-
dir ? `${scheme}://${bucketName}/${dir}` : `${scheme}://${bucketName}`,
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
export async function listCloudDirectorySchemas(
|
|
395
|
-
credentials: CloudStorageCredentials,
|
|
396
|
-
): Promise<{ name: string; isHidden: boolean; isDefault: boolean }[]> {
|
|
397
|
-
const storageType = credentials.type.toUpperCase();
|
|
398
|
-
const buckets = await listCloudBuckets(credentials);
|
|
399
|
-
|
|
400
|
-
logger.info(
|
|
401
|
-
`Listed ${buckets.length} ${storageType} buckets, scanning for directories...`,
|
|
402
|
-
);
|
|
403
|
-
|
|
404
|
-
const allDirArrays: string[][] = [];
|
|
405
|
-
|
|
406
|
-
for (let i = 0; i < buckets.length; i += BUCKET_SCAN_BATCH_SIZE) {
|
|
407
|
-
const batch = buckets.slice(i, i + BUCKET_SCAN_BATCH_SIZE);
|
|
408
|
-
const batchResults = await Promise.all(
|
|
409
|
-
batch.map((bucket) =>
|
|
410
|
-
listDirectorySchemas(credentials, bucket.name).catch((err) => {
|
|
411
|
-
logger.warn(
|
|
412
|
-
`Failed to scan ${storageType} bucket ${bucket.name}`,
|
|
413
|
-
{ error: err },
|
|
414
|
-
);
|
|
415
|
-
return [] as string[];
|
|
416
|
-
}),
|
|
417
|
-
),
|
|
418
|
-
);
|
|
419
|
-
allDirArrays.push(...batchResults);
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
return allDirArrays.flat().map((dirUri) => ({
|
|
423
|
-
name: dirUri,
|
|
424
|
-
isHidden: false,
|
|
425
|
-
isDefault: false,
|
|
426
|
-
}));
|
|
427
|
-
}
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it } from "bun:test";
|
|
2
|
-
import * as sinon from "sinon";
|
|
3
|
-
import {
|
|
4
|
-
BuildManifest,
|
|
5
|
-
ManifestEntry,
|
|
6
|
-
ManifestStore,
|
|
7
|
-
ResourceRepository,
|
|
8
|
-
} from "../storage/DatabaseInterface";
|
|
9
|
-
import { ManifestService } from "./manifest_service";
|
|
10
|
-
import { ProjectStore } from "./project_store";
|
|
11
|
-
|
|
12
|
-
function makeEntry(overrides: Partial<ManifestEntry> = {}): ManifestEntry {
|
|
13
|
-
return {
|
|
14
|
-
id: "entry-1",
|
|
15
|
-
projectId: "proj-1",
|
|
16
|
-
packageName: "pkg",
|
|
17
|
-
buildId: "build-abc",
|
|
18
|
-
tableName: "my_table",
|
|
19
|
-
sourceName: "my_source",
|
|
20
|
-
connectionName: "duckdb",
|
|
21
|
-
createdAt: new Date("2025-01-01"),
|
|
22
|
-
updatedAt: new Date("2025-01-01"),
|
|
23
|
-
...overrides,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function createMocks() {
|
|
28
|
-
const sandbox = sinon.createSandbox();
|
|
29
|
-
|
|
30
|
-
const manifestStore: sinon.SinonStubbedInstance<ManifestStore> = {
|
|
31
|
-
getManifest: sandbox.stub(),
|
|
32
|
-
writeEntry: sandbox.stub(),
|
|
33
|
-
deleteEntry: sandbox.stub(),
|
|
34
|
-
listEntries: sandbox.stub(),
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const repository = {
|
|
38
|
-
listManifestEntries: sandbox.stub(),
|
|
39
|
-
} as unknown as sinon.SinonStubbedInstance<ResourceRepository>;
|
|
40
|
-
|
|
41
|
-
const reloadAllModels = sandbox.stub().resolves();
|
|
42
|
-
|
|
43
|
-
const pkg = {
|
|
44
|
-
reloadAllModels,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const project = {
|
|
48
|
-
getPackage: sandbox.stub().resolves(pkg),
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const projectStore = {
|
|
52
|
-
storageManager: {
|
|
53
|
-
getManifestStore: (_projectId?: string) => manifestStore,
|
|
54
|
-
getRepository: () => repository,
|
|
55
|
-
},
|
|
56
|
-
getProject: sandbox.stub().resolves(project),
|
|
57
|
-
} as unknown as ProjectStore;
|
|
58
|
-
|
|
59
|
-
const service = new ManifestService(projectStore);
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
sandbox,
|
|
63
|
-
manifestStore,
|
|
64
|
-
repository,
|
|
65
|
-
projectStore,
|
|
66
|
-
project,
|
|
67
|
-
pkg,
|
|
68
|
-
reloadAllModels,
|
|
69
|
-
service,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
describe("ManifestService", () => {
|
|
74
|
-
let ctx: ReturnType<typeof createMocks>;
|
|
75
|
-
|
|
76
|
-
beforeEach(() => {
|
|
77
|
-
ctx = createMocks();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe("getManifest", () => {
|
|
81
|
-
it("should delegate to the manifest store", async () => {
|
|
82
|
-
const manifest: BuildManifest = {
|
|
83
|
-
entries: { "build-abc": { tableName: "tbl" } },
|
|
84
|
-
strict: false,
|
|
85
|
-
};
|
|
86
|
-
ctx.manifestStore.getManifest.resolves(manifest);
|
|
87
|
-
|
|
88
|
-
const result = await ctx.service.getManifest("proj-1", "pkg");
|
|
89
|
-
|
|
90
|
-
expect(result).toEqual(manifest);
|
|
91
|
-
expect(ctx.manifestStore.getManifest.calledWith("proj-1", "pkg")).toBe(
|
|
92
|
-
true,
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe("writeEntry", () => {
|
|
98
|
-
it("should delegate to the manifest store", async () => {
|
|
99
|
-
ctx.manifestStore.writeEntry.resolves();
|
|
100
|
-
|
|
101
|
-
await ctx.service.writeEntry(
|
|
102
|
-
"proj-1",
|
|
103
|
-
"pkg",
|
|
104
|
-
"build-abc",
|
|
105
|
-
"tbl",
|
|
106
|
-
"src",
|
|
107
|
-
"duckdb",
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
expect(ctx.manifestStore.writeEntry.calledOnce).toBe(true);
|
|
111
|
-
const args = ctx.manifestStore.writeEntry.firstCall.args;
|
|
112
|
-
expect(args[0]).toBe("proj-1");
|
|
113
|
-
expect(args[1]).toBe("pkg");
|
|
114
|
-
expect(args[2]).toBe("build-abc");
|
|
115
|
-
expect(args[3]).toBe("tbl");
|
|
116
|
-
expect(args[4]).toBe("src");
|
|
117
|
-
expect(args[5]).toBe("duckdb");
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe("deleteEntry", () => {
|
|
122
|
-
it("should delegate to the manifest store", async () => {
|
|
123
|
-
ctx.manifestStore.deleteEntry.resolves();
|
|
124
|
-
|
|
125
|
-
await ctx.service.deleteEntry("proj-1", "entry-1");
|
|
126
|
-
|
|
127
|
-
expect(ctx.manifestStore.deleteEntry.calledOnce).toBe(true);
|
|
128
|
-
expect(ctx.manifestStore.deleteEntry.firstCall.args[0]).toBe(
|
|
129
|
-
"entry-1",
|
|
130
|
-
);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe("reloadManifest", () => {
|
|
135
|
-
it("should get manifest, reload it onto the package, and return it", async () => {
|
|
136
|
-
const manifest: BuildManifest = {
|
|
137
|
-
entries: { "build-abc": { tableName: "tbl" } },
|
|
138
|
-
strict: false,
|
|
139
|
-
};
|
|
140
|
-
ctx.manifestStore.getManifest.resolves(manifest);
|
|
141
|
-
|
|
142
|
-
const result = await ctx.service.reloadManifest(
|
|
143
|
-
"proj-1",
|
|
144
|
-
"pkg",
|
|
145
|
-
"my-project",
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
expect(result).toEqual(manifest);
|
|
149
|
-
expect(
|
|
150
|
-
(ctx.projectStore.getProject as sinon.SinonStub).calledWith(
|
|
151
|
-
"my-project",
|
|
152
|
-
false,
|
|
153
|
-
),
|
|
154
|
-
).toBe(true);
|
|
155
|
-
expect(ctx.project.getPackage.calledWith("pkg", false)).toBe(true);
|
|
156
|
-
expect(ctx.reloadAllModels.calledWith(manifest.entries)).toBe(true);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("should return an empty manifest when no entries exist", async () => {
|
|
160
|
-
const emptyManifest: BuildManifest = {
|
|
161
|
-
entries: {},
|
|
162
|
-
strict: false,
|
|
163
|
-
};
|
|
164
|
-
ctx.manifestStore.getManifest.resolves(emptyManifest);
|
|
165
|
-
|
|
166
|
-
const result = await ctx.service.reloadManifest(
|
|
167
|
-
"proj-1",
|
|
168
|
-
"pkg",
|
|
169
|
-
"my-project",
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
expect(result.entries).toEqual({});
|
|
173
|
-
expect(ctx.reloadAllModels.calledWith({})).toBe(true);
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
describe("listEntries", () => {
|
|
178
|
-
it("should return entries from the manifest store", async () => {
|
|
179
|
-
const entries = [
|
|
180
|
-
makeEntry(),
|
|
181
|
-
makeEntry({ id: "entry-2", buildId: "build-def" }),
|
|
182
|
-
];
|
|
183
|
-
ctx.manifestStore.listEntries.resolves(entries);
|
|
184
|
-
|
|
185
|
-
const result = await ctx.service.listEntries("proj-1", "pkg");
|
|
186
|
-
|
|
187
|
-
expect(result).toEqual(entries);
|
|
188
|
-
expect(ctx.manifestStore.listEntries.calledWith("proj-1", "pkg")).toBe(
|
|
189
|
-
true,
|
|
190
|
-
);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("should return empty array when no entries exist", async () => {
|
|
194
|
-
ctx.manifestStore.listEntries.resolves([]);
|
|
195
|
-
|
|
196
|
-
const result = await ctx.service.listEntries("proj-1", "pkg");
|
|
197
|
-
|
|
198
|
-
expect(result).toEqual([]);
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
});
|