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