@sinclair/typebox 0.34.4 → 0.34.6

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.
@@ -48,7 +48,7 @@ export declare const Module: Runtime.Module<{
48
48
  Iterator: Runtime.ITuple<Types.TIterator<Types.TSchema>>;
49
49
  Awaited: Runtime.ITuple<Types.TSchema>;
50
50
  Array: Runtime.ITuple<Types.TArray<Types.TSchema>>;
51
- Record: Runtime.ITuple<Types.TNever>;
51
+ Record: Runtime.ITuple<Types.TSchema>;
52
52
  Promise: Runtime.ITuple<Types.TPromise<Types.TSchema>>;
53
53
  ConstructorParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
54
54
  FunctionParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
@@ -247,6 +247,7 @@ function IsSchema(value) {
247
247
  IsBoolean(value) ||
248
248
  IsBigInt(value) ||
249
249
  IsAsyncIterator(value) ||
250
+ IsComputed(value) ||
250
251
  IsConstructor(value) ||
251
252
  IsDate(value) ||
252
253
  IsFunction(value) ||
@@ -199,7 +199,11 @@ function IsBoolean(value) {
199
199
  }
200
200
  /** Returns true if the given value is TComputed */
201
201
  function IsComputed(value) {
202
- return IsKindOf(value, 'Computed') && IsString(value.target) && ValueGuard.IsArray(value.parameters) && value.parameters.every((schema) => IsSchema(schema));
202
+ // prettier-ignore
203
+ return (IsKindOf(value, 'Computed') &&
204
+ ValueGuard.IsString(value.target) &&
205
+ ValueGuard.IsArray(value.parameters) &&
206
+ value.parameters.every((schema) => IsSchema(schema)));
203
207
  }
204
208
  /** Returns true if the given value is TConstructor */
205
209
  function IsConstructor(value) {
@@ -517,6 +521,7 @@ function IsSchema(value) {
517
521
  IsBoolean(value) ||
518
522
  IsBigInt(value) ||
519
523
  IsAsyncIterator(value) ||
524
+ IsComputed(value) ||
520
525
  IsConstructor(value) ||
521
526
  IsDate(value) ||
522
527
  IsFunction(value) ||
@@ -9,6 +9,7 @@ import { TIntersect } from '../intersect/index';
9
9
  import { TIterator } from '../iterator/index';
10
10
  import { TObject, TProperties } from '../object/index';
11
11
  import { TOptional } from '../optional/index';
12
+ import { TRecord } from '../record/index';
12
13
  import { TReadonly } from '../readonly/index';
13
14
  import { TRef } from '../ref/index';
14
15
  import { TTuple } from '../tuple/index';
@@ -19,15 +20,15 @@ type TInferAsyncIterator<ModuleProperties extends TProperties, Type extends TSch
19
20
  type TInferConstructor<ModuleProperties extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema> = Ensure<new (...args: TInferTuple<ModuleProperties, Parameters>) => TInfer<ModuleProperties, InstanceType>>;
20
21
  type TInferFunction<ModuleProperties extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema> = Ensure<(...args: TInferTuple<ModuleProperties, Parameters>) => TInfer<ModuleProperties, ReturnType>>;
21
22
  type TInferIterator<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<IterableIterator<TInfer<ModuleProperties, Type>>>);
22
- type TInferIntersect<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown = unknown> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferIntersect<ModuleProperties, R, Result & TInfer<ModuleProperties, L>> : Result);
23
+ type TInferIntersect<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown = unknown> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TInferIntersect<ModuleProperties, Right, Result & TInfer<ModuleProperties, Left>> : Result);
23
24
  type ReadonlyOptionalPropertyKeys<Properties extends TProperties> = {
24
- [K in keyof Properties]: Properties[K] extends TReadonly<TSchema> ? (Properties[K] extends TOptional<Properties[K]> ? K : never) : never;
25
+ [Key in keyof Properties]: Properties[Key] extends TReadonly<TSchema> ? (Properties[Key] extends TOptional<Properties[Key]> ? Key : never) : never;
25
26
  }[keyof Properties];
26
27
  type ReadonlyPropertyKeys<Source extends TProperties> = {
27
- [K in keyof Source]: Source[K] extends TReadonly<TSchema> ? (Source[K] extends TOptional<Source[K]> ? never : K) : never;
28
+ [Key in keyof Source]: Source[Key] extends TReadonly<TSchema> ? (Source[Key] extends TOptional<Source[Key]> ? never : Key) : never;
28
29
  }[keyof Source];
29
30
  type OptionalPropertyKeys<Source extends TProperties> = {
30
- [K in keyof Source]: Source[K] extends TOptional<TSchema> ? (Source[K] extends TReadonly<Source[K]> ? never : K) : never;
31
+ [Key in keyof Source]: Source[Key] extends TOptional<TSchema> ? (Source[Key] extends TReadonly<Source[Key]> ? never : Key) : never;
31
32
  }[keyof Source];
32
33
  type RequiredPropertyKeys<Source extends TProperties> = keyof Omit<Source, ReadonlyOptionalPropertyKeys<Source> | ReadonlyPropertyKeys<Source> | OptionalPropertyKeys<Source>>;
33
34
  type InferPropertiesWithModifiers<Properties extends TProperties, Source extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<Source, ReadonlyOptionalPropertyKeys<Properties>>>> & Readonly<Pick<Source, ReadonlyPropertyKeys<Properties>>> & Partial<Pick<Source, OptionalPropertyKeys<Properties>>> & Required<Pick<Source, RequiredPropertyKeys<Properties>>>)>;
@@ -36,9 +37,10 @@ type InferProperties<ModuleProperties extends TProperties, Properties extends TP
36
37
  }>;
37
38
  type TInferObject<ModuleProperties extends TProperties, Properties extends TProperties> = (InferProperties<ModuleProperties, Properties>);
38
39
  type TInferTuple<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferTuple<ModuleProperties, R, [...Result, TInfer<ModuleProperties, L>]> : Result);
40
+ type TInferRecord<ModuleProperties extends TProperties, Key extends TSchema, Type extends TSchema, InferredKey extends PropertyKey = TInfer<ModuleProperties, Key> extends infer Key extends PropertyKey ? Key : never, InferedType extends unknown = TInfer<ModuleProperties, Type>> = Record<InferredKey, InferedType>;
39
41
  type TInferRef<ModuleProperties extends TProperties, Ref extends string> = (Ref extends keyof ModuleProperties ? TInfer<ModuleProperties, ModuleProperties[Ref]> : unknown);
