@sinclair/typebox 0.34.20 → 0.34.21

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.
@@ -18,7 +18,7 @@ import { type TPick } from '../pick/index';
18
18
  import { type TNever } from '../never/index';
19
19
  import { TPartial } from '../partial/index';
20
20
  import { type TReadonly } from '../readonly/index';
21
- import { type TRecordOrObject } from '../record/index';
21
+ import { type TRecordOrObject, type TRecord } from '../record/index';
22
22
  import { type TRef } from '../ref/index';
23
23
  import { TRequired } from '../required/index';
24
24
  import { type TTuple } from '../tuple/index';
@@ -31,12 +31,12 @@ type TFromKeyOf<Parameters extends TSchema[]> = (Parameters extends [infer T0 ex
31
31
  type TFromPartial<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TPartial<T0> : never);
32
32
  type TFromOmit<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TOmit<T0, T1> : never);
33
33
  type TFromPick<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TPick<T0, T1> : never);
34
- type TFromRecord<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TRecordOrObject<T0, T1> : never);
35
34
  type TFromRequired<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TRequired<T0> : never);
36
- type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] = TDerefParameters<ModuleProperties, Parameters>> = (Target extends 'Awaited' ? TFromAwaited<Dereferenced> : Target extends 'Index' ? TFromIndex<Dereferenced> : Target extends 'KeyOf' ? TFromKeyOf<Dereferenced> : Target extends 'Partial' ? TFromPartial<Dereferenced> : Target extends 'Omit' ? TFromOmit<Dereferenced> : Target extends 'Pick' ? TFromPick<Dereferenced> : Target extends 'Record' ? TFromRecord<Dereferenced> : Target extends 'Required' ? TFromRequired<Dereferenced> : TNever);
35
+ type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] = TDerefParameters<ModuleProperties, Parameters>> = (Target extends 'Awaited' ? TFromAwaited<Dereferenced> : Target extends 'Index' ? TFromIndex<Dereferenced> : Target extends 'KeyOf' ? TFromKeyOf<Dereferenced> : Target extends 'Partial' ? TFromPartial<Dereferenced> : Target extends 'Omit' ? TFromOmit<Dereferenced> : Target extends 'Pick' ? TFromPick<Dereferenced> : Target extends 'Required' ? TFromRequired<Dereferenced> : TNever);
37
36
  type TFromObject<ModuleProperties extends TProperties, Properties extends TProperties> = Ensure<TObject<Evaluate<{
38
37
  [Key in keyof Properties]: TFromType<ModuleProperties, Properties[Key]>;
39
38
  }>>>;
39
+ type TFromRecord<ModuleProperties extends TProperties, Key extends TSchema, Value extends TSchema, Result extends TSchema = TRecordOrObject<Key, TFromType<ModuleProperties, Value>>> = Result;
40
40
  type TFromConstructor<ModuleProperties extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema> = (TConstructor<TFromRest<ModuleProperties, Parameters>, TFromType<ModuleProperties, InstanceType>>);
41
41
  type TFromFunction<ModuleProperties extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema> = Ensure<Ensure<TFunction<TFromRest<ModuleProperties, Parameters>, TFromType<ModuleProperties, ReturnType>>>>;
42
42
  type TFromTuple<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TTuple<TFromRest<ModuleProperties, Types>>>);
@@ -46,7 +46,7 @@ type TFromArray<ModuleProperties extends TProperties, Type extends TSchema> = (E
46
46
  type TFromAsyncIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TAsyncIterator<TFromType<ModuleProperties, Type>>);
47
47
  type TFromIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TIterator<TFromType<ModuleProperties, Type>>);
48
48
  type TFromRest<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
49
- export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
49
+ export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TFromRecord<ModuleProperties, Key, Value> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
50
50
  export declare function FromType<ModuleProperties extends TProperties, Type extends TSchema>(moduleProperties: ModuleProperties, type: Type): TFromType<ModuleProperties, Type>;
51
51
  export type TComputeType<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TFromType<ModuleProperties, ModuleProperties[Key]> : TNever);
52
52
  export declare function ComputeType<ModuleProperties extends TProperties, Key extends PropertyKey>(moduleProperties: ModuleProperties, key: Key): TComputeType<ModuleProperties, Key>;
@@ -5,26 +5,27 @@ exports.FromType = FromType;
5
5
  exports.ComputeType = ComputeType;
6
6
  exports.ComputeModuleProperties = ComputeModuleProperties;
