UNPKG

@zod/core

Version:

TypeScript-first schema declaration and validation library with static type inference

35 lines (34 loc) 930 B
export const $output = Symbol("ZodOutput"); export const $input = Symbol("ZodInput"); export class $ZodRegistry { constructor() { this._map = new WeakMap(); this._idmap = new Map(); } add(schema, ..._meta) { const meta = _meta[0]; this._map.set(schema, meta); if (meta && typeof meta === "object" && "id" in meta) { if (this._idmap.has(meta.id)) { throw new Error(`ID ${meta.id} already exists in the registry`); } this._idmap.set(meta.id, schema); } return this; } remove(schema) { this._map.delete(schema); return this; } get(schema) { return this._map.get(schema); } has(schema) { return this._map.has(schema); } } // registries export function registry() { return new $ZodRegistry(); } export const globalRegistry = /*@__PURE__*/ registry();