@reboot-dev/reboot 0.42.0 → 0.44.0

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/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const REBOOT_VERSION = "0.42.0";
1
+ export declare const REBOOT_VERSION = "0.44.0";
package/version.js CHANGED
@@ -1 +1 @@
1
- export const REBOOT_VERSION = "0.42.0";
1
+ export const REBOOT_VERSION = "0.44.0";
package/zod-to-proto.js CHANGED
@@ -114,7 +114,18 @@ const generate = (proto, { schema, path, name, state = false, }) => {
114
114
  console.error(chalk.stderr.bold.red(`Unexpected literal '${literal}' for property '${key}'; only 'string' literals are currently supported`));
115
115
  process.exit(-1);
116
116
  }
117
- proto.write(`${literal} = ${i++};`);
117
+ // According to Protobuf `enum` rules:
118
+ // `enum` values use C++ scoping rules, meaning that
119
+ // `enum` values are siblings of their type, not
120
+ // children of it.
121
+ // That means we need to prefix the `enum` values
122
+ // with the `enum` type name to avoid name conflicts.
123
+ // It is safe here, since we preserve the original
124
+ // order of the literals and during the conversion
125
+ // from Pydantic model to Protobuf and back we
126
+ // operate with the indexes of the literals, not
127
+ // their names.
128
+ proto.write(`${typeName}_${literal} = ${i++};`);
118
129
  }
119
130
  proto.write(`}`);
120
131
  proto.write(`optional ${typeName} ${field} = ${tag};`);
@@ -262,85 +273,85 @@ const generate = (proto, { schema, path, name, state = false, }) => {
262
273
  proto.write(`map <string, ${typeName}> record = 1;`);
263
274
  }
264
275
  else if (schema instanceof z.ZodArray) {
265
- const element = schema.element;
266
- if (element instanceof z.ZodOptional) {
267
- console.error(chalk.stderr.bold.red(`Array at '${path}' has _optional_ element type which is not supported`));
276
+ const item = schema.element;
277
+ if (item instanceof z.ZodOptional) {
278
+ console.error(chalk.stderr.bold.red(`Array at '${path}' has _optional_ item type which is not supported`));
268
279
  process.exit(-1);
269
280
  }
270
- else if (element instanceof z.ZodDefault) {
271
- console.error(chalk.stderr.bold.red(`Array at '${path}' has _default_ element type which is not supported`));
281
+ else if (item instanceof z.ZodDefault) {
282
+ console.error(chalk.stderr.bold.red(`Array at '${path}' has _default_ item type which is not supported`));
272
283
  process.exit(-1);
273
284
  }
274
285
  const typeName = (() => {
275
286
  // To account for all possible "string" types in Zod, e.g.,
276
287
  // `z.uuid()`, `z.email()`, etc, we can't use `instanceof`.
277
- if (element._zod.def.type === "string") {
288
+ if (item._zod.def.type === "string") {
278
289
  return "string";
279
290
  }
280
- else if (element instanceof z.ZodNumber) {
291
+ else if (item instanceof z.ZodNumber) {
281
292
  return "double";
282
293
  }
283
- else if (element instanceof z.ZodBigInt) {
294
+ else if (item instanceof z.ZodBigInt) {
284
295
  return "int64";
285
296
  }
286
- else if (element instanceof z.ZodBoolean) {
297
+ else if (item instanceof z.ZodBoolean) {
287
298
  return "bool";
288
299
  }
289
- else if (element instanceof z.ZodObject) {
290
- return "Element";
300
+ else if (item instanceof z.ZodObject) {
301
+ return "Item";
291
302
  }
292
- else if (element instanceof z.ZodRecord) {
293
- return "Element";
303
+ else if (item instanceof z.ZodRecord) {
304
+ return "Item";
294
305
  }
295
- else if (element instanceof z.ZodArray) {
296
- return "Element";
306
+ else if (item instanceof z.ZodArray) {
307
+ return "Item";
297
308
  }
298
- else if (element instanceof z.ZodDiscriminatedUnion) {
299
- return "Element";
309
+ else if (item instanceof z.ZodDiscriminatedUnion) {
310
+ return "Item";
300
311
  }
301
- else if (element instanceof z.ZodCustom) {
302
- const meta = element.meta();
303
- if (element instanceof z.ZodCustom && "protobuf" in meta) {
312
+ else if (item instanceof z.ZodCustom) {
313
+ const meta = item.meta();
314
+ if (item instanceof z.ZodCustom && "protobuf" in meta) {
304
315
  return meta.protobuf;
305
316
  }
306
317
  }
307
- else if (iszjson(element)) {
318
+ else if (iszjson(item)) {
308
319
  return "google.protobuf.Value";
309
320
  }
310
- console.error(chalk.stderr.bold.red(`Array at '${path}' has element type '${element._zod.def.type}' which is not (yet) supported`));
321
+ console.error(chalk.stderr.bold.red(`Array at '${path}' has item type '${item._zod.def.type}' which is not (yet) supported`));
311
322
  process.exit(-1);
312
323
  })();
313
- if (element instanceof z.ZodObject) {
324
+ if (item instanceof z.ZodObject) {
314
325
  generate(proto, {
315
- schema: element,
316
- path: `${path}.[element]`,
326
+ schema: item,
327
+ path: `${path}.[item]`,
317
328
  name: typeName,
318
329
  });
319
330
  }
320
- else if (element instanceof z.ZodRecord) {
331
+ else if (item instanceof z.ZodRecord) {
321
332
  proto.write(`message ${typeName} {`);
322
333
  generate(proto, {
323
- schema: element,
324
- path: `${path}.[element]`,
334
+ schema: item,
335
+ path: `${path}.[item]`,
325
336
  });
326
337
  proto.write(`}`);
327
338
  }
328
- else if (element instanceof z.ZodArray) {
339
+ else if (item instanceof z.ZodArray) {
329
340
  proto.write(`message ${typeName} {`);
330
341
  generate(proto, {
331
- schema: element,
332
- path: `${path}.[element]`,
342
+ schema: item,
343
+ path: `${path}.[item]`,
333
344
  });
334
345
  proto.write(`}`);
335
346
  }
336
- else if (element instanceof z.ZodDiscriminatedUnion) {
347
+ else if (item instanceof z.ZodDiscriminatedUnion) {
337
348
  generate(proto, {
338
- schema: element,
339
- path: `${path}.[element]`,
349
+ schema: item,
350
+ path: `${path}.[item]`,
340
351
  name: typeName,
341
352
  });
342
353
  }
343
- proto.write(`repeated ${typeName} elements = 1;`);
354
+ proto.write(`repeated ${typeName} items = 1;`);
344
355
  }
345
356
  else if (schema instanceof z.ZodDiscriminatedUnion) {
346
357
  assert(name !== undefined);