@malloydata/malloy 0.0.391 → 0.0.393

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 (127) hide show
  1. package/dist/api/asynchronous.js +0 -3
  2. package/dist/api/foundation/compile.d.ts +1 -1
  3. package/dist/api/foundation/config.d.ts +80 -8
  4. package/dist/api/foundation/config.js +151 -69
  5. package/dist/api/foundation/config_compile.js +27 -35
  6. package/dist/api/foundation/config_discover.js +5 -9
  7. package/dist/api/foundation/config_overlays.d.ts +6 -0
  8. package/dist/api/foundation/config_overlays.js +12 -0
  9. package/dist/api/foundation/config_resolve.d.ts +4 -1
  10. package/dist/api/foundation/config_resolve.js +64 -4
  11. package/dist/api/foundation/core.d.ts +75 -2
  12. package/dist/api/foundation/core.js +104 -6
  13. package/dist/api/foundation/index.d.ts +2 -0
  14. package/dist/api/foundation/readers.js +1 -1
  15. package/dist/api/foundation/runtime.d.ts +68 -2
  16. package/dist/api/foundation/runtime.js +212 -10
  17. package/dist/api/foundation/types.d.ts +2 -1
  18. package/dist/index.d.ts +3 -1
  19. package/dist/lang/ast/ast-utils.js +0 -1
  20. package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +1 -1
  21. package/dist/lang/ast/expressions/expr-aggregate-function.js +9 -8
  22. package/dist/lang/ast/expressions/expr-coalesce.d.ts +1 -1
  23. package/dist/lang/ast/expressions/expr-coalesce.js +2 -3
  24. package/dist/lang/ast/expressions/expr-count-distinct.js +1 -1
  25. package/dist/lang/ast/expressions/expr-count.js +6 -4
  26. package/dist/lang/ast/expressions/expr-filter-expr.js +0 -1
  27. package/dist/lang/ast/expressions/expr-func.js +9 -4
  28. package/dist/lang/ast/expressions/expr-given.d.ts +18 -0
  29. package/dist/lang/ast/expressions/expr-given.js +69 -0
  30. package/dist/lang/ast/expressions/expr-granular-time.d.ts +1 -1
  31. package/dist/lang/ast/expressions/expr-id-reference.js +3 -2
  32. package/dist/lang/ast/expressions/expr-now.js +0 -1
  33. package/dist/lang/ast/expressions/expr-props.d.ts +132 -132
  34. package/dist/lang/ast/expressions/expr-props.js +2 -2
  35. package/dist/lang/ast/expressions/expr-ungroup.d.ts +1 -1
  36. package/dist/lang/ast/expressions/expr-ungroup.js +4 -4
  37. package/dist/lang/ast/expressions/for-range.d.ts +1 -1
  38. package/dist/lang/ast/expressions/function-ordering.d.ts +1 -1
  39. package/dist/lang/ast/expressions/function-ordering.js +2 -2
  40. package/dist/lang/ast/expressions/time-literal.d.ts +3 -3
  41. package/dist/lang/ast/field-space/include-utils.js +2 -2
  42. package/dist/lang/ast/field-space/index-field-space.js +18 -23
  43. package/dist/lang/ast/field-space/passthrough-space.d.ts +1 -1
  44. package/dist/lang/ast/field-space/query-spaces.d.ts +6 -2
  45. package/dist/lang/ast/field-space/query-spaces.js +29 -19
  46. package/dist/lang/ast/field-space/reference-field.js +1 -1
  47. package/dist/lang/ast/field-space/rename-space-field.d.ts +1 -1
  48. package/dist/lang/ast/field-space/rename-space-field.js +2 -2
  49. package/dist/lang/ast/field-space/struct-space-field-base.js +2 -3
  50. package/dist/lang/ast/index.d.ts +2 -0
  51. package/dist/lang/ast/index.js +2 -0
  52. package/dist/lang/ast/query-builders/index-builder.d.ts +1 -1
  53. package/dist/lang/ast/query-builders/index-builder.js +4 -3
  54. package/dist/lang/ast/query-builders/reduce-builder.d.ts +2 -2
  55. package/dist/lang/ast/query-builders/reduce-builder.js +4 -5
  56. package/dist/lang/ast/query-elements/query-arrow.js +3 -2
  57. package/dist/lang/ast/query-elements/query-base.d.ts +1 -1
  58. package/dist/lang/ast/query-elements/query-base.js +1 -1
  59. package/dist/lang/ast/query-elements/query-refine.js +3 -1
  60. package/dist/lang/ast/query-items/field-declaration.js +2 -2
  61. package/dist/lang/ast/query-properties/drill.js +6 -6
  62. package/dist/lang/ast/query-properties/filters.js +2 -2
  63. package/dist/lang/ast/query-properties/nest.js +3 -3
  64. package/dist/lang/ast/source-elements/composite-source.js +5 -3
  65. package/dist/lang/ast/source-elements/named-source.js +4 -0
  66. package/dist/lang/ast/source-elements/sql-source.js +2 -2
  67. package/dist/lang/ast/source-elements/table-source.js +3 -1
  68. package/dist/lang/ast/source-properties/join.js +4 -4
  69. package/dist/lang/ast/source-query-elements/sq-reference.js +2 -1
  70. package/dist/lang/ast/statements/define-given.d.ts +23 -0
  71. package/dist/lang/ast/statements/define-given.js +163 -0
  72. package/dist/lang/ast/statements/import-statement.js +72 -9
  73. package/dist/lang/ast/typedesc-utils.d.ts +3 -1
  74. package/dist/lang/ast/typedesc-utils.js +4 -47
  75. package/dist/lang/ast/types/expr-value.js +2 -3
  76. package/dist/lang/ast/types/expression-def.d.ts +2 -2
  77. package/dist/lang/ast/types/expression-def.js +2 -2
  78. package/dist/lang/ast/types/malloy-element.d.ts +5 -15
  79. package/dist/lang/ast/types/malloy-element.js +113 -1
  80. package/dist/lang/ast/types/space-field.js +7 -9
  81. package/dist/lang/ast/view-elements/reference-view.js +6 -5
  82. package/dist/lang/ast/view-elements/refine-utils.js +1 -1
  83. package/dist/lang/composite-source-utils.d.ts +30 -15
  84. package/dist/lang/composite-source-utils.js +234 -64
  85. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +171 -169
  86. package/dist/lang/lib/Malloy/MalloyLexer.js +1194 -1178
  87. package/dist/lang/lib/Malloy/MalloyParser.d.ts +408 -334
  88. package/dist/lang/lib/Malloy/MalloyParser.js +3062 -2561
  89. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +68 -0
  90. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +43 -0
  91. package/dist/lang/malloy-to-ast.d.ts +13 -1
  92. package/dist/lang/malloy-to-ast.js +90 -11
  93. package/dist/lang/parse-log.d.ts +8 -0
  94. package/dist/lang/prettify/filter-type.d.ts +3 -0
  95. package/dist/lang/prettify/filter-type.js +38 -0
  96. package/dist/lang/prettify/formatter.js +6 -0
  97. package/dist/lang/prettify/inline-renderer.js +20 -0
  98. package/dist/lang/prettify/rules.d.ts +1 -1
  99. package/dist/lang/prettify/rules.js +1 -0
  100. package/dist/lang/prettify/sections.js +2 -0
  101. package/dist/lang/prettify/tokens.js +2 -0
  102. package/dist/lang/test/expr-to-str.js +2 -0
  103. package/dist/lang/test/parse-expects.d.ts +1 -0
  104. package/dist/lang/test/parse-expects.js +27 -10
  105. package/dist/model/constant_expression_compiler.js +1 -0
  106. package/dist/model/expression_compiler.d.ts +2 -1
  107. package/dist/model/expression_compiler.js +41 -1
  108. package/dist/model/given_binding.d.ts +2 -0
  109. package/dist/model/given_binding.js +204 -0
  110. package/dist/model/index.d.ts +1 -1
  111. package/dist/model/index.js +2 -1
  112. package/dist/model/malloy_types.d.ts +163 -36
  113. package/dist/model/malloy_types.js +97 -0
  114. package/dist/model/query_model_contract.d.ts +2 -1
  115. package/dist/model/query_model_impl.d.ts +2 -1
  116. package/dist/model/query_model_impl.js +7 -0
  117. package/dist/model/query_node.d.ts +2 -1
  118. package/dist/model/source_def_utils.d.ts +2 -1
  119. package/dist/model/source_def_utils.js +4 -0
  120. package/dist/model/utils.d.ts +14 -1
  121. package/dist/model/utils.js +41 -0
  122. package/dist/to_stable.js +1 -1
  123. package/dist/util/closest_match.d.ts +9 -0
  124. package/dist/util/closest_match.js +47 -0
  125. package/dist/version.d.ts +1 -1
  126. package/dist/version.js +1 -1
  127. package/package.json +4 -4
