@malloydata/malloy 0.0.399 → 0.0.400

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 +80 -17
  8. package/dist/api/foundation/core.js +135 -43
  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 +28 -24
  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 +6 -4
  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
@@ -0,0 +1,36 @@
1
+ import type * as Malloy from '@malloydata/malloy-interfaces';
2
+ import type { Tag } from '@malloydata/malloy-tag';
3
+ /**
4
+ * The route a stable {@link Malloy.Annotation} belongs to (`''` for MOTLY
5
+ * tags, `!` for compiler flags, `myApp` for an app's claimed route, etc.).
6
+ * Returns `undefined` if the annotation's prefix is malformed.
7
+ */
8
+ export declare function routeOf(a: Malloy.Annotation): string | undefined;
9
+ /**
10
+ * The payload of a stable {@link Malloy.Annotation} — the substring after
11
+ * the prefix and separator (`'name=foo'` for `'#(filter) name=foo'`,
12
+ * `'tag\n'` for `'# tag\n'` — the lexer keeps the trailing newline).
13
+ * Returns the empty string for an annotation that has no content.
14
+ */
15
+ export declare function payloadOf(a: Malloy.Annotation): string;
16
+ /**
17
+ * Filter `annotations` to just those on `route`, in input order.
18
+ *
19
+ * Annotations with `malformed-route` prefixes are excluded (no clean route
20
+ * to resolve to). `reserved-route` annotations *are* included — their
21
+ * prefix parses to a real route and the user got a compile-time warning,
22
+ * but the data is what it is.
23
+ *
24
+ * Route filtering is level-blind: `# tag` and `## tag` both resolve to
25
+ * route `''`. Producers separate object-level from model-level annotations
26
+ * into different arrays; consumers pass the array carrying the right level.
27
+ */
28
+ export declare function annotationsForRoute(annotations: Malloy.Annotation[] | undefined, route: string): Malloy.Annotation[];
29
+ /**
30
+ * Parse a stable `Malloy.Annotation[]`'s `route` annotations as MOTLY into
31
+ * one Tag. The stable counterpart to `Annotations.parseAsTag` — consumes
32
+ * the flat wire shape, no source offsets. Selection follows
33
+ * {@link annotationsForRoute} semantics (level-blind, malformed-route
34
+ * excluded, reserved-route included).
35
+ */
36
+ export declare function tagFromAnnotations(annotations: Malloy.Annotation[] | undefined, route: string): Tag;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Contributors to the Malloy project
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.routeOf = routeOf;
8
+ exports.payloadOf = payloadOf;
9
+ exports.annotationsForRoute = annotationsForRoute;
10
+ exports.tagFromAnnotations = tagFromAnnotations;
11
+ const malloy_tag_1 = require("@malloydata/malloy-tag");
12
+ const annotation_prefix_1 = require("../lang/annotation-prefix");
13
+ // ============================================================================
14
+ // Helpers for the stable (Thrift-derived) wire shape: `Malloy.Annotation[]`.
15
+ //
16
+ // API consumers (render, query-builder, downstream SDKs that target the
17
+ // stable interface) read annotation arrays off projected stable types
18
+ // (`Malloy.Result`, `Malloy.FieldInfo`, etc.) and want low-ceremony reads —
19
+ // no source offsets, no view class. These helpers consume that array shape
20
+ // directly, using the shared `parsePrefix` for route resolution.
21
+ // ============================================================================
22
+ /**
23
+ * The route a stable {@link Malloy.Annotation} belongs to (`''` for MOTLY
24
+ * tags, `!` for compiler flags, `myApp` for an app's claimed route, etc.).
25
+ * Returns `undefined` if the annotation's prefix is malformed.
26
+ */
27
+ function routeOf(a) {
28
+ const parsed = (0, annotation_prefix_1.parsePrefix)(a.value);
29
+ if (parsed.malformation === 'malformed-route')
30
+ return undefined;
31
+ return parsed.route;
32
+ }
33
+ /**
34
+ * The payload of a stable {@link Malloy.Annotation} — the substring after
35
+ * the prefix and separator (`'name=foo'` for `'#(filter) name=foo'`,
36
+ * `'tag\n'` for `'# tag\n'` — the lexer keeps the trailing newline).
37
+ * Returns the empty string for an annotation that has no content.
38
+ */
39
+ function payloadOf(a) {
40
+ return a.value.slice((0, annotation_prefix_1.parsePrefix)(a.value).contentIndex);
41
+ }
42
+ /**
43
+ * Filter `annotations` to just those on `route`, in input order.
44
+ *
45
+ * Annotations with `malformed-route` prefixes are excluded (no clean route
46
+ * to resolve to). `reserved-route` annotations *are* included — their
47
+ * prefix parses to a real route and the user got a compile-time warning,
48
+ * but the data is what it is.
49
+ *
50
+ * Route filtering is level-blind: `# tag` and `## tag` both resolve to
51
+ * route `''`. Producers separate object-level from model-level annotations
52
+ * into different arrays; consumers pass the array carrying the right level.
53
+ */
54
+ function annotationsForRoute(annotations, route) {
55
+ if (!annotations)
56
+ return [];
57
+ return annotations.filter(a => {
58
+ const parsed = (0, annotation_prefix_1.parsePrefix)(a.value);
59
+ return parsed.route === route && parsed.malformation !== 'malformed-route';
60
+ });
61
+ }
62
+ /**
63
+ * Parse a stable `Malloy.Annotation[]`'s `route` annotations as MOTLY into
64
+ * one Tag. The stable counterpart to `Annotations.parseAsTag` — consumes
65
+ * the flat wire shape, no source offsets. Selection follows
66
+ * {@link annotationsForRoute} semantics (level-blind, malformed-route
67
+ * excluded, reserved-route included).
68
+ */
69
+ function tagFromAnnotations(annotations, route) {
70
+ const session = new malloy_tag_1.TagParser();
71
+ for (const a of annotationsForRoute(annotations, route)) {
72
+ session.parseAnnotation(a.value);
73
+ }
74
+ return session.finish();
75
+ }
76
+ //# sourceMappingURL=annotation-utils.js.map
package/dist/api/core.js CHANGED
@@ -138,7 +138,7 @@ function convertDimension(field) {
138
138
  const typeDef = typeDefFromField(field.type);
139
139
  return {
140
140
  ...(0, model_1.mkFieldDef)(typeDef, field.name),
141
- annotation: field.annotations && field.annotations.length
141
+ annotations: field.annotations && field.annotations.length
142
142
  ? {
143
143
  notes: (_a = field.annotations) === null || _a === void 0 ? void 0 : _a.map(a => ({
144
144
  text: a.value,
@@ -505,7 +505,7 @@ function statedCompileQuery(state) {
505
505
  defaultRowLimit: state.defaultRowLimit,
506
506
  });
507
507
  timer.contribute([sqlTimer.stop()]);
508
- const modelAnnotations = (0, to_stable_1.toStableAnnotations)(result.modelDef.annotation);
508
+ const modelAnnotations = (0, to_stable_1.toStableAnnotations)(result.modelDef.annotations);
509
509
  let source;
510
510
  if (query.compositeResolvedSourceDef) {
511
511
  source = query.compositeResolvedSourceDef;
@@ -519,7 +519,7 @@ function statedCompileQuery(state) {
519
519
  source = (0, model_1.safeRecordGet)(result.modelDef.contents, query.structRef);
520
520
  }
521
521
  }
522
- const sourceAnnotations = (0, to_stable_1.toStableAnnotations)(source.annotation);
522
+ const sourceAnnotations = (0, to_stable_1.toStableAnnotations)(source.annotations);
523
523
  const sourceMetadataTag = malloy_tag_1.Tag.withPrefix('#(malloy) ');
524
524
  sourceMetadataTag.set(['source', 'name'], translatedQuery.sourceExplore);
525
525
  const sourceArguments = (_b = translatedQuery.sourceArguments) !== null && _b !== void 0 ? _b : ((0, model_1.isSourceDef)(source) ? source.arguments : undefined);
@@ -0,0 +1,115 @@
1
+ import type { Tag } from '@malloydata/malloy-tag';
2
+ import type { AnnotationsDef, Note, DocumentLocation } from '../../model';
3
+ import type { LogMessage } from '../../lang';
4
+ /**
5
+ * @deprecated Argument shape for the deprecated RegExp form of
6
+ * {@link annotationToTag}. The RegExp form cannot see multi-line
7
+ * annotations (`#|`…`|#`). Pass a route string to `annotationToTag`
8
+ * instead, or use the {@link Annotations} view on a tagged entity.
9
+ */
10
+ export interface TagParseSpec {
11
+ prefix?: RegExp;
12
+ }
13
+ /**
14
+ * One annotation, returned by {@link Annotations.forRoute} — wraps an IR
15
+ * note with its parsed route and prefix/content split. Carries the offsets
16
+ * a caller needs to parse the payload (`.content`) with their own parser
17
+ * and map parser errors back to source positions.
18
+ *
19
+ * Foundation-owned: not derived from the IR `Note` type, so IR can evolve
20
+ * fields without breaking this public shape. Direct construction is
21
+ * internal; reach instances via `Annotations.forRoute`.
22
+ */
23
+ export declare class RoutedNote {
24
+ private readonly _note;
25
+ readonly route: string;
26
+ readonly contentIndex: number;
27
+ /** @internal */
28
+ constructor(_note: Note, route: string, contentIndex: number);
29
+ /** The annotation exactly as written — prefix + content. */
30
+ get text(): string;
31
+ /** Where this note starts in source. */
32
+ get at(): DocumentLocation;
33
+ /**
34
+ * Multi-line annotations only (`#|`…`|#`). Number of leading-whitespace
35
+ * characters stripped from each body line during the dedent pass (Python
36
+ * `textwrap.dedent` semantics — longest common prefix across non-blank
37
+ * body lines). Omitted for single-line annotations and for multi-line
38
+ * annotations with no common indent.
39
+ *
40
+ * To map your parser's column numbers back to source:
41
+ * `source_col = indentStripped + parser_col` for body lines; first-line
42
+ * columns map straight through, offset by {@link contentIndex}.
43
+ */
44
+ get indentStripped(): number | undefined;
45
+ /** The payload — `text.slice(contentIndex)`. The string to feed to
46
+ * your own parser. */
47
+ get content(): string;
48
+ }
49
+ /**
50
+ * Collect annotations, using the shared prefix parser.
51
+ * - no `route`: every annotation, each carrying its own `route` (the only
52
+ * way to reach one whose prefix is malformed).
53
+ * - a `route`: only annotations on that route; malformed prefixes excluded.
54
+ */
55
+ export declare function collectAnnotations(annote: AnnotationsDef | undefined, route?: string): RoutedNote[];
56
+ /**
57
+ * @deprecated The RegExp form cannot see multi-line annotations
58
+ * (`#|`…`|#`). Use `new Annotations(annote).texts(route)` instead, or the
59
+ * {@link Annotations} view on a tagged entity (`entity.annotations.texts(route)`).
60
+ */
61
+ export declare function annotationToTaglines(annote: AnnotationsDef | undefined, prefix?: RegExp): string[];
62
+ export interface MalloyTagParse {
63
+ tag: Tag;
64
+ log: LogMessage[];
65
+ }
66
+ /** Parse the annotations on `route` (default `''`, the MOTLY tag route) as MOTLY. */
67
+ export declare function annotationToTag(annote: AnnotationsDef | undefined, route?: string): MalloyTagParse;
68
+ /**
69
+ * @deprecated The RegExp `prefix` form cannot see multi-line annotations
70
+ * (`#|`…`|#`) and cannot report content offsets for error mapping. Pass a
71
+ * route string (the other overload), or use {@link Annotations.parseAsTag}
72
+ * on a tagged entity.
73
+ */
74
+ export declare function annotationToTag(annote: AnnotationsDef | undefined, spec?: TagParseSpec): MalloyTagParse;
75
+ /**
76
+ * The route-aware annotation API for a tagged entity.
77
+ *
78
+ * An annotation has a *prefix* (everything from `#`/`##` up to the first
79
+ * whitespace) that resolves to a *route* — a namespace key. Built-in routes:
80
+ * `''` (MOTLY tags, the human default), `!` (compiler flags), `@` (persistence
81
+ * directives), `"` (doc-string markdown). Apps stake their own routes with
82
+ * brackets: `#(myApp) ...` is route `myApp`. The grammar (forms, bracket
83
+ * pairs, malformation warnings) lives in `lang/prefix.ts`.
84
+ *
85
+ * All annotation reading lives here, written once; each tagged class only has
86
+ * to say *where* its annotation is (by handing it to the constructor). Unlike
87
+ * the deprecated RegExp readers (`tagParse`/`getTaglines`), this sees multi-
88
+ * line annotations.
89
+ */
90
+ export declare class Annotations {
91
+ private readonly annote;
92
+ constructor(annote: AnnotationsDef | undefined);
93
+ /**
94
+ * Raw annotation text strings (prefix + content) — all routes if `route` is
95
+ * omitted, just that route's otherwise. The route-based successor to the
96
+ * deprecated `getTaglines`. For source-mapped offsets (when parsing the
97
+ * payload with your own parser), see {@link forRoute}.
98
+ */
99
+ texts(route?: string): string[];
100
+ /**
101
+ * Your route's notes as {@link RoutedNote}s — for callers that parse the
102
+ * payload with their own parser (instead of MOTLY). Read `.content` to
103
+ * feed your parser, and `.at` + `.indentStripped` to map your parser's
104
+ * errors back to source.
105
+ *
106
+ * `malformed-route` annotations are excluded (no clean route to resolve
107
+ * to). `reserved-route` annotations are included — they parse to a real
108
+ * route and the user got a compile-time warning. Route filtering is
109
+ * level-blind (`#` and `##` both go to route `''`); the entity hands
110
+ * you the annotations that apply at its level.
111
+ */
112
+ forRoute(route: string): RoutedNote[];
113
+ /** Parse a route's annotations as a MOTLY tag. Default `''` is the tag route. */
114
+ parseAsTag(route?: string): MalloyTagParse;
115
+ }
@@ -1,11 +1,61 @@
1
1
  "use strict";
2
+ /*
3
+ * Copyright Contributors to the Malloy project
4
+ * SPDX-License-Identifier: MIT
5
+ */
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Annotations = void 0;
7
+ exports.Annotations = exports.RoutedNote = void 0;
4
8
  exports.collectAnnotations = collectAnnotations;
5
9
  exports.annotationToTaglines = annotationToTaglines;
6
10
  exports.annotationToTag = annotationToTag;
7
11
  const malloy_tag_1 = require("@malloydata/malloy-tag");
8
- const prefix_1 = require("./prefix");
12
+ const annotation_prefix_1 = require("../../lang/annotation-prefix");
13
+ /**
14
+ * One annotation, returned by {@link Annotations.forRoute} — wraps an IR
15
+ * note with its parsed route and prefix/content split. Carries the offsets
16
+ * a caller needs to parse the payload (`.content`) with their own parser
17
+ * and map parser errors back to source positions.
18
+ *
19
+ * Foundation-owned: not derived from the IR `Note` type, so IR can evolve
20
+ * fields without breaking this public shape. Direct construction is
21
+ * internal; reach instances via `Annotations.forRoute`.
22
+ */
23
+ class RoutedNote {
24
+ /** @internal */
25
+ constructor(_note, route, contentIndex) {
26
+ this._note = _note;
27
+ this.route = route;
28
+ this.contentIndex = contentIndex;
29
+ }
30
+ /** The annotation exactly as written — prefix + content. */
31
+ get text() {
32
+ return this._note.text;
33
+ }
34
+ /** Where this note starts in source. */
35
+ get at() {
36
+ return this._note.at;
37
+ }
38
+ /**
39
+ * Multi-line annotations only (`#|`…`|#`). Number of leading-whitespace
40
+ * characters stripped from each body line during the dedent pass (Python
41
+ * `textwrap.dedent` semantics — longest common prefix across non-blank
42
+ * body lines). Omitted for single-line annotations and for multi-line
43
+ * annotations with no common indent.
44
+ *
45
+ * To map your parser's column numbers back to source:
46
+ * `source_col = indentStripped + parser_col` for body lines; first-line
47
+ * columns map straight through, offset by {@link contentIndex}.
48
+ */
49
+ get indentStripped() {
50
+ return this._note.indentStripped;
51
+ }
52
+ /** The payload — `text.slice(contentIndex)`. The string to feed to
53
+ * your own parser. */
54
+ get content() {
55
+ return this._note.text.slice(this.contentIndex);
56
+ }
57
+ }
58
+ exports.RoutedNote = RoutedNote;
9
59
  /** Every Note of an annotation, inherited first, in document order. */
10
60
  function* notesInOrder(annote) {
11
61
  if (annote.inherits)
@@ -15,35 +65,28 @@ function* notesInOrder(annote) {
15
65
  if (annote.notes)
16
66
  yield* annote.notes;
17
67
  }
68
+ /**
69
+ * Collect annotations, using the shared prefix parser.
70
+ * - no `route`: every annotation, each carrying its own `route` (the only
71
+ * way to reach one whose prefix is malformed).
72
+ * - a `route`: only annotations on that route; malformed prefixes excluded.
73
+ */
18
74
  function collectAnnotations(annote, route) {
19
- if (route === undefined) {
20
- return Array.from(notesInOrder(annote !== null && annote !== void 0 ? annote : {}), note => {
21
- const { route: noteRoute, contentIndex } = (0, prefix_1.parsePrefix)(note.text);
22
- return {
23
- rawText: note.text,
24
- contentIndex,
25
- at: note.at,
26
- route: noteRoute,
27
- indentStripped: note.indentStripped,
28
- };
29
- });
30
- }
31
75
  const matching = [];
32
76
  for (const note of notesInOrder(annote !== null && annote !== void 0 ? annote : {})) {
33
- const parsed = (0, prefix_1.parsePrefix)(note.text);
34
- if (parsed.route === route && parsed.malformation !== 'malformed-route') {
35
- matching.push({
36
- rawText: note.text,
37
- contentIndex: parsed.contentIndex,
38
- at: note.at,
39
- indentStripped: note.indentStripped,
40
- });
77
+ const parsed = (0, annotation_prefix_1.parsePrefix)(note.text);
78
+ if (route === undefined) {
79
+ matching.push(new RoutedNote(note, parsed.route, parsed.contentIndex));
80
+ }
81
+ else if (parsed.route === route &&
82
+ parsed.malformation !== 'malformed-route') {
83
+ matching.push(new RoutedNote(note, parsed.route, parsed.contentIndex));
41
84
  }
42
85
  }
43
86
  return matching;
44
87
  }
45
88
  /**
46
- * Collect all matching Notes from an Annotation, walking the inherits
89
+ * Collect all matching Notes from an AnnotationsDef, walking the inherits
47
90
  * chain. Returns notes in inheritance order (inherited first).
48
91
  *
49
92
  * @deprecated RegExp prefix matching; use {@link collectAnnotations} with a route.
@@ -53,9 +96,9 @@ function collectNotes(annote, prefix) {
53
96
  return prefix ? notes.filter(note => note.text.match(prefix)) : notes;
54
97
  }
55
98
  /**
56
- * @deprecated The RegExp form cannot see block annotations (`#|`…`|#`). Use
57
- * `new Annotations(annote).texts(route)` instead, or the {@link Annotations}
58
- * view on a tagged entity (`entity.annotations.texts(route)`).
99
+ * @deprecated The RegExp form cannot see multi-line annotations
100
+ * (`#|`…`|#`). Use `new Annotations(annote).texts(route)` instead, or the
101
+ * {@link Annotations} view on a tagged entity (`entity.annotations.texts(route)`).
59
102
  */
60
103
  function annotationToTaglines(annote, prefix) {
61
104
  return collectNotes(annote || {}, prefix).map(n => n.text);
@@ -90,7 +133,7 @@ function annotationToTag(annote, arg) {
90
133
  }
91
134
  const matched = collectAnnotations(annote, arg !== null && arg !== void 0 ? arg : '');
92
135
  return parseTaglines(matched.map(a => ({
93
- text: a.rawText,
136
+ text: a.text,
94
137
  at: a.at,
95
138
  indentStripped: a.indentStripped,
96
139
  })));
@@ -103,12 +146,12 @@ function annotationToTag(annote, arg) {
103
146
  * `''` (MOTLY tags, the human default), `!` (compiler flags), `@` (persistence
104
147
  * directives), `"` (doc-string markdown). Apps stake their own routes with
105
148
  * brackets: `#(myApp) ...` is route `myApp`. The grammar (forms, bracket
106
- * pairs, malformation warnings) lives in `./prefix.ts`.
149
+ * pairs, malformation warnings) lives in `lang/prefix.ts`.
107
150
  *
108
151
  * All annotation reading lives here, written once; each tagged class only has
109
152
  * to say *where* its annotation is (by handing it to the constructor). Unlike
110
- * the deprecated RegExp readers (`tagParse`/`getTaglines`), this sees block
111
- * annotations.
153
+ * the deprecated RegExp readers (`tagParse`/`getTaglines`), this sees multi-
154
+ * line annotations.
112
155
  */
113
156
  class Annotations {
114
157
  constructor(annote) {
@@ -117,21 +160,23 @@ class Annotations {
117
160
  /**
118
161
  * Raw annotation text strings (prefix + content) — all routes if `route` is
119
162
  * omitted, just that route's otherwise. The route-based successor to the
120
- * deprecated `getTaglines`. For source-mapped offsets (bring-your-own
121
- * parsers), see {@link forRoute}.
163
+ * deprecated `getTaglines`. For source-mapped offsets (when parsing the
164
+ * payload with your own parser), see {@link forRoute}.
122
165
  */
123
166
  texts(route) {
124
- const items = route === undefined
125
- ? collectAnnotations(this.annote)
126
- : collectAnnotations(this.annote, route);
127
- return items.map(a => a.rawText);
167
+ return collectAnnotations(this.annote, route).map(a => a.text);
128
168
  }
129
169
  /**
130
- * Your route's annotations as objects (`rawText` + `contentIndex` + `at`)
131
- * the bring-your-own-parser door. A non-MOTLY app (e.g. JSON on its own
132
- * route) reads these to slice the content (`rawText.slice(contentIndex)`)
133
- * itself and map its parser's errors back to source via `at`. Malformed-prefix
134
- * annotations are excluded.
170
+ * Your route's notes as {@link RoutedNote}s for callers that parse the
171
+ * payload with their own parser (instead of MOTLY). Read `.content` to
172
+ * feed your parser, and `.at` + `.indentStripped` to map your parser's
173
+ * errors back to source.
174
+ *
175
+ * `malformed-route` annotations are excluded (no clean route to resolve
176
+ * to). `reserved-route` annotations are included — they parse to a real
177
+ * route and the user got a compile-time warning. Route filtering is
178
+ * level-blind (`#` and `##` both go to route `''`); the entity hands
179
+ * you the annotations that apply at its level.
135
180
  */
136
181
  forRoute(route) {
137
182
  return collectAnnotations(this.annote, route);
@@ -169,7 +214,7 @@ function mapMalloyError(e, note) {
169
214
  /** Length of the annotation prefix per malloy-tag's `stripPrefix`: index of
170
215
  * the first whitespace, or 0 if none. */
171
216
  function prefixLength(text) {
172
- const { contentIndex } = (0, prefix_1.parsePrefix)(text);
217
+ const { contentIndex } = (0, annotation_prefix_1.parsePrefix)(text);
173
218
  return contentIndex === text.length ? 0 : contentIndex - 1;
174
219
  }
175
220
  //# sourceMappingURL=annotation.js.map
@@ -250,7 +250,7 @@ class Malloy {
250
250
  }
251
251
  }
252
252
  }
253
- const { modelAnnotation } = translator.modelAnnotation(model === null || model === void 0 ? void 0 : model._modelDef);
253
+ const { modelAnnotations } = translator.modelAnnotation(model === null || model === void 0 ? void 0 : model._modelDef);
254
254
  if (result.tables) {
255
255
  // collect tables by connection name since there may be multiple connections
256
256
  const tablesByConnection = new Map();
@@ -273,7 +273,7 @@ class Malloy {
273
273
  // the translator runs into an infinite loop fetching tables.
274
274
  const { schemas: tables, errors } = await Malloy.safelyFetchTableSchema(connection, tablePathByKey, {
275
275
  refreshTimestamp,
276
- modelAnnotation,
276
+ modelAnnotations,
277
277
  });
278
278
  translator.update({ tables, errors: { tables: errors } });
279
279
  }
@@ -318,7 +318,7 @@ class Malloy {
318
318
  const conn = await connections.lookupConnection(connectionName);
319
319
  const resolved = await conn.fetchSchemaForSQLStruct(toCompile, {
320
320
  refreshTimestamp,
321
- modelAnnotation,
321
+ modelAnnotations,
322
322
  });
323
323
  if (resolved.error) {
324
324
  translator.update({
@@ -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, 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;
@@ -100,7 +100,9 @@ export declare class Explore extends Entity implements Taggable {
100
100
  get source(): Explore | undefined;
101
101
  isIntrinsic(): boolean;
102
102
  isExploreField(): this is ExploreField;
103
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
103
104
  tagParse(spec?: TagParseSpec): MalloyTagParse;
105
+ /** @deprecated Use `.annotations.texts(route)`. */
104
106
  getTaglines(prefix?: RegExp): string[];
105
107
  get annotations(): Annotations;
106
108
  private parsedModelTag?;
@@ -141,7 +143,9 @@ export declare class AtomicField extends Entity implements Taggable {
141
143
  protected parent: Explore;
142
144
  constructor(fieldTypeDef: AtomicFieldDef, parent: Explore, source?: AtomicField);
143
145
  get type(): AtomicFieldType;
146
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
144
147
  tagParse(spec?: TagParseSpec): MalloyTagParse;
148
+ /** @deprecated Use `.annotations.texts(route)`. */
145
149
  getTaglines(prefix?: RegExp): string[];
146
150
  get annotations(): Annotations;
147
151
  isIntrinsic(): boolean;
@@ -209,7 +213,9 @@ export declare class Query extends Entity {
209
213
  export declare class QueryField extends Query implements Taggable {
210
214
  protected parent: Explore;
211
215
  constructor(turtleDef: TurtleDef, parent: Explore, source?: Query);
216
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
212
217
  tagParse(spec?: TagParseSpec): MalloyTagParse;
218
+ /** @deprecated Use `.annotations.texts(route)`. */
213
219
  getTaglines(prefix?: RegExp): string[];
214
220
  get annotations(): Annotations;
215
221
  isQueryField(): this is QueryField;
@@ -250,6 +256,40 @@ export interface RuntimeContext {
250
256
  * introspection-driven UIs don't render editors for them. */
251
257
  readonly finalizedGivens?: ReadonlySet<string>;
252
258
  }
259
+ export type ReferenceKind = 'field' | 'join' | 'explore' | 'query' | 'sqlBlock' | 'given';
260
+ /**
261
+ * A reference to a definition found at a position in a Malloy document —
262
+ * the Foundation view returned by {@link Model.referenceAt}. Carries the
263
+ * use-site location (where the reference appears), the definition's
264
+ * location (where to go for "go to definition"), the kind of entity
265
+ * referenced, and an `annotations` view over the definition's annotations.
266
+ *
267
+ * Construct via {@link Model.referenceAt}; direct construction is internal.
268
+ */
269
+ export declare class Reference {
270
+ private readonly _ref;
271
+ /** @internal */
272
+ constructor(_ref: DocumentReference);
273
+ /** The name as written at the use site (e.g. `"orders"`). */
274
+ get text(): string;
275
+ /** What kind of entity this reference points at. */
276
+ get kind(): ReferenceKind;
277
+ /** Where this reference appears in source. */
278
+ get location(): DocumentLocation;
279
+ /** Where the definition is. Omitted for synthetic references that have
280
+ * no source-level definition site. */
281
+ get definitionLocation(): DocumentLocation | undefined;
282
+ /** The referent's type as a string (e.g. `"string"` for a string field,
283
+ * `"source"` for a source). Free-form text from the IR; used by IDE
284
+ * display to render type hints. */
285
+ get definitionType(): string;
286
+ /** For given references only: the textual form of the given's default
287
+ * expression, if one was declared. Undefined for non-given references
288
+ * and for givens without a default. */
289
+ get defaultText(): string | undefined;
290
+ /** The definition's annotations, as a view. */
291
+ get annotations(): Annotations;
292
+ }
253
293
  export declare class Model implements Taggable {
254
294
  private modelDef;
255
295
  readonly problems: LogMessage[];
@@ -285,15 +325,23 @@ export declare class Model implements Taggable {
285
325
  * every given the model can accept.
286
326
  */
287
327
  get givens(): ReadonlyMap<string, Given>;
328
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
288
329
  tagParse(spec?: TagParseSpec): MalloyTagParse;
330
+ /** @deprecated Use `.annotations.texts(route)`. */
289
331
  getTaglines(prefix?: RegExp): string[];
290
332
  get annotations(): Annotations;
291
333
  /**
292
- * Retrieve a document reference for the token at the given position within
293
- * the document that produced this model.
334
+ * Retrieve a reference for the token at the given position within the
335
+ * document that produced this model.
294
336
  *
295
337
  * @param position A position within the document.
296
- * @return A `DocumentReference` at that position if one exists.
338
+ * @return A {@link Reference} at that position if one exists.
339
+ */
340
+ referenceAt(position: ModelDocumentPosition): Reference | undefined;
341
+ /**
342
+ * @deprecated Use {@link referenceAt} — returns a Foundation
343
+ * {@link Reference} view instead of the raw IR. This method returns
344
+ * the IR shape directly and will be removed in a future release.
297
345
  */
298
346
  getReference(position: ModelDocumentPosition): DocumentReference | undefined;
299
347
  /**
@@ -414,16 +462,14 @@ export declare class PersistSource implements Taggable {
414
462
  */
415
463
  get _explore(): Explore;
416
464
  /**
417
- * The annotation on this source.
418
- */
419
- get annotation(): Annotation | undefined;
420
- /**
421
- * Parse the source's tags.
465
+ * @deprecated Hands out raw IR (`AnnotationsDef`). Use `.annotations`
466
+ * (returns the {@link Annotations} view). Slated for removal once
467
+ * external consumers migrate.
422
468
  */
469
+ get annotation(): AnnotationsDef | undefined;
470
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
423
471
  tagParse(spec?: TagParseSpec): MalloyTagParse;
424
- /**
425
- * Get annotation taglines matching an optional prefix.
426
- */
472
+ /** @deprecated Use `.annotations.texts(route)`. */
427
473
  getTaglines(prefix?: RegExp): string[];
428
474
  get annotations(): Annotations;
429
475
  /**
@@ -489,7 +535,9 @@ export declare class Given implements Taggable {
489
535
  /** `undefined` when no default — the caller must supply at run time. */
490
536
  get default(): ConstantExpr | undefined;
491
537
  get location(): DocumentLocation | undefined;
538
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
492
539
  tagParse(spec?: TagParseSpec): MalloyTagParse;
540
+ /** @deprecated Use `.annotations.texts(route)`. */
493
541
  getTaglines(prefix?: RegExp): string[];
494
542
  get annotations(): Annotations;
495
543
  }
@@ -500,7 +548,9 @@ export declare class PreparedQuery implements Taggable {
500
548
  _query: InternalQuery | NamedQueryDef;
501
549
  constructor(query: InternalQuery, _model: Model, problems: LogMessage[], name?: string | undefined);
502
550
  get _modelDef(): ModelDef;
551
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
503
552
  tagParse(spec?: TagParseSpec): MalloyTagParse;
553
+ /** @deprecated Use `.annotations.texts(route)`. */
504
554
  getTaglines(prefix?: RegExp): string[];
505
555
  get annotations(): Annotations;
506
556
  /**
@@ -544,11 +594,24 @@ export declare class PreparedResult implements Taggable {
544
594
  protected inner: CompiledQuery;
545
595
  constructor(query: CompiledQuery, modelDef: ModelDef);
546
596
  static fromJson({ query, modelDef, }: PreparedResultJSON): PreparedResult;
597
+ /** @deprecated Use `.annotations.parseAsTag(route)`. */
547
598
  tagParse(spec?: TagParseSpec): MalloyTagParse;
599
+ /** @deprecated Use `.annotations.texts(route)`. */
548
600
  getTaglines(prefix?: RegExp): string[];
549
601
  get annotations(): Annotations;
550
- get annotation(): Annotation | undefined;
551
- get modelAnnotation(): Annotation | undefined;
602
+ /**
603
+ * @deprecated Hands out raw IR (`AnnotationsDef`). Use `.annotations`
604
+ * (returns the {@link Annotations} view) for read access. Internal
605
+ * code that needs the IR shape should read `._rawQuery.annotations`
606
+ * directly. Slated for removal once external consumers migrate.
607
+ */
608
+ get annotation(): AnnotationsDef | undefined;
609
+ /**
610
+ * @deprecated Hands out raw IR (`AnnotationsDef`). Internal code that
611
+ * needs the model-level IR shape should read `._modelDef.annotations`
612
+ * directly. Slated for removal once external consumers migrate.
613
+ */
614
+ get modelAnnotation(): AnnotationsDef | undefined;
552
615
  get modelTag(): Tag;
553
616
  /**
554
617
  * @return The name of the connection this query should be run against.