@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.
Files changed (67) hide show
  1. package/dist/lang/ast/expressions/constant-expression.d.ts +28 -0
  2. package/dist/lang/ast/expressions/{constant-sub-expression.js → constant-expression.js} +6 -5
  3. package/dist/lang/ast/expressions/expr-func.js +29 -11
  4. package/dist/lang/ast/expressions/expr-id-reference.d.ts +0 -1
  5. package/dist/lang/ast/expressions/expr-id-reference.js +0 -24
  6. package/dist/lang/ast/field-space/dynamic-space.d.ts +4 -1
  7. package/dist/lang/ast/field-space/dynamic-space.js +22 -11
  8. package/dist/lang/ast/field-space/index-field-space.js +3 -0
  9. package/dist/lang/ast/field-space/join-space-field.d.ts +3 -1
  10. package/dist/lang/ast/field-space/join-space-field.js +3 -2
  11. package/dist/lang/ast/field-space/parameter-space.d.ts +18 -0
  12. package/dist/lang/ast/field-space/parameter-space.js +67 -0
  13. package/dist/lang/ast/field-space/query-spaces.js +3 -0
  14. package/dist/lang/ast/field-space/reference-field.js +13 -4
  15. package/dist/lang/ast/field-space/refined-space.d.ts +2 -1
  16. package/dist/lang/ast/field-space/refined-space.js +12 -1
  17. package/dist/lang/ast/field-space/static-space.js +3 -5
  18. package/dist/lang/ast/index.d.ts +1 -0
  19. package/dist/lang/ast/index.js +1 -0
  20. package/dist/lang/ast/parameters/argument.d.ts +14 -0
  21. package/dist/lang/ast/parameters/argument.js +20 -0
  22. package/dist/lang/ast/parameters/has-parameter.d.ts +3 -5
  23. package/dist/lang/ast/parameters/has-parameter.js +24 -13
  24. package/dist/lang/ast/query-elements/query-arrow.js +7 -7
  25. package/dist/lang/ast/query-elements/query-head-struct.d.ts +6 -4
  26. package/dist/lang/ast/query-elements/query-head-struct.js +6 -5
  27. package/dist/lang/ast/query-elements/query-raw.js +7 -7
  28. package/dist/lang/ast/query-elements/query-reference.js +2 -2
  29. package/dist/lang/ast/query-items/field-references.d.ts +4 -0
  30. package/dist/lang/ast/query-items/field-references.js +12 -1
  31. package/dist/lang/ast/source-elements/named-source.d.ts +15 -12
  32. package/dist/lang/ast/source-elements/named-source.js +91 -60
  33. package/dist/lang/ast/source-elements/query-source.d.ts +4 -1
  34. package/dist/lang/ast/source-elements/query-source.js +9 -3
  35. package/dist/lang/ast/source-elements/refined-source.d.ts +3 -2
  36. package/dist/lang/ast/source-elements/refined-source.js +12 -7
  37. package/dist/lang/ast/source-elements/source.d.ts +6 -4
  38. package/dist/lang/ast/source-elements/source.js +19 -16
  39. package/dist/lang/ast/source-elements/sql-source.d.ts +2 -2
  40. package/dist/lang/ast/source-elements/sql-source.js +4 -3
  41. package/dist/lang/ast/source-properties/joins.d.ts +5 -4
  42. package/dist/lang/ast/source-properties/joins.js +7 -7
  43. package/dist/lang/ast/source-query-elements/sq-reference.d.ts +3 -1
  44. package/dist/lang/ast/source-query-elements/sq-reference.js +9 -2
  45. package/dist/lang/ast/statements/define-source.d.ts +4 -2
  46. package/dist/lang/ast/statements/define-source.js +28 -14
  47. package/dist/lang/ast/struct-utils.js +3 -2
  48. package/dist/lang/ast/types/expression-def.js +2 -0
  49. package/dist/lang/lib/Malloy/MalloyParser.d.ts +169 -101
  50. package/dist/lang/lib/Malloy/MalloyParser.js +2105 -1600
  51. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +64 -9
  52. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +40 -5
  53. package/dist/lang/malloy-to-ast.d.ts +5 -1
  54. package/dist/lang/malloy-to-ast.js +51 -10
  55. package/dist/lang/test/expressions.spec.js +21 -1
  56. package/dist/lang/test/field-symbols.spec.js +0 -2
  57. package/dist/lang/test/locations.spec.js +3 -0
  58. package/dist/lang/test/parameters.spec.d.ts +1 -0
  59. package/dist/lang/test/parameters.spec.js +578 -0
  60. package/dist/model/malloy_query.d.ts +8 -5
  61. package/dist/model/malloy_query.js +68 -37
  62. package/dist/model/malloy_types.d.ts +12 -14
  63. package/dist/model/malloy_types.js +22 -10
  64. package/package.json +1 -1
  65. package/dist/lang/ast/expressions/constant-sub-expression.d.ts +0 -16
  66. package/dist/lang/ast/parameters/constant-parameter.d.ts +0 -8
  67. package/dist/lang/ast/parameters/constant-parameter.js +0 -54
