@sinclair/typebox 0.32.35 → 0.33.0

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 (209) hide show
  1. package/build/cjs/index.d.ts +1 -0
  2. package/build/cjs/index.js +1 -0
  3. package/build/cjs/system/policy.d.ts +9 -1
  4. package/build/cjs/system/policy.js +13 -2
  5. package/build/cjs/type/any/any.js +4 -3
  6. package/build/cjs/type/array/array.d.ts +1 -1
  7. package/build/cjs/type/array/array.js +3 -8
  8. package/build/cjs/type/async-iterator/async-iterator.js +3 -8
  9. package/build/cjs/type/awaited/awaited.js +3 -3
  10. package/build/cjs/type/bigint/bigint.js +3 -6
  11. package/build/cjs/type/boolean/boolean.js +3 -6
  12. package/build/cjs/type/clone/type.d.ts +1 -1
  13. package/build/cjs/type/clone/type.js +2 -2
  14. package/build/cjs/type/composite/composite.js +1 -1
  15. package/build/cjs/type/const/const.js +3 -3
  16. package/build/cjs/type/constructor/constructor.js +2 -8
  17. package/build/cjs/type/constructor-parameters/constructor-parameters.js +2 -3
  18. package/build/cjs/type/create/immutable.d.ts +2 -0
  19. package/build/cjs/type/create/immutable.js +41 -0
  20. package/build/cjs/type/create/index.d.ts +1 -0
  21. package/build/cjs/type/create/index.js +18 -0
  22. package/build/cjs/type/create/type.d.ts +3 -0
  23. package/build/cjs/type/create/type.js +19 -0
  24. package/build/cjs/type/date/date.js +3 -6
  25. package/build/cjs/type/discard/discard.d.ts +1 -0
  26. package/build/cjs/type/discard/discard.js +1 -0
  27. package/build/cjs/type/enum/enum.js +1 -1
  28. package/build/cjs/type/exclude/exclude.js +4 -4
  29. package/build/cjs/type/extends/extends-from-mapped-key.d.ts +1 -1
  30. package/build/cjs/type/extends/extends-from-mapped-key.js +2 -1
  31. package/build/cjs/type/extends/extends-from-mapped-result.d.ts +1 -1
  32. package/build/cjs/type/extends/extends-from-mapped-result.js +2 -1
  33. package/build/cjs/type/extends/extends.js +4 -4
  34. package/build/cjs/type/extract/extract.js +5 -5
  35. package/build/cjs/type/function/function.js +2 -8
  36. package/build/cjs/type/guard/value.js +3 -0
  37. package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +1 -1
  38. package/build/cjs/type/indexed/indexed-from-mapped-key.js +2 -1
  39. package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +1 -1
  40. package/build/cjs/type/indexed/indexed.js +10 -6
  41. package/build/cjs/type/instance-type/instance-type.js +3 -3
  42. package/build/cjs/type/integer/integer.js +3 -6
  43. package/build/cjs/type/intersect/intersect-create.d.ts +1 -1
  44. package/build/cjs/type/intersect/intersect-create.js +6 -6
  45. package/build/cjs/type/intersect/intersect-evaluated.js +2 -2
  46. package/build/cjs/type/intersect/intersect.js +3 -3
  47. package/build/cjs/type/intrinsic/intrinsic-from-mapped-key.js +4 -2
  48. package/build/cjs/type/intrinsic/intrinsic.js +3 -1
  49. package/build/cjs/type/iterator/iterator.js +3 -8
  50. package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +1 -1
  51. package/build/cjs/type/keyof/keyof-from-mapped-result.js +2 -1
  52. package/build/cjs/type/keyof/keyof.js +3 -3
  53. package/build/cjs/type/literal/literal.js +4 -4
  54. package/build/cjs/type/mapped/mapped-key.js +3 -2
  55. package/build/cjs/type/mapped/mapped-result.js +3 -2
  56. package/build/cjs/type/mapped/mapped.js +2 -3
  57. package/build/cjs/type/never/never.js +3 -6
  58. package/build/cjs/type/not/not.d.ts +1 -1
  59. package/build/cjs/type/not/not.js +3 -7
  60. package/build/cjs/type/null/null.js +3 -6
  61. package/build/cjs/type/number/number.js +3 -6
  62. package/build/cjs/type/object/object.js +13 -12
  63. package/build/cjs/type/omit/omit-from-mapped-key.d.ts +1 -1
  64. package/build/cjs/type/omit/omit-from-mapped-key.js +2 -1
  65. package/build/cjs/type/omit/omit-from-mapped-result.d.ts +1 -1
  66. package/build/cjs/type/omit/omit-from-mapped-result.js +2 -1
  67. package/build/cjs/type/omit/omit.js +4 -4
  68. package/build/cjs/type/optional/optional.js +3 -3
  69. package/build/cjs/type/parameters/parameters.js +2 -3
  70. package/build/cjs/type/partial/partial-from-mapped-result.d.ts +1 -1
  71. package/build/cjs/type/partial/partial-from-mapped-result.js +2 -1
  72. package/build/cjs/type/partial/partial.js +4 -4
  73. package/build/cjs/type/pick/pick-from-mapped-key.d.ts +1 -1
  74. package/build/cjs/type/pick/pick-from-mapped-key.js +2 -1
  75. package/build/cjs/type/pick/pick-from-mapped-result.d.ts +1 -1
  76. package/build/cjs/type/pick/pick-from-mapped-result.js +2 -1
  77. package/build/cjs/type/pick/pick.js +4 -4
  78. package/build/cjs/type/promise/promise.js +3 -8
  79. package/build/cjs/type/readonly/readonly.js +3 -3
  80. package/build/cjs/type/record/record.js +5 -6
  81. package/build/cjs/type/recursive/recursive.js +3 -2
  82. package/build/cjs/type/ref/ref.js +4 -7
  83. package/build/cjs/type/regexp/regexp.js +3 -2
  84. package/build/cjs/type/required/required-from-mapped-result.d.ts +1 -1
  85. package/build/cjs/type/required/required.js +4 -4
  86. package/build/cjs/type/rest/rest.d.ts +1 -1
  87. package/build/cjs/type/rest/rest.js +4 -5
  88. package/build/cjs/type/return-type/return-type.js +3 -3
  89. package/build/cjs/type/string/string.js +3 -2
  90. package/build/cjs/type/symbol/symbol.js +2 -1
  91. package/build/cjs/type/template-literal/template-literal.js +3 -2
  92. package/build/cjs/type/transform/transform.js +1 -3
  93. package/build/cjs/type/tuple/tuple.js +5 -7
  94. package/build/cjs/type/type/javascript.js +13 -13
  95. package/build/cjs/type/type/json.js +35 -35
  96. package/build/cjs/type/uint8array/uint8array.js +3 -2
  97. package/build/cjs/type/undefined/undefined.js +3 -2
  98. package/build/cjs/type/union/union-create.d.ts +1 -1
  99. package/build/cjs/type/union/union-create.js +2 -2
  100. package/build/cjs/type/union/union-evaluated.js +3 -3
  101. package/build/cjs/type/union/union.js +3 -3
  102. package/build/cjs/type/unknown/unknown.js +3 -5
  103. package/build/cjs/type/unsafe/unsafe.js +2 -4
  104. package/build/cjs/type/void/void.js +3 -6
  105. package/build/esm/index.d.mts +1 -0
  106. package/build/esm/index.mjs +1 -0
  107. package/build/esm/system/policy.d.mts +9 -1
  108. package/build/esm/system/policy.mjs +13 -2
  109. package/build/esm/type/any/any.mjs +3 -2
  110. package/build/esm/type/array/array.d.mts +1 -1
  111. package/build/esm/type/array/array.mjs +3 -8
  112. package/build/esm/type/async-iterator/async-iterator.mjs +3 -8
  113. package/build/esm/type/awaited/awaited.mjs +3 -3
  114. package/build/esm/type/bigint/bigint.mjs +3 -6
  115. package/build/esm/type/boolean/boolean.mjs +3 -6
  116. package/build/esm/type/clone/type.d.mts +1 -1
  117. package/build/esm/type/clone/type.mjs +2 -2
  118. package/build/esm/type/composite/composite.mjs +1 -1
  119. package/build/esm/type/const/const.mjs +3 -3
  120. package/build/esm/type/constructor/constructor.mjs +2 -8
  121. package/build/esm/type/constructor-parameters/constructor-parameters.mjs +2 -3
  122. package/build/esm/type/create/immutable.d.mts +2 -0
  123. package/build/esm/type/create/immutable.mjs +37 -0
  124. package/build/esm/type/create/index.d.mts +1 -0
  125. package/build/esm/type/create/index.mjs +1 -0
  126. package/build/esm/type/create/type.d.mts +3 -0
  127. package/build/esm/type/create/type.mjs +15 -0
  128. package/build/esm/type/date/date.mjs +3 -6
  129. package/build/esm/type/discard/discard.d.mts +1 -0
  130. package/build/esm/type/discard/discard.mjs +1 -0
  131. package/build/esm/type/enum/enum.mjs +1 -1
  132. package/build/esm/type/exclude/exclude.mjs +4 -4
  133. package/build/esm/type/extends/extends-from-mapped-key.d.mts +1 -1
  134. package/build/esm/type/extends/extends-from-mapped-key.mjs +2 -1
  135. package/build/esm/type/extends/extends-from-mapped-result.d.mts +1 -1
  136. package/build/esm/type/extends/extends-from-mapped-result.mjs +2 -1
  137. package/build/esm/type/extends/extends.mjs +4 -4
  138. package/build/esm/type/extract/extract.mjs +5 -5
  139. package/build/esm/type/function/function.mjs +2 -8
  140. package/build/esm/type/guard/value.mjs +3 -0
  141. package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +1 -1
  142. package/build/esm/type/indexed/indexed-from-mapped-key.mjs +2 -1
  143. package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +1 -1
  144. package/build/esm/type/indexed/indexed.mjs +10 -6
  145. package/build/esm/type/instance-type/instance-type.mjs +3 -3
  146. package/build/esm/type/integer/integer.mjs +3 -6
  147. package/build/esm/type/intersect/intersect-create.d.mts +1 -1
  148. package/build/esm/type/intersect/intersect-create.mjs +6 -6
  149. package/build/esm/type/intersect/intersect-evaluated.mjs +2 -2
  150. package/build/esm/type/intersect/intersect.mjs +3 -3
  151. package/build/esm/type/intrinsic/intrinsic-from-mapped-key.mjs +4 -2
  152. package/build/esm/type/intrinsic/intrinsic.mjs +3 -1
  153. package/build/esm/type/iterator/iterator.mjs +3 -8
  154. package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +1 -1
  155. package/build/esm/type/keyof/keyof-from-mapped-result.mjs +2 -1
  156. package/build/esm/type/keyof/keyof.mjs +3 -3
  157. package/build/esm/type/literal/literal.mjs +4 -4
  158. package/build/esm/type/mapped/mapped-key.mjs +3 -2
  159. package/build/esm/type/mapped/mapped-result.mjs +3 -2
  160. package/build/esm/type/mapped/mapped.mjs +2 -3
  161. package/build/esm/type/never/never.mjs +3 -6
  162. package/build/esm/type/not/not.d.mts +1 -1
  163. package/build/esm/type/not/not.mjs +3 -7
  164. package/build/esm/type/null/null.mjs +3 -6
  165. package/build/esm/type/number/number.mjs +3 -6
  166. package/build/esm/type/object/object.mjs +14 -13
  167. package/build/esm/type/omit/omit-from-mapped-key.d.mts +1 -1
  168. package/build/esm/type/omit/omit-from-mapped-key.mjs +2 -1
  169. package/build/esm/type/omit/omit-from-mapped-result.d.mts +1 -1
  170. package/build/esm/type/omit/omit-from-mapped-result.mjs +2 -1
  171. package/build/esm/type/omit/omit.mjs +4 -4
  172. package/build/esm/type/optional/optional.mjs +3 -3
  173. package/build/esm/type/parameters/parameters.mjs +2 -3
  174. package/build/esm/type/partial/partial-from-mapped-result.d.mts +1 -1
  175. package/build/esm/type/partial/partial-from-mapped-result.mjs +2 -1
  176. package/build/esm/type/partial/partial.mjs +4 -4
  177. package/build/esm/type/pick/pick-from-mapped-key.d.mts +1 -1
  178. package/build/esm/type/pick/pick-from-mapped-key.mjs +2 -1
  179. package/build/esm/type/pick/pick-from-mapped-result.d.mts +1 -1
  180. package/build/esm/type/pick/pick-from-mapped-result.mjs +2 -1
  181. package/build/esm/type/pick/pick.mjs +4 -4
  182. package/build/esm/type/promise/promise.mjs +3 -8
  183. package/build/esm/type/readonly/readonly.mjs +3 -3
  184. package/build/esm/type/record/record.mjs +5 -6
  185. package/build/esm/type/recursive/recursive.mjs +3 -2
  186. package/build/esm/type/ref/ref.mjs +4 -7
  187. package/build/esm/type/regexp/regexp.mjs +3 -2
  188. package/build/esm/type/required/required-from-mapped-result.d.mts +1 -1
  189. package/build/esm/type/required/required.mjs +4 -4
  190. package/build/esm/type/rest/rest.d.mts +1 -1
  191. package/build/esm/type/rest/rest.mjs +4 -5
  192. package/build/esm/type/return-type/return-type.mjs +3 -3
  193. package/build/esm/type/string/string.mjs +3 -2
  194. package/build/esm/type/symbol/symbol.mjs +2 -1
  195. package/build/esm/type/template-literal/template-literal.mjs +3 -2
  196. package/build/esm/type/transform/transform.mjs +1 -3
  197. package/build/esm/type/tuple/tuple.mjs +5 -7
  198. package/build/esm/type/type/javascript.mjs +13 -13
  199. package/build/esm/type/type/json.mjs +35 -35
  200. package/build/esm/type/uint8array/uint8array.mjs +3 -2
  201. package/build/esm/type/undefined/undefined.mjs +3 -2
  202. package/build/esm/type/union/union-create.d.mts +1 -1
  203. package/build/esm/type/union/union-create.mjs +2 -2
  204. package/build/esm/type/union/union-evaluated.mjs +3 -3
  205. package/build/esm/type/union/union.mjs +3 -3
  206. package/build/esm/type/unknown/unknown.mjs +3 -5
  207. package/build/esm/type/unsafe/unsafe.mjs +2 -4
  208. package/build/esm/type/void/void.mjs +3 -6
  209. package/package.json +1 -1
