@malloy-publisher/server 0.0.382-dev → 0.2.1

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 +3929 -534
  5. package/dist/app/assets/EnvironmentPage-CHq5BF4l.js +1 -0
  6. package/dist/app/assets/HomePage-CIp-pJCa.js +1 -0
  7. package/dist/app/assets/LightMode-mHHPjEeA.js +1 -0
  8. package/dist/app/assets/MainPage-CylxO5Yu.js +2 -0
  9. package/dist/app/assets/MaterializationsPage-a0vjqxib.js +1 -0
  10. package/dist/app/assets/ModelPage-Cz-MrSZQ.js +1 -0
  11. package/dist/app/assets/PackagePage-Cdg5D7AN.js +1 -0
  12. package/dist/app/assets/RouteError-B5SIyn6G.js +1 -0
  13. package/dist/app/assets/ThemeEditorPage-B62rRc-y.js +1 -0
  14. package/dist/app/assets/WorkbookPage-45cG1Gx6.js +1 -0
  15. package/dist/app/assets/{core-CjeTkq8O.es-BqRc6yhC.js → core-DyU47reh.es-DY9b3WjS.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-C5ClsnS7.js +1774 -0
  19. package/dist/app/assets/index-DF9tVqwN.js +1 -0
  20. package/dist/app/assets/index-DSoCUF-f.js +2725 -0
  21. package/dist/app/assets/index-DgVRz2wm.js +2 -0
  22. package/dist/app/assets/index-P-pF8nU5.js +632 -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} +141276 -74705
  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,1331 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it } from "bun:test";
