tspace-spear 1.0.0 → 1.0.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.
Files changed (40) hide show
  1. package/License +1 -1
  2. package/README.md +336 -47
  3. package/build/lib/core/decorators/context.js +10 -9
  4. package/build/lib/core/decorators/context.js.map +1 -0
  5. package/build/lib/core/decorators/controller.js +1 -0
  6. package/build/lib/core/decorators/controller.js.map +1 -0
  7. package/build/lib/core/decorators/headers.js +1 -0
  8. package/build/lib/core/decorators/headers.js.map +1 -0
  9. package/build/lib/core/decorators/index.d.ts +1 -0
  10. package/build/lib/core/decorators/index.js +2 -0
  11. package/build/lib/core/decorators/index.js.map +1 -0
  12. package/build/lib/core/decorators/methods.js +1 -0
  13. package/build/lib/core/decorators/methods.js.map +1 -0
  14. package/build/lib/core/decorators/middleware.d.ts +1 -1
  15. package/build/lib/core/decorators/middleware.js +1 -0
  16. package/build/lib/core/decorators/middleware.js.map +1 -0
  17. package/build/lib/core/decorators/statusCode.js +1 -0
  18. package/build/lib/core/decorators/statusCode.js.map +1 -0
  19. package/build/lib/core/decorators/swagger.d.ts +2 -0
  20. package/build/lib/core/decorators/swagger.js +15 -0
  21. package/build/lib/core/decorators/swagger.js.map +1 -0
  22. package/build/lib/core/server/index.d.ts +53 -24
  23. package/build/lib/core/server/index.js +165 -211
  24. package/build/lib/core/server/index.js.map +1 -0
  25. package/build/lib/core/server/parser-factory.d.ts +26 -0
  26. package/build/lib/core/server/parser-factory.js +413 -0
  27. package/build/lib/core/server/parser-factory.js.map +1 -0
  28. package/build/lib/core/server/router.d.ts +2 -2
  29. package/build/lib/core/server/router.js +1 -0
  30. package/build/lib/core/server/router.js.map +1 -0
  31. package/build/lib/{types → core/types}/index.d.ts +79 -7
  32. package/build/lib/{types → core/types}/index.js +1 -0
  33. package/build/lib/core/types/index.js.map +1 -0
  34. package/build/lib/index.d.ts +4 -13
  35. package/build/lib/index.js +7 -23
  36. package/build/lib/index.js.map +1 -0
  37. package/build/tests/benchmark.test.d.ts +1 -0
  38. package/build/tests/benchmark.test.js +135 -0
  39. package/build/tests/benchmark.test.js.map +1 -0
  40. package/package.json +22 -13
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Swagger = void 0;
4
+ const Swagger = (data) => {
5
+ return (target, propertyKey) => {
6
+ const controller = target.constructor;
7
+ const swaggers = Reflect.hasMetadata("swaggers", controller)
8
+ ? Reflect.getMetadata("swaggers", controller)
9
+ : [];
10
+ swaggers.push(Object.assign({ handler: propertyKey }, data));
11
+ Reflect.defineMetadata("swaggers", swaggers, controller);
12
+ };
13
+ };
14
+ exports.Swagger = Swagger;
15
+ //# sourceMappingURL=swagger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swagger.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/swagger.ts"],"names":[],"mappings":";;;AAEO,MAAM,OAAO,GAAG,CAAC,IAAe,EAAE,EAAE;IACvC,OAAO,CAAC,MAAW,EAAE,WAAgB,EAAE,EAAE;QACrC,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC;QAEtC,MAAM,QAAQ,GAAU,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC;YACnE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC;YAC7C,CAAC,CAAC,EAAE,CAAC;QAEL,QAAQ,CAAC,IAAI,iBACT,OAAO,EAAE,WAAW,IACjB,IAAI,EACT,CAAC;QAEH,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC3D,CAAC,CAAA;AACL,CAAC,CAAA;AAfU,QAAA,OAAO,WAejB"}
@@ -1,11 +1,11 @@
1
- import { ServerResponse } from 'http';
2
- import { Router } from '../..';
3
- import type { TContext, TNextFunction, TApplication } from "../..";
1
+ import findMyWayRouter from 'find-my-way';
2
+ import { Server, ServerResponse } from 'http';
3
+ import { Router, TContext, TNextFunction, TApplication } from '../..';
4
4
  /**
5
5
  *
6
- * The 'Application' class is used to create a server and handle HTTP requests.
6
+ * The 'Spear' class is used to create a server and handle HTTP requests.
7
7
  *
8
- * @returns {Application} application
8
+ * @returns {Spear} application
9
9
  * @example
10
10
  * new Application()
11
11
  * .get('/' , () => 'Hello world!')
@@ -17,17 +17,22 @@ import type { TContext, TNextFunction, TApplication } from "../..";
17
17
  * .listen(3000 , () => console.log('server listening on port : 3000'))
18
18
  *
19
19
  */
