@pangza/core 1.0.1 → 1.1.5
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/dist/{Service → Application}/BaseService.d.ts +1 -1
- package/dist/Application/BaseService.d.ts.map +1 -0
- package/dist/Application/BaseService.js.map +1 -0
- package/dist/Application/bean.d.ts.map +1 -0
- package/dist/Application/bean.js.map +1 -0
- package/dist/Application/container.d.ts.map +1 -0
- package/dist/Application/container.js.map +1 -0
- package/dist/Application/index.d.ts +9 -6
- package/dist/Application/index.d.ts.map +1 -1
- package/dist/Application/index.js +28 -34
- package/dist/Application/index.js.map +1 -1
- package/dist/{Service/decorators.d.ts → Application/iocDecorators.d.ts} +1 -13
- package/dist/Application/iocDecorators.d.ts.map +1 -0
- package/dist/{Service/decorators.js → Application/iocDecorators.js} +4 -74
- package/dist/Application/iocDecorators.js.map +1 -0
- package/dist/{Service/types.d.ts → Application/iocTypes.d.ts} +1 -1
- package/dist/Application/iocTypes.d.ts.map +1 -0
- package/dist/{Service/types.js → Application/iocTypes.js} +1 -1
- package/dist/Application/iocTypes.js.map +1 -0
- package/dist/Application/lifecycle.js +3 -3
- package/dist/Application/lifecycle.js.map +1 -1
- package/dist/Exception/handler.d.ts.map +1 -1
- package/dist/Exception/handler.js +7 -5
- package/dist/Exception/handler.js.map +1 -1
- package/dist/config/ConditionOnProperty.js +1 -1
- package/dist/config/ConditionOnProperty.js.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -5
- package/dist/index.js.map +1 -1
- package/package.json +76 -5
- package/dist/Service/BaseService.d.ts.map +0 -1
- package/dist/Service/BaseService.js.map +0 -1
- package/dist/Service/MapperType.d.ts +0 -22
- package/dist/Service/MapperType.d.ts.map +0 -1
- package/dist/Service/MapperType.js +0 -50
- package/dist/Service/MapperType.js.map +0 -1
- package/dist/Service/bean.d.ts.map +0 -1
- package/dist/Service/bean.js.map +0 -1
- package/dist/Service/container.d.ts.map +0 -1
- package/dist/Service/container.js.map +0 -1
- package/dist/Service/decorators.d.ts.map +0 -1
- package/dist/Service/decorators.js.map +0 -1
- package/dist/Service/index.d.ts +0 -10
- package/dist/Service/index.d.ts.map +0 -1
- package/dist/Service/index.js +0 -22
- package/dist/Service/index.js.map +0 -1
- package/dist/Service/types.d.ts.map +0 -1
- package/dist/Service/types.js.map +0 -1
- package/dist/Validate/decorators.d.ts +0 -36
- package/dist/Validate/decorators.d.ts.map +0 -1
- package/dist/Validate/decorators.js +0 -95
- package/dist/Validate/decorators.js.map +0 -1
- package/dist/Validate/engine.d.ts +0 -20
- package/dist/Validate/engine.d.ts.map +0 -1
- package/dist/Validate/engine.js +0 -94
- package/dist/Validate/engine.js.map +0 -1
- package/dist/Validate/index.d.ts +0 -6
- package/dist/Validate/index.d.ts.map +0 -1
- package/dist/Validate/index.js +0 -28
- package/dist/Validate/index.js.map +0 -1
- package/dist/Validate/rules.d.ts +0 -20
- package/dist/Validate/rules.d.ts.map +0 -1
- package/dist/Validate/rules.js +0 -129
- package/dist/Validate/rules.js.map +0 -1
- package/dist/Validate/types.d.ts +0 -28
- package/dist/Validate/types.d.ts.map +0 -1
- package/dist/Validate/types.js +0 -18
- package/dist/Validate/types.js.map +0 -1
- /package/dist/{Service → Application}/BaseService.js +0 -0
- /package/dist/{Service → Application}/bean.d.ts +0 -0
- /package/dist/{Service → Application}/bean.js +0 -0
- /package/dist/{Service → Application}/container.d.ts +0 -0
- /package/dist/{Service → Application}/container.js +0 -0
package/dist/Validate/engine.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateHandler = validateHandler;
|
|
4
|
-
exports.validateHandlerSync = validateHandlerSync;
|
|
5
|
-
exports.validateMethodArgs = validateMethodArgs;
|
|
6
|
-
const decorators_1 = require("./decorators");
|
|
7
|
-
const types_1 = require("./types");
|
|
8
|
-
function isClassSchema(schema) {
|
|
9
|
-
return typeof schema === "function";
|
|
10
|
-
}
|
|
11
|
-
function resolveRules(schema) {
|
|
12
|
-
if (isClassSchema(schema)) {
|
|
13
|
-
return (0, decorators_1.getClassRules)(schema);
|
|
14
|
-
}
|
|
15
|
-
return schema ?? {};
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* 函数式校验(对齐 Spring Validator / @Valid)。
|
|
19
|
-
* 失败抛出 ValidationError。
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* validateHandler(body, CreateUserDTO);
|
|
23
|
-
* validateHandler(body, {
|
|
24
|
-
* email: [email('邮箱不对'), notNull()],
|
|
25
|
-
* age: [min(1), max(120)],
|
|
26
|
-
* });
|
|
27
|
-
*/
|
|
28
|
-
async function validateHandler(data, schema) {
|
|
29
|
-
const rules = resolveRules(schema);
|
|
30
|
-
const errors = [];
|
|
31
|
-
const obj = data && typeof data === "object" ? data : {};
|
|
32
|
-
for (const [field, fieldRules] of Object.entries(rules)) {
|
|
33
|
-
const list = fieldRules;
|
|
34
|
-
const value = obj[field];
|
|
35
|
-
for (const rule of list) {
|
|
36
|
-
const ok = await rule.validate(value, data);
|
|
37
|
-
if (!ok) {
|
|
38
|
-
errors.push({
|
|
39
|
-
field,
|
|
40
|
-
message: rule.message,
|
|
41
|
-
rule: rule.name,
|
|
42
|
-
});
|
|
43
|
-
break; // 同一字段遇错即停,类似默认 Spring 行为可简化
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (errors.length > 0) {
|
|
48
|
-
throw new types_1.ValidationError(errors);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/** 同步版本:规则内不要用 async */
|
|
52
|
-
function validateHandlerSync(data, schema) {
|
|
53
|
-
const rules = resolveRules(schema);
|
|
54
|
-
const errors = [];
|
|
55
|
-
const obj = data && typeof data === "object" ? data : {};
|
|
56
|
-
for (const [field, fieldRules] of Object.entries(rules)) {
|
|
57
|
-
const value = obj[field];
|
|
58
|
-
for (const rule of fieldRules) {
|
|
59
|
-
const result = rule.validate(value, data);
|
|
60
|
-
const ok = typeof result === "boolean" ? result : false;
|
|
61
|
-
if (!ok) {
|
|
62
|
-
errors.push({ field, message: rule.message, rule: rule.name });
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (errors.length > 0) {
|
|
68
|
-
throw new types_1.ValidationError(errors);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const SKIP_TYPES = new Set([
|
|
72
|
-
Object,
|
|
73
|
-
String,
|
|
74
|
-
Number,
|
|
75
|
-
Boolean,
|
|
76
|
-
Array,
|
|
77
|
-
Function,
|
|
78
|
-
]);
|
|
79
|
-
/**
|
|
80
|
-
* 按 design:paramtypes 校验方法入参(供 Application 调用)。
|
|
81
|
-
*/
|
|
82
|
-
async function validateMethodArgs(args, paramTypes = []) {
|
|
83
|
-
for (let i = 0; i < paramTypes.length; i++) {
|
|
84
|
-
const Type = paramTypes[i];
|
|
85
|
-
if (!Type || SKIP_TYPES.has(Type))
|
|
86
|
-
continue;
|
|
87
|
-
// Express Request 等无规则的类直接跳过
|
|
88
|
-
const rules = (0, decorators_1.getClassRules)(Type);
|
|
89
|
-
if (Object.keys(rules).length === 0)
|
|
90
|
-
continue;
|
|
91
|
-
await validateHandler(args[i], Type);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=engine.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/Validate/engine.ts"],"names":[],"mappings":";;AA+BA,0CA4BC;AAGD,kDAwBC;AAcD,gDAYC;AAhHD,6CAA6C;AAO7C,mCAA0C;AAE1C,SAAS,aAAa,CAAC,MAAsB;IAC3C,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC;AACtC,CAAC;AAED,SAAS,YAAY,CAAC,MAAsB;IAC1C,I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;QAC3B,IAAI,CAAC,IAAI,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,SAAS;QAC5C,6BAA6B;QAC7B,MAAM,KAAK,GAAG,IAAA,0BAAa,EAAC,IAAI,CAAC,CAAC;QAClC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QAC9C,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
package/dist/Validate/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { NotNull, Min, Max, Email, Phone, Custom, Validate, getClassRules, isMethodValidate, getMethodParamTypes, } from "./decorators";
|
|
2
|
-
export { notNull, min, max, email, phone, custom, } from "./rules";
|
|
3
|
-
export { validateHandler, validateHandlerSync, validateMethodArgs, } from "./engine";
|
|
4
|
-
export { ValidationError } from "./types";
|
|
5
|
-
export type { ValidateRule, RuleOptions, FieldError, ClassRuleMap, ValidatorParam, } from "./types";
|
|
6
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Validate/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,GAAG,EACH,GAAG,EACH,KAAK,EACL,KAAK,EACL,MAAM,EACN,QAAQ,EACR,aAAa,EACb,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,OAAO,EACP,GAAG,EACH,GAAG,EACH,KAAK,EACL,KAAK,EACL,MAAM,GACP,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,YAAY,EACV,YAAY,EACZ,WAAW,EACX,UAAU,EACV,YAAY,EACZ,cAAc,GACf,MAAM,SAAS,CAAC"}
|
package/dist/Validate/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationError = exports.validateMethodArgs = exports.validateHandlerSync = exports.validateHandler = exports.custom = exports.phone = exports.email = exports.max = exports.min = exports.notNull = exports.getMethodParamTypes = exports.isMethodValidate = exports.getClassRules = exports.Validate = exports.Custom = exports.Phone = exports.Email = exports.Max = exports.Min = exports.NotNull = void 0;
|
|
4
|
-
var decorators_1 = require("./decorators");
|
|
5
|
-
Object.defineProperty(exports, "NotNull", { enumerable: true, get: function () { return decorators_1.NotNull; } });
|
|
6
|
-
Object.defineProperty(exports, "Min", { enumerable: true, get: function () { return decorators_1.Min; } });
|
|
7
|
-
Object.defineProperty(exports, "Max", { enumerable: true, get: function () { return decorators_1.Max; } });
|
|
8
|
-
Object.defineProperty(exports, "Email", { enumerable: true, get: function () { return decorators_1.Email; } });
|
|
9
|
-
Object.defineProperty(exports, "Phone", { enumerable: true, get: function () { return decorators_1.Phone; } });
|
|
10
|
-
Object.defineProperty(exports, "Custom", { enumerable: true, get: function () { return decorators_1.Custom; } });
|
|
11
|
-
Object.defineProperty(exports, "Validate", { enumerable: true, get: function () { return decorators_1.Validate; } });
|
|
12
|
-
Object.defineProperty(exports, "getClassRules", { enumerable: true, get: function () { return decorators_1.getClassRules; } });
|
|
13
|
-
Object.defineProperty(exports, "isMethodValidate", { enumerable: true, get: function () { return decorators_1.isMethodValidate; } });
|
|
14
|
-
Object.defineProperty(exports, "getMethodParamTypes", { enumerable: true, get: function () { return decorators_1.getMethodParamTypes; } });
|
|
15
|
-
var rules_1 = require("./rules");
|
|
16
|
-
Object.defineProperty(exports, "notNull", { enumerable: true, get: function () { return rules_1.notNull; } });
|
|
17
|
-
Object.defineProperty(exports, "min", { enumerable: true, get: function () { return rules_1.min; } });
|
|
18
|
-
Object.defineProperty(exports, "max", { enumerable: true, get: function () { return rules_1.max; } });
|
|
19
|
-
Object.defineProperty(exports, "email", { enumerable: true, get: function () { return rules_1.email; } });
|
|
20
|
-
Object.defineProperty(exports, "phone", { enumerable: true, get: function () { return rules_1.phone; } });
|
|
21
|
-
Object.defineProperty(exports, "custom", { enumerable: true, get: function () { return rules_1.custom; } });
|
|
22
|
-
var engine_1 = require("./engine");
|
|
23
|
-
Object.defineProperty(exports, "validateHandler", { enumerable: true, get: function () { return engine_1.validateHandler; } });
|
|
24
|
-
Object.defineProperty(exports, "validateHandlerSync", { enumerable: true, get: function () { return engine_1.validateHandlerSync; } });
|
|
25
|
-
Object.defineProperty(exports, "validateMethodArgs", { enumerable: true, get: function () { return engine_1.validateMethodArgs; } });
|
|
26
|
-
var types_1 = require("./types");
|
|
27
|
-
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return types_1.ValidationError; } });
|
|
28
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Validate/index.ts"],"names":[],"mappings":";;;AAAA,2CAWsB;AAVpB,qGAAA,OAAO,OAAA;AACP,iGAAA,GAAG,OAAA;AACH,iGAAA,GAAG,OAAA;AACH,mGAAA,KAAK,OAAA;AACL,mGAAA,KAAK,OAAA;AACL,oGAAA,MAAM,OAAA;AACN,sGAAA,QAAQ,OAAA;AACR,2GAAA,aAAa,OAAA;AACb,8GAAA,gBAAgB,OAAA;AAChB,iHAAA,mBAAmB,OAAA;AAErB,iCAOiB;AANf,gGAAA,OAAO,OAAA;AACP,4FAAA,GAAG,OAAA;AACH,4FAAA,GAAG,OAAA;AACH,8FAAA,KAAK,OAAA;AACL,8FAAA,KAAK,OAAA;AACL,+FAAA,MAAM,OAAA;AAER,mCAIkB;AAHhB,yGAAA,eAAe,OAAA;AACf,6GAAA,mBAAmB,OAAA;AACnB,4GAAA,kBAAkB,OAAA;AAEpB,iCAA0C;AAAjC,wGAAA,eAAe,OAAA"}
|
package/dist/Validate/rules.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { RuleOptions, ValidateRule } from "./types";
|
|
2
|
-
/** 非空(undefined / null / 空字符串) */
|
|
3
|
-
export declare function notNull(options?: RuleOptions | string): ValidateRule;
|
|
4
|
-
/** 最小值:数字比大小;字符串/数组比长度 */
|
|
5
|
-
export declare function min(minValue: number, options?: RuleOptions | string): ValidateRule;
|
|
6
|
-
/** 最大值:数字比大小;字符串/数组比长度 */
|
|
7
|
-
export declare function max(maxValue: number, options?: RuleOptions | string): ValidateRule;
|
|
8
|
-
/** 邮箱 */
|
|
9
|
-
export declare function email(options?: RuleOptions | string): ValidateRule;
|
|
10
|
-
/** 手机号(默认中国大陆) */
|
|
11
|
-
export declare function phone(options?: RuleOptions | string | {
|
|
12
|
-
message?: string;
|
|
13
|
-
locale?: validator.MobilePhoneLocale;
|
|
14
|
-
}): ValidateRule;
|
|
15
|
-
/**
|
|
16
|
-
* 自定义规则(函数返回 true 表示通过)。
|
|
17
|
-
* @example custom((v) => v === 'admin', '仅允许 admin')
|
|
18
|
-
*/
|
|
19
|
-
export declare function custom(fn: (value: unknown, object: unknown) => boolean | Promise<boolean>, options?: RuleOptions | string): ValidateRule;
|
|
20
|
-
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/Validate/rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA2BzD,kCAAkC;AAClC,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,YAAY,CAOpE;AAED,0BAA0B;AAC1B,wBAAgB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,YAAY,CAclF;AAED,0BAA0B;AAC1B,wBAAgB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,YAAY,CAclF;AAED,SAAS;AACT,wBAAgB,KAAK,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,YAAY,CAUlE;AAED,kBAAkB;AAClB,wBAAgB,KAAK,CACnB,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,SAAS,CAAC,iBAAiB,CAAA;CAAE,GAC1F,YAAY,CAmBd;AAED;;;GAGG;AACH,wBAAgB,MAAM,CACpB,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EACnE,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,GAC7B,YAAY,CAOd"}
|
package/dist/Validate/rules.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.notNull = notNull;
|
|
7
|
-
exports.min = min;
|
|
8
|
-
exports.max = max;
|
|
9
|
-
exports.email = email;
|
|
10
|
-
exports.phone = phone;
|
|
11
|
-
exports.custom = custom;
|
|
12
|
-
const validator_1 = __importDefault(require("validator"));
|
|
13
|
-
function msg(options, fallback) {
|
|
14
|
-
return options?.message?.trim() || fallback;
|
|
15
|
-
}
|
|
16
|
-
function isEmpty(value) {
|
|
17
|
-
return (value === undefined ||
|
|
18
|
-
value === null ||
|
|
19
|
-
(typeof value === "string" && value.trim() === ""));
|
|
20
|
-
}
|
|
21
|
-
function toNumber(value) {
|
|
22
|
-
if (typeof value === "number" && Number.isFinite(value))
|
|
23
|
-
return value;
|
|
24
|
-
if (typeof value === "string" && value.trim() !== "" && !Number.isNaN(Number(value))) {
|
|
25
|
-
return Number(value);
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
function lengthOf(value) {
|
|
30
|
-
if (typeof value === "string" || Array.isArray(value))
|
|
31
|
-
return value.length;
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
/** 非空(undefined / null / 空字符串) */
|
|
35
|
-
function notNull(options) {
|
|
36
|
-
const opts = typeof options === "string" ? { message: options } : options;
|
|
37
|
-
return {
|
|
38
|
-
name: "NotNull",
|
|
39
|
-
message: msg(opts, "不能为空"),
|
|
40
|
-
validate: (value) => !isEmpty(value),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/** 最小值:数字比大小;字符串/数组比长度 */
|
|
44
|
-
function min(minValue, options) {
|
|
45
|
-
const opts = typeof options === "string" ? { message: options } : options;
|
|
46
|
-
return {
|
|
47
|
-
name: "Min",
|
|
48
|
-
message: msg(opts, `不能小于 ${minValue}`),
|
|
49
|
-
validate: (value) => {
|
|
50
|
-
if (isEmpty(value))
|
|
51
|
-
return true;
|
|
52
|
-
const num = toNumber(value);
|
|
53
|
-
if (num !== null)
|
|
54
|
-
return num >= minValue;
|
|
55
|
-
const len = lengthOf(value);
|
|
56
|
-
if (len !== null)
|
|
57
|
-
return len >= minValue;
|
|
58
|
-
return false;
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
/** 最大值:数字比大小;字符串/数组比长度 */
|
|
63
|
-
function max(maxValue, options) {
|
|
64
|
-
const opts = typeof options === "string" ? { message: options } : options;
|
|
65
|
-
return {
|
|
66
|
-
name: "Max",
|
|
67
|
-
message: msg(opts, `不能大于 ${maxValue}`),
|
|
68
|
-
validate: (value) => {
|
|
69
|
-
if (isEmpty(value))
|
|
70
|
-
return true;
|
|
71
|
-
const num = toNumber(value);
|
|
72
|
-
if (num !== null)
|
|
73
|
-
return num <= maxValue;
|
|
74
|
-
const len = lengthOf(value);
|
|
75
|
-
if (len !== null)
|
|
76
|
-
return len <= maxValue;
|
|
77
|
-
return false;
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
/** 邮箱 */
|
|
82
|
-
function email(options) {
|
|
83
|
-
const opts = typeof options === "string" ? { message: options } : options;
|
|
84
|
-
return {
|
|
85
|
-
name: "Email",
|
|
86
|
-
message: msg(opts, "邮箱格式不正确"),
|
|
87
|
-
validate: (value) => {
|
|
88
|
-
if (isEmpty(value))
|
|
89
|
-
return true;
|
|
90
|
-
return typeof value === "string" && validator_1.default.isEmail(value);
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
/** 手机号(默认中国大陆) */
|
|
95
|
-
function phone(options) {
|
|
96
|
-
let message;
|
|
97
|
-
let locale = "zh-CN";
|
|
98
|
-
if (typeof options === "string") {
|
|
99
|
-
message = options;
|
|
100
|
-
}
|
|
101
|
-
else if (options && typeof options === "object") {
|
|
102
|
-
message = options.message;
|
|
103
|
-
if ("locale" in options && options.locale) {
|
|
104
|
-
locale = options.locale;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
name: "Phone",
|
|
109
|
-
message: message?.trim() || "手机号格式不正确",
|
|
110
|
-
validate: (value) => {
|
|
111
|
-
if (isEmpty(value))
|
|
112
|
-
return true;
|
|
113
|
-
return typeof value === "string" && validator_1.default.isMobilePhone(value, locale);
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* 自定义规则(函数返回 true 表示通过)。
|
|
119
|
-
* @example custom((v) => v === 'admin', '仅允许 admin')
|
|
120
|
-
*/
|
|
121
|
-
function custom(fn, options) {
|
|
122
|
-
const opts = typeof options === "string" ? { message: options } : options;
|
|
123
|
-
return {
|
|
124
|
-
name: "Custom",
|
|
125
|
-
message: msg(opts, "校验未通过"),
|
|
126
|
-
validate: fn,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=rules.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/Validate/rules.ts"],"names":[],"mappings":";;;;;AA6BA,0BAOC;AAGD,kBAcC;AAGD,kBAcC;AAGD,sBAUC;AAGD,sBAqBC;AAMD,wBAUC;AA3HD,0DAAkC;AAGlC,SAAS,GAAG,CAAC,OAAgC,EAAE,QAAgB;IAC7D,OAAO,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,QAAQ,CAAC;AAC9C,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,CACL,KAAK,KAAK,SAAS;QACnB,KAAK,KAAK,IAAI;QACd,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CACnD,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QACrF,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,MAAM,CAAC;IAC3E,OAAO,IAAI,CAAC;AACd,CAAC;AAED,kCAAkC;AAClC,SAAgB,OAAO,CAAC,OAA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AAQ,EAAE,CAAC;QAClD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC1B,IAAI,QAAQ,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YAC1C,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,OAAO;QACL,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,UAAU;QACtC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YAClB,IAAI,OAAO,CAAC,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC;YAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,mBAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC7E,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,MAAM,CACpB,EAAmE,EACnE,OAA8B;IAE9B,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAC1E,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC;QAC3B,QAAQ,EAAE,EAAE;KACb,CAAC;AACJ,CAAC"}
|
package/dist/Validate/types.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ResponseCode } from "../types/enums";
|
|
2
|
-
/** 单条校验规则 */
|
|
3
|
-
export interface ValidateRule {
|
|
4
|
-
name: string;
|
|
5
|
-
message: string;
|
|
6
|
-
validate: (value: unknown, object: unknown) => boolean | Promise<boolean>;
|
|
7
|
-
}
|
|
8
|
-
/** 规则工厂可选配置 */
|
|
9
|
-
export interface RuleOptions {
|
|
10
|
-
message?: string;
|
|
11
|
-
}
|
|
12
|
-
/** 字段错误明细 */
|
|
13
|
-
export interface FieldError {
|
|
14
|
-
field: string;
|
|
15
|
-
message: string;
|
|
16
|
-
rule: string;
|
|
17
|
-
}
|
|
18
|
-
/** 校验失败异常 */
|
|
19
|
-
export declare class ValidationError extends Error {
|
|
20
|
-
readonly code = ResponseCode.BAD_REQUEST;
|
|
21
|
-
readonly errors: FieldError[];
|
|
22
|
-
constructor(errors: FieldError[], message?: string);
|
|
23
|
-
}
|
|
24
|
-
/** 类字段规则表 */
|
|
25
|
-
export type ClassRuleMap = Record<string, ValidateRule[]>;
|
|
26
|
-
/** validateHandler 的 schema:类 或 字段规则表 */
|
|
27
|
-
export type ValidatorParam = Function | ClassRuleMap;
|
|
28
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/Validate/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,aAAa;AACb,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3E;AAED,eAAe;AACf,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,aAAa;AACb,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,aAAa;AACb,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,4BAA4B;IACzC,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;gBAElB,MAAM,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM;CASnD;AAED,aAAa;AACb,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;AAE1D,yCAAyC;AACzC,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,YAAY,CAAC"}
|
package/dist/Validate/types.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationError = void 0;
|
|
4
|
-
const enums_1 = require("../types/enums");
|
|
5
|
-
/** 校验失败异常 */
|
|
6
|
-
class ValidationError extends Error {
|
|
7
|
-
constructor(errors, message) {
|
|
8
|
-
const msg = message ||
|
|
9
|
-
errors.map((e) => e.message).join("; ") ||
|
|
10
|
-
"参数校验失败";
|
|
11
|
-
super(msg);
|
|
12
|
-
this.code = enums_1.ResponseCode.BAD_REQUEST;
|
|
13
|
-
this.name = "ValidationError";
|
|
14
|
-
this.errors = errors;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.ValidationError = ValidationError;
|
|
18
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/Validate/types.ts"],"names":[],"mappings":";;;AAAA,0CAA8C;AAqB9C,aAAa;AACb,MAAa,eAAgB,SAAQ,KAAK;IAIxC,YAAY,MAAoB,EAAE,OAAgB;QAChD,MAAM,GAAG,GACP,OAAO;YACP,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YACvC,QAAQ,CAAC;QACX,KAAK,CAAC,GAAG,CAAC,CAAC;QARJ,SAAI,GAAG,oBAAY,CAAC,WAAW,CAAC;QASvC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAbD,0CAaC"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|