@@ -46,18 +46,18 @@ class QueryArrow extends query_base_1.QueryBase {
46
46
  if (this.source instanceof source_1.Source) {
47
47
  // We create a fresh query with either the QOPDesc as the head,
48
48
  // the view as the head, or the scalar as the head (if scalar lenses is enabled)
49
- const structRef = isRefOk
50
- ? this.source.structRef()
51
- : this.source.structDef();
49
+ const invoked = isRefOk
50
+ ? this.source.structRef(undefined)
51
+ : { structRef: this.source.structDef(undefined) };
52
52
  queryBase = {
53
53
  type: 'query',
54
- structRef,
54
+ ...invoked,
55
55
  pipeline: [],
56
56
  location: this.location,
57
57
  };
58
- inputStruct = (0, malloy_types_1.refIsStructDef)(structRef)
59
- ? structRef
60
- : this.source.structDef();
58
+ inputStruct = (0, malloy_types_1.refIsStructDef)(invoked.structRef)
59
+ ? invoked.structRef
60
+ : this.source.structDef(undefined);
61
61
  fieldSpace = new static_space_1.StaticSpace(inputStruct);
62
62
  }
63
63
  else {
@@ -1,9 +1,11 @@
1
- import { StructDef, StructRef } from '../../../model/malloy_types';
1
+ import { Argument, InvokedStructRef, StructDef, StructRef } from '../../../model/malloy_types';
2
2
  import { Source } from '../source-elements/source';
3
+ import { ParameterSpace } from '../field-space/parameter-space';
3
4
  export declare class QueryHeadStruct extends Source {
4
5
  readonly fromRef: StructRef;
6
+ readonly sourceArguments: Record<string, Argument> | undefined;
5
7
  elementType: string;
6
- constructor(fromRef: StructRef);
7
- structRef(): StructRef;
8
- structDef(): StructDef;
8
+ constructor(fromRef: StructRef, sourceArguments: Record<string, Argument> | undefined);
9
+ structRef(): InvokedStructRef;
10
+ structDef(parameterSpace: ParameterSpace | undefined): StructDef;
9
11
  }
@@ -27,21 +27,22 @@ const malloy_types_1 = require("../../../model/malloy_types");
27
27
  const source_1 = require("../source-elements/source");
28
28
  const named_source_1 = require("../source-elements/named-source");
29
29
  class QueryHeadStruct extends source_1.Source {
30
- constructor(fromRef) {
30
+ constructor(fromRef, sourceArguments) {
31
31
  super();
32
32
  this.fromRef = fromRef;
33
+ this.sourceArguments = sourceArguments;
33
34
  this.elementType = 'internalOnlyQueryHead';
34
35
  }
35
36
  structRef() {
36
- return this.fromRef;
37
+ return { structRef: this.fromRef };
37
38
  }
38
- structDef() {
39
+ structDef(parameterSpace) {
39
40
  if ((0, malloy_types_1.refIsStructDef)(this.fromRef)) {
40
41
  return this.fromRef;
41
42
  }
42
- const ns = new named_source_1.NamedSource(this.fromRef);
43
+ const ns = new named_source_1.NamedSource(this.fromRef, this.sourceArguments, undefined);
43
44
  this.has({ exploreReference: ns });
44
- return ns.structDef();
45
+ return ns.structDef(parameterSpace);
45
46
  }
46
47
  }
47
48
  exports.QueryHeadStruct = QueryHeadStruct;
@@ -40,16 +40,16 @@ class QueryRaw extends malloy_element_1.MalloyElement {
40
40
  this.elementType = 'query-raw';
41
41
  }
42
42
  queryComp(isRefOk) {
43
- const structRef = isRefOk
44
- ? this.source.structRef()
45
- : this.source.structDef();
46
- const structDef = (0, malloy_types_1.refIsStructDef)(structRef)
47
- ? structRef
48
- : this.source.structDef();
43
+ const invoked = isRefOk
44
+ ? this.source.structRef(undefined)
45
+ : { structRef: this.source.structDef(undefined) };
46
+ const structDef = (0, malloy_types_1.refIsStructDef)(invoked.structRef)
47
+ ? invoked.structRef
48
+ : this.source.structDef(undefined);
49
49
  return {
50
50
  query: {
51
51
  type: 'query',
52
- structRef,
52
+ ...invoked,
53
53
  pipeline: [{ type: 'raw', fields: [] }],
54
54
  location: this.location,
55
55
  },
@@ -54,9 +54,9 @@ class QueryReference extends malloy_element_1.MalloyElement {
54
54
  return oops();
55
55
  }
56
56
  if (query.type === 'query') {
57
- const queryHead = new query_head_struct_1.QueryHeadStruct(query.structRef);
57
+ const queryHead = new query_head_struct_1.QueryHeadStruct(query.structRef, query.sourceArguments);
58
58
  this.has({ queryHead: queryHead });
59
- const inputStruct = queryHead.structDef();
59
+ const inputStruct = queryHead.structDef(undefined);
60
60
  const outputStruct = (0, struct_utils_1.getFinalStruct)(this, inputStruct, query.pipeline);
61
61
  const unRefedQuery = isRefOk
62
62
  ? query
@@ -34,6 +34,10 @@ export declare class PartitionByFieldReference extends FieldReference {
34
34
  elementType: string;
35
35
  typecheck(): void;
36
36
  }
37
+ export declare class ParameterFieldReference extends FieldReference {
38
+ elementType: string;
39
+ typecheck(): void;
40
+ }
37
41
  export declare class CalculateFieldReference extends FieldReference {
38
42
  elementType: string;
39
43
  typecheck(type: TypeDesc): void;
@@ -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.FieldReferences = exports.WildcardFieldReference = exports.ViewOrScalarFieldReference = exports.DimensionFieldReference = exports.MeasureFieldReference = exports.DeclareFieldReference = exports.ProjectFieldReference = exports.GroupByFieldReference = exports.AggregateFieldReference = exports.IndexFieldReference = exports.CalculateFieldReference = exports.PartitionByFieldReference = exports.ExpressionFieldReference = exports.AcceptExceptFieldReference = exports.FieldReference = void 0;
25
+ exports.FieldReferences = exports.WildcardFieldReference = exports.ViewOrScalarFieldReference = exports.DimensionFieldReference = exports.MeasureFieldReference = exports.DeclareFieldReference = exports.ProjectFieldReference = exports.GroupByFieldReference = exports.AggregateFieldReference = exports.IndexFieldReference = exports.CalculateFieldReference = exports.ParameterFieldReference = exports.PartitionByFieldReference = exports.ExpressionFieldReference = exports.AcceptExceptFieldReference = exports.FieldReference = void 0;
26
26
  const reference_field_1 = require("../field-space/reference-field");
27
27
  const definition_list_1 = require("../types/definition-list");
28
28
  const malloy_element_1 = require("../types/malloy-element");
@@ -116,6 +116,17 @@ class PartitionByFieldReference extends FieldReference {
116
116
  }
117
117
  }
118
118
  exports.PartitionByFieldReference = PartitionByFieldReference;
119
+ class ParameterFieldReference extends FieldReference {
120
+ constructor() {
121
+ super(...arguments);
122
+ this.elementType = 'parameterFieldReference';
123
+ }
124
+ // The invocation of the argument will typecheck this
125
+ typecheck() {
126
+ return;
127
+ }
128
+ }
129
+ exports.ParameterFieldReference = ParameterFieldReference;
119
130
  class CalculateFieldReference extends FieldReference {
120
131
  constructor() {
121
132
  super(...arguments);
@@ -1,19 +1,22 @@
1
- import { StructDef, StructRef } from '../../../model/malloy_types';
1
+ import { Argument, InvokedStructRef, StructDef } from '../../../model/malloy_types';
2
2
  import { Source } from './source';
3
- import { ConstantSubExpression } from '../expressions/constant-sub-expression';
4
- import { MalloyElement, ModelEntryReference } from '../types/malloy-element';
5
- export declare class IsValueBlock extends MalloyElement {
6
- readonly isMap: Record<string, ConstantSubExpression>;
7
- elementType: string;
8
- constructor(isMap: Record<string, ConstantSubExpression>);
9
- }
3
+ import { ModelEntryReference } from '../types/malloy-element';
4
+ import { Argument as HasArgument } from '../parameters/argument';
5
+ import { LogSeverity } from '../../parse-log';
6
+ import { ParameterSpace } from '../field-space/parameter-space';
7
+ import { HasParameter } from '../parameters/has-parameter';
10
8
  export declare class NamedSource extends Source {
11
9
  readonly ref: ModelEntryReference | string;
10
+ readonly sourceArguments: Record<string, Argument> | undefined;
11
+ readonly args: HasArgument[] | undefined;
12
12
  elementType: string;
13
- protected isBlock?: IsValueBlock;
14
- constructor(ref: ModelEntryReference | string, paramValues?: Record<string, ConstantSubExpression>);
13
+ constructor(ref: ModelEntryReference | string, sourceArguments: Record<string, Argument> | undefined, args: HasArgument[] | undefined);
15
14
  get refName(): string;
16
- structRef(): StructRef;
15
+ structRef(parameterSpace: ParameterSpace | undefined): InvokedStructRef;
16
+ refLog(message: string, severity?: LogSeverity): void;
17
17
  modelStruct(): StructDef | undefined;
18
- structDef(): StructDef;
18
+ private evaluateArgumentsForRef;
19
+ private evaluateArguments;
20
+ structDef(parameterSpace: ParameterSpace | undefined): StructDef;
21
+ withParameters(parameterSpace: ParameterSpace | undefined, pList: HasParameter[] | undefined): StructDef;
19
22
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  /*
3
3
  * Copyright 2023 Google LLC
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
5
  *
5
6
  * Permission is hereby granted, free of charge, to any person obtaining
6
7
  * a copy of this software and associated documentation files
@@ -22,29 +23,23 @@
22
23
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24
  */
24
25
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.NamedSource = exports.IsValueBlock = void 0;
26
+ exports.NamedSource = void 0;
26
27
  const malloy_types_1 = require("../../../model/malloy_types");
27
28
  const source_1 = require("./source");
28
29
  const error_factory_1 = require("../error-factory");
29
30
  const time_utils_1 = require("../time-utils");
30
31
  const malloy_element_1 = require("../types/malloy-element");
31
- class IsValueBlock extends malloy_element_1.MalloyElement {
32
- constructor(isMap) {
33
- super();
34
- this.isMap = isMap;
35
- this.elementType = 'isValueBlock';
36
- this.has(isMap);
37
- }
38
- }
39
- exports.IsValueBlock = IsValueBlock;
32
+ const expr_id_reference_1 = require("../expressions/expr-id-reference");
33
+ const parameter_space_1 = require("../field-space/parameter-space");
40
34
  class NamedSource extends source_1.Source {
41
- constructor(ref, paramValues = {}) {
35
+ constructor(ref, sourceArguments, args) {
42
36
  super();
43
37
  this.ref = ref;
38
+ this.sourceArguments = sourceArguments;
39
+ this.args = args;
44
40
  this.elementType = 'namedSource';
45
- if (paramValues && Object.keys(paramValues).length > 0) {
46
- this.isBlock = new IsValueBlock(paramValues);
47
- this.has({ parameterValues: this.isBlock });
41
+ if (args) {
42
+ this.has({ args });
48
43
  }
49
44
  if (ref instanceof malloy_element_1.ModelEntryReference) {
50
45
  this.has({ ref: ref });
@@ -53,17 +48,26 @@ class NamedSource extends source_1.Source {
53
48
  get refName() {
54
49
  return this.ref instanceof malloy_element_1.ModelEntryReference ? this.ref.name : this.ref;
55
50
  }
56
- structRef() {
57
- if (this.isBlock) {
58
- return this.structDef();
59
- }
51
+ structRef(parameterSpace) {
60
52
  const modelEnt = this.modelEntry(this.ref);
53
+ // If we are not exporting the referenced structdef, don't use the reference
61
54
  if (modelEnt && !modelEnt.exported) {
62
- // If we are not exporting the referenced structdef, don't
63
- // use the reference
64
- return this.structDef();
55
+ return {
56
+ structRef: this.structDef(parameterSpace),
57
+ };
58
+ }
59
+ return {
60
+ structRef: this.refName,
61
+ sourceArguments: this.evaluateArgumentsForRef(parameterSpace),
62
+ };
63
+ }
64
+ refLog(message, severity) {
65
+ if (typeof this.ref === 'string') {
66
+ this.log(message, severity);
67
+ }
68
+ else {
69
+ this.ref.log(message, severity);
65
70
  }
66
- return this.refName;
67
71
  }
68
72
  modelStruct() {
69
73
  var _a;
@@ -95,7 +99,61 @@ class NamedSource extends source_1.Source {
95
99
  }
96
100
  return { ...entry };
97
101
  }
98
- structDef() {
102
+ evaluateArgumentsForRef(parameterSpace) {
103
+ const base = this.modelStruct();
104
+ if (base === undefined) {
105
+ return {};
106
+ }
107
+ return this.evaluateArguments(parameterSpace, base.parameters, []);
108
+ }
109
+ evaluateArguments(parameterSpace, parametersIn, parametersOut) {
110
+ var _a, _b;
111
+ const outArguments = { ...this.sourceArguments };
112
+ const passedNames = new Set();
113
+ for (const argument of (_a = this.args) !== null && _a !== void 0 ? _a : []) {
114
+ const id = (_b = argument.id) !== null && _b !== void 0 ? _b : (argument.value instanceof expr_id_reference_1.ExprIdReference
115
+ ? argument.value.fieldReference
116
+ : undefined);
117
+ if (id === undefined) {
118
+ argument.value.log('Parameterized source arguments must be named with `parameter_name is`');
119
+ continue;
120
+ }
121
+ const name = id.outputName;
122
+ if (passedNames.has(name)) {
123
+ argument.log(`Cannot pass argument for \`${name}\` more than once`);
124
+ continue;
125
+ }
126
+ passedNames.add(name);
127
+ const parameter = (parametersIn !== null && parametersIn !== void 0 ? parametersIn : {})[name];
128
+ if (!parameter) {
129
+ id.log(`\`${this.refName}\` has no declared parameter named \`${id.refString}\``);
130
+ }
131
+ else {
132
+ const paramSpace = parameterSpace !== null && parameterSpace !== void 0 ? parameterSpace : new parameter_space_1.ParameterSpace(parametersOut !== null && parametersOut !== void 0 ? parametersOut : []);
133
+ const pVal = argument.value.getExpression(paramSpace);
134
+ let value = pVal.value;
135
+ if (pVal.dataType !== parameter.type && (0, malloy_types_1.isCastType)(parameter.type)) {
136
+ value = (0, time_utils_1.castTo)(parameter.type, pVal.value, pVal.dataType, true);
137
+ }
138
+ outArguments[name] = {
139
+ ...parameter,
140
+ value,
141
+ };
142
+ }
143
+ }
144
+ for (const paramName in parametersIn) {
145
+ if (!(paramName in outArguments)) {
146
+ if (!(0, malloy_types_1.paramHasValue)(parametersIn[paramName])) {
147
+ this.refLog(`Argument not provided for required parameter \`${paramName}\``);
148
+ }
149
+ }
150
+ }
151
+ return outArguments;
152
+ }
153
+ structDef(parameterSpace) {
154
+ return this.withParameters(parameterSpace, []);
155
+ }
156
+ withParameters(parameterSpace, pList) {
99
157
  /*
100
158
  Can't really generate the callback list until after all the
101
159
  things before me are translated, and that kinda screws up
@@ -109,50 +167,23 @@ class NamedSource extends source_1.Source {
109
167
  can do other translations and link them into a partial translation
110
168
  which might result in a full translation.
111
169
  */
112
- var _a, _b;
113
- const ret = this.modelStruct();
114
- if (!ret) {
170
+ var _a;
171
+ const base = this.modelStruct();
172
+ if (!base) {
115
173
  const notFound = error_factory_1.ErrorFactory.structDef;
116
174
  const err = `${this.refName}-undefined`;
117
175
  notFound.name = notFound.name + err;
118
176
  notFound.dialect = notFound.dialect + err;
119
177
  return notFound;
120
178
  }
121
- const declared = { ...ret.parameters };
122
- const makeWith = ((_a = this.isBlock) === null || _a === void 0 ? void 0 : _a.isMap) || {};
123
- for (const [pName, pExpr] of Object.entries(makeWith)) {
124
- const decl = declared[pName];
125
- // const pVal = pExpr.constantValue();
126
- if (!decl) {
127
- this.log(`Value given for undeclared parameter '${pName}`);
128
- }
129
- else {
130
- if ((0, malloy_types_1.isValueParameter)(decl)) {
131
- if (decl.constant) {
132
- pExpr.log(`Cannot override constant parameter ${pName}`);
133
- }
134
- else {
135
- const pVal = pExpr.constantValue();
136
- let value = pVal.value;
137
- if (pVal.dataType !== decl.type && (0, malloy_types_1.isCastType)(decl.type)) {
138
- value = (0, time_utils_1.castTo)(decl.type, pVal.value, pVal.dataType, true);
139
- }
140
- decl.value = value;
141
- }
142
- }
143
- else {
144
- // TODO type checking here -- except I am still not sure what
145
- // datatype half conditions have ..
146
- decl.condition = pExpr.constantCondition(decl.type).value;
147
- }
148
- }
149
- }
150
- for (const checkDef in ret.parameters) {
151
- if (!(0, malloy_types_1.paramHasValue)(declared[checkDef])) {
152
- this.log(`Value not provided for required parameter ${checkDef}`);
153
- }
179
+ const outParameters = {};
180
+ for (const parameter of pList !== null && pList !== void 0 ? pList : []) {
181
+ const compiled = parameter.parameter();
182
+ outParameters[compiled.name] = compiled;
154
183
  }
155
- (_b = this.document()) === null || _b === void 0 ? void 0 : _b.rememberToAddModelAnnotations(ret);
184
+ const outArguments = this.evaluateArguments(parameterSpace, base.parameters, pList);
185
+ const ret = { ...base, parameters: outParameters, arguments: outArguments };
186
+ (_a = this.document()) === null || _a === void 0 ? void 0 : _a.rememberToAddModelAnnotations(ret);
156
187
  return ret;
157
188
  }
158
189
  }
@@ -1,9 +1,12 @@
1
1
  import { StructDef } from '../../../model/malloy_types';
2
2
  import { Source } from './source';
3
3
  import { QueryElement } from '../types/query-element';
4
+ import { ParameterSpace } from '../field-space/parameter-space';
5
+ import { HasParameter } from '../parameters/has-parameter';
4
6
  export declare class QuerySource extends Source {
5
7
  readonly query: QueryElement;
6
8
  elementType: string;
7
9
  constructor(query: QueryElement);
8
- structDef(): StructDef;
10
+ structDef(parameterSpace: ParameterSpace | undefined): StructDef;
11
+ withParameters(parameterSpace: ParameterSpace | undefined, pList: HasParameter[] | undefined): StructDef;
9
12
  }
@@ -26,11 +26,14 @@ exports.QuerySource = void 0;
26
26
  const source_1 = require("./source");
27
27
  class QuerySource extends source_1.Source {
28
28
  constructor(query) {
29
- super({ query: query });
29
+ super({ query });
30
30
  this.query = query;
31
31
  this.elementType = 'querySource';
32
32
  }
33
- structDef() {
33
+ structDef(parameterSpace) {
34
+ return this.withParameters(parameterSpace, undefined);
35
+ }
36
+ withParameters(parameterSpace, pList) {
34
37
  var _a;
35
38
  const comp = this.query.queryComp(false);
36
39
  const queryStruct = {
@@ -38,7 +41,10 @@ class QuerySource extends source_1.Source {
38
41
  structSource: { type: 'query', query: comp.query },
39
42
  };
40
43
  (_a = this.document()) === null || _a === void 0 ? void 0 : _a.rememberToAddModelAnnotations(queryStruct);
41
- return queryStruct;
44
+ return {
45
+ ...queryStruct,
46
+ parameters: this.packParameters(pList),
47
+ };
42
48
  }
43
49
  }
44
50
  exports.QuerySource = QuerySource;
@@ -2,6 +2,7 @@ import { Annotation, StructDef } from '../../../model/malloy_types';
2
2
  import { HasParameter } from '../parameters/has-parameter';
3
3
  import { SourceDesc } from '../types/source-desc';
4
4
  import { Source } from './source';
5
+ import { ParameterSpace } from '../field-space/parameter-space';
5
6
  /**
6
7
  * A Source made from a source reference and a set of refinements
7
8
  */
@@ -11,6 +12,6 @@ export declare class RefinedSource extends Source {
11
12
  elementType: string;
12
13
  currentAnnotation?: Annotation;
13
14
  constructor(source: Source, refinement: SourceDesc);
14
- structDef(): StructDef;
15
- withParameters(pList: HasParameter[] | undefined): StructDef;
15
+ structDef(parameterSpace: ParameterSpace | undefined): StructDef;
16
+ withParameters(parameterSpace: ParameterSpace | undefined, pList: HasParameter[] | undefined): StructDef;
16
17
  }
@@ -35,20 +35,21 @@ const source_1 = require("./source");
35
35
  const timezone_statement_1 = require("../source-properties/timezone-statement");
36
36
  const annotation_elements_1 = require("../types/annotation-elements");
37
37
  const renames_1 = require("../source-properties/renames");
38
+ const parameter_space_1 = require("../field-space/parameter-space");
38
39
  /**
39
40
  * A Source made from a source reference and a set of refinements
40
41
  */
41
42
  class RefinedSource extends source_1.Source {
42
43
  constructor(source, refinement) {
43
- super({ source: source, refinement: refinement });
44
+ super({ source, refinement });
44
45
  this.source = source;
45
46
  this.refinement = refinement;
46
47
  this.elementType = 'refinedSource';
47
48
  }
48
- structDef() {
49
- return this.withParameters([]);
49
+ structDef(parameterSpace) {
50
+ return this.withParameters(parameterSpace, []);
50
51
  }
51
- withParameters(pList) {
52
+ withParameters(parameterSpace, pList) {
52
53
  var _a;
53
54
  let primaryKey;
54
55
  let fieldListEdit;
@@ -91,18 +92,22 @@ class RefinedSource extends source_1.Source {
91
92
  errTo.log(`Unexpected source property: '${errTo.elementType}'`);
92
93
  }
93
94
  }
94
- const from = structuredClone(this.source.structDef());
95
+ const paramSpace = pList ? new parameter_space_1.ParameterSpace(pList) : undefined;
96
+ const from = structuredClone(this.source.structDef(paramSpace));
97
+ // Note that this is explicitly not:
98
+ // const from = structuredClone(this.source.withParameters(parameterSpace, pList));
99
+ // Because the parameters are added to the resulting struct, not the base struct
95
100
  if (primaryKey) {
96
101
  from.primaryKey = primaryKey.field.name;
97
102
  }
98
- const fs = refined_space_1.RefinedSpace.filteredFrom(from, fieldListEdit);
103
+ const fs = refined_space_1.RefinedSpace.filteredFrom(from, fieldListEdit, paramSpace);
99
104
  if (newTimezone) {
100
105
  fs.setTimezone(newTimezone);
101
106
  }
102
- fs.pushFields(...fields);
103
107
  if (pList) {
104
108
  fs.addParameters(pList);
105
109
  }
110
+ fs.pushFields(...fields);
106
111
  if (primaryKey) {
107
112
  const keyDef = primaryKey.field.getField(fs);
108
113
  if (keyDef.error) {
@@ -1,12 +1,14 @@
1
- import { StructDef, StructRef } from '../../../model/malloy_types';
1
+ import { InvokedStructRef, Parameter, StructDef } from '../../../model/malloy_types';
2
2
  import { MalloyElement } from '../types/malloy-element';
3
3
  import { HasParameter } from '../parameters/has-parameter';
4
+ import { ParameterSpace } from '../field-space/parameter-space';
4
5
  /**
5
6
  * A "Source" is a thing which you can run queries against. The main
6
7
  * function of a source is to represent an eventual StructDef
7
8
  */
8
9
  export declare abstract class Source extends MalloyElement {
9
- abstract structDef(): StructDef;
10
- structRef(): StructRef;
11
- withParameters(pList: HasParameter[] | undefined): StructDef;
10
+ abstract structDef(parameterSpace: ParameterSpace | undefined): StructDef;
11
+ structRef(parameterSpace: ParameterSpace | undefined): InvokedStructRef;
12
+ protected packParameters(pList: HasParameter[] | undefined): Record<string, Parameter> | undefined;
13
+ withParameters(parameterSpace: ParameterSpace | undefined, pList: HasParameter[] | undefined): StructDef;
12
14
  }
@@ -29,24 +29,27 @@ const malloy_element_1 = require("../types/malloy-element");
29
29
  * function of a source is to represent an eventual StructDef
30
30
  */
31
31
  class Source extends malloy_element_1.MalloyElement {
32
- structRef() {
33
- return this.structDef();
32
+ structRef(parameterSpace) {
33
+ return {
34
+ structRef: this.structDef(parameterSpace),
35
+ };
34
36
  }
35
- withParameters(pList) {
36
- const before = this.structDef();
37
- // TODO name collisions are flagged where?
38
- if (pList) {
39
- const parameters = { ...(before.parameters || {}) };
40
- for (const hasP of pList) {
41
- const pVal = hasP.parameter();
42
- parameters[pVal.name] = pVal;
43
- }
44
- return {
45
- ...before,
46
- parameters,
47
- };
37
+ packParameters(pList) {
38
+ if (pList === undefined)
39
+ return undefined;
40
+ const parameters = {};
41
+ for (const hasP of pList) {
42
+ const pVal = hasP.parameter();
43
+ parameters[pVal.name] = pVal;
48
44
  }
49
- return before;
45
+ return parameters;
46
+ }
47
+ withParameters(parameterSpace, pList) {
48
+ const before = this.structDef(parameterSpace);
49
+ return {
50
+ ...before,
51
+ parameters: this.packParameters(pList),
52
+ };
50
53
  }
51
54
  }
52
55
  exports.Source = Source;
@@ -1,4 +1,4 @@
1
- import { StructDef, StructRef, SQLBlockSource } from '../../../model/malloy_types';
1
+ import { StructDef, SQLBlockSource, InvokedStructRef } from '../../../model/malloy_types';
2
2
  import { NeedCompileSQL } from '../../translate-response';
3
3
  import { Source } from './source';
4
4
  import { SQLString } from '../sql-elements/sql-string';
@@ -11,7 +11,7 @@ export declare class SQLSource extends Source {
11
11
  private connectionNameInvalid;
12
12
  constructor(connectionName: ModelEntryReference, select: SQLString);
13
13
  sqlBlock(): SQLBlockSource;
14
- structRef(): StructRef;
14
+ structRef(): InvokedStructRef;
15
15
  validateConnectionName(): boolean;
16
16
  needs(doc: Document): NeedCompileSQL | undefined;
17
17
  structDef(): StructDef;
@@ -28,12 +28,11 @@ const source_1 = require("./source");
28
28
  const error_factory_1 = require("../error-factory");
29
29
  class SQLSource extends source_1.Source {
30
30
  constructor(connectionName, select) {
31
- super();
31
+ super({ connectionName, select });
32
32
  this.connectionName = connectionName;
33
33
  this.select = select;
34
34
  this.elementType = 'sqlSource';
35
35
  this.connectionNameInvalid = false;
36
- this.has({ connectionName, select });
37
36
  }
38
37
  sqlBlock() {
39
38
  if (!this.requestBlock) {
@@ -42,7 +41,9 @@ class SQLSource extends source_1.Source {
42
41
  return this.requestBlock;
43
42
  }
44
43
  structRef() {
45
- return this.structDef();
44
+ return {
45
+ structRef: this.structDef(),
46
+ };
46
47
  }
47
48
  validateConnectionName() {
48
49
  var _a;
@@ -9,16 +9,17 @@ import { extendNoteMethod, Noteable } from '../types/noteable';
9
9
  import { LegalRefinementStage, QueryPropertyInterface } from '../types/query-property-interface';
10
10
  import { MakeEntry } from '../types/space-entry';
11
11
  import { SourceQueryElement } from '../source-query-elements/source-query-element';
12
+ import { ParameterSpace } from '../field-space/parameter-space';
12
13
  export declare abstract class Join extends MalloyElement implements Noteable, MakeEntry {
13
14
  abstract name: ModelEntryReference;
14
- abstract structDef(): StructDef;
15
+ abstract structDef(parameterSpace: ParameterSpace): StructDef;
15
16
  abstract fixupJoinOn(outer: FieldSpace, inStruct: StructDef): void;
16
17
  readonly isNoteableObj = true;
17
18
  extendNote: typeof extendNoteMethod;
18
19
  abstract sourceExpr: SourceQueryElement;
19
20
  note?: Annotation;
20
21
  makeEntry(fs: DynamicSpace): void;
21
- protected getStructDefFromExpr(): StructDef;
22
+ protected getStructDefFromExpr(parameterSpace: ParameterSpace): StructDef;
22
23
  }
23
24
  export declare class KeyJoin extends Join {
24
25
  readonly name: ModelEntryReference;
@@ -26,7 +27,7 @@ export declare class KeyJoin extends Join {
26
27
  readonly keyExpr: ExpressionDef;
27
28
  elementType: string;
28
29
  constructor(name: ModelEntryReference, sourceExpr: SourceQueryElement, keyExpr: ExpressionDef);
29
- structDef(): StructDef;
30
+ structDef(parameterSpace: ParameterSpace): StructDef;
30
31
  fixupJoinOn(outer: FieldSpace, inStruct: StructDef): void;
31
32
  }
32
33
  type ExpressionJoinType = 'many' | 'one' | 'cross';
@@ -42,7 +43,7 @@ export declare class ExpressionJoin extends Join {
42
43
  set joinOn(joinExpr: ExpressionDef | undefined);
43
44
  get joinOn(): ExpressionDef | undefined;
44
45
  fixupJoinOn(outer: FieldSpace, inStruct: StructDef): Expr | undefined;
45
- structDef(): StructDef;
46
+ structDef(parameterSpace: ParameterSpace): StructDef;
46
47
  }
47
48
  export declare class Joins extends DefinitionList<Join> implements QueryPropertyInterface {
48
49
  elementType: string;