umt 2.19.0 → 2.20.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.
- package/module/Validate/any/core.d.ts +21 -0
- package/module/Validate/any/core.js +19 -0
- package/module/Validate/any/core.js.map +1 -0
- package/module/Validate/any/index.d.ts +1 -0
- package/module/Validate/any/index.js +2 -0
- package/module/Validate/any/index.js.map +1 -0
- package/module/Validate/array/arrayOf.d.ts +6 -1
- package/module/Validate/array/arrayOf.js +1 -0
- package/module/Validate/array/arrayOf.js.map +1 -1
- package/module/Validate/bigint/core.d.ts +24 -0
- package/module/Validate/bigint/core.js +37 -0
- package/module/Validate/bigint/core.js.map +1 -0
- package/module/Validate/bigint/index.d.ts +1 -0
- package/module/Validate/bigint/index.js +2 -0
- package/module/Validate/bigint/index.js.map +1 -0
- package/module/Validate/date/core.d.ts +14 -0
- package/module/Validate/date/core.js +29 -0
- package/module/Validate/date/core.js.map +1 -0
- package/module/Validate/date/index.d.ts +1 -0
- package/module/Validate/date/index.js +2 -0
- package/module/Validate/date/index.js.map +1 -0
- package/module/Validate/file/core.d.ts +13 -0
- package/module/Validate/file/core.js +32 -0
- package/module/Validate/file/core.js.map +1 -0
- package/module/Validate/file/index.d.ts +1 -0
- package/module/Validate/file/index.js +2 -0
- package/module/Validate/file/index.js.map +1 -0
- package/module/Validate/function/core.d.ts +75 -0
- package/module/Validate/function/core.js +66 -0
- package/module/Validate/function/core.js.map +1 -0
- package/module/Validate/function/index.d.ts +1 -0
- package/module/Validate/function/index.js +2 -0
- package/module/Validate/function/index.js.map +1 -0
- package/module/Validate/index.d.ts +11 -0
- package/module/Validate/index.js +11 -0
- package/module/Validate/index.js.map +1 -1
- package/module/Validate/instanceof/core.d.ts +19 -0
- package/module/Validate/instanceof/core.js +32 -0
- package/module/Validate/instanceof/core.js.map +1 -0
- package/module/Validate/instanceof/index.d.ts +1 -0
- package/module/Validate/instanceof/index.js +2 -0
- package/module/Validate/instanceof/index.js.map +1 -0
- package/module/Validate/map/core.d.ts +24 -0
- package/module/Validate/map/core.js +57 -0
- package/module/Validate/map/core.js.map +1 -0
- package/module/Validate/map/index.d.ts +1 -0
- package/module/Validate/map/index.js +2 -0
- package/module/Validate/map/index.js.map +1 -0
- package/module/Validate/never/core.d.ts +22 -0
- package/module/Validate/never/core.js +23 -0
- package/module/Validate/never/core.js.map +1 -0
- package/module/Validate/never/index.d.ts +1 -0
- package/module/Validate/never/index.js +2 -0
- package/module/Validate/never/index.js.map +1 -0
- package/module/Validate/object/core.d.ts +22 -4
- package/module/Validate/object/core.js +5 -3
- package/module/Validate/object/core.js.map +1 -1
- package/module/Validate/object/index.d.ts +4 -0
- package/module/Validate/object/index.js +4 -0
- package/module/Validate/object/index.js.map +1 -1
- package/module/Validate/object/nullable.d.ts +12 -2
- package/module/Validate/object/nullable.js +2 -2
- package/module/Validate/object/nullable.js.map +1 -1
- package/module/Validate/object/omit.d.ts +22 -0
- package/module/Validate/object/omit.js +33 -0
- package/module/Validate/object/omit.js.map +1 -0
- package/module/Validate/object/optional.d.ts +31 -3
- package/module/Validate/object/optional.js +7 -5
- package/module/Validate/object/optional.js.map +1 -1
- package/module/Validate/object/partial.d.ts +25 -0
- package/module/Validate/object/partial.js +29 -0
- package/module/Validate/object/partial.js.map +1 -0
- package/module/Validate/object/pick.d.ts +21 -0
- package/module/Validate/object/pick.js +29 -0
- package/module/Validate/object/pick.js.map +1 -0
- package/module/Validate/object/required.d.ts +22 -0
- package/module/Validate/object/required.js +30 -0
- package/module/Validate/object/required.js.map +1 -0
- package/module/Validate/set/core.d.ts +24 -0
- package/module/Validate/set/core.js +47 -0
- package/module/Validate/set/core.js.map +1 -0
- package/module/Validate/set/index.d.ts +1 -0
- package/module/Validate/set/index.js +2 -0
- package/module/Validate/set/index.js.map +1 -0
- package/module/Validate/templateLiteral/core.d.ts +55 -0
- package/module/Validate/templateLiteral/core.js +68 -0
- package/module/Validate/templateLiteral/core.js.map +1 -0
- package/module/Validate/templateLiteral/index.d.ts +1 -0
- package/module/Validate/templateLiteral/index.js +2 -0
- package/module/Validate/templateLiteral/index.js.map +1 -0
- package/module/Validate/type.d.ts +7 -5
- package/module/Validate/unknown/core.d.ts +21 -0
- package/module/Validate/unknown/core.js +16 -0
- package/module/Validate/unknown/core.js.map +1 -0
- package/module/Validate/unknown/index.d.ts +1 -0
- package/module/Validate/unknown/index.js +2 -0
- package/module/Validate/unknown/index.js.map +1 -0
- package/module/es5/Validate/any/core.d.ts +21 -0
- package/module/es5/Validate/any/core.js +36 -0
- package/module/es5/Validate/any/index.d.ts +1 -0
- package/module/es5/Validate/any/index.js +16 -0
- package/module/es5/Validate/array/arrayOf.d.ts +6 -1
- package/module/es5/Validate/array/arrayOf.js +1 -0
- package/module/es5/Validate/bigint/core.d.ts +24 -0
- package/module/es5/Validate/bigint/core.js +65 -0
- package/module/es5/Validate/bigint/index.d.ts +1 -0
- package/module/es5/Validate/bigint/index.js +16 -0
- package/module/es5/Validate/date/core.d.ts +14 -0
- package/module/es5/Validate/date/core.js +35 -0
- package/module/es5/Validate/date/index.d.ts +1 -0
- package/module/es5/Validate/date/index.js +16 -0
- package/module/es5/Validate/file/core.d.ts +13 -0
- package/module/es5/Validate/file/core.js +39 -0
- package/module/es5/Validate/file/index.d.ts +1 -0
- package/module/es5/Validate/file/index.js +16 -0
- package/module/es5/Validate/function/core.d.ts +75 -0
- package/module/es5/Validate/function/core.js +125 -0
- package/module/es5/Validate/function/index.d.ts +1 -0
- package/module/es5/Validate/function/index.js +16 -0
- package/module/es5/Validate/index.d.ts +11 -0
- package/module/es5/Validate/index.js +121 -0
- package/module/es5/Validate/instanceof/core.d.ts +19 -0
- package/module/es5/Validate/instanceof/core.js +40 -0
- package/module/es5/Validate/instanceof/index.d.ts +1 -0
- package/module/es5/Validate/instanceof/index.js +16 -0
- package/module/es5/Validate/map/core.d.ts +24 -0
- package/module/es5/Validate/map/core.js +81 -0
- package/module/es5/Validate/map/index.d.ts +1 -0
- package/module/es5/Validate/map/index.js +16 -0
- package/module/es5/Validate/never/core.d.ts +22 -0
- package/module/es5/Validate/never/core.js +35 -0
- package/module/es5/Validate/never/index.d.ts +1 -0
- package/module/es5/Validate/never/index.js +16 -0
- package/module/es5/Validate/object/core.d.ts +22 -4
- package/module/es5/Validate/object/core.js +14 -2
- package/module/es5/Validate/object/index.d.ts +4 -0
- package/module/es5/Validate/object/index.js +44 -0
- package/module/es5/Validate/object/nullable.d.ts +12 -2
- package/module/es5/Validate/object/nullable.js +2 -2
- package/module/es5/Validate/object/omit.d.ts +22 -0
- package/module/es5/Validate/object/omit.js +39 -0
- package/module/es5/Validate/object/optional.d.ts +31 -3
- package/module/es5/Validate/object/optional.js +12 -3
- package/module/es5/Validate/object/partial.d.ts +25 -0
- package/module/es5/Validate/object/partial.js +33 -0
- package/module/es5/Validate/object/pick.d.ts +21 -0
- package/module/es5/Validate/object/pick.js +45 -0
- package/module/es5/Validate/object/required.d.ts +22 -0
- package/module/es5/Validate/object/required.js +33 -0
- package/module/es5/Validate/set/core.d.ts +24 -0
- package/module/es5/Validate/set/core.js +65 -0
- package/module/es5/Validate/set/index.d.ts +1 -0
- package/module/es5/Validate/set/index.js +16 -0
- package/module/es5/Validate/templateLiteral/core.d.ts +55 -0
- package/module/es5/Validate/templateLiteral/core.js +114 -0
- package/module/es5/Validate/templateLiteral/index.d.ts +1 -0
- package/module/es5/Validate/templateLiteral/index.js +16 -0
- package/module/es5/Validate/type.d.ts +7 -5
- package/module/es5/Validate/unknown/core.d.ts +21 -0
- package/module/es5/Validate/unknown/core.js +34 -0
- package/module/es5/Validate/unknown/index.d.ts +1 -0
- package/module/es5/Validate/unknown/index.js +16 -0
- package/package.json +1 -1
|
@@ -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
|
+
});
|
|
@@ -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
|
|
@@ -31,12 +32,13 @@ export interface ValidateReturnType<T> {
|
|
|
31
32
|
export type ValidateFunctionType<T> = (value: T) => boolean;
|
|
32
33
|
export type _ValidateType<T> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T;
|
|
33
34
|
export type _ValidateType2<T> = T extends "undefined" ? undefined : T extends "null" ? null : T;
|
|
35
|
+
export type _ValidateType3<T> = T extends "bigint" ? bigint : T extends "any" ? any : T extends "unknown" ? unknown : T extends "never" ? never : T;
|
|
34
36
|
/**
|
|
35
37
|
* 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
|
|
38
|
+
* @template T - The string literal type name ("string", "number", "boolean", "bigint", "undefined", "null", "any", "unknown", "never")
|
|
39
|
+
* @returns The corresponding TypeScript type or the original type T when no tag matches
|
|
38
40
|
*/
|
|
39
|
-
export type ValidateType<T> = T extends "string" | "number" | "boolean" ? _ValidateType<T> : T extends "undefined" | "null" ? _ValidateType2<T> : T;
|
|
41
|
+
export type ValidateType<T> = T extends "string" | "number" | "boolean" ? _ValidateType<T> : T extends "undefined" | "null" ? _ValidateType2<T> : T extends "bigint" | "any" | "unknown" | "never" ? _ValidateType3<T> : T;
|
|
40
42
|
export type SchemaToInterface<T extends (value: any) => ValidateCoreReturnType<any>> = ValidateType<ReturnType<T>["type"]>;
|
|
41
43
|
export type OptionalKeys<T> = {
|
|
42
44
|
[K in keyof T]: undefined extends T[K] ? K : never;
|
|
@@ -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