@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,304 @@
|
|
|
1
|
+
import {
|
|
2
|
+
booleanType,
|
|
3
|
+
list,
|
|
4
|
+
nullable,
|
|
5
|
+
numberType,
|
|
6
|
+
object,
|
|
7
|
+
record,
|
|
8
|
+
stringType,
|
|
9
|
+
union,
|
|
10
|
+
} from 'types/builders'
|
|
11
|
+
import { type JsonPathsOf } from 'types/json_paths_of'
|
|
12
|
+
|
|
13
|
+
describe('JsonPathsOf', function () {
|
|
14
|
+
describe('literal', function () {
|
|
15
|
+
let path: '$'
|
|
16
|
+
|
|
17
|
+
describe('regular', function () {
|
|
18
|
+
type T = JsonPathsOf<typeof stringType>
|
|
19
|
+
|
|
20
|
+
it('equals expected type', function () {
|
|
21
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe('nullable', function () {
|
|
26
|
+
const builder = nullable(stringType)
|
|
27
|
+
type T = JsonPathsOf<typeof builder>
|
|
28
|
+
|
|
29
|
+
it('equals expected type', function () {
|
|
30
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
describe('list', function () {
|
|
36
|
+
let path: '$' | `$.${number}`
|
|
37
|
+
|
|
38
|
+
describe('mutable', function () {
|
|
39
|
+
const builder = list(stringType)
|
|
40
|
+
type T = JsonPathsOf<typeof builder>
|
|
41
|
+
|
|
42
|
+
it('equals expected type', function () {
|
|
43
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
describe('readonly', function () {
|
|
48
|
+
const builder = list(stringType).readonly()
|
|
49
|
+
type T = JsonPathsOf<typeof builder>
|
|
50
|
+
|
|
51
|
+
it('equals expected type', function () {
|
|
52
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
describe('nullable', function () {
|
|
57
|
+
const builder = nullable(list(stringType))
|
|
58
|
+
type T = JsonPathsOf<typeof builder>
|
|
59
|
+
|
|
60
|
+
it('equals expected type', function () {
|
|
61
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
describe('override', function () {
|
|
66
|
+
const builder = list(stringType)
|
|
67
|
+
type T = JsonPathsOf<typeof builder, 'o'>
|
|
68
|
+
|
|
69
|
+
let path: '$' | `$.o`
|
|
70
|
+
it('equals expected type', function () {
|
|
71
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe('record', function () {
|
|
77
|
+
let path: '$' | `$.${string}` | `$.${number}`
|
|
78
|
+
|
|
79
|
+
describe('mutable', function () {
|
|
80
|
+
const builder = record(stringType)
|
|
81
|
+
type T = JsonPathsOf<typeof builder>
|
|
82
|
+
|
|
83
|
+
it('equals expected type', function () {
|
|
84
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
describe('mutable with exact keys', function () {
|
|
89
|
+
const builder = record<typeof stringType, 'a' | 'b'>(stringType)
|
|
90
|
+
type T = JsonPathsOf<typeof builder>
|
|
91
|
+
|
|
92
|
+
let path: '$' | '$.a' | '$.b'
|
|
93
|
+
it('equals expected type', function () {
|
|
94
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
describe('mutable with numeric keys', function () {
|
|
99
|
+
const builder = record<typeof stringType, 1 | 2 | 3>(stringType)
|
|
100
|
+
type T = JsonPathsOf<typeof builder>
|
|
101
|
+
|
|
102
|
+
let path: '$' | '$.1' | '$.2' | '$.3'
|
|
103
|
+
it('equals expected type', function () {
|
|
104
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
describe('readonly', function () {
|
|
109
|
+
const builder = record(stringType).readonly()
|
|
110
|
+
type T = JsonPathsOf<typeof builder>
|
|
111
|
+
|
|
112
|
+
it('equals expected type', function () {
|
|
113
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
describe('partial', function () {
|
|
118
|
+
const builder = record(stringType).partial()
|
|
119
|
+
type T = JsonPathsOf<typeof builder>
|
|
120
|
+
|
|
121
|
+
it('equals expected type', function () {
|
|
122
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
describe('nullable', function () {
|
|
127
|
+
const builder = nullable(record(stringType))
|
|
128
|
+
type T = JsonPathsOf<typeof builder>
|
|
129
|
+
|
|
130
|
+
it('equals expected type', function () {
|
|
131
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
describe('override', function () {
|
|
136
|
+
const builder = record(stringType)
|
|
137
|
+
type T = JsonPathsOf<typeof builder, 'x'>
|
|
138
|
+
|
|
139
|
+
let path: '$' | '$.x'
|
|
140
|
+
it('equals expected type', function () {
|
|
141
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
describe('object', function () {
|
|
147
|
+
describe('simple', function () {
|
|
148
|
+
const builder = object()
|
|
149
|
+
.set('n', numberType)
|
|
150
|
+
.set('b', booleanType)
|
|
151
|
+
.set('s', stringType)
|
|
152
|
+
type T = JsonPathsOf<typeof builder>
|
|
153
|
+
|
|
154
|
+
let path: '$' | '$.n' | '$.b' | '$.s'
|
|
155
|
+
it('equals expected type', function () {
|
|
156
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it('can be used in a record', function () {
|
|
160
|
+
// using our types in a map has previously caused TSC to crash or
|
|
161
|
+
// complain about infinitely deep types
|
|
162
|
+
type M = Record<T, string>
|
|
163
|
+
|
|
164
|
+
expectTypeOf({
|
|
165
|
+
['$']: 's1',
|
|
166
|
+
['$.n']: 's2',
|
|
167
|
+
['$.b']: 's3',
|
|
168
|
+
['$.s']: 's4',
|
|
169
|
+
}).toEqualTypeOf<M>()
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
it('ignores override', function () {
|
|
173
|
+
type T = JsonPathsOf<typeof builder, 'y'>
|
|
174
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
describe('nested', function () {
|
|
179
|
+
const builder = object()
|
|
180
|
+
.set('s1', object().set('a1', booleanType))
|
|
181
|
+
.set('s2', object().set('a2', stringType))
|
|
182
|
+
type T = JsonPathsOf<typeof builder>
|
|
183
|
+
|
|
184
|
+
let path: '$' | '$.s1' | '$.s1.a1' | '$.s2' | '$.s2.a2'
|
|
185
|
+
it('equals expected type', function () {
|
|
186
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
describe('object of list', function () {
|
|
191
|
+
const builder = object()
|
|
192
|
+
.set('l', list(numberType))
|
|
193
|
+
|
|
194
|
+
describe('no override', function () {
|
|
195
|
+
type T = JsonPathsOf<typeof builder>
|
|
196
|
+
|
|
197
|
+
let path: '$' | '$.l' | `$.l.${number}`
|
|
198
|
+
it('equals expected type', function () {
|
|
199
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
describe('passes override', function () {
|
|
204
|
+
type T = JsonPathsOf<typeof builder, 'o'>
|
|
205
|
+
|
|
206
|
+
let path: '$' | '$.l' | '$.l.o'
|
|
207
|
+
it('equals expected type', function () {
|
|
208
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
209
|
+
})
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
describe('union', function () {
|
|
215
|
+
describe('with primitives', function () {
|
|
216
|
+
const builder = union()
|
|
217
|
+
.add('1', numberType)
|
|
218
|
+
.add('2', stringType)
|
|
219
|
+
type T = JsonPathsOf<typeof builder>
|
|
220
|
+
|
|
221
|
+
let path: '$'
|
|
222
|
+
it('equals expected type', function () {
|
|
223
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
224
|
+
})
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
describe('with overlapping record', function () {
|
|
228
|
+
const builder = union()
|
|
229
|
+
.add('1', object().set('a', numberType).set('b', stringType))
|
|
230
|
+
.add('2', object().set('b', stringType).set('c', stringType))
|
|
231
|
+
.add('3', object().set('c', stringType).set('a', stringType))
|
|
232
|
+
type T = JsonPathsOf<typeof builder>
|
|
233
|
+
|
|
234
|
+
let path: '$' | '$.a' | '$.b' | '$.c'
|
|
235
|
+
it('equals expected type', function () {
|
|
236
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
237
|
+
})
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
describe('nested', function () {
|
|
241
|
+
const builder = union()
|
|
242
|
+
.add('1', object().set(
|
|
243
|
+
'a',
|
|
244
|
+
union().add('x', object().set('aa', stringType)),
|
|
245
|
+
))
|
|
246
|
+
.add('2', object().set(
|
|
247
|
+
'b',
|
|
248
|
+
union().add('y', object().set('bb', stringType)),
|
|
249
|
+
))
|
|
250
|
+
type T = JsonPathsOf<typeof builder>
|
|
251
|
+
|
|
252
|
+
let path: '$' | '$.a' | '$.a.aa' | '$.b' | '$.b.bb'
|
|
253
|
+
it('equals expected type', function () {
|
|
254
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
255
|
+
})
|
|
256
|
+
})
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
describe('with discriminator', function () {
|
|
260
|
+
const builder = union('x')
|
|
261
|
+
.add('1', object().set('a', booleanType))
|
|
262
|
+
.add('2', object().set('b', numberType))
|
|
263
|
+
|
|
264
|
+
type T = JsonPathsOf<typeof builder>
|
|
265
|
+
|
|
266
|
+
let path: '$' | '$.1:a' | '$.2:b'
|
|
267
|
+
|
|
268
|
+
it('equals expected type', function () {
|
|
269
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
270
|
+
})
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
describe('with nested discriminator', function () {
|
|
274
|
+
const builder = union('x')
|
|
275
|
+
.add(
|
|
276
|
+
'1',
|
|
277
|
+
union('y').add('p', object().set('a', booleanType)),
|
|
278
|
+
)
|
|
279
|
+
.add(
|
|
280
|
+
'2',
|
|
281
|
+
union('z').add('q', object().set('b', numberType)),
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
type T = JsonPathsOf<typeof builder>
|
|
285
|
+
|
|
286
|
+
let path: '$' | '$.1:p:a' | '$.2:q:b'
|
|
287
|
+
|
|
288
|
+
it('equals expected type', function () {
|
|
289
|
+
expectTypeOf(path).toEqualTypeOf<T>()
|
|
290
|
+
})
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
// breaks linting
|
|
294
|
+
// describe('infinite recursion', function () {
|
|
295
|
+
// function f<T extends Type>(t: T): JsonPathsOf<T> {
|
|
296
|
+
// return JSON.stringify(t) as JsonPathsOf<T>
|
|
297
|
+
// }
|
|
298
|
+
// it('compiles', function () {
|
|
299
|
+
// const builder = list(string)
|
|
300
|
+
|
|
301
|
+
// expect(f(builder)).toBeDefined();
|
|
302
|
+
// })
|
|
303
|
+
// })
|
|
304
|
+
})
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { type SimplifyDeep } from 'type-fest'
|
|
2
|
+
import {
|
|
3
|
+
list,
|
|
4
|
+
numberType,
|
|
5
|
+
object,
|
|
6
|
+
record,
|
|
7
|
+
stringType,
|
|
8
|
+
union,
|
|
9
|
+
} from 'types/builders'
|
|
10
|
+
import { type TypeDefType } from 'types/definitions'
|
|
11
|
+
import { type PartialTypeDefOf } from 'types/partial_type_def_of'
|
|
12
|
+
|
|
13
|
+
describe('PartialTypeDefOf', function () {
|
|
14
|
+
describe('literal', function () {
|
|
15
|
+
type T = PartialTypeDefOf<typeof numberType>
|
|
16
|
+
|
|
17
|
+
let t: {
|
|
18
|
+
readonly typeDef: {
|
|
19
|
+
readonly type: TypeDefType.Union,
|
|
20
|
+
readonly discriminator: null,
|
|
21
|
+
readonly unions: {
|
|
22
|
+
readonly [0]: {
|
|
23
|
+
readonly type: TypeDefType.Literal,
|
|
24
|
+
readonly valuePrototype: [number],
|
|
25
|
+
},
|
|
26
|
+
readonly [1]: {
|
|
27
|
+
readonly type: TypeDefType.Literal,
|
|
28
|
+
readonly valuePrototype: [null],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
it('equals expected type', function () {
|
|
35
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
describe('list', function () {
|
|
40
|
+
const builder = list(numberType)
|
|
41
|
+
type T = PartialTypeDefOf<typeof builder>
|
|
42
|
+
|
|
43
|
+
let t: {
|
|
44
|
+
readonly typeDef: {
|
|
45
|
+
readonly type: TypeDefType.Union,
|
|
46
|
+
readonly discriminator: null,
|
|
47
|
+
readonly unions: {
|
|
48
|
+
readonly [0]: {
|
|
49
|
+
readonly type: TypeDefType.List,
|
|
50
|
+
readonly elements: {
|
|
51
|
+
readonly type: TypeDefType.Union,
|
|
52
|
+
readonly discriminator: null,
|
|
53
|
+
readonly unions: {
|
|
54
|
+
readonly [0]: {
|
|
55
|
+
readonly type: TypeDefType.Literal,
|
|
56
|
+
readonly valuePrototype: [number],
|
|
57
|
+
},
|
|
58
|
+
readonly [1]: {
|
|
59
|
+
readonly type: TypeDefType.Literal,
|
|
60
|
+
readonly valuePrototype: [null],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
readonly [1]: {
|
|
66
|
+
readonly type: TypeDefType.Literal,
|
|
67
|
+
readonly valuePrototype: [null],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
it('equals expected type', function () {
|
|
73
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe('record', function () {
|
|
78
|
+
const builder = record<typeof numberType, 'a' | 'b'>(numberType)
|
|
79
|
+
type T = SimplifyDeep<PartialTypeDefOf<typeof builder>>
|
|
80
|
+
|
|
81
|
+
let t: {
|
|
82
|
+
readonly typeDef: {
|
|
83
|
+
readonly type: TypeDefType.Union,
|
|
84
|
+
readonly discriminator: null,
|
|
85
|
+
readonly unions: {
|
|
86
|
+
readonly [0]: {
|
|
87
|
+
readonly type: TypeDefType.Record,
|
|
88
|
+
readonly keyPrototype: 'a' | 'b',
|
|
89
|
+
readonly valueTypeDef: {
|
|
90
|
+
readonly type: TypeDefType.Union,
|
|
91
|
+
readonly discriminator: null,
|
|
92
|
+
readonly unions: {
|
|
93
|
+
readonly [0]: {
|
|
94
|
+
readonly type: TypeDefType.Literal,
|
|
95
|
+
readonly valuePrototype: [number],
|
|
96
|
+
},
|
|
97
|
+
readonly [1]: {
|
|
98
|
+
readonly type: TypeDefType.Literal,
|
|
99
|
+
readonly valuePrototype: [null],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
} | undefined,
|
|
103
|
+
},
|
|
104
|
+
readonly [1]: {
|
|
105
|
+
readonly type: TypeDefType.Literal,
|
|
106
|
+
readonly valuePrototype: [null],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
it('equals expected type', function () {
|
|
113
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
describe('object', function () {
|
|
118
|
+
const builder = object()
|
|
119
|
+
.set('a', numberType)
|
|
120
|
+
.setReadonly('b', stringType)
|
|
121
|
+
type T = PartialTypeDefOf<typeof builder>
|
|
122
|
+
|
|
123
|
+
let t: {
|
|
124
|
+
readonly typeDef: {
|
|
125
|
+
readonly type: TypeDefType.Union,
|
|
126
|
+
readonly discriminator: null,
|
|
127
|
+
readonly unions: {
|
|
128
|
+
readonly [0]: {
|
|
129
|
+
readonly type: TypeDefType.Object,
|
|
130
|
+
readonly fields: {
|
|
131
|
+
a?: {
|
|
132
|
+
readonly type: TypeDefType.Union,
|
|
133
|
+
readonly discriminator: null,
|
|
134
|
+
readonly unions: {
|
|
135
|
+
readonly [0]: {
|
|
136
|
+
readonly type: TypeDefType.Literal,
|
|
137
|
+
readonly valuePrototype: [number],
|
|
138
|
+
},
|
|
139
|
+
readonly [1]: {
|
|
140
|
+
readonly type: TypeDefType.Literal,
|
|
141
|
+
readonly valuePrototype: [null],
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
readonly b?: {
|
|
146
|
+
readonly type: TypeDefType.Union,
|
|
147
|
+
readonly discriminator: null,
|
|
148
|
+
readonly unions: {
|
|
149
|
+
readonly [0]: {
|
|
150
|
+
readonly type: TypeDefType.Literal,
|
|
151
|
+
readonly valuePrototype: [string],
|
|
152
|
+
},
|
|
153
|
+
readonly [1]: {
|
|
154
|
+
readonly type: TypeDefType.Literal,
|
|
155
|
+
readonly valuePrototype: [null],
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
readonly [1]: {
|
|
162
|
+
readonly type: TypeDefType.Literal,
|
|
163
|
+
readonly valuePrototype: [null],
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
it('equals expected type', function () {
|
|
170
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
describe('union', function () {
|
|
175
|
+
describe('simple', function () {
|
|
176
|
+
const builder = union()
|
|
177
|
+
.add('1', numberType)
|
|
178
|
+
.add('2', stringType)
|
|
179
|
+
type T = PartialTypeDefOf<typeof builder>
|
|
180
|
+
|
|
181
|
+
let t: {
|
|
182
|
+
readonly typeDef: {
|
|
183
|
+
readonly type: TypeDefType.Union,
|
|
184
|
+
readonly discriminator: null,
|
|
185
|
+
readonly unions: {
|
|
186
|
+
readonly [0]: {
|
|
187
|
+
readonly type: TypeDefType.Union,
|
|
188
|
+
readonly discriminator: null,
|
|
189
|
+
readonly unions: {
|
|
190
|
+
readonly [1]: {
|
|
191
|
+
readonly type: TypeDefType.Literal,
|
|
192
|
+
readonly valuePrototype: [number],
|
|
193
|
+
},
|
|
194
|
+
readonly [2]: {
|
|
195
|
+
readonly type: TypeDefType.Literal,
|
|
196
|
+
readonly valuePrototype: [string],
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
readonly [1]: {
|
|
201
|
+
readonly type: TypeDefType.Literal,
|
|
202
|
+
readonly valuePrototype: [null],
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
it('equals expected type', function () {
|
|
209
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
describe('readonly', function () {
|
|
215
|
+
const builder = list(numberType).readonly()
|
|
216
|
+
type T = PartialTypeDefOf<typeof builder>
|
|
217
|
+
|
|
218
|
+
let t: {
|
|
219
|
+
readonly typeDef: {
|
|
220
|
+
readonly type: TypeDefType.Union,
|
|
221
|
+
readonly discriminator: null,
|
|
222
|
+
readonly unions: {
|
|
223
|
+
readonly [0]: {
|
|
224
|
+
readonly type: TypeDefType.List,
|
|
225
|
+
readonly elements: {
|
|
226
|
+
readonly type: TypeDefType.Union,
|
|
227
|
+
readonly discriminator: null,
|
|
228
|
+
readonly unions: {
|
|
229
|
+
readonly [0]: {
|
|
230
|
+
readonly type: TypeDefType.Literal,
|
|
231
|
+
readonly valuePrototype: [number],
|
|
232
|
+
},
|
|
233
|
+
readonly [1]: {
|
|
234
|
+
readonly type: TypeDefType.Literal,
|
|
235
|
+
readonly valuePrototype: [null],
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
readonly [1]: {
|
|
241
|
+
readonly type: TypeDefType.Literal,
|
|
242
|
+
readonly valuePrototype: [null],
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
}
|
|
247
|
+
it('equals expected type', function () {
|
|
248
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
249
|
+
})
|
|
250
|
+
})
|
|
251
|
+
})
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import {
|
|
2
|
+
list,
|
|
3
|
+
numberType,
|
|
4
|
+
object,
|
|
5
|
+
record,
|
|
6
|
+
stringType,
|
|
7
|
+
union,
|
|
8
|
+
} from 'types/builders'
|
|
9
|
+
import { type TypeDefType } from 'types/definitions'
|
|
10
|
+
import { type ReadonlyTypeDefOf } from 'types/readonly_type_def_of'
|
|
11
|
+
|
|
12
|
+
describe('ReadonlyTypeDefOf', function () {
|
|
13
|
+
describe('literal', function () {
|
|
14
|
+
type T = ReadonlyTypeDefOf<typeof numberType>
|
|
15
|
+
|
|
16
|
+
let t: {
|
|
17
|
+
readonly definition: {
|
|
18
|
+
readonly type: TypeDefType.Literal,
|
|
19
|
+
readonly valuePrototype: [number],
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
it('equals expected type', function () {
|
|
23
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
describe('list', function () {
|
|
28
|
+
const builder = list(numberType)
|
|
29
|
+
type T = ReadonlyTypeDefOf<typeof builder>
|
|
30
|
+
|
|
31
|
+
let t: {
|
|
32
|
+
readonly definition: {
|
|
33
|
+
readonly type: TypeDefType.List,
|
|
34
|
+
readonly elements: {
|
|
35
|
+
readonly type: TypeDefType.Literal,
|
|
36
|
+
readonly valuePrototype: [number],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
it('equals expected type', function () {
|
|
41
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe('record', function () {
|
|
46
|
+
const builder = record<typeof numberType, 'a' | 'b'>(numberType)
|
|
47
|
+
type T = ReadonlyTypeDefOf<typeof builder>
|
|
48
|
+
|
|
49
|
+
let t: {
|
|
50
|
+
readonly definition: {
|
|
51
|
+
readonly type: TypeDefType.Record,
|
|
52
|
+
readonly keyPrototype: 'a' | 'b',
|
|
53
|
+
readonly valueTypeDef: {
|
|
54
|
+
readonly type: TypeDefType.Literal,
|
|
55
|
+
readonly valuePrototype: [number],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
it('equals expected type', function () {
|
|
60
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
describe('object', function () {
|
|
65
|
+
const builder = object()
|
|
66
|
+
.set('a', numberType)
|
|
67
|
+
.setOptional('b', stringType)
|
|
68
|
+
type T = ReadonlyTypeDefOf<typeof builder>
|
|
69
|
+
|
|
70
|
+
let t: {
|
|
71
|
+
readonly definition: {
|
|
72
|
+
readonly type: TypeDefType.Object,
|
|
73
|
+
readonly fields: {
|
|
74
|
+
readonly a: {
|
|
75
|
+
readonly type: TypeDefType.Literal,
|
|
76
|
+
readonly valuePrototype: [number],
|
|
77
|
+
},
|
|
78
|
+
readonly b?: {
|
|
79
|
+
readonly type: TypeDefType.Literal,
|
|
80
|
+
readonly valuePrototype: [string],
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
it('equals expected type', function () {
|
|
86
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
describe('union', function () {
|
|
91
|
+
const builder = union()
|
|
92
|
+
.add('1', record<typeof numberType, 'a'>(numberType))
|
|
93
|
+
.add('2', stringType)
|
|
94
|
+
type T = ReadonlyTypeDefOf<typeof builder>
|
|
95
|
+
|
|
96
|
+
let t: {
|
|
97
|
+
readonly definition: {
|
|
98
|
+
readonly type: TypeDefType.Union,
|
|
99
|
+
readonly discriminator: null,
|
|
100
|
+
readonly unions: {
|
|
101
|
+
readonly [1]: {
|
|
102
|
+
readonly type: TypeDefType.Record,
|
|
103
|
+
readonly keyPrototype: 'a',
|
|
104
|
+
readonly valueTypeDef: {
|
|
105
|
+
readonly type: TypeDefType.Literal,
|
|
106
|
+
readonly valuePrototype: [number],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
readonly [2]: {
|
|
110
|
+
readonly type: TypeDefType.Literal,
|
|
111
|
+
readonly valuePrototype: [string],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
it('equals expected type', function () {
|
|
117
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
describe('partial', function () {
|
|
122
|
+
const builder = record<typeof numberType, 'a'>(numberType).partial()
|
|
123
|
+
type T = ReadonlyTypeDefOf<typeof builder>
|
|
124
|
+
|
|
125
|
+
let t: {
|
|
126
|
+
readonly definition: {
|
|
127
|
+
readonly type: TypeDefType.Record,
|
|
128
|
+
readonly keyPrototype: 'a',
|
|
129
|
+
readonly valueTypeDef: {
|
|
130
|
+
readonly type: TypeDefType.Literal,
|
|
131
|
+
readonly valuePrototype: [number],
|
|
132
|
+
} | undefined,
|
|
133
|
+
},
|
|
134
|
+
}
|
|
135
|
+
it('equals expected type', function () {
|
|
136
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
describe('readonly', function () {
|
|
141
|
+
const builder = record<typeof numberType, 'a'>(numberType).readonly()
|
|
142
|
+
type T = ReadonlyTypeDefOf<typeof builder>
|
|
143
|
+
|
|
144
|
+
let t: {
|
|
145
|
+
readonly definition: {
|
|
146
|
+
readonly type: TypeDefType.Record,
|
|
147
|
+
readonly keyPrototype: 'a',
|
|
148
|
+
readonly valueTypeDef: {
|
|
149
|
+
readonly type: TypeDefType.Literal,
|
|
150
|
+
readonly valuePrototype: [number],
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
}
|
|
154
|
+
it('equals expected type', function () {
|
|
155
|
+
expectTypeOf(t).toEqualTypeOf<T>()
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
})
|