@dudousxd/nestjs-durable-store-mikro-orm 0.24.0 → 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
@@ -547,7 +547,7 @@ __name(durableEntities, "durableEntities");
547
547
  var ENTITIES = durableEntities();
548
548
 
549
549
  // src/mikro-orm-state-store.ts
550
- import { RUN_VALUE_FACET_SCAN, attributePredicateOperands, axisIsRunColumn, mergeRunFacetRows, mergeRunValueFacetRows, normalizeAttributeRows, parseDuration, runValueFacetsFromRuns } from "@dudousxd/nestjs-durable-core";
550
+ import { RUN_VALUE_FACET_SCAN, attributePredicateOperands, axisIsRunColumn, mergeRunFacetRows, mergeRunValueFacetRows, normalizeAttributeRows, parseDuration } from "@dudousxd/nestjs-durable-core";
551
551
  import { raw } from "@mikro-orm/core";
552
552
 
553
553
  // src/schema.ts
@@ -1157,11 +1157,7 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1157
1157
  * page of runs instead — see {@link RunValueFacetOptions.scan}. */
1158
1158
  async runValueFacets(axis, query, opts) {
1159
1159
  if (!axisIsRunColumn(axis)) {
1160
- const runs = await this.listRuns({
1161
- ...query,
1162
- limit: opts?.scan ?? RUN_VALUE_FACET_SCAN
1163
- });
1164
- return runValueFacetsFromRuns(runs, axis, opts);
1160
+ return this.scannedValueFacets(axis, query, opts);
1165
1161
  }
1166
1162
  const em = this.fork();
1167
1163
  const meta = em.getMetadata().get(WorkflowRunEntity);
@@ -1176,6 +1172,63 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1176
1172
  count: Number(row.count)
1177
1173
  })), opts);
1178
1174
  }
1175
+ /**
1176
+ * The axes whose values do not live in a column of the run row: `tag` (inside a JSON array) and the
1177
+ * two search-attribute axes (a side table). Both read the newest `scan` matching runs.
1178
+ *
1179
+ * Neither reads a run's PAYLOAD. The obvious implementation — page `listRuns` and count in
1180
+ * memory — pulls `input`, `output` and `error` for every run in the window, which on a control
1181
+ * plane with real payloads is tens of megabytes fetched to produce a list of a hundred short
1182
+ * strings, every time a picker opens. These project the one column each question needs instead:
1183
+ * the tags column, or the run ids that then drive one grouped read of the side table.
1184
+ */
1185
+ async scannedValueFacets(axis, query, opts) {
1186
+ const em = this.fork();
1187
+ const scan = opts?.scan ?? RUN_VALUE_FACET_SCAN;
1188
+ const where = this.runWhere(query);
1189
+ const runMeta = em.getMetadata().get(WorkflowRunEntity);
1190
+ const idCol = runMeta.properties.id?.fieldNames?.[0] ?? "id";
1191
+ if (axis.field === "tag") {
1192
+ const tagsCol = this.tagsColumn(em);
1193
+ const rows = await this.runQueryBuilder(em, query, where).select([
1194
+ `r.${tagsCol}`
1195
+ ]).orderBy({
1196
+ createdAt: "desc"
1197
+ }).limit(scan).execute();
1198
+ const values = [];
1199
+ for (const row of rows) {
1200
+ const raw2 = row.tags ?? row[tagsCol];
1201
+ const tags = typeof raw2 === "string" ? JSON.parse(raw2) : raw2;
1202
+ if (!Array.isArray(tags)) continue;
1203
+ for (const tag of tags) values.push({
1204
+ value: String(tag),
1205
+ count: 1
1206
+ });
1207
+ }
1208
+ return mergeRunValueFacetRows(values, opts);
1209
+ }
1210
+ const idRows = await this.runQueryBuilder(em, query, where).select([
1211
+ `r.${idCol}`
1212
+ ]).orderBy({
1213
+ createdAt: "desc"
1214
+ }).limit(scan).execute();
1215
+ const runIds = idRows.map((row) => String(row.id ?? row[idCol]));
1216
+ if (runIds.length === 0) return [];
1217
+ const attributes = await em.find(RunAttributeEntity, axis.field === "attributeValue" ? {
1218
+ runId: {
1219
+ $in: runIds
1220
+ },
1221
+ key: axis.key
1222
+ } : {
1223
+ runId: {
1224
+ $in: runIds
1225
+ }
1226
+ });
1227
+ return mergeRunValueFacetRows(attributes.map((row) => ({
1228
+ value: axis.field === "attributeKey" ? row.key : row.strValue ?? (row.numValue == null ? null : String(row.numValue)),
1229
+ count: 1
1230
+ })), opts);
1231
+ }
1179
1232
  /** One attribute predicate as a raw EXISTS subquery on the side-table, correlated to the outer run
1180
1233
  * alias. `<>` (ne) also excludes runs where the attribute is absent (missing-key-never-matches):
1181
1234
  * EXISTS already requires a present row, so EXISTS(... <> ...) is exactly ne-with-present. Numeric