koatty 3.10.4 → 3.11.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/CHANGELOG.md +14 -0
- package/README.md +12 -8
- package/dist/README.md +12 -8
- package/dist/index.d.ts +68 -6
- package/dist/index.js +277 -168
- package/dist/index.mjs +273 -170
- package/dist/package.json +3 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,20 @@
|
|
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.11.1](https://github.com/thinkkoa/koatty/compare/v3.11.0...v3.11.1) (2024-01-03)
|
6
|
+
|
7
|
+
|
8
|
+
### Bug Fixes
|
9
|
+
|
10
|
+
* aspect interface ([03b1884](https://github.com/thinkkoa/koatty/commit/03b188401d694ca116c58c71fc0270da8c163cc1))
|
11
|
+
|
12
|
+
## [3.11.0](https://github.com/thinkkoa/koatty/compare/v3.10.4...v3.11.0) (2024-01-03)
|
13
|
+
|
14
|
+
|
15
|
+
### Features
|
16
|
+
|
17
|
+
* 增加Output类 ([09e43c4](https://github.com/thinkkoa/koatty/commit/09e43c49e2e6bc6c9cb85cd03081bd5f25134c5b))
|
18
|
+
|
5
19
|
### [3.10.4](https://github.com/thinkkoa/koatty/compare/v3.10.4-5...v3.10.4) (2023-12-24)
|
6
20
|
|
7
21
|
|
package/README.md
CHANGED
@@ -57,37 +57,41 @@ npm start
|
|
57
57
|
default Controller:
|
58
58
|
|
59
59
|
```javascript
|
60
|
-
import { Controller,
|
61
|
-
PostMapping, RequestMapping, RequestMethod, Valid } from "koatty";
|
60
|
+
import { Controller, Autowired, GetMapping, RequestBody, PathVariable,
|
61
|
+
PostMapping, RequestMapping, RequestMethod, Valid, Output } from "koatty";
|
62
62
|
import { TestDTO } from "../model/dto/TestDTO";
|
63
63
|
import { TestService } from "../service/TestService";
|
64
64
|
import { App } from "../App";
|
65
65
|
|
66
66
|
@Controller()
|
67
|
-
export class IndexController
|
67
|
+
export class IndexController {
|
68
68
|
app: App;
|
69
69
|
|
70
70
|
@Autowired()
|
71
71
|
private testService: TestService;
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
/**
|
74
|
+
* constructor
|
75
|
+
*
|
76
|
+
*/
|
77
|
+
constructor(ctx: KoattyContext) {
|
78
|
+
this.ctx = ctx;
|
75
79
|
}
|
76
80
|
|
77
81
|
@RequestMapping("/:name", RequestMethod.ALL)
|
78
82
|
async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
|
79
83
|
try {
|
80
84
|
const info = await this.testService.sayHello(name);
|
81
|
-
return
|
85
|
+
return Output.ok(this.ctx, "success", info);
|
82
86
|
} catch (err: Error) {
|
83
|
-
return
|
87
|
+
return Output.fail(this.ctx, err.message));
|
84
88
|
}
|
85
89
|
}
|
86
90
|
|
87
91
|
@PostMapping("/test")
|
88
92
|
@Validated() //need DTOClass
|
89
93
|
test(@RequestParam() params: TestDTO) {
|
90
|
-
return
|
94
|
+
return Output.ok(this.ctx, "test", params);
|
91
95
|
}
|
92
96
|
}
|
93
97
|
```
|
package/dist/README.md
CHANGED
@@ -57,37 +57,41 @@ npm start
|
|
57
57
|
default Controller:
|
58
58
|
|
59
59
|
```javascript
|
60
|
-
import { Controller,
|
61
|
-
PostMapping, RequestMapping, RequestMethod, Valid } from "koatty";
|
60
|
+
import { Controller, Autowired, GetMapping, RequestBody, PathVariable,
|
61
|
+
PostMapping, RequestMapping, RequestMethod, Valid, Output } from "koatty";
|
62
62
|
import { TestDTO } from "../model/dto/TestDTO";
|
63
63
|
import { TestService } from "../service/TestService";
|
64
64
|
import { App } from "../App";
|
65
65
|
|
66
66
|
@Controller()
|
67
|
-
export class IndexController
|
67
|
+
export class IndexController {
|
68
68
|
app: App;
|
69
69
|
|
70
70
|
@Autowired()
|
71
71
|
private testService: TestService;
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
/**
|
74
|
+
* constructor
|
75
|
+
*
|
76
|
+
*/
|
77
|
+
constructor(ctx: KoattyContext) {
|
78
|
+
this.ctx = ctx;
|
75
79
|
}
|
76
80
|
|
77
81
|
@RequestMapping("/:name", RequestMethod.ALL)
|
78
82
|
async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
|
79
83
|
try {
|
80
84
|
const info = await this.testService.sayHello(name);
|
81
|
-
return
|
85
|
+
return Output.ok(this.ctx, "success", info);
|
82
86
|
} catch (err: Error) {
|
83
|
-
return
|
87
|
+
return Output.fail(this.ctx, err.message));
|
84
88
|
}
|
85
89
|
}
|
86
90
|
|
87
91
|
@PostMapping("/test")
|
88
92
|
@Validated() //need DTOClass
|
89
93
|
test(@RequestParam() params: TestDTO) {
|
90
|
-
return
|
94
|
+
return Output.ok(this.ctx, "test", params);
|
91
95
|
}
|
92
96
|
}
|
93
97
|
```
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
* @Author: richen
|
3
|
-
* @Date:
|
3
|
+
* @Date: 2024-01-04 07:59:26
|
4
4
|
* @License: BSD (3-Clause)
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
6
6
|
* @HomePage: https://koatty.org/
|
@@ -9,10 +9,12 @@ import { AppEvent } from 'koatty_core';
|
|
9
9
|
import { Config } from 'koatty_config';
|
10
10
|
import { EventHookFunc } from 'koatty_core';
|
11
11
|
import { Helper } from 'koatty_lib';
|
12
|
+
import { IAspect } from 'koatty_container';
|
12
13
|
import { Koatty } from 'koatty_core';
|
13
14
|
import { KoattyContext } from 'koatty_core';
|
14
15
|
import { Logger as Logger_2 } from 'koatty_logger';
|
15
16
|
import { Middleware as Middleware_2 } from 'koa';
|
17
|
+
import { Next } from 'koa';
|
16
18
|
import { Value } from 'koatty_config';
|
17
19
|
|
18
20
|
/**
|
@@ -37,6 +39,7 @@ export declare interface ApiOutput {
|
|
37
39
|
* Base controller
|
38
40
|
*
|
39
41
|
* @export
|
42
|
+
* @deprecated When the framework version is > 3.10.5, do not need to inherit the Base class.
|
40
43
|
* @class BaseController
|
41
44
|
* @implements {IController}
|
42
45
|
*/
|
@@ -58,6 +61,7 @@ export declare class BaseController implements IController {
|
|
58
61
|
/**
|
59
62
|
* Response to normalize json format content for success
|
60
63
|
*
|
64
|
+
* @deprecated 使用 Output.ok 代替
|
61
65
|
* @param {(string | ApiInput)} msg 待处理的message消息
|
62
66
|
* @param {*} [data] 待处理的数据
|
63
67
|
* @param {number} [code=200] 错误码,默认0
|
@@ -68,6 +72,7 @@ export declare class BaseController implements IController {
|
|
68
72
|
/**
|
69
73
|
* Response to normalize json format content for fail
|
70
74
|
*
|
75
|
+
* @deprecated 使用 Output.fail 代替
|
71
76
|
* @param {(string | ApiInput)} msg
|
72
77
|
* @param {*} [data]
|
73
78
|
* @param {number} [code=1]
|
@@ -81,6 +86,7 @@ export declare class BaseController implements IController {
|
|
81
86
|
* Base service
|
82
87
|
*
|
83
88
|
* @export
|
89
|
+
* @deprecated When the framework version is > 3.10.5, do not need to inherit the Base class.
|
84
90
|
* @class Base
|
85
91
|
*/
|
86
92
|
export declare class BaseService implements IService {
|
@@ -182,18 +188,50 @@ export { Helper }
|
|
182
188
|
export declare interface IController {
|
183
189
|
readonly app: Koatty;
|
184
190
|
readonly ctx: KoattyContext;
|
185
|
-
init(...arg: any[]): void;
|
186
|
-
ok(msg: string | ApiInput, data?: any, code?: number): Promise<ApiOutput>;
|
187
|
-
fail(msg: Error | string | ApiInput, data?: any, code?: number): void;
|
188
191
|
}
|
189
192
|
|
190
193
|
/**
|
191
194
|
* Interface for Middleware
|
192
195
|
*/
|
193
196
|
export declare interface IMiddleware {
|
194
|
-
run: (options: any, app: Koatty) =>
|
197
|
+
run: (options: any, app: Koatty) => (ctx: KoattyContext, next: Next) => Promise<any>;
|
195
198
|
}
|
196
199
|
|
200
|
+
/**
|
201
|
+
* check is implements Aspect Interface
|
202
|
+
* @param cls
|
203
|
+
* @returns
|
204
|
+
*/
|
205
|
+
export declare function implementsAspectInterface(cls: any): cls is IAspect;
|
206
|
+
|
207
|
+
/**
|
208
|
+
* check is implements Controller Interface
|
209
|
+
* @param cls
|
210
|
+
* @returns
|
211
|
+
*/
|
212
|
+
export declare function implementsControllerInterface(cls: any): cls is IController;
|
213
|
+
|
214
|
+
/**
|
215
|
+
* check is implements Middleware Interface
|
216
|
+
* @param cls
|
217
|
+
* @returns
|
218
|
+
*/
|
219
|
+
export declare function implementsMiddlewareInterface(cls: any): cls is IMiddleware;
|
220
|
+
|
221
|
+
/**
|
222
|
+
* check is implements Plugin Interface
|
223
|
+
* @param cls
|
224
|
+
* @returns
|
225
|
+
*/
|
226
|
+
export declare function implementsPluginInterface(cls: any): cls is IPlugin;
|
227
|
+
|
228
|
+
/**
|
229
|
+
* check is implements Service Interface
|
230
|
+
* @param cls
|
231
|
+
* @returns
|
232
|
+
*/
|
233
|
+
export declare function implementsServiceInterface(cls: any): cls is IService;
|
234
|
+
|
197
235
|
/**
|
198
236
|
* Interface for Plugin
|
199
237
|
*/
|
@@ -206,7 +244,6 @@ export declare interface IPlugin {
|
|
206
244
|
*/
|
207
245
|
export declare interface IService {
|
208
246
|
readonly app: Koatty;
|
209
|
-
init(...arg: any[]): void;
|
210
247
|
}
|
211
248
|
|
212
249
|
/**
|
@@ -226,6 +263,31 @@ export declare const Logger: Logger_2;
|
|
226
263
|
*/
|
227
264
|
export declare function Middleware(identifier?: string): ClassDecorator;
|
228
265
|
|
266
|
+
export declare class Output {
|
267
|
+
/**
|
268
|
+
* Response to normalize json format content for success
|
269
|
+
*
|
270
|
+
* @param {KoattyContext} ctx
|
271
|
+
* @param {(string | ApiInput)} msg 待处理的message消息
|
272
|
+
* @param {*} [data] 待处理的数据
|
273
|
+
* @param {number} [code=200] 错误码,默认0
|
274
|
+
* @returns {*}
|
275
|
+
* @memberof BaseController
|
276
|
+
*/
|
277
|
+
static ok(ctx: KoattyContext, msg: string | ApiInput, data?: any, code?: number): Promise<ApiOutput>;
|
278
|
+
/**
|
279
|
+
* Response to normalize json format content for fail
|
280
|
+
*
|
281
|
+
* @param {KoattyContext} ctx
|
282
|
+
* @param {(string | ApiInput)} msg
|
283
|
+
* @param {*} [data]
|
284
|
+
* @param {number} [code=1]
|
285
|
+
* @returns {*}
|
286
|
+
* @memberof BaseController
|
287
|
+
*/
|
288
|
+
static fail(ctx: KoattyContext, msg: Error | string | ApiInput, data?: any, code?: number): void;
|
289
|
+
}
|
290
|
+
|
229
291
|
/**
|
230
292
|
* Indicates that an decorated class is a "plugin".
|
231
293
|
*
|