@sinclair/typebox 0.25.24 → 0.26.0-dev.1

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.
Files changed (46) hide show
  1. package/compiler/compiler.d.ts +10 -5
  2. package/compiler/compiler.js +161 -123
  3. package/errors/errors.d.ts +56 -46
  4. package/errors/errors.js +234 -153
  5. package/package.json +1 -6
  6. package/readme.md +294 -207
  7. package/system/system.d.ts +9 -6
  8. package/system/system.js +17 -17
  9. package/typebox.d.ts +388 -162
  10. package/typebox.js +1716 -229
  11. package/value/cast.d.ts +2 -2
  12. package/value/cast.js +121 -188
  13. package/value/check.d.ts +1 -1
  14. package/value/check.js +156 -111
  15. package/value/convert.d.ts +13 -0
  16. package/value/convert.js +345 -0
  17. package/value/create.d.ts +6 -2
  18. package/value/create.js +149 -97
  19. package/{hash → value}/hash.js +39 -14
  20. package/value/index.d.ts +1 -0
  21. package/value/index.js +3 -1
  22. package/value/value.d.ts +2 -8
  23. package/value/value.js +20 -14
  24. package/conditional/conditional.d.ts +0 -17
  25. package/conditional/conditional.js +0 -91
  26. package/conditional/index.d.ts +0 -2
  27. package/conditional/index.js +0 -45
  28. package/conditional/structural.d.ts +0 -11
  29. package/conditional/structural.js +0 -685
  30. package/custom/custom.d.ts +0 -12
  31. package/custom/custom.js +0 -55
  32. package/custom/index.d.ts +0 -1
  33. package/custom/index.js +0 -44
  34. package/format/format.d.ts +0 -12
  35. package/format/format.js +0 -55
  36. package/format/index.d.ts +0 -1
  37. package/format/index.js +0 -44
  38. package/guard/extends.d.ts +0 -10
  39. package/guard/extends.js +0 -50
  40. package/guard/guard.d.ts +0 -60
  41. package/guard/guard.js +0 -440
  42. package/guard/index.d.ts +0 -2
  43. package/guard/index.js +0 -45
  44. package/hash/index.d.ts +0 -1
  45. package/hash/index.js +0 -44
  46. /package/{hash → value}/hash.d.ts +0 -0
