@dudousxd/nestjs-durable-store-prisma 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 CHANGED
@@ -28,6 +28,9 @@ module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/prisma-state-store.ts
30
30
  var import_nestjs_durable_core = require("@dudousxd/nestjs-durable-core");
31
+ var RETENTION_EXCLUDED = [
32
+ import_nestjs_durable_core.LIFECYCLE_REGISTRY_WORKFLOW
33
+ ];
31
34
  function namespaceWhere(namespace) {
32
35
  if (namespace === void 0) return {};
33
36
  return {
@@ -244,7 +247,8 @@ var PrismaStateStore = class {
244
247
  if (policy.maxAge == null && policy.maxCount == null) return 0;
245
248
  const scoped = this.runWhere({
246
249
  ...policy.scope ?? {},
247
- statuses
250
+ statuses,
251
+ excludeWorkflows: RETENTION_EXCLUDED
248
252
  });
249
253
  const ids = /* @__PURE__ */ new Set();
250
254
  if (policy.maxAge != null) {
@@ -261,20 +265,22 @@ var PrismaStateStore = class {
261
265
  ]
262
266
  },
263
267
  select: {
264
- id: true
268
+ id: true,
269
+ tags: true
265
270
  },
266
271
  orderBy: {
267
272
  updatedAt: "asc"
268
273
  },
269
274
  take: limit
270
275
  });
271
- for (const r of rows) ids.add(r.id);
276
+ for (const r of rows) if (!(0, import_nestjs_durable_core.retentionKeeps)(r.tags)) ids.add(r.id);
272
277
  }
273
278
  if (policy.maxCount != null && ids.size < limit) {
274
279
  const rows = await this.db.durableWorkflowRun.findMany({
275
280
  where: scoped,
276
281
  select: {
277
- id: true
282
+ id: true,
283
+ tags: true
278
284
  },
279
285
  orderBy: [
280
286
  {
@@ -289,7 +295,7 @@ var PrismaStateStore = class {
289
295
  });
290
296
  for (const r of rows) {
291
297
  if (ids.size >= limit) break;
292
- ids.add(r.id);
298
+ if (!(0, import_nestjs_durable_core.retentionKeeps)(r.tags)) ids.add(r.id);
293
299
  }
294
300
  }
295
301
  const doomed = [
@@ -635,6 +641,18 @@ var PrismaStateStore = class {
635
641
  if (query.workflows) and.push(anyOf(query.workflows.map((w) => ({
636
642
  workflow: w
637
643
  }))));
644
+ if (query.excludeWorkflows?.length) and.push({
645
+ workflow: {
646
+ notIn: query.excludeWorkflows
647
+ }
648
+ });
649
+ if (query.updatedAfter !== void 0) {
650
+ and.push({
651
+ updatedAt: {
652
+ gte: new Date(query.updatedAfter)
653
+ }
654
+ });
655
+ }
638
656
  if (query.namespaces) and.push(anyOf(query.namespaces.map((n) => ({
639
657
  namespace: n
640
658
  }))));