20
- declare class Application {
20
+ declare class Spear {
21
21
  private readonly _controllers?;
22
22
  private readonly _middlewares?;
23
23
  private readonly _globalPrefix;
24
24
  private readonly _router;
25
+ private readonly _parser;
26
+ private _swagger;
27
+ private _swaggerAdditional;
25
28
  private _errorHandler;
26
29
  private _globalMiddlewares;
27
30
  private _formatResponse;
28
31
  private _onListeners;
29
32
  private _fileUploadOptions;
30
33
  constructor({ controllers, middlewares, globalPrefix, logger }?: TApplication);
34
+ get instance(): this;
35
+ get routers(): findMyWayRouter.Instance<findMyWayRouter.HTTPVersion.V1>;
31
36
  /**
32
37
  * The 'enableCors' is used to enable the cors origins on the server.
33
38
  *
@@ -49,14 +54,6 @@ declare class Application {
49
54
  * @returns {this}
50
55
  */
51
56
  use(middleware: (ctx: TContext, next: TNextFunction) => void): this;
52
- /**
53
- * The 'useRouter' method is used to add the router in the request context.
54
- *
55
- * @parms {Function} router
56
- * @property {Function} router - get() , post() , put() , patch() , delete()
57
- * @returns {this}
58
- */
59
- useRouter(router: Router): this;
60
57
  /**
61
58
  * The 'useBodyParser' method is a middleware used to parse the request body of incoming HTTP requests.
62
59
  *
@@ -69,27 +66,56 @@ declare class Application {
69
66
  * @returns {this}
70
67
  */
71
68
  useCookiesParser(): this;
69
+ /**
70
+ * The 'useRouter' method is used to add the router in the request context.
71
+ *
72
+ * @parms {Function} router
73
+ * @property {Function} router - get() , post() , put() , patch() , delete()
74
+ * @returns {this}
75
+ */
76
+ useRouter(router: Router): this;
72
77
  /**
73
78
  * The 'useFileUpload' method is a middleware used to handler file uploads. It adds a file upload of incoming HTTP requests.
74
79
  *
75
80
  * @param {?Object}
76
81
  * @property {?number} limits
77
- * @property {?boolean} useTempFiles
78
82
  * @property {?string} tempFileDir
79
83
  * @property {?Object} removeTempFile
80
84
  * @property {boolean} removeTempFile.remove
81
85
  * @property {number} removeTempFile.ms
82
86
  * @returns
83
87
  */
84
- useFileUpload({ limits, useTempFiles, tempFileDir, removeTempFile }?: {
85
- limits?: number;
86
- useTempFiles?: boolean;
88
+ useFileUpload({ limit, tempFileDir, removeTempFile }?: {
89
+ limit?: number;
87
90
  tempFileDir?: string;
88
91
  removeTempFile?: {
89
92
  remove: boolean;
90
93
  ms: number;
91
94
  };
92
95
  }): this;
96
+ /**
97
+ * The 'useSwagger' method is a middleware used to create swagger api.
98
+ *
99
+ * @param {?Object}
100
+ * @property {?string} path
101
+ * @property {?array} servers
102
+ * @property {?object} info
103
+ * @property {?array} tags
104
+ * @returns
105
+ */
106
+ useSwagger({ path, servers, info, tags }?: {
107
+ path?: `/${string}`;
108
+ servers?: {
109
+ url: string;
110
+ description?: string;
111
+ }[];
112
+ tags?: string[];
113
+ info?: {
114
+ title?: string;
115
+ description?: string;
116
+ version?: string;
117
+ };
118
+ }): this;
93
119
  /**
94
120
  * The 'formatResponse' method is used to format the response
95
121
  *
@@ -178,19 +204,22 @@ declare class Application {
178
204
  * @param {function} cb
179
205
  * @returns
180
206
  */
181
- listen(port: number | (() => ServerResponse) | undefined, cb: () => void): Promise<void>;
207
+ listen(port: (number | (() => ServerResponse)) | undefined, cb: (callback: {
208
+ server: Server;
209
+ port: number;
210
+ }) => void): Promise<void>;
182
211
  private _logger;
183
212
  private _import;
184
213
  private _registerControllers;
185
214
  private _registerMiddlewares;
186
- private _filesParser;
187
- private _bodyParser;
188
- private _cookiesParser;
189
215
  private _customizeResponse;
190
216
  private _nextFunction;
191
217
  private _wrapHandlers;
192
218
  private _wrapResponse;
193
219
  private _createServer;
220
+ private _normalizePath;
221
+ }
222
+ export { Spear };
223
+ export declare class Application extends Spear {
194
224
  }
195
- export { Application };
196
- export default Application;
225
+ export default Spear;