@sinclair/typebox 0.33.17 → 0.33.18

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.
@@ -40,5 +40,5 @@ export interface TObject<T extends TProperties = TProperties> extends TSchema, O
40
40
  /** `[Json]` Creates an Object type */
41
41
  declare function _Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
42
42
  /** `[Json]` Creates an Object type */
43
- export declare const Object: typeof _Object;
43
+ export declare var Object: typeof _Object;
44
44
  export {};
@@ -0,0 +1,6 @@
1
+ import type { TSchema } from '../../type/schema/index';
2
+ import type { StaticDecode } from '../../type/static/index';
3
+ /** Decodes a value or throws if error */
4
+ export declare function Decode<T extends TSchema, Static = StaticDecode<T>, Result extends Static = Static>(schema: T, references: TSchema[], value: unknown): Result;
5
+ /** Decodes a value or throws if error */
6
+ export declare function Decode<T extends TSchema, Static = StaticDecode<T>, Result extends Static = Static>(schema: T, value: unknown): Result;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Decode = Decode;
5
+ const index_1 = require("../transform/index");
6
+ const index_2 = require("../check/index");
7
+ const index_3 = require("../../errors/index");
8
+ /** Decodes a value or throws if error */
9
+ function Decode(...args) {
10
+ const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
11
+ if (!(0, index_2.Check)(schema, references, value))
12
+ throw new index_1.TransformDecodeCheckError(schema, value, (0, index_3.Errors)(schema, references, value).First());
13
+ return (0, index_1.HasTransform)(schema, references) ? (0, index_1.TransformDecode)(schema, references, value) : value;
14
+ }
@@ -0,0 +1 @@
1
+ export * from './decode';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./decode"), exports);
@@ -0,0 +1,6 @@
1
+ import type { TSchema } from '../../type/schema/index';
2
+ import type { StaticEncode } from '../../type/static/index';
3
+ /** Encodes a value or throws if error */
4
+ export declare function Encode<T extends TSchema, Static = StaticEncode<T>, Result extends Static = Static>(schema: T, references: TSchema[], value: unknown): Result;
5
+ /** Encodes a value or throws if error */
6
+ export declare function Encode<T extends TSchema, Static = StaticEncode<T>, Result extends Static = Static>(schema: T, value: unknown): Result;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Encode = Encode;
5
+ const index_1 = require("../transform/index");
6
+ const index_2 = require("../check/index");
7
+ const index_3 = require("../../errors/index");
8
+ /** Encodes a value or throws if error */
9
+ function Encode(...args) {
10
+ const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
11
+ const encoded = (0, index_1.HasTransform)(schema, references) ? (0, index_1.TransformEncode)(schema, references, value) : value;
12
+ if (!(0, index_2.Check)(schema, references, encoded))
13
+ throw new index_1.TransformEncodeCheckError(schema, encoded, (0, index_3.Errors)(schema, references, encoded).First());
14
+ return encoded;
15
+ }
@@ -0,0 +1 @@
1
+ export * from './encode';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./encode"), exports);
@@ -7,8 +7,10 @@ export * from './clean/index';
7
7
  export * from './clone/index';
8
8
  export * from './convert/index';
9
9
  export * from './create/index';
10
+ export * from './decode/index';
10
11
  export * from './default/index';
11
12
  export * from './delta/index';
13
+ export * from './encode/index';
12
14
  export * from './equal/index';
13
15
  export * from './hash/index';
14
16
  export * from './mutate/index';
@@ -36,8 +36,10 @@ __exportStar(require("./clean/index"), exports);
36
36
  __exportStar(require("./clone/index"), exports);
37
37
  __exportStar(require("./convert/index"), exports);
38
38
  __exportStar(require("./create/index"), exports);
39
+ __exportStar(require("./decode/index"), exports);
39
40
  __exportStar(require("./default/index"), exports);
40
41
  __exportStar(require("./delta/index"), exports);
42
+ __exportStar(require("./encode/index"), exports);
41
43
  __exportStar(require("./equal/index"), exports);
42
44
  __exportStar(require("./hash/index"), exports);
43
45
  __exportStar(require("./mutate/index"), exports);
