@malloydata/malloy-interfaces 0.0.243-dev250314171809 → 0.0.243

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,7 +1,7 @@
1
1
  import type * as Malloy from './types';
2
2
  export * from './types';
3
3
  export { queryToMalloy } from './to_malloy';
4
- export { nestUnions } from './nest_unions';
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;
7
7
  export declare const thingy1: Malloy.Query;
package/dist/index.js CHANGED
@@ -20,12 +20,15 @@ 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.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.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
27
  var nest_unions_1 = require("./nest_unions");
28
28
  Object.defineProperty(exports, "nestUnions", { enumerable: true, get: function () { return nest_unions_1.nestUnions; } });
29
+ Object.defineProperty(exports, "unnestUnions", { enumerable: true, get: function () { return nest_unions_1.unnestUnions; } });
30
+ Object.defineProperty(exports, "convertFromThrift", { enumerable: true, get: function () { return nest_unions_1.convertFromThrift; } });
31
+ Object.defineProperty(exports, "convertToThrift", { enumerable: true, get: function () { return nest_unions_1.convertToThrift; } });
29
32
  exports.test = {
30
33
  entries: [
31
34
  {
@@ -9,10 +9,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.convertToThrift = exports.convertFromThrift = exports.unnestUnions = exports.nestUnions = void 0;
10
10
  const types_1 = require("./types");
11
11
  function nestUnions(obj) {
12
- if (obj === null) {
12
+ if (obj === null || obj === undefined) {
13
13
  return obj;
14
14
  }
15
- else if (typeof obj === 'string' || typeof obj === 'number') {
15
+ else if (typeof obj === 'string' ||
16
+ typeof obj === 'number' ||
17
+ typeof obj === 'boolean') {
16
18
  return obj;
17
19
  }
18
20
  else if (Array.isArray(obj)) {
@@ -42,7 +44,9 @@ function unnestUnions(obj, type) {
42
44
  if (obj === null || obj === undefined) {
43
45
  return obj;
44
46
  }
45
- else if (typeof obj === 'string' || typeof obj === 'number') {
47
+ else if (typeof obj === 'string' ||
48
+ typeof obj === 'number' ||
49
+ typeof obj === 'boolean') {
46
50
  return obj;
47
51
  }
48
52
  else if (Array.isArray(obj)) {
@@ -84,15 +88,21 @@ function convertFromThrift(obj, type) {
84
88
  if (obj === null || obj === undefined) {
85
89
  return obj;
86
90
  }
87
- else if (typeof obj === 'string') {
91
+ else if (typeof obj === 'string' || typeof obj === 'boolean') {
88
92
  return obj;
89
93
  }
90
94
  else if (typeof obj === 'number') {
91
- const typeDefinition = types_1.MALLOY_INTERFACE_TYPES[type];
92
- if (typeDefinition && typeDefinition.type === 'enum') {
93
- return typeDefinition.values[obj - 1];
95
+ if (type === 'number')
96
+ return obj;
97
+ const typeDefinition = getType(type);
98
+ if (typeDefinition.type !== 'enum') {
99
+ throw new Error(`Found a number where a ${type} was expected`);
94
100
  }
95
- return obj;
101
+ const entry = Object.entries(typeDefinition.values).find(([, value]) => value === obj);
102
+ if (entry === undefined) {
103
+ throw new Error(`${obj} is not a valid enum value for ${type}`);
104
+ }
105
+ return entry[0];
96
106
  }
97
107
  else if (Array.isArray(obj)) {
98
108
  return obj.map(value => convertFromThrift(value, type));
@@ -140,7 +150,7 @@ function convertToThrift(obj, type) {
140
150
  if (obj === null || obj === undefined) {
141
151
  return obj;
142
152
  }
143
- else if (typeof obj === 'number') {
153
+ else if (typeof obj === 'number' || typeof obj === 'boolean') {
144
154
  return obj;
145
155
  }
146
156
  else if (typeof obj === 'string') {
@@ -148,7 +158,11 @@ function convertToThrift(obj, type) {
148
158
  return obj;
149
159
  const typeDefinition = getType(type);
150
160
  if (typeDefinition.type === 'enum') {
151
- return typeDefinition.values.indexOf(obj) + 1;
161
+ const value = typeDefinition.values[obj];
162
+ if (value === undefined) {
163
+ throw new Error(`${obj} is not a valid enum value for ${type}`);
164
+ }
165
+ return value;
152
166
  }
153
167
  }
154
168
  else if (Array.isArray(obj)) {
package/dist/types.d.ts CHANGED
@@ -14,7 +14,7 @@ type MalloyInterfaceType = {
14
14
  } | {
15
15
  name: string;
16
16
  type: 'enum';
17
- values: string[];
17
+ values: Record<string, number>;
18
18
  };
19
19
  export declare const MALLOY_INTERFACE_TYPES: Record<string, MalloyInterfaceType>;
20
20
  export type Aggregate = {
package/dist/types.js CHANGED
@@ -366,7 +366,13 @@ exports.MALLOY_INTERFACE_TYPES = {
366
366
  'DateTimeframe': {
367
367
  'type': 'enum',
368
368
  'name': 'DateTimeframe',
369
- 'values': ['year', 'quarter', 'month', 'week', 'day'],
369
+ 'values': {
370
+ 'year': 1,
371
+ 'quarter': 2,
372
+ 'month': 3,
373
+ 'week': 4,
374
+ 'day': 5,
375
+ },
370
376
  },
371
377
  'DateType': {
372
378
  'type': 'struct',
@@ -653,7 +659,12 @@ exports.MALLOY_INTERFACE_TYPES = {
653
659
  'LogSeverity': {
654
660
  'type': 'enum',
655
661
  'name': 'LogSeverity',
656
- 'values': ['debug', 'info', 'warn', 'error'],
662
+ 'values': {
663
+ 'debug': 1,
664
+ 'info': 2,
665
+ 'warn': 3,
666
+ 'error': 4,
667
+ },
657
668
  },
658
669
  'MeasureInfo': {
659
670
  'type': 'struct',
@@ -756,7 +767,10 @@ exports.MALLOY_INTERFACE_TYPES = {
756
767
  'NumberSubtype': {
757
768
  'type': 'enum',
758
769
  'name': 'NumberSubtype',
759
- 'values': ['integer', 'decimal'],
770
+ 'values': {
771
+ 'integer': 1,
772
+ 'decimal': 2,
773
+ },
760
774
  },
761
775
  'NumberType': {
762
776
  'type': 'struct',
@@ -788,7 +802,10 @@ exports.MALLOY_INTERFACE_TYPES = {
788
802
  'OrderByDirection': {
789
803
  'type': 'enum',
790
804
  'name': 'OrderByDirection',
791
- 'values': ['asc', 'desc'],
805
+ 'values': {
806
+ 'asc': 1,
807
+ 'desc': 2,
808
+ },
792
809
  },
793
810
  'ParameterInfo': {
794
811
  'type': 'struct',
@@ -1006,7 +1023,11 @@ exports.MALLOY_INTERFACE_TYPES = {
1006
1023
  'Relationship': {
1007
1024
  'type': 'enum',
1008
1025
  'name': 'Relationship',
1009
- 'values': ['one', 'many', 'cross'],
1026
+ 'values': {
1027
+ 'one': 1,
1028
+ 'many': 2,
1029
+ 'cross': 3,
1030
+ },
1010
1031
  },
1011
1032
  'Result': {
1012
1033
  'type': 'struct',
@@ -1302,16 +1323,16 @@ exports.MALLOY_INTERFACE_TYPES = {
1302
1323
  'TimestampTimeframe': {
1303
1324
  'type': 'enum',
1304
1325
  'name': 'TimestampTimeframe',
1305
- 'values': [
1306
- 'year',
1307
- 'quarter',
1308
- 'month',
1309
- 'week',
1310
- 'day',
1311
- 'hour',
1312
- 'minute',
1313
- 'second',
1314
- ],
1326
+ 'values': {
1327
+ 'year': 1,
1328
+ 'quarter': 2,
1329
+ 'month': 3,
1330
+ 'week': 4,
1331
+ 'day': 5,
1332
+ 'hour': 6,
1333
+ 'minute': 7,
1334
+ 'second': 8,
1335
+ },
1315
1336
  },
1316
1337
  'TimestampType': {
1317
1338
  'type': 'struct',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy-interfaces",
3
- "version": "0.0.243-dev250314171809",
3
+ "version": "0.0.243",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,7 +28,7 @@ type MalloyInterfaceType =
28
28
  fields: Record<string, MalloyInterfaceFieldType>;
29
29
  }
30
30
  | {name: string; type: 'union'; options: Record<string, string>}
31
- | {name: string; type: 'enum'; values: string[]};
31
+ | {name: string; type: 'enum'; values: Record<string, number>};
32
32
 
33
33
  const types: Record<string, MalloyInterfaceType> = {};
34
34
 
@@ -46,10 +46,11 @@ for (const file of fs.readdirSync('./generated-types')) {
46
46
  );
47
47
  if (isAnEnum) {
48
48
  const name = isAnEnum[1];
49
- const values: string[] = [];
50
- const matches = actualTypes.matchAll(/ {4}([A-Z_]+) = \d+/g);
49
+ const values: Record<string, number> = {};
50
+ const matches = actualTypes.matchAll(/ {4}([A-Z_]+) = (\d+)/g);
51
51
  for (const match of matches) {
52
- values.push(match[1].toLowerCase());
52
+ const [name, valueString] = [match[1].toLowerCase(), match[2]];
53
+ values[name] = parseInt(valueString);
53
54
  }
54
55
  types[name] = {
55
56
  type: 'enum',
@@ -152,7 +153,7 @@ type MalloyInterfaceType =
152
153
  fields: Record<string, MalloyInterfaceFieldType>;
153
154
  }
154
155
  | {name: string; type: 'union'; options: Record<string, string>}
155
- | {name: string; type: 'enum'; values: string[]};
156
+ | {name: string; type: 'enum'; values: Record<string, number>};
156
157
  `);
157
158
 
158
159
  console.log(
@@ -172,7 +173,7 @@ for (const typeName in types) {
172
173
  const type = types[typeName];
173
174
  if (type.type === 'enum') {
174
175
  console.log(
175
- `export type ${type.name} = ${type.values
176
+ `export type ${type.name} = ${Object.keys(type.values)
176
177
  .map(v => `'${v}'`)
177
178
  .join(' | ')};\n`
178
179
  );