typebox 1.0.45 → 1.0.47
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/type/action/index.d.mts +1 -0
- package/build/type/action/index.mjs +1 -0
- package/build/type/action/readonly-type.d.mts +11 -0
- package/build/type/action/readonly-type.mjs +11 -0
- package/build/type/engine/index.d.mts +1 -0
- package/build/type/engine/index.mjs +1 -0
- package/build/type/engine/instantiate.d.mts +4 -0
- package/build/type/engine/instantiate.mjs +9 -7
- package/build/type/engine/readonly-type/from-array.d.mts +5 -0
- package/build/type/engine/readonly-type/from-array.mjs +7 -0
- package/build/type/engine/readonly-type/from-cyclic.d.mts +10 -0
- package/build/type/engine/readonly-type/from-cyclic.mjs +11 -0
- package/build/type/engine/readonly-type/from-intersect.d.mts +5 -0
- package/build/type/engine/readonly-type/from-intersect.mjs +7 -0
- package/build/type/engine/readonly-type/from-object.d.mts +8 -0
- package/build/type/engine/readonly-type/from-object.mjs +11 -0
- package/build/type/engine/readonly-type/from-tuple.d.mts +5 -0
- package/build/type/engine/readonly-type/from-tuple.mjs +7 -0
- package/build/type/engine/readonly-type/from-type.d.mts +16 -0
- package/build/type/engine/readonly-type/from-type.mjs +22 -0
- package/build/type/engine/readonly-type/from-union.d.mts +5 -0
- package/build/type/engine/readonly-type/from-union.mjs +7 -0
- package/build/type/engine/readonly-type/index.d.mts +1 -0
- package/build/type/engine/readonly-type/index.mjs +1 -0
- package/build/type/engine/readonly-type/instantiate.d.mts +9 -0
- package/build/type/engine/readonly-type/instantiate.mjs +14 -0
- package/build/type/script/mapping.d.mts +3 -0
- package/build/type/types/_readonly.d.mts +5 -5
- package/build/type/types/_readonly.mjs +3 -3
- package/build/type/types/template-literal.d.mts +6 -4
- package/build/type/types/template-literal.mjs +9 -4
- package/build/typebox.d.mts +1 -0
- package/build/typebox.mjs +1 -0
- package/package.json +1 -1
|
@@ -20,6 +20,7 @@ export * from './options.mjs';
|
|
|
20
20
|
export * from './parameters.mjs';
|
|
21
21
|
export * from './partial.mjs';
|
|
22
22
|
export * from './pick.mjs';
|
|
23
|
+
export * from './readonly-type.mjs';
|
|
23
24
|
export * from './required.mjs';
|
|
24
25
|
export * from './return-type.mjs';
|
|
25
26
|
export * from './uncapitalize.mjs';
|
|
@@ -20,6 +20,7 @@ export * from './options.mjs';
|
|
|
20
20
|
export * from './parameters.mjs';
|
|
21
21
|
export * from './partial.mjs';
|
|
22
22
|
export * from './pick.mjs';
|
|
23
|
+
export * from './readonly-type.mjs';
|
|
23
24
|
export * from './required.mjs';
|
|
24
25
|
export * from './return-type.mjs';
|
|
25
26
|
export * from './uncapitalize.mjs';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type TSchema, type TSchemaOptions } from '../types/schema.mjs';
|
|
2
|
+
import { type TDeferred } from '../types/deferred.mjs';
|
|
3
|
+
import { type TInstantiate } from '../engine/instantiate.mjs';
|
|
4
|
+
/** Creates a deferred ReadonlyType action. */
|
|
5
|
+
export type TReadonlyTypeDeferred<Type extends TSchema> = (TDeferred<'ReadonlyType', [Type]>);
|
|
6
|
+
/** Creates a deferred ReadonlyType action. */
|
|
7
|
+
export declare function ReadonlyTypeDeferred<Type extends TSchema>(type: Type, options?: TSchemaOptions): TDeferred<"ReadonlyType", [Type]>;
|
|
8
|
+
/** This type is an alias for the TypeScript `Readonly<T>` utility type. */
|
|
9
|
+
export type TReadonlyType<Type extends TSchema> = (TInstantiate<{}, TReadonlyTypeDeferred<Type>>);
|
|
10
|
+
/** This type is an alias for the TypeScript `Readonly<T>` utility type. */
|
|
11
|
+
export declare function ReadonlyType<Type extends TSchema>(type: Type, options?: TSchemaOptions): TReadonlyType<Type>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { Deferred } from '../types/deferred.mjs';
|
|
3
|
+
import { Instantiate } from '../engine/instantiate.mjs';
|
|
4
|
+
/** Creates a deferred ReadonlyType action. */
|
|
5
|
+
export function ReadonlyTypeDeferred(type, options = {}) {
|
|
6
|
+
return Deferred('ReadonlyType', [type], options);
|
|
7
|
+
}
|
|
8
|
+
/** This type is an alias for the TypeScript `Readonly<T>` utility type. */
|
|
9
|
+
export function ReadonlyType(type, options = {}) {
|
|
10
|
+
return Instantiate({}, ReadonlyTypeDeferred(type, options));
|
|
11
|
+
}
|
|
@@ -23,6 +23,7 @@ export * from './parameters/index.mjs';
|
|
|
23
23
|
export * from './patterns/index.mjs';
|
|
24
24
|
export * from './partial/index.mjs';
|
|
25
25
|
export * from './pick/index.mjs';
|
|
26
|
+
export * from './readonly-type/index.mjs';
|
|
26
27
|
export * from './record/index.mjs';
|
|
27
28
|
export * from './ref/index.mjs';
|
|
28
29
|
export * from './required/index.mjs';
|
|
@@ -29,6 +29,7 @@ export * from './parameters/index.mjs';
|
|
|
29
29
|
export * from './patterns/index.mjs';
|
|
30
30
|
export * from './partial/index.mjs';
|
|
31
31
|
export * from './pick/index.mjs';
|
|
32
|
+
export * from './readonly-type/index.mjs';
|
|
32
33
|
export * from './record/index.mjs';
|
|
33
34
|
export * from './ref/index.mjs';
|
|
34
35
|
export * from './required/index.mjs';
|
|
@@ -42,6 +42,7 @@ import { type TOptionsInstantiate } from './options/instantiate.mjs';
|
|
|
42
42
|
import { type TParametersInstantiate } from './parameters/instantiate.mjs';
|
|
43
43
|
import { type TPartialInstantiate } from './partial/instantiate.mjs';
|
|
44
44
|
import { type TPickInstantiate } from './pick/instantiate.mjs';
|
|
45
|
+
import { type TReadonlyTypeInstantiate } from './readonly-type/instantiate.mjs';
|
|
45
46
|
import { type TRecordInstantiate } from './record/instantiate.mjs';
|
|
46
47
|
import { type TRefInstantiate } from './ref/instantiate.mjs';
|
|
47
48
|
import { type TRequiredInstantiate } from './required/instantiate.mjs';
|
|
@@ -136,6 +137,9 @@ type TInstantiateDeferred<Context extends TProperties, State extends TState, Act
|
|
|
136
137
|
] extends ['Omit', [infer Type extends TSchema, infer Indexer extends TSchema]] ? TOmitInstantiate<Context, State, Type, Indexer> : [
|
|
137
138
|
Action,
|
|
138
139
|
Parameters
|
|
140
|
+
] extends ['ReadonlyType', [infer Type extends TSchema]] ? TReadonlyTypeInstantiate<Context, State, Type> : [
|
|
141
|
+
Action,
|
|
142
|
+
Parameters
|
|
139
143
|
] extends ['Record', [infer Key extends TSchema, infer Value extends TSchema]] ? TRecordInstantiate<Context, State, Key, Value> : [
|
|
140
144
|
Action,
|
|
141
145
|
Parameters
|
|
@@ -55,6 +55,7 @@ import { OptionsInstantiate } from './options/instantiate.mjs';
|
|
|
55
55
|
import { ParametersInstantiate } from './parameters/instantiate.mjs';
|
|
56
56
|
import { PartialInstantiate } from './partial/instantiate.mjs';
|
|
57
57
|
import { PickInstantiate } from './pick/instantiate.mjs';
|
|
58
|
+
import { ReadonlyTypeInstantiate } from './readonly-type/instantiate.mjs';
|
|
58
59
|
import { RecordInstantiate } from './record/instantiate.mjs';
|
|
59
60
|
import { RefInstantiate } from './ref/instantiate.mjs';
|
|
60
61
|
import { RequiredInstantiate } from './required/instantiate.mjs';
|
|
@@ -131,13 +132,14 @@ function InstantiateDeferred(context, state, action, parameters, options) {
|
|
|
131
132
|
Guard.IsEqual(action, 'Parameters') ? ParametersInstantiate(context, state, parameters[0], options) :
|
|
132
133
|
Guard.IsEqual(action, 'Partial') ? PartialInstantiate(context, state, parameters[0], options) :
|
|
133
134
|
Guard.IsEqual(action, 'Omit') ? OmitInstantiate(context, state, parameters[0], parameters[1], options) :
|
|
134
|
-
Guard.IsEqual(action, '
|
|
135
|
-
Guard.IsEqual(action, '
|
|
136
|
-
Guard.IsEqual(action, '
|
|
137
|
-
Guard.IsEqual(action, '
|
|
138
|
-
Guard.IsEqual(action, '
|
|
139
|
-
Guard.IsEqual(action, '
|
|
140
|
-
|
|
135
|
+
Guard.IsEqual(action, 'ReadonlyType') ? ReadonlyTypeInstantiate(context, state, parameters[0], options) :
|
|
136
|
+
Guard.IsEqual(action, 'Record') ? RecordInstantiate(context, state, parameters[0], parameters[1], options) :
|
|
137
|
+
Guard.IsEqual(action, 'Required') ? RequiredInstantiate(context, state, parameters[0], options) :
|
|
138
|
+
Guard.IsEqual(action, 'ReturnType') ? ReturnTypeInstantiate(context, state, parameters[0], options) :
|
|
139
|
+
Guard.IsEqual(action, 'TemplateLiteral') ? TemplateLiteralInstantiate(context, state, parameters[0], options) :
|
|
140
|
+
Guard.IsEqual(action, 'Uncapitalize') ? UncapitalizeInstantiate(context, state, parameters[0], options) :
|
|
141
|
+
Guard.IsEqual(action, 'Uppercase') ? UppercaseInstantiate(context, state, parameters[0], options) :
|
|
142
|
+
Deferred(action, parameters, options));
|
|
141
143
|
}
|
|
142
144
|
export function InstantiateType(context, state, input) {
|
|
143
145
|
const isImmutable = IsImmutable(input);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TArray } from '../../types/array.mjs';
|
|
3
|
+
import { type TImmutableAdd } from '../../types/_immutable.mjs';
|
|
4
|
+
export type TFromArray<Type extends TSchema, Result extends TSchema = TImmutableAdd<TArray<Type>>> = Result;
|
|
5
|
+
export declare function FromArray<Type extends TSchema>(type: Type): TFromArray<Type>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Memory } from '../../../system/memory/index.mjs';
|
|
2
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
3
|
+
import { type TCyclic } from '../../types/cyclic.mjs';
|
|
4
|
+
import { type TProperties } from '../../types/properties.mjs';
|
|
5
|
+
import { type TFromType } from './from-type.mjs';
|
|
6
|
+
import { type TCyclicTarget } from '../cyclic/target.mjs';
|
|
7
|
+
export type TFromCyclic<Defs extends TProperties, Ref extends string, Target extends TSchema = TCyclicTarget<Defs, Ref>, Partial extends TSchema = TFromType<Target>, Result extends TSchema = TCyclic<Memory.TAssign<Defs, {
|
|
8
|
+
[_ in Ref]: Partial;
|
|
9
|
+
}>, Ref>> = Result;
|
|
10
|
+
export declare function FromCyclic<Defs extends TProperties, Ref extends string>(defs: Defs, ref: Ref): TFromCyclic<Defs, Ref>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { Memory } from '../../../system/memory/index.mjs';
|
|
3
|
+
import { Cyclic } from '../../types/cyclic.mjs';
|
|
4
|
+
import { FromType } from './from-type.mjs';
|
|
5
|
+
import { CyclicTarget } from '../cyclic/target.mjs';
|
|
6
|
+
export function FromCyclic(defs, ref) {
|
|
7
|
+
const target = CyclicTarget(defs, ref);
|
|
8
|
+
const partial = FromType(target);
|
|
9
|
+
const result = Cyclic(Memory.Assign(defs, { [ref]: partial }), ref);
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TFromType } from './from-type.mjs';
|
|
3
|
+
import { type TEvaluateIntersect } from '../evaluate/evaluate.mjs';
|
|
4
|
+
export type TFromIntersect<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromIntersect<Right, [...Result, TFromType<Left>]> : TEvaluateIntersect<Result>);
|
|
5
|
+
export declare function FromIntersect<Types extends TSchema[]>(types: [...Types]): TFromIntersect<Types>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TObject } from '../../types/object.mjs';
|
|
3
|
+
import { type TReadonlyAdd } from '../../types/_readonly.mjs';
|
|
4
|
+
import { type TProperties } from '../../types/properties.mjs';
|
|
5
|
+
export type TFromObject<Properties extends TProperties, Mapped extends TProperties = {
|
|
6
|
+
[Key in keyof Properties]: TReadonlyAdd<Properties[Key]>;
|
|
7
|
+
}, Result extends TSchema = TObject<Mapped>> = Result;
|
|
8
|
+
export declare function FromObject<Properties extends TProperties>(properties: Properties): TFromObject<Properties>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { Guard } from '../../../guard/index.mjs';
|
|
3
|
+
import { Object } from '../../types/object.mjs';
|
|
4
|
+
import { Readonly } from '../../types/_readonly.mjs';
|
|
5
|
+
export function FromObject(properties) {
|
|
6
|
+
const mapped = Guard.Keys(properties).reduce((result, left) => {
|
|
7
|
+
return { ...result, [left]: Readonly(properties[left]) };
|
|
8
|
+
}, {});
|
|
9
|
+
const result = Object(mapped);
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TTuple } from '../../types/tuple.mjs';
|
|
3
|
+
import { type TImmutableAdd } from '../../types/_immutable.mjs';
|
|
4
|
+
export type TFromTuple<Types extends TSchema[], Result extends TSchema = TImmutableAdd<TTuple<Types>>> = Result;
|
|
5
|
+
export declare function FromTuple<Types extends TSchema[]>(types: [...Types]): TFromTuple<Types>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TArray } from '../../types/array.mjs';
|
|
3
|
+
import { type TCyclic } from '../../types/cyclic.mjs';
|
|
4
|
+
import { type TIntersect } from '../../types/intersect.mjs';
|
|
5
|
+
import { type TObject } from '../../types/object.mjs';
|
|
6
|
+
import { type TProperties } from '../../types/properties.mjs';
|
|
7
|
+
import { type TTuple } from '../../types/tuple.mjs';
|
|
8
|
+
import { type TUnion } from '../../types/union.mjs';
|
|
9
|
+
import { type TFromArray } from './from-array.mjs';
|
|
10
|
+
import { type TFromCyclic } from './from-cyclic.mjs';
|
|
11
|
+
import { type TFromIntersect } from './from-intersect.mjs';
|
|
12
|
+
import { type TFromObject } from './from-object.mjs';
|
|
13
|
+
import { type TFromTuple } from './from-tuple.mjs';
|
|
14
|
+
import { type TFromUnion } from './from-union.mjs';
|
|
15
|
+
export type TFromType<Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TFromArray<Type> : Type extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic<Defs, Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type);
|
|
16
|
+
export declare function FromType<Type extends TSchema>(type: Type): TFromType<Type>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { IsArray } from '../../types/array.mjs';
|
|
3
|
+
import { IsCyclic } from '../../types/cyclic.mjs';
|
|
4
|
+
import { IsIntersect } from '../../types/intersect.mjs';
|
|
5
|
+
import { IsObject } from '../../types/object.mjs';
|
|
6
|
+
import { IsTuple } from '../../types/tuple.mjs';
|
|
7
|
+
import { IsUnion } from '../../types/union.mjs';
|
|
8
|
+
import { FromArray } from './from-array.mjs';
|
|
9
|
+
import { FromCyclic } from './from-cyclic.mjs';
|
|
10
|
+
import { FromIntersect } from './from-intersect.mjs';
|
|
11
|
+
import { FromObject } from './from-object.mjs';
|
|
12
|
+
import { FromTuple } from './from-tuple.mjs';
|
|
13
|
+
import { FromUnion } from './from-union.mjs';
|
|
14
|
+
export function FromType(type) {
|
|
15
|
+
return (IsArray(type) ? FromArray(type.items) :
|
|
16
|
+
IsCyclic(type) ? FromCyclic(type.$defs, type.$ref) :
|
|
17
|
+
IsIntersect(type) ? FromIntersect(type.allOf) :
|
|
18
|
+
IsObject(type) ? FromObject(type.properties) :
|
|
19
|
+
IsTuple(type) ? FromTuple(type.items) :
|
|
20
|
+
IsUnion(type) ? FromUnion(type.anyOf) :
|
|
21
|
+
type);
|
|
22
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TSchema } from '../../types/schema.mjs';
|
|
2
|
+
import { type TUnion } from '../../types/union.mjs';
|
|
3
|
+
import { type TFromType } from './from-type.mjs';
|
|
4
|
+
export type TFromUnion<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion<Right, [...Result, TFromType<Left>]> : TUnion<Result>);
|
|
5
|
+
export declare function FromUnion<Types extends TSchema[]>(types: [...Types]): TFromUnion<Types>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './instantiate.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './instantiate.mjs';
|
|
@@ -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 TReadonlyTypeDeferred } from '../../action/readonly-type.mjs';
|
|
4
|
+
import { type TFromType } from './from-type.mjs';
|
|
5
|
+
import { type TState, type TInstantiateType, type TCanInstantiate } from '../instantiate.mjs';
|
|
6
|
+
type TReadonlyTypeImmediate<Context extends TProperties, State extends TState, Type extends TSchema, InstantiatedType extends TSchema = TInstantiateType<Context, State, Type>> = TFromType<InstantiatedType>;
|
|
7
|
+
export type TReadonlyTypeInstantiate<Context extends TProperties, State extends TState, Type extends TSchema> = TCanInstantiate<Context, [Type]> extends true ? TReadonlyTypeImmediate<Context, State, Type> : TReadonlyTypeDeferred<Type>;
|
|
8
|
+
export declare function ReadonlyTypeInstantiate<Context extends TProperties, State extends TState, Type extends TSchema>(context: Context, state: State, type: Type, options: TSchemaOptions): TReadonlyTypeInstantiate<Context, State, Type>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// deno-fmt-ignore-file
|
|
2
|
+
import { Memory } from '../../../system/memory/index.mjs';
|
|
3
|
+
import { ReadonlyTypeDeferred } from '../../action/readonly-type.mjs';
|
|
4
|
+
import { FromType } from './from-type.mjs';
|
|
5
|
+
import { InstantiateType, CanInstantiate } from '../instantiate.mjs';
|
|
6
|
+
function ReadonlyTypeImmediate(context, state, type, options) {
|
|
7
|
+
const instantiatedType = InstantiateType(context, state, type);
|
|
8
|
+
return Memory.Update(FromType(instantiatedType), {}, options);
|
|
9
|
+
}
|
|
10
|
+
export function ReadonlyTypeInstantiate(context, state, type, options) {
|
|
11
|
+
return (CanInstantiate(context, [type])
|
|
12
|
+
? ReadonlyTypeImmediate(context, state, type, options)
|
|
13
|
+
: ReadonlyTypeDeferred(type, options));
|
|
14
|
+
}
|
|
@@ -64,6 +64,9 @@ 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.TReadonlyTypeDeferred<Type> : [
|
|
68
|
+
Target,
|
|
69
|
+
Parameters
|
|
67
70
|
] extends ['Record', [infer Key extends T.TSchema, infer Value extends T.TSchema]] ? T.TRecordDeferred<Key, Value> : [
|
|
68
71
|
Target,
|
|
69
72
|
Parameters
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { type TSchema } from './schema.mjs';
|
|
2
|
-
/** Removes
|
|
2
|
+
/** Removes a Readonly property modifier from the given type. */
|
|
3
3
|
export type TReadonlyRemove<Type extends TSchema, Result extends TSchema = Type extends TReadonly<infer Type extends TSchema> ? Type : Type> = Result;
|
|
4
|
-
/** Removes
|
|
4
|
+
/** Removes a Readonly property modifier from the given type. */
|
|
5
5
|
export declare function ReadonlyRemove<Type extends TSchema>(type: Type): TReadonlyRemove<Type>;
|
|
6
|
-
/** Adds Readonly to the given type. */
|
|
6
|
+
/** Adds a Readonly property modifier to the given type. */
|
|
7
7
|
export type TReadonlyAdd<Type extends TSchema = TSchema> = ('~readonly' extends keyof Type ? Type : TReadonly<Type>);
|
|
8
|
-
/** Adds Readonly to the given type. */
|
|
8
|
+
/** Adds a Readonly property modifier to the given type. */
|
|
9
9
|
export declare function ReadonlyAdd<Type extends TSchema>(type: Type): TReadonlyAdd<Type>;
|
|
10
10
|
export type TReadonly<Type extends TSchema = TSchema> = (Type & {
|
|
11
11
|
'~readonly': true;
|
|
12
12
|
});
|
|
13
|
-
/** Applies an Readonly modifier to the given type. */
|
|
13
|
+
/** Applies an Readonly property modifier to the given type. */
|
|
14
14
|
export declare function Readonly<Type extends TSchema>(type: Type): TReadonlyAdd<Type>;
|
|
15
15
|
/** Returns true if the given value is a TReadonly */
|
|
16
16
|
export declare function IsReadonly(value: unknown): value is TReadonly<TSchema>;
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
import { Memory } from '../../system/memory/index.mjs';
|
|
3
3
|
import { Guard } from '../../guard/index.mjs';
|
|
4
4
|
import { IsSchema } from './schema.mjs';
|
|
5
|
-
/** Removes
|
|
5
|
+
/** Removes a Readonly property modifier from the given type. */
|
|
6
6
|
export function ReadonlyRemove(type) {
|
|
7
7
|
return Memory.Discard(type, ['~readonly']);
|
|
8
8
|
}
|
|
9
|
-
/** Adds Readonly to the given type. */
|
|
9
|
+
/** Adds a Readonly property modifier to the given type. */
|
|
10
10
|
export function ReadonlyAdd(type) {
|
|
11
11
|
return Memory.Update(type, { '~readonly': true }, {});
|
|
12
12
|
}
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
// Factory
|
|
15
15
|
// ------------------------------------------------------------------
|
|
16
|
-
/** Applies an Readonly modifier to the given type. */
|
|
16
|
+
/** Applies an Readonly property modifier to the given type. */
|
|
17
17
|
export function Readonly(type) {
|
|
18
18
|
return ReadonlyAdd(type);
|
|
19
19
|
}
|
|
@@ -14,11 +14,13 @@ export interface TTemplateLiteral<Pattern extends string = string> extends TSche
|
|
|
14
14
|
export type TTemplateLiteralDeferred<Types extends TSchema[]> = (TDeferred<'TemplateLiteral', [Types]>);
|
|
15
15
|
/** Creates a deferred TemplateLiteral action. */
|
|
16
16
|
export declare function TemplateLiteralDeferred<Types extends TSchema[]>(types: [...Types], options?: TSchemaOptions): TTemplateLiteralDeferred<Types>;
|
|
17
|
-
export type
|
|
18
|
-
export declare function
|
|
17
|
+
export type TTemplateLiteralFromTypes<Types extends TSchema[], Result extends TSchema = TInstantiate<{}, TTemplateLiteralDeferred<Types>>> = Result;
|
|
18
|
+
export declare function TemplateLiteralFromTypes<Types extends TSchema[]>(types: [...Types]): TTemplateLiteralFromTypes<Types>;
|
|
19
|
+
export type TTemplateLiteralFromString<Template extends string, Types extends TSchema[] = TParseTemplateIntoTypes<Template>, Result extends TSchema = TTemplateLiteralFromTypes<Types>> = Result;
|
|
20
|
+
export declare function TemplateLiteralFromString<Template extends string>(template: Template): TTemplateLiteralFromString<Template>;
|
|
19
21
|
/** Creates a TemplateLiteral type. */
|
|
20
|
-
export declare function TemplateLiteral<Template extends string>(template: Template, options?: TSchemaOptions):
|
|
22
|
+
export declare function TemplateLiteral<Template extends string>(template: Template, options?: TSchemaOptions): TTemplateLiteralFromString<Template>;
|
|
21
23
|
/** Creates a TemplateLiteral type. */
|
|
22
|
-
export declare function TemplateLiteral<Types extends TSchema[]>(types: [...Types], options?: TSchemaOptions):
|
|
24
|
+
export declare function TemplateLiteral<Types extends TSchema[]>(types: [...Types], options?: TSchemaOptions): TTemplateLiteralFromTypes<Types>;
|
|
23
25
|
/** Returns true if the given value is TTemplateLiteral. */
|
|
24
26
|
export declare function IsTemplateLiteral(value: unknown): value is TTemplateLiteral;
|
|
@@ -5,17 +5,22 @@ import { IsKind } from './schema.mjs';
|
|
|
5
5
|
import { Deferred } from './deferred.mjs';
|
|
6
6
|
import { ParseTemplateIntoTypes } from '../engine/patterns/template.mjs';
|
|
7
7
|
import { Instantiate } from '../engine/instantiate.mjs';
|
|
8
|
+
import { Memory } from '../../system/system.mjs';
|
|
8
9
|
/** Creates a deferred TemplateLiteral action. */
|
|
9
10
|
export function TemplateLiteralDeferred(types, options = {}) {
|
|
10
11
|
return Deferred('TemplateLiteral', [types], options);
|
|
11
12
|
}
|
|
12
|
-
export function
|
|
13
|
-
return Instantiate({}, TemplateLiteralDeferred(types,
|
|
13
|
+
export function TemplateLiteralFromTypes(types) {
|
|
14
|
+
return Instantiate({}, TemplateLiteralDeferred(types, {}));
|
|
15
|
+
}
|
|
16
|
+
export function TemplateLiteralFromString(template) {
|
|
17
|
+
const types = ParseTemplateIntoTypes(template);
|
|
18
|
+
return TemplateLiteralFromTypes(types);
|
|
14
19
|
}
|
|
15
20
|
/** Creates a TemplateLiteral type. */
|
|
16
21
|
export function TemplateLiteral(input, options = {}) {
|
|
17
|
-
const
|
|
18
|
-
return
|
|
22
|
+
const type = Guard.IsString(input) ? TemplateLiteralFromString(input) : TemplateLiteralFromTypes(input);
|
|
23
|
+
return Memory.Update(type, {}, options);
|
|
19
24
|
}
|
|
20
25
|
// ------------------------------------------------------------------
|
|
21
26
|
// Guard
|
package/build/typebox.d.mts
CHANGED
|
@@ -21,6 +21,7 @@ export { Options, type TOptions } from './type/action/options.mjs';
|
|
|
21
21
|
export { Parameters, type TParameters, type TParametersDeferred } from './type/action/parameters.mjs';
|
|
22
22
|
export { Partial, type TPartial, type TPartialDeferred } from './type/action/partial.mjs';
|
|
23
23
|
export { Pick, type TPick, type TPickDeferred } from './type/action/pick.mjs';
|
|
24
|
+
export { ReadonlyType, type TReadonlyType, type TReadonlyTypeDeferred } from './type/action/readonly-type.mjs';
|
|
24
25
|
export { Required, type TRequired, type TRequiredDeferred } from './type/action/required.mjs';
|
|
25
26
|
export { ReturnType, type TReturnType, type TReturnTypeDeferred } from './type/action/return-type.mjs';
|
|
26
27
|
export { type TUncapitalize, type TUncapitalizeDeferred, Uncapitalize } from './type/action/uncapitalize.mjs';
|
package/build/typebox.mjs
CHANGED
|
@@ -33,6 +33,7 @@ export { Options } from './type/action/options.mjs';
|
|
|
33
33
|
export { Parameters } from './type/action/parameters.mjs';
|
|
34
34
|
export { Partial } from './type/action/partial.mjs';
|
|
35
35
|
export { Pick } from './type/action/pick.mjs';
|
|
36
|
+
export { ReadonlyType } from './type/action/readonly-type.mjs';
|
|
36
37
|
export { Required } from './type/action/required.mjs';
|
|
37
38
|
export { ReturnType } from './type/action/return-type.mjs';
|
|
38
39
|
export { Uncapitalize } from './type/action/uncapitalize.mjs';
|