@sinclair/typebox 0.32.22 → 0.32.24
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/type/constructor/constructor.d.mts +1 -1
- package/build/import/type/function/function.d.mts +1 -1
- package/build/import/value/clean/clean.mjs +1 -1
- package/build/import/value/convert/convert.mjs +8 -6
- package/build/import/value/value/value.d.mts +2 -2
- package/build/import/value/value/value.mjs +1 -1
- package/build/require/type/constructor/constructor.d.ts +1 -1
- package/build/require/type/function/function.d.ts +1 -1
- package/build/require/value/clean/clean.js +1 -1
- package/build/require/value/convert/convert.js +7 -5
- package/build/require/value/value/value.d.ts +2 -2
- package/build/require/value/value/value.js +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadon
|
|
|
10
10
|
Static<T, P>
|
|
11
11
|
];
|
|
12
12
|
type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
|
|
13
|
-
type StaticConstructor<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...
|
|
13
|
+
type StaticConstructor<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...param: StaticParameters<T, P>) => StaticReturnType<U, P>>;
|
|
14
14
|
export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
15
15
|
[Kind]: 'Constructor';
|
|
16
16
|
static: StaticConstructor<T, U, this['params']>;
|
|
@@ -10,7 +10,7 @@ type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadon
|
|
|
10
10
|
Static<T, P>
|
|
11
11
|
];
|
|
12
12
|
type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
|
|
13
|
-
type StaticFunction<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...
|
|
13
|
+
type StaticFunction<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...param: StaticParameters<T, P>) => StaticReturnType<U, P>>;
|
|
14
14
|
export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
15
15
|
[Kind]: 'Function';
|
|
16
16
|
static: StaticFunction<T, U, this['params']>;
|
|
@@ -102,7 +102,7 @@ function FromTuple(schema, references, value) {
|
|
|
102
102
|
}
|
|
103
103
|
function FromUnion(schema, references, value) {
|
|
104
104
|
for (const inner of schema.anyOf) {
|
|
105
|
-
if (IsCheckable(inner) && Check(inner, value)) {
|
|
105
|
+
if (IsCheckable(inner) && Check(inner, references, value)) {
|
|
106
106
|
return Visit(inner, references, value);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
@@ -5,7 +5,7 @@ import { Kind } from '../../type/symbols/index.mjs';
|
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
6
|
// ValueGuard
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
|
-
import { IsArray, IsObject, IsDate, IsUndefined, IsString, IsNumber, IsBoolean, IsBigInt, IsSymbol } from '../guard/index.mjs';
|
|
8
|
+
import { IsArray, IsObject, IsDate, IsUndefined, IsString, IsNumber, IsBoolean, IsBigInt, IsSymbol, HasPropertyKey } from '../guard/index.mjs';
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// Conversions
|
|
11
11
|
// ------------------------------------------------------------------
|
|
@@ -142,11 +142,13 @@ function FromObject(schema, references, value) {
|
|
|
142
142
|
const isConvertable = IsObject(value);
|
|
143
143
|
if (!isConvertable)
|
|
144
144
|
return value;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
const result = {};
|
|
146
|
+
for (const key of Object.keys(value)) {
|
|
147
|
+
result[key] = HasPropertyKey(schema.properties, key)
|
|
148
|
+
? Visit(schema.properties[key], references, value[key])
|
|
149
|
+
: value[key];
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
150
152
|
}
|
|
151
153
|
function FromRecord(schema, references, value) {
|
|
152
154
|
const propertyKey = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
@@ -19,9 +19,9 @@ export declare function Check<T extends TSchema>(schema: T, value: unknown): val
|
|
|
19
19
|
export declare function Clean(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
20
20
|
/** `[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. */
|
|
21
21
|
export declare function Clean(schema: TSchema, value: unknown): unknown;
|
|
22
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
22
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
23
23
|
export declare function Convert(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
24
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is
|
|
24
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
25
25
|
export declare function Convert(schema: TSchema, value: unknown): unknown;
|
|
26
26
|
/** Returns a structural clone of the given value */
|
|
27
27
|
export declare function Clone<T>(value: T): T;
|
|
@@ -27,7 +27,7 @@ export function Check(...args) {
|
|
|
27
27
|
export function Clean(...args) {
|
|
28
28
|
return CleanValue.apply(CleanValue, args);
|
|
29
29
|
}
|
|
30
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
30
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
31
31
|
export function Convert(...args) {
|
|
32
32
|
return ConvertValue.apply(ConvertValue, args);
|
|
33
33
|
}
|
|
@@ -10,7 +10,7 @@ type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadon
|
|
|
10
10
|
Static<T, P>
|
|
11
11
|
];
|
|
12
12
|
type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
|
|
13
|
-
type StaticConstructor<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...
|
|
13
|
+
type StaticConstructor<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...param: StaticParameters<T, P>) => StaticReturnType<U, P>>;
|
|
14
14
|
export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
15
15
|
[Kind]: 'Constructor';
|
|
16
16
|
static: StaticConstructor<T, U, this['params']>;
|
|
@@ -10,7 +10,7 @@ type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadon
|
|
|
10
10
|
Static<T, P>
|
|
11
11
|
];
|
|
12
12
|
type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
|
|
13
|
-
type StaticFunction<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...
|
|
13
|
+
type StaticFunction<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...param: StaticParameters<T, P>) => StaticReturnType<U, P>>;
|
|
14
14
|
export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
|
|
15
15
|
[Kind]: 'Function';
|
|
16
16
|
static: StaticFunction<T, U, this['params']>;
|
|
@@ -106,7 +106,7 @@ function FromTuple(schema, references, value) {
|
|
|
106
106
|
}
|
|
107
107
|
function FromUnion(schema, references, value) {
|
|
108
108
|
for (const inner of schema.anyOf) {
|
|
109
|
-
if (IsCheckable(inner) && (0, index_2.Check)(inner, value)) {
|
|
109
|
+
if (IsCheckable(inner) && (0, index_2.Check)(inner, references, value)) {
|
|
110
110
|
return Visit(inner, references, value);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -146,11 +146,13 @@ function FromObject(schema, references, value) {
|
|
|
146
146
|
const isConvertable = (0, index_5.IsObject)(value);
|
|
147
147
|
if (!isConvertable)
|
|
148
148
|
return value;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
const result = {};
|
|
150
|
+
for (const key of Object.keys(value)) {
|
|
151
|
+
result[key] = (0, index_5.HasPropertyKey)(schema.properties, key)
|
|
152
|
+
? Visit(schema.properties[key], references, value[key])
|
|
153
|
+
: value[key];
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
154
156
|
}
|
|
155
157
|
function FromRecord(schema, references, value) {
|
|
156
158
|
const propertyKey = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
@@ -19,9 +19,9 @@ export declare function Check<T extends TSchema>(schema: T, value: unknown): val
|
|
|
19
19
|
export declare function Clean(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
20
20
|
/** `[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. */
|
|
21
21
|
export declare function Clean(schema: TSchema, value: unknown): unknown;
|
|
22
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
22
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
23
23
|
export declare function Convert(schema: TSchema, references: TSchema[], value: unknown): unknown;
|
|
24
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is
|
|
24
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
25
25
|
export declare function Convert(schema: TSchema, value: unknown): unknown;
|
|
26
26
|
/** Returns a structural clone of the given value */
|
|
27
27
|
export declare function Clone<T>(value: T): T;
|
|
@@ -35,7 +35,7 @@ function Clean(...args) {
|
|
|
35
35
|
return index_9.Clean.apply(index_9.Clean, args);
|
|
36
36
|
}
|
|
37
37
|
exports.Clean = Clean;
|
|
38
|
-
/** Converts any type mismatched values to their target type if a reasonable conversion is possible */
|
|
38
|
+
/** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
|
|
39
39
|
function Convert(...args) {
|
|
40
40
|
return index_7.Convert.apply(index_7.Convert, args);
|
|
41
41
|
}
|