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