@sinclair/typebox 0.34.8 → 0.34.10

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 (32) hide show
  1. package/build/cjs/compiler/compiler.d.ts +4 -0
  2. package/build/cjs/compiler/compiler.js +8 -0
  3. package/build/cjs/syntax/runtime.d.ts +1 -1
  4. package/build/cjs/type/indexed/indexed-from-mapped-result.js +1 -2
  5. package/build/cjs/type/indexed/indexed-property-keys.d.ts +3 -3
  6. package/build/cjs/type/indexed/indexed-property-keys.js +7 -7
  7. package/build/cjs/type/indexed/indexed.d.ts +33 -35
  8. package/build/cjs/type/indexed/indexed.js +40 -39
  9. package/build/cjs/type/module/compute.d.ts +3 -3
  10. package/build/cjs/type/module/compute.js +0 -3
  11. package/build/cjs/type/module/infer.d.ts +3 -1
  12. package/build/cjs/type/record/record.d.ts +1 -1
  13. package/build/cjs/type/type/json.d.ts +11 -5
  14. package/build/cjs/value/parse/parse.d.ts +20 -4
  15. package/build/cjs/value/parse/parse.js +73 -17
  16. package/build/esm/compiler/compiler.d.mts +4 -0
  17. package/build/esm/compiler/compiler.mjs +8 -0
  18. package/build/esm/syntax/runtime.d.mts +1 -1
  19. package/build/esm/type/indexed/indexed-from-mapped-result.mjs +1 -2
  20. package/build/esm/type/indexed/indexed-property-keys.d.mts +3 -3
  21. package/build/esm/type/indexed/indexed-property-keys.mjs +7 -7
  22. package/build/esm/type/indexed/indexed.d.mts +33 -35
  23. package/build/esm/type/indexed/indexed.mjs +39 -39
  24. package/build/esm/type/module/compute.d.mts +3 -3
  25. package/build/esm/type/module/compute.mjs +0 -3
  26. package/build/esm/type/module/infer.d.mts +3 -1
  27. package/build/esm/type/record/record.d.mts +1 -1
  28. package/build/esm/type/type/json.d.mts +11 -5
  29. package/build/esm/value/parse/parse.d.mts +20 -4
  30. package/build/esm/value/parse/parse.mjs +70 -16
  31. package/package.json +1 -1
  32. package/readme.md +43 -77
