typebox 1.0.11 → 1.0.13
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/build/schema/index.d.mts +3 -16
- package/build/schema/index.mjs +3 -13
- package/build/value/assert/assert.d.mts +1 -1
- package/build/value/clean/from-union.mjs +1 -1
- package/build/value/codec/decode.d.mts +2 -0
- package/build/value/codec/decode.mjs +8 -1
- package/build/value/codec/encode.d.mts +2 -0
- package/build/value/codec/encode.mjs +8 -1
- package/package.json +34 -24
package/build/schema/index.d.mts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
export *
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export * from './build.mjs';
|
|
5
|
-
export * from './check.mjs';
|
|
6
|
-
export * from './errors.mjs';
|
|
7
|
-
import { Build, BuildResult } from './build.mjs';
|
|
8
|
-
import { Check } from './check.mjs';
|
|
9
|
-
import { Errors } from './errors.mjs';
|
|
10
|
-
declare const _default: {
|
|
11
|
-
Build: typeof Build;
|
|
12
|
-
BuildResult: typeof BuildResult;
|
|
13
|
-
Check: typeof Check;
|
|
14
|
-
Errors: typeof Errors;
|
|
15
|
-
};
|
|
16
|
-
export default _default;
|
|
1
|
+
export * from './schema.mjs';
|
|
2
|
+
import * as Schema from './schema.mjs';
|
|
3
|
+
export default Schema;
|
package/build/schema/index.mjs
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
// ------------------------------------------------------------------
|
|
2
|
-
// Named
|
|
3
|
-
// ------------------------------------------------------------------
|
|
4
|
-
export * as Schema from './schema.mjs';
|
|
5
|
-
// ------------------------------------------------------------------
|
|
6
2
|
// Barrel
|
|
7
3
|
// ------------------------------------------------------------------
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './types/index.mjs';
|
|
10
|
-
export * from './build.mjs';
|
|
11
|
-
export * from './check.mjs';
|
|
12
|
-
export * from './errors.mjs';
|
|
4
|
+
export * from './schema.mjs';
|
|
13
5
|
// ------------------------------------------------------------------
|
|
14
6
|
// Default
|
|
15
7
|
// ------------------------------------------------------------------
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
import { Errors } from './errors.mjs';
|
|
19
|
-
export default { Build, BuildResult, Check, Errors };
|
|
8
|
+
import * as Schema from './schema.mjs';
|
|
9
|
+
export default Schema;
|
|
@@ -5,4 +5,4 @@ export declare class AssertError extends Error {
|
|
|
5
5
|
/** Asserts the a value matches the given type. This function returns a TypeScript type asserts predicate and will throw AssertError if value does not match. */
|
|
6
6
|
export declare function Assert<Context extends TProperties, const Type extends TSchema, Result extends unknown = Static<Type, Context>>(context: Context, type: Type, value: unknown): asserts value is Result;
|
|
7
7
|
/** Asserts the a value matches the given type. This function returns a TypeScript type asserts predicate and will throw AssertError if value does not match. */
|
|
8
|
-
export declare function Assert<const Type extends TSchema, Result extends unknown = Static<Type>>(type:
|
|
8
|
+
export declare function Assert<const Type extends TSchema, Result extends unknown = Static<Type>>(type: Type, value: unknown): asserts value is Result;
|
|
@@ -5,7 +5,7 @@ import { FromType } from './from-type.mjs';
|
|
|
5
5
|
export function FromUnion(context, type, value) {
|
|
6
6
|
for (const schema of type.anyOf) {
|
|
7
7
|
const clean = FromType(context, schema, Clone(value));
|
|
8
|
-
if (Check(context,
|
|
8
|
+
if (Check(context, schema, clean))
|
|
9
9
|
return clean;
|
|
10
10
|
}
|
|
11
11
|
return value;
|
|
@@ -3,6 +3,8 @@ import { AssertError } from '../assert/index.mjs';
|
|
|
3
3
|
export declare class DecodeError extends AssertError {
|
|
4
4
|
constructor(value: unknown, errors: object[]);
|
|
5
5
|
}
|
|
6
|
+
/** Executes Decode callbacks only */
|
|
7
|
+
export declare function DecodeUnsafe(context: TProperties, type: TSchema, value: unknown): unknown;
|
|
6
8
|
/**
|
|
7
9
|
* Decodes a value against the given type by applying a sequence of Clone,
|
|
8
10
|
* Default, Convert, and Clone operations, then executing any embedded Decode
|
|
@@ -23,6 +23,13 @@ function Assert(context, type, value) {
|
|
|
23
23
|
return value;
|
|
24
24
|
}
|
|
25
25
|
// ------------------------------------------------------------------
|
|
26
|
+
// DecodeUnsafe
|
|
27
|
+
// ------------------------------------------------------------------
|
|
28
|
+
/** Executes Decode callbacks only */
|
|
29
|
+
export function DecodeUnsafe(context, type, value) {
|
|
30
|
+
return FromType('Decode', context, type, value);
|
|
31
|
+
}
|
|
32
|
+
// ------------------------------------------------------------------
|
|
26
33
|
// Decoder
|
|
27
34
|
// ------------------------------------------------------------------
|
|
28
35
|
const Decoder = Pipeline([
|
|
@@ -31,7 +38,7 @@ const Decoder = Pipeline([
|
|
|
31
38
|
(context, type, value) => Convert(context, type, value),
|
|
32
39
|
(context, type, value) => Clean(context, type, value),
|
|
33
40
|
(context, type, value) => Assert(context, type, value),
|
|
34
|
-
(context, type, value) =>
|
|
41
|
+
(context, type, value) => DecodeUnsafe(context, type, value)
|
|
35
42
|
]);
|
|
36
43
|
/**
|
|
37
44
|
* Decodes a value against the given type by applying a sequence of Clone,
|
|
@@ -3,6 +3,8 @@ import { AssertError } from '../assert/index.mjs';
|
|
|
3
3
|
export declare class EncodeError extends AssertError {
|
|
4
4
|
constructor(value: unknown, errors: object[]);
|
|
5
5
|
}
|
|
6
|
+
/** Executes Encode callbacks only */
|
|
7
|
+
export declare function EncodeUnsafe(context: TProperties, type: TSchema, value: unknown): unknown;
|
|
6
8
|
/** Encodes a value. */
|
|
7
9
|
export declare function Encode<const Type extends TSchema, Result extends unknown = StaticEncode<Type>>(type: Type, value: unknown): Result;
|
|
8
10
|
/** Encodes a value. */
|
|
@@ -23,11 +23,18 @@ function Assert(context, type, value) {
|
|
|
23
23
|
return value;
|
|
24
24
|
}
|
|
25
25
|
// ------------------------------------------------------------------
|
|
26
|
+
// EncodeUnsafe
|
|
27
|
+
// ------------------------------------------------------------------
|
|
28
|
+
/** Executes Encode callbacks only */
|
|
29
|
+
export function EncodeUnsafe(context, type, value) {
|
|
30
|
+
return FromType('Encode', context, type, value);
|
|
31
|
+
}
|
|
32
|
+
// ------------------------------------------------------------------
|
|
26
33
|
// Encoder
|
|
27
34
|
// ------------------------------------------------------------------
|
|
28
35
|
const Encoder = Pipeline([
|
|
29
36
|
(_context, _type, value) => Clone(value),
|
|
30
|
-
(context, type, value) =>
|
|
37
|
+
(context, type, value) => EncodeUnsafe(context, type, value),
|
|
31
38
|
(context, type, value) => Default(context, type, value),
|
|
32
39
|
(context, type, value) => Convert(context, type, value),
|
|
33
40
|
(context, type, value) => Clean(context, type, value),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typebox",
|
|
3
3
|
"description": "A Runtime Type System for JavaScript",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.13",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
7
7
|
"jsonschema"
|
|
@@ -12,50 +12,63 @@
|
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "https://github.com/sinclairzx81/typebox"
|
|
14
14
|
},
|
|
15
|
+
"type": "module",
|
|
15
16
|
"types": "./build/index.d.mts",
|
|
16
17
|
"module": "./build/index.mjs",
|
|
17
18
|
"exports": {
|
|
18
|
-
"./
|
|
19
|
-
"import": "./build/
|
|
19
|
+
"./guard": {
|
|
20
|
+
"import": "./build/guard/index.mjs",
|
|
21
|
+
"default": "./build/guard/index.mjs"
|
|
20
22
|
},
|
|
21
23
|
"./value": {
|
|
22
|
-
"import": "./build/value/index.mjs"
|
|
24
|
+
"import": "./build/value/index.mjs",
|
|
25
|
+
"default": "./build/value/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./type": {
|
|
28
|
+
"import": "./build/type/index.mjs",
|
|
29
|
+
"default": "./build/type/index.mjs"
|
|
23
30
|
},
|
|
24
31
|
"./system": {
|
|
25
|
-
"import": "./build/system/index.mjs"
|
|
32
|
+
"import": "./build/system/index.mjs",
|
|
33
|
+
"default": "./build/system/index.mjs"
|
|
26
34
|
},
|
|
27
|
-
"./
|
|
28
|
-
"import": "./build/
|
|
35
|
+
"./error": {
|
|
36
|
+
"import": "./build/error/index.mjs",
|
|
37
|
+
"default": "./build/error/index.mjs"
|
|
29
38
|
},
|
|
30
39
|
"./schema": {
|
|
31
|
-
"import": "./build/schema/index.mjs"
|
|
40
|
+
"import": "./build/schema/index.mjs",
|
|
41
|
+
"default": "./build/schema/index.mjs"
|
|
32
42
|
},
|
|
33
43
|
"./compile": {
|
|
34
|
-
"import": "./build/compile/index.mjs"
|
|
35
|
-
|
|
36
|
-
"./guard": {
|
|
37
|
-
"import": "./build/guard/index.mjs"
|
|
44
|
+
"import": "./build/compile/index.mjs",
|
|
45
|
+
"default": "./build/compile/index.mjs"
|
|
38
46
|
},
|
|
39
|
-
"./
|
|
40
|
-
"import": "./build/
|
|
47
|
+
"./format": {
|
|
48
|
+
"import": "./build/format/index.mjs",
|
|
49
|
+
"default": "./build/format/index.mjs"
|
|
41
50
|
},
|
|
42
51
|
".": {
|
|
43
|
-
"import": "./build/index.mjs"
|
|
52
|
+
"import": "./build/index.mjs",
|
|
53
|
+
"default": "./build/index.mjs"
|
|
44
54
|
}
|
|
45
55
|
},
|
|
46
56
|
"typesVersions": {
|
|
47
57
|
"*": {
|
|
48
|
-
"
|
|
49
|
-
"./build/
|
|
58
|
+
"guard": [
|
|
59
|
+
"./build/guard/index.d.mts"
|
|
50
60
|
],
|
|
51
61
|
"value": [
|
|
52
62
|
"./build/value/index.d.mts"
|
|
53
63
|
],
|
|
64
|
+
"type": [
|
|
65
|
+
"./build/type/index.d.mts"
|
|
66
|
+
],
|
|
54
67
|
"system": [
|
|
55
68
|
"./build/system/index.d.mts"
|
|
56
69
|
],
|
|
57
|
-
"
|
|
58
|
-
"./build/
|
|
70
|
+
"error": [
|
|
71
|
+
"./build/error/index.d.mts"
|
|
59
72
|
],
|
|
60
73
|
"schema": [
|
|
61
74
|
"./build/schema/index.d.mts"
|
|
@@ -63,11 +76,8 @@
|
|
|
63
76
|
"compile": [
|
|
64
77
|
"./build/compile/index.d.mts"
|
|
65
78
|
],
|
|
66
|
-
"
|
|
67
|
-
"./build/
|
|
68
|
-
],
|
|
69
|
-
"error": [
|
|
70
|
-
"./build/error/index.d.mts"
|
|
79
|
+
"format": [
|
|
80
|
+
"./build/format/index.d.mts"
|
|
71
81
|
],
|
|
72
82
|
".": [
|
|
73
83
|
"./build/./index.d.mts"
|