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