@sinclair/typebox 0.34.22 → 0.34.24

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.
@@ -36,13 +36,58 @@ const Dereference = (context, key) => {
36
36
  return key in context ? context[key] : t.Ref(key);
37
37
  };
38
38
  // ------------------------------------------------------------------
39
+ // GenericArgumentList
40
+ // ------------------------------------------------------------------
41
+ // prettier-ignore
42
+ const GenericArgumentListMapping = (results) => {
43
+ return (results.length === 3 ? [results[0], ...results[2]] :
44
+ results.length === 2 ? [results[0]] :
45
+ results.length === 1 ? [results[0]] :
46
+ []);
47
+ };
48
+ // prettier-ignore
49
+ const GenericArgumentList = Runtime.Union([
50
+ Runtime.Tuple([Runtime.Ident(), Runtime.Const(Comma), Runtime.Ref('GenericArgumentList')]),
51
+ Runtime.Tuple([Runtime.Ident(), Runtime.Const(Comma)]),
52
+ Runtime.Tuple([Runtime.Ident()]),
53
+ Runtime.Tuple([]),
54
+ ], (results) => GenericArgumentListMapping(results));
55
+ // ------------------------------------------------------------------
56
+ // GenericArguments
57
+ // ------------------------------------------------------------------
58
+ // prettier-ignore
59
+ const GenericArgumentsContext = (args) => {
60
+ return args.reduce((result, arg, index) => {
61
+ return { ...result, [arg]: t.Argument(index) };
62
+ }, {});
63
+ };
64
+ // prettier-ignore
65
+ const GenericArgumentsMapping = (results) => {
66
+ return results.length === 3
67
+ ? GenericArgumentsContext(results[1])
68
+ : {};
69
+ };
70
+ // prettier-ignore
71
+ const GenericArguments = Runtime.Tuple([
72
+ Runtime.Const(LAngle),
73
+ Runtime.Ref('GenericArgumentList'),
74
+ Runtime.Const(RAngle),
75
+ ], results => GenericArgumentsMapping(results));
76
+ // ------------------------------------------------------------------
39
77
  // GenericReference
40
78
  // ------------------------------------------------------------------
41
79
  function GenericReferenceMapping(results, context) {
42
- const target = Dereference(context, results[0]);
43
- return t.Instantiate(target, results[2]);
80
+ const type = Dereference(context, results[0]);
81
+ const args = results[2];
82
+ return t.Instantiate(type, args);
44
83
  }
45
- const GenericReference = Runtime.Tuple([Runtime.Ident(), Runtime.Const(LAngle), Runtime.Ref('Elements'), Runtime.Const(RAngle)], (results, context) => GenericReferenceMapping(results, context));
84
+ // prettier-ignore
85
+ const GenericReference = Runtime.Tuple([
86
+ Runtime.Ident(),
87
+ Runtime.Const(LAngle),
88
+ Runtime.Ref('Elements'),
89
+ Runtime.Const(RAngle)
90
+ ], (results, context) => GenericReferenceMapping(results, context));
46
91
  // ------------------------------------------------------------------
47
92
  // Reference
48
93
  // ------------------------------------------------------------------
@@ -603,6 +648,11 @@ const Uint8Array = Runtime.Const('Uint8Array', Runtime.As(t.Uint8Array()));
603
648
  // ------------------------------------------------------------------
604
649
  // prettier-ignore
605
650
  export const Module = new Runtime.Module({
651
+ // ----------------------------------------------------------------
652
+ // Generic Arguments
653
+ // ----------------------------------------------------------------
654
+ GenericArgumentList,
655
+ GenericArguments,
606
656
  // ----------------------------------------------------------------
607
657
  // Type Expressions
608
658
  // ----------------------------------------------------------------
@@ -42,8 +42,29 @@ type Delimit<Parser extends Static.IParser, Delimiter extends Static.IParser> =
42
42
  Static.Tuple<[]>
43
43
  ], DelimitMapping>);
