@malloy-publisher/server 0.0.197-dev → 0.0.197

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 (60) hide show
  1. package/README.docker.md +88 -20
  2. package/README.md +15 -0
  3. package/build.ts +16 -0
  4. package/dist/app/api-doc.yaml +20 -3
  5. package/dist/app/assets/EnvironmentPage-BVkQH_xQ.js +1 -0
  6. package/dist/app/assets/HomePage-BgH9UkjK.js +1 -0
  7. package/dist/app/assets/MainPage-DiBxABem.js +2 -0
  8. package/dist/app/assets/ModelPage-oS70fj83.js +1 -0
  9. package/dist/app/assets/PackagePage-F_qLDAdv.js +1 -0
  10. package/dist/app/assets/RouteError-WqpffppN.js +1 -0
  11. package/dist/app/assets/WorkbookPage-_YmC-ebR.js +1 -0
  12. package/dist/app/assets/{core-w79IMXAG.es-Bd0UlzOL.js → core-B8L9xCYT.es-BcRLJTnC.js} +14 -14
  13. package/dist/app/assets/index-BMViiwtJ.js +451 -0
  14. package/dist/app/assets/{index-C513UodQ.js → index-C3XPaTaS.js} +15 -15
  15. package/dist/app/assets/index-rg8Ok8nl.js +1803 -0
  16. package/dist/app/assets/{index.umd-BMeMPq_9.js → index.umd-CCAfKkxY.js} +1 -1
  17. package/dist/app/index.html +2 -3
  18. package/dist/default-publisher.config.json +23 -0
  19. package/dist/instrumentation.mjs +1 -3
  20. package/dist/server.mjs +958 -177
  21. package/package.json +11 -12
  22. package/publisher.config.example.bigquery.json +33 -0
  23. package/publisher.config.example.duckdb.json +23 -0
  24. package/publisher.config.json +1 -11
  25. package/src/config.spec.ts +225 -0
  26. package/src/config.ts +96 -2
  27. package/src/controller/connection.controller.ts +1 -1
  28. package/src/default-publisher.config.json +23 -0
  29. package/src/errors.spec.ts +42 -0
  30. package/src/errors.ts +8 -0
  31. package/src/health.ts +26 -0
  32. package/src/logger.ts +1 -3
  33. package/src/pg_helpers.spec.ts +226 -0
  34. package/src/pg_helpers.ts +129 -0
  35. package/src/server-old.ts +1119 -0
  36. package/src/server.ts +36 -0
  37. package/src/service/connection.spec.ts +6 -4
  38. package/src/service/connection.ts +8 -3
  39. package/src/service/connection_config.ts +2 -2
  40. package/src/service/environment.ts +53 -25
  41. package/src/service/environment_store.spec.ts +19 -0
  42. package/src/service/environment_store.ts +21 -2
  43. package/src/service/package.ts +4 -3
  44. package/src/storage/StorageManager.ts +71 -11
  45. package/src/storage/duckdb/schema.ts +41 -0
  46. package/src/utils.ts +11 -0
  47. package/tests/harness/rest_e2e.ts +2 -2
  48. package/tests/integration/legacy_routes/legacy_routes.integration.spec.ts +259 -0
  49. package/tests/unit/duckdb/attached_databases.test.ts +5 -5
  50. package/tests/unit/duckdb/legacy_schema_migration.test.ts +194 -0
  51. package/tests/unit/storage/StorageManager.test.ts +166 -0
  52. package/dist/app/assets/EnvironmentPage-1j6QDWAy.js +0 -1
  53. package/dist/app/assets/HomePage-DMop21VG.js +0 -1
  54. package/dist/app/assets/MainPage-BbE8ETz1.js +0 -2
  55. package/dist/app/assets/ModelPage-D2jvfe3t.js +0 -1
  56. package/dist/app/assets/PackagePage-BbnhGoD3.js +0 -1
  57. package/dist/app/assets/RouteError-D3LGEZ3i.js +0 -1
  58. package/dist/app/assets/WorkbookPage-DttVIj4u.js +0 -1
  59. package/dist/app/assets/index-5K9YjIxF.js +0 -456
  60. package/dist/app/assets/index-DIgzgp69.js +0 -1742
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/server",
3
3
  "description": "Malloy Publisher Server",
4
- "version": "0.0.197-dev",
4
+ "version": "0.0.197",
5
5
  "main": "dist/server.mjs",
