fiberx-backend-toolkit 0.1.9 → 0.1.10
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.
|
@@ -51,5 +51,6 @@ declare class InputValidatorUtil {
|
|
|
51
51
|
static dirExists(directory: string, create_directory?: boolean, return_dir_path?: boolean): boolean | string;
|
|
52
52
|
static isSafeHashCompare(a: string, b: string): boolean;
|
|
53
53
|
static isDeepEqual(a: any, b: any): boolean;
|
|
54
|
+
static hasInputChanged(new_input: Record<string, any>, existing_data: Record<string, any>, keys_to_check: string[]): boolean;
|
|
54
55
|
}
|
|
55
56
|
export default InputValidatorUtil;
|
|
@@ -174,5 +174,40 @@ class InputValidatorUtil {
|
|
|
174
174
|
}
|
|
175
175
|
return false;
|
|
176
176
|
}
|
|
177
|
+
static hasInputChanged(new_input, existing_data, keys_to_check) {
|
|
178
|
+
// Normalize values (booleans, "true"/"false", "1"/"0", null-like)
|
|
179
|
+
const normalize = (val) => {
|
|
180
|
+
if (val === "true")
|
|
181
|
+
return true;
|
|
182
|
+
if (val === "false")
|
|
183
|
+
return false;
|
|
184
|
+
if (val === "1")
|
|
185
|
+
return true;
|
|
186
|
+
if (val === "0")
|
|
187
|
+
return false;
|
|
188
|
+
return val;
|
|
189
|
+
};
|
|
190
|
+
// Utility to get nested value by dot notation
|
|
191
|
+
const getNestedValue = (obj, path) => {
|
|
192
|
+
return path.split('.').reduce((acc, part) => {
|
|
193
|
+
if (acc && typeof acc === 'object' && part in acc) {
|
|
194
|
+
return acc[part];
|
|
195
|
+
}
|
|
196
|
+
return undefined;
|
|
197
|
+
}, obj);
|
|
198
|
+
};
|
|
199
|
+
for (const key of keys_to_check) {
|
|
200
|
+
if (!(key in new_input)) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const new_val = normalize(getNestedValue(new_input, key));
|
|
204
|
+
const old_val = normalize(getNestedValue(existing_data, key));
|
|
205
|
+
if (!InputValidatorUtil.isDeepEqual(new_val, old_val)) {
|
|
206
|
+
console.log("🔺 CHANGED:", key, { new_val, old_val });
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
177
212
|
}
|
|
178
213
|
exports.default = InputValidatorUtil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fiberx-backend-toolkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "A TypeScript backend toolkit providing shared domain logic, infrastructure helpers, and utilities for FiberX server-side applications and services.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|