@@ -12,6 +12,10 @@ export declare class TypeCheck<T extends TSchema> {
12
12
  constructor(schema: T, references: TSchema[], checkFunc: CheckFunction, code: string);
13
13
  /** Returns the generated assertion code used to validate this type. */
14
14
  Code(): string;
15
+ /** Returns the schema type used to validate */
16
+ Schema(): T;
17
+ /** Returns reference types used to validate */
18
+ References(): TSchema[];
15
19
  /** Returns an iterator for each error in this value. */
16
20
  Errors(value: unknown): ValueErrorIterator;
17
21
  /** Returns true if the value matches the compiled type. */
@@ -36,6 +36,14 @@ class TypeCheck {
36
36
  Code() {
37
37
  return this.code;
38
38
  }
39
+ /** Returns the schema type used to validate */
40
+ Schema() {
41
+ return this.schema;
42
+ }
43
+ /** Returns reference types used to validate */
44
+ References() {
45
+ return this.references;
46
+ }
39
47
  /** Returns an iterator for each error in this value. */
40
48
  Errors(value) {
41
49
  return (0, index_2.Errors)(this.schema, this.references, value);
@@ -48,7 +48,7 @@ export declare const Module: Runtime.Module<{
48
48
  Iterator: Runtime.ITuple<Types.TIterator<Types.TSchema>>;
49
49
  Awaited: Runtime.ITuple<Types.TSchema>;
50
50
  Array: Runtime.ITuple<Types.TArray<Types.TSchema>>;
51
- Record: Runtime.ITuple<Types.TSchema>;
51
+ Record: Runtime.ITuple<Types.TNever>;
52
52
  Promise: Runtime.ITuple<Types.TPromise<Types.TSchema>>;
53
53
  ConstructorParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
54
54
  FunctionParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
@@ -9,8 +9,7 @@ const index_2 = require("./index");
9
9
  function FromProperties(type, properties, options) {
10
10
  const result = {};
11
11
  for (const K2 of Object.getOwnPropertyNames(properties)) {
12
- const keys = (0, indexed_property_keys_1.IndexPropertyKeys)(properties[K2]);
13
- result[K2] = (0, index_2.Index)(type, keys, options);
12
+ result[K2] = (0, index_2.Index)(type, (0, indexed_property_keys_1.IndexPropertyKeys)(properties[K2]), options);
14
13
  }
15
14
  return result;
16
15
  }
@@ -4,11 +4,11 @@ import type { TInteger } from '../integer/index';
4
4
  import type { TNumber } from '../number/index';
5
5
  import type { TSchema } from '../schema/index';
6
6
  import type { TUnion } from '../union/index';
7
- type TFromTemplateLiteral<TemplateLiteral extends TTemplateLiteral, Result extends string[] = TTemplateLiteralGenerate<TemplateLiteral>> = Result;
7
+ type TFromTemplateLiteral<TemplateLiteral extends TTemplateLiteral, Keys extends string[] = TTemplateLiteralGenerate<TemplateLiteral>> = (Keys);
8
8
  type TFromUnion<Types extends TSchema[], Result extends string[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion<Right, [...Result, ...TIndexPropertyKeys<Left>]> : Result);
9
9
  type TFromLiteral<LiteralValue extends TLiteralValue> = (LiteralValue extends PropertyKey ? [`${LiteralValue}`] : []);
10
- export type TIndexPropertyKeys<Type extends TSchema, Result extends PropertyKey[] = (Type extends TTemplateLiteral ? TFromTemplateLiteral<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TLiteral<infer LiteralValue extends TLiteralValue> ? TFromLiteral<LiteralValue> : Type extends TNumber ? ['[number]'] : Type extends TInteger ? ['[number]'] : [
11
- ])> = Result;
10
+ export type TIndexPropertyKeys<Type extends TSchema> = (Type extends TTemplateLiteral ? TFromTemplateLiteral<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteral<Value> : Type extends TNumber ? ['[number]'] : Type extends TInteger ? ['[number]'] : [
11
+ ]);
12
12
  /** Returns a tuple of PropertyKeys derived from the given TSchema */
13
13
  export declare function IndexPropertyKeys<Type extends TSchema>(type: Type): TIndexPropertyKeys<Type>;
14
14
  export {};
@@ -9,19 +9,19 @@ const index_1 = require("../template-literal/index");
9
9
  const kind_1 = require("../guard/kind");
10
10
  // prettier-ignore
11
11
  function FromTemplateLiteral(templateLiteral) {
12
- const result = (0, index_1.TemplateLiteralGenerate)(templateLiteral);
13
- return result.map(S => S.toString());
12
+ const keys = (0, index_1.TemplateLiteralGenerate)(templateLiteral);
13
+ return keys.map(key => key.toString());
14
14
  }
15
15
  // prettier-ignore
16
- function FromUnion(type) {
16
+ function FromUnion(types) {
17
17
  const result = [];
18
- for (const left of type)
19
- result.push(...IndexPropertyKeys(left));
18
+ for (const type of types)
19
+ result.push(...IndexPropertyKeys(type));
20
20
  return result;
21
21
  }
22
22
  // prettier-ignore
23
- function FromLiteral(T) {
24
- return ([T.toString()] // TS 5.4 observes TLiteralValue as not having a toString()
23
+ function FromLiteral(literalValue) {
24
+ return ([literalValue.toString()] // TS 5.4 observes TLiteralValue as not having a toString()
25
25
  );
26
26
  }
27
27
  /** Returns a tuple of PropertyKeys derived from the given TSchema */
@@ -1,54 +1,52 @@
1
1
  import { type TSchema, SchemaOptions } from '../schema/index';
2
- import { type TComputed } from '../computed/index';
3
- import { type TLiteral, type TLiteralValue } from '../literal/index';
4
- import { type TObject, type TProperties } from '../object/index';
5
2
  import { type Assert } from '../helpers/index';
3
+ import { type TComputed } from '../computed/index';
6
4
  import { type TNever } from '../never/index';
7
- import { type TRecursive } from '../recursive/index';
5
+ import { type TArray } from '../array/index';
8
6
  import { type TIntersect } from '../intersect/index';
9
- import { TMappedResult, type TMappedKey } from '../mapped/index';
7
+ import { type TMappedResult, type TMappedKey } from '../mapped/index';
8
+ import { type TObject, type TProperties } from '../object/index';
10
9
  import { type TUnion } from '../union/index';
11
- import { type TTuple } from '../tuple/index';
12
- import { type TArray } from '../array/index';
10
+ import { type TRecursive } from '../recursive/index';
13
11
  import { type TRef } from '../ref/index';
12
+ import { type TTuple } from '../tuple/index';
14
13
  import { type TIntersectEvaluated } from '../intersect/index';
15
14
  import { type TUnionEvaluated } from '../union/index';
16
15
  import { type TIndexPropertyKeys } from './indexed-property-keys';
17
16
  import { type TIndexFromMappedKey } from './indexed-from-mapped-key';
18
17
  import { type TIndexFromMappedResult } from './indexed-from-mapped-result';
19
- type TFromRest<T extends TSchema[], K extends PropertyKey, Result extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Result, Assert<TIndexFromPropertyKey<L, K>, TSchema>]> : Result);
18
+ type TFromRest<Types extends TSchema[], Key extends PropertyKey, Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest<Right, Key, [...Result, Assert<TIndexFromPropertyKey<Left, Key>, TSchema>]> : Result);
20
19
  type TFromIntersectRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TNever ? TFromIntersectRest<Right, [...Result]> : TFromIntersectRest<Right, [...Result, Left]> : Result);
21
20
  type TFromIntersect<Types extends TSchema[], Key extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<Types, Key>>>);
22
21
  type TFromUnionRest<Types extends TSchema[], Result extends TSchema[] = []> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TNever ? [] : TFromUnionRest<Right, [Left, ...Result]> : Result;
23
22
  type TFromUnion<Types extends TSchema[], Key extends PropertyKey> = (TUnionEvaluated<TFromUnionRest<TFromRest<Types, Key>>>);
24
- type TFromTuple<Types extends TSchema[], Key extends PropertyKey, Result extends TSchema = (Key extends '[number]' ? TUnionEvaluated<Types> : Key extends keyof Types ? Types[Key] extends infer Type extends TSchema ? Type : TNever : TNever)> = Result;
23
+ type TFromTuple<Types extends TSchema[], Key extends PropertyKey> = (Key extends keyof Types ? Types[Key] : Key extends '[number]' ? TUnionEvaluated<Types> : TNever);
25
24
  type TFromArray<Type extends TSchema, Key extends PropertyKey> = (Key extends '[number]' ? Type : TNever);
26
- type AssertPropertyKey<T extends unknown> = Assert<T, string | number>;
27
- type TFromProperty<Properties extends TProperties, Key extends PropertyKey, Result extends TSchema = (Key extends keyof Properties ? Properties[Key] : `${AssertPropertyKey<Key>}` extends `${AssertPropertyKey<keyof Properties>}` ? Properties[AssertPropertyKey<Key>] : TNever)> = Result;
28
- export type TIndexFromPropertyKey<Type extends TSchema, Key extends PropertyKey> = (Type extends TRecursive<infer S extends TSchema> ? TIndexFromPropertyKey<S, Key> : Type extends TIntersect<infer S extends TSchema[]> ? TFromIntersect<S, Key> : Type extends TUnion<infer S extends TSchema[]> ? TFromUnion<S, Key> : Type extends TTuple<infer S extends TSchema[]> ? TFromTuple<S, Key> : Type extends TArray<infer S extends TSchema> ? TFromArray<S, Key> : Type extends TObject<infer S extends TProperties> ? TFromProperty<S, Key> : TNever);
29
- export declare function IndexFromPropertyKey<Type extends TSchema, Key extends PropertyKey>(type: Type, key: Key): TIndexFromPropertyKey<Type, Key>;
25
+ type AssertPropertyKey<T> = Assert<T, string | number>;
26
+ type TFromProperty<Properties extends TProperties, Key extends PropertyKey> = (Key extends keyof Properties ? Properties[Key] : `${AssertPropertyKey<Key>}` extends `${AssertPropertyKey<keyof Properties>}` ? Properties[AssertPropertyKey<Key>] : TNever);
27
+ export type TIndexFromPropertyKey<Type extends TSchema, Key extends PropertyKey> = (Type extends TRecursive<infer Type extends TSchema> ? TIndexFromPropertyKey<Type, Key> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types, Key> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types, Key> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types, Key> : Type extends TArray<infer Type extends TSchema> ? TFromArray<Type, Key> : Type extends TObject<infer Properties extends TProperties> ? TFromProperty<Properties, Key> : TNever);
28
+ export declare function IndexFromPropertyKey<Type extends TSchema, Key extends PropertyKey>(type: Type, propertyKey: Key): TIndexFromPropertyKey<Type, Key>;
30
29
  export type TIndexFromPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = (PropertyKeys extends [infer Left extends PropertyKey, ...infer Right extends PropertyKey[]] ? TIndexFromPropertyKeys<Type, Right, [...Result, Assert<TIndexFromPropertyKey<Type, Left>, TSchema>]> : Result);
31
30
  export declare function IndexFromPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, propertyKeys: [...PropertyKeys]): TIndexFromPropertyKeys<Type, PropertyKeys>;
32
- type TFromType<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TSchema[] = TIndexFromPropertyKeys<Type, PropertyKeys>> = TUnionEvaluated<Result>;
33
- type TUnionFromPropertyKeys<PropertyKeys extends PropertyKey[], Result extends TLiteral[] = []> = (PropertyKeys extends [infer Key extends PropertyKey, ...infer Rest extends PropertyKey[]] ? Key extends TLiteralValue ? TUnionFromPropertyKeys<Rest, [...Result, TLiteral<Key>]> : TUnionFromPropertyKeys<Rest, [...Result]> : TUnionEvaluated<Result>);
34
- type TResolvePropertyKeys<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
35
- type TResolveTypeKey<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys<Key> : Key;
36
- export type TIndex<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Key extends TMappedResult ? TIndexFromMappedResult<Type, Key> : Key extends TMappedKey ? TIndexFromMappedKey<Type, Key> : [
37
- IsTypeRef,
38
- IsKeyRef
39
- ] extends [true, true] ? TComputed<'Index', [Type, TResolveTypeKey<Key>]> : [
40
- IsTypeRef,
41
- IsKeyRef
42
- ] extends [false, true] ? TComputed<'Index', [Type, TResolveTypeKey<Key>]> : [
43
- IsTypeRef,
44
- IsKeyRef
45
- ] extends [true, false] ? TComputed<'Index', [Type, TResolveTypeKey<Key>]> : TFromType<Type, TResolvePropertyKeys<Key>>);
46
- /** `[Json]` Returns an Indexed property type for the given keys */
47
- export declare function Index<Type extends TSchema, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TIndex<Type, Key>;
48
- /** `[Json]` Returns an Indexed property type for the given keys */
49
- export declare function Index<Type extends TSchema, Key extends TMappedKey>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
50
- /** `[Json]` Returns an Indexed property type for the given keys */
51
- export declare function Index<Type extends TSchema, Key extends TMappedResult>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
52
- /** `[Json]` Returns an Indexed property type for the given keys */
53
- export declare function Index<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
31
+ type FromSchema<Type extends TSchema, PropertyKeys extends PropertyKey[]> = (TUnionEvaluated<TIndexFromPropertyKeys<Type, PropertyKeys>>);
32
+ declare function FromSchema<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, propertyKeys: [...PropertyKeys]): FromSchema<Type, PropertyKeys>;
33
+ export type TIndexFromComputed<Type extends TSchema, Key extends TSchema> = (TComputed<'Index', [Type, Key]>);
34
+ export declare function IndexFromComputed<Type extends TSchema, Key extends TSchema>(type: Type, key: Key): TIndexFromComputed<Type, Key>;
35
+ export type TIndex<Type extends TSchema, PropertyKeys extends PropertyKey[]> = (FromSchema<Type, PropertyKeys>);
36
+ /** `[Json]` Returns an Indexed property type for the given keys */
37
+ export declare function Index<Type extends TRef, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
38
+ /** `[Json]` Returns an Indexed property type for the given keys */
39
+ export declare function Index<Type extends TSchema, Key extends TRef>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
40
+ /** `[Json]` Returns an Indexed property type for the given keys */
41
+ export declare function Index<Type extends TRef, Key extends TRef>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
42
+ /** `[Json]` Returns an Indexed property type for the given keys */
43
+ export declare function Index<Type extends TSchema, MappedResult extends TMappedResult>(type: Type, mappedResult: MappedResult, options?: SchemaOptions): TIndexFromMappedResult<Type, MappedResult>;
44
+ /** `[Json]` Returns an Indexed property type for the given keys */
45
+ export declare function Index<Type extends TSchema, MappedResult extends TMappedResult>(type: Type, mappedResult: MappedResult, options?: SchemaOptions): TIndexFromMappedResult<Type, MappedResult>;
46
+ /** `[Json]` Returns an Indexed property type for the given keys */
47
+ export declare function Index<Type extends TSchema, MappedKey extends TMappedKey>(type: Type, mappedKey: MappedKey, options?: SchemaOptions): TIndexFromMappedKey<Type, MappedKey>;
48
+ /** `[Json]` Returns an Indexed property type for the given keys */
49
+ export declare function Index<Type extends TSchema, Key extends TSchema, PropertyKeys extends PropertyKey[] = TIndexPropertyKeys<Key>>(T: Type, K: Key, options?: SchemaOptions): TIndex<Type, PropertyKeys>;
50
+ /** `[Json]` Returns an Indexed property type for the given keys */
51
+ export declare function Index<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, propertyKeys: readonly [...PropertyKeys], options?: SchemaOptions): TIndex<Type, PropertyKeys>;
54
52
  export {};