6
6
  "bin": {
7
7
  "malloy-publisher": "dist/server.mjs"
@@ -34,16 +34,16 @@
34
34
  "@azure/identity": "^4.13.0",
35
35
  "@azure/storage-blob": "^12.26.0",
36
36
  "@google-cloud/storage": "^7.16.0",
37
- "@malloydata/db-bigquery": "^0.0.383",
38
- "@malloydata/db-databricks": "^0.0.383",
39
- "@malloydata/db-duckdb": "^0.0.383",
40
- "@malloydata/db-mysql": "^0.0.383",
41
- "@malloydata/db-postgres": "^0.0.383",
42
- "@malloydata/db-snowflake": "^0.0.383",
43
- "@malloydata/db-trino": "^0.0.383",
44
- "@malloydata/malloy": "^0.0.383",
45
- "@malloydata/malloy-sql": "^0.0.383",
46
- "@malloydata/render-validator": "^0.0.383",
37
+ "@malloydata/db-bigquery": "^0.0.394",
38
+ "@malloydata/db-databricks": "^0.0.394",
39
+ "@malloydata/db-duckdb": "^0.0.394",
40
+ "@malloydata/db-mysql": "^0.0.394",
41
+ "@malloydata/db-postgres": "^0.0.394",
42
+ "@malloydata/db-snowflake": "^0.0.394",
43
+ "@malloydata/db-trino": "^0.0.394",
44
+ "@malloydata/malloy": "^0.0.394",
45
+ "@malloydata/malloy-sql": "^0.0.394",
46
+ "@malloydata/render-validator": "^0.0.394",
47
47
  "@modelcontextprotocol/sdk": "^1.13.2",
48
48
  "@opentelemetry/api": "^1.9.0",
49
49
  "@opentelemetry/auto-instrumentations-node": "^0.57.0",
@@ -68,7 +68,6 @@
68
68
  "node-cron": "^3.0.3",
69
69
  "recursive-readdir": "^2.2.3",
70
70
  "simple-git": "^3.28.0",
71
- "trino": "^1.1.1",
72
71
  "uuid": "^11.0.3"
73
72
  },
74
73
  "devDependencies": {
@@ -0,0 +1,33 @@
1
+ {
2
+ "frozenConfig": false,
3
+ "environments": [
4
+ {
5
+ "name": "malloy-samples",
6
+ "packages": [
7
+ {
8
+ "name": "ecommerce",
9
+ "location": "https://github.com/credibledata/malloy-samples/tree/main/ecommerce"
10
+ },
11
+ {
12
+ "name": "imdb",
13
+ "location": "https://github.com/credibledata/malloy-samples/tree/main/imdb"
14
+ },
15
+ {
16
+ "name": "faa",
17
+ "location": "https://github.com/credibledata/malloy-samples/tree/main/faa"
18
+ },
19
+ {
20
+ "name": "bigquery-hackernews",
21
+ "location": "https://github.com/credibledata/malloy-samples/tree/main/bigquery-hackernews"
22
+ }
23
+ ],
24
+ "connections": [
25
+ {
26
+ "name": "bigquery",
27
+ "type": "bigquery",
28
+ "bigqueryConnection": {}
29
+ }
30
+ ]
31
+ }
32
+ ]
33
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "frozenConfig": false,
3
+ "environments": [
4
+ {
5
+ "name": "malloy-samples",
6
+ "packages": [
7
+ {
8
+ "name": "ecommerce",
9
+ "location": "https://github.com/credibledata/malloy-samples/tree/main/ecommerce"
10
+ },
11
+ {
12
+ "name": "imdb",
13
+ "location": "https://github.com/credibledata/malloy-samples/tree/main/imdb"
14
+ },
15
+ {
16
+ "name": "faa",
17
+ "location": "https://github.com/credibledata/malloy-samples/tree/main/faa"
18
+ }
19
+ ],
20
+ "connections": []
21
+ }
22
+ ]
23
+ }
@@ -15,19 +15,9 @@
15
15
  {
16
16
  "name": "faa",
17
17
  "location": "https://github.com/credibledata/malloy-samples/tree/main/faa"
18
- },
19
- {
20
- "name": "bigquery-hackernews",
21
- "location": "https://github.com/credibledata/malloy-samples/tree/main/bigquery-hackernews"
22
18
  }
23
19
  ],
