@sinclair/typebox 0.32.0-dev-18 → 0.32.0-dev-19

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 (78) hide show
  1. package/build/import/compiler/compiler.mjs +14 -8
  2. package/build/import/errors/errors.mjs +15 -11
  3. package/build/import/type/awaited/awaited.mjs +4 -4
  4. package/build/import/type/deref/deref.mjs +12 -12
  5. package/build/import/type/exclude/exclude.mjs +8 -5
  6. package/build/import/type/extends/extends-check.mjs +167 -167
  7. package/build/import/type/extends/extends.mjs +3 -3
  8. package/build/import/type/extract/extract.mjs +5 -5
  9. package/build/import/type/guard/type.d.mts +50 -50
  10. package/build/import/type/guard/type.mjs +136 -136
  11. package/build/import/type/indexed/indexed-property-keys.mjs +7 -7
  12. package/build/import/type/indexed/indexed.mjs +9 -9
  13. package/build/import/type/intersect/intersect-create.mjs +4 -4
  14. package/build/import/type/intersect/intersect-evaluated.mjs +1 -1
  15. package/build/import/type/intersect/intersect.mjs +2 -2
  16. package/build/import/type/intrinsic/intrinsic.mjs +5 -5
  17. package/build/import/type/keyof/keyof-property-keys.mjs +7 -7
  18. package/build/import/type/keyof/keyof.mjs +2 -2
  19. package/build/import/type/mapped/mapped.mjs +16 -16
  20. package/build/import/type/modifiers/modifiers.mjs +3 -3
  21. package/build/import/type/object/object.mjs +3 -3
  22. package/build/import/type/omit/omit.mjs +6 -6
  23. package/build/import/type/partial/partial.mjs +5 -5
  24. package/build/import/type/pick/pick.mjs +6 -6
  25. package/build/import/type/record/record.mjs +7 -7
  26. package/build/import/type/required/required.mjs +5 -5
  27. package/build/import/type/rest/rest.mjs +6 -2
  28. package/build/import/type/template-literal/pattern.mjs +9 -9
  29. package/build/import/type/transform/transform.mjs +1 -1
  30. package/build/import/type/union/union-evaluated.mjs +2 -2
  31. package/build/import/value/check/check.mjs +18 -11
  32. package/build/import/value/clean/clean.mjs +9 -7
  33. package/build/import/value/clone/clone.mjs +7 -4
  34. package/build/import/value/convert/convert.mjs +6 -2
  35. package/build/import/value/default/default.mjs +12 -4
  36. package/build/import/value/transform/decode.mjs +12 -6
  37. package/build/import/value/transform/encode.mjs +12 -6
  38. package/build/import/value/transform/has.mjs +24 -18
  39. package/build/require/compiler/compiler.js +77 -71
  40. package/build/require/errors/errors.js +58 -54
  41. package/build/require/type/awaited/awaited.js +3 -3
  42. package/build/require/type/deref/deref.js +11 -11
  43. package/build/require/type/exclude/exclude.js +7 -4
  44. package/build/require/type/extends/extends-check.js +167 -167
  45. package/build/require/type/extends/extends.js +2 -2
  46. package/build/require/type/extract/extract.js +4 -4
  47. package/build/require/type/guard/type.d.ts +50 -50
  48. package/build/require/type/guard/type.js +184 -184
  49. package/build/require/type/indexed/indexed-property-keys.js +6 -6
  50. package/build/require/type/indexed/indexed.js +9 -9
  51. package/build/require/type/intersect/intersect-create.js +3 -3
  52. package/build/require/type/intersect/intersect-evaluated.js +2 -2
  53. package/build/require/type/intersect/intersect.js +1 -1
  54. package/build/require/type/intrinsic/intrinsic.js +4 -4
  55. package/build/require/type/keyof/keyof-property-keys.js +6 -6
  56. package/build/require/type/keyof/keyof.js +1 -1
  57. package/build/require/type/mapped/mapped.js +15 -15
  58. package/build/require/type/modifiers/modifiers.js +2 -2
  59. package/build/require/type/object/object.js +2 -2
  60. package/build/require/type/omit/omit.js +5 -5
  61. package/build/require/type/partial/partial.js +4 -4
  62. package/build/require/type/pick/pick.js +5 -5
  63. package/build/require/type/record/record.js +6 -6
  64. package/build/require/type/required/required.js +4 -4
  65. package/build/require/type/rest/rest.js +5 -1
  66. package/build/require/type/template-literal/pattern.js +8 -8
  67. package/build/require/type/transform/transform.js +1 -1
  68. package/build/require/type/union/union-evaluated.js +1 -1
  69. package/build/require/value/check/check.js +63 -56
  70. package/build/require/value/clean/clean.js +31 -29
  71. package/build/require/value/clone/clone.js +7 -4
  72. package/build/require/value/convert/convert.js +42 -38
  73. package/build/require/value/default/default.js +24 -16
  74. package/build/require/value/transform/decode.js +27 -21
  75. package/build/require/value/transform/encode.js +28 -22
  76. package/build/require/value/transform/has.js +29 -23
  77. package/package.json +1 -1
  78. package/readme.md +5 -5
