From 64d50552b76bf268eb77897caf69e104f94eea45 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 20 Apr 2024 18:54:15 -0500 Subject: [PATCH] Import hono with an import alias --- deno.json | 2 ++ src/app.ts | 18 ++++-------------- src/controllers/api/fallback.ts | 2 +- src/deps.ts | 10 ---------- src/middleware/auth19.ts | 3 ++- src/middleware/auth98.ts | 2 +- src/middleware/cache.ts | 3 ++- src/signers/APISigner.ts | 3 ++- src/utils/api.ts | 3 ++- 9 files changed, 16 insertions(+), 30 deletions(-) diff --git a/deno.json b/deno.json index d04e960..7581193 100644 --- a/deno.json +++ b/deno.json @@ -15,6 +15,8 @@ "@/": "./src/", "@nostrify/nostrify": "jsr:@nostrify/nostrify@^0.9.7", "~/fixtures/": "./fixtures/", + "hono": "https://deno.land/x/hono@v3.10.1/mod.ts", + "hono/middleware": "https://deno.land/x/hono@v3.10.1/middleware.ts", "kysely": "npm:kysely@^0.26.3", "kysely_deno_postgres": "https://deno.land/x/kysely_deno_postgres@v0.4.0/mod.ts" }, diff --git a/src/app.ts b/src/app.ts index a00bd2a..28852dd 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,21 +1,11 @@ import { NostrEvent } from '@nostrify/nostrify'; +import { type Context, Env as HonoEnv, type Handler, Hono, Input as HonoInput, type MiddlewareHandler } from 'hono'; +import { cors, logger, serveStatic } from 'hono/middleware'; import { Conf } from '@/config.ts'; import '@/cron.ts'; import { type User } from '@/db/users.ts'; -import { - type Context, - cors, - Debug, - type Handler, - Hono, - type HonoEnv, - Input, - logger, - type MiddlewareHandler, - sentryMiddleware, - serveStatic, -} from '@/deps.ts'; +import { Debug, sentryMiddleware } from '@/deps.ts'; import '@/firehose.ts'; import { Time } from '@/utils.ts'; @@ -103,7 +93,7 @@ interface AppEnv extends HonoEnv { type AppContext = Context; type AppMiddleware = MiddlewareHandler; -type AppController = Handler>; +type AppController = Handler>; const app = new Hono(); diff --git a/src/controllers/api/fallback.ts b/src/controllers/api/fallback.ts index b46460e..b947928 100644 --- a/src/controllers/api/fallback.ts +++ b/src/controllers/api/fallback.ts @@ -1,4 +1,4 @@ -import type { Context } from '@/deps.ts'; +import type { Context } from 'hono'; const emptyArrayController = (c: Context) => c.json([]); const emptyObjectController = (c: Context) => c.json({}); diff --git a/src/deps.ts b/src/deps.ts index 14fa9ae..f8ba0a8 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -1,14 +1,4 @@ import 'https://gitlab.com/soapbox-pub/deno-safe-fetch/-/raw/v1.0.0/load.ts'; -export { - type Context, - type Env as HonoEnv, - type Handler, - Hono, - HTTPException, - type Input, - type MiddlewareHandler, -} from 'https://deno.land/x/hono@v3.10.1/mod.ts'; -export { cors, logger, serveStatic } from 'https://deno.land/x/hono@v3.10.1/middleware.ts'; export { z } from 'https://deno.land/x/zod@v3.21.4/mod.ts'; export { RelayPoolWorker } from 'npm:nostr-relaypool2@0.6.34'; export { diff --git a/src/middleware/auth19.ts b/src/middleware/auth19.ts index 19344fb..d81c257 100644 --- a/src/middleware/auth19.ts +++ b/src/middleware/auth19.ts @@ -1,5 +1,6 @@ +import { HTTPException } from 'hono'; import { type AppMiddleware } from '@/app.ts'; -import { getPublicKey, HTTPException, nip19 } from '@/deps.ts'; +import { getPublicKey, nip19 } from '@/deps.ts'; /** We only accept "Bearer" type. */ const BEARER_REGEX = new RegExp(`^Bearer (${nip19.BECH32_REGEX.source})$`); diff --git a/src/middleware/auth98.ts b/src/middleware/auth98.ts index 6c99553..db025ae 100644 --- a/src/middleware/auth98.ts +++ b/src/middleware/auth98.ts @@ -1,6 +1,6 @@ import { NostrEvent } from '@nostrify/nostrify'; +import { HTTPException } from 'hono'; import { type AppContext, type AppMiddleware } from '@/app.ts'; -import { HTTPException } from '@/deps.ts'; import { buildAuthEventTemplate, parseAuthRequest, diff --git a/src/middleware/cache.ts b/src/middleware/cache.ts index 87de611..fe28c5f 100644 --- a/src/middleware/cache.ts +++ b/src/middleware/cache.ts @@ -1,4 +1,5 @@ -import { Debug, type MiddlewareHandler } from '@/deps.ts'; +import { type MiddlewareHandler } from 'hono'; +import { Debug } from '@/deps.ts'; import ExpiringCache from '@/utils/expiring-cache.ts'; const debug = Debug('ditto:middleware:cache'); diff --git a/src/signers/APISigner.ts b/src/signers/APISigner.ts index a2a657e..5428043 100644 --- a/src/signers/APISigner.ts +++ b/src/signers/APISigner.ts @@ -1,7 +1,8 @@ import { NostrEvent, NostrSigner, NSecSigner } from '@nostrify/nostrify'; +import { HTTPException } from 'hono'; import { type AppContext } from '@/app.ts'; import { Conf } from '@/config.ts'; -import { HTTPException, Stickynotes } from '@/deps.ts'; +import { Stickynotes } from '@/deps.ts'; import { connectResponseSchema } from '@/schemas/nostr.ts'; import { jsonSchema } from '@/schema.ts'; import { AdminSigner } from '@/signers/AdminSigner.ts'; diff --git a/src/utils/api.ts b/src/utils/api.ts index c33873e..8e57c1d 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -1,7 +1,8 @@ import { NostrEvent, NostrFilter } from '@nostrify/nostrify'; +import { type Context, HTTPException } from 'hono'; import { type AppContext } from '@/app.ts'; import { Conf } from '@/config.ts'; -import { type Context, Debug, EventTemplate, HTTPException, parseFormData, type TypeFest, z } from '@/deps.ts'; +import { Debug, EventTemplate, parseFormData, type TypeFest, z } from '@/deps.ts'; import * as pipeline from '@/pipeline.ts'; import { AdminSigner } from '@/signers/AdminSigner.ts'; import { APISigner } from '@/signers/APISigner.ts';