@better-auth/kysely-adapter 1.7.21 → 1.7.23
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 +0 -8
- package/dist/index.mjs +28 -15
- 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
|
*/
|
|
@@ -120,5 +113,4 @@ export declare function getMssqlSchema(db: Kysely<unknown>): Promise<string>;
|
|
|
120
113
|
export declare function introspectPostgresTables(db: Kysely<unknown>, schemas: readonly string[]): Promise<(TableMetadata & {
|
|
121
114
|
isForeign: boolean;
|
|
122
115
|
})[]>;
|
|
123
|
-
//#endregion
|
|
124
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
|
*/
|
|
@@ -319,8 +317,7 @@ async function findSchemaProblems(db, dbType, expected) {
|
|
|
319
317
|
return diffSchema(physical, tables);
|
|
320
318
|
});
|
|
321
319
|
}
|
|
322
|
-
|
|
323
|
-
//#region src/kysely-adapter.ts
|
|
320
|
+
// src/kysely-adapter.ts
|
|
324
321
|
const kyselyAdapter = (db, config) => {
|
|
325
322
|
let lazyOptions = null;
|
|
326
323
|
let mysqlNoIdWarned = false;
|
|
@@ -352,6 +349,23 @@ const kyselyAdapter = (db, config) => {
|
|
|
352
349
|
allSelects
|
|
353
350
|
};
|
|
354
351
|
};
|
|
352
|
+
const encodeJSONArrays = (modelKey, values) => {
|
|
353
|
+
if (config?.type !== "postgres") return values;
|
|
354
|
+
const fields = schema[getDefaultModelName(modelKey)]?.fields;
|
|
355
|
+
if (!fields) return values;
|
|
356
|
+
let encoded;
|
|
357
|
+
for (const [field, attributes] of Object.entries(fields)) {
|
|
358
|
+
if (attributes.type !== "json") continue;
|
|
359
|
+
const column = getFieldName({
|
|
360
|
+
model: modelKey,
|
|
361
|
+
field
|
|
362
|
+
});
|
|
363
|
+
if (!Array.isArray(values[column])) continue;
|
|
364
|
+
encoded ??= { ...values };
|
|
365
|
+
encoded[column] = JSON.stringify(values[column]);
|
|
366
|
+
}
|
|
367
|
+
return encoded ?? values;
|
|
368
|
+
};
|
|
355
369
|
const withReturning = async (values, builder, model, modelKey, where) => {
|
|
356
370
|
if (config?.type === "mysql") {
|
|
357
371
|
if (where.length > 0) {
|
|
@@ -556,7 +570,7 @@ const kyselyAdapter = (db, config) => {
|
|
|
556
570
|
}
|
|
557
571
|
return {
|
|
558
572
|
async create({ data, model, modelKey = model }) {
|
|
559
|
-
const builder = db.insertInto(model).values(data);
|
|
573
|
+
const builder = db.insertInto(model).values(encodeJSONArrays(modelKey, data));
|
|
560
574
|
return await withReturning(data, builder, model, modelKey, []);
|
|
561
575
|
},
|
|
562
576
|
async findOne({ model, modelKey = model, where, select, join }) {
|
|
@@ -631,14 +645,14 @@ const kyselyAdapter = (db, config) => {
|
|
|
631
645
|
async update({ model, modelKey = model, where, update: values }) {
|
|
632
646
|
if (where.length === 0) return null;
|
|
633
647
|
const { and, or } = convertWhereClause(model, modelKey, where);
|
|
634
|
-
let query = db.updateTable(model).set(values);
|
|
648
|
+
let query = db.updateTable(model).set(encodeJSONArrays(modelKey, values));
|
|
635
649
|
if (and) query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
|
|
636
650
|
if (or) query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
|
|
637
651
|
return await withReturning(values, query, model, modelKey, where);
|
|
638
652
|
},
|
|
639
653
|
async updateMany({ model, modelKey = model, where, update: values }) {
|
|
640
654
|
const { and, or } = convertWhereClause(model, modelKey, where);
|
|
641
|
-
let query = db.updateTable(model).set(values);
|
|
655
|
+
let query = db.updateTable(model).set(encodeJSONArrays(modelKey, values));
|
|
642
656
|
if (and) query = query.where((eb) => eb.and(and.map((expr) => expr(eb))));
|
|
643
657
|
if (or) query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
|
|
644
658
|
const res = (await query.executeTakeFirst()).numUpdatedRows;
|
|
@@ -714,7 +728,7 @@ const kyselyAdapter = (db, config) => {
|
|
|
714
728
|
if (or) query = query.where((eb) => eb.or(or.map((expr) => expr(eb))));
|
|
715
729
|
return query;
|
|
716
730
|
};
|
|
717
|
-
const assignments = { ...set ?? {} };
|
|
731
|
+
const assignments = { ...encodeJSONArrays(modelKey, set ?? {}) };
|
|
718
732
|
for (const [field, delta] of Object.entries(increment)) assignments[field] = sql`${sql.ref(field)} + ${delta}`;
|
|
719
733
|
const idField = getFieldName({
|
|
720
734
|
model: modelKey,
|
|
@@ -775,5 +789,4 @@ const kyselyAdapter = (db, config) => {
|
|
|
775
789
|
return instance;
|
|
776
790
|
};
|
|
777
791
|
};
|
|
778
|
-
//#endregion
|
|
779
792
|
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.23",
|
|
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.23",
|
|
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.21"
|
|
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.23",
|
|
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.21"
|
|
60
|
+
"typescript": "^6.0.3"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsdown",
|