@athenna/http 1.0.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.
- package/LICENSE.md +21 -0
- package/README.md +34 -0
- package/index.d.ts +23 -0
- package/index.js +35 -0
- package/package.json +167 -0
- package/src/Context/Request.d.ts +27 -0
- package/src/Context/Request.js +68 -0
- package/src/Context/Response.d.ts +21 -0
- package/src/Context/Response.js +49 -0
- package/src/Contracts/Context/ContextContract.d.ts +17 -0
- package/src/Contracts/Context/ContextContract.js +10 -0
- package/src/Contracts/Context/Error/ErrorContextContract.d.ts +18 -0
- package/src/Contracts/Context/Error/ErrorContextContract.js +10 -0
- package/src/Contracts/Context/Error/ErrorHandlerContract.d.ts +12 -0
- package/src/Contracts/Context/Error/ErrorHandlerContract.js +10 -0
- package/src/Contracts/Context/HandlerContract.d.ts +12 -0
- package/src/Contracts/Context/HandlerContract.js +10 -0
- package/src/Contracts/Context/Middlewares/Handle/HandleContextContract.d.ts +19 -0
- package/src/Contracts/Context/Middlewares/Handle/HandleContextContract.js +10 -0
- package/src/Contracts/Context/Middlewares/Handle/HandleHandlerContract.d.ts +12 -0
- package/src/Contracts/Context/Middlewares/Handle/HandleHandlerContract.js +10 -0
- package/src/Contracts/Context/Middlewares/Intercept/InterceptContextContract.d.ts +20 -0
- package/src/Contracts/Context/Middlewares/Intercept/InterceptContextContract.js +10 -0
- package/src/Contracts/Context/Middlewares/Intercept/InterceptHandlerContract.d.ts +12 -0
- package/src/Contracts/Context/Middlewares/Intercept/InterceptHandlerContract.js +10 -0
- package/src/Contracts/Context/Middlewares/Intercept/NextInterceptContract.d.ts +11 -0
- package/src/Contracts/Context/Middlewares/Intercept/NextInterceptContract.js +10 -0
- package/src/Contracts/Context/Middlewares/Terminate/TerminateContextContract.d.ts +19 -0
- package/src/Contracts/Context/Middlewares/Terminate/TerminateContextContract.js +10 -0
- package/src/Contracts/Context/Middlewares/Terminate/TerminateHandlerContract.d.ts +12 -0
- package/src/Contracts/Context/Middlewares/Terminate/TerminateHandlerContract.js +10 -0
- package/src/Contracts/Context/NextContract.d.ts +11 -0
- package/src/Contracts/Context/NextContract.js +10 -0
- package/src/Contracts/Context/RequestContract.d.ts +23 -0
- package/src/Contracts/Context/RequestContract.js +10 -0
- package/src/Contracts/Context/ResponseContract.d.ts +18 -0
- package/src/Contracts/Context/ResponseContract.js +10 -0
- package/src/Contracts/FastifyErrorHandlerContract.d.ts +12 -0
- package/src/Contracts/FastifyErrorHandlerContract.js +10 -0
- package/src/Contracts/FastifyHandlerContract.d.ts +12 -0
- package/src/Contracts/FastifyHandlerContract.js +10 -0
- package/src/Contracts/HttpMethodTypes.d.ts +9 -0
- package/src/Contracts/HttpMethodTypes.js +10 -0
- package/src/Contracts/MiddlewareContract.d.ts +16 -0
- package/src/Contracts/MiddlewareContract.js +10 -0
- package/src/Contracts/MiddlewareTypes.d.ts +9 -0
- package/src/Contracts/MiddlewareTypes.js +10 -0
- package/src/Contracts/MiddlewareTypesContract.d.ts +16 -0
- package/src/Contracts/MiddlewareTypesContract.js +10 -0
- package/src/Contracts/RouteContract.d.ts +16 -0
- package/src/Contracts/RouteContract.js +10 -0
- package/src/Exceptions/BadRequestException.d.ts +12 -0
- package/src/Exceptions/BadRequestException.js +18 -0
- package/src/Exceptions/CannotDefineGroupException.d.ts +12 -0
- package/src/Exceptions/CannotDefineGroupException.js +19 -0
- package/src/Exceptions/MiddlewareNotFoundException.d.ts +12 -0
- package/src/Exceptions/MiddlewareNotFoundException.js +19 -0
- package/src/Http.d.ts +34 -0
- package/src/Http.js +91 -0
- package/src/Router/Route.d.ts +42 -0
- package/src/Router/Route.js +99 -0
- package/src/Router/RouteGroup.d.ts +24 -0
- package/src/Router/RouteGroup.js +51 -0
- package/src/Router/RouteResource.d.ts +29 -0
- package/src/Router/RouteResource.js +84 -0
- package/src/Router/Router.d.ts +36 -0
- package/src/Router/Router.js +123 -0
- package/src/Utils/FastifyHandler.d.ts +24 -0
- package/src/Utils/FastifyHandler.js +106 -0
- package/src/Utils/defaultErrorHandler.d.ts +10 -0
- package/src/Utils/defaultErrorHandler.js +30 -0
- package/src/Utils/isMiddlewareContract.d.ts +10 -0
- package/src/Utils/isMiddlewareContract.js +15 -0
- package/src/Utils/removeSlash.d.ts +9 -0
- package/src/Utils/removeSlash.js +23 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 The Athenna Framework
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Http 📶
|
|
2
|
+
|
|
3
|
+
> The Athenna Http server. Built on top of fastify
|
|
4
|
+
|
|
5
|
+
[](https://github.com/athennaio?tab=followers)
|
|
6
|
+
[](https://github.com/athennaio/http/stargazers/)
|
|
7
|
+
|
|
8
|
+
<p>
|
|
9
|
+
<a href="https://www.buymeacoffee.com/athenna" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
<p>
|
|
13
|
+
<img alt="GitHub language count" src="https://img.shields.io/github/languages/count/athennaio/http?style=for-the-badge&logo=appveyor">
|
|
14
|
+
|
|
15
|
+
<img alt="Repository size" src="https://img.shields.io/github/repo-size/athennaio/http?style=for-the-badge&logo=appveyor">
|
|
16
|
+
|
|
17
|
+
<img alt="License" src="https://img.shields.io/badge/license-MIT-brightgreen?style=for-the-badge&logo=appveyor">
|
|
18
|
+
|
|
19
|
+
<img alt="Commitizen" src="https://img.shields.io/badge/commitizen-friendly-brightgreen?style=for-the-badge&logo=appveyor">
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<img src=".github/logo.svg" width="200px" align="right" hspace="30px" vspace="100px">
|
|
23
|
+
|
|
24
|
+
## Links
|
|
25
|
+
|
|
26
|
+
> For project documentation [click here](https://athenna.io). If something is not clear in the documentation please open an issue in the [documentation repository](https://github.com/athennaio/docs)
|
|
27
|
+
|
|
28
|
+
## Contributing
|
|
29
|
+
|
|
30
|
+
> If you want to contribute to this project, first read the [CONTRIBUTING.MD](https://github.com/AthennaIO/Http/blob/develop/CONTRIBUTING.md) file. It will be a pleasure to receive your help.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
Made with 🖤 by [Athenna Team](https://github.com/AthennaIO) :wave:
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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/Http';
|
|
10
|
+
export * from './src/Router/Router';
|
|
11
|
+
export * from './src/Contracts/MiddlewareContract';
|
|
12
|
+
export * from './src/Contracts/Context/ContextContract';
|
|
13
|
+
export * from './src/Contracts/Context/HandlerContract';
|
|
14
|
+
export * from './src/Contracts/Context/RequestContract';
|
|
15
|
+
export * from './src/Contracts/Context/ResponseContract';
|
|
16
|
+
export * from './src/Contracts/Context/Error/ErrorContextContract';
|
|
17
|
+
export * from './src/Contracts/Context/Error/ErrorHandlerContract';
|
|
18
|
+
export * from './src/Contracts/Context/Middlewares/Handle/HandleContextContract';
|
|
19
|
+
export * from './src/Contracts/Context/Middlewares/Handle/HandleHandlerContract';
|
|
20
|
+
export * from './src/Contracts/Context/Middlewares/Intercept/InterceptContextContract';
|
|
21
|
+
export * from './src/Contracts/Context/Middlewares/Intercept/InterceptHandlerContract';
|
|
22
|
+
export * from './src/Contracts/Context/Middlewares/Terminate/TerminateContextContract';
|
|
23
|
+
export * from './src/Contracts/Context/Middlewares/Terminate/TerminateHandlerContract';
|
package/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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/Http"), exports);
|
|
22
|
+
__exportStar(require("./src/Router/Router"), exports);
|
|
23
|
+
__exportStar(require("./src/Contracts/MiddlewareContract"), exports);
|
|
24
|
+
__exportStar(require("./src/Contracts/Context/ContextContract"), exports);
|
|
25
|
+
__exportStar(require("./src/Contracts/Context/HandlerContract"), exports);
|
|
26
|
+
__exportStar(require("./src/Contracts/Context/RequestContract"), exports);
|
|
27
|
+
__exportStar(require("./src/Contracts/Context/ResponseContract"), exports);
|
|
28
|
+
__exportStar(require("./src/Contracts/Context/Error/ErrorContextContract"), exports);
|
|
29
|
+
__exportStar(require("./src/Contracts/Context/Error/ErrorHandlerContract"), exports);
|
|
30
|
+
__exportStar(require("./src/Contracts/Context/Middlewares/Handle/HandleContextContract"), exports);
|
|
31
|
+
__exportStar(require("./src/Contracts/Context/Middlewares/Handle/HandleHandlerContract"), exports);
|
|
32
|
+
__exportStar(require("./src/Contracts/Context/Middlewares/Intercept/InterceptContextContract"), exports);
|
|
33
|
+
__exportStar(require("./src/Contracts/Context/Middlewares/Intercept/InterceptHandlerContract"), exports);
|
|
34
|
+
__exportStar(require("./src/Contracts/Context/Middlewares/Terminate/TerminateContextContract"), exports);
|
|
35
|
+
__exportStar(require("./src/Contracts/Context/Middlewares/Terminate/TerminateHandlerContract"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@athenna/http",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "The Athenna Http server. Built on top of fastify",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "João Lenon <lenon@athenna.io>",
|
|
7
|
+
"repository": "https://github.com/AthennaIO/Http.git",
|
|
8
|
+
"bugs": "https://github.com/AthennaIO/Http/issues",
|
|
9
|
+
"homepage": "https://github.com/AthennaIO/Http#readme",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc --project tsconfig.json && tscpaths -p tsconfig.json -s . -o .",
|
|
12
|
+
"test": "npm run lint:fix && cross-env NODE_TS=true cross-env NODE_ENV=testing jest --verbose",
|
|
13
|
+
"test:debug": "npm run lint:fix && cross-env NODE_TS=true cross-env NODE_ENV=testing cross-env DEBUG=api:* jest --verbose",
|
|
14
|
+
"lint:fix": "eslint \"{src,tests}/**/*.ts\" --fix"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"nodejs",
|
|
18
|
+
"fastify",
|
|
19
|
+
"router",
|
|
20
|
+
"middlewares",
|
|
21
|
+
"http-server",
|
|
22
|
+
"athenna",
|
|
23
|
+
"typescript"
|
|
24
|
+
],
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/jest": "27.0.1",
|
|
27
|
+
"@types/node": "14.17.0",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "4.31.0",
|
|
29
|
+
"@typescript-eslint/parser": "4.31.0",
|
|
30
|
+
"commitizen": "4.2.4",
|
|
31
|
+
"cross-env": "7.0.3",
|
|
32
|
+
"cz-conventional-changelog": "3.3.0",
|
|
33
|
+
"eslint": "7.32.0",
|
|
34
|
+
"eslint-config-prettier": "8.3.0",
|
|
35
|
+
"eslint-config-standard": "16.0.3",
|
|
36
|
+
"eslint-import-resolver-typescript": "2.4.0",
|
|
37
|
+
"eslint-plugin-import": "2.24.2",
|
|
38
|
+
"eslint-plugin-node": "11.1.0",
|
|
39
|
+
"eslint-plugin-prettier": "4.0.0",
|
|
40
|
+
"eslint-plugin-promise": "5.1.0",
|
|
41
|
+
"eslint-plugin-standard": "5.0.0",
|
|
42
|
+
"husky": "3.0.9",
|
|
43
|
+
"jest": "27.1.0",
|
|
44
|
+
"lint-staged": "9.4.3",
|
|
45
|
+
"prettier": "2.0.5",
|
|
46
|
+
"supertest": "^6.2.2",
|
|
47
|
+
"ts-jest": "27.0.5",
|
|
48
|
+
"ts-loader": "9.2.3",
|
|
49
|
+
"ts-node": "10.0.0",
|
|
50
|
+
"tsconfig-paths": "3.9.0",
|
|
51
|
+
"typescript": "4.3.5"
|
|
52
|
+
},
|
|
53
|
+
"lint-staged": {
|
|
54
|
+
"*.js": [
|
|
55
|
+
"eslint --fix",
|
|
56
|
+
"git add"
|
|
57
|
+
],
|
|
58
|
+
"*.json": [
|
|
59
|
+
"prettier --write",
|
|
60
|
+
"git add"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"husky": {
|
|
64
|
+
"hooks": {
|
|
65
|
+
"pre-commit": "lint-staged",
|
|
66
|
+
"prepare-commit-msg": "exec < /dev/tty && git cz --hook || true"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"jest": {
|
|
70
|
+
"modulePaths": [
|
|
71
|
+
"<rootDir>"
|
|
72
|
+
],
|
|
73
|
+
"moduleFileExtensions": [
|
|
74
|
+
"js",
|
|
75
|
+
"json",
|
|
76
|
+
"ts"
|
|
77
|
+
],
|
|
78
|
+
"rootDir": ".",
|
|
79
|
+
"testRegex": "Test.ts$",
|
|
80
|
+
"transform": {
|
|
81
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
82
|
+
},
|
|
83
|
+
"coverageDirectory": "./coverage",
|
|
84
|
+
"preset": "ts-jest",
|
|
85
|
+
"testEnvironment": "node"
|
|
86
|
+
},
|
|
87
|
+
"prettier": {
|
|
88
|
+
"singleQuote": true,
|
|
89
|
+
"trailingComma": "all",
|
|
90
|
+
"arrowParens": "avoid",
|
|
91
|
+
"endOfLine": "lf",
|
|
92
|
+
"semi": false,
|
|
93
|
+
"printWidth": 80,
|
|
94
|
+
"overrides": [
|
|
95
|
+
{
|
|
96
|
+
"files": "tests/**/*",
|
|
97
|
+
"options": {
|
|
98
|
+
"printWidth": 120
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
"eslintConfig": {
|
|
104
|
+
"env": {
|
|
105
|
+
"es6": true,
|
|
106
|
+
"node": true
|
|
107
|
+
},
|
|
108
|
+
"extends": [
|
|
109
|
+
"standard",
|
|
110
|
+
"plugin:@typescript-eslint/recommended",
|
|
111
|
+
"plugin:prettier/recommended"
|
|
112
|
+
],
|
|
113
|
+
"globals": {
|
|
114
|
+
"Atomics": "readonly",
|
|
115
|
+
"SharedArrayBuffer": "readonly"
|
|
116
|
+
},
|
|
117
|
+
"parser": "@typescript-eslint/parser",
|
|
118
|
+
"parserOptions": {
|
|
119
|
+
"ecmaVersion": 2018,
|
|
120
|
+
"sourceType": "module"
|
|
121
|
+
},
|
|
122
|
+
"plugins": [
|
|
123
|
+
"@typescript-eslint",
|
|
124
|
+
"prettier"
|
|
125
|
+
],
|
|
126
|
+
"rules": {
|
|
127
|
+
"dot-notation": "off",
|
|
128
|
+
"camelcase": "off",
|
|
129
|
+
"no-undef": "off",
|
|
130
|
+
"@typescript-eslint/no-var-requires": "off",
|
|
131
|
+
"no-useless-constructor": "off",
|
|
132
|
+
"@typescript-eslint/no-useless-constructor": "off",
|
|
133
|
+
"@typescript-eslint/camelcase": "off",
|
|
134
|
+
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
135
|
+
"@typescript-eslint/interface-name-prefix": "off",
|
|
136
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
137
|
+
"prettier/prettier": "error",
|
|
138
|
+
"@typescript-eslint/no-unused-vars": [
|
|
139
|
+
"error",
|
|
140
|
+
{
|
|
141
|
+
"argsIgnorePattern": "_"
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
"files": [
|
|
147
|
+
"src/*.js",
|
|
148
|
+
"src/*.d.ts",
|
|
149
|
+
"src/**/*.js",
|
|
150
|
+
"src/**/*.d.ts",
|
|
151
|
+
"*.js",
|
|
152
|
+
"*.d.ts"
|
|
153
|
+
],
|
|
154
|
+
"config": {
|
|
155
|
+
"commitizen": {
|
|
156
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
"dependencies": {
|
|
160
|
+
"@athenna/config": "1.0.1",
|
|
161
|
+
"@athenna/ioc": "1.0.3",
|
|
162
|
+
"@secjs/utils": "1.8.0",
|
|
163
|
+
"fastify": "3.27.4",
|
|
164
|
+
"reflect-metadata": "0.1.13",
|
|
165
|
+
"tscpaths": "0.0.9"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 request;
|
|
13
|
+
constructor(request: FastifyRequest);
|
|
14
|
+
get ip(): string;
|
|
15
|
+
get method(): string;
|
|
16
|
+
get hostUrl(): string;
|
|
17
|
+
get baseUrl(): string;
|
|
18
|
+
get originalUrl(): string;
|
|
19
|
+
get body(): Record<string, any>;
|
|
20
|
+
get params(): Record<string, string>;
|
|
21
|
+
get queries(): Record<string, string>;
|
|
22
|
+
get headers(): Record<string, string>;
|
|
23
|
+
param(param: string, defaultValue?: string): string | undefined;
|
|
24
|
+
query(query: string, defaultValue?: string): string | undefined;
|
|
25
|
+
header(header: string, defaultValue?: string): string | undefined;
|
|
26
|
+
payload(payload: string, defaultValue?: string): any;
|
|
27
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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.Request = void 0;
|
|
12
|
+
const utils_1 = require("@secjs/utils");
|
|
13
|
+
const config_1 = require("@athenna/config");
|
|
14
|
+
const removeSlash_1 = require("../Utils/removeSlash");
|
|
15
|
+
class Request {
|
|
16
|
+
constructor(request) {
|
|
17
|
+
this.request = request;
|
|
18
|
+
}
|
|
19
|
+
get ip() {
|
|
20
|
+
return this.request.ip;
|
|
21
|
+
}
|
|
22
|
+
get method() {
|
|
23
|
+
return this.request.method;
|
|
24
|
+
}
|
|
25
|
+
get hostUrl() {
|
|
26
|
+
const url = this.request.url;
|
|
27
|
+
const port = config_1.Env('PORT', '1335');
|
|
28
|
+
let host = config_1.Env('APP_DOMAIN', `http://localhost:${port}`);
|
|
29
|
+
if (!utils_1.Is.Ip(host))
|
|
30
|
+
host = host.replace(`:${port}`, '');
|
|
31
|
+
return removeSlash_1.removeSlash(`${host}${url}`);
|
|
32
|
+
}
|
|
33
|
+
get baseUrl() {
|
|
34
|
+
return this.request.url.split('?')[0];
|
|
35
|
+
}
|
|
36
|
+
get originalUrl() {
|
|
37
|
+
return this.request.url;
|
|
38
|
+
}
|
|
39
|
+
get body() {
|
|
40
|
+
return this.request.body;
|
|
41
|
+
}
|
|
42
|
+
get params() {
|
|
43
|
+
return this.request.params;
|
|
44
|
+
}
|
|
45
|
+
get queries() {
|
|
46
|
+
return this.request.query;
|
|
47
|
+
}
|
|
48
|
+
get headers() {
|
|
49
|
+
return this.request.headers;
|
|
50
|
+
}
|
|
51
|
+
param(param, defaultValue) {
|
|
52
|
+
const params = this.request.params;
|
|
53
|
+
return params[param] || defaultValue;
|
|
54
|
+
}
|
|
55
|
+
query(query, defaultValue) {
|
|
56
|
+
const queries = this.request.query;
|
|
57
|
+
return queries[query] || defaultValue;
|
|
58
|
+
}
|
|
59
|
+
header(header, defaultValue) {
|
|
60
|
+
const headers = this.request.headers;
|
|
61
|
+
return headers[header] || defaultValue;
|
|
62
|
+
}
|
|
63
|
+
payload(payload, defaultValue) {
|
|
64
|
+
const body = this.request.body;
|
|
65
|
+
return body[payload] || defaultValue;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.Request = Request;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 response;
|
|
13
|
+
constructor(response: FastifyReply);
|
|
14
|
+
send(data?: Record<string, any>): void;
|
|
15
|
+
json(data?: Record<string, any>): void;
|
|
16
|
+
status(code: number): this;
|
|
17
|
+
removeHeader(header: string): this;
|
|
18
|
+
header(header: string, value: any): this;
|
|
19
|
+
safeHeader(header: string, value: any): this;
|
|
20
|
+
redirectTo(url: string, statusCode?: number): this;
|
|
21
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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.Response = void 0;
|
|
12
|
+
class Response {
|
|
13
|
+
constructor(response) {
|
|
14
|
+
this.response = response;
|
|
15
|
+
}
|
|
16
|
+
send(data) {
|
|
17
|
+
this.response.send(data);
|
|
18
|
+
}
|
|
19
|
+
json(data) {
|
|
20
|
+
this.response.serialize(data);
|
|
21
|
+
}
|
|
22
|
+
status(code) {
|
|
23
|
+
this.response.status(code);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
removeHeader(header) {
|
|
27
|
+
this.response.removeHeader(header);
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
header(header, value) {
|
|
31
|
+
this.response.header(header, value);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
safeHeader(header, value) {
|
|
35
|
+
if (!this.response.hasHeader(header)) {
|
|
36
|
+
this.response.header(header, value);
|
|
37
|
+
}
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
redirectTo(url, statusCode) {
|
|
41
|
+
if (statusCode) {
|
|
42
|
+
this.response.redirect(statusCode, url);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
this.response.redirect(url);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.Response = Response;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
params: Record<string, string>;
|
|
15
|
+
queries: Record<string, string>;
|
|
16
|
+
data: Record<string, any>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 });
|
|
@@ -0,0 +1,18 @@
|
|
|
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: Record<string, string>;
|
|
15
|
+
queries: Record<string, string>;
|
|
16
|
+
data?: Record<string, any>;
|
|
17
|
+
error: any;
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 });
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 });
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 });
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
params: Record<string, string>;
|
|
16
|
+
queries: Record<string, string>;
|
|
17
|
+
data: Record<string, any>;
|
|
18
|
+
next: NextContract;
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 });
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 });
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
import { NextInterceptContract } from './NextInterceptContract';
|
|
12
|
+
export interface InterceptContextContract {
|
|
13
|
+
request: RequestContract;
|
|
14
|
+
response: ResponseContract;
|
|
15
|
+
params: Record<string, string>;
|
|
16
|
+
queries: Record<string, string>;
|
|
17
|
+
body: Record<string, any>;
|
|
18
|
+
data: Record<string, any>;
|
|
19
|
+
next: NextInterceptContract;
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 });
|
|
@@ -0,0 +1,12 @@
|
|
|
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 { InterceptContextContract } from './InterceptContextContract';
|
|
10
|
+
export interface InterceptHandlerContract {
|
|
11
|
+
(ctx?: InterceptContextContract): Promise<any> | any;
|
|
12
|
+
}
|