@malloydata/malloy 0.0.326 → 0.0.327

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 (51) hide show
  1. package/dist/api/core.js +2 -0
  2. package/dist/api/index.d.ts +1 -0
  3. package/dist/api/index.js +1 -0
  4. package/dist/api/row_data_utils.d.ts +30 -0
  5. package/dist/api/row_data_utils.js +87 -0
  6. package/dist/api/util.js +20 -38
  7. package/dist/dialect/dialect.d.ts +36 -0
  8. package/dist/dialect/dialect.js +28 -1
  9. package/dist/dialect/duckdb/duckdb.d.ts +2 -1
  10. package/dist/dialect/duckdb/duckdb.js +12 -3
  11. package/dist/dialect/mysql/mysql.js +18 -4
  12. package/dist/dialect/pg_impl.d.ts +1 -0
  13. package/dist/dialect/pg_impl.js +2 -0
  14. package/dist/dialect/postgres/postgres.js +4 -1
  15. package/dist/dialect/snowflake/snowflake.d.ts +2 -1
  16. package/dist/dialect/snowflake/snowflake.js +37 -15
  17. package/dist/dialect/standardsql/standardsql.d.ts +2 -1
  18. package/dist/dialect/standardsql/standardsql.js +9 -3
  19. package/dist/dialect/trino/trino.js +10 -2
  20. package/dist/lang/ast/expressions/expr-avg.d.ts +5 -0
  21. package/dist/lang/ast/expressions/expr-avg.js +9 -0
  22. package/dist/lang/ast/expressions/expr-coalesce.js +6 -0
  23. package/dist/lang/ast/expressions/expr-number.d.ts +14 -1
  24. package/dist/lang/ast/expressions/expr-number.js +71 -6
  25. package/dist/lang/ast/expressions/expr-props.d.ts +1 -1
  26. package/dist/lang/ast/expressions/pick-when.js +10 -3
  27. package/dist/lang/ast/types/expression-def.js +36 -2
  28. package/dist/lang/parse-log.d.ts +1 -0
  29. package/dist/lang/test/test-translator.js +2 -0
  30. package/dist/malloy.d.ts +23 -2
  31. package/dist/malloy.js +204 -41
  32. package/dist/model/malloy_types.d.ts +2 -2
  33. package/dist/model/query_model_impl.js +5 -1
  34. package/dist/test/cellsToObject.d.ts +6 -0
  35. package/dist/test/cellsToObject.js +111 -0
  36. package/dist/test/index.d.ts +7 -0
  37. package/dist/test/index.js +16 -20
  38. package/dist/test/matchers.d.ts +10 -0
  39. package/dist/test/matchers.js +17 -0
  40. package/dist/test/resultMatchers.d.ts +42 -0
  41. package/dist/test/resultMatchers.js +722 -0
  42. package/dist/test/runQuery.d.ts +31 -0
  43. package/dist/test/runQuery.js +67 -0
  44. package/dist/test/test-models.d.ts +77 -0
  45. package/dist/test/test-models.js +319 -0
  46. package/dist/test/test-values.d.ts +66 -0
  47. package/dist/test/test-values.js +208 -0
  48. package/dist/to_stable.js +3 -1
  49. package/dist/version.d.ts +1 -1
  50. package/dist/version.js +1 -1
  51. package/package.json +9 -5
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Contributors to the Malloy project
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.TV = void 0;
8
+ const nullExpr = { node: 'null' };
9
+ /**
10
+ * Test Values - type hint functions for test data.
11
+ * Use these when type inference isn't sufficient (nulls, specific numeric types, temporals).
12
+ *
13
+ * @example
14
+ * import { TV, mkTestModel } from '@malloydata/malloy/test';
15
+ *
16
+ * const model = mkTestModel(runtime, {
17
+ * users: [
18
+ * {id: TV.int(1), name: 'alice', created: TV.timestamp('2024-01-01 00:00:00')},
19
+ * {id: TV.int(2), name: null, created: TV.timestamp(null)} // typed nulls
20
+ * ]
21
+ * });
22
+ */
23
+ exports.TV = {
24
+ /**
25
+ * Create an integer value.
26
+ * Use for explicit integer type or typed nulls.
27
+ */
28
+ int(value) {
29
+ const malloyType = { type: 'number', numberType: 'integer' };
30
+ if (value === null) {
31
+ const castExpr = {
32
+ node: 'cast',
33
+ e: nullExpr,
34
+ dstType: { type: 'number', numberType: 'integer' },
35
+ safe: false,
36
+ };
37
+ return { expr: castExpr, malloyType, needsCast: true };
38
+ }
39
+ return {
40
+ expr: { node: 'numberLiteral', literal: String(value) },
41
+ malloyType,
42
+ needsCast: false,
43
+ };
44
+ },
45
+ /**
46
+ * Create a float value.
47
+ * Floats always need casting to ensure proper type.
48
+ */
49
+ float(value) {
50
+ const malloyType = { type: 'number', numberType: 'float' };
51
+ if (value === null) {
52
+ const castExpr = {
53
+ node: 'cast',
54
+ e: nullExpr,
55
+ dstType: { type: 'number', numberType: 'float' },
56
+ safe: false,
57
+ };
58
+ return { expr: castExpr, malloyType, needsCast: true };
59
+ }
60
+ return {
61
+ expr: { node: 'numberLiteral', literal: String(value) },
62
+ malloyType,
63
+ needsCast: true, // floats always need cast
64
+ };
65
+ },
66
+ /**
67
+ * Create a bigint value.
68
+ * Use for explicit bigint type or typed nulls.
69
+ */
70
+ bigint(value) {
71
+ const malloyType = { type: 'number', numberType: 'bigint' };
72
+ if (value === null) {
73
+ const castExpr = {
74
+ node: 'cast',
75
+ e: nullExpr,
76
+ dstType: { type: 'number', numberType: 'bigint' },
77
+ safe: false,
78
+ };
79
+ return { expr: castExpr, malloyType, needsCast: true };
80
+ }
81
+ return {
82
+ expr: { node: 'numberLiteral', literal: String(value) },
83
+ malloyType,
84
+ needsCast: false,
85
+ };
86
+ },
87
+ /**
88
+ * Create a string value.
89
+ * Use for typed nulls.
90
+ */
91
+ string(value) {
92
+ const malloyType = { type: 'string' };
93
+ if (value === null) {
94
+ const castExpr = {
95
+ node: 'cast',
96
+ e: nullExpr,
97
+ dstType: { type: 'string' },
98
+ safe: false,
99
+ };
100
+ return { expr: castExpr, malloyType, needsCast: true };
101
+ }
102
+ return {
103
+ expr: { node: 'stringLiteral', literal: value },
104
+ malloyType,
105
+ needsCast: false,
106
+ };
107
+ },
108
+ /**
109
+ * Create a boolean value.
110
+ * Use for typed nulls.
111
+ */
112
+ bool(value) {
113
+ const malloyType = { type: 'boolean' };
114
+ if (value === null) {
115
+ const castExpr = {
116
+ node: 'cast',
117
+ e: nullExpr,
118
+ dstType: { type: 'boolean' },
119
+ safe: false,
120
+ };
121
+ return { expr: castExpr, malloyType, needsCast: true };
122
+ }
123
+ return {
124
+ expr: value ? { node: 'true' } : { node: 'false' },
125
+ malloyType,
126
+ needsCast: false,
127
+ };
128
+ },
129
+ /**
130
+ * Create a date value (date only, no time).
131
+ * Format: 'YYYY-MM-DD'
132
+ */
133
+ date(value) {
134
+ const malloyType = { type: 'date' };
135
+ if (value === null) {
136
+ const castExpr = {
137
+ node: 'cast',
138
+ e: nullExpr,
139
+ dstType: { type: 'date' },
140
+ safe: false,
141
+ };
142
+ return { expr: castExpr, malloyType, needsCast: true };
143
+ }
144
+ return {
145
+ expr: { node: 'dateLiteral', literal: value, typeDef: { type: 'date' } },
146
+ malloyType,
147
+ needsCast: false,
148
+ };
149
+ },
150
+ /**
151
+ * Create a timestamp value (date + time, no timezone).
152
+ * Format: 'YYYY-MM-DD HH:MM:SS'
153
+ */
154
+ timestamp(value) {
155
+ const malloyType = { type: 'timestamp' };
156
+ if (value === null) {
157
+ const castExpr = {
158
+ node: 'cast',
159
+ e: nullExpr,
160
+ dstType: { type: 'timestamp' },
161
+ safe: false,
162
+ };
163
+ return { expr: castExpr, malloyType, needsCast: true };
164
+ }
165
+ return {
166
+ expr: {
167
+ node: 'timestampLiteral',
168
+ literal: value,
169
+ typeDef: { type: 'timestamp' },
170
+ },
171
+ malloyType,
172
+ needsCast: false,
173
+ };
174
+ },
175
+ /**
176
+ * Create a timestamptz value (date + time + timezone).
177
+ * Format: 'YYYY-MM-DD HH:MM:SS [Timezone]'
178
+ */
179
+ timestamptz(value) {
180
+ const malloyType = { type: 'timestamptz' };
181
+ if (value === null) {
182
+ const castExpr = {
183
+ node: 'cast',
184
+ e: nullExpr,
185
+ dstType: { type: 'timestamptz' },
186
+ safe: false,
187
+ };
188
+ return { expr: castExpr, malloyType, needsCast: true };
189
+ }
190
+ // Use character classes to avoid polynomial regex backtracking (CodeQL warning)
191
+ const match = value.match(/^([^[]+)\[([^\]]+)\]$/);
192
+ if (!match) {
193
+ throw new Error(`Invalid timestamptz format: ${value}. Expected format: 'YYYY-MM-DD HH:MM:SS [Timezone]'`);
194
+ }
195
+ const [, tsPart, timezone] = match;
196
+ return {
197
+ expr: {
198
+ node: 'timestamptzLiteral',
199
+ literal: tsPart.trim(),
200
+ typeDef: { type: 'timestamptz' },
201
+ timezone,
202
+ },
203
+ malloyType,
204
+ needsCast: false,
205
+ };
206
+ },
207
+ };
208
+ //# sourceMappingURL=test-values.js.map
package/dist/to_stable.js CHANGED
@@ -381,7 +381,9 @@ function typeDefToType(field) {
381
381
  ? 'decimal'
382
382
  : field.numberType === 'integer'
383
383
  ? 'integer'
384
- : undefined,
384
+ : field.numberType === 'bigint'
385
+ ? 'bigint'
386
+ : undefined,
385
387
  };
