@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.cjs +58 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +59 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1197,11 +1197,7 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
|
|
|
1197
1197
|
* page of runs instead — see {@link RunValueFacetOptions.scan}. */
|
|
1198
1198
|
async runValueFacets(axis, query, opts) {
|
|
1199
1199
|
if (!(0, import_nestjs_durable_core.axisIsRunColumn)(axis)) {
|
|
1200
|
-
|
|
1201
|
-
...query,
|
|
1202
|
-
limit: opts?.scan ?? import_nestjs_durable_core.RUN_VALUE_FACET_SCAN
|
|
1203
|
-
});
|
|
1204
|
-
return (0, import_nestjs_durable_core.runValueFacetsFromRuns)(runs, axis, opts);
|
|
1200
|
+
return this.scannedValueFacets(axis, query, opts);
|
|
1205
1201
|
}
|
|
1206
1202
|
const em = this.fork();
|
|
1207
1203
|
const meta = em.getMetadata().get(WorkflowRunEntity);
|
|
@@ -1216,6 +1212,63 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
|
|
|
1216
1212
|
count: Number(row.count)
|
|
1217
1213
|
})), opts);
|
|
1218
1214
|
}
|
|
1215
|
+
/**
|
|
1216
|
+
* The axes whose values do not live in a column of the run row: `tag` (inside a JSON array) and the
|
|
1217
|
+
* two search-attribute axes (a side table). Both read the newest `scan` matching runs.
|
|
1218
|
+
*
|
|
1219
|
+
* Neither reads a run's PAYLOAD. The obvious implementation — page `listRuns` and count in
|
|
1220
|
+
* memory — pulls `input`, `output` and `error` for every run in the window, which on a control
|
|
1221
|
+
* plane with real payloads is tens of megabytes fetched to produce a list of a hundred short
|
|
1222
|
+
* strings, every time a picker opens. These project the one column each question needs instead:
|
|
1223
|
+
* the tags column, or the run ids that then drive one grouped read of the side table.
|
|
1224
|
+
*/
|
|
1225
|
+
async scannedValueFacets(axis, query, opts) {
|
|
1226
|
+
const em = this.fork();
|
|
1227
|
+
const scan = opts?.scan ?? import_nestjs_durable_core.RUN_VALUE_FACET_SCAN;
|
|
1228
|
+
const where = this.runWhere(query);
|
|
1229
|
+
const runMeta = em.getMetadata().get(WorkflowRunEntity);
|
|
1230
|
+
const idCol = runMeta.properties.id?.fieldNames?.[0] ?? "id";
|
|
1231
|
+
if (axis.field === "tag") {
|
|
1232
|
+
const tagsCol = this.tagsColumn(em);
|
|
1233
|
+
const rows = await this.runQueryBuilder(em, query, where).select([
|
|
1234
|
+
`r.${tagsCol}`
|
|
1235
|
+
]).orderBy({
|
|
1236
|
+
createdAt: "desc"
|
|
1237
|
+
}).limit(scan).execute();
|
|
1238
|
+
const values = [];
|
|
1239
|
+
for (const row of rows) {
|
|
1240
|
+
const raw2 = row.tags ?? row[tagsCol];
|
|
1241
|
+
const tags = typeof raw2 === "string" ? JSON.parse(raw2) : raw2;
|
|
1242
|
+
if (!Array.isArray(tags)) continue;
|
|
1243
|
+
for (const tag of tags) values.push({
|
|
1244
|
+
value: String(tag),
|
|
1245
|
+
count: 1
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
return (0, import_nestjs_durable_core.mergeRunValueFacetRows)(values, opts);
|
|
1249
|
+
}
|
|
1250
|
+
const idRows = await this.runQueryBuilder(em, query, where).select([
|
|
1251
|
+
`r.${idCol}`
|
|
1252
|
+
]).orderBy({
|
|
1253
|
+
createdAt: "desc"
|
|
1254
|
+
}).limit(scan).execute();
|
|
1255
|
+
const runIds = idRows.map((row) => String(row.id ?? row[idCol]));
|
|
1256
|
+
if (runIds.length === 0) return [];
|
|
1257
|
+
const attributes = await em.find(RunAttributeEntity, axis.field === "attributeValue" ? {
|
|
1258
|
+
runId: {
|
|
1259
|
+
$in: runIds
|
|
1260
|
+
},
|
|
1261
|
+
key: axis.key
|
|
1262
|
+
} : {
|
|
1263
|
+
runId: {
|
|
1264
|
+
$in: runIds
|
|
1265
|
+
}
|
|
1266
|
+
});
|
|
1267
|
+
return (0, import_nestjs_durable_core.mergeRunValueFacetRows)(attributes.map((row) => ({
|
|
1268
|
+
value: axis.field === "attributeKey" ? row.key : row.strValue ?? (row.numValue == null ? null : String(row.numValue)),
|
|
1269
|
+
count: 1
|
|
1270
|
+
})), opts);
|
|
1271
|
+
}
|
|
1219
1272
|
/** One attribute predicate as a raw EXISTS subquery on the side-table, correlated to the outer run
|
|
1220
1273
|
* alias. `<>` (ne) also excludes runs where the attribute is absent (missing-key-never-matches):
|
|
1221
1274
|
* EXISTS already requires a present row, so EXISTS(... <> ...) is exactly ne-with-present. Numeric
|