externalize libsql dependency to let installing env install the correct dep

Signed-off-by: dswbx <dennis.senn@gmx.ch>
This commit is contained in:
dswbx
2024-12-07 06:29:29 +01:00
parent 067213ff60
commit 110c7681b7
3 changed files with 14 additions and 12 deletions

View File

@@ -88,7 +88,7 @@ await tsup.build({
watch, watch,
entry: ["src/index.ts", "src/data/index.ts", "src/core/index.ts", "src/core/utils/index.ts"], entry: ["src/index.ts", "src/data/index.ts", "src/core/index.ts", "src/core/utils/index.ts"],
outDir: "dist", outDir: "dist",
external: ["bun:test"], external: ["bun:test", "@libsql/client"],
metafile: true, metafile: true,
platform: "browser", platform: "browser",
format: ["esm", "cjs"], format: ["esm", "cjs"],

View File

@@ -21,7 +21,7 @@ export class AppBuiltEvent extends Event<{ app: App }> {
export const AppEvents = { AppConfigUpdatedEvent, AppBuiltEvent } as const; export const AppEvents = { AppConfigUpdatedEvent, AppBuiltEvent } as const;
export type CreateAppConfig = { export type CreateAppConfig = {
connection: connection?:
| Connection | Connection
| { | {
type: "libsql"; type: "libsql";
@@ -59,17 +59,19 @@ export class App<DB = any> {
static create(config: CreateAppConfig) { static create(config: CreateAppConfig) {
let connection: Connection | undefined = undefined; let connection: Connection | undefined = undefined;
try {
if (Connection.isConnection(config.connection)) { if (Connection.isConnection(config.connection)) {
connection = config.connection; connection = config.connection;
} else if (typeof config.connection === "object") { } else if (typeof config.connection === "object") {
switch (config.connection.type) {
case "libsql":
connection = new LibsqlConnection(config.connection.config); connection = new LibsqlConnection(config.connection.config);
break;
}
} else { } else {
throw new Error(`Unknown connection of type ${typeof config.connection} given.`); connection = new LibsqlConnection({ url: ":memory:" });
console.warn("[!] No connection provided, using in-memory database");
} }
} catch (e) {
console.error("Could not create connection", e);
}
if (!connection) { if (!connection) {
throw new Error("Invalid connection"); throw new Error("Invalid connection");
} }

View File

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