@better-auth/kysely-adapter 1.7.20 → 1.7.22
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/{bun-sqlite-dialect-DN2jcl8c.mjs → bun-sqlite-dialect-C1xgdqho.mjs} +2 -3
- package/dist/{d1-sqlite-dialect-BgJMzZQp.mjs → d1-sqlite-dialect-CFQyWgtB.mjs} +2 -3
- package/dist/index.d.mts +9 -8
- package/dist/index.mjs +63 -13
- package/dist/node-sqlite-dialect.d.mts +1 -3
- package/dist/node-sqlite-dialect.mjs +2 -3
- package/dist/{sqlite-introspector-_wy6Ac6e.mjs → sqlite-introspector-DeY-XxNH.mjs} +2 -4
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createSqliteIntrospector } from "./sqlite-introspector-
|
|
1
|
+
import { t as createSqliteIntrospector } from "./sqlite-introspector-DeY-XxNH.mjs";
|
|
2
2
|
import { CompiledQuery, DefaultQueryCompiler } from "kysely";
|
|
3
|
-
|
|
3
|
+
// src/bun-sqlite-dialect.ts
|
|
4
4
|
var BunSqliteAdapter = class {
|
|
5
5
|
get supportsCreateIfNotExists() {
|
|
6
6
|
return true;
|
|
@@ -119,5 +119,4 @@ var BunSqliteDialect = class {
|
|
|
119
119
|
return createSqliteIntrospector(db);
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
|
-
//#endregion
|
|
123
122
|
export { BunSqliteDialect };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as DEFAULT_MIGRATION_LOCK_TABLE, i as toSqliteTableMetadata, o as DEFAULT_MIGRATION_TABLE, r as sqliteIntegerPrimaryKeyColumn } from "./sqlite-introspector-
|
|
1
|
+
import { a as DEFAULT_MIGRATION_LOCK_TABLE, i as toSqliteTableMetadata, o as DEFAULT_MIGRATION_TABLE, r as sqliteIntegerPrimaryKeyColumn } from "./sqlite-introspector-DeY-XxNH.mjs";
|
|
2
2
|
import { SqliteAdapter, SqliteQueryCompiler } from "kysely";
|
|
3
|
-
|
|
3
|
+
// src/d1-sqlite-dialect.ts
|
|
4
4
|
function quoteSqliteStringLiteral(value) {
|
|
5
5
|
return `'${value.replaceAll("'", "''")}'`;
|
|
6
6
|
}
|
|
@@ -134,5 +134,4 @@ var D1SqliteDialect = class {
|
|
|
134
134
|
return new D1SqliteIntrospector(db, this.#config.database);
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
|
-
//#endregion
|
|
138
137
|
export { D1SqliteDialect, createD1IndexIntrospector };
|
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { Kysely, TableMetadata } from "kysely";
|
|
|
2
2
|
import { DBAdapter, DBAdapterDebugLogOption } from "@better-auth/core/db/adapter";
|
|
3
3
|
import { ExpectedSchema, IntrospectedTable } from "@better-auth/core/db/internal";
|
|
4
4
|
import { BetterAuthOptions } from "@better-auth/core";
|
|
5
|
-
//#region src/types.d.ts
|
|
6
5
|
export type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
|
|
7
6
|
/**
|
|
8
7
|
* Metadata for a column that participates in a database index.
|
|
@@ -33,8 +32,6 @@ export interface DatabaseIndexMetadata {
|
|
|
33
32
|
* Reads normalized index metadata for the provided database tables.
|
|
34
33
|
*/
|
|
35
34
|
export type DatabaseIndexIntrospector = (tableNames: readonly string[]) => Promise<readonly DatabaseIndexMetadata[]>;
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/dialect.d.ts
|
|
38
35
|
export declare function getKyselyDatabaseType(db: BetterAuthOptions["database"]): KyselyDatabaseType | null;
|
|
39
36
|
export declare const createKyselyAdapter: (config: BetterAuthOptions) => Promise<{
|
|
40
37
|
kysely: Kysely<any>;
|
|
@@ -49,8 +46,6 @@ export declare const createKyselyAdapter: (config: BetterAuthOptions) => Promise
|
|
|
49
46
|
schemaName: undefined;
|
|
50
47
|
transaction: boolean | undefined;
|
|
51
48
|
}>;
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region src/kysely-adapter.d.ts
|
|
54
49
|
interface KyselyAdapterConfig {
|
|
55
50
|
/**
|
|
56
51
|
* Database type.
|
|
@@ -91,8 +86,6 @@ interface KyselyAdapterConfig {
|
|
|
91
86
|
transaction?: boolean | undefined;
|
|
92
87
|
}
|
|
93
88
|
export declare const kyselyAdapter: (db: Kysely<any>, config?: KyselyAdapterConfig | undefined) => (options: BetterAuthOptions) => DBAdapter<BetterAuthOptions>;
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region src/schema-check.d.ts
|
|
96
89
|
/**
|
|
97
90
|
* Converts Kysely table metadata into the shape `diffSchema` compares.
|
|
98
91
|
*/
|
|
@@ -111,5 +104,13 @@ export declare function toPhysicalSchema(db: Kysely<unknown>, expected: Expected
|
|
|
111
104
|
*/
|
|
112
105
|
export declare function getPostgresSchema(db: Kysely<unknown>): Promise<string>;
|
|
113
106
|
export declare function getMssqlSchema(db: Kysely<unknown>): Promise<string>;
|
|
114
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Reads the tables in `schemas` with the metadata Kysely's PostgreSQL
|
|
109
|
+
* introspector reports. That introspector reads every schema and resolves
|
|
110
|
+
* each one by name, so a schema another connection drops during the read
|
|
111
|
+
* fails it with "schema does not exist" or "relation does not exist".
|
|
112
|
+
*/
|
|
113
|
+
export declare function introspectPostgresTables(db: Kysely<unknown>, schemas: readonly string[]): Promise<(TableMetadata & {
|
|
114
|
+
isForeign: boolean;
|
|
115
|
+
})[]>;
|
|
115
116
|
export {};
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { n as introspectSqliteTables } from "./sqlite-introspector-
|
|
1
|
+
import { n as introspectSqliteTables } from "./sqlite-introspector-DeY-XxNH.mjs";
|
|
2
2
|
import { BetterAuthError } from "@better-auth/core/error";
|
|
3
3
|
import { ColumnNode, Kysely, MssqlDialect, MysqlDialect, PostgresDialect, ReferenceNode, SelectQueryNode, SqliteDialect, TableNode, sql } from "kysely";
|
|
4
4
|
import { createAdapterFactory } from "@better-auth/core/db/adapter";
|
|
5
5
|
import { checksSchema, createSchemaCheck, diffSchema, getExpectedSchema, registerSchemaCheck } from "@better-auth/core/db/internal";
|
|
6
6
|
import { logger } from "@better-auth/core/env";
|
|
7
7
|
import { capitalizeFirstLetter } from "@better-auth/core/utils/string";
|
|
8
|
-
|
|
8
|
+
// src/dialect.ts
|
|
9
9
|
function getKyselyDatabaseType(db) {
|
|
10
10
|
if (!db) return null;
|
|
11
11
|
if ("dialect" in db) return getKyselyDatabaseType(db.dialect);
|
|
@@ -78,7 +78,7 @@ const createKyselyAdapter = async (config) => {
|
|
|
78
78
|
transaction = true;
|
|
79
79
|
}
|
|
80
80
|
if ("fileControl" in db) {
|
|
81
|
-
const { BunSqliteDialect } = await import("./bun-sqlite-dialect-
|
|
81
|
+
const { BunSqliteDialect } = await import("./bun-sqlite-dialect-C1xgdqho.mjs");
|
|
82
82
|
dialect = new BunSqliteDialect({ database: db });
|
|
83
83
|
transaction = true;
|
|
84
84
|
}
|
|
@@ -101,7 +101,7 @@ const createKyselyAdapter = async (config) => {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
if ("batch" in db && "exec" in db && "prepare" in db) {
|
|
104
|
-
const { createD1IndexIntrospector, D1SqliteDialect } = await import("./d1-sqlite-dialect-
|
|
104
|
+
const { createD1IndexIntrospector, D1SqliteDialect } = await import("./d1-sqlite-dialect-CFQyWgtB.mjs");
|
|
105
105
|
dialect = new D1SqliteDialect({ database: db });
|
|
106
106
|
introspectIndexes = createD1IndexIntrospector(db);
|
|
107
107
|
transaction = false;
|
|
@@ -114,8 +114,7 @@ const createKyselyAdapter = async (config) => {
|
|
|
114
114
|
transaction
|
|
115
115
|
};
|
|
116
116
|
};
|
|
117
|
-
|
|
118
|
-
//#region src/query-builders.ts
|
|
117
|
+
// src/query-builders.ts
|
|
119
118
|
/**
|
|
120
119
|
* Case-insensitive ILIKE/LIKE for pattern matching.
|
|
121
120
|
* Uses ILIKE on PostgreSQL, LOWER()+LIKE on MySQL/SQLite/MSSQL.
|
|
@@ -161,8 +160,7 @@ function insensitiveNe(columnRef, value) {
|
|
|
161
160
|
value: value.toLowerCase()
|
|
162
161
|
};
|
|
163
162
|
}
|
|
164
|
-
|
|
165
|
-
//#region src/schema-check.ts
|
|
163
|
+
// src/schema-check.ts
|
|
166
164
|
/**
|
|
167
165
|
* Converts Kysely table metadata into the shape `diffSchema` compares.
|
|
168
166
|
*/
|
|
@@ -236,6 +234,60 @@ async function getMssqlSchema(db) {
|
|
|
236
234
|
SELECT SCHEMA_NAME() AS "schemaName"
|
|
237
235
|
`.execute(db.withoutPlugins())).rows[0]?.schemaName || "dbo";
|
|
238
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Reads the tables in `schemas` with the metadata Kysely's PostgreSQL
|
|
239
|
+
* introspector reports. That introspector reads every schema and resolves
|
|
240
|
+
* each one by name, so a schema another connection drops during the read
|
|
241
|
+
* fails it with "schema does not exist" or "relation does not exist".
|
|
242
|
+
*/
|
|
243
|
+
async function introspectPostgresTables(db, schemas) {
|
|
244
|
+
if (schemas.length === 0) return [];
|
|
245
|
+
const { rows } = await sql`
|
|
246
|
+
SELECT
|
|
247
|
+
ns.nspname AS "schema",
|
|
248
|
+
c.relname AS "table",
|
|
249
|
+
c.relkind = 'v' AS "isView",
|
|
250
|
+
c.relkind = 'f' AS "isForeign",
|
|
251
|
+
a.attname AS "column",
|
|
252
|
+
typ.typname AS "dataType",
|
|
253
|
+
NOT a.attnotnull AS "isNullable",
|
|
254
|
+
a.atthasdef AS "hasDefaultValue",
|
|
255
|
+
pg_catalog.pg_get_serial_sequence(
|
|
256
|
+
pg_catalog.quote_ident(ns.nspname) || '.' || pg_catalog.quote_ident(c.relname),
|
|
257
|
+
a.attname
|
|
258
|
+
) IS NOT NULL AS "isAutoIncrementing"
|
|
259
|
+
FROM pg_catalog.pg_attribute AS a
|
|
260
|
+
INNER JOIN pg_catalog.pg_class AS c ON c.oid = a.attrelid
|
|
261
|
+
INNER JOIN pg_catalog.pg_namespace AS ns ON ns.oid = c.relnamespace
|
|
262
|
+
INNER JOIN pg_catalog.pg_type AS typ ON typ.oid = a.atttypid
|
|
263
|
+
WHERE ns.nspname IN (${sql.join(schemas)})
|
|
264
|
+
AND ns.nspname !~ '^pg_'
|
|
265
|
+
AND pg_catalog.has_schema_privilege(ns.oid, 'USAGE')
|
|
266
|
+
AND c.relkind IN ('r', 'v', 'p', 'f')
|
|
267
|
+
AND a.attnum >= 0
|
|
268
|
+
AND NOT a.attisdropped
|
|
269
|
+
ORDER BY ns.nspname, c.relname, a.attnum
|
|
270
|
+
`.execute(db.withoutPlugins());
|
|
271
|
+
const tables = [];
|
|
272
|
+
let current;
|
|
273
|
+
for (const { schema, table, isView, isForeign, column, ...metadata } of rows) {
|
|
274
|
+
if (current?.schema !== schema || current.name !== table) {
|
|
275
|
+
current = {
|
|
276
|
+
name: table,
|
|
277
|
+
schema,
|
|
278
|
+
isView,
|
|
279
|
+
isForeign,
|
|
280
|
+
columns: []
|
|
281
|
+
};
|
|
282
|
+
tables.push(current);
|
|
283
|
+
}
|
|
284
|
+
current.columns.push({
|
|
285
|
+
name: column,
|
|
286
|
+
...metadata
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
return tables;
|
|
290
|
+
}
|
|
239
291
|
async function schemaSearchPath(db, dbType) {
|
|
240
292
|
if (dbType === "postgres") return (await sql`
|
|
241
293
|
SELECT pg_catalog.current_schemas(true)::text[] AS schemas
|
|
@@ -257,7 +309,7 @@ async function findSchemaProblems(db, dbType, expected) {
|
|
|
257
309
|
}
|
|
258
310
|
return db.connection().execute(async (connection) => {
|
|
259
311
|
const searchPath = await schemaSearchPath(connection, dbType);
|
|
260
|
-
const tables = toIntrospectedTables(await connection.introspection.getTables());
|
|
312
|
+
const tables = toIntrospectedTables(dbType === "postgres" ? await introspectPostgresTables(connection, [...searchPath ?? [], ...Object.values(physical).flatMap(({ schema }) => schema ?? [])]) : await connection.introspection.getTables());
|
|
261
313
|
for (const [name, table] of Object.entries(physical)) {
|
|
262
314
|
if (table.schema !== void 0 || !searchPath) continue;
|
|
263
315
|
table.schema = searchPath.find((schema) => tables.some((candidate) => candidate.name === name && candidate.schema === schema)) ?? "";
|
|
@@ -265,8 +317,7 @@ async function findSchemaProblems(db, dbType, expected) {
|
|
|
265
317
|
return diffSchema(physical, tables);
|
|
266
318
|
});
|
|
267
319
|
}
|
|
268
|
-
|
|
269
|
-
//#region src/kysely-adapter.ts
|
|
320
|
+
// src/kysely-adapter.ts
|
|
270
321
|
const kyselyAdapter = (db, config) => {
|
|
271
322
|
let lazyOptions = null;
|
|
272
323
|
let mysqlNoIdWarned = false;
|
|
@@ -721,5 +772,4 @@ const kyselyAdapter = (db, config) => {
|
|
|
721
772
|
return instance;
|
|
722
773
|
};
|
|
723
774
|
};
|
|
724
|
-
|
|
725
|
-
export { createKyselyAdapter, getKyselyDatabaseType, getMssqlSchema, getPostgresSchema, kyselyAdapter, toIntrospectedTables, toPhysicalSchema };
|
|
775
|
+
export { createKyselyAdapter, getKyselyDatabaseType, getMssqlSchema, getPostgresSchema, introspectPostgresTables, kyselyAdapter, toIntrospectedTables, toPhysicalSchema };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DatabaseConnection, DatabaseIntrospector, Dialect, DialectAdapter, Driver, Kysely, QueryCompiler } from "kysely";
|
|
2
2
|
import { DatabaseSync } from "node:sqlite";
|
|
3
|
-
//#region src/node-sqlite-dialect.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Config for the SQLite dialect.
|
|
6
5
|
*/
|
|
@@ -21,5 +20,4 @@ export declare class NodeSqliteDialect implements Dialect {
|
|
|
21
20
|
createQueryCompiler(): QueryCompiler;
|
|
22
21
|
createAdapter(): DialectAdapter;
|
|
23
22
|
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
23
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createSqliteIntrospector } from "./sqlite-introspector-
|
|
1
|
+
import { t as createSqliteIntrospector } from "./sqlite-introspector-DeY-XxNH.mjs";
|
|
2
2
|
import { CompiledQuery, DefaultQueryCompiler } from "kysely";
|
|
3
|
-
|
|
3
|
+
// src/node-sqlite-dialect.ts
|
|
4
4
|
var NodeSqliteAdapter = class {
|
|
5
5
|
get supportsCreateIfNotExists() {
|
|
6
6
|
return true;
|
|
@@ -119,5 +119,4 @@ var NodeSqliteDialect = class {
|
|
|
119
119
|
return createSqliteIntrospector(db);
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
|
-
//#endregion
|
|
123
122
|
export { NodeSqliteDialect };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sql } from "kysely";
|
|
2
|
-
|
|
2
|
+
// src/kysely-migration-tables.ts
|
|
3
3
|
/**
|
|
4
4
|
* Kysely's internal migration table names, mirrored as local constants.
|
|
5
5
|
*
|
|
@@ -14,8 +14,7 @@ import { sql } from "kysely";
|
|
|
14
14
|
*/
|
|
15
15
|
const DEFAULT_MIGRATION_TABLE = "kysely_migration";
|
|
16
16
|
const DEFAULT_MIGRATION_LOCK_TABLE = "kysely_migration_lock";
|
|
17
|
-
|
|
18
|
-
//#region src/sqlite-introspector.ts
|
|
17
|
+
// src/sqlite-introspector.ts
|
|
19
18
|
function sqliteIntegerPrimaryKeyColumn(columns) {
|
|
20
19
|
const primaryKeys = columns.filter((column) => column.pk > 0);
|
|
21
20
|
const primaryKey = primaryKeys.length === 1 ? primaryKeys[0] : void 0;
|
|
@@ -86,5 +85,4 @@ function createSqliteIntrospector(db) {
|
|
|
86
85
|
getMetadata: async (options) => ({ tables: await getTables(options) })
|
|
87
86
|
};
|
|
88
87
|
}
|
|
89
|
-
//#endregion
|
|
90
88
|
export { DEFAULT_MIGRATION_LOCK_TABLE as a, toSqliteTableMetadata as i, introspectSqliteTables as n, DEFAULT_MIGRATION_TABLE as o, sqliteIntegerPrimaryKeyColumn as r, createSqliteIntrospector as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/kysely-adapter",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.22",
|
|
4
4
|
"description": "Kysely adapter for Better Auth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
+
"@better-auth/core": "^1.7.22",
|
|
43
44
|
"@better-auth/utils": "^0.4.2 || ^0.5.0",
|
|
44
|
-
"kysely": "^0.28.17 || ^0.29.0"
|
|
45
|
-
"@better-auth/core": "^1.7.20"
|
|
45
|
+
"kysely": "^0.28.17 || ^0.29.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"kysely": {
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
+
"@better-auth/core": "1.7.22",
|
|
53
54
|
"@better-auth/utils": "0.5.1",
|
|
54
55
|
"@cloudflare/workers-types": "^4.20250121.0",
|
|
55
56
|
"@types/pg": "^8.20.0",
|
|
56
57
|
"kysely": "^0.28.17 || ^0.29.0",
|
|
57
58
|
"pg": "^8.0.0",
|
|
58
59
|
"tsdown": "0.23.1",
|
|
59
|
-
"typescript": "^6.0.3"
|
|
60
|
-
"@better-auth/core": "1.7.20"
|
|
60
|
+
"typescript": "^6.0.3"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|