@esmj/schema 0.6.0 → 0.7.1

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 CHANGED
@@ -426,6 +426,7 @@ const schema = s.object({
426
426
  - `s.date()` - Date validation
427
427
  - `s.object(def)` - Object validation
428
428
  - `s.array(def)` - Array validation
429
+ - `s.literal(value)` - Literal value validation
429
430
  - `s.enum(values)` - Enum validation
430
431
  - `s.union(schemas)` - Union validation
431
432
  - `s.any()` - Any type
@@ -439,6 +440,7 @@ const schema = s.object({
439
440
  - `.nullable()` - Makes field nullable
440
441
  - `.nullish()` - Makes field optional and nullable
441
442
  - `.default(value)` - Sets default value
443
+ - `.catch(value)` - Returns fallback value on any parse failure
442
444
 
443
445
  ### Transformations
444
446
 
@@ -629,6 +631,65 @@ const enumSchemaFunc = s.enum(['admin', 'user', 'guest'], {
629
631
  });
630
632
  ```
631
633
 
634
+ #### `s.literal(value, options?)`
635
+
636
+ Creates a literal schema that validates against an exact value. The value can be a string, number, or boolean. This is useful for discriminated unions, API response types, and strict value validation. You can optionally pass `options` to customize error messages.
637
+
638
+ - **`message`**: Can be either a constant string or a function `(value) => string`.
639
+
640
+ ```typescript
641
+ // String literal
642
+ const adminSchema = s.literal('admin');
643
+ adminSchema.parse('admin'); // ✅ 'admin'
644
+ adminSchema.parse('user'); // ❌ throws error
645
+
646
+ // Number literal
647
+ const statusCode = s.literal(200);
648
+ statusCode.parse(200); // ✅ 200
649
+ statusCode.parse(404); // ❌ throws error
650
+
651
+ // Boolean literal
652
+ const enabled = s.literal(true);
653
+ enabled.parse(true); // ✅ true
654
+ enabled.parse(false); // ❌ throws error
655
+
656
+ // Custom error message
657
+ const typeSchema = s.literal('success', {
658
+ message: 'Response type must be "success"',
659
+ });
660
+
661
+ // Custom error function
662
+ const versionSchema = s.literal(1, {
663
+ message: (value) => `API version must be 1, received ${value}`,
664
+ });
665
+
666
+ // Discriminated unions with literal
667
+ const responseSchema = s.union([
668
+ s.object({
669
+ type: s.literal('success'),
670
+ data: s.string(),
671
+ }),
672
+ s.object({
673
+ type: s.literal('error'),
674
+ error: s.string(),
675
+ }),
676
+ ]);
677
+
678
+ // Using multiple literals in union (similar to enum but with type inference)
679
+ const roleSchema = s.union([
680
+ s.literal('admin'),
681
+ s.literal('user'),
682
+ s.literal('guest'),
683
+ ]);
684
+ ```
685
+
686
+ **Common Use Cases:**
687
+
688
+ - **Discriminated Unions**: Use literal types to distinguish between different object shapes
689
+ - **API Response Types**: Validate exact status codes or response types
690
+ - **Configuration Flags**: Validate boolean flags or specific string values
691
+ - **Type Guards**: Create strict type validation for specific values
692
+
632
693
  #### `s.union(definitions, options?)`
633
694
 
634
695
  Creates a schema that validates against multiple schemas (a union of schemas). The value must match at least one of the provided schemas. You can optionally pass `options` to customize error messages.
@@ -740,6 +801,35 @@ Sets a default value for the schema.
740
801
  const defaultSchema = stringSchema.default('default value');
741
802
  ```
742
803
 
804
+ #### `catch(catchValue)`
805
+
806
+ Returns a fallback value whenever parsing fails, instead of throwing or returning an error.
807
+ Unlike `default()` which only fires when the input is `undefined`, `catch()` fires on **any** validation failure.
808
+
809
+ The fallback can be a static value or a function that receives a context object `{ input, error }`:
810
+ - `input` — the original raw input value
811
+ - `error` — the `ErrorStructure` with the failure message
812
+
813
+ **Note:** The fallback value is returned as-is without re-validation. `catch()` only intercepts failures from schemas and refinements placed **before** it in the chain.
814
+
815
+ ```typescript
816
+ // Static fallback
817
+ const schema = s.string().catch('unknown');
818
+ schema.parse(123); // 'unknown'
819
+ schema.parse('hello'); // 'hello'
820
+
821
+ // Function fallback with context
822
+ const schema2 = s.number().catch((ctx) => {
823
+ console.warn(`Invalid input: ${ctx.input} — ${ctx.error.message}`);
824
+ return 0;
825
+ });
826
+ schema2.parse('bad'); // 0
827
+
828
+ // Distinction from default()
829
+ s.string().catch('fallback').parse(null); // 'fallback' — catch fires for null
830
+ s.string().default('fallback').parse(null); // throws — default does not fire for null
831
+ ```
832
+
743
833
  #### `transform(callback)`
744
834
 
745
835
  Transforms the parsed value using the provided callback.
@@ -1139,7 +1229,7 @@ console.log(result);
1139
1229
 
1140
1230
  ## Examples Folder
1141
1231
 
1142
- The `examples/` folder contains comprehensive, runnable examples demonstrating various use cases:
1232
+ The `examples/` folder contains comprehensive, runnable examples demonstrating various use cases. See the [examples README](examples/README.md) for detailed documentation.
1143
1233
 
1144
1234
  ### Basic Usage (`examples/basic-usage.ts`)
1145
1235
 
@@ -1187,6 +1277,22 @@ Demonstrates how to extend the library with custom methods:
1187
1277
  node --experimental-strip-types examples/custom-extensions.ts
1188
1278
  ```
1189
1279
 
1280
+ ### Registration Form (`examples/registration-form.ts`)
1281
+
1282
+ Complete user registration form validation with email and phone number validation:
1283
+ - Username validation with pattern matching
1284
+ - Email validation using custom extension
1285
+ - International phone number validation
1286
+ - Password strength requirements
1287
+ - Password confirmation matching
1288
+ - Age verification (18+)
1289
+ - Terms acceptance validation
1290
+ - Error collection with `abortEarly: false`
1291
+
1292
+ ```bash
1293
+ node --experimental-strip-types examples/registration-form.ts
1294
+ ```
1295
+
1190
1296
  **To run all examples:**
1191
1297
 
1192
1298
  ```bash
@@ -1195,6 +1301,17 @@ node --experimental-strip-types examples/basic-usage.ts
1195
1301
  node --experimental-strip-types examples/custom-validation.ts
1196
1302
  node --experimental-strip-types examples/advanced-forms.ts
1197
1303
  node --experimental-strip-types examples/custom-extensions.ts
1304
+ node --experimental-strip-types examples/registration-form.ts
1305
+
1306
+ # OR using npm scripts from examples folder
1307
+ cd examples
1308
+ npm install
1309
+ npm run basic
1310
+ npm run custom
1311
+ npm run advanced
1312
+ npm run extensions
1313
+ npm run registration
1314
+ npm run all # Run all examples
1198
1315
 
1199
1316
  # OR using tsx (requires installation)
1200
1317
  npm install -g tsx # If not already installed
@@ -1202,6 +1319,7 @@ npx tsx examples/basic-usage.ts
1202
1319
  npx tsx examples/custom-validation.ts
1203
1320
  npx tsx examples/advanced-forms.ts
1204
1321
  npx tsx examples/custom-extensions.ts
1322
+ npx tsx examples/registration-form.ts
1205
1323
  ```
1206
1324
  ## Migration Guide
1207
1325
 
@@ -1300,4 +1418,3 @@ const userSchema = s.object({
1300
1418
  ## License
1301
1419
 
1302
1420
  MIT
1303
-
package/dist/array.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var P={abortEarly:true};function l(e,o){if(!o)return e;let i=e?.cause?.key?`${o}.${e.cause.key}`:`${o}`;return {message:`Error parsing key "${i}": ${e.message}`,cause:{key:i}}}function g(e,o,i){!e.errors||e.errors.length===0||e.errors.forEach(u=>{let c=l(u,i);o.push(c);});}function S(e){return {...P,...e}}var k=e=>typeof e=="string"||e instanceof String,A=e=>typeof e=="number"||e instanceof Number,w=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),O=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),R={object(e,o){let i=y(O,{...o,type:"object"});return i._getDescription=()=>`object({ ${Object.entries(e).map(([c,s])=>`${c}: ${s._getDescription()}`).join(", ")} })`,h(i,"_parse",(u,c,s)=>{let t=u(c,s),{abortEarly:r}=S(s);if(t.success===false)return t;let n={},a=[];for(let p in e){let f=e[p]._parse(t.data[p],s);if(f.success)n[p]=f.data;else {if(f=f,r!==false){let m=l(f.error,p);return {success:false,error:m,errors:[m]}}g(f,a,p);}}return a.length>0?{success:false,error:a[0],errors:a}:{success:true,data:n}}),i},string(e){return y(k,{...e,type:"string"})},number(e){return y(A,{...e,type:"number"})},boolean(e){return y(w,{...e,type:"boolean"})},date(e){return y(E,{...e,type:"date"})},enum(e,o){let i=t=>e.includes(t),u=t=>`Invalid ${c} value. Expected ${e.map(r=>`"${r}"`).join(" | ")}, received "${t}".`,c="enum",s=y(i,{message:u,...o,type:c});return s._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,s},array(e,o){let i=y(_,{...o,type:"array"});return i._getDescription=()=>`array(${e._getDescription()})`,h(i,"_parse",(u,c,s)=>{let t=u(c,s),{abortEarly:r}=S(s);if(t.success===false)return t;let n=[],a=[];for(let p=0;p<t.data.length;p++){let f=e._parse(t.data[p],s);if(f.success)n.push(f.data);else {if(f=f,r!==false){let m=l(f.error,p);return {success:false,error:m,errors:[m]}}g(f,a,p);}}return a.length>0?{success:false,error:a[0],errors:a}:{success:true,data:n}}),i},any(){return y(()=>true)},preprocess(e,o){return h(o,"_parse",(i,u)=>(u=e(u),i(u))),o},union(e,o){return y(s=>{for(let t=0;t<e.length;t++){let r=e[t]._parse(s);if(r.success)return r}return false},{message:s=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,r)=>` ${r+1}. ${t._getDescription()}`).join(",")} but received "${typeof s}" with value: ${O(s)?JSON.stringify(s):`"${s}"`}`,...o,type:"union"})}};function b(e){return o=>`The value "${o}" must be type of ${e} but is type of "${typeof o}".`}function h(e,o,i){let u=e[o];e[o]=(...c)=>i(u,...c);}function y(e,{type:o="any",name:i,message:u}={}){u=u||b(o);let c={name:i,message:u,type:o},s={_getName(){return i},_getType(){return o},_getDescription(){return this._getName()??this._getType()},_parse(t,r){let n=e(t);if(n===true)return {success:true,data:t};if(typeof n=="object"&&n?.success===true)return n;let a={message:typeof u=="function"?u(t):u};return {success:false,error:a,errors:[a]}},parse(t,r){let n=s._parse(t,r);if(!n.success)throw n=n,new Error(n.error.message,{cause:n.error.cause});return n.data},safeParse(t,r){return s._parse(t,r)},transform(t){return h(this,"_parse",(r,n,a)=>{let p=r(n,a);return p.success&&(p.data=t(p.data)),p}),this},optional(){return h(this,"_parse",(t,r,n)=>{let a=t(r,n);return !a.success&&r===void 0&&(a.data=void 0,a.success=true),a}),this},nullable(){return h(this,"_parse",(t,r,n)=>{let a=t(r,n);return !a.success&&r===null&&(a.data=null,a.success=true),a}),this},nullish(){return h(this,"_parse",(t,r,n)=>{let a=t(r,n);return !a.success&&r==null&&(a.success=true,a.data=r),a}),this},default(t){return h(this,"_parse",(r,n,a)=>(n===void 0&&(n=t,n=typeof t=="function"?t():t),r(n,a))),this},pipe(t){return h(this,"_parse",(r,n,a)=>{let p=r(n,a);return p.success?t._parse(p.data,a):p}),this},refine(t,{message:r,type:n}={}){return n&&(r=r||b(n),o=n),h(this,"_parse",(a,p,f)=>{let m=a(p,f);S(f);if(!m.success)return m;let I=t(m.data);if(I===true||typeof I=="object"&&I?.success===true)return m;let T={message:typeof r=="function"?r(p):r};return {success:false,error:T,errors:[T]}}),this}};return d.length>0?d.reduce((t,r)=>r(t,e,c)??t,s):s}var d=[];function x(e){d.push(e);}x((e,o,i)=>{if(i?.type==="array"){let u=e;u.min=function(c,{message:s}={}){return this.refine(t=>t.length>=c,{message:s||`Array must contain at least ${c} items.`})},u.max=function(c,{message:s}={}){return this.refine(t=>t.length<=c,{message:s||`Array must contain at most ${c} items.`})},u.length=function(c,{message:s}={}){return this.refine(t=>t.length===c,{message:s||`Array must contain exactly ${c} items.`})},u.nonEmpty=function({message:c}={}){return this.refine(s=>s.length>0,{message:c||"Array must not be empty."})},u.unique=function({message:c}={}){return this.refine(s=>{let t=new Set;try{return s.every(r=>{let n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}catch{return new Set(s).size===s.length}},{message:c||"Array items must be unique."})},u.sort=function(){return this.transform(c=>[...c].sort())},u.reverse=function(){return this.transform(c=>[...c].reverse())};}return e});exports.extend=x;exports.hookOriginal=h;exports.s=R;
1
+ 'use strict';var k={abortEarly:true};function y(e,c){if(!c)return e;let p=e?.cause?.key?`${c}.${e.cause.key}`:`${c}`;return {message:`Error parsing key "${p}": ${e.message}`,cause:{key:p}}}function T(e,c,p){if(e.errors?.length)for(let u=0;u<e.errors.length;u++)c.push(y(e.errors[u],p));}function S(e){return {...k,...e}}var w=e=>typeof e=="string"||e instanceof String,P=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),A=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),O=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),R={object(e,c){let p=l(O,{...c,type:"object"});return p._getDescription=()=>`object({ ${Object.entries(e).map(([o,r])=>`${o}: ${r._getDescription()}`).join(", ")} })`,m(p,"_parse",(u,o,r)=>{let t=u(o,r),{abortEarly:n}=S(r);if(t.success===false)return t;let a={},s=[];for(let i in e){let f=e[i]._parse(t.data[i],r);if(f.success)a[i]=f.data;else {if(f=f,n!==false){let h=y(f.error,i);return {success:false,error:h,errors:[h]}}T(f,s,i);}}return s.length>0?{success:false,error:s[0],errors:s}:{success:true,data:a}}),p},string(e){return l(w,{...e,type:"string"})},number(e){return l(P,{...e,type:"number"})},boolean(e){return l(A,{...e,type:"boolean"})},date(e){return l(E,{...e,type:"date"})},enum(e,c){let p=t=>e.includes(t),u=t=>`Invalid ${o} value. Expected ${e.map(n=>`"${n}"`).join(" | ")}, received "${t}".`,o="enum",r=l(p,{message:u,...c,type:o});return r._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,r},array(e,c){let p=l(_,{...c,type:"array"});return p._getDescription=()=>`array(${e._getDescription()})`,m(p,"_parse",(u,o,r)=>{let t=u(o,r),{abortEarly:n}=S(r);if(t.success===false)return t;let a=[],s=[];for(let i=0;i<t.data.length;i++){let f=e._parse(t.data[i],r);if(f.success)a.push(f.data);else {if(f=f,n!==false){let h=y(f.error,i);return {success:false,error:h,errors:[h]}}T(f,s,i);}}return s.length>0?{success:false,error:s[0],errors:s}:{success:true,data:a}}),p},any(){return l(()=>true)},preprocess(e,c){return m(c,"_parse",(p,u)=>(u=e(u),p(u))),c},union(e,c){return l(r=>{for(let t=0;t<e.length;t++){let n=e[t]._parse(r);if(n.success)return n}return false},{message:r=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,n)=>` ${n+1}. ${t._getDescription()}`).join(",")} but received "${typeof r}" with value: ${O(r)?JSON.stringify(r):`"${r}"`}`,...c,type:"union"})},literal(e,c){let o=l(r=>r===e,{message:r=>c?.message?typeof c.message=="function"?c.message(r):c.message:`Expected literal value "${e}", received "${r}"`,name:c?.name,type:"literal"});return o._getDescription=()=>`literal("${e}")`,o}};function b(e){return c=>`The value "${c}" must be type of ${e} but is type of "${typeof c}".`}function m(e,c,p){let u=e[c];e[c]=(...o)=>p(u,...o);}function l(e,{type:c="any",name:p,message:u}={}){u=u||b(c);let o={name:p,message:u,type:c},r={_getName(){return p},_getType(){return c},_getDescription(){return this._getName()??this._getType()},_parse(t,n){let a=e(t);if(a===true)return {success:true,data:t};if(typeof a=="object"&&a?.success===true)return a;let s={message:typeof u=="function"?u(t):u};return {success:false,error:s,errors:[s]}},parse(t,n){let a=r._parse(t,n);if(!a.success)throw a=a,new Error(a.error.message,{cause:a.error.cause});return a.data},safeParse(t,n){return r._parse(t,n)},transform(t){return m(this,"_parse",(n,a,s)=>{let i=n(a,s);return i.success&&(i.data=t(i.data)),i}),this},optional(){return m(this,"_parse",(t,n,a)=>{let s=t(n,a);return !s.success&&n===void 0&&(s.data=void 0,s.success=true),s}),this},nullable(){return m(this,"_parse",(t,n,a)=>{let s=t(n,a);return !s.success&&n===null&&(s.data=null,s.success=true),s}),this},nullish(){return m(this,"_parse",(t,n,a)=>{let s=t(n,a);return !s.success&&n==null&&(s.success=true,s.data=n),s}),this},default(t){return m(this,"_parse",(n,a,s)=>(a===void 0&&(a=typeof t=="function"?t():t),n(a,s))),this},catch(t){return m(this,"_parse",(n,a,s)=>{let i=n(a,s);return i.success?i:{success:true,data:typeof t=="function"?t({input:a,error:i.error}):t}}),this},pipe(t){return m(this,"_parse",(n,a,s)=>{let i=n(a,s);return i.success?t._parse(i.data,s):i}),this},refine(t,{message:n,type:a}={}){return a&&(n=n||b(a),c=a),m(this,"_parse",(s,i,f)=>{let h=s(i,f);S(f);if(!h.success)return h;let I=t(h.data);if(I===true||typeof I=="object"&&I?.success===true)return h;let g={message:typeof n=="function"?n(i):n};return {success:false,error:g,errors:[g]}}),this}};return d.length>0?d.reduce((t,n)=>n(t,e,o)??t,r):r}var d=[];function x(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");d.push(e);}x((e,c,p)=>{if(p?.type==="array"){let u=e;u.min=function(o,{message:r}={}){return this.refine(t=>t.length>=o,{message:r||`Array must contain at least ${o} items.`})},u.max=function(o,{message:r}={}){return this.refine(t=>t.length<=o,{message:r||`Array must contain at most ${o} items.`})},u.length=function(o,{message:r}={}){return this.refine(t=>t.length===o,{message:r||`Array must contain exactly ${o} items.`})},u.nonEmpty=function({message:o}={}){return this.refine(r=>r.length>0,{message:o||"Array must not be empty."})},u.unique=function({message:o}={}){return this.refine(r=>{let t=new Set;try{return r.every(n=>{let a=JSON.stringify(n);return t.has(a)?!1:(t.add(a),!0)})}catch{return new Set(r).size===r.length}},{message:o||"Array items must be unique."})},u.sort=function(){return this.transform(o=>[...o].sort())},u.reverse=function(){return this.transform(o=>[...o].reverse())};}return e});exports.extend=x;exports.hookOriginal=m;exports.s=R;
package/dist/array.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.mjs';
1
+ export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.mjs';
2
2
 
3
3
  declare module './index.ts' {
4
4
  interface ArraySchemaInterface<T extends SchemaType> {
package/dist/array.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.js';
1
+ export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.js';
2
2
 
3
3
  declare module './index.ts' {
4
4
  interface ArraySchemaInterface<T extends SchemaType> {
package/dist/array.mjs CHANGED
@@ -1 +1 @@
1
- import'./chunk-PHNKAD7Q.mjs';export{c as extend,b as hookOriginal,a as s}from'./chunk-NCHMO7B3.mjs';
1
+ import'./chunk-4JJPVRF6.mjs';export{c as extend,b as hookOriginal,a as s}from'./chunk-2NCXW7ID.mjs';
@@ -0,0 +1 @@
1
+ var k={abortEarly:true};function d(e,s){if(!s)return e;let i=e?.cause?.key?`${s}.${e.cause.key}`:`${s}`;return {message:`Error parsing key "${i}": ${e.message}`,cause:{key:i}}}function T(e,s,i){if(e.errors?.length)for(let o=0;o<e.errors.length;o++)s.push(d(e.errors[o],i));}function y(e){return {...k,...e}}var x=e=>typeof e=="string"||e instanceof String,w=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),P=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),b=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),$={object(e,s){let i=h(b,{...s,type:"object"});return i._getDescription=()=>`object({ ${Object.entries(e).map(([p,c])=>`${p}: ${c._getDescription()}`).join(", ")} })`,m(i,"_parse",(o,p,c)=>{let t=o(p,c),{abortEarly:n}=y(c);if(t.success===false)return t;let a={},r=[];for(let u in e){let f=e[u]._parse(t.data[u],c);if(f.success)a[u]=f.data;else {if(f=f,n!==false){let l=d(f.error,u);return {success:false,error:l,errors:[l]}}T(f,r,u);}}return r.length>0?{success:false,error:r[0],errors:r}:{success:true,data:a}}),i},string(e){return h(x,{...e,type:"string"})},number(e){return h(w,{...e,type:"number"})},boolean(e){return h(P,{...e,type:"boolean"})},date(e){return h(E,{...e,type:"date"})},enum(e,s){let i=t=>e.includes(t),o=t=>`Invalid ${p} value. Expected ${e.map(n=>`"${n}"`).join(" | ")}, received "${t}".`,p="enum",c=h(i,{message:o,...s,type:p});return c._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,c},array(e,s){let i=h(_,{...s,type:"array"});return i._getDescription=()=>`array(${e._getDescription()})`,m(i,"_parse",(o,p,c)=>{let t=o(p,c),{abortEarly:n}=y(c);if(t.success===false)return t;let a=[],r=[];for(let u=0;u<t.data.length;u++){let f=e._parse(t.data[u],c);if(f.success)a.push(f.data);else {if(f=f,n!==false){let l=d(f.error,u);return {success:false,error:l,errors:[l]}}T(f,r,u);}}return r.length>0?{success:false,error:r[0],errors:r}:{success:true,data:a}}),i},any(){return h(()=>true)},preprocess(e,s){return m(s,"_parse",(i,o)=>(o=e(o),i(o))),s},union(e,s){return h(c=>{for(let t=0;t<e.length;t++){let n=e[t]._parse(c);if(n.success)return n}return false},{message:c=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,n)=>` ${n+1}. ${t._getDescription()}`).join(",")} but received "${typeof c}" with value: ${b(c)?JSON.stringify(c):`"${c}"`}`,...s,type:"union"})},literal(e,s){let p=h(c=>c===e,{message:c=>s?.message?typeof s.message=="function"?s.message(c):s.message:`Expected literal value "${e}", received "${c}"`,name:s?.name,type:"literal"});return p._getDescription=()=>`literal("${e}")`,p}};function O(e){return s=>`The value "${s}" must be type of ${e} but is type of "${typeof s}".`}function m(e,s,i){let o=e[s];e[s]=(...p)=>i(o,...p);}function h(e,{type:s="any",name:i,message:o}={}){o=o||O(s);let p={name:i,message:o,type:s},c={_getName(){return i},_getType(){return s},_getDescription(){return this._getName()??this._getType()},_parse(t,n){let a=e(t);if(a===true)return {success:true,data:t};if(typeof a=="object"&&a?.success===true)return a;let r={message:typeof o=="function"?o(t):o};return {success:false,error:r,errors:[r]}},parse(t,n){let a=c._parse(t,n);if(!a.success)throw a=a,new Error(a.error.message,{cause:a.error.cause});return a.data},safeParse(t,n){return c._parse(t,n)},transform(t){return m(this,"_parse",(n,a,r)=>{let u=n(a,r);return u.success&&(u.data=t(u.data)),u}),this},optional(){return m(this,"_parse",(t,n,a)=>{let r=t(n,a);return !r.success&&n===void 0&&(r.data=void 0,r.success=true),r}),this},nullable(){return m(this,"_parse",(t,n,a)=>{let r=t(n,a);return !r.success&&n===null&&(r.data=null,r.success=true),r}),this},nullish(){return m(this,"_parse",(t,n,a)=>{let r=t(n,a);return !r.success&&n==null&&(r.success=true,r.data=n),r}),this},default(t){return m(this,"_parse",(n,a,r)=>(a===void 0&&(a=typeof t=="function"?t():t),n(a,r))),this},catch(t){return m(this,"_parse",(n,a,r)=>{let u=n(a,r);return u.success?u:{success:true,data:typeof t=="function"?t({input:a,error:u.error}):t}}),this},pipe(t){return m(this,"_parse",(n,a,r)=>{let u=n(a,r);return u.success?t._parse(u.data,r):u}),this},refine(t,{message:n,type:a}={}){return a&&(n=n||O(a),s=a),m(this,"_parse",(r,u,f)=>{let l=r(u,f);y(f);if(!l.success)return l;let I=t(l.data);if(I===true||typeof I=="object"&&I?.success===true)return l;let g={message:typeof n=="function"?n(u):n};return {success:false,error:g,errors:[g]}}),this}};return S.length>0?S.reduce((t,n)=>n(t,e,p)??t,c):c}var S=[];function A(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");S.push(e);}export{$ as a,m as b,A as c};
@@ -1 +1 @@
1
- import {c}from'./chunk-NCHMO7B3.mjs';c((a,o,m)=>{if(m?.type==="array"){let r=a;r.min=function(e,{message:t}={}){return this.refine(n=>n.length>=e,{message:t||`Array must contain at least ${e} items.`})},r.max=function(e,{message:t}={}){return this.refine(n=>n.length<=e,{message:t||`Array must contain at most ${e} items.`})},r.length=function(e,{message:t}={}){return this.refine(n=>n.length===e,{message:t||`Array must contain exactly ${e} items.`})},r.nonEmpty=function({message:e}={}){return this.refine(t=>t.length>0,{message:e||"Array must not be empty."})},r.unique=function({message:e}={}){return this.refine(t=>{let n=new Set;try{return t.every(c=>{let s=JSON.stringify(c);return n.has(s)?!1:(n.add(s),!0)})}catch{return new Set(t).size===t.length}},{message:e||"Array items must be unique."})},r.sort=function(){return this.transform(e=>[...e].sort())},r.reverse=function(){return this.transform(e=>[...e].reverse())};}return a});
1
+ import {c}from'./chunk-2NCXW7ID.mjs';c((a,o,m)=>{if(m?.type==="array"){let r=a;r.min=function(e,{message:t}={}){return this.refine(n=>n.length>=e,{message:t||`Array must contain at least ${e} items.`})},r.max=function(e,{message:t}={}){return this.refine(n=>n.length<=e,{message:t||`Array must contain at most ${e} items.`})},r.length=function(e,{message:t}={}){return this.refine(n=>n.length===e,{message:t||`Array must contain exactly ${e} items.`})},r.nonEmpty=function({message:e}={}){return this.refine(t=>t.length>0,{message:e||"Array must not be empty."})},r.unique=function({message:e}={}){return this.refine(t=>{let n=new Set;try{return t.every(c=>{let s=JSON.stringify(c);return n.has(s)?!1:(n.add(s),!0)})}catch{return new Set(t).size===t.length}},{message:e||"Array items must be unique."})},r.sort=function(){return this.transform(e=>[...e].sort())},r.reverse=function(){return this.transform(e=>[...e].reverse())};}return a});
@@ -1 +1 @@
1
- import {c}from'./chunk-NCHMO7B3.mjs';c((i,s,c)=>{if(c?.type==="string"){let r=i;r.min=function(t,{message:n}={}){return this.refine(e=>e.length>=t,{message:n||(e=>`String must be at least ${t} characters long (received ${e.length} characters: "${e}")`)})},r.max=function(t,{message:n}={}){return this.refine(e=>e.length<=t,{message:n||(e=>`String must be at most ${t} characters long (received ${e.length} characters: "${e}")`)})},r.length=function(t,{message:n}={}){return this.refine(e=>e.length===t,{message:n||(e=>`String must be exactly ${t} characters long (received ${e.length} characters: "${e}")`)})},r.nonEmpty=function({message:t}={}){return this.refine(n=>n.length>0,{message:t||"String must not be empty (received empty string)"})},r.startsWith=function(t,{message:n}={}){return this.refine(e=>e.startsWith(t),{message:n||(e=>`String must start with "${t}" (received: "${e}")`)})},r.endsWith=function(t,{message:n}={}){return this.refine(e=>e.endsWith(t),{message:n||(e=>`String must end with "${t}" (received: "${e}")`)})},r.includes=function(t,{message:n}={}){return this.refine(e=>e.includes(t),{message:n||(e=>`String must include "${t}" (received: "${e}")`)})},r.toLowerCase=function(){return this.transform(t=>t.toLowerCase())},r.toUpperCase=function(){return this.transform(t=>t.toUpperCase())},r.trim=function(){return this.transform(t=>t.trim())},r.padStart=function(t,n=" "){return this.transform(e=>e.padStart(t,n))},r.padEnd=function(t,n=" "){return this.transform(e=>e.padEnd(t,n))},r.replace=function(t,n){return this.transform(e=>e.replace(t,n))};}return i});
1
+ import {c}from'./chunk-2NCXW7ID.mjs';c((i,s,c)=>{if(c?.type==="string"){let r=i;r.min=function(t,{message:n}={}){return this.refine(e=>e.length>=t,{message:n||(e=>`String must be at least ${t} characters long (received ${e.length} characters: "${e}")`)})},r.max=function(t,{message:n}={}){return this.refine(e=>e.length<=t,{message:n||(e=>`String must be at most ${t} characters long (received ${e.length} characters: "${e}")`)})},r.length=function(t,{message:n}={}){return this.refine(e=>e.length===t,{message:n||(e=>`String must be exactly ${t} characters long (received ${e.length} characters: "${e}")`)})},r.nonEmpty=function({message:t}={}){return this.refine(n=>n.length>0,{message:t||"String must not be empty (received empty string)"})},r.startsWith=function(t,{message:n}={}){return this.refine(e=>e.startsWith(t),{message:n||(e=>`String must start with "${t}" (received: "${e}")`)})},r.endsWith=function(t,{message:n}={}){return this.refine(e=>e.endsWith(t),{message:n||(e=>`String must end with "${t}" (received: "${e}")`)})},r.includes=function(t,{message:n}={}){return this.refine(e=>e.includes(t),{message:n||(e=>`String must include "${t}" (received: "${e}")`)})},r.toLowerCase=function(){return this.transform(t=>t.toLowerCase())},r.toUpperCase=function(){return this.transform(t=>t.toUpperCase())},r.trim=function(){return this.transform(t=>t.trim())},r.padStart=function(t,n=" "){return this.transform(e=>e.padStart(t,n))},r.padEnd=function(t,n=" "){return this.transform(e=>e.padEnd(t,n))},r.replace=function(t,n){return this.transform(e=>e.replace(t,n))};}return i});
@@ -1 +1 @@
1
- import {c}from'./chunk-NCHMO7B3.mjs';c((i,c,m)=>{if(m?.type==="number"){let n=i;n.min=function(e,{message:t}={}){return this.refine(r=>r>=e,{message:t||`Number must be greater than or equal to ${e}.`})},n.max=function(e,{message:t}={}){return this.refine(r=>r<=e,{message:t||`Number must be less than or equal to ${e}.`})},n.positive=function({message:e}={}){return this.refine(t=>t>0,{message:e||"Number must be positive."})},n.negative=function({message:e}={}){return this.refine(t=>t<0,{message:e||"Number must be negative."})},n.int=function({message:e}={}){return this.refine(t=>Number.isInteger(t),{message:e||"Number must be an integer."})},n.float=function({message:e}={}){return this.refine(t=>Number.isFinite(t)&&!Number.isInteger(t),{message:e||"Number must be a floating point (non-integer)."})},n.multipleOf=function(e,{message:t}={}){return this.refine(r=>r%e===0,{message:t||`Number must be a multiple of ${e}.`})},n.finite=function({message:e}={}){return this.refine(t=>Number.isFinite(t),{message:e||"Number must be finite."})};}return i});
1
+ import {c}from'./chunk-2NCXW7ID.mjs';c((i,c,m)=>{if(m?.type==="number"){let n=i;n.min=function(e,{message:t}={}){return this.refine(r=>r>=e,{message:t||`Number must be greater than or equal to ${e}.`})},n.max=function(e,{message:t}={}){return this.refine(r=>r<=e,{message:t||`Number must be less than or equal to ${e}.`})},n.positive=function({message:e}={}){return this.refine(t=>t>0,{message:e||"Number must be positive."})},n.negative=function({message:e}={}){return this.refine(t=>t<0,{message:e||"Number must be negative."})},n.int=function({message:e}={}){return this.refine(t=>Number.isInteger(t),{message:e||"Number must be an integer."})},n.float=function({message:e}={}){return this.refine(t=>Number.isFinite(t)&&!Number.isInteger(t),{message:e||"Number must be a floating point (non-integer)."})},n.multipleOf=function(e,{message:t}={}){return this.refine(r=>r%e===0,{message:t||`Number must be a multiple of ${e}.`})},n.finite=function({message:e}={}){return this.refine(t=>Number.isFinite(t),{message:e||"Number must be finite."})};}return i});
package/dist/full.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var P={abortEarly:true};function y(r,o){if(!o)return r;let u=r?.cause?.key?`${o}.${r.cause.key}`:`${o}`;return {message:`Error parsing key "${u}": ${r.message}`,cause:{key:u}}}function O(r,o,u){!r.errors||r.errors.length===0||r.errors.forEach(a=>{let t=y(a,u);o.push(t);});}function d(r){return {...P,...r}}var $=r=>typeof r=="string"||r instanceof String,N=r=>typeof r=="number"||r instanceof Number,k=r=>r===true||r===false,w=r=>r instanceof Date&&!Number.isNaN(r.getTime()),E=r=>Array.isArray(r),T=r=>typeof r=="object"&&r!==null&&!Array.isArray(r),D={object(r,o){let u=S(T,{...o,type:"object"});return u._getDescription=()=>`object({ ${Object.entries(r).map(([t,n])=>`${t}: ${n._getDescription()}`).join(", ")} })`,h(u,"_parse",(a,t,n)=>{let e=a(t,n),{abortEarly:s}=d(n);if(e.success===false)return e;let c={},i=[];for(let m in r){let p=r[m]._parse(e.data[m],n);if(p.success)c[m]=p.data;else {if(p=p,s!==false){let f=y(p.error,m);return {success:false,error:f,errors:[f]}}O(p,i,m);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:c}}),u},string(r){return S($,{...r,type:"string"})},number(r){return S(N,{...r,type:"number"})},boolean(r){return S(k,{...r,type:"boolean"})},date(r){return S(w,{...r,type:"date"})},enum(r,o){let u=e=>r.includes(e),a=e=>`Invalid ${t} value. Expected ${r.map(s=>`"${s}"`).join(" | ")}, received "${e}".`,t="enum",n=S(u,{message:a,...o,type:t});return n._getDescription=()=>`enum(${r.map(e=>`"${e}"`).join(" | ")})`,n},array(r,o){let u=S(E,{...o,type:"array"});return u._getDescription=()=>`array(${r._getDescription()})`,h(u,"_parse",(a,t,n)=>{let e=a(t,n),{abortEarly:s}=d(n);if(e.success===false)return e;let c=[],i=[];for(let m=0;m<e.data.length;m++){let p=r._parse(e.data[m],n);if(p.success)c.push(p.data);else {if(p=p,s!==false){let f=y(p.error,m);return {success:false,error:f,errors:[f]}}O(p,i,m);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:c}}),u},any(){return S(()=>true)},preprocess(r,o){return h(o,"_parse",(u,a)=>(a=r(a),u(a))),o},union(r,o){return S(n=>{for(let e=0;e<r.length;e++){let s=r[e]._parse(n);if(s.success)return s}return false},{message:n=>`Invalid union value. Expected the value to match one of the schemas:${r.map((e,s)=>` ${s+1}. ${e._getDescription()}`).join(",")} but received "${typeof n}" with value: ${T(n)?JSON.stringify(n):`"${n}"`}`,...o,type:"union"})}};function x(r){return o=>`The value "${o}" must be type of ${r} but is type of "${typeof o}".`}function h(r,o,u){let a=r[o];r[o]=(...t)=>u(a,...t);}function S(r,{type:o="any",name:u,message:a}={}){a=a||x(o);let t={name:u,message:a,type:o},n={_getName(){return u},_getType(){return o},_getDescription(){return this._getName()??this._getType()},_parse(e,s){let c=r(e);if(c===true)return {success:true,data:e};if(typeof c=="object"&&c?.success===true)return c;let i={message:typeof a=="function"?a(e):a};return {success:false,error:i,errors:[i]}},parse(e,s){let c=n._parse(e,s);if(!c.success)throw c=c,new Error(c.error.message,{cause:c.error.cause});return c.data},safeParse(e,s){return n._parse(e,s)},transform(e){return h(this,"_parse",(s,c,i)=>{let m=s(c,i);return m.success&&(m.data=e(m.data)),m}),this},optional(){return h(this,"_parse",(e,s,c)=>{let i=e(s,c);return !i.success&&s===void 0&&(i.data=void 0,i.success=true),i}),this},nullable(){return h(this,"_parse",(e,s,c)=>{let i=e(s,c);return !i.success&&s===null&&(i.data=null,i.success=true),i}),this},nullish(){return h(this,"_parse",(e,s,c)=>{let i=e(s,c);return !i.success&&s==null&&(i.success=true,i.data=s),i}),this},default(e){return h(this,"_parse",(s,c,i)=>(c===void 0&&(c=e,c=typeof e=="function"?e():e),s(c,i))),this},pipe(e){return h(this,"_parse",(s,c,i)=>{let m=s(c,i);return m.success?e._parse(m.data,i):m}),this},refine(e,{message:s,type:c}={}){return c&&(s=s||x(c),o=c),h(this,"_parse",(i,m,p)=>{let f=i(m,p);d(p);if(!f.success)return f;let l=e(f.data);if(l===true||typeof l=="object"&&l?.success===true)return f;let b={message:typeof s=="function"?s(m):s};return {success:false,error:b,errors:[b]}}),this}};return g.length>0?g.reduce((e,s)=>s(e,r,t)??e,n):n}var g=[];function I(r){g.push(r);}I((r,o,u)=>{if(u?.type==="string"){let a=r;a.min=function(t,{message:n}={}){return this.refine(e=>e.length>=t,{message:n||(e=>`String must be at least ${t} characters long (received ${e.length} characters: "${e}")`)})},a.max=function(t,{message:n}={}){return this.refine(e=>e.length<=t,{message:n||(e=>`String must be at most ${t} characters long (received ${e.length} characters: "${e}")`)})},a.length=function(t,{message:n}={}){return this.refine(e=>e.length===t,{message:n||(e=>`String must be exactly ${t} characters long (received ${e.length} characters: "${e}")`)})},a.nonEmpty=function({message:t}={}){return this.refine(n=>n.length>0,{message:t||"String must not be empty (received empty string)"})},a.startsWith=function(t,{message:n}={}){return this.refine(e=>e.startsWith(t),{message:n||(e=>`String must start with "${t}" (received: "${e}")`)})},a.endsWith=function(t,{message:n}={}){return this.refine(e=>e.endsWith(t),{message:n||(e=>`String must end with "${t}" (received: "${e}")`)})},a.includes=function(t,{message:n}={}){return this.refine(e=>e.includes(t),{message:n||(e=>`String must include "${t}" (received: "${e}")`)})},a.toLowerCase=function(){return this.transform(t=>t.toLowerCase())},a.toUpperCase=function(){return this.transform(t=>t.toUpperCase())},a.trim=function(){return this.transform(t=>t.trim())},a.padStart=function(t,n=" "){return this.transform(e=>e.padStart(t,n))},a.padEnd=function(t,n=" "){return this.transform(e=>e.padEnd(t,n))},a.replace=function(t,n){return this.transform(e=>e.replace(t,n))};}return r});I((r,o,u)=>{if(u?.type==="number"){let a=r;a.min=function(t,{message:n}={}){return this.refine(e=>e>=t,{message:n||`Number must be greater than or equal to ${t}.`})},a.max=function(t,{message:n}={}){return this.refine(e=>e<=t,{message:n||`Number must be less than or equal to ${t}.`})},a.positive=function({message:t}={}){return this.refine(n=>n>0,{message:t||"Number must be positive."})},a.negative=function({message:t}={}){return this.refine(n=>n<0,{message:t||"Number must be negative."})},a.int=function({message:t}={}){return this.refine(n=>Number.isInteger(n),{message:t||"Number must be an integer."})},a.float=function({message:t}={}){return this.refine(n=>Number.isFinite(n)&&!Number.isInteger(n),{message:t||"Number must be a floating point (non-integer)."})},a.multipleOf=function(t,{message:n}={}){return this.refine(e=>e%t===0,{message:n||`Number must be a multiple of ${t}.`})},a.finite=function({message:t}={}){return this.refine(n=>Number.isFinite(n),{message:t||"Number must be finite."})};}return r});I((r,o,u)=>{if(u?.type==="array"){let a=r;a.min=function(t,{message:n}={}){return this.refine(e=>e.length>=t,{message:n||`Array must contain at least ${t} items.`})},a.max=function(t,{message:n}={}){return this.refine(e=>e.length<=t,{message:n||`Array must contain at most ${t} items.`})},a.length=function(t,{message:n}={}){return this.refine(e=>e.length===t,{message:n||`Array must contain exactly ${t} items.`})},a.nonEmpty=function({message:t}={}){return this.refine(n=>n.length>0,{message:t||"Array must not be empty."})},a.unique=function({message:t}={}){return this.refine(n=>{let e=new Set;try{return n.every(s=>{let c=JSON.stringify(s);return e.has(c)?!1:(e.add(c),!0)})}catch{return new Set(n).size===n.length}},{message:t||"Array items must be unique."})},a.sort=function(){return this.transform(t=>[...t].sort())},a.reverse=function(){return this.transform(t=>[...t].reverse())};}return r});exports.extend=I;exports.hookOriginal=h;exports.s=D;
1
+ 'use strict';var w={abortEarly:true};function y(n,u){if(!u)return n;let o=n?.cause?.key?`${u}.${n.cause.key}`:`${u}`;return {message:`Error parsing key "${o}": ${n.message}`,cause:{key:o}}}function O(n,u,o){if(n.errors?.length)for(let a=0;a<n.errors.length;a++)u.push(y(n.errors[a],o));}function d(n){return {...w,...n}}var k=n=>typeof n=="string"||n instanceof String,P=n=>(typeof n=="number"||n instanceof Number)&&!Number.isNaN(n),$=n=>n===true||n===false,N=n=>n instanceof Date&&!Number.isNaN(n.getTime()),E=n=>Array.isArray(n),T=n=>typeof n=="object"&&n!==null&&!Array.isArray(n),v={object(n,u){let o=S(T,{...u,type:"object"});return o._getDescription=()=>`object({ ${Object.entries(n).map(([t,r])=>`${t}: ${r._getDescription()}`).join(", ")} })`,p(o,"_parse",(a,t,r)=>{let e=a(t,r),{abortEarly:s}=d(r);if(e.success===false)return e;let c={},i=[];for(let m in n){let f=n[m]._parse(e.data[m],r);if(f.success)c[m]=f.data;else {if(f=f,s!==false){let h=y(f.error,m);return {success:false,error:h,errors:[h]}}O(f,i,m);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:c}}),o},string(n){return S(k,{...n,type:"string"})},number(n){return S(P,{...n,type:"number"})},boolean(n){return S($,{...n,type:"boolean"})},date(n){return S(N,{...n,type:"date"})},enum(n,u){let o=e=>n.includes(e),a=e=>`Invalid ${t} value. Expected ${n.map(s=>`"${s}"`).join(" | ")}, received "${e}".`,t="enum",r=S(o,{message:a,...u,type:t});return r._getDescription=()=>`enum(${n.map(e=>`"${e}"`).join(" | ")})`,r},array(n,u){let o=S(E,{...u,type:"array"});return o._getDescription=()=>`array(${n._getDescription()})`,p(o,"_parse",(a,t,r)=>{let e=a(t,r),{abortEarly:s}=d(r);if(e.success===false)return e;let c=[],i=[];for(let m=0;m<e.data.length;m++){let f=n._parse(e.data[m],r);if(f.success)c.push(f.data);else {if(f=f,s!==false){let h=y(f.error,m);return {success:false,error:h,errors:[h]}}O(f,i,m);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:c}}),o},any(){return S(()=>true)},preprocess(n,u){return p(u,"_parse",(o,a)=>(a=n(a),o(a))),u},union(n,u){return S(r=>{for(let e=0;e<n.length;e++){let s=n[e]._parse(r);if(s.success)return s}return false},{message:r=>`Invalid union value. Expected the value to match one of the schemas:${n.map((e,s)=>` ${s+1}. ${e._getDescription()}`).join(",")} but received "${typeof r}" with value: ${T(r)?JSON.stringify(r):`"${r}"`}`,...u,type:"union"})},literal(n,u){let t=S(r=>r===n,{message:r=>u?.message?typeof u.message=="function"?u.message(r):u.message:`Expected literal value "${n}", received "${r}"`,name:u?.name,type:"literal"});return t._getDescription=()=>`literal("${n}")`,t}};function x(n){return u=>`The value "${u}" must be type of ${n} but is type of "${typeof u}".`}function p(n,u,o){let a=n[u];n[u]=(...t)=>o(a,...t);}function S(n,{type:u="any",name:o,message:a}={}){a=a||x(u);let t={name:o,message:a,type:u},r={_getName(){return o},_getType(){return u},_getDescription(){return this._getName()??this._getType()},_parse(e,s){let c=n(e);if(c===true)return {success:true,data:e};if(typeof c=="object"&&c?.success===true)return c;let i={message:typeof a=="function"?a(e):a};return {success:false,error:i,errors:[i]}},parse(e,s){let c=r._parse(e,s);if(!c.success)throw c=c,new Error(c.error.message,{cause:c.error.cause});return c.data},safeParse(e,s){return r._parse(e,s)},transform(e){return p(this,"_parse",(s,c,i)=>{let m=s(c,i);return m.success&&(m.data=e(m.data)),m}),this},optional(){return p(this,"_parse",(e,s,c)=>{let i=e(s,c);return !i.success&&s===void 0&&(i.data=void 0,i.success=true),i}),this},nullable(){return p(this,"_parse",(e,s,c)=>{let i=e(s,c);return !i.success&&s===null&&(i.data=null,i.success=true),i}),this},nullish(){return p(this,"_parse",(e,s,c)=>{let i=e(s,c);return !i.success&&s==null&&(i.success=true,i.data=s),i}),this},default(e){return p(this,"_parse",(s,c,i)=>(c===void 0&&(c=typeof e=="function"?e():e),s(c,i))),this},catch(e){return p(this,"_parse",(s,c,i)=>{let m=s(c,i);return m.success?m:{success:true,data:typeof e=="function"?e({input:c,error:m.error}):e}}),this},pipe(e){return p(this,"_parse",(s,c,i)=>{let m=s(c,i);return m.success?e._parse(m.data,i):m}),this},refine(e,{message:s,type:c}={}){return c&&(s=s||x(c),u=c),p(this,"_parse",(i,m,f)=>{let h=i(m,f);d(f);if(!h.success)return h;let l=e(h.data);if(l===true||typeof l=="object"&&l?.success===true)return h;let b={message:typeof s=="function"?s(m):s};return {success:false,error:b,errors:[b]}}),this}};return g.length>0?g.reduce((e,s)=>s(e,n,t)??e,r):r}var g=[];function I(n){if(typeof n!="function")throw new TypeError("extend() requires a function argument");g.push(n);}I((n,u,o)=>{if(o?.type==="string"){let a=n;a.min=function(t,{message:r}={}){return this.refine(e=>e.length>=t,{message:r||(e=>`String must be at least ${t} characters long (received ${e.length} characters: "${e}")`)})},a.max=function(t,{message:r}={}){return this.refine(e=>e.length<=t,{message:r||(e=>`String must be at most ${t} characters long (received ${e.length} characters: "${e}")`)})},a.length=function(t,{message:r}={}){return this.refine(e=>e.length===t,{message:r||(e=>`String must be exactly ${t} characters long (received ${e.length} characters: "${e}")`)})},a.nonEmpty=function({message:t}={}){return this.refine(r=>r.length>0,{message:t||"String must not be empty (received empty string)"})},a.startsWith=function(t,{message:r}={}){return this.refine(e=>e.startsWith(t),{message:r||(e=>`String must start with "${t}" (received: "${e}")`)})},a.endsWith=function(t,{message:r}={}){return this.refine(e=>e.endsWith(t),{message:r||(e=>`String must end with "${t}" (received: "${e}")`)})},a.includes=function(t,{message:r}={}){return this.refine(e=>e.includes(t),{message:r||(e=>`String must include "${t}" (received: "${e}")`)})},a.toLowerCase=function(){return this.transform(t=>t.toLowerCase())},a.toUpperCase=function(){return this.transform(t=>t.toUpperCase())},a.trim=function(){return this.transform(t=>t.trim())},a.padStart=function(t,r=" "){return this.transform(e=>e.padStart(t,r))},a.padEnd=function(t,r=" "){return this.transform(e=>e.padEnd(t,r))},a.replace=function(t,r){return this.transform(e=>e.replace(t,r))};}return n});I((n,u,o)=>{if(o?.type==="number"){let a=n;a.min=function(t,{message:r}={}){return this.refine(e=>e>=t,{message:r||`Number must be greater than or equal to ${t}.`})},a.max=function(t,{message:r}={}){return this.refine(e=>e<=t,{message:r||`Number must be less than or equal to ${t}.`})},a.positive=function({message:t}={}){return this.refine(r=>r>0,{message:t||"Number must be positive."})},a.negative=function({message:t}={}){return this.refine(r=>r<0,{message:t||"Number must be negative."})},a.int=function({message:t}={}){return this.refine(r=>Number.isInteger(r),{message:t||"Number must be an integer."})},a.float=function({message:t}={}){return this.refine(r=>Number.isFinite(r)&&!Number.isInteger(r),{message:t||"Number must be a floating point (non-integer)."})},a.multipleOf=function(t,{message:r}={}){return this.refine(e=>e%t===0,{message:r||`Number must be a multiple of ${t}.`})},a.finite=function({message:t}={}){return this.refine(r=>Number.isFinite(r),{message:t||"Number must be finite."})};}return n});I((n,u,o)=>{if(o?.type==="array"){let a=n;a.min=function(t,{message:r}={}){return this.refine(e=>e.length>=t,{message:r||`Array must contain at least ${t} items.`})},a.max=function(t,{message:r}={}){return this.refine(e=>e.length<=t,{message:r||`Array must contain at most ${t} items.`})},a.length=function(t,{message:r}={}){return this.refine(e=>e.length===t,{message:r||`Array must contain exactly ${t} items.`})},a.nonEmpty=function({message:t}={}){return this.refine(r=>r.length>0,{message:t||"Array must not be empty."})},a.unique=function({message:t}={}){return this.refine(r=>{let e=new Set;try{return r.every(s=>{let c=JSON.stringify(s);return e.has(c)?!1:(e.add(c),!0)})}catch{return new Set(r).size===r.length}},{message:t||"Array items must be unique."})},a.sort=function(){return this.transform(t=>[...t].sort())},a.reverse=function(){return this.transform(t=>[...t].reverse())};}return n});exports.extend=I;exports.hookOriginal=p;exports.s=v;
package/dist/full.d.mts CHANGED
@@ -1,4 +1,4 @@
1
1
  import './string.mjs';
2
2
  import './number.mjs';
3
3
  import './array.mjs';
4
- export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.mjs';
4
+ export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.mjs';
package/dist/full.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import './string.js';
2
2
  import './number.js';
3
3
  import './array.js';
4
- export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.js';
4
+ export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.js';
package/dist/full.mjs CHANGED
@@ -1 +1 @@
1
- import'./chunk-PHNKAD7Q.mjs';import'./chunk-SHVCROKM.mjs';import'./chunk-BV6SWQSH.mjs';export{c as extend,b as hookOriginal,a as s}from'./chunk-NCHMO7B3.mjs';
1
+ import'./chunk-4JJPVRF6.mjs';import'./chunk-PH4B25KI.mjs';import'./chunk-LZRUIXQL.mjs';export{c as extend,b as hookOriginal,a as s}from'./chunk-2NCXW7ID.mjs';
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var P={abortEarly:true};function d(e,s){if(!s)return e;let o=e?.cause?.key?`${s}.${e.cause.key}`:`${s}`;return {message:`Error parsing key "${o}": ${e.message}`,cause:{key:o}}}function b(e,s,o){!e.errors||e.errors.length===0||e.errors.forEach(i=>{let f=d(i,o);s.push(f);});}function y(e){return {...P,...e}}var x=e=>typeof e=="string"||e instanceof String,k=e=>typeof e=="number"||e instanceof Number,w=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),g=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),R={object(e,s){let o=l(g,{...s,type:"object"});return o._getDescription=()=>`object({ ${Object.entries(e).map(([f,c])=>`${f}: ${c._getDescription()}`).join(", ")} })`,h(o,"_parse",(i,f,c)=>{let t=i(f,c),{abortEarly:r}=y(c);if(t.success===false)return t;let a={},n=[];for(let u in e){let p=e[u]._parse(t.data[u],c);if(p.success)a[u]=p.data;else {if(p=p,r!==false){let m=d(p.error,u);return {success:false,error:m,errors:[m]}}b(p,n,u);}}return n.length>0?{success:false,error:n[0],errors:n}:{success:true,data:a}}),o},string(e){return l(x,{...e,type:"string"})},number(e){return l(k,{...e,type:"number"})},boolean(e){return l(w,{...e,type:"boolean"})},date(e){return l(E,{...e,type:"date"})},enum(e,s){let o=t=>e.includes(t),i=t=>`Invalid ${f} value. Expected ${e.map(r=>`"${r}"`).join(" | ")}, received "${t}".`,f="enum",c=l(o,{message:i,...s,type:f});return c._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,c},array(e,s){let o=l(_,{...s,type:"array"});return o._getDescription=()=>`array(${e._getDescription()})`,h(o,"_parse",(i,f,c)=>{let t=i(f,c),{abortEarly:r}=y(c);if(t.success===false)return t;let a=[],n=[];for(let u=0;u<t.data.length;u++){let p=e._parse(t.data[u],c);if(p.success)a.push(p.data);else {if(p=p,r!==false){let m=d(p.error,u);return {success:false,error:m,errors:[m]}}b(p,n,u);}}return n.length>0?{success:false,error:n[0],errors:n}:{success:true,data:a}}),o},any(){return l(()=>true)},preprocess(e,s){return h(s,"_parse",(o,i)=>(i=e(i),o(i))),s},union(e,s){return l(c=>{for(let t=0;t<e.length;t++){let r=e[t]._parse(c);if(r.success)return r}return false},{message:c=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,r)=>` ${r+1}. ${t._getDescription()}`).join(",")} but received "${typeof c}" with value: ${g(c)?JSON.stringify(c):`"${c}"`}`,...s,type:"union"})}};function O(e){return s=>`The value "${s}" must be type of ${e} but is type of "${typeof s}".`}function h(e,s,o){let i=e[s];e[s]=(...f)=>o(i,...f);}function l(e,{type:s="any",name:o,message:i}={}){i=i||O(s);let f={name:o,message:i,type:s},c={_getName(){return o},_getType(){return s},_getDescription(){return this._getName()??this._getType()},_parse(t,r){let a=e(t);if(a===true)return {success:true,data:t};if(typeof a=="object"&&a?.success===true)return a;let n={message:typeof i=="function"?i(t):i};return {success:false,error:n,errors:[n]}},parse(t,r){let a=c._parse(t,r);if(!a.success)throw a=a,new Error(a.error.message,{cause:a.error.cause});return a.data},safeParse(t,r){return c._parse(t,r)},transform(t){return h(this,"_parse",(r,a,n)=>{let u=r(a,n);return u.success&&(u.data=t(u.data)),u}),this},optional(){return h(this,"_parse",(t,r,a)=>{let n=t(r,a);return !n.success&&r===void 0&&(n.data=void 0,n.success=true),n}),this},nullable(){return h(this,"_parse",(t,r,a)=>{let n=t(r,a);return !n.success&&r===null&&(n.data=null,n.success=true),n}),this},nullish(){return h(this,"_parse",(t,r,a)=>{let n=t(r,a);return !n.success&&r==null&&(n.success=true,n.data=r),n}),this},default(t){return h(this,"_parse",(r,a,n)=>(a===void 0&&(a=t,a=typeof t=="function"?t():t),r(a,n))),this},pipe(t){return h(this,"_parse",(r,a,n)=>{let u=r(a,n);return u.success?t._parse(u.data,n):u}),this},refine(t,{message:r,type:a}={}){return a&&(r=r||O(a),s=a),h(this,"_parse",(n,u,p)=>{let m=n(u,p);y(p);if(!m.success)return m;let I=t(m.data);if(I===true||typeof I=="object"&&I?.success===true)return m;let T={message:typeof r=="function"?r(u):r};return {success:false,error:T,errors:[T]}}),this}};return S.length>0?S.reduce((t,r)=>r(t,e,f)??t,c):c}var S=[];function $(e){S.push(e);}exports.extend=$;exports.hookOriginal=h;exports.s=R;
1
+ 'use strict';var k={abortEarly:true};function d(e,s){if(!s)return e;let i=e?.cause?.key?`${s}.${e.cause.key}`:`${s}`;return {message:`Error parsing key "${i}": ${e.message}`,cause:{key:i}}}function T(e,s,i){if(e.errors?.length)for(let o=0;o<e.errors.length;o++)s.push(d(e.errors[o],i));}function y(e){return {...k,...e}}var x=e=>typeof e=="string"||e instanceof String,w=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),P=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),b=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),$={object(e,s){let i=h(b,{...s,type:"object"});return i._getDescription=()=>`object({ ${Object.entries(e).map(([p,c])=>`${p}: ${c._getDescription()}`).join(", ")} })`,m(i,"_parse",(o,p,c)=>{let t=o(p,c),{abortEarly:n}=y(c);if(t.success===false)return t;let a={},r=[];for(let u in e){let f=e[u]._parse(t.data[u],c);if(f.success)a[u]=f.data;else {if(f=f,n!==false){let l=d(f.error,u);return {success:false,error:l,errors:[l]}}T(f,r,u);}}return r.length>0?{success:false,error:r[0],errors:r}:{success:true,data:a}}),i},string(e){return h(x,{...e,type:"string"})},number(e){return h(w,{...e,type:"number"})},boolean(e){return h(P,{...e,type:"boolean"})},date(e){return h(E,{...e,type:"date"})},enum(e,s){let i=t=>e.includes(t),o=t=>`Invalid ${p} value. Expected ${e.map(n=>`"${n}"`).join(" | ")}, received "${t}".`,p="enum",c=h(i,{message:o,...s,type:p});return c._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,c},array(e,s){let i=h(_,{...s,type:"array"});return i._getDescription=()=>`array(${e._getDescription()})`,m(i,"_parse",(o,p,c)=>{let t=o(p,c),{abortEarly:n}=y(c);if(t.success===false)return t;let a=[],r=[];for(let u=0;u<t.data.length;u++){let f=e._parse(t.data[u],c);if(f.success)a.push(f.data);else {if(f=f,n!==false){let l=d(f.error,u);return {success:false,error:l,errors:[l]}}T(f,r,u);}}return r.length>0?{success:false,error:r[0],errors:r}:{success:true,data:a}}),i},any(){return h(()=>true)},preprocess(e,s){return m(s,"_parse",(i,o)=>(o=e(o),i(o))),s},union(e,s){return h(c=>{for(let t=0;t<e.length;t++){let n=e[t]._parse(c);if(n.success)return n}return false},{message:c=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,n)=>` ${n+1}. ${t._getDescription()}`).join(",")} but received "${typeof c}" with value: ${b(c)?JSON.stringify(c):`"${c}"`}`,...s,type:"union"})},literal(e,s){let p=h(c=>c===e,{message:c=>s?.message?typeof s.message=="function"?s.message(c):s.message:`Expected literal value "${e}", received "${c}"`,name:s?.name,type:"literal"});return p._getDescription=()=>`literal("${e}")`,p}};function O(e){return s=>`The value "${s}" must be type of ${e} but is type of "${typeof s}".`}function m(e,s,i){let o=e[s];e[s]=(...p)=>i(o,...p);}function h(e,{type:s="any",name:i,message:o}={}){o=o||O(s);let p={name:i,message:o,type:s},c={_getName(){return i},_getType(){return s},_getDescription(){return this._getName()??this._getType()},_parse(t,n){let a=e(t);if(a===true)return {success:true,data:t};if(typeof a=="object"&&a?.success===true)return a;let r={message:typeof o=="function"?o(t):o};return {success:false,error:r,errors:[r]}},parse(t,n){let a=c._parse(t,n);if(!a.success)throw a=a,new Error(a.error.message,{cause:a.error.cause});return a.data},safeParse(t,n){return c._parse(t,n)},transform(t){return m(this,"_parse",(n,a,r)=>{let u=n(a,r);return u.success&&(u.data=t(u.data)),u}),this},optional(){return m(this,"_parse",(t,n,a)=>{let r=t(n,a);return !r.success&&n===void 0&&(r.data=void 0,r.success=true),r}),this},nullable(){return m(this,"_parse",(t,n,a)=>{let r=t(n,a);return !r.success&&n===null&&(r.data=null,r.success=true),r}),this},nullish(){return m(this,"_parse",(t,n,a)=>{let r=t(n,a);return !r.success&&n==null&&(r.success=true,r.data=n),r}),this},default(t){return m(this,"_parse",(n,a,r)=>(a===void 0&&(a=typeof t=="function"?t():t),n(a,r))),this},catch(t){return m(this,"_parse",(n,a,r)=>{let u=n(a,r);return u.success?u:{success:true,data:typeof t=="function"?t({input:a,error:u.error}):t}}),this},pipe(t){return m(this,"_parse",(n,a,r)=>{let u=n(a,r);return u.success?t._parse(u.data,r):u}),this},refine(t,{message:n,type:a}={}){return a&&(n=n||O(a),s=a),m(this,"_parse",(r,u,f)=>{let l=r(u,f);y(f);if(!l.success)return l;let I=t(l.data);if(I===true||typeof I=="object"&&I?.success===true)return l;let g={message:typeof n=="function"?n(u):n};return {success:false,error:g,errors:[g]}}),this}};return S.length>0?S.reduce((t,n)=>n(t,e,p)??t,c):c}var S=[];function A(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");S.push(e);}exports.extend=A;exports.hookOriginal=m;exports.s=$;
package/dist/index.d.mts CHANGED
@@ -30,9 +30,15 @@ interface SchemaInterface<Input, Output> {
30
30
  nullable(): SchemaInterface<Input, Output | null>;
31
31
  nullish(): SchemaInterface<Input, Output | undefined | null>;
32
32
  default(defaultValue: Partial<Input> | (() => Partial<Input>) | Partial<Output>): SchemaInterface<Input, Output>;
33
+ catch(catchValue: Output | ((ctx: {
34
+ input: unknown;
35
+ error: ErrorStructure;
36
+ }) => Output)): SchemaInterface<Input, Output>;
33
37
  pipe<NewOutput>(schema: SchemaInterface<Output, NewOutput>): SchemaInterface<Output, NewOutput>;
34
38
  refine(validation: ValidationMethod<Input, Output>, options?: CreateSchemaInterfaceOptions): SchemaInterface<Input, Output>;
35
39
  }
40
+ interface LiteralSchemaInterface<T extends string | number | boolean> extends SchemaInterface<T, T> {
41
+ }
36
42
  interface UnionSchemaInterface<T extends Array<SchemaInterface<unknown, unknown>>> extends SchemaInterface<ReturnType<T[number]['parse']>, ReturnType<T[number]['parse']>> {
37
43
  }
38
44
  interface EnumSchemaInterface<T extends string> extends SchemaInterface<string, T> {
@@ -53,7 +59,7 @@ interface ObjectSchemaInterface<T extends Record<string, SchemaType>> extends Sc
53
59
  [Property in keyof T]: ReturnType<T[Property]['parse']>;
54
60
  }> {
55
61
  }
56
- type SchemaType = StringSchemaInterface | SchemaInterface<unknown, unknown> | SchemaInterface<string, string> | SchemaInterface<string, string | undefined> | SchemaInterface<string, string | null> | SchemaInterface<string, string | undefined | null> | ObjectSchemaInterface<Record<string, SchemaType>> | SchemaInterface<object, object> | SchemaInterface<object, object | undefined> | SchemaInterface<object, object | null> | SchemaInterface<object, object | undefined | null> | NumberSchemaInterface | SchemaInterface<number, number> | SchemaInterface<number, number | undefined> | SchemaInterface<number, number | null> | SchemaInterface<number, number | undefined | null> | BooleanSchemaInterface | SchemaInterface<boolean, boolean> | SchemaInterface<boolean, boolean | undefined> | SchemaInterface<boolean, boolean | null> | SchemaInterface<boolean, boolean | undefined | null> | DateSchemaInterface | SchemaInterface<Date, Date> | SchemaInterface<Date, Date | undefined> | SchemaInterface<Date, Date | null> | SchemaInterface<Date, Date | undefined | null> | EnumSchemaInterface<string> | UnionSchemaInterface<Array<SchemaInterface<unknown, unknown>>> | ArraySchemaInterface<StringSchemaInterface | ObjectSchemaInterface<Record<string, SchemaType>> | NumberSchemaInterface | BooleanSchemaInterface | DateSchemaInterface | EnumSchemaInterface<string>> | SchemaInterface<Array<unknown>, Array<unknown>> | SchemaInterface<Array<unknown>, Array<unknown> | undefined> | SchemaInterface<Array<unknown>, Array<unknown> | null> | SchemaInterface<Array<unknown>, Array<unknown> | undefined | null>;
62
+ type SchemaType = LiteralSchemaInterface<string> | LiteralSchemaInterface<number> | LiteralSchemaInterface<boolean> | StringSchemaInterface | SchemaInterface<unknown, unknown> | SchemaInterface<string, string> | SchemaInterface<string, string | undefined> | SchemaInterface<string, string | null> | SchemaInterface<string, string | undefined | null> | ObjectSchemaInterface<Record<string, SchemaType>> | SchemaInterface<object, object> | SchemaInterface<object, object | undefined> | SchemaInterface<object, object | null> | SchemaInterface<object, object | undefined | null> | NumberSchemaInterface | SchemaInterface<number, number> | SchemaInterface<number, number | undefined> | SchemaInterface<number, number | null> | SchemaInterface<number, number | undefined | null> | BooleanSchemaInterface | SchemaInterface<boolean, boolean> | SchemaInterface<boolean, boolean | undefined> | SchemaInterface<boolean, boolean | null> | SchemaInterface<boolean, boolean | undefined | null> | DateSchemaInterface | SchemaInterface<Date, Date> | SchemaInterface<Date, Date | undefined> | SchemaInterface<Date, Date | null> | SchemaInterface<Date, Date | undefined | null> | EnumSchemaInterface<string> | UnionSchemaInterface<Array<SchemaInterface<unknown, unknown>>> | ArraySchemaInterface<StringSchemaInterface | ObjectSchemaInterface<Record<string, SchemaType>> | NumberSchemaInterface | BooleanSchemaInterface | DateSchemaInterface | EnumSchemaInterface<string>> | SchemaInterface<Array<unknown>, Array<unknown>> | SchemaInterface<Array<unknown>, Array<unknown> | undefined> | SchemaInterface<Array<unknown>, Array<unknown> | null> | SchemaInterface<Array<unknown>, Array<unknown> | undefined | null>;
57
63
  type ErrorMessage = string | ((value: unknown) => string);
58
64
  type ExtenderType = (inter: SchemaType, validation: Function, options?: {
59
65
  message: ErrorMessage;
@@ -207,8 +213,23 @@ declare const s: {
207
213
  * ```
208
214
  */
209
215
  union<T extends Array<SchemaType>>(definitions: T, options?: SchemaInterfaceOptions): UnionSchemaInterface<T>;
216
+ /**
217
+ * Creates a literal schema that only accepts a specific value.
218
+ *
219
+ * @param value - The exact value to match
220
+ * @param options - Optional configuration
221
+ * @returns Literal schema interface
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * const adminSchema = s.literal('admin');
226
+ * adminSchema.parse('admin'); // 'admin'
227
+ * adminSchema.parse('user'); // throws error
228
+ * ```
229
+ */
230
+ literal<T extends string | number | boolean>(value: T, options?: SchemaInterfaceOptions): LiteralSchemaInterface<T>;
210
231
  };
211
- declare function hookOriginal<Input, Output>(object: SchemaInterface<Input, Output> | SchemaType, method: string, action: (original: Function, ...args: unknown[]) => InternalParseOutput<Output>): void;
232
+ declare function hookOriginal<Input, Output>(object: SchemaInterface<Input, Output> | SchemaType, method: keyof (SchemaInterface<Input, Output> | SchemaType), action: (original: Function, ...args: unknown[]) => InternalParseOutput<Output>): void;
212
233
  /**
213
234
  * Extends the schema system with custom validation methods.
214
235
  * Used to add new methods to schema interfaces like StringSchemaInterface, NumberSchemaInterface, etc.
@@ -267,4 +288,4 @@ declare function extend(callback: ExtenderType): void;
267
288
  */
268
289
  type Infer<T> = T extends SchemaType ? ReturnType<T['parse']> : unknown;
269
290
 
270
- export { type ArraySchemaInterface, type BooleanSchemaInterface, type DateSchemaInterface, type EnumSchemaInterface, type ErrorStructure, type ExtenderType, type Infer, type Invalid, type NumberSchemaInterface, type ObjectSchemaInterface, type SchemaInterface, type SchemaInterfaceOptions, type SchemaType, type StringSchemaInterface, type UnionSchemaInterface, type Valid, extend, hookOriginal, s };
291
+ export { type ArraySchemaInterface, type BooleanSchemaInterface, type DateSchemaInterface, type EnumSchemaInterface, type ErrorStructure, type ExtenderType, type Infer, type Invalid, type LiteralSchemaInterface, type NumberSchemaInterface, type ObjectSchemaInterface, type SchemaInterface, type SchemaInterfaceOptions, type SchemaType, type StringSchemaInterface, type UnionSchemaInterface, type Valid, extend, hookOriginal, s };
package/dist/index.d.ts CHANGED
@@ -30,9 +30,15 @@ interface SchemaInterface<Input, Output> {
30
30
  nullable(): SchemaInterface<Input, Output | null>;
31
31
  nullish(): SchemaInterface<Input, Output | undefined | null>;
32
32
  default(defaultValue: Partial<Input> | (() => Partial<Input>) | Partial<Output>): SchemaInterface<Input, Output>;
33
+ catch(catchValue: Output | ((ctx: {
34
+ input: unknown;
35
+ error: ErrorStructure;
36
+ }) => Output)): SchemaInterface<Input, Output>;
33
37
  pipe<NewOutput>(schema: SchemaInterface<Output, NewOutput>): SchemaInterface<Output, NewOutput>;
34
38
  refine(validation: ValidationMethod<Input, Output>, options?: CreateSchemaInterfaceOptions): SchemaInterface<Input, Output>;
35
39
  }
40
+ interface LiteralSchemaInterface<T extends string | number | boolean> extends SchemaInterface<T, T> {
41
+ }
36
42
  interface UnionSchemaInterface<T extends Array<SchemaInterface<unknown, unknown>>> extends SchemaInterface<ReturnType<T[number]['parse']>, ReturnType<T[number]['parse']>> {
37
43
  }
38
44
  interface EnumSchemaInterface<T extends string> extends SchemaInterface<string, T> {
@@ -53,7 +59,7 @@ interface ObjectSchemaInterface<T extends Record<string, SchemaType>> extends Sc
53
59
  [Property in keyof T]: ReturnType<T[Property]['parse']>;
54
60
  }> {
55
61
  }
56
- type SchemaType = StringSchemaInterface | SchemaInterface<unknown, unknown> | SchemaInterface<string, string> | SchemaInterface<string, string | undefined> | SchemaInterface<string, string | null> | SchemaInterface<string, string | undefined | null> | ObjectSchemaInterface<Record<string, SchemaType>> | SchemaInterface<object, object> | SchemaInterface<object, object | undefined> | SchemaInterface<object, object | null> | SchemaInterface<object, object | undefined | null> | NumberSchemaInterface | SchemaInterface<number, number> | SchemaInterface<number, number | undefined> | SchemaInterface<number, number | null> | SchemaInterface<number, number | undefined | null> | BooleanSchemaInterface | SchemaInterface<boolean, boolean> | SchemaInterface<boolean, boolean | undefined> | SchemaInterface<boolean, boolean | null> | SchemaInterface<boolean, boolean | undefined | null> | DateSchemaInterface | SchemaInterface<Date, Date> | SchemaInterface<Date, Date | undefined> | SchemaInterface<Date, Date | null> | SchemaInterface<Date, Date | undefined | null> | EnumSchemaInterface<string> | UnionSchemaInterface<Array<SchemaInterface<unknown, unknown>>> | ArraySchemaInterface<StringSchemaInterface | ObjectSchemaInterface<Record<string, SchemaType>> | NumberSchemaInterface | BooleanSchemaInterface | DateSchemaInterface | EnumSchemaInterface<string>> | SchemaInterface<Array<unknown>, Array<unknown>> | SchemaInterface<Array<unknown>, Array<unknown> | undefined> | SchemaInterface<Array<unknown>, Array<unknown> | null> | SchemaInterface<Array<unknown>, Array<unknown> | undefined | null>;
62
+ type SchemaType = LiteralSchemaInterface<string> | LiteralSchemaInterface<number> | LiteralSchemaInterface<boolean> | StringSchemaInterface | SchemaInterface<unknown, unknown> | SchemaInterface<string, string> | SchemaInterface<string, string | undefined> | SchemaInterface<string, string | null> | SchemaInterface<string, string | undefined | null> | ObjectSchemaInterface<Record<string, SchemaType>> | SchemaInterface<object, object> | SchemaInterface<object, object | undefined> | SchemaInterface<object, object | null> | SchemaInterface<object, object | undefined | null> | NumberSchemaInterface | SchemaInterface<number, number> | SchemaInterface<number, number | undefined> | SchemaInterface<number, number | null> | SchemaInterface<number, number | undefined | null> | BooleanSchemaInterface | SchemaInterface<boolean, boolean> | SchemaInterface<boolean, boolean | undefined> | SchemaInterface<boolean, boolean | null> | SchemaInterface<boolean, boolean | undefined | null> | DateSchemaInterface | SchemaInterface<Date, Date> | SchemaInterface<Date, Date | undefined> | SchemaInterface<Date, Date | null> | SchemaInterface<Date, Date | undefined | null> | EnumSchemaInterface<string> | UnionSchemaInterface<Array<SchemaInterface<unknown, unknown>>> | ArraySchemaInterface<StringSchemaInterface | ObjectSchemaInterface<Record<string, SchemaType>> | NumberSchemaInterface | BooleanSchemaInterface | DateSchemaInterface | EnumSchemaInterface<string>> | SchemaInterface<Array<unknown>, Array<unknown>> | SchemaInterface<Array<unknown>, Array<unknown> | undefined> | SchemaInterface<Array<unknown>, Array<unknown> | null> | SchemaInterface<Array<unknown>, Array<unknown> | undefined | null>;
57
63
  type ErrorMessage = string | ((value: unknown) => string);
58
64
  type ExtenderType = (inter: SchemaType, validation: Function, options?: {
59
65
  message: ErrorMessage;
@@ -207,8 +213,23 @@ declare const s: {
207
213
  * ```
208
214
  */
209
215
  union<T extends Array<SchemaType>>(definitions: T, options?: SchemaInterfaceOptions): UnionSchemaInterface<T>;
216
+ /**
217
+ * Creates a literal schema that only accepts a specific value.
218
+ *
219
+ * @param value - The exact value to match
220
+ * @param options - Optional configuration
221
+ * @returns Literal schema interface
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * const adminSchema = s.literal('admin');
226
+ * adminSchema.parse('admin'); // 'admin'
227
+ * adminSchema.parse('user'); // throws error
228
+ * ```
229
+ */
230
+ literal<T extends string | number | boolean>(value: T, options?: SchemaInterfaceOptions): LiteralSchemaInterface<T>;
210
231
  };
211
- declare function hookOriginal<Input, Output>(object: SchemaInterface<Input, Output> | SchemaType, method: string, action: (original: Function, ...args: unknown[]) => InternalParseOutput<Output>): void;
232
+ declare function hookOriginal<Input, Output>(object: SchemaInterface<Input, Output> | SchemaType, method: keyof (SchemaInterface<Input, Output> | SchemaType), action: (original: Function, ...args: unknown[]) => InternalParseOutput<Output>): void;
212
233
  /**
213
234
  * Extends the schema system with custom validation methods.
214
235
  * Used to add new methods to schema interfaces like StringSchemaInterface, NumberSchemaInterface, etc.
@@ -267,4 +288,4 @@ declare function extend(callback: ExtenderType): void;
267
288
  */
268
289
  type Infer<T> = T extends SchemaType ? ReturnType<T['parse']> : unknown;
269
290
 
270
- export { type ArraySchemaInterface, type BooleanSchemaInterface, type DateSchemaInterface, type EnumSchemaInterface, type ErrorStructure, type ExtenderType, type Infer, type Invalid, type NumberSchemaInterface, type ObjectSchemaInterface, type SchemaInterface, type SchemaInterfaceOptions, type SchemaType, type StringSchemaInterface, type UnionSchemaInterface, type Valid, extend, hookOriginal, s };
291
+ export { type ArraySchemaInterface, type BooleanSchemaInterface, type DateSchemaInterface, type EnumSchemaInterface, type ErrorStructure, type ExtenderType, type Infer, type Invalid, type LiteralSchemaInterface, type NumberSchemaInterface, type ObjectSchemaInterface, type SchemaInterface, type SchemaInterfaceOptions, type SchemaType, type StringSchemaInterface, type UnionSchemaInterface, type Valid, extend, hookOriginal, s };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export{c as extend,b as hookOriginal,a as s}from'./chunk-NCHMO7B3.mjs';
1
+ export{c as extend,b as hookOriginal,a as s}from'./chunk-2NCXW7ID.mjs';
package/dist/number.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var P={abortEarly:true};function S(e,o){if(!o)return e;let i=e?.cause?.key?`${o}.${e.cause.key}`:`${o}`;return {message:`Error parsing key "${i}": ${e.message}`,cause:{key:i}}}function g(e,o,i){!e.errors||e.errors.length===0||e.errors.forEach(u=>{let c=S(u,i);o.push(c);});}function d(e){return {...P,...e}}var N=e=>typeof e=="string"||e instanceof String,k=e=>typeof e=="number"||e instanceof Number,w=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),O=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),A={object(e,o){let i=I(O,{...o,type:"object"});return i._getDescription=()=>`object({ ${Object.entries(e).map(([c,r])=>`${c}: ${r._getDescription()}`).join(", ")} })`,h(i,"_parse",(u,c,r)=>{let t=u(c,r),{abortEarly:n}=d(r);if(t.success===false)return t;let s={},a=[];for(let p in e){let f=e[p]._parse(t.data[p],r);if(f.success)s[p]=f.data;else {if(f=f,n!==false){let m=S(f.error,p);return {success:false,error:m,errors:[m]}}g(f,a,p);}}return a.length>0?{success:false,error:a[0],errors:a}:{success:true,data:s}}),i},string(e){return I(N,{...e,type:"string"})},number(e){return I(k,{...e,type:"number"})},boolean(e){return I(w,{...e,type:"boolean"})},date(e){return I(E,{...e,type:"date"})},enum(e,o){let i=t=>e.includes(t),u=t=>`Invalid ${c} value. Expected ${e.map(n=>`"${n}"`).join(" | ")}, received "${t}".`,c="enum",r=I(i,{message:u,...o,type:c});return r._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,r},array(e,o){let i=I(_,{...o,type:"array"});return i._getDescription=()=>`array(${e._getDescription()})`,h(i,"_parse",(u,c,r)=>{let t=u(c,r),{abortEarly:n}=d(r);if(t.success===false)return t;let s=[],a=[];for(let p=0;p<t.data.length;p++){let f=e._parse(t.data[p],r);if(f.success)s.push(f.data);else {if(f=f,n!==false){let m=S(f.error,p);return {success:false,error:m,errors:[m]}}g(f,a,p);}}return a.length>0?{success:false,error:a[0],errors:a}:{success:true,data:s}}),i},any(){return I(()=>true)},preprocess(e,o){return h(o,"_parse",(i,u)=>(u=e(u),i(u))),o},union(e,o){return I(r=>{for(let t=0;t<e.length;t++){let n=e[t]._parse(r);if(n.success)return n}return false},{message:r=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,n)=>` ${n+1}. ${t._getDescription()}`).join(",")} but received "${typeof r}" with value: ${O(r)?JSON.stringify(r):`"${r}"`}`,...o,type:"union"})}};function T(e){return o=>`The value "${o}" must be type of ${e} but is type of "${typeof o}".`}function h(e,o,i){let u=e[o];e[o]=(...c)=>i(u,...c);}function I(e,{type:o="any",name:i,message:u}={}){u=u||T(o);let c={name:i,message:u,type:o},r={_getName(){return i},_getType(){return o},_getDescription(){return this._getName()??this._getType()},_parse(t,n){let s=e(t);if(s===true)return {success:true,data:t};if(typeof s=="object"&&s?.success===true)return s;let a={message:typeof u=="function"?u(t):u};return {success:false,error:a,errors:[a]}},parse(t,n){let s=r._parse(t,n);if(!s.success)throw s=s,new Error(s.error.message,{cause:s.error.cause});return s.data},safeParse(t,n){return r._parse(t,n)},transform(t){return h(this,"_parse",(n,s,a)=>{let p=n(s,a);return p.success&&(p.data=t(p.data)),p}),this},optional(){return h(this,"_parse",(t,n,s)=>{let a=t(n,s);return !a.success&&n===void 0&&(a.data=void 0,a.success=true),a}),this},nullable(){return h(this,"_parse",(t,n,s)=>{let a=t(n,s);return !a.success&&n===null&&(a.data=null,a.success=true),a}),this},nullish(){return h(this,"_parse",(t,n,s)=>{let a=t(n,s);return !a.success&&n==null&&(a.success=true,a.data=n),a}),this},default(t){return h(this,"_parse",(n,s,a)=>(s===void 0&&(s=t,s=typeof t=="function"?t():t),n(s,a))),this},pipe(t){return h(this,"_parse",(n,s,a)=>{let p=n(s,a);return p.success?t._parse(p.data,a):p}),this},refine(t,{message:n,type:s}={}){return s&&(n=n||T(s),o=s),h(this,"_parse",(a,p,f)=>{let m=a(p,f);d(f);if(!m.success)return m;let l=t(m.data);if(l===true||typeof l=="object"&&l?.success===true)return m;let b={message:typeof n=="function"?n(p):n};return {success:false,error:b,errors:[b]}}),this}};return y.length>0?y.reduce((t,n)=>n(t,e,c)??t,r):r}var y=[];function x(e){y.push(e);}x((e,o,i)=>{if(i?.type==="number"){let u=e;u.min=function(c,{message:r}={}){return this.refine(t=>t>=c,{message:r||`Number must be greater than or equal to ${c}.`})},u.max=function(c,{message:r}={}){return this.refine(t=>t<=c,{message:r||`Number must be less than or equal to ${c}.`})},u.positive=function({message:c}={}){return this.refine(r=>r>0,{message:c||"Number must be positive."})},u.negative=function({message:c}={}){return this.refine(r=>r<0,{message:c||"Number must be negative."})},u.int=function({message:c}={}){return this.refine(r=>Number.isInteger(r),{message:c||"Number must be an integer."})},u.float=function({message:c}={}){return this.refine(r=>Number.isFinite(r)&&!Number.isInteger(r),{message:c||"Number must be a floating point (non-integer)."})},u.multipleOf=function(c,{message:r}={}){return this.refine(t=>t%c===0,{message:r||`Number must be a multiple of ${c}.`})},u.finite=function({message:c}={}){return this.refine(r=>Number.isFinite(r),{message:c||"Number must be finite."})};}return e});exports.extend=x;exports.hookOriginal=h;exports.s=A;
1
+ 'use strict';var k={abortEarly:true};function S(e,u){if(!u)return e;let p=e?.cause?.key?`${u}.${e.cause.key}`:`${u}`;return {message:`Error parsing key "${p}": ${e.message}`,cause:{key:p}}}function g(e,u,p){if(e.errors?.length)for(let o=0;o<e.errors.length;o++)u.push(S(e.errors[o],p));}function d(e){return {...k,...e}}var w=e=>typeof e=="string"||e instanceof String,P=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),N=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),O=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),R={object(e,u){let p=l(O,{...u,type:"object"});return p._getDescription=()=>`object({ ${Object.entries(e).map(([c,n])=>`${c}: ${n._getDescription()}`).join(", ")} })`,m(p,"_parse",(o,c,n)=>{let t=o(c,n),{abortEarly:r}=d(n);if(t.success===false)return t;let s={},a=[];for(let i in e){let f=e[i]._parse(t.data[i],n);if(f.success)s[i]=f.data;else {if(f=f,r!==false){let h=S(f.error,i);return {success:false,error:h,errors:[h]}}g(f,a,i);}}return a.length>0?{success:false,error:a[0],errors:a}:{success:true,data:s}}),p},string(e){return l(w,{...e,type:"string"})},number(e){return l(P,{...e,type:"number"})},boolean(e){return l(N,{...e,type:"boolean"})},date(e){return l(E,{...e,type:"date"})},enum(e,u){let p=t=>e.includes(t),o=t=>`Invalid ${c} value. Expected ${e.map(r=>`"${r}"`).join(" | ")}, received "${t}".`,c="enum",n=l(p,{message:o,...u,type:c});return n._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,n},array(e,u){let p=l(_,{...u,type:"array"});return p._getDescription=()=>`array(${e._getDescription()})`,m(p,"_parse",(o,c,n)=>{let t=o(c,n),{abortEarly:r}=d(n);if(t.success===false)return t;let s=[],a=[];for(let i=0;i<t.data.length;i++){let f=e._parse(t.data[i],n);if(f.success)s.push(f.data);else {if(f=f,r!==false){let h=S(f.error,i);return {success:false,error:h,errors:[h]}}g(f,a,i);}}return a.length>0?{success:false,error:a[0],errors:a}:{success:true,data:s}}),p},any(){return l(()=>true)},preprocess(e,u){return m(u,"_parse",(p,o)=>(o=e(o),p(o))),u},union(e,u){return l(n=>{for(let t=0;t<e.length;t++){let r=e[t]._parse(n);if(r.success)return r}return false},{message:n=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,r)=>` ${r+1}. ${t._getDescription()}`).join(",")} but received "${typeof n}" with value: ${O(n)?JSON.stringify(n):`"${n}"`}`,...u,type:"union"})},literal(e,u){let c=l(n=>n===e,{message:n=>u?.message?typeof u.message=="function"?u.message(n):u.message:`Expected literal value "${e}", received "${n}"`,name:u?.name,type:"literal"});return c._getDescription=()=>`literal("${e}")`,c}};function T(e){return u=>`The value "${u}" must be type of ${e} but is type of "${typeof u}".`}function m(e,u,p){let o=e[u];e[u]=(...c)=>p(o,...c);}function l(e,{type:u="any",name:p,message:o}={}){o=o||T(u);let c={name:p,message:o,type:u},n={_getName(){return p},_getType(){return u},_getDescription(){return this._getName()??this._getType()},_parse(t,r){let s=e(t);if(s===true)return {success:true,data:t};if(typeof s=="object"&&s?.success===true)return s;let a={message:typeof o=="function"?o(t):o};return {success:false,error:a,errors:[a]}},parse(t,r){let s=n._parse(t,r);if(!s.success)throw s=s,new Error(s.error.message,{cause:s.error.cause});return s.data},safeParse(t,r){return n._parse(t,r)},transform(t){return m(this,"_parse",(r,s,a)=>{let i=r(s,a);return i.success&&(i.data=t(i.data)),i}),this},optional(){return m(this,"_parse",(t,r,s)=>{let a=t(r,s);return !a.success&&r===void 0&&(a.data=void 0,a.success=true),a}),this},nullable(){return m(this,"_parse",(t,r,s)=>{let a=t(r,s);return !a.success&&r===null&&(a.data=null,a.success=true),a}),this},nullish(){return m(this,"_parse",(t,r,s)=>{let a=t(r,s);return !a.success&&r==null&&(a.success=true,a.data=r),a}),this},default(t){return m(this,"_parse",(r,s,a)=>(s===void 0&&(s=typeof t=="function"?t():t),r(s,a))),this},catch(t){return m(this,"_parse",(r,s,a)=>{let i=r(s,a);return i.success?i:{success:true,data:typeof t=="function"?t({input:s,error:i.error}):t}}),this},pipe(t){return m(this,"_parse",(r,s,a)=>{let i=r(s,a);return i.success?t._parse(i.data,a):i}),this},refine(t,{message:r,type:s}={}){return s&&(r=r||T(s),u=s),m(this,"_parse",(a,i,f)=>{let h=a(i,f);d(f);if(!h.success)return h;let I=t(h.data);if(I===true||typeof I=="object"&&I?.success===true)return h;let b={message:typeof r=="function"?r(i):r};return {success:false,error:b,errors:[b]}}),this}};return y.length>0?y.reduce((t,r)=>r(t,e,c)??t,n):n}var y=[];function x(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");y.push(e);}x((e,u,p)=>{if(p?.type==="number"){let o=e;o.min=function(c,{message:n}={}){return this.refine(t=>t>=c,{message:n||`Number must be greater than or equal to ${c}.`})},o.max=function(c,{message:n}={}){return this.refine(t=>t<=c,{message:n||`Number must be less than or equal to ${c}.`})},o.positive=function({message:c}={}){return this.refine(n=>n>0,{message:c||"Number must be positive."})},o.negative=function({message:c}={}){return this.refine(n=>n<0,{message:c||"Number must be negative."})},o.int=function({message:c}={}){return this.refine(n=>Number.isInteger(n),{message:c||"Number must be an integer."})},o.float=function({message:c}={}){return this.refine(n=>Number.isFinite(n)&&!Number.isInteger(n),{message:c||"Number must be a floating point (non-integer)."})},o.multipleOf=function(c,{message:n}={}){return this.refine(t=>t%c===0,{message:n||`Number must be a multiple of ${c}.`})},o.finite=function({message:c}={}){return this.refine(n=>Number.isFinite(n),{message:c||"Number must be finite."})};}return e});exports.extend=x;exports.hookOriginal=m;exports.s=R;
package/dist/number.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.mjs';
1
+ export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.mjs';
2
2
 
3
3
  declare module './index.ts' {
4
4
  interface NumberSchemaInterface {
package/dist/number.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.js';
1
+ export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.js';
2
2
 
3
3
  declare module './index.ts' {
4
4
  interface NumberSchemaInterface {
package/dist/number.mjs CHANGED
@@ -1 +1 @@
1
- import'./chunk-SHVCROKM.mjs';export{c as extend,b as hookOriginal,a as s}from'./chunk-NCHMO7B3.mjs';
1
+ import'./chunk-PH4B25KI.mjs';export{c as extend,b as hookOriginal,a as s}from'./chunk-2NCXW7ID.mjs';
package/dist/string.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var P={abortEarly:true};function I(t,o){if(!o)return t;let i=t?.cause?.key?`${o}.${t.cause.key}`:`${o}`;return {message:`Error parsing key "${i}": ${t.message}`,cause:{key:i}}}function O(t,o,i){!t.errors||t.errors.length===0||t.errors.forEach(c=>{let r=I(c,i);o.push(r);});}function d(t){return {...P,...t}}var k=t=>typeof t=="string"||t instanceof String,w=t=>typeof t=="number"||t instanceof Number,E=t=>t===true||t===false,$=t=>t instanceof Date&&!Number.isNaN(t.getTime()),_=t=>Array.isArray(t),b=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),A={object(t,o){let i=S(b,{...o,type:"object"});return i._getDescription=()=>`object({ ${Object.entries(t).map(([r,n])=>`${r}: ${n._getDescription()}`).join(", ")} })`,h(i,"_parse",(c,r,n)=>{let e=c(r,n),{abortEarly:a}=d(n);if(e.success===false)return e;let u={},s=[];for(let p in t){let f=t[p]._parse(e.data[p],n);if(f.success)u[p]=f.data;else {if(f=f,a!==false){let m=I(f.error,p);return {success:false,error:m,errors:[m]}}O(f,s,p);}}return s.length>0?{success:false,error:s[0],errors:s}:{success:true,data:u}}),i},string(t){return S(k,{...t,type:"string"})},number(t){return S(w,{...t,type:"number"})},boolean(t){return S(E,{...t,type:"boolean"})},date(t){return S($,{...t,type:"date"})},enum(t,o){let i=e=>t.includes(e),c=e=>`Invalid ${r} value. Expected ${t.map(a=>`"${a}"`).join(" | ")}, received "${e}".`,r="enum",n=S(i,{message:c,...o,type:r});return n._getDescription=()=>`enum(${t.map(e=>`"${e}"`).join(" | ")})`,n},array(t,o){let i=S(_,{...o,type:"array"});return i._getDescription=()=>`array(${t._getDescription()})`,h(i,"_parse",(c,r,n)=>{let e=c(r,n),{abortEarly:a}=d(n);if(e.success===false)return e;let u=[],s=[];for(let p=0;p<e.data.length;p++){let f=t._parse(e.data[p],n);if(f.success)u.push(f.data);else {if(f=f,a!==false){let m=I(f.error,p);return {success:false,error:m,errors:[m]}}O(f,s,p);}}return s.length>0?{success:false,error:s[0],errors:s}:{success:true,data:u}}),i},any(){return S(()=>true)},preprocess(t,o){return h(o,"_parse",(i,c)=>(c=t(c),i(c))),o},union(t,o){return S(n=>{for(let e=0;e<t.length;e++){let a=t[e]._parse(n);if(a.success)return a}return false},{message:n=>`Invalid union value. Expected the value to match one of the schemas:${t.map((e,a)=>` ${a+1}. ${e._getDescription()}`).join(",")} but received "${typeof n}" with value: ${b(n)?JSON.stringify(n):`"${n}"`}`,...o,type:"union"})}};function T(t){return o=>`The value "${o}" must be type of ${t} but is type of "${typeof o}".`}function h(t,o,i){let c=t[o];t[o]=(...r)=>i(c,...r);}function S(t,{type:o="any",name:i,message:c}={}){c=c||T(o);let r={name:i,message:c,type:o},n={_getName(){return i},_getType(){return o},_getDescription(){return this._getName()??this._getType()},_parse(e,a){let u=t(e);if(u===true)return {success:true,data:e};if(typeof u=="object"&&u?.success===true)return u;let s={message:typeof c=="function"?c(e):c};return {success:false,error:s,errors:[s]}},parse(e,a){let u=n._parse(e,a);if(!u.success)throw u=u,new Error(u.error.message,{cause:u.error.cause});return u.data},safeParse(e,a){return n._parse(e,a)},transform(e){return h(this,"_parse",(a,u,s)=>{let p=a(u,s);return p.success&&(p.data=e(p.data)),p}),this},optional(){return h(this,"_parse",(e,a,u)=>{let s=e(a,u);return !s.success&&a===void 0&&(s.data=void 0,s.success=true),s}),this},nullable(){return h(this,"_parse",(e,a,u)=>{let s=e(a,u);return !s.success&&a===null&&(s.data=null,s.success=true),s}),this},nullish(){return h(this,"_parse",(e,a,u)=>{let s=e(a,u);return !s.success&&a==null&&(s.success=true,s.data=a),s}),this},default(e){return h(this,"_parse",(a,u,s)=>(u===void 0&&(u=e,u=typeof e=="function"?e():e),a(u,s))),this},pipe(e){return h(this,"_parse",(a,u,s)=>{let p=a(u,s);return p.success?e._parse(p.data,s):p}),this},refine(e,{message:a,type:u}={}){return u&&(a=a||T(u),o=u),h(this,"_parse",(s,p,f)=>{let m=s(p,f);d(f);if(!m.success)return m;let l=e(m.data);if(l===true||typeof l=="object"&&l?.success===true)return m;let g={message:typeof a=="function"?a(p):a};return {success:false,error:g,errors:[g]}}),this}};return y.length>0?y.reduce((e,a)=>a(e,t,r)??e,n):n}var y=[];function x(t){y.push(t);}x((t,o,i)=>{if(i?.type==="string"){let c=t;c.min=function(r,{message:n}={}){return this.refine(e=>e.length>=r,{message:n||(e=>`String must be at least ${r} characters long (received ${e.length} characters: "${e}")`)})},c.max=function(r,{message:n}={}){return this.refine(e=>e.length<=r,{message:n||(e=>`String must be at most ${r} characters long (received ${e.length} characters: "${e}")`)})},c.length=function(r,{message:n}={}){return this.refine(e=>e.length===r,{message:n||(e=>`String must be exactly ${r} characters long (received ${e.length} characters: "${e}")`)})},c.nonEmpty=function({message:r}={}){return this.refine(n=>n.length>0,{message:r||"String must not be empty (received empty string)"})},c.startsWith=function(r,{message:n}={}){return this.refine(e=>e.startsWith(r),{message:n||(e=>`String must start with "${r}" (received: "${e}")`)})},c.endsWith=function(r,{message:n}={}){return this.refine(e=>e.endsWith(r),{message:n||(e=>`String must end with "${r}" (received: "${e}")`)})},c.includes=function(r,{message:n}={}){return this.refine(e=>e.includes(r),{message:n||(e=>`String must include "${r}" (received: "${e}")`)})},c.toLowerCase=function(){return this.transform(r=>r.toLowerCase())},c.toUpperCase=function(){return this.transform(r=>r.toUpperCase())},c.trim=function(){return this.transform(r=>r.trim())},c.padStart=function(r,n=" "){return this.transform(e=>e.padStart(r,n))},c.padEnd=function(r,n=" "){return this.transform(e=>e.padEnd(r,n))},c.replace=function(r,n){return this.transform(e=>e.replace(r,n))};}return t});exports.extend=x;exports.hookOriginal=h;exports.s=A;
1
+ 'use strict';var k={abortEarly:true};function I(t,o){if(!o)return t;let p=t?.cause?.key?`${o}.${t.cause.key}`:`${o}`;return {message:`Error parsing key "${p}": ${t.message}`,cause:{key:p}}}function O(t,o,p){if(t.errors?.length)for(let s=0;s<t.errors.length;s++)o.push(I(t.errors[s],p));}function d(t){return {...k,...t}}var w=t=>typeof t=="string"||t instanceof String,P=t=>(typeof t=="number"||t instanceof Number)&&!Number.isNaN(t),E=t=>t===true||t===false,$=t=>t instanceof Date&&!Number.isNaN(t.getTime()),_=t=>Array.isArray(t),b=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),A={object(t,o){let p=l(b,{...o,type:"object"});return p._getDescription=()=>`object({ ${Object.entries(t).map(([r,n])=>`${r}: ${n._getDescription()}`).join(", ")} })`,m(p,"_parse",(s,r,n)=>{let e=s(r,n),{abortEarly:a}=d(n);if(e.success===false)return e;let u={},c=[];for(let i in t){let f=t[i]._parse(e.data[i],n);if(f.success)u[i]=f.data;else {if(f=f,a!==false){let h=I(f.error,i);return {success:false,error:h,errors:[h]}}O(f,c,i);}}return c.length>0?{success:false,error:c[0],errors:c}:{success:true,data:u}}),p},string(t){return l(w,{...t,type:"string"})},number(t){return l(P,{...t,type:"number"})},boolean(t){return l(E,{...t,type:"boolean"})},date(t){return l($,{...t,type:"date"})},enum(t,o){let p=e=>t.includes(e),s=e=>`Invalid ${r} value. Expected ${t.map(a=>`"${a}"`).join(" | ")}, received "${e}".`,r="enum",n=l(p,{message:s,...o,type:r});return n._getDescription=()=>`enum(${t.map(e=>`"${e}"`).join(" | ")})`,n},array(t,o){let p=l(_,{...o,type:"array"});return p._getDescription=()=>`array(${t._getDescription()})`,m(p,"_parse",(s,r,n)=>{let e=s(r,n),{abortEarly:a}=d(n);if(e.success===false)return e;let u=[],c=[];for(let i=0;i<e.data.length;i++){let f=t._parse(e.data[i],n);if(f.success)u.push(f.data);else {if(f=f,a!==false){let h=I(f.error,i);return {success:false,error:h,errors:[h]}}O(f,c,i);}}return c.length>0?{success:false,error:c[0],errors:c}:{success:true,data:u}}),p},any(){return l(()=>true)},preprocess(t,o){return m(o,"_parse",(p,s)=>(s=t(s),p(s))),o},union(t,o){return l(n=>{for(let e=0;e<t.length;e++){let a=t[e]._parse(n);if(a.success)return a}return false},{message:n=>`Invalid union value. Expected the value to match one of the schemas:${t.map((e,a)=>` ${a+1}. ${e._getDescription()}`).join(",")} but received "${typeof n}" with value: ${b(n)?JSON.stringify(n):`"${n}"`}`,...o,type:"union"})},literal(t,o){let r=l(n=>n===t,{message:n=>o?.message?typeof o.message=="function"?o.message(n):o.message:`Expected literal value "${t}", received "${n}"`,name:o?.name,type:"literal"});return r._getDescription=()=>`literal("${t}")`,r}};function T(t){return o=>`The value "${o}" must be type of ${t} but is type of "${typeof o}".`}function m(t,o,p){let s=t[o];t[o]=(...r)=>p(s,...r);}function l(t,{type:o="any",name:p,message:s}={}){s=s||T(o);let r={name:p,message:s,type:o},n={_getName(){return p},_getType(){return o},_getDescription(){return this._getName()??this._getType()},_parse(e,a){let u=t(e);if(u===true)return {success:true,data:e};if(typeof u=="object"&&u?.success===true)return u;let c={message:typeof s=="function"?s(e):s};return {success:false,error:c,errors:[c]}},parse(e,a){let u=n._parse(e,a);if(!u.success)throw u=u,new Error(u.error.message,{cause:u.error.cause});return u.data},safeParse(e,a){return n._parse(e,a)},transform(e){return m(this,"_parse",(a,u,c)=>{let i=a(u,c);return i.success&&(i.data=e(i.data)),i}),this},optional(){return m(this,"_parse",(e,a,u)=>{let c=e(a,u);return !c.success&&a===void 0&&(c.data=void 0,c.success=true),c}),this},nullable(){return m(this,"_parse",(e,a,u)=>{let c=e(a,u);return !c.success&&a===null&&(c.data=null,c.success=true),c}),this},nullish(){return m(this,"_parse",(e,a,u)=>{let c=e(a,u);return !c.success&&a==null&&(c.success=true,c.data=a),c}),this},default(e){return m(this,"_parse",(a,u,c)=>(u===void 0&&(u=typeof e=="function"?e():e),a(u,c))),this},catch(e){return m(this,"_parse",(a,u,c)=>{let i=a(u,c);return i.success?i:{success:true,data:typeof e=="function"?e({input:u,error:i.error}):e}}),this},pipe(e){return m(this,"_parse",(a,u,c)=>{let i=a(u,c);return i.success?e._parse(i.data,c):i}),this},refine(e,{message:a,type:u}={}){return u&&(a=a||T(u),o=u),m(this,"_parse",(c,i,f)=>{let h=c(i,f);d(f);if(!h.success)return h;let S=e(h.data);if(S===true||typeof S=="object"&&S?.success===true)return h;let y={message:typeof a=="function"?a(i):a};return {success:false,error:y,errors:[y]}}),this}};return g.length>0?g.reduce((e,a)=>a(e,t,r)??e,n):n}var g=[];function x(t){if(typeof t!="function")throw new TypeError("extend() requires a function argument");g.push(t);}x((t,o,p)=>{if(p?.type==="string"){let s=t;s.min=function(r,{message:n}={}){return this.refine(e=>e.length>=r,{message:n||(e=>`String must be at least ${r} characters long (received ${e.length} characters: "${e}")`)})},s.max=function(r,{message:n}={}){return this.refine(e=>e.length<=r,{message:n||(e=>`String must be at most ${r} characters long (received ${e.length} characters: "${e}")`)})},s.length=function(r,{message:n}={}){return this.refine(e=>e.length===r,{message:n||(e=>`String must be exactly ${r} characters long (received ${e.length} characters: "${e}")`)})},s.nonEmpty=function({message:r}={}){return this.refine(n=>n.length>0,{message:r||"String must not be empty (received empty string)"})},s.startsWith=function(r,{message:n}={}){return this.refine(e=>e.startsWith(r),{message:n||(e=>`String must start with "${r}" (received: "${e}")`)})},s.endsWith=function(r,{message:n}={}){return this.refine(e=>e.endsWith(r),{message:n||(e=>`String must end with "${r}" (received: "${e}")`)})},s.includes=function(r,{message:n}={}){return this.refine(e=>e.includes(r),{message:n||(e=>`String must include "${r}" (received: "${e}")`)})},s.toLowerCase=function(){return this.transform(r=>r.toLowerCase())},s.toUpperCase=function(){return this.transform(r=>r.toUpperCase())},s.trim=function(){return this.transform(r=>r.trim())},s.padStart=function(r,n=" "){return this.transform(e=>e.padStart(r,n))},s.padEnd=function(r,n=" "){return this.transform(e=>e.padEnd(r,n))},s.replace=function(r,n){return this.transform(e=>e.replace(r,n))};}return t});exports.extend=x;exports.hookOriginal=m;exports.s=A;
package/dist/string.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.mjs';
1
+ export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.mjs';
2
2
 
3
3
  declare module './index.ts' {
4
4
  interface StringSchemaInterface {
package/dist/string.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.js';
1
+ export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s } from './index.js';
2
2
 
3
3
  declare module './index.ts' {
4
4
  interface StringSchemaInterface {
package/dist/string.mjs CHANGED
@@ -1 +1 @@
1
- import'./chunk-BV6SWQSH.mjs';export{c as extend,b as hookOriginal,a as s}from'./chunk-NCHMO7B3.mjs';
1
+ import'./chunk-LZRUIXQL.mjs';export{c as extend,b as hookOriginal,a as s}from'./chunk-2NCXW7ID.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esmj/schema",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Tiny extendable package for schema validation.",
5
5
  "keywords": [
6
6
  "schema",
@@ -1 +0,0 @@
1
- var P={abortEarly:true};function d(e,s){if(!s)return e;let o=e?.cause?.key?`${s}.${e.cause.key}`:`${s}`;return {message:`Error parsing key "${o}": ${e.message}`,cause:{key:o}}}function b(e,s,o){!e.errors||e.errors.length===0||e.errors.forEach(i=>{let f=d(i,o);s.push(f);});}function y(e){return {...P,...e}}var x=e=>typeof e=="string"||e instanceof String,k=e=>typeof e=="number"||e instanceof Number,w=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),g=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),R={object(e,s){let o=l(g,{...s,type:"object"});return o._getDescription=()=>`object({ ${Object.entries(e).map(([f,c])=>`${f}: ${c._getDescription()}`).join(", ")} })`,h(o,"_parse",(i,f,c)=>{let t=i(f,c),{abortEarly:r}=y(c);if(t.success===false)return t;let a={},n=[];for(let u in e){let p=e[u]._parse(t.data[u],c);if(p.success)a[u]=p.data;else {if(p=p,r!==false){let m=d(p.error,u);return {success:false,error:m,errors:[m]}}b(p,n,u);}}return n.length>0?{success:false,error:n[0],errors:n}:{success:true,data:a}}),o},string(e){return l(x,{...e,type:"string"})},number(e){return l(k,{...e,type:"number"})},boolean(e){return l(w,{...e,type:"boolean"})},date(e){return l(E,{...e,type:"date"})},enum(e,s){let o=t=>e.includes(t),i=t=>`Invalid ${f} value. Expected ${e.map(r=>`"${r}"`).join(" | ")}, received "${t}".`,f="enum",c=l(o,{message:i,...s,type:f});return c._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,c},array(e,s){let o=l(_,{...s,type:"array"});return o._getDescription=()=>`array(${e._getDescription()})`,h(o,"_parse",(i,f,c)=>{let t=i(f,c),{abortEarly:r}=y(c);if(t.success===false)return t;let a=[],n=[];for(let u=0;u<t.data.length;u++){let p=e._parse(t.data[u],c);if(p.success)a.push(p.data);else {if(p=p,r!==false){let m=d(p.error,u);return {success:false,error:m,errors:[m]}}b(p,n,u);}}return n.length>0?{success:false,error:n[0],errors:n}:{success:true,data:a}}),o},any(){return l(()=>true)},preprocess(e,s){return h(s,"_parse",(o,i)=>(i=e(i),o(i))),s},union(e,s){return l(c=>{for(let t=0;t<e.length;t++){let r=e[t]._parse(c);if(r.success)return r}return false},{message:c=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,r)=>` ${r+1}. ${t._getDescription()}`).join(",")} but received "${typeof c}" with value: ${g(c)?JSON.stringify(c):`"${c}"`}`,...s,type:"union"})}};function O(e){return s=>`The value "${s}" must be type of ${e} but is type of "${typeof s}".`}function h(e,s,o){let i=e[s];e[s]=(...f)=>o(i,...f);}function l(e,{type:s="any",name:o,message:i}={}){i=i||O(s);let f={name:o,message:i,type:s},c={_getName(){return o},_getType(){return s},_getDescription(){return this._getName()??this._getType()},_parse(t,r){let a=e(t);if(a===true)return {success:true,data:t};if(typeof a=="object"&&a?.success===true)return a;let n={message:typeof i=="function"?i(t):i};return {success:false,error:n,errors:[n]}},parse(t,r){let a=c._parse(t,r);if(!a.success)throw a=a,new Error(a.error.message,{cause:a.error.cause});return a.data},safeParse(t,r){return c._parse(t,r)},transform(t){return h(this,"_parse",(r,a,n)=>{let u=r(a,n);return u.success&&(u.data=t(u.data)),u}),this},optional(){return h(this,"_parse",(t,r,a)=>{let n=t(r,a);return !n.success&&r===void 0&&(n.data=void 0,n.success=true),n}),this},nullable(){return h(this,"_parse",(t,r,a)=>{let n=t(r,a);return !n.success&&r===null&&(n.data=null,n.success=true),n}),this},nullish(){return h(this,"_parse",(t,r,a)=>{let n=t(r,a);return !n.success&&r==null&&(n.success=true,n.data=r),n}),this},default(t){return h(this,"_parse",(r,a,n)=>(a===void 0&&(a=t,a=typeof t=="function"?t():t),r(a,n))),this},pipe(t){return h(this,"_parse",(r,a,n)=>{let u=r(a,n);return u.success?t._parse(u.data,n):u}),this},refine(t,{message:r,type:a}={}){return a&&(r=r||O(a),s=a),h(this,"_parse",(n,u,p)=>{let m=n(u,p);y(p);if(!m.success)return m;let I=t(m.data);if(I===true||typeof I=="object"&&I?.success===true)return m;let T={message:typeof r=="function"?r(u):r};return {success:false,error:T,errors:[T]}}),this}};return S.length>0?S.reduce((t,r)=>r(t,e,f)??t,c):c}var S=[];function $(e){S.push(e);}export{R as a,h as b,$ as c};