@malloydata/malloy 0.0.3 → 0.0.4

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 (37) hide show
  1. package/dist/lang/ast/ast-expr.d.ts +0 -1
  2. package/dist/lang/ast/ast-main.d.ts +2 -2
  3. package/package.json +1 -1
  4. package/dist/connection_utils.js +0 -56
  5. package/dist/dialect/dialect.js +0 -77
  6. package/dist/dialect/dialect_map.js +0 -35
  7. package/dist/dialect/duckdb.js +0 -347
  8. package/dist/dialect/index.js +0 -27
  9. package/dist/dialect/postgres.js +0 -315
  10. package/dist/dialect/standardsql.js +0 -362
  11. package/dist/index.js +0 -47
  12. package/dist/lang/ast/apply-expr.js +0 -231
  13. package/dist/lang/ast/ast-expr.js +0 -1041
  14. package/dist/lang/ast/ast-main.js +0 -2087
  15. package/dist/lang/ast/ast-time-expr.js +0 -549
  16. package/dist/lang/ast/ast-types.js +0 -215
  17. package/dist/lang/ast/index.js +0 -34
  18. package/dist/lang/ast/time-utils.js +0 -94
  19. package/dist/lang/field-space.js +0 -631
  20. package/dist/lang/field-utils.js +0 -33
  21. package/dist/lang/index.js +0 -22
  22. package/dist/lang/parse-log.js +0 -41
  23. package/dist/lang/reference-list.js +0 -80
  24. package/dist/lang/space-field.js +0 -346
  25. package/dist/lang/test/document-help-context-walker.spec.js +0 -45
  26. package/dist/lang/test/document-symbol-walker.spec.js +0 -100
  27. package/dist/lang/test/field-symbols.spec.js +0 -172
  28. package/dist/lang/test/parse.spec.js +0 -1951
  29. package/dist/lang/test/test-translator.js +0 -334
  30. package/dist/lang/zone.js +0 -97
  31. package/dist/malloy.js +0 -2360
  32. package/dist/model/index.js +0 -34
  33. package/dist/model/malloy_query.js +0 -2994
  34. package/dist/model/malloy_types.js +0 -283
  35. package/dist/model/sql_block.js +0 -41
  36. package/dist/model/utils.js +0 -84
  37. package/dist/runtime_types.js +0 -15
