@4players/odin-common
Version:
A collection of commonly used type definitions and utility functions across ODIN web projects
16 lines (15 loc) • 936 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessagePackRpcSchema = exports.JsonSchema = exports.ByteArraySchema = void 0;
const zod_1 = require("zod");
exports.ByteArraySchema = zod_1.z.custom((value) => value instanceof Uint8Array);
const LiteralSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.number(), zod_1.z.boolean(), zod_1.z.null()]);
exports.JsonSchema = zod_1.z.lazy(() => zod_1.z.union([LiteralSchema, zod_1.z.array(exports.JsonSchema), zod_1.z.record(exports.JsonSchema)]));
exports.MessagePackRpcSchema = zod_1.z.union([
// request with method call
zod_1.z.tuple([zod_1.z.literal(0), zod_1.z.number(), zod_1.z.string(), zod_1.z.unknown()]),
// response
zod_1.z.tuple([zod_1.z.literal(1), zod_1.z.number(), zod_1.z.nullable(zod_1.z.string()), zod_1.z.unknown()]),
// notification
zod_1.z.tuple([zod_1.z.literal(2), zod_1.z.string(), zod_1.z.unknown()]),
]);