[PR #7530] refactor(organization): clean up toZodSchema & Infer types #7378

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7530
Author: @ping-maxwell
Created: 1/21/2026
Status: 🔄 Open

Base: canaryHead: refactor/organization/clean-up-toZodSchema-&-Infer-types


📝 Commits (6)

  • c673689 refactor(organization): clean up toZodSchema & Infer types
  • ac09a71 Update crud-access-control.ts
  • 363e4ce Update client.ts
  • a540f3d fix: remove unused types
  • d8ddb99 Merge branch 'canary' into refactor/organization/clean-up-toZodSchema-&-Infer-types
  • 57ddc18 Merge branch 'canary' into refactor/organization/clean-up-toZodSchema-&-Infer-types

📊 Changes

12 files changed (+98 additions, -112 deletions)

View changed files

📝 packages/better-auth/src/db/field.ts (+2 -2)
📝 packages/better-auth/src/db/to-zod.test.ts (+1 -15)
📝 packages/better-auth/src/db/to-zod.ts (+11 -16)
📝 packages/better-auth/src/plugins/organization/adapter.ts (+11 -18)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+2 -1)
📝 packages/better-auth/src/plugins/organization/organization.ts (+42 -42)
📝 packages/better-auth/src/plugins/organization/routes/crud-access-control.ts (+0 -1)
📝 packages/better-auth/src/plugins/organization/routes/crud-invites.ts (+0 -1)
📝 packages/better-auth/src/plugins/organization/routes/crud-members.ts (+0 -1)
📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+1 -5)
📝 packages/better-auth/src/plugins/organization/routes/crud-team.ts (+0 -2)
📝 packages/better-auth/src/plugins/organization/schema.ts (+28 -8)

📄 Description

Summary by cubic

Simplified schema generation and type inference for the organization plugin. toZodSchema now always excludes fields with input: false, and Infer types are clearer and more consistent across client and server.

  • Refactors

    • Removed isClientSide from toZodSchema. It now always excludes fields with input: false.
    • Stopped filtering returned: false in toZodSchema.
    • Renamed generic flag in InferAdditionalFieldsFromPluginOptions and all Infer* types to ShouldRemoveFieldsWithInputFalse (default true).
    • Updated organization adapter, client, and routes to the new type signatures.
    • Client-facing $Infer and return types now use Infer* defaults (fields with input: false are excluded).
    • Server-side paths explicitly use Infer*<O, false> where hidden fields must be retained.
    • Cleaned up casts and tightened test expectations (e.g., role union, optional teamId).
  • Migration

    • Remove isClientSide wherever toZodSchema is called.
    • If you relied on returned: false being filtered, handle that explicitly in your code.
    • Review Infer* usages:
      • Client types can use defaults (InferOrganization, etc.).
      • Server types that need all fields should use Infer*<O, false>.

Written for commit d8ddb99a76. 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/7530 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 1/21/2026 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `refactor/organization/clean-up-`toZodSchema`-&-`Infer`-types` --- ### 📝 Commits (6) - [`c673689`](https://github.com/better-auth/better-auth/commit/c673689ece758578e5891000f8fc3c288c95214f) refactor(organization): clean up `toZodSchema` & `Infer` types - [`ac09a71`](https://github.com/better-auth/better-auth/commit/ac09a71ddd827bf7b03e613392bf7d3513a91bcf) Update crud-access-control.ts - [`363e4ce`](https://github.com/better-auth/better-auth/commit/363e4ce5d1912fe93fd0ad61f8424dae2f58fd19) Update client.ts - [`a540f3d`](https://github.com/better-auth/better-auth/commit/a540f3d2a398a23cb99891140963462b54a2d4c7) fix: remove unused types - [`d8ddb99`](https://github.com/better-auth/better-auth/commit/d8ddb99a7672d0dfbb2ffab33fc5c19fbf2dcb8a) Merge branch 'canary' into refactor/organization/clean-up-`toZodSchema`-&-`Infer`-types - [`57ddc18`](https://github.com/better-auth/better-auth/commit/57ddc18ab4e35a152529da3e7be27e080932f103) Merge branch 'canary' into refactor/organization/clean-up-`toZodSchema`-&-`Infer`-types ### 📊 Changes **12 files changed** (+98 additions, -112 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/field.ts` (+2 -2) 📝 `packages/better-auth/src/db/to-zod.test.ts` (+1 -15) 📝 `packages/better-auth/src/db/to-zod.ts` (+11 -16) 📝 `packages/better-auth/src/plugins/organization/adapter.ts` (+11 -18) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+2 -1) 📝 `packages/better-auth/src/plugins/organization/organization.ts` (+42 -42) 📝 `packages/better-auth/src/plugins/organization/routes/crud-access-control.ts` (+0 -1) 📝 `packages/better-auth/src/plugins/organization/routes/crud-invites.ts` (+0 -1) 📝 `packages/better-auth/src/plugins/organization/routes/crud-members.ts` (+0 -1) 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+1 -5) 📝 `packages/better-auth/src/plugins/organization/routes/crud-team.ts` (+0 -2) 📝 `packages/better-auth/src/plugins/organization/schema.ts` (+28 -8) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Simplified schema generation and type inference for the organization plugin. toZodSchema now always excludes fields with input: false, and Infer types are clearer and more consistent across client and server. - **Refactors** - Removed isClientSide from toZodSchema. It now always excludes fields with input: false. - Stopped filtering returned: false in toZodSchema. - Renamed generic flag in InferAdditionalFieldsFromPluginOptions and all Infer* types to ShouldRemoveFieldsWithInputFalse (default true). - Updated organization adapter, client, and routes to the new type signatures. - Client-facing $Infer and return types now use Infer* defaults (fields with input: false are excluded). - Server-side paths explicitly use Infer*<O, false> where hidden fields must be retained. - Cleaned up casts and tightened test expectations (e.g., role union, optional teamId). - **Migration** - Remove isClientSide wherever toZodSchema is called. - If you relied on returned: false being filtered, handle that explicitly in your code. - Review Infer* usages: - Client types can use defaults (InferOrganization<O>, etc.). - Server types that need all fields should use Infer*<O, false>. <sup>Written for commit d8ddb99a7672d0dfbb2ffab33fc5c19fbf2dcb8a. 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:34:05 -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#7378