@@ -3,31 +3,28 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.IndexFromPropertyKey = IndexFromPropertyKey;
5
5
  exports.IndexFromPropertyKeys = IndexFromPropertyKeys;
6
+ exports.IndexFromComputed = IndexFromComputed;
6
7
  exports.Index = Index;
7
8
  const type_1 = require("../create/type");
8
- const index_1 = require("../computed/index");
9
- const index_2 = require("../literal/index");
9
+ const index_1 = require("../error/index");
10
+ const index_2 = require("../computed/index");
10
11
  const index_3 = require("../never/index");
11
12
  const index_4 = require("../intersect/index");
12
13
  const index_5 = require("../union/index");
13
- // ------------------------------------------------------------------
14
- // Infrastructure
15
- // ------------------------------------------------------------------
16
14
  const indexed_property_keys_1 = require("./indexed-property-keys");
17
15
  const indexed_from_mapped_key_1 = require("./indexed-from-mapped-key");
18
16
  const indexed_from_mapped_result_1 = require("./indexed-from-mapped-result");
19
17
  // ------------------------------------------------------------------
20
- // KindGuard
18
+ // TypeGuard
21
19
  // ------------------------------------------------------------------
22
20
  const kind_1 = require("../guard/kind");
23
- const value_1 = require("../guard/value");
24
21
  // prettier-ignore
