umt 2.19.0 → 3.0.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 (181) hide show
  1. package/module/Validate/any/core.d.ts +21 -0
  2. package/module/Validate/any/core.js +19 -0
  3. package/module/Validate/any/core.js.map +1 -0
  4. package/module/Validate/any/index.d.ts +1 -0
  5. package/module/Validate/any/index.js +2 -0
  6. package/module/Validate/any/index.js.map +1 -0
  7. package/module/Validate/array/arrayOf.d.ts +12 -4
  8. package/module/Validate/array/arrayOf.js +2 -2
  9. package/module/Validate/array/arrayOf.js.map +1 -1
  10. package/module/Validate/array/index.d.ts +0 -1
  11. package/module/Validate/array/index.js +0 -1
  12. package/module/Validate/array/index.js.map +1 -1
  13. package/module/Validate/bigint/core.d.ts +24 -0
  14. package/module/Validate/bigint/core.js +37 -0
  15. package/module/Validate/bigint/core.js.map +1 -0
  16. package/module/Validate/bigint/index.d.ts +1 -0
  17. package/module/Validate/bigint/index.js +2 -0
  18. package/module/Validate/bigint/index.js.map +1 -0
  19. package/module/Validate/date/core.d.ts +14 -0
  20. package/module/Validate/date/core.js +29 -0
  21. package/module/Validate/date/core.js.map +1 -0
  22. package/module/Validate/date/index.d.ts +1 -0
  23. package/module/Validate/date/index.js +2 -0
  24. package/module/Validate/date/index.js.map +1 -0
  25. package/module/Validate/file/core.d.ts +13 -0
  26. package/module/Validate/file/core.js +32 -0
  27. package/module/Validate/file/core.js.map +1 -0
  28. package/module/Validate/file/index.d.ts +1 -0
  29. package/module/Validate/file/index.js +2 -0
  30. package/module/Validate/file/index.js.map +1 -0
  31. package/module/Validate/function/core.d.ts +75 -0
  32. package/module/Validate/function/core.js +66 -0
  33. package/module/Validate/function/core.js.map +1 -0
  34. package/module/Validate/function/index.d.ts +1 -0
  35. package/module/Validate/function/index.js +2 -0
  36. package/module/Validate/function/index.js.map +1 -0
  37. package/module/Validate/index.d.ts +11 -0
  38. package/module/Validate/index.js +11 -0
  39. package/module/Validate/index.js.map +1 -1
  40. package/module/Validate/instanceof/core.d.ts +19 -0
  41. package/module/Validate/instanceof/core.js +32 -0
  42. package/module/Validate/instanceof/core.js.map +1 -0
  43. package/module/Validate/instanceof/index.d.ts +1 -0
  44. package/module/Validate/instanceof/index.js +2 -0
  45. package/module/Validate/instanceof/index.js.map +1 -0
  46. package/module/Validate/map/core.d.ts +24 -0
  47. package/module/Validate/map/core.js +57 -0
  48. package/module/Validate/map/core.js.map +1 -0
  49. package/module/Validate/map/index.d.ts +1 -0
  50. package/module/Validate/map/index.js +2 -0
  51. package/module/Validate/map/index.js.map +1 -0
  52. package/module/Validate/never/core.d.ts +22 -0
  53. package/module/Validate/never/core.js +23 -0
  54. package/module/Validate/never/core.js.map +1 -0
  55. package/module/Validate/never/index.d.ts +1 -0
  56. package/module/Validate/never/index.js +2 -0
  57. package/module/Validate/never/index.js.map +1 -0
  58. package/module/Validate/object/core.d.ts +22 -4
  59. package/module/Validate/object/core.js +5 -3
  60. package/module/Validate/object/core.js.map +1 -1
  61. package/module/Validate/object/index.d.ts +4 -0
  62. package/module/Validate/object/index.js +4 -0
  63. package/module/Validate/object/index.js.map +1 -1
  64. package/module/Validate/object/intersection.d.ts +5 -2
  65. package/module/Validate/object/intersection.js.map +1 -1
  66. package/module/Validate/object/nullable.d.ts +12 -2
  67. package/module/Validate/object/nullable.js +2 -2
  68. package/module/Validate/object/nullable.js.map +1 -1
  69. package/module/Validate/object/omit.d.ts +22 -0
  70. package/module/Validate/object/omit.js +33 -0
  71. package/module/Validate/object/omit.js.map +1 -0
  72. package/module/Validate/object/optional.d.ts +31 -3
  73. package/module/Validate/object/optional.js +7 -5
  74. package/module/Validate/object/optional.js.map +1 -1
  75. package/module/Validate/object/partial.d.ts +25 -0
  76. package/module/Validate/object/partial.js +29 -0
  77. package/module/Validate/object/partial.js.map +1 -0
  78. package/module/Validate/object/pick.d.ts +21 -0
  79. package/module/Validate/object/pick.js +29 -0
  80. package/module/Validate/object/pick.js.map +1 -0
  81. package/module/Validate/object/required.d.ts +22 -0
  82. package/module/Validate/object/required.js +30 -0
  83. package/module/Validate/object/required.js.map +1 -0
  84. package/module/Validate/set/core.d.ts +24 -0
  85. package/module/Validate/set/core.js +47 -0
  86. package/module/Validate/set/core.js.map +1 -0
  87. package/module/Validate/set/index.d.ts +1 -0
  88. package/module/Validate/set/index.js +2 -0
  89. package/module/Validate/set/index.js.map +1 -0
  90. package/module/Validate/string/oneOf.d.ts +10 -7
  91. package/module/Validate/string/oneOf.js +5 -3
  92. package/module/Validate/string/oneOf.js.map +1 -1
  93. package/module/Validate/templateLiteral/core.d.ts +55 -0
  94. package/module/Validate/templateLiteral/core.js +68 -0
  95. package/module/Validate/templateLiteral/core.js.map +1 -0
  96. package/module/Validate/templateLiteral/index.d.ts +1 -0
  97. package/module/Validate/templateLiteral/index.js +2 -0
  98. package/module/Validate/templateLiteral/index.js.map +1 -0
  99. package/module/Validate/type.d.ts +19 -5
  100. package/module/Validate/unknown/core.d.ts +21 -0
  101. package/module/Validate/unknown/core.js +16 -0
  102. package/module/Validate/unknown/core.js.map +1 -0
  103. package/module/Validate/unknown/index.d.ts +1 -0
  104. package/module/Validate/unknown/index.js +2 -0
  105. package/module/Validate/unknown/index.js.map +1 -0
  106. package/module/es5/Validate/any/core.d.ts +21 -0
  107. package/module/es5/Validate/any/core.js +36 -0
  108. package/module/es5/Validate/any/index.d.ts +1 -0
  109. package/module/es5/Validate/any/index.js +16 -0
  110. package/module/es5/Validate/array/arrayOf.d.ts +12 -4
  111. package/module/es5/Validate/array/arrayOf.js +10 -4
  112. package/module/es5/Validate/array/index.d.ts +0 -1
  113. package/module/es5/Validate/array/index.js +0 -11
  114. package/module/es5/Validate/bigint/core.d.ts +24 -0
  115. package/module/es5/Validate/bigint/core.js +65 -0
  116. package/module/es5/Validate/bigint/index.d.ts +1 -0
  117. package/module/es5/Validate/bigint/index.js +16 -0
  118. package/module/es5/Validate/date/core.d.ts +14 -0
  119. package/module/es5/Validate/date/core.js +35 -0
  120. package/module/es5/Validate/date/index.d.ts +1 -0
  121. package/module/es5/Validate/date/index.js +16 -0
  122. package/module/es5/Validate/file/core.d.ts +13 -0
  123. package/module/es5/Validate/file/core.js +39 -0
  124. package/module/es5/Validate/file/index.d.ts +1 -0
  125. package/module/es5/Validate/file/index.js +16 -0
  126. package/module/es5/Validate/function/core.d.ts +75 -0
  127. package/module/es5/Validate/function/core.js +125 -0
  128. package/module/es5/Validate/function/index.d.ts +1 -0
  129. package/module/es5/Validate/function/index.js +16 -0
  130. package/module/es5/Validate/index.d.ts +11 -0
  131. package/module/es5/Validate/index.js +121 -0
  132. package/module/es5/Validate/instanceof/core.d.ts +19 -0
  133. package/module/es5/Validate/instanceof/core.js +40 -0
  134. package/module/es5/Validate/instanceof/index.d.ts +1 -0
  135. package/module/es5/Validate/instanceof/index.js +16 -0
  136. package/module/es5/Validate/map/core.d.ts +24 -0
  137. package/module/es5/Validate/map/core.js +81 -0
  138. package/module/es5/Validate/map/index.d.ts +1 -0
  139. package/module/es5/Validate/map/index.js +16 -0
  140. package/module/es5/Validate/never/core.d.ts +22 -0
  141. package/module/es5/Validate/never/core.js +35 -0
  142. package/module/es5/Validate/never/index.d.ts +1 -0
  143. package/module/es5/Validate/never/index.js +16 -0
  144. package/module/es5/Validate/object/core.d.ts +22 -4
  145. package/module/es5/Validate/object/core.js +14 -2
  146. package/module/es5/Validate/object/index.d.ts +4 -0
  147. package/module/es5/Validate/object/index.js +44 -0
  148. package/module/es5/Validate/object/intersection.d.ts +5 -2
  149. package/module/es5/Validate/object/intersection.js +6 -0
  150. package/module/es5/Validate/object/nullable.d.ts +12 -2
  151. package/module/es5/Validate/object/nullable.js +2 -2
  152. package/module/es5/Validate/object/omit.d.ts +22 -0
  153. package/module/es5/Validate/object/omit.js +39 -0
  154. package/module/es5/Validate/object/optional.d.ts +31 -3
  155. package/module/es5/Validate/object/optional.js +12 -3
  156. package/module/es5/Validate/object/partial.d.ts +25 -0
  157. package/module/es5/Validate/object/partial.js +33 -0
  158. package/module/es5/Validate/object/pick.d.ts +21 -0
  159. package/module/es5/Validate/object/pick.js +45 -0
  160. package/module/es5/Validate/object/required.d.ts +22 -0
  161. package/module/es5/Validate/object/required.js +33 -0
  162. package/module/es5/Validate/set/core.d.ts +24 -0
  163. package/module/es5/Validate/{array → set}/core.js +30 -27
  164. package/module/es5/Validate/set/index.d.ts +1 -0
  165. package/module/es5/Validate/set/index.js +16 -0
  166. package/module/es5/Validate/string/oneOf.d.ts +10 -7
  167. package/module/es5/Validate/string/oneOf.js +8 -6
  168. package/module/es5/Validate/templateLiteral/core.d.ts +55 -0
  169. package/module/es5/Validate/templateLiteral/core.js +114 -0
  170. package/module/es5/Validate/templateLiteral/index.d.ts +1 -0
  171. package/module/es5/Validate/templateLiteral/index.js +16 -0
  172. package/module/es5/Validate/type.d.ts +19 -5
  173. package/module/es5/Validate/unknown/core.d.ts +21 -0
  174. package/module/es5/Validate/unknown/core.js +34 -0
  175. package/module/es5/Validate/unknown/index.d.ts +1 -0
  176. package/module/es5/Validate/unknown/index.js +16 -0
  177. package/package.json +1 -1
  178. package/module/Validate/array/core.d.ts +0 -14
  179. package/module/Validate/array/core.js +0 -43
  180. package/module/Validate/array/core.js.map +0 -1
  181. package/module/es5/Validate/array/core.d.ts +0 -14
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.pick_ = void 0;
7
+ var _core = require("./core");
8
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
9
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
10
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } /**
11
+ * Object validation - pick
12
+ * Returns a new object validator that only checks the specified keys of the
13
+ * source validator. Mirrors `Pick<T, K>` at the type level so consumers like
14
+ * `union()`, `intersection()`, and `SchemaToInterface` see the narrowed shape.
15
+ *
16
+ * The function is exported as `pick_` because the top-level `Object` module
17
+ * already exposes a `pick` runtime helper.
18
+ */
19
+ /**
20
+ * Picks the given keys from an existing object validator and returns a new
21
+ * object validator covering only those keys.
22
+ * @template T - Original object shape
23
+ * @template K - Tuple of keys to pick from the original shape
24
+ * @param {ObjectValidator<T>} validator - Source object validator
25
+ * @param {K} keys - Keys to retain on the new validator
26
+ * @param {string} [message] - Custom error message for the picked validator
27
+ * @returns {ObjectValidator<Pick<T, K[number]>>} - New validator scoped to picked keys
28
+ */
29
+ var pick_ = exports.pick_ = function pick_(validator, keys, message) {
30
+ var sourceShape = validator.shape;
31
+ var nextShape = {};
32
+ var _iterator = _createForOfIteratorHelper(keys),
33
+ _step;
34
+ try {
35
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
36
+ var key = _step.value;
37
+ nextShape[key] = sourceShape[key];
38
+ }
39
+ } catch (err) {
40
+ _iterator.e(err);
41
+ } finally {
42
+ _iterator.f();
43
+ }
44
+ return (0, _core.object)(nextShape, message);
45
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Object validation - required
3
+ * Returns a new object validator where every key is unwrapped from any
4
+ * `optional()` layer, mirroring `Required<T>` at the type level so consumers
5
+ * see all properties as required again.
6
+ */
7
+ import { type ObjectShape, type ObjectValidator } from "./core";
8
+ import type { OptionalValidator } from "./optional";
9
+ type UnwrapOptional<V> = V extends OptionalValidator<infer Inner, infer R> ? (value: Inner) => R : V;
10
+ type RequiredShape<T extends ObjectShape> = {
11
+ [K in keyof T]: UnwrapOptional<T[K]> extends ObjectShape[string] ? UnwrapOptional<T[K]> : T[K];
12
+ };
13
+ /**
14
+ * Strips `optional()` wrappers from every property validator of `validator`.
15
+ * Validators that are not wrapped in `optional()` are kept as-is.
16
+ * @template T - Original object shape
17
+ * @param {ObjectValidator<T>} validator - Source object validator
18
+ * @param {string} [message] - Custom error message for the new validator
19
+ * @returns {ObjectValidator<RequiredShape<T>>} - New validator where every optional layer is removed
20
+ */
21
+ export declare const required: <T extends ObjectShape>(validator: ObjectValidator<T>, message?: string) => ObjectValidator<RequiredShape<T>>;
22
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.required = void 0;
7
+ var _core = require("./core");
8
+ /**
9
+ * Object validation - required
10
+ * Returns a new object validator where every key is unwrapped from any
11
+ * `optional()` layer, mirroring `Required<T>` at the type level so consumers
12
+ * see all properties as required again.
13
+ */
14
+
15
+ /**
16
+ * Strips `optional()` wrappers from every property validator of `validator`.
17
+ * Validators that are not wrapped in `optional()` are kept as-is.
18
+ * @template T - Original object shape
19
+ * @param {ObjectValidator<T>} validator - Source object validator
20
+ * @param {string} [message] - Custom error message for the new validator
21
+ * @returns {ObjectValidator<RequiredShape<T>>} - New validator where every optional layer is removed
22
+ */
23
+ var required = exports.required = function required(validator, message) {
24
+ var sourceShape = validator.shape;
25
+ var nextShape = {};
26
+ for (var _i = 0, _Object$keys = Object.keys(sourceShape); _i < _Object$keys.length; _i++) {
27
+ var key = _Object$keys[_i];
28
+ var current = sourceShape[key];
29
+ var optionalLike = current;
30
+ nextShape[key] = optionalLike.isOptional === true && typeof optionalLike.inner === "function" ? optionalLike.inner : current;
31
+ }
32
+ return (0, _core.object)(nextShape, message);
33
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Set validation core module
3
+ * Provides validation for `Set` instances. The validator can optionally
4
+ * delegate to a per-element validator, mirroring how `arrayOf()` validates
5
+ * each element of an array.
6
+ *
7
+ * The function is exported as `set_` because the top-level `Object` module
8
+ * already exposes a `set` runtime helper.
9
+ */
10
+ import type { ValidateCoreReturnType, ValidateType } from "../../Validate/type";
11
+ type ExtractValidatedType<V> = V extends (value: never) => {
12
+ type: infer T;
13
+ } ? ValidateType<T> : never;
14
+ /**
15
+ * Creates a Set validator. When a per-element validator is supplied, every
16
+ * element of the set must satisfy it; iteration short-circuits at the first
17
+ * failure and surfaces the failing message.
18
+ * @template IV - Validator for set elements
19
+ * @param {IV} [itemValidator] - Validator applied to every element
20
+ * @param {string} [message] - Custom error message for type validation
21
+ * @returns {Function} - Validator function for Set instances
22
+ */
23
+ export declare const set_: <IV extends (value: any) => ValidateCoreReturnType<unknown> = (value: unknown) => ValidateCoreReturnType<unknown>, T = ExtractValidatedType<IV>>(itemValidator?: IV, message?: string) => (value: Set<T>) => ValidateCoreReturnType<Set<T>>;
24
+ export {};
@@ -3,47 +3,50 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.array = void 0;
7
- var _isArray = require("../../Validate/isArray");
8
- var _isNotEmpty = require("../../Validate/isNotEmpty");
9
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
6
+ exports.set_ = void 0;
10
7
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
11
8
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } /**
13
- * Array validation core module
14
- * Provides functionality to validate arrays with type-specific validation rules
9
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
10
+ /**
11
+ * Set validation core module
12
+ * Provides validation for `Set` instances. The validator can optionally
13
+ * delegate to a per-element validator, mirroring how `arrayOf()` validates
14
+ * each element of an array.
15
+ *
16
+ * The function is exported as `set_` because the top-level `Object` module
17
+ * already exposes a `set` runtime helper.
15
18
  */