40
42
  type TInferUnion<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown = never> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferUnion<ModuleProperties, R, Result | TInfer<ModuleProperties, L>> : Result);
41
- type TInfer<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TInferArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TInferAsyncIterator<ModuleProperties, Type> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TInferConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TInferFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TInferIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TInferIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TInferObject<ModuleProperties, Properties> : Type extends TRef<infer Ref extends string> ? TInferRef<ModuleProperties, Ref> : Type extends TTuple<infer Types extends TSchema[]> ? TInferTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Static<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TInferUnion<ModuleProperties, Types> : Static<Type>);
43
+ type TInfer<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TInferArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TInferAsyncIterator<ModuleProperties, Type> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TInferConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TInferFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TInferIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TInferIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TInferObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Type extends TSchema> ? TInferRecord<ModuleProperties, Key, Type> : Type extends TRef<infer Ref extends string> ? TInferRef<ModuleProperties, Ref> : Type extends TTuple<infer Types extends TSchema[]> ? TInferTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Static<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TInferUnion<ModuleProperties, Types> : Static<Type>);
42
44
  /** Inference Path for Imports. This type is used to compute TImport `static` */
43
45
  export type TInferFromModuleKey<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TInfer<ModuleProperties, ModuleProperties[Key]> : never);
44
46
  export {};
@@ -21,7 +21,8 @@ class TModule {
21
21
  }
22
22
  /** `[Json]` Imports a Type by Key. */
23
23
  Import(key, options) {
24
- return (0, index_1.CreateType)({ [index_2.Kind]: 'Import', $defs: this.$defs, $ref: key }, options);
24
+ const $defs = { ...this.$defs, [key]: (0, index_1.CreateType)(this.$defs[key], options) };
25
+ return (0, index_1.CreateType)({ [index_2.Kind]: 'Import', $defs, $ref: key });
25
26
  }
26
27
  // prettier-ignore
