@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,337 +0,0 @@
1
- /**
2
- * Filter annotation parsing and query filter injection.
3
- *
4
- * Annotation format on a Malloy source:
5
- * #(filter) [name=NAME] dimension=DIMENSION_NAME type=[equal|in|like|greater_than|less_than] [implicit] [required]
6
- *
7
- * At query time, Publisher injects `+ {where: <clause>}` into the Malloy query
8
- * based on the provided filter values and the declared filter definitions.
9
- */
10
-
11
- // ---------------------------------------------------------------------------
12
- // Types
13
- // ---------------------------------------------------------------------------
14
-
15
- export type FilterType = "equal" | "in" | "like" | "greater_than" | "less_than";
16
-
17
- const VALID_FILTER_TYPES = new Set<FilterType>([
18
- "equal",
19
- "in",
20
- "like",
21
- "greater_than",
22
- "less_than",
23
- ]);
24
-
25
- export interface FilterDefinition {
26
- /** Display name for the filter. Defaults to the dimension name. */
27
- name: string;
28
- /** The source dimension this filter targets. */
29
- dimension: string;
30
- /** Comparator type. */
31
- type: FilterType;
32
- /** Hidden from user/agent summaries; set by infrastructure (e.g. row-level security). */
33
- implicit: boolean;
34
- /** Must be provided for every query (or error). */
35
- required: boolean;
36
- }
37
-
38
- /**
39
- * Filter values provided at query time.
40
- * Keys are filter names, values are the filter input(s).
41
- */
42
- export type FilterParams = Record<string, string | string[]>;
43
-
44
- // ---------------------------------------------------------------------------
45
- // Annotation Parsing
46
- // ---------------------------------------------------------------------------
47
-
48
- const ANNOTATION_PREFIX = "#(filter)";
49
-
50
- /**
51
- * Parse a single `#(filter)` annotation string into a definition.
52
- * Returns `null` if the string is not a filter annotation.
53
- * Throws on malformed annotations (missing required fields, bad type).
54
- */
55
- export function parseFilterAnnotation(
56
- annotation: string,
57
- ): FilterDefinition | null {
58
- const trimmed = annotation.trim();
59
- if (!trimmed.startsWith(ANNOTATION_PREFIX)) {
60
- return null;
61
- }
62
-
63
- const body = trimmed.slice(ANNOTATION_PREFIX.length).trim();
64
- const tokens = tokenize(body);
65
-
66
- let name: string | undefined;
67
- let dimension: string | undefined;
68
- let type: FilterType | undefined;
69
- let implicit = false;
70
- let required = false;
71
-
72
- for (const token of tokens) {
73
- if (token.includes("=")) {
74
- const eqIndex = token.indexOf("=");
75
- const key = token.slice(0, eqIndex).toLowerCase();
76
- const value = token.slice(eqIndex + 1);
77
- switch (key) {
78
- case "name":
79
- name = value;
80
- break;
81
- case "dimension":
82
- dimension = value;
83
- break;
84
- case "type":
85
- if (!VALID_FILTER_TYPES.has(value as FilterType)) {
86
- throw new Error(
87
- `Invalid filter type "${value}". Must be one of: ${[...VALID_FILTER_TYPES].join(", ")}`,
88
- );
89
- }
90
- type = value as FilterType;
91
- break;
92
- default:
93
- throw new Error(`Unknown filter parameter "${key}"`);
94
- }
95
- } else {
96
- const flag = token.toLowerCase();
97
- if (flag === "implicit") {
98
- implicit = true;
99
- } else if (flag === "required") {
100
- required = true;
101
- } else {
102
- throw new Error(`Unknown filter flag "${token}"`);
103
- }
104
- }
105
- }
106
-
107
- if (!dimension) {
108
- throw new Error(
109
- "filter annotation missing required 'dimension' parameter",
110
- );
111
- }
112
- if (!type) {
113
- throw new Error("filter annotation missing required 'type' parameter");
114
- }
115
-
116
- return {
117
- name: name ?? dimension,
118
- dimension,
119
- type,
120
- implicit,
121
- required,
122
- };
123
- }
124
-
125
- /**
126
- * Extract all `#(filter)` definitions from a list of annotation strings
127
- * (as found on a Malloy source's `blockNotes`).
128
- */
129
- export function parseFilters(annotations: string[]): FilterDefinition[] {
130
- // Use a Map keyed by filter name so that later annotations (from an
131
- // extending source) override earlier ones (from the base source).
132
- // This is important when `source: child is parent extend {}` inherits
133
- // blockNotes from the parent — the child's annotations come last and
134
- // should win.
135
- const byName = new Map<string, FilterDefinition>();
136
- for (const annotation of annotations) {
137
- const parsed = parseFilterAnnotation(annotation);
138
- if (parsed) {
139
- byName.set(parsed.name, parsed);
140
- }
141
- }
142
- return [...byName.values()];
143
- }
144
-
145
- // ---------------------------------------------------------------------------
146
- // Filter Clause Generation
147
- // ---------------------------------------------------------------------------
148
-
149
- /**
150
- * Escape a string value for embedding in a Malloy query literal.
151
- */
152
- function escapeMalloyString(value: string): string {
153
- return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
154
- }
155
-
156
- /**
157
- * Returns true if the string is a bare boolean literal.
158
- */
159
- function isBooleanLiteral(v: string): boolean {
160
- const lower = v.toLowerCase();
161
- return lower === "true" || lower === "false";
162
- }
163
-
164
- const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
165
- const ISO_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}/;
166
-
167
- /**
168
- * Returns true if the string looks like an ISO date or timestamp.
169
- */
170
- function isDateLiteral(v: string): boolean {
171
- return ISO_DATE_RE.test(v) || ISO_TIMESTAMP_RE.test(v);
172
- }
173
-
174
- /**
175
- * Format a scalar value for Malloy.
176
- * - Boolean literals → unquoted true/false
177
- * - Date/timestamp strings → Malloy temporal literal @YYYY-MM-DD
178
- * - Everything else → single-quoted string
179
- */
180
- function malloyLiteral(v: string): string {
181
- if (isBooleanLiteral(v)) {
182
- return v.toLowerCase();
183
- }
184
- if (isDateLiteral(v)) {
185
- return `@${v.slice(0, 10)}`;
186
- }
187
- return `'${escapeMalloyString(v)}'`;
188
- }
189
-
190
- /**
191
- * Build a single Malloy predicate expression for one filter.
192
- */
193
- function buildPredicate(
194
- filter: FilterDefinition,
195
- value: string | string[],
196
- ): string {
197
- const dim = `\`${filter.dimension}\``;
198
-
199
- switch (filter.type) {
200
- case "equal": {
201
- const v = Array.isArray(value) ? value[0] : value;
202
- return `${dim} = ${malloyLiteral(v)}`;
203
- }
204
- case "in": {
205
- const values = Array.isArray(value) ? value : [value];
206
- if (values.length === 1) {
207
- return `${dim} = ${malloyLiteral(values[0])}`;
208
- }
209
- const conditions = values.map((v) => `${dim} = ${malloyLiteral(v)}`);
210
- return `(${conditions.join(" or ")})`;
211
- }
212
- case "like": {
213
- const v = Array.isArray(value) ? value[0] : value;
214
- const escaped = escapeMalloyString(v.toLowerCase());
215
- const pattern =
216
- escaped.startsWith("%") || escaped.endsWith("%")
217
- ? escaped
218
- : `%${escaped}%`;
219
- return `lower(${dim}) ~ '${pattern}'`;
220
- }
221
- case "greater_than": {
222
- const v = Array.isArray(value) ? value[0] : value;
223
- return `${dim} > ${malloyLiteral(v)}`;
224
- }
225
- case "less_than": {
226
- const v = Array.isArray(value) ? value[0] : value;
227
- return `${dim} < ${malloyLiteral(v)}`;
228
- }
229
- }
230
- }
231
-
232
- /**
233
- * Build a complete Malloy `where:` clause fragment from filter definitions
234
- * and provided parameter values.
235
- *
236
- * Returns an empty string when no filters apply.
237
- * Throws if a required filter has no value.
238
- */
239
- export function buildFilterClause(
240
- filters: FilterDefinition[],
241
- params: FilterParams,
242
- ): string {
243
- const predicates: string[] = [];
244
-
245
- for (const filter of filters) {
246
- const value = params[filter.name];
247
- const hasValue =
248
- value !== undefined &&
249
- value !== null &&
250
- (Array.isArray(value) ? value.length > 0 : value !== "");
251
-
252
- if (!hasValue) {
253
- if (filter.required) {
254
- throw new FilterValidationError(
255
- `Required filter "${filter.name}" (dimension: ${filter.dimension}) was not provided`,
256
- );
257
- }
258
- continue;
259
- }
260
-
261
- predicates.push(buildPredicate(filter, value));
262
- }
263
-
264
- if (predicates.length === 0) {
265
- return "";
266
- }
267
-
268
- return predicates.join(" and ");
269
- }
270
-
271
- /**
272
- * Append a filter refinement to a Malloy query string.
273
- * Uses Malloy's `+ {where: ...}` refinement syntax.
274
- *
275
- * If `filterClause` is empty, returns the original query unchanged.
276
- */
277
- export function injectFilterRefinement(
278
- query: string,
279
- filterClause: string,
280
- ): string {
281
- if (!filterClause) {
282
- return query;
283
- }
284
- return `${query.trimEnd()} + {where: ${filterClause}}`;
285
- }
286
-
287
- // ---------------------------------------------------------------------------
288
- // Validation Error
289
- // ---------------------------------------------------------------------------
290
-
291
- export class FilterValidationError extends Error {
292
- constructor(message: string) {
293
- super(message);
294
- this.name = "FilterValidationError";
295
- }
296
- }
297
-
298
- // ---------------------------------------------------------------------------
299
- // Helpers
300
- // ---------------------------------------------------------------------------
301
-
302
- /**
303
- * Simple tokenizer that splits on whitespace but respects quoted values.
304
- * Handles: `name="Foo Bar" dimension=status type=equal implicit`
305
- */
306
- function tokenize(input: string): string[] {
307
- const tokens: string[] = [];
308
- let current = "";
309
- let inQuote = false;
310
- let quoteChar = "";
311
-
312
- for (const ch of input) {
313
- if (inQuote) {
314
- if (ch === quoteChar) {
315
- inQuote = false;
316
- } else {
317
- current += ch;
318
- }
319
- } else if (ch === '"' || ch === "'") {
320
- inQuote = true;
321
- quoteChar = ch;
322
- } else if (ch === " " || ch === "\t") {
323
- if (current) {
324
- tokens.push(current);
325
- current = "";
326
- }
327
- } else {
328
- current += ch;
329
- }
330
- }
331
-
332
- if (current) {
333
- tokens.push(current);
334
- }
335
-
336
- return tokens;
337
- }