@strictly/react-form 0.0.6 → 0.0.7

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.
@@ -7,12 +7,12 @@ $ tsup
7
7
  CLI Target: esnext
8
8
  CJS Build start
9
9
  ESM Build start
10
- CJS dist/index.cjs 49.29 KB
11
- CJS ⚡️ Build success in 106ms
12
- ESM dist/index.js 45.41 KB
13
- ESM ⚡️ Build success in 106ms
10
+ CJS dist/index.cjs 50.08 KB
11
+ CJS ⚡️ Build success in 121ms
12
+ ESM dist/index.js 46.21 KB
13
+ ESM ⚡️ Build success in 122ms
14
14
  DTS Build start
15
- DTS ⚡️ Build success in 10312ms
16
- DTS dist/index.d.cts 35.93 KB
17
- DTS dist/index.d.ts 35.93 KB
18
- Done in 11.43s.
15
+ DTS ⚡️ Build success in 9863ms
16
+ DTS dist/index.d.cts 36.28 KB
17
+ DTS dist/index.d.ts 36.28 KB
18
+ Done in 10.98s.
@@ -1,3 +1,3 @@
1
1
  yarn run v1.22.22
2
2
  $ tsc
3
- Done in 8.11s.
3
+ Done in 7.67s.
@@ -1,3 +1,3 @@
1
1
  yarn run v1.22.22
2
2
  $ json -f package.json -f package.exports.json --merge > package.release.json
