@punks/backend-entity-manager 0.0.495 → 0.0.498

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.
@@ -1,7 +1,8 @@
1
1
  import { EntryValidationResult } from "../abstractions/serializer";
2
2
  export declare const fieldRequiredValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => any) => EntryValidationResult;
3
- export declare const fieldNumericValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => number, params: {
4
- required?: boolean;
3
+ export declare const fieldNumericValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => number, params?: {
4
+ min?: number;
5
+ max?: number;
5
6
  }) => EntryValidationResult;
6
7
  export declare const fieldTextValidator: <TSheetItem>(item: TSheetItem, selector: (item: TSheetItem) => string | string[], params: {
7
8
  required?: boolean;
package/dist/esm/index.js CHANGED
@@ -41150,9 +41150,25 @@ const fieldRequiredValidator = (item, selector) => {
41150
41150
  const fieldNumericValidator = (item, selector, params) => {
41151
41151
  const value = selector(item);
41152
41152
  const isInvalid = value && !isNaN(value);
41153
+ const errors = [];
41154
+ if (!!value && !isNaN(value)) {
41155
+ errors.push({ errorCode: "notNumeric" });
41156
+ }
41157
+ if (!!params?.min && !!value && value < params.min) {
41158
+ errors.push({
41159
+ errorCode: "min",
41160
+ payload: { current: value, expected: params.min },
41161
+ });
41162
+ }
41163
+ if (!!params?.max && !!value && value > params.max) {
41164
+ errors.push({
41165
+ errorCode: "max",
41166
+ payload: { current: value, expected: params.max },
41167
+ });
41168
+ }
41153
41169
  return {
41154
41170
  isValid: !isInvalid,
41155
- validationErrors: isInvalid ? [{ errorCode: "notNumeric" }] : [],
41171
+ validationErrors: errors,
41156
41172
  };
41157
41173
  };
41158
41174
  const fieldTextValidator = (item, selector, params) => {