From 19d4309272f4563d65f5b7cc674d9fb59d89f126 Mon Sep 17 00:00:00 2001 From: Michael Wolf Date: Sat, 8 Feb 2025 18:27:31 -0600 Subject: [PATCH] Add several constants --- deno/content-types.ts | 36 ++++++++++++++++++++++++++++++++++++ deno/http-codes.ts | 41 +++++++++++++++++++++++++++++++++++++++++ deno/interfaces.ts | 1 + 3 files changed, 78 insertions(+) create mode 100644 deno/content-types.ts create mode 100644 deno/http-codes.ts create mode 100644 deno/interfaces.ts diff --git a/deno/content-types.ts b/deno/content-types.ts new file mode 100644 index 0000000..cd15683 --- /dev/null +++ b/deno/content-types.ts @@ -0,0 +1,36 @@ +import { Extensible } from "./interfaces"; + +const contentTypes: Extensible = { + text: { + plain: "text/plain", + html: "text/html", + css: "text/css", + javascript: "text/javascript", + xml: "text/xml", + }, + image: { + jpeg: "image/jpeg", + png: "image/png", + gif: "image/gif", + svgPlusXml: "image/svg+xml", + webp: "image/webp", + }, + audio: { + "mpeg": "audio/mpeg", + "wav": "audio/wav", + }, + video: { + mp4: "video/mp4", + webm: "video/webm", + xMsvideo: "video/x-msvideo", + }, + application: { + json: "application/json", + pdf: "application/pdf", + zip: "application/zip", + xWwwFormUrlencoded: "x-www-form-urlencoded", + octetStream: "octet-stream", + }, +}; + +export { contentTypes }; diff --git a/deno/http-codes.ts b/deno/http-codes.ts new file mode 100644 index 0000000..ee611d7 --- /dev/null +++ b/deno/http-codes.ts @@ -0,0 +1,41 @@ +import { Extensible } from "./interfaces"; + +type HttpCode = { + code: number; + name: string; + description?: string; +}; +type Group = "success" | "redirection" | "clientErrors" | "serverErrors"; +type CodeDefinitions = { + [K in Group]: { + [K: string]: HttpCode; + }; +}; + +const httpCodes: CodeDefinitions & Extensible = { + success: { + OK: { code: 200, name: "OK", "description": "" }, + Created: { code: 201, name: "Created" }, + Accepted: { code: 202, name: "Accepted" }, + NoContent: { code: 204, name: "No content" }, + }, + redirection: { + // later + }, + clientErrors: { + BadRequest: { code: 400, name: "Bad Request" }, + Unauthorized: { code: 401, name: "Unauthorized" }, + Forbidden: { code: 403, name: "Forbidden" }, + NotFound: { code: 404, name: "Not Found" }, + MethodNotAllowed: { code: 405, name: "Method Not Allowed" }, + NotAcceptable: { code: 406, name: "Not Acceptable" }, + // More later + }, + serverErrors: { + InternalServerError: { code: 500, name: "Internal Server Error" }, + NotImplemented: { code: 500, name: "Not implemented" }, + // more later + }, +}; + +export { httpCodes }; diff --git a/deno/interfaces.ts b/deno/interfaces.ts new file mode 100644 index 0000000..3914b1b --- /dev/null +++ b/deno/interfaces.ts @@ -0,0 +1 @@ +export interface Extensible {}