@malloydata/malloy 0.0.240-dev250311202829 → 0.0.240-dev250311214430

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 (66) hide show
  1. package/dist/api/core.d.ts +1 -0
  2. package/dist/api/core.js +2 -1
  3. package/dist/lang/malloy-parse-info.d.ts +2 -10
  4. package/dist/lang/malloy-to-ast.d.ts +1 -0
  5. package/dist/lang/malloy-to-ast.js +9 -6
  6. package/dist/lang/malloy-to-stable-query.d.ts +76 -0
  7. package/dist/lang/malloy-to-stable-query.js +660 -0
  8. package/dist/lang/parse-log.d.ts +1 -0
  9. package/dist/lang/parse-malloy.d.ts +2 -9
  10. package/dist/lang/parse-malloy.js +7 -112
  11. package/dist/lang/parse-tree-walkers/model-annotation-walker.js +1 -1
  12. package/dist/lang/run-malloy-parser.d.ts +3 -0
  13. package/dist/lang/run-malloy-parser.js +53 -0
  14. package/dist/lang/syntax-errors/malloy-parser-error-listener.d.ts +4 -3
  15. package/dist/lang/syntax-errors/malloy-parser-error-listener.js +8 -4
  16. package/dist/lang/utils.d.ts +27 -1
  17. package/dist/lang/utils.js +78 -1
  18. package/package.json +3 -3
  19. package/dist/api/asynchronous.spec.d.ts +0 -1
  20. package/dist/api/asynchronous.spec.js +0 -240
  21. package/dist/api/sessioned.spec.d.ts +0 -1
  22. package/dist/api/sessioned.spec.js +0 -476
  23. package/dist/api/stateless.spec.d.ts +0 -1
  24. package/dist/api/stateless.spec.js +0 -400
  25. package/dist/lang/test/annotation.spec.d.ts +0 -14
  26. package/dist/lang/test/annotation.spec.js +0 -809
  27. package/dist/lang/test/composite-field-usage.spec.d.ts +0 -1
  28. package/dist/lang/test/composite-field-usage.spec.js +0 -261
  29. package/dist/lang/test/document-help-context-walker.spec.d.ts +0 -1
  30. package/dist/lang/test/document-help-context-walker.spec.js +0 -55
  31. package/dist/lang/test/document-symbol-walker.spec.d.ts +0 -1
  32. package/dist/lang/test/document-symbol-walker.spec.js +0 -209
  33. package/dist/lang/test/expressions.spec.d.ts +0 -1
  34. package/dist/lang/test/expressions.spec.js +0 -1181
  35. package/dist/lang/test/field-symbols.spec.d.ts +0 -1
  36. package/dist/lang/test/field-symbols.spec.js +0 -194
  37. package/dist/lang/test/find-table-path-walker.spec.d.ts +0 -1
  38. package/dist/lang/test/find-table-path-walker.spec.js +0 -50
  39. package/dist/lang/test/imports.spec.d.ts +0 -1
  40. package/dist/lang/test/imports.spec.js +0 -283
  41. package/dist/lang/test/lenses.spec.d.ts +0 -1
  42. package/dist/lang/test/lenses.spec.js +0 -384
  43. package/dist/lang/test/literals.spec.d.ts +0 -1
  44. package/dist/lang/test/literals.spec.js +0 -267
  45. package/dist/lang/test/locations.spec.d.ts +0 -1
  46. package/dist/lang/test/locations.spec.js +0 -679
  47. package/dist/lang/test/model-annotation-walker.spec.d.ts +0 -1
  48. package/dist/lang/test/model-annotation-walker.spec.js +0 -46
  49. package/dist/lang/test/model_serialization.spec.d.ts +0 -5
  50. package/dist/lang/test/model_serialization.spec.js +0 -116
  51. package/dist/lang/test/parameters.spec.d.ts +0 -1
  52. package/dist/lang/test/parameters.spec.js +0 -619
  53. package/dist/lang/test/parse.spec.d.ts +0 -1
  54. package/dist/lang/test/parse.spec.js +0 -893
  55. package/dist/lang/test/pretranslate.spec.d.ts +0 -1
  56. package/dist/lang/test/pretranslate.spec.js +0 -80
  57. package/dist/lang/test/query.spec.d.ts +0 -1
  58. package/dist/lang/test/query.spec.js +0 -1149
  59. package/dist/lang/test/source.spec.d.ts +0 -1
  60. package/dist/lang/test/source.spec.js +0 -570
  61. package/dist/lang/test/sql-block.spec.d.ts +0 -1
  62. package/dist/lang/test/sql-block.spec.js +0 -145
  63. package/dist/lang/test/syntax-errors.spec.d.ts +0 -1
  64. package/dist/lang/test/syntax-errors.spec.js +0 -142
  65. package/dist/model/utils.spec.d.ts +0 -1
  66. package/dist/model/utils.spec.js +0 -38
