@okf/ootils 1.2.1 → 1.3.1
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 +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +117 -4
- package/dist/index.mjs +114 -4
- package/package.json +3 -1
package/dist/index.d.mts
CHANGED
|
@@ -130,4 +130,38 @@ declare const setVal: (data: any, valuePath: string, value: DataValue) => any;
|
|
|
130
130
|
*/
|
|
131
131
|
declare const getVal: (data: any, valuePath: ValuePath, options?: GetValOptions, depthIdx?: number) => any;
|
|
132
132
|
|
|
133
|
-
|
|
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
|
@@ -130,4 +130,38 @@ declare const setVal: (data: any, valuePath: string, value: DataValue) => any;
|
|
|
130
130
|
*/
|
|
131
131
|
declare const getVal: (data: any, valuePath: ValuePath, options?: GetValOptions, depthIdx?: number) => any;
|
|
132
132
|
|
|
133
|
-
|
|
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.js
CHANGED
|
@@ -41,7 +41,7 @@ var require_Annotations = __commonJS({
|
|
|
41
41
|
// Tags section - dynamic structure for various tag categories
|
|
42
42
|
tags: {
|
|
43
43
|
type: Map,
|
|
44
|
-
of: {
|
|
44
|
+
of: new Schema({
|
|
45
45
|
data: [
|
|
46
46
|
{
|
|
47
47
|
_id: { type: Schema.Types.ObjectId },
|
|
@@ -50,7 +50,7 @@ var require_Annotations = __commonJS({
|
|
|
50
50
|
}
|
|
51
51
|
],
|
|
52
52
|
collectionId: String
|
|
53
|
-
}
|
|
53
|
+
}, { _id: false })
|
|
54
54
|
},
|
|
55
55
|
// Meta information
|
|
56
56
|
meta: {
|
|
@@ -73,7 +73,7 @@ var require_Annotations = __commonJS({
|
|
|
73
73
|
annotations: {
|
|
74
74
|
tags: {
|
|
75
75
|
type: Map,
|
|
76
|
-
of: {
|
|
76
|
+
of: new Schema({
|
|
77
77
|
collectionId: String,
|
|
78
78
|
data: [
|
|
79
79
|
{
|
|
@@ -82,7 +82,7 @@ var require_Annotations = __commonJS({
|
|
|
82
82
|
tagId: String
|
|
83
83
|
}
|
|
84
84
|
]
|
|
85
|
-
}
|
|
85
|
+
}, { _id: false })
|
|
86
86
|
},
|
|
87
87
|
fragment: {
|
|
88
88
|
isLexical: Boolean,
|
|
@@ -316,11 +316,14 @@ var require_Tpl = __commonJS({
|
|
|
316
316
|
var index_exports = {};
|
|
317
317
|
__export(index_exports, {
|
|
318
318
|
add: () => add,
|
|
319
|
+
connectToRedis: () => connectToRedis,
|
|
319
320
|
deleteVal: () => deleteVal,
|
|
321
|
+
getAIConfigs: () => getAIConfigs,
|
|
320
322
|
getAnnotationsModelByTenant: () => getAnnotationsModelByTenant,
|
|
321
323
|
getDbByTenant: () => getDbByTenant,
|
|
322
324
|
getModelByTenant: () => getModelByTenant,
|
|
323
325
|
getPlatformConfigsModelByTenant: () => getPlatformConfigsModelByTenant,
|
|
326
|
+
getTpl: () => getTpl,
|
|
324
327
|
getTplModelByTenant: () => getTplModelByTenant,
|
|
325
328
|
getVal: () => getVal,
|
|
326
329
|
initializeGlobalConfig: () => initializeGlobalConfig,
|
|
@@ -601,14 +604,124 @@ var getValV2_getter = (data, valuePath, options, depthIdx) => {
|
|
|
601
604
|
}
|
|
602
605
|
return dataRef[keysArray[len - 1]];
|
|
603
606
|
};
|
|
607
|
+
|
|
608
|
+
// src/redis/index.ts
|
|
609
|
+
var import_ioredis = __toESM(require("ioredis"));
|
|
610
|
+
var redisClient = null;
|
|
611
|
+
var REDIS_CONFIG = {
|
|
612
|
+
port: Number(process.env.REDIS_PORT),
|
|
613
|
+
host: process.env.REDIS_HOST || "",
|
|
614
|
+
username: process.env.REDIS_USERNAME || "",
|
|
615
|
+
password: process.env.REDIS_PASSWORD || ""
|
|
616
|
+
};
|
|
617
|
+
var connectToRedis = async () => {
|
|
618
|
+
try {
|
|
619
|
+
redisClient = new import_ioredis.default(REDIS_CONFIG);
|
|
620
|
+
await redisClient.ping();
|
|
621
|
+
console.log("Redis connected successfully");
|
|
622
|
+
} catch (error) {
|
|
623
|
+
console.error(
|
|
624
|
+
"Redis connection failed:",
|
|
625
|
+
error instanceof Error && error.message
|
|
626
|
+
);
|
|
627
|
+
if (redisClient) {
|
|
628
|
+
redisClient.disconnect();
|
|
629
|
+
}
|
|
630
|
+
throw error;
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
var getRedisClient = () => {
|
|
634
|
+
if (!redisClient) {
|
|
635
|
+
throw new Error("Redis client not initialized. Call connectToRedis first.");
|
|
636
|
+
}
|
|
637
|
+
return redisClient;
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
// src/redis/functions.ts
|
|
641
|
+
var findInCache = async ({
|
|
642
|
+
tenant,
|
|
643
|
+
modelName,
|
|
644
|
+
type,
|
|
645
|
+
query = {}
|
|
646
|
+
}) => {
|
|
647
|
+
const key = `${process.env.ENV}:${tenant}:${modelName}:${type}`;
|
|
648
|
+
try {
|
|
649
|
+
const redisClient2 = getRedisClient();
|
|
650
|
+
const value = await redisClient2.get(key);
|
|
651
|
+
if (value) {
|
|
652
|
+
return JSON.parse(value);
|
|
653
|
+
}
|
|
654
|
+
} catch (error) {
|
|
655
|
+
console.warn(
|
|
656
|
+
`redis read failed for key ${key}`,
|
|
657
|
+
error instanceof Error && error.message
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
try {
|
|
661
|
+
const collection = getDbByTenant({
|
|
662
|
+
tenant,
|
|
663
|
+
env: process.env.ENV
|
|
664
|
+
}).collection(modelName);
|
|
665
|
+
const value = await collection.findOne(query);
|
|
666
|
+
if (!value) {
|
|
667
|
+
throw new Error(`${type} value not found in ${modelName} for ${tenant}`);
|
|
668
|
+
}
|
|
669
|
+
try {
|
|
670
|
+
const redisClient2 = getRedisClient();
|
|
671
|
+
await redisClient2.set(key, JSON.stringify(value));
|
|
672
|
+
} catch (error) {
|
|
673
|
+
console.warn(
|
|
674
|
+
`redis write failed for key ${key}:`,
|
|
675
|
+
error instanceof Error && error.message
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
return value;
|
|
679
|
+
} catch (error) {
|
|
680
|
+
throw new Error(
|
|
681
|
+
`db read failed: ${error instanceof Error && error.message}`
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
var getTpl = async ({ name, tenant }) => {
|
|
686
|
+
if (!name || !tenant) {
|
|
687
|
+
throw new Error("Missing required parameters: name or tenant");
|
|
688
|
+
}
|
|
689
|
+
return await findInCache({
|
|
690
|
+
modelName: "tpls",
|
|
691
|
+
type: name,
|
|
692
|
+
tenant,
|
|
693
|
+
query: {
|
|
694
|
+
kp_content_type: name,
|
|
695
|
+
status: { $in: ["published", "editPublished"] }
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
};
|
|
699
|
+
var getAIConfigs = async ({
|
|
700
|
+
tenant
|
|
701
|
+
}) => {
|
|
702
|
+
if (!tenant) {
|
|
703
|
+
throw new Error("Missing required parameter: tenant");
|
|
704
|
+
}
|
|
705
|
+
return await findInCache({
|
|
706
|
+
modelName: "platformConfigs",
|
|
707
|
+
type: "ai",
|
|
708
|
+
tenant,
|
|
709
|
+
query: {
|
|
710
|
+
type: "ai"
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
};
|
|
604
714
|
// Annotate the CommonJS export names for ESM import in node:
|
|
605
715
|
0 && (module.exports = {
|
|
606
716
|
add,
|
|
717
|
+
connectToRedis,
|
|
607
718
|
deleteVal,
|
|
719
|
+
getAIConfigs,
|
|
608
720
|
getAnnotationsModelByTenant,
|
|
609
721
|
getDbByTenant,
|
|
610
722
|
getModelByTenant,
|
|
611
723
|
getPlatformConfigsModelByTenant,
|
|
724
|
+
getTpl,
|
|
612
725
|
getTplModelByTenant,
|
|
613
726
|
getVal,
|
|
614
727
|
initializeGlobalConfig,
|
package/dist/index.mjs
CHANGED
|
@@ -20,7 +20,7 @@ var require_Annotations = __commonJS({
|
|
|
20
20
|
// Tags section - dynamic structure for various tag categories
|
|
21
21
|
tags: {
|
|
22
22
|
type: Map,
|
|
23
|
-
of: {
|
|
23
|
+
of: new Schema({
|
|
24
24
|
data: [
|
|
25
25
|
{
|
|
26
26
|
_id: { type: Schema.Types.ObjectId },
|
|
@@ -29,7 +29,7 @@ var require_Annotations = __commonJS({
|
|
|
29
29
|
}
|
|
30
30
|
],
|
|
31
31
|
collectionId: String
|
|
32
|
-
}
|
|
32
|
+
}, { _id: false })
|
|
33
33
|
},
|
|
34
34
|
// Meta information
|
|
35
35
|
meta: {
|
|
@@ -52,7 +52,7 @@ var require_Annotations = __commonJS({
|
|
|
52
52
|
annotations: {
|
|
53
53
|
tags: {
|
|
54
54
|
type: Map,
|
|
55
|
-
of: {
|
|
55
|
+
of: new Schema({
|
|
56
56
|
collectionId: String,
|
|
57
57
|
data: [
|
|
58
58
|
{
|
|
@@ -61,7 +61,7 @@ var require_Annotations = __commonJS({
|
|
|
61
61
|
tagId: String
|
|
62
62
|
}
|
|
63
63
|
]
|
|
64
|
-
}
|
|
64
|
+
}, { _id: false })
|
|
65
65
|
},
|
|
66
66
|
fragment: {
|
|
67
67
|
isLexical: Boolean,
|
|
@@ -562,13 +562,123 @@ var getValV2_getter = (data, valuePath, options, depthIdx) => {
|
|
|
562
562
|
}
|
|
563
563
|
return dataRef[keysArray[len - 1]];
|
|
564
564
|
};
|
|
565
|
+
|
|
566
|
+
// src/redis/index.ts
|
|
567
|
+
import IORedis from "ioredis";
|
|
568
|
+
var redisClient = null;
|
|
569
|
+
var REDIS_CONFIG = {
|
|
570
|
+
port: Number(process.env.REDIS_PORT),
|
|
571
|
+
host: process.env.REDIS_HOST || "",
|
|
572
|
+
username: process.env.REDIS_USERNAME || "",
|
|
573
|
+
password: process.env.REDIS_PASSWORD || ""
|
|
574
|
+
};
|
|
575
|
+
var connectToRedis = async () => {
|
|
576
|
+
try {
|
|
577
|
+
redisClient = new IORedis(REDIS_CONFIG);
|
|
578
|
+
await redisClient.ping();
|
|
579
|
+
console.log("Redis connected successfully");
|
|
580
|
+
} catch (error) {
|
|
581
|
+
console.error(
|
|
582
|
+
"Redis connection failed:",
|
|
583
|
+
error instanceof Error && error.message
|
|
584
|
+
);
|
|
585
|
+
if (redisClient) {
|
|
586
|
+
redisClient.disconnect();
|
|
587
|
+
}
|
|
588
|
+
throw error;
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
var getRedisClient = () => {
|
|
592
|
+
if (!redisClient) {
|
|
593
|
+
throw new Error("Redis client not initialized. Call connectToRedis first.");
|
|
594
|
+
}
|
|
595
|
+
return redisClient;
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
// src/redis/functions.ts
|
|
599
|
+
var findInCache = async ({
|
|
600
|
+
tenant,
|
|
601
|
+
modelName,
|
|
602
|
+
type,
|
|
603
|
+
query = {}
|
|
604
|
+
}) => {
|
|
605
|
+
const key = `${process.env.ENV}:${tenant}:${modelName}:${type}`;
|
|
606
|
+
try {
|
|
607
|
+
const redisClient2 = getRedisClient();
|
|
608
|
+
const value = await redisClient2.get(key);
|
|
609
|
+
if (value) {
|
|
610
|
+
return JSON.parse(value);
|
|
611
|
+
}
|
|
612
|
+
} catch (error) {
|
|
613
|
+
console.warn(
|
|
614
|
+
`redis read failed for key ${key}`,
|
|
615
|
+
error instanceof Error && error.message
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
try {
|
|
619
|
+
const collection = getDbByTenant({
|
|
620
|
+
tenant,
|
|
621
|
+
env: process.env.ENV
|
|
622
|
+
}).collection(modelName);
|
|
623
|
+
const value = await collection.findOne(query);
|
|
624
|
+
if (!value) {
|
|
625
|
+
throw new Error(`${type} value not found in ${modelName} for ${tenant}`);
|
|
626
|
+
}
|
|
627
|
+
try {
|
|
628
|
+
const redisClient2 = getRedisClient();
|
|
629
|
+
await redisClient2.set(key, JSON.stringify(value));
|
|
630
|
+
} catch (error) {
|
|
631
|
+
console.warn(
|
|
632
|
+
`redis write failed for key ${key}:`,
|
|
633
|
+
error instanceof Error && error.message
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
return value;
|
|
637
|
+
} catch (error) {
|
|
638
|
+
throw new Error(
|
|
639
|
+
`db read failed: ${error instanceof Error && error.message}`
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
var getTpl = async ({ name, tenant }) => {
|
|
644
|
+
if (!name || !tenant) {
|
|
645
|
+
throw new Error("Missing required parameters: name or tenant");
|
|
646
|
+
}
|
|
647
|
+
return await findInCache({
|
|
648
|
+
modelName: "tpls",
|
|
649
|
+
type: name,
|
|
650
|
+
tenant,
|
|
651
|
+
query: {
|
|
652
|
+
kp_content_type: name,
|
|
653
|
+
status: { $in: ["published", "editPublished"] }
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
};
|
|
657
|
+
var getAIConfigs = async ({
|
|
658
|
+
tenant
|
|
659
|
+
}) => {
|
|
660
|
+
if (!tenant) {
|
|
661
|
+
throw new Error("Missing required parameter: tenant");
|
|
662
|
+
}
|
|
663
|
+
return await findInCache({
|
|
664
|
+
modelName: "platformConfigs",
|
|
665
|
+
type: "ai",
|
|
666
|
+
tenant,
|
|
667
|
+
query: {
|
|
668
|
+
type: "ai"
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
};
|
|
565
672
|
export {
|
|
566
673
|
add,
|
|
674
|
+
connectToRedis,
|
|
567
675
|
deleteVal,
|
|
676
|
+
getAIConfigs,
|
|
568
677
|
getAnnotationsModelByTenant,
|
|
569
678
|
getDbByTenant,
|
|
570
679
|
getModelByTenant,
|
|
571
680
|
getPlatformConfigsModelByTenant,
|
|
681
|
+
getTpl,
|
|
572
682
|
getTplModelByTenant,
|
|
573
683
|
getVal,
|
|
574
684
|
initializeGlobalConfig,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.3.1",
|
|
7
7
|
"description": "Utility functions for both browser and Node.js",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"module": "dist/index.mjs",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"@semantic-release/github": "^11.0.1",
|
|
35
35
|
"@semantic-release/npm": "^12.0.1",
|
|
36
36
|
"@semantic-release/release-notes-generator": "^14.0.3",
|
|
37
|
+
"@types/ioredis": "^4.28.10",
|
|
37
38
|
"@types/node": "^22.13.10",
|
|
38
39
|
"commitizen": "^4.3.1",
|
|
39
40
|
"cz-conventional-changelog": "^3.3.0",
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
"typescript": "^5.8.2"
|
|
43
44
|
},
|
|
44
45
|
"dependencies": {
|
|
46
|
+
"ioredis": "^5.6.1",
|
|
45
47
|
"mongoose": "^8.15.1"
|
|
46
48
|
}
|
|
47
49
|
}
|