@okf/ootils 1.18.3 → 1.20.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.
@@ -723,4 +723,30 @@ interface GetPlatformContextContentParams {
723
723
  }
724
724
  declare const getPlatformContextContent: ({ platformConfigs_ai, }: GetPlatformContextContentParams) => string;
725
725
 
726
- export { BASE_BULLMQ_CONFIG, deleteVal, extractAllBlocksFromTpl, genTagId, getPlatformContextContent, getRollupPossibilities, getVal, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
726
+ interface Author {
727
+ id: string | null;
728
+ name: string;
729
+ }
730
+ interface MergeParams {
731
+ prevObj: any;
732
+ newLexValue: any;
733
+ thisBlockValuePath: string;
734
+ author?: Author;
735
+ }
736
+ /**
737
+ * Merges annoData from a Lexical field into the consolidated annotations.tags structure.
738
+ *
739
+ * This function:
740
+ * 1. Removes all fragments from prevObj that belong to the given valuePath
741
+ * 2. Injects new fragments from annoData into the consolidated structure
742
+ * 3. Removes tags that have no fragments left
743
+ *
744
+ * @param prevObj - The existing consolidated annotations.tags object
745
+ * @param newLexValue - The new Lexical field value containing annoData
746
+ * @param thisBlockValuePath - The valuePath of the Lexical field being processed
747
+ * @param author - Optional author object. Defaults to { id: null, name: "AI" } for backend usage
748
+ * @returns The updated consolidated annotations.tags object
749
+ */
750
+ declare const mergeAnnoDataIntoAnnotationsTags: ({ prevObj, newLexValue, thisBlockValuePath, author, }: MergeParams) => any;
751
+
752
+ export { BASE_BULLMQ_CONFIG, deleteVal, extractAllBlocksFromTpl, genTagId, getPlatformContextContent, getRollupPossibilities, getVal, mergeAnnoDataIntoAnnotationsTags, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
package/dist/browser.d.ts CHANGED
@@ -723,4 +723,30 @@ interface GetPlatformContextContentParams {
723
723
  }
724
724
  declare const getPlatformContextContent: ({ platformConfigs_ai, }: GetPlatformContextContentParams) => string;
725
725
 
726
- export { BASE_BULLMQ_CONFIG, deleteVal, extractAllBlocksFromTpl, genTagId, getPlatformContextContent, getRollupPossibilities, getVal, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
726
+ interface Author {
727
+ id: string | null;
728
+ name: string;
729
+ }
730
+ interface MergeParams {
731
+ prevObj: any;
732
+ newLexValue: any;
733
+ thisBlockValuePath: string;
734
+ author?: Author;
735
+ }
736
+ /**
737
+ * Merges annoData from a Lexical field into the consolidated annotations.tags structure.
738
+ *
739
+ * This function:
740
+ * 1. Removes all fragments from prevObj that belong to the given valuePath
741
+ * 2. Injects new fragments from annoData into the consolidated structure
742
+ * 3. Removes tags that have no fragments left
743
+ *
744
+ * @param prevObj - The existing consolidated annotations.tags object
745
+ * @param newLexValue - The new Lexical field value containing annoData
746
+ * @param thisBlockValuePath - The valuePath of the Lexical field being processed
747
+ * @param author - Optional author object. Defaults to { id: null, name: "AI" } for backend usage
748
+ * @returns The updated consolidated annotations.tags object
749
+ */
750
+ declare const mergeAnnoDataIntoAnnotationsTags: ({ prevObj, newLexValue, thisBlockValuePath, author, }: MergeParams) => any;
751
+
752
+ export { BASE_BULLMQ_CONFIG, deleteVal, extractAllBlocksFromTpl, genTagId, getPlatformContextContent, getRollupPossibilities, getVal, mergeAnnoDataIntoAnnotationsTags, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
package/dist/browser.js CHANGED
@@ -27,6 +27,7 @@ __export(browser_exports, {
27
27
  getPlatformContextContent: () => getPlatformContextContent,
28
28
  getRollupPossibilities: () => getRollupPossibilities,
29
29
  getVal: () => getVal,
30
+ mergeAnnoDataIntoAnnotationsTags: () => mergeAnnoDataIntoAnnotationsTags,
30
31
  recursivelyExtractBlocks: () => _recursExtractBlocks,
31
32
  segrigateDocs: () => segrigateDocs,
32
33
  setVal: () => setVal,
@@ -765,6 +766,90 @@ ${v?.markdownText || ""}` : v?.markdownText || "";
765
766
  }
766
767
  return "";
767
768
  };
769
+
770
+ // src/utils/mergeAnnoDataIntoAnnotationsTags.ts
771
+ var import_lodash = require("lodash");
772
+ var mergeAnnoDataIntoAnnotationsTags = ({
773
+ prevObj,
774
+ newLexValue,
775
+ thisBlockValuePath,
776
+ author = { id: null, name: "AI" }
777
+ }) => {
778
+ let newConsolidated = (0, import_lodash.cloneDeep)(prevObj) || {};
779
+ const { annoData = {} } = newLexValue || {};
780
+ const existingKeys = /* @__PURE__ */ new Map();
781
+ Object.keys(newConsolidated).map((tagType) => {
782
+ if (newConsolidated[tagType].data?.length > 0) {
783
+ newConsolidated[tagType].data.forEach((tag, tagIdx) => {
784
+ if (tag.fragments?.length > 0) {
785
+ newConsolidated[tagType].data[tagIdx].fragments = newConsolidated[tagType].data[tagIdx].fragments.filter((frag) => {
786
+ existingKeys.set(frag.annoDataId, frag?.author ?? "");
787
+ if (frag.extractedFromValuePath !== thisBlockValuePath) {
788
+ return true;
789
+ } else {
790
+ return false;
791
+ }
792
+ });
793
+ }
794
+ });
795
+ }
796
+ });
797
+ Object.keys(annoData).map((annoDataId) => {
798
+ const { tags, fragment = {}, ...restAnnoData } = annoData[annoDataId];
799
+ const tagTypes = Object.keys(tags || {});
800
+ const buildFragment = () => ({
801
+ ...fragment,
802
+ ...restAnnoData,
803
+ annoDataId,
804
+ // Fallback to provided author if author not set (for backwards compatibility)
805
+ author: restAnnoData.author || existingKeys.get(annoDataId) || author,
806
+ extractedFromValuePath: thisBlockValuePath
807
+ });
808
+ if (tagTypes.length > 0) {
809
+ tagTypes.forEach((tagType) => {
810
+ const value = tags[tagType];
811
+ if (newConsolidated[tagType]?.data?.length > 0) {
812
+ value.data.forEach((d) => {
813
+ const foundTagIdx = newConsolidated[tagType].data.findIndex(
814
+ (dd) => dd._id === d._id
815
+ );
816
+ if (foundTagIdx !== -1) {
817
+ const fragsAry = newConsolidated[tagType].data[foundTagIdx].fragments || [];
818
+ if (fragsAry.length === 0) {
819
+ newConsolidated[tagType].data[foundTagIdx].fragments = [
820
+ buildFragment()
821
+ ];
822
+ } else {
823
+ newConsolidated[tagType].data[foundTagIdx].fragments.push(
824
+ buildFragment()
825
+ );
826
+ }
827
+ } else {
828
+ newConsolidated[tagType].data.push({
829
+ ...d,
830
+ fragments: [buildFragment()]
831
+ });
832
+ }
833
+ });
834
+ } else {
835
+ newConsolidated[tagType] = {
836
+ collectionId: value.collectionId,
837
+ data: value.data.map((d) => ({
838
+ ...d,
839
+ fragments: [buildFragment()]
840
+ }))
841
+ };
842
+ }
843
+ });
844
+ }
845
+ });
846
+ Object.keys(newConsolidated).forEach((tagType) => {
847
+ newConsolidated[tagType].data = newConsolidated[tagType].data.filter(
848
+ (d) => d.fragments?.length > 0
849
+ );
850
+ });
851
+ return newConsolidated;
852
+ };
768
853
  // Annotate the CommonJS export names for ESM import in node:
769
854
  0 && (module.exports = {
770
855
  BASE_BULLMQ_CONFIG,
@@ -774,6 +859,7 @@ ${v?.markdownText || ""}` : v?.markdownText || "";
774
859
  getPlatformContextContent,
775
860
  getRollupPossibilities,
776
861
  getVal,
862
+ mergeAnnoDataIntoAnnotationsTags,
777
863
  recursivelyExtractBlocks,
778
864
  segrigateDocs,
779
865
  setVal,
package/dist/browser.mjs CHANGED
@@ -729,6 +729,90 @@ ${v?.markdownText || ""}` : v?.markdownText || "";
729
729
  }
730
730
  return "";
731
731
  };
732
+
733
+ // src/utils/mergeAnnoDataIntoAnnotationsTags.ts
734
+ import { cloneDeep } from "lodash";
735
+ var mergeAnnoDataIntoAnnotationsTags = ({
736
+ prevObj,
737
+ newLexValue,
738
+ thisBlockValuePath,
739
+ author = { id: null, name: "AI" }
740
+ }) => {
741
+ let newConsolidated = cloneDeep(prevObj) || {};
742
+ const { annoData = {} } = newLexValue || {};
743
+ const existingKeys = /* @__PURE__ */ new Map();
744
+ Object.keys(newConsolidated).map((tagType) => {
745
+ if (newConsolidated[tagType].data?.length > 0) {
746
+ newConsolidated[tagType].data.forEach((tag, tagIdx) => {
747
+ if (tag.fragments?.length > 0) {
748
+ newConsolidated[tagType].data[tagIdx].fragments = newConsolidated[tagType].data[tagIdx].fragments.filter((frag) => {
749
+ existingKeys.set(frag.annoDataId, frag?.author ?? "");
750
+ if (frag.extractedFromValuePath !== thisBlockValuePath) {
751
+ return true;
752
+ } else {
753
+ return false;
754
+ }
755
+ });
756
+ }
757
+ });
758
+ }
759
+ });
760
+ Object.keys(annoData).map((annoDataId) => {
761
+ const { tags, fragment = {}, ...restAnnoData } = annoData[annoDataId];
762
+ const tagTypes = Object.keys(tags || {});
763
+ const buildFragment = () => ({
764
+ ...fragment,
765
+ ...restAnnoData,
766
+ annoDataId,
767
+ // Fallback to provided author if author not set (for backwards compatibility)
768
+ author: restAnnoData.author || existingKeys.get(annoDataId) || author,
769
+ extractedFromValuePath: thisBlockValuePath
770
+ });
771
+ if (tagTypes.length > 0) {
772
+ tagTypes.forEach((tagType) => {
773
+ const value = tags[tagType];
774
+ if (newConsolidated[tagType]?.data?.length > 0) {
775
+ value.data.forEach((d) => {
776
+ const foundTagIdx = newConsolidated[tagType].data.findIndex(
777
+ (dd) => dd._id === d._id
778
+ );
779
+ if (foundTagIdx !== -1) {
780
+ const fragsAry = newConsolidated[tagType].data[foundTagIdx].fragments || [];
781
+ if (fragsAry.length === 0) {
782
+ newConsolidated[tagType].data[foundTagIdx].fragments = [
783
+ buildFragment()
784
+ ];
785
+ } else {
786
+ newConsolidated[tagType].data[foundTagIdx].fragments.push(
787
+ buildFragment()
788
+ );
789
+ }
790
+ } else {
791
+ newConsolidated[tagType].data.push({
792
+ ...d,
793
+ fragments: [buildFragment()]
794
+ });
795
+ }
796
+ });
797
+ } else {
798
+ newConsolidated[tagType] = {
799
+ collectionId: value.collectionId,
800
+ data: value.data.map((d) => ({
801
+ ...d,
802
+ fragments: [buildFragment()]
803
+ }))
804
+ };
805
+ }
806
+ });
807
+ }
808
+ });
809
+ Object.keys(newConsolidated).forEach((tagType) => {
810
+ newConsolidated[tagType].data = newConsolidated[tagType].data.filter(
811
+ (d) => d.fragments?.length > 0
812
+ );
813
+ });
814
+ return newConsolidated;
815
+ };
732
816
  export {
733
817
  BASE_BULLMQ_CONFIG,
734
818
  deleteVal,
@@ -737,6 +821,7 @@ export {
737
821
  getPlatformContextContent,
738
822
  getRollupPossibilities,
739
823
  getVal,
824
+ mergeAnnoDataIntoAnnotationsTags,
740
825
  _recursExtractBlocks as recursivelyExtractBlocks,
741
826
  segrigateDocs,
742
827
  setVal,
package/dist/node.d.mts CHANGED
@@ -731,6 +731,32 @@ interface GetPlatformContextContentParams {
731
731
  }
732
732
  declare const getPlatformContextContent: ({ platformConfigs_ai, }: GetPlatformContextContentParams) => string;
733
733
 
734
+ interface Author {
735
+ id: string | null;
736
+ name: string;
737
+ }
738
+ interface MergeParams {
739
+ prevObj: any;
740
+ newLexValue: any;
741
+ thisBlockValuePath: string;
742
+ author?: Author;
743
+ }
744
+ /**
745
+ * Merges annoData from a Lexical field into the consolidated annotations.tags structure.
746
+ *
747
+ * This function:
748
+ * 1. Removes all fragments from prevObj that belong to the given valuePath
749
+ * 2. Injects new fragments from annoData into the consolidated structure
750
+ * 3. Removes tags that have no fragments left
751
+ *
752
+ * @param prevObj - The existing consolidated annotations.tags object
753
+ * @param newLexValue - The new Lexical field value containing annoData
754
+ * @param thisBlockValuePath - The valuePath of the Lexical field being processed
755
+ * @param author - Optional author object. Defaults to { id: null, name: "AI" } for backend usage
756
+ * @returns The updated consolidated annotations.tags object
757
+ */
758
+ declare const mergeAnnoDataIntoAnnotationsTags: ({ prevObj, newLexValue, thisBlockValuePath, author, }: MergeParams) => any;
759
+
734
760
  declare class MongoConnector {
735
761
  static getInstance(): any;
736
762
  static getClusterConnections(): any;
@@ -1277,6 +1303,19 @@ declare class BaseWorker {
1277
1303
  stop(): Promise<void>;
1278
1304
  }
1279
1305
 
1306
+ /**
1307
+ * Producer for Elasticsearch sync jobs for chunks
1308
+ */
1309
+ declare class ChunksElasticSyncProducer extends BaseProducer {
1310
+ constructor(options?: {});
1311
+ /**
1312
+ * Add a single sync job
1313
+ * @param {Object} jobData - Job data containing docIds, tenant, operationType
1314
+ * @returns {Promise<Object>} Job creation result
1315
+ */
1316
+ addJobWithName(jobData: Object): Promise<Object>;
1317
+ }
1318
+
1280
1319
  /**
1281
1320
  * Creates BullMQ configuration with explicit dependencies
1282
1321
  * @param {Object} params Configuration parameters
@@ -1296,4 +1335,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
1296
1335
  };
1297
1336
  }): Object;
1298
1337
 
1299
- export { AIChatSchema, AnnotationSchema, BASE_BULLMQ_CONFIG, BaseProducer, BaseWorker, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, GeneratedTopicsSchema, MongoConnector, PlatformConfigsSchema, ProducerManager, RedisCacheConnector, TplSchema, WorkerManager, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAnnotationsModelByTenant, getDbByTenant, getGeneratedTopicsModelByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getPlatformContextContent, getRollupPossibilities, getTplModelByTenant, getVal, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
1338
+ export { AIChatSchema, AnnotationSchema, BASE_BULLMQ_CONFIG, BaseProducer, BaseWorker, ChunksElasticSyncProducer, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, GeneratedTopicsSchema, MongoConnector, PlatformConfigsSchema, ProducerManager, RedisCacheConnector, TplSchema, WorkerManager, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAnnotationsModelByTenant, getDbByTenant, getGeneratedTopicsModelByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getPlatformContextContent, getRollupPossibilities, getTplModelByTenant, getVal, mergeAnnoDataIntoAnnotationsTags, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
package/dist/node.d.ts CHANGED
@@ -731,6 +731,32 @@ interface GetPlatformContextContentParams {
731
731
  }
732
732
  declare const getPlatformContextContent: ({ platformConfigs_ai, }: GetPlatformContextContentParams) => string;
733
733
 
734
+ interface Author {
735
+ id: string | null;
736
+ name: string;
737
+ }
738
+ interface MergeParams {
739
+ prevObj: any;
740
+ newLexValue: any;
741
+ thisBlockValuePath: string;
742
+ author?: Author;
743
+ }
744
+ /**
745
+ * Merges annoData from a Lexical field into the consolidated annotations.tags structure.
746
+ *
747
+ * This function:
748
+ * 1. Removes all fragments from prevObj that belong to the given valuePath
749
+ * 2. Injects new fragments from annoData into the consolidated structure
750
+ * 3. Removes tags that have no fragments left
751
+ *
752
+ * @param prevObj - The existing consolidated annotations.tags object
753
+ * @param newLexValue - The new Lexical field value containing annoData
754
+ * @param thisBlockValuePath - The valuePath of the Lexical field being processed
755
+ * @param author - Optional author object. Defaults to { id: null, name: "AI" } for backend usage
756
+ * @returns The updated consolidated annotations.tags object
757
+ */
758
+ declare const mergeAnnoDataIntoAnnotationsTags: ({ prevObj, newLexValue, thisBlockValuePath, author, }: MergeParams) => any;
759
+
734
760
  declare class MongoConnector {
735
761
  static getInstance(): any;
736
762
  static getClusterConnections(): any;
@@ -1277,6 +1303,19 @@ declare class BaseWorker {
1277
1303
  stop(): Promise<void>;
1278
1304
  }
1279
1305
 
1306
+ /**
1307
+ * Producer for Elasticsearch sync jobs for chunks
1308
+ */
1309
+ declare class ChunksElasticSyncProducer extends BaseProducer {
1310
+ constructor(options?: {});
1311
+ /**
1312
+ * Add a single sync job
1313
+ * @param {Object} jobData - Job data containing docIds, tenant, operationType
1314
+ * @returns {Promise<Object>} Job creation result
1315
+ */
1316
+ addJobWithName(jobData: Object): Promise<Object>;
1317
+ }
1318
+
1280
1319
  /**
1281
1320
  * Creates BullMQ configuration with explicit dependencies
1282
1321
  * @param {Object} params Configuration parameters
@@ -1296,4 +1335,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
1296
1335
  };
1297
1336
  }): Object;
1298
1337
 
1299
- export { AIChatSchema, AnnotationSchema, BASE_BULLMQ_CONFIG, BaseProducer, BaseWorker, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, GeneratedTopicsSchema, MongoConnector, PlatformConfigsSchema, ProducerManager, RedisCacheConnector, TplSchema, WorkerManager, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAnnotationsModelByTenant, getDbByTenant, getGeneratedTopicsModelByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getPlatformContextContent, getRollupPossibilities, getTplModelByTenant, getVal, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
1338
+ export { AIChatSchema, AnnotationSchema, BASE_BULLMQ_CONFIG, BaseProducer, BaseWorker, ChunksElasticSyncProducer, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, GeneratedTopicsSchema, MongoConnector, PlatformConfigsSchema, ProducerManager, RedisCacheConnector, TplSchema, WorkerManager, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAnnotationsModelByTenant, getDbByTenant, getGeneratedTopicsModelByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getPlatformContextContent, getRollupPossibilities, getTplModelByTenant, getVal, mergeAnnoDataIntoAnnotationsTags, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
package/dist/node.js CHANGED
@@ -1552,6 +1552,48 @@ var require_GET_GLOBAL_BULLMQ_CONFIG = __commonJS({
1552
1552
  }
1553
1553
  });
1554
1554
 
1555
+ // src/bullmq/ChunksElasticSyncProducer.js
1556
+ var require_ChunksElasticSyncProducer = __commonJS({
1557
+ "src/bullmq/ChunksElasticSyncProducer.js"(exports2, module2) {
1558
+ "use strict";
1559
+ var { BaseProducer: BaseProducer2 } = require_BaseProducer();
1560
+ var { GET_GLOBAL_BULLMQ_CONFIG: GET_GLOBAL_BULLMQ_CONFIG2 } = require_GET_GLOBAL_BULLMQ_CONFIG();
1561
+ var ChunksElasticSyncProducer2 = class extends BaseProducer2 {
1562
+ // Preserve class name through minification for ProducerManager lookup
1563
+ static get name() {
1564
+ return "ChunksElasticSyncProducer";
1565
+ }
1566
+ // options - Configuration options (optional, defaults to process.env)
1567
+ constructor(options = {}) {
1568
+ const env = options.env || process.env.ENV;
1569
+ const redisCredentials = options.redisCredentials || {
1570
+ REDIS_HOST: process.env.REDIS_HOST,
1571
+ REDIS_PORT: process.env.REDIS_PORT,
1572
+ REDIS_PASSWORD: process.env.REDIS_PASSWORD
1573
+ };
1574
+ const GLOBAL_BULLMQ_CONFIG = GET_GLOBAL_BULLMQ_CONFIG2({
1575
+ env,
1576
+ redisCredentials
1577
+ });
1578
+ super(GLOBAL_BULLMQ_CONFIG.CHUNKS_ELASTIC_SYNC_QUEUE);
1579
+ }
1580
+ /**
1581
+ * Add a single sync job
1582
+ * @param {Object} jobData - Job data containing docIds, tenant, operationType
1583
+ * @returns {Promise<Object>} Job creation result
1584
+ */
1585
+ async addJobWithName(jobData) {
1586
+ const job = await this.addJob("processChunksElasticSync", jobData);
1587
+ console.log(`\u{1F4C8} Added process chunks elastic sync job: ${job.id}`);
1588
+ return { jobId: job.id };
1589
+ }
1590
+ };
1591
+ module2.exports = {
1592
+ ChunksElasticSyncProducer: ChunksElasticSyncProducer2
1593
+ };
1594
+ }
1595
+ });
1596
+
1555
1597
  // src/node.ts
1556
1598
  var node_exports = {};
1557
1599
  __export(node_exports, {
@@ -1560,6 +1602,7 @@ __export(node_exports, {
1560
1602
  BASE_BULLMQ_CONFIG: () => BASE_BULLMQ_CONFIG,
1561
1603
  BaseProducer: () => import_BaseProducer.BaseProducer,
1562
1604
  BaseWorker: () => import_BaseWorker.BaseWorker,
1605
+ ChunksElasticSyncProducer: () => import_ChunksElasticSyncProducer.ChunksElasticSyncProducer,
1563
1606
  ElasticSearchConnector: () => import_ElasticSearchConnector.ElasticSearchConnector,
1564
1607
  GET_GLOBAL_BULLMQ_CONFIG: () => import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG,
1565
1608
  GeneratedTopicsSchema: () => GeneratedTopics_default,
@@ -1582,6 +1625,7 @@ __export(node_exports, {
1582
1625
  getRollupPossibilities: () => getRollupPossibilities,
1583
1626
  getTplModelByTenant: () => import_getModelByTenant2.getTplModelByTenant,
1584
1627
  getVal: () => getVal,
1628
+ mergeAnnoDataIntoAnnotationsTags: () => mergeAnnoDataIntoAnnotationsTags,
1585
1629
  recursivelyExtractBlocks: () => _recursExtractBlocks,
1586
1630
  segrigateDocs: () => segrigateDocs,
1587
1631
  setVal: () => setVal,
@@ -2021,6 +2065,90 @@ ${v?.markdownText || ""}` : v?.markdownText || "";
2021
2065
  return "";
2022
2066
  };
2023
2067
 
2068
+ // src/utils/mergeAnnoDataIntoAnnotationsTags.ts
2069
+ var import_lodash = require("lodash");
2070
+ var mergeAnnoDataIntoAnnotationsTags = ({
2071
+ prevObj,
2072
+ newLexValue,
2073
+ thisBlockValuePath,
2074
+ author = { id: null, name: "AI" }
2075
+ }) => {
2076
+ let newConsolidated = (0, import_lodash.cloneDeep)(prevObj) || {};
2077
+ const { annoData = {} } = newLexValue || {};
2078
+ const existingKeys = /* @__PURE__ */ new Map();
2079
+ Object.keys(newConsolidated).map((tagType) => {
2080
+ if (newConsolidated[tagType].data?.length > 0) {
2081
+ newConsolidated[tagType].data.forEach((tag, tagIdx) => {
2082
+ if (tag.fragments?.length > 0) {
2083
+ newConsolidated[tagType].data[tagIdx].fragments = newConsolidated[tagType].data[tagIdx].fragments.filter((frag) => {
2084
+ existingKeys.set(frag.annoDataId, frag?.author ?? "");
2085
+ if (frag.extractedFromValuePath !== thisBlockValuePath) {
2086
+ return true;
2087
+ } else {
2088
+ return false;
2089
+ }
2090
+ });
2091
+ }
2092
+ });
2093
+ }
2094
+ });
2095
+ Object.keys(annoData).map((annoDataId) => {
2096
+ const { tags, fragment = {}, ...restAnnoData } = annoData[annoDataId];
2097
+ const tagTypes = Object.keys(tags || {});
2098
+ const buildFragment = () => ({
2099
+ ...fragment,
2100
+ ...restAnnoData,
2101
+ annoDataId,
2102
+ // Fallback to provided author if author not set (for backwards compatibility)
2103
+ author: restAnnoData.author || existingKeys.get(annoDataId) || author,
2104
+ extractedFromValuePath: thisBlockValuePath
2105
+ });
2106
+ if (tagTypes.length > 0) {
2107
+ tagTypes.forEach((tagType) => {
2108
+ const value = tags[tagType];
2109
+ if (newConsolidated[tagType]?.data?.length > 0) {
2110
+ value.data.forEach((d) => {
2111
+ const foundTagIdx = newConsolidated[tagType].data.findIndex(
2112
+ (dd) => dd._id === d._id
2113
+ );
2114
+ if (foundTagIdx !== -1) {
2115
+ const fragsAry = newConsolidated[tagType].data[foundTagIdx].fragments || [];
2116
+ if (fragsAry.length === 0) {
2117
+ newConsolidated[tagType].data[foundTagIdx].fragments = [
2118
+ buildFragment()
2119
+ ];
2120
+ } else {
2121
+ newConsolidated[tagType].data[foundTagIdx].fragments.push(
2122
+ buildFragment()
2123
+ );
2124
+ }
2125
+ } else {
2126
+ newConsolidated[tagType].data.push({
2127
+ ...d,
2128
+ fragments: [buildFragment()]
2129
+ });
2130
+ }
2131
+ });
2132
+ } else {
2133
+ newConsolidated[tagType] = {
2134
+ collectionId: value.collectionId,
2135
+ data: value.data.map((d) => ({
2136
+ ...d,
2137
+ fragments: [buildFragment()]
2138
+ }))
2139
+ };
2140
+ }
2141
+ });
2142
+ }
2143
+ });
2144
+ Object.keys(newConsolidated).forEach((tagType) => {
2145
+ newConsolidated[tagType].data = newConsolidated[tagType].data.filter(
2146
+ (d) => d.fragments?.length > 0
2147
+ );
2148
+ });
2149
+ return newConsolidated;
2150
+ };
2151
+
2024
2152
  // src/node.ts
2025
2153
  var import_MongoConnector2 = __toESM(require_MongoConnector());
2026
2154
  var import_ElasticSearchConnector = __toESM(require_ElasticSearchConnector());
@@ -2353,6 +2481,7 @@ var import_WorkerManager = __toESM(require_WorkerManager());
2353
2481
  var import_ProducerManager = __toESM(require_ProducerManager());
2354
2482
  var import_BaseProducer = __toESM(require_BaseProducer());
2355
2483
  var import_BaseWorker = __toESM(require_BaseWorker());
2484
+ var import_ChunksElasticSyncProducer = __toESM(require_ChunksElasticSyncProducer());
2356
2485
  var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG());
2357
2486
  // Annotate the CommonJS export names for ESM import in node:
2358
2487
  0 && (module.exports = {
@@ -2361,6 +2490,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
2361
2490
  BASE_BULLMQ_CONFIG,
2362
2491
  BaseProducer,
2363
2492
  BaseWorker,
2493
+ ChunksElasticSyncProducer,
2364
2494
  ElasticSearchConnector,
2365
2495
  GET_GLOBAL_BULLMQ_CONFIG,
2366
2496
  GeneratedTopicsSchema,
@@ -2383,6 +2513,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
2383
2513
  getRollupPossibilities,
2384
2514
  getTplModelByTenant,
2385
2515
  getVal,
2516
+ mergeAnnoDataIntoAnnotationsTags,
2386
2517
  recursivelyExtractBlocks,
2387
2518
  segrigateDocs,
2388
2519
  setVal,
package/dist/node.mjs CHANGED
@@ -1557,6 +1557,48 @@ var require_GET_GLOBAL_BULLMQ_CONFIG = __commonJS({
1557
1557
  }
1558
1558
  });
1559
1559
 
1560
+ // src/bullmq/ChunksElasticSyncProducer.js
1561
+ var require_ChunksElasticSyncProducer = __commonJS({
1562
+ "src/bullmq/ChunksElasticSyncProducer.js"(exports, module) {
1563
+ "use strict";
1564
+ var { BaseProducer: BaseProducer2 } = require_BaseProducer();
1565
+ var { GET_GLOBAL_BULLMQ_CONFIG: GET_GLOBAL_BULLMQ_CONFIG2 } = require_GET_GLOBAL_BULLMQ_CONFIG();
1566
+ var ChunksElasticSyncProducer2 = class extends BaseProducer2 {
1567
+ // Preserve class name through minification for ProducerManager lookup
1568
+ static get name() {
1569
+ return "ChunksElasticSyncProducer";
1570
+ }
1571
+ // options - Configuration options (optional, defaults to process.env)
1572
+ constructor(options = {}) {
1573
+ const env = options.env || process.env.ENV;
1574
+ const redisCredentials = options.redisCredentials || {
1575
+ REDIS_HOST: process.env.REDIS_HOST,
1576
+ REDIS_PORT: process.env.REDIS_PORT,
1577
+ REDIS_PASSWORD: process.env.REDIS_PASSWORD
1578
+ };
1579
+ const GLOBAL_BULLMQ_CONFIG = GET_GLOBAL_BULLMQ_CONFIG2({
1580
+ env,
1581
+ redisCredentials
1582
+ });
1583
+ super(GLOBAL_BULLMQ_CONFIG.CHUNKS_ELASTIC_SYNC_QUEUE);
1584
+ }
1585
+ /**
1586
+ * Add a single sync job
1587
+ * @param {Object} jobData - Job data containing docIds, tenant, operationType
1588
+ * @returns {Promise<Object>} Job creation result
1589
+ */
1590
+ async addJobWithName(jobData) {
1591
+ const job = await this.addJob("processChunksElasticSync", jobData);
1592
+ console.log(`\u{1F4C8} Added process chunks elastic sync job: ${job.id}`);
1593
+ return { jobId: job.id };
1594
+ }
1595
+ };
1596
+ module.exports = {
1597
+ ChunksElasticSyncProducer: ChunksElasticSyncProducer2
1598
+ };
1599
+ }
1600
+ });
1601
+
1560
1602
  // src/utils/getterSetterDeleter/utils/set_deleteVal.ts
1561
1603
  var set_deleteVal = (action, data, valuePath, value) => {
1562
1604
  if (valuePath === void 0) return;
@@ -1989,6 +2031,90 @@ ${v?.markdownText || ""}` : v?.markdownText || "";
1989
2031
  return "";
1990
2032
  };
1991
2033
 
2034
+ // src/utils/mergeAnnoDataIntoAnnotationsTags.ts
2035
+ import { cloneDeep } from "lodash";
2036
+ var mergeAnnoDataIntoAnnotationsTags = ({
2037
+ prevObj,
2038
+ newLexValue,
2039
+ thisBlockValuePath,
2040
+ author = { id: null, name: "AI" }
2041
+ }) => {
2042
+ let newConsolidated = cloneDeep(prevObj) || {};
2043
+ const { annoData = {} } = newLexValue || {};
2044
+ const existingKeys = /* @__PURE__ */ new Map();
2045
+ Object.keys(newConsolidated).map((tagType) => {
2046
+ if (newConsolidated[tagType].data?.length > 0) {
2047
+ newConsolidated[tagType].data.forEach((tag, tagIdx) => {
2048
+ if (tag.fragments?.length > 0) {
2049
+ newConsolidated[tagType].data[tagIdx].fragments = newConsolidated[tagType].data[tagIdx].fragments.filter((frag) => {
2050
+ existingKeys.set(frag.annoDataId, frag?.author ?? "");
2051
+ if (frag.extractedFromValuePath !== thisBlockValuePath) {
2052
+ return true;
2053
+ } else {
2054
+ return false;
2055
+ }
2056
+ });
2057
+ }
2058
+ });
2059
+ }
2060
+ });
2061
+ Object.keys(annoData).map((annoDataId) => {
2062
+ const { tags, fragment = {}, ...restAnnoData } = annoData[annoDataId];
2063
+ const tagTypes = Object.keys(tags || {});
2064
+ const buildFragment = () => ({
2065
+ ...fragment,
2066
+ ...restAnnoData,
2067
+ annoDataId,
2068
+ // Fallback to provided author if author not set (for backwards compatibility)
2069
+ author: restAnnoData.author || existingKeys.get(annoDataId) || author,
2070
+ extractedFromValuePath: thisBlockValuePath
2071
+ });
2072
+ if (tagTypes.length > 0) {
2073
+ tagTypes.forEach((tagType) => {
2074
+ const value = tags[tagType];
2075
+ if (newConsolidated[tagType]?.data?.length > 0) {
2076
+ value.data.forEach((d) => {
2077
+ const foundTagIdx = newConsolidated[tagType].data.findIndex(
2078
+ (dd) => dd._id === d._id
2079
+ );
2080
+ if (foundTagIdx !== -1) {
2081
+ const fragsAry = newConsolidated[tagType].data[foundTagIdx].fragments || [];
2082
+ if (fragsAry.length === 0) {
2083
+ newConsolidated[tagType].data[foundTagIdx].fragments = [
2084
+ buildFragment()
2085
+ ];
2086
+ } else {
2087
+ newConsolidated[tagType].data[foundTagIdx].fragments.push(
2088
+ buildFragment()
2089
+ );
2090
+ }
2091
+ } else {
2092
+ newConsolidated[tagType].data.push({
2093
+ ...d,
2094
+ fragments: [buildFragment()]
2095
+ });
2096
+ }
2097
+ });
2098
+ } else {
2099
+ newConsolidated[tagType] = {
2100
+ collectionId: value.collectionId,
2101
+ data: value.data.map((d) => ({
2102
+ ...d,
2103
+ fragments: [buildFragment()]
2104
+ }))
2105
+ };
2106
+ }
2107
+ });
2108
+ }
2109
+ });
2110
+ Object.keys(newConsolidated).forEach((tagType) => {
2111
+ newConsolidated[tagType].data = newConsolidated[tagType].data.filter(
2112
+ (d) => d.fragments?.length > 0
2113
+ );
2114
+ });
2115
+ return newConsolidated;
2116
+ };
2117
+
1992
2118
  // src/node.ts
1993
2119
  var import_MongoConnector2 = __toESM(require_MongoConnector());
1994
2120
  var import_ElasticSearchConnector = __toESM(require_ElasticSearchConnector());
@@ -2321,9 +2447,11 @@ var import_WorkerManager = __toESM(require_WorkerManager());
2321
2447
  var import_ProducerManager = __toESM(require_ProducerManager());
2322
2448
  var import_BaseProducer = __toESM(require_BaseProducer());
2323
2449
  var import_BaseWorker = __toESM(require_BaseWorker());
2450
+ var import_ChunksElasticSyncProducer = __toESM(require_ChunksElasticSyncProducer());
2324
2451
  var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG());
2325
2452
  var export_BaseProducer = import_BaseProducer.BaseProducer;
2326
2453
  var export_BaseWorker = import_BaseWorker.BaseWorker;
2454
+ var export_ChunksElasticSyncProducer = import_ChunksElasticSyncProducer.ChunksElasticSyncProducer;
2327
2455
  var export_ElasticSearchConnector = import_ElasticSearchConnector.ElasticSearchConnector;
2328
2456
  var export_GET_GLOBAL_BULLMQ_CONFIG = import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG;
2329
2457
  var export_MongoConnector = import_MongoConnector2.MongoConnector;
@@ -2341,6 +2469,7 @@ export {
2341
2469
  BASE_BULLMQ_CONFIG,
2342
2470
  export_BaseProducer as BaseProducer,
2343
2471
  export_BaseWorker as BaseWorker,
2472
+ export_ChunksElasticSyncProducer as ChunksElasticSyncProducer,
2344
2473
  export_ElasticSearchConnector as ElasticSearchConnector,
2345
2474
  export_GET_GLOBAL_BULLMQ_CONFIG as GET_GLOBAL_BULLMQ_CONFIG,
2346
2475
  GeneratedTopics_default as GeneratedTopicsSchema,
@@ -2363,6 +2492,7 @@ export {
2363
2492
  getRollupPossibilities,
2364
2493
  export_getTplModelByTenant as getTplModelByTenant,
2365
2494
  getVal,
2495
+ mergeAnnoDataIntoAnnotationsTags,
2366
2496
  _recursExtractBlocks as recursivelyExtractBlocks,
2367
2497
  segrigateDocs,
2368
2498
  setVal,
@@ -723,4 +723,30 @@ interface GetPlatformContextContentParams {
723
723
  }
724
724
  declare const getPlatformContextContent: ({ platformConfigs_ai, }: GetPlatformContextContentParams) => string;
725
725
 
726
- export { BASE_BULLMQ_CONFIG, deleteVal, extractAllBlocksFromTpl, genTagId, getPlatformContextContent, getRollupPossibilities, getVal, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
726
+ interface Author {
727
+ id: string | null;
728
+ name: string;
729
+ }
730
+ interface MergeParams {
731
+ prevObj: any;
732
+ newLexValue: any;
733
+ thisBlockValuePath: string;
734
+ author?: Author;
735
+ }
736
+ /**
737
+ * Merges annoData from a Lexical field into the consolidated annotations.tags structure.
738
+ *
739
+ * This function:
740
+ * 1. Removes all fragments from prevObj that belong to the given valuePath
741
+ * 2. Injects new fragments from annoData into the consolidated structure
742
+ * 3. Removes tags that have no fragments left
743
+ *
744
+ * @param prevObj - The existing consolidated annotations.tags object
745
+ * @param newLexValue - The new Lexical field value containing annoData
746
+ * @param thisBlockValuePath - The valuePath of the Lexical field being processed
747
+ * @param author - Optional author object. Defaults to { id: null, name: "AI" } for backend usage
748
+ * @returns The updated consolidated annotations.tags object
749
+ */
750
+ declare const mergeAnnoDataIntoAnnotationsTags: ({ prevObj, newLexValue, thisBlockValuePath, author, }: MergeParams) => any;
751
+
752
+ export { BASE_BULLMQ_CONFIG, deleteVal, extractAllBlocksFromTpl, genTagId, getPlatformContextContent, getRollupPossibilities, getVal, mergeAnnoDataIntoAnnotationsTags, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
@@ -723,4 +723,30 @@ interface GetPlatformContextContentParams {
723
723
  }
724
724
  declare const getPlatformContextContent: ({ platformConfigs_ai, }: GetPlatformContextContentParams) => string;
725
725
 
726
- export { BASE_BULLMQ_CONFIG, deleteVal, extractAllBlocksFromTpl, genTagId, getPlatformContextContent, getRollupPossibilities, getVal, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
726
+ interface Author {
727
+ id: string | null;
728
+ name: string;
729
+ }
730
+ interface MergeParams {
731
+ prevObj: any;
732
+ newLexValue: any;
733
+ thisBlockValuePath: string;
734
+ author?: Author;
735
+ }
736
+ /**
737
+ * Merges annoData from a Lexical field into the consolidated annotations.tags structure.
738
+ *
739
+ * This function:
740
+ * 1. Removes all fragments from prevObj that belong to the given valuePath
741
+ * 2. Injects new fragments from annoData into the consolidated structure
742
+ * 3. Removes tags that have no fragments left
743
+ *
744
+ * @param prevObj - The existing consolidated annotations.tags object
745
+ * @param newLexValue - The new Lexical field value containing annoData
746
+ * @param thisBlockValuePath - The valuePath of the Lexical field being processed
747
+ * @param author - Optional author object. Defaults to { id: null, name: "AI" } for backend usage
748
+ * @returns The updated consolidated annotations.tags object
749
+ */
750
+ declare const mergeAnnoDataIntoAnnotationsTags: ({ prevObj, newLexValue, thisBlockValuePath, author, }: MergeParams) => any;
751
+
752
+ export { BASE_BULLMQ_CONFIG, deleteVal, extractAllBlocksFromTpl, genTagId, getPlatformContextContent, getRollupPossibilities, getVal, mergeAnnoDataIntoAnnotationsTags, _recursExtractBlocks as recursivelyExtractBlocks, segrigateDocs, setVal, toArray };
package/dist/universal.js CHANGED
@@ -27,6 +27,7 @@ __export(universal_exports, {
27
27
  getPlatformContextContent: () => getPlatformContextContent,
28
28
  getRollupPossibilities: () => getRollupPossibilities,
29
29
  getVal: () => getVal,
30
+ mergeAnnoDataIntoAnnotationsTags: () => mergeAnnoDataIntoAnnotationsTags,
30
31
  recursivelyExtractBlocks: () => _recursExtractBlocks,
31
32
  segrigateDocs: () => segrigateDocs,
32
33
  setVal: () => setVal,
@@ -765,6 +766,90 @@ ${v?.markdownText || ""}` : v?.markdownText || "";
765
766
  }
766
767
  return "";
767
768
  };
769
+
770
+ // src/utils/mergeAnnoDataIntoAnnotationsTags.ts
771
+ var import_lodash = require("lodash");
772
+ var mergeAnnoDataIntoAnnotationsTags = ({
773
+ prevObj,
774
+ newLexValue,
775
+ thisBlockValuePath,
776
+ author = { id: null, name: "AI" }
777
+ }) => {
778
+ let newConsolidated = (0, import_lodash.cloneDeep)(prevObj) || {};
779
+ const { annoData = {} } = newLexValue || {};
780
+ const existingKeys = /* @__PURE__ */ new Map();
781
+ Object.keys(newConsolidated).map((tagType) => {
782
+ if (newConsolidated[tagType].data?.length > 0) {
783
+ newConsolidated[tagType].data.forEach((tag, tagIdx) => {
784
+ if (tag.fragments?.length > 0) {
785
+ newConsolidated[tagType].data[tagIdx].fragments = newConsolidated[tagType].data[tagIdx].fragments.filter((frag) => {
786
+ existingKeys.set(frag.annoDataId, frag?.author ?? "");
787
+ if (frag.extractedFromValuePath !== thisBlockValuePath) {
788
+ return true;
789
+ } else {
790
+ return false;
791
+ }
792
+ });
793
+ }
794
+ });
795
+ }
796
+ });
797
+ Object.keys(annoData).map((annoDataId) => {
798
+ const { tags, fragment = {}, ...restAnnoData } = annoData[annoDataId];
799
+ const tagTypes = Object.keys(tags || {});
800
+ const buildFragment = () => ({
801
+ ...fragment,
802
+ ...restAnnoData,
803
+ annoDataId,
804
+ // Fallback to provided author if author not set (for backwards compatibility)
805
+ author: restAnnoData.author || existingKeys.get(annoDataId) || author,
806
+ extractedFromValuePath: thisBlockValuePath
807
+ });
808
+ if (tagTypes.length > 0) {
809
+ tagTypes.forEach((tagType) => {
810
+ const value = tags[tagType];
811
+ if (newConsolidated[tagType]?.data?.length > 0) {
812
+ value.data.forEach((d) => {
813
+ const foundTagIdx = newConsolidated[tagType].data.findIndex(
814
+ (dd) => dd._id === d._id
815
+ );
816
+ if (foundTagIdx !== -1) {
817
+ const fragsAry = newConsolidated[tagType].data[foundTagIdx].fragments || [];
818
+ if (fragsAry.length === 0) {
819
+ newConsolidated[tagType].data[foundTagIdx].fragments = [
820
+ buildFragment()
821
+ ];
822
+ } else {
823
+ newConsolidated[tagType].data[foundTagIdx].fragments.push(
824
+ buildFragment()
825
+ );
826
+ }
827
+ } else {
828
+ newConsolidated[tagType].data.push({
829
+ ...d,
830
+ fragments: [buildFragment()]
831
+ });
832
+ }
833
+ });
834
+ } else {
835
+ newConsolidated[tagType] = {
836
+ collectionId: value.collectionId,
837
+ data: value.data.map((d) => ({
838
+ ...d,
839
+ fragments: [buildFragment()]
840
+ }))
841
+ };
842
+ }
843
+ });
844
+ }
845
+ });
846
+ Object.keys(newConsolidated).forEach((tagType) => {
847
+ newConsolidated[tagType].data = newConsolidated[tagType].data.filter(
848
+ (d) => d.fragments?.length > 0
849
+ );
850
+ });
851
+ return newConsolidated;
852
+ };
768
853
  // Annotate the CommonJS export names for ESM import in node:
769
854
  0 && (module.exports = {
770
855
  BASE_BULLMQ_CONFIG,
@@ -774,6 +859,7 @@ ${v?.markdownText || ""}` : v?.markdownText || "";
774
859
  getPlatformContextContent,
775
860
  getRollupPossibilities,
776
861
  getVal,
862
+ mergeAnnoDataIntoAnnotationsTags,
777
863
  recursivelyExtractBlocks,
778
864
  segrigateDocs,
779
865
  setVal,
@@ -729,6 +729,90 @@ ${v?.markdownText || ""}` : v?.markdownText || "";
729
729
  }
730
730
  return "";
731
731
  };
732
+
733
+ // src/utils/mergeAnnoDataIntoAnnotationsTags.ts
734
+ import { cloneDeep } from "lodash";
735
+ var mergeAnnoDataIntoAnnotationsTags = ({
736
+ prevObj,
737
+ newLexValue,
738
+ thisBlockValuePath,
739
+ author = { id: null, name: "AI" }
740
+ }) => {
741
+ let newConsolidated = cloneDeep(prevObj) || {};
742
+ const { annoData = {} } = newLexValue || {};
743
+ const existingKeys = /* @__PURE__ */ new Map();
744
+ Object.keys(newConsolidated).map((tagType) => {
745
+ if (newConsolidated[tagType].data?.length > 0) {
746
+ newConsolidated[tagType].data.forEach((tag, tagIdx) => {
747
+ if (tag.fragments?.length > 0) {
748
+ newConsolidated[tagType].data[tagIdx].fragments = newConsolidated[tagType].data[tagIdx].fragments.filter((frag) => {
749
+ existingKeys.set(frag.annoDataId, frag?.author ?? "");
750
+ if (frag.extractedFromValuePath !== thisBlockValuePath) {
751
+ return true;
752
+ } else {
753
+ return false;
754
+ }
755
+ });
756
+ }
757
+ });
758
+ }
759
+ });
760
+ Object.keys(annoData).map((annoDataId) => {
761
+ const { tags, fragment = {}, ...restAnnoData } = annoData[annoDataId];
762
+ const tagTypes = Object.keys(tags || {});
763
+ const buildFragment = () => ({
764
+ ...fragment,
765
+ ...restAnnoData,
766
+ annoDataId,
767
+ // Fallback to provided author if author not set (for backwards compatibility)
768
+ author: restAnnoData.author || existingKeys.get(annoDataId) || author,
769
+ extractedFromValuePath: thisBlockValuePath
770
+ });
771
+ if (tagTypes.length > 0) {
772
+ tagTypes.forEach((tagType) => {
773
+ const value = tags[tagType];
774
+ if (newConsolidated[tagType]?.data?.length > 0) {
775
+ value.data.forEach((d) => {
776
+ const foundTagIdx = newConsolidated[tagType].data.findIndex(
777
+ (dd) => dd._id === d._id
778
+ );
779
+ if (foundTagIdx !== -1) {
780
+ const fragsAry = newConsolidated[tagType].data[foundTagIdx].fragments || [];
781
+ if (fragsAry.length === 0) {
782
+ newConsolidated[tagType].data[foundTagIdx].fragments = [
783
+ buildFragment()
784
+ ];
785
+ } else {
786
+ newConsolidated[tagType].data[foundTagIdx].fragments.push(
787
+ buildFragment()
788
+ );
789
+ }
790
+ } else {
791
+ newConsolidated[tagType].data.push({
792
+ ...d,
793
+ fragments: [buildFragment()]
794
+ });
795
+ }
796
+ });
797
+ } else {
798
+ newConsolidated[tagType] = {
799
+ collectionId: value.collectionId,
800
+ data: value.data.map((d) => ({
801
+ ...d,
802
+ fragments: [buildFragment()]
803
+ }))
804
+ };
805
+ }
806
+ });
807
+ }
808
+ });
809
+ Object.keys(newConsolidated).forEach((tagType) => {
810
+ newConsolidated[tagType].data = newConsolidated[tagType].data.filter(
811
+ (d) => d.fragments?.length > 0
812
+ );
813
+ });
814
+ return newConsolidated;
815
+ };
732
816
  export {
733
817
  BASE_BULLMQ_CONFIG,
734
818
  deleteVal,
@@ -737,6 +821,7 @@ export {
737
821
  getPlatformContextContent,
738
822
  getRollupPossibilities,
739
823
  getVal,
824
+ mergeAnnoDataIntoAnnotationsTags,
740
825
  _recursExtractBlocks as recursivelyExtractBlocks,
741
826
  segrigateDocs,
742
827
  setVal,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.3",
6
+ "version": "1.20.0",
7
7
  "description": "Utility functions for both browser and Node.js",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.mjs",
@@ -65,6 +65,7 @@
65
65
  "@semantic-release/npm": "^13.1.3",
66
66
  "@semantic-release/release-notes-generator": "^14.0.3",
67
67
  "@types/ioredis": "^4.28.10",
68
+ "@types/lodash": "^4.17.23",
68
69
  "@types/mongoose": "^5.11.97",
69
70
  "@types/node": "^22.13.10",
70
71
  "commitizen": "^4.3.1",
@@ -77,6 +78,7 @@
77
78
  "@elastic/elasticsearch": "^8.2.1",
78
79
  "bullmq": "^5.58.2",
79
80
  "ioredis": "^5.6.1",
81
+ "lodash": "^4.17.23",
80
82
  "mongodb": "^6.13.0",
81
83
  "mongoose": "^8.15.1"
82
84
  }