25
22
  function FromRest(types, key) {
26
- return types.map(left => IndexFromPropertyKey(left, key));
23
+ return types.map(type => IndexFromPropertyKey(type, key));
27
24
  }
28
25
  // prettier-ignore
29
26
  function FromIntersectRest(types) {
30
- return types.filter(left => !(0, kind_1.IsNever)(left));
27
+ return types.filter(type => !(0, kind_1.IsNever)(type));
31
28
  }
32
29
  // prettier-ignore
33
30
  function FromIntersect(types, key) {
@@ -45,53 +42,57 @@ function FromUnion(types, key) {
45
42
  }
46
43
  // prettier-ignore
47
44
  function FromTuple(types, key) {
48
- return (key === '[number]' ? (0, index_5.UnionEvaluated)(types) :
49
- key in types ? types[key] :
45
+ return (key in types ? types[key] :
46
+ key === '[number]' ? (0, index_5.UnionEvaluated)(types) :
50
47
  (0, index_3.Never)());
51
48
  }
52
49
  // prettier-ignore
53
50
  function FromArray(type, key) {
54
- // ... ?
55
- return (key === '[number]' ? type : (0, index_3.Never)());
51
+ return (key === '[number]'
52
+ ? type
53
+ : (0, index_3.Never)());
56
54
  }
57
55
  // prettier-ignore
58
- function FromProperty(properties, key) {
59
- return (key in properties ? properties[key] : (0, index_3.Never)());
56
+ function FromProperty(properties, propertyKey) {
57
+ return (propertyKey in properties ? properties[propertyKey] : (0, index_3.Never)());
60
58
  }
61
59
  // prettier-ignore
62
- function IndexFromPropertyKey(type, key) {
63
- return ((0, kind_1.IsIntersect)(type) ? FromIntersect(type.allOf, key) :
64
- (0, kind_1.IsUnion)(type) ? FromUnion(type.anyOf, key) :
65
- (0, kind_1.IsTuple)(type) ? FromTuple(type.items ?? [], key) :
66
- (0, kind_1.IsArray)(type) ? FromArray(type.items, key) :
67
- (0, kind_1.IsObject)(type) ? FromProperty(type.properties, key) :
60
+ function IndexFromPropertyKey(type, propertyKey) {
61
+ return ((0, kind_1.IsIntersect)(type) ? FromIntersect(type.allOf, propertyKey) :
62
+ (0, kind_1.IsUnion)(type) ? FromUnion(type.anyOf, propertyKey) :
63
+ (0, kind_1.IsTuple)(type) ? FromTuple(type.items ?? [], propertyKey) :
64
+ (0, kind_1.IsArray)(type) ? FromArray(type.items, propertyKey) :
65
+ (0, kind_1.IsObject)(type) ? FromProperty(type.properties, propertyKey) :
68
66
  (0, index_3.Never)());
69
67
  }
70
68
  // prettier-ignore
71
69
  function IndexFromPropertyKeys(type, propertyKeys) {
72
- return propertyKeys.map(left => IndexFromPropertyKey(type, left));
70
+ return propertyKeys.map(propertyKey => IndexFromPropertyKey(type, propertyKey));
73
71
  }
74
72
  // prettier-ignore
75
- function FromType(type, propertyKeys) {
76
- const result = IndexFromPropertyKeys(type, propertyKeys);
77
- return (0, index_5.UnionEvaluated)(result);
73
+ function FromSchema(type, propertyKeys) {
74
+ return ((0, index_5.UnionEvaluated)(IndexFromPropertyKeys(type, propertyKeys)));
78
75
  }
79
76
  // prettier-ignore
80
- function UnionFromPropertyKeys(propertyKeys) {
81
- const result = propertyKeys.reduce((result, key) => (0, kind_1.IsLiteralValue)(key) ? [...result, (0, index_2.Literal)(key)] : result, []);
82
- return (0, index_5.UnionEvaluated)(result);
77
+ function IndexFromComputed(type, key) {
78
+ return (0, index_2.Computed)('Index', [type, key]);
83
79
  }
84
80
  /** `[Json]` Returns an Indexed property type for the given keys */
85
- // prettier-ignore
86
81
  function Index(type, key, options) {
87
- const typeKey = (0, value_1.IsArray)(key) ? UnionFromPropertyKeys(key) : key;
88
- const propertyKeys = (0, kind_1.IsSchema)(key) ? (0, indexed_property_keys_1.IndexPropertyKeys)(key) : key;
89
- const isTypeRef = (0, kind_1.IsRef)(type);
90
- const isKeyRef = (0, kind_1.IsRef)(key);
91
- return ((0, kind_1.IsMappedResult)(key) ? (0, indexed_from_mapped_result_1.IndexFromMappedResult)(type, key, options) :
92
- (0, kind_1.IsMappedKey)(key) ? (0, indexed_from_mapped_key_1.IndexFromMappedKey)(type, key, options) :
93
- (isTypeRef && isKeyRef) ? (0, index_1.Computed)('Index', [type, typeKey], options) :
94
- (!isTypeRef && isKeyRef) ? (0, index_1.Computed)('Index', [type, typeKey], options) :
95
- (isTypeRef && !isKeyRef) ? (0, index_1.Computed)('Index', [type, typeKey], options) :
96
- (0, type_1.CreateType)(FromType(type, propertyKeys), options));
82
+ // computed-type
83
+ if ((0, kind_1.IsRef)(type) || (0, kind_1.IsRef)(key)) {
84
+ const error = `Index types using Ref parameters require both Type and Key to be of TSchema`;
85
+ if (!(0, kind_1.IsSchema)(type) || !(0, kind_1.IsSchema)(key))
86
+ throw new index_1.TypeBoxError(error);
87
+ return (0, index_2.Computed)('Index', [type, key]);
88
+ }
89
+ // mapped-types
90
+ if ((0, kind_1.IsMappedResult)(key))
91
+ return (0, indexed_from_mapped_result_1.IndexFromMappedResult)(type, key, options);
92
+ if ((0, kind_1.IsMappedKey)(key))
93
+ return (0, indexed_from_mapped_key_1.IndexFromMappedKey)(type, key, options);
94
+ // prettier-ignore
95
+ return (0, type_1.CreateType)((0, kind_1.IsSchema)(key)
96
+ ? FromSchema(type, (0, indexed_property_keys_1.IndexPropertyKeys)(key))
97
+ : FromSchema(type, key), options);
97
98
  }
@@ -5,8 +5,8 @@ import { type TAwaited } from '../awaited/index';
5
5
  import { type TAsyncIterator } from '../async-iterator/index';
6
6
  import { TComputed } from '../computed/index';
7
7
  import { type TConstructor } from '../constructor/index';
8
- import { type TIndex } from '../indexed/index';
9
- import { TEnum, TEnumRecord } from '../enum/index';
8
+ import { type TIndex, type TIndexPropertyKeys } from '../indexed/index';
9
+ import { TEnum, type TEnumRecord } from '../enum/index';
10
10
  import { type TFunction } from '../function/index';
11
11
  import { type TIntersect, type TIntersectEvaluated } from '../intersect/index';
12
12
  import { type TIterator } from '../iterator/index';
@@ -26,7 +26,7 @@ import { type TUnion, type TUnionEvaluated } from '../union/index';
26
26
  type TDerefParameters<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TRef<infer Key extends string> ? TDerefParameters<ModuleProperties, Right, [...Result, TDeref<ModuleProperties, Key>]> : TDerefParameters<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
27
27
  type TDeref<ModuleProperties extends TProperties, Ref extends string, Result extends TSchema = (Ref extends keyof ModuleProperties ? ModuleProperties[Ref] extends TRef<infer Ref2 extends string> ? TDeref<ModuleProperties, Ref2> : TFromType<ModuleProperties, ModuleProperties[Ref]> : TNever)> = Result;
28
28
  type TFromAwaited<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TAwaited<T0> : never);
29
- type TFromIndex<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TIndex<T0, T1> : never);
29
+ type TFromIndex<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TIndex<T0, TIndexPropertyKeys<T1>> extends infer Result extends TSchema ? Result : never : never);
30
30
  type TFromKeyOf<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TKeyOf<T0> : never);
31
31
  type TFromPartial<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TPartial<T0> : never);
32
32
  type TFromOmit<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TOmit<T0, T1> : never);
@@ -133,9 +133,6 @@ function FromType(moduleProperties, type) {
133
133
  // Traveral
134
134
  KindGuard.IsArray(type) ? (0, index_1.CreateType)(FromArray(moduleProperties, type.items), type) :
135
135
  KindGuard.IsAsyncIterator(type) ? (0, index_1.CreateType)(FromAsyncIterator(moduleProperties, type.items), type) :
136
- // Note: The 'as never' is required due to excessive resolution of TIndex. In fact TIndex, TPick, TOmit and
137
- // all need re-implementation to remove the PropertyKey[] selector. Reimplementation of these types should
138
- // be a priority as there is a potential for the current inference to break on TS compiler changes.
139
136
  KindGuard.IsComputed(type) ? (0, index_1.CreateType)(FromComputed(moduleProperties, type.target, type.parameters)) :
140
137
  KindGuard.IsConstructor(type) ? (0, index_1.CreateType)(FromConstructor(moduleProperties, type.parameters, type.returns), type) :
141
138
  KindGuard.IsFunction(type) ? (0, index_1.CreateType)(FromFunction(moduleProperties, type.parameters, type.returns), type) :
@@ -37,7 +37,9 @@ type InferProperties<ModuleProperties extends TProperties, Properties extends TP
37
37
  }>;
38
38
  type TInferObject<ModuleProperties extends TProperties, Properties extends TProperties> = (InferProperties<ModuleProperties, Properties>);
39
39
  type TInferTuple<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferTuple<ModuleProperties, R, [...Result, TInfer<ModuleProperties, L>]> : Result);
