@xylabs/zod 5.0.82 → 5.0.84
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 +54 -0
- package/dist/neutral/Config.d.ts +2 -0
- package/dist/neutral/Config.d.ts.map +1 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/zodAllFactory.d.ts +7 -1
- package/dist/neutral/zodAllFactory.d.ts.map +1 -1
- package/dist/neutral/zodAsAsyncFactory.d.ts +7 -0
- package/dist/neutral/zodAsAsyncFactory.d.ts.map +1 -1
- package/dist/neutral/zodAsFactory.d.ts +7 -0
- package/dist/neutral/zodAsFactory.d.ts.map +1 -1
- package/dist/neutral/zodIsFactory.d.ts +5 -0
- package/dist/neutral/zodIsFactory.d.ts.map +1 -1
- package/dist/neutral/zodToAsyncFactory.d.ts +7 -0
- package/dist/neutral/zodToAsyncFactory.d.ts.map +1 -1
- package/dist/neutral/zodToFactory.d.ts +7 -0
- package/dist/neutral/zodToFactory.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -53,6 +53,8 @@ function zodAllFactory<T, TName>(zod, name): object;
|
|
|
53
53
|
|
|
54
54
|
**`Alpha`**
|
|
55
55
|
|
|
56
|
+
Creates a bundle of `is`, `as`, and `to` factory functions for a given zod schema.
|
|
57
|
+
|
|
56
58
|
## Type Parameters
|
|
57
59
|
|
|
58
60
|
### T
|
|
@@ -69,14 +71,20 @@ function zodAllFactory<T, TName>(zod, name): object;
|
|
|
69
71
|
|
|
70
72
|
`ZodType`\<`T`\>
|
|
71
73
|
|
|
74
|
+
The zod schema to validate against
|
|
75
|
+
|
|
72
76
|
### name
|
|
73
77
|
|
|
74
78
|
`TName`
|
|
75
79
|
|
|
80
|
+
The name used to suffix the generated function names (e.g. 'Address' produces `isAddress`, `asAddress`, `toAddress`)
|
|
81
|
+
|
|
76
82
|
## Returns
|
|
77
83
|
|
|
78
84
|
`object`
|
|
79
85
|
|
|
86
|
+
An object containing `is<Name>`, `as<Name>`, and `to<Name>` functions
|
|
87
|
+
|
|
80
88
|
### <a id="zodAsAsyncFactory"></a>zodAsAsyncFactory
|
|
81
89
|
|
|
82
90
|
[**@xylabs/zod**](#../README)
|
|
@@ -90,6 +98,9 @@ function zodAsAsyncFactory<TZod>(zod, name): {
|
|
|
90
98
|
};
|
|
91
99
|
```
|
|
92
100
|
|
|
101
|
+
Creates an async function that validates a value against a zod schema and returns it with a narrowed type.
|
|
102
|
+
Uses `safeParseAsync` for schemas with async refinements. When called without an assert config, returns undefined on failure.
|
|
103
|
+
|
|
93
104
|
## Type Parameters
|
|
94
105
|
|
|
95
106
|
### TZod
|
|
@@ -102,12 +113,18 @@ function zodAsAsyncFactory<TZod>(zod, name): {
|
|
|
102
113
|
|
|
103
114
|
`ZodType`\<`TZod`\>
|
|
104
115
|
|
|
116
|
+
The zod schema to validate against
|
|
117
|
+
|
|
105
118
|
### name
|
|
106
119
|
|
|
107
120
|
`string`
|
|
108
121
|
|
|
122
|
+
A name used in error messages for identification
|
|
123
|
+
|
|
109
124
|
## Returns
|
|
110
125
|
|
|
126
|
+
An async function that validates and narrows the type of a value
|
|
127
|
+
|
|
111
128
|
```ts
|
|
112
129
|
<T>(value): Promise<T & TZod | undefined>;
|
|
113
130
|
```
|
|
@@ -165,6 +182,9 @@ function zodAsFactory<TZod>(zod, name): {
|
|
|
165
182
|
};
|
|
166
183
|
```
|
|
167
184
|
|
|
185
|
+
Creates a function that validates a value against a zod schema and returns it with a narrowed type.
|
|
186
|
+
When called without an assert config, returns undefined on failure. When called with an assert config, throws on failure.
|
|
187
|
+
|
|
168
188
|
## Type Parameters
|
|
169
189
|
|
|
170
190
|
### TZod
|
|
@@ -177,12 +197,18 @@ function zodAsFactory<TZod>(zod, name): {
|
|
|
177
197
|
|
|
178
198
|
`ZodType`\<`TZod`\>
|
|
179
199
|
|
|
200
|
+
The zod schema to validate against
|
|
201
|
+
|
|
180
202
|
### name
|
|
181
203
|
|
|
182
204
|
`string`
|
|
183
205
|
|
|
206
|
+
A name used in error messages for identification
|
|
207
|
+
|
|
184
208
|
## Returns
|
|
185
209
|
|
|
210
|
+
A function that validates and narrows the type of a value
|
|
211
|
+
|
|
186
212
|
```ts
|
|
187
213
|
<T>(value): T & TZod | undefined;
|
|
188
214
|
```
|
|
@@ -237,6 +263,8 @@ function zodAsFactory<TZod>(zod, name): {
|
|
|
237
263
|
function zodIsFactory<TZod>(zod): <T>(value) => value is T & TZod;
|
|
238
264
|
```
|
|
239
265
|
|
|
266
|
+
Creates a type guard function that checks if a value matches a zod schema.
|
|
267
|
+
|
|
240
268
|
## Type Parameters
|
|
241
269
|
|
|
242
270
|
### TZod
|
|
@@ -249,8 +277,12 @@ function zodIsFactory<TZod>(zod): <T>(value) => value is T & TZod;
|
|
|
249
277
|
|
|
250
278
|
`ZodType`\<`TZod`\>
|
|
251
279
|
|
|
280
|
+
The zod schema to validate against
|
|
281
|
+
|
|
252
282
|
## Returns
|
|
253
283
|
|
|
284
|
+
A type guard function that returns true if the value passes validation
|
|
285
|
+
|
|
254
286
|
```ts
|
|
255
287
|
<T>(value): value is T & TZod;
|
|
256
288
|
```
|
|
@@ -284,6 +316,9 @@ function zodToAsyncFactory<TZod>(zod, name): {
|
|
|
284
316
|
};
|
|
285
317
|
```
|
|
286
318
|
|
|
319
|
+
Creates an async function that converts a value to the zod schema type, delegating to `zodAsAsyncFactory` internally.
|
|
320
|
+
Provides overloads for optional assertion: without assert config resolves to undefined on failure, with assert config throws on failure.
|
|
321
|
+
|
|
287
322
|
## Type Parameters
|
|
288
323
|
|
|
289
324
|
### TZod
|
|
@@ -296,12 +331,18 @@ function zodToAsyncFactory<TZod>(zod, name): {
|
|
|
296
331
|
|
|
297
332
|
`ZodType`\<`TZod`\>
|
|
298
333
|
|
|
334
|
+
The zod schema to validate against
|
|
335
|
+
|
|
299
336
|
### name
|
|
300
337
|
|
|
301
338
|
`string`
|
|
302
339
|
|
|
340
|
+
A name used in error messages for identification
|
|
341
|
+
|
|
303
342
|
## Returns
|
|
304
343
|
|
|
344
|
+
An async function that validates and converts a value to the schema type
|
|
345
|
+
|
|
305
346
|
```ts
|
|
306
347
|
<T>(value): Promise<T & TZod | undefined>;
|
|
307
348
|
```
|
|
@@ -359,6 +400,9 @@ function zodToFactory<TZod>(zod, name): {
|
|
|
359
400
|
};
|
|
360
401
|
```
|
|
361
402
|
|
|
403
|
+
Creates a function that converts a value to the zod schema type, delegating to `zodAsFactory` internally.
|
|
404
|
+
Provides overloads for optional assertion: without assert config returns undefined on failure, with assert config throws on failure.
|
|
405
|
+
|
|
362
406
|
## Type Parameters
|
|
363
407
|
|
|
364
408
|
### TZod
|
|
@@ -371,12 +415,18 @@ function zodToFactory<TZod>(zod, name): {
|
|
|
371
415
|
|
|
372
416
|
`ZodType`\<`TZod`\>
|
|
373
417
|
|
|
418
|
+
The zod schema to validate against
|
|
419
|
+
|
|
374
420
|
### name
|
|
375
421
|
|
|
376
422
|
`string`
|
|
377
423
|
|
|
424
|
+
A name used in error messages for identification
|
|
425
|
+
|
|
378
426
|
## Returns
|
|
379
427
|
|
|
428
|
+
A function that validates and converts a value to the schema type
|
|
429
|
+
|
|
380
430
|
```ts
|
|
381
431
|
<T>(value): T & TZod | undefined;
|
|
382
432
|
```
|
|
@@ -429,6 +479,8 @@ function zodToFactory<TZod>(zod, name): {
|
|
|
429
479
|
|
|
430
480
|
***
|
|
431
481
|
|
|
482
|
+
Configuration object for zod factory functions, providing a name for error messages.
|
|
483
|
+
|
|
432
484
|
## Properties
|
|
433
485
|
|
|
434
486
|
### name
|
|
@@ -473,6 +525,8 @@ type ZodFactoryConfig =
|
|
|
473
525
|
| ZodFactoryConfigObject;
|
|
474
526
|
```
|
|
475
527
|
|
|
528
|
+
Configuration for zod factory assertion behavior, either an AssertConfig or a named config object.
|
|
529
|
+
|
|
476
530
|
|
|
477
531
|
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
|
478
532
|
|
package/dist/neutral/Config.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { AssertConfig } from '@xylabs/error';
|
|
2
|
+
/** Configuration object for zod factory functions, providing a name for error messages. */
|
|
2
3
|
export interface ZodFactoryConfigObject {
|
|
3
4
|
name: string;
|
|
4
5
|
}
|
|
6
|
+
/** Configuration for zod factory assertion behavior, either an AssertConfig or a named config object. */
|
|
5
7
|
export type ZodFactoryConfig = AssertConfig | ZodFactoryConfigObject;
|
|
6
8
|
//# sourceMappingURL=Config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,sBAAsB,CAAA"}
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD,2FAA2F;AAC3F,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAA;CACb;AAED,yGAAyG;AACzG,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,sBAAsB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/zodAsFactory.ts","../../src/zodIsFactory.ts","../../src/zodToFactory.ts","../../src/zodAllFactory.ts","../../src/zodAsAsyncFactory.ts","../../src/zodToAsyncFactory.ts"],"sourcesContent":["import type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\nimport type * as z from 'zod'\n\nimport type { ZodFactoryConfig } from './Config.ts'\n\nexport function zodAsFactory<TZod>(zod: z.ZodType<TZod>, name: string) {\n function asFunc<T>(value: T): (T & TZod) | undefined\n function asFunc<T>(value: T, assert: ZodFactoryConfig): (T & TZod)\n function asFunc<T>(value: T, assert?: ZodFactoryConfig): (T & TZod) | undefined {\n const result = zod.safeParse(value)\n if (result.success) {\n return value as (T & TZod)\n }\n if (assert !== undefined) {\n let assertConfig: AssertConfig\n switch (typeof assert) {\n case 'string': {\n assertConfig = `[${name}][${value}] ${assert}`\n break\n }\n case 'object': {\n assertConfig = `[${name}][${assert.name}][${value}] ${result.error.message}`\n break\n }\n case 'boolean': {\n assertConfig = `[${name}][${value}] ${result.error.message}`\n break\n }\n case 'function': {\n assertConfig = assert(value, result.error.message)\n break\n }\n }\n return assertError(value, assertConfig, result.error.message)\n }\n }\n\n return asFunc\n}\n","import type * as z from 'zod'\n\nexport function zodIsFactory<TZod>(zod: z.ZodType<TZod>) {\n return <T>(value: T): value is T & TZod => zod.safeParse(value).success\n}\n","import { isDefined } from '@xylabs/typeof'\nimport type * as z from 'zod'\n\nimport type { ZodFactoryConfig } from './Config.ts'\nimport { zodAsFactory } from './zodAsFactory.ts'\n\nexport function zodToFactory<TZod>(zod: z.ZodType<TZod>, name: string) {\n const as = zodAsFactory<TZod>(zod, name)\n function toFunc<T>(value: T): (T & TZod) | undefined\n function toFunc<T>(value: T, assert: ZodFactoryConfig): (T & TZod)\n function toFunc<T>(value: T, assert?: ZodFactoryConfig): (T & TZod) | undefined {\n if (isDefined(assert)) {\n return as(value, assert)\n }\n return as(value)\n }\n return toFunc\n}\n","import type * as z from 'zod'\n\nimport { zodAsFactory } from './zodAsFactory.ts'\nimport { zodIsFactory } from './zodIsFactory.ts'\nimport { zodToFactory } from './zodToFactory.ts'\n\n/** @alpha */\nexport type AllZodFactories<TType, TName extends string> = {\n [K in `is${TName}`]: ReturnType<typeof zodIsFactory<TType>>\n} & {\n [K in `as${TName}`]: ReturnType<typeof zodAsFactory<TType>>\n} & {\n [K in `to${TName}`]: ReturnType<typeof zodToFactory<TType>>\n}\n\n
|
|
1
|
+
{"version":3,"sources":["../../src/zodAsFactory.ts","../../src/zodIsFactory.ts","../../src/zodToFactory.ts","../../src/zodAllFactory.ts","../../src/zodAsAsyncFactory.ts","../../src/zodToAsyncFactory.ts"],"sourcesContent":["import type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\nimport type * as z from 'zod'\n\nimport type { ZodFactoryConfig } from './Config.ts'\n\n/**\n * Creates a function that validates a value against a zod schema and returns it with a narrowed type.\n * When called without an assert config, returns undefined on failure. When called with an assert config, throws on failure.\n * @param zod - The zod schema to validate against\n * @param name - A name used in error messages for identification\n * @returns A function that validates and narrows the type of a value\n */\nexport function zodAsFactory<TZod>(zod: z.ZodType<TZod>, name: string) {\n function asFunc<T>(value: T): (T & TZod) | undefined\n function asFunc<T>(value: T, assert: ZodFactoryConfig): (T & TZod)\n function asFunc<T>(value: T, assert?: ZodFactoryConfig): (T & TZod) | undefined {\n const result = zod.safeParse(value)\n if (result.success) {\n return value as (T & TZod)\n }\n if (assert !== undefined) {\n let assertConfig: AssertConfig\n switch (typeof assert) {\n case 'string': {\n assertConfig = `[${name}][${value}] ${assert}`\n break\n }\n case 'object': {\n assertConfig = `[${name}][${assert.name}][${value}] ${result.error.message}`\n break\n }\n case 'boolean': {\n assertConfig = `[${name}][${value}] ${result.error.message}`\n break\n }\n case 'function': {\n assertConfig = assert(value, result.error.message)\n break\n }\n }\n return assertError(value, assertConfig, result.error.message)\n }\n }\n\n return asFunc\n}\n","import type * as z from 'zod'\n\n/**\n * Creates a type guard function that checks if a value matches a zod schema.\n * @param zod - The zod schema to validate against\n * @returns A type guard function that returns true if the value passes validation\n */\nexport function zodIsFactory<TZod>(zod: z.ZodType<TZod>) {\n return <T>(value: T): value is T & TZod => zod.safeParse(value).success\n}\n","import { isDefined } from '@xylabs/typeof'\nimport type * as z from 'zod'\n\nimport type { ZodFactoryConfig } from './Config.ts'\nimport { zodAsFactory } from './zodAsFactory.ts'\n\n/**\n * Creates a function that converts a value to the zod schema type, delegating to `zodAsFactory` internally.\n * Provides overloads for optional assertion: without assert config returns undefined on failure, with assert config throws on failure.\n * @param zod - The zod schema to validate against\n * @param name - A name used in error messages for identification\n * @returns A function that validates and converts a value to the schema type\n */\nexport function zodToFactory<TZod>(zod: z.ZodType<TZod>, name: string) {\n const as = zodAsFactory<TZod>(zod, name)\n function toFunc<T>(value: T): (T & TZod) | undefined\n function toFunc<T>(value: T, assert: ZodFactoryConfig): (T & TZod)\n function toFunc<T>(value: T, assert?: ZodFactoryConfig): (T & TZod) | undefined {\n if (isDefined(assert)) {\n return as(value, assert)\n }\n return as(value)\n }\n return toFunc\n}\n","import type * as z from 'zod'\n\nimport { zodAsFactory } from './zodAsFactory.ts'\nimport { zodIsFactory } from './zodIsFactory.ts'\nimport { zodToFactory } from './zodToFactory.ts'\n\n/** @alpha */\nexport type AllZodFactories<TType, TName extends string> = {\n [K in `is${TName}`]: ReturnType<typeof zodIsFactory<TType>>\n} & {\n [K in `as${TName}`]: ReturnType<typeof zodAsFactory<TType>>\n} & {\n [K in `to${TName}`]: ReturnType<typeof zodToFactory<TType>>\n}\n\n/**\n * Creates a bundle of `is`, `as`, and `to` factory functions for a given zod schema.\n * @alpha\n * @param zod - The zod schema to validate against\n * @param name - The name used to suffix the generated function names (e.g. 'Address' produces `isAddress`, `asAddress`, `toAddress`)\n * @returns An object containing `is<Name>`, `as<Name>`, and `to<Name>` functions\n */\nexport function zodAllFactory<T, TName extends string>(zod: z.ZodType<T>, name: TName) {\n return {\n [`is${name}`]: zodIsFactory<T>(zod),\n [`as${name}`]: zodAsFactory<T>(zod, `as${name}`),\n [`to${name}`]: zodToFactory<T>(zod, `to${name}`),\n }\n}\n","import type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\nimport type * as z from 'zod'\n\nimport type { ZodFactoryConfig } from './Config.ts'\n\n/**\n * Creates an async function that validates a value against a zod schema and returns it with a narrowed type.\n * Uses `safeParseAsync` for schemas with async refinements. When called without an assert config, returns undefined on failure.\n * @param zod - The zod schema to validate against\n * @param name - A name used in error messages for identification\n * @returns An async function that validates and narrows the type of a value\n */\nexport function zodAsAsyncFactory<TZod>(zod: z.ZodType<TZod>, name: string) {\n function asFunc<T>(value: T): Promise<(T & TZod) | undefined>\n function asFunc<T>(value: T, assert: ZodFactoryConfig): Promise<(T & TZod)>\n async function asFunc<T>(value: T, assert?: ZodFactoryConfig): Promise<(T & TZod) | undefined> {\n const result = await zod.safeParseAsync(value)\n if (result.success) {\n return value as (T & TZod)\n }\n if (assert !== undefined) {\n let assertConfig: AssertConfig\n switch (typeof assert) {\n case 'string': {\n assertConfig = `[${name}][${value}] ${assert}`\n break\n }\n case 'object': {\n assertConfig = `[${name}][${assert.name}][${value}] ${result.error.message}`\n break\n }\n case 'boolean': {\n assertConfig = `[${name}][${value}] ${result.error.message}`\n break\n }\n case 'function': {\n assertConfig = assert(value, result.error.message)\n break\n }\n }\n return assertError(value, assertConfig, result.error.message)\n }\n }\n\n return asFunc\n}\n","import { isDefined } from '@xylabs/typeof'\nimport type * as z from 'zod'\n\nimport type { ZodFactoryConfig } from './Config.ts'\nimport { zodAsAsyncFactory } from './zodAsAsyncFactory.ts'\n\n/**\n * Creates an async function that converts a value to the zod schema type, delegating to `zodAsAsyncFactory` internally.\n * Provides overloads for optional assertion: without assert config resolves to undefined on failure, with assert config throws on failure.\n * @param zod - The zod schema to validate against\n * @param name - A name used in error messages for identification\n * @returns An async function that validates and converts a value to the schema type\n */\nexport function zodToAsyncFactory<TZod>(zod: z.ZodType<TZod>, name: string) {\n const as = zodAsAsyncFactory<TZod>(zod, name)\n function toFunc<T>(value: T): Promise<(T & TZod) | undefined>\n function toFunc<T>(value: T, assert: ZodFactoryConfig): Promise<(T & TZod)>\n async function toFunc<T>(value: T, assert?: ZodFactoryConfig): Promise<(T & TZod) | undefined> {\n if (isDefined(assert)) {\n return await as(value, assert)\n }\n return await as(value)\n }\n return toFunc\n}\n"],"mappings":"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","names":["assertError","isDefined","isDefined"]}
|
|
@@ -10,7 +10,13 @@ export type AllZodFactories<TType, TName extends string> = {
|
|
|
10
10
|
} & {
|
|
11
11
|
[K in `to${TName}`]: ReturnType<typeof zodToFactory<TType>>;
|
|
12
12
|
};
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Creates a bundle of `is`, `as`, and `to` factory functions for a given zod schema.
|
|
15
|
+
* @alpha
|
|
16
|
+
* @param zod - The zod schema to validate against
|
|
17
|
+
* @param name - The name used to suffix the generated function names (e.g. 'Address' produces `isAddress`, `asAddress`, `toAddress`)
|
|
18
|
+
* @returns An object containing `is<Name>`, `as<Name>`, and `to<Name>` functions
|
|
19
|
+
*/
|
|
14
20
|
export declare function zodAllFactory<T, TName extends string>(zod: z.ZodType<T>, name: TName): {
|
|
15
21
|
[x: string]: {
|
|
16
22
|
<T_1>(value: T_1): (T_1 & T) | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zodAllFactory.d.ts","sourceRoot":"","sources":["../../src/zodAllFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,aAAa;AACb,MAAM,MAAM,eAAe,CAAC,KAAK,EAAE,KAAK,SAAS,MAAM,IAAI;KACxD,CAAC,IAAI,KAAK,KAAK,EAAE,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;CAC5D,GAAG;KACD,CAAC,IAAI,KAAK,KAAK,EAAE,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;CAC5D,GAAG;KACD,CAAC,IAAI,KAAK,KAAK,EAAE,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;CAC5D,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"zodAllFactory.d.ts","sourceRoot":"","sources":["../../src/zodAllFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,aAAa;AACb,MAAM,MAAM,eAAe,CAAC,KAAK,EAAE,KAAK,SAAS,MAAM,IAAI;KACxD,CAAC,IAAI,KAAK,KAAK,EAAE,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;CAC5D,GAAG;KACD,CAAC,IAAI,KAAK,KAAK,EAAE,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;CAC5D,GAAG;KACD,CAAC,IAAI,KAAK,KAAK,EAAE,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;CAC5D,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK;;;;;EAMpF"}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type * as z from 'zod';
|
|
2
2
|
import type { ZodFactoryConfig } from './Config.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Creates an async function that validates a value against a zod schema and returns it with a narrowed type.
|
|
5
|
+
* Uses `safeParseAsync` for schemas with async refinements. When called without an assert config, returns undefined on failure.
|
|
6
|
+
* @param zod - The zod schema to validate against
|
|
7
|
+
* @param name - A name used in error messages for identification
|
|
8
|
+
* @returns An async function that validates and narrows the type of a value
|
|
9
|
+
*/
|
|
3
10
|
export declare function zodAsAsyncFactory<TZod>(zod: z.ZodType<TZod>, name: string): {
|
|
4
11
|
<T>(value: T): Promise<(T & TZod) | undefined>;
|
|
5
12
|
<T>(value: T, assert: ZodFactoryConfig): Promise<(T & TZod)>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zodAsAsyncFactory.d.ts","sourceRoot":"","sources":["../../src/zodAsAsyncFactory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEnD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM;KACxD,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;KAC7C,CAAC,SAAS,CAAC,UAAU,gBAAgB,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;EA+B5E"}
|
|
1
|
+
{"version":3,"file":"zodAsAsyncFactory.d.ts","sourceRoot":"","sources":["../../src/zodAsAsyncFactory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEnD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM;KACxD,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;KAC7C,CAAC,SAAS,CAAC,UAAU,gBAAgB,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;EA+B5E"}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type * as z from 'zod';
|
|
2
2
|
import type { ZodFactoryConfig } from './Config.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that validates a value against a zod schema and returns it with a narrowed type.
|
|
5
|
+
* When called without an assert config, returns undefined on failure. When called with an assert config, throws on failure.
|
|
6
|
+
* @param zod - The zod schema to validate against
|
|
7
|
+
* @param name - A name used in error messages for identification
|
|
8
|
+
* @returns A function that validates and narrows the type of a value
|
|
9
|
+
*/
|
|
3
10
|
export declare function zodAsFactory<TZod>(zod: z.ZodType<TZod>, name: string): {
|
|
4
11
|
<T>(value: T): (T & TZod) | undefined;
|
|
5
12
|
<T>(value: T, assert: ZodFactoryConfig): (T & TZod);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zodAsFactory.d.ts","sourceRoot":"","sources":["../../src/zodAsFactory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEnD,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM;KACnD,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS;KACpC,CAAC,SAAS,CAAC,UAAU,gBAAgB,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;EA+BnE"}
|
|
1
|
+
{"version":3,"file":"zodAsFactory.d.ts","sourceRoot":"","sources":["../../src/zodAsFactory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEnD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM;KACnD,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS;KACpC,CAAC,SAAS,CAAC,UAAU,gBAAgB,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;EA+BnE"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type * as z from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a type guard function that checks if a value matches a zod schema.
|
|
4
|
+
* @param zod - The zod schema to validate against
|
|
5
|
+
* @returns A type guard function that returns true if the value passes validation
|
|
6
|
+
*/
|
|
2
7
|
export declare function zodIsFactory<TZod>(zod: z.ZodType<TZod>): <T>(value: T) => value is T & TZod;
|
|
3
8
|
//# sourceMappingURL=zodIsFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zodIsFactory.d.ts","sourceRoot":"","sources":["../../src/zodIsFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAC7C,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CACxC"}
|
|
1
|
+
{"version":3,"file":"zodIsFactory.d.ts","sourceRoot":"","sources":["../../src/zodIsFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAC7C,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CACxC"}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type * as z from 'zod';
|
|
2
2
|
import type { ZodFactoryConfig } from './Config.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Creates an async function that converts a value to the zod schema type, delegating to `zodAsAsyncFactory` internally.
|
|
5
|
+
* Provides overloads for optional assertion: without assert config resolves to undefined on failure, with assert config throws on failure.
|
|
6
|
+
* @param zod - The zod schema to validate against
|
|
7
|
+
* @param name - A name used in error messages for identification
|
|
8
|
+
* @returns An async function that validates and converts a value to the schema type
|
|
9
|
+
*/
|
|
3
10
|
export declare function zodToAsyncFactory<TZod>(zod: z.ZodType<TZod>, name: string): {
|
|
4
11
|
<T>(value: T): Promise<(T & TZod) | undefined>;
|
|
5
12
|
<T>(value: T, assert: ZodFactoryConfig): Promise<(T & TZod)>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zodToAsyncFactory.d.ts","sourceRoot":"","sources":["../../src/zodToAsyncFactory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAGnD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM;KAExD,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;KAC7C,CAAC,SAAS,CAAC,UAAU,gBAAgB,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;EAQ5E"}
|
|
1
|
+
{"version":3,"file":"zodToAsyncFactory.d.ts","sourceRoot":"","sources":["../../src/zodToAsyncFactory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAGnD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM;KAExD,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;KAC7C,CAAC,SAAS,CAAC,UAAU,gBAAgB,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;EAQ5E"}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type * as z from 'zod';
|
|
2
2
|
import type { ZodFactoryConfig } from './Config.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a function that converts a value to the zod schema type, delegating to `zodAsFactory` internally.
|
|
5
|
+
* Provides overloads for optional assertion: without assert config returns undefined on failure, with assert config throws on failure.
|
|
6
|
+
* @param zod - The zod schema to validate against
|
|
7
|
+
* @param name - A name used in error messages for identification
|
|
8
|
+
* @returns A function that validates and converts a value to the schema type
|
|
9
|
+
*/
|
|
3
10
|
export declare function zodToFactory<TZod>(zod: z.ZodType<TZod>, name: string): {
|
|
4
11
|
<T>(value: T): (T & TZod) | undefined;
|
|
5
12
|
<T>(value: T, assert: ZodFactoryConfig): (T & TZod);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zodToFactory.d.ts","sourceRoot":"","sources":["../../src/zodToFactory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAGnD,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM;KAEnD,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS;KACpC,CAAC,SAAS,CAAC,UAAU,gBAAgB,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;EAQnE"}
|
|
1
|
+
{"version":3,"file":"zodToFactory.d.ts","sourceRoot":"","sources":["../../src/zodToFactory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAA;AAE7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAGnD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM;KAEnD,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS;KACpC,CAAC,SAAS,CAAC,UAAU,gBAAgB,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;EAQnE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/zod",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.84",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"!**/*.test.*"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@xylabs/error": "~5.0.
|
|
39
|
-
"@xylabs/typeof": "~5.0.
|
|
38
|
+
"@xylabs/error": "~5.0.84",
|
|
39
|
+
"@xylabs/typeof": "~5.0.84"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
43
|
-
"@xylabs/tsconfig": "~7.4.
|
|
42
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.13",
|
|
43
|
+
"@xylabs/tsconfig": "~7.4.13",
|
|
44
44
|
"typescript": "~5.9.3",
|
|
45
45
|
"vitest": "^4.0.18",
|
|
46
46
|
"zod": "^4.3.6"
|