@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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _mikro_orm_core from '@mikro-orm/core';
2
2
  import { EntityRepository, EntityRepositoryType, EntitySchema, MikroORM } from '@mikro-orm/core';
3
- import { StepKind, RunStatus, StateStore, WorkflowRun, RetentionPolicy, StepCheckpoint, RunQuery, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, ScheduleRecord, ScheduleQuery, SignalWaiter } from '@dudousxd/nestjs-durable-core';
3
+ import { StepKind, RunStatus, StateStore, WorkflowRun, RetentionPolicy, StepCheckpoint, RunQuery, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, ScheduleRecord, ScheduleQuery, SignalWaiter, ChildWait } from '@dudousxd/nestjs-durable-core';
4
4
 
5
5
  /**
6
6
  * Custom repositories for the durable entities, so a host app can `@InjectRepository`/inject a
@@ -291,6 +291,10 @@ declare class MikroOrmStateStore implements StateStore {
291
291
  putSignalWaiter(waiter: SignalWaiter): Promise<void>;
292
292
  takeSignalWaiter(token: string): Promise<SignalWaiter | null>;
293
293
  listSignalWaiters(prefix: string): Promise<SignalWaiter[]>;
294
+ registerChildWaits(entries: ChildWait[]): Promise<void>;
295
+ compactCheckpoints(runId: string, fromSeq: number, toSeq: number, into: StepCheckpoint): Promise<void>;
296
+ listSignalWaitersByRun(runIds: string[]): Promise<SignalWaiter[]>;
297
+ hasSignalWaiter(runId: string, tokenPrefix: string): Promise<boolean>;
294
298
  removeSignalWaiter(waiter: SignalWaiter): Promise<void>;
295
299
  bufferSignal(token: string, payload: unknown): Promise<void>;
296
300
  takeBufferedSignal(token: string): Promise<{
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _mikro_orm_core from '@mikro-orm/core';
2
2
  import { EntityRepository, EntityRepositoryType, EntitySchema, MikroORM } from '@mikro-orm/core';
3
- import { StepKind, RunStatus, StateStore, WorkflowRun, RetentionPolicy, StepCheckpoint, RunQuery, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, ScheduleRecord, ScheduleQuery, SignalWaiter } from '@dudousxd/nestjs-durable-core';
3
+ import { StepKind, RunStatus, StateStore, WorkflowRun, RetentionPolicy, StepCheckpoint, RunQuery, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, ScheduleRecord, ScheduleQuery, SignalWaiter, ChildWait } from '@dudousxd/nestjs-durable-core';
4
4
 
5
5
  /**
6
6
  * Custom repositories for the durable entities, so a host app can `@InjectRepository`/inject a
@@ -291,6 +291,10 @@ declare class MikroOrmStateStore implements StateStore {
291
291
  putSignalWaiter(waiter: SignalWaiter): Promise<void>;
292
292
  takeSignalWaiter(token: string): Promise<SignalWaiter | null>;
293
293
  listSignalWaiters(prefix: string): Promise<SignalWaiter[]>;
294
+ registerChildWaits(entries: ChildWait[]): Promise<void>;
295
+ compactCheckpoints(runId: string, fromSeq: number, toSeq: number, into: StepCheckpoint): Promise<void>;
296
+ listSignalWaitersByRun(runIds: string[]): Promise<SignalWaiter[]>;
297
+ hasSignalWaiter(runId: string, tokenPrefix: string): Promise<boolean>;
294
298
  removeSignalWaiter(waiter: SignalWaiter): Promise<void>;
295
299
  bufferSignal(token: string, payload: unknown): Promise<void>;
296
300
  takeBufferedSignal(token: string): Promise<{
package/dist/index.js CHANGED
@@ -472,6 +472,15 @@ function durableEntities(options = {}) {
472
472
  class: SignalWaiterEntity,
473
473
  tableName: "durable_signal_waiters",
474
474
  repository: /* @__PURE__ */ __name(() => SignalWaiterRepository, "repository"),
475
+ // A run's waiters: the `ctx.all` join barrier probes them once per settled child.
476
+ indexes: [
477
+ {
478
+ name: "durable_signal_waiters_run_id_idx",
479
+ properties: [
480
+ "runId"
481
+ ]
482
+ }
483
+ ],
475
484
  properties: {
476
485
  token: {
477
486
  type: "string",
@@ -1598,6 +1607,66 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1598
1607
  parallelGroup: e.parallelGroup ?? void 0
1599
1608
  }));
1600
1609
  }
1610
+ async registerChildWaits(entries) {
1611
+ if (entries.length === 0) return;
1612
+ await this.fork().transactional(async (em) => {
1613
+ await em.upsertMany(SignalWaiterEntity, entries.map(({ waiter }) => ({
1614
+ token: waiter.token,
1615
+ runId: waiter.runId,
1616
+ seq: waiter.seq,
1617
+ parallelGroup: waiter.parallelGroup ?? null
1618
+ })));
1619
+ await em.upsertMany(StepCheckpointEntity, entries.map(({ checkpoint }) => toCheckpointEntity(checkpoint)));
1620
+ });
1621
+ }
1622
+ async compactCheckpoints(runId, fromSeq, toSeq, into) {
1623
+ await this.fork().transactional(async (em) => {
1624
+ await em.nativeDelete(StepCheckpointEntity, {
1625
+ runId,
1626
+ seq: {
1627
+ $gte: fromSeq,
1628
+ $lte: toSeq
1629
+ }
1630
+ });
1631
+ await em.upsert(StepCheckpointEntity, toCheckpointEntity(into));
1632
+ });
1633
+ }
1634
+ async listSignalWaitersByRun(runIds) {
1635
+ if (runIds.length === 0) return [];
1636
+ const rows = await this.fork().find(SignalWaiterEntity, {
1637
+ runId: {
1638
+ $in: runIds
1639
+ }
1640
+ });
1641
+ return rows.map((e) => ({
1642
+ token: e.token,
1643
+ runId: e.runId,
1644
+ seq: e.seq,
1645
+ parallelGroup: e.parallelGroup ?? void 0
1646
+ }));
1647
+ }
1648
+ async hasSignalWaiter(runId, tokenPrefix) {
1649
+ const em = this.fork();
1650
+ const where = {
1651
+ runId,
1652
+ token: {
1653
+ $like: `${tokenPrefix}%`
1654
+ }
1655
+ };
1656
+ const first = await em.findOne(SignalWaiterEntity, where, {
1657
+ fields: [
1658
+ "token"
1659
+ ]
1660
+ });
1661
+ if (!first) return false;
1662
+ if (first.token.startsWith(tokenPrefix)) return true;
1663
+ const rows = await em.find(SignalWaiterEntity, where, {
1664
+ fields: [
1665
+ "token"
1666
+ ]
1667
+ });
1668
+ return rows.some((r) => r.token.startsWith(tokenPrefix));
1669
+ }
1601
1670
  async removeSignalWaiter(waiter) {
1602
1671
  const em = this.fork();
1603
1672
  await em.nativeDelete(SignalWaiterEntity, {