@malloydata/malloy 0.0.391 → 0.0.392
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/api/asynchronous.js +0 -3
- package/dist/api/foundation/compile.d.ts +1 -1
- package/dist/api/foundation/config.d.ts +80 -8
- package/dist/api/foundation/config.js +151 -69
- package/dist/api/foundation/config_compile.js +27 -35
- package/dist/api/foundation/config_discover.js +5 -9
- package/dist/api/foundation/config_overlays.d.ts +6 -0
- package/dist/api/foundation/config_overlays.js +12 -0
- package/dist/api/foundation/config_resolve.d.ts +4 -1
- package/dist/api/foundation/config_resolve.js +64 -4
- package/dist/api/foundation/core.d.ts +75 -2
- package/dist/api/foundation/core.js +104 -6
- package/dist/api/foundation/index.d.ts +2 -0
- package/dist/api/foundation/readers.js +1 -1
- package/dist/api/foundation/runtime.d.ts +68 -2
- package/dist/api/foundation/runtime.js +212 -10
- package/dist/api/foundation/types.d.ts +2 -1
- package/dist/index.d.ts +3 -1
- package/dist/lang/ast/ast-utils.js +0 -1
- package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-aggregate-function.js +9 -8
- package/dist/lang/ast/expressions/expr-coalesce.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-coalesce.js +2 -3
- package/dist/lang/ast/expressions/expr-count-distinct.js +1 -1
- package/dist/lang/ast/expressions/expr-count.js +6 -4
- package/dist/lang/ast/expressions/expr-filter-expr.js +0 -1
- package/dist/lang/ast/expressions/expr-func.js +9 -4
- package/dist/lang/ast/expressions/expr-given.d.ts +18 -0
- package/dist/lang/ast/expressions/expr-given.js +69 -0
- package/dist/lang/ast/expressions/expr-granular-time.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-id-reference.js +3 -2
- package/dist/lang/ast/expressions/expr-now.js +0 -1
- package/dist/lang/ast/expressions/expr-props.d.ts +132 -132
- package/dist/lang/ast/expressions/expr-props.js +2 -2
- package/dist/lang/ast/expressions/expr-ungroup.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-ungroup.js +4 -4
- package/dist/lang/ast/expressions/for-range.d.ts +1 -1
- package/dist/lang/ast/expressions/function-ordering.d.ts +1 -1
- package/dist/lang/ast/expressions/function-ordering.js +2 -2
- package/dist/lang/ast/expressions/time-literal.d.ts +3 -3
- package/dist/lang/ast/field-space/include-utils.js +2 -2
- package/dist/lang/ast/field-space/index-field-space.js +18 -23
- package/dist/lang/ast/field-space/passthrough-space.d.ts +1 -1
- package/dist/lang/ast/field-space/query-spaces.d.ts +6 -2
- package/dist/lang/ast/field-space/query-spaces.js +29 -19
- package/dist/lang/ast/field-space/reference-field.js +1 -1
- package/dist/lang/ast/field-space/rename-space-field.d.ts +1 -1
- package/dist/lang/ast/field-space/rename-space-field.js +2 -2
- package/dist/lang/ast/field-space/struct-space-field-base.js +2 -3
- package/dist/lang/ast/index.d.ts +2 -0
- package/dist/lang/ast/index.js +2 -0
- package/dist/lang/ast/query-builders/index-builder.d.ts +1 -1
- package/dist/lang/ast/query-builders/index-builder.js +4 -3
- package/dist/lang/ast/query-builders/reduce-builder.d.ts +2 -2
- package/dist/lang/ast/query-builders/reduce-builder.js +4 -5
- package/dist/lang/ast/query-elements/query-arrow.js +3 -2
- package/dist/lang/ast/query-elements/query-base.d.ts +1 -1
- package/dist/lang/ast/query-elements/query-base.js +1 -1
- package/dist/lang/ast/query-elements/query-refine.js +3 -1
- package/dist/lang/ast/query-items/field-declaration.js +2 -2
- package/dist/lang/ast/query-properties/drill.js +6 -6
- package/dist/lang/ast/query-properties/filters.js +2 -2
- package/dist/lang/ast/query-properties/nest.js +3 -3
- package/dist/lang/ast/source-elements/composite-source.js +5 -3
- package/dist/lang/ast/source-elements/named-source.js +4 -0
- package/dist/lang/ast/source-elements/sql-source.js +2 -2
- package/dist/lang/ast/source-elements/table-source.js +3 -1
- package/dist/lang/ast/source-properties/join.js +4 -4
- package/dist/lang/ast/source-query-elements/sq-reference.js +2 -1
- package/dist/lang/ast/statements/define-given.d.ts +29 -0
- package/dist/lang/ast/statements/define-given.js +163 -0
- package/dist/lang/ast/statements/import-statement.js +72 -9
- package/dist/lang/ast/typedesc-utils.d.ts +3 -1
- package/dist/lang/ast/typedesc-utils.js +4 -47
- package/dist/lang/ast/types/expr-value.js +2 -3
- package/dist/lang/ast/types/expression-def.d.ts +2 -2
- package/dist/lang/ast/types/expression-def.js +2 -2
- package/dist/lang/ast/types/malloy-element.d.ts +5 -15
- package/dist/lang/ast/types/malloy-element.js +113 -1
- package/dist/lang/ast/types/space-field.js +7 -9
- package/dist/lang/ast/view-elements/reference-view.js +6 -5
- package/dist/lang/ast/view-elements/refine-utils.js +1 -1
- package/dist/lang/composite-source-utils.d.ts +30 -15
- package/dist/lang/composite-source-utils.js +234 -64
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +171 -169
- package/dist/lang/lib/Malloy/MalloyLexer.js +1194 -1178
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +408 -334
- package/dist/lang/lib/Malloy/MalloyParser.js +3062 -2561
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +68 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +43 -0
- package/dist/lang/malloy-to-ast.d.ts +13 -1
- package/dist/lang/malloy-to-ast.js +90 -11
- package/dist/lang/parse-log.d.ts +8 -0
- package/dist/lang/prettify/filter-type.d.ts +3 -0
- package/dist/lang/prettify/filter-type.js +38 -0
- package/dist/lang/prettify/formatter.js +6 -0
- package/dist/lang/prettify/inline-renderer.js +20 -0
- package/dist/lang/prettify/rules.d.ts +1 -1
- package/dist/lang/prettify/rules.js +1 -0
- package/dist/lang/prettify/sections.js +2 -0
- package/dist/lang/prettify/tokens.js +2 -0
- package/dist/lang/test/expr-to-str.js +2 -0
- package/dist/lang/test/parse-expects.d.ts +1 -0
- package/dist/lang/test/parse-expects.js +27 -10
- package/dist/model/constant_expression_compiler.js +1 -0
- package/dist/model/expression_compiler.d.ts +2 -1
- package/dist/model/expression_compiler.js +41 -1
- package/dist/model/given_binding.d.ts +2 -0
- package/dist/model/given_binding.js +204 -0
- package/dist/model/index.d.ts +1 -1
- package/dist/model/index.js +2 -1
- package/dist/model/malloy_types.d.ts +163 -36
- package/dist/model/malloy_types.js +97 -0
- package/dist/model/query_model_contract.d.ts +2 -1
- package/dist/model/query_model_impl.d.ts +2 -1
- package/dist/model/query_model_impl.js +7 -0
- package/dist/model/query_node.d.ts +2 -1
- package/dist/model/source_def_utils.d.ts +2 -1
- package/dist/model/source_def_utils.js +4 -0
- package/dist/model/utils.d.ts +14 -1
- package/dist/model/utils.js +41 -0
- package/dist/to_stable.js +1 -1
- package/dist/util/closest_match.d.ts +9 -0
- package/dist/util/closest_match.js +47 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
|
@@ -9,6 +9,7 @@ exports.generateFunctionCallExpression = generateFunctionCallExpression;
|
|
|
9
9
|
exports.generateFieldFragment = generateFieldFragment;
|
|
10
10
|
exports.generateOutputFieldFragment = generateOutputFieldFragment;
|
|
11
11
|
exports.generateParameterFragment = generateParameterFragment;
|
|
12
|
+
exports.generateGivenFragment = generateGivenFragment;
|
|
12
13
|
exports.generateFilterFragment = generateFilterFragment;
|
|
13
14
|
exports.generateDimFragment = generateDimFragment;
|
|
14
15
|
exports.generateUngroupedFragment = generateUngroupedFragment;
|
|
@@ -112,6 +113,8 @@ function compileExpr(resultSet, context, expr, state = new utils_1.GenerateState
|
|
|
112
113
|
return generateFieldFragment(resultSet, context, expr, state);
|
|
113
114
|
case 'parameter':
|
|
114
115
|
return generateParameterFragment(resultSet, context, expr, state);
|
|
116
|
+
case 'given':
|
|
117
|
+
return generateGivenFragment(resultSet, context, expr, state);
|
|
115
118
|
case 'filteredExpr':
|
|
116
119
|
return generateFilterFragment(resultSet, context, expr, state);
|
|
117
120
|
case 'all':
|
|
@@ -247,7 +250,7 @@ function exprToSQL(resultSet, context, exprToTranslate, state = new utils_1.Gene
|
|
|
247
250
|
return compiled.sql;
|
|
248
251
|
}
|
|
249
252
|
function generateAppliedFilter(context, filterMatchExpr, qi) {
|
|
250
|
-
var _a;
|
|
253
|
+
var _a, _b, _c;
|
|
251
254
|
let filterExpr = filterMatchExpr.kids.filterExpr;
|
|
252
255
|
while (filterExpr.node === '()') {
|
|
253
256
|
filterExpr = filterExpr.e;
|
|
@@ -263,6 +266,22 @@ function generateAppliedFilter(context, filterMatchExpr, qi) {
|
|
|
263
266
|
throw new Error(`Parameter ${name} was expected to be a filter expression`);
|
|
264
267
|
}
|
|
265
268
|
}
|
|
269
|
+
if (filterExpr.node === 'given') {
|
|
270
|
+
const id = filterExpr.id;
|
|
271
|
+
const supplied = (_c = (_b = context.prepareResultOptions) === null || _b === void 0 ? void 0 : _b.resolvedGivens) === null || _c === void 0 ? void 0 : _c.get(id);
|
|
272
|
+
if (supplied !== undefined) {
|
|
273
|
+
filterExpr = supplied;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
const decl = context.getModel().givens[id];
|
|
277
|
+
if ((decl === null || decl === void 0 ? void 0 : decl.default) !== undefined) {
|
|
278
|
+
filterExpr = decl.default;
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
throw new Error(unsatisfiedGivenMessage(filterExpr.refName));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
266
285
|
if (filterExpr.node !== 'filterLiteral') {
|
|
267
286
|
throw new Error('Can only use filter expression literals or parameters as filter expressions');
|
|
268
287
|
}
|
|
@@ -580,6 +599,27 @@ function generateParameterFragment(resultSet, context, expr, state) {
|
|
|
580
599
|
}
|
|
581
600
|
throw new Error(`Can't generate SQL, no value for ${expr.path}`);
|
|
582
601
|
}
|
|
602
|
+
function generateGivenFragment(resultSet, context, expr, state) {
|
|
603
|
+
var _a, _b;
|
|
604
|
+
const id = expr.id;
|
|
605
|
+
const supplied = (_b = (_a = context.prepareResultOptions) === null || _a === void 0 ? void 0 : _a.resolvedGivens) === null || _b === void 0 ? void 0 : _b.get(id);
|
|
606
|
+
if (supplied !== undefined) {
|
|
607
|
+
return exprToSQL(resultSet, context, supplied, state);
|
|
608
|
+
}
|
|
609
|
+
// The default may itself be a `$OTHER`-bearing expression — recursive
|
|
610
|
+
// compile handles default chains.
|
|
611
|
+
const decl = context.getModel().givens[id];
|
|
612
|
+
if ((decl === null || decl === void 0 ? void 0 : decl.default) !== undefined) {
|
|
613
|
+
return exprToSQL(resultSet, context, decl.default, state);
|
|
614
|
+
}
|
|
615
|
+
throw new Error(unsatisfiedGivenMessage(expr.refName));
|
|
616
|
+
}
|
|
617
|
+
function unsatisfiedGivenMessage(refName) {
|
|
618
|
+
return (`Given '${refName}' has no value and no default. ` +
|
|
619
|
+
`To fix: supply it via \`.run({givens: {${refName}: ...}})\` if it's in scope, ` +
|
|
620
|
+
'or add a default at its declaration, ' +
|
|
621
|
+
`or import the given by name so a value can be supplied (e.g. \`import { ${refName} } from "..."\`).`);
|
|
622
|
+
}
|
|
583
623
|
function generateFilterFragment(resultSet, context, expr, state) {
|
|
584
624
|
const allWhere = new utils_1.AndChain(state.whereSQL);
|
|
585
625
|
for (const cond of expr.kids.filterList) {
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Contributors to the Malloy project
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.resolveSuppliedGivens = resolveSuppliedGivens;
|
|
8
|
+
const luxon_1 = require("luxon");
|
|
9
|
+
const closest_match_1 = require("../util/closest_match");
|
|
10
|
+
const malloy_types_1 = require("./malloy_types");
|
|
11
|
+
function resolveSuppliedGivens(supplied, modelDef) {
|
|
12
|
+
var _a;
|
|
13
|
+
const out = new Map();
|
|
14
|
+
if (!supplied || !modelDef)
|
|
15
|
+
return out;
|
|
16
|
+
const givens = (_a = modelDef.givens) !== null && _a !== void 0 ? _a : {};
|
|
17
|
+
// Object.entries skips inherited properties — protects against
|
|
18
|
+
// prototype pollution from e.g. an Object.create(...)-derived input.
|
|
19
|
+
for (const [name, value] of Object.entries(supplied)) {
|
|
20
|
+
if (value === undefined) {
|
|
21
|
+
throw new Error(`givens.${name}: explicit undefined is not a valid value. ` +
|
|
22
|
+
'Omit the key to defer to declaration default or a lower supply ' +
|
|
23
|
+
'layer; use null for an explicit null value.');
|
|
24
|
+
}
|
|
25
|
+
const entry = modelDef.contents[name];
|
|
26
|
+
if (!entry || entry.type !== 'given') {
|
|
27
|
+
const surfaceNames = [];
|
|
28
|
+
for (const [k, v] of Object.entries(modelDef.contents)) {
|
|
29
|
+
if (v.type === 'given')
|
|
30
|
+
surfaceNames.push(k);
|
|
31
|
+
}
|
|
32
|
+
const suggestion = (0, closest_match_1.closestMatch)(name, surfaceNames);
|
|
33
|
+
const hint = suggestion ? ` (did you mean '${suggestion}'?)` : '';
|
|
34
|
+
throw new Error(`givens: unknown given '${name}'${hint}. Model surfaces [${surfaceNames.join(', ')}]`);
|
|
35
|
+
}
|
|
36
|
+
const decl = givens[entry.id];
|
|
37
|
+
if (!decl) {
|
|
38
|
+
// The namespace entry should never out-live its declaration — if it
|
|
39
|
+
// does, that's a translator bug, not a caller error.
|
|
40
|
+
throw new Error(`givens: internal error: namespace entry '${name}' has no declaration. Likely a compiler bug.`);
|
|
41
|
+
}
|
|
42
|
+
out.set(entry.id, valueToExpr(name, decl.type, value));
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
function valueToExpr(path, type, value) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
if (value === null) {
|
|
49
|
+
return { node: 'null' };
|
|
50
|
+
}
|
|
51
|
+
switch (type.type) {
|
|
52
|
+
case 'string': {
|
|
53
|
+
if (typeof value !== 'string') {
|
|
54
|
+
throw new TypeError(`givens.${path}: expected string, got ${describeJs(value)}`);
|
|
55
|
+
}
|
|
56
|
+
return { node: 'stringLiteral', literal: value };
|
|
57
|
+
}
|
|
58
|
+
case 'number': {
|
|
59
|
+
let lit;
|
|
60
|
+
if (typeof value === 'number') {
|
|
61
|
+
if (!Number.isFinite(value)) {
|
|
62
|
+
throw new TypeError(`givens.${path}: number must be finite, got ${value}`);
|
|
63
|
+
}
|
|
64
|
+
lit = String(value);
|
|
65
|
+
}
|
|
66
|
+
else if (typeof value === 'bigint') {
|
|
67
|
+
lit = value.toString();
|
|
68
|
+
}
|
|
69
|
+
else if (typeof value === 'string') {
|
|
70
|
+
if (!/^-?(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?$/.test(value)) {
|
|
71
|
+
throw new TypeError(`givens.${path}: number-as-string must be numeric, got '${value}'`);
|
|
72
|
+
}
|
|
73
|
+
lit = value;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
throw new TypeError(`givens.${path}: expected number | bigint | string, got ${describeJs(value)}`);
|
|
77
|
+
}
|
|
78
|
+
return { node: 'numberLiteral', literal: lit };
|
|
79
|
+
}
|
|
80
|
+
case 'boolean': {
|
|
81
|
+
if (typeof value !== 'boolean') {
|
|
82
|
+
throw new TypeError(`givens.${path}: expected boolean, got ${describeJs(value)}`);
|
|
83
|
+
}
|
|
84
|
+
return { node: value ? 'true' : 'false' };
|
|
85
|
+
}
|
|
86
|
+
case 'date': {
|
|
87
|
+
if (typeof value !== 'string') {
|
|
88
|
+
throw new TypeError(`givens.${path}: expected ISO date string 'YYYY-MM-DD', got ${describeJs(value)}`);
|
|
89
|
+
}
|
|
90
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
91
|
+
throw new TypeError(`givens.${path}: date must match 'YYYY-MM-DD', got '${value}'`);
|
|
92
|
+
}
|
|
93
|
+
return { node: 'dateLiteral', literal: value, typeDef: { type: 'date' } };
|
|
94
|
+
}
|
|
95
|
+
case 'timestamp': {
|
|
96
|
+
// Naive timestamp: wall-clock value with no offset. Reject JS Date
|
|
97
|
+
// (it's a UTC instant — wrong shape) and reject offset-bearing
|
|
98
|
+
// strings (those want 'timestamptz'). Parse the rest with Luxon and
|
|
99
|
+
// emit canonical "YYYY-MM-DD HH:MM:SS.sss" for the dialect.
|
|
100
|
+
if (typeof value !== 'string') {
|
|
101
|
+
throw new TypeError(`givens.${path}: expected ISO timestamp string (no offset), got ${describeJs(value)}`);
|
|
102
|
+
}
|
|
103
|
+
if (/Z$|[+-]\d{2}:?\d{2}$/.test(value)) {
|
|
104
|
+
throw new TypeError(`givens.${path}: 'timestamp' is naive — use 'timestamptz' for offset/zoned values, got '${value}'`);
|
|
105
|
+
}
|
|
106
|
+
// ISO uses T-separator; SQL form uses space. Accept both.
|
|
107
|
+
let dt = luxon_1.DateTime.fromISO(value, { zone: 'utc' });
|
|
108
|
+
if (!dt.isValid)
|
|
109
|
+
dt = luxon_1.DateTime.fromSQL(value, { zone: 'utc' });
|
|
110
|
+
if (!dt.isValid) {
|
|
111
|
+
throw new TypeError(`givens.${path}: invalid timestamp value '${value}': ${(_a = dt.invalidReason) !== null && _a !== void 0 ? _a : 'unknown'}`);
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
node: 'timestampLiteral',
|
|
115
|
+
literal: dt.toFormat('yyyy-MM-dd HH:mm:ss.SSS'),
|
|
116
|
+
typeDef: { type: 'timestamp' },
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
case 'timestamptz': {
|
|
120
|
+
let dt;
|
|
121
|
+
if (value instanceof Date) {
|
|
122
|
+
dt = luxon_1.DateTime.fromJSDate(value, { zone: 'utc' });
|
|
123
|
+
}
|
|
124
|
+
else if (typeof value === 'string') {
|
|
125
|
+
dt = luxon_1.DateTime.fromISO(value, { setZone: true });
|
|
126
|
+
if (dt.isValid)
|
|
127
|
+
dt = dt.toUTC();
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
throw new TypeError(`givens.${path}: expected JS Date or ISO timestamptz string, got ${describeJs(value)}`);
|
|
131
|
+
}
|
|
132
|
+
if (!dt.isValid) {
|
|
133
|
+
throw new TypeError(`givens.${path}: invalid timestamptz value '${value}': ${(_b = dt.invalidReason) !== null && _b !== void 0 ? _b : 'unknown'}`);
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
node: 'timestamptzLiteral',
|
|
137
|
+
literal: dt.toFormat('yyyy-MM-dd HH:mm:ss.SSS'),
|
|
138
|
+
typeDef: { type: 'timestamptz' },
|
|
139
|
+
timezone: 'UTC',
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
case 'filter expression': {
|
|
143
|
+
if (typeof value !== 'string') {
|
|
144
|
+
throw new TypeError(`givens.${path}: filter<T> givens require a JS string of Malloy filter source, got ${describeJs(value)}`);
|
|
145
|
+
}
|
|
146
|
+
return { node: 'filterLiteral', filterSrc: value };
|
|
147
|
+
}
|
|
148
|
+
case 'array': {
|
|
149
|
+
if (!Array.isArray(value)) {
|
|
150
|
+
throw new TypeError(`givens.${path}: expected array, got ${describeJs(value)}`);
|
|
151
|
+
}
|
|
152
|
+
// RepeatedRecord (array of records) carries `record_element` as its
|
|
153
|
+
// element type and the record's schema in `fields`. Each element is
|
|
154
|
+
// a record of that schema. BasicArray carries a non-record element
|
|
155
|
+
// type directly.
|
|
156
|
+
const elemType = (0, malloy_types_1.isRepeatedRecord)(type)
|
|
157
|
+
? { type: 'record', fields: type.fields }
|
|
158
|
+
: type.elementTypeDef;
|
|
159
|
+
const values = value.map((el, i) => valueToExpr(`${path}[${i}]`, elemType, el));
|
|
160
|
+
return { node: 'arrayLiteral', kids: { values }, typeDef: type };
|
|
161
|
+
}
|
|
162
|
+
case 'record': {
|
|
163
|
+
if (typeof value !== 'object' ||
|
|
164
|
+
Array.isArray(value) ||
|
|
165
|
+
value instanceof Date) {
|
|
166
|
+
throw new TypeError(`givens.${path}: expected object, got ${describeJs(value)}`);
|
|
167
|
+
}
|
|
168
|
+
const obj = value;
|
|
169
|
+
const declared = new Set(type.fields.map(f => f.name));
|
|
170
|
+
for (const k of Object.keys(obj)) {
|
|
171
|
+
if (!declared.has(k)) {
|
|
172
|
+
throw new TypeError(`givens.${path}.${k}: unexpected key (not in record type [${[...declared].join(', ')}])`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const kids = (0, malloy_types_1.mkSafeRecord)();
|
|
176
|
+
for (const field of type.fields) {
|
|
177
|
+
if (!(field.name in obj)) {
|
|
178
|
+
throw new TypeError(`givens.${path}.${field.name}: missing required key`);
|
|
179
|
+
}
|
|
180
|
+
kids[field.name] = valueToExpr(`${path}.${field.name}`, malloy_types_1.TD.atomicDef(field), obj[field.name]);
|
|
181
|
+
}
|
|
182
|
+
return { node: 'recordLiteral', kids, typeDef: type };
|
|
183
|
+
}
|
|
184
|
+
case 'json':
|
|
185
|
+
case 'sql native':
|
|
186
|
+
case 'error':
|
|
187
|
+
throw new Error(`givens.${path}: type '${type.type}' is not bindable`);
|
|
188
|
+
default: {
|
|
189
|
+
// Exhaustiveness: future GivenTypeDef additions will trip this.
|
|
190
|
+
const _x = type;
|
|
191
|
+
throw new Error(`givens.${path}: unhandled given type ${JSON.stringify(_x)}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function describeJs(value) {
|
|
196
|
+
if (value === null)
|
|
197
|
+
return 'null';
|
|
198
|
+
if (Array.isArray(value))
|
|
199
|
+
return 'array';
|
|
200
|
+
if (value instanceof Date)
|
|
201
|
+
return 'Date';
|
|
202
|
+
return typeof value;
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=given_binding.js.map
|
package/dist/model/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { QueryQuery } from './query_query';
|
|
|
4
4
|
import { QueryModelImpl } from './query_model_impl';
|
|
5
5
|
export { QueryField, QueryStruct, QueryQuery, QueryModelImpl as QueryModel };
|
|
6
6
|
export { getResultStructDefForQuery, getResultStructDefForView, } from './query_model_impl';
|
|
7
|
-
export { indent, composeSQLExpr, makeDigest, mkModelDef, pathToKey, } from './utils';
|
|
7
|
+
export { indent, composeSQLExpr, makeDigest, mkModelDef, pathToKey, typeDefToString, } from './utils';
|
|
8
8
|
export { constantExprToSQL } from './constant_expression_compiler';
|
|
9
9
|
export { getCompiledSQL } from './sql_compiled';
|
|
10
10
|
export { mkSourceID, mkBuildID, mkQuerySourceDef, mkSQLSourceDef, mkTableSourceDef, resolveSourceID, registerSource, hasSourceRegistryEntry, } from './source_def_utils';
|
package/dist/model/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
36
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.hasSourceRegistryEntry = exports.registerSource = exports.resolveSourceID = exports.mkTableSourceDef = exports.mkSQLSourceDef = exports.mkQuerySourceDef = exports.mkBuildID = exports.mkSourceID = exports.getCompiledSQL = exports.constantExprToSQL = exports.pathToKey = exports.mkModelDef = exports.makeDigest = exports.composeSQLExpr = exports.indent = exports.getResultStructDefForView = exports.getResultStructDefForQuery = exports.QueryModel = exports.QueryQuery = exports.QueryStruct = exports.QueryField = void 0;
|
|
39
|
+
exports.hasSourceRegistryEntry = exports.registerSource = exports.resolveSourceID = exports.mkTableSourceDef = exports.mkSQLSourceDef = exports.mkQuerySourceDef = exports.mkBuildID = exports.mkSourceID = exports.getCompiledSQL = exports.constantExprToSQL = exports.typeDefToString = exports.pathToKey = exports.mkModelDef = exports.makeDigest = exports.composeSQLExpr = exports.indent = exports.getResultStructDefForView = exports.getResultStructDefForQuery = exports.QueryModel = exports.QueryQuery = exports.QueryStruct = exports.QueryField = void 0;
|
|
40
40
|
__exportStar(require("./malloy_types"), exports);
|
|
41
41
|
const query_node_1 = require("./query_node");
|
|
42
42
|
Object.defineProperty(exports, "QueryField", { enumerable: true, get: function () { return query_node_1.QueryField; } });
|
|
@@ -61,6 +61,7 @@ Object.defineProperty(exports, "composeSQLExpr", { enumerable: true, get: functi
|
|
|
61
61
|
Object.defineProperty(exports, "makeDigest", { enumerable: true, get: function () { return utils_1.makeDigest; } });
|
|
62
62
|
Object.defineProperty(exports, "mkModelDef", { enumerable: true, get: function () { return utils_1.mkModelDef; } });
|
|
63
63
|
Object.defineProperty(exports, "pathToKey", { enumerable: true, get: function () { return utils_1.pathToKey; } });
|
|
64
|
+
Object.defineProperty(exports, "typeDefToString", { enumerable: true, get: function () { return utils_1.typeDefToString; } });
|
|
64
65
|
var constant_expression_compiler_1 = require("./constant_expression_compiler");
|
|
65
66
|
Object.defineProperty(exports, "constantExprToSQL", { enumerable: true, get: function () { return constant_expression_compiler_1.constantExprToSQL; } });
|
|
66
67
|
var sql_compiled_1 = require("./sql_compiled");
|