44
44
  type Dereference<Context extends t.TProperties, Ref extends string> = (Ref extends keyof Context ? Context[Ref] : t.TRef<Ref>);
45
+ interface GenericArgumentListMapping extends Static.IMapping {
46
+ output: (this['input'] extends [infer Ident extends string, Comma, infer Rest extends unknown[]] ? [Ident, ...Rest] : this['input'] extends [infer Ident extends string, Comma] ? [Ident] : this['input'] extends [infer Ident extends string] ? [Ident] : [
47
+ ]);
48
+ }
49
+ type GenericArgumentList = Static.Union<[
50
+ Static.Tuple<[Static.Ident, Static.Const<Comma>, GenericArgumentList]>,
51
+ Static.Tuple<[Static.Ident, Static.Const<Comma>]>,
52
+ Static.Tuple<[Static.Ident]>,
53
+ Static.Tuple<[]>
54
+ ], GenericArgumentListMapping>;
55
+ type GenericArgumentsContext<Args extends string[], Result extends t.TProperties = {}> = (Args extends [...infer Left extends string[], infer Right extends string] ? GenericArgumentsContext<Left, Result & {
56
+ [_ in Right]: t.TArgument<Left['length']>;
57
+ }> : t.Evaluate<Result>);
58
+ interface GenericArgumentsMapping extends Static.IMapping {
59
+ output: this['input'] extends [LAngle, infer Args extends string[], RAngle] ? GenericArgumentsContext<Args> : never;
60
+ }
61
+ export type GenericArguments = Static.Tuple<[
62
+ Static.Const<LAngle>,
63
+ GenericArgumentList,
64
+ Static.Const<RAngle>
65
+ ], GenericArgumentsMapping>;
45
66
  interface GenericReferenceMapping extends Static.IMapping {
46
- output: this['context'] extends t.TProperties ? this['input'] extends [infer Reference extends string, LAngle, infer Parameters extends t.TSchema[], RAngle] ? t.TInstantiate<Dereference<this['context'], Reference>, [...Parameters]> : never : never;
67
+ output: this['context'] extends t.TProperties ? this['input'] extends [infer Reference extends string, LAngle, infer Args extends t.TSchema[], RAngle] ? t.TInstantiate<Dereference<this['context'], Reference>, Args> : never : never;
47
68
  }
