@sinclair/typebox 0.32.0-dev-23 → 0.32.0-dev-25

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.
Files changed (114) hide show
  1. package/build/import/compiler/compiler.d.mts +3 -2
  2. package/build/import/compiler/compiler.mjs +3 -2
  3. package/build/import/errors/errors.d.mts +2 -1
  4. package/build/import/errors/errors.mjs +2 -1
  5. package/build/import/index.d.mts +2 -1
  6. package/build/import/index.mjs +2 -1
  7. package/build/import/system/system.d.mts +3 -2
  8. package/build/import/system/system.mjs +3 -2
  9. package/build/import/type/error/error.d.mts +4 -0
  10. package/build/import/type/error/error.mjs +6 -0
  11. package/build/import/type/error/index.d.mts +1 -0
  12. package/build/import/type/error/index.mjs +1 -0
  13. package/build/import/type/extends/extends-check.d.mts +2 -1
  14. package/build/import/type/extends/extends-check.mjs +2 -1
  15. package/build/import/type/guard/type.d.mts +2 -1
  16. package/build/import/type/guard/type.mjs +2 -1
  17. package/build/import/type/index.d.mts +1 -0
  18. package/build/import/type/index.mjs +1 -0
  19. package/build/import/type/indexed/index.d.mts +1 -0
  20. package/build/import/type/indexed/index.mjs +1 -0
  21. package/build/import/type/indexed/indexed-from-mapped-result.d.mts +12 -0
  22. package/build/import/type/indexed/indexed-from-mapped-result.mjs +18 -0
  23. package/build/import/type/indexed/indexed.d.mts +4 -1
  24. package/build/import/type/indexed/indexed.mjs +6 -5
  25. package/build/import/type/record/record.d.mts +1 -1
  26. package/build/import/type/template-literal/finite.d.mts +2 -1
  27. package/build/import/type/template-literal/finite.mjs +2 -1
  28. package/build/import/type/template-literal/generate.d.mts +2 -1
  29. package/build/import/type/template-literal/generate.mjs +2 -1
  30. package/build/import/type/template-literal/parse.d.mts +2 -1
  31. package/build/import/type/template-literal/parse.mjs +2 -1
  32. package/build/import/type/template-literal/pattern.d.mts +2 -1
  33. package/build/import/type/template-literal/pattern.mjs +2 -1
  34. package/build/import/type/type/json.d.mts +3 -1
  35. package/build/import/value/cast/cast.d.mts +5 -4
  36. package/build/import/value/cast/cast.mjs +5 -4
  37. package/build/import/value/check/check.d.mts +2 -1
  38. package/build/import/value/check/check.mjs +2 -1
  39. package/build/import/value/convert/convert.d.mts +2 -1
  40. package/build/import/value/convert/convert.mjs +2 -1
  41. package/build/import/value/create/create.d.mts +7 -6
  42. package/build/import/value/create/create.mjs +7 -6
  43. package/build/import/value/delta/delta.d.mts +3 -2
  44. package/build/import/value/delta/delta.mjs +3 -2
  45. package/build/import/value/deref/deref.d.mts +2 -1
  46. package/build/import/value/deref/deref.mjs +2 -1
  47. package/build/import/value/hash/hash.d.mts +2 -1
  48. package/build/import/value/hash/hash.mjs +2 -1
  49. package/build/import/value/mutate/mutate.d.mts +3 -2
  50. package/build/import/value/mutate/mutate.mjs +3 -2
  51. package/build/import/value/pointer/pointer.d.mts +3 -2
  52. package/build/import/value/pointer/pointer.mjs +3 -2
  53. package/build/import/value/transform/decode.d.mts +3 -2
  54. package/build/import/value/transform/decode.mjs +3 -2
  55. package/build/import/value/transform/encode.d.mts +3 -2
  56. package/build/import/value/transform/encode.mjs +3 -2
  57. package/build/require/compiler/compiler.d.ts +3 -2
  58. package/build/require/compiler/compiler.js +61 -60
  59. package/build/require/errors/errors.d.ts +2 -1
  60. package/build/require/errors/errors.js +34 -33
  61. package/build/require/index.d.ts +2 -1
  62. package/build/require/index.js +155 -152
  63. package/build/require/system/system.d.ts +3 -2
  64. package/build/require/system/system.js +3 -2
  65. package/build/require/type/error/error.d.ts +4 -0
  66. package/build/require/type/error/error.js +11 -0
  67. package/build/require/type/error/index.d.ts +1 -0
  68. package/build/require/type/error/index.js +18 -0
  69. package/build/require/type/extends/extends-check.d.ts +2 -1
  70. package/build/require/type/extends/extends-check.js +172 -171
  71. package/build/require/type/guard/type.d.ts +2 -1
  72. package/build/require/type/guard/type.js +2 -1
  73. package/build/require/type/index.d.ts +1 -0
  74. package/build/require/type/index.js +1 -0
  75. package/build/require/type/indexed/index.d.ts +1 -0
  76. package/build/require/type/indexed/index.js +1 -0
  77. package/build/require/type/indexed/indexed-from-mapped-result.d.ts +12 -0
  78. package/build/require/type/indexed/indexed-from-mapped-result.js +23 -0
  79. package/build/require/type/indexed/indexed.d.ts +4 -1
  80. package/build/require/type/indexed/indexed.js +5 -4
  81. package/build/require/type/record/record.d.ts +1 -1
  82. package/build/require/type/template-literal/finite.d.ts +2 -1
  83. package/build/require/type/template-literal/finite.js +2 -1
  84. package/build/require/type/template-literal/generate.d.ts +2 -1
  85. package/build/require/type/template-literal/generate.js +2 -1
  86. package/build/require/type/template-literal/parse.d.ts +2 -1
  87. package/build/require/type/template-literal/parse.js +3 -2
  88. package/build/require/type/template-literal/pattern.d.ts +2 -1
  89. package/build/require/type/template-literal/pattern.js +2 -1
  90. package/build/require/type/type/json.d.ts +3 -1
  91. package/build/require/value/cast/cast.d.ts +5 -4
  92. package/build/require/value/cast/cast.js +36 -35
  93. package/build/require/value/check/check.d.ts +2 -1
  94. package/build/require/value/check/check.js +24 -23
  95. package/build/require/value/convert/convert.d.ts +2 -1
  96. package/build/require/value/convert/convert.js +32 -31
  97. package/build/require/value/create/create.d.ts +7 -6
  98. package/build/require/value/create/create.js +7 -6
  99. package/build/require/value/delta/delta.d.ts +3 -2
  100. package/build/require/value/delta/delta.js +20 -19
  101. package/build/require/value/deref/deref.d.ts +2 -1
  102. package/build/require/value/deref/deref.js +2 -1
  103. package/build/require/value/hash/hash.d.ts +2 -1
  104. package/build/require/value/hash/hash.js +2 -1
  105. package/build/require/value/mutate/mutate.d.ts +3 -2
  106. package/build/require/value/mutate/mutate.js +3 -2
  107. package/build/require/value/pointer/pointer.d.ts +3 -2
  108. package/build/require/value/pointer/pointer.js +3 -2
  109. package/build/require/value/transform/decode.d.ts +3 -2
  110. package/build/require/value/transform/decode.js +19 -18
  111. package/build/require/value/transform/encode.d.ts +3 -2
  112. package/build/require/value/transform/encode.js +20 -19
  113. package/package.json +1 -1
  114. package/readme.md +117 -137
