@autofleet/sadot 0.6.4 → 0.6.6
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/api/v1/definition/validations.js +21 -4
- package/dist/hooks/create.d.ts +1 -1
- package/dist/hooks/enrich.d.ts +1 -1
- package/dist/hooks/update.d.ts +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -4
- package/dist/models/CustomFieldDefinition.d.ts +1 -1
- package/dist/models/CustomFieldDefinition.js +11 -6
- package/dist/models/CustomFieldValue.js +3 -8
- package/dist/repository/definition.d.ts +2 -2
- package/dist/repository/value.d.ts +2 -2
- package/dist/scopes/filter.d.ts +2 -2
- package/dist/scopes/filter.js +18 -11
- package/dist/tests/mocks/definition.mock.d.ts +3 -3
- package/dist/tests/mocks/definition.mock.js +8 -10
- package/dist/types/index.d.ts +2 -2
- package/dist/utils/constants/index.d.ts +13 -0
- package/dist/utils/constants/index.js +15 -2
- package/dist/utils/helpers/index.d.ts +3 -3
- package/dist/utils/helpers/index.js +3 -3
- package/dist/utils/validations/index.d.ts +2 -2
- package/dist/utils/validations/index.js +15 -15
- package/dist/utils/validations/{custom-fields.js → schema/custom-fields.js} +0 -1
- package/dist/utils/validations/type.d.ts +10 -14
- package/dist/utils/validations/type.js +0 -48
- package/dist/utils/validations/validators/index.d.ts +14 -0
- package/dist/utils/validations/validators/index.js +33 -0
- package/dist/utils/validations/validators/select.validator.d.ts +5 -0
- package/dist/utils/validations/validators/select.validator.js +9 -0
- package/dist/utils/validations/validators/status.validator.d.ts +12 -0
- package/dist/utils/validations/validators/status.validator.js +9 -0
- package/package.json +9 -8
- package/src/api/v1/definition/index.ts +1 -1
- package/src/api/v1/definition/validations.ts +20 -1
- package/src/hooks/create.ts +1 -1
- package/src/hooks/enrich.ts +4 -4
- package/src/hooks/update.ts +1 -1
- package/src/index.ts +2 -3
- package/src/models/CustomFieldDefinition.ts +7 -5
- package/src/models/CustomFieldValue.ts +1 -5
- package/src/repository/definition.ts +2 -5
- package/src/repository/value.ts +2 -2
- package/src/scopes/filter.ts +19 -13
- package/src/tests/functional/searching/index.ts +1 -1
- package/src/tests/mocks/definition.mock.ts +6 -8
- package/src/types/index.ts +2 -2
- package/src/utils/constants/index.ts +14 -1
- package/src/utils/helpers/index.ts +5 -5
- package/src/utils/init.ts +1 -1
- package/src/utils/validations/index.ts +18 -15
- package/src/utils/validations/{custom-fields.ts → schema/custom-fields.ts} +0 -1
- package/src/utils/validations/type.ts +14 -40
- package/src/utils/validations/validators/index.ts +31 -0
- package/src/utils/validations/validators/select.validator.ts +11 -0
- package/src/utils/validations/validators/status.validator.ts +18 -0
- package/dist/utils/validations/custom.d.ts +0 -15
- package/dist/utils/validations/custom.js +0 -42
- package/dist/utils/validations/validators.d.ts +0 -12
- package/dist/utils/validations/validators.js +0 -33
- package/src/utils/validations/custom.ts +0 -39
- package/src/utils/validations/validators.ts +0 -34
- /package/dist/utils/validations/{custom-fields.d.ts → schema/custom-fields.d.ts} +0 -0
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CustomValidations = void 0;
|
|
4
|
-
// eslint-disable-next-line no-shadow
|
|
5
|
-
var CustomValidations;
|
|
6
|
-
(function (CustomValidations) {
|
|
7
|
-
CustomValidations["SELECT"] = "select";
|
|
8
|
-
CustomValidations["RANGE"] = "between";
|
|
9
|
-
})(CustomValidations = exports.CustomValidations || (exports.CustomValidations = {}));
|
|
10
|
-
/**
|
|
11
|
-
* Validate {@link CustomValidations.ENUM Enum}
|
|
12
|
-
*/
|
|
13
|
-
const validateEnum = (value, enumValues) => (Array.isArray(enumValues)
|
|
14
|
-
&& enumValues.length > 0
|
|
15
|
-
&& enumValues.includes(value));
|
|
16
|
-
/**
|
|
17
|
-
* Validate {@link CustomValidations.RANGE Range}
|
|
18
|
-
*/
|
|
19
|
-
const validateRange = (value, range) => {
|
|
20
|
-
const [min, max] = range;
|
|
21
|
-
if (min === undefined || max === undefined) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
return value >= range.min && value <= range.max;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Validators for custom fields
|
|
28
|
-
*/
|
|
29
|
-
const validators = {
|
|
30
|
-
[CustomValidations.SELECT]: validateEnum,
|
|
31
|
-
[CustomValidations.RANGE]: validateRange,
|
|
32
|
-
};
|
|
33
|
-
exports.default = validators;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-shadow */
|
|
2
|
-
import logger from '../logger';
|
|
3
|
-
import { CustomFieldDefinitionType } from './type';
|
|
4
|
-
import validators from './validators';
|
|
5
|
-
|
|
6
|
-
export const mustHaveCustomValidation = {
|
|
7
|
-
[CustomFieldDefinitionType.SELECT]: true,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Validates the given validations object against the supported field types and their validators.
|
|
12
|
-
* @return true if the validation is valid, false otherwise.
|
|
13
|
-
*/
|
|
14
|
-
export const validateValidation = (valueType, validation) => {
|
|
15
|
-
if (!validation) {
|
|
16
|
-
if (mustHaveCustomValidation[valueType]) {
|
|
17
|
-
logger.error(`No custom validation for custom field type ${valueType} found`);
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Validates the given value against the custom validation rules for the specified field type.
|
|
27
|
-
* If no custom validation rules are provided, it falls back to the default validation.
|
|
28
|
-
* @returns true if the value is valid according to the validation rules, false otherwise.
|
|
29
|
-
*/
|
|
30
|
-
const customValidation = (value, valueType, validation) => {
|
|
31
|
-
const validator = validators?.[valueType];
|
|
32
|
-
if (!validation || !validator) {
|
|
33
|
-
return validateValidation(valueType, validation);
|
|
34
|
-
}
|
|
35
|
-
// Always allow null values
|
|
36
|
-
return value === null || validator(value, validation);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export default customValidation;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line no-shadow
|
|
2
|
-
export enum CustomValidations {
|
|
3
|
-
SELECT = 'select',
|
|
4
|
-
RANGE = 'between'
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
type Validator = (value, validation) => boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Validate {@link CustomValidations.ENUM Enum}
|
|
10
|
-
*/
|
|
11
|
-
const validateEnum: Validator = (value, enumValues) => (Array.isArray(enumValues)
|
|
12
|
-
&& enumValues.length > 0
|
|
13
|
-
&& enumValues.includes(value)
|
|
14
|
-
);
|
|
15
|
-
/**
|
|
16
|
-
* Validate {@link CustomValidations.RANGE Range}
|
|
17
|
-
*/
|
|
18
|
-
const validateRange: Validator = (value, range) => {
|
|
19
|
-
const [min, max] = range;
|
|
20
|
-
if (min === undefined || max === undefined) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
return value >= range.min && value <= range.max;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Validators for custom fields
|
|
28
|
-
*/
|
|
29
|
-
const validators: { [key: string]: Validator } = {
|
|
30
|
-
[CustomValidations.SELECT]: validateEnum,
|
|
31
|
-
[CustomValidations.RANGE]: validateRange,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export default validators;
|
|
File without changes
|