3
- Done in 0.11s.
3
+ Done in 0.12s.
@@ -85,14 +85,14 @@ describe('all', function () {
85
85
  ValueOfType<typeof typeDef>
86
86
  >
87
87
  >
88
- let t: Partial<{
88
+ type C = Partial<{
89
89
  readonly $: ConvenientFieldAdapter<Readonly<Record<'a' | 'b', number>>, ValueOfType<typeof typeDef>>,
90
90
  readonly ['$.a']: ConvenientFieldAdapter<number, ValueOfType<typeof typeDef>>,
91
91
  readonly ['$.b']: ConvenientFieldAdapter<number, ValueOfType<typeof typeDef>>,
92
92
  }>
93
93
 
94
94
  it('equals expected type', function () {
95
- expectTypeOf(t).toEqualTypeOf<T>()
95
+ expectTypeOf<C>().toEqualTypeOf<T>()
96
96
  })
97
97
  })
98
98
 
@@ -104,13 +104,13 @@ describe('all', function () {
104
104
  FlattenedValuesOfType<typeof typeDef>,
105
105
  ValueOfType<typeof typeDef>
106
106
  >
107
- let t: Partial<{
107
+ type C = Partial<{
108
108
  readonly $: ConvenientFieldAdapter<{ readonly x: string, readonly y: boolean }, ValueOfType<typeof typeDef>>,
109
109
  readonly ['$.x']: ConvenientFieldAdapter<string, ValueOfType<typeof typeDef>>,
110
110
  readonly ['$.y']: ConvenientFieldAdapter<boolean, ValueOfType<typeof typeDef>>,
111
111
  }>
112
112
  it('equals expected type', function () {
113
- expectTypeOf(t).toEqualTypeOf<T>()
113
+ expectTypeOf<C>().toEqualTypeOf<T>()
114
114
  })
115
115
 
116
116
  it('matches representative adapters', function () {
@@ -147,12 +147,12 @@ describe('all', function () {
147
147
  A,
148
148
  typeof valuePathsToTypePaths
149
149
  >
150
- let t: {
150
+ type C = {
151
151
  readonly '$.a': A['$.x'],
152
152
  readonly '$.b': A['$.y'],
153
153
  }
154
154
  it('equals expected type', function () {
155
- expectTypeOf(t).toEqualTypeOf<T>()
155
+ expectTypeOf<C>().toEqualTypeOf<T>()
156
156
  })
157
157
  })
158
158
  })
@@ -33,14 +33,14 @@ describe('MergedOfFieldAdapterWithTwoWayConverter', function () {
33
33
  }
34
34
  type M = MergedOfFieldAdaptersWithTwoWayConverter<T, typeof error4, typeof context>
35
35
 
36
- let m: {
36
+ type C = {
37
37
  readonly x: FieldAdapter<boolean, string, typeof error1 | typeof error4, 'x', typeof context>,
38
38
  readonly y: FieldAdapter<number, boolean, typeof error2 | typeof error4, 'y', typeof context>,
39
39
  readonly z: FieldAdapter<string, number, typeof error3 | typeof error4, 'z', typeof context>,
40
40
  }
41
41
 
42
42
  it('merges the errors', function () {
43
- expectTypeOf<M>().toEqualTypeOf(m)
43
+ expectTypeOf<M>().toEqualTypeOf<C>()
44
44
  })
45
45
  })
46
46
 
@@ -117,23 +117,23 @@ describe('mergeFieldAdaptersWithTwoWayConverter', function () {
117
117
  beforeEach(function () {
118
118
  result = merged.booleanAdapter.revert!(true, 'booleanAdapter', context)
119
119
  })
120
- })
121
120
 
122
- it('returns the same value on revert', function () {
123
- expect(result).toEqual(expect.objectContaining({
124
- value: true,
125
- type: UnreliableFieldConversionType.Success,
126
- }))
127
- })
121
+ it('returns the same value on revert', function () {
122
+ expect(result).toEqual(expect.objectContaining({
123
+ value: true,
124
+ type: UnreliableFieldConversionType.Success,
125
+ }))
126
+ })
128
127
 
129
- it('calls the mocked converter', function () {
130
- expect(converter.revert).toHaveBeenCalledOnce()
131
- expect(converter.revert).toHaveBeenCalledWith(true, 'booleanAdapter', context)
132
- })
128
+ it('calls the mocked converter', function () {
129
+ expect(converter.revert).toHaveBeenCalledOnce()
130
+ expect(converter.revert).toHaveBeenCalledWith(true, 'booleanAdapter', context)
131
+ })
133
132
 
134
- it('calls the mocked adapter', function () {
135
- expect(booleanAdapter.revert).toHaveBeenCalledOnce()
136
- expect(booleanAdapter.revert).toHaveBeenCalledWith(true, 'booleanAdapter', context)
133
+ it('calls the mocked adapter', function () {
134
+ expect(booleanAdapter.revert).toHaveBeenCalledOnce()
135
+ expect(booleanAdapter.revert).toHaveBeenCalledWith(true, 'booleanAdapter', context)
136
+ })
137
137
  })
138
138
  })
139
139
  })
@@ -1,15 +1,23 @@
1
+ import {
2
+ numberType,
3
+ object,
4
+ stringType,
5
+ } from '@strictly/define'
1
6
  import { type FieldAdapter } from 'core/mobx/field_adapter'
2
7
  import {
3
8
  subFormFieldAdapters,
4
9
  } from 'core/mobx/sub_form_field_adapters'
10
+ import { UnreliableFieldConversionType } from 'types/field_converters'
5
11
  import { mockDeep } from 'vitest-mock-extended'
6
12
 
7
13
  describe('subFormFieldAdapters', () => {
8
- const fieldAdapter1: FieldAdapter<string, boolean> = mockDeep()
9
- const fieldAdapter2: FieldAdapter<number, boolean> = mockDeep()
14
+ const mockedFieldAdapter1 = mockDeep<Required<FieldAdapter<string, boolean>>>()
15
+ const fieldAdapter1: FieldAdapter<string, boolean> = mockedFieldAdapter1
16
+ const mockedFieldAdapter2 = mockDeep<FieldAdapter<number, boolean>>()
17
+ const fieldAdapter2: FieldAdapter<number, boolean> = mockedFieldAdapter2
10
18
 
11
19
  describe('empty value', () => {
12
- const adapters = subFormFieldAdapters({}, '$.a')
20
+ const adapters = subFormFieldAdapters({}, '$.a', stringType)
13
21
 
14
22
  it('equals expected type', () => {
15
23
  expectTypeOf(adapters).toEqualTypeOf<{}>()
@@ -21,29 +29,68 @@ describe('subFormFieldAdapters', () => {
21
29
  })
22
30
 
23
31
  describe('single adapter', () => {
32
+ const type = object().field('a', stringType)
24
33
  const adapters = subFormFieldAdapters({
25
34
  $: fieldAdapter1,
26
- }, '$.a')
35
+ }, '$.a', type)
27
36
 
28
37
  it('equals expected type', () => {
29
- expectTypeOf(adapters).toEqualTypeOf<{
38
+ // TODO toEqualTypeOf (seems to be a TS error)
39
+ expectTypeOf(adapters).toMatchTypeOf<{
30
40
  '$.a': FieldAdapter<string, boolean>,
31
41
  }>()
32
42
  })
33
43
 
34
44
  it('equals expected value', () => {
35
- expect(adapters).toEqual({ '$.a': fieldAdapter1 })
45
+ expect(adapters).toEqual({ '$.a': expect.anything() })
46
+ })
47
+
48
+ it('calls convert with the correct paths and values', () => {
49
+ const mockedReturnedValue = {
50
+ value: false,
51
+ required: false,
52
+ readonly: false,
53
+ }
54
+ mockedFieldAdapter1.convert.mockReturnValue(mockedReturnedValue)
55
+
56
+ const returnedValue = adapters['$.a'].convert('x', '$.a', { a: 'y' })
57
+ expect(fieldAdapter1.convert).toHaveBeenCalledWith('x', '$', 'y')
58
+ expect(returnedValue).toEqual(mockedReturnedValue)
59
+ })
60
+
61
+ it('calls revert with the correct paths and values', () => {
62
+ const mockedReturnedValue = {
63
+ type: UnreliableFieldConversionType.Success,
64
+ value: 'ok',
65
+ } as const
66
+ mockedFieldAdapter1.revert.mockReturnValue(mockedReturnedValue)
67
+
68
+ const returnedValue = adapters['$.a'].revert?.(true, '$.a', { a: 'y' })
69
+ expect(fieldAdapter1.revert).toHaveBeenCalledWith(true, '$', 'y')
70
+ expect(returnedValue).toEqual(mockedReturnedValue)
71
+ })
72
+
73
+ it('calls create with the correct paths and values', () => {
74
+ const mockedReturnedValue = 'x'
75
+ mockedFieldAdapter1.create.mockReturnValue(mockedReturnedValue)
76
+
77
+ const returnedValue = adapters['$.a'].create('$.a', { a: 'y' })
78
+ expect(fieldAdapter1.create).toHaveBeenCalledWith('$', 'y')
79
+ expect(returnedValue).toEqual(mockedReturnedValue)
36
80
  })
37
81
  })
38
82
 
39
83
  describe('multiple adapters', () => {
84
+ const type = object()
85
+ .field('a', object().field('x', stringType).field('y', numberType))
40
86
  const adapters = subFormFieldAdapters({
41
87
  '$.x': fieldAdapter1,
42
88
  '$.y': fieldAdapter2,
43
- }, '$.a')
89
+ }, '$.a', type)
44
90
 
45
91
  it('equals expected type', () => {
46
- expectTypeOf(adapters).toEqualTypeOf<{
92
+ // TODO toEqualTypeOf (seems to be a TS error)
93
+ expectTypeOf(adapters).toMatchTypeOf<{
47
94
  '$.a.x': FieldAdapter<string, boolean>,
48
95
  '$.a.y': FieldAdapter<number, boolean>,
49
96
  }>()
@@ -51,8 +98,44 @@ describe('subFormFieldAdapters', () => {
51
98
 
52
99
  it('equals expected value', () => {
53
100
  expect(adapters).toEqual({
54
- '$.a.x': fieldAdapter1,
55
- '$.a.y': fieldAdapter2,
101
+ '$.a.x': expect.anything(),
102
+ '$.a.y': expect.anything(),
103
+ })
104
+ })
105
+
106
+ describe('calls convert with correct paths and values', () => {
107
+ const subContext = {
108
+ x: 'a',
109
+ y: 1,
110
+ } as const
111
+ const context = {
112
+ a: subContext,
113
+ }
114
+
115
+ it('calls $.a.x', () => {
116
+ const mockedReturnedValue = {
117
+ value: true,
118
+ readonly: true,
119
+ required: false,
120
+ }
121
+ mockedFieldAdapter1.convert.mockReturnValue(mockedReturnedValue)
122
+
123
+ const returnedValue = adapters['$.a.x'].convert('b', '$.a.x', context)
124
+ expect(fieldAdapter1.convert).toHaveBeenCalledWith('b', '$.x', subContext)
125
+ expect(returnedValue).toEqual(mockedReturnedValue)
126
+ })
127
+
128
+ it('calls $.a.y', () => {
129
+ const mockedReturnedValue = {
130
+ value: false,
131
+ readonly: false,
132
+ required: false,
133
+ }
134
+ mockedFieldAdapter2.convert.mockReturnValue(mockedReturnedValue)
135
+
136
+ const returnedValue = adapters['$.a.y'].convert(2, '$.a.y', context)
137
+ expect(fieldAdapter2.convert).toHaveBeenCalledWith(2, '$.y', subContext)
138
+ expect(returnedValue).toEqual(mockedReturnedValue)
56
139
  })
57
140
  })
58
141
  })
@@ -1,21 +1,68 @@
1
1
  import { type StringConcatOf } from '@strictly/base'
2
- import { type FieldAdapter } from './field_adapter'
2
+ import {
3
+ flattenValuesOfType,
4
+ type Type,
5
+ type ValueOfType,
6
+ } from '@strictly/define'
7
+ import {
8
+ type ErrorOfFieldAdapter,
9
+ type FieldAdapter,
10
+ type FromOfFieldAdapter,
11
+ type ToOfFieldAdapter,
12
+ } from './field_adapter'
3
13
 
4
- type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string> = {
5
- [K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: SubAdapters[K]
14
+ type SubFormFieldAdapter<F extends FieldAdapter, P extends string, Context> = FieldAdapter<
15
+ FromOfFieldAdapter<F>,
16
+ ToOfFieldAdapter<F>,
17
+ ErrorOfFieldAdapter<F>,
18
+ P,
19
+ Context
20
+ >
21
+
22
+ type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string, Context> = {
23
+ [K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: K extends
24
+ StringConcatOf<'$', infer S> ? SubFormFieldAdapter<
25
+ SubAdapters[K],
26
+ `${P}${S}`,
27
+ Context
28
+ >
29
+ : never
6
30
  }
7
31
 
8
- export function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string>(
32
+ export function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string,
33
+ ContextType extends Type>(
9
34
  subAdapters: SubAdapters,
10
35
  prefix: P,
11
- ): SubFormFieldAdapters<SubAdapters, P> {
36
+ contextType: ContextType,
37
+ ): SubFormFieldAdapters<SubAdapters, P, ValueOfType<ContextType>> {
38
+ function getSubValuePathAndContext(valuePath: string, context: ValueOfType<ContextType>) {
39
+ const subValuePath = valuePath.replace(prefix, '$')
40
+ const subContext = flattenValuesOfType(contextType, context)[prefix]
41
+ return [
42
+ subValuePath,
43
+ subContext,
44
+ ] as const
45
+ }
46
+
12
47
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
13
48
  return Object.entries(subAdapters).reduce<Record<string, FieldAdapter>>((acc, [
14
49
  subKey,
15
50
  subValue,
16
51
  ]) => {
17
52
  const key = subKey.replace('$', prefix)
18
- acc[key] = subValue
53
+ // adapt field adapter with new path and context
54
+ const adaptedAdapter: FieldAdapter = {
55
+ convert: (from, valuePath, context) => {
56
+ return subValue.convert(from, ...getSubValuePathAndContext(valuePath, context))
57
+ },
58
+ create: (valuePath, context) => {
59
+ return subValue.create(...getSubValuePathAndContext(valuePath, context))
60
+ },
61
+ revert: subValue.revert && ((from, valuePath, context) => {
62
+ return subValue.revert!(from, ...getSubValuePathAndContext(valuePath, context))
63
+ }),
64
+ }
65
+ acc[key] = adaptedAdapter
19
66
  return acc
20
- }, {}) as SubFormFieldAdapters<SubAdapters, P>
67
+ }, {}) as SubFormFieldAdapters<SubAdapters, P, ValueOfType<ContextType>>
21
68
  }
package/dist/index.cjs CHANGED
@@ -817,13 +817,33 @@ function mergeAdaptersWithValidators(adapters, validators) {
817
817
  }
818
818
 
819
819
  // core/mobx/sub_form_field_adapters.ts
820
- function subFormFieldAdapters(subAdapters, prefix) {
820
+ var import_define3 = require("@strictly/define");
821
+ function subFormFieldAdapters(subAdapters, prefix, contextType) {
822
+ function getSubValuePathAndContext(valuePath, context) {
823
+ const subValuePath = valuePath.replace(prefix, "$");
824
+ const subContext = (0, import_define3.flattenValuesOfType)(contextType, context)[prefix];
825
+ return [
826
+ subValuePath,
827
+ subContext
828
+ ];
829
+ }
821
830
  return Object.entries(subAdapters).reduce((acc, [
822
831
  subKey,
823
832
  subValue
824
833
  ]) => {
825
834
  const key = subKey.replace("$", prefix);
826
- acc[key] = subValue;
835
+ const adaptedAdapter = {
836
+ convert: (from, valuePath, context) => {
837
+ return subValue.convert(from, ...getSubValuePathAndContext(valuePath, context));
838
+ },
839
+ create: (valuePath, context) => {
840
+ return subValue.create(...getSubValuePathAndContext(valuePath, context));
841
+ },
842
+ revert: subValue.revert && ((from, valuePath, context) => {
843
+ return subValue.revert(from, ...getSubValuePathAndContext(valuePath, context));
844
+ })
845
+ };
846
+ acc[key] = adaptedAdapter;
827
847
  return acc;
828
848
  }, {});
829
849
  }
@@ -860,7 +880,7 @@ var IntegerToStringConverter = class {
860
880
  };
861
881
 
862
882
  // field_converters/nullable_to_boolean_converter.ts
863
- var import_define3 = require("@strictly/define");
883
+ var import_define4 = require("@strictly/define");
864
884
  var NullableToBooleanConverter = class {
865
885
  constructor(typeDef, prototype, nullType, defaultToNull = true) {
866
886
  this.typeDef = typeDef;
@@ -878,7 +898,7 @@ var NullableToBooleanConverter = class {
878
898
  }
879
899
  revert(from) {
880
900
  if (from) {
881
- const value = (0, import_define3.copy)(this.typeDef, this.prototype);
901
+ const value = (0, import_define4.copy)(this.typeDef, this.prototype);
882
902
  return {
883
903
  type: 0 /* Success */,
884
904
  value
@@ -896,7 +916,7 @@ var NullableToBooleanConverter = class {
896
916
 
897
917
  // field_converters/select_value_type_converter.ts
898
918
  var import_base5 = require("@strictly/base");
899
- var import_define4 = require("@strictly/define");
919
+ var import_define5 = require("@strictly/define");
900
920
  var AbstractSelectValueTypeConverter = class {
901
921
  constructor(typeDef, values, defaultValueKey, noSuchValueError, required) {
902
922
  this.typeDef = typeDef;
@@ -914,7 +934,7 @@ var AbstractSelectValueTypeConverter = class {
914
934
  value: null
915
935
  };
916
936
  }
917
- const value = prototype == null ? prototype : (0, import_define4.copy)(this.typeDef, prototype);
937
+ const value = prototype == null ? prototype : (0, import_define5.copy)(this.typeDef, prototype);
918
938
  return {
919
939
  type: 0 /* Success */,
920
940
  value
@@ -1007,13 +1027,13 @@ var TrimmingStringConverter = class {
1007
1027
  };
1008
1028
 
1009
1029
  // field_converters/validating_converter.ts
1010
- var import_define5 = require("@strictly/define");
1030
+ var import_define6 = require("@strictly/define");
1011
1031
  function validatingConverter(validators = []) {
1012
1032
  return function(value, valuePath, context) {
1013
1033
  return validators.reduce(
1014
1034
  function(acc, validator) {
1015
1035
  if (acc.type === 0 /* Success */) {
1016
- const error = (0, import_define5.validate)(validator, value, valuePath, context);
1036
+ const error = (0, import_define6.validate)(validator, value, valuePath, context);
1017
1037
  if (error != null) {
1018
1038
  return {
1019
1039
  type: 1 /* Failure */,
@@ -1674,7 +1694,7 @@ var MantineFormImpl = class {
1674
1694
  };
1675
1695
 
1676
1696
  // types/merge_validators.ts
1677
- var import_define6 = require("@strictly/define");
1697
+ var import_define7 = require("@strictly/define");
1678
1698
  function mergeValidators(validators1, validators2) {
1679
1699
  const validators = {
1680
1700
  ...validators1,
@@ -1689,16 +1709,16 @@ function mergeValidators(validators1, validators2) {
1689
1709
  validators3[key] = {
1690
1710
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1691
1711
  validate: function(value, valuePath, context) {
1692
- const error = (0, import_define6.validate)(validator1, value, valuePath, context);
1712
+ const error = (0, import_define7.validate)(validator1, value, valuePath, context);
1693
1713
  if (error != null) {
1694
1714
  return error;
1695
1715
  }
1696
- return (0, import_define6.validate)(validator2, value, valuePath, context);
1716
+ return (0, import_define7.validate)(validator2, value, valuePath, context);
1697
1717
  },
1698
1718
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1699
1719
  annotations: function(valuePath, context) {
1700
- const annotations1 = (0, import_define6.annotations)(validator1, valuePath, context);
1701
- const annotations22 = (0, import_define6.annotations)(validator2, valuePath, context);
1720
+ const annotations1 = (0, import_define7.annotations)(validator1, valuePath, context);
1721
+ const annotations22 = (0, import_define7.annotations)(validator2, valuePath, context);
1702
1722
  return {
1703
1723
  readonly: annotations1.readonly || annotations22.readonly,
1704
1724
  required: annotations1.required || annotations22.required
package/dist/index.d.cts CHANGED
@@ -204,10 +204,11 @@ type MergedOfFieldAdaptersWithValidators<FieldAdapters extends Readonly<Record<K
204
204
  type MergedOfFieldAdapterWithValidator<A extends FieldAdapter, V extends Validator | undefined> = undefined extends V ? A : A extends FieldAdapter<infer From, infer To, infer E1, infer P1, infer C1> ? V extends Validator<From, infer E2, infer P2, infer C2> ? FieldAdapter<From, To, E1 | E2, P1 | P2, C1 | C2> : never : never;
205
205
  declare function mergeAdaptersWithValidators<FieldAdapters extends Readonly<Record<Key, FieldAdapter>>, Validators extends Readonly<Record<string, Validator>>, Key extends keyof Validators = keyof Validators>(adapters: FieldAdapters, validators: Validators): MergedOfFieldAdaptersWithValidators<FieldAdapters, Validators, Key>;
206
206
 
207
- type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string> = {
208
- [K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: SubAdapters[K];
207
+ type SubFormFieldAdapter<F extends FieldAdapter, P extends string, Context> = FieldAdapter<FromOfFieldAdapter<F>, ToOfFieldAdapter<F>, ErrorOfFieldAdapter<F>, P, Context>;
208
+ type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string, Context> = {
209
+ [K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: K extends StringConcatOf<'$', infer S> ? SubFormFieldAdapter<SubAdapters[K], `${P}${S}`, Context> : never;
209
210
  };
210
- declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string>(subAdapters: SubAdapters, prefix: P): SubFormFieldAdapters<SubAdapters, P>;
211
+ declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string, ContextType extends Type>(subAdapters: SubAdapters, prefix: P, contextType: ContextType): SubFormFieldAdapters<SubAdapters, P, ValueOfType<ContextType>>;
211
212
 
212
213
  declare class IntegerToStringConverter<E, ValuePath extends string, Context> implements TwoWayFieldConverter<number, string, E, ValuePath, Context> {
213
214
  private readonly isNanError;
package/dist/index.d.ts CHANGED
@@ -204,10 +204,11 @@ type MergedOfFieldAdaptersWithValidators<FieldAdapters extends Readonly<Record<K
204
204
  type MergedOfFieldAdapterWithValidator<A extends FieldAdapter, V extends Validator | undefined> = undefined extends V ? A : A extends FieldAdapter<infer From, infer To, infer E1, infer P1, infer C1> ? V extends Validator<From, infer E2, infer P2, infer C2> ? FieldAdapter<From, To, E1 | E2, P1 | P2, C1 | C2> : never : never;
205
205
  declare function mergeAdaptersWithValidators<FieldAdapters extends Readonly<Record<Key, FieldAdapter>>, Validators extends Readonly<Record<string, Validator>>, Key extends keyof Validators = keyof Validators>(adapters: FieldAdapters, validators: Validators): MergedOfFieldAdaptersWithValidators<FieldAdapters, Validators, Key>;
206
206
 
207
- type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string> = {
208
- [K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: SubAdapters[K];
207
+ type SubFormFieldAdapter<F extends FieldAdapter, P extends string, Context> = FieldAdapter<FromOfFieldAdapter<F>, ToOfFieldAdapter<F>, ErrorOfFieldAdapter<F>, P, Context>;
208
+ type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string, Context> = {
209
+ [K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: K extends StringConcatOf<'$', infer S> ? SubFormFieldAdapter<SubAdapters[K], `${P}${S}`, Context> : never;
209
210
  };
210
- declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string>(subAdapters: SubAdapters, prefix: P): SubFormFieldAdapters<SubAdapters, P>;
211
+ declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string, ContextType extends Type>(subAdapters: SubAdapters, prefix: P, contextType: ContextType): SubFormFieldAdapters<SubAdapters, P, ValueOfType<ContextType>>;
211
212
 
212
213
  declare class IntegerToStringConverter<E, ValuePath extends string, Context> implements TwoWayFieldConverter<number, string, E, ValuePath, Context> {
213
214
  private readonly isNanError;
package/dist/index.js CHANGED
@@ -790,13 +790,35 @@ function mergeAdaptersWithValidators(adapters, validators) {
790
790
  }
791
791
 
792
792
  // core/mobx/sub_form_field_adapters.ts
793
- function subFormFieldAdapters(subAdapters, prefix) {
793
+ import {
794
+ flattenValuesOfType as flattenValuesOfType2
795
+ } from "@strictly/define";
796
+ function subFormFieldAdapters(subAdapters, prefix, contextType) {
797
+ function getSubValuePathAndContext(valuePath, context) {
798
+ const subValuePath = valuePath.replace(prefix, "$");
799
+ const subContext = flattenValuesOfType2(contextType, context)[prefix];
800
+ return [
801
+ subValuePath,
802
+ subContext
803
+ ];
804
+ }
794
805
  return Object.entries(subAdapters).reduce((acc, [
795
806
  subKey,
796
807
  subValue
797
808
  ]) => {
798
809
  const key = subKey.replace("$", prefix);
799
- acc[key] = subValue;
810
+ const adaptedAdapter = {
811
+ convert: (from, valuePath, context) => {
812
+ return subValue.convert(from, ...getSubValuePathAndContext(valuePath, context));
813
+ },
814
+ create: (valuePath, context) => {
815
+ return subValue.create(...getSubValuePathAndContext(valuePath, context));
816
+ },
817
+ revert: subValue.revert && ((from, valuePath, context) => {
818
+ return subValue.revert(from, ...getSubValuePathAndContext(valuePath, context));
819
+ })
820
+ };
821
+ acc[key] = adaptedAdapter;
800
822
  return acc;
801
823
  }, {});
802
824
  }
package/package.json CHANGED
@@ -69,7 +69,7 @@
69
69
  "test:watch": "vitest"
70
70
  },
71
71
  "type": "module",
72
- "version": "0.0.6",
72
+ "version": "0.0.7",
73
73
  "exports": {
74
74
  ".": {
75
75
  "import": {