@modular-component/core 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +31 -354
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -157
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +155 -240
- package/dist/types/arguments.d.ts +0 -33
- package/dist/types/arguments.d.ts.map +0 -1
- package/dist/types/arguments.js +0 -6
- package/dist/types/arguments.js.map +0 -1
- package/dist/types/methods/add.d.ts +0 -23
- package/dist/types/methods/add.d.ts.map +0 -1
- package/dist/types/methods/add.js +0 -8
- package/dist/types/methods/add.js.map +0 -1
- package/dist/types/methods/at.d.ts +0 -22
- package/dist/types/methods/at.d.ts.map +0 -1
- package/dist/types/methods/at.js +0 -7
- package/dist/types/methods/at.js.map +0 -1
- package/dist/types/methods/before.d.ts +0 -22
- package/dist/types/methods/before.d.ts.map +0 -1
- package/dist/types/methods/before.js +0 -7
- package/dist/types/methods/before.js.map +0 -1
- package/dist/types/methods/hook.d.ts +0 -14
- package/dist/types/methods/hook.d.ts.map +0 -1
- package/dist/types/methods/hook.js +0 -7
- package/dist/types/methods/hook.js.map +0 -1
- package/dist/types/methods/mock.d.ts +0 -26
- package/dist/types/methods/mock.d.ts.map +0 -1
- package/dist/types/methods/mock.js +0 -6
- package/dist/types/methods/mock.js.map +0 -1
- package/dist/types/methods/with.d.ts +0 -52
- package/dist/types/methods/with.d.ts.map +0 -1
- package/dist/types/methods/with.js +0 -8
- package/dist/types/methods/with.js.map +0 -1
- package/dist/types/methods.d.ts +0 -10
- package/dist/types/methods.d.ts.map +0 -1
- package/dist/types/methods.js +0 -5
- package/dist/types/methods.js.map +0 -1
- package/dist/types/modular-component.d.ts +0 -16
- package/dist/types/modular-component.d.ts.map +0 -1
- package/dist/types/modular-component.js +0 -5
- package/dist/types/modular-component.js.map +0 -1
- package/dist/types/stage.d.ts +0 -41
- package/dist/types/stage.d.ts.map +0 -1
- package/dist/types/stage.js +0 -5
- package/dist/types/stage.js.map +0 -1
- package/dist/types/utils.d.ts +0 -24
- package/dist/types/utils.d.ts.map +0 -1
- package/dist/types/utils.js +0 -5
- package/dist/types/utils.js.map +0 -1
- package/dist/types/validation.d.ts +0 -4
- package/dist/types/validation.d.ts.map +0 -1
- package/dist/types/validation.js +0 -2
- package/dist/types/validation.js.map +0 -1
- package/src/types/arguments.ts +0 -57
- package/src/types/methods/add.ts +0 -52
- package/src/types/methods/at.ts +0 -64
- package/src/types/methods/before.ts +0 -64
- package/src/types/methods/hook.ts +0 -27
- package/src/types/methods/mock.ts +0 -90
- package/src/types/methods/with.ts +0 -173
- package/src/types/methods.ts +0 -11
- package/src/types/modular-component.ts +0 -27
- package/src/types/stage.ts +0 -91
- package/src/types/utils.ts +0 -63
- package/src/types/validation.ts +0 -13
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Methods for mocking the value returned by a given stage,
|
|
3
|
-
* replacing the stage and bypassing its transform function
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { ModularComponent } from '../modular-component'
|
|
7
|
-
import { MethodRecord } from '../methods'
|
|
8
|
-
import { ValidateIndex } from '../validation'
|
|
9
|
-
import { ComputeArguments } from '../arguments'
|
|
10
|
-
import { FilterNever, Last, ToIndices } from '../utils'
|
|
11
|
-
import { BeforeStage, ModularStages, StageIndices, StageTuple } from '../stage'
|
|
12
|
-
|
|
13
|
-
interface ModularMockMethodIndices<
|
|
14
|
-
Props extends {},
|
|
15
|
-
Ref,
|
|
16
|
-
Methods extends Record<string, MethodRecord>,
|
|
17
|
-
Stages extends StageTuple,
|
|
18
|
-
Method extends keyof Methods,
|
|
19
|
-
Indices extends number[],
|
|
20
|
-
Symbol extends keyof ModularStages = Methods[Method]['symbol'],
|
|
21
|
-
> {
|
|
22
|
-
<
|
|
23
|
-
Arguments extends ComputeArguments<
|
|
24
|
-
Props,
|
|
25
|
-
Ref,
|
|
26
|
-
Methods,
|
|
27
|
-
BeforeStage<Stages, StageIndex>
|
|
28
|
-
>,
|
|
29
|
-
// Value validation
|
|
30
|
-
Value extends Stages[StageIndex]['value'],
|
|
31
|
-
Mock extends ModularStages<Arguments, Value>[Symbol] extends {
|
|
32
|
-
transform: infer T
|
|
33
|
-
}
|
|
34
|
-
? T
|
|
35
|
-
: Value,
|
|
36
|
-
// Validate index
|
|
37
|
-
StageIndex extends Index extends number ? Indices[Index] : Last<Indices>,
|
|
38
|
-
ValidIndex extends ValidateIndex<Index, ToIndices<Indices>>,
|
|
39
|
-
Index extends number,
|
|
40
|
-
>(
|
|
41
|
-
mock: Mock,
|
|
42
|
-
index: ValidIndex extends true ? Index : ToIndices<Indices>,
|
|
43
|
-
): ModularComponent<Props, Ref, Methods, Stages>
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface ModularMockMethodLast<
|
|
47
|
-
Props extends {},
|
|
48
|
-
Ref,
|
|
49
|
-
Methods extends Record<string, MethodRecord>,
|
|
50
|
-
Stages extends StageTuple,
|
|
51
|
-
Method extends keyof Methods,
|
|
52
|
-
Index extends number,
|
|
53
|
-
Symbol extends keyof ModularStages = Methods[Method]['symbol'],
|
|
54
|
-
> {
|
|
55
|
-
<
|
|
56
|
-
// Value validation
|
|
57
|
-
Value extends Stages[Index]['value'],
|
|
58
|
-
Mock extends ModularStages<any, Value>[Symbol] extends {
|
|
59
|
-
transform: infer T
|
|
60
|
-
}
|
|
61
|
-
? T
|
|
62
|
-
: Value,
|
|
63
|
-
>(
|
|
64
|
-
mock: Mock,
|
|
65
|
-
): ModularComponent<Props, Ref, Methods, Stages>
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
type ModularMockMethod<
|
|
69
|
-
Props extends {},
|
|
70
|
-
Ref,
|
|
71
|
-
Methods extends Record<string, MethodRecord>,
|
|
72
|
-
Stages extends StageTuple,
|
|
73
|
-
Method extends keyof Methods,
|
|
74
|
-
Symbol extends keyof ModularStages = Methods[Method]['symbol'],
|
|
75
|
-
Indices extends StageIndices<Stages, Symbol> = StageIndices<Stages, Symbol>,
|
|
76
|
-
> = Indices['length'] extends 0
|
|
77
|
-
? never
|
|
78
|
-
: ModularMockMethodIndices<Props, Ref, Methods, Stages, Method, Indices> &
|
|
79
|
-
ModularMockMethodLast<Props, Ref, Methods, Stages, Method, Last<Indices>>
|
|
80
|
-
|
|
81
|
-
export type ModularMockMethods<
|
|
82
|
-
Props extends {},
|
|
83
|
-
Ref,
|
|
84
|
-
Methods extends Record<string, MethodRecord>,
|
|
85
|
-
Stages extends StageTuple,
|
|
86
|
-
> = FilterNever<{
|
|
87
|
-
[Method in keyof Methods as `mock${Method extends string
|
|
88
|
-
? Method
|
|
89
|
-
: never}`]: ModularMockMethod<Props, Ref, Methods, Stages, Method>
|
|
90
|
-
}>
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Main factory methods adding or editing an entry for a given
|
|
3
|
-
* stage. If multiple entries for the same stage were added
|
|
4
|
-
* with the `add` method, an index can be passed to select the
|
|
5
|
-
* entry to edit.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { ModularComponent } from '../modular-component'
|
|
9
|
-
import { Last, ToIndices } from '../utils'
|
|
10
|
-
import {
|
|
11
|
-
BeforeStage,
|
|
12
|
-
ModularStages,
|
|
13
|
-
StageIndices,
|
|
14
|
-
StageTuple,
|
|
15
|
-
UpsertStage,
|
|
16
|
-
} from '../stage'
|
|
17
|
-
import { MethodRecord } from '../methods'
|
|
18
|
-
import { ComputeArguments } from '../arguments'
|
|
19
|
-
import { RestrictValue, ValidateIndex } from '../validation'
|
|
20
|
-
|
|
21
|
-
interface ModularWithMethodDefault<
|
|
22
|
-
Props extends {},
|
|
23
|
-
Ref,
|
|
24
|
-
Methods extends Record<string, MethodRecord>,
|
|
25
|
-
Stages extends StageTuple,
|
|
26
|
-
Method extends keyof Methods,
|
|
27
|
-
Symbol extends keyof ModularStages = Methods[Method]['symbol'],
|
|
28
|
-
Arguments extends {} = ComputeArguments<Props, Ref, Methods, Stages>,
|
|
29
|
-
> {
|
|
30
|
-
<Value extends RestrictValue<Arguments, Symbol>>(
|
|
31
|
-
...args: undefined extends RestrictValue<Arguments, Symbol>
|
|
32
|
-
? [value?: Value]
|
|
33
|
-
: [value: Value]
|
|
34
|
-
): ModularComponent<
|
|
35
|
-
Props,
|
|
36
|
-
Ref,
|
|
37
|
-
Methods,
|
|
38
|
-
UpsertStage<Stages, { stage: Symbol; value: Value }>
|
|
39
|
-
>
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface ModularWithMethodIndices<
|
|
43
|
-
Props extends {},
|
|
44
|
-
Ref,
|
|
45
|
-
Methods extends Record<string, MethodRecord>,
|
|
46
|
-
Stages extends StageTuple,
|
|
47
|
-
Method extends keyof Methods,
|
|
48
|
-
Indices extends number[],
|
|
49
|
-
Symbol extends keyof ModularStages = Methods[Method]['symbol'],
|
|
50
|
-
> {
|
|
51
|
-
<
|
|
52
|
-
Arguments extends ComputeArguments<
|
|
53
|
-
Props,
|
|
54
|
-
Ref,
|
|
55
|
-
Methods,
|
|
56
|
-
BeforeStage<Stages, StageIndex>
|
|
57
|
-
>,
|
|
58
|
-
// Validate value
|
|
59
|
-
Value extends RestrictValue<Arguments, Symbol>,
|
|
60
|
-
PreviousValue extends Stages[StageIndex]['value'],
|
|
61
|
-
Valid extends ModularStages<Arguments, Value>[Symbol] extends {
|
|
62
|
-
validate: infer V
|
|
63
|
-
}
|
|
64
|
-
? V
|
|
65
|
-
: ModularStages<Arguments, Value>[Symbol] extends {
|
|
66
|
-
transform: infer V
|
|
67
|
-
}
|
|
68
|
-
? V
|
|
69
|
-
: Value,
|
|
70
|
-
PreviousValid extends ModularStages<
|
|
71
|
-
Arguments,
|
|
72
|
-
PreviousValue
|
|
73
|
-
>[Symbol] extends {
|
|
74
|
-
validate: infer V
|
|
75
|
-
}
|
|
76
|
-
? V
|
|
77
|
-
: ModularStages<Arguments, PreviousValue>[Symbol] extends {
|
|
78
|
-
transform: infer V
|
|
79
|
-
}
|
|
80
|
-
? V
|
|
81
|
-
: PreviousValue,
|
|
82
|
-
ValidValue extends [Valid] extends [PreviousValid] ? true : false,
|
|
83
|
-
// Validate index
|
|
84
|
-
StageIndex extends Index extends number ? Indices[Index] : Last<Indices>,
|
|
85
|
-
ValidIndex extends ValidateIndex<Index, ToIndices<Indices>>,
|
|
86
|
-
Index extends number,
|
|
87
|
-
>(
|
|
88
|
-
value: ValidValue extends true ? Value : PreviousValue,
|
|
89
|
-
index: ValidIndex extends true ? Index : ToIndices<Indices>,
|
|
90
|
-
): ModularComponent<
|
|
91
|
-
Props,
|
|
92
|
-
Ref,
|
|
93
|
-
Methods,
|
|
94
|
-
UpsertStage<Stages, { stage: Symbol; value: Value }, StageIndex>
|
|
95
|
-
>
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
interface ModularWithMethodLast<
|
|
99
|
-
Props extends {},
|
|
100
|
-
Ref,
|
|
101
|
-
Methods extends Record<string, MethodRecord>,
|
|
102
|
-
Stages extends StageTuple,
|
|
103
|
-
Method extends keyof Methods,
|
|
104
|
-
Index extends number,
|
|
105
|
-
Symbol extends keyof ModularStages = Methods[Method]['symbol'],
|
|
106
|
-
Arguments extends {} = ComputeArguments<
|
|
107
|
-
Props,
|
|
108
|
-
Ref,
|
|
109
|
-
Methods,
|
|
110
|
-
BeforeStage<Stages, Index>
|
|
111
|
-
>,
|
|
112
|
-
> {
|
|
113
|
-
<
|
|
114
|
-
// Validate value
|
|
115
|
-
Value extends RestrictValue<Arguments, Symbol>,
|
|
116
|
-
PreviousValue extends Stages[Index]['value'],
|
|
117
|
-
Valid extends ModularStages<Arguments, Value>[Symbol] extends {
|
|
118
|
-
validate: infer V
|
|
119
|
-
}
|
|
120
|
-
? V
|
|
121
|
-
: ModularStages<Arguments, Value>[Symbol] extends {
|
|
122
|
-
transform: infer V
|
|
123
|
-
}
|
|
124
|
-
? V
|
|
125
|
-
: Value,
|
|
126
|
-
PreviousValid extends ModularStages<
|
|
127
|
-
Arguments,
|
|
128
|
-
PreviousValue
|
|
129
|
-
>[Symbol] extends {
|
|
130
|
-
validate: infer V
|
|
131
|
-
}
|
|
132
|
-
? V
|
|
133
|
-
: ModularStages<Arguments, PreviousValue>[Symbol] extends {
|
|
134
|
-
transform: infer V
|
|
135
|
-
}
|
|
136
|
-
? V
|
|
137
|
-
: PreviousValue,
|
|
138
|
-
ValidValue extends [Valid] extends [PreviousValid] ? true : false,
|
|
139
|
-
>(
|
|
140
|
-
...args: undefined extends PreviousValue
|
|
141
|
-
? [value?: ValidValue extends true ? Value : PreviousValue]
|
|
142
|
-
: [value: ValidValue extends true ? Value : PreviousValue]
|
|
143
|
-
): ModularComponent<
|
|
144
|
-
Props,
|
|
145
|
-
Ref,
|
|
146
|
-
Methods,
|
|
147
|
-
UpsertStage<Stages, { stage: Symbol; value: Value }, Index>
|
|
148
|
-
>
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
type ModularWithMethod<
|
|
152
|
-
Props extends {},
|
|
153
|
-
Ref,
|
|
154
|
-
Methods extends Record<string, MethodRecord>,
|
|
155
|
-
Stages extends StageTuple,
|
|
156
|
-
Method extends keyof Methods,
|
|
157
|
-
Symbol extends keyof ModularStages = Methods[Method]['symbol'],
|
|
158
|
-
Indices extends StageIndices<Stages, Symbol> = StageIndices<Stages, Symbol>,
|
|
159
|
-
> = Indices['length'] extends 0
|
|
160
|
-
? ModularWithMethodDefault<Props, Ref, Methods, Stages, Method>
|
|
161
|
-
: ModularWithMethodIndices<Props, Ref, Methods, Stages, Method, Indices> &
|
|
162
|
-
ModularWithMethodLast<Props, Ref, Methods, Stages, Method, Last<Indices>>
|
|
163
|
-
|
|
164
|
-
export type ModularWithMethods<
|
|
165
|
-
Props extends {},
|
|
166
|
-
Ref,
|
|
167
|
-
Methods extends Record<string, MethodRecord>,
|
|
168
|
-
Stages extends StageTuple,
|
|
169
|
-
> = {
|
|
170
|
-
[Method in keyof Methods as `with${Method extends string
|
|
171
|
-
? Method
|
|
172
|
-
: never}`]: ModularWithMethod<Props, Ref, Methods, Stages, Method>
|
|
173
|
-
}
|
package/src/types/methods.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Main ModularComponent type
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { ForwardedRef, FunctionComponent, PropsWithChildren } from 'react'
|
|
6
|
-
|
|
7
|
-
import { StageTuple } from './stage'
|
|
8
|
-
import { MethodRecord } from './methods'
|
|
9
|
-
import { ModularWithMethods } from './methods/with'
|
|
10
|
-
import { ModularAddMethods } from './methods/add'
|
|
11
|
-
import { ModularAtMethods } from './methods/at'
|
|
12
|
-
import { ModularBeforeMethods } from './methods/before'
|
|
13
|
-
import { ModularMockMethods } from './methods/mock'
|
|
14
|
-
import { ModularHookMethods } from './methods/hook'
|
|
15
|
-
|
|
16
|
-
export type ModularComponent<
|
|
17
|
-
Props extends {},
|
|
18
|
-
Ref,
|
|
19
|
-
Methods extends Record<string, MethodRecord>,
|
|
20
|
-
Stages extends StageTuple,
|
|
21
|
-
> = ModularWithMethods<Props, Ref, Methods, Stages> &
|
|
22
|
-
ModularAddMethods<Props, Ref, Methods, Stages> &
|
|
23
|
-
ModularAtMethods<Props, Ref, Methods, Stages> &
|
|
24
|
-
ModularBeforeMethods<Props, Ref, Methods, Stages> &
|
|
25
|
-
ModularMockMethods<Props, Ref, Methods, Stages> &
|
|
26
|
-
ModularHookMethods<Props, Ref, Methods, Stages> &
|
|
27
|
-
FunctionComponent<PropsWithChildren<Props & { ref?: ForwardedRef<Ref> }>>
|
package/src/types/stage.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper for manipulating stages and stage tuples
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { At, Before, Reduce, After, OneLess } from './utils'
|
|
6
|
-
|
|
7
|
-
export interface ModularStages<Args = any, Value = any> {}
|
|
8
|
-
|
|
9
|
-
type StageRecord = {
|
|
10
|
-
stage: keyof ModularStages
|
|
11
|
-
value: unknown
|
|
12
|
-
}
|
|
13
|
-
export type StageTuple = StageRecord[]
|
|
14
|
-
|
|
15
|
-
export type AddStage<List extends StageTuple, Stage extends StageRecord> = [
|
|
16
|
-
...List,
|
|
17
|
-
Stage,
|
|
18
|
-
]
|
|
19
|
-
|
|
20
|
-
export type ReplaceStageAt<
|
|
21
|
-
List extends StageTuple,
|
|
22
|
-
Stage extends StageRecord,
|
|
23
|
-
At extends number | string,
|
|
24
|
-
> = {
|
|
25
|
-
[Index in keyof List]: Index extends At
|
|
26
|
-
? List[Index]['stage'] extends Stage['stage']
|
|
27
|
-
? Stage
|
|
28
|
-
: List[Index]
|
|
29
|
-
: List[Index]
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
type ReplaceStage<
|
|
33
|
-
List extends StageTuple,
|
|
34
|
-
Stage extends StageRecord,
|
|
35
|
-
At extends number | string = never,
|
|
36
|
-
> = [At] extends [never]
|
|
37
|
-
? {
|
|
38
|
-
[Index in keyof List]: List[Index]['stage'] extends Stage['stage']
|
|
39
|
-
? Stage
|
|
40
|
-
: List[Index]
|
|
41
|
-
}
|
|
42
|
-
: ReplaceStageAt<List, Stage, At>
|
|
43
|
-
|
|
44
|
-
export type ExtractStage<
|
|
45
|
-
List extends StageTuple,
|
|
46
|
-
Stage extends symbol,
|
|
47
|
-
Union = List[number],
|
|
48
|
-
> = Union extends { stage: Stage; value: infer U }
|
|
49
|
-
? { stage: Stage; value: U }
|
|
50
|
-
: never
|
|
51
|
-
|
|
52
|
-
export type UpsertStage<
|
|
53
|
-
List extends StageTuple,
|
|
54
|
-
Stage extends StageRecord,
|
|
55
|
-
At extends number = never,
|
|
56
|
-
> = [ExtractStage<List, Stage['stage']>] extends [never]
|
|
57
|
-
? AddStage<List, Stage>
|
|
58
|
-
: ReplaceStage<List, Stage, At>
|
|
59
|
-
|
|
60
|
-
type IsolateStage<Tuple extends StageTuple, Stage extends symbol> = {
|
|
61
|
-
[key in keyof Tuple]: Tuple[key]['stage'] extends Stage ? key : never
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export type StageIndices<
|
|
65
|
-
Tuple extends StageTuple,
|
|
66
|
-
Stage extends symbol,
|
|
67
|
-
> = Reduce<IsolateStage<Tuple, Stage>>
|
|
68
|
-
|
|
69
|
-
export type AtStage<
|
|
70
|
-
Tuple extends StageTuple,
|
|
71
|
-
Index extends number | string,
|
|
72
|
-
> = At<Tuple, Index> extends StageTuple ? At<Tuple, Index> : []
|
|
73
|
-
|
|
74
|
-
export type BeforeStage<
|
|
75
|
-
Tuple extends StageTuple,
|
|
76
|
-
Index extends number | string,
|
|
77
|
-
> = Before<Tuple, Index> extends StageTuple ? Before<Tuple, Index> : []
|
|
78
|
-
|
|
79
|
-
type AfterStage<
|
|
80
|
-
Tuple extends StageTuple,
|
|
81
|
-
Index extends number | string,
|
|
82
|
-
> = After<Tuple, Index> extends StageTuple ? After<Tuple, Index> : []
|
|
83
|
-
|
|
84
|
-
export type CleanUpStages<Tuple extends StageTuple> = {
|
|
85
|
-
[key in keyof Tuple]: StageIndices<
|
|
86
|
-
OneLess<AfterStage<Tuple, key>>,
|
|
87
|
-
Tuple[key]['stage']
|
|
88
|
-
>['length'] extends 0
|
|
89
|
-
? Tuple[key]
|
|
90
|
-
: never
|
|
91
|
-
}
|
package/src/types/utils.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic type helpers (tuple, union, object...)
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// Tuple handling
|
|
6
|
-
export type OneLess<Tuple extends unknown[]> = Tuple extends [
|
|
7
|
-
unknown,
|
|
8
|
-
...infer Rest,
|
|
9
|
-
]
|
|
10
|
-
? Rest
|
|
11
|
-
: Tuple
|
|
12
|
-
export type Before<
|
|
13
|
-
Tuple extends unknown[],
|
|
14
|
-
Index extends string | number,
|
|
15
|
-
> = `${Tuple['length']}` extends `${Index}`
|
|
16
|
-
? Tuple
|
|
17
|
-
: Tuple extends [...infer Keep, infer Drop]
|
|
18
|
-
? Before<Keep, Index>
|
|
19
|
-
: never
|
|
20
|
-
export type After<
|
|
21
|
-
Tuple extends unknown[],
|
|
22
|
-
Index extends string | number,
|
|
23
|
-
Rest extends unknown[] = [],
|
|
24
|
-
> = `${Rest['length']}` extends `${Index}`
|
|
25
|
-
? Tuple
|
|
26
|
-
: Tuple extends [infer Drop, ...infer Keep]
|
|
27
|
-
? After<Keep, Index, [...Rest, Drop]>
|
|
28
|
-
: never
|
|
29
|
-
export type At<
|
|
30
|
-
Tuple extends unknown[],
|
|
31
|
-
Index extends string | number,
|
|
32
|
-
> = `${OneLess<Tuple>['length']}` extends `${Index}`
|
|
33
|
-
? Tuple
|
|
34
|
-
: Tuple extends [...infer Keep, infer Drop]
|
|
35
|
-
? At<Keep, Index>
|
|
36
|
-
: never
|
|
37
|
-
export type Reduce<T extends unknown[]> = T extends [...infer R, infer L]
|
|
38
|
-
? [L] extends [never]
|
|
39
|
-
? [...Reduce<R>]
|
|
40
|
-
: [...Reduce<R>, L]
|
|
41
|
-
: T
|
|
42
|
-
export type ToIndices<T extends unknown[]> = { [key in keyof T]: key }[number]
|
|
43
|
-
export type Last<T extends unknown[]> = T extends [...infer R, infer L]
|
|
44
|
-
? L
|
|
45
|
-
: never
|
|
46
|
-
|
|
47
|
-
// Union handling
|
|
48
|
-
|
|
49
|
-
// Collapse a union of similar object into the intersection of the various objects
|
|
50
|
-
export type UnionToIntersection<U> = [U] extends [never]
|
|
51
|
-
? never
|
|
52
|
-
: (U extends infer V ? (k: U) => void : never) extends (k: infer I) => void
|
|
53
|
-
? I
|
|
54
|
-
: never
|
|
55
|
-
|
|
56
|
-
// Object handling
|
|
57
|
-
type NonNeverKeys<Obj extends {}> = {
|
|
58
|
-
[key in keyof Obj]: Obj[key] extends never ? never : key
|
|
59
|
-
}[keyof Obj]
|
|
60
|
-
|
|
61
|
-
export type FilterNever<Obj extends {}> = {
|
|
62
|
-
[key in NonNeverKeys<Obj>]: Obj[key]
|
|
63
|
-
}
|
package/src/types/validation.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ModularStages } from './stage'
|
|
2
|
-
|
|
3
|
-
export type ValidateIndex<
|
|
4
|
-
Index extends number | undefined,
|
|
5
|
-
Candidates extends string | number,
|
|
6
|
-
> = `${Index}` extends Candidates ? true : false
|
|
7
|
-
|
|
8
|
-
export type RestrictValue<
|
|
9
|
-
Arguments extends {},
|
|
10
|
-
Stage extends keyof ModularStages,
|
|
11
|
-
> = ModularStages<Arguments>[Stage]['restrict'] extends never
|
|
12
|
-
? unknown
|
|
13
|
-
: ModularStages<Arguments>[Stage]['restrict']
|