@okf/ootils 1.5.4 → 1.5.5

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.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Client } from '@elastic/elasticsearch';
1
2
  import mongoose, { Connection, Document, Types } from 'mongoose';
2
3
  import IORedis from 'ioredis';
3
4
  import * as bullmq from 'bullmq';
@@ -187,6 +188,26 @@ declare namespace MongoConnector {
187
188
  let instance: any;
188
189
  }
189
190
 
191
+ declare class ElasticSearchConnector {
192
+ static getInstance(): any;
193
+ static getClient(): any;
194
+ constructor(options?: {});
195
+ client: Client | null;
196
+ cloudId: any;
197
+ apiKey: any;
198
+ /**
199
+ * Initialize Elasticsearch client
200
+ */
201
+ connect(): Client;
202
+ /**
203
+ * Close the Elasticsearch client
204
+ */
205
+ close(): Promise<void>;
206
+ }
207
+ declare namespace ElasticSearchConnector {
208
+ let instance: any;
209
+ }
210
+
190
211
  /**
191
212
  * Get database connection by tenant
192
213
  * @param tenant - Tenant identifier for the database
@@ -572,4 +593,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
572
593
  };
573
594
  }): Object;
574
595
 
575
- export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
596
+ export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
package/dist/node.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Client } from '@elastic/elasticsearch';
1
2
  import mongoose, { Connection, Document, Types } from 'mongoose';
2
3
  import IORedis from 'ioredis';
3
4
  import * as bullmq from 'bullmq';
@@ -187,6 +188,26 @@ declare namespace MongoConnector {
187
188
  let instance: any;
188
189
  }
189
190
 
191
+ declare class ElasticSearchConnector {
192
+ static getInstance(): any;
193
+ static getClient(): any;
194
+ constructor(options?: {});
195
+ client: Client | null;
196
+ cloudId: any;
197
+ apiKey: any;
198
+ /**
199
+ * Initialize Elasticsearch client
200
+ */
201
+ connect(): Client;
202
+ /**
203
+ * Close the Elasticsearch client
204
+ */
205
+ close(): Promise<void>;
206
+ }
207
+ declare namespace ElasticSearchConnector {
208
+ let instance: any;
209
+ }
210
+
190
211
  /**
191
212
  * Get database connection by tenant
192
213
  * @param tenant - Tenant identifier for the database
@@ -572,4 +593,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
572
593
  };
573
594
  }): Object;
574
595
 
575
- export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
596
+ export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
package/dist/node.js CHANGED
@@ -518,6 +518,71 @@ var require_MongoConnector = __commonJS({
518
518
  }
519
519
  });
520
520
 
521
+ // src/ElasticSearchConnector.js
522
+ var require_ElasticSearchConnector = __commonJS({
523
+ "src/ElasticSearchConnector.js"(exports2, module2) {
524
+ "use strict";
525
+ var { Client } = require("@elastic/elasticsearch");
526
+ var ElasticSearchConnector2 = class _ElasticSearchConnector {
527
+ constructor(options = {}) {
528
+ this.client = null;
529
+ this.cloudId = options.cloudId;
530
+ this.apiKey = options.apiKey;
531
+ _ElasticSearchConnector.instance = this;
532
+ if (!this.cloudId) {
533
+ throw new Error("Cloud ID must be provided in constructor options or ELASTIC_CLOUD_ID environment variable");
534
+ }
535
+ if (!this.apiKey) {
536
+ throw new Error("API Key must be provided in constructor options or ELASTIC_API_KEY environment variable");
537
+ }
538
+ }
539
+ /**
540
+ * Initialize Elasticsearch client
541
+ */
542
+ connect() {
543
+ this.client = new Client({
544
+ cloud: {
545
+ id: this.cloudId
546
+ },
547
+ auth: {
548
+ apiKey: this.apiKey
549
+ }
550
+ });
551
+ console.log("\u2705 Elasticsearch client initialized");
552
+ return this.client;
553
+ }
554
+ // Static method to get the instance
555
+ static getInstance() {
556
+ if (!_ElasticSearchConnector.instance) {
557
+ throw new Error("ElasticSearchConnector not initialized");
558
+ }
559
+ return _ElasticSearchConnector.instance;
560
+ }
561
+ // Static method to get the client
562
+ static getClient() {
563
+ if (!_ElasticSearchConnector.instance || !_ElasticSearchConnector.instance.client) {
564
+ throw new Error("ElasticSearchConnector not initialized or client not connected");
565
+ }
566
+ return _ElasticSearchConnector.instance.client;
567
+ }
568
+ /**
569
+ * Close the Elasticsearch client
570
+ */
571
+ async close() {
572
+ if (this.client) {
573
+ await this.client.close();
574
+ console.log("\u2705 Elasticsearch client closed");
575
+ this.client = null;
576
+ }
577
+ }
578
+ };
579
+ ElasticSearchConnector2.instance = null;
580
+ module2.exports = {
581
+ ElasticSearchConnector: ElasticSearchConnector2
582
+ };
583
+ }
584
+ });
585
+
521
586
  // src/db/getDbByTenant.js