40
- type TInferRecord<ModuleProperties extends TProperties, Key extends TSchema, Type extends TSchema, InferredKey extends PropertyKey = TInfer<ModuleProperties, Key> extends infer Key extends PropertyKey ? Key : never, InferedType extends unknown = TInfer<ModuleProperties, Type>> = Record<InferredKey, InferedType>;
40
+ type TInferRecord<ModuleProperties extends TProperties, Key extends TSchema, Type extends TSchema, InferredKey extends PropertyKey = TInfer<ModuleProperties, Key> extends infer Key extends PropertyKey ? Key : never, InferedType extends unknown = TInfer<ModuleProperties, Type>> = Ensure<{
41
+ [_ in InferredKey]: InferedType;
42
+ }>;
41
43
  type TInferRef<ModuleProperties extends TProperties, Ref extends string> = (Ref extends keyof ModuleProperties ? TInfer<ModuleProperties, ModuleProperties[Ref]> : unknown);
42
44
  type TInferUnion<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown = never> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferUnion<ModuleProperties, R, Result | TInfer<ModuleProperties, L>> : Result);
43
45
  type TInfer<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TInferArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TInferAsyncIterator<ModuleProperties, Type> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TInferConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TInferFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TInferIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TInferIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TInferObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Type extends TSchema> ? TInferRecord<ModuleProperties, Key, Type> : Type extends TRef<infer Ref extends string> ? TInferRef<ModuleProperties, Ref> : Type extends TTuple<infer Types extends TSchema[]> ? TInferTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Static<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TInferUnion<ModuleProperties, Types> : Static<Type>);
