@dudousxd/nestjs-durable-store-drizzle 0.24.1 → 0.24.3

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.
@@ -1,6 +1,6 @@
1
1
  import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
2
2
  import { PgDatabase } from 'drizzle-orm/pg-core';
3
- import { StateStore, WorkflowRun, RunStatus, RetentionPolicy, StepCheckpoint, StoreTransaction, OwnedLeaseReclaim, RunQuery, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, ScheduleRecord, ScheduleQuery, CheckpointStat, CheckpointQuery, SignalWaiter, ChildWait } from '@dudousxd/nestjs-durable-core';
3
+ import { StateStore, WorkflowRun, RunStatus, RetentionPolicy, StepCheckpoint, StoreTransaction, OwnedLeaseReclaim, RunQuery, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, ScheduleRecord, ScheduleQuery, CheckpointStat, CheckpointQuery, SignalWaiter, ChildWait, BufferedSignalRow } from '@dudousxd/nestjs-durable-core';
4
4
  import { SQL } from 'drizzle-orm';
5
5
 
6
6
  /**
@@ -120,7 +120,9 @@ declare class DrizzlePgStateStore implements StateStore {
120
120
  deleteRuns(runIds: string[]): Promise<void>;
121
121
  pruneTerminalRuns(policy: RetentionPolicy, nowMs: number, limit: number): Promise<number>;
122
122
  getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
123
+ getCheckpoints(runId: string, seqs: number[]): Promise<StepCheckpoint[]>;
123
124
  saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
125
+ saveCheckpoints(checkpoints: StepCheckpoint[]): Promise<void>;
124
126
  saveCheckpointIfPending(checkpoint: StepCheckpoint): Promise<boolean>;
125
127
  saveCheckpointsIfPending(checkpoints: StepCheckpoint[]): Promise<boolean[]>;
126
128
  transaction<T>(work: (tx: StoreTransaction) => Promise<T>): Promise<T>;
@@ -176,6 +178,8 @@ declare class DrizzlePgStateStore implements StateStore {
176
178
  takeBufferedSignal(token: string): Promise<{
177
179
  payload: unknown;
178
180
  } | null>;
181
+ listBufferedSignals(tokenPrefix: string, afterId: string | undefined, limit: number): Promise<BufferedSignalRow[]>;
182
+ deleteBufferedSignals(ids: string[]): Promise<void>;
179
183
  bufferEvent(input: {
180
184
  name: string;
181
185
  payload: unknown;
@@ -1,6 +1,6 @@
1
1
  import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
2
2
  import { PgDatabase } from 'drizzle-orm/pg-core';
3
- import { StateStore, WorkflowRun, RunStatus, RetentionPolicy, StepCheckpoint, StoreTransaction, OwnedLeaseReclaim, RunQuery, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, ScheduleRecord, ScheduleQuery, CheckpointStat, CheckpointQuery, SignalWaiter, ChildWait } from '@dudousxd/nestjs-durable-core';
3
+ import { StateStore, WorkflowRun, RunStatus, RetentionPolicy, StepCheckpoint, StoreTransaction, OwnedLeaseReclaim, RunQuery, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, ScheduleRecord, ScheduleQuery, CheckpointStat, CheckpointQuery, SignalWaiter, ChildWait, BufferedSignalRow } from '@dudousxd/nestjs-durable-core';
4
4
  import { SQL } from 'drizzle-orm';
5
5
 
6
6
  /**
@@ -120,7 +120,9 @@ declare class DrizzlePgStateStore implements StateStore {
120
120
  deleteRuns(runIds: string[]): Promise<void>;
121
121
  pruneTerminalRuns(policy: RetentionPolicy, nowMs: number, limit: number): Promise<number>;
122
122
  getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
123
+ getCheckpoints(runId: string, seqs: number[]): Promise<StepCheckpoint[]>;
123
124
  saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
125
+ saveCheckpoints(checkpoints: StepCheckpoint[]): Promise<void>;
124
126
  saveCheckpointIfPending(checkpoint: StepCheckpoint): Promise<boolean>;
125
127
  saveCheckpointsIfPending(checkpoints: StepCheckpoint[]): Promise<boolean[]>;
126
128
  transaction<T>(work: (tx: StoreTransaction) => Promise<T>): Promise<T>;
@@ -176,6 +178,8 @@ declare class DrizzlePgStateStore implements StateStore {
176
178
  takeBufferedSignal(token: string): Promise<{
177
179
  payload: unknown;
178
180
  } | null>;
181
+ listBufferedSignals(tokenPrefix: string, afterId: string | undefined, limit: number): Promise<BufferedSignalRow[]>;
182
+ deleteBufferedSignals(ids: string[]): Promise<void>;
179
183
  bufferEvent(input: {
180
184
  name: string;
181
185
  payload: unknown;
package/dist/pg/index.js CHANGED
@@ -199,7 +199,7 @@ __name(ensureDrizzlePgDurableSchema, "ensureDrizzlePgDurableSchema");
199
199
 
200
200
  // src/pg/drizzle-pg-state-store.ts
201
201
  import { RUN_VALUE_FACET_SCAN, SINGLETON_ACTIVE_STATUSES, TERMINAL_RUN_STATUSES, attributePredicateOperands, axisIsRunColumn, clearTerminalSingletonAdmission, mergeRunFacetRows, mergeRunValueFacetRows, normalizeAttributeRows, parseDuration, runValueFacetsFromRuns, singletonAdmissionDenialPatch, singletonAdmissionTags } from "@dudousxd/nestjs-durable-core";
202
- import { and, asc, desc, eq, exists, getTableColumns, gte, inArray, isNotNull, isNull, like, lt, lte, notInArray, or, sql as sql3 } from "drizzle-orm";
202
+ import { and, asc, desc, eq, exists, getTableColumns, gt, gte, inArray, isNotNull, isNull, like, lt, lte, notInArray, or, sql as sql3 } from "drizzle-orm";
203
203
 
204
204
  // src/pg/schema.ts
205
205
  import { getTableName } from "drizzle-orm";
@@ -539,9 +539,33 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
539
539
  const rows = await this.db.select().from(durableStepCheckpoints).where(and(eq(durableStepCheckpoints.runId, runId), eq(durableStepCheckpoints.seq, seq))).limit(1);
540
540
  return rows[0] ? fromCheckpointRow(rows[0]) : null;
541
541
  }
542
+ async getCheckpoints(runId, seqs) {
543
+ const unique = [
544
+ ...new Set(seqs)
545
+ ];
546
+ const rows = [];
547
+ for (let at = 0; at < unique.length; at += 500) {
548
+ rows.push(...await this.db.select().from(durableStepCheckpoints).where(and(eq(durableStepCheckpoints.runId, runId), inArray(durableStepCheckpoints.seq, unique.slice(at, at + 500)))));
549
+ }
550
+ return rows.sort((a, b) => a.seq - b.seq).map(fromCheckpointRow);
551
+ }
542
552
  async saveCheckpoint(checkpoint) {
543
553
  await upsertCheckpoint(this.db, checkpoint);
544
554
  }
555
+ async saveCheckpoints(checkpoints) {
556
+ if (checkpoints.length === 0) return;
557
+ await this.db.transaction(async (tx) => {
558
+ for (let at = 0; at < checkpoints.length; at += CHECKPOINT_BATCH_ROWS) {
559
+ await tx.insert(durableStepCheckpoints).values(checkpoints.slice(at, at + CHECKPOINT_BATCH_ROWS).map(toCheckpointRow)).onConflictDoUpdate({
560
+ target: [
561
+ durableStepCheckpoints.runId,
562
+ durableStepCheckpoints.seq
563
+ ],
564
+ set: excludedSet(durableStepCheckpoints)
565
+ });
566
+ }
567
+ });
568
+ }
545
569
  async saveCheckpointIfPending(checkpoint) {
546
570
  const { runId, seq, ...set } = toCheckpointRow(checkpoint);
547
571
  const rows = await this.db.update(durableStepCheckpoints).set(set).where(and(eq(durableStepCheckpoints.runId, runId), eq(durableStepCheckpoints.seq, seq), eq(durableStepCheckpoints.status, "pending"))).returning({
@@ -903,6 +927,18 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
903
927
  payload: row.payload ?? void 0
904
928
  } : null;
905
929
  }
930
+ async listBufferedSignals(tokenPrefix, afterId, limit) {
931
+ const rows = await this.db.select().from(durableBufferedSignals).where(and(like(durableBufferedSignals.token, `${escapeLike(tokenPrefix)}%`), afterId !== void 0 ? gt(durableBufferedSignals.id, Number(afterId)) : void 0)).orderBy(asc(durableBufferedSignals.id)).limit(limit);
932
+ return rows.filter((r) => r.token.startsWith(tokenPrefix)).map((r) => ({
933
+ id: String(r.id),
934
+ token: r.token,
935
+ payload: r.payload ?? void 0
936
+ }));
937
+ }
938
+ async deleteBufferedSignals(ids) {
939
+ if (ids.length === 0) return;
940
+ await this.db.delete(durableBufferedSignals).where(inArray(durableBufferedSignals.id, ids.map(Number)));
941
+ }
906
942
  async bufferEvent(input) {
907
943
  await this.db.insert(durableBufferedEvents).values({
908
944
  id: input.id,