@midwayjs/decorator 3.0.0-beta.12 → 3.0.0-beta.16
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/decorator/web/requestMapping.d.ts +2 -0
- package/dist/decoratorManager.d.ts +16 -3
- package/dist/decoratorManager.js +21 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.js +10 -1
- package/dist/util/camelCase.d.ts +3 -0
- package/dist/util/camelCase.js +88 -0
- package/dist/util/format.js +12 -12
- package/dist/util/index.d.ts +16 -5
- package/dist/util/index.js +17 -10
- package/package.json +3 -4
- package/CHANGELOG.md +0 -1396
|
@@ -22,10 +22,12 @@ export interface RouterOption {
|
|
|
22
22
|
middleware?: MiddlewareParamArray;
|
|
23
23
|
/**
|
|
24
24
|
* router summary, for swagger
|
|
25
|
+
* @deprecated
|
|
25
26
|
*/
|
|
26
27
|
summary?: string;
|
|
27
28
|
/**
|
|
28
29
|
* router description, for swagger
|
|
30
|
+
* @deprecated
|
|
29
31
|
*/
|
|
30
32
|
description?: string;
|
|
31
33
|
/**
|
|
@@ -281,8 +281,21 @@ export declare function getMethodReturnTypes(target: any, methodName: string | s
|
|
|
281
281
|
* create a custom property inject
|
|
282
282
|
* @param decoratorKey
|
|
283
283
|
* @param metadata
|
|
284
|
+
* @param impl default true, configuration need decoratorService.registerMethodHandler
|
|
284
285
|
*/
|
|
285
|
-
export declare function createCustomPropertyDecorator(decoratorKey: string, metadata: any): PropertyDecorator;
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
export declare function createCustomPropertyDecorator(decoratorKey: string, metadata: any, impl?: boolean): PropertyDecorator;
|
|
287
|
+
/**
|
|
288
|
+
*
|
|
289
|
+
* @param decoratorKey
|
|
290
|
+
* @param metadata
|
|
291
|
+
* @param impl default true, configuration need decoratorService.registerMethodHandler
|
|
292
|
+
*/
|
|
293
|
+
export declare function createCustomMethodDecorator(decoratorKey: string, metadata: any, impl?: boolean): MethodDecorator;
|
|
294
|
+
/**
|
|
295
|
+
*
|
|
296
|
+
* @param decoratorKey
|
|
297
|
+
* @param metadata
|
|
298
|
+
* @param impl default true, configuration need decoratorService.registerMethodHandler
|
|
299
|
+
*/
|
|
300
|
+
export declare function createCustomParamDecorator(decoratorKey: string, metadata: any, impl?: boolean): ParameterDecorator;
|
|
288
301
|
//# sourceMappingURL=decoratorManager.d.ts.map
|
package/dist/decoratorManager.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.createCustomParamDecorator = exports.createCustomMethodDecorator = expor
|
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const constant_1 = require("./constant");
|
|
6
6
|
const util_1 = require("./util");
|
|
7
|
+
const camelCase_1 = require("./util/camelCase");
|
|
7
8
|
const debug = require('util').debuglog('midway:decorator');
|
|
8
9
|
exports.PRELOAD_MODULE_KEY = 'INJECTION_PRELOAD_MODULE_KEY';
|
|
9
10
|
exports.INJECT_CLASS_KEY_PREFIX = 'INJECTION_CLASS_META_DATA';
|
|
@@ -565,7 +566,7 @@ function saveProviderId(identifier, target) {
|
|
|
565
566
|
id: identifier,
|
|
566
567
|
originName: target.name,
|
|
567
568
|
uuid,
|
|
568
|
-
name: (0,
|
|
569
|
+
name: (0, camelCase_1.camelCase)(target.name),
|
|
569
570
|
}, target);
|
|
570
571
|
debug(`save provide: ${target.name} -> ${uuid}`);
|
|
571
572
|
}
|
|
@@ -650,28 +651,43 @@ exports.getMethodReturnTypes = getMethodReturnTypes;
|
|
|
650
651
|
* create a custom property inject
|
|
651
652
|
* @param decoratorKey
|
|
652
653
|
* @param metadata
|
|
654
|
+
* @param impl default true, configuration need decoratorService.registerMethodHandler
|
|
653
655
|
*/
|
|
654
|
-
function createCustomPropertyDecorator(decoratorKey, metadata) {
|
|
656
|
+
function createCustomPropertyDecorator(decoratorKey, metadata, impl = true) {
|
|
655
657
|
return function (target, propertyName) {
|
|
656
658
|
attachClassMetadata(constant_1.INJECT_CUSTOM_PROPERTY, {
|
|
657
659
|
propertyName,
|
|
658
660
|
key: decoratorKey,
|
|
659
661
|
metadata,
|
|
662
|
+
impl,
|
|
660
663
|
}, target, propertyName);
|
|
661
664
|
};
|
|
662
665
|
}
|
|
663
666
|
exports.createCustomPropertyDecorator = createCustomPropertyDecorator;
|
|
664
|
-
|
|
667
|
+
/**
|
|
668
|
+
*
|
|
669
|
+
* @param decoratorKey
|
|
670
|
+
* @param metadata
|
|
671
|
+
* @param impl default true, configuration need decoratorService.registerMethodHandler
|
|
672
|
+
*/
|
|
673
|
+
function createCustomMethodDecorator(decoratorKey, metadata, impl = true) {
|
|
665
674
|
return function (target, propertyName, descriptor) {
|
|
666
675
|
attachClassMetadata(constant_1.INJECT_CUSTOM_METHOD, {
|
|
667
676
|
propertyName,
|
|
668
677
|
key: decoratorKey,
|
|
669
678
|
metadata,
|
|
679
|
+
impl,
|
|
670
680
|
}, target);
|
|
671
681
|
};
|
|
672
682
|
}
|
|
673
683
|
exports.createCustomMethodDecorator = createCustomMethodDecorator;
|
|
674
|
-
|
|
684
|
+
/**
|
|
685
|
+
*
|
|
686
|
+
* @param decoratorKey
|
|
687
|
+
* @param metadata
|
|
688
|
+
* @param impl default true, configuration need decoratorService.registerMethodHandler
|
|
689
|
+
*/
|
|
690
|
+
function createCustomParamDecorator(decoratorKey, metadata, impl = true) {
|
|
675
691
|
return function (target, propertyName, parameterIndex) {
|
|
676
692
|
// const parameterName = getParamNames(target[methodName])[parameterIndex];
|
|
677
693
|
attachClassMetadata(constant_1.INJECT_CUSTOM_PARAM, {
|
|
@@ -679,6 +695,7 @@ function createCustomParamDecorator(decoratorKey, metadata) {
|
|
|
679
695
|
parameterIndex,
|
|
680
696
|
propertyName,
|
|
681
697
|
metadata,
|
|
698
|
+
impl,
|
|
682
699
|
}, target, propertyName, 'multi');
|
|
683
700
|
};
|
|
684
701
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './decorator';
|
|
|
2
2
|
export * from './interface';
|
|
3
3
|
export * from './constant';
|
|
4
4
|
export * from './decoratorManager';
|
|
5
|
-
export
|
|
5
|
+
export { TYPES, sleep, getParamNames, generateRandomId, merge, } from './util/index';
|
|
6
6
|
export * from './util/format';
|
|
7
|
+
export { camelCase, pascalCase } from './util/camelCase';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -10,10 +10,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.pascalCase = exports.camelCase = exports.merge = exports.generateRandomId = exports.getParamNames = exports.sleep = exports.TYPES = void 0;
|
|
13
14
|
__exportStar(require("./decorator"), exports);
|
|
14
15
|
__exportStar(require("./interface"), exports);
|
|
15
16
|
__exportStar(require("./constant"), exports);
|
|
16
17
|
__exportStar(require("./decoratorManager"), exports);
|
|
17
|
-
|
|
18
|
+
var index_1 = require("./util/index");
|
|
19
|
+
Object.defineProperty(exports, "TYPES", { enumerable: true, get: function () { return index_1.TYPES; } });
|
|
20
|
+
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return index_1.sleep; } });
|
|
21
|
+
Object.defineProperty(exports, "getParamNames", { enumerable: true, get: function () { return index_1.getParamNames; } });
|
|
22
|
+
Object.defineProperty(exports, "generateRandomId", { enumerable: true, get: function () { return index_1.generateRandomId; } });
|
|
23
|
+
Object.defineProperty(exports, "merge", { enumerable: true, get: function () { return index_1.merge; } });
|
|
18
24
|
__exportStar(require("./util/format"), exports);
|
|
25
|
+
var camelCase_1 = require("./util/camelCase");
|
|
26
|
+
Object.defineProperty(exports, "camelCase", { enumerable: true, get: function () { return camelCase_1.camelCase; } });
|
|
27
|
+
Object.defineProperty(exports, "pascalCase", { enumerable: true, get: function () { return camelCase_1.pascalCase; } });
|
|
19
28
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pascalCase = exports.camelCase = void 0;
|
|
4
|
+
const UPPERCASE = /[\p{Lu}]/u;
|
|
5
|
+
const LOWERCASE = /[\p{Ll}]/u;
|
|
6
|
+
const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
|
|
7
|
+
const SEPARATORS = /[_.\- ]+/;
|
|
8
|
+
const LEADING_SEPARATORS = new RegExp('^' + SEPARATORS.source);
|
|
9
|
+
const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, 'gu');
|
|
10
|
+
const NUMBERS_AND_IDENTIFIER = new RegExp('\\d+' + IDENTIFIER.source, 'gu');
|
|
11
|
+
const preserveCamelCase = (string, toLowerCase, toUpperCase) => {
|
|
12
|
+
let isLastCharLower = false;
|
|
13
|
+
let isLastCharUpper = false;
|
|
14
|
+
let isLastLastCharUpper = false;
|
|
15
|
+
for (let i = 0; i < string.length; i++) {
|
|
16
|
+
const character = string[i];
|
|
17
|
+
if (isLastCharLower && UPPERCASE.test(character)) {
|
|
18
|
+
string = string.slice(0, i) + '-' + string.slice(i);
|
|
19
|
+
isLastCharLower = false;
|
|
20
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
21
|
+
isLastCharUpper = true;
|
|
22
|
+
i++;
|
|
23
|
+
}
|
|
24
|
+
else if (isLastCharUpper &&
|
|
25
|
+
isLastLastCharUpper &&
|
|
26
|
+
LOWERCASE.test(character)) {
|
|
27
|
+
string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
|
|
28
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
29
|
+
isLastCharUpper = false;
|
|
30
|
+
isLastCharLower = true;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
isLastCharLower =
|
|
34
|
+
toLowerCase(character) === character &&
|
|
35
|
+
toUpperCase(character) !== character;
|
|
36
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
37
|
+
isLastCharUpper =
|
|
38
|
+
toUpperCase(character) === character &&
|
|
39
|
+
toLowerCase(character) !== character;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return string;
|
|
43
|
+
};
|
|
44
|
+
const postProcess = (input, toUpperCase) => {
|
|
45
|
+
SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
|
|
46
|
+
NUMBERS_AND_IDENTIFIER.lastIndex = 0;
|
|
47
|
+
return input
|
|
48
|
+
.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier))
|
|
49
|
+
.replace(NUMBERS_AND_IDENTIFIER, m => toUpperCase(m));
|
|
50
|
+
};
|
|
51
|
+
function camelCaseOrigin(input, options) {
|
|
52
|
+
options = {
|
|
53
|
+
pascalCase: false,
|
|
54
|
+
...options,
|
|
55
|
+
};
|
|
56
|
+
input = input.trim();
|
|
57
|
+
if (input.length === 0) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
const toLowerCase = string => string.toLowerCase();
|
|
61
|
+
const toUpperCase = string => string.toUpperCase();
|
|
62
|
+
if (input.length === 1) {
|
|
63
|
+
return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
|
|
64
|
+
}
|
|
65
|
+
const hasUpperCase = input !== toLowerCase(input);
|
|
66
|
+
if (hasUpperCase) {
|
|
67
|
+
input = preserveCamelCase(input, toLowerCase, toUpperCase);
|
|
68
|
+
}
|
|
69
|
+
input = input.replace(LEADING_SEPARATORS, '');
|
|
70
|
+
input = toLowerCase(input);
|
|
71
|
+
if (options.pascalCase) {
|
|
72
|
+
input = toUpperCase(input.charAt(0)) + input.slice(1);
|
|
73
|
+
}
|
|
74
|
+
return postProcess(input, toUpperCase);
|
|
75
|
+
}
|
|
76
|
+
function camelCase(input) {
|
|
77
|
+
return camelCaseOrigin(input, {
|
|
78
|
+
pascalCase: false,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.camelCase = camelCase;
|
|
82
|
+
function pascalCase(input) {
|
|
83
|
+
return camelCaseOrigin(input, {
|
|
84
|
+
pascalCase: true,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
exports.pascalCase = pascalCase;
|
|
88
|
+
//# sourceMappingURL=camelCase.js.map
|
package/dist/util/format.js
CHANGED
|
@@ -18,18 +18,18 @@ const MS = {
|
|
|
18
18
|
};
|
|
19
19
|
// crontab pre format
|
|
20
20
|
const CRONTAB = {
|
|
21
|
-
EVERY_SECOND: '* * * * *
|
|
22
|
-
EVERY_MINUTE: '0 * * * *
|
|
23
|
-
EVERY_HOUR: '0 0 * * *
|
|
24
|
-
EVERY_DAY: '0 0 0 * *
|
|
25
|
-
EVERY_DAY_ZERO_FIFTEEN: '0 15 0 * *
|
|
26
|
-
EVERY_DAY_ONE_FIFTEEN: '0 15 1 * *
|
|
27
|
-
EVERY_PER_5_SECOND: '
|
|
28
|
-
EVERY_PER_10_SECOND: '
|
|
29
|
-
EVERY_PER_30_SECOND: '
|
|
30
|
-
EVERY_PER_5_MINUTE: '0
|
|
31
|
-
EVERY_PER_10_MINUTE: '0
|
|
32
|
-
EVERY_PER_30_MINUTE: '0
|
|
21
|
+
EVERY_SECOND: '* * * * * *',
|
|
22
|
+
EVERY_MINUTE: '0 * * * * *',
|
|
23
|
+
EVERY_HOUR: '0 0 * * * *',
|
|
24
|
+
EVERY_DAY: '0 0 0 * * *',
|
|
25
|
+
EVERY_DAY_ZERO_FIFTEEN: '0 15 0 * * *',
|
|
26
|
+
EVERY_DAY_ONE_FIFTEEN: '0 15 1 * * *',
|
|
27
|
+
EVERY_PER_5_SECOND: '*/5 * * * * *',
|
|
28
|
+
EVERY_PER_10_SECOND: '*/10 * * * * *',
|
|
29
|
+
EVERY_PER_30_SECOND: '*/30 * * * * *',
|
|
30
|
+
EVERY_PER_5_MINUTE: '0 */5 * * * *',
|
|
31
|
+
EVERY_PER_10_MINUTE: '0 */10 * * * *',
|
|
32
|
+
EVERY_PER_30_MINUTE: '0 */30 * * * *',
|
|
33
33
|
};
|
|
34
34
|
exports.FORMAT = {
|
|
35
35
|
MS,
|
package/dist/util/index.d.ts
CHANGED
|
@@ -18,14 +18,25 @@ export declare function sleep(sleepTime?: number): Promise<void>;
|
|
|
18
18
|
* @param func
|
|
19
19
|
*/
|
|
20
20
|
export declare function getParamNames(func: any): string[];
|
|
21
|
-
/**
|
|
22
|
-
* 按照框架规则返回类名字
|
|
23
|
-
* @param name 类名称
|
|
24
|
-
*/
|
|
25
|
-
export declare function classNamed(name: string): string;
|
|
26
21
|
/**
|
|
27
22
|
* generate a lightweight random id, enough for ioc container
|
|
28
23
|
*/
|
|
29
24
|
export declare function generateRandomId(): string;
|
|
30
25
|
export declare function merge(target: any, src: any): any;
|
|
26
|
+
export declare const TYPES: {
|
|
27
|
+
isClass: typeof isClass;
|
|
28
|
+
isAsyncFunction: typeof isAsyncFunction;
|
|
29
|
+
isGeneratorFunction: typeof isGeneratorFunction;
|
|
30
|
+
isPromise: typeof isPromise;
|
|
31
|
+
isFunction: typeof isFunction;
|
|
32
|
+
isObject: typeof isObject;
|
|
33
|
+
isNumber: typeof isNumber;
|
|
34
|
+
isProxy: typeof isProxy;
|
|
35
|
+
isMap: typeof isMap;
|
|
36
|
+
isSet: typeof isSet;
|
|
37
|
+
isRegExp: typeof isRegExp;
|
|
38
|
+
isUndefined: typeof isUndefined;
|
|
39
|
+
isNull: typeof isNull;
|
|
40
|
+
isNullOrUndefined: typeof isNullOrUndefined;
|
|
41
|
+
};
|
|
31
42
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/util/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TYPES = exports.merge = exports.generateRandomId = exports.getParamNames = exports.sleep = exports.isNullOrUndefined = exports.isNull = exports.isUndefined = exports.isRegExp = exports.isSet = exports.isMap = exports.isProxy = exports.isNumber = exports.isObject = exports.isFunction = exports.isPromise = exports.isGeneratorFunction = exports.isAsyncFunction = exports.isClass = void 0;
|
|
4
4
|
const util = require("util");
|
|
5
|
-
const camelcase = require("camelcase");
|
|
6
5
|
const crypto = require("crypto");
|
|
7
6
|
const ToString = Function.prototype.toString;
|
|
8
7
|
function fnBody(fn) {
|
|
@@ -102,14 +101,6 @@ function getParamNames(func) {
|
|
|
102
101
|
return result;
|
|
103
102
|
}
|
|
104
103
|
exports.getParamNames = getParamNames;
|
|
105
|
-
/**
|
|
106
|
-
* 按照框架规则返回类名字
|
|
107
|
-
* @param name 类名称
|
|
108
|
-
*/
|
|
109
|
-
function classNamed(name) {
|
|
110
|
-
return camelcase(name);
|
|
111
|
-
}
|
|
112
|
-
exports.classNamed = classNamed;
|
|
113
104
|
/**
|
|
114
105
|
* generate a lightweight random id, enough for ioc container
|
|
115
106
|
*/
|
|
@@ -135,4 +126,20 @@ function merge(target, src) {
|
|
|
135
126
|
throw new Error('can not merge meta that type of ' + typeof target);
|
|
136
127
|
}
|
|
137
128
|
exports.merge = merge;
|
|
129
|
+
exports.TYPES = {
|
|
130
|
+
isClass,
|
|
131
|
+
isAsyncFunction,
|
|
132
|
+
isGeneratorFunction,
|
|
133
|
+
isPromise,
|
|
134
|
+
isFunction,
|
|
135
|
+
isObject,
|
|
136
|
+
isNumber,
|
|
137
|
+
isProxy,
|
|
138
|
+
isMap,
|
|
139
|
+
isSet,
|
|
140
|
+
isRegExp,
|
|
141
|
+
isUndefined,
|
|
142
|
+
isNull,
|
|
143
|
+
isNullOrUndefined,
|
|
144
|
+
};
|
|
138
145
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/decorator",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.16",
|
|
4
4
|
"description": "definition decorator for midway project",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -12,11 +12,10 @@
|
|
|
12
12
|
"link": "npm link"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"camelcase": "^6.2.0",
|
|
16
15
|
"reflect-metadata": "^0.1.13"
|
|
17
16
|
},
|
|
18
17
|
"devDependencies": {
|
|
19
|
-
"mm": "3"
|
|
18
|
+
"mm": "3.2.0"
|
|
20
19
|
},
|
|
21
20
|
"keywords": [
|
|
22
21
|
"midway",
|
|
@@ -37,5 +36,5 @@
|
|
|
37
36
|
"publishConfig": {
|
|
38
37
|
"access": "public"
|
|
39
38
|
},
|
|
40
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "43a32745ac45164dfef1494cba979f9652a6692b"
|
|
41
40
|
}
|