@sinclair/typebox 0.25.24 → 0.26.0-dev
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/compiler/compiler.d.ts +9 -4
- package/compiler/compiler.js +160 -122
- package/errors/errors.d.ts +56 -46
- package/errors/errors.js +234 -153
- package/package.json +1 -6
- package/readme.md +294 -207
- package/system/system.d.ts +9 -6
- package/system/system.js +17 -17
- package/typebox.d.ts +386 -162
- package/typebox.js +1710 -229
- package/value/cast.d.ts +2 -2
- package/value/cast.js +121 -188
- package/value/check.d.ts +1 -1
- package/value/check.js +156 -111
- package/value/convert.d.ts +13 -0
- package/value/convert.js +345 -0
- package/value/create.d.ts +6 -2
- package/value/create.js +149 -97
- package/{hash → value}/hash.js +39 -14
- package/value/index.d.ts +1 -0
- package/value/index.js +3 -1
- package/value/value.d.ts +2 -8
- package/value/value.js +20 -14
- package/conditional/conditional.d.ts +0 -17
- package/conditional/conditional.js +0 -91
- package/conditional/index.d.ts +0 -2
- package/conditional/index.js +0 -45
- package/conditional/structural.d.ts +0 -11
- package/conditional/structural.js +0 -685
- package/custom/custom.d.ts +0 -12
- package/custom/custom.js +0 -55
- package/custom/index.d.ts +0 -1
- package/custom/index.js +0 -44
- package/format/format.d.ts +0 -12
- package/format/format.js +0 -55
- package/format/index.d.ts +0 -1
- package/format/index.js +0 -44
- package/guard/extends.d.ts +0 -10
- package/guard/extends.js +0 -50
- package/guard/guard.d.ts +0 -60
- package/guard/guard.js +0 -440
- package/guard/index.d.ts +0 -2
- package/guard/index.js +0 -45
- package/hash/index.d.ts +0 -1
- package/hash/index.js +0 -44
- /package/{hash → value}/hash.d.ts +0 -0
package/guard/guard.js
DELETED
|
@@ -1,440 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/guard
|
|
5
|
-
|
|
6
|
-
The MIT License (MIT)
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, dTribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in
|
|
18
|
-
all copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
-
THE SOFTWARE.
|
|
27
|
-
|
|
28
|
-
---------------------------------------------------------------------------*/
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.TypeGuard = exports.TypeGuardUnknownTypeError = void 0;
|
|
31
|
-
const index_1 = require("../custom/index");
|
|
32
|
-
const Types = require("../typebox");
|
|
33
|
-
class TypeGuardUnknownTypeError extends Error {
|
|
34
|
-
constructor(schema) {
|
|
35
|
-
super('TypeGuard: Unknown type');
|
|
36
|
-
this.schema = schema;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.TypeGuardUnknownTypeError = TypeGuardUnknownTypeError;
|
|
40
|
-
/** Provides functionality to test if values are TypeBox types */
|
|
41
|
-
var TypeGuard;
|
|
42
|
-
(function (TypeGuard) {
|
|
43
|
-
function IsObject(value) {
|
|
44
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
45
|
-
}
|
|
46
|
-
function IsArray(value) {
|
|
47
|
-
return typeof value === 'object' && value !== null && Array.isArray(value);
|
|
48
|
-
}
|
|
49
|
-
function IsPattern(value) {
|
|
50
|
-
try {
|
|
51
|
-
new RegExp(value);
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function IsControlCharacterFree(value) {
|
|
59
|
-
if (typeof value !== 'string')
|
|
60
|
-
return false;
|
|
61
|
-
for (let i = 0; i < value.length; i++) {
|
|
62
|
-
const code = value.charCodeAt(i);
|
|
63
|
-
if ((code >= 7 && code <= 13) || code === 27 || code === 127) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
function IsString(value) {
|
|
70
|
-
return typeof value === 'string';
|
|
71
|
-
}
|
|
72
|
-
function IsNumber(value) {
|
|
73
|
-
return typeof value === 'number' && !isNaN(value);
|
|
74
|
-
}
|
|
75
|
-
function IsBoolean(value) {
|
|
76
|
-
return typeof value === 'boolean';
|
|
77
|
-
}
|
|
78
|
-
function IsOptionalNumber(value) {
|
|
79
|
-
return value === undefined || (value !== undefined && IsNumber(value));
|
|
80
|
-
}
|
|
81
|
-
function IsOptionalBoolean(value) {
|
|
82
|
-
return value === undefined || (value !== undefined && IsBoolean(value));
|
|
83
|
-
}
|
|
84
|
-
function IsOptionalString(value) {
|
|
85
|
-
return value === undefined || (value !== undefined && IsString(value));
|
|
86
|
-
}
|
|
87
|
-
function IsOptionalPattern(value) {
|
|
88
|
-
return value === undefined || (value !== undefined && IsString(value) && IsControlCharacterFree(value) && IsPattern(value));
|
|
89
|
-
}
|
|
90
|
-
function IsOptionalFormat(value) {
|
|
91
|
-
return value === undefined || (value !== undefined && IsString(value) && IsControlCharacterFree(value));
|
|
92
|
-
}
|
|
93
|
-
function IsOptionalSchema(value) {
|
|
94
|
-
return value === undefined || TSchema(value);
|
|
95
|
-
}
|
|
96
|
-
/** Returns true if the given schema is TAny */
|
|
97
|
-
function TAny(schema) {
|
|
98
|
-
return IsObject(schema) && schema[Types.Kind] === 'Any' && IsOptionalString(schema.$id);
|
|
99
|
-
}
|
|
100
|
-
TypeGuard.TAny = TAny;
|
|
101
|
-
/** Returns true if the given schema is TArray */
|
|
102
|
-
function TArray(schema) {
|
|
103
|
-
return (IsObject(schema) &&
|
|
104
|
-
schema[Types.Kind] === 'Array' &&
|
|
105
|
-
schema.type === 'array' &&
|
|
106
|
-
IsOptionalString(schema.$id) &&
|
|
107
|
-
TSchema(schema.items) &&
|
|
108
|
-
IsOptionalNumber(schema.minItems) &&
|
|
109
|
-
IsOptionalNumber(schema.maxItems) &&
|
|
110
|
-
IsOptionalBoolean(schema.uniqueItems));
|
|
111
|
-
}
|
|
112
|
-
TypeGuard.TArray = TArray;
|
|
113
|
-
/** Returns true if the given schema is TBoolean */
|
|
114
|
-
function TBoolean(schema) {
|
|
115
|
-
// prettier-ignore
|
|
116
|
-
return (IsObject(schema) &&
|
|
117
|
-
schema[Types.Kind] === 'Boolean' &&
|
|
118
|
-
schema.type === 'boolean' &&
|
|
119
|
-
IsOptionalString(schema.$id));
|
|
120
|
-
}
|
|
121
|
-
TypeGuard.TBoolean = TBoolean;
|
|
122
|
-
/** Returns true if the given schema is TConstructor */
|
|
123
|
-
function TConstructor(schema) {
|
|
124
|
-
// prettier-ignore
|
|
125
|
-
if (!(IsObject(schema) &&
|
|
126
|
-
schema[Types.Kind] === 'Constructor' &&
|
|
127
|
-
schema.type === 'object' &&
|
|
128
|
-
schema.instanceOf === 'Constructor' &&
|
|
129
|
-
IsOptionalString(schema.$id) &&
|
|
130
|
-
IsArray(schema.parameters) &&
|
|
131
|
-
TSchema(schema.returns))) {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
for (const parameter of schema.parameters) {
|
|
135
|
-
if (!TSchema(parameter))
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
TypeGuard.TConstructor = TConstructor;
|
|
141
|
-
/** Returns true if the given schema is TDate */
|
|
142
|
-
function TDate(schema) {
|
|
143
|
-
return (IsObject(schema) &&
|
|
144
|
-
schema[Types.Kind] === 'Date' &&
|
|
145
|
-
schema.type === 'object' &&
|
|
146
|
-
schema.instanceOf === 'Date' &&
|
|
147
|
-
IsOptionalString(schema.$id) &&
|
|
148
|
-
IsOptionalNumber(schema.minimumTimestamp) &&
|
|
149
|
-
IsOptionalNumber(schema.maximumTimestamp) &&
|
|
150
|
-
IsOptionalNumber(schema.exclusiveMinimumTimestamp) &&
|
|
151
|
-
IsOptionalNumber(schema.exclusiveMaximumTimestamp));
|
|
152
|
-
}
|
|
153
|
-
TypeGuard.TDate = TDate;
|
|
154
|
-
/** Returns true if the given schema is TFunction */
|
|
155
|
-
function TFunction(schema) {
|
|
156
|
-
// prettier-ignore
|
|
157
|
-
if (!(IsObject(schema) &&
|
|
158
|
-
schema[Types.Kind] === 'Function' &&
|
|
159
|
-
schema.type === 'object' &&
|
|
160
|
-
schema.instanceOf === 'Function' &&
|
|
161
|
-
IsOptionalString(schema.$id) &&
|
|
162
|
-
IsArray(schema.parameters) &&
|
|
163
|
-
TSchema(schema.returns))) {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
for (const parameter of schema.parameters) {
|
|
167
|
-
if (!TSchema(parameter))
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
TypeGuard.TFunction = TFunction;
|
|
173
|
-
/** Returns true if the given schema is TInteger */
|
|
174
|
-
function TInteger(schema) {
|
|
175
|
-
return (IsObject(schema) &&
|
|
176
|
-
schema[Types.Kind] === 'Integer' &&
|
|
177
|
-
schema.type === 'integer' &&
|
|
178
|
-
IsOptionalString(schema.$id) &&
|
|
179
|
-
IsOptionalNumber(schema.multipleOf) &&
|
|
180
|
-
IsOptionalNumber(schema.minimum) &&
|
|
181
|
-
IsOptionalNumber(schema.maximum) &&
|
|
182
|
-
IsOptionalNumber(schema.exclusiveMinimum) &&
|
|
183
|
-
IsOptionalNumber(schema.exclusiveMaximum));
|
|
184
|
-
}
|
|
185
|
-
TypeGuard.TInteger = TInteger;
|
|
186
|
-
/** Returns true if the given schema is TLiteral */
|
|
187
|
-
function TLiteral(schema) {
|
|
188
|
-
// prettier-ignore
|
|
189
|
-
return (IsObject(schema) &&
|
|
190
|
-
schema[Types.Kind] === 'Literal' &&
|
|
191
|
-
IsOptionalString(schema.$id) &&
|
|
192
|
-
(IsString(schema.const) ||
|
|
193
|
-
IsNumber(schema.const) ||
|
|
194
|
-
IsBoolean(schema.const)));
|
|
195
|
-
}
|
|
196
|
-
TypeGuard.TLiteral = TLiteral;
|
|
197
|
-
/** Returns true if the given schema is TNever */
|
|
198
|
-
function TNever(schema) {
|
|
199
|
-
return (IsObject(schema) &&
|
|
200
|
-
schema[Types.Kind] === 'Never' &&
|
|
201
|
-
IsArray(schema.allOf) &&
|
|
202
|
-
schema.allOf.length === 2 &&
|
|
203
|
-
IsObject(schema.allOf[0]) &&
|
|
204
|
-
IsString(schema.allOf[0].type) &&
|
|
205
|
-
schema.allOf[0].type === 'boolean' &&
|
|
206
|
-
schema.allOf[0].const === false &&
|
|
207
|
-
IsObject(schema.allOf[1]) &&
|
|
208
|
-
IsString(schema.allOf[1].type) &&
|
|
209
|
-
schema.allOf[1].type === 'boolean' &&
|
|
210
|
-
schema.allOf[1].const === true);
|
|
211
|
-
}
|
|
212
|
-
TypeGuard.TNever = TNever;
|
|
213
|
-
/** Returns true if the given schema is TNull */
|
|
214
|
-
function TNull(schema) {
|
|
215
|
-
return IsObject(schema) && schema[Types.Kind] === 'Null' && schema.type === 'null' && IsOptionalString(schema.$id);
|
|
216
|
-
}
|
|
217
|
-
TypeGuard.TNull = TNull;
|
|
218
|
-
/** Returns true if the given schema is TNumber */
|
|
219
|
-
function TNumber(schema) {
|
|
220
|
-
return (IsObject(schema) &&
|
|
221
|
-
schema[Types.Kind] === 'Number' &&
|
|
222
|
-
schema.type === 'number' &&
|
|
223
|
-
IsOptionalString(schema.$id) &&
|
|
224
|
-
IsOptionalNumber(schema.multipleOf) &&
|
|
225
|
-
IsOptionalNumber(schema.minimum) &&
|
|
226
|
-
IsOptionalNumber(schema.maximum) &&
|
|
227
|
-
IsOptionalNumber(schema.exclusiveMinimum) &&
|
|
228
|
-
IsOptionalNumber(schema.exclusiveMaximum));
|
|
229
|
-
}
|
|
230
|
-
TypeGuard.TNumber = TNumber;
|
|
231
|
-
/** Returns true if the given schema is TObject */
|
|
232
|
-
function TObject(schema) {
|
|
233
|
-
if (!(IsObject(schema) &&
|
|
234
|
-
schema[Types.Kind] === 'Object' &&
|
|
235
|
-
schema.type === 'object' &&
|
|
236
|
-
IsOptionalString(schema.$id) &&
|
|
237
|
-
IsObject(schema.properties) &&
|
|
238
|
-
(IsOptionalBoolean(schema.additionalProperties) || IsOptionalSchema(schema.additionalProperties)) &&
|
|
239
|
-
IsOptionalNumber(schema.minProperties) &&
|
|
240
|
-
IsOptionalNumber(schema.maxProperties))) {
|
|
241
|
-
return false;
|
|
242
|
-
}
|
|
243
|
-
for (const [key, value] of Object.entries(schema.properties)) {
|
|
244
|
-
if (!IsControlCharacterFree(key))
|
|
245
|
-
return false;
|
|
246
|
-
if (!TSchema(value))
|
|
247
|
-
return false;
|
|
248
|
-
}
|
|
249
|
-
return true;
|
|
250
|
-
}
|
|
251
|
-
TypeGuard.TObject = TObject;
|
|
252
|
-
/** Returns true if the given schema is TPromise */
|
|
253
|
-
function TPromise(schema) {
|
|
254
|
-
// prettier-ignore
|
|
255
|
-
return (IsObject(schema) &&
|
|
256
|
-
schema[Types.Kind] === 'Promise' &&
|
|
257
|
-
schema.type === 'object' &&
|
|
258
|
-
schema.instanceOf === 'Promise' &&
|
|
259
|
-
IsOptionalString(schema.$id) &&
|
|
260
|
-
TSchema(schema.item));
|
|
261
|
-
}
|
|
262
|
-
TypeGuard.TPromise = TPromise;
|
|
263
|
-
/** Returns true if the given schema is TRecord */
|
|
264
|
-
function TRecord(schema) {
|
|
265
|
-
// prettier-ignore
|
|
266
|
-
if (!(IsObject(schema) &&
|
|
267
|
-
schema[Types.Kind] === 'Record' &&
|
|
268
|
-
schema.type === 'object' &&
|
|
269
|
-
IsOptionalString(schema.$id) &&
|
|
270
|
-
schema.additionalProperties === false &&
|
|
271
|
-
IsObject(schema.patternProperties))) {
|
|
272
|
-
return false;
|
|
273
|
-
}
|
|
274
|
-
const keys = Object.keys(schema.patternProperties);
|
|
275
|
-
if (keys.length !== 1) {
|
|
276
|
-
return false;
|
|
277
|
-
}
|
|
278
|
-
if (!IsPattern(keys[0])) {
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
if (!TSchema(schema.patternProperties[keys[0]])) {
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
284
|
-
return true;
|
|
285
|
-
}
|
|
286
|
-
TypeGuard.TRecord = TRecord;
|
|
287
|
-
/** Returns true if the given schema is TSelf */
|
|
288
|
-
function TSelf(schema) {
|
|
289
|
-
// prettier-ignore
|
|
290
|
-
return (IsObject(schema) &&
|
|
291
|
-
schema[Types.Kind] === 'Self' &&
|
|
292
|
-
IsOptionalString(schema.$id) &&
|
|
293
|
-
IsString(schema.$ref));
|
|
294
|
-
}
|
|
295
|
-
TypeGuard.TSelf = TSelf;
|
|
296
|
-
/** Returns true if the given schema is TRef */
|
|
297
|
-
function TRef(schema) {
|
|
298
|
-
// prettier-ignore
|
|
299
|
-
return (IsObject(schema) &&
|
|
300
|
-
schema[Types.Kind] === 'Ref' &&
|
|
301
|
-
IsOptionalString(schema.$id) &&
|
|
302
|
-
IsString(schema.$ref));
|
|
303
|
-
}
|
|
304
|
-
TypeGuard.TRef = TRef;
|
|
305
|
-
/** Returns true if the given schema is TString */
|
|
306
|
-
function TString(schema) {
|
|
307
|
-
return (IsObject(schema) &&
|
|
308
|
-
schema[Types.Kind] === 'String' &&
|
|
309
|
-
schema.type === 'string' &&
|
|
310
|
-
IsOptionalString(schema.$id) &&
|
|
311
|
-
IsOptionalNumber(schema.minLength) &&
|
|
312
|
-
IsOptionalNumber(schema.maxLength) &&
|
|
313
|
-
IsOptionalPattern(schema.pattern) &&
|
|
314
|
-
IsOptionalFormat(schema.format));
|
|
315
|
-
}
|
|
316
|
-
TypeGuard.TString = TString;
|
|
317
|
-
/** Returns true if the given schema is TTuple */
|
|
318
|
-
function TTuple(schema) {
|
|
319
|
-
// prettier-ignore
|
|
320
|
-
if (!(IsObject(schema) &&
|
|
321
|
-
schema[Types.Kind] === 'Tuple' &&
|
|
322
|
-
schema.type === 'array' &&
|
|
323
|
-
IsOptionalString(schema.$id) &&
|
|
324
|
-
IsNumber(schema.minItems) &&
|
|
325
|
-
IsNumber(schema.maxItems) &&
|
|
326
|
-
schema.minItems === schema.maxItems)) {
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
if (schema.items === undefined && schema.additionalItems === undefined && schema.minItems === 0) {
|
|
330
|
-
return true;
|
|
331
|
-
}
|
|
332
|
-
if (!IsArray(schema.items)) {
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
for (const inner of schema.items) {
|
|
336
|
-
if (!TSchema(inner))
|
|
337
|
-
return false;
|
|
338
|
-
}
|
|
339
|
-
return true;
|
|
340
|
-
}
|
|
341
|
-
TypeGuard.TTuple = TTuple;
|
|
342
|
-
/** Returns true if the given schema is TUndefined */
|
|
343
|
-
function TUndefined(schema) {
|
|
344
|
-
// prettier-ignore
|
|
345
|
-
return (IsObject(schema) &&
|
|
346
|
-
schema[Types.Kind] === 'Undefined' &&
|
|
347
|
-
schema.type === 'null' &&
|
|
348
|
-
schema.typeOf === 'Undefined' &&
|
|
349
|
-
IsOptionalString(schema.$id));
|
|
350
|
-
}
|
|
351
|
-
TypeGuard.TUndefined = TUndefined;
|
|
352
|
-
/** Returns true if the given schema is TUnion */
|
|
353
|
-
function TUnion(schema) {
|
|
354
|
-
// prettier-ignore
|
|
355
|
-
if (!(IsObject(schema) &&
|
|
356
|
-
schema[Types.Kind] === 'Union' &&
|
|
357
|
-
IsArray(schema.anyOf) &&
|
|
358
|
-
IsOptionalString(schema.$id))) {
|
|
359
|
-
return false;
|
|
360
|
-
}
|
|
361
|
-
for (const inner of schema.anyOf) {
|
|
362
|
-
if (!TSchema(inner))
|
|
363
|
-
return false;
|
|
364
|
-
}
|
|
365
|
-
return true;
|
|
366
|
-
}
|
|
367
|
-
TypeGuard.TUnion = TUnion;
|
|
368
|
-
/** Returns true if the given schema is TUint8Array */
|
|
369
|
-
function TUint8Array(schema) {
|
|
370
|
-
return (IsObject(schema) &&
|
|
371
|
-
schema[Types.Kind] === 'Uint8Array' &&
|
|
372
|
-
schema.type === 'object' &&
|
|
373
|
-
IsOptionalString(schema.$id) &&
|
|
374
|
-
schema.instanceOf === 'Uint8Array' &&
|
|
375
|
-
IsOptionalNumber(schema.minByteLength) &&
|
|
376
|
-
IsOptionalNumber(schema.maxByteLength));
|
|
377
|
-
}
|
|
378
|
-
TypeGuard.TUint8Array = TUint8Array;
|
|
379
|
-
/** Returns true if the given schema is TUnknown */
|
|
380
|
-
function TUnknown(schema) {
|
|
381
|
-
// prettier-ignore
|
|
382
|
-
return (IsObject(schema) &&
|
|
383
|
-
schema[Types.Kind] === 'Unknown' &&
|
|
384
|
-
IsOptionalString(schema.$id));
|
|
385
|
-
}
|
|
386
|
-
TypeGuard.TUnknown = TUnknown;
|
|
387
|
-
/** Returns true if the given schema is TVoid */
|
|
388
|
-
function TVoid(schema) {
|
|
389
|
-
// prettier-ignore
|
|
390
|
-
return (IsObject(schema) &&
|
|
391
|
-
schema[Types.Kind] === 'Void' &&
|
|
392
|
-
schema.type === 'null' &&
|
|
393
|
-
schema.typeOf === 'Void' &&
|
|
394
|
-
IsOptionalString(schema.$id));
|
|
395
|
-
}
|
|
396
|
-
TypeGuard.TVoid = TVoid;
|
|
397
|
-
/** Returns true if the given schema is a registered user defined type */
|
|
398
|
-
function TUserDefined(schema) {
|
|
399
|
-
return IsObject(schema) && IsString(schema[Types.Kind]) && index_1.Custom.Has(schema[Types.Kind]);
|
|
400
|
-
}
|
|
401
|
-
TypeGuard.TUserDefined = TUserDefined;
|
|
402
|
-
/** Returns true if the given schema is TSchema */
|
|
403
|
-
function TSchema(schema) {
|
|
404
|
-
return (TAny(schema) ||
|
|
405
|
-
TArray(schema) ||
|
|
406
|
-
TBoolean(schema) ||
|
|
407
|
-
TConstructor(schema) ||
|
|
408
|
-
TDate(schema) ||
|
|
409
|
-
TFunction(schema) ||
|
|
410
|
-
TInteger(schema) ||
|
|
411
|
-
TLiteral(schema) ||
|
|
412
|
-
TNever(schema) ||
|
|
413
|
-
TNull(schema) ||
|
|
414
|
-
TNumber(schema) ||
|
|
415
|
-
TObject(schema) ||
|
|
416
|
-
TPromise(schema) ||
|
|
417
|
-
TRecord(schema) ||
|
|
418
|
-
TSelf(schema) ||
|
|
419
|
-
TRef(schema) ||
|
|
420
|
-
TString(schema) ||
|
|
421
|
-
TTuple(schema) ||
|
|
422
|
-
TUndefined(schema) ||
|
|
423
|
-
TUnion(schema) ||
|
|
424
|
-
TUint8Array(schema) ||
|
|
425
|
-
TUnknown(schema) ||
|
|
426
|
-
TVoid(schema) ||
|
|
427
|
-
TUserDefined(schema));
|
|
428
|
-
}
|
|
429
|
-
TypeGuard.TSchema = TSchema;
|
|
430
|
-
/** Asserts if this schema and associated references are valid. */
|
|
431
|
-
function Assert(schema, references = []) {
|
|
432
|
-
if (!TSchema(schema))
|
|
433
|
-
throw new TypeGuardUnknownTypeError(schema);
|
|
434
|
-
for (const schema of references) {
|
|
435
|
-
if (!TSchema(schema))
|
|
436
|
-
throw new TypeGuardUnknownTypeError(schema);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
TypeGuard.Assert = Assert;
|
|
440
|
-
})(TypeGuard = exports.TypeGuard || (exports.TypeGuard = {}));
|
package/guard/index.d.ts
DELETED
package/guard/index.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/guards
|
|
5
|
-
|
|
6
|
-
The MIT License (MIT)
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in
|
|
18
|
-
all copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
-
THE SOFTWARE.
|
|
27
|
-
|
|
28
|
-
---------------------------------------------------------------------------*/
|
|
29
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
30
|
-
if (k2 === undefined) k2 = k;
|
|
31
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
32
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
33
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
34
|
-
}
|
|
35
|
-
Object.defineProperty(o, k2, desc);
|
|
36
|
-
}) : (function(o, m, k, k2) {
|
|
37
|
-
if (k2 === undefined) k2 = k;
|
|
38
|
-
o[k2] = m[k];
|
|
39
|
-
}));
|
|
40
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
41
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
42
|
-
};
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
__exportStar(require("./guard"), exports);
|
|
45
|
-
__exportStar(require("./extends"), exports);
|
package/hash/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './hash';
|
package/hash/index.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/hash
|
|
5
|
-
|
|
6
|
-
The MIT License (MIT)
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in
|
|
18
|
-
all copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
-
THE SOFTWARE.
|
|
27
|
-
|
|
28
|
-
---------------------------------------------------------------------------*/
|
|
29
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
30
|
-
if (k2 === undefined) k2 = k;
|
|
31
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
32
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
33
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
34
|
-
}
|
|
35
|
-
Object.defineProperty(o, k2, desc);
|
|
36
|
-
}) : (function(o, m, k, k2) {
|
|
37
|
-
if (k2 === undefined) k2 = k;
|
|
38
|
-
o[k2] = m[k];
|
|
39
|
-
}));
|
|
40
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
41
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
42
|
-
};
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
__exportStar(require("./hash"), exports);
|
|
File without changes
|