@strictly/define 0.0.6 → 0.0.8
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/tsconfig.tsbuildinfo +1 -1
- package/.out/types/builders.d.ts +2 -1
- package/.out/types/builders.js +3 -1
- package/.out/types/specs/flattened_accessors_of_type.tests.js +1 -2
- package/.out/types/specs/flattened_types_of_type.tests.js +8 -16
- package/.out/types/specs/flattened_validators_of_validating_type.tests.js +2 -4
- package/.out/types/specs/flattened_values_of_type.tests.js +2 -4
- package/.out/types/specs/partial_type_of_type.tests.js +6 -12
- package/.out/types/specs/paths_of_type.tests.js +23 -39
- package/.out/types/specs/readonly_type_of_type.tests.js +7 -14
- package/.out/types/specs/strict_definitions.tests.js +2 -4
- package/.out/types/specs/type_of_type.tests.js +3 -6
- package/.out/types/specs/value_of_type.tests.js +13 -26
- package/.out/types/specs/value_to_type_paths_of_type.tests.js +8 -16
- package/.out/validation/specs/errors_of_validators.tests.js +1 -2
- package/.out/validation/specs/validators_of_values.tests.js +3 -6
- package/.out/validation/validator.d.ts +2 -2
- package/.out/validation/validator.js +0 -1
- package/.out/validation/validators/defined_validator.d.ts +1 -1
- package/.out/validation/validators/minimum_string_length_validator.d.ts +1 -1
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/dist/index.cjs +27 -26
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +27 -26
- package/package.json +1 -1
- package/types/builders.ts +8 -2
- package/types/specs/flattened_accessors_of_type.tests.ts +2 -2
- package/types/specs/flattened_types_of_type.tests.ts +16 -16
- package/types/specs/flattened_validators_of_validating_type.tests.ts +4 -4
- package/types/specs/flattened_values_of_type.tests.ts +4 -4
- package/types/specs/partial_type_of_type.tests.ts +12 -12
- package/types/specs/paths_of_type.tests.ts +39 -39
- package/types/specs/readonly_type_of_type.tests.ts +14 -14
- package/types/specs/strict_definitions.tests.ts +6 -6
- package/types/specs/type_of_type.tests.ts +6 -6
- package/types/specs/value_of_type.tests.ts +26 -26
- package/types/specs/value_to_type_paths_of_type.tests.ts +16 -16
- package/validation/specs/errors_of_validators.tests.ts +2 -2
- package/validation/specs/validators_of_values.tests.ts +6 -6
- package/validation/validator.ts +13 -4
- package/validation/validators/defined_validator.ts +1 -3
- package/validation/validators/minimum_string_length_validator.ts +2 -2
|
@@ -12,9 +12,9 @@ describe('ValueOfType', function () {
|
|
|
12
12
|
}
|
|
13
13
|
type T = ValueOfType<{ definition: TypeD }>
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
type C = 'a' | 'b' | 'c'
|
|
16
16
|
it('equals expected type', function () {
|
|
17
|
-
expectTypeOf(
|
|
17
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
18
18
|
})
|
|
19
19
|
})
|
|
20
20
|
|
|
@@ -29,9 +29,9 @@ describe('ValueOfType', function () {
|
|
|
29
29
|
}
|
|
30
30
|
type T = ValueOfType<{ definition: TypeD }>
|
|
31
31
|
describe('mutable', function () {
|
|
32
|
-
|
|
32
|
+
type C = ('a' | 'b' | 'c')[]
|
|
33
33
|
it('equals expected type', function () {
|
|
34
|
-
expectTypeOf(
|
|
34
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
35
35
|
})
|
|
36
36
|
})
|
|
37
37
|
|
|
@@ -46,9 +46,9 @@ describe('ValueOfType', function () {
|
|
|
46
46
|
},
|
|
47
47
|
}>
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
type C = readonly ('a' | 'b' | 'c')[]
|
|
50
50
|
it('equals expected type', function () {
|
|
51
|
-
expectTypeOf(
|
|
51
|
+
expectTypeOf<C>().toEqualTypeOf<R>()
|
|
52
52
|
})
|
|
53
53
|
})
|
|
54
54
|
})
|
|
@@ -66,9 +66,9 @@ describe('ValueOfType', function () {
|
|
|
66
66
|
type T = ValueOfType<{ definition: TypeD }>
|
|
67
67
|
|
|
68
68
|
describe('mutable', function () {
|
|
69
|
-
|
|
69
|
+
type C = Record<'x' | 'y' | 'z', 'a' | 'b' | 'c'>
|
|
70
70
|
it('equals expected type', function () {
|
|
71
|
-
expectTypeOf(
|
|
71
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
72
72
|
})
|
|
73
73
|
})
|
|
74
74
|
|
|
@@ -83,10 +83,10 @@ describe('ValueOfType', function () {
|
|
|
83
83
|
},
|
|
84
84
|
},
|
|
85
85
|
}>
|
|
86
|
-
|
|
86
|
+
type C = Readonly<Record<'x' | 'y' | 'z', 'a' | 'b' | 'c'>>
|
|
87
87
|
|
|
88
88
|
it('equals expected type', function () {
|
|
89
|
-
expectTypeOf(
|
|
89
|
+
expectTypeOf<C>().toEqualTypeOf<R>()
|
|
90
90
|
})
|
|
91
91
|
})
|
|
92
92
|
|
|
@@ -101,9 +101,9 @@ describe('ValueOfType', function () {
|
|
|
101
101
|
}
|
|
102
102
|
type T = ValueOfType<{ definition: TypeD }>
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
type C = Partial<Record<'x' | 'y' | 'z', 'a' | 'b' | 'c'>>
|
|
105
105
|
it('equals expected type', function () {
|
|
106
|
-
expectTypeOf(
|
|
106
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
107
107
|
})
|
|
108
108
|
})
|
|
109
109
|
|
|
@@ -118,9 +118,9 @@ describe('ValueOfType', function () {
|
|
|
118
118
|
}
|
|
119
119
|
type T = ValueOfType<{ definition: TypeD }>
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
type C = Partial<Readonly<Record<'x' | 'y' | 'z', 'a' | 'b' | 'c'>>>
|
|
122
122
|
it('equals expected type', function () {
|
|
123
|
-
expectTypeOf(
|
|
123
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
124
124
|
})
|
|
125
125
|
})
|
|
126
126
|
})
|
|
@@ -142,13 +142,13 @@ describe('ValueOfType', function () {
|
|
|
142
142
|
type T = ValueOfType<{ definition: TypeD }>
|
|
143
143
|
|
|
144
144
|
describe('mutable', function () {
|
|
145
|
-
|
|
145
|
+
type C = {
|
|
146
146
|
a: 'a' | 'b',
|
|
147
147
|
b: number,
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
it('equals expected type', function () {
|
|
151
|
-
expectTypeOf(
|
|
151
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
152
152
|
})
|
|
153
153
|
})
|
|
154
154
|
|
|
@@ -168,12 +168,12 @@ describe('ValueOfType', function () {
|
|
|
168
168
|
}
|
|
169
169
|
type T = ValueOfType<{ definition: TypeD }>
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
type C = {
|
|
172
172
|
readonly a: 'a' | 'b',
|
|
173
173
|
readonly b: number,
|
|
174
174
|
}
|
|
175
175
|
it('equals expected type', function () {
|
|
176
|
-
expectTypeOf(
|
|
176
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
177
177
|
})
|
|
178
178
|
})
|
|
179
179
|
|
|
@@ -193,13 +193,13 @@ describe('ValueOfType', function () {
|
|
|
193
193
|
}
|
|
194
194
|
type T = ValueOfType<{ definition: TypeD }>
|
|
195
195
|
|
|
196
|
-
|
|
196
|
+
type C = {
|
|
197
197
|
a?: 'a' | 'b',
|
|
198
198
|
b?: number,
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
it('equals expected type', function () {
|
|
202
|
-
expectTypeOf(
|
|
202
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
203
203
|
})
|
|
204
204
|
})
|
|
205
205
|
})
|
|
@@ -227,10 +227,10 @@ describe('ValueOfType', function () {
|
|
|
227
227
|
},
|
|
228
228
|
}>
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
type C = null | number | string
|
|
231
231
|
|
|
232
232
|
it('equals expected type', function () {
|
|
233
|
-
expectTypeOf(
|
|
233
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
234
234
|
})
|
|
235
235
|
})
|
|
236
236
|
|
|
@@ -270,7 +270,7 @@ describe('ValueOfType', function () {
|
|
|
270
270
|
},
|
|
271
271
|
}>
|
|
272
272
|
|
|
273
|
-
|
|
273
|
+
type C = {
|
|
274
274
|
readonly d: 1,
|
|
275
275
|
b: string,
|
|
276
276
|
} | {
|
|
@@ -279,7 +279,7 @@ describe('ValueOfType', function () {
|
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
it('equals expected type', function () {
|
|
282
|
-
expectTypeOf(
|
|
282
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
283
283
|
})
|
|
284
284
|
})
|
|
285
285
|
|
|
@@ -313,7 +313,7 @@ describe('ValueOfType', function () {
|
|
|
313
313
|
}>
|
|
314
314
|
>
|
|
315
315
|
|
|
316
|
-
|
|
316
|
+
type C = {
|
|
317
317
|
readonly d: 1,
|
|
318
318
|
b: string,
|
|
319
319
|
} | {
|
|
@@ -322,7 +322,7 @@ describe('ValueOfType', function () {
|
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
it('equals expected type', function () {
|
|
325
|
-
expectTypeOf(
|
|
325
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
326
326
|
})
|
|
327
327
|
})
|
|
328
328
|
})
|
|
@@ -19,11 +19,11 @@ describe('ValueToTypePathsOfType', function () {
|
|
|
19
19
|
describe('literal', function () {
|
|
20
20
|
type T = ValueToTypePathsOfType<typeof numberType.narrow>
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
type C = {
|
|
23
23
|
readonly $: '$',
|
|
24
24
|
}
|
|
25
25
|
it('equals expected type', function () {
|
|
26
|
-
expectTypeOf(
|
|
26
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
27
27
|
})
|
|
28
28
|
})
|
|
29
29
|
|
|
@@ -31,13 +31,13 @@ describe('ValueToTypePathsOfType', function () {
|
|
|
31
31
|
const builder = list(list(numberType))
|
|
32
32
|
type T = SimplifyDeep<ValueToTypePathsOfType<typeof builder.narrow>>
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
type C = {
|
|
35
35
|
readonly $: '$',
|
|
36
36
|
readonly [_: `$.${number}`]: '$.*',
|
|
37
37
|
readonly [_: `$.${number}.${number}`]: '$.*.*',
|
|
38
38
|
}
|
|
39
39
|
it('equals expected type', function () {
|
|
40
|
-
expectTypeOf(
|
|
40
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
41
41
|
})
|
|
42
42
|
})
|
|
43
43
|
|
|
@@ -46,7 +46,7 @@ describe('ValueToTypePathsOfType', function () {
|
|
|
46
46
|
const builder = record<typeof l, 'a' | 'b'>(l)
|
|
47
47
|
type T = SimplifyDeep<ValueToTypePathsOfType<typeof builder>>
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
type C = {
|
|
50
50
|
readonly $: '$',
|
|
51
51
|
readonly [`$.a`]: '$.*',
|
|
52
52
|
readonly [`$.b`]: '$.*',
|
|
@@ -54,7 +54,7 @@ describe('ValueToTypePathsOfType', function () {
|
|
|
54
54
|
readonly [_: `$.b.${number}`]: '$.*.*',
|
|
55
55
|
}
|
|
56
56
|
it('equals expected type', function () {
|
|
57
|
-
expectTypeOf(
|
|
57
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
it('allows lookup of type path', function () {
|
|
@@ -71,7 +71,7 @@ describe('ValueToTypePathsOfType', function () {
|
|
|
71
71
|
|
|
72
72
|
type T = SimplifyDeep<ValueToTypePathsOfType<typeof builder>>
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
type C = {
|
|
75
75
|
readonly $: '$',
|
|
76
76
|
readonly [`$.a`]: '$.a',
|
|
77
77
|
readonly [`$.b`]: '$.b',
|
|
@@ -80,7 +80,7 @@ describe('ValueToTypePathsOfType', function () {
|
|
|
80
80
|
readonly [_: `$.a.${number}`]: '$.a.*',
|
|
81
81
|
}
|
|
82
82
|
it('equals expected type', function () {
|
|
83
|
-
expectTypeOf(
|
|
83
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
it('has the same value paths', function () {
|
|
@@ -101,13 +101,13 @@ describe('ValueToTypePathsOfType', function () {
|
|
|
101
101
|
.or('2', stringType)
|
|
102
102
|
type T = SimplifyDeep<ValueToTypePathsOfType<typeof builder>>
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
type C = {
|
|
105
105
|
readonly $: '$',
|
|
106
106
|
readonly [_: `$.${number}`]: '$.*',
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
it('equals expected type', function () {
|
|
110
|
-
expectTypeOf(
|
|
110
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
111
111
|
})
|
|
112
112
|
})
|
|
113
113
|
|
|
@@ -117,7 +117,7 @@ describe('ValueToTypePathsOfType', function () {
|
|
|
117
117
|
.or('2', object().field('x', numberType).field('y', stringType))
|
|
118
118
|
type T = SimplifyDeep<ValueToTypePathsOfType<typeof builder>>
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
type C = {
|
|
121
121
|
readonly $: '$',
|
|
122
122
|
readonly ['$.1:a']: '$.1:a',
|
|
123
123
|
readonly ['$.1:b']: '$.1:b',
|
|
@@ -125,7 +125,7 @@ describe('ValueToTypePathsOfType', function () {
|
|
|
125
125
|
readonly ['$.2:y']: '$.2:y',
|
|
126
126
|
}
|
|
127
127
|
it('equals expected type', function () {
|
|
128
|
-
expectTypeOf(
|
|
128
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
129
129
|
})
|
|
130
130
|
|
|
131
131
|
it('has the same value paths', function () {
|
|
@@ -145,13 +145,13 @@ describe('ValueToTypePathsOfType', function () {
|
|
|
145
145
|
|
|
146
146
|
type T = SimplifyDeep<ValueToTypePathsOfType<typeof builder>>
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
type C = {
|
|
149
149
|
readonly $: '$',
|
|
150
150
|
readonly [_: `$.${number}`]: '$.*',
|
|
151
151
|
readonly [_: `$.${number}.${number}`]: '$.*.*',
|
|
152
152
|
}
|
|
153
153
|
it('equals expected type', function () {
|
|
154
|
-
expectTypeOf(
|
|
154
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
155
155
|
})
|
|
156
156
|
})
|
|
157
157
|
|
|
@@ -160,13 +160,13 @@ describe('ValueToTypePathsOfType', function () {
|
|
|
160
160
|
|
|
161
161
|
type T = SimplifyDeep<ValueToTypePathsOfType<typeof builder>>
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
type C = {
|
|
164
164
|
readonly $: '$',
|
|
165
165
|
readonly [_: `$.${number}`]: '$.*',
|
|
166
166
|
readonly [_: `$.${number}.${number}`]: '$.*.*',
|
|
167
167
|
}
|
|
168
168
|
it('equals expected type', function () {
|
|
169
|
-
expectTypeOf(
|
|
169
|
+
expectTypeOf<C>().toEqualTypeOf<T>()
|
|
170
170
|
})
|
|
171
171
|
|
|
172
172
|
it('has the same value paths', function () {
|
|
@@ -8,13 +8,13 @@ describe('ErrorsOfValidators', function () {
|
|
|
8
8
|
y: Validator<number, 'b'>,
|
|
9
9
|
}>
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
type C = {
|
|
12
12
|
readonly x: 'a',
|
|
13
13
|
readonly y: 'b',
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
it('equals expected type', function () {
|
|
17
|
-
expectTypeOf<T>().toEqualTypeOf(
|
|
17
|
+
expectTypeOf<T>().toEqualTypeOf<C>()
|
|
18
18
|
})
|
|
19
19
|
})
|
|
20
20
|
})
|
|
@@ -13,13 +13,13 @@ describe('FlattenedValidatorsOfType', function () {
|
|
|
13
13
|
1
|
|
14
14
|
>
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
type C = {
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
18
|
readonly $: Validator<'a' | 'b' | 'c', any, '$', 1>,
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
it('has the expected type', function () {
|
|
22
|
-
expectTypeOf<T>().toEqualTypeOf(
|
|
22
|
+
expectTypeOf<T>().toEqualTypeOf<C>()
|
|
23
23
|
})
|
|
24
24
|
})
|
|
25
25
|
|
|
@@ -36,7 +36,7 @@ describe('FlattenedValidatorsOfType', function () {
|
|
|
36
36
|
2
|
|
37
37
|
>
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
type C = {
|
|
40
40
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
41
|
readonly $: Validator<number[], any, '$', 2>,
|
|
42
42
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -44,7 +44,7 @@ describe('FlattenedValidatorsOfType', function () {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
it('has the expected type', function () {
|
|
47
|
-
expectTypeOf<T>().toEqualTypeOf(
|
|
47
|
+
expectTypeOf<T>().toEqualTypeOf<C>()
|
|
48
48
|
})
|
|
49
49
|
})
|
|
50
50
|
|
|
@@ -56,13 +56,13 @@ describe('FlattenedValidatorsOfType', function () {
|
|
|
56
56
|
}
|
|
57
57
|
>
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
type C = {
|
|
60
60
|
readonly $: Validator<number[]>,
|
|
61
61
|
readonly '$.*': Validator<number>,
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
it('has the expected type', function () {
|
|
65
|
-
expectTypeOf<T>().toEqualTypeOf(
|
|
65
|
+
expectTypeOf<T>().toEqualTypeOf<C>()
|
|
66
66
|
})
|
|
67
67
|
})
|
|
68
68
|
})
|
package/validation/validator.ts
CHANGED
|
@@ -47,11 +47,21 @@ export type ValidationError<Type extends string, Data = {}> = Simplify<
|
|
|
47
47
|
} & Data
|
|
48
48
|
>
|
|
49
49
|
|
|
50
|
-
export function isFunctionalValidator
|
|
50
|
+
export function isFunctionalValidator<
|
|
51
|
+
V,
|
|
52
|
+
E,
|
|
53
|
+
ValuePath extends string,
|
|
54
|
+
Context,
|
|
55
|
+
>(v: Validator<V, E, ValuePath, Context>): v is FunctionalValidator<V, E, ValuePath, Context> {
|
|
51
56
|
return typeof v === 'function'
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
export function isAnnotatedValidator
|
|
59
|
+
export function isAnnotatedValidator<
|
|
60
|
+
V,
|
|
61
|
+
E,
|
|
62
|
+
ValuePath extends string,
|
|
63
|
+
Context,
|
|
64
|
+
>(v: Validator<V, E, ValuePath, Context>): v is AnnotatedValidator<V, E, ValuePath, Context> {
|
|
55
65
|
return typeof v !== 'function'
|
|
56
66
|
}
|
|
57
67
|
|
|
@@ -73,8 +83,7 @@ export function validate<
|
|
|
73
83
|
if (isAnnotatedValidator(validator)) {
|
|
74
84
|
return validator.validate(v, valuePath, context)
|
|
75
85
|
} else {
|
|
76
|
-
|
|
77
|
-
return (validator as FunctionalValidator<V, E, ValuePath, Context>)(v, valuePath, context)
|
|
86
|
+
return validator(v, valuePath, context)
|
|
78
87
|
}
|
|
79
88
|
}
|
|
80
89
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { type AnnotatedValidator } from 'validation/validator'
|
|
2
2
|
|
|
3
|
-
export class DefinedValidator<V, E
|
|
4
|
-
implements AnnotatedValidator<V | null | undefined, E, ValuePath, Context>
|
|
5
|
-
{
|
|
3
|
+
export class DefinedValidator<V, E> implements AnnotatedValidator<V | null | undefined, E, never, never> {
|
|
6
4
|
constructor(private readonly error: E) {
|
|
7
5
|
}
|
|
8
6
|
|
|
@@ -10,8 +10,8 @@ export type MinimumStringLengthValidationError = {
|
|
|
10
10
|
minimumLength: number,
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export class MinimumStringLengthValidator
|
|
14
|
-
implements AnnotatedValidator<string, MinimumStringLengthValidationError,
|
|
13
|
+
export class MinimumStringLengthValidator
|
|
14
|
+
implements AnnotatedValidator<string, MinimumStringLengthValidationError, never, never>
|
|
15
15
|
{
|
|
16
16
|
constructor(private readonly minimumLength: number) {
|
|
17
17
|
}
|