@malloydata/malloy 0.0.276 → 0.0.278

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.
@@ -1,20 +1,18 @@
1
- import type { FilterableType } from '@malloydata/malloy-filter';
2
- import type { Parameter, ParameterType } from '../../../model/malloy_types';
1
+ import type { Parameter, ParameterTypeDef } from '../../../model/malloy_types';
3
2
  import type { ConstantExpression } from '../expressions/constant-expression';
4
3
  import { MalloyElement } from '../types/malloy-element';
5
4
  interface HasInit {
6
5
  name: string;
7
- type?: ParameterType;
8
- filterType?: FilterableType;
6
+ typeDef?: ParameterTypeDef;
9
7
  default?: ConstantExpression;
10
8
  }
11
9
  export declare class HasParameter extends MalloyElement {
12
10
  elementType: string;
13
11
  readonly name: string;
14
- readonly type?: ParameterType;
12
+ readonly typeDef?: ParameterTypeDef;
15
13
  readonly default?: ConstantExpression;
16
- readonly filterType?: FilterableType;
17
14
  constructor(init: HasInit);
15
+ private get type();
18
16
  parameter(): Parameter;
19
17
  }
20
18
  export {};
@@ -31,19 +31,25 @@ class HasParameter extends malloy_element_1.MalloyElement {
31
31
  super();
32
32
  this.elementType = 'hasParameter';
33
33
  this.name = init.name;
34
- if (init.type && (0, malloy_types_1.isParameterType)(init.type)) {
35
- this.type = init.type;
34
+ if (init.typeDef) {
35
+ this.typeDef = init.typeDef;
36
36
  }
37
37
  if (init.default) {
38
38
  this.default = init.default;
39
39
  this.has({ default: this.default });
40
40
  }
41
- if (init.filterType)
42
- this.filterType = init.filterType;
41
+ }
42
+ get type() {
43
+ var _a;
44
+ return (_a = this.typeDef) === null || _a === void 0 ? void 0 : _a.type;
43
45
  }
44
46
  parameter() {
45
47
  var _a;
46
- let paramReturn;
48
+ const paramReturn = {
49
+ ...(this.typeDef || { type: 'error' }),
50
+ value: null,
51
+ name: this.name,
52
+ };
47
53
  if (this.default !== undefined) {
48
54
  const constant = this.default.constantValue();
49
55
  if (this.type &&
@@ -55,9 +61,8 @@ class HasParameter extends malloy_element_1.MalloyElement {
55
61
  if (constant.type === 'null') {
56
62
  if (this.type) {
57
63
  return {
58
- type: this.type,
64
+ ...paramReturn,
59
65
  value: constant.value,
60
- name: this.name,
61
66
  };
62
67
  }
63
68
  else {
@@ -70,40 +75,33 @@ class HasParameter extends malloy_element_1.MalloyElement {
70
75
  }
71
76
  }
72
77
  if (constant.type === 'filter expression') {
73
- if (this.type !== 'filter expression') {
78
+ if (((_a = this.typeDef) === null || _a === void 0 ? void 0 : _a.type) !== 'filter expression') {
74
79
  this.logError('parameter-missing-default-or-type', `Filter expression parameters must have expicit filter type, for example '${this.name}::filter<string>'`);
80
+ return { ...paramReturn, type: 'error' };
75
81
  }
76
- if (this.filterType) {
77
- (0, expression_def_1.checkFilterExpression)(this, this.filterType, constant.value);
78
- }
82
+ (0, expression_def_1.checkFilterExpression)(this, this.typeDef.filterType, constant.value);
79
83
  return {
80
- value: constant.value,
84
+ type: 'filter expression',
85
+ filterType: this.typeDef.filterType,
81
86
  name: this.name,
82
- type: constant.type,
87
+ value: constant.value,
83
88
  };
84
89
  }
85
- if (!(0, malloy_types_1.isCastType)(constant.type) && constant.type !== 'error') {
90
+ if (!(0, malloy_types_1.isParameterType)(constant.type)) {
86
91
  this.default.logError('parameter-illegal-default-type', `Default value cannot have type \`${constant.type}\``);
87
92
  return {
88
- value: constant.value,
89
- name: this.name,
93
+ ...paramReturn,
90
94
  type: 'error',
91
95
  };
92
96
  }
93
- paramReturn = {
94
- value: constant.value,
95
- name: this.name,
96
- type: constant.type,
97
- };
97
+ paramReturn.type = constant.type;
98
+ paramReturn.value = constant.value;
98
99
  }
99
100
  else {
100
101
  if (this.type === undefined) {
101
102
  this.logError('parameter-missing-default-or-type', 'Parameter must have default value or declared type');
103
+ paramReturn.type = 'error';
102
104
  }
103
- paramReturn = { value: null, name: this.name, type: (_a = this.type) !== null && _a !== void 0 ? _a : 'error' };
104
- }
105
- if (paramReturn.type === 'filter expression' && this.filterType) {
106
- paramReturn.filterType = this.filterType;
107
105
  }
108
106
  return paramReturn;
109
107
  }
@@ -264,35 +264,30 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
264
264
  getSourceParameter(pcx) {
265
265
  const name = (0, parse_utils_1.getId)(pcx.parameterNameDef());
266
266
  let pType;
267
- let filterType;
268
267
  const typeCx = pcx.legalParamType();
269
268
  if (typeCx) {
270
- const fTypeCx = typeCx.malloyType();
271
- if (fTypeCx) {
272
- const t = this.getMalloyType(fTypeCx);
269
+ const t = this.getMalloyType(typeCx.malloyType());
270
+ if (typeCx.FILTER()) {
273
271
  if ((0, malloy_filter_1.isFilterable)(t)) {
274
- filterType = t;
272
+ pType = { type: 'filter expression', filterType: t };
275
273
  }
276
274
  else {
277
275
  this.contextError(typeCx, 'parameter-illegal-default-type', `Unknown filter type ${t}`);
278
276
  }
279
277
  }
280
- const parseType = typeCx.FILTER()
281
- ? 'filter expression'
282
- : typeCx.text.toLowerCase();
283
- if (!(0, malloy_types_1.isParameterType)(parseType)) {
284
- this.contextError(typeCx, 'parameter-illegal-default-type', `Unknown parameter type ${parseType}`);
285
- return null;
278
+ else if ((0, malloy_types_1.isParameterType)(t)) {
279
+ pType = { type: t };
280
+ }
281
+ else {
282
+ this.contextError(typeCx, 'parameter-illegal-default-type', `Unknown parameter type ${t}`);
286
283
  }
287
- pType = parseType;
288
284
  }
289
285
  const defaultCx = pcx.fieldExpr();
290
286
  let defVal;
291
287
  if (defaultCx) {
292
- const defaultExpr = new ast.ConstantExpression(this.getFieldExpr(defaultCx));
293
- defVal = this.astAt(defaultExpr, defaultCx);
288
+ defVal = this.astAt(new ast.ConstantExpression(this.getFieldExpr(defaultCx)), defaultCx);
294
289
  }
295
- return this.astAt(new ast.HasParameter({ name, type: pType, default: defVal, filterType }), pcx);
290
+ return this.astAt(new ast.HasParameter({ name, typeDef: pType, default: defVal }), pcx);
296
291
  }
297
292
  getSourceParameters(pcx) {
298
293
  if (pcx === undefined)
@@ -269,13 +269,13 @@ interface ParameterInfo {
269
269
  name: string;
270
270
  value: ConstantExpr | null;
271
271
  }
272
- export interface FilterExpressionDef {
272
+ interface FilterExpressionParamTypeDef {
273
273
  type: 'filter expression';
274
- filterType?: FilterExprType;
274
+ filterType: FilterExprType;
275
275
  }
276
- export type ParameterType = CastType | 'filter expression';
276
+ export type ParameterType = 'string' | 'number' | 'boolean' | 'date' | 'timestamp' | 'filter expression' | 'error';
277
277
  export declare function isParameterType(t: string): t is ParameterType;
278
- export type ParameterTypeDef = AtomicTypeDef | FilterExpressionDef;
278
+ export type ParameterTypeDef = StringTypeDef | NumberTypeDef | BooleanTypeDef | TemporalTypeDef | FilterExpressionParamTypeDef | ErrorTypeDef;
279
279
  export type Parameter = ParameterTypeDef & ParameterInfo;
280
280
  export type Argument = Parameter;
281
281
  export declare function paramHasValue(p: Parameter): boolean;
@@ -76,7 +76,15 @@ function isFilterExprType(s) {
76
76
  }
77
77
  exports.isFilterExprType = isFilterExprType;
78
78
  function isParameterType(t) {
79
- return isCastType(t) || t === 'filter expression';
79
+ return [
80
+ 'string',
81
+ 'number',
82
+ 'boolean',
83
+ 'date',
84
+ 'timestamp',
85
+ 'filter expression',
86
+ 'error',
87
+ ].includes(t);
80
88
  }
81
89
  exports.isParameterType = isParameterType;
82
90
  function paramHasValue(p) {
package/dist/to_stable.js CHANGED
@@ -31,7 +31,12 @@ function modelDefToModelInfo(modelDef) {
31
31
  }
32
32
  return {
33
33
  name,
34
- type: { kind: 'filter_expression_type' },
34
+ type: {
35
+ kind: 'filter_expression_type',
36
+ filter_type: {
37
+ kind: `${parameter.filterType}_type`,
38
+ },
39
+ },
35
40
  default_value: convertParameterDefaultValue(parameter.value),
36
41
  };
37
42
  })
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const MALLOY_VERSION = "0.0.276";
1
+ export declare const MALLOY_VERSION = "0.0.278";
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.276';
5
+ exports.MALLOY_VERSION = '0.0.278';
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.276",
3
+ "version": "0.0.278",
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.276",
45
- "@malloydata/malloy-interfaces": "0.0.276",
46
- "@malloydata/malloy-tag": "0.0.276",
44
+ "@malloydata/malloy-filter": "0.0.278",
45
+ "@malloydata/malloy-interfaces": "0.0.278",
46
+ "@malloydata/malloy-tag": "0.0.278",
47
47
  "antlr4ts": "^0.5.0-alpha.4",
48
48
  "assert": "^2.0.0",
49
49
  "jaro-winkler": "^0.2.8",