@dudousxd/nestjs-durable-store-mikro-orm 0.27.1 → 0.28.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 +81 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +81 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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
|
|
@@ -197,6 +197,7 @@ declare class MikroOrmStateStore implements StateStore {
|
|
|
197
197
|
pruneTerminalRuns(policy: RetentionPolicy, nowMs: number, limit: number): Promise<number>;
|
|
198
198
|
getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
|
|
199
199
|
saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
|
|
200
|
+
saveCheckpointIfPending(checkpoint: StepCheckpoint): Promise<boolean>;
|
|
200
201
|
transaction<T>(work: (tx: {
|
|
201
202
|
raw: unknown;
|
|
202
203
|
saveCheckpoint: (cp: StepCheckpoint) => Promise<void>;
|
|
@@ -291,6 +292,10 @@ declare class MikroOrmStateStore implements StateStore {
|
|
|
291
292
|
putSignalWaiter(waiter: SignalWaiter): Promise<void>;
|
|
292
293
|
takeSignalWaiter(token: string): Promise<SignalWaiter | null>;
|
|
293
294
|
listSignalWaiters(prefix: string): Promise<SignalWaiter[]>;
|
|
295
|
+
registerChildWaits(entries: ChildWait[]): Promise<void>;
|
|
296
|
+
compactCheckpoints(runId: string, fromSeq: number, toSeq: number, into: StepCheckpoint): Promise<void>;
|
|
297
|
+
listSignalWaitersByRun(runIds: string[]): Promise<SignalWaiter[]>;
|
|
298
|
+
hasSignalWaiter(runId: string, tokenPrefix: string): Promise<boolean>;
|
|
294
299
|
removeSignalWaiter(waiter: SignalWaiter): Promise<void>;
|
|
295
300
|
bufferSignal(token: string, payload: unknown): Promise<void>;
|
|
296
301
|
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
|
|
@@ -197,6 +197,7 @@ declare class MikroOrmStateStore implements StateStore {
|
|
|
197
197
|
pruneTerminalRuns(policy: RetentionPolicy, nowMs: number, limit: number): Promise<number>;
|
|
198
198
|
getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
|
|
199
199
|
saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
|
|
200
|
+
saveCheckpointIfPending(checkpoint: StepCheckpoint): Promise<boolean>;
|
|
200
201
|
transaction<T>(work: (tx: {
|
|
201
202
|
raw: unknown;
|
|
202
203
|
saveCheckpoint: (cp: StepCheckpoint) => Promise<void>;
|
|
@@ -291,6 +292,10 @@ declare class MikroOrmStateStore implements StateStore {
|
|
|
291
292
|
putSignalWaiter(waiter: SignalWaiter): Promise<void>;
|
|
292
293
|
takeSignalWaiter(token: string): Promise<SignalWaiter | null>;
|
|
293
294
|
listSignalWaiters(prefix: string): Promise<SignalWaiter[]>;
|
|
295
|
+
registerChildWaits(entries: ChildWait[]): Promise<void>;
|
|
296
|
+
compactCheckpoints(runId: string, fromSeq: number, toSeq: number, into: StepCheckpoint): Promise<void>;
|
|
297
|
+
listSignalWaitersByRun(runIds: string[]): Promise<SignalWaiter[]>;
|
|
298
|
+
hasSignalWaiter(runId: string, tokenPrefix: string): Promise<boolean>;
|
|
294
299
|
removeSignalWaiter(waiter: SignalWaiter): Promise<void>;
|
|
295
300
|
bufferSignal(token: string, payload: unknown): Promise<void>;
|
|
296
301
|
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",
|
|
@@ -1057,6 +1066,18 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
|
|
|
1057
1066
|
await em.upsert(StepCheckpointEntity, toCheckpointEntity(checkpoint));
|
|
1058
1067
|
await em.flush();
|
|
1059
1068
|
}
|
|
1069
|
+
async saveCheckpointIfPending(checkpoint) {
|
|
1070
|
+
const { runId: _runId, seq: _seq, ...data } = toCheckpointEntity(checkpoint);
|
|
1071
|
+
const affected = await this.fork().nativeUpdate(StepCheckpointEntity, {
|
|
1072
|
+
runId: checkpoint.runId,
|
|
1073
|
+
seq: checkpoint.seq,
|
|
1074
|
+
status: "pending"
|
|
1075
|
+
}, {
|
|
1076
|
+
...data,
|
|
1077
|
+
wakeAt: checkpoint.wakeAt != null ? new Date(checkpoint.wakeAt) : null
|
|
1078
|
+
});
|
|
1079
|
+
return affected > 0;
|
|
1080
|
+
}
|
|
1060
1081
|
async transaction(work) {
|
|
1061
1082
|
return this.fork().transactional(async (em) => work({
|
|
1062
1083
|
raw: em,
|
|
@@ -1598,6 +1619,66 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
|
|
|
1598
1619
|
parallelGroup: e.parallelGroup ?? void 0
|
|
1599
1620
|
}));
|
|
1600
1621
|
}
|
|
1622
|
+
async registerChildWaits(entries) {
|
|
1623
|
+
if (entries.length === 0) return;
|
|
1624
|
+
await this.fork().transactional(async (em) => {
|
|
1625
|
+
await em.upsertMany(SignalWaiterEntity, entries.map(({ waiter }) => ({
|
|
1626
|
+
token: waiter.token,
|
|
1627
|
+
runId: waiter.runId,
|
|
1628
|
+
seq: waiter.seq,
|
|
1629
|
+
parallelGroup: waiter.parallelGroup ?? null
|
|
1630
|
+
})));
|
|
1631
|
+
await em.upsertMany(StepCheckpointEntity, entries.map(({ checkpoint }) => toCheckpointEntity(checkpoint)));
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
async compactCheckpoints(runId, fromSeq, toSeq, into) {
|
|
1635
|
+
await this.fork().transactional(async (em) => {
|
|
1636
|
+
await em.nativeDelete(StepCheckpointEntity, {
|
|
1637
|
+
runId,
|
|
1638
|
+
seq: {
|
|
1639
|
+
$gte: fromSeq,
|
|
1640
|
+
$lte: toSeq
|
|
1641
|
+
}
|
|
1642
|
+
});
|
|
1643
|
+
await em.upsert(StepCheckpointEntity, toCheckpointEntity(into));
|
|
1644
|
+
});
|
|
1645
|
+
}
|
|
1646
|
+
async listSignalWaitersByRun(runIds) {
|
|
1647
|
+
if (runIds.length === 0) return [];
|
|
1648
|
+
const rows = await this.fork().find(SignalWaiterEntity, {
|
|
1649
|
+
runId: {
|
|
1650
|
+
$in: runIds
|
|
1651
|
+
}
|
|
1652
|
+
});
|
|
1653
|
+
return rows.map((e) => ({
|
|
1654
|
+
token: e.token,
|
|
1655
|
+
runId: e.runId,
|
|
1656
|
+
seq: e.seq,
|
|
1657
|
+
parallelGroup: e.parallelGroup ?? void 0
|
|
1658
|
+
}));
|
|
1659
|
+
}
|
|
1660
|
+
async hasSignalWaiter(runId, tokenPrefix) {
|
|
1661
|
+
const em = this.fork();
|
|
1662
|
+
const where = {
|
|
1663
|
+
runId,
|
|
1664
|
+
token: {
|
|
1665
|
+
$like: `${tokenPrefix}%`
|
|
1666
|
+
}
|
|
1667
|
+
};
|
|
1668
|
+
const first = await em.findOne(SignalWaiterEntity, where, {
|
|
1669
|
+
fields: [
|
|
1670
|
+
"token"
|
|
1671
|
+
]
|
|
1672
|
+
});
|
|
1673
|
+
if (!first) return false;
|
|
1674
|
+
if (first.token.startsWith(tokenPrefix)) return true;
|
|
1675
|
+
const rows = await em.find(SignalWaiterEntity, where, {
|
|
1676
|
+
fields: [
|
|
1677
|
+
"token"
|
|
1678
|
+
]
|
|
1679
|
+
});
|
|
1680
|
+
return rows.some((r) => r.token.startsWith(tokenPrefix));
|
|
1681
|
+
}
|
|
1601
1682
|
async removeSignalWaiter(waiter) {
|
|
1602
1683
|
const em = this.fork();
|
|
1603
1684
|
await em.nativeDelete(SignalWaiterEntity, {
|