24
- "connections": [
25
- {
26
- "name": "bigquery",
27
- "type": "bigquery",
28
- "bigqueryConnection": {}
29
- }
30
- ]
20
+ "connections": []
31
21
  }
32
22
  ]
33
23
  }
@@ -856,3 +856,228 @@ describe("Config Environment Variable Substitution", () => {
856
856
  });
857
857
  });
858
858
  });
859
+
860
+ // TODO: Remove this during projects cleanup
861
+ describe("Config legacy 'projects' key back-compat", () => {
862
+ const testServerRoot = path.join(process.cwd(), "test-temp-legacy-config");
863
+ const configPath = path.join(testServerRoot, PUBLISHER_CONFIG_NAME);
864
+
865
+ beforeEach(() => {
866
+ if (!fs.existsSync(testServerRoot)) {
867
+ fs.mkdirSync(testServerRoot, { recursive: true });
868
+ }
869
+ });
870
+
871
+ afterEach(() => {
872
+ if (fs.existsSync(configPath)) {
873
+ fs.unlinkSync(configPath);
874
+ }
875
+ if (fs.existsSync(testServerRoot)) {
876
+ fs.rmdirSync(testServerRoot, { recursive: true });
877
+ }
878
+ });
879
+
880
+ it("reads from legacy 'projects' key when 'environments' is absent", async () => {
881
+ // Pre-rename on-disk shape: top-level key is `projects`, not
882
+ // `environments`. Without back-compat this silently parses as empty.
883
+ const legacyConfig = {
884
+ frozenConfig: false,
885
+ projects: [
886
+ {
887
+ name: "legacy-env",
888
+ packages: [
889
+ {
890
+ name: "p1",
891
+ location: "./packages/p1",
892
+ },
893
+ ],
894
+ },
895
+ ],
896
+ };
897
+
898
+ fs.writeFileSync(configPath, JSON.stringify(legacyConfig, null, 2));
899
+
900
+ // Spy on logger.warn so we can assert the deprecation message fired.
901
+ const { logger } = await import("./logger");
902
+ const originalWarn = logger.warn;
903
+ const warnings: string[] = [];
904
+ logger.warn = ((msg: unknown, ..._rest: unknown[]) => {
905
+ warnings.push(typeof msg === "string" ? msg : String(msg));
906
+ return logger;
907
+ }) as typeof logger.warn;
908
+
909
+ try {
910
+ const result = getPublisherConfig(testServerRoot);
911
+
912
+ expect(result.environments.length).toBe(1);
913
+ expect(result.environments[0].name).toBe("legacy-env");
914
+ expect(result.environments[0].packages[0].name).toBe("p1");
915
+
916
+ expect(
917
+ warnings.some((w) => w.includes('uses deprecated "projects" key')),
918
+ ).toBe(true);
919
+ } finally {
920
+ logger.warn = originalWarn;
921
+ }
922
+ });
923
+
924
+ it("prefers the new 'environments' key when both are present", async () => {
925
+ const config = {
926
+ frozenConfig: false,
927
+ environments: [
928
+ {
929
+ name: "new-env",
930
+ packages: [{ name: "p1", location: "./packages/p1" }],
931
+ },
932
+ ],
933
+ projects: [
934
+ {
935
+ name: "should-be-ignored",
936
+ packages: [{ name: "p2", location: "./packages/p2" }],
937
+ },
938
+ ],
939
+ };
940
+
941
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
942
+
943
+ const { logger } = await import("./logger");
944
+ const originalWarn = logger.warn;
945
+ const warnings: string[] = [];
946
+ logger.warn = ((msg: unknown, ..._rest: unknown[]) => {
947
+ warnings.push(typeof msg === "string" ? msg : String(msg));
948
+ return logger;
949
+ }) as typeof logger.warn;
950
+
951
+ try {
952
+ const result = getPublisherConfig(testServerRoot);
953
+
954
+ expect(result.environments.length).toBe(1);
955
+ expect(result.environments[0].name).toBe("new-env");
956
+
957
+ // No deprecation warning should fire when `environments` is present.
958
+ expect(
959
+ warnings.some((w) => w.includes('uses deprecated "projects" key')),
960
+ ).toBe(false);
961
+ } finally {
962
+ logger.warn = originalWarn;
963
+ }
964
+ });
965
+ });
966
+
967
+ describe("Committed example configs", () => {
968
+ const serverDir = path.resolve(__dirname, "..");
969
+
970
+ it.each([
971
+ ["publisher.config.json", false],
972
+ ["publisher.config.example.duckdb.json", false],
973
+ ["publisher.config.example.bigquery.json", true],
974
+ ])(
975
+ "%s parses as a valid PublisherConfig",
976
+ (filename, expectsBigQueryConnection) => {
977
+ const filePath = path.join(serverDir, filename);
978
+ expect(fs.existsSync(filePath)).toBe(true);
979
+
980
+ const raw = fs.readFileSync(filePath, "utf-8");
981
+ const parsed = JSON.parse(raw) as PublisherConfig;
982
+
983
+ expect(parsed).toHaveProperty("environments");
984
+ expect(Array.isArray(parsed.environments)).toBe(true);
985
+ expect(parsed.environments.length).toBeGreaterThan(0);
986
+
987
+ const env = parsed.environments[0];
988
+ expect(env.name).toBeTruthy();
989
+ expect(Array.isArray(env.packages)).toBe(true);
990
+ expect(env.packages.length).toBeGreaterThan(0);
991
+
992
+ if (expectsBigQueryConnection) {
993
+ expect(
994
+ (env.connections ?? []).some((c) => c.type === "bigquery"),
995
+ ).toBe(true);
996
+ expect(
997
+ env.packages.some((p) => p.name === "bigquery-hackernews"),
998
+ ).toBe(true);
999
+ } else {
1000
+ expect(
1001
+ env.packages.some((p) => p.name === "bigquery-hackernews"),
1002
+ ).toBe(false);
1003
+ }
1004
+ },
1005
+ );
1006
+ });
1007
+
1008
+ describe("Config path resolution (--config and bundled default)", () => {
1009
+ const emptyServerRoot = path.join(process.cwd(), "test-empty-server-root");
1010
+ const customConfigPath = path.join(
1011
+ process.cwd(),
1012
+ "test-custom-publisher.config.json",
1013
+ );
1014
+
1015
+ beforeEach(() => {
1016
+ if (!fs.existsSync(emptyServerRoot)) {
1017
+ fs.mkdirSync(emptyServerRoot, { recursive: true });
1018
+ }
1019
+ delete process.env.PUBLISHER_CONFIG_PATH;
1020
+ delete process.env.PUBLISHER_USE_BUNDLED_DEFAULT;
1021
+ });
1022
+
1023
+ afterEach(() => {
1024
+ delete process.env.PUBLISHER_CONFIG_PATH;
1025
+ delete process.env.PUBLISHER_USE_BUNDLED_DEFAULT;
1026
+ if (fs.existsSync(customConfigPath)) {
1027
+ fs.unlinkSync(customConfigPath);
1028
+ }
1029
+ if (fs.existsSync(emptyServerRoot)) {
1030
+ fs.rmSync(emptyServerRoot, { recursive: true, force: true });
1031
+ }
1032
+ });
1033
+
1034
+ it("falls back to the bundled default config when serverRoot has no publisher.config.json and bundled-default opt-in is set", () => {
1035
+ // The bundled default is opt-in (server.ts sets the env var when
1036
+ // the user passed neither --server_root nor --config) so embedded
1037
+ // callers don't get a surprise filesystem read.
1038
+ process.env.PUBLISHER_USE_BUNDLED_DEFAULT = "true";
1039
+ const result = getPublisherConfig(emptyServerRoot);
1040
+
1041
+ expect(result.environments.length).toBeGreaterThan(0);
1042
+ const env = result.environments[0];
1043
+ expect(env.name).toBe("malloy-samples");
1044
+ expect(env.packages.some((p) => p.name === "ecommerce")).toBe(true);
1045
+ expect(env.packages.some((p) => p.name === "bigquery-hackernews")).toBe(
1046
+ false,
1047
+ );
1048
+ });
1049
+
1050
+ it("does NOT fall back to the bundled default when opt-in flag is unset (programmatic construction)", () => {
1051
+ // No PUBLISHER_USE_BUNDLED_DEFAULT, no PUBLISHER_CONFIG_PATH, no
1052
+ // file in emptyServerRoot — result should be the original empty
1053
+ // shape, preserving prior behavior for embeds and tests.
1054
+ const result = getPublisherConfig(emptyServerRoot);
1055
+ expect(result.environments).toEqual([]);
1056
+ });
1057
+
1058
+ it("honors PUBLISHER_CONFIG_PATH (set by --config) over the server root", () => {
1059
+ const customConfig = {
1060
+ frozenConfig: false,
1061
+ environments: [
1062
+ { name: "custom-env", packages: [{ name: "foo", location: "/x" }] },
1063
+ ],
1064
+ };
1065
+ fs.writeFileSync(customConfigPath, JSON.stringify(customConfig));
1066
+ process.env.PUBLISHER_CONFIG_PATH = customConfigPath;
1067
+
1068
+ const result = getPublisherConfig(emptyServerRoot);
1069
+ expect(result.environments[0].name).toBe("custom-env");
1070
+ });
1071
+
1072
+ it("returns empty environments (not the bundled default) when --config points at a missing file", () => {
1073
+ process.env.PUBLISHER_CONFIG_PATH = path.join(
1074
+ process.cwd(),
1075
+ "does-not-exist.json",
1076
+ );
1077
+ // Even with bundled-default opt-in, --config with a missing target
1078
+ // is a user error and we don't paper over it.
1079
+ process.env.PUBLISHER_USE_BUNDLED_DEFAULT = "true";
1080
+ const result = getPublisherConfig(emptyServerRoot);
1081
+ expect(result.environments).toEqual([]);
1082
+ });
1083
+ });
package/src/config.ts CHANGED
@@ -1,9 +1,68 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
+ import { fileURLToPath } from "url";
3
4
  import { components } from "./api";
