@better-auth/kysely-adapter 1.7.3 → 1.7.5

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.d.mts CHANGED
@@ -38,9 +38,16 @@ type DatabaseIndexIntrospector = (tableNames: readonly string[]) => Promise<read
38
38
  //#region src/dialect.d.ts
39
39
  declare function getKyselyDatabaseType(db: BetterAuthOptions["database"]): KyselyDatabaseType | null;
40
40
  declare const createKyselyAdapter: (config: BetterAuthOptions) => Promise<{
41
+ kysely: Kysely<any>;
42
+ databaseType: "postgres" | "mysql" | "sqlite" | "mssql";
43
+ introspectIndexes: undefined;
44
+ schemaName: string | undefined;
45
+ transaction: boolean | undefined;
46
+ } | {
41
47
  kysely: Kysely<any> | null;
42
48
  databaseType: KyselyDatabaseType | null;
43
49
  introspectIndexes: DatabaseIndexIntrospector | undefined;
50
+ schemaName: undefined;
44
51
  transaction: boolean | undefined;
45
52
  }>;
46
53
  //#endregion
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { BetterAuthError } from "@better-auth/core/error";
1
2
  import { ColumnNode, Kysely, MssqlDialect, MysqlDialect, PostgresDialect, ReferenceNode, SelectQueryNode, SqliteDialect, TableNode, sql } from "kysely";
2
3
  import { createAdapterFactory } from "@better-auth/core/db/adapter";
3
4
  import { checksSchema, createSchemaCheck, diffSchema, getExpectedSchema, registerSchemaCheck } from "@better-auth/core/db/internal";
@@ -21,26 +22,43 @@ function getKyselyDatabaseType(db) {
21
22
  if ("batch" in db && "exec" in db && "prepare" in db) return "sqlite";
22
23
  return null;
23
24
  }
25
+ function checkSchemaName(schemaName, databaseType) {
26
+ if (schemaName === void 0) return;
27
+ if (typeof schemaName !== "string" || schemaName.length === 0) throw new BetterAuthError("`database.schemaName` must be a non-empty schema name.");
28
+ if (databaseType !== "postgres") throw new BetterAuthError(`\`database.schemaName\` is only supported on PostgreSQL, but the configured database type is "${databaseType ?? "unknown"}".`);
29
+ }
24
30
  const createKyselyAdapter = async (config) => {
25
31
  const db = config.database;
26
32
  if (!db) return {
27
33
  kysely: null,
28
34
  databaseType: null,
29
35
  introspectIndexes: void 0,
36
+ schemaName: void 0,
30
37
  transaction: void 0
31
38
  };
32
- if ("db" in db) return {
33
- kysely: db.db,
34
- databaseType: db.type,
35
- introspectIndexes: void 0,
36
- transaction: db.transaction
37
- };
38
- if ("dialect" in db) return {
39
- kysely: new Kysely({ dialect: db.dialect }),
40
- databaseType: db.type,
41
- introspectIndexes: void 0,
42
- transaction: db.transaction
43
- };
39
+ if ("db" in db) {
40
+ const schemaName = db.schemaName;
41
+ checkSchemaName(schemaName, db.type);
42
+ return {
43
+ kysely: schemaName ? db.db.withSchema(schemaName) : db.db,
44
+ databaseType: db.type,
45
+ introspectIndexes: void 0,
46
+ schemaName,
47
+ transaction: db.transaction
48
+ };
49
+ }
50
+ if ("dialect" in db) {
51
+ const schemaName = db.schemaName;
52
+ checkSchemaName(schemaName, db.type);
53
+ const kysely = new Kysely({ dialect: db.dialect });
54
+ return {
55
+ kysely: schemaName ? kysely.withSchema(schemaName) : kysely,
56
+ databaseType: db.type,
57
+ introspectIndexes: void 0,
58
+ schemaName,
59
+ transaction: db.transaction
60
+ };
61
+ }
44
62
  let dialect = void 0;
45
63
  let introspectIndexes = void 0;
46
64
  let transaction = void 0;
@@ -91,6 +109,7 @@ const createKyselyAdapter = async (config) => {
91
109
  kysely: dialect ? new Kysely({ dialect }) : null,
92
110
  databaseType,
93
111
  introspectIndexes,
112
+ schemaName: void 0,
94
113
  transaction
95
114
  };
96
115
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/kysely-adapter",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "description": "Kysely adapter for Better Auth",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -42,7 +42,7 @@
42
42
  "peerDependencies": {
43
43
  "@better-auth/utils": "0.4.2",
44
44
  "kysely": "^0.28.17 || ^0.29.0",
45
- "@better-auth/core": "^1.7.3"
45
+ "@better-auth/core": "^1.7.5"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "kysely": {
@@ -57,7 +57,7 @@
57
57
  "pg": "^8.0.0",
58
58
  "tsdown": "0.21.10",
59
59
  "typescript": "^6.0.3",
60
- "@better-auth/core": "1.7.3"
60
+ "@better-auth/core": "1.7.5"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsdown",