@athenna/http 3.0.11 → 3.1.0

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 (151) hide show
  1. package/build/Commands/MakeControllerCommand.d.ts +15 -0
  2. package/build/Commands/MakeControllerCommand.js +42 -0
  3. package/build/Commands/MakeInterceptorCommand.d.ts +15 -0
  4. package/build/Commands/MakeInterceptorCommand.js +42 -0
  5. package/build/Commands/MakeMiddlewareCommand.d.ts +15 -0
  6. package/build/Commands/MakeMiddlewareCommand.js +42 -0
  7. package/build/Commands/MakeTerminatorCommand.d.ts +15 -0
  8. package/build/Commands/MakeTerminatorCommand.js +42 -0
  9. package/build/Commands/RouteListCommand.d.ts +19 -0
  10. package/build/Commands/RouteListCommand.js +62 -0
  11. package/build/Context/Request.d.ts +144 -0
  12. package/build/Context/Request.js +219 -0
  13. package/build/Context/Response.d.ts +67 -0
  14. package/build/Context/Response.js +102 -0
  15. package/build/Contracts/InterceptorContract.d.ts +15 -0
  16. package/build/Contracts/InterceptorContract.js +9 -0
  17. package/build/Contracts/MiddlewareContract.d.ts +15 -0
  18. package/build/Contracts/MiddlewareContract.js +9 -0
  19. package/build/Contracts/TerminatorContract.d.ts +15 -0
  20. package/build/Contracts/TerminatorContract.js +9 -0
  21. package/build/Decorators/Controller.d.ts +14 -0
  22. package/build/Decorators/Controller.js +28 -0
  23. package/build/Decorators/Interceptor.d.ts +14 -0
  24. package/build/Decorators/Interceptor.js +37 -0
  25. package/build/Decorators/Middleware.d.ts +14 -0
  26. package/build/Decorators/Middleware.js +37 -0
  27. package/build/Decorators/Terminator.d.ts +14 -0
  28. package/build/Decorators/Terminator.js +37 -0
  29. package/build/Exceptions/BadGatewayException.d.ts +20 -0
  30. package/build/Exceptions/BadGatewayException.js +22 -0
  31. package/build/Exceptions/BadRequestException.d.ts +20 -0
  32. package/build/Exceptions/BadRequestException.js +22 -0
  33. package/build/Exceptions/ForbiddenException.d.ts +20 -0
  34. package/build/Exceptions/ForbiddenException.js +22 -0
  35. package/build/Exceptions/HttpException.d.ts +20 -0
  36. package/build/Exceptions/HttpException.js +27 -0
  37. package/build/Exceptions/InternalServerException.d.ts +20 -0
  38. package/build/Exceptions/InternalServerException.js +22 -0
  39. package/build/Exceptions/MethodNotAllowedException.d.ts +20 -0
  40. package/build/Exceptions/MethodNotAllowedException.js +22 -0
  41. package/build/Exceptions/NotAcceptableException.d.ts +20 -0
  42. package/build/Exceptions/NotAcceptableException.js +22 -0
  43. package/build/Exceptions/NotFoundException.d.ts +20 -0
  44. package/build/Exceptions/NotFoundException.js +22 -0
  45. package/build/Exceptions/NotImplementedException.d.ts +20 -0
  46. package/build/Exceptions/NotImplementedException.js +22 -0
  47. package/build/Exceptions/PayloadTooLargeException.d.ts +20 -0
  48. package/build/Exceptions/PayloadTooLargeException.js +22 -0
  49. package/build/Exceptions/RequestTimeoutException.d.ts +20 -0
  50. package/build/Exceptions/RequestTimeoutException.js +22 -0
  51. package/build/Exceptions/ServiceUnavailableException.d.ts +20 -0
  52. package/build/Exceptions/ServiceUnavailableException.js +22 -0
  53. package/build/Exceptions/UnauthorizedException.d.ts +20 -0
  54. package/build/Exceptions/UnauthorizedException.js +22 -0
  55. package/build/Exceptions/UndefinedMethodException.d.ts +12 -0
  56. package/build/Exceptions/UndefinedMethodException.js +19 -0
  57. package/build/Exceptions/UnprocessableEntityException.d.ts +20 -0
  58. package/build/Exceptions/UnprocessableEntityException.js +22 -0
  59. package/build/Facades/Route.d.ts +10 -0
  60. package/{src → build}/Facades/Route.js +2 -7
  61. package/build/Facades/Server.d.ts +10 -0
  62. package/{src → build}/Facades/Server.js +2 -7
  63. package/build/Handlers/FastifyHandler.d.ts +41 -0
  64. package/build/Handlers/FastifyHandler.js +116 -0
  65. package/build/Handlers/HttpExceptionHandler.d.ts +31 -0
  66. package/build/Handlers/HttpExceptionHandler.js +82 -0
  67. package/build/Kernels/HttpKernel.d.ts +73 -0
  68. package/build/Kernels/HttpKernel.js +221 -0
  69. package/build/Providers/HttpRouteProvider.d.ts +12 -0
  70. package/build/Providers/HttpRouteProvider.js +15 -0
  71. package/build/Providers/HttpServerProvider.d.ts +13 -0
  72. package/build/Providers/HttpServerProvider.js +25 -0
  73. package/build/Router/Route.d.ts +263 -0
  74. package/build/Router/Route.js +447 -0
  75. package/build/Router/RouteGroup.d.ts +96 -0
  76. package/build/Router/RouteGroup.js +123 -0
  77. package/build/Router/RouteResource.d.ts +108 -0
  78. package/build/Router/RouteResource.js +158 -0
  79. package/build/Router/Router.d.ts +103 -0
  80. package/build/Router/Router.js +188 -0
  81. package/build/Server/ServerImpl.d.ts +129 -0
  82. package/build/Server/ServerImpl.js +213 -0
  83. package/build/Types/Contexts/Context.d.ts +20 -0
  84. package/build/Types/Contexts/Context.js +9 -0
  85. package/build/Types/Contexts/ErrorContext.d.ts +21 -0
  86. package/build/Types/Contexts/ErrorContext.js +9 -0
  87. package/build/Types/Contexts/InterceptContext.d.ts +20 -0
  88. package/build/Types/Contexts/InterceptContext.js +9 -0
  89. package/build/Types/Contexts/TerminateContext.d.ts +21 -0
  90. package/build/Types/Contexts/TerminateContext.js +9 -0
  91. package/build/Types/Controllers/ControllerOptions.d.ts +25 -0
  92. package/build/Types/Controllers/ControllerOptions.js +9 -0
  93. package/build/Types/Middlewares/InterceptorRouteType.d.ts +11 -0
  94. package/build/Types/Middlewares/InterceptorRouteType.js +9 -0
  95. package/build/Types/Middlewares/MiddlewareHandler.d.ts +20 -0
  96. package/build/Types/Middlewares/MiddlewareHandler.js +9 -0
  97. package/build/Types/Middlewares/MiddlewareOptions.d.ts +40 -0
  98. package/build/Types/Middlewares/MiddlewareOptions.js +9 -0
  99. package/build/Types/Middlewares/MiddlewareRouteType.d.ts +11 -0
  100. package/build/Types/Middlewares/MiddlewareRouteType.js +9 -0
  101. package/build/Types/Middlewares/TerminatorRouteType.d.ts +11 -0
  102. package/build/Types/Middlewares/TerminatorRouteType.js +9 -0
  103. package/build/Types/Router/RouteHandler.d.ts +10 -0
  104. package/build/Types/Router/RouteHandler.js +9 -0
  105. package/build/Types/Router/RouteJSON.d.ts +21 -0
  106. package/build/Types/Router/RouteJSON.js +9 -0
  107. package/build/Types/Router/RouteResourceTypes.d.ts +9 -0
  108. package/build/Types/Router/RouteResourceTypes.js +9 -0
  109. package/build/index.d.ts +70 -0
  110. package/build/index.js +48 -0
  111. package/package.json +159 -77
  112. package/templates/controller.edge +8 -36
  113. package/templates/interceptor.edge +8 -0
  114. package/templates/middleware.edge +4 -36
  115. package/templates/terminator.edge +6 -0
  116. package/src/Commands/Make/Controller.js +0 -64
  117. package/src/Commands/Make/Middleware.js +0 -80
  118. package/src/Commands/Route/List.js +0 -107
  119. package/src/Context/Request.js +0 -268
  120. package/src/Context/Response.js +0 -173
  121. package/src/Exceptions/BadGatewayException.js +0 -31
  122. package/src/Exceptions/BadRequestException.js +0 -31
  123. package/src/Exceptions/ForbiddenException.js +0 -31
  124. package/src/Exceptions/HttpException.js +0 -33
  125. package/src/Exceptions/InternalServerException.js +0 -31
  126. package/src/Exceptions/MethodNotAllowedException.js +0 -31
  127. package/src/Exceptions/NotAcceptableException.js +0 -31
  128. package/src/Exceptions/NotFoundException.js +0 -31
  129. package/src/Exceptions/NotImplementedException.js +0 -31
  130. package/src/Exceptions/PayloadTooLargeException.js +0 -31
  131. package/src/Exceptions/RequestTimeoutException.js +0 -31
  132. package/src/Exceptions/ServiceUnavailableException.js +0 -31
  133. package/src/Exceptions/UnauthorizedException.js +0 -31
  134. package/src/Exceptions/UndefinedMethodException.js +0 -30
  135. package/src/Exceptions/UnprocessableEntityException.js +0 -31
  136. package/src/Handlers/FastifyHandler.js +0 -148
  137. package/src/Handlers/HttpExceptionHandler.js +0 -88
  138. package/src/Helpers/HttpLoader.js +0 -38
  139. package/src/Kernels/HttpKernel.js +0 -199
  140. package/src/Providers/ControllerProvider.js +0 -29
  141. package/src/Providers/HttpRouteProvider.js +0 -24
  142. package/src/Providers/HttpServerProvider.js +0 -37
  143. package/src/Providers/MiddlewareProvider.js +0 -29
  144. package/src/Router/Route.js +0 -411
  145. package/src/Router/RouteGroup.js +0 -119
  146. package/src/Router/RouteResource.js +0 -247
  147. package/src/Router/Router.js +0 -313
  148. package/src/Utils/isMiddlewareContract.js +0 -17
  149. package/src/Utils/removeSlashes.js +0 -30
  150. package/src/index.d.ts +0 -1395
  151. package/src/index.js +0 -377
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/http",
3
- "version": "3.0.11",
3
+ "version": "3.1.0",
4
4
  "description": "The Athenna Http server. Built on top of fastify.",
