tspace-spear 1.2.0 → 1.2.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 (62) hide show
  1. package/README.md +777 -705
  2. package/{build → dist}/lib/core/decorators/context.js +86 -0
  3. package/dist/lib/core/decorators/context.js.map +1 -0
  4. package/dist/lib/core/decorators/controller.js +43 -0
  5. package/dist/lib/core/decorators/controller.js.map +1 -0
  6. package/dist/lib/core/decorators/headers.js +44 -0
  7. package/dist/lib/core/decorators/headers.js.map +1 -0
  8. package/dist/lib/core/decorators/methods.js +102 -0
  9. package/dist/lib/core/decorators/methods.js.map +1 -0
  10. package/dist/lib/core/decorators/middleware.js +61 -0
  11. package/dist/lib/core/decorators/middleware.js.map +1 -0
  12. package/dist/lib/core/decorators/statusCode.js +40 -0
  13. package/dist/lib/core/decorators/statusCode.js.map +1 -0
  14. package/dist/lib/core/decorators/swagger.js +52 -0
  15. package/dist/lib/core/decorators/swagger.js.map +1 -0
  16. package/{build → dist}/lib/core/server/index.js +272 -205
  17. package/dist/lib/core/server/index.js.map +1 -0
  18. package/{build → dist}/lib/core/server/parser-factory.js +29 -7
  19. package/dist/lib/core/server/parser-factory.js.map +1 -0
  20. package/dist/lib/core/server/radix-router.js +65 -0
  21. package/dist/lib/core/server/radix-router.js.map +1 -0
  22. package/{build → dist}/lib/core/server/router.js +34 -0
  23. package/dist/lib/core/server/router.js.map +1 -0
  24. package/{build → dist}/lib/index.js +0 -1
  25. package/{build → dist}/lib/index.js.map +1 -1
  26. package/{build → dist}/tests/benchmark.test.js +38 -8
  27. package/{build → dist}/tests/benchmark.test.js.map +1 -1
  28. package/package.json +15 -10
  29. package/build/lib/core/decorators/context.d.ts +0 -5
  30. package/build/lib/core/decorators/context.js.map +0 -1
  31. package/build/lib/core/decorators/controller.d.ts +0 -1
  32. package/build/lib/core/decorators/controller.js +0 -10
  33. package/build/lib/core/decorators/controller.js.map +0 -1
  34. package/build/lib/core/decorators/headers.d.ts +0 -3
  35. package/build/lib/core/decorators/headers.js +0 -15
  36. package/build/lib/core/decorators/headers.js.map +0 -1
  37. package/build/lib/core/decorators/index.d.ts +0 -9
  38. package/build/lib/core/decorators/methods.d.ts +0 -5
  39. package/build/lib/core/decorators/methods.js +0 -25
  40. package/build/lib/core/decorators/methods.js.map +0 -1
  41. package/build/lib/core/decorators/middleware.d.ts +0 -2
  42. package/build/lib/core/decorators/middleware.js +0 -24
  43. package/build/lib/core/decorators/middleware.js.map +0 -1
  44. package/build/lib/core/decorators/statusCode.d.ts +0 -1
  45. package/build/lib/core/decorators/statusCode.js +0 -16
  46. package/build/lib/core/decorators/statusCode.js.map +0 -1
  47. package/build/lib/core/decorators/swagger.d.ts +0 -2
  48. package/build/lib/core/decorators/swagger.js +0 -18
  49. package/build/lib/core/decorators/swagger.js.map +0 -1
  50. package/build/lib/core/server/index.d.ts +0 -312
  51. package/build/lib/core/server/index.js.map +0 -1
  52. package/build/lib/core/server/parser-factory.d.ts +0 -24
  53. package/build/lib/core/server/parser-factory.js.map +0 -1
  54. package/build/lib/core/server/router.d.ts +0 -79
  55. package/build/lib/core/server/router.js.map +0 -1
  56. package/build/lib/core/types/index.d.ts +0 -168
  57. package/build/lib/index.d.ts +0 -11
  58. package/build/tests/benchmark.test.d.ts +0 -1
  59. /package/{build → dist}/lib/core/decorators/index.js +0 -0
  60. /package/{build → dist}/lib/core/decorators/index.js.map +0 -0
  61. /package/{build → dist}/lib/core/types/index.js +0 -0
  62. /package/{build → dist}/lib/core/types/index.js.map +0 -0
