@punks/backend-entity-manager 0.0.390 → 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.
package/dist/cjs/index.js CHANGED
@@ -40757,6 +40757,39 @@ const fieldRequiredValidator = (item, selector) => {
40757
40757
  validationErrors: value ? [] : [{ errorCode: "required" }],
40758
40758
  };
40759
40759
  };
40760
+ const fieldTextValidator = (item, selector, params) => {
40761
+ const value = selector(item);
40762
+ const isRequiredValid = params.required
40763
+ ? typeof value === "string" && value.length >= 0
40764
+ : true;
40765
+ const length = typeof value === "string" ? value.length : 0;
40766
+ const isMinLengthValid = length >= (params.minLength ?? 0);
40767
+ const isMaxLengthValid = length <= (params.maxLength ?? Infinity);
40768
+ const isRegexValid = (typeof value === "string" && params.regex?.test(value)) ?? true;
40769
+ return {
40770
+ isValid: isMinLengthValid && isMaxLengthValid,
40771
+ validationErrors: [
40772
+ ...(isRequiredValid ? [] : [{ errorCode: "required" }]),
40773
+ ...(isMinLengthValid
40774
+ ? []
40775
+ : [
40776
+ {
40777
+ errorCode: "minLength",
40778
+ payload: { current: length, expected: params.minLength },
40779
+ },
40780
+ ]),
40781
+ ...(isMaxLengthValid
40782
+ ? []
40783
+ : [
40784
+ {
40785
+ errorCode: "maxLength",
40786
+ payload: { current: length, expected: params.maxLength },
40787
+ },
40788
+ ]),
40789
+ ...(isRegexValid ? [] : [{ errorCode: "regex" }]),
40790
+ ],
40791
+ };
40792
+ };
40760
40793
  const fieldOptionValidator = (item, selector, { availableOptions, required, }) => {
40761
40794
  const value = selector(item);
40762
40795
  if (!value) {
@@ -44910,6 +44943,7 @@ exports.createExpressFileResponse = createExpressFileResponse;
44910
44943
  exports.fieldOptionValidator = fieldOptionValidator;
44911
44944
  exports.fieldOptionsValidator = fieldOptionsValidator;
44912
44945
  exports.fieldRequiredValidator = fieldRequiredValidator;
44946
+ exports.fieldTextValidator = fieldTextValidator;
44913
44947
  exports.getEntityManagerProviderToken = getEntityManagerProviderToken;
44914
44948
  exports.getLocalizedText = getLocalizedText;
44915
44949
  exports.newUuid = newUuid;