@strictly/define 0.0.1 → 0.0.2

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.
Files changed (199) hide show
  1. package/.out/index.d.ts +17 -11
  2. package/.out/index.js +17 -11
  3. package/.out/transformers/copies/copy.d.ts +3 -3
  4. package/.out/transformers/copies/copy_to.d.ts +3 -3
  5. package/.out/transformers/copies/copy_to.js +4 -0
  6. package/.out/transformers/copies/mobx_copy.d.ts +4 -4
  7. package/.out/transformers/copies/mobx_copy.js +1 -1
  8. package/.out/transformers/copies/specs/copy_to.tests.js +8 -8
  9. package/.out/transformers/copies/specs/mobx_copy.tests.js +1 -1
  10. package/.out/transformers/flatteners/flatten_accessors_of_type.d.ts +5 -0
  11. package/.out/transformers/flatteners/flatten_accessors_of_type.js +11 -0
  12. package/.out/transformers/flatteners/flatten_json_value_to_type_paths_of.d.ts +2 -2
  13. package/.out/transformers/flatteners/flatten_json_value_to_type_paths_of.js +2 -2
  14. package/.out/transformers/flatteners/{flatten_type_def_to.d.ts → flatten_type_to.d.ts} +1 -1
  15. package/.out/transformers/flatteners/{flatten_type_def_to.js → flatten_type_to.js} +1 -1
  16. package/.out/transformers/flatteners/{flatten_type_defs_of.d.ts → flatten_types_of_type.d.ts} +1 -1
  17. package/.out/transformers/flatteners/flatten_types_of_type.js +7 -0
  18. package/.out/transformers/flatteners/flatten_validation_errors_of_type.d.ts +22 -0
  19. package/.out/transformers/flatteners/flatten_validation_errors_of_type.js +10 -0
  20. package/.out/transformers/flatteners/flatten_validators_of_validating_type.d.ts +4 -0
  21. package/.out/transformers/flatteners/flatten_validators_of_validating_type.js +17 -0
  22. package/.out/transformers/flatteners/{flatten_value_type_to.d.ts → flatten_value_to.d.ts} +4 -4
  23. package/.out/transformers/flatteners/{flatten_value_type_to.js → flatten_value_to.js} +7 -2
  24. package/.out/transformers/flatteners/flatten_values_of_type.d.ts +3 -0
  25. package/.out/transformers/flatteners/flatten_values_of_type.js +7 -0
  26. package/.out/transformers/flatteners/specs/{flatten_accessors_of.tests.js → flatten_accessors_of_type.tests.js} +5 -6
  27. package/.out/transformers/flatteners/specs/flatten_json_value_to_type_paths_of.tests.js +6 -6
  28. package/.out/transformers/flatteners/specs/{flatten_type_def_to.tests.js → flatten_type_to.tests.js} +15 -13
  29. package/.out/transformers/flatteners/specs/flatten_types_of_type.tests.js +18 -0
  30. package/.out/transformers/flatteners/specs/flatten_validation_errors_of_type.tests.js +25 -0
  31. package/.out/transformers/flatteners/specs/{flatten_value_type_to.tests.js → flatten_value_to.tests.js} +81 -58
  32. package/.out/transformers/flatteners/specs/{flatten_value_types_of.tests.js → flatten_values_of_type.tests.js} +4 -4
  33. package/.out/transformers/flatteners/specs/value_path_to_type_path.tests.js +5 -3
  34. package/.out/transformers/flatteners/value_path_to_type_path.d.ts +1 -1
  35. package/.out/tsconfig.tsbuildinfo +1 -1
  36. package/.out/types/builders.d.ts +55 -29
  37. package/.out/types/builders.js +116 -32
  38. package/.out/types/definitions.d.ts +1 -1
  39. package/.out/types/flattened_accessors_of_type.d.ts +9 -0
  40. package/.out/types/{flattened_type_defs_of.d.ts → flattened_types_of_type.d.ts} +9 -6
  41. package/.out/types/flattened_types_of_validating_type.d.ts +25 -0
  42. package/.out/types/flattened_validators_of_validating_type.d.ts +10 -0
  43. package/.out/types/flattened_values_of_type.d.ts +6 -0
  44. package/.out/types/{mobx_value_type_of.d.ts → mobx_value_of_type.d.ts} +2 -2
  45. package/.out/types/{partial_type_def_of.d.ts → partial_type_of_type.d.ts} +1 -1
  46. package/.out/types/path_of.d.ts +1 -0
  47. package/.out/types/{json_paths_of.d.ts → paths_of_type.d.ts} +5 -5
  48. package/.out/types/readonly_type_of_type.d.ts +29 -0
  49. package/.out/types/specs/builder.tests.js +73 -23
  50. package/.out/types/specs/{flattened_accessors_of.tests.js → flattened_accessors_of_type.tests.js} +1 -1
  51. package/.out/types/specs/{flattened_type_defs_of.tests.js → flattened_types_of_type.tests.js} +22 -15
  52. package/.out/types/specs/flattened_validators_of_validating_type.tests.js +24 -0
  53. package/.out/types/specs/flattened_values_of_type.tests.js +18 -0
  54. package/.out/types/specs/{partial_type_def_of.tests.js → partial_type_of_type.tests.js} +4 -4
  55. package/.out/types/specs/{json_paths_of.tests.js → paths_of_type.tests.js} +19 -19
  56. package/.out/types/specs/{readonly_type_def_of.tests.js → readonly_type_of_type.tests.js} +6 -6
  57. package/.out/types/specs/type_of_type.tests.d.ts +1 -0
  58. package/.out/types/specs/type_of_type.tests.js +27 -0
  59. package/.out/types/specs/value_of_type.tests.d.ts +1 -0
  60. package/.out/types/specs/{value_type_of.tests.js → value_of_type.tests.js} +1 -1
  61. package/.out/types/specs/value_to_type_paths_of_type.tests.d.ts +1 -0
  62. package/.out/types/specs/{value_to_type_paths_of.tests.js → value_to_type_paths_of_type.tests.js} +9 -9
  63. package/.out/types/specs/value_types_of_discriminated_union.tests.js +2 -2
  64. package/.out/types/strict_definitions.d.ts +2 -2
  65. package/.out/types/type_of_type.d.ts +49 -0
  66. package/.out/types/type_of_type.js +70 -0
  67. package/.out/types/validating_definitions.d.ts +49 -0
  68. package/.out/types/validating_definitions.js +1 -0
  69. package/.out/types/validating_type_def_with_error.d.ts +55 -0
  70. package/.out/types/validating_type_def_with_error.js +1 -0
  71. package/.out/types/value_of_type.d.ts +24 -0
  72. package/.out/types/value_of_type.js +1 -0
  73. package/.out/types/{value_to_type_paths_of.d.ts → value_to_type_paths_of_type.d.ts} +13 -13
  74. package/.out/types/value_to_type_paths_of_type.js +1 -0
  75. package/.out/types/value_types_of_discriminated_union.d.ts +5 -4
  76. package/.out/validation/errors_of_validators.d.ts +4 -0
  77. package/.out/validation/errors_of_validators.js +1 -0
  78. package/.out/validation/specs/errors_of_validators.tests.d.ts +1 -0
  79. package/.out/validation/specs/errors_of_validators.tests.js +9 -0
  80. package/.out/validation/specs/validators_of_values.tests.d.ts +1 -0
  81. package/.out/validation/specs/validators_of_values.tests.js +21 -0
  82. package/.out/validation/validator.d.ts +21 -0
  83. package/.out/validation/validator.js +26 -0
  84. package/.out/validation/validators/defined_validator.d.ts +10 -0
  85. package/.out/validation/validators/defined_validator.js +18 -0
  86. package/.out/validation/validators/minimum_string_length_validator.d.ts +16 -0
  87. package/.out/validation/validators/minimum_string_length_validator.js +23 -0
  88. package/.out/validation/validators_of_values.d.ts +4 -0
  89. package/.out/validation/validators_of_values.js +1 -0
  90. package/.turbo/turbo-build.log +9 -9
  91. package/.turbo/turbo-check-types.log +1 -1
  92. package/.turbo/turbo-release$colon$exports.log +1 -1
  93. package/README.md +16 -2
  94. package/dist/index.cjs +364 -76
  95. package/dist/index.d.cts +365 -114
  96. package/dist/index.d.ts +365 -114
  97. package/dist/index.js +355 -73
  98. package/index.ts +17 -11
  99. package/package.json +11 -3
  100. package/transformers/copies/copy.ts +4 -4
  101. package/transformers/copies/copy_to.ts +11 -7
  102. package/transformers/copies/mobx_copy.ts +6 -6
  103. package/transformers/copies/specs/copy_to.tests.ts +8 -8
  104. package/transformers/copies/specs/mobx_copy.tests.ts +3 -3
  105. package/transformers/flatteners/{flatten_accessors_of.ts → flatten_accessors_of_type.ts} +10 -10
  106. package/transformers/flatteners/flatten_json_value_to_type_paths_of.ts +5 -5
  107. package/transformers/flatteners/{flatten_type_def_to.ts → flatten_type_to.ts} +1 -1
  108. package/transformers/flatteners/{flatten_type_defs_of.ts → flatten_types_of_type.ts} +3 -3
  109. package/transformers/flatteners/flatten_validation_errors_of_type.ts +93 -0
  110. package/transformers/flatteners/flatten_validators_of_validating_type.ts +32 -0
  111. package/transformers/flatteners/{flatten_value_type_to.ts → flatten_value_to.ts} +12 -7
  112. package/transformers/flatteners/{flatten_value_types_of.ts → flatten_values_of_type.ts} +6 -6
  113. package/transformers/flatteners/specs/{flatten_accessors_of.tests.ts → flatten_accessors_of_type.tests.ts} +10 -11
  114. package/transformers/flatteners/specs/flatten_json_value_to_type_paths_of.tests.ts +6 -6
  115. package/transformers/flatteners/specs/{flatten_type_def_to.tests.ts → flatten_type_to.tests.ts} +15 -13
  116. package/transformers/flatteners/specs/flatten_types_of_type.tests.ts +27 -0
  117. package/transformers/flatteners/specs/flatten_validation_errors_of_type.tests.ts +48 -0
  118. package/transformers/flatteners/specs/{flatten_value_type_to.tests.ts → flatten_value_to.tests.ts} +124 -91
  119. package/transformers/flatteners/specs/{flatten_value_types_of.tests.ts → flatten_values_of_type.tests.ts} +4 -4
  120. package/transformers/flatteners/specs/value_path_to_type_path.tests.ts +20 -18
  121. package/transformers/flatteners/value_path_to_type_path.ts +4 -4
  122. package/types/builders.ts +239 -71
  123. package/types/definitions.ts +2 -2
  124. package/types/{flattened_accessors_of.ts → flattened_accessors_of_type.ts} +3 -3
  125. package/types/{flattened_type_defs_of.ts → flattened_types_of_type.ts} +22 -12
  126. package/types/flattened_types_of_validating_type.ts +152 -0
  127. package/types/flattened_validators_of_validating_type.ts +33 -0
  128. package/types/flattened_values_of_type.ts +11 -0
  129. package/types/{mobx_value_type_of.ts → mobx_value_of_type.ts} +2 -2
  130. package/types/{partial_type_def_of.ts → partial_type_of_type.ts} +3 -1
  131. package/types/{json_path_of.ts → path_of.ts} +1 -1
  132. package/types/{json_paths_of.ts → paths_of_type.ts} +5 -5
  133. package/types/readonly_type_of_type.ts +54 -0
  134. package/types/specs/builder.tests.ts +205 -54
  135. package/types/specs/{flattened_accessors_of.tests.ts → flattened_accessors_of_type.tests.ts} +3 -3
  136. package/types/specs/{flattened_type_defs_of.tests.ts → flattened_types_of_type.tests.ts} +82 -34
  137. package/types/specs/flattened_validators_of_validating_type.tests.ts +47 -0
  138. package/types/specs/flattened_values_of_type.tests.ts +39 -0
  139. package/types/specs/{partial_type_def_of.tests.ts → partial_type_of_type.tests.ts} +11 -11
  140. package/types/specs/{json_paths_of.tests.ts → paths_of_type.tests.ts} +47 -47
  141. package/types/specs/{readonly_type_def_of.tests.ts → readonly_type_of_type.tests.ts} +14 -14
  142. package/types/specs/type_of_type.tests.ts +60 -0
  143. package/types/specs/{value_type_of.tests.ts → value_of_type.tests.ts} +15 -15
  144. package/types/specs/{value_to_type_paths_of.tests.ts → value_to_type_paths_of_type.tests.ts} +26 -25
  145. package/types/specs/value_types_of_discriminated_union.tests.ts +6 -6
  146. package/types/strict_definitions.ts +3 -3
  147. package/types/type_of_type.ts +178 -0
  148. package/types/validating_definitions.ts +109 -0
  149. package/types/validating_type_def_with_error.ts +93 -0
  150. package/types/value_of_type.ts +84 -0
  151. package/types/{value_to_type_paths_of.ts → value_to_type_paths_of_type.ts} +30 -29
  152. package/types/value_types_of_discriminated_union.ts +4 -3
  153. package/validation/errors_of_validators.ts +10 -0
  154. package/validation/specs/errors_of_validators.tests.ts +20 -0
  155. package/validation/specs/validators_of_values.tests.ts +68 -0
  156. package/validation/validator.ts +103 -0
  157. package/validation/validators/defined_validator.ts +22 -0
  158. package/validation/validators/minimum_string_length_validator.ts +36 -0
  159. package/validation/validators_of_values.ts +17 -0
  160. package/.out/transformers/flatteners/flatten_accessors_of.d.ts +0 -5
  161. package/.out/transformers/flatteners/flatten_accessors_of.js +0 -11
  162. package/.out/transformers/flatteners/flatten_type_defs_of.js +0 -7
  163. package/.out/transformers/flatteners/flatten_value_types_of.d.ts +0 -3
  164. package/.out/transformers/flatteners/flatten_value_types_of.js +0 -7
  165. package/.out/transformers/flatteners/specs/flatten_type_defs_of.tests.js +0 -17
  166. package/.out/types/flattened_accessors_of.d.ts +0 -9
  167. package/.out/types/flattened_value_types_of.d.ts +0 -6
  168. package/.out/types/json_path_of.d.ts +0 -1
  169. package/.out/types/readonly_type_def_of.d.ts +0 -29
  170. package/.out/types/specs/flattened_value_types_of.tests.js +0 -11
  171. package/.out/types/value_type_of.d.ts +0 -24
  172. package/transformers/flatteners/specs/flatten_type_defs_of.tests.ts +0 -26
  173. package/types/flattened_value_types_of.ts +0 -11
  174. package/types/readonly_type_def_of.ts +0 -53
  175. package/types/specs/flattened_value_types_of.tests.ts +0 -21
  176. package/types/value_type_of.ts +0 -84
  177. /package/.out/transformers/flatteners/specs/{flatten_accessors_of.tests.d.ts → flatten_accessors_of_type.tests.d.ts} +0 -0
  178. /package/.out/transformers/flatteners/specs/{flatten_type_def_to.tests.d.ts → flatten_type_to.tests.d.ts} +0 -0
  179. /package/.out/transformers/flatteners/specs/{flatten_type_defs_of.tests.d.ts → flatten_types_of_type.tests.d.ts} +0 -0
  180. /package/.out/transformers/flatteners/specs/{flatten_value_type_to.tests.d.ts → flatten_validation_errors_of_type.tests.d.ts} +0 -0
  181. /package/.out/transformers/flatteners/specs/{flatten_value_types_of.tests.d.ts → flatten_value_to.tests.d.ts} +0 -0
  182. /package/.out/{types/flattened_accessors_of.js → transformers/flatteners/specs/flatten_values_of_type.tests.d.ts} +0 -0
  183. /package/.out/types/{flattened_type_defs_of.js → flattened_accessors_of_type.js} +0 -0
  184. /package/.out/types/{flattened_value_types_of.js → flattened_types_of_type.js} +0 -0
  185. /package/.out/types/{json_path_of.js → flattened_types_of_validating_type.js} +0 -0
  186. /package/.out/types/{json_paths_of.js → flattened_validators_of_validating_type.js} +0 -0
  187. /package/.out/types/{partial_type_def_of.js → flattened_values_of_type.js} +0 -0
  188. /package/.out/types/{mobx_value_type_of.js → mobx_value_of_type.js} +0 -0
  189. /package/.out/types/{readonly_type_def_of.js → partial_type_of_type.js} +0 -0
  190. /package/.out/types/{specs/flattened_accessors_of.tests.d.ts → path_of.js} +0 -0
  191. /package/.out/types/{specs/flattened_type_defs_of.tests.d.ts → paths_of_type.js} +0 -0
  192. /package/.out/types/{specs/flattened_value_types_of.tests.d.ts → readonly_type_of_type.js} +0 -0
  193. /package/.out/types/specs/{json_paths_of.tests.d.ts → flattened_accessors_of_type.tests.d.ts} +0 -0
  194. /package/.out/types/specs/{partial_type_def_of.tests.d.ts → flattened_types_of_type.tests.d.ts} +0 -0
  195. /package/.out/types/specs/{readonly_type_def_of.tests.d.ts → flattened_validators_of_validating_type.tests.d.ts} +0 -0
  196. /package/.out/types/specs/{value_to_type_paths_of.tests.d.ts → flattened_values_of_type.tests.d.ts} +0 -0
  197. /package/.out/types/specs/{value_type_of.tests.d.ts → partial_type_of_type.tests.d.ts} +0 -0
  198. /package/.out/types/{value_to_type_paths_of.js → specs/paths_of_type.tests.d.ts} +0 -0
  199. /package/.out/types/{value_type_of.js → specs/readonly_type_of_type.tests.d.ts} +0 -0
