chore: use type from core (#5196)

This commit is contained in:
Alex Yang
2025-10-09 13:30:41 -07:00
committed by GitHub
parent 255fbd8faa
commit 6f282eb4ef
6 changed files with 13 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
import type { Models } from "../types"; import type { DBPreservedModels } from "@better-auth/core/db";
import type { BetterAuthOptions } from "@better-auth/core"; import type { BetterAuthOptions } from "@better-auth/core";
import type { DBAdapter, Where } from "@better-auth/core/db/adapter"; import type { DBAdapter, Where } from "@better-auth/core/db/adapter";
import { getCurrentAdapter } from "../context/transaction"; import { getCurrentAdapter } from "../context/transaction";
@@ -13,7 +13,7 @@ export function getWithHooks(
) { ) {
const hooks = ctx.hooks; const hooks = ctx.hooks;
type BaseModels = Extract< type BaseModels = Extract<
Models, DBPreservedModels,
"user" | "account" | "session" | "verification" "user" | "account" | "session" | "verification"
>; >;
async function createWithHooks<T extends Record<string, any>>( async function createWithHooks<T extends Record<string, any>>(

View File

@@ -5,19 +5,6 @@ import type { StripEmptyObjects, UnionToIntersection } from "./helper";
import type { BetterAuthPlugin } from "@better-auth/core"; import type { BetterAuthPlugin } from "@better-auth/core";
import type { User, Session } from "@better-auth/core/db"; import type { User, Session } from "@better-auth/core/db";
export type Models =
| "user"
| "account"
| "session"
| "verification"
| "rate-limit"
| "organization"
| "member"
| "invitation"
| "jwks"
| "passkey"
| "two-factor";
export type AdditionalUserFieldsInput<Options extends BetterAuthOptions> = export type AdditionalUserFieldsInput<Options extends BetterAuthOptions> =
InferFieldsFromPlugins<Options, "user", "input"> & InferFieldsFromPlugins<Options, "user", "input"> &
InferFieldsFromOptions<Options, "user", "input">; InferFieldsFromOptions<Options, "user", "input">;

View File

@@ -4,6 +4,7 @@ import type {
DBFieldType, DBFieldType,
DBPrimitive, DBPrimitive,
BetterAuthDBSchema, BetterAuthDBSchema,
DBPreservedModels,
} from "./type"; } from "./type";
import type { BetterAuthPluginDBSchema } from "./plugin"; import type { BetterAuthPluginDBSchema } from "./plugin";
export type { BetterAuthPluginDBSchema } from "./plugin"; export type { BetterAuthPluginDBSchema } from "./plugin";
@@ -21,6 +22,7 @@ export type {
DBFieldType, DBFieldType,
DBPrimitive, DBPrimitive,
BetterAuthDBSchema, BetterAuthDBSchema,
DBPreservedModels,
}; };
/** /**

View File

@@ -1,16 +1,7 @@
import type { ZodType } from "zod"; import type { ZodType } from "zod";
import type { LiteralString } from "../types"; import type { LiteralString } from "../types";
declare module "../index" { export type DBPreservedModels =
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface BetterAuthMutators<O, C> {
"better-auth/db": {
// todo: we should infer the schema from the adapter
};
}
}
export type Models =
| "user" | "user"
| "account" | "account"
| "session" | "session"

View File

@@ -10,7 +10,7 @@ import type { OAuthProvider } from "../oauth2";
import { createLogger } from "../env"; import { createLogger } from "../env";
import type { DBAdapter, Where } from "../db/adapter"; import type { DBAdapter, Where } from "../db/adapter";
import type { BetterAuthCookies } from "./cookie"; import type { BetterAuthCookies } from "./cookie";
import type { Models } from "../db/type"; import type { DBPreservedModels } from "../db/type";
import type { LiteralUnion } from "./helper"; import type { LiteralUnion } from "./helper";
import type { CookieOptions, EndpointContext } from "better-call"; import type { CookieOptions, EndpointContext } from "better-call";
import type { import type {
@@ -247,7 +247,7 @@ export type AuthContext<Options extends BetterAuthOptions = BetterAuthOptions> =
freshAge: number; freshAge: number;
}; };
generateId: (options: { generateId: (options: {
model: LiteralUnion<Models, string>; model: LiteralUnion<DBPreservedModels, string>;
size?: number; size?: number;
}) => string | false; }) => string | false;
secondaryStorage: SecondaryStorage | undefined; secondaryStorage: SecondaryStorage | undefined;

View File

@@ -2,7 +2,11 @@ import type { Dialect, Kysely, MysqlPool, PostgresPool } from "kysely";
import type { Database } from "better-sqlite3"; import type { Database } from "better-sqlite3";
import type { CookieOptions } from "better-call"; import type { CookieOptions } from "better-call";
import type { LiteralUnion } from "./helper"; import type { LiteralUnion } from "./helper";
import type { DBFieldAttribute, Models, SecondaryStorage } from "../db/type"; import type {
DBFieldAttribute,
DBPreservedModels,
SecondaryStorage,
} from "../db/type";
import type { Account, RateLimit, Session, User, Verification } from "../db"; import type { Account, RateLimit, Session, User, Verification } from "../db";
import type { Database as BunDatabase } from "bun:sqlite"; import type { Database as BunDatabase } from "bun:sqlite";
import type { DatabaseSync } from "node:sqlite"; import type { DatabaseSync } from "node:sqlite";
@@ -17,7 +21,7 @@ type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
type OmitId<T extends { id: unknown }> = Omit<T, "id">; type OmitId<T extends { id: unknown }> = Omit<T, "id">;
export type GenerateIdFn = (options: { export type GenerateIdFn = (options: {
model: LiteralUnion<Models, string>; model: LiteralUnion<DBPreservedModels, string>;
size?: number; size?: number;
}) => string | false; }) => string | false;