auth 1.5.0-beta.19 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { d as generateDrizzleSchema, n as generateSchema, r as generatePrismaSchema, t as adapters, u as generateKyselySchema } from "./generators-
|
|
1
|
+
import { d as generateDrizzleSchema, n as generateSchema, r as generatePrismaSchema, t as adapters, u as generateKyselySchema } from "./generators-YiCQyoNc.mjs";
|
|
2
2
|
|
|
3
3
|
export { adapters, generateDrizzleSchema, generateKyselySchema, generatePrismaSchema, generateSchema };
|
|
@@ -439,6 +439,11 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
|
|
|
439
439
|
const providerProp = generator.properties.find((prop) => prop.type === "assignment" && prop.key === "provider");
|
|
440
440
|
if (providerProp && providerProp.value === "\"prisma-client-js\"") providerProp.value = "\"prisma-client\"";
|
|
441
441
|
}
|
|
442
|
+
const datasource = builder.findByType("datasource", { name: "db" });
|
|
443
|
+
if (datasource && datasource.properties) {
|
|
444
|
+
const urlIndex = datasource.properties.findIndex((prop) => prop.type === "assignment" && prop.key === "url");
|
|
445
|
+
if (urlIndex !== -1) datasource.properties.splice(urlIndex, 1);
|
|
446
|
+
}
|
|
442
447
|
});
|
|
443
448
|
const manyToManyRelations = /* @__PURE__ */ new Map();
|
|
444
449
|
for (const table in tables) {
|
|
@@ -627,8 +632,17 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
|
|
|
627
632
|
};
|
|
628
633
|
const getNewPrisma = (provider, cwd) => {
|
|
629
634
|
const prismaVersion = getPrismaVersion(cwd);
|
|
635
|
+
const isV7 = prismaVersion && prismaVersion >= 7;
|
|
636
|
+
const clientProvider = isV7 ? "prisma-client" : "prisma-client-js";
|
|
637
|
+
if (isV7) return `generator client {
|
|
638
|
+
provider = "${clientProvider}"
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
datasource db {
|
|
642
|
+
provider = "${provider}"
|
|
643
|
+
}`;
|
|
630
644
|
return `generator client {
|
|
631
|
-
provider = "${
|
|
645
|
+
provider = "${clientProvider}"
|
|
632
646
|
}
|
|
633
647
|
|
|
634
648
|
datasource db {
|
|
@@ -658,4 +672,4 @@ const generateSchema = (opts) => {
|
|
|
658
672
|
|
|
659
673
|
//#endregion
|
|
660
674
|
export { getPackageInfo as a, spawnCommand as c, generateDrizzleSchema as d, findMonorepoRoot as i, tryCatch as l, generateSchema as n, hasDependency as o, generatePrismaSchema as r, generateSecretHash as s, adapters as t, generateKyselySchema as u };
|
|
661
|
-
//# sourceMappingURL=generators-
|
|
675
|
+
//# sourceMappingURL=generators-YiCQyoNc.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-YiCQyoNc.mjs","names":["fs","fs"],"sources":["../src/generators/drizzle.ts","../src/generators/kysely.ts","../src/utils/helper.ts","../src/utils/get-package-info.ts","../src/generators/prisma.ts","../src/generators/index.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { initGetFieldName, initGetModelName } from \"better-auth/adapters\";\nimport type { BetterAuthDBSchema, DBFieldAttribute } from \"better-auth/db\";\nimport { getAuthTables } from \"better-auth/db\";\nimport type { BetterAuthOptions } from \"better-auth/types\";\nimport prettier from \"prettier\";\nimport type { SchemaGenerator } from \"./types\";\n\nfunction convertToSnakeCase(str: string, camelCase?: boolean) {\n\tif (camelCase) {\n\t\treturn str;\n\t}\n\t// Handle consecutive capitals (like ID, URL, API) by treating them as a single word\n\treturn str\n\t\t.replace(/([A-Z]+)([A-Z][a-z])/g, \"$1_$2\") // Handle AABb -> AA_Bb\n\t\t.replace(/([a-z\\d])([A-Z])/g, \"$1_$2\") // Handle aBb -> a_Bb\n\t\t.toLowerCase();\n}\n\nexport const generateDrizzleSchema: SchemaGenerator = async ({\n\toptions,\n\tfile,\n\tadapter,\n}) => {\n\tconst tables = getAuthTables(options);\n\tconst filePath = file || \"./auth-schema.ts\";\n\tconst databaseType: \"sqlite\" | \"mysql\" | \"pg\" | undefined =\n\t\tadapter.options?.provider;\n\n\tif (!databaseType) {\n\t\tthrow new Error(\n\t\t\t`Database provider type is undefined during Drizzle schema generation. Please define a \\`provider\\` in the Drizzle adapter config. Read more at https://better-auth.com/docs/adapters/drizzle`,\n\t\t);\n\t}\n\tconst fileExist = existsSync(filePath);\n\n\tlet code: string = generateImport({\n\t\tdatabaseType,\n\t\ttables,\n\t\toptions,\n\t});\n\n\tconst getModelName = initGetModelName({\n\t\tschema: tables,\n\t\tusePlural: adapter.options?.adapterConfig?.usePlural,\n\t});\n\n\tconst getFieldName = initGetFieldName({\n\t\tschema: tables,\n\t\tusePlural: adapter.options?.adapterConfig?.usePlural,\n\t});\n\n\tfor (const tableKey in tables) {\n\t\tconst table = tables[tableKey]!;\n\t\tconst modelName = getModelName(tableKey);\n\t\tconst fields = table.fields;\n\n\t\tfunction getType(name: string, field: DBFieldAttribute) {\n\t\t\t// Not possible to reach, it's here to make typescript happy\n\t\t\tif (!databaseType) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Database provider type is undefined during Drizzle schema generation. Please define a \\`provider\\` in the Drizzle adapter config. Read more at https://better-auth.com/docs/adapters/drizzle`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tname = convertToSnakeCase(name, adapter.options?.camelCase);\n\t\t\tif (field.references?.field === \"id\") {\n\t\t\t\tconst useNumberId = options.advanced?.database?.generateId === \"serial\";\n\t\t\t\tconst useUUIDs = options.advanced?.database?.generateId === \"uuid\";\n\t\t\t\tif (useNumberId) {\n\t\t\t\t\tif (databaseType === \"pg\") {\n\t\t\t\t\t\treturn `integer('${name}')`;\n\t\t\t\t\t} else if (databaseType === \"mysql\") {\n\t\t\t\t\t\treturn `int('${name}')`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// using sqlite\n\t\t\t\t\t\treturn `integer('${name}')`;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (useUUIDs && databaseType === \"pg\") {\n\t\t\t\t\treturn `uuid('${name}')`;\n\t\t\t\t}\n\t\t\t\tif (field.references.field) {\n\t\t\t\t\tif (databaseType === \"mysql\") {\n\t\t\t\t\t\treturn `varchar('${name}', { length: 36 })`;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn `text('${name}')`;\n\t\t\t}\n\t\t\tconst type = field.type;\n\t\t\tif (typeof type !== \"string\") {\n\t\t\t\tif (Array.isArray(type) && type.every((x) => typeof x === \"string\")) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tsqlite: `text({ enum: [${type.map((x) => `'${x}'`).join(\", \")}] })`,\n\t\t\t\t\t\tpg: `text('${name}', { enum: [${type.map((x) => `'${x}'`).join(\", \")}] })`,\n\t\t\t\t\t\tmysql: `mysqlEnum([${type.map((x) => `'${x}'`).join(\", \")}])`,\n\t\t\t\t\t}[databaseType];\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError(\n\t\t\t\t\t\t`Invalid field type for field ${name} in model ${modelName}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst typeMap: Record<\n\t\t\t\ttypeof type,\n\t\t\t\tRecord<typeof databaseType, string>\n\t\t\t> = {\n\t\t\t\tstring: {\n\t\t\t\t\tsqlite: `text('${name}')`,\n\t\t\t\t\tpg: `text('${name}')`,\n\t\t\t\t\tmysql: field.unique\n\t\t\t\t\t\t? `varchar('${name}', { length: 255 })`\n\t\t\t\t\t\t: field.references\n\t\t\t\t\t\t\t? `varchar('${name}', { length: 36 })`\n\t\t\t\t\t\t\t: field.sortable\n\t\t\t\t\t\t\t\t? `varchar('${name}', { length: 255 })`\n\t\t\t\t\t\t\t\t: field.index\n\t\t\t\t\t\t\t\t\t? `varchar('${name}', { length: 255 })`\n\t\t\t\t\t\t\t\t\t: `text('${name}')`,\n\t\t\t\t},\n\t\t\t\tboolean: {\n\t\t\t\t\tsqlite: `integer('${name}', { mode: 'boolean' })`,\n\t\t\t\t\tpg: `boolean('${name}')`,\n\t\t\t\t\tmysql: `boolean('${name}')`,\n\t\t\t\t},\n\t\t\t\tnumber: {\n\t\t\t\t\tsqlite: `integer('${name}')`,\n\t\t\t\t\tpg: field.bigint\n\t\t\t\t\t\t? `bigint('${name}', { mode: 'number' })`\n\t\t\t\t\t\t: `integer('${name}')`,\n\t\t\t\t\tmysql: field.bigint\n\t\t\t\t\t\t? `bigint('${name}', { mode: 'number' })`\n\t\t\t\t\t\t: `int('${name}')`,\n\t\t\t\t},\n\t\t\t\tdate: {\n\t\t\t\t\tsqlite: `integer('${name}', { mode: 'timestamp_ms' })`,\n\t\t\t\t\tpg: `timestamp('${name}')`,\n\t\t\t\t\tmysql: `timestamp('${name}', { fsp: 3 })`,\n\t\t\t\t},\n\t\t\t\t\"number[]\": {\n\t\t\t\t\tsqlite: `text('${name}', { mode: \"json\" })`,\n\t\t\t\t\tpg: field.bigint\n\t\t\t\t\t\t? `bigint('${name}', { mode: 'number' }).array()`\n\t\t\t\t\t\t: `integer('${name}').array()`,\n\t\t\t\t\tmysql: `text('${name}', { mode: 'json' })`,\n\t\t\t\t},\n\t\t\t\t\"string[]\": {\n\t\t\t\t\tsqlite: `text('${name}', { mode: \"json\" })`,\n\t\t\t\t\tpg: `text('${name}').array()`,\n\t\t\t\t\tmysql: `text('${name}', { mode: \"json\" })`,\n\t\t\t\t},\n\t\t\t\tjson: {\n\t\t\t\t\tsqlite: `text('${name}', { mode: \"json\" })`,\n\t\t\t\t\tpg: `jsonb('${name}')`,\n\t\t\t\t\tmysql: `json('${name}', { mode: \"json\" })`,\n\t\t\t\t},\n\t\t\t} as const;\n\t\t\tconst dbTypeMap = (\n\t\t\t\ttypeMap as Record<string, Record<typeof databaseType, string>>\n\t\t\t)[type as string];\n\t\t\tif (!dbTypeMap) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Unsupported field type '${field.type}' for field '${name}'.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn dbTypeMap[databaseType];\n\t\t}\n\n\t\tlet id: string = \"\";\n\n\t\tconst useNumberId = options.advanced?.database?.generateId === \"serial\";\n\t\tconst useUUIDs = options.advanced?.database?.generateId === \"uuid\";\n\n\t\tif (useUUIDs && databaseType === \"pg\") {\n\t\t\tid = `uuid(\"id\").default(sql\\`pg_catalog.gen_random_uuid()\\`).primaryKey()`;\n\t\t} else if (useNumberId) {\n\t\t\tif (databaseType === \"pg\") {\n\t\t\t\tid = `integer(\"id\").generatedByDefaultAsIdentity().primaryKey()`;\n\t\t\t} else if (databaseType === \"sqlite\") {\n\t\t\t\tid = `integer(\"id\", { mode: \"number\" }).primaryKey({ autoIncrement: true })`;\n\t\t\t} else {\n\t\t\t\tid = `int(\"id\").autoincrement().primaryKey()`;\n\t\t\t}\n\t\t} else {\n\t\t\tif (databaseType === \"mysql\") {\n\t\t\t\tid = `varchar('id', { length: 36 }).primaryKey()`;\n\t\t\t} else if (databaseType === \"pg\") {\n\t\t\t\tid = `text('id').primaryKey()`;\n\t\t\t} else {\n\t\t\t\tid = `text('id').primaryKey()`;\n\t\t\t}\n\t\t}\n\n\t\ttype Index = { type: \"uniqueIndex\" | \"index\"; name: string; on: string };\n\n\t\tconst indexes: Index[] = [];\n\n\t\tconst assignIndexes = (indexes: Index[]): string => {\n\t\t\tif (!indexes.length) return \"\";\n\n\t\t\tconst code: string[] = [`, (table) => [`];\n\n\t\t\tfor (const index of indexes) {\n\t\t\t\tcode.push(` ${index.type}(\"${index.name}\").on(table.${index.on}),`);\n\t\t\t}\n\n\t\t\tcode.push(`]`);\n\n\t\t\treturn code.join(\"\\n\");\n\t\t};\n\n\t\tconst schema = `export const ${modelName} = ${databaseType}Table(\"${convertToSnakeCase(\n\t\t\tmodelName,\n\t\t\tadapter.options?.camelCase,\n\t\t)}\", {\n\t\t\t\t\tid: ${id},\n\t\t\t\t\t${Object.keys(fields)\n\t\t\t\t\t\t.map((field) => {\n\t\t\t\t\t\t\tconst attr = fields[field]!;\n\t\t\t\t\t\t\tconst fieldName = attr.fieldName || field;\n\t\t\t\t\t\t\tlet type = getType(fieldName, attr);\n\n\t\t\t\t\t\t\tif (attr.index && !attr.unique) {\n\t\t\t\t\t\t\t\tindexes.push({\n\t\t\t\t\t\t\t\t\ttype: \"index\",\n\t\t\t\t\t\t\t\t\tname: `${modelName}_${fieldName}_idx`,\n\t\t\t\t\t\t\t\t\ton: fieldName,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} else if (attr.index && attr.unique) {\n\t\t\t\t\t\t\t\tindexes.push({\n\t\t\t\t\t\t\t\t\ttype: \"uniqueIndex\",\n\t\t\t\t\t\t\t\t\tname: `${modelName}_${fieldName}_uidx`,\n\t\t\t\t\t\t\t\t\ton: fieldName,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tattr.defaultValue !== null &&\n\t\t\t\t\t\t\t\ttypeof attr.defaultValue !== \"undefined\"\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tif (typeof attr.defaultValue === \"function\") {\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tattr.type === \"date\" &&\n\t\t\t\t\t\t\t\t\t\tattr.defaultValue.toString().includes(\"new Date()\")\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\tif (databaseType === \"sqlite\") {\n\t\t\t\t\t\t\t\t\t\t\ttype += `.default(sql\\`(cast(unixepoch('subsecond') * 1000 as integer))\\`)`;\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\ttype += `.defaultNow()`;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t// we are intentionally not adding .$defaultFn(${attr.defaultValue})\n\t\t\t\t\t\t\t\t\t\t// this is because if the defaultValue is a function, it could have\n\t\t\t\t\t\t\t\t\t\t// custom logic within that function that might not work in drizzle's context.\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else if (typeof attr.defaultValue === \"string\") {\n\t\t\t\t\t\t\t\t\ttype += `.default(\"${attr.defaultValue}\")`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\ttype += `.default(${attr.defaultValue})`;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Add .$onUpdate() for fields with onUpdate property\n\t\t\t\t\t\t\t// Supported for all database types: PostgreSQL, MySQL, and SQLite\n\t\t\t\t\t\t\tif (attr.onUpdate && attr.type === \"date\") {\n\t\t\t\t\t\t\t\tif (typeof attr.onUpdate === \"function\") {\n\t\t\t\t\t\t\t\t\ttype += `.$onUpdate(${attr.onUpdate})`;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn `${fieldName}: ${type}${attr.required ? \".notNull()\" : \"\"}${\n\t\t\t\t\t\t\t\tattr.unique ? \".unique()\" : \"\"\n\t\t\t\t\t\t\t}${\n\t\t\t\t\t\t\t\tattr.references\n\t\t\t\t\t\t\t\t\t? `.references(()=> ${getModelName(\n\t\t\t\t\t\t\t\t\t\t\tattr.references.model,\n\t\t\t\t\t\t\t\t\t\t)}.${getFieldName({ model: attr.references.model, field: attr.references.field })}, { onDelete: '${\n\t\t\t\t\t\t\t\t\t\t\tattr.references.onDelete || \"cascade\"\n\t\t\t\t\t\t\t\t\t\t}' })`\n\t\t\t\t\t\t\t\t\t: \"\"\n\t\t\t\t\t\t\t}`;\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join(\",\\n \")}\n\t\t\t\t\t}${assignIndexes(indexes)});`;\n\t\tcode += `\\n${schema}\\n`;\n\t}\n\n\tlet relationsString: string = \"\";\n\tfor (const tableKey in tables) {\n\t\tconst table = tables[tableKey]!;\n\t\tconst modelName = getModelName(tableKey);\n\n\t\ttype Relation = {\n\t\t\t/**\n\t\t\t * The key of the relation that will be defined in the Drizzle schema.\n\t\t\t * For \"one\" relations: singular (e.g., \"user\")\n\t\t\t * For \"many\" relations: plural (e.g., \"posts\")\n\t\t\t */\n\t\t\tkey: string;\n\t\t\t/**\n\t\t\t * The model name being referenced.\n\t\t\t */\n\t\t\tmodel: string;\n\t\t\t/**\n\t\t\t * The type of the relation: \"one\" (many-to-one) or \"many\" (one-to-many).\n\t\t\t */\n\t\t\ttype: \"one\" | \"many\";\n\t\t\t/**\n\t\t\t * Foreign key field name and reference details (only for \"one\" relations).\n\t\t\t */\n\t\t\treference?: {\n\t\t\t\tfield: string;\n\t\t\t\treferences: string;\n\t\t\t\tfieldName: string; // Original field name for generating unique relation export names\n\t\t\t};\n\t\t};\n\n\t\tconst oneRelations: Relation[] = [];\n\t\tconst manyRelations: Relation[] = [];\n\t\t// Set to track \"many\" relations by key to prevent duplicates\n\t\tconst manyRelationsSet = new Set<string>();\n\n\t\t// 1. Find all foreign keys in THIS table (creates \"one\" relations)\n\t\tconst fields = Object.entries(table.fields);\n\t\tconst foreignFields = fields.filter(([_, field]) => field.references);\n\n\t\tfor (const [fieldName, field] of foreignFields) {\n\t\t\tconst referencedModel = field.references!.model;\n\t\t\tconst relationKey = getModelName(referencedModel);\n\t\t\tconst fieldRef = `${getModelName(tableKey)}.${getFieldName({ model: tableKey, field: fieldName })}`;\n\t\t\tconst referenceRef = `${getModelName(referencedModel)}.${getFieldName({ model: referencedModel, field: field.references!.field || \"id\" })}`;\n\n\t\t\t// Create a separate relation for each foreign key\n\t\t\toneRelations.push({\n\t\t\t\tkey: relationKey,\n\t\t\t\tmodel: getModelName(referencedModel),\n\t\t\t\ttype: \"one\",\n\t\t\t\treference: {\n\t\t\t\t\tfield: fieldRef,\n\t\t\t\t\treferences: referenceRef,\n\t\t\t\t\tfieldName: fieldName,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// 2. Find all OTHER tables that reference THIS table (creates \"many\" relations)\n\t\tconst otherModels = Object.entries(tables).filter(\n\t\t\t([modelName]) => modelName !== tableKey,\n\t\t);\n\n\t\t// Map to track relations by model name to determine if unique or many\n\t\tconst modelRelationsMap = new Map<\n\t\t\tstring,\n\t\t\t{\n\t\t\t\tmodelName: string;\n\t\t\t\thasUnique: boolean;\n\t\t\t\thasMany: boolean;\n\t\t\t}\n\t\t>();\n\n\t\tfor (const [modelName, otherTable] of otherModels) {\n\t\t\tconst foreignKeysPointingHere = Object.entries(otherTable.fields).filter(\n\t\t\t\t([_, field]) =>\n\t\t\t\t\tfield.references?.model === tableKey ||\n\t\t\t\t\tfield.references?.model === getModelName(tableKey),\n\t\t\t);\n\n\t\t\tif (foreignKeysPointingHere.length === 0) continue;\n\n\t\t\t// Check if any foreign key is unique\n\t\t\tconst hasUnique = foreignKeysPointingHere.some(\n\t\t\t\t([_, field]) => !!field.unique,\n\t\t\t);\n\t\t\tconst hasMany = foreignKeysPointingHere.some(\n\t\t\t\t([_, field]) => !field.unique,\n\t\t\t);\n\n\t\t\tmodelRelationsMap.set(modelName, {\n\t\t\t\tmodelName,\n\t\t\t\thasUnique,\n\t\t\t\thasMany,\n\t\t\t});\n\t\t}\n\n\t\t// Add relations, deduplicating by relationKey\n\t\tfor (const { modelName, hasMany } of modelRelationsMap.values()) {\n\t\t\t// Determine relation type: if all are unique, it's \"one\", otherwise \"many\"\n\t\t\tconst relationType = hasMany ? \"many\" : \"one\";\n\t\t\tlet relationKey = getModelName(modelName);\n\n\t\t\t// We have to apply this after checking if they have usePlural because otherwise they will end up seeing:\n\t\t\t/* cspell:disable-next-line */\n\t\t\t// \"sesionss\", or \"accountss\" - double s's.\n\t\t\tif (\n\t\t\t\t!adapter.options?.adapterConfig?.usePlural &&\n\t\t\t\trelationType === \"many\"\n\t\t\t) {\n\t\t\t\trelationKey = `${relationKey}s`;\n\t\t\t}\n\n\t\t\t// Only add if we haven't seen this key before\n\t\t\tif (!manyRelationsSet.has(relationKey)) {\n\t\t\t\tmanyRelationsSet.add(relationKey);\n\t\t\t\tmanyRelations.push({\n\t\t\t\t\tkey: relationKey,\n\t\t\t\t\tmodel: getModelName(modelName),\n\t\t\t\t\ttype: relationType,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Group \"one\" relations by referenced model to detect duplicates\n\t\tconst relationsByModel = new Map<string, Relation[]>();\n\t\tfor (const relation of oneRelations) {\n\t\t\tif (relation.reference) {\n\t\t\t\tconst modelKey = relation.key;\n\t\t\t\tif (!relationsByModel.has(modelKey)) {\n\t\t\t\t\trelationsByModel.set(modelKey, []);\n\t\t\t\t}\n\t\t\t\trelationsByModel.get(modelKey)!.push(relation);\n\t\t\t}\n\t\t}\n\n\t\t// Separate relations with duplicates (same model) from those without\n\t\tconst duplicateRelations: Relation[] = [];\n\t\tconst singleRelations: Relation[] = [];\n\n\t\tfor (const [_modelKey, relations] of relationsByModel.entries()) {\n\t\t\tif (relations.length > 1) {\n\t\t\t\t// Multiple relations to the same model - these need field-specific naming\n\t\t\t\tduplicateRelations.push(...relations);\n\t\t\t} else {\n\t\t\t\t// Single relation to this model - can be combined with others\n\t\t\t\tsingleRelations.push(relations[0]!);\n\t\t\t}\n\t\t}\n\n\t\t// Generate field-specific exports for duplicate relations\n\t\tfor (const relation of duplicateRelations) {\n\t\t\tif (relation.reference) {\n\t\t\t\tconst fieldName = relation.reference.fieldName;\n\t\t\t\tconst relationExportName = `${modelName}${fieldName.charAt(0).toUpperCase() + fieldName.slice(1)}Relations`;\n\n\t\t\t\tconst tableRelation = `export const ${relationExportName} = relations(${getModelName(\n\t\t\t\t\ttable.modelName,\n\t\t\t\t)}, ({ one }) => ({\n\t\t\t\t${relation.key}: one(${relation.model}, {\n\t\t\t\t\tfields: [${relation.reference.field}],\n\t\t\t\t\treferences: [${relation.reference.references}],\n\t\t\t\t})\n\t\t\t}))`;\n\n\t\t\t\trelationsString += `\\n${tableRelation}\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Combine all single \"one\" relations and \"many\" relations into exports\n\t\tconst hasOne = singleRelations.length > 0;\n\t\tconst hasMany = manyRelations.length > 0;\n\n\t\tif (hasOne && hasMany) {\n\t\t\t// Both \"one\" and \"many\" relations exist - combine in one export\n\t\t\tconst tableRelation = `export const ${modelName}Relations = relations(${getModelName(\n\t\t\t\ttable.modelName,\n\t\t\t)}, ({ one, many }) => ({\n\t\t\t\t${singleRelations\n\t\t\t\t\t.map((relation) =>\n\t\t\t\t\t\trelation.reference\n\t\t\t\t\t\t\t? ` ${relation.key}: one(${relation.model}, {\n\t\t\t\t\tfields: [${relation.reference.field}],\n\t\t\t\t\treferences: [${relation.reference.references}],\n\t\t\t\t})`\n\t\t\t\t\t\t\t: \"\",\n\t\t\t\t\t)\n\t\t\t\t\t.filter((x) => x !== \"\")\n\t\t\t\t\t.join(\",\\n \")}${\n\t\t\t\t\tsingleRelations.length > 0 && manyRelations.length > 0 ? \",\" : \"\"\n\t\t\t\t}\n\t\t\t\t${manyRelations\n\t\t\t\t\t.map(({ key, model }) => ` ${key}: many(${model})`)\n\t\t\t\t\t.join(\",\\n \")}\n\t\t\t}))`;\n\n\t\t\trelationsString += `\\n${tableRelation}\\n`;\n\t\t} else if (hasOne) {\n\t\t\t// Only \"one\" relations exist\n\t\t\tconst tableRelation = `export const ${modelName}Relations = relations(${getModelName(\n\t\t\t\ttable.modelName,\n\t\t\t)}, ({ one }) => ({\n\t\t\t\t${singleRelations\n\t\t\t\t\t.map((relation) =>\n\t\t\t\t\t\trelation.reference\n\t\t\t\t\t\t\t? ` ${relation.key}: one(${relation.model}, {\n\t\t\t\t\tfields: [${relation.reference.field}],\n\t\t\t\t\treferences: [${relation.reference.references}],\n\t\t\t\t})`\n\t\t\t\t\t\t\t: \"\",\n\t\t\t\t\t)\n\t\t\t\t\t.filter((x) => x !== \"\")\n\t\t\t\t\t.join(\",\\n \")}\n\t\t\t}))`;\n\n\t\t\trelationsString += `\\n${tableRelation}\\n`;\n\t\t} else if (hasMany) {\n\t\t\t// Only \"many\" relations exist\n\t\t\tconst tableRelation = `export const ${modelName}Relations = relations(${getModelName(\n\t\t\t\ttable.modelName,\n\t\t\t)}, ({ many }) => ({\n\t\t\t\t${manyRelations\n\t\t\t\t\t.map(({ key, model }) => ` ${key}: many(${model})`)\n\t\t\t\t\t.join(\",\\n \")}\n\t\t\t}))`;\n\n\t\t\trelationsString += `\\n${tableRelation}\\n`;\n\t\t}\n\t}\n\tcode += `\\n${relationsString}`;\n\n\tconst formattedCode = await prettier.format(code, {\n\t\tparser: \"typescript\",\n\t});\n\treturn {\n\t\tcode: formattedCode,\n\t\tfileName: filePath,\n\t\toverwrite: fileExist,\n\t};\n};\n\nfunction generateImport({\n\tdatabaseType,\n\ttables,\n\toptions,\n}: {\n\tdatabaseType: \"sqlite\" | \"mysql\" | \"pg\";\n\ttables: BetterAuthDBSchema;\n\toptions: BetterAuthOptions;\n}) {\n\tconst rootImports: string[] = [\"relations\"];\n\tconst coreImports: string[] = [];\n\n\tlet hasBigint = false;\n\tlet hasJson = false;\n\n\tfor (const table of Object.values(tables)) {\n\t\tfor (const field of Object.values(table.fields)) {\n\t\t\tif (field.bigint) hasBigint = true;\n\t\t\tif (field.type === \"json\") hasJson = true;\n\t\t}\n\t\tif (hasJson && hasBigint) break;\n\t}\n\n\tconst useNumberId = options.advanced?.database?.generateId === \"serial\";\n\n\tconst useUUIDs = options.advanced?.database?.generateId === \"uuid\";\n\n\tcoreImports.push(`${databaseType}Table`);\n\tcoreImports.push(\n\t\tdatabaseType === \"mysql\"\n\t\t\t? \"varchar, text\"\n\t\t\t: databaseType === \"pg\"\n\t\t\t\t? \"text\"\n\t\t\t\t: \"text\",\n\t);\n\tcoreImports.push(\n\t\thasBigint ? (databaseType !== \"sqlite\" ? \"bigint\" : \"\") : \"\",\n\t);\n\tcoreImports.push(databaseType !== \"sqlite\" ? \"timestamp, boolean\" : \"\");\n\tif (databaseType === \"mysql\") {\n\t\t// Only include int for MySQL if actually needed\n\t\tconst hasNonBigintNumber = Object.values(tables).some((table) =>\n\t\t\tObject.values(table.fields).some(\n\t\t\t\t(field) =>\n\t\t\t\t\t(field.type === \"number\" || field.type === \"number[]\") &&\n\t\t\t\t\t!field.bigint,\n\t\t\t),\n\t\t);\n\t\tconst needsInt = useNumberId || hasNonBigintNumber;\n\t\tif (needsInt) {\n\t\t\tcoreImports.push(\"int\");\n\t\t}\n\t\tconst hasEnum = Object.values(tables).some((table) =>\n\t\t\tObject.values(table.fields).some(\n\t\t\t\t(field) =>\n\t\t\t\t\ttypeof field.type !== \"string\" &&\n\t\t\t\t\tArray.isArray(field.type) &&\n\t\t\t\t\tfield.type.every((x) => typeof x === \"string\"),\n\t\t\t),\n\t\t);\n\t\tif (hasEnum) {\n\t\t\tcoreImports.push(\"mysqlEnum\");\n\t\t}\n\t} else if (databaseType === \"pg\") {\n\t\tif (useUUIDs) {\n\t\t\trootImports.push(\"sql\");\n\t\t}\n\n\t\t// Only include integer for PG if actually needed\n\t\tconst hasNonBigintNumber = Object.values(tables).some((table) =>\n\t\t\tObject.values(table.fields).some(\n\t\t\t\t(field) =>\n\t\t\t\t\t(field.type === \"number\" || field.type === \"number[]\") &&\n\t\t\t\t\t!field.bigint,\n\t\t\t),\n\t\t);\n\t\tconst hasFkToId = Object.values(tables).some((table) =>\n\t\t\tObject.values(table.fields).some(\n\t\t\t\t(field) => field.references?.field === \"id\",\n\t\t\t),\n\t\t);\n\t\t// handles the references field with useNumberId\n\t\tconst needsInteger =\n\t\t\thasNonBigintNumber ||\n\t\t\t(options.advanced?.database?.generateId === \"serial\" && hasFkToId);\n\t\tif (needsInteger) {\n\t\t\tcoreImports.push(\"integer\");\n\t\t}\n\t} else {\n\t\tcoreImports.push(\"integer\");\n\t}\n\tif (databaseType === \"pg\" && useUUIDs) {\n\t\tcoreImports.push(\"uuid\");\n\t}\n\n\t//handle json last on the import order\n\tif (hasJson) {\n\t\tif (databaseType === \"pg\") coreImports.push(\"jsonb\");\n\t\tif (databaseType === \"mysql\") coreImports.push(\"json\");\n\t\t// sqlite uses text for JSON, so there's no need to handle this case\n\t}\n\n\t// Add sql import for SQLite timestamps with defaultNow\n\tconst hasSQLiteTimestamp =\n\t\tdatabaseType === \"sqlite\" &&\n\t\tObject.values(tables).some((table) =>\n\t\t\tObject.values(table.fields).some(\n\t\t\t\t(field) =>\n\t\t\t\t\tfield.type === \"date\" &&\n\t\t\t\t\tfield.defaultValue &&\n\t\t\t\t\ttypeof field.defaultValue === \"function\" &&\n\t\t\t\t\tfield.defaultValue.toString().includes(\"new Date()\"),\n\t\t\t),\n\t\t);\n\n\tif (hasSQLiteTimestamp) {\n\t\trootImports.push(\"sql\");\n\t}\n\n\t//handle indexes\n\tconst hasIndexes = Object.values(tables).some((table) =>\n\t\tObject.values(table.fields).some((field) => field.index && !field.unique),\n\t);\n\tconst hasUniqueIndexes = Object.values(tables).some((table) =>\n\t\tObject.values(table.fields).some((field) => field.unique && field.index),\n\t);\n\tif (hasIndexes) {\n\t\tcoreImports.push(\"index\");\n\t}\n\tif (hasUniqueIndexes) {\n\t\tcoreImports.push(\"uniqueIndex\");\n\t}\n\n\treturn `${rootImports.length > 0 ? `import { ${rootImports.join(\", \")} } from \"drizzle-orm\";\\n` : \"\"}import { ${coreImports\n\t\t.map((x) => x.trim())\n\t\t.filter((x) => x !== \"\")\n\t\t.join(\", \")} } from \"drizzle-orm/${databaseType}-core\";\\n`;\n}\n","import { getMigrations } from \"better-auth/db/migration\";\nimport type { SchemaGenerator } from \"./types\";\n\nexport const generateKyselySchema: SchemaGenerator = async ({\n\toptions,\n\tfile,\n}) => {\n\tconst { compileMigrations } = await getMigrations(options);\n\tconst migrations = await compileMigrations();\n\treturn {\n\t\tcode: migrations.trim() === \";\" ? \"\" : migrations,\n\t\tfileName:\n\t\t\tfile ||\n\t\t\t`./better-auth_migrations/${new Date()\n\t\t\t\t.toISOString()\n\t\t\t\t.replace(/:/g, \"-\")}.sql`,\n\t};\n};\n","import { spawn } from \"node:child_process\";\nimport Crypto from \"node:crypto\";\n\ntype Success<T> = {\n\tdata: T;\n\terror: null;\n};\n\ntype Failure<E> = {\n\tdata: null;\n\terror: E;\n};\n\nexport type Result<T, E = Error> = Success<T> | Failure<E>;\n\nexport async function tryCatch<T, E = Error>(\n\tpromise: Promise<T>,\n): Promise<Result<T, E>> {\n\ttry {\n\t\tconst data = await promise;\n\t\treturn { data, error: null };\n\t} catch (error) {\n\t\treturn { data: null, error: error as E };\n\t}\n}\n\nexport function enterAlternateScreen() {\n\tprocess.stdout.write(\"\\u001B[?1049h\");\n\tprocess.stdout.write(\"\\u001B[2J\"); // Clear screen\n\tprocess.stdout.write(\"\\u001B[H\"); // Move cursor to home\n}\n\nexport function exitAlternateScreen() {\n\tprocess.stdout.write(\"\\u001B[?1049l\");\n}\n\nexport const generateSecretHash = () => {\n\treturn Crypto.randomBytes(16).toString(\"hex\");\n};\n\nexport const spawnCommand = (cmd: string, cwd: string = process.cwd()) =>\n\tnew Promise<void>((resolve, reject) => {\n\t\tconst child = spawn(cmd, {\n\t\t\tcwd,\n\t\t\tstdio: \"inherit\",\n\t\t\tshell: true,\n\t\t});\n\t\tchild.on(\"close\", (code, signal) => {\n\t\t\tif (code !== 0 && code !== null) {\n\t\t\t\treject(new Error(`Exited with code ${code}`));\n\t\t\t} else if (signal) {\n\t\t\t\treject(new Error(`Killed with signal ${signal}`));\n\t\t\t} else {\n\t\t\t\tresolve();\n\t\t\t}\n\t\t});\n\t\tchild.on(\"error\", reject);\n\t});\n","import { readFileSync } from \"node:fs\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { tryCatch } from \"./helper\";\n\nexport function getPackageInfo(cwd?: string) {\n\tconst packageJsonPath = cwd\n\t\t? path.join(cwd, \"package.json\")\n\t\t: path.join(\"package.json\");\n\treturn JSON.parse(readFileSync(packageJsonPath, \"utf-8\"));\n}\n\nexport function getPrismaVersion(cwd?: string): number | null {\n\ttry {\n\t\tconst packageInfo = getPackageInfo(cwd);\n\t\tconst prismaVersion =\n\t\t\tpackageInfo.dependencies?.prisma ||\n\t\t\tpackageInfo.devDependencies?.prisma ||\n\t\t\tpackageInfo.dependencies?.[\"@prisma/client\"] ||\n\t\t\tpackageInfo.devDependencies?.[\"@prisma/client\"];\n\n\t\tif (!prismaVersion) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// Extract major version number from version string\n\t\t// Handles versions like \"^5.0.0\", \"~7.1.0\", \"7.0.0\", etc.\n\t\tconst match = prismaVersion.match(/(\\d+)/);\n\t\treturn match ? parseInt(match[1], 10) : null;\n\t} catch {\n\t\t// If package.json doesn't exist or can't be read, return null\n\t\treturn null;\n\t}\n}\n\n/**\n * Checks if a package has a specific dependency.\n *\n * @param packageJson The package.json object\n * @param dependency The dependency to check for\n * @returns true if the package has the dependency\n */\nexport function hasDependency(packageJson: any, dependency: string) {\n\tlet hasDependency = false;\n\n\tif (\n\t\tpackageJson.dependencies?.[dependency] ||\n\t\tpackageJson.devDependencies?.[dependency] ||\n\t\tpackageJson.peerDependencies?.[dependency] ||\n\t\tpackageJson.optionalDependencies?.[dependency]\n\t) {\n\t\thasDependency = true;\n\t}\n\n\treturn hasDependency;\n}\n\n/**\n * Checks if a directory is a monorepo root by looking for common monorepo indicators.\n *\n * @param dir Directory to check\n * @returns true if the directory appears to be a monorepo root\n */\nasync function isMonorepoRoot(dir: string) {\n\tconst { data: files } = await tryCatch(fs.readdir(dir, \"utf-8\"));\n\tif (!files) return false;\n\n\t// Check for pnpm workspace\n\tif (files.includes(\"pnpm-workspace.yaml\")) {\n\t\treturn true;\n\t}\n\n\t// Check for yarn/npm workspaces in package.json\n\tif (files.includes(\"package.json\")) {\n\t\tconst packageJsonPath = path.join(dir, \"package.json\");\n\t\tconst { data } = await tryCatch(fs.readFile(packageJsonPath, \"utf-8\"));\n\t\tif (data) {\n\t\t\ttry {\n\t\t\t\tconst packageJson = JSON.parse(data);\n\t\t\t\t// Check for workspaces field (npm/yarn workspaces)\n\t\t\t\t// Workspaces can be an array or an object\n\t\t\t\tif (\n\t\t\t\t\tpackageJson.workspaces &&\n\t\t\t\t\t(Array.isArray(packageJson.workspaces) ||\n\t\t\t\t\t\ttypeof packageJson.workspaces === \"object\")\n\t\t\t\t) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Ignore JSON parse errors\n\t\t\t}\n\t\t}\n\t}\n\n\t// Check for other monorepo indicators\n\tconst monorepoIndicators = [\n\t\t\"lerna.json\", // Lerna\n\t\t/* cSpell:disable */\n\t\t\"turbo.json\", // Turborepo\n\t\t\"nx.json\", // Nx\n\t\t\"rush.json\", // Rush\n\t];\n\n\treturn monorepoIndicators.some((indicator) => files.includes(indicator));\n}\n\n/**\n * Finds the monorepo root by walking up the directory tree.\n *\n * @param startDir Starting directory\n * @returns Path to monorepo root, or null if not found\n */\nexport async function findMonorepoRoot(\n\tstartDir: string,\n): Promise<string | null> {\n\tlet currentDir = path.resolve(startDir);\n\tconst root = path.parse(currentDir).root;\n\n\twhile (currentDir !== root) {\n\t\tif (await isMonorepoRoot(currentDir)) {\n\t\t\treturn currentDir;\n\t\t}\n\t\tconst parentDir = path.dirname(currentDir);\n\t\tif (parentDir === currentDir) {\n\t\t\tbreak;\n\t\t}\n\t\tcurrentDir = parentDir;\n\t}\n\n\treturn null;\n}\n","import { existsSync } from \"node:fs\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { capitalizeFirstLetter } from \"@better-auth/core/utils/string\";\nimport { produceSchema } from \"@mrleebo/prisma-ast\";\nimport { initGetFieldName, initGetModelName } from \"better-auth/adapters\";\nimport type { DBFieldType } from \"better-auth/db\";\nimport { getAuthTables } from \"better-auth/db\";\nimport { getPrismaVersion } from \"../utils/get-package-info\";\nimport type { SchemaGenerator } from \"./types\";\n\nexport const generatePrismaSchema: SchemaGenerator = async ({\n\tadapter,\n\toptions,\n\tfile,\n}) => {\n\tconst provider: \"sqlite\" | \"postgresql\" | \"mysql\" | \"mongodb\" =\n\t\tadapter.options?.provider || \"postgresql\";\n\tconst tables = getAuthTables(options);\n\tconst filePath = file || \"./prisma/schema.prisma\";\n\tconst schemaPrismaExist = existsSync(path.join(process.cwd(), filePath));\n\n\tconst getModelName = initGetModelName({\n\t\tschema: getAuthTables(options),\n\t\tusePlural: adapter.options?.adapterConfig?.usePlural,\n\t});\n\tconst getFieldName = initGetFieldName({\n\t\tschema: getAuthTables(options),\n\t\tusePlural: false,\n\t});\n\n\tlet schemaPrisma = \"\";\n\tif (schemaPrismaExist) {\n\t\tschemaPrisma = await fs.readFile(\n\t\t\tpath.join(process.cwd(), filePath),\n\t\t\t\"utf-8\",\n\t\t);\n\t} else {\n\t\tschemaPrisma = getNewPrisma(provider, process.cwd());\n\t}\n\n\t// Update generator and datasource blocks for Prisma v7+ in existing schemas\n\tconst prismaVersion = getPrismaVersion(process.cwd());\n\tif (prismaVersion && prismaVersion >= 7 && schemaPrismaExist) {\n\t\tschemaPrisma = produceSchema(schemaPrisma, (builder) => {\n\t\t\tconst generator: any = builder.findByType(\"generator\", {\n\t\t\t\tname: \"client\",\n\t\t\t});\n\t\t\tif (generator && generator.properties) {\n\t\t\t\tconst providerProp = generator.properties.find(\n\t\t\t\t\t(prop: any) => prop.type === \"assignment\" && prop.key === \"provider\",\n\t\t\t\t);\n\t\t\t\tif (providerProp && providerProp.value === '\"prisma-client-js\"') {\n\t\t\t\t\tproviderProp.value = '\"prisma-client\"';\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Remove url from datasource block (now configured in prisma.config.ts)\n\t\t\tconst datasource: any = builder.findByType(\"datasource\", {\n\t\t\t\tname: \"db\",\n\t\t\t});\n\t\t\tif (datasource && datasource.properties) {\n\t\t\t\tconst urlIndex = datasource.properties.findIndex(\n\t\t\t\t\t(prop: any) => prop.type === \"assignment\" && prop.key === \"url\",\n\t\t\t\t);\n\t\t\t\tif (urlIndex !== -1) {\n\t\t\t\t\tdatasource.properties.splice(urlIndex, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tconst manyToManyRelations = new Map();\n\n\tfor (const table in tables) {\n\t\tconst fields = tables[table]?.fields;\n\t\tfor (const field in fields) {\n\t\t\tconst attr = fields[field]!;\n\t\t\tif (attr.references) {\n\t\t\t\tconst referencedOriginalModel = attr.references.model;\n\t\t\t\tconst referencedCustomModel =\n\t\t\t\t\ttables[referencedOriginalModel]?.modelName || referencedOriginalModel;\n\t\t\t\tconst referencedModelNameCap = capitalizeFirstLetter(\n\t\t\t\t\tgetModelName(referencedCustomModel),\n\t\t\t\t);\n\n\t\t\t\tif (!manyToManyRelations.has(referencedModelNameCap)) {\n\t\t\t\t\tmanyToManyRelations.set(referencedModelNameCap, new Set());\n\t\t\t\t}\n\n\t\t\t\tconst currentCustomModel = tables[table]?.modelName || table;\n\t\t\t\tconst currentModelNameCap = capitalizeFirstLetter(\n\t\t\t\t\tgetModelName(currentCustomModel),\n\t\t\t\t);\n\n\t\t\t\tmanyToManyRelations\n\t\t\t\t\t.get(referencedModelNameCap)\n\t\t\t\t\t.add(currentModelNameCap);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst indexedFields = new Map<string, string[]>();\n\tfor (const table in tables) {\n\t\tconst fields = tables[table]?.fields;\n\t\tconst customModelName = tables[table]?.modelName || table;\n\t\tconst modelName = capitalizeFirstLetter(getModelName(customModelName));\n\t\tindexedFields.set(modelName, []);\n\n\t\tfor (const field in fields) {\n\t\t\tconst attr = fields[field]!;\n\t\t\tif (attr.index && !attr.unique) {\n\t\t\t\tconst fieldName = attr.fieldName || field;\n\t\t\t\tindexedFields.get(modelName)!.push(fieldName);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst schema = produceSchema(schemaPrisma, (builder) => {\n\t\tfor (const table in tables) {\n\t\t\tconst originalTableName = table;\n\t\t\tconst customModelName = tables[table]?.modelName || table;\n\t\t\tconst modelName = capitalizeFirstLetter(getModelName(customModelName));\n\t\t\tconst fields = tables[table]?.fields;\n\t\t\tfunction getType({\n\t\t\t\tisBigint,\n\t\t\t\tisOptional,\n\t\t\t\ttype,\n\t\t\t}: {\n\t\t\t\ttype: DBFieldType;\n\t\t\t\tisOptional: boolean;\n\t\t\t\tisBigint: boolean;\n\t\t\t}) {\n\t\t\t\tif (type === \"string\") {\n\t\t\t\t\treturn isOptional ? \"String?\" : \"String\";\n\t\t\t\t}\n\t\t\t\tif (type === \"number\" && isBigint) {\n\t\t\t\t\treturn isOptional ? \"BigInt?\" : \"BigInt\";\n\t\t\t\t}\n\t\t\t\tif (type === \"number\") {\n\t\t\t\t\treturn isOptional ? \"Int?\" : \"Int\";\n\t\t\t\t}\n\t\t\t\tif (type === \"boolean\") {\n\t\t\t\t\treturn isOptional ? \"Boolean?\" : \"Boolean\";\n\t\t\t\t}\n\t\t\t\tif (type === \"date\") {\n\t\t\t\t\treturn isOptional ? \"DateTime?\" : \"DateTime\";\n\t\t\t\t}\n\t\t\t\tif (type === \"json\") {\n\t\t\t\t\tif (provider === \"sqlite\" || provider === \"mysql\") {\n\t\t\t\t\t\treturn isOptional ? \"String?\" : \"String\";\n\t\t\t\t\t}\n\t\t\t\t\treturn isOptional ? \"Json?\" : \"Json\";\n\t\t\t\t}\n\t\t\t\tif (type === \"string[]\") {\n\t\t\t\t\t// SQLite and MySQL don't support array of strings, so we use string instead\n\t\t\t\t\t// adapter should handle JSON.stringify and JSON.parse conversion for these fields\n\t\t\t\t\tif (provider === \"sqlite\" || provider === \"mysql\") {\n\t\t\t\t\t\treturn isOptional ? \"String?\" : \"String\";\n\t\t\t\t\t}\n\t\t\t\t\treturn \"String[]\";\n\t\t\t\t}\n\t\t\t\tif (type === \"number[]\") {\n\t\t\t\t\t// SQLite and MySQL don't support array of numbers, so we use int instead\n\t\t\t\t\t// adapter should handle JSON.stringify and JSON.parse conversion for these fields\n\t\t\t\t\tif (provider === \"sqlite\" || provider === \"mysql\") {\n\t\t\t\t\t\treturn \"String\";\n\t\t\t\t\t}\n\t\t\t\t\treturn \"Int[]\";\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst prismaModel = builder.findByType(\"model\", {\n\t\t\t\tname: modelName,\n\t\t\t});\n\n\t\t\tif (!prismaModel) {\n\t\t\t\tif (provider === \"mongodb\") {\n\t\t\t\t\t// Mongo DB doesn't support auto increment, so just use their normal _id.\n\t\t\t\t\tbuilder\n\t\t\t\t\t\t.model(modelName)\n\t\t\t\t\t\t.field(\"id\", \"String\")\n\t\t\t\t\t\t.attribute(\"id\")\n\t\t\t\t\t\t.attribute(`map(\"_id\")`);\n\t\t\t\t} else {\n\t\t\t\t\tconst useNumberId =\n\t\t\t\t\t\toptions.advanced?.database?.generateId === \"serial\";\n\t\t\t\t\tconst useUUIDs = options.advanced?.database?.generateId === \"uuid\";\n\t\t\t\t\tif (useNumberId) {\n\t\t\t\t\t\tbuilder\n\t\t\t\t\t\t\t.model(modelName)\n\t\t\t\t\t\t\t.field(\"id\", \"Int\")\n\t\t\t\t\t\t\t.attribute(\"id\")\n\t\t\t\t\t\t\t.attribute(\"default(autoincrement())\");\n\t\t\t\t\t} else if (useUUIDs && provider === \"postgresql\") {\n\t\t\t\t\t\tbuilder\n\t\t\t\t\t\t\t.model(modelName)\n\t\t\t\t\t\t\t.field(\"id\", \"String\")\n\t\t\t\t\t\t\t.attribute(\"id\")\n\t\t\t\t\t\t\t.attribute('default(dbgenerated(\"pg_catalog.gen_random_uuid()\"))')\n\t\t\t\t\t\t\t.attribute(\"db.Uuid\");\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbuilder.model(modelName).field(\"id\", \"String\").attribute(\"id\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const field in fields) {\n\t\t\t\tconst attr = fields[field]!;\n\t\t\t\tconst fieldName = attr.fieldName || field;\n\n\t\t\t\tif (prismaModel) {\n\t\t\t\t\tconst isAlreadyExist = builder.findByType(\"field\", {\n\t\t\t\t\t\tname: fieldName,\n\t\t\t\t\t\twithin: prismaModel.properties,\n\t\t\t\t\t});\n\t\t\t\t\tif (isAlreadyExist) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst useUUIDs = options.advanced?.database?.generateId === \"uuid\";\n\t\t\t\tconst useNumberId = options.advanced?.database?.generateId === \"serial\";\n\t\t\t\tconst fieldBuilder = builder.model(modelName).field(\n\t\t\t\t\tfieldName,\n\t\t\t\t\tfield === \"id\" && useNumberId\n\t\t\t\t\t\t? getType({\n\t\t\t\t\t\t\t\tisBigint: false,\n\t\t\t\t\t\t\t\tisOptional: false,\n\t\t\t\t\t\t\t\ttype: \"number\",\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: getType({\n\t\t\t\t\t\t\t\tisBigint: attr?.bigint || false,\n\t\t\t\t\t\t\t\tisOptional: !attr?.required,\n\t\t\t\t\t\t\t\ttype:\n\t\t\t\t\t\t\t\t\tattr.references?.field === \"id\"\n\t\t\t\t\t\t\t\t\t\t? useNumberId\n\t\t\t\t\t\t\t\t\t\t\t? \"number\"\n\t\t\t\t\t\t\t\t\t\t\t: \"string\"\n\t\t\t\t\t\t\t\t\t\t: attr.type,\n\t\t\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tif (field === \"id\") {\n\t\t\t\t\tfieldBuilder.attribute(\"id\");\n\t\t\t\t\tif (provider === \"mongodb\") {\n\t\t\t\t\t\tfieldBuilder.attribute(`map(\"_id\")`);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (attr.unique) {\n\t\t\t\t\tbuilder.model(modelName).blockAttribute(`unique([${fieldName}])`);\n\t\t\t\t}\n\n\t\t\t\tif (attr.defaultValue !== undefined) {\n\t\t\t\t\tif (Array.isArray(attr.defaultValue)) {\n\t\t\t\t\t\t// for json objects and array of object\n\n\t\t\t\t\t\tif (attr.type === \"json\") {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tObject.prototype.toString.call(attr.defaultValue[0]) ===\n\t\t\t\t\t\t\t\t\"[object Object]\"\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tfieldBuilder.attribute(\n\t\t\t\t\t\t\t\t\t`default(\"${JSON.stringify(attr.defaultValue).replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"')}\")`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst jsonArray = [];\n\t\t\t\t\t\t\tfor (const value of attr.defaultValue) jsonArray.push(value);\n\t\t\t\t\t\t\tfieldBuilder.attribute(\n\t\t\t\t\t\t\t\t`default(\"${JSON.stringify(jsonArray).replace(/\"/g, '\\\\\"')}\")`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (attr.defaultValue.length === 0) {\n\t\t\t\t\t\t\tfieldBuilder.attribute(`default([])`);\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\ttypeof attr.defaultValue[0] === \"string\" &&\n\t\t\t\t\t\t\tattr.type === \"string[]\"\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tconst valueArray = [];\n\t\t\t\t\t\t\tfor (const value of attr.defaultValue)\n\t\t\t\t\t\t\t\tvalueArray.push(JSON.stringify(value));\n\t\t\t\t\t\t\tfieldBuilder.attribute(`default([${valueArray}])`);\n\t\t\t\t\t\t} else if (typeof attr.defaultValue[0] === \"number\") {\n\t\t\t\t\t\t\tconst valueArray = [];\n\t\t\t\t\t\t\tfor (const value of attr.defaultValue)\n\t\t\t\t\t\t\t\tvalueArray.push(`${value}`);\n\t\t\t\t\t\t\tfieldBuilder.attribute(`default([${valueArray}])`);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// for json objects\n\t\t\t\t\telse if (\n\t\t\t\t\t\ttypeof attr.defaultValue === \"object\" &&\n\t\t\t\t\t\t!Array.isArray(attr.defaultValue) &&\n\t\t\t\t\t\tattr.defaultValue !== null\n\t\t\t\t\t) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tObject.entries(attr.defaultValue as Record<string, any>)\n\t\t\t\t\t\t\t\t.length === 0\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tfieldBuilder.attribute(`default(\"{}\")`);\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfieldBuilder.attribute(\n\t\t\t\t\t\t\t`default(\"${JSON.stringify(attr.defaultValue).replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"')}\")`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (field === \"createdAt\") {\n\t\t\t\t\t\tfieldBuilder.attribute(\"default(now())\");\n\t\t\t\t\t} else if (\n\t\t\t\t\t\ttypeof attr.defaultValue === \"string\" &&\n\t\t\t\t\t\tprovider !== \"mysql\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tfieldBuilder.attribute(`default(\"${attr.defaultValue}\")`);\n\t\t\t\t\t} else if (\n\t\t\t\t\t\ttypeof attr.defaultValue === \"boolean\" ||\n\t\t\t\t\t\ttypeof attr.defaultValue === \"number\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tfieldBuilder.attribute(`default(${attr.defaultValue})`);\n\t\t\t\t\t} else if (typeof attr.defaultValue === \"function\") {\n\t\t\t\t\t\t// we are intentionally not adding the default value here\n\t\t\t\t\t\t// this is because if the defaultValue is a function, it could have\n\t\t\t\t\t\t// custom logic within that function that might not work in prisma's context.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// This is a special handling for updatedAt fields\n\t\t\t\tif (field === \"updatedAt\" && attr.onUpdate) {\n\t\t\t\t\tfieldBuilder.attribute(\"updatedAt\");\n\t\t\t\t} else if (attr.onUpdate) {\n\t\t\t\t\t// we are intentionally not adding the onUpdate value here\n\t\t\t\t\t// this is because if the onUpdate is a function, it could have\n\t\t\t\t\t// custom logic within that function that might not work in prisma's context.\n\t\t\t\t}\n\n\t\t\t\tif (attr.references) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tuseUUIDs &&\n\t\t\t\t\t\tprovider === \"postgresql\" &&\n\t\t\t\t\t\tattr.references?.field === \"id\"\n\t\t\t\t\t) {\n\t\t\t\t\t\tbuilder.model(modelName).field(fieldName).attribute(`db.Uuid`);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst referencedOriginalModelName = getModelName(\n\t\t\t\t\t\tattr.references.model,\n\t\t\t\t\t);\n\t\t\t\t\tconst referencedCustomModelName =\n\t\t\t\t\t\ttables[referencedOriginalModelName]?.modelName ||\n\t\t\t\t\t\treferencedOriginalModelName;\n\t\t\t\t\tlet action = \"Cascade\";\n\t\t\t\t\tif (attr.references.onDelete === \"no action\") action = \"NoAction\";\n\t\t\t\t\telse if (attr.references.onDelete === \"set null\") action = \"SetNull\";\n\t\t\t\t\telse if (attr.references.onDelete === \"set default\")\n\t\t\t\t\t\taction = \"SetDefault\";\n\t\t\t\t\telse if (attr.references.onDelete === \"restrict\") action = \"Restrict\";\n\n\t\t\t\t\tconst relationField = `relation(fields: [${getFieldName({ model: originalTableName, field: fieldName })}], references: [${getFieldName({ model: attr.references.model, field: attr.references.field })}], onDelete: ${action})`;\n\t\t\t\t\tbuilder\n\t\t\t\t\t\t.model(modelName)\n\t\t\t\t\t\t.field(\n\t\t\t\t\t\t\treferencedCustomModelName.toLowerCase(),\n\t\t\t\t\t\t\t`${capitalizeFirstLetter(referencedCustomModelName)}${\n\t\t\t\t\t\t\t\t!attr.required ? \"?\" : \"\"\n\t\t\t\t\t\t\t}`,\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.attribute(relationField);\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\t!attr.unique &&\n\t\t\t\t\t!attr.references &&\n\t\t\t\t\tprovider === \"mysql\" &&\n\t\t\t\t\tattr.type === \"string\"\n\t\t\t\t) {\n\t\t\t\t\tbuilder.model(modelName).field(fieldName).attribute(\"db.Text\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Add many-to-many fields\n\t\t\tif (manyToManyRelations.has(modelName)) {\n\t\t\t\tfor (const relatedModel of manyToManyRelations.get(modelName)) {\n\t\t\t\t\t// Find the FK field on the related model that points to this model\n\t\t\t\t\tconst relatedTableName = Object.keys(tables).find(\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t\tcapitalizeFirstLetter(tables[key]?.modelName || key) ===\n\t\t\t\t\t\t\trelatedModel,\n\t\t\t\t\t);\n\t\t\t\t\tconst relatedFields = relatedTableName\n\t\t\t\t\t\t? tables[relatedTableName]?.fields\n\t\t\t\t\t\t: {};\n\t\t\t\t\tconst fkField = Object.entries(relatedFields || {}).find(\n\t\t\t\t\t\t([_fieldName, fieldAttr]: any) =>\n\t\t\t\t\t\t\tfieldAttr.references &&\n\t\t\t\t\t\t\tgetModelName(fieldAttr.references.model) ===\n\t\t\t\t\t\t\t\tgetModelName(originalTableName),\n\t\t\t\t\t);\n\t\t\t\t\tconst [_fieldKey, fkFieldAttr] = fkField || [];\n\t\t\t\t\tconst isUnique = fkFieldAttr?.unique === true;\n\n\t\t\t\t\tconst fieldName =\n\t\t\t\t\t\tisUnique || adapter.options?.usePlural === true\n\t\t\t\t\t\t\t? `${relatedModel.toLowerCase()}`\n\t\t\t\t\t\t\t: `${relatedModel.toLowerCase()}s`;\n\t\t\t\t\tconst existingField = builder.findByType(\"field\", {\n\t\t\t\t\t\tname: fieldName,\n\t\t\t\t\t\twithin: prismaModel?.properties,\n\t\t\t\t\t});\n\t\t\t\t\tif (!existingField) {\n\t\t\t\t\t\tbuilder\n\t\t\t\t\t\t\t.model(modelName)\n\t\t\t\t\t\t\t.field(fieldName, `${relatedModel}${isUnique ? \"?\" : \"[]\"}`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Add indexes\n\t\t\tconst indexedFieldsForModel = indexedFields.get(modelName);\n\t\t\tif (indexedFieldsForModel && indexedFieldsForModel.length > 0) {\n\t\t\t\tfor (const fieldName of indexedFieldsForModel) {\n\t\t\t\t\tif (prismaModel) {\n\t\t\t\t\t\tconst indexExist = prismaModel.properties.some(\n\t\t\t\t\t\t\t(v) =>\n\t\t\t\t\t\t\t\tv.type === \"attribute\" &&\n\t\t\t\t\t\t\t\tv.name === \"index\" &&\n\t\t\t\t\t\t\t\tJSON.stringify(v.args[0]?.value).includes(fieldName),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (indexExist) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconst field = Object.entries(fields!).find(\n\t\t\t\t\t\t([key, attr]) => (attr.fieldName || key) === fieldName,\n\t\t\t\t\t)?.[1];\n\n\t\t\t\t\tlet indexField = fieldName;\n\t\t\t\t\tif (provider === \"mysql\" && field && field.type === \"string\") {\n\t\t\t\t\t\tconst useNumberId =\n\t\t\t\t\t\t\toptions.advanced?.database?.generateId === \"serial\";\n\t\t\t\t\t\tconst useUUIDs = options.advanced?.database?.generateId === \"uuid\";\n\t\t\t\t\t\tif (field.references?.field === \"id\" && (useNumberId || useUUIDs)) {\n\t\t\t\t\t\t\tindexField = `${fieldName}`;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tindexField = `${fieldName}(length: 191)`; // length of 191 because String in Prisma is varchar(191)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tbuilder.model(modelName).blockAttribute(`index([${indexField}])`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst hasAttribute = builder.findByType(\"attribute\", {\n\t\t\t\tname: \"map\",\n\t\t\t\twithin: prismaModel?.properties,\n\t\t\t});\n\t\t\tconst hasChanged = customModelName !== originalTableName;\n\t\t\tif (!hasAttribute) {\n\t\t\t\tbuilder\n\t\t\t\t\t.model(modelName)\n\t\t\t\t\t.blockAttribute(\n\t\t\t\t\t\t\"map\",\n\t\t\t\t\t\t`${getModelName(hasChanged ? customModelName : originalTableName)}`,\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\t});\n\n\tconst schemaChanged = schema.trim() !== schemaPrisma.trim();\n\n\treturn {\n\t\tcode: schemaChanged ? schema : \"\",\n\t\tfileName: filePath,\n\t\toverwrite: schemaPrismaExist && schemaChanged,\n\t};\n};\n\nconst getNewPrisma = (provider: string, cwd?: string) => {\n\tconst prismaVersion = getPrismaVersion(cwd);\n\tconst isV7 = prismaVersion && prismaVersion >= 7;\n\t// Use \"prisma-client\" for Prisma v7+, otherwise use \"prisma-client-js\"\n\tconst clientProvider = isV7 ? \"prisma-client\" : \"prisma-client-js\";\n\n\t// In Prisma v7+, the url is configured in prisma.config.ts instead of the schema\n\tif (isV7) {\n\t\treturn `generator client {\n provider = \"${clientProvider}\"\n }\n\n datasource db {\n provider = \"${provider}\"\n }`;\n\t}\n\n\treturn `generator client {\n provider = \"${clientProvider}\"\n }\n\n datasource db {\n provider = \"${provider}\"\n url = ${\n\t\t\tprovider === \"sqlite\" ? `\"file:./dev.db\"` : `env(\"DATABASE_URL\")`\n\t\t}\n }`;\n};\n","import type { BetterAuthOptions } from \"@better-auth/core\";\nimport type { DBAdapter } from \"@better-auth/core/db/adapter\";\nimport { generateDrizzleSchema } from \"./drizzle\";\nimport { generateKyselySchema } from \"./kysely\";\nimport { generatePrismaSchema } from \"./prisma\";\n\nexport const adapters = {\n\tprisma: generatePrismaSchema,\n\tdrizzle: generateDrizzleSchema,\n\tkysely: generateKyselySchema,\n};\n\nexport const generateSchema = (opts: {\n\tadapter: DBAdapter;\n\tfile?: string;\n\toptions: BetterAuthOptions;\n}) => {\n\tconst adapter = opts.adapter;\n\tconst generator =\n\t\tadapter.id in adapters\n\t\t\t? adapters[adapter.id as keyof typeof adapters]\n\t\t\t: null;\n\tif (generator) {\n\t\t// generator from the built-in list above\n\t\treturn generator(opts);\n\t}\n\tif (adapter.createSchema) {\n\t\t// use the custom adapter's createSchema method\n\t\treturn adapter\n\t\t\t.createSchema(opts.options, opts.file)\n\t\t\t.then(({ code, path: fileName, overwrite }) => ({\n\t\t\t\tcode,\n\t\t\t\tfileName,\n\t\t\t\toverwrite,\n\t\t\t}));\n\t}\n\n\tthrow new Error(\n\t\t`${adapter.id} is not supported. If it is a custom adapter, please request the maintainer to implement createSchema`,\n\t);\n};\n"],"mappings":";;;;;;;;;;;;;AAQA,SAAS,mBAAmB,KAAa,WAAqB;AAC7D,KAAI,UACH,QAAO;AAGR,QAAO,IACL,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,qBAAqB,QAAQ,CACrC,aAAa;;AAGhB,MAAa,wBAAyC,OAAO,EAC5D,SACA,MACA,cACK;CACL,MAAM,SAAS,cAAc,QAAQ;CACrC,MAAM,WAAW,QAAQ;CACzB,MAAM,eACL,QAAQ,SAAS;AAElB,KAAI,CAAC,aACJ,OAAM,IAAI,MACT,+LACA;CAEF,MAAM,YAAY,WAAW,SAAS;CAEtC,IAAI,OAAe,eAAe;EACjC;EACA;EACA;EACA,CAAC;CAEF,MAAM,eAAe,iBAAiB;EACrC,QAAQ;EACR,WAAW,QAAQ,SAAS,eAAe;EAC3C,CAAC;CAEF,MAAM,eAAe,iBAAiB;EACrC,QAAQ;EACR,WAAW,QAAQ,SAAS,eAAe;EAC3C,CAAC;AAEF,MAAK,MAAM,YAAY,QAAQ;EAC9B,MAAM,QAAQ,OAAO;EACrB,MAAM,YAAY,aAAa,SAAS;EACxC,MAAM,SAAS,MAAM;EAErB,SAAS,QAAQ,MAAc,OAAyB;AAEvD,OAAI,CAAC,aACJ,OAAM,IAAI,MACT,+LACA;AAEF,UAAO,mBAAmB,MAAM,QAAQ,SAAS,UAAU;AAC3D,OAAI,MAAM,YAAY,UAAU,MAAM;IACrC,MAAM,cAAc,QAAQ,UAAU,UAAU,eAAe;IAC/D,MAAM,WAAW,QAAQ,UAAU,UAAU,eAAe;AAC5D,QAAI,YACH,KAAI,iBAAiB,KACpB,QAAO,YAAY,KAAK;aACd,iBAAiB,QAC3B,QAAO,QAAQ,KAAK;QAGpB,QAAO,YAAY,KAAK;AAG1B,QA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D,KAAI,KACH,QAAO;kBACS,eAAe;;;;kBAIf,SAAS;;AAI1B,QAAO;kBACU,eAAe;;;;kBAIf,SAAS;iBAExB,aAAa,WAAW,oBAAoB,sBAC5C;;;;;;AC/eH,MAAa,WAAW;CACvB,QAAQ;CACR,SAAS;CACT,QAAQ;CACR;AAED,MAAa,kBAAkB,SAIzB;CACL,MAAM,UAAU,KAAK;CACrB,MAAM,YACL,QAAQ,MAAM,WACX,SAAS,QAAQ,MACjB;AACJ,KAAI,UAEH,QAAO,UAAU,KAAK;AAEvB,KAAI,QAAQ,aAEX,QAAO,QACL,aAAa,KAAK,SAAS,KAAK,KAAK,CACrC,MAAM,EAAE,MAAM,MAAM,UAAU,iBAAiB;EAC/C;EACA;EACA;EACA,EAAE;AAGL,OAAM,IAAI,MACT,GAAG,QAAQ,GAAG,uGACd"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as getPackageInfo, c as spawnCommand, d as generateDrizzleSchema, i as findMonorepoRoot, l as tryCatch, n as generateSchema, o as hasDependency, r as generatePrismaSchema, s as generateSecretHash$1 } from "./generators-
|
|
2
|
+
import { a as getPackageInfo, c as spawnCommand, d as generateDrizzleSchema, i as findMonorepoRoot, l as tryCatch, n as generateSchema, o as hasDependency, r as generatePrismaSchema, s as generateSecretHash$1 } from "./generators-YiCQyoNc.mjs";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import * as fs$2 from "node:fs";
|
|
5
5
|
import fs, { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
@@ -27,6 +27,7 @@ import z from "zod";
|
|
|
27
27
|
import { env } from "@better-auth/core/env";
|
|
28
28
|
import { log } from "@clack/prompts";
|
|
29
29
|
import { base64 } from "@better-auth/utils/base64";
|
|
30
|
+
import * as semver from "semver";
|
|
30
31
|
import "dotenv/config";
|
|
31
32
|
|
|
32
33
|
//#region src/utils/add-cloudflare-modules.ts
|
|
@@ -436,11 +437,56 @@ async function getConfig({ cwd, configPath, shouldThrowOnError = false }) {
|
|
|
436
437
|
|
|
437
438
|
//#endregion
|
|
438
439
|
//#region src/commands/generate.ts
|
|
440
|
+
function createMockAdapter$1(adapterId, dialect) {
|
|
441
|
+
let provider;
|
|
442
|
+
if (dialect) {
|
|
443
|
+
if (adapterId === "drizzle") if (dialect === "postgresql") provider = "pg";
|
|
444
|
+
else if (dialect === "mysql" || dialect === "sqlite") provider = dialect;
|
|
445
|
+
else provider = dialect;
|
|
446
|
+
else if (adapterId === "prisma") provider = dialect;
|
|
447
|
+
}
|
|
448
|
+
return {
|
|
449
|
+
id: adapterId,
|
|
450
|
+
create: async () => {
|
|
451
|
+
throw new Error("Mock adapter methods should not be called");
|
|
452
|
+
},
|
|
453
|
+
findOne: async () => {
|
|
454
|
+
throw new Error("Mock adapter methods should not be called");
|
|
455
|
+
},
|
|
456
|
+
findMany: async () => {
|
|
457
|
+
throw new Error("Mock adapter methods should not be called");
|
|
458
|
+
},
|
|
459
|
+
count: async () => {
|
|
460
|
+
throw new Error("Mock adapter methods should not be called");
|
|
461
|
+
},
|
|
462
|
+
update: async () => {
|
|
463
|
+
throw new Error("Mock adapter methods should not be called");
|
|
464
|
+
},
|
|
465
|
+
updateMany: async () => {
|
|
466
|
+
throw new Error("Mock adapter methods should not be called");
|
|
467
|
+
},
|
|
468
|
+
delete: async () => {
|
|
469
|
+
throw new Error("Mock adapter methods should not be called");
|
|
470
|
+
},
|
|
471
|
+
deleteMany: async () => {
|
|
472
|
+
throw new Error("Mock adapter methods should not be called");
|
|
473
|
+
},
|
|
474
|
+
transaction: async (callback) => {
|
|
475
|
+
throw new Error("Mock adapter methods should not be called");
|
|
476
|
+
},
|
|
477
|
+
options: {
|
|
478
|
+
adapterConfig: { adapterId },
|
|
479
|
+
...provider && { provider }
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}
|
|
439
483
|
async function generateAction(opts) {
|
|
440
484
|
const options = z$1.object({
|
|
441
485
|
cwd: z$1.string(),
|
|
442
486
|
config: z$1.string().optional(),
|
|
443
487
|
output: z$1.string().optional(),
|
|
488
|
+
adapter: z$1.string().optional(),
|
|
489
|
+
dialect: z$1.string().optional(),
|
|
444
490
|
y: z$1.boolean().optional(),
|
|
445
491
|
yes: z$1.boolean().optional()
|
|
446
492
|
}).parse(opts);
|
|
@@ -457,7 +503,9 @@ async function generateAction(opts) {
|
|
|
457
503
|
console.error("No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.");
|
|
458
504
|
return;
|
|
459
505
|
}
|
|
460
|
-
|
|
506
|
+
let adapter;
|
|
507
|
+
if (options.adapter) adapter = createMockAdapter$1(options.adapter, options.dialect);
|
|
508
|
+
else adapter = await getAdapter(config).catch((e) => {
|
|
461
509
|
console.error(e.message);
|
|
462
510
|
process.exit(1);
|
|
463
511
|
});
|
|
@@ -559,7 +607,7 @@ async function generateAction(opts) {
|
|
|
559
607
|
} catch {}
|
|
560
608
|
process.exit(0);
|
|
561
609
|
}
|
|
562
|
-
const generate = new Command("generate").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("--config <config>", "the path to the configuration file. defaults to the first configuration file found.").option("--output <output>", "the file to output to the generated schema").option("-y, --yes", "automatically answer yes to all prompts", false).option("--y", "(deprecated) same as --yes", false).action(generateAction);
|
|
610
|
+
const generate = new Command("generate").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("--config <config>", "the path to the configuration file. defaults to the first configuration file found.").option("--output <output>", "the file to output to the generated schema").option("--adapter <adapter>", "specify the adapter type (e.g., prisma, drizzle, kysely) without requiring a configured adapter").option("--dialect <dialect>", "specify the database dialect/provider (e.g., postgresql, mysql, sqlite). For drizzle, postgresql maps to 'pg'").option("-y, --yes", "automatically answer yes to all prompts", false).option("--y", "(deprecated) same as --yes", false).action(generateAction);
|
|
563
611
|
|
|
564
612
|
//#endregion
|
|
565
613
|
//#region src/commands/info.ts
|
|
@@ -5672,6 +5720,124 @@ const generateSecretHash = () => {
|
|
|
5672
5720
|
return Crypto.randomBytes(32).toString("hex");
|
|
5673
5721
|
};
|
|
5674
5722
|
|
|
5723
|
+
//#endregion
|
|
5724
|
+
//#region src/utils/fetch-latest-version.ts
|
|
5725
|
+
async function fetchLatestVersion(packageName) {
|
|
5726
|
+
const encoded = packageName.startsWith("@") ? `@${encodeURIComponent(packageName.slice(1))}` : encodeURIComponent(packageName);
|
|
5727
|
+
try {
|
|
5728
|
+
const response = await fetch(`https://registry.npmjs.org/${encoded}/latest`);
|
|
5729
|
+
if (!response.ok) return null;
|
|
5730
|
+
return (await response.json()).version ?? null;
|
|
5731
|
+
} catch {
|
|
5732
|
+
return null;
|
|
5733
|
+
}
|
|
5734
|
+
}
|
|
5735
|
+
|
|
5736
|
+
//#endregion
|
|
5737
|
+
//#region src/commands/upgrade.ts
|
|
5738
|
+
function isBetterAuthPackage(name) {
|
|
5739
|
+
return name === "better-auth" || name.startsWith("@better-auth/");
|
|
5740
|
+
}
|
|
5741
|
+
async function upgradeAction(opts) {
|
|
5742
|
+
const options = z$1.object({
|
|
5743
|
+
cwd: z$1.string(),
|
|
5744
|
+
yes: z$1.boolean().optional()
|
|
5745
|
+
}).parse(opts);
|
|
5746
|
+
const cwd = path.resolve(options.cwd);
|
|
5747
|
+
if (!existsSync(cwd)) {
|
|
5748
|
+
console.error(`The directory "${cwd}" does not exist.`);
|
|
5749
|
+
process.exit(1);
|
|
5750
|
+
}
|
|
5751
|
+
let packageJson;
|
|
5752
|
+
try {
|
|
5753
|
+
packageJson = getPackageInfo(cwd);
|
|
5754
|
+
} catch {
|
|
5755
|
+
console.error(`Could not read package.json in "${cwd}". Make sure you are in a project directory.`);
|
|
5756
|
+
process.exit(1);
|
|
5757
|
+
}
|
|
5758
|
+
const deps = packageJson.dependencies ?? {};
|
|
5759
|
+
const devDeps = packageJson.devDependencies ?? {};
|
|
5760
|
+
const candidates = [];
|
|
5761
|
+
for (const [name, version] of Object.entries(deps)) if (isBetterAuthPackage(name) && !version.startsWith("workspace:")) candidates.push({
|
|
5762
|
+
name,
|
|
5763
|
+
current: version,
|
|
5764
|
+
depType: "prod"
|
|
5765
|
+
});
|
|
5766
|
+
for (const [name, version] of Object.entries(devDeps)) if (isBetterAuthPackage(name) && !version.startsWith("workspace:")) candidates.push({
|
|
5767
|
+
name,
|
|
5768
|
+
current: version,
|
|
5769
|
+
depType: "dev"
|
|
5770
|
+
});
|
|
5771
|
+
if (candidates.length === 0) {
|
|
5772
|
+
console.log("No better-auth packages found in this project.");
|
|
5773
|
+
return;
|
|
5774
|
+
}
|
|
5775
|
+
const spinner = yoctoSpinner({ text: "checking for updates..." }).start();
|
|
5776
|
+
const results = await Promise.allSettled(candidates.map(async (c) => {
|
|
5777
|
+
const latest = await fetchLatestVersion(c.name);
|
|
5778
|
+
return {
|
|
5779
|
+
...c,
|
|
5780
|
+
latest
|
|
5781
|
+
};
|
|
5782
|
+
}));
|
|
5783
|
+
const upgrades = [];
|
|
5784
|
+
for (const result of results) {
|
|
5785
|
+
if (result.status !== "fulfilled" || !result.value.latest) continue;
|
|
5786
|
+
const { name, current, latest, depType } = result.value;
|
|
5787
|
+
const coerced = semver.coerce(current);
|
|
5788
|
+
if (coerced && semver.lt(coerced, latest)) upgrades.push({
|
|
5789
|
+
name,
|
|
5790
|
+
current,
|
|
5791
|
+
latest,
|
|
5792
|
+
depType
|
|
5793
|
+
});
|
|
5794
|
+
}
|
|
5795
|
+
spinner.stop();
|
|
5796
|
+
if (upgrades.length === 0) {
|
|
5797
|
+
console.log("All better-auth packages are up to date.");
|
|
5798
|
+
return;
|
|
5799
|
+
}
|
|
5800
|
+
console.log(`\nThe following packages can be upgraded:\n`);
|
|
5801
|
+
for (const u of upgrades) console.log(` ${chalk.cyan(u.name)} ${chalk.gray(u.current)} ${chalk.white("→")} ${chalk.green(u.latest)}`);
|
|
5802
|
+
console.log();
|
|
5803
|
+
let confirmed = options.yes;
|
|
5804
|
+
if (!confirmed) confirmed = (await prompts({
|
|
5805
|
+
type: "confirm",
|
|
5806
|
+
name: "confirmed",
|
|
5807
|
+
message: "Do you want to upgrade these packages?",
|
|
5808
|
+
initial: true
|
|
5809
|
+
})).confirmed;
|
|
5810
|
+
if (!confirmed) {
|
|
5811
|
+
console.log("Upgrade cancelled.");
|
|
5812
|
+
return;
|
|
5813
|
+
}
|
|
5814
|
+
const { packageManager } = await detectPackageManager(cwd, packageJson);
|
|
5815
|
+
const prodUpgrades = upgrades.filter((u) => u.depType === "prod").map((u) => `${u.name}@${u.latest}`);
|
|
5816
|
+
const devUpgrades = upgrades.filter((u) => u.depType === "dev").map((u) => `${u.name}@${u.latest}`);
|
|
5817
|
+
const installSpinner = yoctoSpinner({ text: "installing updates..." }).start();
|
|
5818
|
+
try {
|
|
5819
|
+
if (prodUpgrades.length > 0) await installDependencies({
|
|
5820
|
+
dependencies: prodUpgrades,
|
|
5821
|
+
packageManager,
|
|
5822
|
+
cwd,
|
|
5823
|
+
type: "prod"
|
|
5824
|
+
});
|
|
5825
|
+
if (devUpgrades.length > 0) await installDependencies({
|
|
5826
|
+
dependencies: devUpgrades,
|
|
5827
|
+
packageManager,
|
|
5828
|
+
cwd,
|
|
5829
|
+
type: "dev"
|
|
5830
|
+
});
|
|
5831
|
+
installSpinner.stop();
|
|
5832
|
+
console.log(chalk.green("Successfully upgraded better-auth packages."));
|
|
5833
|
+
} catch (error) {
|
|
5834
|
+
installSpinner.stop();
|
|
5835
|
+
console.error("Failed to install updates:", error);
|
|
5836
|
+
process.exit(1);
|
|
5837
|
+
}
|
|
5838
|
+
}
|
|
5839
|
+
const upgrade = new Command("upgrade").description("Upgrade better-auth packages to their latest versions").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("-y, --yes", "automatically accept and upgrade without prompting", false).action(upgradeAction);
|
|
5840
|
+
|
|
5675
5841
|
//#endregion
|
|
5676
5842
|
//#region src/index.ts
|
|
5677
5843
|
process.on("SIGINT", () => process.exit(0));
|
|
@@ -5684,7 +5850,7 @@ async function main() {
|
|
|
5684
5850
|
packageInfo = await getPackageInfo();
|
|
5685
5851
|
cliVersion = packageInfo.version || "1.1.2";
|
|
5686
5852
|
} catch {}
|
|
5687
|
-
program.addCommand(init).addCommand(migrate).addCommand(generate).addCommand(generateSecret).addCommand(info).addCommand(login).addCommand(logout).addCommand(mcp).version(cliVersion).description("Better Auth CLI").action(() => program.help());
|
|
5853
|
+
program.addCommand(init).addCommand(migrate).addCommand(generate).addCommand(generateSecret).addCommand(info).addCommand(login).addCommand(logout).addCommand(mcp).addCommand(upgrade).version(cliVersion).description("Better Auth CLI").action(() => program.help());
|
|
5688
5854
|
program.parse();
|
|
5689
5855
|
}
|
|
5690
5856
|
main().catch((error) => {
|