@dudousxd/nestjs-durable-core 0.35.0 → 0.36.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.d.cts CHANGED
@@ -417,6 +417,15 @@ interface StateStore {
417
417
  * No-op if the run doesn't exist. (Token-keyed buffered signals are transient and left alone.)
418
418
  */
419
419
  deleteRun(runId: string): Promise<void>;
420
+ /**
421
+ * Hard-delete up to `limit` terminal runs that fall OUTSIDE `policy` (oldest / over the count cap
422
+ * first), cascading to their child rows exactly like {@link deleteRun}. Returns how many runs were
423
+ * deleted — call again while it returns `limit` to drain a large backlog in bounded batches.
424
+ *
425
+ * Optional: only adapters that implement a bulk prune provide it; the retention poller no-ops with a
426
+ * warning when the configured store omits it. See {@link RetentionPolicy} for the keep/prune rule.
427
+ */
428
+ pruneTerminalRuns?(policy: RetentionPolicy, nowMs: number, limit: number): Promise<number>;
420
429
  getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
421
430
  /**
422
431
  * Persist a checkpoint and advance the run atomically. Durable semantics depend on this
@@ -491,6 +500,26 @@ interface StateStore {
491
500
  */
492
501
  listCheckpointsByNamePrefix?(runId: string, prefixes: string[]): Promise<StepCheckpoint[]>;
493
502
  }
503
+ /** The terminal run statuses — a run in one of these is finished and will never change on its own.
504
+ * Only these are eligible for retention pruning (a {@link RetentionPolicy} targeting a non-terminal
505
+ * status would race the engine and delete live work). */
506
+ declare const TERMINAL_RUN_STATUSES: readonly RunStatus[];
507
+ /**
508
+ * One retention rule for hard-pruning terminal run history. Within `statuses` (terminal only), a run
509
+ * is KEPT only if it satisfies EVERY bound you set, and pruned the moment it violates any:
510
+ * - `maxAgeMs` — prune runs whose `updatedAt` (≈ the time they reached terminal) is older than
511
+ * `now - maxAgeMs`.
512
+ * - `maxCount` — keep only the `maxCount` most-recent (by `updatedAt`) runs in the status set; prune
513
+ * everything past that.
514
+ *
515
+ * Set one or both (both = the most-restrictive wins: capped at `maxCount` rows AND nothing older than
516
+ * `maxAgeMs`). Statuses not named by any policy are never pruned.
517
+ */
518
+ interface RetentionPolicy {
519
+ statuses: RunStatus[];
520
+ maxAgeMs?: number;
521
+ maxCount?: number;
522
+ }
494
523
  /** Typed, queryable per-run data — exact values for `eq`/`ne`, numbers/strings for range ops. */
495
524
  type SearchAttributes = Record<string, string | number | boolean>;
496
525
  type AttributeOp = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte';
@@ -2359,4 +2388,4 @@ declare class InMemoryTransport implements Transport, ControlPlane {
2359
2388
  onControl(handler: (msg: ControlMessage) => void): void;
2360
2389
  }
2361
2390
 