@@ -6,7 +6,7 @@ import { Union } from '../union/index.mjs';
6
6
  // TypeGuard
7
7
  // ------------------------------------------------------------------
8
8
  // prettier-ignore
9
- import { TMappedKey as IsMappedKeyType, TTemplateLiteral as IsTemplateLiteralType, TUnion as IsUnionType, TLiteral as IsLiteralType } from '../guard/type.mjs';
9
+ import { IsMappedKey, IsTemplateLiteral, IsUnion, IsLiteral } from '../guard/type.mjs';
10
10
  // ------------------------------------------------------------------
11
11
  // Apply
12
12
  // ------------------------------------------------------------------
@@ -54,10 +54,10 @@ export function Intrinsic(schema, mode, options = {}) {
54
54
  // prettier-ignore
55
55
  return (
56
56
  // Intrinsic-Mapped-Inference
57
- IsMappedKeyType(schema) ? IntrinsicFromMappedKey(schema, mode, options) :
57
+ IsMappedKey(schema) ? IntrinsicFromMappedKey(schema, mode, options) :
58
58
  // Standard-Inference
59
- IsTemplateLiteralType(schema) ? FromTemplateLiteral(schema, mode, schema) :
60
- IsUnionType(schema) ? Union(FromRest(schema.anyOf, mode), options) :
61
- IsLiteralType(schema) ? Literal(FromLiteralValue(schema.const, mode), options) :
59
+ IsTemplateLiteral(schema) ? FromTemplateLiteral(schema, mode, schema) :
60
+ IsUnion(schema) ? Union(FromRest(schema.anyOf, mode), options) :
61
+ IsLiteral(schema) ? Literal(FromLiteralValue(schema.const, mode), options) :
62
62
  schema);
63
63
  }
@@ -4,7 +4,7 @@ import { OperatorUnionMany, OperatorIntersectMany } from '../operators/index.mjs
4
4
  // TypeGuard
5
5
  // ------------------------------------------------------------------
6
6
  // prettier-ignore
7
- import { TIntersect as IsIntersectType, TUnion as IsUnionType, TTuple as IsTupleType, TArray as IsArrayType, TObject as IsObjectType, TRecord as IsRecordType } from '../guard/type.mjs';
7
+ import { IsIntersect, IsUnion, IsTuple, IsArray, IsObject, IsRecord } from '../guard/type.mjs';
8
8
  // prettier-ignore