@@ -1,4 +1,5 @@
1
1
  import { Kind, Hint, TransformKind } from '../symbols/index';
2
+ import { TypeBoxError } from '../error/index';
2
3
  import { TransformOptions } from '../transform/index';
3
4
  import { TTemplateLiteral, TTemplateLiteralKind } from '../template-literal/index';
4
5
  import { TArray } from '../array/index';
@@ -35,7 +36,7 @@ import type { TUnsafe } from '../unsafe/index';
35
36
  import type { TVoid } from '../void/index';
36
37
  import type { TDate } from '../date/index';
37
38
  import type { TThis } from '../recursive/index';
38
- export declare class TypeGuardUnknownTypeError extends Error {
39
+ export declare class TypeGuardUnknownTypeError extends TypeBoxError {
39
40
  }
40
41
  /** Returns true if this value has a Readonly symbol */
41
42
  export declare function IsReadonly<T extends TSchema>(value: T): value is TReadonly<T>;
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.IsSchema = exports.IsKind = exports.IsVoid = exports.IsUnsafe = exports.IsUnknown = exports.IsUint8Array = exports.IsUnion = exports.IsUnionLiteral = exports.IsUndefined = exports.IsTuple = exports.IsTransform = exports.IsThis = exports.IsTemplateLiteral = exports.IsSymbol = exports.IsString = exports.IsRef = exports.IsRecursive = exports.IsRecord = exports.IsPromise = exports.IsObject = exports.IsNumber = exports.IsNull = exports.IsNot = exports.IsNever = exports.IsMappedResult = exports.IsMappedKey = exports.IsLiteralValue = exports.IsLiteral = exports.IsLiteralBoolean = exports.IsLiteralNumber = exports.IsLiteralString = exports.IsKindOf = exports.IsIterator = exports.IsIntersect = exports.IsProperties = exports.IsInteger = exports.IsFunction = exports.IsDate = exports.IsConstructor = exports.IsBoolean = exports.IsBigInt = exports.IsAsyncIterator = exports.IsArray = exports.IsAny = exports.IsOptional = exports.IsReadonly = exports.TypeGuardUnknownTypeError = void 0;
5
5
  const ValueGuard = require("./value");
6
6
  const index_1 = require("../symbols/index");
7
- class TypeGuardUnknownTypeError extends Error {
7
+ const index_2 = require("../error/index");
8
+ class TypeGuardUnknownTypeError extends index_2.TypeBoxError {
8
9
  }
9
10
  exports.TypeGuardUnknownTypeError = TypeGuardUnknownTypeError;
10
11
  const KnownTypes = [
@@ -13,6 +13,7 @@ export * from './date/index';
13
13
  export * from './deref/index';
14
14
  export * from './discard/index';
15
15
  export * from './enum/index';
16
+ export * from './error/index';
16
17
  export * from './exclude/index';
17
18
  export * from './extends/index';
18
19
  export * from './extract/index';
@@ -30,6 +30,7 @@ __exportStar(require("./date/index"), exports);
30
30
  __exportStar(require("./deref/index"), exports);
31
31
  __exportStar(require("./discard/index"), exports);
32
32
  __exportStar(require("./enum/index"), exports);
33
+ __exportStar(require("./error/index"), exports);
33
34
  __exportStar(require("./exclude/index"), exports);
34
35
  __exportStar(require("./extends/index"), exports);
35
36
  __exportStar(require("./extract/index"), exports);
@@ -1,3 +1,4 @@
1
1
  export * from './indexed-from-mapped-key';
2
+ export * from './indexed-from-mapped-result';
2
3
  export * from './indexed-property-keys';
3
4
  export * from './indexed';
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./indexed-from-mapped-key"), exports);
19
+ __exportStar(require("./indexed-from-mapped-result"), exports);
19
20
  __exportStar(require("./indexed-property-keys"), exports);
20
21
  __exportStar(require("./indexed"), exports);
@@ -0,0 +1,12 @@
1
+ import type { TSchema, SchemaOptions } from '../schema/index';
2
+ import type { TProperties } from '../object/index';
3
+ import { type TMappedResult } from '../mapped/index';
4
+ import { type TIndex } from './index';
5
+ import { TIndexPropertyKeys } from './indexed-property-keys';
6
+ type TFromProperties<T extends TSchema, P extends TProperties> = ({
7
+ [K2 in keyof P]: TIndex<T, TIndexPropertyKeys<P[K2]>>;
8
+ });
9
+ type TFromMappedResult<T extends TSchema, K extends TMappedResult> = (TFromProperties<T, K['properties']>);
10
+ export type TIndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>> = (TMappedResult<P>);
11
+ export declare function IndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>>(T: T, R: R, options: SchemaOptions): TMappedResult<P>;
12
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.IndexFromMappedResult = void 0;
5
+ const index_1 = require("../mapped/index");
6
+ const index_2 = require("./index");
7
+ const indexed_property_keys_1 = require("./indexed-property-keys");
8
+ // prettier-ignore
9
+ function FromProperties(T, P, options) {
10
+ return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
11
+ return { ...Acc, [K2]: (0, index_2.Index)(T, (0, indexed_property_keys_1.IndexPropertyKeys)(P[K2]), options) };
12
+ }, {});
13
+ }
14
+ // prettier-ignore
15
+ function FromMappedResult(T, R, options) {
16
+ return FromProperties(T, R.properties, options);
17
+ }
18
+ // prettier-ignore
19
+ function IndexFromMappedResult(T, R, options) {
20
+ const P = FromMappedResult(T, R, options);
21
+ return (0, index_1.MappedResult)(P);
22
+ }
23
+ exports.IndexFromMappedResult = IndexFromMappedResult;
@@ -4,7 +4,7 @@ import { type Assert } from '../helpers/index';
4
4
  import { type TNever } from '../never/index';
5
5
  import { type TRecursive } from '../recursive/index';
6
6
  import { type TIntersect } from '../intersect/index';
7
- import { type TMappedKey } from '../mapped/index';
7
+ import { TMappedResult, type TMappedKey } from '../mapped/index';
8
8
  import { type TUnion } from '../union/index';
9
9
  import { type TTuple } from '../tuple/index';
10
10
  import { type TArray } from '../array/index';
@@ -12,6 +12,7 @@ import { type TIntersectEvaluated } from '../intersect/index';
12
12
  import { type TUnionEvaluated } from '../union/index';
13
13
  import { type TIndexPropertyKeys } from './indexed-property-keys';
14
14
  import { type TIndexFromMappedKey } from './indexed-from-mapped-key';
15
+ import { type TIndexFromMappedResult } from './indexed-from-mapped-result';
15
16
  type TFromRest<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Acc, Assert<TFromKey<L, K>, TSchema>]> : Acc);
