@guren/core 1.8.0 → 1.8.1

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/index.js CHANGED
@@ -1,300 +1,355 @@
1
- // src/index.ts
2
- export * from "@guren/server";
3
- import {
4
- Model as Model4,
5
- defineModel,
6
- ModelNotFoundException,
7
- MassAssignmentException,
8
- QueryBuilder,
9
- SoftDeletes,
10
- DrizzleAdapter,
11
- createPostgresDatabase,
12
- createMySqlDatabase,
13
- createSqliteDatabase,
14
- createD1Database,
15
- createAwsDataApiDatabase,
16
- runSeeders,
17
- defineSeeder
18
- } from "@guren/orm";
19
-
20
- // src/api-token-store.ts
21
- import { Model } from "@guren/orm";
22
-
23
- // src/store-utils.ts
1
+ import { DrizzleAdapter, MassAssignmentException, Model, Model as Model$1, ModelNotFoundException, QueryBuilder, SoftDeletes, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, runSeeders } from "@guren/orm";
24
2
  import { isExpired, toDate, toOptionalExpiry } from "@guren/server/support/expiry";
3
+ export * from "@guren/server";
4
+ //#region src/store-utils.ts
5
+ /**
6
+ * Decode a JSON-capable column that may hold either the native value
7
+ * (drizzle json mode) or a text-encoded string. Corrupt text falls back
8
+ * instead of throwing, so one bad row cannot break every read.
9
+ *
10
+ * Stays here: it is a drizzle column concern, and the Redis stores decode
11
+ * their own JSON payloads through `redis-values.ts` instead.
12
+ */
25
13
  function decodeJsonColumn(value, fallback) {
26
- if (typeof value === "string") {
27
- try {
28
- return JSON.parse(value);
29
- } catch {
30
- return fallback;
31
- }
32
- }
33
- return value ?? fallback;
14
+ if (typeof value === "string") try {
15
+ return JSON.parse(value);
16
+ } catch {
17
+ return fallback;
18
+ }
19
+ return value ?? fallback;
34
20
  }
