koatty 3.11.4-2 → 3.11.6

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/README.md CHANGED
@@ -1,168 +1,177 @@
1
- # koatty
2
-
3
- Koa2 + Typescript + IOC = koatty.
4
-
5
- Use Typescript's decorator implement IOC and AOP.
6
-
7
- [![Version npm](https://img.shields.io/npm/v/koatty.svg?style=flat-square)](https://www.npmjs.com/package/koatty)[![npm Downloads](https://img.shields.io/npm/dm/koatty.svg?style=flat-square)](https://npmcharts.com/compare/koatty?minimal=true)
8
-
9
- ## New features
10
-
11
- * HTTP、HTTPS、HTTP2、gRPC、WebSocket server.
12
- * Support loading environment configuration, parsing command line parameters (process.argv) and environment variables (process.env)
13
- * `@ExceptionHandler()` Register global exception handling
14
- * graceful shutdown and pre-exit event
15
- * custom decorator based on app events
16
-
17
-
18
- ## Documentation
19
-
20
- [koatty_doc_CN](https://koatty.org/) (In progress💪)
21
-
22
-
23
- ## Installation CLI tools
24
-
25
- ```shell
26
- npm i -g koatty_cli
27
- ```
28
-
29
- ## Quick Start
30
-
31
- ### 1.Create Project
32
-
33
- ```shell
34
- kt new projectName
35
-
36
- ```
37
-
38
- ### 2. Install deps
39
-
40
- ```
41
- cd ./projectName
42
-
43
- npm i
44
- ```
45
-
46
- ### 3. Start up
47
-
48
- ```
49
- npm run dev
50
-
51
- // or
52
- npm start
53
- ```
54
-
55
- ## Code style
56
-
57
- default Controller:
58
-
59
- ```javascript
60
- import { Controller, Autowired, GetMapping, RequestBody, PathVariable,
61
- PostMapping, RequestMapping, RequestMethod, Valid, Output } from "koatty";
62
- import { TestDTO } from "../model/dto/TestDTO";
63
- import { TestService } from "../service/TestService";
64
- import { App } from "../App";
65
-
66
- @Controller()
67
- export class IndexController {
68
- app: App;
69
- ctx: KoattyContext;
70
-
71
- @Autowired()
72
- private testService: TestService;
73
-
74
- /**
75
- * constructor
76
- *
77
- */
78
- constructor(ctx: KoattyContext) {
79
- this.ctx = ctx;
80
- }
81
-
82
- @RequestMapping("/:name", RequestMethod.ALL)
83
- async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
84
- try {
85
- const info = await this.testService.sayHello(name);
86
- return Output.ok(this.ctx, "success", info);
87
- } catch (err: Error) {
88
- return Output.fail(this.ctx, err.message));
89
- }
90
- }
91
-
92
- @PostMapping("/test")
93
- @Validated() //need DTOClass
94
- test(@RequestParam() params: TestDTO) {
95
- return Output.ok(this.ctx, "test", params);
96
- }
97
- }
98
- ```
99
-
100
- ## How to do Unit Testing
101
-
102
- >only support `jest` UT framework now
103
-
104
- ```javascript
105
- import request from 'supertest';
106
- import { ExecBootStrap } from 'koatty';
107
- import { App } from '../src/App';
108
-
109
- describe('UT example', () => {
110
-
111
- let server: any;
112
- beforeAll(async () => {
113
- jest.useFakeTimers();
114
- const appInstance = await ExecBootStrap()(App);
115
- server = await appInstance.listen();
116
- });
117
-
118
- afterAll(done => {
119
- server.close();
120
- done();
121
- });
122
-
123
- it('request', async () => {
124
- const rsp = await request(server).get('/');
125
- expect(rsp.status).toBe(200);
126
- });
127
- });
128
-
129
- ```
130
-
131
- ## How to debug
132
-
133
- if you use vscode , edit the `.vscode/launch.json` , like this:
134
- ```
135
- {
136
- "version": "0.2.0",
137
- "configurations": [
138
- {
139
- "type": "node",
140
- "request": "launch",
141
- "name": "TS Program",
142
- "args": [
143
- "${workspaceRoot}/src/App.ts"
144
- ],
145
- "runtimeArgs": [
146
- "--nolazy",
147
- "-r",
148
- "ts-node/register"
149
- ],
150
- "sourceMaps": true,
151
- "cwd": "${workspaceRoot}",
152
- "protocol": "inspector",
153
- "outputCapture": "std",
154
- "internalConsoleOptions": "neverOpen"
155
- }
156
- ]
157
- }
158
- ```
159
- Select `TS Program` to debug run. Try to call `http://localhost:3000/` .
160
-
161
- ## Example
162
-
163
- Check out the [quick start example][quick-example].
164
-
165
- [quick-example]: https://github.com/Koatty/koatty_template
166
-
167
-
168
-
1
+ # koatty
2
+
3
+ Koa2 + Typescript + IOC = koatty.
4
+
5
+ Use Typescript's decorator implement IOC and AOP.
6
+
7
+ [![Version npm](https://img.shields.io/npm/v/koatty.svg?style=flat-square)](https://www.npmjs.com/package/koatty)[![npm Downloads](https://img.shields.io/npm/dm/koatty.svg?style=flat-square)](https://npmcharts.com/compare/koatty?minimal=true)
8
+
9
+ ## New features
10
+
11
+ * HTTP、HTTPS、HTTP2、gRPC、WebSocket server.
12
+ * Support loading environment configuration, parsing command line parameters (process.argv) and environment variables (process.env)
13
+ * `@ExceptionHandler()` Register global exception handling
14
+ * graceful shutdown and pre-exit event
15
+ * custom decorator based on app events
16
+
17
+
18
+ ## Documentation
19
+
20
+ [koatty_doc_CN](https://koatty.org/) (In progress💪)
21
+
22
+
23
+ ## Installation CLI tools
24
+
25
+ ```shell
26
+ npm i -g koatty_cli
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ### 1.Create Project
32
+
33
+ ```shell
34
+ kt new projectName
35
+
36
+ ```
37
+
38
+ ### 2. Install deps
39
+
40
+ ```
41
+ cd ./projectName
42
+
43
+ npm i
44
+ ```
45
+
46
+ ### 3. Start up
47
+
48
+ ```
49
+ npm run dev
50
+
51
+ // or
52
+ npm start
53
+ ```
54
+
55
+ ## Code style
56
+
57
+ default Controller:
58
+
59
+ ```javascript
60
+ import { Controller, Autowired, GetMapping, RequestBody, PathVariable,
61
+ PostMapping, RequestMapping, RequestMethod, Valid, Output } from "koatty";
62
+ import { TestDTO } from "../model/dto/TestDTO";
63
+ import { TestService } from "../service/TestService";
64
+ import { App } from "../App";
65
+
66
+ @Controller()
67
+ export class IndexController {
68
+ app: App;
69
+ ctx: KoattyContext;
70
+
71
+ @Autowired()
72
+ private testService: TestService;
73
+
74
+ /**
75
+ * constructor
76
+ *
77
+ */
78
+ constructor(ctx: KoattyContext) {
79
+ this.ctx = ctx;
80
+ }
81
+
82
+ @GetMapping('/')
83
+ index() {
84
+ return Output.ok("Hello, koatty!");
85
+ }
86
+
87
+ @RequestMapping("/:name", RequestMethod.ALL)
88
+ async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
89
+ try {
90
+ const info = await this.testService.sayHello(name);
91
+ return Output.ok(this.ctx, "success", info);
92
+ } catch (err: Error) {
93
+ return Output.fail(this.ctx, err.message));
94
+ }
95
+ }
96
+
97
+ @PostMapping("/test")
98
+ @Validated() //need DTOClass
99
+ test(@RequestParam() params: TestDTO) {
100
+ return Output.ok(this.ctx, "test", params);
101
+ }
102
+ }
103
+ ```
104
+
105
+ ## How to do Unit Testing
106
+
107
+ >only support `jest` UT framework now
108
+
109
+ ```javascript
110
+ import request from 'supertest';
111
+ import { ExecBootStrap } from 'koatty';
112
+ import { App } from '../src/App';
113
+
114
+ describe('UT example', () => {
115
+
116
+ let app: KoattyApplication;
117
+ beforeAll(async () => {
118
+ jest.useFakeTimers();
119
+ // test env
120
+ process.env.KOATTY_ENV = 'ts-node';
121
+ app = await ExecBootStrap()(App);
122
+ // app.use(async (ctx: any) => {
123
+ // ctx.body = 'Hello, World!';
124
+ // });
125
+ });
126
+
127
+ afterAll(done => {
128
+ done();
129
+ jest.clearAllMocks();
130
+ });
131
+
132
+ it('request', async () => {
133
+ const res = await request(app.callback()).get('/');
134
+ expect(res.status).toBe(200);
135
+ });
136
+ });
137
+
138
+ ```
139
+
140
+ ## How to debug
141
+
142
+ if you use vscode , edit the `.vscode/launch.json` , like this:
143
+ ```
144
+ {
145
+ "version": "0.2.0",
146
+ "configurations": [
147
+ {
148
+ "type": "node",
149
+ "request": "launch",
150
+ "name": "TS Program",
151
+ "args": [
152
+ "${workspaceRoot}/src/App.ts"
153
+ ],
154
+ "runtimeArgs": [
155
+ "--nolazy",
156
+ "-r",
157
+ "ts-node/register"
158
+ ],
159
+ "sourceMaps": true,
160
+ "cwd": "${workspaceRoot}",
161
+ "protocol": "inspector",
162
+ "outputCapture": "std",
163
+ "internalConsoleOptions": "neverOpen"
164
+ }
165
+ ]
166
+ }
167
+ ```
168
+ Select `TS Program` to debug run. Try to call `http://localhost:3000/` .
169
+
170
+ ## Example
171
+
172
+ Check out the [quick start example][quick-example].
173
+
174
+ [quick-example]: https://github.com/Koatty/koatty_template
175
+
176
+
177
+
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2024-04-15 05:09:35
3
+ * @Date: 2024-12-05 11:22:38
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -9,20 +9,15 @@ 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';
13
- import { Koatty } from 'koatty_core';
14
- import { KoattyContext } from 'koatty_core';
12
+ import { KoattyApplication } from 'koatty_core';
15
13
  import { Logger as Logger_2 } from 'koatty_logger';
16
- import { Middleware as Middleware_2 } from 'koa';
17
- import { Next } from 'koa';
18
- import { Value } from 'koatty_config';
19
14
 
20
15
  /**
21
16
  * @description: bind App event hook func
22
17
  * example:
23
18
  * export function TestDecorator(): ClassDecorator {
24
19
  * return (target: Function) => {
25
- * BindEventHook(AppEvent.appBoot, (app: Koatty) => {
20
+ * BindEventHook(AppEvent.appBoot, (app: KoattyApplication) => {
26
21
  * // todo
27
22
  * return Promise.resolve();
28
23
  * }, target)
@@ -36,7 +31,7 @@ import { Value } from 'koatty_config';
36
31
  export declare function BindEventHook(eventName: AppEvent, eventFunc: EventHookFunc, target: any): void;
37
32
 
38
33
  /**
39
- * Bootstrap application
34
+ * Bootstrap application decorator
40
35
  *
41
36
  * @export
42
37
  * @param {Function} [bootFunc]
@@ -44,15 +39,6 @@ export declare function BindEventHook(eventName: AppEvent, eventFunc: EventHookF
44
39
  */
45
40
  export declare function Bootstrap(bootFunc?: Function): ClassDecorator;
46
41
 
47
- /**
48
- * Indicates that an decorated class is a "component".
49
- *
50
- * @export
51
- * @param {string} [identifier] component name
52
- * @returns {ClassDecorator}
53
- */
54
- export declare function Component(identifier?: string): ClassDecorator;
55
-
56
42
  /**
57
43
  * Define project scan path
58
44
  *
@@ -73,15 +59,6 @@ export { Config }
73
59
  */
74
60
  export declare function ConfigurationScan(scanPath?: string | string[]): ClassDecorator;
75
61
 
76
- /**
77
- * Indicates that an decorated class is a "controller".
78
- *
79
- * @export
80
- * @param {string} [path] controller router path
81
- * @returns {ClassDecorator}
82
- */
83
- export declare function Controller(path?: string): ClassDecorator;
84
-
85
62
  /**
86
63
  * Actively perform dependency injection
87
64
  * Parse the decorator, return the instantiated app.
@@ -89,116 +66,15 @@ export declare function Controller(path?: string): ClassDecorator;
89
66
  * @param {Function} [bootFunc] callback function
90
67
  * @returns
91
68
  */
92
- export declare function ExecBootStrap(bootFunc?: Function): (target: any) => Promise<Koatty>;
69
+ export declare function ExecBootStrap(bootFunc?: Function): (target: any) => Promise<KoattyApplication>;
93
70
 
94
71
  export { Helper }
95
72
 
96
- /**
97
- * Interface for Controller
98
- */
99
- export declare interface IController {
100
- readonly app: Koatty;
101
- readonly ctx: KoattyContext;
102
- }
103
-
104
- /**
105
- * Interface for Middleware
106
- */
107
- export declare interface IMiddleware {
108
- run: (options: any, app: Koatty) => (ctx: KoattyContext, next: Next) => Promise<any>;
109
- }
110
-
111
- /**
112
- * check is implements Aspect Interface
113
- * @param cls
114
- * @returns
115
- */
116
- export declare function implementsAspectInterface(cls: any): cls is IAspect;
117
-
118
- /**
119
- * check is implements Controller Interface
120
- * @param cls
121
- * @returns
122
- */
123
- export declare function implementsControllerInterface(cls: any): cls is IController;
124
-
125
- /**
126
- * check is implements Middleware Interface
127
- * @param cls
128
- * @returns
129
- */
130
- export declare function implementsMiddlewareInterface(cls: any): cls is IMiddleware;
131
-
132
- /**
133
- * check is implements Plugin Interface
134
- * @param cls
135
- * @returns
136
- */
137
- export declare function implementsPluginInterface(cls: any): cls is IPlugin;
138
-
139
- /**
140
- * check is implements Service Interface
141
- * @param cls
142
- * @returns
143
- */
144
- export declare function implementsServiceInterface(cls: any): cls is IService;
145
-
146
- /**
147
- * Interface for Plugin
148
- */
149
- export declare interface IPlugin {
150
- run: (options: any, app: Koatty) => Promise<any>;
151
- }
152
-
153
- /**
154
- * Interface for Service
155
- */
156
- export declare interface IService {
157
- readonly app: Koatty;
158
- }
159
-
160
- /**
161
- * Interface for Middleware
162
- */
163
- export declare interface KoattyMiddleware extends Middleware_2 {
164
- }
165
-
166
73
  export declare const Logger: Logger_2;
167
74
 
168
- /**
169
- * Indicates that an decorated class is a "middleware".
170
- *
171
- * @export
172
- * @param {string} [identifier] class name
173
- * @returns {ClassDecorator}
174
- */
175
- export declare function Middleware(identifier?: string): ClassDecorator;
176
-
177
- /**
178
- * Indicates that an decorated class is a "plugin".
179
- *
180
- * @export
181
- * @param {string} [identifier] class name
182
- * @returns {ClassDecorator}
183
- */
184
- export declare function Plugin(identifier?: string): ClassDecorator;
185
-
186
- /**
187
- * Indicates that an decorated class is a "service".
188
- *
189
- * @export
190
- * @param {string} [identifier] class name
191
- * @returns {ClassDecorator}
192
- */
193
- export declare function Service(identifier?: string): ClassDecorator;
194
-
195
- export { Value }
196
-
197
75
 
198
76
  export * from "koatty_container";
199
77
  export * from "koatty_core";
200
- export * from "koatty_exception";
201
78
  export * from "koatty_router";
202
- export * from "koatty_serve";
203
79
 
204
80
  export { }