free-types-core 1.0.2 → 1.1.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/dist/$Before.d.ts +52 -52
- package/dist/$Before.js +1 -1
- package/dist/Const.d.ts +31 -31
- package/dist/Const.js +1 -1
- package/dist/Flow.d.ts +31 -31
- package/dist/Flow.js +1 -1
- package/dist/From.d.ts +69 -70
- package/dist/From.js +1 -1
- package/dist/Pipe.d.ts +27 -27
- package/dist/Pipe.js +1 -1
- package/dist/Replace.d.ts +9 -9
- package/dist/Replace.js +1 -1
- package/dist/Type.d.ts +83 -83
- package/dist/Type.js +1 -1
- package/dist/TypeDoc.d.ts +15 -15
- package/dist/TypeDoc.js +1 -1
- package/dist/TypesMap.d.ts +17 -17
- package/dist/TypesMap.js +1 -1
- package/dist/apply.d.ts +57 -49
- package/dist/apply.js +1 -1
- package/dist/free-types.d.ts +65 -65
- package/dist/free-types.js +1 -1
- package/dist/helpers.d.ts +99 -99
- package/dist/helpers.js +1 -1
- package/dist/hkt.d.ts +15 -15
- package/dist/hkt.js +1 -1
- package/dist/index.d.ts +17 -17
- package/dist/index.js +12 -12
- package/dist/inferArgs.d.ts +28 -28
- package/dist/inferArgs.js +1 -1
- package/dist/partial.d.ts +55 -55
- package/dist/partial.js +1 -1
- package/dist/unwrap.d.ts +44 -44
- package/dist/unwrap.js +1 -1
- package/dist/utils.d.ts +70 -69
- package/dist/utils.js +2 -2
- package/package.json +36 -34
package/dist/$Before.d.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { Const } from "./Const";
|
|
2
|
-
import { _apply } from "./apply";
|
|
3
|
-
import { Next, ArrayLike } from "./utils";
|
|
4
|
-
import { Contra, NamedConstraints } from "./Type";
|
|
5
|
-
type Type = {
|
|
6
|
-
type: any;
|
|
7
|
-
constraints: any;
|
|
8
|
-
names: any;
|
|
9
|
-
arg: any;
|
|
10
|
-
};
|
|
11
|
-
type Unconstrained = {
|
|
12
|
-
[k: number]: unknown;
|
|
13
|
-
};
|
|
14
|
-
export type $Before<$T extends Type, $P extends ContraIndex<$P, $T, I>, I extends number = never> = [I] extends [never] ? $BeforeN<$T, $P> : $BeforeI<$T, $P, I>;
|
|
15
|
-
interface $BeforeI<$T extends Type, $P extends Type, I extends number, Constraints extends Unconstrained = ReplaceAt<$T['constraints'], I, Const<$P['constraints'][0]>>> extends $Type<$T> {
|
|
16
|
-
type: _apply<$T, ReplaceAt<this['arguments'], I, $P>>;
|
|
17
|
-
constraints: Constraints;
|
|
18
|
-
contra: Contra<Constraints>;
|
|
19
|
-
namedConstraints: NamedConstraints<this>;
|
|
20
|
-
}
|
|
21
|
-
interface $BeforeN<$T extends Type, $P extends Type, Constraints extends Unconstrained = $T['constraints'] extends infer I extends unknown[] ? {
|
|
22
|
-
[K in keyof I]: $P['constraints'][0];
|
|
23
|
-
} : unknown[]> extends $Type<$T> {
|
|
24
|
-
type: _apply<$T, this['arguments'] extends (infer I extends ArrayLike) & unknown[] ? {
|
|
25
|
-
[K in keyof I]: _apply<$P, [I[K]]>;
|
|
26
|
-
} : ArrayLike>;
|
|
27
|
-
constraints: Constraints;
|
|
28
|
-
contra: Contra<Constraints>;
|
|
29
|
-
namedConstraints: NamedConstraints<this>;
|
|
30
|
-
}
|
|
31
|
-
interface $Type<$T extends Type> {
|
|
32
|
-
[k: number]: unknown;
|
|
33
|
-
names: $T['names'];
|
|
34
|
-
arg: $T['arg'];
|
|
35
|
-
arguments: unknown[];
|
|
36
|
-
}
|
|
37
|
-
type ContraIndex<$T extends Type, M extends Type, I extends number, Model = [I] extends [never] ? M['constraints'][number] : M['constraints'][I]> = [Model] extends $T['constraints'] ? {
|
|
38
|
-
constraints: any[];
|
|
39
|
-
type: Model;
|
|
40
|
-
names: any;
|
|
41
|
-
arg: any;
|
|
42
|
-
} : {
|
|
43
|
-
constraints: [Model];
|
|
44
|
-
type: Model;
|
|
45
|
-
names: any;
|
|
46
|
-
arg: any;
|
|
47
|
-
};
|
|
48
|
-
type ReplaceAt<T extends {
|
|
49
|
-
[k: number]: unknown;
|
|
50
|
-
length: number;
|
|
51
|
-
}, N extends number, $P extends Type, L extends number = T['length'], I extends number = 0, R extends unknown[] = []> = I extends L ? R : ReplaceAt<T, N, $P, L, Next<I>, [...R, I extends N ? _apply<$P, [T[I]]> : T[I]]>;
|
|
52
|
-
export {};
|
|
1
|
+
import { Const } from "./Const.js";
|
|
2
|
+
import { _apply } from "./apply.js";
|
|
3
|
+
import { Next, ArrayLike } from "./utils.js";
|
|
4
|
+
import { Contra, NamedConstraints } from "./Type.js";
|
|
5
|
+
type Type = {
|
|
6
|
+
type: any;
|
|
7
|
+
constraints: any;
|
|
8
|
+
names: any;
|
|
9
|
+
arg: any;
|
|
10
|
+
};
|
|
11
|
+
type Unconstrained = {
|
|
12
|
+
[k: number]: unknown;
|
|
13
|
+
};
|
|
14
|
+
export type $Before<$T extends Type, $P extends ContraIndex<$P, $T, I>, I extends number = never> = [I] extends [never] ? $BeforeN<$T, $P> : $BeforeI<$T, $P, I>;
|
|
15
|
+
interface $BeforeI<$T extends Type, $P extends Type, I extends number, Constraints extends Unconstrained = ReplaceAt<$T['constraints'], I, Const<$P['constraints'][0]>>> extends $Type<$T> {
|
|
16
|
+
type: _apply<$T, ReplaceAt<this['arguments'], I, $P>>;
|
|
17
|
+
constraints: Constraints;
|
|
18
|
+
contra: Contra<Constraints>;
|
|
19
|
+
namedConstraints: NamedConstraints<this>;
|
|
20
|
+
}
|
|
21
|
+
interface $BeforeN<$T extends Type, $P extends Type, Constraints extends Unconstrained = $T['constraints'] extends infer I extends unknown[] ? {
|
|
22
|
+
[K in keyof I]: $P['constraints'][0];
|
|
23
|
+
} : unknown[]> extends $Type<$T> {
|
|
24
|
+
type: _apply<$T, this['arguments'] extends (infer I extends ArrayLike) & unknown[] ? {
|
|
25
|
+
[K in keyof I]: _apply<$P, [I[K]]>;
|
|
26
|
+
} : ArrayLike>;
|
|
27
|
+
constraints: Constraints;
|
|
28
|
+
contra: Contra<Constraints>;
|
|
29
|
+
namedConstraints: NamedConstraints<this>;
|
|
30
|
+
}
|
|
31
|
+
interface $Type<$T extends Type> {
|
|
32
|
+
[k: number]: unknown;
|
|
33
|
+
names: $T['names'];
|
|
34
|
+
arg: $T['arg'];
|
|
35
|
+
arguments: unknown[];
|
|
36
|
+
}
|
|
37
|
+
type ContraIndex<$T extends Type, M extends Type, I extends number, Model = [I] extends [never] ? M['constraints'][number] : M['constraints'][I]> = [Model] extends $T['constraints'] ? {
|
|
38
|
+
constraints: any[];
|
|
39
|
+
type: Model;
|
|
40
|
+
names: any;
|
|
41
|
+
arg: any;
|
|
42
|
+
} : {
|
|
43
|
+
constraints: [Model];
|
|
44
|
+
type: Model;
|
|
45
|
+
names: any;
|
|
46
|
+
arg: any;
|
|
47
|
+
};
|
|
48
|
+
type ReplaceAt<T extends {
|
|
49
|
+
[k: number]: unknown;
|
|
50
|
+
length: number;
|
|
51
|
+
}, N extends number, $P extends Type, L extends number = T['length'], I extends number = 0, R extends unknown[] = []> = I extends L ? R : ReplaceAt<T, N, $P, L, Next<I>, [...R, I extends N ? _apply<$P, [T[I]]> : T[I]]>;
|
|
52
|
+
export {};
|
package/dist/$Before.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/dist/Const.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { Type } from './Type';
|
|
2
|
-
export { Const, $Const };
|
|
3
|
-
/**
|
|
4
|
-
* Turn a type `T` into a constant `Type<❋, T>`, totally ignoring arity and type constraints on its input.
|
|
5
|
-
*/
|
|
6
|
-
type Const<T> = ConstantType<{
|
|
7
|
-
type: T;
|
|
8
|
-
}, {
|
|
9
|
-
constraints: any;
|
|
10
|
-
names: any;
|
|
11
|
-
}>;
|
|
12
|
-
interface ConstantType<Out extends {
|
|
13
|
-
type: any;
|
|
14
|
-
}, __> {
|
|
15
|
-
[k: number]: any;
|
|
16
|
-
type: Out['type'];
|
|
17
|
-
arguments: any[] & {
|
|
18
|
-
length: any;
|
|
19
|
-
};
|
|
20
|
-
namedConstraints: any;
|
|
21
|
-
arg: any;
|
|
22
|
-
constraints: any;
|
|
23
|
-
names: any;
|
|
24
|
-
contra: any;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Turn the input into a constant `Type<❋, T>`, totally ignoring arity and type constraints on its input.
|
|
28
|
-
*/
|
|
29
|
-
interface $Const extends Type<1> {
|
|
30
|
-
type: Const<this[0]>;
|
|
31
|
-
}
|
|
1
|
+
import { Type } from './Type.js';
|
|
2
|
+
export { Const, $Const };
|
|
3
|
+
/**
|
|
4
|
+
* Turn a type `T` into a constant `Type<❋, T>`, totally ignoring arity and type constraints on its input.
|
|
5
|
+
*/
|
|
6
|
+
type Const<T> = ConstantType<{
|
|
7
|
+
type: T;
|
|
8
|
+
}, {
|
|
9
|
+
constraints: any;
|
|
10
|
+
names: any;
|
|
11
|
+
}>;
|
|
12
|
+
interface ConstantType<Out extends {
|
|
13
|
+
type: any;
|
|
14
|
+
}, __> {
|
|
15
|
+
[k: number]: any;
|
|
16
|
+
type: Out['type'];
|
|
17
|
+
arguments: any[] & {
|
|
18
|
+
length: any;
|
|
19
|
+
};
|
|
20
|
+
namedConstraints: any;
|
|
21
|
+
arg: any;
|
|
22
|
+
constraints: any;
|
|
23
|
+
names: any;
|
|
24
|
+
contra: any;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Turn the input into a constant `Type<❋, T>`, totally ignoring arity and type constraints on its input.
|
|
28
|
+
*/
|
|
29
|
+
interface $Const extends Type<1> {
|
|
30
|
+
type: Const<this[0]>;
|
|
31
|
+
}
|
package/dist/Const.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/dist/Flow.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { _apply, _Type } from './apply';
|
|
2
|
-
import { Type } from './Type';
|
|
3
|
-
import { Next } from './utils';
|
|
4
|
-
export { Flow };
|
|
5
|
-
type Flow<$Ts extends Composable, Composable extends (_Type & {
|
|
6
|
-
contra: any;
|
|
7
|
-
})[] = $Ts extends [_Type] ? [_Type] : Check<$Ts>> = Composition<{
|
|
8
|
-
type: Fallback<$Ts>;
|
|
9
|
-
constraints: $Ts[0]['constraints'];
|
|
10
|
-
names: $Ts[0]['names'];
|
|
11
|
-
}, $Ts>;
|
|
12
|
-
type Descriptor = {
|
|
13
|
-
type: any;
|
|
14
|
-
constraints: any;
|
|
15
|
-
names: any;
|
|
16
|
-
};
|
|
17
|
-
interface Composition<D extends Descriptor, $Ts extends (_Type & {
|
|
18
|
-
contra: any;
|
|
19
|
-
})[]> extends Type {
|
|
20
|
-
type: unknown[] extends this['arguments'] ? D['type'] : Pipe<[_apply<$Ts[0], this['arguments']>], $Ts>;
|
|
21
|
-
names: D['names'];
|
|
22
|
-
constraints: D['constraints'];
|
|
23
|
-
contra: $Ts[0]['contra'];
|
|
24
|
-
namedConstraints: $Ts[0]['namedConstraints'];
|
|
25
|
-
}
|
|
26
|
-
type Fallback<$Ts> = $Ts extends [...any, infer $T extends {
|
|
27
|
-
type: unknown;
|
|
28
|
-
}] ? $T['type'] : never;
|
|
29
|
-
export type Check<T extends unknown[], R extends _Type[] = [], Last extends _Type[] = []> = T extends [infer A extends _Type, infer B extends _Type, ...infer Rest] ? Check2<A, B> extends infer C extends [_Type, _Type] ? Check<Rest, [...R, ...Last, C[0]], [C[1]]> : never : T extends [infer A extends _Type, infer B extends _Type] ? [...R, ...Last, ...Check2<A, B>] : T extends [infer A extends _Type] ? Last extends [] ? [...R, A] : [...R, ...Check2<Last[0], A>] : [...R, ...Last];
|
|
30
|
-
type Check2<A extends _Type, B extends _Type> = A['type'] extends B['constraints'][0] ? [A, B] : [Type<A['constraints'], B['constraints'][0]>, B];
|
|
31
|
-
type Pipe<Args extends unknown[], $Ts extends _Type[], I extends number = 1, R = _apply<$Ts[I], Args>, N extends number = Next<I>> = N extends $Ts['length'] ? R : R extends $Ts[N]['constraints'][0] ? Pipe<[R], $Ts, N> : never;
|
|
1
|
+
import { _apply, _Type } from './apply.js';
|
|
2
|
+
import { Type } from './Type.js';
|
|
3
|
+
import { Next } from './utils.js';
|
|
4
|
+
export { Flow };
|
|
5
|
+
type Flow<$Ts extends Composable, Composable extends (_Type & {
|
|
6
|
+
contra: any;
|
|
7
|
+
})[] = $Ts extends [_Type] ? [_Type] : Check<$Ts>> = Composition<{
|
|
8
|
+
type: Fallback<$Ts>;
|
|
9
|
+
constraints: $Ts[0]['constraints'];
|
|
10
|
+
names: $Ts[0]['names'];
|
|
11
|
+
}, $Ts>;
|
|
12
|
+
type Descriptor = {
|
|
13
|
+
type: any;
|
|
14
|
+
constraints: any;
|
|
15
|
+
names: any;
|
|
16
|
+
};
|
|
17
|
+
interface Composition<D extends Descriptor, $Ts extends (_Type & {
|
|
18
|
+
contra: any;
|
|
19
|
+
})[]> extends Type {
|
|
20
|
+
type: unknown[] extends this['arguments'] ? D['type'] : Pipe<[_apply<$Ts[0], this['arguments']>], $Ts>;
|
|
21
|
+
names: D['names'];
|
|
22
|
+
constraints: D['constraints'];
|
|
23
|
+
contra: $Ts[0]['contra'];
|
|
24
|
+
namedConstraints: $Ts[0]['namedConstraints'];
|
|
25
|
+
}
|
|
26
|
+
type Fallback<$Ts> = $Ts extends [...any, infer $T extends {
|
|
27
|
+
type: unknown;
|
|
28
|
+
}] ? $T['type'] : never;
|
|
29
|
+
export type Check<T extends unknown[], R extends _Type[] = [], Last extends _Type[] = []> = T extends [infer A extends _Type, infer B extends _Type, ...infer Rest] ? Check2<A, B> extends infer C extends [_Type, _Type] ? Check<Rest, [...R, ...Last, C[0]], [C[1]]> : never : T extends [infer A extends _Type, infer B extends _Type] ? [...R, ...Last, ...Check2<A, B>] : T extends [infer A extends _Type] ? Last extends [] ? [...R, A] : [...R, ...Check2<Last[0], A>] : [...R, ...Last];
|
|
30
|
+
type Check2<A extends _Type, B extends _Type> = A['type'] extends B['constraints'][0] ? [A, B] : [Type<A['constraints'], B['constraints'][0]>, B];
|
|
31
|
+
type Pipe<Args extends unknown[], $Ts extends _Type[], I extends number = 1, R = _apply<$Ts[I], Args>, N extends number = Next<I>> = N extends $Ts['length'] ? R : R extends $Ts[N]['constraints'][0] ? Pipe<[R], $Ts, N> : never;
|
package/dist/Flow.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/dist/From.d.ts
CHANGED
|
@@ -1,70 +1,69 @@
|
|
|
1
|
-
import { Contra, NamedConstraints } from './Type';
|
|
2
|
-
import { ArrayLike,
|
|
3
|
-
export { From };
|
|
4
|
-
type Named = ({
|
|
5
|
-
[k: PropertyKey]: string;
|
|
6
|
-
} | undefined)[];
|
|
7
|
-
type None = {};
|
|
8
|
-
/** Create a new `Type` based upon a Mappable `T`.
|
|
9
|
-
*
|
|
10
|
-
* Optionally take a tuple `Args` to specify which fields to turn into a parameter and in what order they must be applied. Parameters can be set to be optional. Named parameters are created automatically for object types, they can be renamed.
|
|
11
|
-
*
|
|
12
|
-
* */
|
|
13
|
-
type From<T extends Mappable<any>, Args extends readonly (keyof T | undefined)[] | Named = never> = ([
|
|
14
|
-
Args
|
|
15
|
-
] extends [never] ? (T extends unknown[] ? GetIndices<T> : Union2Tuple<keyof T>) extends infer K ? {
|
|
16
|
-
constraints: PseudoTuple<T, K>;
|
|
17
|
-
names: None;
|
|
18
|
-
keys: K;
|
|
19
|
-
} : never : Args extends Named ? {
|
|
20
|
-
constraints: ToConstraints<T, Args>;
|
|
21
|
-
names: GetNames<Args>;
|
|
22
|
-
keys: GetKeys<Args>;
|
|
23
|
-
} : {
|
|
24
|
-
constraints: PseudoTuple<T, Args>;
|
|
25
|
-
names: Args extends (string | undefined)[] ? GenerateNames<Args> : {};
|
|
26
|
-
keys: Required<Args>;
|
|
27
|
-
}) extends infer D extends Descriptor ? FromTemplate<{
|
|
28
|
-
type: T;
|
|
29
|
-
}, D> : never;
|
|
30
|
-
type Descriptor = {
|
|
31
|
-
constraints: any;
|
|
32
|
-
names: any;
|
|
33
|
-
keys: any;
|
|
34
|
-
};
|
|
35
|
-
interface FromTemplate<T extends {
|
|
36
|
-
type: any;
|
|
37
|
-
}, D extends Descriptor> {
|
|
38
|
-
[k: number]: unknown;
|
|
39
|
-
type: T['type'] extends infer Type ? unknown[] extends this['arguments'] ? Type : {
|
|
40
|
-
[K in keyof Type]: Value<Type[K], this['arguments'], IndexOf<K, D['keys']>, D['constraints']>;
|
|
41
|
-
} : never;
|
|
42
|
-
namedConstraints: NamedConstraints<D>;
|
|
43
|
-
names: D['names'];
|
|
44
|
-
constraints: D['constraints'];
|
|
45
|
-
contra: Contra<D['constraints']>;
|
|
46
|
-
arg: any;
|
|
47
|
-
arguments: unknown[];
|
|
48
|
-
}
|
|
49
|
-
type GetIndices<T extends unknown[]> = {
|
|
50
|
-
[K in keyof T]-?: K;
|
|
51
|
-
};
|
|
52
|
-
export type Value<T, This extends ArrayLike, I, Constraints extends ArrayLike> = [
|
|
53
|
-
I
|
|
54
|
-
] extends [never] ? T : IsOptional<Constraints, I> extends true ? This[I & number] extends undefined ? T : This[I & number] : This[I & number];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
};
|
|
1
|
+
import { Contra, NamedConstraints } from './Type.js';
|
|
2
|
+
import { ArrayLike, IsOptional, Mappable, Union2Tuple, Int, IndexOf } from './utils.js';
|
|
3
|
+
export { From };
|
|
4
|
+
type Named = ({
|
|
5
|
+
[k: PropertyKey]: string;
|
|
6
|
+
} | undefined)[];
|
|
7
|
+
type None = {};
|
|
8
|
+
/** Create a new `Type` based upon a Mappable `T`.
|
|
9
|
+
*
|
|
10
|
+
* Optionally take a tuple `Args` to specify which fields to turn into a parameter and in what order they must be applied. Parameters can be set to be optional. Named parameters are created automatically for object types, they can be renamed.
|
|
11
|
+
*
|
|
12
|
+
* */
|
|
13
|
+
type From<T extends Mappable<any>, Args extends readonly (keyof T | undefined)[] | Named = never> = ([
|
|
14
|
+
Args
|
|
15
|
+
] extends [never] ? (T extends unknown[] ? GetIndices<T> : Union2Tuple<keyof T>) extends infer K ? {
|
|
16
|
+
constraints: PseudoTuple<T, K>;
|
|
17
|
+
names: None;
|
|
18
|
+
keys: K;
|
|
19
|
+
} : never : Args extends Named ? {
|
|
20
|
+
constraints: ToConstraints<T, Args>;
|
|
21
|
+
names: GetNames<Args>;
|
|
22
|
+
keys: GetKeys<Args>;
|
|
23
|
+
} : {
|
|
24
|
+
constraints: PseudoTuple<T, Args>;
|
|
25
|
+
names: Args extends (string | undefined)[] ? GenerateNames<Args> : {};
|
|
26
|
+
keys: Required<Args>;
|
|
27
|
+
}) extends infer D extends Descriptor ? FromTemplate<{
|
|
28
|
+
type: T;
|
|
29
|
+
}, D> : never;
|
|
30
|
+
type Descriptor = {
|
|
31
|
+
constraints: any;
|
|
32
|
+
names: any;
|
|
33
|
+
keys: any;
|
|
34
|
+
};
|
|
35
|
+
interface FromTemplate<T extends {
|
|
36
|
+
type: any;
|
|
37
|
+
}, D extends Descriptor> {
|
|
38
|
+
[k: number]: unknown;
|
|
39
|
+
type: T['type'] extends infer Type ? unknown[] extends this['arguments'] ? Type : {
|
|
40
|
+
[K in keyof Type]: Value<Type[K], this['arguments'], IndexOf<K, D['keys']>, D['constraints']>;
|
|
41
|
+
} : never;
|
|
42
|
+
namedConstraints: NamedConstraints<D>;
|
|
43
|
+
names: D['names'];
|
|
44
|
+
constraints: D['constraints'];
|
|
45
|
+
contra: Contra<D['constraints']>;
|
|
46
|
+
arg: any;
|
|
47
|
+
arguments: unknown[];
|
|
48
|
+
}
|
|
49
|
+
type GetIndices<T extends unknown[]> = {
|
|
50
|
+
[K in keyof T]-?: K;
|
|
51
|
+
};
|
|
52
|
+
export type Value<T, This extends ArrayLike, I, Constraints extends ArrayLike> = [
|
|
53
|
+
I
|
|
54
|
+
] extends [never] ? T : IsOptional<Constraints, I> extends true ? This[I & number] extends undefined ? T : This[I & number] : This[I & number];
|
|
55
|
+
type PseudoTuple<T, Keys> = {
|
|
56
|
+
[K in keyof Keys]: Exclude<T[Keys[K] & keyof T], undefined>;
|
|
57
|
+
};
|
|
58
|
+
type ToConstraints<T, Args extends Named> = {
|
|
59
|
+
[K in keyof Args]: T[keyof (Args[K] & {}) & keyof T];
|
|
60
|
+
};
|
|
61
|
+
type GetKeys<Args extends Named, R = Required<Args>> = {
|
|
62
|
+
[K in keyof R]: keyof R[K];
|
|
63
|
+
};
|
|
64
|
+
type GetNames<Args extends Named, T extends Required<Named> = Required<Args>> = unknown & {
|
|
65
|
+
[K in keyof T as T[K & `${number}`][keyof T[K]]]: Int<K>;
|
|
66
|
+
};
|
|
67
|
+
type GenerateNames<Args extends (string | undefined)[]> = unknown & {
|
|
68
|
+
[K in Exclude<keyof Args, keyof []> as Args[K] & string]: Int<K>;
|
|
69
|
+
};
|
package/dist/From.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/dist/Pipe.d.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { Next } from "./utils";
|
|
2
|
-
import { _apply, apply, _Type as Type } from './apply';
|
|
3
|
-
type _Type<C = any> = {
|
|
4
|
-
type: any;
|
|
5
|
-
constraints: C;
|
|
6
|
-
};
|
|
7
|
-
type TooManyArgs = 'You can compose up to 10 free types with Pipe';
|
|
8
|
-
type WrongArg = 'would be called with wrong argument';
|
|
9
|
-
/** Pipe an arguments list or named arguments through a composition of free types
|
|
10
|
-
* ```
|
|
11
|
-
* type Foo = Pipe<[1, 2], $Add, $Next, $Exclaim> // "4!"
|
|
12
|
-
* ```
|
|
13
|
-
* ---
|
|
14
|
-
* **Note**: Error messages are narrower than they need to be:
|
|
15
|
-
* ```
|
|
16
|
-
* Pipe<['foo'], $Exclain, $Next>
|
|
17
|
-
* // ~~~~~
|
|
18
|
-
* // Type<[number], number>' does not satisfy the constraint 'Type<["foo!"], number>
|
|
19
|
-
* ```
|
|
20
|
-
* Understand it as `Type<[number], number>` would be called with wrong argument `"foo!"`. This inconvenience is required for generic higher order compositions to work properly.
|
|
21
|
-
*/
|
|
22
|
-
export type Pipe<Args extends [STOP] extends [never] ? Check : TooManyArgs, A extends Type = never, B extends _<B, WrongArg, RA> = never, C extends _<C, WrongArg, RB> = never, D extends _<D, WrongArg, RC> = never, E extends _<E, WrongArg, RD> = never, F extends _<F, WrongArg, RE> = never, G extends _<G, WrongArg, RF> = never, H extends _<H, WrongArg, RG> = never, I extends _<I, WrongArg, RH> = never, J extends _<J, WrongArg, RI> = never, STOP = never, RA = apply<A, Args, any>, RB = _apply<B, [RA]>, RC = _apply<C, [RB]>, RD = _apply<D, [RC]>, RE = _apply<E, [RD]>, RF = _apply<F, [RE]>, RG = _apply<G, [RF]>, RH = _apply<H, [RG]>, RI = _apply<I, [RH]>, RJ = _apply<J, [RI]>, Check = Args extends readonly unknown[] ? A['constraints'] : A['namedConstraints']> = Result<[RA, RB, RC, RD, RE, RF, RG, RH, RI, RJ]>;
|
|
23
|
-
type Result<T extends unknown[], I extends number = 0, R = never> = [
|
|
24
|
-
T[I]
|
|
25
|
-
] extends [never] ? R : I extends T['length'] ? R : Result<T, Next<I>, T[I]>;
|
|
26
|
-
type _<$T extends _Type, _, $U> = [$U] extends $T['constraints'] ? any : _Type<[$U]>;
|
|
27
|
-
export {};
|
|
1
|
+
import { Next } from "./utils.js";
|
|
2
|
+
import { _apply, apply, _Type as Type } from './apply.js';
|
|
3
|
+
type _Type<C = any> = {
|
|
4
|
+
type: any;
|
|
5
|
+
constraints: C;
|
|
6
|
+
};
|
|
7
|
+
type TooManyArgs = 'You can compose up to 10 free types with Pipe';
|
|
8
|
+
type WrongArg = 'would be called with wrong argument';
|
|
9
|
+
/** Pipe an arguments list or named arguments through a composition of free types
|
|
10
|
+
* ```
|
|
11
|
+
* type Foo = Pipe<[1, 2], $Add, $Next, $Exclaim> // "4!"
|
|
12
|
+
* ```
|
|
13
|
+
* ---
|
|
14
|
+
* **Note**: Error messages are narrower than they need to be:
|
|
15
|
+
* ```
|
|
16
|
+
* Pipe<['foo'], $Exclain, $Next>
|
|
17
|
+
* // ~~~~~
|
|
18
|
+
* // Type<[number], number>' does not satisfy the constraint 'Type<["foo!"], number>
|
|
19
|
+
* ```
|
|
20
|
+
* Understand it as `Type<[number], number>` would be called with wrong argument `"foo!"`. This inconvenience is required for generic higher order compositions to work properly.
|
|
21
|
+
*/
|
|
22
|
+
export type Pipe<Args extends [STOP] extends [never] ? Check : TooManyArgs, A extends Type = never, B extends _<B, WrongArg, RA> = never, C extends _<C, WrongArg, RB> = never, D extends _<D, WrongArg, RC> = never, E extends _<E, WrongArg, RD> = never, F extends _<F, WrongArg, RE> = never, G extends _<G, WrongArg, RF> = never, H extends _<H, WrongArg, RG> = never, I extends _<I, WrongArg, RH> = never, J extends _<J, WrongArg, RI> = never, STOP = never, RA = apply<A, Args, any>, RB = _apply<B, [RA]>, RC = _apply<C, [RB]>, RD = _apply<D, [RC]>, RE = _apply<E, [RD]>, RF = _apply<F, [RE]>, RG = _apply<G, [RF]>, RH = _apply<H, [RG]>, RI = _apply<I, [RH]>, RJ = _apply<J, [RI]>, Check = Args extends readonly unknown[] ? A['constraints'] : A['namedConstraints']> = Result<[RA, RB, RC, RD, RE, RF, RG, RH, RI, RJ]>;
|
|
23
|
+
type Result<T extends unknown[], I extends number = 0, R = never> = [
|
|
24
|
+
T[I]
|
|
25
|
+
] extends [never] ? R : I extends T['length'] ? R : Result<T, Next<I>, T[I]>;
|
|
26
|
+
type _<$T extends _Type, _, $U> = [$U] extends $T['constraints'] ? any : _Type<[$U]>;
|
|
27
|
+
export {};
|
package/dist/Pipe.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/dist/Replace.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { unwrap, Unwrapped, Search } from './unwrap';
|
|
2
|
-
import { _apply } from './apply';
|
|
3
|
-
import { TypesMap } from './TypesMap';
|
|
4
|
-
export { Replace };
|
|
5
|
-
/** Replace the inner value of a type with compatible arguments.
|
|
6
|
-
*
|
|
7
|
-
* Can be used to constrain the inner value of a type
|
|
8
|
-
*/
|
|
9
|
-
type Replace<T, Args extends U['type']['constraints'], From extends Search = TypesMap, U extends Unwrapped = unwrap<T, From>> = _apply<U['type'], Args>;
|
|
1
|
+
import { unwrap, Unwrapped, Search } from './unwrap.js';
|
|
2
|
+
import { _apply } from './apply.js';
|
|
3
|
+
import { TypesMap } from './TypesMap.js';
|
|
4
|
+
export { Replace };
|
|
5
|
+
/** Replace the inner value of a type with compatible arguments.
|
|
6
|
+
*
|
|
7
|
+
* Can be used to constrain the inner value of a type
|
|
8
|
+
*/
|
|
9
|
+
type Replace<T, Args extends U['type']['constraints'], From extends Search = TypesMap, U extends Unwrapped = unwrap<T, From>> = _apply<U['type'], Args>;
|
package/dist/Replace.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|