@malloydata/malloy 0.0.205-dev241028163321 → 0.0.205-dev241028192658

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 (88) hide show
  1. package/dist/dialect/functions/util.d.ts +16 -16
  2. package/dist/dialect/functions/util.js +16 -48
  3. package/dist/index.d.ts +1 -1
  4. package/dist/lang/ast/ast-utils.js +1 -1
  5. package/dist/lang/ast/expressions/binary-boolean.js +27 -4
  6. package/dist/lang/ast/expressions/binary-numeric.js +25 -2
  7. package/dist/lang/ast/expressions/boolean.js +25 -2
  8. package/dist/lang/ast/expressions/case.js +41 -20
  9. package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +2 -2
  10. package/dist/lang/ast/expressions/expr-aggregate-function.js +30 -10
  11. package/dist/lang/ast/expressions/expr-alternation-tree.js +2 -2
  12. package/dist/lang/ast/expressions/expr-asymmetric.d.ts +2 -0
  13. package/dist/lang/ast/expressions/expr-asymmetric.js +3 -0
  14. package/dist/lang/ast/expressions/expr-cast.js +4 -6
  15. package/dist/lang/ast/expressions/expr-coalesce.js +30 -7
  16. package/dist/lang/ast/expressions/expr-compare.js +33 -10
  17. package/dist/lang/ast/expressions/expr-count-distinct.d.ts +2 -0
  18. package/dist/lang/ast/expressions/expr-count-distinct.js +34 -2
  19. package/dist/lang/ast/expressions/expr-count.d.ts +1 -0
  20. package/dist/lang/ast/expressions/expr-count.js +11 -1
  21. package/dist/lang/ast/expressions/expr-func.d.ts +3 -3
  22. package/dist/lang/ast/expressions/expr-func.js +41 -15
  23. package/dist/lang/ast/expressions/expr-granular-time.js +36 -14
  24. package/dist/lang/ast/expressions/expr-logical-op.js +25 -2
  25. package/dist/lang/ast/expressions/expr-max.d.ts +3 -4
  26. package/dist/lang/ast/expressions/expr-max.js +27 -4
  27. package/dist/lang/ast/expressions/expr-min.d.ts +3 -4
  28. package/dist/lang/ast/expressions/expr-min.js +27 -4
  29. package/dist/lang/ast/expressions/expr-minus.js +27 -4
  30. package/dist/lang/ast/expressions/expr-not.js +26 -3
  31. package/dist/lang/ast/expressions/expr-now.js +1 -1
  32. package/dist/lang/ast/expressions/expr-null.js +1 -1
  33. package/dist/lang/ast/expressions/expr-number.js +5 -1
  34. package/dist/lang/ast/expressions/expr-props.js +25 -2
  35. package/dist/lang/ast/expressions/expr-regex.js +1 -1
  36. package/dist/lang/ast/expressions/expr-string.js +1 -1
  37. package/dist/lang/ast/expressions/expr-time-extract.js +18 -18
  38. package/dist/lang/ast/expressions/expr-time.js +4 -4
  39. package/dist/lang/ast/expressions/expr-ungroup.d.ts +0 -2
  40. package/dist/lang/ast/expressions/expr-ungroup.js +26 -6
  41. package/dist/lang/ast/expressions/for-range.js +32 -9
  42. package/dist/lang/ast/expressions/pick-when.js +46 -25
  43. package/dist/lang/ast/expressions/range.js +1 -1
  44. package/dist/lang/ast/expressions/time-literal.js +9 -4
  45. package/dist/lang/ast/field-space/index-field-space.js +1 -3
  46. package/dist/lang/ast/field-space/project-field-space.d.ts +1 -1
  47. package/dist/lang/ast/field-space/project-field-space.js +2 -1
  48. package/dist/lang/ast/field-space/query-spaces.d.ts +1 -1
  49. package/dist/lang/ast/field-space/query-spaces.js +4 -3
  50. package/dist/lang/ast/field-space/reference-field.js +43 -10
  51. package/dist/lang/ast/field-space/rename-space-field.d.ts +2 -2
  52. package/dist/lang/ast/field-space/static-space.js +1 -1
  53. package/dist/lang/ast/field-space/struct-space-field-base.d.ts +2 -2
  54. package/dist/lang/ast/field-space/struct-space-field-base.js +40 -8
  55. package/dist/lang/ast/field-space/view-field.d.ts +2 -2
  56. package/dist/lang/ast/field-space/view-field.js +25 -1
  57. package/dist/lang/ast/parameters/has-parameter.d.ts +1 -1
  58. package/dist/lang/ast/parameters/has-parameter.js +8 -8
  59. package/dist/lang/ast/query-items/field-declaration.d.ts +2 -1
  60. package/dist/lang/ast/query-items/field-declaration.js +34 -9
  61. package/dist/lang/ast/query-items/typecheck_utils.js +11 -13
  62. package/dist/lang/ast/query-properties/filters.js +1 -1
  63. package/dist/lang/ast/source-elements/named-source.js +2 -2
  64. package/dist/lang/ast/source-properties/join.js +3 -3
  65. package/dist/lang/ast/time-utils.d.ts +2 -2
  66. package/dist/lang/ast/time-utils.js +6 -1
  67. package/dist/lang/ast/typedesc-utils.d.ts +48 -0
  68. package/dist/lang/ast/typedesc-utils.js +157 -0
  69. package/dist/lang/ast/types/expr-result.d.ts +2 -1
  70. package/dist/lang/ast/types/expr-value.d.ts +11 -36
  71. package/dist/lang/ast/types/expr-value.js +27 -13
  72. package/dist/lang/ast/types/expression-def.d.ts +3 -2
  73. package/dist/lang/ast/types/expression-def.js +84 -60
  74. package/dist/lang/ast/types/global-name-space.js +2 -2
  75. package/dist/lang/ast/types/granular-result.d.ts +2 -2
  76. package/dist/lang/ast/types/granular-result.js +1 -1
  77. package/dist/lang/ast/types/space-field.js +2 -13
  78. package/dist/lang/ast/types/space-param.d.ts +3 -1
  79. package/dist/lang/ast/types/space-param.js +36 -4
  80. package/dist/lang/ast/types/time-result.d.ts +3 -4
  81. package/dist/lang/parse-log.d.ts +15 -15
  82. package/dist/lang/test/literals.spec.js +1 -1
  83. package/dist/lang/test/parse-expects.js +2 -2
  84. package/dist/model/malloy_types.d.ts +30 -32
  85. package/dist/model/malloy_types.js +25 -16
  86. package/package.json +1 -1
  87. package/dist/lang/ast/fragtype-utils.d.ts +0 -46
  88. package/dist/lang/ast/fragtype-utils.js +0 -115