@@ -52,7 +52,7 @@ export interface TRecord<Key extends TSchema = TSchema, Type extends TSchema = T
52
52
  };
53
53
  additionalProperties: TAdditionalProperties;
54
54
  }
55
- export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [Key, TComputed<Target, Parameters>]> : Key extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [TComputed<Target, Parameters>, Type]> : Key extends TRef<infer Ref extends string> ? TComputed<'Record', [TRef<Ref>, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer Enum extends TEnumRecord> ? TFromEnumKey<Enum, Type> : Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Type> : Key extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteralKey<Value, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : Key);
55
+ export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [Key, TComputed<Target, Parameters>]> : Key extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [TComputed<Target, Parameters>, Type]> : Key extends TRef<infer Ref extends string> ? TComputed<'Record', [TRef<Ref>, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer Enum extends TEnumRecord> ? TFromEnumKey<Enum, Type> : Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Type> : Key extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteralKey<Value, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : TNever);
56
56
  /** `[Json]` Creates a Record type */
57
57
  export declare function Record<Key extends TSchema, Type extends TSchema>(key: Key, type: Type, options?: ObjectOptions): TRecordOrObject<Key, Type>;
58
58
  export {};
@@ -7,7 +7,7 @@ import { type TEnum, type TEnumKey, type TEnumValue } from '../enum/index';
7
7
  import { type TExclude, type TExcludeFromMappedResult, type TExcludeFromTemplateLiteral } from '../exclude/index';
8
8
  import { type TExtends, type TExtendsFromMappedKey, type TExtendsFromMappedResult } from '../extends/index';
9
9
  import { type TExtract, type TExtractFromMappedResult, type TExtractFromTemplateLiteral } from '../extract/index';
10
- import { TIndex, type TIndexPropertyKeys } from '../indexed/index';
10
+ import { TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey, type TIndexFromMappedResult, type TIndexFromComputed } from '../indexed/index';
11
11
  import { type IntegerOptions, type TInteger } from '../integer/index';
12
12
  import { Intersect, type IntersectOptions } from '../intersect/index';
13
13
  import { type TCapitalize, type TUncapitalize, type TLowercase, type TUppercase } from '../intrinsic/index';
@@ -93,13 +93,19 @@ 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<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, key: readonly [...PropertyKeys], options?: SchemaOptions): TIndex<Type, PropertyKeys>;
96
+ Index<Type extends TRef, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
97
97
  /** `[Json]` Returns an Indexed property type for the given keys */
98
- Index<Type extends TSchema, Key extends TMappedKey>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
98
+ Index<Type extends TSchema, Key extends TRef>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
99
99
  /** `[Json]` Returns an Indexed property type for the given keys */
