@malloydata/malloy 0.0.294 → 0.0.296
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/dialect/trino/dialect_functions.js +142 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/dist/lang/ast/expressions/expr-granular-time.d.ts +2 -0
- package/dist/lang/ast/expressions/expr-granular-time.js +13 -0
- package/dist/lang/ast/expressions/expr-id-reference.d.ts +2 -0
- package/dist/lang/ast/expressions/expr-id-reference.js +7 -0
- package/dist/lang/ast/field-space/reference-field.js +11 -6
- package/dist/lang/ast/query-items/field-declaration.js +1 -0
- package/dist/lang/ast/query-properties/drill.d.ts +3 -2
- package/dist/lang/ast/query-properties/drill.js +52 -7
- package/dist/lang/ast/query-properties/filters.js +16 -16
- package/dist/lang/ast/types/expression-def.d.ts +2 -0
- package/dist/lang/ast/types/expression-def.js +3 -0
- package/dist/lang/malloy-to-stable-query.js +4 -2
- package/dist/lang/parse-log.d.ts +1 -6
- package/dist/lang/parse-log.js +0 -8
- package/dist/model/composite_source_utils.d.ts +0 -1
- package/dist/model/composite_source_utils.js +93 -61
- package/dist/model/malloy_query.d.ts +5 -2
- package/dist/model/malloy_query.js +26 -22
- package/dist/model/malloy_types.d.ts +8 -6
- package/dist/to_stable.d.ts +13 -1
- package/dist/to_stable.js +188 -41
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
package/dist/to_stable.js
CHANGED
|
@@ -5,12 +5,48 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
8
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
42
|
exports.sourceDefToSourceInfo = sourceDefToSourceInfo;
|
|
10
43
|
exports.modelDefToModelInfo = modelDefToModelInfo;
|
|
11
44
|
exports.convertFieldInfos = convertFieldInfos;
|
|
12
45
|
exports.writeLiteralToTag = writeLiteralToTag;
|
|
13
46
|
exports.getResultStructMetadataAnnotation = getResultStructMetadataAnnotation;
|
|
47
|
+
exports.writeMalloyObjectToTag = writeMalloyObjectToTag;
|
|
48
|
+
exports.extractMalloyObjectFromTag = extractMalloyObjectFromTag;
|
|
49
|
+
const Malloy = __importStar(require("@malloydata/malloy-interfaces"));
|
|
14
50
|
const model_1 = require("./model");
|
|
15
51
|
const malloy_query_1 = require("./model/malloy_query");
|
|
16
52
|
const annotation_1 = require("./annotation");
|
|
@@ -220,25 +256,23 @@ function getResultMetadataAnnotation(field, resultMetadata) {
|
|
|
220
256
|
tag.set(['drillable']);
|
|
221
257
|
hasAny = true;
|
|
222
258
|
}
|
|
223
|
-
if ((0, model_1.isAtomic)(field) || (0, model_1.isTurtle)(field)) {
|
|
224
|
-
if (field.drillView !== undefined) {
|
|
225
|
-
tag.set(['drill_view'], field.drillView);
|
|
226
|
-
hasAny = true;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
259
|
if (resultMetadata.filterList) {
|
|
230
260
|
addDrillFiltersTag(tag, resultMetadata.filterList);
|
|
231
261
|
hasAny = true;
|
|
232
262
|
}
|
|
263
|
+
if (resultMetadata.drillExpression) {
|
|
264
|
+
writeExpressionToTag(tag, ['drill_expression'], resultMetadata.drillExpression);
|
|
265
|
+
hasAny = true;
|
|
266
|
+
}
|
|
233
267
|
if (resultMetadata.fieldKind === 'dimension') {
|
|
234
268
|
const dot = '.';
|
|
235
269
|
// If field is joined-in from another table i.e. of type `tableName.columnName`,
|
|
236
270
|
// return sourceField, else return name because this could be a renamed field.
|
|
237
|
-
const
|
|
271
|
+
const drillExpressionCode = (resultMetadata === null || resultMetadata === void 0 ? void 0 : resultMetadata.sourceExpression) ||
|
|
238
272
|
((resultMetadata === null || resultMetadata === void 0 ? void 0 : resultMetadata.sourceField.includes(dot))
|
|
239
273
|
? resultMetadata === null || resultMetadata === void 0 ? void 0 : resultMetadata.sourceField
|
|
240
274
|
: identifierCode(field.name));
|
|
241
|
-
tag.set(['drill_expression'],
|
|
275
|
+
tag.set(['drill_expression', 'code'], drillExpressionCode);
|
|
242
276
|
hasAny = true;
|
|
243
277
|
}
|
|
244
278
|
return hasAny
|
|
@@ -248,20 +282,16 @@ function getResultMetadataAnnotation(field, resultMetadata) {
|
|
|
248
282
|
: undefined;
|
|
249
283
|
}
|
|
250
284
|
function addDrillFiltersTag(tag, drillFilters) {
|
|
251
|
-
var _a;
|
|
252
285
|
for (let i = 0; i < drillFilters.length; i++) {
|
|
253
286
|
const filter = drillFilters[i];
|
|
254
287
|
if (filter.expressionType !== 'scalar' || filter.isSourceFilter)
|
|
255
288
|
continue;
|
|
256
289
|
tag.set(['drill_filters', i, 'code'], filter.code);
|
|
257
|
-
if (filter.
|
|
258
|
-
tag.set(['drill_filters', i, '
|
|
290
|
+
if (filter.filterView) {
|
|
291
|
+
tag.set(['drill_filters', i, 'filter_view'], filter.filterView);
|
|
259
292
|
}
|
|
260
|
-
if (filter.
|
|
261
|
-
tag
|
|
262
|
-
...((_a = filter.stableFilter.field_reference.path) !== null && _a !== void 0 ? _a : []),
|
|
263
|
-
filter.stableFilter.field_reference.name,
|
|
264
|
-
]);
|
|
293
|
+
if (filter.filterView === undefined && filter.stableFilter !== undefined) {
|
|
294
|
+
writeExpressionToTag(tag, ['drill_filters', i, 'expression'], filter.stableFilter.expression);
|
|
265
295
|
if (filter.stableFilter.kind === 'filter_string') {
|
|
266
296
|
tag.set(['drill_filters', i, 'kind'], 'filter_expression');
|
|
267
297
|
tag.set(['drill_filters', i, 'filter_expression'], filter.stableFilter.filter);
|
|
@@ -273,32 +303,11 @@ function addDrillFiltersTag(tag, drillFilters) {
|
|
|
273
303
|
}
|
|
274
304
|
}
|
|
275
305
|
}
|
|
306
|
+
function writeExpressionToTag(tag, path, expression) {
|
|
307
|
+
writeMalloyObjectToTag(tag, path, expression, 'Expression');
|
|
308
|
+
}
|
|
276
309
|
function writeLiteralToTag(tag, path, literal) {
|
|
277
|
-
tag
|
|
278
|
-
switch (literal.kind) {
|
|
279
|
-
case 'string_literal':
|
|
280
|
-
tag.set([...path, 'string_value'], literal.string_value);
|
|
281
|
-
break;
|
|
282
|
-
case 'number_literal':
|
|
283
|
-
tag.set([...path, 'number_value'], literal.number_value);
|
|
284
|
-
break;
|
|
285
|
-
case 'boolean_literal':
|
|
286
|
-
tag.set([...path, 'boolean_value'], literal.boolean_value.toString());
|
|
287
|
-
break;
|
|
288
|
-
case 'date_literal':
|
|
289
|
-
tag.set([...path, 'date_value'], literal.date_value);
|
|
290
|
-
tag.set([...path, 'timezone'], literal.timezone);
|
|
291
|
-
tag.set([...path, 'granularity'], literal.granularity);
|
|
292
|
-
break;
|
|
293
|
-
case 'timestamp_literal':
|
|
294
|
-
tag.set([...path, 'timestamp_value'], literal.timestamp_value);
|
|
295
|
-
tag.set([...path, 'timezone'], literal.timezone);
|
|
296
|
-
tag.set([...path, 'granularity'], literal.granularity);
|
|
297
|
-
break;
|
|
298
|
-
case 'filter_expression_literal':
|
|
299
|
-
tag.set([...path, 'filter_expression_value'], literal.filter_expression_value);
|
|
300
|
-
break;
|
|
301
|
-
}
|
|
310
|
+
writeMalloyObjectToTag(tag, path, literal, 'LiteralValue');
|
|
302
311
|
}
|
|
303
312
|
function escapeIdentifier(str) {
|
|
304
313
|
return str.replace(/\\/g, '\\\\').replace(/`/g, '\\`');
|
|
@@ -469,4 +478,142 @@ function convertTimestampTimeframe(timeframe) {
|
|
|
469
478
|
function convertJoinType(type) {
|
|
470
479
|
return type;
|
|
471
480
|
}
|
|
481
|
+
/**
|
|
482
|
+
* Writes a Malloy interface object to a tag at a given path.
|
|
483
|
+
*
|
|
484
|
+
* E.g. `writeMalloyObjectToTag(tag, ['expr'], 'Expression', {kind: 'field_reference', name: 'carrier'})`
|
|
485
|
+
*
|
|
486
|
+
* produces the tag `#(malloy) expr { kind = field_reference name = carrier }`
|
|
487
|
+
*/
|
|
488
|
+
function writeMalloyObjectToTag(tag, path, obj, type) {
|
|
489
|
+
if (type === 'string') {
|
|
490
|
+
tag.set(path, obj);
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
else if (type === 'number') {
|
|
494
|
+
tag.set(path, obj);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
else if (type === 'boolean') {
|
|
498
|
+
tag.set(path, obj.toString());
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
const typelookup = Malloy.MALLOY_INTERFACE_TYPES[type];
|
|
502
|
+
if (typelookup === undefined) {
|
|
503
|
+
throw new Error(`Unknown Malloy interface type ${type}`);
|
|
504
|
+
}
|
|
505
|
+
if (typelookup.type === 'enum') {
|
|
506
|
+
if (typeof obj === 'string') {
|
|
507
|
+
tag.set(path, obj);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
throw new Error(`Expected string for enum ${type}`);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
else if (typelookup.type === 'struct') {
|
|
514
|
+
for (const key in typelookup.fields) {
|
|
515
|
+
const valueType = typelookup.fields[key];
|
|
516
|
+
const value = obj[key];
|
|
517
|
+
if (value === undefined) {
|
|
518
|
+
if (!valueType.optional) {
|
|
519
|
+
throw new Error(`Mising value for non-optional field ${key} in type ${type}`);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
else if (valueType.array) {
|
|
523
|
+
if (Array.isArray(value)) {
|
|
524
|
+
for (let i = 0; i < value.length; i++) {
|
|
525
|
+
writeMalloyObjectToTag(tag, [...path, key, i], value[i], valueType.type);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
throw new Error(`Expected array for field ${key} of type ${type} but got ${typeof obj}`);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
writeMalloyObjectToTag(tag, [...path, key], value, valueType.type);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
// enum
|
|
539
|
+
const kind = obj.kind;
|
|
540
|
+
tag.set([...path, 'kind'], kind);
|
|
541
|
+
const unionType = typelookup.options[kind];
|
|
542
|
+
if (unionType === undefined) {
|
|
543
|
+
throw new Error(`Unknown Malloy interface union kind ${kind} for type ${type}`);
|
|
544
|
+
}
|
|
545
|
+
writeMalloyObjectToTag(tag, path, obj, unionType);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Extracts a Malloy interface object from a tag at a given path; the inverse of `writeMalloyObjectToTag`.
|
|
550
|
+
*/
|
|
551
|
+
function extractMalloyObjectFromTag(tag, type) {
|
|
552
|
+
if (type === 'string') {
|
|
553
|
+
return tag.text();
|
|
554
|
+
}
|
|
555
|
+
else if (type === 'number') {
|
|
556
|
+
return tag.numeric();
|
|
557
|
+
}
|
|
558
|
+
else if (type === 'boolean') {
|
|
559
|
+
return tag.text() === 'true';
|
|
560
|
+
}
|
|
561
|
+
const typeDef = Malloy.MALLOY_INTERFACE_TYPES[type];
|
|
562
|
+
if (typeDef === undefined) {
|
|
563
|
+
throw new Error(`Unknown Malloy interface type ${type}`);
|
|
564
|
+
}
|
|
565
|
+
if (typeDef.type === 'enum') {
|
|
566
|
+
const value = tag.text();
|
|
567
|
+
if (value === undefined) {
|
|
568
|
+
throw new Error(`Missing value for enum ${type}`);
|
|
569
|
+
}
|
|
570
|
+
if (value in typeDef.values) {
|
|
571
|
+
return value;
|
|
572
|
+
}
|
|
573
|
+
throw new Error(`Unknown value ${value} for enum ${type}`);
|
|
574
|
+
}
|
|
575
|
+
else if (typeDef.type === 'struct') {
|
|
576
|
+
const result = {};
|
|
577
|
+
for (const [key, type] of Object.entries(typeDef.fields)) {
|
|
578
|
+
const valueTag = tag.tag(key);
|
|
579
|
+
if (valueTag === undefined) {
|
|
580
|
+
if (type.optional)
|
|
581
|
+
continue;
|
|
582
|
+
else {
|
|
583
|
+
throw new Error(`Missing value for key ${key} of type ${type}`);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (type.array) {
|
|
587
|
+
const arr = [];
|
|
588
|
+
const values = valueTag.array();
|
|
589
|
+
if (values === undefined) {
|
|
590
|
+
throw new Error(`Missing array value for key ${key} of type ${type}`);
|
|
591
|
+
}
|
|
592
|
+
for (const value of values) {
|
|
593
|
+
arr.push(extractMalloyObjectFromTag(value, type.type));
|
|
594
|
+
}
|
|
595
|
+
result[key] = arr;
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
const value = extractMalloyObjectFromTag(valueTag, type.type);
|
|
599
|
+
if (value !== undefined && value !== null) {
|
|
600
|
+
result[key] = value;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
return result;
|
|
605
|
+
} /* (typeDef.type === 'union') */
|
|
606
|
+
else {
|
|
607
|
+
const kind = tag.text('kind');
|
|
608
|
+
if (kind === undefined) {
|
|
609
|
+
throw new Error(`Missing kind for union ${type}`);
|
|
610
|
+
}
|
|
611
|
+
const unionType = typeDef.options[kind];
|
|
612
|
+
if (unionType === undefined) {
|
|
613
|
+
throw new Error(`Unknown kind ${kind} for union ${type}`);
|
|
614
|
+
}
|
|
615
|
+
const value = extractMalloyObjectFromTag(tag, unionType);
|
|
616
|
+
return { kind, ...value };
|
|
617
|
+
}
|
|
618
|
+
}
|
|
472
619
|
//# sourceMappingURL=to_stable.js.map
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const MALLOY_VERSION = "0.0.
|
|
1
|
+
export declare const MALLOY_VERSION = "0.0.296";
|
package/dist/version.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MALLOY_VERSION = void 0;
|
|
4
4
|
// generated with 'generate-version-file' script; do not edit manually
|
|
5
|
-
exports.MALLOY_VERSION = '0.0.
|
|
5
|
+
exports.MALLOY_VERSION = '0.0.296';
|
|
6
6
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/malloy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.296",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"generate-version-file": "VERSION=$(npm pkg get version --workspaces=false | tr -d \\\")\necho \"// generated with 'generate-version-file' script; do not edit manually\\nexport const MALLOY_VERSION = '$VERSION';\" > src/version.ts"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@malloydata/malloy-filter": "0.0.
|
|
45
|
-
"@malloydata/malloy-interfaces": "0.0.
|
|
46
|
-
"@malloydata/malloy-tag": "0.0.
|
|
44
|
+
"@malloydata/malloy-filter": "0.0.296",
|
|
45
|
+
"@malloydata/malloy-interfaces": "0.0.296",
|
|
46
|
+
"@malloydata/malloy-tag": "0.0.296",
|
|
47
47
|
"antlr4ts": "^0.5.0-alpha.4",
|
|
48
48
|
"assert": "^2.0.0",
|
|
49
49
|
"jaro-winkler": "^0.2.8",
|