19
+
16
20
  /**
17
- * Creates an array validator with type-specific validation rules
18
- * @template A - Type of array elements (string | number | boolean)
19
- * @template O - Object containing validation functions for each type
20
- * @param {O} option - Validation functions for each type
21
- * @param {string} [message] - Custom error message for array type validation
22
- * @returns {Function} - Validator function for arrays
21
+ * Creates a Set validator. When a per-element validator is supplied, every
22
+ * element of the set must satisfy it; iteration short-circuits at the first
23
+ * failure and surfaces the failing message.
24
+ * @template IV - Validator for set elements
25
+ * @param {IV} [itemValidator] - Validator applied to every element
26
+ * @param {string} [message] - Custom error message for type validation
27
+ * @returns {Function} - Validator function for Set instances
23
28
  */
24
- var array = exports.array = function array() {
25
- var option = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
26
- var message = arguments.length > 1 ? arguments[1] : undefined;
27
- return function (values) {
28
- if (!(0, _isArray.isArray)(values)) {
29
+ var set_ = exports.set_ = function set_(itemValidator, message) {
30
+ return function (value) {
31
+ if (!(value instanceof Set)) {
29
32
  return {
30
33
  validate: false,
31
34
  message: message !== null && message !== void 0 ? message : "",
32
- type: values
35
+ type: value
33
36
  };
34
37
  }
35
- if ((0, _isNotEmpty.isNotEmpty)(option)) {
36
- var _iterator = _createForOfIteratorHelper(values),
38
+ if (itemValidator) {
39
+ var _iterator = _createForOfIteratorHelper(value),
37
40
  _step;
38
41
  try {
39
42
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
40
- var _value = _step.value;
41
- var validator = option[_typeof(_value)];
42
- if (!(validator !== null && validator !== void 0 && validator(_value).validate)) {
43
+ var item = _step.value;
44
+ var result = itemValidator(item);
45
+ if (!result.validate) {
43
46
  return {
44
47
  validate: false,
45
- message: (validator === null || validator === void 0 ? void 0 : validator(_value).message) || "",
46
- type: values
48
+ message: result.message,
49
+ type: value
47
50
  };
48
51
  }
49
52
  }
@@ -56,7 +59,7 @@ var array = exports.array = function array() {
56
59
  return {
57
60
  validate: true,
58
61
  message: "",
59
- type: values
62
+ type: value
60
63
  };
61
64
  };
62
65
  };
@@ -0,0 +1 @@
1
+ export * from "./core";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _core = require("./core");
7
+ Object.keys(_core).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _core[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return _core[key];
14
+ }
15
+ });
16
+ });
@@ -5,20 +5,23 @@
5
5
  * such as `'standard' | 'squat' | 'decanter' | 'round' | 'tall' | 'flask'`.
6
6
  *
7
7
  * The validator's return type carries the literal union through its `type`
8
- * field directly (instead of going through `Types<T>` which would collapse
9
- * to `"string"`), so consumers like `object()`, `union()`, and `intersection()`
10
- * can preserve the literal union in their inferred types.
8
+ * field as a `LiteralBrand<T>` so that consumers like `object()`, `union()`,
9
+ * and `intersection()` can preserve the literal union in their inferred types.
10
+ * The brand also prevents collisions with reserved type tags such as
11
+ * `"string"`, `"number"`, or `"boolean"` when an allowed value happens to
12
+ * match one of those tag strings.
11
13
  */
14
+ import type { LiteralBrand } from "../../Validate/type";
12
15
  /**
13
16
  * Return type produced by a `oneOf` validator. Structurally compatible with
14
- * `ValidateCoreReturnType<unknown>`, but exposes the literal union directly
15
- * via the `type` field so the inferred type can flow through `object()`,
16
- * `union()`, and `intersection()` without being collapsed to `string`.
17
+ * `ValidateCoreReturnType<unknown>`, but exposes the literal union via a
18
+ * `LiteralBrand` so the inferred type can flow through `object()`, `union()`,
19
+ * and `intersection()` without being collapsed by `ValidateType`.
17
20
  */
18
21
  export interface OneOfReturnType<T extends string> {
19
22
  validate: boolean;
20
23
  message: string;
21
- type: T;
24
+ type: LiteralBrand<T>;
22
25
  }
23
26
  /**
24
27
  * Creates a top-level validator that checks if a string value is one of the
@@ -11,16 +11,18 @@ exports.oneOf = void 0;
11
11
  * such as `'standard' | 'squat' | 'decanter' | 'round' | 'tall' | 'flask'`.
12
12
  *
13
13
  * The validator's return type carries the literal union through its `type`
14
- * field directly (instead of going through `Types<T>` which would collapse
15
- * to `"string"`), so consumers like `object()`, `union()`, and `intersection()`
16
- * can preserve the literal union in their inferred types.
14
+ * field as a `LiteralBrand<T>` so that consumers like `object()`, `union()`,
15
+ * and `intersection()` can preserve the literal union in their inferred types.
16
+ * The brand also prevents collisions with reserved type tags such as
17
+ * `"string"`, `"number"`, or `"boolean"` when an allowed value happens to
18
+ * match one of those tag strings.
17
19
  */
18
20
 
19
21
  /**
20
22
  * Return type produced by a `oneOf` validator. Structurally compatible with
21
- * `ValidateCoreReturnType<unknown>`, but exposes the literal union directly
22
- * via the `type` field so the inferred type can flow through `object()`,
23
- * `union()`, and `intersection()` without being collapsed to `string`.
23
+ * `ValidateCoreReturnType<unknown>`, but exposes the literal union via a
24
+ * `LiteralBrand` so the inferred type can flow through `object()`, `union()`,
25
+ * and `intersection()` without being collapsed by `ValidateType`.
24
26
  */
25
27
 
26
28
  /**
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Template literal validation core module
3
+ * Provides a validator that checks whether a string matches a template
4
+ * literal pattern composed of string fragments and primitive validators
5
+ * (string / number / boolean / bigint). The runtime check is performed by
6
+ * an auto-generated regular expression assembled from the parts, while the
7
+ * inferred type is the corresponding TypeScript template literal type.
8
+ */
9
+ import type { ValidateType } from "../../Validate/type";
10
+ type AnyValidator = (value?: any) => {
11
+ type: unknown;
12
+ };
13
+ /**
14
+ * Allowed parts of a template literal definition. Each element is either a
15
+ * string literal that must appear verbatim, or a primitive validator whose
16
+ * accepted shape is converted to a regex fragment at construction time.
17
+ */
18
+ export type TemplateLiteralPart = string | AnyValidator;
19
+ type ExtractValidatorTag<V> = V extends (value: never) => {
20
+ type: infer T;
21
+ } ? T : never;
22
+ type TagToTemplate<T> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T extends "bigint" ? bigint : ValidateType<T>;
23
+ type PartToTemplate<P> = P extends string ? P : TagToTemplate<ExtractValidatorTag<P>>;
24
+ /**
25
+ * Builds the template literal type produced by joining `Parts`. Each part is
26
+ * mapped to either its literal string value or to the runtime type that the
27
+ * corresponding validator accepts.
28
+ */
29
+ export type BuildTemplateLiteral<Parts extends readonly TemplateLiteralPart[]> = Parts extends readonly [
30
+ infer Head,
31
+ ...infer Tail extends readonly TemplateLiteralPart[]
32
+ ] ? `${Extract<PartToTemplate<Head>, string | number | bigint | boolean>}${BuildTemplateLiteral<Tail>}` : "";
33
+ /**
34
+ * Return type produced by a `templateLiteral` validator. Preserves the
35
+ * literal template string type through the `type` field so consumers like
36
+ * `union()`, `intersection()`, and `SchemaToInterface` can recover it.
37
+ * @template T - The inferred template literal type
38
+ */
39
+ export interface TemplateLiteralReturnType<T extends string> {
40
+ validate: boolean;
41
+ message: string;
42
+ type: T;
43
+ }
44
+ /**
45
+ * Creates a validator that checks whether a value matches a template literal
46
+ * pattern. Each part is either a string literal that must appear verbatim or
47
+ * a primitive validator (string / number / boolean / bigint) that contributes
48
+ * a regex fragment.
49
+ * @template Parts - Tuple describing the template parts
50
+ * @param {Parts} parts - Tuple of literal strings and primitive validators
51
+ * @param {string} [message] - Custom error message for validation failure
52
+ * @returns {Function} - Validator function for template literal strings
53
+ */
54
+ export declare const templateLiteral: <const Parts extends readonly TemplateLiteralPart[]>(parts: Parts, message?: string) => (value: BuildTemplateLiteral<Parts>) => TemplateLiteralReturnType<BuildTemplateLiteral<Parts>>;
55
+ export {};
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.templateLiteral = void 0;
7
+ var _templateObject, _templateObject2, _templateObject3;
8
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
9
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
10
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
11
+ function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
12
+ /**
13
+ * Template literal validation core module
14
+ * Provides a validator that checks whether a string matches a template
15
+ * literal pattern composed of string fragments and primitive validators
16
+ * (string / number / boolean / bigint). The runtime check is performed by
17
+ * an auto-generated regular expression assembled from the parts, while the
18
+ * inferred type is the corresponding TypeScript template literal type.
19
+ */
20
+
21
+ // biome-ignore lint/suspicious/noExplicitAny: validator signatures vary
22
+
23
+ /**
24
+ * Allowed parts of a template literal definition. Each element is either a
25
+ * string literal that must appear verbatim, or a primitive validator whose
26
+ * accepted shape is converted to a regex fragment at construction time.
27
+ */
28
+
29
+ /**
30
+ * Builds the template literal type produced by joining `Parts`. Each part is
31
+ * mapped to either its literal string value or to the runtime type that the
32
+ * corresponding validator accepts.
33
+ */
34
+
35
+ /**
36
+ * Return type produced by a `templateLiteral` validator. Preserves the
37
+ * literal template string type through the `type` field so consumers like
38
+ * `union()`, `intersection()`, and `SchemaToInterface` can recover it.
39
+ * @template T - The inferred template literal type
40
+ */
41
+
42
+ var escapeRegex = function escapeRegex(input) {
43
+ return input.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw(_templateObject || (_templateObject = _taggedTemplateLiteral(["$&"], ["\\$&"]))));
44
+ };
45
+ var tagToPattern = function tagToPattern(tag) {
46
+ switch (tag) {
47
+ case "string":
48
+ {
49
+ return ".*?";
50
+ }
51
+ case "number":
52
+ {
53
+ return String.raw(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["-?(?:d+.d+|d+(?:.d*)?|.d+)"], ["-?(?:\\d+\\.\\d+|\\d+(?:\\.\\d*)?|\\.\\d+)"])));
54
+ }
55
+ case "boolean":
56
+ {
57
+ return "(?:true|false)";
58
+ }
59
+ case "bigint":
60
+ {
61
+ return String.raw(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["-?d+"], ["-?\\d+"])));
62
+ }
63
+ default:
64
+ {
65
+ return ".+?";
66
+ }
67
+ }
68
+ };
69
+ var detectValidatorTag = function detectValidatorTag(validator) {
70
+ var result = validator();
71
+ return result === null || result === void 0 ? void 0 : result.type;
72
+ };
73
+
74
+ /**
75
+ * Creates a validator that checks whether a value matches a template literal
76
+ * pattern. Each part is either a string literal that must appear verbatim or
77
+ * a primitive validator (string / number / boolean / bigint) that contributes
78
+ * a regex fragment.
79
+ * @template Parts - Tuple describing the template parts
80
+ * @param {Parts} parts - Tuple of literal strings and primitive validators
81
+ * @param {string} [message] - Custom error message for validation failure
82
+ * @returns {Function} - Validator function for template literal strings
83
+ */
84
+ var templateLiteral = exports.templateLiteral = function templateLiteral(parts, message) {
85
+ var pattern = "^";
86
+ var _iterator = _createForOfIteratorHelper(parts),
87
+ _step;
88
+ try {
89
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
90
+ var part = _step.value;
91
+ pattern += typeof part === "string" ? escapeRegex(part) : "(?:".concat(tagToPattern(detectValidatorTag(part)), ")");
92
+ }
93
+ } catch (err) {
94
+ _iterator.e(err);
95
+ } finally {
96
+ _iterator.f();
97
+ }
98
+ pattern += "$";
99
+ var regex = new RegExp(pattern);
100
+ return function (value) {
101
+ if (typeof value !== "string" || !regex.test(value)) {
102
+ return {
103
+ validate: false,
104
+ message: message !== null && message !== void 0 ? message : "",
105
+ type: value
106
+ };
107
+ }
108
+ return {
109
+ validate: true,
110
+ message: "",
111
+ type: value
112
+ };
113
+ };
114
+ };
@@ -0,0 +1 @@
1
+ export * from "./core";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _core = require("./core");
7
+ Object.keys(_core).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _core[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return _core[key];
14
+ }
15
+ });
16
+ });
@@ -1,11 +1,12 @@
1
1
  export type _Types<T> = T extends string ? "string" : T extends number ? "number" : T extends boolean ? "boolean" : T;