7
7
  const index_1 = require("../create/index");
8
- const index_2 = require("../discard/index");
9
- const index_3 = require("../array/index");
10
- const index_4 = require("../awaited/index");
11
- const index_5 = require("../async-iterator/index");
12
- const index_6 = require("../constructor/index");
13
- const index_7 = require("../indexed/index");
14
- const index_8 = require("../function/index");
15
- const index_9 = require("../intersect/index");
16
- const index_10 = require("../iterator/index");
17
- const index_11 = require("../keyof/index");
18
- const index_12 = require("../object/index");
19
- const index_13 = require("../omit/index");
20
- const index_14 = require("../pick/index");
21
- const index_15 = require("../never/index");
22
- const index_16 = require("../partial/index");
23
- const index_17 = require("../record/index");
24
- const index_18 = require("../required/index");
25
- const index_19 = require("../tuple/index");
26
- const index_20 = require("../union/index");
27
- const index_21 = require("../symbols/index");
8
+ const index_2 = require("../clone/index");
9
+ const index_3 = require("../discard/index");
10
+ const index_4 = require("../array/index");
11
+ const index_5 = require("../awaited/index");
12
+ const index_6 = require("../async-iterator/index");
13
+ const index_7 = require("../constructor/index");
14
+ const index_8 = require("../indexed/index");
15
+ const index_9 = require("../function/index");
16
+ const index_10 = require("../intersect/index");
17
+ const index_11 = require("../iterator/index");
18
+ const index_12 = require("../keyof/index");
19
+ const index_13 = require("../object/index");
20
+ const index_14 = require("../omit/index");
21
+ const index_15 = require("../pick/index");
22
+ const index_16 = require("../never/index");
23
+ const index_17 = require("../partial/index");
24
+ const index_18 = require("../record/index");
25
+ const index_19 = require("../required/index");
26
+ const index_20 = require("../tuple/index");
27
+ const index_21 = require("../union/index");
28
+ const index_22 = require("../symbols/index");
28
29
  // ------------------------------------------------------------------
29
30
  // KindGuard
30
31
  // ------------------------------------------------------------------
@@ -43,39 +44,35 @@ function Deref(moduleProperties, ref) {
43
44
  ? KindGuard.IsRef(moduleProperties[ref])
44
45
  ? Deref(moduleProperties, moduleProperties[ref].$ref)
45
46
  : FromType(moduleProperties, moduleProperties[ref])
46
- : (0, index_15.Never)());
47
+ : (0, index_16.Never)());
47
48
  }
48
49
  // prettier-ignore
49
50
  function FromAwaited(parameters) {
50
- return (0, index_4.Awaited)(parameters[0]);
51
+ return (0, index_5.Awaited)(parameters[0]);
51
52
  }
52
53
  // prettier-ignore
53
54
  function FromIndex(parameters) {
54
- return (0, index_7.Index)(parameters[0], parameters[1]);
55
+ return (0, index_8.Index)(parameters[0], parameters[1]);
55
56
  }
56
57
  // prettier-ignore
57
58
  function FromKeyOf(parameters) {
58
- return (0, index_11.KeyOf)(parameters[0]);
59
+ return (0, index_12.KeyOf)(parameters[0]);
59
60
  }
60
61
  // prettier-ignore
61
62
  function FromPartial(parameters) {
62
- return (0, index_16.Partial)(parameters[0]);
63
+ return (0, index_17.Partial)(parameters[0]);
63
64
  }
64
65
  // prettier-ignore
65
66
  function FromOmit(parameters) {
66
- return (0, index_13.Omit)(parameters[0], parameters[1]);
67
+ return (0, index_14.Omit)(parameters[0], parameters[1]);
67
68
  }
68
69
  // prettier-ignore
69
70
  function FromPick(parameters) {
70
- return (0, index_14.Pick)(parameters[0], parameters[1]);
71
- }
72
- // prettier-ignore
73
- function FromRecord(parameters) {
74
- return (0, index_17.Record)(parameters[0], parameters[1]);
71
+ return (0, index_15.Pick)(parameters[0], parameters[1]);
75
72
  }
76
73
  // prettier-ignore
77
74
  function FromRequired(parameters) {
78
- return (0, index_18.Required)(parameters[0]);
75
+ return (0, index_19.Required)(parameters[0]);
79
76
  }
80
77
  // prettier-ignore
