@xylabs/zod 5.0.83 → 5.0.86

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,8 @@
15
15
 
16
16
  Base functionality used throughout XY Labs TypeScript/JavaScript libraries
17
17
 
18
+
19
+
18
20
  ## Reference
19
21
 
20
22
  **@xylabs/zod**
@@ -23,21 +25,27 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
23
25
 
24
26
  ## Interfaces
25
27
 
26
- - [ZodFactoryConfigObject](#interfaces/ZodFactoryConfigObject)
28
+ | Interface | Description |
29
+ | ------ | ------ |
30
+ | [ZodFactoryConfigObject](#interfaces/ZodFactoryConfigObject) | Configuration object for zod factory functions, providing a name for error messages. |
27
31
 
28
32
  ## Type Aliases
29
33
 
30
- - [ZodFactoryConfig](#type-aliases/ZodFactoryConfig)
31
- - [AllZodFactories](#type-aliases/AllZodFactories)
34
+ | Type Alias | Description |
35
+ | ------ | ------ |
36
+ | [ZodFactoryConfig](#type-aliases/ZodFactoryConfig) | Configuration for zod factory assertion behavior, either an AssertConfig or a named config object. |
37
+ | [AllZodFactories](#type-aliases/AllZodFactories) | - |
32
38
 
33
39
  ## Functions
34
40
 
35
- - [zodAllFactory](#functions/zodAllFactory)
36
- - [zodAsAsyncFactory](#functions/zodAsAsyncFactory)
37
- - [zodAsFactory](#functions/zodAsFactory)
38
- - [zodIsFactory](#functions/zodIsFactory)
39
- - [zodToAsyncFactory](#functions/zodToAsyncFactory)
40
- - [zodToFactory](#functions/zodToFactory)
41
+ | Function | Description |
42
+ | ------ | ------ |
43
+ | [zodAllFactory](#functions/zodAllFactory) | Creates a bundle of `is`, `as`, and `to` factory functions for a given zod schema. |
44
+ | [zodAsAsyncFactory](#functions/zodAsAsyncFactory) | Creates an async function that validates a value against a zod schema and returns it with a narrowed type. Uses `safeParseAsync` for schemas with async refinements. When called without an assert config, returns undefined on failure. |
45
+ | [zodAsFactory](#functions/zodAsFactory) | Creates a function that validates a value against a zod schema and returns it with a narrowed type. When called without an assert config, returns undefined on failure. When called with an assert config, throws on failure. |
46
+ | [zodIsFactory](#functions/zodIsFactory) | Creates a type guard function that checks if a value matches a zod schema. |
47
+ | [zodToAsyncFactory](#functions/zodToAsyncFactory) | Creates an async function that converts a value to the zod schema type, delegating to `zodAsAsyncFactory` internally. Provides overloads for optional assertion: without assert config resolves to undefined on failure, with assert config throws on failure. |
48
+ | [zodToFactory](#functions/zodToFactory) | Creates a function that converts a value to the zod schema type, delegating to `zodAsFactory` internally. Provides overloads for optional assertion: without assert config returns undefined on failure, with assert config throws on failure. |
41
49
 
42
50
  ### functions
43
51
 
@@ -48,34 +56,44 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
48
56
  ***
49
57
 
50
58
  ```ts
51
- function zodAllFactory<T, TName>(zod, name): object;
59
+ function zodAllFactory<T, TName>(zod: ZodType<T>, name: TName): {
60
+ [key: string]: {
61
+ <T> (value: T): T & T | undefined;
62
+ <T> (value: T, assert: ZodFactoryConfig): T & T;
63
+ };
64
+ };
52
65
  ```
53
66
 
54
67
  **`Alpha`**
55
68
 
56
- ## Type Parameters
57
-
58
- ### T
59
-
60
- `T`
69
+ Creates a bundle of `is`, `as`, and `to` factory functions for a given zod schema.
61
70
 
62
- ### TName
71
+ ## Type Parameters
63
72
 
64
- `TName` *extends* `string`
73
+ | Type Parameter |
74
+ | ------ |
75
+ | `T` |
76
+ | `TName` *extends* `string` |
65
77
 
66
78
  ## Parameters
67
79
 
68
- ### zod
69
-
70
- `ZodType`\<`T`\>
71
-
72
- ### name
73
-
74
- `TName`
80
+ | Parameter | Type | Description |
81
+ | ------ | ------ | ------ |
82
+ | `zod` | `ZodType`\<`T`\> | The zod schema to validate against |
83
+ | `name` | `TName` | The name used to suffix the generated function names (e.g. 'Address' produces `isAddress`, `asAddress`, `toAddress`) |
75
84
 
76
85
  ## Returns
77
86
 
78
- `object`
87
+ ```ts
88
+ {
89
+ [key: string]: {
90
+ <T> (value: T): T & T | undefined;
91
+ <T> (value: T, assert: ZodFactoryConfig): T & T;
92
+ };
93
+ }
94
+ ```
95
+
96
+ An object containing `is<Name>`, `as<Name>`, and `to<Name>` functions
79
97
 
80
98
  ### <a id="zodAsAsyncFactory"></a>zodAsAsyncFactory
81
99
 
@@ -84,69 +102,68 @@ function zodAllFactory<T, TName>(zod, name): object;
84
102
  ***
85
103
 
86
104
  ```ts
87
- function zodAsAsyncFactory<TZod>(zod, name): {
88
- <T> (value): Promise<T & TZod | undefined>;
89
- <T> (value, assert): Promise<T & TZod>;
105
+ function zodAsAsyncFactory<TZod>(zod: ZodType<TZod>, name: string): {
106
+ <T> (value: T): Promise<T & TZod | undefined>;
107
+ <T> (value: T, assert: ZodFactoryConfig): Promise<T & TZod>;
90
108
  };
91
109
  ```
92
110
 
93
- ## Type Parameters
111
+ Creates an async function that validates a value against a zod schema and returns it with a narrowed type.
112
+ Uses `safeParseAsync` for schemas with async refinements. When called without an assert config, returns undefined on failure.
94
113
 
95
- ### TZod
114
+ ## Type Parameters
96
115
 
97
- `TZod`
116
+ | Type Parameter |
117
+ | ------ |
118
+ | `TZod` |
98
119
 
99
120
  ## Parameters
100
121
 
101
- ### zod
102
-
103
- `ZodType`\<`TZod`\>
104
-
105
- ### name
106
-
107
- `string`
122
+ | Parameter | Type | Description |
123
+ | ------ | ------ | ------ |
124
+ | `zod` | `ZodType`\<`TZod`\> | The zod schema to validate against |
125
+ | `name` | `string` | A name used in error messages for identification |
108
126
 
109
127
  ## Returns
110
128
 
129
+ An async function that validates and narrows the type of a value
130
+
111
131
  ```ts
112
- <T>(value): Promise<T & TZod | undefined>;
132
+ <T>(value: T): Promise<T & TZod | undefined>;
113
133
  ```
114
134
 
115
135
  ### Type Parameters
116
136
 
117
- ### T
118
-
119
- `T`
137
+ | Type Parameter |
138
+ | ------ |
139
+ | `T` |
120
140
 
121
141
  ### Parameters
122
142
 
123
- ### value
124
-
125
- `T`
143
+ | Parameter | Type |
144
+ | ------ | ------ |
145
+ | `value` | `T` |
126
146
 
127
147
  ### Returns
128
148
 
129
149
  `Promise`\<`T` & `TZod` \| `undefined`\>
130
150
 
131
151
  ```ts
132
- <T>(value, assert): Promise<T & TZod>;
152
+ <T>(value: T, assert: ZodFactoryConfig): Promise<T & TZod>;
133
153
  ```
134
154
 
135
155
  ### Type Parameters
136
156
 
137
- ### T
138
-
139
- `T`
157
+ | Type Parameter |
158
+ | ------ |
159
+ | `T` |
140
160
 
141
161
  ### Parameters
142
162
 
143
- ### value
144
-
145
- `T`
146
-
147
- ### assert
148
-
149
- [`ZodFactoryConfig`](#../type-aliases/ZodFactoryConfig)
163
+ | Parameter | Type |
164
+ | ------ | ------ |
165
+ | `value` | `T` |
166
+ | `assert` | [`ZodFactoryConfig`](#../type-aliases/ZodFactoryConfig) |
150
167
 
151
168
  ### Returns
152
169
 
@@ -159,69 +176,68 @@ function zodAsAsyncFactory<TZod>(zod, name): {
159
176
  ***
160
177
 
161
178
  ```ts
162
- function zodAsFactory<TZod>(zod, name): {
163
- <T> (value): T & TZod | undefined;
164
- <T> (value, assert): T & TZod;
179
+ function zodAsFactory<TZod>(zod: ZodType<TZod>, name: string): {
180
+ <T> (value: T): T & TZod | undefined;
181
+ <T> (value: T, assert: ZodFactoryConfig): T & TZod;
165
182
  };
166
183
  ```
167
184
 
168
- ## Type Parameters
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.
169
187
 
170
- ### TZod
188
+ ## Type Parameters
171
189
 
172
- `TZod`
190
+ | Type Parameter |
191
+ | ------ |
192
+ | `TZod` |
173
193
 
174
194
  ## Parameters
175
195
 
176
- ### zod
177
-
178
- `ZodType`\<`TZod`\>
179
-
180
- ### name
181
-
182
- `string`
196
+ | Parameter | Type | Description |
197
+ | ------ | ------ | ------ |
198
+ | `zod` | `ZodType`\<`TZod`\> | The zod schema to validate against |
199
+ | `name` | `string` | A name used in error messages for identification |
183
200
 
184
201
  ## Returns
185
202
 
203
+ A function that validates and narrows the type of a value
204
+
186
205
  ```ts
187
- <T>(value): T & TZod | undefined;
206
+ <T>(value: T): T & TZod | undefined;
188
207
  ```
189
208
 
190
209
  ### Type Parameters
191
210
 
192
- ### T
193
-
194
- `T`
211
+ | Type Parameter |
212
+ | ------ |
213
+ | `T` |
195
214
 
196
215
  ### Parameters
197
216
 
198
- ### value
199
-
200
- `T`
217
+ | Parameter | Type |
218
+ | ------ | ------ |
219
+ | `value` | `T` |
201
220
 
202
221
  ### Returns
203
222
 
204
223
  `T` & `TZod` \| `undefined`
205
224
 
206
225
  ```ts
207
- <T>(value, assert): T & TZod;
226
+ <T>(value: T, assert: ZodFactoryConfig): T & TZod;
208
227
  ```
209
228
 
210
229
  ### Type Parameters
211
230
 
212
- ### T
213
-
214
- `T`
231
+ | Type Parameter |
232
+ | ------ |
233
+ | `T` |
215
234
 
216
235
  ### Parameters
217
236
 
218
- ### value
219
-
220
- `T`
221
-
222
- ### assert
223
-
224
- [`ZodFactoryConfig`](#../type-aliases/ZodFactoryConfig)
237
+ | Parameter | Type |
238
+ | ------ | ------ |
239
+ | `value` | `T` |
240
+ | `assert` | [`ZodFactoryConfig`](#../type-aliases/ZodFactoryConfig) |
225
241
 
226
242
  ### Returns
227
243
 
@@ -234,38 +250,42 @@ function zodAsFactory<TZod>(zod, name): {
234
250
  ***
235
251
 
236
252
  ```ts
237
- function zodIsFactory<TZod>(zod): <T>(value) => value is T & TZod;
253
+ function zodIsFactory<TZod>(zod: ZodType<TZod>): <T>(value: T) => value is T & TZod;
238
254
  ```
239
255
 
240
- ## Type Parameters
256
+ Creates a type guard function that checks if a value matches a zod schema.
241
257
 
242
- ### TZod
258
+ ## Type Parameters
243
259
 
244
- `TZod`
260
+ | Type Parameter |
261
+ | ------ |
262
+ | `TZod` |
245
263
 
246
264
  ## Parameters
247
265
 
248
- ### zod
249
-
250
- `ZodType`\<`TZod`\>
266
+ | Parameter | Type | Description |
267
+ | ------ | ------ | ------ |
268
+ | `zod` | `ZodType`\<`TZod`\> | The zod schema to validate against |
251
269
 
252
270
  ## Returns
253
271
 
272
+ A type guard function that returns true if the value passes validation
273
+
254
274
  ```ts
255
- <T>(value): value is T & TZod;
275
+ <T>(value: T): value is T & TZod;
256
276
  ```
257
277
 
258
278
  ### Type Parameters
259
279
 
260
- ### T
261
-
262
- `T`
280
+ | Type Parameter |
281
+ | ------ |
282
+ | `T` |
263
283
 
264
284
  ### Parameters
265
285
 
266
- ### value
267
-
268
- `T`
286
+ | Parameter | Type |
287
+ | ------ | ------ |
288
+ | `value` | `T` |
269
289
 
270
290
  ### Returns
271
291
 
@@ -278,69 +298,68 @@ function zodIsFactory<TZod>(zod): <T>(value) => value is T & TZod;
278
298
  ***
279
299
 
280
300
  ```ts
281
- function zodToAsyncFactory<TZod>(zod, name): {
282
- <T> (value): Promise<T & TZod | undefined>;
283
- <T> (value, assert): Promise<T & TZod>;
301
+ function zodToAsyncFactory<TZod>(zod: ZodType<TZod>, name: string): {
302
+ <T> (value: T): Promise<T & TZod | undefined>;
303
+ <T> (value: T, assert: ZodFactoryConfig): Promise<T & TZod>;
284
304
  };
285
305
  ```
286
306
 
287
- ## Type Parameters
307
+ Creates an async function that converts a value to the zod schema type, delegating to `zodAsAsyncFactory` internally.
308
+ Provides overloads for optional assertion: without assert config resolves to undefined on failure, with assert config throws on failure.
288
309
 
289
- ### TZod
310
+ ## Type Parameters
290
311
 
291
- `TZod`
312
+ | Type Parameter |
313
+ | ------ |
314
+ | `TZod` |
292
315
 
293
316
  ## Parameters
294
317
 
295
- ### zod
296
-
297
- `ZodType`\<`TZod`\>
298
-
299
- ### name
300
-
301
- `string`
318
+ | Parameter | Type | Description |
319
+ | ------ | ------ | ------ |
320
+ | `zod` | `ZodType`\<`TZod`\> | The zod schema to validate against |
321
+ | `name` | `string` | A name used in error messages for identification |
302
322
 
303
323
  ## Returns
304
324
 
325
+ An async function that validates and converts a value to the schema type
326
+
305
327
  ```ts
306
- <T>(value): Promise<T & TZod | undefined>;
328
+ <T>(value: T): Promise<T & TZod | undefined>;
307
329
  ```
308
330
 
309
331
  ### Type Parameters
310
332
 
311
- ### T
312
-
313
- `T`
333
+ | Type Parameter |
334
+ | ------ |
335
+ | `T` |
314
336
 
315
337
  ### Parameters
316
338
 
317
- ### value
318
-
319
- `T`
339
+ | Parameter | Type |
340
+ | ------ | ------ |
341
+ | `value` | `T` |
320
342
 
321
343
  ### Returns
322
344
 
323
345
  `Promise`\<`T` & `TZod` \| `undefined`\>
324
346
 
325
347
  ```ts
326
- <T>(value, assert): Promise<T & TZod>;
348
+ <T>(value: T, assert: ZodFactoryConfig): Promise<T & TZod>;
327
349
  ```
328
350
 
329
351
  ### Type Parameters
330
352
 
331
- ### T
332
-
333
- `T`
353
+ | Type Parameter |
354
+ | ------ |
355
+ | `T` |
334
356
 
335
357
  ### Parameters
336
358
 
337
- ### value
338
-
339
- `T`
340
-
341
- ### assert
342
-
343
- [`ZodFactoryConfig`](#../type-aliases/ZodFactoryConfig)
359
+ | Parameter | Type |
360
+ | ------ | ------ |
361
+ | `value` | `T` |
362
+ | `assert` | [`ZodFactoryConfig`](#../type-aliases/ZodFactoryConfig) |
344
363
 
345
364
  ### Returns
346
365
 
@@ -353,69 +372,68 @@ function zodToAsyncFactory<TZod>(zod, name): {
353
372
  ***
354
373
 
355
374
  ```ts
356
- function zodToFactory<TZod>(zod, name): {
357
- <T> (value): T & TZod | undefined;
358
- <T> (value, assert): T & TZod;
375
+ function zodToFactory<TZod>(zod: ZodType<TZod>, name: string): {
376
+ <T> (value: T): T & TZod | undefined;
377
+ <T> (value: T, assert: ZodFactoryConfig): T & TZod;
359
378
  };
360
379
  ```
361
380
 
362
- ## Type Parameters
381
+ Creates a function that converts a value to the zod schema type, delegating to `zodAsFactory` internally.
382
+ Provides overloads for optional assertion: without assert config returns undefined on failure, with assert config throws on failure.
363
383
 
364
- ### TZod
384
+ ## Type Parameters
365
385
 
366
- `TZod`
386
+ | Type Parameter |
387
+ | ------ |
388
+ | `TZod` |
367
389
 
368
390
  ## Parameters
369
391
 
370
- ### zod
371
-
372
- `ZodType`\<`TZod`\>
373
-
374
- ### name
375
-
376
- `string`
392
+ | Parameter | Type | Description |
393
+ | ------ | ------ | ------ |
394
+ | `zod` | `ZodType`\<`TZod`\> | The zod schema to validate against |
395
+ | `name` | `string` | A name used in error messages for identification |
377
396
 
378
397
  ## Returns
379
398
 
399
+ A function that validates and converts a value to the schema type
400
+
380
401
  ```ts
381
- <T>(value): T & TZod | undefined;
402
+ <T>(value: T): T & TZod | undefined;
382
403
  ```
383
404
 
384
405
  ### Type Parameters
385
406
 
386
- ### T
387
-
388
- `T`
407
+ | Type Parameter |
408
+ | ------ |
409
+ | `T` |
389
410
 
390
411
  ### Parameters
391
412
 
392
- ### value
393
-
394
- `T`
413
+ | Parameter | Type |
414
+ | ------ | ------ |
415
+ | `value` | `T` |
395
416
 
396
417
  ### Returns
397
418
 
398
419
  `T` & `TZod` \| `undefined`
399
420
 
400
421
  ```ts
401
- <T>(value, assert): T & TZod;
422
+ <T>(value: T, assert: ZodFactoryConfig): T & TZod;
402
423
  ```
403
424
 
404
425
  ### Type Parameters
405
426
 
406
- ### T
407
-
408
- `T`
427
+ | Type Parameter |
428
+ | ------ |
429
+ | `T` |
409
430
 
410
431
  ### Parameters
411
432
 
412
- ### value
413
-
414
- `T`
415
-
416
- ### assert
417
-
418
- [`ZodFactoryConfig`](#../type-aliases/ZodFactoryConfig)
433
+ | Parameter | Type |
434
+ | ------ | ------ |
435
+ | `value` | `T` |
436
+ | `assert` | [`ZodFactoryConfig`](#../type-aliases/ZodFactoryConfig) |
419
437
 
420
438
  ### Returns
421
439
 
@@ -429,13 +447,13 @@ function zodToFactory<TZod>(zod, name): {
429
447
 
430
448
  ***
431
449
 
432
- ## Properties
450
+ Configuration object for zod factory functions, providing a name for error messages.
433
451
 
434
- ### name
452
+ ## Properties
435
453
 
436
- ```ts
437
- name: string;
438
- ```
454
+ | Property | Type |
455
+ | ------ | ------ |
456
+ | <a id="name"></a> `name` | `string` |
439
457
 
440
458
  ### type-aliases
441
459
 
@@ -453,13 +471,10 @@ type AllZodFactories<TType, TName> = { [K in `is${TName}`]: ReturnType<typeof zo
453
471
 
454
472
  ## Type Parameters
455
473
 
456
- ### TType
457
-
458
- `TType`
459
-
460
- ### TName
461
-
462
- `TName` *extends* `string`
474
+ | Type Parameter |
475
+ | ------ |
476
+ | `TType` |
477
+ | `TName` *extends* `string` |
463
478
 
464
479
  ### <a id="ZodFactoryConfig"></a>ZodFactoryConfig
465
480
 
@@ -473,6 +488,8 @@ type ZodFactoryConfig =
473
488
  | ZodFactoryConfigObject;
474
489
  ```
475
490
 
491
+ Configuration for zod factory assertion behavior, either an AssertConfig or a named config object.
492
+
476
493
 
477
494
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
478
495
 
@@ -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/** @alpha */\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\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\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"]}
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
- /** @alpha */
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,aAAa;AACb,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK;;;;;EAMpF"}
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.83",
3
+ "version": "5.0.86",
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.83",
39
- "@xylabs/typeof": "~5.0.83"
38
+ "@xylabs/error": "~5.0.86",
39
+ "@xylabs/typeof": "~5.0.86"
40
40
  },
41
41
  "devDependencies": {
42
- "@xylabs/ts-scripts-yarn3": "~7.4.11",
43
- "@xylabs/tsconfig": "~7.4.11",
42
+ "@xylabs/ts-scripts-yarn3": "~7.4.16",
43
+ "@xylabs/tsconfig": "~7.4.16",
44
44
  "typescript": "~5.9.3",
45
45
  "vitest": "^4.0.18",
46
46
  "zod": "^4.3.6"