mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 20:37:21 +00:00
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
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import type { SvelteKitBkndConfig } from "bknd/adapter/sveltekit";
|
|
import { em, entity, text, libsql } from "bknd";
|
|
import { createClient } from "@libsql/client";
|
|
|
|
const schema = em({
|
|
todos: entity("todos", {
|
|
title: text().required(),
|
|
done: text(),
|
|
}),
|
|
});
|
|
|
|
export default {
|
|
connection: libsql(
|
|
createClient({
|
|
url: "file:data.db",
|
|
})
|
|
),
|
|
config: {
|
|
data: schema.toJSON(),
|
|
auth: {
|
|
enabled: true,
|
|
allow_register: true,
|
|
jwt: {
|
|
issuer: "bknd-sveltekit-example",
|
|
secret: "dev-secret-change-in-production-1234567890abcdef",
|
|
},
|
|
roles: {
|
|
admin: {
|
|
implicit_allow: true,
|
|
},
|
|
default: {
|
|
permissions: ["data.entity.read", "data.entity.create"],
|
|
is_default: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
options: {
|
|
seed: async (ctx) => {
|
|
await ctx.app.module.auth.createUser({
|
|
email: "admin@example.com",
|
|
password: "password",
|
|
role: "admin",
|
|
});
|
|
|
|
await ctx.em.mutator("todos").insertMany([
|
|
{ title: "Learn bknd", done: "true" },
|
|
{ title: "Build with SvelteKit", done: "false" },
|
|
]);
|
|
},
|
|
},
|
|
} as const satisfies SvelteKitBkndConfig;
|