522
587
  var getDbByTenant_exports = {};
523
588
  __export(getDbByTenant_exports, {
@@ -962,7 +1027,6 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
962
1027
  },
963
1028
  workerConfig: {
964
1029
  concurrency: 1,
965
- // Process 10 jobs at once for chunk processing
966
1030
  limiter: {
967
1031
  max: 5,
968
1032
  // Max 50 jobs per...
@@ -1008,7 +1072,36 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
1008
1072
  }
1009
1073
  },
1010
1074
  workerConfig: {
1011
- concurrency: 1
1075
+ concurrency: 1,
1076
+ limiter: {
1077
+ max: 5,
1078
+ // Max 5 jobs per...
1079
+ duration: 6e4
1080
+ // ...60 seconds (higher throughput for chunking)
1081
+ }
1082
+ }
1083
+ },
1084
+ ANNOS_ELASTIC_SYNC_QUEUE: {
1085
+ id: "annos-elastic-sync-queue",
1086
+ queueConfig: {
1087
+ defaultJobOptions: {
1088
+ attempts: 3,
1089
+ backoff: {
1090
+ type: "exponential",
1091
+ delay: 2e3
1092
+ },
1093
+ removeOnComplete: 50,
1094
+ removeOnFail: 100
1095
+ }
1096
+ },
1097
+ workerConfig: {
1098
+ concurrency: 5,
1099
+ limiter: {
1100
+ max: 5,
1101
+ // Max 5 jobs per...
1102
+ duration: 6e4
1103
+ // ...60 seconds (higher throughput for chunking)
1104
+ }
1012
1105
  }
1013
1106
  }
1014
1107
  };
