@malloydata/malloy-interfaces 0.0.241 → 0.0.242-dev250313002313
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/nest_unions.d.ts +1 -0
- package/dist/nest_unions.js +50 -1
- package/dist/types.d.ts +20 -0
- package/dist/types.js +1459 -0
- package/package.json +1 -1
- package/scripts/hacky_gen_types.ts +190 -65
package/dist/nest_unions.d.ts
CHANGED
package/dist/nest_unions.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.nestUnions = void 0;
|
|
9
|
+
exports.unnestUnions = exports.nestUnions = void 0;
|
|
10
|
+
const types_1 = require("./types");
|
|
10
11
|
function nestUnions(obj) {
|
|
11
12
|
if (obj === null) {
|
|
12
13
|
return obj;
|
|
@@ -37,4 +38,52 @@ function nestUnions(obj) {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
exports.nestUnions = nestUnions;
|
|
41
|
+
function unnestUnions(obj, type) {
|
|
42
|
+
if (obj === null || obj === undefined) {
|
|
43
|
+
return obj;
|
|
44
|
+
}
|
|
45
|
+
else if (typeof obj === 'string' || typeof obj === 'number') {
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
else if (Array.isArray(obj)) {
|
|
49
|
+
return obj.map(value => unnestUnions(value, type));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (type === undefined) {
|
|
53
|
+
throw new Error('Cannot unnest unions of object without a type');
|
|
54
|
+
}
|
|
55
|
+
const typeDefinition = types_1.MALLOY_INTERFACE_TYPES[type];
|
|
56
|
+
if (typeDefinition === undefined) {
|
|
57
|
+
throw new Error(`Unknown Malloy interface type ${type}`);
|
|
58
|
+
}
|
|
59
|
+
if (typeDefinition.type === 'union') {
|
|
60
|
+
for (const kind in typeDefinition.options) {
|
|
61
|
+
if (obj[kind] !== undefined) {
|
|
62
|
+
const result = unnestUnions(obj[kind], typeDefinition.options[kind]);
|
|
63
|
+
if (typeof result === 'object') {
|
|
64
|
+
return {
|
|
65
|
+
kind,
|
|
66
|
+
...result,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (typeDefinition.type === 'struct') {
|
|
73
|
+
const result = {};
|
|
74
|
+
for (const key in obj) {
|
|
75
|
+
const childType = typeDefinition.fields[key];
|
|
76
|
+
if (childType === undefined) {
|
|
77
|
+
throw new Error(`Unknown field ${key} in ${type}`);
|
|
78
|
+
}
|
|
79
|
+
result[key] = unnestUnions(obj[key], childType.type);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new Error(`Cannot unnest unions in an enum type ${type}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.unnestUnions = unnestUnions;
|
|
40
89
|
//# sourceMappingURL=nest_unions.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
type MalloyInterfaceFieldType = {
|
|
2
|
+
type: string;
|
|
3
|
+
optional: boolean;
|
|
4
|
+
array: boolean;
|
|
5
|
+
};
|
|
6
|
+
type MalloyInterfaceType = {
|
|
7
|
+
name: string;
|
|
8
|
+
type: 'struct';
|
|
9
|
+
fields: Record<string, MalloyInterfaceFieldType>;
|
|
10
|
+
} | {
|
|
11
|
+
name: string;
|
|
12
|
+
type: 'union';
|
|
13
|
+
options: Record<string, string>;
|
|
14
|
+
} | {
|
|
15
|
+
name: string;
|
|
16
|
+
type: 'enum';
|
|
17
|
+
values: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare const MALLOY_INTERFACE_TYPES: Record<string, MalloyInterfaceType>;
|
|
1
20
|
export type Aggregate = {
|
|
2
21
|
name?: string;
|
|
3
22
|
field: Field;
|
|
@@ -499,3 +518,4 @@ export type ViewSegment = {
|
|
|
499
518
|
export type Where = {
|
|
500
519
|
filter: Filter;
|
|
501
520
|
};
|
|
521
|
+
export {};
|