100
- Index<Type extends TSchema, Key extends TMappedResult>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
100
+ Index<Type extends TRef, Key extends TRef>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
101
101
  /** `[Json]` Returns an Indexed property type for the given keys */
102
- Index<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
102
+ Index<Type extends TSchema, MappedResult extends TMappedResult>(type: Type, mappedResult: MappedResult, options?: SchemaOptions): TIndexFromMappedResult<Type, MappedResult>;
103
+ /** `[Json]` Returns an Indexed property type for the given keys */
104
+ Index<Type extends TSchema, MappedKey extends TMappedKey>(type: Type, mappedKey: MappedKey, options?: SchemaOptions): TIndexFromMappedKey<Type, MappedKey>;
105
+ /** `[Json]` Returns an Indexed property type for the given keys */
106
+ Index<Type extends TSchema, Key extends TSchema, PropertyKeys extends PropertyKey[] = TIndexPropertyKeys<Key>>(T: Type, K: Key, options?: SchemaOptions): TIndex<Type, PropertyKeys>;
107
+ /** `[Json]` Returns an Indexed property type for the given keys */
108
+ Index<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, propertyKeys: readonly [...PropertyKeys], options?: SchemaOptions): TIndex<Type, PropertyKeys>;
103
109
  /** `[Json]` Creates an Integer type */
104
110
  Integer(options?: IntegerOptions): TInteger;
105
111
  /** `[Json]` Creates an Intersect type */
@@ -1,6 +1,22 @@
1
+ import { TypeBoxError } from '../../type/error/index';
1
2
  import { TSchema } from '../../type/schema/index';
2
3
  import { StaticDecode } from '../../type/static/index';
3
- /** Parses a value or throws an `AssertError` if invalid. */
4
- export declare function Parse<T extends TSchema, R = StaticDecode<T>>(schema: T, references: TSchema[], value: unknown): R;
5
- /** Parses a value or throws an `AssertError` if invalid. */
6
- export declare function Parse<T extends TSchema, R = StaticDecode<T>>(schema: T, value: unknown): R;
4
+ export declare class ParseError extends TypeBoxError {
5
+ constructor(message: string);
6
+ }
7
+ export type TParseOperation = 'Clone' | 'Clean' | 'Default' | 'Convert' | 'Assert' | 'Decode' | 'Encode' | ({} & string);
8
+ export type TParseFunction = (type: TSchema, references: TSchema[], value: unknown) => unknown;
9
+ export declare namespace ParseRegistry {
10
+ function Delete(key: string): void;
11
+ function Set(key: string, callback: TParseFunction): void;
12
+ function Get(key: string): TParseFunction | undefined;
13
+ }
14
+ export declare const ParseDefault: readonly ["Clone", "Clean", "Default", "Convert", "Assert", "Decode"];
15
+ /** Parses a value using the default parse pipeline. Will throws an `AssertError` if invalid. */
16
+ export declare function Parse<Type extends TSchema, Output = StaticDecode<Type>, Result extends Output = Output>(schema: Type, references: TSchema[], value: unknown): Result;
17
+ /** Parses a value using the default parse pipeline. Will throws an `AssertError` if invalid. */
18
+ export declare function Parse<Type extends TSchema, Output = StaticDecode<Type>, Result extends Output = Output>(schema: Type, value: unknown): Result;
19
+ /** Parses a value using the specified operations. */
20
+ export declare function Parse<Type extends TSchema>(operations: TParseOperation[], schema: Type, references: TSchema[], value: unknown): unknown;
21
+ /** Parses a value using the specified operations. */
22
+ export declare function Parse<Type extends TSchema>(operations: TParseOperation[], schema: Type, value: unknown): unknown;
@@ -1,29 +1,85 @@
1
1
  "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ParseDefault = exports.ParseRegistry = exports.ParseError = void 0;
4
5
  exports.Parse = Parse;
5
- const index_1 = require("../transform/index");
6
- const assert_1 = require("../assert/assert");
7
- const default_1 = require("../default/default");
8
- const convert_1 = require("../convert/convert");
9
- const clean_1 = require("../clean/clean");
10
- const index_2 = require("../clone/index");
6
+ const index_1 = require("../../type/error/index");
7
+ const index_2 = require("../transform/index");
8
+ const index_3 = require("../assert/index");
9
+ const index_4 = require("../default/index");
10
+ const index_5 = require("../convert/index");
11
+ const index_6 = require("../clean/index");
12
+ const index_7 = require("../clone/index");
13
+ // ------------------------------------------------------------------
14
+ // Guards
15
+ // ------------------------------------------------------------------
16
+ const index_8 = require("../guard/index");
17
+ // ------------------------------------------------------------------
18
+ // Error
19
+ // ------------------------------------------------------------------
20
+ class ParseError extends index_1.TypeBoxError {
21
+ constructor(message) {
22
+ super(message);
23
+ }
24
+ }
25
+ exports.ParseError = ParseError;
26
+ // prettier-ignore
27
+ var ParseRegistry;
28
+ (function (ParseRegistry) {
29
+ const registry = new Map([
30
+ ['Clone', (_type, _references, value) => (0, index_7.Clone)(value)],
31
+ ['Clean', (type, references, value) => (0, index_6.Clean)(type, references, value)],
32
+ ['Default', (type, references, value) => (0, index_4.Default)(type, references, value)],
33
+ ['Convert', (type, references, value) => (0, index_5.Convert)(type, references, value)],
34
+ ['Assert', (type, references, value) => { (0, index_3.Assert)(type, references, value); return value; }],
35
+ ['Decode', (type, references, value) => ((0, index_2.HasTransform)(type, references) ? (0, index_2.TransformDecode)(type, references, value) : value)],
36
+ ['Encode', (type, references, value) => ((0, index_2.HasTransform)(type, references) ? (0, index_2.TransformEncode)(type, references, value) : value)],
37
+ ]);
38
+ // Deletes an entry from the registry
39
+ function Delete(key) {
40
+ registry.delete(key);
41
+ }
42
+ ParseRegistry.Delete = Delete;
43
+ // Sets an entry in the registry
44
+ function Set(key, callback) {
45
+ registry.set(key, callback);
46
+ }
47
+ ParseRegistry.Set = Set;
48
+ // Gets an entry in the registry
49
+ function Get(key) {
50
+ return registry.get(key);
51
+ }
52
+ ParseRegistry.Get = Get;
53
+ })(ParseRegistry || (exports.ParseRegistry = ParseRegistry = {}));
54
+ // ------------------------------------------------------------------
55
+ // Default Parse Sequence
56
+ // ------------------------------------------------------------------
11
57
  // prettier-ignore