@@ -6,6 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.prepareConfig = prepareConfig;
8
8
  const registry_1 = require("../../connection/registry");
9
+ const config_overlays_1 = require("./config_overlays");
9
10
  /**
10
11
  * Synchronous top-level walk of a compiled config tree. Extracts the
11
12
  * non-connection sections (which only contain literals — see the section
@@ -22,9 +23,11 @@ const registry_1 = require("../../connection/registry");
22
23
  * via `includeDefaultConnections`. Property defaults are filled in at
23
24
  * lookup time alongside reference resolution.
24
25
  */
25
- function prepareConfig(compiled, _log) {
26
+ function prepareConfig(compiled, overlays, log) {
26
27
  let compiledConnections = {};
27
28
  let manifestPath;
29
+ let givensPath;
30
+ let finalizeGivens;
28
31
  let virtualMap;
29
32
  let includeDefaultConnections = false;
30
33
  for (const [key, node] of Object.entries(compiled.entries)) {
@@ -36,8 +39,16 @@ function prepareConfig(compiled, _log) {
36
39
  break;
37
40
  }
38
41
  case 'manifestPath': {
39
- if (node.kind === 'value' && typeof node.value === 'string') {
40
- manifestPath = node.value;
42
+ manifestPath = resolveSyncStringSetting(node, overlays, log, 'manifestPath');
43
+ break;
44
+ }
45
+ case 'givensPath': {
46
+ givensPath = resolveSyncStringSetting(node, overlays, log, 'givensPath');
47
+ break;
48
+ }
49
+ case 'finalizeGivens': {
50
+ if (node.kind === 'value' && isStringArray(node.value)) {
51
+ finalizeGivens = node.value;
41
52
  }
42
53
  break;
43
54
  }
@@ -60,7 +71,16 @@ function prepareConfig(compiled, _log) {
60
71
  if (includeDefaultConnections) {
61
72
  fabricateMissingConnections(compiledConnections);
62
73
  }
63
- return { compiledConnections, manifestPath, virtualMap };
74
+ return {
75
+ compiledConnections,
76
+ manifestPath,
77
+ givensPath,
78
+ finalizeGivens,
79
+ virtualMap,
80
+ };
81
+ }
82
+ function isStringArray(v) {
83
+ return Array.isArray(v) && v.every(x => typeof x === 'string');
64
84
  }
65
85
  /**
66
86
  * Pull each well-formed compiled connection entry out of the `connections`
@@ -105,4 +125,44 @@ function fabricateMissingConnections(compiledConnections) {
105
125
  };
106
126
  }
107
127
  }
128
+ /**
129
+ * Resolve a top-level string setting that may be a literal or an overlay
130
+ * reference. Top-level scalars are read at construction time, so the overlay
131
+ * MUST resolve synchronously — same rule that applies to `configURL`. An
132
+ * overlay returning a Promise is a hard misuse: warn loudly and drop, so the
133
+ * application notices instead of silently losing the setting.
134
+ *
135
+ * Failure modes mirror connection-property resolution otherwise:
136
+ * - unknown overlay source → warn + drop (case 1)
137
+ * - overlay returns undefined → silent drop (case 2; falls back to default)
138
+ * - non-string literal node → returns undefined (compile-time validation
139
+ * already warned)
140
+ */
141
+ function resolveSyncStringSetting(node, overlays, log, settingName) {
142
+ if (node.kind === 'value') {
143
+ return typeof node.value === 'string' ? node.value : undefined;
144
+ }
145
+ if (node.kind === 'reference') {
146
+ const overlay = overlays[node.source];
147
+ if (!overlay) {
148
+ log.push({
149
+ message: `unknown overlay source "${node.source}" for "${settingName}"`,
150
+ severity: 'warn',
151
+ code: 'config-overlay',
152
+ });
153
+ return undefined;
154
+ }
155
+ const v = overlay(node.path);
156
+ if ((0, config_overlays_1.isThenable)(v)) {
157
+ log.push({
158
+ message: `the \`${node.source}\` overlay returned a Promise for "${settingName}"; top-level string settings must resolve synchronously`,
159
+ severity: 'warn',
160
+ code: 'config-overlay',
161
+ });
162
+ return undefined;
163
+ }
164
+ return typeof v === 'string' ? v : undefined;
165
+ }
166
+ return undefined;
167
+ }
108
168
  //# sourceMappingURL=config_resolve.js.map
@@ -1,5 +1,5 @@
1
1
  import type { LogMessage } from '../../lang';
2
- import type { BuildID, CompiledQuery, DocumentLocation, BooleanFieldDef, JSONFieldDef, NumberFieldDef, StringFieldDef, FilterCondition, Query as InternalQuery, ModelDef, DocumentPosition as ModelDocumentPosition, NamedQueryDef, StructDef, TurtleDef, NativeUnsupportedFieldDef, ImportLocation, Annotation, NamedModelObject, AtomicFieldDef, DateFieldDef, ATimestampFieldDef, SourceDef, Argument, SourceComponentInfo, DocumentReference, PersistableSourceDef } from '../../model';
2
+ import type { BuildID, CompiledQuery, ConstantExpr, DocumentLocation, BooleanFieldDef, JSONFieldDef, NumberFieldDef, StringFieldDef, FilterCondition, Given as InternalGiven, GivenID, GivenTypeDef, Query as InternalQuery, ModelDef, DocumentPosition as ModelDocumentPosition, NamedQueryDef, StructDef, TurtleDef, NativeUnsupportedFieldDef, ImportLocation, Annotation, NamedModelObject, AtomicFieldDef, DateFieldDef, ATimestampFieldDef, SourceDef, Argument, SourceComponentInfo, DocumentReference, PersistableSourceDef } from '../../model';
3
3
  import { QueryModel } from '../../model';
4
4
  import type { Dialect } from '../../dialect';
5
5
  import type { BuildGraph, CompileQueryOptions } from './types';
@@ -230,14 +230,41 @@ export declare class ExploreField extends Explore {
230
230
  get sourceClasses(): string[];
231
231
  get queryTimezone(): string | undefined;
232
232
  }
233
+ /**
234
+ * Runtime-aware concerns layered onto a `Model` after it leaves the
235
+ * compiler. `Malloy.compile()` returns a `Model` with no context; a
236
+ * `Runtime.loadModel()` decoration attaches the runtime's context so
237
+ * context-sensitive views (currently `Model.givens` filtering finalized
238
+ * names; in future, tenant overrides / session bindings / etc.) work
239
+ * correctly. New runtime-aware concerns add a field here rather than a
240
+ * parallel constructor parameter.
241
+ */
242
+ export interface RuntimeContext {
243
+ /** Surface names of givens locked at the runtime layer (from
244
+ * `config.finalizeGivens`). Filtered out of `Model.givens` so
245
+ * introspection-driven UIs don't render editors for them. */
246
+ readonly finalizedGivens?: ReadonlySet<string>;
247
+ }
233
248
  export declare class Model implements Taggable {
234
249
  private modelDef;
235
250
  readonly problems: LogMessage[];
236
251
  readonly fromSources: string[];
252
+ /**
253
+ * Runtime-aware context layered onto this Model. `Malloy.compile()`
254
+ * leaves it undefined; `Runtime.loadModel()` paths attach the
255
+ * runtime's context so methods like `Model.givens` filter correctly.
256
+ */
257
+ private readonly runtimeContext?;
237
258
  private readonly references;
238
259
  private _queryModel?;
239
260
  private readonly contentsMap;
240
- constructor(modelDef: ModelDef, problems: LogMessage[], fromSources: string[], existingQueryModel?: QueryModel);
261
+ constructor(modelDef: ModelDef, problems: LogMessage[], fromSources: string[], existingQueryModel?: QueryModel,
262
+ /**
263
+ * Runtime-aware context layered onto this Model. `Malloy.compile()`
264
+ * leaves it undefined; `Runtime.loadModel()` paths attach the
265
+ * runtime's context so methods like `Model.givens` filter correctly.
266
+ */
267
+ runtimeContext?: RuntimeContext | undefined);
241
268
  /** Safe lookup in model contents by name. */
242
269
  getContent(name: string): NamedModelObject | undefined;
243
270
  get queryModel(): QueryModel;
@@ -247,6 +274,16 @@ export declare class Model implements Taggable {
247
274
  * the model wasn't modified (only queries were added).
248
275
  */
249
276
  getExistingQueryModel(): QueryModel | undefined;
277
+ /**
278
+ * The givens this model surfaces, keyed by caller-facing surface name.
279
+ * Used by whole-model parameter-editor UIs to render input widgets for
280
+ * every given the model can accept.
281
+ *
282
+ * Internal-only givens (declared but never surfaced into the namespace,
283
+ * resolved purely via defaults) are NOT in this map — the caller has no
284
+ * way to set them, so listing them would mislead a UI.
285
+ */
286
+ get givens(): ReadonlyMap<string, Given>;
250
287
  tagParse(spec?: TagParseSpec): MalloyTagParse;
251
288
  getTaglines(prefix?: RegExp): string[];
252
289
  /**
@@ -428,6 +465,30 @@ export declare class PersistSource implements Taggable {
428
465
  */
429
466
  get _model(): Model;
430
467
  }
468
+ /**
469
+ * Foundation API wrapper for a given declaration. Parallel to Explore /
470
+ * PreparedQuery — exposes a stable, callerable surface over the internal
471
+ * `Given` IR record. Returned from `PreparedQuery.givens`.
472
+ */
473
+ export declare class Given implements Taggable {
474
+ readonly name: string;
475
+ readonly id: GivenID;
476
+ private readonly _internal;
477
+ /**
478
+ * @param name Caller-facing surface name in the model (post-rename
479
+ * on import). The key by which the caller passes a
480
+ * value to `.run({givens: {[name]: ...}})`.
481
+ * @param id Global GivenID. Stable across imports and renames.
482
+ * @param _internal The internal Given declaration record.
483
+ */
484
+ constructor(name: string, id: GivenID, _internal: InternalGiven);
485
+ get type(): GivenTypeDef;
486
+ /** `undefined` when no default — the caller must supply at run time. */
487
+ get default(): ConstantExpr | undefined;
488
+ get location(): DocumentLocation | undefined;
489
+ tagParse(spec?: TagParseSpec): MalloyTagParse;
490
+ getTaglines(prefix?: RegExp): string[];
491
+ }
431
492
  export declare class PreparedQuery implements Taggable {
432
493
  private _model;
433
494
  problems: LogMessage[];
@@ -460,6 +521,18 @@ export declare class PreparedQuery implements Taggable {
460
521
  * Get the Model this query belongs to.
461
522
  */
462
523
  get model(): Model;
524
+ /**
525
+ * The givens this specific query references, keyed by caller-facing
526
+ * surface name. Used by "run this query" UIs to prompt only for the
527
+ * givens this query actually touches, not every given declared in the
528
+ * model.
529
+ *
530
+ * Computed as `model.givens` filtered by `query.givenUsage` — i.e. the
531
+ * intersection of "what the model surfaces" with "what this query
532
+ * needs." Internal-only givens (referenced but never surfaced) stay
533
+ * invisible because they're not in `model.givens` to begin with.
534
+ */
535
+ get givens(): ReadonlyMap<string, Given>;
463
536
  }
464
537
  export declare class PreparedResult implements Taggable {
465
538
  protected modelDef: ModelDef;
@@ -4,12 +4,13 @@
4
4
  * SPDX-License-Identifier: MIT
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.PreparedResult = exports.PreparedQuery = exports.PersistSource = exports.Model = exports.ExploreField = exports.QueryField = exports.Query = exports.StringField = exports.UnsupportedField = exports.JSONField = exports.BooleanField = exports.NumberField = exports.TimestampField = exports.DateField = exports.AtomicField = exports.Explore = exports.JoinRelationship = exports.TimestampTimeframe = exports.DateTimeframe = exports.AtomicFieldType = exports.SourceRelationship = void 0;
7
+ exports.PreparedResult = exports.PreparedQuery = exports.Given = exports.PersistSource = exports.Model = exports.ExploreField = exports.QueryField = exports.Query = exports.StringField = exports.UnsupportedField = exports.JSONField = exports.BooleanField = exports.NumberField = exports.TimestampField = exports.DateField = exports.AtomicField = exports.Explore = exports.JoinRelationship = exports.TimestampTimeframe = exports.DateTimeframe = exports.AtomicFieldType = exports.SourceRelationship = void 0;
8
8
  const model_1 = require("../../model");
9
9
  const utils_1 = require("../../model/utils");
10
10
  const dialect_1 = require("../../dialect");
11
11
  const persist_utils_1 = require("../../model/persist_utils");
12
12
  const source_def_utils_1 = require("../../model/source_def_utils");
13
+ const given_binding_1 = require("../../model/given_binding");
13
14
  const malloy_tag_1 = require("@malloydata/malloy-tag");
14
15
  const annotation_1 = require("../../annotation");
15
16
  const to_stable_1 = require("../../to_stable");
@@ -742,15 +743,19 @@ class ExploreField extends Explore {
742
743
  }
743
744
  }
744
745
  exports.ExploreField = ExploreField;
745
- // =============================================================================
746
- // Model
747
- // =============================================================================
748
746
  class Model {
749
- constructor(modelDef, problems, fromSources, existingQueryModel) {
747
+ constructor(modelDef, problems, fromSources, existingQueryModel,
748
+ /**
749
+ * Runtime-aware context layered onto this Model. `Malloy.compile()`
750
+ * leaves it undefined; `Runtime.loadModel()` paths attach the
751
+ * runtime's context so methods like `Model.givens` filter correctly.
752
+ */
753
+ runtimeContext) {
750
754
  var _a, _b;
751
755
  this.modelDef = modelDef;
752
756
  this.problems = problems;
753
757
  this.fromSources = fromSources;
758
+ this.runtimeContext = runtimeContext;
754
759
  this.references = new reference_list_1.ReferenceList((_a = fromSources[0]) !== null && _a !== void 0 ? _a : '', (_b = modelDef.references) !== null && _b !== void 0 ? _b : []);
755
760
  this._queryModel = existingQueryModel;
756
761
  this.contentsMap = new Map(Object.entries(modelDef.contents));
@@ -773,6 +778,33 @@ class Model {
773
778
  getExistingQueryModel() {
774
779
  return this._queryModel;
775
780
  }
781
+ /**
782
+ * The givens this model surfaces, keyed by caller-facing surface name.
783
+ * Used by whole-model parameter-editor UIs to render input widgets for
784
+ * every given the model can accept.
785
+ *
786
+ * Internal-only givens (declared but never surfaced into the namespace,
787
+ * resolved purely via defaults) are NOT in this map — the caller has no
788
+ * way to set them, so listing them would mislead a UI.
789
+ */
790
+ get givens() {
791
+ var _a, _b;
792
+ const out = new Map();
793
+ const givens = this.modelDef.givens;
794
+ if (!givens)
795
+ return out;
796
+ for (const [surfaceName, entry] of this.contentsMap) {
797
+ if (entry.type !== 'given')
798
+ continue;
799
+ if ((_b = (_a = this.runtimeContext) === null || _a === void 0 ? void 0 : _a.finalizedGivens) === null || _b === void 0 ? void 0 : _b.has(surfaceName))
800
+ continue;
801
+ const decl = givens[entry.id];
802
+ if (!decl)
803
+ continue;
804
+ out.set(surfaceName, new Given(surfaceName, entry.id, decl));
805
+ }
806
+ return out;
807
+ }
776
808
  tagParse(spec) {
777
809
  return (0, annotation_1.annotationToTag)(this.modelDef.annotation, spec);
778
810
  }
@@ -1097,6 +1129,42 @@ exports.PersistSource = PersistSource;
1097
1129
  // =============================================================================
1098
1130
  // PreparedQuery
1099
1131
  // =============================================================================
1132
+ /**
1133
+ * Foundation API wrapper for a given declaration. Parallel to Explore /
1134
+ * PreparedQuery — exposes a stable, callerable surface over the internal
1135
+ * `Given` IR record. Returned from `PreparedQuery.givens`.
1136
+ */
1137
+ class Given {
1138
+ /**
1139
+ * @param name Caller-facing surface name in the model (post-rename
1140
+ * on import). The key by which the caller passes a
1141
+ * value to `.run({givens: {[name]: ...}})`.
1142
+ * @param id Global GivenID. Stable across imports and renames.
1143
+ * @param _internal The internal Given declaration record.
1144
+ */
1145
+ constructor(name, id, _internal) {
1146
+ this.name = name;
1147
+ this.id = id;
1148
+ this._internal = _internal;
1149
+ }
1150
+ get type() {
1151
+ return this._internal.type;
1152
+ }
1153
+ /** `undefined` when no default — the caller must supply at run time. */
1154
+ get default() {
1155
+ return this._internal.default;
1156
+ }
1157
+ get location() {
1158
+ return this._internal.location;
1159
+ }
1160
+ tagParse(spec) {
1161
+ return (0, annotation_1.annotationToTag)(this._internal.annotation, spec);
1162
+ }
1163
+ getTaglines(prefix) {
1164
+ return (0, annotation_1.annotationToTaglines)(this._internal.annotation, prefix);
1165
+ }
1166
+ }
1167
+ exports.Given = Given;
1100
1168
  class PreparedQuery {
1101
1169
  constructor(query, _model, problems, name) {
1102
1170
  this._model = _model;
@@ -1129,7 +1197,13 @@ class PreparedQuery {
1129
1197
  */
1130
1198
  getPreparedResult(options) {
1131
1199
  const queryModel = this._model.queryModel;
1132
- const translatedQuery = queryModel.compileQuery(this._query, options);
1200
+ const prepareResultOptions = {
1201
+ ...options,
1202
+ resolvedGivens: (options === null || options === void 0 ? void 0 : options.givens)
1203
+ ? (0, given_binding_1.resolveSuppliedGivens)(options.givens, this._modelDef)
1204
+ : undefined,
1205
+ };
1206
+ const translatedQuery = queryModel.compileQuery(this._query, prepareResultOptions);
1133
1207
  return new PreparedResult({
1134
1208
  ...translatedQuery,
1135
1209
  queryName: this.name || translatedQuery.queryName,
@@ -1158,6 +1232,30 @@ class PreparedQuery {
1158
1232
  get model() {
1159
1233
  return this._model;
1160
1234
  }
1235
+ /**
1236
+ * The givens this specific query references, keyed by caller-facing
1237
+ * surface name. Used by "run this query" UIs to prompt only for the
1238
+ * givens this query actually touches, not every given declared in the
1239
+ * model.
1240
+ *
1241
+ * Computed as `model.givens` filtered by `query.givenUsage` — i.e. the
1242
+ * intersection of "what the model surfaces" with "what this query
1243
+ * needs." Internal-only givens (referenced but never surfaced) stay
1244
+ * invisible because they're not in `model.givens` to begin with.
1245
+ */
1246
+ get givens() {
1247
+ const out = new Map();
1248
+ const usage = this._query.givenUsage;
1249
+ if (!usage || usage.length === 0)
1250
+ return out;
1251
+ const referenced = new Set(usage.map(g => g.id));
1252
+ for (const [name, given] of this._model.givens) {
1253
+ if (referenced.has(given.id)) {
1254
+ out.set(name, given);
1255
+ }
1256
+ }
1257
+ return out;
1258
+ }
1161
1259
  }
1162
1260
  exports.PreparedQuery = PreparedQuery;
1163
1261
  // =============================================================================
@@ -9,7 +9,9 @@ export { type ResultJSON, type DataColumn, type DataArrayOrRecord, Result, DataA
9
9
  export { type WriteStream, DataWriter, JSONWriter, CSVWriter } from './writers';
10
10
  export { Runtime, ConnectionRuntime, SingleConnectionRuntime, ModelMaterializer, QueryMaterializer, PreparedResultMaterializer, ExploreMaterializer, } from './runtime';
11
11
  export { Manifest, MalloyConfig } from './config';
12
+ export type { FilesystemContext, MalloyConfigOptions } from './config';
12
13
  export type { Overlay, ConfigOverlays } from './config_overlays';
14
+ export type { RuntimeContext } from './core';
13
15
  export { envOverlay, contextOverlay, defaultConfigOverlays, } from './config_overlays';
14
16
  export { discoverConfig } from './config_discover';
15
17
  export { Malloy, MalloyError, type MalloyCompileOptions, type MalloyRunOptions, } from './compile';
@@ -26,7 +26,7 @@ async function readURL(urlReader, url) {
26
26
  contents,
27
27
  invalidationKey: isInternalURL(url.toString())
28
28
  ? null
29
- : invalidationKey !== null && invalidationKey !== void 0 ? invalidationKey : hashForInvalidationKey(contents),
29
+ : (invalidationKey !== null && invalidationKey !== void 0 ? invalidationKey : hashForInvalidationKey(contents)),
30
30
  };
31
31
  }
32
32
  async function getInvalidationKey(urlReader, url) {
@@ -1,6 +1,6 @@
1
1
  import type { Connection, LookupConnection } from '../../connection/types';
2
2
  import type { URLReader, EventStream } from '../../runtime_types';
3
- import type { ModelDef, Query as InternalQuery, SearchIndexResult, SearchValueMapResult, QueryRunStats, BuildManifest, VirtualMap } from '../../model';
3
+ import type { ModelDef, Query as InternalQuery, SearchIndexResult, SearchValueMapResult, QueryRunStats, BuildManifest, GivenValue, VirtualMap } from '../../model';
4
4
  import type { Dialect } from '../../dialect';
5
5
  import type { RunSQLOptions } from '../../run_sql_options';
6
6
  import type { CacheManager } from './cache';
@@ -49,12 +49,22 @@ export declare class Runtime {
49
49
  private _config;
50
50
  private _buildManifest;
51
51
  private _resolvedBuildManifestPromise;
52
+ private _resolvedGivensPromise;
53
+ private _constructorGivensMap;
54
+ private _finalizedGivensSet;
52
55
  private _virtualMap;
53
- constructor({ urlReader, connections, connection, config, buildManifest, eventStream, cacheManager, }: {
56
+ constructor({ urlReader, connections, connection, config, buildManifest, eventStream, cacheManager, givens, }: {
54
57
  urlReader?: URLReader;
55
58
  buildManifest?: BuildManifest;
56
59
  eventStream?: EventStream;
57
60
  cacheManager?: CacheManager;
61
+ /**
62
+ * Per-runtime givens supplied directly by the host (multi-tenant
63
+ * server passing JWT-derived values; tests; scripts). Overlaid on top
64
+ * of `config.givensURL` per-key, then per-query supply via
65
+ * `.run({givens: ...})` overlays on top of both.
66
+ */
67
+ givens?: Record<string, GivenValue>;
58
68
  } & Connectionable);
59
69
  /**
60
70
  * @return The `CacheManager` for this runtime instance.
@@ -72,6 +82,35 @@ export declare class Runtime {
72
82
  * @return The `EventStream` for this runtime instance.
73
83
  */
74
84
  get eventStream(): EventStream | undefined;
85
+ /**
86
+ * Constructor-supplied givens, exposed for the materializer's per-query
87
+ * merge. Underscore-prefixed because it's the constructor layer only —
88
+ * use `getGivens()` for the full file+constructor view a caller usually
89
+ * wants.
90
+ *
91
+ * @internal Accessed from QueryMaterializer.
92
+ */
93
+ get _constructorGivens(): ReadonlyMap<string, GivenValue>;
94
+ /**
95
+ * The runtime's effective givens — file (from `config.givensPath`,
96
+ * lazily loaded) merged with the constructor `givens:` option, with
97
+ * the constructor winning per-key. Per-query supply via
98
+ * `.run({ givens: ... })` is *not* included; that's a per-call
99
+ * argument, not runtime state.
100
+ *
101
+ * Async because the file may not yet be loaded; subsequent calls share
102
+ * the cached promise.
103
+ */
104
+ getGivens(): Promise<ReadonlyMap<string, GivenValue>>;
105
+ /**
106
+ * Surface names of givens locked at the runtime layer (the resolved set
107
+ * the `config.finalizeGivens` directive produced). Per-query supply for
108
+ * these names throws; `Model.givens` and `PreparedQuery.givens` filter
109
+ * them out so introspection-driven UIs don't render editors for them.
110
+ *
111
+ * @internal Accessed from QueryMaterializer and Model construction.
112
+ */
113
+ get _finalizedGivens(): ReadonlySet<string>;
75
114
  /**
76
115
  * Setter — install an explicit build manifest for persist source
77
116
  * substitution. From this point on, compiled queries resolve persist
@@ -114,6 +153,23 @@ export declare class Runtime {
114
153
  * of the public API — the leading underscore + `@internal` marks intent.
115
154
  */
116
155
  _resolveBuildManifest(): Promise<BuildManifest | undefined>;
156
+ /**
157
+ * Resolve the per-runtime givens map from `config.givensURL` (the file
158
+ * `givensPath` points at). Lazy and cached as a Promise — first compile
159
+ * triggers the read, subsequent compiles share the result.
160
+ *
161
+ * Stricter error policy than `_resolveBuildManifest`: a missing file or
162
+ * malformed JSON throws. Per design, the per-runtime givens layer is a
163
+ * configured contract, not an opportunistic read; a misconfigured path
164
+ * should fail loudly at the first compile, not silently degrade.
165
+ *
166
+ * Returns `undefined` only when no `givensURL` is configured.
167
+ *
168
+ * @internal Accessed from QueryMaterializer.
169
+ */
170
+ _resolveGivens(): Promise<Record<string, GivenValue> | undefined>;
171
+ /** @internal */
172
+ _invalidateGivensCache(): void;
117
173
  /**
118
174
  * The virtual map for virtual source resolution.
119
175
  * When set, compiled queries automatically resolve virtual sources
@@ -157,6 +213,16 @@ export declare class Runtime {
157
213
  * or loading further related objects.
158
214
  */
159
215
  loadModel(source: ModelURL | ModelString, options?: ParseOptions & CompileOptions & CompileQueryOptions): ModelMaterializer;
216
+ /**
217
+ * Re-wrap a `Model` produced by `Malloy.compile` with this runtime's
218
+ * `RuntimeContext` so context-sensitive Model methods (currently
219
+ * `Model.givens` filtering finalized names; future runtime-aware
220
+ * concerns) work correctly. No-op when there's nothing in the context.
221
+ *
222
+ * @internal Accessed from `ModelMaterializer.extendModel` and Runtime
223
+ * loadModel paths.
224
+ */
225
+ _withRuntimeContext(m: Model): Model;
160
226
  _loadModelFromModelDef(modelDef: ModelDef, options?: CompileQueryOptions): ModelMaterializer;
161
227
  /**
162
228
  * Load a Malloy query by URL or contents.