81
78
  function FromComputed(moduleProperties, target, parameters) {
@@ -86,40 +83,46 @@ function FromComputed(moduleProperties, target, parameters) {
86
83
  target === 'Partial' ? FromPartial(dereferenced) :
87
84
  target === 'Omit' ? FromOmit(dereferenced) :
88
85
  target === 'Pick' ? FromPick(dereferenced) :
89
- target === 'Record' ? FromRecord(dereferenced) :
90
- target === 'Required' ? FromRequired(dereferenced) :
91
- (0, index_15.Never)());
86
+ target === 'Required' ? FromRequired(dereferenced) :
87
+ (0, index_16.Never)());
92
88
  }
93
89
  function FromObject(moduleProperties, properties) {
94
- return (0, index_12.Object)(globalThis.Object.keys(properties).reduce((result, key) => {
90
+ return (0, index_13.Object)(globalThis.Object.keys(properties).reduce((result, key) => {
95
91
  return { ...result, [key]: FromType(moduleProperties, properties[key]) };
96
92
  }, {}));
97
93
  }
98
94
  // prettier-ignore
95
+ function FromRecord(moduleProperties, type) {
96
+ const [value, pattern] = [FromType(moduleProperties, (0, index_18.RecordValue)(type)), (0, index_18.RecordPattern)(type)];
97
+ const result = (0, index_2.CloneType)(type);
98
+ result.patternProperties[pattern] = value;
99
+ return result;
100
+ }
101
+ // prettier-ignore
99
102
  function FromConstructor(moduleProperties, parameters, instanceType) {
100
- return (0, index_6.Constructor)(FromRest(moduleProperties, parameters), FromType(moduleProperties, instanceType));
103
+ return (0, index_7.Constructor)(FromRest(moduleProperties, parameters), FromType(moduleProperties, instanceType));
101
104
  }
102
105
  // prettier-ignore
103
106
  function FromFunction(moduleProperties, parameters, returnType) {
104
- return (0, index_8.Function)(FromRest(moduleProperties, parameters), FromType(moduleProperties, returnType));
107
+ return (0, index_9.Function)(FromRest(moduleProperties, parameters), FromType(moduleProperties, returnType));
105
108
  }
106
109
  function FromTuple(moduleProperties, types) {
107
- return (0, index_19.Tuple)(FromRest(moduleProperties, types));
110
+ return (0, index_20.Tuple)(FromRest(moduleProperties, types));
108
111
  }
109
112
  function FromIntersect(moduleProperties, types) {
110
- return (0, index_9.Intersect)(FromRest(moduleProperties, types));
113
+ return (0, index_10.Intersect)(FromRest(moduleProperties, types));
111
114
  }
112
115
  function FromUnion(moduleProperties, types) {
113
- return (0, index_20.Union)(FromRest(moduleProperties, types));
116
+ return (0, index_21.Union)(FromRest(moduleProperties, types));
114
117
  }
115
118
  function FromArray(moduleProperties, type) {
116
- return (0, index_3.Array)(FromType(moduleProperties, type));
119
+ return (0, index_4.Array)(FromType(moduleProperties, type));
117
120
  }
118
121
  function FromAsyncIterator(moduleProperties, type) {
119
- return (0, index_5.AsyncIterator)(FromType(moduleProperties, type));
122
+ return (0, index_6.AsyncIterator)(FromType(moduleProperties, type));
120
123
  }
121
124
  function FromIterator(moduleProperties, type) {
122
- return (0, index_10.Iterator)(FromType(moduleProperties, type));
125
+ return (0, index_11.Iterator)(FromType(moduleProperties, type));
123
126
  }
124
127
  function FromRest(moduleProperties, types) {
125
128
  return types.map((type) => FromType(moduleProperties, type));
@@ -128,8 +131,8 @@ function FromRest(moduleProperties, types) {
128
131
  function FromType(moduleProperties, type) {
129
132
  return (
130
133
  // Modifier Unwrap - Reapplied via CreateType Options
131
- KindGuard.IsOptional(type) ? (0, index_1.CreateType)(FromType(moduleProperties, (0, index_2.Discard)(type, [index_21.OptionalKind])), type) :
132
- KindGuard.IsReadonly(type) ? (0, index_1.CreateType)(FromType(moduleProperties, (0, index_2.Discard)(type, [index_21.ReadonlyKind])), type) :
134
+ KindGuard.IsOptional(type) ? (0, index_1.CreateType)(FromType(moduleProperties, (0, index_3.Discard)(type, [index_22.OptionalKind])), type) :
135
+ KindGuard.IsReadonly(type) ? (0, index_1.CreateType)(FromType(moduleProperties, (0, index_3.Discard)(type, [index_22.ReadonlyKind])), type) :
133
136
  // Traveral
134
137
  KindGuard.IsArray(type) ? (0, index_1.CreateType)(FromArray(moduleProperties, type.items), type) :
135
138
  KindGuard.IsAsyncIterator(type) ? (0, index_1.CreateType)(FromAsyncIterator(moduleProperties, type.items), type) :
@@ -139,15 +142,16 @@ function FromType(moduleProperties, type) {
139
142
  KindGuard.IsIntersect(type) ? (0, index_1.CreateType)(FromIntersect(moduleProperties, type.allOf), type) :
140
143
  KindGuard.IsIterator(type) ? (0, index_1.CreateType)(FromIterator(moduleProperties, type.items), type) :
141
144
  KindGuard.IsObject(type) ? (0, index_1.CreateType)(FromObject(moduleProperties, type.properties), type) :
142
- KindGuard.IsTuple(type) ? (0, index_1.CreateType)(FromTuple(moduleProperties, type.items || []), type) :
143
- KindGuard.IsUnion(type) ? (0, index_1.CreateType)(FromUnion(moduleProperties, type.anyOf), type) :
144
- type);
145
+ KindGuard.IsRecord(type) ? (0, index_1.CreateType)(FromRecord(moduleProperties, type)) :
146
+ KindGuard.IsTuple(type) ? (0, index_1.CreateType)(FromTuple(moduleProperties, type.items || []), type) :
147
+ KindGuard.IsUnion(type) ? (0, index_1.CreateType)(FromUnion(moduleProperties, type.anyOf), type) :
148
+ type);
145
149
  }
146
150
  // prettier-ignore
147
151
  function ComputeType(moduleProperties, key) {
148
152
  return (key in moduleProperties
149
153
  ? FromType(moduleProperties, moduleProperties[key])
150
- : (0, index_15.Never)());
154
+ : (0, index_16.Never)());
151
155
  }
152
156
  // prettier-ignore
153
157
  function ComputeModuleProperties(moduleProperties) {
@@ -61,11 +61,11 @@ export declare function Record<Key extends TSchema, Type extends TSchema>(key: K
61
61
  /** Gets the Records Pattern */
62
62
  export declare function RecordPattern(record: TRecord): string;
63
63
  /** Gets the Records Key Type */
64
- export type TRecordKey<Type extends TRecord> = (Type extends TRecord<infer Key extends TSchema, TSchema> ? (Key extends TNumber ? TNumber : Key extends TString ? TString : TString) : TString);
64
+ export type TRecordKey<Type extends TRecord, Result extends TSchema = Type extends TRecord<infer Key extends TSchema, TSchema> ? (Key extends TNumber ? TNumber : Key extends TString ? TString : TString) : TString> = Result;
65
65
  /** Gets the Records Key Type */
66
66
  export declare function RecordKey<Type extends TRecord>(type: Type): TRecordKey<Type>;
67
67
  /** Gets a Record Value Type */
68
- export type TRecordValue<Type extends TRecord> = (Type extends TRecord<TSchema, infer Value extends TSchema> ? Value : TNever);
68
+ export type TRecordValue<Type extends TRecord, Result extends TSchema = (Type extends TRecord<TSchema, infer Value extends TSchema> ? Value : TNever)> = Result;
69
69
  /** Gets a Record Value Type */
70
70
  export declare function RecordValue<Type extends TRecord>(type: Type): TRecordValue<Type>;
71
71
  export {};
@@ -18,7 +18,7 @@ import { type TPick } from '../pick/index.mjs';
18
18
  import { type TNever } from '../never/index.mjs';
19
19
  import { TPartial } from '../partial/index.mjs';
20
20
  import { type TReadonly } from '../readonly/index.mjs';
21
- import { type TRecordOrObject } from '../record/index.mjs';
21
+ import { type TRecordOrObject, type TRecord } from '../record/index.mjs';
22
22
  import { type TRef } from '../ref/index.mjs';
23
23
  import { TRequired } from '../required/index.mjs';
24
24
  import { type TTuple } from '../tuple/index.mjs';
@@ -31,12 +31,12 @@ type TFromKeyOf<Parameters extends TSchema[]> = (Parameters extends [infer T0 ex
31
31
  type TFromPartial<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TPartial<T0> : never);
32
32
  type TFromOmit<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TOmit<T0, T1> : never);
33
33
  type TFromPick<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TPick<T0, T1> : never);
34
- type TFromRecord<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TRecordOrObject<T0, T1> : never);
35
34
  type TFromRequired<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TRequired<T0> : never);
36
- type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] = TDerefParameters<ModuleProperties, Parameters>> = (Target extends 'Awaited' ? TFromAwaited<Dereferenced> : Target extends 'Index' ? TFromIndex<Dereferenced> : Target extends 'KeyOf' ? TFromKeyOf<Dereferenced> : Target extends 'Partial' ? TFromPartial<Dereferenced> : Target extends 'Omit' ? TFromOmit<Dereferenced> : Target extends 'Pick' ? TFromPick<Dereferenced> : Target extends 'Record' ? TFromRecord<Dereferenced> : Target extends 'Required' ? TFromRequired<Dereferenced> : TNever);
35
+ type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] = TDerefParameters<ModuleProperties, Parameters>> = (Target extends 'Awaited' ? TFromAwaited<Dereferenced> : Target extends 'Index' ? TFromIndex<Dereferenced> : Target extends 'KeyOf' ? TFromKeyOf<Dereferenced> : Target extends 'Partial' ? TFromPartial<Dereferenced> : Target extends 'Omit' ? TFromOmit<Dereferenced> : Target extends 'Pick' ? TFromPick<Dereferenced> : Target extends 'Required' ? TFromRequired<Dereferenced> : TNever);
37
36
  type TFromObject<ModuleProperties extends TProperties, Properties extends TProperties> = Ensure<TObject<Evaluate<{
38
37
  [Key in keyof Properties]: TFromType<ModuleProperties, Properties[Key]>;
39
38
  }>>>;
39
+ type TFromRecord<ModuleProperties extends TProperties, Key extends TSchema, Value extends TSchema, Result extends TSchema = TRecordOrObject<Key, TFromType<ModuleProperties, Value>>> = Result;
40
40
  type TFromConstructor<ModuleProperties extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema> = (TConstructor<TFromRest<ModuleProperties, Parameters>, TFromType<ModuleProperties, InstanceType>>);
41
41
  type TFromFunction<ModuleProperties extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema> = Ensure<Ensure<TFunction<TFromRest<ModuleProperties, Parameters>, TFromType<ModuleProperties, ReturnType>>>>;
42
42
  type TFromTuple<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TTuple<TFromRest<ModuleProperties, Types>>>);
