@sinclair/typebox 0.32.0-dev-13 → 0.32.0-dev-14
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/build/import/type/guard/type.d.mts +47 -46
- package/build/import/type/guard/type.mjs +294 -293
- package/build/import/type/mapped/mapped.d.mts +9 -6
- package/build/import/type/mapped/mapped.mjs +11 -4
- package/build/require/type/guard/type.d.ts +47 -46
- package/build/require/type/guard/type.js +252 -250
- package/build/require/type/mapped/mapped.d.ts +9 -6
- package/build/require/type/mapped/mapped.js +24 -17
- package/package.json +1 -1
|
@@ -80,303 +80,304 @@ function IsOptionalFormat(value) {
|
|
|
80
80
|
function IsOptionalSchema(value) {
|
|
81
81
|
return ValueGuard.IsUndefined(value) || TSchema(value);
|
|
82
82
|
}
|
|
83
|
-
export function TReadonly(
|
|
84
|
-
return ValueGuard.IsObject(
|
|
85
|
-
}
|
|
86
|
-
export function TOptional(
|
|
87
|
-
return ValueGuard.IsObject(
|
|
88
|
-
}
|
|
89
|
-
export function TAny(
|
|
90
|
-
return (TKindOf(
|
|
91
|
-
IsOptionalString(
|
|
92
|
-
}
|
|
93
|
-
export function TArray(
|
|
94
|
-
return (TKindOf(
|
|
95
|
-
|
|
96
|
-
IsOptionalString(
|
|
97
|
-
TSchema(
|
|
98
|
-
IsOptionalNumber(
|
|
99
|
-
IsOptionalNumber(
|
|
100
|
-
IsOptionalBoolean(
|
|
101
|
-
IsOptionalSchema(
|
|
102
|
-
IsOptionalNumber(
|
|
103
|
-
IsOptionalNumber(
|
|
104
|
-
}
|
|
105
|
-
export function TAsyncIterator(
|
|
106
|
-
return (TKindOf(
|
|
107
|
-
|
|
108
|
-
IsOptionalString(
|
|
109
|
-
TSchema(
|
|
110
|
-
}
|
|
111
|
-
export function TBigInt(
|
|
112
|
-
return (TKindOf(
|
|
113
|
-
|
|
114
|
-
IsOptionalString(
|
|
115
|
-
IsOptionalBigInt(
|
|
116
|
-
IsOptionalBigInt(
|
|
117
|
-
IsOptionalBigInt(
|
|
118
|
-
IsOptionalBigInt(
|
|
119
|
-
IsOptionalBigInt(
|
|
120
|
-
}
|
|
121
|
-
export function TBoolean(
|
|
122
|
-
return (TKindOf(
|
|
123
|
-
|
|
124
|
-
IsOptionalString(
|
|
125
|
-
}
|
|
126
|
-
export function TConstructor(
|
|
127
|
-
return (TKindOf(
|
|
128
|
-
|
|
129
|
-
IsOptionalString(
|
|
130
|
-
ValueGuard.IsArray(
|
|
131
|
-
|
|
132
|
-
TSchema(
|
|
133
|
-
}
|
|
134
|
-
export function TDate(
|
|
135
|
-
return (TKindOf(
|
|
136
|
-
|
|
137
|
-
IsOptionalString(
|
|
138
|
-
IsOptionalNumber(
|
|
139
|
-
IsOptionalNumber(
|
|
140
|
-
IsOptionalNumber(
|
|
141
|
-
IsOptionalNumber(
|
|
142
|
-
IsOptionalNumber(
|
|
143
|
-
}
|
|
144
|
-
export function TFunction(
|
|
145
|
-
return (TKindOf(
|
|
146
|
-
|
|
147
|
-
IsOptionalString(
|
|
148
|
-
ValueGuard.IsArray(
|
|
149
|
-
|
|
150
|
-
TSchema(
|
|
151
|
-
}
|
|
152
|
-
export function TInteger(
|
|
153
|
-
return (TKindOf(
|
|
154
|
-
|
|
155
|
-
IsOptionalString(
|
|
156
|
-
IsOptionalNumber(
|
|
157
|
-
IsOptionalNumber(
|
|
158
|
-
IsOptionalNumber(
|
|
159
|
-
IsOptionalNumber(
|
|
160
|
-
IsOptionalNumber(
|
|
161
|
-
}
|
|
162
|
-
export function TProperties(
|
|
163
|
-
return (ValueGuard.IsObject(
|
|
164
|
-
Object.entries(
|
|
165
|
-
}
|
|
166
|
-
export function TIntersect(
|
|
167
|
-
return (TKindOf(
|
|
168
|
-
(ValueGuard.IsString(
|
|
169
|
-
ValueGuard.IsArray(
|
|
170
|
-
|
|
171
|
-
IsOptionalString(
|
|
172
|
-
(IsOptionalBoolean(
|
|
173
|
-
IsOptionalString(
|
|
174
|
-
}
|
|
175
|
-
export function TIterator(
|
|
176
|
-
return (TKindOf(
|
|
177
|
-
|
|
178
|
-
IsOptionalString(
|
|
179
|
-
TSchema(
|
|
180
|
-
}
|
|
181
|
-
export function TKindOf(
|
|
182
|
-
return ValueGuard.IsObject(
|
|
183
|
-
}
|
|
184
|
-
export function TLiteralString(
|
|
185
|
-
return TLiteral(
|
|
186
|
-
}
|
|
187
|
-
export function TLiteralNumber(
|
|
188
|
-
return TLiteral(
|
|
189
|
-
}
|
|
190
|
-
export function TLiteralBoolean(
|
|
191
|
-
return TLiteral(
|
|
192
|
-
}
|
|
193
|
-
export function TLiteral(
|
|
194
|
-
return (TKindOf(
|
|
195
|
-
IsOptionalString(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
IsOptionalNumber(
|
|
228
|
-
IsOptionalNumber(
|
|
229
|
-
IsOptionalNumber(
|
|
230
|
-
IsOptionalNumber(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
IsOptionalNumber(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
83
|
+
export function TReadonly(value) {
|
|
84
|
+
return ValueGuard.IsObject(value) && value[ReadonlyKind] === 'Readonly';
|
|
85
|
+
}
|
|
86
|
+
export function TOptional(value) {
|
|
87
|
+
return ValueGuard.IsObject(value) && value[OptionalKind] === 'Optional';
|
|
88
|
+
}
|
|
89
|
+
export function TAny(value) {
|
|
90
|
+
return (TKindOf(value, 'Any') &&
|
|
91
|
+
IsOptionalString(value.$id));
|
|
92
|
+
}
|
|
93
|
+
export function TArray(value) {
|
|
94
|
+
return (TKindOf(value, 'Array') &&
|
|
95
|
+
value.type === 'array' &&
|
|
96
|
+
IsOptionalString(value.$id) &&
|
|
97
|
+
TSchema(value.items) &&
|
|
98
|
+
IsOptionalNumber(value.minItems) &&
|
|
99
|
+
IsOptionalNumber(value.maxItems) &&
|
|
100
|
+
IsOptionalBoolean(value.uniqueItems) &&
|
|
101
|
+
IsOptionalSchema(value.contains) &&
|
|
102
|
+
IsOptionalNumber(value.minContains) &&
|
|
103
|
+
IsOptionalNumber(value.maxContains));
|
|
104
|
+
}
|
|
105
|
+
export function TAsyncIterator(value) {
|
|
106
|
+
return (TKindOf(value, 'AsyncIterator') &&
|
|
107
|
+
value.type === 'AsyncIterator' &&
|
|
108
|
+
IsOptionalString(value.$id) &&
|
|
109
|
+
TSchema(value.items));
|
|
110
|
+
}
|
|
111
|
+
export function TBigInt(value) {
|
|
112
|
+
return (TKindOf(value, 'BigInt') &&
|
|
113
|
+
value.type === 'bigint' &&
|
|
114
|
+
IsOptionalString(value.$id) &&
|
|
115
|
+
IsOptionalBigInt(value.exclusiveMaximum) &&
|
|
116
|
+
IsOptionalBigInt(value.exclusiveMinimum) &&
|
|
117
|
+
IsOptionalBigInt(value.maximum) &&
|
|
118
|
+
IsOptionalBigInt(value.minimum) &&
|
|
119
|
+
IsOptionalBigInt(value.multipleOf));
|
|
120
|
+
}
|
|
121
|
+
export function TBoolean(value) {
|
|
122
|
+
return (TKindOf(value, 'Boolean') &&
|
|
123
|
+
value.type === 'boolean' &&
|
|
124
|
+
IsOptionalString(value.$id));
|
|
125
|
+
}
|
|
126
|
+
export function TConstructor(value) {
|
|
127
|
+
return (TKindOf(value, 'Constructor') &&
|
|
128
|
+
value.type === 'Constructor' &&
|
|
129
|
+
IsOptionalString(value.$id) &&
|
|
130
|
+
ValueGuard.IsArray(value.parameters) &&
|
|
131
|
+
value.parameters.every(schema => TSchema(schema)) &&
|
|
132
|
+
TSchema(value.returns));
|
|
133
|
+
}
|
|
134
|
+
export function TDate(value) {
|
|
135
|
+
return (TKindOf(value, 'Date') &&
|
|
136
|
+
value.type === 'Date' &&
|
|
137
|
+
IsOptionalString(value.$id) &&
|
|
138
|
+
IsOptionalNumber(value.exclusiveMaximumTimestamp) &&
|
|
139
|
+
IsOptionalNumber(value.exclusiveMinimumTimestamp) &&
|
|
140
|
+
IsOptionalNumber(value.maximumTimestamp) &&
|
|
141
|
+
IsOptionalNumber(value.minimumTimestamp) &&
|
|
142
|
+
IsOptionalNumber(value.multipleOfTimestamp));
|
|
143
|
+
}
|
|
144
|
+
export function TFunction(value) {
|
|
145
|
+
return (TKindOf(value, 'Function') &&
|
|
146
|
+
value.type === 'Function' &&
|
|
147
|
+
IsOptionalString(value.$id) &&
|
|
148
|
+
ValueGuard.IsArray(value.parameters) &&
|
|
149
|
+
value.parameters.every(schema => TSchema(schema)) &&
|
|
150
|
+
TSchema(value.returns));
|
|
151
|
+
}
|
|
152
|
+
export function TInteger(value) {
|
|
153
|
+
return (TKindOf(value, 'Integer') &&
|
|
154
|
+
value.type === 'integer' &&
|
|
155
|
+
IsOptionalString(value.$id) &&
|
|
156
|
+
IsOptionalNumber(value.exclusiveMaximum) &&
|
|
157
|
+
IsOptionalNumber(value.exclusiveMinimum) &&
|
|
158
|
+
IsOptionalNumber(value.maximum) &&
|
|
159
|
+
IsOptionalNumber(value.minimum) &&
|
|
160
|
+
IsOptionalNumber(value.multipleOf));
|
|
161
|
+
}
|
|
162
|
+
export function TProperties(value) {
|
|
163
|
+
return (ValueGuard.IsObject(value) &&
|
|
164
|
+
Object.entries(value).every(([key, schema]) => IsControlCharacterFree(key) && TSchema(schema)));
|
|
165
|
+
}
|
|
166
|
+
export function TIntersect(value) {
|
|
167
|
+
return (TKindOf(value, 'Intersect') &&
|
|
168
|
+
(ValueGuard.IsString(value.type) && value.type !== 'object' ? false : true) &&
|
|
169
|
+
ValueGuard.IsArray(value.allOf) &&
|
|
170
|
+
value.allOf.every(schema => TSchema(schema) && !TTransform(schema)) &&
|
|
171
|
+
IsOptionalString(value.type) &&
|
|
172
|
+
(IsOptionalBoolean(value.unevaluatedProperties) || IsOptionalSchema(value.unevaluatedProperties)) &&
|
|
173
|
+
IsOptionalString(value.$id));
|
|
174
|
+
}
|
|
175
|
+
export function TIterator(value) {
|
|
176
|
+
return (TKindOf(value, 'Iterator') &&
|
|
177
|
+
value.type === 'Iterator' &&
|
|
178
|
+
IsOptionalString(value.$id) &&
|
|
179
|
+
TSchema(value.items));
|
|
180
|
+
}
|
|
181
|
+
export function TKindOf(value, kind) {
|
|
182
|
+
return ValueGuard.IsObject(value) && Kind in value && value[Kind] === kind;
|
|
183
|
+
}
|
|
184
|
+
export function TLiteralString(value) {
|
|
185
|
+
return TLiteral(value) && ValueGuard.IsString(value.const);
|
|
186
|
+
}
|
|
187
|
+
export function TLiteralNumber(value) {
|
|
188
|
+
return TLiteral(value) && ValueGuard.IsNumber(value.const);
|
|
189
|
+
}
|
|
190
|
+
export function TLiteralBoolean(value) {
|
|
191
|
+
return TLiteral(value) && ValueGuard.IsBoolean(value.const);
|
|
192
|
+
}
|
|
193
|
+
export function TLiteral(value) {
|
|
194
|
+
return (TKindOf(value, 'Literal') &&
|
|
195
|
+
IsOptionalString(value.$id) && TLiteralValue(value.const));
|
|
196
|
+
}
|
|
197
|
+
export function TLiteralValue(value) {
|
|
198
|
+
return ValueGuard.IsBoolean(value) || ValueGuard.IsNumber(value) || ValueGuard.IsString(value);
|
|
199
|
+
}
|
|
200
|
+
export function TMappedKey(value) {
|
|
201
|
+
return (TKindOf(value, 'MappedKey') &&
|
|
202
|
+
ValueGuard.IsArray(value.keys) &&
|
|
203
|
+
value.keys.every(key => ValueGuard.IsNumber(key) || ValueGuard.IsString(key)));
|
|
204
|
+
}
|
|
205
|
+
export function TMappedResult(value) {
|
|
206
|
+
return (TKindOf(value, 'MappedResult') &&
|
|
207
|
+
TProperties(value.properties));
|
|
208
|
+
}
|
|
209
|
+
export function TNever(value) {
|
|
210
|
+
return (TKindOf(value, 'Never') &&
|
|
211
|
+
ValueGuard.IsObject(value.not) &&
|
|
212
|
+
Object.getOwnPropertyNames(value.not).length === 0);
|
|
213
|
+
}
|
|
214
|
+
export function TNot(value) {
|
|
215
|
+
return (TKindOf(value, 'Not') &&
|
|
216
|
+
TSchema(value.not));
|
|
217
|
+
}
|
|
218
|
+
export function TNull(value) {
|
|
219
|
+
return (TKindOf(value, 'Null') &&
|
|
220
|
+
value.type === 'null' &&
|
|
221
|
+
IsOptionalString(value.$id));
|
|
222
|
+
}
|
|
223
|
+
export function TNumber(value) {
|
|
224
|
+
return (TKindOf(value, 'Number') &&
|
|
225
|
+
value.type === 'number' &&
|
|
226
|
+
IsOptionalString(value.$id) &&
|
|
227
|
+
IsOptionalNumber(value.exclusiveMaximum) &&
|
|
228
|
+
IsOptionalNumber(value.exclusiveMinimum) &&
|
|
229
|
+
IsOptionalNumber(value.maximum) &&
|
|
230
|
+
IsOptionalNumber(value.minimum) &&
|
|
231
|
+
IsOptionalNumber(value.multipleOf));
|
|
232
|
+
}
|
|
233
|
+
export function TObject(value) {
|
|
234
|
+
return (TKindOf(value, 'Object') &&
|
|
235
|
+
value.type === 'object' &&
|
|
236
|
+
IsOptionalString(value.$id) &&
|
|
237
|
+
TProperties(value.properties) &&
|
|
238
|
+
IsAdditionalProperties(value.additionalProperties) &&
|
|
239
|
+
IsOptionalNumber(value.minProperties) &&
|
|
240
|
+
IsOptionalNumber(value.maxProperties));
|
|
241
|
+
}
|
|
242
|
+
export function TPromise(value) {
|
|
243
|
+
return (TKindOf(value, 'Promise') &&
|
|
244
|
+
value.type === 'Promise' &&
|
|
245
|
+
IsOptionalString(value.$id) &&
|
|
246
|
+
TSchema(value.item));
|
|
247
|
+
}
|
|
248
|
+
export function TRecord(value) {
|
|
249
|
+
return (TKindOf(value, 'Record') &&
|
|
250
|
+
value.type === 'object' &&
|
|
251
|
+
IsOptionalString(value.$id) &&
|
|
252
|
+
IsAdditionalProperties(value.additionalProperties) &&
|
|
253
|
+
ValueGuard.IsObject(value.patternProperties) &&
|
|
253
254
|
((schema) => {
|
|
254
255
|
const keys = Object.getOwnPropertyNames(schema.patternProperties);
|
|
255
256
|
return (keys.length === 1 &&
|
|
256
257
|
IsPattern(keys[0]) &&
|
|
257
258
|
ValueGuard.IsObject(schema.patternProperties) &&
|
|
258
259
|
TSchema(schema.patternProperties[keys[0]]));
|
|
259
|
-
})(
|
|
260
|
-
}
|
|
261
|
-
export function TRecursive(
|
|
262
|
-
return ValueGuard.IsObject(
|
|
263
|
-
}
|
|
264
|
-
export function TRef(
|
|
265
|
-
return (TKindOf(
|
|
266
|
-
IsOptionalString(
|
|
267
|
-
ValueGuard.IsString(
|
|
268
|
-
}
|
|
269
|
-
export function TString(
|
|
270
|
-
return (TKindOf(
|
|
271
|
-
|
|
272
|
-
IsOptionalString(
|
|
273
|
-
IsOptionalNumber(
|
|
274
|
-
IsOptionalNumber(
|
|
275
|
-
IsOptionalPattern(
|
|
276
|
-
IsOptionalFormat(
|
|
277
|
-
}
|
|
278
|
-
export function TSymbol(
|
|
279
|
-
return (TKindOf(
|
|
280
|
-
|
|
281
|
-
IsOptionalString(
|
|
282
|
-
}
|
|
283
|
-
export function TTemplateLiteral(
|
|
284
|
-
return (TKindOf(
|
|
285
|
-
|
|
286
|
-
ValueGuard.IsString(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
export function TThis(
|
|
291
|
-
return (TKindOf(
|
|
292
|
-
IsOptionalString(
|
|
293
|
-
ValueGuard.IsString(
|
|
294
|
-
}
|
|
295
|
-
export function TTransform(
|
|
296
|
-
return ValueGuard.IsObject(
|
|
297
|
-
}
|
|
298
|
-
export function TTuple(
|
|
299
|
-
return (TKindOf(
|
|
300
|
-
|
|
301
|
-
IsOptionalString(
|
|
302
|
-
ValueGuard.IsNumber(
|
|
303
|
-
ValueGuard.IsNumber(
|
|
304
|
-
|
|
305
|
-
((ValueGuard.IsUndefined(
|
|
306
|
-
ValueGuard.IsUndefined(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
export function TUndefined(
|
|
311
|
-
return (TKindOf(
|
|
312
|
-
|
|
313
|
-
IsOptionalString(
|
|
314
|
-
}
|
|
315
|
-
export function TUnionLiteral(
|
|
316
|
-
return TUnion(
|
|
317
|
-
}
|
|
318
|
-
export function TUnion(
|
|
319
|
-
return (TKindOf(
|
|
320
|
-
IsOptionalString(
|
|
321
|
-
ValueGuard.IsObject(
|
|
322
|
-
ValueGuard.IsArray(
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
export function TUint8Array(
|
|
326
|
-
return (TKindOf(
|
|
327
|
-
|
|
328
|
-
IsOptionalString(
|
|
329
|
-
IsOptionalNumber(
|
|
330
|
-
IsOptionalNumber(
|
|
331
|
-
}
|
|
332
|
-
export function TUnknown(
|
|
333
|
-
return (TKindOf(
|
|
334
|
-
IsOptionalString(
|
|
335
|
-
}
|
|
336
|
-
export function TUnsafe(
|
|
337
|
-
return TKindOf(
|
|
338
|
-
}
|
|
339
|
-
export function TVoid(
|
|
340
|
-
return (TKindOf(
|
|
341
|
-
|
|
342
|
-
IsOptionalString(
|
|
343
|
-
}
|
|
344
|
-
export function TKind(
|
|
345
|
-
return ValueGuard.IsObject(
|
|
346
|
-
}
|
|
347
|
-
export function TSchema(
|
|
348
|
-
return (ValueGuard.IsObject(
|
|
349
|
-
TArray(
|
|
350
|
-
TBoolean(
|
|
351
|
-
TBigInt(
|
|
352
|
-
TAsyncIterator(
|
|
353
|
-
TConstructor(
|
|
354
|
-
TDate(
|
|
355
|
-
TFunction(
|
|
356
|
-
TInteger(
|
|
357
|
-
TIntersect(
|
|
358
|
-
TIterator(
|
|
359
|
-
TLiteral(
|
|
360
|
-
TMappedKey(
|
|
361
|
-
TMappedResult(
|
|
362
|
-
TNever(
|
|
363
|
-
TNot(
|
|
364
|
-
TNull(
|
|
365
|
-
TNumber(
|
|
366
|
-
TObject(
|
|
367
|
-
TPromise(
|
|
368
|
-
TRecord(
|
|
369
|
-
TRef(
|
|
370
|
-
TString(
|
|
371
|
-
TSymbol(
|
|
372
|
-
TTemplateLiteral(
|
|
373
|
-
TThis(
|
|
374
|
-
TTuple(
|
|
375
|
-
TUndefined(
|
|
376
|
-
TUnion(
|
|
377
|
-
TUint8Array(
|
|
378
|
-
TUnknown(
|
|
379
|
-
TUnsafe(
|
|
380
|
-
TVoid(
|
|
381
|
-
TKind(
|
|
260
|
+
})(value));
|
|
261
|
+
}
|
|
262
|
+
export function TRecursive(value) {
|
|
263
|
+
return ValueGuard.IsObject(value) && Hint in value && value[Hint] === 'Recursive';
|
|
264
|
+
}
|
|
265
|
+
export function TRef(value) {
|
|
266
|
+
return (TKindOf(value, 'Ref') &&
|
|
267
|
+
IsOptionalString(value.$id) &&
|
|
268
|
+
ValueGuard.IsString(value.$ref));
|
|
269
|
+
}
|
|
270
|
+
export function TString(value) {
|
|
271
|
+
return (TKindOf(value, 'String') &&
|
|
272
|
+
value.type === 'string' &&
|
|
273
|
+
IsOptionalString(value.$id) &&
|
|
274
|
+
IsOptionalNumber(value.minLength) &&
|
|
275
|
+
IsOptionalNumber(value.maxLength) &&
|
|
276
|
+
IsOptionalPattern(value.pattern) &&
|
|
277
|
+
IsOptionalFormat(value.format));
|
|
278
|
+
}
|
|
279
|
+
export function TSymbol(value) {
|
|
280
|
+
return (TKindOf(value, 'Symbol') &&
|
|
281
|
+
value.type === 'symbol' &&
|
|
282
|
+
IsOptionalString(value.$id));
|
|
283
|
+
}
|
|
284
|
+
export function TTemplateLiteral(value) {
|
|
285
|
+
return (TKindOf(value, 'TemplateLiteral') &&
|
|
286
|
+
value.type === 'string' &&
|
|
287
|
+
ValueGuard.IsString(value.pattern) &&
|
|
288
|
+
value.pattern[0] === '^' &&
|
|
289
|
+
value.pattern[value.pattern.length - 1] === '$');
|
|
290
|
+
}
|
|
291
|
+
export function TThis(value) {
|
|
292
|
+
return (TKindOf(value, 'This') &&
|
|
293
|
+
IsOptionalString(value.$id) &&
|
|
294
|
+
ValueGuard.IsString(value.$ref));
|
|
295
|
+
}
|
|
296
|
+
export function TTransform(value) {
|
|
297
|
+
return ValueGuard.IsObject(value) && TransformKind in value;
|
|
298
|
+
}
|
|
299
|
+
export function TTuple(value) {
|
|
300
|
+
return (TKindOf(value, 'Tuple') &&
|
|
301
|
+
value.type === 'array' &&
|
|
302
|
+
IsOptionalString(value.$id) &&
|
|
303
|
+
ValueGuard.IsNumber(value.minItems) &&
|
|
304
|
+
ValueGuard.IsNumber(value.maxItems) &&
|
|
305
|
+
value.minItems === value.maxItems &&
|
|
306
|
+
((ValueGuard.IsUndefined(value.items) &&
|
|
307
|
+
ValueGuard.IsUndefined(value.additionalItems) &&
|
|
308
|
+
value.minItems === 0) || (ValueGuard.IsArray(value.items) &&
|
|
309
|
+
value.items.every(schema => TSchema(schema)))));
|
|
310
|
+
}
|
|
311
|
+
export function TUndefined(value) {
|
|
312
|
+
return (TKindOf(value, 'Undefined') &&
|
|
313
|
+
value.type === 'undefined' &&
|
|
314
|
+
IsOptionalString(value.$id));
|
|
315
|
+
}
|
|
316
|
+
export function TUnionLiteral(value) {
|
|
317
|
+
return TUnion(value) && value.anyOf.every((schema) => TLiteralString(schema) || TLiteralNumber(schema));
|
|
318
|
+
}
|
|
319
|
+
export function TUnion(value) {
|
|
320
|
+
return (TKindOf(value, 'Union') &&
|
|
321
|
+
IsOptionalString(value.$id) &&
|
|
322
|
+
ValueGuard.IsObject(value) &&
|
|
323
|
+
ValueGuard.IsArray(value.anyOf) &&
|
|
324
|
+
value.anyOf.every(schema => TSchema(schema)));
|
|
325
|
+
}
|
|
326
|
+
export function TUint8Array(value) {
|
|
327
|
+
return (TKindOf(value, 'Uint8Array') &&
|
|
328
|
+
value.type === 'Uint8Array' &&
|
|
329
|
+
IsOptionalString(value.$id) &&
|
|
330
|
+
IsOptionalNumber(value.minByteLength) &&
|
|
331
|
+
IsOptionalNumber(value.maxByteLength));
|
|
332
|
+
}
|
|
333
|
+
export function TUnknown(value) {
|
|
334
|
+
return (TKindOf(value, 'Unknown') &&
|
|
335
|
+
IsOptionalString(value.$id));
|
|
336
|
+
}
|
|
337
|
+
export function TUnsafe(value) {
|
|
338
|
+
return TKindOf(value, 'Unsafe');
|
|
339
|
+
}
|
|
340
|
+
export function TVoid(value) {
|
|
341
|
+
return (TKindOf(value, 'Void') &&
|
|
342
|
+
value.type === 'void' &&
|
|
343
|
+
IsOptionalString(value.$id));
|
|
344
|
+
}
|
|
345
|
+
export function TKind(value) {
|
|
346
|
+
return ValueGuard.IsObject(value) && Kind in value && ValueGuard.IsString(value[Kind]) && !KnownTypes.includes(value[Kind]);
|
|
347
|
+
}
|
|
348
|
+
export function TSchema(value) {
|
|
349
|
+
return (ValueGuard.IsObject(value)) && (TAny(value) ||
|
|
350
|
+
TArray(value) ||
|
|
351
|
+
TBoolean(value) ||
|
|
352
|
+
TBigInt(value) ||
|
|
353
|
+
TAsyncIterator(value) ||
|
|
354
|
+
TConstructor(value) ||
|
|
355
|
+
TDate(value) ||
|
|
356
|
+
TFunction(value) ||
|
|
357
|
+
TInteger(value) ||
|
|
358
|
+
TIntersect(value) ||
|
|
359
|
+
TIterator(value) ||
|
|
360
|
+
TLiteral(value) ||
|
|
361
|
+
TMappedKey(value) ||
|
|
362
|
+
TMappedResult(value) ||
|
|
363
|
+
TNever(value) ||
|
|
364
|
+
TNot(value) ||
|
|
365
|
+
TNull(value) ||
|
|
366
|
+
TNumber(value) ||
|
|
367
|
+
TObject(value) ||
|
|
368
|
+
TPromise(value) ||
|
|
369
|
+
TRecord(value) ||
|
|
370
|
+
TRef(value) ||
|
|
371
|
+
TString(value) ||
|
|
372
|
+
TSymbol(value) ||
|
|
373
|
+
TTemplateLiteral(value) ||
|
|
374
|
+
TThis(value) ||
|
|
375
|
+
TTuple(value) ||
|
|
376
|
+
TUndefined(value) ||
|
|
377
|
+
TUnion(value) ||
|
|
378
|
+
TUint8Array(value) ||
|
|
379
|
+
TUnknown(value) ||
|
|
380
|
+
TUnsafe(value) ||
|
|
381
|
+
TVoid(value) ||
|
|
382
|
+
TKind(value));
|
|
382
383
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TSchema } from '../schema/index.mjs';
|
|
2
|
-
import type { Ensure, Evaluate } from '../helpers/index.mjs';
|
|
2
|
+
import type { Ensure, Evaluate, Assert } from '../helpers/index.mjs';
|
|
3
3
|
import { type TArray } from '../array/index.mjs';
|
|
4
4
|
import { type TAsyncIterator } from '../async-iterator/index.mjs';
|
|
5
5
|
import { type TConstructor } from '../constructor/index.mjs';
|
|
@@ -8,19 +8,22 @@ import { type TIndexPropertyKeys } from '../indexed/index.mjs';
|
|
|
8
8
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
9
9
|
import { type TIterator } from '../iterator/index.mjs';
|
|
10
10
|
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
11
|
-
import { type TNever } from '../never/index.mjs';
|
|
12
11
|
import { type TObject, type TProperties, type ObjectOptions } from '../object/index.mjs';
|
|
13
12
|
import { type TOptional } from '../optional/index.mjs';
|
|
14
13
|
import { type TPromise } from '../promise/index.mjs';
|
|
15
14
|
import { type TReadonly } from '../readonly/index.mjs';
|
|
16
15
|
import { type TTuple } from '../tuple/index.mjs';
|
|
17
16
|
import { type TUnion } from '../union/index.mjs';
|
|
18
|
-
import type
|
|
17
|
+
import { type TMappedResult } from './mapped-result.mjs';
|
|
19
18
|
import type { TMappedKey } from './mapped-key.mjs';
|
|
20
|
-
type FromMappedResult<K extends PropertyKey, P extends TProperties> = (K extends keyof P ? FromSchemaType<K, P[K]> :
|
|
19
|
+
type FromMappedResult<K extends PropertyKey, P extends TProperties> = (K extends keyof P ? FromSchemaType<K, P[K]> : TMappedResult<P>);
|
|
21
20
|
declare function FromMappedResult<K extends PropertyKey, P extends TProperties>(K: K, P: P): FromMappedResult<K, P>;
|
|
22
|
-
type
|
|
23
|
-
|
|
21
|
+
type MappedKeyToMappedResultProperties<K extends PropertyKey, P extends PropertyKey[]> = (P extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? {
|
|
22
|
+
[_ in L]: TLiteral<Assert<L, TLiteralValue>>;
|
|
23
|
+
} & MappedKeyToMappedResultProperties<K, R> : {});
|
|
24
|
+
declare function MappedKeyToMappedResultProperties<K extends PropertyKey, P extends PropertyKey[]>(K: K, P: [...P]): MappedKeyToMappedResultProperties<K, P>;
|
|
25
|
+
type FromMappedKey<K extends PropertyKey, P extends PropertyKey[], R extends TProperties = MappedKeyToMappedResultProperties<K, P>> = (FromMappedResult<K, R>);
|
|
26
|
+
declare function FromMappedKey<K extends PropertyKey, P extends PropertyKey[]>(K: K, P: [...P]): FromMappedResult<K, MappedKeyToMappedResultProperties<K, P>>;
|
|
24
27
|
type FromRest<K extends PropertyKey, T extends TSchema[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [FromSchemaType<K, L>, ...FromRest<K, R>] : [];
|
|
25
28
|
declare function FromRest<K extends PropertyKey, T extends TSchema[]>(K: K, T: [...T]): FromRest<K, T>;
|
|
26
29
|
type FromProperties<K extends PropertyKey, T extends TProperties, R extends TProperties = Evaluate<{
|