koatty 3.5.10 → 3.5.12-2
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/CHANGELOG.md +3 -36
- package/README.md +5 -9
- 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 +98 -0
- package/package.json +38 -38
- package/.eslintignore +0 -9
- package/.eslintrc.js +0 -43
- 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 -23
- package/dist/config/middleware.js +0 -34
- 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 -215
- package/dist/controller/HttpController.js.map +0 -1
- package/dist/core/Bootstrap.d.ts +0 -50
- package/dist/core/Bootstrap.js +0 -215
- 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 -407
- 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/jest.config.js +0 -36
- package/jest_html_reporters.html +0 -60
- package/tsconfig.json +0 -67
package/CHANGELOG.md
CHANGED
@@ -2,41 +2,8 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
4
4
|
|
5
|
-
### [3.5.
|
5
|
+
### [3.5.12-2](https://github.com/thinkkoa/koatty/compare/v3.5.12-1...v3.5.12-2) (2021-12-21)
|
6
6
|
|
7
|
-
### [3.
|
7
|
+
### [3.5.12-1](https://github.com/thinkkoa/koatty/compare/v3.5.12-0...v3.5.12-1) (2021-12-21)
|
8
8
|
|
9
|
-
### [3.
|
10
|
-
|
11
|
-
### [3.4.6](https://github.com/thinkkoa/koatty/compare/v3.4.4...v3.4.6) (2021-11-25)
|
12
|
-
|
13
|
-
### [3.4.4](https://github.com/thinkkoa/koatty/compare/v3.4.2...v3.4.4) (2021-11-20)
|
14
|
-
|
15
|
-
### [3.4.2](https://github.com/thinkkoa/koatty/compare/v3.3.6...v3.4.2) (2021-11-19)
|
16
|
-
|
17
|
-
### [3.3.6](https://github.com/thinkkoa/koatty/compare/v3.2.12...v3.3.6) (2021-07-13)
|
18
|
-
|
19
|
-
### [3.3.4](https://github.com/thinkkoa/koatty/compare/v3.3.3...v3.3.4) (2021-07-07)
|
20
|
-
|
21
|
-
### [3.3.3](https://github.com/thinkkoa/koatty/compare/v3.3.2...v3.3.3) (2021-07-06)
|
22
|
-
|
23
|
-
### [3.3.2](https://github.com/thinkkoa/koatty/compare/v3.3.0...v3.3.2) (2021-07-01)
|
24
|
-
|
25
|
-
### [3.3.0](https://github.com/thinkkoa/koatty/compare/v3.2.12...v3.3.0) (2021-06-24)
|
26
|
-
### [3.2.12](https://github.com/thinkkoa/koatty/compare/v3.2.11...v3.2.12) (2021-06-24)
|
27
|
-
|
28
|
-
### [3.2.11](https://github.com/thinkkoa/koatty/compare/v3.2.10...v3.2.11) (2021-06-24)
|
29
|
-
|
30
|
-
### [3.2.10](https://github.com/thinkkoa/koatty/compare/v3.2.8...v3.2.10) (2021-06-23)
|
31
|
-
|
32
|
-
|
33
|
-
### Bug Fixes
|
34
|
-
|
35
|
-
* eslint ([2297a9d](https://github.com/thinkkoa/koatty/commit/2297a9dc054e911f31dbe5d8802d982077316df7))
|
36
|
-
|
37
|
-
### 3.2.8 (2021-06-21)
|
38
|
-
|
39
|
-
|
40
|
-
### Bug Fixes
|
41
|
-
|
42
|
-
* --story=[#4](https://github.com/thinkkoa/koatty/issues/4) [bug] RequestMapping内的装饰器用法范围模糊 ([93f7abd](https://github.com/thinkkoa/koatty/commit/93f7abd776bc14449e762c163a1194c6608e1cd3))
|
9
|
+
### [3.5.12-0](https://github.com/thinkkoa/koatty/compare/v3.5.10...v3.5.12-0) (2021-12-21)
|
package/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# koatty
|
2
2
|
|
3
|
-
Koa2 + Typescript = koatty.
|
3
|
+
Koa2 + Typescript + IOC = koatty.
|
4
4
|
|
5
5
|
Use Typescript's decorator implement IOC and AOP.
|
6
6
|
|
@@ -11,13 +11,13 @@ Use Typescript's decorator implement IOC and AOP.
|
|
11
11
|
* HTTP、HTTPS、HTTP2 .
|
12
12
|
* gRPC server.
|
13
13
|
* WebSocket server. (unstable)
|
14
|
+
* Support loading environment configuration, support parsing command line parameters (process. argv) and environment variables (process.env)
|
14
15
|
|
15
16
|
|
16
17
|
## Documentation
|
17
18
|
|
18
|
-
[koatty_doc_CN](https://koatty.
|
19
|
+
[koatty_doc_CN](https://koatty.org/) (In progress💪)
|
19
20
|
|
20
|
-
[koatty_doc_EN] come soon...
|
21
21
|
|
22
22
|
## Installation
|
23
23
|
|
@@ -60,14 +60,11 @@ koatty middleware test
|
|
60
60
|
```
|
61
61
|
### 4.Create a Model(Optional)
|
62
62
|
|
63
|
-
Supports [
|
63
|
+
Supports [typeorm](https://github.com/typeorm/typeorm). Please expand other ORM by yourself.
|
64
64
|
|
65
65
|
```shell
|
66
|
-
//thinkorm
|
67
|
-
koatty middleware test
|
68
|
-
|
69
66
|
//typeorm
|
70
|
-
koatty middleware
|
67
|
+
koatty middleware test
|
71
68
|
|
72
69
|
```
|
73
70
|
|
@@ -148,4 +145,3 @@ Check out the [quick start example][quick-example].
|
|
148
145
|
|
149
146
|
|
150
147
|
|
151
|
-
|
package/dist/LICENSE
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
BSD 3-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2020, Koatty
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/dist/README.md
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
# koatty
|
2
|
+
|
3
|
+
Koa2 + Typescript + IOC = koatty.
|
4
|
+
|
5
|
+
Use Typescript's decorator implement IOC and AOP.
|
6
|
+
|
7
|
+
[](https://www.npmjs.com/package/koatty)[](https://npmcharts.com/compare/koatty?minimal=true)
|
8
|
+
|
9
|
+
## New features
|
10
|
+
|
11
|
+
* HTTP、HTTPS、HTTP2 .
|
12
|
+
* gRPC server.
|
13
|
+
* WebSocket server. (unstable)
|
14
|
+
* Support loading environment configuration, support parsing command line parameters (process. argv) and environment variables (process.env)
|
15
|
+
|
16
|
+
|
17
|
+
## Documentation
|
18
|
+
|
19
|
+
[koatty_doc_CN](https://koatty.org/) (In progress💪)
|
20
|
+
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
```shell
|
25
|
+
npm i -g koatty_cli
|
26
|
+
```
|
27
|
+
|
28
|
+
## Quick Start
|
29
|
+
|
30
|
+
### 1.Create Project
|
31
|
+
|
32
|
+
```shell
|
33
|
+
koatty new projectName
|
34
|
+
|
35
|
+
cd ./projectName
|
36
|
+
|
37
|
+
yarn install
|
38
|
+
|
39
|
+
npm start
|
40
|
+
```
|
41
|
+
|
42
|
+
### 2.Create a Controller
|
43
|
+
```shell
|
44
|
+
koatty controller test
|
45
|
+
|
46
|
+
```
|
47
|
+
|
48
|
+
### 3.Create a Service
|
49
|
+
|
50
|
+
```shell
|
51
|
+
koatty service test
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
### 3.Create a Middleware (Optional)
|
56
|
+
|
57
|
+
```shell
|
58
|
+
koatty middleware test
|
59
|
+
|
60
|
+
```
|
61
|
+
### 4.Create a Model(Optional)
|
62
|
+
|
63
|
+
Supports [typeorm](https://github.com/typeorm/typeorm). Please expand other ORM by yourself.
|
64
|
+
|
65
|
+
```shell
|
66
|
+
//typeorm
|
67
|
+
koatty middleware test
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
### 5.Create a DTOClass (Optional)
|
72
|
+
|
73
|
+
```shell
|
74
|
+
koatty dto test
|
75
|
+
|
76
|
+
```
|
77
|
+
|
78
|
+
### 6.Define TestController
|
79
|
+
|
80
|
+
```javascript
|
81
|
+
import { Controller, BaseController, Autowired, GetMapping, RequestBody, PathVariable, PostMapping, RequestMapping, RequestMethod, Valid } from "koatty";
|
82
|
+
import { TestDTO } from "../model/dto/TestDTO";
|
83
|
+
import { TestService } from "../service/TestService";
|
84
|
+
import { App } from "../App";
|
85
|
+
|
86
|
+
@Controller()
|
87
|
+
export class IndexController extends BaseController {
|
88
|
+
app: App;
|
89
|
+
|
90
|
+
@Autowired()
|
91
|
+
private testService: TestService;
|
92
|
+
|
93
|
+
init() {
|
94
|
+
this.cache = {};
|
95
|
+
}
|
96
|
+
|
97
|
+
@RequestMapping("/:name", RequestMethod.ALL)
|
98
|
+
async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
|
99
|
+
const info = await this.testService.sayHello(name).catch((err: any) => this.fail(err.message));
|
100
|
+
return info;
|
101
|
+
}
|
102
|
+
|
103
|
+
@PostMapping("/test")
|
104
|
+
@Validated() //need DTOClass
|
105
|
+
test(@RequestParam() params: TestDTO) {
|
106
|
+
return this.ok("test", params);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
```
|
110
|
+
|
111
|
+
## How to debug
|
112
|
+
|
113
|
+
if you use vscode , edit the `.vscode/launch.json` , like this:
|
114
|
+
```
|
115
|
+
{
|
116
|
+
"version": "0.2.0",
|
117
|
+
"configurations": [
|
118
|
+
{
|
119
|
+
"type": "node",
|
120
|
+
"request": "launch",
|
121
|
+
"name": "TS Program",
|
122
|
+
"args": [
|
123
|
+
"${workspaceRoot}/src/App.ts"
|
124
|
+
],
|
125
|
+
"runtimeArgs": [
|
126
|
+
"--nolazy",
|
127
|
+
"-r",
|
128
|
+
"ts-node/register"
|
129
|
+
],
|
130
|
+
"sourceMaps": true,
|
131
|
+
"cwd": "${workspaceRoot}",
|
132
|
+
"protocol": "inspector",
|
133
|
+
"internalConsoleOptions": "neverOpen"
|
134
|
+
}
|
135
|
+
]
|
136
|
+
}
|
137
|
+
```
|
138
|
+
Select `TS Program` to debug run. Try to call `http://localhost:3000/` .
|
139
|
+
|
140
|
+
## Example
|
141
|
+
|
142
|
+
Check out the [quick start example][quick-example].
|
143
|
+
|
144
|
+
[quick-example]: https://github.com/thinkkoa/koatty_demo/
|
145
|
+
|
146
|
+
|
147
|
+
|
package/dist/index.d.ts
CHANGED
@@ -1,19 +1,363 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
export
|
19
|
-
|
1
|
+
/*!
|
2
|
+
* @Author: richen
|
3
|
+
* @Date: 2021-12-21 12:43:54
|
4
|
+
* @License: BSD (3-Clause)
|
5
|
+
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
|
+
* @HomePage: https://koatty.org/
|
7
|
+
*/
|
8
|
+
import { Helper } from 'koatty_lib';
|
9
|
+
import Koa from 'koa';
|
10
|
+
import { Koatty } from 'koatty_core';
|
11
|
+
import { KoattyContext } from 'koatty_core';
|
12
|
+
import { Logger as Logger_2 } from 'koatty_logger';
|
13
|
+
import { ObjectDefinitionOptions } from 'koatty_container';
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Interface for Api input
|
17
|
+
*/
|
18
|
+
export declare interface ApiInput {
|
19
|
+
code?: number;
|
20
|
+
message?: string;
|
21
|
+
data?: any;
|
22
|
+
}
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Interface for Api output
|
26
|
+
*/
|
27
|
+
export declare interface ApiOutput {
|
28
|
+
code: number;
|
29
|
+
message: string;
|
30
|
+
data: any;
|
31
|
+
}
|
32
|
+
|
33
|
+
export declare type AppReadyHookFunc = (app: Koatty) => Promise<any>;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Base controller
|
37
|
+
*
|
38
|
+
* @export
|
39
|
+
* @class BaseController
|
40
|
+
* @implements {IController}
|
41
|
+
*/
|
42
|
+
export declare class BaseController implements IController {
|
43
|
+
app: Koatty;
|
44
|
+
readonly ctx: KoattyContext;
|
45
|
+
/**
|
46
|
+
* instance of BaseController.
|
47
|
+
* @param {Koatty} app
|
48
|
+
* @param {KoattyContext} ctx
|
49
|
+
* @memberof BaseController
|
50
|
+
*/
|
51
|
+
/**
|
52
|
+
* init
|
53
|
+
*
|
54
|
+
* @protected
|
55
|
+
* @memberof BaseController
|
56
|
+
*/
|
57
|
+
/**
|
58
|
+
* Response to normalize json format content for success
|
59
|
+
*
|
60
|
+
* @param {(string | ApiInput)} msg 待处理的message消息
|
61
|
+
* @param {*} [data] 待处理的数据
|
62
|
+
* @param {number} [code=200] 错误码,默认0
|
63
|
+
* @returns {*}
|
64
|
+
* @memberof BaseController
|
65
|
+
*/
|
66
|
+
ok(msg: string | ApiInput, data?: any, code?: number): Promise<ApiOutput>;
|
67
|
+
/**
|
68
|
+
* Response to normalize json format content for fail
|
69
|
+
*
|
70
|
+
* @param {(string | ApiInput)} msg
|
71
|
+
* @param {*} [data]
|
72
|
+
* @param {number} [code=1]
|
73
|
+
* @returns {*}
|
74
|
+
* @memberof BaseController
|
75
|
+
*/
|
76
|
+
fail(msg: Error | string | ApiInput, data?: any, code?: number): any;
|
77
|
+
}
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Base class
|
81
|
+
*
|
82
|
+
* @export
|
83
|
+
* @class Base
|
84
|
+
*/
|
85
|
+
export declare class BaseService implements IService {
|
86
|
+
app: Koatty;
|
87
|
+
/**
|
88
|
+
* instance of Base.
|
89
|
+
* @param {...any[]} arg
|
90
|
+
* @memberof Base
|
91
|
+
*/
|
92
|
+
/**
|
93
|
+
* init
|
94
|
+
*
|
95
|
+
* @protected
|
96
|
+
* @param {...any[]} arg
|
97
|
+
* @memberof Base
|
98
|
+
*/
|
99
|
+
}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* bind AppReadyHookFunc
|
103
|
+
* example:
|
104
|
+
* export function TestDecorator(): ClassDecorator {
|
105
|
+
* return (target: any) => {
|
106
|
+
* BindAppReadyHook((app: Koatty) => {
|
107
|
+
* // todo
|
108
|
+
* return Promise.resolve();
|
109
|
+
* }, target)
|
110
|
+
* }
|
111
|
+
* }
|
112
|
+
*
|
113
|
+
* @export
|
114
|
+
* @param {AppReadyHookFunc} func
|
115
|
+
* @param {*} target
|
116
|
+
*/
|
117
|
+
export declare function BindAppReadyHook(func: AppReadyHookFunc, target: any): void;
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Bootstrap application
|
121
|
+
*
|
122
|
+
* @export
|
123
|
+
* @param {Function} [bootFunc]
|
124
|
+
* @returns {ClassDecorator}
|
125
|
+
*/
|
126
|
+
export declare function Bootstrap(bootFunc?: Function): ClassDecorator;
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Indicates that an decorated class is a "component".
|
130
|
+
*
|
131
|
+
* @export
|
132
|
+
* @param {string} [identifier] component name
|
133
|
+
* @returns {ClassDecorator}
|
134
|
+
*/
|
135
|
+
export declare function Component(identifier?: string): ClassDecorator;
|
136
|
+
|
137
|
+
/**
|
138
|
+
* Define project scan path
|
139
|
+
*
|
140
|
+
* @export
|
141
|
+
* @param {(string | string[])} [scanPath]
|
142
|
+
* @returns {ClassDecorator}
|
143
|
+
*/
|
144
|
+
export declare function ComponentScan(scanPath?: string | string[]): ClassDecorator;
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Define project configuration scan path
|
148
|
+
*
|
149
|
+
* @export
|
150
|
+
* @param {(string | string[])} [scanPath]
|
151
|
+
* @returns {ClassDecorator}
|
152
|
+
*/
|
153
|
+
export declare function ConfigurationScan(scanPath?: string | string[]): ClassDecorator;
|
154
|
+
|
155
|
+
/**
|
156
|
+
* Indicates that an decorated class is a "controller".
|
157
|
+
*
|
158
|
+
* @export
|
159
|
+
* @param {string} [path] controller router path
|
160
|
+
* @returns {ClassDecorator}
|
161
|
+
*/
|
162
|
+
export declare function Controller(path?: string): ClassDecorator;
|
163
|
+
|
164
|
+
export { Helper }
|
165
|
+
|
166
|
+
/**
|
167
|
+
* HTTP controller
|
168
|
+
*
|
169
|
+
* @export
|
170
|
+
* @class HttpController
|
171
|
+
* @implements {IController}
|
172
|
+
*/
|
173
|
+
export declare class HttpController extends BaseController {
|
174
|
+
/**
|
175
|
+
* Whether it is a GET request
|
176
|
+
*
|
177
|
+
* @public
|
178
|
+
* @returns {boolean}
|
179
|
+
* @memberof HttpController
|
180
|
+
*/
|
181
|
+
isGet(): boolean;
|
182
|
+
/**
|
183
|
+
* Whether it is a POST request
|
184
|
+
*
|
185
|
+
* @public
|
186
|
+
* @returns {boolean}
|
187
|
+
* @memberof HttpController
|
188
|
+
*/
|
189
|
+
isPost(): boolean;
|
190
|
+
/**
|
191
|
+
* Determines whether the METHOD request is specified
|
192
|
+
*
|
193
|
+
* @public
|
194
|
+
* @param {string} method
|
195
|
+
* @returns {boolean}
|
196
|
+
* @memberof HttpController
|
197
|
+
*/
|
198
|
+
isMethod(method: string): boolean;
|
199
|
+
/**
|
200
|
+
* Get/Set headers.
|
201
|
+
*
|
202
|
+
* @public
|
203
|
+
* @param {string} [name]
|
204
|
+
* @param {*} [value]
|
205
|
+
* @returns {*}
|
206
|
+
* @memberof HttpController
|
207
|
+
*/
|
208
|
+
header(name?: string, value?: any): any;
|
209
|
+
/**
|
210
|
+
* Get POST/GET parameters, the POST value is priority.
|
211
|
+
*
|
212
|
+
* @param {string} [name]
|
213
|
+
* @returns
|
214
|
+
* @memberof HttpController
|
215
|
+
*/
|
216
|
+
param(name?: string): any;
|
217
|
+
/**
|
218
|
+
* Set response content-type
|
219
|
+
*
|
220
|
+
* @public
|
221
|
+
* @param {string} contentType
|
222
|
+
* @param {(string | boolean)} [encoding]
|
223
|
+
* @returns {string}
|
224
|
+
* @memberof HttpController
|
225
|
+
*/
|
226
|
+
type(contentType: string, encoding?: string | boolean): string;
|
227
|
+
/**
|
228
|
+
* set cache-control and expires header
|
229
|
+
*
|
230
|
+
* @public
|
231
|
+
* @param {number} [timeout=30]
|
232
|
+
* @returns {void}
|
233
|
+
* @memberof HttpController
|
234
|
+
*/
|
235
|
+
expires(timeout?: number): void;
|
236
|
+
/**
|
237
|
+
* Url redirect
|
238
|
+
*
|
239
|
+
* @param {string} urls
|
240
|
+
* @param {string} [alt]
|
241
|
+
* @returns {void}
|
242
|
+
* @memberof HttpController
|
243
|
+
*/
|
244
|
+
redirect(urls: string, alt?: string): void;
|
245
|
+
/**
|
246
|
+
* Block access
|
247
|
+
*
|
248
|
+
* @param {number} [code=403]
|
249
|
+
* @returns {Promise<any>}
|
250
|
+
* @memberof HttpController
|
251
|
+
*/
|
252
|
+
deny(code?: number): Promise<any>;
|
253
|
+
/**
|
254
|
+
* Set response Body content
|
255
|
+
*
|
256
|
+
* @param {*} data
|
257
|
+
* @param {string} [contentType]
|
258
|
+
* @param {string} [encoding]
|
259
|
+
* @returns {Promise<any>}
|
260
|
+
* @memberof HttpController
|
261
|
+
*/
|
262
|
+
body(data: any, contentType?: string, encoding?: string): Promise<any>;
|
263
|
+
/**
|
264
|
+
* Respond to json formatted content
|
265
|
+
*
|
266
|
+
* @param {*} data
|
267
|
+
* @returns {Promise<any>}
|
268
|
+
* @memberof HttpController
|
269
|
+
*/
|
270
|
+
json(data: any): Promise<any>;
|
271
|
+
/**
|
272
|
+
* Response to normalize json format content for success
|
273
|
+
*
|
274
|
+
* @param {(string | ApiInput)} msg 待处理的message消息
|
275
|
+
* @param {*} [data] 待处理的数据
|
276
|
+
* @param {number} [code=200] 错误码,默认0
|
277
|
+
* @returns {*}
|
278
|
+
* @memberof HttpController
|
279
|
+
*/
|
280
|
+
ok(msg: string | ApiInput, data?: any, code?: number): Promise<any>;
|
281
|
+
/**
|
282
|
+
* Response to normalize json format content for fail
|
283
|
+
*
|
284
|
+
* @param {(string | ApiInput)} msg
|
285
|
+
* @param {*} [data]
|
286
|
+
* @param {number} [code=1]
|
287
|
+
* @returns {*}
|
288
|
+
* @memberof HttpController
|
289
|
+
*/
|
290
|
+
fail(msg: Error | string | ApiInput, data?: any, code?: number): Promise<any>;
|
291
|
+
}
|
292
|
+
|
293
|
+
/**
|
294
|
+
* Interface for Controller
|
295
|
+
*/
|
296
|
+
export declare interface IController {
|
297
|
+
app: Koatty;
|
298
|
+
readonly ctx: KoattyContext;
|
299
|
+
__befor?: () => Promise<any>;
|
300
|
+
__after?: () => Promise<any>;
|
301
|
+
readonly fail: (msg?: Error | string | ApiInput, data?: any, ret?: number) => Promise<any>;
|
302
|
+
readonly ok: (msg?: string | ApiInput, data?: any, ret?: number) => Promise<any>;
|
303
|
+
}
|
304
|
+
|
305
|
+
/**
|
306
|
+
* Interface for Middleware
|
307
|
+
*/
|
308
|
+
export declare interface IMiddleware {
|
309
|
+
run: (options: any, app: Koatty) => Koa.Middleware;
|
310
|
+
}
|
311
|
+
|
312
|
+
/**
|
313
|
+
* Interface for Plugin
|
314
|
+
*/
|
315
|
+
export declare interface IPlugin {
|
316
|
+
run: (options: any, app: Koatty) => Promise<any>;
|
317
|
+
}
|
318
|
+
|
319
|
+
/**
|
320
|
+
* Interface for Service
|
321
|
+
*/
|
322
|
+
export declare interface IService {
|
323
|
+
app: Koatty;
|
324
|
+
}
|
325
|
+
|
326
|
+
export declare const Logger: Logger_2;
|
327
|
+
|
328
|
+
/**
|
329
|
+
* Indicates that an decorated class is a "middleware".
|
330
|
+
*
|
331
|
+
* @export
|
332
|
+
* @param {string} [identifier] middleware name
|
333
|
+
* @returns {ClassDecorator}
|
334
|
+
*/
|
335
|
+
export declare function Middleware(identifier?: string): ClassDecorator;
|
336
|
+
|
337
|
+
/**
|
338
|
+
* Indicates that an decorated class is a "plugin".
|
339
|
+
*
|
340
|
+
* @export
|
341
|
+
* @param {string} [identifier]
|
342
|
+
* @returns {ClassDecorator}
|
343
|
+
*/
|
344
|
+
export declare function Plugin(identifier?: string): ClassDecorator;
|
345
|
+
|
346
|
+
/**
|
347
|
+
* Indicates that an decorated class is a "service".
|
348
|
+
*
|
349
|
+
* @export
|
350
|
+
* @param {string} [identifier] middleware name
|
351
|
+
* @returns {ClassDecorator}
|
352
|
+
*/
|
353
|
+
export declare function Service(identifier?: string): ClassDecorator;
|
354
|
+
|
355
|
+
|
356
|
+
export * from "koatty_container";
|
357
|
+
export * from "koatty_core";
|
358
|
+
export * from "koatty_exception";
|
359
|
+
export * from "koatty_router";
|
360
|
+
export * from "koatty_serve";
|
361
|
+
export * from "koatty_trace";
|
362
|
+
|
363
|
+
export { }
|