typebox 1.1.27 → 1.1.29
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/schema/engine/_refine.mjs +4 -4
- package/build/schema/types/_refine.d.mts +2 -2
- package/build/schema/types/_refine.mjs +4 -4
- package/build/type/action/awaited.d.mts +2 -2
- package/build/type/action/awaited.mjs +2 -3
- package/build/type/action/capitalize.d.mts +2 -2
- package/build/type/action/capitalize.mjs +2 -3
- package/build/type/action/conditional.d.mts +4 -2
- package/build/type/action/conditional.mjs +2 -2
- package/build/type/action/constructor-parameters.d.mts +2 -2
- package/build/type/action/constructor-parameters.mjs +2 -3
- package/build/type/action/evaluate.d.mts +2 -2
- package/build/type/action/evaluate.mjs +2 -3
- package/build/type/action/exclude.d.mts +2 -2
- package/build/type/action/exclude.mjs +2 -3
- package/build/type/action/extract.d.mts +2 -2
- package/build/type/action/extract.mjs +2 -3
- package/build/type/action/index.d.mts +1 -1
- package/build/type/action/index.mjs +1 -1
- package/build/type/action/indexed.d.mts +2 -2
- package/build/type/action/indexed.mjs +2 -3
- package/build/type/action/instance-type.d.mts +2 -2
- package/build/type/action/instance-type.mjs +2 -3
- package/build/type/action/interface.d.mts +2 -2
- package/build/type/action/interface.mjs +5 -3
- package/build/type/action/keyof.d.mts +2 -2
- package/build/type/action/keyof.mjs +2 -3
- package/build/type/action/lowercase.d.mts +2 -2
- package/build/type/action/lowercase.mjs +2 -3
- package/build/type/action/mapped.d.mts +4 -2
- package/build/type/action/mapped.mjs +2 -2
- package/build/type/action/non-nullable.d.mts +2 -2
- package/build/type/action/non-nullable.mjs +2 -3
- package/build/type/action/omit.d.mts +2 -2
- package/build/type/action/omit.mjs +2 -3
- package/build/type/action/options.d.mts +4 -5
- package/build/type/action/options.mjs +3 -4
- package/build/type/action/parameters.d.mts +2 -2
- package/build/type/action/parameters.mjs +2 -3
- package/build/type/action/partial.d.mts +3 -3
- package/build/type/action/partial.mjs +2 -3
- package/build/type/action/pick.d.mts +2 -2
- package/build/type/action/pick.mjs +2 -3
- package/build/type/action/readonly-object.d.mts +16 -0
- package/build/type/action/readonly-object.mjs +16 -0
- package/build/type/action/required.d.mts +2 -2
- package/build/type/action/required.mjs +2 -3
- package/build/type/action/return-type.d.mts +2 -2
- package/build/type/action/return-type.mjs +2 -3
- package/build/type/action/uncapitalize.d.mts +2 -2
- package/build/type/action/uncapitalize.mjs +2 -3
- package/build/type/action/uppercase.d.mts +2 -2
- package/build/type/action/uppercase.mjs +2 -3
- package/build/type/engine/awaited/instantiate.d.mts +4 -3
- package/build/type/engine/awaited/instantiate.mjs +9 -8
- package/build/type/engine/conditional/instantiate.d.mts +4 -2
- package/build/type/engine/conditional/instantiate.mjs +13 -9
- package/build/type/engine/constructor-parameters/instantiate.d.mts +6 -5
- package/build/type/engine/constructor-parameters/instantiate.mjs +13 -11
- package/build/type/engine/evaluate/instantiate.d.mts +3 -3
- package/build/type/engine/evaluate/instantiate.mjs +5 -10
- package/build/type/engine/exclude/instantiate.d.mts +4 -11
- package/build/type/engine/exclude/instantiate.mjs +7 -28
- package/build/type/engine/exclude/operation.d.mts +11 -0
- package/build/type/engine/exclude/operation.mjs +24 -0
- package/build/type/engine/extract/instantiate.d.mts +4 -11
- package/build/type/engine/extract/instantiate.mjs +7 -28
- package/build/type/engine/extract/operation.d.mts +11 -0
- package/build/type/engine/extract/operation.mjs +24 -0
- package/build/type/engine/index.d.mts +1 -1
- package/build/type/engine/index.mjs +1 -1
- package/build/type/engine/indexed/from-object.d.mts +7 -2
- package/build/type/engine/indexed/from-object.mjs +24 -5
- package/build/type/engine/indexed/from-type.d.mts +11 -0
- package/build/type/engine/indexed/from-type.mjs +14 -0
- package/build/type/engine/indexed/instantiate.d.mts +5 -11
- package/build/type/engine/indexed/instantiate.mjs +8 -20
- package/build/type/engine/instance-type/instantiate.d.mts +4 -4
- package/build/type/engine/instance-type/instantiate.mjs +9 -8
- package/build/type/engine/instantiate.d.mts +4 -6
- package/build/type/engine/instantiate.mjs +9 -18
- package/build/type/engine/interface/instantiate.d.mts +6 -4
- package/build/type/engine/interface/instantiate.mjs +12 -8
- package/build/type/engine/intrinsics/instantiate.d.mts +12 -8
- package/build/type/engine/intrinsics/instantiate.mjs +28 -24
- package/build/type/engine/keyof/from-type.d.mts +15 -0
- package/build/type/engine/keyof/from-type.mjs +23 -0
- package/build/type/engine/keyof/instantiate.d.mts +4 -16
- package/build/type/engine/keyof/instantiate.mjs +8 -28
- package/build/type/engine/mapped/instantiate.d.mts +4 -19
- package/build/type/engine/mapped/instantiate.mjs +7 -42
- package/build/type/engine/mapped/mapped-operation.d.mts +22 -0
- package/build/type/engine/mapped/mapped-operation.mjs +42 -0
- package/build/type/engine/mapped/mapped-variants.d.mts +3 -2
- package/build/type/engine/mapped/mapped-variants.mjs +7 -2
- package/build/type/engine/non-nullable/instantiate.d.mts +5 -6
- package/build/type/engine/non-nullable/instantiate.mjs +10 -10
- package/build/type/engine/omit/from-type.d.mts +12 -0
- package/build/type/engine/omit/from-type.mjs +18 -0
- package/build/type/engine/omit/instantiate.d.mts +4 -11
- package/build/type/engine/omit/instantiate.mjs +7 -22
- package/build/type/engine/options/instantiate.d.mts +4 -4
- package/build/type/engine/options/instantiate.mjs +8 -7
- package/build/type/engine/parameters/instantiate.d.mts +6 -5
- package/build/type/engine/parameters/instantiate.mjs +13 -11
- package/build/type/engine/partial/instantiate.d.mts +3 -3
- package/build/type/engine/partial/instantiate.mjs +7 -6
- package/build/type/engine/pick/from-type.d.mts +13 -0
- package/build/type/engine/pick/from-type.mjs +20 -0
- package/build/type/engine/pick/instantiate.d.mts +4 -12
- package/build/type/engine/pick/instantiate.mjs +7 -23
- package/build/type/engine/readonly-object/instantiate.d.mts +9 -0
- package/build/type/engine/readonly-object/instantiate.mjs +15 -0
- package/build/type/engine/record/instantiate.d.mts +3 -3
- package/build/type/engine/record/instantiate.mjs +8 -7
- package/build/type/engine/required/instantiate.d.mts +3 -3
- package/build/type/engine/required/instantiate.mjs +7 -6
- package/build/type/engine/return-type/instantiate.d.mts +5 -4
- package/build/type/engine/return-type/instantiate.mjs +12 -9
- package/build/type/engine/template-literal/encode.d.mts +4 -2
- package/build/type/engine/template-literal/encode.mjs +10 -3
- package/build/type/engine/template-literal/instantiate.d.mts +3 -3
- package/build/type/engine/template-literal/instantiate.mjs +7 -6
- package/build/type/extends/extends.d.mts +4 -2
- package/build/type/extends/extends.mjs +9 -7
- package/build/type/script/mapping.d.mts +1 -1
- package/build/type/script/mapping.mjs +1 -1
- package/build/type/types/_refine.d.mts +13 -6
- package/build/type/types/_refine.mjs +21 -4
- package/build/type/types/promise.d.mts +2 -1
- package/build/type/types/promise.mjs +2 -1
- package/build/type/types/properties.d.mts +2 -1
- package/build/type/types/record.d.mts +3 -5
- package/build/type/types/record.mjs +2 -6
- package/build/type/types/template-literal.d.mts +5 -3
- package/build/type/types/template-literal.mjs +10 -4
- package/build/type/types/unsafe.d.mts +1 -2
- package/build/type/types/unsafe.mjs +5 -3
- package/build/typebox.d.mts +4 -4
- package/build/typebox.mjs +2 -2
- package/build/value/mutate/mutate.d.mts +2 -0
- package/build/value/mutate/mutate.mjs +2 -0
- package/package.json +1 -1
- package/build/type/action/readonly-type.d.mts +0 -11
- package/build/type/action/readonly-type.mjs +0 -12
- package/build/type/engine/readonly-type/instantiate.d.mts +0 -9
- package/build/type/engine/readonly-type/instantiate.mjs +0 -14
- /package/build/type/engine/{readonly-type → readonly-object}/from-array.d.mts +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-array.mjs +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-cyclic.d.mts +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-cyclic.mjs +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-intersect.d.mts +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-intersect.mjs +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-object.d.mts +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-object.mjs +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-tuple.d.mts +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-tuple.mjs +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-type.d.mts +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-type.mjs +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-union.d.mts +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/from-union.mjs +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/index.d.mts +0 -0
- /package/build/type/engine/{readonly-type → readonly-object}/index.mjs +0 -0
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
2
2
|
import { type TProperties } from '../../types/properties.mjs';
|
|
3
3
|
import { type TFunction } from '../../types/function.mjs';
|
|
4
|
-
import { type TNever } from '../../types/never.mjs';
|
|
5
4
|
import { type TTuple } from '../../types/tuple.mjs';
|
|
6
5
|
import { type TParametersDeferred } from '../../action/parameters.mjs';
|
|
7
6
|
import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
|
|
8
|
-
|
|
7
|
+
import { type TInstantiateElements } from '../instantiate.mjs';
|
|
8
|
+
type TParametersOperation<Type extends TSchema, Parameters extends TSchema[] = Type extends TFunction ? Type['parameters'] : [], InstantiatedParameters extends TSchema[] = TInstantiateElements<{}, {
|
|
9
9
|
callstack: [];
|
|
10
|
-
}, TTuple<
|
|
11
|
-
type
|
|
12
|
-
export
|
|
10
|
+
}, Parameters>, Result extends TSchema = TTuple<InstantiatedParameters>> = Result;
|
|
11
|
+
export type TParametersAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TParametersOperation<Type> : TParametersDeferred<Type>> = Result;
|
|
12
|
+
export declare function ParametersAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TParametersAction<Type>;
|
|
13
|
+
export type TParametersInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TParametersAction<InstantiatedType>;
|
|
13
14
|
export declare function ParametersInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TParametersInstantiate<Context, State, Type>;
|
|
14
15
|
export {};
|
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
// deno-fmt-ignore-file
|
|
3
3
|
import { Memory } from '../../../system/memory/index.mjs';
|
|
4
4
|
import { IsFunction } from '../../types/function.mjs';
|
|
5
|
-
import { Never } from '../../types/never.mjs';
|
|
6
5
|
import { Tuple } from '../../types/tuple.mjs';
|
|
7
6
|
import { ParametersDeferred } from '../../action/parameters.mjs';
|
|
8
7
|
import { InstantiateType, CanInstantiate } from '../instantiate.mjs';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
import { InstantiateElements } from '../instantiate.mjs';
|
|
9
|
+
function ParametersOperation(type) {
|
|
10
|
+
const parameters = IsFunction(type) ? type['parameters'] : [];
|
|
11
|
+
const instantiatedParameters = InstantiateElements({}, { callstack: [] }, parameters);
|
|
12
|
+
const result = Tuple(instantiatedParameters);
|
|
13
|
+
return result;
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
const
|
|
16
|
-
|
|
15
|
+
export function ParametersAction(type, options) {
|
|
16
|
+
const result = CanInstantiate([type])
|
|
17
|
+
? Memory.Update(ParametersOperation(type), {}, options)
|
|
18
|
+
: ParametersDeferred(type, options);
|
|
19
|
+
return result;
|
|
17
20
|
}
|
|
18
21
|
export function ParametersInstantiate(context, state, type, options) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
: ParametersDeferred(type, options));
|
|
22
|
+
const instantiatedType = InstantiateType(context, state, type);
|
|
23
|
+
return ParametersAction(instantiatedType, options);
|
|
22
24
|
}
|
|
@@ -3,7 +3,7 @@ import { type TProperties } from '../../types/properties.mjs';
|
|
|
3
3
|
import { type TPartialDeferred } from '../../action/partial.mjs';
|
|
4
4
|
import { type TFromType } from './from-type.mjs';
|
|
5
5
|
import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
|
|
6
|
-
type
|
|
7
|
-
export
|
|
6
|
+
export type TPartialAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType<Type> : TPartialDeferred<Type>> = Result;
|
|
7
|
+
export declare function PartialAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TPartialAction<Type>;
|
|
8
|
+
export type TPartialInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TPartialAction<InstantiatedType>;
|
|
8
9
|
export declare function PartialInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TPartialInstantiate<Context, State, Type>;
|
|
9
|
-
export {};
|
|
@@ -3,12 +3,13 @@ import { Memory } from '../../../system/memory/index.mjs';
|
|
|
3
3
|
import { PartialDeferred } from '../../action/partial.mjs';
|
|
4
4
|
import { FromType } from './from-type.mjs';
|
|
5
5
|
import { InstantiateType, CanInstantiate } from '../instantiate.mjs';
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
|
|
6
|
+
export function PartialAction(type, options) {
|
|
7
|
+
const result = CanInstantiate([type])
|
|
8
|
+
? Memory.Update(FromType(type), {}, options)
|
|
9
|
+
: PartialDeferred(type, options);
|
|
10
|
+
return result;
|
|
9
11
|
}
|
|
10
12
|
export function PartialInstantiate(context, state, type, options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
: PartialDeferred(type, options));
|
|
13
|
+
const instantiatedType = InstantiateType(context, state, type);
|
|
14
|
+
return PartialAction(instantiatedType, options);
|
|
14
15
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Memory } from '../../../system/memory/index.mjs';
|
|
2
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
3
|
+
import { type TProperties } from '../../types/properties.mjs';
|
|
4
|
+
import { type TObject } from '../../types/object.mjs';
|
|
5
|
+
import { type TToIndexableKeys } from '../indexable/to-indexable-keys.mjs';
|
|
6
|
+
import { type TToIndexable } from '../indexable/to-indexable.mjs';
|
|
7
|
+
type TComparable<Indexable extends TProperties> = (keyof Indexable extends string | number ? `${keyof Indexable}` : never);
|
|
8
|
+
type TFromKeys<Indexable extends TProperties, Keys extends string[], Result extends TProperties = {}> = (Keys extends [infer Left extends string, ...infer Right extends string[]] ? Left extends TComparable<Indexable> ? TFromKeys<Indexable, Right, Memory.TAssign<Result, {
|
|
9
|
+
[_ in Left]: Indexable[Left];
|
|
10
|
+
}>> : TFromKeys<Indexable, Right, Result> : Result);
|
|
11
|
+
export type TFromType<Type extends TSchema, Indexer extends TSchema, Indexable extends TProperties = TToIndexable<Type>, Keys extends string[] = TToIndexableKeys<Indexer>, Applied extends TProperties = TFromKeys<Indexable, Keys>, Result extends TSchema = TObject<Applied>> = Result;
|
|
12
|
+
export declare function FromType<Type extends TSchema, Indexer extends TSchema>(type: Type, indexer: Indexer): TFromType<Type, Indexer>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// deno-lint-ignore-file ban-types
|
|
2
|
+
// deno-fmt-ignore-file
|
|
3
|
+
import { Memory } from '../../../system/memory/index.mjs';
|
|
4
|
+
import { Guard } from '../../../guard/index.mjs';
|
|
5
|
+
import { Object } from '../../types/object.mjs';
|
|
6
|
+
import { ToIndexableKeys } from '../indexable/to-indexable-keys.mjs';
|
|
7
|
+
import { ToIndexable } from '../indexable/to-indexable.mjs';
|
|
8
|
+
function FromKeys(properties, keys) {
|
|
9
|
+
const result = Guard.Keys(properties).reduce((result, key) => {
|
|
10
|
+
return keys.includes(key) ? Memory.Assign(result, { [key]: properties[key] }) : result;
|
|
11
|
+
}, {});
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
export function FromType(type, indexer) {
|
|
15
|
+
const indexable = ToIndexable(type);
|
|
16
|
+
const keys = ToIndexableKeys(indexer);
|
|
17
|
+
const applied = FromKeys(indexable, keys);
|
|
18
|
+
const result = Object(applied);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import { Memory } from '../../../system/memory/index.mjs';
|
|
2
1
|
import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
3
2
|
import { type TProperties } from '../../types/properties.mjs';
|
|
4
|
-
import { type TObject } from '../../types/object.mjs';
|
|
5
|
-
import { type TToIndexableKeys } from '../indexable/to-indexable-keys.mjs';
|
|
6
|
-
import { type TToIndexable } from '../indexable/to-indexable.mjs';
|
|
7
3
|
import { type TPickDeferred } from '../../action/pick.mjs';
|
|
8
4
|
import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
|
|
9
|
-
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
type TPickAction<Type extends TSchema, Indexer extends TSchema, Indexable extends TProperties = TToIndexable<Type>, Keys extends string[] = TToIndexableKeys<Indexer>, Applied extends TProperties = TFromKeys<Indexable, Keys>, Result extends TSchema = TObject<Applied>> = Result;
|
|
14
|
-
type TPickImmediate<Context extends TProperties, State extends TState, Type extends TSchema, Indexer extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>, InstantiatedIndexer extends TSchema = TInstantiateType<Context, State, Indexer>> = TPickAction<InstantiatedType, InstantiatedIndexer>;
|
|
15
|
-
export type TPickInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, Indexer extends TSchema> = TCanInstantiate<Context, [Type, Indexer]> extends true ? TPickImmediate<Context, State, Type, Indexer> : TPickDeferred<Type, Indexer>;
|
|
5
|
+
import { type TFromType } from './from-type.mjs';
|
|
6
|
+
export type TPickAction<Type extends TSchema, Indexer extends TSchema, Result extends TSchema = TCanInstantiate<[Type, Indexer]> extends true ? TFromType<Type, Indexer> : TPickDeferred<Type, Indexer>> = Result;
|
|
7
|
+
export declare function PickAction<Type extends TSchema, Indexer extends TSchema>(type: Type, indexer: Indexer, options: TSchemaOptions): TPickAction<Type, Indexer>;
|
|
8
|
+
export type TPickInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, Indexer extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>, InstantiatedIndexer extends TSchema = TInstantiateType<Context, State, Indexer>> = TPickAction<InstantiatedType, InstantiatedIndexer>;
|
|
16
9
|
export declare function PickInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, Indexer extends TSchema>(context: Context, state: State, type: Type, indexer: Indexer, options: TSchemaOptions): TPickInstantiate<Context, State, Type, Indexer>;
|
|
17
|
-
export {};
|
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
// deno-lint-ignore-file ban-types
|
|
2
1
|
// deno-fmt-ignore-file
|
|
3
2
|
import { Memory } from '../../../system/memory/index.mjs';
|
|
4
|
-
import { Guard } from '../../../guard/index.mjs';
|
|
5
|
-
import { Object } from '../../types/object.mjs';
|
|
6
|
-
import { ToIndexableKeys } from '../indexable/to-indexable-keys.mjs';
|
|
7
|
-
import { ToIndexable } from '../indexable/to-indexable.mjs';
|
|
8
3
|
import { PickDeferred } from '../../action/pick.mjs';
|
|
9
4
|
import { InstantiateType, CanInstantiate } from '../instantiate.mjs';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
import { FromType } from './from-type.mjs';
|
|
6
|
+
export function PickAction(type, indexer, options) {
|
|
7
|
+
const result = CanInstantiate([type, indexer])
|
|
8
|
+
? Memory.Update(FromType(type, indexer), {}, options)
|
|
9
|
+
: PickDeferred(type, indexer, options);
|
|
14
10
|
return result;
|
|
15
11
|
}
|
|
16
|
-
function
|
|
17
|
-
const indexable = ToIndexable(type);
|
|
18
|
-
const keys = ToIndexableKeys(indexer);
|
|
19
|
-
const applied = FromKeys(indexable, keys);
|
|
20
|
-
const result = Object(applied);
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
function PickImmediate(context, state, type, indexer, options) {
|
|
12
|
+
export function PickInstantiate(context, state, type, indexer, options) {
|
|
24
13
|
const instantiatedType = InstantiateType(context, state, type);
|
|
25
14
|
const instantiatedIndexer = InstantiateType(context, state, indexer);
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
export function PickInstantiate(context, state, type, indexer, options) {
|
|
29
|
-
return (CanInstantiate(context, [type, indexer])
|
|
30
|
-
? PickImmediate(context, state, type, indexer, options)
|
|
31
|
-
: PickDeferred(type, indexer, options));
|
|
15
|
+
return PickAction(instantiatedType, instantiatedIndexer, options);
|
|
32
16
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type TSchema, type TSchemaOptions } from '../../types/schema.mjs';
|
|
2
|
+
import { type TProperties } from '../../types/properties.mjs';
|
|
3
|
+
import { type TReadonlyObjectDeferred } from '../../action/readonly-object.mjs';
|
|
4
|
+
import { type TFromType } from './from-type.mjs';
|
|
5
|
+
import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
|
|
6
|
+
export type TReadonlyObjectAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType<Type> : TReadonlyObjectDeferred<Type>> = Result;
|
|
7
|
+
export declare function ReadonlyObjectAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TReadonlyObjectAction<Type>;
|
|
8
|
+
export type TReadonlyObjectInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiateType extends TSchema = TInstantiateType<Context, State, Type>> = TReadonlyObjectAction<InstantiateType>;
|
|
9
|
+
export declare function ReadonlyObjectInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TReadonlyObjectInstantiate<Context, State, Type>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { Memory } from '../../../system/memory/index.mjs';
|
|
3
|
+
import { ReadonlyObjectDeferred } from '../../action/readonly-object.mjs';
|
|
4
|
+
import { FromType } from './from-type.mjs';
|
|
5
|
+
import { InstantiateType, CanInstantiate } from '../instantiate.mjs';
|
|
6
|
+
export function ReadonlyObjectAction(type, options) {
|
|
7
|
+
const result = CanInstantiate([type])
|
|
8
|
+
? Memory.Update(FromType(type), {}, options)
|
|
9
|
+
: ReadonlyObjectDeferred(type);
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
export function ReadonlyObjectInstantiate(context, state, type, options) {
|
|
13
|
+
const instantiatedType = InstantiateType(context, state, type);
|
|
14
|
+
return ReadonlyObjectAction(instantiatedType, options);
|
|
15
|
+
}
|
|
@@ -3,7 +3,7 @@ import { type TProperties } from '../../types/properties.mjs';
|
|
|
3
3
|
import { type TRecordDeferred } from '../../types/record.mjs';
|
|
4
4
|
import { type TFromKey } from './from-key.mjs';
|
|
5
5
|
import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
|
|
6
|
-
type
|
|
7
|
-
export
|
|
6
|
+
export type TRecordAction<Key extends TSchema, Value extends TSchema, Result extends TSchema = TCanInstantiate<[Key]> extends true ? TFromKey<Key, Value> : TRecordDeferred<Key, Value>> = Result;
|
|
7
|
+
export declare function RecordAction<Key extends TSchema, Value extends TSchema>(key: Key, value: Value, options: TSchemaOptions): TRecordAction<Key, Value>;
|
|
8
|
+
export type TRecordInstantiate<Context extends TProperties, State extends TState, Key extends TSchema, Value extends TSchema, InstantiatedKey extends TSchema = TInstantiateType<Context, State, Key>, InstantiatedValue extends TSchema = TInstantiateType<Context, State, Value>> = TRecordAction<InstantiatedKey, InstantiatedValue>;
|
|
8
9
|
export declare function RecordInstantiate<Context extends TProperties, State extends TState, Key extends TSchema, Value extends TSchema>(context: Context, state: State, key: Key, value: Value, options: TSchemaOptions): TRecordInstantiate<Context, State, Key, Value>;
|
|
9
|
-
export {};
|
|
@@ -4,13 +4,14 @@ import { Memory } from '../../../system/memory/index.mjs';
|
|
|
4
4
|
import { RecordDeferred } from '../../types/record.mjs';
|
|
5
5
|
import { FromKey } from './from-key.mjs';
|
|
6
6
|
import { InstantiateType, CanInstantiate } from '../instantiate.mjs';
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export function RecordAction(key, value, options) {
|
|
8
|
+
const result = CanInstantiate([key])
|
|
9
|
+
? Memory.Update(FromKey(key, value), {}, options)
|
|
10
|
+
: RecordDeferred(key, value, options);
|
|
11
|
+
return result;
|
|
11
12
|
}
|
|
12
13
|
export function RecordInstantiate(context, state, key, value, options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const instantiatedKey = InstantiateType(context, state, key);
|
|
15
|
+
const instantiatedValue = InstantiateType(context, state, value);
|
|
16
|
+
return RecordAction(instantiatedKey, instantiatedValue, options);
|
|
16
17
|
}
|
|
@@ -3,7 +3,7 @@ import { type TProperties } from '../../types/properties.mjs';
|
|
|
3
3
|
import { type TFromType } from './from-type.mjs';
|
|
4
4
|
import { type TRequiredDeferred } from '../../action/required.mjs';
|
|
5
5
|
import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
|
|
6
|
-
type
|
|
7
|
-
export
|
|
6
|
+
export type TRequiredAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TFromType<Type> : TRequiredDeferred<Type>> = Result;
|
|
7
|
+
export declare function RequiredAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TRequiredAction<Type>;
|
|
8
|
+
export type TRequiredInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TRequiredAction<InstantiatedType>;
|
|
8
9
|
export declare function RequiredInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TRequiredInstantiate<Context, State, Type>;
|
|
9
|
-
export {};
|
|
@@ -3,12 +3,13 @@ import { Memory } from '../../../system/memory/index.mjs';
|
|
|
3
3
|
import { FromType } from './from-type.mjs';
|
|
4
4
|
import { RequiredDeferred } from '../../action/required.mjs';
|
|
5
5
|
import { InstantiateType, CanInstantiate } from '../instantiate.mjs';
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
|
|
6
|
+
export function RequiredAction(type, options) {
|
|
7
|
+
const result = CanInstantiate([type])
|
|
8
|
+
? Memory.Update(FromType(type), {}, options)
|
|
9
|
+
: RequiredDeferred(type, options);
|
|
10
|
+
return result;
|
|
9
11
|
}
|
|
10
12
|
export function RequiredInstantiate(context, state, type, options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
: RequiredDeferred(type, options));
|
|
13
|
+
const instaniatedType = InstantiateType(context, state, type);
|
|
14
|
+
return RequiredAction(instaniatedType, options);
|
|
14
15
|
}
|
|
@@ -4,8 +4,9 @@ import { type TFunction } from '../../types/function.mjs';
|
|
|
4
4
|
import { type TNever } from '../../types/never.mjs';
|
|
5
5
|
import { type TReturnTypeDeferred } from '../../action/return-type.mjs';
|
|
6
6
|
import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
|
|
7
|
-
type
|
|
8
|
-
type
|
|
9
|
-
export
|
|
10
|
-
export
|
|
7
|
+
type TReturnTypeOperation<Type extends TSchema> = (Type extends TFunction ? Type['returnType'] : TNever);
|
|
8
|
+
export type TReturnTypeAction<Type extends TSchema, Result extends TSchema = TCanInstantiate<[Type]> extends true ? TReturnTypeOperation<Type> : TReturnTypeDeferred<Type>> = Result;
|
|
9
|
+
export declare function ReturnTypeAction<Type extends TSchema>(type: Type, options: TSchemaOptions): TReturnTypeAction<Type>;
|
|
10
|
+
export type TReturnTypeInstantiate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TReturnTypeAction<InstantiatedType>;
|
|
11
|
+
export declare function ReturnTypeInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options?: TSchemaOptions): TReturnTypeInstantiate<Context, State, Type>;
|
|
11
12
|
export {};
|
|
@@ -4,15 +4,18 @@ import { IsFunction } from '../../types/function.mjs';
|
|
|
4
4
|
import { Never } from '../../types/never.mjs';
|
|
5
5
|
import { ReturnTypeDeferred } from '../../action/return-type.mjs';
|
|
6
6
|
import { InstantiateType, CanInstantiate } from '../instantiate.mjs';
|
|
7
|
-
function
|
|
8
|
-
return (IsFunction(type)
|
|
7
|
+
function ReturnTypeOperation(type) {
|
|
8
|
+
return (IsFunction(type)
|
|
9
|
+
? type['returnType']
|
|
10
|
+
: Never());
|
|
9
11
|
}
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
|
|
12
|
+
export function ReturnTypeAction(type, options) {
|
|
13
|
+
const result = CanInstantiate([type])
|
|
14
|
+
? Memory.Update(ReturnTypeOperation(type), {}, options)
|
|
15
|
+
: ReturnTypeDeferred(type, options);
|
|
16
|
+
return result;
|
|
13
17
|
}
|
|
14
|
-
export function ReturnTypeInstantiate(context, state, type, options) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
: ReturnTypeDeferred(type, options));
|
|
18
|
+
export function ReturnTypeInstantiate(context, state, type, options = {}) {
|
|
19
|
+
const instantiatedType = InstantiateType(context, state, type);
|
|
20
|
+
return ReturnTypeAction(instantiatedType, options);
|
|
18
21
|
}
|
|
@@ -2,7 +2,7 @@ import { type TSchema } from '../../types/schema.mjs';
|
|
|
2
2
|
import { type TEnum, type TEnumValue } from '../../types/enum.mjs';
|
|
3
3
|
import { type TLiteral, type TLiteralValue } from '../../types/literal.mjs';
|
|
4
4
|
import { type TUnion } from '../../types/union.mjs';
|
|
5
|
-
import { type TTemplateLiteral } from '../../types/template-literal.mjs';
|
|
5
|
+
import { type TTemplateLiteral, TTemplateLiteralDeferred } from '../../types/template-literal.mjs';
|
|
6
6
|
import { type TBigInt, BigIntPattern } from '../../types/bigint.mjs';
|
|
7
7
|
import { type TString, StringPattern } from '../../types/string.mjs';
|
|
8
8
|
import { type TNumber, NumberPattern } from '../../types/number.mjs';
|
|
@@ -10,6 +10,7 @@ import { type TInteger, IntegerPattern } from '../../types/integer.mjs';
|
|
|
10
10
|
import { type TBoolean } from '../../types/boolean.mjs';
|
|
11
11
|
import { NeverPattern } from '../../types/never.mjs';
|
|
12
12
|
import { type TEnumValuesToVariants } from '../enum/enum-to-union.mjs';
|
|
13
|
+
import { type TTemplateLiteralAction } from './instantiate.mjs';
|
|
13
14
|
type TJoinString<Input extends string[], Result extends string = ''> = (Input extends [infer Left extends string, ...infer Right extends string[]] ? Result extends '' ? TJoinString<Right, Left> : TJoinString<Right, `${Result}|${Left}`> : Result);
|
|
14
15
|
type TUnwrapTemplateLiteralPattern<Pattern extends string> = (Pattern extends `^${infer Pattern extends string}$` ? Pattern : never);
|
|
15
16
|
type TEncodeLiteral<Value extends TLiteralValue, Right extends TSchema[], Pattern extends string> = (TEncodeTypes<Right, `${Pattern}${Value}`>);
|
|
@@ -19,9 +20,10 @@ type TEncodeNumber<Right extends TSchema[], Pattern extends string> = (TEncodeTy
|
|
|
19
20
|
type TEncodeBoolean<Right extends TSchema[], Pattern extends string> = (TEncodeType<TUnion<[TLiteral<'false'>, TLiteral<'true'>]>, Right, Pattern>);
|
|
20
21
|
type TEncodeString<Right extends TSchema[], Pattern extends string> = (TEncodeTypes<Right, `${Pattern}${typeof StringPattern}`>);
|
|
21
22
|
type TEncodeTemplateLiteral<TemplatePattern extends string, Right extends TSchema[], Pattern extends string> = (TEncodeTypes<Right, `${Pattern}${TUnwrapTemplateLiteralPattern<TemplatePattern>}`>);
|
|
23
|
+
type TEncodeTemplateLiteralDeferred<Types extends TSchema[], Right extends TSchema[], Pattern extends string, TemplateLiteral extends TSchema = TTemplateLiteralAction<Types>, Result extends TSchema = TEncodeType<TemplateLiteral, Right, Pattern>> = Result;
|
|
22
24
|
type TEncodeEnum<Types extends TEnumValue[], Right extends TSchema[], Pattern extends string, Variants extends TSchema[] = TEnumValuesToVariants<Types>> = TEncodeUnion<Variants, Right, Pattern>;
|
|
23
25
|
type TEncodeUnion<Types extends TSchema[], Right extends TSchema[], Pattern extends string, Result extends string[] = []> = Types extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TEncodeUnion<Tail, Right, Pattern, [...Result, TEncodeType<Head, [], ''>]> : TEncodeTypes<Right, `${Pattern}(${TJoinString<Result>})`>;
|
|
24
|
-
type TEncodeType<Type extends TSchema, Right extends TSchema[], Pattern extends string> = (Type extends TEnum<infer Values extends TEnumValue[]> ? TEncodeEnum<Values, Right, Pattern> : Type extends TInteger ? TEncodeInteger<Right, Pattern> : Type extends TLiteral<infer Value extends TLiteralValue> ? TEncodeLiteral<Value, Right, Pattern> : Type extends TBigInt ? TEncodeBigInt<Right, Pattern> : Type extends TBoolean ? TEncodeBoolean<Right, Pattern> : Type extends TNumber ? TEncodeNumber<Right, Pattern> : Type extends TString ? TEncodeString<Right, Pattern> : Type extends TTemplateLiteral<infer TemplatePattern extends string> ? TEncodeTemplateLiteral<TemplatePattern, Right, Pattern> : Type extends TUnion<infer Types extends TSchema[]> ? TEncodeUnion<Types, Right, Pattern> : typeof NeverPattern);
|
|
26
|
+
type TEncodeType<Type extends TSchema, Right extends TSchema[], Pattern extends string> = (Type extends TEnum<infer Values extends TEnumValue[]> ? TEncodeEnum<Values, Right, Pattern> : Type extends TInteger ? TEncodeInteger<Right, Pattern> : Type extends TLiteral<infer Value extends TLiteralValue> ? TEncodeLiteral<Value, Right, Pattern> : Type extends TBigInt ? TEncodeBigInt<Right, Pattern> : Type extends TBoolean ? TEncodeBoolean<Right, Pattern> : Type extends TNumber ? TEncodeNumber<Right, Pattern> : Type extends TString ? TEncodeString<Right, Pattern> : Type extends TTemplateLiteral<infer TemplatePattern extends string> ? TEncodeTemplateLiteral<TemplatePattern, Right, Pattern> : Type extends TTemplateLiteralDeferred<infer Types extends TSchema[]> ? TEncodeTemplateLiteralDeferred<Types, Right, Pattern> : Type extends TUnion<infer Types extends TSchema[]> ? TEncodeUnion<Types, Right, Pattern> : typeof NeverPattern);
|
|
25
27
|
type TEncodeTypes<Types extends TSchema[], Pattern extends string> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TEncodeType<Left, Right, Pattern> : Pattern);
|
|
26
28
|
type TEncodePattern<Types extends TSchema[], Encoded extends string = TEncodeTypes<Types, ''>, Result extends string = `^${Encoded}$`> = Result;
|
|
27
29
|
/** Encodes a TemplateLiteral type sequence into a TemplateLiteral */
|
|
@@ -3,7 +3,7 @@ import { IsSchema } from '../../types/schema.mjs';
|
|
|
3
3
|
import { IsEnum } from '../../types/enum.mjs';
|
|
4
4
|
import { Literal, IsLiteral } from '../../types/literal.mjs';
|
|
5
5
|
import { Union, IsUnion } from '../../types/union.mjs';
|
|
6
|
-
import { IsTemplateLiteral } from '../../types/template-literal.mjs';
|
|
6
|
+
import { IsTemplateLiteral, IsTemplateLiteralDeferred } from '../../types/template-literal.mjs';
|
|
7
7
|
import { IsBigInt, BigIntPattern } from '../../types/bigint.mjs';
|
|
8
8
|
import { IsString, StringPattern } from '../../types/string.mjs';
|
|
9
9
|
import { IsNumber, NumberPattern } from '../../types/number.mjs';
|
|
@@ -12,6 +12,7 @@ import { IsBoolean } from '../../types/boolean.mjs';
|
|
|
12
12
|
import { NeverPattern } from '../../types/never.mjs';
|
|
13
13
|
import { TemplateLiteralCreate } from './create.mjs';
|
|
14
14
|
import { EnumValuesToVariants } from '../enum/enum-to-union.mjs';
|
|
15
|
+
import { TemplateLiteralAction } from './instantiate.mjs';
|
|
15
16
|
function JoinString(input) {
|
|
16
17
|
return input.join('|');
|
|
17
18
|
}
|
|
@@ -39,6 +40,11 @@ function EncodeString(right, pattern) {
|
|
|
39
40
|
function EncodeTemplateLiteral(templatePattern, right, pattern) {
|
|
40
41
|
return EncodeTypes(right, `${pattern}${UnwrapTemplateLiteralPattern(templatePattern)}`);
|
|
41
42
|
}
|
|
43
|
+
function EncodeTemplateLiteralDeferred(types, right, pattern) {
|
|
44
|
+
const templateLiteral = TemplateLiteralAction(types, {});
|
|
45
|
+
const result = EncodeType(templateLiteral, right, pattern);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
42
48
|
function EncodeEnum(types, right, pattern) {
|
|
43
49
|
const variants = EnumValuesToVariants(types);
|
|
44
50
|
return EncodeUnion(variants, right, pattern);
|
|
@@ -58,8 +64,9 @@ function EncodeType(type, right, pattern) {
|
|
|
58
64
|
IsNumber(type) ? EncodeNumber(right, pattern) :
|
|
59
65
|
IsString(type) ? EncodeString(right, pattern) :
|
|
60
66
|
IsTemplateLiteral(type) ? EncodeTemplateLiteral(type.pattern, right, pattern) :
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
IsTemplateLiteralDeferred(type) ? EncodeTemplateLiteralDeferred(type.parameters[0], right, pattern) :
|
|
68
|
+
IsUnion(type) ? EncodeUnion(type.anyOf, right, pattern) :
|
|
69
|
+
NeverPattern);
|
|
63
70
|
}
|
|
64
71
|
function EncodeTypes(types, pattern) {
|
|
65
72
|
const [left, ...right] = types;
|
|
@@ -3,7 +3,7 @@ import { type TProperties } from '../../types/properties.mjs';
|
|
|
3
3
|
import { type TTemplateLiteralDeferred } from '../../types/template-literal.mjs';
|
|
4
4
|
import { type TTemplateLiteralEncode } from './encode.mjs';
|
|
5
5
|
import { type TState, type TInstantiateTypes, type TCanInstantiate } from '../instantiate.mjs';
|
|
6
|
-
type
|
|
7
|
-
export
|
|
6
|
+
export type TTemplateLiteralAction<Types extends TSchema[], Result extends TSchema = TCanInstantiate<Types> extends true ? TTemplateLiteralEncode<Types> : TTemplateLiteralDeferred<Types>> = Result;
|
|
7
|
+
export declare function TemplateLiteralAction<Types extends TSchema[]>(types: [...Types], options: TSchemaOptions): TTemplateLiteralAction<Types>;
|
|
8
|
+
export type TTemplateLiteralInstantiate<Context extends TProperties, State extends TState, Types extends TSchema[], InstantiatedTypes extends TSchema[] = TInstantiateTypes<Context, State, Types>> = TTemplateLiteralAction<InstantiatedTypes>;
|
|
8
9
|
export declare function TemplateLiteralInstantiate<Context extends TProperties, State extends TState, Types extends TSchema[]>(context: Context, state: State, types: [...Types], options: TSchemaOptions): TTemplateLiteralInstantiate<Context, State, Types>;
|
|
9
|
-
export {};
|
|
@@ -3,12 +3,13 @@ import { Memory } from '../../../system/memory/index.mjs';
|
|
|
3
3
|
import { TemplateLiteralDeferred } from '../../types/template-literal.mjs';
|
|
4
4
|
import { TemplateLiteralEncode } from './encode.mjs';
|
|
5
5
|
import { InstantiateTypes, CanInstantiate } from '../instantiate.mjs';
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
|
|
6
|
+
export function TemplateLiteralAction(types, options) {
|
|
7
|
+
const result = CanInstantiate(types)
|
|
8
|
+
? Memory.Update(TemplateLiteralEncode(types), {}, options)
|
|
9
|
+
: TemplateLiteralDeferred(types, options);
|
|
10
|
+
return result;
|
|
9
11
|
}
|
|
10
12
|
export function TemplateLiteralInstantiate(context, state, types, options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
: TemplateLiteralDeferred(types, options));
|
|
13
|
+
const instantiatedTypes = InstantiateTypes(context, state, types);
|
|
14
|
+
return TemplateLiteralAction(instantiatedTypes, options);
|
|
14
15
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type TSchema } from '../types/schema.mjs';
|
|
2
2
|
import { type TProperties } from '../types/properties.mjs';
|
|
3
3
|
import { type TCyclic } from '../types/cyclic.mjs';
|
|
4
|
+
import { type TUnknown } from '../types/unknown.mjs';
|
|
5
|
+
import { type TUnsafe } from '../types/unsafe.mjs';
|
|
4
6
|
import { type TExtendsLeft } from './extends-left.mjs';
|
|
5
7
|
import { type TCyclicExtends } from '../engine/cyclic/index.mjs';
|
|
6
|
-
type
|
|
8
|
+
type TCanonical<Type extends TSchema> = (Type extends TCyclic ? TCyclicExtends<Type> : Type extends TUnsafe ? TUnknown : Type);
|
|
7
9
|
/** Performs a structural extends check on left and right types and yields inferred types on right if specified. */
|
|
8
|
-
export type TExtends<Inferred extends TProperties, Left extends TSchema, Right extends TSchema,
|
|
10
|
+
export type TExtends<Inferred extends TProperties, Left extends TSchema, Right extends TSchema, CanonicalLeft extends TSchema = TCanonical<Left>, CanonicalRight extends TSchema = TCanonical<Right>> = TExtendsLeft<Inferred, CanonicalLeft, CanonicalRight>;
|
|
9
11
|
/** Performs a structural extends check on left and right types and yields inferred types on right if specified. */
|
|
10
12
|
export declare function Extends<Inferred extends TProperties, Left extends TSchema, Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtends<Inferred, Left, Right>;
|
|
11
13
|
export {};
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { IsCyclic } from '../types/cyclic.mjs';
|
|
3
|
+
import { Unknown } from '../types/unknown.mjs';
|
|
4
|
+
import { IsUnsafe } from '../types/unsafe.mjs';
|
|
3
5
|
import { ExtendsLeft } from './extends-left.mjs';
|
|
4
6
|
import { CyclicExtends } from '../engine/cyclic/index.mjs';
|
|
5
|
-
function
|
|
6
|
-
return (IsCyclic(type)
|
|
7
|
-
?
|
|
8
|
-
|
|
7
|
+
function Canonical(type) {
|
|
8
|
+
return (IsCyclic(type) ? CyclicExtends(type) :
|
|
9
|
+
IsUnsafe(type) ? Unknown() :
|
|
10
|
+
type);
|
|
9
11
|
}
|
|
10
12
|
/** Performs a structural extends check on left and right types and yields inferred types on right if specified. */
|
|
11
13
|
export function Extends(inferred, left, right) {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
return ExtendsLeft(inferred,
|
|
14
|
+
const canonicalLeft = Canonical(left);
|
|
15
|
+
const canonicalRight = Canonical(right);
|
|
16
|
+
return ExtendsLeft(inferred, canonicalLeft, canonicalRight);
|
|
15
17
|
}
|
|
@@ -64,7 +64,7 @@ type TIntrinsicOrCall<Target extends string, Parameters extends T.TSchema[]> = (
|
|
|
64
64
|
] extends ['Pick', [infer Type extends T.TSchema, infer Indexer extends T.TSchema]] ? C.TPickDeferred<Type, Indexer> : [
|
|
65
65
|
Target,
|
|
66
66
|
Parameters
|
|
67
|
-
] extends ['Readonly', [infer Type extends T.TSchema]] ? C.
|
|
67
|
+
] extends ['Readonly', [infer Type extends T.TSchema]] ? C.TReadonlyObjectDeferred<Type> : [
|
|
68
68
|
Target,
|
|
69
69
|
Parameters
|
|
70
70
|
] extends ['Record', [infer Key extends T.TSchema, infer Value extends T.TSchema]] ? T.TRecordDeferred<Key, Value> : [
|
|
@@ -27,7 +27,7 @@ function IntrinsicOrCall(ref, parameters) {
|
|
|
27
27
|
Guard.IsEqual(ref, 'Parameters') ? C.ParametersDeferred(parameters[0]) :
|
|
28
28
|
Guard.IsEqual(ref, 'Partial') ? C.PartialDeferred(parameters[0]) :
|
|
29
29
|
Guard.IsEqual(ref, 'Pick') ? C.PickDeferred(parameters[0], parameters[1]) :
|
|
30
|
-
Guard.IsEqual(ref, 'Readonly') ? C.
|
|
30
|
+
Guard.IsEqual(ref, 'Readonly') ? C.ReadonlyObjectDeferred(parameters[0]) :
|
|
31
31
|
Guard.IsEqual(ref, 'KeyOf') ? C.KeyOfDeferred(parameters[0]) :
|
|
32
32
|
Guard.IsEqual(ref, 'Record') ? T.RecordDeferred(parameters[0], parameters[1]) :
|
|
33
33
|
Guard.IsEqual(ref, 'Required') ? C.RequiredDeferred(parameters[0]) :
|
|
@@ -8,12 +8,19 @@ export declare function RefineAdd<Type extends TSchema>(type: Type, refinement:
|
|
|
8
8
|
export type TRefine<Type extends TSchema = TSchema> = (Type & {
|
|
9
9
|
'~refine': TRefinement<Type>[];
|
|
10
10
|
});
|
|
11
|
-
export type
|
|
11
|
+
export type TRefineCheckCallback<Type extends TSchema = TSchema> = (value: Static<Type>) => boolean;
|
|
12
|
+
export type TRefineErrorCallback<Type extends TSchema = TSchema> = (value: Static<Type>) => string;
|
|
12
13
|
export interface TRefinement<Type extends TSchema = TSchema> {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
check: TRefineCheckCallback<Type>;
|
|
15
|
+
error: TRefineErrorCallback<Type>;
|
|
15
16
|
}
|
|
16
|
-
/**
|
|
17
|
-
export declare function Refine<Type extends TSchema>(type: Type,
|
|
17
|
+
/** Refines a type with an explicit check */
|
|
18
|
+
export declare function Refine<Type extends TSchema>(type: Type, check: TRefineCheckCallback<Type>, error: TRefineErrorCallback<Type>): TRefineAdd<Type>;
|
|
19
|
+
/** Refines a type with an explicit check */
|
|
20
|
+
export declare function Refine<Type extends TSchema>(type: Type, check: TRefineCheckCallback<Type>): TRefineAdd<Type>;
|
|
21
|
+
/** @deprecated Use the error callback signature to generate error message. This overload will be removed in the next version */
|
|
22
|
+
export declare function Refine<Type extends TSchema>(type: Type, check: TRefineCheckCallback<Type>, message: string): TRefineAdd<Type>;
|
|
23
|
+
/** Returns true if the given value is a TRefinement. */
|
|
24
|
+
export declare function IsRefinement(value: unknown): value is TRefinement;
|
|
18
25
|
/** Returns true if the given value is a TRefine. */
|
|
19
|
-
export declare function IsRefine(value: unknown): value is TRefine
|
|
26
|
+
export declare function IsRefine(value: unknown): value is TRefine;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
+
import { Arguments } from '../../system/arguments/index.mjs';
|
|
2
3
|
import { Memory } from '../../system/memory/index.mjs';
|
|
3
4
|
import { Guard } from '../../guard/index.mjs';
|
|
4
5
|
import { IsSchema } from './schema.mjs';
|
|
@@ -7,14 +8,30 @@ export function RefineAdd(type, refinement) {
|
|
|
7
8
|
const refinements = IsRefine(type) ? [...type['~refine'], refinement] : [refinement];
|
|
8
9
|
return Memory.Update(type, { '~refine': refinements }, {});
|
|
9
10
|
}
|
|
10
|
-
/**
|
|
11
|
-
export function Refine(
|
|
12
|
-
|
|
11
|
+
/** Refines a type with an explicit check */
|
|
12
|
+
export function Refine(...args) {
|
|
13
|
+
const [type, check, error_or_message] = Arguments.Match(args, {
|
|
14
|
+
3: (type, check, error) => [type, check, error],
|
|
15
|
+
2: (type, check) => [type, check, () => 'Refine Error'],
|
|
16
|
+
});
|
|
17
|
+
const error = Guard.IsString(error_or_message) ? () => error_or_message : error_or_message;
|
|
18
|
+
return RefineAdd(type, { check, error });
|
|
13
19
|
}
|
|
14
20
|
// ------------------------------------------------------------------
|
|
15
21
|
// Guard
|
|
16
22
|
// ------------------------------------------------------------------
|
|
23
|
+
/** Returns true if the given value is a TRefinement. */
|
|
24
|
+
export function IsRefinement(value) {
|
|
25
|
+
return Guard.IsObjectNotArray(value)
|
|
26
|
+
&& Guard.HasPropertyKey(value, 'check')
|
|
27
|
+
&& Guard.HasPropertyKey(value, 'error')
|
|
28
|
+
&& Guard.IsFunction(value.check)
|
|
29
|
+
&& Guard.IsFunction(value.error);
|
|
30
|
+
}
|
|
17
31
|
/** Returns true if the given value is a TRefine. */
|
|
18
32
|
export function IsRefine(value) {
|
|
19
|
-
return IsSchema(value)
|
|
33
|
+
return IsSchema(value)
|
|
34
|
+
&& Guard.HasPropertyKey(value, '~refine')
|
|
35
|
+
&& Guard.IsArray(value['~refine'])
|
|
36
|
+
&& Guard.Every(value['~refine'], 0, value => IsRefinement(value));
|
|
20
37
|
}
|