zod 3.12.0 → 3.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -5
- package/lib/ZodError.d.ts +0 -1
- package/lib/ZodError.js +0 -1
- package/lib/benchmarks/discriminatedUnion.d.ts +0 -1
- package/lib/benchmarks/discriminatedUnion.js +0 -1
- package/lib/benchmarks/index.d.ts +0 -1
- package/lib/benchmarks/index.js +0 -1
- package/lib/benchmarks/object.d.ts +0 -1
- package/lib/benchmarks/object.js +0 -1
- package/lib/benchmarks/string.d.ts +0 -1
- package/lib/benchmarks/string.js +0 -1
- package/lib/benchmarks/union.d.ts +0 -1
- package/lib/benchmarks/union.js +0 -1
- package/lib/external.d.ts +0 -1
- package/lib/external.js +0 -1
- package/lib/helpers/errorUtil.d.ts +0 -1
- package/lib/helpers/errorUtil.js +0 -1
- package/lib/helpers/parseUtil.d.ts +0 -1
- package/lib/helpers/parseUtil.js +0 -1
- package/lib/helpers/partialUtil.d.ts +0 -1
- package/lib/helpers/partialUtil.js +0 -1
- package/lib/helpers/typeAliases.d.ts +0 -1
- package/lib/helpers/typeAliases.js +0 -1
- package/lib/helpers/util.d.ts +0 -1
- package/lib/helpers/util.js +0 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.mjs +3416 -2
- package/lib/types.d.ts +18 -7
- package/lib/types.js +55 -6
- package/package.json +3 -2
- package/lib/ZodError.d.ts.map +0 -1
- package/lib/ZodError.js.map +0 -1
- package/lib/benchmarks/discriminatedUnion.d.ts.map +0 -1
- package/lib/benchmarks/discriminatedUnion.js.map +0 -1
- package/lib/benchmarks/index.d.ts.map +0 -1
- package/lib/benchmarks/index.js.map +0 -1
- package/lib/benchmarks/object.d.ts.map +0 -1
- package/lib/benchmarks/object.js.map +0 -1
- package/lib/benchmarks/string.d.ts.map +0 -1
- package/lib/benchmarks/string.js.map +0 -1
- package/lib/benchmarks/union.d.ts.map +0 -1
- package/lib/benchmarks/union.js.map +0 -1
- package/lib/external.d.ts.map +0 -1
- package/lib/external.js.map +0 -1
- package/lib/helpers/errorUtil.d.ts.map +0 -1
- package/lib/helpers/errorUtil.js.map +0 -1
- package/lib/helpers/parseUtil.d.ts.map +0 -1
- package/lib/helpers/parseUtil.js.map +0 -1
- package/lib/helpers/partialUtil.d.ts.map +0 -1
- package/lib/helpers/partialUtil.js.map +0 -1
- package/lib/helpers/typeAliases.d.ts.map +0 -1
- package/lib/helpers/typeAliases.js.map +0 -1
- package/lib/helpers/util.d.ts.map +0 -1
- package/lib/helpers/util.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/index.mjs.map +0 -1
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js.map +0 -1
package/lib/index.mjs
CHANGED
|
@@ -1,2 +1,3416 @@
|
|
|
1
|
-
var extendStatics=function(e,t){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)};function __extends(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}extendStatics(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var util,__assign=function(){return(__assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function __awaiter(e,s,i,u){return new(i=i||Promise)(function(r,t){function n(e){try{o(u.next(e))}catch(e){t(e)}}function a(e){try{o(u.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?r(e.value):((t=e.value)instanceof i?t:new i(function(e){e(t)})).then(n,a)}o((u=u.apply(e,s||[])).next())})}function __generator(r,n){var a,o,s,i={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},e={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(a)throw new TypeError("Generator is already executing.");for(;i;)try{if(a=1,o&&(s=2&t[0]?o.return:t[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,t[1])).done)return s;switch(o=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return i.label++,{value:t[1],done:!1};case 5:i.label++,o=t[1],t=[0];continue;case 7:t=i.ops.pop(),i.trys.pop();continue;default:if(!(s=0<(s=i.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){i=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){i.label=t[1];break}if(6===t[0]&&i.label<s[1]){i.label=s[1],s=t;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(t);break}s[2]&&i.ops.pop(),i.trys.pop();continue}t=n.call(r,i)}catch(e){t=[6,e],o=0}finally{a=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}}function __values(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return{value:(e=e&&n>=e.length?void 0:e)&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function __read(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,a,o=r.call(e),s=[];try{for(;(void 0===t||0<t--)&&!(n=o.next()).done;)s.push(n.value)}catch(e){a={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(a)throw a.error}}return s}function __spreadArray(e,t,r){if(r||2===arguments.length)for(var n,a=0,o=t.length;a<o;a++)!n&&a in t||((n=n||Array.prototype.slice.call(t,0,a))[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))}!function(u){u.assertNever=function(e){throw new Error},u.arrayToEnum=function(e){var t,r,n={};try{for(var a=__values(e),o=a.next();!o.done;o=a.next()){var s=o.value;n[s]=s}}catch(e){t={error:e}}finally{try{o&&!o.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}return n},u.getValidEnumValues=function(t){var r,e,n=u.objectKeys(t).filter(function(e){return"number"!=typeof t[t[e]]}),a={};try{for(var o=__values(n),s=o.next();!s.done;s=o.next()){var i=s.value;a[i]=t[i]}}catch(e){r={error:e}}finally{try{s&&!s.done&&(e=o.return)&&e.call(o)}finally{if(r)throw r.error}}return u.objectValues(a)},u.objectValues=function(t){return u.objectKeys(t).map(function(e){return t[e]})},u.objectKeys="function"==typeof Object.keys?function(e){return Object.keys(e)}:function(e){var t,r=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&r.push(t);return r},u.find=function(e,t){var r,n;try{for(var a=__values(e),o=a.next();!o.done;o=a.next()){var s=o.value;if(t(s))return s}}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}},u.isInteger="function"==typeof Number.isInteger?function(e){return Number.isInteger(e)}:function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e}}(util=util||{});var ZodIssueCode=util.arrayToEnum(["invalid_type","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of"]),quotelessJson=function(e){return JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:")},ZodError=function(n){function t(e){var t=this.constructor,r=n.call(this)||this;r.issues=[],r.format=function(){var p={_errors:[]},c=function(e){var t,r;try{for(var n=__values(e.issues),a=n.next();!a.done;a=n.next()){var o=a.value;if("invalid_union"===o.code)o.unionErrors.map(c);else if("invalid_return_type"===o.code)c(o.returnTypeError);else if("invalid_arguments"===o.code)c(o.argumentsError);else if(0===o.path.length)p._errors.push(o.message);else for(var s=p,i=0;i<o.path.length;){var u,d=o.path[i];i===o.path.length-1?(s[d]=s[d]||{_errors:[]},s[d]._errors.push(o.message)):"string"==typeof d?s[d]=s[d]||{_errors:[]}:"number"==typeof d&&((u=[])._errors=[],s[d]=s[d]||u),s=s[d],i++}}}catch(e){t={error:e}}finally{try{a&&!a.done&&(r=n.return)&&r.call(n)}finally{if(t)throw t.error}}};return c(r),p},r.addIssue=function(e){r.issues=__spreadArray(__spreadArray([],__read(r.issues),!1),[e],!1)},r.addIssues=function(e){void 0===e&&(e=[]),r.issues=__spreadArray(__spreadArray([],__read(r.issues),!1),__read(e),!1)};t=t.prototype;return Object.setPrototypeOf?Object.setPrototypeOf(r,t):r.__proto__=t,r.name="ZodError",r.issues=e,r}return __extends(t,n),Object.defineProperty(t.prototype,"errors",{get:function(){return this.issues},enumerable:!1,configurable:!0}),t.prototype.toString=function(){return this.message},Object.defineProperty(t.prototype,"message",{get:function(){return JSON.stringify(this.issues,null,2)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isEmpty",{get:function(){return 0===this.issues.length},enumerable:!1,configurable:!0}),t.prototype.flatten=function(e){var t,r;void 0===e&&(e=function(e){return e.message});var n={},a=[];try{for(var o=__values(this.issues),s=o.next();!s.done;s=o.next()){var i=s.value;0<i.path.length?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(e(i))):a.push(e(i))}}catch(e){t={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}return{formErrors:a,fieldErrors:n}},Object.defineProperty(t.prototype,"formErrors",{get:function(){return this.flatten()},enumerable:!1,configurable:!0}),t.create=function(e){return new t(e)},t}(Error),defaultErrorMap=function(e,t){var r;switch(e.code){case ZodIssueCode.invalid_type:r="undefined"===e.received?"Required":"Expected ".concat(e.expected,", received ").concat(e.received);break;case ZodIssueCode.unrecognized_keys:r="Unrecognized key(s) in object: ".concat(e.keys.map(function(e){return"'".concat(e,"'")}).join(", "));break;case ZodIssueCode.invalid_union:r="Invalid input";break;case ZodIssueCode.invalid_union_discriminator:r="Invalid discriminator value. Expected ".concat(e.options.map(function(e){return"string"==typeof e?"'".concat(e,"'"):e}).join(" | "));break;case ZodIssueCode.invalid_enum_value:r="Invalid enum value. Expected ".concat(e.options.map(function(e){return"string"==typeof e?"'".concat(e,"'"):e}).join(" | "));break;case ZodIssueCode.invalid_arguments:r="Invalid function arguments";break;case ZodIssueCode.invalid_return_type:r="Invalid function return type";break;case ZodIssueCode.invalid_date:r="Invalid date";break;case ZodIssueCode.invalid_string:r="regex"!==e.validation?"Invalid ".concat(e.validation):"Invalid";break;case ZodIssueCode.too_small:r="array"===e.type?"Array must contain ".concat(e.inclusive?"at least":"more than"," ").concat(e.minimum," element(s)"):"string"===e.type?"String must contain ".concat(e.inclusive?"at least":"over"," ").concat(e.minimum," character(s)"):"number"===e.type?"Number must be greater than ".concat(e.inclusive?"or equal to ":"").concat(e.minimum):"Invalid input";break;case ZodIssueCode.too_big:r="array"===e.type?"Array must contain ".concat(e.inclusive?"at most":"less than"," ").concat(e.maximum," element(s)"):"string"===e.type?"String must contain ".concat(e.inclusive?"at most":"under"," ").concat(e.maximum," character(s)"):"number"===e.type?"Number must be less than ".concat(e.inclusive?"or equal to ":"").concat(e.maximum):"Invalid input";break;case ZodIssueCode.custom:r="Invalid input";break;case ZodIssueCode.invalid_intersection_types:r="Intersection results could not be merged";break;case ZodIssueCode.not_multiple_of:r="Number must be a multiple of ".concat(e.multipleOf);break;default:r=t.defaultError,util.assertNever(e)}return{message:r}},overrideErrorMap=defaultErrorMap,setErrorMap=function(e){overrideErrorMap=e},ZodParsedType=util.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]);function cacheAndReturn(e,t,r){return r&&r.set(e,t),t}var getParsedType=function(e,t){if(t&&t.has(e))return t.get(e);switch(typeof e){case"undefined":return cacheAndReturn(e,ZodParsedType.undefined,t);case"string":return cacheAndReturn(e,ZodParsedType.string,t);case"number":return cacheAndReturn(e,isNaN(e)?ZodParsedType.nan:ZodParsedType.number,t);case"boolean":return cacheAndReturn(e,ZodParsedType.boolean,t);case"function":return cacheAndReturn(e,ZodParsedType.function,t);case"bigint":return cacheAndReturn(e,ZodParsedType.bigint,t);case"object":return Array.isArray(e)?cacheAndReturn(e,ZodParsedType.array,t):null===e?cacheAndReturn(e,ZodParsedType.null,t):e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch?cacheAndReturn(e,ZodParsedType.promise,t):"undefined"!=typeof Map&&e instanceof Map?cacheAndReturn(e,ZodParsedType.map,t):"undefined"!=typeof Set&&e instanceof Set?cacheAndReturn(e,ZodParsedType.set,t):"undefined"!=typeof Date&&e instanceof Date?cacheAndReturn(e,ZodParsedType.date,t):cacheAndReturn(e,ZodParsedType.object,t);default:return cacheAndReturn(e,ZodParsedType.unknown,t)}},makeIssue=function(e){var t,r,n=e.data,a=e.path,o=e.errorMaps,e=e.issueData,a=__spreadArray(__spreadArray([],__read(a),!1),__read(e.path||[]),!1),s=__assign(__assign({},e),{path:a}),i="",o=o.filter(function(e){return!!e}).slice().reverse();try{for(var u=__values(o),d=u.next();!d.done;d=u.next())i=(0,d.value)(s,{data:n,defaultError:i}).message}catch(e){t={error:e}}finally{try{d&&!d.done&&(r=u.return)&&r.call(u)}finally{if(t)throw t.error}}return __assign(__assign({},e),{path:a,message:e.message||i})},EMPTY_PATH=[];function addIssueToContext(e,t){t=makeIssue({issueData:t,data:e.data,path:e.path,errorMaps:[e.contextualErrorMap,e.schemaErrorMap,overrideErrorMap,defaultErrorMap].filter(function(e){return!!e})});e.issues.push(t)}var errorUtil,ParseStatus=function(){function l(){this.value="valid"}return l.prototype.dirty=function(){"valid"===this.value&&(this.value="dirty")},l.prototype.abort=function(){"aborted"!==this.value&&(this.value="aborted")},l.mergeArray=function(e,t){var r,n,a=[];try{for(var o=__values(t),s=o.next();!s.done;s=o.next()){var i=s.value;if("aborted"===i.status)return INVALID;"dirty"===i.status&&e.dirty(),a.push(i.value)}}catch(e){r={error:e}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return{status:e.value,value:a}},l.mergeObjectAsync=function(p,c){return __awaiter(this,void 0,void 0,function(){var t,r,n,a,o,s,i,u,d;return __generator(this,function(e){switch(e.label){case 0:t=[],e.label=1;case 1:e.trys.push([1,7,8,9]),r=__values(c),n=r.next(),e.label=2;case 2:return n.done?[3,6]:(a=n.value,s=(o=t).push,d={},[4,a.key]);case 3:return d.key=e.sent(),[4,a.value];case 4:s.apply(o,[(d.value=e.sent(),d)]),e.label=5;case 5:return n=r.next(),[3,2];case 6:return[3,9];case 7:return i=e.sent(),i={error:i},[3,9];case 8:try{n&&!n.done&&(u=r.return)&&u.call(r)}finally{if(i)throw i.error}return[7];case 9:return[2,l.mergeObjectSync(p,t)]}})})},l.mergeObjectSync=function(e,t){var r,n,a={};try{for(var o=__values(t),s=o.next();!s.done;s=o.next()){var i=s.value,u=i.key,d=i.value;if("aborted"===u.status)return INVALID;if("aborted"===d.status)return INVALID;"dirty"===u.status&&e.dirty(),"dirty"===d.status&&e.dirty(),void 0===d.value&&!i.alwaysSet||(a[u.value]=d.value)}}catch(e){r={error:e}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return{status:e.value,value:a}},l}(),INVALID=Object.freeze({status:"aborted"}),DIRTY=function(e){return{status:"dirty",value:e}},OK=function(e){return{status:"valid",value:e}},isAborted=function(e){return"aborted"===e.status},isDirty=function(e){return"dirty"===e.status},isValid=function(e){return"valid"===e.status},isAsync=function(e){return e instanceof Promise};!function(e){e.errToObj=function(e){return"string"==typeof e?{message:e}:e||{}},e.toString=function(e){return"string"==typeof e?e:null==e?void 0:e.message}}(errorUtil=errorUtil||{});var handleResult=function(e,t){if(isValid(t))return{success:!0,data:t.value};if(!e.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,error:new ZodError(e.issues)}};function processCreateParams(r){if(!r)return{};var e=r.errorMap,t=r.invalid_type_error,n=r.required_error,a=r.description;if(e&&(t||n))throw new Error('Can\'t use "invalid" or "required" in conjunction with custom error map.');if(e)return{errorMap:e,description:a};return{errorMap:function(e,t){return"invalid_type"!==e.code?{message:t.defaultError}:void 0===t.data&&n?{message:n}:r.invalid_type_error?{message:r.invalid_type_error}:{message:t.defaultError}},description:a}}var ZodType=function(){function e(e){this.spa=this.safeParseAsync,this.superRefine=this._refinement,this._def=e,this.transform=this.transform.bind(this),this.default=this.default.bind(this)}return Object.defineProperty(e.prototype,"description",{get:function(){return this._def.description},enumerable:!1,configurable:!0}),e.prototype._processInputParams=function(e){return{status:new ParseStatus,ctx:__assign(__assign({},e.parent),{data:e.data,parsedType:getParsedType(e.data,e.parent.typeCache),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent})}},e.prototype._parseSync=function(e){e=this._parse(e);if(isAsync(e))throw new Error("Synchronous parse encountered promise.");return e},e.prototype._parseAsync=function(e){e=this._parse(e);return Promise.resolve(e)},e.prototype.parse=function(e,t){t=this.safeParse(e,t);if(t.success)return t.data;throw t.error},e.prototype.safeParse=function(e,t){t={path:(null==t?void 0:t.path)||[],issues:[],contextualErrorMap:null==t?void 0:t.errorMap,schemaErrorMap:this._def.errorMap,async:null!==(t=null==t?void 0:t.async)&&void 0!==t&&t,typeCache:"undefined"!=typeof Map?new Map:void 0,parent:null,data:e,parsedType:getParsedType(e)},e=this._parseSync({data:e,path:t.path,parent:t});return handleResult(t,e)},e.prototype.parseAsync=function(r,n){return __awaiter(this,void 0,void 0,function(){var t;return __generator(this,function(e){switch(e.label){case 0:return[4,this.safeParseAsync(r,n)];case 1:if((t=e.sent()).success)return[2,t.data];throw t.error}})})},e.prototype.safeParseAsync=function(n,a){return __awaiter(this,void 0,void 0,function(){var t,r;return __generator(this,function(e){switch(e.label){case 0:return t={path:(null==a?void 0:a.path)||[],issues:[],contextualErrorMap:null==a?void 0:a.errorMap,schemaErrorMap:this._def.errorMap,async:!0,typeCache:"undefined"!=typeof Map?new Map:void 0,parent:null,data:n,parsedType:getParsedType(n)},r=this._parse({data:n,path:[],parent:t}),[4,isAsync(r)?r:Promise.resolve(r)];case 1:return r=e.sent(),[2,handleResult(t,r)]}})})},e.prototype.refine=function(a,o){return this._refinement(function(t,r){function n(){return r.addIssue(__assign({code:ZodIssueCode.custom},(e=t,"string"==typeof o||void 0===o?{message:o}:"function"==typeof o?o(e):o)));var e}var e=a(t);return"undefined"!=typeof Promise&&e instanceof Promise?e.then(function(e){return!!e||(n(),!1)}):!!e||(n(),!1)})},e.prototype.refinement=function(r,n){return this._refinement(function(e,t){return!!r(e)||(t.addIssue("function"==typeof n?n(e,t):n),!1)})},e.prototype._refinement=function(e){return new ZodEffects({schema:this,typeName:ZodFirstPartyTypeKind.ZodEffects,effect:{type:"refinement",refinement:e}})},e.prototype.optional=function(){return ZodOptional.create(this)},e.prototype.nullable=function(){return ZodNullable.create(this)},e.prototype.nullish=function(){return this.optional().nullable()},e.prototype.array=function(){return ZodArray.create(this)},e.prototype.promise=function(){return ZodPromise.create(this)},e.prototype.or=function(e){return ZodUnion.create([this,e])},e.prototype.and=function(e){return ZodIntersection.create(this,e)},e.prototype.transform=function(e){return new ZodEffects({schema:this,typeName:ZodFirstPartyTypeKind.ZodEffects,effect:{type:"transform",transform:e}})},e.prototype.default=function(e){return new ZodDefault({innerType:this,defaultValue:"function"==typeof e?e:function(){return e},typeName:ZodFirstPartyTypeKind.ZodDefault})},e.prototype.describe=function(e){return new this.constructor(__assign(__assign({},this._def),{description:e}))},e.prototype.isOptional=function(){return this.safeParse(void 0).success},e.prototype.isNullable=function(){return this.safeParse(null).success},e}(),cuidRegex=/^c[^\s-]{8,}$/i,uuidRegex=/^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i,emailRegex=/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i,ZodString=function(e){function t(){var n=null!==e&&e.apply(this,arguments)||this;return n._regex=function(t,e,r){return n.refinement(function(e){return t.test(e)},__assign({validation:e,code:ZodIssueCode.invalid_string},errorUtil.errToObj(r)))},n.nonempty=function(e){return n.min(1,errorUtil.errToObj(e))},n}return __extends(t,e),t.prototype._parse=function(e){var t,r,e=this._processInputParams(e),n=e.status,a=e.ctx;if(a.parsedType!==ZodParsedType.string)return addIssueToContext(a,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.string,received:a.parsedType}),INVALID;try{for(var o=__values(this._def.checks),s=o.next();!s.done;s=o.next()){var i=s.value;if("min"===i.kind)a.data.length<i.value&&(addIssueToContext(a,{code:ZodIssueCode.too_small,minimum:i.value,type:"string",inclusive:!0,message:i.message}),n.dirty());else if("max"===i.kind)a.data.length>i.value&&(addIssueToContext(a,{code:ZodIssueCode.too_big,maximum:i.value,type:"string",inclusive:!0,message:i.message}),n.dirty());else if("email"===i.kind)emailRegex.test(a.data)||(addIssueToContext(a,{validation:"email",code:ZodIssueCode.invalid_string,message:i.message}),n.dirty());else if("uuid"===i.kind)uuidRegex.test(a.data)||(addIssueToContext(a,{validation:"uuid",code:ZodIssueCode.invalid_string,message:i.message}),n.dirty());else if("cuid"===i.kind)cuidRegex.test(a.data)||(addIssueToContext(a,{validation:"cuid",code:ZodIssueCode.invalid_string,message:i.message}),n.dirty());else if("url"===i.kind)try{new URL(a.data)}catch(e){addIssueToContext(a,{validation:"url",code:ZodIssueCode.invalid_string,message:i.message}),n.dirty()}else"regex"===i.kind&&(i.regex.lastIndex=0,i.regex.test(a.data)||(addIssueToContext(a,{validation:"regex",code:ZodIssueCode.invalid_string,message:i.message}),n.dirty()))}}catch(e){t={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}return{status:n.value,value:a.data}},t.prototype._addCheck=function(e){return new t(__assign(__assign({},this._def),{checks:__spreadArray(__spreadArray([],__read(this._def.checks),!1),[e],!1)}))},t.prototype.email=function(e){return this._addCheck(__assign({kind:"email"},errorUtil.errToObj(e)))},t.prototype.url=function(e){return this._addCheck(__assign({kind:"url"},errorUtil.errToObj(e)))},t.prototype.uuid=function(e){return this._addCheck(__assign({kind:"uuid"},errorUtil.errToObj(e)))},t.prototype.cuid=function(e){return this._addCheck(__assign({kind:"cuid"},errorUtil.errToObj(e)))},t.prototype.regex=function(e,t){return this._addCheck(__assign({kind:"regex",regex:e},errorUtil.errToObj(t)))},t.prototype.min=function(e,t){return this._addCheck(__assign({kind:"min",value:e},errorUtil.errToObj(t)))},t.prototype.max=function(e,t){return this._addCheck(__assign({kind:"max",value:e},errorUtil.errToObj(t)))},t.prototype.length=function(e,t){return this.min(e,t).max(e,t)},Object.defineProperty(t.prototype,"isEmail",{get:function(){return!!this._def.checks.find(function(e){return"email"===e.kind})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isURL",{get:function(){return!!this._def.checks.find(function(e){return"url"===e.kind})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isUUID",{get:function(){return!!this._def.checks.find(function(e){return"uuid"===e.kind})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isCUID",{get:function(){return!!this._def.checks.find(function(e){return"cuid"===e.kind})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minLength",{get:function(){var t=-1/0;return this._def.checks.map(function(e){"min"===e.kind&&(null===t||e.value>t)&&(t=e.value)}),t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxLength",{get:function(){var t=null;return this._def.checks.map(function(e){"max"===e.kind&&(null===t||e.value<t)&&(t=e.value)}),t},enumerable:!1,configurable:!0}),t.create=function(e){return new t(__assign({checks:[],typeName:ZodFirstPartyTypeKind.ZodString},processCreateParams(e)))},t}(ZodType);function floatSafeRemainder(e,t){var r=(e.toString().split(".")[1]||"").length,n=(t.toString().split(".")[1]||"").length,n=n<r?r:n;return parseInt(e.toFixed(n).replace(".",""))%parseInt(t.toFixed(n).replace(".",""))/Math.pow(10,n)}var objectUtil,ZodNumber=function(t){function a(){var e=null!==t&&t.apply(this,arguments)||this;return e.min=e.gte,e.max=e.lte,e.step=e.multipleOf,e}return __extends(a,t),a.prototype._parse=function(e){var t,r,e=this._processInputParams(e),n=e.status,a=e.ctx;if(a.parsedType!==ZodParsedType.number)return addIssueToContext(a,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.number,received:a.parsedType}),INVALID;try{for(var o=__values(this._def.checks),s=o.next();!s.done;s=o.next()){var i=s.value;"int"===i.kind?util.isInteger(a.data)||(addIssueToContext(a,{code:ZodIssueCode.invalid_type,expected:"integer",received:"float",message:i.message}),n.dirty()):"min"===i.kind?(i.inclusive?a.data<i.value:a.data<=i.value)&&(addIssueToContext(a,{code:ZodIssueCode.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,message:i.message}),n.dirty()):"max"===i.kind?(i.inclusive?a.data>i.value:a.data>=i.value)&&(addIssueToContext(a,{code:ZodIssueCode.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,message:i.message}),n.dirty()):"multipleOf"===i.kind?0!==floatSafeRemainder(a.data,i.value)&&(addIssueToContext(a,{code:ZodIssueCode.not_multiple_of,multipleOf:i.value,message:i.message}),n.dirty()):util.assertNever(i)}}catch(e){t={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}return{status:n.value,value:a.data}},a.prototype.gte=function(e,t){return this.setLimit("min",e,!0,errorUtil.toString(t))},a.prototype.gt=function(e,t){return this.setLimit("min",e,!1,errorUtil.toString(t))},a.prototype.lte=function(e,t){return this.setLimit("max",e,!0,errorUtil.toString(t))},a.prototype.lt=function(e,t){return this.setLimit("max",e,!1,errorUtil.toString(t))},a.prototype.setLimit=function(e,t,r,n){return new a(__assign(__assign({},this._def),{checks:__spreadArray(__spreadArray([],__read(this._def.checks),!1),[{kind:e,value:t,inclusive:r,message:errorUtil.toString(n)}],!1)}))},a.prototype._addCheck=function(e){return new a(__assign(__assign({},this._def),{checks:__spreadArray(__spreadArray([],__read(this._def.checks),!1),[e],!1)}))},a.prototype.int=function(e){return this._addCheck({kind:"int",message:errorUtil.toString(e)})},a.prototype.positive=function(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:errorUtil.toString(e)})},a.prototype.negative=function(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:errorUtil.toString(e)})},a.prototype.nonpositive=function(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:errorUtil.toString(e)})},a.prototype.nonnegative=function(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:errorUtil.toString(e)})},a.prototype.multipleOf=function(e,t){return this._addCheck({kind:"multipleOf",value:e,message:errorUtil.toString(t)})},Object.defineProperty(a.prototype,"minValue",{get:function(){var t,e,r=null;try{for(var n=__values(this._def.checks),a=n.next();!a.done;a=n.next()){var o=a.value;"min"===o.kind&&(null===r||o.value>r)&&(r=o.value)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}return r},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"maxValue",{get:function(){var t,e,r=null;try{for(var n=__values(this._def.checks),a=n.next();!a.done;a=n.next()){var o=a.value;"max"===o.kind&&(null===r||o.value<r)&&(r=o.value)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}return r},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"isInt",{get:function(){return!!this._def.checks.find(function(e){return"int"===e.kind})},enumerable:!1,configurable:!0}),a.create=function(e){return new a(__assign({checks:[],typeName:ZodFirstPartyTypeKind.ZodNumber},processCreateParams(e)))},a}(ZodType),ZodBigInt=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype._parse=function(e){e=this._processInputParams(e).ctx;return e.parsedType!==ZodParsedType.bigint?(addIssueToContext(e,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.bigint,received:e.parsedType}),INVALID):OK(e.data)},t.create=function(e){return new t(__assign({typeName:ZodFirstPartyTypeKind.ZodBigInt},processCreateParams(e)))},t}(ZodType),ZodBoolean=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype._parse=function(e){e=this._processInputParams(e).ctx;return e.parsedType!==ZodParsedType.boolean?(addIssueToContext(e,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.boolean,received:e.parsedType}),INVALID):OK(e.data)},t.create=function(e){return new t(__assign({typeName:ZodFirstPartyTypeKind.ZodBoolean},processCreateParams(e)))},t}(ZodType),ZodDate=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype._parse=function(e){var t=this._processInputParams(e),e=t.status,t=t.ctx;return t.parsedType!==ZodParsedType.date?(addIssueToContext(t,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.date,received:t.parsedType}),INVALID):isNaN(t.data.getTime())?(addIssueToContext(t,{code:ZodIssueCode.invalid_date}),INVALID):{status:e.value,value:new Date(t.data.getTime())}},t.create=function(e){return new t(__assign({typeName:ZodFirstPartyTypeKind.ZodDate},processCreateParams(e)))},t}(ZodType),ZodUndefined=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype._parse=function(e){e=this._processInputParams(e).ctx;return e.parsedType!==ZodParsedType.undefined?(addIssueToContext(e,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.undefined,received:e.parsedType}),INVALID):OK(e.data)},t.create=function(e){return new t(__assign({typeName:ZodFirstPartyTypeKind.ZodUndefined},processCreateParams(e)))},t}(ZodType),ZodNull=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype._parse=function(e){e=this._processInputParams(e).ctx;return e.parsedType!==ZodParsedType.null?(addIssueToContext(e,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.null,received:e.parsedType}),INVALID):OK(e.data)},t.create=function(e){return new t(__assign({typeName:ZodFirstPartyTypeKind.ZodNull},processCreateParams(e)))},t}(ZodType),ZodAny=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e._any=!0,e}return __extends(r,t),r.prototype._parse=function(e){e=this._processInputParams(e).ctx;return OK(e.data)},r.create=function(e){return new r(__assign({typeName:ZodFirstPartyTypeKind.ZodAny},processCreateParams(e)))},r}(ZodType),ZodUnknown=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e._unknown=!0,e}return __extends(r,t),r.prototype._parse=function(e){e=this._processInputParams(e).ctx;return OK(e.data)},r.create=function(e){return new r(__assign({typeName:ZodFirstPartyTypeKind.ZodUnknown},processCreateParams(e)))},r}(ZodType),ZodNever=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype._parse=function(e){e=this._processInputParams(e).ctx;return addIssueToContext(e,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.never,received:e.parsedType}),INVALID},t.create=function(e){return new t(__assign({typeName:ZodFirstPartyTypeKind.ZodNever},processCreateParams(e)))},t}(ZodType),ZodVoid=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype._parse=function(e){e=this._processInputParams(e).ctx;return e.parsedType!==ZodParsedType.undefined?(addIssueToContext(e,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.void,received:e.parsedType}),INVALID):OK(e.data)},t.create=function(e){return new t(__assign({typeName:ZodFirstPartyTypeKind.ZodVoid},processCreateParams(e)))},t}(ZodType),ZodArray=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return __extends(r,e),r.prototype._parse=function(e){var e=this._processInputParams(e),t=e.status,r=e.ctx,n=this._def;if(r.parsedType!==ZodParsedType.array)return addIssueToContext(r,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.array,received:r.parsedType}),INVALID;if(null!==n.minLength&&r.data.length<n.minLength.value&&(addIssueToContext(r,{code:ZodIssueCode.too_small,minimum:n.minLength.value,type:"array",inclusive:!0,message:n.minLength.message}),t.dirty()),null!==n.maxLength&&r.data.length>n.maxLength.value&&(addIssueToContext(r,{code:ZodIssueCode.too_big,maximum:n.maxLength.value,type:"array",inclusive:!0,message:n.maxLength.message}),t.dirty()),r.async)return Promise.all(r.data.map(function(e,t){return n.type._parseAsync({parent:r,path:__spreadArray(__spreadArray([],__read(r.path),!1),[t],!1),data:e})})).then(function(e){return ParseStatus.mergeArray(t,e)});e=r.data.map(function(e,t){return n.type._parseSync({parent:r,path:__spreadArray(__spreadArray([],__read(r.path),!1),[t],!1),data:e})});return ParseStatus.mergeArray(t,e)},Object.defineProperty(r.prototype,"element",{get:function(){return this._def.type},enumerable:!1,configurable:!0}),r.prototype.min=function(e,t){return new r(__assign(__assign({},this._def),{minLength:{value:e,message:errorUtil.toString(t)}}))},r.prototype.max=function(e,t){return new r(__assign(__assign({},this._def),{maxLength:{value:e,message:errorUtil.toString(t)}}))},r.prototype.length=function(e,t){return this.min(e,t).max(e,t)},r.prototype.nonempty=function(e){return this.min(1,e)},r.create=function(e,t){return new r(__assign({type:e,minLength:null,maxLength:null,typeName:ZodFirstPartyTypeKind.ZodArray},processCreateParams(t)))},r}(ZodType);(objectUtil||(objectUtil={})).mergeShapes=function(e,t){return __assign(__assign({},e),t)};var AugmentFactory=function(t){return function(e){return new ZodObject(__assign(__assign({},t),{shape:function(){return __assign(__assign({},t.shape()),e)}}))}};function deepPartialify(e){if(e instanceof ZodObject){var t,r={};for(t in e.shape){var n=e.shape[t];r[t]=ZodOptional.create(deepPartialify(n))}return new ZodObject(__assign(__assign({},e._def),{shape:function(){return r}}))}return e instanceof ZodArray?ZodArray.create(deepPartialify(e.element)):e instanceof ZodOptional?ZodOptional.create(deepPartialify(e.unwrap())):e instanceof ZodNullable?ZodNullable.create(deepPartialify(e.unwrap())):e instanceof ZodTuple?ZodTuple.create(e.items.map(function(e){return deepPartialify(e)})):e}var ZodObject=function(t){function s(){var e=null!==t&&t.apply(this,arguments)||this;return e._cached=null,e.nonstrict=e.passthrough,e.augment=AugmentFactory(e._def),e.extend=AugmentFactory(e._def),e}return __extends(s,t),s.prototype._getCached=function(){if(null!==this._cached)return this._cached;var e=this._def.shape(),t=util.objectKeys(e);return this._cached={shape:e,keys:t}},s.prototype._parse=function(e){var t,r,n,a,o,s=this,i=this._processInputParams(e),u=i.status,d=i.ctx;if(d.parsedType!==ZodParsedType.object)return addIssueToContext(d,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.object,received:d.parsedType}),INVALID;var e=this._getCached(),p=e.shape,i=e.keys,e=util.objectKeys(d.data).filter(function(e){return!(e in p)}),c=[];try{for(var l=__values(i),y=l.next();!y.done;y=l.next()){var f=y.value,_=p[f],h=d.data[f];c.push({key:{status:"valid",value:f},value:_._parse({parent:d,data:h,path:__spreadArray(__spreadArray([],__read(d.path),!1),[f],!1)}),alwaysSet:f in d.data})}}catch(e){m={error:e}}finally{try{y&&!y.done&&(t=l.return)&&t.call(l)}finally{if(m)throw m.error}}if(this._def.catchall instanceof ZodNever){var m=this._def.unknownKeys;if("passthrough"===m)try{for(var v=__values(e),Z=v.next();!Z.done;Z=v.next()){f=Z.value;c.push({key:{status:"valid",value:f},value:{status:"valid",value:d.data[f]}})}}catch(e){r={error:e}}finally{try{Z&&!Z.done&&(n=v.return)&&n.call(v)}finally{if(r)throw r.error}}else if("strict"===m)0<e.length&&(addIssueToContext(d,{code:ZodIssueCode.unrecognized_keys,keys:e}),u.dirty());else if("strip"!==m)throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{var g=this._def.catchall;try{for(var T=__values(e),b=T.next();!b.done;b=T.next()){f=b.value,h=d.data[f];c.push({key:{status:"valid",value:f},value:g._parse({parent:d,path:__spreadArray(__spreadArray([],__read(d.path),!1),[f],!1),data:h}),alwaysSet:f in d.data})}}catch(e){a={error:e}}finally{try{b&&!b.done&&(o=T.return)&&o.call(T)}finally{if(a)throw a.error}}}return d.async?Promise.resolve().then(function(){return __awaiter(s,void 0,void 0,function(){var t,r,n,a,o,s,i,u,d;return __generator(this,function(e){switch(e.label){case 0:t=[],e.label=1;case 1:e.trys.push([1,7,8,9]),r=__values(c),n=r.next(),e.label=2;case 2:return n.done?[3,6]:[4,(a=n.value).key];case 3:return d=e.sent(),s=(o=t).push,d={key:d},[4,a.value];case 4:s.apply(o,[(d.value=e.sent(),d.alwaysSet=a.alwaysSet,d)]),e.label=5;case 5:return n=r.next(),[3,2];case 6:return[3,9];case 7:return i=e.sent(),i={error:i},[3,9];case 8:try{n&&!n.done&&(u=r.return)&&u.call(r)}finally{if(i)throw i.error}return[7];case 9:return[2,t]}})})}).then(function(e){return ParseStatus.mergeObjectSync(u,e)}):ParseStatus.mergeObjectSync(u,c)},Object.defineProperty(s.prototype,"shape",{get:function(){return this._def.shape()},enumerable:!1,configurable:!0}),s.prototype.strict=function(a){var o=this;return errorUtil.errToObj,new s(__assign(__assign(__assign({},this._def),{unknownKeys:"strict"}),void 0!==a?{errorMap:function(e,t){var r,n,t=null!==(n=null===(r=(n=o._def).errorMap)||void 0===r?void 0:r.call(n,e,t).message)&&void 0!==n?n:t.defaultError;return"unrecognized_keys"===e.code?{message:null!==(e=errorUtil.errToObj(a).message)&&void 0!==e?e:t}:{message:t}}}:{}))},s.prototype.strip=function(){return new s(__assign(__assign({},this._def),{unknownKeys:"strip"}))},s.prototype.passthrough=function(){return new s(__assign(__assign({},this._def),{unknownKeys:"passthrough"}))},s.prototype.setKey=function(e,t){var r;return this.augment(((r={})[e]=t,r))},s.prototype.merge=function(e){var t=objectUtil.mergeShapes(this._def.shape(),e._def.shape());return new s({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:function(){return t},typeName:ZodFirstPartyTypeKind.ZodObject})},s.prototype.catchall=function(e){return new s(__assign(__assign({},this._def),{catchall:e}))},s.prototype.pick=function(e){var t=this,r={};return util.objectKeys(e).map(function(e){r[e]=t.shape[e]}),new s(__assign(__assign({},this._def),{shape:function(){return r}}))},s.prototype.omit=function(t){var r=this,n={};return util.objectKeys(this.shape).map(function(e){-1===util.objectKeys(t).indexOf(e)&&(n[e]=r.shape[e])}),new s(__assign(__assign({},this._def),{shape:function(){return n}}))},s.prototype.deepPartial=function(){return deepPartialify(this)},s.prototype.partial=function(t){var e,r=this,n={};if(t)return util.objectKeys(this.shape).map(function(e){-1===util.objectKeys(t).indexOf(e)?n[e]=r.shape[e]:n[e]=r.shape[e].optional()}),new s(__assign(__assign({},this._def),{shape:function(){return n}}));for(e in this.shape){var a=this.shape[e];n[e]=a.optional()}return new s(__assign(__assign({},this._def),{shape:function(){return n}}))},s.prototype.required=function(){var e,t={};for(e in this.shape){for(var r=this.shape[e];r instanceof ZodOptional;)r=r._def.innerType;t[e]=r}return new s(__assign(__assign({},this._def),{shape:function(){return t}}))},s.create=function(e,t){return new s(__assign({shape:function(){return e},unknownKeys:"strip",catchall:ZodNever.create(),typeName:ZodFirstPartyTypeKind.ZodObject},processCreateParams(t)))},s.strictCreate=function(e,t){return new s(__assign({shape:function(){return e},unknownKeys:"strict",catchall:ZodNever.create(),typeName:ZodFirstPartyTypeKind.ZodObject},processCreateParams(t)))},s.lazycreate=function(e,t){return new s(__assign({shape:e,unknownKeys:"strip",catchall:ZodNever.create(),typeName:ZodFirstPartyTypeKind.ZodObject},processCreateParams(t)))},s}(ZodType),ZodUnion=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return __extends(r,e),r.prototype._parse=function(e){var t=this,c=this._processInputParams(e).ctx,e=this._def.options;function r(e){var t,r,n,a,o;try{for(var s=__values(e),i=s.next();!i.done;i=s.next())if("valid"===(u=i.value).result.status)return u.result}catch(e){t={error:e}}finally{try{i&&!i.done&&(r=s.return)&&r.call(s)}finally{if(t)throw t.error}}try{for(var u,d=__values(e),p=d.next();!p.done;p=d.next())if("dirty"===(u=p.value).result.status)return(o=c.issues).push.apply(o,__spreadArray([],__read(u.ctx.issues),!1)),u.result}catch(e){n={error:e}}finally{try{p&&!p.done&&(a=d.return)&&a.call(d)}finally{if(n)throw n.error}}e=e.map(function(e){return new ZodError(e.ctx.issues)});return addIssueToContext(c,{code:ZodIssueCode.invalid_union,unionErrors:e}),INVALID}return c.async?Promise.all(e.map(function(n){return __awaiter(t,void 0,void 0,function(){var t,r;return __generator(this,function(e){switch(e.label){case 0:return t=__assign(__assign({},c),{issues:[],parent:null}),r={},[4,n._parseAsync({data:c.data,path:c.path,parent:t})];case 1:return[2,(r.result=e.sent(),r.ctx=t,r)]}})})})).then(r):r(e.map(function(e){var t=__assign(__assign({},c),{issues:[],parent:null});return{result:e._parseSync({data:c.data,path:c.path,parent:t}),ctx:t}}))},Object.defineProperty(r.prototype,"options",{get:function(){return this._def.options},enumerable:!1,configurable:!0}),r.create=function(e,t){return new r(__assign({options:e,typeName:ZodFirstPartyTypeKind.ZodUnion},processCreateParams(t)))},r}(ZodType),ZodDiscriminatedUnion=function(e){function a(){return null!==e&&e.apply(this,arguments)||this}return __extends(a,e),a.prototype._parse=function(e){var t=this._processInputParams(e).ctx;if(t.parsedType!==ZodParsedType.object)return addIssueToContext(t,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.object,received:t.parsedType}),INVALID;var r=this.discriminator,e=t.data[r],e=this.options.get(e);return e?t.async?e._parseAsync({data:t.data,path:t.path,parent:t}):e._parseSync({data:t.data,path:t.path,parent:t}):(addIssueToContext(t,{code:ZodIssueCode.invalid_union_discriminator,options:this.validDiscriminatorValues,path:[r]}),INVALID)},Object.defineProperty(a.prototype,"discriminator",{get:function(){return this._def.discriminator},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"validDiscriminatorValues",{get:function(){return Array.from(this.options.keys())},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"options",{get:function(){return this._def.options},enumerable:!1,configurable:!0}),a.create=function(r,e,t){var n=new Map;try{e.forEach(function(e){var t=e.shape[r].value;n.set(t,e)})}catch(e){throw new Error("The discriminator value could not be extracted from all the provided schemas")}if(n.size!==e.length)throw new Error("Some of the discriminator values are not unique");return new a(__assign({typeName:ZodFirstPartyTypeKind.ZodDiscriminatedUnion,discriminator:r,options:n},processCreateParams(t)))},a}(ZodType);function mergeValues(e,t){var r,n,a=getParsedType(e),o=getParsedType(t);if(e===t)return{valid:!0,data:e};if(a===ZodParsedType.object&&o===ZodParsedType.object){var s=util.objectKeys(t),i=util.objectKeys(e).filter(function(e){return-1!==s.indexOf(e)}),u=__assign(__assign({},e),t);try{for(var d=__values(i),p=d.next();!p.done;p=d.next()){var c=p.value;if(!(l=mergeValues(e[c],t[c])).valid)return{valid:!1};u[c]=l.data}}catch(e){r={error:e}}finally{try{p&&!p.done&&(n=d.return)&&n.call(d)}finally{if(r)throw r.error}}return{valid:!0,data:u}}if(a!==ZodParsedType.array||o!==ZodParsedType.array)return a===ZodParsedType.date&&o===ZodParsedType.date&&+e==+t?{valid:!0,data:e}:{valid:!1};if(e.length!==t.length)return{valid:!1};for(var l,y=[],f=0;f<e.length;f++){if(!(l=mergeValues(e[f],t[f])).valid)return{valid:!1};y.push(l.data)}return{valid:!0,data:y}}var ZodIntersection=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype._parse=function(e){function r(e,t){if(isAborted(e)||isAborted(t))return INVALID;var r=mergeValues(e.value,t.value);return r.valid?((isDirty(e)||isDirty(t))&&n.dirty(),{status:n.value,value:r.data}):(addIssueToContext(a,{code:ZodIssueCode.invalid_intersection_types}),INVALID)}var e=this._processInputParams(e),n=e.status,a=e.ctx;return a.async?Promise.all([this._def.left._parseAsync({data:a.data,path:a.path,parent:a}),this._def.right._parseAsync({data:a.data,path:a.path,parent:a})]).then(function(e){var t=__read(e,2),e=t[0],t=t[1];return r(e,t)}):r(this._def.left._parseSync({data:a.data,path:a.path,parent:a}),this._def.right._parseSync({data:a.data,path:a.path,parent:a}))},n.create=function(e,t,r){return new n(__assign({left:e,right:t,typeName:ZodFirstPartyTypeKind.ZodIntersection},processCreateParams(r)))},n}(ZodType),ZodTuple=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return __extends(r,e),r.prototype._parse=function(e){var n=this,e=this._processInputParams(e),t=e.status,a=e.ctx;if(a.parsedType!==ZodParsedType.array)return addIssueToContext(a,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.array,received:a.parsedType}),INVALID;if(a.data.length<this._def.items.length)return addIssueToContext(a,{code:ZodIssueCode.too_small,minimum:this._def.items.length,inclusive:!0,type:"array"}),INVALID;!this._def.rest&&a.data.length>this._def.items.length&&(addIssueToContext(a,{code:ZodIssueCode.too_big,maximum:this._def.items.length,inclusive:!0,type:"array"}),t.dirty());e=a.data.map(function(e,t){var r=n._def.items[t]||n._def.rest;return r?r._parse({data:e,path:__spreadArray(__spreadArray([],__read(a.path),!1),[t],!1),parent:a}):null}).filter(function(e){return!!e});return a.async?Promise.all(e).then(function(e){return ParseStatus.mergeArray(t,e)}):ParseStatus.mergeArray(t,e)},Object.defineProperty(r.prototype,"items",{get:function(){return this._def.items},enumerable:!1,configurable:!0}),r.prototype.rest=function(e){return new r(__assign(__assign({},this._def),{rest:e}))},r.create=function(e,t){return new r(__assign({items:e,typeName:ZodFirstPartyTypeKind.ZodTuple,rest:null},processCreateParams(t)))},r}(ZodType),ZodRecord=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"keySchema",{get:function(){return this._def.keyType},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"valueSchema",{get:function(){return this._def.valueType},enumerable:!1,configurable:!0}),n.prototype._parse=function(e){var t=this._processInputParams(e),e=t.status,r=t.ctx;if(r.parsedType!==ZodParsedType.object)return addIssueToContext(r,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.object,received:r.parsedType}),INVALID;var n,a=[],o=this._def.keyType,s=this._def.valueType;for(n in r.data)a.push({key:o._parse({data:n,path:__spreadArray(__spreadArray([],__read(r.path),!1),[n],!1),parent:r}),value:s._parse({data:r.data[n],path:__spreadArray(__spreadArray([],__read(r.path),!1),[n],!1),parent:r})});return r.async?ParseStatus.mergeObjectAsync(e,a):ParseStatus.mergeObjectSync(e,a)},Object.defineProperty(n.prototype,"element",{get:function(){return this._def.valueType},enumerable:!1,configurable:!0}),n.create=function(e,t,r){return new n(t instanceof ZodType?__assign({keyType:e,valueType:t,typeName:ZodFirstPartyTypeKind.ZodRecord},processCreateParams(r)):__assign({keyType:ZodString.create(),valueType:e,typeName:ZodFirstPartyTypeKind.ZodRecord},processCreateParams(t)))},n}(ZodType),ZodMap=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype._parse=function(e){var t,r,n=this,e=this._processInputParams(e),u=e.status,a=e.ctx;if(a.parsedType!==ZodParsedType.map)return addIssueToContext(a,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.map,received:a.parsedType}),INVALID;var o=this._def.keyType,s=this._def.valueType,d=__spreadArray([],__read(a.data.entries()),!1).map(function(e,t){var r=__read(e,2),e=r[0],r=r[1];return{key:o._parse({data:e,path:__spreadArray(__spreadArray([],__read(a.path),!1),[t,"key"],!1),parent:a}),value:s._parse({data:r,path:__spreadArray(__spreadArray([],__read(a.path),!1),[t,"value"],!1),parent:a})}});if(a.async){var p=new Map;return Promise.resolve().then(function(){return __awaiter(n,void 0,void 0,function(){var t,r,n,a,o,s,i;return __generator(this,function(e){switch(e.label){case 0:e.trys.push([0,6,7,8]),t=__values(d),r=t.next(),e.label=1;case 1:return r.done?[3,5]:[4,(n=r.value).key];case 2:return a=e.sent(),[4,n.value];case 3:if(o=e.sent(),"aborted"===a.status||"aborted"===o.status)return[2,INVALID];"dirty"!==a.status&&"dirty"!==o.status||u.dirty(),p.set(a.value,o.value),e.label=4;case 4:return r=t.next(),[3,1];case 5:return[3,8];case 6:return s=e.sent(),s={error:s},[3,8];case 7:try{r&&!r.done&&(i=t.return)&&i.call(t)}finally{if(s)throw s.error}return[7];case 8:return[2,{status:u.value,value:p}]}})})})}var i=new Map;try{for(var c=__values(d),l=c.next();!l.done;l=c.next()){var y=l.value,f=y.key,_=y.value;if("aborted"===f.status||"aborted"===_.status)return INVALID;"dirty"!==f.status&&"dirty"!==_.status||u.dirty(),i.set(f.value,_.value)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(r=c.return)&&r.call(c)}finally{if(t)throw t.error}}return{status:u.value,value:i}},n.create=function(e,t,r){return new n(__assign({valueType:t,keyType:e,typeName:ZodFirstPartyTypeKind.ZodMap},processCreateParams(r)))},n}(ZodType),ZodSet=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return __extends(r,e),r.prototype._parse=function(e){var e=this._processInputParams(e),i=e.status,r=e.ctx;if(r.parsedType!==ZodParsedType.set)return addIssueToContext(r,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.set,received:r.parsedType}),INVALID;e=this._def;null!==e.minSize&&r.data.size<e.minSize.value&&(addIssueToContext(r,{code:ZodIssueCode.too_small,minimum:e.minSize.value,type:"set",inclusive:!0,message:e.minSize.message}),i.dirty()),null!==e.maxSize&&r.data.size>e.maxSize.value&&(addIssueToContext(r,{code:ZodIssueCode.too_big,maximum:e.maxSize.value,type:"set",inclusive:!0,message:e.maxSize.message}),i.dirty());var n=this._def.valueType;function t(e){var t,r,n=new Set;try{for(var a=__values(e),o=a.next();!o.done;o=a.next()){var s=o.value;if("aborted"===s.status)return INVALID;"dirty"===s.status&&i.dirty(),n.add(s.value)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}return{status:i.value,value:n}}e=__spreadArray([],__read(r.data.values()),!1).map(function(e,t){return n._parse({data:e,path:__spreadArray(__spreadArray([],__read(r.path),!1),[t],!1),parent:r})});return r.async?Promise.all(e).then(t):t(e)},r.prototype.min=function(e,t){return new r(__assign(__assign({},this._def),{minSize:{value:e,message:errorUtil.toString(t)}}))},r.prototype.max=function(e,t){return new r(__assign(__assign({},this._def),{maxSize:{value:e,message:errorUtil.toString(t)}}))},r.prototype.size=function(e,t){return this.min(e,t).max(e,t)},r.prototype.nonempty=function(e){return this.min(1,e)},r.create=function(e,t){return new r(__assign({valueType:e,minSize:null,maxSize:null,typeName:ZodFirstPartyTypeKind.ZodSet},processCreateParams(t)))},r}(ZodType),ZodFunction=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.validate=e.implement,e}return __extends(n,t),n.prototype._parse=function(e){var o=this,r=this._processInputParams(e).ctx;if(r.parsedType!==ZodParsedType.function)return addIssueToContext(r,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.function,received:r.parsedType}),INVALID;function s(e,t){return makeIssue({data:e,path:r.path,errorMaps:[r.contextualErrorMap,r.schemaErrorMap,overrideErrorMap,defaultErrorMap].filter(function(e){return!!e}),issueData:{code:ZodIssueCode.invalid_arguments,argumentsError:t}})}function i(e,t){return makeIssue({data:e,path:r.path,errorMaps:[r.contextualErrorMap,r.schemaErrorMap,overrideErrorMap,defaultErrorMap].filter(function(e){return!!e}),issueData:{code:ZodIssueCode.invalid_return_type,returnTypeError:t}})}var u={errorMap:r.contextualErrorMap},d=r.data;return this._def.returns instanceof ZodPromise?OK(function(){for(var a=[],e=0;e<arguments.length;e++)a[e]=arguments[e];return __awaiter(o,void 0,void 0,function(){var t,r,n;return __generator(this,function(e){switch(e.label){case 0:return t=new ZodError([]),[4,this._def.args.parseAsync(a,u).catch(function(e){throw t.addIssue(s(a,e)),t})];case 1:return r=e.sent(),[4,d.apply(void 0,__spreadArray([],__read(r),!1))];case 2:return n=e.sent(),[4,this._def.returns._def.type.parseAsync(n,u).catch(function(e){throw t.addIssue(i(n,e)),t})];case 3:return[2,e.sent()]}})})}):OK(function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=o._def.args.safeParse(e,u);if(!r.success)throw new ZodError([s(e,r.error)]);var n=d.apply(void 0,__spreadArray([],__read(r.data),!1)),r=o._def.returns.safeParse(n,u);if(!r.success)throw new ZodError([i(n,r.error)]);return r.data})},n.prototype.parameters=function(){return this._def.args},n.prototype.returnType=function(){return this._def.returns},n.prototype.args=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return new n(__assign(__assign({},this._def),{args:ZodTuple.create(e).rest(ZodUnknown.create())}))},n.prototype.returns=function(e){return new n(__assign(__assign({},this._def),{returns:e}))},n.prototype.implement=function(e){return this.parse(e)},n.prototype.strictImplement=function(e){return this.parse(e)},n.create=function(e,t,r){return new n(__assign({args:(e||ZodTuple.create([])).rest(ZodUnknown.create()),returns:t||ZodUnknown.create(),typeName:ZodFirstPartyTypeKind.ZodFunction},processCreateParams(r)))},n}(ZodType),ZodLazy=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return __extends(r,e),Object.defineProperty(r.prototype,"schema",{get:function(){return this._def.getter()},enumerable:!1,configurable:!0}),r.prototype._parse=function(e){e=this._processInputParams(e).ctx;return this._def.getter()._parse({data:e.data,path:e.path,parent:e})},r.create=function(e,t){return new r(__assign({getter:e,typeName:ZodFirstPartyTypeKind.ZodLazy},processCreateParams(t)))},r}(ZodType),ZodLiteral=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return __extends(r,e),r.prototype._parse=function(e){var t=this._processInputParams(e),e=t.status,t=t.ctx;return t.data!==this._def.value?(addIssueToContext(t,{code:ZodIssueCode.invalid_type,expected:getParsedType(this._def.value),received:t.parsedType}),INVALID):{status:e.value,value:t.data}},Object.defineProperty(r.prototype,"value",{get:function(){return this._def.value},enumerable:!1,configurable:!0}),r.create=function(e,t){return new r(__assign({value:e,typeName:ZodFirstPartyTypeKind.ZodLiteral},processCreateParams(t)))},r}(ZodType);function createZodEnum(e){return new ZodEnum({values:e,typeName:ZodFirstPartyTypeKind.ZodEnum})}var ZodFirstPartyTypeKind,ZodEnum=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype._parse=function(e){e=this._processInputParams(e).ctx;return-1===this._def.values.indexOf(e.data)?(addIssueToContext(e,{code:ZodIssueCode.invalid_enum_value,options:this._def.values}),INVALID):OK(e.data)},Object.defineProperty(t.prototype,"options",{get:function(){return this._def.values},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"enum",{get:function(){var t,e,r={};try{for(var n=__values(this._def.values),a=n.next();!a.done;a=n.next()){var o=a.value;r[o]=o}}catch(e){t={error:e}}finally{try{a&&!a.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}return r},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Values",{get:function(){var t,e,r={};try{for(var n=__values(this._def.values),a=n.next();!a.done;a=n.next()){var o=a.value;r[o]=o}}catch(e){t={error:e}}finally{try{a&&!a.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}return r},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Enum",{get:function(){var t,e,r={};try{for(var n=__values(this._def.values),a=n.next();!a.done;a=n.next()){var o=a.value;r[o]=o}}catch(e){t={error:e}}finally{try{a&&!a.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}return r},enumerable:!1,configurable:!0}),t.create=createZodEnum,t}(ZodType),ZodNativeEnum=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return __extends(r,e),r.prototype._parse=function(e){var t=this._processInputParams(e).ctx,e=util.getValidEnumValues(this._def.values);return-1===e.indexOf(t.data)?(addIssueToContext(t,{code:ZodIssueCode.invalid_enum_value,options:util.objectValues(e)}),INVALID):OK(t.data)},r.create=function(e,t){return new r(__assign({values:e,typeName:ZodFirstPartyTypeKind.ZodNativeEnum},processCreateParams(t)))},r}(ZodType),ZodPromise=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return __extends(r,e),r.prototype._parse=function(e){var t=this,r=this._processInputParams(e).ctx;if(r.parsedType!==ZodParsedType.promise&&!1===r.async)return addIssueToContext(r,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.promise,received:r.parsedType}),INVALID;e=r.parsedType===ZodParsedType.promise?r.data:Promise.resolve(r.data);return OK(e.then(function(e){return t._def.type.parseAsync(e,{path:r.path,errorMap:r.contextualErrorMap})}))},r.create=function(e,t){return new r(__assign({type:e,typeName:ZodFirstPartyTypeKind.ZodPromise},processCreateParams(t)))},r}(ZodType),ZodEffects=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.innerType=function(){return this._def.schema},n.prototype._parse=function(e){var t=this,e=this._processInputParams(e),r=e.status,n=e.ctx,a=this._def.effect||null;if("preprocess"===a.type){e=a.transform(n.data);return n.async?Promise.resolve(e).then(function(e){return t._def.schema._parseAsync({data:e,path:n.path,parent:n})}):this._def.schema._parseSync({data:e,path:n.path,parent:n})}if("refinement"===a.type){var o={addIssue:function(e){addIssueToContext(n,e),e.fatal?r.abort():r.dirty()},get path(){return n.path}};o.addIssue=o.addIssue.bind(o);function s(e){var t=a.refinement(e,o);if(n.async)return Promise.resolve(t);if(t instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e}if(!1!==n.async)return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(function(e){return"aborted"===e.status?INVALID:("dirty"===e.status&&r.dirty(),s(e.value).then(function(){return{status:r.value,value:e.value}}))});var i=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return"aborted"===i.status?INVALID:("dirty"===i.status&&r.dirty(),s(i.value),{status:r.value,value:i.value})}if("transform"===a.type){if(!1!==n.async)return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(function(e){return isValid(e)?Promise.resolve(a.transform(e.value)).then(OK):e});i=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!isValid(i))return i;i=a.transform(i.value);if(i instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return OK(i)}util.assertNever(a)},n.create=function(e,t,r){return new n(__assign({schema:e,typeName:ZodFirstPartyTypeKind.ZodEffects,effect:t},processCreateParams(r)))},n.createWithPreprocess=function(e,t,r){return new n(__assign({schema:t,effect:{type:"preprocess",transform:e},typeName:ZodFirstPartyTypeKind.ZodEffects},processCreateParams(r)))},n}(ZodType),ZodOptional=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return __extends(r,e),r.prototype._parse=function(e){e=this._processInputParams(e).ctx;return e.parsedType===ZodParsedType.undefined?OK(void 0):this._def.innerType._parse({data:e.data,path:e.path,parent:e})},r.prototype.unwrap=function(){return this._def.innerType},r.create=function(e,t){return new r(__assign({innerType:e,typeName:ZodFirstPartyTypeKind.ZodOptional},processCreateParams(t)))},r}(ZodType),ZodNullable=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return __extends(r,e),r.prototype._parse=function(e){e=this._processInputParams(e).ctx;return e.parsedType===ZodParsedType.null?OK(null):this._def.innerType._parse({data:e.data,path:e.path,parent:e})},r.prototype.unwrap=function(){return this._def.innerType},r.create=function(e,t){return new r(__assign({innerType:e,typeName:ZodFirstPartyTypeKind.ZodNullable},processCreateParams(t)))},r}(ZodType),ZodDefault=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype._parse=function(e){var t=this._processInputParams(e).ctx,e=t.data;return t.parsedType===ZodParsedType.undefined&&(e=this._def.defaultValue()),this._def.innerType._parse({data:e,path:t.path,parent:t})},t.prototype.removeDefault=function(){return this._def.innerType},t.create=function(e,t){return new ZodOptional(__assign({innerType:e,typeName:ZodFirstPartyTypeKind.ZodOptional},processCreateParams(t)))},t}(ZodType),custom=function(e,t){return e?ZodAny.create().refine(e,t):ZodAny.create()},late={object:ZodObject.lazycreate};!function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodPromise="ZodPromise"}(ZodFirstPartyTypeKind=ZodFirstPartyTypeKind||{});var instanceOfType=function(t,e){return void 0===e&&(e={message:"Input not instance of ".concat(t.name)}),custom(function(e){return e instanceof t},e)},stringType=ZodString.create,numberType=ZodNumber.create,bigIntType=ZodBigInt.create,booleanType=ZodBoolean.create,dateType=ZodDate.create,undefinedType=ZodUndefined.create,nullType=ZodNull.create,anyType=ZodAny.create,unknownType=ZodUnknown.create,neverType=ZodNever.create,voidType=ZodVoid.create,arrayType=ZodArray.create,objectType=ZodObject.create,strictObjectType=ZodObject.strictCreate,unionType=ZodUnion.create,discriminatedUnionType=ZodDiscriminatedUnion.create,intersectionType=ZodIntersection.create,tupleType=ZodTuple.create,recordType=ZodRecord.create,mapType=ZodMap.create,setType=ZodSet.create,functionType=ZodFunction.create,lazyType=ZodLazy.create,literalType=ZodLiteral.create,enumType=ZodEnum.create,nativeEnumType=ZodNativeEnum.create,promiseType=ZodPromise.create,effectsType=ZodEffects.create,optionalType=ZodOptional.create,nullableType=ZodNullable.create,preprocessType=ZodEffects.createWithPreprocess,ostring=function(){return stringType().optional()},onumber=function(){return numberType().optional()},oboolean=function(){return booleanType().optional()},external=Object.freeze({__proto__:null,ZodParsedType:ZodParsedType,getParsedType:getParsedType,makeIssue:makeIssue,EMPTY_PATH:EMPTY_PATH,addIssueToContext:addIssueToContext,ParseStatus:ParseStatus,INVALID:INVALID,DIRTY:DIRTY,OK:OK,isAborted:isAborted,isDirty:isDirty,isValid:isValid,isAsync:isAsync,ZodType:ZodType,ZodString:ZodString,ZodNumber:ZodNumber,ZodBigInt:ZodBigInt,ZodBoolean:ZodBoolean,ZodDate:ZodDate,ZodUndefined:ZodUndefined,ZodNull:ZodNull,ZodAny:ZodAny,ZodUnknown:ZodUnknown,ZodNever:ZodNever,ZodVoid:ZodVoid,ZodArray:ZodArray,get objectUtil(){return objectUtil},ZodObject:ZodObject,ZodUnion:ZodUnion,ZodDiscriminatedUnion:ZodDiscriminatedUnion,ZodIntersection:ZodIntersection,ZodTuple:ZodTuple,ZodRecord:ZodRecord,ZodMap:ZodMap,ZodSet:ZodSet,ZodFunction:ZodFunction,ZodLazy:ZodLazy,ZodLiteral:ZodLiteral,ZodEnum:ZodEnum,ZodNativeEnum:ZodNativeEnum,ZodPromise:ZodPromise,ZodEffects:ZodEffects,ZodTransformer:ZodEffects,ZodOptional:ZodOptional,ZodNullable:ZodNullable,ZodDefault:ZodDefault,custom:custom,Schema:ZodType,ZodSchema:ZodType,late:late,get ZodFirstPartyTypeKind(){return ZodFirstPartyTypeKind},any:anyType,array:arrayType,bigint:bigIntType,boolean:booleanType,date:dateType,discriminatedUnion:discriminatedUnionType,effect:effectsType,enum:enumType,function:functionType,instanceof:instanceOfType,intersection:intersectionType,lazy:lazyType,literal:literalType,map:mapType,nativeEnum:nativeEnumType,never:neverType,null:nullType,nullable:nullableType,number:numberType,object:objectType,oboolean:oboolean,onumber:onumber,optional:optionalType,ostring:ostring,preprocess:preprocessType,promise:promiseType,record:recordType,set:setType,strictObject:strictObjectType,string:stringType,transformer:effectsType,tuple:tupleType,undefined:undefinedType,union:unionType,unknown:unknownType,void:voidType,ZodIssueCode:ZodIssueCode,quotelessJson:quotelessJson,ZodError:ZodError,defaultErrorMap:defaultErrorMap,get overrideErrorMap(){return overrideErrorMap},setErrorMap:setErrorMap});export{DIRTY,EMPTY_PATH,INVALID,OK,ParseStatus,ZodType as Schema,ZodAny,ZodArray,ZodBigInt,ZodBoolean,ZodDate,ZodDefault,ZodDiscriminatedUnion,ZodEffects,ZodEnum,ZodError,ZodFirstPartyTypeKind,ZodFunction,ZodIntersection,ZodIssueCode,ZodLazy,ZodLiteral,ZodMap,ZodNativeEnum,ZodNever,ZodNull,ZodNullable,ZodNumber,ZodObject,ZodOptional,ZodParsedType,ZodPromise,ZodRecord,ZodType as ZodSchema,ZodSet,ZodString,ZodEffects as ZodTransformer,ZodTuple,ZodType,ZodUndefined,ZodUnion,ZodUnknown,ZodVoid,addIssueToContext,anyType as any,arrayType as array,bigIntType as bigint,booleanType as boolean,custom,dateType as date,defaultErrorMap,discriminatedUnionType as discriminatedUnion,effectsType as effect,enumType as enum,functionType as function,getParsedType,instanceOfType as instanceof,intersectionType as intersection,isAborted,isAsync,isDirty,isValid,late,lazyType as lazy,literalType as literal,makeIssue,mapType as map,nativeEnumType as nativeEnum,neverType as never,nullType as null,nullableType as nullable,numberType as number,objectType as object,objectUtil,oboolean,onumber,optionalType as optional,ostring,overrideErrorMap,preprocessType as preprocess,promiseType as promise,quotelessJson,recordType as record,setType as set,setErrorMap,strictObjectType as strictObject,stringType as string,effectsType as transformer,tupleType as tuple,undefinedType as undefined,unionType as union,unknownType as unknown,voidType as void,external as z};
|
|
2
|
-
|
|
1
|
+
/*! *****************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise */
|
|
16
|
+
|
|
17
|
+
var extendStatics = function(d, b) {
|
|
18
|
+
extendStatics = Object.setPrototypeOf ||
|
|
19
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
20
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
21
|
+
return extendStatics(d, b);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function __extends(d, b) {
|
|
25
|
+
if (typeof b !== "function" && b !== null)
|
|
26
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
27
|
+
extendStatics(d, b);
|
|
28
|
+
function __() { this.constructor = d; }
|
|
29
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var __assign = function() {
|
|
33
|
+
__assign = Object.assign || function __assign(t) {
|
|
34
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
35
|
+
s = arguments[i];
|
|
36
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
37
|
+
}
|
|
38
|
+
return t;
|
|
39
|
+
};
|
|
40
|
+
return __assign.apply(this, arguments);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
44
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
45
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
46
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
47
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
48
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
49
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function __generator(thisArg, body) {
|
|
54
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
55
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
56
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
57
|
+
function step(op) {
|
|
58
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
59
|
+
while (_) try {
|
|
60
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
61
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
62
|
+
switch (op[0]) {
|
|
63
|
+
case 0: case 1: t = op; break;
|
|
64
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
65
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
66
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
67
|
+
default:
|
|
68
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
69
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
70
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
71
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
72
|
+
if (t[2]) _.ops.pop();
|
|
73
|
+
_.trys.pop(); continue;
|
|
74
|
+
}
|
|
75
|
+
op = body.call(thisArg, _);
|
|
76
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
77
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function __values(o) {
|
|
82
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
83
|
+
if (m) return m.call(o);
|
|
84
|
+
if (o && typeof o.length === "number") return {
|
|
85
|
+
next: function () {
|
|
86
|
+
if (o && i >= o.length) o = void 0;
|
|
87
|
+
return { value: o && o[i++], done: !o };
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function __read(o, n) {
|
|
94
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
95
|
+
if (!m) return o;
|
|
96
|
+
var i = m.call(o), r, ar = [], e;
|
|
97
|
+
try {
|
|
98
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
99
|
+
}
|
|
100
|
+
catch (error) { e = { error: error }; }
|
|
101
|
+
finally {
|
|
102
|
+
try {
|
|
103
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
104
|
+
}
|
|
105
|
+
finally { if (e) throw e.error; }
|
|
106
|
+
}
|
|
107
|
+
return ar;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function __spreadArray(to, from, pack) {
|
|
111
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
112
|
+
if (ar || !(i in from)) {
|
|
113
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
114
|
+
ar[i] = from[i];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
var util;
|
|
121
|
+
(function (util) {
|
|
122
|
+
function assertNever(_x) {
|
|
123
|
+
throw new Error();
|
|
124
|
+
}
|
|
125
|
+
util.assertNever = assertNever;
|
|
126
|
+
util.arrayToEnum = function (items) {
|
|
127
|
+
var e_1, _a;
|
|
128
|
+
var obj = {};
|
|
129
|
+
try {
|
|
130
|
+
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
131
|
+
var item = items_1_1.value;
|
|
132
|
+
obj[item] = item;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
136
|
+
finally {
|
|
137
|
+
try {
|
|
138
|
+
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
139
|
+
}
|
|
140
|
+
finally { if (e_1) throw e_1.error; }
|
|
141
|
+
}
|
|
142
|
+
return obj;
|
|
143
|
+
};
|
|
144
|
+
util.getValidEnumValues = function (obj) {
|
|
145
|
+
var e_2, _a;
|
|
146
|
+
var validKeys = util.objectKeys(obj).filter(function (k) { return typeof obj[obj[k]] !== "number"; });
|
|
147
|
+
var filtered = {};
|
|
148
|
+
try {
|
|
149
|
+
for (var validKeys_1 = __values(validKeys), validKeys_1_1 = validKeys_1.next(); !validKeys_1_1.done; validKeys_1_1 = validKeys_1.next()) {
|
|
150
|
+
var k = validKeys_1_1.value;
|
|
151
|
+
filtered[k] = obj[k];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
155
|
+
finally {
|
|
156
|
+
try {
|
|
157
|
+
if (validKeys_1_1 && !validKeys_1_1.done && (_a = validKeys_1.return)) _a.call(validKeys_1);
|
|
158
|
+
}
|
|
159
|
+
finally { if (e_2) throw e_2.error; }
|
|
160
|
+
}
|
|
161
|
+
return util.objectValues(filtered);
|
|
162
|
+
};
|
|
163
|
+
util.objectValues = function (obj) {
|
|
164
|
+
return util.objectKeys(obj).map(function (e) {
|
|
165
|
+
return obj[e];
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
|
|
169
|
+
? function (obj) { return Object.keys(obj); } // eslint-disable-line ban/ban
|
|
170
|
+
: function (object) {
|
|
171
|
+
var keys = [];
|
|
172
|
+
for (var key in object) {
|
|
173
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
174
|
+
keys.push(key);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return keys;
|
|
178
|
+
};
|
|
179
|
+
util.find = function (arr, checker) {
|
|
180
|
+
var e_3, _a;
|
|
181
|
+
try {
|
|
182
|
+
for (var arr_1 = __values(arr), arr_1_1 = arr_1.next(); !arr_1_1.done; arr_1_1 = arr_1.next()) {
|
|
183
|
+
var item = arr_1_1.value;
|
|
184
|
+
if (checker(item))
|
|
185
|
+
return item;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
189
|
+
finally {
|
|
190
|
+
try {
|
|
191
|
+
if (arr_1_1 && !arr_1_1.done && (_a = arr_1.return)) _a.call(arr_1);
|
|
192
|
+
}
|
|
193
|
+
finally { if (e_3) throw e_3.error; }
|
|
194
|
+
}
|
|
195
|
+
return undefined;
|
|
196
|
+
};
|
|
197
|
+
util.isInteger = typeof Number.isInteger === "function"
|
|
198
|
+
? function (val) { return Number.isInteger(val); } // eslint-disable-line ban/ban
|
|
199
|
+
: function (val) {
|
|
200
|
+
return typeof val === "number" && isFinite(val) && Math.floor(val) === val;
|
|
201
|
+
};
|
|
202
|
+
})(util || (util = {}));
|
|
203
|
+
|
|
204
|
+
var ZodIssueCode = util.arrayToEnum([
|
|
205
|
+
"invalid_type",
|
|
206
|
+
"custom",
|
|
207
|
+
"invalid_union",
|
|
208
|
+
"invalid_union_discriminator",
|
|
209
|
+
"invalid_enum_value",
|
|
210
|
+
"unrecognized_keys",
|
|
211
|
+
"invalid_arguments",
|
|
212
|
+
"invalid_return_type",
|
|
213
|
+
"invalid_date",
|
|
214
|
+
"invalid_string",
|
|
215
|
+
"too_small",
|
|
216
|
+
"too_big",
|
|
217
|
+
"invalid_intersection_types",
|
|
218
|
+
"not_multiple_of",
|
|
219
|
+
]);
|
|
220
|
+
var quotelessJson = function (obj) {
|
|
221
|
+
var json = JSON.stringify(obj, null, 2);
|
|
222
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
223
|
+
};
|
|
224
|
+
var ZodError = /** @class */ (function (_super) {
|
|
225
|
+
__extends(ZodError, _super);
|
|
226
|
+
function ZodError(issues) {
|
|
227
|
+
var _newTarget = this.constructor;
|
|
228
|
+
var _this = _super.call(this) || this;
|
|
229
|
+
_this.issues = [];
|
|
230
|
+
_this.format = function () {
|
|
231
|
+
var fieldErrors = { _errors: [] };
|
|
232
|
+
var processError = function (error) {
|
|
233
|
+
var e_1, _a;
|
|
234
|
+
try {
|
|
235
|
+
for (var _b = __values(error.issues), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
236
|
+
var issue = _c.value;
|
|
237
|
+
if (issue.code === "invalid_union") {
|
|
238
|
+
issue.unionErrors.map(processError);
|
|
239
|
+
}
|
|
240
|
+
else if (issue.code === "invalid_return_type") {
|
|
241
|
+
processError(issue.returnTypeError);
|
|
242
|
+
}
|
|
243
|
+
else if (issue.code === "invalid_arguments") {
|
|
244
|
+
processError(issue.argumentsError);
|
|
245
|
+
}
|
|
246
|
+
else if (issue.path.length === 0) {
|
|
247
|
+
fieldErrors._errors.push(issue.message);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
var curr = fieldErrors;
|
|
251
|
+
var i = 0;
|
|
252
|
+
while (i < issue.path.length) {
|
|
253
|
+
var el = issue.path[i];
|
|
254
|
+
var terminal = i === issue.path.length - 1;
|
|
255
|
+
if (!terminal) {
|
|
256
|
+
if (typeof el === "string") {
|
|
257
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
258
|
+
}
|
|
259
|
+
else if (typeof el === "number") {
|
|
260
|
+
var errorArray = [];
|
|
261
|
+
errorArray._errors = [];
|
|
262
|
+
curr[el] = curr[el] || errorArray;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
267
|
+
curr[el]._errors.push(issue.message);
|
|
268
|
+
}
|
|
269
|
+
curr = curr[el];
|
|
270
|
+
i++;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
276
|
+
finally {
|
|
277
|
+
try {
|
|
278
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
279
|
+
}
|
|
280
|
+
finally { if (e_1) throw e_1.error; }
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
processError(_this);
|
|
284
|
+
return fieldErrors;
|
|
285
|
+
};
|
|
286
|
+
_this.addIssue = function (sub) {
|
|
287
|
+
_this.issues = __spreadArray(__spreadArray([], __read(_this.issues), false), [sub], false);
|
|
288
|
+
};
|
|
289
|
+
_this.addIssues = function (subs) {
|
|
290
|
+
if (subs === void 0) { subs = []; }
|
|
291
|
+
_this.issues = __spreadArray(__spreadArray([], __read(_this.issues), false), __read(subs), false);
|
|
292
|
+
};
|
|
293
|
+
var actualProto = _newTarget.prototype;
|
|
294
|
+
if (Object.setPrototypeOf) {
|
|
295
|
+
// eslint-disable-next-line ban/ban
|
|
296
|
+
Object.setPrototypeOf(_this, actualProto);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
_this.__proto__ = actualProto;
|
|
300
|
+
}
|
|
301
|
+
_this.name = "ZodError";
|
|
302
|
+
_this.issues = issues;
|
|
303
|
+
return _this;
|
|
304
|
+
}
|
|
305
|
+
Object.defineProperty(ZodError.prototype, "errors", {
|
|
306
|
+
get: function () {
|
|
307
|
+
return this.issues;
|
|
308
|
+
},
|
|
309
|
+
enumerable: false,
|
|
310
|
+
configurable: true
|
|
311
|
+
});
|
|
312
|
+
ZodError.prototype.toString = function () {
|
|
313
|
+
return this.message;
|
|
314
|
+
};
|
|
315
|
+
Object.defineProperty(ZodError.prototype, "message", {
|
|
316
|
+
get: function () {
|
|
317
|
+
return JSON.stringify(this.issues, null, 2);
|
|
318
|
+
},
|
|
319
|
+
enumerable: false,
|
|
320
|
+
configurable: true
|
|
321
|
+
});
|
|
322
|
+
Object.defineProperty(ZodError.prototype, "isEmpty", {
|
|
323
|
+
get: function () {
|
|
324
|
+
return this.issues.length === 0;
|
|
325
|
+
},
|
|
326
|
+
enumerable: false,
|
|
327
|
+
configurable: true
|
|
328
|
+
});
|
|
329
|
+
ZodError.prototype.flatten = function (mapper) {
|
|
330
|
+
var e_2, _a;
|
|
331
|
+
if (mapper === void 0) { mapper = function (issue) { return issue.message; }; }
|
|
332
|
+
var fieldErrors = {};
|
|
333
|
+
var formErrors = [];
|
|
334
|
+
try {
|
|
335
|
+
for (var _b = __values(this.issues), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
336
|
+
var sub = _c.value;
|
|
337
|
+
if (sub.path.length > 0) {
|
|
338
|
+
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
339
|
+
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
formErrors.push(mapper(sub));
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
347
|
+
finally {
|
|
348
|
+
try {
|
|
349
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
350
|
+
}
|
|
351
|
+
finally { if (e_2) throw e_2.error; }
|
|
352
|
+
}
|
|
353
|
+
return { formErrors: formErrors, fieldErrors: fieldErrors };
|
|
354
|
+
};
|
|
355
|
+
Object.defineProperty(ZodError.prototype, "formErrors", {
|
|
356
|
+
get: function () {
|
|
357
|
+
return this.flatten();
|
|
358
|
+
},
|
|
359
|
+
enumerable: false,
|
|
360
|
+
configurable: true
|
|
361
|
+
});
|
|
362
|
+
ZodError.create = function (issues) {
|
|
363
|
+
var error = new ZodError(issues);
|
|
364
|
+
return error;
|
|
365
|
+
};
|
|
366
|
+
return ZodError;
|
|
367
|
+
}(Error));
|
|
368
|
+
var defaultErrorMap = function (issue, _ctx) {
|
|
369
|
+
var message;
|
|
370
|
+
switch (issue.code) {
|
|
371
|
+
case ZodIssueCode.invalid_type:
|
|
372
|
+
if (issue.received === "undefined") {
|
|
373
|
+
message = "Required";
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
message = "Expected ".concat(issue.expected, ", received ").concat(issue.received);
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
case ZodIssueCode.unrecognized_keys:
|
|
380
|
+
message = "Unrecognized key(s) in object: ".concat(issue.keys
|
|
381
|
+
.map(function (k) { return "'".concat(k, "'"); })
|
|
382
|
+
.join(", "));
|
|
383
|
+
break;
|
|
384
|
+
case ZodIssueCode.invalid_union:
|
|
385
|
+
message = "Invalid input";
|
|
386
|
+
break;
|
|
387
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
388
|
+
message = "Invalid discriminator value. Expected ".concat(issue.options
|
|
389
|
+
.map(function (val) { return (typeof val === "string" ? "'".concat(val, "'") : val); })
|
|
390
|
+
.join(" | "));
|
|
391
|
+
break;
|
|
392
|
+
case ZodIssueCode.invalid_enum_value:
|
|
393
|
+
message = "Invalid enum value. Expected ".concat(issue.options
|
|
394
|
+
.map(function (val) { return (typeof val === "string" ? "'".concat(val, "'") : val); })
|
|
395
|
+
.join(" | "));
|
|
396
|
+
break;
|
|
397
|
+
case ZodIssueCode.invalid_arguments:
|
|
398
|
+
message = "Invalid function arguments";
|
|
399
|
+
break;
|
|
400
|
+
case ZodIssueCode.invalid_return_type:
|
|
401
|
+
message = "Invalid function return type";
|
|
402
|
+
break;
|
|
403
|
+
case ZodIssueCode.invalid_date:
|
|
404
|
+
message = "Invalid date";
|
|
405
|
+
break;
|
|
406
|
+
case ZodIssueCode.invalid_string:
|
|
407
|
+
if (issue.validation !== "regex")
|
|
408
|
+
message = "Invalid ".concat(issue.validation);
|
|
409
|
+
else
|
|
410
|
+
message = "Invalid";
|
|
411
|
+
break;
|
|
412
|
+
case ZodIssueCode.too_small:
|
|
413
|
+
if (issue.type === "array")
|
|
414
|
+
message = "Array must contain ".concat(issue.inclusive ? "at least" : "more than", " ").concat(issue.minimum, " element(s)");
|
|
415
|
+
else if (issue.type === "string")
|
|
416
|
+
message = "String must contain ".concat(issue.inclusive ? "at least" : "over", " ").concat(issue.minimum, " character(s)");
|
|
417
|
+
else if (issue.type === "number")
|
|
418
|
+
message = "Number must be greater than ".concat(issue.inclusive ? "or equal to " : "").concat(issue.minimum);
|
|
419
|
+
else
|
|
420
|
+
message = "Invalid input";
|
|
421
|
+
break;
|
|
422
|
+
case ZodIssueCode.too_big:
|
|
423
|
+
if (issue.type === "array")
|
|
424
|
+
message = "Array must contain ".concat(issue.inclusive ? "at most" : "less than", " ").concat(issue.maximum, " element(s)");
|
|
425
|
+
else if (issue.type === "string")
|
|
426
|
+
message = "String must contain ".concat(issue.inclusive ? "at most" : "under", " ").concat(issue.maximum, " character(s)");
|
|
427
|
+
else if (issue.type === "number")
|
|
428
|
+
message = "Number must be less than ".concat(issue.inclusive ? "or equal to " : "").concat(issue.maximum);
|
|
429
|
+
else
|
|
430
|
+
message = "Invalid input";
|
|
431
|
+
break;
|
|
432
|
+
case ZodIssueCode.custom:
|
|
433
|
+
message = "Invalid input";
|
|
434
|
+
break;
|
|
435
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
436
|
+
message = "Intersection results could not be merged";
|
|
437
|
+
break;
|
|
438
|
+
case ZodIssueCode.not_multiple_of:
|
|
439
|
+
message = "Number must be a multiple of ".concat(issue.multipleOf);
|
|
440
|
+
break;
|
|
441
|
+
default:
|
|
442
|
+
message = _ctx.defaultError;
|
|
443
|
+
util.assertNever(issue);
|
|
444
|
+
}
|
|
445
|
+
return { message: message };
|
|
446
|
+
};
|
|
447
|
+
var overrideErrorMap = defaultErrorMap;
|
|
448
|
+
var setErrorMap = function (map) {
|
|
449
|
+
overrideErrorMap = map;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
var ZodParsedType = util.arrayToEnum([
|
|
453
|
+
"string",
|
|
454
|
+
"nan",
|
|
455
|
+
"number",
|
|
456
|
+
"integer",
|
|
457
|
+
"float",
|
|
458
|
+
"boolean",
|
|
459
|
+
"date",
|
|
460
|
+
"bigint",
|
|
461
|
+
"symbol",
|
|
462
|
+
"function",
|
|
463
|
+
"undefined",
|
|
464
|
+
"null",
|
|
465
|
+
"array",
|
|
466
|
+
"object",
|
|
467
|
+
"unknown",
|
|
468
|
+
"promise",
|
|
469
|
+
"void",
|
|
470
|
+
"never",
|
|
471
|
+
"map",
|
|
472
|
+
"set",
|
|
473
|
+
]);
|
|
474
|
+
function cacheAndReturn(data, parsedType, cache) {
|
|
475
|
+
if (cache)
|
|
476
|
+
cache.set(data, parsedType);
|
|
477
|
+
return parsedType;
|
|
478
|
+
}
|
|
479
|
+
var getParsedType = function (data, cache) {
|
|
480
|
+
if (cache && cache.has(data))
|
|
481
|
+
return cache.get(data);
|
|
482
|
+
var t = typeof data;
|
|
483
|
+
switch (t) {
|
|
484
|
+
case "undefined":
|
|
485
|
+
return cacheAndReturn(data, ZodParsedType.undefined, cache);
|
|
486
|
+
case "string":
|
|
487
|
+
return cacheAndReturn(data, ZodParsedType.string, cache);
|
|
488
|
+
case "number":
|
|
489
|
+
return cacheAndReturn(data, isNaN(data) ? ZodParsedType.nan : ZodParsedType.number, cache);
|
|
490
|
+
case "boolean":
|
|
491
|
+
return cacheAndReturn(data, ZodParsedType.boolean, cache);
|
|
492
|
+
case "function":
|
|
493
|
+
return cacheAndReturn(data, ZodParsedType.function, cache);
|
|
494
|
+
case "bigint":
|
|
495
|
+
return cacheAndReturn(data, ZodParsedType.bigint, cache);
|
|
496
|
+
case "object":
|
|
497
|
+
if (Array.isArray(data)) {
|
|
498
|
+
return cacheAndReturn(data, ZodParsedType.array, cache);
|
|
499
|
+
}
|
|
500
|
+
if (data === null) {
|
|
501
|
+
return cacheAndReturn(data, ZodParsedType.null, cache);
|
|
502
|
+
}
|
|
503
|
+
if (data.then &&
|
|
504
|
+
typeof data.then === "function" &&
|
|
505
|
+
data.catch &&
|
|
506
|
+
typeof data.catch === "function") {
|
|
507
|
+
return cacheAndReturn(data, ZodParsedType.promise, cache);
|
|
508
|
+
}
|
|
509
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
510
|
+
return cacheAndReturn(data, ZodParsedType.map, cache);
|
|
511
|
+
}
|
|
512
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
513
|
+
return cacheAndReturn(data, ZodParsedType.set, cache);
|
|
514
|
+
}
|
|
515
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
516
|
+
return cacheAndReturn(data, ZodParsedType.date, cache);
|
|
517
|
+
}
|
|
518
|
+
return cacheAndReturn(data, ZodParsedType.object, cache);
|
|
519
|
+
default:
|
|
520
|
+
return cacheAndReturn(data, ZodParsedType.unknown, cache);
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
var makeIssue = function (params) {
|
|
524
|
+
var e_1, _a;
|
|
525
|
+
var data = params.data, path = params.path, errorMaps = params.errorMaps, issueData = params.issueData;
|
|
526
|
+
var fullPath = __spreadArray(__spreadArray([], __read(path), false), __read((issueData.path || [])), false);
|
|
527
|
+
var fullIssue = __assign(__assign({}, issueData), { path: fullPath });
|
|
528
|
+
var errorMessage = "";
|
|
529
|
+
var maps = errorMaps
|
|
530
|
+
.filter(function (m) { return !!m; })
|
|
531
|
+
.slice()
|
|
532
|
+
.reverse();
|
|
533
|
+
try {
|
|
534
|
+
for (var maps_1 = __values(maps), maps_1_1 = maps_1.next(); !maps_1_1.done; maps_1_1 = maps_1.next()) {
|
|
535
|
+
var map = maps_1_1.value;
|
|
536
|
+
errorMessage = map(fullIssue, { data: data, defaultError: errorMessage }).message;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
540
|
+
finally {
|
|
541
|
+
try {
|
|
542
|
+
if (maps_1_1 && !maps_1_1.done && (_a = maps_1.return)) _a.call(maps_1);
|
|
543
|
+
}
|
|
544
|
+
finally { if (e_1) throw e_1.error; }
|
|
545
|
+
}
|
|
546
|
+
return __assign(__assign({}, issueData), { path: fullPath, message: issueData.message || errorMessage });
|
|
547
|
+
};
|
|
548
|
+
var EMPTY_PATH = [];
|
|
549
|
+
function addIssueToContext(ctx, issueData) {
|
|
550
|
+
var issue = makeIssue({
|
|
551
|
+
issueData: issueData,
|
|
552
|
+
data: ctx.data,
|
|
553
|
+
path: ctx.path,
|
|
554
|
+
errorMaps: [
|
|
555
|
+
ctx.contextualErrorMap,
|
|
556
|
+
ctx.schemaErrorMap,
|
|
557
|
+
overrideErrorMap,
|
|
558
|
+
defaultErrorMap, // then global default map
|
|
559
|
+
].filter(function (x) { return !!x; }),
|
|
560
|
+
});
|
|
561
|
+
ctx.issues.push(issue);
|
|
562
|
+
}
|
|
563
|
+
var ParseStatus = /** @class */ (function () {
|
|
564
|
+
function ParseStatus() {
|
|
565
|
+
this.value = "valid";
|
|
566
|
+
}
|
|
567
|
+
ParseStatus.prototype.dirty = function () {
|
|
568
|
+
if (this.value === "valid")
|
|
569
|
+
this.value = "dirty";
|
|
570
|
+
};
|
|
571
|
+
ParseStatus.prototype.abort = function () {
|
|
572
|
+
if (this.value !== "aborted")
|
|
573
|
+
this.value = "aborted";
|
|
574
|
+
};
|
|
575
|
+
ParseStatus.mergeArray = function (status, results) {
|
|
576
|
+
var e_2, _a;
|
|
577
|
+
var arrayValue = [];
|
|
578
|
+
try {
|
|
579
|
+
for (var results_1 = __values(results), results_1_1 = results_1.next(); !results_1_1.done; results_1_1 = results_1.next()) {
|
|
580
|
+
var s = results_1_1.value;
|
|
581
|
+
if (s.status === "aborted")
|
|
582
|
+
return INVALID;
|
|
583
|
+
if (s.status === "dirty")
|
|
584
|
+
status.dirty();
|
|
585
|
+
arrayValue.push(s.value);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
589
|
+
finally {
|
|
590
|
+
try {
|
|
591
|
+
if (results_1_1 && !results_1_1.done && (_a = results_1.return)) _a.call(results_1);
|
|
592
|
+
}
|
|
593
|
+
finally { if (e_2) throw e_2.error; }
|
|
594
|
+
}
|
|
595
|
+
return { status: status.value, value: arrayValue };
|
|
596
|
+
};
|
|
597
|
+
ParseStatus.mergeObjectAsync = function (status, pairs) {
|
|
598
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
599
|
+
var syncPairs, pairs_1, pairs_1_1, pair, _a, _b, e_3_1;
|
|
600
|
+
var e_3, _c, _d;
|
|
601
|
+
return __generator(this, function (_e) {
|
|
602
|
+
switch (_e.label) {
|
|
603
|
+
case 0:
|
|
604
|
+
syncPairs = [];
|
|
605
|
+
_e.label = 1;
|
|
606
|
+
case 1:
|
|
607
|
+
_e.trys.push([1, 7, 8, 9]);
|
|
608
|
+
pairs_1 = __values(pairs), pairs_1_1 = pairs_1.next();
|
|
609
|
+
_e.label = 2;
|
|
610
|
+
case 2:
|
|
611
|
+
if (!!pairs_1_1.done) return [3 /*break*/, 6];
|
|
612
|
+
pair = pairs_1_1.value;
|
|
613
|
+
_b = (_a = syncPairs).push;
|
|
614
|
+
_d = {};
|
|
615
|
+
return [4 /*yield*/, pair.key];
|
|
616
|
+
case 3:
|
|
617
|
+
_d.key = _e.sent();
|
|
618
|
+
return [4 /*yield*/, pair.value];
|
|
619
|
+
case 4:
|
|
620
|
+
_b.apply(_a, [(_d.value = _e.sent(),
|
|
621
|
+
_d)]);
|
|
622
|
+
_e.label = 5;
|
|
623
|
+
case 5:
|
|
624
|
+
pairs_1_1 = pairs_1.next();
|
|
625
|
+
return [3 /*break*/, 2];
|
|
626
|
+
case 6: return [3 /*break*/, 9];
|
|
627
|
+
case 7:
|
|
628
|
+
e_3_1 = _e.sent();
|
|
629
|
+
e_3 = { error: e_3_1 };
|
|
630
|
+
return [3 /*break*/, 9];
|
|
631
|
+
case 8:
|
|
632
|
+
try {
|
|
633
|
+
if (pairs_1_1 && !pairs_1_1.done && (_c = pairs_1.return)) _c.call(pairs_1);
|
|
634
|
+
}
|
|
635
|
+
finally { if (e_3) throw e_3.error; }
|
|
636
|
+
return [7 /*endfinally*/];
|
|
637
|
+
case 9: return [2 /*return*/, ParseStatus.mergeObjectSync(status, syncPairs)];
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
});
|
|
641
|
+
};
|
|
642
|
+
ParseStatus.mergeObjectSync = function (status, pairs) {
|
|
643
|
+
var e_4, _a;
|
|
644
|
+
var finalObject = {};
|
|
645
|
+
try {
|
|
646
|
+
for (var pairs_2 = __values(pairs), pairs_2_1 = pairs_2.next(); !pairs_2_1.done; pairs_2_1 = pairs_2.next()) {
|
|
647
|
+
var pair = pairs_2_1.value;
|
|
648
|
+
var key = pair.key, value = pair.value;
|
|
649
|
+
if (key.status === "aborted")
|
|
650
|
+
return INVALID;
|
|
651
|
+
if (value.status === "aborted")
|
|
652
|
+
return INVALID;
|
|
653
|
+
if (key.status === "dirty")
|
|
654
|
+
status.dirty();
|
|
655
|
+
if (value.status === "dirty")
|
|
656
|
+
status.dirty();
|
|
657
|
+
if (typeof value.value !== "undefined" || pair.alwaysSet) {
|
|
658
|
+
finalObject[key.value] = value.value;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
663
|
+
finally {
|
|
664
|
+
try {
|
|
665
|
+
if (pairs_2_1 && !pairs_2_1.done && (_a = pairs_2.return)) _a.call(pairs_2);
|
|
666
|
+
}
|
|
667
|
+
finally { if (e_4) throw e_4.error; }
|
|
668
|
+
}
|
|
669
|
+
return { status: status.value, value: finalObject };
|
|
670
|
+
};
|
|
671
|
+
return ParseStatus;
|
|
672
|
+
}());
|
|
673
|
+
var INVALID = Object.freeze({
|
|
674
|
+
status: "aborted",
|
|
675
|
+
});
|
|
676
|
+
var DIRTY = function (value) { return ({ status: "dirty", value: value }); };
|
|
677
|
+
var OK = function (value) { return ({ status: "valid", value: value }); };
|
|
678
|
+
var isAborted = function (x) {
|
|
679
|
+
return x.status === "aborted";
|
|
680
|
+
};
|
|
681
|
+
var isDirty = function (x) {
|
|
682
|
+
return x.status === "dirty";
|
|
683
|
+
};
|
|
684
|
+
var isValid = function (x) {
|
|
685
|
+
return x.status === "valid";
|
|
686
|
+
};
|
|
687
|
+
var isAsync = function (x) {
|
|
688
|
+
return typeof Promise !== undefined && x instanceof Promise;
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
var errorUtil;
|
|
692
|
+
(function (errorUtil) {
|
|
693
|
+
errorUtil.errToObj = function (message) {
|
|
694
|
+
return typeof message === "string" ? { message: message } : message || {};
|
|
695
|
+
};
|
|
696
|
+
errorUtil.toString = function (message) {
|
|
697
|
+
return typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
698
|
+
};
|
|
699
|
+
})(errorUtil || (errorUtil = {}));
|
|
700
|
+
|
|
701
|
+
var handleResult = function (ctx, result) {
|
|
702
|
+
if (isValid(result)) {
|
|
703
|
+
return { success: true, data: result.value };
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
if (!ctx.issues.length) {
|
|
707
|
+
throw new Error("Validation failed but no issues detected.");
|
|
708
|
+
}
|
|
709
|
+
var error = new ZodError(ctx.issues);
|
|
710
|
+
return { success: false, error: error };
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
function processCreateParams(params) {
|
|
714
|
+
if (!params)
|
|
715
|
+
return {};
|
|
716
|
+
var errorMap = params.errorMap, invalid_type_error = params.invalid_type_error, required_error = params.required_error, description = params.description;
|
|
717
|
+
if (errorMap && (invalid_type_error || required_error)) {
|
|
718
|
+
throw new Error("Can't use \"invalid\" or \"required\" in conjunction with custom error map.");
|
|
719
|
+
}
|
|
720
|
+
if (errorMap)
|
|
721
|
+
return { errorMap: errorMap, description: description };
|
|
722
|
+
var customMap = function (iss, ctx) {
|
|
723
|
+
if (iss.code !== "invalid_type")
|
|
724
|
+
return { message: ctx.defaultError };
|
|
725
|
+
if (typeof ctx.data === "undefined" && required_error)
|
|
726
|
+
return { message: required_error };
|
|
727
|
+
if (params.invalid_type_error)
|
|
728
|
+
return { message: params.invalid_type_error };
|
|
729
|
+
return { message: ctx.defaultError };
|
|
730
|
+
};
|
|
731
|
+
return { errorMap: customMap, description: description };
|
|
732
|
+
}
|
|
733
|
+
var ZodType = /** @class */ (function () {
|
|
734
|
+
function ZodType(def) {
|
|
735
|
+
/** Alias of safeParseAsync */
|
|
736
|
+
this.spa = this.safeParseAsync;
|
|
737
|
+
this.superRefine = this._refinement;
|
|
738
|
+
this._def = def;
|
|
739
|
+
this.parse = this.parse.bind(this);
|
|
740
|
+
this.safeParse = this.safeParse.bind(this);
|
|
741
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
742
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
743
|
+
this.spa = this.spa.bind(this);
|
|
744
|
+
this.refine = this.refine.bind(this);
|
|
745
|
+
this.refinement = this.refinement.bind(this);
|
|
746
|
+
this.superRefine = this.superRefine.bind(this);
|
|
747
|
+
this.optional = this.optional.bind(this);
|
|
748
|
+
this.nullable = this.nullable.bind(this);
|
|
749
|
+
this.nullish = this.nullish.bind(this);
|
|
750
|
+
this.array = this.array.bind(this);
|
|
751
|
+
this.promise = this.promise.bind(this);
|
|
752
|
+
this.or = this.or.bind(this);
|
|
753
|
+
this.and = this.and.bind(this);
|
|
754
|
+
this.transform = this.transform.bind(this);
|
|
755
|
+
this.default = this.default.bind(this);
|
|
756
|
+
this.describe = this.describe.bind(this);
|
|
757
|
+
this.isOptional = this.isOptional.bind(this);
|
|
758
|
+
this.isNullable = this.isNullable.bind(this);
|
|
759
|
+
}
|
|
760
|
+
Object.defineProperty(ZodType.prototype, "description", {
|
|
761
|
+
get: function () {
|
|
762
|
+
return this._def.description;
|
|
763
|
+
},
|
|
764
|
+
enumerable: false,
|
|
765
|
+
configurable: true
|
|
766
|
+
});
|
|
767
|
+
ZodType.prototype._processInputParams = function (input) {
|
|
768
|
+
return {
|
|
769
|
+
status: new ParseStatus(),
|
|
770
|
+
ctx: __assign(__assign({}, input.parent), { data: input.data, parsedType: getParsedType(input.data, input.parent.typeCache), schemaErrorMap: this._def.errorMap, path: input.path, parent: input.parent }),
|
|
771
|
+
};
|
|
772
|
+
};
|
|
773
|
+
ZodType.prototype._parseSync = function (input) {
|
|
774
|
+
var result = this._parse(input);
|
|
775
|
+
if (isAsync(result)) {
|
|
776
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
777
|
+
}
|
|
778
|
+
return result;
|
|
779
|
+
};
|
|
780
|
+
ZodType.prototype._parseAsync = function (input) {
|
|
781
|
+
var result = this._parse(input);
|
|
782
|
+
return Promise.resolve(result);
|
|
783
|
+
};
|
|
784
|
+
ZodType.prototype.parse = function (data, params) {
|
|
785
|
+
var result = this.safeParse(data, params);
|
|
786
|
+
if (result.success)
|
|
787
|
+
return result.data;
|
|
788
|
+
throw result.error;
|
|
789
|
+
};
|
|
790
|
+
ZodType.prototype.safeParse = function (data, params) {
|
|
791
|
+
var _a;
|
|
792
|
+
var ctx = {
|
|
793
|
+
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
794
|
+
issues: [],
|
|
795
|
+
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
796
|
+
schemaErrorMap: this._def.errorMap,
|
|
797
|
+
async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
|
|
798
|
+
typeCache: typeof Map !== "undefined" ? new Map() : undefined,
|
|
799
|
+
parent: null,
|
|
800
|
+
data: data,
|
|
801
|
+
parsedType: getParsedType(data),
|
|
802
|
+
};
|
|
803
|
+
var result = this._parseSync({ data: data, path: ctx.path, parent: ctx });
|
|
804
|
+
return handleResult(ctx, result);
|
|
805
|
+
};
|
|
806
|
+
ZodType.prototype.parseAsync = function (data, params) {
|
|
807
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
808
|
+
var result;
|
|
809
|
+
return __generator(this, function (_a) {
|
|
810
|
+
switch (_a.label) {
|
|
811
|
+
case 0: return [4 /*yield*/, this.safeParseAsync(data, params)];
|
|
812
|
+
case 1:
|
|
813
|
+
result = _a.sent();
|
|
814
|
+
if (result.success)
|
|
815
|
+
return [2 /*return*/, result.data];
|
|
816
|
+
throw result.error;
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
});
|
|
820
|
+
};
|
|
821
|
+
ZodType.prototype.safeParseAsync = function (data, params) {
|
|
822
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
823
|
+
var ctx, maybeAsyncResult, result;
|
|
824
|
+
return __generator(this, function (_a) {
|
|
825
|
+
switch (_a.label) {
|
|
826
|
+
case 0:
|
|
827
|
+
ctx = {
|
|
828
|
+
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
829
|
+
issues: [],
|
|
830
|
+
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
831
|
+
schemaErrorMap: this._def.errorMap,
|
|
832
|
+
async: true,
|
|
833
|
+
typeCache: typeof Map !== "undefined" ? new Map() : undefined,
|
|
834
|
+
parent: null,
|
|
835
|
+
data: data,
|
|
836
|
+
parsedType: getParsedType(data),
|
|
837
|
+
};
|
|
838
|
+
maybeAsyncResult = this._parse({ data: data, path: [], parent: ctx });
|
|
839
|
+
return [4 /*yield*/, (isAsync(maybeAsyncResult)
|
|
840
|
+
? maybeAsyncResult
|
|
841
|
+
: Promise.resolve(maybeAsyncResult))];
|
|
842
|
+
case 1:
|
|
843
|
+
result = _a.sent();
|
|
844
|
+
return [2 /*return*/, handleResult(ctx, result)];
|
|
845
|
+
}
|
|
846
|
+
});
|
|
847
|
+
});
|
|
848
|
+
};
|
|
849
|
+
ZodType.prototype.refine = function (check, message) {
|
|
850
|
+
var getIssueProperties = function (val) {
|
|
851
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
852
|
+
return { message: message };
|
|
853
|
+
}
|
|
854
|
+
else if (typeof message === "function") {
|
|
855
|
+
return message(val);
|
|
856
|
+
}
|
|
857
|
+
else {
|
|
858
|
+
return message;
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
return this._refinement(function (val, ctx) {
|
|
862
|
+
var result = check(val);
|
|
863
|
+
var setError = function () {
|
|
864
|
+
return ctx.addIssue(__assign({ code: ZodIssueCode.custom }, getIssueProperties(val)));
|
|
865
|
+
};
|
|
866
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
867
|
+
return result.then(function (data) {
|
|
868
|
+
if (!data) {
|
|
869
|
+
setError();
|
|
870
|
+
return false;
|
|
871
|
+
}
|
|
872
|
+
else {
|
|
873
|
+
return true;
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
if (!result) {
|
|
878
|
+
setError();
|
|
879
|
+
return false;
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
882
|
+
return true;
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
};
|
|
886
|
+
ZodType.prototype.refinement = function (check, refinementData) {
|
|
887
|
+
return this._refinement(function (val, ctx) {
|
|
888
|
+
if (!check(val)) {
|
|
889
|
+
ctx.addIssue(typeof refinementData === "function"
|
|
890
|
+
? refinementData(val, ctx)
|
|
891
|
+
: refinementData);
|
|
892
|
+
return false;
|
|
893
|
+
}
|
|
894
|
+
else {
|
|
895
|
+
return true;
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
};
|
|
899
|
+
ZodType.prototype._refinement = function (refinement) {
|
|
900
|
+
return new ZodEffects({
|
|
901
|
+
schema: this,
|
|
902
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
903
|
+
effect: { type: "refinement", refinement: refinement },
|
|
904
|
+
});
|
|
905
|
+
};
|
|
906
|
+
ZodType.prototype.optional = function () {
|
|
907
|
+
return ZodOptional.create(this);
|
|
908
|
+
};
|
|
909
|
+
ZodType.prototype.nullable = function () {
|
|
910
|
+
return ZodNullable.create(this);
|
|
911
|
+
};
|
|
912
|
+
ZodType.prototype.nullish = function () {
|
|
913
|
+
return this.optional().nullable();
|
|
914
|
+
};
|
|
915
|
+
ZodType.prototype.array = function () {
|
|
916
|
+
return ZodArray.create(this);
|
|
917
|
+
};
|
|
918
|
+
ZodType.prototype.promise = function () {
|
|
919
|
+
return ZodPromise.create(this);
|
|
920
|
+
};
|
|
921
|
+
ZodType.prototype.or = function (option) {
|
|
922
|
+
return ZodUnion.create([this, option]);
|
|
923
|
+
};
|
|
924
|
+
ZodType.prototype.and = function (incoming) {
|
|
925
|
+
return ZodIntersection.create(this, incoming);
|
|
926
|
+
};
|
|
927
|
+
ZodType.prototype.transform = function (transform) {
|
|
928
|
+
return new ZodEffects({
|
|
929
|
+
schema: this,
|
|
930
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
931
|
+
effect: { type: "transform", transform: transform },
|
|
932
|
+
});
|
|
933
|
+
};
|
|
934
|
+
ZodType.prototype.default = function (def) {
|
|
935
|
+
var defaultValueFunc = typeof def === "function" ? def : function () { return def; };
|
|
936
|
+
return new ZodDefault({
|
|
937
|
+
innerType: this,
|
|
938
|
+
defaultValue: defaultValueFunc,
|
|
939
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
940
|
+
});
|
|
941
|
+
};
|
|
942
|
+
ZodType.prototype.describe = function (description) {
|
|
943
|
+
var This = this.constructor;
|
|
944
|
+
return new This(__assign(__assign({}, this._def), { description: description }));
|
|
945
|
+
};
|
|
946
|
+
ZodType.prototype.isOptional = function () {
|
|
947
|
+
return this.safeParse(undefined).success;
|
|
948
|
+
};
|
|
949
|
+
ZodType.prototype.isNullable = function () {
|
|
950
|
+
return this.safeParse(null).success;
|
|
951
|
+
};
|
|
952
|
+
return ZodType;
|
|
953
|
+
}());
|
|
954
|
+
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
955
|
+
var uuidRegex = /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
956
|
+
// from https://stackoverflow.com/a/46181/1550155
|
|
957
|
+
// old version: too slow, didn't support unicode
|
|
958
|
+
// const emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
|
|
959
|
+
// eslint-disable-next-line
|
|
960
|
+
var emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
|
|
961
|
+
var ZodString = /** @class */ (function (_super) {
|
|
962
|
+
__extends(ZodString, _super);
|
|
963
|
+
function ZodString() {
|
|
964
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
965
|
+
_this._regex = function (regex, validation, message) {
|
|
966
|
+
return _this.refinement(function (data) { return regex.test(data); }, __assign({ validation: validation, code: ZodIssueCode.invalid_string }, errorUtil.errToObj(message)));
|
|
967
|
+
};
|
|
968
|
+
/**
|
|
969
|
+
* Deprecated.
|
|
970
|
+
* Use z.string().min(1) instead.
|
|
971
|
+
*/
|
|
972
|
+
_this.nonempty = function (message) {
|
|
973
|
+
return _this.min(1, errorUtil.errToObj(message));
|
|
974
|
+
};
|
|
975
|
+
return _this;
|
|
976
|
+
}
|
|
977
|
+
ZodString.prototype._parse = function (input) {
|
|
978
|
+
var e_1, _a;
|
|
979
|
+
var _b = this._processInputParams(input), status = _b.status, ctx = _b.ctx;
|
|
980
|
+
if (ctx.parsedType !== ZodParsedType.string) {
|
|
981
|
+
addIssueToContext(ctx, {
|
|
982
|
+
code: ZodIssueCode.invalid_type,
|
|
983
|
+
expected: ZodParsedType.string,
|
|
984
|
+
received: ctx.parsedType,
|
|
985
|
+
}
|
|
986
|
+
//
|
|
987
|
+
);
|
|
988
|
+
return INVALID;
|
|
989
|
+
}
|
|
990
|
+
try {
|
|
991
|
+
for (var _c = __values(this._def.checks), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
992
|
+
var check = _d.value;
|
|
993
|
+
if (check.kind === "min") {
|
|
994
|
+
if (ctx.data.length < check.value) {
|
|
995
|
+
addIssueToContext(ctx, {
|
|
996
|
+
code: ZodIssueCode.too_small,
|
|
997
|
+
minimum: check.value,
|
|
998
|
+
type: "string",
|
|
999
|
+
inclusive: true,
|
|
1000
|
+
message: check.message,
|
|
1001
|
+
});
|
|
1002
|
+
status.dirty();
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
else if (check.kind === "max") {
|
|
1006
|
+
if (ctx.data.length > check.value) {
|
|
1007
|
+
addIssueToContext(ctx, {
|
|
1008
|
+
code: ZodIssueCode.too_big,
|
|
1009
|
+
maximum: check.value,
|
|
1010
|
+
type: "string",
|
|
1011
|
+
inclusive: true,
|
|
1012
|
+
message: check.message,
|
|
1013
|
+
});
|
|
1014
|
+
status.dirty();
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
else if (check.kind === "email") {
|
|
1018
|
+
if (!emailRegex.test(ctx.data)) {
|
|
1019
|
+
addIssueToContext(ctx, {
|
|
1020
|
+
validation: "email",
|
|
1021
|
+
code: ZodIssueCode.invalid_string,
|
|
1022
|
+
message: check.message,
|
|
1023
|
+
});
|
|
1024
|
+
status.dirty();
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
else if (check.kind === "uuid") {
|
|
1028
|
+
if (!uuidRegex.test(ctx.data)) {
|
|
1029
|
+
addIssueToContext(ctx, {
|
|
1030
|
+
validation: "uuid",
|
|
1031
|
+
code: ZodIssueCode.invalid_string,
|
|
1032
|
+
message: check.message,
|
|
1033
|
+
});
|
|
1034
|
+
status.dirty();
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
else if (check.kind === "cuid") {
|
|
1038
|
+
if (!cuidRegex.test(ctx.data)) {
|
|
1039
|
+
addIssueToContext(ctx, {
|
|
1040
|
+
validation: "cuid",
|
|
1041
|
+
code: ZodIssueCode.invalid_string,
|
|
1042
|
+
message: check.message,
|
|
1043
|
+
});
|
|
1044
|
+
status.dirty();
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
else if (check.kind === "url") {
|
|
1048
|
+
try {
|
|
1049
|
+
new URL(ctx.data);
|
|
1050
|
+
}
|
|
1051
|
+
catch (_e) {
|
|
1052
|
+
addIssueToContext(ctx, {
|
|
1053
|
+
validation: "url",
|
|
1054
|
+
code: ZodIssueCode.invalid_string,
|
|
1055
|
+
message: check.message,
|
|
1056
|
+
});
|
|
1057
|
+
status.dirty();
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
else if (check.kind === "regex") {
|
|
1061
|
+
check.regex.lastIndex = 0;
|
|
1062
|
+
var testResult = check.regex.test(ctx.data);
|
|
1063
|
+
if (!testResult) {
|
|
1064
|
+
addIssueToContext(ctx, {
|
|
1065
|
+
validation: "regex",
|
|
1066
|
+
code: ZodIssueCode.invalid_string,
|
|
1067
|
+
message: check.message,
|
|
1068
|
+
});
|
|
1069
|
+
status.dirty();
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1075
|
+
finally {
|
|
1076
|
+
try {
|
|
1077
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
1078
|
+
}
|
|
1079
|
+
finally { if (e_1) throw e_1.error; }
|
|
1080
|
+
}
|
|
1081
|
+
return { status: status.value, value: ctx.data };
|
|
1082
|
+
};
|
|
1083
|
+
ZodString.prototype._addCheck = function (check) {
|
|
1084
|
+
return new ZodString(__assign(__assign({}, this._def), { checks: __spreadArray(__spreadArray([], __read(this._def.checks), false), [check], false) }));
|
|
1085
|
+
};
|
|
1086
|
+
ZodString.prototype.email = function (message) {
|
|
1087
|
+
return this._addCheck(__assign({ kind: "email" }, errorUtil.errToObj(message)));
|
|
1088
|
+
};
|
|
1089
|
+
ZodString.prototype.url = function (message) {
|
|
1090
|
+
return this._addCheck(__assign({ kind: "url" }, errorUtil.errToObj(message)));
|
|
1091
|
+
};
|
|
1092
|
+
ZodString.prototype.uuid = function (message) {
|
|
1093
|
+
return this._addCheck(__assign({ kind: "uuid" }, errorUtil.errToObj(message)));
|
|
1094
|
+
};
|
|
1095
|
+
ZodString.prototype.cuid = function (message) {
|
|
1096
|
+
return this._addCheck(__assign({ kind: "cuid" }, errorUtil.errToObj(message)));
|
|
1097
|
+
};
|
|
1098
|
+
ZodString.prototype.regex = function (regex, message) {
|
|
1099
|
+
return this._addCheck(__assign({ kind: "regex", regex: regex }, errorUtil.errToObj(message)));
|
|
1100
|
+
};
|
|
1101
|
+
ZodString.prototype.min = function (minLength, message) {
|
|
1102
|
+
return this._addCheck(__assign({ kind: "min", value: minLength }, errorUtil.errToObj(message)));
|
|
1103
|
+
};
|
|
1104
|
+
ZodString.prototype.max = function (maxLength, message) {
|
|
1105
|
+
return this._addCheck(__assign({ kind: "max", value: maxLength }, errorUtil.errToObj(message)));
|
|
1106
|
+
};
|
|
1107
|
+
ZodString.prototype.length = function (len, message) {
|
|
1108
|
+
return this.min(len, message).max(len, message);
|
|
1109
|
+
};
|
|
1110
|
+
Object.defineProperty(ZodString.prototype, "isEmail", {
|
|
1111
|
+
get: function () {
|
|
1112
|
+
return !!this._def.checks.find(function (ch) { return ch.kind === "email"; });
|
|
1113
|
+
},
|
|
1114
|
+
enumerable: false,
|
|
1115
|
+
configurable: true
|
|
1116
|
+
});
|
|
1117
|
+
Object.defineProperty(ZodString.prototype, "isURL", {
|
|
1118
|
+
get: function () {
|
|
1119
|
+
return !!this._def.checks.find(function (ch) { return ch.kind === "url"; });
|
|
1120
|
+
},
|
|
1121
|
+
enumerable: false,
|
|
1122
|
+
configurable: true
|
|
1123
|
+
});
|
|
1124
|
+
Object.defineProperty(ZodString.prototype, "isUUID", {
|
|
1125
|
+
get: function () {
|
|
1126
|
+
return !!this._def.checks.find(function (ch) { return ch.kind === "uuid"; });
|
|
1127
|
+
},
|
|
1128
|
+
enumerable: false,
|
|
1129
|
+
configurable: true
|
|
1130
|
+
});
|
|
1131
|
+
Object.defineProperty(ZodString.prototype, "isCUID", {
|
|
1132
|
+
get: function () {
|
|
1133
|
+
return !!this._def.checks.find(function (ch) { return ch.kind === "cuid"; });
|
|
1134
|
+
},
|
|
1135
|
+
enumerable: false,
|
|
1136
|
+
configurable: true
|
|
1137
|
+
});
|
|
1138
|
+
Object.defineProperty(ZodString.prototype, "minLength", {
|
|
1139
|
+
get: function () {
|
|
1140
|
+
var min = -Infinity;
|
|
1141
|
+
this._def.checks.map(function (ch) {
|
|
1142
|
+
if (ch.kind === "min") {
|
|
1143
|
+
if (min === null || ch.value > min) {
|
|
1144
|
+
min = ch.value;
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
});
|
|
1148
|
+
return min;
|
|
1149
|
+
},
|
|
1150
|
+
enumerable: false,
|
|
1151
|
+
configurable: true
|
|
1152
|
+
});
|
|
1153
|
+
Object.defineProperty(ZodString.prototype, "maxLength", {
|
|
1154
|
+
get: function () {
|
|
1155
|
+
var max = null;
|
|
1156
|
+
this._def.checks.map(function (ch) {
|
|
1157
|
+
if (ch.kind === "max") {
|
|
1158
|
+
if (max === null || ch.value < max) {
|
|
1159
|
+
max = ch.value;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1163
|
+
return max;
|
|
1164
|
+
},
|
|
1165
|
+
enumerable: false,
|
|
1166
|
+
configurable: true
|
|
1167
|
+
});
|
|
1168
|
+
ZodString.create = function (params) {
|
|
1169
|
+
return new ZodString(__assign({ checks: [], typeName: ZodFirstPartyTypeKind.ZodString }, processCreateParams(params)));
|
|
1170
|
+
};
|
|
1171
|
+
return ZodString;
|
|
1172
|
+
}(ZodType));
|
|
1173
|
+
// https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
|
|
1174
|
+
function floatSafeRemainder(val, step) {
|
|
1175
|
+
var valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1176
|
+
var stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1177
|
+
var decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1178
|
+
var valInt = parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1179
|
+
var stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1180
|
+
return (valInt % stepInt) / Math.pow(10, decCount);
|
|
1181
|
+
}
|
|
1182
|
+
var ZodNumber = /** @class */ (function (_super) {
|
|
1183
|
+
__extends(ZodNumber, _super);
|
|
1184
|
+
function ZodNumber() {
|
|
1185
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1186
|
+
_this.min = _this.gte;
|
|
1187
|
+
_this.max = _this.lte;
|
|
1188
|
+
_this.step = _this.multipleOf;
|
|
1189
|
+
return _this;
|
|
1190
|
+
}
|
|
1191
|
+
ZodNumber.prototype._parse = function (input) {
|
|
1192
|
+
var e_2, _a;
|
|
1193
|
+
var _b = this._processInputParams(input), status = _b.status, ctx = _b.ctx;
|
|
1194
|
+
if (ctx.parsedType !== ZodParsedType.number) {
|
|
1195
|
+
addIssueToContext(ctx, {
|
|
1196
|
+
code: ZodIssueCode.invalid_type,
|
|
1197
|
+
expected: ZodParsedType.number,
|
|
1198
|
+
received: ctx.parsedType,
|
|
1199
|
+
});
|
|
1200
|
+
return INVALID;
|
|
1201
|
+
}
|
|
1202
|
+
try {
|
|
1203
|
+
for (var _c = __values(this._def.checks), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1204
|
+
var check = _d.value;
|
|
1205
|
+
if (check.kind === "int") {
|
|
1206
|
+
if (!util.isInteger(ctx.data)) {
|
|
1207
|
+
addIssueToContext(ctx, {
|
|
1208
|
+
code: ZodIssueCode.invalid_type,
|
|
1209
|
+
expected: "integer",
|
|
1210
|
+
received: "float",
|
|
1211
|
+
message: check.message,
|
|
1212
|
+
});
|
|
1213
|
+
status.dirty();
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
else if (check.kind === "min") {
|
|
1217
|
+
var tooSmall = check.inclusive
|
|
1218
|
+
? ctx.data < check.value
|
|
1219
|
+
: ctx.data <= check.value;
|
|
1220
|
+
if (tooSmall) {
|
|
1221
|
+
addIssueToContext(ctx, {
|
|
1222
|
+
code: ZodIssueCode.too_small,
|
|
1223
|
+
minimum: check.value,
|
|
1224
|
+
type: "number",
|
|
1225
|
+
inclusive: check.inclusive,
|
|
1226
|
+
message: check.message,
|
|
1227
|
+
});
|
|
1228
|
+
status.dirty();
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
else if (check.kind === "max") {
|
|
1232
|
+
var tooBig = check.inclusive
|
|
1233
|
+
? ctx.data > check.value
|
|
1234
|
+
: ctx.data >= check.value;
|
|
1235
|
+
if (tooBig) {
|
|
1236
|
+
addIssueToContext(ctx, {
|
|
1237
|
+
code: ZodIssueCode.too_big,
|
|
1238
|
+
maximum: check.value,
|
|
1239
|
+
type: "number",
|
|
1240
|
+
inclusive: check.inclusive,
|
|
1241
|
+
message: check.message,
|
|
1242
|
+
});
|
|
1243
|
+
status.dirty();
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
else if (check.kind === "multipleOf") {
|
|
1247
|
+
if (floatSafeRemainder(ctx.data, check.value) !== 0) {
|
|
1248
|
+
addIssueToContext(ctx, {
|
|
1249
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1250
|
+
multipleOf: check.value,
|
|
1251
|
+
message: check.message,
|
|
1252
|
+
});
|
|
1253
|
+
status.dirty();
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
else {
|
|
1257
|
+
util.assertNever(check);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1262
|
+
finally {
|
|
1263
|
+
try {
|
|
1264
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
1265
|
+
}
|
|
1266
|
+
finally { if (e_2) throw e_2.error; }
|
|
1267
|
+
}
|
|
1268
|
+
return { status: status.value, value: ctx.data };
|
|
1269
|
+
};
|
|
1270
|
+
ZodNumber.prototype.gte = function (value, message) {
|
|
1271
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1272
|
+
};
|
|
1273
|
+
ZodNumber.prototype.gt = function (value, message) {
|
|
1274
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1275
|
+
};
|
|
1276
|
+
ZodNumber.prototype.lte = function (value, message) {
|
|
1277
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1278
|
+
};
|
|
1279
|
+
ZodNumber.prototype.lt = function (value, message) {
|
|
1280
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1281
|
+
};
|
|
1282
|
+
ZodNumber.prototype.setLimit = function (kind, value, inclusive, message) {
|
|
1283
|
+
return new ZodNumber(__assign(__assign({}, this._def), { checks: __spreadArray(__spreadArray([], __read(this._def.checks), false), [
|
|
1284
|
+
{
|
|
1285
|
+
kind: kind,
|
|
1286
|
+
value: value,
|
|
1287
|
+
inclusive: inclusive,
|
|
1288
|
+
message: errorUtil.toString(message),
|
|
1289
|
+
},
|
|
1290
|
+
], false) }));
|
|
1291
|
+
};
|
|
1292
|
+
ZodNumber.prototype._addCheck = function (check) {
|
|
1293
|
+
return new ZodNumber(__assign(__assign({}, this._def), { checks: __spreadArray(__spreadArray([], __read(this._def.checks), false), [check], false) }));
|
|
1294
|
+
};
|
|
1295
|
+
ZodNumber.prototype.int = function (message) {
|
|
1296
|
+
return this._addCheck({
|
|
1297
|
+
kind: "int",
|
|
1298
|
+
message: errorUtil.toString(message),
|
|
1299
|
+
});
|
|
1300
|
+
};
|
|
1301
|
+
ZodNumber.prototype.positive = function (message) {
|
|
1302
|
+
return this._addCheck({
|
|
1303
|
+
kind: "min",
|
|
1304
|
+
value: 0,
|
|
1305
|
+
inclusive: false,
|
|
1306
|
+
message: errorUtil.toString(message),
|
|
1307
|
+
});
|
|
1308
|
+
};
|
|
1309
|
+
ZodNumber.prototype.negative = function (message) {
|
|
1310
|
+
return this._addCheck({
|
|
1311
|
+
kind: "max",
|
|
1312
|
+
value: 0,
|
|
1313
|
+
inclusive: false,
|
|
1314
|
+
message: errorUtil.toString(message),
|
|
1315
|
+
});
|
|
1316
|
+
};
|
|
1317
|
+
ZodNumber.prototype.nonpositive = function (message) {
|
|
1318
|
+
return this._addCheck({
|
|
1319
|
+
kind: "max",
|
|
1320
|
+
value: 0,
|
|
1321
|
+
inclusive: true,
|
|
1322
|
+
message: errorUtil.toString(message),
|
|
1323
|
+
});
|
|
1324
|
+
};
|
|
1325
|
+
ZodNumber.prototype.nonnegative = function (message) {
|
|
1326
|
+
return this._addCheck({
|
|
1327
|
+
kind: "min",
|
|
1328
|
+
value: 0,
|
|
1329
|
+
inclusive: true,
|
|
1330
|
+
message: errorUtil.toString(message),
|
|
1331
|
+
});
|
|
1332
|
+
};
|
|
1333
|
+
ZodNumber.prototype.multipleOf = function (value, message) {
|
|
1334
|
+
return this._addCheck({
|
|
1335
|
+
kind: "multipleOf",
|
|
1336
|
+
value: value,
|
|
1337
|
+
message: errorUtil.toString(message),
|
|
1338
|
+
});
|
|
1339
|
+
};
|
|
1340
|
+
Object.defineProperty(ZodNumber.prototype, "minValue", {
|
|
1341
|
+
get: function () {
|
|
1342
|
+
var e_3, _a;
|
|
1343
|
+
var min = null;
|
|
1344
|
+
try {
|
|
1345
|
+
for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1346
|
+
var ch = _c.value;
|
|
1347
|
+
if (ch.kind === "min") {
|
|
1348
|
+
if (min === null || ch.value > min)
|
|
1349
|
+
min = ch.value;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1354
|
+
finally {
|
|
1355
|
+
try {
|
|
1356
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1357
|
+
}
|
|
1358
|
+
finally { if (e_3) throw e_3.error; }
|
|
1359
|
+
}
|
|
1360
|
+
return min;
|
|
1361
|
+
},
|
|
1362
|
+
enumerable: false,
|
|
1363
|
+
configurable: true
|
|
1364
|
+
});
|
|
1365
|
+
Object.defineProperty(ZodNumber.prototype, "maxValue", {
|
|
1366
|
+
get: function () {
|
|
1367
|
+
var e_4, _a;
|
|
1368
|
+
var max = null;
|
|
1369
|
+
try {
|
|
1370
|
+
for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1371
|
+
var ch = _c.value;
|
|
1372
|
+
if (ch.kind === "max") {
|
|
1373
|
+
if (max === null || ch.value < max)
|
|
1374
|
+
max = ch.value;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1379
|
+
finally {
|
|
1380
|
+
try {
|
|
1381
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1382
|
+
}
|
|
1383
|
+
finally { if (e_4) throw e_4.error; }
|
|
1384
|
+
}
|
|
1385
|
+
return max;
|
|
1386
|
+
},
|
|
1387
|
+
enumerable: false,
|
|
1388
|
+
configurable: true
|
|
1389
|
+
});
|
|
1390
|
+
Object.defineProperty(ZodNumber.prototype, "isInt", {
|
|
1391
|
+
get: function () {
|
|
1392
|
+
return !!this._def.checks.find(function (ch) { return ch.kind === "int"; });
|
|
1393
|
+
},
|
|
1394
|
+
enumerable: false,
|
|
1395
|
+
configurable: true
|
|
1396
|
+
});
|
|
1397
|
+
ZodNumber.create = function (params) {
|
|
1398
|
+
return new ZodNumber(__assign({ checks: [], typeName: ZodFirstPartyTypeKind.ZodNumber }, processCreateParams(params)));
|
|
1399
|
+
};
|
|
1400
|
+
return ZodNumber;
|
|
1401
|
+
}(ZodType));
|
|
1402
|
+
var ZodBigInt = /** @class */ (function (_super) {
|
|
1403
|
+
__extends(ZodBigInt, _super);
|
|
1404
|
+
function ZodBigInt() {
|
|
1405
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1406
|
+
}
|
|
1407
|
+
ZodBigInt.prototype._parse = function (input) {
|
|
1408
|
+
var ctx = this._processInputParams(input).ctx;
|
|
1409
|
+
if (ctx.parsedType !== ZodParsedType.bigint) {
|
|
1410
|
+
addIssueToContext(ctx, {
|
|
1411
|
+
code: ZodIssueCode.invalid_type,
|
|
1412
|
+
expected: ZodParsedType.bigint,
|
|
1413
|
+
received: ctx.parsedType,
|
|
1414
|
+
});
|
|
1415
|
+
return INVALID;
|
|
1416
|
+
}
|
|
1417
|
+
return OK(ctx.data);
|
|
1418
|
+
};
|
|
1419
|
+
ZodBigInt.create = function (params) {
|
|
1420
|
+
return new ZodBigInt(__assign({ typeName: ZodFirstPartyTypeKind.ZodBigInt }, processCreateParams(params)));
|
|
1421
|
+
};
|
|
1422
|
+
return ZodBigInt;
|
|
1423
|
+
}(ZodType));
|
|
1424
|
+
var ZodBoolean = /** @class */ (function (_super) {
|
|
1425
|
+
__extends(ZodBoolean, _super);
|
|
1426
|
+
function ZodBoolean() {
|
|
1427
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1428
|
+
}
|
|
1429
|
+
ZodBoolean.prototype._parse = function (input) {
|
|
1430
|
+
var ctx = this._processInputParams(input).ctx;
|
|
1431
|
+
if (ctx.parsedType !== ZodParsedType.boolean) {
|
|
1432
|
+
addIssueToContext(ctx, {
|
|
1433
|
+
code: ZodIssueCode.invalid_type,
|
|
1434
|
+
expected: ZodParsedType.boolean,
|
|
1435
|
+
received: ctx.parsedType,
|
|
1436
|
+
});
|
|
1437
|
+
return INVALID;
|
|
1438
|
+
}
|
|
1439
|
+
return OK(ctx.data);
|
|
1440
|
+
};
|
|
1441
|
+
ZodBoolean.create = function (params) {
|
|
1442
|
+
return new ZodBoolean(__assign({ typeName: ZodFirstPartyTypeKind.ZodBoolean }, processCreateParams(params)));
|
|
1443
|
+
};
|
|
1444
|
+
return ZodBoolean;
|
|
1445
|
+
}(ZodType));
|
|
1446
|
+
var ZodDate = /** @class */ (function (_super) {
|
|
1447
|
+
__extends(ZodDate, _super);
|
|
1448
|
+
function ZodDate() {
|
|
1449
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1450
|
+
}
|
|
1451
|
+
ZodDate.prototype._parse = function (input) {
|
|
1452
|
+
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
1453
|
+
if (ctx.parsedType !== ZodParsedType.date) {
|
|
1454
|
+
addIssueToContext(ctx, {
|
|
1455
|
+
code: ZodIssueCode.invalid_type,
|
|
1456
|
+
expected: ZodParsedType.date,
|
|
1457
|
+
received: ctx.parsedType,
|
|
1458
|
+
});
|
|
1459
|
+
return INVALID;
|
|
1460
|
+
}
|
|
1461
|
+
if (isNaN(ctx.data.getTime())) {
|
|
1462
|
+
addIssueToContext(ctx, {
|
|
1463
|
+
code: ZodIssueCode.invalid_date,
|
|
1464
|
+
});
|
|
1465
|
+
return INVALID;
|
|
1466
|
+
}
|
|
1467
|
+
return {
|
|
1468
|
+
status: status.value,
|
|
1469
|
+
value: new Date(ctx.data.getTime()),
|
|
1470
|
+
};
|
|
1471
|
+
};
|
|
1472
|
+
ZodDate.create = function (params) {
|
|
1473
|
+
return new ZodDate(__assign({ typeName: ZodFirstPartyTypeKind.ZodDate }, processCreateParams(params)));
|
|
1474
|
+
};
|
|
1475
|
+
return ZodDate;
|
|
1476
|
+
}(ZodType));
|
|
1477
|
+
var ZodUndefined = /** @class */ (function (_super) {
|
|
1478
|
+
__extends(ZodUndefined, _super);
|
|
1479
|
+
function ZodUndefined() {
|
|
1480
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1481
|
+
}
|
|
1482
|
+
ZodUndefined.prototype._parse = function (input) {
|
|
1483
|
+
var ctx = this._processInputParams(input).ctx;
|
|
1484
|
+
if (ctx.parsedType !== ZodParsedType.undefined) {
|
|
1485
|
+
addIssueToContext(ctx, {
|
|
1486
|
+
code: ZodIssueCode.invalid_type,
|
|
1487
|
+
expected: ZodParsedType.undefined,
|
|
1488
|
+
received: ctx.parsedType,
|
|
1489
|
+
});
|
|
1490
|
+
return INVALID;
|
|
1491
|
+
}
|
|
1492
|
+
return OK(ctx.data);
|
|
1493
|
+
};
|
|
1494
|
+
ZodUndefined.create = function (params) {
|
|
1495
|
+
return new ZodUndefined(__assign({ typeName: ZodFirstPartyTypeKind.ZodUndefined }, processCreateParams(params)));
|
|
1496
|
+
};
|
|
1497
|
+
return ZodUndefined;
|
|
1498
|
+
}(ZodType));
|
|
1499
|
+
var ZodNull = /** @class */ (function (_super) {
|
|
1500
|
+
__extends(ZodNull, _super);
|
|
1501
|
+
function ZodNull() {
|
|
1502
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1503
|
+
}
|
|
1504
|
+
ZodNull.prototype._parse = function (input) {
|
|
1505
|
+
var ctx = this._processInputParams(input).ctx;
|
|
1506
|
+
if (ctx.parsedType !== ZodParsedType.null) {
|
|
1507
|
+
addIssueToContext(ctx, {
|
|
1508
|
+
code: ZodIssueCode.invalid_type,
|
|
1509
|
+
expected: ZodParsedType.null,
|
|
1510
|
+
received: ctx.parsedType,
|
|
1511
|
+
});
|
|
1512
|
+
return INVALID;
|
|
1513
|
+
}
|
|
1514
|
+
return OK(ctx.data);
|
|
1515
|
+
};
|
|
1516
|
+
ZodNull.create = function (params) {
|
|
1517
|
+
return new ZodNull(__assign({ typeName: ZodFirstPartyTypeKind.ZodNull }, processCreateParams(params)));
|
|
1518
|
+
};
|
|
1519
|
+
return ZodNull;
|
|
1520
|
+
}(ZodType));
|
|
1521
|
+
var ZodAny = /** @class */ (function (_super) {
|
|
1522
|
+
__extends(ZodAny, _super);
|
|
1523
|
+
function ZodAny() {
|
|
1524
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1525
|
+
// to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
|
|
1526
|
+
_this._any = true;
|
|
1527
|
+
return _this;
|
|
1528
|
+
}
|
|
1529
|
+
ZodAny.prototype._parse = function (input) {
|
|
1530
|
+
var ctx = this._processInputParams(input).ctx;
|
|
1531
|
+
return OK(ctx.data);
|
|
1532
|
+
};
|
|
1533
|
+
ZodAny.create = function (params) {
|
|
1534
|
+
return new ZodAny(__assign({ typeName: ZodFirstPartyTypeKind.ZodAny }, processCreateParams(params)));
|
|
1535
|
+
};
|
|
1536
|
+
return ZodAny;
|
|
1537
|
+
}(ZodType));
|
|
1538
|
+
var ZodUnknown = /** @class */ (function (_super) {
|
|
1539
|
+
__extends(ZodUnknown, _super);
|
|
1540
|
+
function ZodUnknown() {
|
|
1541
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1542
|
+
// required
|
|
1543
|
+
_this._unknown = true;
|
|
1544
|
+
return _this;
|
|
1545
|
+
}
|
|
1546
|
+
ZodUnknown.prototype._parse = function (input) {
|
|
1547
|
+
var ctx = this._processInputParams(input).ctx;
|
|
1548
|
+
return OK(ctx.data);
|
|
1549
|
+
};
|
|
1550
|
+
ZodUnknown.create = function (params) {
|
|
1551
|
+
return new ZodUnknown(__assign({ typeName: ZodFirstPartyTypeKind.ZodUnknown }, processCreateParams(params)));
|
|
1552
|
+
};
|
|
1553
|
+
return ZodUnknown;
|
|
1554
|
+
}(ZodType));
|
|
1555
|
+
var ZodNever = /** @class */ (function (_super) {
|
|
1556
|
+
__extends(ZodNever, _super);
|
|
1557
|
+
function ZodNever() {
|
|
1558
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1559
|
+
}
|
|
1560
|
+
ZodNever.prototype._parse = function (input) {
|
|
1561
|
+
var ctx = this._processInputParams(input).ctx;
|
|
1562
|
+
addIssueToContext(ctx, {
|
|
1563
|
+
code: ZodIssueCode.invalid_type,
|
|
1564
|
+
expected: ZodParsedType.never,
|
|
1565
|
+
received: ctx.parsedType,
|
|
1566
|
+
});
|
|
1567
|
+
return INVALID;
|
|
1568
|
+
};
|
|
1569
|
+
ZodNever.create = function (params) {
|
|
1570
|
+
return new ZodNever(__assign({ typeName: ZodFirstPartyTypeKind.ZodNever }, processCreateParams(params)));
|
|
1571
|
+
};
|
|
1572
|
+
return ZodNever;
|
|
1573
|
+
}(ZodType));
|
|
1574
|
+
var ZodVoid = /** @class */ (function (_super) {
|
|
1575
|
+
__extends(ZodVoid, _super);
|
|
1576
|
+
function ZodVoid() {
|
|
1577
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1578
|
+
}
|
|
1579
|
+
ZodVoid.prototype._parse = function (input) {
|
|
1580
|
+
var ctx = this._processInputParams(input).ctx;
|
|
1581
|
+
if (ctx.parsedType !== ZodParsedType.undefined) {
|
|
1582
|
+
addIssueToContext(ctx, {
|
|
1583
|
+
code: ZodIssueCode.invalid_type,
|
|
1584
|
+
expected: ZodParsedType.void,
|
|
1585
|
+
received: ctx.parsedType,
|
|
1586
|
+
});
|
|
1587
|
+
return INVALID;
|
|
1588
|
+
}
|
|
1589
|
+
return OK(ctx.data);
|
|
1590
|
+
};
|
|
1591
|
+
ZodVoid.create = function (params) {
|
|
1592
|
+
return new ZodVoid(__assign({ typeName: ZodFirstPartyTypeKind.ZodVoid }, processCreateParams(params)));
|
|
1593
|
+
};
|
|
1594
|
+
return ZodVoid;
|
|
1595
|
+
}(ZodType));
|
|
1596
|
+
var ZodArray = /** @class */ (function (_super) {
|
|
1597
|
+
__extends(ZodArray, _super);
|
|
1598
|
+
function ZodArray() {
|
|
1599
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1600
|
+
}
|
|
1601
|
+
ZodArray.prototype._parse = function (input) {
|
|
1602
|
+
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
1603
|
+
var def = this._def;
|
|
1604
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
1605
|
+
addIssueToContext(ctx, {
|
|
1606
|
+
code: ZodIssueCode.invalid_type,
|
|
1607
|
+
expected: ZodParsedType.array,
|
|
1608
|
+
received: ctx.parsedType,
|
|
1609
|
+
});
|
|
1610
|
+
return INVALID;
|
|
1611
|
+
}
|
|
1612
|
+
if (def.minLength !== null) {
|
|
1613
|
+
if (ctx.data.length < def.minLength.value) {
|
|
1614
|
+
addIssueToContext(ctx, {
|
|
1615
|
+
code: ZodIssueCode.too_small,
|
|
1616
|
+
minimum: def.minLength.value,
|
|
1617
|
+
type: "array",
|
|
1618
|
+
inclusive: true,
|
|
1619
|
+
message: def.minLength.message,
|
|
1620
|
+
});
|
|
1621
|
+
status.dirty();
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
if (def.maxLength !== null) {
|
|
1625
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
1626
|
+
addIssueToContext(ctx, {
|
|
1627
|
+
code: ZodIssueCode.too_big,
|
|
1628
|
+
maximum: def.maxLength.value,
|
|
1629
|
+
type: "array",
|
|
1630
|
+
inclusive: true,
|
|
1631
|
+
message: def.maxLength.message,
|
|
1632
|
+
});
|
|
1633
|
+
status.dirty();
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
if (ctx.async) {
|
|
1637
|
+
return Promise.all(ctx.data.map(function (item, i) {
|
|
1638
|
+
return def.type._parseAsync({
|
|
1639
|
+
parent: ctx,
|
|
1640
|
+
path: __spreadArray(__spreadArray([], __read(ctx.path), false), [i], false),
|
|
1641
|
+
data: item,
|
|
1642
|
+
});
|
|
1643
|
+
})).then(function (result) {
|
|
1644
|
+
return ParseStatus.mergeArray(status, result);
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
var result = ctx.data.map(function (item, i) {
|
|
1648
|
+
return def.type._parseSync({
|
|
1649
|
+
parent: ctx,
|
|
1650
|
+
path: __spreadArray(__spreadArray([], __read(ctx.path), false), [i], false),
|
|
1651
|
+
data: item,
|
|
1652
|
+
});
|
|
1653
|
+
});
|
|
1654
|
+
return ParseStatus.mergeArray(status, result);
|
|
1655
|
+
};
|
|
1656
|
+
Object.defineProperty(ZodArray.prototype, "element", {
|
|
1657
|
+
get: function () {
|
|
1658
|
+
return this._def.type;
|
|
1659
|
+
},
|
|
1660
|
+
enumerable: false,
|
|
1661
|
+
configurable: true
|
|
1662
|
+
});
|
|
1663
|
+
ZodArray.prototype.min = function (minLength, message) {
|
|
1664
|
+
return new ZodArray(__assign(__assign({}, this._def), { minLength: { value: minLength, message: errorUtil.toString(message) } }));
|
|
1665
|
+
};
|
|
1666
|
+
ZodArray.prototype.max = function (maxLength, message) {
|
|
1667
|
+
return new ZodArray(__assign(__assign({}, this._def), { maxLength: { value: maxLength, message: errorUtil.toString(message) } }));
|
|
1668
|
+
};
|
|
1669
|
+
ZodArray.prototype.length = function (len, message) {
|
|
1670
|
+
return this.min(len, message).max(len, message);
|
|
1671
|
+
};
|
|
1672
|
+
ZodArray.prototype.nonempty = function (message) {
|
|
1673
|
+
return this.min(1, message);
|
|
1674
|
+
};
|
|
1675
|
+
ZodArray.create = function (schema, params) {
|
|
1676
|
+
return new ZodArray(__assign({ type: schema, minLength: null, maxLength: null, typeName: ZodFirstPartyTypeKind.ZodArray }, processCreateParams(params)));
|
|
1677
|
+
};
|
|
1678
|
+
return ZodArray;
|
|
1679
|
+
}(ZodType));
|
|
1680
|
+
/////////////////////////////////////////
|
|
1681
|
+
/////////////////////////////////////////
|
|
1682
|
+
////////// //////////
|
|
1683
|
+
////////// ZodObject //////////
|
|
1684
|
+
////////// //////////
|
|
1685
|
+
/////////////////////////////////////////
|
|
1686
|
+
/////////////////////////////////////////
|
|
1687
|
+
var objectUtil;
|
|
1688
|
+
(function (objectUtil) {
|
|
1689
|
+
objectUtil.mergeShapes = function (first, second) {
|
|
1690
|
+
return __assign(__assign({}, first), second);
|
|
1691
|
+
};
|
|
1692
|
+
})(objectUtil || (objectUtil = {}));
|
|
1693
|
+
var AugmentFactory = function (def) { return function (augmentation) {
|
|
1694
|
+
return new ZodObject(__assign(__assign({}, def), { shape: function () { return (__assign(__assign({}, def.shape()), augmentation)); } }));
|
|
1695
|
+
}; };
|
|
1696
|
+
function deepPartialify(schema) {
|
|
1697
|
+
if (schema instanceof ZodObject) {
|
|
1698
|
+
var newShape_1 = {};
|
|
1699
|
+
for (var key in schema.shape) {
|
|
1700
|
+
var fieldSchema = schema.shape[key];
|
|
1701
|
+
newShape_1[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
1702
|
+
}
|
|
1703
|
+
return new ZodObject(__assign(__assign({}, schema._def), { shape: function () { return newShape_1; } }));
|
|
1704
|
+
}
|
|
1705
|
+
else if (schema instanceof ZodArray) {
|
|
1706
|
+
return ZodArray.create(deepPartialify(schema.element));
|
|
1707
|
+
}
|
|
1708
|
+
else if (schema instanceof ZodOptional) {
|
|
1709
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
1710
|
+
}
|
|
1711
|
+
else if (schema instanceof ZodNullable) {
|
|
1712
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
1713
|
+
}
|
|
1714
|
+
else if (schema instanceof ZodTuple) {
|
|
1715
|
+
return ZodTuple.create(schema.items.map(function (item) { return deepPartialify(item); }));
|
|
1716
|
+
}
|
|
1717
|
+
else {
|
|
1718
|
+
return schema;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
var ZodObject = /** @class */ (function (_super) {
|
|
1722
|
+
__extends(ZodObject, _super);
|
|
1723
|
+
function ZodObject() {
|
|
1724
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1725
|
+
_this._cached = null;
|
|
1726
|
+
/**
|
|
1727
|
+
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
|
1728
|
+
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
1729
|
+
*/
|
|
1730
|
+
_this.nonstrict = _this.passthrough;
|
|
1731
|
+
_this.augment = AugmentFactory(_this._def);
|
|
1732
|
+
_this.extend = AugmentFactory(_this._def);
|
|
1733
|
+
return _this;
|
|
1734
|
+
}
|
|
1735
|
+
ZodObject.prototype._getCached = function () {
|
|
1736
|
+
if (this._cached !== null)
|
|
1737
|
+
return this._cached;
|
|
1738
|
+
var shape = this._def.shape();
|
|
1739
|
+
var keys = util.objectKeys(shape);
|
|
1740
|
+
return (this._cached = { shape: shape, keys: keys });
|
|
1741
|
+
};
|
|
1742
|
+
ZodObject.prototype._parse = function (input) {
|
|
1743
|
+
var e_5, _a, e_6, _b, e_7, _c;
|
|
1744
|
+
var _this = this;
|
|
1745
|
+
var _d = this._processInputParams(input), status = _d.status, ctx = _d.ctx;
|
|
1746
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
1747
|
+
addIssueToContext(ctx, {
|
|
1748
|
+
code: ZodIssueCode.invalid_type,
|
|
1749
|
+
expected: ZodParsedType.object,
|
|
1750
|
+
received: ctx.parsedType,
|
|
1751
|
+
});
|
|
1752
|
+
return INVALID;
|
|
1753
|
+
}
|
|
1754
|
+
var _e = this._getCached(), shape = _e.shape, shapeKeys = _e.keys;
|
|
1755
|
+
var dataKeys = util.objectKeys(ctx.data);
|
|
1756
|
+
var extraKeys = dataKeys.filter(function (k) { return !shapeKeys.includes(k); });
|
|
1757
|
+
var pairs = [];
|
|
1758
|
+
try {
|
|
1759
|
+
for (var shapeKeys_1 = __values(shapeKeys), shapeKeys_1_1 = shapeKeys_1.next(); !shapeKeys_1_1.done; shapeKeys_1_1 = shapeKeys_1.next()) {
|
|
1760
|
+
var key = shapeKeys_1_1.value;
|
|
1761
|
+
var keyValidator = shape[key];
|
|
1762
|
+
var value = ctx.data[key];
|
|
1763
|
+
pairs.push({
|
|
1764
|
+
key: { status: "valid", value: key },
|
|
1765
|
+
value: keyValidator._parse({
|
|
1766
|
+
parent: ctx,
|
|
1767
|
+
data: value,
|
|
1768
|
+
path: __spreadArray(__spreadArray([], __read(ctx.path), false), [key], false),
|
|
1769
|
+
}),
|
|
1770
|
+
alwaysSet: key in ctx.data,
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1775
|
+
finally {
|
|
1776
|
+
try {
|
|
1777
|
+
if (shapeKeys_1_1 && !shapeKeys_1_1.done && (_a = shapeKeys_1.return)) _a.call(shapeKeys_1);
|
|
1778
|
+
}
|
|
1779
|
+
finally { if (e_5) throw e_5.error; }
|
|
1780
|
+
}
|
|
1781
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
1782
|
+
var unknownKeys = this._def.unknownKeys;
|
|
1783
|
+
if (unknownKeys === "passthrough") {
|
|
1784
|
+
try {
|
|
1785
|
+
for (var extraKeys_1 = __values(extraKeys), extraKeys_1_1 = extraKeys_1.next(); !extraKeys_1_1.done; extraKeys_1_1 = extraKeys_1.next()) {
|
|
1786
|
+
var key = extraKeys_1_1.value;
|
|
1787
|
+
pairs.push({
|
|
1788
|
+
key: { status: "valid", value: key },
|
|
1789
|
+
value: { status: "valid", value: ctx.data[key] },
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1794
|
+
finally {
|
|
1795
|
+
try {
|
|
1796
|
+
if (extraKeys_1_1 && !extraKeys_1_1.done && (_b = extraKeys_1.return)) _b.call(extraKeys_1);
|
|
1797
|
+
}
|
|
1798
|
+
finally { if (e_6) throw e_6.error; }
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
else if (unknownKeys === "strict") {
|
|
1802
|
+
if (extraKeys.length > 0) {
|
|
1803
|
+
addIssueToContext(ctx, {
|
|
1804
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
1805
|
+
keys: extraKeys,
|
|
1806
|
+
});
|
|
1807
|
+
status.dirty();
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
else if (unknownKeys === "strip") ;
|
|
1811
|
+
else {
|
|
1812
|
+
throw new Error("Internal ZodObject error: invalid unknownKeys value.");
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
else {
|
|
1816
|
+
// run catchall validation
|
|
1817
|
+
var catchall = this._def.catchall;
|
|
1818
|
+
try {
|
|
1819
|
+
for (var extraKeys_2 = __values(extraKeys), extraKeys_2_1 = extraKeys_2.next(); !extraKeys_2_1.done; extraKeys_2_1 = extraKeys_2.next()) {
|
|
1820
|
+
var key = extraKeys_2_1.value;
|
|
1821
|
+
var value = ctx.data[key];
|
|
1822
|
+
pairs.push({
|
|
1823
|
+
key: { status: "valid", value: key },
|
|
1824
|
+
value: catchall._parse({ parent: ctx, path: __spreadArray(__spreadArray([], __read(ctx.path), false), [key], false), data: value } //, ctx.child(key), value, getParsedType(value)
|
|
1825
|
+
),
|
|
1826
|
+
alwaysSet: key in ctx.data,
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
1831
|
+
finally {
|
|
1832
|
+
try {
|
|
1833
|
+
if (extraKeys_2_1 && !extraKeys_2_1.done && (_c = extraKeys_2.return)) _c.call(extraKeys_2);
|
|
1834
|
+
}
|
|
1835
|
+
finally { if (e_7) throw e_7.error; }
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
if (ctx.async) {
|
|
1839
|
+
return Promise.resolve()
|
|
1840
|
+
.then(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1841
|
+
var syncPairs, pairs_1, pairs_1_1, pair, key, _a, _b, e_8_1;
|
|
1842
|
+
var e_8, _c, _d;
|
|
1843
|
+
return __generator(this, function (_e) {
|
|
1844
|
+
switch (_e.label) {
|
|
1845
|
+
case 0:
|
|
1846
|
+
syncPairs = [];
|
|
1847
|
+
_e.label = 1;
|
|
1848
|
+
case 1:
|
|
1849
|
+
_e.trys.push([1, 7, 8, 9]);
|
|
1850
|
+
pairs_1 = __values(pairs), pairs_1_1 = pairs_1.next();
|
|
1851
|
+
_e.label = 2;
|
|
1852
|
+
case 2:
|
|
1853
|
+
if (!!pairs_1_1.done) return [3 /*break*/, 6];
|
|
1854
|
+
pair = pairs_1_1.value;
|
|
1855
|
+
return [4 /*yield*/, pair.key];
|
|
1856
|
+
case 3:
|
|
1857
|
+
key = _e.sent();
|
|
1858
|
+
_b = (_a = syncPairs).push;
|
|
1859
|
+
_d = {
|
|
1860
|
+
key: key
|
|
1861
|
+
};
|
|
1862
|
+
return [4 /*yield*/, pair.value];
|
|
1863
|
+
case 4:
|
|
1864
|
+
_b.apply(_a, [(_d.value = _e.sent(),
|
|
1865
|
+
_d.alwaysSet = pair.alwaysSet,
|
|
1866
|
+
_d)]);
|
|
1867
|
+
_e.label = 5;
|
|
1868
|
+
case 5:
|
|
1869
|
+
pairs_1_1 = pairs_1.next();
|
|
1870
|
+
return [3 /*break*/, 2];
|
|
1871
|
+
case 6: return [3 /*break*/, 9];
|
|
1872
|
+
case 7:
|
|
1873
|
+
e_8_1 = _e.sent();
|
|
1874
|
+
e_8 = { error: e_8_1 };
|
|
1875
|
+
return [3 /*break*/, 9];
|
|
1876
|
+
case 8:
|
|
1877
|
+
try {
|
|
1878
|
+
if (pairs_1_1 && !pairs_1_1.done && (_c = pairs_1.return)) _c.call(pairs_1);
|
|
1879
|
+
}
|
|
1880
|
+
finally { if (e_8) throw e_8.error; }
|
|
1881
|
+
return [7 /*endfinally*/];
|
|
1882
|
+
case 9: return [2 /*return*/, syncPairs];
|
|
1883
|
+
}
|
|
1884
|
+
});
|
|
1885
|
+
}); })
|
|
1886
|
+
.then(function (syncPairs) {
|
|
1887
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
1888
|
+
});
|
|
1889
|
+
}
|
|
1890
|
+
else {
|
|
1891
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
1892
|
+
}
|
|
1893
|
+
};
|
|
1894
|
+
Object.defineProperty(ZodObject.prototype, "shape", {
|
|
1895
|
+
get: function () {
|
|
1896
|
+
return this._def.shape();
|
|
1897
|
+
},
|
|
1898
|
+
enumerable: false,
|
|
1899
|
+
configurable: true
|
|
1900
|
+
});
|
|
1901
|
+
ZodObject.prototype.strict = function (message) {
|
|
1902
|
+
var _this = this;
|
|
1903
|
+
errorUtil.errToObj;
|
|
1904
|
+
return new ZodObject(__assign(__assign(__assign({}, this._def), { unknownKeys: "strict" }), (message !== undefined
|
|
1905
|
+
? {
|
|
1906
|
+
errorMap: function (issue, ctx) {
|
|
1907
|
+
var _a, _b, _c, _d;
|
|
1908
|
+
var defaultError = (_c = (_b = (_a = _this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
|
|
1909
|
+
if (issue.code === "unrecognized_keys")
|
|
1910
|
+
return {
|
|
1911
|
+
message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
|
|
1912
|
+
};
|
|
1913
|
+
return {
|
|
1914
|
+
message: defaultError,
|
|
1915
|
+
};
|
|
1916
|
+
},
|
|
1917
|
+
}
|
|
1918
|
+
: {})));
|
|
1919
|
+
};
|
|
1920
|
+
ZodObject.prototype.strip = function () {
|
|
1921
|
+
return new ZodObject(__assign(__assign({}, this._def), { unknownKeys: "strip" }));
|
|
1922
|
+
};
|
|
1923
|
+
ZodObject.prototype.passthrough = function () {
|
|
1924
|
+
return new ZodObject(__assign(__assign({}, this._def), { unknownKeys: "passthrough" }));
|
|
1925
|
+
};
|
|
1926
|
+
ZodObject.prototype.setKey = function (key, schema) {
|
|
1927
|
+
var _a;
|
|
1928
|
+
return this.augment((_a = {}, _a[key] = schema, _a));
|
|
1929
|
+
};
|
|
1930
|
+
/**
|
|
1931
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
1932
|
+
* inferred type of merged objects. Please
|
|
1933
|
+
* upgrade if you are experiencing issues.
|
|
1934
|
+
*/
|
|
1935
|
+
ZodObject.prototype.merge = function (merging) {
|
|
1936
|
+
var _this = this;
|
|
1937
|
+
// const mergedShape = objectUtil.mergeShapes(
|
|
1938
|
+
// this._def.shape(),
|
|
1939
|
+
// merging._def.shape()
|
|
1940
|
+
// );
|
|
1941
|
+
var merged = new ZodObject({
|
|
1942
|
+
unknownKeys: merging._def.unknownKeys,
|
|
1943
|
+
catchall: merging._def.catchall,
|
|
1944
|
+
shape: function () {
|
|
1945
|
+
return objectUtil.mergeShapes(_this._def.shape(), merging._def.shape());
|
|
1946
|
+
},
|
|
1947
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1948
|
+
});
|
|
1949
|
+
return merged;
|
|
1950
|
+
};
|
|
1951
|
+
ZodObject.prototype.catchall = function (index) {
|
|
1952
|
+
return new ZodObject(__assign(__assign({}, this._def), { catchall: index }));
|
|
1953
|
+
};
|
|
1954
|
+
ZodObject.prototype.pick = function (mask) {
|
|
1955
|
+
var _this = this;
|
|
1956
|
+
var shape = {};
|
|
1957
|
+
util.objectKeys(mask).map(function (key) {
|
|
1958
|
+
shape[key] = _this.shape[key];
|
|
1959
|
+
});
|
|
1960
|
+
return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return shape; } }));
|
|
1961
|
+
};
|
|
1962
|
+
ZodObject.prototype.omit = function (mask) {
|
|
1963
|
+
var _this = this;
|
|
1964
|
+
var shape = {};
|
|
1965
|
+
util.objectKeys(this.shape).map(function (key) {
|
|
1966
|
+
if (util.objectKeys(mask).indexOf(key) === -1) {
|
|
1967
|
+
shape[key] = _this.shape[key];
|
|
1968
|
+
}
|
|
1969
|
+
});
|
|
1970
|
+
return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return shape; } }));
|
|
1971
|
+
};
|
|
1972
|
+
ZodObject.prototype.deepPartial = function () {
|
|
1973
|
+
return deepPartialify(this);
|
|
1974
|
+
};
|
|
1975
|
+
ZodObject.prototype.partial = function (mask) {
|
|
1976
|
+
var _this = this;
|
|
1977
|
+
var newShape = {};
|
|
1978
|
+
if (mask) {
|
|
1979
|
+
util.objectKeys(this.shape).map(function (key) {
|
|
1980
|
+
if (util.objectKeys(mask).indexOf(key) === -1) {
|
|
1981
|
+
newShape[key] = _this.shape[key];
|
|
1982
|
+
}
|
|
1983
|
+
else {
|
|
1984
|
+
newShape[key] = _this.shape[key].optional();
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return newShape; } }));
|
|
1988
|
+
}
|
|
1989
|
+
else {
|
|
1990
|
+
for (var key in this.shape) {
|
|
1991
|
+
var fieldSchema = this.shape[key];
|
|
1992
|
+
newShape[key] = fieldSchema.optional();
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return newShape; } }));
|
|
1996
|
+
};
|
|
1997
|
+
ZodObject.prototype.required = function () {
|
|
1998
|
+
var newShape = {};
|
|
1999
|
+
for (var key in this.shape) {
|
|
2000
|
+
var fieldSchema = this.shape[key];
|
|
2001
|
+
var newField = fieldSchema;
|
|
2002
|
+
while (newField instanceof ZodOptional) {
|
|
2003
|
+
newField = newField._def.innerType;
|
|
2004
|
+
}
|
|
2005
|
+
newShape[key] = newField;
|
|
2006
|
+
}
|
|
2007
|
+
return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return newShape; } }));
|
|
2008
|
+
};
|
|
2009
|
+
ZodObject.create = function (shape, params) {
|
|
2010
|
+
return new ZodObject(__assign({ shape: function () { return shape; }, unknownKeys: "strip", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
|
|
2011
|
+
};
|
|
2012
|
+
ZodObject.strictCreate = function (shape, params) {
|
|
2013
|
+
return new ZodObject(__assign({ shape: function () { return shape; }, unknownKeys: "strict", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
|
|
2014
|
+
};
|
|
2015
|
+
ZodObject.lazycreate = function (shape, params) {
|
|
2016
|
+
return new ZodObject(__assign({ shape: shape, unknownKeys: "strip", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
|
|
2017
|
+
};
|
|
2018
|
+
return ZodObject;
|
|
2019
|
+
}(ZodType));
|
|
2020
|
+
var ZodUnion = /** @class */ (function (_super) {
|
|
2021
|
+
__extends(ZodUnion, _super);
|
|
2022
|
+
function ZodUnion() {
|
|
2023
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2024
|
+
}
|
|
2025
|
+
ZodUnion.prototype._parse = function (input) {
|
|
2026
|
+
var _this = this;
|
|
2027
|
+
var ctx = this._processInputParams(input).ctx;
|
|
2028
|
+
var options = this._def.options;
|
|
2029
|
+
function handleResults(results) {
|
|
2030
|
+
var e_9, _a, e_10, _b, _c;
|
|
2031
|
+
try {
|
|
2032
|
+
// return first issue-free validation if it exists
|
|
2033
|
+
for (var results_1 = __values(results), results_1_1 = results_1.next(); !results_1_1.done; results_1_1 = results_1.next()) {
|
|
2034
|
+
var result = results_1_1.value;
|
|
2035
|
+
if (result.result.status === "valid") {
|
|
2036
|
+
return result.result;
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
2041
|
+
finally {
|
|
2042
|
+
try {
|
|
2043
|
+
if (results_1_1 && !results_1_1.done && (_a = results_1.return)) _a.call(results_1);
|
|
2044
|
+
}
|
|
2045
|
+
finally { if (e_9) throw e_9.error; }
|
|
2046
|
+
}
|
|
2047
|
+
try {
|
|
2048
|
+
for (var results_2 = __values(results), results_2_1 = results_2.next(); !results_2_1.done; results_2_1 = results_2.next()) {
|
|
2049
|
+
var result = results_2_1.value;
|
|
2050
|
+
if (result.result.status === "dirty") {
|
|
2051
|
+
// add issues from dirty option
|
|
2052
|
+
(_c = ctx.issues).push.apply(_c, __spreadArray([], __read(result.ctx.issues), false));
|
|
2053
|
+
return result.result;
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
2058
|
+
finally {
|
|
2059
|
+
try {
|
|
2060
|
+
if (results_2_1 && !results_2_1.done && (_b = results_2.return)) _b.call(results_2);
|
|
2061
|
+
}
|
|
2062
|
+
finally { if (e_10) throw e_10.error; }
|
|
2063
|
+
}
|
|
2064
|
+
// return invalid
|
|
2065
|
+
var unionErrors = results.map(function (result) { return new ZodError(result.ctx.issues); });
|
|
2066
|
+
addIssueToContext(ctx, {
|
|
2067
|
+
code: ZodIssueCode.invalid_union,
|
|
2068
|
+
unionErrors: unionErrors,
|
|
2069
|
+
});
|
|
2070
|
+
return INVALID;
|
|
2071
|
+
}
|
|
2072
|
+
if (ctx.async) {
|
|
2073
|
+
return Promise.all(options.map(function (option) { return __awaiter(_this, void 0, void 0, function () {
|
|
2074
|
+
var childCtx;
|
|
2075
|
+
var _a;
|
|
2076
|
+
return __generator(this, function (_b) {
|
|
2077
|
+
switch (_b.label) {
|
|
2078
|
+
case 0:
|
|
2079
|
+
childCtx = __assign(__assign({}, ctx), { issues: [], parent: null });
|
|
2080
|
+
_a = {};
|
|
2081
|
+
return [4 /*yield*/, option._parseAsync({
|
|
2082
|
+
data: ctx.data,
|
|
2083
|
+
path: ctx.path,
|
|
2084
|
+
parent: childCtx,
|
|
2085
|
+
})];
|
|
2086
|
+
case 1: return [2 /*return*/, (_a.result = _b.sent(),
|
|
2087
|
+
_a.ctx = childCtx,
|
|
2088
|
+
_a)];
|
|
2089
|
+
}
|
|
2090
|
+
});
|
|
2091
|
+
}); })).then(handleResults);
|
|
2092
|
+
}
|
|
2093
|
+
else {
|
|
2094
|
+
var optionResults = options.map(function (option) {
|
|
2095
|
+
var childCtx = __assign(__assign({}, ctx), { issues: [], parent: null });
|
|
2096
|
+
return {
|
|
2097
|
+
result: option._parseSync({
|
|
2098
|
+
data: ctx.data,
|
|
2099
|
+
path: ctx.path,
|
|
2100
|
+
parent: childCtx,
|
|
2101
|
+
}),
|
|
2102
|
+
ctx: childCtx,
|
|
2103
|
+
};
|
|
2104
|
+
});
|
|
2105
|
+
return handleResults(optionResults);
|
|
2106
|
+
}
|
|
2107
|
+
};
|
|
2108
|
+
Object.defineProperty(ZodUnion.prototype, "options", {
|
|
2109
|
+
get: function () {
|
|
2110
|
+
return this._def.options;
|
|
2111
|
+
},
|
|
2112
|
+
enumerable: false,
|
|
2113
|
+
configurable: true
|
|
2114
|
+
});
|
|
2115
|
+
ZodUnion.create = function (types, params) {
|
|
2116
|
+
return new ZodUnion(__assign({ options: types, typeName: ZodFirstPartyTypeKind.ZodUnion }, processCreateParams(params)));
|
|
2117
|
+
};
|
|
2118
|
+
return ZodUnion;
|
|
2119
|
+
}(ZodType));
|
|
2120
|
+
var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
2121
|
+
__extends(ZodDiscriminatedUnion, _super);
|
|
2122
|
+
function ZodDiscriminatedUnion() {
|
|
2123
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2124
|
+
}
|
|
2125
|
+
ZodDiscriminatedUnion.prototype._parse = function (input) {
|
|
2126
|
+
var ctx = this._processInputParams(input).ctx;
|
|
2127
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
2128
|
+
addIssueToContext(ctx, {
|
|
2129
|
+
code: ZodIssueCode.invalid_type,
|
|
2130
|
+
expected: ZodParsedType.object,
|
|
2131
|
+
received: ctx.parsedType,
|
|
2132
|
+
});
|
|
2133
|
+
return INVALID;
|
|
2134
|
+
}
|
|
2135
|
+
var discriminator = this.discriminator;
|
|
2136
|
+
var discriminatorValue = ctx.data[discriminator];
|
|
2137
|
+
var option = this.options.get(discriminatorValue);
|
|
2138
|
+
if (!option) {
|
|
2139
|
+
addIssueToContext(ctx, {
|
|
2140
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
2141
|
+
options: this.validDiscriminatorValues,
|
|
2142
|
+
path: [discriminator],
|
|
2143
|
+
});
|
|
2144
|
+
return INVALID;
|
|
2145
|
+
}
|
|
2146
|
+
if (ctx.async) {
|
|
2147
|
+
return option._parseAsync({
|
|
2148
|
+
data: ctx.data,
|
|
2149
|
+
path: ctx.path,
|
|
2150
|
+
parent: ctx,
|
|
2151
|
+
});
|
|
2152
|
+
}
|
|
2153
|
+
else {
|
|
2154
|
+
return option._parseSync({
|
|
2155
|
+
data: ctx.data,
|
|
2156
|
+
path: ctx.path,
|
|
2157
|
+
parent: ctx,
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
};
|
|
2161
|
+
Object.defineProperty(ZodDiscriminatedUnion.prototype, "discriminator", {
|
|
2162
|
+
get: function () {
|
|
2163
|
+
return this._def.discriminator;
|
|
2164
|
+
},
|
|
2165
|
+
enumerable: false,
|
|
2166
|
+
configurable: true
|
|
2167
|
+
});
|
|
2168
|
+
Object.defineProperty(ZodDiscriminatedUnion.prototype, "validDiscriminatorValues", {
|
|
2169
|
+
get: function () {
|
|
2170
|
+
return Array.from(this.options.keys());
|
|
2171
|
+
},
|
|
2172
|
+
enumerable: false,
|
|
2173
|
+
configurable: true
|
|
2174
|
+
});
|
|
2175
|
+
Object.defineProperty(ZodDiscriminatedUnion.prototype, "options", {
|
|
2176
|
+
get: function () {
|
|
2177
|
+
return this._def.options;
|
|
2178
|
+
},
|
|
2179
|
+
enumerable: false,
|
|
2180
|
+
configurable: true
|
|
2181
|
+
});
|
|
2182
|
+
/**
|
|
2183
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
2184
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
2185
|
+
* have a different value for each object in the union.
|
|
2186
|
+
* @param discriminator the name of the discriminator property
|
|
2187
|
+
* @param types an array of object schemas
|
|
2188
|
+
* @param params
|
|
2189
|
+
*/
|
|
2190
|
+
ZodDiscriminatedUnion.create = function (discriminator, types, params) {
|
|
2191
|
+
// Get all the valid discriminator values
|
|
2192
|
+
var options = new Map();
|
|
2193
|
+
try {
|
|
2194
|
+
types.forEach(function (type) {
|
|
2195
|
+
var discriminatorValue = type.shape[discriminator].value;
|
|
2196
|
+
options.set(discriminatorValue, type);
|
|
2197
|
+
});
|
|
2198
|
+
}
|
|
2199
|
+
catch (e) {
|
|
2200
|
+
throw new Error("The discriminator value could not be extracted from all the provided schemas");
|
|
2201
|
+
}
|
|
2202
|
+
// Assert that all the discriminator values are unique
|
|
2203
|
+
if (options.size !== types.length) {
|
|
2204
|
+
throw new Error("Some of the discriminator values are not unique");
|
|
2205
|
+
}
|
|
2206
|
+
return new ZodDiscriminatedUnion(__assign({ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion, discriminator: discriminator, options: options }, processCreateParams(params)));
|
|
2207
|
+
};
|
|
2208
|
+
return ZodDiscriminatedUnion;
|
|
2209
|
+
}(ZodType));
|
|
2210
|
+
function mergeValues(a, b) {
|
|
2211
|
+
var e_11, _a;
|
|
2212
|
+
var aType = getParsedType(a);
|
|
2213
|
+
var bType = getParsedType(b);
|
|
2214
|
+
if (a === b) {
|
|
2215
|
+
return { valid: true, data: a };
|
|
2216
|
+
}
|
|
2217
|
+
else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
2218
|
+
var bKeys_1 = util.objectKeys(b);
|
|
2219
|
+
var sharedKeys = util
|
|
2220
|
+
.objectKeys(a)
|
|
2221
|
+
.filter(function (key) { return bKeys_1.indexOf(key) !== -1; });
|
|
2222
|
+
var newObj = __assign(__assign({}, a), b);
|
|
2223
|
+
try {
|
|
2224
|
+
for (var sharedKeys_1 = __values(sharedKeys), sharedKeys_1_1 = sharedKeys_1.next(); !sharedKeys_1_1.done; sharedKeys_1_1 = sharedKeys_1.next()) {
|
|
2225
|
+
var key = sharedKeys_1_1.value;
|
|
2226
|
+
var sharedValue = mergeValues(a[key], b[key]);
|
|
2227
|
+
if (!sharedValue.valid) {
|
|
2228
|
+
return { valid: false };
|
|
2229
|
+
}
|
|
2230
|
+
newObj[key] = sharedValue.data;
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
2234
|
+
finally {
|
|
2235
|
+
try {
|
|
2236
|
+
if (sharedKeys_1_1 && !sharedKeys_1_1.done && (_a = sharedKeys_1.return)) _a.call(sharedKeys_1);
|
|
2237
|
+
}
|
|
2238
|
+
finally { if (e_11) throw e_11.error; }
|
|
2239
|
+
}
|
|
2240
|
+
return { valid: true, data: newObj };
|
|
2241
|
+
}
|
|
2242
|
+
else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
2243
|
+
if (a.length !== b.length) {
|
|
2244
|
+
return { valid: false };
|
|
2245
|
+
}
|
|
2246
|
+
var newArray = [];
|
|
2247
|
+
for (var index = 0; index < a.length; index++) {
|
|
2248
|
+
var itemA = a[index];
|
|
2249
|
+
var itemB = b[index];
|
|
2250
|
+
var sharedValue = mergeValues(itemA, itemB);
|
|
2251
|
+
if (!sharedValue.valid) {
|
|
2252
|
+
return { valid: false };
|
|
2253
|
+
}
|
|
2254
|
+
newArray.push(sharedValue.data);
|
|
2255
|
+
}
|
|
2256
|
+
return { valid: true, data: newArray };
|
|
2257
|
+
}
|
|
2258
|
+
else if (aType === ZodParsedType.date &&
|
|
2259
|
+
bType === ZodParsedType.date &&
|
|
2260
|
+
+a === +b) {
|
|
2261
|
+
return { valid: true, data: a };
|
|
2262
|
+
}
|
|
2263
|
+
else {
|
|
2264
|
+
return { valid: false };
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
var ZodIntersection = /** @class */ (function (_super) {
|
|
2268
|
+
__extends(ZodIntersection, _super);
|
|
2269
|
+
function ZodIntersection() {
|
|
2270
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2271
|
+
}
|
|
2272
|
+
ZodIntersection.prototype._parse = function (input) {
|
|
2273
|
+
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
2274
|
+
var handleParsed = function (parsedLeft, parsedRight) {
|
|
2275
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
2276
|
+
return INVALID;
|
|
2277
|
+
}
|
|
2278
|
+
var merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
2279
|
+
if (!merged.valid) {
|
|
2280
|
+
addIssueToContext(ctx, {
|
|
2281
|
+
code: ZodIssueCode.invalid_intersection_types,
|
|
2282
|
+
});
|
|
2283
|
+
return INVALID;
|
|
2284
|
+
}
|
|
2285
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
2286
|
+
status.dirty();
|
|
2287
|
+
}
|
|
2288
|
+
return { status: status.value, value: merged.data };
|
|
2289
|
+
};
|
|
2290
|
+
if (ctx.async) {
|
|
2291
|
+
return Promise.all([
|
|
2292
|
+
this._def.left._parseAsync({
|
|
2293
|
+
data: ctx.data,
|
|
2294
|
+
path: ctx.path,
|
|
2295
|
+
parent: ctx,
|
|
2296
|
+
}),
|
|
2297
|
+
this._def.right._parseAsync({
|
|
2298
|
+
data: ctx.data,
|
|
2299
|
+
path: ctx.path,
|
|
2300
|
+
parent: ctx,
|
|
2301
|
+
}),
|
|
2302
|
+
]).then(function (_a) {
|
|
2303
|
+
var _b = __read(_a, 2), left = _b[0], right = _b[1];
|
|
2304
|
+
return handleParsed(left, right);
|
|
2305
|
+
});
|
|
2306
|
+
}
|
|
2307
|
+
else {
|
|
2308
|
+
return handleParsed(this._def.left._parseSync({
|
|
2309
|
+
data: ctx.data,
|
|
2310
|
+
path: ctx.path,
|
|
2311
|
+
parent: ctx,
|
|
2312
|
+
}), this._def.right._parseSync({
|
|
2313
|
+
data: ctx.data,
|
|
2314
|
+
path: ctx.path,
|
|
2315
|
+
parent: ctx,
|
|
2316
|
+
}));
|
|
2317
|
+
}
|
|
2318
|
+
};
|
|
2319
|
+
ZodIntersection.create = function (left, right, params) {
|
|
2320
|
+
return new ZodIntersection(__assign({ left: left, right: right, typeName: ZodFirstPartyTypeKind.ZodIntersection }, processCreateParams(params)));
|
|
2321
|
+
};
|
|
2322
|
+
return ZodIntersection;
|
|
2323
|
+
}(ZodType));
|
|
2324
|
+
var ZodTuple = /** @class */ (function (_super) {
|
|
2325
|
+
__extends(ZodTuple, _super);
|
|
2326
|
+
function ZodTuple() {
|
|
2327
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2328
|
+
}
|
|
2329
|
+
ZodTuple.prototype._parse = function (input) {
|
|
2330
|
+
var _this = this;
|
|
2331
|
+
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
2332
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2333
|
+
addIssueToContext(ctx, {
|
|
2334
|
+
code: ZodIssueCode.invalid_type,
|
|
2335
|
+
expected: ZodParsedType.array,
|
|
2336
|
+
received: ctx.parsedType,
|
|
2337
|
+
});
|
|
2338
|
+
return INVALID;
|
|
2339
|
+
}
|
|
2340
|
+
if (ctx.data.length < this._def.items.length) {
|
|
2341
|
+
addIssueToContext(ctx, {
|
|
2342
|
+
code: ZodIssueCode.too_small,
|
|
2343
|
+
minimum: this._def.items.length,
|
|
2344
|
+
inclusive: true,
|
|
2345
|
+
type: "array",
|
|
2346
|
+
});
|
|
2347
|
+
return INVALID;
|
|
2348
|
+
}
|
|
2349
|
+
var rest = this._def.rest;
|
|
2350
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
2351
|
+
addIssueToContext(ctx, {
|
|
2352
|
+
code: ZodIssueCode.too_big,
|
|
2353
|
+
maximum: this._def.items.length,
|
|
2354
|
+
inclusive: true,
|
|
2355
|
+
type: "array",
|
|
2356
|
+
});
|
|
2357
|
+
status.dirty();
|
|
2358
|
+
}
|
|
2359
|
+
var items = ctx.data
|
|
2360
|
+
.map(function (item, itemIndex) {
|
|
2361
|
+
var schema = _this._def.items[itemIndex] || _this._def.rest;
|
|
2362
|
+
if (!schema)
|
|
2363
|
+
return null;
|
|
2364
|
+
return schema._parse({
|
|
2365
|
+
data: item,
|
|
2366
|
+
path: __spreadArray(__spreadArray([], __read(ctx.path), false), [itemIndex], false),
|
|
2367
|
+
parent: ctx,
|
|
2368
|
+
});
|
|
2369
|
+
})
|
|
2370
|
+
.filter(function (x) { return !!x; }); // filter nulls
|
|
2371
|
+
if (ctx.async) {
|
|
2372
|
+
return Promise.all(items).then(function (results) {
|
|
2373
|
+
return ParseStatus.mergeArray(status, results);
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2376
|
+
else {
|
|
2377
|
+
return ParseStatus.mergeArray(status, items);
|
|
2378
|
+
}
|
|
2379
|
+
};
|
|
2380
|
+
Object.defineProperty(ZodTuple.prototype, "items", {
|
|
2381
|
+
get: function () {
|
|
2382
|
+
return this._def.items;
|
|
2383
|
+
},
|
|
2384
|
+
enumerable: false,
|
|
2385
|
+
configurable: true
|
|
2386
|
+
});
|
|
2387
|
+
ZodTuple.prototype.rest = function (rest) {
|
|
2388
|
+
return new ZodTuple(__assign(__assign({}, this._def), { rest: rest }));
|
|
2389
|
+
};
|
|
2390
|
+
ZodTuple.create = function (schemas, params) {
|
|
2391
|
+
return new ZodTuple(__assign({ items: schemas, typeName: ZodFirstPartyTypeKind.ZodTuple, rest: null }, processCreateParams(params)));
|
|
2392
|
+
};
|
|
2393
|
+
return ZodTuple;
|
|
2394
|
+
}(ZodType));
|
|
2395
|
+
var ZodRecord = /** @class */ (function (_super) {
|
|
2396
|
+
__extends(ZodRecord, _super);
|
|
2397
|
+
function ZodRecord() {
|
|
2398
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2399
|
+
}
|
|
2400
|
+
Object.defineProperty(ZodRecord.prototype, "keySchema", {
|
|
2401
|
+
get: function () {
|
|
2402
|
+
return this._def.keyType;
|
|
2403
|
+
},
|
|
2404
|
+
enumerable: false,
|
|
2405
|
+
configurable: true
|
|
2406
|
+
});
|
|
2407
|
+
Object.defineProperty(ZodRecord.prototype, "valueSchema", {
|
|
2408
|
+
get: function () {
|
|
2409
|
+
return this._def.valueType;
|
|
2410
|
+
},
|
|
2411
|
+
enumerable: false,
|
|
2412
|
+
configurable: true
|
|
2413
|
+
});
|
|
2414
|
+
ZodRecord.prototype._parse = function (input) {
|
|
2415
|
+
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
2416
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
2417
|
+
addIssueToContext(ctx, {
|
|
2418
|
+
code: ZodIssueCode.invalid_type,
|
|
2419
|
+
expected: ZodParsedType.object,
|
|
2420
|
+
received: ctx.parsedType,
|
|
2421
|
+
});
|
|
2422
|
+
return INVALID;
|
|
2423
|
+
}
|
|
2424
|
+
var pairs = [];
|
|
2425
|
+
var keyType = this._def.keyType;
|
|
2426
|
+
var valueType = this._def.valueType;
|
|
2427
|
+
for (var key in ctx.data) {
|
|
2428
|
+
pairs.push({
|
|
2429
|
+
key: keyType._parse({
|
|
2430
|
+
data: key,
|
|
2431
|
+
path: __spreadArray(__spreadArray([], __read(ctx.path), false), [key], false),
|
|
2432
|
+
parent: ctx,
|
|
2433
|
+
}),
|
|
2434
|
+
value: valueType._parse({
|
|
2435
|
+
data: ctx.data[key],
|
|
2436
|
+
path: __spreadArray(__spreadArray([], __read(ctx.path), false), [key], false),
|
|
2437
|
+
parent: ctx,
|
|
2438
|
+
}),
|
|
2439
|
+
});
|
|
2440
|
+
}
|
|
2441
|
+
if (ctx.async) {
|
|
2442
|
+
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
2443
|
+
}
|
|
2444
|
+
else {
|
|
2445
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2448
|
+
Object.defineProperty(ZodRecord.prototype, "element", {
|
|
2449
|
+
get: function () {
|
|
2450
|
+
return this._def.valueType;
|
|
2451
|
+
},
|
|
2452
|
+
enumerable: false,
|
|
2453
|
+
configurable: true
|
|
2454
|
+
});
|
|
2455
|
+
ZodRecord.create = function (first, second, third) {
|
|
2456
|
+
if (second instanceof ZodType) {
|
|
2457
|
+
return new ZodRecord(__assign({ keyType: first, valueType: second, typeName: ZodFirstPartyTypeKind.ZodRecord }, processCreateParams(third)));
|
|
2458
|
+
}
|
|
2459
|
+
return new ZodRecord(__assign({ keyType: ZodString.create(), valueType: first, typeName: ZodFirstPartyTypeKind.ZodRecord }, processCreateParams(second)));
|
|
2460
|
+
};
|
|
2461
|
+
return ZodRecord;
|
|
2462
|
+
}(ZodType));
|
|
2463
|
+
var ZodMap = /** @class */ (function (_super) {
|
|
2464
|
+
__extends(ZodMap, _super);
|
|
2465
|
+
function ZodMap() {
|
|
2466
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2467
|
+
}
|
|
2468
|
+
ZodMap.prototype._parse = function (input) {
|
|
2469
|
+
var e_12, _a;
|
|
2470
|
+
var _this = this;
|
|
2471
|
+
var _b = this._processInputParams(input), status = _b.status, ctx = _b.ctx;
|
|
2472
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
2473
|
+
addIssueToContext(ctx, {
|
|
2474
|
+
code: ZodIssueCode.invalid_type,
|
|
2475
|
+
expected: ZodParsedType.map,
|
|
2476
|
+
received: ctx.parsedType,
|
|
2477
|
+
});
|
|
2478
|
+
return INVALID;
|
|
2479
|
+
}
|
|
2480
|
+
var keyType = this._def.keyType;
|
|
2481
|
+
var valueType = this._def.valueType;
|
|
2482
|
+
var pairs = __spreadArray([], __read(ctx.data.entries()), false).map(function (_a, index) {
|
|
2483
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
2484
|
+
return {
|
|
2485
|
+
key: keyType._parse({
|
|
2486
|
+
data: key,
|
|
2487
|
+
path: __spreadArray(__spreadArray([], __read(ctx.path), false), [index, "key"], false),
|
|
2488
|
+
parent: ctx,
|
|
2489
|
+
}),
|
|
2490
|
+
value: valueType._parse({
|
|
2491
|
+
data: value,
|
|
2492
|
+
path: __spreadArray(__spreadArray([], __read(ctx.path), false), [index, "value"], false),
|
|
2493
|
+
parent: ctx,
|
|
2494
|
+
}),
|
|
2495
|
+
};
|
|
2496
|
+
});
|
|
2497
|
+
if (ctx.async) {
|
|
2498
|
+
var finalMap_1 = new Map();
|
|
2499
|
+
return Promise.resolve().then(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2500
|
+
var pairs_3, pairs_3_1, pair, key, value, e_13_1;
|
|
2501
|
+
var e_13, _a;
|
|
2502
|
+
return __generator(this, function (_b) {
|
|
2503
|
+
switch (_b.label) {
|
|
2504
|
+
case 0:
|
|
2505
|
+
_b.trys.push([0, 6, 7, 8]);
|
|
2506
|
+
pairs_3 = __values(pairs), pairs_3_1 = pairs_3.next();
|
|
2507
|
+
_b.label = 1;
|
|
2508
|
+
case 1:
|
|
2509
|
+
if (!!pairs_3_1.done) return [3 /*break*/, 5];
|
|
2510
|
+
pair = pairs_3_1.value;
|
|
2511
|
+
return [4 /*yield*/, pair.key];
|
|
2512
|
+
case 2:
|
|
2513
|
+
key = _b.sent();
|
|
2514
|
+
return [4 /*yield*/, pair.value];
|
|
2515
|
+
case 3:
|
|
2516
|
+
value = _b.sent();
|
|
2517
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
2518
|
+
return [2 /*return*/, INVALID];
|
|
2519
|
+
}
|
|
2520
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
2521
|
+
status.dirty();
|
|
2522
|
+
}
|
|
2523
|
+
finalMap_1.set(key.value, value.value);
|
|
2524
|
+
_b.label = 4;
|
|
2525
|
+
case 4:
|
|
2526
|
+
pairs_3_1 = pairs_3.next();
|
|
2527
|
+
return [3 /*break*/, 1];
|
|
2528
|
+
case 5: return [3 /*break*/, 8];
|
|
2529
|
+
case 6:
|
|
2530
|
+
e_13_1 = _b.sent();
|
|
2531
|
+
e_13 = { error: e_13_1 };
|
|
2532
|
+
return [3 /*break*/, 8];
|
|
2533
|
+
case 7:
|
|
2534
|
+
try {
|
|
2535
|
+
if (pairs_3_1 && !pairs_3_1.done && (_a = pairs_3.return)) _a.call(pairs_3);
|
|
2536
|
+
}
|
|
2537
|
+
finally { if (e_13) throw e_13.error; }
|
|
2538
|
+
return [7 /*endfinally*/];
|
|
2539
|
+
case 8: return [2 /*return*/, { status: status.value, value: finalMap_1 }];
|
|
2540
|
+
}
|
|
2541
|
+
});
|
|
2542
|
+
}); });
|
|
2543
|
+
}
|
|
2544
|
+
else {
|
|
2545
|
+
var finalMap = new Map();
|
|
2546
|
+
try {
|
|
2547
|
+
for (var pairs_2 = __values(pairs), pairs_2_1 = pairs_2.next(); !pairs_2_1.done; pairs_2_1 = pairs_2.next()) {
|
|
2548
|
+
var pair = pairs_2_1.value;
|
|
2549
|
+
var key = pair.key;
|
|
2550
|
+
var value = pair.value;
|
|
2551
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
2552
|
+
return INVALID;
|
|
2553
|
+
}
|
|
2554
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
2555
|
+
status.dirty();
|
|
2556
|
+
}
|
|
2557
|
+
finalMap.set(key.value, value.value);
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
2561
|
+
finally {
|
|
2562
|
+
try {
|
|
2563
|
+
if (pairs_2_1 && !pairs_2_1.done && (_a = pairs_2.return)) _a.call(pairs_2);
|
|
2564
|
+
}
|
|
2565
|
+
finally { if (e_12) throw e_12.error; }
|
|
2566
|
+
}
|
|
2567
|
+
return { status: status.value, value: finalMap };
|
|
2568
|
+
}
|
|
2569
|
+
};
|
|
2570
|
+
ZodMap.create = function (keyType, valueType, params) {
|
|
2571
|
+
return new ZodMap(__assign({ valueType: valueType, keyType: keyType, typeName: ZodFirstPartyTypeKind.ZodMap }, processCreateParams(params)));
|
|
2572
|
+
};
|
|
2573
|
+
return ZodMap;
|
|
2574
|
+
}(ZodType));
|
|
2575
|
+
var ZodSet = /** @class */ (function (_super) {
|
|
2576
|
+
__extends(ZodSet, _super);
|
|
2577
|
+
function ZodSet() {
|
|
2578
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2579
|
+
}
|
|
2580
|
+
ZodSet.prototype._parse = function (input) {
|
|
2581
|
+
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
2582
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
2583
|
+
addIssueToContext(ctx, {
|
|
2584
|
+
code: ZodIssueCode.invalid_type,
|
|
2585
|
+
expected: ZodParsedType.set,
|
|
2586
|
+
received: ctx.parsedType,
|
|
2587
|
+
});
|
|
2588
|
+
return INVALID;
|
|
2589
|
+
}
|
|
2590
|
+
var def = this._def;
|
|
2591
|
+
if (def.minSize !== null) {
|
|
2592
|
+
if (ctx.data.size < def.minSize.value) {
|
|
2593
|
+
addIssueToContext(ctx, {
|
|
2594
|
+
code: ZodIssueCode.too_small,
|
|
2595
|
+
minimum: def.minSize.value,
|
|
2596
|
+
type: "set",
|
|
2597
|
+
inclusive: true,
|
|
2598
|
+
message: def.minSize.message,
|
|
2599
|
+
});
|
|
2600
|
+
status.dirty();
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
if (def.maxSize !== null) {
|
|
2604
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
2605
|
+
addIssueToContext(ctx, {
|
|
2606
|
+
code: ZodIssueCode.too_big,
|
|
2607
|
+
maximum: def.maxSize.value,
|
|
2608
|
+
type: "set",
|
|
2609
|
+
inclusive: true,
|
|
2610
|
+
message: def.maxSize.message,
|
|
2611
|
+
});
|
|
2612
|
+
status.dirty();
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
var valueType = this._def.valueType;
|
|
2616
|
+
function finalizeSet(elements) {
|
|
2617
|
+
var e_14, _a;
|
|
2618
|
+
var parsedSet = new Set();
|
|
2619
|
+
try {
|
|
2620
|
+
for (var elements_1 = __values(elements), elements_1_1 = elements_1.next(); !elements_1_1.done; elements_1_1 = elements_1.next()) {
|
|
2621
|
+
var element = elements_1_1.value;
|
|
2622
|
+
if (element.status === "aborted")
|
|
2623
|
+
return INVALID;
|
|
2624
|
+
if (element.status === "dirty")
|
|
2625
|
+
status.dirty();
|
|
2626
|
+
parsedSet.add(element.value);
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
2630
|
+
finally {
|
|
2631
|
+
try {
|
|
2632
|
+
if (elements_1_1 && !elements_1_1.done && (_a = elements_1.return)) _a.call(elements_1);
|
|
2633
|
+
}
|
|
2634
|
+
finally { if (e_14) throw e_14.error; }
|
|
2635
|
+
}
|
|
2636
|
+
return { status: status.value, value: parsedSet };
|
|
2637
|
+
}
|
|
2638
|
+
var elements = __spreadArray([], __read(ctx.data.values()), false).map(function (item, i) {
|
|
2639
|
+
return valueType._parse({ data: item, path: __spreadArray(__spreadArray([], __read(ctx.path), false), [i], false), parent: ctx });
|
|
2640
|
+
});
|
|
2641
|
+
if (ctx.async) {
|
|
2642
|
+
return Promise.all(elements).then(function (elements) { return finalizeSet(elements); });
|
|
2643
|
+
}
|
|
2644
|
+
else {
|
|
2645
|
+
return finalizeSet(elements);
|
|
2646
|
+
}
|
|
2647
|
+
};
|
|
2648
|
+
ZodSet.prototype.min = function (minSize, message) {
|
|
2649
|
+
return new ZodSet(__assign(__assign({}, this._def), { minSize: { value: minSize, message: errorUtil.toString(message) } }));
|
|
2650
|
+
};
|
|
2651
|
+
ZodSet.prototype.max = function (maxSize, message) {
|
|
2652
|
+
return new ZodSet(__assign(__assign({}, this._def), { maxSize: { value: maxSize, message: errorUtil.toString(message) } }));
|
|
2653
|
+
};
|
|
2654
|
+
ZodSet.prototype.size = function (size, message) {
|
|
2655
|
+
return this.min(size, message).max(size, message);
|
|
2656
|
+
};
|
|
2657
|
+
ZodSet.prototype.nonempty = function (message) {
|
|
2658
|
+
return this.min(1, message);
|
|
2659
|
+
};
|
|
2660
|
+
ZodSet.create = function (valueType, params) {
|
|
2661
|
+
return new ZodSet(__assign({ valueType: valueType, minSize: null, maxSize: null, typeName: ZodFirstPartyTypeKind.ZodSet }, processCreateParams(params)));
|
|
2662
|
+
};
|
|
2663
|
+
return ZodSet;
|
|
2664
|
+
}(ZodType));
|
|
2665
|
+
var ZodFunction = /** @class */ (function (_super) {
|
|
2666
|
+
__extends(ZodFunction, _super);
|
|
2667
|
+
function ZodFunction() {
|
|
2668
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
2669
|
+
_this.validate = _this.implement;
|
|
2670
|
+
return _this;
|
|
2671
|
+
}
|
|
2672
|
+
ZodFunction.prototype._parse = function (input) {
|
|
2673
|
+
var _this = this;
|
|
2674
|
+
var ctx = this._processInputParams(input).ctx;
|
|
2675
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
2676
|
+
addIssueToContext(ctx, {
|
|
2677
|
+
code: ZodIssueCode.invalid_type,
|
|
2678
|
+
expected: ZodParsedType.function,
|
|
2679
|
+
received: ctx.parsedType,
|
|
2680
|
+
});
|
|
2681
|
+
return INVALID;
|
|
2682
|
+
}
|
|
2683
|
+
function makeArgsIssue(args, error) {
|
|
2684
|
+
return makeIssue({
|
|
2685
|
+
data: args,
|
|
2686
|
+
path: ctx.path,
|
|
2687
|
+
errorMaps: [
|
|
2688
|
+
ctx.contextualErrorMap,
|
|
2689
|
+
ctx.schemaErrorMap,
|
|
2690
|
+
overrideErrorMap,
|
|
2691
|
+
defaultErrorMap,
|
|
2692
|
+
].filter(function (x) { return !!x; }),
|
|
2693
|
+
issueData: {
|
|
2694
|
+
code: ZodIssueCode.invalid_arguments,
|
|
2695
|
+
argumentsError: error,
|
|
2696
|
+
},
|
|
2697
|
+
});
|
|
2698
|
+
}
|
|
2699
|
+
function makeReturnsIssue(returns, error) {
|
|
2700
|
+
return makeIssue({
|
|
2701
|
+
data: returns,
|
|
2702
|
+
path: ctx.path,
|
|
2703
|
+
errorMaps: [
|
|
2704
|
+
ctx.contextualErrorMap,
|
|
2705
|
+
ctx.schemaErrorMap,
|
|
2706
|
+
overrideErrorMap,
|
|
2707
|
+
defaultErrorMap,
|
|
2708
|
+
].filter(function (x) { return !!x; }),
|
|
2709
|
+
issueData: {
|
|
2710
|
+
code: ZodIssueCode.invalid_return_type,
|
|
2711
|
+
returnTypeError: error,
|
|
2712
|
+
},
|
|
2713
|
+
});
|
|
2714
|
+
}
|
|
2715
|
+
var params = { errorMap: ctx.contextualErrorMap };
|
|
2716
|
+
var fn = ctx.data;
|
|
2717
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
2718
|
+
return OK(function () {
|
|
2719
|
+
var args = [];
|
|
2720
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2721
|
+
args[_i] = arguments[_i];
|
|
2722
|
+
}
|
|
2723
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
2724
|
+
var error, parsedArgs, result, parsedReturns;
|
|
2725
|
+
return __generator(this, function (_a) {
|
|
2726
|
+
switch (_a.label) {
|
|
2727
|
+
case 0:
|
|
2728
|
+
error = new ZodError([]);
|
|
2729
|
+
return [4 /*yield*/, this._def.args
|
|
2730
|
+
.parseAsync(args, params)
|
|
2731
|
+
.catch(function (e) {
|
|
2732
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
2733
|
+
throw error;
|
|
2734
|
+
})];
|
|
2735
|
+
case 1:
|
|
2736
|
+
parsedArgs = _a.sent();
|
|
2737
|
+
return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(parsedArgs), false))];
|
|
2738
|
+
case 2:
|
|
2739
|
+
result = _a.sent();
|
|
2740
|
+
return [4 /*yield*/, this._def
|
|
2741
|
+
.returns._def.type
|
|
2742
|
+
.parseAsync(result, params)
|
|
2743
|
+
.catch(function (e) {
|
|
2744
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
2745
|
+
throw error;
|
|
2746
|
+
})];
|
|
2747
|
+
case 3:
|
|
2748
|
+
parsedReturns = _a.sent();
|
|
2749
|
+
return [2 /*return*/, parsedReturns];
|
|
2750
|
+
}
|
|
2751
|
+
});
|
|
2752
|
+
});
|
|
2753
|
+
});
|
|
2754
|
+
}
|
|
2755
|
+
else {
|
|
2756
|
+
return OK(function () {
|
|
2757
|
+
var args = [];
|
|
2758
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2759
|
+
args[_i] = arguments[_i];
|
|
2760
|
+
}
|
|
2761
|
+
var parsedArgs = _this._def.args.safeParse(args, params);
|
|
2762
|
+
if (!parsedArgs.success) {
|
|
2763
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
2764
|
+
}
|
|
2765
|
+
var result = fn.apply(void 0, __spreadArray([], __read(parsedArgs.data), false));
|
|
2766
|
+
var parsedReturns = _this._def.returns.safeParse(result, params);
|
|
2767
|
+
if (!parsedReturns.success) {
|
|
2768
|
+
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
2769
|
+
}
|
|
2770
|
+
return parsedReturns.data;
|
|
2771
|
+
});
|
|
2772
|
+
}
|
|
2773
|
+
};
|
|
2774
|
+
ZodFunction.prototype.parameters = function () {
|
|
2775
|
+
return this._def.args;
|
|
2776
|
+
};
|
|
2777
|
+
ZodFunction.prototype.returnType = function () {
|
|
2778
|
+
return this._def.returns;
|
|
2779
|
+
};
|
|
2780
|
+
ZodFunction.prototype.args = function () {
|
|
2781
|
+
var items = [];
|
|
2782
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2783
|
+
items[_i] = arguments[_i];
|
|
2784
|
+
}
|
|
2785
|
+
return new ZodFunction(__assign(__assign({}, this._def), { args: ZodTuple.create(items).rest(ZodUnknown.create()) }));
|
|
2786
|
+
};
|
|
2787
|
+
ZodFunction.prototype.returns = function (returnType) {
|
|
2788
|
+
return new ZodFunction(__assign(__assign({}, this._def), { returns: returnType }));
|
|
2789
|
+
};
|
|
2790
|
+
ZodFunction.prototype.implement = function (func) {
|
|
2791
|
+
var validatedFunc = this.parse(func);
|
|
2792
|
+
return validatedFunc;
|
|
2793
|
+
};
|
|
2794
|
+
ZodFunction.prototype.strictImplement = function (func) {
|
|
2795
|
+
var validatedFunc = this.parse(func);
|
|
2796
|
+
return validatedFunc;
|
|
2797
|
+
};
|
|
2798
|
+
ZodFunction.create = function (args, returns, params) {
|
|
2799
|
+
return new ZodFunction(__assign({ args: (args
|
|
2800
|
+
? args.rest(ZodUnknown.create())
|
|
2801
|
+
: ZodTuple.create([]).rest(ZodUnknown.create())), returns: returns || ZodUnknown.create(), typeName: ZodFirstPartyTypeKind.ZodFunction }, processCreateParams(params)));
|
|
2802
|
+
};
|
|
2803
|
+
return ZodFunction;
|
|
2804
|
+
}(ZodType));
|
|
2805
|
+
var ZodLazy = /** @class */ (function (_super) {
|
|
2806
|
+
__extends(ZodLazy, _super);
|
|
2807
|
+
function ZodLazy() {
|
|
2808
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2809
|
+
}
|
|
2810
|
+
Object.defineProperty(ZodLazy.prototype, "schema", {
|
|
2811
|
+
get: function () {
|
|
2812
|
+
return this._def.getter();
|
|
2813
|
+
},
|
|
2814
|
+
enumerable: false,
|
|
2815
|
+
configurable: true
|
|
2816
|
+
});
|
|
2817
|
+
ZodLazy.prototype._parse = function (input) {
|
|
2818
|
+
var ctx = this._processInputParams(input).ctx;
|
|
2819
|
+
var lazySchema = this._def.getter();
|
|
2820
|
+
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
2821
|
+
};
|
|
2822
|
+
ZodLazy.create = function (getter, params) {
|
|
2823
|
+
return new ZodLazy(__assign({ getter: getter, typeName: ZodFirstPartyTypeKind.ZodLazy }, processCreateParams(params)));
|
|
2824
|
+
};
|
|
2825
|
+
return ZodLazy;
|
|
2826
|
+
}(ZodType));
|
|
2827
|
+
var ZodLiteral = /** @class */ (function (_super) {
|
|
2828
|
+
__extends(ZodLiteral, _super);
|
|
2829
|
+
function ZodLiteral() {
|
|
2830
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2831
|
+
}
|
|
2832
|
+
ZodLiteral.prototype._parse = function (input) {
|
|
2833
|
+
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
2834
|
+
if (ctx.data !== this._def.value) {
|
|
2835
|
+
addIssueToContext(ctx, {
|
|
2836
|
+
code: ZodIssueCode.invalid_type,
|
|
2837
|
+
expected: getParsedType(this._def.value),
|
|
2838
|
+
received: ctx.parsedType,
|
|
2839
|
+
});
|
|
2840
|
+
return INVALID;
|
|
2841
|
+
}
|
|
2842
|
+
return { status: status.value, value: ctx.data };
|
|
2843
|
+
};
|
|
2844
|
+
Object.defineProperty(ZodLiteral.prototype, "value", {
|
|
2845
|
+
get: function () {
|
|
2846
|
+
return this._def.value;
|
|
2847
|
+
},
|
|
2848
|
+
enumerable: false,
|
|
2849
|
+
configurable: true
|
|
2850
|
+
});
|
|
2851
|
+
ZodLiteral.create = function (value, params) {
|
|
2852
|
+
return new ZodLiteral(__assign({ value: value, typeName: ZodFirstPartyTypeKind.ZodLiteral }, processCreateParams(params)));
|
|
2853
|
+
};
|
|
2854
|
+
return ZodLiteral;
|
|
2855
|
+
}(ZodType));
|
|
2856
|
+
function createZodEnum(values) {
|
|
2857
|
+
return new ZodEnum({
|
|
2858
|
+
values: values,
|
|
2859
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
2860
|
+
});
|
|
2861
|
+
}
|
|
2862
|
+
var ZodEnum = /** @class */ (function (_super) {
|
|
2863
|
+
__extends(ZodEnum, _super);
|
|
2864
|
+
function ZodEnum() {
|
|
2865
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2866
|
+
}
|
|
2867
|
+
ZodEnum.prototype._parse = function (input) {
|
|
2868
|
+
var ctx = this._processInputParams(input).ctx;
|
|
2869
|
+
if (this._def.values.indexOf(ctx.data) === -1) {
|
|
2870
|
+
addIssueToContext(ctx, {
|
|
2871
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
2872
|
+
options: this._def.values,
|
|
2873
|
+
});
|
|
2874
|
+
return INVALID;
|
|
2875
|
+
}
|
|
2876
|
+
return OK(ctx.data);
|
|
2877
|
+
};
|
|
2878
|
+
Object.defineProperty(ZodEnum.prototype, "options", {
|
|
2879
|
+
get: function () {
|
|
2880
|
+
return this._def.values;
|
|
2881
|
+
},
|
|
2882
|
+
enumerable: false,
|
|
2883
|
+
configurable: true
|
|
2884
|
+
});
|
|
2885
|
+
Object.defineProperty(ZodEnum.prototype, "enum", {
|
|
2886
|
+
get: function () {
|
|
2887
|
+
var e_15, _a;
|
|
2888
|
+
var enumValues = {};
|
|
2889
|
+
try {
|
|
2890
|
+
for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2891
|
+
var val = _c.value;
|
|
2892
|
+
enumValues[val] = val;
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
2896
|
+
finally {
|
|
2897
|
+
try {
|
|
2898
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2899
|
+
}
|
|
2900
|
+
finally { if (e_15) throw e_15.error; }
|
|
2901
|
+
}
|
|
2902
|
+
return enumValues;
|
|
2903
|
+
},
|
|
2904
|
+
enumerable: false,
|
|
2905
|
+
configurable: true
|
|
2906
|
+
});
|
|
2907
|
+
Object.defineProperty(ZodEnum.prototype, "Values", {
|
|
2908
|
+
get: function () {
|
|
2909
|
+
var e_16, _a;
|
|
2910
|
+
var enumValues = {};
|
|
2911
|
+
try {
|
|
2912
|
+
for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2913
|
+
var val = _c.value;
|
|
2914
|
+
enumValues[val] = val;
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
2918
|
+
finally {
|
|
2919
|
+
try {
|
|
2920
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2921
|
+
}
|
|
2922
|
+
finally { if (e_16) throw e_16.error; }
|
|
2923
|
+
}
|
|
2924
|
+
return enumValues;
|
|
2925
|
+
},
|
|
2926
|
+
enumerable: false,
|
|
2927
|
+
configurable: true
|
|
2928
|
+
});
|
|
2929
|
+
Object.defineProperty(ZodEnum.prototype, "Enum", {
|
|
2930
|
+
get: function () {
|
|
2931
|
+
var e_17, _a;
|
|
2932
|
+
var enumValues = {};
|
|
2933
|
+
try {
|
|
2934
|
+
for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2935
|
+
var val = _c.value;
|
|
2936
|
+
enumValues[val] = val;
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
2940
|
+
finally {
|
|
2941
|
+
try {
|
|
2942
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2943
|
+
}
|
|
2944
|
+
finally { if (e_17) throw e_17.error; }
|
|
2945
|
+
}
|
|
2946
|
+
return enumValues;
|
|
2947
|
+
},
|
|
2948
|
+
enumerable: false,
|
|
2949
|
+
configurable: true
|
|
2950
|
+
});
|
|
2951
|
+
ZodEnum.create = createZodEnum;
|
|
2952
|
+
return ZodEnum;
|
|
2953
|
+
}(ZodType));
|
|
2954
|
+
var ZodNativeEnum = /** @class */ (function (_super) {
|
|
2955
|
+
__extends(ZodNativeEnum, _super);
|
|
2956
|
+
function ZodNativeEnum() {
|
|
2957
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2958
|
+
}
|
|
2959
|
+
ZodNativeEnum.prototype._parse = function (input) {
|
|
2960
|
+
var ctx = this._processInputParams(input).ctx;
|
|
2961
|
+
var nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
2962
|
+
if (nativeEnumValues.indexOf(ctx.data) === -1) {
|
|
2963
|
+
addIssueToContext(ctx, {
|
|
2964
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
2965
|
+
options: util.objectValues(nativeEnumValues),
|
|
2966
|
+
});
|
|
2967
|
+
return INVALID;
|
|
2968
|
+
}
|
|
2969
|
+
return OK(ctx.data);
|
|
2970
|
+
};
|
|
2971
|
+
ZodNativeEnum.create = function (values, params) {
|
|
2972
|
+
return new ZodNativeEnum(__assign({ values: values, typeName: ZodFirstPartyTypeKind.ZodNativeEnum }, processCreateParams(params)));
|
|
2973
|
+
};
|
|
2974
|
+
return ZodNativeEnum;
|
|
2975
|
+
}(ZodType));
|
|
2976
|
+
var ZodPromise = /** @class */ (function (_super) {
|
|
2977
|
+
__extends(ZodPromise, _super);
|
|
2978
|
+
function ZodPromise() {
|
|
2979
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2980
|
+
}
|
|
2981
|
+
ZodPromise.prototype._parse = function (input) {
|
|
2982
|
+
var _this = this;
|
|
2983
|
+
var ctx = this._processInputParams(input).ctx;
|
|
2984
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.async === false) {
|
|
2985
|
+
addIssueToContext(ctx, {
|
|
2986
|
+
code: ZodIssueCode.invalid_type,
|
|
2987
|
+
expected: ZodParsedType.promise,
|
|
2988
|
+
received: ctx.parsedType,
|
|
2989
|
+
});
|
|
2990
|
+
return INVALID;
|
|
2991
|
+
}
|
|
2992
|
+
var promisified = ctx.parsedType === ZodParsedType.promise
|
|
2993
|
+
? ctx.data
|
|
2994
|
+
: Promise.resolve(ctx.data);
|
|
2995
|
+
return OK(promisified.then(function (data) {
|
|
2996
|
+
return _this._def.type.parseAsync(data, {
|
|
2997
|
+
path: ctx.path,
|
|
2998
|
+
errorMap: ctx.contextualErrorMap,
|
|
2999
|
+
});
|
|
3000
|
+
}));
|
|
3001
|
+
};
|
|
3002
|
+
ZodPromise.create = function (schema, params) {
|
|
3003
|
+
return new ZodPromise(__assign({ type: schema, typeName: ZodFirstPartyTypeKind.ZodPromise }, processCreateParams(params)));
|
|
3004
|
+
};
|
|
3005
|
+
return ZodPromise;
|
|
3006
|
+
}(ZodType));
|
|
3007
|
+
var ZodEffects = /** @class */ (function (_super) {
|
|
3008
|
+
__extends(ZodEffects, _super);
|
|
3009
|
+
function ZodEffects() {
|
|
3010
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
3011
|
+
}
|
|
3012
|
+
ZodEffects.prototype.innerType = function () {
|
|
3013
|
+
return this._def.schema;
|
|
3014
|
+
};
|
|
3015
|
+
ZodEffects.prototype._parse = function (input) {
|
|
3016
|
+
var _this = this;
|
|
3017
|
+
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
3018
|
+
var effect = this._def.effect || null;
|
|
3019
|
+
if (effect.type === "preprocess") {
|
|
3020
|
+
var processed = effect.transform(ctx.data);
|
|
3021
|
+
if (ctx.async) {
|
|
3022
|
+
return Promise.resolve(processed).then(function (processed) {
|
|
3023
|
+
return _this._def.schema._parseAsync({
|
|
3024
|
+
data: processed,
|
|
3025
|
+
path: ctx.path,
|
|
3026
|
+
parent: ctx,
|
|
3027
|
+
});
|
|
3028
|
+
});
|
|
3029
|
+
}
|
|
3030
|
+
else {
|
|
3031
|
+
return this._def.schema._parseSync({
|
|
3032
|
+
data: processed,
|
|
3033
|
+
path: ctx.path,
|
|
3034
|
+
parent: ctx,
|
|
3035
|
+
});
|
|
3036
|
+
}
|
|
3037
|
+
}
|
|
3038
|
+
if (effect.type === "refinement") {
|
|
3039
|
+
var checkCtx_1 = {
|
|
3040
|
+
addIssue: function (arg) {
|
|
3041
|
+
addIssueToContext(ctx, arg);
|
|
3042
|
+
if (arg.fatal) {
|
|
3043
|
+
status.abort();
|
|
3044
|
+
}
|
|
3045
|
+
else {
|
|
3046
|
+
status.dirty();
|
|
3047
|
+
}
|
|
3048
|
+
},
|
|
3049
|
+
get path() {
|
|
3050
|
+
return ctx.path;
|
|
3051
|
+
},
|
|
3052
|
+
};
|
|
3053
|
+
checkCtx_1.addIssue = checkCtx_1.addIssue.bind(checkCtx_1);
|
|
3054
|
+
var executeRefinement_1 = function (acc
|
|
3055
|
+
// effect: RefinementEffect<any>
|
|
3056
|
+
) {
|
|
3057
|
+
var result = effect.refinement(acc, checkCtx_1);
|
|
3058
|
+
if (ctx.async) {
|
|
3059
|
+
return Promise.resolve(result);
|
|
3060
|
+
}
|
|
3061
|
+
if (result instanceof Promise) {
|
|
3062
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3063
|
+
}
|
|
3064
|
+
return acc;
|
|
3065
|
+
};
|
|
3066
|
+
if (ctx.async === false) {
|
|
3067
|
+
var inner = this._def.schema._parseSync({
|
|
3068
|
+
data: ctx.data,
|
|
3069
|
+
path: ctx.path,
|
|
3070
|
+
parent: ctx,
|
|
3071
|
+
});
|
|
3072
|
+
if (inner.status === "aborted")
|
|
3073
|
+
return INVALID;
|
|
3074
|
+
if (inner.status === "dirty")
|
|
3075
|
+
status.dirty();
|
|
3076
|
+
// return value is ignored
|
|
3077
|
+
executeRefinement_1(inner.value);
|
|
3078
|
+
return { status: status.value, value: inner.value };
|
|
3079
|
+
}
|
|
3080
|
+
else {
|
|
3081
|
+
return this._def.schema
|
|
3082
|
+
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
3083
|
+
.then(function (inner) {
|
|
3084
|
+
if (inner.status === "aborted")
|
|
3085
|
+
return INVALID;
|
|
3086
|
+
if (inner.status === "dirty")
|
|
3087
|
+
status.dirty();
|
|
3088
|
+
return executeRefinement_1(inner.value).then(function () {
|
|
3089
|
+
return { status: status.value, value: inner.value };
|
|
3090
|
+
});
|
|
3091
|
+
});
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
if (effect.type === "transform") {
|
|
3095
|
+
if (ctx.async === false) {
|
|
3096
|
+
var base = this._def.schema._parseSync({
|
|
3097
|
+
data: ctx.data,
|
|
3098
|
+
path: ctx.path,
|
|
3099
|
+
parent: ctx,
|
|
3100
|
+
});
|
|
3101
|
+
// if (base.status === "aborted") return INVALID;
|
|
3102
|
+
// if (base.status === "dirty") {
|
|
3103
|
+
// return { status: "dirty", value: base.value };
|
|
3104
|
+
// }
|
|
3105
|
+
if (!isValid(base))
|
|
3106
|
+
return base;
|
|
3107
|
+
var result = effect.transform(base.value);
|
|
3108
|
+
if (result instanceof Promise) {
|
|
3109
|
+
throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3110
|
+
}
|
|
3111
|
+
return OK(result);
|
|
3112
|
+
}
|
|
3113
|
+
else {
|
|
3114
|
+
return this._def.schema
|
|
3115
|
+
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
3116
|
+
.then(function (base) {
|
|
3117
|
+
if (!isValid(base))
|
|
3118
|
+
return base;
|
|
3119
|
+
// if (base.status === "aborted") return INVALID;
|
|
3120
|
+
// if (base.status === "dirty") {
|
|
3121
|
+
// return { status: "dirty", value: base.value };
|
|
3122
|
+
// }
|
|
3123
|
+
return Promise.resolve(effect.transform(base.value)).then(OK);
|
|
3124
|
+
});
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
util.assertNever(effect);
|
|
3128
|
+
};
|
|
3129
|
+
ZodEffects.create = function (schema, effect, params) {
|
|
3130
|
+
return new ZodEffects(__assign({ schema: schema, typeName: ZodFirstPartyTypeKind.ZodEffects, effect: effect }, processCreateParams(params)));
|
|
3131
|
+
};
|
|
3132
|
+
ZodEffects.createWithPreprocess = function (preprocess, schema, params) {
|
|
3133
|
+
return new ZodEffects(__assign({ schema: schema, effect: { type: "preprocess", transform: preprocess }, typeName: ZodFirstPartyTypeKind.ZodEffects }, processCreateParams(params)));
|
|
3134
|
+
};
|
|
3135
|
+
return ZodEffects;
|
|
3136
|
+
}(ZodType));
|
|
3137
|
+
var ZodOptional = /** @class */ (function (_super) {
|
|
3138
|
+
__extends(ZodOptional, _super);
|
|
3139
|
+
function ZodOptional() {
|
|
3140
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
3141
|
+
}
|
|
3142
|
+
ZodOptional.prototype._parse = function (input) {
|
|
3143
|
+
var ctx = this._processInputParams(input).ctx;
|
|
3144
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
3145
|
+
return OK(undefined);
|
|
3146
|
+
}
|
|
3147
|
+
return this._def.innerType._parse({
|
|
3148
|
+
data: ctx.data,
|
|
3149
|
+
path: ctx.path,
|
|
3150
|
+
parent: ctx,
|
|
3151
|
+
});
|
|
3152
|
+
};
|
|
3153
|
+
ZodOptional.prototype.unwrap = function () {
|
|
3154
|
+
return this._def.innerType;
|
|
3155
|
+
};
|
|
3156
|
+
ZodOptional.create = function (type, params) {
|
|
3157
|
+
return new ZodOptional(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodOptional }, processCreateParams(params)));
|
|
3158
|
+
};
|
|
3159
|
+
return ZodOptional;
|
|
3160
|
+
}(ZodType));
|
|
3161
|
+
var ZodNullable = /** @class */ (function (_super) {
|
|
3162
|
+
__extends(ZodNullable, _super);
|
|
3163
|
+
function ZodNullable() {
|
|
3164
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
3165
|
+
}
|
|
3166
|
+
ZodNullable.prototype._parse = function (input) {
|
|
3167
|
+
var ctx = this._processInputParams(input).ctx;
|
|
3168
|
+
if (ctx.parsedType === ZodParsedType.null) {
|
|
3169
|
+
return OK(null);
|
|
3170
|
+
}
|
|
3171
|
+
return this._def.innerType._parse({
|
|
3172
|
+
data: ctx.data,
|
|
3173
|
+
path: ctx.path,
|
|
3174
|
+
parent: ctx,
|
|
3175
|
+
});
|
|
3176
|
+
};
|
|
3177
|
+
ZodNullable.prototype.unwrap = function () {
|
|
3178
|
+
return this._def.innerType;
|
|
3179
|
+
};
|
|
3180
|
+
ZodNullable.create = function (type, params) {
|
|
3181
|
+
return new ZodNullable(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodNullable }, processCreateParams(params)));
|
|
3182
|
+
};
|
|
3183
|
+
return ZodNullable;
|
|
3184
|
+
}(ZodType));
|
|
3185
|
+
var ZodDefault = /** @class */ (function (_super) {
|
|
3186
|
+
__extends(ZodDefault, _super);
|
|
3187
|
+
function ZodDefault() {
|
|
3188
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
3189
|
+
}
|
|
3190
|
+
ZodDefault.prototype._parse = function (input) {
|
|
3191
|
+
var ctx = this._processInputParams(input).ctx;
|
|
3192
|
+
var data = ctx.data;
|
|
3193
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
3194
|
+
data = this._def.defaultValue();
|
|
3195
|
+
}
|
|
3196
|
+
return this._def.innerType._parse({
|
|
3197
|
+
data: data,
|
|
3198
|
+
path: ctx.path,
|
|
3199
|
+
parent: ctx,
|
|
3200
|
+
});
|
|
3201
|
+
};
|
|
3202
|
+
ZodDefault.prototype.removeDefault = function () {
|
|
3203
|
+
return this._def.innerType;
|
|
3204
|
+
};
|
|
3205
|
+
ZodDefault.create = function (type, params) {
|
|
3206
|
+
return new ZodOptional(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodOptional }, processCreateParams(params)));
|
|
3207
|
+
};
|
|
3208
|
+
return ZodDefault;
|
|
3209
|
+
}(ZodType));
|
|
3210
|
+
var ZodNaN = /** @class */ (function (_super) {
|
|
3211
|
+
__extends(ZodNaN, _super);
|
|
3212
|
+
function ZodNaN() {
|
|
3213
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
3214
|
+
}
|
|
3215
|
+
ZodNaN.prototype._parse = function (input) {
|
|
3216
|
+
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
3217
|
+
if (ctx.parsedType !== ZodParsedType.nan) {
|
|
3218
|
+
addIssueToContext(ctx, {
|
|
3219
|
+
code: ZodIssueCode.invalid_type,
|
|
3220
|
+
expected: ZodParsedType.nan,
|
|
3221
|
+
received: ctx.parsedType,
|
|
3222
|
+
});
|
|
3223
|
+
return INVALID;
|
|
3224
|
+
}
|
|
3225
|
+
return { status: status.value, value: ctx.data };
|
|
3226
|
+
};
|
|
3227
|
+
ZodNaN.create = function (params) {
|
|
3228
|
+
return new ZodNaN(__assign({ typeName: ZodFirstPartyTypeKind.ZodNaN }, processCreateParams(params)));
|
|
3229
|
+
};
|
|
3230
|
+
return ZodNaN;
|
|
3231
|
+
}(ZodType));
|
|
3232
|
+
var custom = function (check, params) {
|
|
3233
|
+
if (check)
|
|
3234
|
+
return ZodAny.create().refine(check, params);
|
|
3235
|
+
return ZodAny.create();
|
|
3236
|
+
};
|
|
3237
|
+
var late = {
|
|
3238
|
+
object: ZodObject.lazycreate,
|
|
3239
|
+
};
|
|
3240
|
+
var ZodFirstPartyTypeKind;
|
|
3241
|
+
(function (ZodFirstPartyTypeKind) {
|
|
3242
|
+
ZodFirstPartyTypeKind["ZodString"] = "ZodString";
|
|
3243
|
+
ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
|
|
3244
|
+
ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
|
|
3245
|
+
ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
|
|
3246
|
+
ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
|
|
3247
|
+
ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
|
|
3248
|
+
ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
|
|
3249
|
+
ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
|
|
3250
|
+
ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
|
|
3251
|
+
ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
|
|
3252
|
+
ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
|
|
3253
|
+
ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
|
|
3254
|
+
ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
|
|
3255
|
+
ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
|
|
3256
|
+
ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
|
|
3257
|
+
ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
3258
|
+
ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
|
|
3259
|
+
ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
|
|
3260
|
+
ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
|
|
3261
|
+
ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
|
|
3262
|
+
ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
|
|
3263
|
+
ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
|
|
3264
|
+
ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
|
|
3265
|
+
ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
|
|
3266
|
+
ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
|
|
3267
|
+
ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
|
|
3268
|
+
ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
|
|
3269
|
+
ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
|
|
3270
|
+
ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
|
|
3271
|
+
ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
|
|
3272
|
+
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
|
3273
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
3274
|
+
var instanceOfType = function (cls, params) {
|
|
3275
|
+
if (params === void 0) { params = {
|
|
3276
|
+
message: "Input not instance of ".concat(cls.name),
|
|
3277
|
+
}; }
|
|
3278
|
+
return custom(function (data) { return data instanceof cls; }, params);
|
|
3279
|
+
};
|
|
3280
|
+
var stringType = ZodString.create;
|
|
3281
|
+
var numberType = ZodNumber.create;
|
|
3282
|
+
var nanType = ZodNaN.create;
|
|
3283
|
+
var bigIntType = ZodBigInt.create;
|
|
3284
|
+
var booleanType = ZodBoolean.create;
|
|
3285
|
+
var dateType = ZodDate.create;
|
|
3286
|
+
var undefinedType = ZodUndefined.create;
|
|
3287
|
+
var nullType = ZodNull.create;
|
|
3288
|
+
var anyType = ZodAny.create;
|
|
3289
|
+
var unknownType = ZodUnknown.create;
|
|
3290
|
+
var neverType = ZodNever.create;
|
|
3291
|
+
var voidType = ZodVoid.create;
|
|
3292
|
+
var arrayType = ZodArray.create;
|
|
3293
|
+
var objectType = ZodObject.create;
|
|
3294
|
+
var strictObjectType = ZodObject.strictCreate;
|
|
3295
|
+
var unionType = ZodUnion.create;
|
|
3296
|
+
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
3297
|
+
var intersectionType = ZodIntersection.create;
|
|
3298
|
+
var tupleType = ZodTuple.create;
|
|
3299
|
+
var recordType = ZodRecord.create;
|
|
3300
|
+
var mapType = ZodMap.create;
|
|
3301
|
+
var setType = ZodSet.create;
|
|
3302
|
+
var functionType = ZodFunction.create;
|
|
3303
|
+
var lazyType = ZodLazy.create;
|
|
3304
|
+
var literalType = ZodLiteral.create;
|
|
3305
|
+
var enumType = ZodEnum.create;
|
|
3306
|
+
var nativeEnumType = ZodNativeEnum.create;
|
|
3307
|
+
var promiseType = ZodPromise.create;
|
|
3308
|
+
var effectsType = ZodEffects.create;
|
|
3309
|
+
var optionalType = ZodOptional.create;
|
|
3310
|
+
var nullableType = ZodNullable.create;
|
|
3311
|
+
var preprocessType = ZodEffects.createWithPreprocess;
|
|
3312
|
+
var ostring = function () { return stringType().optional(); };
|
|
3313
|
+
var onumber = function () { return numberType().optional(); };
|
|
3314
|
+
var oboolean = function () { return booleanType().optional(); };
|
|
3315
|
+
|
|
3316
|
+
var mod = /*#__PURE__*/Object.freeze({
|
|
3317
|
+
__proto__: null,
|
|
3318
|
+
ZodParsedType: ZodParsedType,
|
|
3319
|
+
getParsedType: getParsedType,
|
|
3320
|
+
makeIssue: makeIssue,
|
|
3321
|
+
EMPTY_PATH: EMPTY_PATH,
|
|
3322
|
+
addIssueToContext: addIssueToContext,
|
|
3323
|
+
ParseStatus: ParseStatus,
|
|
3324
|
+
INVALID: INVALID,
|
|
3325
|
+
DIRTY: DIRTY,
|
|
3326
|
+
OK: OK,
|
|
3327
|
+
isAborted: isAborted,
|
|
3328
|
+
isDirty: isDirty,
|
|
3329
|
+
isValid: isValid,
|
|
3330
|
+
isAsync: isAsync,
|
|
3331
|
+
ZodType: ZodType,
|
|
3332
|
+
ZodString: ZodString,
|
|
3333
|
+
ZodNumber: ZodNumber,
|
|
3334
|
+
ZodBigInt: ZodBigInt,
|
|
3335
|
+
ZodBoolean: ZodBoolean,
|
|
3336
|
+
ZodDate: ZodDate,
|
|
3337
|
+
ZodUndefined: ZodUndefined,
|
|
3338
|
+
ZodNull: ZodNull,
|
|
3339
|
+
ZodAny: ZodAny,
|
|
3340
|
+
ZodUnknown: ZodUnknown,
|
|
3341
|
+
ZodNever: ZodNever,
|
|
3342
|
+
ZodVoid: ZodVoid,
|
|
3343
|
+
ZodArray: ZodArray,
|
|
3344
|
+
get objectUtil () { return objectUtil; },
|
|
3345
|
+
ZodObject: ZodObject,
|
|
3346
|
+
ZodUnion: ZodUnion,
|
|
3347
|
+
ZodDiscriminatedUnion: ZodDiscriminatedUnion,
|
|
3348
|
+
ZodIntersection: ZodIntersection,
|
|
3349
|
+
ZodTuple: ZodTuple,
|
|
3350
|
+
ZodRecord: ZodRecord,
|
|
3351
|
+
ZodMap: ZodMap,
|
|
3352
|
+
ZodSet: ZodSet,
|
|
3353
|
+
ZodFunction: ZodFunction,
|
|
3354
|
+
ZodLazy: ZodLazy,
|
|
3355
|
+
ZodLiteral: ZodLiteral,
|
|
3356
|
+
ZodEnum: ZodEnum,
|
|
3357
|
+
ZodNativeEnum: ZodNativeEnum,
|
|
3358
|
+
ZodPromise: ZodPromise,
|
|
3359
|
+
ZodEffects: ZodEffects,
|
|
3360
|
+
ZodTransformer: ZodEffects,
|
|
3361
|
+
ZodOptional: ZodOptional,
|
|
3362
|
+
ZodNullable: ZodNullable,
|
|
3363
|
+
ZodDefault: ZodDefault,
|
|
3364
|
+
ZodNaN: ZodNaN,
|
|
3365
|
+
custom: custom,
|
|
3366
|
+
Schema: ZodType,
|
|
3367
|
+
ZodSchema: ZodType,
|
|
3368
|
+
late: late,
|
|
3369
|
+
get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
|
|
3370
|
+
any: anyType,
|
|
3371
|
+
array: arrayType,
|
|
3372
|
+
bigint: bigIntType,
|
|
3373
|
+
boolean: booleanType,
|
|
3374
|
+
date: dateType,
|
|
3375
|
+
discriminatedUnion: discriminatedUnionType,
|
|
3376
|
+
effect: effectsType,
|
|
3377
|
+
'enum': enumType,
|
|
3378
|
+
'function': functionType,
|
|
3379
|
+
'instanceof': instanceOfType,
|
|
3380
|
+
intersection: intersectionType,
|
|
3381
|
+
lazy: lazyType,
|
|
3382
|
+
literal: literalType,
|
|
3383
|
+
map: mapType,
|
|
3384
|
+
nan: nanType,
|
|
3385
|
+
nativeEnum: nativeEnumType,
|
|
3386
|
+
never: neverType,
|
|
3387
|
+
'null': nullType,
|
|
3388
|
+
nullable: nullableType,
|
|
3389
|
+
number: numberType,
|
|
3390
|
+
object: objectType,
|
|
3391
|
+
oboolean: oboolean,
|
|
3392
|
+
onumber: onumber,
|
|
3393
|
+
optional: optionalType,
|
|
3394
|
+
ostring: ostring,
|
|
3395
|
+
preprocess: preprocessType,
|
|
3396
|
+
promise: promiseType,
|
|
3397
|
+
record: recordType,
|
|
3398
|
+
set: setType,
|
|
3399
|
+
strictObject: strictObjectType,
|
|
3400
|
+
string: stringType,
|
|
3401
|
+
transformer: effectsType,
|
|
3402
|
+
tuple: tupleType,
|
|
3403
|
+
'undefined': undefinedType,
|
|
3404
|
+
union: unionType,
|
|
3405
|
+
unknown: unknownType,
|
|
3406
|
+
'void': voidType,
|
|
3407
|
+
ZodIssueCode: ZodIssueCode,
|
|
3408
|
+
quotelessJson: quotelessJson,
|
|
3409
|
+
ZodError: ZodError,
|
|
3410
|
+
defaultErrorMap: defaultErrorMap,
|
|
3411
|
+
get overrideErrorMap () { return overrideErrorMap; },
|
|
3412
|
+
setErrorMap: setErrorMap
|
|
3413
|
+
});
|
|
3414
|
+
|
|
3415
|
+
export default mod;
|
|
3416
|
+
export { DIRTY, EMPTY_PATH, INVALID, OK, ParseStatus, ZodType as Schema, ZodAny, ZodArray, ZodBigInt, ZodBoolean, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodEffects, ZodEnum, ZodError, ZodFirstPartyTypeKind, ZodFunction, ZodIntersection, ZodIssueCode, ZodLazy, ZodLiteral, ZodMap, ZodNaN, ZodNativeEnum, ZodNever, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodParsedType, ZodPromise, ZodRecord, ZodType as ZodSchema, ZodSet, ZodString, ZodEffects as ZodTransformer, ZodTuple, ZodType, ZodUndefined, ZodUnion, ZodUnknown, ZodVoid, addIssueToContext, anyType as any, arrayType as array, bigIntType as bigint, booleanType as boolean, custom, dateType as date, defaultErrorMap, discriminatedUnionType as discriminatedUnion, effectsType as effect, enumType as enum, functionType as function, getParsedType, instanceOfType as instanceof, intersectionType as intersection, isAborted, isAsync, isDirty, isValid, late, lazyType as lazy, literalType as literal, makeIssue, mapType as map, nanType as nan, nativeEnumType as nativeEnum, neverType as never, nullType as null, nullableType as nullable, numberType as number, objectType as object, objectUtil, oboolean, onumber, optionalType as optional, ostring, overrideErrorMap, preprocessType as preprocess, promiseType as promise, quotelessJson, recordType as record, setType as set, setErrorMap, strictObjectType as strictObject, stringType as string, effectsType as transformer, tupleType as tuple, undefinedType as undefined, unionType as union, unknownType as unknown, voidType as void, mod as z };
|