@malloydata/malloy 0.0.22-dev230126015148 → 0.0.22-dev230202171033
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/dist/lang/ast/ast-main.d.ts +18 -815
- package/dist/lang/ast/ast-main.js +106 -3241
- package/dist/lang/ast/ast-utils.d.ts +10 -0
- package/dist/lang/ast/ast-utils.js +42 -0
- package/dist/lang/ast/elements/define-explore.d.ts +17 -0
- package/dist/lang/ast/elements/define-explore.js +79 -0
- package/dist/lang/ast/elements/define-query.d.ts +14 -0
- package/dist/lang/ast/elements/define-query.js +56 -0
- package/dist/lang/ast/elements/mallobj.d.ts +12 -0
- package/dist/lang/ast/elements/mallobj.js +53 -0
- package/dist/lang/ast/elements/pipeline-desc.d.ts +28 -0
- package/dist/lang/ast/elements/pipeline-desc.js +102 -0
- package/dist/lang/ast/elements/refined-explore.d.ts +15 -0
- package/dist/lang/ast/elements/refined-explore.js +121 -0
- package/dist/lang/ast/error-factory.d.ts +9 -0
- package/dist/lang/ast/error-factory.js +61 -0
- package/dist/lang/ast/executors/index-executor.d.ts +18 -0
- package/dist/lang/ast/executors/index-executor.js +96 -0
- package/dist/lang/ast/executors/project-executor.d.ts +10 -0
- package/dist/lang/ast/executors/project-executor.js +68 -0
- package/dist/lang/ast/executors/reduce-executor.d.ts +20 -0
- package/dist/lang/ast/executors/reduce-executor.js +149 -0
- package/dist/lang/ast/explore-properties/field-list-edit.d.ts +8 -0
- package/dist/lang/ast/explore-properties/field-list-edit.js +36 -0
- package/dist/lang/ast/explore-properties/primary-key.d.ts +7 -0
- package/dist/lang/ast/{apply-expr.js → explore-properties/primary-key.js} +9 -8
- package/dist/lang/ast/explore-properties/renames.d.ts +11 -0
- package/dist/lang/ast/explore-properties/renames.js +43 -0
- package/dist/lang/ast/explore-properties/turtles.d.ts +5 -0
- package/dist/lang/ast/explore-properties/turtles.js +33 -0
- package/dist/lang/ast/expressions/apply.d.ts +8 -0
- package/dist/lang/ast/expressions/apply.js +37 -0
- package/dist/lang/ast/expressions/binary-boolean.d.ts +12 -0
- package/dist/lang/ast/expressions/binary-boolean.js +54 -0
- package/dist/lang/ast/expressions/binary-numeric.d.ts +11 -0
- package/dist/lang/ast/expressions/binary-numeric.js +42 -0
- package/dist/lang/ast/expressions/boolean.d.ts +8 -0
- package/dist/lang/ast/expressions/boolean.js +39 -0
- package/dist/lang/ast/expressions/constant-sub-expression.d.ts +16 -0
- package/dist/lang/ast/expressions/constant-sub-expression.js +98 -0
- package/dist/lang/ast/expressions/expr-add-sub.d.ts +4 -0
- package/dist/lang/ast/expressions/expr-add-sub.js +34 -0
- package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +15 -0
- package/dist/lang/ast/expressions/expr-aggregate-function.js +99 -0
- package/dist/lang/ast/expressions/expr-alternation-tree.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-alternation-tree.js +54 -0
- package/dist/lang/ast/expressions/expr-asymmetric.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-asymmetric.js +27 -0
- package/dist/lang/ast/expressions/expr-avg.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-avg.js +34 -0
- package/dist/lang/ast/expressions/expr-case.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-case.js +84 -0
- package/dist/lang/ast/expressions/expr-cast.d.ts +13 -0
- package/dist/lang/ast/expressions/expr-cast.js +29 -0
- package/dist/lang/ast/expressions/expr-compare.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-compare.js +48 -0
- package/dist/lang/ast/expressions/expr-count-distinct.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-count-distinct.js +35 -0
- package/dist/lang/ast/expressions/expr-count.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-count.js +57 -0
- package/dist/lang/ast/expressions/expr-filter.d.ts +12 -0
- package/dist/lang/ast/expressions/expr-filter.js +69 -0
- package/dist/lang/ast/expressions/expr-func.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-func.js +63 -0
- package/dist/lang/ast/expressions/expr-granular-time.d.ts +24 -0
- package/dist/lang/ast/expressions/expr-granular-time.js +117 -0
- package/dist/lang/ast/expressions/expr-id-reference.d.ts +12 -0
- package/dist/lang/ast/expressions/expr-id-reference.js +76 -0
- package/dist/lang/ast/expressions/expr-logical-op.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-logical-op.js +36 -0
- package/dist/lang/ast/expressions/expr-max.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-max.js +16 -0
- package/dist/lang/ast/expressions/expr-min.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-min.js +16 -0
- package/dist/lang/ast/expressions/expr-minus.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-minus.js +48 -0
- package/dist/lang/ast/expressions/expr-mul-div.d.ts +4 -0
- package/dist/lang/ast/expressions/expr-mul-div.js +34 -0
- package/dist/lang/ast/expressions/expr-not.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-not.js +49 -0
- package/dist/lang/ast/expressions/expr-now.d.ts +7 -0
- package/dist/lang/ast/expressions/expr-now.js +46 -0
- package/dist/lang/ast/expressions/expr-null.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-null.js +41 -0
- package/dist/lang/ast/expressions/expr-number.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-number.js +42 -0
- package/dist/lang/ast/expressions/expr-parens.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-parens.js +42 -0
- package/dist/lang/ast/expressions/expr-regex.d.ts +8 -0
- package/dist/lang/ast/expressions/expr-regex.js +42 -0
- package/dist/lang/ast/expressions/expr-string.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-string.js +50 -0
- package/dist/lang/ast/expressions/expr-sum.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-sum.js +12 -0
- package/dist/lang/ast/expressions/expr-time-extract.d.ts +13 -0
- package/dist/lang/ast/expressions/expr-time-extract.js +117 -0
- package/dist/lang/ast/expressions/expr-time.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-time.js +62 -0
- package/dist/lang/ast/expressions/expr-ungroup.d.ts +14 -0
- package/dist/lang/ast/expressions/expr-ungroup.js +83 -0
- package/dist/lang/ast/expressions/for-range.d.ts +19 -0
- package/dist/lang/ast/expressions/for-range.js +101 -0
- package/dist/lang/ast/expressions/granular-literal.d.ts +20 -0
- package/dist/lang/ast/expressions/granular-literal.js +148 -0
- package/dist/lang/ast/expressions/partial-compare.d.ts +14 -0
- package/dist/lang/ast/expressions/partial-compare.js +50 -0
- package/dist/lang/ast/expressions/pick-when.d.ts +19 -0
- package/dist/lang/ast/expressions/pick-when.js +156 -0
- package/dist/lang/ast/expressions/range.d.ts +12 -0
- package/dist/lang/ast/expressions/range.js +80 -0
- package/dist/lang/ast/expressions/time-frame.d.ts +7 -0
- package/dist/lang/ast/expressions/time-frame.js +40 -0
- package/dist/lang/ast/expressions/top-by.d.ts +10 -0
- package/dist/lang/ast/expressions/top-by.js +51 -0
- package/dist/lang/ast/expressions/unary.d.ts +5 -0
- package/dist/lang/ast/expressions/unary.js +34 -0
- package/dist/lang/ast/expressions/utils.d.ts +15 -0
- package/dist/lang/ast/expressions/utils.js +106 -0
- package/dist/lang/ast/expressions/when-clause.d.ts +10 -0
- package/dist/lang/ast/expressions/when-clause.js +17 -0
- package/dist/lang/ast/fragtype-utils.d.ts +39 -0
- package/dist/lang/ast/fragtype-utils.js +100 -0
- package/dist/lang/ast/import-elements/import-statement.d.ts +9 -0
- package/dist/lang/ast/import-elements/import-statement.js +78 -0
- package/dist/lang/ast/index.d.ts +94 -3
- package/dist/lang/ast/index.js +94 -3
- package/dist/lang/ast/json-elements/json-element.d.ts +6 -0
- package/dist/lang/ast/json-elements/json-element.js +41 -0
- package/dist/lang/ast/json-elements/json-struct-def.d.ts +10 -0
- package/dist/lang/ast/json-elements/json-struct-def.js +48 -0
- package/dist/lang/ast/nesting/nest-reference.d.ts +7 -0
- package/dist/lang/ast/nesting/nest-reference.js +35 -0
- package/dist/lang/ast/parameters/constant-parameter.d.ts +8 -0
- package/dist/lang/ast/parameters/constant-parameter.js +54 -0
- package/dist/lang/ast/parameters/has-parameter.d.ts +19 -0
- package/dist/lang/ast/parameters/has-parameter.js +64 -0
- package/dist/lang/ast/query-elements/anonymous-query.d.ts +9 -0
- package/dist/lang/ast/query-elements/anonymous-query.js +41 -0
- package/dist/lang/ast/query-elements/existing-query.d.ts +11 -0
- package/dist/lang/ast/query-elements/existing-query.js +79 -0
- package/dist/lang/ast/query-elements/full-query.d.ts +10 -0
- package/dist/lang/ast/query-elements/full-query.js +85 -0
- package/dist/lang/ast/query-elements/query-head-struct.d.ts +9 -0
- package/dist/lang/ast/query-elements/query-head-struct.js +48 -0
- package/dist/lang/ast/query-items/field-declaration.d.ts +31 -0
- package/dist/lang/ast/query-items/field-declaration.js +137 -0
- package/dist/lang/ast/query-items/field-references.d.ts +25 -0
- package/dist/lang/ast/query-items/field-references.js +80 -0
- package/dist/lang/ast/query-properties/aggregate.d.ts +5 -0
- package/dist/lang/ast/query-properties/aggregate.js +39 -0
- package/dist/lang/ast/query-properties/declare-fields.d.ts +5 -0
- package/dist/lang/ast/query-properties/declare-fields.js +33 -0
- package/dist/lang/ast/query-properties/dimmensions.d.ts +5 -0
- package/dist/lang/ast/query-properties/dimmensions.js +36 -0
- package/dist/lang/ast/query-properties/filters.d.ts +18 -0
- package/dist/lang/ast/query-properties/filters.js +89 -0
- package/dist/lang/ast/query-properties/group-by.d.ts +5 -0
- package/dist/lang/ast/query-properties/group-by.js +39 -0
- package/dist/lang/ast/query-properties/indexing.d.ts +10 -0
- package/dist/lang/ast/query-properties/indexing.js +39 -0
- package/dist/lang/ast/query-properties/joins.d.ts +36 -0
- package/dist/lang/ast/query-properties/joins.js +143 -0
- package/dist/lang/ast/query-properties/limit.d.ts +6 -0
- package/dist/lang/ast/query-properties/limit.js +35 -0
- package/dist/lang/ast/query-properties/measures.d.ts +5 -0
- package/dist/lang/ast/query-properties/measures.js +36 -0
- package/dist/lang/ast/query-properties/nests.d.ts +5 -0
- package/dist/lang/ast/query-properties/nests.js +33 -0
- package/dist/lang/ast/query-properties/ordering.d.ts +15 -0
- package/dist/lang/ast/query-properties/ordering.js +66 -0
- package/dist/lang/ast/query-properties/project-statement.d.ts +5 -0
- package/dist/lang/ast/query-properties/project-statement.js +33 -0
- package/dist/lang/ast/query-properties/qop-desc.d.ts +17 -0
- package/dist/lang/ast/query-properties/qop-desc.js +123 -0
- package/dist/lang/ast/query-properties/sampling.d.ts +8 -0
- package/dist/lang/ast/query-properties/sampling.js +38 -0
- package/dist/lang/ast/query-properties/top.d.ts +13 -0
- package/dist/lang/ast/query-properties/top.js +60 -0
- package/dist/lang/ast/result-spaces/index-field-space.d.ts +10 -0
- package/dist/lang/ast/result-spaces/index-field-space.js +57 -0
- package/dist/lang/ast/result-spaces/project-field-space.d.ts +6 -0
- package/dist/lang/ast/result-spaces/project-field-space.js +51 -0
- package/dist/lang/ast/result-spaces/reduce-field-space.d.ts +7 -0
- package/dist/lang/ast/result-spaces/reduce-field-space.js +37 -0
- package/dist/lang/ast/sources/named-source.d.ts +19 -0
- package/dist/lang/ast/sources/named-source.js +147 -0
- package/dist/lang/ast/sources/query-source.d.ts +9 -0
- package/dist/lang/ast/sources/query-source.js +41 -0
- package/dist/lang/ast/sources/sql-source.d.ts +7 -0
- package/dist/lang/ast/sources/sql-source.js +54 -0
- package/dist/lang/ast/sources/table-source.d.ts +8 -0
- package/dist/lang/ast/sources/table-source.js +60 -0
- package/dist/lang/ast/space-fields/column-space-field.d.ts +9 -0
- package/dist/lang/ast/space-fields/column-space-field.js +40 -0
- package/dist/lang/ast/space-fields/join-space-field.d.ts +8 -0
- package/dist/lang/ast/space-fields/join-space-field.js +35 -0
- package/dist/lang/ast/space-fields/query-field-struct.d.ts +10 -0
- package/dist/lang/ast/space-fields/query-field-struct.js +46 -0
- package/dist/lang/ast/space-fields/query-space-field.d.ts +11 -0
- package/dist/lang/ast/space-fields/query-space-field.js +37 -0
- package/dist/lang/ast/space-fields/reference-field.d.ts +11 -0
- package/dist/lang/ast/space-fields/reference-field.js +45 -0
- package/dist/lang/ast/space-fields/rename-space-field.d.ts +11 -0
- package/dist/lang/ast/space-fields/rename-space-field.js +50 -0
- package/dist/lang/ast/space-fields/wild-space-field.d.ts +10 -0
- package/dist/lang/ast/space-fields/wild-space-field.js +40 -0
- package/dist/lang/ast/space-parameters/abstract-parameter.d.ts +10 -0
- package/dist/lang/ast/space-parameters/abstract-parameter.js +41 -0
- package/dist/lang/ast/space-parameters/defined-parameter.d.ts +9 -0
- package/dist/lang/ast/space-parameters/defined-parameter.js +40 -0
- package/dist/lang/ast/space-seed.d.ts +17 -0
- package/dist/lang/ast/space-seed.js +59 -0
- package/dist/lang/ast/sql-elements/sql-statement.d.ts +19 -0
- package/dist/lang/ast/sql-elements/sql-statement.js +80 -0
- package/dist/lang/ast/sql-elements/sql-string.d.ts +12 -0
- package/dist/lang/ast/sql-elements/sql-string.js +60 -0
- package/dist/lang/ast/static-space.d.ts +33 -0
- package/dist/lang/ast/static-space.js +167 -0
- package/dist/lang/ast/struct-utils.d.ts +4 -0
- package/dist/lang/ast/struct-utils.js +48 -0
- package/dist/lang/ast/time-utils.d.ts +5 -2
- package/dist/lang/ast/time-utils.js +37 -1
- package/dist/lang/ast/types/comparison.d.ts +11 -0
- package/dist/lang/ast/types/comparison.js +41 -0
- package/dist/lang/ast/types/compart-types.d.ts +10 -0
- package/dist/lang/ast/types/compart-types.js +37 -0
- package/dist/lang/ast/types/document-compile-result.d.ts +8 -0
- package/dist/lang/ast/types/document-compile-result.js +25 -0
- package/dist/lang/ast/types/equality.d.ts +7 -0
- package/dist/lang/ast/types/equality.js +37 -0
- package/dist/lang/ast/types/executor.d.ts +9 -0
- package/dist/lang/ast/types/executor.js +25 -0
- package/dist/lang/ast/types/explore-desc.d.ts +5 -0
- package/dist/lang/ast/types/explore-desc.js +33 -0
- package/dist/lang/ast/types/explore-field.d.ts +5 -0
- package/dist/lang/ast/types/explore-field.js +32 -0
- package/dist/lang/ast/types/explore-property.d.ts +10 -0
- package/dist/lang/ast/types/explore-property.js +43 -0
- package/dist/lang/ast/types/expr-result.d.ts +5 -0
- package/dist/lang/ast/types/expr-result.js +25 -0
- package/dist/lang/ast/types/expr-value.d.ts +3 -0
- package/dist/lang/ast/types/expr-value.js +25 -0
- package/dist/lang/ast/types/expression-def.d.ts +69 -0
- package/dist/lang/ast/types/expression-def.js +346 -0
- package/dist/lang/ast/types/expression-value-type.d.ts +2 -0
- package/dist/lang/ast/types/expression-value-type.js +25 -0
- package/dist/lang/ast/types/field-collection-member.d.ts +5 -0
- package/dist/lang/ast/types/field-collection-member.js +34 -0
- package/dist/lang/ast/types/field-decl.d.ts +7 -0
- package/dist/lang/ast/types/field-decl.js +37 -0
- package/dist/lang/ast/types/field-map.d.ts +2 -0
- package/dist/lang/ast/types/field-map.js +25 -0
- package/dist/lang/ast/types/field-space.d.ts +26 -0
- package/dist/lang/ast/types/field-space.js +48 -0
- package/dist/lang/ast/types/field-type.d.ts +6 -0
- package/dist/lang/ast/types/field-type.js +25 -0
- package/dist/lang/ast/types/field-value-type.d.ts +3 -0
- package/dist/lang/ast/types/field-value-type.js +25 -0
- package/dist/lang/ast/types/frag-type.d.ts +6 -0
- package/dist/lang/ast/types/frag-type.js +25 -0
- package/dist/lang/ast/types/granular-result.d.ts +7 -0
- package/dist/lang/ast/types/granular-result.js +11 -0
- package/dist/lang/ast/types/lookup-result.d.ts +10 -0
- package/dist/lang/ast/types/lookup-result.js +25 -0
- package/dist/lang/ast/types/malloy-element.d.ts +105 -0
- package/dist/lang/ast/types/malloy-element.js +398 -0
- package/dist/lang/ast/types/model-entry.d.ts +6 -0
- package/dist/lang/ast/types/model-entry.js +25 -0
- package/dist/lang/ast/types/name-space.d.ts +5 -0
- package/dist/lang/ast/types/name-space.js +25 -0
- package/dist/lang/ast/types/nested-query.d.ts +3 -0
- package/dist/lang/ast/types/nested-query.js +25 -0
- package/dist/lang/ast/types/op-desc.d.ts +6 -0
- package/dist/lang/ast/types/op-desc.js +25 -0
- package/dist/lang/ast/types/query-comp.d.ts +5 -0
- package/dist/lang/ast/types/query-comp.js +25 -0
- package/dist/lang/ast/types/query-element.d.ts +5 -0
- package/dist/lang/ast/types/query-element.js +32 -0
- package/dist/lang/ast/types/query-item.d.ts +5 -0
- package/dist/lang/ast/types/query-item.js +25 -0
- package/dist/lang/ast/types/query-property.d.ts +17 -0
- package/dist/lang/ast/types/query-property.js +55 -0
- package/dist/lang/ast/types/space-entry.d.ts +5 -0
- package/dist/lang/ast/types/space-entry.js +29 -0
- package/dist/lang/ast/types/space-field.d.ts +10 -0
- package/dist/lang/ast/types/space-field.js +48 -0
- package/dist/lang/ast/types/space-param.d.ts +6 -0
- package/dist/lang/ast/types/space-param.js +34 -0
- package/dist/lang/ast/types/stage-field-type.d.ts +1 -0
- package/dist/lang/ast/types/stage-field-type.js +25 -0
- package/dist/lang/ast/types/time-result.d.ts +6 -0
- package/dist/lang/ast/types/time-result.js +25 -0
- package/dist/lang/ast/types/turtle-headed-pipe.d.ts +7 -0
- package/dist/lang/ast/types/turtle-headed-pipe.js +37 -0
- package/dist/lang/space-field.d.ts +4 -1
- package/dist/lang/space-field.js +4 -3
- package/dist/lang/test/field-symbols.spec.js +25 -21
- package/dist/lang/test/parse.spec.js +4 -3
- package/dist/lang/test/test-translator.d.ts +3 -1
- package/package.json +1 -1
- package/dist/lang/ast/apply-expr.d.ts +0 -3
- package/dist/lang/ast/ast-expr.d.ts +0 -206
- package/dist/lang/ast/ast-expr.js +0 -781
- package/dist/lang/ast/ast-time-expr.d.ts +0 -69
- package/dist/lang/ast/ast-time-expr.js +0 -389
- package/dist/lang/ast/ast-types.d.ts +0 -83
- package/dist/lang/ast/ast-types.js +0 -225
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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.
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.isEquality = exports.isComparison = exports.timestampOffset = exports.dateOffset = exports.compose = exports.compressExpr = exports.errorFor = exports.isGranularResult = exports.FT = exports.isExpressionValueType = void 0;
|
|
26
|
-
const malloy_types_1 = require("../../model/malloy_types");
|
|
27
|
-
function isExpressionValueType(fv) {
|
|
28
|
-
return ((0, malloy_types_1.isAtomicFieldType)(fv) ||
|
|
29
|
-
["null", "unknown", "duration", "regular expression"].includes(fv));
|
|
30
|
-
}
|
|
31
|
-
exports.isExpressionValueType = isExpressionValueType;
|
|
32
|
-
/**
|
|
33
|
-
* Collects functions which operate on fragtype compatible objects
|
|
34
|
-
*/
|
|
35
|
-
class FT {
|
|
36
|
-
/**
|
|
37
|
-
* Checks if a given type is in a list
|
|
38
|
-
* @param check The type to check (can be undefined)
|
|
39
|
-
* @param from List of types which are OK
|
|
40
|
-
*/
|
|
41
|
-
static in(check, from) {
|
|
42
|
-
if (check) {
|
|
43
|
-
const found = from.find((okType) => FT.eq(okType, check));
|
|
44
|
-
return found !== undefined;
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Checks if a possibly undefined candidate matches a type
|
|
50
|
-
* @param good The real type
|
|
51
|
-
* @param checkThis The possibly undefined candidate
|
|
52
|
-
*/
|
|
53
|
-
static eq(good, checkThis) {
|
|
54
|
-
return (checkThis !== undefined &&
|
|
55
|
-
good.dataType === checkThis.dataType &&
|
|
56
|
-
good.expressionType === checkThis.expressionType);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Checks if the base types, ignoring aggregate, are equal
|
|
60
|
-
* @param left Left type
|
|
61
|
-
* @param right Right type
|
|
62
|
-
* @param nullOk True if a NULL is an acceptable match
|
|
63
|
-
*/
|
|
64
|
-
static typeEq(left, right, nullOk = false) {
|
|
65
|
-
const maybeEq = left.dataType === right.dataType;
|
|
66
|
-
const nullEq = nullOk && (left.dataType === "null" || right.dataType === "null");
|
|
67
|
-
return maybeEq || nullEq;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
* For error messages, returns a comma seperated list of readable names
|
|
72
|
-
* for a list of types.
|
|
73
|
-
* @param types List of type or objects with types
|
|
74
|
-
*/
|
|
75
|
-
static inspect(...types) {
|
|
76
|
-
const strings = types.map((type) => {
|
|
77
|
-
if (type) {
|
|
78
|
-
let inspected = type.dataType;
|
|
79
|
-
if (type.expressionType != "scalar") {
|
|
80
|
-
inspected = `${type.expressionType} ${inspected}`;
|
|
81
|
-
}
|
|
82
|
-
return inspected;
|
|
83
|
-
}
|
|
84
|
-
return "undefined";
|
|
85
|
-
});
|
|
86
|
-
return strings.join(",");
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.FT = FT;
|
|
90
|
-
FT.nullT = mkFragType("null");
|
|
91
|
-
FT.numberT = mkFragType("number");
|
|
92
|
-
FT.stringT = mkFragType("string");
|
|
93
|
-
FT.dateT = mkFragType("date");
|
|
94
|
-
FT.timestampT = mkFragType("timestamp");
|
|
95
|
-
FT.boolT = mkFragType("boolean");
|
|
96
|
-
FT.anyAtomicT = [
|
|
97
|
-
FT.numberT,
|
|
98
|
-
FT.stringT,
|
|
99
|
-
FT.dateT,
|
|
100
|
-
FT.timestampT,
|
|
101
|
-
FT.boolT,
|
|
102
|
-
];
|
|
103
|
-
function mkFragType(dType) {
|
|
104
|
-
return { dataType: dType, expressionType: "scalar" };
|
|
105
|
-
}
|
|
106
|
-
function isGranularResult(v) {
|
|
107
|
-
if (v.dataType !== "date" && v.dataType !== "timestamp") {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
return v.timeframe !== undefined;
|
|
111
|
-
}
|
|
112
|
-
exports.isGranularResult = isGranularResult;
|
|
113
|
-
/**
|
|
114
|
-
* When a translation hits an error, log and return one of these as a value.
|
|
115
|
-
* This will allow the rest of the translation walk to complete. The
|
|
116
|
-
* generated SQL will have a reference to an impossible variable name
|
|
117
|
-
* with the reason embedded in it.
|
|
118
|
-
* @param reason very short phrase, only read by implementers
|
|
119
|
-
* @returns Fragment[] which a debugging humnan will regognize
|
|
120
|
-
*/
|
|
121
|
-
function errorFor(reason) {
|
|
122
|
-
return {
|
|
123
|
-
dataType: "unknown",
|
|
124
|
-
expressionType: "scalar",
|
|
125
|
-
value: [`_ERROR_${reason.replace(/ /g, "_")}`],
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
exports.errorFor = errorFor;
|
|
129
|
-
/**
|
|
130
|
-
* If the passed expresion is not a single term, wrap it in parens
|
|
131
|
-
* @param f expression fragment
|
|
132
|
-
*/
|
|
133
|
-
function term(f) {
|
|
134
|
-
if (f.length > 1) {
|
|
135
|
-
return ["(", ...f, ")"];
|
|
136
|
-
}
|
|
137
|
-
if (f.length === 0) {
|
|
138
|
-
// Trying to compose a binary expresion with an entity that has no value
|
|
139
|
-
// this should at least cause the generated SQL to error, but likely
|
|
140
|
-
// there has already been a semantic error reported.
|
|
141
|
-
return ["__MISSING_VALUE__"];
|
|
142
|
-
}
|
|
143
|
-
return f;
|
|
144
|
-
}
|
|
145
|
-
function compressExpr(expr) {
|
|
146
|
-
// compress all adjacent strings
|
|
147
|
-
const compressValue = [];
|
|
148
|
-
let buildString;
|
|
149
|
-
for (const fragment of expr.flat()) {
|
|
150
|
-
if (typeof fragment === "string") {
|
|
151
|
-
buildString = buildString ? buildString + fragment : fragment;
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
if (buildString) {
|
|
155
|
-
compressValue.push(buildString);
|
|
156
|
-
buildString = undefined;
|
|
157
|
-
}
|
|
158
|
-
compressValue.push(fragment);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (buildString) {
|
|
162
|
-
compressValue.push(buildString);
|
|
163
|
-
}
|
|
164
|
-
return compressValue;
|
|
165
|
-
}
|
|
166
|
-
exports.compressExpr = compressExpr;
|
|
167
|
-
/**
|
|
168
|
-
* Compose a binary expression. Tries to write them safely and concisely
|
|
169
|
-
* @param left
|
|
170
|
-
* @param op
|
|
171
|
-
* @param right
|
|
172
|
-
* @returns Fragment list of the composed expression
|
|
173
|
-
*/
|
|
174
|
-
function compose(left, op, right) {
|
|
175
|
-
const opAlpha = op.match(/^[A-Za-z]/);
|
|
176
|
-
const leftSpace = left.length === 1 && opAlpha ? " " : "";
|
|
177
|
-
const rightSpace = right.length === 1 && opAlpha ? " " : "";
|
|
178
|
-
const newOp = leftSpace + op + rightSpace;
|
|
179
|
-
return [...term(left), newOp, ...term(right)];
|
|
180
|
-
}
|
|
181
|
-
exports.compose = compose;
|
|
182
|
-
function dateOffset(from, op, n, timeframe) {
|
|
183
|
-
const add = op === "+" ? "_ADD" : "_SUB";
|
|
184
|
-
const units = timeframe.toUpperCase();
|
|
185
|
-
return compressExpr([
|
|
186
|
-
`DATE${add}(`,
|
|
187
|
-
...from,
|
|
188
|
-
`,INTERVAL `,
|
|
189
|
-
...n,
|
|
190
|
-
` ${units})`,
|
|
191
|
-
]);
|
|
192
|
-
}
|
|
193
|
-
exports.dateOffset = dateOffset;
|
|
194
|
-
function timestampOffset(from, op, n, timeframe, fromNotTimestamp = false) {
|
|
195
|
-
const useDatetime = ["week", "month", "quarter", "year"].includes(timeframe);
|
|
196
|
-
const add = op === "+" ? "_ADD" : "_SUB";
|
|
197
|
-
const units = timeframe.toUpperCase();
|
|
198
|
-
if (useDatetime) {
|
|
199
|
-
return [
|
|
200
|
-
`TIMESTAMP(DATETIME${add}(DATETIME(`,
|
|
201
|
-
...from,
|
|
202
|
-
`),INTERVAL `,
|
|
203
|
-
...n,
|
|
204
|
-
` ${units}))`,
|
|
205
|
-
];
|
|
206
|
-
}
|
|
207
|
-
const typeFrom = fromNotTimestamp ? ["TIMESTAMP(", ...from, ")"] : from;
|
|
208
|
-
return compressExpr([
|
|
209
|
-
`TIMESTAMP${add}(`,
|
|
210
|
-
...typeFrom,
|
|
211
|
-
`,INTERVAL `,
|
|
212
|
-
...n,
|
|
213
|
-
` ${units})`,
|
|
214
|
-
]);
|
|
215
|
-
}
|
|
216
|
-
exports.timestampOffset = timestampOffset;
|
|
217
|
-
function isComparison(s) {
|
|
218
|
-
return ["~", "!~", "<", "<=", "=", ">", ">=", "!="].includes(s);
|
|
219
|
-
}
|
|
220
|
-
exports.isComparison = isComparison;
|
|
221
|
-
function isEquality(s) {
|
|
222
|
-
return ["~", "!~", "=", "!="].includes(s);
|
|
223
|
-
}
|
|
224
|
-
exports.isEquality = isEquality;
|
|
225
|
-
//# sourceMappingURL=ast-types.js.map
|