@sinclair/typebox 0.25.24 → 0.25.25
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 +25 -28
- package/compiler/compiler.js +495 -498
- package/compiler/index.d.ts +2 -2
- package/compiler/index.js +47 -47
- package/conditional/conditional.d.ts +17 -17
- package/conditional/conditional.js +91 -91
- package/conditional/index.d.ts +2 -2
- package/conditional/index.js +45 -45
- package/conditional/structural.d.ts +11 -11
- package/conditional/structural.js +685 -685
- package/custom/custom.d.ts +12 -12
- package/custom/custom.js +55 -55
- package/custom/index.d.ts +1 -1
- package/custom/index.js +44 -44
- package/errors/errors.d.ts +67 -67
- package/errors/errors.js +472 -472
- package/errors/index.d.ts +1 -1
- package/errors/index.js +44 -44
- package/format/format.d.ts +12 -12
- package/format/format.js +55 -55
- package/format/index.d.ts +1 -1
- package/format/index.js +44 -44
- package/guard/extends.d.ts +10 -10
- package/guard/extends.js +50 -50
- package/guard/guard.d.ts +60 -60
- package/guard/guard.js +440 -440
- package/guard/index.d.ts +2 -2
- package/guard/index.js +45 -45
- package/hash/hash.d.ts +8 -8
- package/hash/hash.js +183 -183
- package/hash/index.d.ts +1 -1
- package/hash/index.js +44 -44
- package/license +22 -22
- package/package.json +55 -52
- package/readme.md +1237 -1237
- package/system/index.d.ts +1 -1
- package/system/index.js +44 -44
- package/system/system.d.ts +17 -17
- package/system/system.js +69 -69
- package/typebox.d.ts +422 -422
- package/typebox.js +388 -388
- package/value/cast.d.ts +26 -26
- package/value/cast.js +415 -415
- package/value/check.d.ts +8 -8
- package/value/check.js +405 -405
- package/value/clone.d.ts +3 -3
- package/value/clone.js +71 -71
- package/value/create.d.ts +14 -14
- package/value/create.js +378 -378
- package/value/delta.d.ts +43 -43
- package/value/delta.js +204 -204
- package/value/equal.d.ts +3 -3
- package/value/equal.js +80 -80
- package/value/index.d.ts +4 -4
- package/value/index.js +53 -53
- package/value/is.d.ts +11 -11
- package/value/is.js +53 -53
- package/value/pointer.d.ts +24 -24
- package/value/pointer.js +142 -142
- package/value/value.d.ts +32 -32
- package/value/value.js +87 -87
package/compiler/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { ValueError, ValueErrorType } from '../errors/index';
|
|
2
|
-
export * from './compiler';
|
|
1
|
+
export { ValueError, ValueErrorType } from '../errors/index';
|
|
2
|
+
export * from './compiler';
|
package/compiler/index.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/compiler
|
|
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
|
-
exports.ValueErrorType = void 0;
|
|
45
|
-
var index_1 = require("../errors/index");
|
|
46
|
-
Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function () { return index_1.ValueErrorType; } });
|
|
47
|
-
__exportStar(require("./compiler"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/compiler
|
|
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
|
+
exports.ValueErrorType = void 0;
|
|
45
|
+
var index_1 = require("../errors/index");
|
|
46
|
+
Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function () { return index_1.ValueErrorType; } });
|
|
47
|
+
__exportStar(require("./compiler"), exports);
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import * as Types from '../typebox';
|
|
2
|
-
export type TExtends<L extends Types.TSchema, R extends Types.TSchema, T extends Types.TSchema, U extends Types.TSchema> = Types.Static<L> extends Types.Static<R> ? T : U;
|
|
3
|
-
export interface TExclude<T extends Types.TUnion, U extends Types.TUnion> extends Types.TUnion<any[]> {
|
|
4
|
-
static: Exclude<Types.Static<T, this['params']>, Types.Static<U, this['params']>>;
|
|
5
|
-
}
|
|
6
|
-
export interface TExtract<T extends Types.TSchema, U extends Types.TUnion> extends Types.TUnion<any[]> {
|
|
7
|
-
static: Extract<Types.Static<T, this['params']>, Types.Static<U, this['params']>>;
|
|
8
|
-
}
|
|
9
|
-
/** Conditional type mapping for TypeBox types */
|
|
10
|
-
export declare namespace Conditional {
|
|
11
|
-
/** (Experimental) Creates a conditional expression type */
|
|
12
|
-
function Extends<L extends Types.TSchema, R extends Types.TSchema, T extends Types.TSchema, U extends Types.TSchema>(left: L, right: R, ok: T, fail: U): TExtends<L, R, T, U>;
|
|
13
|
-
/** (Experimental) Constructs a type by excluding from UnionType all union members that are assignable to ExcludedMembers. */
|
|
14
|
-
function Exclude<T extends Types.TUnion, U extends Types.TUnion>(unionType: T, excludedMembers: U, options?: Types.SchemaOptions): TExclude<T, U>;
|
|
15
|
-
/** (Experimental) Constructs a type by extracting from Type all union members that are assignable to Union. */
|
|
16
|
-
function Extract<T extends Types.TSchema, U extends Types.TUnion>(type: T, union: U, options?: Types.SchemaOptions): TExtract<T, U>;
|
|
17
|
-
}
|
|
1
|
+
import * as Types from '../typebox';
|
|
2
|
+
export type TExtends<L extends Types.TSchema, R extends Types.TSchema, T extends Types.TSchema, U extends Types.TSchema> = Types.Static<L> extends Types.Static<R> ? T : U;
|
|
3
|
+
export interface TExclude<T extends Types.TUnion, U extends Types.TUnion> extends Types.TUnion<any[]> {
|
|
4
|
+
static: Exclude<Types.Static<T, this['params']>, Types.Static<U, this['params']>>;
|
|
5
|
+
}
|
|
6
|
+
export interface TExtract<T extends Types.TSchema, U extends Types.TUnion> extends Types.TUnion<any[]> {
|
|
7
|
+
static: Extract<Types.Static<T, this['params']>, Types.Static<U, this['params']>>;
|
|
8
|
+
}
|
|
9
|
+
/** Conditional type mapping for TypeBox types */
|
|
10
|
+
export declare namespace Conditional {
|
|
11
|
+
/** (Experimental) Creates a conditional expression type */
|
|
12
|
+
function Extends<L extends Types.TSchema, R extends Types.TSchema, T extends Types.TSchema, U extends Types.TSchema>(left: L, right: R, ok: T, fail: U): TExtends<L, R, T, U>;
|
|
13
|
+
/** (Experimental) Constructs a type by excluding from UnionType all union members that are assignable to ExcludedMembers. */
|
|
14
|
+
function Exclude<T extends Types.TUnion, U extends Types.TUnion>(unionType: T, excludedMembers: U, options?: Types.SchemaOptions): TExclude<T, U>;
|
|
15
|
+
/** (Experimental) Constructs a type by extracting from Type all union members that are assignable to Union. */
|
|
16
|
+
function Extract<T extends Types.TSchema, U extends Types.TUnion>(type: T, union: U, options?: Types.SchemaOptions): TExtract<T, U>;
|
|
17
|
+
}
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/conditional
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.Conditional = void 0;
|
|
31
|
-
const Types = require("../typebox");
|
|
32
|
-
const structural_1 = require("./structural");
|
|
33
|
-
const index_1 = require("../guard/index");
|
|
34
|
-
/** Conditional type mapping for TypeBox types */
|
|
35
|
-
var Conditional;
|
|
36
|
-
(function (Conditional) {
|
|
37
|
-
/** (Experimental) Creates a conditional expression type */
|
|
38
|
-
function Extends(left, right, ok, fail) {
|
|
39
|
-
switch (structural_1.Structural.Check(left, right)) {
|
|
40
|
-
case structural_1.StructuralResult.Union:
|
|
41
|
-
return Types.Type.Union([Clone(ok), Clone(fail)]);
|
|
42
|
-
case structural_1.StructuralResult.True:
|
|
43
|
-
return Clone(ok);
|
|
44
|
-
case structural_1.StructuralResult.False:
|
|
45
|
-
return Clone(fail);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
Conditional.Extends = Extends;
|
|
49
|
-
/** (Experimental) Constructs a type by excluding from UnionType all union members that are assignable to ExcludedMembers. */
|
|
50
|
-
function Exclude(unionType, excludedMembers, options = {}) {
|
|
51
|
-
const anyOf = unionType.anyOf
|
|
52
|
-
.filter((schema) => {
|
|
53
|
-
const check = structural_1.Structural.Check(schema, excludedMembers);
|
|
54
|
-
return !(check === structural_1.StructuralResult.True || check === structural_1.StructuralResult.Union);
|
|
55
|
-
})
|
|
56
|
-
.map((schema) => Clone(schema));
|
|
57
|
-
return { ...options, [Types.Kind]: 'Union', anyOf };
|
|
58
|
-
}
|
|
59
|
-
Conditional.Exclude = Exclude;
|
|
60
|
-
/** (Experimental) Constructs a type by extracting from Type all union members that are assignable to Union. */
|
|
61
|
-
function Extract(type, union, options = {}) {
|
|
62
|
-
if (index_1.TypeGuard.TUnion(type)) {
|
|
63
|
-
const anyOf = type.anyOf.filter((schema) => structural_1.Structural.Check(schema, union) === structural_1.StructuralResult.True).map((schema) => Clone(schema));
|
|
64
|
-
return { ...options, [Types.Kind]: 'Union', anyOf };
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
const anyOf = union.anyOf.filter((schema) => structural_1.Structural.Check(type, schema) === structural_1.StructuralResult.True).map((schema) => Clone(schema));
|
|
68
|
-
return { ...options, [Types.Kind]: 'Union', anyOf };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
Conditional.Extract = Extract;
|
|
72
|
-
function Clone(value) {
|
|
73
|
-
const isObject = (object) => typeof object === 'object' && object !== null && !Array.isArray(object);
|
|
74
|
-
const isArray = (object) => typeof object === 'object' && object !== null && Array.isArray(object);
|
|
75
|
-
if (isObject(value)) {
|
|
76
|
-
return Object.keys(value).reduce((acc, key) => ({
|
|
77
|
-
...acc,
|
|
78
|
-
[key]: Clone(value[key]),
|
|
79
|
-
}), Object.getOwnPropertySymbols(value).reduce((acc, key) => ({
|
|
80
|
-
...acc,
|
|
81
|
-
[key]: Clone(value[key]),
|
|
82
|
-
}), {}));
|
|
83
|
-
}
|
|
84
|
-
else if (isArray(value)) {
|
|
85
|
-
return value.map((item) => Clone(item));
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
return value;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
})(Conditional = exports.Conditional || (exports.Conditional = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/conditional
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.Conditional = void 0;
|
|
31
|
+
const Types = require("../typebox");
|
|
32
|
+
const structural_1 = require("./structural");
|
|
33
|
+
const index_1 = require("../guard/index");
|
|
34
|
+
/** Conditional type mapping for TypeBox types */
|
|
35
|
+
var Conditional;
|
|
36
|
+
(function (Conditional) {
|
|
37
|
+
/** (Experimental) Creates a conditional expression type */
|
|
38
|
+
function Extends(left, right, ok, fail) {
|
|
39
|
+
switch (structural_1.Structural.Check(left, right)) {
|
|
40
|
+
case structural_1.StructuralResult.Union:
|
|
41
|
+
return Types.Type.Union([Clone(ok), Clone(fail)]);
|
|
42
|
+
case structural_1.StructuralResult.True:
|
|
43
|
+
return Clone(ok);
|
|
44
|
+
case structural_1.StructuralResult.False:
|
|
45
|
+
return Clone(fail);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
Conditional.Extends = Extends;
|
|
49
|
+
/** (Experimental) Constructs a type by excluding from UnionType all union members that are assignable to ExcludedMembers. */
|
|
50
|
+
function Exclude(unionType, excludedMembers, options = {}) {
|
|
51
|
+
const anyOf = unionType.anyOf
|
|
52
|
+
.filter((schema) => {
|
|
53
|
+
const check = structural_1.Structural.Check(schema, excludedMembers);
|
|
54
|
+
return !(check === structural_1.StructuralResult.True || check === structural_1.StructuralResult.Union);
|
|
55
|
+
})
|
|
56
|
+
.map((schema) => Clone(schema));
|
|
57
|
+
return { ...options, [Types.Kind]: 'Union', anyOf };
|
|
58
|
+
}
|
|
59
|
+
Conditional.Exclude = Exclude;
|
|
60
|
+
/** (Experimental) Constructs a type by extracting from Type all union members that are assignable to Union. */
|
|
61
|
+
function Extract(type, union, options = {}) {
|
|
62
|
+
if (index_1.TypeGuard.TUnion(type)) {
|
|
63
|
+
const anyOf = type.anyOf.filter((schema) => structural_1.Structural.Check(schema, union) === structural_1.StructuralResult.True).map((schema) => Clone(schema));
|
|
64
|
+
return { ...options, [Types.Kind]: 'Union', anyOf };
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const anyOf = union.anyOf.filter((schema) => structural_1.Structural.Check(type, schema) === structural_1.StructuralResult.True).map((schema) => Clone(schema));
|
|
68
|
+
return { ...options, [Types.Kind]: 'Union', anyOf };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
Conditional.Extract = Extract;
|
|
72
|
+
function Clone(value) {
|
|
73
|
+
const isObject = (object) => typeof object === 'object' && object !== null && !Array.isArray(object);
|
|
74
|
+
const isArray = (object) => typeof object === 'object' && object !== null && Array.isArray(object);
|
|
75
|
+
if (isObject(value)) {
|
|
76
|
+
return Object.keys(value).reduce((acc, key) => ({
|
|
77
|
+
...acc,
|
|
78
|
+
[key]: Clone(value[key]),
|
|
79
|
+
}), Object.getOwnPropertySymbols(value).reduce((acc, key) => ({
|
|
80
|
+
...acc,
|
|
81
|
+
[key]: Clone(value[key]),
|
|
82
|
+
}), {}));
|
|
83
|
+
}
|
|
84
|
+
else if (isArray(value)) {
|
|
85
|
+
return value.map((item) => Clone(item));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
})(Conditional = exports.Conditional || (exports.Conditional = {}));
|
package/conditional/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './conditional';
|
|
2
|
-
export * from './structural';
|
|
1
|
+
export * from './conditional';
|
|
2
|
+
export * from './structural';
|
package/conditional/index.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/conditional
|
|
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("./conditional"), exports);
|
|
45
|
-
__exportStar(require("./structural"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/conditional
|
|
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("./conditional"), exports);
|
|
45
|
+
__exportStar(require("./structural"), exports);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as Types from '../typebox';
|
|
2
|
-
export declare enum StructuralResult {
|
|
3
|
-
Union = 0,
|
|
4
|
-
True = 1,
|
|
5
|
-
False = 2
|
|
6
|
-
}
|
|
7
|
-
/** Performs structural equivalence checks against TypeBox types. */
|
|
8
|
-
export declare namespace Structural {
|
|
9
|
-
/** Structurally tests if the left schema extends the right. */
|
|
10
|
-
function Check(left: Types.TSchema, right: Types.TSchema): StructuralResult;
|
|
11
|
-
}
|
|
1
|
+
import * as Types from '../typebox';
|
|
2
|
+
export declare enum StructuralResult {
|
|
3
|
+
Union = 0,
|
|
4
|
+
True = 1,
|
|
5
|
+
False = 2
|
|
6
|
+
}
|
|
7
|
+
/** Performs structural equivalence checks against TypeBox types. */
|
|
8
|
+
export declare namespace Structural {
|
|
9
|
+
/** Structurally tests if the left schema extends the right. */
|
|
10
|
+
function Check(left: Types.TSchema, right: Types.TSchema): StructuralResult;
|
|
11
|
+
}
|