35
-
36
- // src/api-token-store.ts
21
+ //#endregion
22
+ //#region src/api-token-store.ts
23
+ /**
24
+ * Database-backed API token store built on the Guren ORM.
25
+ *
26
+ * Pass the Drizzle table for your `api_tokens` schema. Column property
27
+ * names must match the {@link ApiToken} fields (`id`, `name`,
28
+ * `hashedToken`, `userId`, `abilities`, `lastUsedAt`, `expiresAt`,
29
+ * `createdAt`). The ORM must be configured (the standard
30
+ * `DatabaseProvider` setup) before the store is used.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { DatabaseApiTokenStore, createApiToken } from '@guren/core'
35
+ * import { apiTokens } from '@/db/schema'
36
+ *
37
+ * const store = new DatabaseApiTokenStore(apiTokens)
38
+ *
39
+ * const { plainTextToken } = await createApiToken(store, {
40
+ * name: 'Mobile App Token',
41
+ * userId: user.id,
42
+ * })
43
+ * ```
44
+ */
37
45
  var DatabaseApiTokenStore = class {
38
- model;
39
- abilitiesMode;
40
- constructor(table, options = {}) {
41
- this.abilitiesMode = options.abilitiesMode ?? "json";
42
- this.model = class ApiTokenModel extends Model {
43
- static table = table;
44
- };
45
- }
46
- async store(token) {
47
- await this.model.forceCreate({
48
- ...token,
49
- abilities: this.abilitiesMode === "text" ? JSON.stringify(token.abilities) : token.abilities
50
- });
51
- }
52
- async findByHashedToken(hashedToken) {
53
- const record = await this.model.where({ hashedToken }).first();
54
- return record ? this.deserialize(record) : null;
55
- }
56
- async findByUserId(userId) {
57
- const records = await this.model.where({ userId }).get();
58
- return records.map((record) => this.deserialize(record));
59
- }
60
- async delete(id) {
61
- await this.model.where({ id }).delete();
62
- }
63
- async deleteForUser(userId) {
64
- await this.model.where({ userId }).delete();
65
- }
66
- async updateLastUsed(id, timestamp) {
67
- await this.model.forceUpdate({ id }, { lastUsedAt: timestamp });
68
- }
69
- /**
70
- * Delete tokens whose expiration time has passed. Expired tokens are
71
- * already rejected by `verifyApiToken`; call this from a scheduled
72
- * job to keep the table small.
73
- */
74
- async deleteExpired(now = /* @__PURE__ */ new Date()) {
75
- await this.model.where("expiresAt", "<", now).delete();
76
- }
77
- // Not replaceable with `static casts`: QueryBuilder reads (`where().first()/.get()`)
78
- // bypass model casts, and cast-based writes would fight drizzle column modes
79
- // (Date → ISO string breaks timestamp columns; json-stringify double-encodes jsonb).
80
- deserialize(record) {
81
- const abilities = decodeJsonColumn(record.abilities, []);
82
- return {
83
- id: String(record.id),
84
- name: String(record.name),
85
- hashedToken: String(record.hashedToken),
86
- userId: typeof record.userId === "bigint" ? record.userId.toString() : record.userId,
87
- // Corrupt text degrades to no abilities (deny-by-default) instead of
88
- // throwing on every verification of the affected token. A value that
89
- // decodes to something other than a list of strings degrades the same
90
- // way: `tokenCan` would otherwise run `String.prototype.includes` on it,
91
- // so a stored `'"*"'` would grant every ability.
92
- abilities: Array.isArray(abilities) ? abilities.filter((ability) => typeof ability === "string") : [],
93
- lastUsedAt: toDate(record.lastUsedAt),
94
- // Null means "never expires"; a present-but-unparseable value means a
95
- // malformed row, which must not read as immortal (`verifyApiToken`
96
- // skips its expiry check entirely when this is null).
97
- expiresAt: toOptionalExpiry(record.expiresAt),
98
- createdAt: toDate(record.createdAt) ?? /* @__PURE__ */ new Date(0)
99
- };
100
- }
46
+ model;
47
+ abilitiesMode;
48
+ constructor(table, options = {}) {
49
+ this.abilitiesMode = options.abilitiesMode ?? "json";
50
+ this.model = class ApiTokenModel extends Model$1 {
51
+ static table = table;
52
+ };
53
+ }
54
+ async store(token) {
55
+ await this.model.forceCreate({
56
+ ...token,
57
+ abilities: this.abilitiesMode === "text" ? JSON.stringify(token.abilities) : token.abilities
58
+ });
59
+ }
60
+ async findByHashedToken(hashedToken) {
61
+ const record = await this.model.where({ hashedToken }).first();
62
+ return record ? this.deserialize(record) : null;
63
+ }
64
+ async findByUserId(userId) {
65
+ return (await this.model.where({ userId }).get()).map((record) => this.deserialize(record));
66
+ }
67
+ async delete(id) {
68
+ await this.model.where({ id }).delete();
69
+ }
70
+ async deleteForUser(userId) {
71
+ await this.model.where({ userId }).delete();
72
+ }
73
+ async updateLastUsed(id, timestamp) {
74
+ await this.model.forceUpdate({ id }, { lastUsedAt: timestamp });
75
+ }
76
+ /**
77
+ * Delete tokens whose expiration time has passed. Expired tokens are
78
+ * already rejected by `verifyApiToken`; call this from a scheduled
79
+ * job to keep the table small.
80
+ */
81
+ async deleteExpired(now = /* @__PURE__ */ new Date()) {
82
+ await this.model.where("expiresAt", "<", now).delete();
83
+ }
84
+ deserialize(record) {
85
+ const abilities = decodeJsonColumn(record.abilities, []);
86
+ return {
87
+ id: String(record.id),
88
+ name: String(record.name),
89
+ hashedToken: String(record.hashedToken),
90
+ userId: typeof record.userId === "bigint" ? record.userId.toString() : record.userId,
91
+ abilities: Array.isArray(abilities) ? abilities.filter((ability) => typeof ability === "string") : [],
92
+ lastUsedAt: toDate(record.lastUsedAt),
93
+ expiresAt: toOptionalExpiry(record.expiresAt),
94
+ createdAt: toDate(record.createdAt) ?? /* @__PURE__ */ new Date(0)
95
+ };
96
+ }
101
97
  };
