mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
fix tests and imports
This commit is contained in:
@@ -186,6 +186,11 @@
|
|||||||
"import": "./dist/media/index.js",
|
"import": "./dist/media/index.js",
|
||||||
"require": "./dist/media/index.js"
|
"require": "./dist/media/index.js"
|
||||||
},
|
},
|
||||||
|
"./plugins": {
|
||||||
|
"types": "./dist/types/plugins/index.d.ts",
|
||||||
|
"import": "./dist/plugins/index.js",
|
||||||
|
"require": "./dist/plugins/index.js"
|
||||||
|
},
|
||||||
"./adapter/sqlite": {
|
"./adapter/sqlite": {
|
||||||
"types": "./dist/types/adapter/sqlite/edge.d.ts",
|
"types": "./dist/types/adapter/sqlite/edge.d.ts",
|
||||||
"import": {
|
"import": {
|
||||||
@@ -200,11 +205,6 @@
|
|||||||
},
|
},
|
||||||
"require": "./dist/adapter/sqlite/node.js"
|
"require": "./dist/adapter/sqlite/node.js"
|
||||||
},
|
},
|
||||||
"./plugins": {
|
|
||||||
"types": "./dist/types/plugins/index.d.ts",
|
|
||||||
"import": "./dist/plugins/index.js",
|
|
||||||
"require": "./dist/plugins/index.js"
|
|
||||||
},
|
|
||||||
"./adapter/cloudflare": {
|
"./adapter/cloudflare": {
|
||||||
"types": "./dist/types/adapter/cloudflare/index.d.ts",
|
"types": "./dist/types/adapter/cloudflare/index.d.ts",
|
||||||
"import": "./dist/adapter/cloudflare/index.js",
|
"import": "./dist/adapter/cloudflare/index.js",
|
||||||
@@ -261,14 +261,14 @@
|
|||||||
"cli": ["./dist/types/cli/index.d.ts"],
|
"cli": ["./dist/types/cli/index.d.ts"],
|
||||||
"media": ["./dist/types/media/index.d.ts"],
|
"media": ["./dist/types/media/index.d.ts"],
|
||||||
"plugins": ["./dist/types/plugins/index.d.ts"],
|
"plugins": ["./dist/types/plugins/index.d.ts"],
|
||||||
"sqlite": ["./dist/types/adapter/sqlite/edge.d.ts"],
|
|
||||||
"adapter": ["./dist/types/adapter/index.d.ts"],
|
"adapter": ["./dist/types/adapter/index.d.ts"],
|
||||||
"adapter/cloudflare": ["./dist/types/adapter/cloudflare/index.d.ts"],
|
"adapter/cloudflare": ["./dist/types/adapter/cloudflare/index.d.ts"],
|
||||||
"adapter/vite": ["./dist/types/adapter/vite/index.d.ts"],
|
"adapter/vite": ["./dist/types/adapter/vite/index.d.ts"],
|
||||||
"adapter/nextjs": ["./dist/types/adapter/nextjs/index.d.ts"],
|
"adapter/nextjs": ["./dist/types/adapter/nextjs/index.d.ts"],
|
||||||
"adapter/react-router": ["./dist/types/adapter/react-router/index.d.ts"],
|
"adapter/react-router": ["./dist/types/adapter/react-router/index.d.ts"],
|
||||||
"adapter/bun": ["./dist/types/adapter/bun/index.d.ts"],
|
"adapter/bun": ["./dist/types/adapter/bun/index.d.ts"],
|
||||||
"adapter/node": ["./dist/types/adapter/node/index.d.ts"]
|
"adapter/node": ["./dist/types/adapter/node/index.d.ts"],
|
||||||
|
"adapter/sqlite": ["./dist/types/adapter/sqlite/edge.d.ts"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
import { registerMedia } from "./storage/StorageR2Adapter";
|
import { registerMedia } from "./storage/StorageR2Adapter";
|
||||||
import { getBinding } from "./bindings";
|
import { getBinding } from "./bindings";
|
||||||
import { D1Connection } from "./connection/D1Connection";
|
import { d1Sqlite } from "./connection/D1Connection";
|
||||||
|
import { Connection } from "bknd/data";
|
||||||
import type { CloudflareBkndConfig, CloudflareEnv } from ".";
|
import type { CloudflareBkndConfig, CloudflareEnv } from ".";
|
||||||
import { App } from "bknd";
|
import { App } from "bknd";
|
||||||
import { makeConfig as makeAdapterConfig } from "bknd/adapter";
|
import { makeConfig as makeAdapterConfig } from "bknd/adapter";
|
||||||
@@ -101,7 +102,7 @@ export function makeConfig<Env extends CloudflareEnv = CloudflareEnv>(
|
|||||||
|
|
||||||
// if connection instance is given, don't do anything
|
// if connection instance is given, don't do anything
|
||||||
// other than checking if D1 session is defined
|
// other than checking if D1 session is defined
|
||||||
if (D1Connection.isConnection(appConfig.connection)) {
|
if (Connection.isConnection(appConfig.connection)) {
|
||||||
if (config.d1?.session) {
|
if (config.d1?.session) {
|
||||||
// we cannot guarantee that db was opened with session
|
// we cannot guarantee that db was opened with session
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -139,8 +140,11 @@ export function makeConfig<Env extends CloudflareEnv = CloudflareEnv>(
|
|||||||
if (db) {
|
if (db) {
|
||||||
if (config.d1?.session) {
|
if (config.d1?.session) {
|
||||||
session = db.withSession(sessionId ?? config.d1?.first);
|
session = db.withSession(sessionId ?? config.d1?.first);
|
||||||
|
if (!session) {
|
||||||
|
throw new Error("Couldn't create session");
|
||||||
|
}
|
||||||
|
|
||||||
appConfig.connection = new D1Connection({ binding: session });
|
appConfig.connection = d1Sqlite({ binding: session });
|
||||||
appConfig.options = {
|
appConfig.options = {
|
||||||
...appConfig.options,
|
...appConfig.options,
|
||||||
manager: {
|
manager: {
|
||||||
@@ -154,12 +158,12 @@ export function makeConfig<Env extends CloudflareEnv = CloudflareEnv>(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
appConfig.connection = new D1Connection({ binding: db });
|
appConfig.connection = d1Sqlite({ binding: db });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!D1Connection.isConnection(appConfig.connection)) {
|
if (!Connection.isConnection(appConfig.connection)) {
|
||||||
throw new Error("Couldn't find database connection");
|
throw new Error("Couldn't find database connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ export type D1ConnectionConfig<DB extends D1Database | D1DatabaseSession = D1Dat
|
|||||||
binding: DB;
|
binding: DB;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function d1Sqlite(config: D1ConnectionConfig<D1Database>) {
|
export function d1Sqlite<DB extends D1Database | D1DatabaseSession = D1Database>(
|
||||||
|
config: D1ConnectionConfig<DB>,
|
||||||
|
) {
|
||||||
const db = config.binding;
|
const db = config.binding;
|
||||||
|
|
||||||
return genericSqlite(
|
return genericSqlite(
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { D1Connection, type D1ConnectionConfig } from "./connection/D1Connection";
|
import { d1Sqlite, type D1ConnectionConfig } from "./connection/D1Connection";
|
||||||
|
|
||||||
export * from "./cloudflare-workers.adapter";
|
export * from "./cloudflare-workers.adapter";
|
||||||
export { makeApp, getFresh } from "./modes/fresh";
|
export { makeApp, getFresh } from "./modes/fresh";
|
||||||
export { getCached } from "./modes/cached";
|
export { getCached } from "./modes/cached";
|
||||||
export { DurableBkndApp, getDurable } from "./modes/durable";
|
export { DurableBkndApp, getDurable } from "./modes/durable";
|
||||||
export { D1Connection, type D1ConnectionConfig };
|
export { d1Sqlite, type D1ConnectionConfig };
|
||||||
export {
|
export {
|
||||||
getBinding,
|
getBinding,
|
||||||
getBindings,
|
getBindings,
|
||||||
@@ -14,6 +14,9 @@ export {
|
|||||||
} from "./bindings";
|
} from "./bindings";
|
||||||
export { constants } from "./config";
|
export { constants } from "./config";
|
||||||
|
|
||||||
export function d1(config: D1ConnectionConfig) {
|
// for compatibility with old code
|
||||||
return new D1Connection(config);
|
export function d1<DB extends D1Database | D1DatabaseSession = D1Database>(
|
||||||
|
config: D1ConnectionConfig<DB>,
|
||||||
|
) {
|
||||||
|
return d1Sqlite<DB>(config);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user