fix(core): preserve database option type inference (#11291)

Co-authored-by: Taesu <166604494+bytaesu@users.noreply.github.com>
Co-authored-by: Alexey Sokolov <alexvyber@gmail.com>
This commit is contained in:
better-release[bot]
2026-09-15 06:55:48 +09:00
committed by GitHub
co-authored by Taesu Alexey Sokolov
parent c768d73625
commit ecc4e0df7b
9 changed files with 39 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@better-auth/core": patch
---
Restore database option type inference for projects that do not use Cloudflare Workers.
-4
View File
@@ -178,15 +178,11 @@
"@better-fetch/fetch": "catalog:",
"@opentelemetry/api": "^1.9.0",
"better-call": "catalog:",
"@cloudflare/workers-types": ">=4",
"jose": "^6.1.0",
"kysely": "catalog:peer",
"nanostores": "^1.0.1"
},
"peerDependenciesMeta": {
"@cloudflare/workers-types": {
"optional": true
},
"@opentelemetry/api": {
"optional": true
}
+9
View File
@@ -0,0 +1,9 @@
import type { D1Database as CloudflareD1Database } from "@cloudflare/workers-types";
import { describe, expectTypeOf, it } from "vitest";
import type { D1Database } from "./database";
describe("D1Database", () => {
it("accepts Cloudflare's D1 database type", () => {
expectTypeOf<CloudflareD1Database>().toExtend<D1Database>();
});
});
+21
View File
@@ -0,0 +1,21 @@
type D1Result<T> = {
results: T[];
meta: {
changes: number;
last_row_id: number;
};
};
interface D1PreparedStatement {
bind(...values: unknown[]): D1PreparedStatement;
all<T = Record<string, unknown>>(): Promise<D1Result<T>>;
}
/**
* A Cloudflare D1-compatible database.
*/
export interface D1Database {
prepare(query: string): D1PreparedStatement;
batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>;
exec(query: string): Promise<unknown>;
}
+1
View File
@@ -12,6 +12,7 @@ export type {
BetterAuthCookie,
BetterAuthCookies,
} from "./cookie";
export type { D1Database } from "./database";
export type * from "./helper";
export type {
BaseURLConfig,
+2 -1
View File
@@ -1,6 +1,5 @@
import type { Database as BunDatabase } from "bun:sqlite";
import type { DatabaseSync } from "node:sqlite";
import type { D1Database } from "@cloudflare/workers-types";
import type { CookieOptions } from "better-call";
import type {
Dialect,
@@ -29,10 +28,12 @@ import type { BaseVerification } from "../db/schema/verification";
import type { Logger } from "../env";
import type { SocialProviderList, SocialProviders } from "../social-providers";
import type { AuthContext, GenericEndpointContext } from "./context";
import type { D1Database } from "./database";
import type { Awaitable, LiteralString, LiteralUnion } from "./helper";
import type { BetterAuthPlugin } from "./plugin";
type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
type Optional<T> = {
[P in keyof T]?: T[P] | undefined;
};
-1
View File
@@ -59,7 +59,6 @@
}
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20250121.0",
"@better-auth/core": "workspace:*",
"@better-auth/utils": "catalog:",
"kysely": "catalog:",
@@ -1,4 +1,4 @@
import type { D1Database } from "@cloudflare/workers-types";
import type { D1Database } from "@better-auth/core";
import type {
CompiledQuery,
DatabaseConnection,
-3
View File
@@ -1289,9 +1289,6 @@ importers:
'@better-auth/utils':
specifier: 'catalog:'
version: 0.4.2
'@cloudflare/workers-types':
specifier: ^4.20250121.0
version: 4.20260226.1
kysely:
specifier: 'catalog:'
version: 0.29.2