2
2
  export type _Types2<T> = T extends undefined ? "undefined" : T extends null ? "null" : T;
3
+ export type _Types3<T> = T extends bigint ? "bigint" : T;
3
4
  /**
4
5
  * Maps TypeScript types to their string literal representations
5
6
  * @template T - The type to map
6
- * @returns "string" for string, "number" for number, "boolean" for boolean, or the original type T otherwise
7
+ * @returns "string" for string, "number" for number, "boolean" for boolean, "bigint" for bigint, or the original type T otherwise
7
8
  */
8
- export type Types<T> = T extends string | number | boolean ? _Types<T> : T extends undefined | null ? _Types2<T> : T;
9
+ export type Types<T> = T extends string | number | boolean ? _Types<T> : T extends undefined | null ? _Types2<T> : T extends bigint ? _Types3<T> : T;
9
10
  /**
10
11
  * Core validation result type including validation status, message, and type information
11
12
  * @template T - The type being validated
@@ -29,15 +30,28 @@ export interface ValidateReturnType<T> {
29
30
  * @template T - The type of value to validate
30
31
  */
31
32
  export type ValidateFunctionType<T> = (value: T) => boolean;
33
+ declare const LITERAL_BRAND: unique symbol;
34
+ /**
35
+ * Branded literal type used by validators (such as `oneOf`) that need to keep
36
+ * a string literal verbatim through `ValidateType`. The brand prevents the
37
+ * literal from colliding with reserved type tags like `"string"`, `"number"`,
38
+ * or `"boolean"` when the same string also happens to name a primitive type.
39
+ * @template T - The literal value preserved by the brand
40
+ */
41
+ export type LiteralBrand<T extends string> = T & {
42
+ readonly [LITERAL_BRAND]: T;
43
+ };
32
44
  export type _ValidateType<T> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T;
