@malloydata/malloy 0.0.28-dev230314211807 → 0.0.28-dev230320190215
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lang/ast/elements/define-query.js +1 -1
- package/dist/lang/ast/elements/import-statement.js +2 -6
- package/dist/lang/ast/query-elements/existing-query.d.ts +1 -1
- package/dist/lang/ast/query-elements/existing-query.js +3 -3
- package/dist/lang/ast/query-elements/full-query.d.ts +1 -1
- package/dist/lang/ast/query-elements/full-query.js +5 -3
- package/dist/lang/ast/sources/query-source.js +1 -1
- package/dist/lang/parse-malloy.d.ts +6 -2
- package/dist/lang/parse-malloy.js +3 -2
- package/dist/lang/test/imports.spec.d.ts +1 -0
- package/dist/lang/test/imports.spec.js +160 -0
- package/dist/lang/test/parse-expects.d.ts +14 -0
- package/dist/lang/test/parse-expects.js +232 -0
- package/dist/lang/test/parse.spec.d.ts +1 -14
- package/dist/lang/test/parse.spec.js +83 -459
- package/dist/lang/test/test-translator.d.ts +21 -3
- package/dist/lang/test/test-translator.js +105 -7
- package/package.json +1 -1
|
@@ -2,8 +2,9 @@ import { DocumentLocation, FieldDef, ModelDef, NamedModelObject, PipeSegment, Qu
|
|
|
2
2
|
import { MalloyElement } from '../ast';
|
|
3
3
|
import { NameSpace } from '../ast/types/name-space';
|
|
4
4
|
import { ModelEntry } from '../ast/types/model-entry';
|
|
5
|
-
import { MalloyTranslator } from '../parse-malloy';
|
|
6
|
-
import { TranslateResponse } from '../translate-response';
|
|
5
|
+
import { MalloyChildTranslator, MalloyTranslator } from '../parse-malloy';
|
|
6
|
+
import { DataRequestResponse, TranslateResponse } from '../translate-response';
|
|
7
|
+
import { ExprValue } from '../ast/types/expr-value';
|
|
7
8
|
export declare function pretty(thing: any): string;
|
|
8
9
|
export declare const aTableDef: StructDef;
|
|
9
10
|
/**
|
|
@@ -18,15 +19,32 @@ declare class TestRoot extends MalloyElement implements NameSpace {
|
|
|
18
19
|
getEntry(name: string): ModelEntry | undefined;
|
|
19
20
|
setEntry(_name: string, _val: ModelEntry): void;
|
|
20
21
|
}
|
|
22
|
+
export declare class TestChildTranslator extends MalloyChildTranslator {
|
|
23
|
+
translate(): TranslateResponse;
|
|
24
|
+
addChild(url: string): void;
|
|
25
|
+
}
|
|
21
26
|
export declare class TestTranslator extends MalloyTranslator {
|
|
27
|
+
readonly testSrc: string;
|
|
22
28
|
testRoot?: TestRoot;
|
|
23
29
|
internalModel: ModelDef;
|
|
24
|
-
constructor(
|
|
30
|
+
constructor(testSrc: string, rootRule?: string);
|
|
25
31
|
translate(): TranslateResponse;
|
|
32
|
+
addChild(url: string): void;
|
|
26
33
|
ast(): MalloyElement | undefined;
|
|
27
34
|
private explainFailure;
|
|
28
35
|
get nameSpace(): Record<string, NamedModelObject>;
|
|
29
36
|
exploreFor(exploreName: string): StructDef;
|
|
37
|
+
static inspectCompile: boolean;
|
|
38
|
+
compile(): void;
|
|
39
|
+
unresolved(): DataRequestResponse;
|
|
40
|
+
getSourceDef(srcName: string): StructDef | undefined;
|
|
41
|
+
getQuery(queryName: string | number): Query | undefined;
|
|
42
|
+
}
|
|
43
|
+
export declare class BetaExpression extends TestTranslator {
|
|
44
|
+
private compiled?;
|
|
45
|
+
constructor(src: string);
|
|
46
|
+
compile(): void;
|
|
47
|
+
generated(): ExprValue;
|
|
30
48
|
}
|
|
31
49
|
export declare function getExplore(modelDef: ModelDef, name: string): StructDef;
|
|
32
50
|
export declare function getModelQuery(modelDef: ModelDef, name: string): Query;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable no-console */
|
|
2
3
|
/*
|
|
3
4
|
* Copyright 2023 Google LLC
|
|
4
5
|
*
|
|
@@ -22,11 +23,12 @@
|
|
|
22
23
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
24
|
*/
|
|
24
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.markSource = exports.getJoinField = exports.getQueryField = exports.getField = exports.getModelQuery = exports.getExplore = exports.TestTranslator = exports.aTableDef = exports.pretty = void 0;
|
|
26
|
+
exports.markSource = exports.getJoinField = exports.getQueryField = exports.getField = exports.getModelQuery = exports.getExplore = exports.BetaExpression = exports.TestTranslator = exports.TestChildTranslator = exports.aTableDef = exports.pretty = void 0;
|
|
26
27
|
const util_1 = require("util");
|
|
27
28
|
const malloy_types_1 = require("../../model/malloy_types");
|
|
28
29
|
const ast_1 = require("../ast");
|
|
29
30
|
const parse_malloy_1 = require("../parse-malloy");
|
|
31
|
+
const static_space_1 = require("../ast/field-space/static-space");
|
|
30
32
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
|
|
31
33
|
function pretty(thing) {
|
|
32
34
|
return (0, util_1.inspect)(thing, { breakLength: 72, depth: Infinity });
|
|
@@ -162,19 +164,40 @@ class TestRoot extends ast_1.MalloyElement {
|
|
|
162
164
|
throw new Error("Can't add entries to test model def");
|
|
163
165
|
}
|
|
164
166
|
}
|
|
167
|
+
class TestChildTranslator extends parse_malloy_1.MalloyChildTranslator {
|
|
168
|
+
translate() {
|
|
169
|
+
if (this.root instanceof TestTranslator) {
|
|
170
|
+
return super.translate(this.root.internalModel);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
return super.translate();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
addChild(url) {
|
|
177
|
+
if (!this.childTranslators.get(url)) {
|
|
178
|
+
const child = new TestChildTranslator(url, this.root);
|
|
179
|
+
this.childTranslators.set(url, child);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.TestChildTranslator = TestChildTranslator;
|
|
165
184
|
const testURI = 'internal://test/langtests/root.malloy';
|
|
166
185
|
class TestTranslator extends parse_malloy_1.MalloyTranslator {
|
|
167
|
-
constructor(
|
|
186
|
+
constructor(testSrc, rootRule = 'malloyDocument') {
|
|
168
187
|
super(testURI);
|
|
188
|
+
this.testSrc = testSrc;
|
|
169
189
|
/*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
190
|
+
* All test source files can assume that an import of this
|
|
191
|
+
* model has already happened.
|
|
192
|
+
* source: a is table('aTable') { primary_key: astr }
|
|
193
|
+
* source: b is a
|
|
194
|
+
* source: ab is a {
|
|
174
195
|
* join_one: b with astr
|
|
175
196
|
* measure: acount is count()
|
|
176
197
|
* query: aturtle is { group_by: astr; aggregate: acount }
|
|
177
198
|
* }
|
|
199
|
+
* Also the following tables will be available
|
|
200
|
+
* 'aTable', 'malloytest.carriers'
|
|
178
201
|
*/
|
|
179
202
|
this.internalModel = {
|
|
180
203
|
name: testURI,
|
|
@@ -223,7 +246,7 @@ class TestTranslator extends parse_malloy_1.MalloyTranslator {
|
|
|
223
246
|
},
|
|
224
247
|
};
|
|
225
248
|
this.grammarRule = rootRule;
|
|
226
|
-
this.importZone.define(testURI,
|
|
249
|
+
this.importZone.define(testURI, testSrc);
|
|
227
250
|
for (const tableName in mockSchema) {
|
|
228
251
|
this.schemaZone.define(tableName, mockSchema[tableName]);
|
|
229
252
|
}
|
|
@@ -231,6 +254,12 @@ class TestTranslator extends parse_malloy_1.MalloyTranslator {
|
|
|
231
254
|
translate() {
|
|
232
255
|
return super.translate(this.internalModel);
|
|
233
256
|
}
|
|
257
|
+
addChild(url) {
|
|
258
|
+
if (!this.childTranslators.get(url)) {
|
|
259
|
+
const child = new TestChildTranslator(url, this);
|
|
260
|
+
this.childTranslators.set(url, child);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
234
263
|
ast() {
|
|
235
264
|
const astAsk = this.astStep.step(this);
|
|
236
265
|
if (astAsk.ast) {
|
|
@@ -280,8 +309,77 @@ class TestTranslator extends parse_malloy_1.MalloyTranslator {
|
|
|
280
309
|
}
|
|
281
310
|
throw new Error(`Expected model to contain explore '${exploreName}'`);
|
|
282
311
|
}
|
|
312
|
+
compile() {
|
|
313
|
+
const compileTo = this.translate();
|
|
314
|
+
if (compileTo.translated && TestTranslator.inspectCompile) {
|
|
315
|
+
console.log('MODEL: ', pretty(compileTo.translated.modelDef));
|
|
316
|
+
console.log('QUERIES: ', pretty(compileTo.translated.queryList));
|
|
317
|
+
}
|
|
318
|
+
// All the stuff to ask the ast for a translation is already in TestTranslator
|
|
319
|
+
}
|
|
320
|
+
unresolved() {
|
|
321
|
+
return this.importsAndTablesStep.step(this);
|
|
322
|
+
}
|
|
323
|
+
getSourceDef(srcName) {
|
|
324
|
+
var _a;
|
|
325
|
+
const t = this.translate().translated;
|
|
326
|
+
const s = (_a = t === null || t === void 0 ? void 0 : t.modelDef) === null || _a === void 0 ? void 0 : _a.contents[srcName];
|
|
327
|
+
if (s && s.type === 'struct') {
|
|
328
|
+
return s;
|
|
329
|
+
}
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
getQuery(queryName) {
|
|
333
|
+
const t = this.translate().translated;
|
|
334
|
+
if (t) {
|
|
335
|
+
const s = typeof queryName === 'string'
|
|
336
|
+
? t.modelDef.contents[queryName]
|
|
337
|
+
: t.queryList[queryName];
|
|
338
|
+
if ((s === null || s === void 0 ? void 0 : s.type) === 'query') {
|
|
339
|
+
return s;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
283
344
|
}
|
|
284
345
|
exports.TestTranslator = TestTranslator;
|
|
346
|
+
TestTranslator.inspectCompile = false;
|
|
347
|
+
class BetaExpression extends TestTranslator {
|
|
348
|
+
constructor(src) {
|
|
349
|
+
super(src, 'justExpr');
|
|
350
|
+
}
|
|
351
|
+
compile() {
|
|
352
|
+
const exprAst = this.ast();
|
|
353
|
+
if (exprAst instanceof ast_1.ExpressionDef) {
|
|
354
|
+
const aStruct = this.internalModel.contents['ab'];
|
|
355
|
+
if (aStruct.type === 'struct') {
|
|
356
|
+
const tstFS = new static_space_1.StaticSpace(aStruct);
|
|
357
|
+
const exprDef = exprAst.getExpression(tstFS);
|
|
358
|
+
this.compiled = exprDef;
|
|
359
|
+
if (TestTranslator.inspectCompile) {
|
|
360
|
+
console.log('EXPRESSION: ', pretty(exprDef));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
throw new Error("Can't get simple namespace for expression tests");
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
else if (this.logger.hasErrors()) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
const whatIsIt = (exprAst === null || exprAst === void 0 ? void 0 : exprAst.toString()) || 'NO AST GENERATED';
|
|
372
|
+
throw new Error(`Not an expression: ${whatIsIt}`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
generated() {
|
|
376
|
+
if (!this.compiled) {
|
|
377
|
+
throw new Error('Must compile expression before fetching generated code');
|
|
378
|
+
}
|
|
379
|
+
return this.compiled;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
exports.BetaExpression = BetaExpression;
|
|
285
383
|
function getExplore(modelDef, name) {
|
|
286
384
|
return modelDef.contents[name];
|
|
287
385
|
}
|