From fad9ab96cc2d9c42f5771c5e5b1926e7a8117065 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Fri, 12 Jul 2024 00:13:41 +0530 Subject: [PATCH] feat!: re-export everything from the `@std/http` module It currently includes deprecated things, but those will be removed by deno_std stabilizing this month. BREAKING CHANGE: `createStandardResponse` and `STATUS_CODE` are now exported from hado/http instead of hado/router --- deno.json | 9 +-- deno.lock | 162 +++++++++++++++++++++++++-------------------- scripts/release.ts | 2 +- src/http.ts | 27 ++++++++ src/router.ts | 21 +----- 5 files changed, 125 insertions(+), 96 deletions(-) create mode 100644 src/http.ts diff --git a/deno.json b/deno.json index 597e773..92154e8 100644 --- a/deno.json +++ b/deno.json @@ -2,6 +2,7 @@ "name": "@globalbrain/hado", "version": "0.4.2", "exports": { + "./http": "./src/http.ts", "./router": "./src/router.ts", "./utils": "./src/utils.ts" }, @@ -19,11 +20,11 @@ "noUnusedParameters": true }, "imports": { - "@std/assert": "jsr:@std/assert@^0.226.0", + "@std/assert": "jsr:@std/assert@^1.0.0", "@std/async": "jsr:@std/async@^0.224.2", - "@std/fs": "jsr:@std/fs@^0.229.2", - "@std/http": "jsr:@std/http@^0.224.4", - "@std/net": "jsr:@std/net@^0.224.2", + "@std/fs": "jsr:@std/fs@^0.229.3", + "@std/http": "jsr:@std/http@^0.224.5", + "@std/net": "jsr:@std/net@^0.224.5", "@std/path": "jsr:@std/path@^0.225.2", "@std/regexp": "jsr:@std/regexp@^0.224.1", "chokidar": "npm:chokidar@^3.6.0", diff --git a/deno.lock b/deno.lock index 95319b2..83ec3a2 100644 --- a/deno.lock +++ b/deno.lock @@ -2,48 +2,52 @@ "version": "3", "packages": { "specifiers": { - "jsr:@cliffy/ansi@1.0.0-rc.4": "jsr:@cliffy/ansi@1.0.0-rc.4", - "jsr:@cliffy/keycode@1.0.0-rc.4": "jsr:@cliffy/keycode@1.0.0-rc.4", - "jsr:@cliffy/prompt@1.0.0-rc.4": "jsr:@cliffy/prompt@1.0.0-rc.4", + "jsr:@cliffy/ansi@1.0.0-rc.5": "jsr:@cliffy/ansi@1.0.0-rc.5", + "jsr:@cliffy/internal@1.0.0-rc.5": "jsr:@cliffy/internal@1.0.0-rc.5", + "jsr:@cliffy/keycode@1.0.0-rc.5": "jsr:@cliffy/keycode@1.0.0-rc.5", + "jsr:@cliffy/prompt@1.0.0-rc.5": "jsr:@cliffy/prompt@1.0.0-rc.5", "jsr:@core/unknownutil@^3.18.0": "jsr:@core/unknownutil@3.18.1", "jsr:@david/dax": "jsr:@david/dax@0.41.0", "jsr:@david/which@^0.4.1": "jsr:@david/which@0.4.1", "jsr:@deno/graph@^0.73.1": "jsr:@deno/graph@0.73.1", "jsr:@lambdalisue/async@^2.1.1": "jsr:@lambdalisue/async@2.1.1", - "jsr:@molt/core": "jsr:@molt/core@0.18.4", - "jsr:@molt/lib@^0.18.0": "jsr:@molt/lib@0.18.0", + "jsr:@molt/core": "jsr:@molt/core@0.18.5", + "jsr:@molt/lib@^0.18.0": "jsr:@molt/lib@0.18.5", + "jsr:@std/assert@1.0.0-rc.2": "jsr:@std/assert@1.0.0-rc.2", "jsr:@std/assert@^0.221.0": "jsr:@std/assert@0.221.0", "jsr:@std/assert@^0.222.1": "jsr:@std/assert@0.222.1", "jsr:@std/assert@^0.226.0": "jsr:@std/assert@0.226.0", + "jsr:@std/assert@^1.0.0": "jsr:@std/assert@1.0.0", "jsr:@std/async@^0.224.2": "jsr:@std/async@0.224.2", + "jsr:@std/async@^1.0.0-rc.1": "jsr:@std/async@1.0.0-rc.3", "jsr:@std/bytes@^0.221.0": "jsr:@std/bytes@0.221.0", - "jsr:@std/cli": "jsr:@std/cli@0.224.6", - "jsr:@std/cli@^0.224.6": "jsr:@std/cli@0.224.6", + "jsr:@std/cli": "jsr:@std/cli@0.224.7", + "jsr:@std/cli@^0.224.7": "jsr:@std/cli@0.224.7", "jsr:@std/collections@^0.222.1": "jsr:@std/collections@0.222.1", - "jsr:@std/encoding@0.221": "jsr:@std/encoding@0.221.0", "jsr:@std/encoding@1.0.0-rc.2": "jsr:@std/encoding@1.0.0-rc.2", - "jsr:@std/fmt": "jsr:@std/fmt@0.225.4", - "jsr:@std/fmt@0.221": "jsr:@std/fmt@0.221.0", + "jsr:@std/fmt": "jsr:@std/fmt@0.225.6", "jsr:@std/fmt@^0.221.0": "jsr:@std/fmt@0.221.0", "jsr:@std/fmt@^0.222.1": "jsr:@std/fmt@0.222.1", - "jsr:@std/fmt@^0.225.4": "jsr:@std/fmt@0.225.4", - "jsr:@std/fs": "jsr:@std/fs@0.229.2", + "jsr:@std/fmt@^0.225.4": "jsr:@std/fmt@0.225.6", + "jsr:@std/fmt@~0.225.4": "jsr:@std/fmt@0.225.6", + "jsr:@std/fs": "jsr:@std/fs@0.229.3", "jsr:@std/fs@0.221.0": "jsr:@std/fs@0.221.0", "jsr:@std/fs@^0.222.1": "jsr:@std/fs@0.222.1", - "jsr:@std/fs@^0.229.2": "jsr:@std/fs@0.229.2", - "jsr:@std/http@^0.224.4": "jsr:@std/http@0.224.4", - "jsr:@std/internal@^1.0.0": "jsr:@std/internal@1.0.0", - "jsr:@std/io@0.221": "jsr:@std/io@0.221.0", + "jsr:@std/fs@^0.229.3": "jsr:@std/fs@0.229.3", + "jsr:@std/http@^0.224.5": "jsr:@std/http@0.224.5", + "jsr:@std/internal@^1.0.1": "jsr:@std/internal@1.0.1", "jsr:@std/io@0.221.0": "jsr:@std/io@0.221.0", "jsr:@std/io@^0.221.0": "jsr:@std/io@0.221.0", + "jsr:@std/io@~0.224.2": "jsr:@std/io@0.224.3", "jsr:@std/json@^0.222.1": "jsr:@std/json@0.222.1", "jsr:@std/jsonc@^0.222.1": "jsr:@std/jsonc@0.222.1", - "jsr:@std/media-types@^1.0.0-rc.1": "jsr:@std/media-types@1.0.0-rc.1", - "jsr:@std/net@^0.224.2": "jsr:@std/net@0.224.2", + "jsr:@std/media-types@^1.0.0-rc.1": "jsr:@std/media-types@1.0.1", + "jsr:@std/net@^0.224.3": "jsr:@std/net@0.224.5", + "jsr:@std/net@^0.224.5": "jsr:@std/net@0.224.5", "jsr:@std/path": "jsr:@std/path@0.225.2", - "jsr:@std/path@0.221": "jsr:@std/path@0.221.0", "jsr:@std/path@0.221.0": "jsr:@std/path@0.221.0", "jsr:@std/path@1.0.0-rc.1": "jsr:@std/path@1.0.0-rc.1", + "jsr:@std/path@1.0.0-rc.2": "jsr:@std/path@1.0.0-rc.2", "jsr:@std/path@^0.221.0": "jsr:@std/path@0.221.0", "jsr:@std/path@^0.222.1": "jsr:@std/path@0.222.1", "jsr:@std/path@^0.225.2": "jsr:@std/path@0.225.2", @@ -52,30 +56,32 @@ "jsr:@std/semver": "jsr:@std/semver@0.224.3", "jsr:@std/semver@^0.222.1": "jsr:@std/semver@0.222.1", "jsr:@std/streams@0.221.0": "jsr:@std/streams@0.221.0", - "jsr:@std/streams@^0.224.4": "jsr:@std/streams@0.224.4", - "jsr:@std/text@0.221": "jsr:@std/text@0.221.0", + "jsr:@std/streams@^0.224.5": "jsr:@std/streams@0.224.5", + "jsr:@std/text@1.0.0-rc.1": "jsr:@std/text@1.0.0-rc.1", "npm:chokidar@^3.6.0": "npm:chokidar@3.6.0", "npm:zod@^3.23.8": "npm:zod@3.23.8" }, "jsr": { - "@cliffy/ansi@1.0.0-rc.4": { - "integrity": "df561b6a69bb5177c31618c027274504ed24b996b854fa072eb7d0a380e41ac1", - "dependencies": [ - "jsr:@std/encoding@0.221" - ] + "@cliffy/ansi@1.0.0-rc.5": { + "integrity": "85a4dba4da5d8278dcdfeea98672cd15706c244833f82edc60c61f410d9fc1a9" + }, + "@cliffy/internal@1.0.0-rc.5": { + "integrity": "1e8dca4fcfba1815bf1a899bb880e09f8b45284c352465ef8fb015887c1fc126" }, - "@cliffy/keycode@1.0.0-rc.4": { - "integrity": "872ee86f6a438dc2c532408e542ee97ed19c91aedb8374c2eddc6e02e83c8ce4" + "@cliffy/keycode@1.0.0-rc.5": { + "integrity": "2bcb3cb13873f0b758664394e003fc0cfa751af37a076ca9ec6e574df77aa3a8" }, - "@cliffy/prompt@1.0.0-rc.4": { - "integrity": "d5e52f2bc27040184f046e24af89262fbcbec0770cd528f6f11c58cebda28da9", + "@cliffy/prompt@1.0.0-rc.5": { + "integrity": "3573a4c5c460fc84dcc554e548acfc2616157b60a61a9781833967c5a76da9f0", "dependencies": [ - "jsr:@cliffy/ansi@1.0.0-rc.4", - "jsr:@cliffy/keycode@1.0.0-rc.4", - "jsr:@std/fmt@0.221", - "jsr:@std/io@0.221", - "jsr:@std/path@0.221", - "jsr:@std/text@0.221" + "jsr:@cliffy/ansi@1.0.0-rc.5", + "jsr:@cliffy/internal@1.0.0-rc.5", + "jsr:@cliffy/keycode@1.0.0-rc.5", + "jsr:@std/assert@1.0.0-rc.2", + "jsr:@std/fmt@~0.225.4", + "jsr:@std/io@~0.224.2", + "jsr:@std/path@1.0.0-rc.2", + "jsr:@std/text@1.0.0-rc.1" ] }, "@core/unknownutil@3.18.1": { @@ -101,8 +107,8 @@ "@lambdalisue/async@2.1.1": { "integrity": "1fc9bc6f4ed50215cd2f7217842b18cea80f81c25744f88f8c5eb4be5a1c9ab4" }, - "@molt/core@0.18.4": { - "integrity": "54935625bce7c712ec012e00d56eeb1e9e3f393e615cfc8d3c28c0684093282f", + "@molt/core@0.18.5": { + "integrity": "42bc81de1af0ffd728626bfd99350c0f01ddec53988a8d069561009953a55823", "dependencies": [ "jsr:@core/unknownutil@^3.18.0", "jsr:@deno/graph@^0.73.1", @@ -116,8 +122,8 @@ "jsr:@std/semver@^0.222.1" ] }, - "@molt/lib@0.18.0": { - "integrity": "c5b10f134f8ba68f6f6a389ad08fedca705a12d3d1d12ec2b45b06cf67b9b9e1" + "@molt/lib@0.18.5": { + "integrity": "dfbcf01f9c57f57d0fc2581ec8ac087f933f17da106feaaf60feced2e8cc6eab" }, "@std/assert@0.221.0": { "integrity": "a5f1aa6e7909dbea271754fd4ab3f4e687aeff4873b4cef9a320af813adb489a" @@ -129,26 +135,32 @@ ] }, "@std/assert@0.226.0": { - "integrity": "0dfb5f7c7723c18cec118e080fec76ce15b4c31154b15ad2bd74822603ef75b3", + "integrity": "0dfb5f7c7723c18cec118e080fec76ce15b4c31154b15ad2bd74822603ef75b3" + }, + "@std/assert@1.0.0": { + "integrity": "0e4f6d873f7f35e2a1e6194ceee39686c996b9e5d134948e644d35d4c4df2008", "dependencies": [ - "jsr:@std/internal@^1.0.0" + "jsr:@std/internal@^1.0.1" ] }, + "@std/assert@1.0.0-rc.2": { + "integrity": "0484eab1d76b55fca1c3beaff485a274e67dd3b9f065edcbe70030dfc0b964d3" + }, "@std/async@0.224.2": { "integrity": "4d277d6e165df43d5e061ba0ef3edfddb8e8d558f5b920e3e6b1d2614b44d074" }, + "@std/async@1.0.0-rc.3": { + "integrity": "f0f1cb8cca0981c1ed0a5cf1b264bc3f0a44129e53a94be1e80cebeb2817633b" + }, "@std/bytes@0.221.0": { "integrity": "64a047011cf833890a4a2ab7293ac55a1b4f5a050624ebc6a0159c357de91966" }, - "@std/cli@0.224.6": { - "integrity": "98d7e17a70c1c24980baa2b9a511b29e0a460e7a3b8e3d4e220979d77d5f348e" + "@std/cli@0.224.7": { + "integrity": "654ca6477518e5e3a0d3fabafb2789e92b8c0febf1a1d24ba4b567aba94b5977" }, "@std/collections@0.222.1": { "integrity": "234099e08eead6a87e59f4f1abdcba35df5503cfb0e852e77a19f79359ed5760" }, - "@std/encoding@0.221.0": { - "integrity": "d1dd76ef0dc5d14088411e6dc1dede53bf8308c95d1537df1214c97137208e45" - }, "@std/encoding@1.0.0-rc.2": { "integrity": "160d7674a20ebfbccdf610b3801fee91cf6e42d1c106dd46bbaf46e395cd35ef" }, @@ -158,8 +170,8 @@ "@std/fmt@0.222.1": { "integrity": "ec3382f9b0261c1ab1a5c804aa355d816515fa984cdd827ed32edfb187c0a722" }, - "@std/fmt@0.225.4": { - "integrity": "584c681cf422b70e28959b57e59012823609c087384cbf12d05f67814797fda3" + "@std/fmt@0.225.6": { + "integrity": "aba6aea27f66813cecfd9484e074a9e9845782ab0685c030e453a8a70b37afc8" }, "@std/fs@0.221.0": { "integrity": "028044450299de8ed5a716ade4e6d524399f035513b85913794f4e81f07da286", @@ -175,27 +187,27 @@ "jsr:@std/path@^0.222.1" ] }, - "@std/fs@0.229.2": { - "integrity": "c15dd65678fc3b9e5465b83cfbb1f3bb34d158ef4347f2afa0b759cce8c51bd9", + "@std/fs@0.229.3": { + "integrity": "783bca21f24da92e04c3893c9e79653227ab016c48e96b3078377ebd5222e6eb", "dependencies": [ "jsr:@std/path@1.0.0-rc.1" ] }, - "@std/http@0.224.4": { - "integrity": "7bcae028e408ab65d6802805ee9a807766c9d20a2959de576126e2f25c17ec04", + "@std/http@0.224.5": { + "integrity": "b03b5d1529f6c423badfb82f6640f9f2557b4034cd7c30655ba5bb447ff750a4", "dependencies": [ - "jsr:@std/async@^0.224.2", - "jsr:@std/cli@^0.224.6", + "jsr:@std/async@^1.0.0-rc.1", + "jsr:@std/cli@^0.224.7", "jsr:@std/encoding@1.0.0-rc.2", "jsr:@std/fmt@^0.225.4", "jsr:@std/media-types@^1.0.0-rc.1", - "jsr:@std/net@^0.224.2", - "jsr:@std/path@1.0.0-rc.1", - "jsr:@std/streams@^0.224.4" + "jsr:@std/net@^0.224.3", + "jsr:@std/path@1.0.0-rc.2", + "jsr:@std/streams@^0.224.5" ] }, - "@std/internal@1.0.0": { - "integrity": "ac6a6dfebf838582c4b4f61a6907374e27e05bedb6ce276e0f1608fe84e7cd9a" + "@std/internal@1.0.1": { + "integrity": "6f8c7544d06a11dd256c8d6ba54b11ed870aac6c5aeafff499892662c57673e6" }, "@std/io@0.221.0": { "integrity": "faf7f8700d46ab527fa05cc6167f4b97701a06c413024431c6b4d207caa010da", @@ -204,6 +216,9 @@ "jsr:@std/bytes@^0.221.0" ] }, + "@std/io@0.224.3": { + "integrity": "b402edeb99c6b3778d9ae3e9927bc9085b170b41e5a09bbb7064ab2ee394ae2f" + }, "@std/json@0.222.1": { "integrity": "ce4fb420dfd818fc2569289217842a3e70f249279f038a5e266f7b6572a2829a" }, @@ -214,11 +229,11 @@ "jsr:@std/json@^0.222.1" ] }, - "@std/media-types@1.0.0-rc.1": { - "integrity": "ff3cc8d5b536be2730fc4d446865007faf69bf4d46e7bea426d5e1d9c6ba9053" + "@std/media-types@1.0.1": { + "integrity": "f2ddc3497be0bd87ac0c9b9b26bb454f76bdc45e1b9a12146af47fab3ba2828c" }, - "@std/net@0.224.2": { - "integrity": "d5b45361e6df59eef9f6a202004fccb0944029f4db524710799d391711fac01f" + "@std/net@0.224.5": { + "integrity": "9c2ae90a5c3dc7771da5ae5e13b6f7d5d0b316c1954c5d53f2bfc1129fb757ff" }, "@std/path@0.221.0": { "integrity": "0a36f6b17314ef653a3a1649740cc8db51b25a133ecfe838f20b79a56ebe0095", @@ -241,6 +256,9 @@ "@std/path@1.0.0-rc.1": { "integrity": "b8c00ae2f19106a6bb7cbf1ab9be52aa70de1605daeb2dbdc4f87a7cbaf10ff6" }, + "@std/path@1.0.0-rc.2": { + "integrity": "39f20d37a44d1867abac8d91c169359ea6e942237a45a99ee1e091b32b921c7d" + }, "@std/regexp@0.224.1": { "integrity": "9d49636ebcfe111db1f3f2c85180497baf2d3f83b6abfe89a493c8a356cf24bc" }, @@ -256,11 +274,11 @@ "jsr:@std/io@^0.221.0" ] }, - "@std/streams@0.224.4": { - "integrity": "0601626fbab009b4b4a7407009b4af2fe8e3edcd67630ac66ba7f23542b0d7e1" + "@std/streams@0.224.5": { + "integrity": "bcde7818dd5460d474cdbd674b15f6638b9cd73cd64e52bd852fba2bd4d8ec91" }, - "@std/text@0.221.0": { - "integrity": "a2f89ceb0d8851cd33e6774064621a1da9fbc36578cf4f02c5b5bcd7e8c84b67" + "@std/text@1.0.0-rc.1": { + "integrity": "34c722203e87ee12792c8d4a0cd2ee0e001341cbce75b860fc21be19d62232b0" } }, "npm": { @@ -359,11 +377,11 @@ "remote": {}, "workspace": { "dependencies": [ - "jsr:@std/assert@^0.226.0", + "jsr:@std/assert@^1.0.0", "jsr:@std/async@^0.224.2", - "jsr:@std/fs@^0.229.2", - "jsr:@std/http@^0.224.4", - "jsr:@std/net@^0.224.2", + "jsr:@std/fs@^0.229.3", + "jsr:@std/http@^0.224.5", + "jsr:@std/net@^0.224.5", "jsr:@std/path@^0.225.2", "jsr:@std/regexp@^0.224.1", "npm:chokidar@^3.6.0", diff --git a/scripts/release.ts b/scripts/release.ts index 46a1dd0..e2ad3c5 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -30,7 +30,7 @@ import { type InputOptions, Select as _Select, type SelectOptions, -} from 'jsr:@cliffy/prompt@1.0.0-rc.4' +} from 'jsr:@cliffy/prompt@1.0.0-rc.5' import { $ } from 'jsr:@david/dax' import { Spinner } from 'jsr:@std/cli' import { bold, cyan, dim, green, magenta } from 'jsr:@std/fmt/colors' diff --git a/src/http.ts b/src/http.ts new file mode 100644 index 0000000..4c4d384 --- /dev/null +++ b/src/http.ts @@ -0,0 +1,27 @@ +/** + * @module http + * + * @description + * A collection of HTTP utilities. + */ + +import { STATUS_TEXT, type StatusCode } from '@std/http' + +// re-export everything from the standard HTTP module +export * from '@std/http' + +/** + * Creates a standard response with the given status code. + * @param status The status code. + * @param init The response init. + * @returns The response. + * + * @example + * ```ts + * const response = createStandardResponse(STATUS_CODE.NotFound) + * ``` + */ +export function createStandardResponse(status: StatusCode, init?: ResponseInit): Response { + const statusText = STATUS_TEXT[status] + return new Response(statusText, { status, statusText, ...init }) +} diff --git a/src/router.ts b/src/router.ts index 61ea97f..a339ab8 100644 --- a/src/router.ts +++ b/src/router.ts @@ -23,11 +23,12 @@ import { debounce } from '@std/async' import { walk } from '@std/fs' -import { serveDir, type ServeDirOptions, STATUS_CODE, STATUS_TEXT, type StatusCode } from '@std/http' +import { serveDir, type ServeDirOptions, STATUS_CODE } from '@std/http' import { joinGlobs, toFileUrl } from '@std/path' import { normalize as posixNormalize } from '@std/path/posix/normalize' import { escape } from '@std/regexp' import chokidar from 'chokidar' +import { createStandardResponse } from './http.ts' const methods = new Set(['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH']) @@ -375,24 +376,6 @@ export async function createRouter( } } -/** - * Creates a standard response with the given status code. - * @param status The status code. - * @param init The response init. - * @returns The response. - * - * @example - * ```ts - * const response = createStandardResponse(STATUS_CODE.NotFound) - * ``` - */ -export function createStandardResponse(status: StatusCode, init?: ResponseInit): Response { - const statusText = STATUS_TEXT[status] - return new Response(statusText, { status, statusText, ...init }) -} - -export { STATUS_CODE } from '@std/http' - /** * TODO: * - use URLPatternList once it's available (https://github.com/whatwg/urlpattern/pull/166)