@authhero/kysely-adapter 12.7.0 → 12.8.0
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/kysely-adapter.cjs +1 -1
- package/dist/kysely-adapter.mjs +1095 -976
- package/dist/types/src/cleanup.d.ts +20 -0
- package/dist/types/src/helpers/database-type.d.ts +15 -0
- package/dist/types/src/users/createMany.d.ts +4 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Kysely } from "kysely";
|
|
2
2
|
import { Database } from "./db";
|
|
3
3
|
import { SessionCleanupParams } from "@authhero/adapter-interfaces";
|
|
4
|
+
export declare const MAX_BATCHES = 300;
|
|
4
5
|
/**
|
|
5
6
|
* Create a scoped session cleanup function that can filter by tenant and/or user.
|
|
6
7
|
* This is designed for lazy cleanup after login session creation.
|
|
@@ -12,5 +13,24 @@ import { SessionCleanupParams } from "@authhero/adapter-interfaces";
|
|
|
12
13
|
* independently without expensive subqueries to check for active children.
|
|
13
14
|
*
|
|
14
15
|
* Records are deleted only after they have been expired for the grace period (1 week).
|
|
16
|
+
*
|
|
17
|
+
* The tables are swept round-robin rather than one after another: draining them
|
|
18
|
+
* in a fixed order lets a backlog in the first table consume the whole batch
|
|
19
|
+
* budget, which is how login_sessions went unswept for months while
|
|
20
|
+
* refresh_tokens stayed clean. A sweep that throws — a PlanetScale statement
|
|
21
|
+
* timeout, say — is marked failed and skipped, but does not abort the others;
|
|
22
|
+
* one unhealthy table must not starve the rest.
|
|
23
|
+
*
|
|
24
|
+
* refresh_tokens and sessions expire on either of two columns, and each gets
|
|
25
|
+
* its own statement rather than one `OR`: MySQL declines to index_merge across
|
|
26
|
+
* OR'd predicates and falls back to a full scan, which on a production-sized
|
|
27
|
+
* table exceeds PlanetScale's 20s statement timeout and deletes nothing. Split,
|
|
28
|
+
* every statement is a clean single-column index range. This is the same
|
|
29
|
+
* reasoning — and the same fix — as codes/cleanup.ts.
|
|
30
|
+
*
|
|
31
|
+
* login_sessions is swept first because login_sessions_session_fk is
|
|
32
|
+
* ON DELETE CASCADE: every sessions row deleted cascade-deletes its
|
|
33
|
+
* login_sessions children, so draining the child table first makes the
|
|
34
|
+
* subsequent sessions batches far cheaper.
|
|
15
35
|
*/
|
|
16
36
|
export declare function createSessionCleanup(db: Kysely<Database>): (params?: SessionCleanupParams) => Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Kysely } from "kysely";
|
|
2
|
+
import { Database } from "../db";
|
|
3
|
+
export type DatabaseType = "mysql" | "sqlite";
|
|
4
|
+
/**
|
|
5
|
+
* Probe which engine the adapter is talking to.
|
|
6
|
+
*
|
|
7
|
+
* `VERSION()` exists on MySQL and not on SQLite, so a thrown statement is the
|
|
8
|
+
* signal. Callers should memoize the result per adapter instance — the answer
|
|
9
|
+
* cannot change for a given `Kysely` connection.
|
|
10
|
+
*
|
|
11
|
+
* This matters for chunked deletes: `DELETE ... LIMIT` requires SQLite to be
|
|
12
|
+
* built with `SQLITE_ENABLE_UPDATE_DELETE_LIMIT`, which is not the default, so
|
|
13
|
+
* SQLite deployments take the unchunked path instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getDatabaseType(db: Kysely<Database>): Promise<DatabaseType>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Kysely } from "kysely";
|
|
2
|
+
import { Database } from "../db";
|
|
3
|
+
import { User, UserInsert, WriteOptions } from "@authhero/adapter-interfaces";
|
|
4
|
+
export declare function createMany(db: Kysely<Database>): (tenantId: string, users: UserInsert[], options?: WriteOptions) => Promise<User[]>;
|