@malloydata/malloy 0.0.24-dev230224214106 → 0.0.24-dev230228224434
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/connection_utils.js +10 -10
- package/dist/dialect/dialect.d.ts +2 -2
- package/dist/dialect/dialect.js +13 -13
- package/dist/dialect/dialect_map.d.ts +1 -1
- package/dist/dialect/duckdb.d.ts +3 -3
- package/dist/dialect/duckdb.js +44 -44
- package/dist/dialect/index.d.ts +6 -6
- package/dist/dialect/postgres.d.ts +3 -3
- package/dist/dialect/postgres.js +46 -46
- package/dist/dialect/standardsql.d.ts +4 -4
- package/dist/dialect/standardsql.js +51 -51
- package/dist/index.d.ts +10 -10
- package/dist/lang/ast/ast-utils.d.ts +1 -1
- package/dist/lang/ast/ast-utils.js +3 -3
- package/dist/lang/ast/elements/define-query.d.ts +3 -3
- package/dist/lang/ast/elements/define-query.js +6 -6
- package/dist/lang/ast/elements/define-source.d.ts +4 -4
- package/dist/lang/ast/elements/define-source.js +8 -8
- package/dist/lang/ast/elements/import-statement.d.ts +2 -2
- package/dist/lang/ast/elements/import-statement.js +7 -7
- package/dist/lang/ast/elements/pipeline-desc.d.ts +5 -5
- package/dist/lang/ast/elements/pipeline-desc.js +11 -11
- package/dist/lang/ast/elements/refined-source.d.ts +4 -4
- package/dist/lang/ast/elements/refined-source.js +6 -6
- package/dist/lang/ast/elements/source.d.ts +3 -3
- package/dist/lang/ast/elements/source.js +1 -1
- package/dist/lang/ast/error-factory.d.ts +1 -1
- package/dist/lang/ast/error-factory.js +15 -15
- package/dist/lang/ast/executors/index-executor.d.ts +7 -7
- package/dist/lang/ast/executors/index-executor.js +4 -4
- package/dist/lang/ast/executors/project-executor.d.ts +5 -5
- package/dist/lang/ast/executors/project-executor.js +2 -2
- package/dist/lang/ast/executors/reduce-executor.d.ts +8 -8
- package/dist/lang/ast/executors/reduce-executor.js +5 -5
- package/dist/lang/ast/expressions/apply.d.ts +2 -2
- package/dist/lang/ast/expressions/apply.js +1 -1
- package/dist/lang/ast/expressions/binary-boolean.d.ts +3 -3
- package/dist/lang/ast/expressions/binary-boolean.js +6 -6
- package/dist/lang/ast/expressions/binary-numeric.d.ts +3 -3
- package/dist/lang/ast/expressions/binary-numeric.js +2 -2
- package/dist/lang/ast/expressions/boolean.d.ts +4 -4
- package/dist/lang/ast/expressions/boolean.js +2 -2
- package/dist/lang/ast/expressions/constant-sub-expression.d.ts +4 -4
- package/dist/lang/ast/expressions/constant-sub-expression.js +12 -12
- package/dist/lang/ast/expressions/expr-add-sub.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-add-sub.js +1 -1
- package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +5 -5
- package/dist/lang/ast/expressions/expr-aggregate-function.js +15 -15
- package/dist/lang/ast/expressions/expr-alternation-tree.d.ts +6 -6
- package/dist/lang/ast/expressions/expr-alternation-tree.js +6 -6
- package/dist/lang/ast/expressions/expr-asymmetric.d.ts +5 -5
- package/dist/lang/ast/expressions/expr-asymmetric.js +3 -3
- package/dist/lang/ast/expressions/expr-avg.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-avg.js +2 -2
- package/dist/lang/ast/expressions/expr-cast.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-cast.js +6 -6
- package/dist/lang/ast/expressions/expr-compare.d.ts +5 -5
- package/dist/lang/ast/expressions/expr-compare.js +9 -9
- package/dist/lang/ast/expressions/expr-count-distinct.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-count-distinct.js +1 -1
- package/dist/lang/ast/expressions/expr-count.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-count.js +10 -10
- package/dist/lang/ast/expressions/expr-filter.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-filter.js +13 -13
- package/dist/lang/ast/expressions/expr-func.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-func.js +8 -8
- package/dist/lang/ast/expressions/expr-granular-time.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-granular-time.js +17 -17
- package/dist/lang/ast/expressions/expr-id-reference.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-id-reference.js +11 -11
- package/dist/lang/ast/expressions/expr-logical-op.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-logical-op.js +1 -1
- package/dist/lang/ast/expressions/expr-max.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-max.js +1 -1
- package/dist/lang/ast/expressions/expr-min.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-min.js +1 -1
- package/dist/lang/ast/expressions/expr-minus.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-minus.js +5 -5
- package/dist/lang/ast/expressions/expr-mul-div.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-mul-div.js +1 -1
- package/dist/lang/ast/expressions/expr-not.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-not.js +3 -3
- package/dist/lang/ast/expressions/expr-now.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-now.js +8 -8
- package/dist/lang/ast/expressions/expr-null.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-null.js +4 -4
- package/dist/lang/ast/expressions/expr-number.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-number.js +2 -2
- package/dist/lang/ast/expressions/expr-parens.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-parens.js +3 -3
- package/dist/lang/ast/expressions/expr-regex.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-regex.js +4 -4
- package/dist/lang/ast/expressions/expr-string.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-string.js +8 -8
- package/dist/lang/ast/expressions/expr-sum.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-sum.js +2 -2
- package/dist/lang/ast/expressions/expr-time-extract.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-time-extract.js +30 -30
- package/dist/lang/ast/expressions/expr-time.d.ts +4 -4
- package/dist/lang/ast/expressions/expr-time.js +10 -10
- package/dist/lang/ast/expressions/expr-ungroup.d.ts +6 -6
- package/dist/lang/ast/expressions/expr-ungroup.js +13 -13
- package/dist/lang/ast/expressions/for-range.d.ts +4 -4
- package/dist/lang/ast/expressions/for-range.js +17 -17
- package/dist/lang/ast/expressions/granular-literal.d.ts +4 -4
- package/dist/lang/ast/expressions/granular-literal.js +34 -34
- package/dist/lang/ast/expressions/partial-compare.d.ts +4 -4
- package/dist/lang/ast/expressions/partial-compare.js +4 -4
- package/dist/lang/ast/expressions/pick-when.d.ts +4 -4
- package/dist/lang/ast/expressions/pick-when.js +32 -32
- package/dist/lang/ast/expressions/range.d.ts +3 -3
- package/dist/lang/ast/expressions/range.js +20 -20
- package/dist/lang/ast/expressions/time-frame.d.ts +2 -2
- package/dist/lang/ast/expressions/time-frame.js +3 -3
- package/dist/lang/ast/expressions/top-by.d.ts +4 -4
- package/dist/lang/ast/expressions/top-by.js +5 -5
- package/dist/lang/ast/expressions/unary.d.ts +1 -1
- package/dist/lang/ast/expressions/unary.js +1 -1
- package/dist/lang/ast/expressions/utils.d.ts +2 -2
- package/dist/lang/ast/expressions/utils.js +6 -6
- package/dist/lang/ast/field-space/column-space-field.d.ts +3 -3
- package/dist/lang/ast/field-space/dynamic-space.d.ts +7 -7
- package/dist/lang/ast/field-space/dynamic-space.js +2 -2
- package/dist/lang/ast/field-space/field-definition-value.d.ts +5 -5
- package/dist/lang/ast/field-space/index-field-space.d.ts +3 -3
- package/dist/lang/ast/field-space/index-field-space.js +4 -4
- package/dist/lang/ast/field-space/join-space-field.d.ts +3 -3
- package/dist/lang/ast/field-space/project-field-space.d.ts +2 -2
- package/dist/lang/ast/field-space/project-field-space.js +5 -5
- package/dist/lang/ast/field-space/query-field-struct.d.ts +3 -3
- package/dist/lang/ast/field-space/query-field-struct.js +1 -1
- package/dist/lang/ast/field-space/query-space-field.d.ts +4 -4
- package/dist/lang/ast/field-space/query-space-field.js +1 -1
- package/dist/lang/ast/field-space/query-spaces.d.ts +11 -11
- package/dist/lang/ast/field-space/query-spaces.js +8 -8
- package/dist/lang/ast/field-space/reference-field.d.ts +5 -5
- package/dist/lang/ast/field-space/reference-field.js +1 -1
- package/dist/lang/ast/field-space/refined-space.d.ts +4 -4
- package/dist/lang/ast/field-space/refined-space.js +2 -2
- package/dist/lang/ast/field-space/rename-space-field.d.ts +3 -3
- package/dist/lang/ast/field-space/rename-space-field.js +2 -2
- package/dist/lang/ast/field-space/static-space.d.ts +7 -7
- package/dist/lang/ast/field-space/static-space.js +12 -12
- package/dist/lang/ast/field-space/struct-space-field-base.d.ts +4 -4
- package/dist/lang/ast/field-space/struct-space-field-base.js +1 -1
- package/dist/lang/ast/field-space/wild-space-field.d.ts +4 -4
- package/dist/lang/ast/field-space/wild-space-field.js +1 -1
- package/dist/lang/ast/fragtype-utils.d.ts +1 -1
- package/dist/lang/ast/fragtype-utils.js +15 -15
- package/dist/lang/ast/index.d.ts +90 -90
- package/dist/lang/ast/parameters/constant-parameter.d.ts +3 -3
- package/dist/lang/ast/parameters/constant-parameter.js +10 -10
- package/dist/lang/ast/parameters/has-parameter.d.ts +3 -3
- package/dist/lang/ast/parameters/has-parameter.js +7 -7
- package/dist/lang/ast/query-elements/anonymous-query.d.ts +3 -3
- package/dist/lang/ast/query-elements/anonymous-query.js +2 -2
- package/dist/lang/ast/query-elements/existing-query.d.ts +4 -4
- package/dist/lang/ast/query-elements/existing-query.js +10 -10
- package/dist/lang/ast/query-elements/full-query.d.ts +4 -4
- package/dist/lang/ast/query-elements/full-query.js +10 -10
- package/dist/lang/ast/query-elements/query-head-struct.d.ts +2 -2
- package/dist/lang/ast/query-elements/query-head-struct.js +2 -2
- package/dist/lang/ast/query-items/field-declaration.d.ts +6 -6
- package/dist/lang/ast/query-items/field-declaration.js +14 -14
- package/dist/lang/ast/query-items/field-references.d.ts +6 -6
- package/dist/lang/ast/query-items/field-references.js +9 -9
- package/dist/lang/ast/query-properties/aggregate.d.ts +2 -2
- package/dist/lang/ast/query-properties/aggregate.js +1 -1
- package/dist/lang/ast/query-properties/declare-fields.d.ts +2 -2
- package/dist/lang/ast/query-properties/declare-fields.js +1 -1
- package/dist/lang/ast/query-properties/dimmensions.d.ts +2 -2
- package/dist/lang/ast/query-properties/dimmensions.js +1 -1
- package/dist/lang/ast/query-properties/filters.d.ts +4 -4
- package/dist/lang/ast/query-properties/filters.js +16 -16
- package/dist/lang/ast/query-properties/group-by.d.ts +2 -2
- package/dist/lang/ast/query-properties/group-by.js +1 -1
- package/dist/lang/ast/query-properties/indexing.d.ts +3 -3
- package/dist/lang/ast/query-properties/indexing.js +3 -3
- package/dist/lang/ast/query-properties/joins.d.ts +6 -6
- package/dist/lang/ast/query-properties/joins.js +27 -27
- package/dist/lang/ast/query-properties/limit.d.ts +1 -1
- package/dist/lang/ast/query-properties/limit.js +1 -1
- package/dist/lang/ast/query-properties/measures.d.ts +2 -2
- package/dist/lang/ast/query-properties/measures.js +1 -1
- package/dist/lang/ast/query-properties/nest-reference.d.ts +2 -2
- package/dist/lang/ast/query-properties/nest-reference.js +1 -1
- package/dist/lang/ast/query-properties/nest.d.ts +7 -7
- package/dist/lang/ast/query-properties/nest.js +7 -7
- package/dist/lang/ast/query-properties/nests.d.ts +2 -2
- package/dist/lang/ast/query-properties/nests.js +1 -1
- package/dist/lang/ast/query-properties/ordering.d.ts +3 -3
- package/dist/lang/ast/query-properties/ordering.js +6 -6
- package/dist/lang/ast/query-properties/project-statement.d.ts +2 -2
- package/dist/lang/ast/query-properties/project-statement.js +1 -1
- package/dist/lang/ast/query-properties/qop-desc.d.ts +7 -7
- package/dist/lang/ast/query-properties/qop-desc.js +20 -20
- package/dist/lang/ast/query-properties/sampling.d.ts +2 -2
- package/dist/lang/ast/query-properties/sampling.js +1 -1
- package/dist/lang/ast/query-properties/top.d.ts +4 -4
- package/dist/lang/ast/query-properties/top.js +5 -5
- package/dist/lang/ast/source-properties/field-list-edit.d.ts +4 -4
- package/dist/lang/ast/source-properties/field-list-edit.js +2 -2
- package/dist/lang/ast/source-properties/primary-key.d.ts +2 -2
- package/dist/lang/ast/source-properties/primary-key.js +2 -2
- package/dist/lang/ast/source-properties/renames.d.ts +2 -2
- package/dist/lang/ast/source-properties/renames.js +3 -3
- package/dist/lang/ast/source-properties/turtles.d.ts +2 -2
- package/dist/lang/ast/source-properties/turtles.js +1 -1
- package/dist/lang/ast/sources/named-source.d.ts +4 -4
- package/dist/lang/ast/sources/named-source.js +5 -5
- package/dist/lang/ast/sources/query-source.d.ts +3 -3
- package/dist/lang/ast/sources/query-source.js +3 -3
- package/dist/lang/ast/sources/sql-source.d.ts +2 -2
- package/dist/lang/ast/sources/sql-source.js +2 -2
- package/dist/lang/ast/sources/table-source.d.ts +2 -2
- package/dist/lang/ast/sources/table-source.js +7 -7
- package/dist/lang/ast/space-seed.d.ts +2 -2
- package/dist/lang/ast/space-seed.js +1 -1
- package/dist/lang/ast/sql-elements/sql-statement.d.ts +4 -4
- package/dist/lang/ast/sql-elements/sql-statement.js +9 -9
- package/dist/lang/ast/sql-elements/sql-string.d.ts +3 -3
- package/dist/lang/ast/sql-elements/sql-string.js +6 -6
- package/dist/lang/ast/struct-utils.d.ts +2 -2
- package/dist/lang/ast/struct-utils.js +3 -3
- package/dist/lang/ast/time-utils.d.ts +6 -6
- package/dist/lang/ast/time-utils.js +46 -46
- package/dist/lang/ast/types/document-compile-result.d.ts +2 -2
- package/dist/lang/ast/types/executor.d.ts +3 -3
- package/dist/lang/ast/types/explore-desc.d.ts +2 -2
- package/dist/lang/ast/types/explore-desc.js +1 -1
- package/dist/lang/ast/types/explore-field.d.ts +3 -3
- package/dist/lang/ast/types/expr-result.d.ts +2 -2
- package/dist/lang/ast/types/expr-value.d.ts +2 -2
- package/dist/lang/ast/types/expression-def.d.ts +4 -4
- package/dist/lang/ast/types/expression-def.js +86 -86
- package/dist/lang/ast/types/field-collection-member.d.ts +3 -3
- package/dist/lang/ast/types/field-decl.d.ts +5 -5
- package/dist/lang/ast/types/field-space.d.ts +5 -5
- package/dist/lang/ast/types/field-space.js +1 -1
- package/dist/lang/ast/types/granular-result.d.ts +3 -3
- package/dist/lang/ast/types/granular-result.js +1 -1
- package/dist/lang/ast/types/lookup-result.d.ts +1 -1
- package/dist/lang/ast/types/malloy-element.d.ts +6 -6
- package/dist/lang/ast/types/malloy-element.js +49 -49
- package/dist/lang/ast/types/model-entry.d.ts +1 -1
- package/dist/lang/ast/types/name-space.d.ts +1 -1
- package/dist/lang/ast/types/nested-query.d.ts +2 -2
- package/dist/lang/ast/types/op-desc.d.ts +2 -2
- package/dist/lang/ast/types/query-comp.d.ts +1 -1
- package/dist/lang/ast/types/query-element.d.ts +3 -3
- package/dist/lang/ast/types/query-item.d.ts +4 -4
- package/dist/lang/ast/types/query-property.d.ts +15 -15
- package/dist/lang/ast/types/source-property.d.ts +8 -8
- package/dist/lang/ast/types/space-entry.d.ts +2 -2
- package/dist/lang/ast/types/space-field.d.ts +4 -4
- package/dist/lang/ast/types/space-field.js +4 -4
- package/dist/lang/ast/types/space-param.d.ts +4 -4
- package/dist/lang/ast/types/space-param.js +4 -4
- package/dist/lang/ast/types/time-result.d.ts +2 -2
- package/dist/lang/ast/types/turtle-headed-pipe.d.ts +2 -2
- package/dist/lang/ast/types/turtle-headed-pipe.js +1 -1
- package/dist/lang/ast/types/type-desc.d.ts +3 -3
- package/dist/lang/field-utils.d.ts +1 -1
- package/dist/lang/field-utils.js +4 -4
- package/dist/lang/index.d.ts +10 -10
- package/dist/lang/malloy-to-ast.d.ts +8 -8
- package/dist/lang/malloy-to-ast.js +68 -68
- package/dist/lang/parse-error-handler.d.ts +3 -3
- package/dist/lang/parse-error-handler.js +4 -4
- package/dist/lang/parse-log.d.ts +2 -2
- package/dist/lang/parse-log.js +1 -1
- package/dist/lang/parse-malloy.d.ts +7 -7
- package/dist/lang/parse-malloy.js +81 -81
- package/dist/lang/parse-tree-walkers/document-completion-walker.d.ts +2 -2
- package/dist/lang/parse-tree-walkers/document-completion-walker.js +38 -38
- package/dist/lang/parse-tree-walkers/document-help-context-walker.d.ts +1 -1
- package/dist/lang/parse-tree-walkers/document-help-context-walker.js +14 -14
- package/dist/lang/parse-tree-walkers/document-highlight-walker.d.ts +3 -3
- package/dist/lang/parse-tree-walkers/document-highlight-walker.js +85 -85
- package/dist/lang/parse-tree-walkers/document-symbol-walker.d.ts +4 -4
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +40 -40
- package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +3 -3
- package/dist/lang/parse-tree-walkers/explore-query-walker.js +3 -3
- package/dist/lang/parse-tree-walkers/find-external-references.d.ts +4 -4
- package/dist/lang/parse-tree-walkers/find-external-references.js +2 -2
- package/dist/lang/reference-list.d.ts +1 -1
- package/dist/lang/test/document-help-context-walker.spec.js +9 -9
- package/dist/lang/test/document-symbol-walker.spec.js +32 -32
- package/dist/lang/test/field-symbols.spec.js +87 -87
- package/dist/lang/test/parse.spec.d.ts +1 -1
- package/dist/lang/test/parse.spec.js +768 -768
- package/dist/lang/test/test-translator.d.ts +6 -6
- package/dist/lang/test/test-translator.js +159 -159
- package/dist/lang/translate-response.d.ts +7 -7
- package/dist/lang/translate-response.js +1 -1
- package/dist/lang/zone.d.ts +5 -5
- package/dist/lang/zone.js +8 -8
- package/dist/malloy.d.ts +7 -7
- package/dist/malloy.js +192 -192
- package/dist/model/index.d.ts +2 -2
- package/dist/model/malloy_query.d.ts +12 -12
- package/dist/model/malloy_query.js +497 -502
- package/dist/model/malloy_types.d.ts +68 -68
- package/dist/model/malloy_types.js +102 -102
- package/dist/model/sql_block.d.ts +1 -1
- package/dist/model/sql_block.js +4 -4
- package/dist/model/utils.d.ts +1 -1
- package/dist/model/utils.js +10 -10
- package/dist/runtime_types.d.ts +2 -2
- package/package.json +4 -1
package/dist/malloy.js
CHANGED
|
@@ -28,7 +28,7 @@ const model_1 = require("./model");
|
|
|
28
28
|
class Malloy {
|
|
29
29
|
// TODO load from file built during release
|
|
30
30
|
static get version() {
|
|
31
|
-
return
|
|
31
|
+
return '0.0.1';
|
|
32
32
|
}
|
|
33
33
|
static get log() {
|
|
34
34
|
return Malloy._log || console;
|
|
@@ -38,25 +38,25 @@ class Malloy {
|
|
|
38
38
|
}
|
|
39
39
|
static _parse(source, url) {
|
|
40
40
|
if (url === undefined) {
|
|
41
|
-
url = new URL(
|
|
41
|
+
url = new URL('internal://internal.malloy');
|
|
42
42
|
}
|
|
43
43
|
const translator = new lang_1.MalloyTranslator(url.toString(), {
|
|
44
|
-
|
|
44
|
+
urls: { [url.toString()]: source },
|
|
45
45
|
});
|
|
46
46
|
return new Parse(translator);
|
|
47
47
|
}
|
|
48
|
-
static parse({ url, urlReader, source }) {
|
|
48
|
+
static parse({ url, urlReader, source, }) {
|
|
49
49
|
if (source !== undefined) {
|
|
50
50
|
return Malloy._parse(source, url);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
53
|
if (urlReader === undefined) {
|
|
54
|
-
throw new Error(
|
|
54
|
+
throw new Error('Internal Error: urlReader is required.');
|
|
55
55
|
}
|
|
56
56
|
if (url === undefined) {
|
|
57
|
-
throw new Error(
|
|
57
|
+
throw new Error('Internal Error: url is required if source not present.');
|
|
58
58
|
}
|
|
59
|
-
return urlReader.readURL(url).then(
|
|
59
|
+
return urlReader.readURL(url).then(source => {
|
|
60
60
|
return Malloy._parse(source, url);
|
|
61
61
|
});
|
|
62
62
|
}
|
|
@@ -70,7 +70,7 @@ class Malloy {
|
|
|
70
70
|
* @param model A compiled model to build upon (optional).
|
|
71
71
|
* @return A (promise of a) compiled `Model`.
|
|
72
72
|
*/
|
|
73
|
-
static async compile({ urlReader, connections, parse, model }) {
|
|
73
|
+
static async compile({ urlReader, connections, parse, model, }) {
|
|
74
74
|
const translator = parse._translator;
|
|
75
75
|
// eslint-disable-next-line no-constant-condition
|
|
76
76
|
while (true) {
|
|
@@ -91,8 +91,8 @@ class Malloy {
|
|
|
91
91
|
if (result.urls) {
|
|
92
92
|
for (const neededUrl of result.urls) {
|
|
93
93
|
try {
|
|
94
|
-
if (neededUrl.startsWith(
|
|
95
|
-
throw new Error(
|
|
94
|
+
if (neededUrl.startsWith('internal://')) {
|
|
95
|
+
throw new Error('In order to use relative imports, you must compile a file via a URL.');
|
|
96
96
|
}
|
|
97
97
|
const neededText = await urlReader.readURL(new URL(neededUrl));
|
|
98
98
|
const urls = { [neededUrl]: neededText };
|
|
@@ -100,7 +100,7 @@ class Malloy {
|
|
|
100
100
|
}
|
|
101
101
|
catch (error) {
|
|
102
102
|
translator.update({
|
|
103
|
-
|
|
103
|
+
errors: { urls: { [neededUrl]: error.message } },
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -120,14 +120,14 @@ class Malloy {
|
|
|
120
120
|
tablesByConnection.set(connectionName, connectionToTablesMap);
|
|
121
121
|
}
|
|
122
122
|
// iterate over connections, fetching schema for all missing tables
|
|
123
|
-
for (const [connectionName, connectionTableString] of tablesByConnection) {
|
|
123
|
+
for (const [connectionName, connectionTableString,] of tablesByConnection) {
|
|
124
124
|
try {
|
|
125
125
|
const connection = await connections.lookupConnection(connectionName);
|
|
126
126
|
// TODO detect if the union of `Object.keys(tables)` and `Object.keys(errors)` is not the same
|
|
127
127
|
// as `Object.keys(connectionTableString)`, i.e. that all tables are accounted for. Otherwise
|
|
128
128
|
// the translator runs into an infinite loop fetching tables.
|
|
129
|
-
const {
|
|
130
|
-
translator.update({ tables,
|
|
129
|
+
const { schemas: tables, errors } = await connection.fetchSchemaForTables(connectionTableString);
|
|
130
|
+
translator.update({ tables, errors: { tables: errors } });
|
|
131
131
|
}
|
|
132
132
|
catch (error) {
|
|
133
133
|
// There was an exception getting the connection, associate that error
|
|
@@ -137,7 +137,7 @@ class Malloy {
|
|
|
137
137
|
for (const table of connectionTableString) {
|
|
138
138
|
errors[table] = error.toString();
|
|
139
139
|
}
|
|
140
|
-
translator.update({ tables,
|
|
140
|
+
translator.update({ tables, errors: { tables: errors } });
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
}
|
|
@@ -151,13 +151,13 @@ class Malloy {
|
|
|
151
151
|
const resolved = await conn.fetchSchemaForSQLBlock(expanded);
|
|
152
152
|
if (resolved.error) {
|
|
153
153
|
translator.update({
|
|
154
|
-
|
|
154
|
+
errors: { compileSQL: { [expanded.name]: resolved.error } },
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
157
|
if (resolved.structDef) {
|
|
158
158
|
if ((0, model_1.isSQLBlock)(resolved.structDef)) {
|
|
159
159
|
translator.update({
|
|
160
|
-
|
|
160
|
+
compileSQL: { [expanded.name]: resolved.structDef },
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
}
|
|
@@ -165,7 +165,7 @@ class Malloy {
|
|
|
165
165
|
catch (error) {
|
|
166
166
|
const errors = {};
|
|
167
167
|
errors[toCompile.name] = error.toString();
|
|
168
|
-
translator.update({
|
|
168
|
+
translator.update({ errors: { compileSQL: errors } });
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
}
|
|
@@ -173,7 +173,7 @@ class Malloy {
|
|
|
173
173
|
}
|
|
174
174
|
static compileSQLBlock(partialModel, toCompile) {
|
|
175
175
|
let queryModel;
|
|
176
|
-
const sqlStrings = toCompile.select.map(
|
|
176
|
+
const sqlStrings = toCompile.select.map(segment => {
|
|
177
177
|
if ((0, model_1.isSQLFragment)(segment)) {
|
|
178
178
|
return segment.sql;
|
|
179
179
|
}
|
|
@@ -181,7 +181,7 @@ class Malloy {
|
|
|
181
181
|
// TODO catch exceptions and throw errors ...
|
|
182
182
|
if (!queryModel) {
|
|
183
183
|
if (!partialModel) {
|
|
184
|
-
throw new Error(
|
|
184
|
+
throw new Error('Internal error: Partial model missing when compiling SQL block');
|
|
185
185
|
}
|
|
186
186
|
queryModel = new model_1.QueryModel(partialModel);
|
|
187
187
|
}
|
|
@@ -190,65 +190,65 @@ class Malloy {
|
|
|
190
190
|
});
|
|
191
191
|
const { name, connection } = toCompile;
|
|
192
192
|
return {
|
|
193
|
-
|
|
193
|
+
type: 'sqlBlock',
|
|
194
194
|
name,
|
|
195
195
|
connection,
|
|
196
|
-
|
|
196
|
+
selectStr: sqlStrings.join(''),
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
|
-
static async run({ connections, preparedResult, sqlStruct, connection, options }) {
|
|
199
|
+
static async run({ connections, preparedResult, sqlStruct, connection, options, }) {
|
|
200
200
|
const sqlBlock = sqlStruct === null || sqlStruct === void 0 ? void 0 : sqlStruct.structSource.sqlBlock;
|
|
201
201
|
if (!connection) {
|
|
202
202
|
if (!connections) {
|
|
203
|
-
throw new Error(
|
|
203
|
+
throw new Error('Internal Error: Connection or LookupConnection<Connection> must be provided.');
|
|
204
204
|
}
|
|
205
205
|
const connectionName = (sqlBlock === null || sqlBlock === void 0 ? void 0 : sqlBlock.connection) || (preparedResult === null || preparedResult === void 0 ? void 0 : preparedResult.connectionName);
|
|
206
206
|
connection = await connections.lookupConnection(connectionName);
|
|
207
207
|
}
|
|
208
208
|
if (sqlStruct && sqlBlock) {
|
|
209
|
-
if (sqlStruct.structRelationship.type !==
|
|
209
|
+
if (sqlStruct.structRelationship.type !== 'basetable') {
|
|
210
210
|
throw new Error("Expected schema's structRelationship type to be 'basetable'.");
|
|
211
211
|
}
|
|
212
212
|
const data = await connection.runSQL(sqlBlock.selectStr);
|
|
213
213
|
return new Result({
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
214
|
+
structs: [sqlStruct],
|
|
215
|
+
sql: sqlBlock.selectStr,
|
|
216
|
+
result: data.rows,
|
|
217
|
+
totalRows: data.totalRows,
|
|
218
|
+
lastStageName: sqlBlock.name,
|
|
219
219
|
// TODO feature-sql-block There is no malloy code...
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
malloy: '',
|
|
221
|
+
connectionName: sqlStruct.structRelationship.connectionName,
|
|
222
222
|
// TODO feature-sql-block There is no source explore...
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
sourceExplore: '',
|
|
224
|
+
sourceFilters: [],
|
|
225
225
|
}, {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
name: 'empty_model',
|
|
227
|
+
exports: [],
|
|
228
|
+
contents: {},
|
|
229
229
|
});
|
|
230
230
|
}
|
|
231
231
|
else if (preparedResult) {
|
|
232
232
|
const result = await connection.runSQL(preparedResult.sql, options);
|
|
233
233
|
return new Result({
|
|
234
234
|
...preparedResult._rawQuery,
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
result: result.rows,
|
|
236
|
+
totalRows: result.totalRows,
|
|
237
237
|
}, preparedResult._modelDef);
|
|
238
238
|
}
|
|
239
239
|
else {
|
|
240
|
-
throw new Error(
|
|
240
|
+
throw new Error('Internal error: sqlStruct or preparedResult must be provided.');
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
|
-
static async *runStream({ connections, preparedResult, sqlStruct, connection, options }) {
|
|
243
|
+
static async *runStream({ connections, preparedResult, sqlStruct, connection, options, }) {
|
|
244
244
|
const sqlBlock = sqlStruct === null || sqlStruct === void 0 ? void 0 : sqlStruct.structSource.sqlBlock;
|
|
245
245
|
if (sqlBlock === undefined && preparedResult === undefined) {
|
|
246
|
-
throw new Error(
|
|
246
|
+
throw new Error('Internal error: sqlBlock or preparedResult must be provided.');
|
|
247
247
|
}
|
|
248
248
|
const connectionName = (sqlBlock === null || sqlBlock === void 0 ? void 0 : sqlBlock.connection) || (preparedResult === null || preparedResult === void 0 ? void 0 : preparedResult.connectionName);
|
|
249
249
|
if (connection === undefined) {
|
|
250
250
|
if (connections === undefined) {
|
|
251
|
-
throw new Error(
|
|
251
|
+
throw new Error('Internal Error: Connection or LookupConnection<Connection> must be provided.');
|
|
252
252
|
}
|
|
253
253
|
connection = await connections.lookupConnection(connectionName);
|
|
254
254
|
}
|
|
@@ -259,7 +259,7 @@ class Malloy {
|
|
|
259
259
|
let sql;
|
|
260
260
|
let resultExplore;
|
|
261
261
|
if (sqlStruct) {
|
|
262
|
-
if (sqlStruct.structRelationship.type !==
|
|
262
|
+
if (sqlStruct.structRelationship.type !== 'basetable') {
|
|
263
263
|
throw new Error("Expected schema's structRelationship type to be 'basetable'.");
|
|
264
264
|
}
|
|
265
265
|
resultExplore = new Explore(sqlStruct);
|
|
@@ -270,7 +270,7 @@ class Malloy {
|
|
|
270
270
|
sql = preparedResult.sql;
|
|
271
271
|
}
|
|
272
272
|
else {
|
|
273
|
-
throw new Error(
|
|
273
|
+
throw new Error('Internal error: sqlStruct or preparedResult must be provided.');
|
|
274
274
|
}
|
|
275
275
|
let index = 0;
|
|
276
276
|
for await (const row of connection.runSQLStream(sql, options)) {
|
|
@@ -318,10 +318,10 @@ class Model {
|
|
|
318
318
|
*/
|
|
319
319
|
getPreparedQueryByName(queryName) {
|
|
320
320
|
const query = this.modelDef.contents[queryName];
|
|
321
|
-
if (query.type ===
|
|
321
|
+
if (query.type === 'query') {
|
|
322
322
|
return new PreparedQuery(query, this.modelDef, queryName);
|
|
323
323
|
}
|
|
324
|
-
throw new Error(
|
|
324
|
+
throw new Error('Given query name does not refer to a named query.');
|
|
325
325
|
}
|
|
326
326
|
/**
|
|
327
327
|
* Retrieve a prepared query by the index of an unnamed query at the top level of a model.
|
|
@@ -345,7 +345,7 @@ class Model {
|
|
|
345
345
|
* @return A prepared query.
|
|
346
346
|
*/
|
|
347
347
|
getSQLBlockByName(sqlBlockName) {
|
|
348
|
-
const sqlBlock = this.sqlBlocks.find(
|
|
348
|
+
const sqlBlock = this.sqlBlocks.find(sqlBlock => sqlBlock.as === sqlBlockName);
|
|
349
349
|
if (sqlBlock === undefined) {
|
|
350
350
|
throw new Error(`No SQL Block named '${sqlBlockName}'`);
|
|
351
351
|
}
|
|
@@ -371,7 +371,7 @@ class Model {
|
|
|
371
371
|
*/
|
|
372
372
|
get preparedQuery() {
|
|
373
373
|
if (this.queryList.length === 0) {
|
|
374
|
-
throw new Error(
|
|
374
|
+
throw new Error('Model has no queries.');
|
|
375
375
|
}
|
|
376
376
|
return new PreparedQuery(this.queryList[this.queryList.length - 1], this.modelDef);
|
|
377
377
|
}
|
|
@@ -383,10 +383,10 @@ class Model {
|
|
|
383
383
|
*/
|
|
384
384
|
getExploreByName(name) {
|
|
385
385
|
const struct = this.modelDef.contents[name];
|
|
386
|
-
if (struct.type ===
|
|
386
|
+
if (struct.type === 'struct') {
|
|
387
387
|
return new Explore(struct);
|
|
388
388
|
}
|
|
389
|
-
throw new Error(
|
|
389
|
+
throw new Error("'name' is not an explore");
|
|
390
390
|
}
|
|
391
391
|
/**
|
|
392
392
|
* Get an array of `Explore`s contained in the model.
|
|
@@ -397,14 +397,14 @@ class Model {
|
|
|
397
397
|
const explores = [];
|
|
398
398
|
for (const me in this.modelDef.contents) {
|
|
399
399
|
const ent = this.modelDef.contents[me];
|
|
400
|
-
if (ent.type ===
|
|
400
|
+
if (ent.type === 'struct') {
|
|
401
401
|
explores.push(new Explore(ent));
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
return explores;
|
|
405
405
|
}
|
|
406
406
|
get exportedExplores() {
|
|
407
|
-
return this.explores.filter(
|
|
407
|
+
return this.explores.filter(explore => this.modelDef.exports.includes(explore.name));
|
|
408
408
|
}
|
|
409
409
|
get _modelDef() {
|
|
410
410
|
return this.modelDef;
|
|
@@ -430,16 +430,16 @@ class PreparedQuery {
|
|
|
430
430
|
const translatedQuery = queryModel.compileQuery(this._query);
|
|
431
431
|
return new PreparedResult({
|
|
432
432
|
...translatedQuery,
|
|
433
|
-
|
|
433
|
+
queryName: this.name || translatedQuery.queryName,
|
|
434
434
|
}, this._modelDef);
|
|
435
435
|
}
|
|
436
436
|
get dialect() {
|
|
437
437
|
const sourceRef = this._query.structRef;
|
|
438
|
-
const source = typeof sourceRef ===
|
|
438
|
+
const source = typeof sourceRef === 'string'
|
|
439
439
|
? this._modelDef.contents[sourceRef]
|
|
440
440
|
: sourceRef;
|
|
441
|
-
if (source.type !==
|
|
442
|
-
throw new Error(
|
|
441
|
+
if (source.type !== 'struct') {
|
|
442
|
+
throw new Error('Invalid source for query');
|
|
443
443
|
}
|
|
444
444
|
return source.dialect;
|
|
445
445
|
}
|
|
@@ -448,15 +448,15 @@ class PreparedQuery {
|
|
|
448
448
|
*/
|
|
449
449
|
getFlattenedQuery(defaultName) {
|
|
450
450
|
let structRef = this._query.structRef;
|
|
451
|
-
if (typeof structRef !==
|
|
451
|
+
if (typeof structRef !== 'string') {
|
|
452
452
|
structRef = structRef.as || structRef.name;
|
|
453
453
|
}
|
|
454
454
|
const turtleDef = (0, model_1.flattenQuery)(this._modelDef, {
|
|
455
455
|
...this._query,
|
|
456
|
-
|
|
457
|
-
|
|
456
|
+
type: 'query',
|
|
457
|
+
name: 'as' in this._query ? this._query.as || this._query.name : defaultName,
|
|
458
458
|
});
|
|
459
|
-
return new PreparedQuery({ ...turtleDef, structRef,
|
|
459
|
+
return new PreparedQuery({ ...turtleDef, structRef, type: 'query' }, this._modelDef, this.name || turtleDef.as || turtleDef.name);
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
462
|
exports.PreparedQuery = PreparedQuery;
|
|
@@ -464,10 +464,10 @@ function parseTableURI(tableURI) {
|
|
|
464
464
|
const parts = tableURI.match(/^([^:]*):(.*)$/);
|
|
465
465
|
if (parts) {
|
|
466
466
|
const [, firstPart, secondPart] = parts;
|
|
467
|
-
return {
|
|
467
|
+
return { connectionName: firstPart, tablePath: secondPart };
|
|
468
468
|
}
|
|
469
469
|
else {
|
|
470
|
-
return {
|
|
470
|
+
return { tablePath: tableURI };
|
|
471
471
|
}
|
|
472
472
|
}
|
|
473
473
|
exports.parseTableURI = parseTableURI;
|
|
@@ -487,7 +487,7 @@ class Parse {
|
|
|
487
487
|
* @return An array of document highlights.
|
|
488
488
|
*/
|
|
489
489
|
get highlights() {
|
|
490
|
-
return (this.translator.metadata().highlights || []).map(
|
|
490
|
+
return (this.translator.metadata().highlights || []).map(highlight => new DocumentHighlight(highlight));
|
|
491
491
|
}
|
|
492
492
|
/**
|
|
493
493
|
* Retrieve the symbols defined in the parsed document.
|
|
@@ -498,13 +498,13 @@ class Parse {
|
|
|
498
498
|
* @return An array of document symbols.
|
|
499
499
|
*/
|
|
500
500
|
get symbols() {
|
|
501
|
-
return (this.translator.metadata().symbols || []).map(
|
|
501
|
+
return (this.translator.metadata().symbols || []).map(symbol => new DocumentSymbol(symbol));
|
|
502
502
|
}
|
|
503
503
|
get _translator() {
|
|
504
504
|
return this.translator;
|
|
505
505
|
}
|
|
506
506
|
completions(position) {
|
|
507
|
-
return (this.translator.completions(position).completions || []).map(
|
|
507
|
+
return (this.translator.completions(position).completions || []).map(completion => new DocumentCompletion(completion));
|
|
508
508
|
}
|
|
509
509
|
helpContext(position) {
|
|
510
510
|
return this.translator.helpContext(position).helpContext;
|
|
@@ -561,8 +561,8 @@ class DocumentRange {
|
|
|
561
561
|
*/
|
|
562
562
|
toJSON() {
|
|
563
563
|
return {
|
|
564
|
-
|
|
565
|
-
|
|
564
|
+
start: this.start.toJSON(),
|
|
565
|
+
end: this.end.toJSON(),
|
|
566
566
|
};
|
|
567
567
|
}
|
|
568
568
|
}
|
|
@@ -591,7 +591,7 @@ class DocumentPosition {
|
|
|
591
591
|
* @return This position in JSON format.
|
|
592
592
|
*/
|
|
593
593
|
toJSON() {
|
|
594
|
-
return {
|
|
594
|
+
return { line: this.line, character: this.character };
|
|
595
595
|
}
|
|
596
596
|
}
|
|
597
597
|
exports.DocumentPosition = DocumentPosition;
|
|
@@ -605,7 +605,7 @@ class DocumentSymbol {
|
|
|
605
605
|
this._range = new DocumentRange(new DocumentPosition(documentSymbol.range.start.line, documentSymbol.range.start.character), new DocumentPosition(documentSymbol.range.end.line, documentSymbol.range.end.character));
|
|
606
606
|
this._type = documentSymbol.type;
|
|
607
607
|
this._name = documentSymbol.name;
|
|
608
|
-
this._children = documentSymbol.children.map(
|
|
608
|
+
this._children = documentSymbol.children.map(child => new DocumentSymbol(child));
|
|
609
609
|
}
|
|
610
610
|
/**
|
|
611
611
|
* @return The range of characters in the source Malloy document that define this symbol.
|
|
@@ -677,12 +677,12 @@ class PreparedResult {
|
|
|
677
677
|
*/
|
|
678
678
|
get resultExplore() {
|
|
679
679
|
if (this.inner.structs.length === 0) {
|
|
680
|
-
throw new Error(
|
|
680
|
+
throw new Error('Malformed query result.');
|
|
681
681
|
}
|
|
682
682
|
const explore = this.inner.structs[this.inner.structs.length - 1];
|
|
683
683
|
const namedExplore = {
|
|
684
684
|
...explore,
|
|
685
|
-
|
|
685
|
+
name: this.inner.queryName || explore.name,
|
|
686
686
|
};
|
|
687
687
|
// TODO `sourceExplore` is not fully-implemented yet -- it cannot
|
|
688
688
|
// handle cases where the source of the query is something other than
|
|
@@ -698,9 +698,9 @@ class PreparedResult {
|
|
|
698
698
|
const name = this.inner.sourceExplore;
|
|
699
699
|
const explore = this.modelDef.contents[name];
|
|
700
700
|
if (explore === undefined) {
|
|
701
|
-
throw new Error(
|
|
701
|
+
throw new Error('Malformed query result.');
|
|
702
702
|
}
|
|
703
|
-
if (explore.type ===
|
|
703
|
+
if (explore.type === 'struct') {
|
|
704
704
|
return new Explore(explore);
|
|
705
705
|
}
|
|
706
706
|
throw new Error(`'${name} is not an explore`);
|
|
@@ -720,7 +720,7 @@ exports.PreparedResult = PreparedResult;
|
|
|
720
720
|
*/
|
|
721
721
|
class EmptyURLReader {
|
|
722
722
|
async readURL(_url) {
|
|
723
|
-
throw new Error(
|
|
723
|
+
throw new Error('No files.');
|
|
724
724
|
}
|
|
725
725
|
}
|
|
726
726
|
exports.EmptyURLReader = EmptyURLReader;
|
|
@@ -763,7 +763,7 @@ class FixedConnectionMap {
|
|
|
763
763
|
connectionName = this.defaultConnectionName;
|
|
764
764
|
}
|
|
765
765
|
else {
|
|
766
|
-
throw new Error(
|
|
766
|
+
throw new Error('No default connection.');
|
|
767
767
|
}
|
|
768
768
|
}
|
|
769
769
|
const connection = this.connections.get(connectionName);
|
|
@@ -778,7 +778,7 @@ class FixedConnectionMap {
|
|
|
778
778
|
return this.getConnection(connectionName);
|
|
779
779
|
}
|
|
780
780
|
static fromArray(connections) {
|
|
781
|
-
return new FixedConnectionMap(new Map(connections.map(
|
|
781
|
+
return new FixedConnectionMap(new Map(connections.map(connection => [connection.name, connection])));
|
|
782
782
|
}
|
|
783
783
|
}
|
|
784
784
|
exports.FixedConnectionMap = FixedConnectionMap;
|
|
@@ -855,22 +855,22 @@ class Explore extends Entity {
|
|
|
855
855
|
}
|
|
856
856
|
getQueryByName(name) {
|
|
857
857
|
const internalQuery = {
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
858
|
+
type: 'query',
|
|
859
|
+
structRef: this.structDef,
|
|
860
|
+
pipeline: [
|
|
861
861
|
{
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
}
|
|
865
|
-
]
|
|
862
|
+
type: 'reduce',
|
|
863
|
+
fields: [name],
|
|
864
|
+
},
|
|
865
|
+
],
|
|
866
866
|
};
|
|
867
867
|
return new PreparedQuery(internalQuery, this.modelDef, name);
|
|
868
868
|
}
|
|
869
869
|
get modelDef() {
|
|
870
870
|
return {
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
871
|
+
name: 'generated_model',
|
|
872
|
+
exports: [],
|
|
873
|
+
contents: { [this.structDef.name]: this.structDef },
|
|
874
874
|
};
|
|
875
875
|
}
|
|
876
876
|
getSingleExploreModel() {
|
|
@@ -880,45 +880,45 @@ class Explore extends Entity {
|
|
|
880
880
|
var _a;
|
|
881
881
|
if (this._fieldMap === undefined) {
|
|
882
882
|
const sourceFields = ((_a = this.source) === null || _a === void 0 ? void 0 : _a.fieldMap) || new Map();
|
|
883
|
-
this._fieldMap = new Map(this.structDef.fields.map(
|
|
883
|
+
this._fieldMap = new Map(this.structDef.fields.map(fieldDef => {
|
|
884
884
|
const name = fieldDef.as || fieldDef.name;
|
|
885
885
|
const sourceField = sourceFields.get(fieldDef.name);
|
|
886
|
-
if (fieldDef.type ===
|
|
886
|
+
if (fieldDef.type === 'struct') {
|
|
887
887
|
return [name, new ExploreField(fieldDef, this, sourceField)];
|
|
888
888
|
}
|
|
889
|
-
else if (fieldDef.type ===
|
|
889
|
+
else if (fieldDef.type === 'turtle') {
|
|
890
890
|
return [name, new QueryField(fieldDef, this, sourceField)];
|
|
891
891
|
}
|
|
892
892
|
else {
|
|
893
|
-
if (fieldDef.type ===
|
|
893
|
+
if (fieldDef.type === 'string') {
|
|
894
894
|
return [name, new StringField(fieldDef, this, sourceField)];
|
|
895
895
|
}
|
|
896
|
-
else if (fieldDef.type ===
|
|
896
|
+
else if (fieldDef.type === 'number') {
|
|
897
897
|
return [name, new NumberField(fieldDef, this, sourceField)];
|
|
898
898
|
}
|
|
899
|
-
else if (fieldDef.type ===
|
|
899
|
+
else if (fieldDef.type === 'date') {
|
|
900
900
|
// TODO this is a hack
|
|
901
901
|
// Is this a bug? The extraction functions don't seem like they should return a
|
|
902
902
|
// field of type "date". Rather, they should be of type "number".
|
|
903
903
|
if (fieldDef.timeframe &&
|
|
904
|
-
[
|
|
904
|
+
['day_of_month', 'day_of_week', 'day_of_year'].includes(fieldDef.timeframe)) {
|
|
905
905
|
return [
|
|
906
906
|
name,
|
|
907
|
-
new NumberField({ ...fieldDef,
|
|
907
|
+
new NumberField({ ...fieldDef, type: 'number' }, this, sourceField),
|
|
908
908
|
];
|
|
909
909
|
}
|
|
910
910
|
return [name, new DateField(fieldDef, this, sourceField)];
|
|
911
911
|
}
|
|
912
|
-
else if (fieldDef.type ===
|
|
912
|
+
else if (fieldDef.type === 'timestamp') {
|
|
913
913
|
return [name, new TimestampField(fieldDef, this, sourceField)];
|
|
914
914
|
}
|
|
915
|
-
else if (fieldDef.type ===
|
|
915
|
+
else if (fieldDef.type === 'boolean') {
|
|
916
916
|
return [name, new BooleanField(fieldDef, this, sourceField)];
|
|
917
917
|
}
|
|
918
|
-
else if (fieldDef.type ===
|
|
918
|
+
else if (fieldDef.type === 'json') {
|
|
919
919
|
return [name, new JSONField(fieldDef, this, sourceField)];
|
|
920
920
|
}
|
|
921
|
-
else if (fieldDef.type ===
|
|
921
|
+
else if (fieldDef.type === 'unsupported') {
|
|
922
922
|
return [name, new UnsupportedField(fieldDef, this, sourceField)];
|
|
923
923
|
}
|
|
924
924
|
}
|
|
@@ -930,7 +930,7 @@ class Explore extends Entity {
|
|
|
930
930
|
return [...this.fieldMap.values()];
|
|
931
931
|
}
|
|
932
932
|
get intrinsicFields() {
|
|
933
|
-
return [...this.fieldMap.values()].filter(
|
|
933
|
+
return [...this.fieldMap.values()].filter(f => f.isIntrinsic());
|
|
934
934
|
}
|
|
935
935
|
getFieldByName(fieldName) {
|
|
936
936
|
const field = this.fieldMap.get(fieldName);
|
|
@@ -950,17 +950,17 @@ class Explore extends Entity {
|
|
|
950
950
|
}
|
|
951
951
|
get sourceRelationship() {
|
|
952
952
|
switch (this.structDef.structRelationship.type) {
|
|
953
|
-
case
|
|
953
|
+
case 'many':
|
|
954
954
|
return SourceRelationship.Many;
|
|
955
|
-
case
|
|
955
|
+
case 'one':
|
|
956
956
|
return SourceRelationship.One;
|
|
957
|
-
case
|
|
957
|
+
case 'cross':
|
|
958
958
|
return SourceRelationship.Cross;
|
|
959
|
-
case
|
|
959
|
+
case 'inline':
|
|
960
960
|
return SourceRelationship.Inline;
|
|
961
|
-
case
|
|
961
|
+
case 'nested':
|
|
962
962
|
return SourceRelationship.Nested;
|
|
963
|
-
case
|
|
963
|
+
case 'basetable':
|
|
964
964
|
return SourceRelationship.BaseTable;
|
|
965
965
|
}
|
|
966
966
|
}
|
|
@@ -999,19 +999,19 @@ class AtomicField extends Entity {
|
|
|
999
999
|
}
|
|
1000
1000
|
get type() {
|
|
1001
1001
|
switch (this.fieldTypeDef.type) {
|
|
1002
|
-
case
|
|
1002
|
+
case 'string':
|
|
1003
1003
|
return AtomicFieldType.String;
|
|
1004
|
-
case
|
|
1004
|
+
case 'boolean':
|
|
1005
1005
|
return AtomicFieldType.Boolean;
|
|
1006
|
-
case
|
|
1006
|
+
case 'date':
|
|
1007
1007
|
return AtomicFieldType.Date;
|
|
1008
|
-
case
|
|
1008
|
+
case 'timestamp':
|
|
1009
1009
|
return AtomicFieldType.Timestamp;
|
|
1010
|
-
case
|
|
1010
|
+
case 'number':
|
|
1011
1011
|
return AtomicFieldType.Number;
|
|
1012
|
-
case
|
|
1012
|
+
case 'json':
|
|
1013
1013
|
return AtomicFieldType.Json;
|
|
1014
|
-
case
|
|
1014
|
+
case 'unsupported':
|
|
1015
1015
|
return AtomicFieldType.Unsupported;
|
|
1016
1016
|
}
|
|
1017
1017
|
}
|
|
@@ -1042,16 +1042,16 @@ class AtomicField extends Entity {
|
|
|
1042
1042
|
// was the field generated from a measure in the previous query
|
|
1043
1043
|
sourceWasMeasure() {
|
|
1044
1044
|
var _a;
|
|
1045
|
-
return ((_a = this.fieldTypeDef.resultMetadata) === null || _a === void 0 ? void 0 : _a.fieldKind) ===
|
|
1045
|
+
return ((_a = this.fieldTypeDef.resultMetadata) === null || _a === void 0 ? void 0 : _a.fieldKind) === 'measure';
|
|
1046
1046
|
}
|
|
1047
1047
|
sourceWasMeasureLike() {
|
|
1048
1048
|
var _a, _b;
|
|
1049
|
-
return (((_a = this.fieldTypeDef.resultMetadata) === null || _a === void 0 ? void 0 : _a.fieldKind) ===
|
|
1050
|
-
((_b = this.fieldTypeDef.resultMetadata) === null || _b === void 0 ? void 0 : _b.fieldKind) ===
|
|
1049
|
+
return (((_a = this.fieldTypeDef.resultMetadata) === null || _a === void 0 ? void 0 : _a.fieldKind) === 'measure' ||
|
|
1050
|
+
((_b = this.fieldTypeDef.resultMetadata) === null || _b === void 0 ? void 0 : _b.fieldKind) === 'struct');
|
|
1051
1051
|
}
|
|
1052
1052
|
sourceWasDimension() {
|
|
1053
1053
|
var _a;
|
|
1054
|
-
return ((_a = this.fieldTypeDef.resultMetadata) === null || _a === void 0 ? void 0 : _a.fieldKind) ===
|
|
1054
|
+
return ((_a = this.fieldTypeDef.resultMetadata) === null || _a === void 0 ? void 0 : _a.fieldKind) === 'dimension';
|
|
1055
1055
|
}
|
|
1056
1056
|
hasParentExplore() {
|
|
1057
1057
|
return true;
|
|
@@ -1117,15 +1117,15 @@ class DateField extends AtomicField {
|
|
|
1117
1117
|
return undefined;
|
|
1118
1118
|
}
|
|
1119
1119
|
switch (this.fieldDateDef.timeframe) {
|
|
1120
|
-
case
|
|
1120
|
+
case 'day':
|
|
1121
1121
|
return DateTimeframe.Day;
|
|
1122
|
-
case
|
|
1122
|
+
case 'week':
|
|
1123
1123
|
return DateTimeframe.Week;
|
|
1124
|
-
case
|
|
1124
|
+
case 'month':
|
|
1125
1125
|
return DateTimeframe.Month;
|
|
1126
|
-
case
|
|
1126
|
+
case 'quarter':
|
|
1127
1127
|
return DateTimeframe.Quarter;
|
|
1128
|
-
case
|
|
1128
|
+
case 'year':
|
|
1129
1129
|
return DateTimeframe.Year;
|
|
1130
1130
|
}
|
|
1131
1131
|
}
|
|
@@ -1141,21 +1141,21 @@ class TimestampField extends AtomicField {
|
|
|
1141
1141
|
return undefined;
|
|
1142
1142
|
}
|
|
1143
1143
|
switch (this.fieldTimestampDef.timeframe) {
|
|
1144
|
-
case
|
|
1144
|
+
case 'day':
|
|
1145
1145
|
return TimestampTimeframe.Day;
|
|
1146
|
-
case
|
|
1146
|
+
case 'week':
|
|
1147
1147
|
return TimestampTimeframe.Week;
|
|
1148
|
-
case
|
|
1148
|
+
case 'month':
|
|
1149
1149
|
return TimestampTimeframe.Month;
|
|
1150
|
-
case
|
|
1150
|
+
case 'quarter':
|
|
1151
1151
|
return TimestampTimeframe.Quarter;
|
|
1152
|
-
case
|
|
1152
|
+
case 'year':
|
|
1153
1153
|
return TimestampTimeframe.Year;
|
|
1154
|
-
case
|
|
1154
|
+
case 'second':
|
|
1155
1155
|
return TimestampTimeframe.Second;
|
|
1156
|
-
case
|
|
1156
|
+
case 'hour':
|
|
1157
1157
|
return TimestampTimeframe.Hour;
|
|
1158
|
-
case
|
|
1158
|
+
case 'minute':
|
|
1159
1159
|
return TimestampTimeframe.Minute;
|
|
1160
1160
|
}
|
|
1161
1161
|
}
|
|
@@ -1251,17 +1251,17 @@ class ExploreField extends Explore {
|
|
|
1251
1251
|
}
|
|
1252
1252
|
get joinRelationship() {
|
|
1253
1253
|
switch (this.structDef.structRelationship.type) {
|
|
1254
|
-
case
|
|
1254
|
+
case 'one':
|
|
1255
1255
|
return JoinRelationship.OneToMany;
|
|
1256
|
-
case
|
|
1257
|
-
case
|
|
1256
|
+
case 'many':
|
|
1257
|
+
case 'cross':
|
|
1258
1258
|
return JoinRelationship.ManyToOne;
|
|
1259
|
-
case
|
|
1259
|
+
case 'inline':
|
|
1260
1260
|
return JoinRelationship.OneToOne;
|
|
1261
|
-
case
|
|
1261
|
+
case 'nested':
|
|
1262
1262
|
return JoinRelationship.ManyToOne;
|
|
1263
1263
|
default:
|
|
1264
|
-
throw new Error(
|
|
1264
|
+
throw new Error('An explore field must have a join relationship.');
|
|
1265
1265
|
}
|
|
1266
1266
|
}
|
|
1267
1267
|
isQueryField() {
|
|
@@ -1298,7 +1298,7 @@ class Runtime {
|
|
|
1298
1298
|
}
|
|
1299
1299
|
else {
|
|
1300
1300
|
connections = {
|
|
1301
|
-
|
|
1301
|
+
lookupConnection: () => Promise.resolve(arg),
|
|
1302
1302
|
};
|
|
1303
1303
|
}
|
|
1304
1304
|
}
|
|
@@ -1306,7 +1306,7 @@ class Runtime {
|
|
|
1306
1306
|
urlReader = new EmptyURLReader();
|
|
1307
1307
|
}
|
|
1308
1308
|
if (connections === undefined) {
|
|
1309
|
-
throw new Error(
|
|
1309
|
+
throw new Error('A LookupConnection<Connection> or Connection is required.');
|
|
1310
1310
|
}
|
|
1311
1311
|
this._urlReader = urlReader;
|
|
1312
1312
|
this._connections = connections;
|
|
@@ -1334,16 +1334,16 @@ class Runtime {
|
|
|
1334
1334
|
return new ModelMaterializer(this, async () => {
|
|
1335
1335
|
const parse = source instanceof URL
|
|
1336
1336
|
? await Malloy.parse({
|
|
1337
|
-
|
|
1338
|
-
|
|
1337
|
+
url: source,
|
|
1338
|
+
urlReader: this.urlReader,
|
|
1339
1339
|
})
|
|
1340
1340
|
: Malloy.parse({
|
|
1341
|
-
source
|
|
1341
|
+
source,
|
|
1342
1342
|
});
|
|
1343
1343
|
return Malloy.compile({
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
parse
|
|
1344
|
+
urlReader: this.urlReader,
|
|
1345
|
+
connections: this.connections,
|
|
1346
|
+
parse,
|
|
1347
1347
|
});
|
|
1348
1348
|
});
|
|
1349
1349
|
}
|
|
@@ -1352,7 +1352,7 @@ class Runtime {
|
|
|
1352
1352
|
// `ModelDef` to the world formally. For now, this should only
|
|
1353
1353
|
// be used in tests.
|
|
1354
1354
|
_loadModelFromModelDef(modelDef) {
|
|
1355
|
-
return new ModelMaterializer(this, async
|
|
1355
|
+
return new ModelMaterializer(this, async () => {
|
|
1356
1356
|
return new Model(modelDef, [], []);
|
|
1357
1357
|
});
|
|
1358
1358
|
}
|
|
@@ -1591,18 +1591,18 @@ class ModelMaterializer extends FluentState {
|
|
|
1591
1591
|
const connections = this.runtime.connections;
|
|
1592
1592
|
const parse = query instanceof URL
|
|
1593
1593
|
? await Malloy.parse({
|
|
1594
|
-
|
|
1595
|
-
urlReader
|
|
1594
|
+
url: query,
|
|
1595
|
+
urlReader,
|
|
1596
1596
|
})
|
|
1597
1597
|
: Malloy.parse({
|
|
1598
|
-
|
|
1598
|
+
source: query,
|
|
1599
1599
|
});
|
|
1600
1600
|
const model = await this.getModel();
|
|
1601
1601
|
const queryModel = await Malloy.compile({
|
|
1602
1602
|
urlReader,
|
|
1603
1603
|
connections,
|
|
1604
1604
|
parse,
|
|
1605
|
-
model
|
|
1605
|
+
model,
|
|
1606
1606
|
});
|
|
1607
1607
|
return queryModel.preparedQuery;
|
|
1608
1608
|
});
|
|
@@ -1611,7 +1611,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1611
1611
|
const model = await this.materialize();
|
|
1612
1612
|
const queryModel = new model_1.QueryModel(model._modelDef);
|
|
1613
1613
|
const schema = model.getExploreByName(sourceName).structDef;
|
|
1614
|
-
if (schema.structRelationship.type !==
|
|
1614
|
+
if (schema.structRelationship.type !== 'basetable') {
|
|
1615
1615
|
throw new Error("Expected schema's structRelationship type to be 'basetable'.");
|
|
1616
1616
|
}
|
|
1617
1617
|
const connectionName = schema.structRelationship.connectionName;
|
|
@@ -1621,12 +1621,12 @@ class ModelMaterializer extends FluentState {
|
|
|
1621
1621
|
async searchValueMap(sourceName, limit = 10) {
|
|
1622
1622
|
const model = await this.materialize();
|
|
1623
1623
|
const schema = model.getExploreByName(sourceName);
|
|
1624
|
-
if (schema.structDef.structRelationship.type !==
|
|
1624
|
+
if (schema.structDef.structRelationship.type !== 'basetable') {
|
|
1625
1625
|
throw new Error("Expected schema's structRelationship type to be 'basetable'.");
|
|
1626
1626
|
}
|
|
1627
|
-
let indexQuery =
|
|
1628
|
-
if (schema.getFieldByNameIfExists(
|
|
1629
|
-
indexQuery =
|
|
1627
|
+
let indexQuery = '{index: *}';
|
|
1628
|
+
if (schema.getFieldByNameIfExists('search_index')) {
|
|
1629
|
+
indexQuery = 'search_index';
|
|
1630
1630
|
}
|
|
1631
1631
|
const searchMapMalloy = `
|
|
1632
1632
|
query: ${sourceName}
|
|
@@ -1644,7 +1644,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1644
1644
|
}
|
|
1645
1645
|
`;
|
|
1646
1646
|
const result = await this.loadQuery(searchMapMalloy).run({
|
|
1647
|
-
|
|
1647
|
+
rowLimit: 1000,
|
|
1648
1648
|
});
|
|
1649
1649
|
return result._queryResult.result;
|
|
1650
1650
|
}
|
|
@@ -1889,8 +1889,8 @@ class SQLBlockMaterializer extends FluentState {
|
|
|
1889
1889
|
const connections = this.runtime.connections;
|
|
1890
1890
|
return Malloy.run({
|
|
1891
1891
|
connections,
|
|
1892
|
-
|
|
1893
|
-
options
|
|
1892
|
+
sqlStruct: sqlBlock,
|
|
1893
|
+
options,
|
|
1894
1894
|
});
|
|
1895
1895
|
}
|
|
1896
1896
|
async *runStream(options) {
|
|
@@ -1980,7 +1980,7 @@ class Result extends PreparedResult {
|
|
|
1980
1980
|
return this.inner.totalRows;
|
|
1981
1981
|
}
|
|
1982
1982
|
toJSON() {
|
|
1983
|
-
return {
|
|
1983
|
+
return { queryResult: this.inner, modelDef: this._modelDef };
|
|
1984
1984
|
}
|
|
1985
1985
|
static fromJSON({ queryResult, modelDef }) {
|
|
1986
1986
|
return new Result(queryResult, modelDef);
|
|
@@ -2001,7 +2001,7 @@ class Data {
|
|
|
2001
2001
|
if (this.isString()) {
|
|
2002
2002
|
return this;
|
|
2003
2003
|
}
|
|
2004
|
-
throw new Error(
|
|
2004
|
+
throw new Error('Not a string.');
|
|
2005
2005
|
}
|
|
2006
2006
|
isBoolean() {
|
|
2007
2007
|
return this instanceof DataBoolean;
|
|
@@ -2010,7 +2010,7 @@ class Data {
|
|
|
2010
2010
|
if (this.isBoolean()) {
|
|
2011
2011
|
return this;
|
|
2012
2012
|
}
|
|
2013
|
-
throw new Error(
|
|
2013
|
+
throw new Error('Not a boolean.');
|
|
2014
2014
|
}
|
|
2015
2015
|
isNumber() {
|
|
2016
2016
|
return this instanceof DataNumber;
|
|
@@ -2019,7 +2019,7 @@ class Data {
|
|
|
2019
2019
|
if (this.isNumber()) {
|
|
2020
2020
|
return this;
|
|
2021
2021
|
}
|
|
2022
|
-
throw new Error(
|
|
2022
|
+
throw new Error('Not a number.');
|
|
2023
2023
|
}
|
|
2024
2024
|
isTimestamp() {
|
|
2025
2025
|
return this instanceof DataTimestamp;
|
|
@@ -2028,7 +2028,7 @@ class Data {
|
|
|
2028
2028
|
if (this.isTimestamp()) {
|
|
2029
2029
|
return this;
|
|
2030
2030
|
}
|
|
2031
|
-
throw new Error(
|
|
2031
|
+
throw new Error('Not a timestamp.');
|
|
2032
2032
|
}
|
|
2033
2033
|
isDate() {
|
|
2034
2034
|
return this instanceof DataDate;
|
|
@@ -2037,7 +2037,7 @@ class Data {
|
|
|
2037
2037
|
if (this.isDate()) {
|
|
2038
2038
|
return this;
|
|
2039
2039
|
}
|
|
2040
|
-
throw new Error(
|
|
2040
|
+
throw new Error('Not a date.');
|
|
2041
2041
|
}
|
|
2042
2042
|
isNull() {
|
|
2043
2043
|
return this instanceof DataNull;
|
|
@@ -2049,7 +2049,7 @@ class Data {
|
|
|
2049
2049
|
if (this.isBytes()) {
|
|
2050
2050
|
return this;
|
|
2051
2051
|
}
|
|
2052
|
-
throw new Error(
|
|
2052
|
+
throw new Error('Not bytes.');
|
|
2053
2053
|
}
|
|
2054
2054
|
isRecord() {
|
|
2055
2055
|
return this instanceof DataRecord;
|
|
@@ -2058,7 +2058,7 @@ class Data {
|
|
|
2058
2058
|
if (this.isRecord()) {
|
|
2059
2059
|
return this;
|
|
2060
2060
|
}
|
|
2061
|
-
throw new Error(
|
|
2061
|
+
throw new Error('Not a record.');
|
|
2062
2062
|
}
|
|
2063
2063
|
isUnsupported() {
|
|
2064
2064
|
return this instanceof DataUnsupported;
|
|
@@ -2067,7 +2067,7 @@ class Data {
|
|
|
2067
2067
|
if (this.isUnsupported()) {
|
|
2068
2068
|
return this;
|
|
2069
2069
|
}
|
|
2070
|
-
throw new Error(
|
|
2070
|
+
throw new Error('Not unsupported.');
|
|
2071
2071
|
}
|
|
2072
2072
|
isArray() {
|
|
2073
2073
|
return this instanceof DataArray;
|
|
@@ -2076,13 +2076,13 @@ class Data {
|
|
|
2076
2076
|
if (this.isArray()) {
|
|
2077
2077
|
return this;
|
|
2078
2078
|
}
|
|
2079
|
-
throw new Error(
|
|
2079
|
+
throw new Error('Not an array.');
|
|
2080
2080
|
}
|
|
2081
2081
|
isArrayOrRecord() {
|
|
2082
2082
|
if (this instanceof DataArray || this instanceof DataRecord) {
|
|
2083
2083
|
return this;
|
|
2084
2084
|
}
|
|
2085
|
-
throw new Error(
|
|
2085
|
+
throw new Error('No Array or Record');
|
|
2086
2086
|
}
|
|
2087
2087
|
}
|
|
2088
2088
|
class ScalarData extends Data {
|
|
@@ -2153,10 +2153,10 @@ class DataTimestamp extends ScalarData {
|
|
|
2153
2153
|
if (this._value instanceof Date) {
|
|
2154
2154
|
return this._value;
|
|
2155
2155
|
}
|
|
2156
|
-
else if (typeof this._value ===
|
|
2156
|
+
else if (typeof this._value === 'number') {
|
|
2157
2157
|
return new Date(this._value);
|
|
2158
2158
|
}
|
|
2159
|
-
else if (typeof this._value !==
|
|
2159
|
+
else if (typeof this._value !== 'string') {
|
|
2160
2160
|
return new Date(this._value.value);
|
|
2161
2161
|
}
|
|
2162
2162
|
else {
|
|
@@ -2177,7 +2177,7 @@ class DataDate extends ScalarData {
|
|
|
2177
2177
|
if (this._value instanceof Date) {
|
|
2178
2178
|
return this._value;
|
|
2179
2179
|
}
|
|
2180
|
-
else if (typeof this._value !==
|
|
2180
|
+
else if (typeof this._value !== 'string') {
|
|
2181
2181
|
return new Date(this._value.value);
|
|
2182
2182
|
}
|
|
2183
2183
|
else {
|
|
@@ -2233,12 +2233,12 @@ class DataArray extends Data {
|
|
|
2233
2233
|
return {
|
|
2234
2234
|
next() {
|
|
2235
2235
|
if (currentIndex < queryData.length) {
|
|
2236
|
-
return {
|
|
2236
|
+
return { value: getRow(currentIndex++), done: false };
|
|
2237
2237
|
}
|
|
2238
2238
|
else {
|
|
2239
|
-
return {
|
|
2239
|
+
return { value: undefined, done: true };
|
|
2240
2240
|
}
|
|
2241
|
-
}
|
|
2241
|
+
},
|
|
2242
2242
|
};
|
|
2243
2243
|
}
|
|
2244
2244
|
async *inMemoryStream() {
|
|
@@ -2250,7 +2250,7 @@ class DataArray extends Data {
|
|
|
2250
2250
|
exports.DataArray = DataArray;
|
|
2251
2251
|
function getPath(data, path) {
|
|
2252
2252
|
for (const segment of path) {
|
|
2253
|
-
if (typeof segment ===
|
|
2253
|
+
if (typeof segment === 'number') {
|
|
2254
2254
|
data = data.array.row(segment);
|
|
2255
2255
|
}
|
|
2256
2256
|
else {
|
|
@@ -2274,7 +2274,7 @@ class DataRecord extends Data {
|
|
|
2274
2274
|
return getPath(this, path);
|
|
2275
2275
|
}
|
|
2276
2276
|
cell(fieldOrName) {
|
|
2277
|
-
const fieldName = typeof fieldOrName ===
|
|
2277
|
+
const fieldName = typeof fieldOrName === 'string' ? fieldOrName : fieldOrName.name;
|
|
2278
2278
|
const field = this._field.getFieldByName(fieldName);
|
|
2279
2279
|
const value = this.queryDataRow[fieldName];
|
|
2280
2280
|
if (value === null) {
|
|
@@ -2314,7 +2314,7 @@ class DataRecord extends Data {
|
|
|
2314
2314
|
throw new Error(`Internal Error: could not construct data column for field '${fieldName}'.`);
|
|
2315
2315
|
}
|
|
2316
2316
|
get value() {
|
|
2317
|
-
throw new Error(
|
|
2317
|
+
throw new Error('Not implemented;');
|
|
2318
2318
|
}
|
|
2319
2319
|
// Non repeating values show up as DataRecords
|
|
2320
2320
|
get field() {
|
|
@@ -2331,23 +2331,23 @@ class DataRecord extends Data {
|
|
|
2331
2331
|
if (!returned) {
|
|
2332
2332
|
returned = true;
|
|
2333
2333
|
return {
|
|
2334
|
-
|
|
2335
|
-
|
|
2334
|
+
value: getSelf(),
|
|
2335
|
+
done: false,
|
|
2336
2336
|
};
|
|
2337
2337
|
}
|
|
2338
2338
|
else {
|
|
2339
|
-
return {
|
|
2339
|
+
return { value: undefined, done: true };
|
|
2340
2340
|
}
|
|
2341
|
-
}
|
|
2341
|
+
},
|
|
2342
2342
|
};
|
|
2343
2343
|
}
|
|
2344
2344
|
}
|
|
2345
2345
|
exports.DataRecord = DataRecord;
|
|
2346
2346
|
function isURLReader(thing) {
|
|
2347
|
-
return
|
|
2347
|
+
return 'readURL' in thing;
|
|
2348
2348
|
}
|
|
2349
2349
|
function isLookupConnection(thing) {
|
|
2350
|
-
return
|
|
2350
|
+
return 'lookupConnection' in thing;
|
|
2351
2351
|
}
|
|
2352
2352
|
class DataWriter {
|
|
2353
2353
|
constructor(stream) {
|
|
@@ -2357,22 +2357,22 @@ class DataWriter {
|
|
|
2357
2357
|
exports.DataWriter = DataWriter;
|
|
2358
2358
|
class JSONWriter extends DataWriter {
|
|
2359
2359
|
async process(data) {
|
|
2360
|
-
this.stream.write(
|
|
2360
|
+
this.stream.write('[\n');
|
|
2361
2361
|
for await (const row of data) {
|
|
2362
2362
|
if (row.index !== undefined && row.index > 0) {
|
|
2363
|
-
this.stream.write(
|
|
2363
|
+
this.stream.write(',\n');
|
|
2364
2364
|
}
|
|
2365
2365
|
const json = JSON.stringify(row.toObject(), null, 2);
|
|
2366
|
-
const jsonLines = json.split(
|
|
2366
|
+
const jsonLines = json.split('\n');
|
|
2367
2367
|
for (let i = 0; i < jsonLines.length; i++) {
|
|
2368
2368
|
const line = jsonLines[i];
|
|
2369
2369
|
this.stream.write(` ${line}`);
|
|
2370
2370
|
if (i < jsonLines.length - 1) {
|
|
2371
|
-
this.stream.write(
|
|
2371
|
+
this.stream.write('\n');
|
|
2372
2372
|
}
|
|
2373
2373
|
}
|
|
2374
2374
|
}
|
|
2375
|
-
this.stream.write(
|
|
2375
|
+
this.stream.write('\n]\n');
|
|
2376
2376
|
this.stream.close();
|
|
2377
2377
|
}
|
|
2378
2378
|
}
|
|
@@ -2380,8 +2380,8 @@ exports.JSONWriter = JSONWriter;
|
|
|
2380
2380
|
class CSVWriter extends DataWriter {
|
|
2381
2381
|
constructor() {
|
|
2382
2382
|
super(...arguments);
|
|
2383
|
-
this.columnSeparator =
|
|
2384
|
-
this.rowSeparator =
|
|
2383
|
+
this.columnSeparator = ',';
|
|
2384
|
+
this.rowSeparator = '\n';
|
|
2385
2385
|
this.quoteCharacter = '"';
|
|
2386
2386
|
this.includeHeader = true;
|
|
2387
2387
|
}
|
|
@@ -2391,7 +2391,7 @@ class CSVWriter extends DataWriter {
|
|
|
2391
2391
|
const hasNewline = value.includes(this.rowSeparator);
|
|
2392
2392
|
const needsQuoting = hasInnerCommas || hasInnerQuote || hasNewline;
|
|
2393
2393
|
if (hasInnerQuote) {
|
|
2394
|
-
value = value.replace(new RegExp(this.quoteCharacter,
|
|
2394
|
+
value = value.replace(new RegExp(this.quoteCharacter, 'g'), this.quoteCharacter + this.quoteCharacter);
|
|
2395
2395
|
}
|
|
2396
2396
|
if (needsQuoting) {
|
|
2397
2397
|
value = this.quoteCharacter + value + this.quoteCharacter;
|
|
@@ -2400,7 +2400,7 @@ class CSVWriter extends DataWriter {
|
|
|
2400
2400
|
}
|
|
2401
2401
|
stringify(cell) {
|
|
2402
2402
|
if (cell.isNull()) {
|
|
2403
|
-
return
|
|
2403
|
+
return '';
|
|
2404
2404
|
}
|
|
2405
2405
|
else if (cell.isArray() ||
|
|
2406
2406
|
cell.isRecord() ||
|