16
17
  type TFromIntersectRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? TFromIntersectRest<R, [...Acc]> : TFromIntersectRest<R, [...Acc, L]> : Acc);
17
18
  type TFromIntersect<T extends TSchema[], K extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<T, K>>>);
@@ -27,6 +28,8 @@ type FromSchema<T extends TSchema, K extends PropertyKey[]> = (TUnionEvaluated<T
27
28
  declare function FromSchema<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): FromSchema<T, K>;
28
29
  export type TIndex<T extends TSchema, K extends PropertyKey[]> = (FromSchema<T, K>);
29
30
  /** `[Json]` Returns an Indexed property type for the given keys */
31
+ export declare function Index<T extends TSchema, K extends TMappedResult>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedResult<T, K>;
32
+ /** `[Json]` Returns an Indexed property type for the given keys */
30
33
  export declare function Index<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedKey<T, K>;
31
34
  /** `[Json]` Returns an Indexed property type for the given keys */
32
35
  export declare function Index<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TIndex<T, I>;
@@ -8,10 +8,10 @@ const index_3 = require("../union/index");
8
8
  const type_1 = require("../clone/type");
9
9
  const indexed_property_keys_1 = require("./indexed-property-keys");
10
10
  const indexed_from_mapped_key_1 = require("./indexed-from-mapped-key");
