@okf/ootils 1.26.4 → 1.28.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.js CHANGED
@@ -1939,6 +1939,7 @@ __export(node_exports, {
1939
1939
  UI_CONTENT: () => UI_CONTENT,
1940
1940
  WorkerManager: () => import_WorkerManager.WorkerManager,
1941
1941
  _self_managed_buildAnnoHierarchyConfig: () => _self_managed_buildAnnoHierarchyConfig,
1942
+ _self_managed_buildDocHierarchyConfig: () => _self_managed_buildDocHierarchyConfig,
1942
1943
  _self_managed_getFixedAnnoRollupBlocks: () => _self_managed_getFixedAnnoRollupBlocks,
1943
1944
  _self_managed_getFixedAnnoTagBlock: () => _self_managed_getFixedAnnoTagBlock,
1944
1945
  autoGenFilterConfigsFromTpl: () => autoGenFilterConfigsFromTpl,
@@ -1947,6 +1948,8 @@ __export(node_exports, {
1947
1948
  deleteVal: () => deleteVal,
1948
1949
  extractAllBlocksFromTpl: () => extractAllBlocksFromTpl,
1949
1950
  extractAndOrganizeBlocks: () => extractAndOrganizeBlocks,
1951
+ genCleanCamelCaseId: () => genCleanCamelCaseId,
1952
+ genCleanIdForContentTypeAndValuePaths: () => genCleanIdForContentTypeAndValuePaths,
1950
1953
  genTagId: () => genTagId,
1951
1954
  generateFilterKey: () => generateFilterKey,
1952
1955
  getAIChatModelByTenant: () => import_getModelByTenant2.getAIChatModelByTenant,
@@ -2662,6 +2665,7 @@ var buildFilterConfigurations = ({ groups, type, selectedTpls, allTpls, isRollup
2662
2665
  filterKey,
2663
2666
  contentType: element.contentType,
2664
2667
  path: element.valuePath,
2668
+ ...element.comp && { comp: element.comp },
2665
2669
  source: {
2666
2670
  filterType: "tplType",
2667
2671
  contentType: element.contentType,
@@ -2687,6 +2691,7 @@ var buildFilterConfigurations = ({ groups, type, selectedTpls, allTpls, isRollup
2687
2691
  filterKey: valuePathFilterKey,
2688
2692
  contentType: element.contentType,
2689
2693
  path: element.valuePath,
2694
+ ...element.comp && { comp: element.comp },
2690
2695
  source: {
2691
2696
  filterType: "tplType",
2692
2697
  contentType: element.contentType,
@@ -2712,6 +2717,7 @@ var buildFilterConfigurations = ({ groups, type, selectedTpls, allTpls, isRollup
2712
2717
  filterKey: dateFilterKey,
2713
2718
  contentType: element.contentType,
2714
2719
  path: element.valuePath,
2720
+ ...element.comp && { comp: element.comp },
2715
2721
  source: { filterType: "dateRangeType" },
2716
2722
  target: { filterType: "dateRangeType", valuePath: element.valuePath }
2717
2723
  };
@@ -2729,6 +2735,7 @@ var buildFilterConfigurations = ({ groups, type, selectedTpls, allTpls, isRollup
2729
2735
  filterKey: numberFilterKey,
2730
2736
  contentType: element.contentType,
2731
2737
  path: element.valuePath,
2738
+ ...element.comp && { comp: element.comp },
2732
2739
  source: { filterType: "numberRangeType", valuePath: element.valuePath },
2733
2740
  target: { filterType: "numberRangeType", valuePath: element.valuePath }
2734
2741
  };
@@ -2849,6 +2856,7 @@ var buildFilterConfigurations = ({ groups, type, selectedTpls, allTpls, isRollup
2849
2856
  filterKey: tagFilterKey,
2850
2857
  contentType: element.tagType,
2851
2858
  path: `tags.${element.tagType}`,
2859
+ ...element.comp && { comp: element.comp },
2852
2860
  source: allProfileTpls.some(
2853
2861
  (tpl) => tpl.kp_content_type === element.tagType
2854
2862
  ) ? {
@@ -2990,6 +2998,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
2990
2998
  contentType: tpl.kp_content_type,
2991
2999
  blocks: allBlocks.filter((block) => block.valuePath.startsWith("tags.")).map((block) => ({
2992
3000
  tagType: block.props.tagType,
3001
+ comp: block.comp,
2993
3002
  filterType: "tagType"
2994
3003
  }))
2995
3004
  };
@@ -3017,6 +3026,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
3017
3026
  value: block.valuePath,
3018
3027
  saveValueAsString: block.props?.saveValueAsString,
3019
3028
  contentType: tpl.kp_content_type,
3029
+ comp: block.comp,
3020
3030
  filterType: "valuePathType"
3021
3031
  }))
3022
3032
  };
@@ -3031,6 +3041,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
3031
3041
  value: block.valuePath,
3032
3042
  saveValueAsString: block.props?.saveValueAsString,
3033
3043
  contentType: tpl.kp_content_type,
3044
+ comp: block.comp,
3034
3045
  block,
3035
3046
  filterType: "split_valuePathType"
3036
3047
  }))
@@ -3045,6 +3056,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
3045
3056
  display: block.props?.shortLabel || block.props?.label || block.valuePath,
3046
3057
  value: block.valuePath,
3047
3058
  contentType: tpl.kp_content_type,
3059
+ comp: block.comp,
3048
3060
  filterType: "dateRangeType"
3049
3061
  }))
3050
3062
  };
@@ -3058,6 +3070,7 @@ var extractAndOrganizeBlocks = (selectedTpls, allTpls) => {
3058
3070
  display: block.props?.shortLabel || block.props?.label || block.valuePath,
3059
3071
  value: block.valuePath,
3060
3072
  contentType: tpl.kp_content_type,
3073
+ comp: block.comp,
3061
3074
  filterType: "numberRangeType"
3062
3075
  }))
3063
3076
  };
