tspace-spear 1.0.0 → 1.0.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/License +1 -1
- package/README.md +364 -47
- package/build/lib/core/decorators/context.js +11 -10
- package/build/lib/core/decorators/context.js.map +1 -0
- package/build/lib/core/decorators/controller.js +1 -0
- package/build/lib/core/decorators/controller.js.map +1 -0
- package/build/lib/core/decorators/headers.js +1 -0
- package/build/lib/core/decorators/headers.js.map +1 -0
- package/build/lib/core/decorators/index.d.ts +1 -0
- package/build/lib/core/decorators/index.js +2 -0
- package/build/lib/core/decorators/index.js.map +1 -0
- package/build/lib/core/decorators/methods.js +1 -0
- package/build/lib/core/decorators/methods.js.map +1 -0
- package/build/lib/core/decorators/middleware.d.ts +1 -1
- package/build/lib/core/decorators/middleware.js +1 -0
- package/build/lib/core/decorators/middleware.js.map +1 -0
- package/build/lib/core/decorators/statusCode.js +1 -0
- package/build/lib/core/decorators/statusCode.js.map +1 -0
- package/build/lib/core/decorators/swagger.d.ts +2 -0
- package/build/lib/core/decorators/swagger.js +15 -0
- package/build/lib/core/decorators/swagger.js.map +1 -0
- package/build/lib/core/server/index.d.ts +90 -44
- package/build/lib/core/server/index.js +314 -286
- package/build/lib/core/server/index.js.map +1 -0
- package/build/lib/core/server/parser-factory.d.ts +26 -0
- package/build/lib/core/server/parser-factory.js +428 -0
- package/build/lib/core/server/parser-factory.js.map +1 -0
- package/build/lib/core/server/q.bak.d.ts +0 -0
- package/build/lib/core/server/q.bak.js +965 -0
- package/build/lib/core/server/q.bak.js.map +1 -0
- package/build/lib/core/server/router.d.ts +63 -2
- package/build/lib/core/server/router.js +63 -1
- package/build/lib/core/server/router.js.map +1 -0
- package/build/lib/{types → core/types}/index.d.ts +85 -9
- package/build/lib/{types → core/types}/index.js +1 -0
- package/build/lib/core/types/index.js.map +1 -0
- package/build/lib/index.d.ts +4 -13
- package/build/lib/index.js +7 -23
- package/build/lib/index.js.map +1 -0
- package/build/tests/benchmark.test.d.ts +1 -0
- package/build/tests/benchmark.test.js +135 -0
- package/build/tests/benchmark.test.js.map +1 -0
- package/package.json +30 -19
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/middleware.ts"],"names":[],"mappings":";;;AAEO,MAAM,UAAU,GAAG,CAAC,UAA6B,EAAE,EAAE;IAE1D,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,UAA8B,EAAE,EAAE;QAClE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QACxC,UAAU,CAAC,KAAK,GAAG,UAAS,GAAc,EAAG,IAAoB;YAC/D,IAAI,CAAC;gBAEH,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,UAAU,EAAG,MAAM,CAAC,CAAA;gBAE1D,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,GAAU,EAAE,EAAE;oBACpC,IAAG,GAAG,IAAI,IAAI,EAAE,CAAC;wBACf,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;oBAClB,CAAC;oBACD,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAG,IAAI,CAAC,CAAC;gBAC/C,CAAC,CAAC,CAAA;YAEJ,CAAC;YAAC,OAAO,KAAW,EAAE,CAAC;gBAErB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAA;YACpB,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAA;AAtBY,QAAA,UAAU,cAsBtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statusCode.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/statusCode.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEO,MAAO,UAAU,GAAG,CAAC,UAAmB,EAAE,EAAE;IAC/C,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,UAA8B,EAAE,EAAE;QAChE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,GAAG,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC;QAE1E,UAAU,CAAC,KAAK,GAAG,UAAe,GAAc,EAAG,IAAmB;;gBAClE,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,EAAG,EAAE,cAAc,EAAE,kBAAkB,EAAC,CAAC,CAAA;gBACrE,OAAO,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAG,IAAI,CAAC,CAAC;YACvD,CAAC;SAAA,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC,CAAA;AAba,QAAA,UAAU,cAavB"}
|
|
@@ -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,13 +1,14 @@
|
|
|
1
|
-
import { ServerResponse } from 'http';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { Server, ServerResponse } from 'http';
|
|
2
|
+
import findMyWayRouter from 'find-my-way';
|
|
3
|
+
import { Router } from './router';
|
|
4
|
+
import type { TContext, TNextFunction, TApplication } from '../types';
|
|
4
5
|
/**
|
|
5
6
|
*
|
|
6
|
-
* The '
|
|
7
|
+
* The 'Spear' class is used to create a server and handle HTTP requests.
|
|
7
8
|
*
|
|
8
|
-
* @returns {
|
|
9
|
+
* @returns {Spear} application
|
|
9
10
|
* @example
|
|
10
|
-
* new
|
|
11
|
+
* new Spear()
|
|
11
12
|
* .get('/' , () => 'Hello world!')
|
|
12
13
|
* .get('/json' , () => {
|
|
13
14
|
* return {
|
|
@@ -17,29 +18,23 @@ import type { TContext, TNextFunction, TApplication } from "../..";
|
|
|
17
18
|
* .listen(3000 , () => console.log('server listening on port : 3000'))
|
|
18
19
|
*
|
|
19
20
|
*/
|
|
20
|
-
declare class
|
|
21
|
+
declare class Spear {
|
|
21
22
|
private readonly _controllers?;
|
|
22
23
|
private readonly _middlewares?;
|
|
23
24
|
private readonly _globalPrefix;
|
|
25
|
+
private readonly _cluster?;
|
|
24
26
|
private readonly _router;
|
|
27
|
+
private readonly _parser;
|
|
28
|
+
private _swagger;
|
|
29
|
+
private _swaggerAdditional;
|
|
25
30
|
private _errorHandler;
|
|
26
31
|
private _globalMiddlewares;
|
|
27
32
|
private _formatResponse;
|
|
28
33
|
private _onListeners;
|
|
29
34
|
private _fileUploadOptions;
|
|
30
|
-
constructor({ controllers, middlewares, globalPrefix, logger }?: TApplication);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
* @params {Object}
|
|
35
|
-
* @property {(string | RegExp)[]} origins
|
|
36
|
-
* @property {boolean} credentials
|
|
37
|
-
* @returns
|
|
38
|
-
*/
|
|
39
|
-
enableCors({ origins, credentials }?: {
|
|
40
|
-
origins?: (string | RegExp)[];
|
|
41
|
-
credentials?: boolean;
|
|
42
|
-
}): this;
|
|
35
|
+
constructor({ controllers, middlewares, globalPrefix, logger, cluster }?: TApplication);
|
|
36
|
+
get instance(): this;
|
|
37
|
+
get routers(): findMyWayRouter.Instance<findMyWayRouter.HTTPVersion.V1>;
|
|
43
38
|
/**
|
|
44
39
|
* The 'use' method is used to add the middleware into the request pipeline.
|
|
45
40
|
*
|
|
@@ -50,13 +45,17 @@ declare class Application {
|
|
|
50
45
|
*/
|
|
51
46
|
use(middleware: (ctx: TContext, next: TNextFunction) => void): this;
|
|
52
47
|
/**
|
|
53
|
-
* The '
|
|
48
|
+
* The 'useLogger' method is used to add the middleware view logger response.
|
|
54
49
|
*
|
|
55
|
-
* @
|
|
56
|
-
* @property {
|
|
50
|
+
* @callback {Function} middleware
|
|
51
|
+
* @property {Object} ctx - context { req , res , query , params , cookies , files , body}
|
|
52
|
+
* @property {Function} next - go to next function
|
|
57
53
|
* @returns {this}
|
|
58
54
|
*/
|
|
59
|
-
|
|
55
|
+
useLogger({ methods, exceptPath }?: {
|
|
56
|
+
methods?: ('GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE')[];
|
|
57
|
+
exceptPath?: string[] | RegExp;
|
|
58
|
+
}): this;
|
|
60
59
|
/**
|
|
61
60
|
* The 'useBodyParser' method is a middleware used to parse the request body of incoming HTTP requests.
|
|
62
61
|
*
|
|
@@ -69,27 +68,79 @@ declare class Application {
|
|
|
69
68
|
* @returns {this}
|
|
70
69
|
*/
|
|
71
70
|
useCookiesParser(): this;
|
|
71
|
+
/**
|
|
72
|
+
* The 'useRouter' method is used to add the router in the request context.
|
|
73
|
+
*
|
|
74
|
+
* @parms {Function} router
|
|
75
|
+
* @property {Function} router - get() , post() , put() , patch() , delete()
|
|
76
|
+
* @returns {this}
|
|
77
|
+
*/
|
|
78
|
+
useRouter(router: Router): this;
|
|
72
79
|
/**
|
|
73
80
|
* The 'useFileUpload' method is a middleware used to handler file uploads. It adds a file upload of incoming HTTP requests.
|
|
74
81
|
*
|
|
75
82
|
* @param {?Object}
|
|
76
83
|
* @property {?number} limits
|
|
77
|
-
* @property {?boolean} useTempFiles
|
|
78
84
|
* @property {?string} tempFileDir
|
|
79
85
|
* @property {?Object} removeTempFile
|
|
80
86
|
* @property {boolean} removeTempFile.remove
|
|
81
87
|
* @property {number} removeTempFile.ms
|
|
82
88
|
* @returns
|
|
83
89
|
*/
|
|
84
|
-
useFileUpload({
|
|
85
|
-
|
|
86
|
-
useTempFiles?: boolean;
|
|
90
|
+
useFileUpload({ limit, tempFileDir, removeTempFile }?: {
|
|
91
|
+
limit?: number;
|
|
87
92
|
tempFileDir?: string;
|
|
88
93
|
removeTempFile?: {
|
|
89
94
|
remove: boolean;
|
|
90
95
|
ms: number;
|
|
91
96
|
};
|
|
92
97
|
}): this;
|
|
98
|
+
/**
|
|
99
|
+
* The 'useSwagger' method is a middleware used to create swagger api.
|
|
100
|
+
*
|
|
101
|
+
* @param {?Object}
|
|
102
|
+
* @property {?string} path
|
|
103
|
+
* @property {?array} servers
|
|
104
|
+
* @property {?object} info
|
|
105
|
+
* @property {?array} tags
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
useSwagger({ path, servers, info, tags }?: {
|
|
109
|
+
path?: `/${string}`;
|
|
110
|
+
servers?: {
|
|
111
|
+
url: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
}[];
|
|
114
|
+
tags?: string[];
|
|
115
|
+
info?: {
|
|
116
|
+
title?: string;
|
|
117
|
+
description?: string;
|
|
118
|
+
version?: string;
|
|
119
|
+
};
|
|
120
|
+
}): this;
|
|
121
|
+
/**
|
|
122
|
+
* The 'listen' method is used to bind and start a server to a particular port and optionally a hostname.
|
|
123
|
+
*
|
|
124
|
+
* @param {number} port
|
|
125
|
+
* @param {function} callback
|
|
126
|
+
* @returns
|
|
127
|
+
*/
|
|
128
|
+
listen(port: (number | (() => ServerResponse)) | undefined, callback: (callback: {
|
|
129
|
+
server: Server;
|
|
130
|
+
port: number;
|
|
131
|
+
}) => void): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* The 'enableCors' is used to enable the cors origins on the server.
|
|
134
|
+
*
|
|
135
|
+
* @params {Object}
|
|
136
|
+
* @property {(string | RegExp)[]} origins
|
|
137
|
+
* @property {boolean} credentials
|
|
138
|
+
* @returns
|
|
139
|
+
*/
|
|
140
|
+
enableCors({ origins, credentials }?: {
|
|
141
|
+
origins?: (string | RegExp)[];
|
|
142
|
+
credentials?: boolean;
|
|
143
|
+
}): this;
|
|
93
144
|
/**
|
|
94
145
|
* The 'formatResponse' method is used to format the response
|
|
95
146
|
*
|
|
@@ -98,7 +149,9 @@ declare class Application {
|
|
|
98
149
|
*/
|
|
99
150
|
formatResponse(format: (r: unknown, statusCode: number) => any): this;
|
|
100
151
|
/**
|
|
101
|
-
* The 'errorHandler' method is middleware that is specifically designed to handle errors
|
|
152
|
+
* The 'errorHandler' method is middleware that is specifically designed to handle errors.
|
|
153
|
+
*
|
|
154
|
+
* that occur during the processing of requests
|
|
102
155
|
*
|
|
103
156
|
* @param {function} error
|
|
104
157
|
* @returns
|
|
@@ -162,7 +215,7 @@ declare class Application {
|
|
|
162
215
|
*/
|
|
163
216
|
delete(path: string, ...handlers: ((ctx: TContext, next: TNextFunction) => any)[]): this;
|
|
164
217
|
/**
|
|
165
|
-
* The 'all' method is used to add the request handler to the router for
|
|
218
|
+
* The 'all' method is used to add the request handler to the router for 'GET' 'POST' 'PUT' 'PATCH' 'DELETE' methods.
|
|
166
219
|
*
|
|
167
220
|
* @param {string} path
|
|
168
221
|
* @callback {...Function[]} handlers of the middlewares
|
|
@@ -171,26 +224,19 @@ declare class Application {
|
|
|
171
224
|
* @returns {this}
|
|
172
225
|
*/
|
|
173
226
|
all(path: string, ...handlers: ((ctx: TContext, next: TNextFunction) => any)[]): this;
|
|
174
|
-
|
|
175
|
-
* The 'listen' method is used to bind and start a server to a particular port and optionally a hostname.
|
|
176
|
-
*
|
|
177
|
-
* @param {number} port
|
|
178
|
-
* @param {function} cb
|
|
179
|
-
* @returns
|
|
180
|
-
*/
|
|
181
|
-
listen(port: number | (() => ServerResponse) | undefined, cb: () => void): Promise<void>;
|
|
182
|
-
private _logger;
|
|
227
|
+
private _clusterMode;
|
|
183
228
|
private _import;
|
|
184
229
|
private _registerControllers;
|
|
185
230
|
private _registerMiddlewares;
|
|
186
|
-
private _filesParser;
|
|
187
|
-
private _bodyParser;
|
|
188
|
-
private _cookiesParser;
|
|
189
231
|
private _customizeResponse;
|
|
190
232
|
private _nextFunction;
|
|
191
233
|
private _wrapHandlers;
|
|
192
234
|
private _wrapResponse;
|
|
193
235
|
private _createServer;
|
|
236
|
+
private _normalizePath;
|
|
237
|
+
private _swaggerHandler;
|
|
238
|
+
}
|
|
239
|
+
export declare class Application extends Spear {
|
|
194
240
|
}
|
|
195
|
-
export {
|
|
196
|
-
export default
|
|
241
|
+
export { Spear };
|
|
242
|
+
export default Spear;
|