@malloydata/malloy 0.0.403 → 0.0.405

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 (295) hide show
  1. package/LICENSE +77 -0
  2. package/dist/api/asynchronous.js +2 -4
  3. package/dist/api/connection.js +2 -4
  4. package/dist/api/core.js +5 -6
  5. package/dist/api/foundation/annotation.js +3 -11
  6. package/dist/api/foundation/compile.js +15 -8
  7. package/dist/api/foundation/core.d.ts +44 -6
  8. package/dist/api/foundation/core.js +112 -37
  9. package/dist/api/foundation/result.js +1 -2
  10. package/dist/api/foundation/runtime.js +9 -19
  11. package/dist/api/foundation/taggable.d.ts +5 -0
  12. package/dist/api/foundation/types.d.ts +15 -0
  13. package/dist/api/index.js +4 -6
  14. package/dist/api/sessioned.js +2 -4
  15. package/dist/api/stateless.js +2 -4
  16. package/dist/api/util.js +2 -4
  17. package/dist/connection/base_connection.js +2 -4
  18. package/dist/connection/types.d.ts +1 -3
  19. package/dist/connection_utils.js +2 -20
  20. package/dist/dialect/dialect.d.ts +9 -4
  21. package/dist/dialect/dialect.js +37 -31
  22. package/dist/dialect/dialect_map.js +2 -20
  23. package/dist/dialect/duckdb/dialect_functions.js +2 -4
  24. package/dist/dialect/duckdb/duckdb.js +2 -20
  25. package/dist/dialect/duckdb/function_overrides.js +2 -4
  26. package/dist/dialect/duckdb/index.js +2 -20
  27. package/dist/dialect/duckdb/table-path-parser.js +4 -4
  28. package/dist/dialect/functions/index.js +2 -20
  29. package/dist/dialect/functions/malloy_standard_functions.js +2 -4
  30. package/dist/dialect/functions/util.js +2 -21
  31. package/dist/dialect/index.js +2 -20
  32. package/dist/dialect/mysql/dialect_functions.js +2 -4
  33. package/dist/dialect/mysql/function_overrides.js +2 -4
  34. package/dist/dialect/mysql/index.js +2 -4
  35. package/dist/dialect/mysql/mysql.js +2 -20
  36. package/dist/dialect/pg_impl.d.ts +1 -0
  37. package/dist/dialect/pg_impl.js +10 -4
  38. package/dist/dialect/postgres/dialect_functions.js +2 -4
  39. package/dist/dialect/postgres/function_overrides.js +2 -4
  40. package/dist/dialect/postgres/index.js +2 -20
  41. package/dist/dialect/postgres/postgres.js +2 -20
  42. package/dist/dialect/snowflake/dialect_functions.js +2 -4
  43. package/dist/dialect/snowflake/function_overrides.js +2 -4
  44. package/dist/dialect/snowflake/index.js +2 -20
  45. package/dist/dialect/snowflake/snowflake.js +6 -25
  46. package/dist/dialect/standardsql/dialect_functions.js +2 -4
  47. package/dist/dialect/standardsql/function_overrides.js +2 -4
  48. package/dist/dialect/standardsql/index.js +2 -20
  49. package/dist/dialect/standardsql/standardsql.js +2 -20
  50. package/dist/dialect/tiny_parser.js +2 -4
  51. package/dist/dialect/trino/dialect_functions.js +2 -4
  52. package/dist/dialect/trino/function_overrides.js +2 -4
  53. package/dist/dialect/trino/index.js +2 -20
  54. package/dist/dialect/trino/trino.d.ts +1 -0
  55. package/dist/dialect/trino/trino.js +29 -26
  56. package/dist/index.js +4 -22
  57. package/dist/lang/ast/ast-utils.js +2 -20
  58. package/dist/lang/ast/error-factory.js +2 -20
  59. package/dist/lang/ast/expressions/apply.js +2 -20
  60. package/dist/lang/ast/expressions/binary-boolean.js +2 -20
  61. package/dist/lang/ast/expressions/binary-numeric.js +2 -20
  62. package/dist/lang/ast/expressions/boolean.js +2 -20
  63. package/dist/lang/ast/expressions/case.js +2 -4
  64. package/dist/lang/ast/expressions/constant-expression.js +2 -20
  65. package/dist/lang/ast/expressions/expr-add-sub.js +2 -20
  66. package/dist/lang/ast/expressions/expr-aggregate-function.js +2 -20
  67. package/dist/lang/ast/expressions/expr-alternation-tree.js +2 -20
  68. package/dist/lang/ast/expressions/expr-array-literal.js +2 -4
  69. package/dist/lang/ast/expressions/expr-asymmetric.js +2 -20
  70. package/dist/lang/ast/expressions/expr-avg.js +2 -20
  71. package/dist/lang/ast/expressions/expr-cast.js +2 -20
  72. package/dist/lang/ast/expressions/expr-coalesce.js +2 -20
  73. package/dist/lang/ast/expressions/expr-compare.js +2 -20
  74. package/dist/lang/ast/expressions/expr-count-distinct.js +2 -20
  75. package/dist/lang/ast/expressions/expr-count.js +2 -20
  76. package/dist/lang/ast/expressions/expr-filter-expr.js +2 -4
  77. package/dist/lang/ast/expressions/expr-func.js +6 -24
  78. package/dist/lang/ast/expressions/expr-granular-time.js +2 -20
  79. package/dist/lang/ast/expressions/expr-id-reference.js +2 -20
  80. package/dist/lang/ast/expressions/expr-logical-op.js +2 -20
  81. package/dist/lang/ast/expressions/expr-max.js +2 -20
  82. package/dist/lang/ast/expressions/expr-min.js +2 -20
  83. package/dist/lang/ast/expressions/expr-minus.js +2 -20
  84. package/dist/lang/ast/expressions/expr-mul-div.js +2 -20
  85. package/dist/lang/ast/expressions/expr-not.js +2 -20
  86. package/dist/lang/ast/expressions/expr-now.js +2 -20
  87. package/dist/lang/ast/expressions/expr-null.js +2 -20
  88. package/dist/lang/ast/expressions/expr-number.js +2 -20
  89. package/dist/lang/ast/expressions/expr-parens.js +2 -20
  90. package/dist/lang/ast/expressions/expr-props.js +2 -20
  91. package/dist/lang/ast/expressions/expr-record-literal.js +2 -4
  92. package/dist/lang/ast/expressions/expr-regex.js +2 -20
  93. package/dist/lang/ast/expressions/expr-string.js +4 -0
  94. package/dist/lang/ast/expressions/expr-sum.js +2 -20
  95. package/dist/lang/ast/expressions/expr-time-extract.js +2 -20
  96. package/dist/lang/ast/expressions/expr-time.js +2 -20
  97. package/dist/lang/ast/expressions/expr-ungroup.js +2 -20
  98. package/dist/lang/ast/expressions/for-range.js +2 -20
  99. package/dist/lang/ast/expressions/function-ordering.js +2 -20
  100. package/dist/lang/ast/expressions/grouped_by.js +2 -4
  101. package/dist/lang/ast/expressions/partial-compare.js +2 -20
  102. package/dist/lang/ast/expressions/partition_by.js +2 -20
  103. package/dist/lang/ast/expressions/pick-when.js +2 -20
  104. package/dist/lang/ast/expressions/range.js +2 -20
  105. package/dist/lang/ast/expressions/time-frame.js +2 -20
  106. package/dist/lang/ast/expressions/time-literal.js +2 -20
  107. package/dist/lang/ast/expressions/unary.js +2 -20
  108. package/dist/lang/ast/field-space/ast-view-field.js +2 -20
  109. package/dist/lang/ast/field-space/column-space-field.js +2 -20
  110. package/dist/lang/ast/field-space/def-space.js +2 -4
  111. package/dist/lang/ast/field-space/dynamic-space.js +4 -22
  112. package/dist/lang/ast/field-space/include-utils.js +6 -8
  113. package/dist/lang/ast/field-space/index-field-space.js +2 -20
  114. package/dist/lang/ast/field-space/ir-view-field.js +2 -20
  115. package/dist/lang/ast/field-space/join-space-field.js +2 -20
  116. package/dist/lang/ast/field-space/parameter-space.js +2 -4
  117. package/dist/lang/ast/field-space/passthrough-space.js +2 -4
  118. package/dist/lang/ast/field-space/permissive-space.js +2 -4
  119. package/dist/lang/ast/field-space/project-field-space.js +2 -20
  120. package/dist/lang/ast/field-space/query-input-space.js +2 -20
  121. package/dist/lang/ast/field-space/query-spaces.js +8 -28
  122. package/dist/lang/ast/field-space/reference-field.js +5 -21
  123. package/dist/lang/ast/field-space/refine-from-space-field.js +2 -4
  124. package/dist/lang/ast/field-space/refined-space.js +8 -26
  125. package/dist/lang/ast/field-space/rename-space-field.js +8 -29
  126. package/dist/lang/ast/field-space/static-space.js +3 -21
  127. package/dist/lang/ast/field-space/struct-space-field-base.js +3 -21
  128. package/dist/lang/ast/field-space/view-field.js +2 -20
  129. package/dist/lang/ast/index.js +2 -20
  130. package/dist/lang/ast/parameters/argument.js +2 -4
  131. package/dist/lang/ast/parameters/has-parameter.js +2 -20
  132. package/dist/lang/ast/query-builders/index-builder.js +2 -20
  133. package/dist/lang/ast/query-builders/partial-builder.js +4 -0
  134. package/dist/lang/ast/query-builders/project-builder.js +2 -20
  135. package/dist/lang/ast/query-builders/reduce-builder.js +2 -20
  136. package/dist/lang/ast/query-elements/anonymous-query.js +3 -21
  137. package/dist/lang/ast/query-elements/query-arrow.js +2 -20
  138. package/dist/lang/ast/query-elements/query-base.js +2 -20
  139. package/dist/lang/ast/query-elements/query-head-struct.js +2 -20
  140. package/dist/lang/ast/query-elements/query-raw.js +2 -20
  141. package/dist/lang/ast/query-elements/query-reference.js +2 -20
  142. package/dist/lang/ast/query-elements/query-refine.js +2 -20
  143. package/dist/lang/ast/query-items/field-declaration.js +3 -21
  144. package/dist/lang/ast/query-items/field-references.js +2 -20
  145. package/dist/lang/ast/query-items/typecheck_utils.js +2 -20
  146. package/dist/lang/ast/query-properties/aggregate.js +2 -20
  147. package/dist/lang/ast/query-properties/calculate.js +2 -20
  148. package/dist/lang/ast/query-properties/declare-fields.js +2 -20
  149. package/dist/lang/ast/query-properties/drill.js +5 -10
  150. package/dist/lang/ast/query-properties/extend.js +2 -20
  151. package/dist/lang/ast/query-properties/filters.js +2 -20
  152. package/dist/lang/ast/query-properties/group-by.js +2 -20
  153. package/dist/lang/ast/query-properties/indexing.js +2 -20
  154. package/dist/lang/ast/query-properties/limit.js +2 -20
  155. package/dist/lang/ast/query-properties/nest.js +6 -21
  156. package/dist/lang/ast/query-properties/nests.js +2 -20
  157. package/dist/lang/ast/query-properties/ordering.js +2 -20
  158. package/dist/lang/ast/query-properties/project-statement.js +2 -20
  159. package/dist/lang/ast/query-properties/qop-desc.js +2 -20
  160. package/dist/lang/ast/query-properties/sampling.js +2 -20
  161. package/dist/lang/ast/query-utils.js +2 -20
  162. package/dist/lang/ast/source-elements/composite-source.js +3 -6
  163. package/dist/lang/ast/source-elements/named-source.js +2 -23
  164. package/dist/lang/ast/source-elements/query-source.js +2 -22
  165. package/dist/lang/ast/source-elements/refined-source.js +2 -22
  166. package/dist/lang/ast/source-elements/source.js +2 -20
  167. package/dist/lang/ast/source-elements/sql-source.js +8 -33
  168. package/dist/lang/ast/source-elements/table-source.js +11 -32
  169. package/dist/lang/ast/source-elements/typed-source.js +2 -3
  170. package/dist/lang/ast/source-elements/virtual-source.js +1 -2
  171. package/dist/lang/ast/source-properties/dimensions.js +2 -20
  172. package/dist/lang/ast/source-properties/field-list-edit.js +2 -20
  173. package/dist/lang/ast/source-properties/join.js +7 -31
  174. package/dist/lang/ast/source-properties/measures.js +2 -20
  175. package/dist/lang/ast/source-properties/primary-key.js +2 -20
  176. package/dist/lang/ast/source-properties/renames.js +3 -21
  177. package/dist/lang/ast/source-properties/timezone-statement.js +2 -20
  178. package/dist/lang/ast/source-properties/user-type-shape.js +9 -4
  179. package/dist/lang/ast/source-properties/view-field-declaration.js +6 -21
  180. package/dist/lang/ast/source-properties/views.js +2 -20
  181. package/dist/lang/ast/source-query-elements/include-item.js +2 -4
  182. package/dist/lang/ast/source-query-elements/source-query-element.js +2 -20
  183. package/dist/lang/ast/source-query-elements/sq-arrow.js +2 -20
  184. package/dist/lang/ast/source-query-elements/sq-compose.js +2 -4
  185. package/dist/lang/ast/source-query-elements/sq-extend.js +2 -20
  186. package/dist/lang/ast/source-query-elements/sq-reference.js +3 -21
  187. package/dist/lang/ast/source-query-elements/sq-refine.js +2 -20
  188. package/dist/lang/ast/source-query-elements/sq-source.js +2 -20
  189. package/dist/lang/ast/sql-elements/sql-string.js +2 -20
  190. package/dist/lang/ast/statements/define-given.js +2 -2
  191. package/dist/lang/ast/statements/define-query.js +3 -21
  192. package/dist/lang/ast/statements/define-source.js +8 -23
  193. package/dist/lang/ast/statements/define-user-type.js +1 -1
  194. package/dist/lang/ast/statements/import-statement.js +7 -20
  195. package/dist/lang/ast/time-utils.js +2 -20
  196. package/dist/lang/ast/typedesc-utils.js +2 -20
  197. package/dist/lang/ast/types/annotation-elements.js +2 -20
  198. package/dist/lang/ast/types/binary_operators.js +2 -4
  199. package/dist/lang/ast/types/definition-list.js +2 -20
  200. package/dist/lang/ast/types/dialect-name-space.js +2 -4
  201. package/dist/lang/ast/types/document-compile-result.js +2 -20
  202. package/dist/lang/ast/types/expr-result.js +2 -20
  203. package/dist/lang/ast/types/expr-value.js +2 -20
  204. package/dist/lang/ast/types/expression-def.js +2 -20
  205. package/dist/lang/ast/types/field-collection-member.js +2 -20
  206. package/dist/lang/ast/types/field-prop-statement.js +2 -20
  207. package/dist/lang/ast/types/field-space.js +2 -20
  208. package/dist/lang/ast/types/global-name-space.js +2 -20
  209. package/dist/lang/ast/types/granular-result.js +2 -20
  210. package/dist/lang/ast/types/literal.d.ts +1 -1
  211. package/dist/lang/ast/types/literal.js +2 -4
  212. package/dist/lang/ast/types/lookup-result.js +2 -20
  213. package/dist/lang/ast/types/malloy-element.d.ts +28 -4
  214. package/dist/lang/ast/types/malloy-element.js +63 -77
  215. package/dist/lang/ast/types/model-entry.js +2 -20
  216. package/dist/lang/ast/types/name-space.js +2 -20
  217. package/dist/lang/ast/types/noteable.js +2 -20
  218. package/dist/lang/ast/types/op-desc.js +2 -20
  219. package/dist/lang/ast/types/pipeline-comp.js +2 -20
  220. package/dist/lang/ast/types/query-builder.js +2 -20
  221. package/dist/lang/ast/types/query-comp.js +2 -20
  222. package/dist/lang/ast/types/query-element.js +2 -20
  223. package/dist/lang/ast/types/query-extend-property.js +2 -20
  224. package/dist/lang/ast/types/query-item.js +2 -20
  225. package/dist/lang/ast/types/query-property-interface.js +2 -20
  226. package/dist/lang/ast/types/query-property.js +2 -20
  227. package/dist/lang/ast/types/source-desc.js +2 -20
  228. package/dist/lang/ast/types/source-property.js +2 -20
  229. package/dist/lang/ast/types/space-entry.js +2 -20
  230. package/dist/lang/ast/types/space-field.js +2 -20
  231. package/dist/lang/ast/types/space-param.js +2 -20
  232. package/dist/lang/ast/types/time-result.js +2 -20
  233. package/dist/lang/ast/view-elements/qop-desc-view.js +2 -20
  234. package/dist/lang/ast/view-elements/reference-view.js +2 -20
  235. package/dist/lang/ast/view-elements/refine-utils.js +2 -20
  236. package/dist/lang/ast/view-elements/view-arrow.js +2 -20
  237. package/dist/lang/ast/view-elements/view-refine.js +2 -20
  238. package/dist/lang/ast/view-elements/view.js +2 -20
  239. package/dist/lang/composite-source-utils.js +15 -21
  240. package/dist/lang/field-utils.js +4 -22
  241. package/dist/lang/index.js +2 -20
  242. package/dist/lang/malloy-parse-info.js +2 -20
  243. package/dist/lang/malloy-to-ast.d.ts +1 -1
  244. package/dist/lang/malloy-to-ast.js +2 -21
  245. package/dist/lang/malloy-to-stable-query.js +2 -4
  246. package/dist/lang/parse-log.js +2 -20
  247. package/dist/lang/parse-malloy.d.ts +1 -9
  248. package/dist/lang/parse-malloy.js +8 -50
  249. package/dist/lang/parse-tree-walkers/document-completion-walker.js +2 -20
  250. package/dist/lang/parse-tree-walkers/document-help-context-walker.js +2 -20
  251. package/dist/lang/parse-tree-walkers/document-symbol-walker.js +2 -20
  252. package/dist/lang/parse-tree-walkers/explore-query-walker.js +2 -20
  253. package/dist/lang/parse-tree-walkers/find-external-references.js +2 -20
  254. package/dist/lang/parse-tree-walkers/find-table-path-walker.js +2 -20
  255. package/dist/lang/parse-utils.js +2 -20
  256. package/dist/lang/reference-list.js +2 -20
  257. package/dist/lang/run-malloy-parser.js +2 -4
  258. package/dist/lang/syntax-errors/custom-error-messages.js +2 -4
  259. package/dist/lang/syntax-errors/malloy-error-strategy.js +2 -4
  260. package/dist/lang/syntax-errors/malloy-parser-error-listener.js +2 -4
  261. package/dist/lang/test/expr-to-str.js +2 -4
  262. package/dist/lang/test/parse-expects.js +2 -20
  263. package/dist/lang/test/test-translator.js +6 -29
  264. package/dist/lang/translate-response.d.ts +1 -5
  265. package/dist/lang/translate-response.js +2 -20
  266. package/dist/lang/utils.js +2 -20
  267. package/dist/lang/zone.js +2 -20
  268. package/dist/model/annotation_utils.d.ts +37 -0
  269. package/dist/model/annotation_utils.js +85 -0
  270. package/dist/model/field_instance.js +1 -1
  271. package/dist/model/filter_compilers.js +2 -4
  272. package/dist/model/index.d.ts +2 -1
  273. package/dist/model/index.js +6 -21
  274. package/dist/model/malloy_types.d.ts +43 -9
  275. package/dist/model/malloy_types.js +13 -29
  276. package/dist/model/query_model_impl.d.ts +0 -1
  277. package/dist/model/query_model_impl.js +9 -28
  278. package/dist/model/query_node.d.ts +1 -13
  279. package/dist/model/query_node.js +8 -52
  280. package/dist/model/query_query.js +4 -18
  281. package/dist/model/source_def_utils.js +0 -2
  282. package/dist/model/sql_block.js +2 -20
  283. package/dist/model/utils.d.ts +9 -2
  284. package/dist/model/utils.js +18 -24
  285. package/dist/run_sql_options.d.ts +0 -5
  286. package/dist/run_sql_options.js +2 -20
  287. package/dist/runtime_types.js +2 -20
  288. package/dist/test/cellsToObject.js +2 -4
  289. package/dist/timing.js +2 -4
  290. package/dist/to_stable.js +9 -13
  291. package/dist/version.d.ts +1 -1
  292. package/dist/version.js +1 -1
  293. package/package.json +4 -4
  294. package/dist/lang/parse-tree-walkers/model-annotation-walker.d.ts +0 -5
  295. package/dist/lang/parse-tree-walkers/model-annotation-walker.js +0 -50
