@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/package.json +2 -2
- package/reboot_native.cc +498 -667
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/zod-to-proto.js +47 -36
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const REBOOT_VERSION = "0.
|
|
1
|
+
export declare const REBOOT_VERSION = "0.44.0";
|
package/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const REBOOT_VERSION = "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
|
-
|
|
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
|
|
266
|
-
if (
|
|
267
|
-
console.error(chalk.stderr.bold.red(`Array at '${path}' has _optional_
|
|
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 (
|
|
271
|
-
console.error(chalk.stderr.bold.red(`Array at '${path}' has _default_
|
|
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 (
|
|
288
|
+
if (item._zod.def.type === "string") {
|
|
278
289
|
return "string";
|
|
279
290
|
}
|
|
280
|
-
else if (
|
|
291
|
+
else if (item instanceof z.ZodNumber) {
|
|
281
292
|
return "double";
|
|
282
293
|
}
|
|
283
|
-
else if (
|
|
294
|
+
else if (item instanceof z.ZodBigInt) {
|
|
284
295
|
return "int64";
|
|
285
296
|
}
|
|
286
|
-
else if (
|
|
297
|
+
else if (item instanceof z.ZodBoolean) {
|
|
287
298
|
return "bool";
|
|
288
299
|
}
|
|
289
|
-
else if (
|
|
290
|
-
return "
|
|
300
|
+
else if (item instanceof z.ZodObject) {
|
|
301
|
+
return "Item";
|
|
291
302
|
}
|
|
292
|
-
else if (
|
|
293
|
-
return "
|
|
303
|
+
else if (item instanceof z.ZodRecord) {
|
|
304
|
+
return "Item";
|
|
294
305
|
}
|
|
295
|
-
else if (
|
|
296
|
-
return "
|
|
306
|
+
else if (item instanceof z.ZodArray) {
|
|
307
|
+
return "Item";
|
|
297
308
|
}
|
|
298
|
-
else if (
|
|
299
|
-
return "
|
|
309
|
+
else if (item instanceof z.ZodDiscriminatedUnion) {
|
|
310
|
+
return "Item";
|
|
300
311
|
}
|
|
301
|
-
else if (
|
|
302
|
-
const meta =
|
|
303
|
-
if (
|
|
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(
|
|
318
|
+
else if (iszjson(item)) {
|
|
308
319
|
return "google.protobuf.Value";
|
|
309
320
|
}
|
|
310
|
-
console.error(chalk.stderr.bold.red(`Array at '${path}' has
|
|
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 (
|
|
324
|
+
if (item instanceof z.ZodObject) {
|
|
314
325
|
generate(proto, {
|
|
315
|
-
schema:
|
|
316
|
-
path: `${path}.[
|
|
326
|
+
schema: item,
|
|
327
|
+
path: `${path}.[item]`,
|
|
317
328
|
name: typeName,
|
|
318
329
|
});
|
|
319
330
|
}
|
|
320
|
-
else if (
|
|
331
|
+
else if (item instanceof z.ZodRecord) {
|
|
321
332
|
proto.write(`message ${typeName} {`);
|
|
322
333
|
generate(proto, {
|
|
323
|
-
schema:
|
|
324
|
-
path: `${path}.[
|
|
334
|
+
schema: item,
|
|
335
|
+
path: `${path}.[item]`,
|
|
325
336
|
});
|
|
326
337
|
proto.write(`}`);
|
|
327
338
|
}
|
|
328
|
-
else if (
|
|
339
|
+
else if (item instanceof z.ZodArray) {
|
|
329
340
|
proto.write(`message ${typeName} {`);
|
|
330
341
|
generate(proto, {
|
|
331
|
-
schema:
|
|
332
|
-
path: `${path}.[
|
|
342
|
+
schema: item,
|
|
343
|
+
path: `${path}.[item]`,
|
|
333
344
|
});
|
|
334
345
|
proto.write(`}`);
|
|
335
346
|
}
|
|
336
|
-
else if (
|
|
347
|
+
else if (item instanceof z.ZodDiscriminatedUnion) {
|
|
337
348
|
generate(proto, {
|
|
338
|
-
schema:
|
|
339
|
-
path: `${path}.[
|
|
349
|
+
schema: item,
|
|
350
|
+
path: `${path}.[item]`,
|
|
340
351
|
name: typeName,
|
|
341
352
|
});
|
|
342
353
|
}
|
|
343
|
-
proto.write(`repeated ${typeName}
|
|
354
|
+
proto.write(`repeated ${typeName} items = 1;`);
|
|
344
355
|
}
|
|
345
356
|
else if (schema instanceof z.ZodDiscriminatedUnion) {
|
|
346
357
|
assert(name !== undefined);
|