5
5
  "license": "MIT",
6
6
  "author": "João Lenon <lenon@athenna.io>",
@@ -12,103 +12,126 @@
12
12
  "router",
13
13
  "cors",
14
14
  "ctx",
15
+ "helmet",
16
+ "swagger",
15
17
  "exception-handling",
16
18
  "rate-limiting",
17
19
  "middlewares",
20
+ "terminators",
21
+ "interceptors",
18
22
  "http-server",
19
23
  "athenna",
20
24
  "esm"
21
25
  ],
22
26
  "scripts": {
23
- "lint:fix": "eslint \"{src,tests}/**/*.js\" --fix",
24
- "test": "npm run --silent lint:fix && node ./tests/index.js",
25
- "test:debug": "cross-env DEBUG=api:* && npm run --silent test",
26
- "test:coverage": "c8 npm run --silent test",
27
- "gen:types": "tsc src/*.js --declaration --allowJs --emitDeclarationOnly --out src/index.js"
27
+ "node": "cross-env NODE_OPTIONS=\"--experimental-import-meta-resolve\" ts-node",
28
+ "build": "npm run node --silent -- bin/build.ts",
29
+ "artisan": "npm run node --silent -- bin/artisan.ts",
30
+ "lint:fix": "eslint \"{src,tests}/**/*.ts\" --fix",
31
+ "test": "npm run --silent lint:fix && npm run node --silent -- bin/test.ts",
32
+ "test:debug": "cross-env DEBUG=api:* npm run node --silent -- bin/test.ts --inspect",
33
+ "test:coverage": "c8 npm run --silent test"
28
34
  },
