@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.
Files changed (175) hide show
  1. package/README.docker.md +145 -20
  2. package/README.md +65 -12
  3. package/dist/app/api-doc.html +5 -0
  4. package/dist/app/api-doc.yaml +3903 -583
  5. package/dist/app/assets/EnvironmentPage-DiUgLuCH.js +1 -0
  6. package/dist/app/assets/HomePage-MhhjhnFj.js +1 -0
  7. package/dist/app/assets/LightMode-BEyvNUzT.js +1 -0
  8. package/dist/app/assets/MainPage-D4Cfee9o.js +2 -0
  9. package/dist/app/assets/MaterializationsPage-nGgGqwSN.js +1 -0
  10. package/dist/app/assets/ModelPage-DLAcEw-F.js +1 -0
  11. package/dist/app/assets/PackagePage-Df0ikH7w.js +1 -0
  12. package/dist/app/assets/RouteError-BFQwtroH.js +1 -0
  13. package/dist/app/assets/ThemeEditorPage-OoskoQYN.js +1 -0
  14. package/dist/app/assets/WorkbookPage-CpFgvUDC.js +1 -0
  15. package/dist/app/assets/{core-CjeTkq8O.es-BqRc6yhC.js → core-lb28vQkR.es-BoVSOc75.js} +1 -1
  16. package/dist/app/assets/github-dark-DenFmJkN.es-DHJKELXO.js +1 -0
  17. package/dist/app/assets/index-5eLCcNmP.css +1 -0
  18. package/dist/app/assets/index-6ypuFH6g.js +1774 -0
  19. package/dist/app/assets/index-B8pnU_V_.js +615 -0
  20. package/dist/app/assets/index-BImcHmVP.js +1 -0
  21. package/dist/app/assets/index-DSoCUF-f.js +2725 -0
  22. package/dist/app/assets/index-DfqzSItA.js +2 -0
  23. package/dist/app/assets/index-w_0OQJgZ.js +23 -0
  24. package/dist/app/index.html +8 -4
  25. package/dist/cpufeatures-1yrn0vtw.node +0 -0
  26. package/dist/default-publisher.config.json +23 -0
  27. package/dist/{instrumentation.js → instrumentation.mjs} +10631 -10573
  28. package/dist/package_load_worker.mjs +15219 -0
  29. package/dist/runtime/publisher.js +331 -0
  30. package/dist/{server.js → server.mjs} +115548 -49590
  31. package/dist/sshcrypto-vd2k5hq9.node +0 -0
  32. package/package.json +41 -28
  33. package/publisher.config.example.bigquery.json +33 -0
  34. package/publisher.config.example.duckdb.json +23 -0
  35. package/.eslintrc.json +0 -44
  36. package/.prettierignore +0 -1
  37. package/.prettierrc +0 -4
  38. package/build.ts +0 -38
  39. package/dist/app/assets/HomePage-Dn3E4CuB.js +0 -1
  40. package/dist/app/assets/MainPage-BzB3yoqi.js +0 -2
  41. package/dist/app/assets/ModelPage-C9O_sAXT.js +0 -1
  42. package/dist/app/assets/PackagePage-DcxKEjBX.js +0 -1
  43. package/dist/app/assets/ProjectPage-BDj307rF.js +0 -1
  44. package/dist/app/assets/RouteError-DAShbVCG.js +0 -1
  45. package/dist/app/assets/WorkbookPage-Cs_XYEaB.js +0 -1
  46. package/dist/app/assets/index-15BOvhp0.js +0 -456
  47. package/dist/app/assets/index-Bb2jqquW.js +0 -676
  48. package/dist/app/assets/index-CMlGQMcl.css +0 -1
  49. package/dist/app/assets/index-D68X76-7.js +0 -1276
  50. package/dist/app/assets/index.umd-DGBekgSu.js +0 -1145
  51. package/dxt/malloy_bridge.py +0 -354
  52. package/dxt/manifest.json +0 -22
  53. package/eslint.config.mjs +0 -76
  54. package/k6-tests/README.md +0 -144
  55. package/k6-tests/bun.lock +0 -797
  56. package/k6-tests/load-test/load-test-crud-connections.ts +0 -263
  57. package/k6-tests/load-test/load-test-crud-packages.ts +0 -461
  58. package/k6-tests/load-test/load-test-crud-projects.ts +0 -160
  59. package/k6-tests/load-test/load-test-crud.ts +0 -142
  60. package/k6-tests/load-test/load-test.ts +0 -784
  61. package/k6-tests/package.json +0 -27
  62. package/k6-tests/scripts/run-with-otel.sh +0 -50
  63. package/k6-tests/smoke-test/smoke-test.ts +0 -158
  64. package/k6-tests/tsconfig.json +0 -29
  65. package/k6-tests/utils/client_factory.ts +0 -128
  66. package/k6-tests/utils/common.ts +0 -489
  67. package/k6-tests/utils/logger.ts +0 -62
  68. package/k6-tests/utils/types.d.ts +0 -35
  69. package/malloy_mcp.dxt +0 -0
  70. package/publisher.config.json +0 -33
  71. package/src/config.spec.ts +0 -850
  72. package/src/config.ts +0 -305
  73. package/src/constants.ts +0 -10
  74. package/src/controller/compile.controller.ts +0 -35
  75. package/src/controller/connection.controller.ts +0 -515
  76. package/src/controller/database.controller.ts +0 -21
  77. package/src/controller/manifest.controller.ts +0 -29
  78. package/src/controller/materialization.controller.ts +0 -125
  79. package/src/controller/model.controller.ts +0 -107
  80. package/src/controller/package.controller.ts +0 -182
  81. package/src/controller/query.controller.ts +0 -60
  82. package/src/controller/watch-mode.controller.ts +0 -98
  83. package/src/data_styles.ts +0 -71
  84. package/src/dto/connection.dto.spec.ts +0 -131
  85. package/src/dto/connection.dto.ts +0 -174
  86. package/src/dto/index.ts +0 -2
  87. package/src/dto/package.dto.spec.ts +0 -42
  88. package/src/dto/package.dto.ts +0 -12
  89. package/src/dto/validate.spec.ts +0 -76
  90. package/src/dto/validate.ts +0 -31
  91. package/src/errors.ts +0 -116
  92. package/src/health.ts +0 -189
  93. package/src/instrumentation.ts +0 -148
  94. package/src/logger.ts +0 -154
  95. package/src/mcp/error_messages.ts +0 -199
  96. package/src/mcp/handler_utils.ts +0 -239
  97. package/src/mcp/mcp_constants.ts +0 -22
  98. package/src/mcp/prompts/handlers.ts +0 -84
  99. package/src/mcp/prompts/index.ts +0 -11
  100. package/src/mcp/prompts/prompt_definitions.ts +0 -160
  101. package/src/mcp/prompts/prompt_service.ts +0 -67
  102. package/src/mcp/prompts/utils.ts +0 -62
  103. package/src/mcp/resource_metadata.ts +0 -47
  104. package/src/mcp/resources/model_resource.ts +0 -153
  105. package/src/mcp/resources/notebook_resource.ts +0 -137
  106. package/src/mcp/resources/package_resource.ts +0 -370
  107. package/src/mcp/resources/project_resource.ts +0 -184
  108. package/src/mcp/resources/query_resource.ts +0 -117
  109. package/src/mcp/resources/source_resource.ts +0 -141
  110. package/src/mcp/resources/view_resource.ts +0 -136
  111. package/src/mcp/server.ts +0 -62
  112. package/src/mcp/tools/discovery_tools.ts +0 -258
  113. package/src/mcp/tools/execute_query_tool.ts +0 -265
  114. package/src/server.ts +0 -1195
  115. package/src/service/connection.spec.ts +0 -1331
  116. package/src/service/connection.ts +0 -1511
  117. package/src/service/connection_service.spec.ts +0 -641
  118. package/src/service/connection_service.ts +0 -181
  119. package/src/service/db_utils.spec.ts +0 -714
  120. package/src/service/db_utils.ts +0 -1227
  121. package/src/service/filter.spec.ts +0 -447
  122. package/src/service/filter.ts +0 -337
  123. package/src/service/filter_integration.spec.ts +0 -825
  124. package/src/service/gcs_s3_utils.ts +0 -427
  125. package/src/service/manifest_service.spec.ts +0 -201
  126. package/src/service/manifest_service.ts +0 -106
  127. package/src/service/materialization_service.spec.ts +0 -648
  128. package/src/service/materialization_service.ts +0 -929
  129. package/src/service/materialized_table_gc.spec.ts +0 -383
  130. package/src/service/materialized_table_gc.ts +0 -279
  131. package/src/service/model.spec.ts +0 -257
  132. package/src/service/model.ts +0 -1069
  133. package/src/service/package.spec.ts +0 -236
  134. package/src/service/package.ts +0 -463
  135. package/src/service/project.ts +0 -681
  136. package/src/service/project_compile.spec.ts +0 -197
  137. package/src/service/project_store.spec.ts +0 -859
  138. package/src/service/project_store.ts +0 -1531
  139. package/src/service/quoting.ts +0 -41
  140. package/src/service/resolve_project.ts +0 -13
  141. package/src/storage/BaseRepository.ts +0 -31
  142. package/src/storage/DatabaseInterface.ts +0 -180
  143. package/src/storage/StorageManager.mock.ts +0 -59
  144. package/src/storage/StorageManager.ts +0 -210
  145. package/src/storage/duckdb/ConnectionRepository.ts +0 -141
  146. package/src/storage/duckdb/DuckDBConnection.ts +0 -177
  147. package/src/storage/duckdb/DuckDBManifestStore.ts +0 -70
  148. package/src/storage/duckdb/DuckDBRepository.ts +0 -224
  149. package/src/storage/duckdb/ManifestRepository.ts +0 -119
  150. package/src/storage/duckdb/MaterializationRepository.ts +0 -249
  151. package/src/storage/duckdb/PackageRepository.ts +0 -135
  152. package/src/storage/duckdb/ProjectRepository.ts +0 -148
  153. package/src/storage/duckdb/manifest_store.spec.ts +0 -133
  154. package/src/storage/duckdb/schema.ts +0 -147
  155. package/src/storage/ducklake/DuckLakeManifestStore.ts +0 -146
  156. package/src/utils.ts +0 -13
  157. package/tests/fixtures/persist-test/data/orders.csv +0 -5
  158. package/tests/fixtures/persist-test/persist_test.malloy +0 -11
  159. package/tests/fixtures/persist-test/publisher.json +0 -5
  160. package/tests/fixtures/publisher.config.json +0 -15
  161. package/tests/harness/e2e.ts +0 -96
  162. package/tests/harness/mcp_test_setup.ts +0 -344
  163. package/tests/harness/mocks.ts +0 -37
  164. package/tests/harness/rest_e2e.ts +0 -68
  165. package/tests/harness/uris.ts +0 -31
  166. package/tests/integration/materialization/materialization_lifecycle.integration.spec.ts +0 -470
  167. package/tests/integration/mcp/mcp_execute_query_tool.integration.spec.ts +0 -434
  168. package/tests/integration/mcp/mcp_resource.integration.spec.ts +0 -663
  169. package/tests/integration/mcp/mcp_transport.integration.spec.ts +0 -122
  170. package/tests/integration/mcp/setup.spec.ts +0 -5
  171. package/tests/unit/duckdb/attached_databases.test.ts +0 -1132
  172. package/tests/unit/ducklake/ducklake.test.ts +0 -950
  173. package/tests/unit/mcp/prompt_definitions.test.ts +0 -102
  174. package/tests/unit/mcp/prompt_happy.test.ts +0 -51
  175. package/tsconfig.json +0 -32
