@malloydata/malloy-query-builder 0.0.237-dev250225144145

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.
@@ -0,0 +1,1614 @@
1
+ import * as Malloy from '@malloydata/malloy-interfaces';
2
+ import { Tag, TagSetValue } from '@malloydata/malloy-tag';
3
+ import * as Filter from '@malloydata/malloy-filter';
4
+ export type ParsedFilter = {
5
+ kind: 'string';
6
+ clauses: Filter.StringClause[];
7
+ } | {
8
+ kind: 'number';
9
+ clauses: Filter.NumberClause[];
10
+ } | {
11
+ kind: 'boolean';
12
+ clauses: Filter.BooleanClause[];
13
+ } | {
14
+ kind: 'date';
15
+ clauses: Filter.DateClause[];
16
+ };
17
+ export type PathSegment = number | string;
18
+ export type Path = PathSegment[];
19
+ type ASTAny = ASTNode<unknown>;
20
+ type ASTChildren<T> = {
21
+ [Key in keyof T]: LiteralOrNode<T[Key]>;
22
+ };
23
+ type NonOptionalASTNode<T> = T extends undefined ? never : ASTNode<T>;
24
+ type LiteralOrNode<T> = T extends string ? T : T extends number ? T : T extends string[] ? T : T extends boolean ? T : undefined extends T ? NonOptionalASTNode<T> | undefined : ASTNode<T>;
25
+ declare abstract class ASTNode<T> {
26
+ /**
27
+ * @internal
28
+ */
29
+ edited: boolean;
30
+ /**
31
+ * @internal
32
+ */
33
+ _parent: ASTAny | undefined;
34
+ abstract build(): T;
35
+ /**
36
+ * @internal
37
+ */
38
+ edit(): this;
39
+ /**
40
+ * @internal
41
+ */
42
+ abstract find(path: Path): ASTAny;
43
+ /**
44
+ * Returns this node as an `ASTQuery`. Throws if it is not an `ASTQuery`.
45
+ *
46
+ * There are variants of this method for _all_ ASTXYZ nodes `asXYZ`, but they
47
+ * are not shown here so the docs aren't crazy big.
48
+ *
49
+ * @returns Returns this node as an `ASTQuery`.
50
+ */
51
+ asQuery(): ASTQuery;
52
+ /**
53
+ * Finds the AST node at the given `path`. Throws if it is not an `ASTQuery`.
54
+ *
55
+ * There are variants of this method for _all_ ASTXYZ nodes `findXYZ`, but they
56
+ * are not shown here so the docs aren't crazy big.
57
+ *
58
+ * @param path Path to the desired ASTNode, e.g. `['source', 'parameters', 0]`
59
+ * @returns Returns this node as an `ASTQuery`.
60
+ */
61
+ findQuery(path: Path): ASTQuery;
62
+ /**
63
+ * @hidden
64
+ */
65
+ asReference(): ASTReference;
66
+ /**
67
+ * @hidden
68
+ */
69
+ findReference(path: Path): ASTReference;
70
+ /**
71
+ * @hidden
72
+ */
73
+ asSourceReference(): ASTSourceReference;
74
+ /**
75
+ * @hidden
76
+ */
77
+ findSourceReference(path: Path): ASTSourceReference;
78
+ /**
79
+ * @hidden
80
+ */
81
+ asParameterValueList(): ASTParameterValueList;
82
+ /**
83
+ * @hidden
84
+ */
85
+ findParameterValueList(path: Path): ASTParameterValueList;
86
+ /**
87
+ * @hidden
88
+ */
89
+ asWhere(): ASTWhere;
90
+ /**
91
+ * @hidden
92
+ */
93
+ findWhere(path: Path): ASTWhere;
94
+ /**
95
+ * @hidden
96
+ */
97
+ asWhereList(): ASTWhereList;
98
+ /**
99
+ * @hidden
100
+ */
101
+ findWhereList(path: Path): ASTWhereList;
102
+ /**
103
+ * @hidden
104
+ */
105
+ asParameterValue(): ASTParameterValue;
106
+ /**
107
+ * @hidden
108
+ */
109
+ findParameterValue(path: Path): ASTParameterValue;
110
+ /**
111
+ * @hidden
112
+ */
113
+ asStringLiteralValue(): ASTStringLiteralValue;
114
+ /**
115
+ * @hidden
116
+ */
117
+ findStringLiteralValue(path: Path): ASTStringLiteralValue;
118
+ /**
119
+ * @hidden
120
+ */
121
+ asNumberLiteralValue(): ASTNumberLiteralValue;
122
+ /**
123
+ * @hidden
124
+ */
125
+ findNumberLiteralValue(path: Path): ASTNumberLiteralValue;
126
+ /**
127
+ * @hidden
128
+ */
129
+ asViewOperationList(): ASTViewOperationList;
130
+ /**
131
+ * @hidden
132
+ */
133
+ findViewOperationList(path: Path): ASTViewOperationList;
134
+ /**
135
+ * @hidden
136
+ */
137
+ asGroupByViewOperation(): ASTGroupByViewOperation;
138
+ /**
139
+ * @hidden
140
+ */
141
+ findGroupByViewOperation(path: Path): ASTGroupByViewOperation;
142
+ /**
143
+ * @hidden
144
+ */
145
+ asAggregateViewOperation(): ASTAggregateViewOperation;
146
+ /**
147
+ * @hidden
148
+ */
149
+ findAggregateViewOperation(path: Path): ASTAggregateViewOperation;
150
+ /**
151
+ * @hidden
152
+ */
153
+ asOrderByViewOperation(): ASTOrderByViewOperation;
154
+ /**
155
+ * @hidden
156
+ */
157
+ findOrderByViewOperation(path: Path): ASTOrderByViewOperation;
158
+ /**
159
+ * @hidden
160
+ */
161
+ asField(): ASTField;
162
+ /**
163
+ * @hidden
164
+ */
165
+ findField(path: Path): ASTField;
166
+ /**
167
+ * @hidden
168
+ */
169
+ asReferenceExpression(): ASTReferenceExpression;
170
+ /**
171
+ * @hidden
172
+ */
173
+ findReferenceExpression(path: Path): ASTReferenceExpression;
174
+ /**
175
+ * @hidden
176
+ */
177
+ asReferenceViewDefinition(): ASTReferenceViewDefinition;
178
+ /**
179
+ * @hidden
180
+ */
181
+ findReferenceViewDefinition(path: Path): ASTReferenceViewDefinition;
182
+ /**
183
+ * @hidden
184
+ */
185
+ asArrowQueryDefinition(): ASTArrowQueryDefinition;
186
+ /**
187
+ * @hidden
188
+ */
189
+ findArrowQueryDefinition(path: Path): ASTArrowQueryDefinition;
190
+ /**
191
+ * @hidden
192
+ */
193
+ asArrowViewDefinition(): ASTArrowViewDefinition;
194
+ /**
195
+ * @hidden
196
+ */
197
+ findArrowViewDefinition(path: Path): ASTArrowViewDefinition;
198
+ /**
199
+ * @hidden
200
+ */
201
+ asRefinementViewDefinition(): ASTRefinementViewDefinition;
202
+ /**
203
+ * @hidden
204
+ */
205
+ findRefinementViewDefinition(path: Path): ASTRefinementViewDefinition;
206
+ /**
207
+ * @hidden
208
+ */
209
+ asTimeTruncationExpression(): ASTTimeTruncationExpression;
210
+ /**
211
+ * @hidden
212
+ */
213
+ findTimeTruncationExpression(path: Path): ASTTimeTruncationExpression;
214
+ /**
215
+ * @hidden
216
+ */
217
+ asFilteredFieldExpression(): ASTFilteredFieldExpression;
218
+ /**
219
+ * @hidden
220
+ */
221
+ findFilteredFieldExpression(path: Path): ASTFilteredFieldExpression;
222
+ /**
223
+ * @hidden
224
+ */
225
+ asNestViewOperation(): ASTNestViewOperation;
226
+ /**
227
+ * @hidden
228
+ */
229
+ findNestViewOperation(path: Path): ASTNestViewOperation;
230
+ /**
231
+ * @hidden
232
+ */
233
+ asView(): ASTView;
234
+ /**
235
+ * @hidden
236
+ */
237
+ findView(path: Path): ASTView;
238
+ /**
239
+ * @hidden
240
+ */
241
+ asSegmentViewDefinition(): ASTSegmentViewDefinition;
242
+ /**
243
+ * @hidden
244
+ */
245
+ findSegmentViewDefinition(path: Path): ASTSegmentViewDefinition;
246
+ /**
247
+ * @hidden
248
+ */
249
+ asLimitViewOperation(): ASTLimitViewOperation;
250
+ /**
251
+ * @hidden
252
+ */
253
+ findLimitViewOperation(path: Path): ASTLimitViewOperation;
254
+ /**
255
+ * @hidden
256
+ */
257
+ asAnnotationList(): ASTAnnotationList;
258
+ /**
259
+ * @hidden
260
+ */
261
+ findAnnotationList(path: Path): ASTAnnotationList;
262
+ /**
263
+ * @hidden
264
+ */
265
+ asAnnotation(): ASTAnnotation;
266
+ /**
267
+ * @hidden
268
+ */
269
+ findAnnotation(path: Path): ASTAnnotation;
270
+ /**
271
+ * @internal
272
+ */
273
+ get parent(): ASTAny;
274
+ /**
275
+ * @internal
276
+ */
277
+ set parent(parent: ASTAny);
278
+ /**
279
+ * @internal
280
+ */
281
+ static schemaTryGet(schema: Malloy.Schema, name: string, path: string[] | undefined): Malloy.FieldInfo | undefined;
282
+ /**
283
+ * @internal
284
+ */
285
+ static schemaGet(schema: Malloy.Schema, name: string, path: string[] | undefined): Malloy.FieldInfo;
286
+ /**
287
+ * @internal
288
+ */
289
+ static schemaMerge(a: Malloy.Schema, b: Malloy.Schema): Malloy.Schema;
290
+ }
291
+ declare abstract class ASTListNode<T, N extends ASTNode<T> = ASTNode<T>> extends ASTNode<T[]> {
292
+ protected node: T[];
293
+ protected children: N[];
294
+ originalChildren: N[];
295
+ constructor(node: T[], children: N[]);
296
+ iter(): Generator<N, void, unknown>;
297
+ get length(): number;
298
+ get last(): N;
299
+ /**
300
+ * Get the `i`th element of this list
301
+ *
302
+ * @param i The index of the list to get
303
+ * @returns The item at index `i` in this list
304
+ */
305
+ index(i: number): N;
306
+ /**
307
+ * @internal
308
+ */
309
+ insert(n: N, index: number): void;
310
+ /**
311
+ * @internal
312
+ */
313
+ add(n: N): void;
314
+ /**
315
+ * @internal
316
+ */
317
+ remove(n: N): this | undefined;
318
+ /**
319
+ * @internal
320
+ */
321
+ build(): T[];
322
+ /**
323
+ * @internal
324
+ */
325
+ find(path: Path): ASTAny;
326
+ /**
327
+ * @internal
328
+ */
329
+ findIndex(predicate: (n: N) => boolean): number;
330
+ /**
331
+ * @internal
332
+ */
333
+ indexOf(n: N): number;
334
+ }
335
+ declare abstract class ASTObjectNode<T, Children extends ASTChildren<T>> extends ASTNode<T> {
336
+ protected node: T;
337
+ protected children: Children;
338
+ constructor(node: T, children: Children);
339
+ /**
340
+ * @internal
341
+ */
342
+ build(): T;
343
+ /**
344
+ * @internal
345
+ */
346
+ find(path: Path): ASTAny;
347
+ }
348
+ /**
349
+ * AST Object to represent the whole query AST.
350
+ *
351
+ * ```ts
352
+ * const q = new ASTQuery({
353
+ * source: flightsSourceInfo,
354
+ * });
355
+ * const segment = q.getOrAddDefaultSegment();
356
+ * segment.addGroupBy("carrier");
357
+ * segment.addOrderBy("carrier", Malloy.OrderByDirection.DESC);
358
+ * const malloy = q.toMalloy();
359
+ * const query = q.build();
360
+ * ```
361
+ */
362
+ export declare class ASTQuery extends ASTObjectNode<Malloy.Query, {
363
+ definition: ASTQueryDefinition;
364
+ annotations?: ASTAnnotationList;
365
+ }> implements IASTAnnotatable {
366
+ model: Malloy.ModelInfo;
367
+ /**
368
+ * Create a new Query AST object against a given source.
369
+ *
370
+ * @param options.query Optional query to begin with; if none is provided, will
371
+ * use an empty query (`{pipeline: {stages: []}}`)
372
+ * @param options.source A source to base the query on. Will set the source name
373
+ * in the provided (or default) query to the name of this source.
374
+ */
375
+ constructor(options: {
376
+ query?: Malloy.Query;
377
+ source: Malloy.ModelEntryValueWithSource | Malloy.ModelEntryValueWithQuery | Malloy.SourceInfo | Malloy.QueryInfo;
378
+ });
379
+ /**
380
+ * Create a new Query AST object against a given model.
381
+ *
382
+ * @param options.query Optional query to begin with; if none is provided, will
383
+ * use an empty query (`{pipeline: {stages: []}}`)
384
+ * @param options.model A model to use for building this query. Use {@link setSource}
385
+ * to configure the source, or set {@link setQueryHead} to run
386
+ * a top level query in the model.
387
+ */
388
+ constructor(options: {
389
+ query?: Malloy.Query;
390
+ model: Malloy.ModelInfo;
391
+ });
392
+ get definition(): ASTQueryDefinition;
393
+ set definition(definition: ASTQueryDefinition);
394
+ get annotations(): ASTAnnotationList | undefined;
395
+ reorderFields(names: string[]): void;
396
+ getOrAddAnnotations(): ASTAnnotationList;
397
+ getInheritedTag(prefix?: RegExp | string): Tag;
398
+ getIntrinsicTag(prefix?: RegExp | string): Tag;
399
+ getTag(prefix?: RegExp | string): Tag;
400
+ setTagProperty(path: Path, value?: TagSetValue, prefix?: string): void;
401
+ removeTagProperty(path: Path, prefix?: string): void;
402
+ setViewToEmptySegment(): ASTSegmentViewDefinition;
403
+ isRunnable(): boolean;
404
+ /**
405
+ * Gets an {@link ASTSegmentViewDefinition} for the "default" place to add query
406
+ * operations, or creates one if it doesn't exist.
407
+ *
408
+ * ```
409
+ * run: flights ->
410
+ * ```
411
+ * ```ts
412
+ * q.getOrAddDefaultSegment();
413
+ * ```
414
+ * ```
415
+ * run: flights -> { }
416
+ * ```
417
+ *
418
+ * If there is a view at the head, it will refine it:
419
+ * ```
420
+ * run: flights -> by_carrier
421
+ * ```
422
+ * ```ts
423
+ * q.getOrAddDefaultSegment();
424
+ * ```
425
+ * ```
426
+ * run: flights -> by_carrier + { }
427
+ * ```
428
+ */
429
+ getOrAddDefaultSegment(): ASTSegmentViewDefinition;
430
+ /**
431
+ * Sets the source of this query to be a reference to a source in the model.
432
+ *
433
+ * ```ts
434
+ * q.setSource('flights')
435
+ * ```
436
+ * ```
437
+ * run: flights -> { }
438
+ * ```
439
+ *
440
+ * @param name The name of the source in the model to reference.
441
+ */
442
+ setSource(name: string): void;
443
+ /**
444
+ * Sets the head of this query to be a reference to a top level query.
445
+ *
446
+ * ```ts
447
+ * q.setQueryHead('flights_by_carrier')
448
+ * ```
449
+ * ```
450
+ * run: flights_by_carrier
451
+ * ```
452
+ *
453
+ * @param name The name of the query in the model to reference.
454
+ */
455
+ setQueryHead(name: string): void;
456
+ /**
457
+ * @internal
458
+ */
459
+ getQueryInfo(name: string): Malloy.QueryInfo;
460
+ /**
461
+ * Emits the current query object as Malloy code
462
+ *
463
+ * ```ts
464
+ * q.setSource('flights')
465
+ * q.setView('by_carrier')
466
+ * q.toMalloy();
467
+ * ```
468
+ * ```
469
+ * run: flights -> by_carrier
470
+ * ```
471
+ *
472
+ * @returns Malloy code for the query
473
+ */
474
+ toMalloy(): string;
475
+ /**
476
+ * Build the query into its `Malloy.Query` object form. New JS objects will be
477
+ * created for any subtree which has edits.
478
+ *
479
+ * @returns A `Malloy.Query` representing the current query
480
+ */
481
+ build(): Malloy.Query;
482
+ /**
483
+ * Set the view of this query; overwrites any other query operations.
484
+ *
485
+ * ```
486
+ * run: flights ->
487
+ * ```
488
+ * ```ts
489
+ * q.setView('by_carrier')
490
+ * ```
491
+ * ```
492
+ * run: flights -> by_carrier
493
+ * ```
494
+ *
495
+ * @param name The name of the view to set as the head of the query pipeline
496
+ */
497
+ setView(name: string): ASTReferenceViewDefinition;
498
+ getInheritedAnnotations(): Malloy.Annotation[];
499
+ }
500
+ export type RawLiteralValue = number | string | {
501
+ date: Date;
502
+ granularity: Malloy.TimestampTimeframe;
503
+ } | boolean | null;
504
+ export interface IASTReference extends ASTAny {
505
+ /**
506
+ * Gets the parameter list for this reference, or creates it if it does not exist.
507
+ *
508
+ * @returns The parameter list `ASTParameterValueList`
509
+ */
510
+ getOrAddParameters(): ASTParameterValueList;
511
+ /**
512
+ * Adds a parameter to this source with with the given name and value
513
+ *
514
+ * This will override an existing parameter with the same name.
515
+ *
516
+ * @param name The name of the parameter to set
517
+ * @param value The value of the parameter to set
518
+ */
519
+ setParameter(name: string, value: RawLiteralValue): void;
520
+ tryGetParameter(name: string): ASTParameterValue | undefined;
521
+ parameters: ASTParameterValueList | undefined;
522
+ name: string;
523
+ path: string[] | undefined;
524
+ }
525
+ export declare class ASTReference extends ASTObjectNode<Malloy.Reference, {
526
+ name: string;
527
+ path?: string[];
528
+ parameters?: ASTParameterValueList;
529
+ }> implements IASTReference {
530
+ reference: Malloy.Reference;
531
+ constructor(reference: Malloy.Reference);
532
+ get name(): string;
533
+ set name(value: string);
534
+ get parameters(): ASTParameterValueList | undefined;
535
+ set parameters(parameters: ASTParameterValueList | undefined);
536
+ get path(): string[] | undefined;
537
+ /**
538
+ * @internal
539
+ */
540
+ static getOrAddParameters(reference: IASTReference): ASTParameterValueList;
541
+ /**
542
+ * @internal
543
+ */
544
+ static setParameter(reference: IASTReference, name: string, value: RawLiteralValue): void;
545
+ /**
546
+ * @internal
547
+ */
548
+ static tryGetParameter(reference: IASTReference, name: string): ASTParameterValue | undefined;
549
+ getOrAddParameters(): any;
550
+ setParameter(name: string, value: RawLiteralValue): void;
551
+ tryGetParameter(name: string): ASTParameterValue | undefined;
552
+ }
553
+ export declare class ASTFieldReference extends ASTReference {
554
+ /**
555
+ * @internal
556
+ */
557
+ get segment(): ASTSegmentViewDefinition;
558
+ getFieldInfo(): Malloy.FieldInfo;
559
+ }
560
+ export declare class ASTSourceReference extends ASTReference {
561
+ /**
562
+ * @internal
563
+ */
564
+ get query(): ASTQuery;
565
+ /**
566
+ * Gets the `Malloy.SourceInfo` for the referenced source
567
+ *
568
+ * @returns The source information for the referenced source
569
+ */
570
+ getSourceInfo(): Malloy.SourceInfo;
571
+ getSourceParameters(): Malloy.ParameterInfo[];
572
+ areRequiredParametersSet(): boolean;
573
+ }
574
+ export declare class ASTParameterValueList extends ASTListNode<Malloy.ParameterValue, ASTParameterValue> {
575
+ constructor(parameters: Malloy.ParameterValue[]);
576
+ get parameters(): ASTParameterValue[];
577
+ addParameter(name: string, value: RawLiteralValue): void;
578
+ }
579
+ export declare class ASTParameterValue extends ASTObjectNode<Malloy.ParameterValue, {
580
+ name: string;
581
+ value: ASTLiteralValue;
582
+ }> {
583
+ parameter: Malloy.ParameterValue;
584
+ constructor(parameter: Malloy.ParameterValue);
585
+ get name(): string;
586
+ }
587
+ export type ASTLiteralValue = ASTStringLiteralValue | ASTNumberLiteralValue | ASTBooleanLiteralValue | ASTDateLiteralValue | ASTTimestampLiteralValue | ASTNullLiteralValue;
588
+ export declare const LiteralValueAST: {
589
+ from(value: Malloy.LiteralValue): ASTStringLiteralValue | ASTNumberLiteralValue | ASTBooleanLiteralValue | ASTDateLiteralValue | ASTTimestampLiteralValue | ASTNullLiteralValue;
590
+ makeLiteral(value: RawLiteralValue): Malloy.LiteralValue;
591
+ };
592
+ export declare class ASTStringLiteralValue extends ASTObjectNode<Malloy.LiteralValueWithStringLiteral, {
593
+ kind: 'string_literal';
594
+ string_value: string;
595
+ }> {
596
+ node: Malloy.LiteralValueWithStringLiteral;
597
+ readonly kind: Malloy.LiteralValueType;
598
+ constructor(node: Malloy.LiteralValueWithStringLiteral);
599
+ }
600
+ export declare class ASTNullLiteralValue extends ASTObjectNode<Malloy.LiteralValueWithNullLiteral, {
601
+ kind: 'null_literal';
602
+ }> {
603
+ node: Malloy.LiteralValueWithNullLiteral;
604
+ readonly kind: Malloy.LiteralValueType;
605
+ constructor(node: Malloy.LiteralValueWithNullLiteral);
606
+ }
607
+ export declare class ASTNumberLiteralValue extends ASTObjectNode<Malloy.LiteralValueWithNumberLiteral, {
608
+ kind: 'number_literal';
609
+ number_value: number;
610
+ }> {
611
+ node: Malloy.LiteralValueWithNumberLiteral;
612
+ readonly kind: Malloy.LiteralValueType;
613
+ constructor(node: Malloy.LiteralValueWithNumberLiteral);
614
+ }
615
+ export declare class ASTBooleanLiteralValue extends ASTObjectNode<Malloy.LiteralValueWithBooleanLiteral, {
616
+ kind: 'boolean_literal';
617
+ boolean_value: boolean;
618
+ }> {
619
+ node: Malloy.LiteralValueWithBooleanLiteral;
620
+ readonly kind: Malloy.LiteralValueType;
621
+ constructor(node: Malloy.LiteralValueWithBooleanLiteral);
622
+ }
623
+ export declare class ASTDateLiteralValue extends ASTObjectNode<Malloy.LiteralValueWithDateLiteral, {
624
+ kind: 'date_literal';
625
+ date_value: string;
626
+ granularity?: Malloy.DateTimeframe;
627
+ }> {
628
+ node: Malloy.LiteralValueWithDateLiteral;
629
+ readonly kind: Malloy.LiteralValueType;
630
+ constructor(node: Malloy.LiteralValueWithDateLiteral);
631
+ }
632
+ export declare class ASTTimestampLiteralValue extends ASTObjectNode<Malloy.LiteralValueWithTimestampLiteral, {
633
+ kind: 'timestamp_literal';
634
+ timestamp_value: string;
635
+ granularity?: Malloy.TimestampTimeframe;
636
+ }> {
637
+ node: Malloy.LiteralValueWithTimestampLiteral;
638
+ readonly kind: Malloy.LiteralValueType;
639
+ constructor(node: Malloy.LiteralValueWithTimestampLiteral);
640
+ }
641
+ export declare class ASTUnimplemented<T> extends ASTNode<T> {
642
+ private readonly node;
643
+ constructor(node: T);
644
+ get treeEdited(): boolean;
645
+ build(): T;
646
+ find(): never;
647
+ }
648
+ export interface IASTQueryOrViewDefinition {
649
+ /**
650
+ * Upward propagation of field deletion/rename etc
651
+ * @internal
652
+ */
653
+ propagateUp(f: PropagationFunction): void;
654
+ /**
655
+ * Downward propagation of field deletion/rename etc
656
+ * @internal
657
+ */
658
+ propagateDown(f: PropagationFunction): void;
659
+ }
660
+ type PropagationFunction = (propagatable: IASTQueryOrViewDefinition) => void;
661
+ export interface IASTQueryDefinition extends IASTQueryOrViewDefinition {
662
+ getOrAddDefaultSegment(): ASTSegmentViewDefinition;
663
+ reorderFields(names: string[]): void;
664
+ isRunnable(): boolean;
665
+ }
666
+ export type ASTQueryDefinition = ASTReferenceQueryDefinition | ASTArrowQueryDefinition | ASTRefinementQueryDefinition;
667
+ export declare const ASTQueryDefinition: {
668
+ from: (definition: Malloy.QueryDefinition) => ASTArrowQueryDefinition | ASTReferenceQueryDefinition | ASTRefinementQueryDefinition;
669
+ };
670
+ export declare class ASTArrowQueryDefinition extends ASTObjectNode<Malloy.QueryDefinitionWithArrow, {
671
+ kind: 'arrow';
672
+ source_reference: ASTSourceReference;
673
+ view: ASTViewDefinition;
674
+ }> implements IASTQueryDefinition {
675
+ node: Malloy.QueryDefinitionWithArrow;
676
+ constructor(node: Malloy.QueryDefinitionWithArrow);
677
+ get view(): ASTViewDefinition;
678
+ set view(view: ASTViewDefinition);
679
+ get sourceReference(): ASTSourceReference;
680
+ getOrAddDefaultSegment(): ASTSegmentViewDefinition;
681
+ getSourceInfo(): Malloy.SourceInfo;
682
+ getOutputSchema(): Malloy.Schema;
683
+ isRunnable(): boolean;
684
+ /**
685
+ * @internal
686
+ */
687
+ get query(): ASTQuery;
688
+ /**
689
+ * @internal
690
+ */
691
+ propagateUp(f: PropagationFunction): void;
692
+ /**
693
+ * @internal
694
+ */
695
+ propagateDown(f: PropagationFunction): void;
696
+ reorderFields(names: string[]): void;
697
+ }
698
+ export declare class ASTRefinementQueryDefinition extends ASTObjectNode<Malloy.QueryDefinitionWithRefinement, {
699
+ kind: 'refinement';
700
+ query_reference: ASTReference;
701
+ refinement: ASTViewDefinition;
702
+ }> implements IASTQueryDefinition {
703
+ node: Malloy.QueryDefinitionWithRefinement;
704
+ constructor(node: Malloy.QueryDefinitionWithRefinement);
705
+ get queryReference(): ASTReference;
706
+ get refinement(): ASTViewDefinition;
707
+ set refinement(refinement: ASTViewDefinition);
708
+ isRunnable(): boolean;
709
+ /**
710
+ * @internal
711
+ */
712
+ get query(): ASTQuery;
713
+ getOrAddDefaultSegment(): ASTSegmentViewDefinition;
714
+ getOutputSchema(): Malloy.Schema;
715
+ /**
716
+ * @internal
717
+ */
718
+ propagateUp(f: PropagationFunction): void;
719
+ /**
720
+ * @internal
721
+ */
722
+ propagateDown(f: PropagationFunction): void;
723
+ reorderFields(names: string[]): void;
724
+ }
725
+ export declare class ASTReferenceQueryDefinition extends ASTObjectNode<Malloy.QueryDefinitionWithQueryReference, {
726
+ kind: 'query_reference';
727
+ name: string;
728
+ path?: string[];
729
+ parameters?: ASTParameterValueList;
730
+ }> implements IASTQueryDefinition, IASTReference {
731
+ node: Malloy.QueryDefinitionWithQueryReference;
732
+ constructor(node: Malloy.QueryDefinitionWithQueryReference);
733
+ isRunnable(): boolean;
734
+ get name(): string;
735
+ get query(): ASTQuery;
736
+ get parameters(): ASTParameterValueList | undefined;
737
+ set parameters(parameters: ASTParameterValueList | undefined);
738
+ get path(): string[] | undefined;
739
+ getOrAddDefaultSegment(): ASTSegmentViewDefinition;
740
+ /**
741
+ * @internal
742
+ */
743
+ propagateUp(_f: PropagationFunction): void;
744
+ /**
745
+ * @internal
746
+ */
747
+ propagateDown(_f: PropagationFunction): void;
748
+ reorderFields(names: string[]): void;
749
+ getOrAddParameters(): any;
750
+ setParameter(name: string, value: RawLiteralValue): void;
751
+ tryGetParameter(name: string): ASTParameterValue | undefined;
752
+ }
753
+ export interface IASTViewDefinition extends IASTQueryOrViewDefinition {
754
+ isRunnable(): boolean;
755
+ getOrAddDefaultSegment(): ASTSegmentViewDefinition;
756
+ getInputSchema(): Malloy.Schema;
757
+ getOutputSchema(): Malloy.Schema;
758
+ getImplicitName(): string | undefined;
759
+ getRefinementSchema(): Malloy.Schema;
760
+ addEmptyRefinement(): ASTSegmentViewDefinition;
761
+ addViewRefinement(name: string, path?: string[]): ASTReferenceViewDefinition;
762
+ isValidViewRefinement(name: string, path?: string[]): {
763
+ isValidViewRefinement: boolean;
764
+ error?: string;
765
+ };
766
+ getInheritedAnnotations(): Malloy.Annotation[];
767
+ }
768
+ export type ASTViewDefinition = ASTArrowViewDefinition | ASTRefinementViewDefinition | ASTSegmentViewDefinition | ASTReferenceViewDefinition;
769
+ export declare class ASTReferenceViewDefinition extends ASTObjectNode<Malloy.ViewDefinitionWithViewReference, {
770
+ kind: 'view_reference';
771
+ name: string;
772
+ path?: string[];
773
+ parameters?: ASTParameterValueList;
774
+ }> implements IASTViewDefinition, IASTReference {
775
+ node: Malloy.ViewDefinitionWithViewReference;
776
+ constructor(node: Malloy.ViewDefinitionWithViewReference);
777
+ isRunnable(): boolean;
778
+ get name(): string;
779
+ get path(): string[] | undefined;
780
+ get parameters(): ASTParameterValueList | undefined;
781
+ set parameters(parameters: ASTParameterValueList | undefined);
782
+ getOrAddDefaultSegment(): ASTSegmentViewDefinition;
783
+ addEmptyRefinement(): ASTSegmentViewDefinition;
784
+ addViewRefinement(name: string, path?: string[]): ASTReferenceViewDefinition;
785
+ isValidViewRefinement(name: string, path?: string[]): {
786
+ isValidViewRefinement: boolean;
787
+ error?: string;
788
+ };
789
+ getInputSchema(): Malloy.Schema;
790
+ getOutputSchema(): Malloy.Schema;
791
+ getImplicitName(): string | undefined;
792
+ getViewInfo(): Malloy.FieldInfoWithView;
793
+ getRefinementSchema(): Malloy.Schema;
794
+ /**
795
+ * @internal
796
+ */
797
+ propagateUp(f: PropagationFunction): void;
798
+ /**
799
+ * @internal
800
+ */
801
+ propagateDown(_f: PropagationFunction): void;
802
+ getInheritedAnnotations(): Malloy.Annotation[];
803
+ getOrAddParameters(): any;
804
+ setParameter(name: string, value: RawLiteralValue): void;
805
+ tryGetParameter(name: string): ASTParameterValue | undefined;
806
+ }
807
+ export declare class ASTArrowViewDefinition extends ASTObjectNode<Malloy.ViewDefinitionWithArrow, {
808
+ kind: 'arrow';
809
+ source: ASTViewDefinition;
810
+ view: ASTViewDefinition;
811
+ }> implements IASTViewDefinition {
812
+ node: Malloy.ViewDefinitionWithArrow;
813
+ constructor(node: Malloy.ViewDefinitionWithArrow);
814
+ isRunnable(): boolean;
815
+ get source(): ASTViewDefinition;
816
+ set source(source: ASTViewDefinition);
817
+ get view(): ASTViewDefinition;
818
+ set view(view: ASTViewDefinition);
819
+ getOrAddDefaultSegment(): ASTSegmentViewDefinition;
820
+ addEmptyRefinement(): ASTSegmentViewDefinition;
821
+ addViewRefinement(name: string, path?: string[]): ASTReferenceViewDefinition;
822
+ getInputSchema(): Malloy.Schema;
823
+ getOutputSchema(): Malloy.Schema;
824
+ getImplicitName(): string | undefined;
825
+ getRefinementSchema(): Malloy.Schema;
826
+ isValidViewRefinement(name: string, path?: string[]): {
827
+ isValidViewRefinement: boolean;
828
+ error?: string;
829
+ };
830
+ /**
831
+ * @internal
832
+ */
833
+ propagateUp(f: PropagationFunction): void;
834
+ /**
835
+ * @internal
836
+ */
837
+ propagateDown(f: PropagationFunction): void;
838
+ getInheritedAnnotations(): Malloy.Annotation[];
839
+ }
840
+ export declare class ASTRefinementViewDefinition extends ASTObjectNode<Malloy.ViewDefinitionWithRefinement, {
841
+ kind: 'refinement';
842
+ base: ASTViewDefinition;
843
+ refinement: ASTViewDefinition;
844
+ }> implements IASTViewDefinition {
845
+ node: Malloy.ViewDefinitionWithRefinement;
846
+ constructor(node: Malloy.ViewDefinitionWithRefinement);
847
+ isRunnable(): boolean;
848
+ get refinement(): ASTViewDefinition;
849
+ set refinement(refinement: ASTViewDefinition);
850
+ get base(): ASTViewDefinition;
851
+ set base(base: ASTViewDefinition);
852
+ getOrAddDefaultSegment(): ASTSegmentViewDefinition;
853
+ addEmptyRefinement(): ASTSegmentViewDefinition;
854
+ addViewRefinement(name: string, path?: string[]): ASTReferenceViewDefinition;
855
+ getInputSchema(): Malloy.Schema;
856
+ getOutputSchema(): Malloy.Schema;
857
+ getRefinementSchema(): Malloy.Schema;
858
+ getImplicitName(): string | undefined;
859
+ isValidViewRefinement(name: string, path?: string[]): {
860
+ isValidViewRefinement: boolean;
861
+ error?: string;
862
+ };
863
+ /**
864
+ * @internal
865
+ */
866
+ propagateUp(f: PropagationFunction): void;
867
+ /**
868
+ * @internal
869
+ */
870
+ propagateDown(f: PropagationFunction): void;
871
+ getInheritedAnnotations(): Malloy.Annotation[];
872
+ /**
873
+ * @internal
874
+ */
875
+ static viewRefinementOf(view: Malloy.ViewDefinition, name: string, path?: string[]): ASTRefinementViewDefinition;
876
+ /**
877
+ * @internal
878
+ */
879
+ static segmentRefinementOf(view: Malloy.ViewDefinition): ASTRefinementViewDefinition;
880
+ }
881
+ export declare class ASTSegmentViewDefinition extends ASTObjectNode<Malloy.ViewDefinitionWithSegment, {
882
+ kind: 'segment';
883
+ operations: ASTViewOperationList;
884
+ }> implements IASTViewDefinition {
885
+ node: Malloy.ViewDefinitionWithSegment;
886
+ constructor(node: Malloy.ViewDefinitionWithSegment);
887
+ isRunnable(): boolean;
888
+ get operations(): ASTViewOperationList;
889
+ /**
890
+ * @internal
891
+ */
892
+ renameOrderBys(oldName: string, newName: string): void;
893
+ /**
894
+ * @internal
895
+ */
896
+ propagateUp(f: PropagationFunction): void;
897
+ /**
898
+ * @internal
899
+ */
900
+ propagateDown(_f: PropagationFunction): void;
901
+ /**
902
+ * @internal
903
+ */
904
+ removeOrderBys(name: string): void;
905
+ reorderFields(names: string[]): void;
906
+ renameField(field: ASTAggregateViewOperation | ASTGroupByViewOperation | ASTNestViewOperation, name: string): void;
907
+ /**
908
+ * Adds an order by to the segment. Will override the direction of an existing order by
909
+ * if one is present for the same field.
910
+ *
911
+ * ```
912
+ * run: flights -> { group_by: carrier }
913
+ * ```
914
+ * ```ts
915
+ * q.getOrAddDefaultSegment().addOrderBy("carrier", Malloy.OrderByDirection.DESC);
916
+ * ```
917
+ * ```
918
+ * run: flights -> {
919
+ * group_by: carrier
920
+ * order_by: carrier desc
921
+ * }
922
+ * ```
923
+ *
924
+ * The order by item is added after an existing order by operation if one is present,
925
+ * or to a new order by operation at the end of the query.
926
+ *
927
+ * @param name The name of the field to order by.
928
+ * @param direction The order by direction (ascending or descending).
929
+ */
930
+ addOrderBy(name: string, direction?: Malloy.OrderByDirection): void;
931
+ /**
932
+ * Adds an empty nest to this segment, with the given name.
933
+ * @param name The name of the new nest.
934
+ *
935
+ * The new nest is always added to the end of the query in a new nest block.
936
+ *
937
+ * ```
938
+ * run: flights -> { group_by: carrier }
939
+ * ```
940
+ * ```ts
941
+ * q.getOrAddDefaultSegment().addEmptyNest("by_origin");
942
+ * ```
943
+ * ```
944
+ * run: flights -> {
945
+ * group_by: carrier
946
+ * nest: by_origin is { }
947
+ * }
948
+ * ```
949
+ *
950
+ * @returns The {@link ASTNestViewOperation} that was created.
951
+ *
952
+ */
953
+ addEmptyNest(name: string): ASTNestViewOperation;
954
+ private firstIndexOfOperationType;
955
+ private DEFAULT_INSERTION_ORDER;
956
+ private findInsertionPoint;
957
+ getFieldNamed(name: string): ASTGroupByViewOperation | ASTAggregateViewOperation | ASTNestViewOperation | undefined;
958
+ hasFieldNamed(name: string): boolean;
959
+ hasField(name: string, path?: string[]): boolean;
960
+ getField(name: string, path?: string[]): ASTGroupByViewOperation | ASTAggregateViewOperation | ASTNestViewOperation;
961
+ tryGetField(name: string, path?: string[]): ASTGroupByViewOperation | ASTAggregateViewOperation | ASTNestViewOperation | undefined;
962
+ tryGetFieldNamed(name: string): ASTGroupByViewOperation | ASTAggregateViewOperation | ASTNestViewOperation | undefined;
963
+ getGroupBy(name: string): ASTGroupByViewOperation | undefined;
964
+ removeGroupBy(name: string): this;
965
+ /**
966
+ * Adds a group by field with the given name to this segment.
967
+ *
968
+ * ```
969
+ * run: flights -> { }
970
+ * ```
971
+ * ```ts
972
+ * q.getOrAddDefaultSegment().addGroupBy("carrier");
973
+ * ```
974
+ * ```
975
+ * run: flights -> { group_by: carrier }
976
+ * ```
977
+ *
978
+ * If there is already a group by clause, the new field will be added
979
+ * to that clause (or the first one if there are multiple).
980
+ *
981
+ * ```
982
+ * run: flights -> { group_by: carrier }
983
+ * ```
984
+ * ```ts
985
+ * q.getOrAddDefaultSegment().addGroupBy("origin_code");
986
+ * ```
987
+ * ```
988
+ * run: flights -> {
989
+ * group_by:
990
+ * carrier
991
+ * origin_code
992
+ * }
993
+ * ```
994
+ *
995
+ * If there is no group by clause, it will be added
996
+ * 1) before the first aggregate clause if there is one, or
997
+ * 2) before the first nest clause if there is one, or
998
+ * 3) before the first order by clause if ther is one, or
999
+ * 4) at the end of the query
1000
+ *
1001
+ * ```
1002
+ * run: flights -> {
1003
+ * order_by: flight_count
1004
+ * aggregate: flight_count
1005
+ * }
1006
+ * ```
1007
+ * ```ts
1008
+ * q.getOrAddDefaultSegment().addGroupBy("carrier");
1009
+ * ```
1010
+ * ```
1011
+ * run: flights -> {
1012
+ * order_by: flight_count
1013
+ * group_by: carrier
1014
+ * aggregate: flight_count
1015
+ * }
1016
+ * ```
1017
+ *
1018
+ * @param name The name of the dimension to group by.
1019
+ * @param path Join path for this dimension.
1020
+ */
1021
+ addGroupBy(name: string, path?: string[], rename?: string): ASTGroupByViewOperation;
1022
+ addWhere(name: string, filter: ParsedFilter): ASTWhereViewOperation;
1023
+ addWhere(name: string, filterString: string): ASTWhereViewOperation;
1024
+ addWhere(name: string, path: string[], filter: ParsedFilter): ASTWhereViewOperation;
1025
+ addWhere(name: string, path: string[], filterString: string): ASTWhereViewOperation;
1026
+ private addTimeGroupBy;
1027
+ addDateGroupBy(name: string, path: string[], timeframe: Malloy.DateTimeframe): ASTGroupByViewOperation;
1028
+ addDateGroupBy(name: string, timeframe: Malloy.DateTimeframe): ASTGroupByViewOperation;
1029
+ addTimestampGroupBy(name: string, path: string[], timeframe: Malloy.TimestampTimeframe): ASTGroupByViewOperation;
1030
+ addTimestampGroupBy(name: string, timeframe: Malloy.TimestampTimeframe): ASTGroupByViewOperation;
1031
+ /**
1032
+ * Adds an aggregate item with the given name to this segment.
1033
+ *
1034
+ * ```
1035
+ * run: flights -> { }
1036
+ * ```
1037
+ * ```ts
1038
+ * q.getOrAddDefaultSegment().addAggregate("flight_count");
1039
+ * ```
1040
+ * ```
1041
+ * run: flights -> { aggregate: flight_count }
1042
+ * ```
1043
+ *
1044
+ * Added
1045
+ * 1) at the end of an existing aggregate clause if ther is one, or
1046
+ * 2) before the first nest clause if there is one, or
1047
+ * 3) before the first order by clause if ther is one, or
1048
+ * 4) at the end of the query
1049
+ *
1050
+ * @param name The name of the measure to aggregate.
1051
+ * @param path The join path of the measure to aggregate.
1052
+ * @param rename A new name for this measure
1053
+ */
1054
+ addAggregate(name: string, path?: string[], rename?: string): ASTAggregateViewOperation;
1055
+ /**
1056
+ * Adds a nest item with the given name to this segment.
1057
+ *
1058
+ * ```
1059
+ * run: flights -> { }
1060
+ * ```
1061
+ * ```ts
1062
+ * q.getOrAddDefaultSegment().addNest("by_carrier");
1063
+ * ```
1064
+ * ```
1065
+ * run: flights -> { nest: by_carrier }
1066
+ * ```
1067
+ *
1068
+ * Added
1069
+ * 1) at the end of an existing nest clause if there is one, or
1070
+ * 2) before the first order by clause if ther is one, or
1071
+ * 3) at the end of the query
1072
+ *
1073
+ * @param name The name of the view to nest.
1074
+ * @param rename A new name for this view in the query
1075
+ */
1076
+ addNest(name: string, rename?: string): ASTNestViewOperation;
1077
+ private makeField;
1078
+ private addOperation;
1079
+ /**
1080
+ * @internal
1081
+ */
1082
+ getRefinementSchema(): Malloy.Schema;
1083
+ /**
1084
+ * Sets the limit for this segment. Overrides an existing limit.
1085
+ *
1086
+ * ```
1087
+ * run: flights -> { group_by: carrier }
1088
+ * ```
1089
+ * ```ts
1090
+ * q.getOrAddDefaultSegment().setLimit(10);
1091
+ * ```
1092
+ * ```
1093
+ * run: flights -> {
1094
+ * group_by: carrier
1095
+ * limit: 10
1096
+ * }
1097
+ * ```
1098
+ *
1099
+ * @param limit The limit to set. Must be an integer.
1100
+ */
1101
+ setLimit(limit: number): void;
1102
+ getOrAddDefaultSegment(): ASTSegmentViewDefinition;
1103
+ addEmptyRefinement(): ASTSegmentViewDefinition;
1104
+ addViewRefinement(name: string, path?: string[]): ASTReferenceViewDefinition;
1105
+ getInputSchema(): Malloy.Schema;
1106
+ getOutputSchema(): Malloy.Schema;
1107
+ getImplicitName(): string | undefined;
1108
+ isValidViewRefinement(name: string, path?: string[]): {
1109
+ isValidViewRefinement: boolean;
1110
+ error?: string;
1111
+ };
1112
+ getInheritedAnnotations(): Malloy.Annotation[];
1113
+ }
1114
+ export declare class ASTViewOperationList extends ASTListNode<Malloy.ViewOperation, ASTViewOperation> {
1115
+ constructor(operations: Malloy.ViewOperation[]);
1116
+ get items(): ASTViewOperation[];
1117
+ /**
1118
+ * @internal
1119
+ */
1120
+ set items(operations: ASTViewOperation[]);
1121
+ /**
1122
+ * @internal
1123
+ */
1124
+ get segment(): ASTSegmentViewDefinition;
1125
+ }
1126
+ export type ASTViewOperation = ASTGroupByViewOperation | ASTAggregateViewOperation | ASTOrderByViewOperation | ASTNestViewOperation | ASTLimitViewOperation | ASTWhereViewOperation;
1127
+ export declare const ASTViewOperation: {
1128
+ from(value: Malloy.ViewOperation): ASTViewOperation;
1129
+ isLimit(x: ASTViewOperation): x is ASTLimitViewOperation;
1130
+ };
1131
+ export interface IASTAnnotatable {
1132
+ getOrAddAnnotations(): ASTAnnotationList;
1133
+ getInheritedTag(prefix: RegExp | string): Tag;
1134
+ getIntrinsicTag(prefix: RegExp | string): Tag;
1135
+ getTag(prefix: RegExp | string): Tag;
1136
+ setTagProperty(path: Path, value: TagSetValue, prefix: string): void;
1137
+ removeTagProperty(path: Path, prefix: string): void;
1138
+ }
1139
+ export declare class ASTOrderByViewOperation extends ASTObjectNode<Malloy.ViewOperationWithOrderBy, {
1140
+ kind: 'order_by';
1141
+ field_reference: ASTFieldReference;
1142
+ direction?: Malloy.OrderByDirection;
1143
+ }> {
1144
+ node: Malloy.ViewOperationWithOrderBy;
1145
+ readonly kind: Malloy.ViewOperationType;
1146
+ constructor(node: Malloy.ViewOperationWithOrderBy);
1147
+ get fieldReference(): ASTFieldReference;
1148
+ get name(): string;
1149
+ get direction(): Malloy.OrderByDirection | undefined;
1150
+ set direction(direction: Malloy.OrderByDirection | undefined);
1151
+ get list(): ASTViewOperationList;
1152
+ delete(): void;
1153
+ setField(name: string): void;
1154
+ setDirection(direction: Malloy.OrderByDirection | undefined): void;
1155
+ }
1156
+ export declare class ASTGroupByViewOperation extends ASTObjectNode<Malloy.ViewOperationWithGroupBy, {
1157
+ kind: 'group_by';
1158
+ name?: string;
1159
+ field: ASTField;
1160
+ }> implements IASTAnnotatable {
1161
+ node: Malloy.ViewOperationWithGroupBy;
1162
+ readonly kind: Malloy.ViewOperationType;
1163
+ constructor(node: Malloy.ViewOperationWithGroupBy);
1164
+ get field(): ASTField;
1165
+ get name(): string;
1166
+ set name(name: string);
1167
+ /**
1168
+ * @internal
1169
+ */
1170
+ get list(): ASTViewOperationList;
1171
+ /**
1172
+ * Renames the group by item. If the field's name matches the given name,
1173
+ * removes the `name is` part.
1174
+ *
1175
+ * ```
1176
+ * run: flights -> { group_by: carrier }
1177
+ * ```
1178
+ * ```ts
1179
+ * groupBy.rename("carrier_2");
1180
+ * ```
1181
+ * ```
1182
+ * run: flights -> { group_by: carrier2 is carrier }
1183
+ * ```
1184
+ *
1185
+ * ```
1186
+ * run: flights -> { group_by: renamed is carrier }
1187
+ * ```
1188
+ * ```ts
1189
+ * groupBy.rename("carrier");
1190
+ * ```
1191
+ * ```
1192
+ * run: flights -> { group_by: carrier }
1193
+ * ```
1194
+ *
1195
+ *
1196
+ * @param name The new name
1197
+ */
1198
+ rename(name: string): void;
1199
+ /**
1200
+ * Delete this group by item.
1201
+ *
1202
+ * Possible side effects:
1203
+ * - If this was the last item in the group by operation, the whole
1204
+ * operation is removed.
1205
+ * - Any order by that references this group by item will be removed.
1206
+ *
1207
+ * ```
1208
+ * run: flights -> {
1209
+ * group_by: carrier
1210
+ * aggregate: flight_count
1211
+ * order by:
1212
+ * flight_count desc
1213
+ * carrier asc
1214
+ * }
1215
+ * ```
1216
+ * ```ts
1217
+ * groupBy.delete();
1218
+ * ```
1219
+ * ```
1220
+ * run: flights -> {
1221
+ * aggregate: flight_count
1222
+ * order by: flight_count desc
1223
+ * }
1224
+ * ```
1225
+ *
1226
+ */
1227
+ delete(): void;
1228
+ getFieldInfo(): Malloy.FieldInfo;
1229
+ private get annotations();
1230
+ private set annotations(value);
1231
+ getOrAddAnnotations(): ASTAnnotationList;
1232
+ getInheritedTag(prefix?: RegExp | string): Tag;
1233
+ getIntrinsicTag(prefix?: RegExp | string): Tag;
1234
+ getTag(prefix?: RegExp | string): Tag;
1235
+ setTagProperty(path: Path, value?: TagSetValue, prefix?: string): void;
1236
+ removeTagProperty(path: Path, prefix?: string): void;
1237
+ /**
1238
+ * @internal
1239
+ */
1240
+ static fromReference(name: string, path: string[] | undefined, rename: string | undefined): ASTGroupByViewOperation;
1241
+ }
1242
+ export declare class ASTAggregateViewOperation extends ASTObjectNode<Malloy.ViewOperationWithAggregate, {
1243
+ kind: 'aggregate';
1244
+ name?: string;
1245
+ field: ASTField;
1246
+ }> implements IASTAnnotatable {
1247
+ node: Malloy.ViewOperationWithAggregate;
1248
+ readonly kind: Malloy.ViewOperationType;
1249
+ constructor(node: Malloy.ViewOperationWithAggregate);
1250
+ get field(): ASTField;
1251
+ get name(): string;
1252
+ set name(name: string);
1253
+ get annotations(): ASTAnnotationList | undefined;
1254
+ /**
1255
+ * Renames the aggregate item. If the field's name matches the given name,
1256
+ * removes the `name is` part.
1257
+ *
1258
+ * ```
1259
+ * run: flights -> { aggregate: flight_count }
1260
+ * ```
1261
+ * ```ts
1262
+ * aggregate.rename("flight_count_2");
1263
+ * ```
1264
+ * ```
1265
+ * run: flights -> { aggregate: flight_count2 is flight_count }
1266
+ * ```
1267
+ *
1268
+ * ```
1269
+ * run: flights -> { aggregate: renamed is flight_count }
1270
+ * ```
1271
+ * ```ts
1272
+ * aggregate.rename("flight_count");
1273
+ * ```
1274
+ * ```
1275
+ * run: flights -> { aggregate: flight_count }
1276
+ * ```
1277
+ *
1278
+ *
1279
+ * @param name The new name
1280
+ */
1281
+ rename(name: string): void;
1282
+ /**
1283
+ * @internal
1284
+ */
1285
+ get list(): ASTViewOperationList;
1286
+ delete(): void;
1287
+ getFieldInfo(): Malloy.FieldInfo;
1288
+ getOrAddAnnotations(): ASTAnnotationList;
1289
+ getInheritedTag(prefix?: RegExp | string): Tag;
1290
+ getIntrinsicTag(prefix?: RegExp | string): Tag;
1291
+ getTag(prefix?: RegExp | string): Tag;
1292
+ setTagProperty(path: Path, value?: TagSetValue, prefix?: string): void;
1293
+ removeTagProperty(path: Path, prefix?: string): void;
1294
+ addWhere(name: string, path: string[], filterString: string): ASTFilteredFieldExpression;
1295
+ addWhere(name: string, path: string[], filter: ParsedFilter): ASTFilteredFieldExpression;
1296
+ addWhere(name: string, filterString: string): ASTFilteredFieldExpression;
1297
+ addWhere(name: string, filter: ParsedFilter): ASTFilteredFieldExpression;
1298
+ /**
1299
+ * @internal
1300
+ */
1301
+ static fromReference(name: string, path: string[] | undefined, rename: string | undefined): ASTAggregateViewOperation;
1302
+ }
1303
+ export declare class ASTField extends ASTObjectNode<Malloy.Field, {
1304
+ expression: ASTExpression;
1305
+ annotations?: ASTAnnotationList;
1306
+ }> implements IASTAnnotatable {
1307
+ node: Malloy.Field;
1308
+ constructor(node: Malloy.Field);
1309
+ get expression(): ASTExpression;
1310
+ set expression(expression: ASTExpression);
1311
+ get name(): string;
1312
+ get type(): Malloy.AtomicType | {
1313
+ timeframe: Malloy.DateTimeframe;
1314
+ kind: "date_type";
1315
+ } | {
1316
+ timeframe: Malloy.TimestampTimeframe;
1317
+ kind: "timestamp_type";
1318
+ };
1319
+ get annotations(): ASTAnnotationList | undefined;
1320
+ set annotations(annotations: ASTAnnotationList | undefined);
1321
+ getReference(): Malloy.Reference;
1322
+ getOrAddAnnotations(): ASTAnnotationList;
1323
+ getInheritedTag(prefix?: RegExp | string): Tag;
1324
+ getIntrinsicTag(prefix?: RegExp | string): Tag;
1325
+ getTag(prefix?: RegExp | string): Tag;
1326
+ setTagProperty(path: Path, value?: TagSetValue, prefix?: string): void;
1327
+ removeTagProperty(path: Path, prefix?: string): void;
1328
+ /**
1329
+ * @internal
1330
+ */
1331
+ get segment(): ASTSegmentViewDefinition;
1332
+ getInheritedAnnotations(): Malloy.Annotation[];
1333
+ }
1334
+ export type ASTExpression = ASTReferenceExpression | ASTFilteredFieldExpression | ASTTimeTruncationExpression;
1335
+ export declare const ASTExpression: {
1336
+ from(value: Malloy.Expression): ASTExpression;
1337
+ };
1338
+ export declare class ASTReferenceExpression extends ASTObjectNode<Malloy.ExpressionWithFieldReference, {
1339
+ kind: 'field_reference';
1340
+ name: string;
1341
+ path?: string[];
1342
+ parameters?: ASTParameterValueList;
1343
+ }> implements IASTReference {
1344
+ node: Malloy.ExpressionWithFieldReference;
1345
+ readonly kind: Malloy.ExpressionType;
1346
+ constructor(node: Malloy.ExpressionWithFieldReference);
1347
+ get name(): string;
1348
+ get parameters(): ASTParameterValueList | undefined;
1349
+ set parameters(parameters: ASTParameterValueList | undefined);
1350
+ /**
1351
+ * @internal
1352
+ */
1353
+ get field(): ASTField;
1354
+ get path(): string[] | undefined;
1355
+ getReference(): Malloy.ExpressionWithFieldReference;
1356
+ getFieldInfo(): Malloy.FieldInfoWithDimension | Malloy.FieldInfoWithMeasure;
1357
+ get fieldType(): Malloy.AtomicType;
1358
+ getInheritedAnnotations(): Malloy.Annotation[];
1359
+ getOrAddParameters(): any;
1360
+ setParameter(name: string, value: RawLiteralValue): void;
1361
+ tryGetParameter(name: string): ASTParameterValue | undefined;
1362
+ }
1363
+ export declare class ASTTimeTruncationExpression extends ASTObjectNode<Malloy.ExpressionWithTimeTruncation, {
1364
+ kind: 'time_truncation';
1365
+ field_reference: ASTFieldReference;
1366
+ truncation: Malloy.TimestampTimeframe;
1367
+ }> {
1368
+ node: Malloy.ExpressionWithTimeTruncation;
1369
+ readonly kind: Malloy.ExpressionType;
1370
+ constructor(node: Malloy.ExpressionWithTimeTruncation);
1371
+ getReference(): Malloy.Reference;
1372
+ get fieldReference(): ASTFieldReference;
1373
+ get truncation(): Malloy.TimestampTimeframe;
1374
+ get name(): string;
1375
+ /**
1376
+ * @internal
1377
+ */
1378
+ get field(): ASTField;
1379
+ getFieldInfo(): Malloy.FieldInfoWithDimension | Malloy.FieldInfoWithMeasure;
1380
+ get fieldType(): {
1381
+ timeframe: Malloy.DateTimeframe;
1382
+ kind: "date_type";
1383
+ } | {
1384
+ timeframe: Malloy.TimestampTimeframe;
1385
+ kind: "timestamp_type";
1386
+ };
1387
+ getInheritedAnnotations(): Malloy.Annotation[];
1388
+ }
1389
+ export declare class ASTWhere extends ASTObjectNode<Malloy.Where, {
1390
+ filter: ASTFilter;
1391
+ }> {
1392
+ constructor(node: Malloy.Where);
1393
+ get filter(): ASTFilterWithFilterString;
1394
+ get list(): ASTWhereList;
1395
+ delete(): void;
1396
+ }
1397
+ export declare class ASTWhereList extends ASTListNode<Malloy.Where, ASTWhere> {
1398
+ constructor(wheres: Malloy.Where[]);
1399
+ get expression(): ASTFilteredFieldExpression;
1400
+ }
1401
+ export declare class ASTFilteredFieldExpression extends ASTObjectNode<Malloy.ExpressionWithFilteredField, {
1402
+ kind: 'filtered_field';
1403
+ field_reference: ASTFieldReference;
1404
+ where: ASTWhereList;
1405
+ }> {
1406
+ node: Malloy.ExpressionWithFilteredField;
1407
+ readonly kind: Malloy.ExpressionType;
1408
+ constructor(node: Malloy.ExpressionWithFilteredField);
1409
+ getReference(): Malloy.Reference;
1410
+ get fieldReference(): ASTFieldReference;
1411
+ get name(): string;
1412
+ get where(): ASTWhereList;
1413
+ /**
1414
+ * @internal
1415
+ */
1416
+ get field(): ASTField;
1417
+ getFieldInfo(): Malloy.FieldInfoWithMeasure;
1418
+ get fieldType(): Malloy.AtomicType;
1419
+ getInheritedAnnotations(): Malloy.Annotation[];
1420
+ }
1421
+ export declare class ASTNestViewOperation extends ASTObjectNode<Malloy.ViewOperationWithNest, {
1422
+ kind: 'nest';
1423
+ name?: string;
1424
+ view: ASTView;
1425
+ }> implements IASTAnnotatable {
1426
+ node: Malloy.ViewOperationWithNest;
1427
+ readonly kind: Malloy.ViewOperationType;
1428
+ constructor(node: Malloy.ViewOperationWithNest);
1429
+ get view(): ASTView;
1430
+ get annotations(): ASTAnnotationList | undefined;
1431
+ get name(): string;
1432
+ set name(name: string);
1433
+ /**
1434
+ * @internal
1435
+ */
1436
+ get list(): ASTViewOperationList;
1437
+ getOrAddAnnotations(): ASTAnnotationList;
1438
+ getInheritedTag(prefix?: RegExp | string): Tag;
1439
+ getIntrinsicTag(prefix?: RegExp | string): Tag;
1440
+ getTag(prefix?: RegExp | string): Tag;
1441
+ setTagProperty(path: Path, value?: TagSetValue, prefix?: string): void;
1442
+ removeTagProperty(path: Path, prefix?: string): void;
1443
+ delete(): void;
1444
+ /**
1445
+ * Renames the nest item. If the view's name matches the given name,
1446
+ * removes the `name is` part.
1447
+ *
1448
+ * ```
1449
+ * run: flights -> { nest: by_carrier }
1450
+ * ```
1451
+ * ```ts
1452
+ * nest.rename("by_carrier_2");
1453
+ * ```
1454
+ * ```
1455
+ * run: flights -> { nest: by_carrier_2 is by_carrier }
1456
+ * ```
1457
+ *
1458
+ * ```
1459
+ * run: flights -> { nest: by_carrier_2 is by_carrier }
1460
+ * ```
1461
+ * ```ts
1462
+ * nest.rename("by_carrier");
1463
+ * ```
1464
+ * ```
1465
+ * run: flights -> { nest: by_carrier }
1466
+ * ```
1467
+ *
1468
+ * ```
1469
+ * run: flights -> {
1470
+ * nest: by_carrier is {
1471
+ * group_by: carrier
1472
+ * }
1473
+ * }
1474
+ * ```
1475
+ * ```ts
1476
+ * nest.rename("by_carrier_2");
1477
+ * ```
1478
+ * ```
1479
+ * run: flights -> {
1480
+ * nest: by_carrier_2 is {
1481
+ * group_by: carrier
1482
+ * }
1483
+ * }
1484
+ * ```
1485
+ *
1486
+ * @param name The new name
1487
+ */
1488
+ rename(name: string): void;
1489
+ getFieldInfo(): Malloy.FieldInfo;
1490
+ /**
1491
+ * @internal
1492
+ */
1493
+ static fromReference(name: string, path: string[] | undefined, rename: string | undefined): ASTNestViewOperation;
1494
+ }
1495
+ export declare class ASTWhereViewOperation extends ASTObjectNode<Malloy.ViewOperationWithWhere, {
1496
+ kind: 'where';
1497
+ filter: ASTFilter;
1498
+ }> {
1499
+ node: Malloy.ViewOperationWithWhere;
1500
+ readonly kind: Malloy.ViewOperationType;
1501
+ constructor(node: Malloy.ViewOperationWithWhere);
1502
+ get filter(): ASTFilterWithFilterString;
1503
+ /**
1504
+ * @internal
1505
+ */
1506
+ get list(): ASTViewOperationList;
1507
+ delete(): void;
1508
+ }
1509
+ export type ASTFilter = ASTFilterWithFilterString;
1510
+ export declare const ASTFilter: {
1511
+ from(filter: Malloy.Filter): ASTFilterWithFilterString;
1512
+ };
1513
+ export declare class ASTFilterWithFilterString extends ASTObjectNode<Malloy.FilterWithFilterString, {
1514
+ kind: 'filter_string';
1515
+ field_reference: ASTFieldReference;
1516
+ filter: string;
1517
+ }> {
1518
+ node: Malloy.FilterWithFilterString;
1519
+ readonly kind: Malloy.FilterType;
1520
+ constructor(node: Malloy.FilterWithFilterString);
1521
+ get fieldReference(): ASTFieldReference;
1522
+ get filterString(): string;
1523
+ set filterString(filter: string);
1524
+ setFilterString(filterString: string): void;
1525
+ getFieldInfo(): Malloy.FieldInfoWithDimension | Malloy.FieldInfoWithMeasure;
1526
+ getFilterType(): 'string' | 'boolean' | 'number' | 'date' | 'other';
1527
+ setFilter(filter: ParsedFilter): void;
1528
+ getFilter(): ParsedFilter;
1529
+ }
1530
+ export declare class ASTView extends ASTObjectNode<Malloy.View, {
1531
+ definition: ASTViewDefinition;
1532
+ annotations?: ASTAnnotationList;
1533
+ }> implements IASTAnnotatable {
1534
+ node: Malloy.View;
1535
+ constructor(node: Malloy.View);
1536
+ get definition(): ASTViewDefinition;
1537
+ set definition(definition: ASTViewDefinition);
1538
+ get name(): string | undefined;
1539
+ getOrAddDefaultSegment(): ASTSegmentViewDefinition;
1540
+ /**
1541
+ * @internal
1542
+ */
1543
+ get nest(): ASTNestViewOperation;
1544
+ getInputSchema(): Malloy.Schema;
1545
+ getOutputSchema(): Malloy.Schema;
1546
+ /**
1547
+ * @internal
1548
+ */
1549
+ propagateUp(f: PropagationFunction): void;
1550
+ /**
1551
+ * @internal
1552
+ */
1553
+ propagateDown(f: PropagationFunction): void;
1554
+ reorderFields(names: string[]): void;
1555
+ get annotations(): ASTAnnotationList | undefined;
1556
+ getOrAddAnnotations(): ASTAnnotationList;
1557
+ getInheritedAnnotations(): Malloy.Annotation[];
1558
+ getInheritedTag(prefix?: RegExp | string): Tag;
1559
+ getIntrinsicTag(prefix?: RegExp | string): Tag;
1560
+ getTag(prefix?: RegExp | string): Tag;
1561
+ setTagProperty(path: Path, value?: TagSetValue, prefix?: string): void;
1562
+ removeTagProperty(path: Path, prefix?: string): void;
1563
+ }
1564
+ export declare class ASTLimitViewOperation extends ASTObjectNode<Malloy.ViewOperationWithLimit, {
1565
+ kind: 'limit';
1566
+ limit: number;
1567
+ }> {
1568
+ node: Malloy.ViewOperationWithLimit;
1569
+ readonly kind: Malloy.ViewOperationType;
1570
+ get limit(): number;
1571
+ set limit(limit: number);
1572
+ constructor(node: Malloy.ViewOperationWithLimit);
1573
+ /**
1574
+ * @internal
1575
+ */
1576
+ get list(): ASTViewOperationList;
1577
+ delete(): void;
1578
+ /**
1579
+ * @internal
1580
+ */
1581
+ static validateLimit(limit: number): void;
1582
+ }
1583
+ export declare class ASTAnnotationList extends ASTListNode<Malloy.Annotation, ASTAnnotation> {
1584
+ constructor(annotations: Malloy.Annotation[]);
1585
+ get items(): ASTAnnotation[];
1586
+ getInheritedAnnotations(): Malloy.Annotation[];
1587
+ getIntrinsicTag(prefix?: RegExp | string): Tag;
1588
+ getTag(prefix?: RegExp | string): Tag;
1589
+ get annotations(): Malloy.Annotation[];
1590
+ setTagProperty(path: Path, value?: TagSetValue, prefix?: string): void;
1591
+ removeTagProperty(path: Path, prefix?: string): void;
1592
+ }
1593
+ export declare class ASTAnnotation extends ASTObjectNode<Malloy.Annotation, {
1594
+ value: string;
1595
+ }> {
1596
+ node: Malloy.Annotation;
1597
+ readonly kind: Malloy.ViewOperationType;
1598
+ get value(): string;
1599
+ set value(value: string);
1600
+ constructor(node: Malloy.Annotation);
1601
+ /**
1602
+ * @internal
1603
+ */
1604
+ get list(): ASTAnnotationList;
1605
+ get index(): number;
1606
+ delete(): void;
1607
+ getIntrinsicTag(): Tag;
1608
+ getTag(): Tag;
1609
+ hasPrefix(prefix: string): boolean;
1610
+ hasIntrinsicTagProperty(path: Path): boolean;
1611
+ setTagProperty(path: Path, value: TagSetValue): void;
1612
+ removeTagProperty(path: Path): void;
1613
+ }
1614
+ export {};