@malloydata/malloy-interfaces 0.0.280 → 0.0.282

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/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type * as Malloy from './types';
2
2
  export * from './types';
3
- export { queryToMalloy } from './to_malloy';
3
+ export { queryToMalloy, filterToMalloy } from './to_malloy';
4
4
  export { nestUnions, unnestUnions, convertFromThrift, convertToThrift, } from './nest_unions';
5
5
  export declare const test: Malloy.ModelInfo;
6
6
  export declare const res: Malloy.Result;
package/dist/index.js CHANGED
@@ -20,10 +20,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
20
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.thingy4sddfdfsd = exports.thingy4sdfsd = exports.thingy4dfdsfs = exports.thingy4asdfas = exports.thingy4asdfasdf = exports.thingy3dfdf = exports.thingy3 = exports.thingy2asdf = exports.thingyssdfg = exports.thingy123r = exports.thingy1 = exports.res = exports.test = exports.convertToThrift = exports.convertFromThrift = exports.unnestUnions = exports.nestUnions = exports.queryToMalloy = void 0;
23
+ exports.thingy4sddfdfsd = exports.thingy4sdfsd = exports.thingy4dfdsfs = exports.thingy4asdfas = exports.thingy4asdfasdf = exports.thingy3dfdf = exports.thingy3 = exports.thingy2asdf = exports.thingyssdfg = exports.thingy123r = exports.thingy1 = exports.res = exports.test = exports.convertToThrift = exports.convertFromThrift = exports.unnestUnions = exports.nestUnions = exports.filterToMalloy = exports.queryToMalloy = void 0;
24
24
  __exportStar(require("./types"), exports);
25
25
  var to_malloy_1 = require("./to_malloy");
26
26
  Object.defineProperty(exports, "queryToMalloy", { enumerable: true, get: function () { return to_malloy_1.queryToMalloy; } });
27
+ Object.defineProperty(exports, "filterToMalloy", { enumerable: true, get: function () { return to_malloy_1.filterToMalloy; } });
27
28
  var nest_unions_1 = require("./nest_unions");
28
29
  Object.defineProperty(exports, "nestUnions", { enumerable: true, get: function () { return nest_unions_1.nestUnions; } });
29
30
  Object.defineProperty(exports, "unnestUnions", { enumerable: true, get: function () { return nest_unions_1.unnestUnions; } });
@@ -2,3 +2,6 @@ import type * as Malloy from './types';
2
2
  export declare function queryToMalloy(query: Malloy.Query, { tabWidth }?: {
3
3
  tabWidth: number;
4
4
  }): string;
5
+ export declare function filterToMalloy(filter: Malloy.Filter, { tabWidth }?: {
6
+ tabWidth: number;
7
+ }): string;
package/dist/to_malloy.js CHANGED
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.queryToMalloy = queryToMalloy;
4
+ exports.filterToMalloy = filterToMalloy;
4
5
  const util_1 = require("./util");
5
6
  function queryToMalloy(query, { tabWidth } = { tabWidth: 2 }) {
6
7
  const fragments = queryToFragments(query);
7
8
  return codeFromFragments(fragments, { tabWidth });
8
9
  }
10
+ function filterToMalloy(filter, { tabWidth } = { tabWidth: 2 }) {
11
+ const fragments = filterToFragments(filter);
12
+ return codeFromFragments(fragments, { tabWidth });
13
+ }
9
14
  const INDENT = Symbol('indent');
10
15
  const NEWLINE = Symbol('newline');
11
16
  const OUTDENT = Symbol('outdent');
@@ -68,11 +73,11 @@ function literalToFragments(literal) {
68
73
  return ['null'];
69
74
  case 'date_literal':
70
75
  return [
71
- serializeDateAsLiteral(parseDate(literal.date_value), (_a = literal.granularity) !== null && _a !== void 0 ? _a : 'day'),
76
+ serializeDateAsLiteral(parseDate(literal.date_value), (_a = literal.granularity) !== null && _a !== void 0 ? _a : 'day', literal.timezone),
72
77
  ];
73
78
  case 'timestamp_literal':
74
79
  return [
75
- serializeDateAsLiteral(parseDate(literal.timestamp_value), (_b = literal.granularity) !== null && _b !== void 0 ? _b : 'second'),
80
+ serializeDateAsLiteral(parseDate(literal.timestamp_value), (_b = literal.granularity) !== null && _b !== void 0 ? _b : 'second', literal.timezone),
76
81
  ];
77
82
  }
