@dudousxd/nestjs-durable-store-typeorm 0.20.1 → 0.21.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 CHANGED
@@ -1104,6 +1104,22 @@ var TypeOrmStateStore = class {
1104
1104
  "seq"
1105
1105
  ]);
1106
1106
  }
1107
+ async saveCheckpointIfPending(checkpoint) {
1108
+ const { runId, seq, ...data } = toCheckpointEntity(checkpoint);
1109
+ const set = {
1110
+ ...data,
1111
+ wakeAt: checkpoint.wakeAt != null ? new Date(checkpoint.wakeAt) : () => "NULL"
1112
+ };
1113
+ for (const key of Object.keys(set)) {
1114
+ if (set[key] === void 0) delete set[key];
1115
+ }
1116
+ const result = await this.checkpoints().createQueryBuilder().update().set(set).where({
1117
+ runId,
1118
+ seq,
1119
+ status: "pending"
1120
+ }).execute();
1121
+ return (result.affected ?? 0) > 0;
1122
+ }
1107
1123
  async transaction(work) {
1108
1124
  return this.dataSource.transaction(async (em) => work({
1109
1125
  raw: em,
@@ -1404,6 +1420,15 @@ var TypeOrmStateStore = class {
1404
1420
  });
1405
1421
  return e ? fromCheckpointEntity(e) : void 0;
1406
1422
  }
1423
+ async countCheckpoints(runId, fromSeq, toSeq, statuses) {
1424
+ if (statuses.length === 0) return 0;
1425
+ const row = await this.checkpoints().createQueryBuilder("cp").select("COUNT(*)", "count").where({
1426
+ runId,
1427
+ seq: (0, import_typeorm2.Between)(fromSeq, toSeq),
1428
+ status: (0, import_typeorm2.In)(statuses)
1429
+ }).getRawOne();
1430
+ return Number(row?.count ?? 0);
1431
+ }
1407
1432
  async listCheckpointsByNamePrefix(runId, prefixes) {
1408
1433
  if (prefixes.length === 0) return [];
1409
1434
  const rows = await this.checkpoints().find({