@malloydata/malloy 0.0.399 → 0.0.401

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 (91) hide show
  1. package/dist/api/annotation-utils.d.ts +36 -0
  2. package/dist/api/annotation-utils.js +76 -0
  3. package/dist/api/core.js +3 -3
  4. package/dist/api/foundation/annotation.d.ts +115 -0
  5. package/dist/{annotation.js → api/foundation/annotation.js} +87 -42
  6. package/dist/api/foundation/compile.js +3 -3
  7. package/dist/api/foundation/core.d.ts +122 -29
  8. package/dist/api/foundation/core.js +185 -59
  9. package/dist/api/foundation/index.d.ts +1 -1
  10. package/dist/api/foundation/index.js +3 -2
  11. package/dist/api/foundation/runtime.js +2 -2
  12. package/dist/{taggable.d.ts → api/foundation/taggable.d.ts} +4 -4
  13. package/dist/api/foundation/types.d.ts +1 -1
  14. package/dist/connection/types.d.ts +3 -2
  15. package/dist/index.d.ts +9 -2
  16. package/dist/index.js +17 -4
  17. package/dist/{prefix.js → lang/annotation-prefix.js} +1 -1
  18. package/dist/lang/ast/expressions/expr-given.js +1 -1
  19. package/dist/lang/ast/field-space/dynamic-space.d.ts +1 -1
  20. package/dist/lang/ast/field-space/dynamic-space.js +2 -2
  21. package/dist/lang/ast/field-space/include-utils.d.ts +3 -3
  22. package/dist/lang/ast/field-space/query-spaces.js +2 -2
  23. package/dist/lang/ast/field-space/reference-field.js +5 -5
  24. package/dist/lang/ast/field-space/refined-space.d.ts +2 -2
  25. package/dist/lang/ast/field-space/refined-space.js +3 -3
  26. package/dist/lang/ast/field-space/rename-space-field.d.ts +2 -2
  27. package/dist/lang/ast/field-space/rename-space-field.js +4 -4
  28. package/dist/lang/ast/field-space/static-space.js +1 -1
  29. package/dist/lang/ast/query-elements/anonymous-query.d.ts +2 -2
  30. package/dist/lang/ast/query-elements/anonymous-query.js +3 -3
  31. package/dist/lang/ast/query-elements/query-arrow.js +2 -2
  32. package/dist/lang/ast/query-items/field-declaration.d.ts +2 -2
  33. package/dist/lang/ast/query-items/field-declaration.js +1 -1
  34. package/dist/lang/ast/query-items/field-references.d.ts +3 -3
  35. package/dist/lang/ast/query-properties/nest.js +2 -2
  36. package/dist/lang/ast/source-elements/composite-source.d.ts +2 -2
  37. package/dist/lang/ast/source-elements/refined-source.d.ts +2 -2
  38. package/dist/lang/ast/source-elements/sql-source.js +1 -1
  39. package/dist/lang/ast/source-elements/typed-source.js +7 -4
  40. package/dist/lang/ast/source-properties/join.d.ts +2 -2
  41. package/dist/lang/ast/source-properties/join.js +2 -2
  42. package/dist/lang/ast/source-properties/renames.d.ts +2 -2
  43. package/dist/lang/ast/source-properties/user-type-shape.d.ts +2 -2
  44. package/dist/lang/ast/source-properties/user-type-shape.js +7 -7
  45. package/dist/lang/ast/source-properties/view-field-declaration.d.ts +1 -1
  46. package/dist/lang/ast/source-properties/view-field-declaration.js +2 -2
  47. package/dist/lang/ast/source-query-elements/include-item.d.ts +3 -3
  48. package/dist/lang/ast/statements/define-given.d.ts +2 -2
  49. package/dist/lang/ast/statements/define-given.js +2 -2
  50. package/dist/lang/ast/statements/define-query.d.ts +2 -2
  51. package/dist/lang/ast/statements/define-query.js +2 -2
  52. package/dist/lang/ast/statements/define-source.d.ts +2 -2
  53. package/dist/lang/ast/statements/define-source.js +2 -2
  54. package/dist/lang/ast/statements/define-user-type.d.ts +2 -2
  55. package/dist/lang/ast/statements/define-user-type.js +1 -1
  56. package/dist/lang/ast/statements/import-statement.js +1 -1
  57. package/dist/lang/ast/types/annotation-elements.js +3 -3
  58. package/dist/lang/ast/types/definition-list.d.ts +3 -3
  59. package/dist/lang/ast/types/literal.d.ts +1 -1
  60. package/dist/lang/ast/types/malloy-element.d.ts +4 -4
  61. package/dist/lang/ast/types/malloy-element.js +15 -15
  62. package/dist/lang/ast/types/noteable.d.ts +5 -5
  63. package/dist/lang/ast/types/pipeline-comp.d.ts +2 -2
  64. package/dist/lang/ast/view-elements/reference-view.js +1 -1
  65. package/dist/lang/ast/view-elements/view-refine.js +1 -1
  66. package/dist/lang/composite-source-utils.d.ts +2 -2
  67. package/dist/lang/composite-source-utils.js +6 -6
  68. package/dist/lang/malloy-to-ast.d.ts +3 -3
  69. package/dist/lang/malloy-to-ast.js +5 -5
  70. package/dist/lang/malloy-to-stable-query.d.ts +2 -2
  71. package/dist/lang/parse-malloy.js +6 -6
  72. package/dist/lang/parse-tree-walkers/model-annotation-walker.d.ts +2 -2
  73. package/dist/lang/parse-tree-walkers/model-annotation-walker.js +2 -2
  74. package/dist/lang/prettify/index.js +1 -1
  75. package/dist/lang/prettify/leaf.js +2 -2
  76. package/dist/lang/translate-response.d.ts +2 -2
  77. package/dist/model/malloy_types.d.ts +29 -25
  78. package/dist/model/persist_utils.js +3 -3
  79. package/dist/model/query_model_impl.js +1 -1
  80. package/dist/model/query_node.js +8 -8
  81. package/dist/model/query_query.js +13 -13
  82. package/dist/model/source_def_utils.js +4 -4
  83. package/dist/run_sql_options.d.ts +5 -11
  84. package/dist/to_stable.d.ts +2 -2
  85. package/dist/to_stable.js +7 -7
  86. package/dist/version.d.ts +1 -1
  87. package/dist/version.js +1 -1
  88. package/package.json +4 -4
  89. package/dist/annotation.d.ts +0 -96
  90. /package/dist/{taggable.js → api/foundation/taggable.js} +0 -0
  91. /package/dist/{prefix.d.ts → lang/annotation-prefix.d.ts} +0 -0
