This commit is contained in:
Benjamin Toby 2025-12-11 09:18:22 +01:00
parent f91aff421c
commit c88fb13375
8 changed files with 48 additions and 27 deletions

View File

@ -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 {};

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))) {

View File

@ -11,7 +11,7 @@ type Param<T extends {
};
type Return = {
string: string;
values: string[];
values: (string | number)[];
};
/**
* # SQL Query Generator

View File

@ -1438,7 +1438,7 @@ export type PagePropsType = {
};
export type ResponseQueryObject = {
sql?: string;
params?: string[];
params?: (string | number)[];
};
export type APIResponseObject<T extends any = any> = {
success: boolean;

View File

@ -22,15 +22,26 @@ export default function grabParsedValue({
encryptionKey,
encryptionSalt,
dataKey,
}: Param): any {
let newValue = value;
}: Param): string | number | undefined {
let newValue = value as string | number | undefined;
const targetFieldSchema = tableSchema
? tableSchema?.fields?.find((field) => field.fieldName === dataKey)
: null;
if (typeof newValue == "undefined") return;
if (typeof newValue == "object" && !newValue) newValue = null;
if (typeof newValue == "undefined") {
return;
}
if (
typeof newValue !== "string" &&
typeof newValue !== "number" &&
!newValue
) {
return;
}
if (typeof newValue == "object" && !newValue) {
return;
}
const htmlRegex = /<[^>]+>/g;
@ -47,11 +58,12 @@ export default function grabParsedValue({
}
if (targetFieldSchema?.encrypted) {
newValue = encrypt({
data: newValue,
encryptionKey,
encryptionSalt,
});
newValue =
encrypt({
data: newValue.toString(),
encryptionKey,
encryptionSalt,
}) || undefined;
}
if (typeof newValue === "object") {
@ -63,7 +75,8 @@ export default function grabParsedValue({
targetFieldSchema.pattern,
targetFieldSchema.patternFlags || ""
);
if (!pattern.test(newValue)) {
if (typeof newValue == "string" && !pattern.test(newValue)) {
console.log("DSQL: Pattern not matched =>", newValue);
newValue = "";
}
@ -73,7 +86,7 @@ export default function grabParsedValue({
typeof newValue === "string" &&
(newValue.match(/^null$/i) || !newValue.match(/./i))
) {
newValue = null;
newValue = undefined;
}
if (

View File

@ -16,7 +16,7 @@ type Param<T extends { [key: string]: any } = { [key: string]: any }> = {
type Return = {
string: string;
values: string[];
values: (string | number)[];
};
/**

View File

@ -1673,7 +1673,7 @@ export type PagePropsType = {
export type ResponseQueryObject = {
sql?: string;
params?: string[];
params?: (string | number)[];
};
export type APIResponseObject<T extends any = any> = {

View File

@ -1,6 +1,6 @@
{
"name": "@moduletrace/datasquirel",
"version": "5.5.2",
"version": "5.5.3",
"description": "Cloud-based SQL data management tool",
"main": "dist/index.js",
"bin": {