@okf/ootils 1.3.10 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import mongoose, { Connection, Document, Schema, Model, Types } from 'mongoose';
1
+ import mongoose, { Connection, Document, Types } from 'mongoose';
2
2
  import IORedis from 'ioredis';
3
3
  import * as bullmq from 'bullmq';
4
4
  import { Queue } from 'bullmq/dist/esm/classes/queue';
@@ -157,42 +157,45 @@ declare const _recursExtractBlocks: ({ data, cb, sectionStack, blockPathPrefix }
157
157
  blockPathPrefix?: string;
158
158
  }) => void;
159
159
 
160
- interface DbConnections {
161
- [clusterName: string]: Connection;
160
+ declare class MongoConnector {
161
+ static getInstance(): any;
162
+ static getClusterConnections(): any;
163
+ static getEnv(): any;
164
+ static getDbConfigs(): any;
165
+ constructor(options: any);
166
+ clusterConnections: {};
167
+ env: any;
168
+ dbConfigs: any;
169
+ mongoOptions: any;
170
+ /**
171
+ * Creates multiple MongoDB clusterConnections based on configuration (SYNCHRONOUS)
172
+ * @returns Object containing named database clusterConnections
173
+ */
174
+ multiConnectToMongoDB(): {};
175
+ multiConnectToMongoDBAsync(): Promise<{}>;
176
+ /**
177
+ * Helper function to close clusterConnections object
178
+ */
179
+ closeConnectionsObject(clusterConnections: any): Promise<void>;
180
+ /**
181
+ * Graceful shutdown - close all MongoDB clusterConnections
182
+ */
183
+ closeAllConnections(): Promise<void>;
184
+ }
185
+ declare namespace MongoConnector {
186
+ let instance: any;
162
187
  }
163
- interface DatabaseConfig {
164
- connectTo: string[];
165
- CLUSTER_NAME: string;
166
- DB_URI: string;
167
- }
168
- interface DbConfigs {
169
- [env: string]: DatabaseConfig;
170
- }
171
- interface MultiConnectParams {
172
- env?: string;
173
- dbConfigs?: DbConfigs;
174
- }
175
- /**
176
- * Creates multiple MongoDB connections based on environment configuration
177
- * @param params - Object containing env and dbConfigs (optional, uses global config if not provided)
178
- * @param params.env - Environment string (e.g., 'development', 'production', 'staging')
179
- * @param params.dbConfigs - Database configuration object
180
- * @returns Object containing named database connections
181
- */
182
- declare const multiConnectToMongoDB: ({ env, dbConfigs }?: MultiConnectParams) => DbConnections;
183
188
 
184
189
  /**
185
- * passing env is optional.
186
- * cuz it usually defaults to 'this env' provided by .env file.
187
- *
188
- * However, in some cases where we are syncing tpls &
189
- * configs across envs, we need to be able to specify env
190
- * as well
190
+ * Get database connection by tenant
191
+ * @param tenant - Tenant identifier for the database
192
+ * @param env - Optional environment override (defaults to current environment)
193
+ * @returns Mongoose Connection instance for the tenant-specific database
191
194
  */
192
- declare const getDbByTenant: ({ tenant, env }: {
193
- tenant: string;
194
- env?: string;
195
- }) => Connection;
195
+ declare function getDbByTenant({ tenant, env: _env }: {
196
+ tenant: any;
197
+ env: any;
198
+ }): any;
196
199
 
197
200
  interface GlobalConfigType {
198
201
  env?: string;
@@ -216,58 +219,37 @@ declare const initializeGlobalConfig: (config: GlobalConfigType) => void;
216
219
  */
217
220
  declare const updateGlobalConfig: (updates: Partial<GlobalConfigType>) => void;
218
221
 
219
- interface GetModelByTenantParams {
220
- tenant: string;
221
- modelName: string;
222
- schema: Schema;
223
- env?: string;
224
- mongodb?: {
225
- [clusterName: string]: Connection;
226
- };
227
- dbConfigs?: {
228
- [env: string]: {
229
- CLUSTER_NAME: string;
230
- DB_URI: string;
231
- connectTo?: string[];
232
- };
233
- };
234
- }
235
- interface GetModelShortParams {
236
- tenant: string;
237
- env?: string;
238
- mongodb?: {
239
- [clusterName: string]: Connection;
240
- };
241
- dbConfigs?: {
242
- [env: string]: {
243
- CLUSTER_NAME: string;
244
- DB_URI: string;
245
- connectTo?: string[];
246
- };
247
- };
248
- modelName?: string;
249
- }
250
- declare const getModelByTenant: <T extends Document = Document>({ tenant, modelName, schema, env, }: GetModelByTenantParams) => Model<T>;
251
- declare const getAnnotationsModelByTenant: ({ tenant, env, mongodb, dbConfigs, modelName }: GetModelShortParams) => Model<Document<unknown, any, any, Record<string, any>>, {}, {}, {}, Document<unknown, {}, Document<unknown, any, any, Record<string, any>>, {}> & Document<unknown, any, any, Record<string, any>> & Required<{
252
- _id: unknown;
253
- }> & {
254
- __v: number;
255
- }, any>;
256
- declare const getPlatformConfigsModelByTenant: ({ tenant, env, mongodb, dbConfigs }: GetModelShortParams) => Model<Document<unknown, any, any, Record<string, any>>, {}, {}, {}, Document<unknown, {}, Document<unknown, any, any, Record<string, any>>, {}> & Document<unknown, any, any, Record<string, any>> & Required<{
257
- _id: unknown;
258
- }> & {
259
- __v: number;
260
- }, any>;
261
- declare const getTplModelByTenant: ({ tenant, env, mongodb, dbConfigs }: GetModelShortParams) => Model<Document<unknown, any, any, Record<string, any>>, {}, {}, {}, Document<unknown, {}, Document<unknown, any, any, Record<string, any>>, {}> & Document<unknown, any, any, Record<string, any>> & Required<{
262
- _id: unknown;
263
- }> & {
264
- __v: number;
265
- }, any>;
266
- declare const getAIChatModelByTenant: ({ tenant, env, mongodb, dbConfigs }: GetModelShortParams) => Model<Document<unknown, any, any, Record<string, any>>, {}, {}, {}, Document<unknown, {}, Document<unknown, any, any, Record<string, any>>, {}> & Document<unknown, any, any, Record<string, any>> & Required<{
267
- _id: unknown;
268
- }> & {
269
- __v: number;
270
- }, any>;
222
+ declare function getModelByTenant({ tenant, modelName, schema, env }: {
223
+ tenant: any;
224
+ modelName: any;
225
+ schema: any;
226
+ env: any;
227
+ }): any;
228
+ declare function getAIChatModelByTenant({ tenant, env, mongodb, dbConfigs }: {
229
+ tenant: any;
230
+ env: any;
231
+ mongodb: any;
232
+ dbConfigs: any;
233
+ }): any;
234
+ declare function getAnnotationsModelByTenant({ tenant, env, mongodb, dbConfigs, modelName }: {
235
+ tenant: any;
236
+ env: any;
237
+ mongodb: any;
238
+ dbConfigs: any;
239
+ modelName: any;
240
+ }): any;
241
+ declare function getPlatformConfigsModelByTenant({ tenant, env, mongodb, dbConfigs }: {
242
+ tenant: any;
243
+ env: any;
244
+ mongodb: any;
245
+ dbConfigs: any;
246
+ }): any;
247
+ declare function getTplModelByTenant({ tenant, env, mongodb, dbConfigs }: {
248
+ tenant: any;
249
+ env: any;
250
+ mongodb: any;
251
+ dbConfigs: any;
252
+ }): any;
271
253
 
272
254
  interface GetTplParams {
273
255
  name: string;
@@ -396,7 +378,7 @@ declare const AIChatSchema: mongoose.Schema<IAIChat, mongoose.Model<IAIChat, any
396
378
  __v: number;
397
379
  }>;
398
380
 
399
- declare const platformConfigTypes: readonly ["roles", "nav", "deployment", "userAgreement", "localeData", "theme", "AI"];
381
+ declare const platformConfigTypes: readonly ["roles", "nav", "deployment", "userAgreement", "localeData", "theme", "ai"];
400
382
  type PlatformConfigType = typeof platformConfigTypes[number];
401
383
  interface IPlatformConfig extends Document {
402
384
  type: PlatformConfigType;
@@ -589,4 +571,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
589
571
  };
590
572
  }): Object;
