@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,714 +0,0 @@
1
- import { describe, expect, it, mock } from "bun:test";
2
-
3
- // Stub the missing optional dependency so db_utils.ts can be imported
4
- mock.module("@azure/identity", () => ({
5
- ClientSecretCredential: class {},
6
- }));
7
- mock.module("@azure/storage-blob", () => ({
8
- ContainerClient: class {},
9
- }));
10
- mock.module("@google-cloud/bigquery", () => ({
11
- BigQuery: class {},
12
- }));
13
-
14
- import { Connection } from "@malloydata/malloy";
15
- import { normalizeQueryArray } from "../server";
16
- import {
17
- extractErrorDataFromError,
18
- getSchemasForConnection,
19
- listTablesForSchema,
20
- sqlInFilter,
21
- } from "./db_utils";
22
- import { components } from "../api";
23
-
24
- type ApiConnection = components["schemas"]["Connection"];
25
-
26
- /**
27
- * Minimal mock Connection whose runSQL captures the SQL string
28
- * and returns configurable rows.
29
- */
30
- function mockConnection(rows: unknown[] = []) {
31
- let lastSQL = "";
32
- return {
33
- get lastSQL() {
34
- return lastSQL;
35
- },
36
- conn: {
37
- runSQL: async (sql: string) => {
38
- lastSQL = sql;
39
- return { rows };
40
- },
41
- } as unknown as Connection,
42
- };
43
- }
44
-
45
- // ---------------------------------------------------------------------------
46
- // sqlInFilter
47
- // ---------------------------------------------------------------------------
48
- describe("sqlInFilter", () => {
49
- it("returns empty string for undefined", () => {
50
- expect(sqlInFilter("col", undefined)).toBe("");
51
- });
52
-
53
- it("returns empty string for empty array", () => {
54
- expect(sqlInFilter("col", [])).toBe("");
55
- });
56
-
57
- it("builds single-value IN clause", () => {
58
- expect(sqlInFilter("TABLE_NAME", ["orders"])).toBe(
59
- "AND TABLE_NAME IN ('orders')",
60
- );
61
- });
62
-
63
- it("builds multi-value IN clause", () => {
64
- expect(sqlInFilter("t", ["a", "b", "c"])).toBe(
65
- "AND t IN ('a', 'b', 'c')",
66
- );
67
- });
68
-
69
- it("escapes single quotes in values", () => {
70
- expect(sqlInFilter("t", ["it's", "a'b"])).toBe(
71
- "AND t IN ('it''s', 'a''b')",
72
- );
73
- });
74
- });
75
-
76
- // ---------------------------------------------------------------------------
77
- // normalizeQueryArray
78
- // ---------------------------------------------------------------------------
79
- describe("normalizeQueryArray", () => {
80
- it("returns undefined for undefined", () => {
81
- expect(normalizeQueryArray(undefined)).toBeUndefined();
82
- });
83
-
84
- it("returns undefined for null", () => {
85
- expect(normalizeQueryArray(null)).toBeUndefined();
86
- });
87
-
88
- it("wraps a single string in an array", () => {
89
- expect(normalizeQueryArray("table1")).toEqual(["table1"]);
90
- });
91
-
92
- it("passes through an array of strings", () => {
93
- expect(normalizeQueryArray(["a", "b"])).toEqual(["a", "b"]);
94
- });
95
-
96
- it("converts non-string array elements to strings", () => {
97
- expect(normalizeQueryArray([1, true])).toEqual(["1", "true"]);
98
- });
99
-
100
- it("converts a numeric value to a string array", () => {
101
- expect(normalizeQueryArray(42)).toEqual(["42"]);
102
- });
103
- });
104
-
105
- // ---------------------------------------------------------------------------
106
- // listTablesForSchema – SQL generation & result grouping
107
- // ---------------------------------------------------------------------------
108
- describe("listTablesForSchema", () => {
109
- const columnRows = [
110
- { TABLE_NAME: "orders", COLUMN_NAME: "id", DATA_TYPE: "INTEGER" },
111
- { TABLE_NAME: "orders", COLUMN_NAME: "total", DATA_TYPE: "DECIMAL" },
112
- { TABLE_NAME: "customers", COLUMN_NAME: "id", DATA_TYPE: "INTEGER" },
113
- { TABLE_NAME: "customers", COLUMN_NAME: "name", DATA_TYPE: "VARCHAR" },
114
- ];
115
-
116
- describe("mysql", () => {
117
- const conn: ApiConnection = {
118
- name: "test",
119
- type: "mysql",
120
- mysqlConnection: {
121
- host: "localhost",
122
- port: 3306,
123
- user: "root",
124
- password: "",
125
- database: "testdb",
126
- },
127
- };
128
-
129
- it("queries INFORMATION_SCHEMA.COLUMNS and groups into ApiTable[]", async () => {
130
- const m = mockConnection(columnRows);
131
- const tables = await listTablesForSchema(conn, "testdb", m.conn);
132
-
133
- expect(m.lastSQL).toContain("information_schema.columns");
134
- expect(m.lastSQL).toContain("table_schema = 'testdb'");
135
- expect(tables).toHaveLength(2);
136
- expect(tables[0].resource).toBe("testdb.orders");
137
- expect(tables[0].columns).toEqual([
138
- { name: "id", type: "integer" },
139
- { name: "total", type: "decimal" },
140
- ]);
141
- expect(tables[1].resource).toBe("testdb.customers");
142
- });
143
-
144
- it("includes IN filter when tableNames provided", async () => {
145
- const m = mockConnection(columnRows.slice(0, 2));
146
- await listTablesForSchema(conn, "testdb", m.conn, ["orders"]);
147
- expect(m.lastSQL).toContain("AND TABLE_NAME IN ('orders')");
148
- });
149
-
150
- it("omits IN filter when tableNames is undefined", async () => {
151
- const m = mockConnection(columnRows);
152
- await listTablesForSchema(conn, "testdb", m.conn);
153
- expect(m.lastSQL).not.toContain("IN (");
154
- });
155
- });
156
-
157
- describe("postgres", () => {
158
- const conn: ApiConnection = {
159
- name: "test",
160
- type: "postgres",
161
- postgresConnection: {
162
- host: "localhost",
163
- port: 5432,
164
- userName: "postgres",
165
- password: "",
166
- databaseName: "testdb",
167
- },
168
- };
169
-
170
- it("queries information_schema.columns wrapped in row_to_json", async () => {
171
- const m = mockConnection(columnRows);
172
- const tables = await listTablesForSchema(conn, "public", m.conn);
173
-
174
- expect(m.lastSQL).toContain("row_to_json");
175
- expect(m.lastSQL).toContain("information_schema.columns");
176
- expect(m.lastSQL).toContain("table_schema = 'public'");
177
- expect(tables).toHaveLength(2);
178
- expect(tables[0].resource).toBe("public.orders");
179
- });
180
-
181
- it("includes IN filter when tableNames provided", async () => {
182
- const m = mockConnection([]);
183
- await listTablesForSchema(conn, "public", m.conn, ["orders"]);
184
- expect(m.lastSQL).toContain("AND table_name IN ('orders')");
185
- });
186
- });
187
-
188
- describe("snowflake", () => {
189
- const conn: ApiConnection = {
190
- name: "test",
191
- type: "snowflake",
192
- snowflakeConnection: {
193
- account: "test_account",
194
- username: "user",
195
- password: "pass",
196
- database: "MY_DB",
197
- schema: "PUBLIC",
198
- },
199
- };
200
-
201
- it("queries DATABASE.INFORMATION_SCHEMA.COLUMNS", async () => {
202
- const m = mockConnection(columnRows);
203
- const tables = await listTablesForSchema(conn, "MY_DB.PUBLIC", m.conn);
204
-
205
- expect(m.lastSQL).toContain("MY_DB.INFORMATION_SCHEMA.COLUMNS");
206
- expect(m.lastSQL).toContain("TABLE_SCHEMA = 'PUBLIC'");
207
- expect(tables).toHaveLength(2);
208
- expect(tables[0].resource).toBe("MY_DB.PUBLIC.orders");
209
- });
210
-
211
- it("falls back to connection database when schema is unqualified", async () => {
212
- const m = mockConnection(columnRows);
213
- const tables = await listTablesForSchema(conn, "PUBLIC", m.conn);
214
-
215
- expect(m.lastSQL).toContain("MY_DB.INFORMATION_SCHEMA.COLUMNS");
216
- expect(tables[0].resource).toBe("MY_DB.PUBLIC.orders");
217
- });
218
-
219
- it("includes IN filter when tableNames provided", async () => {
220
- const m = mockConnection([]);
221
- await listTablesForSchema(conn, "MY_DB.PUBLIC", m.conn, [
222
- "orders",
223
- "customers",
224
- ]);
225
- expect(m.lastSQL).toContain(
226
- "AND TABLE_NAME IN ('orders', 'customers')",
227
- );
228
- });
229
- });
230
-
231
- describe("trino", () => {
232
- it("uses catalog-prefixed information_schema.columns", async () => {
233
- const conn: ApiConnection = {
234
- name: "test",
235
- type: "trino",
236
- trinoConnection: {
237
- server: "localhost",
238
- port: 8080,
239
- catalog: "hive",
240
- },
241
- };
242
- const m = mockConnection(columnRows);
243
- const tables = await listTablesForSchema(conn, "default", m.conn);
244
-
245
- expect(m.lastSQL).toContain("hive.information_schema.columns");
246
- expect(m.lastSQL).toContain("table_schema = 'default'");
247
- expect(tables[0].resource).toBe("hive.default.orders");
248
- });
249
-
250
- it("extracts catalog from schemaName when no explicit catalog", async () => {
251
- const conn: ApiConnection = {
252
- name: "test",
253
- type: "trino",
254
- trinoConnection: { server: "localhost", port: 8080 },
255
- };
256
- const m = mockConnection(columnRows);
257
- const tables = await listTablesForSchema(conn, "hive.default", m.conn);
258
-
259
- expect(m.lastSQL).toContain("hive.information_schema.columns");
260
- expect(m.lastSQL).toContain("table_schema = 'default'");
261
- expect(tables[0].resource).toBe("hive.default.orders");
262
- });
263
- });
264
-
265
- describe("duckdb", () => {
266
- const conn: ApiConnection = {
267
- name: "test",
268
- type: "duckdb",
269
- duckdbConnection: {},
270
- };
271
-
272
- it("queries information_schema.columns with catalog and schema", async () => {
273
- const rows = columnRows.map((r) => ({
274
- table_name: r.TABLE_NAME,
275
- column_name: r.COLUMN_NAME,
276
- data_type: r.DATA_TYPE,
277
- }));
278
- const m = mockConnection(rows);
279
- const tables = await listTablesForSchema(conn, "memory.main", m.conn);
280
-
281
- expect(m.lastSQL).toContain("information_schema.columns");
282
- expect(m.lastSQL).toContain("table_schema = 'main'");
283
- expect(m.lastSQL).toContain("table_catalog = 'memory'");
284
- expect(tables).toHaveLength(2);
285
- expect(tables[0].resource).toBe("memory.main.orders");
286
- });
287
- });
288
-
289
- describe("motherduck", () => {
290
- const conn: ApiConnection = {
291
- name: "test",
292
- type: "motherduck",
293
- motherduckConnection: { accessToken: "fake" },
294
- };
295
-
296
- it("queries information_schema.columns", async () => {
297
- const m = mockConnection(columnRows);
298
- const tables = await listTablesForSchema(conn, "main", m.conn);
299
-
300
- expect(m.lastSQL).toContain("information_schema.columns");
301
- expect(m.lastSQL).toContain("table_schema = 'main'");
302
- expect(tables).toHaveLength(2);
303
- expect(tables[0].resource).toBe("main.orders");
304
- });
305
- });
306
-
307
- describe("ducklake", () => {
308
- const conn: ApiConnection = {
309
- name: "test",
310
- type: "ducklake",
311
- ducklakeConnection: {
312
- catalog: {
313
- postgresConnection: {
314
- host: "localhost",
315
- port: 5432,
316
- userName: "postgres",
317
- password: "",
318
- databaseName: "testdb",
319
- },
320
- },
321
- storage: { bucketUrl: "s3://bucket" },
322
- },
323
- };
324
-
325
- it("queries information_schema.columns with catalog and schema", async () => {
326
- const m = mockConnection(columnRows);
327
- const tables = await listTablesForSchema(
328
- conn,
329
- "mycat.myschema",
330
- m.conn,
331
- );
332
-
333
- expect(m.lastSQL).toContain("information_schema.columns");
334
- expect(m.lastSQL).toContain("table_schema = 'myschema'");
335
- expect(m.lastSQL).toContain("table_catalog = 'mycat'");
336
- expect(tables[0].resource).toBe("mycat.myschema.orders");
337
- });
338
- });
339
-
340
- describe("column grouping", () => {
341
- it("lowercases data types", async () => {
342
- const conn: ApiConnection = {
343
- name: "test",
344
- type: "mysql",
345
- mysqlConnection: {
346
- host: "localhost",
347
- port: 3306,
348
- user: "root",
349
- password: "",
350
- database: "testdb",
351
- },
352
- };
353
- const m = mockConnection([
354
- {
355
- TABLE_NAME: "t",
356
- COLUMN_NAME: "col",
357
- DATA_TYPE: "VARCHAR(255)",
358
- },
359
- ]);
360
- const tables = await listTablesForSchema(conn, "testdb", m.conn);
361
- expect(tables[0]?.columns?.[0]?.type).toBe("varchar(255)");
362
- });
363
-
364
- it("returns empty array when no rows", async () => {
365
- const conn: ApiConnection = {
366
- name: "test",
367
- type: "postgres",
368
- postgresConnection: {
369
- host: "localhost",
370
- port: 5432,
371
- userName: "postgres",
372
- password: "",
373
- databaseName: "testdb",
374
- },
375
- };
376
- const m = mockConnection([]);
377
- const tables = await listTablesForSchema(conn, "public", m.conn);
378
- expect(tables).toEqual([]);
379
- });
380
- });
381
-
382
- describe("error handling", () => {
383
- it("throws for unsupported connection type", async () => {
384
- const conn = {
385
- name: "test",
386
- type: "unsupported",
387
- } as unknown as ApiConnection;
388
- const m = mockConnection();
389
- await expect(
390
- listTablesForSchema(conn, "schema", m.conn),
391
- ).rejects.toThrow("Unsupported connection type");
392
- });
393
-
394
- it("throws when duckdb schema is not qualified", async () => {
395
- const conn: ApiConnection = {
396
- name: "test",
397
- type: "duckdb",
398
- duckdbConnection: {},
399
- };
400
- const m = mockConnection();
401
- await expect(
402
- listTablesForSchema(conn, "main", m.conn),
403
- ).rejects.toThrow('must be qualified as "catalog.schema"');
404
- });
405
-
406
- it("throws when snowflake schema is unqualified and no database configured", async () => {
407
- const conn: ApiConnection = {
408
- name: "test",
409
- type: "snowflake",
410
- snowflakeConnection: {
411
- account: "test_account",
412
- username: "user",
413
- password: "pass",
414
- },
415
- };
416
- const m = mockConnection();
417
- await expect(
418
- listTablesForSchema(conn, "PUBLIC", m.conn),
419
- ).rejects.toThrow("Cannot resolve database");
420
- });
421
- });
422
-
423
- describe("ducklake schema prefixing", () => {
424
- const conn: ApiConnection = {
425
- name: "myconn",
426
- type: "ducklake",
427
- ducklakeConnection: {
428
- catalog: {
429
- postgresConnection: {
430
- host: "localhost",
431
- port: 5432,
432
- userName: "postgres",
433
- password: "",
434
- databaseName: "testdb",
435
- },
436
- },
437
- storage: { bucketUrl: "s3://bucket" },
438
- },
439
- };
440
-
441
- it("prefixes bare schema name with connection name", async () => {
442
- const m = mockConnection([]);
443
- await listTablesForSchema(conn, "main", m.conn);
444
- expect(m.lastSQL).toContain("table_catalog = 'myconn'");
445
- expect(m.lastSQL).toContain("table_schema = 'main'");
446
- });
447
-
448
- it("uses provided catalog when schema is already qualified", async () => {
449
- const m = mockConnection([]);
450
- await listTablesForSchema(conn, "othercat.myschema", m.conn);
451
- expect(m.lastSQL).toContain("table_catalog = 'othercat'");
452
- expect(m.lastSQL).toContain("table_schema = 'myschema'");
453
- });
454
- });
455
- });
456
-
457
- // ---------------------------------------------------------------------------
458
- // getSchemasForConnection – schema listing
459
- // ---------------------------------------------------------------------------
460
- describe("getSchemasForConnection", () => {
461
- describe("postgres", () => {
462
- const conn: ApiConnection = {
463
- name: "test",
464
- type: "postgres",
465
- postgresConnection: {
466
- host: "localhost",
467
- port: 5432,
468
- userName: "postgres",
469
- password: "",
470
- databaseName: "testdb",
471
- },
472
- };
473
-
474
- it("queries information_schema.schemata wrapped in row_to_json", async () => {
475
- const rows = [
476
- { schema_name: "public" },
477
- { schema_name: "information_schema" },
478
- { schema_name: "pg_catalog" },
479
- { schema_name: "app" },
480
- ];
481
- const m = mockConnection(rows);
482
- const schemas = await getSchemasForConnection(conn, m.conn);
483
-
484
- expect(m.lastSQL).toContain("row_to_json");
485
- expect(m.lastSQL).toContain("information_schema.schemata");
486
- expect(schemas).toHaveLength(4);
487
- expect(schemas.find((s) => s.name === "public")?.isDefault).toBe(true);
488
- expect(
489
- schemas.find((s) => s.name === "information_schema")?.isHidden,
490
- ).toBe(true);
491
- expect(schemas.find((s) => s.name === "pg_catalog")?.isHidden).toBe(
492
- true,
493
- );
494
- expect(schemas.find((s) => s.name === "app")?.isHidden).toBe(false);
495
- });
496
- });
497
-
498
- describe("mysql", () => {
499
- it("returns a single schema from the connection database", async () => {
500
- const conn: ApiConnection = {
501
- name: "test",
502
- type: "mysql",
503
- mysqlConnection: {
504
- host: "localhost",
505
- port: 3306,
506
- user: "root",
507
- password: "",
508
- database: "mydb",
509
- },
510
- };
511
- const m = mockConnection();
512
- const schemas = await getSchemasForConnection(conn, m.conn);
513
-
514
- expect(schemas).toHaveLength(1);
515
- expect(schemas[0].name).toBe("mydb");
516
- expect(schemas[0].isDefault).toBe(true);
517
- });
518
- });
519
-
520
- describe("snowflake", () => {
521
- it("queries INFORMATION_SCHEMA.SCHEMATA with database filter", async () => {
522
- const conn: ApiConnection = {
523
- name: "test",
524
- type: "snowflake",
525
- snowflakeConnection: {
526
- account: "test_account",
527
- username: "user",
528
- password: "pass",
529
- database: "MY_DB",
530
- schema: "PUBLIC",
531
- },
532
- };
533
- const rows = [
534
- {
535
- CATALOG_NAME: "MY_DB",
536
- SCHEMA_NAME: "PUBLIC",
537
- SCHEMA_OWNER: "SYSADMIN",
538
- },
539
- {
540
- CATALOG_NAME: "MY_DB",
541
- SCHEMA_NAME: "INFORMATION_SCHEMA",
542
- SCHEMA_OWNER: "",
543
- },
544
- ];
545
- const m = mockConnection(rows);
546
- const schemas = await getSchemasForConnection(conn, m.conn);
547
-
548
- expect(m.lastSQL).toContain("INFORMATION_SCHEMA.SCHEMATA");
549
- expect(m.lastSQL).toContain("CATALOG_NAME = 'MY_DB'");
550
- expect(schemas).toHaveLength(2);
551
- expect(schemas.find((s) => s.name === "MY_DB.PUBLIC")?.isDefault).toBe(
552
- true,
553
- );
554
- expect(
555
- schemas.find((s) => s.name === "MY_DB.INFORMATION_SCHEMA")
556
- ?.isHidden,
557
- ).toBe(true);
558
- });
559
- });
560
-
561
- describe("duckdb", () => {
562
- it("queries information_schema.schemata and hides system schemas", async () => {
563
- const conn: ApiConnection = {
564
- name: "test",
565
- type: "duckdb",
566
- duckdbConnection: {},
567
- };
568
- const rows = [
569
- { catalog_name: "main", schema_name: "main" },
570
- { catalog_name: "main", schema_name: "information_schema" },
571
- { catalog_name: "system", schema_name: "main" },
572
- ];
573
- const m = mockConnection(rows);
574
- const schemas = await getSchemasForConnection(conn, m.conn);
575
-
576
- expect(schemas).toHaveLength(3);
577
- const mainMain = schemas.find((s) => s.name === "main.main");
578
- expect(mainMain?.isDefault).toBe(true);
579
- expect(mainMain?.isHidden).toBe(false);
580
- expect(
581
- schemas.find((s) => s.name === "main.information_schema")?.isHidden,
582
- ).toBe(true);
583
- expect(schemas.find((s) => s.name === "system.main")?.isHidden).toBe(
584
- true,
585
- );
586
- });
587
- });
588
-
589
- describe("motherduck", () => {
590
- it("queries information_schema.schemata with optional database filter", async () => {
591
- const conn: ApiConnection = {
592
- name: "test",
593
- type: "motherduck",
594
- motherduckConnection: { accessToken: "fake", database: "mydb" },
595
- };
596
- const rows = [
597
- { schema_name: "main" },
598
- { schema_name: "information_schema" },
599
- ];
600
- const m = mockConnection(rows);
601
- const schemas = await getSchemasForConnection(conn, m.conn);
602
-
603
- expect(m.lastSQL).toContain("catalog_name = 'mydb'");
604
- expect(schemas).toHaveLength(2);
605
- expect(schemas.find((s) => s.name === "main")?.isDefault).toBe(true);
606
- expect(
607
- schemas.find((s) => s.name === "information_schema")?.isHidden,
608
- ).toBe(true);
609
- });
610
- });
611
-
612
- describe("ducklake", () => {
613
- it("queries information_schema.schemata filtered by connection name", async () => {
614
- const conn: ApiConnection = {
615
- name: "myconn",
616
- type: "ducklake",
617
- ducklakeConnection: {
618
- catalog: {
619
- postgresConnection: {
620
- host: "localhost",
621
- port: 5432,
622
- userName: "postgres",
623
- password: "",
624
- databaseName: "testdb",
625
- },
626
- },
627
- storage: { bucketUrl: "s3://bucket" },
628
- },
629
- };
630
- const rows = [
631
- { schema_name: "main" },
632
- { schema_name: "public" },
633
- { schema_name: "internal" },
634
- ];
635
- const m = mockConnection(rows);
636
- const schemas = await getSchemasForConnection(conn, m.conn);
637
-
638
- expect(m.lastSQL).toContain("catalog_name = 'myconn'");
639
- expect(schemas).toHaveLength(3);
640
- expect(schemas.find((s) => s.name === "main")?.isHidden).toBe(false);
641
- expect(schemas.find((s) => s.name === "public")?.isHidden).toBe(false);
642
- expect(schemas.find((s) => s.name === "internal")?.isHidden).toBe(
643
- true,
644
- );
645
- });
646
- });
647
-
648
- describe("trino", () => {
649
- it("queries catalog.information_schema.schemata when catalog is set", async () => {
650
- const conn: ApiConnection = {
651
- name: "test",
652
- type: "trino",
653
- trinoConnection: {
654
- server: "localhost",
655
- port: 8080,
656
- catalog: "hive",
657
- },
658
- };
659
- const rows = [
660
- { schema_name: "default" },
661
- { schema_name: "information_schema" },
662
- ];
663
- const m = mockConnection(rows);
664
- const schemas = await getSchemasForConnection(conn, m.conn);
665
-
666
- expect(m.lastSQL).toContain("hive.information_schema.schemata");
667
- expect(schemas).toHaveLength(2);
668
- expect(schemas.find((s) => s.name === "default")?.isHidden).toBe(
669
- false,
670
- );
671
- expect(
672
- schemas.find((s) => s.name === "information_schema")?.isHidden,
673
- ).toBe(true);
674
- });
675
- });
676
-
677
- it("throws for unsupported connection type", async () => {
678
- const conn = {
679
- name: "test",
680
- type: "unsupported",
681
- } as unknown as ApiConnection;
682
- const m = mockConnection();
683
- await expect(getSchemasForConnection(conn, m.conn)).rejects.toThrow(
684
- "Unsupported connection type",
685
- );
686
- });
687
- });
688
-
689
- // ---------------------------------------------------------------------------
690
- // extractErrorDataFromError
691
- // ---------------------------------------------------------------------------
692
- describe("extractErrorDataFromError", () => {
693
- it("extracts message from Error instance", () => {
694
- const result = extractErrorDataFromError(new Error("boom"));
695
- expect(result.error).toBe("boom");
696
- });
697
-
698
- it("converts string errors", () => {
699
- const result = extractErrorDataFromError("something went wrong");
700
- expect(result.error).toBe("something went wrong");
701
- });
702
-
703
- it("converts non-string non-Error values", () => {
704
- const result = extractErrorDataFromError(42);
705
- expect(result.error).toBe("42");
706
- });
707
-
708
- it("extracts task property when present", () => {
709
- const err = Object.assign(new Error("fail"), { task: { id: 1 } });
710
- const result = extractErrorDataFromError(err);
711
- expect(result.error).toBe("fail");
712
- expect(result.task).toEqual({ id: 1 });
713
- });
714
- });