@dudousxd/nestjs-durable-store-mikro-orm 0.33.8 → 0.34.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
@@ -667,7 +667,7 @@ __name(durableEntities, "durableEntities");
667
667
  var ENTITIES = durableEntities();
668
668
 
669
669
  // src/mikro-orm-state-store.ts
670
- import { ENGINE_MINTED_TAG_PREFIXES, RUN_VALUE_FACET_LIMIT, SINGLETON_ACTIVE_STATUSES, SINGLETON_LOCK_CHUNK, TERMINAL_RUN_STATUSES, attributePredicateOperands, axisIsRunColumn, clearTerminalSingletonAdmission, facetOrigin, mergeRunFacetRows, normalizeAttributeRows, parseDuration, singletonAdmissionDenialPatch, singletonAdmissionTags, singletonClaimantIds } from "@dudousxd/nestjs-durable-core";
670
+ import { ENGINE_MINTED_TAG_PREFIXES, LIFECYCLE_REGISTRY_WORKFLOW, RUN_VALUE_FACET_LIMIT, SINGLETON_ACTIVE_STATUSES, SINGLETON_LOCK_CHUNK, TERMINAL_RUN_STATUSES, attributePredicateOperands, axisIsRunColumn, clearTerminalSingletonAdmission, facetOrigin, mergeRunFacetRows, normalizeAttributeRows, parseDuration, retentionKeeps, singletonAdmissionDenialPatch, singletonAdmissionTags, singletonClaimantIds } from "@dudousxd/nestjs-durable-core";
671
671
  import { LockMode, raw } from "@mikro-orm/core";
672
672
 
673
673
  // src/schema.ts
@@ -1049,6 +1049,9 @@ async function alignDurableCollation(orm) {
1049
1049
  __name(alignDurableCollation, "alignDurableCollation");
1050
1050
 
1051
1051
  // src/mikro-orm-state-store.ts
1052
+ var RETENTION_EXCLUDED = [
1053
+ LIFECYCLE_REGISTRY_WORKFLOW
1054
+ ];
1052
1055
  var MikroOrmStateStore = class _MikroOrmStateStore {
1053
1056
  static {
1054
1057
  __name(this, "MikroOrmStateStore");
@@ -1276,13 +1279,16 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1276
1279
  const idCol = meta.properties.id?.fieldNames?.[0] ?? "id";
1277
1280
  const query = {
1278
1281
  ...policy.scope ?? {},
1279
- statuses
1282
+ statuses,
1283
+ excludeWorkflows: RETENTION_EXCLUDED
1280
1284
  };
1285
+ const tagsCol = meta.properties.tags?.fieldNames?.[0] ?? "tags";
1281
1286
  const scoped = /* @__PURE__ */ __name((extra) => this.runQueryBuilder(em, query, {
1282
1287
  ...this.runWhere(query),
1283
1288
  ...extra ?? {}
1284
1289
  }).select([
1285
- `r.${idCol}`
1290
+ `r.${idCol}`,
1291
+ `r.${tagsCol}`
1286
1292
  ]), "scoped");
1287
1293
  const ids = /* @__PURE__ */ new Set();
1288
1294
  if (policy.maxAge != null) {
@@ -1294,7 +1300,9 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1294
1300
  }).orderBy({
1295
1301
  "r.updatedAt": "asc"
1296
1302
  }).limit(limit).execute();
1297
- for (const r of rows) ids.add(String(r[idCol] ?? r.id));
1303
+ for (const r of rows) {
1304
+ if (!retentionKeeps(r[tagsCol] ?? r.tags)) ids.add(String(r[idCol] ?? r.id));
1305
+ }
1298
1306
  }
1299
1307
  if (policy.maxCount != null && ids.size < limit) {
1300
1308
  const rows = await scoped().orderBy({
@@ -1303,7 +1311,7 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1303
1311
  }).limit(limit).offset(policy.maxCount).execute();
1304
1312
  for (const r of rows) {
1305
1313
  if (ids.size >= limit) break;
1306
- ids.add(String(r[idCol] ?? r.id));
1314
+ if (!retentionKeeps(r[tagsCol] ?? r.tags)) ids.add(String(r[idCol] ?? r.id));
1307
1315
  }
1308
1316
  }
1309
1317
  const idList = [
@@ -1601,6 +1609,18 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1601
1609
  $in: query.workflows
1602
1610
  }
1603
1611
  });
1612
+ if (query.excludeWorkflows?.length) and.push({
1613
+ workflow: {
1614
+ $nin: query.excludeWorkflows
1615
+ }
1616
+ });
1617
+ if (query.updatedAfter !== void 0) {
1618
+ and.push({
1619
+ updatedAt: {
1620
+ $gte: new Date(query.updatedAfter)
1621
+ }
1622
+ });
1623
+ }
1604
1624
  if (query.namespace !== void 0) where.namespace = query.namespace;
1605
1625
  if (query.namespaces) and.push({
1606
1626
  namespace: {