feat: add SvelteKit adapter

Add framework adapter for SvelteKit with:
- `getApp()` - get bknd app instance
- `serve()` - request handler for hooks.server.ts

Usage in hooks.server.ts:
```typescript
import { serve } from "bknd/adapter/sveltekit";
import config from "../bknd.config";

const bkndHandler = serve(config);

export const handle = async ({ event, resolve }) => {
  if (event.url.pathname.startsWith("/api/")) {
    return bkndHandler(event);
  }
  return resolve(event);
};
```

Includes:
- Adapter implementation (app/src/adapter/sveltekit/)
- Test suite
- Working example (examples/sveltekit/)
- Package exports and types
This commit is contained in:
Szymon Rączka
2025-12-26 16:55:10 +01:00
parent 81f3914e7f
commit 90b4de7093
16 changed files with 260 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import { type FrameworkBkndConfig, createFrameworkApp } from "bknd/adapter";
type SvelteKitEnv = NodeJS.ProcessEnv;
type TSvelteKit = {
request: Request;
};
export type SvelteKitBkndConfig<Env = SvelteKitEnv> = FrameworkBkndConfig<Env>;
export async function getApp<Env = SvelteKitEnv>(
config: SvelteKitBkndConfig<Env> = {},
args: Env = process.env as Env,
) {
return await createFrameworkApp(config, args);
}
export function serve<Env = SvelteKitEnv>(
config: SvelteKitBkndConfig<Env> = {},
args: Env = process.env as Env,
) {
return async (fnArgs: TSvelteKit) => {
return (await getApp(config, args)).fetch(fnArgs.request);
};
}