29
35
  "files": [
30
- "src/*.js",
31
- "src/*.d.ts",
32
- "src/**/*.js",
33
- "src/**/*.d.ts",
36
+ "build/*.js",
37
+ "build/*.d.ts",
38
+ "build/**/*.js",
39
+ "build/**/*.d.ts",
34
40
  "templates/*",
35
41
  "templates/**/*"
36
42
  ],
37
43
  "type": "module",
38
- "main": "./src/index.js",
44
+ "main": "./build/index.js",
45
+ "types": "./build/index.d.ts",
39
46
  "exports": {
40
- ".": "./src/index.js",
41
- "./facades/Route": "./src/Facades/Route.js",
42
- "./facades/Server": "./src/Facades/Server.js",
43
- "./providers/ControllerProvider": "./src/Providers/ControllerProvider.js",
44
- "./providers/HttpRouteProvider": "./src/Providers/HttpRouteProvider.js",
45
- "./providers/HttpServerProvider": "./src/Providers/HttpServerProvider.js",
46
- "./providers/MiddlewareProvider": "./src/Providers/MiddlewareProvider.js",
47
- "./commands/Route/List": "./src/Commands/Route/List.js",
48
- "./commands/Make/Controller": "./src/Commands/Make/Controller.js",
49
- "./commands/Make/Middleware": "./src/Commands/Make/Middleware.js"
47
+ ".": "./build/index.js",
48
+ "./providers/HttpRouteProvider": "./build/Providers/HttpRouteProvider.js",
49
+ "./providers/HttpServerProvider": "./build/Providers/HttpServerProvider.js",
50
+ "./commands/RouteListCommand": "./build/Commands/RouteListCommand.js",
51
+ "./commands/MakeControllerCommand": "./build/Commands/MakeControllerCommand.js",
52
+ "./commands/MakeMiddlewareCommand": "./build/Commands/MakeMiddlewareCommand.js",
53
+ "./commands/MakeTerminatorCommand": "./build/Commands/MakeTerminatorCommand.js",
54
+ "./commands/MakeInterceptorCommand": "./build/Commands/MakeInterceptorCommand.js"
50
55
  },