@@ -120,10 +120,8 @@ class IndexFieldSpace extends query_spaces_1.QueryOperationSpace {
120
120
  }
121
121
  else {
122
122
  const eTypeDesc = entry.typeDesc();
123
- const eType = eTypeDesc.dataType;
124
123
  // Don't index arrays and records
125
- const canIndex = (0, malloy_types_1.isAtomicFieldType)(eType) && eType !== 'record' && eType !== 'array';
126
- if (canIndex &&
124
+ if (malloy_types_1.TD.isLeafAtomic(eTypeDesc) &&
127
125
  (0, malloy_types_1.expressionIsScalar)(eTypeDesc.expressionType) &&
128
126
  (dialect === undefined || !dialect.ignoreInProject(name))) {
129
127
  expandEntries.push({ name: indexName, entry });
@@ -2,5 +2,5 @@ import { TypeDesc } from '../../../model/malloy_types';
2
2
  import { QuerySpace } from './query-spaces';
3
3
  export declare class ProjectFieldSpace extends QuerySpace {
4
4
  readonly segmentType = "project";
5
- canContain(typeDesc: TypeDesc): boolean;
5
+ canContain(typeDesc: TypeDesc | undefined): boolean;
6
6
  }
@@ -31,7 +31,8 @@ class ProjectFieldSpace extends query_spaces_1.QuerySpace {
31
31
  this.segmentType = 'project';
32
32
  }
33
33
  canContain(typeDesc) {
34
- if (typeDesc.dataType === 'turtle' ||
34
+ if (typeDesc === undefined ||
35
+ !malloy_types_1.TD.isLeafAtomic(typeDesc) ||
35
36
  (0, malloy_types_1.expressionIsAggregate)(typeDesc.expressionType)) {
36
37
  // We don't need to log here, because an error should have already been logged.
37
38
  return false;
@@ -29,7 +29,7 @@ export declare abstract class QueryOperationSpace extends RefinedSpace implement
29
29
  export declare abstract class QuerySpace extends QueryOperationSpace {
30
30
  addRefineFromFields(refineThis: model.PipeSegment): void;
31
31
  pushFields(...defs: MalloyElement[]): void;
32
- canContain(_typeDesc: model.TypeDesc): boolean;
32
+ canContain(_typeDescResult: model.TypeDesc | undefined): boolean;
33
33
  protected queryFieldDefs(): model.QueryFieldDef[];
34
34
  getQuerySegment(rf: model.QuerySegment | undefined): model.QuerySegment;
35
35
  getPipeSegment(refineFrom: model.QuerySegment | undefined): model.PipeSegment;
@@ -124,7 +124,7 @@ class QueryOperationSpace extends refined_space_1.RefinedSpace {
124
124
  }
125
125
  else {
126
126
  const eType = entry.typeDesc();
127
- if (model.isAtomicFieldType(eType.dataType) &&
127
+ if (model.TD.isAtomic(eType) &&
128
128
  model.expressionIsScalar(eType.expressionType) &&
129
129
  (dialect === undefined || !dialect.ignoreInProject(name))) {
130
130
  expandEntries.push({ name, entry });
@@ -171,7 +171,7 @@ class QuerySpace extends QueryOperationSpace {
171
171
  }
172
172
  }
173
173
  }
174
- canContain(_typeDesc) {
174
+ canContain(_typeDescResult) {
175
175
  return true;
176
176
  }
177
177
  queryFieldDefs() {
@@ -190,7 +190,8 @@ class QuerySpace extends QueryOperationSpace {
190
190
  // isn't sent to the compiler, where it will wig out.
191
191
  // TODO Figure out how to make errors generated by `canContain` go in the right place,
192
192
  // maybe by adding a logable element to SpaceFields.
193
- if (typeDesc.dataType !== 'error' &&
193
+ if (typeDesc &&
194
+ typeDesc.type !== 'error' &&
194
195
  this.canContain(typeDesc) &&
195
196
  !isEmptyNest(fieldQueryDef)) {
196
197
  fields.push(fieldQueryDef);
@@ -21,8 +21,33 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.ReferenceField = void 0;
49
+ const malloy_types_1 = require("../../../model/malloy_types");
50
+ const TDU = __importStar(require("../typedesc-utils"));
26
51
  const space_field_1 = require("../types/space-field");
27
52
  class ReferenceField extends space_field_1.SpaceField {
28
53
  constructor(fieldRef, inFS) {
@@ -39,7 +64,6 @@ class ReferenceField extends space_field_1.SpaceField {
39
64
  return this.memoReference;
40
65
  }
41
66
  getQueryFieldDef(fs) {
42
- var _a;
43
67
  if (!this.queryFieldDef) {
44
68
  const check = this.fieldRef.getField(fs);
45
69
  if (check.error) {
@@ -48,15 +72,24 @@ class ReferenceField extends space_field_1.SpaceField {
48
72
  // TODO investigate removing 'fieldref' as a type, as it obscures the
49
73
  // actual type of the field and is redundant with the slightly
50
74
  // 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: { node: 'parameter', path },
75
+ const path = this.fieldRef.path;
76
+ if (check.found && check.found.refType === 'parameter') {
77
+ const foundType = check.found.typeDesc();
78
+ if (malloy_types_1.TD.isAtomic(foundType)) {
79
+ this.queryFieldDef = {
80
+ ...TDU.atomicDef(foundType),
81
+ name: path[0],
82
+ e: { node: 'parameter', path },
83
+ };
84
+ }
85
+ else {
86
+ // mtoy todo
87
+ throw new Error('impossible turtle/join parameter');
57
88
  }
58
- : { type: 'fieldref', path };
59
- this.queryFieldDef = queryFieldDef;
89
+ }
90
+ else {
91
+ this.queryFieldDef = { type: 'fieldref', path };
92
+ }
60
93
  const refTo = this.referenceTo;
61
94
  if (refTo instanceof space_field_1.SpaceField) {
62
95
  const origFd = refTo.constructorFieldDef();
@@ -82,7 +115,7 @@ class ReferenceField extends space_field_1.SpaceField {
82
115
  this.memoTypeDesc = refTo.typeDesc();
83
116
  return this.memoTypeDesc;
84
117
  }
85
- return { dataType: 'error', expressionType: 'scalar', evalSpace: 'input' };
118
+ return TDU.errorT;
86
119
  }
87
120
  }
88
121
  exports.ReferenceField = ReferenceField;
@@ -1,4 +1,4 @@
1
- import { DocumentLocation, FieldDef, TypeDesc } from '../../../model/malloy_types';
1
+ import { DocumentLocation, FieldDef } from '../../../model/malloy_types';
2
2
  import { SpaceField } from '../types/space-field';
3
3
  export declare class RenameSpaceField extends SpaceField {
4
4
  private readonly otherField;
@@ -6,5 +6,5 @@ export declare class RenameSpaceField extends SpaceField {
6
6
  private readonly location;
7
7
  constructor(otherField: SpaceField, newName: string, location: DocumentLocation);
8
8
  fieldDef(): FieldDef | undefined;
9
- typeDesc(): TypeDesc;
9
+ typeDesc(): import("../../../model/malloy_types").TypeDesc;
10
10
  }
@@ -167,7 +167,7 @@ class StructSpaceField extends struct_space_field_base_1.StructSpaceFieldBase {
167
167
  this.parentDialect = dialect;
168
168
  }
169
169
  get fieldSpace() {
170
- return new StaticSpace(this.sourceDef);
170
+ return new StaticSpace(this.structDef);
171
171
  }
172
172
  }
173
173
  exports.StructSpaceField = StructSpaceField;
@@ -3,8 +3,8 @@ import { FieldSpace } from '../types/field-space';
3
3
  import { JoinPathElement } from '../types/lookup-result';
4
4
  import { SpaceField } from '../types/space-field';
5
5
  export declare abstract class StructSpaceFieldBase extends SpaceField {
6
- protected sourceDef: JoinFieldDef;
7
- constructor(sourceDef: JoinFieldDef);
6
+ protected structDef: JoinFieldDef;
7
+ constructor(structDef: JoinFieldDef);
8
8
  abstract get fieldSpace(): FieldSpace;
9
9
  fieldDef(): JoinFieldDef;
10
10
  get joinPathElement(): JoinPathElement;
@@ -21,29 +21,61 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.StructSpaceFieldBase = void 0;
49
+ const malloy_types_1 = require("../../../model/malloy_types");
50
+ const TDU = __importStar(require("../typedesc-utils"));
26
51
  const space_field_1 = require("../types/space-field");
27
52
  class StructSpaceFieldBase extends space_field_1.SpaceField {
28
- constructor(sourceDef) {
53
+ constructor(structDef) {
29
54
  super();
30
- this.sourceDef = sourceDef;
55
+ this.structDef = structDef;
31
56
  }
32
57
  fieldDef() {
33
- return this.sourceDef;
58
+ return this.structDef;
34
59
  }
35
60
  get joinPathElement() {
36
61
  return {
37
- name: this.sourceDef.as || this.sourceDef.name,
38
- joinType: this.sourceDef.join,
39
- joinElementType: this.sourceDef.type,
62
+ name: this.structDef.as || this.structDef.name,
63
+ joinType: this.structDef.join,
64
+ joinElementType: this.structDef.type,
40
65
  };
41
66
  }
42
67
  typeDesc() {
68
+ if ((0, malloy_types_1.isSourceDef)(this.structDef)) {
69
+ return {
70
+ type: this.structDef.type,
71
+ evalSpace: 'input',
72
+ expressionType: 'scalar',
73
+ };
74
+ }
43
75
  return {
44
- dataType: this.sourceDef.type,
45
- expressionType: 'scalar',
76
+ ...TDU.atomicDef(this.structDef),
46
77
  evalSpace: 'input',
78
+ expressionType: 'scalar',
47
79
  };
48
80
  }
49
81
  }
@@ -1,4 +1,4 @@
1
- import { FieldDef, QueryFieldDef, TypeDesc } from '../../../model/malloy_types';
1
+ import { FieldDef, QueryFieldDef } from '../../../model/malloy_types';
2
2
  import { FieldSpace } from '../types/field-space';
3
3
  import { SpaceField } from '../types/space-field';
4
4
  export declare abstract class ViewField extends SpaceField {
@@ -6,5 +6,5 @@ export declare abstract class ViewField extends SpaceField {
6
6
  constructor(inSpace: FieldSpace);
7
7
  abstract getQueryFieldDef(fs: FieldSpace): QueryFieldDef | undefined;
8
8
  abstract fieldDef(): FieldDef;
9
- typeDesc(): TypeDesc;
9
+ typeDesc(): import("../../../model/malloy_types").TypeDesc;
10
10
  }
@@ -21,8 +21,32 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.ViewField = void 0;
49
+ const TDU = __importStar(require("../typedesc-utils"));
26
50
  const space_field_1 = require("../types/space-field");
27
51
  class ViewField extends space_field_1.SpaceField {
28
52
  constructor(inSpace) {
@@ -30,7 +54,7 @@ class ViewField extends space_field_1.SpaceField {
30
54
  this.inSpace = inSpace;
31
55
  }
32
56
  typeDesc() {
33
- return { dataType: 'turtle', expressionType: 'scalar', evalSpace: 'input' };
57
+ return TDU.viewT;
34
58
  }
35
59
  }
36
60
  exports.ViewField = ViewField;
@@ -3,7 +3,7 @@ import { ConstantExpression } from '../expressions/constant-expression';
3
3
  import { MalloyElement } from '../types/malloy-element';
4
4
  interface HasInit {
5
5
  name: string;
6
- type?: string;
6
+ type?: CastType;
7
7
  default?: ConstantExpression;
8
8
  }
9
9
  export declare class HasParameter extends MalloyElement {
@@ -43,17 +43,17 @@ class HasParameter extends malloy_element_1.MalloyElement {
43
43
  if (this.default !== undefined) {
44
44
  const constant = this.default.constantValue();
45
45
  if (this.type &&
46
- this.type !== constant.dataType &&
47
- constant.dataType !== 'null' &&
48
- constant.dataType !== 'error') {
46
+ this.type !== constant.type &&
47
+ constant.type !== 'null' &&
48
+ constant.type !== 'error') {
49
49
  this.default.logError('parameter-default-does-not-match-declared-type', `Default value for parameter does not match declared type \`${this.type}\``);
50
50
  }
51
- if (constant.dataType === 'null') {
51
+ if (constant.type === 'null') {
52
52
  if (this.type) {
53
53
  return {
54
+ type: this.type,
54
55
  value: constant.value,
55
56
  name: this.name,
56
- type: this.type,
57
57
  };
58
58
  }
59
59
  else {
@@ -65,8 +65,8 @@ class HasParameter extends malloy_element_1.MalloyElement {
65
65
  };
66
66
  }
67
67
  }
68
- if (!(0, malloy_types_1.isCastType)(constant.dataType) && constant.dataType !== 'error') {
69
- this.default.logError('parameter-illegal-default-type', `Default value cannot have type \`${constant.dataType}\``);
68
+ if (!(0, malloy_types_1.isCastType)(constant.type) && constant.type !== 'error') {
69
+ this.default.logError('parameter-illegal-default-type', `Default value cannot have type \`${constant.type}\``);
70
70
  return {
71
71
  value: constant.value,
72
72
  name: this.name,
@@ -76,7 +76,7 @@ class HasParameter extends malloy_element_1.MalloyElement {
76
76
  return {
77
77
  value: constant.value,
78
78
  name: this.name,
79
- type: constant.dataType,
79
+ type: constant.type,
80
80
  };
81
81
  }
82
82
  if (this.type === undefined) {
@@ -1,5 +1,5 @@
1
1
  import { Dialect } from '../../../dialect/dialect';
2
- import { Annotation, StructDef, TypeDesc, FieldDef, AtomicFieldDef } from '../../../model/malloy_types';
2
+ import { Annotation, StructDef, TypeDesc, FieldDef, AtomicFieldDef, FieldDefType } from '../../../model/malloy_types';
3
3
  import { ExprValue } from '../types/expr-value';
4
4
  import { ExpressionDef } from '../types/expression-def';
5
5
  import { FieldName, FieldSpace, QueryFieldSpace } from '../types/field-space';
@@ -84,4 +84,5 @@ export declare class FieldDefinitionValue extends SpaceField {
84
84
  private defInQuery?;
85
85
  getQueryFieldDef(fs: FieldSpace): AtomicFieldDef;
86
86
  typeDesc(): TypeDesc;
87
+ entryType(): FieldDefType;
87
88
  }
@@ -21,10 +21,33 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
24
47
  Object.defineProperty(exports, "__esModule", { value: true });
25
48
  exports.FieldDefinitionValue = exports.DefSpace = exports.DimensionFieldDeclaration = exports.MeasureFieldDeclaration = exports.DeclareFieldDeclaration = exports.ProjectFieldDeclaration = exports.GroupByFieldDeclaration = exports.AggregateFieldDeclaration = exports.CalculateFieldDeclaration = exports.AtomicFieldDeclaration = void 0;
26
49
  const malloy_types_1 = require("../../../model/malloy_types");
27
- const fragtype_utils_1 = require("../fragtype-utils");
50
+ const TDU = __importStar(require("../typedesc-utils"));
28
51
  const granular_result_1 = require("../types/granular-result");
29
52
  const malloy_element_1 = require("../types/malloy-element");
30
53
  const typecheck_utils_1 = require("./typecheck_utils");
@@ -73,7 +96,7 @@ class AtomicFieldDeclaration extends malloy_element_1.MalloyElement {
73
96
  type: 'error',
74
97
  };
75
98
  }
76
- let retType = exprValue.dataType;
99
+ let retType = exprValue.type;
77
100
  if (retType === 'null') {
78
101
  this.expr.logWarning('null-typed-field-definition', 'null value defaults to type number, use "null::TYPE" to specify correct type');
79
102
  retType = 'number';
@@ -138,8 +161,8 @@ class AtomicFieldDeclaration extends malloy_element_1.MalloyElement {
138
161
  }
139
162
  const circularDef = exprFS instanceof DefSpace && exprFS.foundCircle;
140
163
  if (!circularDef) {
141
- if (exprValue.dataType !== 'error') {
142
- const badType = fragtype_utils_1.FT.inspect(exprValue);
164
+ if (exprValue.type !== 'error') {
165
+ const badType = TDU.inspect(exprValue);
143
166
  this.logError('invalid-type-for-field-definition', `Cannot define '${exprName}', unexpected type: ${badType}`);
144
167
  }
145
168
  }
@@ -295,11 +318,9 @@ class FieldDefinitionValue extends space_field_1.SpaceField {
295
318
  return this.fieldName;
296
319
  }
297
320
  fieldDef() {
298
- let def = this.defInSource;
299
- if (def === undefined) {
300
- this.defInSource = def;
301
- def = this.exprDef.fieldDef(this.space, this.name);
302
- }
321
+ var _a;
322
+ const def = (_a = this.defInSource) !== null && _a !== void 0 ? _a : this.exprDef.fieldDef(this.space, this.name);
323
+ this.defInSource = def;
303
324
  return def;
304
325
  }
305
326
  getQueryFieldDef(fs) {
@@ -320,6 +341,10 @@ class FieldDefinitionValue extends space_field_1.SpaceField {
320
341
  }
321
342
  throw new Error(`Can't get typeDesc for ${typeFrom.type}`);
322
343
  }
344
+ entryType() {
345
+ const typeFrom = this.defInQuery || this.fieldDef();
346
+ return typeFrom.type;
347
+ }
323
348
  }
324
349
  exports.FieldDefinitionValue = FieldDefinitionValue;
325
350
  //# sourceMappingURL=field-declaration.js.map
@@ -25,11 +25,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.typecheckGroupBy = exports.typecheckAggregate = exports.typecheckCalculate = exports.typecheckDeclare = exports.typecheckMeasure = exports.typecheckDimension = exports.typecheckIndex = exports.typecheckProject = void 0;
26
26
  const model_1 = require("../../../model");
27
27
  function typecheckProject(type, logTo) {
28
- if (type.dataType === 'turtle' || !(0, model_1.expressionIsScalar)(type.expressionType)) {
28
+ if (type.type === 'turtle' || !(0, model_1.expressionIsScalar)(type.expressionType)) {
29
29
  let useInstead;
30
30
  let kind;
31
31
  let code;
32
- if (type.dataType === 'turtle') {
32
+ if (type.type === 'turtle') {
33
33
  useInstead = 'a nest';
34
34
  kind = 'a view';
35
35
  code = 'select-of-view';
@@ -52,10 +52,10 @@ function typecheckProject(type, logTo) {
52
52
  }
53
53
  exports.typecheckProject = typecheckProject;
54
54
  function typecheckIndex(type, logTo) {
55
- if (type.dataType === 'turtle' || !(0, model_1.expressionIsScalar)(type.expressionType)) {
55
+ if (type.type === 'turtle' || !(0, model_1.expressionIsScalar)(type.expressionType)) {
56
56
  let kind;
57
57
  let code;
58
- if (type.dataType === 'turtle') {
58
+ if (type.type === 'turtle') {
59
59
  kind = 'a view';
60
60
  code = 'index-of-view';
61
61
  }
@@ -103,7 +103,7 @@ function typecheckMeasure(type, logTo) {
103
103
  }
104
104
  exports.typecheckMeasure = typecheckMeasure;
105
105
  function typecheckDeclare(type, logTo) {
106
- if (type.dataType === 'turtle') {
106
+ if (type.type === 'turtle') {
107
107
  logTo.logError('view-in-declare', 'Views cannot be used in a declare block');
108
108
  }
109
109
  else if ((0, model_1.expressionIsAnalytic)(type.expressionType)) {
@@ -112,12 +112,11 @@ function typecheckDeclare(type, logTo) {
112
112
  }
113
113
  exports.typecheckDeclare = typecheckDeclare;
114
114
  function typecheckCalculate(type, logTo) {
115
- if (type.dataType === 'turtle' ||
116
- !(0, model_1.expressionIsAnalytic)(type.expressionType)) {
115
+ if (type.type === 'turtle' || !(0, model_1.expressionIsAnalytic)(type.expressionType)) {
117
116
  let useInstead;
118
117
  let kind;
119
118
  let code;
120
- if (type.dataType === 'turtle') {
119
+ if (type.type === 'turtle') {
121
120
  useInstead = 'a nest';
122
121
  kind = 'a view';
123
122
  code = 'calculate-of-view';
@@ -140,12 +139,11 @@ function typecheckCalculate(type, logTo) {
140
139
  }
141
140
  exports.typecheckCalculate = typecheckCalculate;
142
141
  function typecheckAggregate(type, logTo) {
143
- if (type.dataType === 'turtle' ||
144
- !(0, model_1.expressionIsAggregate)(type.expressionType)) {
142
+ if (type.type === 'turtle' || !(0, model_1.expressionIsAggregate)(type.expressionType)) {
145
143
  let useInstead;
146
144
  let kind;
147
145
  let code;
148
- if (type.dataType === 'turtle') {
146
+ if (type.type === 'turtle') {
149
147
  useInstead = 'a nest';
150
148
  kind = 'a view';
151
149
  code = 'aggregate-of-view';
@@ -168,11 +166,11 @@ function typecheckAggregate(type, logTo) {
168
166
  }
169
167
  exports.typecheckAggregate = typecheckAggregate;
170
168
  function typecheckGroupBy(type, logTo) {
171
- if (type.dataType === 'turtle' || !(0, model_1.expressionIsScalar)(type.expressionType)) {
169
+ if (type.type === 'turtle' || !(0, model_1.expressionIsScalar)(type.expressionType)) {
172
170
  let useInstead;
173
171
  let kind;
174
172
  let code;
175
- if (type.dataType === 'turtle') {
173
+ if (type.type === 'turtle') {
176
174
  useInstead = 'a nest';
177
175
  kind = 'a view';
178
176
  code = 'group-by-view';
@@ -35,7 +35,7 @@ class FilterElement extends malloy_element_1.MalloyElement {
35
35
  }
36
36
  filterCondition(fs) {
37
37
  const exprVal = this.expr.getExpression(fs);
38
- if (exprVal.dataType !== 'boolean') {
38
+ if (exprVal.type !== 'boolean') {
39
39
  this.expr.logError('non-boolean-filter', 'Filter expression must have boolean value');
40
40
  return {
41
41
  node: 'filterCondition',
@@ -139,8 +139,8 @@ class NamedSource extends source_1.Source {
139
139
  const paramSpace = parameterSpace !== null && parameterSpace !== void 0 ? parameterSpace : new parameter_space_1.ParameterSpace(parametersOut !== null && parametersOut !== void 0 ? parametersOut : []);
140
140
  const pVal = argument.value.getExpression(paramSpace);
141
141
  let value = pVal.value;
142
- if (pVal.dataType !== parameter.type && (0, malloy_types_1.isCastType)(parameter.type)) {
143
- value = (0, time_utils_1.castTo)(parameter.type, pVal.value, pVal.dataType, true);
142
+ if (pVal.type !== parameter.type && (0, malloy_types_1.isCastType)(parameter.type)) {
143
+ value = (0, time_utils_1.castTo)(parameter.type, pVal.value, pVal.type, true);
144
144
  }
145
145
  outArguments[name] = {
146
146
  ...parameter,
@@ -83,7 +83,7 @@ class KeyJoin extends Join {
83
83
  if ((0, malloy_types_1.isSourceDef)(inStruct) && inStruct.primaryKey) {
84
84
  const pkey = inStruct.fields.find(f => (f.as || f.name) === inStruct.primaryKey);
85
85
  if (pkey) {
86
- if (pkey.type === exprX.dataType) {
86
+ if (pkey.type === exprX.type) {
87
87
  inStruct.join = 'one';
88
88
  inStruct.onExpression = {
89
89
  node: '=',
@@ -98,7 +98,7 @@ class KeyJoin extends Join {
98
98
  return;
99
99
  }
100
100
  else {
101
- this.logError('join-on-primary-key-type-mismatch', `join_one: with type mismatch with primary key: ${exprX.dataType}/${pkey.type}`);
101
+ this.logError('join-on-primary-key-type-mismatch', `join_one: with type mismatch with primary key: ${exprX.type}/${pkey.type}`);
102
102
  }
103
103
  }
104
104
  else {
@@ -132,7 +132,7 @@ class ExpressionJoin extends Join {
132
132
  return;
133
133
  }
134
134
  const exprX = this.expr.getExpression(outer);
135
- if (exprX.dataType !== 'boolean') {
135
+ if (exprX.type !== 'boolean') {
136
136
  this.logError('non-boolean-join-on', 'join conditions must be boolean expressions');
137
137
  return;
138
138
  }
@@ -1,8 +1,8 @@
1
- import { Expr, TemporalFieldType, TimestampUnit, FieldValueType, CastType, TypecastExpr, TimeDeltaExpr } from '../../model/malloy_types';
1
+ import { Expr, TemporalFieldType, TimestampUnit, CastType, TypecastExpr, TimeDeltaExpr, ExpressionValueType } from '../../model/malloy_types';
2
2
  import { TimeResult } from './types/time-result';
3
3
  export declare function timeOffset(timeType: TemporalFieldType, from: Expr, op: '+' | '-', n: Expr, timeframe: TimestampUnit): TimeDeltaExpr;
4
4
  export declare function castTo(castType: CastType | {
5
5
  raw: string;
6
- }, from: Expr, fromType: FieldValueType, safe?: boolean): TypecastExpr;
6
+ }, from: Expr, fromType: ExpressionValueType, safe?: boolean): TypecastExpr;
7
7
  export declare function resolution(timeframe: string): TemporalFieldType;
8
8
  export declare function mkTimeResult(t: TimeResult, tt: TimestampUnit | undefined): TimeResult;
@@ -75,7 +75,12 @@ function resolution(timeframe) {
75
75
  exports.resolution = resolution;
76
76
  function mkTimeResult(t, tt) {
77
77
  if (tt) {
78
- return { ...t, timeframe: tt };
78
+ if (t.type === 'timestamp') {
79
+ return { ...t, timeframe: tt };
80
+ }
81
+ if ((0, malloy_types_1.isDateUnit)(tt)) {
82
+ return { ...t, timeframe: tt };
83
+ }
79
84
  }
80
85
  return t;
81
86
  }