@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
@@ -9,24 +9,38 @@ import {
9
9
  union,
10
10
  } from 'types/builders'
11
11
  import {
12
- type TypeDefType,
12
+ TypeDefType,
13
13
  } from 'types/definitions'
14
+ import { type Rule } from 'types/validating_definitions'
14
15
 
15
16
  describe('builder', function () {
16
17
  describe('literal', function () {
17
- const { definition: typeDef } = numberType
18
+ const { definition } = numberType
18
19
 
19
20
  it('equals expected type', function () {
20
21
  type C = {
21
22
  readonly type: TypeDefType.Literal,
22
23
  readonly valuePrototype: [number],
24
+ readonly rule: Rule<never>,
25
+ readonly required: boolean,
26
+ readonly readonly: boolean,
23
27
  }
24
28
 
25
- expectTypeOf(typeDef).toEqualTypeOf<C>()
29
+ expectTypeOf(definition).toEqualTypeOf<C>()
30
+ })
31
+
32
+ it('equals expected value', function () {
33
+ expect(definition).toEqual({
34
+ type: TypeDefType.Literal,
35
+ valuePrototype: undefined,
36
+ rule: expect.anything(),
37
+ required: false,
38
+ readonly: false,
39
+ })
26
40
  })
27
41
 
28
42
  describe('nullable', function () {
29
- const { definition: typeDef } = nullable(numberType)
43
+ const { definition } = nullable(numberType)
30
44
 
31
45
  type C = {
32
46
  readonly type: TypeDefType.Union,
@@ -35,15 +49,67 @@ describe('builder', function () {
35
49
  readonly [0]: {
36
50
  readonly type: TypeDefType.Literal,
37
51
  readonly valuePrototype: [number],
52
+ readonly rule: Rule<never>,
53
+ readonly required: boolean,
54
+ readonly readonly: boolean,
38
55
  },
39
56
  readonly [1]: {
40
57
  readonly type: TypeDefType.Literal,
41
58
  readonly valuePrototype: [null],
59
+ readonly rule: Rule<never>,
60
+ readonly required: boolean,
61
+ readonly readonly: boolean,
42
62
  },
43
63
  },
64
+ readonly rule: Rule<never>,
65
+ readonly required: boolean,
66
+ readonly readonly: boolean,
44
67
  }
68
+
45
69
  it('equals expected type', function () {
46
- expectTypeOf(typeDef).toEqualTypeOf<C>()
70
+ expectTypeOf(definition).toEqualTypeOf<C>()
71
+ })
72
+ })
73
+
74
+ describe('required', function () {
75
+ const { definition } = numberType.required()
76
+
77
+ it('equals expected value', function () {
78
+ expect(definition).toEqual({
79
+ type: TypeDefType.Literal,
80
+ valuePrototype: undefined,
81
+ rule: expect.anything(),
82
+ required: true,
83
+ readonly: false,
84
+ })
85
+ })
86
+ })
87
+
88
+ describe('readonly', function () {
89
+ const { definition } = numberType.readonly()
90
+
91
+ it('equals expected value', function () {
92
+ expect(definition).toEqual({
93
+ type: TypeDefType.Literal,
94
+ valuePrototype: undefined,
95
+ rule: expect.anything(),
96
+ required: false,
97
+ readonly: true,
98
+ })
99
+ })
100
+ })
101
+
102
+ describe('readonly & required', function () {
103
+ const { definition } = numberType.readonly().required()
104
+
105
+ it('equals expected value', function () {
106
+ expect(definition).toEqual({
107
+ type: TypeDefType.Literal,
108
+ valuePrototype: undefined,
109
+ rule: expect.anything(),
110
+ required: true,
111
+ readonly: true,
112
+ })
47
113
  })
48
114
  })
49
115
  })
@@ -59,15 +125,21 @@ describe('builder', function () {
59
125
  elements: {
60
126
  readonly type: TypeDefType.Literal,
61
127
  readonly valuePrototype: [number],
128
+ readonly rule: Rule<never>,
129
+ readonly required: boolean,
130
+ readonly readonly: boolean,
62
131
  },
132
+ readonly rule: Rule<never>,
133
+ readonly required: boolean,
134
+ readonly readonly: boolean,
63
135
  }
64
136
  expectTypeOf(typeDef).toEqualTypeOf<C>()
65
137
  })
66
138
  })
67
139
  })
68
140
 
