@strictly/react-form 0.0.1 → 0.0.3
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/.out/core/mobx/field_adapter.d.ts +7 -6
- package/.out/core/mobx/field_adapter_builder.d.ts +12 -13
- package/.out/core/mobx/field_adapter_builder.js +8 -12
- package/.out/core/mobx/field_adapters_of_values.d.ts +4 -0
- package/.out/core/mobx/flattened_adapters_of_fields.d.ts +2 -2
- package/.out/core/mobx/flattened_list_types_of_type.d.ts +8 -0
- package/.out/core/mobx/form_fields_of_field_adapters.d.ts +8 -0
- package/.out/core/mobx/form_presenter.d.ts +21 -24
- package/.out/core/mobx/form_presenter.js +64 -69
- package/.out/core/mobx/merge_field_adapters_with_two_way_converter.d.ts +13 -0
- package/.out/core/mobx/merge_field_adapters_with_two_way_converter.js +11 -0
- package/.out/core/mobx/merge_field_adapters_with_validators.d.ts +11 -0
- package/.out/core/mobx/merge_field_adapters_with_validators.js +45 -0
- package/.out/core/mobx/specs/fixtures.d.ts +7 -0
- package/.out/core/mobx/specs/fixtures.js +20 -0
- package/.out/core/mobx/specs/flattened_adapters_of_fields.tests.js +5 -2
- package/.out/core/mobx/specs/{flattened_list_type_defs_of.tests.js → flattened_list_types_of_types.tests.js} +7 -7
- package/.out/core/mobx/specs/form_presenter.tests.js +162 -60
- package/.out/core/mobx/specs/merge_field_adapters_with_two_way_converter.js +89 -0
- package/.out/core/mobx/specs/merge_field_adapters_with_validators.tests.js +172 -0
- package/.out/core/mobx/types.d.ts +2 -2
- package/.out/field_converters/chain_field_converter.d.ts +3 -3
- package/.out/field_converters/chain_field_converter.js +17 -12
- package/.out/field_converters/identity_converter.d.ts +3 -3
- package/.out/field_converters/identity_converter.js +10 -6
- package/.out/field_converters/integer_to_string_converter.d.ts +5 -4
- package/.out/field_converters/integer_to_string_converter.js +13 -6
- package/.out/field_converters/list_converter.d.ts +2 -2
- package/.out/field_converters/list_converter.js +6 -1
- package/.out/field_converters/maybe_identity_converter.d.ts +3 -3
- package/.out/field_converters/maybe_identity_converter.js +3 -1
- package/.out/field_converters/nullable_to_boolean_converter.d.ts +9 -8
- package/.out/field_converters/nullable_to_boolean_converter.js +13 -7
- package/.out/field_converters/select_value_type_converter.d.ts +20 -15
- package/.out/field_converters/select_value_type_converter.js +29 -14
- package/.out/field_converters/specs/chain_field_converter.tests.d.ts +1 -0
- package/.out/field_converters/specs/chain_field_converter.tests.js +251 -0
- package/.out/field_converters/trimming_string_converter.d.ts +3 -3
- package/.out/field_converters/trimming_string_converter.js +7 -3
- package/.out/field_converters/validating_converter.d.ts +3 -3
- package/.out/field_converters/validating_converter.js +7 -5
- package/.out/index.d.ts +9 -2
- package/.out/index.js +9 -2
- package/.out/mantine/create_checkbox.d.ts +2 -3
- package/.out/mantine/create_checkbox.js +6 -5
- package/.out/mantine/create_pill.js +2 -2
- package/.out/mantine/create_radio.js +1 -1
- package/.out/mantine/create_radio_group.d.ts +2 -3
- package/.out/mantine/create_radio_group.js +4 -3
- package/.out/mantine/create_text_input.d.ts +2 -3
- package/.out/mantine/create_text_input.js +6 -5
- package/.out/mantine/create_value_input.d.ts +2 -3
- package/.out/mantine/create_value_input.js +6 -5
- package/.out/mantine/error_renderer.d.ts +6 -0
- package/.out/mantine/error_renderer.js +5 -0
- package/.out/mantine/hooks.d.ts +9 -13
- package/.out/mantine/hooks.js +10 -15
- package/.out/mantine/specs/checkbox_hooks.stories.d.ts +7 -2
- package/.out/mantine/specs/checkbox_hooks.stories.js +33 -6
- package/.out/mantine/specs/list_hooks.stories.js +2 -2
- package/.out/mantine/specs/radio_group_hooks.stories.d.ts +7 -2
- package/.out/mantine/specs/radio_group_hooks.stories.js +33 -6
- package/.out/mantine/specs/select_hooks.stories.d.ts +8 -2
- package/.out/mantine/specs/select_hooks.stories.js +45 -8
- package/.out/mantine/specs/text_input_hooks.stories.d.ts +5 -1
- package/.out/mantine/specs/text_input_hooks.stories.js +23 -8
- package/.out/mantine/specs/value_input_hooks.stories.d.ts +7 -2
- package/.out/mantine/specs/value_input_hooks.stories.js +49 -15
- package/.out/mantine/types.d.ts +4 -1
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/types/error_of_field.d.ts +2 -0
- package/.out/types/error_of_field.js +1 -0
- package/.out/types/field.d.ts +1 -1
- package/.out/types/field_converters.d.ts +17 -10
- package/.out/types/field_converters.js +5 -5
- package/.out/types/flattened_validators_of_fields.d.ts +8 -0
- package/.out/types/flattened_validators_of_fields.js +1 -0
- package/.out/types/merge_validators.d.ts +7 -0
- package/.out/types/merge_validators.js +38 -0
- package/.out/types/specs/flattened_validators_of_fields.tests.d.ts +1 -0
- package/.out/types/specs/flattened_validators_of_fields.tests.js +16 -0
- package/.out/types/specs/merge_validators.tests.d.ts +1 -0
- package/.out/types/specs/merge_validators.tests.js +192 -0
- package/.out/util/partial.d.ts +11 -5
- package/.out/util/partial.js +55 -15
- package/.turbo/turbo-build.log +9 -9
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/README.md +5 -1
- package/core/mobx/field_adapter.ts +15 -7
- package/core/mobx/field_adapter_builder.ts +39 -75
- package/core/mobx/field_adapters_of_values.ts +17 -0
- package/core/mobx/flattened_adapters_of_fields.ts +3 -3
- package/core/mobx/flattened_list_types_of_type.ts +17 -0
- package/core/mobx/form_fields_of_field_adapters.ts +16 -0
- package/core/mobx/form_presenter.ts +117 -104
- package/core/mobx/merge_field_adapters_with_two_way_converter.ts +68 -0
- package/core/mobx/merge_field_adapters_with_validators.ts +99 -0
- package/core/mobx/specs/fixtures.ts +73 -0
- package/core/mobx/specs/flattened_adapters_of_fields.tests.ts +23 -2
- package/core/mobx/specs/flattened_list_types_of_types.tests.ts +35 -0
- package/core/mobx/specs/form_presenter.tests.ts +248 -124
- package/core/mobx/specs/merge_field_adapters_with_two_way_converter.ts +140 -0
- package/core/mobx/specs/merge_field_adapters_with_validators.tests.ts +259 -0
- package/core/mobx/types.ts +3 -3
- package/dist/index.cjs +527 -10412
- package/dist/index.d.cts +153 -111
- package/dist/index.d.ts +153 -111
- package/dist/index.js +527 -10420
- package/field_converters/chain_field_converter.ts +37 -23
- package/field_converters/identity_converter.ts +14 -10
- package/field_converters/integer_to_string_converter.ts +15 -9
- package/field_converters/list_converter.ts +8 -3
- package/field_converters/maybe_identity_converter.ts +7 -4
- package/field_converters/nullable_to_boolean_converter.ts +23 -16
- package/field_converters/select_value_type_converter.ts +86 -26
- package/field_converters/specs/chain_field_converter.tests.ts +302 -0
- package/field_converters/trimming_string_converter.ts +11 -6
- package/field_converters/validating_converter.ts +21 -11
- package/index.ts +9 -2
- package/mantine/create_checkbox.tsx +15 -8
- package/mantine/create_list.tsx +1 -4
- package/mantine/create_pill.tsx +2 -2
- package/mantine/create_radio.tsx +1 -1
- package/mantine/create_radio_group.tsx +8 -6
- package/mantine/create_text_input.tsx +20 -8
- package/mantine/create_value_input.tsx +17 -8
- package/mantine/error_renderer.ts +15 -0
- package/mantine/hooks.tsx +25 -51
- package/mantine/specs/__snapshots__/checkbox_hooks.tests.tsx.snap +126 -0
- package/mantine/specs/__snapshots__/radio_group_hooks.tests.tsx.snap +356 -0
- package/mantine/specs/__snapshots__/select_hooks.tests.tsx.snap +208 -12
- package/mantine/specs/__snapshots__/text_input_hooks.tests.tsx.snap +45 -0
- package/mantine/specs/__snapshots__/value_input_hooks.tests.tsx.snap +194 -8
- package/mantine/specs/checkbox_hooks.stories.tsx +47 -7
- package/mantine/specs/list_hooks.stories.tsx +2 -2
- package/mantine/specs/radio_group_hooks.stories.tsx +47 -7
- package/mantine/specs/select_hooks.stories.tsx +55 -8
- package/mantine/specs/text_input_hooks.stories.tsx +32 -7
- package/mantine/specs/value_input_hooks.stories.tsx +57 -16
- package/mantine/types.ts +5 -1
- package/package.json +20 -7
- package/tsconfig.json +1 -0
- package/types/error_of_field.ts +3 -0
- package/types/field.ts +1 -1
- package/types/field_converters.ts +21 -10
- package/types/flattened_validators_of_fields.ts +34 -0
- package/types/merge_validators.ts +80 -0
- package/types/specs/error_type_of_field.tests.ts +2 -2
- package/types/specs/flattened_validators_of_fields.tests.ts +93 -0
- package/types/specs/merge_validators.tests.ts +267 -0
- package/util/partial.tsx +200 -16
- package/.out/core/mobx/flattened_list_type_defs_of.d.ts +0 -8
- package/.out/field_validators/minimum_string_length_field_validator.d.ts +0 -2
- package/.out/field_validators/minimum_string_length_field_validator.js +0 -8
- package/.out/types/error_type_of_field.d.ts +0 -2
- package/.out/types/field_validator.d.ts +0 -3
- package/.out/types/flattened_form_fields_of.d.ts +0 -9
- package/.out/types/specs/flattened_form_fields_of.tests.js +0 -13
- package/core/mobx/flattened_list_type_defs_of.ts +0 -17
- package/core/mobx/specs/flattened_list_type_defs_of.tests.ts +0 -35
- package/field_validators/minimum_string_length_field_validator.ts +0 -13
- package/mantine/specs/__snapshots__/check_box_hooks.tests.tsx.snap +0 -227
- package/types/error_type_of_field.ts +0 -3
- package/types/field_validator.ts +0 -7
- package/types/flattened_form_fields_of.ts +0 -16
- package/types/specs/flattened_form_fields_of.tests.ts +0 -43
- /package/.out/core/mobx/{flattened_list_type_defs_of.js → field_adapters_of_values.js} +0 -0
- /package/.out/core/mobx/{specs/flattened_list_type_defs_of.tests.d.ts → flattened_list_types_of_type.js} +0 -0
- /package/.out/{types/error_type_of_field.js → core/mobx/form_fields_of_field_adapters.js} +0 -0
- /package/.out/{types/field_validator.js → core/mobx/specs/flattened_list_types_of_types.tests.d.ts} +0 -0
- /package/.out/{types/flattened_form_fields_of.js → core/mobx/specs/merge_field_adapters_with_two_way_converter.d.ts} +0 -0
- /package/.out/{types/specs/flattened_form_fields_of.tests.d.ts → core/mobx/specs/merge_field_adapters_with_validators.tests.d.ts} +0 -0
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
chainAnnotatedFieldConverter,
|
|
3
|
+
chainUnreliableFieldConverter,
|
|
4
4
|
} from 'field_converters/chain_field_converter'
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
annotatedIdentityConverter,
|
|
7
|
+
unreliableIdentityConverter,
|
|
8
8
|
} from 'field_converters/identity_converter'
|
|
9
9
|
import { listConverter } from 'field_converters/list_converter'
|
|
10
10
|
import { MaybeIdentityConverter } from 'field_converters/maybe_identity_converter'
|
|
11
|
-
import {
|
|
12
|
-
validatingConverter,
|
|
13
|
-
} from 'field_converters/validating_converter'
|
|
14
11
|
import { prototypingFieldValueFactory } from 'field_value_factories/prototyping_field_value_factory'
|
|
15
12
|
import {
|
|
16
|
-
type
|
|
13
|
+
type AnnotatedFieldConverter,
|
|
17
14
|
type FieldValueFactory,
|
|
18
|
-
type SafeFieldConverter,
|
|
19
15
|
type TwoWayFieldConverter,
|
|
20
16
|
type TwoWayFieldConverterWithValueFactory,
|
|
17
|
+
type UnreliableFieldConverter,
|
|
21
18
|
} from 'types/field_converters'
|
|
22
|
-
import { type
|
|
19
|
+
import { type FieldAdapter } from './field_adapter'
|
|
23
20
|
|
|
24
21
|
class FieldAdapterBuilder<
|
|
25
22
|
From,
|
|
@@ -29,66 +26,18 @@ class FieldAdapterBuilder<
|
|
|
29
26
|
Context,
|
|
30
27
|
> {
|
|
31
28
|
constructor(
|
|
32
|
-
readonly convert:
|
|
29
|
+
readonly convert: AnnotatedFieldConverter<From, To, ValuePath, Context>,
|
|
33
30
|
readonly create: FieldValueFactory<From, ValuePath, Context>,
|
|
34
|
-
readonly revert?:
|
|
31
|
+
readonly revert?: UnreliableFieldConverter<To, From, E, ValuePath, Context>,
|
|
35
32
|
) {
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
validateFrom<
|
|
39
|
-
E2,
|
|
40
|
-
>(...validators: readonly FieldValidator<
|
|
41
|
-
From,
|
|
42
|
-
E2,
|
|
43
|
-
ValuePath,
|
|
44
|
-
Context
|
|
45
|
-
>[]): FieldAdapterBuilder<
|
|
46
|
-
From,
|
|
47
|
-
To,
|
|
48
|
-
E | E2,
|
|
49
|
-
ValuePath,
|
|
50
|
-
Context
|
|
51
|
-
> {
|
|
52
|
-
return new FieldAdapterBuilder(
|
|
53
|
-
this.convert,
|
|
54
|
-
this.create,
|
|
55
|
-
this.revert && chainFieldConverter(
|
|
56
|
-
this.revert,
|
|
57
|
-
validatingConverter(validators),
|
|
58
|
-
),
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
validateTo<
|
|
63
|
-
E2,
|
|
64
|
-
>(...validators: readonly FieldValidator<
|
|
65
|
-
To,
|
|
66
|
-
E2,
|
|
67
|
-
ValuePath,
|
|
68
|
-
Context
|
|
69
|
-
>[]): FieldAdapterBuilder<
|
|
70
|
-
From,
|
|
71
|
-
To,
|
|
72
|
-
E | E2,
|
|
73
|
-
ValuePath,
|
|
74
|
-
Context
|
|
75
|
-
> {
|
|
76
|
-
return new FieldAdapterBuilder(
|
|
77
|
-
this.convert,
|
|
78
|
-
this.create,
|
|
79
|
-
this.revert && chainFieldConverter(
|
|
80
|
-
validatingConverter(validators),
|
|
81
|
-
this.revert,
|
|
82
|
-
),
|
|
83
|
-
)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
35
|
chain<To2, E2 = E>(
|
|
87
|
-
converter:
|
|
88
|
-
reverter?:
|
|
36
|
+
converter: AnnotatedFieldConverter<To, To2, ValuePath, Context>,
|
|
37
|
+
reverter?: UnreliableFieldConverter<To2, To, E2, ValuePath, Context>,
|
|
89
38
|
): FieldAdapterBuilder<From, To2, E | E2, ValuePath, Context> {
|
|
90
39
|
return new FieldAdapterBuilder(
|
|
91
|
-
|
|
40
|
+
chainAnnotatedFieldConverter<
|
|
92
41
|
From,
|
|
93
42
|
To,
|
|
94
43
|
To2,
|
|
@@ -99,7 +48,7 @@ class FieldAdapterBuilder<
|
|
|
99
48
|
converter,
|
|
100
49
|
),
|
|
101
50
|
this.create,
|
|
102
|
-
this.revert && reverter &&
|
|
51
|
+
this.revert && reverter && chainUnreliableFieldConverter<
|
|
103
52
|
To2,
|
|
104
53
|
To,
|
|
105
54
|
From,
|
|
@@ -114,7 +63,7 @@ class FieldAdapterBuilder<
|
|
|
114
63
|
)
|
|
115
64
|
}
|
|
116
65
|
|
|
117
|
-
withReverter(reverter:
|
|
66
|
+
withReverter(reverter: UnreliableFieldConverter<
|
|
118
67
|
To,
|
|
119
68
|
From,
|
|
120
69
|
E,
|
|
@@ -152,6 +101,10 @@ class FieldAdapterBuilder<
|
|
|
152
101
|
this.revert && identityConverter.revert.bind(identityConverter),
|
|
153
102
|
)
|
|
154
103
|
}
|
|
104
|
+
|
|
105
|
+
get narrow(): FieldAdapter<From, To, E, ValuePath, Context> {
|
|
106
|
+
return this
|
|
107
|
+
}
|
|
155
108
|
}
|
|
156
109
|
|
|
157
110
|
export function adapter<
|
|
@@ -160,7 +113,7 @@ export function adapter<
|
|
|
160
113
|
ValuePath extends string,
|
|
161
114
|
Context,
|
|
162
115
|
>(
|
|
163
|
-
converter:
|
|
116
|
+
converter: AnnotatedFieldConverter<From, To, ValuePath, Context>,
|
|
164
117
|
valueFactory: FieldValueFactory<From, ValuePath, Context>,
|
|
165
118
|
): FieldAdapterBuilder<From, To, never, ValuePath, Context>
|
|
166
119
|
export function adapter<
|
|
@@ -170,9 +123,9 @@ export function adapter<
|
|
|
170
123
|
ValuePath extends string,
|
|
171
124
|
Context,
|
|
172
125
|
>(
|
|
173
|
-
converter:
|
|
126
|
+
converter: AnnotatedFieldConverter<From, To, ValuePath, Context>,
|
|
174
127
|
valueFactory: FieldValueFactory<From, ValuePath, Context>,
|
|
175
|
-
reverter:
|
|
128
|
+
reverter: UnreliableFieldConverter<To, From, E, ValuePath, Context>,
|
|
176
129
|
): FieldAdapterBuilder<From, To, E, ValuePath, Context>
|
|
177
130
|
export function adapter<
|
|
178
131
|
From,
|
|
@@ -181,9 +134,9 @@ export function adapter<
|
|
|
181
134
|
ValuePath extends string,
|
|
182
135
|
Context,
|
|
183
136
|
>(
|
|
184
|
-
converter:
|
|
137
|
+
converter: AnnotatedFieldConverter<From, To, ValuePath, Context>,
|
|
185
138
|
valueFactory: FieldValueFactory<From, ValuePath, Context>,
|
|
186
|
-
reverter?:
|
|
139
|
+
reverter?: UnreliableFieldConverter<To, From, E, ValuePath, Context>,
|
|
187
140
|
): FieldAdapterBuilder<From, To, E, ValuePath, Context> {
|
|
188
141
|
return new FieldAdapterBuilder(converter, valueFactory, reverter)
|
|
189
142
|
}
|
|
@@ -259,7 +212,7 @@ export function adapterFromPrototype<
|
|
|
259
212
|
ValuePath extends string,
|
|
260
213
|
Context,
|
|
261
214
|
>(
|
|
262
|
-
converter:
|
|
215
|
+
converter: AnnotatedFieldConverter<From, To, ValuePath, Context>,
|
|
263
216
|
prototype: From,
|
|
264
217
|
): FieldAdapterBuilder<From, To, never, ValuePath, Context>
|
|
265
218
|
export function adapterFromPrototype<
|
|
@@ -279,7 +232,18 @@ export function adapterFromPrototype<
|
|
|
279
232
|
ValuePath extends string,
|
|
280
233
|
Context,
|
|
281
234
|
>(
|
|
282
|
-
converter:
|
|
235
|
+
converter: AnnotatedFieldConverter<
|
|
236
|
+
From,
|
|
237
|
+
To,
|
|
238
|
+
ValuePath,
|
|
239
|
+
Context
|
|
240
|
+
> | TwoWayFieldConverter<
|
|
241
|
+
From,
|
|
242
|
+
To,
|
|
243
|
+
E,
|
|
244
|
+
ValuePath,
|
|
245
|
+
Context
|
|
246
|
+
>,
|
|
283
247
|
prototype: From,
|
|
284
248
|
): FieldAdapterBuilder<From, To, E, ValuePath, Context> {
|
|
285
249
|
const factory = prototypingFieldValueFactory<From, ValuePath, Context>(prototype)
|
|
@@ -292,11 +256,11 @@ export function identityAdapter<
|
|
|
292
256
|
V,
|
|
293
257
|
ValuePath extends string,
|
|
294
258
|
Context,
|
|
295
|
-
>(prototype: V) {
|
|
259
|
+
>(prototype: V, required?: boolean) {
|
|
296
260
|
return new FieldAdapterBuilder(
|
|
297
|
-
|
|
261
|
+
annotatedIdentityConverter<V, ValuePath, Context>(required),
|
|
298
262
|
prototypingFieldValueFactory(prototype),
|
|
299
|
-
|
|
263
|
+
unreliableIdentityConverter<V, ValuePath, Context>(),
|
|
300
264
|
)
|
|
301
265
|
}
|
|
302
266
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type FieldAdapter } from './field_adapter'
|
|
2
|
+
|
|
3
|
+
export type FieldAdaptersOfValues<
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
FlattenedValues extends Readonly<Record<string, any>>,
|
|
6
|
+
TypePathsToValuePaths extends Readonly<Record<keyof FlattenedValues, string>> = Readonly<
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
Record<keyof FlattenedValues, any>
|
|
9
|
+
>,
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
Context = any,
|
|
12
|
+
> = {
|
|
13
|
+
readonly [
|
|
14
|
+
K in keyof FlattenedValues
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
]: FieldAdapter<FlattenedValues[K], any, any, TypePathsToValuePaths[K], Context>
|
|
17
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
2
|
+
type ReadonlyTypeOfType,
|
|
3
3
|
type Type,
|
|
4
|
-
type
|
|
4
|
+
type ValueOfType,
|
|
5
5
|
} from '@strictly/define'
|
|
6
6
|
import { type FieldAdapter } from 'core/mobx/field_adapter'
|
|
7
7
|
import {
|
|
@@ -30,6 +30,6 @@ type AdapterOfField<
|
|
|
30
30
|
ValuePath extends string | number | symbol,
|
|
31
31
|
> = ValuePath extends string
|
|
32
32
|
? F extends Field<infer V, infer E> ? undefined extends T ? FieldAdapter<V, V, E, ValuePath>
|
|
33
|
-
: FieldAdapter<
|
|
33
|
+
: FieldAdapter<ValueOfType<ReadonlyTypeOfType<NonNullable<T>>>, V, E, ValuePath>
|
|
34
34
|
: never
|
|
35
35
|
: never
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type FlattenedTypesOfType,
|
|
3
|
+
type ListTypeDef,
|
|
4
|
+
type Type,
|
|
5
|
+
} from '@strictly/define'
|
|
6
|
+
import { type SimplifyDeep } from 'type-fest'
|
|
7
|
+
|
|
8
|
+
export type ListValuePathsOfType<T extends Type> = keyof FlattenedListTypesOfType<T>
|
|
9
|
+
|
|
10
|
+
export type FlattenedListTypesOfType<T extends Type> = FlattenedListTypesOfTypes<
|
|
11
|
+
// SimplifyDeep is necessary here otherwise FlattenedListTypeDefsOfFlattened will complain about infinite depth
|
|
12
|
+
SimplifyDeep<FlattenedTypesOfType<T, null>>
|
|
13
|
+
>
|
|
14
|
+
|
|
15
|
+
type FlattenedListTypesOfTypes<T extends Readonly<Record<string, Type>>> = {
|
|
16
|
+
[K in keyof T as T[K]['definition'] extends ListTypeDef ? K : never]: T[K]
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ValueOf } from 'type-fest'
|
|
2
|
+
import { type Field } from 'types/field'
|
|
3
|
+
import { type FieldAdapter } from './field_adapter'
|
|
4
|
+
|
|
5
|
+
export type FormFieldsOfFieldAdapters<
|
|
6
|
+
ValuePathsToTypePaths extends Readonly<Record<string, string>>,
|
|
7
|
+
FieldAdapters extends Partial<Readonly<Record<ValueOf<ValuePathsToTypePaths>, FieldAdapter>>>,
|
|
8
|
+
> = {
|
|
9
|
+
[
|
|
10
|
+
K in keyof ValuePathsToTypePaths as undefined extends FieldAdapters[ValuePathsToTypePaths[K]] ? never : K
|
|
11
|
+
]: FormFieldOfFieldAdapter<FieldAdapters[ValuePathsToTypePaths[K]]>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type FormFieldOfFieldAdapter<
|
|
15
|
+
F extends FieldAdapter | undefined,
|
|
16
|
+
> = F extends FieldAdapter<infer _From, infer To, infer E> ? Field<To, E> : never
|