@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,850 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from "bun:test";
2
- import fs from "fs";
3
- import path from "path";
4
- import { getPublisherConfig, type PublisherConfig } from "./config";
5
- import { PUBLISHER_CONFIG_NAME } from "./constants";
6
-
7
- describe("Config Environment Variable Substitution", () => {
8
- const testServerRoot = path.join(process.cwd(), "test-temp-config");
9
- const configPath = path.join(testServerRoot, PUBLISHER_CONFIG_NAME);
10
-
11
- beforeEach(() => {
12
- // Create test directory
13
- if (!fs.existsSync(testServerRoot)) {
14
- fs.mkdirSync(testServerRoot, { recursive: true });
15
- }
16
- });
17
-
18
- afterEach(() => {
19
- // Clean up test files and environment variables
20
- if (fs.existsSync(configPath)) {
21
- fs.unlinkSync(configPath);
22
- }
23
- if (fs.existsSync(testServerRoot)) {
24
- fs.rmdirSync(testServerRoot, { recursive: true });
25
- }
26
-
27
- // Clean up all test environment variables
28
- const testEnvVars = [
29
- "TEST_VAR",
30
- "BUCKET_NAME",
31
- "DB_HOST",
32
- "DB_PORT",
33
- "DB_NAME",
34
- "API_KEY",
35
- "API_HOST",
36
- "KEY_NAME",
37
- "VALUE_VAR",
38
- "EMPTY_VAR",
39
- "BUCKET_1",
40
- "BUCKET_2",
41
- "NORMAL_VALUE",
42
- "GCS_BUCKET",
43
- "PROJECT_ID",
44
- "CONNECTION_STRING",
45
- "PACKAGE_NAME",
46
- "DEFINED_VAR",
47
- "DEV_BUCKET",
48
- "PROD_BUCKET",
49
- "DB_CONNECTION",
50
- "ENV",
51
- "DATA_BUCKET",
52
- "TAG1",
53
- "TAG2",
54
- "CONFIG_VALUE",
55
- ];
56
-
57
- testEnvVars.forEach((varName) => {
58
- delete process.env[varName];
59
- });
60
- });
61
-
62
- describe("Scenario 1: ${VAR} present in config but value not available", () => {
63
- it("should throw error when environment variable is not defined", () => {
64
- // The correct behavior: throw an error when a required variable is missing
65
- const locationWithVar = "./path/${UNDEFINED_VAR}/end" as const;
66
-
67
- const config: PublisherConfig = {
68
- frozenConfig: false,
69
- projects: [
70
- {
71
- name: "test-project",
72
- packages: [
73
- {
74
- name: "test-package",
75
- location: locationWithVar,
76
- },
77
- ],
78
- },
79
- ],
80
- };
81
-
82
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
83
-
84
- // Should throw an error about the missing environment variable
85
- expect(() => getPublisherConfig(testServerRoot)).toThrow(
86
- "Environment variable '${UNDEFINED_VAR}' is not set in configuration file",
87
- );
88
- });
89
-
90
- it("should throw error for undefined variables in gs:// URLs", () => {
91
- const locationWithVar = "gs://${BUCKET_NAME}/packages" as const;
92
-
93
- const config: PublisherConfig = {
94
- frozenConfig: false,
95
- projects: [
96
- {
97
- name: "test-project",
98
- packages: [
99
- {
100
- name: "test-package",
101
- location: locationWithVar,
102
- },
103
- ],
104
- },
105
- ],
106
- };
107
-
108
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
109
-
110
- // Should throw an error about the missing environment variable
111
- expect(() => getPublisherConfig(testServerRoot)).toThrow(
112
- "Environment variable '${BUCKET_NAME}' is not set in configuration file",
113
- );
114
- });
115
- });
116
-
117
- describe("Scenario 2: ${VAR} present in config and value is available", () => {
118
- it("should substitute environment variable in package location with gs:// path", () => {
119
- process.env.BUCKET_NAME = "my-test-bucket";
120
-
121
- const config: PublisherConfig = {
122
- frozenConfig: false,
123
- projects: [
124
- {
125
- name: "test-project",
126
- packages: [
127
- {
128
- name: "test-package",
129
- location: "gs://${BUCKET_NAME}/packages",
130
- },
131
- ],
132
- },
133
- ],
134
- };
135
-
136
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
137
-
138
- const result = getPublisherConfig(testServerRoot);
139
-
140
- expect(result.projects[0].packages[0].location).toBe(
141
- "gs://my-test-bucket/packages",
142
- );
143
- });
144
-
145
- it("should substitute environment variable in filesystem path", () => {
146
- process.env.PROJECT_ID = "analytics-2024";
147
-
148
- const config: PublisherConfig = {
149
- frozenConfig: false,
150
- projects: [
151
- {
152
- name: "test-project",
153
- packages: [
154
- {
155
- name: "test-package",
156
- location: "./projects/${PROJECT_ID}/models",
157
- },
158
- ],
159
- },
160
- ],
161
- };
162
-
163
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
164
-
165
- const result = getPublisherConfig(testServerRoot);
166
-
167
- expect(result.projects[0].packages[0].location).toBe(
168
- "./projects/analytics-2024/models",
169
- );
170
- });
171
-
172
- it("should substitute multiple environment variables in single value", () => {
173
- process.env.BUCKET_NAME = "data-warehouse";
174
- process.env.PROJECT_ID = "prod-analytics";
175
-
176
- const config: PublisherConfig = {
177
- frozenConfig: false,
178
- projects: [
179
- {
180
- name: "test-project",
181
- packages: [
182
- {
183
- name: "test-package",
184
- location: "gs://${BUCKET_NAME}/${PROJECT_ID}/models",
185
- },
186
- ],
187
- },
188
- ],
189
- };
190
-
191
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
192
-
193
- const result = getPublisherConfig(testServerRoot);
194
-
195
- expect(result.projects[0].packages[0].location).toBe(
196
- "gs://data-warehouse/prod-analytics/models",
197
- );
198
- });
199
-
200
- it("should substitute variables across multiple packages", () => {
201
- process.env.BUCKET_1 = "bucket-one";
202
- process.env.BUCKET_2 = "bucket-two";
203
-
204
- const config: PublisherConfig = {
205
- frozenConfig: false,
206
- projects: [
207
- {
208
- name: "test-project",
209
- packages: [
210
- {
211
- name: "package-1",
212
- location: "gs://${BUCKET_1}/path",
213
- },
214
- {
215
- name: "package-2",
216
- location: "gs://${BUCKET_2}/path",
217
- },
218
- ],
219
- },
220
- ],
221
- };
222
-
223
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
224
-
225
- const result = getPublisherConfig(testServerRoot);
226
-
227
- expect(result.projects[0].packages[0].location).toBe(
228
- "gs://bucket-one/path",
229
- );
230
- expect(result.projects[0].packages[1].location).toBe(
231
- "gs://bucket-two/path",
232
- );
233
- });
234
-
235
- it("should substitute variables in connection names", () => {
236
- process.env.DB_HOST = "localhost";
237
-
238
- const config: PublisherConfig = {
239
- frozenConfig: false,
240
- projects: [
241
- {
242
- name: "test-project",
243
- packages: [],
244
- connections: [
245
- {
246
- name: "db-${DB_HOST}",
247
- type: "postgres",
248
- },
249
- ],
250
- },
251
- ],
252
- };
253
-
254
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
255
-
256
- const result = getPublisherConfig(testServerRoot);
257
-
258
- expect(result.projects[0].connections?.[0].name).toBe("db-localhost");
259
- });
260
-
261
- it("should substitute variables in nested configuration objects", () => {
262
- process.env.API_KEY = "secret-key-123";
263
- process.env.API_HOST = "api.example.com";
264
-
265
- const config = {
266
- frozenConfig: false,
267
- projects: [
268
- {
269
- name: "test-project",
270
- packages: [],
271
- settings: {
272
- apiEndpoint: "https://${API_HOST}/v1",
273
- credentials: {
274
- apiKey: "${API_KEY}",
275
- },
276
- },
277
- },
278
- ],
279
- };
280
-
281
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
282
-
283
- const result = getPublisherConfig(testServerRoot);
284
- const projectWithSettings = result
285
- .projects[0] as (typeof result.projects)[0] & {
286
- settings: {
287
- apiEndpoint: string;
288
- credentials: {
289
- apiKey: string;
290
- };
291
- };
292
- };
293
-
294
- expect(projectWithSettings.settings.apiEndpoint).toBe(
295
- "https://api.example.com/v1",
296
- );
297
- expect(projectWithSettings.settings.credentials.apiKey).toBe(
298
- "secret-key-123",
299
- );
300
- });
301
-
302
- it("should handle mixed substitution with literal text", () => {
303
- process.env.PROJECT_ID = "my-project";
304
-
305
- const config: PublisherConfig = {
306
- frozenConfig: false,
307
- projects: [
308
- {
309
- name: "test-project",
310
- packages: [
311
- {
312
- name: "test-package",
313
- location:
314
- "gs://bucket/prefix-${PROJECT_ID}-suffix/models",
315
- },
316
- ],
317
- },
318
- ],
319
- };
320
-
321
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
322
-
323
- const result = getPublisherConfig(testServerRoot);
324
-
325
- expect(result.projects[0].packages[0].location).toBe(
326
- "gs://bucket/prefix-my-project-suffix/models",
327
- );
328
- });
329
-
330
- it("should substitute variables across multiple projects", () => {
331
- process.env.DEV_BUCKET = "dev-data";
332
- process.env.PROD_BUCKET = "prod-data";
333
-
334
- const config: PublisherConfig = {
335
- frozenConfig: false,
336
- projects: [
337
- {
338
- name: "development",
339
- packages: [
340
- {
341
- name: "dev-package",
342
- location: "gs://${DEV_BUCKET}/models",
343
- },
344
- ],
345
- },
346
- {
347
- name: "production",
348
- packages: [
349
- {
350
- name: "prod-package",
351
- location: "gs://${PROD_BUCKET}/models",
352
- },
353
- ],
354
- },
355
- ],
356
- };
357
-
358
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
359
-
360
- const result = getPublisherConfig(testServerRoot);
361
-
362
- expect(result.projects[0].packages[0].location).toBe(
363
- "gs://dev-data/models",
364
- );
365
- expect(result.projects[1].packages[0].location).toBe(
366
- "gs://prod-data/models",
367
- );
368
-
369
- delete process.env.DEV_BUCKET;
370
- delete process.env.PROD_BUCKET;
371
- });
372
- });
373
-
374
- describe("Scenario 3: ${VAR} present in config as a key (not as a value)", () => {
375
- it("should NOT substitute environment variables in object keys", () => {
376
- process.env.KEY_NAME = "myKey";
377
-
378
- const config = {
379
- frozenConfig: false,
380
- projects: [
381
- {
382
- name: "test-project",
383
- packages: [],
384
- "${KEY_NAME}": "some-value",
385
- },
386
- ],
387
- };
388
-
389
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
390
-
391
- const result = getPublisherConfig(testServerRoot);
392
-
393
- // The key should remain as-is (not substituted)
394
- expect(result.projects[0]).toHaveProperty("${KEY_NAME}");
395
- expect(
396
- (result.projects[0] as Record<string, unknown>)["${KEY_NAME}"],
397
- ).toBe("some-value");
398
- });
399
-
400
- it("should preserve keys with variable syntax while substituting values", () => {
401
- process.env.NORMAL_VALUE = "substituted-value";
402
-
403
- const config = {
404
- frozenConfig: false,
405
- projects: [
406
- {
407
- name: "test-project",
408
- packages: [],
409
- "${DYNAMIC_KEY}": "value1",
410
- normal_key: "${NORMAL_VALUE}",
411
- },
412
- ],
413
- };
414
-
415
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
416
-
417
- const result = getPublisherConfig(testServerRoot);
418
-
419
- // Key should not be substituted
420
- expect(result.projects[0]).toHaveProperty("${DYNAMIC_KEY}");
421
- expect(
422
- (result.projects[0] as Record<string, unknown>)["${DYNAMIC_KEY}"],
423
- ).toBe("value1");
424
-
425
- // Value should be substituted
426
- expect(
427
- (result.projects[0] as Record<string, unknown>)["normal_key"],
428
- ).toBe("substituted-value");
429
- });
430
-
431
- it("should handle mixed scenario: variable in key and different variable in value", () => {
432
- process.env.VALUE_VAR = "actual-value";
433
-
434
- const config = {
435
- frozenConfig: false,
436
- projects: [
437
- {
438
- name: "test-project",
439
- packages: [],
440
- "${KEY_VAR}": "${VALUE_VAR}",
441
- },
442
- ],
443
- };
444
-
445
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
446
-
447
- const result = getPublisherConfig(testServerRoot);
448
-
449
- // Key remains with variable syntax
450
- expect(result.projects[0]).toHaveProperty("${KEY_VAR}");
451
-
452
- // Value is substituted
453
- expect(
454
- (result.projects[0] as Record<string, unknown>)["${KEY_VAR}"],
455
- ).toBe("actual-value");
456
- });
457
-
458
- it("should substitute variables in package names since they are values", () => {
459
- process.env.PACKAGE_NAME = "my-package";
460
- process.env.BUCKET_NAME = "my-bucket";
461
-
462
- const config: PublisherConfig = {
463
- frozenConfig: false,
464
- projects: [
465
- {
466
- name: "test-project",
467
- packages: [
468
- {
469
- name: "${PACKAGE_NAME}",
470
- location: "gs://${BUCKET_NAME}/models",
471
- },
472
- ],
473
- },
474
- ],
475
- };
476
-
477
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
478
-
479
- const result = getPublisherConfig(testServerRoot);
480
-
481
- // Package name is a property VALUE, so it WILL be substituted
482
- expect(result.projects[0].packages[0].name).toBe("my-package");
483
-
484
- // Location should also be substituted
485
- expect(result.projects[0].packages[0].location).toBe(
486
- "gs://my-bucket/models",
487
- );
488
-
489
- delete process.env.PACKAGE_NAME;
490
- });
491
-
492
- it("should handle nested objects with variable syntax in keys", () => {
493
- process.env.CONFIG_VALUE = "test-value";
494
-
495
- const config = {
496
- frozenConfig: false,
497
- projects: [
498
- {
499
- name: "test-project",
500
- packages: [],
501
- metadata: {
502
- "${DYNAMIC_PROP}": {
503
- setting: "${CONFIG_VALUE}",
504
- },
505
- },
506
- },
507
- ],
508
- };
509
-
510
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
511
-
512
- const result = getPublisherConfig(testServerRoot);
513
- const projectWithMetadata = result
514
- .projects[0] as (typeof result.projects)[0] & {
515
- metadata: Record<string, { setting: string }>;
516
- };
517
-
518
- // Key should remain unchanged
519
- expect(projectWithMetadata.metadata).toHaveProperty("${DYNAMIC_PROP}");
520
-
521
- // Nested value should be substituted
522
- expect(projectWithMetadata.metadata["${DYNAMIC_PROP}"].setting).toBe(
523
- "test-value",
524
- );
525
-
526
- delete process.env.CONFIG_VALUE;
527
- });
528
- });
529
-
530
- describe("Edge cases and special scenarios", () => {
531
- it("should handle empty string environment variable", () => {
532
- process.env.EMPTY_VAR = "";
533
-
534
- const config: PublisherConfig = {
535
- frozenConfig: false,
536
- projects: [
537
- {
538
- name: "test-project",
539
- packages: [
540
- {
541
- name: "test-package",
542
- location: "gs://bucket/${EMPTY_VAR}/path",
543
- },
544
- ],
545
- },
546
- ],
547
- };
548
-
549
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
550
-
551
- const result = getPublisherConfig(testServerRoot);
552
-
553
- expect(result.projects[0].packages[0].location).toBe(
554
- "gs://bucket//path",
555
- );
556
- });
557
-
558
- it("should handle non-string values without modification", () => {
559
- const config: PublisherConfig = {
560
- frozenConfig: true,
561
- projects: [
562
- {
563
- name: "test-project",
564
- packages: [],
565
- },
566
- ],
567
- };
568
-
569
- // Add non-standard properties for testing
570
- const configWithExtras = {
571
- ...config,
572
- projects: [
573
- {
574
- ...config.projects[0],
575
- count: 42,
576
- enabled: true,
577
- ratio: 3.14,
578
- metadata: null,
579
- tags: ["tag1", "tag2"],
580
- },
581
- ],
582
- };
583
-
584
- fs.writeFileSync(
585
- configPath,
586
- JSON.stringify(configWithExtras, null, 2),
587
- );
588
-
589
- const result = getPublisherConfig(testServerRoot);
590
- const projectWithExtras = result
591
- .projects[0] as (typeof result.projects)[0] & {
592
- count: number;
593
- enabled: boolean;
594
- ratio: number;
595
- metadata: null;
596
- tags: string[];
597
- };
598
-
599
- expect(result.frozenConfig).toBe(true);
600
- expect(projectWithExtras.count).toBe(42);
601
- expect(projectWithExtras.enabled).toBe(true);
602
- expect(projectWithExtras.ratio).toBe(3.14);
603
- expect(projectWithExtras.metadata).toBe(null);
604
- expect(projectWithExtras.tags).toEqual(["tag1", "tag2"]);
605
- });
606
-
607
- it("should handle config with no environment variables", () => {
608
- const config: PublisherConfig = {
609
- frozenConfig: false,
610
- projects: [
611
- {
612
- name: "test-project",
613
- packages: [
614
- {
615
- name: "test-package",
616
- location: "./packages/test",
617
- },
618
- ],
619
- },
620
- ],
621
- };
622
-
623
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
624
-
625
- const result = getPublisherConfig(testServerRoot);
626
-
627
- expect(result).toEqual(config);
628
- });
629
-
630
- it("should handle empty projects array", () => {
631
- const config: PublisherConfig = {
632
- frozenConfig: false,
633
- projects: [],
634
- };
635
-
636
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
637
-
638
- const result = getPublisherConfig(testServerRoot);
639
-
640
- expect(result.projects).toEqual([]);
641
- });
642
-
643
- it("should return default config when file does not exist", () => {
644
- // Don't create config file
645
- const result = getPublisherConfig(testServerRoot);
646
-
647
- expect(result).toEqual({
648
- frozenConfig: false,
649
- projects: [],
650
- });
651
- });
652
-
653
- it("should handle whitespace around variable names", () => {
654
- process.env.BUCKET_NAME = "test-bucket";
655
-
656
- const config: PublisherConfig = {
657
- frozenConfig: false,
658
- projects: [
659
- {
660
- name: "test-project",
661
- packages: [
662
- {
663
- name: "test-package",
664
- location: "gs://${ BUCKET_NAME }/path",
665
- },
666
- ],
667
- },
668
- ],
669
- };
670
-
671
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
672
-
673
- const result = getPublisherConfig(testServerRoot);
674
-
675
- // Whitespace around variable name means it won't match the pattern
676
- // Due to bug, the unmatched variable causes duplication
677
- expect(result.projects[0].packages[0].location).toBe(
678
- "gs://${ BUCKET_NAME }/path",
679
- );
680
- });
681
-
682
- it("should handle multiple projects with mixed variable usage", () => {
683
- process.env.PROD_BUCKET = "production-data";
684
-
685
- const config: PublisherConfig = {
686
- frozenConfig: false,
687
- projects: [
688
- {
689
- name: "development",
690
- packages: [
691
- {
692
- name: "dev-package",
693
- location: "./packages/dev",
694
- },
695
- ],
696
- },
697
- {
698
- name: "production",
699
- packages: [
700
- {
701
- name: "prod-package",
702
- location: "gs://${PROD_BUCKET}/models",
703
- },
704
- ],
705
- },
706
- ],
707
- };
708
-
709
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
710
-
711
- const result = getPublisherConfig(testServerRoot);
712
-
713
- expect(result.projects[0].packages[0].location).toBe("./packages/dev");
714
- expect(result.projects[1].packages[0].location).toBe(
715
- "gs://production-data/models",
716
- );
717
-
718
- delete process.env.PROD_BUCKET;
719
- });
720
-
721
- it("should preserve variable syntax if not matching pattern", () => {
722
- const config: PublisherConfig = {
723
- frozenConfig: false,
724
- projects: [
725
- {
726
- name: "test-project",
727
- packages: [
728
- {
729
- name: "test-package",
730
- location: "gs://bucket/${lowercase_var}/path",
731
- },
732
- ],
733
- },
734
- ],
735
- };
736
-
737
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
738
-
739
- const result = getPublisherConfig(testServerRoot);
740
-
741
- // Variable won't match pattern, so won't be substituted
742
- expect(result.projects[0].packages[0].location).toBe(
743
- "gs://bucket/${lowercase_var}/path",
744
- );
745
- });
746
-
747
- it("should handle arrays of strings with variables", () => {
748
- process.env.TAG1 = "analytics";
749
- process.env.TAG2 = "production";
750
-
751
- const config = {
752
- frozenConfig: false,
753
- projects: [
754
- {
755
- name: "test-project",
756
- packages: [],
757
- tags: ["${TAG1}", "${TAG2}", "static-tag"],
758
- },
759
- ],
760
- };
761
-
762
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
763
-
764
- const result = getPublisherConfig(testServerRoot);
765
- const projectWithTags = result
766
- .projects[0] as (typeof result.projects)[0] & {
767
- tags: string[];
768
- };
769
-
770
- expect(projectWithTags.tags).toEqual([
771
- "analytics",
772
- "production",
773
- "static-tag",
774
- ]);
775
-
776
- delete process.env.TAG1;
777
- delete process.env.TAG2;
778
- });
779
- });
780
-
781
- describe("Real-world configuration scenarios", () => {
782
- it("should handle typical multi-environment setup", () => {
783
- process.env.ENV = "staging";
784
- process.env.DATA_BUCKET = "company-data-staging";
785
- process.env.PROJECT_ID = "company-project-staging";
786
-
787
- const config: PublisherConfig = {
788
- frozenConfig: false,
789
- projects: [
790
- {
791
- name: "${ENV}",
792
- packages: [
793
- {
794
- name: "analytics",
795
- location: "gs://${DATA_BUCKET}/${PROJECT_ID}/analytics",
796
- },
797
- {
798
- name: "reporting",
799
- location: "gs://${DATA_BUCKET}/${PROJECT_ID}/reporting",
800
- },
801
- ],
802
- },
803
- ],
804
- };
805
-
806
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
807
-
808
- const result = getPublisherConfig(testServerRoot);
809
-
810
- expect(result.projects[0].name).toBe("staging");
811
- expect(result.projects[0].packages[0].location).toBe(
812
- "gs://company-data-staging/company-project-staging/analytics",
813
- );
814
- expect(result.projects[0].packages[1].location).toBe(
815
- "gs://company-data-staging/company-project-staging/reporting",
816
- );
817
-
818
- delete process.env.ENV;
819
- delete process.env.DATA_BUCKET;
820
- });
821
-
822
- it("should handle connection configurations with environment variables", () => {
823
- process.env.DB_CONNECTION = "production-db";
824
-
825
- const config: PublisherConfig = {
826
- frozenConfig: false,
827
- projects: [
828
- {
829
- name: "production",
830
- packages: [],
831
- connections: [
832
- {
833
- name: "${DB_CONNECTION}",
834
- type: "bigquery",
835
- },
836
- ],
837
- },
838
- ],
839
- };
840
-
841
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
842
-
843
- const result = getPublisherConfig(testServerRoot);
844
-
845
- expect(result.projects[0].connections?.[0].name).toBe("production-db");
846
-
847
- delete process.env.DB_CONNECTION;
848
- });
849
- });
850
- });