@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.
- package/.out/index.d.ts +17 -11
- package/.out/index.js +17 -11
- package/.out/transformers/copies/copy.d.ts +3 -3
- package/.out/transformers/copies/copy_to.d.ts +3 -3
- package/.out/transformers/copies/copy_to.js +4 -0
- package/.out/transformers/copies/mobx_copy.d.ts +4 -4
- package/.out/transformers/copies/mobx_copy.js +1 -1
- package/.out/transformers/copies/specs/copy_to.tests.js +8 -8
- package/.out/transformers/copies/specs/mobx_copy.tests.js +1 -1
- package/.out/transformers/flatteners/flatten_accessors_of_type.d.ts +5 -0
- package/.out/transformers/flatteners/flatten_accessors_of_type.js +11 -0
- package/.out/transformers/flatteners/flatten_json_value_to_type_paths_of.d.ts +2 -2
- package/.out/transformers/flatteners/flatten_json_value_to_type_paths_of.js +2 -2
- package/.out/transformers/flatteners/{flatten_type_def_to.d.ts → flatten_type_to.d.ts} +1 -1
- package/.out/transformers/flatteners/{flatten_type_def_to.js → flatten_type_to.js} +1 -1
- package/.out/transformers/flatteners/{flatten_type_defs_of.d.ts → flatten_types_of_type.d.ts} +1 -1
- package/.out/transformers/flatteners/flatten_types_of_type.js +7 -0
- package/.out/transformers/flatteners/flatten_validation_errors_of_type.d.ts +22 -0
- package/.out/transformers/flatteners/flatten_validation_errors_of_type.js +10 -0
- package/.out/transformers/flatteners/flatten_validators_of_validating_type.d.ts +4 -0
- package/.out/transformers/flatteners/flatten_validators_of_validating_type.js +17 -0
- package/.out/transformers/flatteners/{flatten_value_type_to.d.ts → flatten_value_to.d.ts} +4 -4
- package/.out/transformers/flatteners/{flatten_value_type_to.js → flatten_value_to.js} +7 -2
- package/.out/transformers/flatteners/flatten_values_of_type.d.ts +3 -0
- package/.out/transformers/flatteners/flatten_values_of_type.js +7 -0
- package/.out/transformers/flatteners/specs/{flatten_accessors_of.tests.js → flatten_accessors_of_type.tests.js} +5 -6
- package/.out/transformers/flatteners/specs/flatten_json_value_to_type_paths_of.tests.js +6 -6
- package/.out/transformers/flatteners/specs/{flatten_type_def_to.tests.js → flatten_type_to.tests.js} +15 -13
- package/.out/transformers/flatteners/specs/flatten_types_of_type.tests.js +18 -0
- package/.out/transformers/flatteners/specs/flatten_validation_errors_of_type.tests.js +25 -0
- package/.out/transformers/flatteners/specs/{flatten_value_type_to.tests.js → flatten_value_to.tests.js} +81 -58
- package/.out/transformers/flatteners/specs/{flatten_value_types_of.tests.js → flatten_values_of_type.tests.js} +4 -4
- package/.out/transformers/flatteners/specs/value_path_to_type_path.tests.js +5 -3
- package/.out/transformers/flatteners/value_path_to_type_path.d.ts +1 -1
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/types/builders.d.ts +55 -29
- package/.out/types/builders.js +116 -32
- package/.out/types/definitions.d.ts +1 -1
- package/.out/types/flattened_accessors_of_type.d.ts +9 -0
- package/.out/types/{flattened_type_defs_of.d.ts → flattened_types_of_type.d.ts} +9 -6
- package/.out/types/flattened_types_of_validating_type.d.ts +25 -0
- package/.out/types/flattened_validators_of_validating_type.d.ts +10 -0
- package/.out/types/flattened_values_of_type.d.ts +6 -0
- package/.out/types/{mobx_value_type_of.d.ts → mobx_value_of_type.d.ts} +2 -2
- package/.out/types/{partial_type_def_of.d.ts → partial_type_of_type.d.ts} +1 -1
- package/.out/types/path_of.d.ts +1 -0
- package/.out/types/{json_paths_of.d.ts → paths_of_type.d.ts} +5 -5
- package/.out/types/readonly_type_of_type.d.ts +29 -0
- package/.out/types/specs/builder.tests.js +73 -23
- package/.out/types/specs/{flattened_accessors_of.tests.js → flattened_accessors_of_type.tests.js} +1 -1
- package/.out/types/specs/{flattened_type_defs_of.tests.js → flattened_types_of_type.tests.js} +22 -15
- package/.out/types/specs/flattened_validators_of_validating_type.tests.js +24 -0
- package/.out/types/specs/flattened_values_of_type.tests.js +18 -0
- package/.out/types/specs/{partial_type_def_of.tests.js → partial_type_of_type.tests.js} +4 -4
- package/.out/types/specs/{json_paths_of.tests.js → paths_of_type.tests.js} +19 -19
- package/.out/types/specs/{readonly_type_def_of.tests.js → readonly_type_of_type.tests.js} +6 -6
- package/.out/types/specs/type_of_type.tests.d.ts +1 -0
- package/.out/types/specs/type_of_type.tests.js +27 -0
- package/.out/types/specs/value_of_type.tests.d.ts +1 -0
- package/.out/types/specs/{value_type_of.tests.js → value_of_type.tests.js} +1 -1
- package/.out/types/specs/value_to_type_paths_of_type.tests.d.ts +1 -0
- package/.out/types/specs/{value_to_type_paths_of.tests.js → value_to_type_paths_of_type.tests.js} +9 -9
- package/.out/types/specs/value_types_of_discriminated_union.tests.js +2 -2
- package/.out/types/strict_definitions.d.ts +2 -2
- package/.out/types/type_of_type.d.ts +49 -0
- package/.out/types/type_of_type.js +70 -0
- package/.out/types/validating_definitions.d.ts +49 -0
- package/.out/types/validating_definitions.js +1 -0
- package/.out/types/validating_type_def_with_error.d.ts +55 -0
- package/.out/types/validating_type_def_with_error.js +1 -0
- package/.out/types/value_of_type.d.ts +24 -0
- package/.out/types/value_of_type.js +1 -0
- package/.out/types/{value_to_type_paths_of.d.ts → value_to_type_paths_of_type.d.ts} +13 -13
- package/.out/types/value_to_type_paths_of_type.js +1 -0
- package/.out/types/value_types_of_discriminated_union.d.ts +5 -4
- package/.out/validation/errors_of_validators.d.ts +4 -0
- package/.out/validation/errors_of_validators.js +1 -0
- package/.out/validation/specs/errors_of_validators.tests.d.ts +1 -0
- package/.out/validation/specs/errors_of_validators.tests.js +9 -0
- package/.out/validation/specs/validators_of_values.tests.d.ts +1 -0
- package/.out/validation/specs/validators_of_values.tests.js +21 -0
- package/.out/validation/validator.d.ts +21 -0
- package/.out/validation/validator.js +26 -0
- package/.out/validation/validators/defined_validator.d.ts +10 -0
- package/.out/validation/validators/defined_validator.js +18 -0
- package/.out/validation/validators/minimum_string_length_validator.d.ts +16 -0
- package/.out/validation/validators/minimum_string_length_validator.js +23 -0
- package/.out/validation/validators_of_values.d.ts +4 -0
- package/.out/validation/validators_of_values.js +1 -0
- package/.turbo/turbo-build.log +9 -9
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/README.md +16 -2
- package/dist/index.cjs +364 -76
- package/dist/index.d.cts +365 -114
- package/dist/index.d.ts +365 -114
- package/dist/index.js +355 -73
- package/index.ts +17 -11
- package/package.json +11 -3
- package/transformers/copies/copy.ts +4 -4
- package/transformers/copies/copy_to.ts +11 -7
- package/transformers/copies/mobx_copy.ts +6 -6
- package/transformers/copies/specs/copy_to.tests.ts +8 -8
- package/transformers/copies/specs/mobx_copy.tests.ts +3 -3
- package/transformers/flatteners/{flatten_accessors_of.ts → flatten_accessors_of_type.ts} +10 -10
- package/transformers/flatteners/flatten_json_value_to_type_paths_of.ts +5 -5
- package/transformers/flatteners/{flatten_type_def_to.ts → flatten_type_to.ts} +1 -1
- package/transformers/flatteners/{flatten_type_defs_of.ts → flatten_types_of_type.ts} +3 -3
- package/transformers/flatteners/flatten_validation_errors_of_type.ts +93 -0
- package/transformers/flatteners/flatten_validators_of_validating_type.ts +32 -0
- package/transformers/flatteners/{flatten_value_type_to.ts → flatten_value_to.ts} +12 -7
- package/transformers/flatteners/{flatten_value_types_of.ts → flatten_values_of_type.ts} +6 -6
- package/transformers/flatteners/specs/{flatten_accessors_of.tests.ts → flatten_accessors_of_type.tests.ts} +10 -11
- package/transformers/flatteners/specs/flatten_json_value_to_type_paths_of.tests.ts +6 -6
- package/transformers/flatteners/specs/{flatten_type_def_to.tests.ts → flatten_type_to.tests.ts} +15 -13
- package/transformers/flatteners/specs/flatten_types_of_type.tests.ts +27 -0
- package/transformers/flatteners/specs/flatten_validation_errors_of_type.tests.ts +48 -0
- package/transformers/flatteners/specs/{flatten_value_type_to.tests.ts → flatten_value_to.tests.ts} +124 -91
- package/transformers/flatteners/specs/{flatten_value_types_of.tests.ts → flatten_values_of_type.tests.ts} +4 -4
- package/transformers/flatteners/specs/value_path_to_type_path.tests.ts +20 -18
- package/transformers/flatteners/value_path_to_type_path.ts +4 -4
- package/types/builders.ts +239 -71
- package/types/definitions.ts +2 -2
- package/types/{flattened_accessors_of.ts → flattened_accessors_of_type.ts} +3 -3
- package/types/{flattened_type_defs_of.ts → flattened_types_of_type.ts} +22 -12
- package/types/flattened_types_of_validating_type.ts +152 -0
- package/types/flattened_validators_of_validating_type.ts +33 -0
- package/types/flattened_values_of_type.ts +11 -0
- package/types/{mobx_value_type_of.ts → mobx_value_of_type.ts} +2 -2
- package/types/{partial_type_def_of.ts → partial_type_of_type.ts} +3 -1
- package/types/{json_path_of.ts → path_of.ts} +1 -1
- package/types/{json_paths_of.ts → paths_of_type.ts} +5 -5
- package/types/readonly_type_of_type.ts +54 -0
- package/types/specs/builder.tests.ts +205 -54
- package/types/specs/{flattened_accessors_of.tests.ts → flattened_accessors_of_type.tests.ts} +3 -3
- package/types/specs/{flattened_type_defs_of.tests.ts → flattened_types_of_type.tests.ts} +82 -34
- package/types/specs/flattened_validators_of_validating_type.tests.ts +47 -0
- package/types/specs/flattened_values_of_type.tests.ts +39 -0
- package/types/specs/{partial_type_def_of.tests.ts → partial_type_of_type.tests.ts} +11 -11
- package/types/specs/{json_paths_of.tests.ts → paths_of_type.tests.ts} +47 -47
- package/types/specs/{readonly_type_def_of.tests.ts → readonly_type_of_type.tests.ts} +14 -14
- package/types/specs/type_of_type.tests.ts +60 -0
- package/types/specs/{value_type_of.tests.ts → value_of_type.tests.ts} +15 -15
- package/types/specs/{value_to_type_paths_of.tests.ts → value_to_type_paths_of_type.tests.ts} +26 -25
- package/types/specs/value_types_of_discriminated_union.tests.ts +6 -6
- package/types/strict_definitions.ts +3 -3
- package/types/type_of_type.ts +178 -0
- package/types/validating_definitions.ts +109 -0
- package/types/validating_type_def_with_error.ts +93 -0
- package/types/value_of_type.ts +84 -0
- package/types/{value_to_type_paths_of.ts → value_to_type_paths_of_type.ts} +30 -29
- package/types/value_types_of_discriminated_union.ts +4 -3
- package/validation/errors_of_validators.ts +10 -0
- package/validation/specs/errors_of_validators.tests.ts +20 -0
- package/validation/specs/validators_of_values.tests.ts +68 -0
- package/validation/validator.ts +103 -0
- package/validation/validators/defined_validator.ts +22 -0
- package/validation/validators/minimum_string_length_validator.ts +36 -0
- package/validation/validators_of_values.ts +17 -0
- package/.out/transformers/flatteners/flatten_accessors_of.d.ts +0 -5
- package/.out/transformers/flatteners/flatten_accessors_of.js +0 -11
- package/.out/transformers/flatteners/flatten_type_defs_of.js +0 -7
- package/.out/transformers/flatteners/flatten_value_types_of.d.ts +0 -3
- package/.out/transformers/flatteners/flatten_value_types_of.js +0 -7
- package/.out/transformers/flatteners/specs/flatten_type_defs_of.tests.js +0 -17
- package/.out/types/flattened_accessors_of.d.ts +0 -9
- package/.out/types/flattened_value_types_of.d.ts +0 -6
- package/.out/types/json_path_of.d.ts +0 -1
- package/.out/types/readonly_type_def_of.d.ts +0 -29
- package/.out/types/specs/flattened_value_types_of.tests.js +0 -11
- package/.out/types/value_type_of.d.ts +0 -24
- package/transformers/flatteners/specs/flatten_type_defs_of.tests.ts +0 -26
- package/types/flattened_value_types_of.ts +0 -11
- package/types/readonly_type_def_of.ts +0 -53
- package/types/specs/flattened_value_types_of.tests.ts +0 -21
- package/types/value_type_of.ts +0 -84
- /package/.out/transformers/flatteners/specs/{flatten_accessors_of.tests.d.ts → flatten_accessors_of_type.tests.d.ts} +0 -0
- /package/.out/transformers/flatteners/specs/{flatten_type_def_to.tests.d.ts → flatten_type_to.tests.d.ts} +0 -0
- /package/.out/transformers/flatteners/specs/{flatten_type_defs_of.tests.d.ts → flatten_types_of_type.tests.d.ts} +0 -0
- /package/.out/transformers/flatteners/specs/{flatten_value_type_to.tests.d.ts → flatten_validation_errors_of_type.tests.d.ts} +0 -0
- /package/.out/transformers/flatteners/specs/{flatten_value_types_of.tests.d.ts → flatten_value_to.tests.d.ts} +0 -0
- /package/.out/{types/flattened_accessors_of.js → transformers/flatteners/specs/flatten_values_of_type.tests.d.ts} +0 -0
- /package/.out/types/{flattened_type_defs_of.js → flattened_accessors_of_type.js} +0 -0
- /package/.out/types/{flattened_value_types_of.js → flattened_types_of_type.js} +0 -0
- /package/.out/types/{json_path_of.js → flattened_types_of_validating_type.js} +0 -0
- /package/.out/types/{json_paths_of.js → flattened_validators_of_validating_type.js} +0 -0
- /package/.out/types/{partial_type_def_of.js → flattened_values_of_type.js} +0 -0
- /package/.out/types/{mobx_value_type_of.js → mobx_value_of_type.js} +0 -0
- /package/.out/types/{readonly_type_def_of.js → partial_type_of_type.js} +0 -0
- /package/.out/types/{specs/flattened_accessors_of.tests.d.ts → path_of.js} +0 -0
- /package/.out/types/{specs/flattened_type_defs_of.tests.d.ts → paths_of_type.js} +0 -0
- /package/.out/types/{specs/flattened_value_types_of.tests.d.ts → readonly_type_of_type.js} +0 -0
- /package/.out/types/specs/{json_paths_of.tests.d.ts → flattened_accessors_of_type.tests.d.ts} +0 -0
- /package/.out/types/specs/{partial_type_def_of.tests.d.ts → flattened_types_of_type.tests.d.ts} +0 -0
- /package/.out/types/specs/{readonly_type_def_of.tests.d.ts → flattened_validators_of_validating_type.tests.d.ts} +0 -0
- /package/.out/types/specs/{value_to_type_paths_of.tests.d.ts → flattened_values_of_type.tests.d.ts} +0 -0
- /package/.out/types/specs/{value_type_of.tests.d.ts → partial_type_of_type.tests.d.ts} +0 -0
- /package/.out/types/{value_to_type_paths_of.js → specs/paths_of_type.tests.d.ts} +0 -0
- /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
|
-
|
|
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
|
|
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(
|
|
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
|
|
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(
|
|
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('
|
|
70
|
-
const { definition: typeDef } = list(numberType).
|
|
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).
|
|
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).
|
|
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).
|
|
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).
|
|
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
|
-
.
|
|
176
|
-
.
|
|
177
|
-
.
|
|
178
|
-
.
|
|
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
|
-
.
|
|
344
|
+
.or(
|
|
220
345
|
'1',
|
|
221
346
|
numberType,
|
|
222
347
|
)
|
|
223
|
-
.
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
-
|
|
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
|
})
|
package/types/specs/{flattened_accessors_of.tests.ts → flattened_accessors_of_type.tests.ts}
RENAMED
|
@@ -2,13 +2,13 @@ import {
|
|
|
2
2
|
numberType,
|
|
3
3
|
record,
|
|
4
4
|
} from 'types/builders'
|
|
5
|
-
import { type
|
|
5
|
+
import { type FlattenedAccessorsOfType } from 'types/flattened_accessors_of_type'
|
|
6
6
|
|
|
7
|
-
describe('
|
|
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 =
|
|
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
|
|
12
|
+
import { type FlattenedTypesOfType } from 'types/flattened_types_of_type'
|
|
13
13
|
|
|
14
|
-
describe('
|
|
14
|
+
describe('FlattenedTypesOfType', function () {
|
|
15
15
|
describe('literal', function () {
|
|
16
|
-
type T =
|
|
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<
|
|
33
|
+
type T = SimplifyDeep<FlattenedTypesOfType<typeof builder._type, '*'>>
|
|
34
34
|
|
|
35
35
|
let t: {
|
|
36
|
-
readonly $: SimplifyDeep<typeof builder.
|
|
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<
|
|
51
|
+
type T = SimplifyDeep<FlattenedTypesOfType<typeof builder._type, '*'>>
|
|
52
52
|
|
|
53
53
|
let t: {
|
|
54
|
-
readonly $: SimplifyDeep<typeof builder.
|
|
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
|
-
.
|
|
71
|
-
.
|
|
72
|
-
.
|
|
73
|
-
.
|
|
74
|
-
type T = SimplifyDeep<
|
|
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.
|
|
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
|
|
87
|
-
readonly
|
|
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
|
|
99
|
-
readonly
|
|
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
|
-
.
|
|
115
|
-
.
|
|
116
|
-
type T = SimplifyDeep<
|
|
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.
|
|
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
|
-
.
|
|
142
|
-
.
|
|
143
|
-
type T = SimplifyDeep<
|
|
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.
|
|
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
|
-
.
|
|
215
|
+
.or(
|
|
168
216
|
'1',
|
|
169
217
|
union('y')
|
|
170
|
-
.
|
|
171
|
-
.
|
|
218
|
+
.or('p', object().field('a', booleanType))
|
|
219
|
+
.or('q', object().field('a', stringType)),
|
|
172
220
|
)
|
|
173
|
-
.
|
|
221
|
+
.or(
|
|
174
222
|
'2',
|
|
175
223
|
union('z')
|
|
176
|
-
.
|
|
177
|
-
.
|
|
224
|
+
.or('r', object().field('b', numberType))
|
|
225
|
+
.or('s', object().field('c', stringType)),
|
|
178
226
|
)
|
|
179
|
-
type T = SimplifyDeep<
|
|
227
|
+
type T = SimplifyDeep<FlattenedTypesOfType<typeof builder._type, null>>
|
|
180
228
|
let t: {
|
|
181
|
-
readonly $: SimplifyDeep<typeof builder.
|
|
229
|
+
readonly $: SimplifyDeep<typeof builder._type>,
|
|
182
230
|
readonly ['$.1:p:a']: {
|
|
183
231
|
readonly definition: {
|
|
184
232
|
readonly type: TypeDefType.Literal,
|