@@ -1,61 +1,16 @@
1
- import { type Mutable } from '../mutate/index';
2
- import { Edit } from '../delta/index';
3
- import { ValueErrorIterator } from '../../errors/index';
4
- import type { TSchema } from '../../type/schema/index';
5
- import type { Static, StaticDecode, StaticEncode } from '../../type/static/index';
6
- /** Asserts a value matches the given type or throws an `AssertError` if invalid. */
7
- export declare function Assert<T extends TSchema, R = Static<T>>(schema: T, references: TSchema[], value: unknown): asserts value is R;
8
- /** Asserts a value matches the given type or throws an `AssertError` if invalid. */
9
- export declare function Assert<T extends TSchema, R = Static<T>>(schema: T, value: unknown): asserts value is R;
10
- /** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
11
- export declare function Cast<T extends TSchema>(schema: T, references: TSchema[], value: unknown): Static<T>;
12
- /** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
13
- export declare function Cast<T extends TSchema>(schema: T, value: unknown): Static<T>;
14
- /** Creates a value from the given type and references */
15
- export declare function Create<T extends TSchema>(schema: T, references: TSchema[]): Static<T>;
16
- /** Creates a value from the given type */
17
- export declare function Create<T extends TSchema>(schema: T): Static<T>;
18
- /** Returns true if the value matches the given type and references */
19
- export declare function Check<T extends TSchema>(schema: T, references: TSchema[], value: unknown): value is Static<T>;
20
- /** Returns true if the value matches the given type */
21
- export declare function Check<T extends TSchema>(schema: T, value: unknown): value is Static<T>;
22
- /** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
23
- export declare function Clean(schema: TSchema, references: TSchema[], value: unknown): unknown;
24
- /** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
25
- export declare function Clean(schema: TSchema, value: unknown): unknown;
26
- /** `[Mutable]` Converts any type mismatched values to their target type if a reasonable conversion is possible. */
27
- export declare function Convert(schema: TSchema, references: TSchema[], value: unknown): unknown;
28
- /** `[Mutable]` Converts any type mismatched values to their target type if a reasonable conversion is possible. */
29
- export declare function Convert(schema: TSchema, value: unknown): unknown;
30
- /** Returns a structural clone of the given value */
31
- export declare function Clone<T>(value: T): T;
32
- /** Decodes a value or throws if error */
33
- export declare function Decode<T extends TSchema, Static = StaticDecode<T>, Result extends Static = Static>(schema: T, references: TSchema[], value: unknown): Result;
34
- /** Decodes a value or throws if error */
35
- export declare function Decode<T extends TSchema, Static = StaticDecode<T>, Result extends Static = Static>(schema: T, value: unknown): Result;
36
- /** `[Mutable]` Generates missing properties on a value using default schema annotations if available. This function does not check the value and returns an unknown type. You should Check the result before use. Default is a mutable operation. To avoid mutation, Clone the value first. */
37
- export declare function Default(schema: TSchema, references: TSchema[], value: unknown): unknown;
38
- /** `[Mutable]` Generates missing properties on a value using default schema annotations if available. This function does not check the value and returns an unknown type. You should Check the result before use. Default is a mutable operation. To avoid mutation, Clone the value first. */
39
- export declare function Default(schema: TSchema, value: unknown): unknown;
40
- /** Encodes a value or throws if error */
41
- export declare function Encode<T extends TSchema, Static = StaticEncode<T>, Result extends Static = Static>(schema: T, references: TSchema[], value: unknown): Result;
42
- /** Encodes a value or throws if error */
43
- export declare function Encode<T extends TSchema, Static = StaticEncode<T>, Result extends Static = Static>(schema: T, value: unknown): Result;
44
- /** Parses a value or throws an `AssertError` if invalid. */
45
- export declare function Parse<T extends TSchema, R = StaticDecode<T>>(schema: T, references: TSchema[], value: unknown): R;
46
- /** Parses a value or throws an `AssertError` if invalid. */
47
- export declare function Parse<T extends TSchema, R = StaticDecode<T>>(schema: T, value: unknown): R;
48
- /** Returns an iterator for each error in this value. */
49
- export declare function Errors<T extends TSchema>(schema: T, references: TSchema[], value: unknown): ValueErrorIterator;
50
- /** Returns an iterator for each error in this value. */
51
- export declare function Errors<T extends TSchema>(schema: T, value: unknown): ValueErrorIterator;
52
- /** Returns true if left and right values are structurally equal */
53
- export declare function Equal<T>(left: T, right: unknown): right is T;
54
- /** Returns edits to transform the current value into the next value */
55
- export declare function Diff(current: unknown, next: unknown): Edit[];
56
- /** Returns a FNV1A-64 non cryptographic hash of the given value */
57
- export declare function Hash(value: unknown): bigint;
58
- /** Returns a new value with edits applied to the given value */
59
- export declare function Patch<T = any>(current: unknown, edits: Edit[]): T;
60
- /** `[Mutable]` Performs a deep mutable value assignment while retaining internal references. */
61
- export declare function Mutate(current: Mutable, next: Mutable): void;
1
+ export { Errors, ValueErrorIterator } from '../../errors/index';
2
+ export { Assert } from '../assert/index';
3
+ export { Cast } from '../cast/index';
4
+ export { Check } from '../check/index';
5
+ export { Clean } from '../clean/index';
6
+ export { Clone } from '../clone/index';
7
+ export { Convert } from '../convert/index';
8
+ export { Create } from '../create/index';
9
+ export { Decode } from '../decode/index';
10
+ export { Default } from '../default/index';
11
+ export { Diff, Patch, Edit } from '../delta/index';
12
+ export { Encode } from '../encode/index';
13
+ export { Equal } from '../equal/index';
14
+ export { Hash } from '../hash/index';
15
+ export { Mutate, type Mutable } from '../mutate/index';
16
+ export { Parse } from '../parse/index';
@@ -1,110 +1,39 @@
1
1
  "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Assert = Assert;