11
+ const indexed_from_mapped_result_1 = require("./indexed-from-mapped-result");
11
12
  // ------------------------------------------------------------------
12
13
  // TypeGuard
13
14
  // ------------------------------------------------------------------
14
- // prettier-ignore
15
15
  const type_2 = require("../guard/type");
16
16
  // prettier-ignore
17
17
  function FromRest(T, K, Acc = []) {
@@ -87,8 +87,9 @@ function FromSchema(T, K) {
87
87
  /** `[Json]` Returns an Indexed property type for the given keys */
88
88
  function Index(T, K, options = {}) {
89
89
  // prettier-ignore
90
- return ((0, type_2.IsMappedKey)(K) ? (0, type_1.CloneType)((0, indexed_from_mapped_key_1.IndexFromMappedKey)(T, K, options)) :
91
- (0, type_2.IsSchema)(K) ? (0, type_1.CloneType)(FromSchema(T, (0, indexed_property_keys_1.IndexPropertyKeys)(K)), options) :
92
- (0, type_1.CloneType)(FromSchema(T, K), options));
90
+ return ((0, type_2.IsMappedResult)(K) ? (0, type_1.CloneType)((0, indexed_from_mapped_result_1.IndexFromMappedResult)(T, K, options)) :
91
+ (0, type_2.IsMappedKey)(K) ? (0, type_1.CloneType)((0, indexed_from_mapped_key_1.IndexFromMappedKey)(T, K, options)) :
92
+ (0, type_2.IsSchema)(K) ? (0, type_1.CloneType)(FromSchema(T, (0, indexed_property_keys_1.IndexPropertyKeys)(K)), options) :
93
+ (0, type_1.CloneType)(FromSchema(T, K), options));
93
94
  }
94
95
  exports.Index = Index;
@@ -26,7 +26,7 @@ type TFromUnionKeyLiteralNumber<K extends TLiteral<number>, T extends TSchema> =
26
26
  [_ in K['const']]: T;
27
27
  };
28
28
  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> : {}) : {};
29
- type TFromUnionKey<K extends TSchema[], T extends TSchema, P extends TProperties = TFromUnionKeyRest<K, T>> = (Ensure<TObject<P>>);
29
+ type TFromUnionKey<K extends TSchema[], T extends TSchema, P extends TProperties = TFromUnionKeyRest<K, T>> = (Ensure<TObject<Evaluate<P>>>);
30
30
  type TFromLiteralKey<K extends TLiteralValue, T extends TSchema> = (Ensure<TObject<{
31
31
  [_ in Assert<K, PropertyKey>]: T;
32
32
  }>>);
@@ -1,3 +1,4 @@
1
+ import { TypeBoxError } from '../error/index';
1
2
  import type { TTemplateLiteral, TTemplateLiteralKind } from './index';
2
3
  import type { TUnion } from '../union/index';
3
4
  import type { TString } from '../string/index';
@@ -7,7 +8,7 @@ import type { TInteger } from '../integer/index';
7
8
  import type { TBigInt } from '../bigint/index';
8
9
  import type { TLiteral } from '../literal/index';
9
10
  import type { Expression } from './parse';
10
- export declare class TemplateLiteralFiniteError extends Error {
11
+ export declare class TemplateLiteralFiniteError extends TypeBoxError {
11
12
  }
12
13
  type TFromTemplateLiteralKind<T> = T extends TTemplateLiteral<infer U extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<U> : T extends TUnion<infer U extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<U> : T extends TString ? false : T extends TNumber ? false : T extends TInteger ? false : T extends TBigInt ? false : T extends TBoolean ? true : T extends TLiteral ? true : false;
13
14
  type TFromTemplateLiteralKinds<T extends TTemplateLiteralKind[]> = T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]] ? TFromTemplateLiteralKind<L> extends false ? false : TFromTemplateLiteralKinds<R> : true;
