@midwayjs/decorator 2.13.2 → 2.14.1
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/README.md +1 -1
- package/dist/annotation/index.js +5 -1
- package/dist/annotation/validate.d.ts +7 -1
- package/dist/annotation/validate.js +17 -5
- package/dist/common/decoratorManager.d.ts +1 -1
- package/dist/index.js +5 -1
- package/dist/interface.d.ts +2 -2
- package/package.json +5 -5
- package/CHANGELOG.md +0 -1306
- package/LICENSE +0 -21
package/README.md
CHANGED
package/dist/annotation/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
interface ValidateOptions {
|
|
2
|
+
isTransform?: boolean;
|
|
3
|
+
errorStatus?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function CustomValidate(opt: ValidateOptions): (customOpt?: ValidateOptions) => (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
6
|
+
export declare function Validate(opt?: boolean | ValidateOptions): (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
7
|
+
export {};
|
|
2
8
|
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Validate = void 0;
|
|
3
|
+
exports.Validate = exports.CustomValidate = void 0;
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
const class_transformer_1 = require("class-transformer");
|
|
6
|
-
const
|
|
7
|
-
function
|
|
6
|
+
const joi = require("joi");
|
|
7
|
+
function CustomValidate(opt) {
|
|
8
|
+
return (customOpt = {}) => Validate({ ...opt, ...customOpt });
|
|
9
|
+
}
|
|
10
|
+
exports.CustomValidate = CustomValidate;
|
|
11
|
+
function Validate(opt = true) {
|
|
8
12
|
return function (target, propertyKey, descriptor) {
|
|
9
13
|
const origin = descriptor.value;
|
|
10
14
|
const paramTypes = (0, __1.getMethodParamTypes)(target, propertyKey);
|
|
15
|
+
const options = typeof opt === 'boolean' ? { isTransform: opt } : opt;
|
|
16
|
+
if (!('isTransform' in options)) {
|
|
17
|
+
options.isTransform = true;
|
|
18
|
+
}
|
|
11
19
|
descriptor.value = function (...args) {
|
|
12
20
|
for (let i = 0; i < paramTypes.length; i++) {
|
|
13
21
|
const item = paramTypes[i];
|
|
14
22
|
const rules = (0, __1.getClassExtendedMetadata)(__1.RULES_KEY, item);
|
|
15
23
|
if (rules) {
|
|
16
|
-
const schema =
|
|
24
|
+
const schema = joi.object(rules);
|
|
17
25
|
const result = schema.validate(args[i]);
|
|
18
26
|
if (result.error) {
|
|
27
|
+
if (options.errorStatus) {
|
|
28
|
+
result.error.status =
|
|
29
|
+
options.errorStatus;
|
|
30
|
+
}
|
|
19
31
|
throw result.error;
|
|
20
32
|
}
|
|
21
33
|
else {
|
|
22
34
|
args[i] = result.value;
|
|
23
35
|
}
|
|
24
36
|
// passed
|
|
25
|
-
if (isTransform) {
|
|
37
|
+
if (options.isTransform) {
|
|
26
38
|
args[i] = (0, class_transformer_1.plainToClass)(item, args[i]);
|
|
27
39
|
}
|
|
28
40
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import { ObjectDefinitionOptions, ObjectIdentifier, TagPropsMetadata } from '../interface';
|
|
3
|
-
export
|
|
3
|
+
export type DecoratorKey = string | symbol;
|
|
4
4
|
export declare const PRELOAD_MODULE_KEY = "INJECTION_PRELOAD_MODULE_KEY";
|
|
5
5
|
export declare const INJECT_CLASS_KEY_PREFIX = "INJECTION_CLASS_META_DATA";
|
|
6
6
|
export declare class DecoratorManager extends Map {
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ScopeEnum } from './common/scopeEnum';
|
|
2
2
|
import { Middleware } from 'koa';
|
|
3
3
|
import { RequestHandler } from 'express';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
4
|
+
export type MiddlewareParamArray = Array<Middleware | RequestHandler | string>;
|
|
5
|
+
export type ObjectIdentifier = string;
|
|
6
6
|
/**
|
|
7
7
|
* 内部管理的属性、json、ref等解析实例存储
|
|
8
8
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/decorator",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.1",
|
|
4
4
|
"description": "definition decorator for midway project",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@types/express": "^4.17.8",
|
|
16
16
|
"@types/koa": "^2.11.4",
|
|
17
|
-
"camelcase": "
|
|
18
|
-
"class-transformer": "
|
|
19
|
-
"joi": "
|
|
17
|
+
"camelcase": "6.3.0",
|
|
18
|
+
"class-transformer": "0.3.2",
|
|
19
|
+
"joi": "17.7.1",
|
|
20
20
|
"reflect-metadata": "^0.1.13"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "a603d2348d6141f8f723901498f03a162a037708"
|
|
45
45
|
}
|