4
5
  import { API_PREFIX, PUBLISHER_CONFIG_NAME } from "./constants";
5
6
  import { logger } from "./logger";
6
7
 
8
+ /**
9
+ * Path to the publisher.config.json file shipped inside the published
10
+ * package. Used as a last-resort fallback so `npx @malloy-publisher/server`
11
+ * with no args still boots with the DuckDB-only sample packages.
12
+ *
13
+ * The file is copied next to the running module by `build.ts` at production
14
+ * build time. In a source/dev checkout it lives alongside this file.
15
+ */
16
+ const BUNDLED_DEFAULT_CONFIG_PATH = path.join(
17
+ path.dirname(fileURLToPath(import.meta.url)),
18
+ "default-publisher.config.json",
19
+ );
20
+
21
+ /**
22
+ * Decide which `publisher.config.json` to read.
23
+ *
24
+ * Precedence:
25
+ * 1. `--config <path>` (surfaced via `process.env.PUBLISHER_CONFIG_PATH`)
26
+ * 2. `<serverRoot>/publisher.config.json`
27
+ * 3. The bundled default shipped inside the package — ONLY when
28
+ * `process.env.PUBLISHER_USE_BUNDLED_DEFAULT === "true"`. server.ts
29
+ * sets that flag when the user passed neither `--server_root` nor
30
+ * `--config`, so `npx @malloy-publisher/server` with zero args
31
+ * boots into something usable. Callers that construct an
32
+ * EnvironmentStore programmatically (tests, embeds) don't get
33
+ * surprise filesystem fallbacks they didn't ask for.
34
+ *
35
+ * Returns `null` if step 1 was requested but the file doesn't exist —
36
+ * that's an explicit user mistake and the caller should surface it as
37
+ * an error rather than silently falling back.
38
+ */
39
+ function resolvePublisherConfigPath(serverRoot: string): {
40
+ path: string;
41
+ isBundledDefault: boolean;
42
+ } | null {
43
+ const explicitPath = process.env.PUBLISHER_CONFIG_PATH;
44
+ if (explicitPath && explicitPath.length > 0) {
45
+ if (!fs.existsSync(explicitPath)) {
46
+ return null;
47
+ }
48
+ return { path: explicitPath, isBundledDefault: false };
49
+ }
50
+
51
+ const serverRootPath = path.join(serverRoot, PUBLISHER_CONFIG_NAME);
52
+ if (fs.existsSync(serverRootPath)) {
53
+ return { path: serverRootPath, isBundledDefault: false };
54
+ }
55
+
56
+ if (
57
+ process.env.PUBLISHER_USE_BUNDLED_DEFAULT === "true" &&
58
+ fs.existsSync(BUNDLED_DEFAULT_CONFIG_PATH)
59
+ ) {
60
+ return { path: BUNDLED_DEFAULT_CONFIG_PATH, isBundledDefault: true };
61
+ }
62
+
63
+ return null;
64
+ }
65
+
7
66
  type FilesystemPath = `./${string}` | `../${string}` | `/${string}`;
