@nxgt/janus-drizzle 0.8.1 → 0.9.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/README.md +14 -7
- package/dist/index.js +24 -13
- package/dist/index.js.map +7 -6
- package/dist/stores/count-deleted.d.ts +10 -0
- package/dist/stores/count-deleted.d.ts.map +1 -0
- package/dist/stores/sessions.d.ts.map +1 -1
- package/dist/stores/tokens.d.ts.map +1 -1
- package/dist/tables/tokens.d.ts.map +1 -1
- package/docs/README.md +1 -1
- package/docs/guide/migrations.md +50 -8
- package/docs/guide/wiring.md +2 -2
- package/docs/roadmap.md +6 -0
- package/docs/troubleshooting.md +8 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -85,7 +85,7 @@ declarations import without extensions, so `nodenext` is not supported.
|
|
|
85
85
|
| --- | --- |
|
|
86
86
|
| `createDrizzleAdapter(db, options?)` | Returns `{ store, relations }`, both of the entries below, keyed as `janus()` takes them, so `janus({ …, ...postgres })` wires both. It connects to nothing and creates nothing. `options.tables` is what your schema file's `defineJanusTables(…)` returned. |
|
|
87
87
|
| `DrizzleAdapter` | The type of what `createDrizzleAdapter` returns. |
|
|
88
|
-
| `createDrizzleStores(db, options?)` | The `{ users, sessions, tokens }` that `janus()` takes as `store`. Implements
|
|
88
|
+
| `createDrizzleStores(db, options?)` | The `{ users, sessions, tokens }` that `janus()` takes as `store`. Implements all three optional methods: `sessions.deleteExpiredSessions`, `tokens.deleteExpiredTokens` and `users.findUsers`, so `auth.<type>.findMany(ids)` is one `inArray` statement. |
|
|
89
89
|
| `createDrizzleRelations(db, options?)` | The `RelationStore` that `permissions()` takes as `store`, and `janus()` takes as `relations`. |
|
|
90
90
|
| `defineJanusTables(options?)` | The five tables, `{ users, logins, sessions, tokens, relations }`, as Drizzle tables. Export each from a schema file so your migrations create them. |
|
|
91
91
|
| `JanusTablesOptions` | `{ schema? }`: a `pgSchema(…)` to put the tables in. Absent, they are in the connection's `search_path`, `public` by default. |
|
|
@@ -108,7 +108,7 @@ tables.
|
|
|
108
108
|
| `users` | `id` · `(id, type)` unique, for the logins' foreign key · `(type, id)` for listing · a check that a password has both its hash and its date, or neither · a check that a second factor (`second_factor_method`, `_secret`, `_confirmed_at`, `_last_step`, `_recovery_codes`) has its method and its secret, or none of the five · a check that the method is `totp` and the last step not negative |
|
|
109
109
|
| `logins` | primary key `(type, login)`: **a login is unique per user type** · `(user_id, type)` references the user, `on delete cascade` |
|
|
110
110
|
| `sessions` | `id` · `token_hash` unique · `user_id` · `expires_at`, for `collectExpired()` |
|
|
111
|
-
| `tokens` | `token_hash` · `user_id` · a check on `kind` · `code_hash`, and `attempts`, `not null default 0`, checked `>= 0` |
|
|
111
|
+
| `tokens` | `token_hash` · `user_id` · `expires_at`, for `collectExpired()` · a check on `kind` · `code_hash`, and `attempts`, `not null default 0`, checked `>= 0` |
|
|
112
112
|
| `relations` | one row per tuple, unique `nulls not distinct` over all six columns, subject first: the index `findObjects` pages · `(object_type, object_id, relation)` for one hop forwards |
|
|
113
113
|
|
|
114
114
|
`logins` is also a `text[]` on `users`, which the store reads back in order.
|
|
@@ -174,11 +174,18 @@ a code, in the order written; no codes are `null`, read as `[]`.
|
|
|
174
174
|
`createDrizzleAdapter(db, { tables: janusTables })`, with the object your
|
|
175
175
|
schema file exports.
|
|
176
176
|
- **Call `auth.collectExpired()` on a schedule.** PostgreSQL has no TTL, so
|
|
177
|
-
lapsed sessions stay in `sessions`
|
|
178
|
-
core still refuses them on every read.
|
|
179
|
-
`collectExpired()`
|
|
180
|
-
adds a row per login tried and per
|
|
181
|
-
|
|
177
|
+
lapsed sessions stay in `sessions` and lapsed tokens in `tokens` until
|
|
178
|
+
something deletes them. The core still refuses them on every read.
|
|
179
|
+
`collectExpired()` deletes both and answers how many in all. The tokens
|
|
180
|
+
matter: `@nxgt/janus`'s sign-in throttle adds a row per login tried and per
|
|
181
|
+
15-minute window — a login nobody holds included — and its mail throttle
|
|
182
|
+
one per flow, address or user and window. The first run after an upgrade
|
|
183
|
+
deletes the whole backlog in one statement, so run it off-peak.
|
|
184
|
+
- **Upgrading to 0.9 recommends a migration.** `tokens` gains an index on
|
|
185
|
+
`expires_at`, one `CREATE INDEX`. Without it the delete scans the table.
|
|
186
|
+
Drop a hand-made `tokens (expires_at)` index first, or the column keeps two.
|
|
187
|
+
[To 0.9](docs/guide/migrations.md#to-09-an-index-on-tokensexpires_at) shows
|
|
188
|
+
the statement.
|
|
182
189
|
- **A unique violation on anything but a login is a `StoreFailure`, not
|
|
183
190
|
`LOGIN_TAKEN`.** Such a violation is an adapter bug. Reporting it as a taken
|
|
184
191
|
login would tell somebody their e-mail is in use when it is not.
|
package/dist/index.js
CHANGED
|
@@ -89,7 +89,8 @@ function tokensTable(table) {
|
|
|
89
89
|
}, (t) => [
|
|
90
90
|
check("tokens_kind", sql`${t.kind} in ('verifyEmail', 'resetPassword', 'secondFactor', 'signInCode', 'magicLink', 'stepUp', 'changeEmail')`),
|
|
91
91
|
check("tokens_attempts", sql`${t.attempts} >= 0`),
|
|
92
|
-
index4("tokens_user_id").on(t.userId)
|
|
92
|
+
index4("tokens_user_id").on(t.userId),
|
|
93
|
+
index4("tokens_expires_at").on(t.expiresAt)
|
|
93
94
|
]);
|
|
94
95
|
}
|
|
95
96
|
|
|
@@ -277,10 +278,18 @@ function createDrizzleRelations(db, options = {}) {
|
|
|
277
278
|
}
|
|
278
279
|
|
|
279
280
|
// src/stores/sessions.ts
|
|
280
|
-
import { and as and4, eq as eq4, isNull as isNull3, lte, ne, sql as
|
|
281
|
+
import { and as and4, eq as eq4, isNull as isNull3, lte, ne, sql as sql5 } from "drizzle-orm";
|
|
282
|
+
|
|
283
|
+
// src/stores/count-deleted.ts
|
|
284
|
+
import { count, sql as sql3 } from "drizzle-orm";
|
|
285
|
+
async function deleteAndCount(db, table, where) {
|
|
286
|
+
const deleted = db.$with("deleted").as(db.delete(table).where(where).returning({ one: sql3`1`.as("one") }));
|
|
287
|
+
const [row] = await db.with(deleted).select({ n: count() }).from(deleted);
|
|
288
|
+
return row?.n ?? 0;
|
|
289
|
+
}
|
|
281
290
|
|
|
282
291
|
// src/stores/records.ts
|
|
283
|
-
import { sql as
|
|
292
|
+
import { sql as sql4 } from "drizzle-orm";
|
|
284
293
|
function toUserRow(record) {
|
|
285
294
|
return {
|
|
286
295
|
id: record.id,
|
|
@@ -365,7 +374,7 @@ function toSession(row) {
|
|
|
365
374
|
};
|
|
366
375
|
}
|
|
367
376
|
function stamp(at) {
|
|
368
|
-
return
|
|
377
|
+
return sql4`${at.toISOString()}::timestamptz`;
|
|
369
378
|
}
|
|
370
379
|
|
|
371
380
|
// src/stores/sessions.ts
|
|
@@ -391,8 +400,7 @@ function sessionStore(db, tables) {
|
|
|
391
400
|
return deleted.length;
|
|
392
401
|
}),
|
|
393
402
|
deleteExpiredSessions: (before) => run$("deleteExpiredSessions", async () => {
|
|
394
|
-
|
|
395
|
-
return deleted.length;
|
|
403
|
+
return deleteAndCount(db, tables.sessions, lte(tables.sessions.expiresAt, before));
|
|
396
404
|
})
|
|
397
405
|
};
|
|
398
406
|
}
|
|
@@ -402,7 +410,7 @@ async function reauthenticateSession(db, tables, id, at) {
|
|
|
402
410
|
}
|
|
403
411
|
async function revokeSession(db, tables, id, at) {
|
|
404
412
|
const matched = await db.update(tables.sessions).set({
|
|
405
|
-
revokedAt:
|
|
413
|
+
revokedAt: sql5`coalesce(${tables.sessions.revokedAt}, ${stamp(at)})`
|
|
406
414
|
}).where(eq4(tables.sessions.id, id)).returning({ id: tables.sessions.id });
|
|
407
415
|
return matched.length === 1;
|
|
408
416
|
}
|
|
@@ -413,7 +421,7 @@ async function revokeUserSessions(db, tables, userId, at, except) {
|
|
|
413
421
|
}
|
|
414
422
|
|
|
415
423
|
// src/stores/tokens.ts
|
|
416
|
-
import { and as and5, eq as eq5, isNull as isNull4, ne as ne2, sql as
|
|
424
|
+
import { and as and5, eq as eq5, isNull as isNull4, lte as lte2, ne as ne2, sql as sql6 } from "drizzle-orm";
|
|
417
425
|
function tokenStore(db, tables) {
|
|
418
426
|
const run$ = (operation, body) => run("tokens", operation, body);
|
|
419
427
|
return {
|
|
@@ -429,13 +437,16 @@ function tokenStore(db, tables) {
|
|
|
429
437
|
deleteUserTokens: (userId) => run$("deleteUserTokens", async () => {
|
|
430
438
|
const deleted = await db.delete(tables.tokens).where(eq5(tables.tokens.userId, userId)).returning({ tokenHash: tables.tokens.tokenHash });
|
|
431
439
|
return deleted.length;
|
|
440
|
+
}),
|
|
441
|
+
deleteExpiredTokens: (before) => run$("deleteExpiredTokens", async () => {
|
|
442
|
+
return deleteAndCount(db, tables.tokens, lte2(tables.tokens.expiresAt, before));
|
|
432
443
|
})
|
|
433
444
|
};
|
|
434
445
|
}
|
|
435
446
|
async function consumeToken(db, tables, tokenHash, kind, at) {
|
|
436
447
|
const before = db.$with("before").as(db.select().from(tables.tokens).where(and5(eq5(tables.tokens.tokenHash, tokenHash), eq5(tables.tokens.kind, kind))).for("update"));
|
|
437
448
|
const [spent] = await db.with(before).update(tables.tokens).set({
|
|
438
|
-
spentAt:
|
|
449
|
+
spentAt: sql6`coalesce(${tables.tokens.spentAt}, ${stamp(at)})`
|
|
439
450
|
}).from(before).where(eq5(tables.tokens.tokenHash, before.tokenHash)).returning({
|
|
440
451
|
tokenHash: before.tokenHash,
|
|
441
452
|
kind: before.kind,
|
|
@@ -451,7 +462,7 @@ async function consumeToken(db, tables, tokenHash, kind, at) {
|
|
|
451
462
|
}
|
|
452
463
|
async function countAttempt(db, tables, tokenHash, kind) {
|
|
453
464
|
const match = and5(eq5(tables.tokens.tokenHash, tokenHash), eq5(tables.tokens.kind, kind));
|
|
454
|
-
const [counted] = await db.update(tables.tokens).set({ attempts:
|
|
465
|
+
const [counted] = await db.update(tables.tokens).set({ attempts: sql6`${tables.tokens.attempts} + 1` }).where(and5(match, isNull4(tables.tokens.spentAt))).returning();
|
|
455
466
|
const row = counted ?? (await db.select().from(tables.tokens).where(match))[0];
|
|
456
467
|
return row === undefined ? null : { ...row, userId: row.userId };
|
|
457
468
|
}
|
|
@@ -459,7 +470,7 @@ async function countAttempt(db, tables, tokenHash, kind) {
|
|
|
459
470
|
// src/stores/users.ts
|
|
460
471
|
import { withTransaction as withTransaction2 } from "@nxgt/drizzle/pg";
|
|
461
472
|
import { NotFoundError, StoreConflict as StoreConflict2 } from "@nxgt/janus";
|
|
462
|
-
import { and as and6, asc as asc2, eq as eq6, gt as gt2, inArray, sql as
|
|
473
|
+
import { and as and6, asc as asc2, eq as eq6, gt as gt2, inArray, sql as sql7 } from "drizzle-orm";
|
|
463
474
|
|
|
464
475
|
// src/stores/logins.ts
|
|
465
476
|
async function claimLogins(tx, tables, operation, user, logins) {
|
|
@@ -529,7 +540,7 @@ async function insertUser(db, tables, record) {
|
|
|
529
540
|
async function updateUser(tx, tables, id, patch, ifVersion) {
|
|
530
541
|
const [row] = await tx.update(tables.users).set({
|
|
531
542
|
...toUserSet(patch),
|
|
532
|
-
version:
|
|
543
|
+
version: sql7`${tables.users.version} + 1`
|
|
533
544
|
}).where(and6(eq6(tables.users.id, id), eq6(tables.users.version, ifVersion))).returning();
|
|
534
545
|
if (row === undefined) {
|
|
535
546
|
const [stored] = await tx.select({ version: tables.users.version }).from(tables.users).where(eq6(tables.users.id, id));
|
|
@@ -577,5 +588,5 @@ export {
|
|
|
577
588
|
defineJanusTables
|
|
578
589
|
};
|
|
579
590
|
|
|
580
|
-
//# debugId=
|
|
591
|
+
//# debugId=4769BF1300BE303164756E2164756E21
|
|
581
592
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/tables/index.ts", "../src/tables/logins.ts", "../src/tables/columns.ts", "../src/tables/relations.ts", "../src/tables/sessions.ts", "../src/tables/tokens.ts", "../src/tables/users.ts", "../src/translate.ts", "../src/relations/reads.ts", "../src/relations/tuples.ts", "../src/relations/writes.ts", "../src/relations/index.ts", "../src/stores/sessions.ts", "../src/stores/records.ts", "../src/stores/tokens.ts", "../src/stores/users.ts", "../src/stores/logins.ts", "../src/stores/index.ts", "../src/adapter.ts"],
|
|
3
|
+
"sources": ["../src/tables/index.ts", "../src/tables/logins.ts", "../src/tables/columns.ts", "../src/tables/relations.ts", "../src/tables/sessions.ts", "../src/tables/tokens.ts", "../src/tables/users.ts", "../src/translate.ts", "../src/relations/reads.ts", "../src/relations/tuples.ts", "../src/relations/writes.ts", "../src/relations/index.ts", "../src/stores/sessions.ts", "../src/stores/count-deleted.ts", "../src/stores/records.ts", "../src/stores/tokens.ts", "../src/stores/users.ts", "../src/stores/logins.ts", "../src/stores/index.ts", "../src/adapter.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { type PgSchema, pgTable } from 'drizzle-orm/pg-core';\nimport type { TableFactory } from './columns';\nimport { loginsTable } from './logins';\nimport { relationsTable } from './relations';\nimport { sessionsTable } from './sessions';\nimport { tokensTable } from './tokens';\nimport { usersTable } from './users';\n\n/**\n * The five tables, as Drizzle definitions: **your migrations create them**.\n * Export them from the schema file drizzle-kit reads, and `drizzle-kit\n * generate` writes them into your next migration like any table of your own.\n *\n * **The names carry no prefix** — `users`, `logins`, `sessions`, `tokens`,\n * `relations` — because the setup this package recommends is **a database of\n * its own**, backed up and restored on its own. Beside an application's own\n * tables, give them a PostgreSQL schema instead: `{ schema: pgSchema('janus') }`\n * makes them `janus.users` and the rest, and `pg_dump -n janus` backs them up\n * alone.\n *\n * Columns are `snake_case`, as PostgreSQL's own catalog and `@nxgt/drizzle`'s\n * columns are: a camelCase column would have to be quoted in every query\n * written by hand. The records the stores answer are camelCase, as everywhere\n * in Janus.\n *\n * **What the tables hold is the port's record**, field by field. Nothing is\n * encoded, so a row read in `psql` reads like the record in the code.\n */\n\n/** Where the tables live. */\nexport interface JanusTablesOptions {\n\t/**\n\t * A PostgreSQL schema of their own, `pgSchema('janus')`, for a database the\n\t * application's tables share. **Export it from the schema file too**:\n\t * drizzle-kit writes `CREATE SCHEMA` only for a schema it finds exported.\n\t * Absent, the tables are in the connection's `search_path`, `public` by\n\t * default: the database of their own.\n\t */\n\treadonly schema?: PgSchema;\n}\n\n/**\n * The five tables, in the schema `options` names, or in none.\n *\n * ```ts\n * // src/janus/schema.ts — the schema file of Janus's own drizzle-kit config\n * export const { users, logins, sessions, tokens, relations } = defineJanusTables();\n *\n * // or, in a database the application's tables share\n * export const janus = pgSchema('janus');\n * export const { users, logins, sessions, tokens, relations } = defineJanusTables({ schema: janus });\n * ```\n *\n * Pass what the schema file exports to `createDrizzleAdapter` as `{ tables }`,\n * so the stores query the very tables your migration created.\n */\nexport function defineJanusTables(options: JanusTablesOptions = {}) {\n\tconst { schema } = options;\n\tconst table = (schema === undefined ? pgTable : schema.table) as TableFactory;\n\tconst users = usersTable(table);\n\tconst logins = loginsTable(table, users);\n\tconst sessions = sessionsTable(table);\n\tconst tokens = tokensTable(table);\n\tconst relations = relationsTable(table);\n\treturn { users, logins, sessions, tokens, relations };\n}\n\n/** The five tables `defineJanusTables` answers. */\nexport type JanusTables = ReturnType<typeof defineJanusTables>;\n\n/**\n * Which tables the stores query: **the ones your schema file exports**, so\n * the migration and the stores cannot disagree. Absent, `defineJanusTables()`:\n * the tables in the connection's `search_path`.\n *\n * ```ts\n * // src/db/schema.ts\n * export const janus = pgSchema('janus');\n * export const janusTables = defineJanusTables({ schema: janus });\n * export const { users, logins, sessions, tokens, relations } = janusTables;\n *\n * // where the adapter is wired\n * const postgres = createDrizzleAdapter(db, { tables: janusTables });\n * ```\n */\nexport interface DrizzleAdapterOptions<\n\tK extends keyof JanusTables = keyof JanusTables,\n> {\n\treadonly tables?: Pick<JanusTables, K>;\n}\n",
|
|
6
6
|
"import { foreignKey, index, primaryKey } from 'drizzle-orm/pg-core';\nimport { key, type TableFactory } from './columns';\nimport type { usersTable } from './users';\n\n/**\n * **The uniqueness of a login, per type** (rule 3): one row per login a\n * user holds, and the primary key refuses a second holder. PostgreSQL has\n * no unique index over the elements of an array, so this table is that\n * index, written in the same transaction as the user. Deleting the user\n * deletes its rows.\n */\nexport function loginsTable(\n\ttable: TableFactory,\n\tusers: ReturnType<typeof usersTable>,\n) {\n\treturn table(\n\t\t'logins',\n\t\t{\n\t\t\ttype: key('type').notNull(),\n\t\t\tlogin: key('login').notNull(),\n\t\t\tuserId: key('user_id').notNull(),\n\t\t},\n\t\t(t) => [\n\t\t\tprimaryKey({ name: 'logins_pkey', columns: [t.type, t.login] }),\n\t\t\tforeignKey({\n\t\t\t\tname: 'logins_user_fk',\n\t\t\t\tcolumns: [t.userId, t.type],\n\t\t\t\tforeignColumns: [users.id, users.type],\n\t\t\t}).onDelete('cascade'),\n\t\t\tindex('logins_user_id').on(t.userId),\n\t\t],\n\t);\n}\n",
|
|
7
7
|
"// The building blocks every table is made of: the table factory's type and\n// the column kinds the five tables share.\nimport { customType, type pgTable, timestamp } from 'drizzle-orm/pg-core';\n\n/** `pgTable`, or the `table` of the schema the tables live in. */\nexport type TableFactory = typeof pgTable;\n\n/**\n * A key compared byte by byte, as the port asks (rule 4): `collate \"C\"`. Under\n * a database's default collation, `en_US.UTF-8` or the like, `B` sorts after\n * `a` — and a page in \"ascending id order\" repeats or skips rows.\n */\nexport const key = customType<{ data: string; driverData: string }>({\n\tdataType: () => 'text collate \"C\"',\n});\n\n// Millisecond precision: a JavaScript `Date` has no more. At PostgreSQL's\n// default of microseconds, a timestamp written and read back is not the one\n// the core wrote.\nexport const at = (name: string) =>\n\ttimestamp(name, { withTimezone: true, precision: 3 });\n",
|
|
8
8
|
"import { index, unique } from 'drizzle-orm/pg-core';\nimport { key, type TableFactory } from './columns';\n\n/**\n * Permission tuples, one row each: `record:r1#owners@patient:u1`, or\n * `…@team:t1#members` for a subject set, whose `subject_relation` an\n * entity's row leaves `null`.\n *\n * **The uniqueness of a tuple is the unique constraint**, `nulls not\n * distinct` so two rows for one entity collide — PostgreSQL 15 or later.\n * Its column order is the reverse index `findObjects` pages: every equality\n * first, the object id last.\n */\nexport function relationsTable(table: TableFactory) {\n\treturn table(\n\t\t'relations',\n\t\t{\n\t\t\tobjectType: key('object_type').notNull(),\n\t\t\tobjectId: key('object_id').notNull(),\n\t\t\trelation: key('relation').notNull(),\n\t\t\tsubjectType: key('subject_type').notNull(),\n\t\t\tsubjectId: key('subject_id').notNull(),\n\t\t\tsubjectRelation: key('subject_relation'),\n\t\t},\n\t\t(t) => [\n\t\t\tunique('relations_tuple_unique')\n\t\t\t\t.on(\n\t\t\t\t\tt.subjectType,\n\t\t\t\t\tt.subjectId,\n\t\t\t\t\tt.subjectRelation,\n\t\t\t\t\tt.relation,\n\t\t\t\t\tt.objectType,\n\t\t\t\t\tt.objectId,\n\t\t\t\t)\n\t\t\t\t.nullsNotDistinct(),\n\t\t\t/** One hop forwards: `findSubjectSets`, `findEntities`, `deleteEntity` as the object. */\n\t\t\tindex('relations_object').on(t.objectType, t.objectId, t.relation),\n\t\t],\n\t);\n}\n",
|
|
9
9
|
"import { index, unique } from 'drizzle-orm/pg-core';\nimport { at, key, type TableFactory } from './columns';\n\n/**\n * Sessions. No foreign key to the user: deleting a user deletes the user,\n * and the core deletes the sessions next — as it does when they live\n * elsewhere, in Redis.\n */\nexport function sessionsTable(table: TableFactory) {\n\treturn table(\n\t\t'sessions',\n\t\t{\n\t\t\tid: key('id').primaryKey(),\n\t\t\t/** `sha256` of the session token. The secret itself is never stored. */\n\t\t\ttokenHash: key('token_hash').notNull(),\n\t\t\tuserId: key('user_id').notNull(),\n\t\t\tauthenticatedAt: at('authenticated_at').notNull(),\n\t\t\texpiresAt: at('expires_at').notNull(),\n\t\t\trevokedAt: at('revoked_at'),\n\t\t\tcreatedAt: at('created_at').notNull(),\n\t\t},\n\t\t(t) => [\n\t\t\tunique('sessions_token_hash_unique').on(t.tokenHash),\n\t\t\tindex('sessions_user_id').on(t.userId),\n\t\t\t/** `deleteExpiredSessions`: PostgreSQL has no TTL, so the core collects. */\n\t\t\tindex('sessions_expires_at').on(t.expiresAt),\n\t\t],\n\t);\n}\n",
|
|
10
|
-
"import { sql } from 'drizzle-orm';\nimport { check, index, integer, text } from 'drizzle-orm/pg-core';\nimport { at, key, type TableFactory } from './columns';\n\n/** One-time tokens, keyed by their hash. */\nexport function tokensTable(table: TableFactory) {\n\treturn table(\n\t\t'tokens',\n\t\t{\n\t\t\ttokenHash: key('token_hash').primaryKey(),\n\t\t\tkind: text('kind', {\n\t\t\t\tenum: [\n\t\t\t\t\t'verifyEmail',\n\t\t\t\t\t'resetPassword',\n\t\t\t\t\t'secondFactor',\n\t\t\t\t\t'signInCode',\n\t\t\t\t\t'magicLink',\n\t\t\t\t\t'stepUp',\n\t\t\t\t\t'changeEmail',\n\t\t\t\t],\n\t\t\t}).notNull(),\n\t\t\tuserId: key('user_id').notNull(),\n\t\t\taddress: text('address').notNull(),\n\t\t\t/**\n\t\t\t * An e-mailed code's hash, keyed by the token's secret — for a\n\t\t\t * `changeEmail` token, the address it replaces, keyed the same way.\n\t\t\t */\n\t\t\tcodeHash: text('code_hash'),\n\t\t\t/** Codes tried against it. The default fills the rows a migration finds. */\n\t\t\tattempts: integer('attempts').notNull().default(0),\n\t\t\texpiresAt: at('expires_at').notNull(),\n\t\t\tspentAt: at('spent_at'),\n\t\t\tcreatedAt: at('created_at').notNull(),\n\t\t},\n\t\t(t) => [\n\t\t\tcheck(\n\t\t\t\t'tokens_kind',\n\t\t\t\tsql`${t.kind} in ('verifyEmail', 'resetPassword', 'secondFactor', 'signInCode', 'magicLink', 'stepUp', 'changeEmail')`,\n\t\t\t),\n\t\t\tcheck('tokens_attempts', sql`${t.attempts} >= 0`),\n\t\t\tindex('tokens_user_id').on(t.userId),\n\t\t],\n\t);\n}\n",
|
|
10
|
+
"import { sql } from 'drizzle-orm';\nimport { check, index, integer, text } from 'drizzle-orm/pg-core';\nimport { at, key, type TableFactory } from './columns';\n\n/** One-time tokens, keyed by their hash. */\nexport function tokensTable(table: TableFactory) {\n\treturn table(\n\t\t'tokens',\n\t\t{\n\t\t\ttokenHash: key('token_hash').primaryKey(),\n\t\t\tkind: text('kind', {\n\t\t\t\tenum: [\n\t\t\t\t\t'verifyEmail',\n\t\t\t\t\t'resetPassword',\n\t\t\t\t\t'secondFactor',\n\t\t\t\t\t'signInCode',\n\t\t\t\t\t'magicLink',\n\t\t\t\t\t'stepUp',\n\t\t\t\t\t'changeEmail',\n\t\t\t\t],\n\t\t\t}).notNull(),\n\t\t\tuserId: key('user_id').notNull(),\n\t\t\taddress: text('address').notNull(),\n\t\t\t/**\n\t\t\t * An e-mailed code's hash, keyed by the token's secret — for a\n\t\t\t * `changeEmail` token, the address it replaces, keyed the same way.\n\t\t\t */\n\t\t\tcodeHash: text('code_hash'),\n\t\t\t/** Codes tried against it. The default fills the rows a migration finds. */\n\t\t\tattempts: integer('attempts').notNull().default(0),\n\t\t\texpiresAt: at('expires_at').notNull(),\n\t\t\tspentAt: at('spent_at'),\n\t\t\tcreatedAt: at('created_at').notNull(),\n\t\t},\n\t\t(t) => [\n\t\t\tcheck(\n\t\t\t\t'tokens_kind',\n\t\t\t\tsql`${t.kind} in ('verifyEmail', 'resetPassword', 'secondFactor', 'signInCode', 'magicLink', 'stepUp', 'changeEmail')`,\n\t\t\t),\n\t\t\tcheck('tokens_attempts', sql`${t.attempts} >= 0`),\n\t\t\tindex('tokens_user_id').on(t.userId),\n\t\t\t/** `deleteExpiredTokens`: PostgreSQL has no TTL, so the core collects. */\n\t\t\tindex('tokens_expires_at').on(t.expiresAt),\n\t\t],\n\t);\n}\n",
|
|
11
11
|
"import { sql } from 'drizzle-orm';\nimport {\n\tboolean,\n\tcheck,\n\tindex,\n\tinteger,\n\tjsonb,\n\ttext,\n\tunique,\n} from 'drizzle-orm/pg-core';\nimport { at, key, type TableFactory } from './columns';\n\n/**\n * Users and their passwords: one row each. `logins` is the port's array,\n * verbatim and in order; its uniqueness is `logins`' primary key.\n */\nexport function usersTable(table: TableFactory) {\n\treturn table(\n\t\t'users',\n\t\t{\n\t\t\t/** The UUIDv7 the core minted. `text`, not `uuid`: the store parses nothing. */\n\t\t\tid: key('id').primaryKey(),\n\t\t\ttype: key('type').notNull(),\n\t\t\tschemaVersion: text('schema_version').notNull(),\n\t\t\tactive: boolean('active').notNull(),\n\t\t\t/** The application's fields. The core validated them already. */\n\t\t\tfields: jsonb('fields').notNull(),\n\t\t\tlogins: text('logins').array().notNull(),\n\t\t\tpasswordHash: text('password_hash'),\n\t\t\tpasswordUpdatedAt: at('password_updated_at'),\n\t\t\t/** `'totp'`, or `null` for a user with no second factor. */\n\t\t\tsecondFactorMethod: text('second_factor_method', { enum: ['totp'] }),\n\t\t\t/** Sealed by the core with the application's key: never the plain secret. */\n\t\t\tsecondFactorSecret: text('second_factor_secret'),\n\t\t\tsecondFactorConfirmedAt: at('second_factor_confirmed_at'),\n\t\t\tsecondFactorLastStep: integer('second_factor_last_step'),\n\t\t\t/**\n\t\t\t * The recovery codes' keyed hashes, in order — `null` for none, read\n\t\t\t * as `[]`, so a row written before the column existed reads as no\n\t\t\t * codes.\n\t\t\t */\n\t\t\tsecondFactorRecoveryCodes: text('second_factor_recovery_codes').array(),\n\t\t\temailVerifiedAt: at('email_verified_at'),\n\t\t\tversion: integer('version').notNull(),\n\t\t\tcreatedAt: at('created_at').notNull(),\n\t\t\tupdatedAt: at('updated_at').notNull(),\n\t\t},\n\t\t(t) => [\n\t\t\t/** What `logins` references, so a login's type is its user's. */\n\t\t\tunique('users_id_type_unique').on(t.id, t.type),\n\t\t\t/** `listUsers` reads one type in id order. */\n\t\t\tindex('users_type_id').on(t.type, t.id),\n\t\t\t/** A password is a hash and when it was set, or neither. */\n\t\t\tcheck(\n\t\t\t\t'users_password_whole',\n\t\t\t\tsql`(${t.passwordHash} is null) = (${t.passwordUpdatedAt} is null)`,\n\t\t\t),\n\t\t\t/**\n\t\t\t * A second factor is a method and a secret, or neither; its\n\t\t\t * confirmation, last step and recovery codes exist only beside them.\n\t\t\t */\n\t\t\tcheck(\n\t\t\t\t'users_second_factor_whole',\n\t\t\t\tsql`(${t.secondFactorMethod} is null) = (${t.secondFactorSecret} is null) and (${t.secondFactorMethod} is not null or (${t.secondFactorConfirmedAt} is null and ${t.secondFactorLastStep} is null and ${t.secondFactorRecoveryCodes} is null))`,\n\t\t\t),\n\t\t\t/** `'totp'` is the one method; a step counts up from the epoch. */\n\t\t\tcheck(\n\t\t\t\t'users_second_factor_values',\n\t\t\t\tsql`${t.secondFactorMethod} in ('totp') and ${t.secondFactorLastStep} >= 0`,\n\t\t\t),\n\t\t],\n\t);\n}\n",
|
|
12
12
|
"import { toDataError } from '@nxgt/drizzle';\nimport { JanusError, StoreConflict, StoreFailure } from '@nxgt/janus';\n\n/**\n * **The database's errors, as the port's.** One file, and one default.\n *\n * | What happens | Becomes |\n * | --- | --- |\n * | A login another user of the type holds | `StoreConflict('login')`, carrying `login` and `userType` |\n * | A row with this id already there | nothing: the insert is a retry, and answers what is stored |\n * | A unique violation on **any other constraint** | **`StoreFailure`** |\n * | A check or foreign key refusing a row | **`StoreFailure`** |\n * | Anything else, absolutely | `StoreFailure`, with `@nxgt/drizzle`'s `DataError` as `cause` |\n *\n * The first two are never errors here: a login is written with `on conflict\n * do nothing`, and a login the statement did not write is one somebody else\n * holds — so no conflict is ever told apart by parsing a driver's message.\n *\n * The bold rows go against the obvious reading. A violation the adapter did\n * not mean to cause is an adapter bug, and reporting it as `LOGIN_TAKEN`\n * would tell somebody their login is taken when it is not. The core\n * validated every record before it reached a store, so a constraint refusing\n * one means the adapter and the port disagree — never the caller's fault.\n *\n * **The default is a failure, not an absence.** That branch is what keeps the\n * port's first rule: nothing here answers `null` for an error.\n */\n\nexport type Slot = 'users' | 'sessions' | 'tokens' | 'relations';\n\n/** Runs one port method, and makes every rejection one the port allows. */\nexport async function run<T>(\n\tslot: Slot,\n\toperation: string,\n\tbody: () => Promise<T>,\n): Promise<T> {\n\ttry {\n\t\treturn await body();\n\t} catch (error) {\n\t\t// Already the port's — a conflict, a NOT_FOUND after a read.\n\t\tif (error instanceof JanusError) throw error;\n\t\tthrow new StoreFailure(`${slot}.${operation}: the store could not answer`, {\n\t\t\tslot,\n\t\t\toperation,\n\t\t\tcause: toDataError(error),\n\t\t});\n\t}\n}\n\n/** The refusal the port promises for a taken login. */\nexport function loginTaken(\n\toperation: string,\n\ttype: string,\n\tlogin: string,\n): StoreConflict {\n\treturn new StoreConflict(\n\t\t'login',\n\t\t`${operation}: the login is taken by another ${type}`,\n\t\t{ login, userType: type, operation },\n\t);\n}\n",
|
|
13
13
|
"import type {\n\tCursorPage,\n\tEntity,\n\tRelationTuple,\n\tSubjectSet,\n} from '@nxgt/janus';\nimport type { ObjectPageRequest } from '@nxgt/janus/permissions';\nimport { and, asc, eq, gt, isNotNull, isNull } from 'drizzle-orm';\nimport type { RelationContext } from './context';\nimport { matching, subjectIs } from './tuples';\n\nexport async function has(\n\t{ db, relations }: RelationContext,\n\ttuple: RelationTuple,\n): Promise<boolean> {\n\tconst found = await db\n\t\t.select({ relation: relations.relation })\n\t\t.from(relations)\n\t\t.where(matching(relations, tuple))\n\t\t.limit(1);\n\treturn found.length === 1;\n}\n\nexport async function findSubjectSets(\n\tcontext: RelationContext,\n\tobject: Entity,\n\trelation: string,\n): Promise<SubjectSet[]> {\n\treturn (await holding(context, object, relation, true)).map(\n\t\t(row): SubjectSet => ({\n\t\t\ttype: row.type,\n\t\t\tid: row.id,\n\t\t\trelation: row.relation ?? '',\n\t\t}),\n\t);\n}\n\nexport async function findEntities(\n\tcontext: RelationContext,\n\tobject: Entity,\n\trelation: string,\n): Promise<Entity[]> {\n\treturn (await holding(context, object, relation, false)).map(\n\t\t(row): Entity => ({ type: row.type, id: row.id }),\n\t);\n}\n\n/** One hop from an object: its subject sets, or its entities. */\nfunction holding(\n\t{ db, relations }: RelationContext,\n\tobject: Entity,\n\trelation: string,\n\tsets: boolean,\n) {\n\treturn db\n\t\t.select({\n\t\t\ttype: relations.subjectType,\n\t\t\tid: relations.subjectId,\n\t\t\trelation: relations.subjectRelation,\n\t\t})\n\t\t.from(relations)\n\t\t.where(\n\t\t\tand(\n\t\t\t\teq(relations.objectType, object.type),\n\t\t\t\teq(relations.objectId, object.id),\n\t\t\t\teq(relations.relation, relation),\n\t\t\t\tsets\n\t\t\t\t\t? isNotNull(relations.subjectRelation)\n\t\t\t\t\t: isNull(relations.subjectRelation),\n\t\t\t),\n\t\t);\n}\n\n/** A page of object ids, in id order, after the cursor. */\nexport async function findObjects(\n\t{ db, relations }: RelationContext,\n\t{ type, relation, subject, after, limit }: ObjectPageRequest,\n): Promise<CursorPage<string>> {\n\tconst conditions = [\n\t\tsubjectIs(relations, subject),\n\t\teq(relations.relation, relation),\n\t\teq(relations.objectType, type),\n\t];\n\tif (after !== null) conditions.push(gt(relations.objectId, after));\n\tconst found = await db\n\t\t.select({ id: relations.objectId })\n\t\t.from(relations)\n\t\t.where(and(...conditions))\n\t\t.orderBy(asc(relations.objectId))\n\t\t.limit(limit + 1);\n\tconst items = found.slice(0, limit).map((row) => row.id);\n\tconst last = items.at(-1);\n\treturn {\n\t\titems,\n\t\tnextCursor: found.length > limit && last !== undefined ? last : null,\n\t};\n}\n",
|
|
14
14
|
"import { isSubjectSet, type RelationTuple, type Subject } from '@nxgt/janus';\nimport { and, eq, isNull, type SQL } from 'drizzle-orm';\nimport type { Relations } from './context';\n\n/** Tuples in one order: their notation, compared by code unit. */\nexport function inOrder(\n\ttuples: readonly RelationTuple[],\n): readonly RelationTuple[] {\n\tconst keyOf = (tuple: RelationTuple) =>\n\t\tJSON.stringify([\n\t\t\ttuple.object.type,\n\t\t\ttuple.object.id,\n\t\t\ttuple.relation,\n\t\t\ttuple.subject.type,\n\t\t\ttuple.subject.id,\n\t\t\tisSubjectSet(tuple.subject) ? tuple.subject.relation : null,\n\t\t]);\n\treturn [...tuples].sort((a, b) => {\n\t\tconst [x, y] = [keyOf(a), keyOf(b)];\n\t\treturn x < y ? -1 : x > y ? 1 : 0;\n\t});\n}\n\n/** A tuple as a row: an entity's `subject_relation` is `null`. */\nexport function rowOf(tuple: RelationTuple): Relations['$inferInsert'] {\n\treturn {\n\t\tobjectType: tuple.object.type,\n\t\tobjectId: tuple.object.id,\n\t\trelation: tuple.relation,\n\t\tsubjectType: tuple.subject.type,\n\t\tsubjectId: tuple.subject.id,\n\t\tsubjectRelation: isSubjectSet(tuple.subject)\n\t\t\t? tuple.subject.relation\n\t\t\t: null,\n\t};\n}\n\n/** Exactly this subject: a subject set is not its entity, and the reverse. */\nexport function subjectIs(\n\trelations: Relations,\n\tsubject: Subject,\n): SQL | undefined {\n\treturn and(\n\t\teq(relations.subjectType, subject.type),\n\t\teq(relations.subjectId, subject.id),\n\t\tisSubjectSet(subject)\n\t\t\t? eq(relations.subjectRelation, subject.relation)\n\t\t\t: isNull(relations.subjectRelation),\n\t);\n}\n\n/** Exactly this tuple. */\nexport function matching(\n\trelations: Relations,\n\ttuple: RelationTuple,\n): SQL | undefined {\n\treturn and(\n\t\teq(relations.objectType, tuple.object.type),\n\t\teq(relations.objectId, tuple.object.id),\n\t\teq(relations.relation, tuple.relation),\n\t\tsubjectIs(relations, tuple.subject),\n\t);\n}\n",
|
|
15
15
|
"import { type PgDatabase, withTransaction } from '@nxgt/drizzle/pg';\nimport type { Entity, RelationTuple } from '@nxgt/janus';\nimport { and, eq, or } from 'drizzle-orm';\nimport type { RelationContext, Relations } from './context';\nimport { inOrder, matching, rowOf } from './tuples';\n\n/** One tuple in one statement; more in one transaction. */\nexport async function write(\n\t{ db, relations }: RelationContext,\n\tadd: readonly RelationTuple[],\n\tremove: readonly RelationTuple[],\n): Promise<void> {\n\tif (add.length + remove.length <= 1) return apply(db, relations, add, remove);\n\tawait withTransaction(db, (tx) => apply(tx, relations, add, remove));\n}\n\n/** Removals first, then additions. */\nasync function apply(\n\ttx: PgDatabase,\n\trelations: Relations,\n\tadd: readonly RelationTuple[],\n\tremove: readonly RelationTuple[],\n): Promise<void> {\n\t// In one order, so two writes touching the same tuples take their locks\n\t// alike and never deadlock.\n\tfor (const tuple of inOrder(remove)) {\n\t\tawait tx.delete(relations).where(matching(relations, tuple));\n\t}\n\tif (add.length > 0) {\n\t\t// A stored tuple meets the unique constraint, and is a no-op.\n\t\tawait tx\n\t\t\t.insert(relations)\n\t\t\t.values(inOrder(add).map(rowOf))\n\t\t\t.onConflictDoNothing();\n\t}\n}\n\n/** Every tuple naming the entity, as object or as subject. */\nexport async function deleteEntity(\n\t{ db, relations }: RelationContext,\n\tentity: Entity,\n): Promise<number> {\n\tconst deleted = await db\n\t\t.delete(relations)\n\t\t.where(\n\t\t\tor(\n\t\t\t\tand(\n\t\t\t\t\teq(relations.objectType, entity.type),\n\t\t\t\t\teq(relations.objectId, entity.id),\n\t\t\t\t),\n\t\t\t\tand(\n\t\t\t\t\teq(relations.subjectType, entity.type),\n\t\t\t\t\teq(relations.subjectId, entity.id),\n\t\t\t\t),\n\t\t\t),\n\t\t)\n\t\t.returning({ relation: relations.relation });\n\treturn deleted.length;\n}\n",
|
|
16
16
|
"import type { PgDatabase } from '@nxgt/drizzle/pg';\nimport type { RelationStore } from '@nxgt/janus/permissions';\nimport { type DrizzleAdapterOptions, defineJanusTables } from '../tables';\nimport { run } from '../translate';\nimport type { RelationContext } from './context';\nimport { findEntities, findObjects, findSubjectSets, has } from './reads';\nimport { deleteEntity, write } from './writes';\n\n/**\n * The relation store `permissions()` takes, over one PostgreSQL database\n * through Drizzle — and the one `janus({ relations })` deletes a user's\n * tuples from.\n *\n * ```ts\n * const access = permissions({ model, store: createDrizzleRelations(db) });\n * ```\n *\n * **A write of more than one tuple is a transaction**, `@nxgt/drizzle`'s\n * `withTransaction`: removals first, then additions, all or nothing. It is not\n * retried here — a write is idempotent, so the caller retries.\n */\nexport function createDrizzleRelations(\n\tdb: PgDatabase,\n\toptions: DrizzleAdapterOptions<'relations'> = {},\n): RelationStore {\n\tconst tables = options.tables ?? defineJanusTables();\n\tconst context: RelationContext = { db, relations: tables.relations };\n\tconst run$ = <T>(operation: string, body: () => Promise<T>) =>\n\t\trun('relations', operation, body);\n\n\treturn {\n\t\twrite: ({ add = [], remove = [] }) =>\n\t\t\trun$('write', () => write(context, add, remove)),\n\t\thas: (tuple) => run$('has', () => has(context, tuple)),\n\t\tfindSubjectSets: (object, relation) =>\n\t\t\trun$('findSubjectSets', () => findSubjectSets(context, object, relation)),\n\t\tfindEntities: (object, relation) =>\n\t\t\trun$('findEntities', () => findEntities(context, object, relation)),\n\t\t// The request is unpacked before `run$`, as `write`'s is and as it was\n\t\t// before the split, so a malformed request throws the caller's\n\t\t// TypeError at once instead of reading as an outage.\n\t\tfindObjects: ({ type, relation, subject, after, limit }) =>\n\t\t\trun$('findObjects', () =>\n\t\t\t\tfindObjects(context, { type, relation, subject, after, limit }),\n\t\t\t),\n\t\tdeleteEntity: (entity) =>\n\t\t\trun$('deleteEntity', () => deleteEntity(context, entity)),\n\t};\n}\n",
|
|
17
|
-
"import type { PgDatabase } from '@nxgt/drizzle/pg';\nimport type { SessionRecord, SessionStore } from '@nxgt/janus';\nimport { and, eq, isNull, lte, ne, sql } from 'drizzle-orm';\nimport { run } from '../translate';\nimport type { IdentityTables } from './identity-tables';\nimport { stamp, toSession } from './records';\n\nexport function sessionStore(\n\tdb: PgDatabase,\n\ttables: IdentityTables,\n): SessionStore {\n\tconst run$ = <T>(operation: string, body: () => Promise<T>) =>\n\t\trun('sessions', operation, body);\n\n\treturn {\n\t\tinsertSession: (record) =>\n\t\t\trun$('insertSession', async () => {\n\t\t\t\t// Idempotent under retry: a session with this id is already there.\n\t\t\t\t// A collision on the token hash is not a retry, and fails.\n\t\t\t\tawait db\n\t\t\t\t\t.insert(tables.sessions)\n\t\t\t\t\t.values(record)\n\t\t\t\t\t.onConflictDoNothing({ target: tables.sessions.id });\n\t\t\t}),\n\n\t\tfindSessionByTokenHash: (tokenHash) =>\n\t\t\trun$('findSessionByTokenHash', async () => {\n\t\t\t\tconst [row] = await db\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(tables.sessions)\n\t\t\t\t\t.where(eq(tables.sessions.tokenHash, tokenHash));\n\t\t\t\treturn row === undefined ? null : toSession(row);\n\t\t\t}),\n\n\t\textendSession: (id, expiresAt) =>\n\t\t\trun$('extendSession', async () => {\n\t\t\t\t// `revoked_at is null` in the condition: an extension racing a\n\t\t\t\t// revocation matches nothing, and never brings the session back.\n\t\t\t\tconst [row] = await db\n\t\t\t\t\t.update(tables.sessions)\n\t\t\t\t\t.set({ expiresAt })\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(eq(tables.sessions.id, id), isNull(tables.sessions.revokedAt)),\n\t\t\t\t\t)\n\t\t\t\t\t.returning();\n\t\t\t\treturn row === undefined ? null : toSession(row);\n\t\t\t}),\n\n\t\treauthenticateSession: (id, at) =>\n\t\t\trun$('reauthenticateSession', () =>\n\t\t\t\treauthenticateSession(db, tables, id, at),\n\t\t\t),\n\n\t\trevokeSession: (id, at) =>\n\t\t\trun$('revokeSession', () => revokeSession(db, tables, id, at)),\n\n\t\trevokeUserSessions: (userId, at, except) =>\n\t\t\trun$('revokeUserSessions', () =>\n\t\t\t\trevokeUserSessions(db, tables, userId, at, except),\n\t\t\t),\n\n\t\tdeleteUserSessions: (userId) =>\n\t\t\trun$('deleteUserSessions', async () => {\n\t\t\t\tconst deleted = await db\n\t\t\t\t\t.delete(tables.sessions)\n\t\t\t\t\t.where(eq(tables.sessions.userId, userId))\n\t\t\t\t\t.returning({ id: tables.sessions.id });\n\t\t\t\treturn deleted.length;\n\t\t\t}),\n\n\t\tdeleteExpiredSessions: (before) =>\n\t\t\trun$('deleteExpiredSessions', async () => {\n\t\t\t\
|
|
17
|
+
"import type { PgDatabase } from '@nxgt/drizzle/pg';\nimport type { SessionRecord, SessionStore } from '@nxgt/janus';\nimport { and, eq, isNull, lte, ne, sql } from 'drizzle-orm';\nimport { run } from '../translate';\nimport { deleteAndCount } from './count-deleted';\nimport type { IdentityTables } from './identity-tables';\nimport { stamp, toSession } from './records';\n\nexport function sessionStore(\n\tdb: PgDatabase,\n\ttables: IdentityTables,\n): SessionStore {\n\tconst run$ = <T>(operation: string, body: () => Promise<T>) =>\n\t\trun('sessions', operation, body);\n\n\treturn {\n\t\tinsertSession: (record) =>\n\t\t\trun$('insertSession', async () => {\n\t\t\t\t// Idempotent under retry: a session with this id is already there.\n\t\t\t\t// A collision on the token hash is not a retry, and fails.\n\t\t\t\tawait db\n\t\t\t\t\t.insert(tables.sessions)\n\t\t\t\t\t.values(record)\n\t\t\t\t\t.onConflictDoNothing({ target: tables.sessions.id });\n\t\t\t}),\n\n\t\tfindSessionByTokenHash: (tokenHash) =>\n\t\t\trun$('findSessionByTokenHash', async () => {\n\t\t\t\tconst [row] = await db\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(tables.sessions)\n\t\t\t\t\t.where(eq(tables.sessions.tokenHash, tokenHash));\n\t\t\t\treturn row === undefined ? null : toSession(row);\n\t\t\t}),\n\n\t\textendSession: (id, expiresAt) =>\n\t\t\trun$('extendSession', async () => {\n\t\t\t\t// `revoked_at is null` in the condition: an extension racing a\n\t\t\t\t// revocation matches nothing, and never brings the session back.\n\t\t\t\tconst [row] = await db\n\t\t\t\t\t.update(tables.sessions)\n\t\t\t\t\t.set({ expiresAt })\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(eq(tables.sessions.id, id), isNull(tables.sessions.revokedAt)),\n\t\t\t\t\t)\n\t\t\t\t\t.returning();\n\t\t\t\treturn row === undefined ? null : toSession(row);\n\t\t\t}),\n\n\t\treauthenticateSession: (id, at) =>\n\t\t\trun$('reauthenticateSession', () =>\n\t\t\t\treauthenticateSession(db, tables, id, at),\n\t\t\t),\n\n\t\trevokeSession: (id, at) =>\n\t\t\trun$('revokeSession', () => revokeSession(db, tables, id, at)),\n\n\t\trevokeUserSessions: (userId, at, except) =>\n\t\t\trun$('revokeUserSessions', () =>\n\t\t\t\trevokeUserSessions(db, tables, userId, at, except),\n\t\t\t),\n\n\t\tdeleteUserSessions: (userId) =>\n\t\t\trun$('deleteUserSessions', async () => {\n\t\t\t\tconst deleted = await db\n\t\t\t\t\t.delete(tables.sessions)\n\t\t\t\t\t.where(eq(tables.sessions.userId, userId))\n\t\t\t\t\t.returning({ id: tables.sessions.id });\n\t\t\t\treturn deleted.length;\n\t\t\t}),\n\n\t\tdeleteExpiredSessions: (before) =>\n\t\t\trun$('deleteExpiredSessions', async () => {\n\t\t\t\treturn deleteAndCount(\n\t\t\t\t\tdb,\n\t\t\t\t\ttables.sessions,\n\t\t\t\t\tlte(tables.sessions.expiresAt, before),\n\t\t\t\t);\n\t\t\t}),\n\t};\n}\n\nasync function reauthenticateSession(\n\tdb: PgDatabase,\n\ttables: IdentityTables,\n\tid: string,\n\tat: Date,\n): Promise<SessionRecord | null> {\n\t// The same condition as an extension's: a confirmation racing a\n\t// revocation matches nothing.\n\tconst [row] = await db\n\t\t.update(tables.sessions)\n\t\t.set({ authenticatedAt: at })\n\t\t.where(and(eq(tables.sessions.id, id), isNull(tables.sessions.revokedAt)))\n\t\t.returning();\n\treturn row === undefined ? null : toSession(row);\n}\n\nasync function revokeSession(\n\tdb: PgDatabase,\n\ttables: IdentityTables,\n\tid: string,\n\tat: Date,\n): Promise<boolean> {\n\t// `coalesce`, so a session already revoked keeps its first\n\t// `revokedAt` and still counts as matched.\n\tconst matched = await db\n\t\t.update(tables.sessions)\n\t\t.set({\n\t\t\trevokedAt: sql`coalesce(${tables.sessions.revokedAt}, ${stamp(at)})`,\n\t\t})\n\t\t.where(eq(tables.sessions.id, id))\n\t\t.returning({ id: tables.sessions.id });\n\treturn matched.length === 1;\n}\n\nasync function revokeUserSessions(\n\tdb: PgDatabase,\n\ttables: IdentityTables,\n\tuserId: string,\n\tat: Date,\n\texcept: string | undefined,\n): Promise<number> {\n\tconst standing = and(\n\t\teq(tables.sessions.userId, userId),\n\t\tisNull(tables.sessions.revokedAt),\n\t);\n\tconst revoked = await db\n\t\t.update(tables.sessions)\n\t\t.set({ revokedAt: at })\n\t\t.where(\n\t\t\texcept === undefined\n\t\t\t\t? standing\n\t\t\t\t: and(standing, ne(tables.sessions.id, except)),\n\t\t)\n\t\t.returning({ id: tables.sessions.id });\n\treturn revoked.length;\n}\n",
|
|
18
|
+
"import type { PgDatabase } from '@nxgt/drizzle/pg';\nimport { count, type SQL, sql } from 'drizzle-orm';\nimport type { PgTable } from 'drizzle-orm/pg-core';\n\n/**\n * Deletes the rows of `table` matching `where` and answers how many, counted\n * by the server: `with d as (delete … returning 1) select count(*) from d`.\n * A collection can delete millions of rows; none of them reaches the process.\n */\nexport async function deleteAndCount(\n\tdb: PgDatabase,\n\ttable: PgTable,\n\twhere: SQL | undefined,\n): Promise<number> {\n\tconst deleted = db.$with('deleted').as(\n\t\tdb\n\t\t\t.delete(table)\n\t\t\t.where(where)\n\t\t\t.returning({ one: sql<number>`1`.as('one') }),\n\t);\n\tconst [row] = await db.with(deleted).select({ n: count() }).from(deleted);\n\treturn row?.n ?? 0;\n}\n",
|
|
18
19
|
"import type { Id, SessionRecord, UserPatch, UserRecord } from '@nxgt/janus';\nimport { type SQL, sql } from 'drizzle-orm';\nimport type { JanusTables } from '../tables';\n\n// ─── Rows and records ─────────────────────────────────────────────────────\n//\n// Each record is rebuilt field by field: the port's records are exactly what\n// it declares, and a row carries columns the record names differently.\n\ntype UserRow = JanusTables['users']['$inferSelect'];\ntype UserInsert = JanusTables['users']['$inferInsert'];\ntype SessionRow = JanusTables['sessions']['$inferSelect'];\n\nexport function toUserRow(record: UserRecord): UserInsert {\n\treturn {\n\t\tid: record.id,\n\t\ttype: record.type,\n\t\tschemaVersion: record.schemaVersion,\n\t\tactive: record.active,\n\t\tfields: record.fields,\n\t\tlogins: [...record.logins],\n\t\tpasswordHash: record.password?.hash ?? null,\n\t\tpasswordUpdatedAt: record.password?.updatedAt ?? null,\n\t\t...toSecondFactorColumns(record.secondFactor),\n\t\temailVerifiedAt: record.emailVerifiedAt,\n\t\tversion: record.version,\n\t\tcreatedAt: record.createdAt,\n\t\tupdatedAt: record.updatedAt,\n\t};\n}\n\n/**\n * The columns a patch names. A key present with `undefined` is absent, as the\n * port says — never an erasure. `password: null` is named, and removes the\n * password.\n */\nexport function toUserSet(patch: UserPatch): Partial<UserInsert> {\n\tconst set: Partial<UserInsert> = {\n\t\tupdatedAt: patch.updatedAt,\n\t};\n\tif (patch.schemaVersion !== undefined)\n\t\tset.schemaVersion = patch.schemaVersion;\n\tif (patch.active !== undefined) set.active = patch.active;\n\tif (patch.fields !== undefined) set.fields = patch.fields;\n\tif (patch.logins !== undefined) set.logins = [...patch.logins];\n\tif (patch.emailVerifiedAt !== undefined)\n\t\tset.emailVerifiedAt = patch.emailVerifiedAt;\n\tif (patch.password !== undefined) {\n\t\tset.passwordHash = patch.password?.hash ?? null;\n\t\tset.passwordUpdatedAt = patch.password?.updatedAt ?? null;\n\t}\n\tif (patch.secondFactor !== undefined) {\n\t\tObject.assign(set, toSecondFactorColumns(patch.secondFactor));\n\t}\n\treturn set;\n}\n\n/**\n * A second factor as its five columns, all `null` for none. No recovery\n * codes are written `null` too, never `{}`, and read back as `[]`: a row\n * then holds a code array only while it holds codes, so an instance of 0.3\n * — which knows four columns — can still remove a factor that has none.\n */\nfunction toSecondFactorColumns(secondFactor: UserRecord['secondFactor']) {\n\tconst codes = secondFactor?.recoveryCodes ?? [];\n\treturn {\n\t\tsecondFactorMethod: secondFactor?.method ?? null,\n\t\tsecondFactorSecret: secondFactor?.secret ?? null,\n\t\tsecondFactorConfirmedAt: secondFactor?.confirmedAt ?? null,\n\t\tsecondFactorLastStep: secondFactor?.lastStep ?? null,\n\t\tsecondFactorRecoveryCodes: codes.length === 0 ? null : [...codes],\n\t};\n}\n\nexport function toUser(row: UserRow): UserRecord {\n\treturn {\n\t\tid: row.id as Id,\n\t\ttype: row.type,\n\t\tschemaVersion: row.schemaVersion,\n\t\tactive: row.active,\n\t\tfields: row.fields as UserRecord['fields'],\n\t\tlogins: [...row.logins],\n\t\tpassword:\n\t\t\trow.passwordHash === null || row.passwordUpdatedAt === null\n\t\t\t\t? null\n\t\t\t\t: { hash: row.passwordHash, updatedAt: row.passwordUpdatedAt },\n\t\tsecondFactor:\n\t\t\trow.secondFactorMethod === null || row.secondFactorSecret === null\n\t\t\t\t? null\n\t\t\t\t: {\n\t\t\t\t\t\tmethod: row.secondFactorMethod,\n\t\t\t\t\t\tsecret: row.secondFactorSecret,\n\t\t\t\t\t\tconfirmedAt: row.secondFactorConfirmedAt,\n\t\t\t\t\t\tlastStep: row.secondFactorLastStep,\n\t\t\t\t\t\trecoveryCodes: [...(row.secondFactorRecoveryCodes ?? [])],\n\t\t\t\t\t},\n\t\temailVerifiedAt: row.emailVerifiedAt,\n\t\tversion: row.version,\n\t\tcreatedAt: row.createdAt,\n\t\tupdatedAt: row.updatedAt,\n\t};\n}\n\nexport function toSession(row: SessionRow): SessionRecord {\n\treturn {\n\t\tid: row.id,\n\t\ttokenHash: row.tokenHash,\n\t\tuserId: row.userId as Id,\n\t\tauthenticatedAt: row.authenticatedAt,\n\t\texpiresAt: row.expiresAt,\n\t\trevokedAt: row.revokedAt,\n\t\tcreatedAt: row.createdAt,\n\t};\n}\n\n/**\n * A `Date` inside a `sql` template, as every driver takes it: `timestamptz`\n * from its ISO string. Drizzle's column mapping does not reach a raw\n * template, and postgres.js refuses a `Date` object there.\n */\nexport function stamp(at: Date): SQL {\n\treturn sql`${at.toISOString()}::timestamptz`;\n}\n",
|
|
19
|
-
"import type { PgDatabase } from '@nxgt/drizzle/pg';\nimport type { Id, TokenKind, TokenRecord, TokenStore } from '@nxgt/janus';\nimport { and, eq, isNull, ne, sql } from 'drizzle-orm';\nimport { run } from '../translate';\nimport type { IdentityTables } from './identity-tables';\nimport { stamp } from './records';\n\nexport function tokenStore(db: PgDatabase, tables: IdentityTables): TokenStore {\n\tconst run$ = <T>(operation: string, body: () => Promise<T>) =>\n\t\trun('tokens', operation, body);\n\n\treturn {\n\t\tinsertToken: (record) =>\n\t\t\trun$('insertToken', async () => {\n\t\t\t\t// The hash is the key: a collision is a retry.\n\t\t\t\tawait db.insert(tables.tokens).values(record).onConflictDoNothing();\n\t\t\t}),\n\n\t\tconsumeToken: (tokenHash, kind, at) =>\n\t\t\trun$('consumeToken', () => consumeToken(db, tables, tokenHash, kind, at)),\n\n\t\tcountAttempt: (tokenHash, kind) =>\n\t\t\trun$('countAttempt', () => countAttempt(db, tables, tokenHash, kind)),\n\n\t\tspendUserTokens: (userId, kind, at, except) =>\n\t\t\trun$('spendUserTokens', async () => {\n\t\t\t\t// One statement: each row is written under its lock, and\n\t\t\t\t// re-checked after a concurrent `consumeToken` committed, so the\n\t\t\t\t// two never both spend it.\n\t\t\t\tconst spent = await db\n\t\t\t\t\t.update(tables.tokens)\n\t\t\t\t\t.set({ spentAt: at })\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(\n\t\t\t\t\t\t\teq(tables.tokens.userId, userId),\n\t\t\t\t\t\t\teq(tables.tokens.kind, kind),\n\t\t\t\t\t\t\tisNull(tables.tokens.spentAt),\n\t\t\t\t\t\t\texcept === undefined\n\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t: ne(tables.tokens.tokenHash, except),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.returning({ tokenHash: tables.tokens.tokenHash });\n\t\t\t\treturn spent.length;\n\t\t\t}),\n\n\t\tdeleteUserTokens: (userId) =>\n\t\t\trun$('deleteUserTokens', async () => {\n\t\t\t\tconst deleted = await db\n\t\t\t\t\t.delete(tables.tokens)\n\t\t\t\t\t.where(eq(tables.tokens.userId, userId))\n\t\t\t\t\t.returning({ tokenHash: tables.tokens.tokenHash });\n\t\t\t\treturn deleted.length;\n\t\t\t}),\n\t};\n}\n\nasync function consumeToken(\n\tdb: PgDatabase,\n\ttables: IdentityTables,\n\ttokenHash: string,\n\tkind: TokenKind,\n\tat: Date,\n): Promise<TokenRecord | null> {\n\t// **One conditional write**, answering the row as it was before\n\t// it. `for update` makes a concurrent call wait for this one and\n\t// then read the spent row, so exactly one caller ever reads\n\t// `spentAt: null`; `coalesce` keeps a first `spentAt`.\n\tconst before = db.$with('before').as(\n\t\tdb\n\t\t\t.select()\n\t\t\t.from(tables.tokens)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(tables.tokens.tokenHash, tokenHash),\n\t\t\t\t\teq(tables.tokens.kind, kind),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.for('update'),\n\t);\n\tconst [spent] = await db\n\t\t.with(before)\n\t\t.update(tables.tokens)\n\t\t.set({\n\t\t\tspentAt: sql`coalesce(${tables.tokens.spentAt}, ${stamp(at)})`,\n\t\t})\n\t\t.from(before)\n\t\t.where(eq(tables.tokens.tokenHash, before.tokenHash))\n\t\t.returning({\n\t\t\ttokenHash: before.tokenHash,\n\t\t\tkind: before.kind,\n\t\t\tuserId: before.userId,\n\t\t\taddress: before.address,\n\t\t\tcodeHash: before.codeHash,\n\t\t\tattempts: before.attempts,\n\t\t\texpiresAt: before.expiresAt,\n\t\t\tspentAt: before.spentAt,\n\t\t\tcreatedAt: before.createdAt,\n\t\t});\n\treturn spent === undefined ? null : { ...spent, userId: spent.userId as Id };\n}\n\nasync function countAttempt(\n\tdb: PgDatabase,\n\ttables: IdentityTables,\n\ttokenHash: string,\n\tkind: TokenKind,\n): Promise<TokenRecord | null> {\n\t// **One conditional write**: `attempts + 1` on the row, under the\n\t// row's lock, so twenty concurrent calls answer twenty counts. A\n\t// spent token matches nothing here, and is read as it is below.\n\tconst match = and(\n\t\teq(tables.tokens.tokenHash, tokenHash),\n\t\teq(tables.tokens.kind, kind),\n\t);\n\tconst [counted] = await db\n\t\t.update(tables.tokens)\n\t\t.set({ attempts: sql`${tables.tokens.attempts} + 1` })\n\t\t.where(and(match, isNull(tables.tokens.spentAt)))\n\t\t.returning();\n\tconst row =\n\t\tcounted ?? (await db.select().from(tables.tokens).where(match))[0];\n\treturn row === undefined ? null : { ...row, userId: row.userId as Id };\n}\n",
|
|
20
|
+
"import type { PgDatabase } from '@nxgt/drizzle/pg';\nimport type { Id, TokenKind, TokenRecord, TokenStore } from '@nxgt/janus';\nimport { and, eq, isNull, lte, ne, sql } from 'drizzle-orm';\nimport { run } from '../translate';\nimport { deleteAndCount } from './count-deleted';\nimport type { IdentityTables } from './identity-tables';\nimport { stamp } from './records';\n\nexport function tokenStore(db: PgDatabase, tables: IdentityTables): TokenStore {\n\tconst run$ = <T>(operation: string, body: () => Promise<T>) =>\n\t\trun('tokens', operation, body);\n\n\treturn {\n\t\tinsertToken: (record) =>\n\t\t\trun$('insertToken', async () => {\n\t\t\t\t// The hash is the key: a collision is a retry.\n\t\t\t\tawait db.insert(tables.tokens).values(record).onConflictDoNothing();\n\t\t\t}),\n\n\t\tconsumeToken: (tokenHash, kind, at) =>\n\t\t\trun$('consumeToken', () => consumeToken(db, tables, tokenHash, kind, at)),\n\n\t\tcountAttempt: (tokenHash, kind) =>\n\t\t\trun$('countAttempt', () => countAttempt(db, tables, tokenHash, kind)),\n\n\t\tspendUserTokens: (userId, kind, at, except) =>\n\t\t\trun$('spendUserTokens', async () => {\n\t\t\t\t// One statement: each row is written under its lock, and\n\t\t\t\t// re-checked after a concurrent `consumeToken` committed, so the\n\t\t\t\t// two never both spend it.\n\t\t\t\tconst spent = await db\n\t\t\t\t\t.update(tables.tokens)\n\t\t\t\t\t.set({ spentAt: at })\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(\n\t\t\t\t\t\t\teq(tables.tokens.userId, userId),\n\t\t\t\t\t\t\teq(tables.tokens.kind, kind),\n\t\t\t\t\t\t\tisNull(tables.tokens.spentAt),\n\t\t\t\t\t\t\texcept === undefined\n\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t: ne(tables.tokens.tokenHash, except),\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\t.returning({ tokenHash: tables.tokens.tokenHash });\n\t\t\t\treturn spent.length;\n\t\t\t}),\n\n\t\tdeleteUserTokens: (userId) =>\n\t\t\trun$('deleteUserTokens', async () => {\n\t\t\t\tconst deleted = await db\n\t\t\t\t\t.delete(tables.tokens)\n\t\t\t\t\t.where(eq(tables.tokens.userId, userId))\n\t\t\t\t\t.returning({ tokenHash: tables.tokens.tokenHash });\n\t\t\t\treturn deleted.length;\n\t\t\t}),\n\n\t\tdeleteExpiredTokens: (before) =>\n\t\t\trun$('deleteExpiredTokens', async () => {\n\t\t\t\t// Spent or not, of any kind and any user: a throttle's count is a\n\t\t\t\t// token too. A row that lapses later is never touched.\n\t\t\t\treturn deleteAndCount(\n\t\t\t\t\tdb,\n\t\t\t\t\ttables.tokens,\n\t\t\t\t\tlte(tables.tokens.expiresAt, before),\n\t\t\t\t);\n\t\t\t}),\n\t};\n}\n\nasync function consumeToken(\n\tdb: PgDatabase,\n\ttables: IdentityTables,\n\ttokenHash: string,\n\tkind: TokenKind,\n\tat: Date,\n): Promise<TokenRecord | null> {\n\t// **One conditional write**, answering the row as it was before\n\t// it. `for update` makes a concurrent call wait for this one and\n\t// then read the spent row, so exactly one caller ever reads\n\t// `spentAt: null`; `coalesce` keeps a first `spentAt`.\n\tconst before = db.$with('before').as(\n\t\tdb\n\t\t\t.select()\n\t\t\t.from(tables.tokens)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(tables.tokens.tokenHash, tokenHash),\n\t\t\t\t\teq(tables.tokens.kind, kind),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.for('update'),\n\t);\n\tconst [spent] = await db\n\t\t.with(before)\n\t\t.update(tables.tokens)\n\t\t.set({\n\t\t\tspentAt: sql`coalesce(${tables.tokens.spentAt}, ${stamp(at)})`,\n\t\t})\n\t\t.from(before)\n\t\t.where(eq(tables.tokens.tokenHash, before.tokenHash))\n\t\t.returning({\n\t\t\ttokenHash: before.tokenHash,\n\t\t\tkind: before.kind,\n\t\t\tuserId: before.userId,\n\t\t\taddress: before.address,\n\t\t\tcodeHash: before.codeHash,\n\t\t\tattempts: before.attempts,\n\t\t\texpiresAt: before.expiresAt,\n\t\t\tspentAt: before.spentAt,\n\t\t\tcreatedAt: before.createdAt,\n\t\t});\n\treturn spent === undefined ? null : { ...spent, userId: spent.userId as Id };\n}\n\nasync function countAttempt(\n\tdb: PgDatabase,\n\ttables: IdentityTables,\n\ttokenHash: string,\n\tkind: TokenKind,\n): Promise<TokenRecord | null> {\n\t// **One conditional write**: `attempts + 1` on the row, under the\n\t// row's lock, so twenty concurrent calls answer twenty counts. A\n\t// spent token matches nothing here, and is read as it is below.\n\tconst match = and(\n\t\teq(tables.tokens.tokenHash, tokenHash),\n\t\teq(tables.tokens.kind, kind),\n\t);\n\tconst [counted] = await db\n\t\t.update(tables.tokens)\n\t\t.set({ attempts: sql`${tables.tokens.attempts} + 1` })\n\t\t.where(and(match, isNull(tables.tokens.spentAt)))\n\t\t.returning();\n\tconst row =\n\t\tcounted ?? (await db.select().from(tables.tokens).where(match))[0];\n\treturn row === undefined ? null : { ...row, userId: row.userId as Id };\n}\n",
|
|
20
21
|
"import { type PgDatabase, withTransaction } from '@nxgt/drizzle/pg';\nimport type { UserPatch, UserRecord, UserStore } from '@nxgt/janus';\nimport { NotFoundError, StoreConflict } from '@nxgt/janus';\nimport { and, asc, eq, gt, inArray, sql } from 'drizzle-orm';\nimport { run } from '../translate';\nimport type { IdentityTables } from './identity-tables';\nimport { claimLogins } from './logins';\nimport { toUser, toUserRow, toUserSet } from './records';\n\nexport function userStore(db: PgDatabase, tables: IdentityTables): UserStore {\n\tconst run$ = <T>(operation: string, body: () => Promise<T>) =>\n\t\trun('users', operation, body);\n\n\treturn {\n\t\tinsertUser: (record) =>\n\t\t\trun$('insertUser', () => insertUser(db, tables, record)),\n\n\t\tfindUser: (id) => run$('findUser', () => findUser(db, tables, id)),\n\n\t\t// One statement, whatever the number of ids: the core sends at most\n\t\t// 100, distinct, and puts the answer back in its caller's order.\n\t\tfindUsers: (ids) =>\n\t\t\trun$('findUsers', async () => {\n\t\t\t\tconst found = await db\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(tables.users)\n\t\t\t\t\t.where(inArray(tables.users.id, [...ids]));\n\t\t\t\treturn found.map(toUser);\n\t\t\t}),\n\n\t\tfindUserByLogin: (type, login) =>\n\t\t\trun$('findUserByLogin', async () => {\n\t\t\t\tconst [row] = await db\n\t\t\t\t\t.select({ user: tables.users })\n\t\t\t\t\t.from(tables.logins)\n\t\t\t\t\t.innerJoin(tables.users, eq(tables.users.id, tables.logins.userId))\n\t\t\t\t\t.where(\n\t\t\t\t\t\tand(eq(tables.logins.type, type), eq(tables.logins.login, login)),\n\t\t\t\t\t);\n\t\t\t\treturn row === undefined ? null : toUser(row.user);\n\t\t\t}),\n\n\t\tlistUsers: ({ type, after, limit }) =>\n\t\t\trun$('listUsers', async () => {\n\t\t\t\t// One more than the page, to know whether another follows.\n\t\t\t\tconst found = await db\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(tables.users)\n\t\t\t\t\t.where(\n\t\t\t\t\t\tafter === null\n\t\t\t\t\t\t\t? eq(tables.users.type, type)\n\t\t\t\t\t\t\t: and(eq(tables.users.type, type), gt(tables.users.id, after)),\n\t\t\t\t\t)\n\t\t\t\t\t.orderBy(asc(tables.users.id))\n\t\t\t\t\t.limit(limit + 1);\n\t\t\t\tconst items = found.slice(0, limit).map(toUser);\n\t\t\t\tconst last = items.at(-1);\n\t\t\t\treturn {\n\t\t\t\t\titems,\n\t\t\t\t\tnextCursor:\n\t\t\t\t\t\tfound.length > limit && last !== undefined ? last.id : null,\n\t\t\t\t};\n\t\t\t}),\n\n\t\tupdateUser: (id, patch, ifVersion) =>\n\t\t\trun$('updateUser', () =>\n\t\t\t\twithTransaction(db, (tx) =>\n\t\t\t\t\tupdateUser(tx, tables, id, patch, ifVersion),\n\t\t\t\t),\n\t\t\t),\n\n\t\tdeleteUser: (id) =>\n\t\t\trun$('deleteUser', async () => {\n\t\t\t\t// The logins go with it: their foreign key cascades.\n\t\t\t\tconst deleted = await db\n\t\t\t\t\t.delete(tables.users)\n\t\t\t\t\t.where(eq(tables.users.id, id))\n\t\t\t\t\t.returning({ id: tables.users.id });\n\t\t\t\treturn deleted.length === 1;\n\t\t\t}),\n\t};\n}\n\nasync function findUser(\n\tdb: PgDatabase,\n\ttables: IdentityTables,\n\tid: string,\n): Promise<UserRecord | null> {\n\tconst [row] = await db\n\t\t.select()\n\t\t.from(tables.users)\n\t\t.where(eq(tables.users.id, id));\n\treturn row === undefined ? null : toUser(row);\n}\n\nasync function insertUser(\n\tdb: PgDatabase,\n\ttables: IdentityTables,\n\trecord: UserRecord,\n): Promise<UserRecord> {\n\tconst inserted = await withTransaction(db, async (tx) => {\n\t\tconst [row] = await tx\n\t\t\t.insert(tables.users)\n\t\t\t.values(toUserRow(record))\n\t\t\t.onConflictDoNothing({ target: tables.users.id })\n\t\t\t.returning();\n\t\tif (row === undefined) return null;\n\t\tawait claimLogins(tx, tables, 'insertUser', record, record.logins);\n\t\treturn toUser(row);\n\t});\n\tif (inserted !== null) return inserted;\n\n\t// A retry whose first attempt landed: the user with this id is\n\t// there, and is the answer — logins included, which are theirs.\n\tconst stored = await findUser(db, tables, record.id);\n\tif (stored !== null) return stored;\n\t// Deleted between the two statements: a retry of nothing.\n\tthrow new NotFoundError('insertUser: the user was deleted meanwhile', {\n\t\tuserId: record.id,\n\t\toperation: 'insertUser',\n\t});\n}\n\nasync function updateUser(\n\ttx: PgDatabase,\n\ttables: IdentityTables,\n\tid: string,\n\tpatch: UserPatch,\n\tifVersion: number,\n): Promise<UserRecord> {\n\tconst [row] = await tx\n\t\t.update(tables.users)\n\t\t.set({\n\t\t\t...toUserSet(patch),\n\t\t\tversion: sql`${tables.users.version} + 1`,\n\t\t})\n\t\t.where(and(eq(tables.users.id, id), eq(tables.users.version, ifVersion)))\n\t\t.returning();\n\n\tif (row === undefined) {\n\t\t// The write matched nothing, which alone cannot tell an unknown\n\t\t// id from a moved version: read again, and say which.\n\t\tconst [stored] = await tx\n\t\t\t.select({ version: tables.users.version })\n\t\t\t.from(tables.users)\n\t\t\t.where(eq(tables.users.id, id));\n\t\tif (stored === undefined) {\n\t\t\tthrow new NotFoundError('updateUser: no user has this id', {\n\t\t\t\tuserId: id,\n\t\t\t\toperation: 'updateUser',\n\t\t\t});\n\t\t}\n\t\tthrow new StoreConflict(\n\t\t\t'version',\n\t\t\t`updateUser: expected version ${ifVersion}, found ${stored.version}`,\n\t\t\t{\n\t\t\t\tuserId: id,\n\t\t\t\texpectedVersion: ifVersion,\n\t\t\t\tactualVersion: stored.version,\n\t\t\t\toperation: 'updateUser',\n\t\t\t},\n\t\t);\n\t}\n\n\tif (patch.logins !== undefined) {\n\t\tawait tx.delete(tables.logins).where(eq(tables.logins.userId, id));\n\t\tawait claimLogins(tx, tables, 'updateUser', row, patch.logins);\n\t}\n\treturn toUser(row);\n}\n",
|
|
21
22
|
"import type { PgDatabase } from '@nxgt/drizzle/pg';\nimport { loginTaken } from '../translate';\nimport type { IdentityTables } from './identity-tables';\n\n/**\n * Writes the logins of one user, and throws the port's conflict for the\n * first one another user of the type holds. `on conflict do nothing`: a\n * login the statement did not write is one somebody else holds, and a\n * concurrent sign-up waits for the first to commit, then writes nothing.\n */\nexport async function claimLogins(\n\ttx: PgDatabase,\n\ttables: IdentityTables,\n\toperation: string,\n\tuser: { readonly id: string; readonly type: string },\n\tlogins: readonly string[],\n): Promise<void> {\n\t// Sorted: two transactions claiming the same logins take their locks in\n\t// one order, and never deadlock — the loser waits, then finds them taken.\n\tconst distinct = [...new Set(logins)].sort();\n\tif (distinct.length === 0) return;\n\tconst written = await tx\n\t\t.insert(tables.logins)\n\t\t.values(\n\t\t\tdistinct.map((login) => ({ type: user.type, login, userId: user.id })),\n\t\t)\n\t\t.onConflictDoNothing()\n\t\t.returning({ login: tables.logins.login });\n\tif (written.length === distinct.length) return;\n\tconst claimed = new Set(written.map((row) => row.login));\n\tconst taken = distinct.find((login) => !claimed.has(login)) ?? '';\n\tthrow loginTaken(operation, user.type, taken);\n}\n",
|
|
22
23
|
"import type { PgDatabase } from '@nxgt/drizzle/pg';\nimport type { JanusStores } from '@nxgt/janus';\nimport { type DrizzleAdapterOptions, defineJanusTables } from '../tables';\nimport type { IdentityTable } from './identity-tables';\nimport { sessionStore } from './sessions';\nimport { tokenStore } from './tokens';\nimport { userStore } from './users';\n\n/**\n * The three stores `janus()` takes, over one PostgreSQL database through\n * Drizzle.\n *\n * ```ts\n * const db = drizzle(process.env.DATABASE_URL);\n * const auth = janus({ user, password: { login: 'email' }, store: createDrizzleStores(db), hasher });\n * ```\n *\n * **Every read is one statement**, whose absence is an empty result, turned\n * into `null` here; everything that arrives as a rejection is a failure. There\n * is no path on which an absence and an outage travel the same channel.\n *\n * **A user is written in one transaction** with its logins, whose table holds\n * their uniqueness — `@nxgt/drizzle`'s `withTransaction`, inside the method,\n * as rule 5 allows. Every other write is one statement.\n *\n * `sessions.deleteExpiredSessions` is implemented: PostgreSQL has no TTL, so\n * `auth.collectExpired()` is how lapsed sessions leave the table.\n *\n * `{ tables }` is what your schema file exports; absent, the tables in the\n * connection's `search_path`.\n */\nexport function createDrizzleStores(\n\tdb: PgDatabase,\n\toptions: DrizzleAdapterOptions<IdentityTable> = {},\n): JanusStores {\n\tconst tables = options.tables ?? defineJanusTables();\n\treturn {\n\t\tusers: userStore(db, tables),\n\t\tsessions: sessionStore(db, tables),\n\t\ttokens: tokenStore(db, tables),\n\t};\n}\n",
|
|
23
24
|
"import type { PgDatabase } from '@nxgt/drizzle/pg';\nimport type { JanusStores } from '@nxgt/janus';\nimport type { RelationStore } from '@nxgt/janus/permissions';\nimport { createDrizzleRelations } from './relations';\nimport { createDrizzleStores } from './stores';\nimport type { DrizzleAdapterOptions } from './tables';\n\n/** The whole adapter over one database, keyed as `janus()` takes it. */\nexport interface DrizzleAdapter {\n\t/** The identity stores: `createDrizzleStores(db)`. */\n\treadonly store: JanusStores;\n\t/** The relation store: `createDrizzleRelations(db)`. */\n\treadonly relations: RelationStore;\n}\n\n/**\n * The identity stores and the relation store over one database, under the\n * names `janus()` takes them — so one spread wires both, and deleting a user\n * deletes every tuple naming them:\n *\n * ```ts\n * const postgres = createDrizzleAdapter(db);\n * const auth = janus({ user, password: { login: 'email' }, hasher, ...postgres });\n * const access = permissions({ model, store: postgres.relations });\n * ```\n *\n * It connects to nothing and creates nothing: `db` is your Drizzle instance,\n * and the tables are your migrations'. `{ tables }` is what your schema file\n * exports, needed when they are in a PostgreSQL schema of their own. An\n * application that only authenticates can take `createDrizzleStores(db)` alone.\n */\nexport function createDrizzleAdapter(\n\tdb: PgDatabase,\n\toptions: DrizzleAdapterOptions = {},\n): DrizzleAdapter {\n\treturn {\n\t\tstore: createDrizzleStores(db, options),\n\t\trelations: createDrizzleRelations(db, options),\n\t};\n}\n"
|
|
24
25
|
],
|
|
25
|
-
"mappings": ";AAAA;;;ACAA;;;ACEA;AAUO,IAAM,MAAM,WAAiD;AAAA,EACnE,UAAU,MAAM;AACjB,CAAC;AAKM,IAAM,KAAK,CAAC,SAClB,UAAU,MAAM,EAAE,cAAc,MAAM,WAAW,EAAE,CAAC;;;ADT9C,SAAS,WAAW,CAC1B,OACA,OACC;AAAA,EACD,OAAO,MACN,UACA;AAAA,IACC,MAAM,IAAI,MAAM,EAAE,QAAQ;AAAA,IAC1B,OAAO,IAAI,OAAO,EAAE,QAAQ;AAAA,IAC5B,QAAQ,IAAI,SAAS,EAAE,QAAQ;AAAA,EAChC,GACA,CAAC,MAAM;AAAA,IACN,WAAW,EAAE,MAAM,eAAe,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAAA,IAC9D,WAAW;AAAA,MACV,MAAM;AAAA,MACN,SAAS,CAAC,EAAE,QAAQ,EAAE,IAAI;AAAA,MAC1B,gBAAgB,CAAC,MAAM,IAAI,MAAM,IAAI;AAAA,IACtC,CAAC,EAAE,SAAS,SAAS;AAAA,IACrB,MAAM,gBAAgB,EAAE,GAAG,EAAE,MAAM;AAAA,EACpC,CACD;AAAA;;;AE/BD,kBAAS;AAaF,SAAS,cAAc,C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A,IAC/B,MAAM,GAAG,OAAO,OAAO,MAAM,EAAE,MAAM,IAAG,OAAO,OAAO,QAAQ,EAAE,CAAC;AAAA,IACjE,MAAM,YAAY,IAAI,QAAQ,cAAc,KAAK,MAAM,MAAM;AAAA,EAC9D;AAAA,EACA,OAAO,OAAO,GAAG;AAAA;;;AEzIX,SAAS,mBAAmB,CAClC,IACA,UAAgD,CAAC,GACnC;AAAA,EACd,MAAM,SAAS,QAAQ,UAAU,kBAAkB;AAAA,EACnD,OAAO;AAAA,IACN,OAAO,UAAU,IAAI,MAAM;AAAA,IAC3B,UAAU,aAAa,IAAI,MAAM;AAAA,IACjC,QAAQ,WAAW,IAAI,MAAM;AAAA,EAC9B;AAAA;;;ACTM,SAAS,oBAAoB,CACnC,IACA,UAAiC,CAAC,GACjB;AAAA,EACjB,OAAO;AAAA,IACN,OAAO,oBAAoB,IAAI,OAAO;AAAA,IACtC,WAAW,uBAAuB,IAAI,OAAO;AAAA,EAC9C;AAAA;",
|
|
27
|
+
"debugId": "4769BF1300BE303164756E2164756E21",
|
|
27
28
|
"names": []
|
|
28
29
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PgDatabase } from '@nxgt/drizzle/pg';
|
|
2
|
+
import { type SQL } from 'drizzle-orm';
|
|
3
|
+
import type { PgTable } from 'drizzle-orm/pg-core';
|
|
4
|
+
/**
|
|
5
|
+
* Deletes the rows of `table` matching `where` and answers how many, counted
|
|
6
|
+
* by the server: `with d as (delete … returning 1) select count(*) from d`.
|
|
7
|
+
* A collection can delete millions of rows; none of them reaches the process.
|
|
8
|
+
*/
|
|
9
|
+
export declare function deleteAndCount(db: PgDatabase, table: PgTable, where: SQL | undefined): Promise<number>;
|
|
10
|
+
//# sourceMappingURL=count-deleted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"count-deleted.d.ts","sourceRoot":"","sources":["../../src/stores/count-deleted.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAS,KAAK,GAAG,EAAO,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD;;;;GAIG;AACH,wBAAsB,cAAc,CACnC,EAAE,EAAE,UAAU,EACd,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,GAAG,GAAG,SAAS,GACpB,OAAO,CAAC,MAAM,CAAC,CASjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../src/stores/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../src/stores/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,aAAa,CAAC;AAI/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,wBAAgB,YAAY,CAC3B,EAAE,EAAE,UAAU,EACd,MAAM,EAAE,cAAc,GACpB,YAAY,CAqEd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/stores/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAA8B,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/stores/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAA8B,UAAU,EAAE,MAAM,aAAa,CAAC;AAI1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,wBAAgB,UAAU,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,GAAG,UAAU,CA2D7E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/tables/tokens.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAEvD,4CAA4C;AAC5C,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/tables/tokens.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAEvD,4CAA4C;AAC5C,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwC9C"}
|
package/docs/README.md
CHANGED
|
@@ -7,6 +7,6 @@ give the detail.
|
|
|
7
7
|
| --- | --- |
|
|
8
8
|
| [Wiring the stores and the relations](guide/wiring.md) | You are passing your Drizzle instance to `janus()` and `permissions()`, choosing a driver, or handling what a failure throws |
|
|
9
9
|
| [Where the tables live](guide/database.md) | You are choosing between a database of Janus's own and a PostgreSQL schema in yours, or backing up and restoring Janus's tables |
|
|
10
|
-
| [The tables in your migrations](guide/migrations.md) | You are adding the tables to your schema, generating the migration, upgrading to a version whose tables changed, collecting lapsed sessions, or want to know what the database holds |
|
|
10
|
+
| [The tables in your migrations](guide/migrations.md) | You are adding the tables to your schema, generating the migration, upgrading to a version whose tables changed, collecting lapsed sessions and tokens, or want to know what the database holds |
|
|
11
11
|
| [Troubleshooting](troubleshooting.md) | You have an error message and want its cause and its fix |
|
|
12
12
|
| [Roadmap](roadmap.md) | You want to know what is coming, what shipped, and what is deliberately not planned |
|
package/docs/guide/migrations.md
CHANGED
|
@@ -4,7 +4,7 @@ This page covers:
|
|
|
4
4
|
- adding the five tables to the schema drizzle-kit reads;
|
|
5
5
|
- what the migration creates;
|
|
6
6
|
- upgrading: the migration a new version of the tables needs;
|
|
7
|
-
- collecting lapsed sessions;
|
|
7
|
+
- collecting lapsed sessions and tokens;
|
|
8
8
|
- what the database holds.
|
|
9
9
|
|
|
10
10
|
The core never manages a schema, and the stores create nothing per request.
|
|
@@ -272,21 +272,63 @@ violates check constraint "tokens_kind"`. An instance still on 0.7 writes no
|
|
|
272
272
|
token's `address` holds the new address and `code_hash` the address it
|
|
273
273
|
replaces, keyed by the token's secret.
|
|
274
274
|
|
|
275
|
-
|
|
275
|
+
### To 0.9: an index on `tokens.expires_at`
|
|
276
|
+
|
|
277
|
+
0.9 implements `tokens.deleteExpiredTokens`, so `auth.collectExpired()` now
|
|
278
|
+
deletes lapsed tokens too. The tables gain one index, and **the migration is
|
|
279
|
+
recommended, not required**: the adapter runs without it, but then every
|
|
280
|
+
collection scans the whole `tokens` table.
|
|
281
|
+
|
|
282
|
+
```sql
|
|
283
|
+
CREATE INDEX "tokens_expires_at" ON "tokens" ("expires_at");
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
That is the statement drizzle-kit writes from the 0.8 tables to the 0.9
|
|
287
|
+
ones (`"janus"."tokens"` with a PostgreSQL schema). It rewrites no row, and
|
|
288
|
+
deploys before or after the code: an instance still on 0.8 never deletes a
|
|
289
|
+
token, so the two run side by side. Three things to know:
|
|
290
|
+
|
|
291
|
+
- **Drop a hand-made index first.** The earlier advice was to run
|
|
292
|
+
`create index on tokens (expires_at)` yourself; PostgreSQL named it
|
|
293
|
+
`tokens_expires_at_idx`. drizzle-kit does not know it, so it writes
|
|
294
|
+
`tokens_expires_at` beside it and the table keeps two indexes on one column.
|
|
295
|
+
`drop index tokens_expires_at_idx;` in the same migration (`drop index
|
|
296
|
+
janus.tokens_expires_at_idx;` with a schema of their own).
|
|
297
|
+
- **`CREATE INDEX` blocks writes while it builds**, and sign-ins write to
|
|
298
|
+
`tokens` (the throttles' counts). On a large table, build it off-peak, or
|
|
299
|
+
build it `CONCURRENTLY` yourself, outside the migration, under the exact
|
|
300
|
+
name `tokens_expires_at` (`create index concurrently tokens_expires_at on
|
|
301
|
+
"janus"."tokens" (expires_at);`, schema-qualified when the tables have a
|
|
302
|
+
schema of their own). It cannot run in the migrator's transaction
|
|
303
|
+
(PostgreSQL error 25001). drizzle-kit compares snapshots, not the database,
|
|
304
|
+
so it still writes the plain `CREATE INDEX`, which would fail with
|
|
305
|
+
`relation "tokens_expires_at" already exists`: edit the generated statement
|
|
306
|
+
to `CREATE INDEX IF NOT EXISTS "tokens_expires_at" …`.
|
|
307
|
+
- **The first `collectExpired()` deletes the whole backlog** in one
|
|
308
|
+
statement, every lapsed throttle row since the table was created. Run it
|
|
309
|
+
off-peak the first time.
|
|
310
|
+
|
|
311
|
+
## Collecting lapsed sessions and tokens
|
|
276
312
|
|
|
277
313
|
PostgreSQL has no TTL. A lapsed session is refused on every read, but it stays
|
|
278
|
-
in `sessions` until something deletes it
|
|
279
|
-
deletes every session
|
|
314
|
+
in `sessions` until something deletes it, and so does a lapsed token.
|
|
315
|
+
`auth.collectExpired()` deletes every session and every one-time token whose
|
|
316
|
+
`expiresAt` has passed, and returns how many in all:
|
|
280
317
|
|
|
281
318
|
```ts
|
|
282
319
|
// Hourly, from whatever runs your scheduled jobs.
|
|
283
320
|
const collected = await auth.collectExpired();
|
|
284
|
-
console.info(`janus: ${collected} lapsed sessions deleted`);
|
|
321
|
+
console.info(`janus: ${collected} lapsed sessions and tokens deleted`);
|
|
285
322
|
```
|
|
286
323
|
|
|
287
|
-
`expires_at` is indexed
|
|
288
|
-
|
|
289
|
-
|
|
324
|
+
`expires_at` is indexed on both tables (on `tokens` only once the [0.9
|
|
325
|
+
migration](#to-09-an-index-on-tokensexpires_at) is applied), so each is one
|
|
326
|
+
indexed `delete`. The
|
|
327
|
+
tokens are not few: `@nxgt/janus`'s sign-in throttle adds a row per login
|
|
328
|
+
tried and per 15-minute window, a login nobody holds included, and its mail
|
|
329
|
+
throttle one per flow, address or user and window. A token is deleted spent
|
|
330
|
+
or not, once its `expiresAt` has passed and never before; after that a link
|
|
331
|
+
answers `TOKEN_UNKNOWN` rather than `TOKEN_EXPIRED`.
|
|
290
332
|
|
|
291
333
|
## Reading the tables yourself
|
|
292
334
|
|
package/docs/guide/wiring.md
CHANGED
|
@@ -108,8 +108,8 @@ All three are measured on PostgreSQL 17 and 15 on every CI run.
|
|
|
108
108
|
|
|
109
109
|
Every method of the port is implemented, **including both optional ones**.
|
|
110
110
|
`deleteExpiredSessions`: PostgreSQL has no TTL, so
|
|
111
|
-
`auth.collectExpired()` is how lapsed sessions leave
|
|
112
|
-
The [migrations page](migrations.md#collecting-lapsed-sessions) shows how.
|
|
111
|
+
`auth.collectExpired()` is how lapsed sessions and tokens leave their tables; schedule it.
|
|
112
|
+
The [migrations page](migrations.md#collecting-lapsed-sessions-and-tokens) shows how.
|
|
113
113
|
`findUsers` (since 0.7): one `select … where id in (…)` on the primary key,
|
|
114
114
|
so `auth.<type>.findMany(ids)` reads up to 100 users in one round trip.
|
|
115
115
|
|
package/docs/roadmap.md
CHANGED
|
@@ -36,6 +36,12 @@ Nothing yet.
|
|
|
36
36
|
|
|
37
37
|
## Shipped
|
|
38
38
|
|
|
39
|
+
- **Lapsed tokens collected, v0.9.0** — for `@nxgt/janus` 0.25:
|
|
40
|
+
`tokens.deleteExpiredTokens` is one `delete … where expires_at <= …
|
|
41
|
+
returning`, so `auth.collectExpired()` deletes lapsed tokens, the
|
|
42
|
+
throttles' counts included, beside the sessions. A migration is
|
|
43
|
+
recommended: drizzle-kit writes one `CREATE INDEX` on `tokens.expires_at`,
|
|
44
|
+
and without it the delete scans the table.
|
|
39
45
|
- **Several users in one statement, v0.7.0** — for `@nxgt/janus` 0.18:
|
|
40
46
|
`users.findUsers` is one `select … where id in (…)`, so
|
|
41
47
|
`auth.<type>.findMany(ids)` reads a list of up to 100 ids in one round
|
package/docs/troubleshooting.md
CHANGED
|
@@ -44,7 +44,7 @@ How PostgreSQL's errors become the port's:
|
|
|
44
44
|
- [`STORE_FAILED`: `<slot>.<operation>: the store could not answer`](#store_failed-slotoperation-the-store-could-not-answer)
|
|
45
45
|
- [`LOGIN_TAKEN`: `<operation>: the login is taken by another <type>`](#login_taken-operation-the-login-is-taken-by-another-type)
|
|
46
46
|
- [`NOT_FOUND` / `VERSION_CONFLICT`: `updateUser: …`](#not_found--version_conflict-updateuser-)
|
|
47
|
-
- [The `sessions` table keeps growing](#the-sessions-table-keeps-growing)
|
|
47
|
+
- [The `sessions` or `tokens` table keeps growing](#the-sessions-or-tokens-table-keeps-growing)
|
|
48
48
|
- [`NOT_FOUND`: `insertUser: the user was deleted meanwhile`](#not_found-insertuser-the-user-was-deleted-meanwhile)
|
|
49
49
|
|
|
50
50
|
---
|
|
@@ -364,14 +364,17 @@ written.
|
|
|
364
364
|
|
|
365
365
|
**Fix:** read the user again and retry, or tell the user it changed meanwhile.
|
|
366
366
|
|
|
367
|
-
### The `sessions` table keeps growing
|
|
367
|
+
### The `sessions` or `tokens` table keeps growing
|
|
368
368
|
|
|
369
|
-
**When:** rows whose `expires_at` has passed are never deleted.
|
|
369
|
+
**When:** rows whose `expires_at` has passed are never deleted. In `tokens`
|
|
370
|
+
they are mostly the throttles' counts: a row per login tried and per window.
|
|
370
371
|
|
|
371
372
|
**Why:** PostgreSQL has no TTL. The core refuses a lapsed session on every
|
|
372
|
-
read, but deleting it
|
|
373
|
+
read, but deleting it, and deleting a lapsed token, is
|
|
374
|
+
`auth.collectExpired()`'s job.
|
|
373
375
|
|
|
374
|
-
**Fix:** schedule it.
|
|
376
|
+
**Fix:** schedule it. If the delete is slow, `tokens` lacks its
|
|
377
|
+
`tokens_expires_at` index: [To 0.9](guide/migrations.md#to-09-an-index-on-tokensexpires_at).
|
|
375
378
|
|
|
376
379
|
```ts
|
|
377
380
|
const collected = await auth.collectExpired(); // hourly
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxgt/janus-drizzle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "The PostgreSQL adapter for @nxgt/janus on Drizzle and @nxgt/drizzle: users, sessions, one-time tokens and permission tuples",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@electric-sql/pglite": "0.5.8",
|
|
53
53
|
"@nxgt/drizzle": "0.6.5",
|
|
54
|
-
"@nxgt/janus": "^0.
|
|
54
|
+
"@nxgt/janus": "^0.25.0",
|
|
55
55
|
"@types/bun": "^1.4.2",
|
|
56
56
|
"@types/pg": "^8.23.1",
|
|
57
57
|
"drizzle-kit": "1.0.0-rc.4",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"@nxgt/drizzle": ">=0.6.1 <1",
|
|
65
|
-
"@nxgt/janus": "^0.
|
|
65
|
+
"@nxgt/janus": "^0.25.0",
|
|
66
66
|
"drizzle-orm": ">=1.0.0-rc.4 <2",
|
|
67
67
|
"typescript": "^6.0.3 || ^7.0.0"
|
|
68
68
|
}
|