diff --git a/dist/package-shared/functions/backend/db/grab-parsed-value.d.ts b/dist/package-shared/functions/backend/db/grab-parsed-value.d.ts index 13f32c1..0bb34e7 100644 --- a/dist/package-shared/functions/backend/db/grab-parsed-value.d.ts +++ b/dist/package-shared/functions/backend/db/grab-parsed-value.d.ts @@ -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 {}; diff --git a/dist/package-shared/functions/backend/db/grab-parsed-value.js b/dist/package-shared/functions/backend/db/grab-parsed-value.js index c020ae5..b3b1802 100644 --- a/dist/package-shared/functions/backend/db/grab-parsed-value.js +++ b/dist/package-shared/functions/backend/db/grab-parsed-value.js @@ -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))) { diff --git a/dist/package-shared/functions/dsql/sql/sql-generator.d.ts b/dist/package-shared/functions/dsql/sql/sql-generator.d.ts index 092b5da..b8d34cf 100644 --- a/dist/package-shared/functions/dsql/sql/sql-generator.d.ts +++ b/dist/package-shared/functions/dsql/sql/sql-generator.d.ts @@ -11,7 +11,7 @@ type Param = { success: boolean; diff --git a/package-shared/functions/backend/db/grab-parsed-value.ts b/package-shared/functions/backend/db/grab-parsed-value.ts index f4c6b63..63e097c 100644 --- a/package-shared/functions/backend/db/grab-parsed-value.ts +++ b/package-shared/functions/backend/db/grab-parsed-value.ts @@ -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 ( diff --git a/package-shared/functions/dsql/sql/sql-generator.ts b/package-shared/functions/dsql/sql/sql-generator.ts index cbf8e9c..28220b7 100644 --- a/package-shared/functions/dsql/sql/sql-generator.ts +++ b/package-shared/functions/dsql/sql/sql-generator.ts @@ -16,7 +16,7 @@ type Param = { type Return = { string: string; - values: string[]; + values: (string | number)[]; }; /** diff --git a/package-shared/types/index.ts b/package-shared/types/index.ts index 3fb2329..bec4db7 100644 --- a/package-shared/types/index.ts +++ b/package-shared/types/index.ts @@ -1673,7 +1673,7 @@ export type PagePropsType = { export type ResponseQueryObject = { sql?: string; - params?: string[]; + params?: (string | number)[]; }; export type APIResponseObject = { diff --git a/package.json b/package.json index aca217c..cbff4de 100644 --- a/package.json +++ b/package.json @@ -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": {