@malloydata/malloy 0.0.43 → 0.0.44-dev230623185845
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 +2 -1
- package/dist/index.js +3 -1
- package/dist/lang/ast/elements/define-query.d.ts +7 -1
- package/dist/lang/ast/elements/define-query.js +10 -1
- package/dist/lang/ast/elements/define-source.d.ts +7 -1
- package/dist/lang/ast/elements/define-source.js +16 -9
- package/dist/lang/ast/elements/pipeline-desc.d.ts +2 -1
- package/dist/lang/ast/elements/pipeline-desc.js +6 -2
- package/dist/lang/ast/elements/refined-source.d.ts +5 -4
- package/dist/lang/ast/elements/refined-source.js +5 -0
- package/dist/lang/ast/expressions/expr-id-reference.js +4 -4
- package/dist/lang/ast/field-space/column-space-field.d.ts +1 -1
- package/dist/lang/ast/field-space/column-space-field.js +3 -3
- package/dist/lang/ast/field-space/field-definition-value.d.ts +1 -1
- package/dist/lang/ast/field-space/field-definition-value.js +16 -10
- package/dist/lang/ast/field-space/query-field-struct.js +1 -0
- package/dist/lang/ast/field-space/query-spaces.js +4 -1
- package/dist/lang/ast/field-space/reference-field.d.ts +8 -2
- package/dist/lang/ast/field-space/reference-field.js +51 -9
- package/dist/lang/ast/index.d.ts +2 -2
- package/dist/lang/ast/index.js +2 -2
- package/dist/lang/ast/query-elements/anonymous-query.d.ts +6 -1
- package/dist/lang/ast/query-elements/anonymous-query.js +8 -0
- package/dist/lang/ast/query-elements/existing-query.js +3 -0
- package/dist/lang/ast/query-elements/full-query.js +7 -4
- package/dist/lang/ast/query-elements/run-query.d.ts +6 -1
- package/dist/lang/ast/query-elements/run-query.js +11 -1
- package/dist/lang/ast/query-items/field-declaration.d.ts +6 -2
- package/dist/lang/ast/query-items/field-declaration.js +6 -0
- package/dist/lang/ast/query-items/field-references.d.ts +13 -5
- package/dist/lang/ast/query-items/field-references.js +10 -4
- package/dist/lang/ast/query-properties/aggregate.d.ts +3 -3
- package/dist/lang/ast/query-properties/aggregate.js +5 -4
- package/dist/lang/ast/query-properties/calculate.d.ts +3 -3
- package/dist/lang/ast/query-properties/calculate.js +5 -4
- package/dist/lang/ast/query-properties/declare-fields.d.ts +4 -3
- package/dist/lang/ast/query-properties/declare-fields.js +5 -4
- package/dist/lang/ast/query-properties/dimensions.d.ts +4 -0
- package/dist/lang/ast/query-properties/{dimmensions.js → dimensions.js} +4 -3
- package/dist/lang/ast/query-properties/extend.d.ts +1 -1
- package/dist/lang/ast/query-properties/extend.js +3 -2
- package/dist/lang/ast/query-properties/filters.d.ts +0 -1
- package/dist/lang/ast/query-properties/filters.js +2 -2
- package/dist/lang/ast/query-properties/group-by.d.ts +3 -3
- package/dist/lang/ast/query-properties/group-by.js +5 -4
- package/dist/lang/ast/query-properties/joins.d.ts +10 -4
- package/dist/lang/ast/query-properties/joins.js +16 -2
- package/dist/lang/ast/query-properties/measures.d.ts +1 -2
- package/dist/lang/ast/query-properties/measures.js +3 -2
- package/dist/lang/ast/query-properties/nest.d.ts +5 -1
- package/dist/lang/ast/query-properties/nest.js +11 -1
- package/dist/lang/ast/query-properties/nests.d.ts +3 -2
- package/dist/lang/ast/query-properties/nests.js +4 -3
- package/dist/lang/ast/query-properties/ordering.d.ts +1 -0
- package/dist/lang/ast/query-properties/ordering.js +2 -1
- package/dist/lang/ast/query-properties/project-statement.d.ts +3 -3
- package/dist/lang/ast/query-properties/project-statement.js +5 -4
- package/dist/lang/ast/query-properties/qop-desc.d.ts +1 -1
- package/dist/lang/ast/query-properties/qop-desc.js +3 -2
- package/dist/lang/ast/source-properties/renames.d.ts +1 -1
- package/dist/lang/ast/source-properties/renames.js +3 -2
- package/dist/lang/ast/source-properties/turtles.d.ts +3 -3
- package/dist/lang/ast/source-properties/turtles.js +5 -4
- package/dist/lang/ast/types/definition-list.d.ts +10 -0
- package/dist/lang/ast/types/definition-list.js +52 -0
- package/dist/lang/ast/types/malloy-element.d.ts +21 -6
- package/dist/lang/ast/types/malloy-element.js +45 -13
- package/dist/lang/ast/types/noteable.d.ts +12 -0
- package/dist/lang/ast/types/noteable.js +42 -0
- package/dist/lang/ast/types/query-extend-property.d.ts +1 -1
- package/dist/lang/ast/types/query-extend-property.js +2 -2
- package/dist/lang/ast/types/query-property.d.ts +3 -2
- package/dist/lang/ast/types/query-property.js +2 -0
- package/dist/lang/ast/types/source-desc.d.ts +5 -0
- package/dist/lang/ast/types/{explore-desc.js → source-desc.js} +7 -6
- package/dist/lang/ast/types/source-property.d.ts +2 -2
- package/dist/lang/ast/types/source-property.js +2 -0
- package/dist/lang/ast/types/space-field.d.ts +1 -0
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +56 -54
- package/dist/lang/lib/Malloy/MalloyLexer.js +1051 -1042
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +326 -182
- package/dist/lang/lib/Malloy/MalloyParser.js +2894 -1718
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +133 -19
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +83 -11
- package/dist/lang/malloy-to-ast.d.ts +23 -10
- package/dist/lang/malloy-to-ast.js +144 -122
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +2 -1
- package/dist/lang/test/annotation.spec.d.ts +1 -0
- package/dist/lang/test/annotation.spec.js +565 -0
- package/dist/lang/test/parse.spec.js +20 -19
- package/dist/lang/test/test-translator.d.ts +2 -2
- package/dist/lang/test/test-translator.js +27 -15
- package/dist/malloy.d.ts +11 -5
- package/dist/malloy.js +16 -0
- package/dist/model/malloy_query.js +10 -0
- package/dist/model/malloy_types.d.ts +19 -2
- package/dist/model/malloy_types.js +1 -1
- package/dist/tags.d.ts +21 -0
- package/dist/tags.js +155 -0
- package/package.json +1 -1
- package/dist/lang/ast/query-properties/dimmensions.d.ts +0 -5
- package/dist/lang/ast/types/explore-desc.d.ts +0 -5
|
@@ -49,7 +49,7 @@ export declare class BetaExpression extends TestTranslator {
|
|
|
49
49
|
}
|
|
50
50
|
export declare function getExplore(modelDef: ModelDef, name: string): StructDef;
|
|
51
51
|
export declare function getModelQuery(modelDef: ModelDef, name: string): Query;
|
|
52
|
-
export declare function
|
|
52
|
+
export declare function getFieldDef(thing: StructDef | PipeSegment, name: string): FieldDef;
|
|
53
53
|
export declare function getQueryField(structDef: StructDef, name: string): TurtleDef;
|
|
54
54
|
export declare function getJoinField(structDef: StructDef, name: string): StructDef;
|
|
55
55
|
export interface MarkedSource {
|
|
@@ -57,10 +57,10 @@ export interface MarkedSource {
|
|
|
57
57
|
locations: DocumentLocation[];
|
|
58
58
|
translator?: TestTranslator;
|
|
59
59
|
}
|
|
60
|
-
export declare function expr(unmarked: TemplateStringsArray, ...marked: string[]): MarkedSource;
|
|
61
60
|
interface HasTranslator extends MarkedSource {
|
|
62
61
|
translator: TestTranslator;
|
|
63
62
|
}
|
|
63
|
+
export declare function expr(unmarked: TemplateStringsArray, ...marked: string[]): HasTranslator;
|
|
64
64
|
export declare function model(unmarked: TemplateStringsArray, ...marked: string[]): HasTranslator;
|
|
65
65
|
export declare function markSource(unmarked: TemplateStringsArray, ...marked: string[]): MarkedSource;
|
|
66
66
|
export {};
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.markSource = exports.model = exports.expr = exports.getJoinField = exports.getQueryField = exports.
|
|
26
|
+
exports.markSource = exports.model = exports.expr = exports.getJoinField = exports.getQueryField = exports.getFieldDef = exports.getModelQuery = exports.getExplore = exports.BetaExpression = exports.TestTranslator = exports.TestChildTranslator = exports.aTableDef = exports.pretty = void 0;
|
|
27
27
|
const util_1 = require("util");
|
|
28
28
|
const malloy_types_1 = require("../../model/malloy_types");
|
|
29
29
|
const ast_1 = require("../ast");
|
|
@@ -396,34 +396,46 @@ function getModelQuery(modelDef, name) {
|
|
|
396
396
|
return modelDef.contents[name];
|
|
397
397
|
}
|
|
398
398
|
exports.getModelQuery = getModelQuery;
|
|
399
|
-
function
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
399
|
+
function getFieldDef(thing, name) {
|
|
400
|
+
let found = undefined;
|
|
401
|
+
for (const f of thing.fields) {
|
|
402
|
+
if (typeof f === 'string') {
|
|
403
|
+
if (f === name) {
|
|
404
|
+
throw new Error(`Expected def for '${name}', found a ref`);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
else if ((f.as || f.name) === name) {
|
|
408
|
+
if ((0, malloy_types_1.isFilteredAliasedName)(f)) {
|
|
409
|
+
throw new Error(`FilteredAliasedName for '${name}' unexpected`);
|
|
410
|
+
}
|
|
411
|
+
found = f;
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
403
414
|
}
|
|
404
|
-
if (
|
|
405
|
-
throw new Error(
|
|
415
|
+
if (found === undefined) {
|
|
416
|
+
throw new Error(`Compiled code did not contain expected field '${name}'`);
|
|
406
417
|
}
|
|
407
|
-
|
|
408
|
-
|
|
418
|
+
else {
|
|
419
|
+
return found;
|
|
409
420
|
}
|
|
410
|
-
return result;
|
|
411
421
|
}
|
|
412
|
-
exports.
|
|
422
|
+
exports.getFieldDef = getFieldDef;
|
|
413
423
|
// TODO "as" is almost always a code smell ...
|
|
414
424
|
function getQueryField(structDef, name) {
|
|
415
|
-
return
|
|
425
|
+
return getFieldDef(structDef, name);
|
|
416
426
|
}
|
|
417
427
|
exports.getQueryField = getQueryField;
|
|
418
428
|
// TODO "as" is almost always a code smell ...
|
|
419
429
|
function getJoinField(structDef, name) {
|
|
420
|
-
return
|
|
430
|
+
return getFieldDef(structDef, name);
|
|
421
431
|
}
|
|
422
432
|
exports.getJoinField = getJoinField;
|
|
423
433
|
function expr(unmarked, ...marked) {
|
|
424
434
|
const ms = markSource(unmarked, ...marked);
|
|
425
|
-
|
|
426
|
-
|
|
435
|
+
return {
|
|
436
|
+
...ms,
|
|
437
|
+
translator: new BetaExpression(ms.code),
|
|
438
|
+
};
|
|
427
439
|
}
|
|
428
440
|
exports.expr = expr;
|
|
429
441
|
function model(unmarked, ...marked) {
|
package/dist/malloy.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { DocumentCompletion as DocumentCompletionDefinition, DocumentHighlight a
|
|
|
4
4
|
import { DocumentHelpContext } from './lang/parse-tree-walkers/document-help-context-walker';
|
|
5
5
|
import { CompiledQuery, DocumentReference, FieldBooleanDef, FieldDateDef, FieldJSONDef, FieldNumberDef, FieldStringDef, FieldTimestampDef, FieldTypeDef, FilterExpression, Query as InternalQuery, ModelDef, DocumentPosition as ModelDocumentPosition, NamedQuery, QueryData, QueryDataRow, QueryResult, SQLBlock, SQLBlockStructDef, SearchIndexResult, SearchValueMapResult, StructDef, TurtleDef, FieldUnsupportedDef, QueryRunStats } from './model';
|
|
6
6
|
import { Connection, InfoConnection, LookupConnection, ModelString, ModelURL, QueryString, QueryURL, URLReader } from './runtime_types';
|
|
7
|
+
import { Taggable, Tags } from './tags';
|
|
7
8
|
export interface Loggable {
|
|
8
9
|
debug: (message?: any, ...optionalParams: any[]) => void;
|
|
9
10
|
info: (message?: any, ...optionalParams: any[]) => void;
|
|
@@ -211,11 +212,12 @@ export declare class Model {
|
|
|
211
212
|
/**
|
|
212
213
|
* A prepared query which has all the necessary information to produce its SQL.
|
|
213
214
|
*/
|
|
214
|
-
export declare class PreparedQuery {
|
|
215
|
+
export declare class PreparedQuery implements Taggable {
|
|
215
216
|
_modelDef: ModelDef;
|
|
216
217
|
_query: InternalQuery | NamedQuery;
|
|
217
218
|
name?: string;
|
|
218
219
|
constructor(query: InternalQuery, model: ModelDef, name?: string);
|
|
220
|
+
getTags(): Tags;
|
|
219
221
|
/**
|
|
220
222
|
* Generate the SQL for this query.
|
|
221
223
|
*
|
|
@@ -378,10 +380,11 @@ export declare class DocumentCompletion {
|
|
|
378
380
|
/**
|
|
379
381
|
* A fully-prepared query containing SQL and metadata required to run the query.
|
|
380
382
|
*/
|
|
381
|
-
export declare class PreparedResult {
|
|
383
|
+
export declare class PreparedResult implements Taggable {
|
|
382
384
|
protected inner: CompiledQuery;
|
|
383
385
|
protected modelDef: ModelDef;
|
|
384
386
|
constructor(query: CompiledQuery, modelDef: ModelDef);
|
|
387
|
+
getTags(): Tags;
|
|
385
388
|
/**
|
|
386
389
|
* @return The name of the connection this query should be run against.
|
|
387
390
|
*/
|
|
@@ -515,11 +518,12 @@ export declare enum AtomicFieldType {
|
|
|
515
518
|
Unsupported = "unsupported",
|
|
516
519
|
Error = "error"
|
|
517
520
|
}
|
|
518
|
-
export declare class AtomicField extends Entity {
|
|
521
|
+
export declare class AtomicField extends Entity implements Taggable {
|
|
519
522
|
protected fieldTypeDef: FieldTypeDef;
|
|
520
523
|
protected parent: Explore;
|
|
521
524
|
constructor(fieldTypeDef: FieldTypeDef, parent: Explore, source?: AtomicField);
|
|
522
525
|
get type(): AtomicFieldType;
|
|
526
|
+
getTags(): Tags;
|
|
523
527
|
isIntrinsic(): boolean;
|
|
524
528
|
isQueryField(): this is QueryField;
|
|
525
529
|
isExploreField(): this is ExploreField;
|
|
@@ -595,9 +599,10 @@ export declare class Query extends Entity {
|
|
|
595
599
|
get source(): Query | undefined;
|
|
596
600
|
isIntrinsic(): boolean;
|
|
597
601
|
}
|
|
598
|
-
export declare class QueryField extends Query {
|
|
602
|
+
export declare class QueryField extends Query implements Taggable {
|
|
599
603
|
protected parent: Explore;
|
|
600
604
|
constructor(turtleDef: TurtleDef, parent: Explore, source?: Query);
|
|
605
|
+
getTags(): Tags;
|
|
601
606
|
isQueryField(): this is QueryField;
|
|
602
607
|
isExploreField(): this is ExploreField;
|
|
603
608
|
isAtomicField(): this is AtomicField;
|
|
@@ -611,10 +616,11 @@ export declare enum JoinRelationship {
|
|
|
611
616
|
OneToMany = "one_to_many",
|
|
612
617
|
ManyToOne = "many_to_one"
|
|
613
618
|
}
|
|
614
|
-
export declare class ExploreField extends Explore {
|
|
619
|
+
export declare class ExploreField extends Explore implements Taggable {
|
|
615
620
|
protected _parentExplore: Explore;
|
|
616
621
|
constructor(structDef: StructDef, parentExplore: Explore, source?: Explore);
|
|
617
622
|
get joinRelationship(): JoinRelationship;
|
|
623
|
+
getTags(): Tags;
|
|
618
624
|
isQueryField(): this is QueryField;
|
|
619
625
|
isExploreField(): this is ExploreField;
|
|
620
626
|
isAtomicField(): this is AtomicField;
|
package/dist/malloy.js
CHANGED
|
@@ -26,6 +26,7 @@ exports.CSVWriter = exports.JSONWriter = exports.DataWriter = exports.DataRecord
|
|
|
26
26
|
const lang_1 = require("./lang");
|
|
27
27
|
const model_1 = require("./model");
|
|
28
28
|
const luxon_1 = require("luxon");
|
|
29
|
+
const tags_1 = require("./tags");
|
|
29
30
|
class Malloy {
|
|
30
31
|
// TODO load from file built during release
|
|
31
32
|
static get version() {
|
|
@@ -444,6 +445,9 @@ class PreparedQuery {
|
|
|
444
445
|
this._modelDef = model;
|
|
445
446
|
this.name = name;
|
|
446
447
|
}
|
|
448
|
+
getTags() {
|
|
449
|
+
return new tags_1.Tags(this._query.annotation);
|
|
450
|
+
}
|
|
447
451
|
/**
|
|
448
452
|
* Generate the SQL for this query.
|
|
449
453
|
*
|
|
@@ -677,6 +681,9 @@ class PreparedResult {
|
|
|
677
681
|
this.inner = query;
|
|
678
682
|
this.modelDef = modelDef;
|
|
679
683
|
}
|
|
684
|
+
getTags() {
|
|
685
|
+
return new tags_1.Tags(this.inner.annotation);
|
|
686
|
+
}
|
|
680
687
|
/**
|
|
681
688
|
* @return The name of the connection this query should be run against.
|
|
682
689
|
*/
|
|
@@ -1062,6 +1069,9 @@ class AtomicField extends Entity {
|
|
|
1062
1069
|
return AtomicFieldType.Error;
|
|
1063
1070
|
}
|
|
1064
1071
|
}
|
|
1072
|
+
getTags() {
|
|
1073
|
+
return new tags_1.Tags(this.fieldTypeDef.annotation);
|
|
1074
|
+
}
|
|
1065
1075
|
isIntrinsic() {
|
|
1066
1076
|
return (0, model_1.FieldIsIntrinsic)(this.fieldTypeDef);
|
|
1067
1077
|
}
|
|
@@ -1261,6 +1271,9 @@ class QueryField extends Query {
|
|
|
1261
1271
|
super(turtleDef, parent, source);
|
|
1262
1272
|
this.parent = parent;
|
|
1263
1273
|
}
|
|
1274
|
+
getTags() {
|
|
1275
|
+
return new tags_1.Tags(this.turtleDef.annotation);
|
|
1276
|
+
}
|
|
1264
1277
|
isQueryField() {
|
|
1265
1278
|
return true;
|
|
1266
1279
|
}
|
|
@@ -1311,6 +1324,9 @@ class ExploreField extends Explore {
|
|
|
1311
1324
|
throw new Error('A source field must have a join relationship.');
|
|
1312
1325
|
}
|
|
1313
1326
|
}
|
|
1327
|
+
getTags() {
|
|
1328
|
+
return new tags_1.Tags(this._structDef.annotation);
|
|
1329
|
+
}
|
|
1314
1330
|
isQueryField() {
|
|
1315
1331
|
return false;
|
|
1316
1332
|
}
|
|
@@ -1764,6 +1764,7 @@ class QueryQuery extends QueryField {
|
|
|
1764
1764
|
dimCount++;
|
|
1765
1765
|
}
|
|
1766
1766
|
const location = fi.f.fieldDef.location;
|
|
1767
|
+
const annotation = fi.f.fieldDef.annotation;
|
|
1767
1768
|
// build out the result fields...
|
|
1768
1769
|
switch (fi.f.fieldDef.type) {
|
|
1769
1770
|
case 'boolean':
|
|
@@ -1774,6 +1775,7 @@ class QueryQuery extends QueryField {
|
|
|
1774
1775
|
type: fi.f.fieldDef.type,
|
|
1775
1776
|
resultMetadata,
|
|
1776
1777
|
location,
|
|
1778
|
+
annotation,
|
|
1777
1779
|
});
|
|
1778
1780
|
break;
|
|
1779
1781
|
case 'timestamp': {
|
|
@@ -1785,6 +1787,7 @@ class QueryQuery extends QueryField {
|
|
|
1785
1787
|
timeframe,
|
|
1786
1788
|
resultMetadata,
|
|
1787
1789
|
location,
|
|
1790
|
+
annotation,
|
|
1788
1791
|
});
|
|
1789
1792
|
}
|
|
1790
1793
|
else {
|
|
@@ -1793,6 +1796,7 @@ class QueryQuery extends QueryField {
|
|
|
1793
1796
|
type: 'timestamp',
|
|
1794
1797
|
resultMetadata,
|
|
1795
1798
|
location,
|
|
1799
|
+
annotation,
|
|
1796
1800
|
});
|
|
1797
1801
|
}
|
|
1798
1802
|
break;
|
|
@@ -1804,6 +1808,7 @@ class QueryQuery extends QueryField {
|
|
|
1804
1808
|
timeframe: fi.f.fieldDef.timeframe,
|
|
1805
1809
|
resultMetadata,
|
|
1806
1810
|
location,
|
|
1811
|
+
annotation,
|
|
1807
1812
|
});
|
|
1808
1813
|
break;
|
|
1809
1814
|
}
|
|
@@ -1814,6 +1819,7 @@ class QueryQuery extends QueryField {
|
|
|
1814
1819
|
type: 'number',
|
|
1815
1820
|
resultMetadata,
|
|
1816
1821
|
location,
|
|
1822
|
+
annotation,
|
|
1817
1823
|
});
|
|
1818
1824
|
break;
|
|
1819
1825
|
case 'unsupported':
|
|
@@ -2423,6 +2429,7 @@ class QueryQuery extends QueryField {
|
|
|
2423
2429
|
// console.log(stageWriter.generateSQLStages());
|
|
2424
2430
|
structDef = pipeOut.outputStruct;
|
|
2425
2431
|
}
|
|
2432
|
+
structDef.annotation = fi.turtleDef.annotation;
|
|
2426
2433
|
return {
|
|
2427
2434
|
structDef,
|
|
2428
2435
|
pipeOut,
|
|
@@ -3151,6 +3158,7 @@ class QueryStruct extends QueryNode {
|
|
|
3151
3158
|
flattenTurtleDef(turtleDef) {
|
|
3152
3159
|
let pipeline = turtleDef.pipeline;
|
|
3153
3160
|
let pipeHead = turtleDef.pipeHead;
|
|
3161
|
+
const annotation = turtleDef.annotation;
|
|
3154
3162
|
while (pipeHead) {
|
|
3155
3163
|
const field = this.getFieldByName(pipeHead.name);
|
|
3156
3164
|
if (field instanceof QueryQuery) {
|
|
@@ -3168,6 +3176,7 @@ class QueryStruct extends QueryNode {
|
|
|
3168
3176
|
type: 'turtle',
|
|
3169
3177
|
name: turtleDef.name,
|
|
3170
3178
|
pipeline,
|
|
3179
|
+
annotation,
|
|
3171
3180
|
location: turtleDef.location,
|
|
3172
3181
|
};
|
|
3173
3182
|
return flatTurtleDef;
|
|
@@ -3299,6 +3308,7 @@ class QueryModel {
|
|
|
3299
3308
|
? query.pipeHead.name
|
|
3300
3309
|
: undefined,
|
|
3301
3310
|
connectionName: ret.connectionName,
|
|
3311
|
+
annotation: query.annotation,
|
|
3302
3312
|
};
|
|
3303
3313
|
}
|
|
3304
3314
|
async searchIndex(connection, explore, searchValue, limit = 1000, searchField = undefined) {
|
|
@@ -265,15 +265,20 @@ interface JustExpression {
|
|
|
265
265
|
e: Expr;
|
|
266
266
|
}
|
|
267
267
|
declare type HasExpression = FieldDef & JustExpression;
|
|
268
|
-
/** Grants access to the expression property of a
|
|
268
|
+
/** Grants access to the expression property of a FieldDef */
|
|
269
269
|
export declare function hasExpression(f: FieldDef): f is HasExpression;
|
|
270
270
|
export declare type TimeFieldType = 'date' | 'timestamp';
|
|
271
271
|
export declare function isTimeFieldType(s: string): s is TimeFieldType;
|
|
272
272
|
export declare type AtomicFieldType = 'string' | 'number' | TimeFieldType | 'boolean' | 'unsupported' | 'json' | 'error';
|
|
273
273
|
export declare function isAtomicFieldType(s: string): s is AtomicFieldType;
|
|
274
|
-
/**
|
|
274
|
+
/**
|
|
275
|
+
* Fields which contain scalar data all inherit from this. The field
|
|
276
|
+
* value could be an expression, and this is one of the objects
|
|
277
|
+
* which might have an annotation.
|
|
278
|
+
*/
|
|
275
279
|
export interface FieldAtomicDef extends NamedObject, Expression, ResultMetadata {
|
|
276
280
|
type: AtomicFieldType;
|
|
281
|
+
annotation?: Annotation;
|
|
277
282
|
}
|
|
278
283
|
export declare function FieldIsIntrinsic(f: FieldDef): boolean;
|
|
279
284
|
/** Scalar String Field */
|
|
@@ -368,6 +373,7 @@ export interface Pipeline {
|
|
|
368
373
|
export interface Query extends Pipeline, Filtered, HasLocation {
|
|
369
374
|
type?: 'query';
|
|
370
375
|
structRef: StructRef;
|
|
376
|
+
annotation?: Annotation;
|
|
371
377
|
}
|
|
372
378
|
export declare type NamedQuery = Query & NamedObject;
|
|
373
379
|
export declare type PipeSegment = QuerySegment | IndexSegment;
|
|
@@ -412,6 +418,7 @@ export interface QuerySegment extends Filtered {
|
|
|
412
418
|
}
|
|
413
419
|
export interface TurtleDef extends NamedObject, Pipeline {
|
|
414
420
|
type: 'turtle';
|
|
421
|
+
annotation?: Annotation;
|
|
415
422
|
}
|
|
416
423
|
export declare type JoinRelationship = 'one_to_one' | 'one_to_many' | 'many_to_one' | 'many_to_many';
|
|
417
424
|
export interface JoinOn {
|
|
@@ -482,6 +489,7 @@ export interface StructDef extends NamedObject, ResultStructMetadata, Filtered {
|
|
|
482
489
|
parameters?: Record<string, Parameter>;
|
|
483
490
|
queryTimezone?: string;
|
|
484
491
|
dialect: string;
|
|
492
|
+
annotation?: Annotation;
|
|
485
493
|
}
|
|
486
494
|
export declare type ExpressionValueType = AtomicFieldType | 'null' | 'duration' | 'any' | 'regular expression';
|
|
487
495
|
export declare type FieldValueType = ExpressionValueType | 'turtle' | 'struct';
|
|
@@ -559,10 +567,17 @@ export interface ModelDef {
|
|
|
559
567
|
name: string;
|
|
560
568
|
exports: string[];
|
|
561
569
|
contents: Record<string, NamedModelObject>;
|
|
570
|
+
annotation?: Annotation;
|
|
562
571
|
}
|
|
563
572
|
/** Very common record type */
|
|
564
573
|
export declare type NamedStructDefs = Record<string, StructDef>;
|
|
565
574
|
export declare type NamedModelObjects = Record<string, NamedModelObject>;
|
|
575
|
+
/** Malloy source annotations attached to objects */
|
|
576
|
+
export interface Annotation {
|
|
577
|
+
inherits?: Annotation;
|
|
578
|
+
blockNotes?: string[];
|
|
579
|
+
notes?: string[];
|
|
580
|
+
}
|
|
566
581
|
export declare type QueryScalar = string | boolean | number | Date | Buffer | null;
|
|
567
582
|
/** One value in one column of returned data. */
|
|
568
583
|
export declare type QueryValue = QueryScalar | QueryData | QueryDataRow;
|
|
@@ -593,6 +608,8 @@ export interface CompiledQuery extends DrillSource {
|
|
|
593
608
|
malloy: string;
|
|
594
609
|
queryName?: string | undefined;
|
|
595
610
|
connectionName: string;
|
|
611
|
+
queryTimezone?: string;
|
|
612
|
+
annotation?: Annotation;
|
|
596
613
|
}
|
|
597
614
|
/** Result type for running a Malloy query. */
|
|
598
615
|
export interface QueryResult extends CompiledQuery {
|
|
@@ -204,7 +204,7 @@ function maxOfExpressionTypes(types) {
|
|
|
204
204
|
return types.reduce(maxExpressionType, 'scalar');
|
|
205
205
|
}
|
|
206
206
|
exports.maxOfExpressionTypes = maxOfExpressionTypes;
|
|
207
|
-
/** Grants access to the expression property of a
|
|
207
|
+
/** Grants access to the expression property of a FieldDef */
|
|
208
208
|
function hasExpression(f) {
|
|
209
209
|
return f.e !== undefined;
|
|
210
210
|
}
|
package/dist/tags.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Annotation } from './model';
|
|
2
|
+
declare type MalloyTagProperties = Record<string, string | boolean>;
|
|
3
|
+
interface PropertyTag {
|
|
4
|
+
properties: MalloyTagProperties;
|
|
5
|
+
}
|
|
6
|
+
export interface MalloyTags extends PropertyTag {
|
|
7
|
+
docStrings: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface Taggable {
|
|
10
|
+
getTags: () => Tags;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Collection of useful functions for handing tag data ...
|
|
14
|
+
*/
|
|
15
|
+
export declare class Tags {
|
|
16
|
+
private tags;
|
|
17
|
+
constructor(annotation: Annotation | undefined);
|
|
18
|
+
getMalloyTags(): MalloyTags;
|
|
19
|
+
getTagList(): string[];
|
|
20
|
+
}
|
|
21
|
+
export {};
|
package/dist/tags.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.Tags = void 0;
|
|
26
|
+
function isDocTag(a) {
|
|
27
|
+
return (a === null || a === void 0 ? void 0 : a.docString) !== undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Collection of useful functions for handing tag data ...
|
|
31
|
+
*/
|
|
32
|
+
class Tags {
|
|
33
|
+
constructor(annotation) {
|
|
34
|
+
this.tags = annotation;
|
|
35
|
+
}
|
|
36
|
+
getMalloyTags() {
|
|
37
|
+
const ret = { docStrings: [], properties: {} };
|
|
38
|
+
for (const tagLine of tagList(this.tags)) {
|
|
39
|
+
const tag = parseTag(tagLine, ret.properties);
|
|
40
|
+
if (isDocTag(tag)) {
|
|
41
|
+
ret.docStrings.push(tag.docString);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return ret;
|
|
45
|
+
}
|
|
46
|
+
getTagList() {
|
|
47
|
+
return tagList(this.tags);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.Tags = Tags;
|
|
51
|
+
function tagList(tagNode) {
|
|
52
|
+
if (!tagNode) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
return [
|
|
56
|
+
...(tagNode.inherits ? tagList(tagNode.inherits) : []),
|
|
57
|
+
...(tagNode.blockNotes || []),
|
|
58
|
+
...(tagNode.notes || []),
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Lines which start '#"' are doc strings
|
|
63
|
+
* Lines which start '# ' are property lines ... The property parser is
|
|
64
|
+
* pretty simple, the langauge is:
|
|
65
|
+
* Property can be
|
|
66
|
+
* name -- set the value to "true"
|
|
67
|
+
* -name -- delete a value from the property
|
|
68
|
+
* name=value -- assign value to the name
|
|
69
|
+
* Name can be any sequence of non space characters, or a string
|
|
70
|
+
* A value is any sequence of non space characters, or a string
|
|
71
|
+
* A string is " enclosing and ending in " with \" allowed inside
|
|
72
|
+
*/
|
|
73
|
+
function parseTag(src, tagProp) {
|
|
74
|
+
if (src.startsWith('#" ')) {
|
|
75
|
+
return { docString: src.slice(3) };
|
|
76
|
+
}
|
|
77
|
+
if (!src.startsWith('# ')) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
/*
|
|
81
|
+
* I went back and forth if the grammar for these annotations should be
|
|
82
|
+
* in the parser or the lexer. Eventually the fact that the lexer ate
|
|
83
|
+
* newlines meant I couldn't figure out how to do it in the parser.
|
|
84
|
+
*
|
|
85
|
+
* Seems wrong to be writing a parser though.
|
|
86
|
+
*/
|
|
87
|
+
const tokens = tokenize(src.slice(2));
|
|
88
|
+
let tn = 0;
|
|
89
|
+
const lastToken = tokens.length - 1;
|
|
90
|
+
while (tn <= lastToken) {
|
|
91
|
+
let token = tokens[tn];
|
|
92
|
+
if (token === '=') {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
if (token[0] === '"') {
|
|
96
|
+
token = token.slice(1, -1);
|
|
97
|
+
}
|
|
98
|
+
if (tn !== lastToken && tokens[tn + 1] === '=') {
|
|
99
|
+
if (tn + 2 <= lastToken) {
|
|
100
|
+
let value = tokens[tn + 2];
|
|
101
|
+
if (value !== '=') {
|
|
102
|
+
if (value[0] === '"') {
|
|
103
|
+
value = value.slice(1, -1);
|
|
104
|
+
}
|
|
105
|
+
tagProp[token] = value;
|
|
106
|
+
tn += 3;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
if (token.startsWith('-')) {
|
|
113
|
+
delete tagProp[token.slice(1)];
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
tagProp[token] = true;
|
|
117
|
+
}
|
|
118
|
+
tn += 1;
|
|
119
|
+
}
|
|
120
|
+
return { properties: tagProp };
|
|
121
|
+
}
|
|
122
|
+
function tokenize(src) {
|
|
123
|
+
const parts = [];
|
|
124
|
+
src = src.trim();
|
|
125
|
+
while (src) {
|
|
126
|
+
const skipSpace = src.match(/^\s*(.+$)/);
|
|
127
|
+
if (skipSpace === null) {
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
src = skipSpace[1];
|
|
131
|
+
if (src[0] === '=') {
|
|
132
|
+
parts.push('=');
|
|
133
|
+
src = src.slice(1);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (src[0] === '"') {
|
|
137
|
+
const matchString = src.match(/^"(\\"|[^"])*"/);
|
|
138
|
+
if (!matchString) {
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
parts.push(matchString[0]);
|
|
142
|
+
src = src.slice(matchString[0].length);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const token = src.match(/^[^\s "=]+/);
|
|
146
|
+
if (token) {
|
|
147
|
+
parts.push(token[0]);
|
|
148
|
+
src = src.slice(token[0].length);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
return parts;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=tags.js.map
|
package/package.json
CHANGED