@63klabs/cache-data 1.3.9 → 1.3.11

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.
@@ -5,6 +5,10 @@
5
5
  * single-parameter or multi-parameter interfaces. It handles errors gracefully and
6
6
  * logs validation failures.
7
7
  *
8
+ * The interface is determined by the params array length:
9
+ * - params.length === 1: Pass value directly (single-parameter interface)
10
+ * - params.length > 1: Pass object (multi-parameter interface)
11
+ *
8
12
  * @private
9
13
  * @class ValidationExecutor
10
14
  */
@@ -13,8 +17,8 @@ class ValidationExecutor {
13
17
  * Execute validation function with appropriate interface.
14
18
  *
15
19
  * Determines whether to pass a single value or an object based on the number
16
- * of parameters specified. Handles validation errors gracefully by catching
17
- * exceptions and logging them.
20
+ * of parameters in the params array. Handles validation errors gracefully by
21
+ * catching exceptions and logging them.
18
22
  *
19
23
  * @param {Function} validateFn - Validation function to execute
20
24
  * @param {Array<string>} paramNames - Parameter names to validate
@@ -22,7 +26,7 @@ class ValidationExecutor {
22
26
  * @returns {boolean} True if validation passes, false if fails or throws
23
27
  *
24
28
  * @example
25
- * // Single parameter validation
29
+ * // Single parameter validation (params.length === 1)
26
30
  * const isValid = ValidationExecutor.execute(
27
31
  * (value) => value.length > 0,
28
32
  * ['id'],
@@ -30,7 +34,7 @@ class ValidationExecutor {
30
34
  * );
31
35
  *
32
36
  * @example
33
- * // Multi-parameter validation
37
+ * // Multi-parameter validation (params.length > 1)
34
38
  * const isValid = ValidationExecutor.execute(
35
39
  * ({page, limit}) => page >= 1 && limit >= 1 && limit <= 100,
36
40
  * ['page', 'limit'],
@@ -316,7 +316,7 @@ class ValidationMatcher {
316
316
  * @returns {{validate: Function, params: Array<string>}|null} Validation rule or null
317
317
  */
318
318
  #findGlobalMatch(paramName) {
319
- // Check if parameter has a global validation function
319
+ // >! Try exact match first (for backwards compatibility)
320
320
  if (this.#paramValidations[paramName] && typeof this.#paramValidations[paramName] === 'function') {
321
321
  return {
322
322
  validate: this.#paramValidations[paramName],
@@ -324,6 +324,18 @@ class ValidationMatcher {
324
324
  };
325
325
  }
326
326
 
327
+ // >! Try case-insensitive match for query parameters
328
+ // >! Query parameters are lowercased in ClientRequest, but validation rules may use camelCase
329
+ const lowerParamName = paramName.toLowerCase();
330
+ for (const key in this.#paramValidations) {
331
+ if (key.toLowerCase() === lowerParamName && typeof this.#paramValidations[key] === 'function') {
332
+ return {
333
+ validate: this.#paramValidations[key],
334
+ params: [paramName] // Return the lowercased paramName that was passed in
335
+ };
336
+ }
337
+ }
338
+
327
339
  return null;
328
340
  }
329
341