5
- exports.Cast = Cast;
6
- exports.Create = Create;
7
- exports.Check = Check;
8
- exports.Clean = Clean;
9
- exports.Convert = Convert;
10
- exports.Clone = Clone;
11
- exports.Decode = Decode;
12
- exports.Default = Default;
13
- exports.Encode = Encode;
14
- exports.Parse = Parse;
15
- exports.Errors = Errors;
16
- exports.Equal = Equal;
17
- exports.Diff = Diff;
18
- exports.Hash = Hash;
19
- exports.Patch = Patch;
20
- exports.Mutate = Mutate;
21
- const index_1 = require("../transform/index");
22
- const index_2 = require("../assert/index");
23
- const index_3 = require("../mutate/index");
24
- const index_4 = require("../hash/index");
25
- const index_5 = require("../equal/index");
26
- const index_6 = require("../cast/index");
27
- const index_7 = require("../clone/index");
28
- const index_8 = require("../convert/index");
29
- const index_9 = require("../create/index");
30
- const index_10 = require("../clean/index");
31
- const index_11 = require("../check/index");
32
- const index_12 = require("../parse/index");
33
- const index_13 = require("../default/index");
34
- const index_14 = require("../delta/index");
35
- const index_15 = require("../../errors/index");
36
- /** Asserts a value matches the given type or throws an `AssertError` if invalid. */
37
- function Assert(...args) {
38
- return index_2.Assert.apply(index_2.Assert, args);
39
- }
40
- /** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
41
- function Cast(...args) {
42
- return index_6.Cast.apply(index_6.Cast, args);
43
- }
44
- /** Creates a value from the given type */
45
- function Create(...args) {
46
- return index_9.Create.apply(index_9.Create, args);
47
- }
48
- /** Returns true if the value matches the given type */
49
- function Check(...args) {
50
- return index_11.Check.apply(index_11.Check, args);
51
- }
52
- /** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
53
- function Clean(...args) {
54
- return index_10.Clean.apply(index_10.Clean, args);
55
- }
56
- /** `[Mutable]` Converts any type mismatched values to their target type if a reasonable conversion is possible. */
57
- function Convert(...args) {
58
- return index_8.Convert.apply(index_8.Convert, args);
59
- }
60
- /** Returns a structural clone of the given value */
61
- function Clone(value) {
62
- return (0, index_7.Clone)(value);
63
- }
64
- /** Decodes a value or throws if error */
65
- function Decode(...args) {
66
- const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
67
- if (!Check(schema, references, value))
68
- throw new index_1.TransformDecodeCheckError(schema, value, Errors(schema, references, value).First());
69
- return (0, index_1.HasTransform)(schema, references) ? (0, index_1.TransformDecode)(schema, references, value) : value;
70
- }
71
- /** `[Mutable]` Generates missing properties on a value using default schema annotations if available. This function does not check the value and returns an unknown type. You should Check the result before use. Default is a mutable operation. To avoid mutation, Clone the value first. */
72
- function Default(...args) {
73
- return index_13.Default.apply(index_13.Default, args);
74
- }
75
- /** Encodes a value or throws if error */
76
- function Encode(...args) {
77
- const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
78
- const encoded = (0, index_1.HasTransform)(schema, references) ? (0, index_1.TransformEncode)(schema, references, value) : value;
79
- if (!Check(schema, references, encoded))
80
- throw new index_1.TransformEncodeCheckError(schema, encoded, Errors(schema, references, encoded).First());
81
- return encoded;
82
- }
83
- /** Parses a value or throws an `AssertError` if invalid. */
84
- function Parse(...args) {
85
- return index_12.Parse.apply(index_12.Parse, args);
86
- }
87
- /** Returns an iterator for each error in this value. */
88
- function Errors(...args) {
89
- return index_15.Errors.apply(index_15.Errors, args);
90
- }
91
- /** Returns true if left and right values are structurally equal */
92
- function Equal(left, right) {
93
- return (0, index_5.Equal)(left, right);
94
- }
95
- /** Returns edits to transform the current value into the next value */
96
- function Diff(current, next) {
97
- return (0, index_14.Diff)(current, next);
98
- }
99
- /** Returns a FNV1A-64 non cryptographic hash of the given value */
100
- function Hash(value) {
101
- return (0, index_4.Hash)(value);
102
- }
103
- /** Returns a new value with edits applied to the given value */
104
- function Patch(current, edits) {
105
- return (0, index_14.Patch)(current, edits);
106
- }
107
- /** `[Mutable]` Performs a deep mutable value assignment while retaining internal references. */
108
- function Mutate(current, next) {
109
- (0, index_3.Mutate)(current, next);
110
- }
4
+ exports.Parse = exports.Mutate = exports.Hash = exports.Equal = exports.Encode = exports.Edit = exports.Patch = exports.Diff = exports.Default = exports.Decode = exports.Create = exports.Convert = exports.Clone = exports.Clean = exports.Check = exports.Cast = exports.Assert = exports.ValueErrorIterator = exports.Errors = void 0;
5
+ var index_1 = require("../../errors/index");
6
+ Object.defineProperty(exports, "Errors", { enumerable: true, get: function () { return index_1.Errors; } });
7
+ Object.defineProperty(exports, "ValueErrorIterator", { enumerable: true, get: function () { return index_1.ValueErrorIterator; } });
8
+ var index_2 = require("../assert/index");
9
+ Object.defineProperty(exports, "Assert", { enumerable: true, get: function () { return index_2.Assert; } });
10
+ var index_3 = require("../cast/index");
11
+ Object.defineProperty(exports, "Cast", { enumerable: true, get: function () { return index_3.Cast; } });
12
+ var index_4 = require("../check/index");
13
+ Object.defineProperty(exports, "Check", { enumerable: true, get: function () { return index_4.Check; } });
14
+ var index_5 = require("../clean/index");
15
+ Object.defineProperty(exports, "Clean", { enumerable: true, get: function () { return index_5.Clean; } });
16
+ var index_6 = require("../clone/index");
17
+ Object.defineProperty(exports, "Clone", { enumerable: true, get: function () { return index_6.Clone; } });
18
+ var index_7 = require("../convert/index");
19
+ Object.defineProperty(exports, "Convert", { enumerable: true, get: function () { return index_7.Convert; } });
20
+ var index_8 = require("../create/index");
21
+ Object.defineProperty(exports, "Create", { enumerable: true, get: function () { return index_8.Create; } });
22
+ var index_9 = require("../decode/index");
23
+ Object.defineProperty(exports, "Decode", { enumerable: true, get: function () { return index_9.Decode; } });
24
+ var index_10 = require("../default/index");
25
+ Object.defineProperty(exports, "Default", { enumerable: true, get: function () { return index_10.Default; } });
26
+ var index_11 = require("../delta/index");
27
+ Object.defineProperty(exports, "Diff", { enumerable: true, get: function () { return index_11.Diff; } });
28
+ Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return index_11.Patch; } });
29
+ Object.defineProperty(exports, "Edit", { enumerable: true, get: function () { return index_11.Edit; } });
30
+ var index_12 = require("../encode/index");
31
+ Object.defineProperty(exports, "Encode", { enumerable: true, get: function () { return index_12.Encode; } });
32
+ var index_13 = require("../equal/index");
33
+ Object.defineProperty(exports, "Equal", { enumerable: true, get: function () { return index_13.Equal; } });
34
+ var index_14 = require("../hash/index");
35
+ Object.defineProperty(exports, "Hash", { enumerable: true, get: function () { return index_14.Hash; } });
36
+ var index_15 = require("../mutate/index");
37
+ Object.defineProperty(exports, "Mutate", { enumerable: true, get: function () { return index_15.Mutate; } });
38
+ var index_16 = require("../parse/index");
39
+ Object.defineProperty(exports, "Parse", { enumerable: true, get: function () { return index_16.Parse; } });
@@ -40,5 +40,5 @@ export interface TObject<T extends TProperties = TProperties> extends TSchema, O
40
40
  /** `[Json]` Creates an Object type */
