@modulify/validator 0.2.1 → 0.3.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 +27 -1
- package/README.md +12 -2
- package/dist/assert-BDOtHdLx.cjs +289 -0
- package/dist/assert-CzMg5aO7.mjs +206 -0
- package/dist/assert.cjs +7 -65
- package/dist/assert.d.cts +37 -0
- package/dist/assert.d.mts +37 -0
- package/dist/assert.d.ts +24 -3
- package/dist/assert.mjs +2 -66
- package/dist/assertions-DPYCHREw.mjs +297 -0
- package/dist/assertions-nfOKqcjs.cjs +476 -0
- package/dist/assertions.cjs +34 -206
- package/dist/assertions.d.cts +56 -0
- package/dist/assertions.d.mts +56 -0
- package/dist/assertions.d.ts +43 -45
- package/dist/assertions.mjs +3 -207
- package/dist/checkers.d.cts +8 -0
- package/dist/checkers.d.mts +8 -0
- package/dist/checkers.d.ts +1 -1
- package/dist/combinators.cjs +303 -304
- package/dist/combinators.d.cts +16 -0
- package/dist/combinators.d.mts +16 -0
- package/dist/combinators.d.ts +15 -16
- package/dist/combinators.mjs +304 -315
- package/dist/constraints.d.cts +4 -0
- package/dist/constraints.d.mts +4 -0
- package/dist/constraints.d.ts +2 -2
- package/dist/extractors.d.cts +2 -0
- package/dist/extractors.d.mts +2 -0
- package/dist/index.cjs +210 -213
- package/dist/index.d.cts +12 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.mjs +165 -218
- package/dist/json-schema.cjs +364 -489
- package/dist/json-schema.d.cts +14 -0
- package/dist/json-schema.d.mts +14 -0
- package/dist/json-schema.d.ts +3 -3
- package/dist/json-schema.mjs +365 -492
- package/dist/metadata.cjs +6 -7
- package/dist/metadata.d.cts +8 -0
- package/dist/metadata.d.mts +8 -0
- package/dist/metadata.d.ts +2 -2
- package/dist/metadata.mjs +2 -8
- package/dist/predicates.cjs +98 -41
- package/dist/predicates.d.cts +77 -0
- package/dist/predicates.d.mts +77 -0
- package/dist/predicates.d.ts +25 -4
- package/dist/predicates.mjs +92 -66
- package/dist/types/index.d.cts +984 -0
- package/dist/types/index.d.mts +984 -0
- package/dist/types/index.d.ts +984 -0
- package/dist/types/json-schema.d.cts +75 -0
- package/dist/types/json-schema.d.mts +75 -0
- package/dist/types/json-schema.d.ts +75 -0
- package/dist/violations.d.cts +29 -0
- package/dist/violations.d.mts +29 -0
- package/dist/violations.d.ts +1 -1
- package/docs/RELEASING.md +66 -0
- package/docs/en/00-index.md +2 -0
- package/docs/en/01-shape-api.md +35 -10
- package/docs/en/02-metadata-and-introspection.md +2 -1
- package/docs/en/03-violations.md +1 -1
- package/docs/en/04-json-schema-export.md +5 -0
- package/docs/en/05-public-api.md +35 -3
- package/docs/en/06-common-recipes.md +2 -1
- package/docs/en/07-ai-reference.md +5 -2
- package/docs/en/08-violation-code-types.md +28 -2
- package/docs/en/09-migration.md +75 -0
- package/docs/ru/00-index.md +2 -0
- package/docs/ru/01-shape-api.md +35 -10
- package/docs/ru/02-metadata-and-introspection.md +2 -1
- package/docs/ru/03-violations.md +1 -1
- package/docs/ru/04-json-schema-export.md +5 -0
- package/docs/ru/05-public-api.md +35 -3
- package/docs/ru/06-common-recipes.md +2 -1
- package/docs/ru/07-ai-reference.md +5 -2
- package/docs/ru/08-violation-code-types.md +28 -2
- package/docs/ru/09-migration.md +76 -0
- package/docs/ru/README.md +10 -2
- package/package.json +63 -37
- package/types/index.d.ts +275 -115
- package/dist/metadata.cjs.js +0 -130
- package/dist/metadata.es.js +0 -131
package/types/index.d.ts
CHANGED
|
@@ -27,6 +27,9 @@ export type Checker<T, A extends readonly unknown[] = readonly unknown[]> = (val
|
|
|
27
27
|
/** Extracts a derived value from the original input before a checker runs. */
|
|
28
28
|
export type Extractor<T, V> = (value: T) => V
|
|
29
29
|
|
|
30
|
+
/** Public stage marker for assertion pipelines. */
|
|
31
|
+
export type AssertionStage = 'guard' | 'refinement'
|
|
32
|
+
|
|
30
33
|
/** Origin layer that produced a violation. */
|
|
31
34
|
export type ViolationKind = 'assertion' | 'validator' | 'runtime'
|
|
32
35
|
|
|
@@ -63,23 +66,27 @@ type ResolveViolationSubjectArgs<COrT extends string | readonly unknown[], C ext
|
|
|
63
66
|
* `declare module '@modulify/validator' { interface ViolationCodeRegistry { 'legacy.code': never } }`
|
|
64
67
|
*/
|
|
65
68
|
export interface ViolationCodeRegistry {
|
|
69
|
+
'date.valid': ViolationCodeEntry<'assertion', 'isValidDate', readonly []>;
|
|
66
70
|
'length.exact': ViolationCodeEntry<'assertion', 'hasLength', readonly [exact: number]>;
|
|
67
71
|
'length.max': ViolationCodeEntry<'assertion', 'hasLength', readonly [max: number]>;
|
|
68
72
|
'length.min': ViolationCodeEntry<'assertion', 'hasLength', readonly [min: number]>;
|
|
69
73
|
'length.range': ViolationCodeEntry<'assertion', 'hasLength', readonly [range: readonly [number, number]]>;
|
|
70
74
|
'length.unsupported-type': ViolationCodeEntry<'assertion', 'hasLength', readonly []>;
|
|
71
75
|
'number.exact': ViolationCodeEntry<'assertion', 'hasValue', readonly [exact: number]>;
|
|
76
|
+
'number.finite': ViolationCodeEntry<'assertion', 'isFiniteNumber', readonly []>;
|
|
77
|
+
'number.integer': ViolationCodeEntry<'assertion', 'isInteger', readonly []>;
|
|
72
78
|
'number.max': ViolationCodeEntry<'assertion', 'hasValue', readonly [max: number]>;
|
|
73
79
|
'number.min': ViolationCodeEntry<'assertion', 'hasValue', readonly [min: number]>;
|
|
74
80
|
'number.multiple-of': ViolationCodeEntry<'assertion', 'multipleOf', readonly [step: number]>;
|
|
75
81
|
'number.nan': ViolationCodeEntry<'assertion', 'isNaN', readonly []>;
|
|
76
82
|
'number.range': ViolationCodeEntry<'assertion', 'hasValue', readonly [range: readonly [number, number]]>;
|
|
83
|
+
'number.safe-integer': ViolationCodeEntry<'assertion', 'isSafeInteger', readonly []>;
|
|
77
84
|
'number.unsupported-type': ViolationCodeEntry<'assertion', 'hasValue' | 'multipleOf', readonly []>;
|
|
78
85
|
'runtime.rejection': ViolationCodeEntry<'runtime', 'validate', readonly [reason: unknown]>;
|
|
79
86
|
'shape.fields.mismatch': ViolationCodeEntry<
|
|
80
87
|
'validator',
|
|
81
88
|
'shape',
|
|
82
|
-
readonly [selectors: readonly [
|
|
89
|
+
readonly [selectors: readonly [ShapeFieldSelector, ShapeFieldSelector]]
|
|
83
90
|
>;
|
|
84
91
|
'shape.unknown-key': ViolationCodeEntry<'validator', 'shape', readonly []>;
|
|
85
92
|
'size.exact': ViolationCodeEntry<'assertion', 'hasSize', readonly [exact: number]>;
|
|
@@ -102,12 +109,15 @@ export interface ViolationCodeRegistry {
|
|
|
102
109
|
'type.blob': ViolationCodeEntry<'assertion', 'isBlob', readonly []>;
|
|
103
110
|
'type.boolean': ViolationCodeEntry<'assertion', 'isBoolean', readonly []>;
|
|
104
111
|
'type.date': ViolationCodeEntry<'assertion', 'isDate', readonly []>;
|
|
112
|
+
'type.error': ViolationCodeEntry<'assertion', 'isError', readonly []>;
|
|
105
113
|
'type.file': ViolationCodeEntry<'assertion', 'isFile', readonly []>;
|
|
106
114
|
'type.function': ViolationCodeEntry<'assertion', 'isFunction', readonly []>;
|
|
107
115
|
'type.map': ViolationCodeEntry<'assertion', 'isMap', readonly []>;
|
|
108
116
|
'type.null': ViolationCodeEntry<'assertion', 'isNull', readonly []>;
|
|
109
117
|
'type.number': ViolationCodeEntry<'assertion', 'isNumber', readonly []>;
|
|
118
|
+
'type.promise-like': ViolationCodeEntry<'assertion', 'isPromiseLike', readonly []>;
|
|
110
119
|
'type.record': ViolationCodeEntry<'validator', 'shape' | 'discriminatedUnion' | 'record', readonly []>;
|
|
120
|
+
'type.regexp': ViolationCodeEntry<'assertion', 'isRegExp', readonly []>;
|
|
111
121
|
'type.set': ViolationCodeEntry<'assertion', 'isSet', readonly []>;
|
|
112
122
|
'type.string': ViolationCodeEntry<'assertion', 'isString', readonly []>;
|
|
113
123
|
'type.symbol': ViolationCodeEntry<'assertion', 'isSymbol', readonly []>;
|
|
@@ -225,7 +235,7 @@ export declare const collection: <V extends Violation>(violations: readonly V[])
|
|
|
225
235
|
export type ConstraintMetadata = Readonly<Record<string, unknown>>
|
|
226
236
|
|
|
227
237
|
/** Public descriptor entry for additional assertion-level checks. */
|
|
228
|
-
export interface
|
|
238
|
+
export interface AssertionConstraintDescriptor<
|
|
229
239
|
C extends string = string,
|
|
230
240
|
A extends readonly unknown[] = readonly unknown[],
|
|
231
241
|
> {
|
|
@@ -234,7 +244,7 @@ export interface AssertionDescriptorConstraint<
|
|
|
234
244
|
}
|
|
235
245
|
|
|
236
246
|
/** Shared descriptor shape returned by `describe(...)`. */
|
|
237
|
-
export interface
|
|
247
|
+
export interface BaseConstraintDescriptor<K extends string = string> {
|
|
238
248
|
readonly kind: K;
|
|
239
249
|
readonly metadata?: ConstraintMetadata
|
|
240
250
|
}
|
|
@@ -243,8 +253,8 @@ export interface ConstraintDescriptorBase<K extends string = string> {
|
|
|
243
253
|
export interface AssertionDescriptor<
|
|
244
254
|
C extends string = string,
|
|
245
255
|
A extends readonly unknown[] = readonly unknown[],
|
|
246
|
-
T extends readonly
|
|
247
|
-
> extends
|
|
256
|
+
T extends readonly AssertionConstraintDescriptor[] = readonly AssertionConstraintDescriptor[],
|
|
257
|
+
> extends BaseConstraintDescriptor<'assertion'> {
|
|
248
258
|
readonly name: string;
|
|
249
259
|
readonly bail: boolean;
|
|
250
260
|
readonly code: C;
|
|
@@ -253,17 +263,17 @@ export interface AssertionDescriptor<
|
|
|
253
263
|
}
|
|
254
264
|
|
|
255
265
|
/** Generic fallback descriptor for custom validators without structural instrumentation. */
|
|
256
|
-
export type
|
|
266
|
+
export type OpaqueValidatorDescriptor = BaseConstraintDescriptor<'validator'>
|
|
257
267
|
|
|
258
268
|
/** Public extension descriptor for custom validators that expose their own `describe()` contract. */
|
|
259
|
-
export interface CustomConstraintDescriptor<K extends string = string> extends
|
|
269
|
+
export interface CustomConstraintDescriptor<K extends string = string> extends BaseConstraintDescriptor<K> {
|
|
260
270
|
readonly [key: string]: unknown
|
|
261
271
|
}
|
|
262
272
|
|
|
263
273
|
/** Descriptor for sequential arrays of constraints used in a single slot. */
|
|
264
274
|
export interface AllOfConstraintDescriptor<
|
|
265
275
|
T extends readonly unknown[] = readonly ConstraintDescriptor[],
|
|
266
|
-
> extends
|
|
276
|
+
> extends BaseConstraintDescriptor<'allOf'> {
|
|
267
277
|
readonly constraints: T
|
|
268
278
|
}
|
|
269
279
|
|
|
@@ -271,42 +281,42 @@ export interface AllOfConstraintDescriptor<
|
|
|
271
281
|
export interface WrapperConstraintDescriptor<
|
|
272
282
|
K extends 'optional' | 'nullable' | 'nullish' = 'optional' | 'nullable' | 'nullish',
|
|
273
283
|
C = ConstraintDescriptor,
|
|
274
|
-
> extends
|
|
284
|
+
> extends BaseConstraintDescriptor<K> {
|
|
275
285
|
readonly child: C
|
|
276
286
|
}
|
|
277
287
|
|
|
278
288
|
/** Descriptor for `each(...)`. */
|
|
279
289
|
export interface EachConstraintDescriptor<
|
|
280
290
|
C = ConstraintDescriptor,
|
|
281
|
-
> extends
|
|
291
|
+
> extends BaseConstraintDescriptor<'each'> {
|
|
282
292
|
readonly item: C
|
|
283
293
|
}
|
|
284
294
|
|
|
285
295
|
/** Descriptor for `tuple(...)`. */
|
|
286
296
|
export interface TupleConstraintDescriptor<
|
|
287
297
|
T extends readonly unknown[] = readonly ConstraintDescriptor[],
|
|
288
|
-
> extends
|
|
298
|
+
> extends BaseConstraintDescriptor<'tuple'> {
|
|
289
299
|
readonly items: T
|
|
290
300
|
}
|
|
291
301
|
|
|
292
302
|
/** Descriptor for `union(...)`. */
|
|
293
303
|
export interface UnionConstraintDescriptor<
|
|
294
304
|
T extends readonly unknown[] = readonly ConstraintDescriptor[],
|
|
295
|
-
> extends
|
|
305
|
+
> extends BaseConstraintDescriptor<'union'> {
|
|
296
306
|
readonly branches: T
|
|
297
307
|
}
|
|
298
308
|
|
|
299
309
|
/** Descriptor for `record(...)`. */
|
|
300
310
|
export interface RecordConstraintDescriptor<
|
|
301
311
|
C = ConstraintDescriptor,
|
|
302
|
-
> extends
|
|
312
|
+
> extends BaseConstraintDescriptor<'record'> {
|
|
303
313
|
readonly values: C
|
|
304
314
|
}
|
|
305
315
|
|
|
306
316
|
/** Descriptor for `discriminatedUnion(...)`. */
|
|
307
317
|
export interface DiscriminatedUnionConstraintDescriptor<
|
|
308
318
|
V = Readonly<Record<PropertyKey, ConstraintDescriptor>>,
|
|
309
|
-
> extends
|
|
319
|
+
> extends BaseConstraintDescriptor<'discriminatedUnion'> {
|
|
310
320
|
readonly key: PropertyKey;
|
|
311
321
|
readonly variants: V
|
|
312
322
|
}
|
|
@@ -317,29 +327,37 @@ export interface ObjectShapeRuleDescriptorBase<K extends string = string> {
|
|
|
317
327
|
readonly metadata?: ConstraintMetadata
|
|
318
328
|
}
|
|
319
329
|
|
|
320
|
-
/** Generic compact descriptor for sync object-level rules
|
|
321
|
-
export type
|
|
330
|
+
/** Generic compact descriptor for sync-safe object-level rules. */
|
|
331
|
+
export type SyncObjectShapeRuleDescriptor<
|
|
322
332
|
K extends string = 'refine',
|
|
323
333
|
> = ObjectShapeRuleDescriptorBase<K>
|
|
324
334
|
|
|
335
|
+
/** Compact descriptor for object-level rules registered through the async-first `.refine(...)` API. */
|
|
336
|
+
export interface AsyncObjectShapeRuleDescriptor<
|
|
337
|
+
K extends string = 'refine',
|
|
338
|
+
> extends ObjectShapeRuleDescriptorBase<K> {
|
|
339
|
+
readonly async: true
|
|
340
|
+
}
|
|
341
|
+
|
|
325
342
|
/** Descriptor for the built-in `.fieldsMatch(...)` helper. */
|
|
326
343
|
export interface FieldsMatchObjectShapeRuleDescriptor<
|
|
327
|
-
Left extends
|
|
328
|
-
Right extends
|
|
344
|
+
Left extends ShapeFieldSelector = ShapeFieldSelector,
|
|
345
|
+
Right extends ShapeFieldSelector = ShapeFieldSelector,
|
|
329
346
|
> extends ObjectShapeRuleDescriptorBase<'fieldsMatch'> {
|
|
330
347
|
readonly selectors: readonly [Left, Right]
|
|
331
348
|
}
|
|
332
349
|
|
|
333
350
|
/** Machine-readable summary of object-level rules registered on a shape. */
|
|
334
351
|
export type ObjectShapeRuleDescriptor =
|
|
335
|
-
|
|
|
352
|
+
| SyncObjectShapeRuleDescriptor<string>
|
|
353
|
+
| AsyncObjectShapeRuleDescriptor<string>
|
|
336
354
|
| FieldsMatchObjectShapeRuleDescriptor
|
|
337
355
|
|
|
338
356
|
/** Descriptor for `shape(...)`. */
|
|
339
357
|
export interface ShapeConstraintDescriptor<
|
|
340
358
|
F = Readonly<Record<PropertyKey, ConstraintDescriptor>>,
|
|
341
359
|
R extends readonly ObjectShapeRuleDescriptor[] = readonly ObjectShapeRuleDescriptor[],
|
|
342
|
-
> extends
|
|
360
|
+
> extends BaseConstraintDescriptor<'shape'> {
|
|
343
361
|
readonly unknownKeys: UnknownKeysMode;
|
|
344
362
|
readonly fields: F;
|
|
345
363
|
readonly rules: R
|
|
@@ -349,7 +367,7 @@ export interface ShapeConstraintDescriptor<
|
|
|
349
367
|
export type BuiltInConstraintDescriptor =
|
|
350
368
|
| AssertionDescriptor
|
|
351
369
|
| AllOfConstraintDescriptor
|
|
352
|
-
|
|
|
370
|
+
| OpaqueValidatorDescriptor
|
|
353
371
|
| WrapperConstraintDescriptor
|
|
354
372
|
| EachConstraintDescriptor
|
|
355
373
|
| TupleConstraintDescriptor
|
|
@@ -368,9 +386,13 @@ export type ConstraintDescriptor = BuiltInConstraintDescriptor | CustomConstrain
|
|
|
368
386
|
* `type LengthConstraint = AssertionConstraint<string, number, [min: number], 'length.min'>`
|
|
369
387
|
*/
|
|
370
388
|
export type AssertionConstraint<
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
389
|
+
// Defaults erase heterogeneous checker signatures; concrete tuples retain their types.
|
|
390
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
391
|
+
T = any,
|
|
392
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
393
|
+
V = any,
|
|
394
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
395
|
+
A extends readonly unknown[] = any[],
|
|
374
396
|
C extends string = string
|
|
375
397
|
> = readonly [
|
|
376
398
|
Extractor<T, V>,
|
|
@@ -381,13 +403,13 @@ export type AssertionConstraint<
|
|
|
381
403
|
|
|
382
404
|
/** Maps an assertion checker tuple into its public descriptor entry. */
|
|
383
405
|
export type DescribeAssertionConstraint<C extends AssertionConstraint> =
|
|
384
|
-
C extends
|
|
385
|
-
?
|
|
406
|
+
C extends readonly [unknown, unknown, infer Code extends string, ...infer A]
|
|
407
|
+
? AssertionConstraintDescriptor<Code, A>
|
|
386
408
|
: never
|
|
387
409
|
|
|
388
410
|
/** Maps an assertion checker tuple into the violation subject it can produce. */
|
|
389
411
|
export type AssertionConstraintSubject<C extends AssertionConstraint, N extends string = string> =
|
|
390
|
-
C extends
|
|
412
|
+
C extends readonly [unknown, unknown, infer Code extends string, ...infer A]
|
|
391
413
|
? {
|
|
392
414
|
kind: 'assertion';
|
|
393
415
|
name: N;
|
|
@@ -403,6 +425,8 @@ export type DescribeAssertionConstraintTuple<T extends readonly AssertionConstra
|
|
|
403
425
|
: never
|
|
404
426
|
} & ReadonlyArray<DescribeAssertionConstraint<T[number]>>
|
|
405
427
|
|
|
428
|
+
declare const assertionStageBrand: unique symbol
|
|
429
|
+
|
|
406
430
|
/**
|
|
407
431
|
* Leaf-level validator that checks a single value and either succeeds with `null`
|
|
408
432
|
* or returns a structured violation.
|
|
@@ -415,20 +439,42 @@ export type Assertion<
|
|
|
415
439
|
Code extends string = string,
|
|
416
440
|
A extends readonly unknown[] = readonly unknown[],
|
|
417
441
|
Name extends string = string,
|
|
442
|
+
Stage extends AssertionStage = AssertionStage,
|
|
418
443
|
> = ((value: unknown) => MaybePromise<Omit<Violation<
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
444
|
+
Stage extends 'refinement'
|
|
445
|
+
? AssertionConstraintSubject<C[number], Name>
|
|
446
|
+
: {
|
|
447
|
+
kind: 'assertion';
|
|
448
|
+
name: Name;
|
|
449
|
+
code: Code;
|
|
450
|
+
args: A;
|
|
451
|
+
} | AssertionConstraintSubject<C[number], Name>
|
|
425
452
|
>, 'path'> | null>) & {
|
|
426
453
|
readonly name: Name;
|
|
427
454
|
readonly bail: boolean;
|
|
428
455
|
readonly constraints: C;
|
|
429
456
|
readonly check: Predicate<T>;
|
|
457
|
+
readonly [assertionStageBrand]: Stage;
|
|
430
458
|
}
|
|
431
459
|
|
|
460
|
+
/** Assertion stage that establishes the base domain for subsequent checks. */
|
|
461
|
+
export type Guard<
|
|
462
|
+
T = unknown,
|
|
463
|
+
C extends readonly AssertionConstraint[] = readonly AssertionConstraint[],
|
|
464
|
+
Code extends string = string,
|
|
465
|
+
A extends readonly unknown[] = readonly unknown[],
|
|
466
|
+
Name extends string = string,
|
|
467
|
+
> = Assertion<T, C, Code, A, Name, 'guard'>
|
|
468
|
+
|
|
469
|
+
/** Assertion stage that validates properties inside an already established domain. */
|
|
470
|
+
export type Refinement<
|
|
471
|
+
T = unknown,
|
|
472
|
+
C extends readonly AssertionConstraint[] = readonly AssertionConstraint[],
|
|
473
|
+
Code extends string = string,
|
|
474
|
+
A extends readonly unknown[] = readonly unknown[],
|
|
475
|
+
Name extends string = string,
|
|
476
|
+
> = Assertion<T, C, Code, A, Name, 'refinement'>
|
|
477
|
+
|
|
432
478
|
/**
|
|
433
479
|
* Any reusable validation unit: either a leaf `Assertion` or a composed `Validator`.
|
|
434
480
|
*
|
|
@@ -437,14 +483,77 @@ export type Assertion<
|
|
|
437
483
|
*/
|
|
438
484
|
export type Constraint<T = unknown> = Assertion<T> | Validator<T>
|
|
439
485
|
|
|
486
|
+
type ConstraintSequenceState<
|
|
487
|
+
Value,
|
|
488
|
+
Ready extends boolean,
|
|
489
|
+
> = {
|
|
490
|
+
value: Value;
|
|
491
|
+
ready: Ready;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
type ApplyConstraintStep<
|
|
495
|
+
State extends ConstraintSequenceState<unknown, boolean>,
|
|
496
|
+
Step extends Constraint,
|
|
497
|
+
> =
|
|
498
|
+
[Step] extends [Refinement<infer Input, readonly AssertionConstraint[], string, readonly unknown[], string>]
|
|
499
|
+
? State['ready'] extends true
|
|
500
|
+
? [State['value']] extends [Input]
|
|
501
|
+
? ConstraintSequenceState<State['value'], true>
|
|
502
|
+
: never
|
|
503
|
+
: never
|
|
504
|
+
: Step extends Validator<infer Output>
|
|
505
|
+
? ConstraintSequenceState<State['value'] & Output, false>
|
|
506
|
+
: Step extends Assertion<infer Output>
|
|
507
|
+
? ConstraintSequenceState<State['value'] & Output, true>
|
|
508
|
+
: never
|
|
509
|
+
|
|
510
|
+
type CompatibleConstraintTupleState<
|
|
511
|
+
T extends readonly Constraint[],
|
|
512
|
+
State extends ConstraintSequenceState<unknown, boolean> = ConstraintSequenceState<unknown, false>,
|
|
513
|
+
> =
|
|
514
|
+
T extends readonly [infer First extends Constraint, ...infer Rest extends readonly Constraint[]]
|
|
515
|
+
? ApplyConstraintStep<State, First> extends infer Next
|
|
516
|
+
? [Next] extends [never]
|
|
517
|
+
? never
|
|
518
|
+
: Next extends ConstraintSequenceState<unknown, boolean>
|
|
519
|
+
? CompatibleConstraintTupleState<Rest, Next>
|
|
520
|
+
: never
|
|
521
|
+
: never
|
|
522
|
+
: State
|
|
523
|
+
|
|
524
|
+
/** Tuple of sequential constraints with stage-aware assertion compatibility checks. */
|
|
525
|
+
export type CompatibleConstraintTuple<T extends readonly Constraint[] = readonly Constraint[]> =
|
|
526
|
+
number extends T['length']
|
|
527
|
+
? T
|
|
528
|
+
: T extends readonly [Constraint, ...Constraint[]]
|
|
529
|
+
? CompatibleConstraintTupleState<T> extends never
|
|
530
|
+
? never
|
|
531
|
+
: T
|
|
532
|
+
: T
|
|
533
|
+
|
|
534
|
+
/** One-or-many constraint input after applying staged assertion compatibility checks. */
|
|
535
|
+
export type CompatibleConstraints<C> =
|
|
536
|
+
C extends readonly Constraint[]
|
|
537
|
+
? CompatibleConstraintTuple<C>
|
|
538
|
+
: C extends Refinement<unknown, readonly AssertionConstraint[], string, readonly unknown[], string>
|
|
539
|
+
? never
|
|
540
|
+
: C extends Constraint
|
|
541
|
+
? C
|
|
542
|
+
: never
|
|
543
|
+
|
|
440
544
|
/** Extracts the validated TypeScript type from a single constraint. */
|
|
441
545
|
export type InferConstraint<C> =
|
|
442
|
-
C extends Assertion<infer T, readonly AssertionConstraint[], string, readonly unknown[], string>
|
|
546
|
+
C extends Assertion<infer T, readonly AssertionConstraint[], string, readonly unknown[], string, AssertionStage>
|
|
443
547
|
? T
|
|
444
548
|
: C extends Validator<infer T>
|
|
445
549
|
? T
|
|
446
550
|
: never
|
|
447
551
|
|
|
552
|
+
type InferConstraintIntersection<C> =
|
|
553
|
+
(C extends unknown ? (value: InferConstraint<C>) => void : never) extends (value: infer Output) => void
|
|
554
|
+
? Output
|
|
555
|
+
: never
|
|
556
|
+
|
|
448
557
|
/**
|
|
449
558
|
* Extracts the validated TypeScript type from one or many constraints.
|
|
450
559
|
*
|
|
@@ -460,22 +569,28 @@ export type InferConstraints<C> =
|
|
|
460
569
|
C extends readonly []
|
|
461
570
|
? unknown
|
|
462
571
|
: C extends readonly unknown[]
|
|
463
|
-
?
|
|
572
|
+
? number extends C['length']
|
|
573
|
+
? InferConstraintIntersection<C[number]>
|
|
574
|
+
: Intersect<{ [K in keyof C]: InferConstraint<C[K]> }>
|
|
464
575
|
: InferConstraint<C>
|
|
465
576
|
|
|
466
577
|
/** Internal async runner signature used by composed validators. */
|
|
467
|
-
export type Validate = (
|
|
578
|
+
export type Validate = ((
|
|
468
579
|
value: unknown,
|
|
469
|
-
constraints: MaybeMany<Constraint
|
|
580
|
+
constraints: CompatibleConstraints<MaybeMany<Constraint>>,
|
|
470
581
|
path?: PropertyKey[]
|
|
471
|
-
) => Promise<Violation[]>
|
|
582
|
+
) => Promise<Violation[]>) & {
|
|
583
|
+
readonly sync?: false
|
|
584
|
+
}
|
|
472
585
|
|
|
473
586
|
/** Internal sync runner signature used by composed validators. */
|
|
474
|
-
export type ValidateSync = (
|
|
587
|
+
export type ValidateSync = ((
|
|
475
588
|
value: unknown,
|
|
476
|
-
constraints: MaybeMany<Constraint
|
|
589
|
+
constraints: CompatibleConstraints<MaybeMany<Constraint>>,
|
|
477
590
|
path?: PropertyKey[]
|
|
478
|
-
) => Violation[]
|
|
591
|
+
) => Violation[]) & {
|
|
592
|
+
readonly sync: true
|
|
593
|
+
}
|
|
479
594
|
|
|
480
595
|
/** Internal union of async and sync runner signatures. */
|
|
481
596
|
export type ValidateLike = Validate | ValidateSync
|
|
@@ -489,18 +604,18 @@ export type Validation<F extends ValidateLike> = F extends Validate
|
|
|
489
604
|
export type UnknownKeysMode = 'passthrough' | 'strict'
|
|
490
605
|
|
|
491
606
|
/** Field selector accepted by shape helpers that can point to the current level or a nested path. */
|
|
492
|
-
export type
|
|
607
|
+
export type ShapeFieldSelector = PropertyKey | readonly PropertyKey[]
|
|
493
608
|
|
|
494
|
-
type
|
|
495
|
-
type
|
|
609
|
+
type ResolveShapeRefinementViolationCode<COrA extends string | readonly unknown[]> = COrA extends string ? COrA : string
|
|
610
|
+
type ResolveShapeRefinementViolationArgs<COrA extends string | readonly unknown[], C extends string> = [COrA] extends [readonly unknown[]]
|
|
496
611
|
? COrA
|
|
497
612
|
: ViolationArgs<C>
|
|
498
613
|
|
|
499
|
-
/** Machine-readable
|
|
500
|
-
export type
|
|
614
|
+
/** Machine-readable violation input returned by an object-level shape refinement. */
|
|
615
|
+
export type ShapeRefinementViolationInput<
|
|
501
616
|
COrA extends string | readonly unknown[] = string,
|
|
502
|
-
C extends string =
|
|
503
|
-
A extends readonly unknown[] =
|
|
617
|
+
C extends string = ResolveShapeRefinementViolationCode<COrA>,
|
|
618
|
+
A extends readonly unknown[] = ResolveShapeRefinementViolationArgs<COrA, C>,
|
|
504
619
|
> = {
|
|
505
620
|
path?: PropertyKey[];
|
|
506
621
|
code: C;
|
|
@@ -512,18 +627,68 @@ export type ObjectShapeRefinementIssue<
|
|
|
512
627
|
value?: unknown;
|
|
513
628
|
}
|
|
514
629
|
|
|
515
|
-
/** Sync object-level rule that runs after the base shape has validated successfully. */
|
|
516
|
-
export type
|
|
630
|
+
/** Sync-safe object-level rule that runs after the base shape has validated successfully. */
|
|
631
|
+
export type SyncShapeRefinement<
|
|
517
632
|
T,
|
|
518
|
-
I extends
|
|
633
|
+
I extends ShapeRefinementViolationInput = ShapeRefinementViolationInput,
|
|
519
634
|
> = (
|
|
520
635
|
value: T
|
|
521
636
|
) => MaybeMany<I | null | undefined> | null | undefined
|
|
522
637
|
|
|
638
|
+
/** Async-first object-level rule that runs after the base shape has validated successfully. */
|
|
639
|
+
export type ShapeRefinement<
|
|
640
|
+
T,
|
|
641
|
+
I extends ShapeRefinementViolationInput = ShapeRefinementViolationInput,
|
|
642
|
+
> = (
|
|
643
|
+
value: T
|
|
644
|
+
) => MaybePromise<MaybeMany<I | null | undefined> | null | undefined>
|
|
645
|
+
|
|
646
|
+
type AsyncObjectShapeRuleDescriptorOf<RD extends SyncObjectShapeRuleDescriptor<string>> =
|
|
647
|
+
Omit<RD, 'async'> & AsyncObjectShapeRuleDescriptor<RD['kind']>
|
|
648
|
+
|
|
649
|
+
/** Explicitly sync-safe callable helper exposed as `shape(...).refine.sync(...)`. */
|
|
650
|
+
export interface ShapeRefineMethodSync<
|
|
651
|
+
D extends ShapeDescriptor = ShapeDescriptor,
|
|
652
|
+
M extends UnknownKeysMode = UnknownKeysMode,
|
|
653
|
+
R extends readonly ObjectShapeRuleDescriptor[] = readonly ObjectShapeRuleDescriptor[],
|
|
654
|
+
RI extends ShapeRefinementViolationInput = never,
|
|
655
|
+
> {
|
|
656
|
+
<const I extends ShapeRefinementViolationInput = ShapeRefinementViolationInput>(
|
|
657
|
+
refinement: SyncShapeRefinement<InferShape<D>, I>
|
|
658
|
+
): ObjectShape<D, M, [...R, SyncObjectShapeRuleDescriptor<'refine'>], RI | I>;
|
|
659
|
+
<
|
|
660
|
+
const I extends ShapeRefinementViolationInput = ShapeRefinementViolationInput,
|
|
661
|
+
const RD extends SyncObjectShapeRuleDescriptor<string> = SyncObjectShapeRuleDescriptor<'refine'>
|
|
662
|
+
>(
|
|
663
|
+
refinement: SyncShapeRefinement<InferShape<D>, I>,
|
|
664
|
+
descriptor: RD
|
|
665
|
+
): ObjectShape<D, M, [...R, RD], RI | I>;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/** Async-first callable shape helper exposed as `shape(...).refine(...)`. */
|
|
669
|
+
export interface ShapeRefineMethod<
|
|
670
|
+
D extends ShapeDescriptor = ShapeDescriptor,
|
|
671
|
+
M extends UnknownKeysMode = UnknownKeysMode,
|
|
672
|
+
R extends readonly ObjectShapeRuleDescriptor[] = readonly ObjectShapeRuleDescriptor[],
|
|
673
|
+
RI extends ShapeRefinementViolationInput = never,
|
|
674
|
+
> {
|
|
675
|
+
<const I extends ShapeRefinementViolationInput = ShapeRefinementViolationInput>(
|
|
676
|
+
refinement: ShapeRefinement<InferShape<D>, I>
|
|
677
|
+
): ObjectShape<D, M, [...R, AsyncObjectShapeRuleDescriptor<'refine'>], RI | I>;
|
|
678
|
+
<
|
|
679
|
+
const I extends ShapeRefinementViolationInput = ShapeRefinementViolationInput,
|
|
680
|
+
const RD extends SyncObjectShapeRuleDescriptor<string> = SyncObjectShapeRuleDescriptor<'refine'>
|
|
681
|
+
>(
|
|
682
|
+
refinement: ShapeRefinement<InferShape<D>, I>,
|
|
683
|
+
descriptor: RD
|
|
684
|
+
): ObjectShape<D, M, [...R, AsyncObjectShapeRuleDescriptorOf<RD>], RI | I>;
|
|
685
|
+
sync: ShapeRefineMethodSync<D, M, R, RI>;
|
|
686
|
+
}
|
|
687
|
+
|
|
523
688
|
type KnownCodeViolation<C extends KnownViolationCode> = Violation<KnownViolationSubject<C>>
|
|
524
689
|
|
|
525
|
-
type ShapeRefinementIssueSubject<I extends
|
|
526
|
-
I extends
|
|
690
|
+
type ShapeRefinementIssueSubject<I extends ShapeRefinementViolationInput> =
|
|
691
|
+
I extends ShapeRefinementViolationInput<string | readonly unknown[], infer C, infer A>
|
|
527
692
|
? C extends KnownViolationCode
|
|
528
693
|
? {
|
|
529
694
|
kind: 'validator';
|
|
@@ -534,55 +699,57 @@ type ShapeRefinementIssueSubject<I extends ObjectShapeRefinementIssue> =
|
|
|
534
699
|
: ViolationSubject<A, 'validator', C>
|
|
535
700
|
: never
|
|
536
701
|
|
|
537
|
-
type ShapeRefinementIssueViolation<I extends
|
|
538
|
-
I extends
|
|
702
|
+
type ShapeRefinementIssueViolation<I extends ShapeRefinementViolationInput> =
|
|
703
|
+
I extends ShapeRefinementViolationInput
|
|
539
704
|
? Violation<ShapeRefinementIssueSubject<I>>
|
|
540
705
|
: never
|
|
541
706
|
|
|
542
|
-
type
|
|
543
|
-
[K in keyof D]:
|
|
707
|
+
type InferShapeViolations<D extends ShapeDescriptor> = {
|
|
708
|
+
[K in keyof D]: InferViolations<D[K]>
|
|
544
709
|
}[keyof D]
|
|
545
710
|
|
|
546
711
|
/** Maps a single constraint into the union of violations it can produce. */
|
|
547
712
|
export type InferConstraintViolations<C extends Constraint> =
|
|
548
|
-
C extends
|
|
713
|
+
C extends Guard<unknown, infer AC, infer Code, infer Args, infer Name>
|
|
549
714
|
? Violation<{
|
|
550
715
|
kind: 'assertion';
|
|
551
716
|
name: Name;
|
|
552
717
|
code: Code;
|
|
553
718
|
args: Args;
|
|
554
719
|
} | AssertionConstraintSubject<AC[number], Name>>
|
|
720
|
+
: C extends Refinement<unknown, infer AC, string, readonly unknown[], infer Name>
|
|
721
|
+
? Violation<AssertionConstraintSubject<AC[number], Name>>
|
|
555
722
|
: C extends ObjectShape<infer D, infer M, readonly ObjectShapeRuleDescriptor[], infer RI>
|
|
556
723
|
? KnownCodeViolation<'type.record'>
|
|
557
724
|
| (M extends 'strict' ? KnownCodeViolation<'shape.unknown-key'> : never)
|
|
558
|
-
|
|
|
725
|
+
| InferShapeViolations<D>
|
|
559
726
|
| ShapeRefinementIssueViolation<RI>
|
|
560
727
|
: C extends OptionalValidator<infer Child>
|
|
561
|
-
?
|
|
728
|
+
? InferViolations<Child>
|
|
562
729
|
: C extends NullableValidator<infer Child>
|
|
563
|
-
?
|
|
730
|
+
? InferViolations<Child>
|
|
564
731
|
: C extends NullishValidator<infer Child>
|
|
565
|
-
?
|
|
732
|
+
? InferViolations<Child>
|
|
566
733
|
: C extends EachValidator<infer Child>
|
|
567
|
-
? KnownCodeViolation<'type.array'> |
|
|
734
|
+
? KnownCodeViolation<'type.array'> | InferViolations<Child>
|
|
568
735
|
: C extends TupleValidator<infer Items>
|
|
569
736
|
? KnownCodeViolation<'type.array'>
|
|
570
737
|
| KnownCodeViolation<'tuple.length'>
|
|
571
|
-
|
|
|
738
|
+
| InferViolations<Items[number]>
|
|
572
739
|
: C extends UnionValidator<infer Branches>
|
|
573
|
-
? KnownCodeViolation<'union.no-match'> |
|
|
740
|
+
? KnownCodeViolation<'union.no-match'> | InferViolations<Branches[number]>
|
|
574
741
|
: C extends DiscriminatedUnionValidator<PropertyKey, infer Variants>
|
|
575
742
|
? KnownCodeViolation<'type.record'>
|
|
576
743
|
| KnownCodeViolation<'union.invalid-discriminator'>
|
|
577
|
-
|
|
|
744
|
+
| InferViolations<Variants[keyof Variants]>
|
|
578
745
|
: C extends RecordValidator<infer Values>
|
|
579
|
-
? KnownCodeViolation<'type.record'> |
|
|
746
|
+
? KnownCodeViolation<'type.record'> | InferViolations<Values>
|
|
580
747
|
: C extends Validator
|
|
581
748
|
? Violation
|
|
582
749
|
: never
|
|
583
750
|
|
|
584
751
|
/** Maps one-or-many constraints into the union of violations they can produce. */
|
|
585
|
-
export type
|
|
752
|
+
export type InferViolations<C extends MaybeMany<Constraint>> =
|
|
586
753
|
C extends readonly []
|
|
587
754
|
? never
|
|
588
755
|
: C extends readonly Constraint[]
|
|
@@ -598,7 +765,7 @@ export type ValidationSuccess<T> = [ok: true, validated: T, violations: []]
|
|
|
598
765
|
export type ValidationFailure<V extends Violation = Violation> = [ok: false, validated: unknown, violations: V[]]
|
|
599
766
|
|
|
600
767
|
/**
|
|
601
|
-
* The result
|
|
768
|
+
* The result returned by `validate(...)` and `validate.sync(...)`.
|
|
602
769
|
*
|
|
603
770
|
* Example:
|
|
604
771
|
* `const [ok, validated, violations] = await validate(value, schema)`
|
|
@@ -606,10 +773,7 @@ export type ValidationFailure<V extends Violation = Violation> = [ok: false, val
|
|
|
606
773
|
* Example:
|
|
607
774
|
* `if (ok) validated.name.toUpperCase()`
|
|
608
775
|
*/
|
|
609
|
-
export type
|
|
610
|
-
|
|
611
|
-
/** Alias for `ValidationTuple<T>`. */
|
|
612
|
-
export type ValidationResult<T, V extends Violation = Violation> = ValidationTuple<T, V>
|
|
776
|
+
export type ValidationResult<T, V extends Violation = Violation> = ValidationSuccess<T> | ValidationFailure<V>
|
|
613
777
|
|
|
614
778
|
/** Attaches read-only metadata to a constraint without changing validation semantics. */
|
|
615
779
|
export declare const meta: <const C extends Constraint, const M extends ConstraintMetadata>(constraint: C, metadata: M) => C
|
|
@@ -644,22 +808,27 @@ export interface DescribedValidator<
|
|
|
644
808
|
export declare const custom: <const V extends Validator>(validator: V) => V
|
|
645
809
|
|
|
646
810
|
/** Descriptor that maps object keys to one or many constraints. */
|
|
647
|
-
export type
|
|
811
|
+
export type ShapeDescriptor = Record<PropertyKey, MaybeMany<Constraint>>
|
|
812
|
+
|
|
813
|
+
/** Shape descriptor with stage-aware compatibility checks applied to every field slot. */
|
|
814
|
+
export type CompatibleShapeDescriptor<D extends ShapeDescriptor> = {
|
|
815
|
+
[K in keyof D]: CompatibleConstraints<D[K]>
|
|
816
|
+
}
|
|
648
817
|
|
|
649
|
-
/** Runtime type inferred from
|
|
650
|
-
export type
|
|
818
|
+
/** Runtime type inferred from a shape descriptor. */
|
|
819
|
+
export type InferShape<D extends ShapeDescriptor> = {
|
|
651
820
|
[K in keyof D]: InferConstraints<D[K]>
|
|
652
821
|
}
|
|
653
822
|
|
|
654
823
|
/** Descriptor produced by `.partial()` where every field accepts `undefined`. */
|
|
655
|
-
export type
|
|
824
|
+
export type PartialShapeDescriptor<D extends ShapeDescriptor> = {
|
|
656
825
|
[K in keyof D]: Validator<InferConstraints<D[K]> | undefined>
|
|
657
826
|
}
|
|
658
827
|
|
|
659
828
|
/** Utility type for overriding descriptor keys from left to right. */
|
|
660
|
-
export type
|
|
661
|
-
Left extends
|
|
662
|
-
Right extends
|
|
829
|
+
export type MergeShapeDescriptors<
|
|
830
|
+
Left extends ShapeDescriptor,
|
|
831
|
+
Right extends ShapeDescriptor,
|
|
663
832
|
> = Omit<Left, keyof Right> & Right
|
|
664
833
|
|
|
665
834
|
/**
|
|
@@ -669,67 +838,58 @@ export type MergeObjectDescriptors<
|
|
|
669
838
|
* `const user = shape({ name: isString }).strict()`
|
|
670
839
|
*/
|
|
671
840
|
export interface ObjectShape<
|
|
672
|
-
D extends
|
|
841
|
+
D extends ShapeDescriptor = ShapeDescriptor,
|
|
673
842
|
M extends UnknownKeysMode = 'passthrough',
|
|
674
843
|
R extends readonly ObjectShapeRuleDescriptor[] = readonly ObjectShapeRuleDescriptor[],
|
|
675
|
-
RI extends
|
|
676
|
-
> extends Validator<
|
|
844
|
+
RI extends ShapeRefinementViolationInput = never,
|
|
845
|
+
> extends Validator<InferShape<D>> {
|
|
677
846
|
readonly descriptor: D;
|
|
678
847
|
readonly unknownKeys: M;
|
|
679
|
-
refine<
|
|
680
|
-
|
|
681
|
-
): ObjectShape<D, M, [...R, GenericObjectShapeRuleDescriptor<'refine'>], RI | I>;
|
|
682
|
-
refine<
|
|
683
|
-
const I extends ObjectShapeRefinementIssue = ObjectShapeRefinementIssue,
|
|
684
|
-
const RD extends GenericObjectShapeRuleDescriptor<string> = GenericObjectShapeRuleDescriptor<'refine'>
|
|
685
|
-
>(
|
|
686
|
-
refinement: ObjectShapeRefinement<InferObjectDescriptor<D>, I>,
|
|
687
|
-
descriptor: RD
|
|
688
|
-
): ObjectShape<D, M, [...R, RD], RI | I>;
|
|
689
|
-
fieldsMatch<const K extends readonly [ObjectShapeFieldSelector, ObjectShapeFieldSelector]>(
|
|
848
|
+
readonly refine: ShapeRefineMethod<D, M, R, RI>;
|
|
849
|
+
fieldsMatch<const K extends readonly [ShapeFieldSelector, ShapeFieldSelector]>(
|
|
690
850
|
keys: K
|
|
691
|
-
): ObjectShape<D, M, [...R, FieldsMatchObjectShapeRuleDescriptor<K[0], K[1]>], RI |
|
|
851
|
+
): ObjectShape<D, M, [...R, FieldsMatchObjectShapeRuleDescriptor<K[0], K[1]>], RI | ShapeRefinementViolationInput<'shape.fields.mismatch'>>;
|
|
692
852
|
strict(): ObjectShape<D, 'strict', R, RI>;
|
|
693
853
|
passthrough(): ObjectShape<D, 'passthrough', R, RI>;
|
|
694
854
|
pick<const K extends readonly (keyof D)[]>(keys: K): ObjectShape<Pick<D, K[number]>, M, [], never>;
|
|
695
855
|
omit<const K extends readonly (keyof D)[]>(keys: K): ObjectShape<Omit<D, K[number]>, M, [], never>;
|
|
696
|
-
partial(): ObjectShape<
|
|
697
|
-
extend<const E extends
|
|
698
|
-
merge<const E extends
|
|
699
|
-
shape: ObjectShape<E, OM, OR,
|
|
700
|
-
): ObjectShape<
|
|
856
|
+
partial(): ObjectShape<PartialShapeDescriptor<D>, M, [], never>;
|
|
857
|
+
extend<const E extends ShapeDescriptor>(descriptor: E): ObjectShape<MergeShapeDescriptors<D, E>, M, [], never>;
|
|
858
|
+
merge<const E extends ShapeDescriptor, OM extends UnknownKeysMode, OR extends readonly ObjectShapeRuleDescriptor[]>(
|
|
859
|
+
shape: ObjectShape<E, OM, OR, ShapeRefinementViolationInput>
|
|
860
|
+
): ObjectShape<MergeShapeDescriptors<D, E>, M, [], never>;
|
|
701
861
|
}
|
|
702
862
|
|
|
703
863
|
/** Helper that maps a single constraint into its public `describe(...)` result. */
|
|
704
864
|
export type DescribeConstraint<C extends Constraint> =
|
|
705
|
-
C extends Assertion<unknown, infer AC, infer Code, infer Args, string>
|
|
865
|
+
C extends Assertion<unknown, infer AC, infer Code, infer Args, string, AssertionStage>
|
|
706
866
|
? AssertionDescriptor<Code, Args, DescribeAssertionConstraintTuple<AC>>
|
|
707
|
-
: C extends ObjectShape<infer D, infer M, infer R,
|
|
708
|
-
? ShapeConstraintDescriptor<
|
|
867
|
+
: C extends ObjectShape<infer D, infer M, infer R, ShapeRefinementViolationInput>
|
|
868
|
+
? ShapeConstraintDescriptor<DescribeShapeDescriptor<D>, R> & { readonly unknownKeys: M }
|
|
709
869
|
: C extends OptionalValidator<infer Child>
|
|
710
|
-
? WrapperConstraintDescriptor<'optional',
|
|
870
|
+
? WrapperConstraintDescriptor<'optional', DescribeConstraints<Child>>
|
|
711
871
|
: C extends NullableValidator<infer Child>
|
|
712
|
-
? WrapperConstraintDescriptor<'nullable',
|
|
872
|
+
? WrapperConstraintDescriptor<'nullable', DescribeConstraints<Child>>
|
|
713
873
|
: C extends NullishValidator<infer Child>
|
|
714
|
-
? WrapperConstraintDescriptor<'nullish',
|
|
874
|
+
? WrapperConstraintDescriptor<'nullish', DescribeConstraints<Child>>
|
|
715
875
|
: C extends EachValidator<infer Child>
|
|
716
|
-
? EachConstraintDescriptor<
|
|
876
|
+
? EachConstraintDescriptor<DescribeConstraints<Child>>
|
|
717
877
|
: C extends TupleValidator<infer Items>
|
|
718
878
|
? TupleConstraintDescriptor<DescribeConstraintTuple<Items>>
|
|
719
879
|
: C extends UnionValidator<infer Branches>
|
|
720
880
|
? UnionConstraintDescriptor<DescribeConstraintTuple<Branches>>
|
|
721
881
|
: C extends DiscriminatedUnionValidator<PropertyKey, infer Variants>
|
|
722
|
-
? DiscriminatedUnionConstraintDescriptor<
|
|
882
|
+
? DiscriminatedUnionConstraintDescriptor<DescribeShapeDescriptor<Variants>>
|
|
723
883
|
: C extends RecordValidator<infer Values>
|
|
724
|
-
? RecordConstraintDescriptor<
|
|
884
|
+
? RecordConstraintDescriptor<DescribeConstraints<Values>>
|
|
725
885
|
: C extends DescribedValidator<unknown, infer D>
|
|
726
886
|
? D & { readonly metadata?: ConstraintMetadata }
|
|
727
887
|
: C extends Validator
|
|
728
|
-
?
|
|
888
|
+
? OpaqueValidatorDescriptor
|
|
729
889
|
: never
|
|
730
890
|
|
|
731
891
|
/** Helper that maps a one-or-many constraint slot into its public `describe(...)` result. */
|
|
732
|
-
export type
|
|
892
|
+
export type DescribeConstraints<C extends MaybeMany<Constraint>> =
|
|
733
893
|
C extends readonly [infer Only]
|
|
734
894
|
? Only extends Constraint
|
|
735
895
|
? DescribeConstraint<Only>
|
|
@@ -743,14 +903,14 @@ export type DescribeMaybeMany<C extends MaybeMany<Constraint>> =
|
|
|
743
903
|
: never
|
|
744
904
|
|
|
745
905
|
/** Helper that maps object descriptors into their `describe(...)` field tree. */
|
|
746
|
-
export type
|
|
747
|
-
[K in keyof D]:
|
|
906
|
+
export type DescribeShapeDescriptor<D extends ShapeDescriptor> = {
|
|
907
|
+
[K in keyof D]: DescribeConstraints<D[K]>
|
|
748
908
|
}
|
|
749
909
|
|
|
750
910
|
/** Helper that maps tuples of constraints into tuples of descriptors. */
|
|
751
911
|
export type DescribeConstraintTuple<T extends readonly MaybeMany<Constraint>[]> = {
|
|
752
|
-
readonly [K in keyof T]:
|
|
753
|
-
} & ReadonlyArray<
|
|
912
|
+
readonly [K in keyof T]: DescribeConstraints<T[K]>
|
|
913
|
+
} & ReadonlyArray<DescribeConstraints<T[number]>>
|
|
754
914
|
|
|
755
915
|
declare const optionalValidatorBrand: unique symbol
|
|
756
916
|
declare const nullableValidatorBrand: unique symbol
|