definition-generator-framework 1.12.5 → 1.12.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/framework/definition-component.d.ts +11 -9
- package/dist/framework/definition-component.js +18 -18
- package/dist/framework/definition-generator.d.ts +6 -5
- package/dist/framework/definition-generator.js +16 -18
- package/dist/framework/file-content-generator/file-content-generator.js +1 -1
- package/dist/framework/file-content-generator/file-content-generator.test.js +49 -49
- package/dist/framework/framework.d.ts +14 -13
- package/dist/framework/framework.data.d.ts +3 -3
- package/dist/framework/framework.data.js +13 -7
- package/dist/framework/framework.js +36 -33
- package/dist/framework/framework.model.d.ts +15 -15
- package/dist/framework/framework.model.js +3 -3
- package/dist/helpers/common-functions/common-functions.js +1 -1
- package/dist/helpers/common-functions/common-functions.spec.js +48 -48
- package/dist/helpers/duplicate-helper/duplicate-helper.spec.js +52 -52
- package/dist/helpers/output-helper/output-helper.d.ts +26 -26
- package/dist/helpers/output-helper/output-helper.js +127 -107
- package/dist/helpers/output-helper/output-helper.spec.d.ts +22 -22
- package/dist/helpers/output-helper/output-helper.spec.js +223 -211
- package/dist/helpers/output-helper/output-helper.test.d.ts +22 -22
- package/dist/helpers/output-helper/output-helper.test.js +224 -212
- package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.js +133 -125
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.d.ts +1 -1
- package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.js +174 -156
- package/dist/helpers/validator/custom-validators/image.custom-validator.d.ts +6 -6
- package/dist/helpers/validator/custom-validators/image.custom-validator.js +40 -39
- package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.d.ts +4 -4
- package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.js +29 -29
- package/dist/helpers/validator/joi-custom-validators.spec.js +284 -240
- package/dist/helpers/validator/validator.spec.js +313 -303
- package/dist/pipeline/1-select-definitions-helper.d.ts +13 -13
- package/dist/pipeline/1-select-definitions-helper.js +68 -72
- package/dist/pipeline/1-select-definitions.helper.test.js +40 -40
- package/dist/pipeline/1-select-definitions.spec.js +131 -131
- package/dist/pipeline/2-structure-parser.helper.spec.js +266 -266
- package/dist/pipeline/parsers/array-parser.spec.js +116 -113
- package/dist/pipeline/parsers/object-parser.spec.js +159 -153
- package/dist/pipeline/parsers/primitive-parser.spec.js +67 -67
- package/dist/pre-made-components/assets/3-font.js +4 -4
- package/dist/pre-made-components/events/1-event.d.ts +1 -1
- package/dist/pre-made-components/events/1-event.js +157 -125
- package/dist/pre-made-components/events/2-event-test.d.ts +8 -8
- package/dist/pre-made-components/events/2-event-test.js +156 -119
- package/dist/pre-made-components/events/2-script-test.js +0 -1
- package/dist/pre-made-components/events/event-setup.d.ts +10 -5
- package/dist/pre-made-components/events/event-setup.js +15 -15
- package/dist/pre-made-components/events/script-setup.d.ts +5 -3
- package/dist/pre-made-components/events/script-setup.js +11 -11
- package/package.json +5 -10
|
@@ -1,135 +1,143 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const mocks_1 = require(
|
|
4
|
-
const raw_definition_helper_1 = require(
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
const mocks_1 = require('../../_mocks/mocks');
|
|
4
|
+
const raw_definition_helper_1 = require('./raw-definition.helper');
|
|
5
5
|
const ComponentName = 'ASSET';
|
|
6
6
|
describe('RAW DEFINITION HELPER', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
}
|
|
7
|
+
describe('Find Parsed Structure', () => {
|
|
8
|
+
test('nested definition', () => {
|
|
9
|
+
let rawDefinition = {
|
|
10
|
+
componentName: ComponentName,
|
|
11
|
+
location: mocks_1.SampleLocation1,
|
|
12
|
+
parsedStructure: {
|
|
13
|
+
line: mocks_1.SampleLocation1.line + 1,
|
|
14
|
+
rawData: {
|
|
15
|
+
obj1: {
|
|
16
|
+
line: mocks_1.SampleLocation1.line + 2,
|
|
17
|
+
rawData: [
|
|
18
|
+
{
|
|
19
|
+
line: mocks_1.SampleLocation1.line + 3,
|
|
20
|
+
rawData: {
|
|
21
|
+
obj2: {
|
|
22
|
+
line: mocks_1.SampleLocation1.line + 4,
|
|
23
|
+
rawData: 'test data'
|
|
29
24
|
}
|
|
25
|
+
}
|
|
30
26
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
expect(raw_definition_helper_1.RawDefinitionHelper.findLine(rawDefinition, [])).toEqual(mocks_1.SampleLocation1.line + 1);
|
|
33
|
+
expect(raw_definition_helper_1.RawDefinitionHelper.findLine(rawDefinition, ['obj1'])).toEqual(
|
|
34
|
+
mocks_1.SampleLocation1.line + 2
|
|
35
|
+
);
|
|
36
|
+
expect(raw_definition_helper_1.RawDefinitionHelper.findLine(rawDefinition, ['obj1', 0])).toEqual(
|
|
37
|
+
mocks_1.SampleLocation1.line + 3
|
|
38
|
+
);
|
|
39
|
+
expect(raw_definition_helper_1.RawDefinitionHelper.findLine(rawDefinition, ['obj1', 0, 'obj2'])).toEqual(
|
|
40
|
+
mocks_1.SampleLocation1.line + 4
|
|
41
|
+
);
|
|
42
|
+
expect(raw_definition_helper_1.RawDefinitionHelper.findLine(rawDefinition, ['notExists'])).toEqual(
|
|
43
|
+
mocks_1.SampleLocation1.line + 1
|
|
44
|
+
);
|
|
38
45
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
});
|
|
47
|
+
describe('Flattening', () => {
|
|
48
|
+
test('primitive', () => {
|
|
49
|
+
let rawDefinition = {
|
|
50
|
+
componentName: ComponentName,
|
|
51
|
+
location: mocks_1.SampleLocation1,
|
|
52
|
+
parsedStructure: {
|
|
53
|
+
line: 0,
|
|
54
|
+
rawData: 'test'
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
let expected = 'test';
|
|
58
|
+
expect(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition)).toStrictEqual(expected);
|
|
59
|
+
});
|
|
60
|
+
test('array', () => {
|
|
61
|
+
let rawDefinition = {
|
|
62
|
+
componentName: ComponentName,
|
|
63
|
+
location: mocks_1.SampleLocation1,
|
|
64
|
+
parsedStructure: {
|
|
65
|
+
line: 0,
|
|
66
|
+
rawData: [
|
|
67
|
+
{
|
|
68
|
+
line: 0,
|
|
69
|
+
rawData: [
|
|
70
|
+
{
|
|
71
|
+
line: 0,
|
|
72
|
+
rawData: 'orange'
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
line: 0,
|
|
76
|
+
rawData: 'banana'
|
|
47
77
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
line: 0,
|
|
61
|
-
rawData: [
|
|
62
|
-
{
|
|
63
|
-
line: 0,
|
|
64
|
-
rawData: 'orange'
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
line: 0,
|
|
68
|
-
rawData: 'banana'
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
line: 0,
|
|
74
|
-
rawData: [
|
|
75
|
-
{
|
|
76
|
-
line: 0,
|
|
77
|
-
rawData: '1'
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
line: 0,
|
|
81
|
-
rawData: '2'
|
|
82
|
-
}
|
|
83
|
-
]
|
|
84
|
-
}
|
|
85
|
-
]
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
line: 0,
|
|
82
|
+
rawData: [
|
|
83
|
+
{
|
|
84
|
+
line: 0,
|
|
85
|
+
rawData: '1'
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
line: 0,
|
|
89
|
+
rawData: '2'
|
|
86
90
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
let expected = [
|
|
97
|
+
['orange', 'banana'],
|
|
98
|
+
['1', '2']
|
|
99
|
+
];
|
|
100
|
+
expect(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition)).toStrictEqual(expected);
|
|
101
|
+
});
|
|
102
|
+
test('object', () => {
|
|
103
|
+
let rawDefinition = {
|
|
104
|
+
componentName: ComponentName,
|
|
105
|
+
location: mocks_1.SampleLocation1,
|
|
106
|
+
parsedStructure: {
|
|
107
|
+
line: 0,
|
|
108
|
+
rawData: {
|
|
109
|
+
array1: {
|
|
110
|
+
line: 0,
|
|
111
|
+
rawData: [
|
|
112
|
+
{
|
|
113
|
+
line: 0,
|
|
114
|
+
rawData: 'apple'
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
line: 0,
|
|
118
|
+
rawData: 'orange'
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
array2: {
|
|
123
|
+
line: 0,
|
|
124
|
+
rawData: [
|
|
125
|
+
{
|
|
126
|
+
line: 0,
|
|
127
|
+
rawData: 'xWing'
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
line: 0,
|
|
131
|
+
rawData: 'tieFighter'
|
|
128
132
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
let expected = { array1: ['apple', 'orange'], array2: ['xWing', 'tieFighter'] };
|
|
139
|
+
expect(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition)).toStrictEqual(expected);
|
|
133
140
|
});
|
|
141
|
+
});
|
|
134
142
|
});
|
|
135
|
-
//# sourceMappingURL=raw-definition.helper.spec.js.map
|
|
143
|
+
//# sourceMappingURL=raw-definition.helper.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AssetComponentName =
|
|
1
|
+
export declare const AssetComponentName = 'ASSET';
|
|
@@ -1,173 +1,191 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault =
|
|
3
|
+
(this && this.__importDefault) ||
|
|
4
|
+
function (mod) {
|
|
5
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6
8
|
exports.AssetComponentName = void 0;
|
|
7
|
-
const joi_1 = __importDefault(require(
|
|
8
|
-
const joi_custom_validators_1 = require(
|
|
9
|
-
const mocks_1 = require(
|
|
10
|
-
const raw_definition_helper_1 = require(
|
|
11
|
-
const custom_validator_helper_1 = require(
|
|
12
|
-
const context_1 = require(
|
|
13
|
-
const definition_store_1 = require(
|
|
14
|
-
joi_custom_validators_1.JoiCustomValidators.decorate(joi_1.default, { existsSync:
|
|
9
|
+
const joi_1 = __importDefault(require('joi'));
|
|
10
|
+
const joi_custom_validators_1 = require('../joi-custom-validators');
|
|
11
|
+
const mocks_1 = require('../../../_mocks/mocks');
|
|
12
|
+
const raw_definition_helper_1 = require('../../raw-definition-helper/raw-definition.helper');
|
|
13
|
+
const custom_validator_helper_1 = require('./custom-validator.helper');
|
|
14
|
+
const context_1 = require('../../../framework/context');
|
|
15
|
+
const definition_store_1 = require('../../../framework/definition-store');
|
|
16
|
+
joi_custom_validators_1.JoiCustomValidators.decorate(joi_1.default, { existsSync: path => path !== 'D:/test/false/path.png' });
|
|
15
17
|
exports.AssetComponentName = 'ASSET';
|
|
16
18
|
class Asset {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
static {
|
|
20
|
+
this.$meta = {
|
|
21
|
+
componentName: exports.AssetComponentName
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async process() {}
|
|
21
25
|
}
|
|
22
26
|
class AssetGroup {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
static {
|
|
28
|
+
this.$meta = {
|
|
29
|
+
componentName: 'ASSET-GROUP'
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async process() {}
|
|
27
33
|
}
|
|
28
34
|
function getSimpleRawDefinition(value, offset = 1) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
}
|
|
35
|
+
return {
|
|
36
|
+
componentName: exports.AssetComponentName,
|
|
37
|
+
location: mocks_1.SampleLocation1,
|
|
38
|
+
parsedStructure: {
|
|
39
|
+
line: mocks_1.SampleLocation1.line + offset,
|
|
40
|
+
rawData: {
|
|
41
|
+
value: {
|
|
42
|
+
rawData: value,
|
|
43
|
+
line: mocks_1.SampleLocation1.line + offset
|
|
40
44
|
}
|
|
41
|
-
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
42
48
|
}
|
|
43
49
|
function getFlatRawDefinition(value, offset = 1) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
return {
|
|
51
|
+
componentName: exports.AssetComponentName,
|
|
52
|
+
location: mocks_1.SampleLocation1,
|
|
53
|
+
parsedStructure: {
|
|
54
|
+
line: mocks_1.SampleLocation1.line + offset,
|
|
55
|
+
rawData: value
|
|
56
|
+
}
|
|
57
|
+
};
|
|
52
58
|
}
|
|
53
59
|
describe('JOI CUSTOM VALIDATORS', () => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
beforeEach(() => {
|
|
61
|
+
context_1.Context.config.projectRoot = 'D:/';
|
|
62
|
+
custom_validator_helper_1.CustomValidatorHelper['duplicateHelpers'] = new Map();
|
|
63
|
+
});
|
|
64
|
+
describe('Variable Name', () => {
|
|
65
|
+
let schema = joi_1.default.object().keys({
|
|
66
|
+
value: joi_1.default.string().required()
|
|
67
|
+
});
|
|
68
|
+
test('valid data', () => {
|
|
69
|
+
let rawDefinition = getSimpleRawDefinition('test');
|
|
70
|
+
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
71
|
+
abortEarly: false,
|
|
72
|
+
context: rawDefinition
|
|
73
|
+
});
|
|
74
|
+
expect(value).toEqual({ value: 'test' });
|
|
75
|
+
expect(error).toEqual(undefined);
|
|
76
|
+
});
|
|
77
|
+
test('different groups should not create duplicates', () => {
|
|
78
|
+
let schema2 = joi_1.default.object().keys({
|
|
79
|
+
value: joi_1.default.string().required()
|
|
80
|
+
});
|
|
81
|
+
let rawDefinition1 = getSimpleRawDefinition('test', 1);
|
|
82
|
+
let rawDefinition2 = getSimpleRawDefinition('test', 2);
|
|
83
|
+
schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition1), {
|
|
84
|
+
abortEarly: false,
|
|
85
|
+
context: rawDefinition1
|
|
86
|
+
});
|
|
87
|
+
schema2.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition2), {
|
|
88
|
+
abortEarly: false,
|
|
89
|
+
context: rawDefinition2
|
|
90
|
+
});
|
|
91
|
+
(0, mocks_1.resetContext)();
|
|
92
|
+
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
93
|
+
expect(context_1.Context.errorLogs).toStrictEqual([]);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('Reference', () => {
|
|
97
|
+
let schema = joi_1.default.object().keys({
|
|
98
|
+
value: joi_1.default.string().reference(Asset).required()
|
|
57
99
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
value: joi_1.default.string().required()
|
|
61
|
-
});
|
|
62
|
-
test('valid data', () => {
|
|
63
|
-
let rawDefinition = getSimpleRawDefinition('test');
|
|
64
|
-
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
65
|
-
abortEarly: false,
|
|
66
|
-
context: rawDefinition
|
|
67
|
-
});
|
|
68
|
-
expect(value).toEqual({ value: 'test' });
|
|
69
|
-
expect(error).toEqual(undefined);
|
|
70
|
-
});
|
|
71
|
-
test('different groups should not create duplicates', () => {
|
|
72
|
-
let schema2 = joi_1.default.object().keys({
|
|
73
|
-
value: joi_1.default.string().required()
|
|
74
|
-
});
|
|
75
|
-
let rawDefinition1 = getSimpleRawDefinition('test', 1);
|
|
76
|
-
let rawDefinition2 = getSimpleRawDefinition('test', 2);
|
|
77
|
-
schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition1), { abortEarly: false, context: rawDefinition1 });
|
|
78
|
-
schema2.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition2), { abortEarly: false, context: rawDefinition2 });
|
|
79
|
-
(0, mocks_1.resetContext)();
|
|
80
|
-
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
81
|
-
expect(context_1.Context.errorLogs).toStrictEqual([]);
|
|
82
|
-
});
|
|
100
|
+
let multipleSchema = joi_1.default.object().keys({
|
|
101
|
+
value: joi_1.default.string().reference([AssetGroup, Asset]).required()
|
|
83
102
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
definition_store_1.DefinitionStore['setRawDefinition'](Asset, 'test', rawDefinition);
|
|
94
|
-
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
95
|
-
abortEarly: false,
|
|
96
|
-
context: rawDefinition
|
|
97
|
-
});
|
|
98
|
-
expect(value).toEqual({ value: 'test' });
|
|
99
|
-
expect(error).toEqual(undefined);
|
|
100
|
-
});
|
|
101
|
-
test('multiple reference', () => {
|
|
102
|
-
let rawDefinition = getSimpleRawDefinition('test');
|
|
103
|
-
definition_store_1.DefinitionStore['setRawDefinition'](Asset, 'test', rawDefinition);
|
|
104
|
-
let { value, error } = multipleSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
105
|
-
abortEarly: false,
|
|
106
|
-
context: rawDefinition
|
|
107
|
-
});
|
|
108
|
-
expect(value).toEqual({ value: 'test' });
|
|
109
|
-
expect(error).toEqual(undefined);
|
|
110
|
-
});
|
|
111
|
-
test('primitive valid data', () => {
|
|
112
|
-
let rawDefinition = getFlatRawDefinition('test');
|
|
113
|
-
let primitiveSchema = joi_1.default.string().reference(Asset).required();
|
|
114
|
-
definition_store_1.DefinitionStore['setRawDefinition'](Asset, 'test', rawDefinition);
|
|
115
|
-
let { value, error } = primitiveSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
116
|
-
abortEarly: false,
|
|
117
|
-
context: rawDefinition
|
|
118
|
-
});
|
|
119
|
-
expect(value).toEqual('test');
|
|
120
|
-
expect(error).toEqual(undefined);
|
|
121
|
-
});
|
|
103
|
+
test('valid data', () => {
|
|
104
|
+
let rawDefinition = getSimpleRawDefinition('test');
|
|
105
|
+
definition_store_1.DefinitionStore['setRawDefinition'](Asset, 'test', rawDefinition);
|
|
106
|
+
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
107
|
+
abortEarly: false,
|
|
108
|
+
context: rawDefinition
|
|
109
|
+
});
|
|
110
|
+
expect(value).toEqual({ value: 'test' });
|
|
111
|
+
expect(error).toEqual(undefined);
|
|
122
112
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
113
|
+
test('multiple reference', () => {
|
|
114
|
+
let rawDefinition = getSimpleRawDefinition('test');
|
|
115
|
+
definition_store_1.DefinitionStore['setRawDefinition'](Asset, 'test', rawDefinition);
|
|
116
|
+
let { value, error } = multipleSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
117
|
+
abortEarly: false,
|
|
118
|
+
context: rawDefinition
|
|
119
|
+
});
|
|
120
|
+
expect(value).toEqual({ value: 'test' });
|
|
121
|
+
expect(error).toEqual(undefined);
|
|
122
|
+
});
|
|
123
|
+
test('primitive valid data', () => {
|
|
124
|
+
let rawDefinition = getFlatRawDefinition('test');
|
|
125
|
+
let primitiveSchema = joi_1.default.string().reference(Asset).required();
|
|
126
|
+
definition_store_1.DefinitionStore['setRawDefinition'](Asset, 'test', rawDefinition);
|
|
127
|
+
let { value, error } = primitiveSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
128
|
+
abortEarly: false,
|
|
129
|
+
context: rawDefinition
|
|
130
|
+
});
|
|
131
|
+
expect(value).toEqual('test');
|
|
132
|
+
expect(error).toEqual(undefined);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
describe('Path', () => {
|
|
136
|
+
let schema = joi_1.default.object().keys({
|
|
137
|
+
value: joi_1.default.string().path().required()
|
|
138
|
+
});
|
|
139
|
+
test('valid data', () => {
|
|
140
|
+
let rawDefinition = getSimpleRawDefinition('images/test.png');
|
|
141
|
+
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
142
|
+
abortEarly: false,
|
|
143
|
+
context: rawDefinition
|
|
144
|
+
});
|
|
145
|
+
expect(value).toEqual({ value: '.test/images/test.png' });
|
|
146
|
+
expect(error).toEqual(undefined);
|
|
147
|
+
});
|
|
148
|
+
test('should detect files not existing, invalid url', () => {
|
|
149
|
+
let rawDefinition = getSimpleRawDefinition('invalid data');
|
|
150
|
+
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
151
|
+
abortEarly: false,
|
|
152
|
+
context: rawDefinition
|
|
153
|
+
});
|
|
154
|
+
expect(error?.details).toStrictEqual([
|
|
155
|
+
{
|
|
156
|
+
message: '"value" with value "invalid data" fails to match the required pattern: /^[\\S]+$/',
|
|
157
|
+
path: ['value'],
|
|
158
|
+
type: 'string.pattern.base',
|
|
159
|
+
context: {
|
|
160
|
+
name: undefined,
|
|
161
|
+
regex: /^[\S]+$/,
|
|
162
|
+
value: 'invalid data',
|
|
163
|
+
label: 'value',
|
|
164
|
+
key: 'value'
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
]);
|
|
168
|
+
});
|
|
169
|
+
test('should detect files not existing, missing file', () => {
|
|
170
|
+
let rawDefinition = getSimpleRawDefinition('false/path.png');
|
|
171
|
+
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
172
|
+
abortEarly: false,
|
|
173
|
+
context: rawDefinition
|
|
174
|
+
});
|
|
175
|
+
expect(error?.details).toStrictEqual([
|
|
176
|
+
{
|
|
177
|
+
message: '"value" failed custom validation because No file is found in the path: "D:/test/false/path.png"',
|
|
178
|
+
path: ['value'],
|
|
179
|
+
type: 'any.custom',
|
|
180
|
+
context: {
|
|
181
|
+
error: new Error('No file is found in the path: "D:/test/false/path.png"'),
|
|
182
|
+
label: 'value',
|
|
183
|
+
value: 'false/path.png',
|
|
184
|
+
key: 'value'
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
]);
|
|
171
188
|
});
|
|
189
|
+
});
|
|
172
190
|
});
|
|
173
|
-
//# sourceMappingURL=custom-validator.helper.spec.js.map
|
|
191
|
+
//# sourceMappingURL=custom-validator.helper.spec.js.map
|
|
@@ -3,12 +3,12 @@ import { Vec2 } from 'pixi-framework';
|
|
|
3
3
|
import { CustomValidator } from '../joi-custom-validators';
|
|
4
4
|
import { FileSystem } from '../../../framework/framework.model';
|
|
5
5
|
export interface ValidatedImageUrl {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
readonly url: string;
|
|
7
|
+
readonly size: Vec2;
|
|
8
8
|
}
|
|
9
9
|
export declare class ImageCustomValidator implements CustomValidator {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
private fs;
|
|
11
|
+
readonly regex: RegExp;
|
|
12
|
+
readonly validate: (value: string, helpers: Joi.CustomHelpers) => any | ErrorReport;
|
|
13
|
+
constructor(fs: FileSystem);
|
|
14
14
|
}
|