41
41
  declare function _Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
42
42
  /** `[Json]` Creates an Object type */
43
- export declare const Object: typeof _Object;
43
+ export declare var Object: typeof _Object;
44
44
  export {};
@@ -19,4 +19,4 @@ function _Object(properties, options) {
19
19
  return CreateType(schematic, options);
20
20
  }
21
21
  /** `[Json]` Creates an Object type */
22
- export const Object = _Object;
22
+ export var Object = _Object;
@@ -0,0 +1,6 @@
1
+ import type { TSchema } from '../../type/schema/index.mjs';
2
+ import type { StaticDecode } from '../../type/static/index.mjs';
3
+ /** Decodes a value or throws if error */
4
+ export declare function Decode<T extends TSchema, Static = StaticDecode<T>, Result extends Static = Static>(schema: T, references: TSchema[], value: unknown): Result;
5
+ /** Decodes a value or throws if error */
6
+ export declare function Decode<T extends TSchema, Static = StaticDecode<T>, Result extends Static = Static>(schema: T, value: unknown): Result;
@@ -0,0 +1,10 @@
1
+ import { HasTransform, TransformDecode, TransformDecodeCheckError } from '../transform/index.mjs';
2
+ import { Check } from '../check/index.mjs';
3
+ import { Errors } from '../../errors/index.mjs';
4
+ /** Decodes a value or throws if error */
5
+ export function Decode(...args) {
6
+ const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
7
+ if (!Check(schema, references, value))
8
+ throw new TransformDecodeCheckError(schema, value, Errors(schema, references, value).First());
9
+ return HasTransform(schema, references) ? TransformDecode(schema, references, value) : value;
10
+ }
@@ -0,0 +1 @@
1
+ export * from './decode.mjs';
@@ -0,0 +1 @@
1
+ export * from './decode.mjs';
@@ -0,0 +1,6 @@
1
+ import type { TSchema } from '../../type/schema/index.mjs';
2
+ import type { StaticEncode } from '../../type/static/index.mjs';
3
+ /** Encodes a value or throws if error */
4
+ export declare function Encode<T extends TSchema, Static = StaticEncode<T>, Result extends Static = Static>(schema: T, references: TSchema[], value: unknown): Result;
5
+ /** Encodes a value or throws if error */
6
+ export declare function Encode<T extends TSchema, Static = StaticEncode<T>, Result extends Static = Static>(schema: T, value: unknown): Result;
@@ -0,0 +1,11 @@
1
+ import { HasTransform, TransformEncode, TransformEncodeCheckError } from '../transform/index.mjs';
2
+ import { Check } from '../check/index.mjs';
3
+ import { Errors } from '../../errors/index.mjs';
4
+ /** Encodes a value or throws if error */
5
+ export function Encode(...args) {
6
+ const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
7
+ const encoded = HasTransform(schema, references) ? TransformEncode(schema, references, value) : value;
8
+ if (!Check(schema, references, encoded))
9
+ throw new TransformEncodeCheckError(schema, encoded, Errors(schema, references, encoded).First());
10
+ return encoded;
11
+ }
@@ -0,0 +1 @@
1
+ export * from './encode.mjs';
@@ -0,0 +1 @@
1
+ export * from './encode.mjs';
@@ -7,8 +7,10 @@ export * from './clean/index.mjs';
7
7
  export * from './clone/index.mjs';