51
- "types": "./src/index.d.ts",
52
56
  "imports": {
53
- "#src/*": "./src/*.js",
54
- "#tests/*": "./tests/*.js"
57
+ "#src/*": "./build/*.js",
58
+ "#src": "./build/index.js",
59
+ "#tests/*": "./tests/*.js",
60
+ "#tests": "./tests/index.js"
55
61
  },
56
62
  "dependencies": {
57
- "fastify": "4.9.2"
63
+ "fastify": "^4.13.0"
58
64
  },
59
65
  "devDependencies": {
60
- "@athenna/artisan": "3.0.10",
61
- "@athenna/common": "3.0.2",
62
- "@athenna/config": "3.0.4",
63
- "@athenna/ioc": "3.0.2",
64
- "@athenna/logger": "3.0.9",
65
- "@fastify/cors": "8.1.1",
66
- "@fastify/helmet": "10.0.2",
67
- "@fastify/rate-limit": "7.5.0",
68
- "@fastify/swagger": "8.1.0",
69
- "@fastify/swagger-ui": "1.1.0",
70
- "@japa/assert": "1.3.4",
71
- "@japa/run-failed-tests": "1.0.7",
72
- "@japa/runner": "2.0.7",
73
- "@japa/spec-reporter": "1.1.12",
74
- "@types/commander": "2.12.2",
75
- "c8": "7.11.2",
76
- "cls-rtracer": "2.6.2",
77
- "commitizen": "4.2.5",
78
- "cross-env": "7.0.3",
79
- "cz-conventional-changelog": "3.3.0",
80
- "eslint": "8.14.0",
81
- "eslint-config-prettier": "8.5.0",
82
- "eslint-config-standard": "17.0.0",
83
- "eslint-plugin-import": "2.26.0",
84
- "eslint-plugin-n": "15.2.0",
85
- "eslint-plugin-prettier": "4.0.0",
86
- "eslint-plugin-promise": "6.0.0",
87
- "husky": "3.0.9",
88
- "lint-staged": "12.4.1",
89
- "minimist": "1.2.6",
90
- "prettier": "2.6.2",
91
- "rimraf": "3.0.2",
92
- "typescript": "4.6.4"
66
+ "@athenna/artisan": "^3.0.0",
67
+ "@athenna/common": "^3.0.0",
68
+ "@athenna/config": "^3.0.0",
69
+ "@athenna/ioc": "^3.0.0",
70
+ "@athenna/logger": "^3.0.0",
71
+ "@athenna/view": "^3.0.0",
72
+ "@fastify/cors": "^8.1.1",
73
+ "@fastify/helmet": "^10.0.2",
74
+ "@fastify/rate-limit": "^7.5.0",
75
+ "@fastify/swagger": "^8.1.0",
76
+ "@fastify/swagger-ui": "^1.1.0",
77
+ "@japa/assert": "^1.3.6",
78
+ "@japa/run-failed-tests": "^1.1.0",
79
+ "@japa/runner": "^2.2.2",
80
+ "@japa/spec-reporter": "^1.3.2",
81
+ "@swc/core": "^1.3.27",
82
+ "@types/bytes": "^3.1.1",
83
+ "@types/callsite": "^1.0.31",
84
+ "@types/columnify": "^1.5.1",
85
+ "@types/debug": "^4.1.7",
86
+ "@types/figlet": "^1.5.5",
87
+ "@types/inquirer": "^9.0.3",
88
+ "@types/kind-of": "^6.0.0",
89
+ "@types/lodash": "^4.14.191",
90
+ "@types/ms": "^0.7.31",
91
+ "@types/pluralize": "^0.0.29",
92
+ "@types/sinon": "^10.0.13",
93
+ "@types/uuid": "^9.0.0",
94
+ "@typescript-eslint/eslint-plugin": "^5.48.1",
95
+ "@typescript-eslint/parser": "^5.48.1",
96
+ "c8": "^7.12.0",
97
+ "cls-rtracer": "^2.6.2",
98
+ "commitizen": "^4.2.6",
99
+ "cross-env": "^7.0.3",
100
+ "cz-conventional-changelog": "^3.3.0",
101
+ "eslint": "^8.32.0",
102
+ "eslint-config-prettier": "^8.6.0",
103
+ "eslint-config-standard": "^17.0.0",
104
+ "eslint-plugin-import": "^2.27.5",
105
+ "eslint-plugin-n": "^15.6.1",
106
+ "eslint-plugin-prettier": "^4.2.1",
107
+ "eslint-plugin-promise": "^6.1.1",
108
+ "husky": "^3.1.0",
109
+ "js-yaml": "^4.1.0",
110
+ "lint-staged": "^12.5.0",
111
+ "minimist": "^1.2.7",
112
+ "prettier": "^2.8.3",
113
+ "reflect-metadata": "^0.1.13",
114
+ "rimraf": "^3.0.2",
115
+ "sinon": "^15.0.1",
116
+ "ts-node": "^10.9.1",
117
+ "typescript": "^4.9.4"
93
118
  },
