@malloydata/malloy-query-builder 0.0.240-dev250305162504 → 0.0.240-dev250305163014
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.
- package/README.md +2 -2
- package/dist/query-ast.d.ts +66 -232
- package/dist/query-ast.js +287 -423
- package/dist/query-ast.js.map +1 -1
- package/dist/query-ast.spec.js +243 -76
- package/dist/query-ast.spec.js.map +1 -1
- package/flow/query-ast.d.ts +71 -59
- package/package.json +4 -4
- package/src/query-ast.spec.ts +246 -78
- package/src/query-ast.ts +273 -454
package/dist/query-ast.js
CHANGED
|
@@ -49,394 +49,233 @@ class ASTNode {
|
|
|
49
49
|
this._parent.edit();
|
|
50
50
|
return this;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
asViewOperationList() {
|
|
193
|
-
if (this instanceof ASTViewOperationList)
|
|
194
|
-
return this;
|
|
195
|
-
throw new Error('Not an ASTViewOperationList');
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* @hidden
|
|
199
|
-
*/
|
|
200
|
-
findViewOperationList(path) {
|
|
201
|
-
return this.find(path).asViewOperationList();
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* @hidden
|
|
205
|
-
*/
|
|
206
|
-
asGroupByViewOperation() {
|
|
207
|
-
if (this instanceof ASTGroupByViewOperation)
|
|
208
|
-
return this;
|
|
209
|
-
throw new Error('Not an ASTGroupByViewOperation');
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* @hidden
|
|
213
|
-
*/
|
|
214
|
-
findGroupByViewOperation(path) {
|
|
215
|
-
return this.find(path).asGroupByViewOperation();
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* @hidden
|
|
219
|
-
*/
|
|
220
|
-
asAggregateViewOperation() {
|
|
221
|
-
if (this instanceof ASTAggregateViewOperation)
|
|
222
|
-
return this;
|
|
223
|
-
throw new Error('Not an ASTAggregateViewOperation');
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* @hidden
|
|
227
|
-
*/
|
|
228
|
-
findAggregateViewOperation(path) {
|
|
229
|
-
return this.find(path).asAggregateViewOperation();
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* @hidden
|
|
233
|
-
*/
|
|
234
|
-
asOrderByViewOperation() {
|
|
235
|
-
if (this instanceof ASTOrderByViewOperation)
|
|
236
|
-
return this;
|
|
237
|
-
throw new Error('Not an ASTOrderByViewOperation');
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* @hidden
|
|
241
|
-
*/
|
|
242
|
-
findOrderByViewOperation(path) {
|
|
243
|
-
return this.find(path).asOrderByViewOperation();
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* @hidden
|
|
247
|
-
*/
|
|
248
|
-
asField() {
|
|
249
|
-
if (this instanceof ASTField)
|
|
250
|
-
return this;
|
|
251
|
-
throw new Error('Not an ASTField');
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* @hidden
|
|
255
|
-
*/
|
|
256
|
-
findField(path) {
|
|
257
|
-
return this.find(path).asField();
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* @hidden
|
|
261
|
-
*/
|
|
262
|
-
asReferenceExpression() {
|
|
263
|
-
if (this instanceof ASTReferenceExpression)
|
|
264
|
-
return this;
|
|
265
|
-
throw new Error('Not an ASTReferenceExpression');
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* @hidden
|
|
269
|
-
*/
|
|
270
|
-
findReferenceExpression(path) {
|
|
271
|
-
return this.find(path).asReferenceExpression();
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* @hidden
|
|
275
|
-
*/
|
|
276
|
-
asReferenceViewDefinition() {
|
|
277
|
-
if (this instanceof ASTReferenceViewDefinition)
|
|
278
|
-
return this;
|
|
279
|
-
throw new Error('Not an ASTReferenceViewDefinition');
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* @hidden
|
|
283
|
-
*/
|
|
284
|
-
findReferenceViewDefinition(path) {
|
|
285
|
-
return this.find(path).asReferenceViewDefinition();
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* @hidden
|
|
289
|
-
*/
|
|
290
|
-
asArrowQueryDefinition() {
|
|
291
|
-
if (this instanceof ASTArrowQueryDefinition)
|
|
292
|
-
return this;
|
|
293
|
-
throw new Error('Not an ASTArrowQueryDefinition');
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* @hidden
|
|
297
|
-
*/
|
|
298
|
-
findArrowQueryDefinition(path) {
|
|
299
|
-
return this.find(path).asArrowQueryDefinition();
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* @hidden
|
|
303
|
-
*/
|
|
304
|
-
asArrowViewDefinition() {
|
|
305
|
-
if (this instanceof ASTArrowViewDefinition)
|
|
306
|
-
return this;
|
|
307
|
-
throw new Error('Not an ASTArrowViewDefinition');
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* @hidden
|
|
311
|
-
*/
|
|
312
|
-
findArrowViewDefinition(path) {
|
|
313
|
-
return this.find(path).asArrowViewDefinition();
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* @hidden
|
|
317
|
-
*/
|
|
318
|
-
asRefinementViewDefinition() {
|
|
319
|
-
if (this instanceof ASTRefinementViewDefinition)
|
|
320
|
-
return this;
|
|
321
|
-
throw new Error('Not an ASTRefinementViewDefinition');
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* @hidden
|
|
325
|
-
*/
|
|
326
|
-
findRefinementViewDefinition(path) {
|
|
327
|
-
return this.find(path).asRefinementViewDefinition();
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* @hidden
|
|
331
|
-
*/
|
|
332
|
-
asTimeTruncationExpression() {
|
|
333
|
-
if (this instanceof ASTTimeTruncationExpression)
|
|
334
|
-
return this;
|
|
335
|
-
throw new Error('Not an ASTTimeTruncationExpression');
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* @hidden
|
|
339
|
-
*/
|
|
340
|
-
findTimeTruncationExpression(path) {
|
|
341
|
-
return this.find(path).asTimeTruncationExpression();
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* @hidden
|
|
345
|
-
*/
|
|
346
|
-
asFilteredFieldExpression() {
|
|
347
|
-
if (this instanceof ASTFilteredFieldExpression)
|
|
348
|
-
return this;
|
|
349
|
-
throw new Error('Not an ASTFilteredFieldExpression');
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* @hidden
|
|
353
|
-
*/
|
|
354
|
-
findFilteredFieldExpression(path) {
|
|
355
|
-
return this.find(path).asFilteredFieldExpression();
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* @hidden
|
|
359
|
-
*/
|
|
360
|
-
asNestViewOperation() {
|
|
361
|
-
if (this instanceof ASTNestViewOperation)
|
|
362
|
-
return this;
|
|
363
|
-
throw new Error('Not an ASTNestViewOperation');
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* @hidden
|
|
367
|
-
*/
|
|
368
|
-
findNestViewOperation(path) {
|
|
369
|
-
return this.find(path).asNestViewOperation();
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* @hidden
|
|
373
|
-
*/
|
|
374
|
-
asView() {
|
|
375
|
-
if (this instanceof ASTView)
|
|
376
|
-
return this;
|
|
377
|
-
throw new Error('Not an ASTView');
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* @hidden
|
|
381
|
-
*/
|
|
382
|
-
findView(path) {
|
|
383
|
-
return this.find(path).asView();
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* @hidden
|
|
387
|
-
*/
|
|
388
|
-
asSegmentViewDefinition() {
|
|
389
|
-
if (this instanceof ASTSegmentViewDefinition)
|
|
390
|
-
return this;
|
|
391
|
-
throw new Error('Not an ASTSegmentViewDefinition');
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* @hidden
|
|
395
|
-
*/
|
|
396
|
-
findSegmentViewDefinition(path) {
|
|
397
|
-
return this.find(path).asSegmentViewDefinition();
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* @hidden
|
|
401
|
-
*/
|
|
402
|
-
asLimitViewOperation() {
|
|
403
|
-
if (this instanceof ASTLimitViewOperation)
|
|
404
|
-
return this;
|
|
405
|
-
throw new Error('Not an ASTLimitViewOperation');
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* @hidden
|
|
409
|
-
*/
|
|
410
|
-
findLimitViewOperation(path) {
|
|
411
|
-
return this.find(path).asLimitViewOperation();
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* @hidden
|
|
415
|
-
*/
|
|
416
|
-
asAnnotationList() {
|
|
417
|
-
if (this instanceof ASTAnnotationList)
|
|
418
|
-
return this;
|
|
419
|
-
throw new Error('Not an ASTAnnotationList');
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* @hidden
|
|
423
|
-
*/
|
|
424
|
-
findAnnotationList(path) {
|
|
425
|
-
return this.find(path).asAnnotationList();
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* @hidden
|
|
429
|
-
*/
|
|
430
|
-
asAnnotation() {
|
|
431
|
-
if (this instanceof ASTAnnotation)
|
|
432
|
-
return this;
|
|
433
|
-
throw new Error('Not an ASTAnnotation');
|
|
52
|
+
get as() {
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
54
|
+
const node = this;
|
|
55
|
+
return {
|
|
56
|
+
Query() {
|
|
57
|
+
if (node instanceof ASTQuery)
|
|
58
|
+
return node;
|
|
59
|
+
throw new Error('Not an ASTQuery');
|
|
60
|
+
},
|
|
61
|
+
Reference() {
|
|
62
|
+
if (node instanceof ASTReference)
|
|
63
|
+
return node;
|
|
64
|
+
throw new Error('Not an ASTReference');
|
|
65
|
+
},
|
|
66
|
+
SourceReference() {
|
|
67
|
+
if (node instanceof ASTSourceReference)
|
|
68
|
+
return node;
|
|
69
|
+
throw new Error('Not an ASTSourceReference');
|
|
70
|
+
},
|
|
71
|
+
ParameterValueList() {
|
|
72
|
+
if (node instanceof ASTParameterValueList)
|
|
73
|
+
return node;
|
|
74
|
+
throw new Error('Not an ASTParameterValueList');
|
|
75
|
+
},
|
|
76
|
+
Where() {
|
|
77
|
+
if (node instanceof ASTWhere)
|
|
78
|
+
return node;
|
|
79
|
+
throw new Error('Not an ASTWhere');
|
|
80
|
+
},
|
|
81
|
+
WhereList() {
|
|
82
|
+
if (node instanceof ASTWhereList)
|
|
83
|
+
return node;
|
|
84
|
+
throw new Error('Not an ASTWhereList');
|
|
85
|
+
},
|
|
86
|
+
ParameterValue() {
|
|
87
|
+
if (node instanceof ASTParameterValue)
|
|
88
|
+
return node;
|
|
89
|
+
throw new Error('Not an ASTParameterValue');
|
|
90
|
+
},
|
|
91
|
+
StringLiteralValue() {
|
|
92
|
+
if (node instanceof ASTStringLiteralValue)
|
|
93
|
+
return node;
|
|
94
|
+
throw new Error('Not an ASTStringLiteralValue');
|
|
95
|
+
},
|
|
96
|
+
NumberLiteralValue() {
|
|
97
|
+
if (node instanceof ASTNumberLiteralValue)
|
|
98
|
+
return node;
|
|
99
|
+
throw new Error('Not an ASTNumberLiteralValue');
|
|
100
|
+
},
|
|
101
|
+
ViewOperationList() {
|
|
102
|
+
if (node instanceof ASTViewOperationList)
|
|
103
|
+
return node;
|
|
104
|
+
throw new Error('Not an ASTViewOperationList');
|
|
105
|
+
},
|
|
106
|
+
GroupByViewOperation() {
|
|
107
|
+
if (node instanceof ASTGroupByViewOperation)
|
|
108
|
+
return node;
|
|
109
|
+
throw new Error('Not an ASTGroupByViewOperation');
|
|
110
|
+
},
|
|
111
|
+
AggregateViewOperation() {
|
|
112
|
+
if (node instanceof ASTAggregateViewOperation)
|
|
113
|
+
return node;
|
|
114
|
+
throw new Error('Not an ASTAggregateViewOperation');
|
|
115
|
+
},
|
|
116
|
+
OrderByViewOperation() {
|
|
117
|
+
if (node instanceof ASTOrderByViewOperation)
|
|
118
|
+
return node;
|
|
119
|
+
throw new Error('Not an ASTOrderByViewOperation');
|
|
120
|
+
},
|
|
121
|
+
Field() {
|
|
122
|
+
if (node instanceof ASTField)
|
|
123
|
+
return node;
|
|
124
|
+
throw new Error('Not an ASTField');
|
|
125
|
+
},
|
|
126
|
+
ReferenceExpression() {
|
|
127
|
+
if (node instanceof ASTReferenceExpression)
|
|
128
|
+
return node;
|
|
129
|
+
throw new Error('Not an ASTReferenceExpression');
|
|
130
|
+
},
|
|
131
|
+
ReferenceViewDefinition() {
|
|
132
|
+
if (node instanceof ASTReferenceViewDefinition)
|
|
133
|
+
return node;
|
|
134
|
+
throw new Error('Not an ASTReferenceViewDefinition');
|
|
135
|
+
},
|
|
136
|
+
ArrowQueryDefinition() {
|
|
137
|
+
if (node instanceof ASTArrowQueryDefinition)
|
|
138
|
+
return node;
|
|
139
|
+
throw new Error('Not an ASTArrowQueryDefinition');
|
|
140
|
+
},
|
|
141
|
+
ArrowViewDefinition() {
|
|
142
|
+
if (node instanceof ASTArrowViewDefinition)
|
|
143
|
+
return node;
|
|
144
|
+
throw new Error('Not an ASTArrowViewDefinition');
|
|
145
|
+
},
|
|
146
|
+
RefinementViewDefinition() {
|
|
147
|
+
if (node instanceof ASTRefinementViewDefinition)
|
|
148
|
+
return node;
|
|
149
|
+
throw new Error('Not an ASTRefinementViewDefinition');
|
|
150
|
+
},
|
|
151
|
+
TimeTruncationExpression() {
|
|
152
|
+
if (node instanceof ASTTimeTruncationExpression)
|
|
153
|
+
return node;
|
|
154
|
+
throw new Error('Not an ASTTimeTruncationExpression');
|
|
155
|
+
},
|
|
156
|
+
FilteredFieldExpression() {
|
|
157
|
+
if (node instanceof ASTFilteredFieldExpression)
|
|
158
|
+
return node;
|
|
159
|
+
throw new Error('Not an ASTFilteredFieldExpression');
|
|
160
|
+
},
|
|
161
|
+
NestViewOperation() {
|
|
162
|
+
if (node instanceof ASTNestViewOperation)
|
|
163
|
+
return node;
|
|
164
|
+
throw new Error('Not an ASTNestViewOperation');
|
|
165
|
+
},
|
|
166
|
+
View() {
|
|
167
|
+
if (node instanceof ASTView)
|
|
168
|
+
return node;
|
|
169
|
+
throw new Error('Not an ASTView');
|
|
170
|
+
},
|
|
171
|
+
SegmentViewDefinition() {
|
|
172
|
+
if (node instanceof ASTSegmentViewDefinition)
|
|
173
|
+
return node;
|
|
174
|
+
throw new Error('Not an ASTSegmentViewDefinition');
|
|
175
|
+
},
|
|
176
|
+
LimitViewOperation() {
|
|
177
|
+
if (node instanceof ASTLimitViewOperation)
|
|
178
|
+
return node;
|
|
179
|
+
throw new Error('Not an ASTLimitViewOperation');
|
|
180
|
+
},
|
|
181
|
+
AnnotationList() {
|
|
182
|
+
if (node instanceof ASTAnnotationList)
|
|
183
|
+
return node;
|
|
184
|
+
throw new Error('Not an ASTAnnotationList');
|
|
185
|
+
},
|
|
186
|
+
Annotation() {
|
|
187
|
+
if (node instanceof ASTAnnotation)
|
|
188
|
+
return node;
|
|
189
|
+
throw new Error('Not an ASTAnnotation');
|
|
190
|
+
},
|
|
191
|
+
};
|
|
434
192
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
193
|
+
get find() {
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
195
|
+
const node = this;
|
|
196
|
+
return {
|
|
197
|
+
Query(path) {
|
|
198
|
+
return node.findAny(path).as.Query();
|
|
199
|
+
},
|
|
200
|
+
Reference(path) {
|
|
201
|
+
return node.findAny(path).as.Reference();
|
|
202
|
+
},
|
|
203
|
+
SourceReference(path) {
|
|
204
|
+
return node.findAny(path).as.SourceReference();
|
|
205
|
+
},
|
|
206
|
+
ParameterValueList(path) {
|
|
207
|
+
return node.findAny(path).as.ParameterValueList();
|
|
208
|
+
},
|
|
209
|
+
Where(path) {
|
|
210
|
+
return node.findAny(path).as.Where();
|
|
211
|
+
},
|
|
212
|
+
WhereList(path) {
|
|
213
|
+
return node.findAny(path).as.WhereList();
|
|
214
|
+
},
|
|
215
|
+
ParameterValue(path) {
|
|
216
|
+
return node.findAny(path).as.ParameterValue();
|
|
217
|
+
},
|
|
218
|
+
StringLiteralValue(path) {
|
|
219
|
+
return node.findAny(path).as.StringLiteralValue();
|
|
220
|
+
},
|
|
221
|
+
NumberLiteralValue(path) {
|
|
222
|
+
return node.findAny(path).as.NumberLiteralValue();
|
|
223
|
+
},
|
|
224
|
+
ViewOperationList(path) {
|
|
225
|
+
return node.findAny(path).as.ViewOperationList();
|
|
226
|
+
},
|
|
227
|
+
GroupByViewOperation(path) {
|
|
228
|
+
return node.findAny(path).as.GroupByViewOperation();
|
|
229
|
+
},
|
|
230
|
+
AggregateViewOperation(path) {
|
|
231
|
+
return node.findAny(path).as.AggregateViewOperation();
|
|
232
|
+
},
|
|
233
|
+
OrderByViewOperation(path) {
|
|
234
|
+
return node.findAny(path).as.OrderByViewOperation();
|
|
235
|
+
},
|
|
236
|
+
Field(path) {
|
|
237
|
+
return node.findAny(path).as.Field();
|
|
238
|
+
},
|
|
239
|
+
ReferenceExpression(path) {
|
|
240
|
+
return node.findAny(path).as.ReferenceExpression();
|
|
241
|
+
},
|
|
242
|
+
ReferenceViewDefinition(path) {
|
|
243
|
+
return node.findAny(path).as.ReferenceViewDefinition();
|
|
244
|
+
},
|
|
245
|
+
ArrowQueryDefinition(path) {
|
|
246
|
+
return node.findAny(path).as.ArrowQueryDefinition();
|
|
247
|
+
},
|
|
248
|
+
ArrowViewDefinition(path) {
|
|
249
|
+
return node.findAny(path).as.ArrowViewDefinition();
|
|
250
|
+
},
|
|
251
|
+
RefinementViewDefinition(path) {
|
|
252
|
+
return node.findAny(path).as.RefinementViewDefinition();
|
|
253
|
+
},
|
|
254
|
+
TimeTruncationExpression(path) {
|
|
255
|
+
return node.findAny(path).as.TimeTruncationExpression();
|
|
256
|
+
},
|
|
257
|
+
FilteredFieldExpression(path) {
|
|
258
|
+
return node.findAny(path).as.FilteredFieldExpression();
|
|
259
|
+
},
|
|
260
|
+
NestViewOperation(path) {
|
|
261
|
+
return node.findAny(path).as.NestViewOperation();
|
|
262
|
+
},
|
|
263
|
+
View(path) {
|
|
264
|
+
return node.findAny(path).as.View();
|
|
265
|
+
},
|
|
266
|
+
SegmentViewDefinition(path) {
|
|
267
|
+
return node.findAny(path).as.SegmentViewDefinition();
|
|
268
|
+
},
|
|
269
|
+
LimitViewOperation(path) {
|
|
270
|
+
return node.findAny(path).as.LimitViewOperation();
|
|
271
|
+
},
|
|
272
|
+
AnnotationList(path) {
|
|
273
|
+
return node.findAny(path).as.AnnotationList();
|
|
274
|
+
},
|
|
275
|
+
Annotation(path) {
|
|
276
|
+
return node.findAny(path).as.Annotation();
|
|
277
|
+
},
|
|
278
|
+
};
|
|
440
279
|
}
|
|
441
280
|
/**
|
|
442
281
|
* @internal
|
|
@@ -489,6 +328,18 @@ class ASTNode {
|
|
|
489
328
|
fields: [...a.fields, ...b.fields],
|
|
490
329
|
};
|
|
491
330
|
}
|
|
331
|
+
static tagFor(a, prefix = '# ') {
|
|
332
|
+
var _a, _b, _c;
|
|
333
|
+
const lines = (_b = (_a = a.annotations) === null || _a === void 0 ? void 0 : _a.map(a => a.value)) === null || _b === void 0 ? void 0 : _b.filter(l => l.startsWith(prefix));
|
|
334
|
+
return (_c = malloy_tag_1.Tag.fromTagLines(lines !== null && lines !== void 0 ? lines : []).tag) !== null && _c !== void 0 ? _c : new malloy_tag_1.Tag();
|
|
335
|
+
}
|
|
336
|
+
static fieldWasCalculation(a) {
|
|
337
|
+
if (a.kind !== 'dimension') {
|
|
338
|
+
throw new Error(`${a.name} could not be an output field, because it is a ${a.kind}, and only dimensions can appear in output schemas`);
|
|
339
|
+
}
|
|
340
|
+
const tag = ASTNode.tagFor(a, '#(malloy) ');
|
|
341
|
+
return tag.has('calculation');
|
|
342
|
+
}
|
|
492
343
|
}
|
|
493
344
|
function isBasic(t) {
|
|
494
345
|
return (Array.isArray(t) ||
|
|
@@ -565,7 +416,7 @@ class ASTListNode extends ASTNode {
|
|
|
565
416
|
/**
|
|
566
417
|
* @internal
|
|
567
418
|
*/
|
|
568
|
-
|
|
419
|
+
findAny(path) {
|
|
569
420
|
if (path.length === 0) {
|
|
570
421
|
return this;
|
|
571
422
|
}
|
|
@@ -574,7 +425,7 @@ class ASTListNode extends ASTNode {
|
|
|
574
425
|
throw new Error(`${this.constructor.name} is a ASTListNode and thus cannot contain a ${head}`);
|
|
575
426
|
}
|
|
576
427
|
const child = this.children[head];
|
|
577
|
-
return child.
|
|
428
|
+
return child.findAny(rest);
|
|
578
429
|
}
|
|
579
430
|
/**
|
|
580
431
|
* @internal
|
|
@@ -629,7 +480,7 @@ class ASTObjectNode extends ASTNode {
|
|
|
629
480
|
/**
|
|
630
481
|
* @internal
|
|
631
482
|
*/
|
|
632
|
-
|
|
483
|
+
findAny(path) {
|
|
633
484
|
if (path.length === 0) {
|
|
634
485
|
return this;
|
|
635
486
|
}
|
|
@@ -641,7 +492,7 @@ class ASTObjectNode extends ASTNode {
|
|
|
641
492
|
if (isBasic(child)) {
|
|
642
493
|
throw new Error(`${this.constructor.name}.${head} refers to a basic type, not an ASTNode`);
|
|
643
494
|
}
|
|
644
|
-
return child.
|
|
495
|
+
return child._find(rest);
|
|
645
496
|
}
|
|
646
497
|
}
|
|
647
498
|
/**
|
|
@@ -762,7 +613,7 @@ class ASTQuery extends ASTObjectNode {
|
|
|
762
613
|
operations: [],
|
|
763
614
|
},
|
|
764
615
|
});
|
|
765
|
-
return this.definition.view.
|
|
616
|
+
return this.definition.view.as.SegmentViewDefinition();
|
|
766
617
|
}
|
|
767
618
|
isRunnable() {
|
|
768
619
|
return this.definition.isRunnable();
|
|
@@ -916,7 +767,7 @@ class ASTQuery extends ASTObjectNode {
|
|
|
916
767
|
name,
|
|
917
768
|
},
|
|
918
769
|
});
|
|
919
|
-
return this.definition.view.
|
|
770
|
+
return this.definition.view.as.ReferenceViewDefinition();
|
|
920
771
|
}
|
|
921
772
|
getInheritedAnnotations() {
|
|
922
773
|
var _a, _b;
|
|
@@ -1025,8 +876,14 @@ class ASTFieldReference extends ASTReference {
|
|
|
1025
876
|
return parent.list.segment;
|
|
1026
877
|
}
|
|
1027
878
|
}
|
|
879
|
+
getReferenceSchema() {
|
|
880
|
+
if (this.parent instanceof ASTOrderByViewOperation) {
|
|
881
|
+
return this.segment.getOutputSchema();
|
|
882
|
+
}
|
|
883
|
+
return this.segment.getInputSchema();
|
|
884
|
+
}
|
|
1028
885
|
getFieldInfo() {
|
|
1029
|
-
const schema = this.
|
|
886
|
+
const schema = this.getReferenceSchema();
|
|
1030
887
|
return ASTNode.schemaGet(schema, this.name, this.path);
|
|
1031
888
|
}
|
|
1032
889
|
}
|
|
@@ -1036,7 +893,7 @@ class ASTSourceReference extends ASTReference {
|
|
|
1036
893
|
* @internal
|
|
1037
894
|
*/
|
|
1038
895
|
get query() {
|
|
1039
|
-
return this.parent.parent.
|
|
896
|
+
return this.parent.parent.as.Query();
|
|
1040
897
|
}
|
|
1041
898
|
/**
|
|
1042
899
|
* Gets the `Malloy.SourceInfo` for the referenced source
|
|
@@ -1235,7 +1092,7 @@ class ASTUnimplemented extends ASTNode {
|
|
|
1235
1092
|
build() {
|
|
1236
1093
|
return this.node;
|
|
1237
1094
|
}
|
|
1238
|
-
|
|
1095
|
+
findAny() {
|
|
1239
1096
|
throw new Error('Tried to find a node from an unimplemented node type');
|
|
1240
1097
|
}
|
|
1241
1098
|
}
|
|
@@ -1288,7 +1145,7 @@ class ASTArrowQueryDefinition extends ASTObjectNode {
|
|
|
1288
1145
|
* @internal
|
|
1289
1146
|
*/
|
|
1290
1147
|
get query() {
|
|
1291
|
-
return this.parent.
|
|
1148
|
+
return this.parent.as.Query();
|
|
1292
1149
|
}
|
|
1293
1150
|
/**
|
|
1294
1151
|
* @internal
|
|
@@ -1340,7 +1197,7 @@ class ASTRefinementQueryDefinition extends ASTObjectNode {
|
|
|
1340
1197
|
* @internal
|
|
1341
1198
|
*/
|
|
1342
1199
|
get query() {
|
|
1343
|
-
return this.parent.
|
|
1200
|
+
return this.parent.as.Query();
|
|
1344
1201
|
}
|
|
1345
1202
|
getOrAddDefaultSegment() {
|
|
1346
1203
|
return this.refinement.getOrAddDefaultSegment();
|
|
@@ -1390,7 +1247,7 @@ class ASTReferenceQueryDefinition extends ASTObjectNode {
|
|
|
1390
1247
|
return this.children.name;
|
|
1391
1248
|
}
|
|
1392
1249
|
get query() {
|
|
1393
|
-
return this.parent.
|
|
1250
|
+
return this.parent.as.Query();
|
|
1394
1251
|
}
|
|
1395
1252
|
get parameters() {
|
|
1396
1253
|
return this.children.parameters;
|
|
@@ -1417,7 +1274,7 @@ class ASTReferenceQueryDefinition extends ASTObjectNode {
|
|
|
1417
1274
|
},
|
|
1418
1275
|
});
|
|
1419
1276
|
this.query.definition = newQuery;
|
|
1420
|
-
return newQuery.refinement.
|
|
1277
|
+
return newQuery.refinement.as.SegmentViewDefinition();
|
|
1421
1278
|
}
|
|
1422
1279
|
/**
|
|
1423
1280
|
* @internal
|
|
@@ -1540,7 +1397,7 @@ class ASTReferenceViewDefinition extends ASTObjectNode {
|
|
|
1540
1397
|
addEmptyRefinement() {
|
|
1541
1398
|
const newView = ASTRefinementViewDefinition.segmentRefinementOf(this.build());
|
|
1542
1399
|
swapViewInParent(this, newView);
|
|
1543
|
-
return newView.refinement.
|
|
1400
|
+
return newView.refinement.as.SegmentViewDefinition();
|
|
1544
1401
|
}
|
|
1545
1402
|
addViewRefinement(name, path) {
|
|
1546
1403
|
const { error } = this.isValidViewRefinement(name, path);
|
|
@@ -1549,7 +1406,7 @@ class ASTReferenceViewDefinition extends ASTObjectNode {
|
|
|
1549
1406
|
}
|
|
1550
1407
|
const newView = ASTRefinementViewDefinition.viewRefinementOf(this.build(), name, path);
|
|
1551
1408
|
swapViewInParent(this, newView);
|
|
1552
|
-
return newView.refinement.
|
|
1409
|
+
return newView.refinement.as.ReferenceViewDefinition();
|
|
1553
1410
|
}
|
|
1554
1411
|
isValidViewRefinement(name, path) {
|
|
1555
1412
|
return isValidViewRefinement(this, name, path);
|
|
@@ -1925,16 +1782,18 @@ class ASTSegmentViewDefinition extends ASTObjectNode {
|
|
|
1925
1782
|
if (operation instanceof ASTOrderByViewOperation) {
|
|
1926
1783
|
if (operation.name === name) {
|
|
1927
1784
|
operation.direction = direction;
|
|
1928
|
-
return;
|
|
1785
|
+
return operation;
|
|
1929
1786
|
}
|
|
1930
1787
|
}
|
|
1931
1788
|
}
|
|
1932
|
-
|
|
1933
|
-
this.addOperation(new ASTOrderByViewOperation({
|
|
1789
|
+
const operation = new ASTOrderByViewOperation({
|
|
1934
1790
|
kind: 'order_by',
|
|
1935
1791
|
field_reference: { name },
|
|
1936
1792
|
direction,
|
|
1937
|
-
})
|
|
1793
|
+
});
|
|
1794
|
+
// add a new order by operation
|
|
1795
|
+
this.addOperation(operation);
|
|
1796
|
+
return operation;
|
|
1938
1797
|
}
|
|
1939
1798
|
/**
|
|
1940
1799
|
* Adds an empty nest to this segment, with the given name.
|
|
@@ -2315,7 +2174,7 @@ class ASTSegmentViewDefinition extends ASTObjectNode {
|
|
|
2315
2174
|
addEmptyRefinement() {
|
|
2316
2175
|
const view = ASTRefinementViewDefinition.segmentRefinementOf(this.build());
|
|
2317
2176
|
swapViewInParent(this, view);
|
|
2318
|
-
return view.refinement.
|
|
2177
|
+
return view.refinement.as.SegmentViewDefinition();
|
|
2319
2178
|
}
|
|
2320
2179
|
addViewRefinement(name, path) {
|
|
2321
2180
|
const { error } = this.isValidViewRefinement(name, path);
|
|
@@ -2324,7 +2183,7 @@ class ASTSegmentViewDefinition extends ASTObjectNode {
|
|
|
2324
2183
|
}
|
|
2325
2184
|
const view = ASTRefinementViewDefinition.viewRefinementOf(this.build(), name, path);
|
|
2326
2185
|
swapViewInParent(this, view);
|
|
2327
|
-
return view.refinement.
|
|
2186
|
+
return view.refinement.as.ReferenceViewDefinition();
|
|
2328
2187
|
}
|
|
2329
2188
|
getInputSchema() {
|
|
2330
2189
|
return getInputSchemaFromViewParent(this.parent);
|
|
@@ -2362,7 +2221,7 @@ class ASTViewOperationList extends ASTListNode {
|
|
|
2362
2221
|
* @internal
|
|
2363
2222
|
*/
|
|
2364
2223
|
get segment() {
|
|
2365
|
-
return this.parent.
|
|
2224
|
+
return this.parent.as.SegmentViewDefinition();
|
|
2366
2225
|
}
|
|
2367
2226
|
}
|
|
2368
2227
|
exports.ASTViewOperationList = ASTViewOperationList;
|
|
@@ -2413,7 +2272,7 @@ class ASTOrderByViewOperation extends ASTObjectNode {
|
|
|
2413
2272
|
this.children.direction = direction;
|
|
2414
2273
|
}
|
|
2415
2274
|
get list() {
|
|
2416
|
-
return this.parent.
|
|
2275
|
+
return this.parent.as.ViewOperationList();
|
|
2417
2276
|
}
|
|
2418
2277
|
delete() {
|
|
2419
2278
|
const list = this.list;
|
|
@@ -2462,7 +2321,7 @@ class ASTGroupByViewOperation extends ASTObjectNode {
|
|
|
2462
2321
|
* @internal
|
|
2463
2322
|
*/
|
|
2464
2323
|
get list() {
|
|
2465
|
-
return this.parent.
|
|
2324
|
+
return this.parent.as.ViewOperationList();
|
|
2466
2325
|
}
|
|
2467
2326
|
/**
|
|
2468
2327
|
* Renames the group by item. If the field's name matches the given name,
|
|
@@ -2649,7 +2508,7 @@ class ASTAggregateViewOperation extends ASTObjectNode {
|
|
|
2649
2508
|
* @internal
|
|
2650
2509
|
*/
|
|
2651
2510
|
get list() {
|
|
2652
|
-
return this.parent.
|
|
2511
|
+
return this.parent.as.ViewOperationList();
|
|
2653
2512
|
}
|
|
2654
2513
|
delete() {
|
|
2655
2514
|
this.list.remove(this);
|
|
@@ -2661,6 +2520,11 @@ class ASTAggregateViewOperation extends ASTObjectNode {
|
|
|
2661
2520
|
}
|
|
2662
2521
|
getFieldInfo() {
|
|
2663
2522
|
return {
|
|
2523
|
+
annotations: [
|
|
2524
|
+
{
|
|
2525
|
+
value: malloy_tag_1.Tag.withPrefix('#(malloy) ').set(['calculation']).toString(),
|
|
2526
|
+
},
|
|
2527
|
+
],
|
|
2664
2528
|
kind: 'dimension',
|
|
2665
2529
|
name: this.name,
|
|
2666
2530
|
type: this.field.type,
|
|
@@ -2853,7 +2717,7 @@ class ASTReferenceExpression extends ASTObjectNode {
|
|
|
2853
2717
|
* @internal
|
|
2854
2718
|
*/
|
|
2855
2719
|
get field() {
|
|
2856
|
-
return this.parent.
|
|
2720
|
+
return this.parent.as.Field();
|
|
2857
2721
|
}
|
|
2858
2722
|
get path() {
|
|
2859
2723
|
return this.children.path;
|
|
@@ -2914,7 +2778,7 @@ class ASTTimeTruncationExpression extends ASTObjectNode {
|
|
|
2914
2778
|
* @internal
|
|
2915
2779
|
*/
|
|
2916
2780
|
get field() {
|
|
2917
|
-
return this.parent.
|
|
2781
|
+
return this.parent.as.Field();
|
|
2918
2782
|
}
|
|
2919
2783
|
getFieldInfo() {
|
|
2920
2784
|
const schema = this.field.segment.getInputSchema();
|
|
@@ -2954,7 +2818,7 @@ class ASTWhere extends ASTObjectNode {
|
|
|
2954
2818
|
return this.children.filter;
|
|
2955
2819
|
}
|
|
2956
2820
|
get list() {
|
|
2957
|
-
return this.parent.
|
|
2821
|
+
return this.parent.as.WhereList();
|
|
2958
2822
|
}
|
|
2959
2823
|
delete() {
|
|
2960
2824
|
this.list.remove(this);
|
|
@@ -2966,7 +2830,7 @@ class ASTWhereList extends ASTListNode {
|
|
|
2966
2830
|
super(wheres, wheres.map(p => new ASTWhere(p)));
|
|
2967
2831
|
}
|
|
2968
2832
|
get expression() {
|
|
2969
|
-
return this.parent.
|
|
2833
|
+
return this.parent.as.FilteredFieldExpression();
|
|
2970
2834
|
}
|
|
2971
2835
|
}
|
|
2972
2836
|
exports.ASTWhereList = ASTWhereList;
|
|
@@ -2996,7 +2860,7 @@ class ASTFilteredFieldExpression extends ASTObjectNode {
|
|
|
2996
2860
|
* @internal
|
|
2997
2861
|
*/
|
|
2998
2862
|
get field() {
|
|
2999
|
-
return this.parent.
|
|
2863
|
+
return this.parent.as.Field();
|
|
3000
2864
|
}
|
|
3001
2865
|
getFieldInfo() {
|
|
3002
2866
|
const schema = this.field.segment.getInputSchema();
|
|
@@ -3067,7 +2931,7 @@ class ASTNestViewOperation extends ASTObjectNode {
|
|
|
3067
2931
|
* @internal
|
|
3068
2932
|
*/
|
|
3069
2933
|
get list() {
|
|
3070
|
-
return this.parent.
|
|
2934
|
+
return this.parent.as.ViewOperationList();
|
|
3071
2935
|
}
|
|
3072
2936
|
getOrAddAnnotations() {
|
|
3073
2937
|
return this.view.getOrAddAnnotations();
|
|
@@ -3183,7 +3047,7 @@ class ASTWhereViewOperation extends ASTObjectNode {
|
|
|
3183
3047
|
* @internal
|
|
3184
3048
|
*/
|
|
3185
3049
|
get list() {
|
|
3186
|
-
return this.parent.
|
|
3050
|
+
return this.parent.as.ViewOperationList();
|
|
3187
3051
|
}
|
|
3188
3052
|
delete() {
|
|
3189
3053
|
this.list.remove(this);
|
|
@@ -3270,13 +3134,13 @@ class ASTView extends ASTObjectNode {
|
|
|
3270
3134
|
* @internal
|
|
3271
3135
|
*/
|
|
3272
3136
|
get nest() {
|
|
3273
|
-
return this.parent.
|
|
3137
|
+
return this.parent.as.NestViewOperation();
|
|
3274
3138
|
}
|
|
3275
3139
|
getInputSchema() {
|
|
3276
3140
|
return this.nest.list.segment.getInputSchema();
|
|
3277
3141
|
}
|
|
3278
3142
|
getOutputSchema() {
|
|
3279
|
-
return this.definition.
|
|
3143
|
+
return this.definition.getRefinementSchema();
|
|
3280
3144
|
}
|
|
3281
3145
|
/**
|
|
3282
3146
|
* @internal
|
|
@@ -3355,7 +3219,7 @@ class ASTLimitViewOperation extends ASTObjectNode {
|
|
|
3355
3219
|
* @internal
|
|
3356
3220
|
*/
|
|
3357
3221
|
get list() {
|
|
3358
|
-
return this.parent.
|
|
3222
|
+
return this.parent.as.ViewOperationList();
|
|
3359
3223
|
}
|
|
3360
3224
|
delete() {
|
|
3361
3225
|
this.list.remove(this);
|
|
@@ -3467,7 +3331,7 @@ class ASTAnnotation extends ASTObjectNode {
|
|
|
3467
3331
|
* @internal
|
|
3468
3332
|
*/
|
|
3469
3333
|
get list() {
|
|
3470
|
-
return this.parent.
|
|
3334
|
+
return this.parent.as.AnnotationList();
|
|
3471
3335
|
}
|
|
3472
3336
|
get index() {
|
|
3473
3337
|
return this.list.indexOf(this);
|