69
- describe('readonly', function () {
70
- const { definition: typeDef } = list(numberType).readonly()
141
+ describe('readonlyElements', function () {
142
+ const { definition: typeDef } = list(numberType).readonlyElements()
71
143
 
72
144
  it('equals expected type', function () {
73
145
  type C = {
@@ -75,7 +147,13 @@ describe('builder', function () {
75
147
  readonly elements: {
76
148
  readonly type: TypeDefType.Literal,
77
149
  readonly valuePrototype: [number],
150
+ readonly rule: Rule<never>,
151
+ readonly required: boolean,
152
+ readonly readonly: boolean,
78
153
  },
154
+ readonly rule: Rule<never>,
155
+ readonly required: boolean,
156
+ readonly readonly: boolean,
79
157
  }
80
158
 
81
159
  expectTypeOf(typeDef).toEqualTypeOf<C>()
@@ -95,7 +173,13 @@ describe('builder', function () {
95
173
  valueTypeDef: {
96
174
  readonly type: TypeDefType.Literal,
97
175
  readonly valuePrototype: [number],
176
+ readonly rule: Rule<never>,
177
+ readonly required: boolean,
178
+ readonly readonly: boolean,
98
179
  },
180
+ readonly rule: Rule<never>,
181
+ readonly required: boolean,
182
+ readonly readonly: boolean,
99
183
  }
100
184
 
101
185
  expectTypeOf(typeDef).toEqualTypeOf<C>()
@@ -103,7 +187,7 @@ describe('builder', function () {
103
187
  })
104
188
 
105
189
  describe('readonly', function () {
106
- const { definition: typeDef } = record<typeof numberType, 'a' | 'b' | 'c'>(numberType).readonly()
190
+ const { definition: typeDef } = record<typeof numberType, 'a' | 'b' | 'c'>(numberType).readonlyKeys()
107
191
 
108
192
  it('equals expected type', function () {
109
193
  type C = {
@@ -112,14 +196,20 @@ describe('builder', function () {
112
196
  readonly valueTypeDef: {
113
197
  readonly type: TypeDefType.Literal,
114
198
  readonly valuePrototype: [number],
199
+ readonly rule: Rule<never>,
200
+ readonly required: boolean,
201
+ readonly readonly: boolean,
115
202
  },
203
+ readonly rule: Rule<never>,
204
+ readonly required: boolean,
205
+ readonly readonly: boolean,
116
206
  }
117
207
  expectTypeOf(typeDef).toEqualTypeOf<C>()
118
208
  })
119
209
  })
120
210
 
121
211
  describe('partial', function () {
122
- const { definition: typeDef } = record<typeof numberType, 'a' | 'b' | 'c'>(numberType).partial()
212
+ const { definition: typeDef } = record<typeof numberType, 'a' | 'b' | 'c'>(numberType).partialKeys()
123
213
 
124
214
  it('equals expected type', function () {
125
215
  type C = {
@@ -128,14 +218,21 @@ describe('builder', function () {
128
218
  valueTypeDef: {
129
219
  readonly type: TypeDefType.Literal,
130
220
  readonly valuePrototype: [number],
221
+ readonly rule: Rule<never>,
222
+ readonly required: boolean,
223
+ readonly readonly: boolean,
131
224
  } | undefined,
225
+ readonly rule: Rule<never>,
226
+ readonly required: boolean,
227
+ readonly readonly: boolean,
132
228
  }
133
229
  expectTypeOf(typeDef).toEqualTypeOf<C>()
134
230
  })
135
231
  })
136
232
 
137
- describe('partial readonly', function () {
138
- const { definition: typeDef } = record<typeof numberType, 'a' | 'b' | 'c'>(numberType).partial().readonly()
233
+ describe('partial and readonly', function () {
234
+ const { definition: typeDef } = record<typeof numberType, 'a' | 'b' | 'c'>(numberType).partialKeys()
235
+ .readonlyKeys()
139
236
 
140
237
  it('equals expected type', function () {
141
238
  type C = {
@@ -144,15 +241,22 @@ describe('builder', function () {
144
241
  readonly valueTypeDef: {
145
242
  readonly type: TypeDefType.Literal,
146
243
  readonly valuePrototype: [number],
244
+ readonly rule: Rule<never>,
245
+ readonly required: boolean,
246
+ readonly readonly: boolean,
147
247
  } | undefined,
248
+ readonly rule: Rule<never>,
249
+ readonly required: boolean,
250
+ readonly readonly: boolean,
148
251
  }
149
252
 
150
253
  expectTypeOf(typeDef).toEqualTypeOf<C>()
151
254
  })
152
255
  })
153
256
 
154
- describe('readonly partial', function () {
155
- const { definition: typeDef } = record<typeof numberType, 'a' | 'b' | 'c'>(numberType).readonly().partial()
257
+ describe('readonly and partial', function () {
258
+ const { definition: typeDef } = record<typeof numberType, 'a' | 'b' | 'c'>(numberType).readonlyKeys()
259
+ .partialKeys()
156
260
 
157
261
  it('equals expected type', function () {
158
262
  type C = {
@@ -161,7 +265,13 @@ describe('builder', function () {
161
265
  readonly valueTypeDef: {
162
266
  readonly type: TypeDefType.Literal,
163
267
  readonly valuePrototype: [number],
268
+ readonly rule: Rule<never>,
269
+ readonly required: boolean,
270
+ readonly readonly: boolean,
164
271
  } | undefined,
272
+ readonly rule: Rule<never>,
273
+ readonly required: boolean,
274
+ readonly readonly: boolean,
165
275
  }
166
276
 
167
277
  expectTypeOf(typeDef).toEqualTypeOf<C>()
@@ -172,10 +282,10 @@ describe('builder', function () {
172
282
 
173
283
  describe('object', function () {
174
284
  const { definition: typeDef } = object()
175
- .set('a', numberType)
176
- .setReadonly('b', booleanType)
177
- .setOptional('c', stringType)
178
- .setReadonlyOptional('d', numberType)
285
+ .field('a', numberType)
286
+ .readonlyField('b', booleanType)
287
+ .optionalField('c', stringType)
288
+ .readonlyOptionalField('d', numberType)
179
289
 
180
290
  it('equals expected type', function () {
181
291
  type C = {
@@ -185,26 +295,41 @@ describe('builder', function () {
185
295
  a: {
186
296
  readonly type: TypeDefType.Literal,
187
297
  readonly valuePrototype: [number],
298
+ readonly rule: Rule<never>,
299
+ readonly required: boolean,
300
+ readonly readonly: boolean,
188
301
  },
189
302
  }
190
303
  & {
191
304
  readonly b: {
192
305
  readonly type: TypeDefType.Literal,
193
306
  readonly valuePrototype: [boolean],
307
+ readonly rule: Rule<never>,
308
+ readonly required: boolean,
309
+ readonly readonly: boolean,
194
310
  },
195
311
  }
196
312
  & {
197
313
  c?: {
198
314
  readonly type: TypeDefType.Literal,
199
315
  readonly valuePrototype: [string],
316
+ readonly rule: Rule<never>,
317
+ readonly required: boolean,
318
+ readonly readonly: boolean,
200
319
  },
201
320
  }
202
321
  & {
203
322
  readonly d?: {
204
323
  readonly type: TypeDefType.Literal,
205
324
  readonly valuePrototype: [number],
325
+ readonly rule: Rule<never>,
326
+ readonly required: boolean,
327
+ readonly readonly: boolean,
206
328
  },
207
329
  },
330
+ readonly rule: Rule<never>,
331
+ readonly required: boolean,
332
+ readonly readonly: boolean,
208
333
  }
209
334
 
210
335
  expectTypeOf(typeDef).toEqualTypeOf<C>()
@@ -216,11 +341,11 @@ describe('builder', function () {
216
341
  const {
217
342
  definition: typeDef,
218
343
  } = union()
219
- .add(
344
+ .or(
220
345
  '1',
221
346
  numberType,
222
347
  )
223
- .add(
348
+ .or(
224
349
  '2',
225
350
  stringType,
226
351
  )
@@ -234,61 +359,87 @@ describe('builder', function () {
234
359
  readonly [1]: {
235
360
  readonly type: TypeDefType.Literal,
236
361
  readonly valuePrototype: [number],
362
+ readonly rule: Rule<never>,
363
+ readonly required: boolean,
364
+ readonly readonly: boolean,
237
365
  },
238
366
  }
239
367
  & {
240
368
  readonly [2]: {
241
369
  readonly type: TypeDefType.Literal,
242
370
  readonly valuePrototype: [string],
371
+ readonly rule: Rule<never>,
372
+ readonly required: boolean,
373
+ readonly readonly: boolean,
243
374
  },
244
375
  },
376
+ readonly rule: Rule<never>,
377
+ readonly required: boolean,
378
+ readonly readonly: boolean,
245
379
  }
246
380
  expectTypeOf(typeDef).toEqualTypeOf<C>()
247
381
  })
248
382
  })
249
383
 
250
384
  describe('objects', function () {
251
- const {
252
- definition: typeDef,
253
- } = union()
254
- .add(
255
- '1',
256
- object().set('a', booleanType),
257
- )
258
- .add(
259
- '2',
260
- object().set('b', numberType),
261
- )
385
+ describe('mutable', function () {
386
+ const {
387
+ definition: typeDef,
388
+ } = union()
389
+ .or(
390
+ '1',
391
+ object().field('a', booleanType),
392
+ )
393
+ .or(
394
+ '2',
395
+ object().field('b', numberType),
396
+ )
262
397
 
263
- it('equals expected type', function () {
264
- type C = {
265
- readonly type: TypeDefType.Union,
266
- readonly discriminator: null,
267
- readonly unions:
268
- & {
269
- readonly [1]: {
270
- readonly type: TypeDefType.Object,
271
- readonly fields: {
272
- a: {
273
- readonly type: TypeDefType.Literal,
274
- readonly valuePrototype: [boolean],
398
+ it('equals expected type', function () {
399
+ type C = {
400
+ readonly type: TypeDefType.Union,
401
+ readonly discriminator: null,
402
+ readonly unions:
403
+ & {
404
+ readonly [1]: {
405
+ readonly type: TypeDefType.Object,
406
+ readonly fields: {
407
+ a: {
408
+ readonly type: TypeDefType.Literal,
409
+ readonly valuePrototype: [boolean],
410
+ readonly rule: Rule<never>,
411
+ readonly required: boolean,
412
+ readonly readonly: boolean,
413
+ },
275
414
  },
415
+ readonly rule: Rule<never>,
416
+ readonly required: boolean,
417
+ readonly readonly: boolean,
276
418
  },
277
- },
278
- }
279
- & {
280
- readonly [2]: {
281
- readonly type: TypeDefType.Object,
282
- readonly fields: {
283
- b: {
284
- readonly type: TypeDefType.Literal,
285
- readonly valuePrototype: [number],
419
+ }
420
+ & {
421
+ readonly [2]: {
422
+ readonly type: TypeDefType.Object,
423
+ readonly fields: {
424
+ b: {
425
+ readonly type: TypeDefType.Literal,
426
+ readonly valuePrototype: [number],
427
+ readonly rule: Rule<never>,
428
+ readonly required: boolean,
429
+ readonly readonly: boolean,
430
+ },
286
431
  },
432
+ readonly rule: Rule<never>,
433
+ readonly required: boolean,
434
+ readonly readonly: boolean,
287
435
  },
288
436
  },
289
- },
290
- }
291
- expectTypeOf(typeDef).toEqualTypeOf<C>()
437
+ readonly rule: Rule<never>,
438
+ readonly required: boolean,
439
+ readonly readonly: boolean,
440
+ }
441
+ expectTypeOf(typeDef).toEqualTypeOf<C>()
442
+ })
292
443
  })
293
444
  })
294
445
  })
@@ -2,13 +2,13 @@ import {
2
2
  numberType,
3
3
  record,
4
4
  } from 'types/builders'
5
- import { type FlattenedAccessorsOf } from 'types/flattened_accessors_of'
5
+ import { type FlattenedAccessorsOfType } from 'types/flattened_accessors_of_type'
6
6
 
7
- describe('FlattenedAccessorsOf', function () {
7
+ describe('FlattenedAccessorsOfType', function () {
8
8
  // note we only test a small example since most of the work is done in flatten
9
9
  describe('record', function () {
10
10
  const builder = record<typeof numberType, string>(numberType)
11
- type V = FlattenedAccessorsOf<typeof builder>
11
+ type V = FlattenedAccessorsOfType<typeof builder>
12
12
 
13
13
  let v: {
14
14
  readonly $: {
@@ -9,11 +9,11 @@ import {
9
9
  union,
10
10
  } from 'types/builders'
11
11
  import { type TypeDefType } from 'types/definitions'
12
- import { type FlattenedTypeDefsOf } from 'types/flattened_type_defs_of'
12
+ import { type FlattenedTypesOfType } from 'types/flattened_types_of_type'
13
13
 
14
- describe('FlattenedTypeDefsOf', function () {
14
+ describe('FlattenedTypesOfType', function () {
15
15
  describe('literal', function () {
16
- type T = FlattenedTypeDefsOf<typeof numberType, null>
16
+ type T = FlattenedTypesOfType<typeof numberType._type, null>
17
17
 
18
18
  let t: {
19
19
  readonly $: {
@@ -30,10 +30,10 @@ describe('FlattenedTypeDefsOf', function () {
30
30
 
31
31
  describe('list', function () {
32
32
  const builder = list(numberType)
33
- type T = SimplifyDeep<FlattenedTypeDefsOf<typeof builder, '*'>>
33
+ type T = SimplifyDeep<FlattenedTypesOfType<typeof builder._type, '*'>>
34
34
 
35
35
  let t: {
36
- readonly $: SimplifyDeep<typeof builder.narrow>,
36
+ readonly $: SimplifyDeep<typeof builder._type>,
37
37
  readonly ['$.*']: {
38
38
  readonly definition: {
39
39
  readonly type: TypeDefType.Literal,
@@ -48,10 +48,10 @@ describe('FlattenedTypeDefsOf', function () {
48
48
 
49
49
  describe('record', function () {
50
50
  const builder = record<typeof numberType, 'a' | 'b'>(numberType)
51
- type T = SimplifyDeep<FlattenedTypeDefsOf<typeof builder, '*'>>
51
+ type T = SimplifyDeep<FlattenedTypesOfType<typeof builder._type, '*'>>
52
52
 
53
53
  let t: {
54
- readonly $: SimplifyDeep<typeof builder.narrow>,
54
+ readonly $: SimplifyDeep<typeof builder._type>,
55
55
  readonly ['$.*']: {
56
56
  readonly definition: {
57
57
  readonly type: TypeDefType.Literal,
@@ -67,14 +67,13 @@ describe('FlattenedTypeDefsOf', function () {
67
67
  describe('object', function () {
68
68
  describe('simple', function () {
69
69
  const builder = object()
70
- .set('a', numberType)
71
- .setOptional('b', stringType)
72
- .setReadonly('c', booleanType)
73
- .setReadonlyOptional('d', stringType)
74
- type T = SimplifyDeep<FlattenedTypeDefsOf<typeof builder, null>>
75
-
70
+ .field('a', numberType)
71
+ .optionalField('b', stringType)
72
+ .readonlyField('c', booleanType)
73
+ .readonlyOptionalField('d', stringType)
74
+ type T = SimplifyDeep<FlattenedTypesOfType<typeof builder._type, null>>
76
75
  let t: {
77
- readonly $: SimplifyDeep<typeof builder.narrow>,
76
+ readonly $: SimplifyDeep<typeof builder._type>,
78
77
  readonly ['$.a']: {
79
78
  readonly definition: {
80
79
  readonly type: TypeDefType.Literal,
@@ -83,8 +82,18 @@ describe('FlattenedTypeDefsOf', function () {
83
82
  },
84
83
  readonly ['$.b']: {
85
84
  readonly definition: {
86
- readonly type: TypeDefType.Literal,
87
- readonly valuePrototype: [string],
85
+ readonly discriminator: null,
86
+ readonly type: TypeDefType.Union,
87
+ readonly unions: {
88
+ readonly '0': {
89
+ readonly type: TypeDefType.Literal,
90
+ readonly valuePrototype: [string],
91
+ },
92
+ readonly '1': {
93
+ readonly type: TypeDefType.Literal,
94
+ readonly valuePrototype: [undefined],
95
+ },
96
+ },
88
97
  },
89
98
  },
90
99
  readonly ['$.c']: {
@@ -95,8 +104,18 @@ describe('FlattenedTypeDefsOf', function () {
95
104
  },
96
105
  readonly ['$.d']: {
97
106
  readonly definition: {
98
- readonly type: TypeDefType.Literal,
99
- readonly valuePrototype: [string],
107
+ readonly discriminator: null,
108
+ readonly type: TypeDefType.Union,
109
+ readonly unions: {
110
+ readonly '0': {
111
+ readonly type: TypeDefType.Literal,
112
+ readonly valuePrototype: [string],
113
+ },
114
+ readonly '1': {
115
+ readonly type: TypeDefType.Literal,
116
+ readonly valuePrototype: [undefined],
117
+ },
118
+ },
100
119
  },
101
120
  },
102
121
  }
@@ -104,6 +123,35 @@ describe('FlattenedTypeDefsOf', function () {
104
123
  expectTypeOf(t).toEqualTypeOf<T>()
105
124
  })
106
125
  })
126
+
127
+ describe('optional', function () {
128
+ const builder = object().optionalField('a', stringType)
129
+ type T = SimplifyDeep<FlattenedTypesOfType<typeof builder._type, null>>
130
+
131
+ let t: {
132
+ readonly $: SimplifyDeep<typeof builder._type>,
133
+ readonly '$.a': {
134
+ readonly definition: {
135
+ readonly discriminator: null,
136
+ readonly type: TypeDefType.Union,
137
+ readonly unions: {
138
+ readonly '0': {
139
+ readonly type: TypeDefType.Literal,
140
+ readonly valuePrototype: [string],
141
+ },
142
+ readonly '1': {
143
+ readonly type: TypeDefType.Literal,
144
+ readonly valuePrototype: [undefined],
145
+ },
146
+ },
147
+ },
148
+ },
149
+ }
150
+
151
+ it('equals expected type', function () {
152
+ expectTypeOf(t).toEqualTypeOf<T>()
153
+ })
154
+ })
107
155
  })
108
156
  })
109
157
 
@@ -111,12 +159,12 @@ describe('union', function () {
111
159
  describe('overlapping', function () {
112
160
  describe('non-discriminated', function () {
113
161
  const builder = union()
114
- .add('x', object().set('a', booleanType))
115
- .add('y', object().set('b', numberType))
116
- type T = SimplifyDeep<FlattenedTypeDefsOf<typeof builder, null>>
162
+ .or('x', object().field('a', booleanType))
163
+ .or('y', object().field('b', numberType))
164
+ type T = SimplifyDeep<FlattenedTypesOfType<typeof builder._type, null>>
117
165
 
118
166
  let t: {
119
- readonly $: SimplifyDeep<typeof builder.narrow>,
167
+ readonly $: SimplifyDeep<typeof builder._type>,
120
168
  readonly ['$.a']: {
121
169
  readonly definition: {
122
170
  readonly type: TypeDefType.Literal,
@@ -138,12 +186,12 @@ describe('union', function () {
138
186
 
139
187
  describe('discriminated', function () {
140
188
  const builder = union('x')
141
- .add('1', object().set('a', booleanType))
142
- .add('2', object().set('a', numberType))
143
- type T = SimplifyDeep<FlattenedTypeDefsOf<typeof builder, null>>
189
+ .or('1', object().field('a', booleanType))
190
+ .or('2', object().field('a', numberType))
191
+ type T = SimplifyDeep<FlattenedTypesOfType<typeof builder._type, null>>
144
192
 
145
193
  let t: {
146
- readonly $: SimplifyDeep<typeof builder.narrow>,
194
+ readonly $: SimplifyDeep<typeof builder._type>,
147
195
  readonly ['$.1:a']: {
148
196
  readonly definition: {
149
197
  readonly type: TypeDefType.Literal,
@@ -164,21 +212,21 @@ describe('union', function () {
164
212
 
165
213
  describe('nested discriminated', function () {
166
214
  const builder = union('x')
167
- .add(
215
+ .or(
168
216
  '1',
169
217
  union('y')
170
- .add('p', object().set('a', booleanType))
171
- .add('q', object().set('a', stringType)),
218
+ .or('p', object().field('a', booleanType))
219
+ .or('q', object().field('a', stringType)),
172
220
  )
173
- .add(
221
+ .or(
174
222
  '2',
175
223
  union('z')
176
- .add('r', object().set('b', numberType))
177
- .add('s', object().set('c', stringType)),
224
+ .or('r', object().field('b', numberType))
225
+ .or('s', object().field('c', stringType)),
178
226
  )
179
- type T = SimplifyDeep<FlattenedTypeDefsOf<typeof builder, null>>
227
+ type T = SimplifyDeep<FlattenedTypesOfType<typeof builder._type, null>>
180
228
  let t: {
181
- readonly $: SimplifyDeep<typeof builder.narrow>,
229
+ readonly $: SimplifyDeep<typeof builder._type>,
182
230
  readonly ['$.1:p:a']: {
183
231
  readonly definition: {
184
232
  readonly type: TypeDefType.Literal,