@@ -0,0 +1,85 @@
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.notesInOrder = notesInOrder;
8
+ exports.getModelAnnotations = getModelAnnotations;
9
+ /**
10
+ * Every Note of an annotation bundle, inherited first, in document order
11
+ * (`inherits` → `blockNotes` → `notes`). Later notes win when re-parsed.
12
+ *
13
+ * Internal helper — not part of the public `model` barrel. The public way to
14
+ * read notes is the `Annotations` view (`api/foundation/annotation.ts`), which
15
+ * uses this; the model-annotation fold below uses it too.
16
+ */
17
+ function* notesInOrder(annote) {
18
+ if (annote.inherits)
19
+ yield* notesInOrder(annote.inherits);
20
+ if (annote.blockNotes)
21
+ yield* annote.blockNotes;
22
+ if (annote.notes)
23
+ yield* annote.notes;
24
+ }
25
+ /**
26
+ * The model (`##`) annotations for one model, compiled by walking the
27
+ * annotation-provenance tree: a model's own `##` together with everything it
28
+ * imports/extends, folded down the lineage into a single ordered bundle.
29
+ *
30
+ * `modelID` defaults to `model.modelID` — the common case, "the annotations
31
+ * this model presents." `##` is model-level, so every object resolved in the
32
+ * model reports this same one bundle (resolution takes no object). Pass an
33
+ * explicit `modelID` to compile the bundle for any other model in the closure.
34
+ *
35
+ * Mechanism: a post-order DFS over each model's `inheritsFrom` edges
36
+ * (extend-base is `import₀`, sitting first) emits a model only after its
37
+ * predecessors and only once (its most-ancestral slot); back-edges are skipped,
38
+ * so the walk terminates on a cycle. The result is ordered imports-first /
39
+ * local-last — a consumer that takes "last wins" sees the target model's own
40
+ * `##` win — and is returned as an {@link AnnotationsDef} whose `inherits` chain
41
+ * *is* that order (target at the top, most-ancestral import deepest), so the
42
+ * `Annotations` view / {@link notesInOrder} consume it with no new code.
43
+ *
44
+ * A target with no entry contributes nothing (empty) — the honest answer for a
45
+ * synthetic or detached `ModelDef` (built via `mkModelDef`, a `pseudoModelFor`
46
+ * struct, a model with no `##` anywhere) that never recorded a self-entry. But
47
+ * a recorded `inheritsFrom` *edge* to a model with no entry is corruption —
48
+ * population kept the edge but lost the target — and throws a compiler-bug-class
49
+ * error: the one place that needs the entry is the one place that detects it.
50
+ */
51
+ function getModelAnnotations(model, modelID = model.modelID) {
52
+ var _a, _b;
53
+ const order = []; // ancestral-first, target last; deduped keep-first
54
+ const entered = new Set(); // guards both re-folding and cycles
55
+ const visit = (id, viaEdge) => {
56
+ if (entered.has(id))
57
+ return; // already folded (diamond) or a back-edge cycle
58
+ const entry = model.modelAnnotations[id];
59
+ if (entry === undefined) {
60
+ if (viaEdge) {
61
+ throw new Error(`Internal error: model '${model.modelID}' has an inheritsFrom edge ` +
62
+ `to '${id}', which has no entry in its closure (likely a compiler bug)`);
63
+ }
64
+ return; // target model has no annotations of its own — contribute nothing
65
+ }
66
+ entered.add(id);
67
+ for (const pred of entry.inheritsFrom)
68
+ visit(pred, true);
69
+ order.push(id);
70
+ };
71
+ visit(modelID, false);
72
+ // Build the output `inherits` chain bottom-up: most-ancestral deepest, target
73
+ // at the top. `notesInOrder` then yields ancestral → local. Models that
74
+ // contribute no notes of their own add no link — the chain carries only the
75
+ // notes that exist, not an empty node per model in the lineage.
76
+ let chain = undefined;
77
+ for (const id of order) {
78
+ const own = model.modelAnnotations[id].ownNotes;
79
+ if (!((_a = own.notes) === null || _a === void 0 ? void 0 : _a.length) && !((_b = own.blockNotes) === null || _b === void 0 ? void 0 : _b.length))
80
+ continue;
81
+ chain = { notes: own.notes, blockNotes: own.blockNotes, inherits: chain };
82
+ }
83
+ return chain !== null && chain !== void 0 ? chain : {};
84
+ }
85
+ //# sourceMappingURL=annotation_utils.js.map
@@ -59,7 +59,7 @@ class FieldInstanceField {
59
59
  var _a;
60
60
  if (this.f.parent.primaryKey()) {
61
61
  const pk = this.f.parent.getPrimaryKeyField(this.f.fieldDef);
62
- const pkName = pk.fieldDef.as || pk.fieldDef.name;
62
+ const pkName = (0, malloy_types_1.activeName)(pk.fieldDef);
63
63
  const pkField = this.parent.getField(pkName);
64
64
  return pkField.generateExpression();
65
65
  }
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) Meta Platforms, Inc. and affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
3
+ * Copyright Contributors to the Malloy project
4
+ * SPDX-License-Identifier: MIT
7
5
  */
