@okf/ootils 1.2.0 → 1.3.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/index.d.mts CHANGED
@@ -1,5 +1,113 @@
1
+ import { Connection, Document, Schema, Model } from 'mongoose';
2
+
1
3
  declare function add(a: number, b: number): number;
2
4
 
5
+ interface DbConnections {
6
+ [clusterName: string]: Connection;
7
+ }
8
+ interface DatabaseConfig {
9
+ connectTo: string[];
10
+ CLUSTER_NAME: string;
11
+ DB_URI: string;
12
+ }
13
+ interface DbConfigs {
14
+ [env: string]: DatabaseConfig;
15
+ }
16
+ interface MultiConnectParams {
17
+ env?: string;
18
+ dbConfigs?: DbConfigs;
19
+ }
20
+ /**
21
+ * Creates multiple MongoDB connections based on environment configuration
22
+ * @param params - Object containing env and dbConfigs (optional, uses global config if not provided)
23
+ * @param params.env - Environment string (e.g., 'development', 'production', 'staging')
24
+ * @param params.dbConfigs - Database configuration object
25
+ * @returns Object containing named database connections
26
+ */
27
+ declare const multiConnectToMongoDB: ({ env, dbConfigs }?: MultiConnectParams) => DbConnections;
28
+
29
+ /**
30
+ * passing env is optional.
31
+ * cuz it usually defaults to 'this env' provided by .env file.
32
+ *
33
+ * However, in some cases where we are syncing tpls &
34
+ * configs across envs, we need to be able to specify env
35
+ * as well
36
+ */
37
+ declare const getDbByTenant: ({ tenant, env }: {
38
+ tenant: string;
39
+ env?: string;
40
+ }) => Connection;
41
+
42
+ interface GlobalConfigType {
43
+ env?: string;
44
+ dbConfigs?: {
45
+ [env: string]: {
46
+ CLUSTER_NAME: string;
47
+ DB_URI: string;
48
+ connectTo?: string[];
49
+ };
50
+ };
51
+ mongodb?: {
52
+ [clusterName: string]: Connection;
53
+ };
54
+ }
55
+ /**
56
+ * Initialize the global configuration (replaces entire config)
57
+ */
58
+ declare const initializeGlobalConfig: (config: GlobalConfigType) => void;
59
+ /**
60
+ * Update specific parts of the global configuration (merges with existing)
61
+ */
62
+ declare const updateGlobalConfig: (updates: Partial<GlobalConfigType>) => void;
63
+
64
+ interface GetModelByTenantParams {
65
+ tenant: string;
66
+ modelName: string;
67
+ schema: Schema;
68
+ env?: string;
69
+ mongodb?: {
70
+ [clusterName: string]: Connection;
71
+ };
72
+ dbConfigs?: {
73
+ [env: string]: {
74
+ CLUSTER_NAME: string;
75
+ DB_URI: string;
76
+ connectTo?: string[];
77
+ };
78
+ };
79
+ }
80
+ interface GetModelShortParams {
81
+ tenant: string;
82
+ env?: string;
83
+ mongodb?: {
84
+ [clusterName: string]: Connection;
85
+ };
86
+ dbConfigs?: {
87
+ [env: string]: {
88
+ CLUSTER_NAME: string;
89
+ DB_URI: string;
90
+ connectTo?: string[];
91
+ };
92
+ };
93
+ }
94
+ declare const getModelByTenant: <T extends Document = Document>({ tenant, modelName, schema, env, }: GetModelByTenantParams) => Model<T>;
95
+ declare const getAnnotationsModelByTenant: ({ 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<{
96
+ _id: unknown;
97
+ }> & {
98
+ __v: number;
99
+ }, any>;
100
+ 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<{
101
+ _id: unknown;
102
+ }> & {
103
+ __v: number;
104
+ }, any>;
105
+ 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<{
106
+ _id: unknown;
107
+ }> & {
108
+ __v: number;
109
+ }, any>;
110
+
3
111
  declare const deleteVal: (data: any, valuePath: string) => any;
4
112
 
5
113
  type ValuePath = string | string[];
@@ -22,4 +130,38 @@ declare const setVal: (data: any, valuePath: string, value: DataValue) => any;
22
130
  */
23
131
  declare const getVal: (data: any, valuePath: ValuePath, options?: GetValOptions, depthIdx?: number) => any;
24
132
 
25
- export { add, deleteVal, getVal, setVal };
133
+ interface GetTplParams {
134
+ name: string;
135
+ tenant: string;
136
+ }
137
+ interface GetAIConfigsParams {
138
+ tenant: string;
139
+ }
140
+ interface Template {
141
+ kp_content_type: string;
142
+ category: Record<string, string>;
143
+ kp_templates: Record<string, any>;
144
+ listing: Record<string, any>;
145
+ general: Record<string, any>;
146
+ }
147
+ interface Config {
148
+ enable: boolean;
149
+ contentTypes?: [{
150
+ name: string;
151
+ config?: Record<string, any>;
152
+ }];
153
+ defaultConfig: Record<string, any>;
154
+ }
155
+ interface AIconfig {
156
+ contentChunking: Config;
157
+ contentEnhance: Config;
158
+ annoChunking: Config;
159
+ embedding: Config;
160
+ aiAnnotation: Config;
161
+ }
162
+ declare const getTpl: ({ name, tenant }: GetTplParams) => Promise<Template>;
163
+ declare const getAIConfigs: ({ tenant }: GetAIConfigsParams) => Promise<AIconfig>;
164
+
165
+ declare const connectToRedis: () => Promise<void>;
166
+
167
+ export { add, connectToRedis, deleteVal, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, setVal, updateGlobalConfig };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,113 @@
1
+ import { Connection, Document, Schema, Model } from 'mongoose';
2
+
1
3
  declare function add(a: number, b: number): number;
2
4
 
5
+ interface DbConnections {
6
+ [clusterName: string]: Connection;
7
+ }
8
+ interface DatabaseConfig {
9
+ connectTo: string[];
10
+ CLUSTER_NAME: string;
11
+ DB_URI: string;
12
+ }
13
+ interface DbConfigs {
14
+ [env: string]: DatabaseConfig;
15
+ }
16
+ interface MultiConnectParams {
17
+ env?: string;
18
+ dbConfigs?: DbConfigs;
19
+ }
20
+ /**
21
+ * Creates multiple MongoDB connections based on environment configuration
22
+ * @param params - Object containing env and dbConfigs (optional, uses global config if not provided)
23
+ * @param params.env - Environment string (e.g., 'development', 'production', 'staging')
24
+ * @param params.dbConfigs - Database configuration object
25
+ * @returns Object containing named database connections
26
+ */
27
+ declare const multiConnectToMongoDB: ({ env, dbConfigs }?: MultiConnectParams) => DbConnections;
28
+
29
+ /**
30
+ * passing env is optional.
31
+ * cuz it usually defaults to 'this env' provided by .env file.
32
+ *
33
+ * However, in some cases where we are syncing tpls &
34
+ * configs across envs, we need to be able to specify env
35
+ * as well
36
+ */
37
+ declare const getDbByTenant: ({ tenant, env }: {
38
+ tenant: string;
39
+ env?: string;
40
+ }) => Connection;
41
+
42
+ interface GlobalConfigType {
43
+ env?: string;
44
+ dbConfigs?: {
45
+ [env: string]: {
46
+ CLUSTER_NAME: string;
47
+ DB_URI: string;
48
+ connectTo?: string[];
49
+ };
50
+ };
51
+ mongodb?: {
52
+ [clusterName: string]: Connection;
53
+ };
54
+ }
55
+ /**
56
+ * Initialize the global configuration (replaces entire config)
57
+ */
58
+ declare const initializeGlobalConfig: (config: GlobalConfigType) => void;
59
+ /**
60
+ * Update specific parts of the global configuration (merges with existing)
61
+ */
62
+ declare const updateGlobalConfig: (updates: Partial<GlobalConfigType>) => void;
63
+
64
+ interface GetModelByTenantParams {
65
+ tenant: string;
66
+ modelName: string;
67
+ schema: Schema;
68
+ env?: string;
69
+ mongodb?: {
70
+ [clusterName: string]: Connection;
71
+ };
72
+ dbConfigs?: {
73
+ [env: string]: {
74
+ CLUSTER_NAME: string;
75
+ DB_URI: string;
76
+ connectTo?: string[];
77
+ };
78
+ };
79
+ }
80
+ interface GetModelShortParams {
81
+ tenant: string;
82
+ env?: string;
83
+ mongodb?: {
84
+ [clusterName: string]: Connection;
85
+ };
86
+ dbConfigs?: {
87
+ [env: string]: {
88
+ CLUSTER_NAME: string;
89
+ DB_URI: string;
90
+ connectTo?: string[];
91
+ };
92
+ };
93
+ }
94
+ declare const getModelByTenant: <T extends Document = Document>({ tenant, modelName, schema, env, }: GetModelByTenantParams) => Model<T>;
95
+ declare const getAnnotationsModelByTenant: ({ 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<{
96
+ _id: unknown;
97
+ }> & {
98
+ __v: number;
99
+ }, any>;
100
+ 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<{
101
+ _id: unknown;
102
+ }> & {
103
+ __v: number;
104
+ }, any>;
105
+ 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<{
106
+ _id: unknown;
107
+ }> & {
108
+ __v: number;
109
+ }, any>;
110
+
3
111
  declare const deleteVal: (data: any, valuePath: string) => any;
4
112
 
5
113
  type ValuePath = string | string[];
@@ -22,4 +130,38 @@ declare const setVal: (data: any, valuePath: string, value: DataValue) => any;
22
130
  */
23
131
  declare const getVal: (data: any, valuePath: ValuePath, options?: GetValOptions, depthIdx?: number) => any;
24
132
 
25
- export { add, deleteVal, getVal, setVal };
133
+ interface GetTplParams {
134
+ name: string;
135
+ tenant: string;
136
+ }
137
+ interface GetAIConfigsParams {
138
+ tenant: string;
139
+ }
140
+ interface Template {
141
+ kp_content_type: string;
142
+ category: Record<string, string>;
143
+ kp_templates: Record<string, any>;
144
+ listing: Record<string, any>;
145
+ general: Record<string, any>;
146
+ }
147
+ interface Config {
148
+ enable: boolean;
149
+ contentTypes?: [{
150
+ name: string;
151
+ config?: Record<string, any>;
152
+ }];
153
+ defaultConfig: Record<string, any>;
154
+ }
155
+ interface AIconfig {
156
+ contentChunking: Config;
157
+ contentEnhance: Config;
158
+ annoChunking: Config;
159
+ embedding: Config;
160
+ aiAnnotation: Config;
161
+ }
162
+ declare const getTpl: ({ name, tenant }: GetTplParams) => Promise<Template>;
163
+ declare const getAIConfigs: ({ tenant }: GetAIConfigsParams) => Promise<AIconfig>;
164
+
165
+ declare const connectToRedis: () => Promise<void>;
166
+
167
+ export { add, connectToRedis, deleteVal, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, setVal, updateGlobalConfig };