102
-
103
- // src/session-store.ts
104
- import { Model as Model2 } from "@guren/orm";
98
+ //#endregion
99
+ //#region src/session-store.ts
100
+ /**
101
+ * Database-backed session store built on the Guren ORM — works on any
102
+ * configured connection (SQLite, Postgres, MySQL, or Cloudflare D1), which
103
+ * makes it the serverless default: no Redis required on Lambda, Vercel, or
104
+ * Workers, and reads are strongly consistent (login → redirect → read works).
105
+ *
106
+ * Pass the Drizzle table for your `sessions` schema. Column property names
107
+ * must match `id` (text primary key), `data`, and `expiresAt`:
108
+ *
109
+ * ```ts
110
+ * export const sessions = sqliteTable('sessions', {
111
+ * id: text('id').primaryKey(),
112
+ * data: text('data', { mode: 'json' }).$type<Record<string, unknown>>().notNull(),
113
+ * expiresAt: integer('expires_at', { mode: 'timestamp_ms' }).notNull(),
114
+ * })
115
+ * ```
116
+ *
117
+ * Session values must be JSON-serializable: Dates come back as ISO strings,
118
+ * `undefined` properties are dropped, and `bigint` values fail to serialize —
119
+ * unlike `MemorySessionStore`, which keeps live references. Store primitives
120
+ * and plain objects/arrays in sessions.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * import { DatabaseSessionStore } from '@guren/core'
125
+ * import { sessions } from '@/db/schema'
126
+ *
127
+ * app.use(createSessionMiddleware({ store: new DatabaseSessionStore(sessions) }))
128
+ * ```
129
+ */
105
130
  var DatabaseSessionStore = class {
106
- model;
107
- dataMode;
108
- constructor(table, options = {}) {
109
- this.dataMode = options.dataMode ?? "json";
110
- this.model = class SessionModel extends Model2 {
111
- static table = table;
112
- };
113
- }
114
- async read(id) {
115
- const record = await this.model.where({ id }).first();
116
- if (!record) {
117
- return void 0;
118
- }
119
- if (isExpired(record.expiresAt)) {
120
- await this.model.where({ id, expiresAt: record.expiresAt }).delete();
121
- return void 0;
122
- }
123
- return this.deserialize(record);
124
- }
125
- async write(id, data, ttlSeconds) {
126
- const payload = {
127
- data: this.dataMode === "text" ? JSON.stringify(data) : data,
128
- expiresAt: this.expiryDate(ttlSeconds)
129
- };
130
- const existing = await this.model.where({ id }).first();
131
- if (existing) {
132
- await this.model.forceUpdate({ id }, payload);
133
- return;
134
- }
135
- try {
136
- await this.model.forceCreate({ id, ...payload });
137
- } catch (error) {
138
- const nowExists = await this.model.where({ id }).first();
139
- if (!nowExists) {
140
- throw error;
141
- }
142
- await this.model.forceUpdate({ id }, payload);
143
- }
144
- }
145
- async destroy(id) {
146
- await this.model.where({ id }).delete();
147
- }
148
- /**
149
- * Refresh an existing session's TTL with a single conditional UPDATE — no
150
- * data rewrite, no existence check. Missing rows and rows that have
151
- * already expired (but not yet been swept) are left untouched, never
152
- * resurrected — matching the `SessionStore.touch` contract and the memory
153
- * store's behavior.
154
- */
155
- async touch(id, ttlSeconds) {
156
- await this.model.where({ id }).where("expiresAt", ">", /* @__PURE__ */ new Date()).forceUpdate({ expiresAt: this.expiryDate(ttlSeconds) });
157
- }
158
- /**
159
- * Delete sessions whose expiration time has passed. Expired rows are
160
- * already treated as missing (and removed) by `read`; call this from a
161
- * scheduled job to keep the table small.
162
- */
163
- async deleteExpired(now = /* @__PURE__ */ new Date()) {
164
- await this.model.where("expiresAt", "<=", now).delete();
165
- }
166
- deserialize(record) {
167
- return decodeJsonColumn(record.data, {});
168
- }
169
- expiryDate(ttlSeconds) {
170
- return new Date(Date.now() + ttlSeconds * 1e3);
171
- }
131
+ model;
132
+ dataMode;
133
+ constructor(table, options = {}) {
134
+ this.dataMode = options.dataMode ?? "json";
135
+ this.model = class SessionModel extends Model$1 {
136
+ static table = table;
137
+ };
138
+ }
139
+ async read(id) {
140
+ const record = await this.model.where({ id }).first();
141
+ if (!record) return;
142
+ if (isExpired(record.expiresAt)) {
143
+ await this.model.where({
144
+ id,
145
+ expiresAt: record.expiresAt
146
+ }).delete();
147
+ return;
148
+ }
149
+ return this.deserialize(record);
150
+ }
151
+ async write(id, data, ttlSeconds) {
152
+ const payload = {
153
+ data: this.dataMode === "text" ? JSON.stringify(data) : data,
154
+ expiresAt: this.expiryDate(ttlSeconds)
155
+ };
156
+ if (await this.model.where({ id }).first()) {
157
+ await this.model.forceUpdate({ id }, payload);
158
+ return;
159
+ }
160
+ try {
161
+ await this.model.forceCreate({
162
+ id,
163
+ ...payload
164
+ });
165
+ } catch (error) {
166
+ if (!await this.model.where({ id }).first()) throw error;
167
+ await this.model.forceUpdate({ id }, payload);
168
+ }
169
+ }
170
+ async destroy(id) {
171
+ await this.model.where({ id }).delete();
172
+ }
173
+ /**
174
+ * Refresh an existing session's TTL with a single conditional UPDATE — no
175
+ * data rewrite, no existence check. Missing rows and rows that have
176
+ * already expired (but not yet been swept) are left untouched, never
177
+ * resurrected — matching the `SessionStore.touch` contract and the memory
178
+ * store's behavior.
179
+ */
180
+ async touch(id, ttlSeconds) {
181
+ await this.model.where({ id }).where("expiresAt", ">", /* @__PURE__ */ new Date()).forceUpdate({ expiresAt: this.expiryDate(ttlSeconds) });
182
+ }
183
+ /**
184
+ * Delete sessions whose expiration time has passed. Expired rows are
185
+ * already treated as missing (and removed) by `read`; call this from a
186
+ * scheduled job to keep the table small.
187
+ */
188
+ async deleteExpired(now = /* @__PURE__ */ new Date()) {
189
+ await this.model.where("expiresAt", "<=", now).delete();
190
+ }
191
+ deserialize(record) {
192
+ return decodeJsonColumn(record.data, {});
193
+ }
194
+ expiryDate(ttlSeconds) {
195
+ return new Date(Date.now() + ttlSeconds * 1e3);
196
+ }
172
197
  };
