zod-schema-faker
Version:
Generates mock data from zod schema. Powered by @faker-js/faker and randexp.js
4 lines (3 loc) • 27.8 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("zod/v3"),I=require("@faker-js/faker"),K=require("randexp");class b extends Error{}const x=new Map,w=new Map,l=r=>{const e=r._def.typeName,s=w.get(r)??x.get(e);if(s===void 0)throw new b(`Unsupported schema type: ${e}.
- If this is a custom schema, you may not have installed a corresponding faker. If you need help with installation, please refer to the documentation for more information.
- If this is a built-in schema, it may not be implemented yet. Please file an issue to let us know: https://github.com/soc221b/zod-schema-faker/issues`);return new s(r).fake()};let _=I.fakerEN;function T(r){_=r}function o(){return _}const O=new I.SimpleFaker,z=(r,e)=>{const s=new K(r,e);return s.randInt=(t,a)=>O.number.int({min:t,max:a}),s.gen()},g=r=>{_.seed(r),O.seed(r)},E=T,j=r=>{const e=r(_);if(e instanceof Promise)throw new SyntaxError("InternalError: runFake cannot be used with async functions");return e};function L(r){if(typeof r!="object"||r===null||!("_parse"in r)||typeof r._parse!="function")throw new b(`Expected a zod schema, but got ${r}`)}function P(r,e){return r*e/N(r,e)}function N(r,e){return e===0n||e===0?r:N(e,r%e)}class f{constructor(e){this.schema=e,L(e)}}const D=(()=>{const r=[n.z.string(),n.z.number(),n.z.boolean(),n.z.null()],e=r.map(t=>n.z.array(t)),s=r.map(t=>n.z.object({foo:t}));return[...r,...e,...s]})();class A extends f{fake(){const e=o().helpers.arrayElement(D);return l(e)}}class R extends f{fake(){if(this.schema._def.exactLength!==null){if(this.schema._def.minLength!==null&&this.schema._def.minLength.value!==this.schema._def.exactLength.value)throw new RangeError;if(this.schema._def.maxLength!==null&&this.schema._def.maxLength.value!==this.schema._def.exactLength.value)throw new RangeError}const e=this.schema._def.exactLength?.value??this.schema._def.minLength?.value??0,s=this.schema._def.exactLength?.value??this.schema._def.maxLength?.value??o().number.int({min:e,max:e+2});if(e>s)throw new RangeError;return o().helpers.multiple(()=>l(this.schema._def.type),{count:{min:e,max:s}})}}class M extends f{fake(){let e,s,t=1n;for(const c of this.schema._def.checks)switch(c.kind){case"min":{const i=c.value+(c.inclusive?0n:1n);e=e!==void 0&&e>i?e:i;break}case"max":{const i=c.value-(c.inclusive?0n:1n);s=s!==void 0&&s<i?s:i;break}case"multipleOf":{const i=c.value<0n?-c.value:c.value;t=P(t,i);break}}const a=t*1000n;if(e!==void 0&&s!==void 0){if(e>s)throw new RangeError}else e!==void 0?s=e+a:s!==void 0?e=s-a:(e=-a,s=a);return o().number.bigInt({min:e,max:s,multipleOf:t})}}class B extends f{fake(){return o().datatype.boolean()}}class C extends f{fake(){return l(this.schema._def.type)}}class U extends f{fake(){throw Error()}}class V extends f{fake(){return o().datatype.boolean()?this.schema.parse(new U(n.z.never())):l(this.schema._def.innerType)}}const $=-864e13,W=864e13;class F extends f{fake(){let e,s;for(const t of this.schema._def.checks)switch(t.kind){case"min":{const a=t.value;e=e!==void 0?Math.max(e,a):a;break}case"max":{const a=t.value;s=s!==void 0?Math.min(s,a):a;break}}return e===void 0&&(o().datatype.boolean({probability:.2})?e=$:e=(s??new Date("2025-01-01T00:00:00.000Z").getTime())-31536e6),s===void 0&&(o().datatype.boolean({probability:.2})?s=W:s=e+31536e6),o().date.between({from:e,to:s})}}class q extends f{fake(){return o().datatype.boolean()?this.schema._def.defaultValue():l(this.schema._def.innerType)}}class G extends f{fake(){const e=o().helpers.arrayElement(this.schema.options);return l(e)}}class H extends f{fake(){let e;switch(this.schema._def.effect.type){case"preprocess":e=l(this.schema._def.schema);break;case"refinement":e=l(this.schema._def.schema);break;case"transform":e=this.schema._def.effect.transform(l(this.schema._def.schema),{addIssue:()=>{},path:[]});break;default:this.schema._def.effect}return e}}class J extends f{fake(){return o().helpers.arrayElement(this.schema._def.values)}}class X extends f{fake(){return(...e)=>l(this.schema._def.returns)}}class Y extends f{fake(){const e=this.findIntersectedSchema(this.schema._def.left,this.schema._def.right);if(e.success)return l(e.schema);throw new TypeError("ZodIntersectionFaker: unable to fake the given schema")}findIntersectedSchema=(e,s)=>{const t=[this.findIntersectedSchemaForUndefined,this.findIntersectedSchemaForOptional,this.findIntersectedSchemaForDefault,this.findIntersectedSchemaForCatch,this.findIntersectedSchemaForNull,this.findIntersectedSchemaForNullable,this.findIntersectedSchemaForIntersection,this.findIntersectedSchemaForLazy,this.findIntersectedSchemaForReadonly,this.findIntersectedSchemaForPipe,this.findIntersectedSchemaForBrand,this.findIntersectedSchemaForUnknown,this.findIntersectedSchemaForAny,this.findIntersectedSchemaForArray,this.findIntersectedSchemaForBigint,this.findIntersectedSchemaForBoolean,this.findIntersectedSchemaForDate,this.findIntersectedSchemaForDiscriminatedUnion,this.findIntersectedSchemaForDiscriminatedUnionAndObject,this.findIntersectedSchemaForDiscriminatedUnionAndRecord,this.findIntersectedSchemaForEnum,this.findIntersectedSchemaForLiteral,this.findIntersectedSchemaForNativeEnum,this.findIntersectedSchemaForNumber,this.findIntersectedSchemaForObject,this.findIntersectedSchemaForObjectAndRecord,this.findIntersectedSchemaForRecordWithKeyTypeString,this.findIntersectedSchemaForString,this.findIntersectedSchemaForSymbol,this.findIntersectedSchemaForTuple,this.findIntersectedSchemaForTupleAndArray,this.findIntersectedSchemaForUnion,this.findIntersectedSchemaForUnionAndNonUnion,this.findIntersectedSchemaForVoid];for(const a of t){const c=a(e,s);if(c.success)return c}return{success:!1}};findIntersectedSchemaForUndefined=(e,s)=>{if(s instanceof n.z.ZodUndefined){const t=this.findIntersectedSchema(n.z.never().optional(),e);if(t.success)return t}return e instanceof n.z.ZodUndefined?this.findIntersectedSchemaForUndefined(s,e):{success:!1}};findIntersectedSchemaForOptional=(e,s)=>{if(e instanceof n.z.ZodOptional&&s instanceof n.z.ZodOptional&&o().datatype.boolean({probability:.2}))return{success:!0,schema:n.z.undefined()};if(s instanceof n.z.ZodOptional){const t=this.findIntersectedSchema(e,s._def.innerType);if(t.success)return t}return e instanceof n.z.ZodOptional?this.findIntersectedSchemaForOptional(s,e):{success:!1}};findIntersectedSchemaForDefault=(e,s)=>s instanceof n.z.ZodDefault?{success:!0,schema:n.z.union([n.z.lazy(()=>n.z.literal(s._def.defaultValue())),n.z.intersection(e,s._def.innerType)])}:e instanceof n.z.ZodDefault?this.findIntersectedSchemaForDefault(s,e):{success:!1};findIntersectedSchemaForCatch=(e,s)=>s instanceof n.z.ZodCatch?{success:!0,schema:n.z.union([n.z.lazy(()=>n.z.literal(s._def.catchValue({error:new n.z.ZodError([]),input:void 0}))),n.z.intersection(e,s._def.innerType)])}:e instanceof n.z.ZodCatch?this.findIntersectedSchemaForCatch(s,e):{success:!1};findIntersectedSchemaForNull=(e,s)=>{if(s instanceof n.z.ZodNull){const t=this.findIntersectedSchema(e,n.z.never().nullable());if(t.success)return t}return e instanceof n.z.ZodNull?this.findIntersectedSchemaForNull(s,e):{success:!1}};findIntersectedSchemaForNullable=(e,s)=>{if(e instanceof n.z.ZodNullable&&s instanceof n.z.ZodNullable&&o().datatype.boolean({probability:.2}))return{success:!0,schema:n.z.null()};if(s instanceof n.z.ZodNullable){const t=this.findIntersectedSchema(e,s._def.innerType);if(t.success)return t}return e instanceof n.z.ZodNullable?this.findIntersectedSchemaForNullable(s,e):{success:!1}};findIntersectedSchemaForIntersection=(e,s)=>{if(s instanceof n.z.ZodIntersection){const t=this.findIntersectedSchema(s._def.left,s._def.right);if(t.success){const a=this.findIntersectedSchema(e,t.schema);if(a.success)return{success:!0,schema:a.schema}}return{success:!1}}return e instanceof n.z.ZodIntersection?this.findIntersectedSchemaForIntersection(s,e):{success:!1}};findIntersectedSchemaForLazy=(e,s)=>{if(s instanceof n.z.ZodLazy){const t=this.findIntersectedSchema(e,s._def.getter());return t.success?t:{success:!1}}return e instanceof n.z.ZodLazy?this.findIntersectedSchemaForLazy(s,e):{success:!1}};findIntersectedSchemaForReadonly=(e,s)=>{if(s instanceof n.z.ZodReadonly){const t=this.findIntersectedSchema(e,s._def.innerType);return t.success?t:{success:!1}}return e instanceof n.z.ZodReadonly?this.findIntersectedSchemaForReadonly(s,e):{success:!1}};findIntersectedSchemaForPipe=(e,s)=>{if(s instanceof n.z.ZodPipeline){const t=this.findIntersectedSchema(e,s._def.out);if(t.success)return t}return e instanceof n.z.ZodPipeline?this.findIntersectedSchemaForPipe(s,e):{success:!1}};findIntersectedSchemaForBrand=(e,s)=>{if(s instanceof n.z.ZodBranded){const t=this.findIntersectedSchema(e,s._def.type);if(t.success)return t}return e instanceof n.z.ZodBranded?this.findIntersectedSchemaForBrand(s,e):{success:!1}};findIntersectedSchemaForUnknown=(e,s)=>s instanceof n.z.ZodUnknown?{success:!0,schema:e}:e instanceof n.z.ZodUnknown?this.findIntersectedSchemaForUnknown(s,e):{success:!1};findIntersectedSchemaForAny=(e,s)=>s instanceof n.z.ZodAny?{success:!0,schema:e}:e instanceof n.z.ZodAny?this.findIntersectedSchemaForAny(s,e):{success:!1};findIntersectedSchemaForArray=(e,s)=>{if(!(e instanceof n.z.ZodArray)||!(s instanceof n.z.ZodArray))return{success:!1};const t=this.findIntersectedSchema(e._def.type,s._def.type);if(t.success===!1)return{success:!1};let a=e._def.minLength?.value??null;s._def.minLength!==null&&(a=Math.max(a??0,s._def.minLength.value));let c=e._def.maxLength?.value??null;s._def.maxLength!==null&&(c=Math.min(c??1/0,s._def.maxLength.value));let i=e._def.exactLength?.value??null;if(s._def.exactLength!==null){if(i!==null&&i!==s._def.exactLength.value)return{success:!1};i=s._def.exactLength.value}if(a!==null&&i!==null&&a>i)return{success:!1};if(c!==null&&i!==null&&c<i)return{success:!1};if(a!==null&&c!==null&&a>c)return{success:!1};let d=n.z.array(t.schema);return a!==null&&(d=d.min(a)),c!==null&&(d=d.max(c)),i!==null&&(d=d.length(i)),{success:!0,schema:d}};findIntersectedSchemaForBigint=(e,s)=>{if(!(e instanceof n.z.ZodBigInt)||!(s instanceof n.z.ZodBigInt))return{success:!1};let t=n.z.bigint();for(const a of e._def.checks)switch(a.kind){case"min":t=t.min(a.value);break;case"max":t=t.max(a.value);break;case"multipleOf":t=t.multipleOf(a.value);break}for(const a of s._def.checks)switch(a.kind){case"min":t=t.min(a.value);break;case"max":t=t.max(a.value);break;case"multipleOf":t=t.multipleOf(a.value);break}return{success:!0,schema:t}};findIntersectedSchemaForBoolean=(e,s)=>!(e instanceof n.z.ZodBoolean)||!(s instanceof n.z.ZodBoolean)?{success:!1}:{success:!0,schema:e};findIntersectedSchemaForDate=(e,s)=>{if(!(e instanceof n.z.ZodDate)||!(s instanceof n.z.ZodDate))return{success:!1};let t=n.z.date();for(const a of e._def.checks)switch(a.kind){case"min":t=t.min(new Date(a.value));break;case"max":t=t.max(new Date(a.value));break}for(const a of s._def.checks)switch(a.kind){case"min":t=t.min(new Date(a.value));break;case"max":t=t.max(new Date(a.value));break}return{success:!0,schema:t}};findIntersectedSchemaForDiscriminatedUnion=(e,s)=>{if(!(e instanceof n.z.ZodDiscriminatedUnion)||!(s instanceof n.z.ZodDiscriminatedUnion))return{success:!1};if(e._def.discriminator!==s._def.discriminator)return{success:!1};const t=e._def.options,a=s._def.options,c=[];for(const i of t){const d=i.shape[e._def.discriminator];if(d instanceof n.z.ZodLiteral)for(const p of a){const y=p.shape[s._def.discriminator];if(y instanceof n.z.ZodLiteral&&d._def.value===y._def.value){const Z=this.findIntersectedSchema(i,p);Z.success&&Z.schema instanceof n.z.ZodObject&&c.push(Z.schema)}}}return c.length===0?{success:!1}:{success:!0,schema:n.z.discriminatedUnion(e._def.discriminator,c)}};findIntersectedSchemaForDiscriminatedUnionAndObject=(e,s)=>{if(e instanceof n.z.ZodObject&&s instanceof n.z.ZodDiscriminatedUnion){const t=[];for(const a of s._def.options)e.shape[s._def.discriminator].safeParse(l(a.shape[s._def.discriminator])).success&&t.push(e.merge(n.z.object({[s._def.discriminator]:a.shape[s._def.discriminator]})));if(t.length){const a=n.z.discriminatedUnion(s._def.discriminator,t),c=this.findIntersectedSchema(a,s);if(c.success)return{success:!0,schema:c.schema}}}return e instanceof n.z.ZodDiscriminatedUnion&&s instanceof n.z.ZodObject?this.findIntersectedSchemaForDiscriminatedUnionAndObject(s,e):{success:!1}};findIntersectedSchemaForDiscriminatedUnionAndRecord=(e,s)=>{if(e instanceof n.z.ZodRecord&&s instanceof n.z.ZodDiscriminatedUnion){const t=[];for(const a of s._def.options){const c=this.findIntersectedSchema(e,a);c.success&&c.schema instanceof n.z.ZodObject&&t.push(c.schema)}if(t.length){const a=n.z.discriminatedUnion(s._def.discriminator,t),c=this.findIntersectedSchema(a,s);if(c.success)return{success:!0,schema:c.schema}}}return e instanceof n.z.ZodDiscriminatedUnion&&s instanceof n.z.ZodRecord?this.findIntersectedSchemaForDiscriminatedUnionAndRecord(s,e):{success:!1}};findIntersectedSchemaForEnum=(e,s)=>{if(s instanceof n.z.ZodEnum){const t=[];for(const a of s._def.values)e.safeParse(a).success&&t.push(a);return typeof t.at(0)=="string"?{success:!0,schema:n.z.enum(t)}:{success:!1}}return e instanceof n.z.ZodEnum?this.findIntersectedSchemaForEnum(s,e):{success:!1}};findIntersectedSchemaForLiteral=(e,s)=>s instanceof n.z.ZodLiteral?e.safeParse(s._def.value).success?{success:!0,schema:s}:{success:!1}:e instanceof n.z.ZodLiteral?this.findIntersectedSchemaForLiteral(s,e):{success:!1};findIntersectedSchemaForNativeEnum=(e,s)=>!(e instanceof n.z.ZodNativeEnum)||!(s instanceof n.z.ZodNativeEnum)||e.enum!==s.enum?{success:!1}:{success:!0,schema:e};findIntersectedSchemaForNumber=(e,s)=>{if(!(e instanceof n.z.ZodNumber)||!(s instanceof n.z.ZodNumber))return{success:!1};let t=n.z.number();for(const a of[...e._def.checks,...s._def.checks])switch(a.kind){case"min":t=t.min(a.value);break;case"max":t=t.max(a.value);break;case"int":t=t.int();break;case"finite":t=t.finite();break;case"multipleOf":t=t.multipleOf(a.value);break}return{success:!0,schema:t}};findIntersectedSchemaForObject=(e,s)=>{if(!(e instanceof n.z.ZodObject)||!(s instanceof n.z.ZodObject))return{success:!1};let t=n.z.object({});const a=e._def.unknownKeys,c=s._def.unknownKeys,i=a==="strict"||c==="strict"?"strict":a==="strip"||c==="strip"?"strip":"passthrough",d=e._def.catchall,p=s._def.catchall,y=d instanceof n.z.ZodNever&&c==="strict"||p instanceof n.z.ZodNever&&a==="strict"||a==="strict"||c==="strict"?n.z.never():d instanceof n.z.ZodNever?p:d,Z=new Set([...Object.keys(e.shape),...Object.keys(s.shape)]);for(const u of Z){const m=e.shape[u],h=s.shape[u];if(m===void 0)if(d instanceof n.z.ZodNever)switch(a){case"strict":break;default:t=t.merge(n.z.object({[u]:h}))}else{const k=this.findIntersectedSchema(e._def.catchall,h);if(k.success)t=t.merge(n.z.object({[u]:k.schema}));else return{success:!1}}else if(h===void 0)if(p instanceof n.z.ZodNever)switch(c){case"strict":break;default:t=t.merge(n.z.object({[u]:m}))}else{const k=this.findIntersectedSchema(m,s._def.catchall);if(k.success)t=t.merge(n.z.object({[u]:k.schema}));else return{success:!1}}else{const k=this.findIntersectedSchema(m,h);if(k.success)t=t.merge(n.z.object({[u]:k.schema}));else return{success:!1}}}if(y instanceof n.z.ZodNever)switch(i){case"strict":t=t.strict();break;case"strip":t=t.strip();break;case"passthrough":t=t.passthrough().catchall(y);break}else t=t.catchall(y);return{success:!0,schema:t}};findIntersectedSchemaForObjectAndRecord=(e,s)=>{if(e instanceof n.z.ZodRecord&&s instanceof n.z.ZodObject){const t={};for(const i in s.shape)t[i]=e._def.valueType;const a=n.z.object(t),c=this.findIntersectedSchema(a,s);if(c.success&&c.schema instanceof n.z.ZodObject)if(s._def.catchall instanceof n.z.ZodNever)switch(s._def.unknownKeys){case"strict":return{success:!0,schema:c.schema.strict()};case"strip":return{success:!0,schema:c.schema.strip()};case"passthrough":return{success:!0,schema:c.schema.catchall(e._def.valueType)}}else{const i=this.findIntersectedSchema(e._def.valueType,s._def.catchall);if(i.success)return{success:!0,schema:c.schema.catchall(i.schema)}}}return e instanceof n.z.ZodObject&&s instanceof n.z.ZodRecord?this.findIntersectedSchemaForObjectAndRecord(s,e):{success:!1}};findIntersectedSchemaForRecordWithKeyTypeString=(e,s)=>{if(!(e instanceof n.z.ZodRecord)||!(s instanceof n.z.ZodRecord))return{success:!1};if(!(e._def.keyType instanceof n.z.ZodString)||!(s._def.keyType instanceof n.z.ZodString))return{success:!1};const t=this.findIntersectedSchema(e._def.valueType,s._def.valueType);return t.success===!1?{success:!1}:{success:!0,schema:n.z.record(t.schema)}};findIntersectedSchemaForString=(e,s)=>{if(!(e instanceof n.z.ZodString)||!(s instanceof n.z.ZodString))return{success:!1};const t=["email","url","uuid","nanoid","cuid","cuid2","ulid","regex","jwt","datetime","date","time","duration","ip","cidr","base64","base64url"],a=e._def.checks.map(i=>i.kind).filter(i=>t.some(d=>i===d)),c=s._def.checks.map(i=>i.kind).filter(i=>t.some(d=>i===d));return a.length&&a.some(i=>c.length===0||c.includes(i))===!1?{success:!1}:{success:!0,schema:new n.ZodString({coerce:e._def.coerce||s._def.coerce,checks:[...e._def.checks,...s._def.checks],typeName:e._def.typeName})}};findIntersectedSchemaForSymbol=(e,s)=>!(e instanceof n.z.ZodSymbol)||!(s instanceof n.z.ZodSymbol)?{success:!1}:{success:!0,schema:e};findIntersectedSchemaForTuple=(e,s)=>{if(!(e instanceof n.z.ZodTuple)||!(s instanceof n.z.ZodTuple))return{success:!1};const t=[];let a;for(let i=0;i<Math.min(e._def.items.length,s._def.items.length);++i){const d=this.findIntersectedSchema(e._def.items[i],s._def.items[i]);d.success&&t.push(d.schema)}for(let i=e._def.items.length;i<s._def.items.length;++i){const d=this.findIntersectedSchema(e._def.rest,s._def.items[i]);d.success&&t.push(d.schema)}for(let i=s._def.items.length;i<e._def.items.length;++i){const d=this.findIntersectedSchema(e._def.items[i],s._def.rest);d.success&&t.push(d.schema)}if(e._def.rest!==void 0&&s._def.rest!==void 0){const i=this.findIntersectedSchema(e._def.rest,s._def.rest);i.success&&(a=i.schema)}let c=n.z.tuple(t);return a!==void 0&&(c=c.rest(a)),{success:!0,schema:c}};findIntersectedSchemaForTupleAndArray=(e,s)=>{if(e instanceof n.z.ZodArray&&s instanceof n.z.ZodTuple){const t=[];for(const d of s._def.items){const p=this.findIntersectedSchema(e._def.type,d);p.success&&t.push(p.schema)}let a;if(s._def.rest!==void 0){const d=this.findIntersectedSchema(e._def.type,s._def.rest);d.success&&(a=d.schema)}let c=n.z.tuple(t);if(a!==void 0&&(c=c.rest(a)),this.findIntersectedSchema(c,s).success)return{success:!0,schema:c}}return e instanceof n.z.ZodTuple&&s instanceof n.z.ZodArray?this.findIntersectedSchemaForTupleAndArray(s,e):{success:!1}};findIntersectedSchemaForUnion=(e,s)=>{if(!(e instanceof n.z.ZodUnion)||!(s instanceof n.z.ZodUnion))return{success:!1};let t;for(const a of e._def.options)for(const c of s._def.options){const i=this.findIntersectedSchema(a,c);i.success&&(t=t===void 0?i.schema:n.z.union([t,i.schema]))}return t===void 0?{success:!1}:{success:!0,schema:t}};findIntersectedSchemaForUnionAndNonUnion=(e,s)=>s instanceof n.z.ZodUnion&&!(e instanceof n.z.ZodUnion)?this.findIntersectedSchema(n.z.union([e,n.z.never()]),s):e instanceof n.z.ZodUnion&&!(s instanceof n.z.ZodUnion)?this.findIntersectedSchemaForUnionAndNonUnion(s,e):{success:!1};findIntersectedSchemaForVoid=(e,s)=>!(e instanceof n.z.ZodVoid)||!(s instanceof n.z.ZodVoid)?{success:!1}:{success:!0,schema:e}}class Q extends f{fake(){return l(this.schema._def.getter())}}class ee extends f{fake(){return this.schema._def.value}}class se extends f{fake(){return new Map(o().helpers.multiple(()=>[l(this.schema._def.keyType),l(this.schema._def.valueType)],{count:{min:1,max:10}}))}}class ne extends f{fake(){return NaN}}class te extends f{fake(){return o().helpers.enumValue(this.schema._def.values)}}class ae extends f{fake(){return null}}class ce extends f{fake(){return o().datatype.boolean()?null:l(this.schema._def.innerType)}}class re extends f{fake(){let e,s,t,a=!1,c=!1;for(const d of this.schema._def.checks)switch(d.kind){case"min":{const p=d.value+(d.inclusive?0:1e-15);e=e!==void 0?Math.max(e,p):p;break}case"max":{const p=d.value-(d.inclusive?0:1e-15);s=s!==void 0?Math.min(s,p):p;break}case"multipleOf":{const p=d.value;t=t!==void 0?P(t,p):p;break}case"int":a=!0;break;case"finite":c=!0;break}if(c===!1&&a===!1&&t===void 0){if(e===void 0&&o().datatype.boolean({probability:.2}))return-1/0;if(s===void 0&&o().datatype.boolean({probability:.2}))return 1/0}if(e??=Number.MIN_SAFE_INTEGER,s??=Number.MAX_SAFE_INTEGER,a=a||t!==void 0&&t%1===0,e>s)throw new RangeError;const i=a?"int":"float";return o().number[i]({min:e,max:s,multipleOf:t})}}class ie extends f{fake(){const e={},s=this.schema._def.catchall,t=this.schema._def.unknownKeys;if(s instanceof n.z.ZodNever)switch(t){case"passthrough":{Object.assign(e,Object.fromEntries(o().helpers.multiple(()=>[l(n.z.string().regex(/^extra_[a-z]{5}$/)),l(n.z.any())],{count:{min:0,max:5}})));break}}else Object.assign(e,Object.fromEntries(o().helpers.multiple(()=>[l(n.z.string().regex(/^extra_[a-z]{5}$/)),l(s)],{count:{min:0,max:5}})));const a=this.schema._def.shape(),c=Object.keys(a);for(const i of c){const d=l(a[i]);e[i]=d}return e}}class oe extends f{fake(){if(!o().datatype.boolean())return l(this.schema._def.innerType)}}class de extends f{fake(){return l(this.schema._def.out)}}class fe extends f{fake(){const e=l(this.schema._def.type);return o().datatype.boolean()?Promise.resolve(e):new Promise(s=>{setTimeout(()=>s(e))})}}class ue extends f{fake(){return Object.freeze(l(this.schema._def.innerType))}}class le extends f{fake(){if(!(this.schema._def.keyType instanceof n.z.ZodString))throw new b("Invalid record key type: In runtime JavaScript, all keys are strings.");return Object.fromEntries(o().helpers.multiple(()=>[l(this.schema._def.keyType),l(this.schema._def.valueType)],{count:{min:0,max:10}}))}}class me extends f{fake(){const e=this.schema._def.minSize?.value??0,s=this.schema._def.maxSize?.value??o().number.int({min:e,max:e+10});if(e>s)throw new RangeError;const t=new Set;for(;t.size<e;)t.add(l(this.schema._def.valueType));for(;t.size<s&&o().datatype.boolean();)t.add(l(this.schema._def.valueType));return t}}const S=5,he=S*15,pe=S*200,ye=/^c[^\s-]{8,}$/i,Ze=/^[0-9a-z]+$/,ke=["☘","⚜"],ze=["😳","😀","😁","🤣","😃","😆","😉","😊","😋","😎","😍","😘","🥰","😗","😈","👿"],Fe=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,be=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,v=n.z.date().min(new Date("0000-01-01T00:00:00.000Z")).max(new Date("9999-12-31T23:59:59.999Z"));class _e extends f{fake(){let e,s,t,a,c,i,d=!1,p=!1,y=!1,Z=!1;for(const m of this.schema._def.checks)switch(m.kind){case"base64":return z(Fe);case"base64url":return z(be);case"cidr":{let h="";switch(m.version){case"v4":h=o().internet.ipv4()+"/"+o().number.int({min:0,max:32});break;case"v6":h=o().internet.ipv6()+"/"+o().number.int({min:0,max:128});break;case void 0:h=o().datatype.boolean()?o().internet.ipv4()+"/"+o().number.int({min:0,max:32}):o().internet.ipv6()+"/"+o().number.int({min:0,max:128});break;default:m.version}return h}case"cuid":return z(ye);case"cuid2":return z(Ze);case"date":return new F(v).fake().toISOString().slice(0,10);case"datetime":return new F(v).fake().toISOString();case"duration":return["P",o().datatype.boolean()?o().number.int({min:0,max:10*2e3})+"Y":"",o().datatype.boolean()?o().number.int({min:0,max:120})+"M":"",o().datatype.boolean()?o().number.int({min:0,max:310})+"D":"","T",o().datatype.boolean()?o().number.int({min:0,max:240})+"H":"",o().datatype.boolean()?o().number.int({min:0,max:600})+"M":"",o().datatype.boolean()?o().number.int({min:0,max:600})+"S":""].join("").replace(/T$/,"").replace(/^P$/,"P"+o().number.int({min:0,max:100})+"W");case"email":return o().internet.email();case"emoji":{Z=!0;break}case"endsWith":a=m.value;break;case"includes":c=m.value;break;case"ip":{let h="";switch(m.version){case"v4":h=o().internet.ipv4();break;case"v6":h=o().internet.ipv6();break;case void 0:h=o().internet.ip();break;default:m.version}return h}case"jwt":return o().internet.jwt();case"length":{const h=m.value;if(t!==void 0&&t!==h)throw new RangeError;t=h;break}case"max":{const h=m.value;s=s===void 0?h:Math.min(s,h);break}case"min":{const h=m.value;e=e===void 0?h:Math.max(e,h);break}case"nanoid":return o().string.nanoid();case"regex":return z(m.regex);case"startsWith":i=m.value;break;case"time":return new F(v).fake().toISOString().slice(11,-5);case"toLowerCase":d=!0;break;case"toUpperCase":p=!0;break;case"trim":y=!0;break;case"ulid":return o().string.ulid();case"url":return o().internet.url();case"uuid":return o().string.uuid()}if(t!==void 0){if(e!==void 0){if(t<e)throw new RangeError;e=t}if(s!==void 0){if(s<t)throw new RangeError;s=t}}if(e!==void 0){if(s!==void 0&&e>s)throw new RangeError}else e=0;s===void 0&&(s=t??e+(o().datatype.boolean()?S:o().datatype.boolean()?he:pe));let u="";for(;Number.isFinite(e)&&u.length<e;)u+=o().lorem.word()+" ";for(;Number.isFinite(s)&&u.length<s;)u+=o().lorem.word()+" ";if(u=u.slice(0,s),y&&(u=u.replace(/\s$/,"a")),d?u=u.toLowerCase():u=u.replace(/./g,m=>o().datatype.boolean()?m.toUpperCase():m),p&&(u=u.toUpperCase()),c){const m=o().number.int({min:0,max:Math.max(0,u.length-c.length)});u=u.slice(0,m)+c+u.slice(m)}if(i&&(u=i+u.slice(i.length)),a&&(u=u.slice(-1*a.length)+a),Z){const m=u.length%2;u=Array((u.length-m)/2).fill(null).map(()=>o().helpers.arrayElement(ze)).join(""),m&&(u+=o().helpers.arrayElement(ke))}return u}}class ve extends f{fake(){return Symbol()}}class Se extends f{fake(){return[...this.schema._def.items.map(e=>l(e)),...this.schema._def.rest?[l(this.schema._def.rest)]:[]]}}class Ie extends f{fake(){}}class xe extends f{fake(){return l(o().helpers.arrayElement(this.schema._def.options))}}class we extends f{fake(){return l(n.z.any())}}class Te extends f{fake(){}}function Oe(){const r={[n.z.ZodFirstPartyTypeKind.ZodAny]:A,[n.z.ZodFirstPartyTypeKind.ZodArray]:R,[n.z.ZodFirstPartyTypeKind.ZodBigInt]:M,[n.z.ZodFirstPartyTypeKind.ZodBoolean]:B,[n.z.ZodFirstPartyTypeKind.ZodBranded]:C,[n.z.ZodFirstPartyTypeKind.ZodCatch]:V,[n.z.ZodFirstPartyTypeKind.ZodDate]:F,[n.z.ZodFirstPartyTypeKind.ZodDefault]:q,[n.z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion]:G,[n.z.ZodFirstPartyTypeKind.ZodEffects]:H,[n.z.ZodFirstPartyTypeKind.ZodEnum]:J,[n.z.ZodFirstPartyTypeKind.ZodFunction]:X,[n.z.ZodFirstPartyTypeKind.ZodIntersection]:Y,[n.z.ZodFirstPartyTypeKind.ZodLazy]:Q,[n.z.ZodFirstPartyTypeKind.ZodLiteral]:ee,[n.z.ZodFirstPartyTypeKind.ZodMap]:se,[n.z.ZodFirstPartyTypeKind.ZodNaN]:ne,[n.z.ZodFirstPartyTypeKind.ZodNativeEnum]:te,[n.z.ZodFirstPartyTypeKind.ZodNever]:U,[n.z.ZodFirstPartyTypeKind.ZodNull]:ae,[n.z.ZodFirstPartyTypeKind.ZodNullable]:ce,[n.z.ZodFirstPartyTypeKind.ZodNumber]:re,[n.z.ZodFirstPartyTypeKind.ZodObject]:ie,[n.z.ZodFirstPartyTypeKind.ZodOptional]:oe,[n.z.ZodFirstPartyTypeKind.ZodPipeline]:de,[n.z.ZodFirstPartyTypeKind.ZodPromise]:fe,[n.z.ZodFirstPartyTypeKind.ZodReadonly]:ue,[n.z.ZodFirstPartyTypeKind.ZodRecord]:le,[n.z.ZodFirstPartyTypeKind.ZodSet]:me,[n.z.ZodFirstPartyTypeKind.ZodString]:_e,[n.z.ZodFirstPartyTypeKind.ZodSymbol]:ve,[n.z.ZodFirstPartyTypeKind.ZodTuple]:Se,[n.z.ZodFirstPartyTypeKind.ZodUndefined]:Ie,[n.z.ZodFirstPartyTypeKind.ZodUnion]:xe,[n.z.ZodFirstPartyTypeKind.ZodUnknown]:we,[n.z.ZodFirstPartyTypeKind.ZodVoid]:Te};for(const e of Object.keys(r))x.set(e,r[e])}function Pe(r,e){w.set(r,e)}exports.ZodSchemaFakerError=b;exports.ZodTypeFaker=f;exports.fake=l;exports.getFaker=o;exports.install=Oe;exports.installCustom=Pe;exports.installFaker=E;exports.randexp=z;exports.runFake=j;exports.seed=g;exports.setFaker=T;