@malloydata/malloy 0.0.157 → 0.0.158-dev240805161224
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lang/ast/expressions/constant-expression.d.ts +28 -0
- package/dist/lang/ast/expressions/{constant-sub-expression.js → constant-expression.js} +6 -5
- package/dist/lang/ast/expressions/expr-func.js +29 -11
- package/dist/lang/ast/expressions/expr-id-reference.d.ts +0 -1
- package/dist/lang/ast/expressions/expr-id-reference.js +0 -24
- package/dist/lang/ast/field-space/dynamic-space.d.ts +4 -1
- package/dist/lang/ast/field-space/dynamic-space.js +22 -11
- package/dist/lang/ast/field-space/index-field-space.js +3 -0
- package/dist/lang/ast/field-space/join-space-field.d.ts +3 -1
- package/dist/lang/ast/field-space/join-space-field.js +3 -2
- package/dist/lang/ast/field-space/parameter-space.d.ts +18 -0
- package/dist/lang/ast/field-space/parameter-space.js +67 -0
- package/dist/lang/ast/field-space/query-spaces.js +3 -0
- package/dist/lang/ast/field-space/reference-field.js +13 -4
- package/dist/lang/ast/field-space/refined-space.d.ts +2 -1
- package/dist/lang/ast/field-space/refined-space.js +12 -1
- package/dist/lang/ast/field-space/static-space.js +3 -5
- package/dist/lang/ast/index.d.ts +1 -0
- package/dist/lang/ast/index.js +1 -0
- package/dist/lang/ast/parameters/argument.d.ts +14 -0
- package/dist/lang/ast/parameters/argument.js +20 -0
- package/dist/lang/ast/parameters/has-parameter.d.ts +3 -5
- package/dist/lang/ast/parameters/has-parameter.js +24 -13
- package/dist/lang/ast/query-elements/query-arrow.js +7 -7
- package/dist/lang/ast/query-elements/query-head-struct.d.ts +6 -4
- package/dist/lang/ast/query-elements/query-head-struct.js +6 -5
- package/dist/lang/ast/query-elements/query-raw.js +7 -7
- package/dist/lang/ast/query-elements/query-reference.js +2 -2
- package/dist/lang/ast/query-items/field-references.d.ts +4 -0
- package/dist/lang/ast/query-items/field-references.js +12 -1
- package/dist/lang/ast/source-elements/named-source.d.ts +15 -12
- package/dist/lang/ast/source-elements/named-source.js +91 -60
- package/dist/lang/ast/source-elements/query-source.d.ts +4 -1
- package/dist/lang/ast/source-elements/query-source.js +9 -3
- package/dist/lang/ast/source-elements/refined-source.d.ts +3 -2
- package/dist/lang/ast/source-elements/refined-source.js +12 -7
- package/dist/lang/ast/source-elements/source.d.ts +6 -4
- package/dist/lang/ast/source-elements/source.js +19 -16
- package/dist/lang/ast/source-elements/sql-source.d.ts +2 -2
- package/dist/lang/ast/source-elements/sql-source.js +4 -3
- package/dist/lang/ast/source-properties/joins.d.ts +5 -4
- package/dist/lang/ast/source-properties/joins.js +7 -7
- package/dist/lang/ast/source-query-elements/sq-reference.d.ts +3 -1
- package/dist/lang/ast/source-query-elements/sq-reference.js +9 -2
- package/dist/lang/ast/statements/define-source.d.ts +4 -2
- package/dist/lang/ast/statements/define-source.js +28 -14
- package/dist/lang/ast/struct-utils.js +3 -2
- package/dist/lang/ast/types/expression-def.js +2 -0
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +169 -101
- package/dist/lang/lib/Malloy/MalloyParser.js +2105 -1600
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +64 -9
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +40 -5
- package/dist/lang/malloy-to-ast.d.ts +5 -1
- package/dist/lang/malloy-to-ast.js +51 -10
- package/dist/lang/test/expressions.spec.js +21 -1
- package/dist/lang/test/field-symbols.spec.js +0 -2
- package/dist/lang/test/locations.spec.js +3 -0
- package/dist/lang/test/parameters.spec.d.ts +1 -0
- package/dist/lang/test/parameters.spec.js +578 -0
- package/dist/model/malloy_query.d.ts +8 -5
- package/dist/model/malloy_query.js +68 -37
- package/dist/model/malloy_types.d.ts +12 -14
- package/dist/model/malloy_types.js +22 -10
- package/package.json +1 -1
- package/dist/lang/ast/expressions/constant-sub-expression.d.ts +0 -16
- package/dist/lang/ast/parameters/constant-parameter.d.ts +0 -8
- package/dist/lang/ast/parameters/constant-parameter.js +0 -54
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AtomicFieldType, StructDef } from '../../../model/malloy_types';
|
|
2
|
+
import { ExprValue } from '../types/expr-value';
|
|
3
|
+
import { ExpressionDef } from '../types/expression-def';
|
|
4
|
+
import { FieldSpace, QueryFieldSpace } from '../types/field-space';
|
|
5
|
+
import { LookupResult } from '../types/lookup-result';
|
|
6
|
+
import { SpaceEntry } from '../types/space-entry';
|
|
7
|
+
export declare class ConstantFieldSpace implements FieldSpace {
|
|
8
|
+
readonly type = "fieldSpace";
|
|
9
|
+
structDef(): StructDef;
|
|
10
|
+
emptyStructDef(): StructDef;
|
|
11
|
+
lookup(_name: unknown): LookupResult;
|
|
12
|
+
entries(): [string, SpaceEntry][];
|
|
13
|
+
entry(): undefined;
|
|
14
|
+
dialectObj(): undefined;
|
|
15
|
+
isQueryFieldSpace(): this is QueryFieldSpace;
|
|
16
|
+
}
|
|
17
|
+
export declare class ConstantExpression extends ExpressionDef {
|
|
18
|
+
readonly expr: ExpressionDef;
|
|
19
|
+
elementType: string;
|
|
20
|
+
private cfs?;
|
|
21
|
+
constructor(expr: ExpressionDef);
|
|
22
|
+
getExpression(_fs: FieldSpace): ExprValue;
|
|
23
|
+
private get constantFs();
|
|
24
|
+
constantValue(): ExprValue;
|
|
25
|
+
constantCondition(type: AtomicFieldType): ExprValue;
|
|
26
|
+
apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
|
|
27
|
+
requestExpression(fs: FieldSpace): ExprValue | undefined;
|
|
28
|
+
}
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.
|
|
25
|
+
exports.ConstantExpression = exports.ConstantFieldSpace = void 0;
|
|
26
26
|
const comparison_1 = require("../types/comparison");
|
|
27
27
|
const expression_def_1 = require("../types/expression-def");
|
|
28
28
|
const expr_compare_1 = require("./expr-compare");
|
|
@@ -39,7 +39,7 @@ class ConstantFieldSpace {
|
|
|
39
39
|
}
|
|
40
40
|
lookup(_name) {
|
|
41
41
|
return {
|
|
42
|
-
error: 'Only constants allowed in parameter
|
|
42
|
+
error: 'Only constants allowed in parameter default values',
|
|
43
43
|
found: undefined,
|
|
44
44
|
};
|
|
45
45
|
}
|
|
@@ -56,6 +56,7 @@ class ConstantFieldSpace {
|
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
exports.ConstantFieldSpace = ConstantFieldSpace;
|
|
59
60
|
class DollarReference extends expression_def_1.ExpressionDef {
|
|
60
61
|
constructor(refType) {
|
|
61
62
|
super();
|
|
@@ -71,7 +72,7 @@ class DollarReference extends expression_def_1.ExpressionDef {
|
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
|
-
class
|
|
75
|
+
class ConstantExpression extends expression_def_1.ExpressionDef {
|
|
75
76
|
constructor(expr) {
|
|
76
77
|
super({ expr: expr });
|
|
77
78
|
this.expr = expr;
|
|
@@ -101,5 +102,5 @@ class ConstantSubExpression extends expression_def_1.ExpressionDef {
|
|
|
101
102
|
return this.expr.requestExpression(fs);
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
|
-
exports.
|
|
105
|
-
//# sourceMappingURL=constant-
|
|
105
|
+
exports.ConstantExpression = ConstantExpression;
|
|
106
|
+
//# sourceMappingURL=constant-expression.js.map
|
|
@@ -27,6 +27,7 @@ const malloy_types_1 = require("../../../model/malloy_types");
|
|
|
27
27
|
const ast_utils_1 = require("../ast-utils");
|
|
28
28
|
const struct_space_field_base_1 = require("../field-space/struct-space-field-base");
|
|
29
29
|
const expression_def_1 = require("../types/expression-def");
|
|
30
|
+
const field_space_1 = require("../types/field-space");
|
|
30
31
|
const utils_1 = require("./utils");
|
|
31
32
|
class ExprFunc extends expression_def_1.ExpressionDef {
|
|
32
33
|
constructor(name, args, isRaw, rawType, source) {
|
|
@@ -245,7 +246,9 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
245
246
|
'sql_boolean',
|
|
246
247
|
].includes(func.name)) {
|
|
247
248
|
if (!this.inExperiment('sql_functions', true)) {
|
|
248
|
-
|
|
249
|
+
const message = `Cannot use sql_function \`${func.name}\`; use \`sql_functions\` experiment to enable this behavior`;
|
|
250
|
+
this.log(message);
|
|
251
|
+
return (0, ast_utils_1.errorFor)('sql_function used without enabling');
|
|
249
252
|
}
|
|
250
253
|
const str = argExprs[0].value;
|
|
251
254
|
if (str.length !== 1 ||
|
|
@@ -269,16 +272,31 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
269
272
|
this.log(unsupportedInterpolationMsg);
|
|
270
273
|
return (0, ast_utils_1.errorFor)(`${unsupportedInterpolationMsg}. See LookML \${...} documentation at https://cloud.google.com/looker/docs/reference/param-field-sql#sql_for_dimensions`);
|
|
271
274
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
275
|
+
const expr = [];
|
|
276
|
+
for (const part of parts) {
|
|
277
|
+
if (part.type === 'string') {
|
|
278
|
+
expr.push(part.value);
|
|
279
|
+
}
|
|
280
|
+
else if (part.name === 'TABLE') {
|
|
281
|
+
expr.push({ type: 'source-reference' });
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
const name = new field_space_1.FieldName(part.name);
|
|
285
|
+
this.has({ name });
|
|
286
|
+
const result = fs.lookup([name]);
|
|
287
|
+
if (result.found === undefined) {
|
|
288
|
+
this.log(`Invalid interpolation: ${result.error}`);
|
|
289
|
+
return (0, ast_utils_1.errorFor)('invalid interpolated field');
|
|
290
|
+
}
|
|
291
|
+
if (result.found.refType === 'parameter') {
|
|
292
|
+
expr.push({ type: 'parameter', path: [part.name] });
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
expr.push({ type: 'field', path: [part.name] });
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
funcCall = [{ type: 'sql-string', e: expr }];
|
|
282
300
|
}
|
|
283
301
|
}
|
|
284
302
|
if (type.dataType === 'any') {
|
|
@@ -25,7 +25,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.ExprIdReference = void 0;
|
|
26
26
|
const malloy_types_1 = require("../../../model/malloy_types");
|
|
27
27
|
const ast_utils_1 = require("../ast-utils");
|
|
28
|
-
const space_param_1 = require("../types/space-param");
|
|
29
28
|
const expression_def_1 = require("../types/expression-def");
|
|
30
29
|
class ExprIdReference extends expression_def_1.ExpressionDef {
|
|
31
30
|
constructor(fieldReference) {
|
|
@@ -58,29 +57,6 @@ class ExprIdReference extends expression_def_1.ExpressionDef {
|
|
|
58
57
|
this.log(def.error);
|
|
59
58
|
return (0, ast_utils_1.errorFor)(def.error);
|
|
60
59
|
}
|
|
61
|
-
apply(fs, op, expr) {
|
|
62
|
-
const entry = this.fieldReference.getField(fs).found;
|
|
63
|
-
if (entry instanceof space_param_1.SpaceParam) {
|
|
64
|
-
const cParam = entry.parameter();
|
|
65
|
-
if ((0, malloy_types_1.isConditionParameter)(cParam)) {
|
|
66
|
-
const lval = expr.getExpression(fs);
|
|
67
|
-
return {
|
|
68
|
-
dataType: 'boolean',
|
|
69
|
-
expressionType: lval.expressionType,
|
|
70
|
-
// TODO not sure about the input-ness of parameters
|
|
71
|
-
evalSpace: (0, malloy_types_1.mergeEvalSpaces)(lval.evalSpace, 'input'),
|
|
72
|
-
value: [
|
|
73
|
-
{
|
|
74
|
-
type: 'apply',
|
|
75
|
-
value: lval.value,
|
|
76
|
-
to: [{ type: 'parameter', path: this.fieldReference.path }],
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return super.apply(fs, op, expr);
|
|
83
|
-
}
|
|
84
60
|
}
|
|
85
61
|
exports.ExprIdReference = ExprIdReference;
|
|
86
62
|
//# sourceMappingURL=expr-id-reference.js.map
|
|
@@ -4,16 +4,19 @@ import { HasParameter } from '../parameters/has-parameter';
|
|
|
4
4
|
import { MalloyElement } from '../types/malloy-element';
|
|
5
5
|
import { SourceSpec, SpaceSeed } from '../space-seed';
|
|
6
6
|
import { StaticSpace } from './static-space';
|
|
7
|
+
import { ParameterSpace } from './parameter-space';
|
|
7
8
|
export declare abstract class DynamicSpace extends StaticSpace {
|
|
8
9
|
protected final: model.StructDef | undefined;
|
|
9
10
|
protected source: SpaceSeed;
|
|
10
11
|
completions: (() => void)[];
|
|
11
12
|
private complete;
|
|
13
|
+
private parameters;
|
|
12
14
|
protected newTimezone?: string;
|
|
13
15
|
constructor(extending: SourceSpec);
|
|
14
16
|
isComplete(): void;
|
|
15
17
|
protected setEntry(name: string, value: SpaceEntry): void;
|
|
16
|
-
addParameters(
|
|
18
|
+
addParameters(parameters: HasParameter[]): DynamicSpace;
|
|
19
|
+
parameterSpace(): ParameterSpace;
|
|
17
20
|
newEntry(name: string, logTo: MalloyElement, entry: SpaceEntry): void;
|
|
18
21
|
renameEntry(oldName: string, newName: string, entry: SpaceEntry): void;
|
|
19
22
|
addFieldDef(fd: model.FieldDef): void;
|
|
@@ -32,12 +32,14 @@ const space_param_1 = require("../types/space-param");
|
|
|
32
32
|
const space_seed_1 = require("../space-seed");
|
|
33
33
|
const static_space_1 = require("./static-space");
|
|
34
34
|
const struct_space_field_base_1 = require("./struct-space-field-base");
|
|
35
|
+
const parameter_space_1 = require("./parameter-space");
|
|
35
36
|
class DynamicSpace extends static_space_1.StaticSpace {
|
|
36
37
|
constructor(extending) {
|
|
37
38
|
const source = new space_seed_1.SpaceSeed(extending);
|
|
38
39
|
super(structuredClone(source.structDef));
|
|
39
40
|
this.completions = [];
|
|
40
41
|
this.complete = false;
|
|
42
|
+
this.parameters = [];
|
|
41
43
|
this.final = undefined;
|
|
42
44
|
this.source = source;
|
|
43
45
|
}
|
|
@@ -50,12 +52,18 @@ class DynamicSpace extends static_space_1.StaticSpace {
|
|
|
50
52
|
}
|
|
51
53
|
super.setEntry(name, value);
|
|
52
54
|
}
|
|
53
|
-
addParameters(
|
|
54
|
-
for (const
|
|
55
|
-
this.
|
|
55
|
+
addParameters(parameters) {
|
|
56
|
+
for (const parameter of parameters) {
|
|
57
|
+
if (this.entry(parameter.name) === undefined) {
|
|
58
|
+
this.parameters.push(parameter);
|
|
59
|
+
this.setEntry(parameter.name, new space_param_1.AbstractParameter(parameter));
|
|
60
|
+
}
|
|
56
61
|
}
|
|
57
62
|
return this;
|
|
58
63
|
}
|
|
64
|
+
parameterSpace() {
|
|
65
|
+
return new parameter_space_1.ParameterSpace(this.parameters);
|
|
66
|
+
}
|
|
59
67
|
newEntry(name, logTo, entry) {
|
|
60
68
|
if (this.entry(name)) {
|
|
61
69
|
logTo.log(`Cannot redefine '${name}'`);
|
|
@@ -74,11 +82,19 @@ class DynamicSpace extends static_space_1.StaticSpace {
|
|
|
74
82
|
this.newTimezone = tz;
|
|
75
83
|
}
|
|
76
84
|
structDef() {
|
|
77
|
-
const parameters = this.fromStruct.parameters || {};
|
|
78
85
|
if (this.final === undefined) {
|
|
86
|
+
// Grab all the parameters so that we can populate the "final" structDef
|
|
87
|
+
// with parameters immediately so that views can see them when they are translating
|
|
88
|
+
const parameters = {};
|
|
89
|
+
for (const [name, entry] of this.entries()) {
|
|
90
|
+
if (entry instanceof space_param_1.SpaceParam) {
|
|
91
|
+
parameters[name] = entry.parameter();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
79
94
|
this.final = {
|
|
80
95
|
...this.fromStruct,
|
|
81
96
|
fields: [],
|
|
97
|
+
parameters,
|
|
82
98
|
};
|
|
83
99
|
// Need to process the entities in specific order
|
|
84
100
|
const fields = [];
|
|
@@ -95,14 +111,12 @@ class DynamicSpace extends static_space_1.StaticSpace {
|
|
|
95
111
|
else if (spaceEntry instanceof space_field_1.SpaceField) {
|
|
96
112
|
fields.push([name, spaceEntry]);
|
|
97
113
|
}
|
|
98
|
-
else if (spaceEntry instanceof space_param_1.SpaceParam) {
|
|
99
|
-
parameters[name] = spaceEntry.parameter();
|
|
100
|
-
}
|
|
101
114
|
}
|
|
102
115
|
const reorderFields = [...fields, ...joins, ...turtles];
|
|
116
|
+
const parameterSpace = this.parameterSpace();
|
|
103
117
|
for (const [, field] of reorderFields) {
|
|
104
118
|
if (field instanceof join_space_field_1.JoinSpaceField) {
|
|
105
|
-
const joinStruct = field.join.structDef();
|
|
119
|
+
const joinStruct = field.join.structDef(parameterSpace);
|
|
106
120
|
if (!error_factory_1.ErrorFactory.isErrorStructDef(joinStruct)) {
|
|
107
121
|
this.final.fields.push(joinStruct);
|
|
108
122
|
fixupJoins.push([field.join, joinStruct]);
|
|
@@ -120,9 +134,6 @@ class DynamicSpace extends static_space_1.StaticSpace {
|
|
|
120
134
|
// }
|
|
121
135
|
}
|
|
122
136
|
}
|
|
123
|
-
if (Object.entries(parameters).length > 0) {
|
|
124
|
-
this.final.parameters = parameters;
|
|
125
|
-
}
|
|
126
137
|
// If we have join expressions, we need to now go back and fill them in
|
|
127
138
|
for (const [join, missingOn] of fixupJoins) {
|
|
128
139
|
join.fixupJoinOn(this, missingOn);
|
|
@@ -107,6 +107,9 @@ class IndexFieldSpace extends query_spaces_1.QueryOperationSpace {
|
|
|
107
107
|
if (wild.except.has(name)) {
|
|
108
108
|
continue;
|
|
109
109
|
}
|
|
110
|
+
if (entry.refType === 'parameter') {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
110
113
|
const indexName = field_references_1.IndexFieldReference.indexOutputName([
|
|
111
114
|
...joinPath,
|
|
112
115
|
name,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Join } from '../source-properties/joins';
|
|
2
|
+
import { ParameterSpace } from './parameter-space';
|
|
2
3
|
import { StructSpaceField } from './static-space';
|
|
3
4
|
export declare class JoinSpaceField extends StructSpaceField {
|
|
5
|
+
readonly parameterSpace: ParameterSpace;
|
|
4
6
|
readonly join: Join;
|
|
5
|
-
constructor(join: Join);
|
|
7
|
+
constructor(parameterSpace: ParameterSpace, join: Join);
|
|
6
8
|
}
|
|
@@ -25,8 +25,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.JoinSpaceField = void 0;
|
|
26
26
|
const static_space_1 = require("./static-space");
|
|
27
27
|
class JoinSpaceField extends static_space_1.StructSpaceField {
|
|
28
|
-
constructor(join) {
|
|
29
|
-
super(join.structDef());
|
|
28
|
+
constructor(parameterSpace, join) {
|
|
29
|
+
super(join.structDef(parameterSpace));
|
|
30
|
+
this.parameterSpace = parameterSpace;
|
|
30
31
|
this.join = join;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Dialect } from '../../../dialect';
|
|
2
|
+
import { StructDef } from '../../../model';
|
|
3
|
+
import { HasParameter } from '../parameters/has-parameter';
|
|
4
|
+
import { FieldName, FieldSpace, QueryFieldSpace } from '../types/field-space';
|
|
5
|
+
import { LookupResult } from '../types/lookup-result';
|
|
6
|
+
import { SpaceEntry } from '../types/space-entry';
|
|
7
|
+
export declare class ParameterSpace implements FieldSpace {
|
|
8
|
+
readonly type = "fieldSpace";
|
|
9
|
+
private readonly _map;
|
|
10
|
+
constructor(parameters: HasParameter[]);
|
|
11
|
+
structDef(): StructDef;
|
|
12
|
+
emptyStructDef(): StructDef;
|
|
13
|
+
entry(name: string): SpaceEntry | undefined;
|
|
14
|
+
lookup(symbol: FieldName[]): LookupResult;
|
|
15
|
+
entries(): [string, SpaceEntry][];
|
|
16
|
+
dialectObj(): Dialect | undefined;
|
|
17
|
+
isQueryFieldSpace(): this is QueryFieldSpace;
|
|
18
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ParameterSpace = void 0;
|
|
10
|
+
const space_param_1 = require("../types/space-param");
|
|
11
|
+
class ParameterSpace {
|
|
12
|
+
constructor(parameters) {
|
|
13
|
+
this.type = 'fieldSpace';
|
|
14
|
+
this._map = {};
|
|
15
|
+
for (const parameter of parameters) {
|
|
16
|
+
this._map[parameter.name] = new space_param_1.AbstractParameter(parameter);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
structDef() {
|
|
20
|
+
throw new Error('Parameter space does not have a structDef');
|
|
21
|
+
}
|
|
22
|
+
emptyStructDef() {
|
|
23
|
+
throw new Error('Parameter space does not have an emptyStructDef');
|
|
24
|
+
}
|
|
25
|
+
entry(name) {
|
|
26
|
+
return this._map[name];
|
|
27
|
+
}
|
|
28
|
+
lookup(symbol) {
|
|
29
|
+
const name = symbol[0];
|
|
30
|
+
if (name === undefined) {
|
|
31
|
+
return {
|
|
32
|
+
error: 'Invalid reference',
|
|
33
|
+
found: undefined,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const entry = this.entry(name.refString);
|
|
37
|
+
if (entry === undefined) {
|
|
38
|
+
return {
|
|
39
|
+
error: `\`${name}\` is not defined`,
|
|
40
|
+
found: undefined,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (symbol.length > 1) {
|
|
44
|
+
return {
|
|
45
|
+
error: `\`${name}\` cannot contain a \`${symbol.slice(1).join('.')}\``,
|
|
46
|
+
found: undefined,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
found: entry,
|
|
51
|
+
error: undefined,
|
|
52
|
+
relationship: [],
|
|
53
|
+
isOutputField: false,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
entries() {
|
|
57
|
+
return Object.entries(this._map);
|
|
58
|
+
}
|
|
59
|
+
dialectObj() {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
isQueryFieldSpace() {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.ParameterSpace = ParameterSpace;
|
|
67
|
+
//# sourceMappingURL=parameter-space.js.map
|
|
@@ -114,6 +114,9 @@ class QueryOperationSpace extends refined_space_1.RefinedSpace {
|
|
|
114
114
|
if (wild.except.has(name)) {
|
|
115
115
|
continue;
|
|
116
116
|
}
|
|
117
|
+
if (entry.refType === 'parameter') {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
117
120
|
if (this.entry(name)) {
|
|
118
121
|
const conflict = (_a = this.expandedWild[name]) === null || _a === void 0 ? void 0 : _a.join('.');
|
|
119
122
|
wild.log(`Cannot expand '${name}' in '${wild.refString}' because a field with that name already exists${conflict ? ` (conflicts with ${conflict})` : ''}`);
|
|
@@ -39,15 +39,24 @@ class ReferenceField extends space_field_1.SpaceField {
|
|
|
39
39
|
return this.memoReference;
|
|
40
40
|
}
|
|
41
41
|
getQueryFieldDef(fs) {
|
|
42
|
+
var _a;
|
|
42
43
|
if (!this.queryFieldDef) {
|
|
43
44
|
const check = this.fieldRef.getField(fs);
|
|
44
45
|
if (check.error) {
|
|
45
46
|
this.fieldRef.log(check.error);
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
// TODO investigate removing 'fieldref' as a type, as it obscures the
|
|
49
|
+
// actual type of the field and is redundant with the slightly
|
|
50
|
+
// more verbose `{ e: [{ type: 'field', path }] }`
|
|
51
|
+
const path = this.fieldRef.list.map(f => f.name);
|
|
52
|
+
const queryFieldDef = ((_a = check.found) === null || _a === void 0 ? void 0 : _a.refType) === 'parameter'
|
|
53
|
+
? {
|
|
54
|
+
type: check.found.typeDesc().dataType,
|
|
55
|
+
name: path[0],
|
|
56
|
+
e: [{ type: 'parameter', path }],
|
|
57
|
+
}
|
|
58
|
+
: { type: 'fieldref', path };
|
|
59
|
+
this.queryFieldDef = queryFieldDef;
|
|
51
60
|
const refTo = this.referenceTo;
|
|
52
61
|
if (refTo instanceof space_field_1.SpaceField && refTo.haveFieldDef) {
|
|
53
62
|
const origFd = refTo.haveFieldDef;
|
|
@@ -2,12 +2,13 @@ import { StructDef } from '../../../model/malloy_types';
|
|
|
2
2
|
import { FieldListEdit } from '../source-properties/field-list-edit';
|
|
3
3
|
import { DynamicSpace } from './dynamic-space';
|
|
4
4
|
import { MalloyElement } from '../types/malloy-element';
|
|
5
|
+
import { ParameterSpace } from './parameter-space';
|
|
5
6
|
export declare class RefinedSpace extends DynamicSpace {
|
|
6
7
|
/**
|
|
7
8
|
* Factory for FieldSpace when there are accept/except edits
|
|
8
9
|
* @param from A structdef which seeds this space
|
|
9
10
|
* @param choose A accept/except edit of the "from" fields
|
|
10
11
|
*/
|
|
11
|
-
static filteredFrom(from: StructDef, choose
|
|
12
|
+
static filteredFrom(from: StructDef, choose: FieldListEdit | undefined, parameters: ParameterSpace | undefined): RefinedSpace;
|
|
12
13
|
pushFields(...defs: MalloyElement[]): void;
|
|
13
14
|
}
|
|
@@ -31,11 +31,22 @@ class RefinedSpace extends dynamic_space_1.DynamicSpace {
|
|
|
31
31
|
* @param from A structdef which seeds this space
|
|
32
32
|
* @param choose A accept/except edit of the "from" fields
|
|
33
33
|
*/
|
|
34
|
-
static filteredFrom(from, choose) {
|
|
34
|
+
static filteredFrom(from, choose, parameters) {
|
|
35
35
|
const edited = new RefinedSpace(from);
|
|
36
36
|
if (choose) {
|
|
37
37
|
const names = choose.refs.list;
|
|
38
38
|
const oldMap = edited.entries();
|
|
39
|
+
for (const name of names) {
|
|
40
|
+
const existing = oldMap.find(([symb]) => symb === name.refString);
|
|
41
|
+
if (existing === undefined) {
|
|
42
|
+
if (parameters === null || parameters === void 0 ? void 0 : parameters.entry(name.refString)) {
|
|
43
|
+
name.log(`Illegal \`${choose.edit}:\` of parameter`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
name.log(`\`${name.refString}\` is not defined`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
39
50
|
edited.dropEntries();
|
|
40
51
|
for (const [symbol, value] of oldMap) {
|
|
41
52
|
const included = !!names.find(f => f.refString === symbol);
|
|
@@ -61,11 +61,9 @@ class StaticSpace {
|
|
|
61
61
|
}
|
|
62
62
|
if (this.fromStruct.parameters) {
|
|
63
63
|
for (const [paramName, paramDef] of Object.entries(this.fromStruct.parameters)) {
|
|
64
|
-
if (this.memoMap
|
|
65
|
-
|
|
66
|
-
` : Field and parameter name conflict '${paramName}`);
|
|
64
|
+
if (!(paramName in this.memoMap)) {
|
|
65
|
+
this.memoMap[paramName] = new space_param_1.DefinedParameter(paramDef);
|
|
67
66
|
}
|
|
68
|
-
this.memoMap[paramName] = new space_param_1.DefinedParameter(paramDef);
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
69
|
}
|
|
@@ -91,7 +89,7 @@ class StaticSpace {
|
|
|
91
89
|
return this.fromStruct;
|
|
92
90
|
}
|
|
93
91
|
emptyStructDef() {
|
|
94
|
-
return { ...this.fromStruct, fields: [] };
|
|
92
|
+
return { ...this.fromStruct, fields: [], parameters: {} };
|
|
95
93
|
}
|
|
96
94
|
lookup(path) {
|
|
97
95
|
const head = path[0];
|
package/dist/lang/ast/index.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export * from './expressions/unary';
|
|
|
59
59
|
export * from './expressions/utils';
|
|
60
60
|
export * from './statements/import-statement';
|
|
61
61
|
export * from './query-properties/extend';
|
|
62
|
+
export * from './parameters/argument';
|
|
62
63
|
export * from './parameters/has-parameter';
|
|
63
64
|
export * from './query-elements/anonymous-query';
|
|
64
65
|
export * from './query-elements/query-refine';
|
package/dist/lang/ast/index.js
CHANGED
|
@@ -97,6 +97,7 @@ __exportStar(require("./expressions/unary"), exports);
|
|
|
97
97
|
__exportStar(require("./expressions/utils"), exports);
|
|
98
98
|
__exportStar(require("./statements/import-statement"), exports);
|
|
99
99
|
__exportStar(require("./query-properties/extend"), exports);
|
|
100
|
+
__exportStar(require("./parameters/argument"), exports);
|
|
100
101
|
__exportStar(require("./parameters/has-parameter"), exports);
|
|
101
102
|
__exportStar(require("./query-elements/anonymous-query"), exports);
|
|
102
103
|
__exportStar(require("./query-elements/query-refine"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ParameterFieldReference } from '../query-items/field-references';
|
|
2
|
+
import { ExpressionDef } from '../types/expression-def';
|
|
3
|
+
import { MalloyElement } from '../types/malloy-element';
|
|
4
|
+
interface ArgInit {
|
|
5
|
+
id?: ParameterFieldReference | undefined;
|
|
6
|
+
value: ExpressionDef;
|
|
7
|
+
}
|
|
8
|
+
export declare class Argument extends MalloyElement {
|
|
9
|
+
elementType: string;
|
|
10
|
+
readonly id: ParameterFieldReference | undefined;
|
|
11
|
+
readonly value: ExpressionDef;
|
|
12
|
+
constructor(init: ArgInit);
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Argument = void 0;
|
|
10
|
+
const malloy_element_1 = require("../types/malloy-element");
|
|
11
|
+
class Argument extends malloy_element_1.MalloyElement {
|
|
12
|
+
constructor(init) {
|
|
13
|
+
super({ ...init });
|
|
14
|
+
this.elementType = 'Argument';
|
|
15
|
+
this.id = init.id;
|
|
16
|
+
this.value = init.value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.Argument = Argument;
|
|
20
|
+
//# sourceMappingURL=argument.js.map
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { Parameter, CastType } from '../../../model/malloy_types';
|
|
2
|
-
import {
|
|
2
|
+
import { ConstantExpression } from '../expressions/constant-expression';
|
|
3
3
|
import { MalloyElement } from '../types/malloy-element';
|
|
4
4
|
interface HasInit {
|
|
5
5
|
name: string;
|
|
6
|
-
isCondition: boolean;
|
|
7
6
|
type?: string;
|
|
8
|
-
default?:
|
|
7
|
+
default?: ConstantExpression;
|
|
9
8
|
}
|
|
10
9
|
export declare class HasParameter extends MalloyElement {
|
|
11
10
|
elementType: string;
|
|
12
11
|
readonly name: string;
|
|
13
|
-
readonly isCondition: boolean;
|
|
14
12
|
readonly type?: CastType;
|
|
15
|
-
readonly default?:
|
|
13
|
+
readonly default?: ConstantExpression;
|
|
16
14
|
constructor(init: HasInit);
|
|
17
15
|
parameter(): Parameter;
|
|
18
16
|
}
|
|
@@ -30,7 +30,6 @@ class HasParameter extends malloy_element_1.MalloyElement {
|
|
|
30
30
|
super();
|
|
31
31
|
this.elementType = 'hasParameter';
|
|
32
32
|
this.name = init.name;
|
|
33
|
-
this.isCondition = init.isCondition;
|
|
34
33
|
if (init.type && (0, malloy_types_1.isCastType)(init.type)) {
|
|
35
34
|
this.type = init.type;
|
|
36
35
|
}
|
|
@@ -40,23 +39,35 @@ class HasParameter extends malloy_element_1.MalloyElement {
|
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
parameter() {
|
|
43
|
-
var _a
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
var _a;
|
|
43
|
+
if (this.default !== undefined) {
|
|
44
|
+
const constant = this.default.constantValue();
|
|
45
|
+
if (this.type &&
|
|
46
|
+
this.type !== constant.dataType &&
|
|
47
|
+
constant.dataType !== 'error') {
|
|
48
|
+
this.default.log(`Default value for parameter does not match declared type \`${this.type}\``);
|
|
49
|
+
}
|
|
50
|
+
if (!(0, malloy_types_1.isCastType)(constant.dataType) && constant.dataType !== 'error') {
|
|
51
|
+
this.default.log(`Default value cannot have type \`${constant.dataType}\``);
|
|
52
|
+
return {
|
|
53
|
+
value: constant.value,
|
|
54
|
+
name: this.name,
|
|
55
|
+
type: 'error',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
48
58
|
return {
|
|
49
|
-
|
|
50
|
-
name,
|
|
51
|
-
|
|
59
|
+
value: constant.value,
|
|
60
|
+
name: this.name,
|
|
61
|
+
type: constant.dataType,
|
|
52
62
|
};
|
|
53
63
|
}
|
|
54
|
-
|
|
64
|
+
if (this.type === undefined) {
|
|
65
|
+
this.log('Parameter must have default value or declared type');
|
|
66
|
+
}
|
|
55
67
|
return {
|
|
56
|
-
value:
|
|
57
|
-
type,
|
|
68
|
+
value: null,
|
|
58
69
|
name: this.name,
|
|
59
|
-
|
|
70
|
+
type: (_a = this.type) !== null && _a !== void 0 ? _a : 'error',
|
|
60
71
|
};
|
|
61
72
|
}
|
|
62
73
|
}
|