@dudousxd/nestjs-durable-store-mikro-orm 0.27.0 → 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 +107 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +108 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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",
|
|
@@ -934,13 +943,50 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
|
|
|
934
943
|
async ensureSchema() {
|
|
935
944
|
await ensureMikroOrmDurableSchema(this.orm);
|
|
936
945
|
}
|
|
946
|
+
async tryAdmitSingleton(runId, tag, workflow, limit, retryWakeAt) {
|
|
947
|
+
return this.fork().transactional(async (em) => {
|
|
948
|
+
const where = {
|
|
949
|
+
workflow,
|
|
950
|
+
status: {
|
|
951
|
+
$in: import_nestjs_durable_core.SINGLETON_ACTIVE_STATUSES
|
|
952
|
+
},
|
|
953
|
+
...this.scopeNamespace !== void 0 ? {
|
|
954
|
+
namespace: this.scopeNamespace
|
|
955
|
+
} : {}
|
|
956
|
+
};
|
|
957
|
+
await em.nativeUpdate(WorkflowRunEntity, where, {
|
|
958
|
+
workflow
|
|
959
|
+
});
|
|
960
|
+
const rows = await em.find(WorkflowRunEntity, where);
|
|
961
|
+
const runs = rows.map(fromRunEntity);
|
|
962
|
+
const tags = (0, import_nestjs_durable_core.singletonAdmissionTags)(runs, runId, tag, workflow, limit);
|
|
963
|
+
if (!tags) {
|
|
964
|
+
const patch = (0, import_nestjs_durable_core.singletonAdmissionDenialPatch)(runs, runId, tag, workflow, retryWakeAt);
|
|
965
|
+
if (patch) await em.nativeUpdate(WorkflowRunEntity, {
|
|
966
|
+
id: runId
|
|
967
|
+
}, {
|
|
968
|
+
status: "suspended",
|
|
969
|
+
wakeAt: new Date(patch.wakeAt),
|
|
970
|
+
updatedAt: patch.updatedAt
|
|
971
|
+
});
|
|
972
|
+
return false;
|
|
973
|
+
}
|
|
974
|
+
await em.nativeUpdate(WorkflowRunEntity, {
|
|
975
|
+
id: runId
|
|
976
|
+
}, {
|
|
977
|
+
tags
|
|
978
|
+
});
|
|
979
|
+
return true;
|
|
980
|
+
});
|
|
981
|
+
}
|
|
937
982
|
async createRun(run) {
|
|
938
983
|
const em = this.fork();
|
|
939
984
|
em.create(WorkflowRunEntity, toRunEntity(run));
|
|
940
985
|
await em.flush();
|
|
941
986
|
await this.reindexAttributes(run.id, run.searchAttributes);
|
|
942
987
|
}
|
|
943
|
-
async updateRun(runId,
|
|
988
|
+
async updateRun(runId, inputPatch) {
|
|
989
|
+
const patch = inputPatch.status && import_nestjs_durable_core.TERMINAL_RUN_STATUSES.includes(inputPatch.status) ? await (0, import_nestjs_durable_core.clearTerminalSingletonAdmission)(runId, inputPatch, (id) => this.withScope({}).getRun(id)) : inputPatch;
|
|
944
990
|
const em = this.fork();
|
|
945
991
|
const entity = await em.findOneOrFail(WorkflowRunEntity, {
|
|
946
992
|
id: runId
|
|
@@ -1603,6 +1649,66 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
|
|
|
1603
1649
|
parallelGroup: e.parallelGroup ?? void 0
|
|
1604
1650
|
}));
|
|
1605
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
|
+
}
|
|
1606
1712
|
async removeSignalWaiter(waiter) {
|
|
1607
1713
|
const em = this.fork();
|
|
1608
1714
|
await em.nativeDelete(SignalWaiterEntity, {
|