Skip to content

Commit a61e25a

Browse files
authored
Merge pull request #434 from andrew-scott-fischer/BG-71730-feat-move-response-to-io-ts-http
feat: move Response to io-ts-http
2 parents eadd4ce + 790d142 commit a61e25a

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

packages/io-ts-http/src/httpResponse.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,77 @@
11
import * as t from 'io-ts';
2+
import { KeyToHttpStatus } from './statusCode';
23

34
export type HttpResponse = {
45
[K: number | string]: t.Mixed;
56
};
67

8+
const responseFunction =
9+
<S extends keyof KeyToHttpStatus>(status: S) =>
10+
<T>(payload: T) => ({ type: KeyToHttpStatus[status] as KeyToHttpStatus[S], payload });
11+
12+
export const Response = {
13+
continue: responseFunction('continue'),
14+
switchingProtocols: responseFunction('switchingProtocols'),
15+
processing: responseFunction('processing'),
16+
ok: responseFunction('ok'),
17+
created: responseFunction('created'),
18+
accepted: responseFunction('accepted'),
19+
nonAuthoritativeInformation: responseFunction('nonAuthoritativeInformation'),
20+
noContent: responseFunction('noContent'),
21+
resetContent: responseFunction('resetContent'),
22+
partialContent: responseFunction('partialContent'),
23+
multiStatus: responseFunction('multiStatus'),
24+
alreadyReported: responseFunction('alreadyReported'),
25+
imUsed: responseFunction('imUsed'),
26+
multipleChoices: responseFunction('multipleChoices'),
27+
movedPermanently: responseFunction('movedPermanently'),
28+
found: responseFunction('found'),
29+
seeOther: responseFunction('seeOther'),
30+
notModified: responseFunction('notModified'),
31+
temporaryRedirect: responseFunction('temporaryRedirect'),
32+
permanentRedirect: responseFunction('permanentRedirect'),
33+
invalidRequest: responseFunction('invalidRequest'),
34+
unauthenticated: responseFunction('unauthenticated'),
35+
paymentRequired: responseFunction('paymentRequired'),
36+
permissionDenied: responseFunction('permissionDenied'),
37+
notFound: responseFunction('notFound'),
38+
methodNotAllowed: responseFunction('methodNotAllowed'),
39+
notAcceptable: responseFunction('notAcceptable'),
40+
proxyAuthenticationRequired: responseFunction('proxyAuthenticationRequired'),
41+
requestTimeout: responseFunction('requestTimeout'),
42+
conflict: responseFunction('conflict'),
43+
gone: responseFunction('gone'),
44+
lengthRequired: responseFunction('lengthRequired'),
45+
preconditionFailed: responseFunction('preconditionFailed'),
46+
contentTooLarge: responseFunction('contentTooLarge'),
47+
uriTooLong: responseFunction('uriTooLong'),
48+
unsupportedMediaType: responseFunction('unsupportedMediaType'),
49+
rangeNotSatisfiable: responseFunction('rangeNotSatisfiable'),
50+
exceptionFailed: responseFunction('exceptionFailed'),
51+
imATeapot: responseFunction('imATeapot'),
52+
misdirectedRequest: responseFunction('misdirectedRequest'),
53+
unprocessableContent: responseFunction('unprocessableContent'),
54+
locked: responseFunction('locked'),
55+
failedDependency: responseFunction('failedDependency'),
56+
tooEarly: responseFunction('tooEarly'),
57+
upgradeRequired: responseFunction('upgradeRequired'),
58+
preconditionRequired: responseFunction('preconditionRequired'),
59+
rateLimitExceeded: responseFunction('rateLimitExceeded'),
60+
requestHeaderFieldsTooLarge: responseFunction('requestHeaderFieldsTooLarge'),
61+
unavailableForLegalReasons: responseFunction('unavailableForLegalReasons'),
62+
internalError: responseFunction('internalError'),
63+
notImplemented: responseFunction('notImplemented'),
64+
badGateway: responseFunction('badGateway'),
65+
serviceUnavailable: responseFunction('serviceUnavailable'),
66+
gatewayTimeout: responseFunction('gatewayTimeout'),
67+
httpVersionNotSupported: responseFunction('httpVersionNotSupported'),
68+
variantAlsoNegotiates: responseFunction('variantAlsoNegotiates'),
69+
insufficientStorage: responseFunction('insufficientStorage'),
70+
loopDetected: responseFunction('loopDetected'),
71+
notExtended: responseFunction('notExtended'),
72+
networkAuthenticationRequired: responseFunction('networkAuthenticationRequired'),
73+
};
74+
775
export type ResponseTypeForStatus<
876
Response extends HttpResponse,
977
S extends keyof Response,

0 commit comments

Comments
 (0)