[PR #7711] [MERGED] chore: move generic type into db schema #7506

Closed
opened 2026-03-13 13:39:34 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7711
Author: @himself65
Created: 1/30/2026
Status: Merged
Merged: 1/30/2026
Merged by: @himself65

Base: canaryHead: himself65/2026/01/30/type


📝 Commits (6)

📊 Changes

24 files changed (+741 additions, -345 deletions)

View changed files

📝 e2e/adapter/test/adapter-factory/adapter-factory.test.ts (+5 -4)
📝 packages/better-auth/src/api/routes/password.test.ts (+1 -1)
📝 packages/better-auth/src/api/routes/session.ts (+20 -24)
📝 packages/better-auth/src/api/routes/sign-in.ts (+18 -10)
📝 packages/better-auth/src/api/routes/sign-up.ts (+10 -10)
📝 packages/better-auth/src/client/types.ts (+2 -2)
📝 packages/better-auth/src/db/field.ts (+5 -100)
📝 packages/better-auth/src/plugins/custom-session/index.ts (+3 -3)
📝 packages/better-auth/src/plugins/siwe/index.ts (+2 -1)
📝 packages/better-auth/src/plugins/siwe/schema.ts (+2 -0)
📝 packages/better-auth/src/types/auth.ts (+3 -4)
📝 packages/better-auth/src/types/models.ts (+7 -25)
📝 packages/core/src/db/adapter/factory.ts (+10 -12)
📝 packages/core/src/db/index.ts (+30 -5)
📝 packages/core/src/db/schema/account.ts (+16 -3)
📝 packages/core/src/db/schema/rate-limit.ts (+16 -1)
📝 packages/core/src/db/schema/session.ts (+15 -3)
📝 packages/core/src/db/schema/user.ts (+15 -3)
📝 packages/core/src/db/schema/verification.ts (+16 -3)
📝 packages/core/src/db/type.ts (+154 -1)

...and 4 more files

📄 Description

Summary by cubic

Centralized model type inference in core DB schema and replaced InferUser/InferSession with generic User/Session types. This improves type accuracy across routes, plugins, and options without changing runtime behavior.

  • Refactors

    • Moved field/type inference into core db/type and added InferDBValueType, InferDBFieldInput/Output, InferDBFieldsInput/Output, and FromOptions/FromPlugins helpers.
    • Added generic User, Session, Account, Verification, and RateLimit types that merge base schema, option additionalFields, and plugin fields.
    • Updated API routes and custom-session plugin to use User<O["user"], O["plugins"]> and Session<O["session"], O["plugins"]>.
    • Simplified BetterAuthOptions via BetterAuthDBOptions for user/session/account/verification and integrated into rate-limit options.
    • Exported DB inference helpers from @better-auth/core/db and added unit type tests validating inference.
    • Typed DBAdapter and adapter factory with Options generics for stricter type safety.
  • Migration

    • Replace InferUser with User<O["user"], O["plugins"]>.
    • Replace InferSession with Session<O["session"], O["plugins"]>.
    • Import User/Session (and DB inference helpers if needed) from @better-auth/core/db.
    • Ensure options use BetterAuthDBOptions shape (modelName, fields excluding id, additionalFields).
    • If you referenced InferFieldsInput/Output, switch to InferDBFieldsInput/InferDBFieldsOutput.

Written for commit 0e19913106. Summary will update on new commits.


🔄 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/7711 **Author:** [@himself65](https://github.com/himself65) **Created:** 1/30/2026 **Status:** ✅ Merged **Merged:** 1/30/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2026/01/30/type` --- ### 📝 Commits (6) - [`2bbe976`](https://github.com/better-auth/better-auth/commit/2bbe9769f198f2cd1fff9469d6b747562a2848b2) chore: move infer type into db schema - [`150468f`](https://github.com/better-auth/better-auth/commit/150468fc975db91bd26cba2515c7f6cd7e0ba488) chore: fix - [`b39c85e`](https://github.com/better-auth/better-auth/commit/b39c85e20f6bed146f5444251880c50733e65ba1) chore: fix - [`3d5707b`](https://github.com/better-auth/better-auth/commit/3d5707b3269794160bdafd0beac8e0ae457baa21) chore: fix - [`5aa41bd`](https://github.com/better-auth/better-auth/commit/5aa41bd8e6e7b614196f67e8df21cc6d97fac896) chore: fix - [`0e19913`](https://github.com/better-auth/better-auth/commit/0e199131063edcf0923b97e348f49572a3e56d14) chore: fix ### 📊 Changes **24 files changed** (+741 additions, -345 deletions) <details> <summary>View changed files</summary> 📝 `e2e/adapter/test/adapter-factory/adapter-factory.test.ts` (+5 -4) 📝 `packages/better-auth/src/api/routes/password.test.ts` (+1 -1) 📝 `packages/better-auth/src/api/routes/session.ts` (+20 -24) 📝 `packages/better-auth/src/api/routes/sign-in.ts` (+18 -10) 📝 `packages/better-auth/src/api/routes/sign-up.ts` (+10 -10) 📝 `packages/better-auth/src/client/types.ts` (+2 -2) 📝 `packages/better-auth/src/db/field.ts` (+5 -100) 📝 `packages/better-auth/src/plugins/custom-session/index.ts` (+3 -3) 📝 `packages/better-auth/src/plugins/siwe/index.ts` (+2 -1) 📝 `packages/better-auth/src/plugins/siwe/schema.ts` (+2 -0) 📝 `packages/better-auth/src/types/auth.ts` (+3 -4) 📝 `packages/better-auth/src/types/models.ts` (+7 -25) 📝 `packages/core/src/db/adapter/factory.ts` (+10 -12) 📝 `packages/core/src/db/index.ts` (+30 -5) 📝 `packages/core/src/db/schema/account.ts` (+16 -3) 📝 `packages/core/src/db/schema/rate-limit.ts` (+16 -1) 📝 `packages/core/src/db/schema/session.ts` (+15 -3) 📝 `packages/core/src/db/schema/user.ts` (+15 -3) 📝 `packages/core/src/db/schema/verification.ts` (+16 -3) 📝 `packages/core/src/db/type.ts` (+154 -1) _...and 4 more files_ </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Centralized model type inference in core DB schema and replaced InferUser/InferSession with generic User/Session types. This improves type accuracy across routes, plugins, and options without changing runtime behavior. - **Refactors** - Moved field/type inference into core db/type and added InferDBValueType, InferDBFieldInput/Output, InferDBFieldsInput/Output, and FromOptions/FromPlugins helpers. - Added generic User, Session, Account, Verification, and RateLimit types that merge base schema, option additionalFields, and plugin fields. - Updated API routes and custom-session plugin to use User<O["user"], O["plugins"]> and Session<O["session"], O["plugins"]>. - Simplified BetterAuthOptions via BetterAuthDBOptions for user/session/account/verification and integrated into rate-limit options. - Exported DB inference helpers from @better-auth/core/db and added unit type tests validating inference. - Typed DBAdapter and adapter factory with Options generics for stricter type safety. - **Migration** - Replace InferUser<O> with User<O["user"], O["plugins"]>. - Replace InferSession<O> with Session<O["session"], O["plugins"]>. - Import User/Session (and DB inference helpers if needed) from @better-auth/core/db. - Ensure options use BetterAuthDBOptions shape (modelName, fields excluding id, additionalFields). - If you referenced InferFieldsInput/Output, switch to InferDBFieldsInput/InferDBFieldsOutput. <sup>Written for commit 0e199131063edcf0923b97e348f49572a3e56d14. Summary will update on new commits.</sup> <!-- 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-03-13 13:39:34 -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#7506