8
6
  Object.defineProperty(exports, "__esModule", { value: true });
9
7
  exports.TemporalFilterCompiler = exports.FilterCompilers = void 0;
@@ -4,7 +4,8 @@ import { QueryQuery } from './query_query';
4
4
  import { QueryModelImpl } from './query_model_impl';
5
5
  export { QueryField, QueryStruct, QueryQuery, QueryModelImpl as QueryModel };
6
6
  export { getResultStructDefForQuery, getResultStructDefForView, } from './query_model_impl';
7
- export { indent, composeSQLExpr, makeDigest, mkModelDef, pathToKey, typeDefToString, } from './utils';
7
+ export { indent, composeSQLExpr, makeDigest, mkModelDef, mkModelID, pathToKey, typeDefToString, } from './utils';
8
+ export { getModelAnnotations } from './annotation_utils';
8
9
  export { constantExprToSQL } from './constant_expression_compiler';
9
10
  export { getCompiledSQL } from './sql_compiled';
10
11
  export { MalloyCompileError } from './malloy_compile_error';
@@ -1,25 +1,7 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright 2023 Google LLC
4
- *
5
- * Permission is hereby granted, free of charge, to any person obtaining
6
- * a copy of this software and associated documentation files
7
- * (the "Software"), to deal in the Software without restriction,
8
- * including without limitation the rights to use, copy, modify, merge,
9
- * publish, distribute, sublicense, and/or sell copies of the Software,
10
- * and to permit persons to whom the Software is furnished to do so,
11
- * subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be
14
- * included in all copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3
+ * Copyright Contributors to the Malloy project
4
+ * SPDX-License-Identifier: MIT
23
5
  */