@@ -1 +0,0 @@
1
- export {};
@@ -1,194 +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 static_space_1 = require("../ast/field-space/static-space");
26
- const column_space_field_1 = require("../ast/field-space/column-space-field");
27
- const field_space_1 = require("../ast/types/field-space");
28
- const ir_view_field_1 = require("../ast/field-space/ir-view-field");
29
- const space_param_1 = require("../ast/types/space-param");
30
- /*
31
- ** A set of tests to make sure structdefs can become fieldspaces
32
- ** and the fieldspace produces the same strcutdef
33
- */
34
- describe('structdef comprehension', () => {
35
- function mkStructDef(field) {
36
- return {
37
- type: 'table',
38
- name: 'test',
39
- dialect: 'standardsql',
40
- tablePath: 'test',
41
- connection: 'test',
42
- fields: [field],
43
- };
44
- }
45
- function fieldRef(fieldPath) {
46
- return fieldPath.split('.').map(name => new field_space_1.FieldName(name));
47
- }
48
- test('import string field', () => {
49
- const field = {
50
- name: 't',
51
- type: 'string',
52
- };
53
- const struct = mkStructDef(field);
54
- const space = new static_space_1.StaticSourceSpace(struct);
55
- expect(space.lookup(fieldRef('t')).found).toBeInstanceOf(column_space_field_1.ColumnSpaceField);
56
- const oField = space.structDef().fields[0];
57
- expect(oField).toEqual(field);
58
- });
59
- test('import float field', () => {
60
- const field = {
61
- name: 't',
62
- type: 'number',
63
- numberType: 'float',
64
- };
65
- const struct = mkStructDef(field);
66
- const space = new static_space_1.StaticSourceSpace(struct);
67
- expect(space.lookup(fieldRef('t')).found).toBeInstanceOf(column_space_field_1.ColumnSpaceField);
68
- const oField = space.structDef().fields[0];
69
- expect(oField).toEqual(field);
70
- });
71
- test('import integer field', () => {
72
- const field = {
73
- name: 't',
74
- type: 'number',
75
- numberType: 'integer',
76
- };
77
- const struct = mkStructDef(field);
78
- const space = new static_space_1.StaticSourceSpace(struct);
79
- expect(space.lookup(fieldRef('t')).found).toBeInstanceOf(column_space_field_1.ColumnSpaceField);
80
- const oField = space.structDef().fields[0];
81
- expect(oField).toEqual(field);
82
- });
83
- test('import boolean field', () => {
84
- const field = {
85
- name: 't',
86
- type: 'boolean',
87
- };
88
- const struct = mkStructDef(field);
89
- const space = new static_space_1.StaticSourceSpace(struct);
90
- expect(space.lookup(fieldRef('t')).found).toBeInstanceOf(column_space_field_1.ColumnSpaceField);
91
- const oField = space.structDef().fields[0];
92
- expect(oField).toEqual(field);
93
- });
94
- test('import unsupported field', () => {
95
- const field = {
96
- name: 't',
97
- type: 'sql native',
98
- };
99
- const struct = mkStructDef(field);
100
- const space = new static_space_1.StaticSourceSpace(struct);
101
- expect(space.lookup(fieldRef('t')).found).toBeInstanceOf(column_space_field_1.ColumnSpaceField);
102
- const oField = space.structDef().fields[0];
103
- expect(oField).toEqual(field);
104
- });
105
- test('import repeated record', () => {
106
- const field = {
107
- name: 't',
108
- type: 'array',
109
- elementTypeDef: { type: 'string' },
110
- join: 'many',
111
- matrixOperation: 'left',
112
- fields: [{ type: 'string', name: 'b' }],
113
- };
114
- const struct = mkStructDef(field);
115
- const space = new static_space_1.StaticSourceSpace(struct);
116
- expect(space.lookup(fieldRef('t.b')).found).toBeInstanceOf(column_space_field_1.ColumnSpaceField);
117
- const oField = space.structDef().fields[0];
118
- expect(oField).toEqual(field);
119
- });
120
- test('import inline field', () => {
121
- const field = {
122
- name: 't',
123
- type: 'record',
124
- join: 'one',
125
- matrixOperation: 'left',
126
- fields: [{ type: 'string', name: 'a' }],
127
- };
128
- const struct = mkStructDef(field);
129
- const space = new static_space_1.StaticSourceSpace(struct);
130
- expect(space.lookup(fieldRef('t.a')).found).toBeInstanceOf(column_space_field_1.ColumnSpaceField);
131
- const oField = space.structDef().fields[0];
132
- expect(oField).toEqual(field);
133
- });
134
- test('import join field', () => {
135
- const field = {
136
- name: 't',
137
- type: 'table',
138
- dialect: 'standardsql',
139
- connection: 'test',
140
- join: 'one',
141
- matrixOperation: 'left',
142
- onExpression: {
143
- node: '=',
144
- kids: {
145
- left: { node: 'field', path: ['aKey'] },
146
- right: { node: 'field', path: ['t', 'a'] },
147
- },
148
- },
149
- tablePath: 't',
150
- fields: [{ type: 'string', name: 'a' }],
151
- };
152
- const struct = mkStructDef(field);
153
- const space = new static_space_1.StaticSourceSpace(struct);
154
- expect(space.lookup(fieldRef('t.a')).found).toBeInstanceOf(column_space_field_1.ColumnSpaceField);
155
- const oField = space.structDef().fields[0];
156
- expect(oField).toEqual(field);
157
- });
158
- test('import query stage field', () => {
159
- const field = {
160
- name: 't',
161
- type: 'turtle',
162
- pipeline: [
163
- {
164
- type: 'reduce',
165
- queryFields: [{ type: 'fieldref', path: ['a'] }],
166
- },
167
- ],
168
- };
169
- const struct = mkStructDef(field);
170
- const space = new static_space_1.StaticSourceSpace(struct);
171
- expect(space.lookup(fieldRef('t')).found).toBeInstanceOf(ir_view_field_1.IRViewField);
172
- const oField = space.structDef().fields[0];
173
- expect(oField).toEqual(field);
174
- });
175
- test('import struct with parameters', () => {
176
- const struct = mkStructDef({ name: 'f', type: 'string' });
177
- struct.parameters = {
178
- cReqStr: {
179
- name: 'cReqStr',
180
- type: 'string',
181
- value: null,
182
- },
183
- cOptStr: {
184
- name: 'cOptStr',
185
- type: 'string',
186
- value: { node: 'stringLiteral', literal: 'value' },
187
- },
188
- };
189
- const space = new static_space_1.StaticSourceSpace(struct);
190
- expect(space.lookup(fieldRef('cReqStr')).found).toBeInstanceOf(space_param_1.DefinedParameter);
191
- expect(space.lookup(fieldRef('cOptStr')).found).toBeInstanceOf(space_param_1.DefinedParameter);
192
- });
193
- });
194
- //# sourceMappingURL=field-symbols.spec.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,50 +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
- test('Table path can be retrieved', () => {
27
- const source = (0, test_translator_1.markSource) `
28
- source: flights is ${"DB.table('my.table.flights')"}
29
- source: flights2 is flights extend { dimension: a is astr }
30
- `;
31
- const doc = new test_translator_1.TestTranslator(source.code);
32
- const { pathInfo } = doc.tablePathInfo();
33
- expect(pathInfo === null || pathInfo === void 0 ? void 0 : pathInfo.length).toBe(1);
34
- expect(pathInfo[0].tablePath).toEqual('my.table.flights');
35
- expect(pathInfo[0].connectionId).toEqual('DB');
36
- expect(pathInfo[0].range).toEqual(source.locations[0].range);
37
- });
38
- test('Table path can not be retrieved', () => {
39
- const source = (0, test_translator_1.markSource) `source: flights2 is flights extend { dimension: a is astr }`;
40
- const doc = new test_translator_1.TestTranslator(source.code);
41
- const { pathInfo } = doc.tablePathInfo();
42
- expect(pathInfo === null || pathInfo === void 0 ? void 0 : pathInfo.length).toBe(0);
43
- });
44
- test('Table path can not be retrieved for non string path', () => {
45
- const source = (0, test_translator_1.markSource) `source: flights is duckdb.table("""foo.bar.baz%{foo}""")`;
46
- const doc = new test_translator_1.TestTranslator(source.code);
47
- const { pathInfo } = doc.tablePathInfo();
48
- expect(pathInfo === null || pathInfo === void 0 ? void 0 : pathInfo.length).toBe(0);
49
- });
50
- //# sourceMappingURL=find-table-path-walker.spec.js.map
@@ -1 +0,0 @@
1
- import './parse-expects';
@@ -1,283 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- /*
7
- * Copyright 2023 Google LLC
8
- *
9
- * Permission is hereby granted, free of charge, to any person obtaining
10
- * a copy of this software and associated documentation files
11
- * (the "Software"), to deal in the Software without restriction,
12
- * including without limitation the rights to use, copy, modify, merge,
13
- * publish, distribute, sublicense, and/or sell copies of the Software,
14
- * and to permit persons to whom the Software is furnished to do so,
15
- * subject to the following conditions:
16
- *
17
- * The above copyright notice and this permission notice shall be
18
- * included in all copies or substantial portions of the Software.
19
- *
20
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
- */
28
- const model_1 = require("../../model");
29
- require("./parse-expects");
30
- const test_translator_1 = require("./test-translator");
31
- const escapeRegExp_1 = __importDefault(require("lodash/escapeRegExp"));
32
- describe('import:', () => {
33
- test('simple source', () => {
34
- var _a;
35
- const docParse = new test_translator_1.TestTranslator('import "child"');
36
- const xr = docParse.unresolved();
37
- expect(docParse).toParse();
38
- expect(xr).toEqual({ urls: ['internal://test/langtests/child'] });
39
- docParse.update({
40
- urls: { 'internal://test/langtests/child': 'source: aa is a' },
41
- });
42
- expect(docParse).toTranslate();
43
- const aa = docParse.getSourceDef('aa');
44
- expect(aa).toBeDefined();
45
- expect((_a = docParse.translate().modelDef) === null || _a === void 0 ? void 0 : _a.dependencies).toMatchObject({
46
- 'internal://test/langtests/child': {},
47
- });
48
- });
49
- test('simple source with importBaseURL', () => {
50
- var _a;
51
- const docParse = new test_translator_1.TestTranslator('import "child"', 'http://example.com/');
52
- const xr = docParse.unresolved();
53
- expect(docParse).toParse();
54
- expect(xr).toEqual({ urls: ['http://example.com/child'] });
55
- docParse.update({
56
- urls: { 'http://example.com/child': 'source: aa is a' },
57
- });
58
- expect(docParse).toTranslate();
59
- const aa = docParse.getSourceDef('aa');
60
- expect(aa).toBeDefined();
61
- expect((_a = docParse.translate().modelDef) === null || _a === void 0 ? void 0 : _a.dependencies).toMatchObject({
62
- 'http://example.com/child': {},
63
- });
64
- });
65
- test('simple query', () => {
66
- var _a;
67
- const docParse = new test_translator_1.TestTranslator('import "child"');
68
- const xr = docParse.unresolved();
69
- expect(docParse).toParse();
70
- expect(xr).toEqual({ urls: ['internal://test/langtests/child'] });
71
- docParse.update({
72
- urls: {
73
- 'internal://test/langtests/child': 'query: aq is a->{ select: * }',
74
- },
75
- });
76
- expect(docParse).toTranslate();
77
- const aq = docParse.getQuery('aq');
78
- expect(aq).toBeDefined();
79
- expect((_a = docParse.translate().modelDef) === null || _a === void 0 ? void 0 : _a.dependencies).toMatchObject({
80
- 'internal://test/langtests/child': {},
81
- });
82
- });
83
- test('query based source with named structref', () => {
84
- const docParse = new test_translator_1.TestTranslator(`
85
- import "child"
86
- source: newSrc is a extend {
87
- join_one: b is botProjQSrc on b.astr = astr
88
- }
89
- `);
90
- const xr = docParse.unresolved();
91
- expect(docParse).toParse();
92
- expect(xr).toEqual({ urls: ['internal://test/langtests/child'] });
93
- docParse.update({
94
- urls: {
95
- 'internal://test/langtests/child': `
96
- source: bottomSrc is a
97
- query: botProjQ is bottomSrc -> { select: * }
98
- source: botProjQSrc is botProjQ
99
- `,
100
- },
101
- });
102
- expect(docParse).toTranslate();
103
- const newSrc = docParse.getSourceDef('newSrc');
104
- const maybeField = newSrc === null || newSrc === void 0 ? void 0 : newSrc.fields.find(f => f.name === 'b');
105
- expect(maybeField).toBeDefined();
106
- const f = maybeField;
107
- expect((0, model_1.isJoined)(f)).toBeTruthy();
108
- if ((0, model_1.isJoined)(f)) {
109
- expect(f.type).toBe('query_source');
110
- if (f.type === 'query_source') {
111
- expect(typeof f.query.structRef).not.toBe('string');
112
- }
113
- }
114
- });
115
- test('missing import', () => {
116
- const docParse = new test_translator_1.TestTranslator('import "child"');
117
- const xr = docParse.unresolved();
118
- expect(docParse).toParse();
119
- expect(xr).toEqual({ urls: ['internal://test/langtests/child'] });
120
- const reportedError = 'ENOWAY: No way to find your child';
121
- docParse.update({
122
- errors: {
123
- urls: { 'internal://test/langtests/child': reportedError },
124
- },
125
- });
126
- docParse.translate();
127
- expect(docParse).toLog((0, test_translator_1.errorMessage)(new RegExp((0, escapeRegExp_1.default)(reportedError))));
128
- });
129
- test('chained imports', () => {
130
- var _a, _b;
131
- const docParse = new test_translator_1.TestTranslator('import "child"');
132
- docParse.update({
133
- urls: { 'internal://test/langtests/child': 'import "grandChild"' },
134
- });
135
- const xr = docParse.unresolved();
136
- expect(docParse).toParse();
137
- expect(xr).toEqual({ urls: ['internal://test/langtests/grandChild'] });
138
- docParse.update({
139
- urls: { 'internal://test/langtests/grandChild': '// empty file' },
140
- });
141
- expect(docParse).toTranslate();
142
- const translated = docParse.translate();
143
- const sources = translated.fromSources;
144
- expect(sources).toEqual([
145
- 'internal://test/langtests/root.malloy',
146
- 'internal://test/langtests/child',
147
- 'internal://test/langtests/grandChild',
148
- ]);
149
- expect((_a = translated.modelDef) === null || _a === void 0 ? void 0 : _a.dependencies).toMatchObject({
150
- 'internal://test/langtests/child': {
151
- 'internal://test/langtests/grandChild': {},
152
- },
153
- });
154
- const newDependencies = docParse.newlyTranslatedDependencies();
155
- expect(newDependencies).toMatchObject([
156
- { url: 'internal://test/langtests/child', modelDef: {} },
157
- { url: 'internal://test/langtests/grandChild', modelDef: {} },
158
- ]);
159
- const child = docParse.translatorForDependency('internal://test/langtests/child');
160
- expect((_b = child.translate().modelDef) === null || _b === void 0 ? void 0 : _b.dependencies).toMatchObject({
161
- 'internal://test/langtests/grandChild': {},
162
- });
163
- });
164
- test('relative imports', () => {
165
- const docParse = new test_translator_1.TestTranslator('import "../parent.malloy"');
166
- expect(docParse).toParse();
167
- const xr = docParse.unresolved();
168
- expect(xr).toEqual({ urls: ['internal://test/parent.malloy'] });
169
- docParse.update({
170
- urls: {
171
- 'internal://test/parent.malloy': "source: aa is _db_.table('aTable')",
172
- },
173
- });
174
- expect(docParse).toTranslate();
175
- });
176
- test('relative imports with errors', () => {
177
- const docParse = new test_translator_1.TestTranslator('import "../parent.malloy"');
178
- expect(docParse).toParse();
179
- const xr = docParse.unresolved();
180
- expect(xr).toEqual({ urls: ['internal://test/parent.malloy'] });
181
- docParse.update({
182
- urls: {
183
- 'internal://test/parent.malloy': `
184
- source: aa is _db_.table('aTable') extend {
185
- dimension: astr is 'not legal beause astr exists'
186
- }`,
187
- },
188
- });
189
- expect(docParse).toLog((0, test_translator_1.errorMessage)("Cannot redefine 'astr'"));
190
- });
191
- test('source references expanded when not exported', () => {
192
- const srcFiles = {
193
- 'internal://test/langtests/middle': `
194
- import "bottom"
195
- // in m4 source: NAME is SRC -> { QUERY } wasn't parsing
196
- query: q is bottomSrc -> { group_by: astr }
197
- source: midSrc is q
198
- `,
199
- 'internal://test/langtests/bottom': "source: bottomSrc is _db_.table('aTable')",
200
- };
201
- const fullModel = new test_translator_1.TestTranslator(`
202
- import "middle"
203
- `);
204
- fullModel.update({ urls: srcFiles });
205
- expect(fullModel).toTranslate();
206
- const ms = fullModel.getSourceDef('midSrc');
207
- expect(ms).toBeDefined();
208
- if (ms) {
209
- expect(ms.type).toBe('query_source');
210
- if (ms.type === 'query_source') {
211
- const qs = ms.query.structRef;
212
- expect(typeof qs).not.toBe('string');
213
- }
214
- }
215
- });
216
- test('selective import of source', () => {
217
- const docParse = new test_translator_1.TestTranslator('import { bb } from "child"');
218
- const xr = docParse.unresolved();
219
- expect(docParse).toParse();
220
- expect(xr).toEqual({ urls: ['internal://test/langtests/child'] });
221
- docParse.update({
222
- urls: {
223
- 'internal://test/langtests/child': 'source: aa is a; source: bb is a',
224
- },
225
- });
226
- expect(docParse).toTranslate();
227
- const bb = docParse.getSourceDef('bb');
228
- expect(bb).toBeDefined();
229
- const aa = docParse.getSourceDef('aa');
230
- expect(aa).toBeUndefined();
231
- });
232
- test('renaming import of source', () => {
233
- const docParse = new test_translator_1.TestTranslator('import { bb is aa } from "child"');
234
- const xr = docParse.unresolved();
235
- expect(docParse).toParse();
236
- expect(xr).toEqual({ urls: ['internal://test/langtests/child'] });
237
- docParse.update({
238
- urls: { 'internal://test/langtests/child': 'source: aa is a' },
239
- });
240
- expect(docParse).toTranslate();
241
- const bb = docParse.getSourceDef('bb');
242
- expect(bb).toBeDefined();
243
- });
244
- test('selective import of source, not found', () => {
245
- const doc = (0, test_translator_1.model) `import { ${'bb'} } from "child"`;
246
- const xr = doc.translator.unresolved();
247
- expect(doc).toParse();
248
- expect(xr).toEqual({ urls: ['internal://test/langtests/child'] });
249
- doc.translator.update({
250
- urls: {
251
- 'internal://test/langtests/child': 'source: aa is a',
252
- },
253
- });
254
- expect(doc.translator).toLog((0, test_translator_1.errorMessage)("Cannot find 'bb', not imported"));
255
- });
256
- test('selective renamed import of source, not found', () => {
257
- const doc = (0, test_translator_1.model) `import { cc is ${'bb'} } from "child"`;
258
- const xr = doc.translator.unresolved();
259
- expect(doc).toParse();
260
- expect(xr).toEqual({ urls: ['internal://test/langtests/child'] });
261
- doc.translator.update({
262
- urls: {
263
- 'internal://test/langtests/child': 'source: aa is a',
264
- },
265
- });
266
- expect(doc.translator).toLog((0, test_translator_1.errorMessage)("Cannot find 'bb', not imported"));
267
- });
268
- test('selective import of source, no-redefinition', () => {
269
- const doc = (0, test_translator_1.model) `
270
- import { cc is ${'bb'} } from "child"
271
- import { cc is ${'bb'} } from "child"`;
272
- const xr = doc.translator.unresolved();
273
- expect(doc).toParse();
274
- expect(xr).toEqual({ urls: ['internal://test/langtests/child'] });
275
- doc.translator.update({
276
- urls: {
277
- 'internal://test/langtests/child': 'source: bb is a',
278
- },
279
- });
280
- expect(doc.translator).toLog((0, test_translator_1.errorMessage)("Cannot redefine 'cc'"));
281
- });
282
- });
283
- //# sourceMappingURL=imports.spec.js.map
@@ -1 +0,0 @@
1
- import './parse-expects';