2362
- export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AttributeFilter, type AttributeOp, type BackoffStrategy, type ChildCallOptions, CodecStateStore, ContinueAsNew, type ControlMessage, type ControlPlane, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, type DurableWebhook, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, EventAccumulators, type EventBatchConfig, FatalError, GatherError, type GroupHealth, type Heartbeat, type HistoryEvent, InMemoryAdmissionBackend, InMemoryStateStore, InMemoryTransport, type MetricsCollector, type MetricsSnapshot, type NamedTransport, NonDeterminismError, type PayloadCodec, type QueueConfig, QueueController, type RemoteStepConfig, type RemoteStepDef, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RunAttributeRow, type RunDispatcher, type RunQuery, type RunResult, type RunSchedulesOptions, type RunStatus, STATE_STORE, STATE_STORE_CANONICAL, type ScheduledWorkflow, type SearchAttributes, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StartOptions, type StateStore, type StepCheckpoint, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepResult, type StoreTransaction, type SubProcessHandle, TRANSPORT, TRANSPORT_CANONICAL, type Transport, type UpdateResult, type UpdateValidator, WORKFLOW_NAME_KEY, type WorkerHeartbeat, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRun, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, applyAttributeQuery, attributeColumnFor, attributeOperand, breakpointToken, collectMetrics, createStepLogger, eventMatchOf, eventMatches, eventPrefix, eventToken, matchesAttributes, normalizeAttributeRows, parseDuration, prevCronFireMs, remoteStep, runSchedules, runStepHandler, scheduledRunId, sqlComparator, stepId, workflowName };
2391
+ export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AttributeFilter, type AttributeOp, type BackoffStrategy, type ChildCallOptions, CodecStateStore, ContinueAsNew, type ControlMessage, type ControlPlane, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, type DurableWebhook, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, EventAccumulators, type EventBatchConfig, FatalError, GatherError, type GroupHealth, type Heartbeat, type HistoryEvent, InMemoryAdmissionBackend, InMemoryStateStore, InMemoryTransport, type MetricsCollector, type MetricsSnapshot, type NamedTransport, NonDeterminismError, type PayloadCodec, type QueueConfig, QueueController, type RemoteStepConfig, type RemoteStepDef, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RunAttributeRow, type RunDispatcher, type RunQuery, type RunResult, type RunSchedulesOptions, type RunStatus, STATE_STORE, STATE_STORE_CANONICAL, type ScheduledWorkflow, type SearchAttributes, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StartOptions, type StateStore, type StepCheckpoint, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepResult, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type Transport, type UpdateResult, type UpdateValidator, WORKFLOW_NAME_KEY, type WorkerHeartbeat, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRun, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, applyAttributeQuery, attributeColumnFor, attributeOperand, breakpointToken, collectMetrics, createStepLogger, eventMatchOf, eventMatches, eventPrefix, eventToken, matchesAttributes, normalizeAttributeRows, parseDuration, prevCronFireMs, remoteStep, runSchedules, runStepHandler, scheduledRunId, sqlComparator, stepId, workflowName };
package/dist/index.d.ts CHANGED
@@ -417,6 +417,15 @@ interface StateStore {
417
417
  * No-op if the run doesn't exist. (Token-keyed buffered signals are transient and left alone.)
418
418
  */
419
419
  deleteRun(runId: string): Promise<void>;
420
+ /**
421
+ * Hard-delete up to `limit` terminal runs that fall OUTSIDE `policy` (oldest / over the count cap
422
+ * first), cascading to their child rows exactly like {@link deleteRun}. Returns how many runs were
423
+ * deleted — call again while it returns `limit` to drain a large backlog in bounded batches.
424
+ *
425
+ * Optional: only adapters that implement a bulk prune provide it; the retention poller no-ops with a
426
+ * warning when the configured store omits it. See {@link RetentionPolicy} for the keep/prune rule.
427
+ */
428
+ pruneTerminalRuns?(policy: RetentionPolicy, nowMs: number, limit: number): Promise<number>;
420
429
  getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
421
430
  /**
422
431
  * Persist a checkpoint and advance the run atomically. Durable semantics depend on this
@@ -491,6 +500,26 @@ interface StateStore {
491
500
  */
492
501
  listCheckpointsByNamePrefix?(runId: string, prefixes: string[]): Promise<StepCheckpoint[]>;
493
502
  }
503
+ /** The terminal run statuses — a run in one of these is finished and will never change on its own.
504
+ * Only these are eligible for retention pruning (a {@link RetentionPolicy} targeting a non-terminal
505
+ * status would race the engine and delete live work). */
506
+ declare const TERMINAL_RUN_STATUSES: readonly RunStatus[];
507
+ /**
508
+ * One retention rule for hard-pruning terminal run history. Within `statuses` (terminal only), a run
509
+ * is KEPT only if it satisfies EVERY bound you set, and pruned the moment it violates any:
510
+ * - `maxAgeMs` — prune runs whose `updatedAt` (≈ the time they reached terminal) is older than
511
+ * `now - maxAgeMs`.
512
+ * - `maxCount` — keep only the `maxCount` most-recent (by `updatedAt`) runs in the status set; prune
513
+ * everything past that.
514
+ *
515
+ * Set one or both (both = the most-restrictive wins: capped at `maxCount` rows AND nothing older than
516
+ * `maxAgeMs`). Statuses not named by any policy are never pruned.
517
+ */
518
+ interface RetentionPolicy {
519
+ statuses: RunStatus[];
520
+ maxAgeMs?: number;
521
+ maxCount?: number;
522
+ }
494
523
  /** Typed, queryable per-run data — exact values for `eq`/`ne`, numbers/strings for range ops. */
