@better-auth/drizzle-adapter 1.7.2 → 1.7.3
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
CHANGED
|
@@ -1,8 +1,38 @@
|
|
|
1
1
|
import { a as insensitiveNe, c as getOneToOneRelationKey, i as insensitiveInArray, n as insensitiveEq, o as insensitiveNotInArray, r as insensitiveIlike, s as buildRelationKeysByModel } from "./query-builders-CBLMSM7v.mjs";
|
|
2
2
|
import { createAdapterFactory } from "@better-auth/core/db/adapter";
|
|
3
|
+
import { checksSchema, createSchemaCheck, diffSchema, getExpectedSchema, registerSchemaCheck } from "@better-auth/core/db/internal";
|
|
3
4
|
import { logger } from "@better-auth/core/env";
|
|
4
5
|
import { BetterAuthError } from "@better-auth/core/error";
|
|
5
|
-
import { Column, and, asc, count, desc, eq, gt, gte, inArray, is, isNotNull, isNull, like, lt, lte, ne, notInArray, or, sql } from "drizzle-orm";
|
|
6
|
+
import { Column, Table, and, asc, count, desc, eq, getTableColumns, gt, gte, inArray, is, isNotNull, isNull, like, lt, lte, ne, notInArray, or, sql } from "drizzle-orm";
|
|
7
|
+
//#region src/schema-check.ts
|
|
8
|
+
/**
|
|
9
|
+
* Reads a Drizzle schema object the way the adapter addresses it: each table
|
|
10
|
+
* by the key it is exported under, each column by its property name. Values
|
|
11
|
+
* that are not tables, such as relations, are skipped.
|
|
12
|
+
*/
|
|
13
|
+
function introspectDrizzleSchema(schema) {
|
|
14
|
+
const tables = [];
|
|
15
|
+
for (const [name, table] of Object.entries(schema)) {
|
|
16
|
+
if (!is(table, Table)) continue;
|
|
17
|
+
const columns = Object.entries(getTableColumns(table)).map(([key, column]) => ({
|
|
18
|
+
name: key,
|
|
19
|
+
nullable: !column.notNull,
|
|
20
|
+
hasDefault: column.hasDefault || column.generated !== void 0 || column.generatedIdentity !== void 0
|
|
21
|
+
}));
|
|
22
|
+
tables.push({
|
|
23
|
+
name,
|
|
24
|
+
columns
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return tables;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Compares a Drizzle schema object with the tables this configuration writes.
|
|
31
|
+
*/
|
|
32
|
+
function findDrizzleSchemaProblems(schema, options, usePlural) {
|
|
33
|
+
return diffSchema(getExpectedSchema(options, { usePlural }), introspectDrizzleSchema(schema));
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
6
36
|
//#region src/drizzle-adapter.ts
|
|
7
37
|
/**
|
|
8
38
|
* Derive the number of affected rows from a Drizzle write result.
|
|
@@ -567,7 +597,9 @@ const drizzleAdapter = (db, config) => {
|
|
|
567
597
|
const adapter = createAdapterFactory(adapterOptions);
|
|
568
598
|
return (options) => {
|
|
569
599
|
lazyOptions = options;
|
|
570
|
-
|
|
600
|
+
const instance = adapter(options);
|
|
601
|
+
if (checksSchema(options)) registerSchemaCheck(instance, createSchemaCheck(async () => findDrizzleSchemaProblems(config.schema ?? db._?.fullSchema ?? {}, options, config.usePlural), "drizzle"));
|
|
602
|
+
return instance;
|
|
571
603
|
};
|
|
572
604
|
};
|
|
573
605
|
//#endregion
|
|
@@ -506,7 +506,7 @@ const drizzleAdapter = (db, config) => {
|
|
|
506
506
|
return (await db.update(schemaModel).set(assignments).where(inArray(idColumn, targetIds)).returning())[0] ?? null;
|
|
507
507
|
},
|
|
508
508
|
async createSchema(props) {
|
|
509
|
-
const { generateDrizzleSchema } = await import("../generate-drizzle-schema-
|
|
509
|
+
const { generateDrizzleSchema } = await import("../generate-drizzle-schema-iWvrXnu0.mjs");
|
|
510
510
|
return await generateDrizzleSchema({
|
|
511
511
|
adapterConfig: config,
|
|
512
512
|
options,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/drizzle-adapter",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.3",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/better-auth/better-auth/issues"
|
|
6
6
|
},
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@better-auth/utils": "0.4.2",
|
|
47
47
|
"drizzle-orm": "^0.45.2 || >=1.0.0-rc.1 <2.0.0",
|
|
48
|
-
"@better-auth/core": "^1.7.
|
|
48
|
+
"@better-auth/core": "^1.7.3"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
51
51
|
"drizzle-orm": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"drizzle-orm": "^0.45.2",
|
|
58
58
|
"tsdown": "0.21.10",
|
|
59
59
|
"typescript": "^6.0.3",
|
|
60
|
-
"@better-auth/core": "1.7.
|
|
60
|
+
"@better-auth/core": "1.7.3"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { initGetFieldName, initGetModelName } from "@better-auth/core/db/adapter";
|
|
2
|
+
import { getDatabaseFieldIndexName, getDatabaseIndexStringLength, resolveDatabaseSchemaIndexes } from "@better-auth/core/db/internal";
|
|
2
3
|
import { existsSync } from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { getAuthTables } from "@better-auth/core/db";
|
|
5
|
-
import { getDatabaseFieldIndexName, getDatabaseIndexStringLength, resolveDatabaseSchemaIndexes } from "@better-auth/core/db/internal";
|
|
6
6
|
//#region src/relations-v2/generate-drizzle-schema.ts
|
|
7
7
|
function convertToSnakeCase(str, camelCase) {
|
|
8
8
|
if (camelCase) return str;
|