@malloydata/malloy-interfaces 0.0.298 → 0.0.299

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/dist/to_malloy.js CHANGED
@@ -55,6 +55,17 @@ function wrap(open, block, close, options) {
55
55
  function escapeString(str) {
56
56
  return { contents: str, quoteCharacter: '"' }; // TODO
57
57
  }
58
+ function join(fragments, separator) {
59
+ const result = [];
60
+ for (let i = 0; i < fragments.length; i++) {
61
+ const fragment = fragments[i];
62
+ result.push(fragment);
63
+ if (i < fragments.length - 1) {
64
+ result.push(separator);
65
+ }
66
+ }
67
+ return result;
68
+ }
58
69
  function literalToFragments(literal) {
59
70
  var _a, _b;
60
71
  switch (literal.kind) {
@@ -268,9 +279,9 @@ function segmentToFragments(segment) {
268
279
  function groupedOperationsToFragments(operations) {
269
280
  switch (operations[0].kind) {
270
281
  case 'aggregate':
271
- return aggregateToFragments(operations);
282
+ return fieldOperationToFragments(operations, 'aggregate');
272
283
  case 'group_by':
273
- return groupByToFragments(operations);
284
+ return fieldOperationToFragments(operations, 'group_by');
274
285
  case 'order_by':
275
286
  return orderByToFragments(operations);
276
287
  case 'nest':
@@ -283,6 +294,8 @@ function groupedOperationsToFragments(operations) {
283
294
  return havingToFragments(operations);
284
295
  case 'drill':
285
296
  return drillToFragments(operations);
297
+ case 'calculate':
298
+ return fieldOperationToFragments(operations, 'calculate');
286
299
  }
287
300
  }
288
301
  function formatBlock(label, items, separator = '') {
@@ -320,6 +333,7 @@ function timeUnitToFragment(timeUnit) {
320
333
  return timeUnit;
321
334
  }
322
335
  function expressionToFragments(expression) {
336
+ var _a;
323
337
  switch (expression.kind) {
324
338
  case 'field_reference':
325
339
  return referenceToFragments(expression);
@@ -336,9 +350,31 @@ function expressionToFragments(expression) {
336
350
  ];
337
351
  case 'literal_value':
338
352
  return literalToFragments(expression.literal_value);
353
+ case 'moving_average': {
354
+ const fragments = [
355
+ 'avg_moving',
356
+ ...wrap('(', [
357
+ ...referenceToFragments(expression.field_reference),
358
+ expression.rows_preceding !== undefined
359
+ ? `, ${expression.rows_preceding}`
360
+ : ', 0',
361
+ expression.rows_following !== undefined
362
+ ? `, ${expression.rows_following}`
363
+ : '',
364
+ ], ')', { spaces: false }),
365
+ ];
366
+ if ((_a = expression.partition_fields) === null || _a === void 0 ? void 0 : _a.length) {
367
+ fragments.push(...wrap(' {', [
368
+ 'partition_by',
369
+ ': ',
370
+ ...join(expression.partition_fields.flatMap(partitionField => referenceToFragments(partitionField)), ', '),
371
+ ], '}'));
372
+ }
373
+ return fragments;
374
+ }
339
375
  }
340
376
  }
341
- function groupByOrAggregateItemToFragments(item, hideAnnotations = false) {
377
+ function fieldItemToFragments(item, hideAnnotations = false) {
342
378
  const fragments = [];
343
379
  if (!hideAnnotations) {
344
380
  fragments.push(...annotationsToFragments(item.field.annotations));
@@ -350,22 +386,13 @@ function groupByOrAggregateItemToFragments(item, hideAnnotations = false) {
350
386
  fragments.push(...fieldToFragments(item.field));
351
387
  return fragments;
352
388
  }
353
- function groupByToFragments(groupBy) {
354
- const fragments = [];
355
- const hoistAnnotations = groupBy.length === 1;
356
- if (hoistAnnotations) {
357
- fragments.push(...annotationsToFragments(groupBy[0].field.annotations));
358
- }
359
- fragments.push(...formatBlock('group_by', groupBy.map(i => groupByOrAggregateItemToFragments(i, hoistAnnotations))));
360
- return fragments;
361
- }
362
- function aggregateToFragments(groupBy) {
389
+ function fieldOperationToFragments(operation, label) {
363
390
  const fragments = [];
364
- const hoistAnnotations = groupBy.length === 1;
391
+ const hoistAnnotations = operation.length === 1;
365
392
  if (hoistAnnotations) {
366
- fragments.push(...annotationsToFragments(groupBy[0].field.annotations));
393
+ fragments.push(...annotationsToFragments(operation[0].field.annotations));
367
394
  }
368
- fragments.push(...formatBlock('aggregate', groupBy.map(i => groupByOrAggregateItemToFragments(i, hoistAnnotations))));
395
+ fragments.push(...formatBlock(label, operation.map(i => fieldItemToFragments(i, hoistAnnotations))));
369
396
  return fragments;
370
397
  }
371
398
  function orderByToFragments(orderBy) {
package/dist/types.d.ts CHANGED
@@ -73,6 +73,15 @@ export type BooleanLiteral = {
73
73
  boolean_value: boolean;
74
74
  };
75
75
  export type BooleanType = {};
76
+ export type CalculateInfo = {
77
+ name: string;
78
+ type: AtomicType;
79
+ annotations?: Array<Annotation>;
80
+ };
81
+ export type CalculateOperation = {
82
+ name: string;
83
+ field: Field;
84
+ };
76
85
  export type CellType = 'string_cell' | 'boolean_cell' | 'date_cell' | 'timestamp_cell' | 'number_cell' | 'json_cell' | 'record_cell' | 'array_cell' | 'null_cell' | 'sql_native_cell';
77
86
  export type Cell = CellWithStringCell | CellWithBooleanCell | CellWithDateCell | CellWithTimestampCell | CellWithNumberCell | CellWithJSONCell | CellWithRecordCell | CellWithArrayCell | CellWithNullCell | CellWithSQLNativeCell;
78
87
  export type CellWithStringCell = {
@@ -108,6 +117,7 @@ export type CellWithSQLNativeCell = {
108
117
  export type CompileModelRequest = {
109
118
  model_url: string;
110
119
  extend_model_url?: string;
120
+ exclude_references?: boolean;
111
121
  compiler_needs?: CompilerNeeds;
112
122
  };
113
123
  export type CompileModelResponse = {
@@ -121,6 +131,7 @@ export type CompileQueryRequest = {
121
131
  model_url: string;
122
132
  query: Query;
123
133
  default_row_limit?: number;
134
+ exclude_references?: boolean;
124
135
  compiler_needs?: CompilerNeeds;
125
136
  };
126
137
  export type CompileQueryResponse = {
@@ -135,6 +146,7 @@ export type CompileSourceRequest = {
135
146
  model_url: string;
136
147
  name: string;
137
148
  extend_model_url?: string;
149
+ exclude_references?: boolean;
138
150
  compiler_needs?: CompilerNeeds;
139
151
  };
140
152
  export type CompileSourceResponse = {
@@ -190,8 +202,8 @@ export type DocumentRange = {
190
202
  export type DrillOperation = {
191
203
  filter: Filter;
192
204
  };
193
- export type ExpressionType = 'field_reference' | 'time_truncation' | 'filtered_field' | 'literal_value';
194
- export type Expression = ExpressionWithFieldReference | ExpressionWithTimeTruncation | ExpressionWithFilteredField | ExpressionWithLiteralValue;
205
+ export type ExpressionType = 'field_reference' | 'time_truncation' | 'filtered_field' | 'literal_value' | 'moving_average';
206
+ export type Expression = ExpressionWithFieldReference | ExpressionWithTimeTruncation | ExpressionWithFilteredField | ExpressionWithLiteralValue | ExpressionWithMovingAverage;
195
207
  export type ExpressionWithFieldReference = {
196
208
  kind: 'field_reference';
197
209
  } & Reference;
@@ -204,12 +216,15 @@ export type ExpressionWithFilteredField = {
204
216
  export type ExpressionWithLiteralValue = {
205
217
  kind: 'literal_value';
206
218
  } & LiteralValueExpression;
219
+ export type ExpressionWithMovingAverage = {
220
+ kind: 'moving_average';
221
+ } & MovingAverage;
207
222
  export type Field = {
208
223
  expression: Expression;
209
224
  annotations?: Array<Annotation>;
210
225
  };
211
- export type FieldInfoType = 'dimension' | 'measure' | 'join' | 'view';
212
- export type FieldInfo = FieldInfoWithDimension | FieldInfoWithMeasure | FieldInfoWithJoin | FieldInfoWithView;
226
+ export type FieldInfoType = 'dimension' | 'measure' | 'join' | 'view' | 'calculate';
227
+ export type FieldInfo = FieldInfoWithDimension | FieldInfoWithMeasure | FieldInfoWithJoin | FieldInfoWithView | FieldInfoWithCalculate;
213
228
  export type FieldInfoWithDimension = {
214
229
  kind: 'dimension';
215
230
  } & DimensionInfo;
@@ -222,6 +237,9 @@ export type FieldInfoWithJoin = {
222
237
  export type FieldInfoWithView = {
223
238
  kind: 'view';
224
239
  } & ViewInfo;
240
+ export type FieldInfoWithCalculate = {
241
+ kind: 'calculate';
242
+ } & CalculateInfo;
225
243
  export type File = {
226
244
  url: string;
227
245
  contents?: string;
@@ -345,6 +363,12 @@ export type ModelInfo = {
345
363
  annotations?: Array<Annotation>;
346
364
  anonymous_queries: Array<AnonymousQueryInfo>;
347
365
  };
366
+ export type MovingAverage = {
367
+ field_reference: Reference;
368
+ rows_preceding?: number;
369
+ rows_following?: number;
370
+ partition_fields?: Array<Reference>;
371
+ };
348
372
  export type Nest = {
349
373
  name?: string;
350
374
  view: View;
@@ -479,6 +503,7 @@ export type Result = {
479
503
  export type RunIndexQueryRequest = {
480
504
  model_url: string;
481
505
  source_name: string;
506
+ exclude_references?: boolean;
482
507
  compiler_needs?: CompilerNeeds;
483
508
  };
484
509
  export type RunIndexQueryResponse = {
@@ -490,6 +515,7 @@ export type RunQueryRequest = {
490
515
  model_url: string;
491
516
  query: Query;
492
517
  default_row_limit?: number;
518
+ exclude_references?: boolean;
493
519
  compiler_needs?: CompilerNeeds;
494
520
  };
495
521
  export type RunQueryResponse = {
@@ -584,8 +610,8 @@ export type ViewInfo = {
584
610
  annotations?: Array<Annotation>;
585
611
  definition?: View;
586
612
  };
587
- export type ViewOperationType = 'group_by' | 'aggregate' | 'order_by' | 'limit' | 'where' | 'nest' | 'having' | 'drill';
588
- export type ViewOperation = ViewOperationWithGroupBy | ViewOperationWithAggregate | ViewOperationWithOrderBy | ViewOperationWithLimit | ViewOperationWithWhere | ViewOperationWithNest | ViewOperationWithHaving | ViewOperationWithDrill;
613
+ export type ViewOperationType = 'group_by' | 'aggregate' | 'order_by' | 'limit' | 'where' | 'nest' | 'having' | 'drill' | 'calculate';
614
+ export type ViewOperation = ViewOperationWithGroupBy | ViewOperationWithAggregate | ViewOperationWithOrderBy | ViewOperationWithLimit | ViewOperationWithWhere | ViewOperationWithNest | ViewOperationWithHaving | ViewOperationWithDrill | ViewOperationWithCalculate;
589
615
  export type ViewOperationWithGroupBy = {
590
616
  kind: 'group_by';
591
617
  } & GroupBy;
@@ -610,6 +636,9 @@ export type ViewOperationWithHaving = {
610
636
  export type ViewOperationWithDrill = {
611
637
  kind: 'drill';
612
638
  } & DrillOperation;
639
+ export type ViewOperationWithCalculate = {
640
+ kind: 'calculate';
641
+ } & CalculateOperation;
613
642
  export type ViewRefinement = {
614
643
  base: ViewDefinition;
615
644
  refinement: ViewDefinition;
package/dist/types.js CHANGED
@@ -134,6 +134,43 @@ exports.MALLOY_INTERFACE_TYPES = {
134
134
  'name': 'BooleanType',
135
135
  'fields': {},
136
136
  },
137
+ 'CalculateInfo': {
138
+ 'type': 'struct',
139
+ 'name': 'CalculateInfo',
140
+ 'fields': {
141
+ 'name': {
142
+ 'type': 'string',
143
+ 'optional': false,
144
+ 'array': false,
145
+ },
146
+ 'type': {
147
+ 'type': 'AtomicType',
148
+ 'optional': false,
149
+ 'array': false,
150
+ },
151
+ 'annotations': {
152
+ 'type': 'Annotation',
153
+ 'array': true,
154
+ 'optional': true,
155
+ },
156
+ },
157
+ },
158
+ 'CalculateOperation': {
159
+ 'type': 'struct',
160
+ 'name': 'CalculateOperation',
161
+ 'fields': {
162
+ 'name': {
163
+ 'type': 'string',
164
+ 'optional': false,
165
+ 'array': false,
166
+ },
167
+ 'field': {
168
+ 'type': 'Field',
169
+ 'optional': false,
170
+ 'array': false,
171
+ },
172
+ },
173
+ },
137
174
  'Cell': {
138
175
  'type': 'union',
139
176
  'name': 'Cell',
@@ -164,6 +201,11 @@ exports.MALLOY_INTERFACE_TYPES = {
164
201
  'optional': true,
165
202
  'array': false,
166
203
  },
204
+ 'exclude_references': {
205
+ 'type': 'boolean',
206
+ 'optional': true,
207
+ 'array': false,
208
+ },
167
209
  'compiler_needs': {
168
210
  'type': 'CompilerNeeds',
169
211
  'optional': true,
@@ -221,6 +263,11 @@ exports.MALLOY_INTERFACE_TYPES = {
221
263
  'optional': true,
222
264
  'array': false,
223
265
  },
266
+ 'exclude_references': {
267
+ 'type': 'boolean',
268
+ 'optional': true,
269
+ 'array': false,
270
+ },
224
271
  'compiler_needs': {
225
272
  'type': 'CompilerNeeds',
226
273
  'optional': true,
@@ -283,6 +330,11 @@ exports.MALLOY_INTERFACE_TYPES = {
283
330
  'optional': true,
284
331
  'array': false,
285
332
  },
333
+ 'exclude_references': {
334
+ 'type': 'boolean',
335
+ 'optional': true,
336
+ 'array': false,
337
+ },
286
338
  'compiler_needs': {
287
339
  'type': 'CompilerNeeds',
288
340
  'optional': true,
@@ -497,6 +549,7 @@ exports.MALLOY_INTERFACE_TYPES = {
497
549
  'time_truncation': 'TimeTruncationFieldReference',
498
550
  'filtered_field': 'FilteredField',
499
551
  'literal_value': 'LiteralValueExpression',
552
+ 'moving_average': 'MovingAverage',
500
553
  },
501
554
  },
502
555
  'Field': {
@@ -523,6 +576,7 @@ exports.MALLOY_INTERFACE_TYPES = {
523
576
  'measure': 'MeasureInfo',
524
577
  'join': 'JoinInfo',
525
578
  'view': 'ViewInfo',
579
+ 'calculate': 'CalculateInfo',
526
580
  },
527
581
  },
528
582
  'File': {
@@ -841,6 +895,32 @@ exports.MALLOY_INTERFACE_TYPES = {
841
895
  },
842
896
  },
843
897
  },
898
+ 'MovingAverage': {
899
+ 'type': 'struct',
900
+ 'name': 'MovingAverage',
901
+ 'fields': {
902
+ 'field_reference': {
903
+ 'type': 'Reference',
904
+ 'optional': false,
905
+ 'array': false,
906
+ },
907
+ 'rows_preceding': {
908
+ 'type': 'number',
909
+ 'optional': true,
910
+ 'array': false,
911
+ },
912
+ 'rows_following': {
913
+ 'type': 'number',
914
+ 'optional': true,
915
+ 'array': false,
916
+ },
917
+ 'partition_fields': {
918
+ 'type': 'Reference',
919
+ 'array': true,
920
+ 'optional': true,
921
+ },
922
+ },
923
+ },
844
924
  'Nest': {
845
925
  'type': 'struct',
846
926
  'name': 'Nest',
@@ -1230,6 +1310,11 @@ exports.MALLOY_INTERFACE_TYPES = {
1230
1310
  'optional': false,
1231
1311
  'array': false,
1232
1312
  },
1313
+ 'exclude_references': {
1314
+ 'type': 'boolean',
1315
+ 'optional': true,
1316
+ 'array': false,
1317
+ },
1233
1318
  'compiler_needs': {
1234
1319
  'type': 'CompilerNeeds',
1235
1320
  'optional': true,
@@ -1277,6 +1362,11 @@ exports.MALLOY_INTERFACE_TYPES = {
1277
1362
  'optional': true,
1278
1363
  'array': false,
1279
1364
  },
1365
+ 'exclude_references': {
1366
+ 'type': 'boolean',
1367
+ 'optional': true,
1368
+ 'array': false,
1369
+ },
1280
1370
  'compiler_needs': {
1281
1371
  'type': 'CompilerNeeds',
1282
1372
  'optional': true,
@@ -1633,6 +1723,7 @@ exports.MALLOY_INTERFACE_TYPES = {
1633
1723
  'nest': 'Nest',
1634
1724
  'having': 'FilterOperation',
1635
1725
  'drill': 'DrillOperation',
1726
+ 'calculate': 'CalculateOperation',
1636
1727
  },
1637
1728
  },
1638
1729
  'ViewRefinement': {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy-interfaces",
3
- "version": "0.0.298",
3
+ "version": "0.0.299",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -95,6 +95,7 @@ union FieldInfo {
95
95
  2: required MeasureInfo measure,
96
96
  3: required JoinInfo join,
97
97
  4: required ViewInfo view,
98
+ 5: required CalculateInfo calculate,
98
99
  }
99
100
 
100
101
  // TODO should these just be "AtomicField" with a "fieldtype"
@@ -140,6 +141,12 @@ struct ViewInfo {
140
141
  // Possibly need `filterList` depending on how we do drills
141
142
  }
142
143
 
144
+ struct CalculateInfo {
145
+ 1: required string name,
146
+ 2: required AtomicType type,
147
+ 3: optional list<Annotation> annotations,
148
+ }
149
+
143
150
  struct View {
144
151
  2: required ViewDefinition definition,
145
152
  3: optional list<Annotation> annotations,
@@ -265,6 +272,7 @@ union ViewOperation {
265
272
  6: required Nest nest,
266
273
  7: required FilterOperation having,
267
274
  8: required DrillOperation drill,
275
+ 9: required CalculateOperation calculate,
268
276
  }
269
277
 
270
278
  struct GroupBy {
@@ -310,6 +318,11 @@ struct DrillOperation {
310
318
  1: required Filter filter,
311
319
  }
312
320
 
321
+ struct CalculateOperation {
322
+ 1: required string name,
323
+ 2: required Field field,
324
+ }
325
+
313
326
  union Filter {
314
327
  1: required FilterStringApplication filter_string,
315
328
  2: required LiteralEqualityComparison literal_equality,
@@ -452,6 +465,7 @@ union Expression {
452
465
  2: required TimeTruncationFieldReference time_truncation,
453
466
  3: required FilteredField filtered_field,
454
467
  4: required LiteralValueExpression literal_value,
468
+ 5: required MovingAverage moving_average
455
469
  }
456
470
 
457
471
  struct TimeTruncationFieldReference {
@@ -464,6 +478,13 @@ struct FilteredField {
464
478
  2: required list<FilterOperation> where,
465
479
  }
466
480
 
481
+ struct MovingAverage {
482
+ 1: required Reference field_reference,
483
+ 2: optional i32 rows_preceding,
484
+ 3: optional i32 rows_following,
485
+ 4: optional list<Reference> partition_fields,
486
+ }
487
+
467
488
  struct StringCell {
468
489
  1: required string string_value,
469
490
  }
@@ -645,9 +666,14 @@ struct TimingInfo {
645
666
  // Given the URL to a model, return the StableModelDef for that model
646
667
 
647
668
  struct CompileModelRequest {
669
+ // Main parameters
648
670
  1: required string model_url,
649
671
  2: optional string extend_model_url,
650
672
 
673
+ // Options
674
+ 4: optional bool exclude_references,
675
+
676
+ // Response to compiler needs
651
677
  9: optional CompilerNeeds compiler_needs,
652
678
  }
653
679
 
@@ -663,10 +689,15 @@ struct CompileModelResponse {
663
689
  // Given the URL to a model and a name of a queryable thing, get a StableSourceDef
664
690
 
665
691
  struct CompileSourceRequest {
692
+ // Main parameters
666
693
  1: required string model_url,
667
694
  2: required string name,
668
695
  3: optional string extend_model_url,
669
696
 
697
+ // Options
698
+ 4: optional bool exclude_references,
699
+
700
+ // Response to compiler needs
670
701
  9: optional CompilerNeeds compiler_needs,
671
702
  }
672
703
 
@@ -681,10 +712,15 @@ struct CompileSourceResponse {
681
712
  // Given a StableQueryDef and the URL to a model, run it and return a StableResult
682
713
 
683
714
  struct RunQueryRequest {
715
+ // Main parameters
684
716
  1: required string model_url,
685
717
  2: required Query query,
718
+
719
+ // Options
686
720
  3: optional i32 default_row_limit,
721
+ 4: optional bool exclude_references,
687
722
 
723
+ // Response to compiler needs
688
724
  9: optional CompilerNeeds compiler_needs,
689
725
  }
690
726
 
@@ -700,10 +736,15 @@ struct RunQueryResponse {
700
736
  // Given a StableQueryDef and the URL to a model, compile it and return a StableResultDef
701
737
 
702
738
  struct CompileQueryRequest {
739
+ // Main parameters
703
740
  1: required string model_url,
704
741
  2: required Query query,
742
+
743
+ // Options
705
744
  3: optional i32 default_row_limit,
745
+ 4: optional bool exclude_references,
706
746
 
747
+ // Response to compiler needs
707
748
  9: optional CompilerNeeds compiler_needs,
708
749
  }
709
750
 
@@ -720,9 +761,14 @@ struct CompileQueryResponse {
720
761
  // Given a URL to a model and the name of a source, run the indexing query
721
762
 
722
763
  struct RunIndexQueryRequest {
764
+ // Main parameters
723
765
  1: required string model_url,
724
766
  2: required string source_name,
725
767
 
768
+ // Options
769
+ 4: optional bool exclude_references,
770
+
771
+ // Response to compiler needs
726
772
  9: optional CompilerNeeds compiler_needs,
727
773
  }
728
774