33
45
  export type _ValidateType2<T> = T extends "undefined" ? undefined : T extends "null" ? null : T;
46
+ export type _ValidateType3<T> = T extends "bigint" ? bigint : T extends "any" ? any : T extends "unknown" ? unknown : T extends "never" ? never : T;
34
47
  /**
35
48
  * Maps string literal type names back to their TypeScript types
36
- * @template T - The string literal type name ("string", "number", "boolean")
37
- * @returns The corresponding TypeScript type (string, number, boolean) or the original type T
49
+ * @template T - The string literal type name ("string", "number", "boolean", "bigint", "undefined", "null", "any", "unknown", "never")
50
+ * @returns The corresponding TypeScript type, the unwrapped literal when `T` is a `LiteralBrand`, or the original type `T` when no tag matches
38
51
  */
39
- export type ValidateType<T> = T extends "string" | "number" | "boolean" ? _ValidateType<T> : T extends "undefined" | "null" ? _ValidateType2<T> : T;
52
+ export type ValidateType<T> = T extends LiteralBrand<infer L> ? L : T extends "string" | "number" | "boolean" ? _ValidateType<T> : T extends "undefined" | "null" ? _ValidateType2<T> : T extends "bigint" | "any" | "unknown" | "never" ? _ValidateType3<T> : T;
40
53
  export type SchemaToInterface<T extends (value: any) => ValidateCoreReturnType<any>> = ValidateType<ReturnType<T>["type"]>;
