@sinclair/typebox 0.24.23 → 0.24.24
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 +8 -1
- package/compiler/compiler.js +127 -54
- package/compiler/index.d.ts +1 -1
- package/compiler/index.js +1 -1
- package/{error → errors}/errors.d.ts +4 -0
- package/{error → errors}/errors.js +76 -50
- package/errors/index.d.ts +1 -0
- package/{compiler/property.js → errors/index.js} +16 -36
- package/guard/guard.js +82 -14
- package/package.json +1 -1
- package/readme.md +57 -55
- package/typebox.js +4 -2
- package/value/cast.d.ts +4 -0
- package/value/cast.js +75 -52
- package/value/check.d.ts +4 -0
- package/value/check.js +75 -49
- package/value/create.d.ts +4 -0
- package/value/create.js +75 -53
- package/value/index.d.ts +1 -1
- package/value/index.js +1 -1
- package/value/value.d.ts +1 -1
- package/value/value.js +2 -2
- package/compiler/property.d.ts +0 -4
package/value/check.js
CHANGED
|
@@ -27,8 +27,15 @@ THE SOFTWARE.
|
|
|
27
27
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.ValueCheck = void 0;
|
|
31
|
-
const
|
|
30
|
+
exports.ValueCheck = exports.ValueCheckInvalidTypeError = void 0;
|
|
31
|
+
const index_1 = require("../guard/index");
|
|
32
|
+
class ValueCheckInvalidTypeError extends Error {
|
|
33
|
+
constructor(schema) {
|
|
34
|
+
super('ValueCheck: Invalid type');
|
|
35
|
+
this.schema = schema;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.ValueCheckInvalidTypeError = ValueCheckInvalidTypeError;
|
|
32
39
|
var ValueCheck;
|
|
33
40
|
(function (ValueCheck) {
|
|
34
41
|
function Any(schema, references, value) {
|
|
@@ -244,53 +251,72 @@ var ValueCheck;
|
|
|
244
251
|
return value === null;
|
|
245
252
|
}
|
|
246
253
|
function Visit(schema, references, value) {
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
254
|
+
const refs = schema.$id === undefined ? references : [schema, ...references];
|
|
255
|
+
if (index_1.TypeGuard.TAny(schema)) {
|
|
256
|
+
return Any(schema, refs, value);
|
|
257
|
+
}
|
|
258
|
+
else if (index_1.TypeGuard.TArray(schema)) {
|
|
259
|
+
return Array(schema, refs, value);
|
|
260
|
+
}
|
|
261
|
+
else if (index_1.TypeGuard.TBoolean(schema)) {
|
|
262
|
+
return Boolean(schema, refs, value);
|
|
263
|
+
}
|
|
264
|
+
else if (index_1.TypeGuard.TConstructor(schema)) {
|
|
265
|
+
return Constructor(schema, refs, value);
|
|
266
|
+
}
|
|
267
|
+
else if (index_1.TypeGuard.TFunction(schema)) {
|
|
268
|
+
return Function(schema, refs, value);
|
|
269
|
+
}
|
|
270
|
+
else if (index_1.TypeGuard.TInteger(schema)) {
|
|
271
|
+
return Integer(schema, refs, value);
|
|
272
|
+
}
|
|
273
|
+
else if (index_1.TypeGuard.TLiteral(schema)) {
|
|
274
|
+
return Literal(schema, refs, value);
|
|
275
|
+
}
|
|
276
|
+
else if (index_1.TypeGuard.TNull(schema)) {
|
|
277
|
+
return Null(schema, refs, value);
|
|
278
|
+
}
|
|
279
|
+
else if (index_1.TypeGuard.TNumber(schema)) {
|
|
280
|
+
return Number(schema, refs, value);
|
|
281
|
+
}
|
|
282
|
+
else if (index_1.TypeGuard.TObject(schema)) {
|
|
283
|
+
return Object(schema, refs, value);
|
|
284
|
+
}
|
|
285
|
+
else if (index_1.TypeGuard.TPromise(schema)) {
|
|
286
|
+
return Promise(schema, refs, value);
|
|
287
|
+
}
|
|
288
|
+
else if (index_1.TypeGuard.TRecord(schema)) {
|
|
289
|
+
return Record(schema, refs, value);
|
|
290
|
+
}
|
|
291
|
+
else if (index_1.TypeGuard.TRef(schema)) {
|
|
292
|
+
return Ref(schema, refs, value);
|
|
293
|
+
}
|
|
294
|
+
else if (index_1.TypeGuard.TSelf(schema)) {
|
|
295
|
+
return Self(schema, refs, value);
|
|
296
|
+
}
|
|
297
|
+
else if (index_1.TypeGuard.TString(schema)) {
|
|
298
|
+
return String(schema, refs, value);
|
|
299
|
+
}
|
|
300
|
+
else if (index_1.TypeGuard.TTuple(schema)) {
|
|
301
|
+
return Tuple(schema, refs, value);
|
|
302
|
+
}
|
|
303
|
+
else if (index_1.TypeGuard.TUndefined(schema)) {
|
|
304
|
+
return Undefined(schema, refs, value);
|
|
305
|
+
}
|
|
306
|
+
else if (index_1.TypeGuard.TUnion(schema)) {
|
|
307
|
+
return Union(schema, refs, value);
|
|
308
|
+
}
|
|
309
|
+
else if (index_1.TypeGuard.TUint8Array(schema)) {
|
|
310
|
+
return Uint8Array(schema, refs, value);
|
|
311
|
+
}
|
|
312
|
+
else if (index_1.TypeGuard.TUnknown(schema)) {
|
|
313
|
+
return Unknown(schema, refs, value);
|
|
314
|
+
}
|
|
315
|
+
else if (index_1.TypeGuard.TVoid(schema)) {
|
|
316
|
+
return Void(schema, refs, value);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
throw new ValueCheckInvalidTypeError(schema);
|
|
294
320
|
}
|
|
295
321
|
}
|
|
296
322
|
// -------------------------------------------------------------------------
|
package/value/create.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import * as Types from '../typebox';
|
|
2
|
+
export declare class ValueCreateInvalidTypeError extends Error {
|
|
3
|
+
readonly schema: Types.TSchema;
|
|
4
|
+
constructor(schema: Types.TSchema);
|
|
5
|
+
}
|
|
2
6
|
export declare namespace ValueCreate {
|
|
3
7
|
/** Creates a value from the given schema. If the schema specifies a default value, then that value is returned. */
|
|
4
8
|
function Visit<T extends Types.TSchema>(schema: T, references: Types.TSchema[]): Types.Static<T>;
|
package/value/create.js
CHANGED
|
@@ -27,8 +27,15 @@ THE SOFTWARE.
|
|
|
27
27
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.ValueCreate = void 0;
|
|
31
|
-
const
|
|
30
|
+
exports.ValueCreate = exports.ValueCreateInvalidTypeError = void 0;
|
|
31
|
+
const index_1 = require("../guard/index");
|
|
32
|
+
class ValueCreateInvalidTypeError extends Error {
|
|
33
|
+
constructor(schema) {
|
|
34
|
+
super('ValueCreate: Invalid type');
|
|
35
|
+
this.schema = schema;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.ValueCreateInvalidTypeError = ValueCreateInvalidTypeError;
|
|
32
39
|
var ValueCreate;
|
|
33
40
|
(function (ValueCreate) {
|
|
34
41
|
function Any(schema, references) {
|
|
@@ -269,57 +276,72 @@ var ValueCreate;
|
|
|
269
276
|
}
|
|
270
277
|
/** Creates a value from the given schema. If the schema specifies a default value, then that value is returned. */
|
|
271
278
|
function Visit(schema, references) {
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
279
|
+
const refs = schema.$id === undefined ? references : [schema, ...references];
|
|
280
|
+
if (index_1.TypeGuard.TAny(schema)) {
|
|
281
|
+
return Any(schema, refs);
|
|
282
|
+
}
|
|
283
|
+
else if (index_1.TypeGuard.TArray(schema)) {
|
|
284
|
+
return Array(schema, refs);
|
|
285
|
+
}
|
|
286
|
+
else if (index_1.TypeGuard.TBoolean(schema)) {
|
|
287
|
+
return Boolean(schema, refs);
|
|
288
|
+
}
|
|
289
|
+
else if (index_1.TypeGuard.TConstructor(schema)) {
|
|
290
|
+
return Constructor(schema, refs);
|
|
291
|
+
}
|
|
292
|
+
else if (index_1.TypeGuard.TFunction(schema)) {
|
|
293
|
+
return Function(schema, refs);
|
|
294
|
+
}
|
|
295
|
+
else if (index_1.TypeGuard.TInteger(schema)) {
|
|
296
|
+
return Integer(schema, refs);
|
|
297
|
+
}
|
|
298
|
+
else if (index_1.TypeGuard.TLiteral(schema)) {
|
|
299
|
+
return Literal(schema, refs);
|
|
300
|
+
}
|
|
301
|
+
else if (index_1.TypeGuard.TNull(schema)) {
|
|
302
|
+
return Null(schema, refs);
|
|
303
|
+
}
|
|
304
|
+
else if (index_1.TypeGuard.TNumber(schema)) {
|
|
305
|
+
return Number(schema, refs);
|
|
306
|
+
}
|
|
307
|
+
else if (index_1.TypeGuard.TObject(schema)) {
|
|
308
|
+
return Object(schema, refs);
|
|
309
|
+
}
|
|
310
|
+
else if (index_1.TypeGuard.TPromise(schema)) {
|
|
311
|
+
return Promise(schema, refs);
|
|
312
|
+
}
|
|
313
|
+
else if (index_1.TypeGuard.TRecord(schema)) {
|
|
314
|
+
return Record(schema, refs);
|
|
315
|
+
}
|
|
316
|
+
else if (index_1.TypeGuard.TRef(schema)) {
|
|
317
|
+
return Ref(schema, refs);
|
|
318
|
+
}
|
|
319
|
+
else if (index_1.TypeGuard.TSelf(schema)) {
|
|
320
|
+
return Self(schema, refs);
|
|
321
|
+
}
|
|
322
|
+
else if (index_1.TypeGuard.TString(schema)) {
|
|
323
|
+
return String(schema, refs);
|
|
324
|
+
}
|
|
325
|
+
else if (index_1.TypeGuard.TTuple(schema)) {
|
|
326
|
+
return Tuple(schema, refs);
|
|
327
|
+
}
|
|
328
|
+
else if (index_1.TypeGuard.TUndefined(schema)) {
|
|
329
|
+
return Undefined(schema, refs);
|
|
330
|
+
}
|
|
331
|
+
else if (index_1.TypeGuard.TUnion(schema)) {
|
|
332
|
+
return Union(schema, refs);
|
|
333
|
+
}
|
|
334
|
+
else if (index_1.TypeGuard.TUint8Array(schema)) {
|
|
335
|
+
return Uint8Array(schema, refs);
|
|
336
|
+
}
|
|
337
|
+
else if (index_1.TypeGuard.TUnknown(schema)) {
|
|
338
|
+
return Unknown(schema, refs);
|
|
339
|
+
}
|
|
340
|
+
else if (index_1.TypeGuard.TVoid(schema)) {
|
|
341
|
+
return Void(schema, refs);
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
throw new ValueCreateInvalidTypeError(schema);
|
|
323
345
|
}
|
|
324
346
|
}
|
|
325
347
|
ValueCreate.Visit = Visit;
|
package/value/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { ValueError, ValueErrorType } from '../
|
|
1
|
+
export { ValueError, ValueErrorType } from '../errors/errors';
|
|
2
2
|
export * from './value';
|
package/value/index.js
CHANGED
|
@@ -42,6 +42,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
42
42
|
};
|
|
43
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
44
|
exports.ValueErrorType = void 0;
|
|
45
|
-
var errors_1 = require("../
|
|
45
|
+
var errors_1 = require("../errors/errors");
|
|
46
46
|
Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function () { return errors_1.ValueErrorType; } });
|
|
47
47
|
__exportStar(require("./value"), exports);
|
package/value/value.d.ts
CHANGED
package/value/value.js
CHANGED
|
@@ -28,7 +28,7 @@ THE SOFTWARE.
|
|
|
28
28
|
---------------------------------------------------------------------------*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
30
|
exports.Value = void 0;
|
|
31
|
-
const
|
|
31
|
+
const index_1 = require("../errors/index");
|
|
32
32
|
const cast_1 = require("./cast");
|
|
33
33
|
const create_1 = require("./create");
|
|
34
34
|
const check_1 = require("./check");
|
|
@@ -52,7 +52,7 @@ var Value;
|
|
|
52
52
|
Value.Cast = Cast;
|
|
53
53
|
function* Errors(...args) {
|
|
54
54
|
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
55
|
-
yield*
|
|
55
|
+
yield* index_1.ValueErrors.Errors(schema, references, value);
|
|
56
56
|
}
|
|
57
57
|
Value.Errors = Errors;
|
|
58
58
|
})(Value = exports.Value || (exports.Value = {}));
|
package/compiler/property.d.ts
DELETED