495
524
  type SearchAttributes = Record<string, string | number | boolean>;
496
525
  type AttributeOp = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte';
@@ -2359,4 +2388,4 @@ declare class InMemoryTransport implements Transport, ControlPlane {
2359
2388
  onControl(handler: (msg: ControlMessage) => void): void;
2360
2389
  }
2361
2390
 
2362
- export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AttributeFilter, type AttributeOp, type BackoffStrategy, type ChildCallOptions, CodecStateStore, ContinueAsNew, type ControlMessage, type ControlPlane, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, type DurableWebhook, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, EventAccumulators, type EventBatchConfig, FatalError, GatherError, type GroupHealth, type Heartbeat, type HistoryEvent, InMemoryAdmissionBackend, InMemoryStateStore, InMemoryTransport, type MetricsCollector, type MetricsSnapshot, type NamedTransport, NonDeterminismError, type PayloadCodec, type QueueConfig, QueueController, type RemoteStepConfig, type RemoteStepDef, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RunAttributeRow, type RunDispatcher, type RunQuery, type RunResult, type RunSchedulesOptions, type RunStatus, STATE_STORE, STATE_STORE_CANONICAL, type ScheduledWorkflow, type SearchAttributes, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StartOptions, type StateStore, type StepCheckpoint, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepResult, type StoreTransaction, type SubProcessHandle, TRANSPORT, TRANSPORT_CANONICAL, type Transport, type UpdateResult, type UpdateValidator, WORKFLOW_NAME_KEY, type WorkerHeartbeat, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRun, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, applyAttributeQuery, attributeColumnFor, attributeOperand, breakpointToken, collectMetrics, createStepLogger, eventMatchOf, eventMatches, eventPrefix, eventToken, matchesAttributes, normalizeAttributeRows, parseDuration, prevCronFireMs, remoteStep, runSchedules, runStepHandler, scheduledRunId, sqlComparator, stepId, workflowName };
2391
+ export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AttributeFilter, type AttributeOp, type BackoffStrategy, type ChildCallOptions, CodecStateStore, ContinueAsNew, type ControlMessage, type ControlPlane, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, type DurableWebhook, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, EventAccumulators, type EventBatchConfig, FatalError, GatherError, type GroupHealth, type Heartbeat, type HistoryEvent, InMemoryAdmissionBackend, InMemoryStateStore, InMemoryTransport, type MetricsCollector, type MetricsSnapshot, type NamedTransport, NonDeterminismError, type PayloadCodec, type QueueConfig, QueueController, type RemoteStepConfig, type RemoteStepDef, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RunAttributeRow, type RunDispatcher, type RunQuery, type RunResult, type RunSchedulesOptions, type RunStatus, STATE_STORE, STATE_STORE_CANONICAL, type ScheduledWorkflow, type SearchAttributes, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StartOptions, type StateStore, type StepCheckpoint, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepResult, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type Transport, type UpdateResult, type UpdateValidator, WORKFLOW_NAME_KEY, type WorkerHeartbeat, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRun, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, applyAttributeQuery, attributeColumnFor, attributeOperand, breakpointToken, collectMetrics, createStepLogger, eventMatchOf, eventMatches, eventPrefix, eventToken, matchesAttributes, normalizeAttributeRows, parseDuration, prevCronFireMs, remoteStep, runSchedules, runStepHandler, scheduledRunId, sqlComparator, stepId, workflowName };
package/dist/index.js CHANGED
@@ -3413,6 +3413,14 @@ var RemoteStepError = class extends Error {
3413
3413
  }
3414
3414
  };
3415
3415
 
3416
+ // src/interfaces.ts
3417
+ var TERMINAL_RUN_STATUSES = [
3418
+ "completed",
3419
+ "failed",
3420
+ "cancelled",
3421
+ "dead"
3422
+ ];
3423
+
3416
3424
  // src/remote-step-factory.ts
3417
3425
  function remoteStep(config) {
3418
3426
  return {
@@ -4225,6 +4233,7 @@ export {
4225
4233
  STATE_STORE_CANONICAL,
4226
4234
  SignalTimeoutError,
4227
4235
  SingletonQueueFullError,
4236
+ TERMINAL_RUN_STATUSES,
4228
4237
  TRANSPORT,
4229
4238
  TRANSPORT_CANONICAL,
4230
4239
  WORKFLOW_NAME_KEY,