@okf/ootils 1.39.3 → 1.41.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/node.d.ts CHANGED
@@ -3,6 +3,7 @@ import * as mongoose from 'mongoose';
3
3
  import mongoose__default, { Document, Types, Schema } from 'mongoose';
4
4
  import * as bullmq from 'bullmq';
5
5
  import { Queue } from 'bullmq/dist/esm/classes/queue';
6
+ import { FlowProducer } from 'bullmq/dist/esm/classes/flow-producer';
6
7
  import { Worker } from 'bullmq/dist/esm/classes/worker';
7
8
 
8
9
  declare const deleteVal: (data: any, valuePath: string) => any;
@@ -292,9 +293,10 @@ declare const collectMarkIdsInOrder: (editorState: any) => string[];
292
293
  * }
293
294
  * ]
294
295
  */
295
- declare function getRollupPossibilities({ tagType, allTpls }: {
296
+ declare function getRollupPossibilities({ tagType, allTpls, includeSelfHead, }: {
296
297
  tagType: string;
297
298
  allTpls: any[];
299
+ includeSelfHead?: boolean;
298
300
  }): any[];
299
301
 
300
302
  declare namespace BASE_BULLMQ_CONFIG {
@@ -1248,6 +1250,27 @@ declare const processAuthorAndCommonFilters: (allTpls: any[], filterScopes: stri
1248
1250
 
1249
1251
  declare const _self_managed_getFixedAnnoTagBlock: (selectedTpls: any[], annotationTagsCount: any) => any[];
1250
1252
 
1253
+ /**
1254
+ * FOLLOWUP (consolidate the count->rollupPath rule into one source of truth):
1255
+ *
1256
+ * The rule "given annotationTagsCount, which self-managed anno rollupPaths exist"
1257
+ * (subThemes>0 -> ['tags','subThemes']; subThemes>0 && themes>0 -> ['tags','subThemes','themes'])
1258
+ * is currently duplicated in THREE places and will drift:
1259
+ * 1. here (_self_managed_getFixedAnnoRollupBlocks) -> filter blocks
1260
+ * 2. _self_managed_buildAnnoHierarchyConfig -> anno hierarchy filter UI
1261
+ * 3. okf-fe _extractAllAnnoBasedDimensionsAsOptions.js -> reports dimension dropdown
1262
+ *
1263
+ * (#3 was added to fix a crash: the reports widget previously discovered these rollups
1264
+ * from publishing-segment tpls via getRollupPossibilities, but self-managed taxonomy lives
1265
+ * on `collections`-segment tpls which isTplAnnotationEnabled excludes -> empty list ->
1266
+ * unguarded .find('subThemes') returned undefined -> crash. The FE now builds them from the
1267
+ * count, mirroring this function.)
1268
+ *
1269
+ * Extract a pure helper here in ootils:
1270
+ * export const getSelfManagedAnnoRollupPaths = (annotationTagsCount): string[][] => [...]
1271
+ * then have all three call sites consume it (each maps paths -> its own shape:
1272
+ * filter-blocks / hierarchy levels / dropdown options). One rule, three presentations.
1273
+ */
1251
1274
  declare const _self_managed_getFixedAnnoRollupBlocks: ({ selectedTpls, allTpls, annotationTagsCount }: {
1252
1275
  selectedTpls: any[];
1253
1276
  allTpls: any[];
@@ -1349,6 +1372,7 @@ declare const _self_managed_buildDocHierarchyConfig: ({ combinedDocumentBlocks,
1349
1372
  display: any;
1350
1373
  filters: any[];
1351
1374
  rollups: any[];
1375
+ rollupDisplayMap: Record<string, string>;
1352
1376
  }[];
1353
1377
  };
1354
1378
  target: {
@@ -1508,6 +1532,7 @@ declare const autoGenFilterConfigsFromTpl: ({ selectedTpls, allTpls, filterScope
1508
1532
  display: any;
1509
1533
  filters: any[];
1510
1534
  rollups: any[];
1535
+ rollupDisplayMap: Record<string, string>;
1511
1536
  }[];
1512
1537
  };
1513
1538
  target: {
@@ -2592,6 +2617,100 @@ declare class BaseProducer {
2592
2617
  stop(): Promise<void>;
2593
2618
  }
2594
2619
 
2620
+ /**
2621
+ * BaseFlowProducer — the flow-equivalent of BaseProducer.
2622
+ *
2623
+ * A BullMQ Flow adds its parent + children jobs straight into each queue's
2624
+ * Redis keys WITHOUT going through a Queue instance. That means flow nodes do
2625
+ * NOT inherit their queue's `defaultJobOptions` the way `BaseProducer` jobs do
2626
+ * (BaseProducer gets them for free via `new Queue(id, queueConfig)`). Left
2627
+ * unhandled, options like removeOnComplete/removeOnFail are never applied and
2628
+ * completed/failed jobs accumulate unbounded.
2629
+ *
2630
+ * This base centralises the one thing that must happen for every flow: each
2631
+ * node's `opts` is layered as `{ ...queueDefaultJobOptions, ...nodeOpts }`,
2632
+ * mirroring exactly how BullMQ layers defaultJobOptions under per-`add` opts
2633
+ * for normal queues. So subclasses declare ONLY structure + job-specific opts
2634
+ * (e.g. failParentOnFailure); retention and other defaults flow from the same
2635
+ * GLOBAL_BULLMQ_CONFIG that the queues/workers already read — single source of
2636
+ * truth, no per-call-site restatement.
2637
+ *
2638
+ * Construction takes the SAME config objects (entries of GET_GLOBAL_BULLMQ_CONFIG)
2639
+ * that BaseProducer/BaseWorker consume, so a flow is configured declaratively
2640
+ * alongside its queues.
2641
+ *
2642
+ * @param {Object} params
2643
+ * @param {Object} params.parentConfig
2644
+ * The GLOBAL_BULLMQ_CONFIG entry for the parent queue (has .id, .queueConfig).
2645
+ * @param {Object} params.childConfigs
2646
+ * Map keyed by an arbitrary childKey →
2647
+ * the GLOBAL_BULLMQ_CONFIG entry for that
2648
+ * child queue. Subclasses reference a child
2649
+ * node's queue by this key, never by id.
2650
+ */
2651
+ declare class BaseFlowProducer {
2652
+ constructor({ parentConfig, childConfigs }: {
2653
+ parentConfig: any;
2654
+ childConfigs?: {} | undefined;
2655
+ });
2656
+ parentConfig: any;
2657
+ childConfigs: {};
2658
+ flow: FlowProducer;
2659
+ /**
2660
+ * Build & enqueue a flow declaratively.
2661
+ *
2662
+ * @param {Object} params
2663
+ * @param {string} [params.name] Parent job name.
2664
+ * @param {Object} params.parentData Parent job data.
2665
+ * @param {Object} [params.parentOpts] Per-node opts for the parent, layered
2666
+ * over the parent queue's defaults.
2667
+ * @param {Array} params.children One entry per child node:
2668
+ * @param {string} children[].childKey Key into childConfigs (which queue).
2669
+ * @param {string} [children[].name] Child job name.
2670
+ * @param {Object} children[].data Child job data.
2671
+ * @param {Object} [children[].opts] Job-specific opts (e.g.
2672
+ * failParentOnFailure); layered over
2673
+ * that child queue's defaults.
2674
+ * @returns {Promise<{ parentJobId, childJobIds }>}
2675
+ */
2676
+ addFlow({ name, parentData, parentOpts, children }: {
2677
+ name?: string | undefined;
2678
+ parentData: Object;
2679
+ parentOpts?: Object | undefined;
2680
+ children: any[];
2681
+ }): Promise<{
2682
+ parentJobId: any;
2683
+ childJobIds: any;
2684
+ }>;
2685
+ /**
2686
+ * Find the FIRST parent job in the given states whose data matches the
2687
+ * predicate — e.g. an in-flight lock check ("is a run already pending for
2688
+ * this tenant?"). Opens a short-lived Queue on the parent queue and closes
2689
+ * it before returning, so callers don't have to reach into config internals
2690
+ * to construct one themselves.
2691
+ *
2692
+ * Returns the first match or null. BullMQ can't filter by job.data
2693
+ * server-side, so this still fetches the in-flight set and scans in JS; the
2694
+ * contract is intentionally first-match (not a list) because that's the only
2695
+ * thing the lock-check use case needs.
2696
+ *
2697
+ * @param {Object} params
2698
+ * @param {string[]} params.states
2699
+ * Job states to scan, e.g. ["waiting", "active", "delayed"].
2700
+ * @param {(data: any, job: any) => boolean} params.matchData
2701
+ * Required function; receives job.data (and the job). Without it there's
2702
+ * no meaningful "match", so this throws — returning an arbitrary in-flight
2703
+ * job would be a silent caller bug.
2704
+ * @returns {Promise<Object|null>} The first matching parent job, or null.
2705
+ */
2706
+ findParentJob({ states, matchData }: {
2707
+ states: string[];
2708
+ matchData: (data: any, job: any) => boolean;
2709
+ }): Promise<Object | null>;
2710
+ stop(): Promise<void>;
2711
+ #private;
2712
+ }
2713
+
2595
2714
  declare class BaseWorker {
2596
2715
  constructor(config: any);
2597
2716
  config: any;
@@ -2648,4 +2767,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
2648
2767
  };
2649
2768
  }): Object;
2650
2769
 
2651
- export { AIChatSchema, AnnosElasticSyncProducer, AnnotationSchema, BASE_BULLMQ_CONFIG, BaseProducer, BaseWorker, type BlockCapabilities, type BlockDef, BlockRegistry, CHUNKING_PRESETS, ChunksElasticSyncProducer, ELASTIC_MAPPING_PRESETS, ElasticSearchConnector, FILTER_IDS, GET_GLOBAL_BULLMQ_CONFIG, GeneratedEntitiesSchema, GeneratedTopicsSchema, MONGO_SCHEMA_PRESETS, MongoConnector, PlatformConfigsSchema, ProducerManager, RedisCacheConnector, SecretManagerConnector, TEMP_removeDuplicateFilters, TplSchema, UI_CONTENT, WorkerManager, _self_managed_buildAnnoHierarchyConfig, _self_managed_buildDocHierarchyConfig, _self_managed_getFixedAnnoRollupBlocks, _self_managed_getFixedAnnoTagBlock, autoGenFilterConfigsFromTpl, blockRegistry, buildFilterConfigurations, collectMarkIdsInOrder, compareAndGroupBlocks, deleteVal, extractAllBlocksFromTpl, extractAndOrganizeBlocks, genCleanCamelCaseId, genTagId, generateFilterKey, getAIChatModelByTenant, getAnnoFilterBucketKey, getAnnotationsModelByTenant, getDbByTenant, getFilterKeyForBlock, getGeneratedEntitiesModelByTenant, getGeneratedTopicsModelByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getPlatformContextContent, getRollupPossibilities, getRoutePathToContentTypeLanding, getRoutePathToEditContent, getRoutePathToModerateContent, getRoutePathToMyContent, getRoutePathToPublishedContent, getRoutePathToReviewDashboard, getRoutePathToTCI, getRoutePathToTagCategoryLanding, getTplModelByTenant, getVal, isTplAnnotationEnabled, mergeAnnoDataIntoAnnotationsTags, parseSpecialConfigSyntax, plainTextToLexical, processAuthorAndCommonFilters, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
2770
+ export { AIChatSchema, AnnosElasticSyncProducer, AnnotationSchema, BASE_BULLMQ_CONFIG, BaseFlowProducer, BaseProducer, BaseWorker, type BlockCapabilities, type BlockDef, BlockRegistry, CHUNKING_PRESETS, ChunksElasticSyncProducer, ELASTIC_MAPPING_PRESETS, ElasticSearchConnector, FILTER_IDS, GET_GLOBAL_BULLMQ_CONFIG, GeneratedEntitiesSchema, GeneratedTopicsSchema, MONGO_SCHEMA_PRESETS, MongoConnector, PlatformConfigsSchema, ProducerManager, RedisCacheConnector, SecretManagerConnector, TEMP_removeDuplicateFilters, TplSchema, UI_CONTENT, WorkerManager, _self_managed_buildAnnoHierarchyConfig, _self_managed_buildDocHierarchyConfig, _self_managed_getFixedAnnoRollupBlocks, _self_managed_getFixedAnnoTagBlock, autoGenFilterConfigsFromTpl, blockRegistry, buildFilterConfigurations, collectMarkIdsInOrder, compareAndGroupBlocks, deleteVal, extractAllBlocksFromTpl, extractAndOrganizeBlocks, genCleanCamelCaseId, genTagId, generateFilterKey, getAIChatModelByTenant, getAnnoFilterBucketKey, getAnnotationsModelByTenant, getDbByTenant, getFilterKeyForBlock, getGeneratedEntitiesModelByTenant, getGeneratedTopicsModelByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getPlatformContextContent, getRollupPossibilities, getRoutePathToContentTypeLanding, getRoutePathToEditContent, getRoutePathToModerateContent, getRoutePathToMyContent, getRoutePathToPublishedContent, getRoutePathToReviewDashboard, getRoutePathToTCI, getRoutePathToTagCategoryLanding, getTplModelByTenant, getVal, isTplAnnotationEnabled, mergeAnnoDataIntoAnnotationsTags, parseSpecialConfigSyntax, plainTextToLexical, processAuthorAndCommonFilters, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
package/dist/node.js CHANGED
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __typeError = (msg) => {
9
+ throw TypeError(msg);
10
+ };
8
11
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
12
  var __esm = (fn, res) => function __init() {
10
13
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
@@ -34,6 +37,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
34
37
  ));
35
38
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
39
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
40
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
41
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
42
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
37
43
 
38
44
  // src/bullmq/GLOBAL_BULLMQ_CONFIG.js
39
45
  var GLOBAL_BULLMQ_CONFIG_exports = {};
@@ -1912,6 +1918,133 @@ var require_BaseProducer = __commonJS({
1912
1918
  }
1913
1919
  });
1914
1920
 
1921
+ // src/bullmq/BaseFlowProducer.js
1922
+ var require_BaseFlowProducer = __commonJS({
1923
+ "src/bullmq/BaseFlowProducer.js"(exports2, module2) {
1924
+ "use strict";
1925
+ var { FlowProducer, Queue } = require("bullmq");
1926
+ var _BaseFlowProducer_instances, mergeOpts_fn, childConfig_fn;
1927
+ var BaseFlowProducer2 = class {
1928
+ constructor({ parentConfig, childConfigs = {} }) {
1929
+ __privateAdd(this, _BaseFlowProducer_instances);
1930
+ if (!parentConfig) {
1931
+ throw new Error("BaseFlowProducer requires a parentConfig");
1932
+ }
1933
+ this.parentConfig = parentConfig;
1934
+ this.childConfigs = childConfigs;
1935
+ this.flow = new FlowProducer({
1936
+ connection: parentConfig.queueConfig.connection
1937
+ });
1938
+ }
1939
+ /**
1940
+ * Build & enqueue a flow declaratively.
1941
+ *
1942
+ * @param {Object} params
1943
+ * @param {string} [params.name] Parent job name.
1944
+ * @param {Object} params.parentData Parent job data.
1945
+ * @param {Object} [params.parentOpts] Per-node opts for the parent, layered
1946
+ * over the parent queue's defaults.
1947
+ * @param {Array} params.children One entry per child node:
1948
+ * @param {string} children[].childKey Key into childConfigs (which queue).
1949
+ * @param {string} [children[].name] Child job name.
1950
+ * @param {Object} children[].data Child job data.
1951
+ * @param {Object} [children[].opts] Job-specific opts (e.g.
1952
+ * failParentOnFailure); layered over
1953
+ * that child queue's defaults.
1954
+ * @returns {Promise<{ parentJobId, childJobIds }>}
1955
+ */
1956
+ async addFlow({ name, parentData, parentOpts = {}, children = [] }) {
1957
+ const flowJob = await this.flow.add({
1958
+ name,
1959
+ queueName: this.parentConfig.id,
1960
+ data: parentData,
1961
+ opts: __privateMethod(this, _BaseFlowProducer_instances, mergeOpts_fn).call(this, this.parentConfig, parentOpts),
1962
+ children: children.map((child) => {
1963
+ const childCfg = __privateMethod(this, _BaseFlowProducer_instances, childConfig_fn).call(this, child.childKey);
1964
+ return {
1965
+ name: child.name,
1966
+ queueName: childCfg.id,
1967
+ data: child.data,
1968
+ opts: __privateMethod(this, _BaseFlowProducer_instances, mergeOpts_fn).call(this, childCfg, child.opts)
1969
+ };
1970
+ })
1971
+ });
1972
+ const parentJobId = flowJob?.job?.id;
1973
+ const childJobIds = (flowJob?.children || []).map((c) => c?.job?.id).filter(Boolean);
1974
+ return { parentJobId, childJobIds };
1975
+ }
1976
+ /**
1977
+ * Find the FIRST parent job in the given states whose data matches the
1978
+ * predicate — e.g. an in-flight lock check ("is a run already pending for
1979
+ * this tenant?"). Opens a short-lived Queue on the parent queue and closes
1980
+ * it before returning, so callers don't have to reach into config internals
1981
+ * to construct one themselves.
1982
+ *
1983
+ * Returns the first match or null. BullMQ can't filter by job.data
1984
+ * server-side, so this still fetches the in-flight set and scans in JS; the
1985
+ * contract is intentionally first-match (not a list) because that's the only
1986
+ * thing the lock-check use case needs.
1987
+ *
1988
+ * @param {Object} params
1989
+ * @param {string[]} params.states
1990
+ * Job states to scan, e.g. ["waiting", "active", "delayed"].
1991
+ * @param {(data: any, job: any) => boolean} params.matchData
1992
+ * Required function; receives job.data (and the job). Without it there's
1993
+ * no meaningful "match", so this throws — returning an arbitrary in-flight
1994
+ * job would be a silent caller bug.
1995
+ * @returns {Promise<Object|null>} The first matching parent job, or null.
1996
+ */
1997
+ async findParentJob({ states, matchData }) {
1998
+ if (typeof matchData !== "function") {
1999
+ throw new Error("BaseFlowProducer.findParentJob requires a matchData function");
2000
+ }
2001
+ const parentQueue = new Queue(
2002
+ this.parentConfig.id,
2003
+ this.parentConfig.queueConfig
2004
+ );
2005
+ try {
2006
+ const jobs = await parentQueue.getJobs(states, 0, -1);
2007
+ return jobs.find((job) => matchData(job?.data, job)) || null;
2008
+ } finally {
2009
+ await parentQueue.close();
2010
+ }
2011
+ }
2012
+ async stop() {
2013
+ if (this.flow) {
2014
+ try {
2015
+ await this.flow.close();
2016
+ } catch (err) {
2017
+ console.warn(`[${this.constructor.name}] flow close failed: ${err.message}`);
2018
+ }
2019
+ }
2020
+ }
2021
+ };
2022
+ _BaseFlowProducer_instances = new WeakSet();
2023
+ /**
2024
+ * Layer a queue config's defaultJobOptions under per-node opts — identical
2025
+ * to how BullMQ merges defaultJobOptions under per-`add` opts for a Queue.
2026
+ * Config is the base; anything the node explicitly sets wins.
2027
+ */
2028
+ mergeOpts_fn = function(queueConfig, nodeOpts = {}) {
2029
+ const defaults = queueConfig?.queueConfig?.defaultJobOptions || {};
2030
+ return { ...defaults, ...nodeOpts };
2031
+ };
2032
+ /**
2033
+ * Resolve the GLOBAL_BULLMQ_CONFIG entry for a declared child key.
2034
+ */
2035
+ childConfig_fn = function(childKey) {
2036
+ const cfg = this.childConfigs[childKey];
2037
+ if (!cfg) {
2038
+ throw new Error(
2039
+ `BaseFlowProducer: no child queue declared under key "${childKey}". Declared keys: [${Object.keys(this.childConfigs).join(", ")}]`
2040
+ );
2041
+ }
2042
+ return cfg;
2043
+ };
2044
+ module2.exports = { BaseFlowProducer: BaseFlowProducer2 };
2045
+ }
2046
+ });
2047
+
1915
2048
  // src/bullmq/BaseWorker.js
1916
2049
  var require_BaseWorker = __commonJS({
1917
2050
  "src/bullmq/BaseWorker.js"(exports2, module2) {
@@ -2102,6 +2235,7 @@ __export(node_exports, {
2102
2235
  AnnosElasticSyncProducer: () => import_AnnosElasticSyncProducer.AnnosElasticSyncProducer,
2103
2236
  AnnotationSchema: () => Annotations_default,
2104
2237
  BASE_BULLMQ_CONFIG: () => BASE_BULLMQ_CONFIG,
2238
+ BaseFlowProducer: () => import_BaseFlowProducer.BaseFlowProducer,
2105
2239
  BaseProducer: () => import_BaseProducer.BaseProducer,
2106
2240
  BaseWorker: () => import_BaseWorker.BaseWorker,
2107
2241
  BlockRegistry: () => BlockRegistry,
@@ -2825,7 +2959,8 @@ var collectMarkIdsInOrder = (editorState) => {
2825
2959
  var MAX_DEPTH_ROLLUP_POSSIBILITIES = 10;
2826
2960
  function getRollupPossibilities({
2827
2961
  tagType,
2828
- allTpls
2962
+ allTpls,
2963
+ includeSelfHead = false
2829
2964
  }) {
2830
2965
  const thisTagTpl = allTpls.find((d) => d.kp_content_type === tagType);
2831
2966
  if (!thisTagTpl) return [];
@@ -2857,7 +2992,8 @@ function getRollupPossibilities({
2857
2992
  chains.push({
2858
2993
  rollupType: "tagType",
2859
2994
  tagTypeCollectionToRollup: tagType,
2860
- rollupPath: [...visited, startTagType, nextTagType]
2995
+ rollupPath: [...visited, startTagType, nextTagType],
2996
+ filterDisplay: block.props?.shortLabel || block.props?.label
2861
2997
  });
2862
2998
  if (visited.length < maxDepth - 1) {
2863
2999
  const nextChains = findTagChains(
@@ -2903,7 +3039,8 @@ function getRollupPossibilities({
2903
3039
  const directChain = {
2904
3040
  rollupType: "tagType",
2905
3041
  tagTypeCollectionToRollup: tagType,
2906
- rollupPath: [tagType, block.props.tagType]
3042
+ rollupPath: [tagType, block.props.tagType],
3043
+ filterDisplay: block.props?.shortLabel || block.props?.label
2907
3044
  };
2908
3045
  const deeperChains = findTagChains(
2909
3046
  block.props?.tagType,
@@ -2912,7 +3049,14 @@ function getRollupPossibilities({
2912
3049
  );
2913
3050
  return [directChain, ...deeperChains];
2914
3051
  });
2915
- return [...singleLevelValuePathRollups, ...nestedTagRollups];
3052
+ const selfHeadRollup = includeSelfHead && nestedTagRollups.length > 0 && singleLevelValuePathRollups.length === 0 ? [
3053
+ {
3054
+ rollupType: "tagType",
3055
+ tagTypeCollectionToRollup: tagType,
3056
+ rollupPath: [tagType]
3057
+ }
3058
+ ] : [];
3059
+ return [...singleLevelValuePathRollups, ...selfHeadRollup, ...nestedTagRollups];
2916
3060
  }
2917
3061
 
2918
3062
  // src/universal.ts
@@ -3320,6 +3464,7 @@ var buildFilterConfigurations = ({ groups, type, selectedTpls, allTpls, isRollup
3320
3464
  if (isTerminalValuePath) {
3321
3465
  return element.filterDisplay || lastItemInPath;
3322
3466
  }
3467
+ if (element.filterDisplay) return element.filterDisplay;
3323
3468
  const lastTag = rollupPath[rollupPath.length - 1];
3324
3469
  const lastTagTpl = allTpls.find(
3325
3470
  (tpl) => tpl.kp_content_type === lastTag
@@ -3586,7 +3731,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls, { smTagTypesConfig } = {}
3586
3731
  return {
3587
3732
  contentType: tpl.kp_content_type,
3588
3733
  blocks: allBlocks.filter((block) => block.valuePath.startsWith("tags.") && ["TagsInputSingle", "TagsInputMulti"].includes(block.comp)).flatMap((block) => {
3589
- const possibilities = getRollupPossibilities({ tagType: block.props.tagType, allTpls });
3734
+ const possibilities = getRollupPossibilities({ tagType: block.props.tagType, allTpls, includeSelfHead: true });
3590
3735
  return possibilities.map((p) => ({
3591
3736
  ...p,
3592
3737
  filterType: p.rollupPath ? "nestedRollupTagType" : "rollupValuePathType"
@@ -3919,13 +4064,16 @@ var buildTagTypeParentMap = (tagTypesInGroup, allTpls) => {
3919
4064
  const tagBlocks = blocks.filter(
3920
4065
  (block) => block.valuePath?.startsWith("tags.") && block.props?.tagType
3921
4066
  );
4067
+ const referencedTagTypes = /* @__PURE__ */ new Set();
3922
4068
  for (const block of tagBlocks) {
3923
4069
  const referencedTagType = block.props.tagType;
3924
4070
  if (tagTypeSet.has(referencedTagType) && referencedTagType !== tagType) {
3925
- parentMap.set(tagType, referencedTagType);
3926
- break;
4071
+ referencedTagTypes.add(referencedTagType);
3927
4072
  }
3928
4073
  }
4074
+ if (referencedTagTypes.size === 1) {
4075
+ parentMap.set(tagType, [...referencedTagTypes][0]);
4076
+ }
3929
4077
  }
3930
4078
  for (const child of parentMap.keys()) {
3931
4079
  const visited = /* @__PURE__ */ new Set();
@@ -3999,6 +4147,34 @@ var sortFiltersHierarchically = (filters) => {
3999
4147
  return sorted;
4000
4148
  };
4001
4149
 
4150
+ // src/utils/autoGenFilterConfigsFromTpl/utils/deduplicateRollupTagFilters.ts
4151
+ var deduplicateRollupTagFilters = (rollups) => {
4152
+ const tagTerminals = [];
4153
+ const nonTag = [];
4154
+ for (const r of rollups) {
4155
+ const rp = r.target?.rollupPath;
4156
+ if (rp?.length && !rp[rp.length - 1].startsWith("main.")) {
4157
+ tagTerminals.push(r);
4158
+ } else {
4159
+ nonTag.push({ ...r, isTagRollup: false });
4160
+ }
4161
+ }
4162
+ if (tagTerminals.length === 0) return nonTag;
4163
+ const byTerminal = /* @__PURE__ */ new Map();
4164
+ for (const r of tagTerminals) {
4165
+ const terminal = r.target.rollupPath[r.target.rollupPath.length - 1];
4166
+ const existing = byTerminal.get(terminal);
4167
+ if (!existing || r.target.rollupPath.length < existing.target.rollupPath.length) {
4168
+ byTerminal.set(terminal, r);
4169
+ }
4170
+ }
4171
+ const dedupedTags = [...byTerminal.values()].map((r) => ({
4172
+ ...r,
4173
+ isTagRollup: true
4174
+ }));
4175
+ return [...nonTag, ...dedupedTags];
4176
+ };
4177
+
4002
4178
  // src/utils/autoGenFilterConfigsFromTpl/utils/_self_managed_buildDocHierarchyConfig.ts
4003
4179
  var injectFilterOptionsBy = (filters) => filters.map(
4004
4180
  (f) => f.parentFilterId ? { ...f, source: { ...f.source, filterOptionsBy: { filterId: f.parentFilterId } } } : f
@@ -4105,24 +4281,34 @@ var _self_managed_buildDocHierarchyConfig = ({
4105
4281
  const dedupedFilters = filtersWithCommonFlag.filter(
4106
4282
  (f) => !rollupSourceKeys.has(JSON.stringify(f.source))
4107
4283
  );
4108
- const combined = [...dedupedFilters, ...rollupConfigs];
4284
+ const dedupedRollupConfigs = deduplicateRollupTagFilters(rollupConfigs);
4285
+ const combined = [...dedupedFilters, ...dedupedRollupConfigs];
4109
4286
  const combinedWithParents = injectFilterOptionsBy(
4110
4287
  sortFiltersHierarchically(
4111
4288
  attachParentFields(combined, allTpls)
4112
4289
  )
4113
4290
  );
4114
- const rollupFilterIds = new Set(rollupConfigs.map((r) => r.filterId));
4291
+ const rollupFilterIds = new Set(dedupedRollupConfigs.map((r) => r.filterId));
4115
4292
  const filtersWithParents = combinedWithParents.filter(
4116
4293
  (f) => !rollupFilterIds.has(f.filterId)
4117
4294
  );
4118
4295
  const rollupsWithParents = combinedWithParents.filter(
4119
4296
  (f) => rollupFilterIds.has(f.filterId)
4120
4297
  );
4298
+ const rollupContentTypes = new Set(
4299
+ rollupsWithParents.filter((r) => r.target?.rollupPath).flatMap((r) => r.target.rollupPath)
4300
+ );
4301
+ const rollupDisplayMap = {};
4302
+ for (const ct of rollupContentTypes) {
4303
+ const t = allTpls.find((tp) => tp.kp_content_type === ct);
4304
+ if (t?.general?.content?.title) rollupDisplayMap[ct] = t.general.content.title;
4305
+ }
4121
4306
  return {
4122
4307
  contentType: tpl.kp_content_type,
4123
4308
  display: tplData?.general?.content?.title || tpl.kp_content_type,
4124
4309
  filters: filtersWithParents,
4125
- rollups: rollupsWithParents
4310
+ rollups: rollupsWithParents,
4311
+ rollupDisplayMap
4126
4312
  };
4127
4313
  });
4128
4314
  const filteredPerDataset = perDataset.filter(
@@ -4767,6 +4953,7 @@ init_models();
4767
4953
  var import_WorkerManager = __toESM(require_WorkerManager());
4768
4954
  var import_ProducerManager = __toESM(require_ProducerManager());
4769
4955
  var import_BaseProducer = __toESM(require_BaseProducer());
4956
+ var import_BaseFlowProducer = __toESM(require_BaseFlowProducer());
4770
4957
  var import_BaseWorker = __toESM(require_BaseWorker());
4771
4958
  var import_ChunksElasticSyncProducer = __toESM(require_ChunksElasticSyncProducer());
4772
4959
  var import_AnnosElasticSyncProducer = __toESM(require_AnnosElasticSyncProducer());
@@ -4777,6 +4964,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
4777
4964
  AnnosElasticSyncProducer,
4778
4965
  AnnotationSchema,
4779
4966
  BASE_BULLMQ_CONFIG,
4967
+ BaseFlowProducer,
4780
4968
  BaseProducer,
4781
4969
  BaseWorker,
4782
4970
  BlockRegistry,