@dudousxd/nestjs-durable-store-mikro-orm 0.27.1 → 0.28.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
@@ -514,6 +514,15 @@ function durableEntities(options = {}) {
514
514
  class: SignalWaiterEntity,
515
515
  tableName: "durable_signal_waiters",
516
516
  repository: /* @__PURE__ */ __name(() => SignalWaiterRepository, "repository"),
517
+ // A run's waiters: the `ctx.all` join barrier probes them once per settled child.
518
+ indexes: [
519
+ {
520
+ name: "durable_signal_waiters_run_id_idx",
521
+ properties: [
522
+ "runId"
523
+ ]
524
+ }
525
+ ],
517
526
  properties: {
518
527
  token: {
519
528
  type: "string",
@@ -1640,6 +1649,66 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1640
1649
  parallelGroup: e.parallelGroup ?? void 0
1641
1650
  }));
1642
1651
  }
1652
+ async registerChildWaits(entries) {
1653
+ if (entries.length === 0) return;
1654
+ await this.fork().transactional(async (em) => {
1655
+ await em.upsertMany(SignalWaiterEntity, entries.map(({ waiter }) => ({
1656
+ token: waiter.token,
1657
+ runId: waiter.runId,
1658
+ seq: waiter.seq,
1659
+ parallelGroup: waiter.parallelGroup ?? null
1660
+ })));
1661
+ await em.upsertMany(StepCheckpointEntity, entries.map(({ checkpoint }) => toCheckpointEntity(checkpoint)));
1662
+ });
1663
+ }
1664
+ async compactCheckpoints(runId, fromSeq, toSeq, into) {
1665
+ await this.fork().transactional(async (em) => {
1666
+ await em.nativeDelete(StepCheckpointEntity, {
1667
+ runId,
1668
+ seq: {
1669
+ $gte: fromSeq,
1670
+ $lte: toSeq
1671
+ }
1672
+ });
1673
+ await em.upsert(StepCheckpointEntity, toCheckpointEntity(into));
1674
+ });
1675
+ }
1676
+ async listSignalWaitersByRun(runIds) {
1677
+ if (runIds.length === 0) return [];
1678
+ const rows = await this.fork().find(SignalWaiterEntity, {
1679
+ runId: {
1680
+ $in: runIds
1681
+ }
1682
+ });
1683
+ return rows.map((e) => ({
1684
+ token: e.token,
1685
+ runId: e.runId,
1686
+ seq: e.seq,
1687
+ parallelGroup: e.parallelGroup ?? void 0
1688
+ }));
1689
+ }
1690
+ async hasSignalWaiter(runId, tokenPrefix) {
1691
+ const em = this.fork();
1692
+ const where = {
1693
+ runId,
1694
+ token: {
1695
+ $like: `${tokenPrefix}%`
1696
+ }
1697
+ };
1698
+ const first = await em.findOne(SignalWaiterEntity, where, {
1699
+ fields: [
1700
+ "token"
1701
+ ]
1702
+ });
1703
+ if (!first) return false;
1704
+ if (first.token.startsWith(tokenPrefix)) return true;
1705
+ const rows = await em.find(SignalWaiterEntity, where, {
1706
+ fields: [
1707
+ "token"
1708
+ ]
1709
+ });
1710
+ return rows.some((r) => r.token.startsWith(tokenPrefix));
1711
+ }
1643
1712
  async removeSignalWaiter(waiter) {
1644
1713
  const em = this.fork();
1645
1714
  await em.nativeDelete(SignalWaiterEntity, {