2
- import fs from "fs/promises";
3
- import path from "path";
4
- import sinon from "sinon";
5
- import { DuckDBConnection } from "@malloydata/db-duckdb";
6
- import { createProjectConnections, testConnectionConfig } from "./connection";
7
- import { components } from "../api";
8
-
9
- type ApiConnection = components["schemas"]["Connection"];
10
- type AttachedDatabase = components["schemas"]["AttachedDatabase"];
11
-
12
- const hasPostgresCredentials = () =>
13
- !!(
14
- process.env.POSTGRES_TEST_HOST &&
15
- process.env.POSTGRES_TEST_USER &&
16
- process.env.POSTGRES_TEST_PASSWORD
17
- );
18
-
19
- const hasBigQueryCredentials = () =>
20
- !!(
21
- process.env.GOOGLE_APPLICATION_CREDENTIALS &&
22
- process.env.BIGQUERY_TEST_PROJECT_ID
23
- );
24
-
25
- const hasSnowflakeCredentials = () =>
26
- !!(
27
- process.env.SNOWFLAKE_TEST_ACCOUNT &&
28
- process.env.SNOWFLAKE_TEST_USER &&
29
- process.env.SNOWFLAKE_TEST_PASSWORD &&
30
- process.env.SNOWFLAKE_TEST_WAREHOUSE
31
- );
32
-
33
- const hasS3Credentials = () =>
34
- !!(
35
- process.env.S3_TEST_ACCESS_KEY_ID && process.env.S3_TEST_SECRET_ACCESS_KEY
36
- );
37
-
38
- const hasGCSCredentials = () =>
39
- !!(process.env.GCS_TEST_KEY_ID && process.env.GCS_TEST_SECRET);
40
-
41
- const readBigQueryServiceAccountJson = async (): Promise<string> =>
42
- fs.readFile(process.env.GOOGLE_APPLICATION_CREDENTIALS!, "utf-8");
43
-
44
- describe("connection integration tests", () => {
45
- const testProjectPath = path.join(process.cwd(), "test-project-connections");
46
- let createdConnections: DuckDBConnection[] = [];
47
-
48
- beforeEach(async () => {
49
- await fs.mkdir(testProjectPath, { recursive: true });
50
- });
51
-
52
- afterEach(async () => {
53
- sinon.restore();
54
-
55
- for (const conn of createdConnections) {
56
- try {
57
- await conn.close();
58
- } catch (error) {
59
- console.warn("Error closing connection:", error);
60
- }
61
- }
62
- createdConnections = [];
63
-
64
- const maxRetries = 5;
65
- const delay = 100;
66
- let lastError: unknown;
67
-
68
- for (let attempt = 0; attempt < maxRetries; attempt++) {
69
- try {
70
- await fs.rm(testProjectPath, { recursive: true, force: true });
71
- return;
72
- } catch (error) {
73
- lastError = error;
74
- const errnoError = error as NodeJS.ErrnoException;
75
- if (errnoError.code !== "EBUSY") throw error;
76
- if (attempt < maxRetries - 1) {
77
- await new Promise((resolve) =>
78
- setTimeout(resolve, delay * Math.pow(2, attempt)),
79
- );
80
- }
81
- }
82
- }
83
-
84
- if ((lastError as NodeJS.ErrnoException).code !== "EBUSY") {
85
- throw lastError;
86
- }
87
- });
88
-
89
- describe("createProjectConnections", () => {
90
- describe("DuckDB with PostgreSQL attachment", () => {
91
- it(
92
- "should create DuckDB connection with attached PostgreSQL database",
93
- async () => {
94
- if (!hasPostgresCredentials()) {
95
- console.log(
96
- "Skipping: PostgreSQL credentials not configured",
97
- );
98
- return;
99
- }
100
-
101
- const postgresAttachment: AttachedDatabase = {
102
- name: "pg_test",
103
- type: "postgres",
104
- postgresConnection: {
105
- host: process.env.POSTGRES_TEST_HOST,
106
- port: parseInt(process.env.POSTGRES_TEST_PORT || "5432"),
107
- userName: process.env.POSTGRES_TEST_USER!,
108
- password: process.env.POSTGRES_TEST_PASSWORD!,
109
- databaseName: process.env.POSTGRES_TEST_DATABASE,
110
- },
111
- };
112
-
113
- const duckdbConnection: ApiConnection = {
114
- name: "duckdb_with_postgres",
115
- type: "duckdb",
116
- duckdbConnection: { attachedDatabases: [postgresAttachment] },
117
- };
118
-
119
- const { malloyConnections, apiConnections } =
120
- await createProjectConnections(
121
- [duckdbConnection],
122
- testProjectPath,
123
- );
124
-
125
- expect(malloyConnections.size).toBe(1);
126
- expect(apiConnections.length).toBe(1);
127
-
128
- const connection = malloyConnections.get(
129
- "duckdb_with_postgres",
130
- ) as DuckDBConnection;
131
- expect(connection).toBeDefined();
132
- createdConnections.push(connection);
133
-
134
- const databases = await connection.runSQL("SHOW DATABASES");
135
- const dbNames = databases.rows.map(
136
- (row) => Object.values(row)[0],
137
- );
138
- expect(dbNames).toContain("pg_test");
139
-
140
- const result = await connection.runSQL(
141
- "SELECT 1 as test_value FROM pg_test.information_schema.tables LIMIT 1",
142
- );
143
- expect(result.rows).toBeDefined();
144
- },
145
- { timeout: 30000 },
146
- );
147
-
148
- it(
149
- "should list schemas from attached PostgreSQL database",
150
- async () => {
151
- if (!hasPostgresCredentials()) {
152
- console.log(
153
- "Skipping: PostgreSQL credentials not configured",
154
- );
155
- return;
156
- }
157
-
158
- const duckdbConnection: ApiConnection = {
159
- name: "duckdb_pg_schemas",
160
- type: "duckdb",
161
- duckdbConnection: {
162
- attachedDatabases: [
163
- {
164
- name: "pg_schemas",
165
- type: "postgres",
166
- postgresConnection: {
167
- host: process.env.POSTGRES_TEST_HOST,
168
- port: parseInt(
169
- process.env.POSTGRES_TEST_PORT || "5432",
170
- ),
171
- userName: process.env.POSTGRES_TEST_USER!,
172
- password: process.env.POSTGRES_TEST_PASSWORD!,
173
- databaseName: process.env.POSTGRES_TEST_DATABASE,
174
- },
175
- },
176
- ],
177
- },
178
- };
179
-
180
- const { malloyConnections } = await createProjectConnections(
181
- [duckdbConnection],
182
- testProjectPath,
183
- );
184
-
185
- const connection = malloyConnections.get(
186
- "duckdb_pg_schemas",
187
- ) as DuckDBConnection;
188
- createdConnections.push(connection);
189
-
190
- // listSchemas equivalent
191
- const result = await connection.runSQL(
192
- "SELECT schema_name FROM pg_schemas.information_schema.schemata ORDER BY schema_name",
193
- );
194
- expect(result.rows.length).toBeGreaterThan(0);
195
- const schemaNames = result.rows.map(
196
- (row) => Object.values(row)[0] as string,
197
- );
198
- expect(schemaNames).toContain("public");
199
- },
200
- { timeout: 30000 },
201
- );
202
-
203
- it(
204
- "should list tables from attached PostgreSQL database",
205
- async () => {
206
- if (!hasPostgresCredentials()) {
207
- console.log(
208
- "Skipping: PostgreSQL credentials not configured",
209
- );
210
- return;
211
- }
212
-
213
- const duckdbConnection: ApiConnection = {
214
- name: "duckdb_pg_tables",
215
- type: "duckdb",
216
- duckdbConnection: {
217
- attachedDatabases: [
218
- {
219
- name: "pg_tables_db",
220
- type: "postgres",
221
- postgresConnection: {
222
- host: process.env.POSTGRES_TEST_HOST,
223
- port: parseInt(
224
- process.env.POSTGRES_TEST_PORT || "5432",
225
- ),
226
- userName: process.env.POSTGRES_TEST_USER!,
227
- password: process.env.POSTGRES_TEST_PASSWORD!,
228
- databaseName: process.env.POSTGRES_TEST_DATABASE,
229
- },
230
- },
231
- ],
232
- },
233
- };
234
-
235
- const { malloyConnections } = await createProjectConnections(
236
- [duckdbConnection],
237
- testProjectPath,
238
- );
239
-
240
- const connection = malloyConnections.get(
241
- "duckdb_pg_tables",
242
- ) as DuckDBConnection;
243
- createdConnections.push(connection);
244
-
245
- // listTables equivalent
246
- const result = await connection.runSQL(`
247
- SELECT table_schema, table_name, table_type
248
- FROM pg_tables_db.information_schema.tables
249
- WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
250
- ORDER BY table_schema, table_name
251
- `);
252
- expect(result.rows).toBeDefined();
253
- },
254
- { timeout: 30000 },
255
- );
256
-
257
- it(
258
- "should get table columns from attached PostgreSQL database",
259
- async () => {
260
- if (!hasPostgresCredentials()) {
261
- console.log(
262
- "Skipping: PostgreSQL credentials not configured",
263
- );
264
- return;
265
- }
266
-
267
- const duckdbConnection: ApiConnection = {
268
- name: "duckdb_pg_cols",
269
- type: "duckdb",
270
- duckdbConnection: {
271
- attachedDatabases: [
272
- {
273
- name: "pg_cols",
274
- type: "postgres",
275
- postgresConnection: {
276
- host: process.env.POSTGRES_TEST_HOST,
277
- port: parseInt(
278
- process.env.POSTGRES_TEST_PORT || "5432",
279
- ),
280
- userName: process.env.POSTGRES_TEST_USER!,
281
- password: process.env.POSTGRES_TEST_PASSWORD!,
282
- databaseName: process.env.POSTGRES_TEST_DATABASE,
283
- },
284
- },
285
- ],
286
- },
287
- };
288
-
289
- const { malloyConnections } = await createProjectConnections(
290
- [duckdbConnection],
291
- testProjectPath,
292
- );
293
-
294
- const connection = malloyConnections.get(
295
- "duckdb_pg_cols",
296
- ) as DuckDBConnection;
297
- createdConnections.push(connection);
298
-
299
- const result = await connection.runSQL(`
300
- SELECT column_name, data_type, is_nullable
301
- FROM pg_cols.information_schema.columns
302
- WHERE table_schema = 'information_schema'
303
- AND table_name = 'tables'
304
- ORDER BY ordinal_position
305
- `);
306
- expect(result.rows.length).toBeGreaterThan(0);
307
- const columnNames = result.rows.map(
308
- (row) => (row as Record<string, unknown>)["column_name"],
309
- );
310
- expect(columnNames).toContain("table_name");
311
- expect(columnNames).toContain("table_schema");
312
- },
313
- { timeout: 30000 },
314
- );
315
-
316
- it(
317
- "should handle PostgreSQL connection string format",
318
- async () => {
319
- if (!hasPostgresCredentials()) {
320
- console.log(
321
- "Skipping: PostgreSQL credentials not configured",
322
- );
323
- return;
324
- }
325
-
326
- const connectionString = `host=${process.env.POSTGRES_TEST_HOST} port=${process.env.POSTGRES_TEST_PORT || "5432"} dbname=${process.env.POSTGRES_TEST_DATABASE} user=${process.env.POSTGRES_TEST_USER} password=${process.env.POSTGRES_TEST_PASSWORD}`;
327
-
328
- const duckdbConnection: ApiConnection = {
329
- name: "duckdb_pg_string",
330
- type: "duckdb",
331
- duckdbConnection: {
332
- attachedDatabases: [
333
- {
334
- name: "pg_conn_string",
335
- type: "postgres",
336
- postgresConnection: { connectionString },
337
- },
338
- ],
339
- },
340
- };
341
-
342
- const { malloyConnections } = await createProjectConnections(
343
- [duckdbConnection],
344
- testProjectPath,
345
- );
346
-
347
- const connection = malloyConnections.get(
348
- "duckdb_pg_string",
349
- ) as DuckDBConnection;
350
- createdConnections.push(connection);
351
-
352
- const databases = await connection.runSQL("SHOW DATABASES");
353
- const dbNames = databases.rows.map(
354
- (row) => Object.values(row)[0],
355
- );
356
- expect(dbNames).toContain("pg_conn_string");
357
- },
358
- { timeout: 30000 },
359
- );
360
- });
361
-
362
- describe("DuckDB with BigQuery attachment", () => {
363
- it(
364
- "should create DuckDB connection with attached BigQuery database",
365
- async () => {
366
- if (!hasBigQueryCredentials()) {
367
- console.log("Skipping: BigQuery credentials not configured");
368
- return;
369
- }
370
-
371
- const serviceAccountJson =
372
- await readBigQueryServiceAccountJson();
373
-
374
- const duckdbConnection: ApiConnection = {
375
- name: "duckdb_with_bigquery",
376
- type: "duckdb",
377
- duckdbConnection: {
378
- attachedDatabases: [
379
- {
380
- name: "bq_test",
381
- type: "bigquery",
382
- bigqueryConnection: {
383
- defaultProjectId:
384
- process.env.BIGQUERY_TEST_PROJECT_ID!,
385
- serviceAccountKeyJson: serviceAccountJson,
386
- },
387
- },
388
- ],
389
- },
390
- };
391
-
392
- const { malloyConnections } = await createProjectConnections(
393
- [duckdbConnection],
394
- testProjectPath,
395
- );
396
-
397
- const connection = malloyConnections.get(
398
- "duckdb_with_bigquery",
399
- ) as DuckDBConnection;
400
- expect(connection).toBeDefined();
401
- createdConnections.push(connection);
402
-
403
- const databases = await connection.runSQL("SHOW DATABASES");
404
- const dbNames = databases.rows.map(
405
- (row) => Object.values(row)[0],
406
- );
407
- expect(dbNames).toContain("bq_test");
408
- },
409
- { timeout: 60000 },
410
- );
411
-
412
- it(
413
- "should list datasets (schemas) from attached BigQuery database",
414
- async () => {
415
- if (
416
- !hasBigQueryCredentials() ||
417
- !process.env.BIGQUERY_TEST_DATASET
418
- ) {
419
- console.log(
420
- "Skipping: GOOGLE_APPLICATION_CREDENTIALS, BIGQUERY_TEST_PROJECT_ID, or BIGQUERY_TEST_DATASET not configured",
421
- );
422
- return;
423
- }
424
-
425
- const serviceAccountJson =
426
- await readBigQueryServiceAccountJson();
427
-
428
- const duckdbConnection: ApiConnection = {
429
- name: "duckdb_bq_schemas",
430
- type: "duckdb",
431
- duckdbConnection: {
432
- attachedDatabases: [
433
- {
434
- name: "bq_schemas",
435
- type: "bigquery",
436
- bigqueryConnection: {
437
- defaultProjectId:
438
- process.env.BIGQUERY_TEST_PROJECT_ID!,
439
- serviceAccountKeyJson: serviceAccountJson,
440
- },
441
- },
442
- ],
443
- },
444
- };
445
-
446
- const { malloyConnections } = await createProjectConnections(
447
- [duckdbConnection],
448
- testProjectPath,
449
- );
450
-
451
- const connection = malloyConnections.get(
452
- "duckdb_bq_schemas",
453
- ) as DuckDBConnection;
454
- createdConnections.push(connection);
455
-
456
- const result = await connection.runSQL(
457
- "SELECT schema_name FROM bq_schemas.information_schema.schemata",
458
- );
459
- expect(result.rows.length).toBeGreaterThan(0);
460
- const datasetNames = result.rows.map(
461
- (row) => Object.values(row)[0] as string,
462
- );
463
- expect(datasetNames).toContain(
464
- process.env.BIGQUERY_TEST_DATASET!,
465
- );
466
- },
467
- { timeout: 60000 },
468
- );
469
-
470
- it(
471
- "should list tables from attached BigQuery dataset",
472
- async () => {
473
- if (
474
- !hasBigQueryCredentials() ||
475
- !process.env.BIGQUERY_TEST_DATASET
476
- ) {
477
- console.log(
478
- "Skipping: GOOGLE_APPLICATION_CREDENTIALS, BIGQUERY_TEST_PROJECT_ID, or BIGQUERY_TEST_DATASET not configured",
479
- );
480
- return;
481
- }
482
-
483
- const serviceAccountJson =
484
- await readBigQueryServiceAccountJson();
485
-
486
- const duckdbConnection: ApiConnection = {
487
- name: "duckdb_bq_tables",
488
- type: "duckdb",
489
- duckdbConnection: {
490
- attachedDatabases: [
491
- {
492
- name: "bq_tables",
493
- type: "bigquery",
494
- bigqueryConnection: {
495
- defaultProjectId:
496
- process.env.BIGQUERY_TEST_PROJECT_ID!,
497
- serviceAccountKeyJson: serviceAccountJson,
498
- },
499
- },
500
- ],
501
- },
502
- };
503
-
504
- const { malloyConnections } = await createProjectConnections(
505
- [duckdbConnection],
506
- testProjectPath,
507
- );
508
-
509
- const connection = malloyConnections.get(
510
- "duckdb_bq_tables",
511
- ) as DuckDBConnection;
512
- createdConnections.push(connection);
513
-
514
- const result = await connection.runSQL(`
515
- SELECT table_name, table_type
516
- FROM bq_tables.${process.env.BIGQUERY_TEST_DATASET!}.INFORMATION_SCHEMA.TABLES
517
- ORDER BY table_name
518
- `);
519
- expect(result.rows.length).toBeGreaterThan(0);
520
- },
521
- { timeout: 60000 },
522
- );
523
-
524
- it(
525
- "should get table columns from attached BigQuery table",
526
- async () => {
527
- if (
528
- !hasBigQueryCredentials() ||
529
- !process.env.BIGQUERY_TEST_TABLE
530
- ) {
531
- console.log(
532
- "Skipping: GOOGLE_APPLICATION_CREDENTIALS, BIGQUERY_TEST_PROJECT_ID, or BIGQUERY_TEST_TABLE not configured",
533
- );
534
- return;
535
- }
536
-
537
- const serviceAccountJson =
538
- await readBigQueryServiceAccountJson();
539
- const [dataset, table] =
540
- process.env.BIGQUERY_TEST_TABLE!.split(".");
541
-
542
- const duckdbConnection: ApiConnection = {
543
- name: "duckdb_bq_cols",
544
- type: "duckdb",
545
- duckdbConnection: {
546
- attachedDatabases: [
547
- {
548
- name: "bq_cols",
549
- type: "bigquery",
550
- bigqueryConnection: {
551
- defaultProjectId:
552
- process.env.BIGQUERY_TEST_PROJECT_ID!,
553
- serviceAccountKeyJson: serviceAccountJson,
554
- },
555
- },
556
- ],
557
- },
558
- };
559
-
560
- const { malloyConnections } = await createProjectConnections(
561
- [duckdbConnection],
562
- testProjectPath,
563
- );
564
-
565
- const connection = malloyConnections.get(
566
- "duckdb_bq_cols",
567
- ) as DuckDBConnection;
568
- createdConnections.push(connection);
569
-
570
- // getTable equivalent — fetch column metadata
571
- const result = await connection.runSQL(`
572
- SELECT column_name, data_type, is_nullable
573
- FROM bq_cols.${dataset}.INFORMATION_SCHEMA.COLUMNS
574
- WHERE table_name = '${table}'
575
- ORDER BY ordinal_position
576
- `);
577
- expect(result.rows.length).toBeGreaterThan(0);
578
- },
579
- { timeout: 60000 },
580
- );
581
-
582
- it(
583
- "should query data from attached BigQuery table",
584
- async () => {
585
- if (
586
- !hasBigQueryCredentials() ||
587
- !process.env.BIGQUERY_TEST_TABLE
588
- ) {
589
- console.log(
590
- "Skipping: GOOGLE_APPLICATION_CREDENTIALS, BIGQUERY_TEST_PROJECT_ID, or BIGQUERY_TEST_TABLE not configured",
591
- );
592
- return;
593
- }
594
-
595
- const serviceAccountJson =
596
- await readBigQueryServiceAccountJson();
597
-
598
- const duckdbConnection: ApiConnection = {
599
- name: "duckdb_bq_query",
600
- type: "duckdb",
601
- duckdbConnection: {
602
- attachedDatabases: [
603
- {
604
- name: "bq_query",
605
- type: "bigquery",
606
- bigqueryConnection: {
607
- defaultProjectId:
608
- process.env.BIGQUERY_TEST_PROJECT_ID!,
609
- serviceAccountKeyJson: serviceAccountJson,
610
- },
611
- },
612
- ],
613
- },
614
- };
615
-
616
- const { malloyConnections } = await createProjectConnections(
617
- [duckdbConnection],
618
- testProjectPath,
619
- );
620
-
621
- const connection = malloyConnections.get(
622
- "duckdb_bq_query",
623
- ) as DuckDBConnection;
624
- createdConnections.push(connection);
625
-
626
- const result = await connection.runSQL(
627
- `SELECT * FROM bq_query.${process.env.BIGQUERY_TEST_TABLE!} LIMIT 1`,
628
- );
629
- expect(result.rows).toBeDefined();
630
- expect(result.rows.length).toBeGreaterThan(0);
631
- },
632
- { timeout: 60000 },
633
- );
634
-
635
- it(
636
- "should validate BigQuery service account key format",
637
- async () => {
638
- await expect(
639
- createProjectConnections(
640
- [
641
- {
642
- name: "duckdb_bq_invalid",
643
- type: "duckdb",
644
- duckdbConnection: {
645
- attachedDatabases: [
646
- {
647
- name: "bq_invalid",
648
- type: "bigquery",
649
- bigqueryConnection: {
650
- defaultProjectId: "test-project",
651
- serviceAccountKeyJson: JSON.stringify({
652
- invalid: "key",
653
- }),
654
- },
655
- },
656
- ],
657
- },
658
- },
659
- ],
660
- testProjectPath,
661
- ),
662
- ).rejects.toThrow(/Invalid service account key/);
663
- },
664
- { timeout: 30000 },
665
- );
666
- });
667
-
668
- describe("DuckDB with Snowflake attachment", () => {
669
- it(
670
- "should create DuckDB connection with attached Snowflake database",
671
- async () => {
672
- if (!hasSnowflakeCredentials()) {
673
- console.log("Skipping: Snowflake credentials not configured");
674
- return;
675
- }
676
-
677
- const duckdbConnection: ApiConnection = {
678
- name: "duckdb_with_snowflake",
679
- type: "duckdb",
680
- duckdbConnection: {
681
- attachedDatabases: [
682
- {
683
- name: "sf_test",
684
- type: "snowflake",
685
- snowflakeConnection: {
686
- account: process.env.SNOWFLAKE_TEST_ACCOUNT!,
687
- username: process.env.SNOWFLAKE_TEST_USER!,
688
- password: process.env.SNOWFLAKE_TEST_PASSWORD!,
689
- warehouse: process.env.SNOWFLAKE_TEST_WAREHOUSE!,
690
- database: process.env.SNOWFLAKE_TEST_DATABASE,
691
- schema: process.env.SNOWFLAKE_TEST_SCHEMA,
692
- },
693
- },
694
- ],
695
- },
696
- };
697
-
698
- const { malloyConnections } = await createProjectConnections(
699
- [duckdbConnection],
700
- testProjectPath,
701
- );
702
-
703
- const connection = malloyConnections.get(
704
- "duckdb_with_snowflake",
705
- ) as DuckDBConnection;
706
- expect(connection).toBeDefined();
707
- createdConnections.push(connection);
708
-
709
- const databases = await connection.runSQL("SHOW DATABASES");
710
- const dbNames = databases.rows.map(
711
- (row) => Object.values(row)[0],
712
- );
713
- expect(dbNames).toContain("sf_test");
714
-
715
- const result = await connection.runSQL(
716
- "SELECT * FROM snowflake_query('SELECT 1 as test', 'sf_test_secret')",
717
- );
718
- expect(result.rows).toBeDefined();
719
- },
720
- { timeout: 30000 },
721
- );
722
-
723
- it("should validate required Snowflake fields", async () => {
724
- await expect(
725
- createProjectConnections(
726
- [
727
- {
728
- name: "duckdb_sf_incomplete",
729
- type: "duckdb",
730
- duckdbConnection: {
731
- attachedDatabases: [
732
- {
733
- name: "sf_incomplete",
734
- type: "snowflake",
735
- snowflakeConnection: {
736
- account: "test-account",
737
- username: "test-user",
738
- },
739
- },
740
- ],
741
- },
742
- },
743
- ],
744
- testProjectPath,
745
- ),
746
- ).rejects.toThrow(/required/);
747
- });
748
- });
749
-
750
- describe("DuckDB with S3 attachment", () => {
751
- it(
752
- "should create DuckDB connection with S3 configuration",
753
- async () => {
754
- if (!hasS3Credentials()) {
755
- console.log("Skipping: S3 credentials not configured");
756
- return;
757
- }
758
-
759
- const duckdbConnection: ApiConnection = {
760
- name: "duckdb_with_s3",
761
- type: "duckdb",
762
- duckdbConnection: {
763
- attachedDatabases: [
764
- {
765
- name: "s3_test",
766
- type: "s3",
767
- s3Connection: {
768
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
769
- secretAccessKey:
770
- process.env.S3_TEST_SECRET_ACCESS_KEY!,
771
- region: process.env.S3_TEST_REGION || "us-east-1",
772
- },
773
- },
774
- ],
775
- },
776
- };
777
-
778
- const { malloyConnections } = await createProjectConnections(
779
- [duckdbConnection],
780
- testProjectPath,
781
- );
782
-
783
- const connection = malloyConnections.get(
784
- "duckdb_with_s3",
785
- ) as DuckDBConnection;
786
- expect(connection).toBeDefined();
787
- createdConnections.push(connection);
788
-
789
- const secrets = await connection.runSQL(
790
- "SELECT name FROM duckdb_secrets()",
791
- );
792
- const secretNames = secrets.rows.map(
793
- (row) => Object.values(row)[0],
794
- );
795
- expect(
796
- secretNames.some((name) => String(name).includes("s3")),
797
- ).toBe(true);
798
- },
799
- { timeout: 30000 },
800
- );
801
-
802
- it(
803
- "should handle S3 with custom endpoint",
804
- async () => {
805
- if (!hasS3Credentials()) {
806
- console.log("Skipping: S3 credentials not configured");
807
- return;
808
- }
809
-
810
- const duckdbConnection: ApiConnection = {
811
- name: "duckdb_s3_custom",
812
- type: "duckdb",
813
- duckdbConnection: {
814
- attachedDatabases: [
815
- {
816
- name: "s3_custom",
817
- type: "s3",
818
- s3Connection: {
819
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
820
- secretAccessKey:
821
- process.env.S3_TEST_SECRET_ACCESS_KEY!,
822
- region: "us-east-1",
823
- endpoint: "https://s3.custom-endpoint.com",
824
- },
825
- },
826
- ],
827
- },
828
- };
829
-
830
- const { malloyConnections } = await createProjectConnections(
831
- [duckdbConnection],
832
- testProjectPath,
833
- );
834
-
835
- const connection = malloyConnections.get(
836
- "duckdb_s3_custom",
837
- ) as DuckDBConnection;
838
- createdConnections.push(connection);
839
- expect(connection).toBeDefined();
840
- },
841
- { timeout: 30000 },
842
- );
843
- });
844
-
845
- describe("DuckDB with GCS attachment", () => {
846
- it(
847
- "should create DuckDB connection with GCS configuration",
848
- async () => {
849
- if (!hasGCSCredentials()) {
850
- console.log("Skipping: GCS credentials not configured");
851
- return;
852
- }
853
-
854
- const duckdbConnection: ApiConnection = {
855
- name: "duckdb_with_gcs",
856
- type: "duckdb",
857
- duckdbConnection: {
858
- attachedDatabases: [
859
- {
860
- name: "gcs_test",
861
- type: "gcs",
862
- gcsConnection: {
863
- keyId: process.env.GCS_TEST_KEY_ID!,
864
- secret: process.env.GCS_TEST_SECRET!,
865
- },
866
- },
867
- ],
868
- },
869
- };
870
-
871
- const { malloyConnections } = await createProjectConnections(
872
- [duckdbConnection],
873
- testProjectPath,
874
- );
875
-
876
- const connection = malloyConnections.get(
877
- "duckdb_with_gcs",
878
- ) as DuckDBConnection;
879
- expect(connection).toBeDefined();
880
- createdConnections.push(connection);
881
-
882
- const secrets = await connection.runSQL(
883
- "SELECT name FROM duckdb_secrets()",
884
- );
885
- const secretNames = secrets.rows.map(
886
- (row) => Object.values(row)[0],
887
- );
888
- expect(
889
- secretNames.some((name) => String(name).includes("gcs")),
890
- ).toBe(true);
891
- },
892
- { timeout: 30000 },
893
- );
894
- });
895
-
896
- describe("DuckDB with multiple attachments", () => {
897
- it(
898
- "should attach multiple databases to single DuckDB connection",
899
- async () => {
900
- const attachments: AttachedDatabase[] = [];
901
-
902
- if (hasPostgresCredentials()) {
903
- attachments.push({
904
- name: "pg_multi",
905
- type: "postgres",
906
- postgresConnection: {
907
- host: process.env.POSTGRES_TEST_HOST,
908
- port: parseInt(
909
- process.env.POSTGRES_TEST_PORT || "5432",
910
- ),
911
- userName: process.env.POSTGRES_TEST_USER!,
912
- password: process.env.POSTGRES_TEST_PASSWORD!,
913
- databaseName: process.env.POSTGRES_TEST_DATABASE,
914
- },
915
- });
916
- }
917
-
918
- if (hasBigQueryCredentials()) {
919
- const serviceAccountJson =
920
- await readBigQueryServiceAccountJson();
921
- attachments.push({
922
- name: "bq_multi",
923
- type: "bigquery",
924
- bigqueryConnection: {
925
- defaultProjectId: process.env.BIGQUERY_TEST_PROJECT_ID!,
926
- serviceAccountKeyJson: serviceAccountJson,
927
- },
928
- });
929
- }
930
-
931
- if (hasS3Credentials()) {
932
- attachments.push({
933
- name: "s3_multi",
934
- type: "s3",
935
- s3Connection: {
936
- accessKeyId: process.env.S3_TEST_ACCESS_KEY_ID!,
937
- secretAccessKey: process.env.S3_TEST_SECRET_ACCESS_KEY!,
938
- region: process.env.S3_TEST_REGION || "us-east-1",
939
- },
940
- });
941
- }
942
-
943
- if (attachments.length === 0) {
944
- console.log("Skipping: No database credentials configured");
945
- return;
946
- }
947
-
948
- const { malloyConnections } = await createProjectConnections(
949
- [
950
- {
951
- name: "duckdb_multi",
952
- type: "duckdb",
953
- duckdbConnection: { attachedDatabases: attachments },
954
- },
955
- ],
956
- testProjectPath,
957
- );
958
-
959
- const connection = malloyConnections.get(
960
- "duckdb_multi",
961
- ) as DuckDBConnection;
962
- expect(connection).toBeDefined();
963
- createdConnections.push(connection);
964
-
965
- const databases = await connection.runSQL("SHOW DATABASES");
966
- const dbNames = databases.rows.map(
967
- (row) => Object.values(row)[0],
968
- );
969
- attachments.forEach((attachment) => {
970
- expect(dbNames).toContain(attachment.name!);
971
- });
972
- },
973
- { timeout: 60000 },
974
- );
975
- });
976
-
977
- describe("error handling", () => {
978
- describe("DuckLake connection type", () => {
979
- it(
980
- "should create DuckLake connection",
981
- async () => {
982
- if (!hasPostgresCredentials() || !hasS3Credentials()) {
983
- console.log(
984
- "Skipping: PostgreSQL and S3 credentials not configured",
985
- );
986
- return;
987
- }
988
-
989
- const { malloyConnections } = await createProjectConnections(
990
- [
991
- {
992
- name: "ducklake_test",
993
- type: "ducklake",
994
- ducklakeConnection: {
995
- catalog: {
996
- postgresConnection: {
997
- host: process.env.POSTGRES_TEST_HOST,
998
- port: parseInt(
999
- process.env.POSTGRES_TEST_PORT || "5432",
1000
- ),
1001
- userName: process.env.POSTGRES_TEST_USER!,
1002
- password:
1003
- process.env.POSTGRES_TEST_PASSWORD!,
1004
- databaseName:
1005
- process.env.POSTGRES_TEST_DATABASE,
1006
- },
1007
- },
1008
- storage: {
1009
- bucketUrl:
1010
- process.env.S3_TEST_BUCKET_URL ||
1011
- "s3://test-bucket",
1012
- s3Connection: {
1013
- accessKeyId:
1014
- process.env.S3_TEST_ACCESS_KEY_ID!,
1015
- secretAccessKey:
1016
- process.env.S3_TEST_SECRET_ACCESS_KEY!,
1017
- },
1018
- },
1019
- },
1020
- },
1021
- ],
1022
- testProjectPath,
1023
- );
1024
-
1025
- const connection = malloyConnections.get(
1026
- "ducklake_test",
1027
- ) as DuckDBConnection;
1028
- createdConnections.push(connection);
1029
- expect(connection).toBeDefined();
1030
-
1031
- // Verify DuckLake database is attached
1032
- const databases = await connection.runSQL("SHOW DATABASES");
1033
- const dbNames = databases.rows.map(
1034
- (row) => Object.values(row)[0],
1035
- );
1036
- expect(dbNames).toContain("ducklake_test");
1037
- },
1038
- { timeout: 30000 },
1039
- );
1040
-
1041
- it("should throw error if DuckLake catalog connection is missing", async () => {
1042
- await expect(
1043
- createProjectConnections(
1044
- [
1045
- {
1046
- name: "ducklake_no_catalog",
1047
- type: "ducklake",
1048
- ducklakeConnection: {
1049
- storage: {
1050
- bucketUrl: "s3://test-bucket",
1051
- s3Connection: {
1052
- accessKeyId: "test",
1053
- secretAccessKey: "test",
1054
- },
1055
- },
1056
- },
1057
- } as ApiConnection,
1058
- ],
1059
- testProjectPath,
1060
- ),
1061
- ).rejects.toThrow(
1062
- /PostgreSQL connection configuration is required/,
1063
- );
1064
- });
1065
-
1066
- it("should throw error if DuckLake connection config is missing", async () => {
1067
- await expect(
1068
- createProjectConnections(
1069
- [
1070
- {
1071
- name: "ducklake_missing_config",
1072
- type: "ducklake",
1073
- },
1074
- ],
1075
- testProjectPath,
1076
- ),
1077
- ).rejects.toThrow(
1078
- /DuckLake connection configuration is missing/,
1079
- );
1080
- });
1081
- });
1082
-
1083
- it("should throw error if DuckDB connection name conflicts with attached database", async () => {
1084
- await expect(
1085
- createProjectConnections(
1086
- [
1087
- {
1088
- name: "conflict_db",
1089
- type: "duckdb",
1090
- duckdbConnection: {
1091
- attachedDatabases: [
1092
- {
1093
- name: "conflict_db",
1094
- type: "postgres",
1095
- postgresConnection: {
1096
- connectionString:
1097
- "postgresql://localhost/test",
1098
- },
1099
- },
1100
- ],
1101
- },
1102
- },
1103
- ],
1104
- testProjectPath,
1105
- ),
1106
- ).rejects.toThrow(/cannot conflict/);
1107
- });
1108
-
1109
- it("should throw error if connection name is 'duckdb'", async () => {
1110
- await expect(
1111
- createProjectConnections(
1112
- [
1113
- {
1114
- name: "duckdb",
1115
- type: "duckdb",
1116
- duckdbConnection: { attachedDatabases: [] },
1117
- },
1118
- ],
1119
- testProjectPath,
1120
- ),
1121
- ).rejects.toThrow(/cannot be 'duckdb'/);
1122
- });
1123
-
1124
- it("should throw error if no attached databases configured", async () => {
1125
- await expect(
1126
- createProjectConnections(
1127
- [
1128
- {
1129
- name: "empty_duckdb",
1130
- type: "duckdb",
1131
- duckdbConnection: { attachedDatabases: [] },
1132
- },
1133
- ],
1134
- testProjectPath,
1135
- ),
1136
- ).rejects.toThrow(/at least one attached database/);
1137
- });
1138
-
1139
- it("should handle already attached database gracefully", async () => {
1140
- if (!hasPostgresCredentials()) {
1141
- console.log("Skipping: PostgreSQL credentials not configured");
1142
- return;
1143
- }
1144
-
1145
- const postgresAttachment: AttachedDatabase = {
1146
- name: "pg_duplicate",
1147
- type: "postgres",
1148
- postgresConnection: {
1149
- host: process.env.POSTGRES_TEST_HOST,
1150
- port: parseInt(process.env.POSTGRES_TEST_PORT || "5432"),
1151
- userName: process.env.POSTGRES_TEST_USER!,
1152
- password: process.env.POSTGRES_TEST_PASSWORD!,
1153
- databaseName: process.env.POSTGRES_TEST_DATABASE,
1154
- },
1155
- };
1156
-
1157
- const { malloyConnections } = await createProjectConnections(
1158
- [
1159
- {
1160
- name: "duckdb_duplicate_test",
1161
- type: "duckdb",
1162
- duckdbConnection: {
1163
- attachedDatabases: [
1164
- postgresAttachment,
1165
- postgresAttachment,
1166
- ],
1167
- },
1168
- },
1169
- ],
1170
- testProjectPath,
1171
- );
1172
-
1173
- const connection = malloyConnections.get(
1174
- "duckdb_duplicate_test",
1175
- ) as DuckDBConnection;
1176
- createdConnections.push(connection);
1177
- expect(connection).toBeDefined();
1178
- });
1179
- });
1180
- });
1181
-
1182
- describe("testConnectionConfig", () => {
1183
- it(
1184
- "should successfully test valid PostgreSQL connection",
1185
- async () => {
1186
- if (!hasPostgresCredentials()) {
1187
- console.log("Skipping: PostgreSQL credentials not configured");
1188
- return;
1189
- }
1190
-
1191
- const result = await testConnectionConfig({
1192
- name: "test_postgres",
1193
- type: "postgres",
1194
- postgresConnection: {
1195
- host: process.env.POSTGRES_TEST_HOST,
1196
- port: parseInt(process.env.POSTGRES_TEST_PORT || "5432"),
1197
- userName: process.env.POSTGRES_TEST_USER!,
1198
- password: process.env.POSTGRES_TEST_PASSWORD!,
1199
- databaseName: process.env.POSTGRES_TEST_DATABASE,
1200
- },
1201
- });
1202
-
1203
- expect(result.status).toBe("ok");
1204
- expect(result.errorMessage).toBe("");
1205
- },
1206
- { timeout: 30000 },
1207
- );
1208
-
1209
- it(
1210
- "should fail for invalid PostgreSQL credentials",
1211
- async () => {
1212
- const result = await testConnectionConfig({
1213
- name: "test_postgres_invalid",
1214
- type: "postgres",
1215
- postgresConnection: {
1216
- host: process.env.POSTGRES_TEST_HOST,
1217
- port: parseInt(process.env.POSTGRES_TEST_PORT || "5432"),
1218
- userName: "invalid_user",
1219
- password: "invalid_password",
1220
- databaseName: "nonexistent",
1221
- },
1222
- });
1223
-
1224
- expect(result.status).toBe("failed");
1225
- expect(result.errorMessage).toBeDefined();
1226
- },
1227
- { timeout: 30000 },
1228
- );
1229
-
1230
- it("should fail for missing connection name", async () => {
1231
- const result = await testConnectionConfig({
1232
- name: "",
1233
- type: "postgres",
1234
- postgresConnection: {},
1235
- });
1236
-
1237
- expect(result.status).toBe("failed");
1238
- expect(result.errorMessage).toContain("name is required");
1239
- });
1240
- });
1241
-
1242
- describe("SQL injection prevention", () => {
1243
- it("should properly escape special characters in credentials", async () => {
1244
- if (!hasPostgresCredentials()) {
1245
- console.log("Skipping: PostgreSQL credentials not configured");
1246
- return;
1247
- }
1248
-
1249
- const { malloyConnections } = await createProjectConnections(
1250
- [
1251
- {
1252
- name: "duckdb_special_chars",
1253
- type: "duckdb",
1254
- duckdbConnection: {
1255
- attachedDatabases: [
1256
- {
1257
- name: "pg_special",
1258
- type: "postgres",
1259
- postgresConnection: {
1260
- host: process.env.POSTGRES_TEST_HOST,
1261
- port: parseInt(
1262
- process.env.POSTGRES_TEST_PORT || "5432",
1263
- ),
1264
- userName: process.env.POSTGRES_TEST_USER!,
1265
- password: process.env.POSTGRES_TEST_PASSWORD!,
1266
- databaseName: process.env.POSTGRES_TEST_DATABASE,
1267
- },
1268
- },
1269
- ],
1270
- },
1271
- },
1272
- ],
1273
- testProjectPath,
1274
- );
1275
-
1276
- const connection = malloyConnections.get(
1277
- "duckdb_special_chars",
1278
- ) as DuckDBConnection;
1279
- createdConnections.push(connection);
1280
- expect(connection).toBeDefined();
1281
- });
1282
- });
1283
-
1284
- describe("connection attributes", () => {
1285
- it(
1286
- "should return correct attributes for DuckDB connection",
1287
- async () => {
1288
- if (!hasPostgresCredentials()) {
1289
- console.log("Skipping: PostgreSQL credentials not configured");
1290
- return;
1291
- }
1292
-
1293
- const { apiConnections } = await createProjectConnections(
1294
- [
1295
- {
1296
- name: "duckdb_attrs",
1297
- type: "duckdb",
1298
- duckdbConnection: {
1299
- attachedDatabases: [
1300
- {
1301
- name: "pg_attrs",
1302
- type: "postgres",
1303
- postgresConnection: {
1304
- host: process.env.POSTGRES_TEST_HOST,
1305
- port: parseInt(
1306
- process.env.POSTGRES_TEST_PORT || "5432",
1307
- ),
1308
- userName: process.env.POSTGRES_TEST_USER!,
1309
- password: process.env.POSTGRES_TEST_PASSWORD!,
1310
- databaseName:
1311
- process.env.POSTGRES_TEST_DATABASE,
1312
- },
1313
- },
1314
- ],
1315
- },
1316
- },
1317
- ],
1318
- testProjectPath,
1319
- );
1320
-
1321
- const connection = apiConnections[0];
1322
- expect(connection.attributes).toBeDefined();
1323
- expect(connection.attributes?.dialectName).toBe("duckdb");
1324
- expect(typeof connection.attributes?.canPersist).toBe("boolean");
1325
- expect(typeof connection.attributes?.canStream).toBe("boolean");
1326
- expect(typeof connection.attributes?.isPool).toBe("boolean");
1327
- },
1328
- { timeout: 30000 },
1329
- );
1330
- });
1331
- });