diff --git a/app/src/adapter/adapter-test-suite.ts b/app/src/adapter/adapter-test-suite.ts index 38890ee..8ba2db3 100644 --- a/app/src/adapter/adapter-test-suite.ts +++ b/app/src/adapter/adapter-test-suite.ts @@ -1,5 +1,5 @@ import type { TestRunner } from "core/test"; -import type { BkndConfig, DefaultArgs, FrameworkOptions, RuntimeOptions } from "./index"; +import type { BkndConfig, DefaultArgs } from "./index"; import type { App } from "App"; export function adapterTestSuite< @@ -13,16 +13,8 @@ export function adapterTestSuite< label = "app", overrides = {}, }: { - makeApp: ( - config: Config, - args?: Args, - opts?: RuntimeOptions | FrameworkOptions, - ) => Promise; - makeHandler?: ( - config?: Config, - args?: Args, - opts?: RuntimeOptions | FrameworkOptions, - ) => (request: Request) => Promise; + makeApp: (config: Config, args?: Args) => Promise; + makeHandler?: (config?: Config, args?: Args) => (request: Request) => Promise; label?: string; overrides?: { dbUrl?: string; @@ -30,7 +22,6 @@ export function adapterTestSuite< }, ) { const { test, expect, mock } = testRunner; - const id = crypto.randomUUID(); test(`creates ${label}`, async () => { const beforeBuild = mock(async () => null) as any; @@ -53,7 +44,6 @@ export function adapterTestSuite< url: overrides.dbUrl ?? ":memory:", origin: "localhost", } as any, - { force: false, id }, ); expect(app).toBeDefined(); expect(app.toJSON().server.cors.origin).toEqual("localhost"); @@ -68,8 +58,8 @@ export function adapterTestSuite< return { res, data }; }; - test.skip("responds with the same app id", async () => { - const fetcher = makeHandler(undefined, undefined, { force: false, id }); + /* test.skip("responds with the same app id", async () => { + const fetcher = makeHandler(undefined, undefined, { id }); const { res, data } = await getConfig(fetcher); expect(res.ok).toBe(true); @@ -79,12 +69,12 @@ export function adapterTestSuite< test.skip("creates fresh & responds to api config", async () => { // set the same id, but force recreate - const fetcher = makeHandler(undefined, undefined, { id, force: true }); + const fetcher = makeHandler(undefined, undefined, { id }); const { res, data } = await getConfig(fetcher); expect(res.ok).toBe(true); expect(res.status).toBe(200); expect(data.server.cors.origin).toEqual("*"); - }); + }); */ } } diff --git a/app/src/adapter/astro/astro.adapter.spec.ts b/app/src/adapter/astro/astro.adapter.spec.ts index 3f3d1e8..54f3eb2 100644 --- a/app/src/adapter/astro/astro.adapter.spec.ts +++ b/app/src/adapter/astro/astro.adapter.spec.ts @@ -10,6 +10,6 @@ afterAll(enableConsoleLog); describe("astro adapter", () => { adapterTestSuite(bunTestRunner, { makeApp: astro.getApp, - makeHandler: (c, a, o) => (request: Request) => astro.serve(c, a, o)({ request }), + makeHandler: (c, a) => (request: Request) => astro.serve(c, a)({ request }), }); }); diff --git a/app/src/adapter/astro/astro.adapter.ts b/app/src/adapter/astro/astro.adapter.ts index a684f73..7f24923 100644 --- a/app/src/adapter/astro/astro.adapter.ts +++ b/app/src/adapter/astro/astro.adapter.ts @@ -1,4 +1,4 @@ -import { type FrameworkBkndConfig, createFrameworkApp, type FrameworkOptions } from "bknd/adapter"; +import { type FrameworkBkndConfig, createFrameworkApp } from "bknd/adapter"; type AstroEnv = NodeJS.ProcessEnv; type TAstro = { @@ -9,17 +9,12 @@ export type AstroBkndConfig = FrameworkBkndConfig; export async function getApp( config: AstroBkndConfig = {}, args: Env = {} as Env, - opts: FrameworkOptions = {}, ) { - return await createFrameworkApp(config, args ?? import.meta.env, opts); + return await createFrameworkApp(config, args ?? import.meta.env); } -export function serve( - config: AstroBkndConfig = {}, - args: Env = {} as Env, - opts?: FrameworkOptions, -) { +export function serve(config: AstroBkndConfig = {}, args: Env = {} as Env) { return async (fnArgs: TAstro) => { - return (await getApp(config, args, opts)).fetch(fnArgs.request); + return (await getApp(config, args)).fetch(fnArgs.request); }; } diff --git a/app/src/adapter/aws/aws-lambda.adapter.ts b/app/src/adapter/aws/aws-lambda.adapter.ts index ad19047..8c43b3d 100644 --- a/app/src/adapter/aws/aws-lambda.adapter.ts +++ b/app/src/adapter/aws/aws-lambda.adapter.ts @@ -1,7 +1,7 @@ import type { App } from "bknd"; import { handle } from "hono/aws-lambda"; import { serveStatic } from "@hono/node-server/serve-static"; -import { type RuntimeBkndConfig, createRuntimeApp, type RuntimeOptions } from "bknd/adapter"; +import { type RuntimeBkndConfig, createRuntimeApp } from "bknd/adapter"; type AwsLambdaEnv = object; export type AwsLambdaBkndConfig = @@ -20,7 +20,6 @@ export type AwsLambdaBkndConfig = export async function createApp( { adminOptions = false, assets, ...config }: AwsLambdaBkndConfig = {}, args: Env = {} as Env, - opts?: RuntimeOptions, ): Promise { let additional: Partial = { adminOptions, @@ -57,17 +56,15 @@ export async function createApp( ...additional, }, args ?? process.env, - opts, ); } export function serve( config: AwsLambdaBkndConfig = {}, args: Env = {} as Env, - opts?: RuntimeOptions, ) { return async (event) => { - const app = await createApp(config, args, opts); + const app = await createApp(config, args); return await handle(app.server)(event); }; } diff --git a/app/src/adapter/aws/aws.adapter.spec.ts b/app/src/adapter/aws/aws.adapter.spec.ts index e6873d8..e3007e4 100644 --- a/app/src/adapter/aws/aws.adapter.spec.ts +++ b/app/src/adapter/aws/aws.adapter.spec.ts @@ -11,8 +11,8 @@ describe("aws adapter", () => { adapterTestSuite(bunTestRunner, { makeApp: awsLambda.createApp, // @todo: add a request to lambda event translator? - makeHandler: (c, a, o) => async (request: Request) => { - const app = await awsLambda.createApp(c, a, o); + makeHandler: (c, a) => async (request: Request) => { + const app = await awsLambda.createApp(c, a); return app.fetch(request); }, }); diff --git a/app/src/adapter/bun/bun.adapter.ts b/app/src/adapter/bun/bun.adapter.ts index be87da1..00b61b5 100644 --- a/app/src/adapter/bun/bun.adapter.ts +++ b/app/src/adapter/bun/bun.adapter.ts @@ -1,7 +1,7 @@ /// import path from "node:path"; -import { type RuntimeBkndConfig, createRuntimeApp, type RuntimeOptions } from "bknd/adapter"; +import { type RuntimeBkndConfig, createRuntimeApp } from "bknd/adapter"; import { registerLocalMediaAdapter } from "."; import { config, type App } from "bknd"; import type { ServeOptions } from "bun"; @@ -13,7 +13,6 @@ export type BunBkndConfig = RuntimeBkndConfig & Omit( { distPath, serveStatic: _serveStatic, ...config }: BunBkndConfig = {}, args: Env = {} as Env, - opts?: RuntimeOptions, ) { const root = path.resolve(distPath ?? "./node_modules/bknd/dist", "static"); registerLocalMediaAdapter(); @@ -28,19 +27,17 @@ export async function createApp( ...config, }, args ?? (process.env as Env), - opts, ); } export function createHandler( config: BunBkndConfig = {}, args: Env = {} as Env, - opts?: RuntimeOptions, ) { let app: App | undefined; return async (req: Request) => { if (!app) { - app = await createApp(config, args ?? (process.env as Env), opts); + app = await createApp(config, args ?? (process.env as Env)); } return app.fetch(req); }; @@ -60,7 +57,6 @@ export function serve( ...serveOptions }: BunBkndConfig = {}, args: Env = {} as Env, - opts?: RuntimeOptions, ) { Bun.serve({ ...serveOptions, @@ -77,7 +73,6 @@ export function serve( serveStatic, }, args, - opts, ), }); diff --git a/app/src/adapter/cloudflare/cloudflare-workers.adapter.spec.ts b/app/src/adapter/cloudflare/cloudflare-workers.adapter.spec.ts index 21b1f39..65477b6 100644 --- a/app/src/adapter/cloudflare/cloudflare-workers.adapter.spec.ts +++ b/app/src/adapter/cloudflare/cloudflare-workers.adapter.spec.ts @@ -41,10 +41,10 @@ describe("cf adapter", () => { }); adapterTestSuite>(bunTestRunner, { - makeApp: async (c, a, o) => { - return await createApp(c, { env: a } as any, o); + makeApp: async (c, a) => { + return await createApp(c, { env: a } as any); }, - makeHandler: (c, a, o) => { + makeHandler: (c, a) => { console.log("args", a); return async (request: any) => { const app = await createApp( @@ -53,7 +53,6 @@ describe("cf adapter", () => { connection: { url: DB_URL }, }, a as any, - o, ); return app.fetch(request); }; diff --git a/app/src/adapter/cloudflare/cloudflare-workers.adapter.ts b/app/src/adapter/cloudflare/cloudflare-workers.adapter.ts index 091dc30..05c8332 100644 --- a/app/src/adapter/cloudflare/cloudflare-workers.adapter.ts +++ b/app/src/adapter/cloudflare/cloudflare-workers.adapter.ts @@ -5,7 +5,7 @@ import { Hono } from "hono"; import { serveStatic } from "hono/cloudflare-workers"; import type { MaybePromise } from "bknd"; import { $console } from "bknd/utils"; -import { createRuntimeApp, type RuntimeOptions } from "bknd/adapter"; +import { createRuntimeApp } from "bknd/adapter"; import { registerAsyncsExecutionContext, makeConfig, type CloudflareContext } from "./config"; declare global { @@ -36,10 +36,6 @@ export type CloudflareBkndConfig = RuntimeBkndConfig & export async function createApp( config: CloudflareBkndConfig, ctx: Partial> = {}, - opts: RuntimeOptions = { - // by default, require the app to be rebuilt every time - force: true, - }, ) { const appConfig = await makeConfig( { @@ -53,7 +49,7 @@ export async function createApp( }, ctx, ); - return await createRuntimeApp(appConfig, ctx?.env, opts); + return await createRuntimeApp(appConfig, ctx?.env); } // compatiblity diff --git a/app/src/adapter/index.ts b/app/src/adapter/index.ts index e79c3a4..fbb5e5c 100644 --- a/app/src/adapter/index.ts +++ b/app/src/adapter/index.ts @@ -21,13 +21,6 @@ export type BkndConfig = CreateAppConfig & { export type FrameworkBkndConfig = BkndConfig; -export type CreateAdapterAppOptions = { - force?: boolean; - id?: string; -}; -export type FrameworkOptions = CreateAdapterAppOptions; -export type RuntimeOptions = CreateAdapterAppOptions; - export type RuntimeBkndConfig = BkndConfig & { distPath?: string; serveStatic?: MiddlewareHandler | [string, MiddlewareHandler]; @@ -63,7 +56,6 @@ const apps = new Map(); export async function createAdapterApp( config: Config = {} as Config, args?: Args, - opts?: CreateAdapterAppOptions, ): Promise { const appConfig = await makeConfig(config, args); if (!appConfig.connection || !Connection.isConnection(appConfig.connection)) { @@ -85,9 +77,8 @@ export async function createAdapterApp( config: FrameworkBkndConfig = {}, args?: Args, - opts?: FrameworkOptions, ): Promise { - const app = await createAdapterApp(config, args, opts); + const app = await createAdapterApp(config, args); if (!app.isBuilt()) { if (config.onBuilt) { @@ -110,9 +101,8 @@ export async function createFrameworkApp( export async function createRuntimeApp( { serveStatic, adminOptions, ...config }: RuntimeBkndConfig = {}, args?: Args, - opts?: RuntimeOptions, ): Promise { - const app = await createAdapterApp(config, args, opts); + const app = await createAdapterApp(config, args); if (!app.isBuilt()) { app.emgr.onEvent( diff --git a/app/src/adapter/nextjs/nextjs.adapter.ts b/app/src/adapter/nextjs/nextjs.adapter.ts index bce7009..ba0953b 100644 --- a/app/src/adapter/nextjs/nextjs.adapter.ts +++ b/app/src/adapter/nextjs/nextjs.adapter.ts @@ -1,4 +1,4 @@ -import { createFrameworkApp, type FrameworkBkndConfig, type FrameworkOptions } from "bknd/adapter"; +import { createFrameworkApp, type FrameworkBkndConfig } from "bknd/adapter"; import { isNode } from "bknd/utils"; import type { NextApiRequest } from "next"; @@ -10,9 +10,8 @@ export type NextjsBkndConfig = FrameworkBkndConfig & { export async function getApp( config: NextjsBkndConfig, args: Env = {} as Env, - opts?: FrameworkOptions, ) { - return await createFrameworkApp(config, args ?? (process.env as Env), opts); + return await createFrameworkApp(config, args ?? (process.env as Env)); } function getCleanRequest(req: Request, cleanRequest: NextjsBkndConfig["cleanRequest"]) { @@ -41,10 +40,9 @@ function getCleanRequest(req: Request, cleanRequest: NextjsBkndConfig["cleanRequ export function serve( { cleanRequest, ...config }: NextjsBkndConfig = {}, args: Env = {} as Env, - opts?: FrameworkOptions, ) { return async (req: Request) => { - const app = await getApp(config, args, opts); + const app = await getApp(config, args); const request = getCleanRequest(req, cleanRequest); return app.fetch(request); }; diff --git a/app/src/adapter/node/node.adapter.ts b/app/src/adapter/node/node.adapter.ts index 5a2c058..fd96086 100644 --- a/app/src/adapter/node/node.adapter.ts +++ b/app/src/adapter/node/node.adapter.ts @@ -2,7 +2,7 @@ import path from "node:path"; import { serve as honoServe } from "@hono/node-server"; import { serveStatic } from "@hono/node-server/serve-static"; import { registerLocalMediaAdapter } from "adapter/node/storage"; -import { type RuntimeBkndConfig, createRuntimeApp, type RuntimeOptions } from "bknd/adapter"; +import { type RuntimeBkndConfig, createRuntimeApp } from "bknd/adapter"; import { config as $config, type App } from "bknd"; import { $console } from "bknd/utils"; @@ -18,7 +18,6 @@ export type NodeBkndConfig = RuntimeBkndConfig & { export async function createApp( { distPath, relativeDistPath, ...config }: NodeBkndConfig = {}, args: Env = {} as Env, - opts?: RuntimeOptions, ) { const root = path.relative( process.cwd(), @@ -36,19 +35,17 @@ export async function createApp( }, // @ts-ignore args ?? { env: process.env }, - opts, ); } export function createHandler( config: NodeBkndConfig = {}, args: Env = {} as Env, - opts?: RuntimeOptions, ) { let app: App | undefined; return async (req: Request) => { if (!app) { - app = await createApp(config, args ?? (process.env as Env), opts); + app = await createApp(config, args ?? (process.env as Env)); } return app.fetch(req); }; @@ -57,13 +54,12 @@ export function createHandler( export function serve( { port = $config.server.default_port, hostname, listener, ...config }: NodeBkndConfig = {}, args: Env = {} as Env, - opts?: RuntimeOptions, ) { honoServe( { port, hostname, - fetch: createHandler(config, args, opts), + fetch: createHandler(config, args), }, (connInfo) => { $console.log(`Server is running on http://localhost:${connInfo.port}`); diff --git a/app/src/adapter/react-router/react-router.adapter.spec.ts b/app/src/adapter/react-router/react-router.adapter.spec.ts index 25ef895..bb525c7 100644 --- a/app/src/adapter/react-router/react-router.adapter.spec.ts +++ b/app/src/adapter/react-router/react-router.adapter.spec.ts @@ -10,6 +10,6 @@ afterAll(enableConsoleLog); describe("react-router adapter", () => { adapterTestSuite(bunTestRunner, { makeApp: rr.getApp, - makeHandler: (c, a, o) => (request: Request) => rr.serve(c, a?.env, o)({ request }), + makeHandler: (c, a) => (request: Request) => rr.serve(c, a?.env)({ request }), }); }); diff --git a/app/src/adapter/react-router/react-router.adapter.ts b/app/src/adapter/react-router/react-router.adapter.ts index 4474509..f37260d 100644 --- a/app/src/adapter/react-router/react-router.adapter.ts +++ b/app/src/adapter/react-router/react-router.adapter.ts @@ -1,5 +1,4 @@ import { type FrameworkBkndConfig, createFrameworkApp } from "bknd/adapter"; -import type { FrameworkOptions } from "adapter"; type ReactRouterEnv = NodeJS.ProcessEnv; type ReactRouterFunctionArgs = { @@ -10,17 +9,15 @@ export type ReactRouterBkndConfig = FrameworkBkndConfig( config: ReactRouterBkndConfig, args: Env = {} as Env, - opts?: FrameworkOptions, ) { - return await createFrameworkApp(config, args ?? process.env, opts); + return await createFrameworkApp(config, args ?? process.env); } export function serve( config: ReactRouterBkndConfig = {}, args: Env = {} as Env, - opts?: FrameworkOptions, ) { return async (fnArgs: ReactRouterFunctionArgs) => { - return (await getApp(config, args, opts)).fetch(fnArgs.request); + return (await getApp(config, args)).fetch(fnArgs.request); }; } diff --git a/app/src/adapter/vite/vite.adapter.ts b/app/src/adapter/vite/vite.adapter.ts index c69bc1e..a4cb346 100644 --- a/app/src/adapter/vite/vite.adapter.ts +++ b/app/src/adapter/vite/vite.adapter.ts @@ -1,7 +1,7 @@ import { serveStatic } from "@hono/node-server/serve-static"; import { type DevServerOptions, default as honoViteDevServer } from "@hono/vite-dev-server"; import type { App } from "bknd"; -import { type RuntimeBkndConfig, createRuntimeApp, type FrameworkOptions } from "bknd/adapter"; +import { type RuntimeBkndConfig, createRuntimeApp } from "bknd/adapter"; import { registerLocalMediaAdapter } from "bknd/adapter/node"; import { devServerConfig } from "./dev-server-config"; import type { MiddlewareHandler } from "hono"; @@ -30,7 +30,6 @@ ${addBkndContext ? "" : ""} async function createApp( config: ViteBkndConfig = {}, env: ViteEnv = {} as ViteEnv, - opts: FrameworkOptions = {}, ): Promise { registerLocalMediaAdapter(); return await createRuntimeApp( @@ -47,18 +46,13 @@ async function createApp( ], }, env, - opts, ); } -export function serve( - config: ViteBkndConfig = {}, - args?: ViteEnv, - opts?: FrameworkOptions, -) { +export function serve(config: ViteBkndConfig = {}, args?: ViteEnv) { return { async fetch(request: Request, env: any, ctx: ExecutionContext) { - const app = await createApp(config, env, opts); + const app = await createApp(config, env); return app.fetch(request, env, ctx); }, };