@@ -3304,6 +3317,240 @@ var _self_managed_buildAnnoHierarchyConfig = ({
3304
3317
  };
3305
3318
  };
3306
3319
 
3320
+ // src/utils/autoGenFilterConfigsFromTpl/utils/buildTagTypeParentMap.ts
3321
+ var buildTagTypeParentMap = (tagTypesInGroup, allTpls) => {
3322
+ const tagTypeSet = new Set(tagTypesInGroup);
3323
+ const parentMap = /* @__PURE__ */ new Map();
3324
+ for (const tagType of tagTypesInGroup) {
3325
+ const tpl = allTpls.find((t) => t.kp_content_type === tagType);
3326
+ if (!tpl) continue;
3327
+ const blocks = extractAllBlocksFromTpl({ tpl });
3328
+ const tagBlocks = blocks.filter(
3329
+ (block) => block.valuePath?.startsWith("tags.") && block.props?.tagType
3330
+ );
3331
+ for (const block of tagBlocks) {
3332
+ const referencedTagType = block.props.tagType;
3333
+ if (tagTypeSet.has(referencedTagType) && referencedTagType !== tagType) {
3334
+ parentMap.set(tagType, referencedTagType);
3335
+ break;
3336
+ }
3337
+ }
3338
+ }
3339
+ for (const child of parentMap.keys()) {
3340
+ const visited = /* @__PURE__ */ new Set();
3341
+ let current = child;
3342
+ while (current && parentMap.has(current)) {
3343
+ if (visited.has(current)) {
3344
+ parentMap.delete(current);
3345
+ break;
3346
+ }
3347
+ visited.add(current);
3348
+ current = parentMap.get(current);
3349
+ }
3350
+ }
3351
+ return parentMap;
3352
+ };
3353
+ var attachParentFields = (filters, allTpls) => {
3354
+ const tagTypeFilters = filters.filter(
3355
+ (f) => f.source?.filterType === "tagType" && f.source?.tagType
3356
+ );
3357
+ if (tagTypeFilters.length === 0) return filters;
3358
+ const tagTypesInGroup = tagTypeFilters.map((f) => f.source.tagType);
3359
+ const parentMap = buildTagTypeParentMap(tagTypesInGroup, allTpls);
3360
+ if (parentMap.size === 0) return filters;
3361
+ const tagTypeToFilterId = /* @__PURE__ */ new Map();
3362
+ for (const f of tagTypeFilters) {
3363
+ tagTypeToFilterId.set(f.source.tagType, f.filterId);
3364
+ }
3365
+ return filters.map((f) => {
3366
+ if (f.source?.filterType !== "tagType" || !f.source?.tagType) return f;
3367
+ const parentTagType = parentMap.get(f.source.tagType);
3368
+ if (!parentTagType) return f;
3369
+ const parentFilterId = tagTypeToFilterId.get(parentTagType);
3370
+ if (!parentFilterId) return f;
3371
+ return { ...f, parentFilterId };
3372
+ });
3373
+ };
3374
+ var sortFiltersHierarchically = (filters) => {
3375
+ if (filters.length <= 1) return filters;
3376
+ const hasHierarchy = filters.some((f) => f.parentFilterId);
3377
+ if (!hasHierarchy) return filters;
3378
+ const childrenOf = /* @__PURE__ */ new Map();
3379
+ const roots = [];
3380
+ for (const f of filters) {
3381
+ if (!f.parentFilterId) {
3382
+ roots.push(f);
3383
+ } else {
3384
+ const siblings = childrenOf.get(f.parentFilterId) || [];
3385
+ siblings.push(f);
3386
+ childrenOf.set(f.parentFilterId, siblings);
3387
+ }
3388
+ }
3389
+ const sorted = [];
3390
+ const visited = /* @__PURE__ */ new Set();
3391
+ const visit = (filter) => {
3392
+ if (visited.has(filter.filterId)) return;
3393
+ visited.add(filter.filterId);
3394
+ sorted.push(filter);
3395
+ const children = childrenOf.get(filter.filterId) || [];
3396
+ for (const child of children) {
3397
+ visit(child);
3398
+ }
3399
+ };
3400
+ for (const root of roots) {
3401
+ visit(root);
3402
+ }
3403
+ for (const f of filters) {
3404
+ if (!visited.has(f.filterId)) {
3405
+ sorted.push(f);
3406
+ }
3407
+ }
3408
+ return sorted;
3409
+ };
3410
+
3411
+ // src/utils/autoGenFilterConfigsFromTpl/utils/_self_managed_buildDocHierarchyConfig.ts
3412
+ var _self_managed_buildDocHierarchyConfig = ({
3413
+ combinedDocumentBlocks,
3414
+ docRollupBlocks,
3415
+ selectedTpls,
3416
+ allTpls,
3417
+ commonDocumentFilters,
3418
+ flatDocFilters = false
3419
+ }) => {
3420
+ const allGroups = compareAndGroupBlocks(combinedDocumentBlocks);
3421
+ const commonGroup = allGroups.find(
3422
+ (g) => g.contentTypes.length === selectedTpls.length
3423
+ );
3424
+ const commonFilterConfigs = commonGroup ? sortFiltersHierarchically(
3425
+ attachParentFields(
3426
+ buildFilterConfigurations({
3427
+ groups: [commonGroup],
3428
+ type: "tags",
3429
+ selectedTpls,
3430
+ allTpls,
3431
+ isRollup: false,
3432
+ isAnno: false
3433
+ }).flatMap((s) => s.configs),
3434
+ allTpls
3435
+ )
3436
+ ) : [];
3437
+ const multiDatasetGroups = selectedTpls.length >= 2 ? allGroups.filter(
3438
+ (g) => g.contentTypes.length > 1 && g.contentTypes.length < selectedTpls.length
3439
+ ) : [];
3440
+ const sharedAcrossMultiple = multiDatasetGroups.map((group) => {
3441
+ const groupFilterConfigs = sortFiltersHierarchically(
3442
+ attachParentFields(
3443
+ buildFilterConfigurations({
3444
+ groups: [group],
3445
+ type: "tags",
3446
+ selectedTpls,
3447
+ allTpls,
3448
+ isRollup: false,
3449
+ isAnno: false
3450
+ }).flatMap((s) => s.configs),
3451
+ allTpls
3452
+ )
3453
+ );
3454
+ const display = group.contentTypes.map((ct) => {
3455
+ const tplData = allTpls.find(
3456
+ (t) => t.kp_content_type === ct
3457
+ );
3458
+ return tplData?.general?.content?.title || ct;
3459
+ }).join(" + ");
3460
+ return {
3461
+ contentTypes: group.contentTypes,
3462
+ display,
3463
+ filters: groupFilterConfigs
3464
+ };
3465
+ }).filter((g) => g.filters.length > 0);
3466
+ const commonFilterIds = new Set(commonFilterConfigs.map((f) => f.filterId));
3467
+ const perDataset = selectedTpls.map((tpl) => {
3468
+ const tplBlocks = combinedDocumentBlocks.find(
3469
+ (b) => b.contentType === tpl.kp_content_type
3470
+ );
3471
+ const singleTplGroup = [
3472
+ {
3473
+ contentTypes: [tpl.kp_content_type],
3474
+ elements: tplBlocks?.blocks || []
3475
+ }
3476
+ ];
3477
+ const filters = buildFilterConfigurations({
3478
+ groups: singleTplGroup,
3479
+ type: "tags",
3480
+ selectedTpls: [tpl],
3481
+ allTpls,
3482
+ isRollup: false,
3483
+ isAnno: false
3484
+ }).flatMap((s) => s.configs);
3485
+ const filtersWithCommonFlag = filters.map((f) => ({
3486
+ ...f,
3487
+ isSharedFilter: commonFilterIds.has(f.filterId)
3488
+ }));
3489
+ const rollupData = docRollupBlocks?.find(
3490
+ (b) => b.contentType === tpl.kp_content_type
3491
+ );
3492
+ const rollupGroups = rollupData?.blocks?.length ? compareAndGroupBlocks([rollupData]) : [];
3493
+ const rollupConfigs = rollupGroups.length ? buildFilterConfigurations({
3494
+ groups: rollupGroups,
3495
+ type: "tags",
3496
+ selectedTpls: [tpl],
3497
+ allTpls,
3498
+ isRollup: true,
3499
+ isAnno: false
3500
+ }).flatMap((s) => s.configs) : [];
3501
+ const tplData = allTpls.find(
3502
+ (t) => t.kp_content_type === tpl.kp_content_type
3503
+ );
3504
+ const rollupSourceKeys = new Set(
3505
+ rollupConfigs.map((r) => JSON.stringify(r.source))
3506
+ );
3507
+ const dedupedFilters = filtersWithCommonFlag.filter(
3508
+ (f) => !rollupSourceKeys.has(JSON.stringify(f.source))
3509
+ );
3510
+ const combined = [...dedupedFilters, ...rollupConfigs];
3511
+ const combinedWithParents = sortFiltersHierarchically(
3512
+ attachParentFields(combined, allTpls)
3513
+ );
3514
+ const rollupFilterIds = new Set(rollupConfigs.map((r) => r.filterId));
3515
+ const filtersWithParents = combinedWithParents.filter(
3516
+ (f) => !rollupFilterIds.has(f.filterId)
3517
+ );
3518
+ const rollupsWithParents = combinedWithParents.filter(
3519
+ (f) => rollupFilterIds.has(f.filterId)
3520
+ );
3521
+ return {
3522
+ contentType: tpl.kp_content_type,
3523
+ display: tplData?.general?.content?.title || tpl.kp_content_type,
3524
+ filters: filtersWithParents,
3525
+ rollups: rollupsWithParents
3526
+ };
3527
+ });
3528
+ const filteredPerDataset = perDataset.filter(
3529
+ (d) => d.filters.length > 0 || d.rollups.length > 0
3530
+ );
3531
+ if (commonFilterConfigs.length === 0 && sharedAcrossMultiple.length === 0 && filteredPerDataset.every((d) => d.filters.length === 0)) {
3532
+ return null;
3533
+ }
3534
+ const flatCommonDocFilters = commonDocumentFilters.flatMap(
3535
+ (s) => s.configs || [s]
3536
+ );
3537
+ const shouldFlatten = flatDocFilters && selectedTpls.length === 1;
3538
+ return {
3539
+ filterId: "docHierarchy_document_filters",
3540
+ display: "Combined Content Filters",
3541
+ filterKey: "docHierarchyType::doc",
3542
+ source: {
3543
+ filterType: "docHierarchyType",
3544
+ flatDocFilters: shouldFlatten,
3545
+ commonFilters: commonFilterConfigs,
3546
+ sharedAcrossMultiple,
3547
+ commonDocumentFilters: flatCommonDocFilters,
3548
+ perDataset: filteredPerDataset
3549
+ },
3550
+ target: { filterType: "docHierarchyType" }
3551
+ };
3552
+ };
3553
+
3307
3554
  // src/utils/autoGenFilterConfigsFromTpl/utils/TEMP_removeDuplicateFilters.ts