24
6
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
7
  if (k2 === undefined) k2 = k;
@@ -36,7 +18,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
18
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
19
  };
38
20
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.hasSourceRegistryEntry = exports.registerSource = exports.resolveSourceID = exports.mkTableSourceDef = exports.mkSQLSourceDef = exports.mkQuerySourceDef = exports.mkBuildID = exports.mkSourceID = exports.MalloyCompileError = exports.getCompiledSQL = exports.constantExprToSQL = exports.typeDefToString = exports.pathToKey = exports.mkModelDef = exports.makeDigest = exports.composeSQLExpr = exports.indent = exports.getResultStructDefForView = exports.getResultStructDefForQuery = exports.QueryModel = exports.QueryQuery = exports.QueryStruct = exports.QueryField = void 0;
21
+ exports.hasSourceRegistryEntry = exports.registerSource = exports.resolveSourceID = exports.mkTableSourceDef = exports.mkSQLSourceDef = exports.mkQuerySourceDef = exports.mkBuildID = exports.mkSourceID = exports.MalloyCompileError = exports.getCompiledSQL = exports.constantExprToSQL = exports.getModelAnnotations = exports.typeDefToString = exports.pathToKey = exports.mkModelID = exports.mkModelDef = exports.makeDigest = exports.composeSQLExpr = exports.indent = exports.getResultStructDefForView = exports.getResultStructDefForQuery = exports.QueryModel = exports.QueryQuery = exports.QueryStruct = exports.QueryField = void 0;
40
22
  __exportStar(require("./malloy_types"), exports);