@@ -1056,6 +1149,7 @@ __export(node_exports, {
1056
1149
  AnnotationSchema: () => Annotations_default,
1057
1150
  BaseProducer: () => import_BaseProducer.BaseProducer,
1058
1151
  BaseWorker: () => import_BaseWorker.BaseWorker,
1152
+ ElasticSearchConnector: () => import_ElasticSearchConnector.ElasticSearchConnector,
1059
1153
  GET_GLOBAL_BULLMQ_CONFIG: () => import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG,
1060
1154
  MongoConnector: () => import_MongoConnector2.MongoConnector,
1061
1155
  PlatformConfigsSchema: () => PlatformConfigs_default,
@@ -1360,6 +1454,7 @@ var _extractBlocksFromSomeBuilders = ({
1360
1454
 
1361
1455
  // src/node.ts
1362
1456
  var import_MongoConnector2 = __toESM(require_MongoConnector());
1457
+ var import_ElasticSearchConnector = __toESM(require_ElasticSearchConnector());
1363
1458
  init_getDbByTenant();
1364
1459
 
1365
1460
  // src/db/getGlobalConfig.ts
@@ -1508,6 +1603,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
1508
1603
  AnnotationSchema,
1509
1604
  BaseProducer,
1510
1605
  BaseWorker,
1606
+ ElasticSearchConnector,
1511
1607
  GET_GLOBAL_BULLMQ_CONFIG,
1512
1608
  MongoConnector,
1513
1609
  PlatformConfigsSchema,
package/dist/node.mjs CHANGED
@@ -523,6 +523,71 @@ var require_MongoConnector = __commonJS({
523
523
  }
524
524
  });
525
525
 
526
+ // src/ElasticSearchConnector.js
527
+ var require_ElasticSearchConnector = __commonJS({
528
+ "src/ElasticSearchConnector.js"(exports, module) {
529
+ "use strict";
530
+ var { Client } = __require("@elastic/elasticsearch");
531
+ var ElasticSearchConnector2 = class _ElasticSearchConnector {
532
+ constructor(options = {}) {
533
+ this.client = null;
534
+ this.cloudId = options.cloudId;
535
+ this.apiKey = options.apiKey;
536
+ _ElasticSearchConnector.instance = this;
537
+ if (!this.cloudId) {
538
+ throw new Error("Cloud ID must be provided in constructor options or ELASTIC_CLOUD_ID environment variable");
539
+ }
540
+ if (!this.apiKey) {
541
+ throw new Error("API Key must be provided in constructor options or ELASTIC_API_KEY environment variable");
542
+ }
543
+ }
544
+ /**
545
+ * Initialize Elasticsearch client
546
+ */
547
+ connect() {
548
+ this.client = new Client({
549
+ cloud: {
550
+ id: this.cloudId
551
+ },
552
+ auth: {
553
+ apiKey: this.apiKey
554
+ }
555
+ });
556
+ console.log("\u2705 Elasticsearch client initialized");
557
+ return this.client;
558
+ }
559
+ // Static method to get the instance
560
+ static getInstance() {
561
+ if (!_ElasticSearchConnector.instance) {
562
+ throw new Error("ElasticSearchConnector not initialized");
563
+ }
564
+ return _ElasticSearchConnector.instance;
565
+ }
566
+ // Static method to get the client
567
+ static getClient() {
568
+ if (!_ElasticSearchConnector.instance || !_ElasticSearchConnector.instance.client) {
569
+ throw new Error("ElasticSearchConnector not initialized or client not connected");
570
+ }
571
+ return _ElasticSearchConnector.instance.client;
572
+ }
573
+ /**
574
+ * Close the Elasticsearch client
575
+ */
576
+ async close() {
577
+ if (this.client) {
578
+ await this.client.close();
579
+ console.log("\u2705 Elasticsearch client closed");
580
+ this.client = null;
581
+ }
582
+ }
583
+ };
584
+ ElasticSearchConnector2.instance = null;
585
+ module.exports = {
586
+ ElasticSearchConnector: ElasticSearchConnector2
587
+ };
588
+ }
589
+ });
590
+
526
591
  // src/db/getDbByTenant.js
527
592
  var getDbByTenant_exports = {};
528
593
  __export(getDbByTenant_exports, {
@@ -967,7 +1032,6 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
967
1032
  },
968
1033
  workerConfig: {
969
1034
  concurrency: 1,
970
- // Process 10 jobs at once for chunk processing
971
1035
  limiter: {
972
1036
  max: 5,
973
1037
  // Max 50 jobs per...
@@ -1013,7 +1077,36 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
1013
1077
  }
1014
1078
  },
1015
1079
  workerConfig: {
1016
- concurrency: 1
1080
+ concurrency: 1,
1081
+ limiter: {
1082
+ max: 5,
1083
+ // Max 5 jobs per...
1084
+ duration: 6e4
1085
+ // ...60 seconds (higher throughput for chunking)
1086
+ }
1087
+ }
1088
+ },
1089
+ ANNOS_ELASTIC_SYNC_QUEUE: {
1090
+ id: "annos-elastic-sync-queue",
1091
+ queueConfig: {
1092
+ defaultJobOptions: {
1093
+ attempts: 3,
1094
+ backoff: {
1095
+ type: "exponential",
1096
+ delay: 2e3
1097
+ },
1098
+ removeOnComplete: 50,
1099
+ removeOnFail: 100
1100
+ }
1101
+ },
1102
+ workerConfig: {
1103
+ concurrency: 5,
1104
+ limiter: {
1105
+ max: 5,
1106
+ // Max 5 jobs per...
1107
+ duration: 6e4
1108
+ // ...60 seconds (higher throughput for chunking)
1109
+ }
1017
1110
  }
1018
1111
  }
1019
1112
  };
@@ -1331,6 +1424,7 @@ var _extractBlocksFromSomeBuilders = ({
1331
1424
 
1332
1425
  // src/node.ts
1333
1426
  var import_MongoConnector2 = __toESM(require_MongoConnector());
1427
+ var import_ElasticSearchConnector = __toESM(require_ElasticSearchConnector());
1334
1428
  init_getDbByTenant();
1335
1429
 
1336
1430
  // src/db/getGlobalConfig.ts
@@ -1475,6 +1569,7 @@ var import_BaseWorker = __toESM(require_BaseWorker());
1475
1569
  var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG());
1476
1570
  var export_BaseProducer = import_BaseProducer.BaseProducer;
1477
1571
  var export_BaseWorker = import_BaseWorker.BaseWorker;
1572
+ var export_ElasticSearchConnector = import_ElasticSearchConnector.ElasticSearchConnector;
1478
1573
  var export_GET_GLOBAL_BULLMQ_CONFIG = import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG;
1479
1574
  var export_MongoConnector = import_MongoConnector2.MongoConnector;
1480
1575
  var export_WorkerManager = import_WorkerManager.WorkerManager;
@@ -1488,6 +1583,7 @@ export {
1488
1583
  Annotations_default as AnnotationSchema,
1489
1584
  export_BaseProducer as BaseProducer,
1490
1585
  export_BaseWorker as BaseWorker,
1586
+ export_ElasticSearchConnector as ElasticSearchConnector,
1491
1587
  export_GET_GLOBAL_BULLMQ_CONFIG as GET_GLOBAL_BULLMQ_CONFIG,
1492
1588
  export_MongoConnector as MongoConnector,
1493
1589
  PlatformConfigs_default as PlatformConfigsSchema,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.5.4",
6
+ "version": "1.5.5",
7
7
  "description": "Utility functions for both browser and Node.js",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.mjs",
@@ -74,6 +74,7 @@
74
74
  "typescript": "^5.8.2"
75
75
  },
76
76
  "dependencies": {
77
+ "@elastic/elasticsearch": "^8.2.1",
77
78
  "bullmq": "^5.58.2",
78
79
  "ioredis": "^5.6.1",
79
80
  "mongodb": "^6.13.0",