bupkis 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +8 -8
- package/dist/commonjs/assertion/assertion-types.d.ts +33 -82
- package/dist/commonjs/assertion/assertion-types.d.ts.map +1 -1
- package/dist/commonjs/assertion/create.d.ts +5 -33
- package/dist/commonjs/assertion/create.d.ts.map +1 -1
- package/dist/commonjs/assertion/create.js +17 -6
- package/dist/commonjs/assertion/create.js.map +1 -1
- package/dist/commonjs/assertion/impl/async.d.ts +5 -5
- package/dist/commonjs/assertion/impl/async.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/async.js +2 -2
- package/dist/commonjs/assertion/impl/async.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts +24 -24
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.js +3 -3
- package/dist/commonjs/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync.d.ts +50 -50
- package/dist/commonjs/assertion/impl/sync.d.ts.map +1 -1
- package/dist/commonjs/bootstrap.d.ts +71 -61
- package/dist/commonjs/bootstrap.d.ts.map +1 -1
- package/dist/commonjs/bootstrap.js +20 -10
- package/dist/commonjs/bootstrap.js.map +1 -1
- package/dist/commonjs/error.d.ts +12 -5
- package/dist/commonjs/error.d.ts.map +1 -1
- package/dist/commonjs/error.js +19 -4
- package/dist/commonjs/error.js.map +1 -1
- package/dist/commonjs/expect.d.ts +130 -3
- package/dist/commonjs/expect.d.ts.map +1 -1
- package/dist/commonjs/expect.js +115 -0
- package/dist/commonjs/expect.js.map +1 -1
- package/dist/commonjs/guards.d.ts +22 -15
- package/dist/commonjs/guards.d.ts.map +1 -1
- package/dist/commonjs/guards.js +34 -20
- package/dist/commonjs/guards.js.map +1 -1
- package/dist/commonjs/index.d.ts +113 -62
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +44 -42
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/metadata.d.ts +1 -27
- package/dist/commonjs/metadata.d.ts.map +1 -1
- package/dist/commonjs/metadata.js +16 -15
- package/dist/commonjs/metadata.js.map +1 -1
- package/dist/commonjs/schema.d.ts +59 -26
- package/dist/commonjs/schema.d.ts.map +1 -1
- package/dist/commonjs/schema.js +57 -24
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/commonjs/types.d.ts +449 -39
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +12 -2
- package/dist/commonjs/types.js.map +1 -1
- package/dist/commonjs/util.d.ts +7 -0
- package/dist/commonjs/util.d.ts.map +1 -1
- package/dist/commonjs/util.js +7 -0
- package/dist/commonjs/util.js.map +1 -1
- package/dist/esm/assertion/assertion-types.d.ts +33 -82
- package/dist/esm/assertion/assertion-types.d.ts.map +1 -1
- package/dist/esm/assertion/create.d.ts +5 -33
- package/dist/esm/assertion/create.d.ts.map +1 -1
- package/dist/esm/assertion/create.js +14 -4
- package/dist/esm/assertion/create.js.map +1 -1
- package/dist/esm/assertion/impl/async.d.ts +5 -5
- package/dist/esm/assertion/impl/async.d.ts.map +1 -1
- package/dist/esm/assertion/impl/async.js +2 -2
- package/dist/esm/assertion/impl/async.js.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.d.ts +24 -24
- package/dist/esm/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.js +3 -3
- package/dist/esm/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/esm/assertion/impl/sync.d.ts +50 -50
- package/dist/esm/assertion/impl/sync.d.ts.map +1 -1
- package/dist/esm/bootstrap.d.ts +71 -61
- package/dist/esm/bootstrap.d.ts.map +1 -1
- package/dist/esm/bootstrap.js +19 -9
- package/dist/esm/bootstrap.js.map +1 -1
- package/dist/esm/error.d.ts +12 -5
- package/dist/esm/error.d.ts.map +1 -1
- package/dist/esm/error.js +19 -4
- package/dist/esm/error.js.map +1 -1
- package/dist/esm/expect.d.ts +130 -3
- package/dist/esm/expect.d.ts.map +1 -1
- package/dist/esm/expect.js +115 -0
- package/dist/esm/expect.js.map +1 -1
- package/dist/esm/guards.d.ts +22 -15
- package/dist/esm/guards.d.ts.map +1 -1
- package/dist/esm/guards.js +29 -13
- package/dist/esm/guards.js.map +1 -1
- package/dist/esm/index.d.ts +113 -62
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +46 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/metadata.d.ts +1 -27
- package/dist/esm/metadata.d.ts.map +1 -1
- package/dist/esm/metadata.js +2 -1
- package/dist/esm/metadata.js.map +1 -1
- package/dist/esm/schema.d.ts +59 -26
- package/dist/esm/schema.d.ts.map +1 -1
- package/dist/esm/schema.js +57 -24
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/types.d.ts +449 -39
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +12 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/util.d.ts +7 -0
- package/dist/esm/util.d.ts.map +1 -1
- package/dist/esm/util.js +7 -0
- package/dist/esm/util.js.map +1 -1
- package/package.json +89 -15
- package/src/assertion/assertion-types.ts +38 -41
- package/src/assertion/create.ts +16 -65
- package/src/assertion/impl/async.ts +2 -2
- package/src/assertion/impl/sync-parametric.ts +3 -3
- package/src/bootstrap.ts +21 -10
- package/src/error.ts +21 -4
- package/src/expect.ts +269 -18
- package/src/guards.ts +29 -51
- package/src/index.ts +71 -11
- package/src/metadata.ts +3 -4
- package/src/schema.ts +59 -26
- package/src/types.ts +593 -72
- package/src/util.ts +7 -0
- package/dist/commonjs/api.d.ts +0 -93
- package/dist/commonjs/api.d.ts.map +0 -1
- package/dist/commonjs/api.js +0 -8
- package/dist/commonjs/api.js.map +0 -1
- package/dist/esm/api.d.ts +0 -93
- package/dist/esm/api.d.ts.map +0 -1
- package/dist/esm/api.js +0 -7
- package/dist/esm/api.js.map +0 -1
- package/src/api.ts +0 -149
- package/src/schema.md +0 -15
package/dist/esm/metadata.d.ts
CHANGED
|
@@ -2,15 +2,9 @@
|
|
|
2
2
|
* Defines Bupkis' Zod metadata registry
|
|
3
3
|
*
|
|
4
4
|
* @packageDocumentation
|
|
5
|
+
* @internal
|
|
5
6
|
*/
|
|
6
|
-
import { z } from 'zod';
|
|
7
7
|
import { kStringLiteral } from './constant.js';
|
|
8
|
-
/**
|
|
9
|
-
* Metadata stored in Zod registry
|
|
10
|
-
*
|
|
11
|
-
* @knipignore
|
|
12
|
-
*/
|
|
13
|
-
export type BupkisMeta = z.infer<typeof BupkisRegistrySchema>;
|
|
14
8
|
/**
|
|
15
9
|
* Zod metadata registry for Bupkis
|
|
16
10
|
*/
|
|
@@ -30,24 +24,4 @@ export declare const BupkisRegistry: z.core.$ZodRegistry<{
|
|
|
30
24
|
description?: string | undefined;
|
|
31
25
|
name?: string | undefined;
|
|
32
26
|
}, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
33
|
-
/**
|
|
34
|
-
* Final schema for Bupkis registry
|
|
35
|
-
*/
|
|
36
|
-
declare const BupkisRegistrySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
37
|
-
description: z.ZodOptional<z.ZodString>;
|
|
38
|
-
name: z.ZodOptional<z.ZodString>;
|
|
39
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
40
|
-
value: z.ZodString;
|
|
41
|
-
values: z.ZodOptional<z.ZodNever>;
|
|
42
|
-
[kStringLiteral]: z.ZodLiteral<true>;
|
|
43
|
-
description: z.ZodOptional<z.ZodString>;
|
|
44
|
-
name: z.ZodOptional<z.ZodString>;
|
|
45
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
46
|
-
value: z.ZodOptional<z.ZodNever>;
|
|
47
|
-
values: z.ZodReadonly<z.ZodTuple<[z.ZodString], z.ZodString>>;
|
|
48
|
-
[kStringLiteral]: z.ZodLiteral<true>;
|
|
49
|
-
description: z.ZodOptional<z.ZodString>;
|
|
50
|
-
name: z.ZodOptional<z.ZodString>;
|
|
51
|
-
}, z.core.$strip>]>;
|
|
52
|
-
export {};
|
|
53
27
|
//# sourceMappingURL=metadata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/metadata.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/metadata.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAO/C;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;iFAA2B,CAAC"}
|
package/dist/esm/metadata.js
CHANGED
package/dist/esm/metadata.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/metadata.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/metadata.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAO/C;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,QAAQ,EAAc,CAAC;AAEvD;;GAEG;AACH,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,4BAA4B,CAAC;IACzE,IAAI,EAAE,CAAC;SACJ,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CAAC,uDAAuD,CAAC;CACrE,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,GAAG,wBAAwB,CAAC,KAAK;IACjC,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;CAClC,CAAC,CAAC;AAEH;;GAEG;AACH,8FAA8F;AAC9F,6DAA6D;AAC7D,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC;IACnC,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,wBAAwB,CAAC,KAAK,EAAE,CAAC;IAC/C,CAAC,CAAC,MAAM,CAAC;QACP,GAAG,uBAAuB,CAAC,KAAK;QAChC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE;KAC7B,CAAC;IACF,CAAC,CAAC,MAAM,CAAC;QACP,GAAG,uBAAuB,CAAC,KAAK;QAChC,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE;QAC3B,gDAAgD;QAChD,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;KAC1D,CAAC;CACH,CAAC,CAAC"}
|
package/dist/esm/schema.d.ts
CHANGED
|
@@ -1,18 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Zod
|
|
2
|
+
* Arguably-useful Zod schemas for common types and validation patterns.
|
|
3
3
|
*
|
|
4
4
|
* This module provides reusable Zod schemas for validating constructors,
|
|
5
5
|
* functions, property keys, promises, and other common JavaScript types used
|
|
6
|
-
* throughout the assertion system. These tend to work around
|
|
7
|
-
*
|
|
6
|
+
* throughout the assertion system. These tend to work around the impedence
|
|
7
|
+
* mismatch between **BUPKIS** and Zod.
|
|
8
8
|
*
|
|
9
9
|
* These are used internally, but consumers may also find them useful.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* For example, we have {@link FunctionSchema} which accepts any
|
|
12
|
+
* function—regardless of its signature. We need this because Zod v4's
|
|
13
|
+
* `z.function()` no longer returns a `ZodType` (ref:
|
|
14
|
+
* {@link https://zod.dev/v4/changelog | Zod v4 Migration Guide}) and so behaves
|
|
15
|
+
* differently. `FunctionSchema` allows us to work with functions as _values_
|
|
16
|
+
* instead of something to be implemented.
|
|
17
|
+
*
|
|
18
|
+
* Similarly—but not a new development—`z.promise()` does not parse a
|
|
19
|
+
* {@link Promise} object; it parses the _fulfilled value_. This is not what we
|
|
20
|
+
* want for "is a Promise" assertions, but it _can_ be useful for making sense
|
|
21
|
+
* of the fulfilled value. To solve this, we have
|
|
22
|
+
* {@link WrappedPromiseLikeSchema} (which explicitly supports
|
|
23
|
+
* {@link PromiseLike}/"thenable" objects).
|
|
24
|
+
*
|
|
25
|
+
* @category API
|
|
26
|
+
* @example
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* import * as schema from 'bupkis/schema';
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
12
32
|
* @packageDocumentation
|
|
13
33
|
*/
|
|
14
34
|
import { z } from 'zod/v4';
|
|
15
|
-
import { type Constructor } from './types.js';
|
|
35
|
+
import { type Constructor, type MutableOrReadonly } from './types.js';
|
|
16
36
|
/**
|
|
17
37
|
* A Zod schema that validates JavaScript classes or constructor functions.
|
|
18
38
|
*
|
|
@@ -21,10 +41,9 @@ import { type Constructor } from './types.js';
|
|
|
21
41
|
* uses the {@link isConstructable} guard function to determine if a value can be
|
|
22
42
|
* invoked with the `new` operator to create object instances.
|
|
23
43
|
*
|
|
24
|
-
* @
|
|
44
|
+
* @privateRemarks
|
|
25
45
|
* The schema is registered in the {@link BupkisRegistry} with the name
|
|
26
46
|
* `ClassSchema` for later reference and type checking purposes.
|
|
27
|
-
* @category Schema
|
|
28
47
|
* @example
|
|
29
48
|
*
|
|
30
49
|
* ```typescript
|
|
@@ -38,6 +57,8 @@ import { type Constructor } from './types.js';
|
|
|
38
57
|
* ClassSchema.parse(() => {}); // ✗ Throws validation error
|
|
39
58
|
* ClassSchema.parse({}); // ✗ Throws validation error
|
|
40
59
|
* ```
|
|
60
|
+
*
|
|
61
|
+
* @group Schema
|
|
41
62
|
*/
|
|
42
63
|
export declare const ClassSchema: z.ZodCustom<Constructor, Constructor>;
|
|
43
64
|
/**
|
|
@@ -49,10 +70,9 @@ export declare const ClassSchema: z.ZodCustom<Constructor, Constructor>;
|
|
|
49
70
|
* including regular functions, arrow functions, async functions, generator
|
|
50
71
|
* functions, and methods.
|
|
51
72
|
*
|
|
52
|
-
* @
|
|
73
|
+
* @privateRemarks
|
|
53
74
|
* The schema is registered in the {@link BupkisRegistry} with the name
|
|
54
75
|
* `FunctionSchema` for later reference and type checking purposes.
|
|
55
|
-
* @category Schema
|
|
56
76
|
* @example
|
|
57
77
|
*
|
|
58
78
|
* ```typescript
|
|
@@ -64,8 +84,10 @@ export declare const ClassSchema: z.ZodCustom<Constructor, Constructor>;
|
|
|
64
84
|
* FunctionSchema.parse('not a function'); // ✗ Throws validation error
|
|
65
85
|
* FunctionSchema.parse({}); // ✗ Throws validation error
|
|
66
86
|
* ```
|
|
87
|
+
*
|
|
88
|
+
* @group Schema
|
|
67
89
|
*/
|
|
68
|
-
export declare const FunctionSchema: z.ZodCustom<(...args:
|
|
90
|
+
export declare const FunctionSchema: z.ZodCustom<(...args: MutableOrReadonly<unknown[]>) => unknown, (...args: MutableOrReadonly<unknown[]>) => unknown>;
|
|
69
91
|
/**
|
|
70
92
|
* A Zod schema that validates JavaScript property keys.
|
|
71
93
|
*
|
|
@@ -74,10 +96,9 @@ export declare const FunctionSchema: z.ZodCustom<(...args: any[]) => any, (...ar
|
|
|
74
96
|
* types that JavaScript automatically converts to property keys when used in
|
|
75
97
|
* object access or assignment operations.
|
|
76
98
|
*
|
|
77
|
-
* @
|
|
99
|
+
* @privateRemarks
|
|
78
100
|
* The schema is registered in the `BupkisRegistry` with the name
|
|
79
101
|
* `PropertyKeySchema` for later reference and type checking purposes.
|
|
80
|
-
* @category Schema
|
|
81
102
|
* @example
|
|
82
103
|
*
|
|
83
104
|
* ```typescript
|
|
@@ -87,6 +108,8 @@ export declare const FunctionSchema: z.ZodCustom<(...args: any[]) => any, (...ar
|
|
|
87
108
|
* PropertyKeySchema.parse({}); // ✗ Throws validation error
|
|
88
109
|
* PropertyKeySchema.parse(null); // ✗ Throws validation error
|
|
89
110
|
* ```
|
|
111
|
+
*
|
|
112
|
+
* @group Schema
|
|
90
113
|
*/
|
|
91
114
|
export declare const PropertyKeySchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodSymbol]>;
|
|
92
115
|
/**
|
|
@@ -98,12 +121,11 @@ export declare const PropertyKeySchema: z.ZodUnion<readonly [z.ZodString, z.ZodN
|
|
|
98
121
|
* resolved value, meaning the result of parsing remains a Promise or thenable
|
|
99
122
|
* object.
|
|
100
123
|
*
|
|
101
|
-
* @
|
|
124
|
+
* @privateRemarks
|
|
102
125
|
* The schema is registered in the `BupkisRegistry` with the name
|
|
103
126
|
* `WrappedPromiseLikeSchema` for later reference and type checking purposes.
|
|
104
127
|
* This is useful when you need to validate that something is thenable without
|
|
105
128
|
* automatically resolving it.
|
|
106
|
-
* @category Schema
|
|
107
129
|
* @example
|
|
108
130
|
*
|
|
109
131
|
* ```typescript
|
|
@@ -112,6 +134,8 @@ export declare const PropertyKeySchema: z.ZodUnion<readonly [z.ZodString, z.ZodN
|
|
|
112
134
|
* WrappedPromiseLikeSchema.parse(42); // ✗ Throws validation error
|
|
113
135
|
* WrappedPromiseLikeSchema.parse({}); // ✗ Throws validation error
|
|
114
136
|
* ```
|
|
137
|
+
*
|
|
138
|
+
* @group Schema
|
|
115
139
|
*/
|
|
116
140
|
export declare const WrappedPromiseLikeSchema: z.ZodCustom<PromiseLike<unknown>, PromiseLike<unknown>>;
|
|
117
141
|
/**
|
|
@@ -125,7 +149,6 @@ export declare const WrappedPromiseLikeSchema: z.ZodCustom<PromiseLike<unknown>,
|
|
|
125
149
|
* @remarks
|
|
126
150
|
* The schema is registered in the `BupkisRegistry` with the name
|
|
127
151
|
* `StrongMapSchema` for later reference and type checking purposes.
|
|
128
|
-
* @category Schema
|
|
129
152
|
* @example
|
|
130
153
|
*
|
|
131
154
|
* ```typescript
|
|
@@ -138,6 +161,8 @@ export declare const WrappedPromiseLikeSchema: z.ZodCustom<PromiseLike<unknown>,
|
|
|
138
161
|
* const weakMap = new WeakMap();
|
|
139
162
|
* StrongMapSchema.parse(weakMap); // ✗ Throws validation error
|
|
140
163
|
* ```
|
|
164
|
+
*
|
|
165
|
+
* @group Schema
|
|
141
166
|
*/
|
|
142
167
|
export declare const StrongMapSchema: z.ZodCustom<Map<unknown, unknown>, Map<unknown, unknown>>;
|
|
143
168
|
/**
|
|
@@ -151,7 +176,6 @@ export declare const StrongMapSchema: z.ZodCustom<Map<unknown, unknown>, Map<unk
|
|
|
151
176
|
* @remarks
|
|
152
177
|
* The schema is registered in the `BupkisRegistry` with the name
|
|
153
178
|
* `StrongSetSchema` for later reference and type checking purposes.
|
|
154
|
-
* @category Schema
|
|
155
179
|
* @example
|
|
156
180
|
*
|
|
157
181
|
* ```typescript
|
|
@@ -161,6 +185,8 @@ export declare const StrongMapSchema: z.ZodCustom<Map<unknown, unknown>, Map<unk
|
|
|
161
185
|
* const weakSet = new WeakSet();
|
|
162
186
|
* StrongSetSchema.parse(weakSet); // ✗ Throws validation error
|
|
163
187
|
* ```
|
|
188
|
+
*
|
|
189
|
+
* @group Schema
|
|
164
190
|
*/
|
|
165
191
|
export declare const StrongSetSchema: z.ZodCustom<Set<unknown>, Set<unknown>>;
|
|
166
192
|
/**
|
|
@@ -175,7 +201,6 @@ export declare const StrongSetSchema: z.ZodCustom<Set<unknown>, Set<unknown>>;
|
|
|
175
201
|
* @remarks
|
|
176
202
|
* The schema is registered in the `BupkisRegistry` with the name
|
|
177
203
|
* `ObjectWithNullPrototype` for later reference and type checking purposes.
|
|
178
|
-
* @category Schema
|
|
179
204
|
* @example
|
|
180
205
|
*
|
|
181
206
|
* ```typescript
|
|
@@ -189,6 +214,8 @@ export declare const StrongSetSchema: z.ZodCustom<Set<unknown>, Set<unknown>>;
|
|
|
189
214
|
* const emptyObj = {};
|
|
190
215
|
* NullProtoObjectSchema.parse(emptyObj); // ✗ Throws validation error
|
|
191
216
|
* ```
|
|
217
|
+
*
|
|
218
|
+
* @group Schema
|
|
192
219
|
*/
|
|
193
220
|
export declare const NullProtoObjectSchema: z.ZodCustom<Record<PropertyKey, unknown>, Record<PropertyKey, unknown>>;
|
|
194
221
|
/**
|
|
@@ -205,7 +232,6 @@ export declare const NullProtoObjectSchema: z.ZodCustom<Record<PropertyKey, unkn
|
|
|
205
232
|
* schema cannot reliably detect functions that return Promises but are not
|
|
206
233
|
* declared with `async`, as this determination requires static analysis that is
|
|
207
234
|
* not available at runtime.
|
|
208
|
-
* @category Schema
|
|
209
235
|
* @example
|
|
210
236
|
*
|
|
211
237
|
* ```typescript
|
|
@@ -225,8 +251,10 @@ export declare const NullProtoObjectSchema: z.ZodCustom<Record<PropertyKey, unkn
|
|
|
225
251
|
* const regularFn = () => 42;
|
|
226
252
|
* AsyncFunctionSchema.parse(regularFn); // ✗ Throws validation error
|
|
227
253
|
* ```
|
|
254
|
+
*
|
|
255
|
+
* @group Schema
|
|
228
256
|
*/
|
|
229
|
-
export declare const AsyncFunctionSchema: z.ZodCustom<(...args:
|
|
257
|
+
export declare const AsyncFunctionSchema: z.ZodCustom<(...args: MutableOrReadonly<unknown[]>) => unknown, (...args: MutableOrReadonly<unknown[]>) => unknown>;
|
|
230
258
|
/**
|
|
231
259
|
* A Zod schema that validates truthy JavaScript values.
|
|
232
260
|
*
|
|
@@ -238,7 +266,6 @@ export declare const AsyncFunctionSchema: z.ZodCustom<(...args: any[]) => any, (
|
|
|
238
266
|
* @remarks
|
|
239
267
|
* The schema is registered in the `BupkisRegistry` with the name `Truthy` and
|
|
240
268
|
* indicates that it accepts anything as valid input for evaluation.
|
|
241
|
-
* @category Schema
|
|
242
269
|
* @example
|
|
243
270
|
*
|
|
244
271
|
* ```typescript
|
|
@@ -252,6 +279,8 @@ export declare const AsyncFunctionSchema: z.ZodCustom<(...args: any[]) => any, (
|
|
|
252
279
|
* TruthySchema.parse(''); // ✗ Throws validation error
|
|
253
280
|
* TruthySchema.parse(null); // ✗ Throws validation error
|
|
254
281
|
* ```
|
|
282
|
+
*
|
|
283
|
+
* @group Schema
|
|
255
284
|
*/
|
|
256
285
|
export declare const TruthySchema: z.ZodNonOptional<z.ZodAny>;
|
|
257
286
|
/**
|
|
@@ -265,7 +294,6 @@ export declare const TruthySchema: z.ZodNonOptional<z.ZodAny>;
|
|
|
265
294
|
* @remarks
|
|
266
295
|
* The schema is registered in the `BupkisRegistry` with the name `Falsy` and
|
|
267
296
|
* indicates that it accepts anything as valid input for evaluation.
|
|
268
|
-
* @category Schema
|
|
269
297
|
* @example
|
|
270
298
|
*
|
|
271
299
|
* ```typescript
|
|
@@ -282,6 +310,8 @@ export declare const TruthySchema: z.ZodNonOptional<z.ZodAny>;
|
|
|
282
310
|
* FalsySchema.parse('hello'); // ✗ Throws validation error
|
|
283
311
|
* FalsySchema.parse({}); // ✗ Throws validation error
|
|
284
312
|
* ```
|
|
313
|
+
*
|
|
314
|
+
* @group Schema
|
|
285
315
|
*/
|
|
286
316
|
export declare const FalsySchema: z.ZodNullable<z.ZodAny>;
|
|
287
317
|
/**
|
|
@@ -296,7 +326,6 @@ export declare const FalsySchema: z.ZodNullable<z.ZodAny>;
|
|
|
296
326
|
* @remarks
|
|
297
327
|
* The schema is registered in the `BupkisRegistry` with the name `Primitive`
|
|
298
328
|
* and indicates that it accepts primitive values as valid input.
|
|
299
|
-
* @category Schema
|
|
300
329
|
* @example
|
|
301
330
|
*
|
|
302
331
|
* ```typescript
|
|
@@ -311,6 +340,8 @@ export declare const FalsySchema: z.ZodNullable<z.ZodAny>;
|
|
|
311
340
|
* PrimitiveSchema.parse([]); // ✗ Throws validation error (array)
|
|
312
341
|
* PrimitiveSchema.parse(() => {}); // ✗ Throws validation error (function)
|
|
313
342
|
* ```
|
|
343
|
+
*
|
|
344
|
+
* @group Schema
|
|
314
345
|
*/
|
|
315
346
|
export declare const PrimitiveSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodBigInt, z.ZodSymbol, z.ZodNull, z.ZodUndefined]>;
|
|
316
347
|
/**
|
|
@@ -323,12 +354,11 @@ export declare const PrimitiveSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNum
|
|
|
323
354
|
* it useful for validating collections where the specific array mutability or
|
|
324
355
|
* tuple structure is not critical.
|
|
325
356
|
*
|
|
326
|
-
* @
|
|
357
|
+
* @privateRemarks
|
|
327
358
|
* The schema is registered in the {@link BupkisRegistry} with the name
|
|
328
359
|
* `ArrayLike` for later reference and type checking purposes. This schema is
|
|
329
360
|
* particularly useful when you need to accept various forms of array-like data
|
|
330
361
|
* without being restrictive about mutability or exact tuple structure.
|
|
331
|
-
* @category Schema
|
|
332
362
|
* @example
|
|
333
363
|
*
|
|
334
364
|
* ```typescript
|
|
@@ -340,8 +370,10 @@ export declare const PrimitiveSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNum
|
|
|
340
370
|
* ArrayLikeSchema.parse({}); // ✗ Throws validation error
|
|
341
371
|
* ArrayLikeSchema.parse(null); // ✗ Throws validation error
|
|
342
372
|
* ```
|
|
373
|
+
*
|
|
374
|
+
* @group Schema
|
|
343
375
|
*/
|
|
344
|
-
export declare const ArrayLikeSchema: z.ZodUnion<readonly [z.ZodArray<z.
|
|
376
|
+
export declare const ArrayLikeSchema: z.ZodUnion<readonly [z.ZodArray<z.ZodUnknown>, z.ZodTuple<[z.ZodUnknown], z.ZodUnknown>, z.ZodObject<{
|
|
345
377
|
length: z.ZodNumber;
|
|
346
378
|
}, z.core.$loose>]>;
|
|
347
379
|
/**
|
|
@@ -356,7 +388,6 @@ export declare const ArrayLikeSchema: z.ZodUnion<readonly [z.ZodArray<z.ZodAny>,
|
|
|
356
388
|
* @remarks
|
|
357
389
|
* The schema is registered in the `BupkisRegistry` with the name `RegExp` for
|
|
358
390
|
* later reference and type checking purposes.
|
|
359
|
-
* @category Schema
|
|
360
391
|
* @example
|
|
361
392
|
*
|
|
362
393
|
* ```typescript
|
|
@@ -368,6 +399,8 @@ export declare const ArrayLikeSchema: z.ZodUnion<readonly [z.ZodArray<z.ZodAny>,
|
|
|
368
399
|
* RegExpSchema.parse(/abc/.source); // ✗ Throws validation error (string pattern)
|
|
369
400
|
* RegExpSchema.parse({}); // ✗ Throws validation error (object)
|
|
370
401
|
* ```
|
|
402
|
+
*
|
|
403
|
+
* @group Schema
|
|
371
404
|
*/
|
|
372
405
|
export declare const RegExpSchema: z.ZodCustom<RegExp, RegExp>;
|
|
373
406
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/esm/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAU3B,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,eAAO,MAAM,WAAW,uCAGU,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,cAAc,wBACP,iBAAiB,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,YAAxC,iBAAiB,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,CAMzD,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,iBAAiB,8DAG4B,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,wBAAwB,yDAK4B,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,eAAe,2DAI4B,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,eAAe,yCAI4B,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,qBAAqB,yEAK8B,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,mBAAmB,wBAxMZ,iBAAiB,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,YAAxC,iBAAiB,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,CA4MA,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,YAAY,4BAOrB,CAAC;AAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,WAAW,yBAKsB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,eAAe,oHAWsB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,eAAe;;mBASxB,CAAC;AAEL;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,YAAY,6BAGsB,CAAC"}
|
package/dist/esm/schema.js
CHANGED
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Zod
|
|
2
|
+
* Arguably-useful Zod schemas for common types and validation patterns.
|
|
3
3
|
*
|
|
4
4
|
* This module provides reusable Zod schemas for validating constructors,
|
|
5
5
|
* functions, property keys, promises, and other common JavaScript types used
|
|
6
|
-
* throughout the assertion system. These tend to work around
|
|
7
|
-
*
|
|
6
|
+
* throughout the assertion system. These tend to work around the impedence
|
|
7
|
+
* mismatch between **BUPKIS** and Zod.
|
|
8
8
|
*
|
|
9
9
|
* These are used internally, but consumers may also find them useful.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
11
|
+
* For example, we have {@link FunctionSchema} which accepts any
|
|
12
|
+
* function—regardless of its signature. We need this because Zod v4's
|
|
13
|
+
* `z.function()` no longer returns a `ZodType` (ref:
|
|
14
|
+
* {@link https://zod.dev/v4/changelog | Zod v4 Migration Guide}) and so behaves
|
|
15
|
+
* differently. `FunctionSchema` allows us to work with functions as _values_
|
|
16
|
+
* instead of something to be implemented.
|
|
17
|
+
*
|
|
18
|
+
* Similarly—but not a new development—`z.promise()` does not parse a
|
|
19
|
+
* {@link Promise} object; it parses the _fulfilled value_. This is not what we
|
|
20
|
+
* want for "is a Promise" assertions, but it _can_ be useful for making sense
|
|
21
|
+
* of the fulfilled value. To solve this, we have
|
|
22
|
+
* {@link WrappedPromiseLikeSchema} (which explicitly supports
|
|
23
|
+
* {@link PromiseLike}/"thenable" objects).
|
|
24
|
+
*
|
|
25
|
+
* @category API
|
|
26
|
+
* @example
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* import * as schema from 'bupkis/schema';
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
12
32
|
* @packageDocumentation
|
|
13
33
|
*/
|
|
14
34
|
import { z } from 'zod/v4';
|
|
@@ -22,10 +42,9 @@ import { BupkisRegistry } from './metadata.js';
|
|
|
22
42
|
* uses the {@link isConstructable} guard function to determine if a value can be
|
|
23
43
|
* invoked with the `new` operator to create object instances.
|
|
24
44
|
*
|
|
25
|
-
* @
|
|
45
|
+
* @privateRemarks
|
|
26
46
|
* The schema is registered in the {@link BupkisRegistry} with the name
|
|
27
47
|
* `ClassSchema` for later reference and type checking purposes.
|
|
28
|
-
* @category Schema
|
|
29
48
|
* @example
|
|
30
49
|
*
|
|
31
50
|
* ```typescript
|
|
@@ -39,6 +58,8 @@ import { BupkisRegistry } from './metadata.js';
|
|
|
39
58
|
* ClassSchema.parse(() => {}); // ✗ Throws validation error
|
|
40
59
|
* ClassSchema.parse({}); // ✗ Throws validation error
|
|
41
60
|
* ```
|
|
61
|
+
*
|
|
62
|
+
* @group Schema
|
|
42
63
|
*/
|
|
43
64
|
export const ClassSchema = z
|
|
44
65
|
.custom(isConstructable)
|
|
@@ -53,10 +74,9 @@ export const ClassSchema = z
|
|
|
53
74
|
* including regular functions, arrow functions, async functions, generator
|
|
54
75
|
* functions, and methods.
|
|
55
76
|
*
|
|
56
|
-
* @
|
|
77
|
+
* @privateRemarks
|
|
57
78
|
* The schema is registered in the {@link BupkisRegistry} with the name
|
|
58
79
|
* `FunctionSchema` for later reference and type checking purposes.
|
|
59
|
-
* @category Schema
|
|
60
80
|
* @example
|
|
61
81
|
*
|
|
62
82
|
* ```typescript
|
|
@@ -68,6 +88,8 @@ export const ClassSchema = z
|
|
|
68
88
|
* FunctionSchema.parse('not a function'); // ✗ Throws validation error
|
|
69
89
|
* FunctionSchema.parse({}); // ✗ Throws validation error
|
|
70
90
|
* ```
|
|
91
|
+
*
|
|
92
|
+
* @group Schema
|
|
71
93
|
*/
|
|
72
94
|
export const FunctionSchema = z
|
|
73
95
|
.custom(isFunction)
|
|
@@ -83,10 +105,9 @@ export const FunctionSchema = z
|
|
|
83
105
|
* types that JavaScript automatically converts to property keys when used in
|
|
84
106
|
* object access or assignment operations.
|
|
85
107
|
*
|
|
86
|
-
* @
|
|
108
|
+
* @privateRemarks
|
|
87
109
|
* The schema is registered in the `BupkisRegistry` with the name
|
|
88
110
|
* `PropertyKeySchema` for later reference and type checking purposes.
|
|
89
|
-
* @category Schema
|
|
90
111
|
* @example
|
|
91
112
|
*
|
|
92
113
|
* ```typescript
|
|
@@ -96,6 +117,8 @@ export const FunctionSchema = z
|
|
|
96
117
|
* PropertyKeySchema.parse({}); // ✗ Throws validation error
|
|
97
118
|
* PropertyKeySchema.parse(null); // ✗ Throws validation error
|
|
98
119
|
* ```
|
|
120
|
+
*
|
|
121
|
+
* @group Schema
|
|
99
122
|
*/
|
|
100
123
|
export const PropertyKeySchema = z
|
|
101
124
|
.union([z.string(), z.number(), z.symbol()])
|
|
@@ -110,12 +133,11 @@ export const PropertyKeySchema = z
|
|
|
110
133
|
* resolved value, meaning the result of parsing remains a Promise or thenable
|
|
111
134
|
* object.
|
|
112
135
|
*
|
|
113
|
-
* @
|
|
136
|
+
* @privateRemarks
|
|
114
137
|
* The schema is registered in the `BupkisRegistry` with the name
|
|
115
138
|
* `WrappedPromiseLikeSchema` for later reference and type checking purposes.
|
|
116
139
|
* This is useful when you need to validate that something is thenable without
|
|
117
140
|
* automatically resolving it.
|
|
118
|
-
* @category Schema
|
|
119
141
|
* @example
|
|
120
142
|
*
|
|
121
143
|
* ```typescript
|
|
@@ -124,6 +146,8 @@ export const PropertyKeySchema = z
|
|
|
124
146
|
* WrappedPromiseLikeSchema.parse(42); // ✗ Throws validation error
|
|
125
147
|
* WrappedPromiseLikeSchema.parse({}); // ✗ Throws validation error
|
|
126
148
|
* ```
|
|
149
|
+
*
|
|
150
|
+
* @group Schema
|
|
127
151
|
*/
|
|
128
152
|
export const WrappedPromiseLikeSchema = z
|
|
129
153
|
.custom((value) => isPromiseLike(value))
|
|
@@ -140,7 +164,6 @@ export const WrappedPromiseLikeSchema = z
|
|
|
140
164
|
* @remarks
|
|
141
165
|
* The schema is registered in the `BupkisRegistry` with the name
|
|
142
166
|
* `StrongMapSchema` for later reference and type checking purposes.
|
|
143
|
-
* @category Schema
|
|
144
167
|
* @example
|
|
145
168
|
*
|
|
146
169
|
* ```typescript
|
|
@@ -153,6 +176,8 @@ export const WrappedPromiseLikeSchema = z
|
|
|
153
176
|
* const weakMap = new WeakMap();
|
|
154
177
|
* StrongMapSchema.parse(weakMap); // ✗ Throws validation error
|
|
155
178
|
* ```
|
|
179
|
+
*
|
|
180
|
+
* @group Schema
|
|
156
181
|
*/
|
|
157
182
|
export const StrongMapSchema = z
|
|
158
183
|
.instanceof(Map)
|
|
@@ -170,7 +195,6 @@ export const StrongMapSchema = z
|
|
|
170
195
|
* @remarks
|
|
171
196
|
* The schema is registered in the `BupkisRegistry` with the name
|
|
172
197
|
* `StrongSetSchema` for later reference and type checking purposes.
|
|
173
|
-
* @category Schema
|
|
174
198
|
* @example
|
|
175
199
|
*
|
|
176
200
|
* ```typescript
|
|
@@ -180,6 +204,8 @@ export const StrongMapSchema = z
|
|
|
180
204
|
* const weakSet = new WeakSet();
|
|
181
205
|
* StrongSetSchema.parse(weakSet); // ✗ Throws validation error
|
|
182
206
|
* ```
|
|
207
|
+
*
|
|
208
|
+
* @group Schema
|
|
183
209
|
*/
|
|
184
210
|
export const StrongSetSchema = z
|
|
185
211
|
.instanceof(Set)
|
|
@@ -198,7 +224,6 @@ export const StrongSetSchema = z
|
|
|
198
224
|
* @remarks
|
|
199
225
|
* The schema is registered in the `BupkisRegistry` with the name
|
|
200
226
|
* `ObjectWithNullPrototype` for later reference and type checking purposes.
|
|
201
|
-
* @category Schema
|
|
202
227
|
* @example
|
|
203
228
|
*
|
|
204
229
|
* ```typescript
|
|
@@ -212,6 +237,8 @@ export const StrongSetSchema = z
|
|
|
212
237
|
* const emptyObj = {};
|
|
213
238
|
* NullProtoObjectSchema.parse(emptyObj); // ✗ Throws validation error
|
|
214
239
|
* ```
|
|
240
|
+
*
|
|
241
|
+
* @group Schema
|
|
215
242
|
*/
|
|
216
243
|
export const NullProtoObjectSchema = z
|
|
217
244
|
.custom((value) => isNonNullObject(value) && Object.getPrototypeOf(value) === null)
|
|
@@ -231,7 +258,6 @@ export const NullProtoObjectSchema = z
|
|
|
231
258
|
* schema cannot reliably detect functions that return Promises but are not
|
|
232
259
|
* declared with `async`, as this determination requires static analysis that is
|
|
233
260
|
* not available at runtime.
|
|
234
|
-
* @category Schema
|
|
235
261
|
* @example
|
|
236
262
|
*
|
|
237
263
|
* ```typescript
|
|
@@ -251,6 +277,8 @@ export const NullProtoObjectSchema = z
|
|
|
251
277
|
* const regularFn = () => 42;
|
|
252
278
|
* AsyncFunctionSchema.parse(regularFn); // ✗ Throws validation error
|
|
253
279
|
* ```
|
|
280
|
+
*
|
|
281
|
+
* @group Schema
|
|
254
282
|
*/
|
|
255
283
|
export const AsyncFunctionSchema = FunctionSchema.refine((value) => Object.prototype.toString.call(value) === '[object AsyncFunction]')
|
|
256
284
|
.describe('Function declared with the `async` keyword')
|
|
@@ -266,7 +294,6 @@ export const AsyncFunctionSchema = FunctionSchema.refine((value) => Object.proto
|
|
|
266
294
|
* @remarks
|
|
267
295
|
* The schema is registered in the `BupkisRegistry` with the name `Truthy` and
|
|
268
296
|
* indicates that it accepts anything as valid input for evaluation.
|
|
269
|
-
* @category Schema
|
|
270
297
|
* @example
|
|
271
298
|
*
|
|
272
299
|
* ```typescript
|
|
@@ -280,6 +307,8 @@ export const AsyncFunctionSchema = FunctionSchema.refine((value) => Object.proto
|
|
|
280
307
|
* TruthySchema.parse(''); // ✗ Throws validation error
|
|
281
308
|
* TruthySchema.parse(null); // ✗ Throws validation error
|
|
282
309
|
* ```
|
|
310
|
+
*
|
|
311
|
+
* @group Schema
|
|
283
312
|
*/
|
|
284
313
|
export const TruthySchema = z
|
|
285
314
|
.any()
|
|
@@ -300,7 +329,6 @@ export const TruthySchema = z
|
|
|
300
329
|
* @remarks
|
|
301
330
|
* The schema is registered in the `BupkisRegistry` with the name `Falsy` and
|
|
302
331
|
* indicates that it accepts anything as valid input for evaluation.
|
|
303
|
-
* @category Schema
|
|
304
332
|
* @example
|
|
305
333
|
*
|
|
306
334
|
* ```typescript
|
|
@@ -317,6 +345,8 @@ export const TruthySchema = z
|
|
|
317
345
|
* FalsySchema.parse('hello'); // ✗ Throws validation error
|
|
318
346
|
* FalsySchema.parse({}); // ✗ Throws validation error
|
|
319
347
|
* ```
|
|
348
|
+
*
|
|
349
|
+
* @group Schema
|
|
320
350
|
*/
|
|
321
351
|
export const FalsySchema = z
|
|
322
352
|
.any()
|
|
@@ -336,7 +366,6 @@ export const FalsySchema = z
|
|
|
336
366
|
* @remarks
|
|
337
367
|
* The schema is registered in the `BupkisRegistry` with the name `Primitive`
|
|
338
368
|
* and indicates that it accepts primitive values as valid input.
|
|
339
|
-
* @category Schema
|
|
340
369
|
* @example
|
|
341
370
|
*
|
|
342
371
|
* ```typescript
|
|
@@ -351,6 +380,8 @@ export const FalsySchema = z
|
|
|
351
380
|
* PrimitiveSchema.parse([]); // ✗ Throws validation error (array)
|
|
352
381
|
* PrimitiveSchema.parse(() => {}); // ✗ Throws validation error (function)
|
|
353
382
|
* ```
|
|
383
|
+
*
|
|
384
|
+
* @group Schema
|
|
354
385
|
*/
|
|
355
386
|
export const PrimitiveSchema = z
|
|
356
387
|
.union([
|
|
@@ -374,12 +405,11 @@ export const PrimitiveSchema = z
|
|
|
374
405
|
* it useful for validating collections where the specific array mutability or
|
|
375
406
|
* tuple structure is not critical.
|
|
376
407
|
*
|
|
377
|
-
* @
|
|
408
|
+
* @privateRemarks
|
|
378
409
|
* The schema is registered in the {@link BupkisRegistry} with the name
|
|
379
410
|
* `ArrayLike` for later reference and type checking purposes. This schema is
|
|
380
411
|
* particularly useful when you need to accept various forms of array-like data
|
|
381
412
|
* without being restrictive about mutability or exact tuple structure.
|
|
382
|
-
* @category Schema
|
|
383
413
|
* @example
|
|
384
414
|
*
|
|
385
415
|
* ```typescript
|
|
@@ -391,11 +421,13 @@ export const PrimitiveSchema = z
|
|
|
391
421
|
* ArrayLikeSchema.parse({}); // ✗ Throws validation error
|
|
392
422
|
* ArrayLikeSchema.parse(null); // ✗ Throws validation error
|
|
393
423
|
* ```
|
|
424
|
+
*
|
|
425
|
+
* @group Schema
|
|
394
426
|
*/
|
|
395
427
|
export const ArrayLikeSchema = z
|
|
396
428
|
.union([
|
|
397
|
-
z.array(z.
|
|
398
|
-
z.tuple([z.
|
|
429
|
+
z.array(z.unknown()),
|
|
430
|
+
z.tuple([z.unknown()], z.unknown()),
|
|
399
431
|
z.looseObject({ length: z.number().nonnegative().int() }),
|
|
400
432
|
])
|
|
401
433
|
.describe('Array-like value')
|
|
@@ -414,7 +446,6 @@ export const ArrayLikeSchema = z
|
|
|
414
446
|
* @remarks
|
|
415
447
|
* The schema is registered in the `BupkisRegistry` with the name `RegExp` for
|
|
416
448
|
* later reference and type checking purposes.
|
|
417
|
-
* @category Schema
|
|
418
449
|
* @example
|
|
419
450
|
*
|
|
420
451
|
* ```typescript
|
|
@@ -426,6 +457,8 @@ export const ArrayLikeSchema = z
|
|
|
426
457
|
* RegExpSchema.parse(/abc/.source); // ✗ Throws validation error (string pattern)
|
|
427
458
|
* RegExpSchema.parse({}); // ✗ Throws validation error (object)
|
|
428
459
|
* ```
|
|
460
|
+
*
|
|
461
|
+
* @group Schema
|
|
429
462
|
*/
|
|
430
463
|
export const RegExpSchema = z
|
|
431
464
|
.instanceof(RegExp)
|
package/dist/esm/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,OAAO,EACL,GAAG,EACH,eAAe,EACf,UAAU,EACV,eAAe,EACf,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC;KACzB,MAAM,CAAc,eAAe,CAAC;KACpC,QAAQ,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;KACjD,QAAQ,CAAC,qBAAqB,CAAC,CAAC;AAEnC;;;;;;;;;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