@dudousxd/nestjs-durable-store-drizzle 0.24.7 → 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.cjs +13 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/pg/index.cjs +13 -5
- package/dist/pg/index.cjs.map +1 -1
- package/dist/pg/index.js +14 -6
- package/dist/pg/index.js.map +1 -1
- package/package.json +3 -3
package/dist/pg/index.js
CHANGED
|
@@ -198,7 +198,7 @@ async function ensureDrizzlePgDurableSchema(db, options = {}) {
|
|
|
198
198
|
__name(ensureDrizzlePgDurableSchema, "ensureDrizzlePgDurableSchema");
|
|
199
199
|
|
|
200
200
|
// src/pg/drizzle-pg-state-store.ts
|
|
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";
|
|
201
|
+
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";
|
|
202
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
|
|
@@ -366,6 +366,9 @@ function durablePgManagedTables() {
|
|
|
366
366
|
__name(durablePgManagedTables, "durablePgManagedTables");
|
|
367
367
|
|
|
368
368
|
// src/pg/drizzle-pg-state-store.ts
|
|
369
|
+
var RETENTION_EXCLUDED = [
|
|
370
|
+
LIFECYCLE_REGISTRY_WORKFLOW
|
|
371
|
+
];
|
|
369
372
|
function anyOf(conditions) {
|
|
370
373
|
const present = conditions.filter((c) => c !== void 0);
|
|
371
374
|
return present.length ? or(...present) : sql3`1 = 0`;
|
|
@@ -512,28 +515,31 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
512
515
|
if (policy.maxAge == null && policy.maxCount == null) return 0;
|
|
513
516
|
const scoped = this.runFilters({
|
|
514
517
|
...policy.scope ?? {},
|
|
515
|
-
statuses
|
|
518
|
+
statuses,
|
|
519
|
+
excludeWorkflows: RETENTION_EXCLUDED
|
|
516
520
|
});
|
|
517
521
|
return this.db.transaction(async (tx) => {
|
|
518
522
|
const ids = /* @__PURE__ */ new Set();
|
|
519
523
|
if (policy.maxAge != null) {
|
|
520
524
|
const cutoff = new Date(nowMs - parseDuration(policy.maxAge));
|
|
521
525
|
const rows = await tx.select({
|
|
522
|
-
id: durableWorkflowRuns.id
|
|
526
|
+
id: durableWorkflowRuns.id,
|
|
527
|
+
tags: durableWorkflowRuns.tags
|
|
523
528
|
}).from(durableWorkflowRuns).where(and(...scoped, lt(durableWorkflowRuns.updatedAt, cutoff))).orderBy(asc(durableWorkflowRuns.updatedAt)).limit(limit).for("update", {
|
|
524
529
|
skipLocked: true
|
|
525
530
|
});
|
|
526
|
-
for (const r of rows) ids.add(r.id);
|
|
531
|
+
for (const r of rows) if (!retentionKeeps(r.tags)) ids.add(r.id);
|
|
527
532
|
}
|
|
528
533
|
if (policy.maxCount != null && ids.size < limit) {
|
|
529
534
|
const rows = await tx.select({
|
|
530
|
-
id: durableWorkflowRuns.id
|
|
535
|
+
id: durableWorkflowRuns.id,
|
|
536
|
+
tags: durableWorkflowRuns.tags
|
|
531
537
|
}).from(durableWorkflowRuns).where(and(...scoped)).orderBy(desc(durableWorkflowRuns.updatedAt), desc(durableWorkflowRuns.id)).limit(limit).offset(policy.maxCount).for("update", {
|
|
532
538
|
skipLocked: true
|
|
533
539
|
});
|
|
534
540
|
for (const r of rows) {
|
|
535
541
|
if (ids.size >= limit) break;
|
|
536
|
-
ids.add(r.id);
|
|
542
|
+
if (!retentionKeeps(r.tags)) ids.add(r.id);
|
|
537
543
|
}
|
|
538
544
|
}
|
|
539
545
|
if (ids.size === 0) return 0;
|
|
@@ -711,6 +717,8 @@ var DrizzlePgStateStore = class _DrizzlePgStateStore {
|
|
|
711
717
|
this.scope(),
|
|
712
718
|
query.workflow ? eq(durableWorkflowRuns.workflow, query.workflow) : void 0,
|
|
713
719
|
query.workflows ? query.workflows.length ? inArray(durableWorkflowRuns.workflow, query.workflows) : sql3`1 = 0` : void 0,
|
|
720
|
+
query.excludeWorkflows?.length ? notInArray(durableWorkflowRuns.workflow, query.excludeWorkflows) : void 0,
|
|
721
|
+
query.updatedAfter !== void 0 ? gte(durableWorkflowRuns.updatedAt, new Date(query.updatedAfter)) : void 0,
|
|
714
722
|
// The tenant boundary. Also the engine's execution-timeout sweep path
|
|
715
723
|
// (`listRuns({ workflow, status, namespace })`) — unscoped, it would cancel another tenant's runs.
|
|
716
724
|
namespaceFilter(query.namespace),
|