94
119
  "c8": {
95
120
  "all": true,
96
121
  "include": [
97
- "src/**/*.js"
122
+ "src/**/*.ts"
98
123
  ],
99
124
  "exclude": [
100
- "src/Exceptions/*.js"
125
+ "src/Types/*",
126
+ "src/Contracts/*",
127
+ "src/Exceptions/*"
101
128
  ],
102
129
  "reporter": [
103
130
  "text-summary",
104
131
  "html"
105
132
  ],
106
133
  "report-dir": "./tests/Coverage",
107
- "check-coverage": true,
108
- "statements": "70",
109
- "branches": "70",
110
- "functions": "70",
111
- "lines": "70"
134
+ "check-coverage": true
112
135
  },
113
136
  "husky": {
114
137
  "hooks": {
@@ -116,7 +139,7 @@
116
139
  }
117
140
  },
118
141
  "lint-staged": {
119
- "*.js": [
142
+ "*.ts": [
120
143
  "eslint --fix",
121
144
  "git add"
122
145
  ],
@@ -146,34 +169,93 @@
146
169
  }
147
170
  ]
148
171
  },
172
+ "eslintIgnore": [
173
+ "build/**/*"
174
+ ],
149
175
  "eslintConfig": {
150
176
  "env": {
151
177
  "es2021": true,
152
178
  "node": true
153
179
  },
154
180
  "globals": {
155
- "ioc": true
181
+ "ioc": true,
182
+ "Env": true,
183
+ "Path": true,
184
+ "Config": true
156
185
  },
157
186
  "plugins": [
158
- "prettier"
187
+ "prettier",
188
+ "@typescript-eslint"
159
189
  ],
160
190
  "extends": [
161
191
  "standard",
162
192
  "eslint:recommended",
163
- "plugin:prettier/recommended"
164
- ],
165
- "ignorePatterns": [
166
- "**/*.d.ts"
193
+ "plugin:prettier/recommended",
194
+ "plugin:@typescript-eslint/recommended",
195
+ "plugin:@typescript-eslint/eslint-recommended"
167
196
  ],
168
- "parserOptions": {
169
- "ecmaVersion": "latest",
170
- "sourceType": "module"
171
- },
197
+ "parser": "@typescript-eslint/parser",
172
198
  "rules": {
173
199
  "camelcase": "off",
174
200
  "dot-notation": "off",
175
201
  "prettier/prettier": "error",
176
- "no-useless-constructor": "off"
202
+ "no-useless-constructor": "off",
203
+ "@typescript-eslint/no-explicit-any": "off",
204
+ "@typescript-eslint/no-empty-function": "off",
205
+ "@typescript-eslint/no-unused-vars": [
206
+ "error",
207
+ {
208
+ "argsIgnorePattern": "^_",
209
+ "varsIgnorePattern": "^_",
210
+ "caughtErrorsIgnorePattern": "^_"
211
+ }
212
+ ]
213
+ }
214
+ },
215
+ "athenna": {
216
+ "preloads": [],
217
+ "services": [],
218
+ "providers": [],
219
+ "commands": [
220
+ "#src/Commands/MakeControllerCommand",
221
+ "#src/Commands/MakeInterceptorCommand",
222
+ "#src/Commands/MakeMiddlewareCommand",
223
+ "#src/Commands/MakeTerminatorCommand",
224
+ "#src/Commands/RouteListCommand"
225
+ ],
226
+ "controllers": [
227
+ "#tests/Stubs/controllers/HelloController",
228
+ "#tests/Stubs/controllers/DecoratedController"
229
+ ],
230
+ "middlewares": [
231
+ "#tests/Stubs/middlewares/Middleware",
232
+ "#tests/Stubs/middlewares/ImportedMiddleware",
233
+ "#tests/Stubs/middlewares/DecoratedMiddleware",
234
+ "#tests/Stubs/middlewares/DecoratedInterceptor",
235
+ "#tests/Stubs/middlewares/DecoratedTerminator"
236
+ ],
237
+ "namedMiddlewares": {
238
+ "middleware": "#tests/Stubs/middlewares/Middleware",
239
+ "interceptor": "#tests/Stubs/middlewares/Interceptor",
240
+ "terminator": "#tests/Stubs/middlewares/Terminator",
241
+ "not-found-middleware": "#tests/Stubs/middlewares/DecoratedMiddleware",
242
+ "not-found-interceptor": "#tests/Stubs/middlewares/DecoratedInterceptor",
243
+ "not-found-terminator": "#tests/Stubs/middlewares/DecoratedTerminator"
244
+ },
245
+ "globalMiddlewares": [
246
+ "#tests/Stubs/middlewares/Middleware",
247
+ "#tests/Stubs/middlewares/Interceptor",
248
+ "#tests/Stubs/middlewares/Terminator",
249
+ "#tests/Stubs/middlewares/DecoratedGlobalMiddleware",
250
+ "#tests/Stubs/middlewares/DecoratedGlobalInterceptor",
251
+ "#tests/Stubs/middlewares/DecoratedGlobalTerminator"
252
+ ],
253
+ "commandsManifest": {
254
+ "route:list": "#src/Commands/RouteListCommand",
255
+ "make:controller": "#src/Commands/MakeControllerCommand",
256
+ "make:interceptor": "#src/Commands/MakeInterceptorCommand",
257
+ "make:middleware": "#src/Commands/MakeMiddlewareCommand",
258
+ "make:terminator": "#src/Commands/MakeTerminatorCommand"
177
259
  }
178
260
  }
