@getstrata/core 2.2.42 → 2.2.43
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/CHANGELOG.md +6 -0
- package/dist/core/database/transaction.d.ts +6 -1
- package/dist/core/events/deferredModelEvents.d.ts +4 -1
- package/dist/entries/audit/exportAuditLogs.js +10 -3
- package/dist/entries/auth/basicAuthGuard.js +10 -3
- package/dist/entries/auth/oauth/samlProvider.js +10 -3
- package/dist/entries/auth/oneTimeToken.js +2 -2
- package/dist/entries/auth/saml/samlServiceProvider.js +10 -3
- package/dist/entries/auth/scimAuthMiddleware.js +10 -3
- package/dist/entries/jobs/exportAuditLogsJob.js +10 -3
- package/dist/entries/queue/queueMetrics.js +10 -3
- package/dist/entries/tenant/databaseTenantContext.js +10 -3
- package/dist/entries/tenant/tenantDatabaseScope.js +10 -3
- package/dist/framework/public-api.d.ts +1 -1
- package/dist/index.js +19 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @getstrata/core changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.43
|
|
4
|
+
|
|
5
|
+
Add `afterCommit` for process-local effects after the outermost managed transaction, sharing savepoint rollback and tenant replay with model events. Generated auth SMTP uses this boundary even inside RLS request transactions; callback failures propagate after commit without undoing persisted accounts. Durable delivery still requires the SQL outbox.
|
|
6
|
+
|
|
7
|
+
Fix MySQL verification/reset and session-revocation timestamps through the shared SQL dialect; make signup account and verification-token persistence atomic with SMTP after commit; initialize no-tenancy seed connections; add installed starter auth/SMTP/MFA/rollback journeys for every database and frontend, plus generated TypeScript profiles.
|
|
8
|
+
|
|
3
9
|
## 2.2.42
|
|
4
10
|
|
|
5
11
|
Generate auth JSON and forms with explicit private, no-store cache policy. Add privateJsonResponse and typed view namespace header defaults while preserving normal public defaults, native cookies, per-response overrides and HTMX representation behavior. Cover packed APIs and actual generated cookie/token/JWT/CSRF/profile/form HTTP responses.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { afterCommit } from "../events/deferredModelEvents.ts";
|
|
1
2
|
import { type TransactionAcquisitionMetrics } from "./acquisitionMetrics.ts";
|
|
2
3
|
import type { DatabaseConnection } from "./baseRepository.ts";
|
|
3
4
|
import { hasActiveTransaction, requestTransactionRollback } from "./transactionControl.ts";
|
|
@@ -15,4 +16,8 @@ declare function runInTransaction<TValue>(operation: (connection: DatabaseConnec
|
|
|
15
16
|
export type { TransactionAcquisitionMetrics, TransactionAcquisitionSnapshot, } from "./acquisitionMetrics.ts";
|
|
16
17
|
export { createTransactionAcquisitionMetrics, renderTransactionAcquisitionMetrics, } from "./acquisitionMetrics.ts";
|
|
17
18
|
export type { TransactionOptions };
|
|
18
|
-
|
|
19
|
+
/** Register process-local work for the successful outermost commit. Awaiting
|
|
20
|
+
* registration does not execute it early inside an active transaction. Outside
|
|
21
|
+
* a managed transaction it runs immediately. Failure propagates after commit;
|
|
22
|
+
* committed writes cannot roll back. Use the SQL outbox for durable delivery. */
|
|
23
|
+
export { afterCommit, hasActiveTransaction, isActiveTransactionConnection, requestTransactionRollback, runInTransaction, };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
declare function dispatchModelEvent(event: string, payload: unknown): Promise<void>;
|
|
2
|
+
/** Internal queue shared with model events so savepoint rollback and tenant replay
|
|
3
|
+
* follow exactly the same transaction boundary. This is not durable delivery. */
|
|
4
|
+
declare function afterCommit(callback: () => void | Promise<void>): Promise<void>;
|
|
2
5
|
declare function runWithDeferredModelEvents<T>(callback: () => T | Promise<T>): Promise<T>;
|
|
3
6
|
declare function onDeferredModelRollback(callback: () => void): void;
|
|
4
|
-
export { dispatchModelEvent, onDeferredModelRollback, runWithDeferredModelEvents };
|
|
7
|
+
export { afterCommit, dispatchModelEvent, onDeferredModelRollback, runWithDeferredModelEvents };
|
|
@@ -279,7 +279,7 @@ function groupQueuedModelEvents(queued) {
|
|
|
279
279
|
for (const item of queued) {
|
|
280
280
|
const lastGroup = groups[groups.length - 1];
|
|
281
281
|
const last = lastGroup?.[lastGroup.length - 1];
|
|
282
|
-
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
|
|
282
|
+
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
|
|
283
283
|
groups.push([item]);
|
|
284
284
|
} else {
|
|
285
285
|
lastGroup.push(item);
|
|
@@ -289,7 +289,10 @@ function groupQueuedModelEvents(queued) {
|
|
|
289
289
|
}
|
|
290
290
|
async function dispatchEventBatch(batch) {
|
|
291
291
|
for (const item of batch) {
|
|
292
|
-
|
|
292
|
+
if ("callback" in item)
|
|
293
|
+
await item.callback();
|
|
294
|
+
else
|
|
295
|
+
await eventBus.dispatch(item.event, item.payload);
|
|
293
296
|
}
|
|
294
297
|
}
|
|
295
298
|
async function dispatchQueuedModelEvents(queued) {
|
|
@@ -300,7 +303,11 @@ async function dispatchQueuedModelEvents(queued) {
|
|
|
300
303
|
for (const batch of groupQueuedModelEvents(queued)) {
|
|
301
304
|
const tenant = batch[0]?.tenant ?? null;
|
|
302
305
|
if (tenant) {
|
|
303
|
-
|
|
306
|
+
if (batch.some((item) => ("callback" in item))) {
|
|
307
|
+
await runWithTenant(tenant, () => dispatchEventBatch(batch));
|
|
308
|
+
} else {
|
|
309
|
+
await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
|
|
310
|
+
}
|
|
304
311
|
} else {
|
|
305
312
|
await dispatchEventBatch(batch);
|
|
306
313
|
}
|
|
@@ -336,7 +336,7 @@ function groupQueuedModelEvents(queued) {
|
|
|
336
336
|
for (const item of queued) {
|
|
337
337
|
const lastGroup = groups[groups.length - 1];
|
|
338
338
|
const last = lastGroup?.[lastGroup.length - 1];
|
|
339
|
-
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
|
|
339
|
+
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
|
|
340
340
|
groups.push([item]);
|
|
341
341
|
} else {
|
|
342
342
|
lastGroup.push(item);
|
|
@@ -346,7 +346,10 @@ function groupQueuedModelEvents(queued) {
|
|
|
346
346
|
}
|
|
347
347
|
async function dispatchEventBatch(batch) {
|
|
348
348
|
for (const item of batch) {
|
|
349
|
-
|
|
349
|
+
if ("callback" in item)
|
|
350
|
+
await item.callback();
|
|
351
|
+
else
|
|
352
|
+
await eventBus.dispatch(item.event, item.payload);
|
|
350
353
|
}
|
|
351
354
|
}
|
|
352
355
|
async function dispatchQueuedModelEvents(queued) {
|
|
@@ -357,7 +360,11 @@ async function dispatchQueuedModelEvents(queued) {
|
|
|
357
360
|
for (const batch of groupQueuedModelEvents(queued)) {
|
|
358
361
|
const tenant = batch[0]?.tenant ?? null;
|
|
359
362
|
if (tenant) {
|
|
360
|
-
|
|
363
|
+
if (batch.some((item) => ("callback" in item))) {
|
|
364
|
+
await runWithTenant(tenant, () => dispatchEventBatch(batch));
|
|
365
|
+
} else {
|
|
366
|
+
await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
|
|
367
|
+
}
|
|
361
368
|
} else {
|
|
362
369
|
await dispatchEventBatch(batch);
|
|
363
370
|
}
|
|
@@ -555,7 +555,7 @@ function groupQueuedModelEvents(queued) {
|
|
|
555
555
|
for (const item of queued) {
|
|
556
556
|
const lastGroup = groups[groups.length - 1];
|
|
557
557
|
const last = lastGroup?.[lastGroup.length - 1];
|
|
558
|
-
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
|
|
558
|
+
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
|
|
559
559
|
groups.push([item]);
|
|
560
560
|
} else {
|
|
561
561
|
lastGroup.push(item);
|
|
@@ -565,7 +565,10 @@ function groupQueuedModelEvents(queued) {
|
|
|
565
565
|
}
|
|
566
566
|
async function dispatchEventBatch(batch) {
|
|
567
567
|
for (const item of batch) {
|
|
568
|
-
|
|
568
|
+
if ("callback" in item)
|
|
569
|
+
await item.callback();
|
|
570
|
+
else
|
|
571
|
+
await eventBus.dispatch(item.event, item.payload);
|
|
569
572
|
}
|
|
570
573
|
}
|
|
571
574
|
async function dispatchQueuedModelEvents(queued) {
|
|
@@ -576,7 +579,11 @@ async function dispatchQueuedModelEvents(queued) {
|
|
|
576
579
|
for (const batch of groupQueuedModelEvents(queued)) {
|
|
577
580
|
const tenant = batch[0]?.tenant ?? null;
|
|
578
581
|
if (tenant) {
|
|
579
|
-
|
|
582
|
+
if (batch.some((item) => ("callback" in item))) {
|
|
583
|
+
await runWithTenant(tenant, () => dispatchEventBatch(batch));
|
|
584
|
+
} else {
|
|
585
|
+
await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
|
|
586
|
+
}
|
|
580
587
|
} else {
|
|
581
588
|
await dispatchEventBatch(batch);
|
|
582
589
|
}
|
|
@@ -352,7 +352,7 @@ async function consumeOneTimeToken(sql, purpose, plain, now = new Date) {
|
|
|
352
352
|
return null;
|
|
353
353
|
}
|
|
354
354
|
const dialect = currentSqlDialect();
|
|
355
|
-
const consumedAt =
|
|
355
|
+
const consumedAt = dialect.timestampValue(now);
|
|
356
356
|
const hash = hashOneTimeToken(token);
|
|
357
357
|
const returning = dialect.returningClause("user_id");
|
|
358
358
|
const updated = await sql.unsafe(`UPDATE auth_one_time_tokens
|
|
@@ -377,7 +377,7 @@ async function consumeOneTimeToken(sql, purpose, plain, now = new Date) {
|
|
|
377
377
|
async function revokeUserSessions(sql, userId, options = {}) {
|
|
378
378
|
const dialect = currentSqlDialect();
|
|
379
379
|
const versionUpdate = options.incrementAuthVersion ? ", auth_version = auth_version + 1" : "";
|
|
380
|
-
await sql.unsafe(`UPDATE users SET session_valid_after = ${dialect.placeholder(1)}${versionUpdate} WHERE id = ${dialect.placeholder(2)}`, [new Date
|
|
380
|
+
await sql.unsafe(`UPDATE users SET session_valid_after = ${dialect.placeholder(1)}${versionUpdate} WHERE id = ${dialect.placeholder(2)}`, [dialect.timestampValue(new Date), userId]);
|
|
381
381
|
await deleteOptionalCredentials(sql, "sessions", userId);
|
|
382
382
|
if (options.revokeApiTokens !== false) {
|
|
383
383
|
await deleteOptionalCredentials(sql, "api_tokens", userId);
|
|
@@ -555,7 +555,7 @@ function groupQueuedModelEvents(queued) {
|
|
|
555
555
|
for (const item of queued) {
|
|
556
556
|
const lastGroup = groups[groups.length - 1];
|
|
557
557
|
const last = lastGroup?.[lastGroup.length - 1];
|
|
558
|
-
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
|
|
558
|
+
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
|
|
559
559
|
groups.push([item]);
|
|
560
560
|
} else {
|
|
561
561
|
lastGroup.push(item);
|
|
@@ -565,7 +565,10 @@ function groupQueuedModelEvents(queued) {
|
|
|
565
565
|
}
|
|
566
566
|
async function dispatchEventBatch(batch) {
|
|
567
567
|
for (const item of batch) {
|
|
568
|
-
|
|
568
|
+
if ("callback" in item)
|
|
569
|
+
await item.callback();
|
|
570
|
+
else
|
|
571
|
+
await eventBus.dispatch(item.event, item.payload);
|
|
569
572
|
}
|
|
570
573
|
}
|
|
571
574
|
async function dispatchQueuedModelEvents(queued) {
|
|
@@ -576,7 +579,11 @@ async function dispatchQueuedModelEvents(queued) {
|
|
|
576
579
|
for (const batch of groupQueuedModelEvents(queued)) {
|
|
577
580
|
const tenant = batch[0]?.tenant ?? null;
|
|
578
581
|
if (tenant) {
|
|
579
|
-
|
|
582
|
+
if (batch.some((item) => ("callback" in item))) {
|
|
583
|
+
await runWithTenant(tenant, () => dispatchEventBatch(batch));
|
|
584
|
+
} else {
|
|
585
|
+
await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
|
|
586
|
+
}
|
|
580
587
|
} else {
|
|
581
588
|
await dispatchEventBatch(batch);
|
|
582
589
|
}
|
|
@@ -823,7 +823,7 @@ function groupQueuedModelEvents(queued) {
|
|
|
823
823
|
for (const item of queued) {
|
|
824
824
|
const lastGroup = groups[groups.length - 1];
|
|
825
825
|
const last = lastGroup?.[lastGroup.length - 1];
|
|
826
|
-
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
|
|
826
|
+
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
|
|
827
827
|
groups.push([item]);
|
|
828
828
|
} else {
|
|
829
829
|
lastGroup.push(item);
|
|
@@ -833,7 +833,10 @@ function groupQueuedModelEvents(queued) {
|
|
|
833
833
|
}
|
|
834
834
|
async function dispatchEventBatch(batch) {
|
|
835
835
|
for (const item of batch) {
|
|
836
|
-
|
|
836
|
+
if ("callback" in item)
|
|
837
|
+
await item.callback();
|
|
838
|
+
else
|
|
839
|
+
await eventBus.dispatch(item.event, item.payload);
|
|
837
840
|
}
|
|
838
841
|
}
|
|
839
842
|
async function dispatchQueuedModelEvents(queued) {
|
|
@@ -844,7 +847,11 @@ async function dispatchQueuedModelEvents(queued) {
|
|
|
844
847
|
for (const batch of groupQueuedModelEvents(queued)) {
|
|
845
848
|
const tenant = batch[0]?.tenant ?? null;
|
|
846
849
|
if (tenant) {
|
|
847
|
-
|
|
850
|
+
if (batch.some((item) => ("callback" in item))) {
|
|
851
|
+
await runWithTenant(tenant, () => dispatchEventBatch(batch));
|
|
852
|
+
} else {
|
|
853
|
+
await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
|
|
854
|
+
}
|
|
848
855
|
} else {
|
|
849
856
|
await dispatchEventBatch(batch);
|
|
850
857
|
}
|
|
@@ -279,7 +279,7 @@ function groupQueuedModelEvents(queued) {
|
|
|
279
279
|
for (const item of queued) {
|
|
280
280
|
const lastGroup = groups[groups.length - 1];
|
|
281
281
|
const last = lastGroup?.[lastGroup.length - 1];
|
|
282
|
-
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
|
|
282
|
+
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
|
|
283
283
|
groups.push([item]);
|
|
284
284
|
} else {
|
|
285
285
|
lastGroup.push(item);
|
|
@@ -289,7 +289,10 @@ function groupQueuedModelEvents(queued) {
|
|
|
289
289
|
}
|
|
290
290
|
async function dispatchEventBatch(batch) {
|
|
291
291
|
for (const item of batch) {
|
|
292
|
-
|
|
292
|
+
if ("callback" in item)
|
|
293
|
+
await item.callback();
|
|
294
|
+
else
|
|
295
|
+
await eventBus.dispatch(item.event, item.payload);
|
|
293
296
|
}
|
|
294
297
|
}
|
|
295
298
|
async function dispatchQueuedModelEvents(queued) {
|
|
@@ -300,7 +303,11 @@ async function dispatchQueuedModelEvents(queued) {
|
|
|
300
303
|
for (const batch of groupQueuedModelEvents(queued)) {
|
|
301
304
|
const tenant = batch[0]?.tenant ?? null;
|
|
302
305
|
if (tenant) {
|
|
303
|
-
|
|
306
|
+
if (batch.some((item) => ("callback" in item))) {
|
|
307
|
+
await runWithTenant(tenant, () => dispatchEventBatch(batch));
|
|
308
|
+
} else {
|
|
309
|
+
await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
|
|
310
|
+
}
|
|
304
311
|
} else {
|
|
305
312
|
await dispatchEventBatch(batch);
|
|
306
313
|
}
|
|
@@ -664,7 +664,7 @@ function groupQueuedModelEvents(queued) {
|
|
|
664
664
|
for (const item of queued) {
|
|
665
665
|
const lastGroup = groups[groups.length - 1];
|
|
666
666
|
const last = lastGroup?.[lastGroup.length - 1];
|
|
667
|
-
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
|
|
667
|
+
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
|
|
668
668
|
groups.push([item]);
|
|
669
669
|
} else {
|
|
670
670
|
lastGroup.push(item);
|
|
@@ -674,7 +674,10 @@ function groupQueuedModelEvents(queued) {
|
|
|
674
674
|
}
|
|
675
675
|
async function dispatchEventBatch(batch) {
|
|
676
676
|
for (const item of batch) {
|
|
677
|
-
|
|
677
|
+
if ("callback" in item)
|
|
678
|
+
await item.callback();
|
|
679
|
+
else
|
|
680
|
+
await eventBus.dispatch(item.event, item.payload);
|
|
678
681
|
}
|
|
679
682
|
}
|
|
680
683
|
async function dispatchQueuedModelEvents(queued) {
|
|
@@ -685,7 +688,11 @@ async function dispatchQueuedModelEvents(queued) {
|
|
|
685
688
|
for (const batch of groupQueuedModelEvents(queued)) {
|
|
686
689
|
const tenant = batch[0]?.tenant ?? null;
|
|
687
690
|
if (tenant) {
|
|
688
|
-
|
|
691
|
+
if (batch.some((item) => ("callback" in item))) {
|
|
692
|
+
await runWithTenant(tenant, () => dispatchEventBatch(batch));
|
|
693
|
+
} else {
|
|
694
|
+
await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
|
|
695
|
+
}
|
|
689
696
|
} else {
|
|
690
697
|
await dispatchEventBatch(batch);
|
|
691
698
|
}
|
|
@@ -279,7 +279,7 @@ function groupQueuedModelEvents(queued) {
|
|
|
279
279
|
for (const item of queued) {
|
|
280
280
|
const lastGroup = groups[groups.length - 1];
|
|
281
281
|
const last = lastGroup?.[lastGroup.length - 1];
|
|
282
|
-
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
|
|
282
|
+
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
|
|
283
283
|
groups.push([item]);
|
|
284
284
|
} else {
|
|
285
285
|
lastGroup.push(item);
|
|
@@ -289,7 +289,10 @@ function groupQueuedModelEvents(queued) {
|
|
|
289
289
|
}
|
|
290
290
|
async function dispatchEventBatch(batch) {
|
|
291
291
|
for (const item of batch) {
|
|
292
|
-
|
|
292
|
+
if ("callback" in item)
|
|
293
|
+
await item.callback();
|
|
294
|
+
else
|
|
295
|
+
await eventBus.dispatch(item.event, item.payload);
|
|
293
296
|
}
|
|
294
297
|
}
|
|
295
298
|
async function dispatchQueuedModelEvents(queued) {
|
|
@@ -300,7 +303,11 @@ async function dispatchQueuedModelEvents(queued) {
|
|
|
300
303
|
for (const batch of groupQueuedModelEvents(queued)) {
|
|
301
304
|
const tenant = batch[0]?.tenant ?? null;
|
|
302
305
|
if (tenant) {
|
|
303
|
-
|
|
306
|
+
if (batch.some((item) => ("callback" in item))) {
|
|
307
|
+
await runWithTenant(tenant, () => dispatchEventBatch(batch));
|
|
308
|
+
} else {
|
|
309
|
+
await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
|
|
310
|
+
}
|
|
304
311
|
} else {
|
|
305
312
|
await dispatchEventBatch(batch);
|
|
306
313
|
}
|
|
@@ -212,7 +212,7 @@ function groupQueuedModelEvents(queued) {
|
|
|
212
212
|
for (const item of queued) {
|
|
213
213
|
const lastGroup = groups[groups.length - 1];
|
|
214
214
|
const last = lastGroup?.[lastGroup.length - 1];
|
|
215
|
-
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
|
|
215
|
+
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
|
|
216
216
|
groups.push([item]);
|
|
217
217
|
} else {
|
|
218
218
|
lastGroup.push(item);
|
|
@@ -222,7 +222,10 @@ function groupQueuedModelEvents(queued) {
|
|
|
222
222
|
}
|
|
223
223
|
async function dispatchEventBatch(batch) {
|
|
224
224
|
for (const item of batch) {
|
|
225
|
-
|
|
225
|
+
if ("callback" in item)
|
|
226
|
+
await item.callback();
|
|
227
|
+
else
|
|
228
|
+
await eventBus.dispatch(item.event, item.payload);
|
|
226
229
|
}
|
|
227
230
|
}
|
|
228
231
|
async function dispatchQueuedModelEvents(queued) {
|
|
@@ -233,7 +236,11 @@ async function dispatchQueuedModelEvents(queued) {
|
|
|
233
236
|
for (const batch of groupQueuedModelEvents(queued)) {
|
|
234
237
|
const tenant = batch[0]?.tenant ?? null;
|
|
235
238
|
if (tenant) {
|
|
236
|
-
|
|
239
|
+
if (batch.some((item) => ("callback" in item))) {
|
|
240
|
+
await runWithTenant(tenant, () => dispatchEventBatch(batch));
|
|
241
|
+
} else {
|
|
242
|
+
await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
|
|
243
|
+
}
|
|
237
244
|
} else {
|
|
238
245
|
await dispatchEventBatch(batch);
|
|
239
246
|
}
|
|
@@ -69,7 +69,7 @@ export type { Seeder, SeederDatabase } from "../core/database/seeders/types.ts";
|
|
|
69
69
|
export { createSqliteConnection } from "../core/database/sqliteConnection.ts";
|
|
70
70
|
export { defineTable } from "../core/database/table.ts";
|
|
71
71
|
export type { TransactionOptions } from "../core/database/transaction.ts";
|
|
72
|
-
export { hasActiveTransaction, isActiveTransactionConnection, requestTransactionRollback, runInTransaction, } from "../core/database/transaction.ts";
|
|
72
|
+
export { afterCommit, hasActiveTransaction, isActiveTransactionConnection, requestTransactionRollback, runInTransaction, } from "../core/database/transaction.ts";
|
|
73
73
|
export type { ModelWhere, ModelWriteValues, QueryJoin, QueryJoinOn, QueryOptions, QueryOrder, QuerySelectItem, QueryWhere, } from "../core/database/types.ts";
|
|
74
74
|
export type { WhereNode } from "../core/database/whereBuilder.ts";
|
|
75
75
|
export { WhereBuilder } from "../core/database/whereBuilder.ts";
|
package/dist/index.js
CHANGED
|
@@ -384,7 +384,7 @@ function groupQueuedModelEvents(queued) {
|
|
|
384
384
|
for (const item of queued) {
|
|
385
385
|
const lastGroup = groups[groups.length - 1];
|
|
386
386
|
const last = lastGroup?.[lastGroup.length - 1];
|
|
387
|
-
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
|
|
387
|
+
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
|
|
388
388
|
groups.push([item]);
|
|
389
389
|
} else {
|
|
390
390
|
lastGroup.push(item);
|
|
@@ -394,7 +394,10 @@ function groupQueuedModelEvents(queued) {
|
|
|
394
394
|
}
|
|
395
395
|
async function dispatchEventBatch(batch) {
|
|
396
396
|
for (const item of batch) {
|
|
397
|
-
|
|
397
|
+
if ("callback" in item)
|
|
398
|
+
await item.callback();
|
|
399
|
+
else
|
|
400
|
+
await eventBus.dispatch(item.event, item.payload);
|
|
398
401
|
}
|
|
399
402
|
}
|
|
400
403
|
async function dispatchQueuedModelEvents(queued) {
|
|
@@ -405,7 +408,11 @@ async function dispatchQueuedModelEvents(queued) {
|
|
|
405
408
|
for (const batch of groupQueuedModelEvents(queued)) {
|
|
406
409
|
const tenant = batch[0]?.tenant ?? null;
|
|
407
410
|
if (tenant) {
|
|
408
|
-
|
|
411
|
+
if (batch.some((item) => ("callback" in item))) {
|
|
412
|
+
await runWithTenant(tenant, () => dispatchEventBatch(batch));
|
|
413
|
+
} else {
|
|
414
|
+
await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
|
|
415
|
+
}
|
|
409
416
|
} else {
|
|
410
417
|
await dispatchEventBatch(batch);
|
|
411
418
|
}
|
|
@@ -425,6 +432,14 @@ async function dispatchModelEvent(event, payload) {
|
|
|
425
432
|
}
|
|
426
433
|
await eventBus.dispatch(event, payload);
|
|
427
434
|
}
|
|
435
|
+
async function afterCommit(callback) {
|
|
436
|
+
const frame = deferredModelEvents.getStore()?.frames.at(-1);
|
|
437
|
+
if (frame) {
|
|
438
|
+
frame.push({ callback, tenant: currentTenant() });
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
await callback();
|
|
442
|
+
}
|
|
428
443
|
async function runWithDeferredModelEvents(callback) {
|
|
429
444
|
const existing = deferredModelEvents.getStore();
|
|
430
445
|
if (existing) {
|
|
@@ -17197,6 +17212,7 @@ export {
|
|
|
17197
17212
|
WhereBuilder,
|
|
17198
17213
|
absoluteTemporarySignedUrl,
|
|
17199
17214
|
acquireTracingRuntime,
|
|
17215
|
+
afterCommit,
|
|
17200
17216
|
apiPrefix,
|
|
17201
17217
|
appCookieName,
|
|
17202
17218
|
appDevSecret,
|