[PR #5208] [CLOSED] DB Types #22753

Closed
opened 2026-04-15 21:15:19 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5208
Author: @R5dan
Created: 10/10/2025
Status: Closed

Base: canaryHead: feat/db-types


📝 Commits (4)

📊 Changes

19 files changed (+861 additions, -616 deletions)

View changed files

📝 packages/better-auth/src/db/field.ts (+18 -20)
📝 packages/better-auth/src/types/context.ts (+9 -7)
📝 packages/better-auth/src/types/helper.ts (+3 -9)
📝 packages/core/src/db/adapter/index.ts (+146 -91)
📝 packages/core/src/db/index.ts (+11 -6)
📝 packages/core/src/db/plugin.ts (+28 -7)
packages/core/src/db/schema.ts (+142 -0)
packages/core/src/db/schema/account.ts (+0 -34)
packages/core/src/db/schema/rate-limit.ts (+0 -21)
packages/core/src/db/schema/session.ts (+0 -17)
packages/core/src/db/schema/shared.ts (+0 -7)
packages/core/src/db/schema/user.ts (+0 -16)
packages/core/src/db/schema/verification.ts (+0 -15)
📝 packages/core/src/db/type.ts (+44 -26)
📝 packages/core/src/middleware/index.ts (+85 -9)
📝 packages/core/src/types/context.ts (+153 -137)
📝 packages/core/src/types/init-options.ts (+184 -161)
📝 packages/core/src/types/plugin-client.ts (+12 -6)
📝 packages/core/src/types/plugin.ts (+26 -27)

📄 Description

Replaces #5170

This is a PR to add more type safety to Better Auth, specifically in regards to accessing and editing the database via endpoints and plugins.

Main Functionality:

Plugins now have there adapter types changed to include there own types
Hooks and middleware also have database changes
Database fields have typed values for config options such as defaultValue based on the field type provide


Summary by cubic

Adds schema-aware TypeScript types to the DB adapter and core tables, replacing Zod models with typed field definitions and queries. This improves safety for endpoints, plugins, and adapters with better IntelliSense and compile-time checks.

  • New Features

    • field() helper for typed fields with defaultValue, onUpdate, and transform checks.
    • Schema generics for DBAdapter/CustomAdapter with typed Where operators and values.
    • InferDBType and DBFieldPrimitive to derive record types from table schemas.
    • BetterAuthPluginDBTableSchema and a unified schema export in shared.ts.
  • Refactors

    • Core tables (account, user, session, verification, rateLimit) rewritten as typed table schemas; Zod removed.
    • Adapter methods now use model keys and typed data/select/where; CleanedWhere is field-typed.
    • Core fields (id, createdAt, updatedAt) defined via field() and composed into a shared schema.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5208 **Author:** [@R5dan](https://github.com/R5dan) **Created:** 10/10/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/db-types` --- ### 📝 Commits (4) - [`b4f4ff1`](https://github.com/better-auth/better-auth/commit/b4f4ff1d09148165b0fa50ef77c207bd2020c097) first commit - [`e56eaa9`](https://github.com/better-auth/better-auth/commit/e56eaa9e184119157e35ad0bb2b4ef138c791480) core - [`b1b6e53`](https://github.com/better-auth/better-auth/commit/b1b6e53c1d3cb76b86485bd5a539639f65fb2780) field - [`7c0b83b`](https://github.com/better-auth/better-auth/commit/7c0b83b8edf0de865c36a98964fd20454f6a56fa) push ### 📊 Changes **19 files changed** (+861 additions, -616 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/field.ts` (+18 -20) 📝 `packages/better-auth/src/types/context.ts` (+9 -7) 📝 `packages/better-auth/src/types/helper.ts` (+3 -9) 📝 `packages/core/src/db/adapter/index.ts` (+146 -91) 📝 `packages/core/src/db/index.ts` (+11 -6) 📝 `packages/core/src/db/plugin.ts` (+28 -7) ➕ `packages/core/src/db/schema.ts` (+142 -0) ➖ `packages/core/src/db/schema/account.ts` (+0 -34) ➖ `packages/core/src/db/schema/rate-limit.ts` (+0 -21) ➖ `packages/core/src/db/schema/session.ts` (+0 -17) ➖ `packages/core/src/db/schema/shared.ts` (+0 -7) ➖ `packages/core/src/db/schema/user.ts` (+0 -16) ➖ `packages/core/src/db/schema/verification.ts` (+0 -15) 📝 `packages/core/src/db/type.ts` (+44 -26) 📝 `packages/core/src/middleware/index.ts` (+85 -9) 📝 `packages/core/src/types/context.ts` (+153 -137) 📝 `packages/core/src/types/init-options.ts` (+184 -161) 📝 `packages/core/src/types/plugin-client.ts` (+12 -6) 📝 `packages/core/src/types/plugin.ts` (+26 -27) </details> ### 📄 Description Replaces #5170 This is a PR to add more type safety to Better Auth, specifically in regards to accessing and editing the database via endpoints and plugins. Main Functionality: Plugins now have there adapter types changed to include there own types Hooks and middleware also have database changes Database fields have typed values for config options such as defaultValue based on the field type provide <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds schema-aware TypeScript types to the DB adapter and core tables, replacing Zod models with typed field definitions and queries. This improves safety for endpoints, plugins, and adapters with better IntelliSense and compile-time checks. - **New Features** - field() helper for typed fields with defaultValue, onUpdate, and transform checks. - Schema generics for DBAdapter/CustomAdapter with typed Where operators and values. - InferDBType and DBFieldPrimitive to derive record types from table schemas. - BetterAuthPluginDBTableSchema and a unified schema export in shared.ts. - **Refactors** - Core tables (account, user, session, verification, rateLimit) rewritten as typed table schemas; Zod removed. - Adapter methods now use model keys and typed data/select/where; CleanedWhere is field-typed. - Core fields (id, createdAt, updatedAt) defined via field() and composed into a shared schema. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 21:15:19 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#22753