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