@better-auth/kysely-adapter 1.7.1 → 1.7.2
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.
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import { n as DEFAULT_MIGRATION_TABLE, t as DEFAULT_MIGRATION_LOCK_TABLE } from "./kysely-migration-tables-DFfmKhq-.mjs";
|
|
2
2
|
import { SqliteAdapter, SqliteQueryCompiler } from "kysely";
|
|
3
3
|
//#region src/d1-sqlite-dialect.ts
|
|
4
|
+
function quoteSqliteStringLiteral(value) {
|
|
5
|
+
return `'${value.replaceAll("'", "''")}'`;
|
|
6
|
+
}
|
|
7
|
+
function createD1IndexIntrospector(database) {
|
|
8
|
+
return async (tableNames) => {
|
|
9
|
+
if (tableNames.length === 0) return [];
|
|
10
|
+
const indexes = (await database.batch(tableNames.map((tableName) => database.prepare(`PRAGMA index_list(${quoteSqliteStringLiteral(tableName)})`)))).flatMap((indexList, tablePosition) => {
|
|
11
|
+
const tableName = tableNames[tablePosition];
|
|
12
|
+
if (!tableName) return [];
|
|
13
|
+
return indexList.results.map((index) => ({
|
|
14
|
+
...index,
|
|
15
|
+
tableName
|
|
16
|
+
}));
|
|
17
|
+
});
|
|
18
|
+
if (indexes.length === 0) return [];
|
|
19
|
+
const indexColumns = await database.batch(indexes.map((index) => database.prepare(`PRAGMA index_info(${quoteSqliteStringLiteral(index.name)})`)));
|
|
20
|
+
return indexes.map((index, indexPosition) => ({
|
|
21
|
+
columns: (indexColumns[indexPosition]?.results ?? []).map((column) => ({
|
|
22
|
+
fullLength: column.name !== null,
|
|
23
|
+
name: column.name,
|
|
24
|
+
position: column.seqno
|
|
25
|
+
})),
|
|
26
|
+
name: index.name,
|
|
27
|
+
partial: index.partial !== 0,
|
|
28
|
+
table: index.tableName,
|
|
29
|
+
unique: index.unique !== 0,
|
|
30
|
+
valid: true
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
}
|
|
4
34
|
var D1SqliteAdapter = class extends SqliteAdapter {};
|
|
5
35
|
var D1SqliteDriver = class {
|
|
6
36
|
#config;
|
|
@@ -111,4 +141,4 @@ var D1SqliteDialect = class {
|
|
|
111
141
|
}
|
|
112
142
|
};
|
|
113
143
|
//#endregion
|
|
114
|
-
export { D1SqliteDialect };
|
|
144
|
+
export { D1SqliteDialect, createD1IndexIntrospector };
|
package/dist/index.d.mts
CHANGED
|
@@ -4,12 +4,42 @@ import { BetterAuthOptions } from "@better-auth/core";
|
|
|
4
4
|
|
|
5
5
|
//#region src/types.d.ts
|
|
6
6
|
type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
|
|
7
|
+
/**
|
|
8
|
+
* Metadata for a column that participates in a database index.
|
|
9
|
+
*/
|
|
10
|
+
interface DatabaseIndexColumnMetadata {
|
|
11
|
+
/**
|
|
12
|
+
* Whether the index covers the complete column value rather than a prefix.
|
|
13
|
+
*/
|
|
14
|
+
readonly fullLength: boolean;
|
|
15
|
+
readonly name: string | null;
|
|
16
|
+
readonly position: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Database-agnostic metadata for an index.
|
|
20
|
+
*/
|
|
21
|
+
interface DatabaseIndexMetadata {
|
|
22
|
+
readonly columns: readonly DatabaseIndexColumnMetadata[];
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly partial: boolean;
|
|
25
|
+
readonly table: string;
|
|
26
|
+
readonly unique: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether the database reports the index as complete and usable.
|
|
29
|
+
*/
|
|
30
|
+
readonly valid: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reads normalized index metadata for the provided database tables.
|
|
34
|
+
*/
|
|
35
|
+
type DatabaseIndexIntrospector = (tableNames: readonly string[]) => Promise<readonly DatabaseIndexMetadata[]>;
|
|
7
36
|
//#endregion
|
|
8
37
|
//#region src/dialect.d.ts
|
|
9
38
|
declare function getKyselyDatabaseType(db: BetterAuthOptions["database"]): KyselyDatabaseType | null;
|
|
10
39
|
declare const createKyselyAdapter: (config: BetterAuthOptions) => Promise<{
|
|
11
40
|
kysely: Kysely<any> | null;
|
|
12
41
|
databaseType: KyselyDatabaseType | null;
|
|
42
|
+
introspectIndexes: DatabaseIndexIntrospector | undefined;
|
|
13
43
|
transaction: boolean | undefined;
|
|
14
44
|
}>;
|
|
15
45
|
//#endregion
|
|
@@ -55,4 +85,4 @@ interface KyselyAdapterConfig {
|
|
|
55
85
|
}
|
|
56
86
|
declare const kyselyAdapter: (db: Kysely<any>, config?: KyselyAdapterConfig | undefined) => (options: BetterAuthOptions) => DBAdapter<BetterAuthOptions>;
|
|
57
87
|
//#endregion
|
|
58
|
-
export { KyselyDatabaseType, createKyselyAdapter, getKyselyDatabaseType, kyselyAdapter };
|
|
88
|
+
export { DatabaseIndexColumnMetadata, DatabaseIndexIntrospector, DatabaseIndexMetadata, KyselyDatabaseType, createKyselyAdapter, getKyselyDatabaseType, kyselyAdapter };
|
package/dist/index.mjs
CHANGED
|
@@ -25,19 +25,23 @@ const createKyselyAdapter = async (config) => {
|
|
|
25
25
|
if (!db) return {
|
|
26
26
|
kysely: null,
|
|
27
27
|
databaseType: null,
|
|
28
|
+
introspectIndexes: void 0,
|
|
28
29
|
transaction: void 0
|
|
29
30
|
};
|
|
30
31
|
if ("db" in db) return {
|
|
31
32
|
kysely: db.db,
|
|
32
33
|
databaseType: db.type,
|
|
34
|
+
introspectIndexes: void 0,
|
|
33
35
|
transaction: db.transaction
|
|
34
36
|
};
|
|
35
37
|
if ("dialect" in db) return {
|
|
36
38
|
kysely: new Kysely({ dialect: db.dialect }),
|
|
37
39
|
databaseType: db.type,
|
|
40
|
+
introspectIndexes: void 0,
|
|
38
41
|
transaction: db.transaction
|
|
39
42
|
};
|
|
40
43
|
let dialect = void 0;
|
|
44
|
+
let introspectIndexes = void 0;
|
|
41
45
|
let transaction = void 0;
|
|
42
46
|
const databaseType = getKyselyDatabaseType(db);
|
|
43
47
|
if ("createDriver" in db) dialect = db;
|
|
@@ -77,13 +81,15 @@ const createKyselyAdapter = async (config) => {
|
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
if ("batch" in db && "exec" in db && "prepare" in db) {
|
|
80
|
-
const { D1SqliteDialect } = await import("./d1-sqlite-dialect-
|
|
84
|
+
const { createD1IndexIntrospector, D1SqliteDialect } = await import("./d1-sqlite-dialect-D4qp4-wW.mjs");
|
|
81
85
|
dialect = new D1SqliteDialect({ database: db });
|
|
86
|
+
introspectIndexes = createD1IndexIntrospector(db);
|
|
82
87
|
transaction = false;
|
|
83
88
|
}
|
|
84
89
|
return {
|
|
85
90
|
kysely: dialect ? new Kysely({ dialect }) : null,
|
|
86
91
|
databaseType,
|
|
92
|
+
introspectIndexes,
|
|
87
93
|
transaction
|
|
88
94
|
};
|
|
89
95
|
};
|
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.2",
|
|
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.
|
|
45
|
+
"@better-auth/core": "^1.7.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"kysely": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"kysely": "^0.28.17 || ^0.29.0",
|
|
56
56
|
"tsdown": "0.21.10",
|
|
57
57
|
"typescript": "^6.0.3",
|
|
58
|
-
"@better-auth/core": "1.7.
|
|
58
|
+
"@better-auth/core": "1.7.2"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "tsdown",
|