@sinclair/typebox 0.32.0-dev-11 → 0.32.0-dev-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/import/compiler/compiler.mjs +3 -3
- package/build/import/errors/errors.mjs +3 -3
- package/build/import/index.d.mts +6 -6
- package/build/import/index.mjs +4 -4
- 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-from-result.d.mts +13 -0
- package/build/import/type/extends/extends-mapped-result-from-result.mjs +14 -0
- package/build/import/type/extends/extends-mapped-result.d.mts +17 -0
- package/build/import/type/extends/extends-mapped-result.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 +3 -2
- package/build/import/type/indexed/index.mjs +3 -2
- package/build/import/type/indexed/indexed-mapped-result.d.mts +16 -0
- package/build/import/type/indexed/indexed-mapped-result.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 → indexed-result.d.mts} +2 -2
- package/build/import/type/indexed/{indexed-type.mjs → indexed-result.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/intrinsic/capitalize.d.mts +4 -0
- package/build/import/type/intrinsic/capitalize.mjs +5 -0
- package/build/import/type/intrinsic/index.d.mts +5 -0
- package/build/import/type/intrinsic/index.mjs +5 -0
- package/build/import/type/intrinsic/intrinsic-mapped-result.d.mts +15 -0
- package/build/import/type/intrinsic/intrinsic-mapped-result.mjs +21 -0
- package/build/import/type/intrinsic/intrinsic.d.mts +9 -14
- package/build/import/type/intrinsic/intrinsic.mjs +10 -21
- package/build/import/type/intrinsic/lowercase.d.mts +4 -0
- package/build/import/type/intrinsic/lowercase.mjs +5 -0
- package/build/import/type/intrinsic/uncapitalize.d.mts +4 -0
- package/build/import/type/intrinsic/uncapitalize.mjs +5 -0
- package/build/import/type/intrinsic/uppercase.d.mts +4 -0
- package/build/import/type/intrinsic/uppercase.mjs +5 -0
- 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/index.d.mts +2 -0
- package/build/import/type/mapped/index.mjs +2 -0
- package/build/import/type/mapped/mapped-key.d.mts +8 -0
- package/build/import/type/mapped/mapped-key.mjs +7 -0
- package/build/import/type/mapped/mapped-result.d.mts +9 -0
- package/build/import/type/mapped/mapped-result.mjs +7 -0
- package/build/import/type/mapped/mapped.d.mts +39 -23
- package/build/import/type/mapped/mapped.mjs +65 -11
- package/build/import/type/omit/index.d.mts +1 -0
- package/build/import/type/omit/index.mjs +1 -0
- package/build/import/type/omit/omit-mapped-result.d.mts +15 -0
- package/build/import/type/omit/omit-mapped-result.mjs +20 -0
- package/build/import/type/omit/omit.d.mts +5 -2
- package/build/import/type/omit/omit.mjs +12 -6
- package/build/import/type/pick/index.d.mts +1 -0
- package/build/import/type/pick/index.mjs +1 -0
- package/build/import/type/pick/pick-mapped-result.d.mts +15 -0
- package/build/import/type/pick/pick-mapped-result.mjs +20 -0
- package/build/import/type/pick/pick.d.mts +5 -2
- package/build/import/type/pick/pick.mjs +12 -6
- package/build/import/type/record/record.mjs +4 -4
- package/build/import/type/type/json.d.mts +17 -8
- 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/transform/decode.mjs +5 -5
- package/build/import/value/transform/encode.mjs +5 -5
- package/build/require/compiler/compiler.js +2 -2
- package/build/require/errors/errors.js +2 -2
- package/build/require/index.d.ts +6 -6
- package/build/require/index.js +9 -8
- 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-from-result.d.ts +13 -0
- package/build/require/type/extends/extends-mapped-result-from-result.js +18 -0
- package/build/require/type/extends/extends-mapped-result.d.ts +17 -0
- package/build/require/type/extends/extends-mapped-result.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 +3 -2
- package/build/require/type/indexed/index.js +3 -2
- package/build/require/type/indexed/indexed-mapped-result.d.ts +16 -0
- package/build/require/type/indexed/indexed-mapped-result.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 → indexed-result.d.ts} +2 -2
- package/build/require/type/indexed/{indexed-type.js → indexed-result.js} +3 -3
- package/build/require/type/indexed/indexed.d.ts +7 -4
- package/build/require/type/indexed/indexed.js +8 -7
- package/build/require/type/intrinsic/capitalize.d.ts +4 -0
- package/build/require/type/intrinsic/capitalize.js +9 -0
- package/build/require/type/intrinsic/index.d.ts +5 -0
- package/build/require/type/intrinsic/index.js +5 -0
- package/build/require/type/intrinsic/intrinsic-mapped-result.d.ts +15 -0
- package/build/require/type/intrinsic/intrinsic-mapped-result.js +25 -0
- package/build/require/type/intrinsic/intrinsic.d.ts +9 -14
- package/build/require/type/intrinsic/intrinsic.js +10 -25
- package/build/require/type/intrinsic/lowercase.d.ts +4 -0
- package/build/require/type/intrinsic/lowercase.js +9 -0
- package/build/require/type/intrinsic/uncapitalize.d.ts +4 -0
- package/build/require/type/intrinsic/uncapitalize.js +9 -0
- package/build/require/type/intrinsic/uppercase.d.ts +4 -0
- package/build/require/type/intrinsic/uppercase.js +9 -0
- 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/index.d.ts +2 -0
- package/build/require/type/mapped/index.js +2 -0
- package/build/require/type/mapped/mapped-key.d.ts +8 -0
- package/build/require/type/mapped/mapped-key.js +11 -0
- package/build/require/type/mapped/mapped-result.d.ts +9 -0
- package/build/require/type/mapped/mapped-result.js +11 -0
- package/build/require/type/mapped/mapped.d.ts +39 -23
- package/build/require/type/mapped/mapped.js +65 -11
- package/build/require/type/omit/index.d.ts +1 -0
- package/build/require/type/omit/index.js +1 -0
- package/build/require/type/omit/omit-mapped-result.d.ts +15 -0
- package/build/require/type/omit/omit-mapped-result.js +24 -0
- package/build/require/type/omit/omit.d.ts +5 -2
- package/build/require/type/omit/omit.js +10 -4
- package/build/require/type/pick/index.d.ts +1 -0
- package/build/require/type/pick/index.js +1 -0
- package/build/require/type/pick/pick-mapped-result.d.ts +15 -0
- package/build/require/type/pick/pick-mapped-result.js +24 -0
- package/build/require/type/pick/pick.d.ts +5 -2
- package/build/require/type/pick/pick.js +10 -4
- package/build/require/type/record/record.js +2 -2
- package/build/require/type/type/json.d.ts +17 -8
- 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/transform/decode.js +3 -3
- package/build/require/value/transform/encode.js +3 -3
- package/package.json +1 -1
- package/readme.md +115 -47
- 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,11 +3,11 @@ 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 { IndexPropertyKeys } 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';
|
|
10
|
-
import {
|
|
10
|
+
import { TInteger as IsIntegerType, TLiteral as IsLiteralType, TNumber as IsNumberType, TString as IsStringType, TTemplateLiteral as IsTemplateLiteralType, TUnion as IsUnionType, } from '../guard/type.mjs';
|
|
11
11
|
function FromPattern(pattern, T) {
|
|
12
12
|
return { [Kind]: 'Record', type: 'object', patternProperties: { [pattern]: CloneType(T) } };
|
|
13
13
|
}
|
|
@@ -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(IndexPropertyKeys(K), T)
|
|
22
22
|
: FromPattern(K.pattern, T));
|
|
23
23
|
}
|
|
24
24
|
function FromUnionKey(K, T) {
|
|
25
|
-
return FromKeys(
|
|
25
|
+
return FromKeys(IndexPropertyKeys(Union(K)), T);
|
|
26
26
|
}
|
|
27
27
|
function FromLiteralKey(K, T) {
|
|
28
28
|
return FromKeys([K.toString()], T);
|
|
@@ -6,23 +6,25 @@ 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 TExtendsMappedResult, type TExtendsMappedResultFromResult } from '../extends/index.mjs';
|
|
10
10
|
import { type TExtract } from '../extract/index.mjs';
|
|
11
|
-
import { TIndex, type
|
|
11
|
+
import { TIndex, type TIndexPropertyKeys, type TIndexMappedResult } 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 TMappedFunction, 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
|
-
import { type TOmit } from '../omit/index.mjs';
|
|
24
|
+
import { type TOmit, type TOmitMappedResult } from '../omit/index.mjs';
|
|
23
25
|
import { type TOptional } from '../optional/index.mjs';
|
|
24
26
|
import { type TPartial } from '../partial/index.mjs';
|
|
25
|
-
import { type TPick } from '../pick/index.mjs';
|
|
27
|
+
import { type TPick, type TPickMappedResult } from '../pick/index.mjs';
|
|
26
28
|
import { type TReadonly } from '../readonly/index.mjs';
|
|
27
29
|
import { type TReadonlyOptional } from '../readonly-optional/index.mjs';
|
|
28
30
|
import { type RecordResolve } from '../record/index.mjs';
|
|
@@ -51,25 +53,32 @@ 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): TExtendsMappedResultFromResult<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): TExtendsMappedResult<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): TIndexMappedResult<T, K>;
|
|
62
|
+
Index<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<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[] = TIndexPropertyKeys<K>, F extends TMappedFunction<I> = TMappedFunction<I>, R extends TMapped<I, F> = TMapped<I, F>>(key: K, map: F, options?: ObjectOptions): R;
|
|
70
|
+
Mapped<K extends PropertyKey[], F extends TMappedFunction<K> = TMappedFunction<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
|
|
76
|
+
Omit<T extends TSchema, K extends TMappedKey>(T: T, K: K): TOmitMappedResult<T, K>;
|
|
77
|
+
Omit<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TOmit<T, I>;
|
|
70
78
|
Omit<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TOmit<T, K>;
|
|
71
79
|
Partial<T extends TSchema>(schema: T, options?: ObjectOptions): TPartial<T>;
|
|
72
|
-
Pick<T extends TSchema, K extends
|
|
80
|
+
Pick<T extends TSchema, K extends TMappedKey>(T: T, K: K): TPickMappedResult<T, K>;
|
|
81
|
+
Pick<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TPick<T, I>;
|
|
73
82
|
Pick<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TPick<T, K>;
|
|
74
83
|
Record<K extends TSchema, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): RecordResolve<K, T>;
|
|
75
84
|
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;
|
|
@@ -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 { Index } 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(Index(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]) }
|
|
@@ -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 { Index } 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(Index(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]) }
|
|
@@ -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();
|
package/build/require/index.d.ts
CHANGED
|
@@ -21,25 +21,25 @@ export { Extends, type TExtends, ExtendsCheck, ExtendsResult, ExtendsUndefinedCh
|
|
|
21
21
|
export { Extract, type TExtract } from './type/extract/index';
|
|
22
22
|
export { Function, type TFunction } from './type/function/index';
|
|
23
23
|
export { Increment, type Assert, type AssertType, type AssertRest, type AssertProperties, type Ensure, type Evaluate, type TupleToIntersect, type TupleToUnion, type UnionToTuple } from './type/helpers/index';
|
|
24
|
-
export { Index, type TIndex,
|
|
24
|
+
export { Index, IndexPropertyKeys, IndexMappedResult, type TIndex, type TIndexPropertyKeys, type TIndexMappedResult } from './type/indexed/index';
|
|
25
25
|
export { InstanceType, type TInstanceType } from './type/instance-type/index';
|
|
26
26
|
export { Integer, type TInteger, type IntegerOptions } from './type/integer/index';
|
|
27
27
|
export { Intersect, type TIntersect, type IntersectOptions } from './type/intersect/index';
|
|
28
28
|
export { Iterator, type TIterator } from './type/iterator/index';
|
|
29
|
-
export { Capitalize, type TCapitalize, Lowercase, type TLowercase, Uncapitalize, type TUncapitalize, Uppercase, type TUppercase
|
|
30
|
-
export { KeyOf, type TKeyOf,
|
|
29
|
+
export { Intrinsic, type TIntrinsic, Capitalize, type TCapitalize, Lowercase, type TLowercase, Uncapitalize, type TUncapitalize, Uppercase, type TUppercase } from './type/intrinsic/index';
|
|
30
|
+
export { KeyOf, type TKeyOf, KeyOfPropertyKeys, KeyOfPattern } from './type/keyof/index';
|
|
31
31
|
export { Literal, type TLiteral } from './type/literal/index';
|
|
32
|
-
export { Mapped, type
|
|
32
|
+
export { Mapped, MappedKey, MappedResult, type TMapped, type TMappedKey, type TMappedResult, type TMappedFunction } from './type/mapped/index';
|
|
33
33
|
export { Never, type TNever } from './type/never/index';
|
|
34
34
|
export { Not, type TNot } from './type/not/index';
|
|
35
35
|
export { Null, type TNull } from './type/null/index';
|
|
36
36
|
export { Number, type TNumber, type NumberOptions } from './type/number/index';
|
|
37
37
|
export { Object, type TObject, type TProperties, type ObjectOptions } from './type/object/index';
|
|
38
|
-
export { Omit, type TOmit } from './type/omit/index';
|
|
38
|
+
export { Omit, type TOmit, type TOmitMappedResult } from './type/omit/index';
|
|
39
39
|
export { Optional, type TOptional } from './type/optional/index';
|
|
40
40
|
export { Parameters, type TParameters } from './type/parameters/index';
|
|
41
41
|
export { Partial, type TPartial } from './type/partial/index';
|
|
42
|
-
export { Pick, type TPick } from './type/pick/index';
|
|
42
|
+
export { Pick, type TPick, type TPickMappedResult } from './type/pick/index';
|
|
43
43
|
export { Promise, type TPromise } from './type/promise/index';
|
|
44
44
|
export { Readonly, type TReadonly } from './type/readonly/index';
|
|
45
45
|
export { ReadonlyOptional, type TReadonlyOptional } from './type/readonly-optional/index';
|
package/build/require/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.JavaScriptTypeBuilder = exports.JsonTypeBuilder = exports.Type = exports.Void = exports.Unsafe = exports.Unknown = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.TransformEncodeBuilder = exports.TransformDecodeBuilder = exports.Transform = exports.TemplateLiteralGenerate = exports.TemplateLiteralParseExact = exports.TemplateLiteralParse = exports.IsTemplateLiteralFinite = exports.TemplateLiteral = exports.Symbol = exports.String = exports.Strict = exports.ReturnType = exports.Rest = exports.Required = exports.RegExp = exports.Ref = exports.Recursive = exports.Record = exports.ReadonlyOptional = exports.Readonly = exports.Promise = exports.Pick = exports.Partial = exports.Parameters = exports.Optional = exports.Omit = exports.Object = exports.Number = exports.Null = exports.Not = exports.Never = exports.
|
|
3
|
+
exports.Uppercase = exports.Uncapitalize = exports.Lowercase = exports.Capitalize = exports.Intrinsic = exports.Iterator = exports.Intersect = exports.Integer = exports.InstanceType = exports.IndexMappedResult = exports.IndexPropertyKeys = exports.Index = exports.Increment = exports.Function = exports.Extract = exports.ExtendsUndefinedCheck = exports.ExtendsResult = exports.ExtendsCheck = exports.Extends = exports.Exclude = exports.Enum = exports.Deref = exports.Date = exports.ConstructorParameters = exports.Constructor = exports.Const = exports.Composite = exports.Boolean = exports.BigInt = exports.Awaited = exports.AsyncIterator = exports.Array = exports.Any = exports.CloneRest = exports.CloneType = exports.ValueGuard = exports.TypeGuard = exports.FormatRegistry = exports.TypeRegistry = exports.PatternStringExact = exports.PatternString = exports.PatternNumberExact = exports.PatternNumber = exports.PatternBooleanExact = exports.PatternBoolean = exports.TransformKind = exports.OptionalKind = exports.ReadonlyKind = exports.Hint = exports.Kind = void 0;
|
|
4
|
+
exports.JavaScriptTypeBuilder = exports.JsonTypeBuilder = exports.Type = exports.Void = exports.Unsafe = exports.Unknown = exports.Union = exports.Undefined = exports.Uint8Array = exports.Tuple = exports.TransformEncodeBuilder = exports.TransformDecodeBuilder = exports.Transform = exports.TemplateLiteralGenerate = exports.TemplateLiteralParseExact = exports.TemplateLiteralParse = exports.IsTemplateLiteralFinite = exports.TemplateLiteral = exports.Symbol = exports.String = exports.Strict = exports.ReturnType = exports.Rest = exports.Required = exports.RegExp = exports.Ref = exports.Recursive = exports.Record = exports.ReadonlyOptional = exports.Readonly = exports.Promise = exports.Pick = exports.Partial = exports.Parameters = exports.Optional = exports.Omit = exports.Object = exports.Number = exports.Null = exports.Not = exports.Never = exports.MappedResult = exports.MappedKey = exports.Mapped = exports.Literal = exports.KeyOfPattern = exports.KeyOfPropertyKeys = exports.KeyOf = void 0;
|
|
5
5
|
var index_1 = require("./type/symbols/index");
|
|
6
6
|
Object.defineProperty(exports, "Kind", { enumerable: true, get: function () { return index_1.Kind; } });
|
|
7
7
|
Object.defineProperty(exports, "Hint", { enumerable: true, get: function () { return index_1.Hint; } });
|
|
@@ -65,8 +65,8 @@ var index_22 = require("./type/helpers/index");
|
|
|
65
65
|
Object.defineProperty(exports, "Increment", { enumerable: true, get: function () { return index_22.Increment; } });
|
|
66
66
|
var index_23 = require("./type/indexed/index");
|
|
67
67
|
Object.defineProperty(exports, "Index", { enumerable: true, get: function () { return index_23.Index; } });
|
|
68
|
-
Object.defineProperty(exports, "
|
|
69
|
-
Object.defineProperty(exports, "
|
|
68
|
+
Object.defineProperty(exports, "IndexPropertyKeys", { enumerable: true, get: function () { return index_23.IndexPropertyKeys; } });
|
|
69
|
+
Object.defineProperty(exports, "IndexMappedResult", { enumerable: true, get: function () { return index_23.IndexMappedResult; } });
|
|
70
70
|
var index_24 = require("./type/instance-type/index");
|
|
71
71
|
Object.defineProperty(exports, "InstanceType", { enumerable: true, get: function () { return index_24.InstanceType; } });
|
|
72
72
|
var index_25 = require("./type/integer/index");
|
|
@@ -76,20 +76,21 @@ Object.defineProperty(exports, "Intersect", { enumerable: true, get: function ()
|
|
|
76
76
|
var index_27 = require("./type/iterator/index");
|
|
77
77
|
Object.defineProperty(exports, "Iterator", { enumerable: true, get: function () { return index_27.Iterator; } });
|
|
78
78
|
var index_28 = require("./type/intrinsic/index");
|
|
79
|
+
Object.defineProperty(exports, "Intrinsic", { enumerable: true, get: function () { return index_28.Intrinsic; } });
|
|
79
80
|
Object.defineProperty(exports, "Capitalize", { enumerable: true, get: function () { return index_28.Capitalize; } });
|
|
80
81
|
Object.defineProperty(exports, "Lowercase", { enumerable: true, get: function () { return index_28.Lowercase; } });
|
|
81
82
|
Object.defineProperty(exports, "Uncapitalize", { enumerable: true, get: function () { return index_28.Uncapitalize; } });
|
|
82
83
|
Object.defineProperty(exports, "Uppercase", { enumerable: true, get: function () { return index_28.Uppercase; } });
|
|
83
|
-
Object.defineProperty(exports, "IntrinsicResolve", { enumerable: true, get: function () { return index_28.IntrinsicResolve; } });
|
|
84
84
|
var index_29 = require("./type/keyof/index");
|
|
85
85
|
Object.defineProperty(exports, "KeyOf", { enumerable: true, get: function () { return index_29.KeyOf; } });
|
|
86
|
-
Object.defineProperty(exports, "
|
|
87
|
-
Object.defineProperty(exports, "
|
|
88
|
-
Object.defineProperty(exports, "KeyOfTypeResolve", { enumerable: true, get: function () { return index_29.KeyOfTypeResolve; } });
|
|
86
|
+
Object.defineProperty(exports, "KeyOfPropertyKeys", { enumerable: true, get: function () { return index_29.KeyOfPropertyKeys; } });
|
|
87
|
+
Object.defineProperty(exports, "KeyOfPattern", { enumerable: true, get: function () { return index_29.KeyOfPattern; } });
|
|
89
88
|
var index_30 = require("./type/literal/index");
|
|
90
89
|
Object.defineProperty(exports, "Literal", { enumerable: true, get: function () { return index_30.Literal; } });
|
|
91
90
|
var index_31 = require("./type/mapped/index");
|
|
92
91
|
Object.defineProperty(exports, "Mapped", { enumerable: true, get: function () { return index_31.Mapped; } });
|
|
92
|
+
Object.defineProperty(exports, "MappedKey", { enumerable: true, get: function () { return index_31.MappedKey; } });
|
|
93
|
+
Object.defineProperty(exports, "MappedResult", { enumerable: true, get: function () { return index_31.MappedResult; } });
|
|
93
94
|
var index_32 = require("./type/never/index");
|
|
94
95
|
Object.defineProperty(exports, "Never", { enumerable: true, get: function () { return index_32.Never; } });
|
|
95
96
|
var index_33 = require("./type/not/index");
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { UnionToTuple, Assert, Evaluate } from '../helpers/index';
|
|
2
2
|
import { type TObject, type ObjectOptions } from '../object/index';
|
|
3
3
|
import { type TIntersect } from '../intersect/index';
|
|
4
|
-
import {
|
|
4
|
+
import { type TIndex } from '../indexed/index';
|
|
5
5
|
type CompositeKeys<T extends TObject[]> = T extends [infer L extends TObject, ...infer R extends TObject[]] ? keyof L['properties'] | CompositeKeys<R> : never;
|
|
6
6
|
type CompositeIndex<T extends TIntersect<TObject[]>, K extends string[]> = K extends [infer L extends string, ...infer R extends string[]] ? {
|
|
7
|
-
[_ in L]:
|
|
7
|
+
[_ in L]: TIndex<T, [L]>;
|
|
8
8
|
} & CompositeIndex<T, R> : {};
|
|
9
9
|
type CompositeReduce<T extends TObject[]> = UnionToTuple<CompositeKeys<T>> extends infer K ? Evaluate<CompositeIndex<TIntersect<T>, Assert<K, string[]>>> : {};
|
|
10
10
|
export type CompositeResolve<T extends TObject[]> = TIntersect<T> extends TIntersect ? TObject<CompositeReduce<T>> : TObject<{}>;
|
|
@@ -8,7 +8,7 @@ const index_4 = require("../indexed/index");
|
|
|
8
8
|
const type_1 = require("../clone/type");
|
|
9
9
|
function CompositeResolve(T) {
|
|
10
10
|
const intersect = (0, index_2.Intersect)(T, {});
|
|
11
|
-
const keys = (0, index_3.
|
|
11
|
+
const keys = (0, index_3.KeyOfPropertyKeys)(intersect);
|
|
12
12
|
const properties = keys.reduce((acc, key) => ({ ...acc, [key]: (0, index_4.Index)(intersect, [key]) }), {});
|
|
13
13
|
return (0, index_1.Object)(properties);
|
|
14
14
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TSchema } from '../schema/index';
|
|
2
|
+
import type { TProperties } from '../object/index';
|
|
3
|
+
import { type TMappedResult } from '../mapped/index';
|
|
4
|
+
import { type TExtends } from './extends';
|
|
5
|
+
type MappedResultExtendsPropertyKeys<K extends TProperties, U extends TSchema, L extends TSchema, R extends TSchema> = ({
|
|
6
|
+
[K2 in keyof K]: TExtends<K[K2], U, L, R>;
|
|
7
|
+
});
|
|
8
|
+
declare function MappedResultExtendsPropertyKeys<K extends TProperties, U extends TSchema, L extends TSchema, R extends TSchema>(K: K, U: U, L: L, R: R): MappedResultExtendsPropertyKeys<K, U, L, R>;
|
|
9
|
+
type MappedResultExtendsProperties<K extends TMappedResult, U extends TSchema, L extends TSchema, R extends TSchema> = (MappedResultExtendsPropertyKeys<K['properties'], U, L, R>);
|
|
10
|
+
declare function MappedResultExtendsProperties<K extends TMappedResult, U extends TSchema, L extends TSchema, R extends TSchema>(K: K, U: U, L: L, R: R): MappedResultExtendsProperties<K, U, L, R>;
|
|
11
|
+
export type TExtendsMappedResultFromResult<T extends TMappedResult, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = MappedResultExtendsProperties<T, U, L, R>> = (TMappedResult<P>);
|
|
12
|
+
export declare function ExtendsMappedResultFromResult<T extends TMappedResult, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = MappedResultExtendsProperties<T, U, L, R>>(T: T, U: U, L: L, R: R): TMappedResult<P>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtendsMappedResultFromResult = void 0;
|
|
4
|
+
const index_1 = require("../mapped/index");
|
|
5
|
+
const extends_1 = require("./extends");
|
|
6
|
+
function MappedResultExtendsPropertyKeys(K, U, L, R) {
|
|
7
|
+
return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => {
|
|
8
|
+
return { ...Acc, [K2]: (0, extends_1.Extends)(K[K2], U, L, R) };
|
|
9
|
+
}, {});
|
|
10
|
+
}
|
|
11
|
+
function MappedResultExtendsProperties(K, U, L, R) {
|
|
12
|
+
return MappedResultExtendsPropertyKeys(K.properties, U, L, R);
|
|
13
|
+
}
|
|
14
|
+
function ExtendsMappedResultFromResult(T, U, L, R) {
|
|
15
|
+
const P = MappedResultExtendsProperties(T, U, L, R);
|
|
16
|
+
return (0, index_1.MappedResult)(P);
|
|
17
|
+
}
|
|
18
|
+
exports.ExtendsMappedResultFromResult = ExtendsMappedResultFromResult;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TSchema } from '../schema/index';
|
|
2
|
+
import type { TProperties } from '../object/index';
|
|
3
|
+
import type { Assert } from '../helpers/index';
|
|
4
|
+
import { type TMappedResult, type TMappedKey } from '../mapped/index';
|
|
5
|
+
import { TLiteral, TLiteralValue } from '../literal/index';
|
|
6
|
+
import { type TExtends } from './extends';
|
|
7
|
+
type MappedExtendsPropertyKey<K extends PropertyKey, U extends TSchema, L extends TSchema, R extends TSchema> = {
|
|
8
|
+
[_ in K]: TExtends<TLiteral<Assert<K, TLiteralValue>>, U, L, R>;
|
|
9
|
+
};
|
|
10
|
+
declare function MappedExtendsPropertyKey<K extends PropertyKey, U extends TSchema, L extends TSchema, R extends TSchema>(K: K, U: U, L: L, R: R): MappedExtendsPropertyKey<K, U, L, R>;
|
|
11
|
+
type MappedExtendsPropertyKeys<K extends PropertyKey[], U extends TSchema, L extends TSchema, R extends TSchema> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? MappedExtendsPropertyKey<LK, U, L, R> & MappedExtendsPropertyKeys<RK, U, L, R> : {});
|
|
12
|
+
declare function MappedExtendsPropertyKeys<K extends PropertyKey[], U extends TSchema, L extends TSchema, R extends TSchema>(K: [...K], U: U, L: L, R: R): MappedExtendsPropertyKeys<K, U, L, R>;
|
|
13
|
+
type MappedExtendsProperties<K extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema> = (MappedExtendsPropertyKeys<K['keys'], U, L, R>);
|
|
14
|
+
declare function MappedExtendsProperties<K extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema>(K: K, U: U, L: L, R: R): MappedExtendsProperties<K, U, L, R>;
|
|
15
|
+
export type TExtendsMappedResult<T extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = MappedExtendsProperties<T, U, L, R>> = (TMappedResult<P>);
|
|
16
|
+
export declare function ExtendsMappedResult<T extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = MappedExtendsProperties<T, U, L, R>>(T: T, U: U, L: L, R: R): TMappedResult<P>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtendsMappedResult = void 0;
|
|
4
|
+
const index_1 = require("../mapped/index");
|
|
5
|
+
const index_2 = require("../literal/index");
|
|
6
|
+
const extends_1 = require("./extends");
|
|
7
|
+
function MappedExtendsPropertyKey(K, U, L, R) {
|
|
8
|
+
return {
|
|
9
|
+
[K]: (0, extends_1.Extends)((0, index_2.Literal)(K), U, L, R)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function MappedExtendsPropertyKeys(K, U, L, R) {
|
|
13
|
+
const [LK, ...RK] = K;
|
|
14
|
+
return (K.length > 0
|
|
15
|
+
? { ...MappedExtendsPropertyKey(LK, U, L, R), ...MappedExtendsPropertyKeys(RK, U, L, R) }
|
|
16
|
+
: {});
|
|
17
|
+
}
|
|
18
|
+
function MappedExtendsProperties(K, U, L, R) {
|
|
19
|
+
return MappedExtendsPropertyKeys(K.keys, U, L, R);
|
|
20
|
+
}
|
|
21
|
+
function ExtendsMappedResult(T, U, L, R) {
|
|
22
|
+
const P = MappedExtendsProperties(T, U, L, R);
|
|
23
|
+
return (0, index_1.MappedResult)(P);
|
|
24
|
+
}
|
|
25
|
+
exports.ExtendsMappedResult = ExtendsMappedResult;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index';
|
|
2
2
|
import type { Static } from '../static/index';
|
|
3
3
|
import { type TUnion } from '../union/index';
|
|
4
|
+
import { TMappedKey, TMappedResult } from '../mapped/index';
|
|
4
5
|
import { UnionToTuple } from '../helpers/index';
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import { type TExtendsMappedResult } from './extends-mapped-result';
|
|
7
|
+
import { type TExtendsMappedResultFromResult } from './extends-mapped-result-from-result';
|
|
8
|
+
type ExtendsResolve<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema> = ((Static<L> extends Static<R> ? T : U) extends infer O extends TSchema ? UnionToTuple<O> extends [infer X extends TSchema, infer Y extends TSchema] ? TUnion<[X, Y]> : O : never);
|
|
9
|
+
declare function ExtendsResolve<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema>(left: L, right: R, trueType: T, falseType: U): ExtendsResolve<L, R, T, U>;
|
|
7
10
|
export type TExtends<L extends TSchema, R extends TSchema, T extends TSchema, F extends TSchema> = ExtendsResolve<L, R, T, F>;
|
|
11
|
+
export declare function Extends<L extends TMappedResult, R extends TSchema, T extends TSchema, F extends TSchema>(L: L, R: R, T: T, F: F, options?: SchemaOptions): TExtendsMappedResultFromResult<L, R, T, F>;
|
|
12
|
+
export declare function Extends<L extends TMappedKey, R extends TSchema, T extends TSchema, F extends TSchema>(L: L, R: R, T: T, F: F, options?: SchemaOptions): TExtendsMappedResult<L, R, T, F>;
|
|
8
13
|
export declare function 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>;
|
|
14
|
+
export {};
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Extends =
|
|
3
|
+
exports.Extends = void 0;
|
|
4
|
+
const type_1 = require("../guard/type");
|
|
4
5
|
const index_1 = require("../union/index");
|
|
5
6
|
const extends_check_1 = require("./extends-check");
|
|
6
|
-
const
|
|
7
|
+
const type_2 = require("../clone/type");
|
|
8
|
+
const extends_mapped_result_1 = require("./extends-mapped-result");
|
|
9
|
+
const extends_mapped_result_from_result_1 = require("./extends-mapped-result-from-result");
|
|
7
10
|
function ExtendsResolve(left, right, trueType, falseType) {
|
|
8
11
|
const R = (0, extends_check_1.ExtendsCheck)(left, right);
|
|
9
12
|
return (R === extends_check_1.ExtendsResult.Union ? (0, index_1.Union)([trueType, falseType]) :
|
|
10
13
|
R === extends_check_1.ExtendsResult.True ? trueType :
|
|
11
14
|
falseType);
|
|
12
15
|
}
|
|
13
|
-
exports.ExtendsResolve = ExtendsResolve;
|
|
14
16
|
function Extends(L, R, T, F, options = {}) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
return ((0, type_1.TMappedResult)(L) ? (0, type_2.CloneType)((0, extends_mapped_result_from_result_1.ExtendsMappedResultFromResult)(L, R, T, F), options) :
|
|
18
|
+
(0, type_1.TMappedKey)(L) ? (0, type_2.CloneType)((0, extends_mapped_result_1.ExtendsMappedResult)(L, R, T, F), options) :
|
|
19
|
+
(0, type_2.CloneType)(ExtendsResolve(L, R, T, F), options));
|
|
17
20
|
}
|
|
18
21
|
exports.Extends = Extends;
|
|
@@ -15,5 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./extends-check"), exports);
|
|
18
|
+
__exportStar(require("./extends-mapped-result-from-result"), exports);
|
|
19
|
+
__exportStar(require("./extends-mapped-result"), exports);
|
|
18
20
|
__exportStar(require("./extends-undefined"), exports);
|
|
19
21
|
__exportStar(require("./extends"), exports);
|
|
@@ -15,11 +15,12 @@ import type { TInteger } from '../integer/index';
|
|
|
15
15
|
import type { TIntersect } from '../intersect/index';
|
|
16
16
|
import type { TIterator } from '../iterator/index';
|
|
17
17
|
import type { TLiteral } from '../literal/index';
|
|
18
|
+
import type { TMappedKey, TMappedResult } from '../mapped/index';
|
|
18
19
|
import type { TNever } from '../never/index';
|
|
19
20
|
import type { TNot } from '../not/index';
|
|
20
21
|
import type { TNull } from '../null/index';
|
|
21
22
|
import type { TNumber } from '../number/index';
|
|
22
|
-
import type { TObject } from '../object/index';
|
|
23
|
+
import type { TObject, TProperties } from '../object/index';
|
|
23
24
|
import type { TOptional } from '../optional/index';
|
|
24
25
|
import type { TPromise } from '../promise/index';
|
|
25
26
|
import type { TReadonly } from '../readonly/index';
|
|
@@ -47,6 +48,7 @@ export declare function TConstructor(schema: unknown): schema is TConstructor;
|
|
|
47
48
|
export declare function TDate(schema: unknown): schema is TDate;
|
|
48
49
|
export declare function TFunction(schema: unknown): schema is TFunction;
|
|
49
50
|
export declare function TInteger(schema: unknown): schema is TInteger;
|
|
51
|
+
export declare function TProperties(schema: unknown): schema is TProperties;
|
|
50
52
|
export declare function TIntersect(schema: unknown): schema is TIntersect;
|
|
51
53
|
export declare function TIterator(schema: unknown): schema is TIterator;
|
|
52
54
|
export declare function TKindOf<T extends string>(schema: unknown, kind: T): schema is Record<PropertyKey, unknown> & {
|
|
@@ -56,6 +58,8 @@ export declare function TLiteralString(schema: unknown): schema is TLiteral<stri
|
|
|
56
58
|
export declare function TLiteralNumber(schema: unknown): schema is TLiteral<number>;
|
|
57
59
|
export declare function TLiteralBoolean(schema: unknown): schema is TLiteral<boolean>;
|
|
58
60
|
export declare function TLiteral(schema: unknown): schema is TLiteral;
|
|
61
|
+
export declare function TMappedKey(schema: unknown): schema is TMappedKey;
|
|
62
|
+
export declare function TMappedResult(schema: unknown): schema is TMappedResult;
|
|
59
63
|
export declare function TNever(schema: unknown): schema is TNever;
|
|
60
64
|
export declare function TNot(schema: unknown): schema is TNot;
|
|
61
65
|
export declare function TNull(schema: unknown): schema is TNull;
|