@malloydata/malloy 0.0.392 → 0.0.393

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.
@@ -4,9 +4,6 @@ import type { DocStatement, Document } from '../types/malloy-element';
4
4
  import { DocStatementList, MalloyElement } from '../types/malloy-element';
5
5
  import type { Noteable } from '../types/noteable';
6
6
  import { extendNoteMethod } from '../types/noteable';
7
- /**
8
- * One named given declaration: `NAME :: TYPE [is EXPR]`.
9
- */
10
7
  export declare class GivenDeclaration extends MalloyElement implements DocStatement, Noteable {
11
8
  readonly name: string;
12
9
  readonly typeDef: GivenTypeDef;
@@ -19,9 +16,6 @@ export declare class GivenDeclaration extends MalloyElement implements DocStatem
19
16
  protected varInfo(): string;
20
17
  execute(doc: Document): void;
21
18
  }
22
- /**
23
- * Top-level `given:` block — a sequence of given declarations.
24
- */
25
19
  export declare class DefineGivens extends DocStatementList {
26
20
  elementType: string;
27
21
  readonly givens: GivenDeclaration[];
@@ -11,20 +11,15 @@ const utils_1 = require("../../../model/utils");
11
11
  const expression_def_1 = require("../types/expression-def");
12
12
  const malloy_element_1 = require("../types/malloy-element");
13
13
  const noteable_1 = require("../types/noteable");
14
- /**
15
- * True when exactly one of `declared` and `constVal` is filter-typed.
16
- * Catches `filter<T>` declared with a non-filter default (and vice versa)
17
- * at definition time. Inner-content validation of `filter<T>` defaults
18
- * (syntax + compatibility with `T`) is the filter machinery's job at the
19
- * use site; we don't try to do it here.
20
- */
14
+ // `filter<T>` defaults can't be type-checked via TD.eq — the filter
15
+ // expression value shape doesn't match an atomic typeDef. Catch only
16
+ // the gross kind mismatch here; inner-content validation (filter
17
+ // syntax + T compatibility) belongs to the filter machinery at use
18
+ // site.
21
19
  function filterTypeMismatch(declared, constVal) {
22
20
  return ((declared.type === 'filter expression') !==
23
21
  (constVal.type === 'filter expression'));
24
22
  }
25
- /**
26
- * One named given declaration: `NAME :: TYPE [is EXPR]`.
27
- */
28
23
  class GivenDeclaration extends malloy_element_1.MalloyElement {
29
24
  constructor(name, typeDef, defaultExpr) {
30
25
  super();
@@ -42,7 +37,7 @@ class GivenDeclaration extends malloy_element_1.MalloyElement {
42
37
  return ` ${this.name} :: ${(0, utils_1.typeDefToString)(this.typeDef)}`;
43
38
  }
44
39
  execute(doc) {
45
- var _a, _b, _c, _d;
40
+ var _a, _b, _c, _d, _e;
46
41
  if (this.typeDef.type === 'error')
47
42
  return;
48
43
  if (doc.modelEntry(this.name)) {
@@ -60,11 +55,19 @@ class GivenDeclaration extends malloy_element_1.MalloyElement {
60
55
  if (this.default) {
61
56
  const constVal = this.default.constantValue();
62
57
  if (constVal.type !== 'error') {
58
+ // `X :: timestamp is @2024-01-01` works because date literals
59
+ // carry a morphic.timestamp. Date/timestamp are the only
60
+ // MorphicType targets — other declared types fall through to
61
+ // the TD.eq check below.
62
+ const morphed = this.typeDef.type === 'date' || this.typeDef.type === 'timestamp'
63
+ ? (0, expression_def_1.getMorphicValue)(constVal, this.typeDef.type)
64
+ : undefined;
63
65
  // `filter<T>` defaults are filter-expression literals — their
64
66
  // shape doesn't match an atomic typeDef, so type-check there is
65
67
  // owned by the filter machinery, not us. `null` is implicitly
66
68
  // accepted for any declared type.
67
69
  if (constVal.type !== 'null' &&
70
+ morphed === undefined &&
68
71
  (filterTypeMismatch(this.typeDef, constVal) ||
69
72
  !malloy_types_1.TD.eq(this.typeDef, constVal))) {
70
73
  const actual = malloy_types_1.TD.isAtomic(constVal)
@@ -79,7 +82,7 @@ class GivenDeclaration extends malloy_element_1.MalloyElement {
79
82
  // again at use site. Catches bad filter syntax early.
80
83
  (0, expression_def_1.checkFilterExpression)(this.default, this.typeDef.filterType, constVal.value);
81
84
  }
82
- defaultExpr = constVal.value;
85
+ defaultExpr = (_a = morphed === null || morphed === void 0 ? void 0 : morphed.value) !== null && _a !== void 0 ? _a : constVal.value;
83
86
  // Build the transitive closure of givens reachable through this
84
87
  // default's expression. We only include direct refs PLUS each
85
88
  // referenced given's already-precomputed transitive (which is
@@ -100,7 +103,7 @@ class GivenDeclaration extends malloy_element_1.MalloyElement {
100
103
  seen.add(g.id);
101
104
  closure.push(g);
102
105
  const refDecl = doc.documentGivens.get(g.id);
103
- for (const t of (_a = refDecl === null || refDecl === void 0 ? void 0 : refDecl.givenUsage) !== null && _a !== void 0 ? _a : []) {
106
+ for (const t of (_b = refDecl === null || refDecl === void 0 ? void 0 : refDecl.givenUsage) !== null && _b !== void 0 ? _b : []) {
104
107
  if (seen.has(t.id))
105
108
  continue;
106
109
  seen.add(t.id);
@@ -111,8 +114,8 @@ class GivenDeclaration extends malloy_element_1.MalloyElement {
111
114
  }
112
115
  }
113
116
  }
114
- const id = (0, source_def_utils_1.mkGivenID)(this.name, (_b = this.location) === null || _b === void 0 ? void 0 : _b.url);
115
- const defaultText = defaultExpr !== undefined ? (_c = this.default) === null || _c === void 0 ? void 0 : _c.code : undefined;
117
+ const id = (0, source_def_utils_1.mkGivenID)(this.name, (_c = this.location) === null || _c === void 0 ? void 0 : _c.url);
118
+ const defaultText = defaultExpr !== undefined ? (_d = this.default) === null || _d === void 0 ? void 0 : _d.code : undefined;
116
119
  const givenIR = {
117
120
  name: this.name,
118
121
  type: this.typeDef,
@@ -132,7 +135,7 @@ class GivenDeclaration extends malloy_element_1.MalloyElement {
132
135
  this.addReference({
133
136
  type: 'givenReference',
134
137
  text: this.name,
135
- location: (_d = this.location) !== null && _d !== void 0 ? _d : {
138
+ location: (_e = this.location) !== null && _e !== void 0 ? _e : {
136
139
  url: '',
137
140
  range: {
138
141
  start: { line: 0, character: 0 },
@@ -149,9 +152,6 @@ class GivenDeclaration extends malloy_element_1.MalloyElement {
149
152
  }
150
153
  }
151
154
  exports.GivenDeclaration = GivenDeclaration;
152
- /**
153
- * Top-level `given:` block — a sequence of given declarations.
154
- */
155
155
  class DefineGivens extends malloy_element_1.DocStatementList {
156
156
  constructor(givens) {
157
157
  super(givens);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const MALLOY_VERSION = "0.0.392";
1
+ export declare const MALLOY_VERSION = "0.0.393";
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.392';
5
+ exports.MALLOY_VERSION = '0.0.393';
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.392",
3
+ "version": "0.0.393",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -51,9 +51,9 @@
51
51
  "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"
52
52
  },
53
53
  "dependencies": {
54
- "@malloydata/malloy-filter": "0.0.392",
55
- "@malloydata/malloy-interfaces": "0.0.392",
56
- "@malloydata/malloy-tag": "0.0.392",
54
+ "@malloydata/malloy-filter": "0.0.393",
55
+ "@malloydata/malloy-interfaces": "0.0.393",
56
+ "@malloydata/malloy-tag": "0.0.393",
57
57
  "@noble/hashes": "^1.8.0",
58
58
  "antlr4ts": "^0.5.0-alpha.4",
59
59
  "assert": "^2.0.0",