48
69
  type GenericReference = Static.Tuple<[
49
70
  Static.Ident,
@@ -1,33 +1,31 @@
1
- import * as Types from '../type/index.mjs';
1
+ import * as t from '../type/index.mjs';
2
2
  import { Static } from '../parser/index.mjs';
3
- import { Type } from './static.mjs';
4
- /** Parses a TSchema type from TypeScript syntax but does not infer schematics */
5
- export declare function NoInfer<Context extends Record<PropertyKey, Types.TSchema>, Code extends string>(context: Context, code: Code, options?: Types.SchemaOptions): Types.TSchema | undefined;
6
- /** Parses a TSchema type from TypeScript syntax but does not infer schematics */
7
- export declare function NoInfer<Code extends string>(code: Code, options?: Types.SchemaOptions): Types.TSchema | undefined;
8
- /** Infers a TSchema type from TypeScript syntax. */
9
- export type TSyntax<Context extends Record<PropertyKey, Types.TSchema>, Code extends string> = (Static.Parse<Type, Code, Context> extends [infer Type extends Types.TSchema, string] ? Type : Types.TNever);
10
- /** Parses a TSchema type from TypeScript syntax */
11
- export declare function Syntax<Context extends Record<PropertyKey, Types.TSchema>, Code extends string>(context: Context, code: Code, options?: Types.SchemaOptions): TSyntax<Context, Code>;
12
- /** Parses a TSchema type from TypeScript syntax */
13
- export declare function Syntax<Code extends string>(code: Code, options?: Types.SchemaOptions): TSyntax<{}, Code>;
3
+ import { Type, GenericArguments } from './static.mjs';
4
+ type TParseSyntax<Context extends Record<PropertyKey, t.TSchema>, Code extends string> = (Static.Parse<GenericArguments, Code, {}> extends [infer Args extends t.TProperties, infer Rest extends string] ? Static.Parse<Type, Rest, Context & Args> : Static.Parse<Type, Code, Context>);
5
+ /** Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
6
+ export declare function NoInfer<Context extends Record<PropertyKey, t.TSchema>, Code extends string>(context: Context, code: Code, options?: t.SchemaOptions): t.TSchema;
7
+ /** Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
8
+ export declare function NoInfer<Code extends string>(code: Code, options?: t.SchemaOptions): t.TSchema;
9
+ /** Parses a TypeScript annotation into a TypeBox type */
10
+ export type TSyntax<Context extends Record<PropertyKey, t.TSchema>, Code extends string> = (TParseSyntax<Context, Code> extends [infer Type extends t.TSchema, string] ? Type : t.TNever);
11
+ /** Parses a TypeScript annotation into a TypeBox type */
12
+ export declare function Syntax<Context extends Record<PropertyKey, t.TSchema>, Annotation extends string>(context: Context, annotation: Annotation, options?: t.SchemaOptions): TSyntax<Context, Annotation>;
13
+ /** Parses a TypeScript annotation into a TypeBox type */
14
+ export declare function Syntax<Annotation extends string>(annotation: Annotation, options?: t.SchemaOptions): TSyntax<{}, Annotation>;
14
15
  /**
15
- * Parses a TSchema type from Syntax.
16
16
  * @deprecated Use Syntax() function
17
17
  */
18
- export declare function Parse<Context extends Record<PropertyKey, Types.TSchema>, Code extends string>(context: Context, code: Code, options?: Types.SchemaOptions): TSyntax<Context, Code>;
18
+ export declare function Parse<Context extends Record<PropertyKey, t.TSchema>, Annotation extends string>(context: Context, annotation: Annotation, options?: t.SchemaOptions): TSyntax<Context, Annotation>;
19
19
  /**
20
- * Parses a TSchema type from Syntax.
21
20
  * @deprecated Use Syntax() function
22
21
  */
23
- export declare function Parse<Code extends string>(code: Code, options?: Types.SchemaOptions): TSyntax<{}, Code>;
22
+ export declare function Parse<Annotation extends string>(annotation: Annotation, options?: t.SchemaOptions): TSyntax<{}, Annotation>;
24
23
  /**
25
- * Parses a TSchema from TypeScript Syntax
26
24
  * @deprecated Use NoInfer() function
27
25
  */
28
- export declare function ParseOnly<Context extends Record<PropertyKey, Types.TSchema>, Code extends string>(context: Context, code: Code, options?: Types.SchemaOptions): Types.TSchema | undefined;
26
+ export declare function ParseOnly<Context extends Record<PropertyKey, t.TSchema>, Code extends string>(context: Context, code: Code, options?: t.SchemaOptions): t.TSchema | undefined;
29
27
  /**
30
- * Parses a TSchema from TypeScript Syntax
31
28
  * @deprecated Use NoInfer() function
32
29
  */
33
- export declare function ParseOnly<Code extends string>(code: Code, options?: Types.SchemaOptions): Types.TSchema | undefined;
30
+ export declare function ParseOnly<Code extends string>(code: Code, options?: t.SchemaOptions): t.TSchema | undefined;
31
+ export {};
@@ -1,28 +1,33 @@
1
- import * as Types from '../type/index.mjs';
1
+ import * as t from '../type/index.mjs';
2
2
  import { Module } from './runtime.mjs';
3
- /** Parses a TSchema type from TypeScript syntax but does not infer schematics */
3
+ // prettier-ignore
4
+ function ParseSyntax(context, code) {
5
+ const results = Module.Parse('GenericArguments', code, {}); // [ArgumentContext, Rest]
6
+ return (results.length === 2
7
+ ? Module.Parse('Type', results[1], { ...context, ...results[0] })
8
+ : Module.Parse('Type', code, context));
9
+ }
10
+ /** Parses a TypeScript annotation into a TypeBox type but does not infer schematics */
4
11
  // prettier-ignore
5
12
  export function NoInfer(...args) {
6
13
  const withContext = typeof args[0] === 'string' ? false : true;
7
14
  const [context, code, options] = withContext ? [args[0], args[1], args[2] || {}] : [{}, args[0], args[1] || {}];
8
- const type = Module.Parse('Type', code, context)[0];
9
- return Types.KindGuard.IsSchema(type)
10
- ? Types.CloneType(type, options)
11
- : Types.Never(options);
15
+ const result = ParseSyntax(context, code)[0];
16
+ return t.KindGuard.IsSchema(result)
17
+ ? t.CloneType(result, options)
18
+ : t.Never(options);
12
19
  }
13
- /** Parses a TSchema type from TypeScript syntax */
20
+ /** Parses a TypeScript annotation into a TypeBox type */
14
21
  export function Syntax(...args) {
15
22
  return NoInfer.apply(null, args);
16
23
  }
17
24
  /**
18
- * Parses a TSchema type from Syntax.
19
25
  * @deprecated Use Syntax() function
20
26
  */
21
27
  export function Parse(...args) {
22
28
  return NoInfer.apply(null, args);
23
29
  }
24
30
  /**
25
- * Parses a TSchema from TypeScript Syntax
26
31
  * @deprecated Use NoInfer() function
27
32
  */
28
33
  export function ParseOnly(...args) {
@@ -1,25 +1,50 @@
1
- import type { TSchema } from '../schema/index.mjs';
2
- import type { TArgument } from '../argument/index.mjs';
3
- import { type TNever } from '../never/index.mjs';
1
+ import { type TSchema } from '../schema/index.mjs';
2
+ import { type TArgument } from '../argument/index.mjs';
3
+ import { type TUnknown } from '../unknown/index.mjs';
4
4
  import { type TReadonlyOptional } from '../readonly-optional/index.mjs';
5
5
  import { type TReadonly } from '../readonly/index.mjs';
6
6
  import { type TOptional } from '../optional/index.mjs';
7
- import { type TRemap, type TMapping as TRemapMapping } from '../remap/index.mjs';
8
- type TInstantiateArgument<Argument extends TArgument, Type extends TSchema, IsArgumentReadonly extends number = Argument extends TReadonly<TSchema> ? 1 : 0, IsArgumentOptional extends number = Argument extends TOptional<TSchema> ? 1 : 0, Result extends TSchema = ([
9
- IsArgumentReadonly,
10
- IsArgumentOptional
11
- ] extends [1, 1] ? TReadonlyOptional<Type> : [
12
- IsArgumentReadonly,
13
- IsArgumentOptional
14
- ] extends [0, 1] ? TOptional<Type> : [
15
- IsArgumentReadonly,
16
- IsArgumentOptional
17
- ] extends [1, 0] ? TReadonly<Type> : Type)> = Result;
18
- interface TInstantiateArguments<Arguments extends TSchema[]> extends TRemapMapping {
19
- output: (this['input'] extends TArgument<infer Index extends number> ? Index extends keyof Arguments ? Arguments[Index] extends TSchema ? TInstantiateArgument<this['input'], Arguments[Index]> : TNever : TNever : this['input']);
20
- }
7
+ import { type TConstructor } from '../constructor/index.mjs';
8
+ import { type TFunction } from '../function/index.mjs';
9
+ import { type TIntersect } from '../intersect/index.mjs';
10
+ import { type TUnion } from '../union/index.mjs';
11
+ import { type TTuple } from '../tuple/index.mjs';
12
+ import { type TArray } from '../array/index.mjs';
13
+ import { type TAsyncIterator } from '../async-iterator/index.mjs';
14
+ import { type TIterator } from '../iterator/index.mjs';
15
+ import { type TPromise } from '../promise/index.mjs';
16
+ import { type TObject, type TProperties } from '../object/index.mjs';
17
+ import { type TRecordOrObject, type TRecord } from '../record/index.mjs';
18
+ type TFromConstructor<Args extends TSchema[], Parameters extends TSchema[], InstanceType extends TSchema, Result extends TConstructor = TConstructor<TFromTypes<Args, Parameters>, TFromType<Args, InstanceType>>> = Result;
19
+ type TFromFunction<Args extends TSchema[], Parameters extends TSchema[], ReturnType extends TSchema, Result extends TFunction = TFunction<TFromTypes<Args, Parameters>, TFromType<Args, ReturnType>>> = Result;
20
+ type TFromIntersect<Args extends TSchema[], Types extends TSchema[], Result extends TIntersect = TIntersect<TFromTypes<Args, Types>>> = Result;
21
+ type TFromUnion<Args extends TSchema[], Types extends TSchema[], Result extends TUnion = TUnion<TFromTypes<Args, Types>>> = Result;
22
+ type TFromTuple<Args extends TSchema[], Types extends TSchema[], Result extends TTuple = TTuple<TFromTypes<Args, Types>>> = Result;
23
+ type TFromArray<Args extends TSchema[], Type extends TSchema, Result extends TArray = TArray<TFromType<Args, Type>>> = Result;
24
+ type TFromAsyncIterator<Args extends TSchema[], Type extends TSchema, Result extends TAsyncIterator = TAsyncIterator<TFromType<Args, Type>>> = Result;
25
+ type TFromIterator<Args extends TSchema[], Type extends TSchema, Result extends TIterator = TIterator<TFromType<Args, Type>>> = Result;
26
+ type TFromPromise<Args extends TSchema[], Type extends TSchema, Result extends TPromise = TPromise<TFromType<Args, Type>>> = Result;
27
+ type TFromObject<Args extends TSchema[], Properties extends TProperties, Result extends TProperties = TFromProperties<Args, Properties>> = TObject<Result>;
28
+ type TFromRecord<Args extends TSchema[], Key extends TSchema, Value extends TSchema, MappedKey extends TSchema = TFromType<Args, Key>, MappedValue extends TSchema = TFromType<Args, Value>, Result extends TSchema = TRecordOrObject<MappedKey, MappedValue>> = Result;
29
+ type TFromArgument<Args extends TSchema[], Index extends number, Result extends TSchema = Index extends keyof Args[Index] ? Args[Index] : TUnknown> = Result;
30
+ type TFromProperty<Args extends TSchema[], Type extends TSchema, IsReadonly extends boolean = Type extends TReadonly<Type> ? true : false, IsOptional extends boolean = Type extends TOptional<Type> ? true : false, Mapped extends TSchema = TFromType<Args, Type>, Result extends TSchema = ([
31
+ IsReadonly,
32
+ IsOptional
33
+ ] extends [true, true] ? TReadonlyOptional<Mapped> : [
34
+ IsReadonly,
35
+ IsOptional
36
+ ] extends [true, false] ? TReadonly<Mapped> : [
37
+ IsReadonly,
38
+ IsOptional
39
+ ] extends [false, true] ? TOptional<Mapped> : Mapped)> = Result;
40
+ type TFromProperties<Args extends TSchema[], Properties extends TProperties, Result extends TProperties = {
41
+ [Key in keyof Properties]: TFromProperty<Args, Properties[Key]>;
42
+ }> = Result;
43
+ export type TFromTypes<Args extends TSchema[], Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes<Args, Right, [...Result, TFromType<Args, Left>]> : Result);
44
+ export declare function FromTypes<Args extends TSchema[], Types extends TSchema[]>(args: [...Args], types: [...Types]): TFromTypes<Args, Types>;
45
+ export type TFromType<Args extends TSchema[], Type extends TSchema> = (Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<Args, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<Args, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Args, Types> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Args, Types> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Args, Types> : Type extends TArray<infer Type extends TSchema> ? TFromArray<Args, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<Args, Type> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<Args, Type> : Type extends TPromise<infer Type extends TSchema> ? TFromPromise<Args, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<Args, Properties> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TFromRecord<Args, Key, Value> : Type extends TArgument<infer Index extends number> ? TFromArgument<Args, Index> : Type);
21
46
  /** `[JavaScript]` Instantiates a type with the given parameters */
22
- export type TInstantiate<Type extends TSchema, Arguments extends TSchema[]> = (TRemap<Type, TInstantiateArguments<Arguments>>);
47
+ export type TInstantiate<Type extends TSchema, Args extends TSchema[], Result extends TSchema = TFromType<Args, Type>> = Result;
23
48
  /** `[JavaScript]` Instantiates a type with the given parameters */
24
- export declare function Instantiate<Type extends TSchema, Arguments extends TSchema[]>(type: Type, args: [...Arguments]): TInstantiate<Type, Arguments>;
49
+ export declare function Instantiate<Type extends TSchema, Args extends TSchema[]>(type: Type, args: [...Args]): TInstantiate<Type, Args>;
25
50
  export {};
@@ -1,28 +1,115 @@
1
- import { Never } from '../never/index.mjs';
1
+ import { CloneType } from '../clone/type.mjs';
2
+ import { Unknown } from '../unknown/index.mjs';
2
3
  import { ReadonlyOptional } from '../readonly-optional/index.mjs';
3
4
  import { Readonly } from '../readonly/index.mjs';
4
5
  import { Optional } from '../optional/index.mjs';
5
- import { Remap } from '../remap/index.mjs';
6
+ import { Object } from '../object/index.mjs';
7
+ import { Record, RecordKey, RecordValue } from '../record/index.mjs';
8
+ import * as ValueGuard from '../guard/value.mjs';
6
9
  import * as KindGuard from '../guard/kind.mjs';
7
10
  // prettier-ignore
8
- function InstantiateArgument(argument, type) {
9
- const isReadonly = KindGuard.IsReadonly(argument);
10
- const isOptional = KindGuard.IsOptional(argument);
11
- return (isReadonly && isOptional ? ReadonlyOptional(type) :
12
- isReadonly && !isOptional ? Readonly(type) :
13
- !isReadonly && isOptional ? Optional(type) :
14
- type);
11
+ function FromConstructor(args, type) {
12
+ type.parameters = FromTypes(args, type.parameters);
13
+ type.returns = FromType(args, type.returns);
14
+ return type;
15
+ }
16
+ // prettier-ignore
17
+ function FromFunction(args, type) {
18
+ type.parameters = FromTypes(args, type.parameters);
19
+ type.returns = FromType(args, type.returns);
20
+ return type;
21
+ }
22
+ // prettier-ignore
23
+ function FromIntersect(args, type) {
24
+ type.allOf = FromTypes(args, type.allOf);
25
+ return type;
26
+ }
27
+ // prettier-ignore
28
+ function FromUnion(args, type) {
29
+ type.anyOf = FromTypes(args, type.anyOf);
30
+ return type;
31
+ }
32
+ // prettier-ignore
33
+ function FromTuple(args, type) {
34
+ if (ValueGuard.IsUndefined(type.items))
35
+ return type;
36
+ type.items = FromTypes(args, type.items);
37
+ return type;
38
+ }
39
+ // prettier-ignore
40
+ function FromArray(args, type) {
41
+ type.items = FromType(args, type.items);
42
+ return type;
43
+ }
44
+ // prettier-ignore
45
+ function FromAsyncIterator(args, type) {
46
+ type.items = FromType(args, type.items);
47
+ return type;
48
+ }
49
+ // prettier-ignore
50
+ function FromIterator(args, type) {
51
+ type.items = FromType(args, type.items);
52
+ return type;
53
+ }
54
+ // prettier-ignore
55
+ function FromPromise(args, type) {
56
+ type.item = FromType(args, type.item);
57
+ return type;
58
+ }
59
+ // prettier-ignore
60
+ function FromObject(args, type) {
61
+ const properties = FromProperties(args, type.properties);
62
+ return { ...type, ...Object(properties) }; // retain options
63
+ }
64
+ // prettier-ignore
65
+ function FromRecord(args, type) {
66
+ const mappedKey = FromType(args, RecordKey(type));
67
+ const mappedValue = FromType(args, RecordValue(type));
68
+ const result = Record(mappedKey, mappedValue);
69
+ return { ...type, ...result }; // retain options
70
+ }
71
+ // prettier-ignore
72
+ function FromArgument(args, argument) {
73
+ return argument.index in args ? args[argument.index] : Unknown();
74
+ }
75
+ // prettier-ignore
76
+ function FromProperty(args, type) {
77
+ const isReadonly = KindGuard.IsReadonly(type);
78
+ const isOptional = KindGuard.IsOptional(type);
79
+ const mapped = FromType(args, type);
80
+ return (isReadonly && isOptional ? ReadonlyOptional(mapped) :
81
+ isReadonly && !isOptional ? Readonly(mapped) :
82
+ !isReadonly && isOptional ? Optional(mapped) :
83
+ mapped);
84
+ }
85
+ // prettier-ignore
86
+ function FromProperties(args, properties) {
87
+ return globalThis.Object.getOwnPropertyNames(properties).reduce((result, key) => {
88
+ return { ...result, [key]: FromProperty(args, properties[key]) };
89
+ }, {});
90
+ }
91
+ // prettier-ignore
92
+ export function FromTypes(args, types) {
93
+ return types.map(type => FromType(args, type));
94
+ }
95
+ // prettier-ignore
96
+ function FromType(args, type) {
97
+ return (KindGuard.IsConstructor(type) ? FromConstructor(args, type) :
98
+ KindGuard.IsFunction(type) ? FromFunction(args, type) :
99
+ KindGuard.IsIntersect(type) ? FromIntersect(args, type) :
100
+ KindGuard.IsUnion(type) ? FromUnion(args, type) :
101
+ KindGuard.IsTuple(type) ? FromTuple(args, type) :
102
+ KindGuard.IsArray(type) ? FromArray(args, type) :
103
+ KindGuard.IsAsyncIterator(type) ? FromAsyncIterator(args, type) :
104
+ KindGuard.IsIterator(type) ? FromIterator(args, type) :
105
+ KindGuard.IsPromise(type) ? FromPromise(args, type) :
106
+ KindGuard.IsObject(type) ? FromObject(args, type) :
107
+ KindGuard.IsRecord(type) ? FromRecord(args, type) :
108
+ KindGuard.IsArgument(type) ? FromArgument(args, type) :
109
+ type);
15
110
  }
16
111
  /** `[JavaScript]` Instantiates a type with the given parameters */
17
112
  // prettier-ignore
18
113
  export function Instantiate(type, args) {
19
- return Remap(type, (type) => {
20
- return KindGuard.IsArgument(type)
21
- ? type.index in args
22
- ? KindGuard.IsSchema(args[type.index])
23
- ? InstantiateArgument(type, args[type.index])
24
- : Never()
25
- : Never()
26
- : type;
27
- });
114
+ return FromType(args, CloneType(type));
28
115
  }
@@ -43,7 +43,6 @@ export { Record } from '../record/index.mjs';
43
43
  export { Recursive } from '../recursive/index.mjs';
44
44
  export { Ref } from '../ref/index.mjs';
45
45
  export { RegExp } from '../regexp/index.mjs';
46
- export { Remap } from '../remap/index.mjs';
47
46
  export { Required } from '../required/index.mjs';
48
47
  export { Rest } from '../rest/index.mjs';
49
48
  export { ReturnType } from '../return-type/index.mjs';
@@ -46,7 +46,6 @@ export { Record } from '../record/index.mjs';
46
46
  export { Recursive } from '../recursive/index.mjs';
47
47
  export { Ref } from '../ref/index.mjs';
48
48
  export { RegExp } from '../regexp/index.mjs';
49
- export { Remap } from '../remap/index.mjs';
50
49
  export { Required } from '../required/index.mjs';
51
50
  export { Rest } from '../rest/index.mjs';
52
51
  export { ReturnType } from '../return-type/index.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.34.22",
3
+ "version": "0.34.24",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",