@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,145 +0,0 @@
1
- "use strict";
2
- /* eslint-disable no-console */
3
- /*
4
- * Copyright 2023 Google LLC
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining
7
- * a copy of this software and associated documentation files
8
- * (the "Software"), to deal in the Software without restriction,
9
- * including without limitation the rights to use, copy, modify, merge,
10
- * publish, distribute, sublicense, and/or sell copies of the Software,
11
- * and to permit persons to whom the Software is furnished to do so,
12
- * subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be
15
- * included in all copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
- */
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const test_translator_1 = require("./test-translator");
27
- require("./parse-expects");
28
- const parse_malloy_1 = require("../parse-malloy");
29
- const sql_block_1 = require("../../model/sql_block");
30
- describe('connection sql()', () => {
31
- const selStmt = 'SELECT * FROM aTable';
32
- function makeSchemaResponse(sql) {
33
- const cname = sql.connection || 'bigquery';
34
- const key = (0, sql_block_1.sqlKey)(cname, sql.selectStr);
35
- return {
36
- [key]: {
37
- type: 'sql_select',
38
- name: key,
39
- dialect: 'standardsql',
40
- connection: cname,
41
- selectStr: selStmt,
42
- fields: test_translator_1.aTableDef.fields,
43
- },
44
- };
45
- }
46
- test('source from sql', () => {
47
- const model = new test_translator_1.TestTranslator(`
48
- source: users is aConnection.sql("""${selStmt}""")
49
- source: malloyUsers is users extend { primary_key: ai }
50
- `);
51
- expect(model).toParse();
52
- const needReq = model.translate();
53
- const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
54
- expect(needs).toBeDefined();
55
- if (needs) {
56
- model.update({ compileSQL: makeSchemaResponse(needs) });
57
- expect(model).toTranslate();
58
- const users = model.getSourceDef('malloyUsers');
59
- expect(users).toBeDefined();
60
- }
61
- });
62
- test('source from imported sql-based-source', () => {
63
- const createModel = `
64
- source: malloyUsers is _db_.sql('${selStmt}') extend { primary_key: ai }
65
- `;
66
- const model = new test_translator_1.TestTranslator(`
67
- import "createModel.malloy"
68
- source: importUsers is malloyUsers
69
- run: malloyUsers -> { select: * }
70
- run: importUsers -> { select: * }
71
- `);
72
- model.importZone.define('internal://test/langtests/createModel.malloy', createModel);
73
- expect(model).toParse();
74
- const needReq = model.translate();
75
- const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
76
- expect(needs).toBeDefined();
77
- model.update({ compileSQL: makeSchemaResponse(needs) });
78
- expect(model).toTranslate();
79
- });
80
- it('simple turducken', () => {
81
- const m = new test_translator_1.TestTranslator(`
82
- source: someSql is _db_.sql("""SELECT * FROM %{ a -> { group_by: astr } } WHERE 1=1""")
83
- `);
84
- expect(m).toParse();
85
- const compileSql = m.translate().compileSQL;
86
- expect(compileSql).toBeDefined();
87
- if (compileSql) {
88
- expect(compileSql.selectStr).toEqual('SELECT * FROM (SELECT \n base.`astr` as `astr`\nFROM `aTable` as base\nGROUP BY 1\nORDER BY 1 asc\n) WHERE 1=1');
89
- }
90
- });
91
- it('turduckenzilla', () => {
92
- const m = new test_translator_1.TestTranslator(`
93
- run: duckdb.sql("""
94
- SELECT * from (%{
95
- duckdb.sql("""SELECT 2 as two""") extend {
96
- view: b is {
97
- nest: c is {
98
- extend: {
99
- join_one: d is duckdb.sql("""
100
- SELECT * from (%{
101
- duckdb.sql("""SELECT 3 as three""") extend {
102
- view: b is {
103
- nest: c is {
104
- extend: {
105
- join_one: d is duckdb.sql("""SELECT 4 as four""") on three = d.four - 1
106
- }
107
- group_by: three
108
- }
109
- }
110
- } -> { group_by: three }
111
- })
112
- """) on two = d.three
113
- }
114
- group_by: two
115
- }
116
- }
117
- } -> { group_by: two }
118
- })
119
- """) -> { group_by: two }
120
- `);
121
- expect(m).toParse();
122
- });
123
- test('source from extended sql-based-source', () => {
124
- var _a;
125
- const model = new test_translator_1.TestTranslator(`
126
- source: sql_block is aConnection.sql("""${selStmt}""")
127
- source: malloy_source is sql_block extend { primary_key: ai }
128
- `);
129
- expect(model).toParse();
130
- const needReq = model.translate();
131
- const needs = needReq === null || needReq === void 0 ? void 0 : needReq.compileSQL;
132
- expect(needs).toBeDefined();
133
- model.update({ compileSQL: makeSchemaResponse(needs) });
134
- expect(model).toTranslate();
135
- const modelDef = (_a = model === null || model === void 0 ? void 0 : model.translate()) === null || _a === void 0 ? void 0 : _a.modelDef;
136
- // this tests the underlying api that .extendModel calls
137
- const extModel = new parse_malloy_1.MalloyTranslator('sqlblocktest://main');
138
- extModel.importZone.define('sqlblocktest://main', 'run: malloy_source -> { select: * }');
139
- const tr = extModel.translate(modelDef);
140
- // because extModel is not a TestTranslator we can't use the hotness
141
- expect(tr.problems).toEqual([]);
142
- expect(tr.modelDef).toBeDefined();
143
- });
144
- });
145
- //# sourceMappingURL=sql-block.spec.js.map
@@ -1 +0,0 @@
1
- import './parse-expects';
@@ -1,142 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) Meta Platforms, Inc. and affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const test_translator_1 = require("./test-translator");
10
- require("./parse-expects");
11
- /**
12
- * Unit tests intended to cover the custom error messages defined in
13
- * malloy-custom-error-messages.ts.
14
- *
15
- * These tests are intended to prevent unintended regressions. It is
16
- * okay to change or remove tests here as long as you are doing so
17
- * for a good reason.
18
- */
19
- describe('custom error messages', () => {
20
- describe('source', () => {
21
- test('missing alias', () => {
22
- expect('source: x extend { }').toLogAtLeast((0, test_translator_1.errorMessage)("Expected 'is' or '(' following identifier 'x'"));
23
- });
24
- test('missing closing curly: EOF', () => {
25
- expect('source: x is a extend {').toLogAtLeast((0, test_translator_1.errorMessage)("Missing '}' at '<EOF>'"));
26
- });
27
- test('source: missing colon in root context', () => {
28
- expect('source x is a extend { }').toLogAtLeast((0, test_translator_1.errorMessage)("Expected ':' following 'source'"));
29
- });
30
- test('opening curly to EOF', () => {
31
- expect(`
32
- source: y is x extend {
33
- `).toLogAtLeast((0, test_translator_1.errorMessage)("Missing '}' at '<EOF>'"));
34
- });
35
- test('expression missing operand before curly', () => {
36
- expect("source: a is presto.table('malloytest.state_facts') {}").toLogAtLeast((0, test_translator_1.errorMessage)("Unexpected '{' following source expression. Expected: 'extend', 'include', '+' or '->'"));
37
- });
38
- test('missing opening curly after source extend keyword', () => {
39
- expect(`
40
- source: x is a extend
41
- primary_key: id
42
- `).toLogAtLeast((0, test_translator_1.errorMessage)("missing '{' at 'primary_key:'"));
43
- });
44
- });
45
- describe('exploreProperties', () => {
46
- test('misspelled "join"', () => {
47
- expect(`source: x is a extend {
48
- join: data is y on dataId = data.id
49
- }`).toLogAtLeast((0, test_translator_1.errorMessage)("Unexpected 'join:'. Did you mean 'join_one:', 'join_many:' or 'join_cross:'?"));
50
- expect(`source: x is a extend {
51
- primary_key: name
52
- join: data is y on dataId = data.id
53
- }`).toLogAtLeast((0, test_translator_1.errorMessage)("Unexpected 'join:'. Did you mean 'join_one:', 'join_many:' or 'join_cross:'?"));
54
- });
55
- test('misspelled "primary_key:"', () => {
56
- expect('source: x is a extend { primaryKey: name }').toLogAtLeast((0, test_translator_1.errorMessage)("Unexpected 'primaryKey'. Did you mean 'primary_key:'?"));
57
- expect('source: x is a extend { primary key: name }').toLogAtLeast((0, test_translator_1.errorMessage)("Unexpected 'primary'. Did you mean 'primary_key:'?"));
58
- });
59
- test('explore statement keyword missing colon', () => {
60
- expect('source: x is a extend { where x > 5 }').toLogAtLeast((0, test_translator_1.errorMessage)("Expected ':' following 'where'"));
61
- expect('source: x is a extend { primary_key name }').toLogAtLeast((0, test_translator_1.errorMessage)("Expected ':' following 'primary_key'"));
62
- expect('source: x is a extend { declare total is value.sum() }').toLogAtLeast((0, test_translator_1.errorMessage)("Expected ':' following 'declare'"));
63
- });
64
- test('incorrect opening curly after dimension', () => {
65
- expect(`
66
- source: x is a extend {
67
- dimension: {
68
- test is best
69
- }
70
- }
71
- `).toLogAtLeast((0, test_translator_1.errorMessage)("extraneous input '{' expecting {BQ_STRING, IDENTIFIER}"));
72
- });
73
- });
74
- describe('view', () => {
75
- test('view is missing name', () => {
76
- expect(`
77
- source: x is a extend { view: {
78
- group_by: b
79
- } }
80
- `).toLogAtLeast((0, test_translator_1.errorMessage)("'view:' must be followed by '<identifier> is {'"));
81
- });
82
- test('missing closing curly, source>view', () => {
83
- expect(`
84
- source: x is a extend {
85
- view: y is {
86
- group_by: b
87
-
88
- view: z is {
89
- group_by: c
90
- }
91
- }
92
- `).toLogAtLeast((0, test_translator_1.errorMessage)("Missing '}' at 'view:'"));
93
- });
94
- test('missing alias for aggregate inside source>view', () => {
95
- expect(`
96
- source: x is aa extend {
97
- measure: airport_count is count()
98
-
99
- view: by_state is {
100
- where: state is not null
101
- aggregate: count()
102
- }
103
- }
104
- `).toLogAtLeast((0, test_translator_1.errorMessage)("'aggregate:' entries must include a name (ex: `some_name is count()`)"));
105
- });
106
- });
107
- describe('queryStatement', () => {
108
- test('misspelled group_by:', () => {
109
- expect('source: x is a -> { groupBy: name }').toLogAtLeast((0, test_translator_1.errorMessage)("Unexpected 'groupBy'. Did you mean 'group_by:'?"));
110
- expect('source: x is a -> { group by: name }').toLogAtLeast((0, test_translator_1.errorMessage)("Unexpected 'group'. Did you mean 'group_by:'?"));
111
- expect('source: x is a -> { group by name }').toLogAtLeast((0, test_translator_1.errorMessage)("Unexpected 'group'. Did you mean 'group_by:'?"));
112
- });
113
- test('misspelled order_by:', () => {
114
- expect('source: x is a -> { orderBy: name }').toLogAtLeast((0, test_translator_1.errorMessage)("Unexpected 'orderBy'. Did you mean 'order_by:'?"));
115
- expect('source: x is a -> { order by: name }').toLogAtLeast((0, test_translator_1.errorMessage)("Unexpected 'order'. Did you mean 'order_by:'?"));
116
- expect('source: x is a -> { order by name }').toLogAtLeast((0, test_translator_1.errorMessage)("Unexpected 'order'. Did you mean 'order_by:'?"));
117
- });
118
- test('query statement keyword missing colon', () => {
119
- expect('source: x is a -> { group_by x > 5 }').toLogAtLeast((0, test_translator_1.errorMessage)("Expected ':' following 'group_by'"));
120
- expect('source: x is a -> { declare name is id }').toLogAtLeast((0, test_translator_1.errorMessage)("Expected ':' following 'declare'"));
121
- expect('source: x is a -> { select * }').toLogAtLeast((0, test_translator_1.errorMessage)("Expected ':' following 'select'"));
122
- expect('source: x is a -> { project i, j, k}').toLogAtLeast((0, test_translator_1.errorMessage)("Expected ':' following 'project'"));
123
- expect('source: x is a -> { where val > 5}').toLogAtLeast((0, test_translator_1.errorMessage)("Expected ':' following 'where'"));
124
- expect('source: x is a -> { order_by name desc, 2 asc}').toLogAtLeast((0, test_translator_1.errorMessage)("Expected ':' following 'order_by'"));
125
- });
126
- });
127
- describe('run', () => {
128
- test('missing alias for aggregate entry', () => {
129
- expect(`
130
- run: x -> {
131
- aggregate: count()
132
- }
133
- `).toLogAtLeast((0, test_translator_1.errorMessage)("'aggregate:' entries must include a name (ex: `some_name is count()`)"));
134
- });
135
- test('run opening curly to EOF', () => {
136
- expect(`
137
- run: x -> {
138
- `).toLogAtLeast((0, test_translator_1.errorMessage)("Missing '}' at '<EOF>'"));
139
- });
140
- });
141
- });
142
- //# sourceMappingURL=syntax-errors.spec.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,38 +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
- // eslint-disable-next-line no-restricted-imports
26
- const utils_1 = require("./utils");
27
- describe('model/utils', () => {
28
- it('should generate deterministic hashes', () => {
29
- const hash1 = (0, utils_1.generateHash)('test-content');
30
- expect(hash1).toEqual('ab17568f-0362-503d-a9c6-76fb0b203636');
31
- });
32
- it('should generate unique hashes', () => {
33
- const hash1 = (0, utils_1.generateHash)('test-content');
34
- const hash2 = (0, utils_1.generateHash)('test-content-different');
35
- expect(hash1).not.toEqual(hash2);
36
- });
37
- });
38
- //# sourceMappingURL=utils.spec.js.map