@malloydata/malloy 0.0.22-dev230126015148 → 0.0.22-dev230206094309

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/package.json +2 -2
  2. package/dist/connection_utils.d.ts +0 -1
  3. package/dist/connection_utils.js +0 -66
  4. package/dist/dialect/dialect.d.ts +0 -66
  5. package/dist/dialect/dialect.js +0 -85
  6. package/dist/dialect/dialect_map.d.ts +0 -3
  7. package/dist/dialect/dialect_map.js +0 -45
  8. package/dist/dialect/duckdb.d.ts +0 -52
  9. package/dist/dialect/duckdb.js +0 -364
  10. package/dist/dialect/index.d.ts +0 -6
  11. package/dist/dialect/index.js +0 -37
  12. package/dist/dialect/postgres.d.ts +0 -52
  13. package/dist/dialect/postgres.js +0 -330
  14. package/dist/dialect/standardsql.d.ts +0 -49
  15. package/dist/dialect/standardsql.js +0 -381
  16. package/dist/index.d.ts +0 -10
  17. package/dist/index.js +0 -59
  18. package/dist/lang/ast/apply-expr.d.ts +0 -3
  19. package/dist/lang/ast/apply-expr.js +0 -34
  20. package/dist/lang/ast/ast-expr.d.ts +0 -206
  21. package/dist/lang/ast/ast-expr.js +0 -781
  22. package/dist/lang/ast/ast-main.d.ts +0 -915
  23. package/dist/lang/ast/ast-main.js +0 -3672
  24. package/dist/lang/ast/ast-time-expr.d.ts +0 -69
  25. package/dist/lang/ast/ast-time-expr.js +0 -389
  26. package/dist/lang/ast/ast-types.d.ts +0 -83
  27. package/dist/lang/ast/ast-types.js +0 -225
  28. package/dist/lang/ast/index.d.ts +0 -5
  29. package/dist/lang/ast/index.js +0 -44
  30. package/dist/lang/ast/time-utils.d.ts +0 -9
  31. package/dist/lang/ast/time-utils.js +0 -104
  32. package/dist/lang/field-utils.d.ts +0 -5
  33. package/dist/lang/field-utils.js +0 -43
  34. package/dist/lang/index.d.ts +0 -9
  35. package/dist/lang/index.js +0 -32
  36. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +0 -165
  37. package/dist/lang/lib/Malloy/MalloyLexer.js +0 -1232
  38. package/dist/lang/lib/Malloy/MalloyParser.d.ts +0 -1947
  39. package/dist/lang/lib/Malloy/MalloyParser.js +0 -11909
  40. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +0 -2022
  41. package/dist/lang/lib/Malloy/MalloyParserListener.js +0 -4
  42. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +0 -1274
  43. package/dist/lang/lib/Malloy/MalloyParserVisitor.js +0 -4
  44. package/dist/lang/parse-log.d.ts +0 -27
  45. package/dist/lang/parse-log.js +0 -51
  46. package/dist/lang/parse-malloy.d.ts +0 -236
  47. package/dist/lang/parse-malloy.js +0 -746
  48. package/dist/lang/parse-to-ast.d.ts +0 -155
  49. package/dist/lang/parse-to-ast.js +0 -990
  50. package/dist/lang/parse-tree-walkers/document-completion-walker.d.ts +0 -10
  51. package/dist/lang/parse-tree-walkers/document-completion-walker.js +0 -148
  52. package/dist/lang/parse-tree-walkers/document-help-context-walker.d.ts +0 -9
  53. package/dist/lang/parse-tree-walkers/document-help-context-walker.js +0 -107
  54. package/dist/lang/parse-tree-walkers/document-highlight-walker.d.ts +0 -83
  55. package/dist/lang/parse-tree-walkers/document-highlight-walker.js +0 -385
  56. package/dist/lang/parse-tree-walkers/document-symbol-walker.d.ts +0 -11
  57. package/dist/lang/parse-tree-walkers/document-symbol-walker.js +0 -182
  58. package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +0 -34
  59. package/dist/lang/parse-tree-walkers/explore-query-walker.js +0 -74
  60. package/dist/lang/parse-tree-walkers/find-external-references.d.ts +0 -11
  61. package/dist/lang/parse-tree-walkers/find-external-references.js +0 -61
  62. package/dist/lang/reference-list.d.ts +0 -10
  63. package/dist/lang/reference-list.js +0 -90
  64. package/dist/lang/space-field.d.ts +0 -17
  65. package/dist/lang/space-field.js +0 -127
  66. package/dist/lang/test/document-help-context-walker.spec.d.ts +0 -1
  67. package/dist/lang/test/document-help-context-walker.spec.js +0 -55
  68. package/dist/lang/test/document-symbol-walker.spec.d.ts +0 -1
  69. package/dist/lang/test/document-symbol-walker.spec.js +0 -110
  70. package/dist/lang/test/field-symbols.spec.d.ts +0 -1
  71. package/dist/lang/test/field-symbols.spec.js +0 -180
  72. package/dist/lang/test/parse.spec.d.ts +0 -14
  73. package/dist/lang/test/parse.spec.js +0 -2134
  74. package/dist/lang/test/test-translator.d.ts +0 -38
  75. package/dist/lang/test/test-translator.js +0 -344
  76. package/dist/lang/zone.d.ts +0 -57
  77. package/dist/lang/zone.js +0 -107
  78. package/dist/malloy.d.ts +0 -1146
  79. package/dist/malloy.js +0 -2413
  80. package/dist/model/index.d.ts +0 -2
  81. package/dist/model/index.js +0 -45
  82. package/dist/model/malloy_query.d.ts +0 -351
  83. package/dist/model/malloy_query.js +0 -3174
  84. package/dist/model/malloy_types.d.ts +0 -551
  85. package/dist/model/malloy_types.js +0 -378
  86. package/dist/model/sql_block.d.ts +0 -7
  87. package/dist/model/sql_block.js +0 -56
  88. package/dist/model/utils.d.ts +0 -22
  89. package/dist/model/utils.js +0 -102
  90. package/dist/run_sql_options.d.ts +0 -3
  91. package/dist/run_sql_options.js +0 -25
  92. package/dist/runtime_types.d.ts +0 -105
  93. package/dist/runtime_types.js +0 -25
