@sinclair/typebox 0.32.0-dev-10 → 0.32.0-dev-12
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/import/compiler/compiler.mjs +4 -4
- package/build/import/errors/errors.mjs +3 -3
- package/build/import/index.d.mts +3 -3
- package/build/import/index.mjs +2 -2
- package/build/import/type/composite/composite.d.mts +2 -2
- package/build/import/type/composite/composite.mjs +2 -2
- package/build/import/type/extends/extends-mapped-result.d.mts +13 -0
- package/build/import/type/extends/extends-mapped-result.mjs +14 -0
- package/build/import/type/extends/extends-mapped.d.mts +17 -0
- package/build/import/type/extends/extends-mapped.mjs +21 -0
- package/build/import/type/extends/extends.d.mts +8 -2
- package/build/import/type/extends/extends.mjs +7 -3
- package/build/import/type/extends/index.d.mts +2 -0
- package/build/import/type/extends/index.mjs +2 -0
- package/build/import/type/guard/type.d.mts +5 -1
- package/build/import/type/guard/type.mjs +18 -2
- package/build/import/type/indexed/index.d.mts +2 -1
- package/build/import/type/indexed/index.mjs +2 -1
- package/build/import/type/indexed/indexed-mapped.d.mts +16 -0
- package/build/import/type/indexed/indexed-mapped.mjs +18 -0
- package/build/import/type/indexed/{indexed-key.d.mts → indexed-property-keys.d.mts} +3 -3
- package/build/import/type/indexed/{indexed-key.mjs → indexed-property-keys.mjs} +2 -2
- package/build/import/type/indexed/indexed-type.d.mts +2 -2
- package/build/import/type/indexed/indexed-type.mjs +1 -1
- package/build/import/type/indexed/indexed.d.mts +7 -4
- package/build/import/type/indexed/indexed.mjs +7 -6
- package/build/import/type/keyof/index.d.mts +1 -2
- package/build/import/type/keyof/index.mjs +1 -2
- package/build/import/type/keyof/{keyof-string.d.mts → keyof-property-keys.d.mts} +4 -4
- package/build/import/type/keyof/{keyof-string.mjs → keyof-property-keys.mjs} +4 -4
- package/build/import/type/keyof/keyof.d.mts +12 -4
- package/build/import/type/keyof/keyof.mjs +14 -3
- package/build/import/type/mapped/mapped.d.mts +41 -15
- package/build/import/type/mapped/mapped.mjs +75 -11
- package/build/import/type/omit/omit.d.mts +2 -2
- package/build/import/type/omit/omit.mjs +2 -2
- package/build/import/type/pick/pick.d.mts +2 -2
- package/build/import/type/pick/pick.mjs +2 -2
- package/build/import/type/record/record.mjs +3 -3
- package/build/import/type/tuple/tuple.d.mts +3 -1
- package/build/import/type/type/json.d.mts +13 -6
- package/build/import/type/type/json.mjs +6 -2
- package/build/import/value/check/check.mjs +3 -3
- package/build/import/value/clean/clean.mjs +2 -2
- package/build/import/value/index.d.mts +1 -1
- package/build/import/value/index.mjs +1 -1
- package/build/import/value/transform/decode.d.mts +1 -1
- package/build/import/value/transform/decode.mjs +6 -6
- package/build/import/value/transform/encode.d.mts +1 -1
- package/build/import/value/transform/encode.mjs +6 -6
- package/build/import/value/value/value.mjs +3 -3
- package/build/require/compiler/compiler.js +4 -4
- package/build/require/errors/errors.js +2 -2
- package/build/require/index.d.ts +3 -3
- package/build/require/index.js +7 -7
- package/build/require/type/composite/composite.d.ts +2 -2
- package/build/require/type/composite/composite.js +1 -1
- package/build/require/type/extends/extends-mapped-result.d.ts +13 -0
- package/build/require/type/extends/extends-mapped-result.js +18 -0
- package/build/require/type/extends/extends-mapped.d.ts +17 -0
- package/build/require/type/extends/extends-mapped.js +25 -0
- package/build/require/type/extends/extends.d.ts +8 -2
- package/build/require/type/extends/extends.js +8 -5
- package/build/require/type/extends/index.d.ts +2 -0
- package/build/require/type/extends/index.js +2 -0
- package/build/require/type/guard/type.d.ts +5 -1
- package/build/require/type/guard/type.js +53 -34
- package/build/require/type/indexed/index.d.ts +2 -1
- package/build/require/type/indexed/index.js +2 -1
- package/build/require/type/indexed/indexed-mapped.d.ts +16 -0
- package/build/require/type/indexed/indexed-mapped.js +22 -0
- package/build/require/type/indexed/{indexed-key.d.ts → indexed-property-keys.d.ts} +3 -3
- package/build/require/type/indexed/{indexed-key.js → indexed-property-keys.js} +4 -4
- package/build/require/type/indexed/indexed-type.d.ts +2 -2
- package/build/require/type/indexed/indexed-type.js +3 -3
- package/build/require/type/indexed/indexed.d.ts +7 -4
- package/build/require/type/indexed/indexed.js +7 -6
- package/build/require/type/keyof/index.d.ts +1 -2
- package/build/require/type/keyof/index.js +1 -2
- package/build/require/type/keyof/{keyof-string.d.ts → keyof-property-keys.d.ts} +4 -4
- package/build/require/type/keyof/{keyof-string.js → keyof-property-keys.js} +7 -7
- package/build/require/type/keyof/keyof.d.ts +12 -4
- package/build/require/type/keyof/keyof.js +14 -3
- package/build/require/type/mapped/mapped.d.ts +41 -15
- package/build/require/type/mapped/mapped.js +80 -12
- package/build/require/type/omit/omit.d.ts +2 -2
- package/build/require/type/omit/omit.js +1 -1
- package/build/require/type/pick/pick.d.ts +2 -2
- package/build/require/type/pick/pick.js +1 -1
- package/build/require/type/record/record.js +2 -2
- package/build/require/type/tuple/tuple.d.ts +3 -1
- package/build/require/type/type/json.d.ts +13 -6
- package/build/require/type/type/json.js +54 -50
- package/build/require/value/check/check.js +2 -2
- package/build/require/value/clean/clean.js +15 -15
- package/build/require/value/index.d.ts +1 -1
- package/build/require/value/index.js +3 -3
- package/build/require/value/transform/decode.d.ts +1 -1
- package/build/require/value/transform/decode.js +6 -6
- package/build/require/value/transform/encode.d.ts +1 -1
- package/build/require/value/transform/encode.js +6 -6
- package/build/require/value/value/value.js +2 -2
- package/package.json +4 -1
- package/build/import/type/keyof/keyof-type.d.mts +0 -11
- package/build/import/type/keyof/keyof-type.mjs +0 -15
- package/build/require/type/keyof/keyof-type.d.ts +0 -11
- package/build/require/type/keyof/keyof-type.js +0 -19
|
@@ -3,16 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Clean = void 0;
|
|
4
4
|
const index_1 = require("../guard/index");
|
|
5
5
|
const type_1 = require("../../type/guard/type");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
6
|
+
const index_2 = require("../../type/keyof/index");
|
|
7
|
+
const index_3 = require("../check/index");
|
|
8
|
+
const index_4 = require("../clone/index");
|
|
9
|
+
const index_5 = require("../deref/index");
|
|
10
|
+
const index_6 = require("../../type/symbols/index");
|
|
11
11
|
function IsSchema(schema) {
|
|
12
12
|
return (0, type_1.TSchema)(schema);
|
|
13
13
|
}
|
|
14
14
|
function IsCheckable(schema) {
|
|
15
|
-
return (0, type_1.TSchema)(schema) && schema[
|
|
15
|
+
return (0, type_1.TSchema)(schema) && schema[index_6.Kind] !== 'Unsafe';
|
|
16
16
|
}
|
|
17
17
|
function TArray(schema, references, value) {
|
|
18
18
|
if (!(0, index_1.IsArray)(value))
|
|
@@ -21,15 +21,15 @@ function TArray(schema, references, value) {
|
|
|
21
21
|
}
|
|
22
22
|
function TIntersect(schema, references, value) {
|
|
23
23
|
const unevaluatedProperties = schema.unevaluatedProperties;
|
|
24
|
-
const intersections = schema.allOf.map((schema) => Visit(schema, references, (0,
|
|
24
|
+
const intersections = schema.allOf.map((schema) => Visit(schema, references, (0, index_4.Clone)(value)));
|
|
25
25
|
const composite = intersections.reduce((acc, value) => ((0, index_1.IsObject)(value) ? { ...acc, ...value } : value), {});
|
|
26
26
|
if (!(0, index_1.IsObject)(value) || !(0, index_1.IsObject)(composite) || !IsSchema(unevaluatedProperties))
|
|
27
27
|
return composite;
|
|
28
|
-
const knownkeys = (0,
|
|
28
|
+
const knownkeys = (0, index_2.KeyOfPropertyKeys)(schema);
|
|
29
29
|
for (const key of Object.getOwnPropertyNames(value)) {
|
|
30
30
|
if (knownkeys.includes(key))
|
|
31
31
|
continue;
|
|
32
|
-
if ((0,
|
|
32
|
+
if ((0, index_3.Check)(unevaluatedProperties, references, value[key])) {
|
|
33
33
|
composite[key] = Visit(unevaluatedProperties, references, value[key]);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -44,7 +44,7 @@ function TObject(schema, references, value) {
|
|
|
44
44
|
value[key] = Visit(schema.properties[key], references, value[key]);
|
|
45
45
|
continue;
|
|
46
46
|
}
|
|
47
|
-
if (IsSchema(additionalProperties) && (0,
|
|
47
|
+
if (IsSchema(additionalProperties) && (0, index_3.Check)(additionalProperties, references, value[key])) {
|
|
48
48
|
value[key] = Visit(additionalProperties, references, value[key]);
|
|
49
49
|
continue;
|
|
50
50
|
}
|
|
@@ -64,7 +64,7 @@ function TRecord(schema, references, value) {
|
|
|
64
64
|
value[key] = Visit(propertySchema, references, value[key]);
|
|
65
65
|
continue;
|
|
66
66
|
}
|
|
67
|
-
if (IsSchema(additionalProperties) && (0,
|
|
67
|
+
if (IsSchema(additionalProperties) && (0, index_3.Check)(additionalProperties, references, value[key])) {
|
|
68
68
|
value[key] = Visit(additionalProperties, references, value[key]);
|
|
69
69
|
continue;
|
|
70
70
|
}
|
|
@@ -73,10 +73,10 @@ function TRecord(schema, references, value) {
|
|
|
73
73
|
return value;
|
|
74
74
|
}
|
|
75
75
|
function TRef(schema, references, value) {
|
|
76
|
-
return Visit((0,
|
|
76
|
+
return Visit((0, index_5.Deref)(schema, references), references, value);
|
|
77
77
|
}
|
|
78
78
|
function TThis(schema, references, value) {
|
|
79
|
-
return Visit((0,
|
|
79
|
+
return Visit((0, index_5.Deref)(schema, references), references, value);
|
|
80
80
|
}
|
|
81
81
|
function TTuple(schema, references, value) {
|
|
82
82
|
if (!(0, index_1.IsArray)(value))
|
|
@@ -93,7 +93,7 @@ function TTuple(schema, references, value) {
|
|
|
93
93
|
}
|
|
94
94
|
function TUnion(schema, references, value) {
|
|
95
95
|
for (const inner of schema.anyOf) {
|
|
96
|
-
if (IsCheckable(inner) && (0,
|
|
96
|
+
if (IsCheckable(inner) && (0, index_3.Check)(inner, value)) {
|
|
97
97
|
return Visit(inner, references, value);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -102,7 +102,7 @@ function TUnion(schema, references, value) {
|
|
|
102
102
|
function Visit(schema, references, value) {
|
|
103
103
|
const references_ = (0, index_1.IsString)(schema.$id) ? [...references, schema] : references;
|
|
104
104
|
const schema_ = schema;
|
|
105
|
-
switch (schema_[
|
|
105
|
+
switch (schema_[index_6.Kind]) {
|
|
106
106
|
case 'Array':
|
|
107
107
|
return TArray(schema_, references_, value);
|
|
108
108
|
case 'Intersect':
|
|
@@ -11,6 +11,6 @@ export { Equal } from './equal/index';
|
|
|
11
11
|
export { Hash, ValueHashError } from './hash/index';
|
|
12
12
|
export { Mutate, type Mutable, ValueMutateInvalidRootMutationError, ValueMutateTypeMismatchError } from './mutate/index';
|
|
13
13
|
export { ValuePointer } from './pointer/index';
|
|
14
|
-
export {
|
|
14
|
+
export { TransformDecode as DecodeTransform, TransformEncode as EncodeTransform, HasTransform, TransformDecodeCheckError, TransformDecodeError, TransformEncodeCheckError, TransformEncodeError } from './transform/index';
|
|
15
15
|
export { ArrayType, HasPropertyKey, IsArray, IsAsyncIterator, IsBigInt, IsBoolean, IsDate, IsFunction, IsInteger, IsIterator, IsNull, IsNumber, IsObject, IsPlainObject, IsPromise, IsString, IsSymbol, IsTypedArray, IsUint8Array, IsUndefined, IsValueType, ObjectType, TypedArrayType, ValueType, } from './guard/index';
|
|
16
16
|
export { Value } from './value/index';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IsInteger = exports.IsFunction = exports.IsDate = exports.IsBoolean = exports.IsBigInt = exports.IsAsyncIterator = exports.IsArray = exports.HasPropertyKey = exports.TransformEncodeError = exports.TransformEncodeCheckError = exports.TransformDecodeError = exports.TransformDecodeCheckError = exports.HasTransform = exports.
|
|
3
|
+
exports.IsInteger = exports.IsFunction = exports.IsDate = exports.IsBoolean = exports.IsBigInt = exports.IsAsyncIterator = exports.IsArray = exports.HasPropertyKey = exports.TransformEncodeError = exports.TransformEncodeCheckError = exports.TransformDecodeError = exports.TransformDecodeCheckError = exports.HasTransform = exports.EncodeTransform = exports.DecodeTransform = exports.ValuePointer = exports.ValueMutateTypeMismatchError = exports.ValueMutateInvalidRootMutationError = exports.Mutate = exports.ValueHashError = exports.Hash = exports.Equal = exports.ValueDeltaUnableToDiffUnknownValue = exports.ValueDeltaObjectWithSymbolKeyError = exports.Update = exports.Insert = exports.Delete = exports.Edit = exports.Patch = exports.Diff = exports.Default = exports.ValueCreateUnknownTypeError = exports.ValueCreateTempateLiteralTypeError = exports.ValueCreateRecursiveInstantiationError = exports.ValueCreateNotTypeError = exports.ValueCreateNeverTypeError = exports.ValueCreateIntersectTypeError = exports.Create = exports.ValueConvertUnknownTypeError = exports.Convert = exports.Clone = exports.Clean = exports.Check = exports.ValueCastUnknownTypeError = exports.ValueCastRecursiveTypeError = exports.ValueCastNeverTypeError = exports.ValueCastArrayUniqueItemsTypeError = exports.Cast = exports.ValueErrorIterator = exports.ValueErrorType = void 0;
|
|
4
4
|
exports.Value = exports.IsValueType = exports.IsUndefined = exports.IsUint8Array = exports.IsTypedArray = exports.IsSymbol = exports.IsString = exports.IsPromise = exports.IsPlainObject = exports.IsObject = exports.IsNumber = exports.IsNull = exports.IsIterator = void 0;
|
|
5
5
|
var index_1 = require("../errors/index");
|
|
6
6
|
Object.defineProperty(exports, "ValueErrorType", { enumerable: true, get: function () { return index_1.ValueErrorType; } });
|
|
@@ -51,8 +51,8 @@ Object.defineProperty(exports, "ValueMutateTypeMismatchError", { enumerable: tru
|
|
|
51
51
|
var index_13 = require("./pointer/index");
|
|
52
52
|
Object.defineProperty(exports, "ValuePointer", { enumerable: true, get: function () { return index_13.ValuePointer; } });
|
|
53
53
|
var index_14 = require("./transform/index");
|
|
54
|
-
Object.defineProperty(exports, "
|
|
55
|
-
Object.defineProperty(exports, "
|
|
54
|
+
Object.defineProperty(exports, "DecodeTransform", { enumerable: true, get: function () { return index_14.TransformDecode; } });
|
|
55
|
+
Object.defineProperty(exports, "EncodeTransform", { enumerable: true, get: function () { return index_14.TransformEncode; } });
|
|
56
56
|
Object.defineProperty(exports, "HasTransform", { enumerable: true, get: function () { return index_14.HasTransform; } });
|
|
57
57
|
Object.defineProperty(exports, "TransformDecodeCheckError", { enumerable: true, get: function () { return index_14.TransformDecodeCheckError; } });
|
|
58
58
|
Object.defineProperty(exports, "TransformDecodeError", { enumerable: true, get: function () { return index_14.TransformDecodeError; } });
|
|
@@ -11,4 +11,4 @@ export declare class TransformDecodeError extends Error {
|
|
|
11
11
|
readonly value: unknown;
|
|
12
12
|
constructor(schema: TSchema, value: unknown, error: any);
|
|
13
13
|
}
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function TransformDecode(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TransformDecode = exports.TransformDecodeError = exports.TransformDecodeCheckError = void 0;
|
|
4
4
|
const type_1 = require("../../type/guard/type");
|
|
5
5
|
const index_1 = require("../../type/symbols/index");
|
|
6
6
|
const index_2 = require("../guard/index");
|
|
@@ -41,10 +41,10 @@ function TArray(schema, references, value) {
|
|
|
41
41
|
function TIntersect(schema, references, value) {
|
|
42
42
|
if (!(0, index_2.IsPlainObject)(value) || (0, index_2.IsValueType)(value))
|
|
43
43
|
return Default(schema, value);
|
|
44
|
-
const knownKeys = (0, index_3.
|
|
44
|
+
const knownKeys = (0, index_3.KeyOfPropertyKeys)(schema);
|
|
45
45
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
46
46
|
return (key in value)
|
|
47
|
-
? { ...value, [key]: Visit((0, index_4.
|
|
47
|
+
? { ...value, [key]: Visit((0, index_4.IndexedType)(schema, [key]), references, value[key]) }
|
|
48
48
|
: value;
|
|
49
49
|
}, value);
|
|
50
50
|
if (!(0, type_1.TTransform)(schema.unevaluatedProperties)) {
|
|
@@ -65,7 +65,7 @@ function TNot(schema, references, value) {
|
|
|
65
65
|
function TObject(schema, references, value) {
|
|
66
66
|
if (!(0, index_2.IsPlainObject)(value))
|
|
67
67
|
return Default(schema, value);
|
|
68
|
-
const knownKeys = (0, index_3.
|
|
68
|
+
const knownKeys = (0, index_3.KeyOfPropertyKeys)(schema);
|
|
69
69
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
70
70
|
return (key in value)
|
|
71
71
|
? { ...value, [key]: Visit(schema.properties[key], references, value[key]) }
|
|
@@ -155,7 +155,7 @@ function Visit(schema, references, value) {
|
|
|
155
155
|
return Default(schema_, value);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
function
|
|
158
|
+
function TransformDecode(schema, references, value) {
|
|
159
159
|
return Visit(schema, references, value);
|
|
160
160
|
}
|
|
161
|
-
exports.
|
|
161
|
+
exports.TransformDecode = TransformDecode;
|
|
@@ -11,4 +11,4 @@ export declare class TransformEncodeError extends Error {
|
|
|
11
11
|
readonly value: unknown;
|
|
12
12
|
constructor(schema: TSchema, value: unknown, error: any);
|
|
13
13
|
}
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function TransformEncode(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TransformEncode = exports.TransformEncodeError = exports.TransformEncodeCheckError = void 0;
|
|
4
4
|
const type_1 = require("../../type/guard/type");
|
|
5
5
|
const index_1 = require("../../type/symbols/index");
|
|
6
6
|
const index_2 = require("../guard/index");
|
|
@@ -43,10 +43,10 @@ function TIntersect(schema, references, value) {
|
|
|
43
43
|
const defaulted = Default(schema, value);
|
|
44
44
|
if (!(0, index_2.IsPlainObject)(value) || (0, index_2.IsValueType)(value))
|
|
45
45
|
return defaulted;
|
|
46
|
-
const knownKeys = (0, index_3.
|
|
46
|
+
const knownKeys = (0, index_3.KeyOfPropertyKeys)(schema);
|
|
47
47
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
48
48
|
return key in defaulted
|
|
49
|
-
? { ...value, [key]: Visit((0, index_4.
|
|
49
|
+
? { ...value, [key]: Visit((0, index_4.IndexedType)(schema, [key]), references, value[key]) }
|
|
50
50
|
: value;
|
|
51
51
|
}, defaulted);
|
|
52
52
|
if (!(0, type_1.TTransform)(schema.unevaluatedProperties)) {
|
|
@@ -67,7 +67,7 @@ function TObject(schema, references, value) {
|
|
|
67
67
|
const defaulted = Default(schema, value);
|
|
68
68
|
if (!(0, index_2.IsPlainObject)(value))
|
|
69
69
|
return defaulted;
|
|
70
|
-
const knownKeys = (0, index_3.
|
|
70
|
+
const knownKeys = (0, index_3.KeyOfPropertyKeys)(schema);
|
|
71
71
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
72
72
|
return key in value
|
|
73
73
|
? { ...value, [key]: Visit(schema.properties[key], references, value[key]) }
|
|
@@ -161,7 +161,7 @@ function Visit(schema, references, value) {
|
|
|
161
161
|
return Default(schema_, value);
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function TransformEncode(schema, references, value) {
|
|
165
165
|
return Visit(schema, references, value);
|
|
166
166
|
}
|
|
167
|
-
exports.
|
|
167
|
+
exports.TransformEncode = TransformEncode;
|
|
@@ -42,7 +42,7 @@ function Decode(...args) {
|
|
|
42
42
|
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
43
43
|
if (!Check(schema, references, value))
|
|
44
44
|
throw new index_1.TransformDecodeCheckError(schema, value, Errors(schema, references, value).First());
|
|
45
|
-
return (0, index_1.
|
|
45
|
+
return (0, index_1.TransformDecode)(schema, references, value);
|
|
46
46
|
}
|
|
47
47
|
exports.Decode = Decode;
|
|
48
48
|
function Default(...args) {
|
|
@@ -51,7 +51,7 @@ function Default(...args) {
|
|
|
51
51
|
exports.Default = Default;
|
|
52
52
|
function Encode(...args) {
|
|
53
53
|
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
54
|
-
const encoded = (0, index_1.
|
|
54
|
+
const encoded = (0, index_1.TransformEncode)(schema, references, value);
|
|
55
55
|
if (!Check(schema, references, encoded))
|
|
56
56
|
throw new index_1.TransformEncodeCheckError(schema, value, Errors(schema, references, value).First());
|
|
57
57
|
return encoded;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sinclair/typebox",
|
|
3
|
-
"version": "0.32.0-dev-
|
|
3
|
+
"version": "0.32.0-dev-12",
|
|
4
4
|
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "https://github.com/sinclairzx81/typebox"
|
|
16
16
|
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "echo test"
|
|
19
|
+
},
|
|
17
20
|
"module": "./build/import/index.mjs",
|
|
18
21
|
"types": "./build/require/index.d.ts",
|
|
19
22
|
"main": "./build/require/index.js",
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { TSchema } from '../schema/index.mjs';
|
|
2
|
-
import type { Ensure } from '../helpers/index.mjs';
|
|
3
|
-
import { type TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
4
|
-
import { type TNumber } from '../number/index.mjs';
|
|
5
|
-
import { KeyOfStringResolve } from './keyof-string.mjs';
|
|
6
|
-
import { UnionResolve } from '../union/index.mjs';
|
|
7
|
-
type FromLiterals<T extends TLiteralValue[]> = (T extends [infer L extends TLiteralValue, ...infer R extends TLiteralValue[]] ? L extends '[number]' ? [TNumber, ...FromLiterals<R>] : [TLiteral<L>, ...FromLiterals<R>] : []);
|
|
8
|
-
declare function FromLiterals<T extends TLiteralValue[]>(T: [...T]): FromLiterals<T>;
|
|
9
|
-
export type KeyOfTypeResolve<T extends TSchema> = (Ensure<UnionResolve<FromLiterals<KeyOfStringResolve<T>>>>);
|
|
10
|
-
export declare function KeyOfTypeResolve<T extends TSchema>(T: T): KeyOfTypeResolve<T>;
|
|
11
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Literal } from '../literal/index.mjs';
|
|
2
|
-
import { Number } from '../number/index.mjs';
|
|
3
|
-
import { KeyOfStringResolve } from './keyof-string.mjs';
|
|
4
|
-
import { UnionResolve } from '../union/index.mjs';
|
|
5
|
-
function FromLiterals(T) {
|
|
6
|
-
const [L, ...R] = T;
|
|
7
|
-
return (T.length > 0
|
|
8
|
-
? L === '[number]'
|
|
9
|
-
? [Number(), ...FromLiterals(R)]
|
|
10
|
-
: [Literal(L), ...FromLiterals(R)]
|
|
11
|
-
: []);
|
|
12
|
-
}
|
|
13
|
-
export function KeyOfTypeResolve(T) {
|
|
14
|
-
return (UnionResolve(FromLiterals(KeyOfStringResolve(T))));
|
|
15
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { TSchema } from '../schema/index';
|
|
2
|
-
import type { Ensure } from '../helpers/index';
|
|
3
|
-
import { type TLiteral, TLiteralValue } from '../literal/index';
|
|
4
|
-
import { type TNumber } from '../number/index';
|
|
5
|
-
import { KeyOfStringResolve } from './keyof-string';
|
|
6
|
-
import { UnionResolve } from '../union/index';
|
|
7
|
-
type FromLiterals<T extends TLiteralValue[]> = (T extends [infer L extends TLiteralValue, ...infer R extends TLiteralValue[]] ? L extends '[number]' ? [TNumber, ...FromLiterals<R>] : [TLiteral<L>, ...FromLiterals<R>] : []);
|
|
8
|
-
declare function FromLiterals<T extends TLiteralValue[]>(T: [...T]): FromLiterals<T>;
|
|
9
|
-
export type KeyOfTypeResolve<T extends TSchema> = (Ensure<UnionResolve<FromLiterals<KeyOfStringResolve<T>>>>);
|
|
10
|
-
export declare function KeyOfTypeResolve<T extends TSchema>(T: T): KeyOfTypeResolve<T>;
|
|
11
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KeyOfTypeResolve = void 0;
|
|
4
|
-
const index_1 = require("../literal/index");
|
|
5
|
-
const index_2 = require("../number/index");
|
|
6
|
-
const keyof_string_1 = require("./keyof-string");
|
|
7
|
-
const index_3 = require("../union/index");
|
|
8
|
-
function FromLiterals(T) {
|
|
9
|
-
const [L, ...R] = T;
|
|
10
|
-
return (T.length > 0
|
|
11
|
-
? L === '[number]'
|
|
12
|
-
? [(0, index_2.Number)(), ...FromLiterals(R)]
|
|
13
|
-
: [(0, index_1.Literal)(L), ...FromLiterals(R)]
|
|
14
|
-
: []);
|
|
15
|
-
}
|
|
16
|
-
function KeyOfTypeResolve(T) {
|
|
17
|
-
return ((0, index_3.UnionResolve)(FromLiterals((0, keyof_string_1.KeyOfStringResolve)(T))));
|
|
18
|
-
}
|
|
19
|
-
exports.KeyOfTypeResolve = KeyOfTypeResolve;
|