@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,14 +1,60 @@
1
1
  import { booleanType, list, nullable, numberType, object, record, stringType, union, } from 'types/builders';
2
+ import { TypeDefType, } from 'types/definitions';
2
3
  describe('builder', function () {
3
4
  describe('literal', function () {
4
- const { definition: typeDef } = numberType;
5
+ const { definition } = numberType;
5
6
  it('equals expected type', function () {
6
- expectTypeOf(typeDef).toEqualTypeOf();
7
+ expectTypeOf(definition).toEqualTypeOf();
8
+ });
9
+ it('equals expected value', function () {
10
+ expect(definition).toEqual({
11
+ type: TypeDefType.Literal,
12
+ valuePrototype: undefined,
13
+ rule: expect.anything(),
14
+ required: false,
15
+ readonly: false,
16
+ });
7
17
  });
8
18
  describe('nullable', function () {
9
- const { definition: typeDef } = nullable(numberType);
19
+ const { definition } = nullable(numberType);
10
20
  it('equals expected type', function () {
11
- expectTypeOf(typeDef).toEqualTypeOf();
21
+ expectTypeOf(definition).toEqualTypeOf();
22
+ });
23
+ });
24
+ describe('required', function () {
25
+ const { definition } = numberType.required();
26
+ it('equals expected value', function () {
27
+ expect(definition).toEqual({
28
+ type: TypeDefType.Literal,
29
+ valuePrototype: undefined,
30
+ rule: expect.anything(),
31
+ required: true,
32
+ readonly: false,
33
+ });
34
+ });
35
+ });
36
+ describe('readonly', function () {
37
+ const { definition } = numberType.readonly();
38
+ it('equals expected value', function () {
39
+ expect(definition).toEqual({
40
+ type: TypeDefType.Literal,
41
+ valuePrototype: undefined,
42
+ rule: expect.anything(),
43
+ required: false,
44
+ readonly: true,
45
+ });
46
+ });
47
+ });
48
+ describe('readonly & required', function () {
49
+ const { definition } = numberType.readonly().required();
50
+ it('equals expected value', function () {
51
+ expect(definition).toEqual({
52
+ type: TypeDefType.Literal,
53
+ valuePrototype: undefined,
54
+ rule: expect.anything(),
55
+ required: true,
56
+ readonly: true,
57
+ });
12
58
  });
13
59
  });
14
60
  });
@@ -21,8 +67,8 @@ describe('builder', function () {
21
67
  });
22
68
  });
23
69
  });
