@better-auth/kysely-adapter 1.7.12 → 1.7.13
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-DoOVo4ja.mjs → bun-sqlite-dialect-DN2jcl8c.mjs} +1 -1
- package/dist/{d1-sqlite-dialect-m0f01-4z.mjs → d1-sqlite-dialect-BgJMzZQp.mjs} +3 -2
- package/dist/index.d.mts +12 -13
- package/dist/index.mjs +12 -6
- package/dist/node-sqlite-dialect.d.mts +3 -5
- package/dist/node-sqlite-dialect.mjs +1 -1
- package/package.json +5 -5
- /package/dist/{sqlite-introspector-DSCAP82F.mjs → sqlite-introspector-_wy6Ac6e.mjs} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createSqliteIntrospector } from "./sqlite-introspector-
|
|
1
|
+
import { t as createSqliteIntrospector } from "./sqlite-introspector-_wy6Ac6e.mjs";
|
|
2
2
|
import { CompiledQuery, DefaultQueryCompiler } from "kysely";
|
|
3
3
|
//#region src/bun-sqlite-dialect.ts
|
|
4
4
|
var BunSqliteAdapter = class {
|
|
@@ -1,4 +1,4 @@
|
|
|
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-_wy6Ac6e.mjs";
|
|
2
2
|
import { SqliteAdapter, SqliteQueryCompiler } from "kysely";
|
|
3
3
|
//#region src/d1-sqlite-dialect.ts
|
|
4
4
|
function quoteSqliteStringLiteral(value) {
|
|
@@ -107,7 +107,8 @@ var D1SqliteIntrospector = class {
|
|
|
107
107
|
const indexResults = rowidCandidates.length ? await this.#d1.batch(rowidCandidates.map(({ tableName }) => this.#d1.prepare(`PRAGMA index_list(${quoteSqliteStringLiteral(tableName)})`))) : [];
|
|
108
108
|
const generatedColumns = new Map(rowidCandidates.filter((_, index) => !indexResults[index]?.results?.some((row) => row.origin === "pk")).map(({ index, column }) => [index, column]));
|
|
109
109
|
return tables.map((table, index) => {
|
|
110
|
-
|
|
110
|
+
const columns = batchResults[index]?.results ?? [];
|
|
111
|
+
return toSqliteTableMetadata(table, columns, generatedColumns.get(index));
|
|
111
112
|
});
|
|
112
113
|
}
|
|
113
114
|
async getMetadata(options) {
|
package/dist/index.d.mts
CHANGED
|
@@ -2,13 +2,12 @@ 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
|
-
|
|
6
5
|
//#region src/types.d.ts
|
|
7
|
-
type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
|
|
6
|
+
export type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
|
|
8
7
|
/**
|
|
9
8
|
* Metadata for a column that participates in a database index.
|
|
10
9
|
*/
|
|
11
|
-
interface DatabaseIndexColumnMetadata {
|
|
10
|
+
export interface DatabaseIndexColumnMetadata {
|
|
12
11
|
/**
|
|
13
12
|
* Whether the index covers the complete column value rather than a prefix.
|
|
14
13
|
*/
|
|
@@ -19,7 +18,7 @@ interface DatabaseIndexColumnMetadata {
|
|
|
19
18
|
/**
|
|
20
19
|
* Database-agnostic metadata for an index.
|
|
21
20
|
*/
|
|
22
|
-
interface DatabaseIndexMetadata {
|
|
21
|
+
export interface DatabaseIndexMetadata {
|
|
23
22
|
readonly columns: readonly DatabaseIndexColumnMetadata[];
|
|
24
23
|
readonly name: string;
|
|
25
24
|
readonly partial: boolean;
|
|
@@ -33,11 +32,11 @@ interface DatabaseIndexMetadata {
|
|
|
33
32
|
/**
|
|
34
33
|
* Reads normalized index metadata for the provided database tables.
|
|
35
34
|
*/
|
|
36
|
-
type DatabaseIndexIntrospector = (tableNames: readonly string[]) => Promise<readonly DatabaseIndexMetadata[]>;
|
|
35
|
+
export type DatabaseIndexIntrospector = (tableNames: readonly string[]) => Promise<readonly DatabaseIndexMetadata[]>;
|
|
37
36
|
//#endregion
|
|
38
37
|
//#region src/dialect.d.ts
|
|
39
|
-
declare function getKyselyDatabaseType(db: BetterAuthOptions["database"]): KyselyDatabaseType | null;
|
|
40
|
-
declare const createKyselyAdapter: (config: BetterAuthOptions) => Promise<{
|
|
38
|
+
export declare function getKyselyDatabaseType(db: BetterAuthOptions["database"]): KyselyDatabaseType | null;
|
|
39
|
+
export declare const createKyselyAdapter: (config: BetterAuthOptions) => Promise<{
|
|
41
40
|
kysely: Kysely<any>;
|
|
42
41
|
databaseType: "postgres" | "mysql" | "sqlite" | "mssql";
|
|
43
42
|
introspectIndexes: undefined;
|
|
@@ -91,26 +90,26 @@ interface KyselyAdapterConfig {
|
|
|
91
90
|
*/
|
|
92
91
|
transaction?: boolean | undefined;
|
|
93
92
|
}
|
|
94
|
-
declare const kyselyAdapter: (db: Kysely<any>, config?: KyselyAdapterConfig | undefined) => (options: BetterAuthOptions) => DBAdapter<BetterAuthOptions>;
|
|
93
|
+
export declare const kyselyAdapter: (db: Kysely<any>, config?: KyselyAdapterConfig | undefined) => (options: BetterAuthOptions) => DBAdapter<BetterAuthOptions>;
|
|
95
94
|
//#endregion
|
|
96
95
|
//#region src/schema-check.d.ts
|
|
97
96
|
/**
|
|
98
97
|
* Converts Kysely table metadata into the shape `diffSchema` compares.
|
|
99
98
|
*/
|
|
100
|
-
declare function toIntrospectedTables(tables: readonly TableMetadata[]): IntrospectedTable[];
|
|
99
|
+
export declare function toIntrospectedTables(tables: readonly TableMetadata[]): IntrospectedTable[];
|
|
101
100
|
/**
|
|
102
101
|
* The expected schema in the identifiers the connection sends. A plugin that
|
|
103
102
|
* renames identifiers, such as `CamelCasePlugin`, does so in `transformQuery`,
|
|
104
103
|
* so compiling one select per table through the connection yields the names
|
|
105
104
|
* the database is asked for. Without such a plugin the schema is unchanged.
|
|
106
105
|
*/
|
|
107
|
-
declare function toPhysicalSchema(db: Kysely<unknown>, expected: ExpectedSchema): ExpectedSchema;
|
|
106
|
+
export declare function toPhysicalSchema(db: Kysely<unknown>, expected: ExpectedSchema): ExpectedSchema;
|
|
108
107
|
/**
|
|
109
108
|
* The default schema for migration tooling. Let PostgreSQL resolve role
|
|
110
109
|
* names and privileges, retaining the legacy public fallback when none exists.
|
|
111
110
|
* Runtime validation uses the effective search path instead of this fallback.
|
|
112
111
|
*/
|
|
113
|
-
declare function getPostgresSchema(db: Kysely<unknown>): Promise<string>;
|
|
114
|
-
declare function getMssqlSchema(db: Kysely<unknown>): Promise<string>;
|
|
112
|
+
export declare function getPostgresSchema(db: Kysely<unknown>): Promise<string>;
|
|
113
|
+
export declare function getMssqlSchema(db: Kysely<unknown>): Promise<string>;
|
|
115
114
|
//#endregion
|
|
116
|
-
export {
|
|
115
|
+
export {};
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as introspectSqliteTables } from "./sqlite-introspector-
|
|
1
|
+
import { n as introspectSqliteTables } from "./sqlite-introspector-_wy6Ac6e.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";
|
|
@@ -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-DN2jcl8c.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-BgJMzZQp.mjs");
|
|
105
105
|
dialect = new D1SqliteDialect({ database: db });
|
|
106
106
|
introspectIndexes = createD1IndexIntrospector(db);
|
|
107
107
|
transaction = false;
|
|
@@ -250,7 +250,11 @@ async function schemaSearchPath(db, dbType) {
|
|
|
250
250
|
*/
|
|
251
251
|
async function findSchemaProblems(db, dbType, expected) {
|
|
252
252
|
const physical = toPhysicalSchema(db, expected);
|
|
253
|
-
if (dbType === "sqlite")
|
|
253
|
+
if (dbType === "sqlite") {
|
|
254
|
+
const tableNames = Object.entries(physical).flatMap(([name, table]) => table.disableMigrations ? [] : [name]);
|
|
255
|
+
const tables = await introspectSqliteTables(db, tableNames);
|
|
256
|
+
return diffSchema(physical, toIntrospectedTables(tables));
|
|
257
|
+
}
|
|
254
258
|
return db.connection().execute(async (connection) => {
|
|
255
259
|
const searchPath = await schemaSearchPath(connection, dbType);
|
|
256
260
|
const tables = toIntrospectedTables(await connection.introspection.getTables());
|
|
@@ -498,7 +502,8 @@ const kyselyAdapter = (db, config) => {
|
|
|
498
502
|
}
|
|
499
503
|
return {
|
|
500
504
|
async create({ data, model, modelKey = model }) {
|
|
501
|
-
|
|
505
|
+
const builder = db.insertInto(model).values(data);
|
|
506
|
+
return await withReturning(data, builder, model, modelKey, []);
|
|
502
507
|
},
|
|
503
508
|
async findOne({ model, modelKey = model, where, select, join }) {
|
|
504
509
|
const { and, or } = convertWhereClause(model, modelKey, where);
|
|
@@ -711,7 +716,8 @@ const kyselyAdapter = (db, config) => {
|
|
|
711
716
|
return (options) => {
|
|
712
717
|
lazyOptions = options;
|
|
713
718
|
const instance = adapter(options);
|
|
714
|
-
|
|
719
|
+
const schemaCheck = createSchemaCheck(() => findSchemaProblems(db, config?.type, getExpectedSchema(options, { usePlural: config?.usePlural })), "database", options.database);
|
|
720
|
+
registerSchemaCheck(instance, schemaCheck, { runtimeEnabled: checksSchema(options) });
|
|
715
721
|
return instance;
|
|
716
722
|
};
|
|
717
723
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { DatabaseConnection, DatabaseIntrospector, Dialect, DialectAdapter, Driver, Kysely, QueryCompiler } from "kysely";
|
|
2
2
|
import { DatabaseSync } from "node:sqlite";
|
|
3
|
-
|
|
4
3
|
//#region src/node-sqlite-dialect.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Config for the SQLite dialect.
|
|
7
6
|
*/
|
|
8
|
-
interface NodeSqliteDialectConfig {
|
|
7
|
+
export interface NodeSqliteDialectConfig {
|
|
9
8
|
/**
|
|
10
9
|
* A sqlite DatabaseSync instance or a function that returns one.
|
|
11
10
|
*/
|
|
@@ -15,7 +14,7 @@ interface NodeSqliteDialectConfig {
|
|
|
15
14
|
*/
|
|
16
15
|
onCreateConnection?: ((connection: DatabaseConnection) => Promise<void>) | undefined;
|
|
17
16
|
}
|
|
18
|
-
declare class NodeSqliteDialect implements Dialect {
|
|
17
|
+
export declare class NodeSqliteDialect implements Dialect {
|
|
19
18
|
#private;
|
|
20
19
|
constructor(config: NodeSqliteDialectConfig);
|
|
21
20
|
createDriver(): Driver;
|
|
@@ -23,5 +22,4 @@ declare class NodeSqliteDialect implements Dialect {
|
|
|
23
22
|
createAdapter(): DialectAdapter;
|
|
24
23
|
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
|
|
25
24
|
}
|
|
26
|
-
//#endregion
|
|
27
|
-
export { NodeSqliteDialect, NodeSqliteDialectConfig };
|
|
25
|
+
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createSqliteIntrospector } from "./sqlite-introspector-
|
|
1
|
+
import { t as createSqliteIntrospector } from "./sqlite-introspector-_wy6Ac6e.mjs";
|
|
2
2
|
import { CompiledQuery, DefaultQueryCompiler } from "kysely";
|
|
3
3
|
//#region src/node-sqlite-dialect.ts
|
|
4
4
|
var NodeSqliteAdapter = class {
|
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.13",
|
|
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 || ^0.5.0",
|
|
44
44
|
"kysely": "^0.28.17 || ^0.29.0",
|
|
45
|
-
"@better-auth/core": "^1.7.
|
|
45
|
+
"@better-auth/core": "^1.7.13"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"kysely": {
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@better-auth/utils": "0.5.
|
|
53
|
+
"@better-auth/utils": "0.5.1",
|
|
54
54
|
"@cloudflare/workers-types": "^4.20250121.0",
|
|
55
55
|
"@types/pg": "^8.20.0",
|
|
56
56
|
"kysely": "^0.28.17 || ^0.29.0",
|
|
57
57
|
"pg": "^8.0.0",
|
|
58
|
-
"tsdown": "0.
|
|
58
|
+
"tsdown": "0.23.1",
|
|
59
59
|
"typescript": "^6.0.3",
|
|
60
|
-
"@better-auth/core": "1.7.
|
|
60
|
+
"@better-auth/core": "1.7.13"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|
|
File without changes
|