@@ -46,7 +46,7 @@ type TFromArray<ModuleProperties extends TProperties, Type extends TSchema> = (E
46
46
  type TFromAsyncIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TAsyncIterator<TFromType<ModuleProperties, Type>>);
47
47
  type TFromIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TIterator<TFromType<ModuleProperties, Type>>);
48
48
  type TFromRest<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
49
- export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
49
+ export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TFromRecord<ModuleProperties, Key, Value> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
50
50
  export declare function FromType<ModuleProperties extends TProperties, Type extends TSchema>(moduleProperties: ModuleProperties, type: Type): TFromType<ModuleProperties, Type>;
51
51
  export type TComputeType<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TFromType<ModuleProperties, ModuleProperties[Key]> : TNever);
52
52
  export declare function ComputeType<ModuleProperties extends TProperties, Key extends PropertyKey>(moduleProperties: ModuleProperties, key: Key): TComputeType<ModuleProperties, Key>;
@@ -1,4 +1,5 @@
1
1
  import { CreateType } from '../create/index.mjs';
2
+ import { CloneType } from '../clone/index.mjs';
2
3
  import { Discard } from '../discard/index.mjs';
3
4
  import { Array } from '../array/index.mjs';
4
5
  import { Awaited } from '../awaited/index.mjs';
