@autofleet/sadot 1.6.18-beta.2 → 1.6.18-beta.21
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/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.cjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js +10 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs +8 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js +7 -0
- package/dist/_virtual/rolldown_runtime.cjs +43 -0
- package/dist/{chunk-DJulfCLt.js → _virtual/rolldown_runtime.js} +1 -2
- package/dist/api/index.cjs +12 -0
- package/dist/api/index.js +11 -0
- package/dist/api/v1/definition/index.cjs +113 -0
- package/dist/api/v1/definition/index.js +112 -0
- package/dist/api/v1/definition/validations.cjs +128 -0
- package/dist/api/v1/definition/validations.js +125 -0
- package/dist/api/v1/errors.cjs +14 -0
- package/dist/api/v1/errors.js +13 -0
- package/dist/api/v1/field-policies/index.cjs +104 -0
- package/dist/api/v1/field-policies/index.js +103 -0
- package/dist/api/v1/index.cjs +16 -0
- package/dist/api/v1/index.js +15 -0
- package/dist/api/v1/validator/index.cjs +132 -0
- package/dist/api/v1/validator/index.js +131 -0
- package/dist/api/v1/validator/validations.cjs +40 -0
- package/dist/api/v1/validator/validations.d.cts +22 -0
- package/dist/api/v1/validator/validations.d.ts +22 -0
- package/dist/api/v1/validator/validations.js +38 -0
- package/dist/errors/index.cjs +62 -0
- package/dist/errors/index.js +55 -0
- package/dist/events/index.cjs +52 -0
- package/dist/events/index.js +50 -0
- package/dist/hooks/enrich.cjs +175 -0
- package/dist/hooks/enrich.js +175 -0
- package/dist/hooks/find.cjs +22 -0
- package/dist/hooks/find.js +22 -0
- package/dist/hooks/hooks.cjs +310 -0
- package/dist/hooks/hooks.js +302 -0
- package/dist/hooks/index.cjs +3 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/utils/updateInstanceValues.cjs +27 -0
- package/dist/hooks/utils/updateInstanceValues.js +27 -0
- package/dist/index.cjs +48 -33508
- package/dist/index.d.cts +13 -396
- package/dist/index.d.ts +14 -394
- package/dist/index.js +21 -33435
- package/dist/init-state.cjs +56 -0
- package/dist/init-state.d.cts +35 -0
- package/dist/init-state.d.ts +35 -0
- package/dist/init-state.js +55 -0
- package/dist/mat-path-state.cjs +10 -0
- package/dist/mat-path-state.js +9 -0
- package/dist/migrations/001-create-core-tables.cjs +70 -0
- package/dist/migrations/001-create-core-tables.js +68 -0
- package/dist/migrations/002-create-custom-field-entries.cjs +27 -0
- package/dist/migrations/002-create-custom-field-entries.js +25 -0
- package/dist/migrations/003-create-custom-field-model-type-map.cjs +35 -0
- package/dist/migrations/003-create-custom-field-model-type-map.js +33 -0
- package/dist/migrations/004-create-field-policy-tables.cjs +29 -0
- package/dist/migrations/004-create-field-policy-tables.js +27 -0
- package/dist/migrations/005-add-entity-type-to-field-policies.cjs +20 -0
- package/dist/migrations/005-add-entity-type-to-field-policies.js +18 -0
- package/dist/migrations/index.cjs +94 -0
- package/dist/migrations/index.js +95 -0
- package/dist/models/CustomFieldDefinition.cjs +147 -0
- package/dist/models/CustomFieldDefinition.d.cts +40 -0
- package/dist/models/CustomFieldDefinition.d.ts +40 -0
- package/dist/models/CustomFieldDefinition.js +146 -0
- package/dist/models/CustomFieldEntries.cjs +71 -0
- package/dist/models/CustomFieldEntries.d.cts +15 -0
- package/dist/models/CustomFieldEntries.d.ts +15 -0
- package/dist/models/CustomFieldEntries.js +70 -0
- package/dist/models/CustomFieldModelTypeMap.cjs +62 -0
- package/dist/models/CustomFieldModelTypeMap.d.cts +14 -0
- package/dist/models/CustomFieldModelTypeMap.d.ts +14 -0
- package/dist/models/CustomFieldModelTypeMap.js +61 -0
- package/dist/models/CustomFieldValue.cjs +109 -0
- package/dist/models/CustomFieldValue.d.cts +20 -0
- package/dist/models/CustomFieldValue.d.ts +20 -0
- package/dist/models/CustomFieldValue.js +108 -0
- package/dist/models/CustomValidator.cjs +68 -0
- package/dist/models/CustomValidator.d.cts +18 -0
- package/dist/models/CustomValidator.d.ts +18 -0
- package/dist/models/CustomValidator.js +67 -0
- package/dist/models/FieldPolicy.cjs +54 -0
- package/dist/models/FieldPolicy.d.cts +25 -0
- package/dist/models/FieldPolicy.d.ts +25 -0
- package/dist/models/FieldPolicy.js +53 -0
- package/dist/models/index.cjs +163 -0
- package/dist/models/index.d.ts +11 -0
- package/dist/models/index.js +161 -0
- package/dist/models/tests/AssociatedTestModel.cjs +51 -0
- package/dist/models/tests/AssociatedTestModel.d.ts +2 -0
- package/dist/models/tests/AssociatedTestModel.js +50 -0
- package/dist/models/tests/TestModel.cjs +43 -0
- package/dist/models/tests/TestModel.d.ts +2 -0
- package/dist/models/tests/TestModel.js +42 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +35 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.d.ts +2 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +34 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +33 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.d.ts +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.js +32 -0
- package/dist/repository/definition.cjs +221 -0
- package/dist/repository/definition.js +212 -0
- package/dist/repository/entries.cjs +69 -0
- package/dist/repository/entries.js +67 -0
- package/dist/repository/field-policy.cjs +69 -0
- package/dist/repository/field-policy.d.cts +35 -0
- package/dist/repository/field-policy.d.ts +35 -0
- package/dist/repository/field-policy.js +59 -0
- package/dist/repository/utils/formatValues.cjs +14 -0
- package/dist/repository/utils/formatValues.js +14 -0
- package/dist/repository/validator.cjs +85 -0
- package/dist/repository/validator.js +78 -0
- package/dist/repository/value.cjs +77 -0
- package/dist/repository/value.js +76 -0
- package/dist/scopes/filter.cjs +56 -0
- package/dist/scopes/filter.d.cts +22 -0
- package/dist/scopes/filter.d.ts +22 -0
- package/dist/scopes/filter.js +54 -0
- package/dist/scopes/helpers/filter.helpers.cjs +152 -0
- package/dist/scopes/helpers/filter.helpers.d.cts +16 -0
- package/dist/scopes/helpers/filter.helpers.d.ts +16 -0
- package/dist/scopes/helpers/filter.helpers.js +147 -0
- package/dist/scopes/index.cjs +1 -0
- package/dist/scopes/index.js +3 -0
- package/dist/types/index.d.cts +75 -0
- package/dist/types/index.d.ts +76 -0
- package/dist/utils/constants/index.cjs +32 -0
- package/dist/utils/constants/index.d.cts +23 -0
- package/dist/utils/constants/index.d.ts +23 -0
- package/dist/utils/constants/index.js +29 -0
- package/dist/utils/db/index.cjs +15 -0
- package/dist/utils/db/index.js +14 -0
- package/dist/utils/helpers/index.cjs +23 -0
- package/dist/utils/helpers/index.d.cts +30 -0
- package/dist/utils/helpers/index.d.ts +30 -0
- package/dist/utils/helpers/index.js +21 -0
- package/dist/utils/init.cjs +115 -0
- package/dist/utils/init.js +111 -0
- package/dist/utils/logger/index.cjs +15 -0
- package/dist/utils/logger/index.js +12 -0
- package/dist/utils/scopeAttributes.cjs +12 -0
- package/dist/utils/scopeAttributes.js +11 -0
- package/dist/utils/validations/index.cjs +34 -0
- package/dist/utils/validations/index.js +32 -0
- package/dist/utils/validations/schema/custom-fields.cjs +9 -0
- package/dist/utils/validations/schema/custom-fields.d.cts +6 -0
- package/dist/utils/validations/schema/custom-fields.d.ts +6 -0
- package/dist/utils/validations/schema/custom-fields.js +7 -0
- package/dist/utils/validations/schema/validator-schema.cjs +102 -0
- package/dist/utils/validations/schema/validator-schema.js +99 -0
- package/dist/utils/validations/validators/index.cjs +45 -0
- package/dist/utils/validations/validators/index.js +42 -0
- package/dist/utils/validations/validators/multi-select-dropdown.validator.cjs +7 -0
- package/dist/utils/validations/validators/multi-select-dropdown.validator.js +7 -0
- package/dist/utils/validations/validators/multi-select-status.validator.cjs +10 -0
- package/dist/utils/validations/validators/multi-select-status.validator.js +10 -0
- package/dist/utils/validations/validators/multi-select.helpers.cjs +12 -0
- package/dist/utils/validations/validators/multi-select.helpers.js +10 -0
- package/dist/utils/validations/validators/select.validator.cjs +12 -0
- package/dist/utils/validations/validators/select.validator.js +10 -0
- package/dist/utils/validations/validators/status.validator.cjs +12 -0
- package/dist/utils/validations/validators/status.validator.js +10 -0
- package/package.json +4 -4
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_index = require('../../logger/index.cjs');
|
|
3
|
+
let _autofleet_errors = require("@autofleet/errors");
|
|
4
|
+
let ajv = require("ajv");
|
|
5
|
+
ajv = require_rolldown_runtime.__toESM(ajv);
|
|
6
|
+
let ajv_formats = require("ajv-formats");
|
|
7
|
+
ajv_formats = require_rolldown_runtime.__toESM(ajv_formats);
|
|
8
|
+
|
|
9
|
+
//#region src/utils/validations/schema/validator-schema.ts
|
|
10
|
+
const metaValidator = new ajv.default({
|
|
11
|
+
allErrors: true,
|
|
12
|
+
strict: false,
|
|
13
|
+
strictTypes: false,
|
|
14
|
+
$data: true
|
|
15
|
+
});
|
|
16
|
+
(0, ajv_formats.default)(metaValidator);
|
|
17
|
+
/**
|
|
18
|
+
* Schema for validating JSON Schema objects in custom validators
|
|
19
|
+
* This is a meta-schema to ensure that custom validator schemas are valid Ajv schemas
|
|
20
|
+
*/
|
|
21
|
+
const validatorMetaSchema = {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
type: {
|
|
25
|
+
type: "string",
|
|
26
|
+
enum: ["object"]
|
|
27
|
+
},
|
|
28
|
+
properties: {
|
|
29
|
+
type: "object",
|
|
30
|
+
properties: {
|
|
31
|
+
before: {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
type: {
|
|
35
|
+
type: "string",
|
|
36
|
+
enum: ["object"]
|
|
37
|
+
},
|
|
38
|
+
properties: { type: "object" }
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
after: {
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {
|
|
44
|
+
type: {
|
|
45
|
+
type: "string",
|
|
46
|
+
enum: ["object"]
|
|
47
|
+
},
|
|
48
|
+
properties: { type: "object" }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
required: {
|
|
54
|
+
type: "array",
|
|
55
|
+
items: { type: "string" }
|
|
56
|
+
},
|
|
57
|
+
if: { type: "object" },
|
|
58
|
+
then: { type: "object" },
|
|
59
|
+
else: { type: "object" }
|
|
60
|
+
},
|
|
61
|
+
required: ["type", "properties"]
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Validates that a given schema is a valid Ajv schema
|
|
65
|
+
* This function is used to validate schemas passed to custom validators
|
|
66
|
+
*
|
|
67
|
+
* @param schema The schema to validate
|
|
68
|
+
* @returns true if valid, throws an error if invalid
|
|
69
|
+
*/
|
|
70
|
+
const validateValidatorSchema = (schema) => {
|
|
71
|
+
try {
|
|
72
|
+
const validateMetaSchema = metaValidator.compile(validatorMetaSchema);
|
|
73
|
+
if (!validateMetaSchema(schema)) {
|
|
74
|
+
const errorDetails = validateMetaSchema.errors?.map((err) => `${err.instancePath || ""} ${err.message || "Invalid schema structure"}`).join(", ");
|
|
75
|
+
require_index.default.error("Invalid validator schema structure", {
|
|
76
|
+
errors: validateMetaSchema.errors,
|
|
77
|
+
schema
|
|
78
|
+
});
|
|
79
|
+
throw new _autofleet_errors.BadRequest([/* @__PURE__ */ new Error(`Invalid validator schema structure: ${errorDetails}`)], ["Invalid validator schema structure"]);
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
metaValidator.compile(schema);
|
|
83
|
+
return true;
|
|
84
|
+
} catch (compileError) {
|
|
85
|
+
require_index.default.error("Failed to compile validator schema", {
|
|
86
|
+
error: compileError,
|
|
87
|
+
schema
|
|
88
|
+
});
|
|
89
|
+
throw new _autofleet_errors.BadRequest([/* @__PURE__ */ new Error(`Failed to compile validator schema: ${compileError.message}`)], ["Invalid validator schema"]);
|
|
90
|
+
}
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (error instanceof _autofleet_errors.BadRequest) throw error;
|
|
93
|
+
require_index.default.error("Error validating validator schema", {
|
|
94
|
+
error,
|
|
95
|
+
schema
|
|
96
|
+
});
|
|
97
|
+
throw new _autofleet_errors.BadRequest([/* @__PURE__ */ new Error(`Error validating validator schema: ${error.message}`)], ["Invalid validator schema"]);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
exports.validateValidatorSchema = validateValidatorSchema;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import logger_default from "../../logger/index.js";
|
|
2
|
+
import { BadRequest } from "@autofleet/errors";
|
|
3
|
+
import Ajv from "ajv";
|
|
4
|
+
import addFormats from "ajv-formats";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/validations/schema/validator-schema.ts
|
|
7
|
+
const metaValidator = new Ajv({
|
|
8
|
+
allErrors: true,
|
|
9
|
+
strict: false,
|
|
10
|
+
strictTypes: false,
|
|
11
|
+
$data: true
|
|
12
|
+
});
|
|
13
|
+
addFormats(metaValidator);
|
|
14
|
+
/**
|
|
15
|
+
* Schema for validating JSON Schema objects in custom validators
|
|
16
|
+
* This is a meta-schema to ensure that custom validator schemas are valid Ajv schemas
|
|
17
|
+
*/
|
|
18
|
+
const validatorMetaSchema = {
|
|
19
|
+
type: "object",
|
|
20
|
+
properties: {
|
|
21
|
+
type: {
|
|
22
|
+
type: "string",
|
|
23
|
+
enum: ["object"]
|
|
24
|
+
},
|
|
25
|
+
properties: {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
before: {
|
|
29
|
+
type: "object",
|
|
30
|
+
properties: {
|
|
31
|
+
type: {
|
|
32
|
+
type: "string",
|
|
33
|
+
enum: ["object"]
|
|
34
|
+
},
|
|
35
|
+
properties: { type: "object" }
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
after: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
type: {
|
|
42
|
+
type: "string",
|
|
43
|
+
enum: ["object"]
|
|
44
|
+
},
|
|
45
|
+
properties: { type: "object" }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
required: {
|
|
51
|
+
type: "array",
|
|
52
|
+
items: { type: "string" }
|
|
53
|
+
},
|
|
54
|
+
if: { type: "object" },
|
|
55
|
+
then: { type: "object" },
|
|
56
|
+
else: { type: "object" }
|
|
57
|
+
},
|
|
58
|
+
required: ["type", "properties"]
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Validates that a given schema is a valid Ajv schema
|
|
62
|
+
* This function is used to validate schemas passed to custom validators
|
|
63
|
+
*
|
|
64
|
+
* @param schema The schema to validate
|
|
65
|
+
* @returns true if valid, throws an error if invalid
|
|
66
|
+
*/
|
|
67
|
+
const validateValidatorSchema = (schema) => {
|
|
68
|
+
try {
|
|
69
|
+
const validateMetaSchema = metaValidator.compile(validatorMetaSchema);
|
|
70
|
+
if (!validateMetaSchema(schema)) {
|
|
71
|
+
const errorDetails = validateMetaSchema.errors?.map((err) => `${err.instancePath || ""} ${err.message || "Invalid schema structure"}`).join(", ");
|
|
72
|
+
logger_default.error("Invalid validator schema structure", {
|
|
73
|
+
errors: validateMetaSchema.errors,
|
|
74
|
+
schema
|
|
75
|
+
});
|
|
76
|
+
throw new BadRequest([/* @__PURE__ */ new Error(`Invalid validator schema structure: ${errorDetails}`)], ["Invalid validator schema structure"]);
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
metaValidator.compile(schema);
|
|
80
|
+
return true;
|
|
81
|
+
} catch (compileError) {
|
|
82
|
+
logger_default.error("Failed to compile validator schema", {
|
|
83
|
+
error: compileError,
|
|
84
|
+
schema
|
|
85
|
+
});
|
|
86
|
+
throw new BadRequest([/* @__PURE__ */ new Error(`Failed to compile validator schema: ${compileError.message}`)], ["Invalid validator schema"]);
|
|
87
|
+
}
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (error instanceof BadRequest) throw error;
|
|
90
|
+
logger_default.error("Error validating validator schema", {
|
|
91
|
+
error,
|
|
92
|
+
schema
|
|
93
|
+
});
|
|
94
|
+
throw new BadRequest([/* @__PURE__ */ new Error(`Error validating validator schema: ${error.message}`)], ["Invalid validator schema"]);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
export { validateValidatorSchema };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_index = require('../../constants/index.cjs');
|
|
3
|
+
const require_select_validator = require('./select.validator.cjs');
|
|
4
|
+
const require_status_validator = require('./status.validator.cjs');
|
|
5
|
+
const require_multi_select_status_validator = require('./multi-select-status.validator.cjs');
|
|
6
|
+
const require_multi_select_dropdown_validator = require('./multi-select-dropdown.validator.cjs');
|
|
7
|
+
let joi = require("joi");
|
|
8
|
+
joi = require_rolldown_runtime.__toESM(joi);
|
|
9
|
+
|
|
10
|
+
//#region src/utils/validations/validators/index.ts
|
|
11
|
+
/**
|
|
12
|
+
* Custom field types that must have custom validation.
|
|
13
|
+
* TODO: remove this after moving to schema-based validation
|
|
14
|
+
*/
|
|
15
|
+
const CustomValidationTypes = {
|
|
16
|
+
[require_index.CustomFieldDefinitionType.SELECT]: require_index.CustomFieldDefinitionType.SELECT,
|
|
17
|
+
[require_index.CustomFieldDefinitionType.STATUS]: require_index.CustomFieldDefinitionType.STATUS,
|
|
18
|
+
[require_index.CustomFieldDefinitionType.MULTI_SELECT_STATUS]: require_index.CustomFieldDefinitionType.MULTI_SELECT_STATUS,
|
|
19
|
+
[require_index.CustomFieldDefinitionType.MULTI_SELECT_DROPDOWN]: require_index.CustomFieldDefinitionType.MULTI_SELECT_DROPDOWN
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Validators for custom fields
|
|
23
|
+
*/
|
|
24
|
+
const validators = {
|
|
25
|
+
[require_index.CustomFieldDefinitionType.SELECT]: require_select_validator.validateSelect,
|
|
26
|
+
[require_index.CustomFieldDefinitionType.STATUS]: require_status_validator.validateStatus,
|
|
27
|
+
[require_index.CustomFieldDefinitionType.MULTI_SELECT_STATUS]: require_multi_select_status_validator.validateMultiSelectStatus,
|
|
28
|
+
[require_index.CustomFieldDefinitionType.MULTI_SELECT_DROPDOWN]: require_multi_select_dropdown_validator.validateMultiSelectDropdown,
|
|
29
|
+
[require_index.CustomFieldDefinitionType.TEXT]: (value) => joi.default.string().min(0).validate(value),
|
|
30
|
+
[require_index.CustomFieldDefinitionType.NUMBER]: (value) => joi.default.number().strict(true).validate(value),
|
|
31
|
+
[require_index.CustomFieldDefinitionType.BOOLEAN]: (value) => joi.default.boolean().strict().validate(value),
|
|
32
|
+
[require_index.CustomFieldDefinitionType.DATE]: (value) => joi.default.date().validate(value),
|
|
33
|
+
[require_index.CustomFieldDefinitionType.DATETIME]: (value) => joi.default.date().validate(value),
|
|
34
|
+
[require_index.CustomFieldDefinitionType.IMAGE]: (value) => joi.default.array().min(1).unique().items(joi.default.string().uri()).validate(value),
|
|
35
|
+
[require_index.CustomFieldDefinitionType.FILE]: (value) => joi.default.array().min(1).unique().items(joi.default.object({
|
|
36
|
+
name: joi.default.string().required(),
|
|
37
|
+
type: joi.default.string(),
|
|
38
|
+
size: joi.default.string(),
|
|
39
|
+
addedBy: joi.default.string().uuid()
|
|
40
|
+
})).validate(value)
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
exports.CustomValidationTypes = CustomValidationTypes;
|
|
45
|
+
exports.validators = validators;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CustomFieldDefinitionType } from "../../constants/index.js";
|
|
2
|
+
import { validateSelect } from "./select.validator.js";
|
|
3
|
+
import { validateStatus } from "./status.validator.js";
|
|
4
|
+
import { validateMultiSelectStatus } from "./multi-select-status.validator.js";
|
|
5
|
+
import { validateMultiSelectDropdown } from "./multi-select-dropdown.validator.js";
|
|
6
|
+
import Joi from "joi";
|
|
7
|
+
|
|
8
|
+
//#region src/utils/validations/validators/index.ts
|
|
9
|
+
/**
|
|
10
|
+
* Custom field types that must have custom validation.
|
|
11
|
+
* TODO: remove this after moving to schema-based validation
|
|
12
|
+
*/
|
|
13
|
+
const CustomValidationTypes = {
|
|
14
|
+
[CustomFieldDefinitionType.SELECT]: CustomFieldDefinitionType.SELECT,
|
|
15
|
+
[CustomFieldDefinitionType.STATUS]: CustomFieldDefinitionType.STATUS,
|
|
16
|
+
[CustomFieldDefinitionType.MULTI_SELECT_STATUS]: CustomFieldDefinitionType.MULTI_SELECT_STATUS,
|
|
17
|
+
[CustomFieldDefinitionType.MULTI_SELECT_DROPDOWN]: CustomFieldDefinitionType.MULTI_SELECT_DROPDOWN
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Validators for custom fields
|
|
21
|
+
*/
|
|
22
|
+
const validators = {
|
|
23
|
+
[CustomFieldDefinitionType.SELECT]: validateSelect,
|
|
24
|
+
[CustomFieldDefinitionType.STATUS]: validateStatus,
|
|
25
|
+
[CustomFieldDefinitionType.MULTI_SELECT_STATUS]: validateMultiSelectStatus,
|
|
26
|
+
[CustomFieldDefinitionType.MULTI_SELECT_DROPDOWN]: validateMultiSelectDropdown,
|
|
27
|
+
[CustomFieldDefinitionType.TEXT]: (value) => Joi.string().min(0).validate(value),
|
|
28
|
+
[CustomFieldDefinitionType.NUMBER]: (value) => Joi.number().strict(true).validate(value),
|
|
29
|
+
[CustomFieldDefinitionType.BOOLEAN]: (value) => Joi.boolean().strict().validate(value),
|
|
30
|
+
[CustomFieldDefinitionType.DATE]: (value) => Joi.date().validate(value),
|
|
31
|
+
[CustomFieldDefinitionType.DATETIME]: (value) => Joi.date().validate(value),
|
|
32
|
+
[CustomFieldDefinitionType.IMAGE]: (value) => Joi.array().min(1).unique().items(Joi.string().uri()).validate(value),
|
|
33
|
+
[CustomFieldDefinitionType.FILE]: (value) => Joi.array().min(1).unique().items(Joi.object({
|
|
34
|
+
name: Joi.string().required(),
|
|
35
|
+
type: Joi.string(),
|
|
36
|
+
size: Joi.string(),
|
|
37
|
+
addedBy: Joi.string().uuid()
|
|
38
|
+
})).validate(value)
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { CustomValidationTypes, validators };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_multi_select_helpers = require('./multi-select.helpers.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/utils/validations/validators/multi-select-dropdown.validator.ts
|
|
4
|
+
const validateMultiSelectDropdown = (value, options) => require_multi_select_helpers.validateMultiSelect(value, options ?? []);
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.validateMultiSelectDropdown = validateMultiSelectDropdown;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { validateMultiSelect } from "./multi-select.helpers.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/validations/validators/multi-select-dropdown.validator.ts
|
|
4
|
+
const validateMultiSelectDropdown = (value, options) => validateMultiSelect(value, options ?? []);
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { validateMultiSelectDropdown };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const require_multi_select_helpers = require('./multi-select.helpers.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/utils/validations/validators/multi-select-status.validator.ts
|
|
4
|
+
/**
|
|
5
|
+
* Validate that the value is an array containing only the allowed multi-select values
|
|
6
|
+
*/
|
|
7
|
+
const validateMultiSelectStatus = (value, multiSelectOptions) => require_multi_select_helpers.validateMultiSelect(value, (multiSelectOptions ?? []).map((option) => option.value));
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.validateMultiSelectStatus = validateMultiSelectStatus;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { validateMultiSelect } from "./multi-select.helpers.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/validations/validators/multi-select-status.validator.ts
|
|
4
|
+
/**
|
|
5
|
+
* Validate that the value is an array containing only the allowed multi-select values
|
|
6
|
+
*/
|
|
7
|
+
const validateMultiSelectStatus = (value, multiSelectOptions) => validateMultiSelect(value, (multiSelectOptions ?? []).map((option) => option.value));
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { validateMultiSelectStatus };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let joi = require("joi");
|
|
3
|
+
joi = require_rolldown_runtime.__toESM(joi);
|
|
4
|
+
|
|
5
|
+
//#region src/utils/validations/validators/multi-select.helpers.ts
|
|
6
|
+
const validateMultiSelect = (value, allowedValues) => {
|
|
7
|
+
if (!allowedValues.length) return joi.default.valid(null).messages({ "any.only": "custom field definition has no allowed values" }).validate(value);
|
|
8
|
+
return joi.default.array().allow(null).items(joi.default.string().valid(...allowedValues)).unique().validate(value);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.validateMultiSelect = validateMultiSelect;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Joi from "joi";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/validations/validators/multi-select.helpers.ts
|
|
4
|
+
const validateMultiSelect = (value, allowedValues) => {
|
|
5
|
+
if (!allowedValues.length) return Joi.valid(null).messages({ "any.only": "custom field definition has no allowed values" }).validate(value);
|
|
6
|
+
return Joi.array().allow(null).items(Joi.string().valid(...allowedValues)).unique().validate(value);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { validateMultiSelect };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let joi = require("joi");
|
|
3
|
+
joi = require_rolldown_runtime.__toESM(joi);
|
|
4
|
+
|
|
5
|
+
//#region src/utils/validations/validators/select.validator.ts
|
|
6
|
+
/**
|
|
7
|
+
* Validate that the value is one of the select values
|
|
8
|
+
*/
|
|
9
|
+
const validateSelect = (value, selectValues) => joi.default.string().allow(null).valid(...selectValues).validate(value);
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.validateSelect = validateSelect;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Joi from "joi";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/validations/validators/select.validator.ts
|
|
4
|
+
/**
|
|
5
|
+
* Validate that the value is one of the select values
|
|
6
|
+
*/
|
|
7
|
+
const validateSelect = (value, selectValues) => Joi.string().allow(null).valid(...selectValues).validate(value);
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { validateSelect };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let joi = require("joi");
|
|
3
|
+
joi = require_rolldown_runtime.__toESM(joi);
|
|
4
|
+
|
|
5
|
+
//#region src/utils/validations/validators/status.validator.ts
|
|
6
|
+
/**
|
|
7
|
+
* Validate that the value is one of the status values
|
|
8
|
+
*/
|
|
9
|
+
const validateStatus = (value, statusValues) => joi.default.string().allow(null).valid(...statusValues.map((statusValue) => statusValue.value)).validate(value);
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.validateStatus = validateStatus;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Joi from "joi";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/validations/validators/status.validator.ts
|
|
4
|
+
/**
|
|
5
|
+
* Validate that the value is one of the status values
|
|
6
|
+
*/
|
|
7
|
+
const validateStatus = (value, statusValues) => Joi.string().allow(null).valid(...statusValues.map((statusValue) => statusValue.value)).validate(value);
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { validateStatus };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/sadot",
|
|
3
|
-
"version": "1.6.18-beta.
|
|
3
|
+
"version": "1.6.18-beta.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"express": "^4.21.2",
|
|
54
54
|
"npm-watch": "^0.11.0",
|
|
55
55
|
"supertest": "^7.0.0",
|
|
56
|
-
"@autofleet/errors": "^3.3.7",
|
|
57
|
-
"@autofleet/zehut": "^4.13.3",
|
|
58
56
|
"@autofleet/node-common": "^4.3.22",
|
|
59
|
-
"@autofleet/logger": "^4.7.0"
|
|
57
|
+
"@autofleet/logger": "^4.7.0",
|
|
58
|
+
"@autofleet/errors": "^3.3.7",
|
|
59
|
+
"@autofleet/zehut": "^4.13.4"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@autofleet/errors": "^3",
|