@@ -1,6 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Cookies = exports.Query = exports.Params = exports.Files = exports.Body = void 0;
4
+ /**
5
+ * Extract specific fields from `ctx.body`.
6
+ *
7
+ * This decorator filters the request body and keeps only the
8
+ * specified keys. The filtered result replaces `ctx.body`
9
+ * before the controller method is executed.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * @Body('email', 'password')
14
+ * async login(ctx: T.Context) {
15
+ * // ctx.body = { email: "...", password: "..." }
16
+ * }
17
+ * ```
18
+ *
19
+ * @param {...string} bodyParms - Body field names to extract.
20
+ * @returns {MethodDecorator}
21
+ */
4
22
  const Body = (...bodyParms) => {
5
23
  return function (target, key, descriptor) {
6
24
  const originalMethod = descriptor.value;
@@ -14,6 +32,23 @@ const Body = (...bodyParms) => {
14
32
  };
15
33
  };
16
34
  exports.Body = Body;
35
+ /**
36
+ * Extract specific uploaded files from `ctx.files`.
37
+ *
38
+ * Filters uploaded files and keeps only the specified
39
+ * file field names before executing the controller method.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * \@Files('avatar', 'resume')
44
+ * async upload(ctx: T.Context) {
45
+ * // ctx.files = { avatar: File, resume: File }
46
+ * }
47
+ * ```
48
+ *
49
+ * @param {...string} filesParms - File field names to extract.
50
+ * @returns {MethodDecorator}
51
+ */
17
52
  const Files = (...filesParms) => {
18
53
  return function (target, key, descriptor) {
19
54
  const originalMethod = descriptor.value;
@@ -27,6 +62,23 @@ const Files = (...filesParms) => {
27
62
  };
28
63
  };
29
64
  exports.Files = Files;
65
+ /**
66
+ * Extract specific route parameters from `ctx.params`.
67
+ *
68
+ * Filters route parameters and keeps only the specified
69
+ * parameter names.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * \@Params('id')
74
+ * async getUser(ctx: T.Context) {
75
+ * // ctx.params = { id: "123" }
76
+ * }
77
+ * ```
78
+ *
79
+ * @param {...string} paramsData - Route parameter names to extract.
80
+ * @returns {MethodDecorator}
81
+ */
30
82
  const Params = (...paramsData) => {
31
83
  return function (target, key, descriptor) {
32
84
  const originalMethod = descriptor.value;
@@ -40,6 +92,23 @@ const Params = (...paramsData) => {
40
92
  };
41
93
  };
42
94
  exports.Params = Params;
95
+ /**
96
+ * Extract specific query parameters from `ctx.query`.
97
+ *
98
+ * Filters query parameters and keeps only the specified
99
+ * query keys.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * \@Query('page', 'limit')
104
+ * async listUsers(ctx: T.Context) {
105
+ * // ctx.query = { page: "1", limit: "10" }
106
+ * }
107
+ * ```
108
+ *
109
+ * @param {...string} queryParms - Query parameter names to extract.
110
+ * @returns {MethodDecorator}
111
+ */
43
112
  const Query = (...queryParms) => {
44
113
  return function (target, key, descriptor) {
45
114
  const originalMethod = descriptor.value;
@@ -53,6 +122,23 @@ const Query = (...queryParms) => {
53
122
  };
54
123
  };
55
124
  exports.Query = Query;
125
+ /**
126
+ * Extract specific cookies from `ctx.cookies`.
127
+ *
128
+ * Filters cookies and keeps only the specified cookie keys
129
+ * before executing the controller method.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * \@Cookies('token')
134
+ * async profile(ctx: T.Context) {
135
+ * // ctx.cookies = { token: "..." }
136
+ * }
137
+ * ```
138
+ *
139
+ * @param {...string} cookiesParms - Cookie names to extract.
140
+ * @returns {MethodDecorator}
141
+ */
56
142
  const Cookies = (...cookiesParms) => {
57
143
  return function (target, key, descriptor) {
58
144
  const originalMethod = descriptor.value;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/context.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;GAiBG;AACI,MAAM,IAAI,GAAG,CAAC,GAAG,SAAmB,EAAY,EAAE;IACrD,OAAO,UAAU,MAAW,EAAE,GAAW,EAAE,UAA8B;QACrE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAc,EAAE,IAAoB;YACnE,MAAM,CAAC,GAAG,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC;YAC1B,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,CACzB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,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,CAAC,CAAC,CAAC,GAAG,CAAC,EAChE,EAAE,CACL,CAAC;YAEF,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YAEzD,OAAO,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QACtD,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC,CAAC;AAlBW,QAAA,OAAO,WAkBlB"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Controller = void 0;
4
+ /**
5
+ * Declares a class as a controller and assigns a base route path.
6
+ *
7
+ * The provided path will be used as the **base URL prefix**
8
+ * for all routes defined inside the controller. The path must
9
+ * start with `/`.
10
+ *
11
+ * This decorator stores the controller path using
12
+ * `Reflect.defineMetadata` under the key `"controllers"`.
13
+ * The framework can later read this metadata to register
14
+ * routes automatically.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * \@Controller('/users')
19
+ * class UserController {
20
+ *
21
+ * async list(ctx: T.Context) {
22
+ * return [{ id: 1, name: "John" }];
23
+ * }
24
+ *
25
+ * }
26
+ * ```
27
+ *
28
+ * If a route handler defines `/profile`, the final route becomes:
29
+ *
30
+ * ```
31
+ * /users/profile
32
+ * ```
33
+ *
34
+ * @param {`/${string}`} path - Base route path for the controller.
35
+ * @returns {ClassDecorator}
36
+ */
37
+ const Controller = (path) => {
38
+ return (target) => {
39
+ return Reflect.defineMetadata("controllers", path, target);
40
+ };
41
+ };
42
+ exports.Controller = Controller;
43
+ //# sourceMappingURL=controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/controller.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACI,MAAM,UAAU,GAAG,CAAC,IAAkB,EAAkB,EAAE;IAC/D,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,OAAO,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC7D,CAAC,CAAC;AACJ,CAAC,CAAA;AAJY,QAAA,UAAU,cAItB"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WriteHeader = void 0;
4
+ /**
5
+ * Sets the HTTP response headers and status code before the controller method executes.
6
+ *
7
+ * This decorator calls `res.writeHead()` on the underlying Node.js response object,
8
+ * allowing you to define the response **status code** and **headers** in advance.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * class UserController {
13
+ *
14
+ * \@WriteHeader(200, { "Content-Type": "application/json" })
15
+ * async profile(ctx: T.Context) {
16
+ * return { id: 1, name: "John" };
17
+ * }
18
+ *
19
+ * }
20
+ * ```
21
+ *
22
+ * Example response:
23
+ *
24
+ * ```
25
+ * HTTP/1.1 200 OK
26
+ * Content-Type: application/json
27
+ * ```
28
+ *
29
+ * @param {number} statusCode - HTTP status code to send with the response.
30
+ * @param {OutgoingHttpHeaders} contentType - Response headers to set.
31
+ * @returns {Function}
32
+ */
33
+ const WriteHeader = (statusCode, contentType) => {
34
+ return (target, key, descriptor) => {
35
+ const originalMethod = descriptor.value;
36
+ descriptor.value = async function (ctx, next) {
37
+ ctx.res.writeHead(...[statusCode, contentType]);
38
+ return await originalMethod.call(this, ctx, next);
39
+ };
40
+ return descriptor;
41
+ };
42
+ };
43
+ exports.WriteHeader = WriteHeader;
44
+ //# sourceMappingURL=headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/headers.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACI,MAAM,WAAW,GAAG,CAAC,UAAkB,EAAE,WAAgC,EAAY,EAAE;IAC5F,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,UAA8B,EAAE,EAAE;QAClE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAc,EAAE,IAAoB;YACrE,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;YAChD,OAAO,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QACpD,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,WAAW,eAWtB"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Options = exports.Head = exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = void 0;
4
+ const methodDecorator = (method) => {
5
+ return (path) => {
6
+ return (target, propertyKey) => {
7
+ const controller = target.constructor;
8
+ const routers = Reflect.hasMetadata("routers", controller)
9
+ ? Reflect.getMetadata("routers", controller)
10
+ : [];
11
+ routers.push({
12
+ method,
13
+ path,
14
+ handler: propertyKey,
15
+ });
16
+ Reflect.defineMetadata("routers", routers, controller);
17
+ };
18
+ };
19
+ };
20
+ /**
21
+ * Maps a controller method to an HTTP GET route.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * \@Get('/users')
26
+ * async list(ctx: T.Context) {
27
+ * return [{ id: 1, name: "John" }];
28
+ * }
29
+ * ```
30
+ */
31
+ exports.Get = methodDecorator('get');
32
+ /**
33
+ * Maps a controller method to an HTTP POST route.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * \@Post('/users')
38
+ * async create(ctx: T.Context) {
39
+ * return { success: true };
40
+ * }
41
+ * ```
42
+ */
43
+ exports.Post = methodDecorator('post');
44
+ /**
45
+ * Maps a controller method to an HTTP PUT route.
46
+ *
47
+ * Used for replacing a resource.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * \@Put('/users/:id')
52
+ * async update(ctx: T.Context) {}
53
+ * ```
54
+ */
55
+ exports.Put = methodDecorator('put');
56
+ /**
57
+ * Maps a controller method to an HTTP PATCH route.
58
+ *
59
+ * Used for partially updating a resource.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * \@Patch('/users/:id')
64
+ * async patch(ctx: T.Context) {}
65
+ * ```
66
+ */
67
+ exports.Patch = methodDecorator('patch');
68
+ /**
69
+ * Maps a controller method to an HTTP DELETE route.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * \@Delete('/users/:id')
74
+ * async remove(ctx: T.Context) {}
75
+ * ```
76
+ */
77
+ exports.Delete = methodDecorator('delete');
78
+ /**
79
+ * Maps a controller method to an HTTP HEAD route.
80
+ *
81
+ * HEAD responses contain only headers and no response body.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * \@Head('/health')
86
+ * async health(ctx: T.Context) {}
87
+ * ```
88
+ */
89
+ exports.Head = methodDecorator('head');
90
+ /**
91
+ * Maps a controller method to an HTTP OPTIONS route.
92
+ *
93
+ * Typically used for CORS preflight requests.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * \@Options('/users')
98
+ * async options(ctx: T.Context) {}
99
+ * ```
100
+ */
101
+ exports.Options = methodDecorator('options');
102
+ //# sourceMappingURL=methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/methods.ts"],"names":[],"mappings":";;;AAEA,MAAM,eAAe,GAAG,CAAC,MAAgB,EAAE,EAAE;IAC3C,OAAO,CAAC,IAAkB,EAAE,EAAE;QAC5B,OAAO,CAAC,MAAU,EAAE,WAAe,EAAE,EAAE;YACrC,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC;YAEtC,MAAM,OAAO,GAAe,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,UAAU,CAAC;gBACpE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,UAAU,CAAC;gBAC5C,CAAC,CAAC,EAAE,CAAC;YAEP,OAAO,CAAC,IAAI,CAAC;gBACX,MAAM;gBACN,IAAI;gBACJ,OAAO,EAAE,WAAW;aACrB,CAAC,CAAC;YAEH,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QACzD,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC,CAAA;AAED;;;;;;;;;;GAUG;AACU,QAAA,GAAG,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;AAE1C;;;;;;;;;;GAUG;AACU,QAAA,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;AAE5C;;;;;;;;;;GAUG;AACU,QAAA,GAAG,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;AAE1C;;;;;;;;;;GAUG;AACU,QAAA,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;AAE9C;;;;;;;;GAQG;AACU,QAAA,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;AAEhD;;;;;;;;;;GAUG;AACU,QAAA,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;AAE5C;;;;;;;;;;GAUG;AACU,QAAA,OAAO,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Middleware = void 0;
4
+ /**
5
+ * Attaches a middleware function to a controller method.
6
+ *
7
+ * The middleware will be executed **before the route handler**.
8
+ * If the middleware calls `next(err)`, the error will be forwarded
9
+ * to the framework's error handler. Otherwise, the original
10
+ * controller method will be executed.
11
+ *
12
+ * This decorator also stores middleware metadata using `Reflect.defineMetadata`
13
+ * so the framework can discover and execute it during the request lifecycle.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * class UserController {
18
+ *
19
+ * \@Middleware(authMiddleware)
20
+ * async profile(ctx: T.Context) {
21
+ * return { user: ctx.user };
22
+ * }
23
+ *
24
+ * }
25
+ * ```
26
+ *
27
+ * Example middleware:
28
+ *
29
+ * ```ts
30
+ * const authMiddleware: T.RequestFunction = (ctx, next) => {
31
+ * if (!ctx.user) {
32
+ * return next(new Error("Unauthorized"));
33
+ * }
34
+ * next();
35
+ * };
36
+ * ```
37
+ *
38
+ * @param {T.RequestFunction} middleware - Middleware function to execute before the route handler.
39
+ * @returns {MethodDecorator}
40
+ */
41
+ const Middleware = (middleware) => {
42
+ return (target, key, descriptor) => {
43
+ const originalMethod = descriptor.value;
44
+ descriptor.value = function (ctx, next) {
45
+ try {
46
+ Reflect.defineMetadata("middlewares", descriptor, target);
47
+ return middleware(ctx, (err) => {
48
+ if (err != null) {
49
+ return next(err);
50
+ }
51
+ return originalMethod.call(this, ctx, next);
52
+ });
53
+ }
54
+ catch (error) {
55
+ return next(error);
56
+ }
57
+ };
58
+ };
59
+ };
60
+ exports.Middleware = Middleware;
61
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/middleware.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACI,MAAM,UAAU,GAAG,CAAC,UAA6B,EAAY,EAAE;IAEpE,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,UAA8B,EAAE,EAAE;QAClE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,UAAU,GAAc,EAAE,IAAoB;YAC/D,IAAI;gBAEF,OAAO,CAAC,cAAc,CAAC,aAAa,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;gBAE1D,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,GAAS,EAAE,EAAE;oBACnC,IAAI,GAAG,IAAI,IAAI,EAAE;wBACf,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;qBAClB;oBAED,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;gBAC9C,CAAC,CAAC,CAAC;aAEJ;YAAC,OAAO,KAAU,EAAE;gBACnB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAvBW,QAAA,UAAU,cAuBrB"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StatusCode = void 0;
4
+ /**
5
+ * Sets the HTTP response status code before executing the controller method.
6
+ *
7
+ * The provided status code will be automatically clamped between **100** and **599**
8
+ * to ensure a valid HTTP status range. It also sets the default
9
+ * `Content-Type` header to `application/json`.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * class UserController {
14
+ * \@StatusCode(201)
15
+ * async create(ctx: T.Context) {
16
+ * return { success: true };
17
+ * }
18
+ * }
19
+ * ```
20
+ *
21
+ * In this example the response will be sent with:
22
+ * - Status: **201 Created**
23
+ * - Header: `Content-Type: application/json`
24
+ *
25
+ * @param {T.StatusCode} statusCode - HTTP status code to send with the response.
26
+ * @returns {MethodDecorator}
27
+ */
28
+ const StatusCode = (statusCode) => {
29
+ return (target, key, descriptor) => {
30
+ const originalMethod = descriptor.value;
31
+ const code = statusCode < 100 ? 100 : statusCode > 599 ? 599 : statusCode;
32
+ descriptor.value = async function (ctx, next) {
33
+ ctx.res.writeHead(code, { 'Content-Type': 'application/json' });
34
+ return await originalMethod.call(this, ctx, next);
35
+ };
36
+ return descriptor;
37
+ };
38
+ };
39
+ exports.StatusCode = StatusCode;
40
+ //# sourceMappingURL=statusCode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statusCode.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/statusCode.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,UAAU,GAAG,CAAC,UAAwB,EAAY,EAAE;IAC7D,OAAO,CAAC,MAAW,EAAE,GAAW,EAAE,UAA8B,EAAE,EAAE;QAChE,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,MAAM,IAAI,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,KAAK,WAAW,GAAc,EAAE,IAAoB;YACnE,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;YAChE,OAAO,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QACtD,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC,CAAC;AAbW,QAAA,UAAU,cAarB"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Swagger = void 0;
4
+ /**
5
+ * Attaches Swagger/OpenAPI specification metadata to a controller method.
6
+ *
7
+ * This decorator stores route documentation using `Reflect.defineMetadata`
8
+ * so the framework can later collect it and generate **Swagger / OpenAPI**
9
+ * documentation automatically.
10
+ *
11
+ * The metadata is stored on the controller constructor under the key `"swaggers"`.
12
+ * Each decorated method contributes a Swagger specification object.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * class UserController {
17
+ *
18
+ * \@Swagger({
19
+ * summary: "Get user profile",
20
+ * description: "Returns the authenticated user's profile",
21
+ * tags: ["Users"],
22
+ * responses: {
23
+ * 200: {
24
+ * description: "Successful response"
25
+ * }
26
+ * }
27
+ * })
28
+ * async profile(ctx: T.Context) {
29
+ * return { id: 1, name: "John" };
30
+ * }
31
+ *
32
+ * }
33
+ * ```
34
+ *
35
+ * @param {T.Swagger.Spec} data - Swagger/OpenAPI specification for the route.
36
+ * @returns {MethodDecorator}
37
+ */
38
+ const Swagger = (data) => {
39
+ return (target, propertyKey) => {
40
+ const controller = target.constructor;
41
+ const swaggers = Reflect.hasMetadata("swaggers", controller)
42
+ ? Reflect.getMetadata("swaggers", controller)
43
+ : [];
44
+ swaggers.push({
45
+ handler: propertyKey,
46
+ ...data,
47
+ });
48
+ Reflect.defineMetadata("swaggers", swaggers, controller);
49
+ };
50
+ };
51
+ exports.Swagger = Swagger;
52
+ //# sourceMappingURL=swagger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swagger.js","sourceRoot":"","sources":["../../../../src/lib/core/decorators/swagger.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACI,MAAM,OAAO,GAAG,CAAC,IAAoB,EAAE,EAAE;IAC9C,OAAO,CAAC,MAAW,EAAE,WAAgB,EAAE,EAAE;QACvC,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC;QAEtC,MAAM,QAAQ,GAAU,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC;YACjE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC;YAC7C,CAAC,CAAC,EAAE,CAAC;QAEP,QAAQ,CAAC,IAAI,CAAC;YACZ,OAAO,EAAE,WAAW;YACpB,GAAG,IAAI;SACR,CAAC,CAAC;QAEH,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,OAAO,WAelB"}