27
28
  WithIdentifiers($defs) {
@@ -1,58 +1,58 @@
1
+ import { Kind } from '../symbols/index';
1
2
  import type { TSchema } from '../schema/index';
2
3
  import type { Static } from '../static/index';
3
4
  import type { Evaluate, Ensure, Assert } from '../helpers/index';
4
5
  import { type TAny } from '../any/index';
5
6
  import { type TComputed } from '../computed/index';
6
- import { type TObject, type TProperties, type TAdditionalProperties, type ObjectOptions } from '../object/index';
7
+ import { type TEnumRecord, type TEnum } from '../enum/index';
8
+ import { type TInteger } from '../integer/index';
7
9
  import { type TLiteral, type TLiteralValue } from '../literal/index';
8
10
  import { type TNever } from '../never/index';
9
- import { type TUnion } from '../union/index';
10
- import { type TRegExp } from '../regexp/index';
11
- import { type TString } from '../string/index';
12
- import { type TInteger } from '../integer/index';
13
11
  import { type TNumber } from '../number/index';
14
- import { type TEnum } from '../enum/index';
12
+ import { type TObject, type TProperties, type TAdditionalProperties, type ObjectOptions } from '../object/index';
15
13
  import { type TRef } from '../ref/index';
14
+ import { type TRegExp } from '../regexp/index';
15
+ import { type TString } from '../string/index';
16
+ import { type TUnion } from '../union/index';
16
17
  import { TIsTemplateLiteralFinite, type TTemplateLiteral } from '../template-literal/index';
17
- import { Kind } from '../symbols/index';
18
- type TFromTemplateLiteralKeyInfinite<K extends TTemplateLiteral, T extends TSchema> = Ensure<TRecord<K, T>>;
19
- type TFromTemplateLiteralKeyFinite<K extends TTemplateLiteral, T extends TSchema, I extends string = Static<K>> = (Ensure<TObject<Evaluate<{
20
- [_ in I]: T;
18
+ type TFromTemplateLiteralKeyInfinite<Key extends TTemplateLiteral, Type extends TSchema> = Ensure<TRecord<Key, Type>>;
19
+ type TFromTemplateLiteralKeyFinite<Key extends TTemplateLiteral, Type extends TSchema, I extends string = Static<Key>> = (Ensure<TObject<Evaluate<{
20
+ [_ in I]: Type;
21
21
  }>>>);
22
- type TFromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema> = TIsTemplateLiteralFinite<K> extends false ? TFromTemplateLiteralKeyInfinite<K, T> : TFromTemplateLiteralKeyFinite<K, T>;
23
- type TFromEnumKey<K extends Record<string, string | number>, T extends TSchema> = Ensure<TObject<{
24
- [_ in K[keyof K]]: T;
22
+ type TFromTemplateLiteralKey<Key extends TTemplateLiteral, Type extends TSchema> = TIsTemplateLiteralFinite<Key> extends false ? TFromTemplateLiteralKeyInfinite<Key, Type> : TFromTemplateLiteralKeyFinite<Key, Type>;
23
+ type TFromEnumKey<Key extends Record<string, string | number>, Type extends TSchema> = Ensure<TObject<{
24
+ [_ in Key[keyof Key]]: Type;
25
25
  }>>;
26
- type TFromUnionKeyLiteralString<K extends TLiteral<string>, T extends TSchema> = {
27
- [_ in K['const']]: T;
26
+ type TFromUnionKeyLiteralString<Key extends TLiteral<string>, Type extends TSchema> = {
27
+ [_ in Key['const']]: Type;
28
28
  };
29
- type TFromUnionKeyLiteralNumber<K extends TLiteral<number>, T extends TSchema> = {
30
- [_ in K['const']]: T;
29
+ type TFromUnionKeyLiteralNumber<Key extends TLiteral<number>, Type extends TSchema> = {
30
+ [_ in Key['const']]: Type;
31
31
  };
32
- type TFromUnionKeyRest<K extends TSchema[], T extends TSchema> = K extends [infer L extends TSchema, ...infer R extends TSchema[]] ? (L extends TUnion<infer S> ? TFromUnionKeyRest<S, T> & TFromUnionKeyRest<R, T> : L extends TLiteral<string> ? TFromUnionKeyLiteralString<L, T> & TFromUnionKeyRest<R, T> : L extends TLiteral<number> ? TFromUnionKeyLiteralNumber<L, T> & TFromUnionKeyRest<R, T> : {}) : {};
33
- type TFromUnionKey<K extends TSchema[], T extends TSchema, P extends TProperties = TFromUnionKeyRest<K, T>> = (Ensure<TObject<Evaluate<P>>>);
34
- type TFromLiteralKey<K extends TLiteralValue, T extends TSchema> = (Ensure<TObject<{
35
- [_ in Assert<K, PropertyKey>]: T;
32
+ type TFromUnionKeyRest<Keys extends TSchema[], Type extends TSchema> = Keys extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? (Left extends TUnion<infer Types extends TSchema[]> ? TFromUnionKeyRest<Types, Type> & TFromUnionKeyRest<Right, Type> : Left extends TLiteral<string> ? TFromUnionKeyLiteralString<Left, Type> & TFromUnionKeyRest<Right, Type> : Left extends TLiteral<number> ? TFromUnionKeyLiteralNumber<Left, Type> & TFromUnionKeyRest<Right, Type> : {}) : {};
33
+ type TFromUnionKey<Key extends TSchema[], Type extends TSchema, P extends TProperties = TFromUnionKeyRest<Key, Type>> = (Ensure<TObject<Evaluate<P>>>);
34
+ type TFromLiteralKey<Key extends TLiteralValue, Type extends TSchema> = (Ensure<TObject<{
35
+ [_ in Assert<Key, PropertyKey>]: Type;
36
36
  }>>);
37
- type TFromRegExpKey<_ extends TRegExp, T extends TSchema> = (Ensure<TRecord<TRegExp, T>>);
38
- type TFromStringKey<_ extends TString, T extends TSchema> = (Ensure<TRecord<TString, T>>);
39
- type TFromAnyKey<_ extends TAny, T extends TSchema> = (Ensure<TRecord<TAny, T>>);
40
- type TFromNeverKey<_ extends TNever, T extends TSchema> = (Ensure<TRecord<TNever, T>>);
41
- type TFromIntegerKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
42
- type TFromNumberKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
43
- type RecordStatic<K extends TSchema, T extends TSchema, P extends unknown[]> = (Evaluate<{
44
- [_ in Assert<Static<K>, PropertyKey>]: Static<T, P>;
37
+ type TFromRegExpKey<_Key extends TRegExp, Type extends TSchema> = (Ensure<TRecord<TRegExp, Type>>);
38
+ type TFromStringKey<_Key extends TString, Type extends TSchema> = (Ensure<TRecord<TString, Type>>);
39
+ type TFromAnyKey<_Key extends TAny, Type extends TSchema> = (Ensure<TRecord<TAny, Type>>);
40
+ type TFromNeverKey<_Key extends TNever, Type extends TSchema> = (Ensure<TRecord<TNever, Type>>);
41
+ type TFromIntegerKey<_Key extends TSchema, Type extends TSchema> = (Ensure<TRecord<TNumber, Type>>);
42
+ type TFromNumberKey<_Key extends TSchema, Type extends TSchema> = (Ensure<TRecord<TNumber, Type>>);
43
+ type RecordStatic<Key extends TSchema, Type extends TSchema, P extends unknown[]> = (Evaluate<{
44
+ [_ in Assert<Static<Key>, PropertyKey>]: Static<Type, P>;
45
45
  }>);
46
- export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchema> extends TSchema {
46
+ export interface TRecord<Key extends TSchema = TSchema, Type extends TSchema = TSchema> extends TSchema {
47
47
  [Kind]: 'Record';
48
- static: RecordStatic<K, T, this['params']>;
48
+ static: RecordStatic<Key, Type, this['params']>;
49
49
  type: 'object';
50
50
  patternProperties: {
51
- [pattern: string]: T;
51
+ [pattern: string]: Type;
52
52
  };
53
53
  additionalProperties: TAdditionalProperties;
54
54
  }
55
- export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = Type extends TRef ? TComputed<'Record', [Key, Type]> : Key extends TRef ? TComputed<'Record', [Key, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer S> ? TFromEnumKey<S, Type> : Key extends TUnion<infer S> ? TFromUnionKey<S, Type> : Key extends TLiteral<infer S> ? TFromLiteralKey<S, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : TNever;
55
+ export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [Key, TComputed<Target, Parameters>]> : Key extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [TComputed<Target, Parameters>, Type]> : Key extends TRef<infer Ref extends string> ? TComputed<'Record', [TRef<Ref>, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer Enum extends TEnumRecord> ? TFromEnumKey<Enum, Type> : Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Type> : Key extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteralKey<Value, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : Key);
56
56
  /** `[Json]` Creates a Record type */
57
57
  export declare function Record<Key extends TSchema, Type extends TSchema>(key: Key, type: Type, options?: ObjectOptions): TRecordOrObject<Key, Type>;
58
58
  export {};
@@ -3,14 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Record = Record;
5
5
  const type_1 = require("../create/type");
6
- const index_1 = require("../computed/index");
7
- const index_2 = require("../object/index");
6
+ const index_1 = require("../symbols/index");
7
+ const index_2 = require("../computed/index");
8
8
  const index_3 = require("../never/index");
9
- const index_4 = require("../union/index");
10
- const index_5 = require("../template-literal/index");
11
- const index_6 = require("../patterns/index");
12
- const index_7 = require("../indexed/index");
13
- const index_8 = require("../symbols/index");
9
+ const index_4 = require("../object/index");
10
+ const index_5 = require("../ref/index");
11
+ const index_6 = require("../union/index");
12
+ const index_7 = require("../template-literal/index");
13
+ const index_8 = require("../patterns/index");
14
+ const index_9 = require("../indexed/index");
14
15
  // ------------------------------------------------------------------
15
16
  // ValueGuard
16
17
  // ------------------------------------------------------------------
@@ -24,60 +25,56 @@ const kind_1 = require("../guard/kind");
24
25
  // ------------------------------------------------------------------
25
26
  // prettier-ignore
26
27
  function RecordCreateFromPattern(pattern, T, options) {
27
- return (0, type_1.CreateType)({
28
- [index_8.Kind]: 'Record',
29
- type: 'object',
30
- patternProperties: { [pattern]: T }
31
- }, options);
28
+ return (0, type_1.CreateType)({ [index_1.Kind]: 'Record', type: 'object', patternProperties: { [pattern]: T } }, options);
32
29
  }
33
30
  // ------------------------------------------------------------------
34
31
  // RecordCreateFromKeys
35
32
  // ------------------------------------------------------------------
36
33
  // prettier-ignore
37
34
  function RecordCreateFromKeys(K, T, options) {
38
- const Acc = {};
35
+ const result = {};
39
36
  for (const K2 of K)
40
- Acc[K2] = T;
41
- return (0, index_2.Object)(Acc, { ...options, [index_8.Hint]: 'Record' });
37
+ result[K2] = T;
38
+ return (0, index_4.Object)(result, { ...options, [index_1.Hint]: 'Record' });
42
39
  }
43
40
  // prettier-ignore
44
41
  function FromTemplateLiteralKey(K, T, options) {
45
- return ((0, index_5.IsTemplateLiteralFinite)(K)
46
- ? RecordCreateFromKeys((0, index_7.IndexPropertyKeys)(K), T, options)
42
+ return ((0, index_7.IsTemplateLiteralFinite)(K)
43
+ ? RecordCreateFromKeys((0, index_9.IndexPropertyKeys)(K), T, options)
47
44
  : RecordCreateFromPattern(K.pattern, T, options));
48
45
  }
49
46
  // prettier-ignore
50
- function FromUnionKey(K, T, options) {
51
- return RecordCreateFromKeys((0, index_7.IndexPropertyKeys)((0, index_4.Union)(K)), T, options);
47
+ function FromUnionKey(key, type, options) {
48
+ return RecordCreateFromKeys((0, index_9.IndexPropertyKeys)((0, index_6.Union)(key)), type, options);
52
49
  }
53
50
  // prettier-ignore
54
- function FromLiteralKey(K, T, options) {
55
- return RecordCreateFromKeys([K.toString()], T, options);
51
+ function FromLiteralKey(key, type, options) {
52
+ return RecordCreateFromKeys([key.toString()], type, options);
56
53
  }
57
54
  // prettier-ignore
58
- function FromRegExpKey(K, T, options) {
59
- return RecordCreateFromPattern(K.source, T, options);
55
+ function FromRegExpKey(key, type, options) {
56
+ return RecordCreateFromPattern(key.source, type, options);
60
57
  }
61
58
  // prettier-ignore
62
- function FromStringKey(K, T, options) {
63
- const pattern = (0, value_1.IsUndefined)(K.pattern) ? index_6.PatternStringExact : K.pattern;
64
- return RecordCreateFromPattern(pattern, T, options);
59
+ function FromStringKey(key, type, options) {
60
+ const pattern = (0, value_1.IsUndefined)(key.pattern) ? index_8.PatternStringExact : key.pattern;
61
+ return RecordCreateFromPattern(pattern, type, options);
65
62
  }
66
63
  // prettier-ignore
67
- function FromAnyKey(K, T, options) {
68
- return RecordCreateFromPattern(index_6.PatternStringExact, T, options);
64
+ function FromAnyKey(_, type, options) {
65
+ return RecordCreateFromPattern(index_8.PatternStringExact, type, options);
69
66
  }
70
67
  // prettier-ignore
71
- function FromNeverKey(K, T, options) {
72
- return RecordCreateFromPattern(index_6.PatternNeverExact, T, options);
68
+ function FromNeverKey(_key, type, options) {
69
+ return RecordCreateFromPattern(index_8.PatternNeverExact, type, options);
73
70
  }
74
71
  // prettier-ignore
75
- function FromIntegerKey(_, T, options) {
76
- return RecordCreateFromPattern(index_6.PatternNumberExact, T, options);
72
+ function FromIntegerKey(_key, type, options) {
73
+ return RecordCreateFromPattern(index_8.PatternNumberExact, type, options);
77
74
  }
78
75
  // prettier-ignore
79
- function FromNumberKey(_, T, options) {
80
- return RecordCreateFromPattern(index_6.PatternNumberExact, T, options);
76
+ function FromNumberKey(_, type, options) {
77
+ return RecordCreateFromPattern(index_8.PatternNumberExact, type, options);
81
78
  }
82
79
  // ------------------------------------------------------------------
83
80
  // TRecordOrObject
@@ -85,16 +82,17 @@ function FromNumberKey(_, T, options) {
85
82
  /** `[Json]` Creates a Record type */
86
83
  function Record(key, type, options = {}) {
87
84
  // prettier-ignore
88
- return ((0, kind_1.IsRef)(type) ? (0, index_1.Computed)('Record', [key, type]) :
89
- (0, kind_1.IsRef)(key) ? (0, index_1.Computed)('Record', [key, type]) :
90
- (0, kind_1.IsUnion)(key) ? FromUnionKey(key.anyOf, type, options) :
91
- (0, kind_1.IsTemplateLiteral)(key) ? FromTemplateLiteralKey(key, type, options) :
92
- (0, kind_1.IsLiteral)(key) ? FromLiteralKey(key.const, type, options) :
93
- (0, kind_1.IsInteger)(key) ? FromIntegerKey(key, type, options) :
94
- (0, kind_1.IsNumber)(key) ? FromNumberKey(key, type, options) :
95
- (0, kind_1.IsRegExp)(key) ? FromRegExpKey(key, type, options) :
96
- (0, kind_1.IsString)(key) ? FromStringKey(key, type, options) :
97
- (0, kind_1.IsAny)(key) ? FromAnyKey(key, type, options) :
98
- (0, kind_1.IsNever)(key) ? FromNeverKey(key, type, options) :
99
- (0, index_3.Never)(options));
85
+ return ((0, kind_1.IsComputed)(type) ? (0, index_2.Computed)('Record', [key, (0, index_2.Computed)(type.target, type.parameters)], options) :
86
+ (0, kind_1.IsComputed)(key) ? (0, index_2.Computed)('Record', [(0, index_2.Computed)(type.target, type.parameters), type], options) :
87
+ (0, kind_1.IsRef)(key) ? (0, index_2.Computed)('Record', [(0, index_5.Ref)(key.$ref), type]) :
88
+ (0, kind_1.IsUnion)(key) ? FromUnionKey(key.anyOf, type, options) :
89
+ (0, kind_1.IsTemplateLiteral)(key) ? FromTemplateLiteralKey(key, type, options) :
90
+ (0, kind_1.IsLiteral)(key) ? FromLiteralKey(key.const, type, options) :
91
+ (0, kind_1.IsInteger)(key) ? FromIntegerKey(key, type, options) :
92
+ (0, kind_1.IsNumber)(key) ? FromNumberKey(key, type, options) :
93
+ (0, kind_1.IsRegExp)(key) ? FromRegExpKey(key, type, options) :
94
+ (0, kind_1.IsString)(key) ? FromStringKey(key, type, options) :
95
+ (0, kind_1.IsAny)(key) ? FromAnyKey(key, type, options) :
96
+ (0, kind_1.IsNever)(key) ? FromNeverKey(key, type, options) :
97
+ (0, index_3.Never)(options));
100
98
  }
@@ -48,7 +48,7 @@ export declare const Module: Runtime.Module<{
48
48
  Iterator: Runtime.ITuple<Types.TIterator<Types.TSchema>>;
49
49
  Awaited: Runtime.ITuple<Types.TSchema>;
50
50
  Array: Runtime.ITuple<Types.TArray<Types.TSchema>>;
51
- Record: Runtime.ITuple<Types.TNever>;
51
+ Record: Runtime.ITuple<Types.TSchema>;
52
52
  Promise: Runtime.ITuple<Types.TPromise<Types.TSchema>>;
53
53
  ConstructorParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
54
54
  FunctionParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
@@ -196,6 +196,7 @@ export function IsSchema(value) {
196
196
  IsBoolean(value) ||
197
197
  IsBigInt(value) ||
198
198
  IsAsyncIterator(value) ||
199
+ IsComputed(value) ||
199
200
  IsConstructor(value) ||
200
201
  IsDate(value) ||
201
202
  IsFunction(value) ||
@@ -145,7 +145,11 @@ export function IsBoolean(value) {
145
145
  }
146
146
  /** Returns true if the given value is TComputed */
147
147
  export function IsComputed(value) {
148
- return IsKindOf(value, 'Computed') && IsString(value.target) && ValueGuard.IsArray(value.parameters) && value.parameters.every((schema) => IsSchema(schema));
148
+ // prettier-ignore
149
+ return (IsKindOf(value, 'Computed') &&
150
+ ValueGuard.IsString(value.target) &&
151
+ ValueGuard.IsArray(value.parameters) &&
152
+ value.parameters.every((schema) => IsSchema(schema)));
149
153
  }
150
154
  /** Returns true if the given value is TConstructor */
151
155
  export function IsConstructor(value) {
@@ -463,6 +467,7 @@ export function IsSchema(value) {
463
467
  IsBoolean(value) ||
464
468
  IsBigInt(value) ||
465
469
  IsAsyncIterator(value) ||
470
+ IsComputed(value) ||
466
471
  IsConstructor(value) ||
467
472
  IsDate(value) ||
468
473
  IsFunction(value) ||
@@ -4,7 +4,7 @@ import { Awaited } from '../awaited/index.mjs';
4
4
  import { AsyncIterator } from '../async-iterator/index.mjs';
5
5
  import { Constructor } from '../constructor/index.mjs';
6
6
  import { Index } from '../indexed/index.mjs';
7
- import { Function } from '../function/index.mjs';
7
+ import { Function as FunctionType } from '../function/index.mjs';
8
8
  import { Intersect } from '../intersect/index.mjs';
9
9
  import { Iterator } from '../iterator/index.mjs';
10
10
  import { KeyOf } from '../keyof/index.mjs';
@@ -93,7 +93,7 @@ function FromConstructor(moduleProperties, parameters, instanceType) {
93
93
  }
94
94
  // prettier-ignore
95
95
  function FromFunction(moduleProperties, parameters, returnType) {
96
- return Function(FromRest(moduleProperties, parameters), FromType(moduleProperties, returnType));
96
+ return FunctionType(FromRest(moduleProperties, parameters), FromType(moduleProperties, returnType));
97
97
  }
98
98
  function FromTuple(moduleProperties, types) {
99
99
  return Tuple(FromRest(moduleProperties, types));
@@ -9,6 +9,7 @@ import { TIntersect } from '../intersect/index.mjs';
9
9
  import { TIterator } from '../iterator/index.mjs';
10
10
  import { TObject, TProperties } from '../object/index.mjs';
11
11
  import { TOptional } from '../optional/index.mjs';
12
+ import { TRecord } from '../record/index.mjs';
12
13
  import { TReadonly } from '../readonly/index.mjs';
13
14
  import { TRef } from '../ref/index.mjs';
14
15
  import { TTuple } from '../tuple/index.mjs';
@@ -19,15 +20,15 @@ type TInferAsyncIterator<ModuleProperties extends TProperties, Type extends TSch
19
20
  type TInferConstructor<ModuleProperties extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema> = Ensure<new (...args: TInferTuple<ModuleProperties, Parameters>) => TInfer<ModuleProperties, InstanceType>>;
20
21
  type TInferFunction<ModuleProperties extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema> = Ensure<(...args: TInferTuple<ModuleProperties, Parameters>) => TInfer<ModuleProperties, ReturnType>>;
21
22
  type TInferIterator<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<IterableIterator<TInfer<ModuleProperties, Type>>>);
22
- type TInferIntersect<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown = unknown> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferIntersect<ModuleProperties, R, Result & TInfer<ModuleProperties, L>> : Result);
23
+ type TInferIntersect<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown = unknown> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TInferIntersect<ModuleProperties, Right, Result & TInfer<ModuleProperties, Left>> : Result);
23
24
  type ReadonlyOptionalPropertyKeys<Properties extends TProperties> = {
24
- [K in keyof Properties]: Properties[K] extends TReadonly<TSchema> ? (Properties[K] extends TOptional<Properties[K]> ? K : never) : never;
25
+ [Key in keyof Properties]: Properties[Key] extends TReadonly<TSchema> ? (Properties[Key] extends TOptional<Properties[Key]> ? Key : never) : never;
25
26
  }[keyof Properties];
26
27
  type ReadonlyPropertyKeys<Source extends TProperties> = {
27
- [K in keyof Source]: Source[K] extends TReadonly<TSchema> ? (Source[K] extends TOptional<Source[K]> ? never : K) : never;
28
+ [Key in keyof Source]: Source[Key] extends TReadonly<TSchema> ? (Source[Key] extends TOptional<Source[Key]> ? never : Key) : never;
28
29
  }[keyof Source];
29
30
  type OptionalPropertyKeys<Source extends TProperties> = {
30
- [K in keyof Source]: Source[K] extends TOptional<TSchema> ? (Source[K] extends TReadonly<Source[K]> ? never : K) : never;
31
+ [Key in keyof Source]: Source[Key] extends TOptional<TSchema> ? (Source[Key] extends TReadonly<Source[Key]> ? never : Key) : never;
31
32
  }[keyof Source];
32
33
  type RequiredPropertyKeys<Source extends TProperties> = keyof Omit<Source, ReadonlyOptionalPropertyKeys<Source> | ReadonlyPropertyKeys<Source> | OptionalPropertyKeys<Source>>;
33
34
  type InferPropertiesWithModifiers<Properties extends TProperties, Source extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<Source, ReadonlyOptionalPropertyKeys<Properties>>>> & Readonly<Pick<Source, ReadonlyPropertyKeys<Properties>>> & Partial<Pick<Source, OptionalPropertyKeys<Properties>>> & Required<Pick<Source, RequiredPropertyKeys<Properties>>>)>;
@@ -36,9 +37,10 @@ type InferProperties<ModuleProperties extends TProperties, Properties extends TP
36
37
  }>;
37
38
  type TInferObject<ModuleProperties extends TProperties, Properties extends TProperties> = (InferProperties<ModuleProperties, Properties>);
38
39
  type TInferTuple<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferTuple<ModuleProperties, R, [...Result, TInfer<ModuleProperties, L>]> : Result);
40
+ type TInferRecord<ModuleProperties extends TProperties, Key extends TSchema, Type extends TSchema, InferredKey extends PropertyKey = TInfer<ModuleProperties, Key> extends infer Key extends PropertyKey ? Key : never, InferedType extends unknown = TInfer<ModuleProperties, Type>> = Record<InferredKey, InferedType>;
39
41
  type TInferRef<ModuleProperties extends TProperties, Ref extends string> = (Ref extends keyof ModuleProperties ? TInfer<ModuleProperties, ModuleProperties[Ref]> : unknown);
40
42
  type TInferUnion<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown = never> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferUnion<ModuleProperties, R, Result | TInfer<ModuleProperties, L>> : Result);
41
- type TInfer<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TInferArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TInferAsyncIterator<ModuleProperties, Type> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TInferConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TInferFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TInferIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TInferIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TInferObject<ModuleProperties, Properties> : Type extends TRef<infer Ref extends string> ? TInferRef<ModuleProperties, Ref> : Type extends TTuple<infer Types extends TSchema[]> ? TInferTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Static<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TInferUnion<ModuleProperties, Types> : Static<Type>);
43
+ type TInfer<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TInferArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TInferAsyncIterator<ModuleProperties, Type> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TInferConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TInferFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TInferIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TInferIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TInferObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Type extends TSchema> ? TInferRecord<ModuleProperties, Key, Type> : Type extends TRef<infer Ref extends string> ? TInferRef<ModuleProperties, Ref> : Type extends TTuple<infer Types extends TSchema[]> ? TInferTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Static<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TInferUnion<ModuleProperties, Types> : Static<Type>);
42
44
  /** Inference Path for Imports. This type is used to compute TImport `static` */
43
45
  export type TInferFromModuleKey<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TInfer<ModuleProperties, ModuleProperties[Key]> : never);
44
46
  export {};
@@ -16,7 +16,8 @@ export class TModule {
16
16
  }
17
17
  /** `[Json]` Imports a Type by Key. */
18
18
  Import(key, options) {
19
- return CreateType({ [Kind]: 'Import', $defs: this.$defs, $ref: key }, options);
19
+ const $defs = { ...this.$defs, [key]: CreateType(this.$defs[key], options) };
20
+ return CreateType({ [Kind]: 'Import', $defs, $ref: key });
20
21
  }
21
22
  // prettier-ignore
22
23
  WithIdentifiers($defs) {
@@ -1,58 +1,58 @@
1
+ import { Kind } from '../symbols/index.mjs';
1
2
  import type { TSchema } from '../schema/index.mjs';
2
3
  import type { Static } from '../static/index.mjs';
3
4
  import type { Evaluate, Ensure, Assert } from '../helpers/index.mjs';
4
5
  import { type TAny } from '../any/index.mjs';
5
6
  import { type TComputed } from '../computed/index.mjs';
6
- import { type TObject, type TProperties, type TAdditionalProperties, type ObjectOptions } from '../object/index.mjs';
7
+ import { type TEnumRecord, type TEnum } from '../enum/index.mjs';
8
+ import { type TInteger } from '../integer/index.mjs';
7
9
  import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
8
10
  import { type TNever } from '../never/index.mjs';
9
- import { type TUnion } from '../union/index.mjs';
10
- import { type TRegExp } from '../regexp/index.mjs';
11
- import { type TString } from '../string/index.mjs';
12
- import { type TInteger } from '../integer/index.mjs';
13
11
  import { type TNumber } from '../number/index.mjs';
14
- import { type TEnum } from '../enum/index.mjs';
12
+ import { type TObject, type TProperties, type TAdditionalProperties, type ObjectOptions } from '../object/index.mjs';
15
13
  import { type TRef } from '../ref/index.mjs';
14
+ import { type TRegExp } from '../regexp/index.mjs';
15
+ import { type TString } from '../string/index.mjs';
16
+ import { type TUnion } from '../union/index.mjs';
16
17
  import { TIsTemplateLiteralFinite, type TTemplateLiteral } from '../template-literal/index.mjs';
17
- import { Kind } from '../symbols/index.mjs';
18
- type TFromTemplateLiteralKeyInfinite<K extends TTemplateLiteral, T extends TSchema> = Ensure<TRecord<K, T>>;
19
- type TFromTemplateLiteralKeyFinite<K extends TTemplateLiteral, T extends TSchema, I extends string = Static<K>> = (Ensure<TObject<Evaluate<{
20
- [_ in I]: T;
18
+ type TFromTemplateLiteralKeyInfinite<Key extends TTemplateLiteral, Type extends TSchema> = Ensure<TRecord<Key, Type>>;
19
+ type TFromTemplateLiteralKeyFinite<Key extends TTemplateLiteral, Type extends TSchema, I extends string = Static<Key>> = (Ensure<TObject<Evaluate<{
20
+ [_ in I]: Type;
21
21
  }>>>);
22
- type TFromTemplateLiteralKey<K extends TTemplateLiteral, T extends TSchema> = TIsTemplateLiteralFinite<K> extends false ? TFromTemplateLiteralKeyInfinite<K, T> : TFromTemplateLiteralKeyFinite<K, T>;
23
- type TFromEnumKey<K extends Record<string, string | number>, T extends TSchema> = Ensure<TObject<{
24
- [_ in K[keyof K]]: T;
22
+ type TFromTemplateLiteralKey<Key extends TTemplateLiteral, Type extends TSchema> = TIsTemplateLiteralFinite<Key> extends false ? TFromTemplateLiteralKeyInfinite<Key, Type> : TFromTemplateLiteralKeyFinite<Key, Type>;
23
+ type TFromEnumKey<Key extends Record<string, string | number>, Type extends TSchema> = Ensure<TObject<{
24
+ [_ in Key[keyof Key]]: Type;
25
25
  }>>;
26
- type TFromUnionKeyLiteralString<K extends TLiteral<string>, T extends TSchema> = {
27
- [_ in K['const']]: T;
26
+ type TFromUnionKeyLiteralString<Key extends TLiteral<string>, Type extends TSchema> = {
27
+ [_ in Key['const']]: Type;
28
28
  };
29
- type TFromUnionKeyLiteralNumber<K extends TLiteral<number>, T extends TSchema> = {
30
- [_ in K['const']]: T;
29
+ type TFromUnionKeyLiteralNumber<Key extends TLiteral<number>, Type extends TSchema> = {
30
+ [_ in Key['const']]: Type;
31
31
  };
32
- type TFromUnionKeyRest<K extends TSchema[], T extends TSchema> = K extends [infer L extends TSchema, ...infer R extends TSchema[]] ? (L extends TUnion<infer S> ? TFromUnionKeyRest<S, T> & TFromUnionKeyRest<R, T> : L extends TLiteral<string> ? TFromUnionKeyLiteralString<L, T> & TFromUnionKeyRest<R, T> : L extends TLiteral<number> ? TFromUnionKeyLiteralNumber<L, T> & TFromUnionKeyRest<R, T> : {}) : {};
33
- type TFromUnionKey<K extends TSchema[], T extends TSchema, P extends TProperties = TFromUnionKeyRest<K, T>> = (Ensure<TObject<Evaluate<P>>>);
34
- type TFromLiteralKey<K extends TLiteralValue, T extends TSchema> = (Ensure<TObject<{
35
- [_ in Assert<K, PropertyKey>]: T;
32
+ type TFromUnionKeyRest<Keys extends TSchema[], Type extends TSchema> = Keys extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? (Left extends TUnion<infer Types extends TSchema[]> ? TFromUnionKeyRest<Types, Type> & TFromUnionKeyRest<Right, Type> : Left extends TLiteral<string> ? TFromUnionKeyLiteralString<Left, Type> & TFromUnionKeyRest<Right, Type> : Left extends TLiteral<number> ? TFromUnionKeyLiteralNumber<Left, Type> & TFromUnionKeyRest<Right, Type> : {}) : {};
33
+ type TFromUnionKey<Key extends TSchema[], Type extends TSchema, P extends TProperties = TFromUnionKeyRest<Key, Type>> = (Ensure<TObject<Evaluate<P>>>);
34
+ type TFromLiteralKey<Key extends TLiteralValue, Type extends TSchema> = (Ensure<TObject<{
35
+ [_ in Assert<Key, PropertyKey>]: Type;
36
36
  }>>);
37
- type TFromRegExpKey<_ extends TRegExp, T extends TSchema> = (Ensure<TRecord<TRegExp, T>>);
38
- type TFromStringKey<_ extends TString, T extends TSchema> = (Ensure<TRecord<TString, T>>);
39
- type TFromAnyKey<_ extends TAny, T extends TSchema> = (Ensure<TRecord<TAny, T>>);
40
- type TFromNeverKey<_ extends TNever, T extends TSchema> = (Ensure<TRecord<TNever, T>>);
41
- type TFromIntegerKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
42
- type TFromNumberKey<_ extends TSchema, T extends TSchema> = (Ensure<TRecord<TNumber, T>>);
43
- type RecordStatic<K extends TSchema, T extends TSchema, P extends unknown[]> = (Evaluate<{
44
- [_ in Assert<Static<K>, PropertyKey>]: Static<T, P>;
37
+ type TFromRegExpKey<_Key extends TRegExp, Type extends TSchema> = (Ensure<TRecord<TRegExp, Type>>);
38
+ type TFromStringKey<_Key extends TString, Type extends TSchema> = (Ensure<TRecord<TString, Type>>);
39
+ type TFromAnyKey<_Key extends TAny, Type extends TSchema> = (Ensure<TRecord<TAny, Type>>);
40
+ type TFromNeverKey<_Key extends TNever, Type extends TSchema> = (Ensure<TRecord<TNever, Type>>);
41
+ type TFromIntegerKey<_Key extends TSchema, Type extends TSchema> = (Ensure<TRecord<TNumber, Type>>);
42
+ type TFromNumberKey<_Key extends TSchema, Type extends TSchema> = (Ensure<TRecord<TNumber, Type>>);
43
+ type RecordStatic<Key extends TSchema, Type extends TSchema, P extends unknown[]> = (Evaluate<{
44
+ [_ in Assert<Static<Key>, PropertyKey>]: Static<Type, P>;
45
45
  }>);
46
- export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchema> extends TSchema {
46
+ export interface TRecord<Key extends TSchema = TSchema, Type extends TSchema = TSchema> extends TSchema {
47
47
  [Kind]: 'Record';
48
- static: RecordStatic<K, T, this['params']>;
48
+ static: RecordStatic<Key, Type, this['params']>;
49
49
  type: 'object';
50
50
  patternProperties: {
51
- [pattern: string]: T;
51
+ [pattern: string]: Type;
52
52
  };
53
53
  additionalProperties: TAdditionalProperties;
54
54
  }
55
- export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = Type extends TRef ? TComputed<'Record', [Key, Type]> : Key extends TRef ? TComputed<'Record', [Key, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer S> ? TFromEnumKey<S, Type> : Key extends TUnion<infer S> ? TFromUnionKey<S, Type> : Key extends TLiteral<infer S> ? TFromLiteralKey<S, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : TNever;
55
+ export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [Key, TComputed<Target, Parameters>]> : Key extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [TComputed<Target, Parameters>, Type]> : Key extends TRef<infer Ref extends string> ? TComputed<'Record', [TRef<Ref>, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer Enum extends TEnumRecord> ? TFromEnumKey<Enum, Type> : Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Type> : Key extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteralKey<Value, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : Key);
56
56
  /** `[Json]` Creates a Record type */
57
57
  export declare function Record<Key extends TSchema, Type extends TSchema>(key: Key, type: Type, options?: ObjectOptions): TRecordOrObject<Key, Type>;
58
58
  export {};
@@ -1,12 +1,13 @@
1
1
  import { CreateType } from '../create/type.mjs';
2
+ import { Kind, Hint } from '../symbols/index.mjs';
2
3
  import { Computed } from '../computed/index.mjs';
3
- import { Object } from '../object/index.mjs';
4
4
  import { Never } from '../never/index.mjs';
5
+ import { Object } from '../object/index.mjs';
6
+ import { Ref } from '../ref/index.mjs';
5
7
  import { Union } from '../union/index.mjs';
6
8
  import { IsTemplateLiteralFinite } from '../template-literal/index.mjs';
7
9
  import { PatternStringExact, PatternNumberExact, PatternNeverExact } from '../patterns/index.mjs';
8
10
  import { IndexPropertyKeys } from '../indexed/index.mjs';
9
- import { Kind, Hint } from '../symbols/index.mjs';
10
11
  // ------------------------------------------------------------------
11
12
  // ValueGuard
12
13
  // ------------------------------------------------------------------
@@ -14,27 +15,23 @@ import { IsUndefined } from '../guard/value.mjs';
14
15
  // ------------------------------------------------------------------
15
16
  // TypeGuard
16
17
  // ------------------------------------------------------------------
17
- import { IsInteger, IsLiteral, IsAny, IsNever, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion, IsRef } from '../guard/kind.mjs';
18
+ import { IsInteger, IsLiteral, IsAny, IsNever, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion, IsRef, IsComputed } from '../guard/kind.mjs';
18
19
  // ------------------------------------------------------------------
19
20
  // RecordCreateFromPattern
20
21
  // ------------------------------------------------------------------
21
22
  // prettier-ignore
22
23
  function RecordCreateFromPattern(pattern, T, options) {
23
- return CreateType({
24
- [Kind]: 'Record',
25
- type: 'object',
26
- patternProperties: { [pattern]: T }
27
- }, options);
24
+ return CreateType({ [Kind]: 'Record', type: 'object', patternProperties: { [pattern]: T } }, options);
28
25
  }
29
26
  // ------------------------------------------------------------------
30
27
  // RecordCreateFromKeys
31
28
  // ------------------------------------------------------------------
32
29
  // prettier-ignore
33
30
  function RecordCreateFromKeys(K, T, options) {
34
- const Acc = {};
31
+ const result = {};
35
32
  for (const K2 of K)
36
- Acc[K2] = T;
37
- return Object(Acc, { ...options, [Hint]: 'Record' });
33
+ result[K2] = T;
34
+ return Object(result, { ...options, [Hint]: 'Record' });
38
35
  }
39
36
  // prettier-ignore
40
37
  function FromTemplateLiteralKey(K, T, options) {
@@ -43,37 +40,37 @@ function FromTemplateLiteralKey(K, T, options) {
43
40
  : RecordCreateFromPattern(K.pattern, T, options));
44
41
  }
45
42
  // prettier-ignore
46
- function FromUnionKey(K, T, options) {
47
- return RecordCreateFromKeys(IndexPropertyKeys(Union(K)), T, options);
43
+ function FromUnionKey(key, type, options) {
44
+ return RecordCreateFromKeys(IndexPropertyKeys(Union(key)), type, options);
48
45
  }
49
46
  // prettier-ignore
50
- function FromLiteralKey(K, T, options) {
51
- return RecordCreateFromKeys([K.toString()], T, options);
47
+ function FromLiteralKey(key, type, options) {
48
+ return RecordCreateFromKeys([key.toString()], type, options);
52
49
  }
53
50
  // prettier-ignore
54
- function FromRegExpKey(K, T, options) {
55
- return RecordCreateFromPattern(K.source, T, options);
51
+ function FromRegExpKey(key, type, options) {
52
+ return RecordCreateFromPattern(key.source, type, options);
56
53
  }
57
54
  // prettier-ignore
58
- function FromStringKey(K, T, options) {
59
- const pattern = IsUndefined(K.pattern) ? PatternStringExact : K.pattern;
60
- return RecordCreateFromPattern(pattern, T, options);
55
+ function FromStringKey(key, type, options) {
56
+ const pattern = IsUndefined(key.pattern) ? PatternStringExact : key.pattern;
57
+ return RecordCreateFromPattern(pattern, type, options);
61
58
  }
62
59
  // prettier-ignore
63
- function FromAnyKey(K, T, options) {
64
- return RecordCreateFromPattern(PatternStringExact, T, options);
60
+ function FromAnyKey(_, type, options) {
61
+ return RecordCreateFromPattern(PatternStringExact, type, options);
65
62
  }
66
63
  // prettier-ignore
67
- function FromNeverKey(K, T, options) {
68
- return RecordCreateFromPattern(PatternNeverExact, T, options);
64
+ function FromNeverKey(_key, type, options) {
65
+ return RecordCreateFromPattern(PatternNeverExact, type, options);
69
66
  }
70
67
  // prettier-ignore
71
- function FromIntegerKey(_, T, options) {
72
- return RecordCreateFromPattern(PatternNumberExact, T, options);
68
+ function FromIntegerKey(_key, type, options) {
69
+ return RecordCreateFromPattern(PatternNumberExact, type, options);
73
70
  }
74
71
  // prettier-ignore
75
- function FromNumberKey(_, T, options) {
76
- return RecordCreateFromPattern(PatternNumberExact, T, options);
72
+ function FromNumberKey(_, type, options) {
73
+ return RecordCreateFromPattern(PatternNumberExact, type, options);
77
74
  }
78
75
  // ------------------------------------------------------------------
79
76
  // TRecordOrObject
@@ -81,16 +78,17 @@ function FromNumberKey(_, T, options) {
81
78
  /** `[Json]` Creates a Record type */
82
79
  export function Record(key, type, options = {}) {
83
80
  // prettier-ignore
84
- return (IsRef(type) ? Computed('Record', [key, type]) :
85
- IsRef(key) ? Computed('Record', [key, type]) :
86
- IsUnion(key) ? FromUnionKey(key.anyOf, type, options) :
87
- IsTemplateLiteral(key) ? FromTemplateLiteralKey(key, type, options) :
88
- IsLiteral(key) ? FromLiteralKey(key.const, type, options) :
89
- IsInteger(key) ? FromIntegerKey(key, type, options) :
90
- IsNumber(key) ? FromNumberKey(key, type, options) :
91
- IsRegExp(key) ? FromRegExpKey(key, type, options) :
92
- IsString(key) ? FromStringKey(key, type, options) :
93
- IsAny(key) ? FromAnyKey(key, type, options) :
94
- IsNever(key) ? FromNeverKey(key, type, options) :
95
- Never(options));
81
+ return (IsComputed(type) ? Computed('Record', [key, Computed(type.target, type.parameters)], options) :
82
+ IsComputed(key) ? Computed('Record', [Computed(type.target, type.parameters), type], options) :
83
+ IsRef(key) ? Computed('Record', [Ref(key.$ref), type]) :
84
+ IsUnion(key) ? FromUnionKey(key.anyOf, type, options) :
85
+ IsTemplateLiteral(key) ? FromTemplateLiteralKey(key, type, options) :
86
+ IsLiteral(key) ? FromLiteralKey(key.const, type, options) :
87
+ IsInteger(key) ? FromIntegerKey(key, type, options) :
88
+ IsNumber(key) ? FromNumberKey(key, type, options) :
89
+ IsRegExp(key) ? FromRegExpKey(key, type, options) :
90
+ IsString(key) ? FromStringKey(key, type, options) :
91
+ IsAny(key) ? FromAnyKey(key, type, options) :
92
+ IsNever(key) ? FromNeverKey(key, type, options) :
93
+ Never(options));
96
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.34.4",
3
+ "version": "0.34.6",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",