update app create config to accept libsql config directly

This commit is contained in:
dswbx
2025-02-12 09:21:51 +01:00
parent f466dd166d
commit 2c6a4d2bed
20 changed files with 59 additions and 100 deletions

View File

@@ -30,9 +30,11 @@ export type CreateAppConfig = {
connection?:
| Connection
| {
// @deprecated
type: "libsql";
config: LibSqlCredentials;
};
}
| LibSqlCredentials;
initialConfig?: InitialModuleConfigs;
plugins?: AppPlugin[];
options?: Omit<ModuleManagerOptions, "initial" | "onUpdated">;
@@ -179,7 +181,14 @@ export function createApp(config: CreateAppConfig = {}) {
if (Connection.isConnection(config.connection)) {
connection = config.connection;
} else if (typeof config.connection === "object") {
connection = new LibsqlConnection(config.connection.config);
if ("type" in config.connection) {
console.warn(
"[WARN] Using deprecated connection type 'libsql', use the 'config' object directly."
);
connection = new LibsqlConnection(config.connection.config);
} else {
connection = new LibsqlConnection(config.connection);
}
} else {
connection = new LibsqlConnection({ url: ":memory:" });
console.warn("[!] No connection provided, using in-memory database");

View File

@@ -104,7 +104,7 @@ async function action(options: {
let app: App;
if (options.dbUrl || !configFilePath) {
const connection = options.dbUrl
? { type: "libsql" as const, config: { url: options.dbUrl, authToken: options.dbToken } }
? { url: options.dbUrl, authToken: options.dbToken }
: undefined;
app = await makeApp({ connection, server: { platform: options.server } });
} else {

View File

@@ -1,6 +1,6 @@
import { type Client, type Config, type InStatement, createClient } from "@libsql/client";
import { LibsqlDialect } from "@libsql/kysely-libsql";
import { type DatabaseIntrospector, Kysely, ParseJSONResultsPlugin, sql } from "kysely";
import { type DatabaseIntrospector, Kysely, ParseJSONResultsPlugin } from "kysely";
import { FilterNumericKeysPlugin } from "../plugins/FilterNumericKeysPlugin";
import { KyselyPluginRunner } from "../plugins/KyselyPluginRunner";
import type { QB } from "./Connection";

View File

@@ -1,4 +1,11 @@
export { App, createApp, AppEvents, type AppConfig, type CreateAppConfig } from "./App";
export {
App,
createApp,
AppEvents,
type AppConfig,
type CreateAppConfig,
type AppPlugin
} from "./App";
export {
getDefaultConfig,
@@ -6,7 +13,8 @@ export {
type ModuleConfigs,
type ModuleSchemas,
type ModuleManagerOptions,
type ModuleBuildContext
type ModuleBuildContext,
type InitialModuleConfigs
} from "./modules/ModuleManager";
export * as middlewares from "modules/middlewares";

View File

@@ -32,10 +32,7 @@ export default {
async fetch(request: Request) {
if (!app || recreate) {
app = App.create({
connection: {
type: "libsql",
config: credentials
},
connection: credentials,
initialConfig
});
app.emgr.onEvent(