@okf/ootils 1.3.2 → 1.3.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/index.d.mts +34 -23
- package/dist/index.d.ts +34 -23
- package/dist/index.js +128 -101
- package/dist/index.mjs +127 -101
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -109,28 +109,6 @@ declare const getTplModelByTenant: ({ tenant, env, mongodb, dbConfigs }: GetMode
|
|
|
109
109
|
__v: number;
|
|
110
110
|
}, any>;
|
|
111
111
|
|
|
112
|
-
declare const deleteVal: (data: any, valuePath: string) => any;
|
|
113
|
-
|
|
114
|
-
type ValuePath = string | string[];
|
|
115
|
-
type DataValue = any;
|
|
116
|
-
interface GetValOptions {
|
|
117
|
-
flattenIfValueIsArray?: boolean;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
declare const setVal: (data: any, valuePath: string, value: DataValue) => any;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
*
|
|
124
|
-
* @param {*} data
|
|
125
|
-
* @param {*} valuePath
|
|
126
|
-
* @returns
|
|
127
|
-
* - if target value is an array found inside an array, it will flatten them out so that there is a single array
|
|
128
|
-
* - if target value is an array NOT found inside an array, that will be returned as is.
|
|
129
|
-
* - if target value is a string/object/number/boolean found inside an array of arrays, then the inner arrays will be flattened so that there is a single array
|
|
130
|
-
* - if target value is a string/object/number/boolean NOT found inside an array, it will be returned as is.
|
|
131
|
-
*/
|
|
132
|
-
declare const getVal: (data: any, valuePath: ValuePath, options?: GetValOptions, depthIdx?: number) => any;
|
|
133
|
-
|
|
134
112
|
interface GetTplParams {
|
|
135
113
|
name: string;
|
|
136
114
|
tenant: string;
|
|
@@ -166,4 +144,37 @@ declare const getAIConfigs: ({ tenant }: GetAIConfigsParams) => Promise<AIconfig
|
|
|
166
144
|
declare const connectToRedis: () => Promise<void>;
|
|
167
145
|
declare const getRedisClient: () => IORedis;
|
|
168
146
|
|
|
169
|
-
|
|
147
|
+
declare const deleteVal: (data: any, valuePath: string) => any;
|
|
148
|
+
|
|
149
|
+
type ValuePath = string | string[];
|
|
150
|
+
type DataValue = any;
|
|
151
|
+
interface GetValOptions {
|
|
152
|
+
flattenIfValueIsArray?: boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
declare const setVal: (data: any, valuePath: string, value: DataValue) => any;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
*
|
|
159
|
+
* @param {*} data
|
|
160
|
+
* @param {*} valuePath
|
|
161
|
+
* @returns
|
|
162
|
+
* - if target value is an array found inside an array, it will flatten them out so that there is a single array
|
|
163
|
+
* - if target value is an array NOT found inside an array, that will be returned as is.
|
|
164
|
+
* - if target value is a string/object/number/boolean found inside an array of arrays, then the inner arrays will be flattened so that there is a single array
|
|
165
|
+
* - if target value is a string/object/number/boolean NOT found inside an array, it will be returned as is.
|
|
166
|
+
*/
|
|
167
|
+
declare const getVal: (data: any, valuePath: ValuePath, options?: GetValOptions, depthIdx?: number) => any;
|
|
168
|
+
|
|
169
|
+
interface RichTextBlock {
|
|
170
|
+
text: string;
|
|
171
|
+
[key: string]: any;
|
|
172
|
+
}
|
|
173
|
+
interface RichTextValue {
|
|
174
|
+
blocks: RichTextBlock[];
|
|
175
|
+
[key: string]: any;
|
|
176
|
+
}
|
|
177
|
+
type TagNameInput = string | number | RichTextValue | null | undefined;
|
|
178
|
+
declare const genTagId: (tagName: TagNameInput) => string;
|
|
179
|
+
|
|
180
|
+
export { add, connectToRedis, deleteVal, genTagId, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, setVal, updateGlobalConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -109,28 +109,6 @@ declare const getTplModelByTenant: ({ tenant, env, mongodb, dbConfigs }: GetMode
|
|
|
109
109
|
__v: number;
|
|
110
110
|
}, any>;
|
|
111
111
|
|
|
112
|
-
declare const deleteVal: (data: any, valuePath: string) => any;
|
|
113
|
-
|
|
114
|
-
type ValuePath = string | string[];
|
|
115
|
-
type DataValue = any;
|
|
116
|
-
interface GetValOptions {
|
|
117
|
-
flattenIfValueIsArray?: boolean;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
declare const setVal: (data: any, valuePath: string, value: DataValue) => any;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
*
|
|
124
|
-
* @param {*} data
|
|
125
|
-
* @param {*} valuePath
|
|
126
|
-
* @returns
|
|
127
|
-
* - if target value is an array found inside an array, it will flatten them out so that there is a single array
|
|
128
|
-
* - if target value is an array NOT found inside an array, that will be returned as is.
|
|
129
|
-
* - if target value is a string/object/number/boolean found inside an array of arrays, then the inner arrays will be flattened so that there is a single array
|
|
130
|
-
* - if target value is a string/object/number/boolean NOT found inside an array, it will be returned as is.
|
|
131
|
-
*/
|
|
132
|
-
declare const getVal: (data: any, valuePath: ValuePath, options?: GetValOptions, depthIdx?: number) => any;
|
|
133
|
-
|
|
134
112
|
interface GetTplParams {
|
|
135
113
|
name: string;
|
|
136
114
|
tenant: string;
|
|
@@ -166,4 +144,37 @@ declare const getAIConfigs: ({ tenant }: GetAIConfigsParams) => Promise<AIconfig
|
|
|
166
144
|
declare const connectToRedis: () => Promise<void>;
|
|
167
145
|
declare const getRedisClient: () => IORedis;
|
|
168
146
|
|
|
169
|
-
|
|
147
|
+
declare const deleteVal: (data: any, valuePath: string) => any;
|
|
148
|
+
|
|
149
|
+
type ValuePath = string | string[];
|
|
150
|
+
type DataValue = any;
|
|
151
|
+
interface GetValOptions {
|
|
152
|
+
flattenIfValueIsArray?: boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
declare const setVal: (data: any, valuePath: string, value: DataValue) => any;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
*
|
|
159
|
+
* @param {*} data
|
|
160
|
+
* @param {*} valuePath
|
|
161
|
+
* @returns
|
|
162
|
+
* - if target value is an array found inside an array, it will flatten them out so that there is a single array
|
|
163
|
+
* - if target value is an array NOT found inside an array, that will be returned as is.
|
|
164
|
+
* - if target value is a string/object/number/boolean found inside an array of arrays, then the inner arrays will be flattened so that there is a single array
|
|
165
|
+
* - if target value is a string/object/number/boolean NOT found inside an array, it will be returned as is.
|
|
166
|
+
*/
|
|
167
|
+
declare const getVal: (data: any, valuePath: ValuePath, options?: GetValOptions, depthIdx?: number) => any;
|
|
168
|
+
|
|
169
|
+
interface RichTextBlock {
|
|
170
|
+
text: string;
|
|
171
|
+
[key: string]: any;
|
|
172
|
+
}
|
|
173
|
+
interface RichTextValue {
|
|
174
|
+
blocks: RichTextBlock[];
|
|
175
|
+
[key: string]: any;
|
|
176
|
+
}
|
|
177
|
+
type TagNameInput = string | number | RichTextValue | null | undefined;
|
|
178
|
+
declare const genTagId: (tagName: TagNameInput) => string;
|
|
179
|
+
|
|
180
|
+
export { add, connectToRedis, deleteVal, genTagId, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, setVal, updateGlobalConfig };
|
package/dist/index.js
CHANGED
|
@@ -320,6 +320,7 @@ __export(index_exports, {
|
|
|
320
320
|
add: () => add,
|
|
321
321
|
connectToRedis: () => connectToRedis,
|
|
322
322
|
deleteVal: () => deleteVal,
|
|
323
|
+
genTagId: () => genTagId,
|
|
323
324
|
getAIConfigs: () => getAIConfigs,
|
|
324
325
|
getAnnotationsModelByTenant: () => getAnnotationsModelByTenant,
|
|
325
326
|
getDbByTenant: () => getDbByTenant,
|
|
@@ -477,6 +478,113 @@ var getTplModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTen
|
|
|
477
478
|
env
|
|
478
479
|
});
|
|
479
480
|
|
|
481
|
+
// src/redis/index.ts
|
|
482
|
+
var import_ioredis = __toESM(require("ioredis"));
|
|
483
|
+
var redisClient = null;
|
|
484
|
+
var REDIS_CONFIG = {
|
|
485
|
+
port: Number(process.env.REDIS_PORT),
|
|
486
|
+
host: process.env.REDIS_HOST || "",
|
|
487
|
+
username: process.env.REDIS_USERNAME || "",
|
|
488
|
+
password: process.env.REDIS_PASSWORD || ""
|
|
489
|
+
};
|
|
490
|
+
var connectToRedis = async () => {
|
|
491
|
+
try {
|
|
492
|
+
redisClient = new import_ioredis.default(REDIS_CONFIG);
|
|
493
|
+
await redisClient.ping();
|
|
494
|
+
console.log("Redis connected successfully");
|
|
495
|
+
} catch (error) {
|
|
496
|
+
console.error(
|
|
497
|
+
"Redis connection failed:",
|
|
498
|
+
error instanceof Error && error.message
|
|
499
|
+
);
|
|
500
|
+
if (redisClient) {
|
|
501
|
+
redisClient.disconnect();
|
|
502
|
+
}
|
|
503
|
+
throw error;
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
var getRedisClient = () => {
|
|
507
|
+
if (!redisClient) {
|
|
508
|
+
throw new Error("Redis client not initialized. Call connectToRedis first.");
|
|
509
|
+
}
|
|
510
|
+
return redisClient;
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
// src/redis/functions.ts
|
|
514
|
+
var findInCache = async ({
|
|
515
|
+
tenant,
|
|
516
|
+
modelName,
|
|
517
|
+
type,
|
|
518
|
+
query = {}
|
|
519
|
+
}) => {
|
|
520
|
+
const key = `${process.env.ENV}:${tenant}:${modelName}:${type}`;
|
|
521
|
+
try {
|
|
522
|
+
const redisClient2 = getRedisClient();
|
|
523
|
+
const value = await redisClient2.get(key);
|
|
524
|
+
if (value) {
|
|
525
|
+
return JSON.parse(value);
|
|
526
|
+
}
|
|
527
|
+
} catch (error) {
|
|
528
|
+
console.warn(
|
|
529
|
+
`redis read failed for key ${key}`,
|
|
530
|
+
error instanceof Error && error.message
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
try {
|
|
534
|
+
const collection = getDbByTenant({
|
|
535
|
+
tenant,
|
|
536
|
+
env: process.env.ENV
|
|
537
|
+
}).collection(modelName);
|
|
538
|
+
const value = await collection.findOne(query);
|
|
539
|
+
if (!value) {
|
|
540
|
+
throw new Error(`${type} value not found in ${modelName} for ${tenant}`);
|
|
541
|
+
}
|
|
542
|
+
try {
|
|
543
|
+
const redisClient2 = getRedisClient();
|
|
544
|
+
await redisClient2.set(key, JSON.stringify(value));
|
|
545
|
+
} catch (error) {
|
|
546
|
+
console.warn(
|
|
547
|
+
`redis write failed for key ${key}:`,
|
|
548
|
+
error instanceof Error && error.message
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
return value;
|
|
552
|
+
} catch (error) {
|
|
553
|
+
throw new Error(
|
|
554
|
+
`db read failed: ${error instanceof Error && error.message}`
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
var getTpl = async ({ name, tenant }) => {
|
|
559
|
+
if (!name || !tenant) {
|
|
560
|
+
throw new Error("Missing required parameters: name or tenant");
|
|
561
|
+
}
|
|
562
|
+
return await findInCache({
|
|
563
|
+
modelName: "tpls",
|
|
564
|
+
type: name,
|
|
565
|
+
tenant,
|
|
566
|
+
query: {
|
|
567
|
+
kp_content_type: name,
|
|
568
|
+
status: { $in: ["published", "editPublished"] }
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
};
|
|
572
|
+
var getAIConfigs = async ({
|
|
573
|
+
tenant
|
|
574
|
+
}) => {
|
|
575
|
+
if (!tenant) {
|
|
576
|
+
throw new Error("Missing required parameter: tenant");
|
|
577
|
+
}
|
|
578
|
+
return await findInCache({
|
|
579
|
+
modelName: "platformConfigs",
|
|
580
|
+
type: "ai",
|
|
581
|
+
tenant,
|
|
582
|
+
query: {
|
|
583
|
+
type: "ai"
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
};
|
|
587
|
+
|
|
480
588
|
// src/utils/getterSetterDeleter/utils/set_deleteVal.ts
|
|
481
589
|
var set_deleteVal = (action, data, valuePath, value) => {
|
|
482
590
|
if (valuePath === void 0) return;
|
|
@@ -608,117 +716,36 @@ var getValV2_getter = (data, valuePath, options, depthIdx) => {
|
|
|
608
716
|
return dataRef[keysArray[len - 1]];
|
|
609
717
|
};
|
|
610
718
|
|
|
611
|
-
// src/
|
|
612
|
-
var
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
username: process.env.REDIS_USERNAME || "",
|
|
618
|
-
password: process.env.REDIS_PASSWORD || ""
|
|
619
|
-
};
|
|
620
|
-
var connectToRedis = async () => {
|
|
621
|
-
try {
|
|
622
|
-
redisClient = new import_ioredis.default(REDIS_CONFIG);
|
|
623
|
-
await redisClient.ping();
|
|
624
|
-
console.log("Redis connected successfully");
|
|
625
|
-
} catch (error) {
|
|
626
|
-
console.error(
|
|
627
|
-
"Redis connection failed:",
|
|
628
|
-
error instanceof Error && error.message
|
|
629
|
-
);
|
|
630
|
-
if (redisClient) {
|
|
631
|
-
redisClient.disconnect();
|
|
632
|
-
}
|
|
633
|
-
throw error;
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
var getRedisClient = () => {
|
|
637
|
-
if (!redisClient) {
|
|
638
|
-
throw new Error("Redis client not initialized. Call connectToRedis first.");
|
|
639
|
-
}
|
|
640
|
-
return redisClient;
|
|
641
|
-
};
|
|
642
|
-
|
|
643
|
-
// src/redis/functions.ts
|
|
644
|
-
var findInCache = async ({
|
|
645
|
-
tenant,
|
|
646
|
-
modelName,
|
|
647
|
-
type,
|
|
648
|
-
query = {}
|
|
649
|
-
}) => {
|
|
650
|
-
const key = `${process.env.ENV}:${tenant}:${modelName}:${type}`;
|
|
651
|
-
try {
|
|
652
|
-
const redisClient2 = getRedisClient();
|
|
653
|
-
const value = await redisClient2.get(key);
|
|
654
|
-
if (value) {
|
|
655
|
-
return JSON.parse(value);
|
|
656
|
-
}
|
|
657
|
-
} catch (error) {
|
|
658
|
-
console.warn(
|
|
659
|
-
`redis read failed for key ${key}`,
|
|
660
|
-
error instanceof Error && error.message
|
|
661
|
-
);
|
|
719
|
+
// src/utils/genTagId.ts
|
|
720
|
+
var convertFromRichText = (value) => {
|
|
721
|
+
if (!value) return "";
|
|
722
|
+
let val = "";
|
|
723
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
724
|
+
return String(value);
|
|
662
725
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
if (!value) {
|
|
670
|
-
throw new Error(`${type} value not found in ${modelName} for ${tenant}`);
|
|
671
|
-
}
|
|
672
|
-
try {
|
|
673
|
-
const redisClient2 = getRedisClient();
|
|
674
|
-
await redisClient2.set(key, JSON.stringify(value));
|
|
675
|
-
} catch (error) {
|
|
676
|
-
console.warn(
|
|
677
|
-
`redis write failed for key ${key}:`,
|
|
678
|
-
error instanceof Error && error.message
|
|
679
|
-
);
|
|
726
|
+
if (typeof value === "object" && "blocks" in value && Array.isArray(value.blocks)) {
|
|
727
|
+
for (let i = 0; i < value.blocks.length; i++) {
|
|
728
|
+
const block = value.blocks[i];
|
|
729
|
+
if (block && block.text && block.text.length > 0) {
|
|
730
|
+
val = val + block.text;
|
|
731
|
+
}
|
|
680
732
|
}
|
|
681
|
-
return value;
|
|
682
|
-
} catch (error) {
|
|
683
|
-
throw new Error(
|
|
684
|
-
`db read failed: ${error instanceof Error && error.message}`
|
|
685
|
-
);
|
|
686
|
-
}
|
|
687
|
-
};
|
|
688
|
-
var getTpl = async ({ name, tenant }) => {
|
|
689
|
-
if (!name || !tenant) {
|
|
690
|
-
throw new Error("Missing required parameters: name or tenant");
|
|
691
733
|
}
|
|
692
|
-
return
|
|
693
|
-
modelName: "tpls",
|
|
694
|
-
type: name,
|
|
695
|
-
tenant,
|
|
696
|
-
query: {
|
|
697
|
-
kp_content_type: name,
|
|
698
|
-
status: { $in: ["published", "editPublished"] }
|
|
699
|
-
}
|
|
700
|
-
});
|
|
734
|
+
return val;
|
|
701
735
|
};
|
|
702
|
-
var
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
return await findInCache({
|
|
709
|
-
modelName: "platformConfigs",
|
|
710
|
-
type: "ai",
|
|
711
|
-
tenant,
|
|
712
|
-
query: {
|
|
713
|
-
type: "ai"
|
|
714
|
-
}
|
|
715
|
-
});
|
|
736
|
+
var genTagId = (tagName) => {
|
|
737
|
+
let toReturn = convertFromRichText(tagName);
|
|
738
|
+
const regex = /[^\p{L}\p{N}\+]+/gui;
|
|
739
|
+
toReturn = toReturn.trim().toLowerCase().replace(regex, "_");
|
|
740
|
+
toReturn = toReturn.replace(/\+/g, "plus");
|
|
741
|
+
return toReturn.replace(/^_+|_+$/, "");
|
|
716
742
|
};
|
|
717
743
|
// Annotate the CommonJS export names for ESM import in node:
|
|
718
744
|
0 && (module.exports = {
|
|
719
745
|
add,
|
|
720
746
|
connectToRedis,
|
|
721
747
|
deleteVal,
|
|
748
|
+
genTagId,
|
|
722
749
|
getAIConfigs,
|
|
723
750
|
getAnnotationsModelByTenant,
|
|
724
751
|
getDbByTenant,
|
package/dist/index.mjs
CHANGED
|
@@ -434,6 +434,113 @@ var getTplModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTen
|
|
|
434
434
|
env
|
|
435
435
|
});
|
|
436
436
|
|
|
437
|
+
// src/redis/index.ts
|
|
438
|
+
import IORedis from "ioredis";
|
|
439
|
+
var redisClient = null;
|
|
440
|
+
var REDIS_CONFIG = {
|
|
441
|
+
port: Number(process.env.REDIS_PORT),
|
|
442
|
+
host: process.env.REDIS_HOST || "",
|
|
443
|
+
username: process.env.REDIS_USERNAME || "",
|
|
444
|
+
password: process.env.REDIS_PASSWORD || ""
|
|
445
|
+
};
|
|
446
|
+
var connectToRedis = async () => {
|
|
447
|
+
try {
|
|
448
|
+
redisClient = new IORedis(REDIS_CONFIG);
|
|
449
|
+
await redisClient.ping();
|
|
450
|
+
console.log("Redis connected successfully");
|
|
451
|
+
} catch (error) {
|
|
452
|
+
console.error(
|
|
453
|
+
"Redis connection failed:",
|
|
454
|
+
error instanceof Error && error.message
|
|
455
|
+
);
|
|
456
|
+
if (redisClient) {
|
|
457
|
+
redisClient.disconnect();
|
|
458
|
+
}
|
|
459
|
+
throw error;
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
var getRedisClient = () => {
|
|
463
|
+
if (!redisClient) {
|
|
464
|
+
throw new Error("Redis client not initialized. Call connectToRedis first.");
|
|
465
|
+
}
|
|
466
|
+
return redisClient;
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// src/redis/functions.ts
|
|
470
|
+
var findInCache = async ({
|
|
471
|
+
tenant,
|
|
472
|
+
modelName,
|
|
473
|
+
type,
|
|
474
|
+
query = {}
|
|
475
|
+
}) => {
|
|
476
|
+
const key = `${process.env.ENV}:${tenant}:${modelName}:${type}`;
|
|
477
|
+
try {
|
|
478
|
+
const redisClient2 = getRedisClient();
|
|
479
|
+
const value = await redisClient2.get(key);
|
|
480
|
+
if (value) {
|
|
481
|
+
return JSON.parse(value);
|
|
482
|
+
}
|
|
483
|
+
} catch (error) {
|
|
484
|
+
console.warn(
|
|
485
|
+
`redis read failed for key ${key}`,
|
|
486
|
+
error instanceof Error && error.message
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
try {
|
|
490
|
+
const collection = getDbByTenant({
|
|
491
|
+
tenant,
|
|
492
|
+
env: process.env.ENV
|
|
493
|
+
}).collection(modelName);
|
|
494
|
+
const value = await collection.findOne(query);
|
|
495
|
+
if (!value) {
|
|
496
|
+
throw new Error(`${type} value not found in ${modelName} for ${tenant}`);
|
|
497
|
+
}
|
|
498
|
+
try {
|
|
499
|
+
const redisClient2 = getRedisClient();
|
|
500
|
+
await redisClient2.set(key, JSON.stringify(value));
|
|
501
|
+
} catch (error) {
|
|
502
|
+
console.warn(
|
|
503
|
+
`redis write failed for key ${key}:`,
|
|
504
|
+
error instanceof Error && error.message
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
return value;
|
|
508
|
+
} catch (error) {
|
|
509
|
+
throw new Error(
|
|
510
|
+
`db read failed: ${error instanceof Error && error.message}`
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
var getTpl = async ({ name, tenant }) => {
|
|
515
|
+
if (!name || !tenant) {
|
|
516
|
+
throw new Error("Missing required parameters: name or tenant");
|
|
517
|
+
}
|
|
518
|
+
return await findInCache({
|
|
519
|
+
modelName: "tpls",
|
|
520
|
+
type: name,
|
|
521
|
+
tenant,
|
|
522
|
+
query: {
|
|
523
|
+
kp_content_type: name,
|
|
524
|
+
status: { $in: ["published", "editPublished"] }
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
};
|
|
528
|
+
var getAIConfigs = async ({
|
|
529
|
+
tenant
|
|
530
|
+
}) => {
|
|
531
|
+
if (!tenant) {
|
|
532
|
+
throw new Error("Missing required parameter: tenant");
|
|
533
|
+
}
|
|
534
|
+
return await findInCache({
|
|
535
|
+
modelName: "platformConfigs",
|
|
536
|
+
type: "ai",
|
|
537
|
+
tenant,
|
|
538
|
+
query: {
|
|
539
|
+
type: "ai"
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
|
|
437
544
|
// src/utils/getterSetterDeleter/utils/set_deleteVal.ts
|
|
438
545
|
var set_deleteVal = (action, data, valuePath, value) => {
|
|
439
546
|
if (valuePath === void 0) return;
|
|
@@ -565,116 +672,35 @@ var getValV2_getter = (data, valuePath, options, depthIdx) => {
|
|
|
565
672
|
return dataRef[keysArray[len - 1]];
|
|
566
673
|
};
|
|
567
674
|
|
|
568
|
-
// src/
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
username: process.env.REDIS_USERNAME || "",
|
|
575
|
-
password: process.env.REDIS_PASSWORD || ""
|
|
576
|
-
};
|
|
577
|
-
var connectToRedis = async () => {
|
|
578
|
-
try {
|
|
579
|
-
redisClient = new IORedis(REDIS_CONFIG);
|
|
580
|
-
await redisClient.ping();
|
|
581
|
-
console.log("Redis connected successfully");
|
|
582
|
-
} catch (error) {
|
|
583
|
-
console.error(
|
|
584
|
-
"Redis connection failed:",
|
|
585
|
-
error instanceof Error && error.message
|
|
586
|
-
);
|
|
587
|
-
if (redisClient) {
|
|
588
|
-
redisClient.disconnect();
|
|
589
|
-
}
|
|
590
|
-
throw error;
|
|
591
|
-
}
|
|
592
|
-
};
|
|
593
|
-
var getRedisClient = () => {
|
|
594
|
-
if (!redisClient) {
|
|
595
|
-
throw new Error("Redis client not initialized. Call connectToRedis first.");
|
|
596
|
-
}
|
|
597
|
-
return redisClient;
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
// src/redis/functions.ts
|
|
601
|
-
var findInCache = async ({
|
|
602
|
-
tenant,
|
|
603
|
-
modelName,
|
|
604
|
-
type,
|
|
605
|
-
query = {}
|
|
606
|
-
}) => {
|
|
607
|
-
const key = `${process.env.ENV}:${tenant}:${modelName}:${type}`;
|
|
608
|
-
try {
|
|
609
|
-
const redisClient2 = getRedisClient();
|
|
610
|
-
const value = await redisClient2.get(key);
|
|
611
|
-
if (value) {
|
|
612
|
-
return JSON.parse(value);
|
|
613
|
-
}
|
|
614
|
-
} catch (error) {
|
|
615
|
-
console.warn(
|
|
616
|
-
`redis read failed for key ${key}`,
|
|
617
|
-
error instanceof Error && error.message
|
|
618
|
-
);
|
|
675
|
+
// src/utils/genTagId.ts
|
|
676
|
+
var convertFromRichText = (value) => {
|
|
677
|
+
if (!value) return "";
|
|
678
|
+
let val = "";
|
|
679
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
680
|
+
return String(value);
|
|
619
681
|
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
if (!value) {
|
|
627
|
-
throw new Error(`${type} value not found in ${modelName} for ${tenant}`);
|
|
628
|
-
}
|
|
629
|
-
try {
|
|
630
|
-
const redisClient2 = getRedisClient();
|
|
631
|
-
await redisClient2.set(key, JSON.stringify(value));
|
|
632
|
-
} catch (error) {
|
|
633
|
-
console.warn(
|
|
634
|
-
`redis write failed for key ${key}:`,
|
|
635
|
-
error instanceof Error && error.message
|
|
636
|
-
);
|
|
682
|
+
if (typeof value === "object" && "blocks" in value && Array.isArray(value.blocks)) {
|
|
683
|
+
for (let i = 0; i < value.blocks.length; i++) {
|
|
684
|
+
const block = value.blocks[i];
|
|
685
|
+
if (block && block.text && block.text.length > 0) {
|
|
686
|
+
val = val + block.text;
|
|
687
|
+
}
|
|
637
688
|
}
|
|
638
|
-
return value;
|
|
639
|
-
} catch (error) {
|
|
640
|
-
throw new Error(
|
|
641
|
-
`db read failed: ${error instanceof Error && error.message}`
|
|
642
|
-
);
|
|
643
|
-
}
|
|
644
|
-
};
|
|
645
|
-
var getTpl = async ({ name, tenant }) => {
|
|
646
|
-
if (!name || !tenant) {
|
|
647
|
-
throw new Error("Missing required parameters: name or tenant");
|
|
648
689
|
}
|
|
649
|
-
return
|
|
650
|
-
modelName: "tpls",
|
|
651
|
-
type: name,
|
|
652
|
-
tenant,
|
|
653
|
-
query: {
|
|
654
|
-
kp_content_type: name,
|
|
655
|
-
status: { $in: ["published", "editPublished"] }
|
|
656
|
-
}
|
|
657
|
-
});
|
|
690
|
+
return val;
|
|
658
691
|
};
|
|
659
|
-
var
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
return await findInCache({
|
|
666
|
-
modelName: "platformConfigs",
|
|
667
|
-
type: "ai",
|
|
668
|
-
tenant,
|
|
669
|
-
query: {
|
|
670
|
-
type: "ai"
|
|
671
|
-
}
|
|
672
|
-
});
|
|
692
|
+
var genTagId = (tagName) => {
|
|
693
|
+
let toReturn = convertFromRichText(tagName);
|
|
694
|
+
const regex = /[^\p{L}\p{N}\+]+/gui;
|
|
695
|
+
toReturn = toReturn.trim().toLowerCase().replace(regex, "_");
|
|
696
|
+
toReturn = toReturn.replace(/\+/g, "plus");
|
|
697
|
+
return toReturn.replace(/^_+|_+$/, "");
|
|
673
698
|
};
|
|
674
699
|
export {
|
|
675
700
|
add,
|
|
676
701
|
connectToRedis,
|
|
677
702
|
deleteVal,
|
|
703
|
+
genTagId,
|
|
678
704
|
getAIConfigs,
|
|
679
705
|
getAnnotationsModelByTenant,
|
|
680
706
|
getDbByTenant,
|