| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925 |
- import * as core from "../core/index.js";
- import * as util from "../core/util.js";
- import * as parse from "./parse.js";
- export const ZodMiniType = /*@__PURE__*/ core.$constructor("ZodMiniType", (inst, def) => {
- if (!inst._zod)
- throw new Error("Uninitialized schema in ZodMiniType.");
- core.$ZodType.init(inst, def);
- inst.def = def;
- inst.type = def.type;
- inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
- inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
- inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
- inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params);
- inst.check = (...checks) => {
- return inst.clone({
- ...def,
- checks: [
- ...(def.checks ?? []),
- ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
- ],
- }, { parent: true });
- };
- inst.with = inst.check;
- inst.clone = (_def, params) => core.clone(inst, _def, params);
- inst.brand = () => inst;
- inst.register = ((reg, meta) => {
- reg.add(inst, meta);
- return inst;
- });
- inst.apply = (fn) => fn(inst);
- });
- export const ZodMiniString = /*@__PURE__*/ core.$constructor("ZodMiniString", (inst, def) => {
- core.$ZodString.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function string(params) {
- return core._string(ZodMiniString, params);
- }
- export const ZodMiniStringFormat = /*@__PURE__*/ core.$constructor("ZodMiniStringFormat", (inst, def) => {
- core.$ZodStringFormat.init(inst, def);
- ZodMiniString.init(inst, def);
- });
- export const ZodMiniEmail = /*@__PURE__*/ core.$constructor("ZodMiniEmail", (inst, def) => {
- core.$ZodEmail.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function email(params) {
- return core._email(ZodMiniEmail, params);
- }
- export const ZodMiniGUID = /*@__PURE__*/ core.$constructor("ZodMiniGUID", (inst, def) => {
- core.$ZodGUID.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function guid(params) {
- return core._guid(ZodMiniGUID, params);
- }
- export const ZodMiniUUID = /*@__PURE__*/ core.$constructor("ZodMiniUUID", (inst, def) => {
- core.$ZodUUID.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function uuid(params) {
- return core._uuid(ZodMiniUUID, params);
- }
- // @__NO_SIDE_EFFECTS__
- export function uuidv4(params) {
- return core._uuidv4(ZodMiniUUID, params);
- }
- // ZodMiniUUIDv6
- // @__NO_SIDE_EFFECTS__
- export function uuidv6(params) {
- return core._uuidv6(ZodMiniUUID, params);
- }
- // ZodMiniUUIDv7
- // @__NO_SIDE_EFFECTS__
- export function uuidv7(params) {
- return core._uuidv7(ZodMiniUUID, params);
- }
- export const ZodMiniURL = /*@__PURE__*/ core.$constructor("ZodMiniURL", (inst, def) => {
- core.$ZodURL.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function url(params) {
- return core._url(ZodMiniURL, params);
- }
- // @__NO_SIDE_EFFECTS__
- export function httpUrl(params) {
- return core._url(ZodMiniURL, {
- protocol: /^https?$/,
- hostname: core.regexes.domain,
- ...util.normalizeParams(params),
- });
- }
- export const ZodMiniEmoji = /*@__PURE__*/ core.$constructor("ZodMiniEmoji", (inst, def) => {
- core.$ZodEmoji.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function emoji(params) {
- return core._emoji(ZodMiniEmoji, params);
- }
- export const ZodMiniNanoID = /*@__PURE__*/ core.$constructor("ZodMiniNanoID", (inst, def) => {
- core.$ZodNanoID.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function nanoid(params) {
- return core._nanoid(ZodMiniNanoID, params);
- }
- export const ZodMiniCUID = /*@__PURE__*/ core.$constructor("ZodMiniCUID", (inst, def) => {
- core.$ZodCUID.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function cuid(params) {
- return core._cuid(ZodMiniCUID, params);
- }
- export const ZodMiniCUID2 = /*@__PURE__*/ core.$constructor("ZodMiniCUID2", (inst, def) => {
- core.$ZodCUID2.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function cuid2(params) {
- return core._cuid2(ZodMiniCUID2, params);
- }
- export const ZodMiniULID = /*@__PURE__*/ core.$constructor("ZodMiniULID", (inst, def) => {
- core.$ZodULID.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function ulid(params) {
- return core._ulid(ZodMiniULID, params);
- }
- export const ZodMiniXID = /*@__PURE__*/ core.$constructor("ZodMiniXID", (inst, def) => {
- core.$ZodXID.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function xid(params) {
- return core._xid(ZodMiniXID, params);
- }
- export const ZodMiniKSUID = /*@__PURE__*/ core.$constructor("ZodMiniKSUID", (inst, def) => {
- core.$ZodKSUID.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function ksuid(params) {
- return core._ksuid(ZodMiniKSUID, params);
- }
- export const ZodMiniIPv4 = /*@__PURE__*/ core.$constructor("ZodMiniIPv4", (inst, def) => {
- core.$ZodIPv4.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function ipv4(params) {
- return core._ipv4(ZodMiniIPv4, params);
- }
- export const ZodMiniIPv6 = /*@__PURE__*/ core.$constructor("ZodMiniIPv6", (inst, def) => {
- core.$ZodIPv6.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function ipv6(params) {
- return core._ipv6(ZodMiniIPv6, params);
- }
- export const ZodMiniCIDRv4 = /*@__PURE__*/ core.$constructor("ZodMiniCIDRv4", (inst, def) => {
- core.$ZodCIDRv4.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function cidrv4(params) {
- return core._cidrv4(ZodMiniCIDRv4, params);
- }
- export const ZodMiniCIDRv6 = /*@__PURE__*/ core.$constructor("ZodMiniCIDRv6", (inst, def) => {
- core.$ZodCIDRv6.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function cidrv6(params) {
- return core._cidrv6(ZodMiniCIDRv6, params);
- }
- export const ZodMiniMAC = /*@__PURE__*/ core.$constructor("ZodMiniMAC", (inst, def) => {
- core.$ZodMAC.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function mac(params) {
- return core._mac(ZodMiniMAC, params);
- }
- export const ZodMiniBase64 = /*@__PURE__*/ core.$constructor("ZodMiniBase64", (inst, def) => {
- core.$ZodBase64.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function base64(params) {
- return core._base64(ZodMiniBase64, params);
- }
- export const ZodMiniBase64URL = /*@__PURE__*/ core.$constructor("ZodMiniBase64URL", (inst, def) => {
- core.$ZodBase64URL.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function base64url(params) {
- return core._base64url(ZodMiniBase64URL, params);
- }
- export const ZodMiniE164 = /*@__PURE__*/ core.$constructor("ZodMiniE164", (inst, def) => {
- core.$ZodE164.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function e164(params) {
- return core._e164(ZodMiniE164, params);
- }
- export const ZodMiniJWT = /*@__PURE__*/ core.$constructor("ZodMiniJWT", (inst, def) => {
- core.$ZodJWT.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function jwt(params) {
- return core._jwt(ZodMiniJWT, params);
- }
- export const ZodMiniCustomStringFormat = /*@__PURE__*/ core.$constructor("ZodMiniCustomStringFormat", (inst, def) => {
- core.$ZodCustomStringFormat.init(inst, def);
- ZodMiniStringFormat.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function stringFormat(format, fnOrRegex, _params = {}) {
- return core._stringFormat(ZodMiniCustomStringFormat, format, fnOrRegex, _params);
- }
- // @__NO_SIDE_EFFECTS__
- export function hostname(_params) {
- return core._stringFormat(ZodMiniCustomStringFormat, "hostname", core.regexes.hostname, _params);
- }
- // @__NO_SIDE_EFFECTS__
- export function hex(_params) {
- return core._stringFormat(ZodMiniCustomStringFormat, "hex", core.regexes.hex, _params);
- }
- // @__NO_SIDE_EFFECTS__
- export function hash(alg, params) {
- const enc = params?.enc ?? "hex";
- const format = `${alg}_${enc}`;
- const regex = core.regexes[format];
- // check for unrecognized format
- if (!regex)
- throw new Error(`Unrecognized hash format: ${format}`);
- return core._stringFormat(ZodMiniCustomStringFormat, format, regex, params);
- }
- export const ZodMiniNumber = /*@__PURE__*/ core.$constructor("ZodMiniNumber", (inst, def) => {
- core.$ZodNumber.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function number(params) {
- return core._number(ZodMiniNumber, params);
- }
- export const ZodMiniNumberFormat = /*@__PURE__*/ core.$constructor("ZodMiniNumberFormat", (inst, def) => {
- core.$ZodNumberFormat.init(inst, def);
- ZodMiniNumber.init(inst, def);
- });
- // int
- // @__NO_SIDE_EFFECTS__
- export function int(params) {
- return core._int(ZodMiniNumberFormat, params);
- }
- // float32
- // @__NO_SIDE_EFFECTS__
- export function float32(params) {
- return core._float32(ZodMiniNumberFormat, params);
- }
- // float64
- // @__NO_SIDE_EFFECTS__
- export function float64(params) {
- return core._float64(ZodMiniNumberFormat, params);
- }
- // int32
- // @__NO_SIDE_EFFECTS__
- export function int32(params) {
- return core._int32(ZodMiniNumberFormat, params);
- }
- // uint32
- // @__NO_SIDE_EFFECTS__
- export function uint32(params) {
- return core._uint32(ZodMiniNumberFormat, params);
- }
- export const ZodMiniBoolean = /*@__PURE__*/ core.$constructor("ZodMiniBoolean", (inst, def) => {
- core.$ZodBoolean.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function boolean(params) {
- return core._boolean(ZodMiniBoolean, params);
- }
- export const ZodMiniBigInt = /*@__PURE__*/ core.$constructor("ZodMiniBigInt", (inst, def) => {
- core.$ZodBigInt.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function bigint(params) {
- return core._bigint(ZodMiniBigInt, params);
- }
- export const ZodMiniBigIntFormat = /*@__PURE__*/ core.$constructor("ZodMiniBigIntFormat", (inst, def) => {
- core.$ZodBigIntFormat.init(inst, def);
- ZodMiniBigInt.init(inst, def);
- });
- // int64
- // @__NO_SIDE_EFFECTS__
- export function int64(params) {
- return core._int64(ZodMiniBigIntFormat, params);
- }
- // uint64
- // @__NO_SIDE_EFFECTS__
- export function uint64(params) {
- return core._uint64(ZodMiniBigIntFormat, params);
- }
- export const ZodMiniSymbol = /*@__PURE__*/ core.$constructor("ZodMiniSymbol", (inst, def) => {
- core.$ZodSymbol.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function symbol(params) {
- return core._symbol(ZodMiniSymbol, params);
- }
- export const ZodMiniUndefined = /*@__PURE__*/ core.$constructor("ZodMiniUndefined", (inst, def) => {
- core.$ZodUndefined.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- function _undefined(params) {
- return core._undefined(ZodMiniUndefined, params);
- }
- export { _undefined as undefined };
- export const ZodMiniNull = /*@__PURE__*/ core.$constructor("ZodMiniNull", (inst, def) => {
- core.$ZodNull.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- function _null(params) {
- return core._null(ZodMiniNull, params);
- }
- export { _null as null };
- export const ZodMiniAny = /*@__PURE__*/ core.$constructor("ZodMiniAny", (inst, def) => {
- core.$ZodAny.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function any() {
- return core._any(ZodMiniAny);
- }
- export const ZodMiniUnknown = /*@__PURE__*/ core.$constructor("ZodMiniUnknown", (inst, def) => {
- core.$ZodUnknown.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function unknown() {
- return core._unknown(ZodMiniUnknown);
- }
- export const ZodMiniNever = /*@__PURE__*/ core.$constructor("ZodMiniNever", (inst, def) => {
- core.$ZodNever.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function never(params) {
- return core._never(ZodMiniNever, params);
- }
- export const ZodMiniVoid = /*@__PURE__*/ core.$constructor("ZodMiniVoid", (inst, def) => {
- core.$ZodVoid.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- function _void(params) {
- return core._void(ZodMiniVoid, params);
- }
- export { _void as void };
- export const ZodMiniDate = /*@__PURE__*/ core.$constructor("ZodMiniDate", (inst, def) => {
- core.$ZodDate.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function date(params) {
- return core._date(ZodMiniDate, params);
- }
- export const ZodMiniArray = /*@__PURE__*/ core.$constructor("ZodMiniArray", (inst, def) => {
- core.$ZodArray.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function array(element, params) {
- return new ZodMiniArray({
- type: "array",
- element: element,
- ...util.normalizeParams(params),
- });
- }
- // .keyof
- // @__NO_SIDE_EFFECTS__
- export function keyof(schema) {
- const shape = schema._zod.def.shape;
- return _enum(Object.keys(shape));
- }
- export const ZodMiniObject = /*@__PURE__*/ core.$constructor("ZodMiniObject", (inst, def) => {
- core.$ZodObject.init(inst, def);
- ZodMiniType.init(inst, def);
- util.defineLazy(inst, "shape", () => def.shape);
- });
- // @__NO_SIDE_EFFECTS__
- export function object(shape, params) {
- const def = {
- type: "object",
- shape: shape ?? {},
- ...util.normalizeParams(params),
- };
- return new ZodMiniObject(def);
- }
- // strictObject
- // @__NO_SIDE_EFFECTS__
- export function strictObject(shape, params) {
- return new ZodMiniObject({
- type: "object",
- shape,
- catchall: never(),
- ...util.normalizeParams(params),
- });
- }
- // looseObject
- // @__NO_SIDE_EFFECTS__
- export function looseObject(shape, params) {
- return new ZodMiniObject({
- type: "object",
- shape,
- catchall: unknown(),
- ...util.normalizeParams(params),
- });
- }
- // object methods
- // @__NO_SIDE_EFFECTS__
- export function extend(schema, shape) {
- return util.extend(schema, shape);
- }
- // @__NO_SIDE_EFFECTS__
- export function safeExtend(schema, shape) {
- return util.safeExtend(schema, shape);
- }
- // @__NO_SIDE_EFFECTS__
- export function merge(schema, shape) {
- return util.extend(schema, shape);
- }
- // @__NO_SIDE_EFFECTS__
- export function pick(schema, mask) {
- return util.pick(schema, mask);
- }
- // .omit
- // @__NO_SIDE_EFFECTS__
- export function omit(schema, mask) {
- return util.omit(schema, mask);
- }
- // @__NO_SIDE_EFFECTS__
- export function partial(schema, mask) {
- return util.partial(ZodMiniOptional, schema, mask);
- }
- // @__NO_SIDE_EFFECTS__
- export function required(schema, mask) {
- return util.required(ZodMiniNonOptional, schema, mask);
- }
- // @__NO_SIDE_EFFECTS__
- export function catchall(inst, catchall) {
- return inst.clone({ ...inst._zod.def, catchall: catchall });
- }
- export const ZodMiniUnion = /*@__PURE__*/ core.$constructor("ZodMiniUnion", (inst, def) => {
- core.$ZodUnion.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function union(options, params) {
- return new ZodMiniUnion({
- type: "union",
- options: options,
- ...util.normalizeParams(params),
- });
- }
- export const ZodMiniXor = /*@__PURE__*/ core.$constructor("ZodMiniXor", (inst, def) => {
- ZodMiniUnion.init(inst, def);
- core.$ZodXor.init(inst, def);
- });
- /** Creates an exclusive union (XOR) where exactly one option must match.
- * Unlike regular unions that succeed when any option matches, xor fails if
- * zero or more than one option matches the input. */
- export function xor(options, params) {
- return new ZodMiniXor({
- type: "union",
- options: options,
- inclusive: false,
- ...util.normalizeParams(params),
- });
- }
- export const ZodMiniDiscriminatedUnion = /*@__PURE__*/ core.$constructor("ZodMiniDiscriminatedUnion", (inst, def) => {
- core.$ZodDiscriminatedUnion.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function discriminatedUnion(discriminator, options, params) {
- return new ZodMiniDiscriminatedUnion({
- type: "union",
- options,
- discriminator,
- ...util.normalizeParams(params),
- });
- }
- export const ZodMiniIntersection = /*@__PURE__*/ core.$constructor("ZodMiniIntersection", (inst, def) => {
- core.$ZodIntersection.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function intersection(left, right) {
- return new ZodMiniIntersection({
- type: "intersection",
- left: left,
- right: right,
- });
- }
- export const ZodMiniTuple = /*@__PURE__*/ core.$constructor("ZodMiniTuple", (inst, def) => {
- core.$ZodTuple.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function tuple(items, _paramsOrRest, _params) {
- const hasRest = _paramsOrRest instanceof core.$ZodType;
- const params = hasRest ? _params : _paramsOrRest;
- const rest = hasRest ? _paramsOrRest : null;
- return new ZodMiniTuple({
- type: "tuple",
- items: items,
- rest,
- ...util.normalizeParams(params),
- });
- }
- export const ZodMiniRecord = /*@__PURE__*/ core.$constructor("ZodMiniRecord", (inst, def) => {
- core.$ZodRecord.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function record(keyType, valueType, params) {
- return new ZodMiniRecord({
- type: "record",
- keyType,
- valueType: valueType,
- ...util.normalizeParams(params),
- });
- }
- // @__NO_SIDE_EFFECTS__
- export function partialRecord(keyType, valueType, params) {
- const k = core.clone(keyType);
- k._zod.values = undefined;
- return new ZodMiniRecord({
- type: "record",
- keyType: k,
- valueType: valueType,
- ...util.normalizeParams(params),
- });
- }
- export function looseRecord(keyType, valueType, params) {
- return new ZodMiniRecord({
- type: "record",
- keyType,
- valueType: valueType,
- mode: "loose",
- ...util.normalizeParams(params),
- });
- }
- export const ZodMiniMap = /*@__PURE__*/ core.$constructor("ZodMiniMap", (inst, def) => {
- core.$ZodMap.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function map(keyType, valueType, params) {
- return new ZodMiniMap({
- type: "map",
- keyType: keyType,
- valueType: valueType,
- ...util.normalizeParams(params),
- });
- }
- export const ZodMiniSet = /*@__PURE__*/ core.$constructor("ZodMiniSet", (inst, def) => {
- core.$ZodSet.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function set(valueType, params) {
- return new ZodMiniSet({
- type: "set",
- valueType: valueType,
- ...util.normalizeParams(params),
- });
- }
- export const ZodMiniEnum = /*@__PURE__*/ core.$constructor("ZodMiniEnum", (inst, def) => {
- core.$ZodEnum.init(inst, def);
- ZodMiniType.init(inst, def);
- inst.options = Object.values(def.entries);
- });
- // @__NO_SIDE_EFFECTS__
- function _enum(values, params) {
- const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
- return new ZodMiniEnum({
- type: "enum",
- entries,
- ...util.normalizeParams(params),
- });
- }
- export { _enum as enum };
- // @__NO_SIDE_EFFECTS__
- /** @deprecated This API has been merged into `z.enum()`. Use `z.enum()` instead.
- *
- * ```ts
- * enum Colors { red, green, blue }
- * z.enum(Colors);
- * ```
- */
- export function nativeEnum(entries, params) {
- return new ZodMiniEnum({
- type: "enum",
- entries,
- ...util.normalizeParams(params),
- });
- }
- export const ZodMiniLiteral = /*@__PURE__*/ core.$constructor("ZodMiniLiteral", (inst, def) => {
- core.$ZodLiteral.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function literal(value, params) {
- return new ZodMiniLiteral({
- type: "literal",
- values: Array.isArray(value) ? value : [value],
- ...util.normalizeParams(params),
- });
- }
- export const ZodMiniFile = /*@__PURE__*/ core.$constructor("ZodMiniFile", (inst, def) => {
- core.$ZodFile.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function file(params) {
- return core._file(ZodMiniFile, params);
- }
- export const ZodMiniTransform = /*@__PURE__*/ core.$constructor("ZodMiniTransform", (inst, def) => {
- core.$ZodTransform.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function transform(fn) {
- return new ZodMiniTransform({
- type: "transform",
- transform: fn,
- });
- }
- export const ZodMiniOptional = /*@__PURE__*/ core.$constructor("ZodMiniOptional", (inst, def) => {
- core.$ZodOptional.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function optional(innerType) {
- return new ZodMiniOptional({
- type: "optional",
- innerType: innerType,
- });
- }
- export const ZodMiniExactOptional = /*@__PURE__*/ core.$constructor("ZodMiniExactOptional", (inst, def) => {
- core.$ZodExactOptional.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function exactOptional(innerType) {
- return new ZodMiniExactOptional({
- type: "optional",
- innerType: innerType,
- });
- }
- export const ZodMiniNullable = /*@__PURE__*/ core.$constructor("ZodMiniNullable", (inst, def) => {
- core.$ZodNullable.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function nullable(innerType) {
- return new ZodMiniNullable({
- type: "nullable",
- innerType: innerType,
- });
- }
- // nullish
- // @__NO_SIDE_EFFECTS__
- export function nullish(innerType) {
- return optional(nullable(innerType));
- }
- export const ZodMiniDefault = /*@__PURE__*/ core.$constructor("ZodMiniDefault", (inst, def) => {
- core.$ZodDefault.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function _default(innerType, defaultValue) {
- return new ZodMiniDefault({
- type: "default",
- innerType: innerType,
- get defaultValue() {
- return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
- },
- });
- }
- export const ZodMiniPrefault = /*@__PURE__*/ core.$constructor("ZodMiniPrefault", (inst, def) => {
- core.$ZodPrefault.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function prefault(innerType, defaultValue) {
- return new ZodMiniPrefault({
- type: "prefault",
- innerType: innerType,
- get defaultValue() {
- return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
- },
- });
- }
- export const ZodMiniNonOptional = /*@__PURE__*/ core.$constructor("ZodMiniNonOptional", (inst, def) => {
- core.$ZodNonOptional.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function nonoptional(innerType, params) {
- return new ZodMiniNonOptional({
- type: "nonoptional",
- innerType: innerType,
- ...util.normalizeParams(params),
- });
- }
- export const ZodMiniSuccess = /*@__PURE__*/ core.$constructor("ZodMiniSuccess", (inst, def) => {
- core.$ZodSuccess.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function success(innerType) {
- return new ZodMiniSuccess({
- type: "success",
- innerType: innerType,
- });
- }
- export const ZodMiniCatch = /*@__PURE__*/ core.$constructor("ZodMiniCatch", (inst, def) => {
- core.$ZodCatch.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- function _catch(innerType, catchValue) {
- return new ZodMiniCatch({
- type: "catch",
- innerType: innerType,
- catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
- });
- }
- export { _catch as catch };
- export const ZodMiniNaN = /*@__PURE__*/ core.$constructor("ZodMiniNaN", (inst, def) => {
- core.$ZodNaN.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function nan(params) {
- return core._nan(ZodMiniNaN, params);
- }
- export const ZodMiniPipe = /*@__PURE__*/ core.$constructor("ZodMiniPipe", (inst, def) => {
- core.$ZodPipe.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function pipe(in_, out) {
- return new ZodMiniPipe({
- type: "pipe",
- in: in_,
- out: out,
- });
- }
- export const ZodMiniCodec = /*@__PURE__*/ core.$constructor("ZodMiniCodec", (inst, def) => {
- ZodMiniPipe.init(inst, def);
- core.$ZodCodec.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function codec(in_, out, params) {
- return new ZodMiniCodec({
- type: "pipe",
- in: in_,
- out: out,
- transform: params.decode,
- reverseTransform: params.encode,
- });
- }
- export const ZodMiniReadonly = /*@__PURE__*/ core.$constructor("ZodMiniReadonly", (inst, def) => {
- core.$ZodReadonly.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function readonly(innerType) {
- return new ZodMiniReadonly({
- type: "readonly",
- innerType: innerType,
- });
- }
- export const ZodMiniTemplateLiteral = /*@__PURE__*/ core.$constructor("ZodMiniTemplateLiteral", (inst, def) => {
- core.$ZodTemplateLiteral.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function templateLiteral(parts, params) {
- return new ZodMiniTemplateLiteral({
- type: "template_literal",
- parts,
- ...util.normalizeParams(params),
- });
- }
- export const ZodMiniLazy = /*@__PURE__*/ core.$constructor("ZodMiniLazy", (inst, def) => {
- core.$ZodLazy.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // export function lazy<T extends object>(getter: () => T): T {
- // return util.createTransparentProxy<T>(getter);
- // }
- // @__NO_SIDE_EFFECTS__
- function _lazy(getter) {
- return new ZodMiniLazy({
- type: "lazy",
- getter: getter,
- });
- }
- export { _lazy as lazy };
- export const ZodMiniPromise = /*@__PURE__*/ core.$constructor("ZodMiniPromise", (inst, def) => {
- core.$ZodPromise.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function promise(innerType) {
- return new ZodMiniPromise({
- type: "promise",
- innerType: innerType,
- });
- }
- export const ZodMiniCustom = /*@__PURE__*/ core.$constructor("ZodMiniCustom", (inst, def) => {
- core.$ZodCustom.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // custom checks
- // @__NO_SIDE_EFFECTS__
- export function check(fn, params) {
- const ch = new core.$ZodCheck({
- check: "custom",
- ...util.normalizeParams(params),
- });
- ch._zod.check = fn;
- return ch;
- }
- // ZodCustom
- // custom schema
- // @__NO_SIDE_EFFECTS__
- export function custom(fn, _params) {
- return core._custom(ZodMiniCustom, fn ?? (() => true), _params);
- }
- // refine
- // @__NO_SIDE_EFFECTS__
- export function refine(fn, _params = {}) {
- return core._refine(ZodMiniCustom, fn, _params);
- }
- // superRefine
- // @__NO_SIDE_EFFECTS__
- export function superRefine(fn) {
- return core._superRefine(fn);
- }
- // Re-export describe and meta from core
- export const describe = core.describe;
- export const meta = core.meta;
- // instanceof
- class Class {
- constructor(..._args) { }
- }
- // @__NO_SIDE_EFFECTS__
- function _instanceof(cls, params = {}) {
- const inst = custom((data) => data instanceof cls, params);
- inst._zod.bag.Class = cls;
- // Override check to emit invalid_type instead of custom
- inst._zod.check = (payload) => {
- if (!(payload.value instanceof cls)) {
- payload.issues.push({
- code: "invalid_type",
- expected: cls.name,
- input: payload.value,
- inst,
- path: [...(inst._zod.def.path ?? [])],
- });
- }
- };
- return inst;
- }
- export { _instanceof as instanceof };
- // stringbool
- export const stringbool = (...args) => core._stringbool({
- Codec: ZodMiniCodec,
- Boolean: ZodMiniBoolean,
- String: ZodMiniString,
- }, ...args);
- // @__NO_SIDE_EFFECTS__
- export function json() {
- const jsonSchema = _lazy(() => {
- return union([string(), number(), boolean(), _null(), array(jsonSchema), record(string(), jsonSchema)]);
- });
- return jsonSchema;
- }
- export const ZodMiniFunction = /*@__PURE__*/ core.$constructor("ZodMiniFunction", (inst, def) => {
- core.$ZodFunction.init(inst, def);
- ZodMiniType.init(inst, def);
- });
- // @__NO_SIDE_EFFECTS__
- export function _function(params) {
- return new ZodMiniFunction({
- type: "function",
- input: Array.isArray(params?.input) ? tuple(params?.input) : (params?.input ?? array(unknown())),
- output: params?.output ?? unknown(),
- });
- }
- export { _function as function };
|