@sinclair/typebox 0.34.19 → 0.34.20

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.
@@ -4,14 +4,12 @@ import type { Static } from '../static/index';
4
4
  import type { Evaluate, Ensure, Assert } from '../helpers/index';
5
5
  import { type TAny } from '../any/index';
6
6
  import { type TBoolean } from '../boolean/index';
7
- import { type TComputed } from '../computed/index';
8
7
  import { type TEnumRecord, type TEnum } from '../enum/index';
9
8
  import { type TInteger } from '../integer/index';
10
9
  import { type TLiteral, type TLiteralValue } from '../literal/index';
11
10
  import { type TNever } from '../never/index';
12
11
  import { type TNumber } from '../number/index';
13
12
  import { type TObject, type TProperties, type TAdditionalProperties, type ObjectOptions } from '../object/index';
14
- import { type TRef } from '../ref/index';
15
13
  import { type TRegExp } from '../regexp/index';
16
14
  import { type TString } from '../string/index';
17
15
  import { type TUnion } from '../union/index';
@@ -57,7 +55,7 @@ export interface TRecord<Key extends TSchema = TSchema, Type extends TSchema = T
57
55
  };
58
56
  additionalProperties: TAdditionalProperties;
59
57
  }
60
- 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 TBoolean ? TFromBooleanKey<Key, 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);
58
+ export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (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 TBoolean ? TFromBooleanKey<Key, 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);
61
59
  /** `[Json]` Creates a Record type */
62
60
  export declare function Record<Key extends TSchema, Type extends TSchema>(key: Key, type: Type, options?: ObjectOptions): TRecordOrObject<Key, Type>;
63
61
  /** Gets the Records Pattern */
@@ -7,16 +7,14 @@ exports.RecordKey = RecordKey;
7
7
  exports.RecordValue = RecordValue;
8
8
  const type_1 = require("../create/type");
9
9
  const index_1 = require("../symbols/index");
10
- const index_2 = require("../computed/index");
11
- const index_3 = require("../never/index");
12
- const index_4 = require("../number/index");
13
- const index_5 = require("../object/index");
14
- const index_6 = require("../ref/index");
15
- const index_7 = require("../string/index");
16
- const index_8 = require("../union/index");
17
- const index_9 = require("../template-literal/index");
18
- const index_10 = require("../patterns/index");
19
- const index_11 = require("../indexed/index");
10
+ const index_2 = require("../never/index");
11
+ const index_3 = require("../number/index");
12
+ const index_4 = require("../object/index");
13
+ const index_5 = require("../string/index");
14
+ const index_6 = require("../union/index");
15
+ const index_7 = require("../template-literal/index");
16
+ const index_8 = require("../patterns/index");
17
+ const index_9 = require("../indexed/index");
20
18
  // ------------------------------------------------------------------
21
19
  // ValueGuard
22
20
  // ------------------------------------------------------------------
@@ -40,17 +38,17 @@ function RecordCreateFromKeys(K, T, options) {
40
38
  const result = {};
41
39
  for (const K2 of K)
42
40
  result[K2] = T;
43
- return (0, index_5.Object)(result, { ...options, [index_1.Hint]: 'Record' });
41
+ return (0, index_4.Object)(result, { ...options, [index_1.Hint]: 'Record' });
44
42
  }
45
43
  // prettier-ignore
