-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from ty-ras/issue/45-add-http-methods
#45 During the work on enabling non-200 code, lon…
- Loading branch information
Showing
5 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@ty-ras/data", | ||
"version": "0.12.3", | ||
"version": "0.13.0", | ||
"author": { | ||
"name": "Stanislav Muhametsin", | ||
"email": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import test from "ava"; | ||
import * as spec from "../methods"; | ||
|
||
test("Validate isMethodWithoutRequestBody works", (t) => { | ||
t.plan(8); | ||
for (const [method, result] of Object.entries(methodRequestBodySpec)) { | ||
t.deepEqual( | ||
spec.isMethodWithoutRequestBody(method as spec.HttpMethod), | ||
result, | ||
`The return value of isMethodWithoutRequestBody for ${method} must be expected`, | ||
); | ||
} | ||
}); | ||
|
||
const methodRequestBodySpec: Record<spec.HttpMethod, boolean> = { | ||
OPTIONS: true, | ||
GET: true, | ||
POST: false, | ||
PUT: false, | ||
DELETE: false, | ||
HEAD: true, | ||
PATCH: false, | ||
TRACE: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export type HttpMethod = | ||
| typeof METHOD_GET | ||
| typeof METHOD_HEAD | ||
| typeof METHOD_POST | ||
| typeof METHOD_PUT | ||
| typeof METHOD_PATCH | ||
| typeof METHOD_DELETE | ||
| typeof METHOD_OPTIONS | ||
| typeof METHOD_TRACE; | ||
|
||
export type HttpMethodWithoutBody = keyof typeof HttpMethodsWithoutBody; | ||
export type HttpMethodWithBody = Exclude<HttpMethod, HttpMethodWithoutBody>; | ||
|
||
export const isMethodWithoutRequestBody = ( | ||
method: HttpMethod, | ||
): method is HttpMethodWithoutBody => method in HttpMethodsWithoutBody; | ||
|
||
export const METHOD_GET = "GET"; | ||
export const METHOD_HEAD = "HEAD"; | ||
export const METHOD_POST = "POST"; | ||
export const METHOD_PUT = "PUT"; | ||
export const METHOD_PATCH = "PATCH"; | ||
export const METHOD_DELETE = "DELETE"; | ||
export const METHOD_OPTIONS = "OPTIONS"; | ||
export const METHOD_TRACE = "TRACE"; | ||
|
||
const HttpMethodsWithoutBody = { | ||
[METHOD_TRACE]: true, | ||
[METHOD_GET]: true, | ||
[METHOD_OPTIONS]: true, | ||
[METHOD_HEAD]: true, | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@ty-ras/protocol", | ||
"version": "0.12.1", | ||
"version": "0.13.0", | ||
"author": { | ||
"name": "Stanislav Muhametsin", | ||
"email": "[email protected]", | ||
|