@esmj/schema 0.7.2 → 0.7.4

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
@@ -15,6 +15,7 @@ This small library provides a simple schema validation system for JavaScript/Typ
15
15
  - [Number Extensions](#number-extensions-esmjschemanumber)
16
16
  - [Array Extensions](#array-extensions-esmjschemaarray)
17
17
  - [Full Extensions](#full-extensions-esmjschemafull)
18
+ - [Named Exports & Tree-Shaking](#named-exports--tree-shaking)
18
19
  - [API Reference Summary](#api-reference-summary)
19
20
  - [Schema Types](#schema-types)
20
21
  - [s.coerce](#scoerce)
@@ -107,11 +108,13 @@ const result = schema.parse({
107
108
 
108
109
  ### Performance Highlights
109
110
 
110
- - **Schema Creation**: Create schemas at up to 4 370 618 ops/s (0.23 μs latency) with @sinclair/typebox, or 736 810 ops/s (1.36 μs latency) with @esmj/schema. Superstruct and @esmj/schema are also among the fastest for schema creation.
111
- - **Parsing**: Parse data at up to 4 627 714 ops/s (0.22 μs latency) with @zod/mini (note: @zod/mini was observed to consume 200% CPU, while other libraries used only 100% CPU), or 3 142 587 ops/s (0.32 μs latency) with @esmj/schema. ArkType and effect/Schema also show strong parsing throughput.
112
- - **Error Handling**: Efficiently manage errors at up to 2 428 049 ops/s (0.41 μs latency) with @esmj/schema, or 1 386 616 ops/s (0.72 μs latency) with @zod/mini.
111
+ - **Schema Creation**: Create schemas at up to 4,370,618 ops/s (0.23 μs latency) with @sinclair/typebox, or 736,810 ops/s (1.36 μs latency) with @esmj/schema. Superstruct is also competitive for schema creation performance.
112
+ - **Parsing**: Parse data at up to **33,620,146 ops/s** (**0.03 μs** latency) with **AJV** (best result in this benchmark). For comparison, `@zod/mini` reached **4,627,714 ops/s** (**0.22 μs**, observed at 200% CPU), and `@esmj/schema` reached **3,142,587 ops/s** (**0.32 μs**), with ArkType and effect/Schema also performing strongly.
113
+ - **Error Handling**: Handle validation errors at up to **19,693,821 ops/s** (**0.05 μs** latency) with **AJV** (best result in this benchmark), while `@esmj/schema` delivered **2,428,049 ops/s** (**0.41 μs**) with a developer-friendly API.
113
114
 
114
- These performance metrics make `@esmj/schema` an excellent choice for both frontend and backend applications where speed and efficiency are critical.
115
+ Across the benchmark tables, `@esmj/schema` shows strong all-around results: fast schema creation, very competitive parsing and error-handling throughput, and a very small bundle size (`~1.6 KB` core).
116
+
117
+ For most TypeScript applications, it offers a practical balance of performance, size, and developer ergonomics. If absolute peak throughput in a single category is the only goal, some specialized options (for example, AJV or TypeBox in specific tests) can be faster.
115
118
 
116
119
  ## Comparison with Similar Libraries
117
120
 
@@ -125,6 +128,7 @@ When choosing a schema validation library, bundle size can be an important facto
125
128
  | Yup | ~12.2 KB |
126
129
  | Zod@3 | ~13 KB |
127
130
  | @zod/mini | ~20.5 KB |
131
+ | AJV | ~31.4 KB |
128
132
  | Joi | ~40.4 KB |
129
133
  | Zod@4 | ~40.8 KB |
130
134
  | ArkType | ~41.8 KB |
@@ -147,6 +151,7 @@ When choosing a schema validation library, bundle size can be an important facto
147
151
  | `@sinclair/typebox` | `4 370 618.49 ± 1.23%` | `0.23 ± 1.23%` |
148
152
  | ArkType | 16 282.69 ± 4.14% | 61.61 ± 4.38% |
149
153
  | effect/Schema | 24 919.15 ± 4.31% | 40.31 ± 4.78% |
154
+ | AJV | 240.32 ± 4.67% | 4 164.31 ± 2.04% |
150
155
 
151
156
  #### Parsing Performance
152
157
 
@@ -154,19 +159,20 @@ When choosing a schema validation library, bundle size can be an important facto
154
159
  |-------------------|-------------------------------:|-------------------------:|
155
160
  | @esmj/schema | 3 142 587.31 ± 0.97% | 0.32 ± 0.99% |
156
161
  | zod@3 | 1 018 777.24 ± 0.64% | 0.98 ± 0.65% |
157
- | `@zod/mini` | `4 627 714.90 ± 2.23%` | `0.22 ± 2.36%` |
162
+ | @zod/mini. | 4 627 714.90 ± 2.23% | 0.22 ± 2.36% |
158
163
  | Yup | 108 361.49 ± 0.50% | 9.23 ± 0.51% |
159
164
  | Superstruct | 252 904.42 ± 2.20% | 3.96 ± 2.44% |
160
165
  | Joi | 346 094.49 ± 0.65% | 2.89 ± 0.65% |
161
166
  | @sinclair/typebox | 228 711.62 ± 2.03% | 4.38 ± 2.23% |
162
167
  | ArkType | 1 677 066.00 ± 0.58% | 0.60 ± 0.59% |
163
168
  | effect/Schema | 1 060 056.14 ± 0.61% | 0.94 ± 0.61% |
169
+ | `AJV` | `33 620 146.24 ± 1.19%` | `0.03 ± 1.26%` |
164
170
 
165
171
  #### Error Handling Performance
166
172
 
167
173
  | Library | Throughput average (ops/s) | Latency average (μs) |
168
174
  |-------------------|-------------------------------:|-------------------------:|
169
- | `@esmj/schema` | `2 428 049.34 ± 0.54%` | `0.41 ± 0.53%` |
175
+ | @esmj/schema | 2 428 049.34 ± 0.54% | 0.41 ± 0.53% |
170
176
  | zod@3 | 641 504.22 ± 3.67% | 1.57 ± 4.38% |
171
177
  | @zod/mini | 1 386 616.61 ± 0.60% | 0.72 ± 0.60% |
172
178
  | Yup | 98 904.30 ± 0.61% | 10.11 ± 0.61% |
@@ -175,6 +181,7 @@ When choosing a schema validation library, bundle size can be an important facto
175
181
  | @sinclair/typebox | 228 734.49 ± 0.55% | 4.37 ± 0.56% |
176
182
  | ArkType | 258 685.33 ± 1.23% | 3.87 ± 1.23% |
177
183
  | effect/Schema | 165 753.69 ± 0.99% | 6.03 ± 1.00% |
184
+ | `AJV` | `19 693 821.79 ± 1.81%` | `0.05 ± 1.83%` |
178
185
 
179
186
  **Note:** During the performance tests, `@zod/mini` was observed to consume 200% CPU, while other libraries used only 100% CPU. This may affect the interpretation of the results, especially in multi-threaded environments.
180
187
 
@@ -250,6 +257,13 @@ import { s } from '@esmj/schema/array';
250
257
  import '@esmj/schema/string';
251
258
  import '@esmj/schema/number';
252
259
  import { s } from '@esmj/schema';
260
+
261
+ // Tree-shakeable named exports — bundle only what you use
262
+ import { string, number, object, array } from '@esmj/schema';
263
+ import { coerce, cast } from '@esmj/schema';
264
+
265
+ // Named exports for reserved-word factories
266
+ import { functionSchema, enumSchema } from '@esmj/schema';
253
267
  ```
254
268
 
255
269
  ### Bundle Size Impact
@@ -262,7 +276,48 @@ import { s } from '@esmj/schema';
262
276
 
263
277
  **Recommendation:** Import only the extensions you need to minimize bundle size.
264
278
 
265
- ### String Extensions (`@esmj/schema/string`)
279
+ ### Named Exports & Tree-Shaking
280
+
281
+ Every factory in the core module is exported both as a named function **and** as a property on `s`. The two references are identical — no extra wrapper, no overhead.
282
+
283
+ ```typescript
284
+ import { s } from '@esmj/schema';
285
+ import { string, number } from '@esmj/schema';
286
+
287
+ s.string === string; // true
288
+ ```
289
+
290
+ When you import individual factories, bundlers (webpack, Rollup, Vite, esbuild) tree-shake everything else out:
291
+
292
+ ```typescript
293
+ // Only `string` and `number` end up in the final bundle — object, array, coerce, cast, etc. are excluded
294
+ import { string, number } from '@esmj/schema';
295
+
296
+ const nameSchema = string().optional();
297
+ const ageSchema = number();
298
+ ```
299
+
300
+ The `coerce` and `cast` namespaces are also individually exported:
301
+
302
+ ```typescript
303
+ import { coerce } from '@esmj/schema';
304
+
305
+ const schema = coerce.number();
306
+ schema.parse('42'); // 42
307
+ ```
308
+
309
+ Because `function` and `enum` are reserved words in JavaScript, their standalone names are `functionSchema` and `enumSchema`:
310
+
311
+ ```typescript
312
+ import { functionSchema, enumSchema } from '@esmj/schema';
313
+
314
+ const cb = functionSchema();
315
+ const role = enumSchema(['admin', 'user', 'guest']);
316
+ ```
317
+
318
+ They are still accessible as `s.function()` and `s.enum()` for full API compatibility.
319
+
320
+
266
321
 
267
322
  String extensions provide common validation and transformation methods for string schemas.
268
323
 
@@ -422,19 +477,22 @@ const schema = s.object({
422
477
 
423
478
  ### Core Types
424
479
 
425
- - `s.string()` - String validation
426
- - `s.number()` - Number validation
427
- - `s.boolean()` - Boolean validation
428
- - `s.date()` - Date validation
429
- - `s.object(def)` - Object validation
430
- - `s.array(def)` - Array validation
431
- - `s.literal(value)` - Literal value validation
432
- - `s.enum(values)` - Enum validation
433
- - `s.union(schemas)` - Union validation
434
- - `s.any()` - Any type
435
- - `s.null()` - Null type
436
- - `s.undefined()` - Undefined type
437
- - `s.unknown()` - Unknown type
480
+ All factory functions below are available both as methods on `s` **and** as individual named exports for tree-shaking:
481
+
482
+ - `s.string()` / `import { string }` - String validation
483
+ - `s.number()` / `import { number }` - Number validation
484
+ - `s.boolean()` / `import { boolean }` - Boolean validation
485
+ - `s.date()` / `import { date }` - Date validation
486
+ - `s.function()` / `import { functionSchema }` - Function validation
487
+ - `s.object(def)` / `import { object }` - Object validation
488
+ - `s.array(def)` / `import { array }` - Array validation
489
+ - `s.literal(value)` / `import { literal }` - Literal value validation
490
+ - `s.enum(values)` / `import { enumSchema }` - Enum validation
491
+ - `s.union(schemas)` / `import { union }` - Union validation
492
+ - `s.any()` / `import { any }` - Any type
493
+ - `s.preprocess(fn, schema)` / `import { preprocess }` - Preprocess before validation
494
+ - `s.coerce` / `import { coerce }` - Coerce namespace
495
+ - `s.cast` / `import { cast }` - Cast namespace
438
496
 
439
497
  ### Modifiers
440
498
 
@@ -590,6 +648,27 @@ const dateSchemaFunc = s.date({
590
648
  });
591
649
  ```
592
650
 
651
+ #### `s.function(options?)`
652
+
653
+ Creates a function schema that validates the value is callable.
654
+
655
+ - **`message`**: Can be either a constant string or a function `(value) => string`.
656
+
657
+ ```typescript
658
+ const callbackSchema = s.function();
659
+ callbackSchema.parse(() => {}); // () => {}
660
+ callbackSchema.parse(async () => {}); // async () => {}
661
+ callbackSchema.parse('hello'); // throws
662
+
663
+ const callbackSchemaMsg = s.function({
664
+ message: 'Expected a callback function.',
665
+ });
666
+
667
+ const callbackSchemaFunc = s.function({
668
+ message: (value) => `Custom error: "${value}" is not a function.`,
669
+ });
670
+ ```
671
+
593
672
  #### `s.object(definition, options?)`
594
673
 
595
674
  Creates an object schema with the given definition. You can optionally pass `options` to customize error messages.
package/dist/array.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var E={abortEarly:true};function b(e,a){if(!a)return e;let n=e?.cause?.key?`${a}.${e.cause.key}`:`${a}`;return {message:`Error parsing key "${n}": ${e.message}`,cause:{key:n}}}function k(e,a,n){if(e.errors?.length)for(let r=0;r<e.errors.length;r++)a.push(b(e.errors[r],n));}function T(e){return {...E,...e}}var l=e=>typeof e=="string"||e instanceof String,d=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),g=e=>e===true||e===false,$=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),x=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),m={object(e,a){let n=S(x,{...a,type:"object"});return n._getDescription=()=>`object({ ${Object.entries(e).map(([u,c])=>`${u}: ${c._getDescription()}`).join(", ")} })`,h(n,"_parse",(r,u,c)=>{let t=r(u,c),{abortEarly:s}=T(c);if(t.success===false)return t;let o={},i=[];for(let p in e){let f=e[p]._parse(t.data[p],c);if(f.success)o[p]=f.data;else {if(f=f,s!==false){let I=b(f.error,p);return {success:false,error:I,errors:[I]}}k(f,i,p);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:o}}),n},string(e){return S(l,{...e,type:"string"})},number(e){return S(d,{...e,type:"number"})},boolean(e){return S(g,{...e,type:"boolean"})},date(e){return S($,{...e,type:"date"})},enum(e,a){let n=t=>e.includes(t),r=t=>`Invalid ${u} value. Expected ${e.map(s=>`"${s}"`).join(" | ")}, received "${t}".`,u="enum",c=S(n,{message:r,...a,type:u});return c._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,c},array(e,a){let n=S(_,{...a,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,h(n,"_parse",(r,u,c)=>{let t=r(u,c),{abortEarly:s}=T(c);if(t.success===false)return t;let o=[],i=[];for(let p=0;p<t.data.length;p++){let f=e._parse(t.data[p],c);if(f.success)o.push(f.data);else {if(f=f,s!==false){let I=b(f.error,p);return {success:false,error:I,errors:[I]}}k(f,i,p);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:o}}),n},any(){return S(()=>true)},preprocess(e,a){return h(a,"_parse",(n,r)=>(r=e(r),n(r))),a},union(e,a){return S(c=>{for(let t=0;t<e.length;t++){let s=e[t]._parse(c);if(s.success)return s}return false},{message:c=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,s)=>` ${s+1}. ${t._getDescription()}`).join(",")} but received "${typeof c}" with value: ${x(c)?JSON.stringify(c):`"${c}"`}`,...a,type:"union"})},literal(e,a){let u=S(c=>c===e,{message:c=>a?.message?typeof a.message=="function"?a.message(c):a.message:`Expected literal value "${e}", received "${c}"`,name:a?.name,type:"literal"});return u._getDescription=()=>`literal("${e}")`,u},coerce:{string(e){return m.preprocess(a=>String(a),m.string(e))},number(e){let a=e?.message??(n=>`Cannot coerce "${n}" to a valid number.`);return m.preprocess(n=>Number(n),m.number({...e,message:a}))},boolean(e){return m.preprocess(a=>!!a,m.boolean(e))},date(e){let a=e?.message??(n=>`Cannot coerce "${n}" to a valid date.`);return m.preprocess(n=>new Date(n),m.date({...e,message:a}))}},cast:{boolean(e){let a=e?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return m.preprocess(n=>{let r;return l(n)&&(r=n.toLowerCase()),r==="true"||r==="yes"||r==="on"||r==="1"||n===1?true:r==="false"||r==="no"||r==="off"||r==="0"||n===0?false:n},m.boolean({...e,message:a}))},number(e){let a=e?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return m.preprocess(n=>{if(g(n))return Number(n);if(l(n)){let r=n.trim();if(r==="")return n;let u=Number(r);if(Number.isFinite(u))return u}return n},m.number({...e,message:a}))},string(e){let a=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return m.preprocess(n=>g(n)||d(n)&&Number.isFinite(n)?String(n):n,m.string({...e,message:a}))},date(e){let a=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return m.preprocess(n=>{let r;return l(n)&&(r=n.trim()),d(n)&&Number.isFinite(n)||r?new Date(r??n):n},m.date({...e,message:a}))},json(e,a){let n=a?.message??(r=>`Cannot parse "${r}" as JSON.`);return h(e,"_parse",(r,u)=>{if(l(u))try{u=JSON.parse(u);}catch{let c={message:typeof n=="function"?n(u):n};return {success:false,error:c,errors:[c]}}return r(u)}),e}}};function P(e){return a=>`The value "${a}" must be type of ${e} but is type of "${typeof a}".`}function h(e,a,n){let r=e[a];e[a]=(...u)=>n(r,...u);}function S(e,{type:a="any",name:n,message:r}={}){r=r||P(a);let u={name:n,message:r,type:a},c={_getName(){return n},_getType(){return a},_getDescription(){return this._getName()??this._getType()},_parse(t,s){let o=e(t);if(o===true)return {success:true,data:t};if(typeof o=="object"&&o?.success===true)return o;let i={message:typeof r=="function"?r(t):r};return {success:false,error:i,errors:[i]}},parse(t,s){let o=c._parse(t,s);if(!o.success)throw o=o,new Error(o.error.message,{cause:o.error.cause});return o.data},safeParse(t,s){return c._parse(t,s)},transform(t){return h(this,"_parse",(s,o,i)=>{let p=s(o,i);return p.success&&(p.data=t(p.data)),p}),this},optional(){return h(this,"_parse",(t,s,o)=>{let i=t(s,o);return !i.success&&s===void 0&&(i.data=void 0,i.success=true),i}),this},nullable(){return h(this,"_parse",(t,s,o)=>{let i=t(s,o);return !i.success&&s===null&&(i.data=null,i.success=true),i}),this},nullish(){return h(this,"_parse",(t,s,o)=>{let i=t(s,o);return !i.success&&s==null&&(i.success=true,i.data=s),i}),this},default(t){return h(this,"_parse",(s,o,i)=>(o===void 0&&(o=typeof t=="function"?t():t),s(o,i))),this},catch(t){return h(this,"_parse",(s,o,i)=>{let p=s(o,i);return p.success?p:{success:true,data:typeof t=="function"?t({input:o,error:p.error}):t}}),this},pipe(t){return h(this,"_parse",(s,o,i)=>{let p=s(o,i);return p.success?t._parse(p.data,i):p}),this},refine(t,{message:s,type:o}={}){return o&&(s=s||P(o),a=o),h(this,"_parse",(i,p,f)=>{let I=i(p,f);T(f);if(!I.success)return I;let y=t(I.data);if(y===true||typeof y=="object"&&y?.success===true)return I;let w={message:typeof s=="function"?s(p):s};return {success:false,error:w,errors:[w]}}),this}};return O.length>0?O.reduce((t,s)=>s(t,e,u)??t,c):c}var O=[];function A(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");O.push(e);}A((e,a,n)=>{if(n?.type==="array"){let r=e;r.min=function(u,{message:c}={}){return this.refine(t=>t.length>=u,{message:c||`Array must contain at least ${u} items.`})},r.max=function(u,{message:c}={}){return this.refine(t=>t.length<=u,{message:c||`Array must contain at most ${u} items.`})},r.length=function(u,{message:c}={}){return this.refine(t=>t.length===u,{message:c||`Array must contain exactly ${u} items.`})},r.nonEmpty=function({message:u}={}){return this.refine(c=>c.length>0,{message:u||"Array must not be empty."})},r.unique=function({message:u}={}){return this.refine(c=>{let t=new Set;try{return c.every(s=>{let o=JSON.stringify(s);return t.has(o)?!1:(t.add(o),!0)})}catch{return new Set(c).size===c.length}},{message:u||"Array items must be unique."})},r.sort=function(){return this.transform(u=>[...u].sort())},r.reverse=function(){return this.transform(u=>[...u].reverse())};}return e});exports.extend=A;exports.hookOriginal=h;exports.s=m;exports.schema=m;
1
+ 'use strict';var N={abortEarly:true};function b(e,a){if(!a)return e;let n=e?.cause?.key?`${a}.${e.cause.key}`:`${a}`;return {message:`Error parsing key "${n}": ${e.message}`,cause:{key:n}}}function $(e,a,n){if(e.errors?.length)for(let r=0;r<e.errors.length;r++)a.push(b(e.errors[r],n));}function O(e){return e?.abortEarly!==void 0?e:N}var y=e=>typeof e=="string"||e instanceof String,d=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),g=e=>e===true||e===false,R=e=>e instanceof Date&&!Number.isNaN(e.getTime()),j=e=>typeof e=="function",F=e=>Array.isArray(e),_=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function C(e,a){let n=h(_,{...a,type:"object"});return n._getDescription=()=>`object({ ${Object.entries(e).map(([u,s])=>`${u}: ${s._getDescription()}`).join(", ")} })`,m(n,"_parse",(r,u,s)=>{let t=r(u,s),{abortEarly:c}=O(s);if(t.success===false)return t;let o={},i=[];for(let f in e){let p=e[f]._parse(t.data[f],s);if(p.success)o[f]=p.data;else {if(p=p,c!==false){let S=b(p.error,f);return {success:false,error:S,errors:[S]}}$(p,i,f);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:o}}),n}function k(e){return h(y,{...e,type:"string"})}function w(e){return h(d,{...e,type:"number"})}function x(e){return h(g,{...e,type:"boolean"})}function A(e){return h(R,{...e,type:"date"})}function V(e){return h(j,{...e,type:"function"})}function B(e,a){let n=t=>e.includes(t),r=t=>`Invalid ${u} value. Expected ${e.map(c=>`"${c}"`).join(" | ")}, received "${t}".`,u="enum",s=h(n,{message:r,...a,type:u});return s._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,s}function L(e,a){let n=h(F,{...a,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,m(n,"_parse",(r,u,s)=>{let t=r(u,s),{abortEarly:c}=O(s);if(t.success===false)return t;let o=[],i=[];for(let f=0;f<t.data.length;f++){let p=e._parse(t.data[f],s);if(p.success)o.push(p.data);else {if(p=p,c!==false){let S=b(p.error,f);return {success:false,error:S,errors:[S]}}$(p,i,f);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:o}}),n}function M(){return h(()=>true)}function I(e,a){return m(a,"_parse",(n,r)=>(r=e(r),n(r))),a}function q(e,a){return h(s=>{for(let t=0;t<e.length;t++){let c=e[t]._parse(s);if(c.success)return c}return false},{message:s=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,c)=>` ${c+1}. ${t._getDescription()}`).join(",")} but received "${typeof s}" with value: ${_(s)?JSON.stringify(s):`"${s}"`}`,...a,type:"union"})}function J(e,a){let u=h(s=>s===e,{message:s=>a?.message?typeof a.message=="function"?a.message(s):a.message:`Expected literal value "${e}", received "${s}"`,name:a?.name,type:"literal"});return u._getDescription=()=>`literal("${e}")`,u}var U={string(e){return I(a=>String(a),k(e))},number(e){let a=e?.message??(n=>`Cannot coerce "${n}" to a valid number.`);return I(n=>Number(n),w({...e,message:a}))},boolean(e){return I(a=>!!a,x(e))},date(e){let a=e?.message??(n=>`Cannot coerce "${n}" to a valid date.`);return I(n=>new Date(n),A({...e,message:a}))}},v={boolean(e){let a=e?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return I(n=>{let r;return y(n)&&(r=n.toLowerCase()),r==="true"||r==="yes"||r==="on"||r==="1"||n===1?true:r==="false"||r==="no"||r==="off"||r==="0"||n===0?false:n},x({...e,message:a}))},number(e){let a=e?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return I(n=>{if(g(n))return Number(n);if(y(n)){let r=n.trim();if(r==="")return n;let u=Number(r);if(Number.isFinite(u))return u}return n},w({...e,message:a}))},string(e){let a=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return I(n=>g(n)||d(n)&&Number.isFinite(n)?String(n):n,k({...e,message:a}))},date(e){let a=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return I(n=>{let r;return y(n)&&(r=n.trim()),d(n)&&Number.isFinite(n)||r?new Date(r??n):n},A({...e,message:a}))},json(e,a){let n=a?.message??(r=>`Cannot parse "${r}" as JSON.`);return m(e,"_parse",(r,u)=>{if(y(u))try{u=JSON.parse(u);}catch{let s={message:typeof n=="function"?n(u):n};return {success:false,error:s,errors:[s]}}return r(u)}),e}},H={object:C,string:k,number:w,boolean:x,date:A,function:V,enum:B,array:L,any:M,preprocess:I,union:q,literal:J,coerce:U,cast:v};function E(e){return a=>`The value "${a}" must be type of ${e} but is type of "${typeof a}".`}function m(e,a,n){let r=e[a];e[a]=(...u)=>n(r,...u);}function h(e,{type:a="any",name:n,message:r}={}){r=r||E(a);let u={name:n,message:r,type:a},s={_getName(){return n},_getType(){return a},_getDescription(){return this._getName()??this._getType()},_parse(t,c){let o=e(t);if(o===true)return {success:true,data:t};if(typeof o=="object"&&o?.success===true)return o;let i={message:typeof r=="function"?r(t):r};return {success:false,error:i,errors:[i]}},parse(t,c){let o=s._parse(t,c);if(!o.success)throw o=o,new Error(o.error.message,{cause:o.error.cause});return o.data},safeParse(t,c){return s._parse(t,c)},transform(t){return m(this,"_parse",(c,o,i)=>{let f=c(o,i);return f.success&&(f.data=t(f.data)),f}),this},optional(){return m(this,"_parse",(t,c,o)=>{let i=t(c,o);return !i.success&&c===void 0&&(i.data=void 0,i.success=true),i}),this},nullable(){return m(this,"_parse",(t,c,o)=>{let i=t(c,o);return !i.success&&c===null&&(i.data=null,i.success=true),i}),this},nullish(){return m(this,"_parse",(t,c,o)=>{let i=t(c,o);return !i.success&&c==null&&(i.success=true,i.data=c),i}),this},default(t){return m(this,"_parse",(c,o,i)=>(o===void 0&&(o=typeof t=="function"?t():t),c(o,i))),this},catch(t){return m(this,"_parse",(c,o,i)=>{let f=c(o,i);return f.success?f:{success:true,data:typeof t=="function"?t({input:o,error:f.error}):t}}),this},pipe(t){return m(this,"_parse",(c,o,i)=>{let f=c(o,i);return f.success?t._parse(f.data,i):f}),this},refine(t,{message:c,type:o}={}){return o&&(c=c||E(o),a=o),m(this,"_parse",(i,f,p)=>{let S=i(f,p),{abortEarly:z}=O(p);if(!S.success)return S;let l=t(S.data);if(l===true||typeof l=="object"&&l?.success===true)return S;let P={message:typeof c=="function"?c(f):c};return {success:false,error:P,errors:[P]}}),this}};return T.length>0?T.reduce((t,c)=>c(t,e,u)??t,s):s}var T=[];function D(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");T.push(e);}D((e,a,n)=>{if(n?.type==="array"){let r=e;r.min=function(u,{message:s}={}){return this.refine(t=>t.length>=u,{message:s||`Array must contain at least ${u} items.`})},r.max=function(u,{message:s}={}){return this.refine(t=>t.length<=u,{message:s||`Array must contain at most ${u} items.`})},r.length=function(u,{message:s}={}){return this.refine(t=>t.length===u,{message:s||`Array must contain exactly ${u} items.`})},r.nonEmpty=function({message:u}={}){return this.refine(s=>s.length>0,{message:u||"Array must not be empty."})},r.unique=function({message:u}={}){return this.refine(s=>{let t=new Set;try{return s.every(c=>{let o=JSON.stringify(c);return t.has(o)?!1:(t.add(o),!0)})}catch{return new Set(s).size===s.length}},{message:u||"Array items must be unique."})},r.sort=function(){return this.transform(u=>[...u].sort())},r.reverse=function(){return this.transform(u=>[...u].reverse())};}return e});exports.any=M;exports.array=L;exports.boolean=x;exports.cast=v;exports.coerce=U;exports.date=A;exports.enumSchema=B;exports.extend=D;exports.functionSchema=V;exports.hookOriginal=m;exports.literal=J;exports.number=w;exports.object=C;exports.preprocess=I;exports.s=H;exports.schema=H;exports.string=k;exports.union=q;
package/dist/array.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s, s as schema } from './index.mjs';
1
+ export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, FunctionSchemaInterface, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, any, array, boolean, cast, coerce, date, enumSchema, extend, functionSchema, hookOriginal, literal, number, object, preprocess, s, s as schema, string, union } 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, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s, s as schema } from './index.js';
1
+ export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, FunctionSchemaInterface, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, any, array, boolean, cast, coerce, date, enumSchema, extend, functionSchema, hookOriginal, literal, number, object, preprocess, s, s as schema, string, union } 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-GJNOESJT.mjs';export{c as extend,b as hookOriginal,a as s,a as schema}from'./chunk-QIW3OXV4.mjs';
1
+ import'./chunk-5XWCCG75.mjs';export{i as any,h as array,d as boolean,n as cast,m as coerce,e as date,g as enumSchema,q as extend,f as functionSchema,p as hookOriginal,l as literal,c as number,a as object,j as preprocess,o as s,o as schema,b as string,k as union}from'./chunk-37YJYCTR.mjs';
@@ -0,0 +1 @@
1
+ var N={abortEarly:true};function T(e,t){if(!t)return e;let n=e?.cause?.key?`${t}.${e.cause.key}`:`${t}`;return {message:`Error parsing key "${n}": ${e.message}`,cause:{key:n}}}function _(e,t,n){if(e.errors?.length)for(let a=0;a<e.errors.length;a++)t.push(T(e.errors[a],n));}function O(e){return e?.abortEarly!==void 0?e:N}var S=e=>typeof e=="string"||e instanceof String,y=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),g=e=>e===true||e===false,R=e=>e instanceof Date&&!Number.isNaN(e.getTime()),A=e=>typeof e=="function",j=e=>Array.isArray(e),$=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function F(e,t){let n=h($,{...t,type:"object"});return n._getDescription=()=>`object({ ${Object.entries(e).map(([f,o])=>`${f}: ${o._getDescription()}`).join(", ")} })`,m(n,"_parse",(a,f,o)=>{let r=a(f,o),{abortEarly:c}=O(o);if(r.success===false)return r;let u={},s=[];for(let i in e){let p=e[i]._parse(r.data[i],o);if(p.success)u[i]=p.data;else {if(p=p,c!==false){let I=T(p.error,i);return {success:false,error:I,errors:[I]}}_(p,s,i);}}return s.length>0?{success:false,error:s[0],errors:s}:{success:true,data:u}}),n}function k(e){return h(S,{...e,type:"string"})}function w(e){return h(y,{...e,type:"number"})}function x(e){return h(g,{...e,type:"boolean"})}function P(e){return h(R,{...e,type:"date"})}function C(e){return h(A,{...e,type:"function"})}function V(e,t){let n=r=>e.includes(r),a=r=>`Invalid ${f} value. Expected ${e.map(c=>`"${c}"`).join(" | ")}, received "${r}".`,f="enum",o=h(n,{message:a,...t,type:f});return o._getDescription=()=>`enum(${e.map(r=>`"${r}"`).join(" | ")})`,o}function B(e,t){let n=h(j,{...t,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,m(n,"_parse",(a,f,o)=>{let r=a(f,o),{abortEarly:c}=O(o);if(r.success===false)return r;let u=[],s=[];for(let i=0;i<r.data.length;i++){let p=e._parse(r.data[i],o);if(p.success)u.push(p.data);else {if(p=p,c!==false){let I=T(p.error,i);return {success:false,error:I,errors:[I]}}_(p,s,i);}}return s.length>0?{success:false,error:s[0],errors:s}:{success:true,data:u}}),n}function L(){return h(()=>true)}function l(e,t){return m(t,"_parse",(n,a)=>(a=e(a),n(a))),t}function M(e,t){return h(o=>{for(let r=0;r<e.length;r++){let c=e[r]._parse(o);if(c.success)return c}return false},{message:o=>`Invalid union value. Expected the value to match one of the schemas:${e.map((r,c)=>` ${c+1}. ${r._getDescription()}`).join(",")} but received "${typeof o}" with value: ${$(o)?JSON.stringify(o):`"${o}"`}`,...t,type:"union"})}function U(e,t){let f=h(o=>o===e,{message:o=>t?.message?typeof t.message=="function"?t.message(o):t.message:`Expected literal value "${e}", received "${o}"`,name:t?.name,type:"literal"});return f._getDescription=()=>`literal("${e}")`,f}var J={string(e){return l(t=>String(t),k(e))},number(e){let t=e?.message??(n=>`Cannot coerce "${n}" to a valid number.`);return l(n=>Number(n),w({...e,message:t}))},boolean(e){return l(t=>!!t,x(e))},date(e){let t=e?.message??(n=>`Cannot coerce "${n}" to a valid date.`);return l(n=>new Date(n),P({...e,message:t}))}},q={boolean(e){let t=e?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return l(n=>{let a;return S(n)&&(a=n.toLowerCase()),a==="true"||a==="yes"||a==="on"||a==="1"||n===1?true:a==="false"||a==="no"||a==="off"||a==="0"||n===0?false:n},x({...e,message:t}))},number(e){let t=e?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return l(n=>{if(g(n))return Number(n);if(S(n)){let a=n.trim();if(a==="")return n;let f=Number(a);if(Number.isFinite(f))return f}return n},w({...e,message:t}))},string(e){let t=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return l(n=>g(n)||y(n)&&Number.isFinite(n)?String(n):n,k({...e,message:t}))},date(e){let t=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return l(n=>{let a;return S(n)&&(a=n.trim()),y(n)&&Number.isFinite(n)||a?new Date(a??n):n},P({...e,message:t}))},json(e,t){let n=t?.message??(a=>`Cannot parse "${a}" as JSON.`);return m(e,"_parse",(a,f)=>{if(S(f))try{f=JSON.parse(f);}catch{let o={message:typeof n=="function"?n(f):n};return {success:false,error:o,errors:[o]}}return a(f)}),e}},H={object:F,string:k,number:w,boolean:x,date:P,function:C,enum:V,array:B,any:L,preprocess:l,union:M,literal:U,coerce:J,cast:q};function D(e){return t=>`The value "${t}" must be type of ${e} but is type of "${typeof t}".`}function m(e,t,n){let a=e[t];e[t]=(...f)=>n(a,...f);}function h(e,{type:t="any",name:n,message:a}={}){a=a||D(t);let f={name:n,message:a,type:t},o={_getName(){return n},_getType(){return t},_getDescription(){return this._getName()??this._getType()},_parse(r,c){let u=e(r);if(u===true)return {success:true,data:r};if(typeof u=="object"&&u?.success===true)return u;let s={message:typeof a=="function"?a(r):a};return {success:false,error:s,errors:[s]}},parse(r,c){let u=o._parse(r,c);if(!u.success)throw u=u,new Error(u.error.message,{cause:u.error.cause});return u.data},safeParse(r,c){return o._parse(r,c)},transform(r){return m(this,"_parse",(c,u,s)=>{let i=c(u,s);return i.success&&(i.data=r(i.data)),i}),this},optional(){return m(this,"_parse",(r,c,u)=>{let s=r(c,u);return !s.success&&c===void 0&&(s.data=void 0,s.success=true),s}),this},nullable(){return m(this,"_parse",(r,c,u)=>{let s=r(c,u);return !s.success&&c===null&&(s.data=null,s.success=true),s}),this},nullish(){return m(this,"_parse",(r,c,u)=>{let s=r(c,u);return !s.success&&c==null&&(s.success=true,s.data=c),s}),this},default(r){return m(this,"_parse",(c,u,s)=>(u===void 0&&(u=typeof r=="function"?r():r),c(u,s))),this},catch(r){return m(this,"_parse",(c,u,s)=>{let i=c(u,s);return i.success?i:{success:true,data:typeof r=="function"?r({input:u,error:i.error}):r}}),this},pipe(r){return m(this,"_parse",(c,u,s)=>{let i=c(u,s);return i.success?r._parse(i.data,s):i}),this},refine(r,{message:c,type:u}={}){return u&&(c=c||D(u),t=u),m(this,"_parse",(s,i,p)=>{let I=s(i,p),{abortEarly:z}=O(p);if(!I.success)return I;let d=r(I.data);if(d===true||typeof d=="object"&&d?.success===true)return I;let E={message:typeof c=="function"?c(i):c};return {success:false,error:E,errors:[E]}}),this}};return b.length>0?b.reduce((r,c)=>c(r,e,f)??r,o):o}var b=[];function Q(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");b.push(e);}export{F as a,k as b,w as c,x as d,P as e,C as f,V as g,B as h,L as i,l as j,M as k,U as l,J as m,q as n,H as o,m as p,Q as q};
@@ -0,0 +1 @@
1
+ import {q}from'./chunk-37YJYCTR.mjs';q((t,h,i)=>{if(i?.type==="array"){let r=t;r.min=function(e,{message:n}={}){return this.refine(a=>a.length>=e,{message:n||`Array must contain at least ${e} items.`})},r.max=function(e,{message:n}={}){return this.refine(a=>a.length<=e,{message:n||`Array must contain at most ${e} items.`})},r.length=function(e,{message:n}={}){return this.refine(a=>a.length===e,{message:n||`Array must contain exactly ${e} items.`})},r.nonEmpty=function({message:e}={}){return this.refine(n=>n.length>0,{message:e||"Array must not be empty."})},r.unique=function({message:e}={}){return this.refine(n=>{let a=new Set;try{return n.every(c=>{let s=JSON.stringify(c);return a.has(s)?!1:(a.add(s),!0)})}catch{return new Set(n).size===n.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 t});
@@ -0,0 +1 @@
1
+ import {q}from'./chunk-37YJYCTR.mjs';q((r,c,i)=>{if(i?.type==="number"){let t=r;t.min=function(e,{message:n}={}){return this.refine(a=>a>=e,{message:n||`Number must be greater than or equal to ${e}.`})},t.max=function(e,{message:n}={}){return this.refine(a=>a<=e,{message:n||`Number must be less than or equal to ${e}.`})},t.positive=function({message:e}={}){return this.refine(n=>n>0,{message:e||"Number must be positive."})},t.negative=function({message:e}={}){return this.refine(n=>n<0,{message:e||"Number must be negative."})},t.int=function({message:e}={}){return this.refine(n=>Number.isInteger(n),{message:e||"Number must be an integer."})},t.float=function({message:e}={}){return this.refine(n=>Number.isFinite(n)&&!Number.isInteger(n),{message:e||"Number must be a floating point (non-integer)."})},t.multipleOf=function(e,{message:n}={}){return this.refine(a=>a%e===0,{message:n||`Number must be a multiple of ${e}.`})},t.finite=function({message:e}={}){return this.refine(n=>Number.isFinite(n),{message:e||"Number must be finite."})};}return r});
@@ -0,0 +1 @@
1
+ import {q}from'./chunk-37YJYCTR.mjs';q((a,s,i)=>{if(i?.type==="string"){let r=a;r.min=function(n,{message:t}={}){return this.refine(e=>e.length>=n,{message:t||(e=>`String must be at least ${n} characters long (received ${e.length} characters: "${e}")`)})},r.max=function(n,{message:t}={}){return this.refine(e=>e.length<=n,{message:t||(e=>`String must be at most ${n} characters long (received ${e.length} characters: "${e}")`)})},r.length=function(n,{message:t}={}){return this.refine(e=>e.length===n,{message:t||(e=>`String must be exactly ${n} characters long (received ${e.length} characters: "${e}")`)})},r.nonEmpty=function({message:n}={}){return this.refine(t=>t.length>0,{message:n||"String must not be empty (received empty string)"})},r.startsWith=function(n,{message:t}={}){return this.refine(e=>e.startsWith(n),{message:t||(e=>`String must start with "${n}" (received: "${e}")`)})},r.endsWith=function(n,{message:t}={}){return this.refine(e=>e.endsWith(n),{message:t||(e=>`String must end with "${n}" (received: "${e}")`)})},r.includes=function(n,{message:t}={}){return this.refine(e=>e.includes(n),{message:t||(e=>`String must include "${n}" (received: "${e}")`)})},r.toLowerCase=function(){return this.transform(n=>n.toLowerCase())},r.toUpperCase=function(){return this.transform(n=>n.toUpperCase())},r.trim=function(){return this.transform(n=>n.trim())},r.padStart=function(n,t=" "){return this.transform(e=>e.padStart(n,t))},r.padEnd=function(n,t=" "){return this.transform(e=>e.padEnd(n,t))},r.replace=function(n,t){return this.transform(e=>e.replace(n,t))};}return a});
package/dist/full.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var P={abortEarly:true};function O(e,c){if(!c)return e;let s=e?.cause?.key?`${c}.${e.cause.key}`:`${c}`;return {message:`Error parsing key "${s}": ${e.message}`,cause:{key:s}}}function k(e,c,s){if(e.errors?.length)for(let a=0;a<e.errors.length;a++)c.push(O(e.errors[a],s));}function T(e){return {...P,...e}}var g=e=>typeof e=="string"||e instanceof String,y=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),b=e=>e===true||e===false,E=e=>e instanceof Date&&!Number.isNaN(e.getTime()),A=e=>Array.isArray(e),N=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),p={object(e,c){let s=I(N,{...c,type:"object"});return s._getDescription=()=>`object({ ${Object.entries(e).map(([n,r])=>`${n}: ${r._getDescription()}`).join(", ")} })`,h(s,"_parse",(a,n,r)=>{let t=a(n,r),{abortEarly:o}=T(r);if(t.success===false)return t;let i={},u=[];for(let m in e){let f=e[m]._parse(t.data[m],r);if(f.success)i[m]=f.data;else {if(f=f,o!==false){let S=O(f.error,m);return {success:false,error:S,errors:[S]}}k(f,u,m);}}return u.length>0?{success:false,error:u[0],errors:u}:{success:true,data:i}}),s},string(e){return I(g,{...e,type:"string"})},number(e){return I(y,{...e,type:"number"})},boolean(e){return I(b,{...e,type:"boolean"})},date(e){return I(E,{...e,type:"date"})},enum(e,c){let s=t=>e.includes(t),a=t=>`Invalid ${n} value. Expected ${e.map(o=>`"${o}"`).join(" | ")}, received "${t}".`,n="enum",r=I(s,{message:a,...c,type:n});return r._getDescription=()=>`enum(${e.map(t=>`"${t}"`).join(" | ")})`,r},array(e,c){let s=I(A,{...c,type:"array"});return s._getDescription=()=>`array(${e._getDescription()})`,h(s,"_parse",(a,n,r)=>{let t=a(n,r),{abortEarly:o}=T(r);if(t.success===false)return t;let i=[],u=[];for(let m=0;m<t.data.length;m++){let f=e._parse(t.data[m],r);if(f.success)i.push(f.data);else {if(f=f,o!==false){let S=O(f.error,m);return {success:false,error:S,errors:[S]}}k(f,u,m);}}return u.length>0?{success:false,error:u[0],errors:u}:{success:true,data:i}}),s},any(){return I(()=>true)},preprocess(e,c){return h(c,"_parse",(s,a)=>(a=e(a),s(a))),c},union(e,c){return I(r=>{for(let t=0;t<e.length;t++){let o=e[t]._parse(r);if(o.success)return o}return false},{message:r=>`Invalid union value. Expected the value to match one of the schemas:${e.map((t,o)=>` ${o+1}. ${t._getDescription()}`).join(",")} but received "${typeof r}" with value: ${N(r)?JSON.stringify(r):`"${r}"`}`,...c,type:"union"})},literal(e,c){let n=I(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 n._getDescription=()=>`literal("${e}")`,n},coerce:{string(e){return p.preprocess(c=>String(c),p.string(e))},number(e){let c=e?.message??(s=>`Cannot coerce "${s}" to a valid number.`);return p.preprocess(s=>Number(s),p.number({...e,message:c}))},boolean(e){return p.preprocess(c=>!!c,p.boolean(e))},date(e){let c=e?.message??(s=>`Cannot coerce "${s}" to a valid date.`);return p.preprocess(s=>new Date(s),p.date({...e,message:c}))}},cast:{boolean(e){let c=e?.message??(s=>`Cannot cast "${s}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return p.preprocess(s=>{let a;return g(s)&&(a=s.toLowerCase()),a==="true"||a==="yes"||a==="on"||a==="1"||s===1?true:a==="false"||a==="no"||a==="off"||a==="0"||s===0?false:s},p.boolean({...e,message:c}))},number(e){let c=e?.message??(s=>`Cannot cast "${s}" to a number. Expected a numeric string or number.`);return p.preprocess(s=>{if(b(s))return Number(s);if(g(s)){let a=s.trim();if(a==="")return s;let n=Number(a);if(Number.isFinite(n))return n}return s},p.number({...e,message:c}))},string(e){let c=e?.message??(s=>`Cannot cast "${s}" to string. Expected a string, number, or boolean.`);return p.preprocess(s=>b(s)||y(s)&&Number.isFinite(s)?String(s):s,p.string({...e,message:c}))},date(e){let c=e?.message??(s=>`Cannot cast "${s}" to a valid date.`);return p.preprocess(s=>{let a;return g(s)&&(a=s.trim()),y(s)&&Number.isFinite(s)||a?new Date(a??s):s},p.date({...e,message:c}))},json(e,c){let s=c?.message??(a=>`Cannot parse "${a}" as JSON.`);return h(e,"_parse",(a,n)=>{if(g(n))try{n=JSON.parse(n);}catch{let r={message:typeof s=="function"?s(n):s};return {success:false,error:r,errors:[r]}}return a(n)}),e}}};function $(e){return c=>`The value "${c}" must be type of ${e} but is type of "${typeof c}".`}function h(e,c,s){let a=e[c];e[c]=(...n)=>s(a,...n);}function I(e,{type:c="any",name:s,message:a}={}){a=a||$(c);let n={name:s,message:a,type:c},r={_getName(){return s},_getType(){return c},_getDescription(){return this._getName()??this._getType()},_parse(t,o){let i=e(t);if(i===true)return {success:true,data:t};if(typeof i=="object"&&i?.success===true)return i;let u={message:typeof a=="function"?a(t):a};return {success:false,error:u,errors:[u]}},parse(t,o){let i=r._parse(t,o);if(!i.success)throw i=i,new Error(i.error.message,{cause:i.error.cause});return i.data},safeParse(t,o){return r._parse(t,o)},transform(t){return h(this,"_parse",(o,i,u)=>{let m=o(i,u);return m.success&&(m.data=t(m.data)),m}),this},optional(){return h(this,"_parse",(t,o,i)=>{let u=t(o,i);return !u.success&&o===void 0&&(u.data=void 0,u.success=true),u}),this},nullable(){return h(this,"_parse",(t,o,i)=>{let u=t(o,i);return !u.success&&o===null&&(u.data=null,u.success=true),u}),this},nullish(){return h(this,"_parse",(t,o,i)=>{let u=t(o,i);return !u.success&&o==null&&(u.success=true,u.data=o),u}),this},default(t){return h(this,"_parse",(o,i,u)=>(i===void 0&&(i=typeof t=="function"?t():t),o(i,u))),this},catch(t){return h(this,"_parse",(o,i,u)=>{let m=o(i,u);return m.success?m:{success:true,data:typeof t=="function"?t({input:i,error:m.error}):t}}),this},pipe(t){return h(this,"_parse",(o,i,u)=>{let m=o(i,u);return m.success?t._parse(m.data,u):m}),this},refine(t,{message:o,type:i}={}){return i&&(o=o||$(i),c=i),h(this,"_parse",(u,m,f)=>{let S=u(m,f);T(f);if(!S.success)return S;let d=t(S.data);if(d===true||typeof d=="object"&&d?.success===true)return S;let x={message:typeof o=="function"?o(m):o};return {success:false,error:x,errors:[x]}}),this}};return w.length>0?w.reduce((t,o)=>o(t,e,n)??t,r):r}var w=[];function l(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");w.push(e);}l((e,c,s)=>{if(s?.type==="string"){let a=e;a.min=function(n,{message:r}={}){return this.refine(t=>t.length>=n,{message:r||(t=>`String must be at least ${n} characters long (received ${t.length} characters: "${t}")`)})},a.max=function(n,{message:r}={}){return this.refine(t=>t.length<=n,{message:r||(t=>`String must be at most ${n} characters long (received ${t.length} characters: "${t}")`)})},a.length=function(n,{message:r}={}){return this.refine(t=>t.length===n,{message:r||(t=>`String must be exactly ${n} characters long (received ${t.length} characters: "${t}")`)})},a.nonEmpty=function({message:n}={}){return this.refine(r=>r.length>0,{message:n||"String must not be empty (received empty string)"})},a.startsWith=function(n,{message:r}={}){return this.refine(t=>t.startsWith(n),{message:r||(t=>`String must start with "${n}" (received: "${t}")`)})},a.endsWith=function(n,{message:r}={}){return this.refine(t=>t.endsWith(n),{message:r||(t=>`String must end with "${n}" (received: "${t}")`)})},a.includes=function(n,{message:r}={}){return this.refine(t=>t.includes(n),{message:r||(t=>`String must include "${n}" (received: "${t}")`)})},a.toLowerCase=function(){return this.transform(n=>n.toLowerCase())},a.toUpperCase=function(){return this.transform(n=>n.toUpperCase())},a.trim=function(){return this.transform(n=>n.trim())},a.padStart=function(n,r=" "){return this.transform(t=>t.padStart(n,r))},a.padEnd=function(n,r=" "){return this.transform(t=>t.padEnd(n,r))},a.replace=function(n,r){return this.transform(t=>t.replace(n,r))};}return e});l((e,c,s)=>{if(s?.type==="number"){let a=e;a.min=function(n,{message:r}={}){return this.refine(t=>t>=n,{message:r||`Number must be greater than or equal to ${n}.`})},a.max=function(n,{message:r}={}){return this.refine(t=>t<=n,{message:r||`Number must be less than or equal to ${n}.`})},a.positive=function({message:n}={}){return this.refine(r=>r>0,{message:n||"Number must be positive."})},a.negative=function({message:n}={}){return this.refine(r=>r<0,{message:n||"Number must be negative."})},a.int=function({message:n}={}){return this.refine(r=>Number.isInteger(r),{message:n||"Number must be an integer."})},a.float=function({message:n}={}){return this.refine(r=>Number.isFinite(r)&&!Number.isInteger(r),{message:n||"Number must be a floating point (non-integer)."})},a.multipleOf=function(n,{message:r}={}){return this.refine(t=>t%n===0,{message:r||`Number must be a multiple of ${n}.`})},a.finite=function({message:n}={}){return this.refine(r=>Number.isFinite(r),{message:n||"Number must be finite."})};}return e});l((e,c,s)=>{if(s?.type==="array"){let a=e;a.min=function(n,{message:r}={}){return this.refine(t=>t.length>=n,{message:r||`Array must contain at least ${n} items.`})},a.max=function(n,{message:r}={}){return this.refine(t=>t.length<=n,{message:r||`Array must contain at most ${n} items.`})},a.length=function(n,{message:r}={}){return this.refine(t=>t.length===n,{message:r||`Array must contain exactly ${n} items.`})},a.nonEmpty=function({message:n}={}){return this.refine(r=>r.length>0,{message:n||"Array must not be empty."})},a.unique=function({message:n}={}){return this.refine(r=>{let t=new Set;try{return r.every(o=>{let i=JSON.stringify(o);return t.has(i)?!1:(t.add(i),!0)})}catch{return new Set(r).size===r.length}},{message:n||"Array items must be unique."})},a.sort=function(){return this.transform(n=>[...n].sort())},a.reverse=function(){return this.transform(n=>[...n].reverse())};}return e});exports.extend=l;exports.hookOriginal=h;exports.s=p;exports.schema=p;
1
+ 'use strict';var D={abortEarly:true};function T(e,s){if(!s)return e;let c=e?.cause?.key?`${s}.${e.cause.key}`:`${s}`;return {message:`Error parsing key "${c}": ${e.message}`,cause:{key:c}}}function E(e,s,c){if(e.errors?.length)for(let a=0;a<e.errors.length;a++)s.push(T(e.errors[a],c));}function w(e){return e?.abortEarly!==void 0?e:D}var g=e=>typeof e=="string"||e instanceof String,d=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),b=e=>e===true||e===false,R=e=>e instanceof Date&&!Number.isNaN(e.getTime()),j=e=>typeof e=="function",F=e=>Array.isArray(e),_=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function C(e,s){let c=h(_,{...s,type:"object"});return c._getDescription=()=>`object({ ${Object.entries(e).map(([t,r])=>`${t}: ${r._getDescription()}`).join(", ")} })`,p(c,"_parse",(a,t,r)=>{let n=a(t,r),{abortEarly:o}=w(r);if(n.success===false)return n;let u={},i=[];for(let m in e){let f=e[m]._parse(n.data[m],r);if(f.success)u[m]=f.data;else {if(f=f,o!==false){let S=T(f.error,m);return {success:false,error:S,errors:[S]}}E(f,i,m);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:u}}),c}function k(e){return h(g,{...e,type:"string"})}function x(e){return h(d,{...e,type:"number"})}function N(e){return h(b,{...e,type:"boolean"})}function $(e){return h(R,{...e,type:"date"})}function v(e){return h(j,{...e,type:"function"})}function V(e,s){let c=n=>e.includes(n),a=n=>`Invalid ${t} value. Expected ${e.map(o=>`"${o}"`).join(" | ")}, received "${n}".`,t="enum",r=h(c,{message:a,...s,type:t});return r._getDescription=()=>`enum(${e.map(n=>`"${n}"`).join(" | ")})`,r}function L(e,s){let c=h(F,{...s,type:"array"});return c._getDescription=()=>`array(${e._getDescription()})`,p(c,"_parse",(a,t,r)=>{let n=a(t,r),{abortEarly:o}=w(r);if(n.success===false)return n;let u=[],i=[];for(let m=0;m<n.data.length;m++){let f=e._parse(n.data[m],r);if(f.success)u.push(f.data);else {if(f=f,o!==false){let S=T(f.error,m);return {success:false,error:S,errors:[S]}}E(f,i,m);}}return i.length>0?{success:false,error:i[0],errors:i}:{success:true,data:u}}),c}function B(){return h(()=>true)}function I(e,s){return p(s,"_parse",(c,a)=>(a=e(a),c(a))),s}function M(e,s){return h(r=>{for(let n=0;n<e.length;n++){let o=e[n]._parse(r);if(o.success)return o}return false},{message:r=>`Invalid union value. Expected the value to match one of the schemas:${e.map((n,o)=>` ${o+1}. ${n._getDescription()}`).join(",")} but received "${typeof r}" with value: ${_(r)?JSON.stringify(r):`"${r}"`}`,...s,type:"union"})}function U(e,s){let t=h(r=>r===e,{message:r=>s?.message?typeof s.message=="function"?s.message(r):s.message:`Expected literal value "${e}", received "${r}"`,name:s?.name,type:"literal"});return t._getDescription=()=>`literal("${e}")`,t}var q={string(e){return I(s=>String(s),k(e))},number(e){let s=e?.message??(c=>`Cannot coerce "${c}" to a valid number.`);return I(c=>Number(c),x({...e,message:s}))},boolean(e){return I(s=>!!s,N(e))},date(e){let s=e?.message??(c=>`Cannot coerce "${c}" to a valid date.`);return I(c=>new Date(c),$({...e,message:s}))}},W={boolean(e){let s=e?.message??(c=>`Cannot cast "${c}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return I(c=>{let a;return g(c)&&(a=c.toLowerCase()),a==="true"||a==="yes"||a==="on"||a==="1"||c===1?true:a==="false"||a==="no"||a==="off"||a==="0"||c===0?false:c},N({...e,message:s}))},number(e){let s=e?.message??(c=>`Cannot cast "${c}" to a number. Expected a numeric string or number.`);return I(c=>{if(b(c))return Number(c);if(g(c)){let a=c.trim();if(a==="")return c;let t=Number(a);if(Number.isFinite(t))return t}return c},x({...e,message:s}))},string(e){let s=e?.message??(c=>`Cannot cast "${c}" to string. Expected a string, number, or boolean.`);return I(c=>b(c)||d(c)&&Number.isFinite(c)?String(c):c,k({...e,message:s}))},date(e){let s=e?.message??(c=>`Cannot cast "${c}" to a valid date.`);return I(c=>{let a;return g(c)&&(a=c.trim()),d(c)&&Number.isFinite(c)||a?new Date(a??c):c},$({...e,message:s}))},json(e,s){let c=s?.message??(a=>`Cannot parse "${a}" as JSON.`);return p(e,"_parse",(a,t)=>{if(g(t))try{t=JSON.parse(t);}catch{let r={message:typeof c=="function"?c(t):c};return {success:false,error:r,errors:[r]}}return a(t)}),e}},G={object:C,string:k,number:x,boolean:N,date:$,function:v,enum:V,array:L,any:B,preprocess:I,union:M,literal:U,coerce:q,cast:W};function P(e){return s=>`The value "${s}" must be type of ${e} but is type of "${typeof s}".`}function p(e,s,c){let a=e[s];e[s]=(...t)=>c(a,...t);}function h(e,{type:s="any",name:c,message:a}={}){a=a||P(s);let t={name:c,message:a,type:s},r={_getName(){return c},_getType(){return s},_getDescription(){return this._getName()??this._getType()},_parse(n,o){let u=e(n);if(u===true)return {success:true,data:n};if(typeof u=="object"&&u?.success===true)return u;let i={message:typeof a=="function"?a(n):a};return {success:false,error:i,errors:[i]}},parse(n,o){let u=r._parse(n,o);if(!u.success)throw u=u,new Error(u.error.message,{cause:u.error.cause});return u.data},safeParse(n,o){return r._parse(n,o)},transform(n){return p(this,"_parse",(o,u,i)=>{let m=o(u,i);return m.success&&(m.data=n(m.data)),m}),this},optional(){return p(this,"_parse",(n,o,u)=>{let i=n(o,u);return !i.success&&o===void 0&&(i.data=void 0,i.success=true),i}),this},nullable(){return p(this,"_parse",(n,o,u)=>{let i=n(o,u);return !i.success&&o===null&&(i.data=null,i.success=true),i}),this},nullish(){return p(this,"_parse",(n,o,u)=>{let i=n(o,u);return !i.success&&o==null&&(i.success=true,i.data=o),i}),this},default(n){return p(this,"_parse",(o,u,i)=>(u===void 0&&(u=typeof n=="function"?n():n),o(u,i))),this},catch(n){return p(this,"_parse",(o,u,i)=>{let m=o(u,i);return m.success?m:{success:true,data:typeof n=="function"?n({input:u,error:m.error}):n}}),this},pipe(n){return p(this,"_parse",(o,u,i)=>{let m=o(u,i);return m.success?n._parse(m.data,i):m}),this},refine(n,{message:o,type:u}={}){return u&&(o=o||P(u),s=u),p(this,"_parse",(i,m,f)=>{let S=i(m,f),{abortEarly:J}=w(f);if(!S.success)return S;let y=n(S.data);if(y===true||typeof y=="object"&&y?.success===true)return S;let A={message:typeof o=="function"?o(m):o};return {success:false,error:A,errors:[A]}}),this}};return O.length>0?O.reduce((n,o)=>o(n,e,t)??n,r):r}var O=[];function l(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");O.push(e);}l((e,s,c)=>{if(c?.type==="string"){let a=e;a.min=function(t,{message:r}={}){return this.refine(n=>n.length>=t,{message:r||(n=>`String must be at least ${t} characters long (received ${n.length} characters: "${n}")`)})},a.max=function(t,{message:r}={}){return this.refine(n=>n.length<=t,{message:r||(n=>`String must be at most ${t} characters long (received ${n.length} characters: "${n}")`)})},a.length=function(t,{message:r}={}){return this.refine(n=>n.length===t,{message:r||(n=>`String must be exactly ${t} characters long (received ${n.length} characters: "${n}")`)})},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(n=>n.startsWith(t),{message:r||(n=>`String must start with "${t}" (received: "${n}")`)})},a.endsWith=function(t,{message:r}={}){return this.refine(n=>n.endsWith(t),{message:r||(n=>`String must end with "${t}" (received: "${n}")`)})},a.includes=function(t,{message:r}={}){return this.refine(n=>n.includes(t),{message:r||(n=>`String must include "${t}" (received: "${n}")`)})},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(n=>n.padStart(t,r))},a.padEnd=function(t,r=" "){return this.transform(n=>n.padEnd(t,r))},a.replace=function(t,r){return this.transform(n=>n.replace(t,r))};}return e});l((e,s,c)=>{if(c?.type==="number"){let a=e;a.min=function(t,{message:r}={}){return this.refine(n=>n>=t,{message:r||`Number must be greater than or equal to ${t}.`})},a.max=function(t,{message:r}={}){return this.refine(n=>n<=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(n=>n%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 e});l((e,s,c)=>{if(c?.type==="array"){let a=e;a.min=function(t,{message:r}={}){return this.refine(n=>n.length>=t,{message:r||`Array must contain at least ${t} items.`})},a.max=function(t,{message:r}={}){return this.refine(n=>n.length<=t,{message:r||`Array must contain at most ${t} items.`})},a.length=function(t,{message:r}={}){return this.refine(n=>n.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 n=new Set;try{return r.every(o=>{let u=JSON.stringify(o);return n.has(u)?!1:(n.add(u),!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 e});exports.any=B;exports.array=L;exports.boolean=N;exports.cast=W;exports.coerce=q;exports.date=$;exports.enumSchema=V;exports.extend=l;exports.functionSchema=v;exports.hookOriginal=p;exports.literal=U;exports.number=x;exports.object=C;exports.preprocess=I;exports.s=G;exports.schema=G;exports.string=k;exports.union=M;
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, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s, s as schema } from './index.mjs';
4
+ export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, FunctionSchemaInterface, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, any, array, boolean, cast, coerce, date, enumSchema, extend, functionSchema, hookOriginal, literal, number, object, preprocess, s, s as schema, string, union } 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, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, extend, hookOriginal, s, s as schema } from './index.js';
4
+ export { ArraySchemaInterface, BooleanSchemaInterface, DateSchemaInterface, EnumSchemaInterface, ErrorStructure, ExtenderType, FunctionSchemaInterface, Infer, Invalid, LiteralSchemaInterface, NumberSchemaInterface, ObjectSchemaInterface, SchemaInterface, SchemaInterfaceOptions, SchemaType, StringSchemaInterface, UnionSchemaInterface, Valid, any, array, boolean, cast, coerce, date, enumSchema, extend, functionSchema, hookOriginal, literal, number, object, preprocess, s, s as schema, string, union } from './index.js';
package/dist/full.mjs CHANGED
@@ -1 +1 @@
1
- import'./chunk-GJNOESJT.mjs';import'./chunk-3C2I2ZOZ.mjs';import'./chunk-G6KRMWVT.mjs';export{c as extend,b as hookOriginal,a as s,a as schema}from'./chunk-QIW3OXV4.mjs';
1
+ import'./chunk-5XWCCG75.mjs';import'./chunk-NCRS6NBV.mjs';import'./chunk-NRGPACGD.mjs';export{i as any,h as array,d as boolean,n as cast,m as coerce,e as date,g as enumSchema,q as extend,f as functionSchema,p as hookOriginal,l as literal,c as number,a as object,j as preprocess,o as s,o as schema,b as string,k as union}from'./chunk-37YJYCTR.mjs';
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var E={abortEarly:true};function b(e,t){if(!t)return e;let n=e?.cause?.key?`${t}.${e.cause.key}`:`${t}`;return {message:`Error parsing key "${n}": ${e.message}`,cause:{key:n}}}function w(e,t,n){if(e.errors?.length)for(let a=0;a<e.errors.length;a++)t.push(b(e.errors[a],n));}function T(e){return {...E,...e}}var d=e=>typeof e=="string"||e instanceof String,y=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),g=e=>e===true||e===false,D=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=e=>Array.isArray(e),x=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),m={object(e,t){let n=l(x,{...t,type:"object"});return n._getDescription=()=>`object({ ${Object.entries(e).map(([p,o])=>`${p}: ${o._getDescription()}`).join(", ")} })`,h(n,"_parse",(a,p,o)=>{let r=a(p,o),{abortEarly:s}=T(o);if(r.success===false)return r;let u={},c=[];for(let i in e){let f=e[i]._parse(r.data[i],o);if(f.success)u[i]=f.data;else {if(f=f,s!==false){let I=b(f.error,i);return {success:false,error:I,errors:[I]}}w(f,c,i);}}return c.length>0?{success:false,error:c[0],errors:c}:{success:true,data:u}}),n},string(e){return l(d,{...e,type:"string"})},number(e){return l(y,{...e,type:"number"})},boolean(e){return l(g,{...e,type:"boolean"})},date(e){return l(D,{...e,type:"date"})},enum(e,t){let n=r=>e.includes(r),a=r=>`Invalid ${p} value. Expected ${e.map(s=>`"${s}"`).join(" | ")}, received "${r}".`,p="enum",o=l(n,{message:a,...t,type:p});return o._getDescription=()=>`enum(${e.map(r=>`"${r}"`).join(" | ")})`,o},array(e,t){let n=l(_,{...t,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,h(n,"_parse",(a,p,o)=>{let r=a(p,o),{abortEarly:s}=T(o);if(r.success===false)return r;let u=[],c=[];for(let i=0;i<r.data.length;i++){let f=e._parse(r.data[i],o);if(f.success)u.push(f.data);else {if(f=f,s!==false){let I=b(f.error,i);return {success:false,error:I,errors:[I]}}w(f,c,i);}}return c.length>0?{success:false,error:c[0],errors:c}:{success:true,data:u}}),n},any(){return l(()=>true)},preprocess(e,t){return h(t,"_parse",(n,a)=>(a=e(a),n(a))),t},union(e,t){return l(o=>{for(let r=0;r<e.length;r++){let s=e[r]._parse(o);if(s.success)return s}return false},{message:o=>`Invalid union value. Expected the value to match one of the schemas:${e.map((r,s)=>` ${s+1}. ${r._getDescription()}`).join(",")} but received "${typeof o}" with value: ${x(o)?JSON.stringify(o):`"${o}"`}`,...t,type:"union"})},literal(e,t){let p=l(o=>o===e,{message:o=>t?.message?typeof t.message=="function"?t.message(o):t.message:`Expected literal value "${e}", received "${o}"`,name:t?.name,type:"literal"});return p._getDescription=()=>`literal("${e}")`,p},coerce:{string(e){return m.preprocess(t=>String(t),m.string(e))},number(e){let t=e?.message??(n=>`Cannot coerce "${n}" to a valid number.`);return m.preprocess(n=>Number(n),m.number({...e,message:t}))},boolean(e){return m.preprocess(t=>!!t,m.boolean(e))},date(e){let t=e?.message??(n=>`Cannot coerce "${n}" to a valid date.`);return m.preprocess(n=>new Date(n),m.date({...e,message:t}))}},cast:{boolean(e){let t=e?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return m.preprocess(n=>{let a;return d(n)&&(a=n.toLowerCase()),a==="true"||a==="yes"||a==="on"||a==="1"||n===1?true:a==="false"||a==="no"||a==="off"||a==="0"||n===0?false:n},m.boolean({...e,message:t}))},number(e){let t=e?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return m.preprocess(n=>{if(g(n))return Number(n);if(d(n)){let a=n.trim();if(a==="")return n;let p=Number(a);if(Number.isFinite(p))return p}return n},m.number({...e,message:t}))},string(e){let t=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return m.preprocess(n=>g(n)||y(n)&&Number.isFinite(n)?String(n):n,m.string({...e,message:t}))},date(e){let t=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return m.preprocess(n=>{let a;return d(n)&&(a=n.trim()),y(n)&&Number.isFinite(n)||a?new Date(a??n):n},m.date({...e,message:t}))},json(e,t){let n=t?.message??(a=>`Cannot parse "${a}" as JSON.`);return h(e,"_parse",(a,p)=>{if(d(p))try{p=JSON.parse(p);}catch{let o={message:typeof n=="function"?n(p):n};return {success:false,error:o,errors:[o]}}return a(p)}),e}}};function P(e){return t=>`The value "${t}" must be type of ${e} but is type of "${typeof t}".`}function h(e,t,n){let a=e[t];e[t]=(...p)=>n(a,...p);}function l(e,{type:t="any",name:n,message:a}={}){a=a||P(t);let p={name:n,message:a,type:t},o={_getName(){return n},_getType(){return t},_getDescription(){return this._getName()??this._getType()},_parse(r,s){let u=e(r);if(u===true)return {success:true,data:r};if(typeof u=="object"&&u?.success===true)return u;let c={message:typeof a=="function"?a(r):a};return {success:false,error:c,errors:[c]}},parse(r,s){let u=o._parse(r,s);if(!u.success)throw u=u,new Error(u.error.message,{cause:u.error.cause});return u.data},safeParse(r,s){return o._parse(r,s)},transform(r){return h(this,"_parse",(s,u,c)=>{let i=s(u,c);return i.success&&(i.data=r(i.data)),i}),this},optional(){return h(this,"_parse",(r,s,u)=>{let c=r(s,u);return !c.success&&s===void 0&&(c.data=void 0,c.success=true),c}),this},nullable(){return h(this,"_parse",(r,s,u)=>{let c=r(s,u);return !c.success&&s===null&&(c.data=null,c.success=true),c}),this},nullish(){return h(this,"_parse",(r,s,u)=>{let c=r(s,u);return !c.success&&s==null&&(c.success=true,c.data=s),c}),this},default(r){return h(this,"_parse",(s,u,c)=>(u===void 0&&(u=typeof r=="function"?r():r),s(u,c))),this},catch(r){return h(this,"_parse",(s,u,c)=>{let i=s(u,c);return i.success?i:{success:true,data:typeof r=="function"?r({input:u,error:i.error}):r}}),this},pipe(r){return h(this,"_parse",(s,u,c)=>{let i=s(u,c);return i.success?r._parse(i.data,c):i}),this},refine(r,{message:s,type:u}={}){return u&&(s=s||P(u),t=u),h(this,"_parse",(c,i,f)=>{let I=c(i,f);T(f);if(!I.success)return I;let S=r(I.data);if(S===true||typeof S=="object"&&S?.success===true)return I;let k={message:typeof s=="function"?s(i):s};return {success:false,error:k,errors:[k]}}),this}};return O.length>0?O.reduce((r,s)=>s(r,e,p)??r,o):o}var O=[];function A(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");O.push(e);}exports.extend=A;exports.hookOriginal=h;exports.s=m;exports.schema=m;
1
+ 'use strict';var N={abortEarly:true};function T(e,t){if(!t)return e;let n=e?.cause?.key?`${t}.${e.cause.key}`:`${t}`;return {message:`Error parsing key "${n}": ${e.message}`,cause:{key:n}}}function _(e,t,n){if(e.errors?.length)for(let a=0;a<e.errors.length;a++)t.push(T(e.errors[a],n));}function O(e){return e?.abortEarly!==void 0?e:N}var S=e=>typeof e=="string"||e instanceof String,y=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),g=e=>e===true||e===false,R=e=>e instanceof Date&&!Number.isNaN(e.getTime()),A=e=>typeof e=="function",j=e=>Array.isArray(e),$=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function F(e,t){let n=h($,{...t,type:"object"});return n._getDescription=()=>`object({ ${Object.entries(e).map(([f,o])=>`${f}: ${o._getDescription()}`).join(", ")} })`,m(n,"_parse",(a,f,o)=>{let r=a(f,o),{abortEarly:c}=O(o);if(r.success===false)return r;let u={},s=[];for(let i in e){let p=e[i]._parse(r.data[i],o);if(p.success)u[i]=p.data;else {if(p=p,c!==false){let I=T(p.error,i);return {success:false,error:I,errors:[I]}}_(p,s,i);}}return s.length>0?{success:false,error:s[0],errors:s}:{success:true,data:u}}),n}function k(e){return h(S,{...e,type:"string"})}function w(e){return h(y,{...e,type:"number"})}function x(e){return h(g,{...e,type:"boolean"})}function P(e){return h(R,{...e,type:"date"})}function C(e){return h(A,{...e,type:"function"})}function V(e,t){let n=r=>e.includes(r),a=r=>`Invalid ${f} value. Expected ${e.map(c=>`"${c}"`).join(" | ")}, received "${r}".`,f="enum",o=h(n,{message:a,...t,type:f});return o._getDescription=()=>`enum(${e.map(r=>`"${r}"`).join(" | ")})`,o}function B(e,t){let n=h(j,{...t,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,m(n,"_parse",(a,f,o)=>{let r=a(f,o),{abortEarly:c}=O(o);if(r.success===false)return r;let u=[],s=[];for(let i=0;i<r.data.length;i++){let p=e._parse(r.data[i],o);if(p.success)u.push(p.data);else {if(p=p,c!==false){let I=T(p.error,i);return {success:false,error:I,errors:[I]}}_(p,s,i);}}return s.length>0?{success:false,error:s[0],errors:s}:{success:true,data:u}}),n}function L(){return h(()=>true)}function l(e,t){return m(t,"_parse",(n,a)=>(a=e(a),n(a))),t}function M(e,t){return h(o=>{for(let r=0;r<e.length;r++){let c=e[r]._parse(o);if(c.success)return c}return false},{message:o=>`Invalid union value. Expected the value to match one of the schemas:${e.map((r,c)=>` ${c+1}. ${r._getDescription()}`).join(",")} but received "${typeof o}" with value: ${$(o)?JSON.stringify(o):`"${o}"`}`,...t,type:"union"})}function U(e,t){let f=h(o=>o===e,{message:o=>t?.message?typeof t.message=="function"?t.message(o):t.message:`Expected literal value "${e}", received "${o}"`,name:t?.name,type:"literal"});return f._getDescription=()=>`literal("${e}")`,f}var J={string(e){return l(t=>String(t),k(e))},number(e){let t=e?.message??(n=>`Cannot coerce "${n}" to a valid number.`);return l(n=>Number(n),w({...e,message:t}))},boolean(e){return l(t=>!!t,x(e))},date(e){let t=e?.message??(n=>`Cannot coerce "${n}" to a valid date.`);return l(n=>new Date(n),P({...e,message:t}))}},q={boolean(e){let t=e?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return l(n=>{let a;return S(n)&&(a=n.toLowerCase()),a==="true"||a==="yes"||a==="on"||a==="1"||n===1?true:a==="false"||a==="no"||a==="off"||a==="0"||n===0?false:n},x({...e,message:t}))},number(e){let t=e?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return l(n=>{if(g(n))return Number(n);if(S(n)){let a=n.trim();if(a==="")return n;let f=Number(a);if(Number.isFinite(f))return f}return n},w({...e,message:t}))},string(e){let t=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return l(n=>g(n)||y(n)&&Number.isFinite(n)?String(n):n,k({...e,message:t}))},date(e){let t=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return l(n=>{let a;return S(n)&&(a=n.trim()),y(n)&&Number.isFinite(n)||a?new Date(a??n):n},P({...e,message:t}))},json(e,t){let n=t?.message??(a=>`Cannot parse "${a}" as JSON.`);return m(e,"_parse",(a,f)=>{if(S(f))try{f=JSON.parse(f);}catch{let o={message:typeof n=="function"?n(f):n};return {success:false,error:o,errors:[o]}}return a(f)}),e}},H={object:F,string:k,number:w,boolean:x,date:P,function:C,enum:V,array:B,any:L,preprocess:l,union:M,literal:U,coerce:J,cast:q};function D(e){return t=>`The value "${t}" must be type of ${e} but is type of "${typeof t}".`}function m(e,t,n){let a=e[t];e[t]=(...f)=>n(a,...f);}function h(e,{type:t="any",name:n,message:a}={}){a=a||D(t);let f={name:n,message:a,type:t},o={_getName(){return n},_getType(){return t},_getDescription(){return this._getName()??this._getType()},_parse(r,c){let u=e(r);if(u===true)return {success:true,data:r};if(typeof u=="object"&&u?.success===true)return u;let s={message:typeof a=="function"?a(r):a};return {success:false,error:s,errors:[s]}},parse(r,c){let u=o._parse(r,c);if(!u.success)throw u=u,new Error(u.error.message,{cause:u.error.cause});return u.data},safeParse(r,c){return o._parse(r,c)},transform(r){return m(this,"_parse",(c,u,s)=>{let i=c(u,s);return i.success&&(i.data=r(i.data)),i}),this},optional(){return m(this,"_parse",(r,c,u)=>{let s=r(c,u);return !s.success&&c===void 0&&(s.data=void 0,s.success=true),s}),this},nullable(){return m(this,"_parse",(r,c,u)=>{let s=r(c,u);return !s.success&&c===null&&(s.data=null,s.success=true),s}),this},nullish(){return m(this,"_parse",(r,c,u)=>{let s=r(c,u);return !s.success&&c==null&&(s.success=true,s.data=c),s}),this},default(r){return m(this,"_parse",(c,u,s)=>(u===void 0&&(u=typeof r=="function"?r():r),c(u,s))),this},catch(r){return m(this,"_parse",(c,u,s)=>{let i=c(u,s);return i.success?i:{success:true,data:typeof r=="function"?r({input:u,error:i.error}):r}}),this},pipe(r){return m(this,"_parse",(c,u,s)=>{let i=c(u,s);return i.success?r._parse(i.data,s):i}),this},refine(r,{message:c,type:u}={}){return u&&(c=c||D(u),t=u),m(this,"_parse",(s,i,p)=>{let I=s(i,p),{abortEarly:z}=O(p);if(!I.success)return I;let d=r(I.data);if(d===true||typeof d=="object"&&d?.success===true)return I;let E={message:typeof c=="function"?c(i):c};return {success:false,error:E,errors:[E]}}),this}};return b.length>0?b.reduce((r,c)=>c(r,e,f)??r,o):o}var b=[];function Q(e){if(typeof e!="function")throw new TypeError("extend() requires a function argument");b.push(e);}exports.any=L;exports.array=B;exports.boolean=x;exports.cast=q;exports.coerce=J;exports.date=P;exports.enumSchema=V;exports.extend=Q;exports.functionSchema=C;exports.hookOriginal=m;exports.literal=U;exports.number=w;exports.object=F;exports.preprocess=l;exports.s=H;exports.schema=H;exports.string=k;exports.union=M;