@malloydata/malloy-interfaces 0.0.237-dev250224215546 → 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.
- package/README.md +5 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +411 -19
- package/dist/reserved_words.d.ts +1 -0
- package/dist/reserved_words.js +117 -0
- package/dist/to_malloy.d.ts +4 -0
- package/dist/to_malloy.js +438 -0
- package/dist/types.d.ts +396 -0
- package/dist/types.js +3 -0
- package/dist/util.d.ts +1 -0
- package/dist/util.js +20 -0
- package/package.json +11 -2
- package/scripts/hacky_gen_types.ts +89 -0
- package/thrift/malloy.thrift +525 -0
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
struct ModelInfo {
|
|
9
|
+
1: required list<ModelEntryValue> entries,
|
|
10
|
+
2: optional list<Annotation> annotations,
|
|
11
|
+
3: required list<QueryInfo> anonymous_queries,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
union ModelEntryValue {
|
|
15
|
+
1: required SourceInfo source,
|
|
16
|
+
2: required QueryInfo query,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
struct SourceInfo {
|
|
20
|
+
1: required string name,
|
|
21
|
+
2: required Schema schema,
|
|
22
|
+
3: optional list<Annotation> annotations,
|
|
23
|
+
4: optional list<ParameterInfo> parameters,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
struct ParameterInfo {
|
|
27
|
+
1: required string name,
|
|
28
|
+
2: required AtomicType type,
|
|
29
|
+
3: optional LiteralValue default_value,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
struct QueryInfo {
|
|
33
|
+
1: required string name,
|
|
34
|
+
2: required Schema schema,
|
|
35
|
+
3: optional list<Annotation> annotations,
|
|
36
|
+
// "openable query"
|
|
37
|
+
4: optional Query definition,
|
|
38
|
+
// TODO consider code and location for ALL objects in the model
|
|
39
|
+
// TODO should this be optional or always present? or not here at all?
|
|
40
|
+
// Argument against: if all objects have their code, then there is tons of repetition
|
|
41
|
+
// Instead, maybe just have all the code in the model (or not at all, rely on user?)
|
|
42
|
+
// and use locations
|
|
43
|
+
// What about definitions from other files?
|
|
44
|
+
// Should Location have a url at all, or just be the Range -- does Thrift handle repetition of
|
|
45
|
+
// strings well?
|
|
46
|
+
5: optional string code,
|
|
47
|
+
// TODO should this be optional or always present? or not here at all?
|
|
48
|
+
6: optional Location location,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
struct AnonymousQueryInfo {
|
|
52
|
+
2: required Schema schema,
|
|
53
|
+
4: optional list<Annotation> annotations,
|
|
54
|
+
// "openable query"
|
|
55
|
+
5: optional Query definition,
|
|
56
|
+
// TODO consider code and location for ALL objects in the model
|
|
57
|
+
// TODO should this be optional or always present? or not here at all?
|
|
58
|
+
// Argument against: if all objects have their code, then there is tons of repetition
|
|
59
|
+
// Instead, maybe just have all the code in the model (or not at all, rely on user?)
|
|
60
|
+
// and use locations
|
|
61
|
+
// What about definitions from other files?
|
|
62
|
+
// Should Location have a url at all, or just be the Range -- does Thrift handle repetition of
|
|
63
|
+
// strings well?
|
|
64
|
+
6: optional string code,
|
|
65
|
+
// TODO should this be optional or always present? or not here at all?
|
|
66
|
+
7: optional Location location,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
struct Location {
|
|
70
|
+
1: required string url,
|
|
71
|
+
2: required Range range,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
struct Range {
|
|
75
|
+
1: required Position start,
|
|
76
|
+
2: required Position end,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
struct Position {
|
|
80
|
+
1: required i32 line,
|
|
81
|
+
2: required i32 character,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
struct Schema {
|
|
85
|
+
1: required list<FieldInfo> fields,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
struct Annotation {
|
|
89
|
+
1: required string value,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
union FieldInfo {
|
|
93
|
+
// 1: required AtomicField atomic_field,
|
|
94
|
+
1: required DimensionInfo dimension,
|
|
95
|
+
2: required MeasureInfo measure,
|
|
96
|
+
3: required JoinInfo join,
|
|
97
|
+
4: required ViewInfo view,
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// TODO should these just be "AtomicField" with a "fieldtype"
|
|
101
|
+
struct DimensionInfo {
|
|
102
|
+
1: required string name,
|
|
103
|
+
2: required AtomicType type,
|
|
104
|
+
3: optional list<Annotation> annotations,
|
|
105
|
+
// TODO possibly need "wasDimension vs wasMeasure"
|
|
106
|
+
// TODO possibly need "isExpression" depending on how we do drills
|
|
107
|
+
// TODO possibly need "isParameter" depending on how we do drills
|
|
108
|
+
// TODO possibly need "isProtected/isPrivate" depending on how we do drills
|
|
109
|
+
// TODO possibly need `referenceId` to enable renderer to know when two fields are the same
|
|
110
|
+
// or maybe we can come up with another solution?
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
struct MeasureInfo {
|
|
114
|
+
1: required string name,
|
|
115
|
+
2: required AtomicType type,
|
|
116
|
+
3: optional list<Annotation> annotations,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// TODO do I need the full "nested"/"query"/"one_to_one" etc?
|
|
120
|
+
enum Relationship {
|
|
121
|
+
ONE = 1,
|
|
122
|
+
MANY = 2,
|
|
123
|
+
CROSS = 3
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
struct JoinInfo {
|
|
127
|
+
1: required string name,
|
|
128
|
+
2: required Schema schema,
|
|
129
|
+
3: optional list<Annotation> annotations,
|
|
130
|
+
4: required Relationship relationship,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
struct ViewInfo {
|
|
134
|
+
1: required string name,
|
|
135
|
+
2: required Schema schema,
|
|
136
|
+
3: optional list<Annotation> annotations,
|
|
137
|
+
// TODO naming of this
|
|
138
|
+
// "openable view"
|
|
139
|
+
4: optional View definition,
|
|
140
|
+
// Possibly need `filterList` depending on how we do drills
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
struct View {
|
|
144
|
+
2: required ViewDefinition definition,
|
|
145
|
+
3: optional list<Annotation> annotations,
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
enum OrderByDirection {
|
|
149
|
+
ASC = 1,
|
|
150
|
+
DESC = 2,
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
struct StringType {
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
struct BooleanType {
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
enum NumberSubtype {
|
|
160
|
+
INTEGER = 1,
|
|
161
|
+
DECIMAL = 2,
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
struct NumberType {
|
|
165
|
+
1: optional NumberSubtype subtype,
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
struct JSONType {
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
struct ArrayType {
|
|
172
|
+
1: required AtomicType element_type;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
struct RecordType {
|
|
176
|
+
1: required list<DimensionInfo> fields
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
union AtomicType {
|
|
180
|
+
1: required StringType string_type,
|
|
181
|
+
2: required BooleanType boolean_type,
|
|
182
|
+
3: required NumberType number_type,
|
|
183
|
+
4: required JSONType json_type,
|
|
184
|
+
5: required SQLNativeType sql_native_type,
|
|
185
|
+
6: required DateType date_type,
|
|
186
|
+
7: required TimestampType timestamp_type,
|
|
187
|
+
9: required ArrayType array_type,
|
|
188
|
+
10: required RecordType record_type,
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
struct SQLNativeType {
|
|
192
|
+
1: optional string sql_type,
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
enum DateTimeframe {
|
|
196
|
+
YEAR = 1,
|
|
197
|
+
QUARTER = 2,
|
|
198
|
+
MONTH = 3,
|
|
199
|
+
WEEK = 4,
|
|
200
|
+
DAY = 5,
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
enum TimestampTimeframe {
|
|
204
|
+
YEAR = 1,
|
|
205
|
+
QUARTER = 2,
|
|
206
|
+
MONTH = 3,
|
|
207
|
+
WEEK = 4,
|
|
208
|
+
DAY = 5,
|
|
209
|
+
HOUR = 6,
|
|
210
|
+
MINUTE = 7,
|
|
211
|
+
SECOND = 8,
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
struct DateType {
|
|
215
|
+
2: optional DateTimeframe timeframe,
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
struct TimestampType {
|
|
219
|
+
2: optional TimestampTimeframe timeframe,
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/*
|
|
223
|
+
|
|
224
|
+
Questions:
|
|
225
|
+
- Should `fields`, `sources`, etc. be Map<string, Field> or Field[]
|
|
226
|
+
- Any way to have an "either" type? use unions?
|
|
227
|
+
- How to represent a refinement of a model query
|
|
228
|
+
|
|
229
|
+
Generate typescript?
|
|
230
|
+
- https://github.com/creditkarma/thrift-typescript
|
|
231
|
+
- https://www.internalfb.com/diff/D68557062
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
union ViewOperation {
|
|
235
|
+
1: required GroupBy group_by,
|
|
236
|
+
2: required Aggregate aggregate,
|
|
237
|
+
3: OrderBy order_by,
|
|
238
|
+
4: required Limit limit,
|
|
239
|
+
5: required Where where,
|
|
240
|
+
6: required Nest nest,
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
struct GroupBy {
|
|
244
|
+
1: optional string name,
|
|
245
|
+
2: required Field field,
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
struct Nest {
|
|
249
|
+
1: optional string name,
|
|
250
|
+
2: required View view,
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
struct Aggregate {
|
|
254
|
+
1: optional string name,
|
|
255
|
+
2: required Field field,
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
struct Field {
|
|
259
|
+
1: required Expression expression,
|
|
260
|
+
// TODO only two kinds of distinguishable annotations are before `aggregate:` and before `name is value`
|
|
261
|
+
// between `name` and `is`, or between `is` and `value` are converted to before `name`.
|
|
262
|
+
2: optional list<Annotation> annotations,
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
struct OrderBy {
|
|
266
|
+
1: required Reference field_reference,
|
|
267
|
+
2: optional OrderByDirection direction,
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
struct Limit {
|
|
271
|
+
1: required i32 limit,
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// TODO this is a bit annoying, but the current typescript system doesn't really
|
|
275
|
+
// allow me to have a union whose property is also a union, since I'm compressing them
|
|
276
|
+
// into an intersection type of `{__type: } & Where`. If Where is also a union, then
|
|
277
|
+
// there would be two `__type` fields...
|
|
278
|
+
struct Where {
|
|
279
|
+
1: required Filter filter,
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
union Filter {
|
|
283
|
+
1: required FilterStringApplication filter_string,
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
struct FilterStringApplication {
|
|
287
|
+
1: required Reference field_reference,
|
|
288
|
+
2: required string filter,
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
|
|
293
|
+
stages: [
|
|
294
|
+
{ref: ff}
|
|
295
|
+
{refin: {base: ff}, {seg}}
|
|
296
|
+
{seg}
|
|
297
|
+
]
|
|
298
|
+
|
|
299
|
+
stages: [
|
|
300
|
+
{
|
|
301
|
+
refinements: [
|
|
302
|
+
{ref}
|
|
303
|
+
{ref}
|
|
304
|
+
{seg}
|
|
305
|
+
]
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
struct Query {
|
|
312
|
+
1: required QueryDefinition definition,
|
|
313
|
+
2: optional list<Annotation> annotations,
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
union QueryDefinition {
|
|
317
|
+
1: QueryArrow arrow,
|
|
318
|
+
2: Reference query_reference,
|
|
319
|
+
3: QueryRefinement refinement,
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
struct QueryArrow {
|
|
323
|
+
1: required Reference source_reference,
|
|
324
|
+
2: required ViewDefinition view,
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
struct QueryRefinement {
|
|
328
|
+
1: required Reference query_reference,
|
|
329
|
+
2: required ViewDefinition refinement,
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
union ViewDefinition {
|
|
333
|
+
1: ViewArrow arrow,
|
|
334
|
+
2: Reference view_reference,
|
|
335
|
+
3: ViewRefinement refinement,
|
|
336
|
+
4: ViewSegment segment,
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
struct ViewRefinement {
|
|
340
|
+
1: required ViewDefinition base,
|
|
341
|
+
2: required ViewDefinition refinement,
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
struct ViewArrow {
|
|
345
|
+
1: required ViewDefinition source,
|
|
346
|
+
2: required ViewDefinition view,
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
struct ViewSegment {
|
|
350
|
+
1: required list<ViewOperation> operations,
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
struct Reference {
|
|
354
|
+
1: required string name,
|
|
355
|
+
2: optional list<string> path,
|
|
356
|
+
3: optional list<ParameterValue> parameters,
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
struct ParameterValue {
|
|
360
|
+
1: required string name,
|
|
361
|
+
2: required LiteralValue value,
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
union LiteralValue {
|
|
365
|
+
1: required StringLiteral string_literal,
|
|
366
|
+
2: required NumberLiteral number_literal,
|
|
367
|
+
3: required DateLiteral date_literal,
|
|
368
|
+
4: required TimestampLiteral timestamp_literal,
|
|
369
|
+
5: required BooleanLiteral boolean_literal,
|
|
370
|
+
6: required NullLiteral null_literal,
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
struct StringLiteral {
|
|
374
|
+
1: required string string_value,
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
struct NumberLiteral {
|
|
378
|
+
1: required double number_value,
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
struct BooleanLiteral {
|
|
382
|
+
1: required bool boolean_value,
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
struct DateLiteral {
|
|
386
|
+
1: required string date_value,
|
|
387
|
+
2: optional DateTimeframe granularity,
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
struct TimestampLiteral {
|
|
391
|
+
1: required string timestamp_value,
|
|
392
|
+
2: optional TimestampTimeframe granularity,
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
struct NullLiteral {
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
union Expression {
|
|
399
|
+
1: required Reference field_reference,
|
|
400
|
+
2: required TimeTruncationFieldReference time_truncation,
|
|
401
|
+
3: required FilteredField filtered_field,
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
struct TimeTruncationFieldReference {
|
|
405
|
+
1: required Reference field_reference, // TODO do I make this circular, more like actual grammar? e.g. TimeTruncation rather than TimeTruncationFieldReference
|
|
406
|
+
2: required TimestampTimeframe truncation,
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
struct FilteredField {
|
|
410
|
+
1: required Reference field_reference,
|
|
411
|
+
2: required list<Where> where,
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
struct StringCell {
|
|
415
|
+
1: required string string_value,
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
struct BooleanCell {
|
|
419
|
+
1: required bool boolean_value,
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
struct NumberCell {
|
|
423
|
+
1: required double number_value,
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
struct TimestampCell {
|
|
427
|
+
1: required string timestamp_value, // TODO another way to represent dates?
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
struct DateCell {
|
|
431
|
+
1: required string date_value, // TODO another way to represent dates?
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
struct JSONCell {
|
|
435
|
+
1: required string json_value,
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
struct ArrayCell {
|
|
439
|
+
1: required list<Cell> array_value,
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// A record is also just a list of values, because we don't need to store the names in the data
|
|
443
|
+
struct RecordCell {
|
|
444
|
+
1: required list<Cell> record_value,
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
struct TableCell {
|
|
448
|
+
1: required Table table_value,
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
union Cell {
|
|
452
|
+
1: required StringCell string_cell,
|
|
453
|
+
2: required BooleanCell boolean_cell,
|
|
454
|
+
3: required DateCell date_cell,
|
|
455
|
+
4: required TimestampCell timestamp_cell, // TODO does this need to be separate?
|
|
456
|
+
5: required NumberCell number_cell,
|
|
457
|
+
6: required JSONCell json_cell, // TODO does this need to be here?
|
|
458
|
+
7: required RecordCell record_cell,
|
|
459
|
+
8: required ArrayCell array_cell,
|
|
460
|
+
9: required TableCell table_cell, // TODO does this need to be different from an array of records
|
|
461
|
+
// TODO sql_native???
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
struct Row {
|
|
465
|
+
1: required list<Cell> cells,
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
struct Table {
|
|
469
|
+
1: required list<Row> rows,
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
union Data {
|
|
473
|
+
1: required RecordCell record,
|
|
474
|
+
2: required Table table,
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// should this be one type "Result" with optional data/sql, or three different types?
|
|
478
|
+
struct Result {
|
|
479
|
+
1: optional Data data,
|
|
480
|
+
2: required Schema schema,
|
|
481
|
+
3: optional string sql,
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/*
|
|
485
|
+
|
|
486
|
+
Result metadata:
|
|
487
|
+
|
|
488
|
+
// I think not used
|
|
489
|
+
|
|
490
|
+
sourceField: string;
|
|
491
|
+
|
|
492
|
+
// used by drill to drill on fields which were expressions (probably in future replaced with `where: view_name.field ? ...`)
|
|
493
|
+
|
|
494
|
+
sourceExpression?: string;
|
|
495
|
+
|
|
496
|
+
// only used by legacy renderer
|
|
497
|
+
|
|
498
|
+
sourceClasses: string[];
|
|
499
|
+
|
|
500
|
+
// used by drill to collect filters
|
|
501
|
+
|
|
502
|
+
filterList?: FilterCondition[];
|
|
503
|
+
|
|
504
|
+
// used by renderer to pick default axes
|
|
505
|
+
|
|
506
|
+
fieldKind: 'measure' | 'dimension' | 'struct';
|
|
507
|
+
|
|
508
|
+
// used by renderer to know whether two fields in the result are the same, for hover syncing and axis sharing etc
|
|
509
|
+
|
|
510
|
+
referenceId?: string;
|
|
511
|
+
*/
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
/*
|
|
515
|
+
TODO
|
|
516
|
+
- formalize difference between a "Summary" of a thing and a "Definition" of a thing
|
|
517
|
+
this will make the naming of things clearer: ViewSummary vs ViewDefinition
|
|
518
|
+
- Openable views
|
|
519
|
+
- code for things
|
|
520
|
+
- openable dimensions/measures?
|
|
521
|
+
|
|
522
|
+
*/
|
|
523
|
+
|
|
524
|
+
// concern: shape of FieldInfo and GroupBy (no object for "Field") are funadmentally pretty different,
|
|
525
|
+
// but it might be nice for them to be more similar.
|