12
- const ParseReducer = [
13
- (_schema, _references, value) => (0, index_2.Clone)(value),
14
- (schema, references, value) => (0, default_1.Default)(schema, references, value),
15
- (schema, references, value) => (0, clean_1.Clean)(schema, references, value),
16
- (schema, references, value) => (0, convert_1.Convert)(schema, references, value),
17
- (schema, references, value) => { (0, assert_1.Assert)(schema, references, value); return value; },
18
- (schema, references, value) => ((0, index_1.HasTransform)(schema, references) ? (0, index_1.TransformDecode)(schema, references, value) : value),
58
+ exports.ParseDefault = [
59
+ 'Clone',
60
+ 'Clean',
61
+ 'Default',
62
+ 'Convert',
63
+ 'Assert',
64
+ 'Decode'
19
65
  ];
20
66
  // ------------------------------------------------------------------
21
67
  // ParseValue
22
68
  // ------------------------------------------------------------------
23
- function ParseValue(schema, references, value) {
24
- return ParseReducer.reduce((value, reducer) => reducer(schema, references, value), value);
69
+ function ParseValue(operations, type, references, value) {
70
+ return operations.reduce((value, operationKey) => {
71
+ const operation = ParseRegistry.Get(operationKey);
72
+ if ((0, index_8.IsUndefined)(operation))
73
+ throw new ParseError(`Unable to find Parse operation '${operationKey}'`);
74
+ return operation(type, references, value);
75
+ }, value);
25
76
  }
26
- /** Parses a value or throws an `AssertError` if invalid. */
77
+ /** Parses a value */
27
78
  function Parse(...args) {
28
- return args.length === 3 ? ParseValue(args[0], args[1], args[2]) : ParseValue(args[0], [], args[1]);
79
+ // prettier-ignore
80
+ const [operations, schema, references, value] = (args.length === 4 ? [args[0], args[1], args[2], args[3]] :
81
+ args.length === 3 ? (0, index_8.IsArray)(args[0]) ? [args[0], args[1], [], args[2]] : [exports.ParseDefault, args[0], args[1], args[2]] :
82
+ args.length === 2 ? [exports.ParseDefault, args[0], [], args[1]] :
83
+ (() => { throw new ParseError('Invalid Arguments'); })());
84
+ return ParseValue(operations, schema, references, value);
29
85
  }
@@ -12,6 +12,10 @@ export declare class TypeCheck<T extends TSchema> {
12
12
  constructor(schema: T, references: TSchema[], checkFunc: CheckFunction, code: string);
13
13
  /** Returns the generated assertion code used to validate this type. */
14
14
  Code(): string;
15
+ /** Returns the schema type used to validate */
16
+ Schema(): T;
17
+ /** Returns reference types used to validate */
18
+ References(): TSchema[];
15
19
  /** Returns an iterator for each error in this value. */
16
20
  Errors(value: unknown): ValueErrorIterator;
17
21
  /** Returns true if the value matches the compiled type. */
@@ -32,6 +32,14 @@ export class TypeCheck {
32
32
  Code() {
33
33
  return this.code;
34
34
  }
35
+ /** Returns the schema type used to validate */
36
+ Schema() {
37
+ return this.schema;
38
+ }
39
+ /** Returns reference types used to validate */
40
+ References() {
41
+ return this.references;
42
+ }
35
43
  /** Returns an iterator for each error in this value. */
36
44
  Errors(value) {
37
45
  return Errors(this.schema, this.references, value);
@@ -48,7 +48,7 @@ export declare const Module: Runtime.Module<{
48
48
  Iterator: Runtime.ITuple<Types.TIterator<Types.TSchema>>;
49
49
  Awaited: Runtime.ITuple<Types.TSchema>;
50
50
  Array: Runtime.ITuple<Types.TArray<Types.TSchema>>;
51
- Record: Runtime.ITuple<Types.TSchema>;
51
+ Record: Runtime.ITuple<Types.TNever>;
52
52
  Promise: Runtime.ITuple<Types.TPromise<Types.TSchema>>;
53
53
  ConstructorParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
54
54
  FunctionParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
@@ -5,8 +5,7 @@ import { Index } from './index.mjs';
5
5
  function FromProperties(type, properties, options) {
6
6
  const result = {};
7
7
  for (const K2 of Object.getOwnPropertyNames(properties)) {
8
- const keys = IndexPropertyKeys(properties[K2]);
9
- result[K2] = Index(type, keys, options);
8
+ result[K2] = Index(type, IndexPropertyKeys(properties[K2]), options);
10
9
  }
11
10
  return result;
12
11
  }