179
261
  }
@@ -1,52 +1,24 @@
1
- export class {{ namePascal }} {
2
- /**
3
- * Resolve any dependency of the service container
4
- * inside the constructor.
5
- */
6
- constructor() {}
1
+ import { Context, Controller } from '@athenna/http'
7
2
 
8
- /**
9
- * Index method
10
- *
11
- * @param {import('@athenna/http').ContextContract} ctx
12
- */
13
- async index({ response }) {
3
+ @Controller()
4
+ export class {{ namePascal }} {
5
+ public async index({ response }: Context): Promise<void> {
14
6
  return response.status(200).send([{}])
15
7
  }
16
8
 
17
- /**
18
- * Store method
19
- *
20
- * @param {import('@athenna/http').ContextContract} ctx
21
- */
22
- async store({ response }) {
9
+ public async store({ response }: Context): Promise<void> {
23
10
  return response.status(201).send({})
24
11
  }
25
12
 
26
- /**
27
- * Show method
28
- *
29
- * @param {import('@athenna/http').ContextContract} ctx
30
- */
31
- async show({ response }) {
13
+ public async show({ response }: Context): Promise<void> {
32
14
  return response.status(200).send({})
33
15
  }
34
16
 
35
- /**
36
- * Update method
37
- *
38
- * @param {import('@athenna/http').ContextContract} ctx
39
- */
40
- async update({ response, params }) {
17
+ public async update({ response, params }: Context): Promise<void> {
41
18
  return response.status(200).send({ id: params.id })
42
19
  }
43
20
 
44
- /**
45
- * Delete method
46
- *
47
- * @param {import('@athenna/http').ContextContract} ctx
48
- */
49
- async delete({ response }) {
21
+ public async delete({ response }: Context): Promise<void> {
50
22
  return response.status(204)
51
23
  }
52
24
  }
@@ -0,0 +1,8 @@
1
+ import { Interceptor, InterceptContext, InterceptorContract } from '@athenna/http'
2
+
3
+ @Interceptor()
4
+ export class {{ namePascal }} implements InterceptorContract {
5
+ public async intercept(ctx: InterceptContext): Promise<unknown> {
6
+ return ctx.body
7
+ }
8
+ }
@@ -1,38 +1,6 @@
1
- export class {{ namePascal }} {
2
- /**
3
- * Resolve any dependency of the service container
4
- * inside the constructor.
5
- */
6
- constructor() {}
1
+ import { Context, Middleware, MiddlewareContract } from '@athenna/http'
7
2
 
8
- /**
9
- * Handle method is executed before the request gets
10
- * in your controller.
11
- *
12
- * @param {import('@athenna/http').HandleContextContract} ctx
13
- * @return {Promise<void>}
14
- */
15
- async handle(ctx) {}
16
-
17
- /**
18
- * Intercept method is executed before the response
19
- * has been sent.
20
- *
21
- * @param {import('@athenna/http').InterceptContextContract} ctx
22
- * @return {Promise<any>}
23
- */
24
- async intercept({ body }) {
25
- body.intercepted = true
26
-
27
- return body
28
- }
29
-
30
- /**
31
- * Terminate method is executed after the response
32
- * has been sent.
33
- *
34
- * @param {import('@athenna/http').TerminateContextContract} ctx
35
- * @return {Promise<void>}
36
- */
37
- async terminate(ctx) {}
3
+ @Middleware()
4
+ export class {{ namePascal }} implements MiddlewareContract {
5
+ public async handle(ctx: Context): Promise<void> {}
38
6
  }
@@ -0,0 +1,6 @@
1
+ import { Terminator, TerminateContext, TerminatorContract } from '@athenna/http'
2
+
3
+ @Terminator()
4
+ export class {{ namePascal }} implements TerminatorContract {
5
+ public async terminate(ctx: TerminateContext): Promise<void> {}
6
+ }
@@ -1,64 +0,0 @@
1
- /**
2
- * @athenna/http
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Path } from '@athenna/common'
11
- import { Command } from '@athenna/artisan'
12
-
13
- export class MakeController extends Command {
14
- /**
15
- * The name and signature of the console command.
16
- *
17
- * @return {string}
18
- */
19
- get signature() {
20
- return 'make:controller <name>'
21
- }
22
-
23
- /**
24
- * The console command description.
25
- *
26
- * @return {string}
27
- */
28
- get description() {
29
- return 'Make a new controller file.'
30
- }
31
-
32
- /**
33
- * Set additional flags in the commander instance.
34
- * This method is executed when registering your command.
35
- *
36
- * @param {import('@athenna/artisan').Commander} commander
37
- * @return {import('@athenna/artisan').Commander}
38
- */
39
- addFlags(commander) {
40
- return commander.option(
41
- '--no-lint',
42
- 'Do not run eslint in the controller.',
43
- true,
44
- )
45
- }
46
-
47
- /**
48
- * Execute the console command.
49
- *
50
- * @param {string} name
51
- * @param {any} options
52
- * @return {Promise<void>}
53
- */
54
- async handle(name, options) {
55
- const resource = 'Controller'
56
- const path = Path.http(`Controllers/${name}.${Path.ext()}`)
57
-
58
- this.title(`MAKING ${resource}\n`, 'bold', 'green')
59
-
60
- const file = await this.makeFile(path, 'controller', options.lint)
61
-
62
- this.success(`${resource} ({yellow} "${file.name}") successfully created.`)
63
- }
64
- }
@@ -1,80 +0,0 @@
1
- /**
2
- * @athenna/http
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Path, String } from '@athenna/common'
11
- import { Artisan, Command, FilePropertiesHelper } from '@athenna/artisan'
12
-
13
- export class MakeMiddleware extends Command {
14
- /**
15
- * The name and signature of the console command.
16
- *
17
- * @return {string}
18
- */
19
- get signature() {
20
- return 'make:middleware <name>'
21
- }
22
-
23
- /**
24
- * The console command description.
25
- *
26
- * @return {string}
27
- */
28
- get description() {
29
- return 'Make a new middleware file.'
30
- }
31
-
32
- /**
33
- * Set additional flags in the commander instance.
34
- * This method is executed when registering your command.
35
- *
36
- * @param {import('@athenna/artisan').Commander} commander
37
- * @return {import('@athenna/artisan').Commander}
38
- */
39
- addFlags(commander) {
40
- return commander
41
- .option(
42
- '--no-register',
43
- 'Do not register the middleware inside Kernel.',
44
- true,
45
- )
46
- .option('--no-lint', 'Do not run eslint in the middleware.', true)
47
- }
48
-
49
- /**
50
- * Execute the console command.
51
- *
52
- * @param {string} name
53
- * @param {any} options
54
- * @return {Promise<void>}
55
- */
56
- async handle(name, options) {
57
- const resource = 'Middleware'
58
- const path = Path.http(`Middlewares/${name}.${Path.ext()}`)
59
-
60
- this.title(`MAKING ${resource}\n`, 'bold', 'green')
61
-
62
- const file = await this.makeFile(path, 'middleware', options.lint)
63
-
64
- this.success(`${resource} ({yellow} "${file.name}") successfully created.`)
65
-
66
- if (options.register) {
67
- const path = Path.http(`Kernel.${Path.ext()}`)
68
-
69
- await FilePropertiesHelper.addContentToObjectGetter(
70
- path,
71
- 'namedMiddlewares',
72
- `${String.toCamelCase(
73
- file.name,
74
- )}: import('#app/Http/Middlewares/${name}')`,
75
- )
76
-
77
- await Artisan.call(`eslint:fix ${path} --quiet`)
78
- }
79
- }
80
- }