Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: move Response to io-ts-http
Ticket: BG-71730
  • Loading branch information
andrew-scott-fischer committed Mar 29, 2023
commit 790d142a843e08a96589ab77d30a1c0bf1161550
68 changes: 68 additions & 0 deletions packages/io-ts-http/src/httpResponse.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,77 @@
import * as t from 'io-ts';
import { KeyToHttpStatus } from './statusCode';

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

const responseFunction =
<S extends keyof KeyToHttpStatus>(status: S) =>
<T>(payload: T) => ({ type: KeyToHttpStatus[status] as KeyToHttpStatus[S], payload });

export const Response = {
continue: responseFunction('continue'),
switchingProtocols: responseFunction('switchingProtocols'),
processing: responseFunction('processing'),
ok: responseFunction('ok'),
created: responseFunction('created'),
accepted: responseFunction('accepted'),
nonAuthoritativeInformation: responseFunction('nonAuthoritativeInformation'),
noContent: responseFunction('noContent'),
resetContent: responseFunction('resetContent'),
partialContent: responseFunction('partialContent'),
multiStatus: responseFunction('multiStatus'),
alreadyReported: responseFunction('alreadyReported'),
imUsed: responseFunction('imUsed'),
multipleChoices: responseFunction('multipleChoices'),
movedPermanently: responseFunction('movedPermanently'),
found: responseFunction('found'),
seeOther: responseFunction('seeOther'),
notModified: responseFunction('notModified'),
temporaryRedirect: responseFunction('temporaryRedirect'),
permanentRedirect: responseFunction('permanentRedirect'),
invalidRequest: responseFunction('invalidRequest'),
unauthenticated: responseFunction('unauthenticated'),
paymentRequired: responseFunction('paymentRequired'),
permissionDenied: responseFunction('permissionDenied'),
notFound: responseFunction('notFound'),
methodNotAllowed: responseFunction('methodNotAllowed'),
notAcceptable: responseFunction('notAcceptable'),
proxyAuthenticationRequired: responseFunction('proxyAuthenticationRequired'),
requestTimeout: responseFunction('requestTimeout'),
conflict: responseFunction('conflict'),
gone: responseFunction('gone'),
lengthRequired: responseFunction('lengthRequired'),
preconditionFailed: responseFunction('preconditionFailed'),
contentTooLarge: responseFunction('contentTooLarge'),
uriTooLong: responseFunction('uriTooLong'),
unsupportedMediaType: responseFunction('unsupportedMediaType'),
rangeNotSatisfiable: responseFunction('rangeNotSatisfiable'),
exceptionFailed: responseFunction('exceptionFailed'),
imATeapot: responseFunction('imATeapot'),
misdirectedRequest: responseFunction('misdirectedRequest'),
unprocessableContent: responseFunction('unprocessableContent'),
locked: responseFunction('locked'),
failedDependency: responseFunction('failedDependency'),
tooEarly: responseFunction('tooEarly'),
upgradeRequired: responseFunction('upgradeRequired'),
preconditionRequired: responseFunction('preconditionRequired'),
rateLimitExceeded: responseFunction('rateLimitExceeded'),
requestHeaderFieldsTooLarge: responseFunction('requestHeaderFieldsTooLarge'),
unavailableForLegalReasons: responseFunction('unavailableForLegalReasons'),
internalError: responseFunction('internalError'),
notImplemented: responseFunction('notImplemented'),
badGateway: responseFunction('badGateway'),
serviceUnavailable: responseFunction('serviceUnavailable'),
gatewayTimeout: responseFunction('gatewayTimeout'),
httpVersionNotSupported: responseFunction('httpVersionNotSupported'),
variantAlsoNegotiates: responseFunction('variantAlsoNegotiates'),
insufficientStorage: responseFunction('insufficientStorage'),
loopDetected: responseFunction('loopDetected'),
notExtended: responseFunction('notExtended'),
networkAuthenticationRequired: responseFunction('networkAuthenticationRequired'),
};

export type ResponseTypeForStatus<
Response extends HttpResponse,
S extends keyof Response,
Expand Down