Skip to content

Commit 83d9628

Browse files
committed
refactor(better-auth): update adapter and migration logic for improved type safety
- Changed `AdapterDebugLogs` to `DBAdapterDebugLogOption` in `FileMakerAdapterConfig`. - Updated `betterAuthSchema` type in `planMigration` to use a more accurate schema definition. - Enhanced CLI to utilize `getSchema` instead of `getAuthTables` for better compatibility. - Added new entries to `.gitignore` for machine-specific sync files.
1 parent cccd530 commit 83d9628

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

.beads/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ beads.left.meta.json
3232
beads.right.jsonl
3333
beads.right.meta.json
3434

35+
# Sync state (local-only, per-machine)
36+
# These files are machine-specific and should not be shared across clones
37+
.sync.lock
38+
sync_base.jsonl
39+
3540
# NOTE: Do NOT add negation patterns (e.g., !issues.jsonl) here.
3641
# They would override fork protection in .git/info/exclude, allowing
3742
# contributors to accidentally commit upstream issue databases.

packages/better-auth/src/adapter.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** biome-ignore-all lint/suspicious/noExplicitAny: library code */
22
import { logger } from "better-auth";
3-
import { type AdapterDebugLogs, type CleanedWhere, createAdapter } from "better-auth/adapters";
3+
import { type CleanedWhere, createAdapter, type DBAdapterDebugLogOption } from "better-auth/adapters";
44
import buildQuery from "odata-query";
55
import { prettifyError, z } from "zod/v4";
66
import { createRawFetch, type FmOdataConfig } from "./odata";
@@ -15,11 +15,11 @@ const configSchema = z.object({
1515
}),
1616
});
1717

18-
interface FileMakerAdapterConfig {
18+
export interface FileMakerAdapterConfig {
1919
/**
2020
* Helps you debug issues with the adapter.
2121
*/
22-
debugLogs?: AdapterDebugLogs;
22+
debugLogs?: DBAdapterDebugLogOption;
2323
/**
2424
* If the table names in the schema are plural.
2525
*/
@@ -168,7 +168,7 @@ export const FileMakerAdapter = (_config: FileMakerAdapterConfig = defaultConfig
168168
logging: config.debugLogs ? "verbose" : "none",
169169
});
170170

171-
return createAdapter({
171+
const adapterFactory = createAdapter({
172172
config: {
173173
adapterId: "filemaker",
174174
adapterName: "FileMaker",
@@ -382,4 +382,8 @@ export const FileMakerAdapter = (_config: FileMakerAdapterConfig = defaultConfig
382382
};
383383
},
384384
});
385+
386+
// Expose the FileMaker config for CLI access
387+
(adapterFactory as any).filemakerConfig = config as FileMakerAdapterConfig;
388+
return adapterFactory;
385389
};

packages/better-auth/src/cli/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env node --no-warnings
22
import { Command } from "@commander-js/extra-typings";
33
import { logger } from "better-auth";
4-
import { getAdapter, getAuthTables } from "better-auth/db";
4+
import { getAdapter, getSchema } from "better-auth/db";
55
import chalk from "chalk";
66
import fs from "fs-extra";
77
import prompts from "prompts";
8-
import type { AdapterOptions } from "../adapter";
8+
import type { FileMakerAdapterConfig } from "../adapter";
99
import { getConfig } from "../better-auth-cli/utils/get-config";
1010
import { executeMigration, planMigration, prettyPrintMigrationPlan } from "../migrate";
1111
import { createRawFetch } from "../odata";
@@ -50,9 +50,9 @@ async function main() {
5050
return;
5151
}
5252

53-
const betterAuthSchema = getAuthTables(config);
53+
const betterAuthSchema = getSchema(config);
5454

55-
const adapterConfig = (adapter.options as AdapterOptions).config;
55+
const adapterConfig = (adapter as unknown as { filemakerConfig: FileMakerAdapterConfig }).filemakerConfig;
5656
const { fetch } = createRawFetch({
5757
...adapterConfig.odata,
5858
auth:

packages/better-auth/src/migrate.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import type { BetterAuthDbSchema } from "better-auth/db";
1+
import type { DBFieldAttribute } from "better-auth/db";
22
import chalk from "chalk";
33
import type { Metadata } from "fm-odata-client";
44
import z from "zod/v4";
55
import type { createRawFetch } from "./odata";
66

7+
/** Schema type returned by better-auth's getSchema function */
8+
type BetterAuthSchema = Record<string, { fields: Record<string, DBFieldAttribute>; order: number }>;
9+
710
export async function getMetadata(fetch: ReturnType<typeof createRawFetch>["fetch"], databaseName: string) {
811
console.log("getting metadata...");
912
const result = await fetch("/$metadata", {
@@ -28,7 +31,7 @@ export async function getMetadata(fetch: ReturnType<typeof createRawFetch>["fetc
2831

2932
export async function planMigration(
3033
fetch: ReturnType<typeof createRawFetch>["fetch"],
31-
betterAuthSchema: BetterAuthDbSchema,
34+
betterAuthSchema: BetterAuthSchema,
3235
databaseName: string,
3336
): Promise<MigrationPlan> {
3437
const metadata = await getMetadata(fetch, databaseName);
@@ -86,7 +89,7 @@ export async function planMigration(
8689
.sort((a, b) => (a[1].order ?? 0) - (b[1].order ?? 0))
8790
.map(([key, value]) => ({
8891
...value,
89-
keyName: key,
92+
modelName: key, // Use the key as modelName since getSchema uses table names as keys
9093
}));
9194

9295
const migrationPlan: MigrationPlan = [];

0 commit comments

Comments
 (0)