tspace-spear 1.2.3 → 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.
Files changed (54) hide show
  1. package/README.md +268 -19
  2. package/dist/lib/core/const/index.d.ts +153 -0
  3. package/dist/lib/core/const/index.js +105 -0
  4. package/dist/lib/core/const/index.js.map +1 -0
  5. package/dist/lib/core/decorators/context.d.ts +16 -9
  6. package/dist/lib/core/decorators/context.js +85 -59
  7. package/dist/lib/core/decorators/context.js.map +1 -1
  8. package/dist/lib/core/decorators/headers.d.ts +2 -2
  9. package/dist/lib/core/decorators/headers.js +1 -1
  10. package/dist/lib/core/decorators/headers.js.map +1 -1
  11. package/dist/lib/core/decorators/methods.d.ts +7 -7
  12. package/dist/lib/core/decorators/methods.js.map +1 -1
  13. package/dist/lib/core/decorators/middleware.d.ts +3 -3
  14. package/dist/lib/core/decorators/middleware.js +2 -2
  15. package/dist/lib/core/decorators/middleware.js.map +1 -1
  16. package/dist/lib/core/decorators/statusCode.d.ts +1 -1
  17. package/dist/lib/core/decorators/statusCode.js.map +1 -1
  18. package/dist/lib/core/decorators/swagger.d.ts +1 -1
  19. package/dist/lib/core/decorators/swagger.js.map +1 -1
  20. package/dist/lib/core/server/express.d.ts +295 -0
  21. package/dist/lib/core/server/express.js +1356 -0
  22. package/dist/lib/core/server/express.js.map +1 -0
  23. package/dist/lib/core/server/fast-router.d.ts +133 -0
  24. package/dist/lib/core/server/fast-router.js +277 -0
  25. package/dist/lib/core/server/fast-router.js.map +1 -0
  26. package/dist/lib/core/server/index.d.ts +34 -37
  27. package/dist/lib/core/server/index.js +192 -501
  28. package/dist/lib/core/server/index.js.map +1 -1
  29. package/dist/lib/core/server/net/index.d.ts +20 -0
  30. package/dist/lib/core/server/net/index.js +393 -0
  31. package/dist/lib/core/server/net/index.js.map +1 -0
  32. package/dist/lib/core/server/parser-factory.d.ts +10 -11
  33. package/dist/lib/core/server/parser-factory.js +259 -437
  34. package/dist/lib/core/server/parser-factory.js.map +1 -1
  35. package/dist/lib/core/server/request.d.ts +2 -0
  36. package/dist/lib/core/server/request.js +7 -0
  37. package/dist/lib/core/server/request.js.map +1 -0
  38. package/dist/lib/core/server/response.d.ts +6 -0
  39. package/dist/lib/core/server/response.js +168 -0
  40. package/dist/lib/core/server/response.js.map +1 -0
  41. package/dist/lib/core/server/router.d.ts +2 -12
  42. package/dist/lib/core/server/router.js +2 -13
  43. package/dist/lib/core/server/router.js.map +1 -1
  44. package/dist/lib/core/server/uWS/index.d.ts +30 -0
  45. package/dist/lib/core/server/uWS/index.js +357 -0
  46. package/dist/lib/core/server/uWS/index.js.map +1 -0
  47. package/dist/lib/core/types/index.d.ts +144 -43
  48. package/dist/lib/core/utils/index.d.ts +12 -0
  49. package/dist/lib/core/utils/index.js +137 -0
  50. package/dist/lib/core/utils/index.js.map +1 -0
  51. package/dist/lib/index.d.ts +3 -3
  52. package/dist/lib/index.js +3 -2
  53. package/dist/lib/index.js.map +1 -1
  54. package/package.json +19 -14
@@ -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,17 +22,15 @@ 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
28
  private _adapter;
29
29
  private _cluster?;
30
30
  private _cors?;
31
31
  private _swagger;
32
32
  private _swaggerSpecs;