41
23
  const query_node_1 = require("./query_node");
42
24
  Object.defineProperty(exports, "QueryField", { enumerable: true, get: function () { return query_node_1.QueryField; } });
@@ -60,8 +42,11 @@ Object.defineProperty(exports, "indent", { enumerable: true, get: function () {
60
42
  Object.defineProperty(exports, "composeSQLExpr", { enumerable: true, get: function () { return utils_1.composeSQLExpr; } });
61
43
  Object.defineProperty(exports, "makeDigest", { enumerable: true, get: function () { return utils_1.makeDigest; } });
62
44
  Object.defineProperty(exports, "mkModelDef", { enumerable: true, get: function () { return utils_1.mkModelDef; } });
45
+ Object.defineProperty(exports, "mkModelID", { enumerable: true, get: function () { return utils_1.mkModelID; } });
63
46
  Object.defineProperty(exports, "pathToKey", { enumerable: true, get: function () { return utils_1.pathToKey; } });
64
47
  Object.defineProperty(exports, "typeDefToString", { enumerable: true, get: function () { return utils_1.typeDefToString; } });
48
+ var annotation_utils_1 = require("./annotation_utils");
49
+ Object.defineProperty(exports, "getModelAnnotations", { enumerable: true, get: function () { return annotation_utils_1.getModelAnnotations; } });
65
50
  var constant_expression_compiler_1 = require("./constant_expression_compiler");
66
51
  Object.defineProperty(exports, "constantExprToSQL", { enumerable: true, get: function () { return constant_expression_compiler_1.constantExprToSQL; } });
67
52
  var sql_compiled_1 = require("./sql_compiled");
@@ -444,6 +444,13 @@ export interface AliasedName {
444
444
  name: string;
445
445
  as?: string;
446
446
  }
447
+ /**
448
+ * The name an `AliasedName` goes by in its current context: its `as` binding
449
+ * if it has one, otherwise its intrinsic `name`. This is the only correct way
450
+ * to ask "what is this called here" — see the `name`/`as` invariant in
451
+ * model/CONTEXT.md.
452
+ */
453
+ export declare function activeName(an: AliasedName): string;
447
454
  /** all named objects have a type an a name (optionally aliased) */
448
455
  export interface NamedObject extends AliasedName, HasLocation {
449
456
  type: string;
@@ -664,7 +671,6 @@ export interface Query extends Pipeline, Filtered {
664
671
  name?: string;
665
672
  structRef: StructRef;
666
673
  sourceArguments?: SafeRecord<Argument>;
667
- modelAnnotations?: AnnotationsDef;
668
674
  compositeResolvedSourceDef?: SourceDef;
669
675
  givenUsage?: GivenUsage;
670
676
  }
@@ -832,7 +838,6 @@ export interface TurtleDefPlusFilters extends TurtleDef, Filtered {
832
838
  }
833
839
  interface StructDefBase extends HasLocation, NamedObject, HasAnnotations {
834
840
  type: string;
835
- modelAnnotations?: ModelAnnotationsDef;
836
841
  fields: FieldDef[];
837
842
  /** Marker for error placeholder structs created by ErrorFactory */
838
843
  errorFactory?: boolean;
@@ -879,6 +884,13 @@ export type SourceID = string;
879
884
  export type GivenID = string;
880
885
  /** Hash of (connectionDigest, sql) - uniquely identifies a built artifact */
881
886
  export type BuildID = string;
887
+ /**
888
+ * Identifies the model a definition came from. Either a real model URL or a
889
+ * synthetic `"internal <uuid>"` for URL-less models. The space makes the
890
+ * synthetic form an illegal URL, so it can never collide with a real model
891
+ * URL. Created with `mkModelID`.
892
+ */
893
+ export type ModelID = string;
882
894
  /**
883
895
  * Reference to a source in modelDef.contents by name.
884
896
  * Used in sourceRegistry to avoid duplicating SourceDefs that are in the namespace.
@@ -1092,8 +1104,6 @@ export interface RefToField extends HasAnnotations {
1092
1104
  }
1093
1105
  export type QueryFieldDef = AtomicFieldDef | TurtleDef | RefToField;
1094
1106
  export type TypedDef = AtomicTypeDef | JoinFieldDef | TurtleDef | RefToField | StructDef;
1095
- /** Get the output name for a NamedObject */
1096
- export declare function getIdentifier(n: AliasedName): string;
1097
1107
  export interface UserTypeFieldDef extends HasAnnotations {
1098
1108
  name: string;
1099
1109
  typeDef: AtomicTypeDef;
@@ -1110,6 +1120,7 @@ export interface DependencyTree {
1110
1120
  /** Result of parsing a model file */
1111
1121
  export interface ModelDef {
1112
1122
  name: string;
1123
+ modelID: ModelID;
1113
1124
  exports: string[];
1114
1125
  contents: SafeRecord<NamedModelObject>;
1115
1126
  /**
@@ -1120,7 +1131,17 @@ export interface ModelDef {
1120
1131
  */
1121
1132
  sourceRegistry: Record<SourceID, SourceRegistryValue>;
1122
1133
  givens?: Record<GivenID, Given>;
1123
- annotations?: ModelAnnotationsDef;
1134
+ /**
1135
+ * Model (`##`) annotations of every model involved in this compile, keyed by
1136
+ * {@link ModelID} — this model plus everything it imported or extended (the
1137
+ * whole closure, so any model's annotations are answerable from this
1138
+ * `ModelDef` alone, even after it crosses the wire). Each entry carries that
1139
+ * model's own `##` (`ownNotes`) and its direct import/extend predecessors
1140
+ * (`inheritsFrom`, the DAG of edges, extend-base prepended as `import₀`).
1141
+ * {@link getModelAnnotations} folds `inheritsFrom` from any model to produce
1142
+ * that model's deduped, ordered annotation set.
1143
+ */
1144
+ modelAnnotations: Record<ModelID, ModelAnnotationEntry>;
1124
1145
  queryList: Query[];
1125
1146
  dependencies: DependencyTree;
1126
1147
  references?: DocumentReference[];
@@ -1131,7 +1152,16 @@ export type NamedSourceDefs = SafeRecord<SourceDef>;
1131
1152
  export type NamedModelObjects = SafeRecord<NamedModelObject>;
1132
1153
  /** Bundle of source annotations attached to one object: the `notes` and
1133
1154
  * `blockNotes` written on it, plus the bundle from the spiritual parent
1134
- * via `inherits`. The IR shape paired with the `Annotations` view class. */
1155
+ * via `inherits`. The IR shape paired with the `Annotations` view class.
1156
+ *
1157
+ * This is the one annotation bundle type for both `#` object annotations (on
1158
+ * fields, views, sources, queries, …) and `##` model annotations. Object
1159
+ * annotations carry no model provenance: `##` is model-level, resolved by
1160
+ * folding {@link ModelDef.modelAnnotations} keyed by {@link ModelID}, not by
1161
+ * per-object stamping. A model's own `##` is just an `AnnotationsDef` whose
1162
+ * `inherits` chain is unused as stored (`ModelAnnotationEntry.ownNotes`) and,
1163
+ * when returned by {@link getModelAnnotations}, *is* the folded order (local at the
1164
+ * top) so the `Annotations` view / `notesInOrder` read it with no new code. */
1135
1165
  export interface AnnotationsDef {
1136
1166
  inherits?: AnnotationsDef;
1137
1167
  blockNotes?: Note[];
@@ -1150,9 +1180,13 @@ export interface Note {
1150
1180
  */
1151
1181
  indentStripped?: number;
1152
1182
  }
1153
- /** Annotations bundle with a uuid to make it easier to stream. */
1154
- export interface ModelAnnotationsDef extends AnnotationsDef {
1155
- id: string;
1183
+ /** One model's entry in {@link ModelDef.modelAnnotations}: its own `##`
1184
+ * (`ownNotes`) plus its **direct** import/extend predecessors (`inheritsFrom`),
1185
+ * in fold order with the extend-base prepended as `import₀`. Direct edges only
1186
+ * — the lineage DAG, not the resolved order; {@link getModelAnnotations} resolves. */
1187
+ export interface ModelAnnotationEntry {
1188
+ ownNotes: AnnotationsDef;
1189
+ inheritsFrom: ModelID[];
1156
1190
  }
1157
1191
  export type QueryScalar = string | boolean | number | bigint | Date | Buffer | null;
1158
1192
  /** One value in one column of returned data. */
@@ -1,26 +1,7 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright 2023 Google LLC
4
- * Copyright (c) Meta Platforms, Inc. and affiliates.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining
7
- * a copy of this software and associated documentation files
8
- * (the "Software"), to deal in the Software without restriction,
9
- * including without limitation the rights to use, copy, modify, merge,
10
- * publish, distribute, sublicense, and/or sell copies of the Software,
11
- * and to permit persons to whom the Software is furnished to do so,
12
- * subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be
15
- * included in all copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3
+ * Copyright Contributors to the Malloy project
4
+ * SPDX-License-Identifier: MIT
24
5
  */
25
6
  Object.defineProperty(exports, "__esModule", { value: true });
26
7
  exports.TD = exports.ValueType = void 0;
@@ -36,6 +17,7 @@ exports.isFilterExprType = isFilterExprType;
36
17
  exports.isTimeLiteral = isTimeLiteral;
37
18
  exports.isParameterType = isParameterType;
38
19
  exports.paramHasValue = paramHasValue;
20
+ exports.activeName = activeName;
39
21
  exports.expressionIsScalar = expressionIsScalar;
40
22
  exports.expressionIsAggregate = expressionIsAggregate;
41
23
  exports.expressionIsUngroupedAggregate = expressionIsUngroupedAggregate;
@@ -93,7 +75,6 @@ exports.isBaseTable = isBaseTable;
93
75
  exports.isLiteral = isLiteral;
94
76
  exports.mergeEvalSpaces = mergeEvalSpaces;
95
77
  exports.isBasicAtomic = isBasicAtomic;
96
- exports.getIdentifier = getIdentifier;
97
78
  exports.isUserTypeDef = isUserTypeDef;
98
79
  exports.isCompoundArrayData = isCompoundArrayData;
99
80
  exports.isTurtle = isTurtle;
@@ -183,6 +164,16 @@ function isParameterType(t) {
183
164
  function paramHasValue(p) {
184
165
  return p.value !== null;
185
166
  }
167
+ /**
168
+ * The name an `AliasedName` goes by in its current context: its `as` binding
169
+ * if it has one, otherwise its intrinsic `name`. This is the only correct way
170
+ * to ask "what is this called here" — see the `name`/`as` invariant in
171
+ * model/CONTEXT.md.
172
+ */
173
+ function activeName(an) {
174
+ var _a;
175
+ return (_a = an.as) !== null && _a !== void 0 ? _a : an.name;
176
+ }
186
177
  function expressionIsScalar(e) {
187
178
  return e === undefined || e === 'scalar';
188
179
  }
@@ -580,13 +571,6 @@ function isBasicAtomic(fd) {
580
571
  fd.type === 'sql native' ||
581
572
  fd.type === 'error');
582
573
  }
583
- /** Get the output name for a NamedObject */
584
- function getIdentifier(n) {
585
- if (n.as !== undefined) {
586
- return n.as;
587
- }
588
- return n.name;
589
- }
590
574
  function isUserTypeDef(sd) {
591
575
  return sd.type === 'userType';
592
576
  }
@@ -12,7 +12,6 @@ export declare class QueryModelImpl implements QueryModel, ModelRootInterface {
12
12
  structs: Map<string, QueryStruct>;
13
13
  get givens(): Record<string, Given>;
14
14
  constructor(modelDef: ModelDef | undefined);
15
- getFinalOutputStruct(query: Query, options: PrepareResultOptions | undefined): SourceDef | undefined;
16
15
  loadModelFromDef(modelDef: ModelDef): void;
17
16
  getStructByName(name: string): QueryStruct;
18
17
  getStructFromRef(structRef: StructRef, sourceArguments: Record<string, Argument> | undefined, prepareResultOptions?: PrepareResultOptions): QueryStruct;
@@ -33,31 +33,17 @@ class QueryModelImpl {
33
33
  this.loadModelFromDef(modelDef);
34
34
  }
35
35
  }
36
- // Another circularity breaking method ... call into QueryQuery
37
- // to find the output shape of a query
38
- getFinalOutputStruct(query, options) {
39
- const result = this.loadQuery(query, undefined, options, false, false);
40
- return result.structs.pop();
41
- }
42
36
  loadModelFromDef(modelDef) {
43
37
  this.modelDef = modelDef;
44
38
  for (const s of Object.values(this.modelDef.contents)) {
45
- let qs;
39
+ // Only sources become QueryStructs. query/userType/given are namespace
40
+ // metadata, not queryable, and are skipped.
46
41
  if ((0, malloy_types_1.isSourceDef)(s)) {
47
- qs = new query_node_1.QueryStruct(s, undefined, { model: this }, {});
48
- this.structs.set((0, malloy_types_1.getIdentifier)(s), qs);
49
- qs.resolveQueryFields((query, options) => this.getFinalOutputStruct(query, options));
50
- }
51
- else if (s.type === 'query') {
52
- /* TODO */
53
- }
54
- else if (s.type === 'userType') {
55
- // User type definitions are metadata only, not queryable
42
+ this.structs.set((0, malloy_types_1.activeName)(s), new query_node_1.QueryStruct(s, undefined, { model: this }, {}));
56
43
  }
57
- else if (s.type === 'given') {
58
- // Givens are metadata in the namespace, not queryable structures.
59
- }
60
- else {
44
+ else if (s.type !== 'query' &&
45
+ s.type !== 'userType' &&
46
+ s.type !== 'given') {
61
47
  throw new Error('Internal Error: Unknown structure type');
62
48
  }
63
49
  }
@@ -73,10 +59,7 @@ class QueryModelImpl {
73
59
  prepareResultOptions !== null && prepareResultOptions !== void 0 ? prepareResultOptions : (prepareResultOptions = {});
74
60
  if (typeof structRef === 'string') {
75
61
  const ret = this.getStructByName(structRef);
76
- if (sourceArguments !== undefined) {
77
- return new query_node_1.QueryStruct(ret.structDef, sourceArguments, ret.parent ? { struct: ret.parent } : { model: this }, prepareResultOptions);
78
- }
79
- return ret;
62
+ return new query_node_1.QueryStruct(ret.structDef, sourceArguments !== null && sourceArguments !== void 0 ? sourceArguments : ret.sourceArguments, ret.parent ? { struct: ret.parent } : { model: this }, prepareResultOptions);
80
63
  }
81
64
  return new query_node_1.QueryStruct(structRef, sourceArguments, { model: this }, prepareResultOptions);
82
65
  }
@@ -103,7 +86,7 @@ class QueryModelImpl {
103
86
  if (emitFinalStage && q.parent.dialect.hasFinalStage) {
104
87
  // const fieldNames: string[] = [];
105
88
  // for (const f of ret.outputStruct.fields) {
106
- // fieldNames.push(getIdentifier(f));
89
+ // fieldNames.push(activeName(f));
107
90
  // }
108
91
  const fieldNames = [];
109
92
  for (const f of ret.outputStruct.fields) {
@@ -156,9 +139,7 @@ class QueryModelImpl {
156
139
  const addedDefaultRowLimit = addDefaultRowLimit.addedDefaultRowLimit;
157
140
  const ret = this.loadQuery(query, undefined, prepareResultOptions, finalize, false);
158
141
  const structRef = (_a = query.compositeResolvedSourceDef) !== null && _a !== void 0 ? _a : query.structRef;
159
- const sourceExplore = typeof structRef === 'string'
160
- ? structRef
161
- : structRef.as || structRef.name;
142
+ const sourceExplore = typeof structRef === 'string' ? structRef : (0, malloy_types_1.activeName)(structRef);
162
143
  const sourceArguments = (_b = query.sourceArguments) !== null && _b !== void 0 ? _b : (typeof structRef === 'string' ? undefined : structRef.arguments);
163
144
  // LTNote: I don't understand why this might be here. It should have happened in loadQuery...
164
145
  if (finalize && this.dialect.hasFinalStage) {
@@ -1,6 +1,5 @@
1
- import type { FieldDef, BooleanFieldDef, DateFieldDef, DocumentLocation, StringFieldDef, JSONFieldDef, NumberFieldDef, ATimestampFieldDef, NativeUnsupportedFieldDef, JoinFieldDef, Argument, Given, GivenID, PrepareResultOptions, AtomicFieldDef, BasicAtomicDef, FilterCondition, RefToField, StructDef, TurtleDef, TurtleDefPlusFilters, SourceDef, Query } from './malloy_types';
1
+ import type { FieldDef, BooleanFieldDef, DateFieldDef, DocumentLocation, StringFieldDef, JSONFieldDef, NumberFieldDef, ATimestampFieldDef, NativeUnsupportedFieldDef, JoinFieldDef, Argument, Given, GivenID, PrepareResultOptions, AtomicFieldDef, BasicAtomicDef, FilterCondition, RefToField, StructDef, TurtleDef, TurtleDefPlusFilters } from './malloy_types';
2
2
  import type { EventStream } from '../runtime_types';
3
- import type { Tag } from '@malloydata/malloy-tag';
4
3
  import type { Dialect } from '../dialect';
5
4
  declare abstract class QueryNode {
6
5
  readonly referenceId: string;
@@ -91,8 +90,6 @@ export declare class QueryStruct {
91
90
  constructor(structDef: StructDef, sourceArguments: Record<string, Argument> | undefined, parent: ParentQueryStruct | ParentQueryModel, prepareResultOptions: PrepareResultOptions);
92
91
  private static turtleFieldMaker;
93
92
  static registerTurtleFieldMaker(maker: (field: TurtleDef, parent: QueryStruct) => QueryField): void;
94
- private _modelTag;
95
- modelCompilerFlags(): Tag;
96
93
  protected findFirstDialect(): string;
97
94
  maybeEmitParameterizedSourceUsage(): void;
98
95
  private resolveParentParameterReferences;
@@ -109,15 +106,6 @@ export declare class QueryStruct {
109
106
  addFieldToNameMap(as: string, n: QueryField, at?: DocumentLocation): void;
110
107
  /** the the primary key or throw an error. */
111
108
  getPrimaryKeyField(fieldDef: FieldDef): QueryBasicField;
112
- /**
113
- * called after all structure has been loaded. Examine this structure to see
114
- * if if it is based on a query and if it is, add the output fields (unless
115
- * they exist) to the structure.
116
- *
117
- * finalOutputStruct exists so that query_node doesn't need to
118
- * to import query_query
119
- */
120
- resolveQueryFields(finalOutputStruct: (query: Query, options: PrepareResultOptions | undefined) => SourceDef | undefined): void;
121
109
  getModel(): ModelRootInterface;
122
110
  get eventStream(): EventStream | undefined;
123
111
  /** makes a new queryable field object from a fieldDef */
@@ -14,7 +14,6 @@ exports.isBasicScalar = isBasicScalar;
14
14
  const uuid_1 = require("uuid");
15
15
  const malloy_compile_error_1 = require("./malloy_compile_error");
16
16
  const malloy_types_1 = require("./malloy_types");
17
- const annotation_1 = require("../api/foundation/annotation");
18
17
  const dialect_1 = require("../dialect");
19
18
  const utils_1 = require("./utils");
20
19
  class QueryNode {
@@ -33,7 +32,7 @@ class QueryField extends QueryNode {
33
32
  this.fieldDef = fieldDef;
34
33
  }
35
34
  getIdentifier() {
36
- return (0, malloy_types_1.getIdentifier)(this.fieldDef);
35
+ return (0, malloy_types_1.activeName)(this.fieldDef);
37
36
  }
38
37
  getJoinableParent() {
39
38
  const parent = this.parent;
@@ -179,7 +178,6 @@ class QueryStruct {
179
178
  this.sourceArguments = sourceArguments;
180
179
  this.prepareResultOptions = prepareResultOptions;
181
180
  this.nameMap = new Map();
182
- this._modelTag = undefined;
183
181
  this._arguments = undefined;
184
182
  if ('model' in parent) {
185
183
  this.model = parent.model;
@@ -203,14 +201,6 @@ class QueryStruct {
203
201
  static registerTurtleFieldMaker(maker) {
204
202
  QueryStruct.turtleFieldMaker = maker;
205
203
  }
206
- modelCompilerFlags() {
207
- if (this._modelTag === undefined) {
208
- const annotation = this.structDef.modelAnnotations;
209
- const { tag } = new annotation_1.Annotations(annotation).parseAsTag('!');
210
- this._modelTag = tag;
211
- }
212
- return this._modelTag;
213
- }
214
204
  findFirstDialect() {
215
205
  if ((0, malloy_types_1.isSourceDef)(this.structDef)) {
216
206
  return this.structDef.dialect;
@@ -281,7 +271,7 @@ class QueryStruct {
281
271
  }
282
272
  addFieldsFromFieldList(fields) {
283
273
  for (const field of fields) {
284
- const as = (0, malloy_types_1.getIdentifier)(field);
274
+ const as = (0, malloy_types_1.activeName)(field);
285
275
  if (field.type === 'turtle') {
286
276
  if (!QueryStruct.turtleFieldMaker) {
287
277
  throw new Error('INTERNAL ERROR: QueryQuery must initialize QueryStruct nested factory method');
@@ -313,7 +303,7 @@ class QueryStruct {
313
303
  // make a unique alias name
314
304
  if (ret === undefined) {
315
305
  const aliases = Array.from(this.pathAliasMap.values());
316
- const base = identifierNormalize((0, malloy_types_1.getIdentifier)(this.structDef));
306
+ const base = identifierNormalize((0, malloy_types_1.activeName)(this.structDef));
317
307
  let name = `${base}_0`;
318
308
  let n = 1;
319
309
  while (aliases.includes(name) && n < 1000) {
@@ -338,7 +328,7 @@ class QueryStruct {
338
328
  if (this.unnestWithNumbers() && this.parent !== undefined) {
339
329
  const x = this.parent.getSQLIdentifier() +
340
330
  '.' +
341
- (0, malloy_types_1.getIdentifier)(this.structDef) +
331
+ (0, malloy_types_1.activeName)(this.structDef) +
342
332
  `[${this.getIdentifier()}.__row_id]`;
343
333
  return x;
344
334
  }
@@ -386,7 +376,7 @@ class QueryStruct {
386
376
  }
387
377
  // if this is an inline object, include the parents alias.
388
378
  if (this.structDef.type === 'record' && this.parent) {
389
- return this.parent.sqlSimpleChildReference((0, malloy_types_1.getIdentifier)(this.structDef));
379
+ return this.parent.sqlSimpleChildReference((0, malloy_types_1.activeName)(this.structDef));
390
380
  }
391
381
  // we are somewhere in the join tree. Make sure the alias is unique.
392
382
  return this.getAliasIdentifier();
@@ -394,7 +384,7 @@ class QueryStruct {
394
384
  // return the name of the field in Malloy
395
385
  getFullOutputName() {
396
386
  if (this.parent) {
397
- return (this.parent.getFullOutputName() + (0, malloy_types_1.getIdentifier)(this.structDef) + '.');
387
+ return this.parent.getFullOutputName() + (0, malloy_types_1.activeName)(this.structDef) + '.';
398
388
  }
399
389
  else {
400
390
  return '';
@@ -428,45 +418,11 @@ class QueryStruct {
428
418
  return pk;
429
419
  }
430
420
  else {
431
- throw new malloy_compile_error_1.MalloyCompileError(`Source '${(0, malloy_types_1.getIdentifier)(this.structDef)}' has no primary key; ` +
432
- `cannot compute a unique key for field '${(0, malloy_types_1.getIdentifier)(fieldDef)}'. ` +
421
+ throw new malloy_compile_error_1.MalloyCompileError(`Source '${(0, malloy_types_1.activeName)(this.structDef)}' has no primary key; ` +
422
+ `cannot compute a unique key for field '${(0, malloy_types_1.activeName)(fieldDef)}'. ` +
433
423
  'Add `primary_key: <field>` to the source definition.', 'compiler-missing-primary-key', fieldDef.location);
434
424
  }
435
425
  }
436
- /**
437
- * called after all structure has been loaded. Examine this structure to see
438
- * if if it is based on a query and if it is, add the output fields (unless
439
- * they exist) to the structure.
440
- *
441
- * finalOutputStruct exists so that query_node doesn't need to
442
- * to import query_query
443
- */
444
- resolveQueryFields(finalOutputStruct) {
445
- if (this.structDef.type === 'query_source' && finalOutputStruct) {
446
- const resultStruct = finalOutputStruct(this.structDef.query, this.prepareResultOptions);
447
- // should never happen.
448
- if (!resultStruct) {
449
- throw new Error("Internal Error, query didn't produce a struct");
450
- }
451
- const structDef = { ...this.structDef };
452
- for (const f of resultStruct.fields) {
453
- const as = (0, malloy_types_1.getIdentifier)(f);
454
- if (!this.nameMap.has(as)) {
455
- structDef.fields.push(f);
456
- this.nameMap.set(as, this.makeQueryField(f));
457
- }
458
- }
459
- this.structDef = structDef;
460
- if (!this.structDef.primaryKey && resultStruct.primaryKey) {
461
- this.structDef.primaryKey = resultStruct.primaryKey;
462
- }
463
- }
464
- for (const [, v] of this.nameMap) {
465
- if (v instanceof QueryFieldStruct) {
466
- v.queryStruct.resolveQueryFields(finalOutputStruct);
467
- }
468
- }
469
- }
470
426
  getModel() {
471
427
  if (this.model) {
472
428
  return this.model;