@malloydata/malloy 0.0.404 → 0.0.406
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.
- package/LICENSE +77 -0
- package/dist/api/asynchronous.js +2 -4
- package/dist/api/connection.js +2 -4
- package/dist/api/core.js +5 -6
- package/dist/api/foundation/annotation.js +3 -11
- package/dist/api/foundation/compile.js +15 -8
- package/dist/api/foundation/core.d.ts +44 -6
- package/dist/api/foundation/core.js +106 -31
- package/dist/api/foundation/runtime.js +9 -19
- package/dist/api/foundation/taggable.d.ts +5 -0
- package/dist/api/foundation/types.d.ts +15 -0
- package/dist/api/index.js +4 -6
- package/dist/api/sessioned.js +2 -4
- package/dist/api/stateless.js +2 -4
- package/dist/api/util.js +2 -4
- package/dist/connection/base_connection.js +2 -4
- package/dist/connection/types.d.ts +1 -3
- package/dist/connection_utils.js +2 -20
- package/dist/dialect/dialect.js +2 -20
- package/dist/dialect/dialect_map.js +2 -20
- package/dist/dialect/duckdb/dialect_functions.js +2 -4
- package/dist/dialect/duckdb/duckdb.js +2 -20
- package/dist/dialect/duckdb/function_overrides.js +2 -4
- package/dist/dialect/duckdb/index.js +2 -20
- package/dist/dialect/duckdb/table-path-parser.js +4 -4
- package/dist/dialect/functions/index.js +2 -20
- package/dist/dialect/functions/malloy_standard_functions.js +2 -4
- package/dist/dialect/functions/util.js +2 -21
- package/dist/dialect/index.js +2 -20
- package/dist/dialect/mysql/dialect_functions.js +2 -4
- package/dist/dialect/mysql/function_overrides.js +2 -4
- package/dist/dialect/mysql/index.js +2 -4
- package/dist/dialect/mysql/mysql.js +2 -20
- package/dist/dialect/pg_impl.js +2 -4
- package/dist/dialect/postgres/dialect_functions.js +2 -4
- package/dist/dialect/postgres/function_overrides.js +2 -4
- package/dist/dialect/postgres/index.js +2 -20
- package/dist/dialect/postgres/postgres.js +2 -20
- package/dist/dialect/snowflake/dialect_functions.js +2 -4
- package/dist/dialect/snowflake/function_overrides.js +2 -4
- package/dist/dialect/snowflake/index.js +2 -20
- package/dist/dialect/snowflake/snowflake.js +2 -20
- package/dist/dialect/standardsql/dialect_functions.js +2 -4
- package/dist/dialect/standardsql/function_overrides.js +2 -4
- package/dist/dialect/standardsql/index.js +2 -20
- package/dist/dialect/standardsql/standardsql.js +2 -20
- package/dist/dialect/tiny_parser.js +2 -4
- package/dist/dialect/trino/dialect_functions.js +2 -4
- package/dist/dialect/trino/function_overrides.js +2 -4
- package/dist/dialect/trino/index.js +2 -20
- package/dist/dialect/trino/trino.js +2 -20
- package/dist/index.js +4 -22
- package/dist/lang/ast/ast-utils.js +2 -20
- package/dist/lang/ast/error-factory.js +2 -20
- package/dist/lang/ast/expressions/apply.js +2 -20
- package/dist/lang/ast/expressions/binary-boolean.js +2 -20
- package/dist/lang/ast/expressions/binary-numeric.js +2 -20
- package/dist/lang/ast/expressions/boolean.js +2 -20
- package/dist/lang/ast/expressions/case.js +2 -4
- package/dist/lang/ast/expressions/constant-expression.js +2 -20
- package/dist/lang/ast/expressions/expr-add-sub.js +2 -20
- package/dist/lang/ast/expressions/expr-aggregate-function.js +2 -20
- package/dist/lang/ast/expressions/expr-alternation-tree.js +2 -20
- package/dist/lang/ast/expressions/expr-array-literal.js +2 -4
- package/dist/lang/ast/expressions/expr-asymmetric.js +2 -20
- package/dist/lang/ast/expressions/expr-avg.js +2 -20
- package/dist/lang/ast/expressions/expr-cast.js +2 -20
- package/dist/lang/ast/expressions/expr-coalesce.js +2 -20
- package/dist/lang/ast/expressions/expr-compare.js +2 -20
- package/dist/lang/ast/expressions/expr-count-distinct.js +2 -20
- package/dist/lang/ast/expressions/expr-count.js +2 -20
- package/dist/lang/ast/expressions/expr-filter-expr.js +2 -4
- package/dist/lang/ast/expressions/expr-func.js +2 -20
- package/dist/lang/ast/expressions/expr-granular-time.js +2 -20
- package/dist/lang/ast/expressions/expr-id-reference.js +2 -20
- package/dist/lang/ast/expressions/expr-logical-op.js +2 -20
- package/dist/lang/ast/expressions/expr-max.js +2 -20
- package/dist/lang/ast/expressions/expr-min.js +2 -20
- package/dist/lang/ast/expressions/expr-minus.js +2 -20
- package/dist/lang/ast/expressions/expr-mul-div.js +2 -20
- package/dist/lang/ast/expressions/expr-not.js +2 -20
- package/dist/lang/ast/expressions/expr-now.js +2 -20
- package/dist/lang/ast/expressions/expr-null.js +2 -20
- package/dist/lang/ast/expressions/expr-number.js +2 -20
- package/dist/lang/ast/expressions/expr-parens.js +2 -20
- package/dist/lang/ast/expressions/expr-props.js +2 -20
- package/dist/lang/ast/expressions/expr-record-literal.js +2 -4
- package/dist/lang/ast/expressions/expr-regex.js +2 -20
- package/dist/lang/ast/expressions/expr-string.js +4 -0
- package/dist/lang/ast/expressions/expr-sum.js +2 -20
- package/dist/lang/ast/expressions/expr-time-extract.js +2 -20
- package/dist/lang/ast/expressions/expr-time.js +2 -20
- package/dist/lang/ast/expressions/expr-ungroup.js +2 -20
- package/dist/lang/ast/expressions/for-range.js +2 -20
- package/dist/lang/ast/expressions/function-ordering.js +2 -20
- package/dist/lang/ast/expressions/grouped_by.js +2 -4
- package/dist/lang/ast/expressions/partial-compare.js +2 -20
- package/dist/lang/ast/expressions/partition_by.js +2 -20
- package/dist/lang/ast/expressions/pick-when.js +2 -20
- package/dist/lang/ast/expressions/range.js +2 -20
- package/dist/lang/ast/expressions/time-frame.js +2 -20
- package/dist/lang/ast/expressions/time-literal.js +2 -20
- package/dist/lang/ast/expressions/unary.js +2 -20
- package/dist/lang/ast/field-space/ast-view-field.js +2 -20
- package/dist/lang/ast/field-space/column-space-field.js +2 -20
- package/dist/lang/ast/field-space/def-space.js +2 -4
- package/dist/lang/ast/field-space/dynamic-space.js +2 -20
- package/dist/lang/ast/field-space/include-utils.js +2 -4
- package/dist/lang/ast/field-space/index-field-space.js +2 -20
- package/dist/lang/ast/field-space/ir-view-field.js +2 -20
- package/dist/lang/ast/field-space/join-space-field.js +2 -20
- package/dist/lang/ast/field-space/parameter-space.js +2 -4
- package/dist/lang/ast/field-space/passthrough-space.js +2 -4
- package/dist/lang/ast/field-space/permissive-space.js +2 -4
- package/dist/lang/ast/field-space/project-field-space.js +2 -20
- package/dist/lang/ast/field-space/query-input-space.js +2 -20
- package/dist/lang/ast/field-space/query-spaces.js +2 -20
- package/dist/lang/ast/field-space/reference-field.js +5 -21
- package/dist/lang/ast/field-space/refine-from-space-field.js +2 -4
- package/dist/lang/ast/field-space/refined-space.js +2 -20
- package/dist/lang/ast/field-space/rename-space-field.js +2 -20
- package/dist/lang/ast/field-space/static-space.js +2 -20
- package/dist/lang/ast/field-space/struct-space-field-base.js +2 -20
- package/dist/lang/ast/field-space/view-field.js +2 -20
- package/dist/lang/ast/index.js +2 -20
- package/dist/lang/ast/parameters/argument.js +2 -4
- package/dist/lang/ast/parameters/has-parameter.js +2 -20
- package/dist/lang/ast/query-builders/index-builder.js +2 -20
- package/dist/lang/ast/query-builders/partial-builder.js +4 -0
- package/dist/lang/ast/query-builders/project-builder.js +2 -20
- package/dist/lang/ast/query-builders/reduce-builder.js +2 -20
- package/dist/lang/ast/query-elements/anonymous-query.js +3 -21
- package/dist/lang/ast/query-elements/query-arrow.js +2 -20
- package/dist/lang/ast/query-elements/query-base.js +2 -20
- package/dist/lang/ast/query-elements/query-head-struct.js +2 -20
- package/dist/lang/ast/query-elements/query-raw.js +2 -20
- package/dist/lang/ast/query-elements/query-reference.js +2 -20
- package/dist/lang/ast/query-elements/query-refine.js +2 -20
- package/dist/lang/ast/query-items/field-declaration.js +3 -21
- package/dist/lang/ast/query-items/field-references.js +2 -20
- package/dist/lang/ast/query-items/typecheck_utils.js +2 -20
- package/dist/lang/ast/query-properties/aggregate.js +2 -20
- package/dist/lang/ast/query-properties/calculate.js +2 -20
- package/dist/lang/ast/query-properties/declare-fields.js +2 -20
- package/dist/lang/ast/query-properties/drill.js +2 -4
- package/dist/lang/ast/query-properties/extend.js +2 -20
- package/dist/lang/ast/query-properties/filters.js +2 -20
- package/dist/lang/ast/query-properties/group-by.js +2 -20
- package/dist/lang/ast/query-properties/indexing.js +2 -20
- package/dist/lang/ast/query-properties/limit.js +2 -20
- package/dist/lang/ast/query-properties/nest.js +6 -21
- package/dist/lang/ast/query-properties/nests.js +2 -20
- package/dist/lang/ast/query-properties/ordering.js +2 -20
- package/dist/lang/ast/query-properties/project-statement.js +2 -20
- package/dist/lang/ast/query-properties/qop-desc.js +2 -20
- package/dist/lang/ast/query-properties/sampling.js +2 -20
- package/dist/lang/ast/query-utils.js +2 -20
- package/dist/lang/ast/source-elements/composite-source.js +2 -4
- package/dist/lang/ast/source-elements/named-source.js +2 -23
- package/dist/lang/ast/source-elements/query-source.js +2 -22
- package/dist/lang/ast/source-elements/refined-source.js +2 -22
- package/dist/lang/ast/source-elements/source.js +2 -20
- package/dist/lang/ast/source-elements/sql-source.js +2 -25
- package/dist/lang/ast/source-elements/table-source.js +3 -22
- package/dist/lang/ast/source-elements/virtual-source.js +1 -2
- package/dist/lang/ast/source-properties/dimensions.js +2 -20
- package/dist/lang/ast/source-properties/field-list-edit.js +2 -20
- package/dist/lang/ast/source-properties/join.js +4 -26
- package/dist/lang/ast/source-properties/measures.js +2 -20
- package/dist/lang/ast/source-properties/primary-key.js +2 -20
- package/dist/lang/ast/source-properties/renames.js +3 -21
- package/dist/lang/ast/source-properties/timezone-statement.js +2 -20
- package/dist/lang/ast/source-properties/user-type-shape.js +9 -4
- package/dist/lang/ast/source-properties/view-field-declaration.js +6 -21
- package/dist/lang/ast/source-properties/views.js +2 -20
- package/dist/lang/ast/source-query-elements/include-item.js +2 -4
- package/dist/lang/ast/source-query-elements/source-query-element.js +2 -20
- package/dist/lang/ast/source-query-elements/sq-arrow.js +2 -20
- package/dist/lang/ast/source-query-elements/sq-compose.js +2 -4
- package/dist/lang/ast/source-query-elements/sq-extend.js +2 -20
- package/dist/lang/ast/source-query-elements/sq-reference.js +2 -20
- package/dist/lang/ast/source-query-elements/sq-refine.js +2 -20
- package/dist/lang/ast/source-query-elements/sq-source.js +2 -20
- package/dist/lang/ast/sql-elements/sql-string.js +2 -20
- package/dist/lang/ast/statements/define-given.js +22 -2
- package/dist/lang/ast/statements/define-query.js +3 -21
- package/dist/lang/ast/statements/define-source.js +7 -22
- package/dist/lang/ast/statements/define-user-type.js +1 -1
- package/dist/lang/ast/statements/import-statement.js +7 -20
- package/dist/lang/ast/time-utils.js +2 -20
- package/dist/lang/ast/typedesc-utils.js +2 -20
- package/dist/lang/ast/types/annotation-elements.js +2 -20
- package/dist/lang/ast/types/binary_operators.js +2 -4
- package/dist/lang/ast/types/definition-list.js +2 -20
- package/dist/lang/ast/types/dialect-name-space.js +2 -4
- package/dist/lang/ast/types/document-compile-result.js +2 -20
- package/dist/lang/ast/types/expr-result.js +2 -20
- package/dist/lang/ast/types/expr-value.js +2 -20
- package/dist/lang/ast/types/expression-def.js +2 -20
- package/dist/lang/ast/types/field-collection-member.js +2 -20
- package/dist/lang/ast/types/field-prop-statement.js +2 -20
- package/dist/lang/ast/types/field-space.js +2 -20
- package/dist/lang/ast/types/global-name-space.js +2 -20
- package/dist/lang/ast/types/granular-result.js +2 -20
- package/dist/lang/ast/types/literal.d.ts +1 -1
- package/dist/lang/ast/types/literal.js +2 -4
- package/dist/lang/ast/types/lookup-result.js +2 -20
- package/dist/lang/ast/types/malloy-element.d.ts +27 -4
- package/dist/lang/ast/types/malloy-element.js +54 -70
- package/dist/lang/ast/types/model-entry.js +2 -20
- package/dist/lang/ast/types/name-space.js +2 -20
- package/dist/lang/ast/types/noteable.js +2 -20
- package/dist/lang/ast/types/op-desc.js +2 -20
- package/dist/lang/ast/types/pipeline-comp.js +2 -20
- package/dist/lang/ast/types/query-builder.js +2 -20
- package/dist/lang/ast/types/query-comp.js +2 -20
- package/dist/lang/ast/types/query-element.js +2 -20
- package/dist/lang/ast/types/query-extend-property.js +2 -20
- package/dist/lang/ast/types/query-item.js +2 -20
- package/dist/lang/ast/types/query-property-interface.js +2 -20
- package/dist/lang/ast/types/query-property.js +2 -20
- package/dist/lang/ast/types/source-desc.js +2 -20
- package/dist/lang/ast/types/source-property.js +2 -20
- package/dist/lang/ast/types/space-entry.js +2 -20
- package/dist/lang/ast/types/space-field.js +2 -20
- package/dist/lang/ast/types/space-param.js +2 -20
- package/dist/lang/ast/types/time-result.js +2 -20
- package/dist/lang/ast/view-elements/qop-desc-view.js +2 -20
- package/dist/lang/ast/view-elements/reference-view.js +2 -20
- package/dist/lang/ast/view-elements/refine-utils.js +2 -20
- package/dist/lang/ast/view-elements/view-arrow.js +2 -20
- package/dist/lang/ast/view-elements/view-refine.js +2 -20
- package/dist/lang/ast/view-elements/view.js +2 -20
- package/dist/lang/composite-source-utils.js +2 -4
- package/dist/lang/field-utils.js +2 -20
- package/dist/lang/index.js +2 -20
- package/dist/lang/malloy-parse-info.js +2 -20
- package/dist/lang/malloy-to-ast.d.ts +1 -1
- package/dist/lang/malloy-to-ast.js +2 -21
- package/dist/lang/malloy-to-stable-query.js +2 -4
- package/dist/lang/parse-log.d.ts +5 -0
- package/dist/lang/parse-log.js +3 -20
- package/dist/lang/parse-malloy.d.ts +1 -9
- package/dist/lang/parse-malloy.js +33 -83
- package/dist/lang/parse-tree-walkers/document-completion-walker.js +2 -20
- package/dist/lang/parse-tree-walkers/document-help-context-walker.js +2 -20
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +2 -20
- package/dist/lang/parse-tree-walkers/explore-query-walker.js +2 -20
- package/dist/lang/parse-tree-walkers/find-external-references.js +2 -20
- package/dist/lang/parse-tree-walkers/find-table-path-walker.js +2 -20
- package/dist/lang/parse-utils.js +2 -20
- package/dist/lang/reference-list.js +2 -20
- package/dist/lang/run-malloy-parser.js +2 -4
- package/dist/lang/syntax-errors/custom-error-messages.js +2 -4
- package/dist/lang/syntax-errors/malloy-error-strategy.js +2 -4
- package/dist/lang/syntax-errors/malloy-parser-error-listener.js +2 -4
- package/dist/lang/test/expr-to-str.js +2 -4
- package/dist/lang/test/parse-expects.js +2 -20
- package/dist/lang/test/test-translator.js +4 -25
- package/dist/lang/translate-response.d.ts +1 -5
- package/dist/lang/translate-response.js +2 -20
- package/dist/lang/utils.js +2 -20
- package/dist/lang/zone.js +2 -20
- package/dist/model/annotation_utils.d.ts +37 -0
- package/dist/model/annotation_utils.js +85 -0
- package/dist/model/expression_compiler.js +5 -7
- package/dist/model/filter_compilers.js +2 -4
- package/dist/model/given_binding.d.ts +16 -4
- package/dist/model/given_binding.js +30 -4
- package/dist/model/index.d.ts +2 -1
- package/dist/model/index.js +6 -21
- package/dist/model/inline_expr.d.ts +10 -4
- package/dist/model/inline_expr.js +24 -26
- package/dist/model/malloy_types.d.ts +36 -7
- package/dist/model/malloy_types.js +2 -21
- package/dist/model/query_node.d.ts +0 -3
- package/dist/model/query_node.js +0 -10
- package/dist/model/query_query.js +2 -16
- package/dist/model/source_def_utils.js +0 -2
- package/dist/model/sql_block.js +2 -20
- package/dist/model/utils.d.ts +9 -2
- package/dist/model/utils.js +15 -21
- package/dist/run_sql_options.d.ts +0 -5
- package/dist/run_sql_options.js +2 -20
- package/dist/runtime_types.js +2 -20
- package/dist/test/cellsToObject.js +2 -4
- package/dist/timing.js +2 -4
- package/dist/to_stable.js +2 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/dist/lang/parse-tree-walkers/model-annotation-walker.d.ts +0 -5
- package/dist/lang/parse-tree-walkers/model-annotation-walker.js +0 -50
package/dist/lang/zone.js
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright
|
|
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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
7
|
exports.Zone = void 0;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AnnotationsDef, ModelDef, ModelID, Note } from './malloy_types';
|
|
2
|
+
/**
|
|
3
|
+
* Every Note of an annotation bundle, inherited first, in document order
|
|
4
|
+
* (`inherits` → `blockNotes` → `notes`). Later notes win when re-parsed.
|
|
5
|
+
*
|
|
6
|
+
* Internal helper — not part of the public `model` barrel. The public way to
|
|
7
|
+
* read notes is the `Annotations` view (`api/foundation/annotation.ts`), which
|
|
8
|
+
* uses this; the model-annotation fold below uses it too.
|
|
9
|
+
*/
|
|
10
|
+
export declare function notesInOrder(annote: AnnotationsDef): Generator<Note>;
|
|
11
|
+
/**
|
|
12
|
+
* The model (`##`) annotations for one model, compiled by walking the
|
|
13
|
+
* annotation-provenance tree: a model's own `##` together with everything it
|
|
14
|
+
* imports/extends, folded down the lineage into a single ordered bundle.
|
|
15
|
+
*
|
|
16
|
+
* `modelID` defaults to `model.modelID` — the common case, "the annotations
|
|
17
|
+
* this model presents." `##` is model-level, so every object resolved in the
|
|
18
|
+
* model reports this same one bundle (resolution takes no object). Pass an
|
|
19
|
+
* explicit `modelID` to compile the bundle for any other model in the closure.
|
|
20
|
+
*
|
|
21
|
+
* Mechanism: a post-order DFS over each model's `inheritsFrom` edges
|
|
22
|
+
* (extend-base is `import₀`, sitting first) emits a model only after its
|
|
23
|
+
* predecessors and only once (its most-ancestral slot); back-edges are skipped,
|
|
24
|
+
* so the walk terminates on a cycle. The result is ordered imports-first /
|
|
25
|
+
* local-last — a consumer that takes "last wins" sees the target model's own
|
|
26
|
+
* `##` win — and is returned as an {@link AnnotationsDef} whose `inherits` chain
|
|
27
|
+
* *is* that order (target at the top, most-ancestral import deepest), so the
|
|
28
|
+
* `Annotations` view / {@link notesInOrder} consume it with no new code.
|
|
29
|
+
*
|
|
30
|
+
* A target with no entry contributes nothing (empty) — the honest answer for a
|
|
31
|
+
* synthetic or detached `ModelDef` (built via `mkModelDef`, a `pseudoModelFor`
|
|
32
|
+
* struct, a model with no `##` anywhere) that never recorded a self-entry. But
|
|
33
|
+
* a recorded `inheritsFrom` *edge* to a model with no entry is corruption —
|
|
34
|
+
* population kept the edge but lost the target — and throws a compiler-bug-class
|
|
35
|
+
* error: the one place that needs the entry is the one place that detects it.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getModelAnnotations(model: ModelDef, modelID?: ModelID): AnnotationsDef;
|
|
@@ -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
|
|
@@ -30,6 +30,7 @@ const filter_compilers_1 = require("./filter_compilers");
|
|
|
30
30
|
const utils_1 = require("./utils");
|
|
31
31
|
const query_node_1 = require("./query_node");
|
|
32
32
|
const malloy_compile_error_1 = require("./malloy_compile_error");
|
|
33
|
+
const given_binding_1 = require("./given_binding");
|
|
33
34
|
const NUMERIC_DECIMAL_PRECISION = 9;
|
|
34
35
|
function sqlSumDistinct(dialect, sqlExp, sqlDistintKey) {
|
|
35
36
|
const precision = 9;
|
|
@@ -628,13 +629,10 @@ function generateParameterFragment(resultSet, context, expr, state) {
|
|
|
628
629
|
* and the `'inGiven'` SQL-emit case ($ARR in `expr in $ARR`).
|
|
629
630
|
*/
|
|
630
631
|
function resolveGivenBoundExpr(context, ref) {
|
|
631
|
-
var _a
|
|
632
|
-
const
|
|
633
|
-
if (
|
|
634
|
-
return
|
|
635
|
-
const decl = context.getModel().givens[ref.id];
|
|
636
|
-
if ((decl === null || decl === void 0 ? void 0 : decl.default) !== undefined)
|
|
637
|
-
return decl.default;
|
|
632
|
+
var _a;
|
|
633
|
+
const value = (0, given_binding_1.lookupGivenValue)((_a = context.prepareResultOptions) === null || _a === void 0 ? void 0 : _a.resolvedGivens, context.getModel().givens, ref.id);
|
|
634
|
+
if (value !== undefined)
|
|
635
|
+
return value;
|
|
638
636
|
throw new malloy_compile_error_1.MalloyCompileError(unsatisfiedGivenMessage(ref.refName), 'compiler-given-no-value', ref.at);
|
|
639
637
|
}
|
|
640
638
|
function generateGivenFragment(resultSet, context, expr, state) {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright
|
|
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;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import type { Expr, GivenID, GivenValue, ModelDef } from './malloy_types';
|
|
1
|
+
import type { Expr, Given, GivenID, GivenValue, ModelDef } from './malloy_types';
|
|
2
|
+
/**
|
|
3
|
+
* The one definition of "what value does a given reference stand for":
|
|
4
|
+
* the caller-supplied value if one is bound, otherwise the declaration
|
|
5
|
+
* default. Returns undefined when neither exists — callers decide how to
|
|
6
|
+
* report that, since the right diagnostic differs by site (a bind-time
|
|
7
|
+
* inline fold vs. SQL emission). Shared by `evaluateInlineGivens` here
|
|
8
|
+
* and `resolveGivenBoundExpr` in the compiler.
|
|
9
|
+
*/
|
|
10
|
+
export declare function lookupGivenValue(bound: Map<GivenID, Expr> | undefined, givens: Record<GivenID, Given> | undefined, id: GivenID): Expr | undefined;
|
|
2
11
|
export declare function resolveSuppliedGivens(supplied: Record<string, GivenValue> | undefined, modelDef: ModelDef | undefined): Map<GivenID, Expr>;
|
|
3
12
|
/**
|
|
4
13
|
* Evaluate every `inline` given's default to a literal Expr and add it
|
|
@@ -10,8 +19,11 @@ export declare function resolveSuppliedGivens(supplied: Record<string, GivenValu
|
|
|
10
19
|
* `inline-no-default` error at declaration time.
|
|
11
20
|
*
|
|
12
21
|
* Iteration follows `modelDef.contents` insertion order, which (by
|
|
13
|
-
* Malloy's no-forward-refs rule) is also topological order
|
|
14
|
-
*
|
|
15
|
-
*
|
|
22
|
+
* Malloy's no-forward-refs rule) is also topological order. An inline
|
|
23
|
+
* default that references another inline given relies on this: the
|
|
24
|
+
* referenced one was declared first, so it is already folded into
|
|
25
|
+
* `bound` by the time this one reads it. A reference to a regular given
|
|
26
|
+
* resolves straight to its supplied value or declaration default (see
|
|
27
|
+
* `resolveGiven`), which needs no ordering.
|
|
16
28
|
*/
|
|
17
29
|
export declare function evaluateInlineGivens(bound: Map<GivenID, Expr>, modelDef: ModelDef | undefined): Map<GivenID, Expr>;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.lookupGivenValue = lookupGivenValue;
|
|
7
8
|
exports.resolveSuppliedGivens = resolveSuppliedGivens;
|
|
8
9
|
exports.evaluateInlineGivens = evaluateInlineGivens;
|
|
9
10
|
const luxon_1 = require("luxon");
|
|
@@ -11,6 +12,18 @@ const closest_match_1 = require("../util/closest_match");
|
|
|
11
12
|
const inline_expr_1 = require("./inline_expr");
|
|
12
13
|
const malloy_types_1 = require("./malloy_types");
|
|
13
14
|
const malloy_compile_error_1 = require("./malloy_compile_error");
|
|
15
|
+
/**
|
|
16
|
+
* The one definition of "what value does a given reference stand for":
|
|
17
|
+
* the caller-supplied value if one is bound, otherwise the declaration
|
|
18
|
+
* default. Returns undefined when neither exists — callers decide how to
|
|
19
|
+
* report that, since the right diagnostic differs by site (a bind-time
|
|
20
|
+
* inline fold vs. SQL emission). Shared by `evaluateInlineGivens` here
|
|
21
|
+
* and `resolveGivenBoundExpr` in the compiler.
|
|
22
|
+
*/
|
|
23
|
+
function lookupGivenValue(bound, givens, id) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
return (_a = bound === null || bound === void 0 ? void 0 : bound.get(id)) !== null && _a !== void 0 ? _a : (_b = givens === null || givens === void 0 ? void 0 : givens[id]) === null || _b === void 0 ? void 0 : _b.default;
|
|
26
|
+
}
|
|
14
27
|
function resolveSuppliedGivens(supplied, modelDef) {
|
|
15
28
|
var _a;
|
|
16
29
|
const out = new Map();
|
|
@@ -57,15 +70,28 @@ function resolveSuppliedGivens(supplied, modelDef) {
|
|
|
57
70
|
* `inline-no-default` error at declaration time.
|
|
58
71
|
*
|
|
59
72
|
* Iteration follows `modelDef.contents` insertion order, which (by
|
|
60
|
-
* Malloy's no-forward-refs rule) is also topological order
|
|
61
|
-
*
|
|
62
|
-
*
|
|
73
|
+
* Malloy's no-forward-refs rule) is also topological order. An inline
|
|
74
|
+
* default that references another inline given relies on this: the
|
|
75
|
+
* referenced one was declared first, so it is already folded into
|
|
76
|
+
* `bound` by the time this one reads it. A reference to a regular given
|
|
77
|
+
* resolves straight to its supplied value or declaration default (see
|
|
78
|
+
* `resolveGiven`), which needs no ordering.
|
|
63
79
|
*/
|
|
64
80
|
function evaluateInlineGivens(bound, modelDef) {
|
|
65
81
|
var _a;
|
|
66
82
|
if (!modelDef)
|
|
67
83
|
return bound;
|
|
68
84
|
const givens = (_a = modelDef.givens) !== null && _a !== void 0 ? _a : {};
|
|
85
|
+
// A `$REF` in an inline default resolves to its supplied value, else
|
|
86
|
+
// its declaration default; a reference with neither is a caller error.
|
|
87
|
+
// `bound` is read live, so a given folded earlier in the loop is
|
|
88
|
+
// visible to one folded later.
|
|
89
|
+
const resolveGiven = (id, refName) => {
|
|
90
|
+
const v = lookupGivenValue(bound, givens, id);
|
|
91
|
+
if (v !== undefined)
|
|
92
|
+
return v;
|
|
93
|
+
throw new malloy_compile_error_1.MalloyCompileError(`Inline given depends on '${refName}', which has no supplied value and no default. Supply a value for '${refName}' or give it a declaration default.`, 'runtime-given-unsatisfied-inline', undefined);
|
|
94
|
+
};
|
|
69
95
|
for (const [, entry] of Object.entries(modelDef.contents)) {
|
|
70
96
|
if (entry.type !== 'given')
|
|
71
97
|
continue;
|
|
@@ -76,7 +102,7 @@ function evaluateInlineGivens(bound, modelDef) {
|
|
|
76
102
|
continue;
|
|
77
103
|
if (decl.default === undefined)
|
|
78
104
|
continue;
|
|
79
|
-
bound.set(entry.id, (0, inline_expr_1.inlineExpr)(decl.default,
|
|
105
|
+
bound.set(entry.id, (0, inline_expr_1.inlineExpr)(decl.default, resolveGiven));
|
|
80
106
|
}
|
|
81
107
|
return bound;
|
|
82
108
|
}
|
package/dist/model/index.d.ts
CHANGED
|
@@ -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';
|
package/dist/model/index.js
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright
|
|
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");
|
|
@@ -18,13 +18,19 @@ export declare const INLINE_OPS: ReadonlySet<string>;
|
|
|
18
18
|
*/
|
|
19
19
|
export declare const INLINE_LEAVES: ReadonlySet<string>;
|
|
20
20
|
/**
|
|
21
|
-
* Bind-time evaluator for `inline` given defaults. Walks the Expr tree
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* Bind-time evaluator for `inline` given defaults. Walks the Expr tree
|
|
22
|
+
* and returns a literal Expr (string/number/boolean/null/arrayLiteral).
|
|
23
|
+
*
|
|
24
|
+
* A pure folder: it does not know how given references get their values.
|
|
25
|
+
* `resolveGiven` is handed a given reference's id and surface name (both
|
|
26
|
+
* a `$NAME` ref and the array of an `expr in $NAME`) and returns the Expr
|
|
27
|
+
* that reference stands for — caller-supplied value, declaration default,
|
|
28
|
+
* or a thrown error if neither. That policy lives with the caller
|
|
29
|
+
* (`given_binding.ts`), not here — see `lookupGivenValue`.
|
|
24
30
|
*
|
|
25
31
|
* Throws on any node outside `INLINE_OPS ∪ INLINE_LEAVES`. The
|
|
26
32
|
* translator's pre-flight check should have rejected such defaults
|
|
27
33
|
* already, so a throw here flags a compiler bug rather than a caller
|
|
28
34
|
* error.
|
|
29
35
|
*/
|
|
30
|
-
export declare function inlineExpr(e: Expr,
|
|
36
|
+
export declare function inlineExpr(e: Expr, resolveGiven: (id: GivenID, refName: string) => Expr): Expr;
|
|
@@ -45,16 +45,22 @@ exports.INLINE_LEAVES = new Set([
|
|
|
45
45
|
'given',
|
|
46
46
|
]);
|
|
47
47
|
/**
|
|
48
|
-
* Bind-time evaluator for `inline` given defaults. Walks the Expr tree
|
|
49
|
-
*
|
|
50
|
-
*
|
|
48
|
+
* Bind-time evaluator for `inline` given defaults. Walks the Expr tree
|
|
49
|
+
* and returns a literal Expr (string/number/boolean/null/arrayLiteral).
|
|
50
|
+
*
|
|
51
|
+
* A pure folder: it does not know how given references get their values.
|
|
52
|
+
* `resolveGiven` is handed a given reference's id and surface name (both
|
|
53
|
+
* a `$NAME` ref and the array of an `expr in $NAME`) and returns the Expr
|
|
54
|
+
* that reference stands for — caller-supplied value, declaration default,
|
|
55
|
+
* or a thrown error if neither. That policy lives with the caller
|
|
56
|
+
* (`given_binding.ts`), not here — see `lookupGivenValue`.
|
|
51
57
|
*
|
|
52
58
|
* Throws on any node outside `INLINE_OPS ∪ INLINE_LEAVES`. The
|
|
53
59
|
* translator's pre-flight check should have rejected such defaults
|
|
54
60
|
* already, so a throw here flags a compiler bug rather than a caller
|
|
55
61
|
* error.
|
|
56
62
|
*/
|
|
57
|
-
function inlineExpr(e,
|
|
63
|
+
function inlineExpr(e, resolveGiven) {
|
|
58
64
|
switch (e.node) {
|
|
59
65
|
case 'stringLiteral':
|
|
60
66
|
case 'numberLiteral':
|
|
@@ -63,23 +69,18 @@ function inlineExpr(e, bound) {
|
|
|
63
69
|
case 'null':
|
|
64
70
|
case 'arrayLiteral':
|
|
65
71
|
return e;
|
|
66
|
-
case 'given':
|
|
67
|
-
|
|
68
|
-
if (v === undefined) {
|
|
69
|
-
throw new Error(`inlineExpr: given '${e.refName}' has no bound value and no default — translator should have caught this earlier`);
|
|
70
|
-
}
|
|
71
|
-
return inlineExpr(v, bound);
|
|
72
|
-
}
|
|
72
|
+
case 'given':
|
|
73
|
+
return inlineExpr(resolveGiven(e.id, e.refName), resolveGiven);
|
|
73
74
|
case '()':
|
|
74
|
-
return inlineExpr(e.e,
|
|
75
|
+
return inlineExpr(e.e, resolveGiven);
|
|
75
76
|
case 'not': {
|
|
76
|
-
const inner = inlineExpr(e.e,
|
|
77
|
+
const inner = inlineExpr(e.e, resolveGiven);
|
|
77
78
|
return toBoolLiteral(!exprAsBool(inner));
|
|
78
79
|
}
|
|
79
80
|
case 'and':
|
|
80
81
|
case 'or': {
|
|
81
|
-
const left = exprAsBool(inlineExpr(e.kids.left,
|
|
82
|
-
const right = exprAsBool(inlineExpr(e.kids.right,
|
|
82
|
+
const left = exprAsBool(inlineExpr(e.kids.left, resolveGiven));
|
|
83
|
+
const right = exprAsBool(inlineExpr(e.kids.right, resolveGiven));
|
|
83
84
|
return toBoolLiteral(e.node === 'and' ? left && right : left || right);
|
|
84
85
|
}
|
|
85
86
|
case '=':
|
|
@@ -88,23 +89,20 @@ function inlineExpr(e, bound) {
|
|
|
88
89
|
case '<':
|
|
89
90
|
case '>=':
|
|
90
91
|
case '<=': {
|
|
91
|
-
const left = inlineExpr(e.kids.left,
|
|
92
|
-
const right = inlineExpr(e.kids.right,
|
|
92
|
+
const left = inlineExpr(e.kids.left, resolveGiven);
|
|
93
|
+
const right = inlineExpr(e.kids.right, resolveGiven);
|
|
93
94
|
return toBoolLiteral(compareLiterals(e.node, left, right));
|
|
94
95
|
}
|
|
95
96
|
case 'inGiven': {
|
|
96
|
-
const lhs = inlineExpr(e.e,
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
throw new Error(`inlineExpr: given '${e.givenRef.refName}' has no bound value and no default — translator should have caught this earlier`);
|
|
100
|
-
}
|
|
101
|
-
if (arrBound.node === 'null') {
|
|
97
|
+
const lhs = inlineExpr(e.e, resolveGiven);
|
|
98
|
+
const arr = inlineExpr(resolveGiven(e.givenRef.id, e.givenRef.refName), resolveGiven);
|
|
99
|
+
if (arr.node === 'null') {
|
|
102
100
|
return toBoolLiteral(e.not);
|
|
103
101
|
}
|
|
104
|
-
if (
|
|
105
|
-
throw new Error(`inlineExpr: 'inGiven'
|
|
102
|
+
if (arr.node !== 'arrayLiteral') {
|
|
103
|
+
throw new Error(`inlineExpr: 'inGiven' resolved to '${arr.node}', expected 'arrayLiteral'`);
|
|
106
104
|
}
|
|
107
|
-
const found =
|
|
105
|
+
const found = arr.kids.values.some(v => compareLiterals('=', lhs, inlineExpr(v, resolveGiven)));
|
|
108
106
|
return toBoolLiteral(e.not ? !found : found);
|
|
109
107
|
}
|
|
110
108
|
default:
|
|
@@ -671,7 +671,6 @@ export interface Query extends Pipeline, Filtered {
|
|
|
671
671
|
name?: string;
|
|
672
672
|
structRef: StructRef;
|
|
673
673
|
sourceArguments?: SafeRecord<Argument>;
|
|
674
|
-
modelAnnotations?: AnnotationsDef;
|
|
675
674
|
compositeResolvedSourceDef?: SourceDef;
|
|
676
675
|
givenUsage?: GivenUsage;
|
|
677
676
|
}
|
|
@@ -839,7 +838,6 @@ export interface TurtleDefPlusFilters extends TurtleDef, Filtered {
|
|
|
839
838
|
}
|
|
840
839
|
interface StructDefBase extends HasLocation, NamedObject, HasAnnotations {
|
|
841
840
|
type: string;
|
|
842
|
-
modelAnnotations?: ModelAnnotationsDef;
|
|
843
841
|
fields: FieldDef[];
|
|
844
842
|
/** Marker for error placeholder structs created by ErrorFactory */
|
|
845
843
|
errorFactory?: boolean;
|
|
@@ -886,6 +884,13 @@ export type SourceID = string;
|
|
|
886
884
|
export type GivenID = string;
|
|
887
885
|
/** Hash of (connectionDigest, sql) - uniquely identifies a built artifact */
|
|
888
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;
|
|
889
894
|
/**
|
|
890
895
|
* Reference to a source in modelDef.contents by name.
|
|
891
896
|
* Used in sourceRegistry to avoid duplicating SourceDefs that are in the namespace.
|
|
@@ -1115,6 +1120,7 @@ export interface DependencyTree {
|
|
|
1115
1120
|
/** Result of parsing a model file */
|
|
1116
1121
|
export interface ModelDef {
|
|
1117
1122
|
name: string;
|
|
1123
|
+
modelID: ModelID;
|
|
1118
1124
|
exports: string[];
|
|
1119
1125
|
contents: SafeRecord<NamedModelObject>;
|
|
1120
1126
|
/**
|
|
@@ -1125,7 +1131,17 @@ export interface ModelDef {
|
|
|
1125
1131
|
*/
|
|
1126
1132
|
sourceRegistry: Record<SourceID, SourceRegistryValue>;
|
|
1127
1133
|
givens?: Record<GivenID, Given>;
|
|
1128
|
-
|
|
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>;
|
|
1129
1145
|
queryList: Query[];
|
|
1130
1146
|
dependencies: DependencyTree;
|
|
1131
1147
|
references?: DocumentReference[];
|
|
@@ -1136,7 +1152,16 @@ export type NamedSourceDefs = SafeRecord<SourceDef>;
|
|
|
1136
1152
|
export type NamedModelObjects = SafeRecord<NamedModelObject>;
|
|
1137
1153
|
/** Bundle of source annotations attached to one object: the `notes` and
|
|
1138
1154
|
* `blockNotes` written on it, plus the bundle from the spiritual parent
|
|
1139
|
-
* 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. */
|
|
1140
1165
|
export interface AnnotationsDef {
|
|
1141
1166
|
inherits?: AnnotationsDef;
|
|
1142
1167
|
blockNotes?: Note[];
|
|
@@ -1155,9 +1180,13 @@ export interface Note {
|
|
|
1155
1180
|
*/
|
|
1156
1181
|
indentStripped?: number;
|
|
1157
1182
|
}
|
|
1158
|
-
/**
|
|
1159
|
-
|
|
1160
|
-
|
|
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[];
|
|
1161
1190
|
}
|
|
1162
1191
|
export type QueryScalar = string | boolean | number | bigint | Date | Buffer | null;
|
|
1163
1192
|
/** One value in one column of returned data. */
|
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright
|
|
4
|
-
*
|
|
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;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
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;
|
package/dist/model/query_node.js
CHANGED
|
@@ -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 {
|
|
@@ -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;
|