@dudousxd/nestjs-durable-store-typeorm 0.19.1 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +78 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +79 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -417,6 +417,14 @@ function durableEntities(options = {}) {
|
|
|
417
417
|
name: "SignalWaiterEntity",
|
|
418
418
|
target: SignalWaiterEntity,
|
|
419
419
|
tableName: "durable_signal_waiters",
|
|
420
|
+
indices: [
|
|
421
|
+
{
|
|
422
|
+
name: "durable_signal_waiters_run_id_idx",
|
|
423
|
+
columns: [
|
|
424
|
+
"runId"
|
|
425
|
+
]
|
|
426
|
+
}
|
|
427
|
+
],
|
|
420
428
|
columns: {
|
|
421
429
|
token: {
|
|
422
430
|
type: "text",
|
|
@@ -832,6 +840,11 @@ async function ensureTypeOrmDurableSchema(dataSource) {
|
|
|
832
840
|
"durable_runs_namespace_status_idx",
|
|
833
841
|
`${runs} (${runsCol("namespace")}, ${runsCol("status")}, ${runsCol("createdAt")})`
|
|
834
842
|
],
|
|
843
|
+
// A run's waiters: the `ctx.all` join barrier probes them once per settled child.
|
|
844
|
+
[
|
|
845
|
+
"durable_signal_waiters_run_id_idx",
|
|
846
|
+
`${waiters} (${waiterCol("runId")})`
|
|
847
|
+
],
|
|
835
848
|
// buffered signals are taken FIFO per token (smallest id) — index the token for the scan.
|
|
836
849
|
[
|
|
837
850
|
"durable_buffered_signals_token_idx",
|
|
@@ -1417,6 +1430,71 @@ var TypeOrmStateStore = class {
|
|
|
1417
1430
|
parallelGroup: e.parallelGroup ?? void 0
|
|
1418
1431
|
}));
|
|
1419
1432
|
}
|
|
1433
|
+
async registerChildWaits(entries) {
|
|
1434
|
+
if (entries.length === 0) return;
|
|
1435
|
+
await this.dataSource.transaction(async (em) => {
|
|
1436
|
+
await em.getRepository(SignalWaiterEntity).upsert(entries.map(({ waiter }) => ({
|
|
1437
|
+
token: waiter.token,
|
|
1438
|
+
runId: waiter.runId,
|
|
1439
|
+
seq: waiter.seq,
|
|
1440
|
+
parallelGroup: waiter.parallelGroup ?? null
|
|
1441
|
+
})), [
|
|
1442
|
+
"token"
|
|
1443
|
+
]);
|
|
1444
|
+
await em.getRepository(StepCheckpointEntity).upsert(entries.map(({ checkpoint }) => toCheckpointEntity(checkpoint)), [
|
|
1445
|
+
"runId",
|
|
1446
|
+
"seq"
|
|
1447
|
+
]);
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
async compactCheckpoints(runId, fromSeq, toSeq, into) {
|
|
1451
|
+
await this.dataSource.transaction(async (em) => {
|
|
1452
|
+
const checkpoints = em.getRepository(StepCheckpointEntity);
|
|
1453
|
+
await checkpoints.delete({
|
|
1454
|
+
runId,
|
|
1455
|
+
seq: (0, import_typeorm2.Between)(fromSeq, toSeq)
|
|
1456
|
+
});
|
|
1457
|
+
await checkpoints.upsert(toCheckpointEntity(into), [
|
|
1458
|
+
"runId",
|
|
1459
|
+
"seq"
|
|
1460
|
+
]);
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
async listSignalWaitersByRun(runIds) {
|
|
1464
|
+
if (runIds.length === 0) return [];
|
|
1465
|
+
const rows = await this.waiters().find({
|
|
1466
|
+
where: {
|
|
1467
|
+
runId: (0, import_typeorm2.In)(runIds)
|
|
1468
|
+
}
|
|
1469
|
+
});
|
|
1470
|
+
return rows.map((e) => ({
|
|
1471
|
+
token: e.token,
|
|
1472
|
+
runId: e.runId,
|
|
1473
|
+
seq: e.seq,
|
|
1474
|
+
parallelGroup: e.parallelGroup ?? void 0
|
|
1475
|
+
}));
|
|
1476
|
+
}
|
|
1477
|
+
async hasSignalWaiter(runId, tokenPrefix) {
|
|
1478
|
+
const where = {
|
|
1479
|
+
runId,
|
|
1480
|
+
token: (0, import_typeorm2.Like)(`${tokenPrefix}%`)
|
|
1481
|
+
};
|
|
1482
|
+
const first = await this.waiters().findOne({
|
|
1483
|
+
where,
|
|
1484
|
+
select: {
|
|
1485
|
+
token: true
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
if (!first) return false;
|
|
1489
|
+
if (first.token.startsWith(tokenPrefix)) return true;
|
|
1490
|
+
const rows = await this.waiters().find({
|
|
1491
|
+
where,
|
|
1492
|
+
select: {
|
|
1493
|
+
token: true
|
|
1494
|
+
}
|
|
1495
|
+
});
|
|
1496
|
+
return rows.some((r) => r.token.startsWith(tokenPrefix));
|
|
1497
|
+
}
|
|
1420
1498
|
async takeSignalWaiter(token) {
|
|
1421
1499
|
const e = await this.waiters().findOneBy({
|
|
1422
1500
|
token
|