@strictly/define 0.0.1
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/.eslintrc.cjs +31 -0
- package/.out/index.d.ts +20 -0
- package/.out/index.js +20 -0
- package/.out/transformers/copies/copy.d.ts +4 -0
- package/.out/transformers/copies/copy.js +7 -0
- package/.out/transformers/copies/copy_to.d.ts +6 -0
- package/.out/transformers/copies/copy_to.js +91 -0
- package/.out/transformers/copies/mobx_copy.d.ts +5 -0
- package/.out/transformers/copies/mobx_copy.js +42 -0
- package/.out/transformers/copies/specs/copy_to.tests.d.ts +1 -0
- package/.out/transformers/copies/specs/copy_to.tests.js +97 -0
- package/.out/transformers/copies/specs/mobx_copy.tests.d.ts +1 -0
- package/.out/transformers/copies/specs/mobx_copy.tests.js +19 -0
- package/.out/transformers/flatteners/flatten_accessors_of.d.ts +5 -0
- package/.out/transformers/flatteners/flatten_accessors_of.js +11 -0
- package/.out/transformers/flatteners/flatten_json_value_to_type_paths_of.d.ts +3 -0
- package/.out/transformers/flatteners/flatten_json_value_to_type_paths_of.js +10 -0
- package/.out/transformers/flatteners/flatten_type_def_to.d.ts +4 -0
- package/.out/transformers/flatteners/flatten_type_def_to.js +49 -0
- package/.out/transformers/flatteners/flatten_type_defs_of.d.ts +3 -0
- package/.out/transformers/flatteners/flatten_type_defs_of.js +7 -0
- package/.out/transformers/flatteners/flatten_value_type_to.d.ts +11 -0
- package/.out/transformers/flatteners/flatten_value_type_to.js +79 -0
- package/.out/transformers/flatteners/flatten_value_types_of.d.ts +3 -0
- package/.out/transformers/flatteners/flatten_value_types_of.js +7 -0
- package/.out/transformers/flatteners/json_path.d.ts +2 -0
- package/.out/transformers/flatteners/json_path.js +14 -0
- package/.out/transformers/flatteners/specs/flatten_accessors_of.tests.d.ts +1 -0
- package/.out/transformers/flatteners/specs/flatten_accessors_of.tests.js +90 -0
- package/.out/transformers/flatteners/specs/flatten_json_value_to_type_paths_of.tests.d.ts +1 -0
- package/.out/transformers/flatteners/specs/flatten_json_value_to_type_paths_of.tests.js +94 -0
- package/.out/transformers/flatteners/specs/flatten_type_def_to.tests.d.ts +1 -0
- package/.out/transformers/flatteners/specs/flatten_type_def_to.tests.js +110 -0
- package/.out/transformers/flatteners/specs/flatten_type_defs_of.tests.d.ts +1 -0
- package/.out/transformers/flatteners/specs/flatten_type_defs_of.tests.js +17 -0
- package/.out/transformers/flatteners/specs/flatten_value_type_to.tests.d.ts +1 -0
- package/.out/transformers/flatteners/specs/flatten_value_type_to.tests.js +297 -0
- package/.out/transformers/flatteners/specs/flatten_value_types_of.tests.d.ts +1 -0
- package/.out/transformers/flatteners/specs/flatten_value_types_of.tests.js +37 -0
- package/.out/transformers/flatteners/specs/value_path_to_type_path.tests.d.ts +1 -0
- package/.out/transformers/flatteners/specs/value_path_to_type_path.tests.js +167 -0
- package/.out/transformers/flatteners/value_path_to_type_path.d.ts +2 -0
- package/.out/transformers/flatteners/value_path_to_type_path.js +96 -0
- package/.out/tsconfig.json +15 -0
- package/.out/tsconfig.tsbuildinfo +1 -0
- package/.out/tsup.config.d.ts +3 -0
- package/.out/tsup.config.js +12 -0
- package/.out/types/builders.d.ts +62 -0
- package/.out/types/builders.js +148 -0
- package/.out/types/definitions.d.ts +41 -0
- package/.out/types/definitions.js +26 -0
- package/.out/types/flattened.d.ts +2 -0
- package/.out/types/flattened.js +1 -0
- package/.out/types/flattened_accessors_of.d.ts +9 -0
- package/.out/types/flattened_accessors_of.js +1 -0
- package/.out/types/flattened_type_defs_of.d.ts +21 -0
- package/.out/types/flattened_type_defs_of.js +1 -0
- package/.out/types/flattened_value_types_of.d.ts +6 -0
- package/.out/types/flattened_value_types_of.js +1 -0
- package/.out/types/json_path_of.d.ts +1 -0
- package/.out/types/json_path_of.js +1 -0
- package/.out/types/json_paths_of.d.ts +16 -0
- package/.out/types/json_paths_of.js +1 -0
- package/.out/types/mobx_value_type_of.d.ts +11 -0
- package/.out/types/mobx_value_type_of.js +2 -0
- package/.out/types/partial_type_def_of.d.ts +40 -0
- package/.out/types/partial_type_def_of.js +1 -0
- package/.out/types/readonly_type_def_of.d.ts +29 -0
- package/.out/types/readonly_type_def_of.js +1 -0
- package/.out/types/specs/builder.tests.d.ts +1 -0
- package/.out/types/specs/builder.tests.js +93 -0
- package/.out/types/specs/flattened_accessors_of.tests.d.ts +1 -0
- package/.out/types/specs/flattened_accessors_of.tests.js +11 -0
- package/.out/types/specs/flattened_type_defs_of.tests.d.ts +1 -0
- package/.out/types/specs/flattened_type_defs_of.tests.js +71 -0
- package/.out/types/specs/flattened_value_types_of.tests.d.ts +1 -0
- package/.out/types/specs/flattened_value_types_of.tests.js +11 -0
- package/.out/types/specs/json_paths_of.tests.d.ts +1 -0
- package/.out/types/specs/json_paths_of.tests.js +199 -0
- package/.out/types/specs/partial_type_def_of.tests.d.ts +1 -0
- package/.out/types/specs/partial_type_def_of.tests.js +50 -0
- package/.out/types/specs/readonly_type_def_of.tests.d.ts +1 -0
- package/.out/types/specs/readonly_type_def_of.tests.js +55 -0
- package/.out/types/specs/strict_definitions.tests.d.ts +1 -0
- package/.out/types/specs/strict_definitions.tests.js +42 -0
- package/.out/types/specs/value_to_type_paths_of.tests.d.ts +1 -0
- package/.out/types/specs/value_to_type_paths_of.tests.js +90 -0
- package/.out/types/specs/value_type_of.tests.d.ts +1 -0
- package/.out/types/specs/value_type_of.tests.js +91 -0
- package/.out/types/specs/value_types_of_discriminated_union.tests.d.ts +1 -0
- package/.out/types/specs/value_types_of_discriminated_union.tests.js +9 -0
- package/.out/types/strict_definitions.d.ts +44 -0
- package/.out/types/strict_definitions.js +1 -0
- package/.out/types/value_to_type_paths_of.d.ts +22 -0
- package/.out/types/value_to_type_paths_of.js +1 -0
- package/.out/types/value_type_of.d.ts +24 -0
- package/.out/types/value_type_of.js +1 -0
- package/.out/types/value_types_of_discriminated_union.d.ts +9 -0
- package/.out/types/value_types_of_discriminated_union.js +1 -0
- package/.out/vitest.workspace.d.ts +2 -0
- package/.out/vitest.workspace.js +7 -0
- package/.turbo/turbo-build.log +18 -0
- package/.turbo/turbo-check-types.log +3 -0
- package/.turbo/turbo-release$colon$exports.log +3 -0
- package/README.md +12 -0
- package/dist/index.cjs +798 -0
- package/dist/index.d.cts +301 -0
- package/dist/index.d.ts +301 -0
- package/dist/index.js +775 -0
- package/index.ts +20 -0
- package/package.exports.json +18 -0
- package/package.json +45 -0
- package/transformers/copies/copy.ts +18 -0
- package/transformers/copies/copy_to.ts +226 -0
- package/transformers/copies/mobx_copy.ts +81 -0
- package/transformers/copies/specs/copy_to.tests.ts +143 -0
- package/transformers/copies/specs/mobx_copy.tests.ts +26 -0
- package/transformers/flatteners/flatten_accessors_of.ts +43 -0
- package/transformers/flatteners/flatten_json_value_to_type_paths_of.ts +39 -0
- package/transformers/flatteners/flatten_type_def_to.ts +127 -0
- package/transformers/flatteners/flatten_type_defs_of.ts +16 -0
- package/transformers/flatteners/flatten_value_type_to.ts +227 -0
- package/transformers/flatteners/flatten_value_types_of.ts +23 -0
- package/transformers/flatteners/json_path.ts +15 -0
- package/transformers/flatteners/specs/flatten_accessors_of.tests.ts +113 -0
- package/transformers/flatteners/specs/flatten_json_value_to_type_paths_of.tests.ts +115 -0
- package/transformers/flatteners/specs/flatten_type_def_to.tests.ts +146 -0
- package/transformers/flatteners/specs/flatten_type_defs_of.tests.ts +26 -0
- package/transformers/flatteners/specs/flatten_value_type_to.tests.ts +452 -0
- package/transformers/flatteners/specs/flatten_value_types_of.tests.ts +46 -0
- package/transformers/flatteners/specs/value_path_to_type_path.tests.ts +240 -0
- package/transformers/flatteners/value_path_to_type_path.ts +164 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +15 -0
- package/tsup.config.ts +16 -0
- package/types/builders.ts +284 -0
- package/types/definitions.ts +106 -0
- package/types/flattened.ts +5 -0
- package/types/flattened_accessors_of.ts +15 -0
- package/types/flattened_type_defs_of.ts +130 -0
- package/types/flattened_value_types_of.ts +11 -0
- package/types/json_path_of.ts +7 -0
- package/types/json_paths_of.ts +129 -0
- package/types/mobx_value_type_of.ts +16 -0
- package/types/partial_type_def_of.ts +64 -0
- package/types/readonly_type_def_of.ts +53 -0
- package/types/specs/builder.tests.ts +295 -0
- package/types/specs/flattened_accessors_of.tests.ts +27 -0
- package/types/specs/flattened_type_defs_of.tests.ts +212 -0
- package/types/specs/flattened_value_types_of.tests.ts +21 -0
- package/types/specs/json_paths_of.tests.ts +304 -0
- package/types/specs/partial_type_def_of.tests.ts +251 -0
- package/types/specs/readonly_type_def_of.tests.ts +158 -0
- package/types/specs/strict_definitions.tests.ts +184 -0
- package/types/specs/value_to_type_paths_of.tests.ts +181 -0
- package/types/specs/value_type_of.tests.ts +329 -0
- package/types/specs/value_types_of_discriminated_union.tests.ts +30 -0
- package/types/strict_definitions.ts +107 -0
- package/types/value_to_type_paths_of.ts +184 -0
- package/types/value_type_of.ts +84 -0
- package/types/value_types_of_discriminated_union.ts +14 -0
- package/vitest.workspace.ts +11 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { numberType, record, } from 'types/builders';
|
|
2
|
+
describe('FlattenedValueTypesOf', 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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { booleanType, list, nullable, numberType, object, record, stringType, union, } from 'types/builders';
|
|
2
|
+
describe('JsonPathsOf', function () {
|
|
3
|
+
describe('literal', function () {
|
|
4
|
+
let path;
|
|
5
|
+
describe('regular', function () {
|
|
6
|
+
it('equals expected type', function () {
|
|
7
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
describe('nullable', function () {
|
|
11
|
+
const builder = nullable(stringType);
|
|
12
|
+
it('equals expected type', function () {
|
|
13
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe('list', function () {
|
|
18
|
+
let path;
|
|
19
|
+
describe('mutable', function () {
|
|
20
|
+
const builder = list(stringType);
|
|
21
|
+
it('equals expected type', function () {
|
|
22
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('readonly', function () {
|
|
26
|
+
const builder = list(stringType).readonly();
|
|
27
|
+
it('equals expected type', function () {
|
|
28
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('nullable', function () {
|
|
32
|
+
const builder = nullable(list(stringType));
|
|
33
|
+
it('equals expected type', function () {
|
|
34
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('override', function () {
|
|
38
|
+
const builder = list(stringType);
|
|
39
|
+
let path;
|
|
40
|
+
it('equals expected type', function () {
|
|
41
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe('record', function () {
|
|
46
|
+
let path;
|
|
47
|
+
describe('mutable', function () {
|
|
48
|
+
const builder = record(stringType);
|
|
49
|
+
it('equals expected type', function () {
|
|
50
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('mutable with exact keys', function () {
|
|
54
|
+
const builder = record(stringType);
|
|
55
|
+
let path;
|
|
56
|
+
it('equals expected type', function () {
|
|
57
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('mutable with numeric keys', function () {
|
|
61
|
+
const builder = record(stringType);
|
|
62
|
+
let path;
|
|
63
|
+
it('equals expected type', function () {
|
|
64
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe('readonly', function () {
|
|
68
|
+
const builder = record(stringType).readonly();
|
|
69
|
+
it('equals expected type', function () {
|
|
70
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('partial', function () {
|
|
74
|
+
const builder = record(stringType).partial();
|
|
75
|
+
it('equals expected type', function () {
|
|
76
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe('nullable', function () {
|
|
80
|
+
const builder = nullable(record(stringType));
|
|
81
|
+
it('equals expected type', function () {
|
|
82
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('override', function () {
|
|
86
|
+
const builder = record(stringType);
|
|
87
|
+
let path;
|
|
88
|
+
it('equals expected type', function () {
|
|
89
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('object', function () {
|
|
94
|
+
describe('simple', function () {
|
|
95
|
+
const builder = object()
|
|
96
|
+
.set('n', numberType)
|
|
97
|
+
.set('b', booleanType)
|
|
98
|
+
.set('s', stringType);
|
|
99
|
+
let path;
|
|
100
|
+
it('equals expected type', function () {
|
|
101
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
102
|
+
});
|
|
103
|
+
it('can be used in a record', function () {
|
|
104
|
+
expectTypeOf({
|
|
105
|
+
['$']: 's1',
|
|
106
|
+
['$.n']: 's2',
|
|
107
|
+
['$.b']: 's3',
|
|
108
|
+
['$.s']: 's4',
|
|
109
|
+
}).toEqualTypeOf();
|
|
110
|
+
});
|
|
111
|
+
it('ignores override', function () {
|
|
112
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe('nested', function () {
|
|
116
|
+
const builder = object()
|
|
117
|
+
.set('s1', object().set('a1', booleanType))
|
|
118
|
+
.set('s2', object().set('a2', stringType));
|
|
119
|
+
let path;
|
|
120
|
+
it('equals expected type', function () {
|
|
121
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
describe('object of list', function () {
|
|
125
|
+
const builder = object()
|
|
126
|
+
.set('l', list(numberType));
|
|
127
|
+
describe('no override', function () {
|
|
128
|
+
let path;
|
|
129
|
+
it('equals expected type', function () {
|
|
130
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
describe('passes override', function () {
|
|
134
|
+
let path;
|
|
135
|
+
it('equals expected type', function () {
|
|
136
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
describe('union', function () {
|
|
142
|
+
describe('with primitives', function () {
|
|
143
|
+
const builder = union()
|
|
144
|
+
.add('1', numberType)
|
|
145
|
+
.add('2', stringType);
|
|
146
|
+
let path;
|
|
147
|
+
it('equals expected type', function () {
|
|
148
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
describe('with overlapping record', function () {
|
|
152
|
+
const builder = union()
|
|
153
|
+
.add('1', object().set('a', numberType).set('b', stringType))
|
|
154
|
+
.add('2', object().set('b', stringType).set('c', stringType))
|
|
155
|
+
.add('3', object().set('c', stringType).set('a', stringType));
|
|
156
|
+
let path;
|
|
157
|
+
it('equals expected type', function () {
|
|
158
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe('nested', function () {
|
|
162
|
+
const builder = union()
|
|
163
|
+
.add('1', object().set('a', union().add('x', object().set('aa', stringType))))
|
|
164
|
+
.add('2', object().set('b', union().add('y', object().set('bb', stringType))));
|
|
165
|
+
let path;
|
|
166
|
+
it('equals expected type', function () {
|
|
167
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
describe('with discriminator', function () {
|
|
172
|
+
const builder = union('x')
|
|
173
|
+
.add('1', object().set('a', booleanType))
|
|
174
|
+
.add('2', object().set('b', numberType));
|
|
175
|
+
let path;
|
|
176
|
+
it('equals expected type', function () {
|
|
177
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
describe('with nested discriminator', function () {
|
|
181
|
+
const builder = union('x')
|
|
182
|
+
.add('1', union('y').add('p', object().set('a', booleanType)))
|
|
183
|
+
.add('2', union('z').add('q', object().set('b', numberType)));
|
|
184
|
+
let path;
|
|
185
|
+
it('equals expected type', function () {
|
|
186
|
+
expectTypeOf(path).toEqualTypeOf();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
// breaks linting
|
|
190
|
+
// describe('infinite recursion', function () {
|
|
191
|
+
// function f<T extends Type>(t: T): JsonPathsOf<T> {
|
|
192
|
+
// return JSON.stringify(t) as JsonPathsOf<T>
|
|
193
|
+
// }
|
|
194
|
+
// it('compiles', function () {
|
|
195
|
+
// const builder = list(string)
|
|
196
|
+
// expect(f(builder)).toBeDefined();
|
|
197
|
+
// })
|
|
198
|
+
// })
|
|
199
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { list, numberType, object, record, stringType, union, } from 'types/builders';
|
|
2
|
+
describe('PartialTypeDefOf', function () {
|
|
3
|
+
describe('literal', function () {
|
|
4
|
+
let t;
|
|
5
|
+
it('equals expected type', function () {
|
|
6
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
describe('list', function () {
|
|
10
|
+
const builder = list(numberType);
|
|
11
|
+
let t;
|
|
12
|
+
it('equals expected type', function () {
|
|
13
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe('record', function () {
|
|
17
|
+
const builder = record(numberType);
|
|
18
|
+
let t;
|
|
19
|
+
it('equals expected type', function () {
|
|
20
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe('object', function () {
|
|
24
|
+
const builder = object()
|
|
25
|
+
.set('a', numberType)
|
|
26
|
+
.setReadonly('b', stringType);
|
|
27
|
+
let t;
|
|
28
|
+
it('equals expected type', function () {
|
|
29
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe('union', function () {
|
|
33
|
+
describe('simple', function () {
|
|
34
|
+
const builder = union()
|
|
35
|
+
.add('1', numberType)
|
|
36
|
+
.add('2', stringType);
|
|
37
|
+
let t;
|
|
38
|
+
it('equals expected type', function () {
|
|
39
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('readonly', function () {
|
|
44
|
+
const builder = list(numberType).readonly();
|
|
45
|
+
let t;
|
|
46
|
+
it('equals expected type', function () {
|
|
47
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { list, numberType, object, record, stringType, union, } from 'types/builders';
|
|
2
|
+
describe('ReadonlyTypeDefOf', function () {
|
|
3
|
+
describe('literal', function () {
|
|
4
|
+
let t;
|
|
5
|
+
it('equals expected type', function () {
|
|
6
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
describe('list', function () {
|
|
10
|
+
const builder = list(numberType);
|
|
11
|
+
let t;
|
|
12
|
+
it('equals expected type', function () {
|
|
13
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe('record', function () {
|
|
17
|
+
const builder = record(numberType);
|
|
18
|
+
let t;
|
|
19
|
+
it('equals expected type', function () {
|
|
20
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe('object', function () {
|
|
24
|
+
const builder = object()
|
|
25
|
+
.set('a', numberType)
|
|
26
|
+
.setOptional('b', stringType);
|
|
27
|
+
let t;
|
|
28
|
+
it('equals expected type', function () {
|
|
29
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe('union', function () {
|
|
33
|
+
const builder = union()
|
|
34
|
+
.add('1', record(numberType))
|
|
35
|
+
.add('2', stringType);
|
|
36
|
+
let t;
|
|
37
|
+
it('equals expected type', function () {
|
|
38
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('partial', function () {
|
|
42
|
+
const builder = record(numberType).partial();
|
|
43
|
+
let t;
|
|
44
|
+
it('equals expected type', function () {
|
|
45
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
describe('readonly', function () {
|
|
49
|
+
const builder = record(numberType).readonly();
|
|
50
|
+
let t;
|
|
51
|
+
it('equals expected type', function () {
|
|
52
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
describe('Strict Definitions', function () {
|
|
2
|
+
describe('IsStrictUnion', function () {
|
|
3
|
+
it('detects a non-discriminated strict union', function () {
|
|
4
|
+
expectTypeOf().toEqualTypeOf();
|
|
5
|
+
});
|
|
6
|
+
it('detects a union with a non-literal type', function () {
|
|
7
|
+
expectTypeOf().toEqualTypeOf();
|
|
8
|
+
});
|
|
9
|
+
it('detects a union with a non-literal type in position 0', function () {
|
|
10
|
+
expectTypeOf().toEqualTypeOf();
|
|
11
|
+
});
|
|
12
|
+
it('detects a non-discriminated strict union with multiple options and a non-literal type', function () {
|
|
13
|
+
expectTypeOf().toEqualTypeOf();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe('StrictUnion', function () {
|
|
17
|
+
it('enforces non-strict unions are of type never', function () {
|
|
18
|
+
expectTypeOf().toEqualTypeOf();
|
|
19
|
+
});
|
|
20
|
+
it('allows unions of multiple literal options', function () {
|
|
21
|
+
expectTypeOf().toEqualTypeOf();
|
|
22
|
+
});
|
|
23
|
+
it('allows unions of multiple literal options and one complex type', function () {
|
|
24
|
+
expectTypeOf().toEqualTypeOf();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('assignment', function () {
|
|
28
|
+
describe('can be assigned to a non-strict equivalent type', function () {
|
|
29
|
+
let t;
|
|
30
|
+
it('equals type', function () {
|
|
31
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('cannot be assigned to an invalid non-strict equivalent type', function () {
|
|
36
|
+
let t;
|
|
37
|
+
it('equals type', function () {
|
|
38
|
+
expectTypeOf().not.toMatchTypeOf(t);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { booleanType, list, nullable, numberType, object, record, stringType, union, } from 'types/builders';
|
|
2
|
+
describe('FlattenedJsonPathsOf', function () {
|
|
3
|
+
describe('literal', function () {
|
|
4
|
+
let t;
|
|
5
|
+
it('equals expected type', function () {
|
|
6
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
describe('list', function () {
|
|
10
|
+
const builder = list(list(numberType));
|
|
11
|
+
let t;
|
|
12
|
+
it('equals expected type', function () {
|
|
13
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe('record', function () {
|
|
17
|
+
const l = list(numberType);
|
|
18
|
+
const builder = record(l);
|
|
19
|
+
let t;
|
|
20
|
+
it('equals expected type', function () {
|
|
21
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
22
|
+
});
|
|
23
|
+
it('allows lookup of type path', function () {
|
|
24
|
+
expectTypeOf().toEqualTypeOf();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('object', function () {
|
|
28
|
+
const builder = object()
|
|
29
|
+
.set('a', list(numberType))
|
|
30
|
+
.setOptional('b', booleanType)
|
|
31
|
+
.setReadonly('c', stringType)
|
|
32
|
+
.setReadonlyOptional('d', stringType);
|
|
33
|
+
let t;
|
|
34
|
+
it('equals expected type', function () {
|
|
35
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
36
|
+
});
|
|
37
|
+
it('has the same value paths', function () {
|
|
38
|
+
expectTypeOf().toEqualTypeOf();
|
|
39
|
+
});
|
|
40
|
+
it('has the same type paths', function () {
|
|
41
|
+
expectTypeOf().toEqualTypeOf();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe('union', function () {
|
|
45
|
+
describe('non-discriminated', function () {
|
|
46
|
+
const builder = union()
|
|
47
|
+
.add('1', list(numberType))
|
|
48
|
+
.add('2', stringType);
|
|
49
|
+
let t;
|
|
50
|
+
it('equals expected type', function () {
|
|
51
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('discriminated', function () {
|
|
55
|
+
const builder = union('d')
|
|
56
|
+
.add('1', object().set('a', booleanType).set('b', numberType))
|
|
57
|
+
.add('2', object().set('x', numberType).set('y', stringType));
|
|
58
|
+
let t;
|
|
59
|
+
it('equals expected type', function () {
|
|
60
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
61
|
+
});
|
|
62
|
+
it('has the same value paths', function () {
|
|
63
|
+
expectTypeOf().toEqualTypeOf();
|
|
64
|
+
});
|
|
65
|
+
it('has the same type paths', function () {
|
|
66
|
+
expectTypeOf().toEqualTypeOf();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('readonly', function () {
|
|
71
|
+
const builder = list(list(numberType)).readonly();
|
|
72
|
+
let t;
|
|
73
|
+
it('equals expected type', function () {
|
|
74
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe('nullable', function () {
|
|
78
|
+
const builder = nullable(list(nullable(list(numberType))));
|
|
79
|
+
let t;
|
|
80
|
+
it('equals expected type', function () {
|
|
81
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
82
|
+
});
|
|
83
|
+
it('has the same value paths', function () {
|
|
84
|
+
expectTypeOf().toEqualTypeOf();
|
|
85
|
+
});
|
|
86
|
+
it('has the same type paths', function () {
|
|
87
|
+
expectTypeOf().toEqualTypeOf();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
describe('ValueTypeOf', function () {
|
|
2
|
+
describe('literal', function () {
|
|
3
|
+
let t;
|
|
4
|
+
it('equals expected type', function () {
|
|
5
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
6
|
+
});
|
|
7
|
+
});
|
|
8
|
+
describe('list', function () {
|
|
9
|
+
describe('simple', function () {
|
|
10
|
+
describe('mutable', function () {
|
|
11
|
+
let a;
|
|
12
|
+
it('equals expected type', function () {
|
|
13
|
+
expectTypeOf(a).toEqualTypeOf();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe('readonly', function () {
|
|
17
|
+
let a;
|
|
18
|
+
it('equals expected type', function () {
|
|
19
|
+
expectTypeOf(a).toEqualTypeOf();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('record', function () {
|
|
25
|
+
describe('mutable', function () {
|
|
26
|
+
let t;
|
|
27
|
+
it('equals expected type', function () {
|
|
28
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('readonly', function () {
|
|
32
|
+
let r;
|
|
33
|
+
it('equals expected type', function () {
|
|
34
|
+
expectTypeOf(r).toEqualTypeOf();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('partial', function () {
|
|
38
|
+
let t;
|
|
39
|
+
it('equals expected type', function () {
|
|
40
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('partial readonly', function () {
|
|
44
|
+
let t;
|
|
45
|
+
it('equals expected type', function () {
|
|
46
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('object', function () {
|
|
51
|
+
describe('mutable', function () {
|
|
52
|
+
let value;
|
|
53
|
+
it('equals expected type', function () {
|
|
54
|
+
expectTypeOf(value).toEqualTypeOf();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('readonly', function () {
|
|
58
|
+
let value;
|
|
59
|
+
it('equals expected type', function () {
|
|
60
|
+
expectTypeOf(value).toEqualTypeOf();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe('partial', function () {
|
|
64
|
+
let v;
|
|
65
|
+
it('equals expected type', function () {
|
|
66
|
+
expectTypeOf(v).toEqualTypeOf();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('union', function () {
|
|
71
|
+
describe('non-discriminated', function () {
|
|
72
|
+
let t;
|
|
73
|
+
it('equals expected type', function () {
|
|
74
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe('implicitly discriminated', function () {
|
|
78
|
+
let t;
|
|
79
|
+
it('equals expected type', function () {
|
|
80
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('explicitly discriminated', function () {
|
|
84
|
+
let t;
|
|
85
|
+
it('equals expected type', function () {
|
|
86
|
+
expectTypeOf(t).toEqualTypeOf();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { booleanType, numberType, object, union, } from 'types/builders';
|
|
2
|
+
describe('ValueTypesOfDiscriminatedUnion', function () {
|
|
3
|
+
it('matches expected type', function () {
|
|
4
|
+
const { definition } = union('d')
|
|
5
|
+
.add('a', object().set('x', numberType))
|
|
6
|
+
.add('b', object().set('y', booleanType));
|
|
7
|
+
expectTypeOf().toEqualTypeOf();
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type IsEqual, type Simplify } from 'type-fest';
|
|
2
|
+
import { type ObjectFieldKey, type RecordKeyType, type TypeDefType, type UnionKey } from './definitions';
|
|
3
|
+
export type StrictType<T extends StrictTypeDef = StrictTypeDef> = {
|
|
4
|
+
readonly definition: T;
|
|
5
|
+
};
|
|
6
|
+
export type StrictTypeDef = StrictLiteralTypeDef | StrictListTypeDef | StrictRecordTypeDef | StrictObjectTypeDef | StrictUnionTypeDef;
|
|
7
|
+
type AnyTypeDef = any;
|
|
8
|
+
export type StrictLiteralTypeDef<V = any> = {
|
|
9
|
+
readonly type: TypeDefType.Literal;
|
|
10
|
+
readonly valuePrototype: [V];
|
|
11
|
+
};
|
|
12
|
+
export type StrictListTypeDef<E extends StrictTypeDef = AnyTypeDef> = {
|
|
13
|
+
readonly type: TypeDefType.List;
|
|
14
|
+
readonly elements: E;
|
|
15
|
+
};
|
|
16
|
+
export type StrictRecordTypeDef<K extends RecordKeyType = RecordKeyType, V extends StrictTypeDef | undefined = AnyTypeDef> = {
|
|
17
|
+
readonly type: TypeDefType.Record;
|
|
18
|
+
readonly keyPrototype: K;
|
|
19
|
+
readonly valueTypeDef: V;
|
|
20
|
+
};
|
|
21
|
+
export type StrictStructuredTypeDefFields = {
|
|
22
|
+
[Key: ObjectFieldKey]: AnyTypeDef;
|
|
23
|
+
};
|
|
24
|
+
export type StrictObjectTypeDef<Fields extends StrictStructuredTypeDefFields = StrictStructuredTypeDefFields> = {
|
|
25
|
+
readonly type: TypeDefType.Object;
|
|
26
|
+
readonly fields: Fields;
|
|
27
|
+
};
|
|
28
|
+
export type StrictUnionTypeDef<D extends string | null = string | null, U extends Readonly<Record<UnionKey, AnyTypeDef>> = Readonly<Record<UnionKey, AnyTypeDef>>> = D extends null ? IsStrictUnion<U> extends true ? {
|
|
29
|
+
readonly discriminator: null;
|
|
30
|
+
readonly type: TypeDefType.Union;
|
|
31
|
+
readonly unions: U;
|
|
32
|
+
} : never : {
|
|
33
|
+
readonly discriminator: D;
|
|
34
|
+
readonly type: TypeDefType.Union;
|
|
35
|
+
readonly unions: U;
|
|
36
|
+
};
|
|
37
|
+
export type IsStrictUnion<U extends Readonly<Record<UnionKey, AnyTypeDef>>> = IsEqual<U, Simplify<{
|
|
38
|
+
readonly [K in keyof Omit<U, '0'> as U[K] extends StrictLiteralTypeDef ? K : never]: U[K];
|
|
39
|
+
} & (U extends {
|
|
40
|
+
readonly ['0']: AnyTypeDef;
|
|
41
|
+
} ? {
|
|
42
|
+
readonly ['0']: U['0'];
|
|
43
|
+
} : {})>>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type SimplifyDeep, type UnionToIntersection } from 'type-fest';
|
|
2
|
+
import { type ListTypeDef, type LiteralTypeDef, type ObjectTypeDef, type RecordTypeDef, type TypeDef, type UnionTypeDef } from './definitions';
|
|
3
|
+
import { type Depths, type StartingDepth } from './flattened';
|
|
4
|
+
import { type JsonPathOf } from './json_path_of';
|
|
5
|
+
import { type StrictType } from './strict_definitions';
|
|
6
|
+
export type ValueToTypePathsOf<T extends StrictType, SegmentOverride extends string = '*', Path extends string = '$'> = SimplifyDeep<InternalFlattenedJsonPathsOf<T['definition'], SegmentOverride, Path, Path, StartingDepth>>;
|
|
7
|
+
type InternalFlattenedJsonPathsOf<T extends TypeDef, SegmentOverride extends string, ValuePath extends string, TypePath extends string, Depth extends number> = {
|
|
8
|
+
readonly [K in ValuePath]: TypePath;
|
|
9
|
+
} & InternalFlattenedJsonPathsOfChildren<T, SegmentOverride, ValuePath, TypePath, '', Depth>;
|
|
10
|
+
type InternalFlattenedJsonPathsOfChildren<T extends TypeDef, SegmentOverride extends string, ValuePath extends string, TypePath extends string, Qualifier extends string, Depth extends number, NextDepth extends number = Depths[Depth]> = NextDepth extends -1 ? never : T extends LiteralTypeDef ? InternalFlattenedJsonPathsOfLiteralChildren : T extends ListTypeDef ? InternalFlattenedJsonPathsOfListChildren<T, SegmentOverride, ValuePath, TypePath, NextDepth> : T extends RecordTypeDef ? InternalFlattenedJsonPathsOfRecordChildren<T, SegmentOverride, ValuePath, TypePath, NextDepth> : T extends ObjectTypeDef ? InternalFlattenedJsonPathsOfObjectChildren<T, SegmentOverride, ValuePath, TypePath, Qualifier, NextDepth> : T extends UnionTypeDef ? InternalFlattenedJsonPathsOfUnionChildren<T, SegmentOverride, ValuePath, TypePath, Qualifier, NextDepth> : never;
|
|
11
|
+
type InternalFlattenedJsonPathsOfLiteralChildren = {};
|
|
12
|
+
type InternalFlattenedJsonPathsOfListChildren<T extends ListTypeDef, SegmentOverride extends string, ValuePath extends string, TypePath extends string, Depth extends number> = InternalFlattenedJsonPathsOf<T['elements'], SegmentOverride, JsonPathOf<ValuePath, number>, JsonPathOf<TypePath, number, SegmentOverride>, Depth>;
|
|
13
|
+
type InternalFlattenedJsonPathsOfRecordChildren<T extends RecordTypeDef, SegmentOverride extends string, ValuePath extends string, TypePath extends string, Depth extends number> = InternalFlattenedJsonPathsOf<T['valueTypeDef'], SegmentOverride, JsonPathOf<ValuePath, T['keyPrototype']>, JsonPathOf<TypePath, T['keyPrototype'], SegmentOverride>, Depth>;
|
|
14
|
+
type InternalFlattenedJsonPathsOfObjectChildren<T extends ObjectTypeDef, SegmentOverride extends string, ValuePath extends string, TypePath extends string, Qualifier extends string, Depth extends number> = T extends ObjectTypeDef<infer Fields> ? keyof Fields extends string ? UnionToIntersection<{
|
|
15
|
+
readonly [K in keyof Fields]-?: InternalFlattenedJsonPathsOf<Exclude<Fields[K], undefined>, SegmentOverride, JsonPathOf<ValuePath, `${Qualifier}${K}`>, JsonPathOf<TypePath, `${Qualifier}${K}`>, Depth>;
|
|
16
|
+
}[keyof Fields]> : never : never;
|
|
17
|
+
type InternalFlattenedJsonPathsOfUnionChildren<T extends UnionTypeDef, SegmentOverride extends string, ValuePath extends string, TypePath extends string, Qualifier extends string, Depth extends number> = T extends UnionTypeDef<infer D, infer Unions> ? keyof Unions extends string ? D extends null ? UnionToIntersection<{
|
|
18
|
+
readonly [K in keyof Unions]: InternalFlattenedJsonPathsOfChildren<Unions[K], SegmentOverride, ValuePath, TypePath, '', Depth>;
|
|
19
|
+
}[keyof Unions]> : UnionToIntersection<{
|
|
20
|
+
readonly [K in keyof Unions]: InternalFlattenedJsonPathsOfChildren<Unions[K], SegmentOverride, ValuePath, TypePath, `${Qualifier}${K}:`, Depth>;
|
|
21
|
+
}[keyof Unions]> : never : never;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|