@dudousxd/nestjs-durable-store-drizzle 0.24.6 → 0.25.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.js CHANGED
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/drizzle-state-store.ts
5
- 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";
5
+ import { LIFECYCLE_REGISTRY_WORKFLOW, RUN_VALUE_FACET_SCAN, SINGLETON_ACTIVE_STATUSES, TERMINAL_RUN_STATUSES, attributePredicateOperands, axisIsRunColumn, clearTerminalSingletonAdmission, mergeRunFacetRows, mergeRunValueFacetRows, normalizeAttributeRows, parseDuration, retentionKeeps, runValueFacetsFromRuns, singletonAdmissionDenialPatch, singletonAdmissionTags } from "@dudousxd/nestjs-durable-core";
6
6
  import { and, asc, desc, eq, exists, getTableColumns, gt, gte, inArray, isNotNull, isNull, like, lt, lte, notInArray, or, sql } from "drizzle-orm";
7
7
 
8
8
  // src/schema.ts
@@ -216,6 +216,9 @@ function durableManagedTables() {
216
216
  __name(durableManagedTables, "durableManagedTables");
217
217
 
218
218
  // src/drizzle-state-store.ts
219
+ var RETENTION_EXCLUDED = [
220
+ LIFECYCLE_REGISTRY_WORKFLOW
221
+ ];
219
222
  function anyOf(conditions) {
220
223
  const present = conditions.filter((c) => c !== void 0);
221
224
  return present.length ? or(...present) : sql`1 = 0`;
@@ -324,23 +327,26 @@ var DrizzleStateStore = class {
324
327
  if (policy.maxAge == null && policy.maxCount == null) return 0;
325
328
  const scoped = this.runFilters({
326
329
  ...policy.scope ?? {},
327
- statuses
330
+ statuses,
331
+ excludeWorkflows: RETENTION_EXCLUDED
328
332
  });
329
333
  const ids = /* @__PURE__ */ new Set();
330
334
  if (policy.maxAge != null) {
331
335
  const cutoff = nowMs - parseDuration(policy.maxAge);
332
336
  const rows = await this.db.select({
333
- id: workflowRuns.id
337
+ id: workflowRuns.id,
338
+ tags: workflowRuns.tags
334
339
  }).from(workflowRuns).where(and(...scoped, lt(workflowRuns.updatedAt, cutoff))).orderBy(asc(workflowRuns.updatedAt)).limit(limit);
335
- for (const r of rows) ids.add(r.id);
340
+ for (const r of rows) if (!retentionKeeps(r.tags)) ids.add(r.id);
336
341
  }
337
342
  if (policy.maxCount != null && ids.size < limit) {
338
343
  const rows = await this.db.select({
339
- id: workflowRuns.id
344
+ id: workflowRuns.id,
345
+ tags: workflowRuns.tags
340
346
  }).from(workflowRuns).where(and(...scoped)).orderBy(desc(workflowRuns.updatedAt), desc(workflowRuns.id)).limit(limit).offset(policy.maxCount);
341
347
  for (const r of rows) {
342
348
  if (ids.size >= limit) break;
343
- ids.add(r.id);
349
+ if (!retentionKeeps(r.tags)) ids.add(r.id);
344
350
  }
345
351
  }
346
352
  const doomed = [
@@ -589,6 +595,8 @@ var DrizzleStateStore = class {
589
595
  // The plural form of each axis below: ORed within itself, ANDed with everything else, and an
590
596
  // empty set matches nothing — the same contract `statuses` already had.
591
597
  query.workflows ? anyOf(query.workflows.map((w) => eq(workflowRuns.workflow, w))) : void 0,
598
+ query.excludeWorkflows?.length ? notInArray(workflowRuns.workflow, query.excludeWorkflows) : void 0,
599
+ query.updatedAfter !== void 0 ? gte(workflowRuns.updatedAt, query.updatedAfter) : void 0,
592
600
  // The tenant boundary, ANDed with everything else. This is not only a dashboard facet: it is
593
601
  // the fourth namespace-scoped worker path, because `engine.sweepTimeouts` cancels runs past
594
602
  // their `executionTimeout` via `listRuns({ workflow, status, namespace })` — unscoped here, a