tspace-spear 1.2.2 → 1.2.4
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/README.md +304 -23
- package/dist/lib/core/const/index.d.ts +153 -0
- package/dist/lib/core/const/index.js +105 -0
- package/dist/lib/core/const/index.js.map +1 -0
- package/dist/lib/core/decorators/context.d.ts +16 -9
- package/dist/lib/core/decorators/context.js +85 -59
- package/dist/lib/core/decorators/context.js.map +1 -1
- package/dist/lib/core/decorators/headers.d.ts +2 -2
- package/dist/lib/core/decorators/headers.js +1 -1
- package/dist/lib/core/decorators/headers.js.map +1 -1
- package/dist/lib/core/decorators/methods.d.ts +7 -7
- package/dist/lib/core/decorators/methods.js.map +1 -1
- package/dist/lib/core/decorators/middleware.d.ts +3 -3
- package/dist/lib/core/decorators/middleware.js +2 -2
- package/dist/lib/core/decorators/middleware.js.map +1 -1
- package/dist/lib/core/decorators/statusCode.d.ts +1 -1
- package/dist/lib/core/decorators/statusCode.js.map +1 -1
- package/dist/lib/core/decorators/swagger.d.ts +1 -1
- package/dist/lib/core/decorators/swagger.js.map +1 -1
- package/dist/lib/core/server/express.d.ts +295 -0
- package/dist/lib/core/server/express.js +1356 -0
- package/dist/lib/core/server/express.js.map +1 -0
- package/dist/lib/core/server/fast-router.d.ts +133 -0
- package/dist/lib/core/server/fast-router.js +277 -0
- package/dist/lib/core/server/fast-router.js.map +1 -0
- package/dist/lib/core/server/index.d.ts +43 -36
- package/dist/lib/core/server/index.js +300 -426
- package/dist/lib/core/server/index.js.map +1 -1
- package/dist/lib/core/server/net/index.d.ts +20 -0
- package/dist/lib/core/server/net/index.js +393 -0
- package/dist/lib/core/server/net/index.js.map +1 -0
- package/dist/lib/core/server/parser-factory.d.ts +20 -12
- package/dist/lib/core/server/parser-factory.js +283 -196
- package/dist/lib/core/server/parser-factory.js.map +1 -1
- package/dist/lib/core/server/request.d.ts +2 -0
- package/dist/lib/core/server/request.js +7 -0
- package/dist/lib/core/server/request.js.map +1 -0
- package/dist/lib/core/server/response.d.ts +6 -0
- package/dist/lib/core/server/response.js +168 -0
- package/dist/lib/core/server/response.js.map +1 -0
- package/dist/lib/core/server/router.d.ts +2 -2
- package/dist/lib/core/server/router.js +2 -1
- package/dist/lib/core/server/router.js.map +1 -1
- package/dist/lib/core/server/uWS/index.d.ts +30 -0
- package/dist/lib/core/server/uWS/index.js +357 -0
- package/dist/lib/core/server/uWS/index.js.map +1 -0
- package/dist/lib/core/types/index.d.ts +159 -38
- package/dist/lib/core/utils/index.d.ts +12 -0
- package/dist/lib/core/utils/index.js +137 -0
- package/dist/lib/core/utils/index.js.map +1 -0
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +3 -2
- package/dist/lib/index.js.map +1 -1
- package/package.json +27 -11
- package/dist/tests/benchmark.test.d.ts +0 -1
- package/dist/tests/benchmark.test.js +0 -145
- package/dist/tests/benchmark.test.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Server } from 'http';
|
|
2
|
-
import findMyWayRouter, { type Instance } from 'find-my-way';
|
|
3
2
|
import WebSocket from 'ws';
|
|
3
|
+
import { FastRouter } from './fast-router';
|
|
4
4
|
import { Router } from './router';
|
|
5
5
|
import type { T } from '../types';
|
|
6
6
|
/**
|
|
@@ -22,22 +22,21 @@ import type { T } from '../types';
|
|
|
22
22
|
declare class Spear {
|
|
23
23
|
private readonly _controllers?;
|
|
24
24
|
private readonly _middlewares?;
|
|
25
|
-
private readonly _globalPrefix;
|
|
26
25
|
private readonly _router;
|
|
27
26
|
private readonly _parser;
|
|
27
|
+
private _globalPrefix;
|
|
28
|
+
private _adapter;
|
|
28
29
|
private _cluster?;
|
|
29
30
|
private _cors?;
|
|
30
31
|
private _swagger;
|
|
31
32
|
private _swaggerSpecs;
|
|
32
|
-
private
|
|
33
|
-
private _ws?;
|
|
34
|
-
private _wsOptions?;
|
|
33
|
+
private _ws;
|
|
35
34
|
private _errorHandler;
|
|
36
35
|
private _globalMiddlewares;
|
|
37
36
|
private _formatResponse;
|
|
38
37
|
private _onListeners;
|
|
39
38
|
private _fileUploadOptions;
|
|
40
|
-
constructor({ controllers, middlewares, globalPrefix, logger, cluster }?: T.Application);
|
|
39
|
+
constructor({ controllers, middlewares, globalPrefix, logger, cluster, adapter }?: T.Application);
|
|
41
40
|
/**
|
|
42
41
|
* The get 'instance' method is used to get the instance of Spear.
|
|
43
42
|
*
|
|
@@ -47,9 +46,9 @@ declare class Spear {
|
|
|
47
46
|
/**
|
|
48
47
|
* The get 'routers' method is used get the all routers.
|
|
49
48
|
*
|
|
50
|
-
* @returns {
|
|
49
|
+
* @returns {FastRouter}
|
|
51
50
|
*/
|
|
52
|
-
get routers():
|
|
51
|
+
get routers(): FastRouter;
|
|
53
52
|
/**
|
|
54
53
|
* The 'ws' method is used to creates the WebSocket server.
|
|
55
54
|
*
|
|
@@ -66,7 +65,25 @@ declare class Spear {
|
|
|
66
65
|
* @property {Function} next - go to next function
|
|
67
66
|
* @returns {this}
|
|
68
67
|
*/
|
|
69
|
-
use(middleware:
|
|
68
|
+
use(middleware: T.ContextHandler): this;
|
|
69
|
+
/**
|
|
70
|
+
* The 'useGlobalPrefix' method is used to sets a global prefix for all routes in the router.
|
|
71
|
+
*
|
|
72
|
+
* If `globalPrefix` is `null` or `undefined`, it will default to an empty string,
|
|
73
|
+
* meaning no prefix will be applied.
|
|
74
|
+
*
|
|
75
|
+
* @param {string | null} globalPrefix - The base path prefix to apply to all routes.
|
|
76
|
+
* @returns {this} Returns the current instance for method chaining.
|
|
77
|
+
*/
|
|
78
|
+
useGlobalPrefix(globalPrefix: string | null): this;
|
|
79
|
+
/**
|
|
80
|
+
* The 'useAdater' method is used to switch between different server implementations,
|
|
81
|
+
* such as the native Node.js HTTP server or uWebSockets.js (uWS).
|
|
82
|
+
*
|
|
83
|
+
* @param {T.AdapterServer} adapter - The adapter instance (e.g., HTTP or uWS).
|
|
84
|
+
* @returns {this} Returns the current instance for chaining
|
|
85
|
+
*/
|
|
86
|
+
useAdater(adapter: T.AdapterServer): this;
|
|
70
87
|
/**
|
|
71
88
|
* The 'useCluster' method is used cluster run the server
|
|
72
89
|
*
|
|
@@ -99,11 +116,11 @@ declare class Spear {
|
|
|
99
116
|
* The 'useFileUpload' method is a middleware used to handler file uploads. It adds a file upload of incoming HTTP requests.
|
|
100
117
|
*
|
|
101
118
|
* @param {?Object}
|
|
102
|
-
* @property {?number} limits
|
|
119
|
+
* @property {?number} limits // bytes. default Infinity
|
|
103
120
|
* @property {?string} tempFileDir
|
|
104
121
|
* @property {?Object} removeTempFile
|
|
105
122
|
* @property {boolean} removeTempFile.remove
|
|
106
|
-
* @property {number}
|
|
123
|
+
* @property {number} removeTempFile.ms
|
|
107
124
|
* @returns
|
|
108
125
|
*/
|
|
109
126
|
useFileUpload({ limit, tempFileDir, removeTempFile }?: {
|
|
@@ -167,7 +184,7 @@ declare class Spear {
|
|
|
167
184
|
* @param {function} format
|
|
168
185
|
* @returns
|
|
169
186
|
*/
|
|
170
|
-
response(format: (r: unknown, statusCode: number) => any): this;
|
|
187
|
+
response(format: (r: unknown, statusCode: number) => Record<string, any> | string): this;
|
|
171
188
|
/**
|
|
172
189
|
* The 'catch' method is middleware that is specifically designed to handle errors.
|
|
173
190
|
*
|
|
@@ -176,14 +193,14 @@ declare class Spear {
|
|
|
176
193
|
* @param {function} error
|
|
177
194
|
* @returns
|
|
178
195
|
*/
|
|
179
|
-
catch(error: (err: any, ctx: T.Context) =>
|
|
196
|
+
catch(error: (err: any, ctx: T.Context) => T.Response): this;
|
|
180
197
|
/**
|
|
181
198
|
* The 'notfound' method is middleware that is specifically designed to handle errors notfound that occur during the processing of requests
|
|
182
199
|
*
|
|
183
200
|
* @param {function} fn
|
|
184
201
|
* @returns
|
|
185
202
|
*/
|
|
186
|
-
notfound(fn: (ctx: T.Context) =>
|
|
203
|
+
notfound(fn: (ctx: T.Context) => T.Response): this;
|
|
187
204
|
/**
|
|
188
205
|
* The 'get' method is used to add the request handler to the router for the 'GET' method.
|
|
189
206
|
*
|
|
@@ -193,7 +210,7 @@ declare class Spear {
|
|
|
193
210
|
* @property {Function} next - go to next function
|
|
194
211
|
* @returns {this}
|
|
195
212
|
*/
|
|
196
|
-
get(path: string, ...handlers:
|
|
213
|
+
get(path: string, ...handlers: T.ContextHandler[]): this;
|
|
197
214
|
/**
|
|
198
215
|
* The 'post' method is used to add the request handler to the router for the 'POST' method.
|
|
199
216
|
*
|
|
@@ -203,7 +220,7 @@ declare class Spear {
|
|
|
203
220
|
* @property {Function} next - go to next function
|
|
204
221
|
* @returns {this}
|
|
205
222
|
*/
|
|
206
|
-
post(path: string, ...handlers:
|
|
223
|
+
post(path: string, ...handlers: T.ContextHandler[]): this;
|
|
207
224
|
/**
|
|
208
225
|
* The 'put' method is used to add the request handler to the router for the 'PUT' method.
|
|
209
226
|
*
|
|
@@ -213,7 +230,7 @@ declare class Spear {
|
|
|
213
230
|
* @property {Function} next - go to next function
|
|
214
231
|
* @returns {this}
|
|
215
232
|
*/
|
|
216
|
-
put(path: string, ...handlers:
|
|
233
|
+
put(path: string, ...handlers: T.ContextHandler[]): this;
|
|
217
234
|
/**
|
|
218
235
|
* The 'patch' method is used to add the request handler to the router for the 'PATCH' method.
|
|
219
236
|
*
|
|
@@ -223,7 +240,7 @@ declare class Spear {
|
|
|
223
240
|
* @property {Function} next - go to next function
|
|
224
241
|
* @returns {this}
|
|
225
242
|
*/
|
|
226
|
-
patch(path: string, ...handlers:
|
|
243
|
+
patch(path: string, ...handlers: T.ContextHandler[]): this;
|
|
227
244
|
/**
|
|
228
245
|
* The 'delete' method is used to add the request handler to the router for the 'DELETE' method.
|
|
229
246
|
*
|
|
@@ -233,7 +250,7 @@ declare class Spear {
|
|
|
233
250
|
* @property {Function} next - go to next function
|
|
234
251
|
* @returns {this}
|
|
235
252
|
*/
|
|
236
|
-
delete(path: string, ...handlers:
|
|
253
|
+
delete(path: string, ...handlers: T.ContextHandler[]): this;
|
|
237
254
|
/**
|
|
238
255
|
* The 'head' method is used to add the request handler to the router for 'HEAD' methods.
|
|
239
256
|
*
|
|
@@ -243,7 +260,7 @@ declare class Spear {
|
|
|
243
260
|
* @property {function} next - go to next function
|
|
244
261
|
* @returns {this}
|
|
245
262
|
*/
|
|
246
|
-
head(path: string, ...handlers:
|
|
263
|
+
head(path: string, ...handlers: T.ContextHandler[]): this;
|
|
247
264
|
/**
|
|
248
265
|
* The 'head' method is used to add the request handler to the router for 'HEAD' methods.
|
|
249
266
|
*
|
|
@@ -253,9 +270,9 @@ declare class Spear {
|
|
|
253
270
|
* @property {function} next - go to next function
|
|
254
271
|
* @returns {this}
|
|
255
272
|
*/
|
|
256
|
-
options(path: string, ...handlers:
|
|
273
|
+
options(path: string, ...handlers: T.ContextHandler[]): this;
|
|
257
274
|
/**
|
|
258
|
-
* The '
|
|
275
|
+
* The 'all' method is used to add the request handler to the router for 'GET' 'POST' 'PUT' 'PATCH' 'DELETE' 'HEAD' 'OPTIONS' methods.
|
|
259
276
|
*
|
|
260
277
|
* @param {string} path
|
|
261
278
|
* @callback {...Function[]} handlers of the middlewares
|
|
@@ -263,26 +280,16 @@ declare class Spear {
|
|
|
263
280
|
* @property {function} next - go to next function
|
|
264
281
|
* @returns {this}
|
|
265
282
|
*/
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* The 'all' method is used to add the request handler to the router for 'GET' 'POST' 'PUT' 'PATCH' 'DELETE' 'HEAD' 'OPTIONS' methods.
|
|
269
|
-
*
|
|
270
|
-
* @param {string} path
|
|
271
|
-
* @callback {...Function[]} handlers of the middlewares
|
|
272
|
-
* @property {object} ctx - context { req , res , query , params , cookies , files , body}
|
|
273
|
-
* @property {function} next - go to next function
|
|
274
|
-
* @returns {this}
|
|
275
|
-
*/
|
|
276
|
-
all(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
|
|
277
|
-
private _clusterMode;
|
|
283
|
+
all(path: string, ...handlers: T.ContextHandler[]): this;
|
|
278
284
|
private _import;
|
|
279
285
|
private _registerControllers;
|
|
280
286
|
private _registerMiddlewares;
|
|
281
|
-
private _customizeResponse;
|
|
282
287
|
private _wrapHandlers;
|
|
283
288
|
private _wrapResponse;
|
|
284
|
-
private
|
|
289
|
+
private _nextError;
|
|
290
|
+
private _clusterMode;
|
|
285
291
|
private _createServer;
|
|
292
|
+
private _createContext;
|
|
286
293
|
private _normalizePath;
|
|
287
294
|
private _swaggerHandler;
|
|
288
295
|
}
|