@@ -1,11 +0,0 @@
1
- import { CommonTokenStream } from "antlr4ts";
2
- import type { ParseTree } from "antlr4ts/tree";
3
- import { DocumentRange } from "../../model/malloy_types";
4
- import { MalloyTranslation } from "../parse-malloy";
5
- declare type References = Record<string, DocumentRange>;
6
- interface FinderFound {
7
- tables?: References;
8
- urls?: References;
9
- }
10
- export declare function findReferences(trans: MalloyTranslation, tokens: CommonTokenStream, parseTree: ParseTree): FinderFound | null;
11
- export {};
@@ -1,61 +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.findReferences = void 0;
26
- const ParseTreeWalker_1 = require("antlr4ts/tree/ParseTreeWalker");
27
- class FindExternalReferences {
28
- constructor(trans, tokens) {
29
- this.trans = trans;
30
- this.tokens = tokens;
31
- this.needTables = {};
32
- this.needImports = {};
33
- }
34
- enterTableName(pcx) {
35
- const tableName = this.tokens.getText(pcx).slice(1, -1);
36
- if (!this.needTables[tableName]) {
37
- this.needTables[tableName] = this.trans.rangeFromContext(pcx);
38
- }
39
- }
40
- enterImportURL(pcx) {
41
- const url = JSON.parse(pcx.JSON_STRING().text);
42
- if (!this.needImports[url]) {
43
- this.needImports[url] = this.trans.rangeFromContext(pcx);
44
- }
45
- }
46
- }
47
- function findReferences(trans, tokens, parseTree) {
48
- const finder = new FindExternalReferences(trans, tokens);
49
- const listener = finder;
50
- ParseTreeWalker_1.ParseTreeWalker.DEFAULT.walk(listener, parseTree);
51
- let refs = {};
52
- if (Object.keys(finder.needTables).length > 0) {
53
- refs = { tables: finder.needTables };
54
- }
55
- if (Object.keys(finder.needImports).length > 0) {
56
- refs = { ...refs, urls: finder.needImports };
57
- }
58
- return Object.keys(refs).length > 0 ? refs : null;
59
- }
60
- exports.findReferences = findReferences;
61
- //# sourceMappingURL=find-external-references.js.map
@@ -1,10 +0,0 @@
1
- import { DocumentReference, DocumentPosition } from "../model";
2
- export declare class ReferenceList {
3
- private readonly sourceURL;
4
- constructor(sourceURL: string);
5
- private readonly references;
6
- private findIndexBefore;
7
- add(reference: DocumentReference): void;
8
- private isPositionEqual;
9
- find(position: DocumentPosition): DocumentReference | undefined;
10
- }
@@ -1,90 +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.ReferenceList = void 0;
26
- class ReferenceList {
27
- constructor(sourceURL) {
28
- this.sourceURL = sourceURL;
29
- // These should always be sorted by their end positions
30
- this.references = [];
31
- }
32
- findIndexBefore(position) {
33
- let low = 0;
34
- let high = this.references.length;
35
- while (low < high) {
36
- const middle = Math.floor((low + high) / 2);
37
- const compare = this.references[middle].location.range.end;
38
- if (compare.line < position.line ||
39
- (compare.line === position.line &&
40
- compare.character < position.character)) {
41
- low = middle + 1;
42
- }
43
- else {
44
- high = middle;
45
- }
46
- }
47
- return low;
48
- }
49
- add(reference) {
50
- // Ignore any reference in another file
51
- if (reference.location.url !== this.sourceURL) {
52
- return;
53
- }
54
- const insertIndex = this.findIndexBefore(reference.location.range.end);
55
- // Ignore duplicate references
56
- if (insertIndex < this.references.length &&
57
- this.isPositionEqual(reference, this.references[insertIndex])) {
58
- return;
59
- }
60
- this.references.splice(insertIndex, 0, reference);
61
- }
62
- isPositionEqual(referenceA, referenceB) {
63
- const rangeA = referenceA.location.range;
64
- const rangeB = referenceB.location.range;
65
- return (rangeA.start.line === rangeB.start.line &&
66
- rangeA.start.character === rangeB.start.character &&
67
- rangeA.end.line === rangeB.end.line &&
68
- rangeA.end.character === rangeB.end.character);
69
- }
70
- find(position) {
71
- // Here we assume that references DO NOT overlap. And then we do a binary
72
- // search to find the one we're looking for.
73
- const index = this.findIndexBefore(position);
74
- if (index === this.references.length) {
75
- return undefined;
76
- }
77
- const reference = this.references[index];
78
- if (reference.location.range.start.line <= position.line &&
79
- reference.location.range.end.line >= position.line &&
80
- (position.line !== reference.location.range.start.line ||
81
- position.character >= reference.location.range.start.character) &&
82
- (position.line !== reference.location.range.end.line ||
83
- position.character <= reference.location.range.end.character)) {
84
- return reference;
85
- }
86
- return undefined;
87
- }
88
- }
89
- exports.ReferenceList = ReferenceList;
90
- //# sourceMappingURL=reference-list.js.map
@@ -1,17 +0,0 @@
1
- import * as model from "../model/malloy_types";
2
- import { FieldReference, FieldSpace, FieldType, SpaceField } from "./ast/ast-main";
3
- /**
4
- * FilteredAliasedName
5
- */
6
- export declare class FANSPaceField extends SpaceField {
7
- readonly ref: FieldReference;
8
- readonly inSpace: FieldSpace;
9
- as?: string;
10
- filterList?: model.FilterExpression[];
11
- constructor(ref: FieldReference, inSpace: FieldSpace, refInit?: Partial<model.FilteredAliasedName>);
12
- name(): string;
13
- private filtersPresent;
14
- fieldDef(): model.FieldDef | undefined;
15
- getQueryFieldDef(_fs: FieldSpace): model.QueryFieldDef;
16
- type(): FieldType;
17
- }
@@ -1,127 +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
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- var desc = Object.getOwnPropertyDescriptor(m, k);
27
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
- desc = { enumerable: true, get: function() { return m[k]; } };
29
- }
30
- Object.defineProperty(o, k2, desc);
31
- }) : (function(o, m, k, k2) {
32
- if (k2 === undefined) k2 = k;
33
- o[k2] = m[k];
34
- }));
35
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
- Object.defineProperty(o, "default", { enumerable: true, value: v });
37
- }) : function(o, v) {
38
- o["default"] = v;
39
- });
40
- var __importStar = (this && this.__importStar) || function (mod) {
41
- if (mod && mod.__esModule) return mod;
42
- var result = {};
43
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
- __setModuleDefault(result, mod);
45
- return result;
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.FANSPaceField = void 0;
49
- const model = __importStar(require("../model/malloy_types"));
50
- const ast_main_1 = require("./ast/ast-main");
51
- // "Space Fields" are a field in a field space
52
- /**
53
- * FilteredAliasedName
54
- */
55
- class FANSPaceField extends ast_main_1.SpaceField {
56
- constructor(ref, inSpace, refInit) {
57
- super();
58
- this.ref = ref;
59
- this.inSpace = inSpace;
60
- Object.assign(this, refInit);
61
- }
62
- name() {
63
- return this.as || this.ref.refString;
64
- }
65
- filtersPresent() {
66
- return this.filterList && this.filterList.length > 0;
67
- }
68
- fieldDef() {
69
- if (this.as === undefined) {
70
- return undefined;
71
- }
72
- const fromField = this.ref.getField(this.inSpace).found;
73
- if (fromField === undefined) {
74
- // TODO should errror
75
- return undefined;
76
- }
77
- const fieldTypeInfo = fromField.type();
78
- const fieldType = fieldTypeInfo.type;
79
- // TODO starting to feel like this should be a method call on a spaceentry
80
- if (model.isAtomicFieldType(fieldType)) {
81
- if (fromField instanceof ast_main_1.SpaceParam) {
82
- return {
83
- type: fieldType,
84
- name: this.as,
85
- e: [{ type: "parameter", path: this.ref.refString }],
86
- expressionType: "scalar",
87
- };
88
- }
89
- let fieldExpr = [{ type: "field", path: this.ref.refString }];
90
- if (this.filtersPresent() && this.filterList) {
91
- const newfieldExpr = [
92
- {
93
- type: "filterExpression",
94
- filterList: this.filterList,
95
- e: fieldExpr,
96
- },
97
- ];
98
- fieldExpr = newfieldExpr;
99
- }
100
- return {
101
- type: fieldType,
102
- name: this.as,
103
- e: fieldExpr,
104
- expressionType: fieldTypeInfo.expressionType,
105
- };
106
- }
107
- return undefined;
108
- }
109
- getQueryFieldDef(_fs) {
110
- // TODO if this reference is to a field which does not exist
111
- // it needs to be an error SOMEWHERE
112
- const n = { name: this.ref.refString };
113
- if (this.filtersPresent()) {
114
- n.filterList = this.filterList;
115
- }
116
- if (this.as) {
117
- n.as = this.as;
118
- }
119
- return n.as || n.filterList ? n : this.ref.refString;
120
- }
121
- type() {
122
- const field = this.ref.getField(this.inSpace).found;
123
- return (field === null || field === void 0 ? void 0 : field.type()) || { type: "unknown" };
124
- }
125
- }
126
- exports.FANSPaceField = FANSPaceField;
127
- //# sourceMappingURL=space-field.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,55 +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
- const test_translator_1 = require("./test-translator");
26
- function testHelpContext(source, position, type, token) {
27
- const doc = new test_translator_1.TestTranslator(source.code);
28
- expect(doc.logger.hasErrors()).toBeFalsy();
29
- const helpContext = doc.helpContext(position).helpContext;
30
- expect(helpContext).toEqual({ type, token });
31
- }
32
- const source = `source: foo is table('bar') {
33
- where: bazz ~ 'biff'
34
- query: foo is {
35
- group_by: bazz
36
- where: bop ~ 'blat'
37
- }
38
- }
39
-
40
- query: bar {
41
- group_by: bazz
42
- }`;
43
- test("Supports model properties", () => {
44
- testHelpContext((0, test_translator_1.markSource) `${source}`, { line: 0, character: 1 }, "model_property", "source:");
45
- testHelpContext((0, test_translator_1.markSource) `${source}`, { line: 8, character: 1 }, "model_property", "query:");
46
- });
47
- test("Supports explore properties", () => {
48
- testHelpContext((0, test_translator_1.markSource) `${source}`, { line: 1, character: 3 }, "explore_property", "where:");
49
- testHelpContext((0, test_translator_1.markSource) `${source}`, { line: 2, character: 3 }, "explore_property", "query:");
50
- });
51
- test("Supports query properties", () => {
52
- testHelpContext((0, test_translator_1.markSource) `${source}`, { line: 3, character: 5 }, "query_property", "group_by:");
53
- testHelpContext((0, test_translator_1.markSource) `${source}`, { line: 4, character: 5 }, "query_property", "where:");
54
- });
55
- //# sourceMappingURL=document-help-context-walker.spec.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,110 +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
- const test_translator_1 = require("./test-translator");
26
- class MalloyExplore extends test_translator_1.TestTranslator {
27
- constructor(src) {
28
- super(src);
29
- }
30
- get symbols() {
31
- const md = this.metadata();
32
- return md.symbols || [];
33
- }
34
- }
35
- function testSymbol(source, name, type, path) {
36
- const doc = new MalloyExplore(source.code);
37
- let current = { children: doc.symbols };
38
- path.forEach((segment) => {
39
- current = current.children[segment];
40
- });
41
- expect(doc.logger.hasErrors()).toBeFalsy();
42
- expect(current).toMatchObject({
43
- name,
44
- range: source.locations[0].range,
45
- type,
46
- });
47
- }
48
- test("explore symbols are included", () => {
49
- testSymbol((0, test_translator_1.markSource) `explore: ${"flights is table('my.table.flights')"}`, "flights", "explore", [0]);
50
- });
51
- test("query symbols are included", () => {
52
- testSymbol((0, test_translator_1.markSource) `query: ${"flights_by_carrier is flights -> by_carrier"}`, "flights_by_carrier", "query", [0]);
53
- });
54
- test("expression field defs are included", () => {
55
- testSymbol((0, test_translator_1.markSource) `
56
- explore: flights is table('my.table.flights') {
57
- dimension: ${"one is 1"}
58
- }
59
- `, "one", "field", [0, 0]);
60
- });
61
- test("renamed fields are included", () => {
62
- testSymbol((0, test_translator_1.markSource) `
63
- explore: flights is table('my.table.flights') {
64
- rename: ${"field_two is field_2"}
65
- }
66
- `, "field_two", "field", [0, 0]);
67
- });
68
- test("name only fields are included", () => {
69
- testSymbol((0, test_translator_1.markSource) `
70
- explore: flights is table('my.table.flights') {
71
- dimension: ${"field_two is field_2"}
72
- }
73
- `, "field_two", "field", [0, 0]);
74
- });
75
- test("turtle fields are included", () => {
76
- testSymbol((0, test_translator_1.markSource) `
77
- explore: flights is table('my.table.flights') {
78
- query: ${"my_turtle is { group_by: a }"}
79
- }
80
- `, "my_turtle", "query", [0, 0]);
81
- });
82
- test("turtle children fields are included", () => {
83
- testSymbol((0, test_translator_1.markSource) `
84
- explore: flights is table('my.table.flights') {
85
- query: my_turtle is { group_by: ${"a"} }
86
- }
87
- `, "a", "field", [0, 0, 0]);
88
- });
89
- test("turtle children turtles are included", () => {
90
- testSymbol((0, test_translator_1.markSource) `
91
- explore: flights is table('my.table.flights') {
92
- query: my_turtle is { nest: ${"inner_turtle is { group_by: a }"} }
93
- }
94
- `, "inner_turtle", "query", [0, 0, 0]);
95
- });
96
- test("join withs are included", () => {
97
- testSymbol((0, test_translator_1.markSource) `
98
- explore: flights is table('my.table.flights') {
99
- join_one: ${"a is b with c"}
100
- }
101
- `, "a", "join", [0, 0]);
102
- });
103
- test("join ons are included", () => {
104
- testSymbol((0, test_translator_1.markSource) `
105
- explore: flights is table('my.table.flights') {
106
- join_one: ${"a is b on c"}
107
- }
108
- `, "a", "join", [0, 0]);
109
- });
110
- //# sourceMappingURL=document-symbol-walker.spec.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,180 +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
- const ast_main_1 = require("../ast/ast-main");
26
- /*
27
- ** A set of tests to make sure structdefs can become fieldspaces
28
- ** and the fieldspace produces the same strcutdef
29
- */
30
- describe("structdef comprehension", () => {
31
- function mkStructDef(field) {
32
- return {
33
- type: "struct",
34
- name: "test",
35
- dialect: "standardsql",
36
- structSource: { type: "table", tablePath: "test" },
37
- structRelationship: { type: "basetable", connectionName: "test" },
38
- fields: [field],
39
- };
40
- }
41
- function fieldRef(fieldPath) {
42
- return fieldPath.split(".").map((name) => new ast_main_1.FieldName(name));
43
- }
44
- test(`import string field`, () => {
45
- const field = {
46
- name: "t",
47
- type: "string",
48
- };
49
- const struct = mkStructDef(field);
50
- const space = new ast_main_1.StaticSpace(struct);
51
- expect(space.lookup(fieldRef("t")).found).toBeInstanceOf(ast_main_1.ColumnSpaceField);
52
- const oField = space.structDef().fields[0];
53
- expect(oField).toEqual(field);
54
- });
55
- test(`import float field`, () => {
56
- const field = {
57
- name: "t",
58
- type: "number",
59
- numberType: "float",
60
- };
61
- const struct = mkStructDef(field);
62
- const space = new ast_main_1.StaticSpace(struct);
63
- expect(space.lookup(fieldRef("t")).found).toBeInstanceOf(ast_main_1.ColumnSpaceField);
64
- const oField = space.structDef().fields[0];
65
- expect(oField).toEqual(field);
66
- });
67
- test(`import integer field`, () => {
68
- const field = {
69
- name: "t",
70
- type: "number",
71
- numberType: "integer",
72
- };
73
- const struct = mkStructDef(field);
74
- const space = new ast_main_1.StaticSpace(struct);
75
- expect(space.lookup(fieldRef("t")).found).toBeInstanceOf(ast_main_1.ColumnSpaceField);
76
- const oField = space.structDef().fields[0];
77
- expect(oField).toEqual(field);
78
- });
79
- test(`import boolean field`, () => {
80
- const field = {
81
- name: "t",
82
- type: "boolean",
83
- };
84
- const struct = mkStructDef(field);
85
- const space = new ast_main_1.StaticSpace(struct);
86
- expect(space.lookup(fieldRef("t")).found).toBeInstanceOf(ast_main_1.ColumnSpaceField);
87
- const oField = space.structDef().fields[0];
88
- expect(oField).toEqual(field);
89
- });
90
- test(`import nested field`, () => {
91
- const field = {
92
- name: "t",
93
- type: "struct",
94
- dialect: "standardsql",
95
- structRelationship: { type: "nested", field: "a", isArray: false },
96
- structSource: { type: "nested" },
97
- fields: [{ type: "string", name: "b" }],
98
- };
99
- const struct = mkStructDef(field);
100
- const space = new ast_main_1.StaticSpace(struct);
101
- expect(space.lookup(fieldRef("t.b")).found).toBeInstanceOf(ast_main_1.ColumnSpaceField);
102
- const oField = space.structDef().fields[0];
103
- expect(oField).toEqual(field);
104
- });
105
- test(`import inline field`, () => {
106
- const field = {
107
- name: "t",
108
- type: "struct",
109
- dialect: "standardsql",
110
- structRelationship: { type: "inline" },
111
- structSource: { type: "inline" },
112
- fields: [{ type: "string", name: "a" }],
113
- };
114
- const struct = mkStructDef(field);
115
- const space = new ast_main_1.StaticSpace(struct);
116
- expect(space.lookup(fieldRef("t.a")).found).toBeInstanceOf(ast_main_1.ColumnSpaceField);
117
- const oField = space.structDef().fields[0];
118
- expect(oField).toEqual(field);
119
- });
120
- test(`import join field`, () => {
121
- const field = {
122
- name: "t",
123
- type: "struct",
124
- dialect: "standardsql",
125
- structRelationship: {
126
- type: "one",
127
- onExpression: [
128
- { type: "field", path: "aKey" },
129
- "=",
130
- { type: "field", path: "t.a" },
131
- ],
132
- },
133
- structSource: { type: "table", tablePath: "t" },
134
- fields: [{ type: "string", name: "a" }],
135
- };
136
- const struct = mkStructDef(field);
137
- const space = new ast_main_1.StaticSpace(struct);
138
- expect(space.lookup(fieldRef("t.a")).found).toBeInstanceOf(ast_main_1.ColumnSpaceField);
139
- const oField = space.structDef().fields[0];
140
- expect(oField).toEqual(field);
141
- });
142
- test(`import query stage field`, () => {
143
- const field = {
144
- name: "t",
145
- type: "turtle",
146
- pipeline: [
147
- {
148
- type: "reduce",
149
- fields: ["a"],
150
- },
151
- ],
152
- };
153
- const struct = mkStructDef(field);
154
- const space = new ast_main_1.StaticSpace(struct);
155
- expect(space.lookup(fieldRef("t")).found).toBeInstanceOf(ast_main_1.QueryFieldStruct);
156
- const oField = space.structDef().fields[0];
157
- expect(oField).toEqual(field);
158
- });
159
- test("import struct with parameters", () => {
160
- const struct = mkStructDef({ name: "f", type: "string" });
161
- struct.parameters = {
162
- cReqStr: {
163
- name: "cReqStr",
164
- type: "string",
165
- value: null,
166
- constant: false,
167
- },
168
- cOptStr: {
169
- name: "cOptStr",
170
- type: "string",
171
- value: ["value"],
172
- constant: false,
173
- },
174
- };
175
- const space = new ast_main_1.StaticSpace(struct);
176
- expect(space.lookup(fieldRef("cReqStr")).found).toBeInstanceOf(ast_main_1.DefinedParameter);
177
- expect(space.lookup(fieldRef("cOptStr")).found).toBeInstanceOf(ast_main_1.DefinedParameter);
178
- });
179
- });
180
- //# sourceMappingURL=field-symbols.spec.js.map