@dudousxd/nestjs-durable-store-drizzle 0.24.5 → 0.24.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/pg/index.cjs CHANGED
@@ -463,10 +463,10 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
463
463
  }
464
464
  async tryAdmitSingleton(runId, tag, workflow, limit, retryWakeAt) {
465
465
  return this.db.transaction(async (tx) => {
466
- const where = (0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(durableWorkflowRuns.workflow, workflow), (0, import_drizzle_orm4.inArray)(durableWorkflowRuns.status, import_nestjs_durable_core.SINGLETON_ACTIVE_STATUSES), this.scope());
467
- await tx.update(durableWorkflowRuns).set({
468
- workflow
469
- }).where(where);
466
+ const where = (0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(durableWorkflowRuns.workflow, workflow), (0, import_drizzle_orm4.inArray)(durableWorkflowRuns.status, import_nestjs_durable_core.SINGLETON_ACTIVE_STATUSES), hasTag(tag), this.scope());
467
+ await tx.select({
468
+ id: durableWorkflowRuns.id
469
+ }).from(durableWorkflowRuns).where(where).orderBy((0, import_drizzle_orm4.asc)(durableWorkflowRuns.id)).for("update");
470
470
  const rows = await tx.select().from(durableWorkflowRuns).where(where);
471
471
  const runs = rows.map(fromRunRow);
472
472
  const tags = (0, import_nestjs_durable_core.singletonAdmissionTags)(runs, runId, tag, workflow, limit);
@@ -482,6 +482,11 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
482
482
  });
483
483
  }
484
484
  async createRun(run) {
485
+ if ((0, import_nestjs_durable_core.normalizeAttributeRows)(run.id, run.searchAttributes).length === 0) {
486
+ await this.db.insert(durableWorkflowRuns).values(toRunRow(run));
487
+ await this.db.delete(durableRunAttributes).where((0, import_drizzle_orm4.eq)(durableRunAttributes.runId, run.id));
488
+ return;
489
+ }
485
490
  await this.db.transaction(async (tx) => {
486
491
  await tx.insert(durableWorkflowRuns).values(toRunRow(run));
487
492
  await reindexAttributes(tx, run.id, run.searchAttributes);
@@ -492,6 +497,10 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
492
497
  const row = toRunPatch(patch);
493
498
  const reindex = "searchAttributes" in patch;
494
499
  if (!Object.keys(row).length && !reindex) return;
500
+ if (!reindex) {
501
+ await this.db.update(durableWorkflowRuns).set(row).where((0, import_drizzle_orm4.eq)(durableWorkflowRuns.id, runId));
502
+ return;
503
+ }
495
504
  await this.db.transaction(async (tx) => {
496
505
  if (Object.keys(row).length) await tx.update(durableWorkflowRuns).set(row).where((0, import_drizzle_orm4.eq)(durableWorkflowRuns.id, runId));
497
506
  if (reindex) await reindexAttributes(tx, runId, patch.searchAttributes);
@@ -1133,6 +1142,9 @@ async function reindexAttributes(db, runId, attributes) {
1133
1142
  }
1134
1143
  __name(reindexAttributes, "reindexAttributes");
1135
1144
  async function deleteRunsCascade(db, runIds) {
1145
+ await db.select({
1146
+ id: durableWorkflowRuns.id
1147
+ }).from(durableWorkflowRuns).where((0, import_drizzle_orm4.inArray)(durableWorkflowRuns.id, runIds)).orderBy((0, import_drizzle_orm4.asc)(durableWorkflowRuns.id)).for("update");
1136
1148
  await db.delete(durableStepCheckpoints).where((0, import_drizzle_orm4.inArray)(durableStepCheckpoints.runId, runIds));
1137
1149
  await db.delete(durableSignalWaiters).where((0, import_drizzle_orm4.inArray)(durableSignalWaiters.runId, runIds));
1138
1150
  await db.delete(durableRunAttributes).where((0, import_drizzle_orm4.inArray)(durableRunAttributes.runId, runIds));