@dudousxd/nestjs-durable-store-mikro-orm 0.33.5 → 0.33.7

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
@@ -1176,22 +1176,25 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1176
1176
  });
1177
1177
  }
1178
1178
  async createRun(run) {
1179
- const em = this.fork();
1180
- em.create(WorkflowRunEntity, toRunEntity(run));
1181
- await em.flush();
1179
+ await this.fork().insert(WorkflowRunEntity, toRunEntity(run));
1182
1180
  await this.reindexAttributes(run.id, run.searchAttributes);
1183
1181
  }
1184
1182
  async updateRun(runId, inputPatch) {
1185
1183
  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;
1184
+ const data = runUpdateData(patch);
1186
1185
  const em = this.fork();
1187
- const entity = await em.findOneOrFail(WorkflowRunEntity, {
1188
- id: runId
1189
- });
1190
- Object.assign(entity, toRunEntity({
1191
- ...fromRunEntity(entity),
1192
- ...patch
1193
- }));
1194
- await em.flush();
1186
+ if (Object.keys(data).length) {
1187
+ const affected = await em.nativeUpdate(WorkflowRunEntity, {
1188
+ id: runId
1189
+ }, data);
1190
+ if (affected === 0) await em.findOneOrFail(WorkflowRunEntity, {
1191
+ id: runId
1192
+ });
1193
+ } else {
1194
+ await em.findOneOrFail(WorkflowRunEntity, {
1195
+ id: runId
1196
+ });
1197
+ }
1195
1198
  if ("searchAttributes" in patch) await this.reindexAttributes(runId, patch.searchAttributes);
1196
1199
  }
1197
1200
  async updateRunIf(runId, expectedStatuses, inputPatch) {
@@ -2016,6 +2019,27 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
2016
2019
  });
2017
2020
  return entity ? fromCheckpointEntity(entity) : void 0;
2018
2021
  }
2022
+ async hasCheckpoints(runId, fromSeq, toSeq, statuses) {
2023
+ if (statuses.length === 0) return false;
2024
+ const row = await this.fork().findOne(StepCheckpointEntity, {
2025
+ runId,
2026
+ seq: {
2027
+ $gte: fromSeq,
2028
+ $lte: toSeq
2029
+ },
2030
+ status: {
2031
+ $in: statuses
2032
+ }
2033
+ }, {
2034
+ fields: [
2035
+ "seq"
2036
+ ],
2037
+ orderBy: {
2038
+ seq: "desc"
2039
+ }
2040
+ });
2041
+ return row !== null;
2042
+ }
2019
2043
  async countCheckpoints(runId, fromSeq, toSeq, statuses) {
2020
2044
  if (statuses.length === 0) return 0;
2021
2045
  return this.fork().count(StepCheckpointEntity, {