173
-
174
- // src/oauth-state-store.ts
175
- import { Model as Model3 } from "@guren/orm";
198
+ //#endregion
199
+ //#region src/oauth-state-store.ts
200
+ /**
201
+ * Database-backed OAuth state store built on the Guren ORM.
202
+ *
203
+ * The default `MemoryOAuthStateStore` keeps state in per-isolate memory,
204
+ * which breaks on serverless: the OAuth authorize redirect and the callback
205
+ * that follows it can land on different instances, so an in-memory map
206
+ * never sees the state that was just written. Backing the store with the
207
+ * database makes state visible to whichever instance handles the callback.
208
+ *
209
+ * Pass the Drizzle table for your `oauth_states` schema. Column property
210
+ * names must match `stateHash` (text primary key), `provider`,
211
+ * `redirectTo`, `expiresAt`, and `binding`:
212
+ *
213
+ * ```ts
214
+ * export const oauthStates = sqliteTable('oauth_states', {
215
+ * stateHash: text('state_hash').primaryKey(),
216
+ * provider: text('provider').notNull(),
217
+ * redirectTo: text('redirect_to'),
218
+ * expiresAt: integer('expires_at', { mode: 'timestamp_ms' }).notNull(),
219
+ * binding: text('binding'),
220
+ * })
221
+ * ```
222
+ *
223
+ * `binding` is required for `authorize({ bindTo })` to survive the round trip
224
+ * to the provider. Without the column the store cannot persist it, and every
225
+ * bound state comes back unbound.
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * import { createOAuthManager, DatabaseOAuthStateStore } from '@guren/core'
230
+ * import { oauthStates } from '@/db/schema'
231
+ *
232
+ * export const oauth = createOAuthManager({
233
+ * stateStore: new DatabaseOAuthStateStore(oauthStates),
234
+ * })
235
+ * ```
236
+ */
176
237
  var DatabaseOAuthStateStore = class {
177
- model;
178
- constructor(table) {
179
- this.model = class OAuthStateModel extends Model3 {
180
- static table = table;
181
- };
182
- }
183
- async store(stateHash, payload) {
184
- await this.model.forceCreate({
185
- stateHash,
186
- provider: payload.provider,
187
- redirectTo: payload.redirectTo ?? null,
188
- expiresAt: payload.expiresAt,
189
- // Persisted, not derived: an unbound state verifies for any browser.
190
- binding: payload.binding ?? null
191
- });
192
- }
193
- async find(stateHash) {
194
- const record = await this.fetchLive(stateHash);
195
- return record ? mapRecordToPayload(record) : null;
196
- }
197
- /**
198
- * Fetch the row for `stateHash`, clearing it out and returning null if
199
- * expired. Shared by `find` and `consume`, which otherwise diverge only
200
- * in what they do with a live row.
201
- */
202
- async fetchLive(stateHash) {
203
- const record = await this.model.where({ stateHash }).first();
204
- if (!record) {
205
- return null;
206
- }
207
- if (isExpired(record.expiresAt)) {
208
- await this.model.where({ stateHash, expiresAt: record.expiresAt }).delete();
209
- return null;
210
- }
211
- return record;
212
- }
213
- async delete(stateHash) {
214
- await this.model.where({ stateHash }).delete();
215
- }
216
- /**
217
- * Atomically fetch and delete a state, guaranteeing exactly one concurrent
218
- * caller for the same hash receives the payload.
219
- *
220
- * This guarantee depends on the configured ORM adapter's `delete()`
221
- * reporting whether a row actually matched — either the deleted row
222
- * (RETURNING) or an affected-row count. `DrizzleAdapter`, the framework's
223
- * default and only shipped adapter, always does this: RETURNING drivers
224
- * (Postgres, SQLite, D1) resolve to the deleted row or `undefined` only
225
- * when zero rows matched; MySQL resolves to a result carrying
226
- * `affectedRows` (verified by inspection, not a dedicated test).
227
- *
228
- * The `ORMAdapter.delete` contract also permits a bare `void` return.
229
- * A custom adapter (via `Model.useAdapter()`) that returns `void`
230
- * unconditionally — on both a successful delete and a no-op — gives
231
- * `consume()` no way to tell which caller won: the value is identical for
232
- * both, so no post-hoc check can attribute the deletion. Rather than
233
- * silently rejecting every real login for such adapters,
234
- * `deleteRemovedRow` treats an unrecognized non-null result as removed —
235
- * this reopens the pre-consume find-then-delete race window (multiple
236
- * concurrent callers can pass) for adapters that can't report a match,
237
- * but does not break login. It is fail-closed (returns null / rejects)
238
- * only for `null`/`undefined`, DrizzleAdapter's definitive "no rows
239
- * matched" signal.
240
- */
241
- async consume(stateHash) {
242
- const record = await this.fetchLive(stateHash);
243
- if (!record) {
244
- return null;
245
- }
246
- const result = await this.model.where({ stateHash, expiresAt: record.expiresAt }).delete();
247
- return deleteRemovedRow(result) ? mapRecordToPayload(record) : null;
248
- }
249
- /**
250
- * Delete OAuth states whose expiration time has passed. Expired states
251
- * are already rejected by `find`; call this from a scheduled job to keep
252
- * the table small.
253
- */
254
- async deleteExpired(now = /* @__PURE__ */ new Date()) {
255
- await this.model.where("expiresAt", "<=", now).delete();
256
- }
238
+ model;
239
+ constructor(table) {
240
+ this.model = class OAuthStateModel extends Model$1 {
241
+ static table = table;
242
+ };
243
+ }
244
+ async store(stateHash, payload) {
245
+ await this.model.forceCreate({
246
+ stateHash,
247
+ provider: payload.provider,
248
+ redirectTo: payload.redirectTo ?? null,
249
+ expiresAt: payload.expiresAt,
250
+ binding: payload.binding ?? null
251
+ });
252
+ }
253
+ async find(stateHash) {
254
+ const record = await this.fetchLive(stateHash);
255
+ return record ? mapRecordToPayload(record) : null;
256
+ }
257
+ /**
258
+ * Fetch the row for `stateHash`, clearing it out and returning null if
259
+ * expired. Shared by `find` and `consume`, which otherwise diverge only
260
+ * in what they do with a live row.
261
+ */
262
+ async fetchLive(stateHash) {
263
+ const record = await this.model.where({ stateHash }).first();
264
+ if (!record) return null;
265
+ if (isExpired(record.expiresAt)) {
266
+ await this.model.where({
267
+ stateHash,
268
+ expiresAt: record.expiresAt
269
+ }).delete();
270
+ return null;
271
+ }
272
+ return record;
273
+ }
274
+ async delete(stateHash) {
275
+ await this.model.where({ stateHash }).delete();
276
+ }
277
+ /**
278
+ * Atomically fetch and delete a state, guaranteeing exactly one concurrent
279
+ * caller for the same hash receives the payload.
280
+ *
281
+ * This guarantee depends on the configured ORM adapter's `delete()`
282
+ * reporting whether a row actually matched — either the deleted row
283
+ * (RETURNING) or an affected-row count. `DrizzleAdapter`, the framework's
284
+ * default and only shipped adapter, always does this: RETURNING drivers
285
+ * (Postgres, SQLite, D1) resolve to the deleted row or `undefined` only
286
+ * when zero rows matched; MySQL resolves to a result carrying
287
+ * `affectedRows` (verified by inspection, not a dedicated test).
288
+ *
289
+ * The `ORMAdapter.delete` contract also permits a bare `void` return.
290
+ * A custom adapter (via `Model.useAdapter()`) that returns `void`
291
+ * unconditionally — on both a successful delete and a no-op — gives
292
+ * `consume()` no way to tell which caller won: the value is identical for
293
+ * both, so no post-hoc check can attribute the deletion. Rather than
294
+ * silently rejecting every real login for such adapters,
295
+ * `deleteRemovedRow` treats an unrecognized non-null result as removed —
296
+ * this reopens the pre-consume find-then-delete race window (multiple
297
+ * concurrent callers can pass) for adapters that can't report a match,
298
+ * but does not break login. It is fail-closed (returns null / rejects)
299
+ * only for `null`/`undefined`, DrizzleAdapter's definitive "no rows
300
+ * matched" signal.
301
+ */
302
+ async consume(stateHash) {
303
+ const record = await this.fetchLive(stateHash);
304
+ if (!record) return null;
305
+ return deleteRemovedRow(await this.model.where({
306
+ stateHash,
307
+ expiresAt: record.expiresAt
308
+ }).delete()) ? mapRecordToPayload(record) : null;
309
+ }
310
+ /**
311
+ * Delete OAuth states whose expiration time has passed. Expired states
312
+ * are already rejected by `find`; call this from a scheduled job to keep
313
+ * the table small.
314
+ */
315
+ async deleteExpired(now = /* @__PURE__ */ new Date()) {
316
+ await this.model.where("expiresAt", "<=", now).delete();
317
+ }
257
318
  };
