@punks/backend-entity-manager 0.0.496 → 0.0.499

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