@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
|
@@ -1,24 +1,50 @@
|
|
|
1
1
|
import type { TSchema } from '../schema/index.mjs';
|
|
2
|
-
import type { Evaluate } from '../helpers/index.mjs';
|
|
3
|
-
import
|
|
4
|
-
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
5
|
-
import { IndexedKeyResolve } from '../indexed/indexed-key.mjs';
|
|
2
|
+
import type { Ensure, Evaluate } from '../helpers/index.mjs';
|
|
3
|
+
import { IndexedPropertyKeys } from '../indexed/index.mjs';
|
|
6
4
|
import { Kind } from '../symbols/index.mjs';
|
|
5
|
+
import { type TArray } from '../array/index.mjs';
|
|
6
|
+
import { type TAsyncIterator } from '../async-iterator/index.mjs';
|
|
7
|
+
import { type TConstructor } from '../constructor/index.mjs';
|
|
8
|
+
import { type TFunction } from '../function/index.mjs';
|
|
9
|
+
import { type TIntersect } from '../intersect/index.mjs';
|
|
10
|
+
import { type TIterator } from '../iterator/index.mjs';
|
|
11
|
+
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
12
|
+
import { type TNever } from '../never/index.mjs';
|
|
13
|
+
import { type TObject, type TProperties, type ObjectOptions } from '../object/index.mjs';
|
|
14
|
+
import { type TOptional } from '../optional/index.mjs';
|
|
15
|
+
import { type TPromise } from '../promise/index.mjs';
|
|
16
|
+
import { type TReadonly } from '../readonly/index.mjs';
|
|
17
|
+
import { type TUnion } from '../union/index.mjs';
|
|
7
18
|
export interface TMappedKey<T extends PropertyKey[] = PropertyKey[]> extends TSchema {
|
|
8
19
|
[Kind]: 'MappedKey';
|
|
9
20
|
static: T[number];
|
|
10
|
-
|
|
21
|
+
keys: T;
|
|
11
22
|
}
|
|
23
|
+
export declare function MappedKey<T extends PropertyKey[]>(T: [...T]): TMappedKey<T>;
|
|
12
24
|
export type MappedFunction<K extends PropertyKey[], I = TMappedKey<K>> = (T: I) => TSchema;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
type FromMappedResult<K extends PropertyKey, P extends TProperties> = (K extends keyof P ? FromMappedPropertyKey<K, P[K]> : TNever);
|
|
26
|
+
declare function FromMappedResult<K extends PropertyKey, P extends TProperties>(K: K, P: P): FromMappedResult<K, P>;
|
|
27
|
+
type FromMappedKey<K extends PropertyKey, _ extends PropertyKey[]> = (K extends TLiteralValue ? TLiteral<K> : TLiteral<'never'>);
|
|
28
|
+
declare function FromMappedKey<K extends PropertyKey, P extends PropertyKey[]>(K: K, _: [...P]): TLiteral<TLiteralValue>;
|
|
29
|
+
type FromRest<K extends PropertyKey, T extends TSchema[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [FromMappedPropertyKey<K, L>, ...FromRest<K, R>] : [];
|
|
30
|
+
declare function FromRest<K extends PropertyKey, T extends TSchema[]>(K: K, T: [...T]): FromRest<K, T>;
|
|
31
|
+
type FromProperties<K extends PropertyKey, T extends TProperties, R extends TProperties = Evaluate<{
|
|
32
|
+
[K2 in keyof T]: FromMappedPropertyKey<K, T[K2]>;
|
|
33
|
+
}>> = R;
|
|
34
|
+
declare function FromProperties<K extends PropertyKey, T extends TProperties>(K: K, T: T): FromProperties<K, T>;
|
|
35
|
+
export type FromMappedPropertyKey<K extends PropertyKey, T extends TSchema> = (T extends TReadonly<infer S> ? TReadonly<FromMappedPropertyKey<K, S>> : T extends TOptional<infer S> ? TOptional<FromMappedPropertyKey<K, S>> : T extends TMappedResult<infer P> ? FromMappedResult<K, P> : T extends TMappedKey<infer S> ? FromMappedKey<K, S> : T extends TConstructor<infer S extends TSchema[], infer R extends TSchema> ? TConstructor<FromRest<K, S>, FromMappedPropertyKey<K, R>> : T extends TFunction<infer S extends TSchema[], infer R extends TSchema> ? TFunction<FromRest<K, S>, FromMappedPropertyKey<K, R>> : T extends TAsyncIterator<infer S> ? TAsyncIterator<FromMappedPropertyKey<K, S>> : T extends TIterator<infer S> ? TIterator<FromMappedPropertyKey<K, S>> : T extends TIntersect<infer S> ? TIntersect<FromRest<K, S>> : T extends TUnion<infer S> ? TUnion<FromRest<K, S>> : T extends TObject<infer S> ? TObject<FromProperties<K, S>> : T extends TArray<infer S> ? TArray<FromMappedPropertyKey<K, S>> : T extends TPromise<infer S> ? TPromise<FromMappedPropertyKey<K, S>> : T);
|
|
36
|
+
export declare function FromMappedPropertyKey<K extends PropertyKey, T extends TSchema>(K: K, T: T): FromMappedPropertyKey<K, T>;
|
|
37
|
+
export type FromMappedPropertyKeys<K extends PropertyKey[], T extends TSchema> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? {
|
|
38
|
+
[_ in L]: FromMappedPropertyKey<L, T>;
|
|
39
|
+
} & FromMappedPropertyKeys<R, T> : {});
|
|
40
|
+
export declare function FromMappedPropertyKeys<K extends PropertyKey[], T extends TSchema>(K: [...K], T: T): FromMappedPropertyKeys<K, T>;
|
|
41
|
+
export interface TMappedResult<T extends TProperties = TProperties> extends TSchema {
|
|
19
42
|
[Kind]: 'MappedResult';
|
|
20
|
-
|
|
21
|
-
|
|
43
|
+
properties: T;
|
|
44
|
+
static: unknown;
|
|
22
45
|
}
|
|
23
|
-
export declare function
|
|
24
|
-
export
|
|
46
|
+
export declare function MappedResult<T extends TProperties>(properties: T): TMappedResult<T>;
|
|
47
|
+
export type TMapped<K extends PropertyKey[], F extends MappedFunction<K>, R extends TProperties = Evaluate<FromMappedPropertyKeys<K, ReturnType<F>>>> = Ensure<TObject<R>>;
|
|
48
|
+
export declare function Mapped<K extends TSchema, I extends PropertyKey[] = IndexedPropertyKeys<K>, F extends MappedFunction<I> = MappedFunction<I>, R extends TMapped<I, F> = TMapped<I, F>>(key: K, map: F, options?: ObjectOptions): R;
|
|
49
|
+
export declare function Mapped<K extends PropertyKey[], F extends MappedFunction<K> = MappedFunction<K>, R extends TMapped<K, F> = TMapped<K, F>>(key: [...K], map: F, options?: ObjectOptions): R;
|
|
50
|
+
export {};
|
|
@@ -1,14 +1,78 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Literal } from '../literal/index.mjs';
|
|
3
|
-
import { IndexedKeyResolve } from '../indexed/indexed-key.mjs';
|
|
1
|
+
import { IndexedPropertyKeys } from '../indexed/index.mjs';
|
|
4
2
|
import { TSchema as IsSchemaType } from '../guard/type.mjs';
|
|
5
|
-
import { Kind } from '../symbols/index.mjs';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
import { Kind, OptionalKind, ReadonlyKind } from '../symbols/index.mjs';
|
|
4
|
+
import { CloneType } from '../clone/type.mjs';
|
|
5
|
+
import { Discard } from '../discard/index.mjs';
|
|
6
|
+
import { Array } from '../array/index.mjs';
|
|
7
|
+
import { AsyncIterator } from '../async-iterator/index.mjs';
|
|
8
|
+
import { Constructor } from '../constructor/index.mjs';
|
|
9
|
+
import { Function as FunctionType } from '../function/index.mjs';
|
|
10
|
+
import { Intersect } from '../intersect/index.mjs';
|
|
11
|
+
import { Iterator } from '../iterator/index.mjs';
|
|
12
|
+
import { Literal } from '../literal/index.mjs';
|
|
13
|
+
import { Never } from '../never/index.mjs';
|
|
14
|
+
import { Object } from '../object/index.mjs';
|
|
15
|
+
import { Optional } from '../optional/index.mjs';
|
|
16
|
+
import { Promise } from '../promise/index.mjs';
|
|
17
|
+
import { Readonly } from '../readonly/index.mjs';
|
|
18
|
+
import { Union } from '../union/index.mjs';
|
|
19
|
+
import { TOptional as IsOptionalType, TReadonly as IsReadonlyType, TMappedResult as IsMappedResultType, TMappedKey as IsMappedKeyType, TConstructor as IsConstructorType, TFunction as IsFunctionType, TAsyncIterator as IsAsyncIteratorType, TIterator as IsIteratorType, TIntersect as IsIntersectType, TUnion as IsUnionType, TObject as IsObjectType, TArray as IsArrayType, TPromise as IsPromiseType, } from '../guard/type.mjs';
|
|
20
|
+
export function MappedKey(T) {
|
|
21
|
+
return {
|
|
22
|
+
[Kind]: 'MappedKey',
|
|
23
|
+
keys: T
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function FromMappedResult(K, P) {
|
|
27
|
+
return (K in P
|
|
28
|
+
? FromMappedPropertyKey(K, P[K])
|
|
29
|
+
: Never());
|
|
30
|
+
}
|
|
31
|
+
function FromMappedKey(K, _) {
|
|
32
|
+
return Literal(K);
|
|
33
|
+
}
|
|
34
|
+
function FromRest(K, T) {
|
|
35
|
+
const [L, ...R] = T;
|
|
36
|
+
return (T.length > 0
|
|
37
|
+
? [FromMappedPropertyKey(K, L), ...FromRest(K, R)]
|
|
38
|
+
: []);
|
|
39
|
+
}
|
|
40
|
+
function FromProperties(K, T) {
|
|
41
|
+
return globalThis.Object.getOwnPropertyNames(T).reduce((Acc, K2) => {
|
|
42
|
+
return { ...Acc, [K2]: FromMappedPropertyKey(K, T[K2]) };
|
|
12
43
|
}, {});
|
|
13
|
-
|
|
44
|
+
}
|
|
45
|
+
export function FromMappedPropertyKey(K, T) {
|
|
46
|
+
return (IsOptionalType(T) ? Optional(FromMappedPropertyKey(K, Discard(T, [OptionalKind]))) :
|
|
47
|
+
IsReadonlyType(T) ? Readonly(FromMappedPropertyKey(K, Discard(T, [ReadonlyKind]))) :
|
|
48
|
+
IsMappedResultType(T) ? FromMappedResult(K, T.properties) :
|
|
49
|
+
IsMappedKeyType(T) ? FromMappedKey(K, T.keys) :
|
|
50
|
+
IsConstructorType(T) ? Constructor(FromRest(K, T.parameters), FromMappedPropertyKey(K, T.returns)) :
|
|
51
|
+
IsFunctionType(T) ? FunctionType(FromRest(K, T.parameters), FromMappedPropertyKey(K, T.returns)) :
|
|
52
|
+
IsAsyncIteratorType(T) ? AsyncIterator(FromMappedPropertyKey(K, T.items)) :
|
|
53
|
+
IsIteratorType(T) ? Iterator(FromMappedPropertyKey(K, T.items)) :
|
|
54
|
+
IsIntersectType(T) ? Intersect(FromRest(K, T.allOf)) :
|
|
55
|
+
IsUnionType(T) ? Union(FromRest(K, T.anyOf)) :
|
|
56
|
+
IsObjectType(T) ? Object(FromProperties(K, T.properties)) :
|
|
57
|
+
IsArrayType(T) ? Array(FromMappedPropertyKey(K, T.items)) :
|
|
58
|
+
IsPromiseType(T) ? Promise(FromMappedPropertyKey(K, T.item)) :
|
|
59
|
+
T);
|
|
60
|
+
}
|
|
61
|
+
export function FromMappedPropertyKeys(K, T) {
|
|
62
|
+
const [L, ...R] = K;
|
|
63
|
+
return (K.length > 0
|
|
64
|
+
? { [L]: FromMappedPropertyKey(L, T), ...FromMappedPropertyKeys(R, T) }
|
|
65
|
+
: {});
|
|
66
|
+
}
|
|
67
|
+
export function MappedResult(properties) {
|
|
68
|
+
return {
|
|
69
|
+
[Kind]: 'MappedResult',
|
|
70
|
+
properties
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function Mapped(key, map, options = {}) {
|
|
74
|
+
const K = IsSchemaType(key) ? IndexedPropertyKeys(key) : key;
|
|
75
|
+
const RT = map({ [Kind]: 'MappedKey', keys: K });
|
|
76
|
+
const R = FromMappedPropertyKeys(K, RT);
|
|
77
|
+
return CloneType(Object(R), options);
|
|
14
78
|
}
|
|
@@ -4,7 +4,7 @@ import { type TRecursive } from '../recursive/index.mjs';
|
|
|
4
4
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
5
5
|
import { type TUnion } from '../union/index.mjs';
|
|
6
6
|
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import { IndexedPropertyKeys } from '../indexed/index.mjs';
|
|
8
8
|
type FromIntersect<T extends TSchema[], K extends PropertyKey[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [OmitResolve<L, K>, ...FromIntersect<R, K>] : [];
|
|
9
9
|
declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromIntersect<T, K>;
|
|
10
10
|
type FromUnion<T extends TSchema[], K extends PropertyKey[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [OmitResolve<L, K>, ...FromUnion<R, K>] : [];
|
|
@@ -14,6 +14,6 @@ declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(
|
|
|
14
14
|
export type OmitResolve<T extends TProperties, K extends PropertyKey[]> = T extends TRecursive<infer S> ? TRecursive<OmitResolve<S, K>> : T extends TIntersect<infer S> ? TIntersect<FromIntersect<S, K>> : T extends TUnion<infer S> ? TUnion<FromUnion<S, K>> : T extends TObject<infer S> ? TObject<FromProperties<S, K>> : TObject<{}>;
|
|
15
15
|
export declare function OmitResolve<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): OmitResolve<T, K>;
|
|
16
16
|
export type TOmit<T extends TSchema, K extends PropertyKey[]> = OmitResolve<T, K>;
|
|
17
|
-
export declare function Omit<T extends TSchema, K extends TSchema, I extends PropertyKey[] =
|
|
17
|
+
export declare function Omit<T extends TSchema, K extends TSchema, I extends PropertyKey[] = IndexedPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TOmit<T, I>;
|
|
18
18
|
export declare function Omit<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TOmit<T, K>;
|
|
19
19
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Intersect } from '../intersect/index.mjs';
|
|
2
2
|
import { Union } from '../union/index.mjs';
|
|
3
3
|
import { Object } from '../object/index.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { IndexedPropertyKeys } from '../indexed/index.mjs';
|
|
5
5
|
import { Discard } from '../discard/index.mjs';
|
|
6
6
|
import { TransformKind } from '../symbols/index.mjs';
|
|
7
7
|
import { CloneType } from '../clone/type.mjs';
|
|
@@ -28,7 +28,7 @@ export function OmitResolve(T, K) {
|
|
|
28
28
|
Object({}));
|
|
29
29
|
}
|
|
30
30
|
export function Omit(T, K, options = {}) {
|
|
31
|
-
const I = IsSchemaType(K) ?
|
|
31
|
+
const I = IsSchemaType(K) ? IndexedPropertyKeys(K) : K;
|
|
32
32
|
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
33
33
|
const R = CloneType(OmitResolve(T, I), options);
|
|
34
34
|
return { ...D, ...R };
|
|
@@ -4,7 +4,7 @@ import { type TRecursive } from '../recursive/index.mjs';
|
|
|
4
4
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
5
5
|
import { type TUnion } from '../union/index.mjs';
|
|
6
6
|
import { type TObject, type TProperties } from '../object/index.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import { IndexedPropertyKeys } from '../indexed/index.mjs';
|
|
8
8
|
type FromIntersect<T extends TSchema[], K extends PropertyKey[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [PickResolve<L, K>, ...FromIntersect<R, K>] : [];
|
|
9
9
|
declare function FromIntersect<T extends TSchema[], K extends PropertyKey[]>(T: T, K: K): FromIntersect<T, K>;
|
|
10
10
|
type FromUnion<T extends TSchema[], K extends PropertyKey[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [PickResolve<L, K>, ...FromUnion<R, K>] : [];
|
|
@@ -14,6 +14,6 @@ declare function FromProperties<T extends TProperties, K extends PropertyKey[]>(
|
|
|
14
14
|
export type PickResolve<T extends TProperties, K extends PropertyKey[]> = T extends TRecursive<infer S> ? TRecursive<PickResolve<S, K>> : T extends TIntersect<infer S> ? TIntersect<FromIntersect<S, K>> : T extends TUnion<infer S> ? TUnion<FromUnion<S, K>> : T extends TObject<infer S> ? TObject<FromProperties<S, K>> : TObject<{}>;
|
|
15
15
|
export declare function PickResolve<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): PickResolve<T, K>;
|
|
16
16
|
export type TPick<T extends TSchema, K extends PropertyKey[]> = PickResolve<T, K>;
|
|
17
|
-
export declare function Pick<T extends TSchema, K extends TSchema, I extends PropertyKey[] =
|
|
17
|
+
export declare function Pick<T extends TSchema, K extends TSchema, I extends PropertyKey[] = IndexedPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TPick<T, I>;
|
|
18
18
|
export declare function Pick<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TPick<T, K>;
|
|
19
19
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Intersect } from '../intersect/index.mjs';
|
|
2
2
|
import { Union } from '../union/index.mjs';
|
|
3
3
|
import { Object } from '../object/index.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { IndexedPropertyKeys } from '../indexed/index.mjs';
|
|
5
5
|
import { Discard } from '../discard/index.mjs';
|
|
6
6
|
import { TransformKind } from '../symbols/index.mjs';
|
|
7
7
|
import { CloneType } from '../clone/type.mjs';
|
|
@@ -24,7 +24,7 @@ export function PickResolve(T, K) {
|
|
|
24
24
|
Object({}));
|
|
25
25
|
}
|
|
26
26
|
export function Pick(T, K, options = {}) {
|
|
27
|
-
const I = IsSchemaType(K) ?
|
|
27
|
+
const I = IsSchemaType(K) ? IndexedPropertyKeys(K) : K;
|
|
28
28
|
const D = Discard(T, [TransformKind, '$id', 'required']);
|
|
29
29
|
const R = CloneType(PickResolve(T, I), options);
|
|
30
30
|
return { ...D, ...R };
|
|
@@ -3,7 +3,7 @@ import { Never } from '../never/index.mjs';
|
|
|
3
3
|
import { Union } from '../union/index.mjs';
|
|
4
4
|
import { IsTemplateLiteralFinite, TemplateLiteralParseExact } from '../template-literal/index.mjs';
|
|
5
5
|
import { PatternStringExact, PatternNumberExact } from '../patterns/index.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { IndexedPropertyKeys } from '../indexed/index.mjs';
|
|
7
7
|
import { Kind, Hint } from '../symbols/index.mjs';
|
|
8
8
|
import { CloneType } from '../clone/type.mjs';
|
|
9
9
|
import { IsUndefined } from '../guard/value.mjs';
|
|
@@ -18,11 +18,11 @@ function FromKeys(keys, T) {
|
|
|
18
18
|
function FromTemplateLiteralKey(K, T) {
|
|
19
19
|
const expression = TemplateLiteralParseExact(K.pattern);
|
|
20
20
|
return (IsTemplateLiteralFinite(expression)
|
|
21
|
-
? FromKeys(
|
|
21
|
+
? FromKeys(IndexedPropertyKeys(K), T)
|
|
22
22
|
: FromPattern(K.pattern, T));
|
|
23
23
|
}
|
|
24
24
|
function FromUnionKey(K, T) {
|
|
25
|
-
return FromKeys(
|
|
25
|
+
return FromKeys(IndexedPropertyKeys(Union(K)), T);
|
|
26
26
|
}
|
|
27
27
|
function FromLiteralKey(K, T) {
|
|
28
28
|
return FromKeys([K.toString()], T);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import type { Static } from '../static/index.mjs';
|
|
3
3
|
import { Kind } from '../symbols/index.mjs';
|
|
4
|
-
|
|
4
|
+
type FromRest<T extends TSchema[], P extends unknown[]> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [Static<L, P>, ...FromRest<R, P>] : [];
|
|
5
|
+
type TupleResolve<T extends TSchema[], P extends unknown[], R extends unknown[] = FromRest<T, P>> = R;
|
|
5
6
|
export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
6
7
|
[Kind]: 'Tuple';
|
|
7
8
|
static: TupleResolve<T, this['params']>;
|
|
@@ -12,3 +13,4 @@ export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
|
|
|
12
13
|
maxItems: number;
|
|
13
14
|
}
|
|
14
15
|
export declare function Tuple<T extends TSchema[]>(items: [...T], options?: SchemaOptions): TTuple<T>;
|
|
16
|
+
export {};
|
|
@@ -6,17 +6,19 @@ import { type TConst } from '../const/index.mjs';
|
|
|
6
6
|
import { type TDeref } from '../deref/index.mjs';
|
|
7
7
|
import { type TEnum, type TEnumKey, type TEnumValue } from '../enum/index.mjs';
|
|
8
8
|
import { type TExclude } from '../exclude/index.mjs';
|
|
9
|
-
import { type TExtends } from '../extends/index.mjs';
|
|
9
|
+
import { type TExtends, type MappedExtends, type MappedResultExtends } from '../extends/index.mjs';
|
|
10
10
|
import { type TExtract } from '../extract/index.mjs';
|
|
11
|
-
import { TIndex, type
|
|
11
|
+
import { TIndex, type IndexedPropertyKeys, type TMappedIndex } from '../indexed/index.mjs';
|
|
12
12
|
import { type IntegerOptions, type TInteger } from '../integer/index.mjs';
|
|
13
13
|
import { type IntersectOptions, type IntersectResolve } from '../intersect/index.mjs';
|
|
14
14
|
import { type TCapitalize, type TUncapitalize, type TLowercase, type TUppercase } from '../intrinsic/index.mjs';
|
|
15
15
|
import { type TKeyOf } from '../keyof/index.mjs';
|
|
16
16
|
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
17
|
+
import { type MappedFunction, type TMapped, type TMappedResult } from '../mapped/index.mjs';
|
|
17
18
|
import { type TNever } from '../never/index.mjs';
|
|
18
19
|
import { type TNot } from '../not/index.mjs';
|
|
19
20
|
import { type TNull } from '../null/index.mjs';
|
|
21
|
+
import { type TMappedKey } from '../mapped/index.mjs';
|
|
20
22
|
import { type TNumber, type NumberOptions } from '../number/index.mjs';
|
|
21
23
|
import { type TObject, type TProperties, type ObjectOptions } from '../object/index.mjs';
|
|
22
24
|
import { type TOmit } from '../omit/index.mjs';
|
|
@@ -51,25 +53,30 @@ export declare class JsonTypeBuilder {
|
|
|
51
53
|
Const<T>(value: T, options?: SchemaOptions): TConst<T>;
|
|
52
54
|
Deref<T extends TSchema>(schema: T, references: TSchema[]): TDeref<T>;
|
|
53
55
|
Enum<V extends TEnumValue, T extends Record<TEnumKey, V>>(item: T, options?: SchemaOptions): TEnum<T>;
|
|
54
|
-
Extends<L extends
|
|
56
|
+
Extends<L extends TMappedResult, R extends TSchema, T extends TSchema, F extends TSchema>(L: L, R: R, T: T, F: F, options?: SchemaOptions): MappedResultExtends<L, R, T, F>;
|
|
57
|
+
Extends<L extends TMappedKey, R extends TSchema, T extends TSchema, F extends TSchema>(L: L, R: R, T: T, F: F, options?: SchemaOptions): MappedExtends<L, R, T, F>;
|
|
58
|
+
Extends<L extends TSchema, R extends TSchema, T extends TSchema, F extends TSchema>(L: L, R: R, T: T, F: F, options?: SchemaOptions): TExtends<L, R, T, F>;
|
|
55
59
|
Exclude<L extends TSchema, R extends TSchema>(unionType: L, excludedMembers: R, options?: SchemaOptions): TExclude<L, R>;
|
|
56
60
|
Extract<L extends TSchema, R extends TSchema>(type: L, union: R, options?: SchemaOptions): TExtract<L, R>;
|
|
57
|
-
Index<T extends TSchema, K extends
|
|
61
|
+
Index<T extends TSchema, K extends TMappedKey>(T: T, K: K): TMappedIndex<T, K>;
|
|
62
|
+
Index<T extends TSchema, K extends TSchema, I extends PropertyKey[] = IndexedPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TIndex<T, I>;
|
|
58
63
|
Index<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TIndex<T, K>;
|
|
59
64
|
Integer(options?: IntegerOptions): TInteger;
|
|
60
65
|
Intersect<T extends TSchema[]>(T: [...T], options?: IntersectOptions): IntersectResolve<T>;
|
|
61
66
|
KeyOf<T extends TSchema>(schema: T, options?: SchemaOptions): TKeyOf<T>;
|
|
62
67
|
Literal<T extends TLiteralValue>(value: T, options?: SchemaOptions): TLiteral<T>;
|
|
63
68
|
Lowercase<T extends TSchema>(schema: T, options?: SchemaOptions): TLowercase<T>;
|
|
69
|
+
Mapped<K extends TSchema, I extends PropertyKey[] = IndexedPropertyKeys<K>, F extends MappedFunction<I> = MappedFunction<I>, R extends TMapped<I, F> = TMapped<I, F>>(key: K, map: F, options?: ObjectOptions): R;
|
|
70
|
+
Mapped<K extends PropertyKey[], F extends MappedFunction<K> = MappedFunction<K>, R extends TMapped<K, F> = TMapped<K, F>>(key: [...K], map: F, options?: ObjectOptions): R;
|
|
64
71
|
Never(options?: SchemaOptions): TNever;
|
|
65
72
|
Not<T extends TSchema>(schema: T, options?: SchemaOptions): TNot<T>;
|
|
66
73
|
Null(options?: SchemaOptions): TNull;
|
|
67
74
|
Number(options?: NumberOptions): TNumber;
|
|
68
75
|
Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
|
|
69
|
-
Omit<T extends TSchema, K extends TSchema, I extends PropertyKey[] =
|
|
76
|
+
Omit<T extends TSchema, K extends TSchema, I extends PropertyKey[] = IndexedPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TOmit<T, I>;
|
|
70
77
|
Omit<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TOmit<T, K>;
|
|
71
78
|
Partial<T extends TSchema>(schema: T, options?: ObjectOptions): TPartial<T>;
|
|
72
|
-
Pick<T extends TSchema, K extends TSchema, I extends PropertyKey[] =
|
|
79
|
+
Pick<T extends TSchema, K extends TSchema, I extends PropertyKey[] = IndexedPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TPick<T, I>;
|
|
73
80
|
Pick<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TPick<T, K>;
|
|
74
81
|
Record<K extends TSchema, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): RecordResolve<K, T>;
|
|
75
82
|
Recursive<T extends TSchema>(callback: (thisType: TThis) => T, options?: SchemaOptions): TRecursive<T>;
|
|
@@ -14,6 +14,7 @@ import { Intersect } from '../intersect/index.mjs';
|
|
|
14
14
|
import { Capitalize, Uncapitalize, Lowercase, Uppercase } from '../intrinsic/index.mjs';
|
|
15
15
|
import { KeyOf } from '../keyof/index.mjs';
|
|
16
16
|
import { Literal } from '../literal/index.mjs';
|
|
17
|
+
import { Mapped } from '../mapped/index.mjs';
|
|
17
18
|
import { Never } from '../never/index.mjs';
|
|
18
19
|
import { Not } from '../not/index.mjs';
|
|
19
20
|
import { Null } from '../null/index.mjs';
|
|
@@ -75,8 +76,8 @@ export class JsonTypeBuilder {
|
|
|
75
76
|
Enum(item, options = {}) {
|
|
76
77
|
return Enum(item, options);
|
|
77
78
|
}
|
|
78
|
-
Extends(
|
|
79
|
-
return Extends(
|
|
79
|
+
Extends(L, R, T, F, options = {}) {
|
|
80
|
+
return Extends(L, R, T, F, options);
|
|
80
81
|
}
|
|
81
82
|
Exclude(unionType, excludedMembers, options = {}) {
|
|
82
83
|
return Exclude(unionType, excludedMembers, options);
|
|
@@ -102,6 +103,9 @@ export class JsonTypeBuilder {
|
|
|
102
103
|
Lowercase(schema, options = {}) {
|
|
103
104
|
return Lowercase(schema, options);
|
|
104
105
|
}
|
|
106
|
+
Mapped(key, map, options = {}) {
|
|
107
|
+
return Mapped(key, map, options);
|
|
108
|
+
}
|
|
105
109
|
Never(options = {}) {
|
|
106
110
|
return Never(options);
|
|
107
111
|
}
|
|
@@ -3,7 +3,7 @@ import { TypeSystemPolicy } from '../../system/index.mjs';
|
|
|
3
3
|
import { Deref } from '../deref/index.mjs';
|
|
4
4
|
import { Hash } from '../hash/index.mjs';
|
|
5
5
|
import { Kind } from '../../type/symbols/index.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { KeyOfPattern } from '../../type/keyof/index.mjs';
|
|
7
7
|
import { ExtendsUndefinedCheck } from '../../type/extends/index.mjs';
|
|
8
8
|
import { TSchema as IsSchemaType } from '../../type/guard/type.mjs';
|
|
9
9
|
import { TypeRegistry, FormatRegistry } from '../../type/registry/index.mjs';
|
|
@@ -139,12 +139,12 @@ function TInteger(schema, references, value) {
|
|
|
139
139
|
function TIntersect(schema, references, value) {
|
|
140
140
|
const check1 = schema.allOf.every((schema) => Visit(schema, references, value));
|
|
141
141
|
if (schema.unevaluatedProperties === false) {
|
|
142
|
-
const keyPattern = new RegExp(
|
|
142
|
+
const keyPattern = new RegExp(KeyOfPattern(schema));
|
|
143
143
|
const check2 = Object.getOwnPropertyNames(value).every((key) => keyPattern.test(key));
|
|
144
144
|
return check1 && check2;
|
|
145
145
|
}
|
|
146
146
|
else if (IsSchemaType(schema.unevaluatedProperties)) {
|
|
147
|
-
const keyCheck = new RegExp(
|
|
147
|
+
const keyCheck = new RegExp(KeyOfPattern(schema));
|
|
148
148
|
const check2 = Object.getOwnPropertyNames(value).every((key) => keyCheck.test(key) || Visit(schema.unevaluatedProperties, references, value[key]));
|
|
149
149
|
return check1 && check2;
|
|
150
150
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IsString, IsObject, IsArray, IsUndefined } from '../guard/index.mjs';
|
|
2
2
|
import { TSchema as IsSchemaType } from '../../type/guard/type.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { KeyOfPropertyKeys } from '../../type/keyof/index.mjs';
|
|
4
4
|
import { Check } from '../check/index.mjs';
|
|
5
5
|
import { Clone } from '../clone/index.mjs';
|
|
6
6
|
import { Deref } from '../deref/index.mjs';
|
|
@@ -22,7 +22,7 @@ function TIntersect(schema, references, value) {
|
|
|
22
22
|
const composite = intersections.reduce((acc, value) => (IsObject(value) ? { ...acc, ...value } : value), {});
|
|
23
23
|
if (!IsObject(value) || !IsObject(composite) || !IsSchema(unevaluatedProperties))
|
|
24
24
|
return composite;
|
|
25
|
-
const knownkeys =
|
|
25
|
+
const knownkeys = KeyOfPropertyKeys(schema);
|
|
26
26
|
for (const key of Object.getOwnPropertyNames(value)) {
|
|
27
27
|
if (knownkeys.includes(key))
|
|
28
28
|
continue;
|
|
@@ -11,6 +11,6 @@ export { Equal } from './equal/index.mjs';
|
|
|
11
11
|
export { Hash, ValueHashError } from './hash/index.mjs';
|
|
12
12
|
export { Mutate, type Mutable, ValueMutateInvalidRootMutationError, ValueMutateTypeMismatchError } from './mutate/index.mjs';
|
|
13
13
|
export { ValuePointer } from './pointer/index.mjs';
|
|
14
|
-
export {
|
|
14
|
+
export { TransformDecode as DecodeTransform, TransformEncode as EncodeTransform, HasTransform, TransformDecodeCheckError, TransformDecodeError, TransformEncodeCheckError, TransformEncodeError } from './transform/index.mjs';
|
|
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.mjs';
|
|
16
16
|
export { Value } from './value/index.mjs';
|
|
@@ -11,6 +11,6 @@ export { Equal } from './equal/index.mjs';
|
|
|
11
11
|
export { Hash, ValueHashError } from './hash/index.mjs';
|
|
12
12
|
export { Mutate, ValueMutateInvalidRootMutationError, ValueMutateTypeMismatchError } from './mutate/index.mjs';
|
|
13
13
|
export { ValuePointer } from './pointer/index.mjs';
|
|
14
|
-
export {
|
|
14
|
+
export { TransformDecode as DecodeTransform, TransformEncode as EncodeTransform, HasTransform, TransformDecodeCheckError, TransformDecodeError, TransformEncodeCheckError, TransformEncodeError } from './transform/index.mjs';
|
|
15
15
|
export { HasPropertyKey, IsArray, IsAsyncIterator, IsBigInt, IsBoolean, IsDate, IsFunction, IsInteger, IsIterator, IsNull, IsNumber, IsObject, IsPlainObject, IsPromise, IsString, IsSymbol, IsTypedArray, IsUint8Array, IsUndefined, IsValueType, } from './guard/index.mjs';
|
|
16
16
|
export { Value } from './value/index.mjs';
|
|
@@ -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,8 +1,8 @@
|
|
|
1
1
|
import { TTransform as IsTransformType, TSchema as IsSchemaType } from '../../type/guard/type.mjs';
|
|
2
2
|
import { Kind, TransformKind } from '../../type/symbols/index.mjs';
|
|
3
3
|
import { IsPlainObject, IsArray, IsValueType } from '../guard/index.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { KeyOfPropertyKeys } from '../../type/keyof/index.mjs';
|
|
5
|
+
import { IndexedType } from '../../type/indexed/index.mjs';
|
|
6
6
|
import { Deref } from '../deref/index.mjs';
|
|
7
7
|
import { Check } from '../check/index.mjs';
|
|
8
8
|
export class TransformDecodeCheckError extends Error {
|
|
@@ -41,10 +41,10 @@ function TArray(schema, references, value) {
|
|
|
41
41
|
function TIntersect(schema, references, value) {
|
|
42
42
|
if (!IsPlainObject(value) || IsValueType(value))
|
|
43
43
|
return Default(schema, value);
|
|
44
|
-
const knownKeys =
|
|
44
|
+
const knownKeys = KeyOfPropertyKeys(schema);
|
|
45
45
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
46
46
|
return (key in value)
|
|
47
|
-
? { ...value, [key]: Visit(
|
|
47
|
+
? { ...value, [key]: Visit(IndexedType(schema, [key]), references, value[key]) }
|
|
48
48
|
: value;
|
|
49
49
|
}, value);
|
|
50
50
|
if (!IsTransformType(schema.unevaluatedProperties)) {
|
|
@@ -65,7 +65,7 @@ function TNot(schema, references, value) {
|
|
|
65
65
|
function TObject(schema, references, value) {
|
|
66
66
|
if (!IsPlainObject(value))
|
|
67
67
|
return Default(schema, value);
|
|
68
|
-
const knownKeys =
|
|
68
|
+
const knownKeys = 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,6 +155,6 @@ function Visit(schema, references, value) {
|
|
|
155
155
|
return Default(schema_, value);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
export function
|
|
158
|
+
export function TransformDecode(schema, references, value) {
|
|
159
159
|
return Visit(schema, references, value);
|
|
160
160
|
}
|
|
@@ -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,8 +1,8 @@
|
|
|
1
1
|
import { TTransform as IsTransformType, TSchema as IsSchemaType } from '../../type/guard/type.mjs';
|
|
2
2
|
import { Kind, TransformKind } from '../../type/symbols/index.mjs';
|
|
3
3
|
import { IsPlainObject, IsArray, IsValueType } from '../guard/index.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { KeyOfPropertyKeys } from '../../type/keyof/index.mjs';
|
|
5
|
+
import { IndexedType } from '../../type/indexed/index.mjs';
|
|
6
6
|
import { Deref } from '../deref/index.mjs';
|
|
7
7
|
import { Check } from '../check/index.mjs';
|
|
8
8
|
export class TransformEncodeCheckError extends Error {
|
|
@@ -43,10 +43,10 @@ function TIntersect(schema, references, value) {
|
|
|
43
43
|
const defaulted = Default(schema, value);
|
|
44
44
|
if (!IsPlainObject(value) || IsValueType(value))
|
|
45
45
|
return defaulted;
|
|
46
|
-
const knownKeys =
|
|
46
|
+
const knownKeys = KeyOfPropertyKeys(schema);
|
|
47
47
|
const knownProperties = knownKeys.reduce((value, key) => {
|
|
48
48
|
return key in defaulted
|
|
49
|
-
? { ...value, [key]: Visit(
|
|
49
|
+
? { ...value, [key]: Visit(IndexedType(schema, [key]), references, value[key]) }
|
|
50
50
|
: value;
|
|
51
51
|
}, defaulted);
|
|
52
52
|
if (!IsTransformType(schema.unevaluatedProperties)) {
|
|
@@ -67,7 +67,7 @@ function TObject(schema, references, value) {
|
|
|
67
67
|
const defaulted = Default(schema, value);
|
|
68
68
|
if (!IsPlainObject(value))
|
|
69
69
|
return defaulted;
|
|
70
|
-
const knownKeys =
|
|
70
|
+
const knownKeys = 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,6 +161,6 @@ function Visit(schema, references, value) {
|
|
|
161
161
|
return Default(schema_, value);
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
export function
|
|
164
|
+
export function TransformEncode(schema, references, value) {
|
|
165
165
|
return Visit(schema, references, value);
|
|
166
166
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TransformDecode, TransformEncode, TransformDecodeCheckError, TransformEncodeCheckError } from '../transform/index.mjs';
|
|
2
2
|
import { Mutate as MutateValue } from '../mutate/index.mjs';
|
|
3
3
|
import { Hash as HashValue } from '../hash/index.mjs';
|
|
4
4
|
import { Equal as EqualValue } from '../equal/index.mjs';
|
|
@@ -33,14 +33,14 @@ export function Decode(...args) {
|
|
|
33
33
|
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
34
34
|
if (!Check(schema, references, value))
|
|
35
35
|
throw new TransformDecodeCheckError(schema, value, Errors(schema, references, value).First());
|
|
36
|
-
return
|
|
36
|
+
return TransformDecode(schema, references, value);
|
|
37
37
|
}
|
|
38
38
|
export function Default(...args) {
|
|
39
39
|
return DefaultValue.apply(DefaultValue, args);
|
|
40
40
|
}
|
|
41
41
|
export function Encode(...args) {
|
|
42
42
|
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
43
|
-
const encoded =
|
|
43
|
+
const encoded = TransformEncode(schema, references, value);
|
|
44
44
|
if (!Check(schema, references, encoded))
|
|
45
45
|
throw new TransformEncodeCheckError(schema, value, Errors(schema, references, value).First());
|
|
46
46
|
return encoded;
|
|
@@ -33,10 +33,10 @@ class TypeCheck {
|
|
|
33
33
|
Decode(value) {
|
|
34
34
|
if (!this.checkFunc(value))
|
|
35
35
|
throw new index_1.TransformDecodeCheckError(this.schema, value, this.Errors(value).First());
|
|
36
|
-
return this.hasTransform ? (0, index_1.
|
|
36
|
+
return this.hasTransform ? (0, index_1.TransformDecode)(this.schema, this.references, value) : value;
|
|
37
37
|
}
|
|
38
38
|
Encode(value) {
|
|
39
|
-
const encoded = this.hasTransform ? (0, index_1.
|
|
39
|
+
const encoded = this.hasTransform ? (0, index_1.TransformEncode)(this.schema, this.references, value) : value;
|
|
40
40
|
if (!this.checkFunc(encoded))
|
|
41
41
|
throw new index_1.TransformEncodeCheckError(this.schema, value, this.Errors(value).First());
|
|
42
42
|
return encoded;
|
|
@@ -237,12 +237,12 @@ var TypeCompiler;
|
|
|
237
237
|
function* TIntersect(schema, references, value) {
|
|
238
238
|
const check1 = schema.allOf.map((schema) => CreateExpression(schema, references, value)).join(' && ');
|
|
239
239
|
if (schema.unevaluatedProperties === false) {
|
|
240
|
-
const keyCheck = CreateVariable(`${new RegExp((0, index_9.
|
|
240
|
+
const keyCheck = CreateVariable(`${new RegExp((0, index_9.KeyOfPattern)(schema))};`);
|
|
241
241
|
const check2 = `Object.getOwnPropertyNames(${value}).every(key => ${keyCheck}.test(key))`;
|
|
242
242
|
yield `(${check1} && ${check2})`;
|
|
243
243
|
}
|
|
244
244
|
else if ((0, type_1.TSchema)(schema.unevaluatedProperties)) {
|
|
245
|
-
const keyCheck = CreateVariable(`${new RegExp((0, index_9.
|
|
245
|
+
const keyCheck = CreateVariable(`${new RegExp((0, index_9.KeyOfPattern)(schema))};`);
|
|
246
246
|
const check2 = `Object.getOwnPropertyNames(${value}).every(key => ${keyCheck}.test(key) || ${CreateExpression(schema.unevaluatedProperties, references, `${value}[key]`)})`;
|
|
247
247
|
yield `(${check1} && ${check2})`;
|
|
248
248
|
}
|
|
@@ -227,7 +227,7 @@ function* TIntersect(schema, references, path, value) {
|
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
if (schema.unevaluatedProperties === false) {
|
|
230
|
-
const keyCheck = new RegExp((0, index_3.
|
|
230
|
+
const keyCheck = new RegExp((0, index_3.KeyOfPattern)(schema));
|
|
231
231
|
for (const valueKey of Object.getOwnPropertyNames(value)) {
|
|
232
232
|
if (!keyCheck.test(valueKey)) {
|
|
233
233
|
yield Create(ValueErrorType.IntersectUnevaluatedProperties, schema, `${path}/${valueKey}`, value);
|
|
@@ -235,7 +235,7 @@ function* TIntersect(schema, references, path, value) {
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
if (typeof schema.unevaluatedProperties === 'object') {
|
|
238
|
-
const keyCheck = new RegExp((0, index_3.
|
|
238
|
+
const keyCheck = new RegExp((0, index_3.KeyOfPattern)(schema));
|
|
239
239
|
for (const valueKey of Object.getOwnPropertyNames(value)) {
|
|
240
240
|
if (!keyCheck.test(valueKey)) {
|
|
241
241
|
const next = Visit(schema.unevaluatedProperties, references, `${path}/${valueKey}`, value[valueKey]).next();
|