@@ -1,3 +1,3 @@
1
1
  import type { TSchema, SchemaOptions } from '../schema/index';
2
2
  import { TUnion } from './union-type';
3
- export declare function UnionCreate<T extends TSchema[]>(T: [...T], options: SchemaOptions): TUnion<T>;
3
+ export declare function UnionCreate<T extends TSchema[]>(T: [...T], options?: SchemaOptions): TUnion<T>;
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.UnionCreate = UnionCreate;
5
- const type_1 = require("../clone/type");
5
+ const type_1 = require("../create/type");
6
6
  const index_1 = require("../symbols/index");
7
7
  function UnionCreate(T, options) {
8
- return { ...options, [index_1.Kind]: 'Union', anyOf: (0, type_1.CloneRest)(T) };
8
+ return (0, type_1.CreateType)({ [index_1.Kind]: 'Union', anyOf: T }, options);
9
9
  }
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.UnionEvaluated = UnionEvaluated;
5
+ const type_1 = require("../create/type");
5
6
  const index_1 = require("../symbols/index");
6
- const type_1 = require("../clone/type");
7
7
  const index_2 = require("../discard/index");
8
8
  const index_3 = require("../never/index");
9
9
  const index_4 = require("../optional/index");
@@ -31,9 +31,9 @@ function ResolveUnion(T, options) {
31
31
  : (0, union_create_1.UnionCreate)(RemoveOptionalFromRest(T), options));