8
67
  type GcsPath = `gs://${string}`;
9
68
  type ApiConnection = components["schemas"]["Connection"];
@@ -77,13 +136,30 @@ function processConfigValue(value: unknown): unknown {
77
136
  }
78
137
 
79
138
  export const getPublisherConfig = (serverRoot: string): PublisherConfig => {
80
- const publisherConfigPath = path.join(serverRoot, PUBLISHER_CONFIG_NAME);
81
- if (!fs.existsSync(publisherConfigPath)) {
139
+ const resolved = resolvePublisherConfigPath(serverRoot);
140
+ if (!resolved) {
141
+ if (
142
+ process.env.PUBLISHER_CONFIG_PATH &&
143
+ process.env.PUBLISHER_CONFIG_PATH.length > 0
144
+ ) {
145
+ // Explicit --config was given but the path didn't exist. Loud
146
+ // failure here so a typo in the flag doesn't silently boot the
147
+ // server with an empty environment list.
148
+ logger.error(
149
+ `--config path not found: ${process.env.PUBLISHER_CONFIG_PATH}. Using default empty config.`,
150
+ );
151
+ }
82
152
  return {
83
153
  frozenConfig: false,
84
154
  environments: [],
85
155
  };
86
156
  }
157
+ const publisherConfigPath = resolved.path;
158
+ if (resolved.isBundledDefault) {
159
+ logger.info(
160
+ `No publisher.config.json found at ${path.join(serverRoot, PUBLISHER_CONFIG_NAME)}; falling back to bundled DuckDB-only default. Pass --config <path> or place a config in the server root to override.`,
161
+ );
162
+ }
87
163
 
88
164
  let rawConfig: unknown;
89
165
  try {
@@ -108,6 +184,24 @@ export const getPublisherConfig = (serverRoot: string): PublisherConfig => {
108
184
  // Process environment variables in config values
109
185
  const processedConfig = processConfigValue(rawConfig);
110
186
 
187
+ // TODO: Remove this during projects cleanup
188
+ // Back-compat: the top-level key was renamed `projects` → `environments`.
189
+ // If a config still uses the old key, accept it once with a deprecation
190
+ // warning so existing on-disk configs don't silently parse as empty.
191
+ if (
192
+ processedConfig &&
193
+ typeof processedConfig === "object" &&
194
+ !("environments" in processedConfig) &&
195
+ "projects" in processedConfig
196
+ ) {
197
+ logger.warn(
198
+ `${PUBLISHER_CONFIG_NAME} uses deprecated "projects" key; rename to "environments".`,
199
+ );
200
+ (processedConfig as Record<string, unknown>).environments = (
201
+ processedConfig as Record<string, unknown>
202
+ ).projects;
203
+ }
204
+
111
205
  if (
112
206
  processedConfig &&
113
207
  typeof processedConfig === "object" &&
@@ -91,7 +91,7 @@ function validateAdminAuthoredConnection(
91
91
  ): void {
92
92
  if (connectionName === "duckdb" || connectionConfig.name === "duckdb") {
93
93
  throw new BadRequestError(
94
- "DuckDB connection name cannot be 'duckdb'; it is reserved for Publisher package sandboxes.",
94
+ "Connection name 'duckdb' is reserved for per-package sandboxes. Choose a different name for environment-level DuckDB connections (e.g. 'shared_duckdb').",
95
95
  );
96
96
  }
97
97
 
@@ -0,0 +1,23 @@
1
+ {
2
+ "frozenConfig": false,
3
+ "environments": [
4
+ {
5
+ "name": "malloy-samples",
6
+ "packages": [
7
+ {
8
+ "name": "ecommerce",
9
+ "location": "https://github.com/credibledata/malloy-samples/tree/main/ecommerce"
10
+ },
11
+ {
12
+ "name": "imdb",
13
+ "location": "https://github.com/credibledata/malloy-samples/tree/main/imdb"
14
+ },
15
+ {
16
+ "name": "faa",
17
+ "location": "https://github.com/credibledata/malloy-samples/tree/main/faa"
18
+ }
19
+ ],
20
+ "connections": []
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1,42 @@
1
+ import { describe, expect, it } from "bun:test";
2
+ import {
3
+ BadRequestError,
4
+ ConnectionAuthError,
5
+ ConnectionError,
6
+ internalErrorToHttpError,
7
+ } from "./errors";
8
+
9
+ describe("internalErrorToHttpError", () => {
10
+ it("maps ConnectionAuthError to 422", () => {
11
+ const { status, json } = internalErrorToHttpError(
12
+ new ConnectionAuthError("creds rejected for db_x"),
13
+ );
14
+ expect(status).toBe(422);
15
+ expect(json).toEqual({
16
+ code: 422,
17
+ message: "creds rejected for db_x",
18
+ });
19
+ });
20
+
21
+ it("maps BadRequestError to 400", () => {
22
+ const { status, json } = internalErrorToHttpError(
23
+ new BadRequestError("bad input"),
24
+ );
25
+ expect(status).toBe(400);
26
+ expect(json).toEqual({ code: 400, message: "bad input" });
27
+ });
28
+
29
+ it("maps ConnectionError to 502 (distinct from auth, still retryable)", () => {
30
+ const { status, json } = internalErrorToHttpError(
31
+ new ConnectionError("upstream broken"),
32
+ );
33
+ expect(status).toBe(502);
34
+ expect(json).toEqual({ code: 502, message: "upstream broken" });
35
+ });
36
+
37
+ it("falls through to 500 for unrecognized errors", () => {
38
+ const { status, json } = internalErrorToHttpError(new Error("boom"));
39
+ expect(status).toBe(500);
40
+ expect(json.message).toBe("boom");
41
+ });
42
+ });
package/src/errors.ts CHANGED
@@ -16,6 +16,8 @@ export function internalErrorToHttpError(error: Error) {
16
16
  return httpError(400, error.message);
17
17
  } else if (error instanceof ConnectionNotFoundError) {
18
18
  return httpError(404, error.message);
19
+ } else if (error instanceof ConnectionAuthError) {
20
+ return httpError(422, error.message);
19
21
  } else if (error instanceof ModelCompilationError) {
20
22
  return httpError(424, error.message);
21
23
  } else if (error instanceof ConnectionError) {
@@ -83,6 +85,12 @@ export class ConnectionError extends Error {
83
85
  }
84
86
  }
85
87
 
88
+ export class ConnectionAuthError extends Error {
89
+ constructor(message: string) {
90
+ super(message);
91
+ }
92
+ }
93
+
86
94
  export class ModelCompilationError extends Error {
87
95
  constructor(error: MalloyError) {
88
96
  super(error.message);
package/src/health.ts CHANGED
@@ -41,6 +41,32 @@ export function markReady(): void {
41
41
  }
42
42
  }
43
43
 
44
+ /**
45
+ * Marks the service as degraded: one or more environments failed to
46
+ * initialize. The surviving environments are still queryable, and
47
+ * callers polling /api/v0/status see operationalState="degraded" plus
48
+ * a failedEnvironments list.
49
+ *
50
+ * Readiness probe (/health/readiness) returns 503 — degraded pods are
51
+ * pulled out of K8s load-balancer rotation so traffic does not get
52
+ * routed to a replica that can only serve a fraction of the configured
53
+ * environments. Operators should fix the failing config and restart
54
+ * the pod; if you want degraded traffic to be served anyway (e.g. for
55
+ * a single-replica local dev instance), poll /api/v0/status directly
56
+ * instead of /health/readiness.
57
+ */
58
+ export function markDegraded(): void {
59
+ if (operationalState !== "draining") {
60
+ operationalState = "degraded";
61
+ ready = false;
62
+ logger.warn(
63
+ "Service marked as degraded; one or more environments failed to initialize. Readiness probe will fail until the config is fixed and the process restarts.",
64
+ );
65
+ } else {
66
+ logger.error("Service is already draining - cannot mark as degraded");
67
+ }
68
+ }
69
+
44
70
  /**
45
71
  * Marks the service as not ready (readiness probe will return 503).
46
72
  */
package/src/logger.ts CHANGED
@@ -28,9 +28,7 @@ export const logger = winston.createLogger({
28
28
  ? winston.format.combine(
29
29
  winston.format.uncolorize(),
30
30
  winston.format.timestamp(),
31
- winston.format.metadata({
32
- fillExcept: ["message", "level", "timestamp"],
33
- }),
31
+ winston.format.errors({ stack: true }),
34
32
  winston.format.json(),
35
33
  )
36
34
  : winston.format.combine(