78
83
  }
@@ -104,7 +109,7 @@ function parseDate(date) {
104
109
  }
105
110
  return ['1970', '01', '01', '00', '00', '00'];
106
111
  }
107
- function serializeDateAsLiteral([year, month, day, hour, minute, second], granularity) {
112
+ function serializeDateAsLiteral([year, month, day, hour, minute, second], granularity, timezone) {
108
113
  switch (granularity) {
109
114
  case 'year': {
110
115
  return `@${year}`;
@@ -129,6 +134,9 @@ function serializeDateAsLiteral([year, month, day, hour, minute, second], granul
129
134
  return `@${year}-${month}-${day} ${hour}:${minute}`;
130
135
  }
131
136
  case 'second': {
137
+ if (timezone !== undefined) {
138
+ return `@${year}-${month}-${day} ${hour}:${minute}:${second}[${timezone}]`;
139
+ }
132
140
  return `@${year}-${month}-${day} ${hour}:${minute}:${second}`;
133
141
  }
134
142
  default:
@@ -273,6 +281,8 @@ function groupedOperationsToFragments(operations) {
273
281
  return whereToFragments(operations);
274
282
  case 'having':
275
283
  return havingToFragments(operations);
284
+ case 'drill':
285
+ return drillToFragments(operations);
276
286
  }
277
287
  }
278
288
  function formatBlock(label, items, separator = '') {
@@ -324,6 +334,8 @@ function expressionToFragments(expression) {
324
334
  ...referenceToFragments(expression.field_reference),
325
335
  ...wrap(' {', whereToFragments(expression.where), '}'),
326
336
  ];
337
+ case 'literal_value':
338
+ return literalToFragments(expression.literal_value);
327
339
  }
328
340
  }
329
341
  function groupByOrAggregateItemToFragments(item, hideAnnotations = false) {
@@ -409,6 +421,9 @@ function limitToFragments(limits) {
409
421
  function whereToFragments(where) {
410
422
  return formatBlock('where', where.map(filterOperationItemToFragments), ',');
411
423
  }
424
+ function drillToFragments(drill) {
425
+ return formatBlock('drill', drill.map(filterOperationItemToFragments), ',');
426
+ }
412
427
  function havingToFragments(having) {
413
428
  return formatBlock('having', having.map(filterOperationItemToFragments), ',');
414
429
  }
@@ -444,16 +459,25 @@ function escapeFilter(filter, quote) {
444
459
  }
445
460
  return result;
446
461
  }
447
- function filterOperationItemToFragments(whereItem) {
448
- switch (whereItem.filter.kind) {
462
+ function filterToFragments(filter) {
463
+ switch (filter.kind) {
449
464
  case 'filter_string':
450
465
  return [
451
- ...referenceToFragments(whereItem.filter.field_reference),
466
+ ...referenceToFragments(filter.field_reference),
452
467
  ' ~ ',
453
- quoteFilter(whereItem.filter.filter),
468
+ quoteFilter(filter.filter),
469
+ ];
470
+ case 'literal_equality':
471
+ return [
472
+ ...referenceToFragments(filter.field_reference),
473
+ ' = ',
474
+ ...literalToFragments(filter.value),
454
475
  ];
455
476
  }
456
477
  }
478
+ function filterOperationItemToFragments(whereItem) {
479
+ return filterToFragments(whereItem.filter);
480
+ }
457
481
  function annotationsToFragments(annotations) {
458
482
  return annotations ? annotations.flatMap(annotationToFragments) : [];
459
483
  }
package/dist/types.d.ts CHANGED
@@ -165,6 +165,7 @@ export type DateCell = {
165
165
  export type DateLiteral = {
166
166
  date_value: string;
167
167
  granularity?: DateTimeframe;
168
+ timezone?: string;
168
169
  };
169
170
  export type DateTimeframe = 'year' | 'quarter' | 'month' | 'week' | 'day';
170
171
  export type DateType = {
@@ -183,8 +184,11 @@ export type DocumentRange = {
183
184
  start: DocumentPosition;
184
185
  end: DocumentPosition;
185
186
  };
186
- export type ExpressionType = 'field_reference' | 'time_truncation' | 'filtered_field';
187
- export type Expression = ExpressionWithFieldReference | ExpressionWithTimeTruncation | ExpressionWithFilteredField;
187
+ export type DrillOperation = {
188
+ filter: Filter;
189
+ };
190
+ export type ExpressionType = 'field_reference' | 'time_truncation' | 'filtered_field' | 'literal_value';
191
+ export type Expression = ExpressionWithFieldReference | ExpressionWithTimeTruncation | ExpressionWithFilteredField | ExpressionWithLiteralValue;
188
192
  export type ExpressionWithFieldReference = {
189
193
  kind: 'field_reference';
190
194
  } & Reference;
@@ -194,6 +198,9 @@ export type ExpressionWithTimeTruncation = {
194
198
  export type ExpressionWithFilteredField = {
195
199
  kind: 'filtered_field';
196
200
  } & FilteredField;
201
+ export type ExpressionWithLiteralValue = {
202
+ kind: 'literal_value';
203
+ } & LiteralValueExpression;
197
204
  export type Field = {
198
205
  expression: Expression;
199
206
  annotations?: Array<Annotation>;
@@ -217,11 +224,14 @@ export type File = {
217
224
  contents?: string;
218
225
  invalidation_key?: string;
219
226
  };
220
- export type FilterType = 'filter_string';
221
- export type Filter = FilterWithFilterString;
227
+ export type FilterType = 'filter_string' | 'literal_equality';
228
+ export type Filter = FilterWithFilterString | FilterWithLiteralEquality;
222
229
  export type FilterWithFilterString = {
223
230
  kind: 'filter_string';
224
231
  } & FilterStringApplication;
232
+ export type FilterWithLiteralEquality = {
233
+ kind: 'literal_equality';
234
+ } & LiteralEqualityComparison;
225
235
  export type FilterExpressionLiteral = {
226
236
  filter_expression_value: string;
227
237
  };
@@ -273,6 +283,10 @@ export type JoinInfo = {
273
283
  export type Limit = {
274
284
  limit: number;
275
285
  };
286
+ export type LiteralEqualityComparison = {
287
+ field_reference: Reference;
288
+ value: LiteralValue;
289
+ };
276
290
  export type LiteralValueType = 'string_literal' | 'number_literal' | 'date_literal' | 'timestamp_literal' | 'boolean_literal' | 'null_literal' | 'filter_expression_literal';
277
291
  export type LiteralValue = LiteralValueWithStringLiteral | LiteralValueWithNumberLiteral | LiteralValueWithDateLiteral | LiteralValueWithTimestampLiteral | LiteralValueWithBooleanLiteral | LiteralValueWithNullLiteral | LiteralValueWithFilterExpressionLiteral;
278
292
  export type LiteralValueWithStringLiteral = {
@@ -296,6 +310,9 @@ export type LiteralValueWithNullLiteral = {
296
310
  export type LiteralValueWithFilterExpressionLiteral = {
297
311
  kind: 'filter_expression_literal';
298
312
  } & FilterExpressionLiteral;
313
+ export type LiteralValueExpression = {
314
+ literal_value: LiteralValue;
315
+ };
299
316
  export type Location = {
300
317
  url: string;
301
318
  range: Range;
@@ -519,6 +536,7 @@ export type TimestampCell = {
519
536
  export type TimestampLiteral = {
520
537
  timestamp_value: string;
521
538
  granularity?: TimestampTimeframe;
539
+ timezone?: string;
522
540
  };
523
541
  export type TimestampTimeframe = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
524
542
  export type TimestampType = {
@@ -556,8 +574,8 @@ export type ViewInfo = {
556
574
  annotations?: Array<Annotation>;
557
575
  definition?: View;
558
576
  };
559
- export type ViewOperationType = 'group_by' | 'aggregate' | 'order_by' | 'limit' | 'where' | 'nest' | 'having';
560
- export type ViewOperation = ViewOperationWithGroupBy | ViewOperationWithAggregate | ViewOperationWithOrderBy | ViewOperationWithLimit | ViewOperationWithWhere | ViewOperationWithNest | ViewOperationWithHaving;
577
+ export type ViewOperationType = 'group_by' | 'aggregate' | 'order_by' | 'limit' | 'where' | 'nest' | 'having' | 'drill';
578
+ export type ViewOperation = ViewOperationWithGroupBy | ViewOperationWithAggregate | ViewOperationWithOrderBy | ViewOperationWithLimit | ViewOperationWithWhere | ViewOperationWithNest | ViewOperationWithHaving | ViewOperationWithDrill;
561
579
  export type ViewOperationWithGroupBy = {
562
580
  kind: 'group_by';
563
581
  } & GroupBy;
@@ -579,6 +597,9 @@ export type ViewOperationWithNest = {
579
597
  export type ViewOperationWithHaving = {
580
598
  kind: 'having';
581
599
  } & FilterOperation;
600
+ export type ViewOperationWithDrill = {
601
+ kind: 'drill';
602
+ } & DrillOperation;
582
603
  export type ViewRefinement = {
583
604
  base: ViewDefinition;
584
605
  refinement: ViewDefinition;
package/dist/types.js CHANGED
@@ -381,6 +381,11 @@ exports.MALLOY_INTERFACE_TYPES = {
381
381
  'optional': true,
382
382
  'array': false,
383
383
  },
384
+ 'timezone': {
385
+ 'type': 'string',
386
+ 'optional': true,
387
+ 'array': false,
388
+ },
384
389
  },
385
390
  },
386
391
  'DateTimeframe': {
@@ -458,6 +463,17 @@ exports.MALLOY_INTERFACE_TYPES = {
458
463
  },
459
464
  },
460
465
  },
466
+ 'DrillOperation': {
467
+ 'type': 'struct',
468
+ 'name': 'DrillOperation',
469
+ 'fields': {
470
+ 'filter': {
471
+ 'type': 'Filter',
472
+ 'optional': false,
473
+ 'array': false,
474
+ },
475
+ },
476
+ },
461
477
  'Expression': {
462
478
  'type': 'union',
463
479
  'name': 'Expression',
@@ -465,6 +481,7 @@ exports.MALLOY_INTERFACE_TYPES = {
465
481
  'field_reference': 'Reference',
466
482
  'time_truncation': 'TimeTruncationFieldReference',
467
483
  'filtered_field': 'FilteredField',
484
+ 'literal_value': 'LiteralValueExpression',
468
485
  },
469
486
  },
470
487
  'Field': {
@@ -519,6 +536,7 @@ exports.MALLOY_INTERFACE_TYPES = {
519
536
  'name': 'Filter',
520
537
  'options': {
521
538
  'filter_string': 'FilterStringApplication',
539
+ 'literal_equality': 'LiteralEqualityComparison',
522
540
  },
523
541
  },
524
542
  'FilterExpressionLiteral': {
@@ -666,6 +684,22 @@ exports.MALLOY_INTERFACE_TYPES = {
666
684
  },
667
685
  },
668
686
  },
687
+ 'LiteralEqualityComparison': {
688
+ 'type': 'struct',
689
+ 'name': 'LiteralEqualityComparison',
690
+ 'fields': {
691
+ 'field_reference': {
692
+ 'type': 'Reference',
693
+ 'optional': false,
694
+ 'array': false,
695
+ },
696
+ 'value': {
697
+ 'type': 'LiteralValue',
698
+ 'optional': false,
699
+ 'array': false,
700
+ },
701
+ },
702
+ },
669
703
  'LiteralValue': {
670
704
  'type': 'union',
671
705
  'name': 'LiteralValue',
@@ -679,6 +713,17 @@ exports.MALLOY_INTERFACE_TYPES = {
679
713
  'filter_expression_literal': 'FilterExpressionLiteral',
680
714
  },
681
715
  },
716
+ 'LiteralValueExpression': {
717
+ 'type': 'struct',
718
+ 'name': 'LiteralValueExpression',
719
+ 'fields': {
720
+ 'literal_value': {
721
+ 'type': 'LiteralValue',
722
+ 'optional': false,
723
+ 'array': false,
724
+ },
725
+ },
726
+ },
682
727
  'Location': {
683
728
  'type': 'struct',
684
729
  'name': 'Location',
@@ -1414,6 +1459,11 @@ exports.MALLOY_INTERFACE_TYPES = {
1414
1459
  'optional': true,
1415
1460
  'array': false,
1416
1461
  },
1462
+ 'timezone': {
1463
+ 'type': 'string',
1464
+ 'optional': true,
1465
+ 'array': false,
1466
+ },
1417
1467
  },
1418
1468
  },
1419
1469
  'TimestampTimeframe': {
@@ -1536,6 +1586,7 @@ exports.MALLOY_INTERFACE_TYPES = {
1536
1586
  'where': 'FilterOperation',
1537
1587
  'nest': 'Nest',
1538
1588
  'having': 'FilterOperation',
1589
+ 'drill': 'DrillOperation',
1539
1590
  },
1540
1591
  },
1541
1592
  'ViewRefinement': {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy-interfaces",
3
- "version": "0.0.280",
3
+ "version": "0.0.282",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -264,6 +264,7 @@ union ViewOperation {
264
264
  5: required FilterOperation where,
265
265
  6: required Nest nest,
266
266
  7: required FilterOperation having,
267
+ 8: required DrillOperation drill,
267
268
  }
268
269
 
269
270
  struct GroupBy {
@@ -305,8 +306,13 @@ struct FilterOperation {
305
306
  1: required Filter filter,
306
307
  }
307
308
 
309
+ struct DrillOperation {
310
+ 1: required Filter filter,
311
+ }
312
+
308
313
  union Filter {
309
314
  1: required FilterStringApplication filter_string,
315
+ 2: required LiteralEqualityComparison literal_equality,
310
316
  }
311
317
 
312
318
  struct FilterStringApplication {
@@ -314,6 +320,11 @@ struct FilterStringApplication {
314
320
  2: required string filter,
315
321
  }
316
322
 
323
+ struct LiteralEqualityComparison {
324
+ 1: required Reference field_reference,
325
+ 2: required LiteralValue value,
326
+ }
327
+
317
328
  /**
318
329
 
319
330
  stages: [
@@ -416,11 +427,13 @@ struct BooleanLiteral {
416
427
  struct DateLiteral {
417
428
  1: required string date_value,
418
429
  2: optional DateTimeframe granularity,
430
+ 3: optional string timezone,
419
431
  }
420
432
 
421
433
  struct TimestampLiteral {
422
434
  1: required string timestamp_value,
423
435
  2: optional TimestampTimeframe granularity,
436
+ 3: optional string timezone,
424
437
  }
425
438
 
426
439
  struct NullLiteral {
@@ -430,10 +443,15 @@ struct FilterExpressionLiteral {
430
443
  1: required string filter_expression_value,
431
444
  }
432
445
 
446
+ struct LiteralValueExpression {
447
+ 1: required LiteralValue literal_value,
448
+ }
449
+
433
450
  union Expression {
434
451
  1: required Reference field_reference,
435
452
  2: required TimeTruncationFieldReference time_truncation,
436
453
  3: required FilteredField filtered_field,
454
+ 4: required LiteralValueExpression literal_value,
437
455
  }
438
456
 
439
457
  struct TimeTruncationFieldReference {