386
388
  case 'boolean':
387
389
  return { kind: 'boolean_type' };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const MALLOY_VERSION = "0.0.326";
1
+ export declare const MALLOY_VERSION = "0.0.327";
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.326';
5
+ exports.MALLOY_VERSION = '0.0.327';
6
6
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.326",
3
+ "version": "0.0.327",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
7
7
  "./test": "./dist/test/index.js",
8
+ "./test/matchers": "./dist/test/matchers.js",
8
9
  "./connection": "./dist/connection/index.js",
9
10
  "./package.json": "./package.json"
10
11
  },
@@ -16,6 +17,9 @@
16
17
  "test": [
17
18
  "./dist/test/index.d.ts"
18
19
  ],
20
+ "test/matchers": [
21
+ "./dist/test/matchers.d.ts"
22
+ ],
19
23
  "connection": [
20
24
  "./dist/connection/index.d.ts"
21
25
  ]
@@ -34,16 +38,16 @@
34
38
  "scripts": {
35
39
  "test": "jest --config=../../jest.config.js",
36
40
  "build-parser": "node src/lang/grammar/build_parser.js",
37
- "clean": "tsc --build --clean && rm -rf src/lang/lib dist",
41
+ "clean": "tsc --build --clean && rm -f tsconfig.tsbuildinfo && rm -rf src/lang/lib dist",
38
42
  "build": "npm run build-parser && tsc --build",
39
43
  "malloyc": "ts-node ../../scripts/malloy-to-json",
40
44
  "prepublishOnly": "npm run clean && npm run build",
41
45
  "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
46
  },
43
47
  "dependencies": {
44
- "@malloydata/malloy-filter": "0.0.326",
45
- "@malloydata/malloy-interfaces": "0.0.326",
46
- "@malloydata/malloy-tag": "0.0.326",
48
+ "@malloydata/malloy-filter": "0.0.327",
49
+ "@malloydata/malloy-interfaces": "0.0.327",
50
+ "@malloydata/malloy-tag": "0.0.327",
47
51
  "antlr4ts": "^0.5.0-alpha.4",
48
52
  "assert": "^2.0.0",
49
53
  "jaro-winkler": "^0.2.8",