@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 { ValueErrorIterator } from '../errors/index.mjs';
2
+ import { TypeBoxError } from '../type/error/index.mjs';
2
3
  import type { TSchema } from '../type/schema/index.mjs';
3
4
  import type { Static, StaticDecode, StaticEncode } from '../type/static/index.mjs';
4
5
  export type CheckFunction = (value: unknown) => boolean;
@@ -20,11 +21,11 @@ export declare class TypeCheck<T extends TSchema> {
20
21
  /** Encodes a value or throws if error */
21
22
  Encode(value: unknown): StaticEncode<T>;
22
23
  }
23
- export declare class TypeCompilerUnknownTypeError extends Error {
24
+ export declare class TypeCompilerUnknownTypeError extends TypeBoxError {
24
25
  readonly schema: TSchema;
25
26
  constructor(schema: TSchema);
26
27
  }
27
- export declare class TypeCompilerTypeGuardError extends Error {
28
+ export declare class TypeCompilerTypeGuardError extends TypeBoxError {
28
29
  readonly schema: TSchema;
29
30
  constructor(schema: TSchema);
30
31
  }
@@ -1,6 +1,7 @@
1
1
  import { TransformEncode, TransformDecode, HasTransform, TransformDecodeCheckError, TransformEncodeCheckError } from '../value/transform/index.mjs';
2
2
  import { Errors } from '../errors/index.mjs';
3
3
  import { TypeSystemPolicy } from '../system/index.mjs';
4
+ import { TypeBoxError } from '../type/error/index.mjs';
4
5
  import { Deref } from '../value/deref/index.mjs';
5
6
  import { Hash } from '../value/hash/index.mjs';
6
7
  import { Kind } from '../type/symbols/index.mjs';
@@ -142,14 +143,14 @@ var LiteralString;
142
143
  // ------------------------------------------------------------------
143
144
  // Errors
144
145
  // ------------------------------------------------------------------
145
- export class TypeCompilerUnknownTypeError extends Error {
146
+ export class TypeCompilerUnknownTypeError extends TypeBoxError {
146
147
  schema;
147
148
  constructor(schema) {
148
149
  super('Unknown type');
149
150
  this.schema = schema;
150
151
  }
151
152
  }
152
- export class TypeCompilerTypeGuardError extends Error {
153
+ export class TypeCompilerTypeGuardError extends TypeBoxError {
153
154
  schema;
154
155
  constructor(schema) {
155
156
  super('Preflight validation check failed to guard for the given schema');
@@ -1,3 +1,4 @@
1
+ import { TypeBoxError } from '../type/error/index.mjs';
1
2
  import type { TSchema } from '../type/schema/index.mjs';
2
3
  export declare enum ValueErrorType {
3
4
  ArrayContains = 0,
@@ -71,7 +72,7 @@ export interface ValueError {
71
72
  value: unknown;
72
73
  message: string;
73
74
  }
74
- export declare class ValueErrorsUnknownTypeError extends Error {
75
+ export declare class ValueErrorsUnknownTypeError extends TypeBoxError {
75
76
  readonly schema: TSchema;
76
77
  constructor(schema: TSchema);
77
78
  }
@@ -3,6 +3,7 @@ import { KeyOfPattern } from '../type/keyof/index.mjs';
3
3
  import { TypeRegistry, FormatRegistry } from '../type/registry/index.mjs';
4
4
  import { ExtendsUndefinedCheck } from '../type/extends/extends-undefined.mjs';
5
5
  import { GetErrorFunction } from './function.mjs';
6
+ import { TypeBoxError } from '../type/error/index.mjs';
6
7
  import { Deref } from '../value/deref/index.mjs';
7
8
  import { Hash } from '../value/hash/index.mjs';
8
9
  import { Kind } from '../type/symbols/index.mjs';
@@ -84,7 +85,7 @@ export var ValueErrorType;
84
85
  // ------------------------------------------------------------------
85
86
  // ValueErrors
86
87
  // ------------------------------------------------------------------
87
- export class ValueErrorsUnknownTypeError extends Error {
88
+ export class ValueErrorsUnknownTypeError extends TypeBoxError {
88
89
  schema;
89
90
  constructor(schema) {
90
91
  super('Unknown type');
@@ -3,6 +3,7 @@ export { PatternBoolean, PatternBooleanExact, PatternNumber, PatternNumberExact,
3
3
  export { TypeRegistry, FormatRegistry } from './type/registry/index.mjs';
4
4
  export { TypeGuard, ValueGuard } from './type/guard/index.mjs';
5
5
  export { CloneType, CloneRest } from './type/clone/type.mjs';
6
+ export { TypeBoxError } from './type/error/index.mjs';
6
7
  export { Any, type TAny } from './type/any/index.mjs';
7
8
  export { Array, type TArray, type ArrayOptions } from './type/array/index.mjs';
8
9
  export { AsyncIterator, type TAsyncIterator } from './type/async-iterator/index.mjs';
@@ -21,7 +22,7 @@ export { Extends, type TExtends, type ExtendsFromMappedResult, type ExtendsFromM
21
22
  export { Extract, type TExtract, type TExtractFromMappedResult } from './type/extract/index.mjs';
22
23
  export { Function, type TFunction } from './type/function/index.mjs';
23
24
  export { Increment, type Assert, type AssertType, type AssertRest, type AssertProperties, type Ensure, type Evaluate, type TupleToIntersect, type TupleToUnion, type UnionToTuple } from './type/helpers/index.mjs';
24
- export { Index, IndexPropertyKeys, IndexFromMappedKey, type TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey } from './type/indexed/index.mjs';
25
+ export { Index, IndexPropertyKeys, IndexFromMappedKey, IndexFromMappedResult, type TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey, type TIndexFromMappedResult } from './type/indexed/index.mjs';
25
26
  export { InstanceType, type TInstanceType } from './type/instance-type/index.mjs';
26
27
  export { Integer, type TInteger, type IntegerOptions } from './type/integer/index.mjs';
27
28
  export { Intersect, IntersectEvaluated, type TIntersect, type TIntersectEvaluated, type IntersectOptions } from './type/intersect/index.mjs';
@@ -6,6 +6,7 @@ export { PatternBoolean, PatternBooleanExact, PatternNumber, PatternNumberExact,
6
6
  export { TypeRegistry, FormatRegistry } from './type/registry/index.mjs';
7
7
  export { TypeGuard, ValueGuard } from './type/guard/index.mjs';
8
8
  export { CloneType, CloneRest } from './type/clone/type.mjs';
9
+ export { TypeBoxError } from './type/error/index.mjs';
9
10
  // ------------------------------------------------------------------
10
11
  // Type
11
12
  // ------------------------------------------------------------------
@@ -27,7 +28,7 @@ export { Extends, ExtendsCheck, ExtendsResult, ExtendsUndefinedCheck } from './t
27
28
  export { Extract } from './type/extract/index.mjs';
28
29
  export { Function } from './type/function/index.mjs';
29
30
  export { Increment } from './type/helpers/index.mjs';
30
- export { Index, IndexPropertyKeys, IndexFromMappedKey } from './type/indexed/index.mjs';
31
+ export { Index, IndexPropertyKeys, IndexFromMappedKey, IndexFromMappedResult } from './type/indexed/index.mjs';
31
32
  export { InstanceType } from './type/instance-type/index.mjs';
32
33
  export { Integer } from './type/integer/index.mjs';
33
34
  export { Intersect, IntersectEvaluated } from './type/intersect/index.mjs';
@@ -1,7 +1,8 @@
1
- export declare class TypeSystemDuplicateTypeKind extends Error {
1
+ import { TypeBoxError } from '../type/error/index.mjs';
2
+ export declare class TypeSystemDuplicateTypeKind extends TypeBoxError {
2
3
  constructor(kind: string);
3
4
  }
4
- export declare class TypeSystemDuplicateFormat extends Error {
5
+ export declare class TypeSystemDuplicateFormat extends TypeBoxError {
5
6
  constructor(kind: string);
6
7
  }
7
8
  /** Creates user defined types and formats and provides overrides for value checking behaviours */
@@ -1,15 +1,16 @@
1
1
  import { TypeRegistry, FormatRegistry } from '../type/registry/index.mjs';
2
2
  import { Unsafe } from '../type/unsafe/index.mjs';
3
3
  import { Kind } from '../type/symbols/index.mjs';
4
+ import { TypeBoxError } from '../type/error/index.mjs';
4
5
  // ------------------------------------------------------------------
5
6
  // Errors
6
7
  // ------------------------------------------------------------------
7
- export class TypeSystemDuplicateTypeKind extends Error {
8
+ export class TypeSystemDuplicateTypeKind extends TypeBoxError {
8
9
  constructor(kind) {
9
10
  super(`Duplicate type kind '${kind}' detected`);
10
11
  }
11
12
  }
12
- export class TypeSystemDuplicateFormat extends Error {
13
+ export class TypeSystemDuplicateFormat extends TypeBoxError {
13
14
  constructor(kind) {
14
15
  super(`Duplicate string format '${kind}' detected`);
15
16
  }
@@ -0,0 +1,4 @@
1
+ /** The base Error type thrown for all TypeBox exceptions */
2
+ export declare class TypeBoxError extends Error {
3
+ constructor(message: string);
4
+ }
@@ -0,0 +1,6 @@
1
+ /** The base Error type thrown for all TypeBox exceptions */
2
+ export class TypeBoxError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ }
6
+ }
@@ -0,0 +1 @@
1
+ export * from './error.mjs';
@@ -0,0 +1 @@
1
+ export * from './error.mjs';
@@ -1,5 +1,6 @@
1
1
  import { type TSchema } from '../schema/index.mjs';
2
- export declare class ExtendsResolverError extends Error {
2
+ import { TypeBoxError } from '../error/index.mjs';
3
+ export declare class ExtendsResolverError extends TypeBoxError {
3
4
  }
4
5
  export declare enum ExtendsResult {
5
6
  Union = 0,
@@ -6,8 +6,9 @@ import { Unknown } from '../unknown/index.mjs';
6
6
  import { TemplateLiteralToUnion } from '../template-literal/index.mjs';
7
7
  import { PatternNumberExact, PatternStringExact } from '../patterns/index.mjs';
8
8
  import { Kind, Hint } from '../symbols/index.mjs';
9
+ import { TypeBoxError } from '../error/index.mjs';
9
10
  import { TypeGuard, ValueGuard } from '../guard/index.mjs';
10
- export class ExtendsResolverError extends Error {
11
+ export class ExtendsResolverError extends TypeBoxError {
11
12
  }
12
13
  export var ExtendsResult;
13
14
  (function (ExtendsResult) {
@@ -1,4 +1,5 @@
1
1
  import { Kind, Hint, TransformKind } from '../symbols/index.mjs';
2
+ import { TypeBoxError } from '../error/index.mjs';
2
3
  import { TransformOptions } from '../transform/index.mjs';
3
4
  import { TTemplateLiteral, TTemplateLiteralKind } from '../template-literal/index.mjs';
4
5
  import { TArray } from '../array/index.mjs';
@@ -35,7 +36,7 @@ import type { TUnsafe } from '../unsafe/index.mjs';
35
36
  import type { TVoid } from '../void/index.mjs';
36
37
  import type { TDate } from '../date/index.mjs';
37
38
  import type { TThis } from '../recursive/index.mjs';
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>;
@@ -1,6 +1,7 @@
1
1
  import * as ValueGuard from './value.mjs';
2
2
  import { Kind, Hint, TransformKind, ReadonlyKind, OptionalKind } from '../symbols/index.mjs';
3
- export class TypeGuardUnknownTypeError extends Error {
3
+ import { TypeBoxError } from '../error/index.mjs';
4
+ export class TypeGuardUnknownTypeError extends TypeBoxError {
4
5
  }
5
6
  const KnownTypes = [
6
7
  'Any',
@@ -13,6 +13,7 @@ export * from './date/index.mjs';
13
13
  export * from './deref/index.mjs';
14
14
  export * from './discard/index.mjs';
15
15
  export * from './enum/index.mjs';
16
+ export * from './error/index.mjs';
16
17
  export * from './exclude/index.mjs';
17
18
  export * from './extends/index.mjs';
18
19
  export * from './extract/index.mjs';
@@ -13,6 +13,7 @@ export * from './date/index.mjs';
13
13
  export * from './deref/index.mjs';
14
14
  export * from './discard/index.mjs';
15
15
  export * from './enum/index.mjs';
16
+ export * from './error/index.mjs';
16
17
  export * from './exclude/index.mjs';
17
18
  export * from './extends/index.mjs';
18
19
  export * from './extract/index.mjs';
@@ -1,3 +1,4 @@
1
1
  export * from './indexed-from-mapped-key.mjs';
2
+ export * from './indexed-from-mapped-result.mjs';
2
3
  export * from './indexed-property-keys.mjs';
3
4
  export * from './indexed.mjs';
@@ -1,3 +1,4 @@
1
1
  export * from './indexed-from-mapped-key.mjs';
2
+ export * from './indexed-from-mapped-result.mjs';
2
3
  export * from './indexed-property-keys.mjs';
3
4
  export * from './indexed.mjs';
@@ -0,0 +1,12 @@
1
+ import type { TSchema, SchemaOptions } from '../schema/index.mjs';
2
+ import type { TProperties } from '../object/index.mjs';
3
+ import { type TMappedResult } from '../mapped/index.mjs';
4
+ import { type TIndex } from './index.mjs';
5
+ import { TIndexPropertyKeys } from './indexed-property-keys.mjs';
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,18 @@
1
+ import { MappedResult } from '../mapped/index.mjs';
2
+ import { Index } from './index.mjs';
3
+ import { IndexPropertyKeys } from './indexed-property-keys.mjs';
4
+ // prettier-ignore
5
+ function FromProperties(T, P, options) {
6
+ return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
7
+ return { ...Acc, [K2]: Index(T, IndexPropertyKeys(P[K2]), options) };
8
+ }, {});
9
+ }
10
+ // prettier-ignore
11
+ function FromMappedResult(T, R, options) {
12
+ return FromProperties(T, R.properties, options);
13
+ }
14
+ // prettier-ignore
15
+ export function IndexFromMappedResult(T, R, options) {
16
+ const P = FromMappedResult(T, R, options);
17
+ return MappedResult(P);
18
+ }
@@ -4,7 +4,7 @@ import { type Assert } from '../helpers/index.mjs';
4
4
  import { type TNever } from '../never/index.mjs';
5
5
  import { type TRecursive } from '../recursive/index.mjs';
6
6
  import { type TIntersect } from '../intersect/index.mjs';
7
- import { type TMappedKey } from '../mapped/index.mjs';
7
+ import { TMappedResult, type TMappedKey } from '../mapped/index.mjs';
8
8
  import { type TUnion } from '../union/index.mjs';
9
9
  import { type TTuple } from '../tuple/index.mjs';
10
10
  import { type TArray } from '../array/index.mjs';
@@ -12,6 +12,7 @@ import { type TIntersectEvaluated } from '../intersect/index.mjs';
12
12
  import { type TUnionEvaluated } from '../union/index.mjs';
13
13
  import { type TIndexPropertyKeys } from './indexed-property-keys.mjs';
14
14
  import { type TIndexFromMappedKey } from './indexed-from-mapped-key.mjs';
15
+ import { type TIndexFromMappedResult } from './indexed-from-mapped-result.mjs';
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>;
@@ -4,11 +4,11 @@ import { UnionEvaluated } from '../union/index.mjs';
4
4
  import { CloneType } from '../clone/type.mjs';
5
5
  import { IndexPropertyKeys } from './indexed-property-keys.mjs';
6
6
  import { IndexFromMappedKey } from './indexed-from-mapped-key.mjs';
7
+ import { IndexFromMappedResult } from './indexed-from-mapped-result.mjs';
7
8
  // ------------------------------------------------------------------
8
9
  // TypeGuard
9
10
  // ------------------------------------------------------------------
10
- // prettier-ignore
11
- import { IsArray, IsIntersect, IsObject, IsMappedKey, IsNever, IsSchema, IsTuple, IsUnion } from '../guard/type.mjs';
11
+ import { IsArray, IsIntersect, IsObject, IsMappedKey, IsMappedResult, IsNever, IsSchema, IsTuple, IsUnion } from '../guard/type.mjs';
12
12
  // prettier-ignore
13
13
  function FromRest(T, K, Acc = []) {
14
14
  const [L, ...R] = T;
@@ -83,7 +83,8 @@ function FromSchema(T, K) {
83
83
  /** `[Json]` Returns an Indexed property type for the given keys */
84
84
  export function Index(T, K, options = {}) {
85
85
  // prettier-ignore
86
- return (IsMappedKey(K) ? CloneType(IndexFromMappedKey(T, K, options)) :
87
- IsSchema(K) ? CloneType(FromSchema(T, IndexPropertyKeys(K)), options) :
88
- CloneType(FromSchema(T, K), options));
86
+ return (IsMappedResult(K) ? CloneType(IndexFromMappedResult(T, K, options)) :
87
+ IsMappedKey(K) ? CloneType(IndexFromMappedKey(T, K, options)) :
88
+ IsSchema(K) ? CloneType(FromSchema(T, IndexPropertyKeys(K)), options) :
89
+ CloneType(FromSchema(T, K), options));
89
90
  }
@@ -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.mjs';
1
2
  import type { TTemplateLiteral, TTemplateLiteralKind } from './index.mjs';
2
3
  import type { TUnion } from '../union/index.mjs';
3
4
  import type { TString } from '../string/index.mjs';
@@ -7,7 +8,7 @@ import type { TInteger } from '../integer/index.mjs';
7
8
  import type { TBigInt } from '../bigint/index.mjs';
8
9
  import type { TLiteral } from '../literal/index.mjs';
9
10
  import type { Expression } from './parse.mjs';
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;
@@ -1,8 +1,9 @@
1
1
  import { TemplateLiteralParseExact } from './parse.mjs';
2
+ import { TypeBoxError } from '../error/index.mjs';
2
3
  // ------------------------------------------------------------------
3
4
  // TemplateLiteralFiniteError
4
5
  // ------------------------------------------------------------------
5
- export class TemplateLiteralFiniteError extends Error {
6
+ export class TemplateLiteralFiniteError extends TypeBoxError {
6
7
  }
7
8
  // ------------------------------------------------------------------
8
9
  // IsTemplateLiteralFiniteCheck
@@ -1,11 +1,12 @@
1
1
  import { TIsTemplateLiteralFinite } from './finite.mjs';
2
+ import { TypeBoxError } from '../error/index.mjs';
2
3
  import type { Assert } from '../helpers/index.mjs';
3
4
  import type { TBoolean } from '../boolean/index.mjs';
4
5
  import type { TTemplateLiteral, TTemplateLiteralKind } from './index.mjs';
5
6
  import type { TLiteral, TLiteralValue } from '../literal/index.mjs';
6
7
  import type { Expression } from './parse.mjs';
7
8
  import type { TUnion } from '../union/index.mjs';
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;
@@ -1,9 +1,10 @@
1
1
  import { IsTemplateLiteralExpressionFinite } from './finite.mjs';
2
2
  import { TemplateLiteralParseExact } from './parse.mjs';
3
+ import { TypeBoxError } from '../error/index.mjs';
3
4
  // ------------------------------------------------------------------
4
5
  // TemplateLiteralGenerateError
5
6
  // ------------------------------------------------------------------
6
- export class TemplateLiteralGenerateError extends Error {
7
+ export class TemplateLiteralGenerateError extends TypeBoxError {
7
8
  }
8
9
  // ------------------------------------------------------------------
9
10
  // TemplateLiteralExpressionGenerate
@@ -1,4 +1,5 @@
1
- export declare class TemplateLiteralParserError extends Error {
1
+ import { TypeBoxError } from '../error/index.mjs';
2
+ export declare class TemplateLiteralParserError extends TypeBoxError {
2
3
  }
3
4
  export type Expression = ExpressionAnd | ExpressionOr | ExpressionConst;
4
5
  export type ExpressionConst = {
@@ -1,7 +1,8 @@
1
+ import { TypeBoxError } from '../error/index.mjs';
1
2
  // ------------------------------------------------------------------
2
3
  // TemplateLiteralParserError
3
4
  // ------------------------------------------------------------------
4
- export class TemplateLiteralParserError extends Error {
5
+ export class TemplateLiteralParserError extends TypeBoxError {
5
6
  }
6
7
  // prettier-ignore
7
8
  function IsNonEscaped(pattern, index, char) {
@@ -1,4 +1,5 @@
1
1
  import type { TTemplateLiteralKind } from './index.mjs';
2
- export declare class TemplateLiteralPatternError extends Error {
2
+ import { TypeBoxError } from '../error/index.mjs';
3
+ export declare class TemplateLiteralPatternError extends TypeBoxError {
3
4
  }
4
5
  export declare function TemplateLiteralPattern(kinds: TTemplateLiteralKind[]): string;
@@ -1,5 +1,6 @@
1
1
  import { PatternNumber, PatternString, PatternBoolean } from '../patterns/index.mjs';
2
2
  import { Kind } from '../symbols/index.mjs';
3
+ import { TypeBoxError } from '../error/index.mjs';
3
4
  // ------------------------------------------------------------------
4
5
  // TypeGuard
5
6
  // ------------------------------------------------------------------
@@ -8,7 +9,7 @@ import { IsTemplateLiteral, IsUnion, IsNumber, IsInteger, IsBigInt, IsString, Is
8
9
  // ------------------------------------------------------------------
9
10
  // TemplateLiteralPatternError
10
11
  // ------------------------------------------------------------------
11
- export class TemplateLiteralPatternError extends Error {
12
+ export class TemplateLiteralPatternError extends TypeBoxError {
12
13
  }
13
14
  // ------------------------------------------------------------------
14
15
  // TemplateLiteralPattern
@@ -8,7 +8,7 @@ import { type TEnum, type TEnumKey, type TEnumValue } from '../enum/index.mjs';
8
8
  import { type TExclude, type TExcludeFromMappedResult } from '../exclude/index.mjs';
9
9
  import { type TExtends, type TExtendsFromMappedKey, type TExtendsFromMappedResult } from '../extends/index.mjs';
10
10
  import { type TExtract, type TExtractFromMappedResult } from '../extract/index.mjs';
11
- import { TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey } from '../indexed/index.mjs';
11
+ import { TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey, type TIndexFromMappedResult } from '../indexed/index.mjs';
12
12
  import { type IntegerOptions, type TInteger } from '../integer/index.mjs';
13
13
  import { Intersect, type IntersectOptions } from '../intersect/index.mjs';
14
14
  import { type TCapitalize, type TUncapitalize, type TLowercase, type TUppercase } from '../intrinsic/index.mjs';
@@ -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.mjs';
1
2
  import type { TSchema } from '../../type/schema/index.mjs';
2
3
  import type { Static } from '../../type/static/index.mjs';
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
  }
@@ -1,4 +1,5 @@
1
1
  import { IsPlainObject, IsArray, IsString, IsNumber, IsNull } from '../guard/index.mjs';
2
+ import { TypeBoxError } from '../../type/error/index.mjs';
2
3
  import { Kind } from '../../type/symbols/index.mjs';
3
4
  import { Create } from '../create/index.mjs';
4
5
  import { Check } from '../check/index.mjs';
@@ -7,7 +8,7 @@ import { Deref } from '../deref/index.mjs';
7
8
  // ------------------------------------------------------------------
8
9
  // Errors
9
10
  // ------------------------------------------------------------------
10
- export class ValueCastArrayUniqueItemsTypeError extends Error {
11
+ export class ValueCastArrayUniqueItemsTypeError extends TypeBoxError {
11
12
  schema;
12
13
  value;
13
14
  constructor(schema, value) {
@@ -16,21 +17,21 @@ export class ValueCastArrayUniqueItemsTypeError extends Error {
16
17
  this.value = value;
17
18
  }
18
19
  }
19
- export class ValueCastNeverTypeError extends Error {
20
+ export class ValueCastNeverTypeError extends TypeBoxError {
20
21
  schema;
21
22
  constructor(schema) {
22
23
  super('Never types cannot be cast');
23
24
  this.schema = schema;
24
25
  }
25
26
  }
26
- export class ValueCastRecursiveTypeError extends Error {
27
+ export class ValueCastRecursiveTypeError extends TypeBoxError {
27
28
  schema;
28
29
  constructor(schema) {
29
30
  super('Cannot cast recursive schemas');
30
31
  this.schema = schema;
31
32
  }
32
33
  }
33
- export class ValueCastUnknownTypeError extends Error {
34
+ export class ValueCastUnknownTypeError extends TypeBoxError {
34
35
  schema;
35
36
  constructor(schema) {
36
37
  super('Unknown type');
@@ -1,6 +1,7 @@
1
+ import { TypeBoxError } from '../../type/error/index.mjs';
1
2
  import type { TSchema } from '../../type/schema/index.mjs';
2
3
  import type { Static } from '../../type/static/index.mjs';
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
  }
@@ -5,6 +5,7 @@ import { Kind } from '../../type/symbols/index.mjs';
5
5
  import { KeyOfPattern } from '../../type/keyof/index.mjs';
6
6
  import { ExtendsUndefinedCheck } from '../../type/extends/index.mjs';
7
7
  import { TypeRegistry, FormatRegistry } from '../../type/registry/index.mjs';
8
+ import { TypeBoxError } from '../../type/error/index.mjs';
8
9
  import { Never } from '../../type/never/index.mjs';
9
10
  // ------------------------------------------------------------------
10
11
  // ValueGuard
@@ -18,7 +19,7 @@ import { IsSchema } from '../../type/guard/type.mjs';
18
19
  // ------------------------------------------------------------------
19
20
  // Errors
20
21
  // ------------------------------------------------------------------
21
- export class ValueCheckUnknownTypeError extends Error {
22
+ export class ValueCheckUnknownTypeError extends TypeBoxError {
22
23
  schema;
23
24
  constructor(schema) {
24
25
  super(`Unknown type`);
@@ -1,5 +1,6 @@
1
+ import { TypeBoxError } from '../../type/error/index.mjs';
1
2
  import type { TSchema } from '../../type/schema/index.mjs';
2
- export declare class ValueConvertUnknownTypeError extends Error {
3
+ export declare class ValueConvertUnknownTypeError extends TypeBoxError {
3
4
  readonly schema: TSchema;
4
5
  constructor(schema: TSchema);
5
6
  }
@@ -1,6 +1,7 @@
1
1
  import { Clone } from '../clone/index.mjs';
2
2
  import { Check } from '../check/index.mjs';
3
3
  import { Deref } from '../deref/index.mjs';
4
+ import { TypeBoxError } from '../../type/error/index.mjs';
4
5
  import { IsObject as IsObjectType } from '../../type/guard/type.mjs';
5
6
  import { Kind } from '../../type/symbols/index.mjs';
6
7
  import { Composite } from '../../type/composite/index.mjs';
@@ -12,7 +13,7 @@ import { IsArray, IsObject, IsDate, IsUndefined, IsString, IsNumber, IsBoolean,
12
13
  // ------------------------------------------------------------------
13
14
  // Errors
14
15
  // ------------------------------------------------------------------
15
- export class ValueConvertUnknownTypeError extends Error {
16
+ export class ValueConvertUnknownTypeError extends TypeBoxError {
16
17
  schema;
17
18
  constructor(schema) {
18
19
  super('Unknown type');
@@ -1,26 +1,27 @@
1
+ import { TypeBoxError } from '../../type/error/index.mjs';
1
2
  import type { TSchema } from '../../type/schema/index.mjs';
2
3
  import type { Static } from '../../type/static/index.mjs';
3
- export declare class ValueCreateUnknownTypeError extends Error {
4
+ export declare class ValueCreateUnknownTypeError extends TypeBoxError {
4
5
  readonly schema: TSchema;
5
6
  constructor(schema: TSchema);
6
7
  }
7
- export declare class ValueCreateNeverTypeError extends Error {
8
+ export declare class ValueCreateNeverTypeError extends TypeBoxError {
8
9
  readonly schema: TSchema;
9
10
  constructor(schema: TSchema);
10
11
  }
11
- export declare class ValueCreateNotTypeError extends Error {
12
+ export declare class ValueCreateNotTypeError extends TypeBoxError {
12
13
  readonly schema: TSchema;
13
14
  constructor(schema: TSchema);
14
15
  }
15
- export declare class ValueCreateIntersectTypeError extends Error {
16
+ export declare class ValueCreateIntersectTypeError extends TypeBoxError {
16
17
  readonly schema: TSchema;
17
18
  constructor(schema: TSchema);
18
19
  }
19
- export declare class ValueCreateTempateLiteralTypeError extends Error {
20
+ export declare class ValueCreateTempateLiteralTypeError extends TypeBoxError {
20
21
  readonly schema: TSchema;
21
22
  constructor(schema: TSchema);
22
23
  }
23
- export declare class ValueCreateRecursiveInstantiationError extends Error {
24
+ export declare class ValueCreateRecursiveInstantiationError extends TypeBoxError {
24
25
  readonly schema: TSchema;
25
26
  readonly recursiveMaxDepth: number;
26
27
  constructor(schema: TSchema, recursiveMaxDepth: number);