package/custom/custom.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
- /*--------------------------------------------------------------------------
3
-
4
- @sinclair/typebox/custom
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.Custom = void 0;
31
- /** Provides functions to create user defined types */
32
- var Custom;
33
- (function (Custom) {
34
- const customs = new Map();
35
- /** Clears all user defined types */
36
- function Clear() {
37
- return customs.clear();
38
- }
39
- Custom.Clear = Clear;
40
- /** Returns true if this user defined type exists */
41
- function Has(kind) {
42
- return customs.has(kind);
43
- }
44
- Custom.Has = Has;
45
- /** Sets a validation function for a user defined type */
46
- function Set(kind, func) {
47
- customs.set(kind, func);
48
- }
49
- Custom.Set = Set;
50
- /** Gets a custom validation function for a user defined type */
51
- function Get(kind) {
52
- return customs.get(kind);
53
- }
54
- Custom.Get = Get;
55
- })(Custom = exports.Custom || (exports.Custom = {}));
package/custom/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './custom';
package/custom/index.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
- /*--------------------------------------------------------------------------
3
-
4
- @sinclair/typebox/custom
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("./custom"), exports);
@@ -1,12 +0,0 @@
1
- export type FormatValidationFunction = (value: string) => boolean;
2
- /** Provides functions to create user defined string formats */
3
- export declare namespace Format {
4
- /** Clears all user defined string formats */
5
- function Clear(): void;
6
- /** Returns true if the user defined string format exists */
7
- function Has(format: string): boolean;
8
- /** Sets a validation function for a user defined string format */
9
- function Set(format: string, func: FormatValidationFunction): void;
10
- /** Gets a validation function for a user defined string format */
11
- function Get(format: string): FormatValidationFunction | undefined;
12
- }
package/format/format.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
- /*--------------------------------------------------------------------------
3
-
4
- @sinclair/typebox/format
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.Format = void 0;
31
- /** Provides functions to create user defined string formats */
32
- var Format;
33
- (function (Format) {
34
- const formats = new Map();
35
- /** Clears all user defined string formats */
36
- function Clear() {
37
- return formats.clear();
38
- }
39
- Format.Clear = Clear;
40
- /** Returns true if the user defined string format exists */
41
- function Has(format) {
42
- return formats.has(format);
43
- }
44
- Format.Has = Has;
45
- /** Sets a validation function for a user defined string format */
46
- function Set(format, func) {
47
- formats.set(format, func);
48
- }
49
- Format.Set = Set;
50
- /** Gets a validation function for a user defined string format */
51
- function Get(format) {
52
- return formats.get(format);
53
- }
54
- Format.Get = Get;
55
- })(Format = exports.Format || (exports.Format = {}));
package/format/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './format';
package/format/index.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
- /*--------------------------------------------------------------------------
3
-
4
- @sinclair/typebox/format
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("./format"), exports);
@@ -1,10 +0,0 @@
1
- import * as Types from '../typebox';
2
- export declare namespace TypeExtends {
3
- /**
4
- * This function returns true if the given schema is undefined, either directly or
5
- * through union composition. This check is required on object property types of
6
- * undefined, where an additional `'x' in value` check is required to determine
7
- * the keys existence.
8
- */
9
- function Undefined(schema: Types.TSchema): boolean;
10
- }
package/guard/extends.js DELETED
@@ -1,50 +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.TypeExtends = void 0;
31
- const Types = require("../typebox");
32
- var TypeExtends;
33
- (function (TypeExtends) {
34
- /**
35
- * This function returns true if the given schema is undefined, either directly or
36
- * through union composition. This check is required on object property types of
37
- * undefined, where an additional `'x' in value` check is required to determine
38
- * the keys existence.
39
- */
40
- function Undefined(schema) {
41
- if (schema[Types.Kind] === 'Undefined')
42
- return true;
43
- if (schema[Types.Kind] === 'Union') {
44
- const union = schema;
45
- return union.anyOf.some((schema) => Undefined(schema));
46
- }
47
- return false;
48
- }
49
- TypeExtends.Undefined = Undefined;
50
- })(TypeExtends = exports.TypeExtends || (exports.TypeExtends = {}));
package/guard/guard.d.ts DELETED
@@ -1,60 +0,0 @@
1
- import * as Types from '../typebox';
2
- export declare class TypeGuardUnknownTypeError extends Error {
3
- readonly schema: unknown;
4
- constructor(schema: unknown);
5
- }
6
- /** Provides functionality to test if values are TypeBox types */
7
- export declare namespace TypeGuard {
8
- /** Returns true if the given schema is TAny */
9
- function TAny(schema: unknown): schema is Types.TAny;
10
- /** Returns true if the given schema is TArray */
11
- function TArray(schema: unknown): schema is Types.TArray;
12
- /** Returns true if the given schema is TBoolean */
13
- function TBoolean(schema: unknown): schema is Types.TBoolean;
14
- /** Returns true if the given schema is TConstructor */
15
- function TConstructor(schema: unknown): schema is Types.TConstructor;
16
- /** Returns true if the given schema is TDate */
17
- function TDate(schema: unknown): schema is Types.TDate;
18
- /** Returns true if the given schema is TFunction */
19
- function TFunction(schema: unknown): schema is Types.TFunction;
20
- /** Returns true if the given schema is TInteger */
21
- function TInteger(schema: unknown): schema is Types.TInteger;
22
- /** Returns true if the given schema is TLiteral */
23
- function TLiteral(schema: unknown): schema is Types.TLiteral;
24
- /** Returns true if the given schema is TNever */
25
- function TNever(schema: unknown): schema is Types.TNever;
26
- /** Returns true if the given schema is TNull */
27
- function TNull(schema: unknown): schema is Types.TNull;
28
- /** Returns true if the given schema is TNumber */
29
- function TNumber(schema: unknown): schema is Types.TNumber;
30
- /** Returns true if the given schema is TObject */
31
- function TObject(schema: unknown): schema is Types.TObject;
32
- /** Returns true if the given schema is TPromise */
33
- function TPromise(schema: unknown): schema is Types.TPromise;
34
- /** Returns true if the given schema is TRecord */
35
- function TRecord(schema: unknown): schema is Types.TRecord;
36
- /** Returns true if the given schema is TSelf */
37
- function TSelf(schema: unknown): schema is Types.TSelf;
38
- /** Returns true if the given schema is TRef */
39
- function TRef(schema: unknown): schema is Types.TRef;
40
- /** Returns true if the given schema is TString */
41
- function TString(schema: unknown): schema is Types.TString;
42
- /** Returns true if the given schema is TTuple */
43
- function TTuple(schema: unknown): schema is Types.TTuple;
44
- /** Returns true if the given schema is TUndefined */
45
- function TUndefined(schema: unknown): schema is Types.TUndefined;
46
- /** Returns true if the given schema is TUnion */
47
- function TUnion(schema: unknown): schema is Types.TUnion;
48
- /** Returns true if the given schema is TUint8Array */
49
- function TUint8Array(schema: unknown): schema is Types.TUint8Array;
50
- /** Returns true if the given schema is TUnknown */
51
- function TUnknown(schema: unknown): schema is Types.TUnknown;
52
- /** Returns true if the given schema is TVoid */
53
- function TVoid(schema: unknown): schema is Types.TVoid;
54
- /** Returns true if the given schema is a registered user defined type */
55
- function TUserDefined(schema: unknown): schema is Types.TSchema;
56
- /** Returns true if the given schema is TSchema */
57
- function TSchema(schema: unknown): schema is Types.TSchema;
58
- /** Asserts if this schema and associated references are valid. */
59
- function Assert<T extends Types.TSchema>(schema: T, references?: Types.TSchema[]): void;
60
- }