decoders 1.25.2 → 1.26.0-beta2
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 +20 -0
- package/{array.js → cjs/array.js} +5 -5
- package/{array.js.flow → cjs/array.js.flow} +1 -1
- package/{boolean.js → cjs/boolean.js} +4 -4
- package/{boolean.js.flow → cjs/boolean.js.flow} +1 -1
- package/{constants.js → cjs/constants.js} +7 -7
- package/{constants.js.flow → cjs/constants.js.flow} +3 -3
- package/{date.js → cjs/date.js} +2 -2
- package/{date.js.flow → cjs/date.js.flow} +1 -1
- package/{describe.js → cjs/describe.js} +0 -0
- package/{describe.js.flow → cjs/describe.js.flow} +0 -0
- package/{dispatch.js → cjs/dispatch.js} +0 -0
- package/{dispatch.js.flow → cjs/dispatch.js.flow} +0 -0
- package/{either.js → cjs/either.js} +6 -6
- package/{either.js.flow → cjs/either.js.flow} +2 -4
- package/{fail.js → cjs/fail.js} +2 -2
- package/{fail.js.flow → cjs/fail.js.flow} +1 -1
- package/{guard.js → cjs/guard.js} +0 -0
- package/{guard.js.flow → cjs/guard.js.flow} +0 -0
- package/{index.js → cjs/index.js} +110 -110
- package/{index.js.flow → cjs/index.js.flow} +0 -0
- package/{instanceOf.js → cjs/instanceOf.js} +2 -2
- package/{instanceOf.js.flow → cjs/instanceOf.js.flow} +1 -1
- package/{json.js → cjs/json.js} +1 -1
- package/{json.js.flow → cjs/json.js.flow} +0 -0
- package/{lazy.js → cjs/lazy.js} +0 -0
- package/{lazy.js.flow → cjs/lazy.js.flow} +0 -0
- package/{mapping.js → cjs/mapping.js} +4 -4
- package/{mapping.js.flow → cjs/mapping.js.flow} +1 -1
- package/{number.js → cjs/number.js} +3 -3
- package/{number.js.flow → cjs/number.js.flow} +1 -1
- package/{object.js → cjs/object.js} +8 -8
- package/{object.js.flow → cjs/object.js.flow} +1 -1
- package/{optional.js → cjs/optional.js} +5 -5
- package/{optional.js.flow → cjs/optional.js.flow} +1 -1
- package/{string.js → cjs/string.js} +7 -6
- package/{string.js.flow → cjs/string.js.flow} +1 -1
- package/{tuple.js → cjs/tuple.js} +13 -13
- package/{tuple.js.flow → cjs/tuple.js.flow} +1 -1
- package/cjs/types.js +3 -0
- package/{types.js.flow → cjs/types.js.flow} +3 -1
- package/{utils.js → cjs/utils.js} +6 -6
- package/{utils.js.flow → cjs/utils.js.flow} +1 -1
- package/es/index.js +1039 -0
- package/package.json +9 -5
- package/{array.d.ts → ts/array.d.ts} +1 -1
- package/{boolean.d.ts → ts/boolean.d.ts} +0 -0
- package/{constants.d.ts → ts/constants.d.ts} +1 -2
- package/{date.d.ts → ts/date.d.ts} +0 -0
- package/{describe.d.ts → ts/describe.d.ts} +0 -0
- package/{dispatch.d.ts → ts/dispatch.d.ts} +0 -0
- package/{either.d.ts → ts/either.d.ts} +1 -3
- package/{fail.d.ts → ts/fail.d.ts} +0 -0
- package/{guard.d.ts → ts/guard.d.ts} +0 -0
- package/ts/helpers.d.ts +79 -0
- package/{index.d.ts → ts/index.d.ts} +1 -1
- package/{instanceOf.d.ts → ts/instanceOf.d.ts} +0 -0
- package/{json.d.ts → ts/json.d.ts} +0 -0
- package/{lazy.d.ts → ts/lazy.d.ts} +0 -0
- package/{mapping.d.ts → ts/mapping.d.ts} +0 -0
- package/{number.d.ts → ts/number.d.ts} +0 -0
- package/{object.d.ts → ts/object.d.ts} +3 -3
- package/{optional.d.ts → ts/optional.d.ts} +0 -0
- package/{string.d.ts → ts/string.d.ts} +0 -0
- package/{tuple.d.ts → ts/tuple.d.ts} +0 -0
- package/{types.d.ts → ts/types.d.ts} +3 -1
- package/{utils.d.ts → ts/utils.d.ts} +0 -0
- package/helpers.d.ts +0 -62
- package/types.js +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decoders",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.0-beta2",
|
|
4
4
|
"description": "Elegant and battle-tested validation library for type-safe input data (for TypeScript and Flow)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/nvie/decoders/issues"
|
|
14
14
|
},
|
|
15
|
-
"main": "./index.js",
|
|
15
|
+
"main": "./cjs/index.js",
|
|
16
|
+
"module": "./es/index.js",
|
|
16
17
|
"keywords": [
|
|
17
18
|
"decoder",
|
|
18
19
|
"decoders",
|
|
@@ -39,11 +40,14 @@
|
|
|
39
40
|
"map",
|
|
40
41
|
"predicate"
|
|
41
42
|
],
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@babel/runtime": "^7.16.0"
|
|
45
|
+
},
|
|
42
46
|
"dependencies": {
|
|
43
|
-
"debrief": "^1.
|
|
44
|
-
"lemons": "^1.
|
|
47
|
+
"debrief": "^1.6.0-beta2",
|
|
48
|
+
"lemons": "^1.7.0-beta2"
|
|
45
49
|
},
|
|
46
|
-
"types": "./index.d.ts",
|
|
50
|
+
"types": "./ts/index.d.ts",
|
|
47
51
|
"githubUrl": "https://github.com/nvie/decoders",
|
|
48
52
|
"sideEffects": false
|
|
49
53
|
}
|
|
@@ -2,4 +2,4 @@ import { Decoder } from './types';
|
|
|
2
2
|
|
|
3
3
|
export const poja: Decoder<unknown[]>;
|
|
4
4
|
export function array<T>(decoder: Decoder<T>): Decoder<T[]>;
|
|
5
|
-
export function nonEmptyArray<T>(decoder: Decoder<T>): Decoder<T[]>;
|
|
5
|
+
export function nonEmptyArray<T>(decoder: Decoder<T>): Decoder<[T, ...T[]]>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Decoder } from './types';
|
|
2
|
-
|
|
3
|
-
export type Scalar = string | number | boolean | symbol | undefined | null;
|
|
1
|
+
import { Decoder, Scalar } from './types';
|
|
4
2
|
|
|
5
3
|
export function either<T1, T2>(d1: Decoder<T1>, d2: Decoder<T2>): Decoder<T1 | T2>;
|
|
6
4
|
export function either2<T1, T2>(d1: Decoder<T1>, d2: Decoder<T2>): Decoder<T1 | T2>;
|
|
File without changes
|
|
File without changes
|
package/ts/helpers.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a type like:
|
|
3
|
+
*
|
|
4
|
+
* {
|
|
5
|
+
* a: string;
|
|
6
|
+
* b: number | undefined;
|
|
7
|
+
* c: null | undefined;
|
|
8
|
+
* d: null;
|
|
9
|
+
* e: undefined;
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* Will drop all the "undefined" types. In this case, only "e":
|
|
13
|
+
*
|
|
14
|
+
* {
|
|
15
|
+
* a: string;
|
|
16
|
+
* b: number | undefined;
|
|
17
|
+
* c: null | undefined;
|
|
18
|
+
* d: null;
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
type Compact<T> = { [K in IsDefined<T, keyof T>]: T[K] };
|
|
23
|
+
|
|
24
|
+
type IsDefined<T, K extends keyof T> = K extends any
|
|
25
|
+
? T[K] extends undefined
|
|
26
|
+
? never
|
|
27
|
+
: K
|
|
28
|
+
: never;
|
|
29
|
+
|
|
30
|
+
//
|
|
31
|
+
// HACK:
|
|
32
|
+
// These weird conditionals test whether TypeScript is configured with the
|
|
33
|
+
// `strictNullChecks` compiler option. We use these definitions to influence
|
|
34
|
+
// what's considered a "required" vs an "optional" key for the AllowImplicit
|
|
35
|
+
// type.
|
|
36
|
+
//
|
|
37
|
+
// If strictNullChecks is false, then we should not be emitting any `?` fields
|
|
38
|
+
// and consider all fields "required" because everything is optional by default
|
|
39
|
+
// in that mode anyway.
|
|
40
|
+
//
|
|
41
|
+
type NoStrictNullChecks = undefined extends string ? 1 : undefined;
|
|
42
|
+
// ^^^^^^^^^^^^^^^^^^^^^^^^
|
|
43
|
+
type StrictNullChecks = undefined extends string ? undefined : 1;
|
|
44
|
+
// ^^^^^^^^^^^^^^^^^^^^^^^^
|
|
45
|
+
|
|
46
|
+
export type RequiredKeys<T> = keyof Compact<{
|
|
47
|
+
[K in keyof T]: undefined extends T[K] ? NoStrictNullChecks : 1;
|
|
48
|
+
}>;
|
|
49
|
+
|
|
50
|
+
export type OptionalKeys<T> = keyof Compact<{
|
|
51
|
+
[K in keyof T]: undefined extends T[K] ? 1 : StrictNullChecks;
|
|
52
|
+
}>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Transforms an object type, by marking all fields that contain "undefined"
|
|
56
|
+
* with a question mark, i.e. allowing implicit-undefineds when
|
|
57
|
+
* explicit-undefined are also allowed.
|
|
58
|
+
*
|
|
59
|
+
* For example, if:
|
|
60
|
+
*
|
|
61
|
+
* type User = {
|
|
62
|
+
* name: string;
|
|
63
|
+
* age: number | null | undefined;
|
|
64
|
+
* }
|
|
65
|
+
*
|
|
66
|
+
* Then AllowImplicit<User> will become equivalent to:
|
|
67
|
+
*
|
|
68
|
+
* {
|
|
69
|
+
* name: string;
|
|
70
|
+
* age?: number | null;
|
|
71
|
+
* ^
|
|
72
|
+
* Note the question mark
|
|
73
|
+
* }
|
|
74
|
+
*/
|
|
75
|
+
type AllowImplicit<T> = { [K in RequiredKeys<T>]-?: T[K] } & {
|
|
76
|
+
[K in OptionalKeys<T>]+?: Exclude<T[K], undefined>;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export { AllowImplicit };
|
|
@@ -3,7 +3,7 @@ import { Decoder, DecoderType, Guard, GuardType } from './types';
|
|
|
3
3
|
export { guard } from './guard';
|
|
4
4
|
export { compose, map, predicate } from './utils';
|
|
5
5
|
|
|
6
|
-
export { array, poja } from './array';
|
|
6
|
+
export { array, nonEmptyArray, poja } from './array';
|
|
7
7
|
export { boolean, numericBoolean, truthy } from './boolean';
|
|
8
8
|
export { constant, hardcoded, mixed, null_, undefined_, unknown } from './constants';
|
|
9
9
|
export { date, iso8601 } from './date';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { $DecoderType, Decoder } from './types';
|
|
2
2
|
import { AllowImplicit } from './helpers';
|
|
3
3
|
|
|
4
|
-
export type ObjectDecoderType<T> = AllowImplicit<
|
|
5
|
-
|
|
6
|
-
>;
|
|
4
|
+
export type ObjectDecoderType<T> = AllowImplicit<{
|
|
5
|
+
[key in keyof T]: $DecoderType<T[key]>;
|
|
6
|
+
}>;
|
|
7
7
|
|
|
8
8
|
export const pojo: Decoder<{ [key: string]: unknown }>;
|
|
9
9
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/helpers.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Given a type like:
|
|
3
|
-
*
|
|
4
|
-
* {
|
|
5
|
-
* a: string;
|
|
6
|
-
* b: number | undefined;
|
|
7
|
-
* c: null | undefined;
|
|
8
|
-
* d: null;
|
|
9
|
-
* e: undefined;
|
|
10
|
-
* }
|
|
11
|
-
*
|
|
12
|
-
* Will drop all the "undefined" types. In this case, only "e":
|
|
13
|
-
*
|
|
14
|
-
* {
|
|
15
|
-
* a: string;
|
|
16
|
-
* b: number | undefined;
|
|
17
|
-
* c: null | undefined;
|
|
18
|
-
* d: null;
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
type Compact<T> = { [K in IsDefined<T, keyof T>]: T[K] };
|
|
23
|
-
|
|
24
|
-
type IsDefined<T, K extends keyof T> = K extends any
|
|
25
|
-
? T[K] extends undefined
|
|
26
|
-
? never
|
|
27
|
-
: K
|
|
28
|
-
: never;
|
|
29
|
-
|
|
30
|
-
export type RequiredKeys<T> = keyof Compact<
|
|
31
|
-
{ [K in keyof T]: undefined extends T[K] ? undefined : 1 }
|
|
32
|
-
>;
|
|
33
|
-
|
|
34
|
-
export type OptionalKeys<T> = keyof Compact<
|
|
35
|
-
{ [K in keyof T]: undefined extends T[K] ? 1 : undefined }
|
|
36
|
-
>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Transforms an object type, by marking all fields that contain "undefined"
|
|
40
|
-
* with a question mark, i.e. allowing implicit-undefineds when
|
|
41
|
-
* explicit-undefined are also allowed.
|
|
42
|
-
*
|
|
43
|
-
* For example, if:
|
|
44
|
-
*
|
|
45
|
-
* type User = {
|
|
46
|
-
* name: string;
|
|
47
|
-
* age: number | null | undefined;
|
|
48
|
-
* }
|
|
49
|
-
*
|
|
50
|
-
* Then AllowImplicit<User> will become equivalent to:
|
|
51
|
-
*
|
|
52
|
-
* {
|
|
53
|
-
* name: string;
|
|
54
|
-
* age?: number | null;
|
|
55
|
-
* ^
|
|
56
|
-
* Note the question mark
|
|
57
|
-
* }
|
|
58
|
-
*/
|
|
59
|
-
type AllowImplicit<T> = { [K in RequiredKeys<T>]-?: T[K] } &
|
|
60
|
-
{ [K in OptionalKeys<T>]+?: Exclude<T[K], undefined> };
|
|
61
|
-
|
|
62
|
-
export { AllowImplicit };
|