1 |
|
2 |
|
3 |
|
4 | import { Either } from 'fp-ts/es6/Either'
|
5 | import { Predicate, Refinement } from 'fp-ts/es6/function'
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export interface ContextEntry {
|
11 | readonly key: string
|
12 | readonly type: Decoder<any, any>
|
13 |
|
14 | readonly actual?: unknown
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export interface Context extends ReadonlyArray<ContextEntry> {}
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export interface ValidationError {
|
26 |
|
27 | readonly value: unknown
|
28 |
|
29 | readonly context: Context
|
30 |
|
31 | readonly message?: string
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | export interface Errors extends Array<ValidationError> {}
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export declare type Validation<A> = Either<Errors, A>
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | export declare const failures: <T>(errors: Errors) => Validation<T>
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | export declare const failure: <T>(value: unknown, context: Context, message?: string | undefined) => Either<Errors, T>
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | export declare const success: <T>(value: T) => Validation<T>
|
58 |
|
59 |
|
60 |
|
61 | export declare type Is<A> = (u: unknown) => u is A
|
62 |
|
63 |
|
64 |
|
65 | export declare type Validate<I, A> = (i: I, context: Context) => Validation<A>
|
66 |
|
67 |
|
68 |
|
69 | export declare type Decode<I, A> = (i: I) => Validation<A>
|
70 |
|
71 |
|
72 |
|
73 | export declare type Encode<A, O> = (a: A) => O
|
74 |
|
75 |
|
76 |
|
77 | export interface Any extends Type<any, any, any> {}
|
78 |
|
79 |
|
80 |
|
81 | export interface Mixed extends Type<any, any, unknown> {}
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | export declare type TypeOf<C extends Any> = C['_A']
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | export declare type InputOf<C extends Any> = C['_I']
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | export declare type OutputOf<C extends Any> = C['_O']
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | export interface Decoder<I, A> {
|
102 | readonly name: string
|
103 | readonly validate: Validate<I, A>
|
104 | readonly decode: Decode<I, A>
|
105 | }
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | export interface Encoder<A, O> {
|
111 | readonly encode: Encode<A, O>
|
112 | }
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | export declare class Type<A, O = A, I = unknown> implements Decoder<I, A>, Encoder<A, O> {
|
118 |
|
119 | readonly name: string
|
120 |
|
121 | readonly is: Is<A>
|
122 |
|
123 | readonly validate: Validate<I, A>
|
124 |
|
125 | readonly encode: Encode<A, O>
|
126 | |
127 |
|
128 |
|
129 | readonly _A: A
|
130 | |
131 |
|
132 |
|
133 | readonly _O: O
|
134 | |
135 |
|
136 |
|
137 | readonly _I: I
|
138 | constructor(
|
139 |
|
140 | name: string,
|
141 |
|
142 | is: Is<A>,
|
143 |
|
144 | validate: Validate<I, A>,
|
145 |
|
146 | encode: Encode<A, O>
|
147 | )
|
148 | /**
|
149 | * @since 1.0.0
|
150 | */
|
151 | pipe<B, IB, A extends IB, OB extends A>(this: Type<A, O, I>, ab: Type<B, OB, IB>, name?: string): Type<B, O, I>
|
152 | /**
|
153 | * @since 1.0.0
|
154 | */
|
155 | asDecoder(): Decoder<I, A>
|
156 | /**
|
157 | * @since 1.0.0
|
158 | */
|
159 | asEncoder(): Encoder<A, O>
|
160 | /**
|
161 | * a version of `validate` with a default context
|
162 | * @since 1.0.0
|
163 | */
|
164 | decode(i: I): Validation<A>
|
165 | }
|
166 | /**
|
167 | * @since 1.0.0
|
168 | */
|
169 | export declare const identity: <A>(a: A) => A
|
170 | /**
|
171 | * @since 1.0.0
|
172 | */
|
173 | export declare function getFunctionName(f: Function): string
|
174 | /**
|
175 | * @since 1.0.0
|
176 | */
|
177 | export declare function getContextEntry(key: string, decoder: Decoder<any, any>): ContextEntry
|
178 | /**
|
179 | * @since 1.0.0
|
180 | */
|
181 | export declare function appendContext(c: Context, key: string, decoder: Decoder<any, any>, actual?: unknown): Context
|
182 | /**
|
183 | * @since 1.0.0
|
184 | */
|
185 | export interface AnyProps {
|
186 | [key: string]: Any
|
187 | }
|
188 |
|
189 |
|
190 |
|
191 | export declare type TypeOfProps<P extends AnyProps> = {
|
192 | [K in keyof P]: TypeOf<P[K]>
|
193 | }
|
194 |
|
195 |
|
196 |
|
197 | export declare type OutputOfProps<P extends AnyProps> = {
|
198 | [K in keyof P]: OutputOf<P[K]>
|
199 | }
|
200 |
|
201 |
|
202 |
|
203 | export interface Props {
|
204 | [key: string]: Mixed
|
205 | }
|
206 |
|
207 |
|
208 |
|
209 | export declare type TypeOfPartialProps<P extends AnyProps> = {
|
210 | [K in keyof P]?: TypeOf<P[K]>
|
211 | }
|
212 |
|
213 |
|
214 |
|
215 | export declare type OutputOfPartialProps<P extends AnyProps> = {
|
216 | [K in keyof P]?: OutputOf<P[K]>
|
217 | }
|
218 |
|
219 |
|
220 |
|
221 | export declare type TypeOfDictionary<D extends Any, C extends Any> = {
|
222 | [K in TypeOf<D>]: TypeOf<C>
|
223 | }
|
224 |
|
225 |
|
226 |
|
227 | export declare type OutputOfDictionary<D extends Any, C extends Any> = {
|
228 | [K in OutputOf<D>]: OutputOf<C>
|
229 | }
|
230 |
|
231 |
|
232 |
|
233 | export interface HasPropsRefinement extends RefinementType<HasProps, any, any, any> {}
|
234 |
|
235 |
|
236 |
|
237 | export interface HasPropsReadonly extends ReadonlyType<HasProps, any, any, any> {}
|
238 |
|
239 |
|
240 |
|
241 | export interface HasPropsIntersection extends IntersectionType<Array<HasProps>, any, any, any> {}
|
242 |
|
243 |
|
244 |
|
245 | export declare type HasProps =
|
246 | | HasPropsRefinement
|
247 | | HasPropsReadonly
|
248 | | HasPropsIntersection
|
249 | | InterfaceType<any, any, any, any>
|
250 | | StrictType<any, any, any, any>
|
251 | | PartialType<any, any, any, any>
|
252 |
|
253 |
|
254 |
|
255 | export declare class NullType extends Type<null> {
|
256 | |
257 |
|
258 |
|
259 | readonly _tag: 'NullType'
|
260 | constructor()
|
261 | }
|
262 | /**
|
263 | * @since 1.5.3
|
264 | */
|
265 | export interface NullC extends NullType {}
|
266 |
|
267 |
|
268 |
|
269 |
|
270 | export declare const nullType: NullC
|
271 |
|
272 |
|
273 |
|
274 | export declare class UndefinedType extends Type<undefined> {
|
275 | |
276 |
|
277 |
|
278 | readonly _tag: 'UndefinedType'
|
279 | constructor()
|
280 | }
|
281 | /**
|
282 | * @since 1.5.3
|
283 | */
|
284 | export interface UndefinedC extends UndefinedType {}
|
285 | declare const undefinedType: UndefinedC
|
286 |
|
287 |
|
288 |
|
289 | export declare class VoidType extends Type<void> {
|
290 | |
291 |
|
292 |
|
293 | readonly _tag: 'VoidType'
|
294 | constructor()
|
295 | }
|
296 | /**
|
297 | * @since 1.5.3
|
298 | */
|
299 | export interface VoidC extends VoidType {}
|
300 |
|
301 |
|
302 |
|
303 |
|
304 | export declare const voidType: VoidC
|
305 |
|
306 |
|
307 |
|
308 | export declare class UnknownType extends Type<unknown> {
|
309 | |
310 |
|
311 |
|
312 | readonly _tag: 'UnknownType'
|
313 | constructor()
|
314 | }
|
315 | /**
|
316 | * @since 1.5.3
|
317 | */
|
318 | export interface UnknownC extends UnknownType {}
|
319 |
|
320 |
|
321 |
|
322 |
|
323 | export declare const unknown: UnknownC
|
324 |
|
325 |
|
326 |
|
327 | export declare class StringType extends Type<string> {
|
328 | |
329 |
|
330 |
|
331 | readonly _tag: 'StringType'
|
332 | constructor()
|
333 | }
|
334 | /**
|
335 | * @since 1.5.3
|
336 | */
|
337 | export interface StringC extends StringType {}
|
338 |
|
339 |
|
340 |
|
341 |
|
342 | export declare const string: StringC
|
343 |
|
344 |
|
345 |
|
346 | export declare class NumberType extends Type<number> {
|
347 | |
348 |
|
349 |
|
350 | readonly _tag: 'NumberType'
|
351 | constructor()
|
352 | }
|
353 | /**
|
354 | * @since 1.5.3
|
355 | */
|
356 | export interface NumberC extends NumberType {}
|
357 |
|
358 |
|
359 |
|
360 |
|
361 | export declare const number: NumberC
|
362 |
|
363 |
|
364 |
|
365 | export declare class BigIntType extends Type<bigint> {
|
366 | |
367 |
|
368 |
|
369 | readonly _tag: 'BigIntType'
|
370 | constructor()
|
371 | }
|
372 | /**
|
373 | * @since 2.1.0
|
374 | */
|
375 | export interface BigIntC extends BigIntType {}
|
376 |
|
377 |
|
378 |
|
379 |
|
380 | export declare const bigint: BigIntC
|
381 |
|
382 |
|
383 |
|
384 | export declare class BooleanType extends Type<boolean> {
|
385 | |
386 |
|
387 |
|
388 | readonly _tag: 'BooleanType'
|
389 | constructor()
|
390 | }
|
391 | /**
|
392 | * @since 1.5.3
|
393 | */
|
394 | export interface BooleanC extends BooleanType {}
|
395 |
|
396 |
|
397 |
|
398 |
|
399 | export declare const boolean: BooleanC
|
400 |
|
401 |
|
402 |
|
403 | export declare class AnyArrayType extends Type<Array<unknown>> {
|
404 | |
405 |
|
406 |
|
407 | readonly _tag: 'AnyArrayType'
|
408 | constructor()
|
409 | }
|
410 | /**
|
411 | * @since 1.5.3
|
412 | */
|
413 | export interface UnknownArrayC extends AnyArrayType {}
|
414 |
|
415 |
|
416 |
|
417 |
|
418 | export declare const UnknownArray: UnknownArrayC
|
419 |
|
420 |
|
421 |
|
422 | export declare class AnyDictionaryType extends Type<{
|
423 | [key: string]: unknown
|
424 | }> {
|
425 | |
426 |
|
427 |
|
428 | readonly _tag: 'AnyDictionaryType'
|
429 | constructor()
|
430 | }
|
431 | /**
|
432 | * @since 1.5.3
|
433 | */
|
434 | export interface UnknownRecordC extends AnyDictionaryType {}
|
435 |
|
436 |
|
437 |
|
438 |
|
439 | export declare const UnknownRecord: UnknownRecordC
|
440 | export {
|
441 | |
442 |
|
443 |
|
444 |
|
445 | nullType as null,
|
446 | |
447 |
|
448 |
|
449 |
|
450 | undefinedType as undefined,
|
451 | |
452 |
|
453 |
|
454 |
|
455 | voidType as void
|
456 | }
|
457 | declare type LiteralValue = string | number | boolean
|
458 |
|
459 |
|
460 |
|
461 | export declare class LiteralType<V extends LiteralValue> extends Type<V> {
|
462 | readonly value: V
|
463 | |
464 |
|
465 |
|
466 | readonly _tag: 'LiteralType'
|
467 | constructor(
|
468 | name: string,
|
469 | is: LiteralType<V>['is'],
|
470 | validate: LiteralType<V>['validate'],
|
471 | encode: LiteralType<V>['encode'],
|
472 | value: V
|
473 | )
|
474 | }
|
475 | /**
|
476 | * @since 1.5.3
|
477 | */
|
478 | export interface LiteralC<V extends LiteralValue> extends LiteralType<V> {}
|
479 |
|
480 |
|
481 |
|
482 |
|
483 | export declare function literal<V extends LiteralValue>(value: V, name?: string): LiteralC<V>
|
484 | /**
|
485 | * @since 1.0.0
|
486 | */
|
487 | export declare class KeyofType<
|
488 | D extends {
|
489 | [key: string]: unknown
|
490 | }
|
491 | > extends Type<keyof D> {
|
492 | readonly keys: D
|
493 | |
494 |
|
495 |
|
496 | readonly _tag: 'KeyofType'
|
497 | constructor(
|
498 | name: string,
|
499 | is: KeyofType<D>['is'],
|
500 | validate: KeyofType<D>['validate'],
|
501 | encode: KeyofType<D>['encode'],
|
502 | keys: D
|
503 | )
|
504 | }
|
505 | /**
|
506 | * @since 1.5.3
|
507 | */
|
508 | export interface KeyofC<
|
509 | D extends {
|
510 | [key: string]: unknown
|
511 | }
|
512 | > extends KeyofType<D> {}
|
513 |
|
514 |
|
515 |
|
516 |
|
517 | export declare function keyof<
|
518 | D extends {
|
519 | [key: string]: unknown
|
520 | }
|
521 | >(keys: D, name?: string): KeyofC<D>
|
522 |
|
523 |
|
524 |
|
525 | export declare class RefinementType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
526 | readonly type: C
|
527 | readonly predicate: Predicate<A>
|
528 | |
529 |
|
530 |
|
531 | readonly _tag: 'RefinementType'
|
532 | constructor(
|
533 | name: string,
|
534 | is: RefinementType<C, A, O, I>['is'],
|
535 | validate: RefinementType<C, A, O, I>['validate'],
|
536 | encode: RefinementType<C, A, O, I>['encode'],
|
537 | type: C,
|
538 | predicate: Predicate<A>
|
539 | )
|
540 | }
|
541 | declare const _brand: unique symbol
|
542 | /**
|
543 | * @since 1.8.1
|
544 | */
|
545 | export interface Brand<B> {
|
546 | readonly [_brand]: B
|
547 | }
|
548 |
|
549 |
|
550 |
|
551 | export declare type Branded<A, B> = A & Brand<B>
|
552 |
|
553 |
|
554 |
|
555 | export interface BrandC<C extends Any, B> extends RefinementType<C, Branded<TypeOf<C>, B>, OutputOf<C>, InputOf<C>> {}
|
556 |
|
557 |
|
558 |
|
559 |
|
560 | export declare function brand<
|
561 | C extends Any,
|
562 | N extends string,
|
563 | B extends {
|
564 | readonly [K in N]: symbol
|
565 | }
|
566 | >(codec: C, predicate: Refinement<TypeOf<C>, Branded<TypeOf<C>, B>>, name: N): BrandC<C, B>
|
567 |
|
568 |
|
569 |
|
570 | export interface IntBrand {
|
571 | readonly Int: unique symbol
|
572 | }
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 | export declare const Int: BrandC<NumberC, IntBrand>
|
580 |
|
581 |
|
582 |
|
583 | export declare type Int = Branded<number, IntBrand>
|
584 |
|
585 |
|
586 |
|
587 | export declare class RecursiveType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
588 | runDefinition: () => C
|
589 | |
590 |
|
591 |
|
592 | readonly _tag: 'RecursiveType'
|
593 | constructor(
|
594 | name: string,
|
595 | is: RecursiveType<C, A, O, I>['is'],
|
596 | validate: RecursiveType<C, A, O, I>['validate'],
|
597 | encode: RecursiveType<C, A, O, I>['encode'],
|
598 | runDefinition: () => C
|
599 | )
|
600 | /**
|
601 | * @since 1.0.0
|
602 | */
|
603 | readonly type: C
|
604 | }
|
605 | /**
|
606 | * @category combinators
|
607 | * @since 1.0.0
|
608 | */
|
609 | export declare function recursion<A, O = A, I = unknown, C extends Type<A, O, I> = Type<A, O, I>>(
|
610 | name: string,
|
611 | definition: (self: C) => C
|
612 | ): RecursiveType<C, A, O, I>
|
613 | /**
|
614 | * @since 1.0.0
|
615 | */
|
616 | export declare class ArrayType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
617 | readonly type: C
|
618 | |
619 |
|
620 |
|
621 | readonly _tag: 'ArrayType'
|
622 | constructor(
|
623 | name: string,
|
624 | is: ArrayType<C, A, O, I>['is'],
|
625 | validate: ArrayType<C, A, O, I>['validate'],
|
626 | encode: ArrayType<C, A, O, I>['encode'],
|
627 | type: C
|
628 | )
|
629 | }
|
630 | /**
|
631 | * @since 1.5.3
|
632 | */
|
633 | export interface ArrayC<C extends Mixed> extends ArrayType<C, Array<TypeOf<C>>, Array<OutputOf<C>>, unknown> {}
|
634 |
|
635 |
|
636 |
|
637 |
|
638 | export declare function array<C extends Mixed>(item: C, name?: string): ArrayC<C>
|
639 | /**
|
640 | * @since 1.0.0
|
641 | */
|
642 | export declare class InterfaceType<P, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
643 | readonly props: P
|
644 | |
645 |
|
646 |
|
647 | readonly _tag: 'InterfaceType'
|
648 | constructor(
|
649 | name: string,
|
650 | is: InterfaceType<P, A, O, I>['is'],
|
651 | validate: InterfaceType<P, A, O, I>['validate'],
|
652 | encode: InterfaceType<P, A, O, I>['encode'],
|
653 | props: P
|
654 | )
|
655 | }
|
656 | /**
|
657 | * @since 1.5.3
|
658 | */
|
659 | export interface TypeC<P extends Props>
|
660 | extends InterfaceType<
|
661 | P,
|
662 | {
|
663 | [K in keyof P]: TypeOf<P[K]>
|
664 | },
|
665 | {
|
666 | [K in keyof P]: OutputOf<P[K]>
|
667 | },
|
668 | unknown
|
669 | > {}
|
670 |
|
671 |
|
672 |
|
673 |
|
674 | export declare function type<P extends Props>(props: P, name?: string): TypeC<P>
|
675 | /**
|
676 | * @since 1.0.0
|
677 | */
|
678 | export declare class PartialType<P, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
679 | readonly props: P
|
680 | |
681 |
|
682 |
|
683 | readonly _tag: 'PartialType'
|
684 | constructor(
|
685 | name: string,
|
686 | is: PartialType<P, A, O, I>['is'],
|
687 | validate: PartialType<P, A, O, I>['validate'],
|
688 | encode: PartialType<P, A, O, I>['encode'],
|
689 | props: P
|
690 | )
|
691 | }
|
692 | /**
|
693 | * @since 1.5.3
|
694 | */
|
695 | export interface PartialC<P extends Props>
|
696 | extends PartialType<
|
697 | P,
|
698 | {
|
699 | [K in keyof P]?: TypeOf<P[K]>
|
700 | },
|
701 | {
|
702 | [K in keyof P]?: OutputOf<P[K]>
|
703 | },
|
704 | unknown
|
705 | > {}
|
706 |
|
707 |
|
708 |
|
709 |
|
710 | export declare function partial<P extends Props>(props: P, name?: string): PartialC<P>
|
711 | /**
|
712 | * @since 1.0.0
|
713 | */
|
714 | export declare class DictionaryType<D extends Any, C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
715 | readonly domain: D
|
716 | readonly codomain: C
|
717 | |
718 |
|
719 |
|
720 | readonly _tag: 'DictionaryType'
|
721 | constructor(
|
722 | name: string,
|
723 | is: DictionaryType<D, C, A, O, I>['is'],
|
724 | validate: DictionaryType<D, C, A, O, I>['validate'],
|
725 | encode: DictionaryType<D, C, A, O, I>['encode'],
|
726 | domain: D,
|
727 | codomain: C
|
728 | )
|
729 | }
|
730 | /**
|
731 | * @since 1.5.3
|
732 | */
|
733 | export interface RecordC<D extends Mixed, C extends Mixed>
|
734 | extends DictionaryType<
|
735 | D,
|
736 | C,
|
737 | {
|
738 | [K in TypeOf<D>]: TypeOf<C>
|
739 | },
|
740 | {
|
741 | [K in OutputOf<D>]: OutputOf<C>
|
742 | },
|
743 | unknown
|
744 | > {}
|
745 |
|
746 |
|
747 |
|
748 |
|
749 | export declare function record<D extends Mixed, C extends Mixed>(domain: D, codomain: C, name?: string): RecordC<D, C>
|
750 | /**
|
751 | * @since 1.0.0
|
752 | */
|
753 | export declare class UnionType<CS extends Array<Any>, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
754 | readonly types: CS
|
755 | |
756 |
|
757 |
|
758 | readonly _tag: 'UnionType'
|
759 | constructor(
|
760 | name: string,
|
761 | is: UnionType<CS, A, O, I>['is'],
|
762 | validate: UnionType<CS, A, O, I>['validate'],
|
763 | encode: UnionType<CS, A, O, I>['encode'],
|
764 | types: CS
|
765 | )
|
766 | }
|
767 | /**
|
768 | * @since 1.5.3
|
769 | */
|
770 | export interface UnionC<CS extends [Mixed, Mixed, ...Array<Mixed>]>
|
771 | extends UnionType<CS, TypeOf<CS[number]>, OutputOf<CS[number]>, unknown> {}
|
772 |
|
773 |
|
774 |
|
775 |
|
776 | export declare function union<CS extends [Mixed, Mixed, ...Array<Mixed>]>(codecs: CS, name?: string): UnionC<CS>
|
777 | /**
|
778 | * @since 1.0.0
|
779 | */
|
780 | export declare class IntersectionType<CS extends Array<Any>, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
781 | readonly types: CS
|
782 | |
783 |
|
784 |
|
785 | readonly _tag: 'IntersectionType'
|
786 | constructor(
|
787 | name: string,
|
788 | is: IntersectionType<CS, A, O, I>['is'],
|
789 | validate: IntersectionType<CS, A, O, I>['validate'],
|
790 | encode: IntersectionType<CS, A, O, I>['encode'],
|
791 | types: CS
|
792 | )
|
793 | }
|
794 | /**
|
795 | * @since 1.5.3
|
796 | */
|
797 | export interface IntersectionC<CS extends [Mixed, Mixed, ...Array<Mixed>]>
|
798 | extends IntersectionType<
|
799 | CS,
|
800 | CS extends {
|
801 | length: 2
|
802 | }
|
803 | ? TypeOf<CS[0]> & TypeOf<CS[1]>
|
804 | : CS extends {
|
805 | length: 3
|
806 | }
|
807 | ? TypeOf<CS[0]> & TypeOf<CS[1]> & TypeOf<CS[2]>
|
808 | : CS extends {
|
809 | length: 4
|
810 | }
|
811 | ? TypeOf<CS[0]> & TypeOf<CS[1]> & TypeOf<CS[2]> & TypeOf<CS[3]>
|
812 | : CS extends {
|
813 | length: 5
|
814 | }
|
815 | ? TypeOf<CS[0]> & TypeOf<CS[1]> & TypeOf<CS[2]> & TypeOf<CS[3]> & TypeOf<CS[4]>
|
816 | : unknown,
|
817 | CS extends {
|
818 | length: 2
|
819 | }
|
820 | ? OutputOf<CS[0]> & OutputOf<CS[1]>
|
821 | : CS extends {
|
822 | length: 3
|
823 | }
|
824 | ? OutputOf<CS[0]> & OutputOf<CS[1]> & OutputOf<CS[2]>
|
825 | : CS extends {
|
826 | length: 4
|
827 | }
|
828 | ? OutputOf<CS[0]> & OutputOf<CS[1]> & OutputOf<CS[2]> & OutputOf<CS[3]>
|
829 | : CS extends {
|
830 | length: 5
|
831 | }
|
832 | ? OutputOf<CS[0]> & OutputOf<CS[1]> & OutputOf<CS[2]> & OutputOf<CS[3]> & OutputOf<CS[4]>
|
833 | : unknown,
|
834 | unknown
|
835 | > {}
|
836 |
|
837 |
|
838 |
|
839 |
|
840 | export declare function intersection<
|
841 | A extends Mixed,
|
842 | B extends Mixed,
|
843 | C extends Mixed,
|
844 | D extends Mixed,
|
845 | E extends Mixed
|
846 | >(codecs: [A, B, C, D, E], name?: string): IntersectionC<[A, B, C, D, E]>
|
847 | export declare function intersection<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed>(
|
848 | codecs: [A, B, C, D],
|
849 | name?: string
|
850 | ): IntersectionC<[A, B, C, D]>
|
851 | export declare function intersection<A extends Mixed, B extends Mixed, C extends Mixed>(
|
852 | codecs: [A, B, C],
|
853 | name?: string
|
854 | ): IntersectionC<[A, B, C]>
|
855 | export declare function intersection<A extends Mixed, B extends Mixed>(
|
856 | codecs: [A, B],
|
857 | name?: string
|
858 | ): IntersectionC<[A, B]>
|
859 | /**
|
860 | * @since 1.0.0
|
861 | */
|
862 | export declare class TupleType<CS extends Array<Any>, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
863 | readonly types: CS
|
864 | /**
|
865 | * @since 1.0.0
|
866 | */
|
867 | readonly _tag: 'TupleType'
|
868 | constructor(
|
869 | name: string,
|
870 | is: TupleType<CS, A, O, I>['is'],
|
871 | validate: TupleType<CS, A, O, I>['validate'],
|
872 | encode: TupleType<CS, A, O, I>['encode'],
|
873 | types: CS
|
874 | )
|
875 | }
|
876 | /**
|
877 | * @since 1.5.3
|
878 | */
|
879 | export interface TupleC<CS extends [Mixed, ...Array<Mixed>]>
|
880 | extends TupleType<
|
881 | CS,
|
882 | CS extends {
|
883 | length: 1
|
884 | }
|
885 | ? [TypeOf<CS[0]>]
|
886 | : CS extends {
|
887 | length: 2
|
888 | }
|
889 | ? [TypeOf<CS[0]>, TypeOf<CS[1]>]
|
890 | : CS extends {
|
891 | length: 3
|
892 | }
|
893 | ? [TypeOf<CS[0]>, TypeOf<CS[1]>, TypeOf<CS[2]>]
|
894 | : CS extends {
|
895 | length: 4
|
896 | }
|
897 | ? [TypeOf<CS[0]>, TypeOf<CS[1]>, TypeOf<CS[2]>, TypeOf<CS[3]>]
|
898 | : CS extends {
|
899 | length: 5
|
900 | }
|
901 | ? [TypeOf<CS[0]>, TypeOf<CS[1]>, TypeOf<CS[2]>, TypeOf<CS[3]>, TypeOf<CS[4]>]
|
902 | : unknown,
|
903 | CS extends {
|
904 | length: 1
|
905 | }
|
906 | ? [OutputOf<CS[0]>]
|
907 | : CS extends {
|
908 | length: 2
|
909 | }
|
910 | ? [OutputOf<CS[0]>, OutputOf<CS[1]>]
|
911 | : CS extends {
|
912 | length: 3
|
913 | }
|
914 | ? [OutputOf<CS[0]>, OutputOf<CS[1]>, OutputOf<CS[2]>]
|
915 | : CS extends {
|
916 | length: 4
|
917 | }
|
918 | ? [OutputOf<CS[0]>, OutputOf<CS[1]>, OutputOf<CS[2]>, OutputOf<CS[3]>]
|
919 | : CS extends {
|
920 | length: 5
|
921 | }
|
922 | ? [OutputOf<CS[0]>, OutputOf<CS[1]>, OutputOf<CS[2]>, OutputOf<CS[3]>, OutputOf<CS[4]>]
|
923 | : unknown,
|
924 | unknown
|
925 | > {}
|
926 |
|
927 |
|
928 |
|
929 |
|
930 | export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed, E extends Mixed>(
|
931 | codecs: [A, B, C, D, E],
|
932 | name?: string
|
933 | ): TupleC<[A, B, C, D, E]>
|
934 | export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed, D extends Mixed>(
|
935 | codecs: [A, B, C, D],
|
936 | name?: string
|
937 | ): TupleC<[A, B, C, D]>
|
938 | export declare function tuple<A extends Mixed, B extends Mixed, C extends Mixed>(
|
939 | codecs: [A, B, C],
|
940 | name?: string
|
941 | ): TupleC<[A, B, C]>
|
942 | export declare function tuple<A extends Mixed, B extends Mixed>(codecs: [A, B], name?: string): TupleC<[A, B]>
|
943 | export declare function tuple<A extends Mixed>(codecs: [A], name?: string): TupleC<[A]>
|
944 | /**
|
945 | * @since 1.0.0
|
946 | */
|
947 | export declare class ReadonlyType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
948 | readonly type: C
|
949 | /**
|
950 | * @since 1.0.0
|
951 | */
|
952 | readonly _tag: 'ReadonlyType'
|
953 | constructor(
|
954 | name: string,
|
955 | is: ReadonlyType<C, A, O, I>['is'],
|
956 | validate: ReadonlyType<C, A, O, I>['validate'],
|
957 | encode: ReadonlyType<C, A, O, I>['encode'],
|
958 | type: C
|
959 | )
|
960 | }
|
961 | /**
|
962 | * @since 1.5.3
|
963 | */
|
964 | export interface ReadonlyC<C extends Mixed>
|
965 | extends ReadonlyType<C, Readonly<TypeOf<C>>, Readonly<OutputOf<C>>, unknown> {}
|
966 | /**
|
967 | * @category combinators
|
968 | * @since 1.0.0
|
969 | */
|
970 | export declare function readonly<C extends Mixed>(codec: C, name?: string): ReadonlyC<C>
|
971 | /**
|
972 | * @since 1.0.0
|
973 | */
|
974 | export declare class ReadonlyArrayType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
975 | readonly type: C
|
976 | /**
|
977 | * @since 1.0.0
|
978 | */
|
979 | readonly _tag: 'ReadonlyArrayType'
|
980 | constructor(
|
981 | name: string,
|
982 | is: ReadonlyArrayType<C, A, O, I>['is'],
|
983 | validate: ReadonlyArrayType<C, A, O, I>['validate'],
|
984 | encode: ReadonlyArrayType<C, A, O, I>['encode'],
|
985 | type: C
|
986 | )
|
987 | }
|
988 | /**
|
989 | * @since 1.5.3
|
990 | */
|
991 | export interface ReadonlyArrayC<C extends Mixed>
|
992 | extends ReadonlyArrayType<C, ReadonlyArray<TypeOf<C>>, ReadonlyArray<OutputOf<C>>, unknown> {}
|
993 | /**
|
994 | * @category combinators
|
995 | * @since 1.0.0
|
996 | */
|
997 | export declare function readonlyArray<C extends Mixed>(item: C, name?: string): ReadonlyArrayC<C>
|
998 | /**
|
999 | * Strips additional properties, equivalent to `exact(type(props))`.
|
1000 | *
|
1001 | * @category combinators
|
1002 | * @since 1.0.0
|
1003 | */
|
1004 | export declare const strict: <P extends Props>(props: P, name?: string | undefined) => ExactC<TypeC<P>>
|
1005 | /**
|
1006 | * @since 1.1.0
|
1007 | */
|
1008 | export declare class ExactType<C extends Any, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
1009 | readonly type: C
|
1010 | /**
|
1011 | * @since 1.0.0
|
1012 | */
|
1013 | readonly _tag: 'ExactType'
|
1014 | constructor(
|
1015 | name: string,
|
1016 | is: ExactType<C, A, O, I>['is'],
|
1017 | validate: ExactType<C, A, O, I>['validate'],
|
1018 | encode: ExactType<C, A, O, I>['encode'],
|
1019 | type: C
|
1020 | )
|
1021 | }
|
1022 | /**
|
1023 | * @since 1.5.3
|
1024 | */
|
1025 | export interface ExactC<C extends HasProps> extends ExactType<C, TypeOf<C>, OutputOf<C>, InputOf<C>> {}
|
1026 | /**
|
1027 | * Strips additional properties.
|
1028 | *
|
1029 | * @category combinators
|
1030 | * @since 1.1.0
|
1031 | */
|
1032 | export declare function exact<C extends HasProps>(codec: C, name?: string): ExactC<C>
|
1033 | /**
|
1034 | * @since 1.0.0
|
1035 | * @deprecated
|
1036 | */
|
1037 | export declare class FunctionType extends Type<Function> {
|
1038 | /**
|
1039 | * @since 1.0.0
|
1040 | */
|
1041 | readonly _tag: 'FunctionType'
|
1042 | constructor()
|
1043 | }
|
1044 | /**
|
1045 | * @since 1.5.3
|
1046 | * @deprecated
|
1047 | */
|
1048 | export interface FunctionC extends FunctionType {}
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 | export declare const Function: FunctionC
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 | export declare class TaggedUnionType<
|
1060 | Tag extends string,
|
1061 | CS extends Array<Mixed>,
|
1062 | A = any,
|
1063 | O = A,
|
1064 | I = unknown
|
1065 | > extends UnionType<CS, A, O, I> {
|
1066 | readonly tag: Tag
|
1067 | constructor(
|
1068 | name: string,
|
1069 | is: TaggedUnionType<Tag, CS, A, O, I>['is'],
|
1070 | validate: TaggedUnionType<Tag, CS, A, O, I>['validate'],
|
1071 | encode: TaggedUnionType<Tag, CS, A, O, I>['encode'],
|
1072 | codecs: CS,
|
1073 | tag: Tag
|
1074 | )
|
1075 | }
|
1076 | /**
|
1077 | * @since 1.5.3
|
1078 | * @deprecated
|
1079 | */
|
1080 | export interface TaggedUnionC<Tag extends string, CS extends [Mixed, Mixed, ...Array<Mixed>]> // tslint:disable-next-line: deprecation
|
1081 | extends TaggedUnionType<Tag, CS, TypeOf<CS[number]>, OutputOf<CS[number]>, unknown> {}
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 | export declare const taggedUnion: <Tag extends string, CS extends [Mixed, Mixed, ...Mixed[]]>(
|
1090 | tag: Tag,
|
1091 | codecs: CS,
|
1092 | name?: string
|
1093 | ) => TaggedUnionC<Tag, CS>
|
1094 | export {
|
1095 | |
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 | UnknownArray as Array
|
1103 | }
|
1104 | export {
|
1105 | |
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 | type as interface
|
1113 | }
|
1114 | /**
|
1115 | * Use `unknown` instead.
|
1116 | *
|
1117 | * @since 1.0.0
|
1118 | * @deprecated
|
1119 | */
|
1120 | export declare type mixed = unknown
|
1121 | /**
|
1122 | * @since 1.0.0
|
1123 | * @deprecated
|
1124 | */
|
1125 | export declare const getValidationError: (value: unknown, context: Context) => ValidationError
|
1126 | /**
|
1127 | * @since 1.0.0
|
1128 | * @deprecated
|
1129 | */
|
1130 | export declare const getDefaultContext: (decoder: Decoder<any, any>) => Context
|
1131 | /**
|
1132 | * @since 1.0.0
|
1133 | * @deprecated
|
1134 | */
|
1135 | export declare class NeverType extends Type<never> {
|
1136 | |
1137 |
|
1138 |
|
1139 | readonly _tag: 'NeverType'
|
1140 | constructor()
|
1141 | }
|
1142 | /**
|
1143 | * @since 1.5.3
|
1144 | * @deprecated
|
1145 | */
|
1146 | export interface NeverC extends NeverType {}
|
1147 |
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 | export declare const never: NeverC
|
1153 |
|
1154 |
|
1155 |
|
1156 |
|
1157 | export declare class AnyType extends Type<any> {
|
1158 | |
1159 |
|
1160 |
|
1161 | readonly _tag: 'AnyType'
|
1162 | constructor()
|
1163 | }
|
1164 | /**
|
1165 | * @since 1.5.3
|
1166 | * @deprecated
|
1167 | */
|
1168 | export interface AnyC extends AnyType {}
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 | export declare const any: AnyC
|
1177 |
|
1178 |
|
1179 |
|
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 | export declare const Dictionary: UnknownRecordC
|
1185 |
|
1186 |
|
1187 |
|
1188 |
|
1189 | export declare class ObjectType extends Type<object> {
|
1190 | |
1191 |
|
1192 |
|
1193 | readonly _tag: 'ObjectType'
|
1194 | constructor()
|
1195 | }
|
1196 | /**
|
1197 | * @since 1.5.3
|
1198 | * @deprecated
|
1199 | */
|
1200 | export interface ObjectC extends ObjectType {}
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 |
|
1206 |
|
1207 |
|
1208 | export declare const object: ObjectC
|
1209 |
|
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 |
|
1215 | export interface RefinementC<C extends Any> extends RefinementType<C, TypeOf<C>, OutputOf<C>, InputOf<C>> {}
|
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 |
|
1221 |
|
1222 |
|
1223 | export declare function refinement<C extends Any>(
|
1224 | codec: C,
|
1225 | predicate: Predicate<TypeOf<C>>,
|
1226 | name?: string
|
1227 | ): RefinementC<C>
|
1228 | /**
|
1229 | * Use `Int` instead.
|
1230 | *
|
1231 | * @category primitives
|
1232 | * @since 1.0.0
|
1233 | * @deprecated
|
1234 | */
|
1235 | export declare const Integer: RefinementC<NumberC>
|
1236 | /**
|
1237 | * Use `record` instead.
|
1238 | *
|
1239 | * @category combinators
|
1240 | * @since 1.0.0
|
1241 | * @deprecated
|
1242 | */
|
1243 | export declare const dictionary: typeof record
|
1244 | /**
|
1245 | * @since 1.4.2
|
1246 | * @deprecated
|
1247 | */
|
1248 | export declare type Compact<A> = {
|
1249 | [K in keyof A]: A[K]
|
1250 | }
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 | export declare class StrictType<P, A = any, O = A, I = unknown> extends Type<A, O, I> {
|
1256 | readonly props: P
|
1257 | |
1258 |
|
1259 |
|
1260 | readonly _tag: 'StrictType'
|
1261 | constructor(
|
1262 | name: string,
|
1263 | is: StrictType<P, A, O, I>['is'],
|
1264 | validate: StrictType<P, A, O, I>['validate'],
|
1265 | encode: StrictType<P, A, O, I>['encode'],
|
1266 | props: P
|
1267 | )
|
1268 | }
|
1269 | /**
|
1270 | * @since 1.5.3
|
1271 | * @deprecated
|
1272 | */
|
1273 | export interface StrictC<P extends Props> // tslint:disable-next-line: deprecation
|
1274 | extends StrictType<
|
1275 | P,
|
1276 | {
|
1277 | [K in keyof P]: TypeOf<P[K]>
|
1278 | },
|
1279 | {
|
1280 | [K in keyof P]: OutputOf<P[K]>
|
1281 | },
|
1282 | unknown
|
1283 | > {}
|
1284 |
|
1285 |
|
1286 |
|
1287 |
|
1288 | export declare type TaggedProps<Tag extends string> = {
|
1289 | [K in Tag]: LiteralType<any>
|
1290 | }
|
1291 |
|
1292 |
|
1293 |
|
1294 |
|
1295 | export interface TaggedRefinement<Tag extends string, A, O = A> extends RefinementType<Tagged<Tag>, A, O> {}
|
1296 |
|
1297 |
|
1298 |
|
1299 |
|
1300 | export interface TaggedUnion<Tag extends string, A, O = A> extends UnionType<Array<Tagged<Tag>>, A, O> {}
|
1301 |
|
1302 |
|
1303 |
|
1304 |
|
1305 | export declare type TaggedIntersectionArgument<Tag extends string> =
|
1306 | | [Tagged<Tag>]
|
1307 | | [Tagged<Tag>, Mixed]
|
1308 | | [Mixed, Tagged<Tag>]
|
1309 | | [Tagged<Tag>, Mixed, Mixed]
|
1310 | | [Mixed, Tagged<Tag>, Mixed]
|
1311 | | [Mixed, Mixed, Tagged<Tag>]
|
1312 | | [Tagged<Tag>, Mixed, Mixed, Mixed]
|
1313 | | [Mixed, Tagged<Tag>, Mixed, Mixed]
|
1314 | | [Mixed, Mixed, Tagged<Tag>, Mixed]
|
1315 | | [Mixed, Mixed, Mixed, Tagged<Tag>]
|
1316 | | [Tagged<Tag>, Mixed, Mixed, Mixed, Mixed]
|
1317 | | [Mixed, Tagged<Tag>, Mixed, Mixed, Mixed]
|
1318 | | [Mixed, Mixed, Tagged<Tag>, Mixed, Mixed]
|
1319 | | [Mixed, Mixed, Mixed, Tagged<Tag>, Mixed]
|
1320 | | [Mixed, Mixed, Mixed, Mixed, Tagged<Tag>]
|
1321 |
|
1322 |
|
1323 |
|
1324 |
|
1325 | export interface TaggedIntersection<Tag extends string, A, O = A> // tslint:disable-next-line: deprecation
|
1326 | extends IntersectionType<TaggedIntersectionArgument<Tag>, A, O> {}
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 | export interface TaggedExact<Tag extends string, A, O = A> extends ExactType<Tagged<Tag>, A, O> {}
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 | export declare type Tagged<Tag extends string, A = any, O = A> =
|
1337 | | InterfaceType<TaggedProps<Tag>, A, O>
|
1338 | | StrictType<TaggedProps<Tag>, A, O>
|
1339 | | TaggedRefinement<Tag, A, O>
|
1340 | | TaggedUnion<Tag, A, O>
|
1341 | | TaggedIntersection<Tag, A, O>
|
1342 | | TaggedExact<Tag, A, O>
|
1343 | | RecursiveType<any, A, O>
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 | export declare function clean<A, O = A, I = unknown>(codec: Type<A, O, I>): Type<A, O, I>
|
1352 | /**
|
1353 | * @since 1.0.0
|
1354 | * @deprecated
|
1355 | */
|
1356 | export declare type PropsOf<
|
1357 | T extends {
|
1358 | props: any
|
1359 | }
|
1360 | > = T['props']
|
1361 |
|
1362 |
|
1363 |
|
1364 |
|
1365 | export declare type Exact<T, X extends T> = T &
|
1366 | {
|
1367 | [K in ({
|
1368 | [K in keyof X]: K
|
1369 | } &
|
1370 | {
|
1371 | [K in keyof T]: never
|
1372 | } & {
|
1373 | [key: string]: never
|
1374 | })[keyof X]]?: never
|
1375 | }
|
1376 |
|
1377 |
|
1378 |
|
1379 |
|
1380 |
|
1381 |
|
1382 |
|
1383 | export declare function alias<A, O, P, I>(
|
1384 | codec: PartialType<P, A, O, I>
|
1385 | ): <
|
1386 | AA extends Exact<A, AA>,
|
1387 | OO extends Exact<O, OO> = O,
|
1388 | PP extends Exact<P, PP> = P,
|
1389 | II extends I = I
|
1390 | >() => PartialType<PP, AA, OO, II>
|
1391 | export declare function alias<A, O, P, I>(
|
1392 | codec: StrictType<P, A, O, I>
|
1393 | ): <
|
1394 | AA extends Exact<A, AA>,
|
1395 | OO extends Exact<O, OO> = O,
|
1396 | PP extends Exact<P, PP> = P,
|
1397 | II extends I = I
|
1398 | >() => StrictType<PP, AA, OO, II>
|
1399 | export declare function alias<A, O, P, I>(
|
1400 | codec: InterfaceType<P, A, O, I>
|
1401 | ): <
|
1402 | AA extends Exact<A, AA>,
|
1403 | OO extends Exact<O, OO> = O,
|
1404 | PP extends Exact<P, PP> = P,
|
1405 | II extends I = I
|
1406 | >() => InterfaceType<PP, AA, OO, II>
|
1407 |
|
\ | No newline at end of file |