@@ -3,10 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.IsTemplateLiteralFinite = exports.IsTemplateLiteralExpressionFinite = exports.TemplateLiteralFiniteError = void 0;
5
5
  const parse_1 = require("./parse");
6
+ const index_1 = require("../error/index");
6
7
  // ------------------------------------------------------------------
7
8
  // TemplateLiteralFiniteError
8
9
  // ------------------------------------------------------------------
9
- class TemplateLiteralFiniteError extends Error {
10
+ class TemplateLiteralFiniteError extends index_1.TypeBoxError {
10
11
  }
11
12
  exports.TemplateLiteralFiniteError = TemplateLiteralFiniteError;
12
13
  // ------------------------------------------------------------------
@@ -1,11 +1,12 @@
1
1
  import { TIsTemplateLiteralFinite } from './finite';
2
+ import { TypeBoxError } from '../error/index';
2
3
  import type { Assert } from '../helpers/index';
3
4
  import type { TBoolean } from '../boolean/index';
4
5
  import type { TTemplateLiteral, TTemplateLiteralKind } from './index';
5
6
  import type { TLiteral, TLiteralValue } from '../literal/index';
6
7
  import type { Expression } from './parse';
7
8
  import type { TUnion } from '../union/index';
8
- export declare class TemplateLiteralGenerateError extends Error {
9
+ export declare class TemplateLiteralGenerateError extends TypeBoxError {
9
10
  }
10
11
  type TStringReduceUnary<L extends string, R extends string[], Acc extends string[] = []> = R extends [infer A extends string, ...infer B extends string[]] ? TStringReduceUnary<L, B, [...Acc, `${L}${A}`]> : Acc;
11
12
  type TStringReduceBinary<L extends string[], R extends string[], Acc extends string[] = []> = L extends [infer A extends string, ...infer B extends string[]] ? TStringReduceBinary<B, R, [...Acc, ...TStringReduceUnary<A, R>]> : Acc;
@@ -4,10 +4,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.TemplateLiteralGenerate = exports.TemplateLiteralExpressionGenerate = exports.TemplateLiteralGenerateError = void 0;
5
5
  const finite_1 = require("./finite");
6
6
  const parse_1 = require("./parse");
7
+ const index_1 = require("../error/index");
7
8
  // ------------------------------------------------------------------
8
9
  // TemplateLiteralGenerateError
9
10
  // ------------------------------------------------------------------
10
- class TemplateLiteralGenerateError extends Error {
11
+ class TemplateLiteralGenerateError extends index_1.TypeBoxError {
11
12
  }
12
13
  exports.TemplateLiteralGenerateError = TemplateLiteralGenerateError;
13
14
  // ------------------------------------------------------------------
@@ -1,4 +1,5 @@
1
- export declare class TemplateLiteralParserError extends Error {
1
+ import { TypeBoxError } from '../error/index';
2
+ export declare class TemplateLiteralParserError extends TypeBoxError {
2
3
  }
3
4
  export type Expression = ExpressionAnd | ExpressionOr | ExpressionConst;
4
5
  export type ExpressionConst = {
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.TemplateLiteralParseExact = exports.TemplateLiteralParse = exports.TemplateLiteralParserError = void 0;
4
+
5
+ const index_1 = require("../error/index");
5
6
  // ------------------------------------------------------------------
6
7
  // TemplateLiteralParserError
7
8
  // ------------------------------------------------------------------
8
- class TemplateLiteralParserError extends Error {
9
+ class TemplateLiteralParserError extends index_1.TypeBoxError {
9
10
  }
10
11
  exports.TemplateLiteralParserError = TemplateLiteralParserError;
11
12
  // prettier-ignore
@@ -1,4 +1,5 @@
1
1
  import type { TTemplateLiteralKind } from './index';
2
- export declare class TemplateLiteralPatternError extends Error {
2
+ import { TypeBoxError } from '../error/index';
3
+ export declare class TemplateLiteralPatternError extends TypeBoxError {
3
4
  }
4
5
  export declare function TemplateLiteralPattern(kinds: TTemplateLiteralKind[]): string;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.TemplateLiteralPattern = exports.TemplateLiteralPatternError = void 0;
5
5
  const index_1 = require("../patterns/index");
6
6
  const index_2 = require("../symbols/index");
7
+ const index_3 = require("../error/index");
7
8
  // ------------------------------------------------------------------
8
9
  // TypeGuard
9
10
  // ------------------------------------------------------------------
@@ -12,7 +13,7 @@ const type_1 = require("../guard/type");
12
13
  // ------------------------------------------------------------------
13
14
  // TemplateLiteralPatternError
14
15
  // ------------------------------------------------------------------
15
- class TemplateLiteralPatternError extends Error {
16
+ class TemplateLiteralPatternError extends index_3.TypeBoxError {
16
17
  }
17
18
  exports.TemplateLiteralPatternError = TemplateLiteralPatternError;
18
19
  // ------------------------------------------------------------------
@@ -8,7 +8,7 @@ import { type TEnum, type TEnumKey, type TEnumValue } from '../enum/index';
8
8
  import { type TExclude, type TExcludeFromMappedResult } from '../exclude/index';
9
9
  import { type TExtends, type TExtendsFromMappedKey, type TExtendsFromMappedResult } from '../extends/index';
10
10
  import { type TExtract, type TExtractFromMappedResult } from '../extract/index';
11
- import { TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey } from '../indexed/index';
11
+ import { TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey, type TIndexFromMappedResult } from '../indexed/index';
12
12
  import { type IntegerOptions, type TInteger } from '../integer/index';
13
13
  import { Intersect, type IntersectOptions } from '../intersect/index';
14
14
  import { type TCapitalize, type TUncapitalize, type TLowercase, type TUppercase } from '../intrinsic/index';
@@ -93,6 +93,8 @@ export declare class JsonTypeBuilder {
93
93
  /** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
94
94
  Extract<L extends TSchema, R extends TSchema>(type: L, union: R, options?: SchemaOptions): TExtract<L, R>;
95
95
  /** `[Json]` Returns an Indexed property type for the given keys */
96
+ Index<T extends TSchema, K extends TMappedResult>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedResult<T, K>;
97
+ /** `[Json]` Returns an Indexed property type for the given keys */
96
98
  Index<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedKey<T, K>;
97
99
  /** `[Json]` Returns an Indexed property type for the given keys */
98
100
  Index<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TIndex<T, I>;
@@ -1,19 +1,20 @@
1
+ import { TypeBoxError } from '../../type/error/index';
1
2
  import type { TSchema } from '../../type/schema/index';
2
3
  import type { Static } from '../../type/static/index';
3
- export declare class ValueCastArrayUniqueItemsTypeError extends Error {
4
+ export declare class ValueCastArrayUniqueItemsTypeError extends TypeBoxError {
4
5
  readonly schema: TSchema;
5
6
  readonly value: unknown;
6
7
  constructor(schema: TSchema, value: unknown);
7
8
  }
8
- export declare class ValueCastNeverTypeError extends Error {
9
+ export declare class ValueCastNeverTypeError extends TypeBoxError {
9
10
  readonly schema: TSchema;
10
11
  constructor(schema: TSchema);
11
12
  }
12
- export declare class ValueCastRecursiveTypeError extends Error {
13
+ export declare class ValueCastRecursiveTypeError extends TypeBoxError {
13
14
  readonly schema: TSchema;
14
15
  constructor(schema: TSchema);
15
16
  }
16
- export declare class ValueCastUnknownTypeError extends Error {
17
+ export declare class ValueCastUnknownTypeError extends TypeBoxError {
17
18
  readonly schema: TSchema;
18
19
  constructor(schema: TSchema);
19
20
  }
@@ -3,15 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Cast = exports.ValueCastUnknownTypeError = exports.ValueCastRecursiveTypeError = exports.ValueCastNeverTypeError = exports.ValueCastArrayUniqueItemsTypeError = void 0;
5
5
  const index_1 = require("../guard/index");
6
- const index_2 = require("../../type/symbols/index");
7
- const index_3 = require("../create/index");
8
- const index_4 = require("../check/index");
9
- const index_5 = require("../clone/index");
10
- const index_6 = require("../deref/index");
6
+ const index_2 = require("../../type/error/index");
7
+ const index_3 = require("../../type/symbols/index");
8
+ const index_4 = require("../create/index");
9
+ const index_5 = require("../check/index");
10
+ const index_6 = require("../clone/index");
11
+ const index_7 = require("../deref/index");
11
12
  // ------------------------------------------------------------------
12
13
  // Errors
13
14
  // ------------------------------------------------------------------
14
- class ValueCastArrayUniqueItemsTypeError extends Error {
15
+ class ValueCastArrayUniqueItemsTypeError extends index_2.TypeBoxError {
15
16
  constructor(schema, value) {
16
17
  super('Array cast produced invalid data due to uniqueItems constraint');
17
18
  this.schema = schema;
@@ -19,21 +20,21 @@ class ValueCastArrayUniqueItemsTypeError extends Error {
19
20
  }
20
21
  }
21
22
  exports.ValueCastArrayUniqueItemsTypeError = ValueCastArrayUniqueItemsTypeError;
22
- class ValueCastNeverTypeError extends Error {
23
+ class ValueCastNeverTypeError extends index_2.TypeBoxError {
23
24
  constructor(schema) {
24
25
  super('Never types cannot be cast');
25
26
  this.schema = schema;
26
27
  }
27
28
  }
28
29
  exports.ValueCastNeverTypeError = ValueCastNeverTypeError;
29
- class ValueCastRecursiveTypeError extends Error {
30
+ class ValueCastRecursiveTypeError extends index_2.TypeBoxError {
30
31
  constructor(schema) {
31
32
  super('Cannot cast recursive schemas');
32
33
  this.schema = schema;
33
34
  }
34
35
  }
35
36
  exports.ValueCastRecursiveTypeError = ValueCastRecursiveTypeError;
36
- class ValueCastUnknownTypeError extends Error {
37
+ class ValueCastUnknownTypeError extends index_2.TypeBoxError {
37
38
  constructor(schema) {
38
39
  super('Unknown type');
39
40
  this.schema = schema;
@@ -49,20 +50,20 @@ exports.ValueCastUnknownTypeError = ValueCastUnknownTypeError;
49
50
  // used as union discriminator fields.
50
51
  // ------------------------------------------------------------------
51
52
  function ScoreUnion(schema, references, value) {
52
- if (schema[index_2.Kind] === 'Object' && typeof value === 'object' && !(0, index_1.IsNull)(value)) {
53
+ if (schema[index_3.Kind] === 'Object' && typeof value === 'object' && !(0, index_1.IsNull)(value)) {
53
54
  const object = schema;
54
55
  const keys = Object.getOwnPropertyNames(value);
55
56
  const entries = Object.entries(object.properties);
56
57
  const [point, max] = [1 / entries.length, entries.length];
57
58
  return entries.reduce((acc, [key, schema]) => {
58
- const literal = schema[index_2.Kind] === 'Literal' && schema.const === value[key] ? max : 0;
59
- const checks = (0, index_4.Check)(schema, references, value[key]) ? point : 0;
59
+ const literal = schema[index_3.Kind] === 'Literal' && schema.const === value[key] ? max : 0;
60
+ const checks = (0, index_5.Check)(schema, references, value[key]) ? point : 0;
60
61
  const exists = keys.includes(key) ? point : 0;
61
62
  return acc + (literal + checks + exists);
62
63
  }, 0);
63
64
  }
64
65
  else {
65
- return (0, index_4.Check)(schema, references, value) ? 1 : 0;
66
+ return (0, index_5.Check)(schema, references, value) ? 1 : 0;
66
67
  }
67
68
  }
68
69
  function SelectUnion(union, references, value) {
@@ -89,31 +90,31 @@ function CastUnion(union, references, value) {
89
90
  // Default
90
91
  // ------------------------------------------------------------------
91
92
  function DefaultClone(schema, references, value) {
92
- return (0, index_4.Check)(schema, references, value) ? (0, index_5.Clone)(value) : (0, index_3.Create)(schema, references);
93
+ return (0, index_5.Check)(schema, references, value) ? (0, index_6.Clone)(value) : (0, index_4.Create)(schema, references);
93
94
  }
94
95
  function Default(schema, references, value) {
95
- return (0, index_4.Check)(schema, references, value) ? value : (0, index_3.Create)(schema, references);
96
+ return (0, index_5.Check)(schema, references, value) ? value : (0, index_4.Create)(schema, references);
96
97
  }
97
98
  // ------------------------------------------------------------------
98
99
  // Cast
99
100
  // ------------------------------------------------------------------
100
101
  function FromArray(schema, references, value) {
101
- if ((0, index_4.Check)(schema, references, value))
102
- return (0, index_5.Clone)(value);
103
- const created = (0, index_1.IsArray)(value) ? (0, index_5.Clone)(value) : (0, index_3.Create)(schema, references);
102
+ if ((0, index_5.Check)(schema, references, value))
103
+ return (0, index_6.Clone)(value);
104
+ const created = (0, index_1.IsArray)(value) ? (0, index_6.Clone)(value) : (0, index_4.Create)(schema, references);
104
105
  const minimum = (0, index_1.IsNumber)(schema.minItems) && created.length < schema.minItems ? [...created, ...Array.from({ length: schema.minItems - created.length }, () => null)] : created;
105
106
  const maximum = (0, index_1.IsNumber)(schema.maxItems) && minimum.length > schema.maxItems ? minimum.slice(0, schema.maxItems) : minimum;
106
107
  const casted = maximum.map((value) => Visit(schema.items, references, value));
107
108
  if (schema.uniqueItems !== true)
108
109
  return casted;
109
110
  const unique = [...new Set(casted)];
110
- if (!(0, index_4.Check)(schema, references, unique))
111
+ if (!(0, index_5.Check)(schema, references, unique))
111
112
  throw new ValueCastArrayUniqueItemsTypeError(schema, unique);
112
113
  return unique;
113
114
  }
114
115
  function FromConstructor(schema, references, value) {
115
- if ((0, index_4.Check)(schema, references, value))
116
- return (0, index_3.Create)(schema, references);
116
+ if ((0, index_5.Check)(schema, references, value))
117
+ return (0, index_4.Create)(schema, references);
117
118
  const required = new Set(schema.returns.required || []);
118
119
  const result = function () { };
119
120
  for (const [key, property] of Object.entries(schema.returns.properties)) {
@@ -124,18 +125,18 @@ function FromConstructor(schema, references, value) {
124
125
  return result;
125
126
  }
126
127
  function FromIntersect(schema, references, value) {
127
- const created = (0, index_3.Create)(schema, references);
128
+ const created = (0, index_4.Create)(schema, references);
128
129
  const mapped = (0, index_1.IsPlainObject)(created) && (0, index_1.IsPlainObject)(value) ? { ...created, ...value } : value;
129
- return (0, index_4.Check)(schema, references, mapped) ? mapped : (0, index_3.Create)(schema, references);
130
+ return (0, index_5.Check)(schema, references, mapped) ? mapped : (0, index_4.Create)(schema, references);
130
131
  }
131
132
  function FromNever(schema, references, value) {
132
133
  throw new ValueCastNeverTypeError(schema);
133
134
  }
134
135
  function FromObject(schema, references, value) {
135
- if ((0, index_4.Check)(schema, references, value))
136
+ if ((0, index_5.Check)(schema, references, value))
136
137
  return value;
137
138
  if (value === null || typeof value !== 'object')
138
- return (0, index_3.Create)(schema, references);
139
+ return (0, index_4.Create)(schema, references);
139
140
  const required = new Set(schema.required || []);
140
141
  const result = {};
141
142
  for (const [key, property] of Object.entries(schema.properties)) {
@@ -155,10 +156,10 @@ function FromObject(schema, references, value) {
155
156
  return result;
156
157
  }
157
158
  function FromRecord(schema, references, value) {
158
- if ((0, index_4.Check)(schema, references, value))
159
- return (0, index_5.Clone)(value);
159
+ if ((0, index_5.Check)(schema, references, value))
160
+ return (0, index_6.Clone)(value);
160
161
  if (value === null || typeof value !== 'object' || Array.isArray(value) || value instanceof Date)
161
- return (0, index_3.Create)(schema, references);
162
+ return (0, index_4.Create)(schema, references);
162
163
  const subschemaPropertyName = Object.getOwnPropertyNames(schema.patternProperties)[0];
163
164
  const subschema = schema.patternProperties[subschemaPropertyName];
164
165
  const result = {};
@@ -168,27 +169,27 @@ function FromRecord(schema, references, value) {
168
169
  return result;
169
170
  }
170
171
  function FromRef(schema, references, value) {
171
- return Visit((0, index_6.Deref)(schema, references), references, value);
172
+ return Visit((0, index_7.Deref)(schema, references), references, value);
172
173
  }
173
174
  function FromThis(schema, references, value) {
174
- return Visit((0, index_6.Deref)(schema, references), references, value);
175
+ return Visit((0, index_7.Deref)(schema, references), references, value);
175
176
  }
176
177
  function FromTuple(schema, references, value) {
177
- if ((0, index_4.Check)(schema, references, value))
178
- return (0, index_5.Clone)(value);
178
+ if ((0, index_5.Check)(schema, references, value))
179
+ return (0, index_6.Clone)(value);
179
180
  if (!(0, index_1.IsArray)(value))
180
- return (0, index_3.Create)(schema, references);
181
+ return (0, index_4.Create)(schema, references);
181
182
  if (schema.items === undefined)
182
183
  return [];
183
184
  return schema.items.map((schema, index) => Visit(schema, references, value[index]));
184
185
  }
185
186
  function FromUnion(schema, references, value) {
186
- return (0, index_4.Check)(schema, references, value) ? (0, index_5.Clone)(value) : CastUnion(schema, references, value);
187
+ return (0, index_5.Check)(schema, references, value) ? (0, index_6.Clone)(value) : CastUnion(schema, references, value);
187
188
  }
188
189
  function Visit(schema, references, value) {
189
190
  const references_ = (0, index_1.IsString)(schema.$id) ? [...references, schema] : references;
190
191
  const schema_ = schema;
191
- switch (schema[index_2.Kind]) {
192
+ switch (schema[index_3.Kind]) {
192
193
  // --------------------------------------------------------------
193
194
  // Structural
194
195
  // --------------------------------------------------------------
@@ -1,6 +1,7 @@
1
+ import { TypeBoxError } from '../../type/error/index';
1
2
  import type { TSchema } from '../../type/schema/index';
2
3
  import type { Static } from '../../type/static/index';
3
- export declare class ValueCheckUnknownTypeError extends Error {
4
+ export declare class ValueCheckUnknownTypeError extends TypeBoxError {
4
5
  readonly schema: TSchema;
5
6
  constructor(schema: TSchema);
6
7
  }