definition-generator-framework 1.3.10 → 1.3.12
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/helpers/validator/custom-validators/reference.custom-validator.d.ts +3 -2
- package/dist/helpers/validator/custom-validators/reference.custom-validator.js +19 -2
- package/dist/helpers/validator/custom-validators/reference.custom-validator.js.map +1 -1
- package/dist/helpers/validator/joi-custom-validators.d.ts +4 -1
- package/dist/helpers/validator/joi-custom-validators.js +2 -2
- package/dist/helpers/validator/joi-custom-validators.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import Joi, { ErrorReport } from 'joi';
|
|
2
|
-
import { CustomValidator } from '../joi-custom-validators';
|
|
2
|
+
import { CustomValidator, ReferenceCustomValidatorOptions } from '../joi-custom-validators';
|
|
3
3
|
import { DefinitionComponentClassType } from '../../../framework/definition-component';
|
|
4
4
|
export declare class ReferenceCustomValidator implements CustomValidator {
|
|
5
|
+
private options?;
|
|
5
6
|
readonly regex: RegExp;
|
|
6
7
|
readonly validate: (value: string, helpers: Joi.CustomHelpers) => any | ErrorReport;
|
|
7
8
|
readonly handleError: (error: Joi.ErrorReport) => void;
|
|
8
9
|
private referencedComponents;
|
|
9
|
-
constructor(definitionComponentClasses: DefinitionComponentClassType<any> | DefinitionComponentClassType<any>[]);
|
|
10
|
+
constructor(definitionComponentClasses: DefinitionComponentClassType<any> | DefinitionComponentClassType<any>[], options?: ReferenceCustomValidatorOptions | undefined);
|
|
10
11
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReferenceCustomValidator = void 0;
|
|
4
|
+
const helpers_lib_1 = require("helpers-lib");
|
|
4
5
|
const common_functions_1 = require("../../common-functions/common-functions");
|
|
5
6
|
const custom_validator_helper_1 = require("../custom-validator-helper/custom-validator.helper");
|
|
6
|
-
const
|
|
7
|
+
const definition_store_1 = require("../../../framework/definition-store");
|
|
7
8
|
class ReferenceCustomValidator {
|
|
8
|
-
constructor(definitionComponentClasses) {
|
|
9
|
+
constructor(definitionComponentClasses, options) {
|
|
10
|
+
this.options = options;
|
|
9
11
|
this.regex = /^[a-z]+([a-zA-Z0-9]+)*$/;
|
|
10
12
|
this.validate = (value, helpers) => {
|
|
11
13
|
let validationState = custom_validator_helper_1.CustomValidatorHelper.getValidationState(helpers);
|
|
@@ -16,6 +18,18 @@ class ReferenceCustomValidator {
|
|
|
16
18
|
}
|
|
17
19
|
else {
|
|
18
20
|
let definitionName = common_functions_1.CommonFunctions.decorateDefinitionName(value, referencedComponent.name);
|
|
21
|
+
if (this.options?.propertyShouldExist) {
|
|
22
|
+
let propertyShouldExist = helpers_lib_1.Comparator.isArray(this.options.propertyShouldExist)
|
|
23
|
+
? this.options.propertyShouldExist
|
|
24
|
+
: [this.options.propertyShouldExist];
|
|
25
|
+
let definition = definition_store_1.DefinitionStore.getDefinition(referencedComponent.component, definitionName);
|
|
26
|
+
propertyShouldExist.forEach(propertyPath => {
|
|
27
|
+
let property = helpers_lib_1.JsonHelper.deepFind(definition, propertyPath);
|
|
28
|
+
if (!property || (helpers_lib_1.Comparator.isArray(property) && property.length === 0)) {
|
|
29
|
+
return helpers.error('any.noProperty');
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
19
33
|
return definitionName;
|
|
20
34
|
}
|
|
21
35
|
}
|
|
@@ -32,6 +46,9 @@ class ReferenceCustomValidator {
|
|
|
32
46
|
.map(component => component.name)
|
|
33
47
|
.join(', ')}"`;
|
|
34
48
|
}
|
|
49
|
+
else if (error.code === 'any.noProperty') {
|
|
50
|
+
error.message = `Property "${error.state.path}" does not exist in definition "${error.value}"`;
|
|
51
|
+
}
|
|
35
52
|
};
|
|
36
53
|
this.referencedComponents = [];
|
|
37
54
|
let componentClasses = helpers_lib_1.Comparator.isArray(definitionComponentClasses)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reference.custom-validator.js","sourceRoot":"","sources":["../../../../src/helpers/validator/custom-validators/reference.custom-validator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"reference.custom-validator.js","sourceRoot":"","sources":["../../../../src/helpers/validator/custom-validators/reference.custom-validator.ts"],"names":[],"mappings":";;;AACA,6CAAqD;AAErD,8EAA0E;AAE1E,gGAA2F;AAE3F,0EAAsE;AAEtE,MAAa,wBAAwB;IAmDnC,YACE,0BAAmG,EAC3F,OAAyC;QAAzC,YAAO,GAAP,OAAO,CAAkC;QApD1C,UAAK,GAAG,yBAAyB,CAAC;QAElC,aAAQ,GAAG,CAAC,KAAa,EAAE,OAA0B,EAAqB,EAAE;YACnF,IAAI,eAAe,GAAG,+CAAqB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;YACxE,IAAI,eAAe,KAAK,OAAO,EAAE,CAAC;gBAChC,IAAI,mBAAmB,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CACnE,+CAAqB,CAAC,kBAAkB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CACpE,CAAC;gBACF,IAAI,CAAC,mBAAmB,EAAE,CAAC;oBACzB,OAAO,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;gBACrC,CAAC;qBAAM,CAAC;oBACN,IAAI,cAAc,GAAG,kCAAe,CAAC,sBAAsB,CAAC,KAAK,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;oBAE7F,IAAI,IAAI,CAAC,OAAO,EAAE,mBAAmB,EAAE,CAAC;wBACtC,IAAI,mBAAmB,GAAG,wBAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC;4BAC5E,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB;4BAClC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,mBAA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AC,OAAO,GAAG,aAAa,KAAK,CAAC,KAAK,CAAC,IAAI,mCAAmC,KAAK,CAAC,KAAK,GAAG,CAAC;YACjG,CAAC;QACH,CAAC,CAAC;QAEM,yBAAoB,GAAqE,EAAE,CAAC;QAMlG,IAAI,gBAAgB,GAAG,wBAAU,CAAC,OAAO,CAAC,0BAA0B,CAAC;YACnE,CAAC,CAAC,0BAA0B;YAC5B,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC;QAEjC,IAAI,CAAC,oBAAoB,GAAG,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;YAC7D,IAAI,EAAE,+CAAqB,CAAC,0BAA0B,CAAC,SAAS,CAAC;YACjE,SAAS;SACV,CAAC,CAAC,CAAC;IACN,CAAC;CACF;AAhED,4DAgEC"}
|
|
@@ -6,12 +6,15 @@ export interface CustomValidator {
|
|
|
6
6
|
readonly validate: Joi.CustomValidator<any, any>;
|
|
7
7
|
readonly handleError: (error: Joi.ErrorReport) => void;
|
|
8
8
|
}
|
|
9
|
+
export interface ReferenceCustomValidatorOptions {
|
|
10
|
+
propertyShouldExist?: string | string[];
|
|
11
|
+
}
|
|
9
12
|
declare module 'joi' {
|
|
10
13
|
interface StringSchema {
|
|
11
14
|
uniqueNameGroup(definitionComponentClass: DefinitionComponentClassType<any>): Joi.StringSchema;
|
|
12
15
|
path(): Joi.StringSchema;
|
|
13
16
|
image(): Joi.StringSchema;
|
|
14
|
-
reference(definitionComponentClass: DefinitionComponentClassType<any> | DefinitionComponentClassType<any>[]): Joi.StringSchema;
|
|
17
|
+
reference(definitionComponentClass: DefinitionComponentClassType<any> | DefinitionComponentClassType<any>[], options?: ReferenceCustomValidatorOptions): Joi.StringSchema;
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
export declare class JoiCustomValidators {
|
|
@@ -47,8 +47,8 @@ class JoiCustomValidators {
|
|
|
47
47
|
return JoiCustomValidators.defineCustomValidator(this, imageCustomValidator);
|
|
48
48
|
};
|
|
49
49
|
// @ts-ignore
|
|
50
|
-
Joi.string().__proto__.reference = function (definitionComponentClasses) {
|
|
51
|
-
let referenceCustomValidator = new reference_custom_validator_1.ReferenceCustomValidator(definitionComponentClasses);
|
|
50
|
+
Joi.string().__proto__.reference = function (definitionComponentClasses, options) {
|
|
51
|
+
let referenceCustomValidator = new reference_custom_validator_1.ReferenceCustomValidator(definitionComponentClasses, options);
|
|
52
52
|
return JoiCustomValidators.defineCustomValidator(this, referenceCustomValidator);
|
|
53
53
|
};
|
|
54
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"joi-custom-validators.js","sourceRoot":"","sources":["../../../src/helpers/validator/joi-custom-validators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA2B;AAG3B,qFAAgF;AAChF,+GAAwG;AACxG,uFAAkF;AAClF,+FAA0F;
|
|
1
|
+
{"version":3,"file":"joi-custom-validators.js","sourceRoot":"","sources":["../../../src/helpers/validator/joi-custom-validators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA2B;AAG3B,qFAAgF;AAChF,+GAAwG;AACxG,uFAAkF;AAClF,+FAA0F;AAyB1F,MAAa,mBAAmB;IAC9B,MAAM,CAAC,QAAQ,CAAC,EAAc;QAC5B,aAAa;QACb,GAAG,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,eAAe,GAAG,UAAU,wBAA2D;YAC5G,IAAI,8BAA8B,GAAG,IAAI,mEAA8B,CAAC,wBAAwB,CAAC,CAAC;YAClG,OAAO,mBAAmB,CAAC,qBAAqB,CAAC,IAAI,EAAE,8BAA8B,CAAC,CAAC;QACzF,CAAC,CAAC;QACF,aAAa;QACb,GAAG,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,GAAG;YAC5B,IAAI,mBAAmB,GAAG,IAAI,2CAAmB,CAAC,EAAE,CAAC,CAAC;YACtD,OAAO,mBAAmB,C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