@punks/backend-entity-manager 0.0.391 → 0.0.392

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.
@@ -2,6 +2,7 @@
2
2
  export type EntryValidationError = {
3
3
  errorCode: string;
4
4
  value?: any;
5
+ payload?: any;
5
6
  };
6
7
  export type EntryValidationResult = {
7
8
  isValid: boolean;
package/dist/esm/index.js CHANGED
@@ -40747,18 +40747,30 @@ const fieldTextValidator = (item, selector, params) => {
40747
40747
  const isRequiredValid = params.required
40748
40748
  ? typeof value === "string" && value.length >= 0
40749
40749
  : true;
40750
- const isMinLengthValid = typeof value === "string" && value.length >= (params.minLength ?? 0);
40751
- const isMaxLengthValid = typeof value === "string" && value.length <= (params.maxLength ?? Infinity);
40750
+ const length = typeof value === "string" ? value.length : 0;
40751
+ const isMinLengthValid = length >= (params.minLength ?? 0);
40752
+ const isMaxLengthValid = length <= (params.maxLength ?? Infinity);
40752
40753
  const isRegexValid = (typeof value === "string" && params.regex?.test(value)) ?? true;
40753
40754
  return {
40754
40755
  isValid: isMinLengthValid && isMaxLengthValid,
40755
40756
  validationErrors: [
40756
40757
  ...(isRequiredValid ? [] : [{ errorCode: "required" }]),
40757
- ...(isMinLengthValid && isMaxLengthValid
40758
+ ...(isMinLengthValid
40758
40759
  ? []
40759
- : [{ errorCode: "length" }]),
40760
- ...(isMinLengthValid ? [] : [{ errorCode: "minLength" }]),
40761
- ...(isMaxLengthValid ? [] : [{ errorCode: "maxLength" }]),
40760
+ : [
40761
+ {
40762
+ errorCode: "minLength",
40763
+ payload: { current: length, expected: params.minLength },
40764
+ },
40765
+ ]),
40766
+ ...(isMaxLengthValid
40767
+ ? []
40768
+ : [
40769
+ {
40770
+ errorCode: "maxLength",
40771
+ payload: { current: length, expected: params.maxLength },
40772
+ },
40773
+ ]),
40762
40774
  ...(isRegexValid ? [] : [{ errorCode: "regex" }]),
40763
40775
  ],
40764
40776
  };