@strictly/define 0.0.1 → 0.0.3
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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { flattenValueTo, } from 'transformers/flatteners/flatten_value_to';
|
|
2
2
|
import { booleanType, list, literal, nullType, numberType, object, record, union, } from 'types/builders';
|
|
3
3
|
import { vi, } from 'vitest';
|
|
4
|
-
describe('
|
|
4
|
+
describe('flattenValueTo', function () {
|
|
5
5
|
let toStringMapper;
|
|
6
6
|
let setMapper;
|
|
7
7
|
let setter;
|
|
@@ -15,11 +15,11 @@ describe('flattenValueTypeTo', function () {
|
|
|
15
15
|
setter = vi.fn();
|
|
16
16
|
});
|
|
17
17
|
describe('literal', function () {
|
|
18
|
-
const
|
|
18
|
+
const type = numberType;
|
|
19
19
|
describe('toString', function () {
|
|
20
20
|
let flattened;
|
|
21
21
|
beforeEach(function () {
|
|
22
|
-
flattened =
|
|
22
|
+
flattened = flattenValueTo(type, 1, setter, toStringMapper);
|
|
23
23
|
});
|
|
24
24
|
it('equals expected type', function () {
|
|
25
25
|
expect(flattened).toEqual({
|
|
@@ -33,7 +33,7 @@ describe('flattenValueTypeTo', function () {
|
|
|
33
33
|
describe('setter', function () {
|
|
34
34
|
let flattened;
|
|
35
35
|
beforeEach(function () {
|
|
36
|
-
flattened =
|
|
36
|
+
flattened = flattenValueTo(type, 1, setter, setMapper);
|
|
37
37
|
});
|
|
38
38
|
it('calls the top level setter', function () {
|
|
39
39
|
const value = 3;
|
|
@@ -56,7 +56,7 @@ describe('flattenValueTypeTo', function () {
|
|
|
56
56
|
describe('toString', function () {
|
|
57
57
|
let flattened;
|
|
58
58
|
beforeEach(function () {
|
|
59
|
-
flattened =
|
|
59
|
+
flattened = flattenValueTo(typeDef, l, setter, toStringMapper);
|
|
60
60
|
});
|
|
61
61
|
it('equals expected type', function () {
|
|
62
62
|
expect(flattened).toEqual({
|
|
@@ -73,7 +73,7 @@ describe('flattenValueTypeTo', function () {
|
|
|
73
73
|
describe('setter', function () {
|
|
74
74
|
let flattened;
|
|
75
75
|
beforeEach(function () {
|
|
76
|
-
flattened =
|
|
76
|
+
flattened = flattenValueTo(typeDef, l, setter, setMapper);
|
|
77
77
|
});
|
|
78
78
|
it('sets a value in the list', function () {
|
|
79
79
|
flattened['$.1'](4);
|
|
@@ -97,7 +97,7 @@ describe('flattenValueTypeTo', function () {
|
|
|
97
97
|
describe('toString', function () {
|
|
98
98
|
let flattened;
|
|
99
99
|
beforeEach(function () {
|
|
100
|
-
flattened =
|
|
100
|
+
flattened = flattenValueTo(typeDef, m, setter, toStringMapper);
|
|
101
101
|
});
|
|
102
102
|
it('equals expected type', function () {
|
|
103
103
|
expect(flattened).toEqual({
|
|
@@ -110,7 +110,7 @@ describe('flattenValueTypeTo', function () {
|
|
|
110
110
|
describe('setter', function () {
|
|
111
111
|
let flattened;
|
|
112
112
|
beforeEach(function () {
|
|
113
|
-
flattened =
|
|
113
|
+
flattened = flattenValueTo(typeDef, m, setter, setMapper);
|
|
114
114
|
});
|
|
115
115
|
it('sets a value in the record', function () {
|
|
116
116
|
flattened['$.a'](4);
|
|
@@ -122,46 +122,69 @@ describe('flattenValueTypeTo', function () {
|
|
|
122
122
|
});
|
|
123
123
|
});
|
|
124
124
|
describe('object', function () {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
s = {
|
|
131
|
-
a: 1,
|
|
132
|
-
b: false,
|
|
133
|
-
};
|
|
134
|
-
});
|
|
135
|
-
describe('toString', function () {
|
|
136
|
-
let flattened;
|
|
125
|
+
describe('mandatory fields', function () {
|
|
126
|
+
const type = object()
|
|
127
|
+
.field('a', numberType)
|
|
128
|
+
.field('b', booleanType);
|
|
129
|
+
let s;
|
|
137
130
|
beforeEach(function () {
|
|
138
|
-
|
|
131
|
+
s = {
|
|
132
|
+
a: 1,
|
|
133
|
+
b: false,
|
|
134
|
+
};
|
|
139
135
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
136
|
+
describe('toString', function () {
|
|
137
|
+
let flattened;
|
|
138
|
+
beforeEach(function () {
|
|
139
|
+
flattened = flattenValueTo(type, s, setter, toStringMapper);
|
|
140
|
+
});
|
|
141
|
+
it('equals expected type', function () {
|
|
142
|
+
expect(flattened).toEqual({
|
|
143
|
+
$: '{"a":1,"b":false}',
|
|
144
|
+
['$.a']: '1',
|
|
145
|
+
['$.b']: 'false',
|
|
146
|
+
});
|
|
145
147
|
});
|
|
146
148
|
});
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
149
|
+
describe('setter', function () {
|
|
150
|
+
let flattened;
|
|
151
|
+
beforeEach(function () {
|
|
152
|
+
flattened = flattenValueTo(type, s, setter, setMapper);
|
|
153
|
+
});
|
|
154
|
+
it('sets "a" in the object', function () {
|
|
155
|
+
flattened['$.a'](2);
|
|
156
|
+
expect(s).toEqual({
|
|
157
|
+
a: 2,
|
|
158
|
+
b: false,
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
it('sets "b" in the object', function () {
|
|
162
|
+
flattened['$.b'](true);
|
|
163
|
+
expect(s).toEqual({
|
|
164
|
+
a: 1,
|
|
165
|
+
b: true,
|
|
166
|
+
});
|
|
158
167
|
});
|
|
159
168
|
});
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
169
|
+
});
|
|
170
|
+
describe('nested optional field', function () {
|
|
171
|
+
const type = object()
|
|
172
|
+
.optionalField('a', object().optionalField('b', numberType));
|
|
173
|
+
describe('empty', function () {
|
|
174
|
+
let s;
|
|
175
|
+
beforeEach(function () {
|
|
176
|
+
s = {};
|
|
177
|
+
});
|
|
178
|
+
describe('toString', function () {
|
|
179
|
+
let flattened;
|
|
180
|
+
beforeEach(function () {
|
|
181
|
+
flattened = flattenValueTo(type, s, setter, toStringMapper);
|
|
182
|
+
});
|
|
183
|
+
it('equals expected type', function () {
|
|
184
|
+
expect(flattened).toEqual({
|
|
185
|
+
$: '{}',
|
|
186
|
+
});
|
|
187
|
+
});
|
|
165
188
|
});
|
|
166
189
|
});
|
|
167
190
|
});
|
|
@@ -169,8 +192,8 @@ describe('flattenValueTypeTo', function () {
|
|
|
169
192
|
describe('union', function () {
|
|
170
193
|
describe('discriminated', function () {
|
|
171
194
|
const typeDef = union('d')
|
|
172
|
-
.
|
|
173
|
-
.
|
|
195
|
+
.or('1', object().field('a', numberType))
|
|
196
|
+
.or('2', object().field('b', booleanType));
|
|
174
197
|
let u;
|
|
175
198
|
beforeEach(function () {
|
|
176
199
|
u = {
|
|
@@ -181,7 +204,7 @@ describe('flattenValueTypeTo', function () {
|
|
|
181
204
|
describe('toString', function () {
|
|
182
205
|
let flattened;
|
|
183
206
|
beforeEach(function () {
|
|
184
|
-
flattened =
|
|
207
|
+
flattened = flattenValueTo(typeDef, u, setter, toStringMapper);
|
|
185
208
|
});
|
|
186
209
|
it('equals expected type', function () {
|
|
187
210
|
expect(flattened).toEqual({
|
|
@@ -193,7 +216,7 @@ describe('flattenValueTypeTo', function () {
|
|
|
193
216
|
describe('setter', function () {
|
|
194
217
|
let flattened;
|
|
195
218
|
beforeEach(function () {
|
|
196
|
-
flattened =
|
|
219
|
+
flattened = flattenValueTo(typeDef, u, setter, setMapper);
|
|
197
220
|
});
|
|
198
221
|
it('sets a value', function () {
|
|
199
222
|
const value = {
|
|
@@ -213,9 +236,9 @@ describe('flattenValueTypeTo', function () {
|
|
|
213
236
|
});
|
|
214
237
|
});
|
|
215
238
|
describe('non-discriminated', function () {
|
|
216
|
-
const
|
|
217
|
-
.
|
|
218
|
-
.
|
|
239
|
+
const type = union()
|
|
240
|
+
.or('0', numberType)
|
|
241
|
+
.or('1', nullType);
|
|
219
242
|
let u;
|
|
220
243
|
beforeEach(function () {
|
|
221
244
|
u = null;
|
|
@@ -223,7 +246,7 @@ describe('flattenValueTypeTo', function () {
|
|
|
223
246
|
describe('toString', function () {
|
|
224
247
|
let flattened;
|
|
225
248
|
beforeEach(function () {
|
|
226
|
-
flattened =
|
|
249
|
+
flattened = flattenValueTo(type, u, setter, toStringMapper);
|
|
227
250
|
});
|
|
228
251
|
it('equals expected type', function () {
|
|
229
252
|
expect(flattened).toEqual({
|
|
@@ -234,7 +257,7 @@ describe('flattenValueTypeTo', function () {
|
|
|
234
257
|
describe('setter', function () {
|
|
235
258
|
let flattened;
|
|
236
259
|
beforeEach(function () {
|
|
237
|
-
flattened =
|
|
260
|
+
flattened = flattenValueTo(type, u, setter, setMapper);
|
|
238
261
|
});
|
|
239
262
|
it('sets a value', function () {
|
|
240
263
|
const value = 2;
|
|
@@ -244,10 +267,10 @@ describe('flattenValueTypeTo', function () {
|
|
|
244
267
|
});
|
|
245
268
|
});
|
|
246
269
|
describe('complex non-discriminated', function () {
|
|
247
|
-
const
|
|
248
|
-
.
|
|
249
|
-
.
|
|
250
|
-
.
|
|
270
|
+
const type = union()
|
|
271
|
+
.or('z', list(numberType))
|
|
272
|
+
.or('x', nullType)
|
|
273
|
+
.or('y', literal([false]));
|
|
251
274
|
let u;
|
|
252
275
|
beforeEach(function () {
|
|
253
276
|
u = [
|
|
@@ -259,7 +282,7 @@ describe('flattenValueTypeTo', function () {
|
|
|
259
282
|
describe('toString', function () {
|
|
260
283
|
let flattened;
|
|
261
284
|
beforeEach(function () {
|
|
262
|
-
flattened =
|
|
285
|
+
flattened = flattenValueTo(type, u, setter, toStringMapper);
|
|
263
286
|
});
|
|
264
287
|
it('equals expected type', function () {
|
|
265
288
|
expect(flattened).toEqual({
|
|
@@ -273,7 +296,7 @@ describe('flattenValueTypeTo', function () {
|
|
|
273
296
|
describe('setter', function () {
|
|
274
297
|
let flattened;
|
|
275
298
|
beforeEach(function () {
|
|
276
|
-
flattened =
|
|
299
|
+
flattened = flattenValueTo(type, u, setter, setMapper);
|
|
277
300
|
});
|
|
278
301
|
it('sets the top level value', function () {
|
|
279
302
|
const value = [100];
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { flattenValuesOfType } from 'transformers/flatteners/flatten_values_of_type';
|
|
2
2
|
import { booleanType, list, numberType, object, } from 'types/builders';
|
|
3
3
|
describe('flattenValueTypesOf', function () {
|
|
4
4
|
// note that we already have tests for the type and the function that this calls, so
|
|
5
5
|
// this is only a sanity check
|
|
6
6
|
it('flattens', function () {
|
|
7
|
-
const flattened =
|
|
8
|
-
.
|
|
9
|
-
.
|
|
7
|
+
const flattened = flattenValuesOfType(object()
|
|
8
|
+
.field('a', list(numberType))
|
|
9
|
+
.field('b', booleanType), {
|
|
10
10
|
a: [
|
|
11
11
|
1,
|
|
12
12
|
2,
|
|
@@ -85,7 +85,9 @@ describe('valuePathToTypePath', function () {
|
|
|
85
85
|
});
|
|
86
86
|
});
|
|
87
87
|
describe('object', function () {
|
|
88
|
-
const typeDef = object()
|
|
88
|
+
const typeDef = object()
|
|
89
|
+
.field('a', numberType)
|
|
90
|
+
.field('b', booleanType);
|
|
89
91
|
describe.each([
|
|
90
92
|
[
|
|
91
93
|
'$',
|
|
@@ -121,8 +123,8 @@ describe('valuePathToTypePath', function () {
|
|
|
121
123
|
describe('union', function () {
|
|
122
124
|
describe('discriminated', function () {
|
|
123
125
|
const typeDef = union('w')
|
|
124
|
-
.
|
|
125
|
-
.
|
|
126
|
+
.or('x', object().field('a', numberType).field('b', booleanType))
|
|
127
|
+
.or('y', object().field('b', stringType).field('c', booleanType));
|
|
126
128
|
describe.each([
|
|
127
129
|
[
|
|
128
130
|
'$',
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type Type } from 'types/definitions';
|
|
2
|
-
export declare function valuePathToTypePath<
|
|
2
|
+
export declare function valuePathToTypePath<ValuePathsToTypePaths extends Record<string, string>, ValuePath extends keyof ValuePathsToTypePaths>({ definition: typeDef }: Type, valuePath: ValuePath, allowMissingPaths?: boolean): ValuePathsToTypePaths[ValuePath];
|