@@ -1,13 +1,13 @@
1
1
  import type { LogMessage } from '../../lang';
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';
2
+ import type { BuildID, CompiledQuery, ConstantExpr, DocumentLocation, BooleanFieldDef, JSONFieldDef, NumberFieldDef, StringFieldDef, FilterCondition, Given as InternalGiven, GivenID, GivenTypeDef, Query as InternalQuery, Pipeline, ModelDef, DocumentPosition as ModelDocumentPosition, NamedQueryDef, StructDef, TurtleDef, NativeUnsupportedFieldDef, ImportLocation, AnnotationsDef, 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';
6
6
  import { Tag } from '@malloydata/malloy-tag';
7
- import type { MalloyTagParse, TagParseSpec } from '../../annotation';
8
- import { Annotations } from '../../annotation';
7
+ import type { MalloyTagParse, TagParseSpec } from './annotation';
8
+ import { Annotations } from './annotation';
9
9
  import type * as Malloy from '@malloydata/malloy-interfaces';
10
- import type { Taggable } from '../../taggable';
10
+ import type { Taggable } from './taggable';
11
11
  declare abstract class Entity {
12
12
  private readonly _name;
13
13
  protected readonly _parent?: Explore;
@@ -90,6 +90,16 @@ export type PreparedResultJSON = {
90
90
  query: CompiledQuery;
91
91
  modelDef: ModelDef;
92
92
  };
93
+ /**
94
+ * Identifier-only enumeration of a model's top-level queries.
95
+ * Internal: returned by `Model.queries()`, not exported. Callers pair
96
+ * the names with `getPreparedQueryByName` and the indices `0..unnamed-1`
97
+ * with `getPreparedQueryByIndex` to load any one of them.
98
+ */
99
+ interface ModelQueries {
100
+ named: string[];
101
+ unnamed: number;
102
+ }
93
103
  export declare class Explore extends Entity implements Taggable {
94
104
  protected readonly _structDef: StructDef;
95
105
  protected readonly _parentExplore?: Explore;
@@ -100,7 +110,9 @@ export declare class Explore extends Entity implements Taggable {
100
110
  get source(): Explore | undefined;
101
111
  isIntrinsic(): boolean;
102
112
  isExploreField(): this is ExploreField;
113
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
103
114
  tagParse(spec?: TagParseSpec): MalloyTagParse;
115
+ /** @deprecated Use `.annotations.texts(route)`. */
104
116
  getTaglines(prefix?: RegExp): string[];
105
117
  get annotations(): Annotations;
106
118
  private parsedModelTag?;
@@ -141,7 +153,9 @@ export declare class AtomicField extends Entity implements Taggable {
141
153
  protected parent: Explore;
142
154
  constructor(fieldTypeDef: AtomicFieldDef, parent: Explore, source?: AtomicField);
143
155
  get type(): AtomicFieldType;
156
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
144
157
  tagParse(spec?: TagParseSpec): MalloyTagParse;
158
+ /** @deprecated Use `.annotations.texts(route)`. */
145
159
  getTaglines(prefix?: RegExp): string[];
146
160
  get annotations(): Annotations;
147
161
  isIntrinsic(): boolean;
@@ -198,20 +212,22 @@ export declare class StringField extends AtomicField {
198
212
  private fieldStringDef;
199
213
  constructor(fieldStringDef: StringFieldDef, parent: Explore, source?: AtomicField);
200
214
  }
201
- export declare class Query extends Entity {
215
+ export declare class Query extends Entity implements Taggable {
202
216
  protected turtleDef: TurtleDef;
203
217
  private sourceQuery?;
204
218
  constructor(turtleDef: TurtleDef, parent?: Explore, source?: Query);
205
219
  get source(): Query | undefined;
206
220
  isIntrinsic(): boolean;
207
221
  get location(): DocumentLocation | undefined;
208
- }
209
- export declare class QueryField extends Query implements Taggable {
210
- protected parent: Explore;
211
- constructor(turtleDef: TurtleDef, parent: Explore, source?: Query);
222
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
212
223
  tagParse(spec?: TagParseSpec): MalloyTagParse;
224
+ /** @deprecated Use `.annotations.texts(route)`. */
213
225
  getTaglines(prefix?: RegExp): string[];
214
226
  get annotations(): Annotations;
227
+ }
228
+ export declare class QueryField extends Query {
229
+ protected parent: Explore;
230
+ constructor(turtleDef: TurtleDef, parent: Explore, source?: Query);
215
231
  isQueryField(): this is QueryField;
216
232
  isExploreField(): this is ExploreField;
217
233
  isAtomicField(): this is AtomicField;
@@ -250,6 +266,40 @@ export interface RuntimeContext {
250
266
  * introspection-driven UIs don't render editors for them. */
251
267
  readonly finalizedGivens?: ReadonlySet<string>;
252
268
  }
269
+ export type ReferenceKind = 'field' | 'join' | 'explore' | 'query' | 'sqlBlock' | 'given';
270
+ /**
271
+ * A reference to a definition found at a position in a Malloy document —
272
+ * the Foundation view returned by {@link Model.referenceAt}. Carries the
273
+ * use-site location (where the reference appears), the definition's
274
+ * location (where to go for "go to definition"), the kind of entity
275
+ * referenced, and an `annotations` view over the definition's annotations.
276
+ *
277
+ * Construct via {@link Model.referenceAt}; direct construction is internal.
278
+ */
279
+ export declare class Reference {
280
+ private readonly _ref;
281
+ /** @internal */
282
+ constructor(_ref: DocumentReference);
283
+ /** The name as written at the use site (e.g. `"orders"`). */
284
+ get text(): string;
285
+ /** What kind of entity this reference points at. */
286
+ get kind(): ReferenceKind;
287
+ /** Where this reference appears in source. */
288
+ get location(): DocumentLocation;
289
+ /** Where the definition is. Omitted for synthetic references that have
290
+ * no source-level definition site. */
291
+ get definitionLocation(): DocumentLocation | undefined;
292
+ /** The referent's type as a string (e.g. `"string"` for a string field,
293
+ * `"source"` for a source). Free-form text from the IR; used by IDE
294
+ * display to render type hints. */
295
+ get definitionType(): string;
296
+ /** For given references only: the textual form of the given's default
297
+ * expression, if one was declared. Undefined for non-given references
298
+ * and for givens without a default. */
299
+ get defaultText(): string | undefined;
300
+ /** The definition's annotations, as a view. */
301
+ get annotations(): Annotations;
302
+ }
253
303
  export declare class Model implements Taggable {
254
304
  private modelDef;
255
305
  readonly problems: LogMessage[];
@@ -285,15 +335,23 @@ export declare class Model implements Taggable {
285
335
  * every given the model can accept.
286
336
  */
287
337
  get givens(): ReadonlyMap<string, Given>;
338
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
288
339
  tagParse(spec?: TagParseSpec): MalloyTagParse;
340
+ /** @deprecated Use `.annotations.texts(route)`. */
289
341
  getTaglines(prefix?: RegExp): string[];
290
342
  get annotations(): Annotations;
291
343
  /**
292
- * Retrieve a document reference for the token at the given position within
293
- * the document that produced this model.
344
+ * Retrieve a reference for the token at the given position within the
345
+ * document that produced this model.
294
346
  *
295
347
  * @param position A position within the document.
296
- * @return A `DocumentReference` at that position if one exists.
348
+ * @return A {@link Reference} at that position if one exists.
349
+ */
350
+ referenceAt(position: ModelDocumentPosition): Reference | undefined;
351
+ /**
352
+ * @deprecated Use {@link referenceAt} — returns a Foundation
353
+ * {@link Reference} view instead of the raw IR. This method returns
354
+ * the IR shape directly and will be removed in a future release.
297
355
  */
298
356
  getReference(position: ModelDocumentPosition): DocumentReference | undefined;
299
357
  /**
@@ -344,9 +402,18 @@ export declare class Model implements Taggable {
344
402
  */
345
403
  get explores(): Explore[];
346
404
  /**
347
- * Get an array of `NamedQueryDef`s contained in the model.
405
+ * Enumerate the model's top-level queries by identifier.
348
406
  *
349
- * @return An array of `NamedQueryDef`s contained in the model.
407
+ * Returns the names of named queries (`query: foo is ...`) and the count
408
+ * of unnamed `run:` statements. Pair with {@link getPreparedQueryByName}
409
+ * and {@link getPreparedQueryByIndex} to load any of them — those are the
410
+ * only path to the query itself; this getter exposes only identifiers,
411
+ * not IR.
412
+ */
413
+ queries(): ModelQueries;
414
+ /**
415
+ * @deprecated Leaks IR. Use {@link queries} for enumeration and
416
+ * {@link getPreparedQueryByName} to load a named query.
350
417
  */
351
418
  get namedQueries(): NamedQueryDef[];
352
419
  get exportedExplores(): Explore[];
@@ -414,16 +481,14 @@ export declare class PersistSource implements Taggable {
414
481
  */
415
482
  get _explore(): Explore;
416
483
  /**
417
- * The annotation on this source.
418
- */
419
- get annotation(): Annotation | undefined;
420
- /**
421
- * Parse the source's tags.
484
+ * @deprecated Hands out raw IR (`AnnotationsDef`). Use `.annotations`
485
+ * (returns the {@link Annotations} view). Slated for removal once
486
+ * external consumers migrate.
422
487
  */
488
+ get annotation(): AnnotationsDef | undefined;
489
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
423
490
  tagParse(spec?: TagParseSpec): MalloyTagParse;
424
- /**
425
- * Get annotation taglines matching an optional prefix.
426
- */
491
+ /** @deprecated Use `.annotations.texts(route)`. */
427
492
  getTaglines(prefix?: RegExp): string[];
428
493
  get annotations(): Annotations;
429
494
  /**
@@ -489,20 +554,35 @@ export declare class Given implements Taggable {
489
554
  /** `undefined` when no default — the caller must supply at run time. */
490
555
  get default(): ConstantExpr | undefined;
491
556
  get location(): DocumentLocation | undefined;
557
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
492
558
  tagParse(spec?: TagParseSpec): MalloyTagParse;
559
+ /** @deprecated Use `.annotations.texts(route)`. */
493
560
  getTaglines(prefix?: RegExp): string[];
494
561
  get annotations(): Annotations;
495
562
  }
496
- export declare class PreparedQuery implements Taggable {
563
+ /**
564
+ * Internal abstract base for Foundation wrappers around an IR `Pipeline`
565
+ * (an IR object that has a pipeline, annotations, and a source location).
566
+ * Owns the four `Taggable` accessors and a `location` getter, all reading
567
+ * from the wrapped IR. Not exported.
568
+ */
569
+ declare abstract class PipelineBase implements Taggable {
570
+ protected pipelineDef: Pipeline;
571
+ constructor(pipelineDef: Pipeline);
572
+ get annotations(): Annotations;
573
+ get location(): DocumentLocation | undefined;
574
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
575
+ tagParse(spec?: TagParseSpec): MalloyTagParse;
576
+ /** @deprecated Use `.annotations.texts(route)`. */
577
+ getTaglines(prefix?: RegExp): string[];
578
+ }
579
+ export declare class PreparedQuery extends PipelineBase {
497
580
  private _model;
498
581
  problems: LogMessage[];
499
582
  name?: string | undefined;
500
- _query: InternalQuery | NamedQueryDef;
501
583
  constructor(query: InternalQuery, _model: Model, problems: LogMessage[], name?: string | undefined);
584
+ get _query(): InternalQuery | NamedQueryDef;
502
585
  get _modelDef(): ModelDef;
503
- tagParse(spec?: TagParseSpec): MalloyTagParse;
504
- getTaglines(prefix?: RegExp): string[];
505
- get annotations(): Annotations;
506
586
  /**
507
587
  * Generate the SQL for this query.
508
588
  *
@@ -544,11 +624,24 @@ export declare class PreparedResult implements Taggable {
544
624
  protected inner: CompiledQuery;
545
625
  constructor(query: CompiledQuery, modelDef: ModelDef);
546
626
  static fromJson({ query, modelDef, }: PreparedResultJSON): PreparedResult;
627
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
547
628
  tagParse(spec?: TagParseSpec): MalloyTagParse;
629
+ /** @deprecated Use `.annotations.texts(route)`. */
548
630
  getTaglines(prefix?: RegExp): string[];
549
631
  get annotations(): Annotations;
550
- get annotation(): Annotation | undefined;
551
- get modelAnnotation(): Annotation | undefined;
632
+ /**
633
+ * @deprecated Hands out raw IR (`AnnotationsDef`). Use `.annotations`
634
+ * (returns the {@link Annotations} view) for read access. Internal
635
+ * code that needs the IR shape should read `._rawQuery.annotations`
636
+ * directly. Slated for removal once external consumers migrate.
637
+ */
638
+ get annotation(): AnnotationsDef | undefined;
639
+ /**
640
+ * @deprecated Hands out raw IR (`AnnotationsDef`). Internal code that
641
+ * needs the model-level IR shape should read `._modelDef.annotations`
642
+ * directly. Slated for removal once external consumers migrate.
643
+ */
644
+ get modelAnnotation(): AnnotationsDef | undefined;
552
645
  get modelTag(): Tag;
553
646
  /**
554
647
  * @return The name of the connection this query should be run against.
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: MIT
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
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;
7
+ exports.PreparedResult = exports.PreparedQuery = exports.Given = exports.PersistSource = exports.Model = exports.Reference = 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");
@@ -12,7 +12,7 @@ const persist_utils_1 = require("../../model/persist_utils");
12
12
  const source_def_utils_1 = require("../../model/source_def_utils");
13
13
  const given_binding_1 = require("../../model/given_binding");
14
14
  const malloy_tag_1 = require("@malloydata/malloy-tag");
15
- const annotation_1 = require("../../annotation");
15
+ const annotation_1 = require("./annotation");
16
16
  const to_stable_1 = require("../../to_stable");
17
17
  const util_1 = require("../util");
18
18
  const utils_2 = require("../../lang/utils");
@@ -148,17 +148,19 @@ class Explore extends Entity {
148
148
  isExploreField() {
149
149
  return false;
150
150
  }
151
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
151
152
  tagParse(spec) {
152
- return (0, annotation_1.annotationToTag)(this._structDef.annotation, spec);
153
+ return (0, annotation_1.annotationToTag)(this._structDef.annotations, spec);
153
154
  }
155
+ /** @deprecated Use `.annotations.texts(route)`. */
154
156
  getTaglines(prefix) {
155
- return (0, annotation_1.annotationToTaglines)(this._structDef.annotation, prefix);
157
+ return (0, annotation_1.annotationToTaglines)(this._structDef.annotations, prefix);
156
158
  }
157
159
  get annotations() {
158
- return new annotation_1.Annotations(this._structDef.annotation);
160
+ return new annotation_1.Annotations(this._structDef.annotations);
159
161
  }
160
162
  get modelTag() {
161
- this.parsedModelTag || (this.parsedModelTag = new annotation_1.Annotations(this._structDef.modelAnnotation).parseAsTag().tag);
163
+ this.parsedModelTag || (this.parsedModelTag = new annotation_1.Annotations(this._structDef.modelAnnotations).parseAsTag().tag);
162
164
  return this.parsedModelTag;
163
165
  }
164
166
  /**
@@ -462,14 +464,16 @@ class AtomicField extends Entity {
462
464
  }
463
465
  }
464
466
  }
467
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
465
468
  tagParse(spec) {
466
- return (0, annotation_1.annotationToTag)(this.fieldTypeDef.annotation, spec);
469
+ return (0, annotation_1.annotationToTag)(this.fieldTypeDef.annotations, spec);
467
470
  }
471
+ /** @deprecated Use `.annotations.texts(route)`. */
468
472
  getTaglines(prefix) {
469
- return (0, annotation_1.annotationToTaglines)(this.fieldTypeDef.annotation, prefix);
473
+ return (0, annotation_1.annotationToTaglines)(this.fieldTypeDef.annotations, prefix);
470
474
  }
471
475
  get annotations() {
472
- return new annotation_1.Annotations(this.fieldTypeDef.annotation);
476
+ return new annotation_1.Annotations(this.fieldTypeDef.annotations);
473
477
  }
474
478
  isIntrinsic() {
475
479
  return (0, model_1.fieldIsIntrinsic)(this.fieldTypeDef);
@@ -659,6 +663,17 @@ class Query extends Entity {
659
663
  get location() {
660
664
  return this.turtleDef.location;
661
665
  }
666
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
667
+ tagParse(spec) {
668
+ return (0, annotation_1.annotationToTag)(this.turtleDef.annotations, spec);
669
+ }
670
+ /** @deprecated Use `.annotations.texts(route)`. */
671
+ getTaglines(prefix) {
672
+ return (0, annotation_1.annotationToTaglines)(this.turtleDef.annotations, prefix);
673
+ }
674
+ get annotations() {
675
+ return new annotation_1.Annotations(this.turtleDef.annotations);
676
+ }
662
677
  }
663
678
  exports.Query = Query;
664
679
  class QueryField extends Query {
@@ -666,15 +681,6 @@ class QueryField extends Query {
666
681
  super(turtleDef, parent, source);
667
682
  this.parent = parent;
668
683
  }
669
- tagParse(spec) {
670
- return (0, annotation_1.annotationToTag)(this.turtleDef.annotation, spec);
671
- }
672
- getTaglines(prefix) {
673
- return (0, annotation_1.annotationToTaglines)(this.turtleDef.annotation, prefix);
674
- }
675
- get annotations() {
676
- return new annotation_1.Annotations(this.turtleDef.annotation);
677
- }
678
684
  isQueryField() {
679
685
  return true;
680
686
  }
@@ -726,10 +732,10 @@ class ExploreField extends Explore {
726
732
  return this.joinRelationship !== JoinRelationship.OneToOne;
727
733
  }
728
734
  tagParse(spec) {
729
- return (0, annotation_1.annotationToTag)(this._structDef.annotation, spec);
735
+ return (0, annotation_1.annotationToTag)(this._structDef.annotations, spec);
730
736
  }
731
737
  get annotations() {
732
- return new annotation_1.Annotations(this._structDef.annotation);
738
+ return new annotation_1.Annotations(this._structDef.annotations);
733
739
  }
734
740
  isQueryField() {
735
741
  return false;
@@ -755,6 +761,66 @@ class ExploreField extends Explore {
755
761
  }
756
762
  }
757
763
  exports.ExploreField = ExploreField;
764
+ const REFERENCE_KIND_BY_IR_TYPE = {
765
+ fieldReference: 'field',
766
+ joinReference: 'join',
767
+ exploreReference: 'explore',
768
+ queryReference: 'query',
769
+ sqlBlockReference: 'sqlBlock',
770
+ givenReference: 'given',
771
+ };
772
+ /**
773
+ * A reference to a definition found at a position in a Malloy document —
774
+ * the Foundation view returned by {@link Model.referenceAt}. Carries the
775
+ * use-site location (where the reference appears), the definition's
776
+ * location (where to go for "go to definition"), the kind of entity
777
+ * referenced, and an `annotations` view over the definition's annotations.
778
+ *
779
+ * Construct via {@link Model.referenceAt}; direct construction is internal.
780
+ */
781
+ class Reference {
782
+ /** @internal */
783
+ constructor(_ref) {
784
+ this._ref = _ref;
785
+ }
786
+ /** The name as written at the use site (e.g. `"orders"`). */
787
+ get text() {
788
+ return this._ref.text;
789
+ }
790
+ /** What kind of entity this reference points at. */
791
+ get kind() {
792
+ return REFERENCE_KIND_BY_IR_TYPE[this._ref.type];
793
+ }
794
+ /** Where this reference appears in source. */
795
+ get location() {
796
+ return this._ref.location;
797
+ }
798
+ /** Where the definition is. Omitted for synthetic references that have
799
+ * no source-level definition site. */
800
+ get definitionLocation() {
801
+ return this._ref.definition.location;
802
+ }
803
+ /** The referent's type as a string (e.g. `"string"` for a string field,
804
+ * `"source"` for a source). Free-form text from the IR; used by IDE
805
+ * display to render type hints. */
806
+ get definitionType() {
807
+ return this._ref.definition.type;
808
+ }
809
+ /** For given references only: the textual form of the given's default
810
+ * expression, if one was declared. Undefined for non-given references
811
+ * and for givens without a default. */
812
+ get defaultText() {
813
+ if (this._ref.type === 'givenReference') {
814
+ return this._ref.definition.defaultText;
815
+ }
816
+ return undefined;
817
+ }
818
+ /** The definition's annotations, as a view. */
819
+ get annotations() {
820
+ return new annotation_1.Annotations(this._ref.definition.annotations);
821
+ }
822
+ }
823
+ exports.Reference = Reference;
758
824
  class Model {
759
825
  constructor(modelDef, problems, fromSources, existingQueryModel,
760
826
  /**
@@ -813,21 +879,32 @@ class Model {
813
879
  }
814
880
  return out;
815
881
  }
882
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
816
883
  tagParse(spec) {
817
- return (0, annotation_1.annotationToTag)(this.modelDef.annotation, spec);
884
+ return (0, annotation_1.annotationToTag)(this.modelDef.annotations, spec);
818
885
  }
886
+ /** @deprecated Use `.annotations.texts(route)`. */
819
887
  getTaglines(prefix) {
820
- return (0, annotation_1.annotationToTaglines)(this.modelDef.annotation, prefix);
888
+ return (0, annotation_1.annotationToTaglines)(this.modelDef.annotations, prefix);
821
889
  }
822
890
  get annotations() {
823
- return new annotation_1.Annotations(this.modelDef.annotation);
891
+ return new annotation_1.Annotations(this.modelDef.annotations);
824
892
  }
825
893
  /**
826
- * Retrieve a document reference for the token at the given position within
827
- * the document that produced this model.
894
+ * Retrieve a reference for the token at the given position within the
895
+ * document that produced this model.
828
896
  *
829
897
  * @param position A position within the document.
830
- * @return A `DocumentReference` at that position if one exists.
898
+ * @return A {@link Reference} at that position if one exists.
899
+ */
900
+ referenceAt(position) {
901
+ const ref = this.references.find(position);
902
+ return ref ? new Reference(ref) : undefined;
903
+ }
904
+ /**
905
+ * @deprecated Use {@link referenceAt} — returns a Foundation
906
+ * {@link Reference} view instead of the raw IR. This method returns
907
+ * the IR shape directly and will be removed in a future release.
831
908
  */
832
909
  getReference(position) {
833
910
  return this.references.find(position);
@@ -914,9 +991,26 @@ class Model {
914
991
  .map(structDef => new Explore(structDef));
915
992
  }
916
993
  /**
917
- * Get an array of `NamedQueryDef`s contained in the model.
994
+ * Enumerate the model's top-level queries by identifier.
918
995
  *
919
- * @return An array of `NamedQueryDef`s contained in the model.
996
+ * Returns the names of named queries (`query: foo is ...`) and the count
997
+ * of unnamed `run:` statements. Pair with {@link getPreparedQueryByName}
998
+ * and {@link getPreparedQueryByIndex} to load any of them — those are the
999
+ * only path to the query itself; this getter exposes only identifiers,
1000
+ * not IR.
1001
+ */
1002
+ queries() {
1003
+ const named = [];
1004
+ for (const object of Object.values(this.modelDef.contents)) {
1005
+ if (object.type === 'query') {
1006
+ named.push(object.name);
1007
+ }
1008
+ }
1009
+ return { named, unnamed: this.modelDef.queryList.length };
1010
+ }
1011
+ /**
1012
+ * @deprecated Leaks IR. Use {@link queries} for enumeration and
1013
+ * {@link getPreparedQueryByName} to load a named query.
920
1014
  */
921
1015
  get namedQueries() {
922
1016
  const isNamedQueryDef = (object) => object.type === 'query';
@@ -1055,20 +1149,18 @@ class PersistSource {
1055
1149
  return this.explore;
1056
1150
  }
1057
1151
  /**
1058
- * The annotation on this source.
1152
+ * @deprecated Hands out raw IR (`AnnotationsDef`). Use `.annotations`
1153
+ * (returns the {@link Annotations} view). Slated for removal once
1154
+ * external consumers migrate.
1059
1155
  */
1060
1156
  get annotation() {
1061
- return this.persistableDef.annotation;
1157
+ return this.persistableDef.annotations;
1062
1158
  }
1063
- /**
1064
- * Parse the source's tags.
1065
- */
1159
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
1066
1160
  tagParse(spec) {
1067
1161
  return this.explore.tagParse(spec);
1068
1162
  }
1069
- /**
1070
- * Get annotation taglines matching an optional prefix.
1071
- */
1163
+ /** @deprecated Use `.annotations.texts(route)`. */
1072
1164
  getTaglines(prefix) {
1073
1165
  return this.explore.getTaglines(prefix);
1074
1166
  }
@@ -1171,36 +1263,57 @@ class Given {
1171
1263
  get location() {
1172
1264
  return this._internal.location;
1173
1265
  }
1266
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
1174
1267
  tagParse(spec) {
1175
- return (0, annotation_1.annotationToTag)(this._internal.annotation, spec);
1268
+ return (0, annotation_1.annotationToTag)(this._internal.annotations, spec);
1176
1269
  }
1270
+ /** @deprecated Use `.annotations.texts(route)`. */
1177
1271
  getTaglines(prefix) {
1178
- return (0, annotation_1.annotationToTaglines)(this._internal.annotation, prefix);
1272
+ return (0, annotation_1.annotationToTaglines)(this._internal.annotations, prefix);
1179
1273
  }
1180
1274
  get annotations() {
1181
- return new annotation_1.Annotations(this._internal.annotation);
1275
+ return new annotation_1.Annotations(this._internal.annotations);
1182
1276
  }
1183
1277
  }
1184
1278
  exports.Given = Given;
1185
- class PreparedQuery {
1279
+ /**
1280
+ * Internal abstract base for Foundation wrappers around an IR `Pipeline`
1281
+ * (an IR object that has a pipeline, annotations, and a source location).
1282
+ * Owns the four `Taggable` accessors and a `location` getter, all reading
1283
+ * from the wrapped IR. Not exported.
1284
+ */
1285
+ class PipelineBase {
1286
+ constructor(pipelineDef) {
1287
+ this.pipelineDef = pipelineDef;
1288
+ }
1289
+ get annotations() {
1290
+ return new annotation_1.Annotations(this.pipelineDef.annotations);
1291
+ }
1292
+ get location() {
1293
+ return this.pipelineDef.location;
1294
+ }
1295
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
1296
+ tagParse(spec) {
1297
+ return (0, annotation_1.annotationToTag)(this.pipelineDef.annotations, spec);
1298
+ }
1299
+ /** @deprecated Use `.annotations.texts(route)`. */
1300
+ getTaglines(prefix) {
1301
+ return (0, annotation_1.annotationToTaglines)(this.pipelineDef.annotations, prefix);
1302
+ }
1303
+ }
1304
+ class PreparedQuery extends PipelineBase {
1186
1305
  constructor(query, _model, problems, name) {
1306
+ super(query);
1187
1307
  this._model = _model;
1188
1308
  this.problems = problems;
1189
1309
  this.name = name;
1190
- this._query = query;
1310
+ }
1311
+ get _query() {
1312
+ return this.pipelineDef;
1191
1313
  }
1192
1314
  get _modelDef() {
1193
1315
  return this._model._modelDef;
1194
1316
  }
1195
- tagParse(spec) {
1196
- return (0, annotation_1.annotationToTag)(this._query.annotation, spec);
1197
- }
1198
- getTaglines(prefix) {
1199
- return (0, annotation_1.annotationToTaglines)(this._query.annotation, prefix);
1200
- }
1201
- get annotations() {
1202
- return new annotation_1.Annotations(this._query.annotation);
1203
- }
1204
1317
  /**
1205
1318
  * Generate the SQL for this query.
1206
1319
  *
@@ -1299,23 +1412,36 @@ class PreparedResult {
1299
1412
  }
1300
1413
  return new PreparedResult(query, modelDef);
1301
1414
  }
1415
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
1302
1416
  tagParse(spec) {
1303
- return (0, annotation_1.annotationToTag)(this.inner.annotation, spec);
1417
+ return (0, annotation_1.annotationToTag)(this.inner.annotations, spec);
1304
1418
  }
1419
+ /** @deprecated Use `.annotations.texts(route)`. */
1305
1420
  getTaglines(prefix) {
1306
- return (0, annotation_1.annotationToTaglines)(this.inner.annotation, prefix);
1421
+ return (0, annotation_1.annotationToTaglines)(this.inner.annotations, prefix);
1307
1422
  }
1308
1423
  get annotations() {
1309
- return new annotation_1.Annotations(this.inner.annotation);
1424
+ return new annotation_1.Annotations(this.inner.annotations);
1310
1425
  }
1426
+ /**
1427
+ * @deprecated Hands out raw IR (`AnnotationsDef`). Use `.annotations`
1428
+ * (returns the {@link Annotations} view) for read access. Internal
1429
+ * code that needs the IR shape should read `._rawQuery.annotations`
1430
+ * directly. Slated for removal once external consumers migrate.
1431
+ */
1311
1432
  get annotation() {
1312
- return this.inner.annotation;
1433
+ return this.inner.annotations;
1313
1434
  }
1435
+ /**
1436
+ * @deprecated Hands out raw IR (`AnnotationsDef`). Internal code that
1437
+ * needs the model-level IR shape should read `._modelDef.annotations`
1438
+ * directly. Slated for removal once external consumers migrate.
1439
+ */
1314
1440
  get modelAnnotation() {
1315
- return this.modelDef.annotation;
1441
+ return this.modelDef.annotations;
1316
1442
  }
1317
1443
  get modelTag() {
1318
- return new annotation_1.Annotations(this.modelDef.annotation).parseAsTag().tag;
1444
+ return new annotation_1.Annotations(this.modelDef.annotations).parseAsTag().tag;
1319
1445
  }
1320
1446
  /**
1321
1447
  * @return The name of the connection this query should be run against.
@@ -1346,7 +1472,7 @@ class PreparedResult {
1346
1472
  const explore = this.inner.structs[this.inner.structs.length - 1];
1347
1473
  const namedExplore = {
1348
1474
  ...explore,
1349
- annotation: this.inner.annotation,
1475
+ annotations: this.inner.annotations,
1350
1476
  name: this.inner.queryName || explore.name,
1351
1477
  };
1352
1478
  try {
@@ -1388,7 +1514,7 @@ class PreparedResult {
1388
1514
  const structs = this.inner.structs;
1389
1515
  const struct = structs[structs.length - 1];
1390
1516
  const schema = { fields: (0, to_stable_1.convertFieldInfos)(struct, struct.fields) };
1391
- const annotations = (0, to_stable_1.toStableAnnotations)(this.inner.annotation);
1517
+ const annotations = (0, to_stable_1.toStableAnnotations)(this.inner.annotations);
1392
1518
  const metadataAnnot = struct.resultMetadata
1393
1519
  ? (0, to_stable_1.getResultStructMetadataAnnotation)(struct, struct.resultMetadata)
1394
1520
  : undefined;
@@ -1417,7 +1543,7 @@ class PreparedResult {
1417
1543
  .set(['query_name'], this.inner.queryName || struct.name)
1418
1544
  .toString(),
1419
1545
  });
1420
- const modelAnnotations = (0, to_stable_1.toStableAnnotations)(this.modelDef.annotation);
1546
+ const modelAnnotations = (0, to_stable_1.toStableAnnotations)(this.modelDef.annotations);
1421
1547
  return {
1422
1548
  schema,
1423
1549
  data,