@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
|
@@ -7,7 +7,7 @@ import { Hash } from '../value/hash/index.mjs';
|
|
|
7
7
|
import { Kind } from '../type/symbols/index.mjs';
|
|
8
8
|
import { TSchema as IsSchemaType } from '../type/guard/type.mjs';
|
|
9
9
|
import { TypeRegistry, FormatRegistry } from '../type/registry/index.mjs';
|
|
10
|
-
import {
|
|
10
|
+
import { KeyOfPattern } from '../type/keyof/index.mjs';
|
|
11
11
|
import { ExtendsUndefinedCheck } from '../type/extends/extends-undefined.mjs';
|
|
12
12
|
import { Never } from '../type/never/index.mjs';
|
|
13
13
|
export class TypeCheck {
|
|
@@ -238,12 +238,12 @@ export var TypeCompiler;
|
|
|
238
238
|
function* TIntersect(schema, references, value) {
|
|
239
239
|
const check1 = schema.allOf.map((schema) => CreateExpression(schema, references, value)).join(' && ');
|
|
240
240
|
if (schema.unevaluatedProperties === false) {
|
|
241
|
-
const keyCheck = CreateVariable(`${new RegExp(
|
|
241
|
+
const keyCheck = CreateVariable(`${new RegExp(KeyOfPattern(schema))};`);
|
|
242
242
|
const check2 = `Object.getOwnPropertyNames(${value}).every(key => ${keyCheck}.test(key))`;
|
|
243
243
|
yield `(${check1} && ${check2})`;
|
|
244
244
|
}
|
|
245
245
|
else if (IsSchemaType(schema.unevaluatedProperties)) {
|
|
246
|
-
const keyCheck = CreateVariable(`${new RegExp(
|
|
246
|
+
const keyCheck = CreateVariable(`${new RegExp(KeyOfPattern(schema))};`);
|
|
247
247
|
const check2 = `Object.getOwnPropertyNames(${value}).every(key => ${keyCheck}.test(key) || ${CreateExpression(schema.unevaluatedProperties, references, `${value}[key]`)})`;
|
|
248
248
|
yield `(${check1} && ${check2})`;
|
|
249
249
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IsArray, IsUint8Array, IsDate, IsPromise, IsFunction, IsAsyncIterator, IsIterator, IsBoolean, IsNumber, IsBigInt, IsString, IsSymbol, IsInteger, IsNull, IsUndefined } from '../value/guard/index.mjs';
|
|
2
2
|
import { TypeSystemPolicy } from '../system/index.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { KeyOfPattern } from '../type/keyof/index.mjs';
|
|
4
4
|
import { TypeRegistry, FormatRegistry } from '../type/registry/index.mjs';
|
|
5
5
|
import { ExtendsUndefinedCheck } from '../type/extends/extends-undefined.mjs';
|
|
6
6
|
import { GetErrorFunction } from './function.mjs';
|
|
@@ -224,7 +224,7 @@ function* TIntersect(schema, references, path, value) {
|
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
if (schema.unevaluatedProperties === false) {
|
|
227
|
-
const keyCheck = new RegExp(
|
|
227
|
+
const keyCheck = new RegExp(KeyOfPattern(schema));
|
|
228
228
|
for (const valueKey of Object.getOwnPropertyNames(value)) {
|
|
229
229
|
if (!keyCheck.test(valueKey)) {
|
|
230
230
|
yield Create(ValueErrorType.IntersectUnevaluatedProperties, schema, `${path}/${valueKey}`, value);
|
|
@@ -232,7 +232,7 @@ function* TIntersect(schema, references, path, value) {
|
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
if (typeof schema.unevaluatedProperties === 'object') {
|
|
235
|
-
const keyCheck = new RegExp(
|
|
235
|
+
const keyCheck = new RegExp(KeyOfPattern(schema));
|
|
236
236
|
for (const valueKey of Object.getOwnPropertyNames(value)) {
|
|
237
237
|
if (!keyCheck.test(valueKey)) {
|
|
238
238
|
const next = Visit(schema.unevaluatedProperties, references, `${path}/${valueKey}`, value[valueKey]).next();
|
package/build/import/index.d.mts
CHANGED
|
@@ -21,25 +21,25 @@ export { Extends, type TExtends, ExtendsCheck, ExtendsResult, ExtendsUndefinedCh
|
|
|
21
21
|
export { Extract, type TExtract } from './type/extract/index.mjs';
|
|
22
22
|
export { Function, type TFunction } from './type/function/index.mjs';
|
|
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.mjs';
|
|
24
|
-
export { Index, type TIndex,
|
|
24
|
+
export { Index, IndexPropertyKeys, IndexMappedResult, type TIndex, type TIndexPropertyKeys, type TIndexMappedResult } from './type/indexed/index.mjs';
|
|
25
25
|
export { InstanceType, type TInstanceType } from './type/instance-type/index.mjs';
|
|
26
26
|
export { Integer, type TInteger, type IntegerOptions } from './type/integer/index.mjs';
|
|
27
27
|
export { Intersect, type TIntersect, type IntersectOptions } from './type/intersect/index.mjs';
|
|
28
28
|
export { Iterator, type TIterator } from './type/iterator/index.mjs';
|
|
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.mjs';
|
|
30
|
+
export { KeyOf, type TKeyOf, KeyOfPropertyKeys, KeyOfPattern } from './type/keyof/index.mjs';
|
|
31
31
|
export { Literal, type TLiteral } from './type/literal/index.mjs';
|
|
32
|
-
export { Mapped, type
|
|
32
|
+
export { Mapped, MappedKey, MappedResult, type TMapped, type TMappedKey, type TMappedResult, type TMappedFunction } from './type/mapped/index.mjs';
|
|
33
33
|
export { Never, type TNever } from './type/never/index.mjs';
|
|
34
34
|
export { Not, type TNot } from './type/not/index.mjs';
|
|
35
35
|
export { Null, type TNull } from './type/null/index.mjs';
|
|
36
36
|
export { Number, type TNumber, type NumberOptions } from './type/number/index.mjs';
|
|
37
37
|
export { Object, type TObject, type TProperties, type ObjectOptions } from './type/object/index.mjs';
|
|
38
|
-
export { Omit, type TOmit } from './type/omit/index.mjs';
|
|
38
|
+
export { Omit, type TOmit, type TOmitMappedResult } from './type/omit/index.mjs';
|
|
39
39
|
export { Optional, type TOptional } from './type/optional/index.mjs';
|
|
40
40
|
export { Parameters, type TParameters } from './type/parameters/index.mjs';
|
|
41
41
|
export { Partial, type TPartial } from './type/partial/index.mjs';
|
|
42
|
-
export { Pick, type TPick } from './type/pick/index.mjs';
|
|
42
|
+
export { Pick, type TPick, type TPickMappedResult } from './type/pick/index.mjs';
|
|
43
43
|
export { Promise, type TPromise } from './type/promise/index.mjs';
|
|
44
44
|
export { Readonly, type TReadonly } from './type/readonly/index.mjs';
|
|
45
45
|
export { ReadonlyOptional, type TReadonlyOptional } from './type/readonly-optional/index.mjs';
|
package/build/import/index.mjs
CHANGED
|
@@ -21,15 +21,15 @@ export { Extends, ExtendsCheck, ExtendsResult, ExtendsUndefinedCheck } from './t
|
|
|
21
21
|
export { Extract } from './type/extract/index.mjs';
|
|
22
22
|
export { Function } from './type/function/index.mjs';
|
|
23
23
|
export { Increment } from './type/helpers/index.mjs';
|
|
24
|
-
export { Index,
|
|
24
|
+
export { Index, IndexPropertyKeys, IndexMappedResult } from './type/indexed/index.mjs';
|
|
25
25
|
export { InstanceType } from './type/instance-type/index.mjs';
|
|
26
26
|
export { Integer } from './type/integer/index.mjs';
|
|
27
27
|
export { Intersect } from './type/intersect/index.mjs';
|
|
28
28
|
export { Iterator } from './type/iterator/index.mjs';
|
|
29
|
-
export { Capitalize, Lowercase, Uncapitalize, Uppercase
|
|
30
|
-
export { KeyOf,
|
|
29
|
+
export { Intrinsic, Capitalize, Lowercase, Uncapitalize, Uppercase } from './type/intrinsic/index.mjs';
|
|
30
|
+
export { KeyOf, KeyOfPropertyKeys, KeyOfPattern } from './type/keyof/index.mjs';
|
|
31
31
|
export { Literal } from './type/literal/index.mjs';
|
|
32
|
-
export { Mapped } from './type/mapped/index.mjs';
|
|
32
|
+
export { Mapped, MappedKey, MappedResult } from './type/mapped/index.mjs';
|
|
33
33
|
export { Never } from './type/never/index.mjs';
|
|
34
34
|
export { Not } from './type/not/index.mjs';
|
|
35
35
|
export { Null } from './type/null/index.mjs';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { UnionToTuple, Assert, Evaluate } from '../helpers/index.mjs';
|
|
2
2
|
import { type TObject, type ObjectOptions } from '../object/index.mjs';
|
|
3
3
|
import { type TIntersect } from '../intersect/index.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { type TIndex } from '../indexed/index.mjs';
|
|
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<{}>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Object } from '../object/index.mjs';
|
|
2
2
|
import { Intersect } from '../intersect/index.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { KeyOfPropertyKeys } from '../keyof/index.mjs';
|
|
4
4
|
import { Index } from '../indexed/index.mjs';
|
|
5
5
|
import { CloneType } from '../clone/type.mjs';
|
|
6
6
|
export function CompositeResolve(T) {
|
|
7
7
|
const intersect = Intersect(T, {});
|
|
8
|
-
const keys =
|
|
8
|
+
const keys = KeyOfPropertyKeys(intersect);
|
|
9
9
|
const properties = keys.reduce((acc, key) => ({ ...acc, [key]: Index(intersect, [key]) }), {});
|
|
10
10
|
return Object(properties);
|
|
11
11
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TSchema } from '../schema/index.mjs';
|
|
2
|
+
import type { TProperties } from '../object/index.mjs';
|
|
3
|
+
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
|
+
import { type TExtends } from './extends.mjs';
|
|
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,14 @@
|
|
|
1
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
+
import { Extends } from './extends.mjs';
|
|
3
|
+
function MappedResultExtendsPropertyKeys(K, U, L, R) {
|
|
4
|
+
return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => {
|
|
5
|
+
return { ...Acc, [K2]: Extends(K[K2], U, L, R) };
|
|
6
|
+
}, {});
|
|
7
|
+
}
|
|
8
|
+
function MappedResultExtendsProperties(K, U, L, R) {
|
|
9
|
+
return MappedResultExtendsPropertyKeys(K.properties, U, L, R);
|
|
10
|
+
}
|
|
11
|
+
export function ExtendsMappedResultFromResult(T, U, L, R) {
|
|
12
|
+
const P = MappedResultExtendsProperties(T, U, L, R);
|
|
13
|
+
return MappedResult(P);
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TSchema } from '../schema/index.mjs';
|
|
2
|
+
import type { TProperties } from '../object/index.mjs';
|
|
3
|
+
import type { Assert } from '../helpers/index.mjs';
|
|
4
|
+
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
5
|
+
import { TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
6
|
+
import { type TExtends } from './extends.mjs';
|
|
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,21 @@
|
|
|
1
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
+
import { Literal } from '../literal/index.mjs';
|
|
3
|
+
import { Extends } from './extends.mjs';
|
|
4
|
+
function MappedExtendsPropertyKey(K, U, L, R) {
|
|
5
|
+
return {
|
|
6
|
+
[K]: Extends(Literal(K), U, L, R)
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function MappedExtendsPropertyKeys(K, U, L, R) {
|
|
10
|
+
const [LK, ...RK] = K;
|
|
11
|
+
return (K.length > 0
|
|
12
|
+
? { ...MappedExtendsPropertyKey(LK, U, L, R), ...MappedExtendsPropertyKeys(RK, U, L, R) }
|
|
13
|
+
: {});
|
|
14
|
+
}
|
|
15
|
+
function MappedExtendsProperties(K, U, L, R) {
|
|
16
|
+
return MappedExtendsPropertyKeys(K.keys, U, L, R);
|
|
17
|
+
}
|
|
18
|
+
export function ExtendsMappedResult(T, U, L, R) {
|
|
19
|
+
const P = MappedExtendsProperties(T, U, L, R);
|
|
20
|
+
return MappedResult(P);
|
|
21
|
+
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import type { Static } from '../static/index.mjs';
|
|
3
3
|
import { type TUnion } from '../union/index.mjs';
|
|
4
|
+
import { TMappedKey, TMappedResult } from '../mapped/index.mjs';
|
|
4
5
|
import { UnionToTuple } from '../helpers/index.mjs';
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import { type TExtendsMappedResult } from './extends-mapped-result.mjs';
|
|
7
|
+
import { type TExtendsMappedResultFromResult } from './extends-mapped-result-from-result.mjs';
|
|
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,13 +1,17 @@
|
|
|
1
|
+
import { TMappedKey as IsMappedKeyType, TMappedResult as IsMappedResultType } from '../guard/type.mjs';
|
|
1
2
|
import { Union } from '../union/index.mjs';
|
|
2
3
|
import { ExtendsCheck, ExtendsResult } from './extends-check.mjs';
|
|
3
4
|
import { CloneType } from '../clone/type.mjs';
|
|
4
|
-
|
|
5
|
+
import { ExtendsMappedResult } from './extends-mapped-result.mjs';
|
|
6
|
+
import { ExtendsMappedResultFromResult } from './extends-mapped-result-from-result.mjs';
|
|
7
|
+
function ExtendsResolve(left, right, trueType, falseType) {
|
|
5
8
|
const R = ExtendsCheck(left, right);
|
|
6
9
|
return (R === ExtendsResult.Union ? Union([trueType, falseType]) :
|
|
7
10
|
R === ExtendsResult.True ? trueType :
|
|
8
11
|
falseType);
|
|
9
12
|
}
|
|
10
13
|
export function Extends(L, R, T, F, options = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
return (IsMappedResultType(L) ? CloneType(ExtendsMappedResultFromResult(L, R, T, F), options) :
|
|
15
|
+
IsMappedKeyType(L) ? CloneType(ExtendsMappedResult(L, R, T, F), options) :
|
|
16
|
+
CloneType(ExtendsResolve(L, R, T, F), options));
|
|
13
17
|
}
|
|
@@ -15,11 +15,12 @@ import type { TInteger } from '../integer/index.mjs';
|
|
|
15
15
|
import type { TIntersect } from '../intersect/index.mjs';
|
|
16
16
|
import type { TIterator } from '../iterator/index.mjs';
|
|
17
17
|
import type { TLiteral } from '../literal/index.mjs';
|
|
18
|
+
import type { TMappedKey, TMappedResult } from '../mapped/index.mjs';
|
|
18
19
|
import type { TNever } from '../never/index.mjs';
|
|
19
20
|
import type { TNot } from '../not/index.mjs';
|
|
20
21
|
import type { TNull } from '../null/index.mjs';
|
|
21
22
|
import type { TNumber } from '../number/index.mjs';
|
|
22
|
-
import type { TObject } from '../object/index.mjs';
|
|
23
|
+
import type { TObject, TProperties } from '../object/index.mjs';
|
|
23
24
|
import type { TOptional } from '../optional/index.mjs';
|
|
24
25
|
import type { TPromise } from '../promise/index.mjs';
|
|
25
26
|
import type { TReadonly } from '../readonly/index.mjs';
|
|
@@ -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;
|
|
@@ -16,6 +16,8 @@ const KnownTypes = [
|
|
|
16
16
|
'Intersect',
|
|
17
17
|
'Iterator',
|
|
18
18
|
'Literal',
|
|
19
|
+
'MappedKey',
|
|
20
|
+
'MappedResult',
|
|
19
21
|
'Not',
|
|
20
22
|
'Null',
|
|
21
23
|
'Number',
|
|
@@ -157,6 +159,10 @@ export function TInteger(schema) {
|
|
|
157
159
|
IsOptionalNumber(schema.minimum) &&
|
|
158
160
|
IsOptionalNumber(schema.multipleOf));
|
|
159
161
|
}
|
|
162
|
+
export function TProperties(schema) {
|
|
163
|
+
return (ValueGuard.IsObject(schema) &&
|
|
164
|
+
Object.entries(schema).every(([key, schema]) => IsControlCharacterFree(key) && TSchema(schema)));
|
|
165
|
+
}
|
|
160
166
|
export function TIntersect(schema) {
|
|
161
167
|
return (TKindOf(schema, 'Intersect') &&
|
|
162
168
|
(ValueGuard.IsString(schema.type) && schema.type !== 'object' ? false : true) &&
|
|
@@ -190,6 +196,15 @@ export function TLiteral(schema) {
|
|
|
190
196
|
ValueGuard.IsNumber(schema.const) ||
|
|
191
197
|
ValueGuard.IsString(schema.const)));
|
|
192
198
|
}
|
|
199
|
+
export function TMappedKey(schema) {
|
|
200
|
+
return (TKindOf(schema, 'MappedKey') &&
|
|
201
|
+
ValueGuard.IsArray(schema.keys) &&
|
|
202
|
+
schema.keys.every(key => ValueGuard.IsNumber(key) || ValueGuard.IsString(key)));
|
|
203
|
+
}
|
|
204
|
+
export function TMappedResult(schema) {
|
|
205
|
+
return (TKindOf(schema, 'MappedResult') &&
|
|
206
|
+
TProperties(schema.properties));
|
|
207
|
+
}
|
|
193
208
|
export function TNever(schema) {
|
|
194
209
|
return (TKindOf(schema, 'Never') &&
|
|
195
210
|
ValueGuard.IsObject(schema.not) &&
|
|
@@ -218,8 +233,7 @@ export function TObject(schema) {
|
|
|
218
233
|
return (TKindOf(schema, 'Object') &&
|
|
219
234
|
schema.type === 'object' &&
|
|
220
235
|
IsOptionalString(schema.$id) &&
|
|
221
|
-
|
|
222
|
-
Object.entries(schema.properties).every(([key, schema]) => IsControlCharacterFree(key) && TSchema(schema)) &&
|
|
236
|
+
TProperties(schema.properties) &&
|
|
223
237
|
IsAdditionalProperties(schema.additionalProperties) &&
|
|
224
238
|
IsOptionalNumber(schema.minProperties) &&
|
|
225
239
|
IsOptionalNumber(schema.maxProperties));
|
|
@@ -343,6 +357,8 @@ export function TSchema(schema) {
|
|
|
343
357
|
TIntersect(schema) ||
|
|
344
358
|
TIterator(schema) ||
|
|
345
359
|
TLiteral(schema) ||
|
|
360
|
+
TMappedKey(schema) ||
|
|
361
|
+
TMappedResult(schema) ||
|
|
346
362
|
TNever(schema) ||
|
|
347
363
|
TNot(schema) ||
|
|
348
364
|
TNull(schema) ||
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type TSchema } from '../schema/index.mjs';
|
|
2
|
+
import { type TProperties } from '../object/index.mjs';
|
|
3
|
+
import { type TIndexResult } from './indexed-result.mjs';
|
|
4
|
+
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
5
|
+
import { Evaluate } from '../helpers/index.mjs';
|
|
6
|
+
type MappedIndexPropertyKey<T extends TSchema, K extends PropertyKey> = {
|
|
7
|
+
[_ in K]: TIndexResult<T, [K]>;
|
|
8
|
+
};
|
|
9
|
+
declare function MappedIndexPropertyKey<T extends TSchema, K extends PropertyKey>(T: T, K: K): MappedIndexPropertyKey<T, K>;
|
|
10
|
+
type MappedIndexPropertyKeys<T extends TSchema, K extends PropertyKey[]> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? MappedIndexPropertyKey<T, L> & MappedIndexPropertyKeys<T, R> : {});
|
|
11
|
+
declare function MappedIndexPropertyKeys<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): MappedIndexPropertyKeys<T, K>;
|
|
12
|
+
type MappedIndexProperties<T extends TSchema, K extends TMappedKey> = Evaluate<MappedIndexPropertyKeys<T, K['keys']>>;
|
|
13
|
+
declare function MappedIndexProperties<T extends TSchema, K extends TMappedKey>(T: T, K: K): MappedIndexProperties<T, K>;
|
|
14
|
+
export type TIndexMappedResult<T extends TSchema, K extends TMappedKey, P extends TProperties = MappedIndexProperties<T, K>> = (TMappedResult<P>);
|
|
15
|
+
export declare function IndexMappedResult<T extends TSchema, K extends TMappedKey, P extends TProperties = MappedIndexProperties<T, K>>(T: T, K: K): TMappedResult<P>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IndexResult } from './indexed-result.mjs';
|
|
2
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
3
|
+
function MappedIndexPropertyKey(T, K) {
|
|
4
|
+
return { [K]: IndexResult(T, [K]) };
|
|
5
|
+
}
|
|
6
|
+
function MappedIndexPropertyKeys(T, K) {
|
|
7
|
+
const [L, ...R] = K;
|
|
8
|
+
return (K.length > 0
|
|
9
|
+
? { ...MappedIndexPropertyKey(T, L), ...MappedIndexPropertyKeys(T, R) }
|
|
10
|
+
: {});
|
|
11
|
+
}
|
|
12
|
+
function MappedIndexProperties(T, K) {
|
|
13
|
+
return MappedIndexPropertyKeys(T, K.keys);
|
|
14
|
+
}
|
|
15
|
+
export function IndexMappedResult(T, K) {
|
|
16
|
+
const P = MappedIndexProperties(T, K);
|
|
17
|
+
return MappedResult(P);
|
|
18
|
+
}
|
|
@@ -6,11 +6,11 @@ import { type TSchema } from '../schema/index.mjs';
|
|
|
6
6
|
import { type TUnion } from '../union/index.mjs';
|
|
7
7
|
type FromTemplateLiteral<T extends TTemplateLiteral, F = IsTemplateLiteralFinite<T>> = (F extends true ? TemplateLiteralGenerate<T> extends infer R extends string[] ? R : [] : []);
|
|
8
8
|
declare function FromTemplateLiteral<T extends TTemplateLiteral>(T: T): FromTemplateLiteral<T>;
|
|
9
|
-
type FromUnion<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [...
|
|
9
|
+
type FromUnion<T extends TSchema[]> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [...TIndexPropertyKeys<L>, ...FromUnion<R>] : []);
|
|
10
10
|
declare function FromUnion<T extends TSchema[]>(T: T): FromUnion<T>;
|
|
11
11
|
type FromLiteral<T extends TLiteralValue> = (T extends PropertyKey ? [`${T}`] : []);
|
|
12
12
|
declare function FromLiteral<T extends TLiteralValue>(T: T): FromLiteral<T>;
|
|
13
|
-
export type
|
|
13
|
+
export type TIndexPropertyKeys<T extends TSchema> = (T extends TTemplateLiteral ? FromTemplateLiteral<T> : T extends TUnion<infer S> ? FromUnion<S> : T extends TLiteral<infer S> ? FromLiteral<S> : T extends TNumber ? ['[number]'] : T extends TInteger ? ['[number]'] : [
|
|
14
14
|
]);
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function IndexPropertyKeys<T extends TSchema>(T: T): TIndexPropertyKeys<T>;
|
|
16
16
|
export {};
|
|
@@ -13,13 +13,13 @@ function FromTemplateLiteral(T) {
|
|
|
13
13
|
function FromUnion(T) {
|
|
14
14
|
const [L, ...R] = T;
|
|
15
15
|
return (T.length > 0
|
|
16
|
-
? [...
|
|
16
|
+
? [...IndexPropertyKeys(L), ...FromUnion(R)]
|
|
17
17
|
: []);
|
|
18
18
|
}
|
|
19
19
|
function FromLiteral(T) {
|
|
20
20
|
return ([T.toString()]);
|
|
21
21
|
}
|
|
22
|
-
export function
|
|
22
|
+
export function IndexPropertyKeys(T) {
|
|
23
23
|
return [...new Set((IsTemplateLiteralType(T) ? FromTemplateLiteral(T) :
|
|
24
24
|
IsUnionType(T) ? FromUnion(T.anyOf) :
|
|
25
25
|
IsLiteralType(T) ? FromLiteral(T.const) :
|
|
@@ -28,6 +28,6 @@ type FromKey<T extends TSchema, K extends PropertyKey> = (T extends TRecursive<i
|
|
|
28
28
|
declare function FromKey<T extends TSchema, K extends PropertyKey>(T: T, K: K): FromKey<T, K>;
|
|
29
29
|
type FromKeys<T extends TSchema, K extends PropertyKey[]> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? [FromKey<T, L>, ...FromKeys<T, R>] : []);
|
|
30
30
|
declare function FromKeys<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): FromKeys<T, K>;
|
|
31
|
-
export type
|
|
32
|
-
export declare function
|
|
31
|
+
export type TIndexResult<T extends TSchema, K extends PropertyKey[]> = (UnionResolve<FromKeys<T, K>>);
|
|
32
|
+
export declare function IndexResult<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): TIndexResult<T, K>;
|
|
33
33
|
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { type TIndexResult } from './indexed-result.mjs';
|
|
3
|
+
import { type TIndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
4
|
+
import { type TIndexMappedResult } from './indexed-mapped-result.mjs';
|
|
5
|
+
import { TMappedKey } from '../mapped/index.mjs';
|
|
6
|
+
export type TIndex<T extends TSchema, K extends PropertyKey[]> = TIndexResult<T, K>;
|
|
7
|
+
export declare function Index<T extends TSchema, K extends TMappedKey>(T: T, K: K): TIndexMappedResult<T, K>;
|
|
8
|
+
export declare function Index<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TIndex<T, I>;
|
|
6
9
|
export declare function Index<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TIndex<T, K>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { TSchema as IsSchemaType, TMappedKey as IsMappedKey } from '../guard/type.mjs';
|
|
2
|
+
import { IndexResult } from './indexed-result.mjs';
|
|
3
|
+
import { IndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
4
|
+
import { IndexMappedResult } from './indexed-mapped-result.mjs';
|
|
3
5
|
import { CloneType } from '../clone/type.mjs';
|
|
4
|
-
import { TSchema as IsSchemaType } from '../guard/type.mjs';
|
|
5
6
|
export function Index(T, K, options = {}) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
return (IsMappedKey(K) ? CloneType(IndexMappedResult(T, K), options) :
|
|
8
|
+
IsSchemaType(K) ? CloneType(IndexResult(T, IndexPropertyKeys(K)), options) :
|
|
9
|
+
CloneType(IndexResult(T, K), options));
|
|
9
10
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
|
+
import { TIntrinsic } from './intrinsic.mjs';
|
|
3
|
+
export type TCapitalize<T extends TSchema> = TIntrinsic<T, 'Capitalize'>;
|
|
4
|
+
export declare function Capitalize<T extends TSchema>(T: T, options?: SchemaOptions): TCapitalize<T>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TProperties } from '../object/index.mjs';
|
|
2
|
+
import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
|
|
3
|
+
import { type TIntrinsic, type IntrinsicMode } from './intrinsic.mjs';
|
|
4
|
+
import { TLiteral, TLiteralValue } from '../literal/index.mjs';
|
|
5
|
+
type MappedIntrinsicPropertyKey<K extends PropertyKey, M extends IntrinsicMode, P extends TLiteralValue = K extends TLiteralValue ? K : never> = {
|
|
6
|
+
[_ in K]: TIntrinsic<TLiteral<P>, M>;
|
|
7
|
+
};
|
|
8
|
+
declare function MappedIntrinsicPropertyKey<K extends PropertyKey, M extends IntrinsicMode>(K: K, M: M): MappedIntrinsicPropertyKey<K, M>;
|
|
9
|
+
type MappedIntrinsicPropertyKeys<K extends PropertyKey[], M extends IntrinsicMode> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? MappedIntrinsicPropertyKey<L, M> & MappedIntrinsicPropertyKeys<R, M> : {});
|
|
10
|
+
declare function MappedIntrinsicPropertyKeys<K extends PropertyKey[], M extends IntrinsicMode>(K: [...K], M: M): MappedIntrinsicPropertyKeys<K, M>;
|
|
11
|
+
type MappedIntrinsicProperties<K extends TMappedKey, M extends IntrinsicMode> = (MappedIntrinsicPropertyKeys<K['keys'], M>);
|
|
12
|
+
declare function MappedIntrinsicProperties<K extends TMappedKey, M extends IntrinsicMode>(T: K, M: M): MappedIntrinsicProperties<K, M>;
|
|
13
|
+
export type TIntrinsicMappedResult<K extends TMappedKey, M extends IntrinsicMode, P extends TProperties = MappedIntrinsicProperties<K, M>> = (TMappedResult<P>);
|
|
14
|
+
export declare function IntrinsicMappedResult<K extends TMappedKey, M extends IntrinsicMode, P extends TProperties = MappedIntrinsicProperties<K, M>>(T: K, M: M): TMappedResult<P>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
+
import { Intrinsic } from './intrinsic.mjs';
|
|
3
|
+
import { Literal } from '../literal/index.mjs';
|
|
4
|
+
function MappedIntrinsicPropertyKey(K, M) {
|
|
5
|
+
return {
|
|
6
|
+
[K]: Intrinsic(Literal(K), M)
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function MappedIntrinsicPropertyKeys(K, M) {
|
|
10
|
+
const [L, ...R] = K;
|
|
11
|
+
return (K.length > 0
|
|
12
|
+
? { ...MappedIntrinsicPropertyKey(L, M), ...MappedIntrinsicPropertyKeys(R, M) }
|
|
13
|
+
: {});
|
|
14
|
+
}
|
|
15
|
+
function MappedIntrinsicProperties(T, M) {
|
|
16
|
+
return MappedIntrinsicPropertyKeys(T['keys'], M);
|
|
17
|
+
}
|
|
18
|
+
export function IntrinsicMappedResult(T, M) {
|
|
19
|
+
const P = MappedIntrinsicProperties(T, M);
|
|
20
|
+
return MappedResult(P);
|
|
21
|
+
}
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import type { TSchema
|
|
1
|
+
import type { TSchema } from '../schema/index.mjs';
|
|
2
2
|
import { type TTemplateLiteral, type TTemplateLiteralKind } from '../template-literal/index.mjs';
|
|
3
|
+
import { type TIntrinsicMappedResult } from './intrinsic-mapped-result.mjs';
|
|
3
4
|
import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
|
|
4
5
|
import { type TUnion } from '../union/index.mjs';
|
|
5
|
-
|
|
6
|
-
type
|
|
6
|
+
import { type TMappedKey } from '../mapped/index.mjs';
|
|
7
|
+
export type IntrinsicMode = 'Uppercase' | 'Lowercase' | 'Capitalize' | 'Uncapitalize';
|
|
8
|
+
type FromTemplateLiteral<T extends TTemplateLiteralKind[], M extends IntrinsicMode> = M extends IntrinsicMode ? T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? [TIntrinsic<L, M>, ...FromTemplateLiteral<R, M>] : T : T;
|
|
7
9
|
declare function FromTemplateLiteral<T extends TTemplateLiteralKind[], M extends IntrinsicMode>(schema: TTemplateLiteral, mode: IntrinsicMode): FromTemplateLiteral<T, M>;
|
|
8
10
|
type FromLiteralValue<T, M extends IntrinsicMode> = (T extends string ? M extends 'Uncapitalize' ? Uncapitalize<T> : M extends 'Capitalize' ? Capitalize<T> : M extends 'Uppercase' ? Uppercase<T> : M extends 'Lowercase' ? Lowercase<T> : string : T);
|
|
9
11
|
declare function FromLiteralValue(value: TLiteralValue, mode: IntrinsicMode): string;
|
|
10
|
-
type FromRest<T extends TSchema[], M extends IntrinsicMode> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [
|
|
12
|
+
type FromRest<T extends TSchema[], M extends IntrinsicMode> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? [TIntrinsic<L, M>, ...FromRest<R, M>] : [];
|
|
11
13
|
declare function FromRest<T extends TSchema[], M extends IntrinsicMode>(T: [...T], mode: M): FromRest<T, M>;
|
|
12
|
-
export type
|
|
13
|
-
export declare function
|
|
14
|
-
export
|
|
15
|
-
export declare function Uncapitalize<T extends TSchema>(T: T, options?: SchemaOptions): TUncapitalize<T>;
|
|
16
|
-
export type TUppercase<T extends TSchema> = IntrinsicResolve<T, 'Uppercase'>;
|
|
17
|
-
export declare function Uppercase<T extends TSchema>(T: T, options?: SchemaOptions): TUppercase<T>;
|
|
18
|
-
export type TLowercase<T extends TSchema> = IntrinsicResolve<T, 'Lowercase'>;
|
|
19
|
-
export declare function Lowercase<T extends TSchema>(T: T, options?: SchemaOptions): TLowercase<T>;
|
|
20
|
-
export type TCapitalize<T extends TSchema> = IntrinsicResolve<T, 'Capitalize'>;
|
|
21
|
-
export declare function Capitalize<T extends TSchema>(T: T, options?: SchemaOptions): TCapitalize<T>;
|
|
14
|
+
export type TIntrinsic<T extends TSchema, M extends IntrinsicMode> = T extends TMappedKey ? TIntrinsicMappedResult<T, M> : T extends TTemplateLiteral<infer S> ? TTemplateLiteral<FromTemplateLiteral<S, M>> : T extends TUnion<infer S> ? TUnion<FromRest<S, M>> : T extends TLiteral<infer S> ? TLiteral<FromLiteralValue<S, M>> : T;
|
|
15
|
+
export declare function Intrinsic<T extends TMappedKey, M extends IntrinsicMode>(schema: T, mode: M): TIntrinsicMappedResult<T, M>;
|
|
16
|
+
export declare function Intrinsic<T extends TSchema, M extends IntrinsicMode>(schema: T, mode: M): TIntrinsic<T, M>;
|
|
22
17
|
export {};
|