definition-generator-framework 1.13.1 → 2.0.0-rc0
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/index.d.mts +198 -0
- package/dist/index.d.ts +198 -17
- package/dist/index.js +43 -50
- package/dist/index.mjs +43 -0
- package/package.json +27 -13
- package/dist/_mocks/mocks.d.ts +0 -7
- package/dist/_mocks/mocks.js +0 -44
- package/dist/decorators/definition-component.d.ts +0 -18
- package/dist/decorators/definition-component.js +0 -52
- package/dist/decorators/definition-generator.d.ts +0 -11
- package/dist/decorators/definition-generator.js +0 -30
- package/dist/framework/context.d.ts +0 -24
- package/dist/framework/context.js +0 -64
- package/dist/framework/definition-component.d.ts +0 -20
- package/dist/framework/definition-component.js +0 -29
- package/dist/framework/definition-generator.d.ts +0 -11
- package/dist/framework/definition-generator.js +0 -22
- package/dist/framework/definition-store.d.ts +0 -25
- package/dist/framework/definition-store.js +0 -121
- package/dist/framework/file-content-generator/file-content-generator.d.ts +0 -19
- package/dist/framework/file-content-generator/file-content-generator.js +0 -117
- package/dist/framework/file-content-generator/file-content-generator.test.d.ts +0 -24
- package/dist/framework/file-content-generator/file-content-generator.test.js +0 -161
- package/dist/framework/file-generators/index-file-generator.d.ts +0 -13
- package/dist/framework/file-generators/index-file-generator.js +0 -139
- package/dist/framework/file-generators/types-file-generator.d.ts +0 -6
- package/dist/framework/file-generators/types-file-generator.js +0 -35
- package/dist/framework/framework.d.ts +0 -28
- package/dist/framework/framework.data.d.ts +0 -6
- package/dist/framework/framework.data.js +0 -17
- package/dist/framework/framework.js +0 -51
- package/dist/framework/framework.model.d.ts +0 -32
- package/dist/framework/framework.model.js +0 -3
- package/dist/framework/index-file-generator/index-file-generator.d.ts +0 -10
- package/dist/framework/index-file-generator/index-file-generator.js +0 -118
- package/dist/framework/interfaces.d.ts +0 -46
- package/dist/framework/interfaces.js +0 -3
- package/dist/framework/kernel.d.ts +0 -12
- package/dist/framework/kernel.js +0 -308
- package/dist/helpers/common-functions/common-functions.d.ts +0 -10
- package/dist/helpers/common-functions/common-functions.js +0 -29
- package/dist/helpers/common-functions/common-functions.spec.d.ts +0 -1
- package/dist/helpers/common-functions/common-functions.spec.js +0 -50
- package/dist/helpers/common-functions/common-functions.test.d.ts +0 -1
- package/dist/helpers/common-functions/common-functions.test.js +0 -51
- package/dist/helpers/duplicate-helper/duplicate-helper.d.ts +0 -11
- package/dist/helpers/duplicate-helper/duplicate-helper.js +0 -40
- package/dist/helpers/duplicate-helper/duplicate-helper.spec.d.ts +0 -1
- package/dist/helpers/duplicate-helper/duplicate-helper.spec.js +0 -54
- package/dist/helpers/duplicate-helper/duplicate-helper.test.d.ts +0 -1
- package/dist/helpers/duplicate-helper/duplicate-helper.test.js +0 -55
- package/dist/helpers/output-helper/output-helper.d.ts +0 -30
- package/dist/helpers/output-helper/output-helper.js +0 -143
- package/dist/helpers/output-helper/output-helper.spec.d.ts +0 -24
- package/dist/helpers/output-helper/output-helper.spec.js +0 -261
- package/dist/helpers/output-helper/output-helper.test.d.ts +0 -24
- package/dist/helpers/output-helper/output-helper.test.js +0 -262
- package/dist/helpers/raw-definition-helper/raw-definition.helper.d.ts +0 -7
- package/dist/helpers/raw-definition-helper/raw-definition.helper.js +0 -66
- package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.d.ts +0 -1
- package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.js +0 -143
- package/dist/helpers/raw-definition-helper/raw-definition.helper.test.d.ts +0 -1
- package/dist/helpers/raw-definition-helper/raw-definition.helper.test.js +0 -136
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.d.ts +0 -16
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.js +0 -48
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.d.ts +0 -1
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.js +0 -191
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.test.d.ts +0 -1
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.test.js +0 -213
- package/dist/helpers/validator/custom-validators/helpers/sprite-validation.helper.d.ts +0 -13
- package/dist/helpers/validator/custom-validators/helpers/sprite-validation.helper.js +0 -53
- package/dist/helpers/validator/custom-validators/helpers/sprite-validation.helper.test.d.ts +0 -1
- package/dist/helpers/validator/custom-validators/helpers/sprite-validation.helper.test.js +0 -96
- package/dist/helpers/validator/custom-validators/image.custom-validator.d.ts +0 -14
- package/dist/helpers/validator/custom-validators/image.custom-validator.js +0 -44
- package/dist/helpers/validator/custom-validators/path.custom-validator.d.ts +0 -9
- package/dist/helpers/validator/custom-validators/path.custom-validator.js +0 -30
- package/dist/helpers/validator/custom-validators/position-on-sprite.d.ts +0 -14
- package/dist/helpers/validator/custom-validators/position-on-sprite.js +0 -44
- package/dist/helpers/validator/custom-validators/reference.custom-validator.d.ts +0 -22
- package/dist/helpers/validator/custom-validators/reference.custom-validator.js +0 -123
- package/dist/helpers/validator/custom-validators/sprite.custom-validator.d.ts +0 -14
- package/dist/helpers/validator/custom-validators/sprite.custom-validator.js +0 -43
- package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.d.ts +0 -9
- package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.js +0 -33
- package/dist/helpers/validator/custom-validators/unique.custom-validator.d.ts +0 -8
- package/dist/helpers/validator/custom-validators/unique.custom-validator.js +0 -20
- package/dist/helpers/validator/joi-custom-validators.d.ts +0 -33
- package/dist/helpers/validator/joi-custom-validators.js +0 -54
- package/dist/helpers/validator/joi-custom-validators.spec.d.ts +0 -1
- package/dist/helpers/validator/joi-custom-validators.spec.js +0 -304
- package/dist/helpers/validator/validator.d.ts +0 -21
- package/dist/helpers/validator/validator.js +0 -74
- package/dist/helpers/validator/validator.spec.d.ts +0 -1
- package/dist/helpers/validator/validator.spec.js +0 -332
- package/dist/helpers/validator/validator.test.d.ts +0 -1
- package/dist/helpers/validator/validator.test.js +0 -329
- package/dist/pipeline/1-select-definitions-helper.d.ts +0 -20
- package/dist/pipeline/1-select-definitions-helper.js +0 -76
- package/dist/pipeline/1-select-definitions.helper.d.ts +0 -20
- package/dist/pipeline/1-select-definitions.helper.js +0 -80
- package/dist/pipeline/1-select-definitions.helper.test.d.ts +0 -1
- package/dist/pipeline/1-select-definitions.helper.test.js +0 -141
- package/dist/pipeline/1-select-definitions.spec.d.ts +0 -1
- package/dist/pipeline/1-select-definitions.spec.js +0 -140
- package/dist/pipeline/2-structure-parser.helper.d.ts +0 -11
- package/dist/pipeline/2-structure-parser.helper.js +0 -70
- package/dist/pipeline/2-structure-parser.helper.spec.d.ts +0 -1
- package/dist/pipeline/2-structure-parser.helper.spec.js +0 -280
- package/dist/pipeline/2-structure-parser.helper.test.d.ts +0 -1
- package/dist/pipeline/2-structure-parser.helper.test.js +0 -281
- package/dist/pipeline/3-config.d.ts +0 -9
- package/dist/pipeline/3-config.js +0 -36
- package/dist/pipeline/_mocks/index.d.ts +0 -13
- package/dist/pipeline/_mocks/index.js +0 -52
- package/dist/pipeline/parsers/array-parser.d.ts +0 -4
- package/dist/pipeline/parsers/array-parser.js +0 -69
- package/dist/pipeline/parsers/array-parser.spec.d.ts +0 -1
- package/dist/pipeline/parsers/array-parser.spec.js +0 -128
- package/dist/pipeline/parsers/array-parser.test.d.ts +0 -1
- package/dist/pipeline/parsers/array-parser.test.js +0 -126
- package/dist/pipeline/parsers/object-parser.d.ts +0 -4
- package/dist/pipeline/parsers/object-parser.js +0 -135
- package/dist/pipeline/parsers/object-parser.spec.d.ts +0 -1
- package/dist/pipeline/parsers/object-parser.spec.js +0 -179
- package/dist/pipeline/parsers/object-parser.test.d.ts +0 -1
- package/dist/pipeline/parsers/object-parser.test.js +0 -186
- package/dist/pipeline/parsers/primitive-parser.d.ts +0 -7
- package/dist/pipeline/parsers/primitive-parser.js +0 -111
- package/dist/pipeline/parsers/primitive-parser.spec.d.ts +0 -1
- package/dist/pipeline/parsers/primitive-parser.spec.js +0 -79
- package/dist/pipeline/parsers/primitive-parser.test.d.ts +0 -1
- package/dist/pipeline/parsers/primitive-parser.test.js +0 -85
- package/dist/pipeline/raw-data-parser.d.ts +0 -5
- package/dist/pipeline/raw-data-parser.js +0 -25
- package/dist/pre-made-components/_validators/shape-validators.d.ts +0 -7
- package/dist/pre-made-components/_validators/shape-validators.js +0 -37
- package/dist/pre-made-components/_validators/sprite-validators.d.ts +0 -7
- package/dist/pre-made-components/_validators/sprite-validators.js +0 -43
- package/dist/pre-made-components/assets/1-sprite.d.ts +0 -15
- package/dist/pre-made-components/assets/1-sprite.js +0 -74
- package/dist/pre-made-components/assets/2-sprite-group.d.ts +0 -11
- package/dist/pre-made-components/assets/2-sprite-group.js +0 -41
- package/dist/pre-made-components/assets/3-font.d.ts +0 -17
- package/dist/pre-made-components/assets/3-font.js +0 -71
- package/dist/pre-made-components/events/1-event.d.ts +0 -6
- package/dist/pre-made-components/events/1-event.js +0 -206
- package/dist/pre-made-components/events/1-script.d.ts +0 -8
- package/dist/pre-made-components/events/1-script.js +0 -102
- package/dist/pre-made-components/events/2-event-test.d.ts +0 -18
- package/dist/pre-made-components/events/2-event-test.js +0 -172
- package/dist/pre-made-components/events/2-script-test.d.ts +0 -7
- package/dist/pre-made-components/events/2-script-test.js +0 -102
- package/dist/pre-made-components/events/3-event.d.ts +0 -7
- package/dist/pre-made-components/events/3-event.js +0 -100
- package/dist/pre-made-components/events/4-event-test.d.ts +0 -7
- package/dist/pre-made-components/events/4-event-test.js +0 -89
- package/dist/pre-made-components/events/event-setup.d.ts +0 -13
- package/dist/pre-made-components/events/event-setup.js +0 -20
- package/dist/pre-made-components/events/helpers/quotes-to-tags.helper.d.ts +0 -3
- package/dist/pre-made-components/events/helpers/quotes-to-tags.helper.js +0 -24
- package/dist/pre-made-components/events/helpers/quotes-to-tags.helper.test.d.ts +0 -1
- package/dist/pre-made-components/events/helpers/quotes-to-tags.helper.test.js +0 -39
- package/dist/pre-made-components/events/helpers/script-testing.helper.d.ts +0 -33
- package/dist/pre-made-components/events/helpers/script-testing.helper.js +0 -79
- package/dist/pre-made-components/events/script-setup.d.ts +0 -8
- package/dist/pre-made-components/events/script-setup.js +0 -16
- package/dist/pre-made-components/events/scripting-setup.d.ts +0 -33
- package/dist/pre-made-components/events/scripting-setup.js +0 -97
- package/dist/pre-made-components/events/validators.d.ts +0 -6
- package/dist/pre-made-components/events/validators.js +0 -96
- package/dist/setup.d.ts +0 -1
- package/dist/setup.js +0 -10
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LazyReferenceCustomValidator = exports.ReferenceCustomValidator = void 0;
|
|
4
|
-
const helpers_lib_1 = require("helpers-lib");
|
|
5
|
-
const context_1 = require("../../../framework/context");
|
|
6
|
-
const definition_store_1 = require("../../../framework/definition-store");
|
|
7
|
-
const raw_definition_helper_1 = require("../../raw-definition-helper/raw-definition.helper");
|
|
8
|
-
const custom_validator_helper_1 = require("../custom-validator-helper/custom-validator.helper");
|
|
9
|
-
class ReferenceCustomValidatorBase {
|
|
10
|
-
constructor(options) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.regex = /^[a-z]+([a-zA-Z0-9]+)*$/;
|
|
13
|
-
}
|
|
14
|
-
validatePropertyExistence(referencedComponent, definitionName, options) {
|
|
15
|
-
if (options?.additionalValidation) {
|
|
16
|
-
let rawDefinition = definition_store_1.DefinitionStore['getRawDefinition'](referencedComponent, definitionName);
|
|
17
|
-
let flattenedRawDefinition = rawDefinition ? raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition) : undefined;
|
|
18
|
-
let validation = options.additionalValidation.validate(flattenedRawDefinition);
|
|
19
|
-
if (validation.error) {
|
|
20
|
-
throw new Error(validation.error.message);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
class ReferenceCustomValidator extends ReferenceCustomValidatorBase {
|
|
26
|
-
constructor(definitionComponentClasses, options) {
|
|
27
|
-
super(options);
|
|
28
|
-
this.validate = (value, helpers) => {
|
|
29
|
-
let validationState = custom_validator_helper_1.CustomValidatorHelper.getValidationState(helpers);
|
|
30
|
-
if (validationState === 'valid') {
|
|
31
|
-
let referencedComponent = this.referencedComponents.find(component => definition_store_1.DefinitionStore.getDefinition(component, value));
|
|
32
|
-
if (!referencedComponent) {
|
|
33
|
-
let referencedComponentRawDefinitionExists = this.referencedComponents.find(component => definition_store_1.DefinitionStore['isRawDefinitionExists'](component, value));
|
|
34
|
-
if (referencedComponentRawDefinitionExists) {
|
|
35
|
-
// If referenced definition is failed its own validation, there should be no additional error
|
|
36
|
-
helpers.prefs.context.failSilently = true;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
throw new Error(`There is no "${this.referencedComponents
|
|
40
|
-
.map(component => custom_validator_helper_1.CustomValidatorHelper.getDefinitionComponentName(component))
|
|
41
|
-
.join(' or ')}" definition found for "${value}"`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.validatePropertyExistence(referencedComponent, value, this.options);
|
|
46
|
-
if (this.includeType) {
|
|
47
|
-
return {
|
|
48
|
-
value,
|
|
49
|
-
type: custom_validator_helper_1.CustomValidatorHelper.getDefinitionComponentName(referencedComponent)
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
return value;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
throw new Error(`Internal Error; joi validation context for reference validator: Path: "${helpers.state.path}", RawDefinition: "${JSON.stringify(helpers.prefs.context)}"`);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
this.referencedComponents = [];
|
|
62
|
-
if (helpers_lib_1.Comparator.isArray(definitionComponentClasses)) {
|
|
63
|
-
this.includeType = true;
|
|
64
|
-
this.referencedComponents = definitionComponentClasses;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
this.includeType = false;
|
|
68
|
-
this.referencedComponents = [definitionComponentClasses];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.ReferenceCustomValidator = ReferenceCustomValidator;
|
|
73
|
-
class LazyReferenceCustomValidator extends ReferenceCustomValidatorBase {
|
|
74
|
-
constructor(componentName, options) {
|
|
75
|
-
super(options);
|
|
76
|
-
this.componentName = componentName;
|
|
77
|
-
this.validate = (value, helpers) => {
|
|
78
|
-
if (!context_1.Context.componentInProgressData) {
|
|
79
|
-
helpers_lib_1.ConsoleHelper.log('Unexpected error: Lazy reference validation has been called outside of the validation cycle.', 'red');
|
|
80
|
-
}
|
|
81
|
-
else if (!context_1.Context.componentInProgressData.meta.keyName) {
|
|
82
|
-
helpers_lib_1.ConsoleHelper.log('Lazy reference can only be used for definitions with key name defined.', 'red');
|
|
83
|
-
}
|
|
84
|
-
else if (context_1.Context.componentInProgressData.meta.componentName !== this.componentName) {
|
|
85
|
-
helpers_lib_1.ConsoleHelper.log(`Lazy reference can only be used for self referencing. It is used under: "${this.componentName}"`, 'red');
|
|
86
|
-
}
|
|
87
|
-
else if (context_1.Context.componentInProgressData.meta.singleton) {
|
|
88
|
-
helpers_lib_1.ConsoleHelper.log(`Lazy reference cannot be used for singleton components. It is used under: "${this.componentName}"`, 'red');
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
let rootDefinition = helpers.state.ancestors.at(-1);
|
|
92
|
-
let definitionId = rootDefinition[context_1.Context.componentInProgressData.meta.keyName];
|
|
93
|
-
if (!definitionId) {
|
|
94
|
-
helpers_lib_1.ConsoleHelper.log(`Unexpected error: definitionId cannot be retrieved by keyname.`, 'red');
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
if (!context_1.Context.componentInProgressData.idToReferencesMap.has(definitionId)) {
|
|
98
|
-
context_1.Context.componentInProgressData.idToReferencesMap.set(definitionId, new Set());
|
|
99
|
-
}
|
|
100
|
-
let references = context_1.Context.componentInProgressData.idToReferencesMap.get(definitionId);
|
|
101
|
-
references.add(value);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
let referencedComponent = definition_store_1.DefinitionStore['getComponentClass'](this.componentName);
|
|
105
|
-
let validationState = custom_validator_helper_1.CustomValidatorHelper.getValidationState(helpers);
|
|
106
|
-
if (validationState === 'valid') {
|
|
107
|
-
let referencedComponentRawDefinitionExists = definition_store_1.DefinitionStore['isRawDefinitionExists'](referencedComponent, value);
|
|
108
|
-
if (!referencedComponentRawDefinitionExists) {
|
|
109
|
-
throw new Error(`There is no "${this.componentName}" definition found for "${value}"`);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
this.validatePropertyExistence(referencedComponent, value, this.options);
|
|
113
|
-
return value;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
throw new Error(`Internal Error; joi validation context for reference validator: Path: "${helpers.state.path}", RawDefinition: "${JSON.stringify(helpers.prefs.context)}"`);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
exports.LazyReferenceCustomValidator = LazyReferenceCustomValidator;
|
|
123
|
-
//# sourceMappingURL=reference.custom-validator.js.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Vec2 } from 'helpers-lib';
|
|
2
|
-
import Joi, { ErrorReport } from 'joi';
|
|
3
|
-
import { FileSystem } from '../../../framework/interfaces';
|
|
4
|
-
import { CustomStringValidator } from '../joi-custom-validators';
|
|
5
|
-
export interface ValidatedSpriteUrl {
|
|
6
|
-
readonly url: string;
|
|
7
|
-
readonly size: Vec2;
|
|
8
|
-
}
|
|
9
|
-
export declare class SpriteCustomValidator implements CustomStringValidator {
|
|
10
|
-
private fs;
|
|
11
|
-
readonly regex: RegExp;
|
|
12
|
-
readonly validate: (value: string, helpers: Joi.CustomHelpers) => any | ErrorReport;
|
|
13
|
-
constructor(fs: FileSystem);
|
|
14
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SpriteCustomValidator = void 0;
|
|
7
|
-
const image_size_1 = __importDefault(require("image-size"));
|
|
8
|
-
const context_1 = require("../../../framework/context");
|
|
9
|
-
const custom_validator_helper_1 = require("../custom-validator-helper/custom-validator.helper");
|
|
10
|
-
class SpriteCustomValidator {
|
|
11
|
-
constructor(fs) {
|
|
12
|
-
this.fs = fs;
|
|
13
|
-
this.regex = /^[\S]+$/;
|
|
14
|
-
this.validate = (value, helpers) => {
|
|
15
|
-
let validationState = custom_validator_helper_1.CustomValidatorHelper.getValidationState(helpers);
|
|
16
|
-
if (validationState === 'valid') {
|
|
17
|
-
let { rawDefinition } = custom_validator_helper_1.CustomValidatorHelper.getPathAndRawDefinition(helpers);
|
|
18
|
-
let pathPrefix = rawDefinition.location.path.substring(0, rawDefinition.location.path.lastIndexOf('/') + 1);
|
|
19
|
-
value = pathPrefix + value;
|
|
20
|
-
if (!this.fs.existsSync(value)) {
|
|
21
|
-
throw new Error(`No file is found in the path: "${value}"`);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
try {
|
|
25
|
-
let size = (0, image_size_1.default)(value);
|
|
26
|
-
return {
|
|
27
|
-
url: value.replace(context_1.Context.config.projectRoot, '.'),
|
|
28
|
-
size: { x: size.width, y: size.height }
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
throw new Error(`The file in the path "${value}" is not an image`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
throw new Error(`Internal Error; joi validation context for image validator: Path: "${helpers.state.path}", RawDefinition: "${JSON.stringify(helpers.prefs.context.rawDefinition)}"`);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.SpriteCustomValidator = SpriteCustomValidator;
|
|
43
|
-
//# sourceMappingURL=sprite.custom-validator.js.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import Joi, { ErrorReport } from 'joi';
|
|
2
|
-
import { CustomValidator } from '../joi-custom-validators';
|
|
3
|
-
import { DefinitionComponentClassType } from '../../../framework/definition-component';
|
|
4
|
-
export declare class UniqueNameGroupCustomValidator implements CustomValidator {
|
|
5
|
-
private definitionComponentClass;
|
|
6
|
-
readonly regex: RegExp;
|
|
7
|
-
readonly validate: (value: string, helpers: Joi.CustomHelpers) => any | ErrorReport;
|
|
8
|
-
constructor(definitionComponentClass: DefinitionComponentClassType<any>);
|
|
9
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.UniqueNameGroupCustomValidator = void 0;
|
|
4
|
-
const common_functions_1 = require('../../common-functions/common-functions');
|
|
5
|
-
const raw_definition_helper_1 = require('../../raw-definition-helper/raw-definition.helper');
|
|
6
|
-
const custom_validator_helper_1 = require('../custom-validator-helper/custom-validator.helper');
|
|
7
|
-
class UniqueNameGroupCustomValidator {
|
|
8
|
-
constructor(definitionComponentClass) {
|
|
9
|
-
this.definitionComponentClass = definitionComponentClass;
|
|
10
|
-
this.regex = /^[a-z]+([a-zA-Z0-9]+)*$/;
|
|
11
|
-
this.validate = (value, helpers) => {
|
|
12
|
-
let componentName = this.definitionComponentClass.$meta.componentName;
|
|
13
|
-
let validationState = custom_validator_helper_1.CustomValidatorHelper.getValidationState(helpers);
|
|
14
|
-
if (validationState === 'valid') {
|
|
15
|
-
let { path, rawDefinition } = custom_validator_helper_1.CustomValidatorHelper.getPathAndRawDefinition(helpers);
|
|
16
|
-
let duplicateHelper = custom_validator_helper_1.CustomValidatorHelper.getDuplicateHelper(componentName);
|
|
17
|
-
duplicateHelper.newEntry(value, {
|
|
18
|
-
line: raw_definition_helper_1.RawDefinitionHelper.findLine(rawDefinition, path),
|
|
19
|
-
path: rawDefinition.location.path
|
|
20
|
-
});
|
|
21
|
-
return common_functions_1.CommonFunctions.decorateDefinitionName(value, componentName);
|
|
22
|
-
} else if (validationState === 'registerLoop') {
|
|
23
|
-
custom_validator_helper_1.CustomValidatorHelper.getDefinitionNames(componentName).add(value);
|
|
24
|
-
} else {
|
|
25
|
-
throw new Error(
|
|
26
|
-
`Internal Error; joi validation context for uniqueNameGroup validator: Path: "${helpers.state.path}", RawDefinition: "${JSON.stringify(helpers.prefs.context)}"`
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.UniqueNameGroupCustomValidator = UniqueNameGroupCustomValidator;
|
|
33
|
-
//# sourceMappingURL=unique-name-group.custom-validator.js.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import Joi, { ErrorReport } from 'joi';
|
|
2
|
-
import { CustomStringValidator } from '../joi-custom-validators';
|
|
3
|
-
export declare class UniqueCustomValidator implements CustomStringValidator {
|
|
4
|
-
private nameSpace;
|
|
5
|
-
readonly regex: RegExp;
|
|
6
|
-
readonly validate: (value: string, helpers: Joi.CustomHelpers) => any | ErrorReport;
|
|
7
|
-
constructor(nameSpace: Set<string>);
|
|
8
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UniqueCustomValidator = void 0;
|
|
4
|
-
class UniqueCustomValidator {
|
|
5
|
-
constructor(nameSpace) {
|
|
6
|
-
this.nameSpace = nameSpace;
|
|
7
|
-
this.regex = /^[\S]+$/;
|
|
8
|
-
this.validate = (value, helpers) => {
|
|
9
|
-
if (this.nameSpace.has(value)) {
|
|
10
|
-
throw new Error(`Value "${value}" is not unique in the name space: "${Array.from(this.nameSpace).join(', ')}"`);
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
this.nameSpace.add(value);
|
|
14
|
-
return value;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.UniqueCustomValidator = UniqueCustomValidator;
|
|
20
|
-
//# sourceMappingURL=unique.custom-validator.js.map
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
import { DefinitionComponentClassType } from '../../decorators/definition-component';
|
|
3
|
-
import { FileSystem } from '../../framework/interfaces';
|
|
4
|
-
import { PositionOnSpriteValidationOptions } from './custom-validators/position-on-sprite';
|
|
5
|
-
export interface CustomStringValidator {
|
|
6
|
-
readonly regex: RegExp;
|
|
7
|
-
readonly validate: Joi.CustomValidator<any, any>;
|
|
8
|
-
}
|
|
9
|
-
export interface CustomObjectValidator {
|
|
10
|
-
readonly validate: Joi.CustomValidator<any, any>;
|
|
11
|
-
}
|
|
12
|
-
export interface ReferenceCustomValidatorOptions {
|
|
13
|
-
additionalValidation?: Joi.Schema;
|
|
14
|
-
}
|
|
15
|
-
declare module 'joi' {
|
|
16
|
-
interface StringSchema {
|
|
17
|
-
unique(nameSpace: Set<string>): Joi.StringSchema;
|
|
18
|
-
path(): Joi.StringSchema;
|
|
19
|
-
sprite(): Joi.StringSchema;
|
|
20
|
-
reference(definitionComponentClass: DefinitionComponentClassType<any> | DefinitionComponentClassType<any>[], options?: ReferenceCustomValidatorOptions): Joi.StringSchema;
|
|
21
|
-
lazyReference(componentName: string, options?: ReferenceCustomValidatorOptions): Joi.StringSchema;
|
|
22
|
-
}
|
|
23
|
-
interface ObjectSchema {
|
|
24
|
-
/**
|
|
25
|
-
* Converts the values to relative position from anchor on sprite.
|
|
26
|
-
*/
|
|
27
|
-
positionOnSprite(options: PositionOnSpriteValidationOptions): Joi.ObjectSchema;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export declare class JoiCustomValidators {
|
|
31
|
-
static decorate(joi: object, fs: FileSystem): void;
|
|
32
|
-
private static defineCustomStringValidator;
|
|
33
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.JoiCustomValidators = void 0;
|
|
7
|
-
const joi_1 = __importDefault(require("joi"));
|
|
8
|
-
const path_custom_validator_1 = require("./custom-validators/path.custom-validator");
|
|
9
|
-
const position_on_sprite_1 = require("./custom-validators/position-on-sprite");
|
|
10
|
-
const reference_custom_validator_1 = require("./custom-validators/reference.custom-validator");
|
|
11
|
-
const sprite_custom_validator_1 = require("./custom-validators/sprite.custom-validator");
|
|
12
|
-
const unique_custom_validator_1 = require("./custom-validators/unique.custom-validator");
|
|
13
|
-
class JoiCustomValidators {
|
|
14
|
-
static decorate(joi, fs) {
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
joi.string().__proto__.unique = function (nameSpace) {
|
|
17
|
-
let uniqueCustomValidator = new unique_custom_validator_1.UniqueCustomValidator(nameSpace);
|
|
18
|
-
return JoiCustomValidators.defineCustomStringValidator(this, uniqueCustomValidator);
|
|
19
|
-
};
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
joi.string().__proto__.path = function () {
|
|
22
|
-
let pathCustomValidator = new path_custom_validator_1.PathCustomValidator(fs);
|
|
23
|
-
return JoiCustomValidators.defineCustomStringValidator(this, pathCustomValidator);
|
|
24
|
-
};
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
joi.string().__proto__.sprite = function () {
|
|
27
|
-
let spriteCustomValidator = new sprite_custom_validator_1.SpriteCustomValidator(fs);
|
|
28
|
-
return JoiCustomValidators.defineCustomStringValidator(this, spriteCustomValidator);
|
|
29
|
-
};
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
joi.string().__proto__.reference = function (definitionComponentClasses, options) {
|
|
32
|
-
let referenceCustomValidator = new reference_custom_validator_1.ReferenceCustomValidator(definitionComponentClasses, options);
|
|
33
|
-
return JoiCustomValidators.defineCustomStringValidator(this, referenceCustomValidator);
|
|
34
|
-
};
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
joi.string().__proto__.lazyReference = function (componentName, options) {
|
|
37
|
-
let lazyReferenceCustomValidator = new reference_custom_validator_1.LazyReferenceCustomValidator(componentName, options);
|
|
38
|
-
return JoiCustomValidators.defineCustomStringValidator(this, lazyReferenceCustomValidator);
|
|
39
|
-
};
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
joi.object().__proto__.positionOnSprite = function (options) {
|
|
42
|
-
let positionOnSpriteValidator = new position_on_sprite_1.PositionOnSpriteCustomValidator(options);
|
|
43
|
-
return this.custom(positionOnSpriteValidator.validate);
|
|
44
|
-
};
|
|
45
|
-
if (joi !== joi_1.default) {
|
|
46
|
-
this.decorate(joi_1.default, fs);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
static defineCustomStringValidator(schema, customValidator) {
|
|
50
|
-
return schema.regex(customValidator.regex).custom(customValidator.validate);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.JoiCustomValidators = JoiCustomValidators;
|
|
54
|
-
//# sourceMappingURL=joi-custom-validators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __createBinding =
|
|
3
|
-
(this && this.__createBinding) ||
|
|
4
|
-
(Object.create
|
|
5
|
-
? function (o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
-
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function () {
|
|
12
|
-
return m[k];
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
Object.defineProperty(o, k2, desc);
|
|
17
|
-
}
|
|
18
|
-
: function (o, m, k, k2) {
|
|
19
|
-
if (k2 === undefined) k2 = k;
|
|
20
|
-
o[k2] = m[k];
|
|
21
|
-
});
|
|
22
|
-
var __setModuleDefault =
|
|
23
|
-
(this && this.__setModuleDefault) ||
|
|
24
|
-
(Object.create
|
|
25
|
-
? function (o, v) {
|
|
26
|
-
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
27
|
-
}
|
|
28
|
-
: function (o, v) {
|
|
29
|
-
o['default'] = v;
|
|
30
|
-
});
|
|
31
|
-
var __importStar =
|
|
32
|
-
(this && this.__importStar) ||
|
|
33
|
-
function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null)
|
|
37
|
-
for (var k in mod) if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
-
__setModuleDefault(result, mod);
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
42
|
-
const Joi = __importStar(require('joi'));
|
|
43
|
-
const joi_custom_validators_1 = require('./joi-custom-validators');
|
|
44
|
-
const mocks_1 = require('../../_mocks/mocks');
|
|
45
|
-
const raw_definition_helper_1 = require('../raw-definition-helper/raw-definition.helper');
|
|
46
|
-
joi_custom_validators_1.JoiCustomValidators.decorate({ existsSync: path => path !== 'D:/test/false/path.png' });
|
|
47
|
-
const DefinitionType = 'ASSET';
|
|
48
|
-
class Asset {
|
|
49
|
-
static {
|
|
50
|
-
this.$meta = {
|
|
51
|
-
definitionName: DefinitionType
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
async process() {}
|
|
55
|
-
}
|
|
56
|
-
class AssetGroup {
|
|
57
|
-
static {
|
|
58
|
-
this.$meta = {
|
|
59
|
-
definitionName: 'ASSET-GROUP'
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
async process() {}
|
|
63
|
-
}
|
|
64
|
-
function getSimpleRawDefinition(value, offset = 1) {
|
|
65
|
-
return {
|
|
66
|
-
type: DefinitionType,
|
|
67
|
-
location: mocks_1.SampleLocation1,
|
|
68
|
-
parsedStructure: {
|
|
69
|
-
line: mocks_1.SampleLocation1.line + offset,
|
|
70
|
-
rawData: {
|
|
71
|
-
value: {
|
|
72
|
-
rawData: value,
|
|
73
|
-
line: mocks_1.SampleLocation1.line + offset
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function getFlatRawDefinition(value, offset = 1) {
|
|
80
|
-
return {
|
|
81
|
-
type: DefinitionType,
|
|
82
|
-
location: mocks_1.SampleLocation1,
|
|
83
|
-
parsedStructure: {
|
|
84
|
-
line: mocks_1.SampleLocation1.line + offset,
|
|
85
|
-
rawData: value
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
describe('JOI CUSTOM VALIDATORS', () => {
|
|
90
|
-
beforeEach(() => {
|
|
91
|
-
let validators = joi_custom_validators_1.JoiCustomValidators;
|
|
92
|
-
validators.rootDirectory = 'D:/';
|
|
93
|
-
validators.definitionNames = new Map();
|
|
94
|
-
validators.duplicateHelpers = new Map();
|
|
95
|
-
});
|
|
96
|
-
describe('Variable Name', () => {
|
|
97
|
-
let schema = Joi.object().keys({
|
|
98
|
-
value: Joi.string().uniqueNameGroup(Asset).required()
|
|
99
|
-
});
|
|
100
|
-
test('valid data', () => {
|
|
101
|
-
let rawDefinition = getSimpleRawDefinition('test');
|
|
102
|
-
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
103
|
-
abortEarly: false,
|
|
104
|
-
context: rawDefinition
|
|
105
|
-
});
|
|
106
|
-
expect(value).toEqual({ value: 'assetTest' });
|
|
107
|
-
expect(error).toEqual(undefined);
|
|
108
|
-
});
|
|
109
|
-
test('invalid data', () => {
|
|
110
|
-
let rawDefinition = getSimpleRawDefinition('invalid data');
|
|
111
|
-
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
112
|
-
abortEarly: false,
|
|
113
|
-
context: rawDefinition
|
|
114
|
-
});
|
|
115
|
-
expect(error?.details).toStrictEqual([
|
|
116
|
-
{
|
|
117
|
-
message: '"value" with value "invalid data" fails to match the required pattern: /^[a-z]+([a-zA-Z0-9]+)*$/',
|
|
118
|
-
path: [],
|
|
119
|
-
type: 'string.pattern.base',
|
|
120
|
-
context: {
|
|
121
|
-
name: undefined,
|
|
122
|
-
regex: /^[a-z]+([a-zA-Z0-9]+)*$/,
|
|
123
|
-
value: 'invalid data',
|
|
124
|
-
label: 'value',
|
|
125
|
-
key: 'value'
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
]);
|
|
129
|
-
});
|
|
130
|
-
test('should detect duplicate variable names', () => {
|
|
131
|
-
let rawDefinition1 = getSimpleRawDefinition('test', 1);
|
|
132
|
-
let rawDefinition2 = getSimpleRawDefinition('test', 2);
|
|
133
|
-
schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition1), {
|
|
134
|
-
abortEarly: false,
|
|
135
|
-
context: rawDefinition1
|
|
136
|
-
});
|
|
137
|
-
schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition2), {
|
|
138
|
-
abortEarly: false,
|
|
139
|
-
context: rawDefinition2
|
|
140
|
-
});
|
|
141
|
-
let context = (0, mocks_1.getMockContext)();
|
|
142
|
-
joi_custom_validators_1.JoiCustomValidators.logDuplicates(context);
|
|
143
|
-
expect(context.errorLogs).toStrictEqual([
|
|
144
|
-
{
|
|
145
|
-
description: 'Value should be singular! Group: "ASSET", Value: "test"',
|
|
146
|
-
location: { line: mocks_1.SampleLocation1.line + 1, path: 'D:/test/file-1.md' }
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
description: 'Value should be singular! Group: "ASSET", Value: "test"',
|
|
150
|
-
location: { line: mocks_1.SampleLocation1.line + 2, path: 'D:/test/file-1.md' }
|
|
151
|
-
}
|
|
152
|
-
]);
|
|
153
|
-
});
|
|
154
|
-
test('different groups should not create duplicates', () => {
|
|
155
|
-
let schema2 = Joi.object().keys({
|
|
156
|
-
value: Joi.string().uniqueNameGroup(AssetGroup).required()
|
|
157
|
-
});
|
|
158
|
-
let rawDefinition1 = getSimpleRawDefinition('test', 1);
|
|
159
|
-
let rawDefinition2 = getSimpleRawDefinition('test', 2);
|
|
160
|
-
schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition1), {
|
|
161
|
-
abortEarly: false,
|
|
162
|
-
context: rawDefinition1
|
|
163
|
-
});
|
|
164
|
-
schema2.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition2), {
|
|
165
|
-
abortEarly: false,
|
|
166
|
-
context: rawDefinition2
|
|
167
|
-
});
|
|
168
|
-
let context = (0, mocks_1.getMockContext)();
|
|
169
|
-
joi_custom_validators_1.JoiCustomValidators.logDuplicates(context);
|
|
170
|
-
expect(context.errorLogs).toStrictEqual([]);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
describe('Reference', () => {
|
|
174
|
-
let schema = Joi.object().keys({
|
|
175
|
-
value: Joi.string().reference(Asset).required()
|
|
176
|
-
});
|
|
177
|
-
let multipleSchema = Joi.object().keys({
|
|
178
|
-
value: Joi.string().reference([AssetGroup, Asset]).required()
|
|
179
|
-
});
|
|
180
|
-
test('valid data', () => {
|
|
181
|
-
let rawDefinition = getSimpleRawDefinition('test');
|
|
182
|
-
let validators = joi_custom_validators_1.JoiCustomValidators;
|
|
183
|
-
validators.getDefinitionNames(DefinitionType).add('test');
|
|
184
|
-
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
185
|
-
abortEarly: false,
|
|
186
|
-
context: rawDefinition
|
|
187
|
-
});
|
|
188
|
-
expect(value).toEqual({ value: 'assetTest' });
|
|
189
|
-
expect(error).toEqual(undefined);
|
|
190
|
-
});
|
|
191
|
-
test('multiple reference', () => {
|
|
192
|
-
let rawDefinition = getSimpleRawDefinition('test');
|
|
193
|
-
let validators = joi_custom_validators_1.JoiCustomValidators;
|
|
194
|
-
validators.getDefinitionNames(DefinitionType).add('test');
|
|
195
|
-
let { value, error } = multipleSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
196
|
-
abortEarly: false,
|
|
197
|
-
context: rawDefinition
|
|
198
|
-
});
|
|
199
|
-
expect(value).toEqual({ value: 'assetTest' });
|
|
200
|
-
expect(error).toEqual(undefined);
|
|
201
|
-
});
|
|
202
|
-
test('primitive valid data', () => {
|
|
203
|
-
let rawDefinition = getFlatRawDefinition('test');
|
|
204
|
-
let primitiveSchema = Joi.string().reference(Asset).required();
|
|
205
|
-
let validators = joi_custom_validators_1.JoiCustomValidators;
|
|
206
|
-
validators.getDefinitionNames(DefinitionType).add('test');
|
|
207
|
-
let { value, error } = primitiveSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
208
|
-
abortEarly: false,
|
|
209
|
-
context: rawDefinition
|
|
210
|
-
});
|
|
211
|
-
expect(value).toEqual('assetTest');
|
|
212
|
-
expect(error).toEqual(undefined);
|
|
213
|
-
});
|
|
214
|
-
test('should detect non existing references', () => {
|
|
215
|
-
let rawDefinition = getSimpleRawDefinition('test');
|
|
216
|
-
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
217
|
-
abortEarly: false,
|
|
218
|
-
context: rawDefinition
|
|
219
|
-
});
|
|
220
|
-
expect(error?.details).toEqual([
|
|
221
|
-
{
|
|
222
|
-
context: {
|
|
223
|
-
key: 'value',
|
|
224
|
-
label: 'value',
|
|
225
|
-
value: 'test'
|
|
226
|
-
},
|
|
227
|
-
message: 'There is no definition found for "test" in name field: "ASSET"',
|
|
228
|
-
path: ['value'],
|
|
229
|
-
type: 'any.custom'
|
|
230
|
-
}
|
|
231
|
-
]);
|
|
232
|
-
});
|
|
233
|
-
test('should detect non existing multiple references', () => {
|
|
234
|
-
let rawDefinition = getSimpleRawDefinition('test');
|
|
235
|
-
let { error } = multipleSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
236
|
-
abortEarly: false,
|
|
237
|
-
context: rawDefinition
|
|
238
|
-
});
|
|
239
|
-
expect(error?.details).toEqual([
|
|
240
|
-
{
|
|
241
|
-
context: {
|
|
242
|
-
key: 'value',
|
|
243
|
-
label: 'value',
|
|
244
|
-
value: 'test'
|
|
245
|
-
},
|
|
246
|
-
message: 'There is no definition found for "test" in name field: "ASSET-GROUP, ASSET"',
|
|
247
|
-
path: ['value'],
|
|
248
|
-
type: 'any.custom'
|
|
249
|
-
}
|
|
250
|
-
]);
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
describe('Path', () => {
|
|
254
|
-
let schema = Joi.object().keys({
|
|
255
|
-
value: Joi.string().path().required()
|
|
256
|
-
});
|
|
257
|
-
test('valid data', () => {
|
|
258
|
-
let rawDefinition = getSimpleRawDefinition('images/test.png');
|
|
259
|
-
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
260
|
-
abortEarly: false,
|
|
261
|
-
context: rawDefinition
|
|
262
|
-
});
|
|
263
|
-
expect(value).toEqual({ value: '.test/images/test.png' });
|
|
264
|
-
expect(error).toEqual(undefined);
|
|
265
|
-
});
|
|
266
|
-
test('should detect files not existing', () => {
|
|
267
|
-
let rawDefinition = getSimpleRawDefinition('invalid data');
|
|
268
|
-
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
269
|
-
abortEarly: false,
|
|
270
|
-
context: rawDefinition
|
|
271
|
-
});
|
|
272
|
-
expect(error?.details).toStrictEqual([
|
|
273
|
-
{
|
|
274
|
-
message: '"value" with value "invalid data" fails to match the required pattern: /^[\\S]+$/',
|
|
275
|
-
path: ['value'],
|
|
276
|
-
type: 'string.pattern.base',
|
|
277
|
-
context: {
|
|
278
|
-
name: undefined,
|
|
279
|
-
regex: /^[\S]+$/,
|
|
280
|
-
value: 'invalid data',
|
|
281
|
-
label: 'value',
|
|
282
|
-
key: 'value'
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
]);
|
|
286
|
-
});
|
|
287
|
-
test('should detect files not existing', () => {
|
|
288
|
-
let rawDefinition = getSimpleRawDefinition('false/path.png');
|
|
289
|
-
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
290
|
-
abortEarly: false,
|
|
291
|
-
context: rawDefinition
|
|
292
|
-
});
|
|
293
|
-
expect(error?.details).toStrictEqual([
|
|
294
|
-
{
|
|
295
|
-
message: 'No file is found in the path: "false/path.png"',
|
|
296
|
-
path: ['value'],
|
|
297
|
-
type: 'any.custom',
|
|
298
|
-
context: { label: 'value', value: 'false/path.png', key: 'value' }
|
|
299
|
-
}
|
|
300
|
-
]);
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
//# sourceMappingURL=joi-custom-validators.spec.js.map
|