8
8
  export * from './convert/index.mjs';
9
9
  export * from './create/index.mjs';
10
+ export * from './decode/index.mjs';
10
11
  export * from './default/index.mjs';
11
12
  export * from './delta/index.mjs';
13
+ export * from './encode/index.mjs';
12
14
  export * from './equal/index.mjs';
13
15
  export * from './hash/index.mjs';
14
16
  export * from './mutate/index.mjs';
@@ -16,8 +16,10 @@ export * from './clean/index.mjs';
16
16
  export * from './clone/index.mjs';
17
17
  export * from './convert/index.mjs';
18
18
  export * from './create/index.mjs';
19
+ export * from './decode/index.mjs';
19
20
  export * from './default/index.mjs';
20
21
  export * from './delta/index.mjs';
22
+ export * from './encode/index.mjs';
21
23
  export * from './equal/index.mjs';
22
24
  export * from './hash/index.mjs';
23
25
  export * from './mutate/index.mjs';
@@ -1,61 +1,16 @@
1
- import { type Mutable } from '../mutate/index.mjs';
2
- import { Edit } from '../delta/index.mjs';
3
- import { ValueErrorIterator } from '../../errors/index.mjs';
4
- import type { TSchema } from '../../type/schema/index.mjs';
5
- import type { Static, StaticDecode, StaticEncode } from '../../type/static/index.mjs';
6
- /** Asserts a value matches the given type or throws an `AssertError` if invalid. */
7
- export declare function Assert<T extends TSchema, R = Static<T>>(schema: T, references: TSchema[], value: unknown): asserts value is R;
8
- /** Asserts a value matches the given type or throws an `AssertError` if invalid. */
9
- export declare function Assert<T extends TSchema, R = Static<T>>(schema: T, value: unknown): asserts value is R;
10
- /** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
11
- export declare function Cast<T extends TSchema>(schema: T, references: TSchema[], value: unknown): Static<T>;
12
- /** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
13
- export declare function Cast<T extends TSchema>(schema: T, value: unknown): Static<T>;
14
- /** Creates a value from the given type and references */
15
- export declare function Create<T extends TSchema>(schema: T, references: TSchema[]): Static<T>;
16
- /** Creates a value from the given type */
17
- export declare function Create<T extends TSchema>(schema: T): Static<T>;
18
- /** Returns true if the value matches the given type and references */
19
- export declare function Check<T extends TSchema>(schema: T, references: TSchema[], value: unknown): value is Static<T>;
20
- /** Returns true if the value matches the given type */
21
- export declare function Check<T extends TSchema>(schema: T, value: unknown): value is Static<T>;
22
- /** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
23
- export declare function Clean(schema: TSchema, references: TSchema[], value: unknown): unknown;
24
- /** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
25
- export declare function Clean(schema: TSchema, value: unknown): unknown;
26
- /** `[Mutable]` Converts any type mismatched values to their target type if a reasonable conversion is possible. */
27
- export declare function Convert(schema: TSchema, references: TSchema[], value: unknown): unknown;
28
- /** `[Mutable]` Converts any type mismatched values to their target type if a reasonable conversion is possible. */
29
- export declare function Convert(schema: TSchema, value: unknown): unknown;
30
- /** Returns a structural clone of the given value */
31
- export declare function Clone<T>(value: T): T;
32
- /** Decodes a value or throws if error */
33
- export declare function Decode<T extends TSchema, Static = StaticDecode<T>, Result extends Static = Static>(schema: T, references: TSchema[], value: unknown): Result;
34
- /** Decodes a value or throws if error */
35
- export declare function Decode<T extends TSchema, Static = StaticDecode<T>, Result extends Static = Static>(schema: T, value: unknown): Result;
36
- /** `[Mutable]` Generates missing properties on a value using default schema annotations if available. This function does not check the value and returns an unknown type. You should Check the result before use. Default is a mutable operation. To avoid mutation, Clone the value first. */
37
- export declare function Default(schema: TSchema, references: TSchema[], value: unknown): unknown;
38
- /** `[Mutable]` Generates missing properties on a value using default schema annotations if available. This function does not check the value and returns an unknown type. You should Check the result before use. Default is a mutable operation. To avoid mutation, Clone the value first. */
39
- export declare function Default(schema: TSchema, value: unknown): unknown;
40
- /** Encodes a value or throws if error */
41
- export declare function Encode<T extends TSchema, Static = StaticEncode<T>, Result extends Static = Static>(schema: T, references: TSchema[], value: unknown): Result;
42
- /** Encodes a value or throws if error */
43
- export declare function Encode<T extends TSchema, Static = StaticEncode<T>, Result extends Static = Static>(schema: T, value: unknown): Result;
44
- /** Parses a value or throws an `AssertError` if invalid. */
45
- export declare function Parse<T extends TSchema, R = StaticDecode<T>>(schema: T, references: TSchema[], value: unknown): R;
46
- /** Parses a value or throws an `AssertError` if invalid. */
47
- export declare function Parse<T extends TSchema, R = StaticDecode<T>>(schema: T, value: unknown): R;
48
- /** Returns an iterator for each error in this value. */
49
- export declare function Errors<T extends TSchema>(schema: T, references: TSchema[], value: unknown): ValueErrorIterator;
50
- /** Returns an iterator for each error in this value. */
51
- export declare function Errors<T extends TSchema>(schema: T, value: unknown): ValueErrorIterator;
52
- /** Returns true if left and right values are structurally equal */
53
- export declare function Equal<T>(left: T, right: unknown): right is T;
54
- /** Returns edits to transform the current value into the next value */
55
- export declare function Diff(current: unknown, next: unknown): Edit[];
56
- /** Returns a FNV1A-64 non cryptographic hash of the given value */
57
- export declare function Hash(value: unknown): bigint;
58
- /** Returns a new value with edits applied to the given value */
59
- export declare function Patch<T = any>(current: unknown, edits: Edit[]): T;
60
- /** `[Mutable]` Performs a deep mutable value assignment while retaining internal references. */
61
- export declare function Mutate(current: Mutable, next: Mutable): void;
1
+ export { Errors, ValueErrorIterator } from '../../errors/index.mjs';
2
+ export { Assert } from '../assert/index.mjs';
3
+ export { Cast } from '../cast/index.mjs';
4
+ export { Check } from '../check/index.mjs';
5
+ export { Clean } from '../clean/index.mjs';
6
+ export { Clone } from '../clone/index.mjs';
7
+ export { Convert } from '../convert/index.mjs';
8
+ export { Create } from '../create/index.mjs';
9
+ export { Decode } from '../decode/index.mjs';
10
+ export { Default } from '../default/index.mjs';
11
+ export { Diff, Patch, Edit } from '../delta/index.mjs';
12
+ export { Encode } from '../encode/index.mjs';
13
+ export { Equal } from '../equal/index.mjs';
14
+ export { Hash } from '../hash/index.mjs';
15
+ export { Mutate, type Mutable } from '../mutate/index.mjs';
16
+ export { Parse } from '../parse/index.mjs';
@@ -1,90 +1,16 @@
1
- import { HasTransform, TransformDecode, TransformEncode, TransformDecodeCheckError, TransformEncodeCheckError } from '../transform/index.mjs';
2
- import { Assert as AssertValue } from '../assert/index.mjs';
3
- import { Mutate as MutateValue } from '../mutate/index.mjs';
4
- import { Hash as HashValue } from '../hash/index.mjs';
5
- import { Equal as EqualValue } from '../equal/index.mjs';
6
- import { Cast as CastValue } from '../cast/index.mjs';
7
- import { Clone as CloneValue } from '../clone/index.mjs';
8
- import { Convert as ConvertValue } from '../convert/index.mjs';
9
- import { Create as CreateValue } from '../create/index.mjs';
10
- import { Clean as CleanValue } from '../clean/index.mjs';
11
- import { Check as CheckValue } from '../check/index.mjs';
12
- import { Parse as ParseValue } from '../parse/index.mjs';
13
- import { Default as DefaultValue } from '../default/index.mjs';
14
- import { Diff as DiffValue, Patch as PatchValue } from '../delta/index.mjs';
15
- import { Errors as ValueErrors } from '../../errors/index.mjs';
16
- /** Asserts a value matches the given type or throws an `AssertError` if invalid. */
17
- export function Assert(...args) {
18
- return AssertValue.apply(AssertValue, args);
19
- }
20
- /** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
21
- export function Cast(...args) {
22
- return CastValue.apply(CastValue, args);
23
- }
24
- /** Creates a value from the given type */
25
- export function Create(...args) {
26
- return CreateValue.apply(CreateValue, args);
27
- }
28
- /** Returns true if the value matches the given type */
29
- export function Check(...args) {
30
- return CheckValue.apply(CheckValue, args);
31
- }
32
- /** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
33
- export function Clean(...args) {
34
- return CleanValue.apply(CleanValue, args);
35
- }
36
- /** `[Mutable]` Converts any type mismatched values to their target type if a reasonable conversion is possible. */
37
- export function Convert(...args) {
38
- return ConvertValue.apply(ConvertValue, args);
39
- }
40
- /** Returns a structural clone of the given value */
41
- export function Clone(value) {
42
- return CloneValue(value);
43
- }
44
- /** Decodes a value or throws if error */
45
- export function Decode(...args) {
46
- const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
47
- if (!Check(schema, references, value))
48
- throw new TransformDecodeCheckError(schema, value, Errors(schema, references, value).First());
49
- return HasTransform(schema, references) ? TransformDecode(schema, references, value) : value;
50
- }
51
- /** `[Mutable]` Generates missing properties on a value using default schema annotations if available. This function does not check the value and returns an unknown type. You should Check the result before use. Default is a mutable operation. To avoid mutation, Clone the value first. */
52
- export function Default(...args) {
53
- return DefaultValue.apply(DefaultValue, args);
54
- }
55
- /** Encodes a value or throws if error */
56
- export function Encode(...args) {
57
- const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
58
- const encoded = HasTransform(schema, references) ? TransformEncode(schema, references, value) : value;
59
- if (!Check(schema, references, encoded))
60
- throw new TransformEncodeCheckError(schema, encoded, Errors(schema, references, encoded).First());
61
- return encoded;
62
- }
63
- /** Parses a value or throws an `AssertError` if invalid. */
64
- export function Parse(...args) {
65
- return ParseValue.apply(ParseValue, args);
66
- }
67
- /** Returns an iterator for each error in this value. */
68
- export function Errors(...args) {
69
- return ValueErrors.apply(ValueErrors, args);
70
- }
71
- /** Returns true if left and right values are structurally equal */
72
- export function Equal(left, right) {
73
- return EqualValue(left, right);
74
- }
75
- /** Returns edits to transform the current value into the next value */
76
- export function Diff(current, next) {
77
- return DiffValue(current, next);
78
- }
79
- /** Returns a FNV1A-64 non cryptographic hash of the given value */
80
- export function Hash(value) {
81
- return HashValue(value);
82
- }
83
- /** Returns a new value with edits applied to the given value */
84
- export function Patch(current, edits) {
85
- return PatchValue(current, edits);
86
- }
87
- /** `[Mutable]` Performs a deep mutable value assignment while retaining internal references. */
88
- export function Mutate(current, next) {
89
- MutateValue(current, next);
90
- }
1
+ export { Errors, ValueErrorIterator } from '../../errors/index.mjs';
2
+ export { Assert } from '../assert/index.mjs';
3
+ export { Cast } from '../cast/index.mjs';
4
+ export { Check } from '../check/index.mjs';
5
+ export { Clean } from '../clean/index.mjs';
6
+ export { Clone } from '../clone/index.mjs';
7
+ export { Convert } from '../convert/index.mjs';
8
+ export { Create } from '../create/index.mjs';
9
+ export { Decode } from '../decode/index.mjs';
10
+ export { Default } from '../default/index.mjs';
11
+ export { Diff, Patch, Edit } from '../delta/index.mjs';
12
+ export { Encode } from '../encode/index.mjs';
13
+ export { Equal } from '../equal/index.mjs';
14
+ export { Hash } from '../hash/index.mjs';
15
+ export { Mutate } from '../mutate/index.mjs';
16
+ export { Parse } from '../parse/index.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.33.17",
3
+ "version": "0.33.18",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/readme.md CHANGED
@@ -1646,6 +1646,7 @@ The following is a list of community packages that offer general tooling, extend
1646
1646
  | [fetch-typebox](https://github.com/erfanium/fetch-typebox) | Drop-in replacement for fetch that brings easy integration with TypeBox |
1647
1647
  | [h3-typebox](https://github.com/kevinmarrec/h3-typebox) | Schema validation utilities for h3 using TypeBox & Ajv |
1648
1648
  | [http-wizard](https://github.com/flodlc/http-wizard) | Type safe http client library for Fastify |
1649
+ | [json2typebox](https://github.com/hacxy/json2typebox) | Creating TypeBox code from Json Data |
1649
1650
  | [nominal-typebox](https://github.com/Coder-Spirit/nominal/tree/main/%40coderspirit/nominal-typebox) | Allows devs to integrate nominal types into TypeBox schemas |
1650
1651
  | [openapi-box](https://github.com/geut/openapi-box) | Generate TypeBox types from OpenApi IDL + Http client library |
1651
1652
  | [prismabox](https://github.com/m1212e/prismabox) | Converts a prisma.schema to typebox schema matching the database models |