@@ -14,7 +15,7 @@ import { Omit } from '../omit/index.mjs';
14
15
  import { Pick } from '../pick/index.mjs';
15
16
  import { Never } from '../never/index.mjs';
16
17
  import { Partial } from '../partial/index.mjs';
17
- import { Record } from '../record/index.mjs';
18
+ import { RecordValue, RecordPattern } from '../record/index.mjs';
18
19
  import { Required } from '../required/index.mjs';
19
20
  import { Tuple } from '../tuple/index.mjs';
20
21
  import { Union } from '../union/index.mjs';
@@ -64,10 +65,6 @@ function FromPick(parameters) {
64
65
  return Pick(parameters[0], parameters[1]);
65
66
  }
66
67
  // prettier-ignore
67
- function FromRecord(parameters) {
68
- return Record(parameters[0], parameters[1]);
69
- }
70
- // prettier-ignore
71
68
  function FromRequired(parameters) {
72
69
  return Required(parameters[0]);
73
70
  }
@@ -80,9 +77,8 @@ function FromComputed(moduleProperties, target, parameters) {
80
77
  target === 'Partial' ? FromPartial(dereferenced) :
81
78
  target === 'Omit' ? FromOmit(dereferenced) :
82
79
  target === 'Pick' ? FromPick(dereferenced) :
83
- target === 'Record' ? FromRecord(dereferenced) :
84
- target === 'Required' ? FromRequired(dereferenced) :
85
- Never());
80
+ target === 'Required' ? FromRequired(dereferenced) :
81
+ Never());
86
82
  }