33
- private _wss?;
34
- private _ws?;
35
- private _wsOptions?;
33
+ private _ws;
36
34
  private _errorHandler;
37
35
  private _globalMiddlewares;
38
36
  private _formatResponse;
@@ -48,9 +46,9 @@ declare class Spear {
48
46
  /**
49
47
  * The get 'routers' method is used get the all routers.
50
48
  *
51
- * @returns {Instance<findMyWayRouter.HTTPVersion.V1>}
49
+ * @returns {FastRouter}
52
50
  */
53
- get routers(): Instance<findMyWayRouter.HTTPVersion.V1>;
51
+ get routers(): FastRouter;
54
52
  /**
55
53
  * The 'ws' method is used to creates the WebSocket server.
56
54
  *
@@ -67,15 +65,25 @@ declare class Spear {
67
65
  * @property {Function} next - go to next function
68
66
  * @returns {this}
69
67
  */
70
- use(middleware: (ctx: T.Context, next: T.NextFunction) => void): this;
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;
71
79
  /**
72
80
  * The 'useAdater' method is used to switch between different server implementations,
73
81
  * such as the native Node.js HTTP server or uWebSockets.js (uWS).
74
82
  *
75
- * @param {T.Adapter} adapter - The adapter instance (e.g., HTTP or uWS).
83
+ * @param {T.AdapterServer} adapter - The adapter instance (e.g., HTTP or uWS).
76
84
  * @returns {this} Returns the current instance for chaining
77
85
  */
78
- useAdater(adapter: T.Adapter): this;
86
+ useAdater(adapter: T.AdapterServer): this;
79
87
  /**
80
88
  * The 'useCluster' method is used cluster run the server
81
89
  *
@@ -108,11 +116,11 @@ declare class Spear {
108
116
  * The 'useFileUpload' method is a middleware used to handler file uploads. It adds a file upload of incoming HTTP requests.
109
117
  *
110
118
  * @param {?Object}
111
- * @property {?number} limits
119
+ * @property {?number} limits // bytes. default Infinity
112
120
  * @property {?string} tempFileDir
113
121
  * @property {?Object} removeTempFile
114
122
  * @property {boolean} removeTempFile.remove
115
- * @property {number} removeTempFile.ms
123
+ * @property {number} removeTempFile.ms
116
124
  * @returns
117
125
  */
118
126
  useFileUpload({ limit, tempFileDir, removeTempFile }?: {
@@ -176,7 +184,7 @@ declare class Spear {
176
184
  * @param {function} format
177
185
  * @returns
178
186
  */
179
- response(format: (r: unknown, statusCode: number) => any): this;
187
+ response(format: (r: unknown, statusCode: number) => Record<string, any> | string): this;
180
188
  /**
181
189
  * The 'catch' method is middleware that is specifically designed to handle errors.
182
190
  *
@@ -185,14 +193,14 @@ declare class Spear {
185
193
  * @param {function} error
186
194
  * @returns
187
195
  */
188
- catch(error: (err: any, ctx: T.Context) => any): this;
196
+ catch(error: (err: any, ctx: T.Context) => T.Response): this;
189
197
  /**
190
198
  * The 'notfound' method is middleware that is specifically designed to handle errors notfound that occur during the processing of requests
191
199
  *
192
200
  * @param {function} fn
193
201
  * @returns
194
202
  */
195
- notfound(fn: (ctx: T.Context) => any): this;
203
+ notfound(fn: (ctx: T.Context) => T.Response): this;
196
204
  /**
197
205
  * The 'get' method is used to add the request handler to the router for the 'GET' method.
198
206
  *
@@ -202,7 +210,7 @@ declare class Spear {
202
210
  * @property {Function} next - go to next function
203
211
  * @returns {this}
204
212
  */
205
- get(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
213
+ get(path: string, ...handlers: T.ContextHandler[]): this;
206
214
  /**
207
215
  * The 'post' method is used to add the request handler to the router for the 'POST' method.
208
216
  *
@@ -212,7 +220,7 @@ declare class Spear {
212
220
  * @property {Function} next - go to next function
213
221
  * @returns {this}
214
222
  */
215
- post(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
223
+ post(path: string, ...handlers: T.ContextHandler[]): this;
216
224
  /**
217
225
  * The 'put' method is used to add the request handler to the router for the 'PUT' method.
218
226
  *
@@ -222,7 +230,7 @@ declare class Spear {
222
230
  * @property {Function} next - go to next function
223
231
  * @returns {this}
224
232
  */
225
- put(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
233
+ put(path: string, ...handlers: T.ContextHandler[]): this;
226
234
  /**
227
235
  * The 'patch' method is used to add the request handler to the router for the 'PATCH' method.
228
236
  *
@@ -232,7 +240,7 @@ declare class Spear {
232
240
  * @property {Function} next - go to next function
233
241
  * @returns {this}
234
242
  */
235
- patch(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
243
+ patch(path: string, ...handlers: T.ContextHandler[]): this;
236
244
  /**
237
245
  * The 'delete' method is used to add the request handler to the router for the 'DELETE' method.
238
246
  *
@@ -242,7 +250,7 @@ declare class Spear {
242
250
  * @property {Function} next - go to next function
243
251
  * @returns {this}
244
252
  */
245
- delete(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
253
+ delete(path: string, ...handlers: T.ContextHandler[]): this;
246
254
  /**
247
255
  * The 'head' method is used to add the request handler to the router for 'HEAD' methods.
248
256
  *
@@ -252,7 +260,7 @@ declare class Spear {
252
260
  * @property {function} next - go to next function
253
261
  * @returns {this}
254
262
  */
255
- head(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
263
+ head(path: string, ...handlers: T.ContextHandler[]): this;
256
264
  /**
257
265
  * The 'head' method is used to add the request handler to the router for 'HEAD' methods.
258
266
  *
@@ -262,9 +270,9 @@ declare class Spear {
262
270
  * @property {function} next - go to next function
263
271
  * @returns {this}
264
272
  */
265
- options(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
273
+ options(path: string, ...handlers: T.ContextHandler[]): this;
266
274
  /**
267
- * The 'any' method is used to add the request handler to the router for 'GET' 'POST' 'PUT' 'PATCH' 'DELETE' 'HEAD' 'OPTIONS' methods.
275
+ * The 'all' method is used to add the request handler to the router for 'GET' 'POST' 'PUT' 'PATCH' 'DELETE' 'HEAD' 'OPTIONS' methods.
268
276
  *
269
277
  * @param {string} path
270
278
  * @callback {...Function[]} handlers of the middlewares
@@ -272,27 +280,16 @@ declare class Spear {
272
280
  * @property {function} next - go to next function
273
281
  * @returns {this}
274
282
  */
275
- any(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
276
- /**
277
- * The 'all' method is used to add the request handler to the router for 'GET' 'POST' 'PUT' 'PATCH' 'DELETE' 'HEAD' 'OPTIONS' methods.
278
- *
279
- * @param {string} path
280
- * @callback {...Function[]} handlers of the middlewares
281
- * @property {object} ctx - context { req , res , query , params , cookies , files , body}
282
- * @property {function} next - go to next function
283
- * @returns {this}
284
- */
285
- all(path: string, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this;
283
+ all(path: string, ...handlers: T.ContextHandler[]): this;
286
284
  private _import;
287
285
  private _registerControllers;
288
286
  private _registerMiddlewares;
289
- private _customizeResponse;
290
287
  private _wrapHandlers;
291
288
  private _wrapResponse;
292
- private _nextFunction;
289
+ private _nextError;
293
290
  private _clusterMode;
294
291
  private _createServer;
295
- private _uWSRequestResponse;
292
+ private _createContext;
296
293
  private _normalizePath;
297
294
  private _swaggerHandler;
298
295
  }