9
9
  function FromRest(T) {
10
10
  const [L, ...R] = T;
@@ -53,12 +53,12 @@ function FromPatternProperties(patternProperties) {
53
53
  /** Returns a tuple of PropertyKeys derived from the given TSchema. */
54
54
  // prettier-ignore
55
55
  export function KeyOfPropertyKeys(T) {
56
- return (IsIntersectType(T) ? FromIntersect(T.allOf) :
57
- IsUnionType(T) ? FromUnion(T.anyOf) :
58
- IsTupleType(T) ? FromTuple(T.items ?? []) :
59
- IsArrayType(T) ? FromArray(T.items) :
60
- IsObjectType(T) ? FromProperties(T.properties) :
61
- IsRecordType(T) ? FromPatternProperties(T.patternProperties) :
56
+ return (IsIntersect(T) ? FromIntersect(T.allOf) :
57
+ IsUnion(T) ? FromUnion(T.anyOf) :
58
+ IsTuple(T) ? FromTuple(T.items ?? []) :
59
+ IsArray(T) ? FromArray(T.items) :
60
+ IsObject(T) ? FromProperties(T.properties) :
61
+ IsRecord(T) ? FromPatternProperties(T.patternProperties) :
62
62
  []);
63
63
  }
64
64
  // ----------------------------------------------------------------
@@ -8,7 +8,7 @@ import { KeyOfFromMappedResult } from './keyof-from-mapped-result.mjs';
8
8
  // TypeGuard
9
9
  // ------------------------------------------------------------------
10
10
  // prettier-ignore
11
- import { TMappedResult as IsMappedResultType } from '../guard/type.mjs';
11
+ import { IsMappedResult } from '../guard/type.mjs';
12
12
  // prettier-ignore
13
13
  function FromLiterals(T) {
14
14
  const [L, ...R] = T;
@@ -20,7 +20,7 @@ function FromLiterals(T) {
20
20
  }
21
21
  /** `[Json]` Creates a KeyOf type */
22
22
  export function KeyOf(T, options = {}) {
23
- if (IsMappedResultType(T)) {
23
+ if (IsMappedResult(T)) {
24
24
  return KeyOfFromMappedResult(T, options);
25
25
  }
26
26
  else {
@@ -22,7 +22,7 @@ import { MappedResult } from './mapped-result.mjs';
22
22
  // TypeGuard
23
23
  // ------------------------------------------------------------------
24
24
  // prettier-ignore
25
- import { TArray as IsArrayType, TAsyncIterator as IsAsyncIteratorType, TConstructor as IsConstructorType, TFunction as IsFunctionType, TIntersect as IsIntersectType, TIterator as IsIteratorType, TReadonly as IsReadonlyType, TMappedResult as IsMappedResultType, TMappedKey as IsMappedKeyType, TObject as IsObjectType, TOptional as IsOptionalType, TPromise as IsPromiseType, TSchema as IsSchemaType, TTuple as IsTupleType, TUnion as IsUnionType, } from '../guard/type.mjs';
25
+ import { IsArray, IsAsyncIterator, IsConstructor, IsFunction, IsIntersect, IsIterator, IsReadonly, IsMappedResult, IsMappedKey, IsObject, IsOptional, IsPromise, IsSchema, IsTuple, IsUnion, } from '../guard/type.mjs';
26
26
  // prettier-ignore
27
27
  function FromMappedResult(K, P) {
28
28
  return (K in P
@@ -58,22 +58,22 @@ function FromProperties(K, T) {
58
58
  function FromSchemaType(K, T) {
59
59
  return (
60
60
  // unevaluated modifier types
61
- IsOptionalType(T) ? Optional(FromSchemaType(K, Discard(T, [OptionalKind]))) :
62
- IsReadonlyType(T) ? Readonly(FromSchemaType(K, Discard(T, [ReadonlyKind]))) :
61
+ IsOptional(T) ? Optional(FromSchemaType(K, Discard(T, [OptionalKind]))) :
62
+ IsReadonly(T) ? Readonly(FromSchemaType(K, Discard(T, [ReadonlyKind]))) :
63
63
  // unevaluated mapped types
64
- IsMappedResultType(T) ? FromMappedResult(K, T.properties) :
65
- IsMappedKeyType(T) ? FromMappedKey(K, T.keys) :
64
+ IsMappedResult(T) ? FromMappedResult(K, T.properties) :
65
+ IsMappedKey(T) ? FromMappedKey(K, T.keys) :
66
66
  // unevaluated types
67
- IsConstructorType(T) ? Constructor(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
68
- IsFunctionType(T) ? FunctionType(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
69
- IsAsyncIteratorType(T) ? AsyncIterator(FromSchemaType(K, T.items)) :
70
- IsIteratorType(T) ? Iterator(FromSchemaType(K, T.items)) :
71
- IsIntersectType(T) ? Intersect(FromRest(K, T.allOf)) :
72
- IsUnionType(T) ? Union(FromRest(K, T.anyOf)) :
73
- IsTupleType(T) ? Tuple(FromRest(K, T.items ?? [])) :
74
- IsObjectType(T) ? Object(FromProperties(K, T.properties)) :
75
- IsArrayType(T) ? Array(FromSchemaType(K, T.items)) :
76
- IsPromiseType(T) ? Promise(FromSchemaType(K, T.item)) :
67
+ IsConstructor(T) ? Constructor(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
68
+ IsFunction(T) ? FunctionType(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
69
+ IsAsyncIterator(T) ? AsyncIterator(FromSchemaType(K, T.items)) :
70
+ IsIterator(T) ? Iterator(FromSchemaType(K, T.items)) :
71
+ IsIntersect(T) ? Intersect(FromRest(K, T.allOf)) :
72
+ IsUnion(T) ? Union(FromRest(K, T.anyOf)) :
73
+ IsTuple(T) ? Tuple(FromRest(K, T.items ?? [])) :
74
+ IsObject(T) ? Object(FromProperties(K, T.properties)) :
75
+ IsArray(T) ? Array(FromSchemaType(K, T.items)) :
76
+ IsPromise(T) ? Promise(FromSchemaType(K, T.item)) :
77
77
  T);
78
78
  }
79
79
  // prettier-ignore
@@ -85,7 +85,7 @@ function FromMappedFunctionReturnType(K, T) {
85
85
  }
86
86
  /** `[Json]` Creates a Mapped object type */
87
87
  export function Mapped(key, map, options = {}) {
88
- const K = IsSchemaType(key) ? IndexPropertyKeys(key) : key;
88
+ const K = IsSchema(key) ? IndexPropertyKeys(key) : key;
89
89
  const RT = map({ [Kind]: 'MappedKey', keys: K });
90
90
  const R = FromMappedFunctionReturnType(K, RT);
91
91
  return CloneType(Object(R), options);
@@ -7,12 +7,12 @@ import { OptionalKind } from '../symbols/index.mjs';
7
7
  // TypeGuard
8
8
  // ------------------------------------------------------------------
9
9
  // prettier-ignore
10
- import { TOptional as IsOptionalType } from '../guard/type.mjs';
10
+ import { IsOptional } from '../guard/type.mjs';
11
11
  // prettier-ignore
12
12
  function IsOptionalFromIntersect(T) {
13
13
  const [L, ...R] = T;
14
14
  return (T.length > 0
15
- ? IsOptionalType(L)
15
+ ? IsOptional(L)
16
16
  ? IsOptionalFromIntersect(R)
17
17
  : false
18
18
  : true);
@@ -21,7 +21,7 @@ function IsOptionalFromIntersect(T) {
21
21
  function IsOptionalFromUnion(T) {
22
22
  const [L, ...R] = T;
23
23
  return (T.length > 0
24
- ? IsOptionalType(L)
24
+ ? IsOptional(L)
25
25
  ? true
26
26
  : IsOptionalFromUnion(R)
27
27
  : false);
@@ -4,13 +4,13 @@ import { Kind } from '../symbols/index.mjs';
4
4
  // TypeGuard
5
5
  // ------------------------------------------------------------------
6
6
  // prettier-ignore
7
- import { TOptional as IsOptionalType, TSchema as IsSchemaType } from '../guard/type.mjs';
7
+ import { IsOptional, IsSchema } from '../guard/type.mjs';
8
8
  /** `[Json]` Creates an Object type */
9
9
  export function _Object(properties, options = {}) {
10
10
  const propertyKeys = globalThis.Object.getOwnPropertyNames(properties);
11
- const optionalKeys = propertyKeys.filter((key) => IsOptionalType(properties[key]));
11
+ const optionalKeys = propertyKeys.filter((key) => IsOptional(properties[key]));
12
12
  const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
13
- const clonedAdditionalProperties = IsSchemaType(options.additionalProperties) ? { additionalProperties: CloneType(options.additionalProperties) } : {};
13
+ const clonedAdditionalProperties = IsSchema(options.additionalProperties) ? { additionalProperties: CloneType(options.additionalProperties) } : {};
14
14
  const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: CloneType(properties[key]) }), {});
15
15
  return (requiredKeys.length > 0
16
16
  ? { ...options, ...clonedAdditionalProperties, [Kind]: 'Object', type: 'object', properties: clonedProperties, required: requiredKeys }
@@ -10,7 +10,7 @@ import { OmitFromMappedKey } from './omit-from-mapped-key.mjs';
10
10
  // TypeGuard
11
11
  // ------------------------------------------------------------------
12
12
  // prettier-ignore
13
- import { TMappedKey as IsMappedKeyType, TIntersect as IsIntersectType, TUnion as IsUnionType, TObject as IsObjectType, TSchema as IsSchemaType } from '../guard/type.mjs';
13
+ import { IsMappedKey, IsIntersect, IsUnion, IsObject, IsSchema } from '../guard/type.mjs';
14
14
  // prettier-ignore
15
15
  function FromIntersect(T, K) {
16
16
  return T.map((T) => OmitResolve(T, K));
@@ -35,17 +35,17 @@ function FromProperties(T, K) {
35
35
  }
36
36
  // prettier-ignore
37
37
  export function OmitResolve(T, K) {
38
- return (IsIntersectType(T) ? Intersect(FromIntersect(T.allOf, K)) :
39
- IsUnionType(T) ? Union(FromUnion(T.anyOf, K)) :
40
- IsObjectType(T) ? Object(FromProperties(T.properties, K)) :
38
+ return (IsIntersect(T) ? Intersect(FromIntersect(T.allOf, K)) :
39
+ IsUnion(T) ? Union(FromUnion(T.anyOf, K)) :
40
+ IsObject(T) ? Object(FromProperties(T.properties, K)) :
41
41
  Object({}));
42
42
  }
43
43
  export function Omit(T, K, options = {}) {
44
- if (IsMappedKeyType(K)) {
44
+ if (IsMappedKey(K)) {
45
45
  return OmitFromMappedKey(T, K, options);
46
46
  }
47
47
  else {
48
- const I = IsSchemaType(K) ? IndexPropertyKeys(K) : K;
48
+ const I = IsSchema(K) ? IndexPropertyKeys(K) : K;
49
49
  const D = Discard(T, [TransformKind, '$id', 'required']);
50
50
  const R = CloneType(OmitResolve(T, I), options);
51
51
  return { ...D, ...R };
@@ -10,7 +10,7 @@ import { PartialFromMappedResult } from './partial-from-mapped-result.mjs';
10
10
  // TypeGuard
11
11
  // ------------------------------------------------------------------
12
12
  // prettier-ignore
13
- import { TMappedResult as IsMappedResultType, TIntersect as IsIntersectType, TUnion as IsUnionType, TObject as IsObjectType } from '../guard/type.mjs';
13
+ import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/type.mjs';
14
14
  // prettier-ignore
15
15
  function FromIntersect(T) {
16
16
  const [L, ...R] = T;
@@ -33,14 +33,14 @@ function FromProperties(T) {
33
33
  }
34
34
  // prettier-ignore
35
35
  function PartialResolve(T) {
36
- return (IsIntersectType(T) ? Intersect(FromIntersect(T.allOf)) :
37
- IsUnionType(T) ? Union(FromUnion(T.anyOf)) :
38
- IsObjectType(T) ? Object(FromProperties(T.properties)) :
36
+ return (IsIntersect(T) ? Intersect(FromIntersect(T.allOf)) :
37
+ IsUnion(T) ? Union(FromUnion(T.anyOf)) :
38
+ IsObject(T) ? Object(FromProperties(T.properties)) :
39
39
  Object({}));
40
40
  }
41
41
  /** `[Json]` Constructs a type where all properties are optional */
42
42
  export function Partial(T, options = {}) {
43
- if (IsMappedResultType(T)) {
43
+ if (IsMappedResult(T)) {
44
44
  return PartialFromMappedResult(T, options);
45
45
  }
46
46
  else {
@@ -10,7 +10,7 @@ import { PickFromMappedKey } from './pick-from-mapped-key.mjs';
10
10
  // TypeGuard
11
11
  // ------------------------------------------------------------------
12
12
  // prettier-ignore
13
- import { TMappedKey as IsMappedKeyType, TIntersect as IsIntersectType, TUnion as IsUnionType, TObject as IsObjectType, TSchema as IsSchemaType, } from '../guard/type.mjs';
13
+ import { IsMappedKey, IsIntersect, IsUnion, IsObject, IsSchema, } from '../guard/type.mjs';
14
14
  function FromIntersect(T, K) {
15
15
  return T.map((T) => PickResolve(T, K));
16
16
  }
@@ -26,17 +26,17 @@ function FromProperties(T, K) {
26
26
  }
27
27
  // prettier-ignore
28
28
  export function PickResolve(T, K) {
29
- return (IsIntersectType(T) ? Intersect(FromIntersect(T.allOf, K)) :
30
- IsUnionType(T) ? Union(FromUnion(T.anyOf, K)) :
31
- IsObjectType(T) ? Object(FromProperties(T.properties, K)) :
29
+ return (IsIntersect(T) ? Intersect(FromIntersect(T.allOf, K)) :
30
+ IsUnion(T) ? Union(FromUnion(T.anyOf, K)) :
31
+ IsObject(T) ? Object(FromProperties(T.properties, K)) :
32
32
  Object({}));
33
33
  }
34
34
  export function Pick(T, K, options = {}) {
35
- if (IsMappedKeyType(K)) {
35
+ if (IsMappedKey(K)) {
36
36
  return PickFromMappedKey(T, K, options);
37
37
  }
38
38
  else {
39
- const I = IsSchemaType(K) ? IndexPropertyKeys(K) : K;
39
+ const I = IsSchema(K) ? IndexPropertyKeys(K) : K;
40
40
  const D = Discard(T, [TransformKind, '$id', 'required']);
41
41
  const R = CloneType(PickResolve(T, I), options);
42
42
  return { ...D, ...R };
@@ -11,7 +11,7 @@ import { IsUndefined } from '../guard/value.mjs';
11
11
  // TypeGuard
12
12
  // ------------------------------------------------------------------
13
13
  // prettier-ignore
14
- import { TInteger as IsIntegerType, TLiteral as IsLiteralType, TNumber as IsNumberType, TString as IsStringType, TTemplateLiteral as IsTemplateLiteralType, TUnion as IsUnionType, } from '../guard/type.mjs';
14
+ import { IsInteger, IsLiteral, IsNumber, IsString, IsTemplateLiteral, IsUnion } from '../guard/type.mjs';
15
15
  // ------------------------------------------------------------------
16
16
  // RecordCreateFromPattern
17
17
  // ------------------------------------------------------------------
@@ -66,11 +66,11 @@ function FromNumberKey(_, T, options) {
66
66
  /** `[Json]` Creates a Record type */
67
67
  export function Record(K, T, options = {}) {
68
68
  // prettier-ignore
69
- return (IsUnionType(K) ? FromUnionKey(K.anyOf, T, options) :
70
- IsTemplateLiteralType(K) ? FromTemplateLiteralKey(K, T, options) :
71
- IsLiteralType(K) ? FromLiteralKey(K.const, T, options) :
72
- IsStringType(K) ? FromStringKey(K, T, options) :
73
- IsIntegerType(K) ? FromIntegerKey(K, T, options) :
74
- IsNumberType(K) ? FromNumberKey(K, T, options) :
69
+ return (IsUnion(K) ? FromUnionKey(K.anyOf, T, options) :
70
+ IsTemplateLiteral(K) ? FromTemplateLiteralKey(K, T, options) :
71
+ IsLiteral(K) ? FromLiteralKey(K.const, T, options) :
72
+ IsString(K) ? FromStringKey(K, T, options) :
73
+ IsInteger(K) ? FromIntegerKey(K, T, options) :
74
+ IsNumber(K) ? FromNumberKey(K, T, options) :
75
75
  Never(options));
76
76
  }
@@ -9,7 +9,7 @@ import { RequiredFromMappedResult } from './required-from-mapped-result.mjs';
9
9
  // TypeGuard
10
10
  // ------------------------------------------------------------------
11
11
  // prettier-ignore
12
- import { TMappedResult as IsMappedResultType, TIntersect as IsIntersectType, TUnion as IsUnionType, TObject as IsObjectType } from '../guard/type.mjs';
12
+ import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/type.mjs';
13
13
  // prettier-ignore
14
14
  function FromIntersect(T) {
15
15
  const [L, ...R] = T;
@@ -32,14 +32,14 @@ function FromProperties(T) {
32
32
  }
33
33
  // prettier-ignore
34
34
  function RequiredResolve(T) {
35
- return (IsIntersectType(T) ? Intersect(FromIntersect(T.allOf)) :
36
- IsUnionType(T) ? Union(FromUnion(T.anyOf)) :
37
- IsObjectType(T) ? Object(FromProperties(T.properties)) :
35
+ return (IsIntersect(T) ? Intersect(FromIntersect(T.allOf)) :
36
+ IsUnion(T) ? Union(FromUnion(T.anyOf)) :
37
+ IsObject(T) ? Object(FromProperties(T.properties)) :
38
38
  Object({}));
39
39
  }
40
40
  /** `[Json]` Constructs a type where all properties are required */
41
41
  export function Required(T, options = {}) {
42
- if (IsMappedResultType(T)) {
42
+ if (IsMappedResult(T)) {
43
43
  return RequiredFromMappedResult(T, options);
44
44
  }
45
45
  else {
@@ -3,9 +3,13 @@ import { CloneRest } from '../clone/type.mjs';
3
3
  // TypeGuard
4
4
  // ------------------------------------------------------------------
5
5
  // prettier-ignore
6
- import { TIntersect as IsIntersectType, TUnion as IsUnionType, TTuple as IsTupleType } from '../guard/type.mjs';
6
+ import { IsIntersect, IsUnion, IsTuple } from '../guard/type.mjs';
7
+ // prettier-ignore
7
8
  export function RestResolve(T) {
8
- return (IsIntersectType(T) ? [...T.allOf] : IsUnionType(T) ? [...T.anyOf] : IsTupleType(T) ? [...(T.items ?? [])] : []);
9
+ return (IsIntersect(T) ? [...T.allOf] :
10
+ IsUnion(T) ? [...T.anyOf] :
11
+ IsTuple(T) ? [...(T.items ?? [])] :
12
+ []);
9
13
  }
10
14
  /** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
11
15
  export function Rest(T) {
@@ -4,7 +4,7 @@ import { Kind } from '../symbols/index.mjs';
4
4
  // TypeGuard
5
5
  // ------------------------------------------------------------------
6
6
  // prettier-ignore
7
- import { TTemplateLiteral as IsTemplateLiteralType, TUnion as IsUnionType, TNumber as IsNumberType, TInteger as IsIntegerType, TBigInt as IsBigIntType, TString as IsStringType, TLiteral as IsLiteralType, TBoolean as IsBooleanType, } from '../guard/type.mjs';
7
+ import { IsTemplateLiteral, IsUnion, IsNumber, IsInteger, IsBigInt, IsString, IsLiteral, IsBoolean } from '../guard/type.mjs';
8
8
  // ------------------------------------------------------------------
9
9
  // TemplateLiteralPatternError
10
10
  // ------------------------------------------------------------------
@@ -18,14 +18,14 @@ function Escape(value) {
18
18
  }
19
19
  // prettier-ignore
20
20
  function Visit(schema, acc) {
21
- return (IsTemplateLiteralType(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) :
22
- IsUnionType(schema) ? `(${schema.anyOf.map((schema) => Visit(schema, acc)).join('|')})` :
23
- IsNumberType(schema) ? `${acc}${PatternNumber}` :
24
- IsIntegerType(schema) ? `${acc}${PatternNumber}` :
25
- IsBigIntType(schema) ? `${acc}${PatternNumber}` :
26
- IsStringType(schema) ? `${acc}${PatternString}` :
27
- IsLiteralType(schema) ? `${acc}${Escape(schema.const.toString())}` :
28
- IsBooleanType(schema) ? `${acc}${PatternBoolean}` :
21
+ return (IsTemplateLiteral(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) :
22
+ IsUnion(schema) ? `(${schema.anyOf.map((schema) => Visit(schema, acc)).join('|')})` :
23
+ IsNumber(schema) ? `${acc}${PatternNumber}` :
24
+ IsInteger(schema) ? `${acc}${PatternNumber}` :
25
+ IsBigInt(schema) ? `${acc}${PatternNumber}` :
26
+ IsString(schema) ? `${acc}${PatternString}` :
27
+ IsLiteral(schema) ? `${acc}${Escape(schema.const.toString())}` :
28
+ IsBoolean(schema) ? `${acc}${PatternBoolean}` :
29
29
  (() => { throw new TemplateLiteralPatternError(`Unexpected Kind '${schema[Kind]}'`); })());
30
30
  }
31
31
  export function TemplateLiteralPattern(kinds) {
@@ -4,7 +4,7 @@ import { TransformKind } from '../symbols/index.mjs';
4
4
  // TypeGuard
5
5
  // ------------------------------------------------------------------
6
6
  // prettier-ignore
7
- import { TTransform as IsTransform } from '../guard/type.mjs';
7
+ import { IsTransform } from '../guard/type.mjs';
8
8
  // ------------------------------------------------------------------
9
9
  // TransformBuilders
10
10
  // ------------------------------------------------------------------
@@ -8,12 +8,12 @@ import { UnionCreate } from './union-create.mjs';
8
8
  // TypeGuard
9
9
  // ------------------------------------------------------------------
10
10
  // prettier-ignore
11
- import { TOptional as IsOptionalType } from '../guard/type.mjs';
11
+ import { IsOptional } from '../guard/type.mjs';
12
12
  // prettier-ignore
13
13
  function IsUnionOptional(T) {
14
14
  const [L, ...R] = T;
15
15
  return (T.length > 0
16
- ? IsOptionalType(L)
16
+ ? IsOptional(L)
17
17
  ? true
18
18
  : IsUnionOptional(R)
19
19
  : false);
@@ -1,16 +1,23 @@
1
- import { IsArray, IsUint8Array, IsDate, IsPromise, IsFunction, IsAsyncIterator, IsIterator, IsBoolean, IsNumber, IsBigInt, IsString, IsSymbol, IsInteger, IsNull, IsUndefined } from '../guard/index.mjs';
2
1
  import { TypeSystemPolicy } from '../../system/index.mjs';
3
2
  import { Deref } from '../deref/index.mjs';
4
3
  import { Hash } from '../hash/index.mjs';
5
4
  import { Kind } from '../../type/symbols/index.mjs';
6
5
  import { KeyOfPattern } from '../../type/keyof/index.mjs';
7
6
  import { ExtendsUndefinedCheck } from '../../type/extends/index.mjs';
8
- import { TSchema as IsSchemaType } from '../../type/guard/type.mjs';
9
7
  import { TypeRegistry, FormatRegistry } from '../../type/registry/index.mjs';
10
8
  import { Never } from '../../type/never/index.mjs';
11
- // --------------------------------------------------------------------------
9
+ // ------------------------------------------------------------------
10
+ // ValueGuard
11
+ // ------------------------------------------------------------------
12
+ // prettier-ignore
13
+ import { IsArray, IsUint8Array, IsDate, IsPromise, IsFunction, IsAsyncIterator, IsIterator, IsBoolean, IsNumber, IsBigInt, IsString, IsSymbol, IsInteger, IsNull, IsUndefined } from '../guard/index.mjs';
14
+ // ------------------------------------------------------------------
15
+ // TypeGuard
16
+ // ------------------------------------------------------------------
17
+ import { IsSchema } from '../../type/guard/type.mjs';
18
+ // ------------------------------------------------------------------
12
19
  // Errors
13
- // --------------------------------------------------------------------------
20
+ // ------------------------------------------------------------------
14
21
  export class ValueCheckUnknownTypeError extends Error {
15
22
  schema;
16
23
  constructor(schema) {
@@ -18,21 +25,21 @@ export class ValueCheckUnknownTypeError extends Error {
18
25
  this.schema = schema;
19
26
  }
20
27
  }
21
- // --------------------------------------------------------------------------
28
+ // ------------------------------------------------------------------
22
29
  // TypeGuards
23
- // --------------------------------------------------------------------------
30
+ // ------------------------------------------------------------------
24
31
  function IsAnyOrUnknown(schema) {
25
32
  return schema[Kind] === 'Any' || schema[Kind] === 'Unknown';
26
33
  }
27
- // --------------------------------------------------------------------------
34
+ // ------------------------------------------------------------------
28
35
  // Guards
29
- // --------------------------------------------------------------------------
36
+ // ------------------------------------------------------------------
30
37
  function IsDefined(value) {
31
38
  return value !== undefined;
32
39
  }
33
- // --------------------------------------------------------------------------
40
+ // ------------------------------------------------------------------
34
41
  // Types
35
- // --------------------------------------------------------------------------
42
+ // ------------------------------------------------------------------
36
43
  function TAny(schema, references, value) {
37
44
  return true;
38
45
  }
@@ -157,7 +164,7 @@ function TIntersect(schema, references, value) {
157
164
  const check2 = Object.getOwnPropertyNames(value).every((key) => keyPattern.test(key));
158
165
  return check1 && check2;
159
166
  }
160
- else if (IsSchemaType(schema.unevaluatedProperties)) {
167
+ else if (IsSchema(schema.unevaluatedProperties)) {
161
168
  const keyCheck = new RegExp(KeyOfPattern(schema));
162
169
  const check2 = Object.getOwnPropertyNames(value).every((key) => keyCheck.test(key) || Visit(schema.unevaluatedProperties, references, value[key]));
163
170
  return check1 && check2;
@@ -1,21 +1,23 @@
1
- import { IsString, IsObject, IsArray, IsUndefined } from '../guard/index.mjs';
2
- import { TSchema as IsSchemaType } from '../../type/guard/type.mjs';
3
1
  import { KeyOfPropertyKeys } from '../../type/keyof/index.mjs';
4
2
  import { Check } from '../check/index.mjs';
5
3
  import { Clone } from '../clone/index.mjs';
6
4
  import { Deref } from '../deref/index.mjs';
7
5
  import { Kind } from '../../type/symbols/index.mjs';
8
6
  // ------------------------------------------------------------------
9
- // IsSchema
7
+ // ValueGuard
10
8
  // ------------------------------------------------------------------
11
- function IsSchema(schema) {
12
- return IsSchemaType(schema);
13
- }
9
+ // prettier-ignore
10
+ import { IsString, IsObject, IsArray, IsUndefined } from '../guard/index.mjs';
11
+ // ------------------------------------------------------------------
12
+ // TypeGuard
13
+ // ------------------------------------------------------------------
14
+ // prettier-ignore
15
+ import { IsSchema } from '../../type/guard/type.mjs';
14
16
  // ------------------------------------------------------------------
15
17
  // IsCheckable
16
18
  // ------------------------------------------------------------------
17
19
  function IsCheckable(schema) {
18
- return IsSchemaType(schema) && schema[Kind] !== 'Unsafe';
20
+ return IsSchema(schema) && schema[Kind] !== 'Unsafe';
19
21
  }
20
22
  // ------------------------------------------------------------------
21
23
  // Types
@@ -1,7 +1,10 @@
1
+ // ------------------------------------------------------------------
2
+ // ValueGuard
3
+ // ------------------------------------------------------------------
1
4
  import { IsArray, IsDate, IsPlainObject, IsTypedArray, IsValueType } from '../guard/index.mjs';
2
- // --------------------------------------------------------------------------
5
+ // ------------------------------------------------------------------
3
6
  // Clonable
4
- // --------------------------------------------------------------------------
7
+ // ------------------------------------------------------------------
5
8
  function ObjectType(value) {
6
9
  const keys = [...Object.getOwnPropertyNames(value), ...Object.getOwnPropertySymbols(value)];
7
10
  return keys.reduce((acc, key) => ({ ...acc, [key]: Clone(value[key]) }), {});
@@ -18,9 +21,9 @@ function DateType(value) {
18
21
  function ValueType(value) {
19
22
  return value;
20
23
  }
21
- // --------------------------------------------------------------------------
24
+ // ------------------------------------------------------------------
22
25
  // Clone
23
- // --------------------------------------------------------------------------
26
+ // ------------------------------------------------------------------
24
27
  /** Returns a clone of the given value */
25
28
  export function Clone(value) {
26
29
  if (IsArray(value))
@@ -1,11 +1,15 @@
1
- import { IsArray, IsObject, IsDate, IsUndefined, IsString, IsNumber, IsBoolean, IsBigInt, IsSymbol } from '../guard/index.mjs';
2
1
  import { Clone } from '../clone/index.mjs';
3
2
  import { Check } from '../check/index.mjs';
4
3
  import { Deref } from '../deref/index.mjs';
5
- import { TObject as IsObjectType } from '../../type/guard/type.mjs';
4
+ import { IsObject as IsObjectType } from '../../type/guard/type.mjs';
6
5
  import { Kind } from '../../type/symbols/index.mjs';
7
6
  import { Composite } from '../../type/composite/index.mjs';
8
7
  // ------------------------------------------------------------------
8
+ // ValueGuard
9
+ // ------------------------------------------------------------------
10
+ // prettier-ignore
11
+ import { IsArray, IsObject, IsDate, IsUndefined, IsString, IsNumber, IsBoolean, IsBigInt, IsSymbol } from '../guard/index.mjs';
12
+ // ------------------------------------------------------------------
9
13
  // Errors
10
14
  // ------------------------------------------------------------------
11
15
  export class ValueConvertUnknownTypeError extends Error {
@@ -1,9 +1,17 @@
1
- import { IsString, IsObject, IsArray, IsUndefined } from '../guard/index.mjs';
2
- import { TSchema as IsSchemaType } from '../../type/guard/type.mjs';
3
1
  import { Check } from '../check/index.mjs';
4
2
  import { Deref } from '../deref/index.mjs';
5
3
  import { Kind } from '../../type/symbols/index.mjs';
6
4
  // ------------------------------------------------------------------
5
+ // ValueGuard
6
+ // ------------------------------------------------------------------
7
+ // prettier-ignore
8
+ import { IsString, IsObject, IsArray, IsUndefined } from '../guard/index.mjs';
9
+ // ------------------------------------------------------------------
10
+ // TypeGuard
11
+ // ------------------------------------------------------------------
12
+ // prettier-ignore
13
+ import { IsSchema } from '../../type/guard/type.mjs';
14
+ // ------------------------------------------------------------------
7
15
  // ValueOrDefault
8
16
  // ------------------------------------------------------------------
9
17
  function ValueOrDefault(schema, value) {
@@ -13,13 +21,13 @@ function ValueOrDefault(schema, value) {
13
21
  // IsCheckable
14
22
  // ------------------------------------------------------------------
15
23
  function IsCheckable(schema) {
16
- return IsSchemaType(schema) && schema[Kind] !== 'Unsafe';
24
+ return IsSchema(schema) && schema[Kind] !== 'Unsafe';
17
25
  }
18
26
  // ------------------------------------------------------------------
19
27
  // IsDefaultSchema
20
28
  // ------------------------------------------------------------------
21
29
  function IsDefaultSchema(value) {
22
- return IsSchemaType(value) && 'default' in value;
30
+ return IsSchema(value) && 'default' in value;
23
31
  }
24
32
  // ------------------------------------------------------------------
25
33
  // Types