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.
Files changed (129) hide show
  1. package/.commitlintrc.js +3 -0
  2. package/.eslintignore +2 -0
  3. package/.huskyrc +5 -0
  4. package/.versionrc.js +16 -0
  5. package/CHANGELOG.md +1 -38
  6. package/README.md +4 -7
  7. package/api-extractor.json +345 -0
  8. package/dist/LICENSE +29 -0
  9. package/dist/README.md +147 -0
  10. package/dist/index.d.ts +363 -19
  11. package/dist/index.js +1266 -26
  12. package/dist/index.mjs +1197 -0
  13. package/dist/package.json +99 -0
  14. package/docs/api/index.md +12 -0
  15. package/docs/api/koatty.apiinput.code.md +11 -0
  16. package/docs/api/koatty.apiinput.data.md +11 -0
  17. package/docs/api/koatty.apiinput.md +22 -0
  18. package/docs/api/koatty.apiinput.message.md +11 -0
  19. package/docs/api/koatty.apioutput.code.md +11 -0
  20. package/docs/api/koatty.apioutput.data.md +11 -0
  21. package/docs/api/koatty.apioutput.md +22 -0
  22. package/docs/api/koatty.apioutput.message.md +11 -0
  23. package/docs/api/koatty.appreadyhookfunc.md +11 -0
  24. package/docs/api/koatty.basecontroller._constructor_.md +20 -0
  25. package/docs/api/koatty.basecontroller._options.md +11 -0
  26. package/docs/api/koatty.basecontroller.app.md +11 -0
  27. package/docs/api/koatty.basecontroller.ctx.md +11 -0
  28. package/docs/api/koatty.basecontroller.fail.md +28 -0
  29. package/docs/api/koatty.basecontroller.init.md +19 -0
  30. package/docs/api/koatty.basecontroller.md +39 -0
  31. package/docs/api/koatty.basecontroller.ok.md +28 -0
  32. package/docs/api/koatty.baseservice._constructor_.md +20 -0
  33. package/docs/api/koatty.baseservice._options.md +11 -0
  34. package/docs/api/koatty.baseservice.app.md +11 -0
  35. package/docs/api/koatty.baseservice.init.md +25 -0
  36. package/docs/api/koatty.baseservice.md +36 -0
  37. package/docs/api/koatty.bindappreadyhook.md +26 -0
  38. package/docs/api/koatty.bootstrap.md +27 -0
  39. package/docs/api/koatty.component.md +27 -0
  40. package/docs/api/koatty.componentscan.md +27 -0
  41. package/docs/api/koatty.configurationscan.md +27 -0
  42. package/docs/api/koatty.controller.md +27 -0
  43. package/docs/api/koatty.httpcontroller.body.md +28 -0
  44. package/docs/api/koatty.httpcontroller.deny.md +26 -0
  45. package/docs/api/koatty.httpcontroller.expires.md +26 -0
  46. package/docs/api/koatty.httpcontroller.fail.md +28 -0
  47. package/docs/api/koatty.httpcontroller.header.md +27 -0
  48. package/docs/api/koatty.httpcontroller.isget.md +19 -0
  49. package/docs/api/koatty.httpcontroller.ismethod.md +26 -0
  50. package/docs/api/koatty.httpcontroller.ispost.md +19 -0
  51. package/docs/api/koatty.httpcontroller.json.md +26 -0
  52. package/docs/api/koatty.httpcontroller.md +35 -0
  53. package/docs/api/koatty.httpcontroller.ok.md +28 -0
  54. package/docs/api/koatty.httpcontroller.param.md +26 -0
  55. package/docs/api/koatty.httpcontroller.redirect.md +27 -0
  56. package/docs/api/koatty.httpcontroller.type.md +27 -0
  57. package/docs/api/koatty.icontroller.__after.md +11 -0
  58. package/docs/api/koatty.icontroller.__befor.md +11 -0
  59. package/docs/api/koatty.icontroller.app.md +11 -0
  60. package/docs/api/koatty.icontroller.ctx.md +11 -0
  61. package/docs/api/koatty.icontroller.fail.md +11 -0
  62. package/docs/api/koatty.icontroller.md +25 -0
  63. package/docs/api/koatty.icontroller.ok.md +11 -0
  64. package/docs/api/koatty.imiddleware.md +20 -0
  65. package/docs/api/koatty.imiddleware.run.md +11 -0
  66. package/docs/api/koatty.iplugin.md +20 -0
  67. package/docs/api/koatty.iplugin.run.md +11 -0
  68. package/docs/api/koatty.iservice.app.md +11 -0
  69. package/docs/api/koatty.iservice.md +20 -0
  70. package/docs/api/koatty.logger.md +11 -0
  71. package/docs/api/koatty.md +51 -0
  72. package/docs/api/koatty.middleware.md +27 -0
  73. package/docs/api/koatty.plugin.md +27 -0
  74. package/docs/api/koatty.service.md +27 -0
  75. package/jest.config.js +0 -2
  76. package/jest_html_reporters.html +1 -1
  77. package/package.json +37 -35
  78. package/rollup.config.js +63 -0
  79. package/scripts/copyright.js +28 -0
  80. package/scripts/postBuild.js +10 -0
  81. package/tsconfig.json +4 -2
  82. package/babel.config.js +0 -21
  83. package/commitlint.config.js +0 -14
  84. package/dist/config/config.d.ts +0 -18
  85. package/dist/config/config.js +0 -25
  86. package/dist/config/config.js.map +0 -1
  87. package/dist/config/middleware.d.ts +0 -28
  88. package/dist/config/middleware.js +0 -32
  89. package/dist/config/middleware.js.map +0 -1
  90. package/dist/config/plugin.d.ts +0 -11
  91. package/dist/config/plugin.js +0 -15
  92. package/dist/config/plugin.js.map +0 -1
  93. package/dist/config/router.d.ts +0 -8
  94. package/dist/config/router.js +0 -32
  95. package/dist/config/router.js.map +0 -1
  96. package/dist/controller/BaseController.d.ts +0 -60
  97. package/dist/controller/BaseController.js +0 -137
  98. package/dist/controller/BaseController.js.map +0 -1
  99. package/dist/controller/HttpController.d.ts +0 -131
  100. package/dist/controller/HttpController.js +0 -214
  101. package/dist/controller/HttpController.js.map +0 -1
  102. package/dist/core/Bootstrap.d.ts +0 -50
  103. package/dist/core/Bootstrap.js +0 -218
  104. package/dist/core/Bootstrap.js.map +0 -1
  105. package/dist/core/Component.d.ts +0 -94
  106. package/dist/core/Component.js +0 -89
  107. package/dist/core/Component.js.map +0 -1
  108. package/dist/core/Constants.d.ts +0 -11
  109. package/dist/core/Constants.js +0 -24
  110. package/dist/core/Constants.js.map +0 -1
  111. package/dist/core/Loader.d.ts +0 -110
  112. package/dist/core/Loader.js +0 -394
  113. package/dist/core/Loader.js.map +0 -1
  114. package/dist/index.js.map +0 -1
  115. package/dist/middleware/PayloadMiddleware.d.ts +0 -11
  116. package/dist/middleware/PayloadMiddleware.js +0 -22
  117. package/dist/middleware/PayloadMiddleware.js.map +0 -1
  118. package/dist/middleware/TraceMiddleware.d.ts +0 -11
  119. package/dist/middleware/TraceMiddleware.js +0 -22
  120. package/dist/middleware/TraceMiddleware.js.map +0 -1
  121. package/dist/service/BaseService.d.ts +0 -33
  122. package/dist/service/BaseService.js +0 -32
  123. package/dist/service/BaseService.js.map +0 -1
  124. package/dist/util/Helper.d.ts +0 -25
  125. package/dist/util/Helper.js +0 -117
  126. package/dist/util/Helper.js.map +0 -1
  127. package/dist/util/Logger.d.ts +0 -27
  128. package/dist/util/Logger.js +0 -41
  129. package/dist/util/Logger.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,19 +1,363 @@
1
- /**
2
- * @ author: richen
3
- * @ copyright: Copyright (c) - <richenlin(at)gmail.com>
4
- * @ license: BSD (3-Clause)
5
- * @ version: 2020-05-18 10:43:05
6
- */
7
- export * from "./controller/BaseController";
8
- export * from "./controller/HttpController";
9
- export * from "./core/Bootstrap";
10
- export * from "./core/Component";
11
- export * from "./service/BaseService";
12
- export * from "koatty_core";
13
- export * from "koatty_container";
14
- export * from "koatty_exception";
15
- export * from "koatty_router";
16
- export * from "koatty_serve";
17
- export * from "koatty_trace";
18
- export { Helper } from "./util/Helper";
19
- export { Logger } from "./util/Logger";
1
+ /*!
2
+ * @Author: richen
3
+ * @Date: 2021-12-21 12:22:04
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 { }