koatty 3.5.11 → 3.5.12-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/.commitlintrc.js +3 -0
- package/.eslintignore +2 -0
- package/.huskyrc +5 -0
- package/.versionrc.js +16 -0
- package/CHANGELOG.md +1 -38
- package/README.md +4 -7
- package/api-extractor.json +345 -0
- package/dist/LICENSE +29 -0
- package/dist/README.md +147 -0
- package/dist/index.d.ts +363 -19
- package/dist/index.js +1266 -26
- package/dist/index.mjs +1197 -0
- package/dist/package.json +99 -0
- package/docs/api/index.md +12 -0
- package/docs/api/koatty.apiinput.code.md +11 -0
- package/docs/api/koatty.apiinput.data.md +11 -0
- package/docs/api/koatty.apiinput.md +22 -0
- package/docs/api/koatty.apiinput.message.md +11 -0
- package/docs/api/koatty.apioutput.code.md +11 -0
- package/docs/api/koatty.apioutput.data.md +11 -0
- package/docs/api/koatty.apioutput.md +22 -0
- package/docs/api/koatty.apioutput.message.md +11 -0
- package/docs/api/koatty.appreadyhookfunc.md +11 -0
- package/docs/api/koatty.basecontroller._constructor_.md +20 -0
- package/docs/api/koatty.basecontroller._options.md +11 -0
- package/docs/api/koatty.basecontroller.app.md +11 -0
- package/docs/api/koatty.basecontroller.ctx.md +11 -0
- package/docs/api/koatty.basecontroller.fail.md +28 -0
- package/docs/api/koatty.basecontroller.init.md +19 -0
- package/docs/api/koatty.basecontroller.md +39 -0
- package/docs/api/koatty.basecontroller.ok.md +28 -0
- package/docs/api/koatty.baseservice._constructor_.md +20 -0
- package/docs/api/koatty.baseservice._options.md +11 -0
- package/docs/api/koatty.baseservice.app.md +11 -0
- package/docs/api/koatty.baseservice.init.md +25 -0
- package/docs/api/koatty.baseservice.md +36 -0
- package/docs/api/koatty.bindappreadyhook.md +26 -0
- package/docs/api/koatty.bootstrap.md +27 -0
- package/docs/api/koatty.component.md +27 -0
- package/docs/api/koatty.componentscan.md +27 -0
- package/docs/api/koatty.configurationscan.md +27 -0
- package/docs/api/koatty.controller.md +27 -0
- package/docs/api/koatty.httpcontroller.body.md +28 -0
- package/docs/api/koatty.httpcontroller.deny.md +26 -0
- package/docs/api/koatty.httpcontroller.expires.md +26 -0
- package/docs/api/koatty.httpcontroller.fail.md +28 -0
- package/docs/api/koatty.httpcontroller.header.md +27 -0
- package/docs/api/koatty.httpcontroller.isget.md +19 -0
- package/docs/api/koatty.httpcontroller.ismethod.md +26 -0
- package/docs/api/koatty.httpcontroller.ispost.md +19 -0
- package/docs/api/koatty.httpcontroller.json.md +26 -0
- package/docs/api/koatty.httpcontroller.md +35 -0
- package/docs/api/koatty.httpcontroller.ok.md +28 -0
- package/docs/api/koatty.httpcontroller.param.md +26 -0
- package/docs/api/koatty.httpcontroller.redirect.md +27 -0
- package/docs/api/koatty.httpcontroller.type.md +27 -0
- package/docs/api/koatty.icontroller.__after.md +11 -0
- package/docs/api/koatty.icontroller.__befor.md +11 -0
- package/docs/api/koatty.icontroller.app.md +11 -0
- package/docs/api/koatty.icontroller.ctx.md +11 -0
- package/docs/api/koatty.icontroller.fail.md +11 -0
- package/docs/api/koatty.icontroller.md +25 -0
- package/docs/api/koatty.icontroller.ok.md +11 -0
- package/docs/api/koatty.imiddleware.md +20 -0
- package/docs/api/koatty.imiddleware.run.md +11 -0
- package/docs/api/koatty.iplugin.md +20 -0
- package/docs/api/koatty.iplugin.run.md +11 -0
- package/docs/api/koatty.iservice.app.md +11 -0
- package/docs/api/koatty.iservice.md +20 -0
- package/docs/api/koatty.logger.md +11 -0
- package/docs/api/koatty.md +51 -0
- package/docs/api/koatty.middleware.md +27 -0
- package/docs/api/koatty.plugin.md +27 -0
- package/docs/api/koatty.service.md +27 -0
- package/jest.config.js +0 -2
- package/jest_html_reporters.html +1 -1
- package/package.json +37 -35
- package/rollup.config.js +63 -0
- package/scripts/copyright.js +28 -0
- package/scripts/postBuild.js +10 -0
- package/tsconfig.json +4 -2
- package/babel.config.js +0 -21
- package/commitlint.config.js +0 -14
- package/dist/config/config.d.ts +0 -18
- package/dist/config/config.js +0 -25
- package/dist/config/config.js.map +0 -1
- package/dist/config/middleware.d.ts +0 -28
- package/dist/config/middleware.js +0 -32
- package/dist/config/middleware.js.map +0 -1
- package/dist/config/plugin.d.ts +0 -11
- package/dist/config/plugin.js +0 -15
- package/dist/config/plugin.js.map +0 -1
- package/dist/config/router.d.ts +0 -8
- package/dist/config/router.js +0 -32
- package/dist/config/router.js.map +0 -1
- package/dist/controller/BaseController.d.ts +0 -60
- package/dist/controller/BaseController.js +0 -137
- package/dist/controller/BaseController.js.map +0 -1
- package/dist/controller/HttpController.d.ts +0 -131
- package/dist/controller/HttpController.js +0 -214
- package/dist/controller/HttpController.js.map +0 -1
- package/dist/core/Bootstrap.d.ts +0 -50
- package/dist/core/Bootstrap.js +0 -218
- package/dist/core/Bootstrap.js.map +0 -1
- package/dist/core/Component.d.ts +0 -94
- package/dist/core/Component.js +0 -89
- package/dist/core/Component.js.map +0 -1
- package/dist/core/Constants.d.ts +0 -11
- package/dist/core/Constants.js +0 -24
- package/dist/core/Constants.js.map +0 -1
- package/dist/core/Loader.d.ts +0 -110
- package/dist/core/Loader.js +0 -394
- package/dist/core/Loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/middleware/PayloadMiddleware.d.ts +0 -11
- package/dist/middleware/PayloadMiddleware.js +0 -22
- package/dist/middleware/PayloadMiddleware.js.map +0 -1
- package/dist/middleware/TraceMiddleware.d.ts +0 -11
- package/dist/middleware/TraceMiddleware.js +0 -22
- package/dist/middleware/TraceMiddleware.js.map +0 -1
- package/dist/service/BaseService.d.ts +0 -33
- package/dist/service/BaseService.js +0 -32
- package/dist/service/BaseService.js.map +0 -1
- package/dist/util/Helper.d.ts +0 -25
- package/dist/util/Helper.js +0 -117
- package/dist/util/Helper.js.map +0 -1
- package/dist/util/Logger.d.ts +0 -27
- package/dist/util/Logger.js +0 -41
- package/dist/util/Logger.js.map +0 -1
package/dist/config/router.js
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
/**
|
4
|
-
* @ author: richen
|
5
|
-
* @ copyright: Copyright (c) - <richenlin(at)gmail.com>
|
6
|
-
* @ license: BSD (3-Clause)
|
7
|
-
* @ version: 2019-11-01 18:37:35
|
8
|
-
*/
|
9
|
-
exports.default = {
|
10
|
-
// prefix: string;
|
11
|
-
/**
|
12
|
-
* Methods which should be supported by the router.
|
13
|
-
*/
|
14
|
-
// methods?: string[];
|
15
|
-
// routerPath?: string;
|
16
|
-
/**
|
17
|
-
* Whether or not routing should be case-sensitive.
|
18
|
-
*/
|
19
|
-
// sensitive?: boolean;
|
20
|
-
/**
|
21
|
-
* Whether or not routes should matched strictly.
|
22
|
-
*
|
23
|
-
* If strict matching is enabled, the trailing slash is taken into
|
24
|
-
* account when matching routes.
|
25
|
-
*/
|
26
|
-
// strict?: boolean;
|
27
|
-
/**
|
28
|
-
* Other extended configuration
|
29
|
-
*/
|
30
|
-
// ext?: any;
|
31
|
-
};
|
32
|
-
//# sourceMappingURL=router.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/config/router.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,kBAAe;AACX,kBAAkB;AAElB;;GAEG;AACH,sBAAsB;AAEtB,uBAAuB;AAEvB;;GAEG;AACH,uBAAuB;AAEvB;;;;;GAKG;AACH,oBAAoB;AAEpB;;GAEG;AACH,aAAa;CAChB,CAAC"}
|
@@ -1,60 +0,0 @@
|
|
1
|
-
import { Koatty, KoattyContext } from 'koatty_core';
|
2
|
-
import { ObjectDefinitionOptions } from "koatty_container";
|
3
|
-
import { ApiInput, ApiOutput, IController } from '../core/Component';
|
4
|
-
/**
|
5
|
-
* Base controller
|
6
|
-
*
|
7
|
-
* @export
|
8
|
-
* @class BaseController
|
9
|
-
* @implements {IController}
|
10
|
-
*/
|
11
|
-
export declare class BaseController implements IController {
|
12
|
-
app: Koatty;
|
13
|
-
ctx: KoattyContext;
|
14
|
-
protected _options: ObjectDefinitionOptions;
|
15
|
-
/**
|
16
|
-
* instance of BaseController.
|
17
|
-
* @param {Koatty} app
|
18
|
-
* @param {KoattyContext} ctx
|
19
|
-
* @memberof BaseController
|
20
|
-
*/
|
21
|
-
protected constructor(ctx: KoattyContext);
|
22
|
-
/**
|
23
|
-
* init
|
24
|
-
*
|
25
|
-
* @protected
|
26
|
-
* @memberof BaseController
|
27
|
-
*/
|
28
|
-
protected init(): void;
|
29
|
-
/**
|
30
|
-
* Format api interface data format
|
31
|
-
*
|
32
|
-
* @private
|
33
|
-
* @param {Error | string | ApiInput} msg 待处理的接口数据信息|接口msg
|
34
|
-
* @param {*} data 待返回的数据
|
35
|
-
* @param {number} defaultCode 默认错误码
|
36
|
-
* @returns {ApiOutput} 格式化之后的接口数据
|
37
|
-
* @memberof BaseController
|
38
|
-
*/
|
39
|
-
protected formatApiData(msg: any, data: any, defaultCode: number): ApiOutput;
|
40
|
-
/**
|
41
|
-
* Response to normalize json format content for success
|
42
|
-
*
|
43
|
-
* @param {(string | ApiInput)} msg 待处理的message消息
|
44
|
-
* @param {*} [data] 待处理的数据
|
45
|
-
* @param {number} [code=200] 错误码,默认0
|
46
|
-
* @returns {Promise<ApiOutput>}
|
47
|
-
* @memberof BaseController
|
48
|
-
*/
|
49
|
-
ok(msg: string | ApiInput, data?: any, code?: number): Promise<ApiOutput>;
|
50
|
-
/**
|
51
|
-
* Response to normalize json format content for fail
|
52
|
-
*
|
53
|
-
* @param {(string | ApiInput)} msg
|
54
|
-
* @param {*} [data]
|
55
|
-
* @param {number} [code=1]
|
56
|
-
* @returns {Promise<ApiOutput>}
|
57
|
-
* @memberof BaseController
|
58
|
-
*/
|
59
|
-
fail(msg: Error | string | ApiInput, data?: any, code?: number): Promise<ApiOutput>;
|
60
|
-
}
|
@@ -1,137 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.BaseController = void 0;
|
4
|
-
/**
|
5
|
-
* @ author: richen
|
6
|
-
* @ copyright: Copyright (c) - <richenlin(at)gmail.com>
|
7
|
-
* @ license: BSD (3-Clause)
|
8
|
-
* @ version: 2020-05-20 15:45:24
|
9
|
-
*/
|
10
|
-
const Helper_1 = require("../util/Helper");
|
11
|
-
/**
|
12
|
-
* Base controller
|
13
|
-
*
|
14
|
-
* @export
|
15
|
-
* @class BaseController
|
16
|
-
* @implements {IController}
|
17
|
-
*/
|
18
|
-
class BaseController {
|
19
|
-
/**
|
20
|
-
* instance of BaseController.
|
21
|
-
* @param {Koatty} app
|
22
|
-
* @param {KoattyContext} ctx
|
23
|
-
* @memberof BaseController
|
24
|
-
*/
|
25
|
-
constructor(ctx) {
|
26
|
-
this.ctx = ctx;
|
27
|
-
this.init();
|
28
|
-
}
|
29
|
-
/**
|
30
|
-
* init
|
31
|
-
*
|
32
|
-
* @protected
|
33
|
-
* @memberof BaseController
|
34
|
-
*/
|
35
|
-
init() {
|
36
|
-
}
|
37
|
-
// /**
|
38
|
-
// * Class pre-execution method, executed before each class member methods (except constructor, init, __after) are executed.
|
39
|
-
// *
|
40
|
-
// * @returns {Promise<any>}
|
41
|
-
// * @memberof BaseController
|
42
|
-
// */
|
43
|
-
// public __before(): Promise<any> {
|
44
|
-
// return Promise.resolve();
|
45
|
-
// }
|
46
|
-
// /**
|
47
|
-
// * Class after-execution method,after each class member methods (except constructor, init, __before) are executed.
|
48
|
-
// *
|
49
|
-
// * @public
|
50
|
-
// * @returns {*}
|
51
|
-
// * @memberof BaseController
|
52
|
-
// */
|
53
|
-
// public __after(): Promise<any> {
|
54
|
-
// return Promise.resolve();
|
55
|
-
// }
|
56
|
-
/**
|
57
|
-
* Format api interface data format
|
58
|
-
*
|
59
|
-
* @private
|
60
|
-
* @param {Error | string | ApiInput} msg 待处理的接口数据信息|接口msg
|
61
|
-
* @param {*} data 待返回的数据
|
62
|
-
* @param {number} defaultCode 默认错误码
|
63
|
-
* @returns {ApiOutput} 格式化之后的接口数据
|
64
|
-
* @memberof BaseController
|
65
|
-
*/
|
66
|
-
formatApiData(msg, data, defaultCode) {
|
67
|
-
let obj = {
|
68
|
-
code: defaultCode,
|
69
|
-
message: '',
|
70
|
-
data: null,
|
71
|
-
};
|
72
|
-
if (Helper_1.Helper.isError(msg)) {
|
73
|
-
const { code, message } = msg;
|
74
|
-
obj.code = code || defaultCode;
|
75
|
-
obj.message = message;
|
76
|
-
}
|
77
|
-
else if (Helper_1.Helper.isObject(msg)) {
|
78
|
-
obj = { ...obj, ...msg };
|
79
|
-
}
|
80
|
-
else {
|
81
|
-
obj.message = msg;
|
82
|
-
obj.data = data;
|
83
|
-
}
|
84
|
-
return obj;
|
85
|
-
}
|
86
|
-
/**
|
87
|
-
* Response to normalize json format content for success
|
88
|
-
*
|
89
|
-
* @param {(string | ApiInput)} msg 待处理的message消息
|
90
|
-
* @param {*} [data] 待处理的数据
|
91
|
-
* @param {number} [code=200] 错误码,默认0
|
92
|
-
* @returns {Promise<ApiOutput>}
|
93
|
-
* @memberof BaseController
|
94
|
-
*/
|
95
|
-
ok(msg, data, code = 0) {
|
96
|
-
const obj = this.formatApiData(msg, data, code);
|
97
|
-
return Promise.resolve(obj);
|
98
|
-
}
|
99
|
-
/**
|
100
|
-
* Response to normalize json format content for fail
|
101
|
-
*
|
102
|
-
* @param {(string | ApiInput)} msg
|
103
|
-
* @param {*} [data]
|
104
|
-
* @param {number} [code=1]
|
105
|
-
* @returns {Promise<ApiOutput>}
|
106
|
-
* @memberof BaseController
|
107
|
-
*/
|
108
|
-
fail(msg, data, code = 1) {
|
109
|
-
const obj = this.formatApiData(msg, data, code);
|
110
|
-
return Promise.resolve(obj);
|
111
|
-
}
|
112
|
-
}
|
113
|
-
exports.BaseController = BaseController;
|
114
|
-
// const properties = ["constructor", "init"];
|
115
|
-
// export const BaseController = new Proxy(Base, {
|
116
|
-
// set(target, key, value, receiver) {
|
117
|
-
// if (Reflect.get(target, key, receiver) === undefined) {
|
118
|
-
// return Reflect.set(target, key, value, receiver);
|
119
|
-
// } else if (key === "init") {
|
120
|
-
// return Reflect.set(target, key, value, receiver);
|
121
|
-
// } else {
|
122
|
-
// throw Error("Cannot redefine getter-only property");
|
123
|
-
// }
|
124
|
-
// },
|
125
|
-
// deleteProperty(target, key) {
|
126
|
-
// throw Error("Cannot delete getter-only property");
|
127
|
-
// },
|
128
|
-
// construct(target, args, newTarget) {
|
129
|
-
// Reflect.ownKeys(target.prototype).map((n) => {
|
130
|
-
// if (newTarget.prototype.hasOwnProperty(n) && !properties.includes(Helper.toString(n))) {
|
131
|
-
// throw Error(`Cannot override the final method "${Helper.toString(n)}"`);
|
132
|
-
// }
|
133
|
-
// });
|
134
|
-
// return Reflect.construct(target, args, newTarget);
|
135
|
-
// }
|
136
|
-
// });
|
137
|
-
//# sourceMappingURL=BaseController.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"BaseController.js","sourceRoot":"","sources":["../../src/controller/BaseController.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,2CAAwC;AAKxC;;;;;;GAMG;AACH,MAAa,cAAc;IAMvB;;;;;OAKG;IACH,YAAsB,GAAkB;QACpC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,EAAE,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACO,IAAI;IAEd,CAAC;IAED,MAAM;IACN,6HAA6H;IAC7H,KAAK;IACL,6BAA6B;IAC7B,8BAA8B;IAC9B,MAAM;IACN,oCAAoC;IACpC,gCAAgC;IAChC,IAAI;IAEJ,MAAM;IACN,qHAAqH;IACrH,KAAK;IACL,aAAa;IACb,kBAAkB;IAClB,8BAA8B;IAC9B,MAAM;IACN,mCAAmC;IACnC,gCAAgC;IAChC,IAAI;IAEJ;;;;;;;;;OASG;IACO,aAAa,CAAC,GAAQ,EAAE,IAAS,EAAE,WAAmB;QAC5D,IAAI,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AAoC;AACpC,6DAA6D;AAC7D,SAAS;AACT,2CAA2C;AAC3C,yDAAyD;AACzD,uGAAuG;AACvG,2FAA2F;AAC3F,gBAAgB;AAChB,cAAc;AACd,6DAA6D;AAC7D,QAAQ;AACR,MAAM"}
|
@@ -1,131 +0,0 @@
|
|
1
|
-
import { Koatty, KoattyContext } from 'koatty_core';
|
2
|
-
import { ApiInput, ApiOutput } from '../core/Component';
|
3
|
-
import { BaseController } from "./BaseController";
|
4
|
-
/**
|
5
|
-
* HTTP controller
|
6
|
-
*
|
7
|
-
* @export
|
8
|
-
* @class HttpController
|
9
|
-
* @implements {IController}
|
10
|
-
*/
|
11
|
-
export declare class HttpController extends BaseController {
|
12
|
-
app: Koatty;
|
13
|
-
ctx: KoattyContext;
|
14
|
-
/**
|
15
|
-
* Whether it is a GET request
|
16
|
-
*
|
17
|
-
* @public
|
18
|
-
* @returns {boolean}
|
19
|
-
* @memberof HttpController
|
20
|
-
*/
|
21
|
-
isGet(): boolean;
|
22
|
-
/**
|
23
|
-
* Whether it is a POST request
|
24
|
-
*
|
25
|
-
* @public
|
26
|
-
* @returns {boolean}
|
27
|
-
* @memberof HttpController
|
28
|
-
*/
|
29
|
-
isPost(): boolean;
|
30
|
-
/**
|
31
|
-
* Determines whether the METHOD request is specified
|
32
|
-
*
|
33
|
-
* @public
|
34
|
-
* @param {string} method
|
35
|
-
* @returns {boolean}
|
36
|
-
* @memberof HttpController
|
37
|
-
*/
|
38
|
-
isMethod(method: string): boolean;
|
39
|
-
/**
|
40
|
-
* Get/Set headers.
|
41
|
-
*
|
42
|
-
* @public
|
43
|
-
* @param {string} [name]
|
44
|
-
* @param {*} [value]
|
45
|
-
* @returns {*}
|
46
|
-
* @memberof HttpController
|
47
|
-
*/
|
48
|
-
header(name?: string, value?: any): any;
|
49
|
-
/**
|
50
|
-
* Get POST/GET parameters, the POST value is priority.
|
51
|
-
*
|
52
|
-
* @param {string} [name]
|
53
|
-
* @returns
|
54
|
-
* @memberof HttpController
|
55
|
-
*/
|
56
|
-
param(name?: string): Promise<any>;
|
57
|
-
/**
|
58
|
-
* Set response content-type
|
59
|
-
*
|
60
|
-
* @public
|
61
|
-
* @param {string} contentType
|
62
|
-
* @param {(string | boolean)} [encoding]
|
63
|
-
* @returns {string}
|
64
|
-
* @memberof HttpController
|
65
|
-
*/
|
66
|
-
type(contentType: string, encoding?: string | boolean): string;
|
67
|
-
/**
|
68
|
-
* set cache-control and expires header
|
69
|
-
*
|
70
|
-
* @public
|
71
|
-
* @param {number} [timeout=30]
|
72
|
-
* @returns {void}
|
73
|
-
* @memberof HttpController
|
74
|
-
*/
|
75
|
-
expires(timeout?: number): void;
|
76
|
-
/**
|
77
|
-
* Url redirect
|
78
|
-
*
|
79
|
-
* @param {string} urls
|
80
|
-
* @param {string} [alt]
|
81
|
-
* @returns {void}
|
82
|
-
* @memberof HttpController
|
83
|
-
*/
|
84
|
-
redirect(urls: string, alt?: string): void;
|
85
|
-
/**
|
86
|
-
* Block access
|
87
|
-
*
|
88
|
-
* @param {number} [code=403]
|
89
|
-
* @returns {Promise<any>}
|
90
|
-
* @memberof HttpController
|
91
|
-
*/
|
92
|
-
deny(code?: number): Promise<any>;
|
93
|
-
/**
|
94
|
-
* Set response Body content
|
95
|
-
*
|
96
|
-
* @param {*} data
|
97
|
-
* @param {string} [contentType]
|
98
|
-
* @param {string} [encoding]
|
99
|
-
* @returns {Promise<any>}
|
100
|
-
* @memberof HttpController
|
101
|
-
*/
|
102
|
-
body(data: any, contentType?: string, encoding?: string): Promise<any>;
|
103
|
-
/**
|
104
|
-
* Respond to json formatted content
|
105
|
-
*
|
106
|
-
* @param {*} data
|
107
|
-
* @returns {Promise<any>}
|
108
|
-
* @memberof HttpController
|
109
|
-
*/
|
110
|
-
json(data: any): Promise<any>;
|
111
|
-
/**
|
112
|
-
* Response to normalize json format content for success
|
113
|
-
*
|
114
|
-
* @param {(string | ApiInput)} msg 待处理的message消息
|
115
|
-
* @param {*} [data] 待处理的数据
|
116
|
-
* @param {number} [code=200] 错误码,默认0
|
117
|
-
* @returns {Promise<ApiOutput>}
|
118
|
-
* @memberof HttpController
|
119
|
-
*/
|
120
|
-
ok(msg: string | ApiInput, data?: any, code?: number): Promise<ApiOutput>;
|
121
|
-
/**
|
122
|
-
* Response to normalize json format content for fail
|
123
|
-
*
|
124
|
-
* @param {(string | ApiInput)} msg
|
125
|
-
* @param {*} [data]
|
126
|
-
* @param {number} [code=1]
|
127
|
-
* @returns {Promise<ApiOutput>}
|
128
|
-
* @memberof HttpController
|
129
|
-
*/
|
130
|
-
fail(msg: Error | string | ApiInput, data?: any, code?: number): Promise<ApiOutput>;
|
131
|
-
}
|
@@ -1,214 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.HttpController = void 0;
|
4
|
-
/**
|
5
|
-
* @ author: richen
|
6
|
-
* @ copyright: Copyright (c) - <richenlin(at)gmail.com>
|
7
|
-
* @ license: BSD (3-Clause)
|
8
|
-
* @ version: 2020-05-20 15:45:24
|
9
|
-
*/
|
10
|
-
const Helper_1 = require("../util/Helper");
|
11
|
-
const BaseController_1 = require("./BaseController");
|
12
|
-
/**
|
13
|
-
* HTTP controller
|
14
|
-
*
|
15
|
-
* @export
|
16
|
-
* @class HttpController
|
17
|
-
* @implements {IController}
|
18
|
-
*/
|
19
|
-
class HttpController extends BaseController_1.BaseController {
|
20
|
-
/**
|
21
|
-
* Whether it is a GET request
|
22
|
-
*
|
23
|
-
* @public
|
24
|
-
* @returns {boolean}
|
25
|
-
* @memberof HttpController
|
26
|
-
*/
|
27
|
-
isGet() {
|
28
|
-
return this.ctx.method === "GET";
|
29
|
-
}
|
30
|
-
/**
|
31
|
-
* Whether it is a POST request
|
32
|
-
*
|
33
|
-
* @public
|
34
|
-
* @returns {boolean}
|
35
|
-
* @memberof HttpController
|
36
|
-
*/
|
37
|
-
isPost() {
|
38
|
-
return this.ctx.method === "POST";
|
39
|
-
}
|
40
|
-
/**
|
41
|
-
* Determines whether the METHOD request is specified
|
42
|
-
*
|
43
|
-
* @public
|
44
|
-
* @param {string} method
|
45
|
-
* @returns {boolean}
|
46
|
-
* @memberof HttpController
|
47
|
-
*/
|
48
|
-
isMethod(method) {
|
49
|
-
return this.ctx.method === method.toUpperCase();
|
50
|
-
}
|
51
|
-
/**
|
52
|
-
* Get/Set headers.
|
53
|
-
*
|
54
|
-
* @public
|
55
|
-
* @param {string} [name]
|
56
|
-
* @param {*} [value]
|
57
|
-
* @returns {*}
|
58
|
-
* @memberof HttpController
|
59
|
-
*/
|
60
|
-
header(name, value) {
|
61
|
-
if (name === undefined) {
|
62
|
-
return this.ctx.headers;
|
63
|
-
}
|
64
|
-
if (value === undefined) {
|
65
|
-
return this.ctx.get(name);
|
66
|
-
}
|
67
|
-
return this.ctx.set(name, value);
|
68
|
-
}
|
69
|
-
/**
|
70
|
-
* Get POST/GET parameters, the POST value is priority.
|
71
|
-
*
|
72
|
-
* @param {string} [name]
|
73
|
-
* @returns
|
74
|
-
* @memberof HttpController
|
75
|
-
*/
|
76
|
-
param(name) {
|
77
|
-
return this.ctx.bodyParser().then((body) => {
|
78
|
-
const getParams = this.ctx.queryParser() || {};
|
79
|
-
const postParams = (body.post ? body.post : body) || {};
|
80
|
-
if (name !== undefined) {
|
81
|
-
return postParams[name] === undefined ? getParams[name] : postParams[name];
|
82
|
-
}
|
83
|
-
return { ...getParams, ...postParams };
|
84
|
-
});
|
85
|
-
}
|
86
|
-
/**
|
87
|
-
* Set response content-type
|
88
|
-
*
|
89
|
-
* @public
|
90
|
-
* @param {string} contentType
|
91
|
-
* @param {(string | boolean)} [encoding]
|
92
|
-
* @returns {string}
|
93
|
-
* @memberof HttpController
|
94
|
-
*/
|
95
|
-
type(contentType, encoding) {
|
96
|
-
if (encoding !== false && !contentType.includes("charset")) {
|
97
|
-
contentType = `${contentType}; charset=${encoding || this.app.config("encoding")}`;
|
98
|
-
}
|
99
|
-
this.ctx.type = contentType;
|
100
|
-
return contentType;
|
101
|
-
}
|
102
|
-
/**
|
103
|
-
* set cache-control and expires header
|
104
|
-
*
|
105
|
-
* @public
|
106
|
-
* @param {number} [timeout=30]
|
107
|
-
* @returns {void}
|
108
|
-
* @memberof HttpController
|
109
|
-
*/
|
110
|
-
expires(timeout = 30) {
|
111
|
-
timeout = Helper_1.Helper.toNumber(timeout) * 1000;
|
112
|
-
const date = new Date(Date.now() + timeout);
|
113
|
-
this.ctx.set("Cache-Control", `max-age=${timeout}`);
|
114
|
-
return this.ctx.set("Expires", date.toUTCString());
|
115
|
-
}
|
116
|
-
/**
|
117
|
-
* Url redirect
|
118
|
-
*
|
119
|
-
* @param {string} urls
|
120
|
-
* @param {string} [alt]
|
121
|
-
* @returns {void}
|
122
|
-
* @memberof HttpController
|
123
|
-
*/
|
124
|
-
redirect(urls, alt) {
|
125
|
-
return this.ctx.redirect(urls, alt);
|
126
|
-
}
|
127
|
-
/**
|
128
|
-
* Block access
|
129
|
-
*
|
130
|
-
* @param {number} [code=403]
|
131
|
-
* @returns {Promise<any>}
|
132
|
-
* @memberof HttpController
|
133
|
-
*/
|
134
|
-
deny(code = 403) {
|
135
|
-
return this.ctx.throw(code);
|
136
|
-
}
|
137
|
-
/**
|
138
|
-
* Set response Body content
|
139
|
-
*
|
140
|
-
* @param {*} data
|
141
|
-
* @param {string} [contentType]
|
142
|
-
* @param {string} [encoding]
|
143
|
-
* @returns {Promise<any>}
|
144
|
-
* @memberof HttpController
|
145
|
-
*/
|
146
|
-
body(data, contentType, encoding) {
|
147
|
-
contentType = contentType || "text/plain";
|
148
|
-
encoding = encoding || this.app.config("encoding") || "utf-8";
|
149
|
-
this.type(contentType, encoding);
|
150
|
-
this.ctx.body = data;
|
151
|
-
return null;
|
152
|
-
}
|
153
|
-
/**
|
154
|
-
* Respond to json formatted content
|
155
|
-
*
|
156
|
-
* @param {*} data
|
157
|
-
* @returns {Promise<any>}
|
158
|
-
* @memberof HttpController
|
159
|
-
*/
|
160
|
-
json(data) {
|
161
|
-
return this.body(data, "application/json");
|
162
|
-
}
|
163
|
-
/**
|
164
|
-
* Response to normalize json format content for success
|
165
|
-
*
|
166
|
-
* @param {(string | ApiInput)} msg 待处理的message消息
|
167
|
-
* @param {*} [data] 待处理的数据
|
168
|
-
* @param {number} [code=200] 错误码,默认0
|
169
|
-
* @returns {Promise<ApiOutput>}
|
170
|
-
* @memberof HttpController
|
171
|
-
*/
|
172
|
-
ok(msg, data, code = 0) {
|
173
|
-
const obj = this.formatApiData(msg, data, code);
|
174
|
-
return this.json(obj);
|
175
|
-
}
|
176
|
-
/**
|
177
|
-
* Response to normalize json format content for fail
|
178
|
-
*
|
179
|
-
* @param {(string | ApiInput)} msg
|
180
|
-
* @param {*} [data]
|
181
|
-
* @param {number} [code=1]
|
182
|
-
* @returns {Promise<ApiOutput>}
|
183
|
-
* @memberof HttpController
|
184
|
-
*/
|
185
|
-
fail(msg, data, code = 1) {
|
186
|
-
const obj = this.formatApiData(msg, data, code);
|
187
|
-
return this.json(obj);
|
188
|
-
}
|
189
|
-
}
|
190
|
-
exports.HttpController = HttpController;
|
191
|
-
// const properties = ["constructor", "init"];
|
192
|
-
// export const HttpController = new Proxy(Base, {
|
193
|
-
// set(target, key, value, receiver) {
|
194
|
-
// if (Reflect.get(target, key, receiver) === undefined) {
|
195
|
-
// return Reflect.set(target, key, value, receiver);
|
196
|
-
// } else if (key === "init") {
|
197
|
-
// return Reflect.set(target, key, value, receiver);
|
198
|
-
// } else {
|
199
|
-
// throw Error("Cannot redefine getter-only property");
|
200
|
-
// }
|
201
|
-
// },
|
202
|
-
// deleteProperty(target, key) {
|
203
|
-
// throw Error("Cannot delete getter-only property");
|
204
|
-
// },
|
205
|
-
// construct(target, args, newTarget) {
|
206
|
-
// Reflect.ownKeys(target.prototype).map((n) => {
|
207
|
-
// if (newTarget.prototype.hasOwnProperty(n) && !properties.includes(Helper.toString(n))) {
|
208
|
-
// throw Error(`Cannot override the final method "${Helper.toString(n)}"`);
|
209
|
-
// }
|
210
|
-
// });
|
211
|
-
// return Reflect.construct(target, args, newTarget);
|
212
|
-
// }
|
213
|
-
// });
|
214
|
-
//# sourceMappingURL=HttpController.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"HttpController.js","sourceRoot":"","sources":["../../src/controller/HttpController.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,2CAAwC;AAGxC,qDAAkD;AAElD;;;;;;GAMG;AACH,MAAa,cAAe,SAAQ,+BAAc;IAI9C;;;;;;OAMG;IACI,KAAK;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,KAAK,CAAC;IACrC,CAAC;IAED;;;;;;OAMG;IACI,MAAM;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC;IACtC,CAAC;IAED;;;;;;;OAOG;IACI,QAAQ,CAAC,MAAc;QAC1B,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,WAAW,EAAE,CAAC;IACpD,CAAC;IAED;;;;;;;;OAQG;IACI,MAAM,CAAC,IAAa,EAAE,KAAW;QACpC,IAAI,IAAI,KAAK,SAAS,EAAE;YACpB,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;SAC3B;QACD,IAAI,KAAK,KAAK,SAAS,EAAE;YACrB,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SAC7B;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,IAAa;QACtB,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC,IAAS,EAAE,EAAE;YAC5C,MAAM,SAAS,GAAQ,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC;YACpD,MAAM,UAAU,GAAG,CAAC,I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ClE,gEAAgE;AAChE,uCAAuC;AACvC,gEAAgE;AAChE,mBAAmB;AACnB,mEAAmE;AACnE,YAAY;AACZ,SAAS;AACT,oCAAoC;AACpC,6DAA6D;AAC7D,SAAS;AACT,2CAA2C;AAC3C,yDAAyD;AACzD,uGAAuG;AACvG,2FAA2F;AAC3F,gBAAgB;AAChB,cAAc;AACd,6DAA6D;AAC7D,QAAQ;AACR,MAAM"}
|
package/dist/core/Bootstrap.d.ts
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @ author: richen
|
3
|
-
* @ copyright: Copyright (c) - <richenlin(at)gmail.com>
|
4
|
-
* @ license: BSD (3-Clause)
|
5
|
-
* @ version: 2020-07-06 11:22:58
|
6
|
-
*/
|
7
|
-
import "reflect-metadata";
|
8
|
-
import { Koatty } from 'koatty_core';
|
9
|
-
/**
|
10
|
-
* Bootstrap application
|
11
|
-
*
|
12
|
-
* @export
|
13
|
-
* @param {Function} [bootFunc]
|
14
|
-
* @returns {ClassDecorator}
|
15
|
-
*/
|
16
|
-
export declare function Bootstrap(bootFunc?: Function): ClassDecorator;
|
17
|
-
/**
|
18
|
-
* Define project scan path
|
19
|
-
*
|
20
|
-
* @export
|
21
|
-
* @param {(string | string[])} [scanPath]
|
22
|
-
* @returns {ClassDecorator}
|
23
|
-
*/
|
24
|
-
export declare function ComponentScan(scanPath?: string | string[]): ClassDecorator;
|
25
|
-
/**
|
26
|
-
* Define project configuration scan path
|
27
|
-
*
|
28
|
-
* @export
|
29
|
-
* @param {(string | string[])} [scanPath]
|
30
|
-
* @returns {ClassDecorator}
|
31
|
-
*/
|
32
|
-
export declare function ConfigurationScan(scanPath?: string | string[]): ClassDecorator;
|
33
|
-
export declare type AppReadyHookFunc = (app: Koatty) => Promise<any>;
|
34
|
-
/**
|
35
|
-
* bind AppReadyHookFunc
|
36
|
-
* example:
|
37
|
-
* export function TestDecorator(): ClassDecorator {
|
38
|
-
* return (target: any) => {
|
39
|
-
* BindAppReadyHook((app: Koatty) => {
|
40
|
-
* // todo
|
41
|
-
* return Promise.resolve();
|
42
|
-
* }, target)
|
43
|
-
* }
|
44
|
-
* }
|
45
|
-
*
|
46
|
-
* @export
|
47
|
-
* @param {AppReadyHookFunc} func
|
48
|
-
* @param {*} target
|
49
|
-
*/
|
50
|
-
export declare function BindAppReadyHook(func: AppReadyHookFunc, target: any): void;
|