@@ -1,950 +0,0 @@
1
- import { DuckDBConnection } from "@malloydata/db-duckdb";
2
- import { afterEach, beforeEach, describe, expect, it } from "bun:test";
3
- import fs from "fs/promises";
4
- import path from "path";
5
- import { components } from "../../../src/api";
6
- import {
7
- createProjectConnections,
8
- deleteDuckLakeConnectionFile,
9
- testConnectionConfig,
10
- } from "../../../src/service/connection";
11
- import {
12
- getSchemasForConnection,
13
- listTablesForSchema,
14
- } from "../../../src/service/db_utils";
15
-
16
- type ApiConnection = components["schemas"]["Connection"];
17
-
18
- const hasPostgresCredentials = () =>
19
- !!(
20
- process.env.POSTGRES_TEST_HOST &&
21
- process.env.POSTGRES_TEST_USER &&
22
- process.env.POSTGRES_TEST_PASSWORD
23
- );
24
-
25
- const hasS3Credentials = () =>
26
- !!(
27
- process.env.S3_TEST_ACCESS_KEY_ID && process.env.S3_TEST_SECRET_ACCESS_KEY
28
- );
29
-
30
- const hasGCSCredentials = () =>
31
- !!(process.env.GCS_TEST_KEY_ID && process.env.GCS_TEST_SECRET);
32
-
33
- describe("DuckLake Connection Tests", () => {
34
- const testProjectPath = path.join(process.cwd(), "test-project-ducklake");
35
- let createdConnections: DuckDBConnection[] = [];
36
-
37
- beforeEach(async () => {
38
- await fs.mkdir(testProjectPath, { recursive: true });
39
- });
40
-
41
- afterEach(async () => {
42
- // Close all connections
43
- for (const conn of createdConnections) {
44
- try {
45
- await conn.close();
46
- } catch (error) {
47
- console.warn("Error closing connection:", error);
48
- }
49
- }
50
- createdConnections = [];
51
-
52
- // Clean up DuckLake database files from testProjectPath
53
- try {
54
- const files = await fs.readdir(testProjectPath);
55
- for (const file of files) {
56
- if (file.endsWith("_ducklake.duckdb")) {
57
- await fs.rm(path.join(testProjectPath, file), { force: true });
58
- }
59
- }
60
- } catch (error) {
61
- // Ignore cleanup errors
62
- }
63
-
64
- // Clean up DuckLake database files from process.cwd() (created by testConnectionConfig)
65
- // testConnectionConfig creates files in process.cwd() instead of testProjectPath
66
- try {
67
- const cwdFiles = await fs.readdir(process.cwd());
68
- for (const file of cwdFiles) {
69
- if (file.endsWith("_ducklake.duckdb")) {
70
- const filePath = path.join(process.cwd(), file);
71
- // Only delete test files, not production files
72
- if (file.includes("_test") || file.includes("invalid")) {
73
- await fs.rm(filePath, { force: true });
74
- }
75
- }
76
- }
77
- } catch (_error) {
78
- // Ignore cleanup errors (file might not exist or already deleted)
79
- }
80
-
81
- // Clean up test directory
82
- const maxRetries = 5;
83
- const delay = 100;
84
- let lastError: unknown;
85
-
86
- for (let attempt = 0; attempt < maxRetries; attempt++) {
87
- try {
88
- await fs.rm(testProjectPath, { recursive: true, force: true });
89
- return;
90
- } catch (error) {
91
- lastError = error;
92
- const errnoError = error as NodeJS.ErrnoException;
93
- if (errnoError.code !== "EBUSY") throw error;
94
- if (attempt < maxRetries - 1) {
95
- await new Promise((resolve) =>
96
- setTimeout(resolve, delay * Math.pow(2, attempt)),
97
- );
98
- }
99
- }
100
- }
101
-
102
- if ((lastError as NodeJS.ErrnoError).code !== "EBUSY") {
103
- throw lastError;
104
- }
105
- });
106
-
107
- describe("Connection Creation", () => {
108
- it(
109
- "should create DuckLake connection with S3 storage",
110
- async () => {
111
- if (!hasPostgresCredentials() || !hasS3Credentials()) {
112
- console.log(
113
- "Skipping: PostgreSQL and S3 credentials not configured",
114
- );
115
- return;
116
- }
117
-
118
- const ducklakeConnection: ApiConnection = {
119
- name: "ducklake_s3_test",
120
- type: "ducklake",
121
- ducklakeConnection: {
122
- catalog: {
123
- postgresConnection: {
124
- host: process.env.POSTGRES_TEST_HOST,
125
- port: parseInt(
126
- process.env.POSTGRES_TEST_PORT || "5432",
127
- ),
128
- userName: process.env.POSTGRES_TEST_USER!,
129
- password: process.env.POSTGRES_TEST_PASSWORD!,
130
- databaseName: process.env.POSTGRES_TEST_DATABASE,
131
- },
132
- },
133
- storage: {
134
- bucketUrl:
135
- process.env.S3_TEST_BUCKET_URL || "s3://test-bucket",
136
- s3Connection: {
137
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
138
- secretAccessKey: process.env.S3_TEST_SECRET_ACCESS_KEY!,
139
- region: process.env.S3_TEST_REGION || "us-east-1",
140
- },
141
- },
142
- },
143
- };
144
-
145
- const { malloyConnections, apiConnections } =
146
- await createProjectConnections(
147
- [ducklakeConnection],
148
- testProjectPath,
149
- );
150
-
151
- expect(malloyConnections.size).toBe(1);
152
- expect(apiConnections.length).toBe(1);
153
-
154
- const connection = malloyConnections.get(
155
- "ducklake_s3_test",
156
- ) as DuckDBConnection;
157
- expect(connection).toBeDefined();
158
- createdConnections.push(connection);
159
-
160
- // Verify DuckLake database is attached
161
- const databases = await connection.runSQL("SHOW DATABASES");
162
- const dbNames = databases.rows.map((row) => Object.values(row)[0]);
163
- expect(dbNames).toContain("ducklake_s3_test");
164
-
165
- // Verify database file was created
166
- const dbPath = path.join(
167
- testProjectPath,
168
- "ducklake_s3_test_ducklake.duckdb",
169
- );
170
- const exists = await fs
171
- .access(dbPath)
172
- .then(() => true)
173
- .catch(() => false);
174
- expect(exists).toBe(true);
175
- },
176
- { timeout: 30000 },
177
- );
178
-
179
- it(
180
- "should create DuckLake connection with GCS storage",
181
- async () => {
182
- if (!hasPostgresCredentials() || !hasGCSCredentials()) {
183
- console.log(
184
- "Skipping: PostgreSQL and GCS credentials not configured",
185
- );
186
- return;
187
- }
188
-
189
- const ducklakeConnection: ApiConnection = {
190
- name: "ducklake_gcs_test",
191
- type: "ducklake",
192
- ducklakeConnection: {
193
- catalog: {
194
- postgresConnection: {
195
- host: process.env.POSTGRES_TEST_HOST,
196
- port: parseInt(
197
- process.env.POSTGRES_TEST_PORT || "5432",
198
- ),
199
- userName: process.env.POSTGRES_TEST_USER!,
200
- password: process.env.POSTGRES_TEST_PASSWORD!,
201
- databaseName: process.env.POSTGRES_TEST_DATABASE,
202
- },
203
- },
204
- storage: {
205
- bucketUrl:
206
- process.env.GCS_TEST_BUCKET_URL || "gs://test-bucket",
207
- gcsConnection: {
208
- keyId: process.env.GCS_TEST_KEY_ID!,
209
- secret: process.env.GCS_TEST_SECRET!,
210
- },
211
- },
212
- },
213
- };
214
-
215
- const { malloyConnections } = await createProjectConnections(
216
- [ducklakeConnection],
217
- testProjectPath,
218
- );
219
-
220
- const connection = malloyConnections.get(
221
- "ducklake_gcs_test",
222
- ) as DuckDBConnection;
223
- expect(connection).toBeDefined();
224
- createdConnections.push(connection);
225
-
226
- // Verify DuckLake database is attached
227
- const databases = await connection.runSQL("SHOW DATABASES");
228
- const dbNames = databases.rows.map((row) => Object.values(row)[0]);
229
- expect(dbNames).toContain("ducklake_gcs_test");
230
- },
231
- { timeout: 30000 },
232
- );
233
-
234
- it(
235
- "should load required extensions for DuckLake",
236
- async () => {
237
- if (!hasPostgresCredentials() || !hasS3Credentials()) {
238
- console.log(
239
- "Skipping: PostgreSQL and S3 credentials not configured",
240
- );
241
- return;
242
- }
243
-
244
- const ducklakeConnection: ApiConnection = {
245
- name: "ducklake_extensions_test",
246
- type: "ducklake",
247
- ducklakeConnection: {
248
- catalog: {
249
- postgresConnection: {
250
- host: process.env.POSTGRES_TEST_HOST,
251
- port: parseInt(
252
- process.env.POSTGRES_TEST_PORT || "5432",
253
- ),
254
- userName: process.env.POSTGRES_TEST_USER!,
255
- password: process.env.POSTGRES_TEST_PASSWORD!,
256
- databaseName: process.env.POSTGRES_TEST_DATABASE,
257
- },
258
- },
259
- storage: {
260
- bucketUrl:
261
- process.env.S3_TEST_BUCKET_URL || "s3://test-bucket",
262
- s3Connection: {
263
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
264
- secretAccessKey: process.env.S3_TEST_SECRET_ACCESS_KEY!,
265
- region: process.env.S3_TEST_REGION || "us-east-1",
266
- },
267
- },
268
- },
269
- };
270
-
271
- const { malloyConnections } = await createProjectConnections(
272
- [ducklakeConnection],
273
- testProjectPath,
274
- );
275
-
276
- const connection = malloyConnections.get(
277
- "ducklake_extensions_test",
278
- ) as DuckDBConnection;
279
- createdConnections.push(connection);
280
-
281
- // Verify required extensions are loaded
282
- const extensions = await connection.runSQL(
283
- "SELECT extension_name FROM duckdb_extensions() WHERE loaded = true",
284
- );
285
- const extensionNames = extensions.rows.map(
286
- (row) => Object.values(row)[0] as string,
287
- );
288
-
289
- // DuckLake requires these extensions
290
- expect(extensionNames).toContain("ducklake");
291
- expect(extensionNames).toContain("postgres_scanner");
292
- expect(extensionNames).toContain("httpfs");
293
- },
294
- { timeout: 30000 },
295
- );
296
- });
297
-
298
- describe("Schema Operations", () => {
299
- it(
300
- "should list schemas from DuckLake connection",
301
- async () => {
302
- if (!hasPostgresCredentials() || !hasS3Credentials()) {
303
- console.log(
304
- "Skipping: PostgreSQL and S3 credentials not configured",
305
- );
306
- return;
307
- }
308
-
309
- const ducklakeConnection: ApiConnection = {
310
- name: "ducklake_schemas_test",
311
- type: "ducklake",
312
- ducklakeConnection: {
313
- catalog: {
314
- postgresConnection: {
315
- host: process.env.POSTGRES_TEST_HOST,
316
- port: parseInt(
317
- process.env.POSTGRES_TEST_PORT || "5432",
318
- ),
319
- userName: process.env.POSTGRES_TEST_USER!,
320
- password: process.env.POSTGRES_TEST_PASSWORD!,
321
- databaseName: process.env.POSTGRES_TEST_DATABASE,
322
- },
323
- },
324
- storage: {
325
- bucketUrl:
326
- process.env.S3_TEST_BUCKET_URL || "s3://test-bucket",
327
- s3Connection: {
328
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
329
- secretAccessKey: process.env.S3_TEST_SECRET_ACCESS_KEY!,
330
- region: process.env.S3_TEST_REGION || "us-east-1",
331
- },
332
- },
333
- },
334
- };
335
-
336
- const { malloyConnections } = await createProjectConnections(
337
- [ducklakeConnection],
338
- testProjectPath,
339
- );
340
-
341
- const connection = malloyConnections.get(
342
- "ducklake_schemas_test",
343
- ) as DuckDBConnection;
344
- createdConnections.push(connection);
345
-
346
- // Test schema listing using db_utils
347
- const schemas = await getSchemasForConnection(
348
- ducklakeConnection,
349
- connection,
350
- );
351
- expect(schemas).toBeDefined();
352
- expect(Array.isArray(schemas)).toBe(true);
353
-
354
- // Also test direct SQL query
355
- const result = await connection.runSQL(
356
- `SELECT DISTINCT schema_name FROM information_schema.schemata WHERE catalog_name = 'ducklake_schemas_test' ORDER BY schema_name`,
357
- );
358
- expect(result.rows).toBeDefined();
359
- expect(result.rows.length).toBeGreaterThanOrEqual(0);
360
- },
361
- { timeout: 30000 },
362
- );
363
- });
364
-
365
- describe("Table Operations", () => {
366
- it(
367
- "should list tables from DuckLake schema",
368
- async () => {
369
- if (!hasPostgresCredentials() || !hasS3Credentials()) {
370
- console.log(
371
- "Skipping: PostgreSQL and S3 credentials not configured",
372
- );
373
- return;
374
- }
375
-
376
- const ducklakeConnection: ApiConnection = {
377
- name: "ducklake_tables_test",
378
- type: "ducklake",
379
- ducklakeConnection: {
380
- catalog: {
381
- postgresConnection: {
382
- host: process.env.POSTGRES_TEST_HOST,
383
- port: parseInt(
384
- process.env.POSTGRES_TEST_PORT || "5432",
385
- ),
386
- userName: process.env.POSTGRES_TEST_USER!,
387
- password: process.env.POSTGRES_TEST_PASSWORD!,
388
- databaseName: process.env.POSTGRES_TEST_DATABASE,
389
- },
390
- },
391
- storage: {
392
- bucketUrl:
393
- process.env.S3_TEST_BUCKET_URL || "s3://test-bucket",
394
- s3Connection: {
395
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
396
- secretAccessKey: process.env.S3_TEST_SECRET_ACCESS_KEY!,
397
- region: process.env.S3_TEST_REGION || "us-east-1",
398
- },
399
- },
400
- },
401
- };
402
-
403
- const { malloyConnections } = await createProjectConnections(
404
- [ducklakeConnection],
405
- testProjectPath,
406
- );
407
-
408
- const connection = malloyConnections.get(
409
- "ducklake_tables_test",
410
- ) as DuckDBConnection;
411
- createdConnections.push(connection);
412
-
413
- // Get schemas first
414
- const schemas = await getSchemasForConnection(
415
- ducklakeConnection,
416
- connection,
417
- );
418
- if (schemas.length === 0) {
419
- console.log("No schemas found, skipping table listing test");
420
- return;
421
- }
422
-
423
- // Test table listing for first schema
424
- const schemaName = schemas[0].name!;
425
- const tables = await listTablesForSchema(
426
- ducklakeConnection,
427
- schemaName,
428
- connection,
429
- );
430
- expect(tables).toBeDefined();
431
- expect(Array.isArray(tables)).toBe(true);
432
- },
433
- { timeout: 30000 },
434
- );
435
-
436
- it(
437
- "should handle table path prefixing correctly",
438
- async () => {
439
- if (!hasPostgresCredentials() || !hasS3Credentials()) {
440
- console.log(
441
- "Skipping: PostgreSQL and S3 credentials not configured",
442
- );
443
- return;
444
- }
445
-
446
- const ducklakeConnection: ApiConnection = {
447
- name: "ducklake_prefix_test",
448
- type: "ducklake",
449
- ducklakeConnection: {
450
- catalog: {
451
- postgresConnection: {
452
- host: process.env.POSTGRES_TEST_HOST,
453
- port: parseInt(
454
- process.env.POSTGRES_TEST_PORT || "5432",
455
- ),
456
- userName: process.env.POSTGRES_TEST_USER!,
457
- password: process.env.POSTGRES_TEST_PASSWORD!,
458
- databaseName: process.env.POSTGRES_TEST_DATABASE,
459
- },
460
- },
461
- storage: {
462
- bucketUrl:
463
- process.env.S3_TEST_BUCKET_URL || "s3://test-bucket",
464
- s3Connection: {
465
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
466
- secretAccessKey: process.env.S3_TEST_SECRET_ACCESS_KEY!,
467
- region: process.env.S3_TEST_REGION || "us-east-1",
468
- },
469
- },
470
- },
471
- };
472
-
473
- const { malloyConnections } = await createProjectConnections(
474
- [ducklakeConnection],
475
- testProjectPath,
476
- );
477
-
478
- const connection = malloyConnections.get(
479
- "ducklake_prefix_test",
480
- ) as DuckDBConnection;
481
- createdConnections.push(connection);
482
-
483
- // Test that connection name is used as catalog prefix
484
- // DuckLake tables should be accessible as connectionName.schemaName.tableName
485
- const result = await connection.runSQL(
486
- `SELECT catalog_name, schema_name FROM information_schema.schemata WHERE catalog_name = 'ducklake_prefix_test' LIMIT 1`,
487
- );
488
- expect(result.rows).toBeDefined();
489
- },
490
- { timeout: 30000 },
491
- );
492
- });
493
-
494
- describe("Query Operations", () => {
495
- it(
496
- "should execute queries against DuckLake database",
497
- async () => {
498
- if (!hasPostgresCredentials() || !hasS3Credentials()) {
499
- console.log(
500
- "Skipping: PostgreSQL and S3 credentials not configured",
501
- );
502
- return;
503
- }
504
-
505
- const ducklakeConnection: ApiConnection = {
506
- name: "ducklake_query_test",
507
- type: "ducklake",
508
- ducklakeConnection: {
509
- catalog: {
510
- postgresConnection: {
511
- host: process.env.POSTGRES_TEST_HOST,
512
- port: parseInt(
513
- process.env.POSTGRES_TEST_PORT || "5432",
514
- ),
515
- userName: process.env.POSTGRES_TEST_USER!,
516
- password: process.env.POSTGRES_TEST_PASSWORD!,
517
- databaseName: process.env.POSTGRES_TEST_DATABASE,
518
- },
519
- },
520
- storage: {
521
- bucketUrl:
522
- process.env.S3_TEST_BUCKET_URL || "s3://test-bucket",
523
- s3Connection: {
524
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
525
- secretAccessKey: process.env.S3_TEST_SECRET_ACCESS_KEY!,
526
- region: process.env.S3_TEST_REGION || "us-east-1",
527
- },
528
- },
529
- },
530
- };
531
-
532
- const { malloyConnections } = await createProjectConnections(
533
- [ducklakeConnection],
534
- testProjectPath,
535
- );
536
-
537
- const connection = malloyConnections.get(
538
- "ducklake_query_test",
539
- ) as DuckDBConnection;
540
- createdConnections.push(connection);
541
-
542
- // Test basic query
543
- const result = await connection.runSQL(
544
- `SELECT schema_name FROM information_schema.schemata WHERE catalog_name = 'ducklake_query_test' LIMIT 1`,
545
- );
546
- expect(result.rows).toBeDefined();
547
- expect(Array.isArray(result.rows)).toBe(true);
548
- },
549
- { timeout: 30000 },
550
- );
551
- });
552
-
553
- describe("Error Handling", () => {
554
- it("should throw error if DuckLake catalog connection is missing", async () => {
555
- await expect(
556
- createProjectConnections(
557
- [
558
- {
559
- name: "ducklake_no_catalog",
560
- type: "ducklake",
561
- ducklakeConnection: {
562
- storage: {
563
- bucketUrl: "s3://test-bucket",
564
- s3Connection: {
565
- accessKeyId: "test",
566
- secretAccessKey: "test",
567
- },
568
- },
569
- },
570
- } as ApiConnection,
571
- ],
572
- testProjectPath,
573
- ),
574
- ).rejects.toThrow(/PostgreSQL connection configuration is required/);
575
- });
576
-
577
- it("should throw error if DuckLake storage bucketUrl is missing", async () => {
578
- await expect(
579
- createProjectConnections(
580
- [
581
- {
582
- name: "ducklake_no_bucket",
583
- type: "ducklake",
584
- ducklakeConnection: {
585
- catalog: {
586
- postgresConnection: {
587
- host: "localhost",
588
- port: 5432,
589
- userName: "test",
590
- password: "test",
591
- databaseName: "test",
592
- },
593
- },
594
- storage: {
595
- s3Connection: {
596
- accessKeyId: "test",
597
- secretAccessKey: "test",
598
- },
599
- },
600
- },
601
- } as ApiConnection,
602
- ],
603
- testProjectPath,
604
- ),
605
- ).rejects.toThrow(/Storage bucketUrl is required/);
606
- });
607
-
608
- it("should throw error if DuckLake connection config is missing", async () => {
609
- await expect(
610
- createProjectConnections(
611
- [
612
- {
613
- name: "ducklake_missing_config",
614
- type: "ducklake",
615
- },
616
- ],
617
- testProjectPath,
618
- ),
619
- ).rejects.toThrow(/DuckLake connection configuration is missing/);
620
- });
621
-
622
- it("should handle already attached database gracefully", async () => {
623
- if (!hasPostgresCredentials() || !hasS3Credentials()) {
624
- console.log(
625
- "Skipping: PostgreSQL and S3 credentials not configured",
626
- );
627
- return;
628
- }
629
-
630
- const ducklakeConnection: ApiConnection = {
631
- name: "ducklake_duplicate_test",
632
- type: "ducklake",
633
- ducklakeConnection: {
634
- catalog: {
635
- postgresConnection: {
636
- host: process.env.POSTGRES_TEST_HOST,
637
- port: parseInt(process.env.POSTGRES_TEST_PORT || "5432"),
638
- userName: process.env.POSTGRES_TEST_USER!,
639
- password: process.env.POSTGRES_TEST_PASSWORD!,
640
- databaseName: process.env.POSTGRES_TEST_DATABASE,
641
- },
642
- },
643
- storage: {
644
- bucketUrl:
645
- process.env.S3_TEST_BUCKET_URL || "s3://test-bucket",
646
- s3Connection: {
647
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
648
- secretAccessKey: process.env.S3_TEST_SECRET_ACCESS_KEY!,
649
- region: process.env.S3_TEST_REGION || "us-east-1",
650
- },
651
- },
652
- },
653
- };
654
-
655
- // Create connection twice - second should handle already attached gracefully
656
- const { malloyConnections: conn1 } = await createProjectConnections(
657
- [ducklakeConnection],
658
- testProjectPath,
659
- );
660
- const connection1 = conn1.get(
661
- "ducklake_duplicate_test",
662
- ) as DuckDBConnection;
663
- createdConnections.push(connection1);
664
-
665
- const { malloyConnections: conn2 } = await createProjectConnections(
666
- [ducklakeConnection],
667
- testProjectPath,
668
- );
669
- const connection2 = conn2.get(
670
- "ducklake_duplicate_test",
671
- ) as DuckDBConnection;
672
- createdConnections.push(connection2);
673
-
674
- expect(connection1).toBeDefined();
675
- expect(connection2).toBeDefined();
676
- });
677
- });
678
-
679
- describe("Database File Management", () => {
680
- it(
681
- "should create database file with correct naming pattern",
682
- async () => {
683
- if (!hasPostgresCredentials() || !hasS3Credentials()) {
684
- console.log(
685
- "Skipping: PostgreSQL and S3 credentials not configured",
686
- );
687
- return;
688
- }
689
-
690
- const ducklakeConnection: ApiConnection = {
691
- name: "ducklake_file_test",
692
- type: "ducklake",
693
- ducklakeConnection: {
694
- catalog: {
695
- postgresConnection: {
696
- host: process.env.POSTGRES_TEST_HOST,
697
- port: parseInt(
698
- process.env.POSTGRES_TEST_PORT || "5432",
699
- ),
700
- userName: process.env.POSTGRES_TEST_USER!,
701
- password: process.env.POSTGRES_TEST_PASSWORD!,
702
- databaseName: process.env.POSTGRES_TEST_DATABASE,
703
- },
704
- },
705
- storage: {
706
- bucketUrl:
707
- process.env.S3_TEST_BUCKET_URL || "s3://test-bucket",
708
- s3Connection: {
709
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
710
- secretAccessKey: process.env.S3_TEST_SECRET_ACCESS_KEY!,
711
- region: process.env.S3_TEST_REGION || "us-east-1",
712
- },
713
- },
714
- },
715
- };
716
-
717
- const { malloyConnections } = await createProjectConnections(
718
- [ducklakeConnection],
719
- testProjectPath,
720
- );
721
-
722
- const connection = malloyConnections.get(
723
- "ducklake_file_test",
724
- ) as DuckDBConnection;
725
- createdConnections.push(connection);
726
-
727
- // Verify database file follows naming pattern: {connectionName}_ducklake.duckdb
728
- const dbPath = path.join(
729
- testProjectPath,
730
- "ducklake_file_test_ducklake.duckdb",
731
- );
732
- const exists = await fs
733
- .access(dbPath)
734
- .then(() => true)
735
- .catch(() => false);
736
- expect(exists).toBe(true);
737
- },
738
- { timeout: 30000 },
739
- );
740
-
741
- it("should delete DuckLake connection file", async () => {
742
- if (!hasPostgresCredentials() || !hasS3Credentials()) {
743
- console.log(
744
- "Skipping: PostgreSQL and S3 credentials not configured",
745
- );
746
- return;
747
- }
748
-
749
- const ducklakeConnection: ApiConnection = {
750
- name: "ducklake_delete_test",
751
- type: "ducklake",
752
- ducklakeConnection: {
753
- catalog: {
754
- postgresConnection: {
755
- host: process.env.POSTGRES_TEST_HOST,
756
- port: parseInt(process.env.POSTGRES_TEST_PORT || "5432"),
757
- userName: process.env.POSTGRES_TEST_USER!,
758
- password: process.env.POSTGRES_TEST_PASSWORD!,
759
- databaseName: process.env.POSTGRES_TEST_DATABASE,
760
- },
761
- },
762
- storage: {
763
- bucketUrl:
764
- process.env.S3_TEST_BUCKET_URL || "s3://test-bucket",
765
- s3Connection: {
766
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
767
- secretAccessKey: process.env.S3_TEST_SECRET_ACCESS_KEY!,
768
- region: process.env.S3_TEST_REGION || "us-east-1",
769
- },
770
- },
771
- },
772
- };
773
-
774
- const { malloyConnections } = await createProjectConnections(
775
- [ducklakeConnection],
776
- testProjectPath,
777
- );
778
-
779
- const connection = malloyConnections.get(
780
- "ducklake_delete_test",
781
- ) as DuckDBConnection;
782
- await connection.close();
783
- createdConnections = createdConnections.filter(
784
- (c) => c !== connection,
785
- );
786
-
787
- // Delete the file
788
- await deleteDuckLakeConnectionFile(
789
- "ducklake_delete_test",
790
- testProjectPath,
791
- );
792
-
793
- // Verify file is deleted
794
- const dbPath = path.join(
795
- testProjectPath,
796
- "ducklake_delete_test_ducklake.duckdb",
797
- );
798
- const exists = await fs
799
- .access(dbPath)
800
- .then(() => true)
801
- .catch(() => false);
802
- expect(exists).toBe(false);
803
- });
804
-
805
- it("should handle deletion of non-existent file gracefully", async () => {
806
- // Should not throw error if file doesn't exist
807
- // The function catches ENOENT errors internally, so this should complete without throwing
808
- await expect(
809
- deleteDuckLakeConnectionFile(
810
- "nonexistent_connection",
811
- testProjectPath,
812
- ),
813
- ).resolves.toBeUndefined();
814
- });
815
- });
816
-
817
- describe("Connection Testing", () => {
818
- it(
819
- "should test DuckLake connection configuration",
820
- async () => {
821
- if (!hasPostgresCredentials() || !hasS3Credentials()) {
822
- console.log(
823
- "Skipping: PostgreSQL and S3 credentials not configured",
824
- );
825
- return;
826
- }
827
-
828
- const result = await testConnectionConfig({
829
- name: "ducklake_test_config",
830
- type: "ducklake",
831
- ducklakeConnection: {
832
- catalog: {
833
- postgresConnection: {
834
- host: process.env.POSTGRES_TEST_HOST,
835
- port: parseInt(
836
- process.env.POSTGRES_TEST_PORT || "5432",
837
- ),
838
- userName: process.env.POSTGRES_TEST_USER!,
839
- password: process.env.POSTGRES_TEST_PASSWORD!,
840
- databaseName: process.env.POSTGRES_TEST_DATABASE,
841
- },
842
- },
843
- storage: {
844
- bucketUrl:
845
- process.env.S3_TEST_BUCKET_URL || "s3://test-bucket",
846
- s3Connection: {
847
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
848
- secretAccessKey: process.env.S3_TEST_SECRET_ACCESS_KEY!,
849
- region: process.env.S3_TEST_REGION || "us-east-1",
850
- },
851
- },
852
- },
853
- });
854
-
855
- expect(result.status).toBe("ok");
856
- expect(result.errorMessage).toBe("");
857
- },
858
- { timeout: 30000 },
859
- );
860
-
861
- it(
862
- "should fail test for invalid DuckLake configuration",
863
- async () => {
864
- const result = await testConnectionConfig({
865
- name: "ducklake_invalid_test",
866
- type: "ducklake",
867
- ducklakeConnection: {
868
- catalog: {
869
- postgresConnection: {
870
- host: "invalid-host",
871
- port: 5432,
872
- userName: "invalid",
873
- password: "invalid",
874
- databaseName: "invalid",
875
- },
876
- },
877
- storage: {
878
- bucketUrl: "s3://invalid-bucket",
879
- s3Connection: {
880
- accessKeyId: "invalid",
881
- secretAccessKey: "invalid",
882
- },
883
- },
884
- },
885
- });
886
-
887
- expect(result.status).toBe("failed");
888
- expect(result.errorMessage).toBeDefined();
889
- expect(result.errorMessage.length).toBeGreaterThan(0);
890
- },
891
- { timeout: 30000 },
892
- );
893
- });
894
-
895
- describe("Connection Attributes", () => {
896
- it(
897
- "should return correct attributes for DuckLake connection",
898
- async () => {
899
- if (!hasPostgresCredentials() || !hasS3Credentials()) {
900
- console.log(
901
- "Skipping: PostgreSQL and S3 credentials not configured",
902
- );
903
- return;
904
- }
905
-
906
- const { apiConnections } = await createProjectConnections(
907
- [
908
- {
909
- name: "ducklake_attrs_test",
910
- type: "ducklake",
911
- ducklakeConnection: {
912
- catalog: {
913
- postgresConnection: {
914
- host: process.env.POSTGRES_TEST_HOST,
915
- port: parseInt(
916
- process.env.POSTGRES_TEST_PORT || "5432",
917
- ),
918
- userName: process.env.POSTGRES_TEST_USER!,
919
- password: process.env.POSTGRES_TEST_PASSWORD!,
920
- databaseName: process.env.POSTGRES_TEST_DATABASE,
921
- },
922
- },
923
- storage: {
924
- bucketUrl:
925
- process.env.S3_TEST_BUCKET_URL ||
926
- "s3://test-bucket",
927
- s3Connection: {
928
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
929
- secretAccessKey:
930
- process.env.S3_TEST_SECRET_ACCESS_KEY!,
931
- region: process.env.S3_TEST_REGION || "us-east-1",
932
- },
933
- },
934
- },
935
- },
936
- ],
937
- testProjectPath,
938
- );
939
-
940
- const connection = apiConnections[0];
941
- expect(connection.attributes).toBeDefined();
942
- expect(connection.attributes?.dialectName).toBe("duckdb");
943
- expect(typeof connection.attributes?.canPersist).toBe("boolean");
944
- expect(typeof connection.attributes?.canStream).toBe("boolean");
945
- expect(typeof connection.attributes?.isPool).toBe("boolean");
946
- },
947
- { timeout: 30000 },
948
- );
949
- });
950
- });