@athenna/http 1.3.3 → 1.3.6

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 (95) hide show
  1. package/LICENSE.md +3 -15
  2. package/README.md +8 -5
  3. package/package.json +95 -106
  4. package/src/Context/Request.js +168 -137
  5. package/src/Context/Response.js +102 -94
  6. package/src/Exceptions/UndefinedMethodException.js +30 -0
  7. package/src/Facades/Route.js +7 -5
  8. package/src/Facades/Server.js +7 -5
  9. package/src/Handlers/FastifyHandler.js +134 -115
  10. package/src/Handlers/HttpExceptionHandler.js +72 -68
  11. package/src/Kernels/HttpKernel.js +142 -124
  12. package/src/Providers/ControllerProvider.js +30 -39
  13. package/src/Providers/HttpRouteProvider.js +15 -16
  14. package/src/Providers/HttpServerProvider.js +13 -15
  15. package/src/Providers/MiddlewareProvider.js +30 -39
  16. package/src/Router/Route.js +192 -99
  17. package/src/Router/RouteGroup.js +66 -40
  18. package/src/Router/RouteResource.js +156 -74
  19. package/src/Router/Router.js +284 -112
  20. package/src/Utils/isMiddlewareContract.js +8 -6
  21. package/src/Utils/removeSlashes.js +21 -0
  22. package/src/index.d.ts +658 -0
  23. package/src/index.js +284 -0
  24. package/index.d.ts +0 -29
  25. package/index.js +0 -41
  26. package/src/Context/Request.d.ts +0 -103
  27. package/src/Context/Response.d.ts +0 -77
  28. package/src/Contracts/Context/ContextContract.d.ts +0 -17
  29. package/src/Contracts/Context/ContextContract.js +0 -10
  30. package/src/Contracts/Context/Error/ErrorContextContract.d.ts +0 -18
  31. package/src/Contracts/Context/Error/ErrorContextContract.js +0 -10
  32. package/src/Contracts/Context/Error/ErrorHandlerContract.d.ts +0 -12
  33. package/src/Contracts/Context/Error/ErrorHandlerContract.js +0 -10
  34. package/src/Contracts/Context/HandlerContract.d.ts +0 -12
  35. package/src/Contracts/Context/HandlerContract.js +0 -10
  36. package/src/Contracts/Context/Middlewares/Handle/HandleContextContract.d.ts +0 -19
  37. package/src/Contracts/Context/Middlewares/Handle/HandleContextContract.js +0 -10
  38. package/src/Contracts/Context/Middlewares/Handle/HandleHandlerContract.d.ts +0 -12
  39. package/src/Contracts/Context/Middlewares/Handle/HandleHandlerContract.js +0 -10
  40. package/src/Contracts/Context/Middlewares/Intercept/InterceptContextContract.d.ts +0 -19
  41. package/src/Contracts/Context/Middlewares/Intercept/InterceptContextContract.js +0 -10
  42. package/src/Contracts/Context/Middlewares/Intercept/InterceptHandlerContract.d.ts +0 -12
  43. package/src/Contracts/Context/Middlewares/Intercept/InterceptHandlerContract.js +0 -10
  44. package/src/Contracts/Context/Middlewares/Terminate/TerminateContextContract.d.ts +0 -23
  45. package/src/Contracts/Context/Middlewares/Terminate/TerminateContextContract.js +0 -10
  46. package/src/Contracts/Context/Middlewares/Terminate/TerminateHandlerContract.d.ts +0 -12
  47. package/src/Contracts/Context/Middlewares/Terminate/TerminateHandlerContract.js +0 -10
  48. package/src/Contracts/Context/NextContract.d.ts +0 -11
  49. package/src/Contracts/Context/NextContract.js +0 -10
  50. package/src/Contracts/Context/RequestContract.d.ts +0 -25
  51. package/src/Contracts/Context/RequestContract.js +0 -10
  52. package/src/Contracts/Context/ResponseContract.d.ts +0 -20
  53. package/src/Contracts/Context/ResponseContract.js +0 -2
  54. package/src/Contracts/FastifyErrorHandlerContract.d.ts +0 -12
  55. package/src/Contracts/FastifyErrorHandlerContract.js +0 -10
  56. package/src/Contracts/FastifyHandlerContract.d.ts +0 -12
  57. package/src/Contracts/FastifyHandlerContract.js +0 -10
  58. package/src/Contracts/HttpMethodTypes.d.ts +0 -9
  59. package/src/Contracts/HttpMethodTypes.js +0 -10
  60. package/src/Contracts/MiddlewareContract.d.ts +0 -16
  61. package/src/Contracts/MiddlewareContract.js +0 -10
  62. package/src/Contracts/MiddlewareTypes.d.ts +0 -9
  63. package/src/Contracts/MiddlewareTypes.js +0 -10
  64. package/src/Contracts/MiddlewareTypesContract.d.ts +0 -16
  65. package/src/Contracts/MiddlewareTypesContract.js +0 -10
  66. package/src/Contracts/RouteContract.d.ts +0 -16
  67. package/src/Contracts/RouteContract.js +0 -10
  68. package/src/Exceptions/BadRequestException.d.ts +0 -12
  69. package/src/Exceptions/BadRequestException.js +0 -18
  70. package/src/Exceptions/CannotDefineGroupException.d.ts +0 -12
  71. package/src/Exceptions/CannotDefineGroupException.js +0 -19
  72. package/src/Exceptions/MiddlewareNotFoundException.d.ts +0 -12
  73. package/src/Exceptions/MiddlewareNotFoundException.js +0 -19
  74. package/src/Exceptions/UndefinedControllerMethodException.d.ts +0 -12
  75. package/src/Exceptions/UndefinedControllerMethodException.js +0 -19
  76. package/src/Facades/Route.d.ts +0 -10
  77. package/src/Facades/Server.d.ts +0 -10
  78. package/src/Handlers/FastifyHandler.d.ts +0 -26
  79. package/src/Handlers/HttpExceptionHandler.d.ts +0 -27
  80. package/src/Http.d.ts +0 -167
  81. package/src/Http.js +0 -223
  82. package/src/Kernels/HttpKernel.d.ts +0 -54
  83. package/src/Providers/ControllerProvider.d.ts +0 -17
  84. package/src/Providers/HttpRouteProvider.d.ts +0 -17
  85. package/src/Providers/HttpServerProvider.d.ts +0 -17
  86. package/src/Providers/MiddlewareProvider.d.ts +0 -17
  87. package/src/Router/Route.d.ts +0 -32
  88. package/src/Router/RouteGroup.d.ts +0 -24
  89. package/src/Router/RouteResource.d.ts +0 -29
  90. package/src/Router/Router.d.ts +0 -39
  91. package/src/Utils/getAppFiles.d.ts +0 -10
  92. package/src/Utils/getAppFiles.js +0 -22
  93. package/src/Utils/isMiddlewareContract.d.ts +0 -10
  94. package/src/Utils/removeSlash.d.ts +0 -9
  95. package/src/Utils/removeSlash.js +0 -23
