@malloydata/malloy 0.0.11-dev221202152346 → 0.0.11
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/index.d.ts +1 -1
- package/dist/lang/ast/ast-main.d.ts +61 -21
- package/dist/lang/ast/ast-main.js +170 -92
- package/dist/lang/index.d.ts +1 -1
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +135 -128
- package/dist/lang/lib/Malloy/MalloyLexer.js +1124 -1069
- package/dist/lang/lib/Malloy/MalloyListener.d.ts +2026 -0
- package/dist/lang/lib/Malloy/MalloyListener.js +4 -0
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +276 -232
- package/dist/lang/lib/Malloy/MalloyParser.js +1719 -1456
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +48 -15
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +30 -9
- package/dist/lang/lib/Malloy/MalloyVisitor.d.ts +1276 -0
- package/dist/lang/lib/Malloy/MalloyVisitor.js +4 -0
- package/dist/lang/parse-malloy.d.ts +14 -23
- package/dist/lang/parse-malloy.js +37 -51
- package/dist/lang/parse-to-ast.d.ts +3 -2
- package/dist/lang/parse-to-ast.js +45 -13
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +2 -2
- package/dist/lang/test/parse.spec.d.ts +5 -3
- package/dist/lang/test/parse.spec.js +267 -181
- package/dist/malloy.d.ts +20 -20
- package/dist/malloy.js +73 -75
- package/dist/md5.d.ts +1 -0
- package/dist/md5.js +30 -0
- package/dist/model/malloy_query.js +1 -1
- package/dist/model/malloy_types.d.ts +19 -9
- package/dist/model/malloy_types.js +10 -1
- package/dist/model/sql_block.d.ts +5 -9
- package/dist/model/sql_block.js +21 -13
- package/dist/runtime_types.d.ts +8 -23
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export { HighlightType, MalloyTranslator, } from "./lang";
|
|
|
4
4
|
export type { LogMessage, TranslateResponse } from "./lang";
|
|
5
5
|
export { Malloy, Runtime, AtomicFieldType, ConnectionRuntime, SingleConnectionRuntime, EmptyURLReader, InMemoryURLReader, FixedConnectionMap, MalloyError, JoinRelationship, SourceRelationship, DateTimeframe, TimestampTimeframe, Result, parseTableURI, QueryMaterializer, CSVWriter, JSONWriter, DataWriter, } from "./malloy";
|
|
6
6
|
export type { Explore, Model, PreparedQuery, PreparedResult, Field, AtomicField, ExploreField, QueryField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, ModelMaterializer, DocumentSymbol, DocumentHighlight, ResultJSON, RunSQLOptions, PreparedResultMaterializer, SQLBlockMaterializer, ExploreMaterializer, WriteStream, } from "./malloy";
|
|
7
|
-
export type { URLReader, InfoConnection, LookupConnection, Connection, QueryString, ModelString, QueryURL, ModelURL, PooledConnection, TestableConnection, PersistSQLResults,
|
|
7
|
+
export type { URLReader, InfoConnection, LookupConnection, Connection, QueryString, ModelString, QueryURL, ModelURL, PooledConnection, TestableConnection, PersistSQLResults, StreamingConnection, } from "./runtime_types";
|
|
8
8
|
export type { Loggable } from "./malloy";
|
|
9
9
|
export { toAsyncGenerator } from "./connection_utils";
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as model from "../../model/malloy_types";
|
|
2
2
|
import { FieldSpace, QuerySpace, LookupResult } from "../field-space";
|
|
3
|
-
import { MalloyTranslation } from "../parse-malloy";
|
|
3
|
+
import { MalloyTranslation, ModelDataRequest } from "../parse-malloy";
|
|
4
4
|
import { ConstantSubExpression, ExpressionDef, FieldDeclaration } from "./index";
|
|
5
|
-
import { SQLBlockRequest } from "../../model/sql_block";
|
|
6
5
|
export declare class ErrorFactory {
|
|
7
6
|
static get structDef(): model.StructDef;
|
|
8
7
|
static isErrorStructDef(s: model.StructDef): boolean;
|
|
@@ -55,7 +54,7 @@ export declare abstract class MalloyElement {
|
|
|
55
54
|
}
|
|
56
55
|
export declare class ListOf<ET extends MalloyElement> extends MalloyElement {
|
|
57
56
|
elementType: string;
|
|
58
|
-
|
|
57
|
+
protected elements: ET[];
|
|
59
58
|
constructor(listDesc: string, elements: ET[]);
|
|
60
59
|
private newContents;
|
|
61
60
|
get list(): ET[];
|
|
@@ -80,7 +79,11 @@ export declare abstract class Mallobj extends MalloyElement {
|
|
|
80
79
|
withParameters(pList: HasParameter[] | undefined): model.StructDef;
|
|
81
80
|
}
|
|
82
81
|
export interface DocStatement extends MalloyElement {
|
|
83
|
-
execute(doc: Document):
|
|
82
|
+
execute(doc: Document): ModelDataRequest;
|
|
83
|
+
}
|
|
84
|
+
export declare class RunList extends ListOf<DocStatement> {
|
|
85
|
+
execCursor: number;
|
|
86
|
+
executeList(doc: Document): ModelDataRequest;
|
|
84
87
|
}
|
|
85
88
|
export declare function isDocStatement(e: MalloyElement): e is DocStatement;
|
|
86
89
|
export declare class DefineExplore extends MalloyElement implements DocStatement {
|
|
@@ -90,11 +93,11 @@ export declare class DefineExplore extends MalloyElement implements DocStatement
|
|
|
90
93
|
elementType: string;
|
|
91
94
|
readonly parameters?: HasParameter[];
|
|
92
95
|
constructor(name: string, mallobj: Mallobj, exported: boolean, params?: MalloyElement[]);
|
|
93
|
-
execute(doc: Document):
|
|
96
|
+
execute(doc: Document): ModelDataRequest;
|
|
94
97
|
}
|
|
95
|
-
export declare class DefineSourceList extends
|
|
98
|
+
export declare class DefineSourceList extends RunList implements DocStatement {
|
|
96
99
|
constructor(sourceList: DefineExplore[]);
|
|
97
|
-
execute(doc: Document):
|
|
100
|
+
execute(doc: Document): ModelDataRequest;
|
|
98
101
|
}
|
|
99
102
|
/**
|
|
100
103
|
* A Mallobj made from a source and a set of refinements
|
|
@@ -263,22 +266,44 @@ export declare class QOPDesc extends ListOf<QueryProperty> {
|
|
|
263
266
|
getOp(inputFS: FieldSpace, forPipeline: PipelineDesc | null): OpDesc;
|
|
264
267
|
}
|
|
265
268
|
export interface ModelEntry {
|
|
266
|
-
entry: model.NamedModelObject
|
|
269
|
+
entry: model.NamedModelObject;
|
|
267
270
|
exported?: boolean;
|
|
271
|
+
sqlType?: boolean;
|
|
268
272
|
}
|
|
269
273
|
export interface NameSpace {
|
|
270
274
|
getEntry(name: string): ModelEntry | undefined;
|
|
271
275
|
setEntry(name: string, value: ModelEntry, exported: boolean): void;
|
|
272
276
|
}
|
|
277
|
+
interface DocumentCompileResult {
|
|
278
|
+
modelDef: model.ModelDef;
|
|
279
|
+
queryList: model.Query[];
|
|
280
|
+
sqlBlocks: model.SQLBlockStructDef[];
|
|
281
|
+
needs: ModelDataRequest;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* The Document class is a little weird because we might need to bounce back
|
|
285
|
+
* to the requestor, which might be on the other side of a wire, to get
|
|
286
|
+
* back some schema information. The intended translation of a Document
|
|
287
|
+
* is to call initModelDef(), and then to call modelDataRequest() until it
|
|
288
|
+
* returns undefined. At any time you can call modelDef to get the model
|
|
289
|
+
* as it exists so far, but the translation is not complete until
|
|
290
|
+
* modelDataRequest() returns undefined;
|
|
291
|
+
*
|
|
292
|
+
* TODO probably modelRequest should be the method and you call it
|
|
293
|
+
* until it returns a model with no additional data needed ...
|
|
294
|
+
* that can be tomorrow
|
|
295
|
+
*/
|
|
273
296
|
export declare class Document extends MalloyElement implements NameSpace {
|
|
274
|
-
readonly statements: DocStatement[];
|
|
275
297
|
elementType: string;
|
|
276
298
|
documentModel: Record<string, ModelEntry>;
|
|
277
299
|
queryList: model.Query[];
|
|
278
|
-
sqlBlocks: model.
|
|
300
|
+
sqlBlocks: model.SQLBlockStructDef[];
|
|
301
|
+
statements: RunList;
|
|
279
302
|
constructor(statements: DocStatement[]);
|
|
280
|
-
|
|
281
|
-
|
|
303
|
+
initModelDef(extendingModelDef: model.ModelDef | undefined): void;
|
|
304
|
+
compile(): DocumentCompileResult;
|
|
305
|
+
modelDef(): model.ModelDef;
|
|
306
|
+
defineSQL(sql: model.SQLBlockStructDef, name?: string): boolean;
|
|
282
307
|
getEntry(str: string): ModelEntry;
|
|
283
308
|
setEntry(str: string, ent: ModelEntry): void;
|
|
284
309
|
}
|
|
@@ -399,22 +424,22 @@ export declare class Nests extends ListOf<NestedQuery> {
|
|
|
399
424
|
}
|
|
400
425
|
export declare type QueryElement = FullQuery | ExistingQuery;
|
|
401
426
|
export declare function isQueryElement(e: MalloyElement): e is QueryElement;
|
|
402
|
-
export declare class DefineQueryList extends
|
|
427
|
+
export declare class DefineQueryList extends RunList implements DocStatement {
|
|
403
428
|
constructor(queryList: DefineQuery[]);
|
|
404
|
-
execute(doc: Document):
|
|
429
|
+
execute(doc: Document): ModelDataRequest;
|
|
405
430
|
}
|
|
406
431
|
export declare class DefineQuery extends MalloyElement implements DocStatement {
|
|
407
432
|
readonly name: string;
|
|
408
433
|
readonly queryDetails: QueryElement;
|
|
409
434
|
elementType: string;
|
|
410
435
|
constructor(name: string, queryDetails: QueryElement);
|
|
411
|
-
execute(doc: Document):
|
|
436
|
+
execute(doc: Document): ModelDataRequest;
|
|
412
437
|
}
|
|
413
438
|
export declare class AnonymousQuery extends MalloyElement implements DocStatement {
|
|
414
439
|
readonly theQuery: QueryElement;
|
|
415
440
|
elementType: string;
|
|
416
441
|
constructor(theQuery: QueryElement);
|
|
417
|
-
execute(doc: Document):
|
|
442
|
+
execute(doc: Document): ModelDataRequest;
|
|
418
443
|
}
|
|
419
444
|
declare type TopInit = FieldName | ExpressionDef;
|
|
420
445
|
export declare class Top extends MalloyElement {
|
|
@@ -441,7 +466,7 @@ export declare class ImportStatement extends MalloyElement implements DocStateme
|
|
|
441
466
|
elementType: string;
|
|
442
467
|
fullURL?: string;
|
|
443
468
|
constructor(url: string, baseURL: string);
|
|
444
|
-
execute(doc: Document):
|
|
469
|
+
execute(doc: Document): ModelDataRequest;
|
|
445
470
|
}
|
|
446
471
|
interface HasInit {
|
|
447
472
|
name: string;
|
|
@@ -463,13 +488,28 @@ export declare class ConstantParameter extends HasParameter {
|
|
|
463
488
|
constructor(name: string, value: ConstantSubExpression);
|
|
464
489
|
parameter(): model.Parameter;
|
|
465
490
|
}
|
|
491
|
+
declare type SQLStringSegment = string | QueryElement;
|
|
492
|
+
export declare class SQLString extends MalloyElement {
|
|
493
|
+
elementType: string;
|
|
494
|
+
elements: SQLStringSegment[];
|
|
495
|
+
containsQueries: boolean;
|
|
496
|
+
push(el: string | MalloyElement): void;
|
|
497
|
+
sqlPhrases(): model.SQLPhrase[];
|
|
498
|
+
}
|
|
466
499
|
export declare class SQLStatement extends MalloyElement implements DocStatement {
|
|
467
|
-
readonly
|
|
500
|
+
readonly select: SQLString;
|
|
468
501
|
elementType: string;
|
|
469
502
|
is?: string;
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
503
|
+
connection?: string;
|
|
504
|
+
requestBlock?: model.SQLBlockSource;
|
|
505
|
+
constructor(select: SQLString);
|
|
506
|
+
sqlBlock(): model.SQLBlockSource;
|
|
507
|
+
/**
|
|
508
|
+
* This is the one statement which pauses execution. First time through
|
|
509
|
+
* it will generate a schema request, next time through it will either
|
|
510
|
+
* record the error or record the schema.
|
|
511
|
+
*/
|
|
512
|
+
execute(doc: Document): ModelDataRequest;
|
|
473
513
|
}
|
|
474
514
|
export declare class SampleProperty extends MalloyElement {
|
|
475
515
|
readonly sample: model.Sampling;
|
|
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
exports.SampleProperty = exports.SQLStatement = exports.ConstantParameter = exports.HasParameter = exports.ImportStatement = exports.JSONStructDef = exports.JSONElement = exports.Top = exports.AnonymousQuery = exports.DefineQuery = exports.DefineQueryList = exports.isQueryElement = exports.Nests = exports.isNestedQuery = exports.NestDefinition = exports.NestRefinement = exports.NestReference = exports.TurtleDecl = void 0;
|
|
26
|
+
exports.TurtleHeadedPipe = exports.ExistingQuery = exports.Index = exports.Turtles = exports.Limit = exports.Ordering = exports.OrderBy = exports.WildcardFieldReference = exports.RenameField = exports.PrimaryKey = exports.Document = exports.QOPDesc = exports.Aggregate = exports.GroupBy = exports.FieldListEdit = exports.ProjectStatement = exports.isFieldCollectionMember = exports.FieldReferences = exports.FieldReference = exports.FieldName = exports.Renames = exports.Dimensions = exports.Measures = exports.DeclareFields = exports.Filter = exports.FilterElement = exports.ExploreDesc = exports.isExploreProperty = exports.isQueryProperty = exports.Joins = exports.ExpressionJoin = exports.KeyJoin = exports.Join = exports.QuerySource = exports.SQLSource = exports.NamedSource = exports.ModelEntryReference = exports.IsValueBlock = exports.TableSource = exports.RefinedExplore = exports.DefineSourceList = exports.DefineExplore = exports.isDocStatement = exports.RunList = exports.Mallobj = exports.isExploreField = exports.Unimplemented = exports.ListOf = exports.MalloyElement = exports.ErrorFactory = void 0;
|
|
27
|
+
exports.SampleProperty = exports.SQLStatement = exports.SQLString = exports.ConstantParameter = exports.HasParameter = exports.ImportStatement = exports.JSONStructDef = exports.JSONElement = exports.Top = exports.AnonymousQuery = exports.DefineQuery = exports.DefineQueryList = exports.isQueryElement = exports.Nests = exports.isNestedQuery = exports.NestDefinition = exports.NestRefinement = exports.NestReference = exports.TurtleDecl = exports.FullQuery = void 0;
|
|
28
28
|
/*
|
|
29
29
|
* Copyright 2021 Google LLC
|
|
30
30
|
*
|
|
@@ -174,20 +174,22 @@ class MalloyElement {
|
|
|
174
174
|
});
|
|
175
175
|
}
|
|
176
176
|
else if ((result === null || result === void 0 ? void 0 : result.entry.type) === "struct") {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
177
|
+
if (model.isSQLBlock(result.entry)) {
|
|
178
|
+
this.addReference({
|
|
179
|
+
type: "sqlBlockReference",
|
|
180
|
+
text: key,
|
|
181
|
+
definition: result.entry,
|
|
182
|
+
location: reference.location,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
this.addReference({
|
|
187
|
+
type: "exploreReference",
|
|
188
|
+
text: key,
|
|
189
|
+
definition: result.entry,
|
|
190
|
+
location: reference.location,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
return result;
|
|
@@ -398,6 +400,30 @@ class QueryHeadStruct extends Mallobj {
|
|
|
398
400
|
return ns.structDef();
|
|
399
401
|
}
|
|
400
402
|
}
|
|
403
|
+
class RunList extends ListOf {
|
|
404
|
+
constructor() {
|
|
405
|
+
super(...arguments);
|
|
406
|
+
this.execCursor = 0;
|
|
407
|
+
}
|
|
408
|
+
executeList(doc) {
|
|
409
|
+
while (this.execCursor < this.elements.length) {
|
|
410
|
+
if (doc.errorsExist()) {
|
|
411
|
+
// This stops cascading errors
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const el = this.elements[this.execCursor];
|
|
415
|
+
if (isDocStatement(el)) {
|
|
416
|
+
const resp = el.execute(doc);
|
|
417
|
+
if (resp) {
|
|
418
|
+
return resp;
|
|
419
|
+
}
|
|
420
|
+
this.execCursor += 1;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return undefined;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
exports.RunList = RunList;
|
|
401
427
|
function isDocStatement(e) {
|
|
402
428
|
return e.execute !== undefined;
|
|
403
429
|
}
|
|
@@ -443,15 +469,12 @@ class DefineExplore extends MalloyElement {
|
|
|
443
469
|
}
|
|
444
470
|
}
|
|
445
471
|
exports.DefineExplore = DefineExplore;
|
|
446
|
-
class DefineSourceList extends
|
|
472
|
+
class DefineSourceList extends RunList {
|
|
447
473
|
constructor(sourceList) {
|
|
448
474
|
super("defineSources", sourceList);
|
|
449
|
-
this.has({ sourceList });
|
|
450
475
|
}
|
|
451
476
|
execute(doc) {
|
|
452
|
-
|
|
453
|
-
dq.execute(doc);
|
|
454
|
-
}
|
|
477
|
+
return this.executeList(doc);
|
|
455
478
|
}
|
|
456
479
|
}
|
|
457
480
|
exports.DefineSourceList = DefineSourceList;
|
|
@@ -563,9 +586,7 @@ class TableSource extends Mallobj {
|
|
|
563
586
|
};
|
|
564
587
|
}
|
|
565
588
|
if (tableDefEntry.status == "error") {
|
|
566
|
-
msg = tableDefEntry.message
|
|
567
|
-
? `'Schema error: ${tableDefEntry.message}`
|
|
568
|
-
: `Schema error '${this.name}': ${tableDefEntry.message}`;
|
|
589
|
+
msg = tableDefEntry.message;
|
|
569
590
|
}
|
|
570
591
|
}
|
|
571
592
|
this.log(msg);
|
|
@@ -625,22 +646,22 @@ class NamedSource extends Mallobj {
|
|
|
625
646
|
return this.refName;
|
|
626
647
|
}
|
|
627
648
|
modelStruct() {
|
|
628
|
-
|
|
629
|
-
const
|
|
630
|
-
if (!
|
|
649
|
+
const modelEnt = this.modelEntry(this.ref);
|
|
650
|
+
const entry = modelEnt === null || modelEnt === void 0 ? void 0 : modelEnt.entry;
|
|
651
|
+
if (!entry) {
|
|
631
652
|
const undefMsg = `Undefined source '${this.refName}'`;
|
|
632
653
|
(this.ref instanceof ModelEntryReference ? this.ref : this).log(undefMsg);
|
|
633
654
|
return;
|
|
634
655
|
}
|
|
635
|
-
if (
|
|
636
|
-
this.log(`Must use 'from()'
|
|
656
|
+
if (entry.type === "query") {
|
|
657
|
+
this.log(`Must use 'from()' for query source '${this.refName}`);
|
|
637
658
|
return;
|
|
638
659
|
}
|
|
639
|
-
else if (modelEnt.
|
|
640
|
-
this.log(`Must use 'from_sql()'
|
|
660
|
+
else if (modelEnt.sqlType) {
|
|
661
|
+
this.log(`Must use 'from_sql()' for sql source '${this.refName}`);
|
|
641
662
|
return;
|
|
642
663
|
}
|
|
643
|
-
return { ...
|
|
664
|
+
return { ...entry };
|
|
644
665
|
}
|
|
645
666
|
structDef() {
|
|
646
667
|
/*
|
|
@@ -712,51 +733,21 @@ class SQLSource extends NamedSource {
|
|
|
712
733
|
return this.structDef();
|
|
713
734
|
}
|
|
714
735
|
modelStruct() {
|
|
715
|
-
|
|
716
|
-
const
|
|
717
|
-
if (!
|
|
736
|
+
const modelEnt = this.modelEntry(this.ref);
|
|
737
|
+
const entry = modelEnt === null || modelEnt === void 0 ? void 0 : modelEnt.entry;
|
|
738
|
+
if (!entry) {
|
|
718
739
|
this.log(`Undefined from_sql source '${this.refName}'`);
|
|
719
740
|
return;
|
|
720
741
|
}
|
|
721
|
-
if (
|
|
742
|
+
if (entry.type === "query") {
|
|
722
743
|
this.log(`Cannot use 'from_sql()' to explore query '${this.refName}'`);
|
|
723
744
|
return;
|
|
724
745
|
}
|
|
725
|
-
else if (modelEnt.
|
|
746
|
+
else if (!modelEnt.sqlType) {
|
|
726
747
|
this.log(`Cannot use 'from_sql()' to explore '${this.refName}'`);
|
|
727
748
|
return;
|
|
728
749
|
}
|
|
729
|
-
|
|
730
|
-
if (!sqlDefEntry) {
|
|
731
|
-
this.log(`Cant't look up schema for sql block '${this.refName}'`);
|
|
732
|
-
return;
|
|
733
|
-
}
|
|
734
|
-
if (modelEnt.type == "sqlBlock") {
|
|
735
|
-
const key = modelEnt.name;
|
|
736
|
-
const lookup = sqlDefEntry.getEntry(key);
|
|
737
|
-
let msg = `Schema read failure for sql query '${this.refName}'`;
|
|
738
|
-
if (lookup) {
|
|
739
|
-
if (lookup.status == "present") {
|
|
740
|
-
const structDef = lookup.value;
|
|
741
|
-
return {
|
|
742
|
-
...structDef,
|
|
743
|
-
fields: structDef.fields.map((field) => ({
|
|
744
|
-
...field,
|
|
745
|
-
location: modelEnt.location,
|
|
746
|
-
})),
|
|
747
|
-
};
|
|
748
|
-
}
|
|
749
|
-
if (lookup.status == "error") {
|
|
750
|
-
msg = lookup.message.includes(this.refName)
|
|
751
|
-
? `'Schema error: ${lookup.message}`
|
|
752
|
-
: `Schema error '${this.refName}': ${lookup.message}`;
|
|
753
|
-
}
|
|
754
|
-
this.log(msg);
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
else {
|
|
758
|
-
this.log(`Mis-typed definition for'${this.refName}'`);
|
|
759
|
-
}
|
|
750
|
+
return entry;
|
|
760
751
|
}
|
|
761
752
|
}
|
|
762
753
|
exports.SQLSource = SQLSource;
|
|
@@ -1397,16 +1388,30 @@ class QOPDesc extends ListOf {
|
|
|
1397
1388
|
}
|
|
1398
1389
|
}
|
|
1399
1390
|
exports.QOPDesc = QOPDesc;
|
|
1391
|
+
/**
|
|
1392
|
+
* The Document class is a little weird because we might need to bounce back
|
|
1393
|
+
* to the requestor, which might be on the other side of a wire, to get
|
|
1394
|
+
* back some schema information. The intended translation of a Document
|
|
1395
|
+
* is to call initModelDef(), and then to call modelDataRequest() until it
|
|
1396
|
+
* returns undefined. At any time you can call modelDef to get the model
|
|
1397
|
+
* as it exists so far, but the translation is not complete until
|
|
1398
|
+
* modelDataRequest() returns undefined;
|
|
1399
|
+
*
|
|
1400
|
+
* TODO probably modelRequest should be the method and you call it
|
|
1401
|
+
* until it returns a model with no additional data needed ...
|
|
1402
|
+
* that can be tomorrow
|
|
1403
|
+
*/
|
|
1400
1404
|
class Document extends MalloyElement {
|
|
1401
1405
|
constructor(statements) {
|
|
1402
|
-
super(
|
|
1403
|
-
this.statements = statements;
|
|
1406
|
+
super();
|
|
1404
1407
|
this.elementType = "document";
|
|
1405
1408
|
this.documentModel = {};
|
|
1406
1409
|
this.queryList = [];
|
|
1407
1410
|
this.sqlBlocks = [];
|
|
1411
|
+
this.statements = new RunList("topLevelStatements", statements);
|
|
1412
|
+
this.has({ statements });
|
|
1408
1413
|
}
|
|
1409
|
-
|
|
1414
|
+
initModelDef(extendingModelDef) {
|
|
1410
1415
|
this.documentModel = {};
|
|
1411
1416
|
this.queryList = [];
|
|
1412
1417
|
this.sqlBlocks = [];
|
|
@@ -1419,14 +1424,18 @@ class Document extends MalloyElement {
|
|
|
1419
1424
|
}
|
|
1420
1425
|
}
|
|
1421
1426
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1427
|
+
}
|
|
1428
|
+
compile() {
|
|
1429
|
+
const needs = this.statements.executeList(this);
|
|
1430
|
+
const ret = {
|
|
1431
|
+
modelDef: this.modelDef(),
|
|
1432
|
+
queryList: this.queryList,
|
|
1433
|
+
sqlBlocks: this.sqlBlocks,
|
|
1434
|
+
needs,
|
|
1435
|
+
};
|
|
1436
|
+
return ret;
|
|
1437
|
+
}
|
|
1438
|
+
modelDef() {
|
|
1430
1439
|
const def = { name: "", exports: [], contents: {} };
|
|
1431
1440
|
for (const entry in this.documentModel) {
|
|
1432
1441
|
const entryDef = this.documentModel[entry].entry;
|
|
@@ -1446,7 +1455,7 @@ class Document extends MalloyElement {
|
|
|
1446
1455
|
return false;
|
|
1447
1456
|
}
|
|
1448
1457
|
ret.as = name;
|
|
1449
|
-
this.setEntry(name, { entry: ret });
|
|
1458
|
+
this.setEntry(name, { entry: ret, sqlType: true });
|
|
1450
1459
|
}
|
|
1451
1460
|
this.sqlBlocks.push(ret);
|
|
1452
1461
|
return true;
|
|
@@ -1844,15 +1853,12 @@ function isQueryElement(e) {
|
|
|
1844
1853
|
return e instanceof FullQuery || e instanceof ExistingQuery;
|
|
1845
1854
|
}
|
|
1846
1855
|
exports.isQueryElement = isQueryElement;
|
|
1847
|
-
class DefineQueryList extends
|
|
1856
|
+
class DefineQueryList extends RunList {
|
|
1848
1857
|
constructor(queryList) {
|
|
1849
1858
|
super("defineQueries", queryList);
|
|
1850
|
-
this.has({ queryList });
|
|
1851
1859
|
}
|
|
1852
1860
|
execute(doc) {
|
|
1853
|
-
|
|
1854
|
-
dq.execute(doc);
|
|
1855
|
-
}
|
|
1861
|
+
return this.executeList(doc);
|
|
1856
1862
|
}
|
|
1857
1863
|
}
|
|
1858
1864
|
exports.DefineQueryList = DefineQueryList;
|
|
@@ -1872,6 +1878,7 @@ class DefineQuery extends MalloyElement {
|
|
|
1872
1878
|
};
|
|
1873
1879
|
const exported = false;
|
|
1874
1880
|
doc.setEntry(this.name, { entry, exported });
|
|
1881
|
+
return undefined;
|
|
1875
1882
|
}
|
|
1876
1883
|
}
|
|
1877
1884
|
exports.DefineQuery = DefineQuery;
|
|
@@ -1885,6 +1892,7 @@ class AnonymousQuery extends MalloyElement {
|
|
|
1885
1892
|
execute(doc) {
|
|
1886
1893
|
const modelQuery = this.theQuery.query();
|
|
1887
1894
|
doc.queryList.push(modelQuery);
|
|
1895
|
+
return undefined;
|
|
1888
1896
|
}
|
|
1889
1897
|
}
|
|
1890
1898
|
exports.AnonymousQuery = AnonymousQuery;
|
|
@@ -1981,6 +1989,10 @@ class ImportStatement extends MalloyElement {
|
|
|
1981
1989
|
else if (this.fullURL) {
|
|
1982
1990
|
const src = trans.root.importZone.getEntry(this.fullURL);
|
|
1983
1991
|
if (src.status === "present") {
|
|
1992
|
+
const childNeeds = trans.childRequest(this.fullURL);
|
|
1993
|
+
if (childNeeds) {
|
|
1994
|
+
return childNeeds;
|
|
1995
|
+
}
|
|
1984
1996
|
const importStructs = trans.getChildExports(this.fullURL);
|
|
1985
1997
|
for (const importing in importStructs) {
|
|
1986
1998
|
doc.setEntry(importing, {
|
|
@@ -1996,6 +2008,7 @@ class ImportStatement extends MalloyElement {
|
|
|
1996
2008
|
this.log(`import failed with status: '${src.status}'`);
|
|
1997
2009
|
}
|
|
1998
2010
|
}
|
|
2011
|
+
return undefined;
|
|
1999
2012
|
}
|
|
2000
2013
|
}
|
|
2001
2014
|
exports.ImportStatement = ImportStatement;
|
|
@@ -2061,21 +2074,86 @@ class ConstantParameter extends HasParameter {
|
|
|
2061
2074
|
}
|
|
2062
2075
|
}
|
|
2063
2076
|
exports.ConstantParameter = ConstantParameter;
|
|
2077
|
+
class SQLString extends MalloyElement {
|
|
2078
|
+
constructor() {
|
|
2079
|
+
super(...arguments);
|
|
2080
|
+
this.elementType = "sqlString";
|
|
2081
|
+
this.elements = [];
|
|
2082
|
+
this.containsQueries = false;
|
|
2083
|
+
}
|
|
2084
|
+
push(el) {
|
|
2085
|
+
if (typeof el == "string") {
|
|
2086
|
+
if (el.length > 0) {
|
|
2087
|
+
this.elements.push(el);
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
else if (isQueryElement(el)) {
|
|
2091
|
+
this.elements.push(el);
|
|
2092
|
+
this.containsQueries = true;
|
|
2093
|
+
el.parent = this;
|
|
2094
|
+
}
|
|
2095
|
+
else {
|
|
2096
|
+
el.log("This element is not legal inside an SQL string");
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
sqlPhrases() {
|
|
2100
|
+
return this.elements.map((el) => {
|
|
2101
|
+
if (typeof el == "string") {
|
|
2102
|
+
return { sql: el };
|
|
2103
|
+
}
|
|
2104
|
+
return el.query();
|
|
2105
|
+
});
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
exports.SQLString = SQLString;
|
|
2064
2109
|
class SQLStatement extends MalloyElement {
|
|
2065
|
-
constructor(
|
|
2110
|
+
constructor(select) {
|
|
2066
2111
|
super();
|
|
2067
|
-
this.
|
|
2112
|
+
this.select = select;
|
|
2068
2113
|
this.elementType = "sqlStatement";
|
|
2114
|
+
this.has({ select });
|
|
2069
2115
|
}
|
|
2070
2116
|
sqlBlock() {
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2117
|
+
if (!this.requestBlock) {
|
|
2118
|
+
this.requestBlock = (0, sql_block_1.makeSQLBlock)(this.select.sqlPhrases(), this.connection);
|
|
2119
|
+
}
|
|
2120
|
+
return this.requestBlock;
|
|
2074
2121
|
}
|
|
2122
|
+
/**
|
|
2123
|
+
* This is the one statement which pauses execution. First time through
|
|
2124
|
+
* it will generate a schema request, next time through it will either
|
|
2125
|
+
* record the error or record the schema.
|
|
2126
|
+
*/
|
|
2075
2127
|
execute(doc) {
|
|
2076
|
-
|
|
2077
|
-
|
|
2128
|
+
var _a;
|
|
2129
|
+
const sqlDefEntry = (_a = this.translator()) === null || _a === void 0 ? void 0 : _a.root.sqlQueryZone;
|
|
2130
|
+
if (!sqlDefEntry) {
|
|
2131
|
+
this.log("Cant't look up schema for sql block");
|
|
2132
|
+
return;
|
|
2078
2133
|
}
|
|
2134
|
+
const sql = this.sqlBlock();
|
|
2135
|
+
sqlDefEntry.reference(sql.name, this.location);
|
|
2136
|
+
const lookup = sqlDefEntry.getEntry(sql.name);
|
|
2137
|
+
if (lookup.status == "error") {
|
|
2138
|
+
this.select.log(`'Schema error: ${lookup.message}`);
|
|
2139
|
+
return undefined;
|
|
2140
|
+
}
|
|
2141
|
+
if (lookup.status == "present") {
|
|
2142
|
+
const location = this.select.location;
|
|
2143
|
+
const locStruct = {
|
|
2144
|
+
...lookup.value,
|
|
2145
|
+
fields: lookup.value.fields.map((f) => ({ ...f, location })),
|
|
2146
|
+
location: this.location,
|
|
2147
|
+
};
|
|
2148
|
+
if (this.is && !doc.defineSQL(locStruct, this.is)) {
|
|
2149
|
+
this.log(`'${this.is}' already defined`);
|
|
2150
|
+
}
|
|
2151
|
+
return undefined;
|
|
2152
|
+
}
|
|
2153
|
+
return {
|
|
2154
|
+
compileSQL: sql,
|
|
2155
|
+
partialModel: this.select.containsQueries ? doc.modelDef() : undefined,
|
|
2156
|
+
};
|
|
2079
2157
|
}
|
|
2080
2158
|
}
|
|
2081
2159
|
exports.SQLStatement = SQLStatement;
|
package/dist/lang/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { MalloyTranslator } from "./parse-malloy";
|
|
2
|
-
export type { TranslateResponse, UpdateData, SchemaData, URLData,
|
|
2
|
+
export type { TranslateResponse, UpdateData, SchemaData, URLData, SQLBlockData, } from "./parse-malloy";
|
|
3
3
|
export { exploreQueryWalkerBuilder } from "./parse-tree-walkers/explore-query-walker";
|
|
4
4
|
export type { ExploreClauseRef } from "./parse-tree-walkers/explore-query-walker";
|
|
5
5
|
export { HighlightType } from "./parse-tree-walkers/document-highlight-walker";
|