@strictly/react-form 0.0.1
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/.eslintrc.cjs +26 -0
- package/.out/.storybook/main.d.ts +3 -0
- package/.out/.storybook/main.js +32 -0
- package/.out/.storybook/preview.d.ts +4 -0
- package/.out/.storybook/preview.js +20 -0
- package/.out/.vitest/install_deterministic_random.d.ts +2 -0
- package/.out/.vitest/install_deterministic_random.js +15 -0
- package/.out/.vitest/install_storybook_preview.d.ts +1 -0
- package/.out/.vitest/install_storybook_preview.js +7 -0
- package/.out/.vitest/match_media.d.ts +1 -0
- package/.out/.vitest/match_media.js +5 -0
- package/.out/.vitest/resize_observer.d.ts +1 -0
- package/.out/.vitest/resize_observer.js +4 -0
- package/.out/core/mobx/field_adapter.d.ts +9 -0
- package/.out/core/mobx/field_adapter.js +1 -0
- package/.out/core/mobx/field_adapter_builder.d.ts +22 -0
- package/.out/core/mobx/field_adapter_builder.js +56 -0
- package/.out/core/mobx/flattened_adapters_of_fields.d.ts +9 -0
- package/.out/core/mobx/flattened_adapters_of_fields.js +1 -0
- package/.out/core/mobx/flattened_list_type_defs_of.d.ts +8 -0
- package/.out/core/mobx/flattened_list_type_defs_of.js +1 -0
- package/.out/core/mobx/form_presenter.d.ts +61 -0
- package/.out/core/mobx/form_presenter.js +425 -0
- package/.out/core/mobx/specs/flattened_adapters_of_fields.tests.d.ts +1 -0
- package/.out/core/mobx/specs/flattened_adapters_of_fields.tests.js +13 -0
- package/.out/core/mobx/specs/flattened_list_type_defs_of.tests.d.ts +1 -0
- package/.out/core/mobx/specs/flattened_list_type_defs_of.tests.js +16 -0
- package/.out/core/mobx/specs/form_presenter.tests.d.ts +1 -0
- package/.out/core/mobx/specs/form_presenter.tests.js +697 -0
- package/.out/core/mobx/types.d.ts +19 -0
- package/.out/core/mobx/types.js +1 -0
- package/.out/core/props.d.ts +12 -0
- package/.out/core/props.js +1 -0
- package/.out/field_converters/chain_field_converter.d.ts +3 -0
- package/.out/field_converters/chain_field_converter.js +46 -0
- package/.out/field_converters/identity_converter.d.ts +3 -0
- package/.out/field_converters/identity_converter.js +14 -0
- package/.out/field_converters/integer_to_string_converter.d.ts +7 -0
- package/.out/field_converters/integer_to_string_converter.js +26 -0
- package/.out/field_converters/list_converter.d.ts +2 -0
- package/.out/field_converters/list_converter.js +8 -0
- package/.out/field_converters/maybe_identity_converter.d.ts +8 -0
- package/.out/field_converters/maybe_identity_converter.js +15 -0
- package/.out/field_converters/nullable_to_boolean_converter.d.ts +11 -0
- package/.out/field_converters/nullable_to_boolean_converter.js +31 -0
- package/.out/field_converters/select_value_type_converter.d.ts +23 -0
- package/.out/field_converters/select_value_type_converter.js +60 -0
- package/.out/field_converters/trimming_string_converter.d.ts +6 -0
- package/.out/field_converters/trimming_string_converter.js +14 -0
- package/.out/field_converters/validating_converter.d.ts +3 -0
- package/.out/field_converters/validating_converter.js +21 -0
- package/.out/field_validators/minimum_string_length_field_validator.d.ts +2 -0
- package/.out/field_validators/minimum_string_length_field_validator.js +8 -0
- package/.out/field_value_factories/prototyping_field_value_factory.d.ts +2 -0
- package/.out/field_value_factories/prototyping_field_value_factory.js +5 -0
- package/.out/index.d.ts +16 -0
- package/.out/index.js +16 -0
- package/.out/mantine/create_checkbox.d.ts +9 -0
- package/.out/mantine/create_checkbox.js +37 -0
- package/.out/mantine/create_list.d.ts +15 -0
- package/.out/mantine/create_list.js +16 -0
- package/.out/mantine/create_pill.d.ts +7 -0
- package/.out/mantine/create_pill.js +15 -0
- package/.out/mantine/create_radio.d.ts +8 -0
- package/.out/mantine/create_radio.js +10 -0
- package/.out/mantine/create_radio_group.d.ts +9 -0
- package/.out/mantine/create_radio_group.js +34 -0
- package/.out/mantine/create_text_input.d.ts +19 -0
- package/.out/mantine/create_text_input.js +38 -0
- package/.out/mantine/create_value_input.d.ts +17 -0
- package/.out/mantine/create_value_input.js +38 -0
- package/.out/mantine/hooks.d.ts +56 -0
- package/.out/mantine/hooks.js +135 -0
- package/.out/mantine/specs/checkbox_constants.d.ts +1 -0
- package/.out/mantine/specs/checkbox_constants.js +1 -0
- package/.out/mantine/specs/checkbox_hooks.stories.d.ts +13 -0
- package/.out/mantine/specs/checkbox_hooks.stories.js +63 -0
- package/.out/mantine/specs/checkbox_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/checkbox_hooks.tests.js +74 -0
- package/.out/mantine/specs/list_hooks.stories.d.ts +11 -0
- package/.out/mantine/specs/list_hooks.stories.js +48 -0
- package/.out/mantine/specs/list_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/list_hooks.tests.js +12 -0
- package/.out/mantine/specs/radio_group_constants.d.ts +4 -0
- package/.out/mantine/specs/radio_group_constants.js +11 -0
- package/.out/mantine/specs/radio_group_hooks.stories.d.ts +14 -0
- package/.out/mantine/specs/radio_group_hooks.stories.js +68 -0
- package/.out/mantine/specs/radio_group_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/radio_group_hooks.tests.js +62 -0
- package/.out/mantine/specs/select_hooks.stories.d.ts +12 -0
- package/.out/mantine/specs/select_hooks.stories.js +57 -0
- package/.out/mantine/specs/select_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/select_hooks.tests.js +12 -0
- package/.out/mantine/specs/select_hooks_constant.d.ts +1 -0
- package/.out/mantine/specs/select_hooks_constant.js +1 -0
- package/.out/mantine/specs/text_input_constants.d.ts +1 -0
- package/.out/mantine/specs/text_input_constants.js +1 -0
- package/.out/mantine/specs/text_input_hooks.stories.d.ts +21 -0
- package/.out/mantine/specs/text_input_hooks.stories.js +88 -0
- package/.out/mantine/specs/text_input_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/text_input_hooks.tests.js +79 -0
- package/.out/mantine/specs/value_input_constants.d.ts +2 -0
- package/.out/mantine/specs/value_input_constants.js +2 -0
- package/.out/mantine/specs/value_input_hooks.stories.d.ts +23 -0
- package/.out/mantine/specs/value_input_hooks.stories.js +124 -0
- package/.out/mantine/specs/value_input_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/value_input_hooks.tests.js +12 -0
- package/.out/mantine/types.d.ts +11 -0
- package/.out/mantine/types.js +1 -0
- package/.out/tsconfig.json +27 -0
- package/.out/tsconfig.tsbuildinfo +1 -0
- package/.out/tsup.config.d.ts +3 -0
- package/.out/tsup.config.js +12 -0
- package/.out/types/all_fields_of_fields.d.ts +5 -0
- package/.out/types/all_fields_of_fields.js +1 -0
- package/.out/types/boolean_fields_of_fields.d.ts +5 -0
- package/.out/types/boolean_fields_of_fields.js +1 -0
- package/.out/types/error_type_of_field.d.ts +2 -0
- package/.out/types/error_type_of_field.js +1 -0
- package/.out/types/field.d.ts +7 -0
- package/.out/types/field.js +1 -0
- package/.out/types/field_converters.d.ts +29 -0
- package/.out/types/field_converters.js +5 -0
- package/.out/types/field_validator.d.ts +3 -0
- package/.out/types/field_validator.js +1 -0
- package/.out/types/flattened_form_fields_of.d.ts +9 -0
- package/.out/types/flattened_form_fields_of.js +1 -0
- package/.out/types/list_fields_of_fields.d.ts +5 -0
- package/.out/types/list_fields_of_fields.js +1 -0
- package/.out/types/specs/boolean_fields_of_fields.tests.d.ts +1 -0
- package/.out/types/specs/boolean_fields_of_fields.tests.js +11 -0
- package/.out/types/specs/error_type_of_field.tests.d.ts +1 -0
- package/.out/types/specs/error_type_of_field.tests.js +7 -0
- package/.out/types/specs/flattened_form_fields_of.tests.d.ts +1 -0
- package/.out/types/specs/flattened_form_fields_of.tests.js +13 -0
- package/.out/types/specs/string_fields_of_fields.tests.d.ts +1 -0
- package/.out/types/specs/string_fields_of_fields.tests.js +19 -0
- package/.out/types/specs/value_type_of_field.tests.d.ts +1 -0
- package/.out/types/specs/value_type_of_field.tests.js +7 -0
- package/.out/types/string_fields_of_fields.d.ts +5 -0
- package/.out/types/string_fields_of_fields.js +1 -0
- package/.out/types/value_type_of_field.d.ts +2 -0
- package/.out/types/value_type_of_field.js +1 -0
- package/.out/util/partial.d.ts +11 -0
- package/.out/util/partial.js +74 -0
- package/.out/vitest.workspace.d.ts +2 -0
- package/.out/vitest.workspace.js +22 -0
- package/.storybook/main.ts +40 -0
- package/.storybook/preview.tsx +28 -0
- package/.storybook/vite.config.mts +38 -0
- package/.turbo/turbo-build.log +18 -0
- package/.turbo/turbo-check-types.log +3 -0
- package/.turbo/turbo-release$colon$exports.log +3 -0
- package/.vitest/install_deterministic_random.ts +17 -0
- package/.vitest/install_storybook_preview.ts +9 -0
- package/.vitest/match_media.ts +7 -0
- package/.vitest/resize_observer.ts +5 -0
- package/README.md +2 -0
- package/core/mobx/field_adapter.ts +32 -0
- package/core/mobx/field_adapter_builder.ts +313 -0
- package/core/mobx/flattened_adapters_of_fields.ts +35 -0
- package/core/mobx/flattened_list_type_defs_of.ts +17 -0
- package/core/mobx/form_presenter.ts +705 -0
- package/core/mobx/specs/flattened_adapters_of_fields.tests.ts +72 -0
- package/core/mobx/specs/flattened_list_type_defs_of.tests.ts +35 -0
- package/core/mobx/specs/form_presenter.tests.ts +989 -0
- package/core/mobx/types.ts +54 -0
- package/core/props.ts +21 -0
- package/dist/index.cjs +11479 -0
- package/dist/index.d.cts +345 -0
- package/dist/index.d.ts +345 -0
- package/dist/index.js +11486 -0
- package/field_converters/chain_field_converter.ts +74 -0
- package/field_converters/identity_converter.ts +39 -0
- package/field_converters/integer_to_string_converter.ts +32 -0
- package/field_converters/list_converter.ts +15 -0
- package/field_converters/maybe_identity_converter.ts +23 -0
- package/field_converters/nullable_to_boolean_converter.ts +56 -0
- package/field_converters/select_value_type_converter.ts +141 -0
- package/field_converters/trimming_string_converter.ts +23 -0
- package/field_converters/validating_converter.ts +35 -0
- package/field_validators/minimum_string_length_field_validator.ts +13 -0
- package/field_value_factories/prototyping_field_value_factory.ts +11 -0
- package/index.ts +16 -0
- package/mantine/create_checkbox.tsx +79 -0
- package/mantine/create_list.tsx +58 -0
- package/mantine/create_pill.tsx +43 -0
- package/mantine/create_radio.tsx +36 -0
- package/mantine/create_radio_group.tsx +71 -0
- package/mantine/create_text_input.tsx +80 -0
- package/mantine/create_value_input.tsx +81 -0
- package/mantine/hooks.tsx +394 -0
- package/mantine/specs/__snapshots__/check_box_hooks.tests.tsx.snap +227 -0
- package/mantine/specs/__snapshots__/checkbox_hooks.tests.tsx.snap +227 -0
- package/mantine/specs/__snapshots__/list_hooks.tests.tsx.snap +68 -0
- package/mantine/specs/__snapshots__/radio_group_hooks.tests.tsx.snap +695 -0
- package/mantine/specs/__snapshots__/select_hooks.tests.tsx.snap +225 -0
- package/mantine/specs/__snapshots__/text_input_hooks.tests.tsx.snap +202 -0
- package/mantine/specs/__snapshots__/value_input_hooks.tests.tsx.snap +613 -0
- package/mantine/specs/checkbox_constants.ts +1 -0
- package/mantine/specs/checkbox_hooks.stories.tsx +79 -0
- package/mantine/specs/checkbox_hooks.tests.tsx +100 -0
- package/mantine/specs/list_hooks.stories.tsx +83 -0
- package/mantine/specs/list_hooks.tests.tsx +15 -0
- package/mantine/specs/radio_group_constants.ts +12 -0
- package/mantine/specs/radio_group_hooks.stories.tsx +103 -0
- package/mantine/specs/radio_group_hooks.tests.tsx +92 -0
- package/mantine/specs/select_hooks.stories.tsx +77 -0
- package/mantine/specs/select_hooks.tests.tsx +14 -0
- package/mantine/specs/select_hooks_constant.ts +1 -0
- package/mantine/specs/text_input_constants.ts +1 -0
- package/mantine/specs/text_input_hooks.stories.tsx +124 -0
- package/mantine/specs/text_input_hooks.tests.tsx +106 -0
- package/mantine/specs/value_input_constants.ts +2 -0
- package/mantine/specs/value_input_hooks.stories.tsx +182 -0
- package/mantine/specs/value_input_hooks.tests.tsx +14 -0
- package/mantine/types.ts +13 -0
- package/package.exports.json +18 -0
- package/package.json +74 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.json +27 -0
- package/tsup.config.ts +16 -0
- package/types/all_fields_of_fields.ts +9 -0
- package/types/boolean_fields_of_fields.ts +8 -0
- package/types/error_type_of_field.ts +3 -0
- package/types/field.ts +9 -0
- package/types/field_converters.ts +64 -0
- package/types/field_validator.ts +7 -0
- package/types/flattened_form_fields_of.ts +16 -0
- package/types/list_fields_of_fields.ts +7 -0
- package/types/specs/boolean_fields_of_fields.tests.ts +23 -0
- package/types/specs/error_type_of_field.tests.ts +10 -0
- package/types/specs/flattened_form_fields_of.tests.ts +43 -0
- package/types/specs/string_fields_of_fields.tests.ts +40 -0
- package/types/specs/value_type_of_field.tests.ts +10 -0
- package/types/string_fields_of_fields.ts +6 -0
- package/types/value_type_of_field.ts +3 -0
- package/util/partial.tsx +200 -0
- package/vitest.workspace.ts +26 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import {
|
|
2
|
+
chainFieldConverter,
|
|
3
|
+
chainSafeFieldConverter,
|
|
4
|
+
} from 'field_converters/chain_field_converter'
|
|
5
|
+
import {
|
|
6
|
+
identityConverter,
|
|
7
|
+
safeIdentityConverter,
|
|
8
|
+
} from 'field_converters/identity_converter'
|
|
9
|
+
import { listConverter } from 'field_converters/list_converter'
|
|
10
|
+
import { MaybeIdentityConverter } from 'field_converters/maybe_identity_converter'
|
|
11
|
+
import {
|
|
12
|
+
validatingConverter,
|
|
13
|
+
} from 'field_converters/validating_converter'
|
|
14
|
+
import { prototypingFieldValueFactory } from 'field_value_factories/prototyping_field_value_factory'
|
|
15
|
+
import {
|
|
16
|
+
type FieldConverter,
|
|
17
|
+
type FieldValueFactory,
|
|
18
|
+
type SafeFieldConverter,
|
|
19
|
+
type TwoWayFieldConverter,
|
|
20
|
+
type TwoWayFieldConverterWithValueFactory,
|
|
21
|
+
} from 'types/field_converters'
|
|
22
|
+
import { type FieldValidator } from 'types/field_validator'
|
|
23
|
+
|
|
24
|
+
class FieldAdapterBuilder<
|
|
25
|
+
From,
|
|
26
|
+
To,
|
|
27
|
+
E,
|
|
28
|
+
ValuePath extends string,
|
|
29
|
+
Context,
|
|
30
|
+
> {
|
|
31
|
+
constructor(
|
|
32
|
+
readonly convert: SafeFieldConverter<From, To, ValuePath, Context>,
|
|
33
|
+
readonly create: FieldValueFactory<From, ValuePath, Context>,
|
|
34
|
+
readonly revert?: FieldConverter<To, From, E, ValuePath, Context>,
|
|
35
|
+
) {
|
|
36
|
+
}
|
|
37
|
+
|
|
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
|
+
chain<To2, E2 = E>(
|
|
87
|
+
converter: SafeFieldConverter<To, To2, ValuePath, Context>,
|
|
88
|
+
reverter?: FieldConverter<To2, To, E2, ValuePath, Context>,
|
|
89
|
+
): FieldAdapterBuilder<From, To2, E | E2, ValuePath, Context> {
|
|
90
|
+
return new FieldAdapterBuilder(
|
|
91
|
+
chainSafeFieldConverter<
|
|
92
|
+
From,
|
|
93
|
+
To,
|
|
94
|
+
To2,
|
|
95
|
+
ValuePath,
|
|
96
|
+
Context
|
|
97
|
+
>(
|
|
98
|
+
this.convert,
|
|
99
|
+
converter,
|
|
100
|
+
),
|
|
101
|
+
this.create,
|
|
102
|
+
this.revert && reverter && chainFieldConverter<
|
|
103
|
+
To2,
|
|
104
|
+
To,
|
|
105
|
+
From,
|
|
106
|
+
E2,
|
|
107
|
+
E,
|
|
108
|
+
ValuePath,
|
|
109
|
+
Context
|
|
110
|
+
>(
|
|
111
|
+
reverter,
|
|
112
|
+
this.revert,
|
|
113
|
+
),
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
withReverter(reverter: FieldConverter<
|
|
118
|
+
To,
|
|
119
|
+
From,
|
|
120
|
+
E,
|
|
121
|
+
ValuePath,
|
|
122
|
+
Context
|
|
123
|
+
>): FieldAdapterBuilder<
|
|
124
|
+
From,
|
|
125
|
+
To,
|
|
126
|
+
E,
|
|
127
|
+
ValuePath,
|
|
128
|
+
Context
|
|
129
|
+
> {
|
|
130
|
+
return new FieldAdapterBuilder(
|
|
131
|
+
this.convert,
|
|
132
|
+
this.create,
|
|
133
|
+
reverter,
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
withIdentity(isFrom: (from: To | From) => from is From): FieldAdapterBuilder<
|
|
138
|
+
From,
|
|
139
|
+
To | From,
|
|
140
|
+
E,
|
|
141
|
+
ValuePath,
|
|
142
|
+
Context
|
|
143
|
+
> {
|
|
144
|
+
const identityConverter = new MaybeIdentityConverter<From, To, E, ValuePath, Context>({
|
|
145
|
+
convert: this.convert,
|
|
146
|
+
// should never get called if null
|
|
147
|
+
revert: this.revert!,
|
|
148
|
+
}, isFrom)
|
|
149
|
+
return new FieldAdapterBuilder(
|
|
150
|
+
identityConverter.convert.bind(identityConverter),
|
|
151
|
+
this.create,
|
|
152
|
+
this.revert && identityConverter.revert.bind(identityConverter),
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function adapter<
|
|
158
|
+
From,
|
|
159
|
+
To,
|
|
160
|
+
ValuePath extends string,
|
|
161
|
+
Context,
|
|
162
|
+
>(
|
|
163
|
+
converter: SafeFieldConverter<From, To, ValuePath, Context>,
|
|
164
|
+
valueFactory: FieldValueFactory<From, ValuePath, Context>,
|
|
165
|
+
): FieldAdapterBuilder<From, To, never, ValuePath, Context>
|
|
166
|
+
export function adapter<
|
|
167
|
+
From,
|
|
168
|
+
To,
|
|
169
|
+
E,
|
|
170
|
+
ValuePath extends string,
|
|
171
|
+
Context,
|
|
172
|
+
>(
|
|
173
|
+
converter: SafeFieldConverter<From, To, ValuePath, Context>,
|
|
174
|
+
valueFactory: FieldValueFactory<From, ValuePath, Context>,
|
|
175
|
+
reverter: FieldConverter<To, From, E, ValuePath, Context>,
|
|
176
|
+
): FieldAdapterBuilder<From, To, E, ValuePath, Context>
|
|
177
|
+
export function adapter<
|
|
178
|
+
From,
|
|
179
|
+
To,
|
|
180
|
+
E,
|
|
181
|
+
ValuePath extends string,
|
|
182
|
+
Context,
|
|
183
|
+
>(
|
|
184
|
+
converter: SafeFieldConverter<From, To, ValuePath, Context>,
|
|
185
|
+
valueFactory: FieldValueFactory<From, ValuePath, Context>,
|
|
186
|
+
reverter?: FieldConverter<To, From, E, ValuePath, Context>,
|
|
187
|
+
): FieldAdapterBuilder<From, To, E, ValuePath, Context> {
|
|
188
|
+
return new FieldAdapterBuilder(converter, valueFactory, reverter)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function adapterFromTwoWayConverter<
|
|
192
|
+
From,
|
|
193
|
+
To,
|
|
194
|
+
E,
|
|
195
|
+
ValuePath extends string,
|
|
196
|
+
Context,
|
|
197
|
+
>(
|
|
198
|
+
converter: TwoWayFieldConverter<From, To, E, ValuePath, Context>,
|
|
199
|
+
valueFactory: FieldValueFactory<From, ValuePath, Context>,
|
|
200
|
+
): FieldAdapterBuilder<From, To, E, ValuePath, Context>
|
|
201
|
+
export function adapterFromTwoWayConverter<
|
|
202
|
+
From,
|
|
203
|
+
To,
|
|
204
|
+
E,
|
|
205
|
+
ValuePath extends string,
|
|
206
|
+
Context,
|
|
207
|
+
>(converter: TwoWayFieldConverterWithValueFactory<
|
|
208
|
+
From,
|
|
209
|
+
To,
|
|
210
|
+
E,
|
|
211
|
+
ValuePath,
|
|
212
|
+
Context
|
|
213
|
+
>): FieldAdapterBuilder<
|
|
214
|
+
From,
|
|
215
|
+
To,
|
|
216
|
+
E,
|
|
217
|
+
ValuePath,
|
|
218
|
+
Context
|
|
219
|
+
>
|
|
220
|
+
export function adapterFromTwoWayConverter<
|
|
221
|
+
From,
|
|
222
|
+
To,
|
|
223
|
+
E,
|
|
224
|
+
ValuePath extends string,
|
|
225
|
+
Context,
|
|
226
|
+
>(
|
|
227
|
+
converter: TwoWayFieldConverter<
|
|
228
|
+
From,
|
|
229
|
+
To,
|
|
230
|
+
E,
|
|
231
|
+
ValuePath,
|
|
232
|
+
Context
|
|
233
|
+
> | TwoWayFieldConverterWithValueFactory<
|
|
234
|
+
From,
|
|
235
|
+
To,
|
|
236
|
+
E,
|
|
237
|
+
ValuePath,
|
|
238
|
+
Context
|
|
239
|
+
>,
|
|
240
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
241
|
+
valueFactory: FieldValueFactory<From, ValuePath, Context> = (converter as TwoWayFieldConverterWithValueFactory<
|
|
242
|
+
From,
|
|
243
|
+
To,
|
|
244
|
+
E,
|
|
245
|
+
ValuePath,
|
|
246
|
+
Context
|
|
247
|
+
>).create.bind(converter),
|
|
248
|
+
): FieldAdapterBuilder<From, To, E, ValuePath, Context> {
|
|
249
|
+
return new FieldAdapterBuilder(
|
|
250
|
+
converter.convert.bind(converter),
|
|
251
|
+
valueFactory,
|
|
252
|
+
converter.revert.bind(converter),
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export function adapterFromPrototype<
|
|
257
|
+
From,
|
|
258
|
+
To,
|
|
259
|
+
ValuePath extends string,
|
|
260
|
+
Context,
|
|
261
|
+
>(
|
|
262
|
+
converter: SafeFieldConverter<From, To, ValuePath, Context>,
|
|
263
|
+
prototype: From,
|
|
264
|
+
): FieldAdapterBuilder<From, To, never, ValuePath, Context>
|
|
265
|
+
export function adapterFromPrototype<
|
|
266
|
+
From,
|
|
267
|
+
To,
|
|
268
|
+
E,
|
|
269
|
+
ValuePath extends string,
|
|
270
|
+
Context,
|
|
271
|
+
>(
|
|
272
|
+
converter: TwoWayFieldConverter<From, To, E, ValuePath, Context>,
|
|
273
|
+
prototype: From,
|
|
274
|
+
): FieldAdapterBuilder<From, To, E, ValuePath, Context>
|
|
275
|
+
export function adapterFromPrototype<
|
|
276
|
+
From,
|
|
277
|
+
To,
|
|
278
|
+
E,
|
|
279
|
+
ValuePath extends string,
|
|
280
|
+
Context,
|
|
281
|
+
>(
|
|
282
|
+
converter: SafeFieldConverter<From, To, ValuePath, Context> | TwoWayFieldConverter<From, To, E, ValuePath, Context>,
|
|
283
|
+
prototype: From,
|
|
284
|
+
): FieldAdapterBuilder<From, To, E, ValuePath, Context> {
|
|
285
|
+
const factory = prototypingFieldValueFactory<From, ValuePath, Context>(prototype)
|
|
286
|
+
return typeof converter === 'function'
|
|
287
|
+
? new FieldAdapterBuilder(converter, factory)
|
|
288
|
+
: new FieldAdapterBuilder(converter.convert.bind(converter), factory, converter.revert.bind(converter))
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export function identityAdapter<
|
|
292
|
+
V,
|
|
293
|
+
ValuePath extends string,
|
|
294
|
+
Context,
|
|
295
|
+
>(prototype: V) {
|
|
296
|
+
return new FieldAdapterBuilder(
|
|
297
|
+
safeIdentityConverter<V, ValuePath, Context>(),
|
|
298
|
+
prototypingFieldValueFactory(prototype),
|
|
299
|
+
identityConverter<V, ValuePath, Context>(),
|
|
300
|
+
)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export function listAdapter<
|
|
304
|
+
E,
|
|
305
|
+
K extends string,
|
|
306
|
+
ValuePath extends string,
|
|
307
|
+
Context,
|
|
308
|
+
>() {
|
|
309
|
+
return new FieldAdapterBuilder<readonly E[], readonly K[], never, ValuePath, Context>(
|
|
310
|
+
listConverter<E, K, ValuePath, Context>(),
|
|
311
|
+
prototypingFieldValueFactory<readonly E[], ValuePath, Context>([]),
|
|
312
|
+
)
|
|
313
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ReadonlyTypeDefOf,
|
|
3
|
+
type Type,
|
|
4
|
+
type ValueTypeOf,
|
|
5
|
+
} from '@strictly/define'
|
|
6
|
+
import { type FieldAdapter } from 'core/mobx/field_adapter'
|
|
7
|
+
import {
|
|
8
|
+
type SimplifyDeep,
|
|
9
|
+
type ValueOf,
|
|
10
|
+
} from 'type-fest'
|
|
11
|
+
import { type Field } from 'types/field'
|
|
12
|
+
|
|
13
|
+
export type FlattenedAdaptersOfFields<
|
|
14
|
+
ValuePathsToTypePaths extends Readonly<Record<string, string>>,
|
|
15
|
+
FlattenedTypeDefs extends Partial<Readonly<Record<ValueOf<ValuePathsToTypePaths>, Type>>>,
|
|
16
|
+
FormFields extends Partial<Readonly<Record<keyof ValuePathsToTypePaths, Field>>>,
|
|
17
|
+
> = SimplifyDeep<{
|
|
18
|
+
readonly [
|
|
19
|
+
K in keyof ValuePathsToTypePaths as FormFields[K] extends Field ? ValuePathsToTypePaths[K] : never
|
|
20
|
+
]: AdapterOfField<
|
|
21
|
+
NonNullable<FormFields[K]>,
|
|
22
|
+
FlattenedTypeDefs[ValuePathsToTypePaths[K]],
|
|
23
|
+
K
|
|
24
|
+
>
|
|
25
|
+
}>
|
|
26
|
+
|
|
27
|
+
type AdapterOfField<
|
|
28
|
+
F extends Field,
|
|
29
|
+
T extends Type | undefined,
|
|
30
|
+
ValuePath extends string | number | symbol,
|
|
31
|
+
> = ValuePath extends string
|
|
32
|
+
? F extends Field<infer V, infer E> ? undefined extends T ? FieldAdapter<V, V, E, ValuePath>
|
|
33
|
+
: FieldAdapter<ValueTypeOf<ReadonlyTypeDefOf<NonNullable<T>>>, V, E, ValuePath>
|
|
34
|
+
: never
|
|
35
|
+
: never
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type FlattenedTypeDefsOf,
|
|
3
|
+
type ListTypeDef,
|
|
4
|
+
type Type,
|
|
5
|
+
} from '@strictly/define'
|
|
6
|
+
import { type SimplifyDeep } from 'type-fest'
|
|
7
|
+
|
|
8
|
+
export type ListJsonPathsOf<T extends Type> = keyof FlattenedListTypeDefsOf<T>
|
|
9
|
+
|
|
10
|
+
export type FlattenedListTypeDefsOf<T extends Type> = FlattenedListTypeDefsOfFlattened<
|
|
11
|
+
// SimplifyDeep is necessary here otherwise FlattenedListTypeDefsOfFlattened will complain about infinite depth
|
|
12
|
+
SimplifyDeep<FlattenedTypeDefsOf<T, null>>
|
|
13
|
+
>
|
|
14
|
+
|
|
15
|
+
type FlattenedListTypeDefsOfFlattened<T extends Readonly<Record<string, Type>>> = {
|
|
16
|
+
[K in keyof T as T[K]['definition'] extends ListTypeDef ? K : never]: T[K]
|
|
17
|
+
}
|