@@ -1,334 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2021 Google LLC
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License
7
- * version 2 as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- */
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.markSource = exports.getJoinField = exports.getQueryField = exports.getField = exports.getModelQuery = exports.getExplore = exports.TestTranslator = exports.aTableDef = exports.pretty = void 0;
16
- const util_1 = require("util");
17
- const malloy_types_1 = require("../../model/malloy_types");
18
- const ast_1 = require("../ast");
19
- const parse_malloy_1 = require("../parse-malloy");
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
21
- function pretty(thing) {
22
- return (0, util_1.inspect)(thing, { breakLength: 72, depth: Infinity });
23
- }
24
- exports.pretty = pretty;
25
- const mockSchema = {
26
- aTable: {
27
- type: "struct",
28
- name: "aTable",
29
- dialect: "standardsql",
30
- structSource: { type: "table", tablePath: "aTable" },
31
- structRelationship: { type: "basetable", connectionName: "test" },
32
- fields: [
33
- { type: "string", name: "astr" },
34
- { type: "number", name: "af", numberType: "float" },
35
- { type: "number", name: "ai", numberType: "integer" },
36
- { type: "date", name: "ad" },
37
- { type: "boolean", name: "abool" },
38
- { type: "timestamp", name: "ats" },
39
- ],
40
- },
41
- "malloytest.carriers": {
42
- type: "struct",
43
- name: "malloytest.carriers",
44
- dialect: "standardsql",
45
- structSource: {
46
- type: "table",
47
- tablePath: "malloytest.carriers",
48
- },
49
- structRelationship: { type: "basetable", connectionName: "bigquery" },
50
- fields: [
51
- { name: "code", type: "string" },
52
- { name: "name", type: "string" },
53
- { name: "nickname", type: "string" },
54
- ],
55
- as: "carriers",
56
- },
57
- "malloytest.flights": {
58
- type: "struct",
59
- name: "malloytest.flights",
60
- dialect: "standardsql",
61
- structSource: {
62
- type: "table",
63
- tablePath: "malloytest.flights",
64
- },
65
- structRelationship: { type: "basetable", connectionName: "bigquery" },
66
- fields: [
67
- { name: "carrier", type: "string" },
68
- { name: "origin", type: "string" },
69
- { name: "destination", type: "string" },
70
- { name: "flight_num", type: "string" },
71
- { name: "flight_time", type: "number", numberType: "integer" },
72
- { name: "tail_num", type: "string" },
73
- { name: "dep_time", type: "timestamp" },
74
- { name: "arr_time", type: "timestamp" },
75
- { name: "dep_delay", type: "number", numberType: "integer" },
76
- { name: "arr_delay", type: "number", numberType: "integer" },
77
- { name: "taxi_out", type: "number", numberType: "integer" },
78
- { name: "taxi_in", type: "number", numberType: "integer" },
79
- { name: "distance", type: "number", numberType: "integer" },
80
- { name: "cancelled", type: "string" },
81
- { name: "diverted", type: "string" },
82
- { name: "id2", type: "number", numberType: "integer" },
83
- ],
84
- as: "flights",
85
- },
86
- "malloytest.airports": {
87
- type: "struct",
88
- name: "malloytest.airports",
89
- dialect: "standardsql",
90
- structSource: {
91
- type: "table",
92
- tablePath: "malloytest.airports",
93
- },
94
- structRelationship: { type: "basetable", connectionName: "bigquery" },
95
- fields: [
96
- { name: "id", type: "number", numberType: "integer" },
97
- { name: "code", type: "string" },
98
- { name: "site_number", type: "string" },
99
- { name: "fac_type", type: "string" },
100
- { name: "fac_use", type: "string" },
101
- { name: "faa_region", type: "string" },
102
- { name: "faa_dist", type: "string" },
103
- { name: "city", type: "string" },
104
- { name: "county", type: "string" },
105
- { name: "state", type: "string" },
106
- { name: "full_name", type: "string" },
107
- { name: "own_type", type: "string" },
108
- { name: "longitude", type: "number", numberType: "float" },
109
- { name: "latitude", type: "number", numberType: "float" },
110
- { name: "elevation", type: "number", numberType: "integer" },
111
- { name: "aero_cht", type: "string" },
112
- { name: "cbd_dist", type: "number", numberType: "integer" },
113
- { name: "cbd_dir", type: "string" },
114
- { name: "act_date", type: "string" },
115
- { name: "cert", type: "string" },
116
- { name: "fed_agree", type: "string" },
117
- { name: "cust_intl", type: "string" },
118
- { name: "c_ldg_rts", type: "string" },
119
- { name: "joint_use", type: "string" },
120
- { name: "mil_rts", type: "string" },
121
- { name: "cntl_twr", type: "string" },
122
- { name: "major", type: "string" },
123
- ],
124
- as: "airports",
125
- },
126
- };
127
- exports.aTableDef = mockSchema.aTable;
128
- /**
129
- * When translating partial trees, there will not be a document node
130
- * to handle namespace requests, this stands in for document in that case.
131
- */
132
- class TestRoot extends ast_1.MalloyElement {
133
- constructor(child, forTranslator, modelDef) {
134
- super({ child });
135
- this.modelDef = modelDef;
136
- this.elementType = "test root";
137
- this.setTranslator(forTranslator);
138
- }
139
- namespace() {
140
- return this;
141
- }
142
- getEntry(name) {
143
- const struct = this.modelDef.contents[name];
144
- if (struct.type == "struct") {
145
- const exported = this.modelDef.exports.includes(name);
146
- return { entry: struct, exported };
147
- }
148
- }
149
- setEntry(_name, _val) {
150
- throw new Error("Can't add entries to test model def");
151
- }
152
- }
153
- const testURI = "internal://test/langtests/root.malloy";
154
- class TestTranslator extends parse_malloy_1.MalloyTranslator {
155
- constructor(source, rootRule = "malloyDocument") {
156
- super(testURI);
157
- /*
158
- * Tests can assume this model exists:
159
- * explore: a is table('aTable') { primary_key: astr }
160
- * explore: b is a
161
- * explore: ab is a {
162
- * join_one: b with astr
163
- * measure: acount is count()
164
- * query: aturtle is { group_by: astr; aggregate: acount }
165
- * }
166
- */
167
- this.internalModel = {
168
- name: testURI,
169
- exports: [],
170
- contents: {
171
- a: { ...exports.aTableDef, primaryKey: "astr", as: "a" },
172
- b: { ...exports.aTableDef, primaryKey: "astr", as: "b" },
173
- ab: {
174
- ...exports.aTableDef,
175
- as: "ab",
176
- primaryKey: "astr",
177
- fields: [
178
- ...exports.aTableDef.fields,
179
- {
180
- ...exports.aTableDef,
181
- as: "b",
182
- structRelationship: {
183
- type: "one",
184
- onExpression: [
185
- { type: "field", path: "astr" },
186
- "=",
187
- { type: "field", path: "b.astr" },
188
- ],
189
- },
190
- },
191
- {
192
- type: "number",
193
- name: "acount",
194
- numberType: "integer",
195
- aggregate: true,
196
- e: ["COUNT()"],
197
- code: "count()",
198
- },
199
- {
200
- type: "turtle",
201
- name: "aturtle",
202
- pipeline: [
203
- {
204
- type: "reduce",
205
- fields: ["astr", "acount"],
206
- },
207
- ],
208
- },
209
- ],
210
- },
211
- },
212
- };
213
- this.grammarRule = rootRule;
214
- this.importZone.define(testURI, source);
215
- for (const tableName in mockSchema) {
216
- this.schemaZone.define(tableName, mockSchema[tableName]);
217
- }
218
- }
219
- translate() {
220
- return super.translate(this.internalModel);
221
- }
222
- ast() {
223
- const astAsk = this.astStep.step(this);
224
- if (astAsk.ast) {
225
- if (this.grammarRule !== "malloyDocument") {
226
- this.testRoot = new TestRoot(astAsk.ast, this, this.internalModel);
227
- }
228
- return astAsk.ast;
229
- }
230
- this.explainFailure();
231
- }
232
- explainFailure() {
233
- let mysterious = true;
234
- if (this.logger.empty()) {
235
- const whatImports = this.importZone.getUndefined();
236
- if (whatImports) {
237
- mysterious = false;
238
- this.logger.log({
239
- at: this.defaultLocation(),
240
- message: `Missing imports: ${whatImports.join(",")}`,
241
- });
242
- }
243
- const needThese = this.schemaZone.getUndefined();
244
- if (needThese) {
245
- mysterious = false;
246
- this.logger.log({
247
- at: this.defaultLocation(),
248
- message: `Missing schema: ${needThese.join(",")}`,
249
- });
250
- }
251
- if (mysterious) {
252
- this.logger.log({
253
- at: this.defaultLocation(),
254
- message: "mysterious translation failure",
255
- });
256
- }
257
- }
258
- }
259
- get nameSpace() {
260
- var _a;
261
- const gotModel = this.translate();
262
- return ((_a = gotModel === null || gotModel === void 0 ? void 0 : gotModel.translated) === null || _a === void 0 ? void 0 : _a.modelDef.contents) || {};
263
- }
264
- exploreFor(exploreName) {
265
- const explore = this.nameSpace[exploreName];
266
- if (explore && explore.type === "struct") {
267
- return explore;
268
- }
269
- throw new Error(`Expected model to contain explore '${exploreName}'`);
270
- }
271
- }
272
- exports.TestTranslator = TestTranslator;
273
- function getExplore(modelDef, name) {
274
- return modelDef.contents[name];
275
- }
276
- exports.getExplore = getExplore;
277
- function getModelQuery(modelDef, name) {
278
- return modelDef.contents[name];
279
- }
280
- exports.getModelQuery = getModelQuery;
281
- function getField(thing, name) {
282
- const result = thing.fields.find((field) => typeof field !== "string" && (field.as || field.name) === name);
283
- if (typeof result === "string") {
284
- throw new Error("Expected a def, got a ref.");
285
- }
286
- if (result === undefined) {
287
- throw new Error("Expected a field, not undefined");
288
- }
289
- if ((0, malloy_types_1.isFilteredAliasedName)(result)) {
290
- throw new Error("Ignoring these for now");
291
- }
292
- return result;
293
- }
294
- exports.getField = getField;
295
- // TODO "as" is almost always a code smell ...
296
- function getQueryField(structDef, name) {
297
- return getField(structDef, name);
298
- }
299
- exports.getQueryField = getQueryField;
300
- // TODO "as" is almost always a code smell ...
301
- function getJoinField(structDef, name) {
302
- return getField(structDef, name);
303
- }
304
- exports.getJoinField = getJoinField;
305
- function markSource(unmarked, ...marked) {
306
- let code = "";
307
- const locations = [];
308
- for (let index = 0; index < marked.length; index++) {
309
- const mark = marked[index];
310
- code += unmarked[index];
311
- const lines = code.split("\n");
312
- const start = {
313
- line: lines.length - 1,
314
- character: lines[lines.length - 1].length,
315
- };
316
- const bitLines = mark.split("\n");
317
- const location = {
318
- url: testURI,
319
- range: {
320
- start,
321
- end: {
322
- line: start.line + bitLines.length - 1,
323
- character: bitLines.length === 1 ? start.character + mark.length : mark.length,
324
- },
325
- },
326
- };
327
- locations.push(location);
328
- code += mark;
329
- }
330
- code += unmarked[marked.length];
331
- return { code, locations };
332
- }
333
- exports.markSource = markSource;
334
- //# sourceMappingURL=test-translator.js.map
package/dist/lang/zone.js DELETED
@@ -1,97 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2021 Google LLC
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License
7
- * version 2 as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- */
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Zone = void 0;
16
- /**
17
- * A Zone is a symbol table which may contain references to symbols
18
- * which are not yet defined. This is used by the parser to track
19
- * references to objects which it will have to request values from
20
- * before the translation can be complete. The API is struictured to
21
- * build the repsonse-style interfaces that the translator uses.
22
- */
23
- class Zone {
24
- constructor() {
25
- this.location = {};
26
- this.zone = new Map();
27
- }
28
- get(str) {
29
- const zst = this.zone.get(str);
30
- if ((zst === null || zst === void 0 ? void 0 : zst.status) === "present") {
31
- return zst.value;
32
- }
33
- }
34
- getEntry(str) {
35
- const zst = this.zone.get(str);
36
- if (zst) {
37
- if (zst.firstReference || !this.location[str]) {
38
- return zst;
39
- }
40
- return { ...zst, firstReference: this.location[str] };
41
- }
42
- return { status: "error", message: "import reference failure" };
43
- }
44
- /**
45
- * Add a symbol and it's definition to the symbol table.
46
- * @param str
47
- * @param val
48
- */
49
- define(str, val) {
50
- this.zone.set(str, { status: "present", value: val });
51
- }
52
- /**
53
- * Add a symbol to the symbol table.
54
- * @param str The symbol
55
- * @param loc The location of the reference
56
- */
57
- reference(str, loc) {
58
- const zst = this.zone.get(str);
59
- if ((zst === null || zst === void 0 ? void 0 : zst.status) == undefined) {
60
- this.zone.set(str, { status: "reference", firstReference: loc });
61
- this.location[str] = loc;
62
- }
63
- }
64
- /**
65
- * @returns A list of all symbols which have references but not definitions
66
- */
67
- getUndefined() {
68
- const allUndefined = [];
69
- for (const [name, val] of this.zone) {
70
- if (val.status === "reference") {
71
- allUndefined.push(name);
72
- }
73
- }
74
- return allUndefined.length > 0 ? allUndefined : undefined;
75
- }
76
- /**
77
- * Provide values for symbols
78
- * @param updateData Symbols and their values
79
- * @param errorData Pass on errors encountered during fetch
80
- */
81
- updateFrom(updateData, errorData) {
82
- if (updateData) {
83
- for (const [updateKey, updateVal] of Object.entries(updateData)) {
84
- if (updateVal !== undefined) {
85
- this.define(updateKey, updateVal);
86
- }
87
- }
88
- }
89
- if (errorData) {
90
- for (const [errorKey, errorMessage] of Object.entries(errorData)) {
91
- this.zone.set(errorKey, { status: "error", message: errorMessage });
92
- }
93
- }
94
- }
95
- }
96
- exports.Zone = Zone;
97
- //# sourceMappingURL=zone.js.map