@okf/ootils 1.26.1 → 1.26.3
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/browser.d.mts +54 -7
- package/dist/browser.d.ts +54 -7
- package/dist/browser.js +28 -0
- package/dist/browser.mjs +28 -0
- package/dist/node.d.mts +175 -33
- package/dist/node.d.ts +175 -33
- package/dist/node.js +277 -79
- package/dist/node.mjs +274 -77
- package/dist/universal.d.mts +54 -7
- package/dist/universal.d.ts +54 -7
- package/dist/universal.js +28 -0
- package/dist/universal.mjs +28 -0
- package/package.json +1 -1
package/dist/node.js
CHANGED
|
@@ -218,6 +218,34 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
},
|
|
221
|
+
SENTIMENT_AND_NER_QUEUE: {
|
|
222
|
+
id: "sentiment-and-ner-queue",
|
|
223
|
+
queueConfig: {
|
|
224
|
+
defaultJobOptions: {
|
|
225
|
+
attempts: 3,
|
|
226
|
+
backoff: {
|
|
227
|
+
type: "exponential",
|
|
228
|
+
delay: 2e3
|
|
229
|
+
},
|
|
230
|
+
removeOnComplete: 30,
|
|
231
|
+
removeOnFail: 100
|
|
232
|
+
},
|
|
233
|
+
streams: {
|
|
234
|
+
events: {
|
|
235
|
+
maxLen: 10
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
workerConfig: {
|
|
240
|
+
concurrency: 1,
|
|
241
|
+
lockDuration: 9e4,
|
|
242
|
+
maxStalledCount: 3,
|
|
243
|
+
limiter: {
|
|
244
|
+
max: 100,
|
|
245
|
+
duration: 6e4
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
},
|
|
221
249
|
AI_AUTO_ANNOTATE_QUEUE: {
|
|
222
250
|
id: "ai-auto-annotate-queue",
|
|
223
251
|
queueConfig: {
|
|
@@ -874,31 +902,54 @@ var require_ElasticSearchConnector = __commonJS({
|
|
|
874
902
|
"use strict";
|
|
875
903
|
var { Client } = require("@elastic/elasticsearch");
|
|
876
904
|
var ElasticSearchConnector2 = class _ElasticSearchConnector {
|
|
905
|
+
/**
|
|
906
|
+
* @param {Object} options
|
|
907
|
+
*
|
|
908
|
+
* Multi-env mode (preferred):
|
|
909
|
+
* { env: 'dev', configs: { dev: { cloudId, apiKey }, staging: { cloudId, apiKey }, prod: { cloudId, apiKey } } }
|
|
910
|
+
*
|
|
911
|
+
* Legacy single-env mode (backwards compat):
|
|
912
|
+
* { cloudId: '...', apiKey: '...' }
|
|
913
|
+
*/
|
|
877
914
|
constructor(options = {}) {
|
|
915
|
+
this.env = options.env || null;
|
|
916
|
+
this.clients = {};
|
|
878
917
|
this.client = null;
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
if (!this.apiKey) {
|
|
886
|
-
throw new Error("API Key must be provided in constructor options or ELASTIC_API_KEY environment variable");
|
|
918
|
+
if (options.configs) {
|
|
919
|
+
this._configs = options.configs;
|
|
920
|
+
} else if (options.cloudId && options.apiKey) {
|
|
921
|
+
this._legacyConfig = { cloudId: options.cloudId, apiKey: options.apiKey };
|
|
922
|
+
} else {
|
|
923
|
+
throw new Error("ElasticSearchConnector: provide either { configs } for multi-env or { cloudId, apiKey } for single-env");
|
|
887
924
|
}
|
|
925
|
+
_ElasticSearchConnector.instance = this;
|
|
888
926
|
}
|
|
889
927
|
/**
|
|
890
|
-
* Initialize Elasticsearch client
|
|
928
|
+
* Initialize Elasticsearch client(s).
|
|
929
|
+
* Multi-env: connects to all configured envs.
|
|
930
|
+
* Legacy: connects a single client.
|
|
891
931
|
*/
|
|
892
932
|
connect() {
|
|
893
|
-
this.
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
933
|
+
if (this._configs) {
|
|
934
|
+
for (const [env, conf] of Object.entries(this._configs)) {
|
|
935
|
+
if (!conf.cloudId || !conf.apiKey) {
|
|
936
|
+
console.log(`[ES] Skipping env "${env}" \u2014 missing cloudId or apiKey`);
|
|
937
|
+
continue;
|
|
938
|
+
}
|
|
939
|
+
this.clients[env] = new Client({
|
|
940
|
+
cloud: { id: conf.cloudId },
|
|
941
|
+
auth: { apiKey: conf.apiKey }
|
|
942
|
+
});
|
|
899
943
|
}
|
|
900
|
-
|
|
901
|
-
|
|
944
|
+
this.client = this.clients[this.env] || null;
|
|
945
|
+
console.log(`\u2705 Elasticsearch clients initialized for envs: ${Object.keys(this.clients).join(", ")}`);
|
|
946
|
+
} else {
|
|
947
|
+
this.client = new Client({
|
|
948
|
+
cloud: { id: this._legacyConfig.cloudId },
|
|
949
|
+
auth: { apiKey: this._legacyConfig.apiKey }
|
|
950
|
+
});
|
|
951
|
+
console.log("\u2705 Elasticsearch client initialized");
|
|
952
|
+
}
|
|
902
953
|
return this.client;
|
|
903
954
|
}
|
|
904
955
|
// Static method to get the instance
|
|
@@ -908,22 +959,43 @@ var require_ElasticSearchConnector = __commonJS({
|
|
|
908
959
|
}
|
|
909
960
|
return _ElasticSearchConnector.instance;
|
|
910
961
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
962
|
+
/**
|
|
963
|
+
* Get an Elasticsearch client.
|
|
964
|
+
* @param {string} [env] - Optional env to get a specific env's client.
|
|
965
|
+
* If omitted, returns the current env's client (backwards compat).
|
|
966
|
+
*/
|
|
967
|
+
static getClient(env) {
|
|
968
|
+
const inst = _ElasticSearchConnector.instance;
|
|
969
|
+
if (!inst) {
|
|
970
|
+
throw new Error("ElasticSearchConnector not initialized");
|
|
915
971
|
}
|
|
916
|
-
|
|
972
|
+
if (env && inst.clients[env]) {
|
|
973
|
+
return inst.clients[env];
|
|
974
|
+
}
|
|
975
|
+
if (inst.client) {
|
|
976
|
+
return inst.client;
|
|
977
|
+
}
|
|
978
|
+
throw new Error("ElasticSearchConnector not initialized or client not connected");
|
|
979
|
+
}
|
|
980
|
+
static getEnv() {
|
|
981
|
+
return _ElasticSearchConnector.instance?.env;
|
|
917
982
|
}
|
|
918
983
|
/**
|
|
919
|
-
* Close
|
|
984
|
+
* Close all Elasticsearch clients.
|
|
920
985
|
*/
|
|
921
986
|
async close() {
|
|
922
|
-
|
|
987
|
+
for (const [env, client] of Object.entries(this.clients)) {
|
|
988
|
+
try {
|
|
989
|
+
await client.close();
|
|
990
|
+
} catch (_) {
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
if (this.client && !Object.values(this.clients).includes(this.client)) {
|
|
923
994
|
await this.client.close();
|
|
924
|
-
console.log("\u2705 Elasticsearch client closed");
|
|
925
|
-
this.client = null;
|
|
926
995
|
}
|
|
996
|
+
this.clients = {};
|
|
997
|
+
this.client = null;
|
|
998
|
+
console.log("\u2705 Elasticsearch client(s) closed");
|
|
927
999
|
}
|
|
928
1000
|
};
|
|
929
1001
|
ElasticSearchConnector2.instance = null;
|
|
@@ -1066,11 +1138,55 @@ var init_GeneratedTopics = __esm({
|
|
|
1066
1138
|
}
|
|
1067
1139
|
});
|
|
1068
1140
|
|
|
1141
|
+
// src/models/GeneratedEntities.ts
|
|
1142
|
+
var import_mongoose6, GeneratedEntitiesSchema, GeneratedEntities_default;
|
|
1143
|
+
var init_GeneratedEntities = __esm({
|
|
1144
|
+
"src/models/GeneratedEntities.ts"() {
|
|
1145
|
+
"use strict";
|
|
1146
|
+
import_mongoose6 = require("mongoose");
|
|
1147
|
+
GeneratedEntitiesSchema = new import_mongoose6.Schema(
|
|
1148
|
+
{
|
|
1149
|
+
canonicalName: {
|
|
1150
|
+
type: String,
|
|
1151
|
+
trim: true,
|
|
1152
|
+
required: true
|
|
1153
|
+
},
|
|
1154
|
+
type: {
|
|
1155
|
+
type: String,
|
|
1156
|
+
required: true,
|
|
1157
|
+
trim: true
|
|
1158
|
+
},
|
|
1159
|
+
embeddings: {
|
|
1160
|
+
type: [Number],
|
|
1161
|
+
required: true
|
|
1162
|
+
},
|
|
1163
|
+
aliases: {
|
|
1164
|
+
type: [String],
|
|
1165
|
+
default: []
|
|
1166
|
+
}
|
|
1167
|
+
},
|
|
1168
|
+
{ timestamps: true, collection: "SYSTEM_generatedEntities" }
|
|
1169
|
+
);
|
|
1170
|
+
GeneratedEntitiesSchema.index(
|
|
1171
|
+
{
|
|
1172
|
+
canonicalName: 1,
|
|
1173
|
+
type: 1
|
|
1174
|
+
},
|
|
1175
|
+
{
|
|
1176
|
+
unique: true,
|
|
1177
|
+
name: "unique_entity_per_type"
|
|
1178
|
+
}
|
|
1179
|
+
);
|
|
1180
|
+
GeneratedEntities_default = GeneratedEntitiesSchema;
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
|
|
1069
1184
|
// src/models/index.ts
|
|
1070
1185
|
var models_exports = {};
|
|
1071
1186
|
__export(models_exports, {
|
|
1072
1187
|
AIChatSchema: () => AIChat_default,
|
|
1073
1188
|
AnnotationSchema: () => Annotations_default,
|
|
1189
|
+
GeneratedEntitiesSchema: () => GeneratedEntities_default,
|
|
1074
1190
|
GeneratedTopicsSchema: () => GeneratedTopics_default,
|
|
1075
1191
|
PlatformConfigsSchema: () => PlatformConfigs_default,
|
|
1076
1192
|
TplSchema: () => Tpl_default
|
|
@@ -1083,6 +1199,7 @@ var init_models = __esm({
|
|
|
1083
1199
|
init_PlatformConfigs();
|
|
1084
1200
|
init_Tpl();
|
|
1085
1201
|
init_GeneratedTopics();
|
|
1202
|
+
init_GeneratedEntities();
|
|
1086
1203
|
}
|
|
1087
1204
|
});
|
|
1088
1205
|
|
|
@@ -1091,11 +1208,11 @@ var getDbByTenant_exports = {};
|
|
|
1091
1208
|
__export(getDbByTenant_exports, {
|
|
1092
1209
|
getDbByTenant: () => getDbByTenant
|
|
1093
1210
|
});
|
|
1094
|
-
var
|
|
1211
|
+
var import_mongoose7, import_MongoConnector, getDbByTenant;
|
|
1095
1212
|
var init_getDbByTenant = __esm({
|
|
1096
1213
|
"src/db/getDbByTenant.js"() {
|
|
1097
1214
|
"use strict";
|
|
1098
|
-
|
|
1215
|
+
import_mongoose7 = require("mongoose");
|
|
1099
1216
|
import_MongoConnector = __toESM(require_MongoConnector());
|
|
1100
1217
|
getDbByTenant = ({
|
|
1101
1218
|
tenant,
|
|
@@ -1123,7 +1240,7 @@ var require_getModelByTenant = __commonJS({
|
|
|
1123
1240
|
"src/db/getModelByTenant.js"(exports2, module2) {
|
|
1124
1241
|
"use strict";
|
|
1125
1242
|
var { getDbByTenant: getDbByTenant2 } = (init_getDbByTenant(), __toCommonJS(getDbByTenant_exports));
|
|
1126
|
-
var { AIChatSchema: AIChatSchema2, AnnotationSchema: AnnotationSchema2, PlatformConfigsSchema: PlatformConfigsSchema2, TplSchema: TplSchema2, GeneratedTopicsSchema: GeneratedTopicsSchema2 } = (init_models(), __toCommonJS(models_exports));
|
|
1243
|
+
var { AIChatSchema: AIChatSchema2, AnnotationSchema: AnnotationSchema2, PlatformConfigsSchema: PlatformConfigsSchema2, TplSchema: TplSchema2, GeneratedTopicsSchema: GeneratedTopicsSchema2, GeneratedEntitiesSchema: GeneratedEntitiesSchema2 } = (init_models(), __toCommonJS(models_exports));
|
|
1127
1244
|
var getModelByTenant3 = ({ tenant, modelName, schema, env }) => {
|
|
1128
1245
|
if (!tenant) {
|
|
1129
1246
|
throw new Error("tenant id has not been provided");
|
|
@@ -1164,13 +1281,20 @@ var require_getModelByTenant = __commonJS({
|
|
|
1164
1281
|
schema: GeneratedTopicsSchema2,
|
|
1165
1282
|
env
|
|
1166
1283
|
});
|
|
1284
|
+
var getGeneratedEntitiesModelByTenant2 = ({ tenant, env }) => getModelByTenant3({
|
|
1285
|
+
tenant,
|
|
1286
|
+
modelName: "generatedEntities",
|
|
1287
|
+
schema: GeneratedEntitiesSchema2,
|
|
1288
|
+
env
|
|
1289
|
+
});
|
|
1167
1290
|
module2.exports = {
|
|
1168
1291
|
getModelByTenant: getModelByTenant3,
|
|
1169
1292
|
getAIChatModelByTenant: getAIChatModelByTenant2,
|
|
1170
1293
|
getAnnotationsModelByTenant: getAnnotationsModelByTenant2,
|
|
1171
1294
|
getPlatformConfigsModelByTenant: getPlatformConfigsModelByTenant2,
|
|
1172
1295
|
getTplModelByTenant: getTplModelByTenant2,
|
|
1173
|
-
getGeneratedTopicsModelByTenant: getGeneratedTopicsModelByTenant2
|
|
1296
|
+
getGeneratedTopicsModelByTenant: getGeneratedTopicsModelByTenant2,
|
|
1297
|
+
getGeneratedEntitiesModelByTenant: getGeneratedEntitiesModelByTenant2
|
|
1174
1298
|
};
|
|
1175
1299
|
}
|
|
1176
1300
|
});
|
|
@@ -1235,6 +1359,36 @@ var init_SecretManagerConnector = __esm({
|
|
|
1235
1359
|
const configs = _SecretManagerConnector.getSecret("envSpecificConfigs");
|
|
1236
1360
|
return env ? configs[env] : configs;
|
|
1237
1361
|
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Get Redis configs for all envs, structured for RedisCacheConnector multi-env mode.
|
|
1364
|
+
* @returns {{ dev: { host, port, password }, staging: { host, port, password }, prod: { host, port, password } }}
|
|
1365
|
+
*/
|
|
1366
|
+
static getRedisConfigsForAllEnvs() {
|
|
1367
|
+
const all = _SecretManagerConnector.getEnvSpecificConfigs();
|
|
1368
|
+
const result = {};
|
|
1369
|
+
for (const env of Object.keys(all)) {
|
|
1370
|
+
const c = all[env];
|
|
1371
|
+
if (c?.REDIS_HOST) {
|
|
1372
|
+
result[env] = { host: c.REDIS_HOST, port: c.REDIS_PORT, password: c.REDIS_PASSWORD };
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
return result;
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* Get Elasticsearch configs for all envs, structured for ElasticSearchConnector multi-env mode.
|
|
1379
|
+
* @returns {{ dev: { cloudId, apiKey }, staging: { cloudId, apiKey }, prod: { cloudId, apiKey } }}
|
|
1380
|
+
*/
|
|
1381
|
+
static getElasticConfigsForAllEnvs() {
|
|
1382
|
+
const all = _SecretManagerConnector.getEnvSpecificConfigs();
|
|
1383
|
+
const result = {};
|
|
1384
|
+
for (const env of Object.keys(all)) {
|
|
1385
|
+
const c = all[env];
|
|
1386
|
+
if (c?.ELASTIC_CLOUD_ID) {
|
|
1387
|
+
result[env] = { cloudId: c.ELASTIC_CLOUD_ID, apiKey: c.ELASTIC_API_KEY };
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
return result;
|
|
1391
|
+
}
|
|
1238
1392
|
static async addSecretVersion(secretName, data) {
|
|
1239
1393
|
const instance = _SecretManagerConnector.instance;
|
|
1240
1394
|
const payload = Buffer.from(JSON.stringify(data, null, 2));
|
|
@@ -1762,6 +1916,7 @@ __export(node_exports, {
|
|
|
1762
1916
|
ElasticSearchConnector: () => import_ElasticSearchConnector.ElasticSearchConnector,
|
|
1763
1917
|
FILTER_IDS: () => FILTER_IDS,
|
|
1764
1918
|
GET_GLOBAL_BULLMQ_CONFIG: () => import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG,
|
|
1919
|
+
GeneratedEntitiesSchema: () => GeneratedEntities_default,
|
|
1765
1920
|
GeneratedTopicsSchema: () => GeneratedTopics_default,
|
|
1766
1921
|
MongoConnector: () => import_MongoConnector3.MongoConnector,
|
|
1767
1922
|
PlatformConfigsSchema: () => PlatformConfigs_default,
|
|
@@ -1787,6 +1942,7 @@ __export(node_exports, {
|
|
|
1787
1942
|
getAnnotationsModelByTenant: () => import_getModelByTenant2.getAnnotationsModelByTenant,
|
|
1788
1943
|
getDbByTenant: () => getDbByTenant,
|
|
1789
1944
|
getFilterKeyForBlock: () => getFilterKeyForBlock,
|
|
1945
|
+
getGeneratedEntitiesModelByTenant: () => import_getModelByTenant2.getGeneratedEntitiesModelByTenant,
|
|
1790
1946
|
getGeneratedTopicsModelByTenant: () => import_getModelByTenant2.getGeneratedTopicsModelByTenant,
|
|
1791
1947
|
getModelByTenant: () => import_getModelByTenant2.getModelByTenant,
|
|
1792
1948
|
getPlatformConfigsModelByTenant: () => import_getModelByTenant2.getPlatformConfigsModelByTenant,
|
|
@@ -3324,24 +3480,56 @@ var BASE_SETTINGS_FOR_CONFIGS_CACHE = [
|
|
|
3324
3480
|
}
|
|
3325
3481
|
];
|
|
3326
3482
|
var RedisCacheConnector = class _RedisCacheConnector {
|
|
3483
|
+
/**
|
|
3484
|
+
* @param {Object} options
|
|
3485
|
+
*
|
|
3486
|
+
* Multi-env mode (preferred):
|
|
3487
|
+
* { env: 'dev', configs: { dev: { host, port, password }, staging: { host, port, password }, prod: { host, port, password } } }
|
|
3488
|
+
*
|
|
3489
|
+
* Legacy single-env mode (backwards compat):
|
|
3490
|
+
* { host: '...', port: 6379, password: '...', env: 'dev' }
|
|
3491
|
+
*/
|
|
3327
3492
|
constructor(options = {}) {
|
|
3328
3493
|
/**
|
|
3329
|
-
* Initialize Redis client
|
|
3494
|
+
* Initialize Redis client(s).
|
|
3495
|
+
* Multi-env: connects to all configured envs.
|
|
3496
|
+
* Legacy: connects a single client.
|
|
3330
3497
|
*/
|
|
3331
3498
|
__publicField(this, "connect", async () => {
|
|
3332
3499
|
try {
|
|
3333
|
-
this.
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3500
|
+
if (this._configs) {
|
|
3501
|
+
for (const [env, conf] of Object.entries(this._configs)) {
|
|
3502
|
+
if (!conf.host || !conf.port || !conf.password) {
|
|
3503
|
+
console.log(`[Redis] Skipping env "${env}" \u2014 missing config`);
|
|
3504
|
+
continue;
|
|
3505
|
+
}
|
|
3506
|
+
const redisClient = new import_ioredis.default({
|
|
3507
|
+
host: conf.host,
|
|
3508
|
+
port: conf.port,
|
|
3509
|
+
password: conf.password
|
|
3510
|
+
});
|
|
3511
|
+
await new Promise((resolve, reject) => {
|
|
3512
|
+
redisClient.on("ready", resolve);
|
|
3513
|
+
redisClient.on("error", reject);
|
|
3514
|
+
});
|
|
3515
|
+
this.clients[env] = redisClient;
|
|
3516
|
+
}
|
|
3517
|
+
this.client = this.clients[this.env] || null;
|
|
3518
|
+
console.log(`\u2705 Redis clients initialized for envs: ${Object.keys(this.clients).join(", ")}`);
|
|
3519
|
+
} else {
|
|
3520
|
+
this.client = new import_ioredis.default({
|
|
3521
|
+
host: this._legacyConfig.host,
|
|
3522
|
+
port: this._legacyConfig.port,
|
|
3523
|
+
password: this._legacyConfig.password
|
|
3524
|
+
});
|
|
3525
|
+
this.client.on("connect", () => {
|
|
3526
|
+
console.log("\u2705 Connected to our redis cache instance!");
|
|
3527
|
+
});
|
|
3528
|
+
await new Promise((resolve, reject) => {
|
|
3529
|
+
this.client.on("ready", resolve);
|
|
3530
|
+
this.client.on("error", reject);
|
|
3531
|
+
});
|
|
3532
|
+
}
|
|
3345
3533
|
return this.client;
|
|
3346
3534
|
} catch (err) {
|
|
3347
3535
|
console.error(err.message);
|
|
@@ -3353,24 +3541,20 @@ var RedisCacheConnector = class _RedisCacheConnector {
|
|
|
3353
3541
|
"RedisCacheConnector instance already exists. Use RedisCacheConnector.getInstance() instead."
|
|
3354
3542
|
);
|
|
3355
3543
|
}
|
|
3356
|
-
this.client = null;
|
|
3357
|
-
this.host = options.host;
|
|
3358
3544
|
this.env = options.env;
|
|
3359
|
-
this.
|
|
3360
|
-
this.
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
throw new Error("
|
|
3367
|
-
}
|
|
3368
|
-
if (!this.password) {
|
|
3369
|
-
throw new Error("Password must be provided in constructor options");
|
|
3545
|
+
this.clients = {};
|
|
3546
|
+
this.client = null;
|
|
3547
|
+
if (options.configs) {
|
|
3548
|
+
this._configs = options.configs;
|
|
3549
|
+
} else if (options.host && options.port && options.password) {
|
|
3550
|
+
this._legacyConfig = { host: options.host, port: options.port, password: options.password };
|
|
3551
|
+
} else {
|
|
3552
|
+
throw new Error("RedisCacheConnector: provide either { configs } for multi-env or { host, port, password } for single-env");
|
|
3370
3553
|
}
|
|
3371
3554
|
if (!this.env) {
|
|
3372
3555
|
throw new Error("Env must be provided in constructor options");
|
|
3373
3556
|
}
|
|
3557
|
+
_RedisCacheConnector.instance = this;
|
|
3374
3558
|
}
|
|
3375
3559
|
static getEnv() {
|
|
3376
3560
|
if (!_RedisCacheConnector.instance) {
|
|
@@ -3385,14 +3569,23 @@ var RedisCacheConnector = class _RedisCacheConnector {
|
|
|
3385
3569
|
}
|
|
3386
3570
|
return _RedisCacheConnector.instance;
|
|
3387
3571
|
}
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3572
|
+
/**
|
|
3573
|
+
* Get a Redis client.
|
|
3574
|
+
* @param {string} [env] - Optional env to get a specific env's client.
|
|
3575
|
+
* If omitted, returns the current env's client (backwards compat).
|
|
3576
|
+
*/
|
|
3577
|
+
static getClient(env) {
|
|
3578
|
+
const inst = _RedisCacheConnector.instance;
|
|
3579
|
+
if (!inst) {
|
|
3580
|
+
throw new Error("RedisCacheConnector not initialized or client not connected");
|
|
3581
|
+
}
|
|
3582
|
+
if (env && inst.clients[env]) {
|
|
3583
|
+
return inst.clients[env];
|
|
3394
3584
|
}
|
|
3395
|
-
|
|
3585
|
+
if (inst.client) {
|
|
3586
|
+
return inst.client;
|
|
3587
|
+
}
|
|
3588
|
+
throw new Error("RedisCacheConnector not initialized or client not connected");
|
|
3396
3589
|
}
|
|
3397
3590
|
/**
|
|
3398
3591
|
* Find documents in Redis cache
|
|
@@ -3406,8 +3599,8 @@ var RedisCacheConnector = class _RedisCacheConnector {
|
|
|
3406
3599
|
*/
|
|
3407
3600
|
static async findConfigsInCache({ tenant, modelName, type, env }) {
|
|
3408
3601
|
try {
|
|
3409
|
-
const client = this.getClient();
|
|
3410
3602
|
const environment = env || this.getEnv();
|
|
3603
|
+
const client = this.getClient(environment);
|
|
3411
3604
|
const keyPrefix = `${environment}:${tenant}:${modelName}:`;
|
|
3412
3605
|
const keys = await client.keys(`${keyPrefix}${type || "*"}`);
|
|
3413
3606
|
if (keys.length === 0) {
|
|
@@ -3472,12 +3665,6 @@ var RedisCacheConnector = class _RedisCacheConnector {
|
|
|
3472
3665
|
/**
|
|
3473
3666
|
* Generate Redis key for config caching
|
|
3474
3667
|
* @private
|
|
3475
|
-
* @param {Object} params - Parameters for key generation
|
|
3476
|
-
* @param {string} params.tenant - The tenant identifier
|
|
3477
|
-
* @param {'platformConfigs'|'tpl'} params.modelName - The model/collection name
|
|
3478
|
-
* @param {string} params.type - The document type
|
|
3479
|
-
* @param {string} [params.env] - Environment (defaults to current env)
|
|
3480
|
-
* @returns {string} The Redis key
|
|
3481
3668
|
*/
|
|
3482
3669
|
static _getRedisKeyForConfig({ tenant, modelName, type, env }) {
|
|
3483
3670
|
const environment = env || this.getEnv();
|
|
@@ -3495,12 +3682,13 @@ var RedisCacheConnector = class _RedisCacheConnector {
|
|
|
3495
3682
|
* @see {platformConfigTypes} for valid platformConfigs type values
|
|
3496
3683
|
*/
|
|
3497
3684
|
static async setOneConfigInCache({ tenant, modelName, type, val, env }) {
|
|
3498
|
-
const
|
|
3685
|
+
const environment = env || this.getEnv();
|
|
3686
|
+
const client = this.getClient(environment);
|
|
3499
3687
|
const cacheKey = this._getRedisKeyForConfig({
|
|
3500
3688
|
tenant,
|
|
3501
3689
|
modelName,
|
|
3502
3690
|
type,
|
|
3503
|
-
env
|
|
3691
|
+
env: environment
|
|
3504
3692
|
});
|
|
3505
3693
|
await client.set(cacheKey, JSON.stringify(val));
|
|
3506
3694
|
}
|
|
@@ -3526,12 +3714,13 @@ var RedisCacheConnector = class _RedisCacheConnector {
|
|
|
3526
3714
|
newVal,
|
|
3527
3715
|
env
|
|
3528
3716
|
}) {
|
|
3529
|
-
const
|
|
3717
|
+
const environment = env || this.getEnv();
|
|
3718
|
+
const client = this.getClient(environment);
|
|
3530
3719
|
const cacheKey = this._getRedisKeyForConfig({
|
|
3531
3720
|
tenant,
|
|
3532
3721
|
modelName,
|
|
3533
3722
|
type,
|
|
3534
|
-
env
|
|
3723
|
+
env: environment
|
|
3535
3724
|
});
|
|
3536
3725
|
const delResult = await client.del(cacheKey);
|
|
3537
3726
|
let setResult;
|
|
@@ -3556,8 +3745,8 @@ var RedisCacheConnector = class _RedisCacheConnector {
|
|
|
3556
3745
|
*/
|
|
3557
3746
|
static async loadTplsAndPlatformConfigsToCache({ tenant }) {
|
|
3558
3747
|
try {
|
|
3559
|
-
const client = this.getClient();
|
|
3560
3748
|
const environment = this.getEnv();
|
|
3749
|
+
const client = this.getClient(environment);
|
|
3561
3750
|
if (!tenant) throw new Error("No tenant/s defined to recache");
|
|
3562
3751
|
console.log(`Loading configs and templates into cache...`);
|
|
3563
3752
|
const tenantToClusterMapping = import_MongoConnector2.MongoConnector.getTenantToClusterMapping();
|
|
@@ -3607,14 +3796,21 @@ var RedisCacheConnector = class _RedisCacheConnector {
|
|
|
3607
3796
|
}
|
|
3608
3797
|
}
|
|
3609
3798
|
/**
|
|
3610
|
-
* Close
|
|
3799
|
+
* Close all Redis clients.
|
|
3611
3800
|
*/
|
|
3612
3801
|
async close() {
|
|
3613
|
-
|
|
3802
|
+
for (const [env, client] of Object.entries(this.clients)) {
|
|
3803
|
+
try {
|
|
3804
|
+
await client.quit();
|
|
3805
|
+
} catch (_) {
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
if (this.client && !Object.values(this.clients).includes(this.client)) {
|
|
3614
3809
|
await this.client.quit();
|
|
3615
|
-
console.log("\u2705 Redis client closed");
|
|
3616
|
-
this.client = null;
|
|
3617
3810
|
}
|
|
3811
|
+
this.clients = {};
|
|
3812
|
+
this.client = null;
|
|
3813
|
+
console.log("\u2705 Redis client closed");
|
|
3618
3814
|
}
|
|
3619
3815
|
};
|
|
3620
3816
|
RedisCacheConnector.instance = null;
|
|
@@ -3643,6 +3839,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
|
|
|
3643
3839
|
ElasticSearchConnector,
|
|
3644
3840
|
FILTER_IDS,
|
|
3645
3841
|
GET_GLOBAL_BULLMQ_CONFIG,
|
|
3842
|
+
GeneratedEntitiesSchema,
|
|
3646
3843
|
GeneratedTopicsSchema,
|
|
3647
3844
|
MongoConnector,
|
|
3648
3845
|
PlatformConfigsSchema,
|
|
@@ -3668,6 +3865,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
|
|
|
3668
3865
|
getAnnotationsModelByTenant,
|
|
3669
3866
|
getDbByTenant,
|
|
3670
3867
|
getFilterKeyForBlock,
|
|
3868
|
+
getGeneratedEntitiesModelByTenant,
|
|
3671
3869
|
getGeneratedTopicsModelByTenant,
|
|
3672
3870
|
getModelByTenant,
|
|
3673
3871
|
getPlatformConfigsModelByTenant,
|