@dudousxd/nestjs-durable-store-typeorm 0.19.1 → 0.20.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.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",
@@ -1133,12 +1146,20 @@ var TypeOrmStateStore = class {
1133
1146
  });
1134
1147
  return rows.map(fromRunEntity);
1135
1148
  }
1136
- async listDueTimers(nowMs, namespace) {
1137
- const rows = await this.runs().findBy({
1138
- status: "suspended",
1139
- wakeAt: (0, import_typeorm2.LessThanOrEqual)(new Date(nowMs)),
1140
- ...namespace !== void 0 ? {
1141
- namespace
1149
+ async listDueTimers(nowMs, namespace, limit) {
1150
+ const rows = await this.runs().find({
1151
+ where: {
1152
+ status: "suspended",
1153
+ wakeAt: (0, import_typeorm2.LessThanOrEqual)(new Date(nowMs)),
1154
+ ...namespace !== void 0 ? {
1155
+ namespace
1156
+ } : {}
1157
+ },
1158
+ order: {
1159
+ wakeAt: "ASC"
1160
+ },
1161
+ ...limit !== void 0 ? {
1162
+ take: limit
1142
1163
  } : {}
1143
1164
  });
1144
1165
  return rows.map(fromRunEntity);
@@ -1417,6 +1438,71 @@ var TypeOrmStateStore = class {
1417
1438
  parallelGroup: e.parallelGroup ?? void 0
1418
1439
  }));
1419
1440
  }
1441
+ async registerChildWaits(entries) {
1442
+ if (entries.length === 0) return;
1443
+ await this.dataSource.transaction(async (em) => {
1444
+ await em.getRepository(SignalWaiterEntity).upsert(entries.map(({ waiter }) => ({
1445
+ token: waiter.token,
1446
+ runId: waiter.runId,
1447
+ seq: waiter.seq,
1448
+ parallelGroup: waiter.parallelGroup ?? null
1449
+ })), [
1450
+ "token"
1451
+ ]);
1452
+ await em.getRepository(StepCheckpointEntity).upsert(entries.map(({ checkpoint }) => toCheckpointEntity(checkpoint)), [
1453
+ "runId",
1454
+ "seq"
1455
+ ]);
1456
+ });
1457
+ }
1458
+ async compactCheckpoints(runId, fromSeq, toSeq, into) {
1459
+ await this.dataSource.transaction(async (em) => {
1460
+ const checkpoints = em.getRepository(StepCheckpointEntity);
1461
+ await checkpoints.delete({
1462
+ runId,
1463
+ seq: (0, import_typeorm2.Between)(fromSeq, toSeq)
1464
+ });
1465
+ await checkpoints.upsert(toCheckpointEntity(into), [
1466
+ "runId",
1467
+ "seq"
1468
+ ]);
1469
+ });
1470
+ }
1471
+ async listSignalWaitersByRun(runIds) {
1472
+ if (runIds.length === 0) return [];
1473
+ const rows = await this.waiters().find({
1474
+ where: {
1475
+ runId: (0, import_typeorm2.In)(runIds)
1476
+ }
1477
+ });
1478
+ return rows.map((e) => ({
1479
+ token: e.token,
1480
+ runId: e.runId,
1481
+ seq: e.seq,
1482
+ parallelGroup: e.parallelGroup ?? void 0
1483
+ }));
1484
+ }
1485
+ async hasSignalWaiter(runId, tokenPrefix) {
1486
+ const where = {
1487
+ runId,
1488
+ token: (0, import_typeorm2.Like)(`${tokenPrefix}%`)
1489
+ };
1490
+ const first = await this.waiters().findOne({
1491
+ where,
1492
+ select: {
1493
+ token: true
1494
+ }
1495
+ });
1496
+ if (!first) return false;
1497
+ if (first.token.startsWith(tokenPrefix)) return true;
1498
+ const rows = await this.waiters().find({
1499
+ where,
1500
+ select: {
1501
+ token: true
1502
+ }
1503
+ });
1504
+ return rows.some((r) => r.token.startsWith(tokenPrefix));
1505
+ }
1420
1506
  async takeSignalWaiter(token) {
1421
1507
  const e = await this.waiters().findOneBy({
1422
1508
  token