@malloydata/malloy 0.0.83 → 0.0.84-dev230920141302
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/malloy-parse-info.d.ts +1 -0
- package/dist/lang/malloy-to-ast.js +1 -1
- package/dist/lang/parse-malloy.d.ts +3 -2
- package/dist/lang/parse-malloy.js +6 -4
- package/dist/lang/test/imports.spec.js +12 -0
- package/dist/lang/test/test-translator.d.ts +1 -1
- package/dist/lang/test/test-translator.js +4 -4
- package/dist/malloy.d.ts +23 -18
- package/dist/malloy.js +44 -34
- package/package.json +1 -1
|
@@ -1254,7 +1254,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1254
1254
|
}
|
|
1255
1255
|
visitImportStatement(pcx) {
|
|
1256
1256
|
const url = this.getPlainString(pcx.importURL());
|
|
1257
|
-
const importStmt = this.astAt(new ast.ImportStatement(url, this.parseInfo.
|
|
1257
|
+
const importStmt = this.astAt(new ast.ImportStatement(url, this.parseInfo.importBaseURL), pcx);
|
|
1258
1258
|
const selectCx = pcx.importSelect();
|
|
1259
1259
|
if (selectCx) {
|
|
1260
1260
|
for (const item of selectCx.importItem()) {
|
|
@@ -91,6 +91,7 @@ declare class TranslateStep implements TranslationStep {
|
|
|
91
91
|
}
|
|
92
92
|
export declare abstract class MalloyTranslation {
|
|
93
93
|
readonly sourceURL: string;
|
|
94
|
+
readonly importBaseURL: string | null;
|
|
94
95
|
grammarRule: string;
|
|
95
96
|
abstract root: MalloyTranslator;
|
|
96
97
|
childTranslators: Map<string, MalloyTranslation>;
|
|
@@ -107,7 +108,7 @@ export declare abstract class MalloyTranslation {
|
|
|
107
108
|
readonly helpContextStep: HelpContextStep;
|
|
108
109
|
readonly translateStep: TranslateStep;
|
|
109
110
|
readonly references: ReferenceList;
|
|
110
|
-
constructor(sourceURL: string, grammarRule?: string);
|
|
111
|
+
constructor(sourceURL: string, importBaseURL?: string | null, grammarRule?: string);
|
|
111
112
|
addChild(url: string): void;
|
|
112
113
|
addReference(reference: DocumentReference): void;
|
|
113
114
|
referenceAt(position: DocumentPosition): DocumentReference | undefined;
|
|
@@ -167,7 +168,7 @@ export declare class MalloyTranslator extends MalloyTranslation {
|
|
|
167
168
|
logger: MessageLog;
|
|
168
169
|
compilerFlags: Tag;
|
|
169
170
|
readonly root: MalloyTranslator;
|
|
170
|
-
constructor(rootURL: string, preload?: ParseUpdate | null);
|
|
171
|
+
constructor(rootURL: string, importURL?: string | null, preload?: ParseUpdate | null);
|
|
171
172
|
update(dd: ParseUpdate): void;
|
|
172
173
|
}
|
|
173
174
|
interface ErrorData {
|
|
@@ -187,6 +187,7 @@ class ParseStep {
|
|
|
187
187
|
tokenStream: tokenStream,
|
|
188
188
|
sourceStream: inputStream,
|
|
189
189
|
sourceURL: that.sourceURL,
|
|
190
|
+
importBaseURL: that.importBaseURL || that.sourceURL,
|
|
190
191
|
rangeFromContext: cx => that.rangeFromContext(cx),
|
|
191
192
|
// TODO put the real version here
|
|
192
193
|
malloyVersion: '0.0.0-m4',
|
|
@@ -214,7 +215,7 @@ class ImportsAndTablesStep {
|
|
|
214
215
|
for (const relativeRef in this.parseReferences.urls) {
|
|
215
216
|
const firstRef = this.parseReferences.urls[relativeRef];
|
|
216
217
|
try {
|
|
217
|
-
const ref = decodeURI(new URL(relativeRef, that.sourceURL).toString());
|
|
218
|
+
const ref = decodeURI(new URL(relativeRef, that.importBaseURL || that.sourceURL).toString());
|
|
218
219
|
that.addChild(ref);
|
|
219
220
|
that.root.importZone.reference(ref, {
|
|
220
221
|
url: that.sourceURL,
|
|
@@ -505,8 +506,9 @@ class TranslateStep {
|
|
|
505
506
|
}
|
|
506
507
|
}
|
|
507
508
|
class MalloyTranslation {
|
|
508
|
-
constructor(sourceURL, grammarRule = 'malloyDocument') {
|
|
509
|
+
constructor(sourceURL, importBaseURL = null, grammarRule = 'malloyDocument') {
|
|
509
510
|
this.sourceURL = sourceURL;
|
|
511
|
+
this.importBaseURL = importBaseURL;
|
|
510
512
|
this.grammarRule = grammarRule;
|
|
511
513
|
this.queryList = [];
|
|
512
514
|
this.sqlBlocks = [];
|
|
@@ -759,8 +761,8 @@ exports.MalloyChildTranslator = MalloyChildTranslator;
|
|
|
759
761
|
* no need to call again, the translation is finished or error'd.
|
|
760
762
|
*/
|
|
761
763
|
class MalloyTranslator extends MalloyTranslation {
|
|
762
|
-
constructor(rootURL, preload = null) {
|
|
763
|
-
super(rootURL);
|
|
764
|
+
constructor(rootURL, importURL = null, preload = null) {
|
|
765
|
+
super(rootURL, importURL);
|
|
764
766
|
this.schemaZone = new zone_1.Zone();
|
|
765
767
|
this.importZone = new zone_1.Zone();
|
|
766
768
|
this.sqlQueryZone = new zone_1.Zone();
|
|
@@ -41,6 +41,18 @@ describe('import:', () => {
|
|
|
41
41
|
const aa = docParse.getSourceDef('aa');
|
|
42
42
|
expect(aa).toBeDefined();
|
|
43
43
|
});
|
|
44
|
+
test('simple source with importBaseURL', () => {
|
|
45
|
+
const docParse = new test_translator_1.TestTranslator('import "child"', 'http://example.com/');
|
|
46
|
+
const xr = docParse.unresolved();
|
|
47
|
+
expect(docParse).toParse();
|
|
48
|
+
expect(xr).toEqual({ urls: ['http://example.com/child'] });
|
|
49
|
+
docParse.update({
|
|
50
|
+
urls: { 'http://example.com/child': 'source: aa is a' },
|
|
51
|
+
});
|
|
52
|
+
expect(docParse).toTranslate();
|
|
53
|
+
const aa = docParse.getSourceDef('aa');
|
|
54
|
+
expect(aa).toBeDefined();
|
|
55
|
+
});
|
|
44
56
|
test('simple query', () => {
|
|
45
57
|
const docParse = new test_translator_1.TestTranslator('import "child"');
|
|
46
58
|
const xr = docParse.unresolved();
|
|
@@ -28,7 +28,7 @@ export declare class TestTranslator extends MalloyTranslator {
|
|
|
28
28
|
readonly testSrc: string;
|
|
29
29
|
testRoot?: TestRoot;
|
|
30
30
|
internalModel: ModelDef;
|
|
31
|
-
constructor(testSrc: string, rootRule?: string, internalModel?: ModelDef);
|
|
31
|
+
constructor(testSrc: string, importBaseURL?: string | null, rootRule?: string, internalModel?: ModelDef);
|
|
32
32
|
translate(): TranslateResponse;
|
|
33
33
|
addChild(url: string): void;
|
|
34
34
|
ast(): MalloyElement | undefined;
|
|
@@ -204,8 +204,8 @@ class TestChildTranslator extends parse_malloy_1.MalloyChildTranslator {
|
|
|
204
204
|
exports.TestChildTranslator = TestChildTranslator;
|
|
205
205
|
const testURI = 'internal://test/langtests/root.malloy';
|
|
206
206
|
class TestTranslator extends parse_malloy_1.MalloyTranslator {
|
|
207
|
-
constructor(testSrc, rootRule = 'malloyDocument', internalModel) {
|
|
208
|
-
super(testURI);
|
|
207
|
+
constructor(testSrc, importBaseURL = null, rootRule = 'malloyDocument', internalModel) {
|
|
208
|
+
super(testURI, importBaseURL);
|
|
209
209
|
this.testSrc = testSrc;
|
|
210
210
|
/*
|
|
211
211
|
* All test source files can assume that an import of this
|
|
@@ -374,7 +374,7 @@ exports.TestTranslator = TestTranslator;
|
|
|
374
374
|
TestTranslator.inspectCompile = false;
|
|
375
375
|
class BetaExpression extends TestTranslator {
|
|
376
376
|
constructor(src) {
|
|
377
|
-
super(src, 'justExpr');
|
|
377
|
+
super(src, null, 'justExpr');
|
|
378
378
|
}
|
|
379
379
|
testFS() {
|
|
380
380
|
const aStruct = this.internalModel.contents['ab'];
|
|
@@ -477,7 +477,7 @@ function makeModelFunc(options) {
|
|
|
477
477
|
return {
|
|
478
478
|
...ms,
|
|
479
479
|
translator: new TestTranslator(((_a = options.prefix) !== null && _a !== void 0 ? _a : '') +
|
|
480
|
-
(options.wrap ? options.wrap(ms.code) : ms.code), undefined, options === null || options === void 0 ? void 0 : options.model),
|
|
480
|
+
(options.wrap ? options.wrap(ms.code) : ms.code), null, undefined, options === null || options === void 0 ? void 0 : options.model),
|
|
481
481
|
};
|
|
482
482
|
};
|
|
483
483
|
}
|
package/dist/malloy.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export interface Loggable {
|
|
|
11
11
|
warn: (message?: any, ...optionalParams: any[]) => void;
|
|
12
12
|
error: (message?: any, ...optionalParams: any[]) => void;
|
|
13
13
|
}
|
|
14
|
+
export interface ParseOptions {
|
|
15
|
+
importBaseURL?: URL;
|
|
16
|
+
}
|
|
14
17
|
export declare class Malloy {
|
|
15
18
|
static get version(): string;
|
|
16
19
|
private static _log;
|
|
@@ -24,9 +27,10 @@ export declare class Malloy {
|
|
|
24
27
|
* @param urlReader Object capable of fetching URL contents.
|
|
25
28
|
* @return A (promise of a) `Parse` result.
|
|
26
29
|
*/
|
|
27
|
-
static parse({ url, urlReader, }: {
|
|
30
|
+
static parse({ url, urlReader, options, }: {
|
|
28
31
|
url: URL;
|
|
29
32
|
urlReader: URLReader;
|
|
33
|
+
options?: ParseOptions;
|
|
30
34
|
}): Promise<Parse>;
|
|
31
35
|
/**
|
|
32
36
|
* Parse a Malloy document by contents.
|
|
@@ -35,9 +39,10 @@ export declare class Malloy {
|
|
|
35
39
|
* @param source The contents of the Malloy document to parse.
|
|
36
40
|
* @return A `Parse` result.
|
|
37
41
|
*/
|
|
38
|
-
static parse({ source, url }: {
|
|
42
|
+
static parse({ source, url, options, }: {
|
|
39
43
|
url?: URL;
|
|
40
44
|
source: string;
|
|
45
|
+
options?: ParseOptions;
|
|
41
46
|
}): Parse;
|
|
42
47
|
/**
|
|
43
48
|
* Compile a parsed Malloy document.
|
|
@@ -700,7 +705,7 @@ export declare class Runtime {
|
|
|
700
705
|
* @return A `ModelMaterializer` capable of materializing the requested model,
|
|
701
706
|
* or loading further related objects.
|
|
702
707
|
*/
|
|
703
|
-
loadModel(source: ModelURL | ModelString): ModelMaterializer;
|
|
708
|
+
loadModel(source: ModelURL | ModelString, options?: ParseOptions): ModelMaterializer;
|
|
704
709
|
_loadModelFromModelDef(modelDef: ModelDef): ModelMaterializer;
|
|
705
710
|
/**
|
|
706
711
|
* Load a Malloy query by URL or contents.
|
|
@@ -709,7 +714,7 @@ export declare class Runtime {
|
|
|
709
714
|
* @return A `QueryMaterializer` capable of materializing the requested query, running it,
|
|
710
715
|
* or loading further related objects.
|
|
711
716
|
*/
|
|
712
|
-
loadQuery(query: QueryURL | QueryString): QueryMaterializer;
|
|
717
|
+
loadQuery(query: QueryURL | QueryString, options?: ParseOptions): QueryMaterializer;
|
|
713
718
|
/**
|
|
714
719
|
* Load a Malloy query by the URL or contents of a Malloy model document
|
|
715
720
|
* and the index of an unnamed query contained in the model.
|
|
@@ -719,7 +724,7 @@ export declare class Runtime {
|
|
|
719
724
|
* @return A `QueryMaterializer` capable of materializing the requested query, running it,
|
|
720
725
|
* or loading further related objects.
|
|
721
726
|
*/
|
|
722
|
-
loadQueryByIndex(model: ModelURL | ModelString, index: number): QueryMaterializer;
|
|
727
|
+
loadQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions): QueryMaterializer;
|
|
723
728
|
/**
|
|
724
729
|
* Load a Malloy query by the URL or contents of a Malloy model document
|
|
725
730
|
* and the name of a query contained in the model.
|
|
@@ -729,7 +734,7 @@ export declare class Runtime {
|
|
|
729
734
|
* @return A `QueryMaterializer` capable of materializing the requested query, running it,
|
|
730
735
|
* or loading further related objects.
|
|
731
736
|
*/
|
|
732
|
-
loadQueryByName(model: ModelURL | ModelString, name: string): QueryMaterializer;
|
|
737
|
+
loadQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions): QueryMaterializer;
|
|
733
738
|
/**
|
|
734
739
|
* Load a SQL block by the URL or contents of a Malloy model document
|
|
735
740
|
* and the name of a query contained in the model.
|
|
@@ -739,7 +744,7 @@ export declare class Runtime {
|
|
|
739
744
|
* @return A `SQLBlockMaterializer` capable of materializing the requested query, running it,
|
|
740
745
|
* or loading further related objects.
|
|
741
746
|
*/
|
|
742
|
-
loadSQLBlockByName(model: ModelURL | ModelString, name: string): SQLBlockMaterializer;
|
|
747
|
+
loadSQLBlockByName(model: ModelURL | ModelString, name: string, options?: ParseOptions): SQLBlockMaterializer;
|
|
743
748
|
/**
|
|
744
749
|
* Load a SQL block by the URL or contents of a Malloy model document
|
|
745
750
|
* and the name of a query contained in the model.
|
|
@@ -749,21 +754,21 @@ export declare class Runtime {
|
|
|
749
754
|
* @return A `SQLBlockMaterializer` capable of materializing the requested query, running it,
|
|
750
755
|
* or loading further related objects.
|
|
751
756
|
*/
|
|
752
|
-
loadSQLBlockByIndex(model: ModelURL | ModelString, index: number): SQLBlockMaterializer;
|
|
757
|
+
loadSQLBlockByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions): SQLBlockMaterializer;
|
|
753
758
|
/**
|
|
754
759
|
* Compile a Malloy model by URL or contents.
|
|
755
760
|
*
|
|
756
761
|
* @param source The URL or contents of a Malloy model document to compile.
|
|
757
762
|
* @return A promise of a compiled `Model`.
|
|
758
763
|
*/
|
|
759
|
-
getModel(source: ModelURL | ModelString): Promise<Model>;
|
|
764
|
+
getModel(source: ModelURL | ModelString, options?: ParseOptions): Promise<Model>;
|
|
760
765
|
/**
|
|
761
766
|
* Compile a Malloy query by URL or contents.
|
|
762
767
|
*
|
|
763
768
|
* @param query The URL or contents of a Malloy query document to compile.
|
|
764
769
|
* @return A promise of a compiled `PreparedQuery`.
|
|
765
770
|
*/
|
|
766
|
-
getQuery(query: QueryURL | QueryString): Promise<PreparedQuery>;
|
|
771
|
+
getQuery(query: QueryURL | QueryString, options?: ParseOptions): Promise<PreparedQuery>;
|
|
767
772
|
/**
|
|
768
773
|
* Compile a Malloy query by the URL or contents of a model document
|
|
769
774
|
* and the index of an unnamed query contained within the model.
|
|
@@ -772,7 +777,7 @@ export declare class Runtime {
|
|
|
772
777
|
* @param index The index of an unnamed query contained within the model.
|
|
773
778
|
* @return A promise of a compiled `PreparedQuery`.
|
|
774
779
|
*/
|
|
775
|
-
getQueryByIndex(model: ModelURL | ModelString, index: number): Promise<PreparedQuery>;
|
|
780
|
+
getQueryByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions): Promise<PreparedQuery>;
|
|
776
781
|
/**
|
|
777
782
|
* Compile a Malloy query by the URL or contents of a model document
|
|
778
783
|
* and the name of a query contained within the model.
|
|
@@ -781,7 +786,7 @@ export declare class Runtime {
|
|
|
781
786
|
* @param name The name of a query contained within the model.
|
|
782
787
|
* @return A promise of a compiled `PreparedQuery`.
|
|
783
788
|
*/
|
|
784
|
-
getQueryByName(model: ModelURL | ModelString, name: string): Promise<PreparedQuery>;
|
|
789
|
+
getQueryByName(model: ModelURL | ModelString, name: string, options?: ParseOptions): Promise<PreparedQuery>;
|
|
785
790
|
/**
|
|
786
791
|
* Get a SQL block by the URL or contents of a Malloy model document
|
|
787
792
|
* and the name of a SQL block contained in the model.
|
|
@@ -790,7 +795,7 @@ export declare class Runtime {
|
|
|
790
795
|
* @param name The name of the sql block to use within the model.
|
|
791
796
|
* @return A promise of a `CompiledSQLBlock`.
|
|
792
797
|
*/
|
|
793
|
-
getSQLBlockByName(model: ModelURL | ModelString, name: string): Promise<SQLBlockStructDef>;
|
|
798
|
+
getSQLBlockByName(model: ModelURL | ModelString, name: string, options?: ParseOptions): Promise<SQLBlockStructDef>;
|
|
794
799
|
/**
|
|
795
800
|
* Get a SQL block by the URL or contents of a Malloy model document
|
|
796
801
|
* and the name of a query contained in the model.
|
|
@@ -799,7 +804,7 @@ export declare class Runtime {
|
|
|
799
804
|
* @param index The index of the SQL block to use within the model. Note: named blocks are indexable, too.
|
|
800
805
|
* @return A promise of a `SQLBlock`.
|
|
801
806
|
*/
|
|
802
|
-
getSQLBlockByIndex(model: ModelURL | ModelString, index: number): Promise<SQLBlockStructDef>;
|
|
807
|
+
getSQLBlockByIndex(model: ModelURL | ModelString, index: number, options?: ParseOptions): Promise<SQLBlockStructDef>;
|
|
803
808
|
}
|
|
804
809
|
export declare class ConnectionRuntime extends Runtime {
|
|
805
810
|
readonly rawConnections: Connection[];
|
|
@@ -860,7 +865,7 @@ export declare class ModelMaterializer extends FluentState<Model> {
|
|
|
860
865
|
* @return A `QueryMaterializer` capable of materializing the requested query, running it,
|
|
861
866
|
* or loading further related objects.
|
|
862
867
|
*/
|
|
863
|
-
loadQuery(query: QueryString | QueryURL): QueryMaterializer;
|
|
868
|
+
loadQuery(query: QueryString | QueryURL, options?: ParseOptions): QueryMaterializer;
|
|
864
869
|
/**
|
|
865
870
|
* Extend a Malloy model by URL or contents.
|
|
866
871
|
*
|
|
@@ -868,9 +873,9 @@ export declare class ModelMaterializer extends FluentState<Model> {
|
|
|
868
873
|
* @return A `ModelMaterializer` capable of materializing the requested model,
|
|
869
874
|
* or loading further related objects.
|
|
870
875
|
*/
|
|
871
|
-
extendModel(query: QueryString | QueryURL): ModelMaterializer;
|
|
876
|
+
extendModel(query: QueryString | QueryURL, options?: ParseOptions): ModelMaterializer;
|
|
872
877
|
search(sourceName: string, searchTerm: string, limit?: number, searchField?: string | undefined): Promise<SearchIndexResult[] | undefined>;
|
|
873
|
-
searchValueMap(sourceName: string, limit?: number): Promise<SearchValueMapResult[] | undefined>;
|
|
878
|
+
searchValueMap(sourceName: string, limit?: number, options?: ParseOptions): Promise<SearchValueMapResult[] | undefined>;
|
|
874
879
|
/**
|
|
875
880
|
* Load a SQL Block by name.
|
|
876
881
|
*
|
|
@@ -915,7 +920,7 @@ export declare class ModelMaterializer extends FluentState<Model> {
|
|
|
915
920
|
* @param query The URL or contents of a query document to compile.
|
|
916
921
|
* @return A promise to a prepared query.
|
|
917
922
|
*/
|
|
918
|
-
getQuery(query: QueryString | QueryURL): Promise<PreparedQuery>;
|
|
923
|
+
getQuery(query: QueryString | QueryURL, options?: ParseOptions): Promise<PreparedQuery>;
|
|
919
924
|
/**
|
|
920
925
|
* Get a SQL Block by name.
|
|
921
926
|
*
|
package/dist/malloy.js
CHANGED
|
@@ -39,18 +39,22 @@ class Malloy {
|
|
|
39
39
|
static setLogger(log) {
|
|
40
40
|
Malloy._log = log;
|
|
41
41
|
}
|
|
42
|
-
static _parse(source, url) {
|
|
42
|
+
static _parse(source, url, options) {
|
|
43
43
|
if (url === undefined) {
|
|
44
44
|
url = new URL('internal://internal.malloy');
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
let importBaseURL = url;
|
|
47
|
+
if (options === null || options === void 0 ? void 0 : options.importBaseURL) {
|
|
48
|
+
importBaseURL = options === null || options === void 0 ? void 0 : options.importBaseURL;
|
|
49
|
+
}
|
|
50
|
+
const translator = new lang_1.MalloyTranslator(url.toString(), importBaseURL.toString(), {
|
|
47
51
|
urls: { [url.toString()]: source },
|
|
48
52
|
});
|
|
49
53
|
return new Parse(translator);
|
|
50
54
|
}
|
|
51
|
-
static parse({ url, urlReader, source, }) {
|
|
55
|
+
static parse({ url, urlReader, source, options, }) {
|
|
52
56
|
if (source !== undefined) {
|
|
53
|
-
return Malloy._parse(source, url);
|
|
57
|
+
return Malloy._parse(source, url, options);
|
|
54
58
|
}
|
|
55
59
|
else {
|
|
56
60
|
if (urlReader === undefined) {
|
|
@@ -60,7 +64,7 @@ class Malloy {
|
|
|
60
64
|
throw new Error('Internal Error: url is required if source not present.');
|
|
61
65
|
}
|
|
62
66
|
return urlReader.readURL(url).then(source => {
|
|
63
|
-
return Malloy._parse(source, url);
|
|
67
|
+
return Malloy._parse(source, url, options);
|
|
64
68
|
});
|
|
65
69
|
}
|
|
66
70
|
}
|
|
@@ -1484,15 +1488,17 @@ class Runtime {
|
|
|
1484
1488
|
* @return A `ModelMaterializer` capable of materializing the requested model,
|
|
1485
1489
|
* or loading further related objects.
|
|
1486
1490
|
*/
|
|
1487
|
-
loadModel(source) {
|
|
1491
|
+
loadModel(source, options) {
|
|
1488
1492
|
return new ModelMaterializer(this, async () => {
|
|
1489
1493
|
const parse = source instanceof URL
|
|
1490
1494
|
? await Malloy.parse({
|
|
1491
1495
|
url: source,
|
|
1492
1496
|
urlReader: this.urlReader,
|
|
1497
|
+
options,
|
|
1493
1498
|
})
|
|
1494
1499
|
: Malloy.parse({
|
|
1495
1500
|
source,
|
|
1501
|
+
options,
|
|
1496
1502
|
});
|
|
1497
1503
|
return Malloy.compile({
|
|
1498
1504
|
urlReader: this.urlReader,
|
|
@@ -1517,8 +1523,8 @@ class Runtime {
|
|
|
1517
1523
|
* @return A `QueryMaterializer` capable of materializing the requested query, running it,
|
|
1518
1524
|
* or loading further related objects.
|
|
1519
1525
|
*/
|
|
1520
|
-
loadQuery(query) {
|
|
1521
|
-
return this.loadModel(query).loadFinalQuery();
|
|
1526
|
+
loadQuery(query, options) {
|
|
1527
|
+
return this.loadModel(query, options).loadFinalQuery();
|
|
1522
1528
|
}
|
|
1523
1529
|
/**
|
|
1524
1530
|
* Load a Malloy query by the URL or contents of a Malloy model document
|
|
@@ -1529,8 +1535,8 @@ class Runtime {
|
|
|
1529
1535
|
* @return A `QueryMaterializer` capable of materializing the requested query, running it,
|
|
1530
1536
|
* or loading further related objects.
|
|
1531
1537
|
*/
|
|
1532
|
-
loadQueryByIndex(model, index) {
|
|
1533
|
-
return this.loadModel(model).loadQueryByIndex(index);
|
|
1538
|
+
loadQueryByIndex(model, index, options) {
|
|
1539
|
+
return this.loadModel(model, options).loadQueryByIndex(index);
|
|
1534
1540
|
}
|
|
1535
1541
|
/**
|
|
1536
1542
|
* Load a Malloy query by the URL or contents of a Malloy model document
|
|
@@ -1541,8 +1547,8 @@ class Runtime {
|
|
|
1541
1547
|
* @return A `QueryMaterializer` capable of materializing the requested query, running it,
|
|
1542
1548
|
* or loading further related objects.
|
|
1543
1549
|
*/
|
|
1544
|
-
loadQueryByName(model, name) {
|
|
1545
|
-
return this.loadModel(model).loadQueryByName(name);
|
|
1550
|
+
loadQueryByName(model, name, options) {
|
|
1551
|
+
return this.loadModel(model, options).loadQueryByName(name);
|
|
1546
1552
|
}
|
|
1547
1553
|
/**
|
|
1548
1554
|
* Load a SQL block by the URL or contents of a Malloy model document
|
|
@@ -1553,8 +1559,8 @@ class Runtime {
|
|
|
1553
1559
|
* @return A `SQLBlockMaterializer` capable of materializing the requested query, running it,
|
|
1554
1560
|
* or loading further related objects.
|
|
1555
1561
|
*/
|
|
1556
|
-
loadSQLBlockByName(model, name) {
|
|
1557
|
-
return this.loadModel(model).loadSQLBlockByName(name);
|
|
1562
|
+
loadSQLBlockByName(model, name, options) {
|
|
1563
|
+
return this.loadModel(model, options).loadSQLBlockByName(name);
|
|
1558
1564
|
}
|
|
1559
1565
|
/**
|
|
1560
1566
|
* Load a SQL block by the URL or contents of a Malloy model document
|
|
@@ -1565,8 +1571,8 @@ class Runtime {
|
|
|
1565
1571
|
* @return A `SQLBlockMaterializer` capable of materializing the requested query, running it,
|
|
1566
1572
|
* or loading further related objects.
|
|
1567
1573
|
*/
|
|
1568
|
-
loadSQLBlockByIndex(model, index) {
|
|
1569
|
-
return this.loadModel(model).loadSQLBlockByIndex(index);
|
|
1574
|
+
loadSQLBlockByIndex(model, index, options) {
|
|
1575
|
+
return this.loadModel(model, options).loadSQLBlockByIndex(index);
|
|
1570
1576
|
}
|
|
1571
1577
|
// TODO maybe use overloads for the alternative parameters
|
|
1572
1578
|
/**
|
|
@@ -1575,8 +1581,8 @@ class Runtime {
|
|
|
1575
1581
|
* @param source The URL or contents of a Malloy model document to compile.
|
|
1576
1582
|
* @return A promise of a compiled `Model`.
|
|
1577
1583
|
*/
|
|
1578
|
-
getModel(source) {
|
|
1579
|
-
return this.loadModel(source).getModel();
|
|
1584
|
+
getModel(source, options) {
|
|
1585
|
+
return this.loadModel(source, options).getModel();
|
|
1580
1586
|
}
|
|
1581
1587
|
/**
|
|
1582
1588
|
* Compile a Malloy query by URL or contents.
|
|
@@ -1584,8 +1590,8 @@ class Runtime {
|
|
|
1584
1590
|
* @param query The URL or contents of a Malloy query document to compile.
|
|
1585
1591
|
* @return A promise of a compiled `PreparedQuery`.
|
|
1586
1592
|
*/
|
|
1587
|
-
getQuery(query) {
|
|
1588
|
-
return this.loadQuery(query).getPreparedQuery();
|
|
1593
|
+
getQuery(query, options) {
|
|
1594
|
+
return this.loadQuery(query, options).getPreparedQuery();
|
|
1589
1595
|
}
|
|
1590
1596
|
/**
|
|
1591
1597
|
* Compile a Malloy query by the URL or contents of a model document
|
|
@@ -1595,8 +1601,8 @@ class Runtime {
|
|
|
1595
1601
|
* @param index The index of an unnamed query contained within the model.
|
|
1596
1602
|
* @return A promise of a compiled `PreparedQuery`.
|
|
1597
1603
|
*/
|
|
1598
|
-
getQueryByIndex(model, index) {
|
|
1599
|
-
return this.loadQueryByIndex(model, index).getPreparedQuery();
|
|
1604
|
+
getQueryByIndex(model, index, options) {
|
|
1605
|
+
return this.loadQueryByIndex(model, index, options).getPreparedQuery();
|
|
1600
1606
|
}
|
|
1601
1607
|
/**
|
|
1602
1608
|
* Compile a Malloy query by the URL or contents of a model document
|
|
@@ -1606,8 +1612,8 @@ class Runtime {
|
|
|
1606
1612
|
* @param name The name of a query contained within the model.
|
|
1607
1613
|
* @return A promise of a compiled `PreparedQuery`.
|
|
1608
1614
|
*/
|
|
1609
|
-
getQueryByName(model, name) {
|
|
1610
|
-
return this.loadQueryByName(model, name).getPreparedQuery();
|
|
1615
|
+
getQueryByName(model, name, options) {
|
|
1616
|
+
return this.loadQueryByName(model, name, options).getPreparedQuery();
|
|
1611
1617
|
}
|
|
1612
1618
|
/**
|
|
1613
1619
|
* Get a SQL block by the URL or contents of a Malloy model document
|
|
@@ -1617,8 +1623,8 @@ class Runtime {
|
|
|
1617
1623
|
* @param name The name of the sql block to use within the model.
|
|
1618
1624
|
* @return A promise of a `CompiledSQLBlock`.
|
|
1619
1625
|
*/
|
|
1620
|
-
getSQLBlockByName(model, name) {
|
|
1621
|
-
return this.loadSQLBlockByName(model, name).getSQLBlock();
|
|
1626
|
+
getSQLBlockByName(model, name, options) {
|
|
1627
|
+
return this.loadSQLBlockByName(model, name, options).getSQLBlock();
|
|
1622
1628
|
}
|
|
1623
1629
|
/**
|
|
1624
1630
|
* Get a SQL block by the URL or contents of a Malloy model document
|
|
@@ -1628,8 +1634,8 @@ class Runtime {
|
|
|
1628
1634
|
* @param index The index of the SQL block to use within the model. Note: named blocks are indexable, too.
|
|
1629
1635
|
* @return A promise of a `SQLBlock`.
|
|
1630
1636
|
*/
|
|
1631
|
-
getSQLBlockByIndex(model, index) {
|
|
1632
|
-
return this.loadSQLBlockByIndex(model, index).getSQLBlock();
|
|
1637
|
+
getSQLBlockByIndex(model, index, options) {
|
|
1638
|
+
return this.loadSQLBlockByIndex(model, index, options).getSQLBlock();
|
|
1633
1639
|
}
|
|
1634
1640
|
}
|
|
1635
1641
|
exports.Runtime = Runtime;
|
|
@@ -1742,7 +1748,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1742
1748
|
* @return A `QueryMaterializer` capable of materializing the requested query, running it,
|
|
1743
1749
|
* or loading further related objects.
|
|
1744
1750
|
*/
|
|
1745
|
-
loadQuery(query) {
|
|
1751
|
+
loadQuery(query, options) {
|
|
1746
1752
|
return this.makeQueryMaterializer(async () => {
|
|
1747
1753
|
const urlReader = this.runtime.urlReader;
|
|
1748
1754
|
const connections = this.runtime.connections;
|
|
@@ -1750,9 +1756,11 @@ class ModelMaterializer extends FluentState {
|
|
|
1750
1756
|
? await Malloy.parse({
|
|
1751
1757
|
url: query,
|
|
1752
1758
|
urlReader,
|
|
1759
|
+
options,
|
|
1753
1760
|
})
|
|
1754
1761
|
: Malloy.parse({
|
|
1755
1762
|
source: query,
|
|
1763
|
+
options,
|
|
1756
1764
|
});
|
|
1757
1765
|
const model = await this.getModel();
|
|
1758
1766
|
const queryModel = await Malloy.compile({
|
|
@@ -1771,7 +1779,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1771
1779
|
* @return A `ModelMaterializer` capable of materializing the requested model,
|
|
1772
1780
|
* or loading further related objects.
|
|
1773
1781
|
*/
|
|
1774
|
-
extendModel(query) {
|
|
1782
|
+
extendModel(query, options) {
|
|
1775
1783
|
return new ModelMaterializer(this.runtime, async () => {
|
|
1776
1784
|
const urlReader = this.runtime.urlReader;
|
|
1777
1785
|
const connections = this.runtime.connections;
|
|
@@ -1779,9 +1787,11 @@ class ModelMaterializer extends FluentState {
|
|
|
1779
1787
|
? await Malloy.parse({
|
|
1780
1788
|
url: query,
|
|
1781
1789
|
urlReader,
|
|
1790
|
+
options,
|
|
1782
1791
|
})
|
|
1783
1792
|
: Malloy.parse({
|
|
1784
1793
|
source: query,
|
|
1794
|
+
options,
|
|
1785
1795
|
});
|
|
1786
1796
|
const model = await this.getModel();
|
|
1787
1797
|
const queryModel = await Malloy.compile({
|
|
@@ -1804,7 +1814,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1804
1814
|
const connection = await this.runtime.connections.lookupConnection(connectionName);
|
|
1805
1815
|
return await queryModel.searchIndex(connection, sourceName, searchTerm, limit, searchField);
|
|
1806
1816
|
}
|
|
1807
|
-
async searchValueMap(sourceName, limit = 10) {
|
|
1817
|
+
async searchValueMap(sourceName, limit = 10, options) {
|
|
1808
1818
|
const model = await this.materialize();
|
|
1809
1819
|
const schema = model.getExploreByName(sourceName);
|
|
1810
1820
|
if (schema.structDef.structRelationship.type !== 'basetable') {
|
|
@@ -1829,7 +1839,7 @@ class ModelMaterializer extends FluentState {
|
|
|
1829
1839
|
limit: 1000
|
|
1830
1840
|
}
|
|
1831
1841
|
`;
|
|
1832
|
-
const result = await this.loadQuery(searchMapMalloy).run({
|
|
1842
|
+
const result = await this.loadQuery(searchMapMalloy, options).run({
|
|
1833
1843
|
rowLimit: 1000,
|
|
1834
1844
|
});
|
|
1835
1845
|
return result._queryResult.result;
|
|
@@ -1892,8 +1902,8 @@ class ModelMaterializer extends FluentState {
|
|
|
1892
1902
|
* @param query The URL or contents of a query document to compile.
|
|
1893
1903
|
* @return A promise to a prepared query.
|
|
1894
1904
|
*/
|
|
1895
|
-
getQuery(query) {
|
|
1896
|
-
return this.loadQuery(query).getPreparedQuery();
|
|
1905
|
+
getQuery(query, options) {
|
|
1906
|
+
return this.loadQuery(query, options).getPreparedQuery();
|
|
1897
1907
|
}
|
|
1898
1908
|
/**
|
|
1899
1909
|
* Get a SQL Block by name.
|