package/src/Http.d.ts DELETED
@@ -1,167 +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
- import LightMyRequest from 'light-my-request';
10
- import { FastifyCorsOptions } from 'fastify-cors';
11
- import { RateLimitPluginOptions } from 'fastify-rate-limit';
12
- import { FastifyInstance, FastifyPluginCallback, FastifyPluginOptions, FastifyRegisterOptions, InjectOptions, PrintRoutesOptions } from 'fastify';
13
- import { HttpMethodTypes } from './Contracts/HttpMethodTypes';
14
- import { HandlerContract } from './Contracts/Context/HandlerContract';
15
- import { MiddlewareTypesContract } from './Contracts/MiddlewareTypesContract';
16
- import { ErrorHandlerContract } from './Contracts/Context/Error/ErrorHandlerContract';
17
- import { HandleHandlerContract } from './Contracts/Context/Middlewares/Handle/HandleHandlerContract';
18
- import { InterceptHandlerContract } from './Contracts/Context/Middlewares/Intercept/InterceptHandlerContract';
19
- import { TerminateHandlerContract } from './Contracts/Context/Middlewares/Terminate/TerminateHandlerContract';
20
- export declare class Http {
21
- /**
22
- * Holds the fastify server instance.
23
- *
24
- * @private
25
- */
26
- private readonly server;
27
- /**
28
- * Instantiate Http class and fastify server.
29
- *
30
- * @return Http
31
- */
32
- constructor();
33
- /**
34
- * Set the fastify error handler.
35
- *
36
- * @return Http
37
- */
38
- setErrorHandler(handler: ErrorHandlerContract): void;
39
- /**
40
- * Register a new fastify plugin.
41
- *
42
- * @return FastifyInstance
43
- */
44
- register(plugin: FastifyPluginCallback<FastifyPluginOptions>, opts?: FastifyRegisterOptions<FastifyPluginOptions>): void;
45
- /**
46
- * Register the cors plugin to fastify server.
47
- */
48
- registerCors(opts?: FastifyCorsOptions): void;
49
- /**
50
- * Register the rateLimit plugin to fastify server.
51
- */
52
- registerRateLimit(opts?: RateLimitPluginOptions): void;
53
- /**
54
- * Get the fastify server instance.
55
- *
56
- * @return FastifyInstance
57
- */
58
- getServer(): FastifyInstance;
59
- /**
60
- * Print all routes registered
61
- *
62
- * @param options {PrintRoutesOptions}
63
- * @return string
64
- */
65
- getRoutes(options?: PrintRoutesOptions): string;
66
- /**
67
- * Print all routes registered.
68
- *
69
- * @param handler {HandleHandlerContract,InterceptHandlerContract,TerminateHandlerContract}
70
- * @param type {handle,intercept,terminate}
71
- * @return void
72
- */
73
- use(handler: HandleHandlerContract): any;
74
- use(handler: HandleHandlerContract, type: 'handle'): any;
75
- use(handler: InterceptHandlerContract, type: 'intercept'): any;
76
- use(handler: TerminateHandlerContract, type: 'terminate'): any;
77
- request(): LightMyRequest.Chain;
78
- request(options: InjectOptions | string): Promise<LightMyRequest.Response>;
79
- /**
80
- * Boot the http server to start listening on port and host defined.
81
- *
82
- * @param port {string,number}
83
- * @param host {string}
84
- * @return void
85
- */
86
- listen(port?: string | number, host?: string): Promise<string>;
87
- /**
88
- * Close the http server.
89
- *
90
- * @param cb {any}
91
- * @return Promise<void>
92
- */
93
- close(cb?: any): Promise<void>;
94
- /**
95
- * Add a new route to the http server.
96
- *
97
- * @param url {string}
98
- * @param methods {HttpMethodTypes[]}
99
- * @param handler {HandlerContract}
100
- * @param middlewares {MiddlewareTypesContract}
101
- * @return void
102
- */
103
- route(url: string, methods: HttpMethodTypes[], handler: HandlerContract, middlewares?: MiddlewareTypesContract): void;
104
- /**
105
- * Add a new GET route to the http server.
106
- *
107
- * @param url {string}
108
- * @param handler {HandlerContract}
109
- * @param middlewares {MiddlewareTypesContract}
110
- * @return void
111
- */
112
- get(url: string, handler: HandlerContract, middlewares?: MiddlewareTypesContract): void;
113
- /**
114
- * Add a new HEAD route to the http server.
115
- *
116
- * @param url {string}
117
- * @param handler {HandlerContract}
118
- * @param middlewares {MiddlewareTypesContract}
119
- * @return void
120
- */
121
- head(url: string, handler: HandlerContract, middlewares?: MiddlewareTypesContract): void;
122
- /**
123
- * Add a new POST route to the http server.
124
- *
125
- * @param url {string}
126
- * @param handler {HandlerContract}
127
- * @param middlewares {MiddlewareTypesContract}
128
- * @return void
129
- */
130
- post(url: string, handler: HandlerContract, middlewares?: MiddlewareTypesContract): void;
131
- /**
132
- * Add a new PUT route to the http server.
133
- *
134
- * @param url {string}
135
- * @param handler {HandlerContract}
136
- * @param middlewares {MiddlewareTypesContract}
137
- * @return void
138
- */
139
- put(url: string, handler: HandlerContract, middlewares?: MiddlewareTypesContract): void;
140
- /**
141
- * Add a new PATCH route to the http server.
142
- *
143
- * @param url {string}
144
- * @param handler {HandlerContract}
145
- * @param middlewares {MiddlewareTypesContract}
146
- * @return void
147
- */
148
- patch(url: string, handler: HandlerContract, middlewares?: MiddlewareTypesContract): void;
149
- /**
150
- * Add a new DELETE route to the http server.
151
- *
152
- * @param url {string}
153
- * @param handler {HandlerContract}
154
- * @param middlewares {MiddlewareTypesContract}
155
- * @return void
156
- */
157
- delete(url: string, handler: HandlerContract, middlewares?: MiddlewareTypesContract): void;
158
- /**
159
- * Add a new OPTIONS route to the http server.
160
- *
161
- * @param url {string}
162
- * @param handler {HandlerContract}
163
- * @param middlewares {MiddlewareTypesContract}
164
- * @return void
165
- */
166
- options(url: string, handler: HandlerContract, middlewares?: MiddlewareTypesContract): void;
167
- }
package/src/Http.js DELETED
@@ -1,223 +0,0 @@
1
- "use strict";
2
- /**
3
- * @athenna/http
4
- *
5
- * (c) João Lenon <lenon@athenna.io>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- var __importDefault = (this && this.__importDefault) || function (mod) {
11
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.Http = void 0;
15
- const fastify_cors_1 = __importDefault(require("fastify-cors"));
16
- const fastify_rate_limit_1 = __importDefault(require("fastify-rate-limit"));
17
- const fastify_1 = __importDefault(require("fastify"));
18
- const FastifyHandler_1 = require("./Handlers/FastifyHandler");
19
- class Http {
20
- /**
21
- * Instantiate Http class and fastify server.
22
- *
23
- * @return Http
24
- */
25
- constructor() {
26
- this.server = fastify_1.default();
27
- }
28
- /**
29
- * Set the fastify error handler.
30
- *
31
- * @return Http
32
- */
33
- setErrorHandler(handler) {
34
- const fastifyErrorHandler = FastifyHandler_1.FastifyHandler.createErrorHandler(handler);
35
- this.server.setErrorHandler(fastifyErrorHandler);
36
- }
37
- /**
38
- * Register a new fastify plugin.
39
- *
40
- * @return FastifyInstance
41
- */
42
- register(plugin, opts) {
43
- this.server.register(plugin, opts);
44
- }
45
- /**
46
- * Register the cors plugin to fastify server.
47
- */
48
- registerCors(opts) {
49
- this.register(fastify_cors_1.default, opts);
50
- }
51
- /**
52
- * Register the rateLimit plugin to fastify server.
53
- */
54
- registerRateLimit(opts) {
55
- this.register(fastify_rate_limit_1.default, opts);
56
- }
57
- /**
58
- * Get the fastify server instance.
59
- *
60
- * @return FastifyInstance
61
- */
62
- getServer() {
63
- return this.server;
64
- }
65
- /**
66
- * Print all routes registered
67
- *
68
- * @param options {PrintRoutesOptions}
69
- * @return string
70
- */
71
- getRoutes(options) {
72
- return this.server.printRoutes(options);
73
- }
74
- use(handler, type = 'handle') {
75
- let hookName = 'preHandler';
76
- let handlerType = 'createDoneHandler';
77
- switch (type) {
78
- case 'intercept':
79
- hookName = 'onSend';
80
- handlerType = 'createOnSendHandler';
81
- break;
82
- case 'terminate':
83
- hookName = 'onResponse';
84
- handlerType = 'createResponseHandler';
85
- break;
86
- }
87
- this.server.addHook(hookName, FastifyHandler_1.FastifyHandler[handlerType](handler));
88
- }
89
- /**
90
- * Return a request handler to make internal requests to the Http server.
91
- *
92
- * @param options {InjectOptions,string}
93
- * @return {LightMyRequest.Chain,Promise<LightMyRequest.Response>}
94
- */
95
- request(options) {
96
- const server = this.getServer();
97
- if (!options) {
98
- return server.inject();
99
- }
100
- return server.inject(options);
101
- }
102
- /**
103
- * Boot the http server to start listening on port and host defined.
104
- *
105
- * @param port {string,number}
106
- * @param host {string}
107
- * @return void
108
- */
109
- async listen(port, host) {
110
- return this.server.listen(port || 1335, host || 'localhost');
111
- }
112
- /**
113
- * Close the http server.
114
- *
115
- * @param cb {any}
116
- * @return Promise<void>
117
- */
118
- // eslint-disable-next-line @typescript-eslint/no-empty-function
119
- async close(cb) {
120
- if (cb) {
121
- return this.server.close(cb);
122
- }
123
- return this.server.close();
124
- }
125
- /**
126
- * Add a new route to the http server.
127
- *
128
- * @param url {string}
129
- * @param methods {HttpMethodTypes[]}
130
- * @param handler {HandlerContract}
131
- * @param middlewares {MiddlewareTypesContract}
132
- * @return void
133
- */
134
- route(url, methods, handler, middlewares) {
135
- const { handlers, terminators, interceptors } = Object.assign({}, { handlers: [], terminators: [], interceptors: [] }, middlewares);
136
- this.server.route({
137
- url,
138
- method: methods,
139
- handler: FastifyHandler_1.FastifyHandler.createRequestHandler(handler),
140
- preHandler: handlers.map(m => FastifyHandler_1.FastifyHandler.createDoneHandler(m)),
141
- onResponse: terminators.map(m => FastifyHandler_1.FastifyHandler.createResponseHandler(m)),
142
- onSend: interceptors.map(m => FastifyHandler_1.FastifyHandler.createOnSendHandler(m)),
143
- });
144
- }
145
- /**
146
- * Add a new GET route to the http server.
147
- *
148
- * @param url {string}
149
- * @param handler {HandlerContract}
150
- * @param middlewares {MiddlewareTypesContract}
151
- * @return void
152
- */
153
- get(url, handler, middlewares) {
154
- this.route(url, ['GET'], handler, middlewares);
155
- }
156
- /**
157
- * Add a new HEAD route to the http server.
158
- *
159
- * @param url {string}
160
- * @param handler {HandlerContract}
161
- * @param middlewares {MiddlewareTypesContract}
162
- * @return void
163
- */
164
- head(url, handler, middlewares) {
165
- this.route(url, ['HEAD'], handler, middlewares);
166
- }
167
- /**
168
- * Add a new POST route to the http server.
169
- *
170
- * @param url {string}
171
- * @param handler {HandlerContract}
172
- * @param middlewares {MiddlewareTypesContract}
173
- * @return void
174
- */
175
- post(url, handler, middlewares) {
176
- this.route(url, ['POST'], handler, middlewares);
177
- }
178
- /**
179
- * Add a new PUT route to the http server.
180
- *
181
- * @param url {string}
182
- * @param handler {HandlerContract}
183
- * @param middlewares {MiddlewareTypesContract}
184
- * @return void
185
- */
186
- put(url, handler, middlewares) {
187
- this.route(url, ['PUT'], handler, middlewares);
188
- }
189
- /**
190
- * Add a new PATCH route to the http server.
191
- *
192
- * @param url {string}
193
- * @param handler {HandlerContract}
194
- * @param middlewares {MiddlewareTypesContract}
195
- * @return void
196
- */
197
- patch(url, handler, middlewares) {
198
- this.route(url, ['PATCH'], handler, middlewares);
199
- }
200
- /**
201
- * Add a new DELETE route to the http server.
202
- *
203
- * @param url {string}
204
- * @param handler {HandlerContract}
205
- * @param middlewares {MiddlewareTypesContract}
206
- * @return void
207
- */
208
- delete(url, handler, middlewares) {
209
- this.route(url, ['DELETE'], handler, middlewares);
210
- }
211
- /**
212
- * Add a new OPTIONS route to the http server.
213
- *
214
- * @param url {string}
215
- * @param handler {HandlerContract}
216
- * @param middlewares {MiddlewareTypesContract}
217
- * @return void
218
- */
219
- options(url, handler, middlewares) {
220
- this.route(url, ['OPTIONS'], handler, middlewares);
221
- }
222
- }
223
- exports.Http = Http;
@@ -1,54 +0,0 @@
1
- import { MiddlewareContract } from '../Contracts/MiddlewareContract';
2
- export declare type MiddlewareContractClass = {
3
- new (container?: any): MiddlewareContract;
4
- };
5
- export declare abstract class HttpKernel {
6
- /**
7
- * The application's global HTTP middlewares.
8
- *
9
- * This middlewares are run during every request to your http server.
10
- */
11
- protected abstract globalMiddlewares: MiddlewareContractClass[] | Promise<any>[];
12
- /**
13
- * The application's named HTTP middlewares.
14
- *
15
- * Here you define all your named middlewares to use inside routes/http file.
16
- */
17
- protected abstract namedMiddlewares: Record<string, Promise<any> | MiddlewareContractClass>;
18
- /**
19
- * Register all global and named middlewares to the server.
20
- *
21
- * @return void
22
- */
23
- registerMiddlewares(): Promise<void>;
24
- /**
25
- * Register cors plugin
26
- *
27
- * @return void
28
- */
29
- registerCors(): Promise<void>;
30
- /**
31
- * Register rate limit plugin
32
- *
33
- * @return void
34
- */
35
- registerRateLimit(): Promise<void>;
36
- /**
37
- * Register the default error handler
38
- *
39
- * @return void
40
- */
41
- registerErrorHandler(): Promise<void>;
42
- /**
43
- * Register log terminate middleware
44
- *
45
- * @return void
46
- */
47
- registerLogMiddleware(): Promise<void>;
48
- /**
49
- * Register the requestId handle middleware.
50
- *
51
- * @return void
52
- */
53
- registerRequestIdMiddleware(): Promise<void>;
54
- }
@@ -1,17 +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
- import { ServiceProvider } from '@athenna/ioc';
10
- export declare class ControllerProvider extends ServiceProvider {
11
- /**
12
- * Bootstrap any application services.
13
- *
14
- * @return void
15
- */
16
- boot(): Promise<void>;
17
- }
@@ -1,17 +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
- import { ServiceProvider } from '@athenna/ioc';
10
- export declare class HttpRouteProvider extends ServiceProvider {
11
- /**
12
- * Bootstrap any application services.
13
- *
14
- * @return void
15
- */
16
- boot(): void;
17
- }
@@ -1,17 +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
- import { ServiceProvider } from '@athenna/ioc';
10
- export declare class HttpServerProvider extends ServiceProvider {
11
- /**
12
- * Register any application services.
13
- *
14
- * @return void
15
- */
16
- register(): void;
17
- }
@@ -1,17 +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
- import { ServiceProvider } from '@athenna/ioc';
10
- export declare class MiddlewareProvider extends ServiceProvider {
11
- /**
12
- * Bootstrap any application services.
13
- *
14
- * @return void
15
- */
16
- boot(): Promise<void>;
17
- }
@@ -1,32 +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
- import '@athenna/ioc';
10
- import { MiddlewareTypes } from '../Contracts/MiddlewareTypes';
11
- import { HttpMethodTypes } from '../Contracts/HttpMethodTypes';
12
- import { MiddlewareContract } from '../Contracts/MiddlewareContract';
13
- import { HandlerContract } from '../Contracts/Context/HandlerContract';
14
- import { InterceptHandlerContract } from '../Contracts/Context/Middlewares/Intercept/InterceptHandlerContract';
15
- import { TerminateHandlerContract } from '../Contracts/Context/Middlewares/Terminate/TerminateHandlerContract';
16
- export declare class Route {
17
- name: string;
18
- deleted: boolean;
19
- private readonly url;
20
- private readonly handler;
21
- private readonly methods;
22
- private routeMiddlewares;
23
- private routeNamespace;
24
- private prefixes;
25
- constructor(url: string, methods: HttpMethodTypes[], handler: HandlerContract | string);
26
- prefix(prefix: any): this;
27
- as(name: string, prepend?: boolean): this;
28
- namespace(namespace: string, overwrite?: boolean): this;
29
- middleware(middleware: HandlerContract | MiddlewareContract | InterceptHandlerContract | TerminateHandlerContract | string, type?: MiddlewareTypes, prepend?: boolean): this;
30
- toJSON(): any;
31
- private getUrl;
32
- }
@@ -1,24 +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
- import { Route } from './Route';
10
- import { RouteResource } from './RouteResource';
11
- import { MiddlewareTypes } from '../Contracts/MiddlewareTypes';
12
- import { MiddlewareContract } from '../Contracts/MiddlewareContract';
13
- import { HandlerContract } from '../Contracts/Context/HandlerContract';
14
- import { InterceptHandlerContract } from '../Contracts/Context/Middlewares/Intercept/InterceptHandlerContract';
15
- import { TerminateHandlerContract } from '../Contracts/Context/Middlewares/Terminate/TerminateHandlerContract';
16
- export declare class RouteGroup {
17
- routes: (Route | RouteResource | RouteGroup)[];
18
- constructor(routes: (Route | RouteResource | RouteGroup)[]);
19
- prefix(prefix: string): this;
20
- as(name: string): this;
21
- namespace(namespace: string): this;
22
- middleware(middleware: HandlerContract | MiddlewareContract | InterceptHandlerContract | TerminateHandlerContract | string, type?: MiddlewareTypes, prepend?: boolean): this;
23
- private invoke;
24
- }
@@ -1,29 +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
- import { Route } from './Route';
10
- import { MiddlewareTypes } from '../Contracts/MiddlewareTypes';
11
- import { MiddlewareContract } from '../Contracts/MiddlewareContract';
12
- import { HandlerContract } from '../Contracts/Context/HandlerContract';
13
- import { InterceptHandlerContract } from '../Contracts/Context/Middlewares/Intercept/InterceptHandlerContract';
14
- import { TerminateHandlerContract } from '../Contracts/Context/Middlewares/Terminate/TerminateHandlerContract';
15
- export declare class RouteResource {
16
- routes: Route[];
17
- private resource;
18
- private readonly controller;
19
- private resourceName;
20
- constructor(resource: string, controller: any);
21
- middleware(middleware: HandlerContract | MiddlewareContract | InterceptHandlerContract | TerminateHandlerContract | string, type?: MiddlewareTypes): this;
22
- only(names: string[]): this;
23
- except(names: string[]): this;
24
- namespace(namespace: string): this;
25
- as(name: string): this;
26
- private makeRoute;
27
- private buildRoutes;
28
- private filter;
29
- }
@@ -1,39 +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
- import '@athenna/ioc';
10
- import { Http } from '../Http';
11
- import { Route } from './Route';
12
- import { RouteGroup } from './RouteGroup';
13
- import { RouteResource } from './RouteResource';
14
- import { HttpMethodTypes } from '../Contracts/HttpMethodTypes';
15
- import { HandlerContract } from '../Contracts/Context/HandlerContract';
16
- export declare class Router {
17
- routes: (Route | RouteResource | RouteGroup)[];
18
- private readonly openedGroups;
19
- private readonly http;
20
- private controllerInstance;
21
- constructor(http: Http);
22
- listRoutes(): any;
23
- controller(controller: any): this;
24
- route(url: string, methods: HttpMethodTypes[], handler: HandlerContract | string): Route;
25
- group(callback: () => void): RouteGroup;
26
- resource(resource: string, controller: any): RouteResource;
27
- redirect(url: string, redirectTo: string, status?: number): Route;
28
- get(url: string, handler: HandlerContract | string): Route;
29
- head(url: string, handler: HandlerContract | string): Route;
30
- post(url: string, handler: HandlerContract | string): Route;
31
- put(url: string, handler: HandlerContract | string): Route;
32
- patch(url: string, handler: HandlerContract | string): Route;
33
- delete(url: string, handler: HandlerContract | string): Route;
34
- options(url: string, handler: HandlerContract | string): Route;
35
- any(url: string, handler: HandlerContract | string): Route;
36
- register(): void;
37
- toRoutesJSON(routes?: any): any;
38
- private getRecentGroup;
39
- }
@@ -1,10 +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
- import { File } from '@secjs/utils';
10
- export declare function getAppFiles(path: string): File[];
@@ -1,22 +0,0 @@
1
- "use strict";
2
- /**
3
- * @athenna/http
4
- *
5
- * (c) João Lenon <lenon@athenna.io>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.getAppFiles = void 0;
12
- const fs_1 = require("fs");
13
- const utils_1 = require("@secjs/utils");
14
- function getAppFiles(path) {
15
- if (!fs_1.existsSync(path))
16
- return [];
17
- return (new utils_1.Folder(path)
18
- .loadSync()
19
- // Get all .js and .ts files but not the .d.ts.
20
- .getFilesByPattern('!(*.d)*.*(js|ts)'));
21
- }
22
- exports.getAppFiles = getAppFiles;
@@ -1,10 +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
- import { MiddlewareContract } from '../Contracts/MiddlewareContract';
10
- export declare function isMiddlewareContract(object: any): object is MiddlewareContract;