@malloydata/malloy 0.0.96-dev231025212541 → 0.0.96-dev231025215824
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/types/malloy-element.d.ts +13 -0
- package/dist/lang/ast/types/malloy-element.js +31 -1
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +15 -0
- package/dist/lang/lib/Malloy/MalloyParser.js +1414 -1388
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +11 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +7 -0
- package/dist/lang/malloy-to-ast.d.ts +3 -1
- package/dist/lang/malloy-to-ast.js +14 -2
- package/dist/lang/parse-malloy.d.ts +2 -1
- package/dist/lang/parse-malloy.js +12 -3
- package/dist/lang/test/parse.spec.js +12 -0
- package/dist/malloy.d.ts +19 -15
- package/dist/malloy.js +17 -3
- package/dist/runtime_types.d.ts +9 -5
- package/dist/tags.d.ts +4 -2
- package/dist/tags.js +10 -2
- package/package.json +1 -1
|
@@ -204,6 +204,7 @@ import { JustExprContext } from "./MalloyParser";
|
|
|
204
204
|
import { SqlExploreNameRefContext } from "./MalloyParser";
|
|
205
205
|
import { NameSQLBlockContext } from "./MalloyParser";
|
|
206
206
|
import { ConnectionNameContext } from "./MalloyParser";
|
|
207
|
+
import { ExperimentalStatementForTestingContext } from "./MalloyParser";
|
|
207
208
|
/**
|
|
208
209
|
* This interface defines a complete listener for a parse tree produced by
|
|
209
210
|
* `MalloyParser`.
|
|
@@ -2411,4 +2412,14 @@ export interface MalloyParserListener extends ParseTreeListener {
|
|
|
2411
2412
|
* @param ctx the parse tree
|
|
2412
2413
|
*/
|
|
2413
2414
|
exitConnectionName?: (ctx: ConnectionNameContext) => void;
|
|
2415
|
+
/**
|
|
2416
|
+
* Enter a parse tree produced by `MalloyParser.experimentalStatementForTesting`.
|
|
2417
|
+
* @param ctx the parse tree
|
|
2418
|
+
*/
|
|
2419
|
+
enterExperimentalStatementForTesting?: (ctx: ExperimentalStatementForTestingContext) => void;
|
|
2420
|
+
/**
|
|
2421
|
+
* Exit a parse tree produced by `MalloyParser.experimentalStatementForTesting`.
|
|
2422
|
+
* @param ctx the parse tree
|
|
2423
|
+
*/
|
|
2424
|
+
exitExperimentalStatementForTesting?: (ctx: ExperimentalStatementForTestingContext) => void;
|
|
2414
2425
|
}
|
|
@@ -204,6 +204,7 @@ import { JustExprContext } from "./MalloyParser";
|
|
|
204
204
|
import { SqlExploreNameRefContext } from "./MalloyParser";
|
|
205
205
|
import { NameSQLBlockContext } from "./MalloyParser";
|
|
206
206
|
import { ConnectionNameContext } from "./MalloyParser";
|
|
207
|
+
import { ExperimentalStatementForTestingContext } from "./MalloyParser";
|
|
207
208
|
/**
|
|
208
209
|
* This interface defines a complete generic visitor for a parse tree produced
|
|
209
210
|
* by `MalloyParser`.
|
|
@@ -1518,4 +1519,10 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
|
|
|
1518
1519
|
* @return the visitor result
|
|
1519
1520
|
*/
|
|
1520
1521
|
visitConnectionName?: (ctx: ConnectionNameContext) => Result;
|
|
1522
|
+
/**
|
|
1523
|
+
* Visit a parse tree produced by `MalloyParser.experimentalStatementForTesting`.
|
|
1524
|
+
* @param ctx the parse tree
|
|
1525
|
+
* @return the visitor result
|
|
1526
|
+
*/
|
|
1527
|
+
visitExperimentalStatementForTesting?: (ctx: ExperimentalStatementForTestingContext) => Result;
|
|
1521
1528
|
}
|
|
@@ -30,7 +30,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
30
30
|
readonly parseInfo: MalloyParseInfo;
|
|
31
31
|
readonly msgLog: MessageLogger;
|
|
32
32
|
compilerFlags: Tag;
|
|
33
|
-
constructor(parseInfo: MalloyParseInfo, msgLog: MessageLogger);
|
|
33
|
+
constructor(parseInfo: MalloyParseInfo, msgLog: MessageLogger, compilerFlags: Tag);
|
|
34
34
|
/**
|
|
35
35
|
* Mostly used to flag a case where the grammar and the type system are
|
|
36
36
|
* no longer in sync. A visitor was written based on a grammar which
|
|
@@ -49,6 +49,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
49
49
|
* Log an error message relative to a parse node
|
|
50
50
|
*/
|
|
51
51
|
protected contextError(cx: ParserRuleContext, msg: string, sev?: LogSeverity): void;
|
|
52
|
+
protected inExperiment(experimentID: string, cx: ParserRuleContext): boolean;
|
|
52
53
|
protected m4Severity(): LogSeverity | false;
|
|
53
54
|
protected m4advisory(cx: ParserRuleContext, msg: string): void;
|
|
54
55
|
protected only<T extends ast.MalloyElement>(els: ast.MalloyElement[], isGood: (el: ast.MalloyElement) => T | false, desc: string): T[];
|
|
@@ -212,5 +213,6 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
212
213
|
visitSQTable(pcx: parse.SQTableContext): ast.SQSourceWrapper | ErrorNode;
|
|
213
214
|
visitSQLegacySQLBlock(pcx: parse.SQLegacySQLBlockContext): ast.SQSourceWrapper;
|
|
214
215
|
visitSQSQL(pcx: parse.SQSQLContext): ast.SQSourceWrapper;
|
|
216
|
+
visitExperimentalStatementForTesting(pcx: parse.ExperimentalStatementForTestingContext): ast.ExperimentalExperiment;
|
|
215
217
|
}
|
|
216
218
|
export {};
|
|
@@ -73,11 +73,11 @@ const DEFAULT_COMPILER_FLAGS = ['##! m4warnings=error'];
|
|
|
73
73
|
* AST from an ANTLR parse tree.
|
|
74
74
|
*/
|
|
75
75
|
class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
76
|
-
constructor(parseInfo, msgLog) {
|
|
76
|
+
constructor(parseInfo, msgLog, compilerFlags) {
|
|
77
77
|
super();
|
|
78
78
|
this.parseInfo = parseInfo;
|
|
79
79
|
this.msgLog = msgLog;
|
|
80
|
-
this.compilerFlags =
|
|
80
|
+
this.compilerFlags = compilerFlags;
|
|
81
81
|
for (const flag of DEFAULT_COMPILER_FLAGS) {
|
|
82
82
|
const withNewTag = tags_1.Tag.fromTagline(flag, this.compilerFlags);
|
|
83
83
|
this.compilerFlags = withNewTag.tag;
|
|
@@ -118,6 +118,14 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
118
118
|
severity: sev,
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
|
+
inExperiment(experimentID, cx) {
|
|
122
|
+
const experimental = this.compilerFlags.tag('experimental');
|
|
123
|
+
if (experimental) {
|
|
124
|
+
return experimental.bare() || experimental.has(experimentID);
|
|
125
|
+
}
|
|
126
|
+
this.contextError(cx, `Experimental flag '${experimentID}' required to enable this feature`);
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
121
129
|
m4Severity() {
|
|
122
130
|
const m4severityTag = this.compilerFlags.tag('m4warnings');
|
|
123
131
|
if (m4severityTag) {
|
|
@@ -1339,6 +1347,10 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1339
1347
|
const sqExpr = new ast.SQSourceWrapper(this.visitSqlSource(pcx.sqlSource()));
|
|
1340
1348
|
return this.astAt(sqExpr, pcx);
|
|
1341
1349
|
}
|
|
1350
|
+
visitExperimentalStatementForTesting(pcx) {
|
|
1351
|
+
this.inExperiment('compilerTestExperimentParse', pcx);
|
|
1352
|
+
return this.astAt(new ast.ExperimentalExperiment('compilerTestExperimentTranslate'), pcx);
|
|
1353
|
+
}
|
|
1342
1354
|
}
|
|
1343
1355
|
exports.MalloyToAST = MalloyToAST;
|
|
1344
1356
|
//# sourceMappingURL=malloy-to-ast.js.map
|
|
@@ -86,6 +86,7 @@ declare class HelpContextStep implements TranslationStep {
|
|
|
86
86
|
declare class TranslateStep implements TranslationStep {
|
|
87
87
|
readonly astStep: ASTStep;
|
|
88
88
|
response?: TranslateResponse;
|
|
89
|
+
importedFlags: boolean;
|
|
89
90
|
constructor(astStep: ASTStep);
|
|
90
91
|
step(that: MalloyTranslation, extendingModel?: ModelDef): TranslateResponse;
|
|
91
92
|
}
|
|
@@ -100,6 +101,7 @@ export declare abstract class MalloyTranslation {
|
|
|
100
101
|
sqlBlocks: SQLBlockStructDef[];
|
|
101
102
|
modelDef: ModelDef;
|
|
102
103
|
imports: ImportLocation[];
|
|
104
|
+
compilerFlags: Tag;
|
|
103
105
|
readonly parseStep: ParseStep;
|
|
104
106
|
readonly importsAndTablesStep: ImportsAndTablesStep;
|
|
105
107
|
readonly astStep: ASTStep;
|
|
@@ -166,7 +168,6 @@ export declare class MalloyTranslator extends MalloyTranslation {
|
|
|
166
168
|
importZone: Zone<string>;
|
|
167
169
|
sqlQueryZone: Zone<SQLBlockStructDef>;
|
|
168
170
|
logger: MessageLog;
|
|
169
|
-
compilerFlags: Tag;
|
|
170
171
|
readonly root: MalloyTranslator;
|
|
171
172
|
constructor(rootURL: string, importURL?: string | null, preload?: ParseUpdate | null);
|
|
172
173
|
update(dd: ParseUpdate): void;
|
|
@@ -291,9 +291,9 @@ class ASTStep {
|
|
|
291
291
|
if (!parse) {
|
|
292
292
|
throw new Error('TRANSLATOR INTERNAL ERROR: Translator parse response had no errors, but also no parser');
|
|
293
293
|
}
|
|
294
|
-
const secondPass = new malloy_to_ast_1.MalloyToAST(parse, that.root.logger);
|
|
294
|
+
const secondPass = new malloy_to_ast_1.MalloyToAST(parse, that.root.logger, that.compilerFlags);
|
|
295
295
|
const newAst = secondPass.visit(parse.root);
|
|
296
|
-
that.
|
|
296
|
+
that.compilerFlags = secondPass.compilerFlags;
|
|
297
297
|
if (that.root.logger.hasErrors()) {
|
|
298
298
|
this.response = that.fatalResponse();
|
|
299
299
|
return this.response;
|
|
@@ -450,11 +450,20 @@ class HelpContextStep {
|
|
|
450
450
|
class TranslateStep {
|
|
451
451
|
constructor(astStep) {
|
|
452
452
|
this.astStep = astStep;
|
|
453
|
+
this.importedFlags = false;
|
|
453
454
|
}
|
|
454
455
|
step(that, extendingModel) {
|
|
455
456
|
if (this.response) {
|
|
456
457
|
return this.response;
|
|
457
458
|
}
|
|
459
|
+
// begin with the compiler flags of the model we are extending
|
|
460
|
+
if (extendingModel && !this.importedFlags) {
|
|
461
|
+
const tagParse = tags_1.Tag.annotationToTag(extendingModel.annotation, {
|
|
462
|
+
prefix: /^##! /,
|
|
463
|
+
});
|
|
464
|
+
that.compilerFlags = tagParse.tag;
|
|
465
|
+
this.importedFlags = true;
|
|
466
|
+
}
|
|
458
467
|
const astResponse = this.astStep.step(that);
|
|
459
468
|
if ((0, translate_response_1.isNeedResponse)(astResponse)) {
|
|
460
469
|
return astResponse;
|
|
@@ -513,6 +522,7 @@ class MalloyTranslation {
|
|
|
513
522
|
this.queryList = [];
|
|
514
523
|
this.sqlBlocks = [];
|
|
515
524
|
this.imports = [];
|
|
525
|
+
this.compilerFlags = new tags_1.Tag();
|
|
516
526
|
this.childTranslators = new Map();
|
|
517
527
|
this.modelDef = {
|
|
518
528
|
name: sourceURL,
|
|
@@ -767,7 +777,6 @@ class MalloyTranslator extends MalloyTranslation {
|
|
|
767
777
|
this.importZone = new zone_1.Zone();
|
|
768
778
|
this.sqlQueryZone = new zone_1.Zone();
|
|
769
779
|
this.logger = new parse_log_1.MessageLog();
|
|
770
|
-
this.compilerFlags = new tags_1.Tag();
|
|
771
780
|
this.root = this;
|
|
772
781
|
if (preload) {
|
|
773
782
|
this.update(preload);
|
|
@@ -59,6 +59,18 @@ describe('model statements', () => {
|
|
|
59
59
|
test('errors on redefinition of query', () => {
|
|
60
60
|
expect('query: q1 is a -> { select: * }, q1 is a -> { select: * }').translationToFailWith("'q1' is already defined, cannot redefine");
|
|
61
61
|
});
|
|
62
|
+
test('##! experimental enables all experiments', () => {
|
|
63
|
+
expect('##! experimental\n;;[ "x" ]').toTranslate();
|
|
64
|
+
});
|
|
65
|
+
test('experimental explicit enable', () => {
|
|
66
|
+
expect('##! experimental { compilerTestExperimentParse compilerTestExperimentTranslate }\n;;[ "x" ]').toTranslate();
|
|
67
|
+
});
|
|
68
|
+
test('experiment failures in parse are flagged', () => {
|
|
69
|
+
expect(';;[ "x" ]').translationToFailWith("Experimental flag 'compilerTestExperimentParse' required to enable this feature");
|
|
70
|
+
});
|
|
71
|
+
test('experiment failures in second pass are flagged', () => {
|
|
72
|
+
expect('##! experimental.compilerTestExperimentParse\n;;[ "x" ]').translationToFailWith("Experimental flag 'compilerTestExperimentTranslate' is not set, feature not available");
|
|
73
|
+
});
|
|
62
74
|
});
|
|
63
75
|
describe('error handling', () => {
|
|
64
76
|
test('field and query with same name does not overflow', () => {
|
package/dist/malloy.d.ts
CHANGED
|
@@ -14,6 +14,9 @@ export interface Loggable {
|
|
|
14
14
|
export interface ParseOptions {
|
|
15
15
|
importBaseURL?: URL;
|
|
16
16
|
}
|
|
17
|
+
export interface CompileOptions {
|
|
18
|
+
refreshSchemaCache?: boolean | number;
|
|
19
|
+
}
|
|
17
20
|
export declare class Malloy {
|
|
18
21
|
static get version(): string;
|
|
19
22
|
private static _log;
|
|
@@ -53,11 +56,12 @@ export declare class Malloy {
|
|
|
53
56
|
* @param model A compiled model to build upon (optional).
|
|
54
57
|
* @return A (promise of a) compiled `Model`.
|
|
55
58
|
*/
|
|
56
|
-
static compile({ urlReader, connections, parse, model, }: {
|
|
59
|
+
static compile({ urlReader, connections, parse, model, refreshSchemaCache, }: {
|
|
57
60
|
urlReader: URLReader;
|
|
58
61
|
connections: LookupConnection<InfoConnection>;
|
|
59
62
|
parse: Parse;
|
|
60
63
|
model?: Model;
|
|
64
|
+
refreshSchemaCache?: boolean | number;
|
|
61
65
|
}): Promise<Model>;
|
|
62
66
|
private static compileSQLBlock;
|
|
63
67
|
/**
|
|
@@ -710,7 +714,7 @@ export declare class Runtime {
|
|
|
710
714
|
* @return A `ModelMaterializer` capable of materializing the requested model,
|
|
711
715
|
* or loading further related objects.
|
|
712
716
|
*/
|
|
713
|
-
loadModel(source: ModelURL | ModelString, options?: ParseOptions): ModelMaterializer;
|
|
717
|
+
loadModel(source: ModelURL | ModelString, options?: ParseOptions & CompileOptions): ModelMaterializer;
|
|
714
718
|
_loadModelFromModelDef(modelDef: ModelDef): ModelMaterializer;
|
|
715
719
|
/**
|
|
716
720
|
* Load a Malloy query by URL or contents.
|
|
@@ -719,7 +723,7 @@ export declare class Runtime {
|
|
|
719
723
|
* @return A `QueryMaterializer` capable of materializing the requested query, running it,
|
|
720
724
|
* or loading further related objects.
|
|
721
725
|
*/
|
|
722
|
-
loadQuery(query: QueryURL | QueryString, options?: ParseOptions): QueryMaterializer;
|
|
726
|
+
loadQuery(query: QueryURL | QueryString, options?: ParseOptions & CompileOptions): QueryMaterializer;
|
|
723
727
|
/**
|
|
724
728
|
* Load a Malloy query by the URL or contents of a Malloy model document
|
|
725
729
|
* and the index of an unnamed query contained in the model.
|
|
@@ -729,7 +733,7 @@ export declare class Runtime {
|
|
|
729
733
|
* @return A `QueryMaterializer` capable of materializing the requested query, running it,
|
|
730
734
|
* or loading further related objects.
|
|
731
735
|
*/
|
|
732
|
-
loadQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions): QueryMaterializer;
|
|
736
|
+
loadQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions & CompileOptions): QueryMaterializer;
|
|
733
737
|
/**
|
|
734
738
|
* Load a Malloy query by the URL or contents of a Malloy model document
|
|
735
739
|
* and the name of a query contained in the model.
|
|
@@ -739,7 +743,7 @@ export declare class Runtime {
|
|
|
739
743
|
* @return A `QueryMaterializer` capable of materializing the requested query, running it,
|
|
740
744
|
* or loading further related objects.
|
|
741
745
|
*/
|
|
742
|
-
loadQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions): QueryMaterializer;
|
|
746
|
+
loadQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions): QueryMaterializer;
|
|
743
747
|
/**
|
|
744
748
|
* Load a SQL block by the URL or contents of a Malloy model document
|
|
745
749
|
* and the name of a query contained in the model.
|
|
@@ -749,7 +753,7 @@ export declare class Runtime {
|
|
|
749
753
|
* @return A `SQLBlockMaterializer` capable of materializing the requested query, running it,
|
|
750
754
|
* or loading further related objects.
|
|
751
755
|
*/
|
|
752
|
-
loadSQLBlockByName(model: ModelURL | ModelString, name: string, options?: ParseOptions): SQLBlockMaterializer;
|
|
756
|
+
loadSQLBlockByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions): SQLBlockMaterializer;
|
|
753
757
|
/**
|
|
754
758
|
* Load a SQL block by the URL or contents of a Malloy model document
|
|
755
759
|
* and the name of a query contained in the model.
|
|
@@ -759,21 +763,21 @@ export declare class Runtime {
|
|
|
759
763
|
* @return A `SQLBlockMaterializer` capable of materializing the requested query, running it,
|
|
760
764
|
* or loading further related objects.
|
|
761
765
|
*/
|
|
762
|
-
loadSQLBlockByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions): SQLBlockMaterializer;
|
|
766
|
+
loadSQLBlockByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions & CompileOptions): SQLBlockMaterializer;
|
|
763
767
|
/**
|
|
764
768
|
* Compile a Malloy model by URL or contents.
|
|
765
769
|
*
|
|
766
770
|
* @param source The URL or contents of a Malloy model document to compile.
|
|
767
771
|
* @return A promise of a compiled `Model`.
|
|
768
772
|
*/
|
|
769
|
-
getModel(source: ModelURL | ModelString, options?: ParseOptions): Promise<Model>;
|
|
773
|
+
getModel(source: ModelURL | ModelString, options?: ParseOptions & CompileOptions): Promise<Model>;
|
|
770
774
|
/**
|
|
771
775
|
* Compile a Malloy query by URL or contents.
|
|
772
776
|
*
|
|
773
777
|
* @param query The URL or contents of a Malloy query document to compile.
|
|
774
778
|
* @return A promise of a compiled `PreparedQuery`.
|
|
775
779
|
*/
|
|
776
|
-
getQuery(query: QueryURL | QueryString, options?: ParseOptions): Promise<PreparedQuery>;
|
|
780
|
+
getQuery(query: QueryURL | QueryString, options?: ParseOptions & CompileOptions): Promise<PreparedQuery>;
|
|
777
781
|
/**
|
|
778
782
|
* Compile a Malloy query by the URL or contents of a model document
|
|
779
783
|
* and the index of an unnamed query contained within the model.
|
|
@@ -782,7 +786,7 @@ export declare class Runtime {
|
|
|
782
786
|
* @param index The index of an unnamed query contained within the model.
|
|
783
787
|
* @return A promise of a compiled `PreparedQuery`.
|
|
784
788
|
*/
|
|
785
|
-
getQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions): Promise<PreparedQuery>;
|
|
789
|
+
getQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions & CompileOptions): Promise<PreparedQuery>;
|
|
786
790
|
/**
|
|
787
791
|
* Compile a Malloy query by the URL or contents of a model document
|
|
788
792
|
* and the name of a query contained within the model.
|
|
@@ -791,7 +795,7 @@ export declare class Runtime {
|
|
|
791
795
|
* @param name The name of a query contained within the model.
|
|
792
796
|
* @return A promise of a compiled `PreparedQuery`.
|
|
793
797
|
*/
|
|
794
|
-
getQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions): Promise<PreparedQuery>;
|
|
798
|
+
getQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions): Promise<PreparedQuery>;
|
|
795
799
|
/**
|
|
796
800
|
* Get a SQL block by the URL or contents of a Malloy model document
|
|
797
801
|
* and the name of a SQL block contained in the model.
|
|
@@ -800,7 +804,7 @@ export declare class Runtime {
|
|
|
800
804
|
* @param name The name of the sql block to use within the model.
|
|
801
805
|
* @return A promise of a `CompiledSQLBlock`.
|
|
802
806
|
*/
|
|
803
|
-
getSQLBlockByName(model: ModelURL | ModelString, name: string, options?: ParseOptions): Promise<SQLBlockStructDef>;
|
|
807
|
+
getSQLBlockByName(model: ModelURL | ModelString, name: string, options?: ParseOptions & CompileOptions): Promise<SQLBlockStructDef>;
|
|
804
808
|
/**
|
|
805
809
|
* Get a SQL block by the URL or contents of a Malloy model document
|
|
806
810
|
* and the name of a query contained in the model.
|
|
@@ -809,7 +813,7 @@ export declare class Runtime {
|
|
|
809
813
|
* @param index The index of the SQL block to use within the model. Note: named blocks are indexable, too.
|
|
810
814
|
* @return A promise of a `SQLBlock`.
|
|
811
815
|
*/
|
|
812
|
-
getSQLBlockByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions): Promise<SQLBlockStructDef>;
|
|
816
|
+
getSQLBlockByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions & CompileOptions): Promise<SQLBlockStructDef>;
|
|
813
817
|
}
|
|
814
818
|
export declare class ConnectionRuntime extends Runtime {
|
|
815
819
|
readonly rawConnections: Connection[];
|
|
@@ -870,7 +874,7 @@ export declare class ModelMaterializer extends FluentState<Model> {
|
|
|
870
874
|
* @return A `QueryMaterializer` capable of materializing the requested query, running it,
|
|
871
875
|
* or loading further related objects.
|
|
872
876
|
*/
|
|
873
|
-
loadQuery(query: QueryString | QueryURL, options?: ParseOptions): QueryMaterializer;
|
|
877
|
+
loadQuery(query: QueryString | QueryURL, options?: ParseOptions & CompileOptions): QueryMaterializer;
|
|
874
878
|
/**
|
|
875
879
|
* Extend a Malloy model by URL or contents.
|
|
876
880
|
*
|
|
@@ -878,7 +882,7 @@ export declare class ModelMaterializer extends FluentState<Model> {
|
|
|
878
882
|
* @return A `ModelMaterializer` capable of materializing the requested model,
|
|
879
883
|
* or loading further related objects.
|
|
880
884
|
*/
|
|
881
|
-
extendModel(query: QueryString | QueryURL, options?: ParseOptions): ModelMaterializer;
|
|
885
|
+
extendModel(query: QueryString | QueryURL, options?: ParseOptions & CompileOptions): ModelMaterializer;
|
|
882
886
|
search(sourceName: string, searchTerm: string, limit?: number, searchField?: string | undefined): Promise<SearchIndexResult[] | undefined>;
|
|
883
887
|
searchValueMap(sourceName: string, limit?: number, options?: ParseOptions): Promise<SearchValueMapResult[] | undefined>;
|
|
884
888
|
/**
|
package/dist/malloy.js
CHANGED
|
@@ -77,7 +77,14 @@ class Malloy {
|
|
|
77
77
|
* @param model A compiled model to build upon (optional).
|
|
78
78
|
* @return A (promise of a) compiled `Model`.
|
|
79
79
|
*/
|
|
80
|
-
static async compile({ urlReader, connections, parse, model, }) {
|
|
80
|
+
static async compile({ urlReader, connections, parse, model, refreshSchemaCache, }) {
|
|
81
|
+
let refreshTimestamp;
|
|
82
|
+
if (refreshSchemaCache) {
|
|
83
|
+
refreshTimestamp =
|
|
84
|
+
typeof refreshSchemaCache === 'number'
|
|
85
|
+
? refreshSchemaCache
|
|
86
|
+
: Date.now();
|
|
87
|
+
}
|
|
81
88
|
const translator = parse._translator;
|
|
82
89
|
// eslint-disable-next-line no-constant-condition
|
|
83
90
|
while (true) {
|
|
@@ -132,7 +139,9 @@ class Malloy {
|
|
|
132
139
|
// TODO detect if the union of `Object.keys(tables)` and `Object.keys(errors)` is not the same
|
|
133
140
|
// as `Object.keys(tablePathByKey)`, i.e. that all tables are accounted for. Otherwise
|
|
134
141
|
// the translator runs into an infinite loop fetching tables.
|
|
135
|
-
const { schemas: tables, errors } = await connection.fetchSchemaForTables(tablePathByKey
|
|
142
|
+
const { schemas: tables, errors } = await connection.fetchSchemaForTables(tablePathByKey, {
|
|
143
|
+
refreshTimestamp,
|
|
144
|
+
});
|
|
136
145
|
translator.update({ tables, errors: { tables: errors } });
|
|
137
146
|
}
|
|
138
147
|
catch (error) {
|
|
@@ -154,7 +163,9 @@ class Malloy {
|
|
|
154
163
|
try {
|
|
155
164
|
const conn = await connections.lookupConnection(connectionName);
|
|
156
165
|
const expanded = Malloy.compileSQLBlock(result.partialModel, toCompile);
|
|
157
|
-
const resolved = await conn.fetchSchemaForSQLBlock(expanded
|
|
166
|
+
const resolved = await conn.fetchSchemaForSQLBlock(expanded, {
|
|
167
|
+
refreshTimestamp,
|
|
168
|
+
});
|
|
158
169
|
if (resolved.error) {
|
|
159
170
|
translator.update({
|
|
160
171
|
errors: { compileSQL: { [expanded.name]: resolved.error } },
|
|
@@ -1514,6 +1525,7 @@ class Runtime {
|
|
|
1514
1525
|
urlReader: this.urlReader,
|
|
1515
1526
|
connections: this.connections,
|
|
1516
1527
|
parse,
|
|
1528
|
+
refreshSchemaCache: options === null || options === void 0 ? void 0 : options.refreshSchemaCache,
|
|
1517
1529
|
});
|
|
1518
1530
|
});
|
|
1519
1531
|
}
|
|
@@ -1778,6 +1790,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1778
1790
|
connections,
|
|
1779
1791
|
parse,
|
|
1780
1792
|
model,
|
|
1793
|
+
refreshSchemaCache: options === null || options === void 0 ? void 0 : options.refreshSchemaCache,
|
|
1781
1794
|
});
|
|
1782
1795
|
return queryModel.preparedQuery;
|
|
1783
1796
|
});
|
|
@@ -1809,6 +1822,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1809
1822
|
connections,
|
|
1810
1823
|
parse,
|
|
1811
1824
|
model,
|
|
1825
|
+
refreshSchemaCache: options === null || options === void 0 ? void 0 : options.refreshSchemaCache,
|
|
1812
1826
|
});
|
|
1813
1827
|
return queryModel;
|
|
1814
1828
|
});
|
package/dist/runtime_types.d.ts
CHANGED
|
@@ -29,6 +29,12 @@ export interface URLReader {
|
|
|
29
29
|
*/
|
|
30
30
|
readURL: (url: URL) => Promise<string>;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Options passed to fetchSchema methods.
|
|
34
|
+
*/
|
|
35
|
+
export interface FetchSchemaOptions {
|
|
36
|
+
refreshTimestamp?: number;
|
|
37
|
+
}
|
|
32
38
|
/**
|
|
33
39
|
* An object capable of reading schemas for given table names.
|
|
34
40
|
*/
|
|
@@ -40,7 +46,7 @@ export interface InfoConnection {
|
|
|
40
46
|
* as a map of keys to table names.
|
|
41
47
|
* @return A mapping of table keys to schemas.
|
|
42
48
|
*/
|
|
43
|
-
fetchSchemaForTables(tables: Record<string, string
|
|
49
|
+
fetchSchemaForTables(tables: Record<string, string>, options: FetchSchemaOptions): Promise<{
|
|
44
50
|
schemas: Record<string, StructDef>;
|
|
45
51
|
errors: Record<string, string>;
|
|
46
52
|
}>;
|
|
@@ -50,7 +56,7 @@ export interface InfoConnection {
|
|
|
50
56
|
* @param block The SQL blocks to fetch schemas for.
|
|
51
57
|
* @return A mapping of SQL block names to schemas.
|
|
52
58
|
*/
|
|
53
|
-
fetchSchemaForSQLBlock(block: SQLBlock): Promise<{
|
|
59
|
+
fetchSchemaForSQLBlock(block: SQLBlock, options: FetchSchemaOptions): Promise<{
|
|
54
60
|
structDef: StructDef;
|
|
55
61
|
error?: undefined;
|
|
56
62
|
} | {
|
|
@@ -109,9 +115,7 @@ export interface PersistSQLResults extends Connection {
|
|
|
109
115
|
manifestTemporaryTable(sqlCommand: string): Promise<string>;
|
|
110
116
|
}
|
|
111
117
|
export interface StreamingConnection extends Connection {
|
|
112
|
-
runSQLStream(sqlCommand: string, options?:
|
|
113
|
-
rowLimit?: number;
|
|
114
|
-
}): AsyncIterableIterator<QueryDataRow>;
|
|
118
|
+
runSQLStream(sqlCommand: string, options?: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
|
|
115
119
|
}
|
|
116
120
|
/**
|
|
117
121
|
* A mapping of connection names to connections.
|
package/dist/tags.d.ts
CHANGED
|
@@ -29,8 +29,9 @@ export interface Taggable {
|
|
|
29
29
|
* tag.numeric(p?) => numeric value of tag.p or undefined
|
|
30
30
|
* tag.textArray(p ?) => string[] value of elements in tag.p or undefined
|
|
31
31
|
* tag.numericArray(p?) => string[] value of elements in tag.p or undefined
|
|
32
|
-
* tag.tag(p) => Tag value of tag.p
|
|
33
|
-
* tag.has(p) => boolean "tag contains tag.p"
|
|
32
|
+
* tag.tag(p?) => Tag value of tag.p
|
|
33
|
+
* tag.has(p?) => boolean "tag contains tag.p"
|
|
34
|
+
* tag.bare(p?) => tag.p exists and has no properties
|
|
34
35
|
* tag.dict => Record<string,Tag> of tag properties
|
|
35
36
|
* ```
|
|
36
37
|
*/
|
|
@@ -60,6 +61,7 @@ export declare class Tag implements TagInterface {
|
|
|
60
61
|
has(...at: string[]): boolean;
|
|
61
62
|
text(...at: string[]): string | undefined;
|
|
62
63
|
numeric(...at: string[]): number | undefined;
|
|
64
|
+
bare(...at: string[]): boolean | undefined;
|
|
63
65
|
get dict(): Record<string, Tag>;
|
|
64
66
|
array(...at: string[]): Tag[] | undefined;
|
|
65
67
|
textArray(...at: string[]): string[] | undefined;
|
package/dist/tags.js
CHANGED
|
@@ -42,8 +42,9 @@ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
|
42
42
|
* tag.numeric(p?) => numeric value of tag.p or undefined
|
|
43
43
|
* tag.textArray(p ?) => string[] value of elements in tag.p or undefined
|
|
44
44
|
* tag.numericArray(p?) => string[] value of elements in tag.p or undefined
|
|
45
|
-
* tag.tag(p) => Tag value of tag.p
|
|
46
|
-
* tag.has(p) => boolean "tag contains tag.p"
|
|
45
|
+
* tag.tag(p?) => Tag value of tag.p
|
|
46
|
+
* tag.has(p?) => boolean "tag contains tag.p"
|
|
47
|
+
* tag.bare(p?) => tag.p exists and has no properties
|
|
47
48
|
* tag.dict => Record<string,Tag> of tag properties
|
|
48
49
|
* ```
|
|
49
50
|
*/
|
|
@@ -188,6 +189,13 @@ class Tag {
|
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
191
|
}
|
|
192
|
+
bare(...at) {
|
|
193
|
+
const p = this.find(at);
|
|
194
|
+
if (p === undefined) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
return (p.properties === undefined || Object.entries(p.properties).length === 0);
|
|
198
|
+
}
|
|
191
199
|
get dict() {
|
|
192
200
|
const newDict = {};
|
|
193
201
|
if (this.properties) {
|