@@ -1,4 +1,4 @@
1
- import { flattenTypeDefTo } from 'transformers/flatteners/flatten_type_def_to'
1
+ import { flattenTypeTo } from 'transformers/flatteners/flatten_type_to'
2
2
  import {
3
3
  booleanType,
4
4
  list,
@@ -29,7 +29,7 @@ describe('flattenTypeDefTo', function () {
29
29
 
30
30
  describe('literal', function () {
31
31
  beforeEach(function () {
32
- flattened = flattenTypeDefTo(numberType, toTypeDefType)
32
+ flattened = flattenTypeTo(numberType, toTypeDefType)
33
33
  })
34
34
 
35
35
  it('equals expected type', function () {
@@ -46,7 +46,7 @@ describe('flattenTypeDefTo', function () {
46
46
  describe('list', function () {
47
47
  const type = list(numberType)
48
48
  beforeEach(function () {
49
- flattened = flattenTypeDefTo(type, toTypeDefType)
49
+ flattened = flattenTypeTo(type, toTypeDefType)
50
50
  })
51
51
 
52
52
  it('equals expected type', function () {
@@ -64,7 +64,7 @@ describe('flattenTypeDefTo', function () {
64
64
  describe('record', function () {
65
65
  const type = record<typeof numberType, 'a' | 'b'>(numberType)
66
66
  beforeEach(function () {
67
- flattened = flattenTypeDefTo(type, toTypeDefType)
67
+ flattened = flattenTypeTo(type, toTypeDefType)
68
68
  })
69
69
 
70
70
  it('equals expected type', function () {
@@ -82,9 +82,11 @@ describe('flattenTypeDefTo', function () {
82
82
  })
83
83
 
84
84
  describe('object', function () {
85
- const type = object().set('a', numberType).set('b', list(booleanType))
85
+ const type = object()
86
+ .field('a', numberType)
87
+ .field('b', list(booleanType))
86
88
  beforeEach(function () {
87
- flattened = flattenTypeDefTo(type, toTypeDefType)
89
+ flattened = flattenTypeTo(type, toTypeDefType)
88
90
  })
89
91
 
90
92
  it('equals expected type', function () {
@@ -104,11 +106,11 @@ describe('flattenTypeDefTo', function () {
104
106
  describe('union', function () {
105
107
  describe('non-discriminated', function () {
106
108
  const type = union()
107
- .add('a', nullType)
108
- .add('b', booleanType)
109
- .add('c', numberType)
109
+ .or('a', nullType)
110
+ .or('b', booleanType)
111
+ .or('c', numberType)
110
112
  beforeEach(function () {
111
- flattened = flattenTypeDefTo(type, toTypeDefType)
113
+ flattened = flattenTypeTo(type, toTypeDefType)
112
114
  })
113
115
 
114
116
  it('equals expected type', function () {
@@ -124,10 +126,10 @@ describe('flattenTypeDefTo', function () {
124
126
 
125
127
  describe('discriminated', function () {
126
128
  const type = union('d')
127
- .add('a', object().set('a', booleanType))
128
- .add('b', object().set('b', numberType))
129
+ .or('a', object().field('a', booleanType))
130
+ .or('b', object().field('b', numberType))
129
131
  beforeEach(function () {
130
- flattened = flattenTypeDefTo(type, toTypeDefType)
132
+ flattened = flattenTypeTo(type, toTypeDefType)
131
133
  })
132
134
 
133
135
  it('equals expected type', function () {
@@ -0,0 +1,27 @@
1
+ import { flattenTypesOfType } from 'transformers/flatteners/flatten_types_of_type'
2
+ import {
3
+ booleanType,
4
+ list,
5
+ numberType,
6
+ object,
7
+ } from 'types/builders'
8
+
9
+ describe('flattenTypeDefsOf', function () {
10
+ it('flattens', function () {
11
+ const listTypeDef = list(numberType)
12
+ const structTypeDef = object()
13
+ .field('a', listTypeDef)
14
+ .field('b', booleanType)
15
+ ._type
16
+ const flattened = flattenTypesOfType(
17
+ structTypeDef,
18
+ )
19
+
20
+ expect(flattened).toEqual({
21
+ $: structTypeDef,
22
+ '$.a': listTypeDef._type,
23
+ '$.a.*': numberType._type,
24
+ '$.b': booleanType._type,
25
+ })
26
+ })
27
+ })
@@ -0,0 +1,48 @@
1
+ import { flattenValidationErrorsOfType } from 'transformers/flatteners/flatten_validation_errors_of_type'
2
+ import { literal } from 'types/builders'
3
+ import { type ValueToTypePathsOfType } from 'types/value_to_type_paths_of_type'
4
+
5
+ describe('flattenValidationsOfType', function () {
6
+ describe('literal', function () {
7
+ const type = literal<'a' | 'b' | 'c'>()
8
+ describe('failures', function () {
9
+ const validators = {
10
+ $: () => 'error',
11
+ }
12
+
13
+ const errors = flattenValidationErrorsOfType<
14
+ typeof type,
15
+ ValueToTypePathsOfType<typeof type>,
16
+ typeof validators
17
+ >(
18
+ type,
19
+ 'a',
20
+ validators,
21
+ )
22
+
23
+ it('reports an error', function () {
24
+ expect(errors.$).toBe('error')
25
+ })
26
+ })
27
+
28
+ describe('success', function () {
29
+ const validators = {
30
+ $: () => null,
31
+ }
32
+
33
+ const errors = flattenValidationErrorsOfType<
34
+ typeof type,
35
+ ValueToTypePathsOfType<typeof type>,
36
+ typeof validators
37
+ >(
38
+ type,
39
+ 'a',
40
+ validators,
41
+ )
42
+
43
+ it('reports no error', function () {
44
+ expect(errors.$).toBe(null)
45
+ })
46
+ })
47
+ })
48
+ })
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  type AnyValueType,
3
- flattenValueTypeTo,
3
+ flattenValueTo,
4
4
  type Mapper,
5
5
  type Setter,
6
- } from 'transformers/flatteners/flatten_value_type_to'
6
+ } from 'transformers/flatteners/flatten_value_to'
7
7
  import { type SimplifyDeep } from 'type-fest'
8
8
  import {
9
9
  booleanType,
@@ -19,22 +19,22 @@ import {
19
19
  type Type,
20
20
  type TypeDef,
21
21
  } from 'types/definitions'
22
- import { type FlattenedTypeDefsOf } from 'types/flattened_type_defs_of'
23
- import { type ValueTypeOf } from 'types/value_type_of'
22
+ import { type FlattenedTypesOfType } from 'types/flattened_types_of_type'
23
+ import { type ValueOfType } from 'types/value_of_type'
24
24
  import {
25
25
  type Mock,
26
26
  vi,
27
27
  } from 'vitest'
28
28
 
29
29
  type FlattenedSetters<R extends Record<string, Type>> = {
30
- [K in keyof R]: Setter<ValueTypeOf<R[K]>>
30
+ [K in keyof R]: Setter<ValueOfType<R[K]>>
31
31
  }
32
32
 
33
33
  type FlattenedToStrings<R extends Record<string, Type>> = {
34
34
  [K in keyof R]: string
35
35
  }
36
36
 
37
- describe('flattenValueTypeTo', function () {
37
+ describe('flattenValueTo', function () {
38
38
  let toStringMapper: Mock<Mapper<string>>
39
39
  let setMapper: Mock<Mapper<(v: AnyValueType) => void>>
40
40
  let setter: Mock<(v: AnyValueType) => void>
@@ -49,13 +49,13 @@ describe('flattenValueTypeTo', function () {
49
49
  })
50
50
 
51
51
  describe('literal', function () {
52
- const typeDef = numberType
53
- type F = FlattenedTypeDefsOf<typeof typeDef, null>
52
+ const type = numberType
53
+ type F = FlattenedTypesOfType<typeof type, null>
54
54
  describe('toString', function () {
55
55
  let flattened: FlattenedToStrings<F>
56
56
  beforeEach(function () {
57
- flattened = flattenValueTypeTo(
58
- typeDef,
57
+ flattened = flattenValueTo(
58
+ type,
59
59
  1,
60
60
  setter,
61
61
  toStringMapper,
@@ -76,8 +76,8 @@ describe('flattenValueTypeTo', function () {
76
76
  describe('setter', function () {
77
77
  let flattened: FlattenedSetters<F>
78
78
  beforeEach(function () {
79
- flattened = flattenValueTypeTo(
80
- typeDef,
79
+ flattened = flattenValueTo(
80
+ type,
81
81
  1,
82
82
  setter,
83
83
  setMapper,
@@ -95,8 +95,8 @@ describe('flattenValueTypeTo', function () {
95
95
 
96
96
  describe('list', function () {
97
97
  const typeDef = list(numberType)
98
- type F = FlattenedTypeDefsOf<typeof typeDef, null>
99
- let l: ValueTypeOf<typeof typeDef>
98
+ type F = FlattenedTypesOfType<typeof typeDef, null>
99
+ let l: ValueOfType<typeof typeDef>
100
100
  beforeEach(function () {
101
101
  l = [
102
102
  1,
@@ -108,7 +108,7 @@ describe('flattenValueTypeTo', function () {
108
108
  describe('toString', function () {
109
109
  let flattened: FlattenedToStrings<F>
110
110
  beforeEach(function () {
111
- flattened = flattenValueTypeTo(
111
+ flattened = flattenValueTo(
112
112
  typeDef,
113
113
  l,
114
114
  setter,
@@ -133,7 +133,7 @@ describe('flattenValueTypeTo', function () {
133
133
  describe('setter', function () {
134
134
  let flattened: FlattenedSetters<F>
135
135
  beforeEach(function () {
136
- flattened = flattenValueTypeTo(
136
+ flattened = flattenValueTo(
137
137
  typeDef,
138
138
  l,
139
139
  setter,
@@ -154,9 +154,9 @@ describe('flattenValueTypeTo', function () {
154
154
 
155
155
  describe('record', function () {
156
156
  const typeDef = record<typeof numberType, 'a' | 'b'>(numberType)
157
- type F = FlattenedTypeDefsOf<typeof typeDef, null>
157
+ type F = FlattenedTypesOfType<typeof typeDef, null>
158
158
 
159
- let m: ValueTypeOf<typeof typeDef>
159
+ let m: ValueOfType<typeof typeDef>
160
160
  beforeEach(function () {
161
161
  m = {
162
162
  a: 1,
@@ -167,7 +167,7 @@ describe('flattenValueTypeTo', function () {
167
167
  describe('toString', function () {
168
168
  let flattened: FlattenedToStrings<F>
169
169
  beforeEach(function () {
170
- flattened = flattenValueTypeTo(
170
+ flattened = flattenValueTo(
171
171
  typeDef,
172
172
  m,
173
173
  setter,
@@ -187,7 +187,7 @@ describe('flattenValueTypeTo', function () {
187
187
  describe('setter', function () {
188
188
  let flattened: FlattenedSetters<F>
189
189
  beforeEach(function () {
190
- flattened = flattenValueTypeTo(
190
+ flattened = flattenValueTo(
191
191
  typeDef,
192
192
  m,
193
193
  setter,
@@ -206,63 +206,96 @@ describe('flattenValueTypeTo', function () {
206
206
  })
207
207
 
208
208
  describe('object', function () {
209
- const typeDef = object()
210
- .set('a', numberType)
211
- .set('b', booleanType)
212
- type F = FlattenedTypeDefsOf<typeof typeDef, null>
209
+ describe('mandatory fields', function () {
210
+ const type = object()
211
+ .field('a', numberType)
212
+ .field('b', booleanType)
213
+ type F = FlattenedTypesOfType<typeof type, null>
213
214
 
214
- let s: ValueTypeOf<typeof typeDef>
215
- beforeEach(function () {
216
- s = {
217
- a: 1,
218
- b: false,
219
- }
220
- })
221
-
222
- describe('toString', function () {
223
- let flattened: FlattenedToStrings<F>
215
+ let s: ValueOfType<typeof type>
224
216
  beforeEach(function () {
225
- flattened = flattenValueTypeTo(
226
- typeDef,
227
- s,
228
- setter,
229
- toStringMapper,
230
- )
217
+ s = {
218
+ a: 1,
219
+ b: false,
220
+ }
231
221
  })
232
222
 
233
- it('equals expected type', function () {
234
- expect(flattened).toEqual({
235
- $: '{"a":1,"b":false}',
236
- ['$.a']: '1',
237
- ['$.b']: 'false',
223
+ describe('toString', function () {
224
+ let flattened: FlattenedToStrings<F>
225
+ beforeEach(function () {
226
+ flattened = flattenValueTo(
227
+ type,
228
+ s,
229
+ setter,
230
+ toStringMapper,
231
+ )
238
232
  })
239
- })
240
- })
241
233
 
242
- describe('setter', function () {
243
- let flattened: FlattenedSetters<F>
244
- beforeEach(function () {
245
- flattened = flattenValueTypeTo(
246
- typeDef,
247
- s,
248
- setter,
249
- setMapper,
250
- )
234
+ it('equals expected type', function () {
235
+ expect(flattened).toEqual({
236
+ $: '{"a":1,"b":false}',
237
+ ['$.a']: '1',
238
+ ['$.b']: 'false',
239
+ })
240
+ })
251
241
  })
252
242
 
253
- it('sets "a" in the object', function () {
254
- flattened['$.a'](2)
255
- expect(s).toEqual({
256
- a: 2,
257
- b: false,
243
+ describe('setter', function () {
244
+ let flattened: FlattenedSetters<F>
245
+ beforeEach(function () {
246
+ flattened = flattenValueTo(
247
+ type,
248
+ s,
249
+ setter,
250
+ setMapper,
251
+ )
252
+ })
253
+
254
+ it('sets "a" in the object', function () {
255
+ flattened['$.a'](2)
256
+ expect(s).toEqual({
257
+ a: 2,
258
+ b: false,
259
+ })
260
+ })
261
+
262
+ it('sets "b" in the object', function () {
263
+ flattened['$.b'](true)
264
+ expect(s).toEqual({
265
+ a: 1,
266
+ b: true,
267
+ })
258
268
  })
259
269
  })
270
+ })
260
271
 
261
- it('sets "b" in the object', function () {
262
- flattened['$.b'](true)
263
- expect(s).toEqual({
264
- a: 1,
265
- b: true,
272
+ describe('nested optional field', function () {
273
+ const type = object()
274
+ .optionalField('a', object().optionalField('b', numberType))
275
+ type F = FlattenedTypesOfType<typeof type, null>
276
+
277
+ describe('empty', function () {
278
+ let s: ValueOfType<typeof type>
279
+ beforeEach(function () {
280
+ s = {}
281
+ })
282
+
283
+ describe('toString', function () {
284
+ let flattened: FlattenedToStrings<F>
285
+ beforeEach(function () {
286
+ flattened = flattenValueTo(
287
+ type,
288
+ s,
289
+ setter,
290
+ toStringMapper,
291
+ )
292
+ })
293
+
294
+ it('equals expected type', function () {
295
+ expect(flattened).toEqual({
296
+ $: '{}',
297
+ })
298
+ })
266
299
  })
267
300
  })
268
301
  })
@@ -271,10 +304,10 @@ describe('flattenValueTypeTo', function () {
271
304
  describe('union', function () {
272
305
  describe('discriminated', function () {
273
306
  const typeDef = union('d')
274
- .add('1', object().set('a', numberType))
275
- .add('2', object().set('b', booleanType))
276
- type F = SimplifyDeep<FlattenedTypeDefsOf<typeof typeDef, null>>
277
- let u: ValueTypeOf<typeof typeDef>
307
+ .or('1', object().field('a', numberType))
308
+ .or('2', object().field('b', booleanType))
309
+ type F = SimplifyDeep<FlattenedTypesOfType<typeof typeDef, null>>
310
+ let u: ValueOfType<typeof typeDef>
278
311
  beforeEach(function () {
279
312
  u = {
280
313
  d: '1',
@@ -285,7 +318,7 @@ describe('flattenValueTypeTo', function () {
285
318
  describe('toString', function () {
286
319
  let flattened: FlattenedToStrings<F>
287
320
  beforeEach(function () {
288
- flattened = flattenValueTypeTo(
321
+ flattened = flattenValueTo(
289
322
  typeDef,
290
323
  u,
291
324
  setter,
@@ -305,7 +338,7 @@ describe('flattenValueTypeTo', function () {
305
338
  type G = SimplifyDeep<FlattenedSetters<F>>
306
339
  let flattened: G
307
340
  beforeEach(function () {
308
- flattened = flattenValueTypeTo(
341
+ flattened = flattenValueTo(
309
342
  typeDef,
310
343
  u,
311
344
  setter,
@@ -334,11 +367,11 @@ describe('flattenValueTypeTo', function () {
334
367
  })
335
368
  })
336
369
  describe('non-discriminated', function () {
337
- const typeDef = union()
338
- .add('0', numberType)
339
- .add('1', nullType)
340
- type F = FlattenedTypeDefsOf<typeof typeDef, null>
341
- let u: ValueTypeOf<typeof typeDef>
370
+ const type = union()
371
+ .or('0', numberType)
372
+ .or('1', nullType)
373
+ type F = FlattenedTypesOfType<typeof type, null>
374
+ let u: ValueOfType<typeof type>
342
375
 
343
376
  beforeEach(function () {
344
377
  u = null
@@ -347,8 +380,8 @@ describe('flattenValueTypeTo', function () {
347
380
  describe('toString', function () {
348
381
  let flattened: FlattenedToStrings<F>
349
382
  beforeEach(function () {
350
- flattened = flattenValueTypeTo(
351
- typeDef,
383
+ flattened = flattenValueTo(
384
+ type,
352
385
  u,
353
386
  setter,
354
387
  toStringMapper,
@@ -365,8 +398,8 @@ describe('flattenValueTypeTo', function () {
365
398
  describe('setter', function () {
366
399
  let flattened: FlattenedSetters<F>
367
400
  beforeEach(function () {
368
- flattened = flattenValueTypeTo(
369
- typeDef,
401
+ flattened = flattenValueTo(
402
+ type,
370
403
  u,
371
404
  setter,
372
405
  setMapper,
@@ -383,13 +416,13 @@ describe('flattenValueTypeTo', function () {
383
416
  })
384
417
 
385
418
  describe('complex non-discriminated', function () {
386
- const typeDef = union()
387
- .add('z', list(numberType))
388
- .add('x', nullType)
389
- .add('y', literal([false]))
390
- type F = FlattenedTypeDefsOf<typeof typeDef, null>
419
+ const type = union()
420
+ .or('z', list(numberType))
421
+ .or('x', nullType)
422
+ .or('y', literal([false]))
423
+ type F = FlattenedTypesOfType<typeof type, null>
391
424
 
392
- let u: ValueTypeOf<typeof typeDef>
425
+ let u: ValueOfType<typeof type>
393
426
  beforeEach(function () {
394
427
  u = [
395
428
  1,
@@ -401,8 +434,8 @@ describe('flattenValueTypeTo', function () {
401
434
  describe('toString', function () {
402
435
  let flattened: FlattenedToStrings<F>
403
436
  beforeEach(function () {
404
- flattened = flattenValueTypeTo(
405
- typeDef,
437
+ flattened = flattenValueTo(
438
+ type,
406
439
  u,
407
440
  setter,
408
441
  toStringMapper,
@@ -422,8 +455,8 @@ describe('flattenValueTypeTo', function () {
422
455
  describe('setter', function () {
423
456
  let flattened: FlattenedSetters<F>
424
457
  beforeEach(function () {
425
- flattened = flattenValueTypeTo(
426
- typeDef,
458
+ flattened = flattenValueTo(
459
+ type,
427
460
  u,
428
461
  setter,
429
462
  setMapper,
@@ -1,4 +1,4 @@
1
- import { flattenValueTypesOf } from 'transformers/flatteners/flatten_value_types_of'
1
+ import { flattenValuesOfType } from 'transformers/flatteners/flatten_values_of_type'
2
2
  import {
3
3
  booleanType,
4
4
  list,
@@ -10,10 +10,10 @@ describe('flattenValueTypesOf', function () {
10
10
  // note that we already have tests for the type and the function that this calls, so
11
11
  // this is only a sanity check
12
12
  it('flattens', function () {
13
- const flattened = flattenValueTypesOf(
13
+ const flattened = flattenValuesOfType(
14
14
  object()
15
- .set('a', list(numberType))
16
- .set('b', booleanType),
15
+ .field('a', list(numberType))
16
+ .field('b', booleanType),
17
17
  {
18
18
  a: [
19
19
  1,
@@ -8,14 +8,14 @@ import {
8
8
  stringType,
9
9
  union,
10
10
  } from 'types/builders'
11
- import { type ValueToTypePathsOf } from 'types/value_to_type_paths_of'
11
+ import { type ValueToTypePathsOfType } from 'types/value_to_type_paths_of_type'
12
12
 
13
13
  describe('valuePathToTypePath', function () {
14
14
  describe('literal', function () {
15
15
  const typeDef = numberType
16
- type JsonPaths = ValueToTypePathsOf<typeof typeDef>
16
+ type Paths = ValueToTypePathsOfType<typeof typeDef>
17
17
 
18
- const typePath = valuePathToTypePath<JsonPaths, '$'>(typeDef, '$')
18
+ const typePath = valuePathToTypePath<Paths, '$'>(typeDef, '$')
19
19
 
20
20
  it('maps a value path to the expected type path', function () {
21
21
  expect(typePath).toEqual('$')
@@ -42,7 +42,7 @@ describe('valuePathToTypePath', function () {
42
42
 
43
43
  describe('list', function () {
44
44
  const typeDef = list(numberType)
45
- type JsonPaths = ValueToTypePathsOf<typeof typeDef>
45
+ type Paths = ValueToTypePathsOfType<typeof typeDef>
46
46
 
47
47
  describe.each([
48
48
  [
@@ -54,7 +54,7 @@ describe('valuePathToTypePath', function () {
54
54
  '$.*',
55
55
  ],
56
56
  ] as const)('it maps "%s"', function (from, to) {
57
- const typePath = valuePathToTypePath<JsonPaths, typeof from>(typeDef, from)
57
+ const typePath = valuePathToTypePath<Paths, typeof from>(typeDef, from)
58
58
 
59
59
  it('maps a value path to the expected type path', function () {
60
60
  expect(typePath).toEqual(to)
@@ -67,7 +67,7 @@ describe('valuePathToTypePath', function () {
67
67
 
68
68
  describe('fake subpath', function () {
69
69
  const fakeTypePath = valuePathToTypePath<
70
- JsonPaths & {
70
+ Paths & {
71
71
  [_: `$.${number}.fake`]: '$.*.fake',
72
72
  },
73
73
  '$.0.fake'
@@ -86,7 +86,7 @@ describe('valuePathToTypePath', function () {
86
86
  describe('record', function () {
87
87
  type Key = 'a' | 'b'
88
88
  const typeDef = record<typeof numberType, Key>(numberType)
89
- type JsonPaths = ValueToTypePathsOf<typeof typeDef>
89
+ type Paths = ValueToTypePathsOfType<typeof typeDef>
90
90
 
91
91
  describe.each([
92
92
  [
@@ -102,7 +102,7 @@ describe('valuePathToTypePath', function () {
102
102
  '$.*',
103
103
  ],
104
104
  ] as const)('it maps "%s"', function (from, to) {
105
- const typePath = valuePathToTypePath<JsonPaths, typeof from>(typeDef, from)
105
+ const typePath = valuePathToTypePath<Paths, typeof from>(typeDef, from)
106
106
 
107
107
  it('maps a value path to the expected type path', function () {
108
108
  expect(typePath).toEqual(to)
@@ -115,7 +115,7 @@ describe('valuePathToTypePath', function () {
115
115
 
116
116
  describe('fake subpath', function () {
117
117
  const fakeTypePath = valuePathToTypePath<
118
- JsonPaths & {
118
+ Paths & {
119
119
  '$.a.fake': '$.*.fake',
120
120
  '$.b.fake': '$.*.fake',
121
121
  },
@@ -133,8 +133,10 @@ describe('valuePathToTypePath', function () {
133
133
  })
134
134
 
135
135
  describe('object', function () {
136
- const typeDef = object().set('a', numberType).set('b', booleanType)
137
- type JsonPaths = ValueToTypePathsOf<typeof typeDef>
136
+ const typeDef = object()
137
+ .field('a', numberType)
138
+ .field('b', booleanType)
139
+ type Paths = ValueToTypePathsOfType<typeof typeDef>
138
140
 
139
141
  describe.each([
140
142
  [
@@ -150,7 +152,7 @@ describe('valuePathToTypePath', function () {
150
152
  '$.b',
151
153
  ],
152
154
  ] as const)('it maps %s', function (from, to) {
153
- const typePath = valuePathToTypePath<JsonPaths, typeof from>(typeDef, from)
155
+ const typePath = valuePathToTypePath<Paths, typeof from>(typeDef, from)
154
156
 
155
157
  it('maps a value path to the expected type path', function () {
156
158
  expect(typePath).toEqual(to)
@@ -163,7 +165,7 @@ describe('valuePathToTypePath', function () {
163
165
 
164
166
  describe('fake field', function () {
165
167
  const fakeTypePath = valuePathToTypePath<
166
- JsonPaths & {
168
+ Paths & {
167
169
  '$.fake': '$.fake',
168
170
  },
169
171
  '$.fake'
@@ -182,9 +184,9 @@ describe('valuePathToTypePath', function () {
182
184
  describe('union', function () {
183
185
  describe('discriminated', function () {
184
186
  const typeDef = union('w')
185
- .add('x', object().set('a', numberType).set('b', booleanType))
186
- .add('y', object().set('b', stringType).set('c', booleanType))
187
- type JsonPaths = ValueToTypePathsOf<typeof typeDef>
187
+ .or('x', object().field('a', numberType).field('b', booleanType))
188
+ .or('y', object().field('b', stringType).field('c', booleanType))
189
+ type Paths = ValueToTypePathsOfType<typeof typeDef>
188
190
 
189
191
  describe.each([
190
192
  [
@@ -208,7 +210,7 @@ describe('valuePathToTypePath', function () {
208
210
  '$.y:c',
209
211
  ],
210
212
  ] as const)('it maps %s', function (from, to) {
211
- const typePath = valuePathToTypePath<JsonPaths, typeof from>(typeDef, from)
213
+ const typePath = valuePathToTypePath<Paths, typeof from>(typeDef, from)
212
214
 
213
215
  it('maps a value path to the expected type path', function () {
214
216
  expect(typePath).toEqual(to)
@@ -221,7 +223,7 @@ describe('valuePathToTypePath', function () {
221
223
 
222
224
  describe('fake', function () {
223
225
  const fakeTypePath = valuePathToTypePath<
224
- JsonPaths & {
226
+ Paths & {
225
227
  '$.fake': '$.fake',
226
228
  },
227
229
  '$.fake'