32
32
  }
33
33
  /** `[Json]` Creates an evaluated Union type */
34
- function UnionEvaluated(T, options = {}) {
34
+ function UnionEvaluated(T, options) {
35
35
  // prettier-ignore
36
36
  return (T.length === 0 ? (0, index_3.Never)(options) :
37
- T.length === 1 ? (0, type_1.CloneType)(T[0], options) :
37
+ T.length === 1 ? (0, type_1.CreateType)(T[0], options) :
38
38
  ResolveUnion(T, options));
39
39
  }
@@ -3,12 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Union = Union;
5
5
  const index_1 = require("../never/index");
6
- const type_1 = require("../clone/type");
6
+ const type_1 = require("../create/type");
7
7
  const union_create_1 = require("./union-create");
8
8
  /** `[Json]` Creates a Union type */
9
- function Union(T, options = {}) {
9
+ function Union(T, options) {
10
10
  // prettier-ignore
11
11
  return (T.length === 0 ? (0, index_1.Never)(options) :
12
- T.length === 1 ? (0, type_1.CloneType)(T[0], options) :
12
+ T.length === 1 ? (0, type_1.CreateType)(T[0], options) :
13
13
  (0, union_create_1.UnionCreate)(T, options));
14
14
  }
@@ -2,11 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Unknown = Unknown;
5
+ const type_1 = require("../create/type");
5
6
  const index_1 = require("../symbols/index");
6
7
  /** `[Json]` Creates an Unknown type */
7
- function Unknown(options = {}) {
8
- return {
9
- ...options,
10
- [index_1.Kind]: 'Unknown',
11
- };
8
+ function Unknown(options) {
9
+ return (0, type_1.CreateType)({ [index_1.Kind]: 'Unknown' }, options);
12
10
  }
@@ -2,11 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Unsafe = Unsafe;
5
+ const type_1 = require("../create/type");
5
6
  const index_1 = require("../symbols/index");
6
7
  /** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
7
8
  function Unsafe(options = {}) {
8
- return {
9
- ...options,
10
- [index_1.Kind]: options[index_1.Kind] ?? 'Unsafe',
11
- };
9
+ return (0, type_1.CreateType)({ [index_1.Kind]: options[index_1.Kind] ?? 'Unsafe' }, options);
12
10
  }
@@ -2,12 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Void = Void;
5
+ const type_1 = require("../create/type");
5
6
  const index_1 = require("../symbols/index");
6
7
  /** `[JavaScript]` Creates a Void type */
7
- function Void(options = {}) {
8
- return {
9
- ...options,
10
- [index_1.Kind]: 'Void',
11
- type: 'void',
12
- };
8
+ function Void(options) {
9
+ return (0, type_1.CreateType)({ [index_1.Kind]: 'Void', type: 'void' }, options);
13
10
  }
@@ -1,4 +1,5 @@
1
1
  export * from './type/clone/index.mjs';
2
+ export * from './type/create/index.mjs';
2
3
  export * from './type/error/index.mjs';
3
4
  export * from './type/guard/index.mjs';
4
5
  export * from './type/helpers/index.mjs';
@@ -2,6 +2,7 @@
2
2
  // Infrastructure
3
3
  // ------------------------------------------------------------------
4
4
  export * from './type/clone/index.mjs';
5
+ export * from './type/create/index.mjs';
5
6
  export * from './type/error/index.mjs';
6
7
  export * from './type/guard/index.mjs';
7
8
  export * from './type/helpers/index.mjs';
@@ -1,5 +1,13 @@
1
1
  export declare namespace TypeSystemPolicy {
2
- /** Shared assertion routines used by the value and errors modules */
2
+ /**
3
+ * Configures the instantiation behavior of TypeBox types. The `default` option assigns raw JavaScript
4
+ * references for embedded types, which may cause side effects if type properties are explicitly updated
5
+ * outside the TypeBox type builder. The `clone` option creates copies of any shared types upon creation,
6
+ * preventing unintended side effects. The `freeze` option applies `Object.freeze()` to the type, making
7
+ * it fully readonly and immutable. Implementations should use `default` whenever possible, as it is the
8
+ * fastest way to instantiate types. The default setting is `default`.
9
+ */
10
+ let InstanceMode: 'default' | 'clone' | 'freeze';
3
11
  /** Sets whether TypeBox should assert optional properties using the TypeScript `exactOptionalPropertyTypes` assertion policy. The default is `false` */
4
12
  let ExactOptionalPropertyTypes: boolean;
5
13
  /** Sets whether arrays should be treated as a kind of objects. The default is `false` */
@@ -2,9 +2,20 @@ import { IsObject, IsArray, IsNumber, IsUndefined } from '../value/guard/index.m
2
2
  export var TypeSystemPolicy;
3
3
  (function (TypeSystemPolicy) {
4
4
  // ------------------------------------------------------------------
5
- // TypeSystemPolicy
5
+ // TypeSystemPolicy: Instancing
6
+ // ------------------------------------------------------------------
7
+ /**
8
+ * Configures the instantiation behavior of TypeBox types. The `default` option assigns raw JavaScript
9
+ * references for embedded types, which may cause side effects if type properties are explicitly updated
10
+ * outside the TypeBox type builder. The `clone` option creates copies of any shared types upon creation,
11
+ * preventing unintended side effects. The `freeze` option applies `Object.freeze()` to the type, making
12
+ * it fully readonly and immutable. Implementations should use `default` whenever possible, as it is the
13
+ * fastest way to instantiate types. The default setting is `default`.
14
+ */
15
+ TypeSystemPolicy.InstanceMode = 'default';
16
+ // ------------------------------------------------------------------
17
+ // TypeSystemPolicy: Checking
6
18
  // ------------------------------------------------------------------
7
- /** Shared assertion routines used by the value and errors modules */
8
19
  /** Sets whether TypeBox should assert optional properties using the TypeScript `exactOptionalPropertyTypes` assertion policy. The default is `false` */
9
20
  TypeSystemPolicy.ExactOptionalPropertyTypes = false;
10
21
  /** Sets whether arrays should be treated as a kind of objects. The default is `false` */
@@ -1,5 +1,6 @@
1
+ import { CreateType } from '../create/index.mjs';
1
2
  import { Kind } from '../symbols/index.mjs';
2
3
  /** `[Json]` Creates an Any type */
3
- export function Any(options = {}) {
4
- return { ...options, [Kind]: 'Any' };
4
+ export function Any(options) {
5
+ return CreateType({ [Kind]: 'Any' }, options);
5
6
  }
@@ -24,5 +24,5 @@ export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptio
24
24
  items: T;
25
25
  }
26
26
  /** `[Json]` Creates an Array type */
27
- export declare function Array<T extends TSchema>(schema: T, options?: ArrayOptions): TArray<T>;
27
+ export declare function Array<T extends TSchema>(items: T, options?: ArrayOptions): TArray<T>;
28
28
  export {};
@@ -1,11 +1,6 @@
1
- import { CloneType } from '../clone/type.mjs';
1
+ import { CreateType } from '../create/type.mjs';
2
2
  import { Kind } from '../symbols/index.mjs';
3
3
  /** `[Json]` Creates an Array type */
4
- export function Array(schema, options = {}) {
5
- return {
6
- ...options,
7
- [Kind]: 'Array',
8
- type: 'array',
9
- items: CloneType(schema),
10
- };
4
+ export function Array(items, options) {
5
+ return CreateType({ [Kind]: 'Array', type: 'array', items }, options);
11
6
  }
@@ -1,11 +1,6 @@
1
1
  import { Kind } from '../symbols/index.mjs';
2
- import { CloneType } from '../clone/type.mjs';
2
+ import { CreateType } from '../create/type.mjs';
3
3
  /** `[JavaScript]` Creates a AsyncIterator type */
4
- export function AsyncIterator(items, options = {}) {
5
- return {
6
- ...options,
7
- [Kind]: 'AsyncIterator',
8
- type: 'AsyncIterator',
9
- items: CloneType(items),
10
- };
4
+ export function AsyncIterator(items, options) {
5
+ return CreateType({ [Kind]: 'AsyncIterator', type: 'AsyncIterator', items }, options);
11
6
  }
@@ -1,6 +1,6 @@
1
1
  import { Intersect } from '../intersect/index.mjs';
2
2
  import { Union } from '../union/index.mjs';
3
- import { CloneType } from '../clone/type.mjs';
3
+ import { CreateType } from '../create/type.mjs';
4
4
  // ------------------------------------------------------------------
5
5
  // TypeGuard
6
6
  // ------------------------------------------------------------------
@@ -32,6 +32,6 @@ function AwaitedResolve(T) {
32
32
  T);
33
33
  }
34
34
  /** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
35
- export function Awaited(T, options = {}) {
36
- return CloneType(AwaitedResolve(T), options);
35
+ export function Awaited(T, options) {
36
+ return CreateType(AwaitedResolve(T), options);
37
37
  }
@@ -1,9 +1,6 @@
1
1
  import { Kind } from '../symbols/index.mjs';
2
+ import { CreateType } from '../create/index.mjs';
2
3
  /** `[JavaScript]` Creates a BigInt type */
3
- export function BigInt(options = {}) {
4
- return {
5
- ...options,
6
- [Kind]: 'BigInt',
7
- type: 'bigint',
8
- };
4
+ export function BigInt(options) {
5
+ return CreateType({ [Kind]: 'BigInt', type: 'bigint' }, options);
9
6
  }
@@ -1,9 +1,6 @@
1
1
  import { Kind } from '../symbols/index.mjs';
2
+ import { CreateType } from '../create/index.mjs';
2
3
  /** `[Json]` Creates a Boolean type */
3
- export function Boolean(options = {}) {
4
- return {
5
- ...options,
6
- [Kind]: 'Boolean',
7
- type: 'boolean',
8
- };
4
+ export function Boolean(options) {
5
+ return CreateType({ [Kind]: 'Boolean', type: 'boolean' }, options);
9
6
  }
@@ -1,4 +1,4 @@
1
- import type { TSchema, SchemaOptions } from '../schema/index.mjs';
1
+ import { TSchema, SchemaOptions } from '../schema/index.mjs';
2
2
  /** Clones a Rest */
3
3
  export declare function CloneRest<T extends TSchema[]>(schemas: T): T;
4
4
  /** Clones a Type */
@@ -4,6 +4,6 @@ export function CloneRest(schemas) {
4
4
  return schemas.map((schema) => CloneType(schema));
5
5
  }
6
6
  /** Clones a Type */
7
- export function CloneType(schema, options = {}) {
8
- return { ...Clone(schema), ...options };
7
+ export function CloneType(schema, options) {
8
+ return options === undefined ? Clone(schema) : Clone({ ...options, ...schema });
9
9
  }
@@ -34,7 +34,7 @@ function CompositeProperties(T, K) {
34
34
  return Acc;
35
35
  }
36
36
  // prettier-ignore
37
- export function Composite(T, options = {}) {
37
+ export function Composite(T, options) {
38
38
  const K = CompositeKeys(T);
39
39
  const P = CompositeProperties(T, K);
40
40
  const R = Object(P, options);
@@ -11,7 +11,7 @@ import { Readonly } from '../readonly/index.mjs';
11
11
  import { Undefined } from '../undefined/index.mjs';
12
12
  import { Uint8Array } from '../uint8array/index.mjs';
13
13
  import { Unknown } from '../unknown/index.mjs';
14
- import { CloneType } from '../clone/index.mjs';
14
+ import { CreateType } from '../create/index.mjs';
15
15
  // ------------------------------------------------------------------
16
16
  // ValueGuard
17
17
  // ------------------------------------------------------------------
@@ -49,6 +49,6 @@ function FromValue(value, root) {
49
49
  Object({}));
50
50
  }
51
51
  /** `[JavaScript]` Creates a readonly const type from the given value. */
52
- export function Const(T, options = {}) {
53
- return CloneType(FromValue(T, true), options);
52
+ export function Const(T, options) {
53
+ return CreateType(FromValue(T, true), options);
54
54
  }
@@ -1,12 +1,6 @@
1
- import { CloneType, CloneRest } from '../clone/type.mjs';
1
+ import { CreateType } from '../create/type.mjs';
2
2
  import { Kind } from '../symbols/index.mjs';
3
3
  /** `[JavaScript]` Creates a Constructor type */
4
4
  export function Constructor(parameters, returns, options) {
5
- return {
6
- ...options,
7
- [Kind]: 'Constructor',
8
- type: 'Constructor',
9
- parameters: CloneRest(parameters),
10
- returns: CloneType(returns),
11
- };
5
+ return CreateType({ [Kind]: 'Constructor', type: 'Constructor', parameters, returns }, options);
12
6
  }
@@ -1,6 +1,5 @@
1
1
  import { Tuple } from '../tuple/index.mjs';
2
- import { CloneRest } from '../clone/type.mjs';
3
2
  /** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
4
- export function ConstructorParameters(schema, options = {}) {
5
- return Tuple(CloneRest(schema.parameters), { ...options });
3
+ export function ConstructorParameters(schema, options) {
4
+ return Tuple(schema.parameters, options);
6
5
  }
@@ -0,0 +1,2 @@
1
+ /** Specialized deep immutable value. Applies freeze recursively to the given value */
2
+ export declare function Immutable<T>(value: T): T;
@@ -0,0 +1,37 @@
1
+ import * as ValueGuard from '../guard/value.mjs';
2
+ function ImmutableArray(value) {
3
+ return globalThis.Object.freeze(value).map((value) => Immutable(value));
4
+ }
5
+ function ImmutableDate(value) {
6
+ return value;
7
+ }
8
+ function ImmutableUint8Array(value) {
9
+ return value;
10
+ }
11
+ function ImmutableRegExp(value) {
12
+ return value;
13
+ }
14
+ function ImmutableObject(value) {
15
+ const result = {};
16
+ for (const key of Object.getOwnPropertyNames(value)) {
17
+ result[key] = Immutable(value[key]);
18
+ }
19
+ for (const key of Object.getOwnPropertySymbols(value)) {
20
+ result[key] = Immutable(value[key]);
21
+ }
22
+ return globalThis.Object.freeze(result);
23
+ }
24
+ /** Specialized deep immutable value. Applies freeze recursively to the given value */
25
+ export function Immutable(value) {
26
+ return ValueGuard.IsArray(value)
27
+ ? ImmutableArray(value)
28
+ : ValueGuard.IsDate(value)
29
+ ? ImmutableDate(value)
30
+ : ValueGuard.IsUint8Array(value)
31
+ ? ImmutableUint8Array(value)
32
+ : ValueGuard.IsRegExp(value)
33
+ ? ImmutableRegExp(value)
34
+ : ValueGuard.IsObject(value)
35
+ ? ImmutableObject(value)
36
+ : value;
37
+ }
@@ -0,0 +1 @@
1
+ export * from './type.mjs';
@@ -0,0 +1 @@
1
+ export * from './type.mjs';
@@ -0,0 +1,3 @@
1
+ import { SchemaOptions } from '../schema/schema.mjs';
2
+ /** Creates TypeBox schematics using the configured InstanceMode */
3
+ export declare function CreateType(schema: Record<any, unknown>, options?: SchemaOptions): unknown;
@@ -0,0 +1,15 @@
1
+ import { TypeSystemPolicy } from '../../system/policy.mjs';
2
+ import { Immutable } from './immutable.mjs';
3
+ import { Clone } from '../clone/value.mjs';
4
+ /** Creates TypeBox schematics using the configured InstanceMode */
5
+ export function CreateType(schema, options) {
6
+ const result = options !== undefined ? Object.assign(options, schema) : schema;
7
+ switch (TypeSystemPolicy.InstanceMode) {
8
+ case 'freeze':
9
+ return Immutable(result);
10
+ case 'clone':
11
+ return Clone(result);
12
+ default:
13
+ return result;
14
+ }
15
+ }
@@ -1,9 +1,6 @@
1
1
  import { Kind } from '../symbols/index.mjs';
2
+ import { CreateType } from '../create/type.mjs';
2
3
  /** `[JavaScript]` Creates a Date type */
3
- export function Date(options = {}) {
4
- return {
5
- ...options,
6
- [Kind]: 'Date',
7
- type: 'Date',
8
- };
4
+ export function Date(options) {
5
+ return CreateType({ [Kind]: 'Date', type: 'Date' }, options);
9
6
  }
@@ -1 +1,2 @@
1
+ /** Discards property keys from the given value. This function returns a shallow Clone. */
1
2
  export declare function Discard(value: Record<PropertyKey, any>, keys: PropertyKey[]): Record<PropertyKey, any>;
@@ -2,6 +2,7 @@ function DiscardKey(value, key) {
2
2
  const { [key]: _, ...rest } = value;
3
3
  return rest;
4
4
  }
5
+ /** Discards property keys from the given value. This function returns a shallow Clone. */
5
6
  export function Discard(value, keys) {
6
7
  return keys.reduce((acc, key) => DiscardKey(acc, key), value);
7
8
  }
@@ -6,7 +6,7 @@ import { Union } from '../union/index.mjs';
6
6
  // ------------------------------------------------------------------
7
7
  import { IsUndefined } from '../guard/value.mjs';
8
8
  /** `[Json]` Creates a Enum type */
9
- export function Enum(item, options = {}) {
9
+ export function Enum(item, options) {
10
10
  if (IsUndefined(item))
11
11
  throw new Error('Enum undefined or empty');
12
12
  const values1 = globalThis.Object.getOwnPropertyNames(item)
@@ -1,7 +1,7 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Union } from '../union/index.mjs';
2
3
  import { Never } from '../never/index.mjs';
3
4
  import { ExtendsCheck, ExtendsResult } from '../extends/index.mjs';
4
- import { CloneType } from '../clone/type.mjs';
5
5
  import { ExcludeFromMappedResult } from './exclude-from-mapped-result.mjs';
6
6
  import { ExcludeFromTemplateLiteral } from './exclude-from-template-literal.mjs';
7
7
  // ------------------------------------------------------------------
@@ -16,10 +16,10 @@ function ExcludeRest(L, R) {
16
16
  export function Exclude(L, R, options = {}) {
17
17
  // overloads
18
18
  if (IsTemplateLiteral(L))
19
- return CloneType(ExcludeFromTemplateLiteral(L, R), options);
19
+ return CreateType(ExcludeFromTemplateLiteral(L, R), options);
20
20
  if (IsMappedResult(L))
21
- return CloneType(ExcludeFromMappedResult(L, R), options);
21
+ return CreateType(ExcludeFromMappedResult(L, R), options);
22
22
  // prettier-ignore
23
- return CloneType(IsUnion(L) ? ExcludeRest(L.anyOf, R) :
23
+ return CreateType(IsUnion(L) ? ExcludeRest(L.anyOf, R) :
24
24
  ExtendsCheck(L, R) !== ExtendsResult.False ? Never() : L, options);
25
25
  }
@@ -10,5 +10,5 @@ type TFromPropertyKey<K extends PropertyKey, U extends TSchema, L extends TSchem
10
10
  type TFromPropertyKeys<K extends PropertyKey[], U extends TSchema, L extends TSchema, R extends TSchema, Acc extends TProperties = {}> = (K extends [infer LK extends PropertyKey, ...infer RK extends PropertyKey[]] ? TFromPropertyKeys<RK, U, L, R, Acc & TFromPropertyKey<LK, U, L, R>> : Acc);
11
11
  type TFromMappedKey<K extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema> = (TFromPropertyKeys<K['keys'], U, L, R>);
12
12
  export type TExtendsFromMappedKey<T extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = TFromMappedKey<T, U, L, R>> = (TMappedResult<P>);
13
- export declare function ExtendsFromMappedKey<T extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = TFromMappedKey<T, U, L, R>>(T: T, U: U, L: L, R: R, options: SchemaOptions): TMappedResult<P>;
13
+ export declare function ExtendsFromMappedKey<T extends TMappedKey, U extends TSchema, L extends TSchema, R extends TSchema, P extends TProperties = TFromMappedKey<T, U, L, R>>(T: T, U: U, L: L, R: R, options?: SchemaOptions): TMappedResult<P>;
14
14
  export {};
@@ -1,10 +1,11 @@
1
1
  import { MappedResult } from '../mapped/index.mjs';
2
2
  import { Literal } from '../literal/index.mjs';
3
3
  import { Extends } from './extends.mjs';
4
+ import { Clone } from '../clone/value.mjs';
4
5
  // prettier-ignore
5
6
  function FromPropertyKey(K, U, L, R, options) {
6
7
  return {
7
- [K]: Extends(Literal(K), U, L, R, options)
8
+ [K]: Extends(Literal(K), U, L, R, Clone(options))
8
9
  };
9
10
  }
10
11
  // prettier-ignore
@@ -7,5 +7,5 @@ type TFromProperties<P extends TProperties, Right extends TSchema, False extends
7
7
  });
8
8
  type TFromMappedResult<Left extends TMappedResult, Right extends TSchema, True extends TSchema, False extends TSchema> = (TFromProperties<Left['properties'], Right, True, False>);
9
9
  export type TExtendsFromMappedResult<Left extends TMappedResult, Right extends TSchema, True extends TSchema, False extends TSchema, P extends TProperties = TFromMappedResult<Left, Right, True, False>> = (TMappedResult<P>);
10
- export declare function ExtendsFromMappedResult<Left extends TMappedResult, Right extends TSchema, True extends TSchema, False extends TSchema, P extends TProperties = TFromMappedResult<Left, Right, True, False>>(Left: Left, Right: Right, True: True, False: False, options: SchemaOptions): TMappedResult<P>;
10
+ export declare function ExtendsFromMappedResult<Left extends TMappedResult, Right extends TSchema, True extends TSchema, False extends TSchema, P extends TProperties = TFromMappedResult<Left, Right, True, False>>(Left: Left, Right: Right, True: True, False: False, options?: SchemaOptions): TMappedResult<P>;
11
11
  export {};
@@ -1,10 +1,11 @@
1
1
  import { MappedResult } from '../mapped/index.mjs';
2
2
  import { Extends } from './extends.mjs';
3
+ import { Clone } from '../clone/value.mjs';
3
4
  // prettier-ignore
4
5
  function FromProperties(P, Right, True, False, options) {
5
6
  const Acc = {};
6
7
  for (const K2 of globalThis.Object.getOwnPropertyNames(P))
7
- Acc[K2] = Extends(P[K2], Right, True, False, options);
8
+ Acc[K2] = Extends(P[K2], Right, True, False, Clone(options));
8
9
  return Acc;
9
10
  }
10
11
  // prettier-ignore
@@ -1,6 +1,6 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Union } from '../union/index.mjs';
2
3
  import { ExtendsCheck, ExtendsResult } from './extends-check.mjs';
3
- import { CloneType } from '../clone/type.mjs';
4
4
  import { ExtendsFromMappedKey } from './extends-from-mapped-key.mjs';
5
5
  import { ExtendsFromMappedResult } from './extends-from-mapped-result.mjs';
6
6
  // ------------------------------------------------------------------
@@ -15,9 +15,9 @@ function ExtendsResolve(left, right, trueType, falseType) {
15
15
  falseType);
16
16
  }
17
17
  /** `[Json]` Creates a Conditional type */
18
- export function Extends(L, R, T, F, options = {}) {
18
+ export function Extends(L, R, T, F, options) {
19
19
  // prettier-ignore
20
20
  return (IsMappedResult(L) ? ExtendsFromMappedResult(L, R, T, F, options) :
21
- IsMappedKey(L) ? CloneType(ExtendsFromMappedKey(L, R, T, F, options)) :
22
- CloneType(ExtendsResolve(L, R, T, F), options));
21
+ IsMappedKey(L) ? CreateType(ExtendsFromMappedKey(L, R, T, F, options)) :
22
+ CreateType(ExtendsResolve(L, R, T, F), options));
23
23
  }
@@ -1,7 +1,7 @@
1
+ import { CreateType } from '../create/type.mjs';
1
2
  import { Union } from '../union/index.mjs';
2
3
  import { Never } from '../never/index.mjs';
3
4
  import { ExtendsCheck, ExtendsResult } from '../extends/index.mjs';
4
- import { CloneType } from '../clone/type.mjs';
5
5
  import { ExtractFromMappedResult } from './extract-from-mapped-result.mjs';
6
6
  import { ExtractFromTemplateLiteral } from './extract-from-template-literal.mjs';
7
7
  // ------------------------------------------------------------------
@@ -13,13 +13,13 @@ function ExtractRest(L, R) {
13
13
  return extracted.length === 1 ? extracted[0] : Union(extracted);
14
14
  }
15
15
  /** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
16
- export function Extract(L, R, options = {}) {
16
+ export function Extract(L, R, options) {
17
17
  // overloads
18
18
  if (IsTemplateLiteral(L))
19
- return CloneType(ExtractFromTemplateLiteral(L, R), options);
19
+ return CreateType(ExtractFromTemplateLiteral(L, R), options);
20
20
  if (IsMappedResult(L))
21
- return CloneType(ExtractFromMappedResult(L, R), options);
21
+ return CreateType(ExtractFromMappedResult(L, R), options);
22
22
  // prettier-ignore
23
- return CloneType(IsUnion(L) ? ExtractRest(L.anyOf, R) :
23
+ return CreateType(IsUnion(L) ? ExtractRest(L.anyOf, R) :
24
24
  ExtendsCheck(L, R) !== ExtendsResult.False ? L : Never(), options);
25
25
  }
@@ -1,12 +1,6 @@
1
- import { CloneType, CloneRest } from '../clone/type.mjs';
1
+ import { CreateType } from '../create/type.mjs';
2
2
  import { Kind } from '../symbols/index.mjs';
3
3
  /** `[JavaScript]` Creates a Function type */
4
4
  export function Function(parameters, returns, options) {
5
- return {
6
- ...options,
7
- [Kind]: 'Function',
8
- type: 'Function',
9
- parameters: CloneRest(parameters),
10
- returns: CloneType(returns),
11
- };
5
+ return CreateType({ [Kind]: 'Function', type: 'Function', parameters, returns }, options);
12
6
  }
@@ -1,3 +1,6 @@
1
+ // --------------------------------------------------------------------------
2
+ // Object Instances
3
+ // --------------------------------------------------------------------------
1
4
  /** Returns true if this value is an async iterator */
2
5
  export function IsAsyncIterator(value) {
3
6
  return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.asyncIterator in value;
@@ -9,5 +9,5 @@ type TMappedIndexPropertyKey<T extends TSchema, K extends PropertyKey> = {
9
9
  type TMappedIndexPropertyKeys<T extends TSchema, K extends PropertyKey[], Acc extends TProperties = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TMappedIndexPropertyKeys<T, R, Acc & TMappedIndexPropertyKey<T, L>> : Acc);
10
10
  type TMappedIndexProperties<T extends TSchema, K extends TMappedKey> = Evaluate<TMappedIndexPropertyKeys<T, K['keys']>>;
11
11
  export type TIndexFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TMappedIndexProperties<T, K>> = (Ensure<TMappedResult<P>>);
12
- export declare function IndexFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TMappedIndexProperties<T, K>>(T: T, K: K, options: SchemaOptions): TMappedResult<P>;
12
+ export declare function IndexFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TMappedIndexProperties<T, K>>(T: T, K: K, options?: SchemaOptions): TMappedResult<P>;
13
13
  export {};
@@ -1,8 +1,9 @@
1
1
  import { Index } from './indexed.mjs';
2
2
  import { MappedResult } from '../mapped/index.mjs';
3
+ import { Clone } from '../clone/value.mjs';
3
4
  // prettier-ignore
4
5
  function MappedIndexPropertyKey(T, K, options) {
5
- return { [K]: Index(T, [K], options) };
6
+ return { [K]: Index(T, [K], Clone(options)) };
6
7
  }
7
8
  // prettier-ignore
8
9
  function MappedIndexPropertyKeys(T, K, options) {
@@ -8,5 +8,5 @@ type TFromProperties<T extends TSchema, P extends TProperties> = ({
8
8
  });
9
9
  type TFromMappedResult<T extends TSchema, R extends TMappedResult> = (TFromProperties<T, R['properties']>);
10
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>;
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
12
  export {};