@4players/odin-common
Version:
A collection of commonly used type definitions and utility functions across ODIN web projects
13 lines (12 loc) • 611 B
JavaScript
import { z } from 'zod';
export const ByteArraySchema = z.custom((value) => value instanceof Uint8Array);
const LiteralSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
export const JsonSchema = z.lazy(() => z.union([LiteralSchema, z.array(JsonSchema), z.record(JsonSchema)]));
export const MessagePackRpcSchema = z.union([
// request with method call
z.tuple([z.literal(0), z.number(), z.string(), z.unknown()]),
// response
z.tuple([z.literal(1), z.number(), z.nullable(z.string()), z.unknown()]),
// notification
z.tuple([z.literal(2), z.string(), z.unknown()]),
]);