[PR #7082] [MERGED] chore(cli): export schema generators via /api subpath #23965

Closed
opened 2026-04-15 22:05:28 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

Base: canaryHead: feat/cli-api-exports


📝 Commits (2)

  • 26af830 feat(cli): export schema generators via /api subpath
  • dba3f8b chore: lint fix

📊 Changes

7 files changed (+41 additions, -18 deletions)

View changed files

📝 packages/cli/package.json (+14 -1)
packages/cli/src/api.ts (+9 -0)
📝 packages/cli/src/generators/index.ts (+3 -4)
📝 packages/cli/src/generators/kysely.ts (+1 -1)
📝 packages/cli/src/generators/types.ts (+8 -6)
📝 packages/cli/test/generate.test.ts (+4 -4)
📝 packages/cli/tsdown.config.ts (+2 -2)

📄 Description

Closes #7073

Summary

  • Expose schema generators programmatically via @better-auth/cli/api
  • Follow drizzle-kit pattern as suggested in issue comment

Usage

import { generateDrizzleSchema, generatePrismaSchema, generateKyselySchema } from "@better-auth/cli/api";
import type { DBAdapter, SchemaGenerator, SchemaGeneratorResult } from "@better-auth/cli/api";

Changes

  • New src/api.ts entry point
  • Renamed generateMigrationsgenerateKyselySchema for consistency
  • generateSchema() now throws instead of process.exit(1) for programmatic use
  • Added SchemaGeneratorResult type export
  • Re-exported DBAdapter type (avoids deep import from @better-auth/core/db/adapter)
  • generateAuthConfig not included (out of scope, potential future addition)
  • Root export has no types - intentional, it's a CLI binary not a library

Summary by cubic

Add a programmatic API for schema generation under @better-auth/cli/api, following drizzle-kit’s subpath export pattern. Apps can now import generators with first-class typings.

  • New Features

    • Export /api subpath with ESM and .d.ts (package.json exports/typesVersions).
    • New api entry re-exporting generators, generateSchema, adapters, and types (SchemaGenerator, SchemaGeneratorResult, DBAdapter).
    • generateSchema throws errors instead of exiting for programmatic use.
  • Refactors

    • Renamed generateMigrations to generateKyselySchema and updated references.
    • Build .d.ts and include api.ts in tsdown config.

Written for commit dba3f8bb59. 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/7082 **Author:** [@onmax](https://github.com/onmax) **Created:** 1/1/2026 **Status:** ✅ Merged **Merged:** 1/2/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `feat/cli-api-exports` --- ### 📝 Commits (2) - [`26af830`](https://github.com/better-auth/better-auth/commit/26af83082d057692241a3dcd99c7c842ccaaf07c) feat(cli): export schema generators via /api subpath - [`dba3f8b`](https://github.com/better-auth/better-auth/commit/dba3f8bb5900e1c528c87fd9eba6c7ae9f952314) chore: lint fix ### 📊 Changes **7 files changed** (+41 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `packages/cli/package.json` (+14 -1) ➕ `packages/cli/src/api.ts` (+9 -0) 📝 `packages/cli/src/generators/index.ts` (+3 -4) 📝 `packages/cli/src/generators/kysely.ts` (+1 -1) 📝 `packages/cli/src/generators/types.ts` (+8 -6) 📝 `packages/cli/test/generate.test.ts` (+4 -4) 📝 `packages/cli/tsdown.config.ts` (+2 -2) </details> ### 📄 Description Closes #7073 ## Summary - Expose schema generators programmatically via `@better-auth/cli/api` - Follow drizzle-kit pattern as suggested in issue comment ## Usage ```ts import { generateDrizzleSchema, generatePrismaSchema, generateKyselySchema } from "@better-auth/cli/api"; import type { DBAdapter, SchemaGenerator, SchemaGeneratorResult } from "@better-auth/cli/api"; ``` ## Changes - New `src/api.ts` entry point - Renamed `generateMigrations` → `generateKyselySchema` for consistency - `generateSchema()` now throws instead of `process.exit(1)` for programmatic use - Added `SchemaGeneratorResult` type export - Re-exported `DBAdapter` type (avoids deep import from `@better-auth/core/db/adapter`) ## Related - `generateAuthConfig` not included (out of scope, potential future addition) - Root export has no types - intentional, it's a CLI binary not a library <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add a programmatic API for schema generation under @better-auth/cli/api, following drizzle-kit’s subpath export pattern. Apps can now import generators with first-class typings. - **New Features** - Export /api subpath with ESM and .d.ts (package.json exports/typesVersions). - New api entry re-exporting generators, generateSchema, adapters, and types (SchemaGenerator, SchemaGeneratorResult, DBAdapter). - generateSchema throws errors instead of exiting for programmatic use. - **Refactors** - Renamed generateMigrations to generateKyselySchema and updated references. - Build .d.ts and include api.ts in tsdown config. <sup>Written for commit dba3f8bb5900e1c528c87fd9eba6c7ae9f952314. 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-04-15 22:05:28 -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#23965