mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-18 11:32:15 -05:00
fix(core): preserve database option type inference (#11290)
Co-authored-by: Alexey Sokolov <alexvyber@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@better-auth/core": patch
|
||||
---
|
||||
|
||||
Restore database option type inference for projects that do not use Cloudflare Workers.
|
||||
@@ -184,7 +184,6 @@
|
||||
"peerDependencies": {
|
||||
"@better-auth/utils": "catalog:",
|
||||
"@better-fetch/fetch": "catalog:",
|
||||
"@cloudflare/workers-types": ">=4",
|
||||
"@opentelemetry/api": "^1.9.0",
|
||||
"better-call": "catalog:",
|
||||
"jose": "^6.1.0",
|
||||
@@ -192,9 +191,6 @@
|
||||
"nanostores": "catalog:peer"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@cloudflare/workers-types": {
|
||||
"optional": true
|
||||
},
|
||||
"@opentelemetry/api": {
|
||||
"optional": true
|
||||
}
|
||||
|
||||
@@ -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>();
|
||||
});
|
||||
});
|
||||
@@ -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>;
|
||||
}
|
||||
@@ -14,6 +14,7 @@ export type {
|
||||
BetterAuthCookies,
|
||||
CookieCachePayload,
|
||||
} from "./cookie";
|
||||
export type { D1Database } from "./database";
|
||||
export type * from "./helper";
|
||||
export type {
|
||||
BaseURLConfig,
|
||||
|
||||
@@ -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,
|
||||
@@ -28,10 +27,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,4 +1,4 @@
|
||||
import type { D1Database } from "@cloudflare/workers-types";
|
||||
import type { D1Database } from "@better-auth/core";
|
||||
import type {
|
||||
CompiledQuery,
|
||||
DatabaseConnection,
|
||||
|
||||
Reference in New Issue
Block a user