591
573
 
592
- export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, GET_GLOBAL_BULLMQ_CONFIG, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
574
+ 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 };
package/dist/node.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import mongoose, { Connection, Document, Schema, Model, Types } from 'mongoose';
1
+ import mongoose, { Connection, Document, Types } from 'mongoose';
2
2
  import IORedis from 'ioredis';
3
3
  import * as bullmq from 'bullmq';
4
4
  import { Queue } from 'bullmq/dist/esm/classes/queue';
@@ -157,42 +157,45 @@ declare const _recursExtractBlocks: ({ data, cb, sectionStack, blockPathPrefix }
157
157
  blockPathPrefix?: string;
158
158
  }) => void;
159
159
 
160
- interface DbConnections {
161
- [clusterName: string]: Connection;
160
+ declare class MongoConnector {
161
+ static getInstance(): any;
162
+ static getClusterConnections(): any;
163
+ static getEnv(): any;
164
+ static getDbConfigs(): any;
165
+ constructor(options: any);
166
+ clusterConnections: {};
167
+ env: any;
168
+ dbConfigs: any;
169
+ mongoOptions: any;
170
+ /**
171
+ * Creates multiple MongoDB clusterConnections based on configuration (SYNCHRONOUS)
172
+ * @returns Object containing named database clusterConnections
173
+ */
174
+ multiConnectToMongoDB(): {};
175
+ multiConnectToMongoDBAsync(): Promise<{}>;
176
+ /**
177
+ * Helper function to close clusterConnections object
178
+ */
179
+ closeConnectionsObject(clusterConnections: any): Promise<void>;
180
+ /**
181
+ * Graceful shutdown - close all MongoDB clusterConnections
182
+ */
183
+ closeAllConnections(): Promise<void>;
184
+ }
185
+ declare namespace MongoConnector {
186
+ let instance: any;
162
187
  }
163
- interface DatabaseConfig {
164
- connectTo: string[];
165
- CLUSTER_NAME: string;
166
- DB_URI: string;
167
- }
168
- interface DbConfigs {
169
- [env: string]: DatabaseConfig;
170
- }
171
- interface MultiConnectParams {
172
- env?: string;
173
- dbConfigs?: DbConfigs;
174
- }
175
- /**
176
- * Creates multiple MongoDB connections based on environment configuration
177
- * @param params - Object containing env and dbConfigs (optional, uses global config if not provided)
178
- * @param params.env - Environment string (e.g., 'development', 'production', 'staging')
179
- * @param params.dbConfigs - Database configuration object
180
- * @returns Object containing named database connections
181
- */
182
- declare const multiConnectToMongoDB: ({ env, dbConfigs }?: MultiConnectParams) => DbConnections;
183
188
 
184
189
  /**
185
- * passing env is optional.
186
- * cuz it usually defaults to 'this env' provided by .env file.
187
- *
188
- * However, in some cases where we are syncing tpls &
189
- * configs across envs, we need to be able to specify env
190
- * as well
190
+ * Get database connection by tenant
191
+ * @param tenant - Tenant identifier for the database
192
+ * @param env - Optional environment override (defaults to current environment)
193
+ * @returns Mongoose Connection instance for the tenant-specific database
191
194
  */
192
- declare const getDbByTenant: ({ tenant, env }: {
193
- tenant: string;
194
- env?: string;
195
- }) => Connection;
195
+ declare function getDbByTenant({ tenant, env: _env }: {
196
+ tenant: any;
197
+ env: any;
198
+ }): any;
196
199
 
197
200
  interface GlobalConfigType {
198
201
  env?: string;
@@ -216,58 +219,37 @@ declare const initializeGlobalConfig: (config: GlobalConfigType) => void;
216
219
  */
217
220
  declare const updateGlobalConfig: (updates: Partial<GlobalConfigType>) => void;
218
221
 
219
- interface GetModelByTenantParams {
220
- tenant: string;
221
- modelName: string;
222
- schema: Schema;
223
- env?: string;
224
- mongodb?: {
225
- [clusterName: string]: Connection;
226
- };
227
- dbConfigs?: {
228
- [env: string]: {
229
- CLUSTER_NAME: string;
230
- DB_URI: string;
231
- connectTo?: string[];
232
- };
233
- };
234
- }
235
- interface GetModelShortParams {
236
- tenant: string;
237
- env?: string;
238
- mongodb?: {
239
- [clusterName: string]: Connection;
240
- };
241
- dbConfigs?: {
242
- [env: string]: {
243
- CLUSTER_NAME: string;
244
- DB_URI: string;
245
- connectTo?: string[];
246
- };
247
- };
248
- modelName?: string;
249
- }
250
- declare const getModelByTenant: <T extends Document = Document>({ tenant, modelName, schema, env, }: GetModelByTenantParams) => Model<T>;
251
- declare const getAnnotationsModelByTenant: ({ tenant, env, mongodb, dbConfigs, modelName }: GetModelShortParams) => Model<Document<unknown, any, any, Record<string, any>>, {}, {}, {}, Document<unknown, {}, Document<unknown, any, any, Record<string, any>>, {}> & Document<unknown, any, any, Record<string, any>> & Required<{
252
- _id: unknown;
253
- }> & {
254
- __v: number;
255
- }, any>;
256
- declare const getPlatformConfigsModelByTenant: ({ tenant, env, mongodb, dbConfigs }: GetModelShortParams) => Model<Document<unknown, any, any, Record<string, any>>, {}, {}, {}, Document<unknown, {}, Document<unknown, any, any, Record<string, any>>, {}> & Document<unknown, any, any, Record<string, any>> & Required<{
257
- _id: unknown;
258
- }> & {
259
- __v: number;
260
- }, any>;
261
- declare const getTplModelByTenant: ({ tenant, env, mongodb, dbConfigs }: GetModelShortParams) => Model<Document<unknown, any, any, Record<string, any>>, {}, {}, {}, Document<unknown, {}, Document<unknown, any, any, Record<string, any>>, {}> & Document<unknown, any, any, Record<string, any>> & Required<{
262
- _id: unknown;
263
- }> & {
264
- __v: number;
265
- }, any>;
266
- declare const getAIChatModelByTenant: ({ tenant, env, mongodb, dbConfigs }: GetModelShortParams) => Model<Document<unknown, any, any, Record<string, any>>, {}, {}, {}, Document<unknown, {}, Document<unknown, any, any, Record<string, any>>, {}> & Document<unknown, any, any, Record<string, any>> & Required<{
267
- _id: unknown;
268
- }> & {
269
- __v: number;
270
- }, any>;
222
+ declare function getModelByTenant({ tenant, modelName, schema, env }: {
223
+ tenant: any;
224
+ modelName: any;
225
+ schema: any;
226
+ env: any;
227
+ }): any;
228
+ declare function getAIChatModelByTenant({ tenant, env, mongodb, dbConfigs }: {
229
+ tenant: any;
230
+ env: any;
231
+ mongodb: any;
232
+ dbConfigs: any;
233
+ }): any;
234
+ declare function getAnnotationsModelByTenant({ tenant, env, mongodb, dbConfigs, modelName }: {
235
+ tenant: any;
236
+ env: any;
237
+ mongodb: any;
238
+ dbConfigs: any;
239
+ modelName: any;
240
+ }): any;
241
+ declare function getPlatformConfigsModelByTenant({ tenant, env, mongodb, dbConfigs }: {
242
+ tenant: any;
243
+ env: any;
244
+ mongodb: any;
245
+ dbConfigs: any;
246
+ }): any;
247
+ declare function getTplModelByTenant({ tenant, env, mongodb, dbConfigs }: {
248
+ tenant: any;
249
+ env: any;
250
+ mongodb: any;
251
+ dbConfigs: any;
252
+ }): any;
271
253
 
272
254
  interface GetTplParams {
273
255
  name: string;
@@ -396,7 +378,7 @@ declare const AIChatSchema: mongoose.Schema<IAIChat, mongoose.Model<IAIChat, any
396
378
  __v: number;
397
379
  }>;
398
380
 
399
- declare const platformConfigTypes: readonly ["roles", "nav", "deployment", "userAgreement", "localeData", "theme", "AI"];
381
+ declare const platformConfigTypes: readonly ["roles", "nav", "deployment", "userAgreement", "localeData", "theme", "ai"];
400
382
  type PlatformConfigType = typeof platformConfigTypes[number];
401
383
  interface IPlatformConfig extends Document {
402
384
  type: PlatformConfigType;
@@ -589,4 +571,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
589
571
  };
590
572
  }): Object;
591
573
 
592
- export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, GET_GLOBAL_BULLMQ_CONFIG, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
574
+ 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 };