@oxog/vld 2.2.7 → 2.4.0
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/CHANGELOG.md +25 -0
- package/dist/chunks/index-CKPStM3V.js +1 -0
- package/dist/cjs/chunks/index-lejEpLfv.cjs +1 -0
- package/dist/cjs/cli/bin.cjs +1 -1
- package/dist/cjs/compile.cjs +1 -0
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/locales/gu.cjs +1 -0
- package/dist/cjs/locales/index.cjs +1 -1
- package/dist/cjs/locales/kn.cjs +1 -0
- package/dist/cjs/locales/ne.cjs +1 -0
- package/dist/cjs/locales/pt-BR-v4.cjs +1 -0
- package/dist/cjs/locales/sk.cjs +1 -0
- package/dist/cjs/v3/index.cjs +1 -1
- package/dist/cjs/v4/core/index.cjs +1 -1
- package/dist/cjs/v4/index.cjs +1 -1
- package/dist/cjs/v4/locales/index.cjs +1 -1
- package/dist/cjs/v4/mini/index.cjs +1 -1
- package/dist/cjs/v4-mini/index.cjs +1 -1
- package/dist/cjs/validators/object.cjs +1 -1
- package/dist/cjs/validators/string-formats.cjs +1 -1
- package/dist/compile.d.ts +81 -0
- package/dist/compile.js +1 -0
- package/dist/index.d.ts +316 -9
- package/dist/index.js +1 -1
- package/dist/locales/gu.d.ts +2 -0
- package/dist/locales/gu.js +1 -0
- package/dist/locales/index.js +1 -1
- package/dist/locales/kn.d.ts +2 -0
- package/dist/locales/kn.js +1 -0
- package/dist/locales/ne.d.ts +2 -0
- package/dist/locales/ne.js +1 -0
- package/dist/locales/pt-BR-v4.d.ts +2 -0
- package/dist/locales/pt-BR-v4.js +1 -0
- package/dist/locales/sk.d.ts +2 -0
- package/dist/locales/sk.js +1 -0
- package/dist/v3/index.js +1 -1
- package/dist/v4/core/index.d.ts +13 -0
- package/dist/v4/core/index.js +1 -1
- package/dist/v4/index.d.ts +1 -0
- package/dist/v4/index.js +1 -1
- package/dist/v4/locales/index.d.ts +6 -0
- package/dist/v4/locales/index.js +1 -1
- package/dist/v4/mini/index.js +1 -1
- package/dist/v4-mini/index.d.ts +2 -0
- package/dist/v4-mini/index.js +1 -1
- package/dist/validators/custom.js +1 -1
- package/dist/validators/object.d.ts +9 -0
- package/dist/validators/object.js +1 -1
- package/dist/validators/string-formats.d.ts +1 -0
- package/dist/validators/string-formats.js +1 -1
- package/package.json +7 -2
- package/dist/chunks/index-yjpbvFgw.js +0 -1
- package/dist/cjs/chunks/index-BEV9nG0N.cjs +0 -1
package/dist/v4/mini/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{_default,catchall,extend,maximum,merge,minimum,omit,partial,pick,required,safeExtend}from"../../v4-mini/index.js";export{$brand,$input,$output,NEVER,TimePrecision,ZodFirstPartyTypeKind,ZodIssueCode,_ZodString,_function,any,array,base64,base64Bytes,base64url,bigint,boolean,catch,check,cidrv4,cidrv6,clone,codec,coerce,config,core,createLogger,createNoOpLogger,creditCard,cuid,cuid2,custom,date,decode,decodeAsync,deepPartial,default,describe,disableLogging,discriminatedUnion,e164,email,emoji,enableDebug,encode,encodeAsync,endsWith,enum,exactOptional,file,float32,float64,formatError,fromJSONSchema,_function as function,getErrorMap,getLogger,gt,gte,guid,hash,hex,hexBytes,hostname,httpUrl,includes,initLogger,input,instanceof,int,int32,int64,intersection,ipv4,ipv6,iso,json,jwt,keyof,ksuid,lazy,length,literal,locales,looseObject,looseRecord,lowercase,lt,lte,mac,map,mapSchema,maxLength,maxSize,meta,mime,minLength,minSize,multipleOf,nan,nanoid,nativeEnum,negative,never,nonnegative,nonoptional,nonpositive,normalize,null,nullable,nullish,number,object,optional,output,overwrite,parse,parseAsync,partialRecord,pipe,positive,prefault,preprocess,promise,property,readonly,record,refine,regex,regexes,safeDecode,safeDecodeAsync,safeEncode,safeEncodeAsync,safeParse,safeParseAsync,set,setErrorMap,setLogLevel,size,slugify,startsWith,strictObject,string,stringFormat,stringbool,superRefine,symbol,templateLiteral,toJSONSchema,toLowerCase,toUpperCase,transform,trim,tuple,uint32,uint64,uint8Array,ulid,undefined,union,unknown,uppercase,url,util,uuid,uuidv4,uuidv6,uuidv7,default as v,void,xid,xor,z}from"../../index.js";export{Err,Ok,ResultUtils,all,failure,flatMap,fromNullable,isErr,isOk,isResult,mapErr,match,success,tryCatch,tryCatchAsync,unwrap,unwrapOr}from"../../compat/result.js";export{VldBase,VldMeta,VldBrand as ZodBranded,VldCatch as ZodCatch,VldDefault as ZodDefault,VldExactOptional as ZodExactOptional,VldMeta as ZodMeta,VldBrand as ZodMiniBrand,VldCatch as ZodMiniCatch,VldDefault as ZodMiniDefault,VldExactOptional as ZodMiniExactOptional,VldRefine as ZodMiniNonOptional,VldNullable as ZodMiniNullable,VldOptional as ZodMiniOptional,VldPipe as ZodMiniPipe,VldPrefault as ZodMiniPrefault,VldReadonly as ZodMiniReadonly,VldTransform as ZodMiniTransform,VldBase as ZodMiniType,VldRefine as ZodNonOptional,VldNullable as ZodNullable,VldOptional as ZodOptional,VldPipe as ZodPipe,VldPrefault as ZodPrefault,VldPreprocess as ZodPreprocess,VldReadonly as ZodReadonly,VldTransform as ZodTransform,VldBase as ZodType}from"../../validators/base.js";export{V as VldError,V as ZodError,V as ZodRealError}from"../../chunks/errors-core-CerMg2rq.js";export{VldIntersection,VldIntersection as ZodIntersection,VldIntersection as ZodMiniIntersection}from"../../validators/intersection.js";export{VldAny as ZodAny,VldAny as ZodMiniAny}from"../../validators/any.js";export{VldArray as ZodArray,VldArray as ZodMiniArray}from"../../validators/array.js";export{VldStringFormat as ZodBase64,VldStringFormat as ZodBase64URL,VldStringFormat as ZodCIDRv4,VldStringFormat as ZodCIDRv6,VldStringFormat as ZodCUID,VldStringFormat as ZodCUID2,VldStringFormat as ZodCreditCard,VldStringFormat as ZodCustomStringFormat,VldStringFormat as ZodE164,VldStringFormat as ZodEmail,VldStringFormat as ZodEmoji,VldStringFormat as ZodGUID,VldStringFormat as ZodIPv4,VldStringFormat as ZodIPv6,VldStringFormat as ZodISODate,VldStringFormat as ZodISODateTime,VldStringFormat as ZodISODuration,VldStringFormat as ZodISOTime,VldStringFormat as ZodJWT,VldStringFormat as ZodKSUID,VldStringFormat as ZodMAC,VldStringFormat as ZodMiniBase64,VldStringFormat as ZodMiniBase64URL,VldStringFormat as ZodMiniCIDRv4,VldStringFormat as ZodMiniCIDRv6,VldStringFormat as ZodMiniCUID,VldStringFormat as ZodMiniCUID2,VldStringFormat as ZodMiniCreditCard,VldStringFormat as ZodMiniCustomStringFormat,VldStringFormat as ZodMiniE164,VldStringFormat as ZodMiniEmail,VldStringFormat as ZodMiniEmoji,VldStringFormat as ZodMiniGUID,VldStringFormat as ZodMiniIPv4,VldStringFormat as ZodMiniIPv6,VldStringFormat as ZodMiniISODate,VldStringFormat as ZodMiniISODateTime,VldStringFormat as ZodMiniISODuration,VldStringFormat as ZodMiniISOTime,VldStringFormat as ZodMiniJWT,VldStringFormat as ZodMiniKSUID,VldStringFormat as ZodMiniMAC,VldStringFormat as ZodMiniNanoID,VldStringFormat as ZodMiniStringFormat,VldStringFormat as ZodMiniULID,VldStringFormat as ZodMiniURL,VldStringFormat as ZodMiniUUID,VldStringFormat as ZodMiniXID,VldStringFormat as ZodNanoID,VldStringFormat as ZodStringFormat,VldStringFormat as ZodULID,VldStringFormat as ZodURL,VldStringFormat as ZodUUID,VldStringFormat as ZodXID}from"../../validators/string-formats.js";export{VldBigInt as ZodBigInt,VldBigInt as ZodBigIntFormat,VldBigInt as ZodMiniBigInt,VldBigInt as ZodMiniBigIntFormat}from"../../validators/bigint.js";export{VldBoolean as ZodBoolean,VldBoolean as ZodMiniBoolean}from"../../validators/boolean.js";export{VldCodec as ZodCodec,VldCodec as ZodMiniCodec}from"../../validators/codec.js";export{VldCustom as ZodCustom,VldCustom as ZodMiniCustom,VldCustom as ZodMiniSuccess,VldCustom as ZodSuccess}from"../../validators/custom.js";export{VldDate as ZodDate,VldDate as ZodMiniDate}from"../../validators/date.js";export{VldDiscriminatedUnion as ZodDiscriminatedUnion,VldDiscriminatedUnion as ZodMiniDiscriminatedUnion}from"../../validators/discriminated-union.js";export{VldEnum as ZodEnum,VldEnum as ZodMiniEnum}from"../../validators/enum.js";export{VldFile as ZodFile,VldFile as ZodMiniFile}from"../../validators/file.js";export{VldFunction as ZodFunction,VldFunction as ZodMiniFunction}from"../../validators/function.js";export{VldJson as ZodJSON}from"../../validators/json.js";export{VldLazy as ZodLazy,VldLazy as ZodMiniLazy}from"../../validators/lazy.js";export{VldLiteral as ZodLiteral,VldLiteral as ZodMiniLiteral}from"../../validators/literal.js";export{VldMap as ZodMap,VldMap as ZodMiniMap}from"../../validators/map.js";export{VldNan as ZodMiniNaN,VldNan as ZodNaN}from"../../validators/nan.js";export{VldNever as ZodMiniNever,VldNever as ZodNever}from"../../validators/never.js";export{VldNull as ZodMiniNull,VldNull as ZodNull}from"../../validators/null.js";export{VldNumber as ZodMiniNumber,VldNumber as ZodMiniNumberFormat,VldNumber as ZodNumber,VldNumber as ZodNumberFormat}from"../../validators/number.js";export{VldObject as ZodMiniObject,VldObject as ZodObject}from"../../validators/object.js";export{VldPromise as ZodMiniPromise,VldPromise as ZodPromise}from"../../validators/promise.js";export{VldRecord as ZodMiniRecord,VldRecord as ZodRecord}from"../../validators/record.js";export{VldSet as ZodMiniSet,VldSet as ZodSet}from"../../validators/set.js";export{VldString as ZodMiniString,VldString as ZodString}from"../../validators/string.js";export{VldSymbol as ZodMiniSymbol,VldSymbol as ZodSymbol}from"../../validators/symbol.js";export{VldTemplateLiteral as ZodMiniTemplateLiteral,VldTemplateLiteral as ZodTemplateLiteral}from"../../validators/template-literal.js";export{VldTuple as ZodMiniTuple,VldTuple as ZodTuple}from"../../validators/tuple.js";export{VldUndefined as ZodMiniUndefined,VldUndefined as ZodUndefined}from"../../validators/undefined.js";export{VldUnion as ZodMiniUnion,VldUnion as ZodUnion}from"../../validators/union.js";export{VldUnknown as ZodMiniUnknown,VldUnknown as ZodUnknown}from"../../validators/unknown.js";export{VldVoid as ZodMiniVoid,VldVoid as ZodVoid}from"../../validators/void.js";export{VldXor as ZodMiniXor,VldXor as ZodXor}from"../../validators/xor.js";export{b as base64Json,a as base64ToBytes,c as base64ToUint8Array,d as base64UrlToBytes,e as base64urlToBytes,f as bytesToUtf8,g as epochMillisToDate,h as epochSecondsToDate,i as hexLowerToBytes,j as hexToBytes,k as hexToUint8Array,l as invertCodec,m as isoDatetimeToDate,n as jsonCodec,o as jwtPayload,p as numberToBigInt,s as stringToBigInt,q as stringToBoolean,r as stringToHttpURL,t as stringToInt,u as stringToNumber,v as stringToURL,w as stringToUint8Array,x as uint8ArrayToBase64,y as uint8ArrayToBase64Url,z as uint8ArrayToHex,A as uint8ArrayToString,B as uriComponent,C as utf8ToBytes}from"../../chunks/index-CkbfQQ4n.js";export{blue,bold,createTheme,cyan,dim,gray,green,grey,italic,magenta,default as pigment,red,strip,supportsColor,underline,vldTheme,white,yellow}from"../../pigment.js";export{createEmitter,createEventBus,withEmitter}from"../../compat/emitter.js";export{createVldKernel,definePlugin,getVldKernel,resetVldKernel,usePlugin}from"../../kernel.js";export{flattenError,prettifyError,prettifyErrorColored,prettifyErrorPlain,treeifyError}from"../../errors.js";export{getLocale,getMessages,getSupportedLocales,isLocaleLoaded,isLocaleSupported,registerLocale,setLocale}from"../../locales/runtime.js";export{globalRegistry,registry}from"../../registry.js";export{s as setLocaleAsync}from"../../chunks/index-
|
|
1
|
+
export{_default,catchall,exactPartial,extend,maximum,merge,minimum,omit,partial,pick,required,safeExtend}from"../../v4-mini/index.js";export{$brand,$input,$output,NEVER,TimePrecision,ZodFirstPartyTypeKind,ZodIssueCode,_ZodString,_function,any,array,base64,base64Bytes,base64url,bigint,boolean,catch,check,cidrv4,cidrv6,clone,codec,coerce,config,core,createLogger,createNoOpLogger,creditCard,cuid,cuid2,custom,date,decode,decodeAsync,deepPartial,default,describe,disableLogging,discriminatedUnion,e164,email,emoji,enableDebug,encode,encodeAsync,endsWith,enum,exactOptional,file,float32,float64,formatError,fromJSONSchema,_function as function,getErrorMap,getLogger,gt,gte,guid,hash,hex,hexBytes,hostname,httpUrl,includes,initLogger,input,instanceof,int,int32,int64,intersection,ipv4,ipv6,iso,json,jwt,keyof,ksuid,lazy,length,literal,locales,looseObject,looseRecord,lowercase,lt,lte,mac,map,mapSchema,maxLength,maxSize,meta,mime,minLength,minSize,multipleOf,nan,nanoid,nativeEnum,negative,never,nonnegative,nonoptional,nonpositive,normalize,null,nullable,nullish,number,object,optional,output,overwrite,parse,parseAsync,partialRecord,pipe,positive,prefault,preprocess,promise,property,readonly,record,refine,regex,regexes,safeDecode,safeDecodeAsync,safeEncode,safeEncodeAsync,safeParse,safeParseAsync,set,setErrorMap,setLogLevel,size,slugify,startsWith,strictObject,string,stringFormat,stringbool,superRefine,symbol,templateLiteral,toJSONSchema,toLowerCase,toUpperCase,transform,trim,tuple,uint32,uint64,uint8Array,ulid,undefined,union,unknown,uppercase,url,util,uuid,uuidv4,uuidv6,uuidv7,default as v,void,xid,xor,z}from"../../index.js";export{Err,Ok,ResultUtils,all,failure,flatMap,fromNullable,isErr,isOk,isResult,mapErr,match,success,tryCatch,tryCatchAsync,unwrap,unwrapOr}from"../../compat/result.js";export{VldBase,VldMeta,VldBrand as ZodBranded,VldCatch as ZodCatch,VldDefault as ZodDefault,VldExactOptional as ZodExactOptional,VldMeta as ZodMeta,VldBrand as ZodMiniBrand,VldCatch as ZodMiniCatch,VldDefault as ZodMiniDefault,VldExactOptional as ZodMiniExactOptional,VldRefine as ZodMiniNonOptional,VldNullable as ZodMiniNullable,VldOptional as ZodMiniOptional,VldPipe as ZodMiniPipe,VldPrefault as ZodMiniPrefault,VldReadonly as ZodMiniReadonly,VldTransform as ZodMiniTransform,VldBase as ZodMiniType,VldRefine as ZodNonOptional,VldNullable as ZodNullable,VldOptional as ZodOptional,VldPipe as ZodPipe,VldPrefault as ZodPrefault,VldPreprocess as ZodPreprocess,VldReadonly as ZodReadonly,VldTransform as ZodTransform,VldBase as ZodType}from"../../validators/base.js";export{V as VldError,V as ZodError,V as ZodRealError}from"../../chunks/errors-core-CerMg2rq.js";export{VldIntersection,VldIntersection as ZodIntersection,VldIntersection as ZodMiniIntersection}from"../../validators/intersection.js";export{VldAny as ZodAny,VldAny as ZodMiniAny}from"../../validators/any.js";export{VldArray as ZodArray,VldArray as ZodMiniArray}from"../../validators/array.js";export{VldStringFormat as ZodBase64,VldStringFormat as ZodBase64URL,VldStringFormat as ZodCIDRv4,VldStringFormat as ZodCIDRv6,VldStringFormat as ZodCUID,VldStringFormat as ZodCUID2,VldStringFormat as ZodCreditCard,VldStringFormat as ZodCustomStringFormat,VldStringFormat as ZodE164,VldStringFormat as ZodEmail,VldStringFormat as ZodEmoji,VldStringFormat as ZodGUID,VldStringFormat as ZodIPv4,VldStringFormat as ZodIPv6,VldStringFormat as ZodISODate,VldStringFormat as ZodISODateTime,VldStringFormat as ZodISODuration,VldStringFormat as ZodISOTime,VldStringFormat as ZodJWT,VldStringFormat as ZodKSUID,VldStringFormat as ZodMAC,VldStringFormat as ZodMiniBase64,VldStringFormat as ZodMiniBase64URL,VldStringFormat as ZodMiniCIDRv4,VldStringFormat as ZodMiniCIDRv6,VldStringFormat as ZodMiniCUID,VldStringFormat as ZodMiniCUID2,VldStringFormat as ZodMiniCreditCard,VldStringFormat as ZodMiniCustomStringFormat,VldStringFormat as ZodMiniE164,VldStringFormat as ZodMiniEmail,VldStringFormat as ZodMiniEmoji,VldStringFormat as ZodMiniGUID,VldStringFormat as ZodMiniIPv4,VldStringFormat as ZodMiniIPv6,VldStringFormat as ZodMiniISODate,VldStringFormat as ZodMiniISODateTime,VldStringFormat as ZodMiniISODuration,VldStringFormat as ZodMiniISOTime,VldStringFormat as ZodMiniJWT,VldStringFormat as ZodMiniKSUID,VldStringFormat as ZodMiniMAC,VldStringFormat as ZodMiniNanoID,VldStringFormat as ZodMiniStringFormat,VldStringFormat as ZodMiniULID,VldStringFormat as ZodMiniURL,VldStringFormat as ZodMiniUUID,VldStringFormat as ZodMiniXID,VldStringFormat as ZodNanoID,VldStringFormat as ZodStringFormat,VldStringFormat as ZodULID,VldStringFormat as ZodURL,VldStringFormat as ZodUUID,VldStringFormat as ZodXID}from"../../validators/string-formats.js";export{VldBigInt as ZodBigInt,VldBigInt as ZodBigIntFormat,VldBigInt as ZodMiniBigInt,VldBigInt as ZodMiniBigIntFormat}from"../../validators/bigint.js";export{VldBoolean as ZodBoolean,VldBoolean as ZodMiniBoolean}from"../../validators/boolean.js";export{VldCodec as ZodCodec,VldCodec as ZodMiniCodec}from"../../validators/codec.js";export{ZodCompileAsyncError,ZodCompileError,ZodCompileUnsupportedError,compile,getDiscriminatedOption,memoizer,properties,toZod,validate,validateAsync,compileFn as zodCompileFn}from"../../compile.js";export{VldCustom as ZodCustom,VldCustom as ZodMiniCustom,VldCustom as ZodMiniSuccess,VldCustom as ZodSuccess}from"../../validators/custom.js";export{VldDate as ZodDate,VldDate as ZodMiniDate}from"../../validators/date.js";export{VldDiscriminatedUnion as ZodDiscriminatedUnion,VldDiscriminatedUnion as ZodMiniDiscriminatedUnion}from"../../validators/discriminated-union.js";export{VldEnum as ZodEnum,VldEnum as ZodMiniEnum}from"../../validators/enum.js";export{VldFile as ZodFile,VldFile as ZodMiniFile}from"../../validators/file.js";export{VldFunction as ZodFunction,VldFunction as ZodMiniFunction}from"../../validators/function.js";export{VldJson as ZodJSON}from"../../validators/json.js";export{VldLazy as ZodLazy,VldLazy as ZodMiniLazy}from"../../validators/lazy.js";export{VldLiteral as ZodLiteral,VldLiteral as ZodMiniLiteral}from"../../validators/literal.js";export{VldMap as ZodMap,VldMap as ZodMiniMap}from"../../validators/map.js";export{VldNan as ZodMiniNaN,VldNan as ZodNaN}from"../../validators/nan.js";export{VldNever as ZodMiniNever,VldNever as ZodNever}from"../../validators/never.js";export{VldNull as ZodMiniNull,VldNull as ZodNull}from"../../validators/null.js";export{VldNumber as ZodMiniNumber,VldNumber as ZodMiniNumberFormat,VldNumber as ZodNumber,VldNumber as ZodNumberFormat}from"../../validators/number.js";export{VldObject as ZodMiniObject,VldObject as ZodObject}from"../../validators/object.js";export{VldPromise as ZodMiniPromise,VldPromise as ZodPromise}from"../../validators/promise.js";export{VldRecord as ZodMiniRecord,VldRecord as ZodRecord}from"../../validators/record.js";export{VldSet as ZodMiniSet,VldSet as ZodSet}from"../../validators/set.js";export{VldString as ZodMiniString,VldString as ZodString}from"../../validators/string.js";export{VldSymbol as ZodMiniSymbol,VldSymbol as ZodSymbol}from"../../validators/symbol.js";export{VldTemplateLiteral as ZodMiniTemplateLiteral,VldTemplateLiteral as ZodTemplateLiteral}from"../../validators/template-literal.js";export{VldTuple as ZodMiniTuple,VldTuple as ZodTuple}from"../../validators/tuple.js";export{VldUndefined as ZodMiniUndefined,VldUndefined as ZodUndefined}from"../../validators/undefined.js";export{VldUnion as ZodMiniUnion,VldUnion as ZodUnion}from"../../validators/union.js";export{VldUnknown as ZodMiniUnknown,VldUnknown as ZodUnknown}from"../../validators/unknown.js";export{VldVoid as ZodMiniVoid,VldVoid as ZodVoid}from"../../validators/void.js";export{VldXor as ZodMiniXor,VldXor as ZodXor}from"../../validators/xor.js";export{b as base64Json,a as base64ToBytes,c as base64ToUint8Array,d as base64UrlToBytes,e as base64urlToBytes,f as bytesToUtf8,g as epochMillisToDate,h as epochSecondsToDate,i as hexLowerToBytes,j as hexToBytes,k as hexToUint8Array,l as invertCodec,m as isoDatetimeToDate,n as jsonCodec,o as jwtPayload,p as numberToBigInt,s as stringToBigInt,q as stringToBoolean,r as stringToHttpURL,t as stringToInt,u as stringToNumber,v as stringToURL,w as stringToUint8Array,x as uint8ArrayToBase64,y as uint8ArrayToBase64Url,z as uint8ArrayToHex,A as uint8ArrayToString,B as uriComponent,C as utf8ToBytes}from"../../chunks/index-CkbfQQ4n.js";export{blue,bold,createTheme,cyan,dim,gray,green,grey,italic,magenta,default as pigment,red,strip,supportsColor,underline,vldTheme,white,yellow}from"../../pigment.js";export{createEmitter,createEventBus,withEmitter}from"../../compat/emitter.js";export{createVldKernel,definePlugin,getVldKernel,resetVldKernel,usePlugin}from"../../kernel.js";export{flattenError,prettifyError,prettifyErrorColored,prettifyErrorPlain,treeifyError}from"../../errors.js";export{getLocale,getMessages,getSupportedLocales,isLocaleLoaded,isLocaleSupported,registerLocale,setLocale}from"../../locales/runtime.js";export{globalRegistry,registry}from"../../registry.js";export{s as setLocaleAsync}from"../../chunks/index-CKPStM3V.js";
|
package/dist/v4-mini/index.d.ts
CHANGED
|
@@ -20,3 +20,5 @@ export declare const catchall: <T extends Record<string, any>>(schema: VldObject
|
|
|
20
20
|
export declare const _default: <TInput, TOutput>(schema: VldBase<TInput, TOutput>, defaultValue: TOutput | (() => TOutput)) => import("../index.js").ZodDefault<TInput, TOutput>;
|
|
21
21
|
export declare const minimum: (value: number, params?: ConstraintParam) => VldBase<unknown, number>;
|
|
22
22
|
export declare const maximum: (value: number, params?: ConstraintParam) => VldBase<unknown, number>;
|
|
23
|
+
export { compile, validate, validateAsync, properties, getDiscriminatedOption, memoizer, toZod, ZodCompileError, ZodCompileAsyncError, ZodCompileUnsupportedError } from '../compile.js';
|
|
24
|
+
export declare const exactPartial: <T extends Record<string, any>>(schema: VldObject<T>) => VldObject<any>;
|
package/dist/v4-mini/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{number as Z}from"../index.js";export{$brand,$input,$output,NEVER,TimePrecision,ZodFirstPartyTypeKind,ZodIssueCode,_ZodString,_function,any,array,base64,base64Bytes,base64url,bigint,boolean,catch,check,cidrv4,cidrv6,clone,codec,coerce,config,core,createLogger,createNoOpLogger,creditCard,cuid,cuid2,custom,date,decode,decodeAsync,deepPartial,default,describe,disableLogging,discriminatedUnion,e164,email,emoji,enableDebug,encode,encodeAsync,endsWith,enum,exactOptional,file,float32,float64,formatError,fromJSONSchema,_function as function,getErrorMap,getLogger,gt,gte,guid,hash,hex,hexBytes,hostname,httpUrl,includes,initLogger,input,instanceof,int,int32,int64,intersection,ipv4,ipv6,iso,json,jwt,keyof,ksuid,lazy,length,literal,locales,looseObject,looseRecord,lowercase,lt,lte,mac,map,mapSchema,maxLength,maxSize,meta,mime,minLength,minSize,multipleOf,nan,nanoid,nativeEnum,negative,never,nonnegative,nonoptional,nonpositive,normalize,null,nullable,nullish,object,optional,output,overwrite,parse,parseAsync,partialRecord,pipe,positive,prefault,preprocess,promise,property,readonly,record,refine,regex,regexes,safeDecode,safeDecodeAsync,safeEncode,safeEncodeAsync,safeParse,safeParseAsync,set,setErrorMap,setLogLevel,size,slugify,startsWith,strictObject,string,stringFormat,stringbool,superRefine,symbol,templateLiteral,toJSONSchema,toLowerCase,toUpperCase,transform,trim,tuple,uint32,uint64,uint8Array,ulid,undefined,union,unknown,uppercase,url,util,uuid,uuidv4,uuidv6,uuidv7,default as v,void,xid,xor,z}from"../index.js";export{Err,Ok,ResultUtils,all,failure,flatMap,fromNullable,isErr,isOk,isResult,mapErr,match,success,tryCatch,tryCatchAsync,unwrap,unwrapOr}from"../compat/result.js";export{VldBase,VldMeta,VldBrand as ZodBranded,VldCatch as ZodCatch,VldDefault as ZodDefault,VldExactOptional as ZodExactOptional,VldMeta as ZodMeta,VldBrand as ZodMiniBrand,VldCatch as ZodMiniCatch,VldDefault as ZodMiniDefault,VldExactOptional as ZodMiniExactOptional,VldRefine as ZodMiniNonOptional,VldNullable as ZodMiniNullable,VldOptional as ZodMiniOptional,VldPipe as ZodMiniPipe,VldPrefault as ZodMiniPrefault,VldReadonly as ZodMiniReadonly,VldTransform as ZodMiniTransform,VldBase as ZodMiniType,VldRefine as ZodNonOptional,VldNullable as ZodNullable,VldOptional as ZodOptional,VldPipe as ZodPipe,VldPrefault as ZodPrefault,VldPreprocess as ZodPreprocess,VldReadonly as ZodReadonly,VldTransform as ZodTransform,VldBase as ZodType}from"../validators/base.js";export{V as VldError,V as ZodError,V as ZodRealError}from"../chunks/errors-core-CerMg2rq.js";export{VldIntersection,VldIntersection as ZodIntersection,VldIntersection as ZodMiniIntersection}from"../validators/intersection.js";export{VldAny as ZodAny,VldAny as ZodMiniAny}from"../validators/any.js";export{VldArray as ZodArray,VldArray as ZodMiniArray}from"../validators/array.js";export{VldStringFormat as ZodBase64,VldStringFormat as ZodBase64URL,VldStringFormat as ZodCIDRv4,VldStringFormat as ZodCIDRv6,VldStringFormat as ZodCUID,VldStringFormat as ZodCUID2,VldStringFormat as ZodCreditCard,VldStringFormat as ZodCustomStringFormat,VldStringFormat as ZodE164,VldStringFormat as ZodEmail,VldStringFormat as ZodEmoji,VldStringFormat as ZodGUID,VldStringFormat as ZodIPv4,VldStringFormat as ZodIPv6,VldStringFormat as ZodISODate,VldStringFormat as ZodISODateTime,VldStringFormat as ZodISODuration,VldStringFormat as ZodISOTime,VldStringFormat as ZodJWT,VldStringFormat as ZodKSUID,VldStringFormat as ZodMAC,VldStringFormat as ZodMiniBase64,VldStringFormat as ZodMiniBase64URL,VldStringFormat as ZodMiniCIDRv4,VldStringFormat as ZodMiniCIDRv6,VldStringFormat as ZodMiniCUID,VldStringFormat as ZodMiniCUID2,VldStringFormat as ZodMiniCreditCard,VldStringFormat as ZodMiniCustomStringFormat,VldStringFormat as ZodMiniE164,VldStringFormat as ZodMiniEmail,VldStringFormat as ZodMiniEmoji,VldStringFormat as ZodMiniGUID,VldStringFormat as ZodMiniIPv4,VldStringFormat as ZodMiniIPv6,VldStringFormat as ZodMiniISODate,VldStringFormat as ZodMiniISODateTime,VldStringFormat as ZodMiniISODuration,VldStringFormat as ZodMiniISOTime,VldStringFormat as ZodMiniJWT,VldStringFormat as ZodMiniKSUID,VldStringFormat as ZodMiniMAC,VldStringFormat as ZodMiniNanoID,VldStringFormat as ZodMiniStringFormat,VldStringFormat as ZodMiniULID,VldStringFormat as ZodMiniURL,VldStringFormat as ZodMiniUUID,VldStringFormat as ZodMiniXID,VldStringFormat as ZodNanoID,VldStringFormat as ZodStringFormat,VldStringFormat as ZodULID,VldStringFormat as ZodURL,VldStringFormat as ZodUUID,VldStringFormat as ZodXID}from"../validators/string-formats.js";export{VldBigInt as ZodBigInt,VldBigInt as ZodBigIntFormat,VldBigInt as ZodMiniBigInt,VldBigInt as ZodMiniBigIntFormat}from"../validators/bigint.js";export{VldBoolean as ZodBoolean,VldBoolean as ZodMiniBoolean}from"../validators/boolean.js";export{VldCodec as ZodCodec,VldCodec as ZodMiniCodec}from"../validators/codec.js";export{VldCustom as ZodCustom,VldCustom as ZodMiniCustom,VldCustom as ZodMiniSuccess,VldCustom as ZodSuccess}from"../validators/custom.js";export{VldDate as ZodDate,VldDate as ZodMiniDate}from"../validators/date.js";export{VldDiscriminatedUnion as ZodDiscriminatedUnion,VldDiscriminatedUnion as ZodMiniDiscriminatedUnion}from"../validators/discriminated-union.js";export{VldEnum as ZodEnum,VldEnum as ZodMiniEnum}from"../validators/enum.js";export{VldFile as ZodFile,VldFile as ZodMiniFile}from"../validators/file.js";export{VldFunction as ZodFunction,VldFunction as ZodMiniFunction}from"../validators/function.js";export{VldJson as ZodJSON}from"../validators/json.js";export{VldLazy as ZodLazy,VldLazy as ZodMiniLazy}from"../validators/lazy.js";export{VldLiteral as ZodLiteral,VldLiteral as ZodMiniLiteral}from"../validators/literal.js";export{VldMap as ZodMap,VldMap as ZodMiniMap}from"../validators/map.js";export{VldNan as ZodMiniNaN,VldNan as ZodNaN}from"../validators/nan.js";export{VldNever as ZodMiniNever,VldNever as ZodNever}from"../validators/never.js";export{VldNull as ZodMiniNull,VldNull as ZodNull}from"../validators/null.js";export{VldNumber as ZodMiniNumber,VldNumber as ZodMiniNumberFormat,VldNumber as ZodNumber,VldNumber as ZodNumberFormat}from"../validators/number.js";export{VldObject as ZodMiniObject,VldObject as ZodObject}from"../validators/object.js";export{VldPromise as ZodMiniPromise,VldPromise as ZodPromise}from"../validators/promise.js";export{VldRecord as ZodMiniRecord,VldRecord as ZodRecord}from"../validators/record.js";export{VldSet as ZodMiniSet,VldSet as ZodSet}from"../validators/set.js";export{VldString as ZodMiniString,VldString as ZodString}from"../validators/string.js";export{VldSymbol as ZodMiniSymbol,VldSymbol as ZodSymbol}from"../validators/symbol.js";export{VldTemplateLiteral as ZodMiniTemplateLiteral,VldTemplateLiteral as ZodTemplateLiteral}from"../validators/template-literal.js";export{VldTuple as ZodMiniTuple,VldTuple as ZodTuple}from"../validators/tuple.js";export{VldUndefined as ZodMiniUndefined,VldUndefined as ZodUndefined}from"../validators/undefined.js";export{VldUnion as ZodMiniUnion,VldUnion as ZodUnion}from"../validators/union.js";export{VldUnknown as ZodMiniUnknown,VldUnknown as ZodUnknown}from"../validators/unknown.js";export{VldVoid as ZodMiniVoid,VldVoid as ZodVoid}from"../validators/void.js";export{VldXor as ZodMiniXor,VldXor as ZodXor}from"../validators/xor.js";export{b as base64Json,a as base64ToBytes,c as base64ToUint8Array,d as base64UrlToBytes,e as base64urlToBytes,f as bytesToUtf8,g as epochMillisToDate,h as epochSecondsToDate,i as hexLowerToBytes,j as hexToBytes,k as hexToUint8Array,l as invertCodec,m as isoDatetimeToDate,n as jsonCodec,o as jwtPayload,p as numberToBigInt,s as stringToBigInt,q as stringToBoolean,r as stringToHttpURL,t as stringToInt,u as stringToNumber,v as stringToURL,w as stringToUint8Array,x as uint8ArrayToBase64,y as uint8ArrayToBase64Url,z as uint8ArrayToHex,A as uint8ArrayToString,B as uriComponent,C as utf8ToBytes}from"../chunks/index-CkbfQQ4n.js";export{blue,bold,createTheme,cyan,dim,gray,green,grey,italic,magenta,default as pigment,red,strip,supportsColor,underline,vldTheme,white,yellow}from"../pigment.js";export{createEmitter,createEventBus,withEmitter}from"../compat/emitter.js";export{createVldKernel,definePlugin,getVldKernel,resetVldKernel,usePlugin}from"../kernel.js";export{flattenError,prettifyError,prettifyErrorColored,prettifyErrorPlain,treeifyError}from"../errors.js";export{getLocale,getMessages,getSupportedLocales,isLocaleLoaded,isLocaleSupported,registerLocale,setLocale}from"../locales/runtime.js";export{globalRegistry,registry}from"../registry.js";export{s as setLocaleAsync}from"../chunks/index-
|
|
1
|
+
import{number as Z}from"../index.js";export{$brand,$input,$output,NEVER,TimePrecision,ZodFirstPartyTypeKind,ZodIssueCode,_ZodString,_function,any,array,base64,base64Bytes,base64url,bigint,boolean,catch,check,cidrv4,cidrv6,clone,codec,coerce,config,core,createLogger,createNoOpLogger,creditCard,cuid,cuid2,custom,date,decode,decodeAsync,deepPartial,default,describe,disableLogging,discriminatedUnion,e164,email,emoji,enableDebug,encode,encodeAsync,endsWith,enum,exactOptional,file,float32,float64,formatError,fromJSONSchema,_function as function,getErrorMap,getLogger,gt,gte,guid,hash,hex,hexBytes,hostname,httpUrl,includes,initLogger,input,instanceof,int,int32,int64,intersection,ipv4,ipv6,iso,json,jwt,keyof,ksuid,lazy,length,literal,locales,looseObject,looseRecord,lowercase,lt,lte,mac,map,mapSchema,maxLength,maxSize,meta,mime,minLength,minSize,multipleOf,nan,nanoid,nativeEnum,negative,never,nonnegative,nonoptional,nonpositive,normalize,null,nullable,nullish,object,optional,output,overwrite,parse,parseAsync,partialRecord,pipe,positive,prefault,preprocess,promise,property,readonly,record,refine,regex,regexes,safeDecode,safeDecodeAsync,safeEncode,safeEncodeAsync,safeParse,safeParseAsync,set,setErrorMap,setLogLevel,size,slugify,startsWith,strictObject,string,stringFormat,stringbool,superRefine,symbol,templateLiteral,toJSONSchema,toLowerCase,toUpperCase,transform,trim,tuple,uint32,uint64,uint8Array,ulid,undefined,union,unknown,uppercase,url,util,uuid,uuidv4,uuidv6,uuidv7,default as v,void,xid,xor,z}from"../index.js";export{ZodCompileAsyncError,ZodCompileError,ZodCompileUnsupportedError,compile,getDiscriminatedOption,memoizer,properties,toZod,validate,validateAsync,compileFn as zodCompileFn}from"../compile.js";export{Err,Ok,ResultUtils,all,failure,flatMap,fromNullable,isErr,isOk,isResult,mapErr,match,success,tryCatch,tryCatchAsync,unwrap,unwrapOr}from"../compat/result.js";export{VldBase,VldMeta,VldBrand as ZodBranded,VldCatch as ZodCatch,VldDefault as ZodDefault,VldExactOptional as ZodExactOptional,VldMeta as ZodMeta,VldBrand as ZodMiniBrand,VldCatch as ZodMiniCatch,VldDefault as ZodMiniDefault,VldExactOptional as ZodMiniExactOptional,VldRefine as ZodMiniNonOptional,VldNullable as ZodMiniNullable,VldOptional as ZodMiniOptional,VldPipe as ZodMiniPipe,VldPrefault as ZodMiniPrefault,VldReadonly as ZodMiniReadonly,VldTransform as ZodMiniTransform,VldBase as ZodMiniType,VldRefine as ZodNonOptional,VldNullable as ZodNullable,VldOptional as ZodOptional,VldPipe as ZodPipe,VldPrefault as ZodPrefault,VldPreprocess as ZodPreprocess,VldReadonly as ZodReadonly,VldTransform as ZodTransform,VldBase as ZodType}from"../validators/base.js";export{V as VldError,V as ZodError,V as ZodRealError}from"../chunks/errors-core-CerMg2rq.js";export{VldIntersection,VldIntersection as ZodIntersection,VldIntersection as ZodMiniIntersection}from"../validators/intersection.js";export{VldAny as ZodAny,VldAny as ZodMiniAny}from"../validators/any.js";export{VldArray as ZodArray,VldArray as ZodMiniArray}from"../validators/array.js";export{VldStringFormat as ZodBase64,VldStringFormat as ZodBase64URL,VldStringFormat as ZodCIDRv4,VldStringFormat as ZodCIDRv6,VldStringFormat as ZodCUID,VldStringFormat as ZodCUID2,VldStringFormat as ZodCreditCard,VldStringFormat as ZodCustomStringFormat,VldStringFormat as ZodE164,VldStringFormat as ZodEmail,VldStringFormat as ZodEmoji,VldStringFormat as ZodGUID,VldStringFormat as ZodIPv4,VldStringFormat as ZodIPv6,VldStringFormat as ZodISODate,VldStringFormat as ZodISODateTime,VldStringFormat as ZodISODuration,VldStringFormat as ZodISOTime,VldStringFormat as ZodJWT,VldStringFormat as ZodKSUID,VldStringFormat as ZodMAC,VldStringFormat as ZodMiniBase64,VldStringFormat as ZodMiniBase64URL,VldStringFormat as ZodMiniCIDRv4,VldStringFormat as ZodMiniCIDRv6,VldStringFormat as ZodMiniCUID,VldStringFormat as ZodMiniCUID2,VldStringFormat as ZodMiniCreditCard,VldStringFormat as ZodMiniCustomStringFormat,VldStringFormat as ZodMiniE164,VldStringFormat as ZodMiniEmail,VldStringFormat as ZodMiniEmoji,VldStringFormat as ZodMiniGUID,VldStringFormat as ZodMiniIPv4,VldStringFormat as ZodMiniIPv6,VldStringFormat as ZodMiniISODate,VldStringFormat as ZodMiniISODateTime,VldStringFormat as ZodMiniISODuration,VldStringFormat as ZodMiniISOTime,VldStringFormat as ZodMiniJWT,VldStringFormat as ZodMiniKSUID,VldStringFormat as ZodMiniMAC,VldStringFormat as ZodMiniNanoID,VldStringFormat as ZodMiniStringFormat,VldStringFormat as ZodMiniULID,VldStringFormat as ZodMiniURL,VldStringFormat as ZodMiniUUID,VldStringFormat as ZodMiniXID,VldStringFormat as ZodNanoID,VldStringFormat as ZodStringFormat,VldStringFormat as ZodULID,VldStringFormat as ZodURL,VldStringFormat as ZodUUID,VldStringFormat as ZodXID}from"../validators/string-formats.js";export{VldBigInt as ZodBigInt,VldBigInt as ZodBigIntFormat,VldBigInt as ZodMiniBigInt,VldBigInt as ZodMiniBigIntFormat}from"../validators/bigint.js";export{VldBoolean as ZodBoolean,VldBoolean as ZodMiniBoolean}from"../validators/boolean.js";export{VldCodec as ZodCodec,VldCodec as ZodMiniCodec}from"../validators/codec.js";export{VldCustom as ZodCustom,VldCustom as ZodMiniCustom,VldCustom as ZodMiniSuccess,VldCustom as ZodSuccess}from"../validators/custom.js";export{VldDate as ZodDate,VldDate as ZodMiniDate}from"../validators/date.js";export{VldDiscriminatedUnion as ZodDiscriminatedUnion,VldDiscriminatedUnion as ZodMiniDiscriminatedUnion}from"../validators/discriminated-union.js";export{VldEnum as ZodEnum,VldEnum as ZodMiniEnum}from"../validators/enum.js";export{VldFile as ZodFile,VldFile as ZodMiniFile}from"../validators/file.js";export{VldFunction as ZodFunction,VldFunction as ZodMiniFunction}from"../validators/function.js";export{VldJson as ZodJSON}from"../validators/json.js";export{VldLazy as ZodLazy,VldLazy as ZodMiniLazy}from"../validators/lazy.js";export{VldLiteral as ZodLiteral,VldLiteral as ZodMiniLiteral}from"../validators/literal.js";export{VldMap as ZodMap,VldMap as ZodMiniMap}from"../validators/map.js";export{VldNan as ZodMiniNaN,VldNan as ZodNaN}from"../validators/nan.js";export{VldNever as ZodMiniNever,VldNever as ZodNever}from"../validators/never.js";export{VldNull as ZodMiniNull,VldNull as ZodNull}from"../validators/null.js";export{VldNumber as ZodMiniNumber,VldNumber as ZodMiniNumberFormat,VldNumber as ZodNumber,VldNumber as ZodNumberFormat}from"../validators/number.js";export{VldObject as ZodMiniObject,VldObject as ZodObject}from"../validators/object.js";export{VldPromise as ZodMiniPromise,VldPromise as ZodPromise}from"../validators/promise.js";export{VldRecord as ZodMiniRecord,VldRecord as ZodRecord}from"../validators/record.js";export{VldSet as ZodMiniSet,VldSet as ZodSet}from"../validators/set.js";export{VldString as ZodMiniString,VldString as ZodString}from"../validators/string.js";export{VldSymbol as ZodMiniSymbol,VldSymbol as ZodSymbol}from"../validators/symbol.js";export{VldTemplateLiteral as ZodMiniTemplateLiteral,VldTemplateLiteral as ZodTemplateLiteral}from"../validators/template-literal.js";export{VldTuple as ZodMiniTuple,VldTuple as ZodTuple}from"../validators/tuple.js";export{VldUndefined as ZodMiniUndefined,VldUndefined as ZodUndefined}from"../validators/undefined.js";export{VldUnion as ZodMiniUnion,VldUnion as ZodUnion}from"../validators/union.js";export{VldUnknown as ZodMiniUnknown,VldUnknown as ZodUnknown}from"../validators/unknown.js";export{VldVoid as ZodMiniVoid,VldVoid as ZodVoid}from"../validators/void.js";export{VldXor as ZodMiniXor,VldXor as ZodXor}from"../validators/xor.js";export{b as base64Json,a as base64ToBytes,c as base64ToUint8Array,d as base64UrlToBytes,e as base64urlToBytes,f as bytesToUtf8,g as epochMillisToDate,h as epochSecondsToDate,i as hexLowerToBytes,j as hexToBytes,k as hexToUint8Array,l as invertCodec,m as isoDatetimeToDate,n as jsonCodec,o as jwtPayload,p as numberToBigInt,s as stringToBigInt,q as stringToBoolean,r as stringToHttpURL,t as stringToInt,u as stringToNumber,v as stringToURL,w as stringToUint8Array,x as uint8ArrayToBase64,y as uint8ArrayToBase64Url,z as uint8ArrayToHex,A as uint8ArrayToString,B as uriComponent,C as utf8ToBytes}from"../chunks/index-CkbfQQ4n.js";export{blue,bold,createTheme,cyan,dim,gray,green,grey,italic,magenta,default as pigment,red,strip,supportsColor,underline,vldTheme,white,yellow}from"../pigment.js";export{createEmitter,createEventBus,withEmitter}from"../compat/emitter.js";export{createVldKernel,definePlugin,getVldKernel,resetVldKernel,usePlugin}from"../kernel.js";export{flattenError,prettifyError,prettifyErrorColored,prettifyErrorPlain,treeifyError}from"../errors.js";export{getLocale,getMessages,getSupportedLocales,isLocaleLoaded,isLocaleSupported,registerLocale,setLocale}from"../locales/runtime.js";export{globalRegistry,registry}from"../registry.js";export{s as setLocaleAsync}from"../chunks/index-CKPStM3V.js";function S(o){return Object.keys(o).filter(a=>o[a])}function M(o){return"string"==typeof o?o:o?.message||o?.error}const F=(o,a)=>o.pick(...S(a)),I=(o,a)=>o.omit(...S(a)),T=o=>o.partial(),U=o=>o.required(),D=(o,a)=>o.extend(a),E=(o,a)=>o.safeExtend(a),L=(o,a)=>a&&"function"==typeof a.parse?o.merge(a):o.extend(a),N=(o,a)=>o.catchall(a),O=(o,a)=>o.default("function"==typeof a?a():a),P=(o,a)=>{const r=M(a);return Z().min(o,r)},R=(o,a)=>{const r=M(a);return Z().max(o,r)},J=o=>o.exactPartial();export{O as _default,N as catchall,J as exactPartial,D as extend,R as maximum,L as merge,P as minimum,Z as number,I as omit,T as partial,F as pick,U as required,E as safeExtend};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{VldBase as s,VLD_VALIDATOR_TYPES as r,ensureVldError as e,resolveErrorMessage as a}from"./base.js";class VldCustom extends s{constructor(s){super(r.CUSTOM),this._parseFn=s.parse,this._parseAsyncFn=s.parseAsync||(s=>Promise.resolve(this._parseFn(s))),this._safeParseFn=s.safeParse?r=>{const a=s.safeParse(r);return a.success?{success:!0,data:a.data}:{success:!1,error:e(a.error)}}:s=>{try{return{success:!0,data:this._parseFn(s)}}catch(s){return{success:!1,error:e(s)}}},this._safeParseAsyncFn=s.safeParseAsync?async r=>{const a=await s.safeParseAsync(r);return a.success?{success:!0,data:a.data}:{success:!1,error:e(a.error)}}:async s=>{try{return{success:!0,data:await this._parseAsyncFn(s)}}catch(s){return{success:!1,error:e(s)}}}}static create(s){return new VldCustom(s)}parse(s){return this._parseFn(s)}safeParse(s){return this._safeParseFn(s)}async parseAsync(s){return this._parseAsyncFn(s)}async safeParseAsync(s){return this._safeParseAsyncFn(s)}}function t(s,r){if("function"==typeof s){const t=s;return VldCustom.create({parse:s=>{if(!t(s))throw e(a(r,"Custom validation failed"));return s}})}return s?VldCustom.create(s):VldCustom.create({parse:s=>s})}export{VldCustom,t as custom};
|
|
@@ -109,6 +109,15 @@ export declare class VldObject<T extends Record<string, any>> extends VldBase<un
|
|
|
109
109
|
* Create a new validator with deep partial (nested objects also partial)
|
|
110
110
|
*/
|
|
111
111
|
deepPartial(): VldObject<any>;
|
|
112
|
+
/**
|
|
113
|
+
* Zod 4 `z.exactPartial()` counterpart - same as `partial()` but errors
|
|
114
|
+
* when an explicit `undefined` is provided for an optional field. VLD
|
|
115
|
+
* mirrors Zod's behaviour by rejecting explicit-undefined inputs through
|
|
116
|
+
* `VldExactOptional`.
|
|
117
|
+
*/
|
|
118
|
+
exactPartial(): VldObject<{
|
|
119
|
+
[K in keyof T]?: T[K];
|
|
120
|
+
}>;
|
|
112
121
|
/**
|
|
113
122
|
* Create a new validator with only specified keys
|
|
114
123
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{VldBase as e,VLD_VALIDATOR_TYPES as t,VldOptional as s}from"./base.js";import{getMessages as i}from"../locales/runtime.js";import{VldEnum as r}from"./enum.js";import{i as n}from"../chunks/security-Dy24T8N7.js";import{V as o}from"../chunks/errors-core-CerMg2rq.js";class VldObject extends e{createSafeParseError(e,t){if(e instanceof o)return void 0!==t?new o(e.issues.map(e=>({...e,path:e.path?[t,...e.path]:[t],message:e.message.startsWith("Invalid field")?e.message:i().objectField(String(t),e.message)}))):e;const s=e instanceof Error?e.message:String(e);return new o([{code:"invalid_type",path:void 0!==t?[t]:[],message:void 0===t||s.startsWith("Invalid field")?s:i().objectField(String(t),s)}])}constructor(s){super(t.OBJECT),this._config=s,this._shapeKeys=Object.keys(s.shape),this._shapeKeysSet=new Set(this._shapeKeys),this._validators=this._shapeKeys.map(e=>this.tryGetFieldValidator(e)),this._validatorTypes=this._shapeKeys.map((e,t)=>this._validators[t]?.validatorType||this.getValidatorType(e)),this._simpleFieldModes=this._validators.map((e,t)=>this.getSimpleFieldMode(e,this._validatorTypes[t])),this._simpleFieldValues=this._validators.map((e,t)=>"literal"===this._simpleFieldModes[t]?e.literal:void 0),this._canUseSimpleObjectFastPath=!s.strict&&!s.passthrough&&!s.catchall&&this._shapeKeys.length>0&&this._simpleFieldModes.every(e=>void 0!==e),this._canUseSafeParseFastPath=this._validators.every(t=>t instanceof e)&&(void 0===s.catchall||s.catchall instanceof e)}tryGetFieldValidator(e){try{const t=Object.getOwnPropertyDescriptor(this._config.shape,e);if(t?.get)return;return this.resolveFieldValidator(e)}catch{return}}resolveFieldValidator(e){try{const t=this._config.shape[e];if(!t||"function"!=typeof t.safeParse)return;return t}catch{return}}getFieldValidator(e,t){const s=(void 0===t?void 0:this._validators[t])||this.resolveFieldValidator(e);if(!s)throw new Error(`Invalid validator for field "${e}"`);return s}getValidatorType(e){try{const s=this._config.shape[e];return s?.validatorType||t.UNKNOWN}catch{return t.UNKNOWN}}getSimpleFieldMode(e,s){if(e&&!0===e.isSimple)switch(s){case t.STRING:return"string";case t.NUMBER:return"number";case t.BOOLEAN:return"boolean";case t.BIGINT:return"bigint";case t.SYMBOL:return"symbol";case t.NULL:return"null";case t.UNDEFINED:case t.VOID:return"undefinedValue";case t.LITERAL:return"literal";case t.ANY:case t.UNKNOWN:return"passthrough";default:return}}getSimpleFieldError(e,t,s){switch(e){case"string":return i().invalidString;case"number":return i().invalidNumber;case"boolean":return i().invalidBoolean;case"bigint":return i().invalidBigint;case"symbol":return i().invalidSymbol;case"null":return"Expected null, received "+typeof s;case"undefinedValue":return i().expectedUndefined;case"literal":return i().literalExpected(JSON.stringify(t),JSON.stringify(s));default:return i().invalidObject}}parseCheckedField(e,s,i){if(s===t.STRING&&"string"==typeof i){const t=e.parseKnownString;if("function"==typeof t)return t.call(e,i)}if(s===t.NUMBER&&"number"==typeof i&&!isNaN(i)){const t=e.parseKnownNumber;if("function"==typeof t)return t.call(e,i)}if(s===t.BOOLEAN&&"boolean"==typeof i){const t=e.parseKnownBoolean;if("function"==typeof t)return t.call(e,i)}if(s===t.BIGINT&&"bigint"==typeof i){const t=e.parseKnownBigInt;if("function"==typeof t)return t.call(e,i)}if(s===t.SYMBOL&&"symbol"==typeof i){const t=e.parseKnownSymbol;if("function"==typeof t)return t.call(e,i)}if(s===t.FUNCTION&&"function"==typeof i){const t=e.parseKnownFunction;if("function"==typeof t)return t.call(e,i)}if(s===t.FILE&&"object"==typeof i&&null!==i&&("size"in i&&"type"in i||"undefined"!=typeof File&&i instanceof File)){const t=e.parseKnownFile;if("function"==typeof t)return t.call(e,i)}if(s===t.DATE&&i instanceof Date){const t=e.parseKnownDate;if("function"==typeof t)return t.call(e,i)}if(s===t.OBJECT&&"object"==typeof i&&null!==i&&!Array.isArray(i)){const t=e.parseKnownObject;if("function"==typeof t)return t.call(e,i)}if(s===t.ARRAY&&Array.isArray(i)){const t=e.parseKnownArray;if("function"==typeof t)return t.call(e,i)}if(s===t.TUPLE&&Array.isArray(i)){const t=e.parseKnownTuple;if("function"==typeof t)return t.call(e,i)}if(s===t.RECORD&&"object"==typeof i&&null!==i&&!Array.isArray(i)){const t=e.parseKnownRecord;if("function"==typeof t)return t.call(e,i)}if(s===t.SET&&i instanceof Set){const t=e.parseKnownSet;if("function"==typeof t)return t.call(e,i)}if(s===t.MAP&&i instanceof Map){const t=e.parseKnownMap;if("function"==typeof t)return t.call(e,i)}return e.parse(i)}parseSimpleObjectValue(e,t,s=!1){if(2===this._shapeKeys.length&&"string"===this._simpleFieldModes[0]&&"number"===this._simpleFieldModes[1]){const t=this._shapeKeys[0],s=e[t];if("string"!=typeof s)throw new Error(i().objectField(t,i().invalidString));const r=this._shapeKeys[1],n=e[r];if("number"!=typeof n||isNaN(n))throw new Error(i().objectField(r,i().invalidNumber));const o={};return o[t]=s,o[r]=n,o}if(3===this._shapeKeys.length&&"literal"===this._simpleFieldModes[0]&&"string"===this._simpleFieldModes[1]&&"number"===this._simpleFieldModes[2]){const r=this._shapeKeys[0],n=e[r],o=this._simpleFieldValues[0];if((!s||r!==t)&&n!==o)throw new Error(i().objectField(r,this.getSimpleFieldError("literal",o,n)));const a=this._shapeKeys[1],c=e[a];if("string"!=typeof c)throw new Error(i().objectField(a,i().invalidString));const l=this._shapeKeys[2],h=e[l];if("number"!=typeof h||isNaN(h))throw new Error(i().objectField(l,i().invalidNumber));const f={};return f[r]=o,f[a]=c,f[l]=h,f}const r={};for(let n=0;n<this._shapeKeys.length;n++){const o=this._shapeKeys[n],a=e[o],c=this._simpleFieldModes[n];switch(c){case"string":if("string"!=typeof a)throw new Error(i().objectField(o,i().invalidString));r[o]=a;break;case"number":if("number"!=typeof a||isNaN(a))throw new Error(i().objectField(o,i().invalidNumber));r[o]=a;break;case"boolean":if("boolean"!=typeof a)throw new Error(i().objectField(o,i().invalidBoolean));r[o]=a;break;case"bigint":if("bigint"!=typeof a)throw new Error(i().objectField(o,i().invalidBigint));r[o]=a;break;case"symbol":if("symbol"!=typeof a)throw new Error(i().objectField(o,i().invalidSymbol));r[o]=a;break;case"null":if(null!==a)throw new Error(i().objectField(o,this.getSimpleFieldError(c,void 0,a)));r[o]=null;break;case"undefinedValue":if(void 0!==a)throw new Error(i().objectField(o,i().expectedUndefined));r[o]=void 0;break;case"literal":if(s&&o===t){r[o]=this._simpleFieldValues[n];break}if(a!==this._simpleFieldValues[n])throw new Error(i().objectField(o,this.getSimpleFieldError(c,this._simpleFieldValues[n],a)));r[o]=this._simpleFieldValues[n];break;case"passthrough":r[o]=a;break;default:throw new Error(i().objectField(o,i().invalidObject))}}return r}get config(){return this._config}get shapeKeys(){return this._shapeKeys}get shapeKeysSet(){return this._shapeKeysSet}static create(e){return new VldObject({shape:e})}parse(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this._config.errorMessage||i().invalidObject);return this.parseObjectValue(e)}parseKnownObject(e,t){return this.parseObjectValue(e,t)}parseTrustedKnownObject(e,t){return this.parseObjectValue(e,t,!0)}parseObjectValue(e,t,s=!1){if(this._canUseSimpleObjectFastPath)return this.parseSimpleObjectValue(e,t,s);const r={};let a="";try{for(let n=0;n<this._shapeKeys.length;n++){if(a=this._shapeKeys[n],s&&a===t&&"literal"===this._simpleFieldModes[n]){r[a]=this._simpleFieldValues[n];continue}const o=this._simpleFieldModes[n];if(void 0!==o){const t=e[a];switch(o){case"string":if("string"!=typeof t)throw new Error(i().invalidString);r[a]=t;continue;case"number":if("number"!=typeof t||isNaN(t))throw new Error(i().invalidNumber);r[a]=t;continue;case"boolean":if("boolean"!=typeof t)throw new Error(i().invalidBoolean);r[a]=t;continue;case"bigint":if("bigint"!=typeof t)throw new Error(i().invalidBigint);r[a]=t;continue;case"symbol":if("symbol"!=typeof t)throw new Error(i().invalidSymbol);r[a]=t;continue;case"null":if(null!==t)throw new Error(this.getSimpleFieldError(o,void 0,t));r[a]=null;continue;case"undefinedValue":if(void 0!==t)throw new Error(i().expectedUndefined);r[a]=void 0;continue;case"literal":if(t!==this._simpleFieldValues[n])throw new Error(this.getSimpleFieldError(o,this._simpleFieldValues[n],t));r[a]=this._simpleFieldValues[n];continue;case"passthrough":r[a]=t;continue}continue}const c=this.getFieldValidator(a,n);r[a]=this.parseCheckedField(c,this._validatorTypes[n],e[a])}}catch(e){if(e instanceof o)throw new o(e.issues.map(e=>({...e,path:e.path?[a,...e.path]:[a],message:i().objectField(a,e.message.startsWith("Invalid field")?e.message.replace(/^Invalid field "[^"]+": /,""):e.message)})));const t=e instanceof Error?e.message:String(e);throw new o([{code:"invalid_type",path:[a],message:t.startsWith("Invalid field")?t:i().objectField(a,t)}])}if(this._config.strict||this._config.passthrough||this._config.catchall){const t=Object.keys(e);if(this._config.strict){const e=[];for(let s=0;s<t.length;s++){const i=t[s];this._shapeKeysSet.has(i)||e.push(i)}if(e.length>0)throw new Error(i().unexpectedKeys(e))}if(this._config.passthrough)for(let s=0;s<t.length;s++){const i=t[s];this._shapeKeysSet.has(i)||n(i)||(r[i]=e[i])}if(this._config.catchall)for(let s=0;s<t.length;s++){const o=t[s];if(!this._shapeKeysSet.has(o)&&!n(o))try{r[o]=this._config.catchall.parse(e[o])}catch(e){throw new Error(i().objectField(o,e.message))}}}return r}safeParse(t){if("object"!=typeof t||null===t||Array.isArray(t))return{success:!1,error:this.createSafeParseError(this._config.errorMessage||i().invalidObject)};const s=t;if(this._canUseSimpleObjectFastPath)try{return{success:!0,data:this.parseSimpleObjectValue(s)}}catch{}if(this._canUseSafeParseFastPath)try{return{success:!0,data:this.parseObjectValue(s)}}catch{}const r={},a=[];for(let t=0;t<this._shapeKeys.length;t++){const n=this._shapeKeys[t],o=s[n],c=this._simpleFieldModes[t];if(void 0!==c){if("string"===c&&"string"==typeof o||"number"===c&&"number"==typeof o&&!isNaN(o)||"boolean"===c&&"boolean"==typeof o||"bigint"===c&&"bigint"==typeof o||"symbol"===c&&"symbol"==typeof o||"null"===c&&null===o||"undefinedValue"===c&&void 0===o||"literal"===c&&o===this._simpleFieldValues[t]||"passthrough"===c){r[n]="literal"===c?this._simpleFieldValues[t]:"null"===c?null:o;continue}a.push({code:"invalid_type",path:[n],message:i().objectField(n,this.getSimpleFieldError(c,this._simpleFieldValues[t],o))});continue}let l;try{l=this.getFieldValidator(n,t)}catch(e){const t=this.createSafeParseError(e,n);a.push(...t.issues);continue}try{if(l instanceof e)r[n]=this.parseCheckedField(l,this._validatorTypes[t],o);else{const e=l.safeParse(o);if(e.success)r[n]=e.data;else{const t=this.createSafeParseError(e.error,n);a.push(...t.issues)}}}catch(e){const t=this.createSafeParseError(e,n);a.push(...t.issues)}}if(this._config.strict||this._config.passthrough||this._config.catchall){const t=Object.keys(s);if(this._config.strict){const e=[];for(let s=0;s<t.length;s++){const i=t[s];this._shapeKeysSet.has(i)||e.push(i)}e.length>0&&a.push(...e.map(e=>({code:"unrecognized_keys",path:[e],message:i().unexpectedKeys([e])})))}if(this._config.passthrough)for(let e=0;e<t.length;e++){const i=t[e];this._shapeKeysSet.has(i)||n(i)||(r[i]=s[i])}if(this._config.catchall){const i=this._config.catchall;for(let o=0;o<t.length;o++){const c=t[o];if(!this._shapeKeysSet.has(c)&&!n(c))try{if(i instanceof e)r[c]=i.parse(s[c]);else{const e=i.safeParse(s[c]);if(e.success)r[c]=e.data;else{const t=this.createSafeParseError(e.error,c);a.push(...t.issues)}}}catch(e){const t=this.createSafeParseError(e,c);a.push(...t.issues)}}}}return a.length>0?{success:!1,error:new o(a)}:{success:!0,data:r}}encode(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this._config.errorMessage||i().invalidObject);return this.encodeObjectSync(e)}safeEncode(e){try{return{success:!0,data:this.encode(e)}}catch(e){return{success:!1,error:this.createSafeParseError(e.message)}}}async encodeAsync(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this._config.errorMessage||i().invalidObject);return this.encodeObjectAsync(e)}async safeEncodeAsync(e){try{return{success:!0,data:await this.encodeAsync(e)}}catch(e){return{success:!1,error:this.createSafeParseError(e.message)}}}encodeObjectSync(e){const t={};for(let s=0;s<this._shapeKeys.length;s++){const i=this._shapeKeys[s],r=this.getFieldValidator(i,s).encode(e[i]);(void 0!==r||Object.prototype.hasOwnProperty.call(e,i))&&(t[i]=r)}return this.encodeExtraKeysSync(e,t),t}async encodeObjectAsync(e){const t={};for(let s=0;s<this._shapeKeys.length;s++){const i=this._shapeKeys[s],r=await this.getFieldValidator(i,s).encodeAsync(e[i]);(void 0!==r||Object.prototype.hasOwnProperty.call(e,i))&&(t[i]=r)}const s=this.getEncodedExtraKeys(e);for(const i of s)n(i)||(this._config.catchall?t[i]=await this._config.catchall.encodeAsync(e[i]):this._config.passthrough&&(t[i]=e[i]));return t}getEncodedExtraKeys(e){const t=Object.keys(e).filter(e=>!this._shapeKeysSet.has(e));if(this._config.strict&&t.length>0)throw new Error(i().unexpectedKeys(t));return t}encodeExtraKeysSync(e,t){for(const s of this.getEncodedExtraKeys(e))n(s)||(this._config.catchall?t[s]=this._config.catchall.encode(e[s]):this._config.passthrough&&(t[s]=e[s]))}strict(e){return new VldObject({...this._config,strict:!0,passthrough:!1,errorMessage:e})}passthrough(){return new VldObject({...this._config,strict:!1,passthrough:!0})}loose(){return this.passthrough()}strip(){const e={...this._config,strict:!1,passthrough:!1};return delete e.catchall,new VldObject(e)}partial(){const e={};for(const t in this._config.shape)e[t]=new s(this._config.shape[t]);return new VldObject({...this._config,shape:e})}deepPartial(){const e={};for(const t in this._config.shape){const i=this._config.shape[t];e[t]=new s(i instanceof VldObject?i.deepPartial():i)}return new VldObject({...this._config,shape:e})}pick(...e){const t={};let s=[];s=1!==e.length||"object"!=typeof e[0]||null===e[0]||Array.isArray(e[0])?e.flat():Object.keys(e[0]).filter(t=>e[0][t]);for(const e of s)e in this._config.shape&&(t[e]=this._config.shape[e]);return new VldObject({...this._config,shape:t})}omit(...e){let t;t=1!==e.length||"object"!=typeof e[0]||null===e[0]||Array.isArray(e[0])?new Set(e.flat()):new Set(Object.keys(e[0]).filter(t=>e[0][t]));const s={};for(const e in this._config.shape)t.has(e)||(s[e]=this._config.shape[e]);return new VldObject({...this._config,shape:s})}extend(e){return new VldObject({...this._config,shape:{...this._config.shape,...e}})}merge(e){return new VldObject({...this._config,shape:{...this._config.shape,...e.config.shape}})}required(){const e={};for(const t in this._config.shape){const i=this._config.shape[t];if(i instanceof s){const s=i.baseValidator;if(!s||"function"!=typeof s.parse)throw new Error(`Invalid VldOptional structure for field "${t}": missing or invalid baseValidator`);e[t]=s}else e[t]=i}return new VldObject({...this._config,shape:e})}catchall(e){return new VldObject({...this._config,catchall:e,passthrough:!1})}get shape(){return this._config.shape}keyof(){const e=Object.keys(this._config.shape);if(0===e.length)throw new Error("Cannot create keyof enum from empty object");return r.create(e)}safeExtend(e){const t=new Set(Object.keys(this._config.shape)),s=Object.keys(e),r=[];for(const e of s)t.has(e)&&r.push(e);if(r.length>0)throw new Error(`safeExtend: ${i().safeExtendOverlap(r)}`);return new VldObject({...this._config,shape:{...this._config.shape,...e}})}}export{VldObject};
|
|
1
|
+
import{VldBase as e,VLD_VALIDATOR_TYPES as t,VldOptional as s,VldExactOptional as i}from"./base.js";import{getMessages as r}from"../locales/runtime.js";import{VldEnum as n}from"./enum.js";import{i as o}from"../chunks/security-Dy24T8N7.js";import{V as a}from"../chunks/errors-core-CerMg2rq.js";class VldObject extends e{createSafeParseError(e,t){if(e instanceof a)return void 0!==t?new a(e.issues.map(e=>({...e,path:e.path?[t,...e.path]:[t],message:e.message.startsWith("Invalid field")?e.message:r().objectField(String(t),e.message)}))):e;const s=e instanceof Error?e.message:String(e);return new a([{code:"invalid_type",path:void 0!==t?[t]:[],message:void 0===t||s.startsWith("Invalid field")?s:r().objectField(String(t),s)}])}constructor(s){super(t.OBJECT),this._config=s,this._shapeKeys=Object.keys(s.shape),this._shapeKeysSet=new Set(this._shapeKeys),this._validators=this._shapeKeys.map(e=>this.tryGetFieldValidator(e)),this._validatorTypes=this._shapeKeys.map((e,t)=>this._validators[t]?.validatorType||this.getValidatorType(e)),this._simpleFieldModes=this._validators.map((e,t)=>this.getSimpleFieldMode(e,this._validatorTypes[t])),this._simpleFieldValues=this._validators.map((e,t)=>"literal"===this._simpleFieldModes[t]?e.literal:void 0),this._canUseSimpleObjectFastPath=!s.strict&&!s.passthrough&&!s.catchall&&this._shapeKeys.length>0&&this._simpleFieldModes.every(e=>void 0!==e),this._canUseSafeParseFastPath=this._validators.every(t=>t instanceof e)&&(void 0===s.catchall||s.catchall instanceof e)}tryGetFieldValidator(e){try{const t=Object.getOwnPropertyDescriptor(this._config.shape,e);if(t?.get)return;return this.resolveFieldValidator(e)}catch{return}}resolveFieldValidator(e){try{const t=this._config.shape[e];if(!t||"function"!=typeof t.safeParse)return;return t}catch{return}}getFieldValidator(e,t){const s=(void 0===t?void 0:this._validators[t])||this.resolveFieldValidator(e);if(!s)throw new Error(`Invalid validator for field "${e}"`);return s}getValidatorType(e){try{const s=this._config.shape[e];return s?.validatorType||t.UNKNOWN}catch{return t.UNKNOWN}}getSimpleFieldMode(e,s){if(e&&!0===e.isSimple)switch(s){case t.STRING:return"string";case t.NUMBER:return"number";case t.BOOLEAN:return"boolean";case t.BIGINT:return"bigint";case t.SYMBOL:return"symbol";case t.NULL:return"null";case t.UNDEFINED:case t.VOID:return"undefinedValue";case t.LITERAL:return"literal";case t.ANY:case t.UNKNOWN:return"passthrough";default:return}}getSimpleFieldError(e,t,s){switch(e){case"string":return r().invalidString;case"number":return r().invalidNumber;case"boolean":return r().invalidBoolean;case"bigint":return r().invalidBigint;case"symbol":return r().invalidSymbol;case"null":return"Expected null, received "+typeof s;case"undefinedValue":return r().expectedUndefined;case"literal":return r().literalExpected(JSON.stringify(t),JSON.stringify(s));default:return r().invalidObject}}parseCheckedField(e,s,i){if(s===t.STRING&&"string"==typeof i){const t=e.parseKnownString;if("function"==typeof t)return t.call(e,i)}if(s===t.NUMBER&&"number"==typeof i&&!isNaN(i)){const t=e.parseKnownNumber;if("function"==typeof t)return t.call(e,i)}if(s===t.BOOLEAN&&"boolean"==typeof i){const t=e.parseKnownBoolean;if("function"==typeof t)return t.call(e,i)}if(s===t.BIGINT&&"bigint"==typeof i){const t=e.parseKnownBigInt;if("function"==typeof t)return t.call(e,i)}if(s===t.SYMBOL&&"symbol"==typeof i){const t=e.parseKnownSymbol;if("function"==typeof t)return t.call(e,i)}if(s===t.FUNCTION&&"function"==typeof i){const t=e.parseKnownFunction;if("function"==typeof t)return t.call(e,i)}if(s===t.FILE&&"object"==typeof i&&null!==i&&("size"in i&&"type"in i||"undefined"!=typeof File&&i instanceof File)){const t=e.parseKnownFile;if("function"==typeof t)return t.call(e,i)}if(s===t.DATE&&i instanceof Date){const t=e.parseKnownDate;if("function"==typeof t)return t.call(e,i)}if(s===t.OBJECT&&"object"==typeof i&&null!==i&&!Array.isArray(i)){const t=e.parseKnownObject;if("function"==typeof t)return t.call(e,i)}if(s===t.ARRAY&&Array.isArray(i)){const t=e.parseKnownArray;if("function"==typeof t)return t.call(e,i)}if(s===t.TUPLE&&Array.isArray(i)){const t=e.parseKnownTuple;if("function"==typeof t)return t.call(e,i)}if(s===t.RECORD&&"object"==typeof i&&null!==i&&!Array.isArray(i)){const t=e.parseKnownRecord;if("function"==typeof t)return t.call(e,i)}if(s===t.SET&&i instanceof Set){const t=e.parseKnownSet;if("function"==typeof t)return t.call(e,i)}if(s===t.MAP&&i instanceof Map){const t=e.parseKnownMap;if("function"==typeof t)return t.call(e,i)}return e.parse(i)}parseSimpleObjectValue(e,t,s=!1){if(2===this._shapeKeys.length&&"string"===this._simpleFieldModes[0]&&"number"===this._simpleFieldModes[1]){const t=this._shapeKeys[0],s=e[t];if("string"!=typeof s)throw new Error(r().objectField(t,r().invalidString));const i=this._shapeKeys[1],n=e[i];if("number"!=typeof n||isNaN(n))throw new Error(r().objectField(i,r().invalidNumber));const o={};return o[t]=s,o[i]=n,o}if(3===this._shapeKeys.length&&"literal"===this._simpleFieldModes[0]&&"string"===this._simpleFieldModes[1]&&"number"===this._simpleFieldModes[2]){const i=this._shapeKeys[0],n=e[i],o=this._simpleFieldValues[0];if((!s||i!==t)&&n!==o)throw new Error(r().objectField(i,this.getSimpleFieldError("literal",o,n)));const a=this._shapeKeys[1],c=e[a];if("string"!=typeof c)throw new Error(r().objectField(a,r().invalidString));const l=this._shapeKeys[2],h=e[l];if("number"!=typeof h||isNaN(h))throw new Error(r().objectField(l,r().invalidNumber));const f={};return f[i]=o,f[a]=c,f[l]=h,f}const i={};for(let n=0;n<this._shapeKeys.length;n++){const o=this._shapeKeys[n],a=e[o],c=this._simpleFieldModes[n];switch(c){case"string":if("string"!=typeof a)throw new Error(r().objectField(o,r().invalidString));i[o]=a;break;case"number":if("number"!=typeof a||isNaN(a))throw new Error(r().objectField(o,r().invalidNumber));i[o]=a;break;case"boolean":if("boolean"!=typeof a)throw new Error(r().objectField(o,r().invalidBoolean));i[o]=a;break;case"bigint":if("bigint"!=typeof a)throw new Error(r().objectField(o,r().invalidBigint));i[o]=a;break;case"symbol":if("symbol"!=typeof a)throw new Error(r().objectField(o,r().invalidSymbol));i[o]=a;break;case"null":if(null!==a)throw new Error(r().objectField(o,this.getSimpleFieldError(c,void 0,a)));i[o]=null;break;case"undefinedValue":if(void 0!==a)throw new Error(r().objectField(o,r().expectedUndefined));i[o]=void 0;break;case"literal":if(s&&o===t){i[o]=this._simpleFieldValues[n];break}if(a!==this._simpleFieldValues[n])throw new Error(r().objectField(o,this.getSimpleFieldError(c,this._simpleFieldValues[n],a)));i[o]=this._simpleFieldValues[n];break;case"passthrough":i[o]=a;break;default:throw new Error(r().objectField(o,r().invalidObject))}}return i}get config(){return this._config}get shapeKeys(){return this._shapeKeys}get shapeKeysSet(){return this._shapeKeysSet}static create(e){return new VldObject({shape:e})}parse(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this._config.errorMessage||r().invalidObject);return this.parseObjectValue(e)}parseKnownObject(e,t){return this.parseObjectValue(e,t)}parseTrustedKnownObject(e,t){return this.parseObjectValue(e,t,!0)}parseObjectValue(e,t,s=!1){if(this._canUseSimpleObjectFastPath)return this.parseSimpleObjectValue(e,t,s);const i={};let n="";try{for(let o=0;o<this._shapeKeys.length;o++){if(n=this._shapeKeys[o],s&&n===t&&"literal"===this._simpleFieldModes[o]){i[n]=this._simpleFieldValues[o];continue}const a=this._simpleFieldModes[o];if(void 0!==a){const t=e[n];switch(a){case"string":if("string"!=typeof t)throw new Error(r().invalidString);i[n]=t;continue;case"number":if("number"!=typeof t||isNaN(t))throw new Error(r().invalidNumber);i[n]=t;continue;case"boolean":if("boolean"!=typeof t)throw new Error(r().invalidBoolean);i[n]=t;continue;case"bigint":if("bigint"!=typeof t)throw new Error(r().invalidBigint);i[n]=t;continue;case"symbol":if("symbol"!=typeof t)throw new Error(r().invalidSymbol);i[n]=t;continue;case"null":if(null!==t)throw new Error(this.getSimpleFieldError(a,void 0,t));i[n]=null;continue;case"undefinedValue":if(void 0!==t)throw new Error(r().expectedUndefined);i[n]=void 0;continue;case"literal":if(t!==this._simpleFieldValues[o])throw new Error(this.getSimpleFieldError(a,this._simpleFieldValues[o],t));i[n]=this._simpleFieldValues[o];continue;case"passthrough":i[n]=t;continue}continue}const c=this.getFieldValidator(n,o);i[n]=this.parseCheckedField(c,this._validatorTypes[o],e[n])}}catch(e){if(e instanceof a)throw new a(e.issues.map(e=>({...e,path:e.path?[n,...e.path]:[n],message:r().objectField(n,e.message.startsWith("Invalid field")?e.message.replace(/^Invalid field "[^"]+": /,""):e.message)})));const t=e instanceof Error?e.message:String(e);throw new a([{code:"invalid_type",path:[n],message:t.startsWith("Invalid field")?t:r().objectField(n,t)}])}if(this._config.strict||this._config.passthrough||this._config.catchall){const t=Object.keys(e);if(this._config.strict){const e=[];for(let s=0;s<t.length;s++){const i=t[s];this._shapeKeysSet.has(i)||e.push(i)}if(e.length>0)throw new Error(r().unexpectedKeys(e))}if(this._config.passthrough)for(let s=0;s<t.length;s++){const r=t[s];this._shapeKeysSet.has(r)||o(r)||(i[r]=e[r])}if(this._config.catchall)for(let s=0;s<t.length;s++){const n=t[s];if(!this._shapeKeysSet.has(n)&&!o(n))try{i[n]=this._config.catchall.parse(e[n])}catch(e){throw new Error(r().objectField(n,e.message))}}}return i}safeParse(t){if("object"!=typeof t||null===t||Array.isArray(t))return{success:!1,error:this.createSafeParseError(this._config.errorMessage||r().invalidObject)};const s=t;if(this._canUseSimpleObjectFastPath)try{return{success:!0,data:this.parseSimpleObjectValue(s)}}catch{}if(this._canUseSafeParseFastPath)try{return{success:!0,data:this.parseObjectValue(s)}}catch{}const i={},n=[];for(let t=0;t<this._shapeKeys.length;t++){const o=this._shapeKeys[t],a=s[o],c=this._simpleFieldModes[t];if(void 0!==c){if("string"===c&&"string"==typeof a||"number"===c&&"number"==typeof a&&!isNaN(a)||"boolean"===c&&"boolean"==typeof a||"bigint"===c&&"bigint"==typeof a||"symbol"===c&&"symbol"==typeof a||"null"===c&&null===a||"undefinedValue"===c&&void 0===a||"literal"===c&&a===this._simpleFieldValues[t]||"passthrough"===c){i[o]="literal"===c?this._simpleFieldValues[t]:"null"===c?null:a;continue}n.push({code:"invalid_type",path:[o],message:r().objectField(o,this.getSimpleFieldError(c,this._simpleFieldValues[t],a))});continue}let l;try{l=this.getFieldValidator(o,t)}catch(e){const t=this.createSafeParseError(e,o);n.push(...t.issues);continue}try{if(l instanceof e)i[o]=this.parseCheckedField(l,this._validatorTypes[t],a);else{const e=l.safeParse(a);if(e.success)i[o]=e.data;else{const t=this.createSafeParseError(e.error,o);n.push(...t.issues)}}}catch(e){const t=this.createSafeParseError(e,o);n.push(...t.issues)}}if(this._config.strict||this._config.passthrough||this._config.catchall){const t=Object.keys(s);if(this._config.strict){const e=[];for(let s=0;s<t.length;s++){const i=t[s];this._shapeKeysSet.has(i)||e.push(i)}e.length>0&&n.push(...e.map(e=>({code:"unrecognized_keys",path:[e],message:r().unexpectedKeys([e])})))}if(this._config.passthrough)for(let e=0;e<t.length;e++){const r=t[e];this._shapeKeysSet.has(r)||o(r)||(i[r]=s[r])}if(this._config.catchall){const r=this._config.catchall;for(let a=0;a<t.length;a++){const c=t[a];if(!this._shapeKeysSet.has(c)&&!o(c))try{if(r instanceof e)i[c]=r.parse(s[c]);else{const e=r.safeParse(s[c]);if(e.success)i[c]=e.data;else{const t=this.createSafeParseError(e.error,c);n.push(...t.issues)}}}catch(e){const t=this.createSafeParseError(e,c);n.push(...t.issues)}}}}return n.length>0?{success:!1,error:new a(n)}:{success:!0,data:i}}encode(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this._config.errorMessage||r().invalidObject);return this.encodeObjectSync(e)}safeEncode(e){try{return{success:!0,data:this.encode(e)}}catch(e){return{success:!1,error:this.createSafeParseError(e.message)}}}async encodeAsync(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this._config.errorMessage||r().invalidObject);return this.encodeObjectAsync(e)}async safeEncodeAsync(e){try{return{success:!0,data:await this.encodeAsync(e)}}catch(e){return{success:!1,error:this.createSafeParseError(e.message)}}}encodeObjectSync(e){const t={};for(let s=0;s<this._shapeKeys.length;s++){const i=this._shapeKeys[s],r=this.getFieldValidator(i,s).encode(e[i]);(void 0!==r||Object.prototype.hasOwnProperty.call(e,i))&&(t[i]=r)}return this.encodeExtraKeysSync(e,t),t}async encodeObjectAsync(e){const t={};for(let s=0;s<this._shapeKeys.length;s++){const i=this._shapeKeys[s],r=await this.getFieldValidator(i,s).encodeAsync(e[i]);(void 0!==r||Object.prototype.hasOwnProperty.call(e,i))&&(t[i]=r)}const s=this.getEncodedExtraKeys(e);for(const i of s)o(i)||(this._config.catchall?t[i]=await this._config.catchall.encodeAsync(e[i]):this._config.passthrough&&(t[i]=e[i]));return t}getEncodedExtraKeys(e){const t=Object.keys(e).filter(e=>!this._shapeKeysSet.has(e));if(this._config.strict&&t.length>0)throw new Error(r().unexpectedKeys(t));return t}encodeExtraKeysSync(e,t){for(const s of this.getEncodedExtraKeys(e))o(s)||(this._config.catchall?t[s]=this._config.catchall.encode(e[s]):this._config.passthrough&&(t[s]=e[s]))}strict(e){return new VldObject({...this._config,strict:!0,passthrough:!1,errorMessage:e})}passthrough(){return new VldObject({...this._config,strict:!1,passthrough:!0})}loose(){return this.passthrough()}strip(){const e={...this._config,strict:!1,passthrough:!1};return delete e.catchall,new VldObject(e)}partial(){const e={};for(const t in this._config.shape)e[t]=new s(this._config.shape[t]);return new VldObject({...this._config,shape:e})}deepPartial(){const e={};for(const t in this._config.shape){const i=this._config.shape[t];e[t]=new s(i instanceof VldObject?i.deepPartial():i)}return new VldObject({...this._config,shape:e})}exactPartial(){const e={};for(const t in this._config.shape)e[t]=new i(this._config.shape[t]);return new VldObject({...this._config,shape:e})}pick(...e){const t={};let s=[];s=1!==e.length||"object"!=typeof e[0]||null===e[0]||Array.isArray(e[0])?e.flat():Object.keys(e[0]).filter(t=>e[0][t]);for(const e of s)e in this._config.shape&&(t[e]=this._config.shape[e]);return new VldObject({...this._config,shape:t})}omit(...e){let t;t=1!==e.length||"object"!=typeof e[0]||null===e[0]||Array.isArray(e[0])?new Set(e.flat()):new Set(Object.keys(e[0]).filter(t=>e[0][t]));const s={};for(const e in this._config.shape)t.has(e)||(s[e]=this._config.shape[e]);return new VldObject({...this._config,shape:s})}extend(e){return new VldObject({...this._config,shape:{...this._config.shape,...e}})}merge(e){return new VldObject({...this._config,shape:{...this._config.shape,...e.config.shape}})}required(){const e={};for(const t in this._config.shape){const i=this._config.shape[t];if(i instanceof s){const s=i.baseValidator;if(!s||"function"!=typeof s.parse)throw new Error(`Invalid VldOptional structure for field "${t}": missing or invalid baseValidator`);e[t]=s}else e[t]=i}return new VldObject({...this._config,shape:e})}catchall(e){return new VldObject({...this._config,catchall:e,passthrough:!1})}get shape(){return this._config.shape}keyof(){const e=Object.keys(this._config.shape);if(0===e.length)throw new Error("Cannot create keyof enum from empty object");return n.create(e)}safeExtend(e){const t=new Set(Object.keys(this._config.shape)),s=Object.keys(e),i=[];for(const e of s)t.has(e)&&i.push(e);if(i.length>0)throw new Error(`safeExtend: ${r().safeExtendOverlap(i)}`);return new VldObject({...this._config,shape:{...this._config.shape,...e}})}}export{VldObject};
|
|
@@ -28,6 +28,7 @@ declare function stringRegex(options?: {
|
|
|
28
28
|
declare function macRegex(delimiter?: string): RegExp;
|
|
29
29
|
type StaticRegexName = 'base64' | 'base64url' | 'bigint' | 'boolean' | 'browserEmail' | 'cidrv4' | 'cidrv6' | 'creditCard' | 'cuid' | 'cuid2' | 'date' | 'domain' | 'duration' | 'e164' | 'email' | 'extendedDuration' | 'guid' | 'hex' | 'hostname' | 'html5Email' | 'httpProtocol' | 'httpUrl' | 'idnEmail' | 'integer' | 'ipv4' | 'ipv6' | 'jwt' | 'ksuid' | 'lowercase' | 'md5' | 'md5_base64' | 'md5_base64url' | 'md5_hex' | 'nanoid' | 'null' | 'number' | 'rfc5322Email' | 'sha1' | 'sha1_base64' | 'sha1_base64url' | 'sha1_hex' | 'sha256' | 'sha256_base64' | 'sha256_base64url' | 'sha256_hex' | 'sha384' | 'sha384_base64' | 'sha384_base64url' | 'sha384_hex' | 'sha512' | 'sha512_base64' | 'sha512_base64url' | 'sha512_hex' | 'ulid' | 'undefined' | 'unicodeEmail' | 'uppercase' | 'uuid4' | 'uuid6' | 'uuid7' | 'xid';
|
|
30
30
|
export type RegexNamespace = Readonly<Record<StaticRegexName, RegExp> & {
|
|
31
|
+
nanoidOfLength: (length: number) => RegExp;
|
|
31
32
|
datetime: typeof dateTimeRegex;
|
|
32
33
|
emoji: () => RegExp;
|
|
33
34
|
mac: typeof macRegex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{VldBase as t,VLD_VALIDATOR_TYPES as a}from"./base.js";import{getMessages as
|
|
1
|
+
import{VldBase as t,VLD_VALIDATOR_TYPES as a}from"./base.js";import{getMessages as e}from"../locales/runtime.js";import{i as r}from"../chunks/ip-validation-g5LWgy9t.js";import{V as i,c as n,g as d}from"../chunks/errors-core-CerMg2rq.js";const o="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))";function s(t,a){return t.lastIndex=0,t.test(a)}function c(t,a){return new RegExp(`^[A-Za-z0-9+/]{${t}}${a}$`)}function u(t){return new RegExp(`^[A-Za-z0-9_-]{${t}}$`)}function f(t){const a="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"!=typeof t.precision?`${a}(?::[0-5]\\d(?:\\.\\d+)?)?`:-1===t.precision?a:0===t.precision?`${a}:[0-5]\\d`:`${a}:[0-5]\\d\\.\\d{${t.precision}}`}function m(t){return void 0===t?/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/:new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`)}const l={cuid:/^[cC][0-9a-z]{6,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,xid:/^[0-9a-vA-V]{20}$/,ksuid:/^[A-Za-z0-9]{27}$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,nanoidOfLength:t=>new RegExp(`^[a-zA-Z0-9_-]{${t}}$`),duration:/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,extendedDuration:/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,guid:/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,creditCard:/^\d(?:[ -]?\d){11,18}$/,uuid:m,uuid4:m(4),uuid6:m(6),uuid7:m(7),email:/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+.-]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9-]*\.)+[A-Za-z]{2,}$/,html5Email:/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,rfc5322Email:/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}))$/,unicodeEmail:/^[^\s@"]{1,64}@[^\s@]{1,255}$/u,idnEmail:/^[^\s@"]{1,64}@[^\s@]{1,255}$/u,browserEmail:/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,emoji:()=>/^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv6:/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,mac:function(t=":"){const a=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^(?:[0-9A-F]{2}${a}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${a}){5}[0-9a-f]{2}$`)},cidrv4:/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,cidrv6:/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,base64url:/^[A-Za-z0-9_-]*$/,hostname:/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,domain:/^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/,httpProtocol:/^https?$/,e164:/^\+[1-9]\d{6,14}$/,date:new RegExp(`^${o}$`),time:function(t={}){return new RegExp(`^${f(t)}$`)},datetime:function(t={}){const a=["Z"];return t.local&&a.push(""),t.offset&&a.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)"),new RegExp(`^${o}T${f(t)}(?:${a.join("|")})$`)},string:function(t){const a=t?`[\\s\\S]{${t.minimum??0},${t.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${a}$`)},bigint:/^-?\d+n?$/,integer:/^-?\d+$/,number:/^-?\d+(?:\.\d+)?$/,boolean:/^(?:true|false)$/i,null:/^null$/i,undefined:/^undefined$/i,lowercase:/^[^A-Z]*$/,uppercase:/^[^a-z]*$/,hex:/^[0-9a-fA-F]*$/,md5_hex:/^[0-9a-fA-F]{32}$/,md5_base64:c(22,"=="),md5_base64url:u(22),sha1_hex:/^[0-9a-fA-F]{40}$/,sha1_base64:c(27,"="),sha1_base64url:u(27),sha256_hex:/^[0-9a-fA-F]{64}$/,sha256_base64:c(43,"="),sha256_base64url:u(43),sha384_hex:/^[0-9a-fA-F]{96}$/,sha384_base64:c(64,""),sha384_base64url:u(64),sha512_hex:/^[0-9a-fA-F]{128}$/,sha512_base64:c(86,"=="),sha512_base64url:u(86),jwt:/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/,httpUrl:/^https?:\/\/[^\s/$.?#].[^\s]*$/,md5:/^[a-f0-9]{32}$/i,sha1:/^[a-f0-9]{40}$/i,sha256:/^[a-f0-9]{64}$/i,sha384:/^[a-f0-9]{96}$/i,sha512:/^[a-f0-9]{128}$/i};class VldStringFormat extends t{constructor(t,e,r,i=t=>t,n){super(a.STRING_FORMAT),this._format=t,this._validator=e,this._errorMessage=r,this._normalize=i,this._patternSource=n}static create(t,a,e,r,i){return new VldStringFormat(t,a,e,r,i)}_createFormatIssue(){const t={code:"invalid_format",path:[],origin:"string",format:this._format,message:this._errorMessage||`Invalid ${this._format}`};return this._patternSource&&(t.pattern=this._patternSource),new i([t])}parse(t){if("string"!=typeof t)throw new i([n("string",d(t),e().invalidString)]);if(!this._validator(t))throw this._createFormatIssue();return this._normalize(t)}safeParse(t){return"string"!=typeof t?{success:!1,error:new i([n("string",d(t),e().invalidString)])}:this._validator(t)?{success:!0,data:this._normalize(t)}:{success:!1,error:this._createFormatIssue()}}}const $=t=>{const a=t?.pattern??l.email;return VldStringFormat.create("email",t=>s(a,t),void 0,void 0,a.source)},A=(t={})=>VldStringFormat.create("url",a=>{const e=(t=>{try{return new URL(t)}catch{return}})(a);return void 0!==e&&(!t.hostname||s(t.hostname,e.hostname))&&(!t.protocol||s(t.protocol,e.protocol.slice(0,-1)))},void 0,t.normalize?t=>new URL(t).href:void 0),F=t=>{const a=m(void 0===t?.version?void 0:Number(t.version.slice(1)));return VldStringFormat.create("uuid",t=>s(a,t))},g=()=>VldStringFormat.create("uuid",t=>s(l.uuid4,t)),h=()=>VldStringFormat.create("uuid",t=>s(l.uuid6,t)),p=()=>VldStringFormat.create("uuid",t=>s(l.uuid7,t)),S=()=>VldStringFormat.create("hostname",t=>s(l.hostname,t)),z=()=>VldStringFormat.create("emoji",t=>s(l.emoji(),t)),Z=()=>VldStringFormat.create("base64",t=>s(l.base64,t)),_=()=>VldStringFormat.create("base64url",t=>s(l.base64url,t)),V=()=>VldStringFormat.create("hex",t=>s(l.hex,t)),v=()=>VldStringFormat.create("jwt",t=>s(l.jwt,t)),x=()=>VldStringFormat.create("nanoid",t=>s(l.nanoid,t)),b=()=>VldStringFormat.create("cuid",t=>s(l.cuid,t)),w=()=>VldStringFormat.create("cuid2",t=>s(l.cuid2,t)),E=()=>VldStringFormat.create("ulid",t=>s(l.ulid,t)),R=()=>VldStringFormat.create("ipv4",t=>s(l.ipv4,t)),j=()=>VldStringFormat.create("ipv6",t=>s(l.ipv6,t)),I=t=>{const a=l.mac(t?.delimiter);return VldStringFormat.create("mac",t=>s(a,t))},M=()=>VldStringFormat.create("cidrv4",t=>s(l.cidrv4,t)),T=()=>VldStringFormat.create("cidrv6",t=>{const a=t.lastIndexOf("/");if(a<=0)return!1;const e=Number(t.slice(a+1));return Number.isInteger(e)&&e>=0&&e<=128&&r(t.slice(0,a))}),D=()=>VldStringFormat.create("e164",t=>s(l.e164,t)),O=()=>VldStringFormat.create("xid",t=>s(l.xid,t)),k=()=>VldStringFormat.create("guid",t=>s(l.guid,t)),C=()=>VldStringFormat.create("httpUrl",t=>s(l.httpUrl,t)),P=()=>VldStringFormat.create("ksuid",t=>s(l.ksuid,t)),N=t=>VldStringFormat.create("hash",a=>l[t]?.test(a)??!1,`Invalid ${t} hash`),U=/[ -]/g;function y(t){return!!l.creditCard.test(t)&&function(t){let a=0,e=!1;for(let r=t.length-1;r>=0;r--){let i=t.charCodeAt(r)-48;e&&(i*=2,i>9&&(i-=9)),a+=i,e=!e}return a%10==0}(t.replace(U,""))}const H=t=>VldStringFormat.create("credit_card",y,t?.message,void 0,l.creditCard.source),W={ZodISODate:VldStringFormat,ZodISODateTime:VldStringFormat,ZodISODuration:VldStringFormat,ZodISOTime:VldStringFormat,date:()=>VldStringFormat.create("date",t=>s(l.date,t)),time:(t={})=>{const a=l.time(t);return VldStringFormat.create("time",t=>s(a,t))},datetime:(t={})=>{const a=l.datetime(t);return VldStringFormat.create("datetime",t=>s(a,t))},dateTime:(t={local:!0})=>{const a=l.datetime(t);return VldStringFormat.create("datetime",t=>s(a,t))},duration:()=>VldStringFormat.create("duration",t=>s(l.duration,t))},L=(t,a)=>{const e=a instanceof RegExp?t=>s(a,t):a;return VldStringFormat.create(t,e)};export{VldStringFormat,Z as base64,_ as base64url,M as cidrv4,T as cidrv6,H as creditCard,b as cuid,w as cuid2,D as e164,$ as email,z as emoji,k as guid,N as hash,V as hex,S as hostname,C as httpUrl,R as ipv4,j as ipv6,y as isValidCreditCard,W as iso,v as jwt,P as ksuid,I as mac,x as nanoid,l as regexes,L as stringFormat,E as ulid,A as url,F as uuid,g as uuidv4,h as uuidv6,p as uuidv7,O as xid};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxog/vld",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Ultra-fast TypeScript-first schema validation with zero dependencies, 27+ language support, plugin system, and CLI tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.cjs",
|
|
@@ -90,6 +90,11 @@
|
|
|
90
90
|
"import": "./dist/locales/*.js",
|
|
91
91
|
"require": "./dist/cjs/locales/*.cjs"
|
|
92
92
|
},
|
|
93
|
+
"./compile": {
|
|
94
|
+
"types": "./dist/compile.d.ts",
|
|
95
|
+
"import": "./dist/compile.js",
|
|
96
|
+
"require": "./dist/cjs/compile.cjs"
|
|
97
|
+
},
|
|
93
98
|
"./locales/lazy": {
|
|
94
99
|
"types": "./dist/locales/lazy.d.ts",
|
|
95
100
|
"import": "./dist/locales/lazy.js",
|
|
@@ -230,7 +235,7 @@
|
|
|
230
235
|
"ts-jest": "^29.4.11",
|
|
231
236
|
"tslib": "^2.8.1",
|
|
232
237
|
"typescript": "^5.3.3",
|
|
233
|
-
"zod": "^4.4
|
|
238
|
+
"zod": "^4.5.4"
|
|
234
239
|
},
|
|
235
240
|
"overrides": {
|
|
236
241
|
"@babel/core": "^7.29.7",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{registerLocale as o,registerFallbackLocale as s,setLocale as r,getLocale as l,getMessages as e,getMessagesForLocale as t,getSupportedLocales as m,isLocaleLoaded as a,isLocaleSupported as i}from"../locales/runtime.js";import{en as c}from"../locales/en.js";import{tr as f}from"../locales/tr.js";import{es as p}from"../locales/es.js";import{fr as j}from"../locales/fr.js";import{de as n}from"../locales/de.js";import{it as d}from"../locales/it.js";import{pt as h}from"../locales/pt.js";import{ru as u}from"../locales/ru.js";import{ja as g}from"../locales/ja.js";import{ko as k}from"../locales/ko.js";import{zh as v}from"../locales/zh.js";import{ar as L}from"../locales/ar.js";import{hi as y}from"../locales/hi.js";import{nl as z}from"../locales/nl.js";import{pl as b}from"../locales/pl.js";import{da as M}from"../locales/da.js";import{sv as R}from"../locales/sv.js";import{no as _}from"../locales/no.js";import{fi as w}from"../locales/fi.js";import{th as A}from"../locales/th.js";import{vi as B}from"../locales/vi.js";import{id as X}from"../locales/id.js";import{bn as q}from"../locales/bn.js";import{sw as x}from"../locales/sw.js";import{af as S}from"../locales/af.js";import{ptBR as C}from"../locales/pt-BR.js";import{esMX as F}from"../locales/es-MX.js";const O=["en","tr","es","fr","de","it","pt","ru","ja","ko","zh","ar","hi","nl","pl","da","sv","no","fi","th","vi","id","bn","sw","af","pt-BR","es-MX"],D=["is","cs","sk","hu","ro","bg","hr","sl","lv","lt","et","el","mk","sq","sr","bs","me","mt","ga","cy","eu","ca","ms","tl","ur","fa","he","ka","am","hy","az","kk","ky","uz","tg","mn","my","km","lo","si","ta","te","ml","kn","gu","pa","or","as","ne","mr","sd","dv","ha","yo","ig","zu","xh","st","tn","ts","ve","nr","ss","es-AR","fr-CA","qu","gn","ay"],E={en:c,tr:f,es:p,fr:j,de:n,it:d,pt:h,ru:u,ja:g,ko:k,zh:v,ar:L,hi:y,nl:z,pl:b,da:M,sv:R,no:_,fi:w,th:A,vi:B,id:X,bn:q,sw:x,af:S,"pt-BR":C,"es-MX":F};for(const s of O)o(s,E[s]);for(const o of D)s(o);async function G(o){r(o)}var H=Object.freeze({__proto__:null,getLocale:l,getMessages:e,getMessagesForLocale:t,getSupportedLocales:m,isLocaleLoaded:a,isLocaleSupported:i,registerLocale:o,setLocale:r,setLocaleAsync:G});export{H as l,G as s};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("../locales/runtime.cjs"),s=require("../locales/en.cjs"),r=require("../locales/tr.cjs"),l=require("../locales/es.cjs"),c=require("../locales/fr.cjs"),a=require("../locales/de.cjs"),o=require("../locales/it.cjs"),i=require("../locales/pt.cjs"),t=require("../locales/ru.cjs"),u=require("../locales/ja.cjs"),j=require("../locales/ko.cjs"),n=require("../locales/zh.cjs"),q=require("../locales/ar.cjs"),p=require("../locales/hi.cjs"),d=require("../locales/nl.cjs"),g=require("../locales/pl.cjs"),L=require("../locales/da.cjs"),f=require("../locales/sv.cjs"),h=require("../locales/no.cjs"),k=require("../locales/fi.cjs"),v=require("../locales/th.cjs"),m=require("../locales/vi.cjs"),y=require("../locales/id.cjs"),b=require("../locales/bn.cjs"),z=require("../locales/sw.cjs"),M=require("../locales/af.cjs"),R=require("../locales/pt-BR.cjs"),w=require("../locales/es-MX.cjs");const A=["en","tr","es","fr","de","it","pt","ru","ja","ko","zh","ar","hi","nl","pl","da","sv","no","fi","th","vi","id","bn","sw","af","pt-BR","es-MX"],B=["is","cs","sk","hu","ro","bg","hr","sl","lv","lt","et","el","mk","sq","sr","bs","me","mt","ga","cy","eu","ca","ms","tl","ur","fa","he","ka","am","hy","az","kk","ky","uz","tg","mn","my","km","lo","si","ta","te","ml","kn","gu","pa","or","as","ne","mr","sd","dv","ha","yo","ig","zu","xh","st","tn","ts","ve","nr","ss","es-AR","fr-CA","qu","gn","ay"],S={en:s.en,tr:r.tr,es:l.es,fr:c.fr,de:a.de,it:o.it,pt:i.pt,ru:t.ru,ja:u.ja,ko:j.ko,zh:n.zh,ar:q.ar,hi:p.hi,nl:d.nl,pl:g.pl,da:L.da,sv:f.sv,no:h.no,fi:k.fi,th:v.th,vi:m.vi,id:y.id,bn:b.bn,sw:z.sw,af:M.af,"pt-BR":R.ptBR,"es-MX":w.esMX};for(const s of A)e.registerLocale(s,S[s]);for(const s of B)e.registerFallbackLocale(s);async function X(s){e.setLocale(s)}var _=Object.freeze({__proto__:null,getLocale:e.getLocale,getMessages:e.getMessages,getMessagesForLocale:e.getMessagesForLocale,getSupportedLocales:e.getSupportedLocales,isLocaleLoaded:e.isLocaleLoaded,isLocaleSupported:e.isLocaleSupported,registerLocale:e.registerLocale,setLocale:e.setLocale,setLocaleAsync:X});exports.localeNamespace=_,exports.setLocaleAsync=X;
|