@athenna/http 1.3.1 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +3 -15
- package/README.md +8 -5
- package/package.json +95 -106
- package/src/Context/Request.js +168 -137
- package/src/Context/Response.js +102 -94
- package/src/Exceptions/UndefinedMethodException.js +30 -0
- package/src/Facades/Route.js +7 -5
- package/src/Facades/Server.js +7 -5
- package/src/Handlers/FastifyHandler.js +134 -115
- package/src/Handlers/HttpExceptionHandler.js +71 -68
- package/src/Kernels/HttpKernel.js +142 -124
- package/src/Providers/ControllerProvider.js +30 -39
- package/src/Providers/HttpRouteProvider.js +15 -16
- package/src/Providers/HttpServerProvider.js +13 -15
- package/src/Providers/MiddlewareProvider.js +30 -39
- package/src/Router/Route.js +192 -99
- package/src/Router/RouteGroup.js +66 -40
- package/src/Router/RouteResource.js +156 -74
- package/src/Router/Router.js +284 -112
- package/src/Utils/isMiddlewareContract.js +8 -6
- package/src/Utils/removeSlashes.js +21 -0
- package/src/index.d.ts +658 -0
- package/src/index.js +284 -0
- package/index.d.ts +0 -30
- package/index.js +0 -42
- package/src/Context/Request.d.ts +0 -103
- package/src/Context/Response.d.ts +0 -77
- package/src/Contracts/Context/ContextContract.d.ts +0 -17
- package/src/Contracts/Context/ContextContract.js +0 -10
- package/src/Contracts/Context/Error/ErrorContextContract.d.ts +0 -18
- package/src/Contracts/Context/Error/ErrorContextContract.js +0 -10
- package/src/Contracts/Context/Error/ErrorHandlerContract.d.ts +0 -12
- package/src/Contracts/Context/Error/ErrorHandlerContract.js +0 -10
- package/src/Contracts/Context/HandlerContract.d.ts +0 -12
- package/src/Contracts/Context/HandlerContract.js +0 -10
- package/src/Contracts/Context/Middlewares/Handle/HandleContextContract.d.ts +0 -19
- package/src/Contracts/Context/Middlewares/Handle/HandleContextContract.js +0 -10
- package/src/Contracts/Context/Middlewares/Handle/HandleHandlerContract.d.ts +0 -12
- package/src/Contracts/Context/Middlewares/Handle/HandleHandlerContract.js +0 -10
- package/src/Contracts/Context/Middlewares/Intercept/InterceptContextContract.d.ts +0 -19
- package/src/Contracts/Context/Middlewares/Intercept/InterceptContextContract.js +0 -10
- package/src/Contracts/Context/Middlewares/Intercept/InterceptHandlerContract.d.ts +0 -12
- package/src/Contracts/Context/Middlewares/Intercept/InterceptHandlerContract.js +0 -10
- package/src/Contracts/Context/Middlewares/Terminate/TerminateContextContract.d.ts +0 -23
- package/src/Contracts/Context/Middlewares/Terminate/TerminateContextContract.js +0 -10
- package/src/Contracts/Context/Middlewares/Terminate/TerminateHandlerContract.d.ts +0 -12
- package/src/Contracts/Context/Middlewares/Terminate/TerminateHandlerContract.js +0 -10
- package/src/Contracts/Context/NextContract.d.ts +0 -11
- package/src/Contracts/Context/NextContract.js +0 -10
- package/src/Contracts/Context/RequestContract.d.ts +0 -25
- package/src/Contracts/Context/RequestContract.js +0 -10
- package/src/Contracts/Context/ResponseContract.d.ts +0 -20
- package/src/Contracts/Context/ResponseContract.js +0 -2
- package/src/Contracts/FastifyErrorHandlerContract.d.ts +0 -12
- package/src/Contracts/FastifyErrorHandlerContract.js +0 -10
- package/src/Contracts/FastifyHandlerContract.d.ts +0 -12
- package/src/Contracts/FastifyHandlerContract.js +0 -10
- package/src/Contracts/HttpMethodTypes.d.ts +0 -9
- package/src/Contracts/HttpMethodTypes.js +0 -10
- package/src/Contracts/MiddlewareContract.d.ts +0 -16
- package/src/Contracts/MiddlewareContract.js +0 -10
- package/src/Contracts/MiddlewareTypes.d.ts +0 -9
- package/src/Contracts/MiddlewareTypes.js +0 -10
- package/src/Contracts/MiddlewareTypesContract.d.ts +0 -16
- package/src/Contracts/MiddlewareTypesContract.js +0 -10
- package/src/Contracts/RouteContract.d.ts +0 -16
- package/src/Contracts/RouteContract.js +0 -10
- package/src/Exceptions/BadRequestException.d.ts +0 -12
- package/src/Exceptions/BadRequestException.js +0 -18
- package/src/Exceptions/CannotDefineGroupException.d.ts +0 -12
- package/src/Exceptions/CannotDefineGroupException.js +0 -19
- package/src/Exceptions/Exception.d.ts +0 -12
- package/src/Exceptions/Exception.js +0 -18
- package/src/Exceptions/MiddlewareNotFoundException.d.ts +0 -12
- package/src/Exceptions/MiddlewareNotFoundException.js +0 -19
- package/src/Exceptions/UndefinedControllerMethodException.d.ts +0 -12
- package/src/Exceptions/UndefinedControllerMethodException.js +0 -19
- package/src/Facades/Route.d.ts +0 -10
- package/src/Facades/Server.d.ts +0 -10
- package/src/Handlers/FastifyHandler.d.ts +0 -26
- package/src/Handlers/HttpExceptionHandler.d.ts +0 -27
- package/src/Http.d.ts +0 -167
- package/src/Http.js +0 -223
- package/src/Kernels/HttpKernel.d.ts +0 -54
- package/src/Providers/ControllerProvider.d.ts +0 -17
- package/src/Providers/HttpRouteProvider.d.ts +0 -17
- package/src/Providers/HttpServerProvider.d.ts +0 -17
- package/src/Providers/MiddlewareProvider.d.ts +0 -17
- package/src/Router/Route.d.ts +0 -32
- package/src/Router/RouteGroup.d.ts +0 -24
- package/src/Router/RouteResource.d.ts +0 -29
- package/src/Router/Router.d.ts +0 -39
- package/src/Utils/getAppFiles.d.ts +0 -10
- package/src/Utils/getAppFiles.js +0 -22
- package/src/Utils/isMiddlewareContract.d.ts +0 -10
- package/src/Utils/removeSlash.d.ts +0 -9
- package/src/Utils/removeSlash.js +0 -23
package/src/index.js
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
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 { Options } from '@secjs/utils'
|
|
11
|
+
|
|
12
|
+
import fastify from 'fastify'
|
|
13
|
+
import fastifyCors from 'fastify-cors'
|
|
14
|
+
import fastifyRateLimit from 'fastify-rate-limit'
|
|
15
|
+
import { FastifyHandler } from '#src/Handlers/FastifyHandler'
|
|
16
|
+
|
|
17
|
+
export * from './Facades/Route.js'
|
|
18
|
+
export * from './Facades/Server.js'
|
|
19
|
+
export * from './Kernels/HttpKernel.js'
|
|
20
|
+
export * from './Handlers/HttpExceptionHandler.js'
|
|
21
|
+
|
|
22
|
+
export class Http {
|
|
23
|
+
/**
|
|
24
|
+
* Holds the fastify server instance.
|
|
25
|
+
*
|
|
26
|
+
* @type {import('fastify').FastifyInstance}
|
|
27
|
+
*/
|
|
28
|
+
#server
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new instance of Http class.
|
|
32
|
+
*
|
|
33
|
+
* @return {Http}
|
|
34
|
+
*/
|
|
35
|
+
constructor() {
|
|
36
|
+
this.#server = fastify()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Set the fastify error handler.
|
|
41
|
+
*
|
|
42
|
+
* @param {any} handler
|
|
43
|
+
* @return {Http}
|
|
44
|
+
*/
|
|
45
|
+
setErrorHandler(handler) {
|
|
46
|
+
const fastifyErrorHandler = FastifyHandler.createErrorHandler(handler)
|
|
47
|
+
|
|
48
|
+
this.#server.setErrorHandler(fastifyErrorHandler)
|
|
49
|
+
|
|
50
|
+
return this
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Register a new fastify plugin.
|
|
55
|
+
*
|
|
56
|
+
* @param {import('fastify').FastifyPluginCallback<import('fastify').FastifyPluginOptions>} plugin
|
|
57
|
+
* @param {import('fastify').FastifyRegisterOptions<import('fastify').FastifyPluginOptions>} [options]
|
|
58
|
+
* @return {Http}
|
|
59
|
+
*/
|
|
60
|
+
register(plugin, options) {
|
|
61
|
+
this.#server.register(plugin, options)
|
|
62
|
+
|
|
63
|
+
return this
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Register the cors plugin to fastify server.
|
|
68
|
+
*
|
|
69
|
+
* @param {import('fastify-cors').FastifyCorsOptions} [options]
|
|
70
|
+
* @return {Http}
|
|
71
|
+
*/
|
|
72
|
+
registerCors(options) {
|
|
73
|
+
this.register(fastifyCors, options)
|
|
74
|
+
|
|
75
|
+
return this
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Register the rate limit plugin to fastify server.
|
|
80
|
+
*
|
|
81
|
+
* @param {import('fastify-rate-limit').RateLimitPluginOptions} [options]
|
|
82
|
+
* @return {Http}
|
|
83
|
+
*/
|
|
84
|
+
registerRateLimit(options) {
|
|
85
|
+
this.register(fastifyRateLimit, options)
|
|
86
|
+
|
|
87
|
+
return this
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the fastify server instance.
|
|
92
|
+
*
|
|
93
|
+
* @return {import('fastify').FastifyInstance}
|
|
94
|
+
*/
|
|
95
|
+
getFastify() {
|
|
96
|
+
return this.#server
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Print all routes registered.
|
|
101
|
+
*
|
|
102
|
+
* @param {import('fastify').PrintRoutesOptions} [options]
|
|
103
|
+
* @return {string}
|
|
104
|
+
*/
|
|
105
|
+
getRoutes(options) {
|
|
106
|
+
return this.#server.printRoutes(options)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Print all routes registered.
|
|
111
|
+
*
|
|
112
|
+
* @param {any} handler
|
|
113
|
+
* @param {'handle'|'intercept'|'terminate'} type
|
|
114
|
+
* @return void
|
|
115
|
+
*/
|
|
116
|
+
use(handler, type = 'handle') {
|
|
117
|
+
let hookName = 'preHandler'
|
|
118
|
+
let handlerType = 'createDoneHandler'
|
|
119
|
+
|
|
120
|
+
switch (type) {
|
|
121
|
+
case 'intercept':
|
|
122
|
+
hookName = 'onSend'
|
|
123
|
+
handlerType = 'createOnSendHandler'
|
|
124
|
+
break
|
|
125
|
+
case 'terminate':
|
|
126
|
+
hookName = 'onResponse'
|
|
127
|
+
handlerType = 'createOnResponseHandler'
|
|
128
|
+
break
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
this.#server.addHook(hookName, FastifyHandler[handlerType](handler))
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Return a request handler to make internal requests to the Http server.
|
|
136
|
+
*
|
|
137
|
+
* @param {import('fastify').InjectOptions|string} [options]
|
|
138
|
+
* @return {import('light-my-request').Chain,Promise<import('light-my-request').Response>}
|
|
139
|
+
*/
|
|
140
|
+
request(options) {
|
|
141
|
+
const server = this.getFastify()
|
|
142
|
+
|
|
143
|
+
if (!options) {
|
|
144
|
+
return server.inject()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return server.inject(options)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Boot the http server to start listening on port and host defined.
|
|
152
|
+
*
|
|
153
|
+
* @param {string|number} [port]
|
|
154
|
+
* @param {string} [host]
|
|
155
|
+
* @return {Promise<string>}
|
|
156
|
+
*/
|
|
157
|
+
async listen(port = 1335, host = '0.0.0.0') {
|
|
158
|
+
return this.#server.listen(port, host)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Close the http server.
|
|
163
|
+
*
|
|
164
|
+
* @return {Promise<void>}
|
|
165
|
+
*/
|
|
166
|
+
async close() {
|
|
167
|
+
return this.#server.close()
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Add a new route to the http server.
|
|
172
|
+
*
|
|
173
|
+
* @param {string} url
|
|
174
|
+
* @param {string[]} methods
|
|
175
|
+
* @param {any} handler
|
|
176
|
+
* @param {any} [middlewares]
|
|
177
|
+
* @return {void}
|
|
178
|
+
*/
|
|
179
|
+
route(url, methods, handler, middlewares) {
|
|
180
|
+
const { handlers, terminators, interceptors } = Options.create(
|
|
181
|
+
middlewares,
|
|
182
|
+
{
|
|
183
|
+
handlers: [],
|
|
184
|
+
terminators: [],
|
|
185
|
+
interceptors: [],
|
|
186
|
+
},
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
this.#server.route({
|
|
190
|
+
url,
|
|
191
|
+
method: methods,
|
|
192
|
+
onResponse: terminators.map(m =>
|
|
193
|
+
FastifyHandler.createOnResponseHandler(m),
|
|
194
|
+
),
|
|
195
|
+
handler: FastifyHandler.createRequestHandler(handler),
|
|
196
|
+
preHandler: handlers.map(m => FastifyHandler.createDoneHandler(m)),
|
|
197
|
+
onSend: interceptors.map(m => FastifyHandler.createOnSendHandler(m)),
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Add a new GET route to the http server.
|
|
203
|
+
*
|
|
204
|
+
* @param {string} url
|
|
205
|
+
* @param {any} handler
|
|
206
|
+
* @param {any} [middlewares]
|
|
207
|
+
* @return {void}
|
|
208
|
+
*/
|
|
209
|
+
get(url, handler, middlewares) {
|
|
210
|
+
this.route(url, ['GET'], handler, middlewares)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Add a new HEAD route to the http server.
|
|
215
|
+
*
|
|
216
|
+
* @param {string} url
|
|
217
|
+
* @param {any} handler
|
|
218
|
+
* @param {any} [middlewares]
|
|
219
|
+
* @return {void}
|
|
220
|
+
*/
|
|
221
|
+
head(url, handler, middlewares) {
|
|
222
|
+
this.route(url, ['HEAD'], handler, middlewares)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Add a new POST route to the http server.
|
|
227
|
+
*
|
|
228
|
+
* @param {string} url
|
|
229
|
+
* @param {any} handler
|
|
230
|
+
* @param {any} [middlewares]
|
|
231
|
+
* @return {void}
|
|
232
|
+
*/
|
|
233
|
+
post(url, handler, middlewares) {
|
|
234
|
+
this.route(url, ['POST'], handler, middlewares)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Add a new PUT route to the http server.
|
|
239
|
+
*
|
|
240
|
+
* @param {string} url
|
|
241
|
+
* @param {any} handler
|
|
242
|
+
* @param {any} [middlewares]
|
|
243
|
+
* @return {void}
|
|
244
|
+
*/
|
|
245
|
+
put(url, handler, middlewares) {
|
|
246
|
+
this.route(url, ['PUT'], handler, middlewares)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Add a new PATCH route to the http server.
|
|
251
|
+
*
|
|
252
|
+
* @param {string} url
|
|
253
|
+
* @param {any} handler
|
|
254
|
+
* @param {any} [middlewares]
|
|
255
|
+
* @return {void}
|
|
256
|
+
*/
|
|
257
|
+
patch(url, handler, middlewares) {
|
|
258
|
+
this.route(url, ['PATCH'], handler, middlewares)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Add a new DELETE route to the http server.
|
|
263
|
+
*
|
|
264
|
+
* @param {string} url
|
|
265
|
+
* @param {any} handler
|
|
266
|
+
* @param {any} [middlewares]
|
|
267
|
+
* @return {void}
|
|
268
|
+
*/
|
|
269
|
+
delete(url, handler, middlewares) {
|
|
270
|
+
this.route(url, ['DELETE'], handler, middlewares)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Add a new OPTIONS route to the http server.
|
|
275
|
+
*
|
|
276
|
+
* @param {string} url
|
|
277
|
+
* @param {any} handler
|
|
278
|
+
* @param {any} [middlewares]
|
|
279
|
+
* @return {void}
|
|
280
|
+
*/
|
|
281
|
+
options(url, handler, middlewares) {
|
|
282
|
+
this.route(url, ['OPTIONS'], handler, middlewares)
|
|
283
|
+
}
|
|
284
|
+
}
|
package/index.d.ts
DELETED
|
@@ -1,30 +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
|
-
export * from './src/Facades/Route';
|
|
10
|
-
export * from './src/Facades/Server';
|
|
11
|
-
export * from './src/Http';
|
|
12
|
-
export * from './src/Router/Router';
|
|
13
|
-
export * from './src/Kernels/HttpKernel';
|
|
14
|
-
export * from './src/Exceptions/Exception';
|
|
15
|
-
export * from './src/Providers/HttpRouteProvider';
|
|
16
|
-
export * from './src/Providers/HttpServerProvider';
|
|
17
|
-
export * from './src/Handlers/HttpExceptionHandler';
|
|
18
|
-
export * from './src/Contracts/MiddlewareContract';
|
|
19
|
-
export * from './src/Contracts/Context/ContextContract';
|
|
20
|
-
export * from './src/Contracts/Context/HandlerContract';
|
|
21
|
-
export * from './src/Contracts/Context/RequestContract';
|
|
22
|
-
export * from './src/Contracts/Context/ResponseContract';
|
|
23
|
-
export * from './src/Contracts/Context/Error/ErrorContextContract';
|
|
24
|
-
export * from './src/Contracts/Context/Error/ErrorHandlerContract';
|
|
25
|
-
export * from './src/Contracts/Context/Middlewares/Handle/HandleContextContract';
|
|
26
|
-
export * from './src/Contracts/Context/Middlewares/Handle/HandleHandlerContract';
|
|
27
|
-
export * from './src/Contracts/Context/Middlewares/Intercept/InterceptContextContract';
|
|
28
|
-
export * from './src/Contracts/Context/Middlewares/Intercept/InterceptHandlerContract';
|
|
29
|
-
export * from './src/Contracts/Context/Middlewares/Terminate/TerminateContextContract';
|
|
30
|
-
export * from './src/Contracts/Context/Middlewares/Terminate/TerminateHandlerContract';
|
package/index.js
DELETED
|
@@ -1,42 +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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
__exportStar(require("./src/Facades/Route"), exports);
|
|
22
|
-
__exportStar(require("./src/Facades/Server"), exports);
|
|
23
|
-
__exportStar(require("./src/Http"), exports);
|
|
24
|
-
__exportStar(require("./src/Router/Router"), exports);
|
|
25
|
-
__exportStar(require("./src/Kernels/HttpKernel"), exports);
|
|
26
|
-
__exportStar(require("./src/Exceptions/Exception"), exports);
|
|
27
|
-
__exportStar(require("./src/Providers/HttpRouteProvider"), exports);
|
|
28
|
-
__exportStar(require("./src/Providers/HttpServerProvider"), exports);
|
|
29
|
-
__exportStar(require("./src/Handlers/HttpExceptionHandler"), exports);
|
|
30
|
-
__exportStar(require("./src/Contracts/MiddlewareContract"), exports);
|
|
31
|
-
__exportStar(require("./src/Contracts/Context/ContextContract"), exports);
|
|
32
|
-
__exportStar(require("./src/Contracts/Context/HandlerContract"), exports);
|
|
33
|
-
__exportStar(require("./src/Contracts/Context/RequestContract"), exports);
|
|
34
|
-
__exportStar(require("./src/Contracts/Context/ResponseContract"), exports);
|
|
35
|
-
__exportStar(require("./src/Contracts/Context/Error/ErrorContextContract"), exports);
|
|
36
|
-
__exportStar(require("./src/Contracts/Context/Error/ErrorHandlerContract"), exports);
|
|
37
|
-
__exportStar(require("./src/Contracts/Context/Middlewares/Handle/HandleContextContract"), exports);
|
|
38
|
-
__exportStar(require("./src/Contracts/Context/Middlewares/Handle/HandleHandlerContract"), exports);
|
|
39
|
-
__exportStar(require("./src/Contracts/Context/Middlewares/Intercept/InterceptContextContract"), exports);
|
|
40
|
-
__exportStar(require("./src/Contracts/Context/Middlewares/Intercept/InterceptHandlerContract"), exports);
|
|
41
|
-
__exportStar(require("./src/Contracts/Context/Middlewares/Terminate/TerminateContextContract"), exports);
|
|
42
|
-
__exportStar(require("./src/Contracts/Context/Middlewares/Terminate/TerminateHandlerContract"), exports);
|
package/src/Context/Request.d.ts
DELETED
|
@@ -1,103 +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 { FastifyRequest } from 'fastify';
|
|
10
|
-
import { RequestContract } from '../Contracts/Context/RequestContract';
|
|
11
|
-
export declare class Request implements RequestContract {
|
|
12
|
-
private readonly request;
|
|
13
|
-
/**
|
|
14
|
-
* Create a new instance of Request.
|
|
15
|
-
*
|
|
16
|
-
* @return Request
|
|
17
|
-
*/
|
|
18
|
-
constructor(request: FastifyRequest);
|
|
19
|
-
/**
|
|
20
|
-
* Get the request ip.
|
|
21
|
-
*
|
|
22
|
-
* @return string
|
|
23
|
-
*/
|
|
24
|
-
get ip(): string;
|
|
25
|
-
/**
|
|
26
|
-
* Get the request method.
|
|
27
|
-
*
|
|
28
|
-
* @return string
|
|
29
|
-
*/
|
|
30
|
-
get method(): string;
|
|
31
|
-
/**
|
|
32
|
-
* Get the host url from request.
|
|
33
|
-
*
|
|
34
|
-
* @return string
|
|
35
|
-
*/
|
|
36
|
-
get hostUrl(): string;
|
|
37
|
-
/**
|
|
38
|
-
* Get the base request url.
|
|
39
|
-
*
|
|
40
|
-
* @return string
|
|
41
|
-
*/
|
|
42
|
-
get baseUrl(): string;
|
|
43
|
-
/**
|
|
44
|
-
* Get the original request url.
|
|
45
|
-
*
|
|
46
|
-
* @return string
|
|
47
|
-
*/
|
|
48
|
-
get originalUrl(): string;
|
|
49
|
-
/**
|
|
50
|
-
* Get all body from request.
|
|
51
|
-
*
|
|
52
|
-
* @return any
|
|
53
|
-
*/
|
|
54
|
-
get body(): any;
|
|
55
|
-
/**
|
|
56
|
-
* Get all params from request.
|
|
57
|
-
*
|
|
58
|
-
* @return any
|
|
59
|
-
*/
|
|
60
|
-
get params(): any;
|
|
61
|
-
/**
|
|
62
|
-
* Get all queries from request.
|
|
63
|
-
*
|
|
64
|
-
* @return any
|
|
65
|
-
*/
|
|
66
|
-
get queries(): any;
|
|
67
|
-
/**
|
|
68
|
-
* Get all headers from request.
|
|
69
|
-
*
|
|
70
|
-
* @return any
|
|
71
|
-
*/
|
|
72
|
-
get headers(): any;
|
|
73
|
-
/**
|
|
74
|
-
* Get a value from the request params or the default value.
|
|
75
|
-
*
|
|
76
|
-
* @return any
|
|
77
|
-
*/
|
|
78
|
-
param(param: string, defaultValue?: string): any;
|
|
79
|
-
/**
|
|
80
|
-
* Get a value from the request query param or the default value.
|
|
81
|
-
*
|
|
82
|
-
* @return any
|
|
83
|
-
*/
|
|
84
|
-
query(query: string, defaultValue?: string): any;
|
|
85
|
-
/**
|
|
86
|
-
* Get a value from the request header or the default value.
|
|
87
|
-
*
|
|
88
|
-
* @return any
|
|
89
|
-
*/
|
|
90
|
-
header(header: string, defaultValue?: string): any;
|
|
91
|
-
/**
|
|
92
|
-
* Get a value from the request body or the default value.
|
|
93
|
-
*
|
|
94
|
-
* @return any
|
|
95
|
-
*/
|
|
96
|
-
payload(payload: string, defaultValue?: string): any;
|
|
97
|
-
/**
|
|
98
|
-
* Get the default fastify request object.
|
|
99
|
-
*
|
|
100
|
-
* @return FastifyRequest
|
|
101
|
-
*/
|
|
102
|
-
getFastifyRequest(): FastifyRequest;
|
|
103
|
-
}
|
|
@@ -1,77 +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 { FastifyReply } from 'fastify';
|
|
10
|
-
import { ResponseContract } from '../Contracts/Context/ResponseContract';
|
|
11
|
-
export declare class Response implements ResponseContract {
|
|
12
|
-
private readonly response;
|
|
13
|
-
/**
|
|
14
|
-
* Create a new instance of Response.
|
|
15
|
-
*
|
|
16
|
-
* @return Response
|
|
17
|
-
*/
|
|
18
|
-
constructor(response: FastifyReply);
|
|
19
|
-
/**
|
|
20
|
-
* Terminate the request sending the response body.
|
|
21
|
-
*
|
|
22
|
-
* @param data
|
|
23
|
-
* @return void
|
|
24
|
-
*/
|
|
25
|
-
send(data?: any): void;
|
|
26
|
-
/**
|
|
27
|
-
* Terminate the request sending the response body.
|
|
28
|
-
*
|
|
29
|
-
* @param data
|
|
30
|
-
* @return void
|
|
31
|
-
*/
|
|
32
|
-
json(data?: any): void;
|
|
33
|
-
/**
|
|
34
|
-
* Set the response status code.
|
|
35
|
-
*
|
|
36
|
-
* @param code
|
|
37
|
-
* @return Response
|
|
38
|
-
*/
|
|
39
|
-
status(code: number): this;
|
|
40
|
-
/**
|
|
41
|
-
* Remove some header from the response.
|
|
42
|
-
*
|
|
43
|
-
* @param header
|
|
44
|
-
* @return Response
|
|
45
|
-
*/
|
|
46
|
-
removeHeader(header: string): this;
|
|
47
|
-
/**
|
|
48
|
-
* Add some header to the response.
|
|
49
|
-
*
|
|
50
|
-
* @param header
|
|
51
|
-
* @param value
|
|
52
|
-
* @return Response
|
|
53
|
-
*/
|
|
54
|
-
header(header: string, value: any): this;
|
|
55
|
-
/**
|
|
56
|
-
* Only add some header to the response if it's not defined yet.
|
|
57
|
-
*
|
|
58
|
-
* @param header
|
|
59
|
-
* @param value
|
|
60
|
-
* @return Response
|
|
61
|
-
*/
|
|
62
|
-
safeHeader(header: string, value: any): this;
|
|
63
|
-
/**
|
|
64
|
-
* Redirect the response to other url with different status code.
|
|
65
|
-
*
|
|
66
|
-
* @param url
|
|
67
|
-
* @param statusCode
|
|
68
|
-
* @return void
|
|
69
|
-
*/
|
|
70
|
-
redirectTo(url: string, statusCode?: number): void;
|
|
71
|
-
/**
|
|
72
|
-
* Get the default fastify response object.
|
|
73
|
-
*
|
|
74
|
-
* @return FastifyReply
|
|
75
|
-
*/
|
|
76
|
-
getFastifyResponse(): FastifyReply;
|
|
77
|
-
}
|
|
@@ -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 { RequestContract } from './RequestContract';
|
|
10
|
-
import { ResponseContract } from './ResponseContract';
|
|
11
|
-
export interface ContextContract {
|
|
12
|
-
request: RequestContract;
|
|
13
|
-
response: ResponseContract;
|
|
14
|
-
data: any;
|
|
15
|
-
params: any;
|
|
16
|
-
queries: any;
|
|
17
|
-
}
|
|
@@ -1,10 +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 });
|
|
@@ -1,18 +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 { RequestContract } from '../RequestContract';
|
|
10
|
-
import { ResponseContract } from '../ResponseContract';
|
|
11
|
-
export interface ErrorContextContract {
|
|
12
|
-
request: RequestContract;
|
|
13
|
-
response: ResponseContract;
|
|
14
|
-
params: any;
|
|
15
|
-
queries: any;
|
|
16
|
-
data: any;
|
|
17
|
-
error: any;
|
|
18
|
-
}
|
|
@@ -1,10 +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 });
|
|
@@ -1,12 +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 { ErrorContextContract } from './ErrorContextContract';
|
|
10
|
-
export interface ErrorHandlerContract {
|
|
11
|
-
(ctx?: ErrorContextContract): Promise<any> | any;
|
|
12
|
-
}
|
|
@@ -1,10 +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 });
|
|
@@ -1,12 +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 { ContextContract } from './ContextContract';
|
|
10
|
-
export interface HandlerContract {
|
|
11
|
-
(ctx: ContextContract): Promise<any> | any;
|
|
12
|
-
}
|
|
@@ -1,10 +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 });
|
|
@@ -1,19 +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 { NextContract } from '../../NextContract';
|
|
10
|
-
import { RequestContract } from '../../RequestContract';
|
|
11
|
-
import { ResponseContract } from '../../ResponseContract';
|
|
12
|
-
export interface HandleContextContract {
|
|
13
|
-
request: RequestContract;
|
|
14
|
-
response: ResponseContract;
|
|
15
|
-
data: any;
|
|
16
|
-
params: any;
|
|
17
|
-
queries: any;
|
|
18
|
-
next: NextContract;
|
|
19
|
-
}
|
|
@@ -1,10 +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 });
|
|
@@ -1,12 +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 { HandleContextContract } from './HandleContextContract';
|
|
10
|
-
export interface HandleHandlerContract {
|
|
11
|
-
(ctx: HandleContextContract): Promise<any> | any;
|
|
12
|
-
}
|