3308
3555
  var TEMP_removeDuplicateFilters = (filterGroups) => {
3309
3556
  return filterGroups.map((group) => {
@@ -3440,7 +3687,25 @@ var autoGenFilterConfigsFromTpl = ({
3440
3687
  ...annotationRollupSections
3441
3688
  ].filter((section) => Array.isArray(section.configs) ? section.configs.length > 0 : true)
3442
3689
  };
3443
- const final_documentTagsFilterConfigs = {
3690
+ const isSMTDocFilterUI = isSelfManagedTenant && filterScopes.includes("doc");
3691
+ const final_documentTagsFilterConfigs = isSMTDocFilterUI ? (() => {
3692
+ const docHierarchyConfig = _self_managed_buildDocHierarchyConfig({
3693
+ combinedDocumentBlocks: extractedBlocks.combinedDocumentBlocks,
3694
+ docRollupBlocks: extractedBlocks.docRollupBlocks,
3695
+ selectedTpls,
3696
+ allTpls,
3697
+ commonDocumentFilters
3698
+ });
3699
+ if (!docHierarchyConfig) return { sectionId: "documentTagsSection", sectionTitle: "Document Filters", configs: [] };
3700
+ return {
3701
+ sectionId: "documentTagsSection",
3702
+ // sectionTitle: 'Document Filters',
3703
+ configs: [{
3704
+ sectionId: "self_managed_consolidated_doc_filters",
3705
+ configs: [docHierarchyConfig]
3706
+ }]
3707
+ };
3708
+ })() : {
3444
3709
  sectionId: "documentTagsSection",
3445
3710
  sectionTitle: "Document Filters",
3446
3711
  configs: [
@@ -3455,6 +3720,40 @@ var autoGenFilterConfigsFromTpl = ({
3455
3720
  return result;
3456
3721
  };
3457
3722
 
3723
+ // src/utils/genCleanCamelCaseId.ts
3724
+ var genCleanCamelCaseId = (id) => {
3725
+ if (!id || typeof id !== "string") return id;
3726
+ const isAlreadyClean = /^\p{Ll}[\p{L}\p{N}]*$/u.test(id) || /^a\d[\p{L}\p{N}]*$/u.test(id);
3727
+ if (isAlreadyClean) return id;
3728
+ const words = id.split(/[^\p{L}\p{N}]+/u).filter(Boolean);
3729
+ if (words.length === 0) return "a";
3730
+ const result = words.map((word, i) => {
3731
+ const lower = word.toLowerCase();
3732
+ return i === 0 ? lower : lower.charAt(0).toUpperCase() + lower.slice(1);
3733
+ }).join("");
3734
+ return /^\d/.test(result) ? "a" + result : result;
3735
+ };
3736
+
3737
+ // src/utils/genCleanIdForContentTypeAndValuePaths.ts
3738
+ var CHARS = "abcdefghijklmnopqrstuvwxyz0123456789";
3739
+ function genShortId(length = 4) {
3740
+ let result = "";
3741
+ for (let i = 0; i < length; i++) {
3742
+ result += CHARS[Math.floor(Math.random() * CHARS.length)];
3743
+ }
3744
+ return result;
3745
+ }
3746
+ var genCleanIdForContentTypeAndValuePaths = (text, maxLength = 10, shortIdLength = 4) => {
3747
+ if (!text || typeof text !== "string") return text;
3748
+ let cleaned = text.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
3749
+ if (!cleaned) {
3750
+ throw new Error(`[genCleanIdForContentTypeAndValuePaths] Input "${text}" contains no alphanumeric characters`);
3751
+ }
3752
+ if (/^\d/.test(cleaned)) cleaned = "a" + cleaned;
3753
+ const truncated = cleaned.slice(0, maxLength);
3754
+ return `${truncated}_${genShortId(shortIdLength)}`;
3755
+ };
3756
+
3458
3757
  // src/node.ts
3459
3758
  var import_MongoConnector3 = __toESM(require_MongoConnector());
3460
3759
  var import_ElasticSearchConnector = __toESM(require_ElasticSearchConnector());
@@ -3862,6 +4161,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
3862
4161
  UI_CONTENT,
3863
4162
  WorkerManager,
3864
4163
  _self_managed_buildAnnoHierarchyConfig,
4164
+ _self_managed_buildDocHierarchyConfig,
3865
4165
  _self_managed_getFixedAnnoRollupBlocks,
3866
4166
  _self_managed_getFixedAnnoTagBlock,
3867
4167
  autoGenFilterConfigsFromTpl,
@@ -3870,6 +4170,8 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
3870
4170
  deleteVal,
3871
4171
  extractAllBlocksFromTpl,
3872
4172
  extractAndOrganizeBlocks,
4173
+ genCleanCamelCaseId,
4174
+ genCleanIdForContentTypeAndValuePaths,
3873
4175
  genTagId,
3874
4176
  generateFilterKey,
3875
4177
  getAIChatModelByTenant,