mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 21:06:04 +00:00
chore: updated cf deps, improved vite dev
This commit is contained in:
@@ -78,10 +78,10 @@
|
||||
"@aws-sdk/client-s3": "^3.758.0",
|
||||
"@bluwy/giget-core": "^0.1.2",
|
||||
"@clack/prompts": "^0.11.0",
|
||||
"@cloudflare/vitest-pool-workers": "^0.8.38",
|
||||
"@cloudflare/vitest-pool-workers": "^0.9.3",
|
||||
"@cloudflare/workers-types": "^4.20250606.0",
|
||||
"@dagrejs/dagre": "^1.1.4",
|
||||
"@hono/vite-dev-server": "^0.19.1",
|
||||
"@hono/vite-dev-server": "^0.21.0",
|
||||
"@hookform/resolvers": "^4.1.3",
|
||||
"@libsql/client": "^0.15.9",
|
||||
"@mantine/modals": "^7.17.1",
|
||||
@@ -131,7 +131,8 @@
|
||||
"vite-tsconfig-paths": "^5.1.4",
|
||||
"vitest": "^3.0.9",
|
||||
"wouter": "^3.6.0",
|
||||
"wrangler": "^4.37.1"
|
||||
"wrangler": "^4.37.1",
|
||||
"miniflare": "^4.20250913.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@hono/node-server": "^1.14.3"
|
||||
|
||||
@@ -52,7 +52,6 @@ export async function makeConfig<Args = DefaultArgs>(
|
||||
}
|
||||
|
||||
// a map that contains all apps by id
|
||||
const apps = new Map<string, App>();
|
||||
export async function createAdapterApp<Config extends BkndConfig = BkndConfig, Args = DefaultArgs>(
|
||||
config: Config = {} as Config,
|
||||
args?: Args,
|
||||
|
||||
@@ -9,18 +9,28 @@ export const PLATFORMS = ["node", "bun"] as const;
|
||||
export type Platform = (typeof PLATFORMS)[number];
|
||||
|
||||
export async function serveStatic(server: Platform): Promise<MiddlewareHandler> {
|
||||
const onNotFound = (path: string) => {
|
||||
$console.debug("Couldn't resolve static file at", path);
|
||||
};
|
||||
|
||||
switch (server) {
|
||||
case "node": {
|
||||
const m = await import("@hono/node-server/serve-static");
|
||||
const root = getRelativeDistPath() + "/static";
|
||||
$console.log("Serving static files from", root);
|
||||
return m.serveStatic({
|
||||
// somehow different for node
|
||||
root: getRelativeDistPath() + "/static",
|
||||
root,
|
||||
onNotFound,
|
||||
});
|
||||
}
|
||||
case "bun": {
|
||||
const m = await import("hono/bun");
|
||||
const root = path.resolve(getRelativeDistPath(), "static");
|
||||
$console.log("Serving static files from", root);
|
||||
return m.serveStatic({
|
||||
root: path.resolve(getRelativeDistPath(), "static"),
|
||||
root,
|
||||
onNotFound,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,7 +571,7 @@ export class DbModuleManager extends ModuleManager {
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
$console.error(`[Safe Mutate] failed "${name}":`, String(e));
|
||||
$console.error(`[Safe Mutate] failed "${name}":`, e);
|
||||
|
||||
// revert to previous config & rebuild using original listener
|
||||
this.revertModules();
|
||||
|
||||
106
app/vite.dev.ts
106
app/vite.dev.ts
@@ -1,76 +1,62 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { serveStatic } from "@hono/node-server/serve-static";
|
||||
import { showRoutes } from "hono/dev";
|
||||
import { App, registries } from "./src";
|
||||
import { App, registries, type CreateAppConfig } from "./src";
|
||||
import { StorageLocalAdapter } from "./src/adapter/node";
|
||||
import type { Connection } from "./src/data/connection/Connection";
|
||||
import { __bknd } from "modules/db/DbModuleManager";
|
||||
import { nodeSqlite } from "./src/adapter/node/connection/NodeSqliteConnection";
|
||||
import { libsql } from "./src/data/connection/sqlite/libsql/LibsqlConnection";
|
||||
import { $console } from "core/utils/console";
|
||||
import { createClient } from "@libsql/client";
|
||||
import util from "node:util";
|
||||
import { d1Sqlite } from "adapter/cloudflare/connection/D1Connection";
|
||||
|
||||
util.inspect.defaultOptions.depth = 5;
|
||||
|
||||
registries.media.register("local", StorageLocalAdapter);
|
||||
|
||||
const config: CreateAppConfig = {};
|
||||
|
||||
const dbType = import.meta.env.VITE_DB_TYPE ?? "node";
|
||||
$console.debug("Using db type", dbType);
|
||||
|
||||
let dbUrl = import.meta.env.VITE_DB_URL ?? ":memory:";
|
||||
|
||||
const example = import.meta.env.VITE_EXAMPLE;
|
||||
|
||||
let connection: Connection;
|
||||
|
||||
if (import.meta.env.VITE_DB_LIBSQL_URL) {
|
||||
connection = libsql(
|
||||
createClient({
|
||||
url: import.meta.env.VITE_DB_LIBSQL_URL!,
|
||||
authToken: import.meta.env.VITE_DB_LIBSQL_TOKEN!,
|
||||
}),
|
||||
);
|
||||
$console.debug("Using libsql connection", import.meta.env.VITE_DB_URL);
|
||||
} else {
|
||||
const dbUrl = example ? `file:.configs/${example}.db` : import.meta.env.VITE_DB_URL;
|
||||
if (dbUrl) {
|
||||
connection = nodeSqlite({ url: dbUrl });
|
||||
$console.debug("Using node-sqlite connection", dbUrl);
|
||||
} else if (import.meta.env.VITE_DB_LIBSQL_URL) {
|
||||
connection = libsql(
|
||||
createClient({
|
||||
url: import.meta.env.VITE_DB_LIBSQL_URL!,
|
||||
authToken: import.meta.env.VITE_DB_LIBSQL_TOKEN!,
|
||||
}),
|
||||
);
|
||||
$console.debug("Using libsql connection", import.meta.env.VITE_DB_URL);
|
||||
} else {
|
||||
connection = nodeSqlite();
|
||||
$console.debug("No connection provided, using in-memory database");
|
||||
}
|
||||
if (example) {
|
||||
const configPath = `.configs/${example}.json`;
|
||||
$console.debug("Loading config from", configPath);
|
||||
const exampleConfig = JSON.parse(await readFile(configPath, "utf-8"));
|
||||
config.config = exampleConfig;
|
||||
dbUrl = `file:.configs/${example}.db`;
|
||||
}
|
||||
|
||||
/* if (example) {
|
||||
const { version, ...config } = JSON.parse(await readFile(`.configs/${example}.json`, "utf-8"));
|
||||
|
||||
// create db with config
|
||||
const conn = new LibsqlConnection(credentials);
|
||||
const em = new EntityManager([__bknd], conn);
|
||||
try {
|
||||
await em.schema().sync({ force: true });
|
||||
} catch (e) {}
|
||||
const { data: existing } = await em.repo(__bknd).findOne({ type: "config" });
|
||||
|
||||
if (!existing || existing.version !== version) {
|
||||
if (existing) await em.mutator(__bknd).deleteOne(existing.id);
|
||||
await em.mutator(__bknd).insertOne({
|
||||
version,
|
||||
json: config,
|
||||
created_at: new Date(),
|
||||
type: "config",
|
||||
});
|
||||
} else {
|
||||
await em.mutator(__bknd).updateOne(existing.id, {
|
||||
json: config,
|
||||
});
|
||||
switch (dbType) {
|
||||
case "libsql": {
|
||||
$console.debug("Using libsql connection", dbUrl);
|
||||
const authToken = import.meta.env.VITE_DB_LIBSQL_TOKEN;
|
||||
config.connection = libsql(
|
||||
createClient({
|
||||
url: dbUrl,
|
||||
authToken,
|
||||
}),
|
||||
);
|
||||
break;
|
||||
}
|
||||
} */
|
||||
case "d1": {
|
||||
$console.debug("Using d1 connection");
|
||||
|
||||
const { getPlatformProxy } = await import("wrangler");
|
||||
const platformProxy = await getPlatformProxy({
|
||||
configPath: "./vite.wrangler.json",
|
||||
});
|
||||
config.connection = d1Sqlite({ binding: platformProxy.env.DB as any });
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
$console.debug("Using node-sqlite connection", dbUrl);
|
||||
config.connection = nodeSqlite({ url: dbUrl });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let app: App;
|
||||
const recreate = import.meta.env.VITE_APP_FRESH === "1";
|
||||
@@ -79,9 +65,9 @@ let firstStart = true;
|
||||
export default {
|
||||
async fetch(request: Request) {
|
||||
if (!app || recreate) {
|
||||
app = App.create({
|
||||
connection,
|
||||
});
|
||||
const sync = !!(firstStart && example);
|
||||
|
||||
app = App.create(config);
|
||||
app.emgr.onEvent(
|
||||
App.Events.AppBuiltEvent,
|
||||
async () => {
|
||||
@@ -91,7 +77,7 @@ export default {
|
||||
"sync",
|
||||
);
|
||||
await app.build({
|
||||
sync: !!(firstStart && example),
|
||||
sync,
|
||||
});
|
||||
|
||||
// log routes
|
||||
|
||||
Reference in New Issue
Block a user