@better-auth/cli 1.4.0-beta.24 → 1.4.0-beta.27
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/index.mjs +18 -16
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -195,10 +195,12 @@ const generateDrizzleSchema = async ({ options, file, adapter }) => {
|
|
|
195
195
|
const foreignKeysPointingHere = Object.entries(otherTable.fields).filter(([_, field]) => field.references?.model === tableKey || field.references?.model === getModelName(tableKey));
|
|
196
196
|
for (const [fieldName, field] of foreignKeysPointingHere) {
|
|
197
197
|
const isUnique = !!field.unique;
|
|
198
|
-
|
|
198
|
+
let relationKey = getModelName(modelName);
|
|
199
|
+
if (!adapter.options?.adapterConfig?.usePlural && !isUnique) relationKey = `${relationKey}s`;
|
|
200
|
+
const model = getModelName(modelName);
|
|
199
201
|
relations.push({
|
|
200
202
|
key: relationKey,
|
|
201
|
-
model
|
|
203
|
+
model,
|
|
202
204
|
type: isUnique ? "one" : "many"
|
|
203
205
|
});
|
|
204
206
|
}
|
|
@@ -279,6 +281,14 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
|
|
|
279
281
|
const tables = getAuthTables(options);
|
|
280
282
|
const filePath = file || "./prisma/schema.prisma";
|
|
281
283
|
const schemaPrismaExist = existsSync(path.join(process.cwd(), filePath));
|
|
284
|
+
const getModelName = initGetModelName({
|
|
285
|
+
schema: getAuthTables(options),
|
|
286
|
+
usePlural: adapter.options?.adapterConfig?.usePlural
|
|
287
|
+
});
|
|
288
|
+
const getFieldName = initGetFieldName({
|
|
289
|
+
schema: getAuthTables(options),
|
|
290
|
+
usePlural: false
|
|
291
|
+
});
|
|
282
292
|
let schemaPrisma = "";
|
|
283
293
|
if (schemaPrismaExist) schemaPrisma = await fs$1.readFile(path.join(process.cwd(), filePath), "utf-8");
|
|
284
294
|
else schemaPrisma = getNewPrisma(provider);
|
|
@@ -289,9 +299,9 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
|
|
|
289
299
|
const attr = fields[field];
|
|
290
300
|
if (attr.references) {
|
|
291
301
|
const referencedOriginalModel = attr.references.model;
|
|
292
|
-
const referencedModelNameCap = capitalizeFirstLetter(tables[referencedOriginalModel]?.modelName || referencedOriginalModel);
|
|
302
|
+
const referencedModelNameCap = capitalizeFirstLetter(getModelName(tables[referencedOriginalModel]?.modelName || referencedOriginalModel));
|
|
293
303
|
if (!manyToManyRelations.has(referencedModelNameCap)) manyToManyRelations.set(referencedModelNameCap, /* @__PURE__ */ new Set());
|
|
294
|
-
const currentModelNameCap = capitalizeFirstLetter(tables[table]?.modelName || table);
|
|
304
|
+
const currentModelNameCap = capitalizeFirstLetter(getModelName(tables[table]?.modelName || table));
|
|
295
305
|
manyToManyRelations.get(referencedModelNameCap).add(currentModelNameCap);
|
|
296
306
|
}
|
|
297
307
|
}
|
|
@@ -299,7 +309,7 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
|
|
|
299
309
|
const indexedFields = /* @__PURE__ */ new Map();
|
|
300
310
|
for (const table in tables) {
|
|
301
311
|
const fields = tables[table]?.fields;
|
|
302
|
-
const modelName = capitalizeFirstLetter(tables[table]?.modelName || table);
|
|
312
|
+
const modelName = capitalizeFirstLetter(getModelName(tables[table]?.modelName || table));
|
|
303
313
|
indexedFields.set(modelName, []);
|
|
304
314
|
for (const field in fields) {
|
|
305
315
|
const attr = fields[field];
|
|
@@ -313,7 +323,7 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
|
|
|
313
323
|
for (const table in tables) {
|
|
314
324
|
const originalTableName = table;
|
|
315
325
|
const customModelName = tables[table]?.modelName || table;
|
|
316
|
-
const modelName = capitalizeFirstLetter(customModelName);
|
|
326
|
+
const modelName = capitalizeFirstLetter(getModelName(customModelName));
|
|
317
327
|
const fields = tables[table]?.fields;
|
|
318
328
|
function getType({ isBigint, isOptional, type }) {
|
|
319
329
|
if (type === "string") return isOptional ? "String?" : "String";
|
|
@@ -334,14 +344,6 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
|
|
|
334
344
|
else if (useUUIDs && provider === "postgresql") builder.model(modelName).field("id", "String").attribute("id").attribute("default(dbgenerated(\"pg_catalog.gen_random_uuid()\"))").attribute("db.Uuid");
|
|
335
345
|
else builder.model(modelName).field("id", "String").attribute("id");
|
|
336
346
|
}
|
|
337
|
-
const getModelName = initGetModelName({
|
|
338
|
-
schema: getAuthTables(options),
|
|
339
|
-
usePlural: adapter.options?.adapterConfig?.usePlural
|
|
340
|
-
});
|
|
341
|
-
const getFieldName = initGetFieldName({
|
|
342
|
-
schema: getAuthTables(options),
|
|
343
|
-
usePlural: false
|
|
344
|
-
});
|
|
345
347
|
for (const field in fields) {
|
|
346
348
|
const attr = fields[field];
|
|
347
349
|
const fieldName = attr.fieldName || field;
|
|
@@ -430,7 +432,7 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
|
|
|
430
432
|
const relatedFields = relatedTableName ? tables[relatedTableName]?.fields : {};
|
|
431
433
|
const [_fieldKey, fkFieldAttr] = Object.entries(relatedFields || {}).find(([_fieldName, fieldAttr]) => fieldAttr.references && getModelName(fieldAttr.references.model) === getModelName(originalTableName)) || [];
|
|
432
434
|
const isUnique = fkFieldAttr?.unique === true;
|
|
433
|
-
const fieldName = isUnique ? `${relatedModel.toLowerCase()}` : `${relatedModel.toLowerCase()}s`;
|
|
435
|
+
const fieldName = isUnique || adapter.options?.usePlural === true ? `${relatedModel.toLowerCase()}` : `${relatedModel.toLowerCase()}s`;
|
|
434
436
|
if (!builder.findByType("field", {
|
|
435
437
|
name: fieldName,
|
|
436
438
|
within: prismaModel?.properties
|
|
@@ -453,7 +455,7 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
|
|
|
453
455
|
within: prismaModel?.properties
|
|
454
456
|
});
|
|
455
457
|
const hasChanged = customModelName !== originalTableName;
|
|
456
|
-
if (!hasAttribute) builder.model(modelName).blockAttribute("map", `${hasChanged ? customModelName : originalTableName}`);
|
|
458
|
+
if (!hasAttribute) builder.model(modelName).blockAttribute("map", `${getModelName(hasChanged ? customModelName : originalTableName)}`);
|
|
457
459
|
}
|
|
458
460
|
});
|
|
459
461
|
const schemaChanged = schema.trim() !== schemaPrisma.trim();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/cli",
|
|
3
|
-
"version": "1.4.0-beta.
|
|
3
|
+
"version": "1.4.0-beta.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The CLI for Better Auth",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"tsx": "^4.20.6",
|
|
35
35
|
"type-fest": "^5.2.0",
|
|
36
36
|
"typescript": "^5.9.3",
|
|
37
|
-
"@better-auth/passkey": "1.4.0-beta.
|
|
37
|
+
"@better-auth/passkey": "1.4.0-beta.27"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@babel/core": "^7.28.4",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"tinyexec": "^0.3.2",
|
|
63
63
|
"yocto-spinner": "^0.2.3",
|
|
64
64
|
"zod": "^4.1.12",
|
|
65
|
-
"
|
|
66
|
-
"better-auth": "1.4.0-beta.
|
|
65
|
+
"better-auth": "1.4.0-beta.27",
|
|
66
|
+
"@better-auth/core": "1.4.0-beta.27"
|
|
67
67
|
},
|
|
68
68
|
"files": [
|
|
69
69
|
"dist"
|