24
- describe('readonly', function () {
25
- const { definition: typeDef } = list(numberType).readonly();
70
+ describe('readonlyElements', function () {
71
+ const { definition: typeDef } = list(numberType).readonlyElements();
26
72
  it('equals expected type', function () {
27
73
  expectTypeOf(typeDef).toEqualTypeOf();
28
74
  });
@@ -37,25 +83,27 @@ describe('builder', function () {
37
83
  });
38
84
  });
39
85
  describe('readonly', function () {
40
- const { definition: typeDef } = record(numberType).readonly();
86
+ const { definition: typeDef } = record(numberType).readonlyKeys();
41
87
  it('equals expected type', function () {
42
88
  expectTypeOf(typeDef).toEqualTypeOf();
43
89
  });
44
90
  });
45
91
  describe('partial', function () {
46
- const { definition: typeDef } = record(numberType).partial();
92
+ const { definition: typeDef } = record(numberType).partialKeys();
47
93
  it('equals expected type', function () {
48
94
  expectTypeOf(typeDef).toEqualTypeOf();
49
95
  });
50
96
  });
51
- describe('partial readonly', function () {
52
- const { definition: typeDef } = record(numberType).partial().readonly();
97
+ describe('partial and readonly', function () {
98
+ const { definition: typeDef } = record(numberType).partialKeys()
99
+ .readonlyKeys();
53
100
  it('equals expected type', function () {
54
101
  expectTypeOf(typeDef).toEqualTypeOf();
55
102
  });
56
103
  });
57
- describe('readonly partial', function () {
58
- const { definition: typeDef } = record(numberType).readonly().partial();
104
+ describe('readonly and partial', function () {
105
+ const { definition: typeDef } = record(numberType).readonlyKeys()
106
+ .partialKeys();
59
107
  it('equals expected type', function () {
60
108
  expectTypeOf(typeDef).toEqualTypeOf();
61
109
  });
@@ -64,10 +112,10 @@ describe('builder', function () {
64
112
  });
65
113
  describe('object', function () {
66
114
  const { definition: typeDef } = object()
67
- .set('a', numberType)
68
- .setReadonly('b', booleanType)
69
- .setOptional('c', stringType)
70
- .setReadonlyOptional('d', numberType);
115
+ .field('a', numberType)
116
+ .readonlyField('b', booleanType)
117
+ .optionalField('c', stringType)
118
+ .readonlyOptionalField('d', numberType);
71
119
  it('equals expected type', function () {
72
120
  expectTypeOf(typeDef).toEqualTypeOf();
73
121
  });
@@ -75,18 +123,20 @@ describe('builder', function () {
75
123
  describe('union', function () {
76
124
  describe('literals', function () {
77
125
  const { definition: typeDef, } = union()
78
- .add('1', numberType)
79
- .add('2', stringType);
126
+ .or('1', numberType)
127
+ .or('2', stringType);
80
128
  it('equals expected type', function () {
81
129
  expectTypeOf(typeDef).toEqualTypeOf();
82
130
  });
83
131
  });
84
132
  describe('objects', function () {
85
- const { definition: typeDef, } = union()
86
- .add('1', object().set('a', booleanType))
87
- .add('2', object().set('b', numberType));
88
- it('equals expected type', function () {
89
- expectTypeOf(typeDef).toEqualTypeOf();
133
+ describe('mutable', function () {
134
+ const { definition: typeDef, } = union()
135
+ .or('1', object().field('a', booleanType))
136
+ .or('2', object().field('b', numberType));
137
+ it('equals expected type', function () {
138
+ expectTypeOf(typeDef).toEqualTypeOf();
139
+ });
90
140
  });
91
141
  });
92
142
  });
@@ -1,5 +1,5 @@
1
1
  import { numberType, record, } from 'types/builders';
2
- describe('FlattenedAccessorsOf', function () {
2
+ describe('FlattenedAccessorsOfType', function () {
3
3
  // note we only test a small example since most of the work is done in flatten
4
4
  describe('record', function () {
5
5
  const builder = record(numberType);
@@ -1,5 +1,5 @@
1
1
  import { booleanType, list, numberType, object, record, stringType, union, } from 'types/builders';
2
- describe('FlattenedTypeDefsOf', function () {
2
+ describe('FlattenedTypesOfType', function () {
3
3
  describe('literal', function () {
4
4
  let t;
5
5
  it('equals expected type', function () {
@@ -23,10 +23,17 @@ describe('FlattenedTypeDefsOf', function () {
23
23
  describe('object', function () {
24
24
  describe('simple', function () {
25
25
  const builder = object()
26
- .set('a', numberType)
27
- .setOptional('b', stringType)
28
- .setReadonly('c', booleanType)
29
- .setReadonlyOptional('d', stringType);
26
+ .field('a', numberType)
27
+ .optionalField('b', stringType)
28
+ .readonlyField('c', booleanType)
29
+ .readonlyOptionalField('d', stringType);
30
+ let t;
31
+ it('equals expected type', function () {
32
+ expectTypeOf(t).toEqualTypeOf();
33
+ });
34
+ });
35
+ describe('optional', function () {
36
+ const builder = object().optionalField('a', stringType);
30
37
  let t;
31
38
  it('equals expected type', function () {
32
39
  expectTypeOf(t).toEqualTypeOf();
@@ -38,8 +45,8 @@ describe('union', function () {
38
45
  describe('overlapping', function () {
39
46
  describe('non-discriminated', function () {
40
47
  const builder = union()
41
- .add('x', object().set('a', booleanType))
42
- .add('y', object().set('b', numberType));
48
+ .or('x', object().field('a', booleanType))
49
+ .or('y', object().field('b', numberType));
43
50
  let t;
44
51
  it('equals expected type', function () {
45
52
  expectTypeOf(t).toEqualTypeOf();
@@ -47,8 +54,8 @@ describe('union', function () {
47
54
  });
48
55
  describe('discriminated', function () {
49
56
  const builder = union('x')
50
- .add('1', object().set('a', booleanType))
51
- .add('2', object().set('a', numberType));
57
+ .or('1', object().field('a', booleanType))
58
+ .or('2', object().field('a', numberType));
52
59
  let t;
53
60
  it('equals expected type', function () {
54
61
  expectTypeOf(t).toEqualTypeOf();
@@ -56,12 +63,12 @@ describe('union', function () {
56
63
  });
57
64
  describe('nested discriminated', function () {
58
65
  const builder = union('x')
59
- .add('1', union('y')
60
- .add('p', object().set('a', booleanType))
61
- .add('q', object().set('a', stringType)))
62
- .add('2', union('z')
63
- .add('r', object().set('b', numberType))
64
- .add('s', object().set('c', stringType)));
66
+ .or('1', union('y')
67
+ .or('p', object().field('a', booleanType))
68
+ .or('q', object().field('a', stringType)))
69
+ .or('2', union('z')
70
+ .or('r', object().field('b', numberType))
71
+ .or('s', object().field('c', stringType)));
65
72
  let t;
66
73
  it('equals expected type', function () {
67
74
  expectTypeOf(t).toEqualTypeOf();
@@ -0,0 +1,24 @@
1
+ import { list, numberType, } from 'types/builders';
2
+ describe('FlattenedValidatorsOfValidatingType', function () {
3
+ describe('literal', function () {
4
+ const literalType = numberType.enforce(function () {
5
+ return 'a';
6
+ });
7
+ let t;
8
+ it('equals expected type', function () {
9
+ expectTypeOf().toEqualTypeOf(t);
10
+ });
11
+ });
12
+ describe('list', function () {
13
+ const literalType = numberType.enforce(function () {
14
+ return 'x';
15
+ });
16
+ const listType = list(literalType.narrow).enforce(function () {
17
+ return 'y';
18
+ });
19
+ let t;
20
+ it('equals expected type', function () {
21
+ expectTypeOf().toEqualTypeOf(t);
22
+ });
23
+ });
24
+ });
@@ -0,0 +1,18 @@
1
+ import { numberType, object, record, stringType, } from 'types/builders';
2
+ describe('FlattenedValuesOfType', function () {
3
+ // note we only test a small example since most of the work is done in flatten
4
+ describe('record', function () {
5
+ const builder = record(numberType);
6
+ let v;
7
+ it('equals expected type', function () {
8
+ expectTypeOf(v).toEqualTypeOf();
9
+ });
10
+ });
11
+ describe('object', function () {
12
+ const builder = object().optionalField('a', stringType);
13
+ let v;
14
+ it('equals expected type', function () {
15
+ expectTypeOf(v).toEqualTypeOf();
16
+ });
17
+ });
18
+ });
@@ -22,8 +22,8 @@ describe('PartialTypeDefOf', function () {
22
22
  });
23
23
  describe('object', function () {
24
24
  const builder = object()
25
- .set('a', numberType)
26
- .setReadonly('b', stringType);
25
+ .field('a', numberType)
26
+ .readonlyField('b', stringType);
27
27
  let t;
28
28
  it('equals expected type', function () {
29
29
  expectTypeOf(t).toEqualTypeOf();
@@ -32,8 +32,8 @@ describe('PartialTypeDefOf', function () {
32
32
  describe('union', function () {
33
33
  describe('simple', function () {
34
34
  const builder = union()
35
- .add('1', numberType)
36
- .add('2', stringType);
35
+ .or('1', numberType)
36
+ .or('2', stringType);
37
37
  let t;
38
38
  it('equals expected type', function () {
39
39
  expectTypeOf(t).toEqualTypeOf();
@@ -1,5 +1,5 @@
1
1
  import { booleanType, list, nullable, numberType, object, record, stringType, union, } from 'types/builders';
2
- describe('JsonPathsOf', function () {
2
+ describe('PathsOfType', function () {
3
3
  describe('literal', function () {
4
4
  let path;
5
5
  describe('regular', function () {
@@ -71,7 +71,7 @@ describe('JsonPathsOf', function () {
71
71
  });
72
72
  });
73
73
  describe('partial', function () {
74
- const builder = record(stringType).partial();
74
+ const builder = record(stringType).partialKeys();
75
75
  it('equals expected type', function () {
76
76
  expectTypeOf(path).toEqualTypeOf();
77
77
  });
@@ -93,9 +93,9 @@ describe('JsonPathsOf', function () {
93
93
  describe('object', function () {
94
94
  describe('simple', function () {
95
95
  const builder = object()
96
- .set('n', numberType)
97
- .set('b', booleanType)
98
- .set('s', stringType);
96
+ .field('n', numberType)
97
+ .field('b', booleanType)
98
+ .field('s', stringType);
99
99
  let path;
100
100
  it('equals expected type', function () {
101
101
  expectTypeOf(path).toEqualTypeOf();
@@ -114,8 +114,8 @@ describe('JsonPathsOf', function () {
114
114
  });
115
115
  describe('nested', function () {
116
116
  const builder = object()
117
- .set('s1', object().set('a1', booleanType))
118
- .set('s2', object().set('a2', stringType));
117
+ .field('s1', object().field('a1', booleanType))
118
+ .field('s2', object().field('a2', stringType));
119
119
  let path;
120
120
  it('equals expected type', function () {
121
121
  expectTypeOf(path).toEqualTypeOf();
@@ -123,7 +123,7 @@ describe('JsonPathsOf', function () {
123
123
  });
124
124
  describe('object of list', function () {
125
125
  const builder = object()
126
- .set('l', list(numberType));
126
+ .field('l', list(numberType));
127
127
  describe('no override', function () {
128
128
  let path;
129
129
  it('equals expected type', function () {
@@ -141,8 +141,8 @@ describe('JsonPathsOf', function () {
141
141
  describe('union', function () {
142
142
  describe('with primitives', function () {
143
143
  const builder = union()
144
- .add('1', numberType)
145
- .add('2', stringType);
144
+ .or('1', numberType)
145
+ .or('2', stringType);
146
146
  let path;
147
147
  it('equals expected type', function () {
148
148
  expectTypeOf(path).toEqualTypeOf();
@@ -150,9 +150,9 @@ describe('JsonPathsOf', function () {
150
150
  });
151
151
  describe('with overlapping record', function () {
152
152
  const builder = union()
153
- .add('1', object().set('a', numberType).set('b', stringType))
154
- .add('2', object().set('b', stringType).set('c', stringType))
155
- .add('3', object().set('c', stringType).set('a', stringType));
153
+ .or('1', object().field('a', numberType).field('b', stringType))
154
+ .or('2', object().field('b', stringType).field('c', stringType))
155
+ .or('3', object().field('c', stringType).field('a', stringType));
156
156
  let path;
157
157
  it('equals expected type', function () {
158
158
  expectTypeOf(path).toEqualTypeOf();
@@ -160,8 +160,8 @@ describe('JsonPathsOf', function () {
160
160
  });
161
161
  describe('nested', function () {
162
162
  const builder = union()
163
- .add('1', object().set('a', union().add('x', object().set('aa', stringType))))
164
- .add('2', object().set('b', union().add('y', object().set('bb', stringType))));
163
+ .or('1', object().field('a', union().or('x', object().field('aa', stringType))))
164
+ .or('2', object().field('b', union().or('y', object().field('bb', stringType))));
165
165
  let path;
166
166
  it('equals expected type', function () {
167
167
  expectTypeOf(path).toEqualTypeOf();
@@ -170,8 +170,8 @@ describe('JsonPathsOf', function () {
170
170
  });
171
171
  describe('with discriminator', function () {
172
172
  const builder = union('x')
173
- .add('1', object().set('a', booleanType))
174
- .add('2', object().set('b', numberType));
173
+ .or('1', object().field('a', booleanType))
174
+ .or('2', object().field('b', numberType));
175
175
  let path;
176
176
  it('equals expected type', function () {
177
177
  expectTypeOf(path).toEqualTypeOf();
@@ -179,8 +179,8 @@ describe('JsonPathsOf', function () {
179
179
  });
180
180
  describe('with nested discriminator', function () {
181
181
  const builder = union('x')
182
- .add('1', union('y').add('p', object().set('a', booleanType)))
183
- .add('2', union('z').add('q', object().set('b', numberType)));
182
+ .or('1', union('y').or('p', object().field('a', booleanType)))
183
+ .or('2', union('z').or('q', object().field('b', numberType)));
184
184
  let path;
185
185
  it('equals expected type', function () {
186
186
  expectTypeOf(path).toEqualTypeOf();
@@ -22,8 +22,8 @@ describe('ReadonlyTypeDefOf', function () {
22
22
  });
23
23
  describe('object', function () {
24
24
  const builder = object()
25
- .set('a', numberType)
26
- .setOptional('b', stringType);
25
+ .field('a', numberType)
26
+ .optionalField('b', stringType);
27
27
  let t;
28
28
  it('equals expected type', function () {
29
29
  expectTypeOf(t).toEqualTypeOf();
@@ -31,22 +31,22 @@ describe('ReadonlyTypeDefOf', function () {
31
31
  });
32
32
  describe('union', function () {
33
33
  const builder = union()
34
- .add('1', record(numberType))
35
- .add('2', stringType);
34
+ .or('1', record(numberType))
35
+ .or('2', stringType);
36
36
  let t;
37
37
  it('equals expected type', function () {
38
38
  expectTypeOf(t).toEqualTypeOf();
39
39
  });
40
40
  });
41
41
  describe('partial', function () {
42
- const builder = record(numberType).partial();
42
+ const builder = record(numberType).partialKeys();
43
43
  let t;
44
44
  it('equals expected type', function () {
45
45
  expectTypeOf(t).toEqualTypeOf();
46
46
  });
47
47
  });
48
48
  describe('readonly', function () {
49
- const builder = record(numberType).readonly();
49
+ const builder = record(numberType).readonlyKeys();
50
50
  let t;
51
51
  it('equals expected type', function () {
52
52
  expectTypeOf(t).toEqualTypeOf();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import { list, numberType, } from 'types/builders';
2
+ describe('TypeOfType', function () {
3
+ describe('literal', function () {
4
+ const literalType = numberType;
5
+ let t;
6
+ it('equals expected type', function () {
7
+ expectTypeOf().toEqualTypeOf(t);
8
+ });
9
+ });
10
+ describe('list', function () {
11
+ describe('mutable', function () {
12
+ const listType = list(numberType);
13
+ let t;
14
+ it('equals expected type', function () {
15
+ expectTypeOf().toEqualTypeOf(t);
16
+ });
17
+ });
18
+ describe('readonly', function () {
19
+ const listType = list(numberType).readonlyElements();
20
+ let t;
21
+ it('equals expected type', function () {
22
+ expectTypeOf().toEqualTypeOf(t);
23
+ });
24
+ });
25
+ });
26
+ // TODO other types
27
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- describe('ValueTypeOf', function () {
1
+ describe('ValueOfType', function () {
2
2
  describe('literal', function () {
3
3
  let t;
4
4
  it('equals expected type', function () {
@@ -1,5 +1,5 @@
1
1
  import { booleanType, list, nullable, numberType, object, record, stringType, union, } from 'types/builders';
2
- describe('FlattenedJsonPathsOf', function () {
2
+ describe('ValueToTypePathsOfType', function () {
3
3
  describe('literal', function () {
4
4
  let t;
5
5
  it('equals expected type', function () {
@@ -26,10 +26,10 @@ describe('FlattenedJsonPathsOf', function () {
26
26
  });
27
27
  describe('object', function () {
28
28
  const builder = object()
29
- .set('a', list(numberType))
30
- .setOptional('b', booleanType)
31
- .setReadonly('c', stringType)
32
- .setReadonlyOptional('d', stringType);
29
+ .field('a', list(numberType))
30
+ .optionalField('b', booleanType)
31
+ .readonlyField('c', stringType)
32
+ .readonlyOptionalField('d', stringType);
33
33
  let t;
34
34
  it('equals expected type', function () {
35
35
  expectTypeOf(t).toEqualTypeOf();
@@ -44,8 +44,8 @@ describe('FlattenedJsonPathsOf', function () {
44
44
  describe('union', function () {
45
45
  describe('non-discriminated', function () {
46
46
  const builder = union()
47
- .add('1', list(numberType))
48
- .add('2', stringType);
47
+ .or('1', list(numberType))
48
+ .or('2', stringType);
49
49
  let t;
50
50
  it('equals expected type', function () {
51
51
  expectTypeOf(t).toEqualTypeOf();
@@ -53,8 +53,8 @@ describe('FlattenedJsonPathsOf', function () {
53
53
  });
54
54
  describe('discriminated', function () {
55
55
  const builder = union('d')
56
- .add('1', object().set('a', booleanType).set('b', numberType))
57
- .add('2', object().set('x', numberType).set('y', stringType));
56
+ .or('1', object().field('a', booleanType).field('b', numberType))
57
+ .or('2', object().field('x', numberType).field('y', stringType));
58
58
  let t;
59
59
  it('equals expected type', function () {
60
60
  expectTypeOf(t).toEqualTypeOf();
@@ -2,8 +2,8 @@ import { booleanType, numberType, object, union, } from 'types/builders';
2
2
  describe('ValueTypesOfDiscriminatedUnion', function () {
3
3
  it('matches expected type', function () {
4
4
  const { definition } = union('d')
5
- .add('a', object().set('x', numberType))
6
- .add('b', object().set('y', booleanType));
5
+ .or('a', object().field('x', numberType))
6
+ .or('b', object().field('y', booleanType));
7
7
  expectTypeOf().toEqualTypeOf();
8
8
  });
9
9
  });
@@ -18,10 +18,10 @@ export type StrictRecordTypeDef<K extends RecordKeyType = RecordKeyType, V exten
18
18
  readonly keyPrototype: K;
19
19
  readonly valueTypeDef: V;
20
20
  };
21
- export type StrictStructuredTypeDefFields = {
21
+ export type StrictObjectTypeDefFields = {
22
22
  [Key: ObjectFieldKey]: AnyTypeDef;
23
23
  };
24
- export type StrictObjectTypeDef<Fields extends StrictStructuredTypeDefFields = StrictStructuredTypeDefFields> = {
24
+ export type StrictObjectTypeDef<Fields extends StrictObjectTypeDefFields = StrictObjectTypeDefFields> = {
25
25
  readonly type: TypeDefType.Object;
26
26
  readonly fields: Fields;
27
27
  };
@@ -0,0 +1,49 @@
1
+ import { type IsFieldReadonly } from '@strictly/base';
2
+ import { type ListTypeDef, type LiteralTypeDef, type ObjectFieldKey, type ObjectTypeDef, type RecordTypeDef, type Type, type TypeDef, TypeDefType, type UnionTypeDef } from 'types/definitions';
3
+ export type TypeOfType<T extends Type> = T extends Type<infer D> ? {
4
+ readonly definition: TypeDefOfTypeDef<D>;
5
+ } : never;
6
+ type TypeDefOfTypeDef<D extends TypeDef> = D extends LiteralTypeDef ? TypeDefOfLiteralTypeDef<D> : D extends ListTypeDef ? TypeDefOfListTypeDef<D> : D extends RecordTypeDef ? TypeDefOfRecordTypeDef<D> : D extends ObjectTypeDef ? TypeDefOfObjectTypeDef<D> : D extends UnionTypeDef ? TypeDefOfUnionTypeDef<D> : never;
7
+ type TypeDefOfLiteralTypeDef<T extends LiteralTypeDef> = T extends LiteralTypeDef<infer V> ? {
8
+ readonly type: TypeDefType.Literal;
9
+ readonly valuePrototype: [V];
10
+ } : never;
11
+ type TypeDefOfListTypeDef<T extends ListTypeDef> = T extends ListTypeDef<infer E> ? IsFieldReadonly<T, 'elements'> extends true ? {
12
+ readonly type: TypeDefType.List;
13
+ readonly elements: TypeDefOfTypeDef<E>;
14
+ } : {
15
+ readonly type: TypeDefType.List;
16
+ elements: TypeDefOfTypeDef<E>;
17
+ } : never;
18
+ type TypeDefOfRecordTypeDef<T extends RecordTypeDef> = T extends RecordTypeDef<infer K, infer V> ? undefined extends V ? IsFieldReadonly<T, 'valueTypeDef'> extends true ? {
19
+ readonly type: TypeDefType.Record;
20
+ readonly keyPrototype: K;
21
+ readonly valueTypeDef: TypeDefOfTypeDef<NonNullable<V>> | undefined;
22
+ } : {
23
+ readonly type: TypeDefType.Record;
24
+ readonly keyPrototype: K;
25
+ valueTypeDef: TypeDefOfTypeDef<NonNullable<V>> | undefined;
26
+ } : IsFieldReadonly<T, 'valueTypeDef'> extends true ? {
27
+ readonly type: TypeDefType.Record;
28
+ readonly keyPrototype: K;
29
+ readonly valueTypeDef: TypeDefOfTypeDef<NonNullable<V>>;
30
+ } : {
31
+ readonly type: TypeDefType.Record;
32
+ readonly keyPrototype: K;
33
+ valueTypeDef: TypeDefOfTypeDef<NonNullable<V>>;
34
+ } : never;
35
+ type TypeDefOfObjectTypeDef<T extends ObjectTypeDef> = T extends ObjectTypeDef<infer Fields> ? {
36
+ readonly type: TypeDefType.Object;
37
+ readonly fields: {
38
+ [K in keyof Fields as K extends ObjectFieldKey ? K : never]: TypeDefOfTypeDef<NonNullable<Fields[K]>>;
39
+ };
40
+ } : never;
41
+ type TypeDefOfUnionTypeDef<T extends UnionTypeDef> = T extends UnionTypeDef<infer D, infer U> ? {
42
+ readonly type: TypeDefType.Union;
43
+ readonly discriminator: D;
44
+ readonly unions: {
45
+ [K in keyof U]: TypeDefOfTypeDef<U[K]>;
46
+ };
47
+ } : never;
48
+ export declare function typeOfType<T extends Type>({ definition }: T): TypeOfType<T>;
49
+ export {};