46
44
  function FromTemplateLiteralKey(K, T, options) {
47
- return ((0, index_9.IsTemplateLiteralFinite)(K)
48
- ? RecordCreateFromKeys((0, index_11.IndexPropertyKeys)(K), T, options)
45
+ return ((0, index_7.IsTemplateLiteralFinite)(K)
46
+ ? RecordCreateFromKeys((0, index_9.IndexPropertyKeys)(K), T, options)
49
47
  : RecordCreateFromPattern(K.pattern, T, options));
50
48
  }
51
49
  // prettier-ignore
52
50
  function FromUnionKey(key, type, options) {
53
- return RecordCreateFromKeys((0, index_11.IndexPropertyKeys)((0, index_8.Union)(key)), type, options);
51
+ return RecordCreateFromKeys((0, index_9.IndexPropertyKeys)((0, index_6.Union)(key)), type, options);
54
52
  }
55
53
  // prettier-ignore
56
54
  function FromLiteralKey(key, type, options) {
@@ -62,28 +60,28 @@ function FromRegExpKey(key, type, options) {
62
60
  }
63
61
  // prettier-ignore
64
62
  function FromStringKey(key, type, options) {
65
- const pattern = (0, value_1.IsUndefined)(key.pattern) ? index_10.PatternStringExact : key.pattern;
63
+ const pattern = (0, value_1.IsUndefined)(key.pattern) ? index_8.PatternStringExact : key.pattern;
66
64
  return RecordCreateFromPattern(pattern, type, options);
67
65
  }
68
66
  // prettier-ignore
69
67
  function FromAnyKey(_, type, options) {
70
- return RecordCreateFromPattern(index_10.PatternStringExact, type, options);
68
+ return RecordCreateFromPattern(index_8.PatternStringExact, type, options);
71
69
  }
72
70
  // prettier-ignore
73
71
  function FromNeverKey(_key, type, options) {
74
- return RecordCreateFromPattern(index_10.PatternNeverExact, type, options);
72
+ return RecordCreateFromPattern(index_8.PatternNeverExact, type, options);
75
73
  }
76
74
  // prettier-ignore
77
75
  function FromBooleanKey(_key, type, options) {
78
- return (0, index_5.Object)({ true: type, false: type }, options);
76
+ return (0, index_4.Object)({ true: type, false: type }, options);
79
77
  }
80
78
  // prettier-ignore
81
79
  function FromIntegerKey(_key, type, options) {
82
- return RecordCreateFromPattern(index_10.PatternNumberExact, type, options);
80
+ return RecordCreateFromPattern(index_8.PatternNumberExact, type, options);
83
81
  }
84
82
  // prettier-ignore
85
83
  function FromNumberKey(_, type, options) {
86
- return RecordCreateFromPattern(index_10.PatternNumberExact, type, options);
84
+ return RecordCreateFromPattern(index_8.PatternNumberExact, type, options);
87
85
  }
88
86
  // ------------------------------------------------------------------
89
87
  // TRecordOrObject
@@ -91,20 +89,17 @@ function FromNumberKey(_, type, options) {
91
89
  /** `[Json]` Creates a Record type */
92
90
  function Record(key, type, options = {}) {
93
91
  // prettier-ignore
94
- return ((0, kind_1.IsComputed)(type) ? (0, index_2.Computed)('Record', [key, (0, index_2.Computed)(type.target, type.parameters)], options) :
95
- (0, kind_1.IsComputed)(key) ? (0, index_2.Computed)('Record', [(0, index_2.Computed)(type.target, type.parameters), type], options) :
96
- (0, kind_1.IsRef)(key) ? (0, index_2.Computed)('Record', [(0, index_6.Ref)(key.$ref), type]) :
97
- (0, kind_1.IsUnion)(key) ? FromUnionKey(key.anyOf, type, options) :
98
- (0, kind_1.IsTemplateLiteral)(key) ? FromTemplateLiteralKey(key, type, options) :
99
- (0, kind_1.IsLiteral)(key) ? FromLiteralKey(key.const, type, options) :
100
- (0, kind_1.IsBoolean)(key) ? FromBooleanKey(key, type, options) :
101
- (0, kind_1.IsInteger)(key) ? FromIntegerKey(key, type, options) :
102
- (0, kind_1.IsNumber)(key) ? FromNumberKey(key, type, options) :
103
- (0, kind_1.IsRegExp)(key) ? FromRegExpKey(key, type, options) :
104
- (0, kind_1.IsString)(key) ? FromStringKey(key, type, options) :
105
- (0, kind_1.IsAny)(key) ? FromAnyKey(key, type, options) :
106
- (0, kind_1.IsNever)(key) ? FromNeverKey(key, type, options) :
107
- (0, index_3.Never)(options));
92
+ return ((0, kind_1.IsUnion)(key) ? FromUnionKey(key.anyOf, type, options) :
93
+ (0, kind_1.IsTemplateLiteral)(key) ? FromTemplateLiteralKey(key, type, options) :
94
+ (0, kind_1.IsLiteral)(key) ? FromLiteralKey(key.const, type, options) :
95
+ (0, kind_1.IsBoolean)(key) ? FromBooleanKey(key, type, options) :
96
+ (0, kind_1.IsInteger)(key) ? FromIntegerKey(key, type, options) :
97
+ (0, kind_1.IsNumber)(key) ? FromNumberKey(key, type, options) :
98
+ (0, kind_1.IsRegExp)(key) ? FromRegExpKey(key, type, options) :
99
+ (0, kind_1.IsString)(key) ? FromStringKey(key, type, options) :
100
+ (0, kind_1.IsAny)(key) ? FromAnyKey(key, type, options) :
101
+ (0, kind_1.IsNever)(key) ? FromNeverKey(key, type, options) :
102
+ (0, index_2.Never)(options));
108
103
  }
109
104
  // ------------------------------------------------------------------
110
105
  // Record Utilities
@@ -117,9 +112,9 @@ function RecordPattern(record) {
117
112
  // prettier-ignore
118
113
  function RecordKey(type) {
119
114
  const pattern = RecordPattern(type);
120
- return (pattern === index_10.PatternStringExact ? (0, index_7.String)() :
121
- pattern === index_10.PatternNumberExact ? (0, index_4.Number)() :
122
- (0, index_7.String)({ pattern }));
115
+ return (pattern === index_8.PatternStringExact ? (0, index_5.String)() :
116
+ pattern === index_8.PatternNumberExact ? (0, index_3.Number)() :
117
+ (0, index_5.String)({ pattern }));
123
118
  }
124
119
  /** Gets a Record Value Type */
125
120
  // prettier-ignore
@@ -4,14 +4,12 @@ import type { Static } from '../static/index.mjs';
4
4
  import type { Evaluate, Ensure, Assert } from '../helpers/index.mjs';
5
5
  import { type TAny } from '../any/index.mjs';
6
6
  import { type TBoolean } from '../boolean/index.mjs';
7
- import { type TComputed } from '../computed/index.mjs';
8
7
  import { type TEnumRecord, type TEnum } from '../enum/index.mjs';
9
8
  import { type TInteger } from '../integer/index.mjs';
10
9
  import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
11
10
  import { type TNever } from '../never/index.mjs';
12
11
  import { type TNumber } from '../number/index.mjs';
13
12
  import { type TObject, type TProperties, type TAdditionalProperties, type ObjectOptions } from '../object/index.mjs';
14
- import { type TRef } from '../ref/index.mjs';
15
13
  import { type TRegExp } from '../regexp/index.mjs';
16
14
  import { type TString } from '../string/index.mjs';
17
15
  import { type TUnion } from '../union/index.mjs';
@@ -57,7 +55,7 @@ export interface TRecord<Key extends TSchema = TSchema, Type extends TSchema = T
57
55
  };
58
56
  additionalProperties: TAdditionalProperties;
59
57
  }
60
- 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 TBoolean ? TFromBooleanKey<Key, 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);
58
+ export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (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 TBoolean ? TFromBooleanKey<Key, 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);
61
59
  /** `[Json]` Creates a Record type */
62
60
  export declare function Record<Key extends TSchema, Type extends TSchema>(key: Key, type: Type, options?: ObjectOptions): TRecordOrObject<Key, Type>;
63
61
  /** Gets the Records Pattern */
@@ -1,10 +1,8 @@
1
1
  import { CreateType } from '../create/type.mjs';
2
2
  import { Kind, Hint } from '../symbols/index.mjs';
3
- import { Computed } from '../computed/index.mjs';
4
3
  import { Never } from '../never/index.mjs';
5
4
  import { Number } from '../number/index.mjs';
6
5
  import { Object } from '../object/index.mjs';
7
- import { Ref } from '../ref/index.mjs';
8
6
  import { String } from '../string/index.mjs';
9
7
  import { Union } from '../union/index.mjs';
10
8
  import { IsTemplateLiteralFinite } from '../template-literal/index.mjs';
@@ -17,7 +15,7 @@ import { IsUndefined } from '../guard/value.mjs';
17
15
  // ------------------------------------------------------------------
18
16
  // TypeGuard
19
17
  // ------------------------------------------------------------------
20
- import { IsInteger, IsLiteral, IsAny, IsBoolean, IsNever, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion, IsRef, IsComputed } from '../guard/kind.mjs';
18
+ import { IsInteger, IsLiteral, IsAny, IsBoolean, IsNever, IsNumber, IsString, IsRegExp, IsTemplateLiteral, IsUnion } from '../guard/kind.mjs';
21
19
  // ------------------------------------------------------------------
22
20
  // RecordCreateFromPattern
23
21
  // ------------------------------------------------------------------
@@ -84,20 +82,17 @@ function FromNumberKey(_, type, options) {
84
82
  /** `[Json]` Creates a Record type */
85
83
  export function Record(key, type, options = {}) {
86
84
  // prettier-ignore
87
- return (IsComputed(type) ? Computed('Record', [key, Computed(type.target, type.parameters)], options) :
88
- IsComputed(key) ? Computed('Record', [Computed(type.target, type.parameters), type], options) :
89
- IsRef(key) ? Computed('Record', [Ref(key.$ref), type]) :
90
- IsUnion(key) ? FromUnionKey(key.anyOf, type, options) :
91
- IsTemplateLiteral(key) ? FromTemplateLiteralKey(key, type, options) :
92
- IsLiteral(key) ? FromLiteralKey(key.const, type, options) :
93
- IsBoolean(key) ? FromBooleanKey(key, type, options) :
94
- IsInteger(key) ? FromIntegerKey(key, type, options) :
95
- IsNumber(key) ? FromNumberKey(key, type, options) :
96
- IsRegExp(key) ? FromRegExpKey(key, type, options) :
97
- IsString(key) ? FromStringKey(key, type, options) :
98
- IsAny(key) ? FromAnyKey(key, type, options) :
99
- IsNever(key) ? FromNeverKey(key, type, options) :
100
- Never(options));
85
+ return (IsUnion(key) ? FromUnionKey(key.anyOf, type, options) :
86
+ IsTemplateLiteral(key) ? FromTemplateLiteralKey(key, type, options) :
87
+ IsLiteral(key) ? FromLiteralKey(key.const, type, options) :
88
+ IsBoolean(key) ? FromBooleanKey(key, 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));
101
96
  }
102
97
  // ------------------------------------------------------------------
103
98
  // Record Utilities
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.34.19",
3
+ "version": "0.34.20",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",