@malloydata/malloy-interfaces 0.0.237-dev250225015031 → 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
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
export type Aggregate = {
|
|
2
|
+
name?: string;
|
|
3
|
+
field: Field;
|
|
4
|
+
};
|
|
5
|
+
export type Annotation = {
|
|
6
|
+
value: string;
|
|
7
|
+
};
|
|
8
|
+
export type AnonymousQueryInfo = {
|
|
9
|
+
schema: Schema;
|
|
10
|
+
annotations?: Array<Annotation>;
|
|
11
|
+
definition?: Query;
|
|
12
|
+
code?: string;
|
|
13
|
+
location?: Location;
|
|
14
|
+
};
|
|
15
|
+
export type ArrayCell = {
|
|
16
|
+
array_value: Array<Cell>;
|
|
17
|
+
};
|
|
18
|
+
export type ArrayType = {
|
|
19
|
+
element_type: AtomicType;
|
|
20
|
+
};
|
|
21
|
+
export type AtomicTypeType = 'string_type' | 'boolean_type' | 'number_type' | 'json_type' | 'sql_native_type' | 'date_type' | 'timestamp_type' | 'array_type' | 'record_type';
|
|
22
|
+
export type AtomicType = AtomicTypeWithStringType | AtomicTypeWithBooleanType | AtomicTypeWithNumberType | AtomicTypeWithJSONType | AtomicTypeWithSQLNativeType | AtomicTypeWithDateType | AtomicTypeWithTimestampType | AtomicTypeWithArrayType | AtomicTypeWithRecordType;
|
|
23
|
+
export type AtomicTypeWithStringType = {
|
|
24
|
+
kind: 'string_type';
|
|
25
|
+
} & StringType;
|
|
26
|
+
export type AtomicTypeWithBooleanType = {
|
|
27
|
+
kind: 'boolean_type';
|
|
28
|
+
} & BooleanType;
|
|
29
|
+
export type AtomicTypeWithNumberType = {
|
|
30
|
+
kind: 'number_type';
|
|
31
|
+
} & NumberType;
|
|
32
|
+
export type AtomicTypeWithJSONType = {
|
|
33
|
+
kind: 'json_type';
|
|
34
|
+
} & JSONType;
|
|
35
|
+
export type AtomicTypeWithSQLNativeType = {
|
|
36
|
+
kind: 'sql_native_type';
|
|
37
|
+
} & SQLNativeType;
|
|
38
|
+
export type AtomicTypeWithDateType = {
|
|
39
|
+
kind: 'date_type';
|
|
40
|
+
} & DateType;
|
|
41
|
+
export type AtomicTypeWithTimestampType = {
|
|
42
|
+
kind: 'timestamp_type';
|
|
43
|
+
} & TimestampType;
|
|
44
|
+
export type AtomicTypeWithArrayType = {
|
|
45
|
+
kind: 'array_type';
|
|
46
|
+
} & ArrayType;
|
|
47
|
+
export type AtomicTypeWithRecordType = {
|
|
48
|
+
kind: 'record_type';
|
|
49
|
+
} & RecordType;
|
|
50
|
+
export type BooleanCell = {
|
|
51
|
+
boolean_value: boolean;
|
|
52
|
+
};
|
|
53
|
+
export type BooleanLiteral = {
|
|
54
|
+
boolean_value: boolean;
|
|
55
|
+
};
|
|
56
|
+
export type BooleanType = {};
|
|
57
|
+
export type CellType = 'string_cell' | 'boolean_cell' | 'date_cell' | 'timestamp_cell' | 'number_cell' | 'json_cell' | 'record_cell' | 'array_cell' | 'table_cell';
|
|
58
|
+
export type Cell = CellWithStringCell | CellWithBooleanCell | CellWithDateCell | CellWithTimestampCell | CellWithNumberCell | CellWithJSONCell | CellWithRecordCell | CellWithArrayCell | CellWithTableCell;
|
|
59
|
+
export type CellWithStringCell = {
|
|
60
|
+
kind: 'string_cell';
|
|
61
|
+
} & StringCell;
|
|
62
|
+
export type CellWithBooleanCell = {
|
|
63
|
+
kind: 'boolean_cell';
|
|
64
|
+
} & BooleanCell;
|
|
65
|
+
export type CellWithDateCell = {
|
|
66
|
+
kind: 'date_cell';
|
|
67
|
+
} & DateCell;
|
|
68
|
+
export type CellWithTimestampCell = {
|
|
69
|
+
kind: 'timestamp_cell';
|
|
70
|
+
} & TimestampCell;
|
|
71
|
+
export type CellWithNumberCell = {
|
|
72
|
+
kind: 'number_cell';
|
|
73
|
+
} & NumberCell;
|
|
74
|
+
export type CellWithJSONCell = {
|
|
75
|
+
kind: 'json_cell';
|
|
76
|
+
} & JSONCell;
|
|
77
|
+
export type CellWithRecordCell = {
|
|
78
|
+
kind: 'record_cell';
|
|
79
|
+
} & RecordCell;
|
|
80
|
+
export type CellWithArrayCell = {
|
|
81
|
+
kind: 'array_cell';
|
|
82
|
+
} & ArrayCell;
|
|
83
|
+
export type CellWithTableCell = {
|
|
84
|
+
kind: 'table_cell';
|
|
85
|
+
} & TableCell;
|
|
86
|
+
export type DataType = 'record' | 'table';
|
|
87
|
+
export type Data = DataWithRecord | DataWithTable;
|
|
88
|
+
export type DataWithRecord = {
|
|
89
|
+
kind: 'record';
|
|
90
|
+
} & RecordCell;
|
|
91
|
+
export type DataWithTable = {
|
|
92
|
+
kind: 'table';
|
|
93
|
+
} & Table;
|
|
94
|
+
export type DateCell = {
|
|
95
|
+
date_value: string;
|
|
96
|
+
};
|
|
97
|
+
export type DateLiteral = {
|
|
98
|
+
date_value: string;
|
|
99
|
+
granularity?: DateTimeframe;
|
|
100
|
+
};
|
|
101
|
+
export type DateTimeframe = 'year' | 'quarter' | 'month' | 'week' | 'day';
|
|
102
|
+
export type DateType = {
|
|
103
|
+
timeframe?: DateTimeframe;
|
|
104
|
+
};
|
|
105
|
+
export type DimensionInfo = {
|
|
106
|
+
name: string;
|
|
107
|
+
type: AtomicType;
|
|
108
|
+
annotations?: Array<Annotation>;
|
|
109
|
+
};
|
|
110
|
+
export type ExpressionType = 'field_reference' | 'time_truncation' | 'filtered_field';
|
|
111
|
+
export type Expression = ExpressionWithFieldReference | ExpressionWithTimeTruncation | ExpressionWithFilteredField;
|
|
112
|
+
export type ExpressionWithFieldReference = {
|
|
113
|
+
kind: 'field_reference';
|
|
114
|
+
} & Reference;
|
|
115
|
+
export type ExpressionWithTimeTruncation = {
|
|
116
|
+
kind: 'time_truncation';
|
|
117
|
+
} & TimeTruncationFieldReference;
|
|
118
|
+
export type ExpressionWithFilteredField = {
|
|
119
|
+
kind: 'filtered_field';
|
|
120
|
+
} & FilteredField;
|
|
121
|
+
export type Field = {
|
|
122
|
+
expression: Expression;
|
|
123
|
+
annotations?: Array<Annotation>;
|
|
124
|
+
};
|
|
125
|
+
export type FieldInfoType = 'dimension' | 'measure' | 'join' | 'view';
|
|
126
|
+
export type FieldInfo = FieldInfoWithDimension | FieldInfoWithMeasure | FieldInfoWithJoin | FieldInfoWithView;
|
|
127
|
+
export type FieldInfoWithDimension = {
|
|
128
|
+
kind: 'dimension';
|
|
129
|
+
} & DimensionInfo;
|
|
130
|
+
export type FieldInfoWithMeasure = {
|
|
131
|
+
kind: 'measure';
|
|
132
|
+
} & MeasureInfo;
|
|
133
|
+
export type FieldInfoWithJoin = {
|
|
134
|
+
kind: 'join';
|
|
135
|
+
} & JoinInfo;
|
|
136
|
+
export type FieldInfoWithView = {
|
|
137
|
+
kind: 'view';
|
|
138
|
+
} & ViewInfo;
|
|
139
|
+
export type FilterType = 'filter_string';
|
|
140
|
+
export type Filter = FilterWithFilterString;
|
|
141
|
+
export type FilterWithFilterString = {
|
|
142
|
+
kind: 'filter_string';
|
|
143
|
+
} & FilterStringApplication;
|
|
144
|
+
export type FilterStringApplication = {
|
|
145
|
+
field_reference: Reference;
|
|
146
|
+
filter: string;
|
|
147
|
+
};
|
|
148
|
+
export type FilteredField = {
|
|
149
|
+
field_reference: Reference;
|
|
150
|
+
where: Array<Where>;
|
|
151
|
+
};
|
|
152
|
+
export type GroupBy = {
|
|
153
|
+
name?: string;
|
|
154
|
+
field: Field;
|
|
155
|
+
};
|
|
156
|
+
export type JSONCell = {
|
|
157
|
+
json_value: string;
|
|
158
|
+
};
|
|
159
|
+
export type JSONType = {};
|
|
160
|
+
export type JoinInfo = {
|
|
161
|
+
name: string;
|
|
162
|
+
schema: Schema;
|
|
163
|
+
annotations?: Array<Annotation>;
|
|
164
|
+
relationship: Relationship;
|
|
165
|
+
};
|
|
166
|
+
export type Limit = {
|
|
167
|
+
limit: number;
|
|
168
|
+
};
|
|
169
|
+
export type LiteralValueType = 'string_literal' | 'number_literal' | 'date_literal' | 'timestamp_literal' | 'boolean_literal' | 'null_literal';
|
|
170
|
+
export type LiteralValue = LiteralValueWithStringLiteral | LiteralValueWithNumberLiteral | LiteralValueWithDateLiteral | LiteralValueWithTimestampLiteral | LiteralValueWithBooleanLiteral | LiteralValueWithNullLiteral;
|
|
171
|
+
export type LiteralValueWithStringLiteral = {
|
|
172
|
+
kind: 'string_literal';
|
|
173
|
+
} & StringLiteral;
|
|
174
|
+
export type LiteralValueWithNumberLiteral = {
|
|
175
|
+
kind: 'number_literal';
|
|
176
|
+
} & NumberLiteral;
|
|
177
|
+
export type LiteralValueWithDateLiteral = {
|
|
178
|
+
kind: 'date_literal';
|
|
179
|
+
} & DateLiteral;
|
|
180
|
+
export type LiteralValueWithTimestampLiteral = {
|
|
181
|
+
kind: 'timestamp_literal';
|
|
182
|
+
} & TimestampLiteral;
|
|
183
|
+
export type LiteralValueWithBooleanLiteral = {
|
|
184
|
+
kind: 'boolean_literal';
|
|
185
|
+
} & BooleanLiteral;
|
|
186
|
+
export type LiteralValueWithNullLiteral = {
|
|
187
|
+
kind: 'null_literal';
|
|
188
|
+
} & NullLiteral;
|
|
189
|
+
export type Location = {
|
|
190
|
+
url: string;
|
|
191
|
+
range: Range;
|
|
192
|
+
};
|
|
193
|
+
export type MeasureInfo = {
|
|
194
|
+
name: string;
|
|
195
|
+
type: AtomicType;
|
|
196
|
+
annotations?: Array<Annotation>;
|
|
197
|
+
};
|
|
198
|
+
export type ModelEntryValueType = 'source' | 'query';
|
|
199
|
+
export type ModelEntryValue = ModelEntryValueWithSource | ModelEntryValueWithQuery;
|
|
200
|
+
export type ModelEntryValueWithSource = {
|
|
201
|
+
kind: 'source';
|
|
202
|
+
} & SourceInfo;
|
|
203
|
+
export type ModelEntryValueWithQuery = {
|
|
204
|
+
kind: 'query';
|
|
205
|
+
} & QueryInfo;
|
|
206
|
+
export type ModelInfo = {
|
|
207
|
+
entries: Array<ModelEntryValue>;
|
|
208
|
+
annotations?: Array<Annotation>;
|
|
209
|
+
anonymous_queries: Array<QueryInfo>;
|
|
210
|
+
};
|
|
211
|
+
export type Nest = {
|
|
212
|
+
name?: string;
|
|
213
|
+
view: View;
|
|
214
|
+
};
|
|
215
|
+
export type NullLiteral = {};
|
|
216
|
+
export type NumberCell = {
|
|
217
|
+
number_value: number;
|
|
218
|
+
};
|
|
219
|
+
export type NumberLiteral = {
|
|
220
|
+
number_value: number;
|
|
221
|
+
};
|
|
222
|
+
export type NumberSubtype = 'integer' | 'decimal';
|
|
223
|
+
export type NumberType = {
|
|
224
|
+
subtype?: NumberSubtype;
|
|
225
|
+
};
|
|
226
|
+
export type OrderBy = {
|
|
227
|
+
field_reference: Reference;
|
|
228
|
+
direction?: OrderByDirection;
|
|
229
|
+
};
|
|
230
|
+
export type OrderByDirection = 'asc' | 'desc';
|
|
231
|
+
export type ParameterInfo = {
|
|
232
|
+
name: string;
|
|
233
|
+
type: AtomicType;
|
|
234
|
+
default_value?: LiteralValue;
|
|
235
|
+
};
|
|
236
|
+
export type ParameterValue = {
|
|
237
|
+
name: string;
|
|
238
|
+
value: LiteralValue;
|
|
239
|
+
};
|
|
240
|
+
export type Position = {
|
|
241
|
+
line: number;
|
|
242
|
+
character: number;
|
|
243
|
+
};
|
|
244
|
+
export type Query = {
|
|
245
|
+
definition: QueryDefinition;
|
|
246
|
+
annotations?: Array<Annotation>;
|
|
247
|
+
};
|
|
248
|
+
export type QueryArrow = {
|
|
249
|
+
source_reference: Reference;
|
|
250
|
+
view: ViewDefinition;
|
|
251
|
+
};
|
|
252
|
+
export type QueryDefinitionType = 'arrow' | 'query_reference' | 'refinement';
|
|
253
|
+
export type QueryDefinition = QueryDefinitionWithArrow | QueryDefinitionWithQueryReference | QueryDefinitionWithRefinement;
|
|
254
|
+
export type QueryDefinitionWithArrow = {
|
|
255
|
+
kind: 'arrow';
|
|
256
|
+
} & QueryArrow;
|
|
257
|
+
export type QueryDefinitionWithQueryReference = {
|
|
258
|
+
kind: 'query_reference';
|
|
259
|
+
} & Reference;
|
|
260
|
+
export type QueryDefinitionWithRefinement = {
|
|
261
|
+
kind: 'refinement';
|
|
262
|
+
} & QueryRefinement;
|
|
263
|
+
export type QueryInfo = {
|
|
264
|
+
name: string;
|
|
265
|
+
schema: Schema;
|
|
266
|
+
annotations?: Array<Annotation>;
|
|
267
|
+
definition?: Query;
|
|
268
|
+
code?: string;
|
|
269
|
+
location?: Location;
|
|
270
|
+
};
|
|
271
|
+
export type QueryRefinement = {
|
|
272
|
+
query_reference: Reference;
|
|
273
|
+
refinement: ViewDefinition;
|
|
274
|
+
};
|
|
275
|
+
export type Range = {
|
|
276
|
+
start: Position;
|
|
277
|
+
end: Position;
|
|
278
|
+
};
|
|
279
|
+
export type RecordCell = {
|
|
280
|
+
record_value: Array<Cell>;
|
|
281
|
+
};
|
|
282
|
+
export type RecordType = {
|
|
283
|
+
fields: Array<DimensionInfo>;
|
|
284
|
+
};
|
|
285
|
+
export type Reference = {
|
|
286
|
+
name: string;
|
|
287
|
+
path?: Array<string>;
|
|
288
|
+
parameters?: Array<ParameterValue>;
|
|
289
|
+
};
|
|
290
|
+
export type Relationship = 'one' | 'many' | 'cross';
|
|
291
|
+
export type Result = {
|
|
292
|
+
data?: Data;
|
|
293
|
+
schema: Schema;
|
|
294
|
+
sql?: string;
|
|
295
|
+
};
|
|
296
|
+
export type Row = {
|
|
297
|
+
cells: Array<Cell>;
|
|
298
|
+
};
|
|
299
|
+
export type SQLNativeType = {
|
|
300
|
+
sql_type?: string;
|
|
301
|
+
};
|
|
302
|
+
export type Schema = {
|
|
303
|
+
fields: Array<FieldInfo>;
|
|
304
|
+
};
|
|
305
|
+
export type SourceInfo = {
|
|
306
|
+
name: string;
|
|
307
|
+
schema: Schema;
|
|
308
|
+
annotations?: Array<Annotation>;
|
|
309
|
+
parameters?: Array<ParameterInfo>;
|
|
310
|
+
};
|
|
311
|
+
export type StringCell = {
|
|
312
|
+
string_value: string;
|
|
313
|
+
};
|
|
314
|
+
export type StringLiteral = {
|
|
315
|
+
string_value: string;
|
|
316
|
+
};
|
|
317
|
+
export type StringType = {};
|
|
318
|
+
export type Table = {
|
|
319
|
+
rows: Array<Row>;
|
|
320
|
+
};
|
|
321
|
+
export type TableCell = {
|
|
322
|
+
table_value: Table;
|
|
323
|
+
};
|
|
324
|
+
export type TimeTruncationFieldReference = {
|
|
325
|
+
field_reference: Reference;
|
|
326
|
+
truncation: TimestampTimeframe;
|
|
327
|
+
};
|
|
328
|
+
export type TimestampCell = {
|
|
329
|
+
timestamp_value: string;
|
|
330
|
+
};
|
|
331
|
+
export type TimestampLiteral = {
|
|
332
|
+
timestamp_value: string;
|
|
333
|
+
granularity?: TimestampTimeframe;
|
|
334
|
+
};
|
|
335
|
+
export type TimestampTimeframe = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
|
|
336
|
+
export type TimestampType = {
|
|
337
|
+
timeframe?: TimestampTimeframe;
|
|
338
|
+
};
|
|
339
|
+
export type View = {
|
|
340
|
+
definition: ViewDefinition;
|
|
341
|
+
annotations?: Array<Annotation>;
|
|
342
|
+
};
|
|
343
|
+
export type ViewArrow = {
|
|
344
|
+
source: ViewDefinition;
|
|
345
|
+
view: ViewDefinition;
|
|
346
|
+
};
|
|
347
|
+
export type ViewDefinitionType = 'arrow' | 'view_reference' | 'refinement' | 'segment';
|
|
348
|
+
export type ViewDefinition = ViewDefinitionWithArrow | ViewDefinitionWithViewReference | ViewDefinitionWithRefinement | ViewDefinitionWithSegment;
|
|
349
|
+
export type ViewDefinitionWithArrow = {
|
|
350
|
+
kind: 'arrow';
|
|
351
|
+
} & ViewArrow;
|
|
352
|
+
export type ViewDefinitionWithViewReference = {
|
|
353
|
+
kind: 'view_reference';
|
|
354
|
+
} & Reference;
|
|
355
|
+
export type ViewDefinitionWithRefinement = {
|
|
356
|
+
kind: 'refinement';
|
|
357
|
+
} & ViewRefinement;
|
|
358
|
+
export type ViewDefinitionWithSegment = {
|
|
359
|
+
kind: 'segment';
|
|
360
|
+
} & ViewSegment;
|
|
361
|
+
export type ViewInfo = {
|
|
362
|
+
name: string;
|
|
363
|
+
schema: Schema;
|
|
364
|
+
annotations?: Array<Annotation>;
|
|
365
|
+
definition?: View;
|
|
366
|
+
};
|
|
367
|
+
export type ViewOperationType = 'group_by' | 'aggregate' | 'order_by' | 'limit' | 'where' | 'nest';
|
|
368
|
+
export type ViewOperation = ViewOperationWithGroupBy | ViewOperationWithAggregate | ViewOperationWithOrderBy | ViewOperationWithLimit | ViewOperationWithWhere | ViewOperationWithNest;
|
|
369
|
+
export type ViewOperationWithGroupBy = {
|
|
370
|
+
kind: 'group_by';
|
|
371
|
+
} & GroupBy;
|
|
372
|
+
export type ViewOperationWithAggregate = {
|
|
373
|
+
kind: 'aggregate';
|
|
374
|
+
} & Aggregate;
|
|
375
|
+
export type ViewOperationWithOrderBy = {
|
|
376
|
+
kind: 'order_by';
|
|
377
|
+
} & OrderBy;
|
|
378
|
+
export type ViewOperationWithLimit = {
|
|
379
|
+
kind: 'limit';
|
|
380
|
+
} & Limit;
|
|
381
|
+
export type ViewOperationWithWhere = {
|
|
382
|
+
kind: 'where';
|
|
383
|
+
} & Where;
|
|
384
|
+
export type ViewOperationWithNest = {
|
|
385
|
+
kind: 'nest';
|
|
386
|
+
} & Nest;
|
|
387
|
+
export type ViewRefinement = {
|
|
388
|
+
base: ViewDefinition;
|
|
389
|
+
refinement: ViewDefinition;
|
|
390
|
+
};
|
|
391
|
+
export type ViewSegment = {
|
|
392
|
+
operations: Array<ViewOperation>;
|
|
393
|
+
};
|
|
394
|
+
export type Where = {
|
|
395
|
+
filter: Filter;
|
|
396
|
+
};
|
package/dist/types.js
ADDED
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function maybeQuoteIdentifier(name: string): string;
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maybeQuoteIdentifier = void 0;
|
|
4
|
+
const reserved_words_1 = require("./reserved_words");
|
|
5
|
+
function shouldQuoteIdentifier(name) {
|
|
6
|
+
const containsFunnyCharacters = !name.match(/^[A-Za-z_][A-Za-z_0-9]*$/);
|
|
7
|
+
const isReserved = reserved_words_1.RESERVED_WORDS.includes(name.toLowerCase());
|
|
8
|
+
return containsFunnyCharacters || isReserved;
|
|
9
|
+
}
|
|
10
|
+
function maybeQuoteIdentifier(name) {
|
|
11
|
+
const path = name.split('.');
|
|
12
|
+
for (let i = 0; i < path.length; i++) {
|
|
13
|
+
if (shouldQuoteIdentifier(path[i])) {
|
|
14
|
+
path[i] = `\`${path[i]}\``;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return path.join('.');
|
|
18
|
+
}
|
|
19
|
+
exports.maybeQuoteIdentifier = maybeQuoteIdentifier;
|
|
20
|
+
//# sourceMappingURL=util.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/malloy-interfaces",
|
|
3
|
-
"version": "0.0.237-
|
|
3
|
+
"version": "0.0.237-dev250225144145",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,6 +16,15 @@
|
|
|
16
16
|
"test": "jest --config=../../jest.config.js",
|
|
17
17
|
"clean": "tsc --build --clean",
|
|
18
18
|
"build": "tsc --build",
|
|
19
|
-
"prepublishOnly": "npm run clean && npm run build"
|
|
19
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
20
|
+
"verify-types": "thrift-typescript --strictUnions --target thrift-server --sourceDir thrift --outDir generated-types malloy.thrift",
|
|
21
|
+
"generate-types": "rm -f generated-types/* && thrift-typescript --strictUnions --target thrift-server --sourceDir thrift --outDir generated-types malloy.thrift && ts-node scripts/hacky_gen_types.ts > src/types.ts && cd ../.. && eslint 'packages/malloy-interfaces/src/types.ts' --fix"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@creditkarma/thrift-typescript": "^3.7.6",
|
|
25
|
+
"ts-node": "^10.9.2"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@creditkarma/thrift-server-core": "^1.0.4"
|
|
20
29
|
}
|
|
21
30
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line no-console
|
|
4
|
+
console.log(`/*
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
/*
|
|
11
|
+
* Autogenerated.
|
|
12
|
+
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
|
13
|
+
*/`);
|
|
14
|
+
|
|
15
|
+
function snakeToCamel(m: string) {
|
|
16
|
+
return m.replace(/_([a-z])/g, g => g[1].toUpperCase());
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function fixEnum(m: string) {
|
|
20
|
+
m = m.replace(/enum ([A-Za-z]+)Type {/, 'type $1Type = ');
|
|
21
|
+
return m.replace(/ {2}[A-Za-z]+With[A-Za-z_]+ = ("[a-z_]+"),?\n}?/g, '| $1');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function fixEnum2(m: string) {
|
|
25
|
+
m = m.replace(/export enum ([A-Za-z_]+) {\n/g, 'export type $1 =');
|
|
26
|
+
m = m.replace(/ {2}([A-Z_]+) = \d+,?\n/g, m =>
|
|
27
|
+
m.replace(/ {2}([A-Z_]+) = \d+,?\n/, '| "$1"').toLowerCase()
|
|
28
|
+
);
|
|
29
|
+
return m.replace(/\}/, '');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function fixUnionType(m: string) {
|
|
33
|
+
m = m.replace(/\n {2}(__type: [A-Za-z_]+Type.[A-Za-z_]+);\n/, '$1} &');
|
|
34
|
+
m = m.replace(/ {2}[a-z_]+\?: undefined;\n/g, '');
|
|
35
|
+
m = m.replace(/ {2}[a-z_]+: ([A-Za-z_]+);\n/, ' $1');
|
|
36
|
+
m = m.replace(/}$/, ';');
|
|
37
|
+
return m;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let allTypes = '';
|
|
41
|
+
for (const file of fs.readdirSync('./generated-types')) {
|
|
42
|
+
if (file === 'index.ts') continue;
|
|
43
|
+
const text = fs.readFileSync(`./generated-types/${file}`, 'utf8');
|
|
44
|
+
const lines = text.split('\n');
|
|
45
|
+
const firstTypeLine = lines.findIndex(line => line.startsWith('export'));
|
|
46
|
+
const firstNonTypeLine = lines.findIndex(
|
|
47
|
+
line => line.endsWith('Args;') || line.endsWith('Args {')
|
|
48
|
+
);
|
|
49
|
+
let actualTypes = lines.slice(firstTypeLine, firstNonTypeLine).join('\n');
|
|
50
|
+
actualTypes = actualTypes.replace(
|
|
51
|
+
/export interface I([A-Za-z_]+) {/g,
|
|
52
|
+
'export type $1 = {'
|
|
53
|
+
);
|
|
54
|
+
actualTypes = actualTypes.replace(/([A-Za-z]+)\.I\1/g, '$1');
|
|
55
|
+
actualTypes = actualTypes.replace(/([A-Za-z]+)\.\1/g, '$1');
|
|
56
|
+
actualTypes = actualTypes.replace(/= I/g, '= ');
|
|
57
|
+
actualTypes = actualTypes.replace(/\| I/g, '| ');
|
|
58
|
+
actualTypes = actualTypes.replace(/ {4}/g, ' ');
|
|
59
|
+
actualTypes = actualTypes.replace(
|
|
60
|
+
/enum ([A-Za-z]+)Type {\n( {2}\1With([A-Za-z_]+) = "[a-z_]+",?\n)+}/g,
|
|
61
|
+
fixEnum
|
|
62
|
+
);
|
|
63
|
+
actualTypes = actualTypes.replace(
|
|
64
|
+
/export type ([A-Za-z]+)With([A-Za-z_]+) = {\n {2}(__type: \1Type.\1With\2);\n( {2}[a-z_]+\?: undefined;\n)*( {2}[a-z_]+: [A-Za-z_]+;\n)( {2}[a-z_]+\?: undefined;\n)*}/g,
|
|
65
|
+
fixUnionType
|
|
66
|
+
);
|
|
67
|
+
actualTypes = actualTypes.replace(
|
|
68
|
+
/__type: ([A-Za-z]+)Type\.\1With[A-Za-z_]+/g,
|
|
69
|
+
m =>
|
|
70
|
+
m
|
|
71
|
+
.replace(
|
|
72
|
+
/__type: [A-Za-z]+Type\.[A-Za-z]+With([A-Za-z_]+)/,
|
|
73
|
+
'__type: "$1"'
|
|
74
|
+
)
|
|
75
|
+
.toLowerCase()
|
|
76
|
+
);
|
|
77
|
+
actualTypes = actualTypes.replace(
|
|
78
|
+
/export enum ([A-Za-z_]+) {\n( {2}[A-Z_]+ = \d+,?\n)+}/g,
|
|
79
|
+
fixEnum2
|
|
80
|
+
);
|
|
81
|
+
actualTypes = actualTypes.replace(/Json/g, 'JSON');
|
|
82
|
+
actualTypes = actualTypes.replace(/Sql/g, 'SQL');
|
|
83
|
+
actualTypes = actualTypes.replace(/__type/g, 'kind');
|
|
84
|
+
actualTypes = actualTypes.replace(/With[A-Za-z_]+/g, snakeToCamel);
|
|
85
|
+
allTypes += actualTypes + '\n';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// eslint-disable-next-line no-console
|
|
89
|
+
console.log(allTypes);
|