87
83
  function FromObject(moduleProperties, properties) {
88
84
  return Object(globalThis.Object.keys(properties).reduce((result, key) => {
@@ -90,6 +86,13 @@ function FromObject(moduleProperties, properties) {
90
86
  }, {}));
91
87
  }
92
88
  // prettier-ignore
89
+ function FromRecord(moduleProperties, type) {
90
+ const [value, pattern] = [FromType(moduleProperties, RecordValue(type)), RecordPattern(type)];
91
+ const result = CloneType(type);
92
+ result.patternProperties[pattern] = value;
93
+ return result;
94
+ }
95
+ // prettier-ignore
93
96
  function FromConstructor(moduleProperties, parameters, instanceType) {
94
97
  return Constructor(FromRest(moduleProperties, parameters), FromType(moduleProperties, instanceType));
95
98
  }
@@ -133,9 +136,10 @@ export function FromType(moduleProperties, type) {
133
136
  KindGuard.IsIntersect(type) ? CreateType(FromIntersect(moduleProperties, type.allOf), type) :
134
137
  KindGuard.IsIterator(type) ? CreateType(FromIterator(moduleProperties, type.items), type) :
135
138
  KindGuard.IsObject(type) ? CreateType(FromObject(moduleProperties, type.properties), type) :
136
- KindGuard.IsTuple(type) ? CreateType(FromTuple(moduleProperties, type.items || []), type) :
137
- KindGuard.IsUnion(type) ? CreateType(FromUnion(moduleProperties, type.anyOf), type) :
138
- type);
139
+ KindGuard.IsRecord(type) ? CreateType(FromRecord(moduleProperties, type)) :
140
+ KindGuard.IsTuple(type) ? CreateType(FromTuple(moduleProperties, type.items || []), type) :
141
+ KindGuard.IsUnion(type) ? CreateType(FromUnion(moduleProperties, type.anyOf), type) :
142
+ type);
139
143
  }
140
144
  // prettier-ignore
141
145
  export function ComputeType(moduleProperties, key) {
@@ -61,11 +61,11 @@ export declare function Record<Key extends TSchema, Type extends TSchema>(key: K
61
61
  /** Gets the Records Pattern */
62
62
  export declare function RecordPattern(record: TRecord): string;
63
63
  /** Gets the Records Key Type */
64
- export type TRecordKey<Type extends TRecord> = (Type extends TRecord<infer Key extends TSchema, TSchema> ? (Key extends TNumber ? TNumber : Key extends TString ? TString : TString) : TString);
64
+ export type TRecordKey<Type extends TRecord, Result extends TSchema = Type extends TRecord<infer Key extends TSchema, TSchema> ? (Key extends TNumber ? TNumber : Key extends TString ? TString : TString) : TString> = Result;
65
65
  /** Gets the Records Key Type */
66
66
  export declare function RecordKey<Type extends TRecord>(type: Type): TRecordKey<Type>;
67
67
  /** Gets a Record Value Type */
68
- export type TRecordValue<Type extends TRecord> = (Type extends TRecord<TSchema, infer Value extends TSchema> ? Value : TNever);
68
+ export type TRecordValue<Type extends TRecord, Result extends TSchema = (Type extends TRecord<TSchema, infer Value extends TSchema> ? Value : TNever)> = Result;
69
69
  /** Gets a Record Value Type */
70
70
  export declare function RecordValue<Type extends TRecord>(type: Type): TRecordValue<Type>;
71
71
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.34.20",
3
+ "version": "0.34.21",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",