@sinclair/typebox 0.32.0-dev-24 → 0.32.0-dev-25
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/index.d.mts +1 -1
- package/build/import/index.mjs +1 -1
- package/build/import/type/indexed/index.d.mts +1 -0
- package/build/import/type/indexed/index.mjs +1 -0
- package/build/import/type/indexed/indexed-from-mapped-result.d.mts +12 -0
- package/build/import/type/indexed/indexed-from-mapped-result.mjs +18 -0
- package/build/import/type/indexed/indexed.d.mts +4 -1
- package/build/import/type/indexed/indexed.mjs +6 -5
- package/build/import/type/type/json.d.mts +3 -1
- package/build/require/index.d.ts +1 -1
- package/build/require/index.js +4 -3
- package/build/require/type/indexed/index.d.ts +1 -0
- package/build/require/type/indexed/index.js +1 -0
- package/build/require/type/indexed/indexed-from-mapped-result.d.ts +12 -0
- package/build/require/type/indexed/indexed-from-mapped-result.js +23 -0
- package/build/require/type/indexed/indexed.d.ts +4 -1
- package/build/require/type/indexed/indexed.js +5 -4
- package/build/require/type/type/json.d.ts +3 -1
- package/package.json +1 -1
- package/readme.md +7 -7
package/build/import/index.d.mts
CHANGED
|
@@ -22,7 +22,7 @@ export { Extends, type TExtends, type ExtendsFromMappedResult, type ExtendsFromM
|
|
|
22
22
|
export { Extract, type TExtract, type TExtractFromMappedResult } from './type/extract/index.mjs';
|
|
23
23
|
export { Function, type TFunction } from './type/function/index.mjs';
|
|
24
24
|
export { Increment, type Assert, type AssertType, type AssertRest, type AssertProperties, type Ensure, type Evaluate, type TupleToIntersect, type TupleToUnion, type UnionToTuple } from './type/helpers/index.mjs';
|
|
25
|
-
export { Index, IndexPropertyKeys, IndexFromMappedKey, type TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey } from './type/indexed/index.mjs';
|
|
25
|
+
export { Index, IndexPropertyKeys, IndexFromMappedKey, IndexFromMappedResult, type TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey, type TIndexFromMappedResult } from './type/indexed/index.mjs';
|
|
26
26
|
export { InstanceType, type TInstanceType } from './type/instance-type/index.mjs';
|
|
27
27
|
export { Integer, type TInteger, type IntegerOptions } from './type/integer/index.mjs';
|
|
28
28
|
export { Intersect, IntersectEvaluated, type TIntersect, type TIntersectEvaluated, type IntersectOptions } from './type/intersect/index.mjs';
|
package/build/import/index.mjs
CHANGED
|
@@ -28,7 +28,7 @@ export { Extends, ExtendsCheck, ExtendsResult, ExtendsUndefinedCheck } from './t
|
|
|
28
28
|
export { Extract } from './type/extract/index.mjs';
|
|
29
29
|
export { Function } from './type/function/index.mjs';
|
|
30
30
|
export { Increment } from './type/helpers/index.mjs';
|
|
31
|
-
export { Index, IndexPropertyKeys, IndexFromMappedKey } from './type/indexed/index.mjs';
|
|
31
|
+
export { Index, IndexPropertyKeys, IndexFromMappedKey, IndexFromMappedResult } from './type/indexed/index.mjs';
|
|
32
32
|
export { InstanceType } from './type/instance-type/index.mjs';
|
|
33
33
|
export { Integer } from './type/integer/index.mjs';
|
|
34
34
|
export { Intersect, IntersectEvaluated } from './type/intersect/index.mjs';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import type { TProperties } from '../object/index.mjs';
|
|
3
|
+
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
|
+
import { type TIndex } from './index.mjs';
|
|
5
|
+
import { TIndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
6
|
+
type TFromProperties<T extends TSchema, P extends TProperties> = ({
|
|
7
|
+
[K2 in keyof P]: TIndex<T, TIndexPropertyKeys<P[K2]>>;
|
|
8
|
+
});
|
|
9
|
+
type TFromMappedResult<T extends TSchema, K extends TMappedResult> = (TFromProperties<T, K['properties']>);
|
|
10
|
+
export type TIndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>> = (TMappedResult<P>);
|
|
11
|
+
export declare function IndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>>(T: T, R: R, options: SchemaOptions): TMappedResult<P>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
+
import { Index } from './index.mjs';
|
|
3
|
+
import { IndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
4
|
+
// prettier-ignore
|
|
5
|
+
function FromProperties(T, P, options) {
|
|
6
|
+
return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
|
|
7
|
+
return { ...Acc, [K2]: Index(T, IndexPropertyKeys(P[K2]), options) };
|
|
8
|
+
}, {});
|
|
9
|
+
}
|
|
10
|
+
// prettier-ignore
|
|
11
|
+
function FromMappedResult(T, R, options) {
|
|
12
|
+
return FromProperties(T, R.properties, options);
|
|
13
|
+
}
|
|
14
|
+
// prettier-ignore
|
|
15
|
+
export function IndexFromMappedResult(T, R, options) {
|
|
16
|
+
const P = FromMappedResult(T, R, options);
|
|
17
|
+
return MappedResult(P);
|
|
18
|
+
}
|
|
@@ -4,7 +4,7 @@ import { type Assert } from '../helpers/index.mjs';
|
|
|
4
4
|
import { type TNever } from '../never/index.mjs';
|
|
5
5
|
import { type TRecursive } from '../recursive/index.mjs';
|
|
6
6
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
7
|
-
import { type TMappedKey } from '../mapped/index.mjs';
|
|
7
|
+
import { TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
8
8
|
import { type TUnion } from '../union/index.mjs';
|
|
9
9
|
import { type TTuple } from '../tuple/index.mjs';
|
|
10
10
|
import { type TArray } from '../array/index.mjs';
|
|
@@ -12,6 +12,7 @@ import { type TIntersectEvaluated } from '../intersect/index.mjs';
|
|
|
12
12
|
import { type TUnionEvaluated } from '../union/index.mjs';
|
|
13
13
|
import { type TIndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
14
14
|
import { type TIndexFromMappedKey } from './indexed-from-mapped-key.mjs';
|
|
15
|
+
import { type TIndexFromMappedResult } from './indexed-from-mapped-result.mjs';
|
|
15
16
|
type TFromRest<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Acc, Assert<TFromKey<L, K>, TSchema>]> : Acc);
|
|
16
17
|
type TFromIntersectRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? TFromIntersectRest<R, [...Acc]> : TFromIntersectRest<R, [...Acc, L]> : Acc);
|
|
17
18
|
type TFromIntersect<T extends TSchema[], K extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<T, K>>>);
|
|
@@ -27,6 +28,8 @@ type FromSchema<T extends TSchema, K extends PropertyKey[]> = (TUnionEvaluated<T
|
|
|
27
28
|
declare function FromSchema<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): FromSchema<T, K>;
|
|
28
29
|
export type TIndex<T extends TSchema, K extends PropertyKey[]> = (FromSchema<T, K>);
|
|
29
30
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
31
|
+
export declare function Index<T extends TSchema, K extends TMappedResult>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedResult<T, K>;
|
|
32
|
+
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
30
33
|
export declare function Index<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedKey<T, K>;
|
|
31
34
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
32
35
|
export declare function Index<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TIndex<T, I>;
|
|
@@ -4,11 +4,11 @@ import { UnionEvaluated } from '../union/index.mjs';
|
|
|
4
4
|
import { CloneType } from '../clone/type.mjs';
|
|
5
5
|
import { IndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
6
6
|
import { IndexFromMappedKey } from './indexed-from-mapped-key.mjs';
|
|
7
|
+
import { IndexFromMappedResult } from './indexed-from-mapped-result.mjs';
|
|
7
8
|
// ------------------------------------------------------------------
|
|
8
9
|
// TypeGuard
|
|
9
10
|
// ------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
import { IsArray, IsIntersect, IsObject, IsMappedKey, IsNever, IsSchema, IsTuple, IsUnion } from '../guard/type.mjs';
|
|
11
|
+
import { IsArray, IsIntersect, IsObject, IsMappedKey, IsMappedResult, IsNever, IsSchema, IsTuple, IsUnion } from '../guard/type.mjs';
|
|
12
12
|
// prettier-ignore
|
|
13
13
|
function FromRest(T, K, Acc = []) {
|
|
14
14
|
const [L, ...R] = T;
|
|
@@ -83,7 +83,8 @@ function FromSchema(T, K) {
|
|
|
83
83
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
84
84
|
export function Index(T, K, options = {}) {
|
|
85
85
|
// prettier-ignore
|
|
86
|
-
return (
|
|
87
|
-
|
|
88
|
-
CloneType(FromSchema(T, K), options)
|
|
86
|
+
return (IsMappedResult(K) ? CloneType(IndexFromMappedResult(T, K, options)) :
|
|
87
|
+
IsMappedKey(K) ? CloneType(IndexFromMappedKey(T, K, options)) :
|
|
88
|
+
IsSchema(K) ? CloneType(FromSchema(T, IndexPropertyKeys(K)), options) :
|
|
89
|
+
CloneType(FromSchema(T, K), options));
|
|
89
90
|
}
|
|
@@ -8,7 +8,7 @@ import { type TEnum, type TEnumKey, type TEnumValue } from '../enum/index.mjs';
|
|
|
8
8
|
import { type TExclude, type TExcludeFromMappedResult } from '../exclude/index.mjs';
|
|
9
9
|
import { type TExtends, type TExtendsFromMappedKey, type TExtendsFromMappedResult } from '../extends/index.mjs';
|
|
10
10
|
import { type TExtract, type TExtractFromMappedResult } from '../extract/index.mjs';
|
|
11
|
-
import { TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey } from '../indexed/index.mjs';
|
|
11
|
+
import { TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey, type TIndexFromMappedResult } from '../indexed/index.mjs';
|
|
12
12
|
import { type IntegerOptions, type TInteger } from '../integer/index.mjs';
|
|
13
13
|
import { Intersect, type IntersectOptions } from '../intersect/index.mjs';
|
|
14
14
|
import { type TCapitalize, type TUncapitalize, type TLowercase, type TUppercase } from '../intrinsic/index.mjs';
|
|
@@ -93,6 +93,8 @@ export declare class JsonTypeBuilder {
|
|
|
93
93
|
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
94
94
|
Extract<L extends TSchema, R extends TSchema>(type: L, union: R, options?: SchemaOptions): TExtract<L, R>;
|
|
95
95
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
96
|
+
Index<T extends TSchema, K extends TMappedResult>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedResult<T, K>;
|
|
97
|
+
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
96
98
|
Index<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedKey<T, K>;
|
|
97
99
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
98
100
|
Index<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TIndex<T, I>;
|
package/build/require/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export { Extends, type TExtends, type ExtendsFromMappedResult, type ExtendsFromM
|
|
|
22
22
|
export { Extract, type TExtract, type TExtractFromMappedResult } from './type/extract/index';
|
|
23
23
|
export { Function, type TFunction } from './type/function/index';
|
|
24
24
|
export { Increment, type Assert, type AssertType, type AssertRest, type AssertProperties, type Ensure, type Evaluate, type TupleToIntersect, type TupleToUnion, type UnionToTuple } from './type/helpers/index';
|
|
25
|
-
export { Index, IndexPropertyKeys, IndexFromMappedKey, type TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey } from './type/indexed/index';
|
|
25
|
+
export { Index, IndexPropertyKeys, IndexFromMappedKey, IndexFromMappedResult, type TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey, type TIndexFromMappedResult } from './type/indexed/index';
|
|
26
26
|
export { InstanceType, type TInstanceType } from './type/instance-type/index';
|
|
27
27
|
export { Integer, type TInteger, type IntegerOptions } from './type/integer/index';
|
|
28
28
|
export { Intersect, IntersectEvaluated, type TIntersect, type TIntersectEvaluated, type IntersectOptions } from './type/intersect/index';
|
package/build/require/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.JavaScriptTypeBuilder = exports.JsonTypeBuilder = exports.Type = exports.Void = exports.Unsafe = exports.Unknown = exports.UnionEvaluated = void 0;
|
|
4
|
+
exports.IntrinsicFromMappedKey = exports.Intrinsic = exports.Iterator = exports.IntersectEvaluated = exports.Intersect = exports.Integer = exports.InstanceType = exports.IndexFromMappedResult = exports.IndexFromMappedKey = 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.TypeBoxError = 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;
|
|
5
|
+
exports.Undefined = exports.Uint8Array = exports.Tuple = exports.TransformEncodeBuilder = exports.TransformDecodeBuilder = exports.Transform = exports.TemplateLiteralExpressionGenerate = exports.TemplateLiteralGenerate = exports.TemplateLiteralParseExact = exports.TemplateLiteralParse = exports.IsTemplateLiteralExpressionFinite = 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.ReadonlyFromMappedResult = exports.Readonly = exports.Promise = exports.Pick = exports.PartialFromMappedResult = exports.Partial = exports.Parameters = exports.OptionalFromMappedResult = 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 = exports.Uppercase = exports.Uncapitalize = exports.Lowercase = exports.Capitalize = void 0;
|
|
6
|
+
exports.JavaScriptTypeBuilder = exports.JsonTypeBuilder = exports.Type = exports.Void = exports.Unsafe = exports.Unknown = exports.UnionEvaluated = exports.Union = void 0;
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// Infrastructure
|
|
9
9
|
// ------------------------------------------------------------------
|
|
@@ -77,6 +77,7 @@ var index_24 = require("./type/indexed/index");
|
|
|
77
77
|
Object.defineProperty(exports, "Index", { enumerable: true, get: function () { return index_24.Index; } });
|
|
78
78
|
Object.defineProperty(exports, "IndexPropertyKeys", { enumerable: true, get: function () { return index_24.IndexPropertyKeys; } });
|
|
79
79
|
Object.defineProperty(exports, "IndexFromMappedKey", { enumerable: true, get: function () { return index_24.IndexFromMappedKey; } });
|
|
80
|
+
Object.defineProperty(exports, "IndexFromMappedResult", { enumerable: true, get: function () { return index_24.IndexFromMappedResult; } });
|
|
80
81
|
var index_25 = require("./type/instance-type/index");
|
|
81
82
|
Object.defineProperty(exports, "InstanceType", { enumerable: true, get: function () { return index_25.InstanceType; } });
|
|
82
83
|
var index_26 = require("./type/integer/index");
|
|
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
__exportStar(require("./indexed-from-mapped-key"), exports);
|
|
19
|
+
__exportStar(require("./indexed-from-mapped-result"), exports);
|
|
19
20
|
__exportStar(require("./indexed-property-keys"), exports);
|
|
20
21
|
__exportStar(require("./indexed"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TSchema, SchemaOptions } from '../schema/index';
|
|
2
|
+
import type { TProperties } from '../object/index';
|
|
3
|
+
import { type TMappedResult } from '../mapped/index';
|
|
4
|
+
import { type TIndex } from './index';
|
|
5
|
+
import { TIndexPropertyKeys } from './indexed-property-keys';
|
|
6
|
+
type TFromProperties<T extends TSchema, P extends TProperties> = ({
|
|
7
|
+
[K2 in keyof P]: TIndex<T, TIndexPropertyKeys<P[K2]>>;
|
|
8
|
+
});
|
|
9
|
+
type TFromMappedResult<T extends TSchema, K extends TMappedResult> = (TFromProperties<T, K['properties']>);
|
|
10
|
+
export type TIndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>> = (TMappedResult<P>);
|
|
11
|
+
export declare function IndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>>(T: T, R: R, options: SchemaOptions): TMappedResult<P>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.IndexFromMappedResult = void 0;
|
|
5
|
+
const index_1 = require("../mapped/index");
|
|
6
|
+
const index_2 = require("./index");
|
|
7
|
+
const indexed_property_keys_1 = require("./indexed-property-keys");
|
|
8
|
+
// prettier-ignore
|
|
9
|
+
function FromProperties(T, P, options) {
|
|
10
|
+
return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
|
|
11
|
+
return { ...Acc, [K2]: (0, index_2.Index)(T, (0, indexed_property_keys_1.IndexPropertyKeys)(P[K2]), options) };
|
|
12
|
+
}, {});
|
|
13
|
+
}
|
|
14
|
+
// prettier-ignore
|
|
15
|
+
function FromMappedResult(T, R, options) {
|
|
16
|
+
return FromProperties(T, R.properties, options);
|
|
17
|
+
}
|
|
18
|
+
// prettier-ignore
|
|
19
|
+
function IndexFromMappedResult(T, R, options) {
|
|
20
|
+
const P = FromMappedResult(T, R, options);
|
|
21
|
+
return (0, index_1.MappedResult)(P);
|
|
22
|
+
}
|
|
23
|
+
exports.IndexFromMappedResult = IndexFromMappedResult;
|
|
@@ -4,7 +4,7 @@ import { type Assert } from '../helpers/index';
|
|
|
4
4
|
import { type TNever } from '../never/index';
|
|
5
5
|
import { type TRecursive } from '../recursive/index';
|
|
6
6
|
import { type TIntersect } from '../intersect/index';
|
|
7
|
-
import { type TMappedKey } from '../mapped/index';
|
|
7
|
+
import { TMappedResult, type TMappedKey } from '../mapped/index';
|
|
8
8
|
import { type TUnion } from '../union/index';
|
|
9
9
|
import { type TTuple } from '../tuple/index';
|
|
10
10
|
import { type TArray } from '../array/index';
|
|
@@ -12,6 +12,7 @@ import { type TIntersectEvaluated } from '../intersect/index';
|
|
|
12
12
|
import { type TUnionEvaluated } from '../union/index';
|
|
13
13
|
import { type TIndexPropertyKeys } from './indexed-property-keys';
|
|
14
14
|
import { type TIndexFromMappedKey } from './indexed-from-mapped-key';
|
|
15
|
+
import { type TIndexFromMappedResult } from './indexed-from-mapped-result';
|
|
15
16
|
type TFromRest<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Acc, Assert<TFromKey<L, K>, TSchema>]> : Acc);
|
|
16
17
|
type TFromIntersectRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? TFromIntersectRest<R, [...Acc]> : TFromIntersectRest<R, [...Acc, L]> : Acc);
|
|
17
18
|
type TFromIntersect<T extends TSchema[], K extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<T, K>>>);
|
|
@@ -27,6 +28,8 @@ type FromSchema<T extends TSchema, K extends PropertyKey[]> = (TUnionEvaluated<T
|
|
|
27
28
|
declare function FromSchema<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): FromSchema<T, K>;
|
|
28
29
|
export type TIndex<T extends TSchema, K extends PropertyKey[]> = (FromSchema<T, K>);
|
|
29
30
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
31
|
+
export declare function Index<T extends TSchema, K extends TMappedResult>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedResult<T, K>;
|
|
32
|
+
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
30
33
|
export declare function Index<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedKey<T, K>;
|
|
31
34
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
32
35
|
export declare function Index<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TIndex<T, I>;
|
|
@@ -8,10 +8,10 @@ const index_3 = require("../union/index");
|
|
|
8
8
|
const type_1 = require("../clone/type");
|
|
9
9
|
const indexed_property_keys_1 = require("./indexed-property-keys");
|
|
10
10
|
const indexed_from_mapped_key_1 = require("./indexed-from-mapped-key");
|
|
11
|
+
const indexed_from_mapped_result_1 = require("./indexed-from-mapped-result");
|
|
11
12
|
// ------------------------------------------------------------------
|
|
12
13
|
// TypeGuard
|
|
13
14
|
// ------------------------------------------------------------------
|
|
14
|
-
// prettier-ignore
|
|
15
15
|
const type_2 = require("../guard/type");
|
|
16
16
|
// prettier-ignore
|
|
17
17
|
function FromRest(T, K, Acc = []) {
|
|
@@ -87,8 +87,9 @@ function FromSchema(T, K) {
|
|
|
87
87
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
88
88
|
function Index(T, K, options = {}) {
|
|
89
89
|
// prettier-ignore
|
|
90
|
-
return ((0, type_2.
|
|
91
|
-
(0, type_2.
|
|
92
|
-
(0, type_1.CloneType)(FromSchema(T, K), options)
|
|
90
|
+
return ((0, type_2.IsMappedResult)(K) ? (0, type_1.CloneType)((0, indexed_from_mapped_result_1.IndexFromMappedResult)(T, K, options)) :
|
|
91
|
+
(0, type_2.IsMappedKey)(K) ? (0, type_1.CloneType)((0, indexed_from_mapped_key_1.IndexFromMappedKey)(T, K, options)) :
|
|
92
|
+
(0, type_2.IsSchema)(K) ? (0, type_1.CloneType)(FromSchema(T, (0, indexed_property_keys_1.IndexPropertyKeys)(K)), options) :
|
|
93
|
+
(0, type_1.CloneType)(FromSchema(T, K), options));
|
|
93
94
|
}
|
|
94
95
|
exports.Index = Index;
|
|
@@ -8,7 +8,7 @@ import { type TEnum, type TEnumKey, type TEnumValue } from '../enum/index';
|
|
|
8
8
|
import { type TExclude, type TExcludeFromMappedResult } from '../exclude/index';
|
|
9
9
|
import { type TExtends, type TExtendsFromMappedKey, type TExtendsFromMappedResult } from '../extends/index';
|
|
10
10
|
import { type TExtract, type TExtractFromMappedResult } from '../extract/index';
|
|
11
|
-
import { TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey } from '../indexed/index';
|
|
11
|
+
import { TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey, type TIndexFromMappedResult } from '../indexed/index';
|
|
12
12
|
import { type IntegerOptions, type TInteger } from '../integer/index';
|
|
13
13
|
import { Intersect, type IntersectOptions } from '../intersect/index';
|
|
14
14
|
import { type TCapitalize, type TUncapitalize, type TLowercase, type TUppercase } from '../intrinsic/index';
|
|
@@ -93,6 +93,8 @@ export declare class JsonTypeBuilder {
|
|
|
93
93
|
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
94
94
|
Extract<L extends TSchema, R extends TSchema>(type: L, union: R, options?: SchemaOptions): TExtract<L, R>;
|
|
95
95
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
96
|
+
Index<T extends TSchema, K extends TMappedResult>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedResult<T, K>;
|
|
97
|
+
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
96
98
|
Index<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedKey<T, K>;
|
|
97
99
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
98
100
|
Index<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TIndex<T, I>;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -913,13 +913,13 @@ const T = Type.Object({ // const T: TObject<{
|
|
|
913
913
|
|
|
914
914
|
const A = Type.Index(T, ['x']) // type A = T['x']
|
|
915
915
|
//
|
|
916
|
-
// ...
|
|
916
|
+
// ... evaluated as
|
|
917
917
|
//
|
|
918
918
|
// const A: TNumber
|
|
919
919
|
|
|
920
920
|
const B = Type.Index(T, ['x', 'y']) // type B = T['x' | 'y']
|
|
921
921
|
//
|
|
922
|
-
// ...
|
|
922
|
+
// ... evaluated as
|
|
923
923
|
//
|
|
924
924
|
// const B: TUnion<[
|
|
925
925
|
// TNumber,
|
|
@@ -928,7 +928,7 @@ const B = Type.Index(T, ['x', 'y']) // type B = T['x' | 'y']
|
|
|
928
928
|
|
|
929
929
|
const C = Type.Index(T, Type.KeyOf(T)) // type C = T[keyof T]
|
|
930
930
|
//
|
|
931
|
-
// ...
|
|
931
|
+
// ... evaluated as
|
|
932
932
|
//
|
|
933
933
|
// const C: TUnion<[
|
|
934
934
|
// TNumber,
|
|
@@ -1795,11 +1795,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1795
1795
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1796
1796
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1797
1797
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1798
|
-
│ typebox/compiler │ '
|
|
1799
|
-
│ typebox/errors │ ' 55.5 kb' │ ' 25.2 kb' │ '2.
|
|
1798
|
+
│ typebox/compiler │ '120.5 kb' │ ' 52.7 kb' │ '2.29 x' │
|
|
1799
|
+
│ typebox/errors │ ' 55.5 kb' │ ' 25.2 kb' │ '2.20 x' │
|
|
1800
1800
|
│ typebox/system │ ' 4.7 kb' │ ' 2.0 kb' │ '2.33 x' │
|
|
1801
|
-
│ typebox/value │ '
|
|
1802
|
-
│ typebox │ '
|
|
1801
|
+
│ typebox/value │ '147.4 kb' │ ' 62.2 kb' │ '2.37 x' │
|
|
1802
|
+
│ typebox │ ' 91.3 kb' │ ' 38.0 kb' │ '2.40 x' │
|
|
1803
1803
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1804
1804
|
```
|
|
1805
1805
|
|