This commit is contained in:
2025-12-11 09:18:22 +01:00
parent f91aff421c
commit c88fb13375
8 changed files with 48 additions and 27 deletions
@@ -10,5 +10,5 @@ type Param = {
* # Update DB Function
* @description
*/
export default function grabParsedValue({ value, tableSchema, encryptionKey, encryptionSalt, dataKey, }: Param): any;
export default function grabParsedValue({ value, tableSchema, encryptionKey, encryptionSalt, dataKey, }: Param): string | number | undefined;
export {};
+18 -10
View File
@@ -17,10 +17,17 @@ function grabParsedValue({ value, tableSchema, encryptionKey, encryptionSalt, da
const targetFieldSchema = tableSchema
? (_a = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _a === void 0 ? void 0 : _a.find((field) => field.fieldName === dataKey)
: null;
if (typeof newValue == "undefined")
if (typeof newValue == "undefined") {
return;
if (typeof newValue == "object" && !newValue)
newValue = null;
}
if (typeof newValue !== "string" &&
typeof newValue !== "number" &&
!newValue) {
return;
}
if (typeof newValue == "object" && !newValue) {
return;
}
const htmlRegex = /<[^>]+>/g;
if ((targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.richText) || String(newValue).match(htmlRegex)) {
newValue = (0, sanitize_html_1.default)(newValue, sanitizeHtmlOptions_1.default);
@@ -31,25 +38,26 @@ function grabParsedValue({ value, tableSchema, encryptionKey, encryptionSalt, da
newValue = "";
}
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.encrypted) {
newValue = (0, encrypt_1.default)({
data: newValue,
encryptionKey,
encryptionSalt,
});
newValue =
(0, encrypt_1.default)({
data: newValue.toString(),
encryptionKey,
encryptionSalt,
}) || undefined;
}
if (typeof newValue === "object") {
newValue = JSON.stringify(newValue);
}
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.pattern) {
const pattern = new RegExp(targetFieldSchema.pattern, targetFieldSchema.patternFlags || "");
if (!pattern.test(newValue)) {
if (typeof newValue == "string" && !pattern.test(newValue)) {
console.log("DSQL: Pattern not matched =>", newValue);
newValue = "";
}
}
if (typeof newValue === "string" &&
(newValue.match(/^null$/i) || !newValue.match(/./i))) {
newValue = null;
newValue = undefined;
}
if (typeof newValue === "boolean" ||
((_c = targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.dataType) === null || _c === void 0 ? void 0 : _c.match(/boolean/i))) {