319
+ /**
320
+ * Build the public payload from a live (non-expired) row. Shared by `find`
321
+ * and `consume` so the column-to-payload mapping only lives in one place.
322
+ */
258
323
  function mapRecordToPayload(record) {
259
- return {
260
- provider: String(record.provider),
261
- redirectTo: record.redirectTo == null ? void 0 : String(record.redirectTo),
262
- // fetchLive's isExpired check guarantees this parses.
263
- expiresAt: toDate(record.expiresAt),
264
- binding: record.binding == null ? void 0 : String(record.binding)
265
- };
324
+ return {
325
+ provider: String(record.provider),
326
+ redirectTo: record.redirectTo == null ? void 0 : String(record.redirectTo),
327
+ expiresAt: toDate(record.expiresAt),
328
+ binding: record.binding == null ? void 0 : String(record.binding)
329
+ };
266
330
  }
331
+ /**
332
+ * Interpret an adapter delete result as "this call removed the row". See
333
+ * the `consume()` JSDoc above for the full adapter-support tradeoff: this
334
+ * is exact for DrizzleAdapter, and best-effort (assume removed) for any
335
+ * other result shape, since a bare `void` return carries no information to
336
+ * confirm or refute a match.
337
+ */
267
338
  function deleteRemovedRow(result) {
268
- if (result == null) return false;
269
- if (typeof result === "number") return result > 0;
270
- if (Array.isArray(result)) {
271
- return result.length > 0 && deleteRemovedRow(result[0]);
272
- }
273
- if (typeof result === "object") {
274
- const record = result;
275
- for (const key of ["affectedRows", "rowsAffected", "rowCount", "changes"]) {
276
- if (typeof record[key] === "number") return record[key] > 0;
277
- }
278
- return true;
279
- }
280
- return Boolean(result);
339
+ if (result == null) return false;
340
+ if (typeof result === "number") return result > 0;
341
+ if (Array.isArray(result)) return result.length > 0 && deleteRemovedRow(result[0]);
342
+ if (typeof result === "object") {
343
+ const record = result;
344
+ for (const key of [
345
+ "affectedRows",
346
+ "rowsAffected",
347
+ "rowCount",
348
+ "changes"
349
+ ]) if (typeof record[key] === "number") return record[key] > 0;
350
+ return true;
351
+ }
352
+ return Boolean(result);
281
353
  }
282
- export {
283
- DatabaseApiTokenStore,
284
- DatabaseOAuthStateStore,
285
- DatabaseSessionStore,
286
- DrizzleAdapter,
287
- MassAssignmentException,
288
- Model4 as Model,
289
- ModelNotFoundException,
290
- QueryBuilder,
291
- SoftDeletes,
292
- createAwsDataApiDatabase,
293
- createD1Database,
294
- createMySqlDatabase,
295
- createPostgresDatabase,
296
- createSqliteDatabase,
297
- defineModel,
298
- defineSeeder,
299
- runSeeders
300
- };
354
+ //#endregion
355
+ export { DatabaseApiTokenStore, DatabaseOAuthStateStore, DatabaseSessionStore, DrizzleAdapter, MassAssignmentException, Model, ModelNotFoundException, QueryBuilder, SoftDeletes, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, runSeeders };