definition-generator-framework 1.13.1 → 2.0.0-rc1
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 +204 -0
- package/dist/index.d.ts +204 -17
- package/dist/index.js +43 -50
- package/dist/index.mjs +43 -0
- package/package.json +28 -14
- 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,191 +0,0 @@
|
|
|
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 });
|
|
8
|
-
exports.AssetComponentName = void 0;
|
|
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' });
|
|
17
|
-
exports.AssetComponentName = 'ASSET';
|
|
18
|
-
class Asset {
|
|
19
|
-
static {
|
|
20
|
-
this.$meta = {
|
|
21
|
-
componentName: exports.AssetComponentName
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
async process() {}
|
|
25
|
-
}
|
|
26
|
-
class AssetGroup {
|
|
27
|
-
static {
|
|
28
|
-
this.$meta = {
|
|
29
|
-
componentName: 'ASSET-GROUP'
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
async process() {}
|
|
33
|
-
}
|
|
34
|
-
function getSimpleRawDefinition(value, offset = 1) {
|
|
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
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function getFlatRawDefinition(value, offset = 1) {
|
|
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
|
-
};
|
|
58
|
-
}
|
|
59
|
-
describe('JOI CUSTOM VALIDATORS', () => {
|
|
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()
|
|
99
|
-
});
|
|
100
|
-
let multipleSchema = joi_1.default.object().keys({
|
|
101
|
-
value: joi_1.default.string().reference([AssetGroup, Asset]).required()
|
|
102
|
-
});
|
|
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);
|
|
112
|
-
});
|
|
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
|
-
]);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
//# sourceMappingURL=custom-validator.helper.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const AssetComponentName = "ASSET";
|
|
@@ -1,213 +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.AssetComponentName = void 0;
|
|
7
|
-
const joi_1 = __importDefault(require("joi"));
|
|
8
|
-
const vitest_1 = require("vitest");
|
|
9
|
-
const mocks_1 = require("../../../_mocks/mocks");
|
|
10
|
-
const context_1 = require("../../../framework/context");
|
|
11
|
-
const definition_store_1 = require("../../../framework/definition-store");
|
|
12
|
-
const raw_definition_helper_1 = require("../../raw-definition-helper/raw-definition.helper");
|
|
13
|
-
const joi_custom_validators_1 = require("../joi-custom-validators");
|
|
14
|
-
const custom_validator_helper_1 = require("./custom-validator.helper");
|
|
15
|
-
joi_custom_validators_1.JoiCustomValidators.decorate(joi_1.default, { existsSync: (path) => path !== 'D:/test/false/path.png' });
|
|
16
|
-
exports.AssetComponentName = 'ASSET';
|
|
17
|
-
class Asset {
|
|
18
|
-
static { this.$meta = {
|
|
19
|
-
keyName: 'id',
|
|
20
|
-
componentName: exports.AssetComponentName
|
|
21
|
-
}; }
|
|
22
|
-
async process() { }
|
|
23
|
-
}
|
|
24
|
-
const AssetGroupComponentName = 'ASSET-GROUP';
|
|
25
|
-
class AssetGroup {
|
|
26
|
-
static { this.$meta = {
|
|
27
|
-
keyName: 'id',
|
|
28
|
-
componentName: 'ASSET-GROUP'
|
|
29
|
-
}; }
|
|
30
|
-
async process() { }
|
|
31
|
-
}
|
|
32
|
-
definition_store_1.DefinitionStore['setComponents'](new Map([
|
|
33
|
-
[exports.AssetComponentName, Asset],
|
|
34
|
-
[AssetGroupComponentName, AssetGroup]
|
|
35
|
-
]));
|
|
36
|
-
function getSimpleRawDefinition(value, offset = 1) {
|
|
37
|
-
return {
|
|
38
|
-
componentName: exports.AssetComponentName,
|
|
39
|
-
location: mocks_1.SampleLocation1,
|
|
40
|
-
parsedStructure: {
|
|
41
|
-
line: mocks_1.SampleLocation1.line + offset,
|
|
42
|
-
rawData: {
|
|
43
|
-
value: {
|
|
44
|
-
rawData: value,
|
|
45
|
-
line: mocks_1.SampleLocation1.line + offset
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function getFlatRawDefinition(value, offset = 1) {
|
|
52
|
-
return {
|
|
53
|
-
componentName: exports.AssetComponentName,
|
|
54
|
-
location: mocks_1.SampleLocation1,
|
|
55
|
-
parsedStructure: {
|
|
56
|
-
line: mocks_1.SampleLocation1.line + offset,
|
|
57
|
-
rawData: value
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
(0, vitest_1.describe)('JOI CUSTOM VALIDATORS', () => {
|
|
62
|
-
(0, vitest_1.beforeEach)(() => {
|
|
63
|
-
context_1.Context.config.projectRoot = 'D:/';
|
|
64
|
-
custom_validator_helper_1.CustomValidatorHelper['duplicateHelpers'] = new Map();
|
|
65
|
-
});
|
|
66
|
-
(0, vitest_1.describe)('Variable Name', () => {
|
|
67
|
-
let schema = joi_1.default.object().keys({
|
|
68
|
-
value: joi_1.default.string().required()
|
|
69
|
-
});
|
|
70
|
-
(0, vitest_1.test)('valid data', () => {
|
|
71
|
-
let rawDefinition = getSimpleRawDefinition('test');
|
|
72
|
-
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
73
|
-
abortEarly: false,
|
|
74
|
-
context: { rawDefinition }
|
|
75
|
-
});
|
|
76
|
-
(0, vitest_1.expect)(value).toEqual({ value: 'test' });
|
|
77
|
-
(0, vitest_1.expect)(error).toEqual(undefined);
|
|
78
|
-
});
|
|
79
|
-
(0, vitest_1.test)('different groups should not create duplicates', () => {
|
|
80
|
-
let schema2 = joi_1.default.object().keys({
|
|
81
|
-
value: joi_1.default.string().required()
|
|
82
|
-
});
|
|
83
|
-
let rawDefinition1 = getSimpleRawDefinition('test', 1);
|
|
84
|
-
let rawDefinition2 = getSimpleRawDefinition('test', 2);
|
|
85
|
-
schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition1), {
|
|
86
|
-
abortEarly: false,
|
|
87
|
-
context: { rawDefinition: rawDefinition1 }
|
|
88
|
-
});
|
|
89
|
-
schema2.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition2), {
|
|
90
|
-
abortEarly: false,
|
|
91
|
-
context: { rawDefinition: rawDefinition2 }
|
|
92
|
-
});
|
|
93
|
-
(0, mocks_1.resetContext)();
|
|
94
|
-
custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
|
|
95
|
-
(0, vitest_1.expect)(context_1.Context['errorLogBuffer']).toStrictEqual([]);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
(0, vitest_1.describe)('Reference', () => {
|
|
99
|
-
let schema = joi_1.default.object().keys({
|
|
100
|
-
value: joi_1.default.string().reference(Asset).required()
|
|
101
|
-
});
|
|
102
|
-
let multipleSchema = joi_1.default.object().keys({
|
|
103
|
-
value: joi_1.default.string().reference([AssetGroup, Asset]).required()
|
|
104
|
-
});
|
|
105
|
-
(0, vitest_1.test)('valid data', () => {
|
|
106
|
-
let rawDefinition = getSimpleRawDefinition('test');
|
|
107
|
-
let flattened = raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition);
|
|
108
|
-
definition_store_1.DefinitionStore['setRawDefinitionByKey'](Asset, 'test', rawDefinition);
|
|
109
|
-
definition_store_1.DefinitionStore['setDefinition'](Asset, 'test', flattened);
|
|
110
|
-
let { value, error } = schema.validate(flattened, {
|
|
111
|
-
abortEarly: false,
|
|
112
|
-
context: { rawDefinition }
|
|
113
|
-
});
|
|
114
|
-
(0, vitest_1.expect)(value).toEqual({ value: 'test' });
|
|
115
|
-
(0, vitest_1.expect)(error).toEqual(undefined);
|
|
116
|
-
});
|
|
117
|
-
(0, vitest_1.test)('multiple reference', () => {
|
|
118
|
-
let rawDefinition = getSimpleRawDefinition('test');
|
|
119
|
-
let flattened = raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition);
|
|
120
|
-
definition_store_1.DefinitionStore['setRawDefinitionByKey'](Asset, 'test', rawDefinition);
|
|
121
|
-
definition_store_1.DefinitionStore['setDefinition'](Asset, 'test', flattened);
|
|
122
|
-
let { value, error } = multipleSchema.validate(flattened, {
|
|
123
|
-
abortEarly: false,
|
|
124
|
-
context: { rawDefinition }
|
|
125
|
-
});
|
|
126
|
-
(0, vitest_1.expect)(value).toEqual({
|
|
127
|
-
value: {
|
|
128
|
-
type: 'ASSET',
|
|
129
|
-
value: 'test'
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
(0, vitest_1.expect)(error).toEqual(undefined);
|
|
133
|
-
});
|
|
134
|
-
(0, vitest_1.test)('silently fail when self referenced definition fails its validation', () => {
|
|
135
|
-
let rawDefinition = getFlatRawDefinition('test');
|
|
136
|
-
let primitiveSchema = joi_1.default.string().reference(Asset).required();
|
|
137
|
-
definition_store_1.DefinitionStore['setRawDefinitionByKey'](Asset, 'test', rawDefinition);
|
|
138
|
-
let { value, error } = primitiveSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
139
|
-
abortEarly: false,
|
|
140
|
-
context: { rawDefinition }
|
|
141
|
-
});
|
|
142
|
-
(0, vitest_1.expect)(value).toEqual('test');
|
|
143
|
-
(0, vitest_1.expect)(error).toEqual(undefined);
|
|
144
|
-
});
|
|
145
|
-
(0, vitest_1.test)('primitive valid data', () => {
|
|
146
|
-
let rawDefinition = getFlatRawDefinition('test');
|
|
147
|
-
let primitiveSchema = joi_1.default.string().reference(Asset).required();
|
|
148
|
-
definition_store_1.DefinitionStore['setRawDefinitionByKey'](Asset, 'test', rawDefinition);
|
|
149
|
-
let { value, error } = primitiveSchema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
150
|
-
abortEarly: false,
|
|
151
|
-
context: { rawDefinition }
|
|
152
|
-
});
|
|
153
|
-
(0, vitest_1.expect)(value).toEqual('test');
|
|
154
|
-
(0, vitest_1.expect)(error).toEqual(undefined);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
(0, vitest_1.describe)('Path', () => {
|
|
158
|
-
let schema = joi_1.default.object().keys({
|
|
159
|
-
value: joi_1.default.string().path().required()
|
|
160
|
-
});
|
|
161
|
-
(0, vitest_1.test)('valid data', () => {
|
|
162
|
-
let rawDefinition = getSimpleRawDefinition('images/test.png');
|
|
163
|
-
let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
164
|
-
abortEarly: false,
|
|
165
|
-
context: { rawDefinition }
|
|
166
|
-
});
|
|
167
|
-
(0, vitest_1.expect)(value).toEqual({ value: '.test/images/test.png' });
|
|
168
|
-
(0, vitest_1.expect)(error).toEqual(undefined);
|
|
169
|
-
});
|
|
170
|
-
(0, vitest_1.test)('should detect files not existing, invalid url', () => {
|
|
171
|
-
let rawDefinition = getSimpleRawDefinition('invalid data');
|
|
172
|
-
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
173
|
-
abortEarly: false,
|
|
174
|
-
context: { rawDefinition }
|
|
175
|
-
});
|
|
176
|
-
(0, vitest_1.expect)(error?.details).toStrictEqual([
|
|
177
|
-
{
|
|
178
|
-
message: '"value" with value "invalid data" fails to match the required pattern: /^[\\S]+$/',
|
|
179
|
-
path: ['value'],
|
|
180
|
-
type: 'string.pattern.base',
|
|
181
|
-
context: {
|
|
182
|
-
name: undefined,
|
|
183
|
-
regex: /^[\S]+$/,
|
|
184
|
-
value: 'invalid data',
|
|
185
|
-
label: 'value',
|
|
186
|
-
key: 'value'
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
]);
|
|
190
|
-
});
|
|
191
|
-
(0, vitest_1.test)('should detect files not existing, missing file', () => {
|
|
192
|
-
let rawDefinition = getSimpleRawDefinition('false/path.png');
|
|
193
|
-
let { error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
|
|
194
|
-
abortEarly: false,
|
|
195
|
-
context: { rawDefinition }
|
|
196
|
-
});
|
|
197
|
-
(0, vitest_1.expect)(error?.details).toStrictEqual([
|
|
198
|
-
{
|
|
199
|
-
message: '"value" failed custom validation because No file is found in the path: "D:/test/false/path.png"',
|
|
200
|
-
path: ['value'],
|
|
201
|
-
type: 'any.custom',
|
|
202
|
-
context: {
|
|
203
|
-
error: new Error('No file is found in the path: "D:/test/false/path.png"'),
|
|
204
|
-
label: 'value',
|
|
205
|
-
value: 'false/path.png',
|
|
206
|
-
key: 'value'
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
]);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
//# sourceMappingURL=custom-validator.helper.test.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Vec2 } from 'helpers-lib';
|
|
2
|
-
export declare class SpriteValidationHelper {
|
|
3
|
-
private anchorLocation;
|
|
4
|
-
private scale;
|
|
5
|
-
private boundingBox;
|
|
6
|
-
private checkIfPositionIsOnSprite;
|
|
7
|
-
constructor(spriteSize: Vec2, anchor: Vec2, scale: number, checkIfPositionIsOnSprite?: boolean);
|
|
8
|
-
convertPositionToSpriteAnchor(position: Vec2): Vec2;
|
|
9
|
-
getRotationFromAnchor(positionFromAnchor: Vec2): number;
|
|
10
|
-
private validateLocationOnSprite;
|
|
11
|
-
private getAnchorLocation;
|
|
12
|
-
private getBoundingBox;
|
|
13
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SpriteValidationHelper = void 0;
|
|
4
|
-
const helpers_lib_1 = require("helpers-lib");
|
|
5
|
-
class SpriteValidationHelper {
|
|
6
|
-
constructor(spriteSize, anchor, scale, checkIfPositionIsOnSprite) {
|
|
7
|
-
spriteSize = { x: spriteSize.x * scale, y: spriteSize.y * scale };
|
|
8
|
-
this.scale = scale;
|
|
9
|
-
this.checkIfPositionIsOnSprite = checkIfPositionIsOnSprite || false;
|
|
10
|
-
this.anchorLocation = this.getAnchorLocation(spriteSize, anchor);
|
|
11
|
-
this.boundingBox = this.getBoundingBox(spriteSize, this.anchorLocation);
|
|
12
|
-
}
|
|
13
|
-
convertPositionToSpriteAnchor(position) {
|
|
14
|
-
position = { x: position.x * this.scale, y: position.y * this.scale };
|
|
15
|
-
let positionToSpriteAnchor = {
|
|
16
|
-
x: position.x + this.boundingBox.topLeft.x,
|
|
17
|
-
y: position.y + this.boundingBox.topLeft.y
|
|
18
|
-
};
|
|
19
|
-
if (this.checkIfPositionIsOnSprite) {
|
|
20
|
-
let valid = this.validateLocationOnSprite(positionToSpriteAnchor);
|
|
21
|
-
if (!valid) {
|
|
22
|
-
throw new Error(`location is outside of the sprite boundaries. Entered position: {x: ${position.x}, y: ${position.y}}, position on sprite: {x: ${positionToSpriteAnchor.x}, y: ${positionToSpriteAnchor.y}}, bounding box: ${JSON.stringify(this.boundingBox)}.`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return positionToSpriteAnchor;
|
|
26
|
-
}
|
|
27
|
-
getRotationFromAnchor(positionFromAnchor) {
|
|
28
|
-
return helpers_lib_1.Vector.fromVec2(positionFromAnchor).radian.value;
|
|
29
|
-
}
|
|
30
|
-
validateLocationOnSprite(location) {
|
|
31
|
-
if (location.x < this.boundingBox.topLeft.x ||
|
|
32
|
-
location.x > this.boundingBox.bottomRight.x ||
|
|
33
|
-
location.y < this.boundingBox.topLeft.y ||
|
|
34
|
-
location.y > this.boundingBox.bottomRight.y) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
getAnchorLocation(spriteSize, anchor) {
|
|
42
|
-
return { x: spriteSize.x * anchor.x, y: spriteSize.y * anchor.y };
|
|
43
|
-
}
|
|
44
|
-
getBoundingBox(spriteSize, anchorLocation) {
|
|
45
|
-
let boundingBox = {
|
|
46
|
-
topLeft: { x: -anchorLocation.x, y: -anchorLocation.y },
|
|
47
|
-
bottomRight: { x: spriteSize.x - anchorLocation.x, y: spriteSize.y - anchorLocation.y }
|
|
48
|
-
};
|
|
49
|
-
return boundingBox;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.SpriteValidationHelper = SpriteValidationHelper;
|
|
53
|
-
//# sourceMappingURL=sprite-validation.helper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const sprite_validation_helper_1 = require("./sprite-validation.helper");
|
|
5
|
-
(0, vitest_1.describe)('Validators', () => {
|
|
6
|
-
(0, vitest_1.describe)('convertPositionToSpriteAnchor', () => {
|
|
7
|
-
(0, vitest_1.test)('should convert the location to the sprite location', () => {
|
|
8
|
-
let location = { x: 50, y: 50 };
|
|
9
|
-
let spriteSize = { x: 100, y: 100 };
|
|
10
|
-
let anchor = { x: 0.8, y: 0.5 };
|
|
11
|
-
let spriteValidationHelper = new sprite_validation_helper_1.SpriteValidationHelper(spriteSize, anchor, 1);
|
|
12
|
-
(0, vitest_1.expect)(spriteValidationHelper.convertPositionToSpriteAnchor(location)).toEqual({ x: -30, y: 0 });
|
|
13
|
-
});
|
|
14
|
-
(0, vitest_1.test)('should convert the location with scale to the sprite location', () => {
|
|
15
|
-
let location = { x: 50, y: 50 };
|
|
16
|
-
let spriteSize = { x: 100, y: 100 };
|
|
17
|
-
let anchor = { x: 0.8, y: 0.5 };
|
|
18
|
-
let spriteValidationHelper = new sprite_validation_helper_1.SpriteValidationHelper(spriteSize, anchor, 0.5);
|
|
19
|
-
(0, vitest_1.expect)(spriteValidationHelper.convertPositionToSpriteAnchor(location)).toEqual({ x: -15, y: 0 });
|
|
20
|
-
});
|
|
21
|
-
(0, vitest_1.test)('should throw an error if location is outside of the sprite boundaries', () => {
|
|
22
|
-
let location = { x: -51, y: 51 };
|
|
23
|
-
let spriteSize = { x: 100, y: 100 };
|
|
24
|
-
let anchor = { x: 0.5, y: 0.5 };
|
|
25
|
-
let spriteValidationHelper = new sprite_validation_helper_1.SpriteValidationHelper(spriteSize, anchor, 1, true);
|
|
26
|
-
(0, vitest_1.expect)(() => spriteValidationHelper.convertPositionToSpriteAnchor(location)).toThrow();
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
(0, vitest_1.describe)('getRotationFromAnchor', () => {
|
|
30
|
-
(0, vitest_1.test)('should return the rotation from the anchor sample 1', () => {
|
|
31
|
-
let positionFromAnchor = { x: 25, y: 0 };
|
|
32
|
-
let spriteSize = { x: 100, y: 100 };
|
|
33
|
-
let anchor = { x: 0.5, y: 0.5 };
|
|
34
|
-
let spriteValidationHelper = new sprite_validation_helper_1.SpriteValidationHelper(spriteSize, anchor, 1);
|
|
35
|
-
(0, vitest_1.expect)(spriteValidationHelper.getRotationFromAnchor(positionFromAnchor)).toEqual(Math.PI / 2);
|
|
36
|
-
});
|
|
37
|
-
(0, vitest_1.test)('should return the rotation from the anchor with scale sample 1', () => {
|
|
38
|
-
let positionFromAnchor = { x: 25, y: 0 };
|
|
39
|
-
let spriteSize = { x: 100, y: 100 };
|
|
40
|
-
let anchor = { x: 0.5, y: 0.5 };
|
|
41
|
-
let spriteValidationHelper = new sprite_validation_helper_1.SpriteValidationHelper(spriteSize, anchor, 0.5);
|
|
42
|
-
(0, vitest_1.expect)(spriteValidationHelper.getRotationFromAnchor(positionFromAnchor)).toEqual(Math.PI / 2);
|
|
43
|
-
});
|
|
44
|
-
(0, vitest_1.test)('should return the rotation from the anchor sample 2', () => {
|
|
45
|
-
let positionFromAnchor = { x: 0, y: -25 };
|
|
46
|
-
let spriteSize = { x: 100, y: 100 };
|
|
47
|
-
let anchor = { x: 0.5, y: 0.5 };
|
|
48
|
-
let spriteValidationHelper = new sprite_validation_helper_1.SpriteValidationHelper(spriteSize, anchor, 1);
|
|
49
|
-
(0, vitest_1.expect)(spriteValidationHelper.getRotationFromAnchor(positionFromAnchor)).toEqual(0);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
(0, vitest_1.describe)('validateLocationOnSprite', () => {
|
|
53
|
-
(0, vitest_1.test)('should not throw an error if location on the sprite boundaries', () => {
|
|
54
|
-
let location = { x: -50, y: 50 };
|
|
55
|
-
let spriteSize = { x: 100, y: 100 };
|
|
56
|
-
let anchor = { x: 0.5, y: 0.5 };
|
|
57
|
-
let spriteValidationHelper = new sprite_validation_helper_1.SpriteValidationHelper(spriteSize, anchor, 1);
|
|
58
|
-
(0, vitest_1.expect)(spriteValidationHelper['validateLocationOnSprite'](location)).toEqual(true);
|
|
59
|
-
});
|
|
60
|
-
(0, vitest_1.test)('should not throw an error if location is inside of the sprite with scale boundaries', () => {
|
|
61
|
-
let location = { x: -51, y: 51 };
|
|
62
|
-
let spriteSize = { x: 100, y: 100 };
|
|
63
|
-
let anchor = { x: 0.5, y: 0.5 };
|
|
64
|
-
let spriteValidationHelper = new sprite_validation_helper_1.SpriteValidationHelper(spriteSize, anchor, 2);
|
|
65
|
-
(0, vitest_1.expect)(spriteValidationHelper['validateLocationOnSprite'](location)).toEqual(true);
|
|
66
|
-
});
|
|
67
|
-
(0, vitest_1.test)('should throw an error if location is outside of the sprite boundaries', () => {
|
|
68
|
-
let location = { x: -51, y: 51 };
|
|
69
|
-
let spriteSize = { x: 100, y: 100 };
|
|
70
|
-
let anchor = { x: 0.5, y: 0.5 };
|
|
71
|
-
let spriteValidationHelper = new sprite_validation_helper_1.SpriteValidationHelper(spriteSize, anchor, 1);
|
|
72
|
-
(0, vitest_1.expect)(spriteValidationHelper['validateLocationOnSprite'](location)).toEqual(false);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
(0, vitest_1.describe)('getBoundingBox', () => {
|
|
76
|
-
(0, vitest_1.test)('should return the bounding box of the sprite without scale', () => {
|
|
77
|
-
let spriteSize = { x: 100, y: 100 };
|
|
78
|
-
let anchor = { x: 0.2, y: 0.2 };
|
|
79
|
-
let spriteValidationHelper = new sprite_validation_helper_1.SpriteValidationHelper(spriteSize, anchor, 1);
|
|
80
|
-
(0, vitest_1.expect)(spriteValidationHelper['boundingBox']).toEqual({
|
|
81
|
-
topLeft: { x: -20, y: -20 },
|
|
82
|
-
bottomRight: { x: 80, y: 80 }
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
(0, vitest_1.test)('should return the bounding box of the sprite with scale', () => {
|
|
86
|
-
let spriteSize = { x: 100, y: 100 };
|
|
87
|
-
let anchor = { x: 0.2, y: 0.2 };
|
|
88
|
-
let spriteValidationHelper = new sprite_validation_helper_1.SpriteValidationHelper(spriteSize, anchor, 0.5);
|
|
89
|
-
(0, vitest_1.expect)(spriteValidationHelper['boundingBox']).toEqual({
|
|
90
|
-
topLeft: { x: -10, y: -10 },
|
|
91
|
-
bottomRight: { x: 40, y: 40 }
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
//# sourceMappingURL=sprite-validation.helper.test.js.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import Joi, { ErrorReport } from 'joi';
|
|
2
|
-
import { Vec2 } from 'pixi-framework';
|
|
3
|
-
import { CustomValidator } from '../joi-custom-validators';
|
|
4
|
-
import { FileSystem } from '../../../framework/framework.model';
|
|
5
|
-
export interface ValidatedImageUrl {
|
|
6
|
-
readonly url: string;
|
|
7
|
-
readonly size: Vec2;
|
|
8
|
-
}
|
|
9
|
-
export declare class ImageCustomValidator implements CustomValidator {
|
|
10
|
-
private fs;
|
|
11
|
-
readonly regex: RegExp;
|
|
12
|
-
readonly validate: (value: string, helpers: Joi.CustomHelpers) => any | ErrorReport;
|
|
13
|
-
constructor(fs: FileSystem);
|
|
14
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
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 });
|
|
8
|
-
exports.ImageCustomValidator = void 0;
|
|
9
|
-
const image_size_1 = __importDefault(require('image-size'));
|
|
10
|
-
const custom_validator_helper_1 = require('../custom-validator-helper/custom-validator.helper');
|
|
11
|
-
const context_1 = require('../../../framework/context');
|
|
12
|
-
class ImageCustomValidator {
|
|
13
|
-
constructor(fs) {
|
|
14
|
-
this.fs = fs;
|
|
15
|
-
this.regex = /^[\S]+$/;
|
|
16
|
-
this.validate = (value, helpers) => {
|
|
17
|
-
let validationState = custom_validator_helper_1.CustomValidatorHelper.getValidationState(helpers);
|
|
18
|
-
if (validationState === 'valid') {
|
|
19
|
-
let { rawDefinition } = custom_validator_helper_1.CustomValidatorHelper.getPathAndRawDefinition(helpers);
|
|
20
|
-
let pathPrefix = rawDefinition.location.path.substring(0, rawDefinition.location.path.lastIndexOf('/') + 1);
|
|
21
|
-
value = pathPrefix + value;
|
|
22
|
-
if (!this.fs.existsSync(value)) {
|
|
23
|
-
throw new Error(`No file is found in the path: "${value}"`);
|
|
24
|
-
} else {
|
|
25
|
-
try {
|
|
26
|
-
let size = (0, image_size_1.default)(value);
|
|
27
|
-
return {
|
|
28
|
-
url: value.replace(context_1.Context.config.projectRoot, '.'),
|
|
29
|
-
size: { x: size.width, y: size.height }
|
|
30
|
-
};
|
|
31
|
-
} catch (error) {
|
|
32
|
-
throw new Error(`The file in the path "${value}" is not an image`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
throw new Error(
|
|
37
|
-
`Internal Error; joi validation context for image validator: Path: "${helpers.state.path}", RawDefinition: "${JSON.stringify(helpers.prefs.context)}"`
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.ImageCustomValidator = ImageCustomValidator;
|
|
44
|
-
//# sourceMappingURL=image.custom-validator.js.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import Joi, { ErrorReport } from 'joi';
|
|
2
|
-
import { FileSystem } from '../../../framework/interfaces';
|
|
3
|
-
import { CustomStringValidator } from '../joi-custom-validators';
|
|
4
|
-
export declare class PathCustomValidator implements CustomStringValidator {
|
|
5
|
-
private fs;
|
|
6
|
-
readonly regex: RegExp;
|
|
7
|
-
readonly validate: (value: string, helpers: Joi.CustomHelpers) => any | ErrorReport;
|
|
8
|
-
constructor(fs: FileSystem);
|
|
9
|
-
}
|