diff --git a/packages/io-ts-http/src/statusCode.ts b/packages/io-ts-http/src/statusCode.ts index d0d01b43..6e899256 100644 --- a/packages/io-ts-http/src/statusCode.ts +++ b/packages/io-ts-http/src/statusCode.ts @@ -1,29 +1,131 @@ // TODO: Enforce consistency at the type level export const HttpToKeyStatus = { + 100: 'continue', + 101: 'switchingProtocols', + 102: 'processing', 200: 'ok', + 201: 'created', + 202: 'accepted', + 203: 'nonAuthoritativeInformation', + 204: 'noContent', + 205: 'resetContent', + 206: 'partialContent', + 207: 'multiStatus', + 208: 'alreadyReported', + 226: 'imUsed', + 300: 'multipleChoices', + 301: 'movedPermanently', + 302: 'found', + 303: 'seeOther', + 304: 'notModified', + 307: 'temporaryRedirect', + 308: 'permanentRedirect', 400: 'invalidRequest', 401: 'unauthenticated', + 402: 'paymentRequired', 403: 'permissionDenied', 404: 'notFound', + 405: 'methodNotAllowed', + 406: 'notAcceptable', + 407: 'proxyAuthenticationRequired', + 408: 'requestTimeout', 409: 'conflict', + 410: 'gone', + 411: 'lengthRequired', + 412: 'preconditionFailed', + 413: 'contentTooLarge', + 414: 'uriTooLong', + 415: 'unsupportedMediaType', + 416: 'rangeNotSatisfiable', + 417: 'exceptionFailed', + 418: 'imATeapot', + 421: 'misdirectedRequest', + 422: 'unprocessableContent', + 423: 'locked', + 424: 'failedDependency', + 425: 'tooEarly', + 426: 'upgradeRequired', + 428: 'preconditionRequired', 429: 'rateLimitExceeded', + 431: 'requestHeaderFieldsTooLarge', + 451: 'unavailableForLegalReasons', 500: 'internalError', + 501: 'notImplemented', + 502: 'badGateway', 503: 'serviceUnavailable', + 504: 'gatewayTimeout', + 505: 'httpVersionNotSupported', + 506: 'variantAlsoNegotiates', + 507: 'insufficientStorage', + 508: 'loopDetected', + 510: 'notExtended', + 511: 'networkAuthenticationRequired', } as const; export type HttpToKeyStatus = typeof HttpToKeyStatus; export const KeyToHttpStatus = { + continue: 100, + switchingProtocols: 101, + processing: 102, ok: 200, + created: 201, + accepted: 202, + nonAuthoritativeInformation: 203, + noContent: 204, + resetContent: 205, + partialContent: 206, + multiStatus: 207, + alreadyReported: 208, + imUsed: 226, + multipleChoices: 300, + movedPermanently: 301, + found: 302, + seeOther: 303, + notModified: 304, + temporaryRedirect: 307, + permanentRedirect: 308, invalidRequest: 400, unauthenticated: 401, + paymentRequired: 402, permissionDenied: 403, notFound: 404, + methodNotAllowed: 405, + notAcceptable: 406, + proxyAuthenticationRequired: 407, + requestTimeout: 408, conflict: 409, + gone: 410, + lengthRequired: 411, + preconditionFailed: 412, + contentTooLarge: 413, + uriTooLong: 414, + unsupportedMediaType: 415, + rangeNotSatisfiable: 416, + exceptionFailed: 417, + imATeapot: 418, + misdirectedRequest: 421, + unprocessableContent: 422, + locked: 423, + failedDependency: 424, + tooEarly: 425, + upgradeRequired: 426, + preconditionRequired: 428, rateLimitExceeded: 429, + requestHeaderFieldsTooLarge: 431, + unavailableForLegalReasons: 451, internalError: 500, + notImplemented: 501, + badGateway: 502, serviceUnavailable: 503, + gatewayTimeout: 504, + httpVersionNotSupported: 505, + variantAlsoNegotiates: 506, + insufficientStorage: 507, + loopDetected: 508, + notExtended: 510, + networkAuthenticationRequired: 511, } as const; export type KeyToHttpStatus = typeof KeyToHttpStatus; diff --git a/packages/response/src/keyed-response.ts b/packages/response/src/keyed-response.ts index 7a063e39..274d6c64 100644 --- a/packages/response/src/keyed-response.ts +++ b/packages/response/src/keyed-response.ts @@ -2,28 +2,67 @@ * @api-ts/response */ -// HTTP | GRPC | Response -// ----------------------------|--------------------|--------------------------- -// 400 (bad request) | INVALID_ARGUMENT | Response.invalidRequest -// 401 (unauthorized) | UNAUTHENTICATED | Response.unauthenticated -// 403 (forbidden) | PERMISSION_DENIED | Response.permissionDenied -// 404 (not found) | NOT_FOUND | Response.notFound -// 405 (method not allowed) | NOT_FOUND | Response.notFound -// 409 (conflict) | ALREADY_EXISTS | Response.conflict -// 429 (rate-limit) | RESOURCE_EXHAUSTED | Response.rateLimitExceeded -// 500 (internal server error) | INTERNAL | Response.internalError -// 503 (service unavailable) | UNAVAILABLE | Response.serviceUnavailable - export type KeyedStatus = + | 'continue' + | 'switchingProtocols' + | 'processing' | 'ok' + | 'created' + | 'accepted' + | 'nonAuthoritativeInformation' + | 'noContent' + | 'resetContent' + | 'partialContent' + | 'multiStatus' + | 'alreadyReported' + | 'imUsed' + | 'multipleChoices' + | 'movedPermanently' + | 'found' + | 'seeOther' + | 'notModified' + | 'temporaryRedirect' + | 'permanentRedirect' | 'invalidRequest' | 'unauthenticated' + | 'paymentRequired' | 'permissionDenied' | 'notFound' + | 'methodNotAllowed' + | 'notAcceptable' + | 'proxyAuthenticationRequired' + | 'requestTimeout' | 'conflict' + | 'gone' + | 'lengthRequired' + | 'preconditionFailed' + | 'contentTooLarge' + | 'uriTooLong' + | 'unsupportedMediaType' + | 'rangeNotSatisfiable' + | 'exceptionFailed' + | 'imATeapot' + | 'misdirectedRequest' + | 'unprocessableContent' + | 'locked' + | 'failedDependency' + | 'tooEarly' + | 'upgradeRequired' + | 'preconditionRequired' | 'rateLimitExceeded' + | 'requestHeaderFieldsTooLarge' + | 'unavailableForLegalReasons' | 'internalError' - | 'serviceUnavailable'; + | 'notImplemented' + | 'badGateway' + | 'serviceUnavailable' + | 'gatewayTimeout' + | 'httpVersionNotSupported' + | 'variantAlsoNegotiates' + | 'insufficientStorage' + | 'loopDetected' + | 'notExtended' + | 'networkAuthenticationRequired'; export type KeyedResponse = { type: KeyedStatus; payload: unknown }; @@ -32,13 +71,64 @@ const responseFunction = (payload: T) => ({ type: status, payload }); export const KeyedResponse = { + 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'), }; diff --git a/packages/response/src/response.ts b/packages/response/src/response.ts index 4f65555a..7de9a7b5 100644 --- a/packages/response/src/response.ts +++ b/packages/response/src/response.ts @@ -2,19 +2,67 @@ * @api-ts/response */ -// HTTP | GRPC | Response -// ----------------------------|--------------------|--------------------------- -// 400 (bad request) | INVALID_ARGUMENT | Response.invalidRequest -// 401 (unauthorized) | UNAUTHENTICATED | Response.unauthenticated -// 403 (forbidden) | PERMISSION_DENIED | Response.permissionDenied -// 404 (not found) | NOT_FOUND | Response.notFound -// 405 (method not allowed) | NOT_FOUND | Response.notFound -// 409 (conflict) | ALREADY_EXISTS | Response.conflict -// 429 (rate-limit) | RESOURCE_EXHAUSTED | Response.rateLimitExceeded -// 500 (internal server error) | INTERNAL | Response.internalError -// 503 (service unavailable) | UNAVAILABLE | Response.serviceUnavailable - -export type Status = 200 | 400 | 401 | 403 | 404 | 409 | 429 | 500 | 503; +export type Status = + | 100 + | 101 + | 102 + | 200 + | 201 + | 202 + | 203 + | 204 + | 205 + | 206 + | 207 + | 208 + | 226 + | 300 + | 301 + | 302 + | 303 + | 304 + | 307 + | 308 + | 400 + | 401 + | 402 + | 403 + | 404 + | 405 + | 406 + | 407 + | 408 + | 409 + | 410 + | 411 + | 412 + | 413 + | 414 + | 415 + | 416 + | 417 + | 418 + | 421 + | 422 + | 423 + | 424 + | 425 + | 426 + | 428 + | 429 + | 431 + | 451 + | 500 + | 501 + | 502 + | 503 + | 504 + | 505 + | 506 + | 507 + | 508 + | 510 + | 511; export type Response = { type: Status; payload: unknown }; @@ -23,13 +71,64 @@ const ResponseFunction = (payload: T) => ({ type: status, payload }); export const Response = { + continue: ResponseFunction(100), + switchingProtocols: ResponseFunction(101), + processing: ResponseFunction(102), ok: ResponseFunction(200), + created: ResponseFunction(201), + accepted: ResponseFunction(202), + nonAuthoritativeInformation: ResponseFunction(203), + noContent: ResponseFunction(204), + resetContent: ResponseFunction(205), + partialContent: ResponseFunction(206), + multiStatus: ResponseFunction(207), + alreadyReported: ResponseFunction(208), + imUsed: ResponseFunction(226), + multipleChoices: ResponseFunction(300), + movedPermanently: ResponseFunction(301), + found: ResponseFunction(302), + seeOther: ResponseFunction(303), + notModified: ResponseFunction(304), + temporaryRedirect: ResponseFunction(307), + permanentRedirect: ResponseFunction(308), invalidRequest: ResponseFunction(400), unauthenticated: ResponseFunction(401), + paymentRequired: ResponseFunction(402), permissionDenied: ResponseFunction(403), notFound: ResponseFunction(404), + methodNotAllowed: ResponseFunction(405), + notAcceptable: ResponseFunction(406), + proxyAuthenticationRequired: ResponseFunction(407), + requestTimeout: ResponseFunction(408), conflict: ResponseFunction(409), + gone: ResponseFunction(410), + lengthRequired: ResponseFunction(411), + preconditionFailed: ResponseFunction(412), + contentTooLarge: ResponseFunction(413), + uriTooLong: ResponseFunction(414), + unsupportedMediaType: ResponseFunction(415), + rangeNotSatisfiable: ResponseFunction(416), + exceptionFailed: ResponseFunction(417), + imATeapot: ResponseFunction(418), + misdirectedRequest: ResponseFunction(421), + unprocessableContent: ResponseFunction(422), + locked: ResponseFunction(423), + failedDependency: ResponseFunction(424), + tooEarly: ResponseFunction(425), + upgradeRequired: ResponseFunction(426), + preconditionRequired: ResponseFunction(428), rateLimitExceeded: ResponseFunction(429), + requestHeaderFieldsTooLarge: ResponseFunction(431), + unavailableForLegalReasons: ResponseFunction(451), internalError: ResponseFunction(500), + notImplemented: ResponseFunction(501), + badGateway: ResponseFunction(502), serviceUnavailable: ResponseFunction(503), + gatewayTimeout: ResponseFunction(504), + httpVersionNotSupported: ResponseFunction(505), + variantAlsoNegotiates: ResponseFunction(506), + insufficientStorage: ResponseFunction(507), + loopDetected: ResponseFunction(508), + notExtended: ResponseFunction(510), + networkAuthenticationRequired: ResponseFunction(511), };