41
54
  export type OptionalKeys<T> = {
42
55
  [K in keyof T]: undefined extends T[K] ? K : never;
43
56
  }[keyof T];
57
+ export {};
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Unknown validation core module
3
+ * Provides a validator that accepts any value but exposes it as `unknown`
4
+ * to keep callers honest about narrowing before use.
5
+ */
6
+ /**
7
+ * Return type produced by an `unknown` validator. Exposes the literal
8
+ * `"unknown"` tag through the `type` field so `ValidateType<"unknown">` can
9
+ * map it back to the `unknown` runtime type when consumed by downstream
10
+ * helpers.
11
+ */
12
+ export interface UnknownReturnType {
13
+ validate: boolean;
14
+ message: string;
15
+ type: "unknown";
16
+ }
17
+ /**
18
+ * Creates a validator that accepts any value but typed as unknown
19
+ * @returns {Function} - Validator that always succeeds
20
+ */
21
+ export declare const unknown: () => ((value: unknown) => UnknownReturnType);
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.unknown = void 0;
7
+ /**
8
+ * Unknown validation core module
9
+ * Provides a validator that accepts any value but exposes it as `unknown`
10
+ * to keep callers honest about narrowing before use.
11
+ */
12
+
13
+ /**
14
+ * Return type produced by an `unknown` validator. Exposes the literal
15
+ * `"unknown"` tag through the `type` field so `ValidateType<"unknown">` can
16
+ * map it back to the `unknown` runtime type when consumed by downstream
17
+ * helpers.
18
+ */
19
+
20
+ var unknownValidator = function unknownValidator(_value) {
21
+ return {
22
+ validate: true,
23
+ message: "",
24
+ type: "unknown"
25
+ };
26
+ };
27
+
28
+ /**
29
+ * Creates a validator that accepts any value but typed as unknown
30
+ * @returns {Function} - Validator that always succeeds
31
+ */
32
+ var unknown = exports.unknown = function unknown() {
33
+ return unknownValidator;
34
+ };
@@ -0,0 +1 @@
1
+ export * from "./core";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _core = require("./core");
7
+ Object.keys(_core).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _core[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return _core[key];
14
+ }
15
+ });
16
+ });
package/package.json CHANGED
@@ -226,5 +226,5 @@
226
226
  },
227
227
  "type": "module",
228
228
  "types": "module/index.d.ts",
229
- "version": "2.19.0"
229
+ "version": "3.0.0"
230
230
  }
@@ -1,14 +0,0 @@
1
- /**
2
- * Array validation core module
3
- * Provides functionality to validate arrays with type-specific validation rules
4
- */
5
- import type { Types, ValidateCoreReturnType, ValidateType } from "../../Validate/type";
6
- /**
7
- * Creates an array validator with type-specific validation rules
8
- * @template A - Type of array elements (string | number | boolean)
9
- * @template O - Object containing validation functions for each type
10
- * @param {O} option - Validation functions for each type
11
- * @param {string} [message] - Custom error message for array type validation
12
- * @returns {Function} - Validator function for arrays
13
- */
14
- export declare const array: <A extends string | number | boolean, O extends { [P in Types<A>]: (value: ValidateType<P>) => ValidateCoreReturnType<ValidateType<P>>; } = { [P in Types<A>]: (value: ValidateType<P>) => ValidateCoreReturnType<ValidateType<P>>; }>(option?: O, message?: string) => (values: A[]) => ValidateCoreReturnType<A[]>;