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.
Files changed (173) hide show
  1. package/dist/index.d.mts +198 -0
  2. package/dist/index.d.ts +198 -17
  3. package/dist/index.js +43 -50
  4. package/dist/index.mjs +43 -0
  5. package/package.json +27 -13
  6. package/dist/_mocks/mocks.d.ts +0 -7
  7. package/dist/_mocks/mocks.js +0 -44
  8. package/dist/decorators/definition-component.d.ts +0 -18
  9. package/dist/decorators/definition-component.js +0 -52
  10. package/dist/decorators/definition-generator.d.ts +0 -11
  11. package/dist/decorators/definition-generator.js +0 -30
  12. package/dist/framework/context.d.ts +0 -24
  13. package/dist/framework/context.js +0 -64
  14. package/dist/framework/definition-component.d.ts +0 -20
  15. package/dist/framework/definition-component.js +0 -29
  16. package/dist/framework/definition-generator.d.ts +0 -11
  17. package/dist/framework/definition-generator.js +0 -22
  18. package/dist/framework/definition-store.d.ts +0 -25
  19. package/dist/framework/definition-store.js +0 -121
  20. package/dist/framework/file-content-generator/file-content-generator.d.ts +0 -19
  21. package/dist/framework/file-content-generator/file-content-generator.js +0 -117
  22. package/dist/framework/file-content-generator/file-content-generator.test.d.ts +0 -24
  23. package/dist/framework/file-content-generator/file-content-generator.test.js +0 -161
  24. package/dist/framework/file-generators/index-file-generator.d.ts +0 -13
  25. package/dist/framework/file-generators/index-file-generator.js +0 -139
  26. package/dist/framework/file-generators/types-file-generator.d.ts +0 -6
  27. package/dist/framework/file-generators/types-file-generator.js +0 -35
  28. package/dist/framework/framework.d.ts +0 -28
  29. package/dist/framework/framework.data.d.ts +0 -6
  30. package/dist/framework/framework.data.js +0 -17
  31. package/dist/framework/framework.js +0 -51
  32. package/dist/framework/framework.model.d.ts +0 -32
  33. package/dist/framework/framework.model.js +0 -3
  34. package/dist/framework/index-file-generator/index-file-generator.d.ts +0 -10
  35. package/dist/framework/index-file-generator/index-file-generator.js +0 -118
  36. package/dist/framework/interfaces.d.ts +0 -46
  37. package/dist/framework/interfaces.js +0 -3
  38. package/dist/framework/kernel.d.ts +0 -12
  39. package/dist/framework/kernel.js +0 -308
  40. package/dist/helpers/common-functions/common-functions.d.ts +0 -10
  41. package/dist/helpers/common-functions/common-functions.js +0 -29
  42. package/dist/helpers/common-functions/common-functions.spec.d.ts +0 -1
  43. package/dist/helpers/common-functions/common-functions.spec.js +0 -50
  44. package/dist/helpers/common-functions/common-functions.test.d.ts +0 -1
  45. package/dist/helpers/common-functions/common-functions.test.js +0 -51
  46. package/dist/helpers/duplicate-helper/duplicate-helper.d.ts +0 -11
  47. package/dist/helpers/duplicate-helper/duplicate-helper.js +0 -40
  48. package/dist/helpers/duplicate-helper/duplicate-helper.spec.d.ts +0 -1
  49. package/dist/helpers/duplicate-helper/duplicate-helper.spec.js +0 -54
  50. package/dist/helpers/duplicate-helper/duplicate-helper.test.d.ts +0 -1
  51. package/dist/helpers/duplicate-helper/duplicate-helper.test.js +0 -55
  52. package/dist/helpers/output-helper/output-helper.d.ts +0 -30
  53. package/dist/helpers/output-helper/output-helper.js +0 -143
  54. package/dist/helpers/output-helper/output-helper.spec.d.ts +0 -24
  55. package/dist/helpers/output-helper/output-helper.spec.js +0 -261
  56. package/dist/helpers/output-helper/output-helper.test.d.ts +0 -24
  57. package/dist/helpers/output-helper/output-helper.test.js +0 -262
  58. package/dist/helpers/raw-definition-helper/raw-definition.helper.d.ts +0 -7
  59. package/dist/helpers/raw-definition-helper/raw-definition.helper.js +0 -66
  60. package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.d.ts +0 -1
  61. package/dist/helpers/raw-definition-helper/raw-definition.helper.spec.js +0 -143
  62. package/dist/helpers/raw-definition-helper/raw-definition.helper.test.d.ts +0 -1
  63. package/dist/helpers/raw-definition-helper/raw-definition.helper.test.js +0 -136
  64. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.d.ts +0 -16
  65. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.js +0 -48
  66. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.d.ts +0 -1
  67. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.spec.js +0 -191
  68. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.test.d.ts +0 -1
  69. package/dist/helpers/validator/custom-validator-helper/custom-validator.helper.test.js +0 -213
  70. package/dist/helpers/validator/custom-validators/helpers/sprite-validation.helper.d.ts +0 -13
  71. package/dist/helpers/validator/custom-validators/helpers/sprite-validation.helper.js +0 -53
  72. package/dist/helpers/validator/custom-validators/helpers/sprite-validation.helper.test.d.ts +0 -1
  73. package/dist/helpers/validator/custom-validators/helpers/sprite-validation.helper.test.js +0 -96
  74. package/dist/helpers/validator/custom-validators/image.custom-validator.d.ts +0 -14
  75. package/dist/helpers/validator/custom-validators/image.custom-validator.js +0 -44
  76. package/dist/helpers/validator/custom-validators/path.custom-validator.d.ts +0 -9
  77. package/dist/helpers/validator/custom-validators/path.custom-validator.js +0 -30
  78. package/dist/helpers/validator/custom-validators/position-on-sprite.d.ts +0 -14
  79. package/dist/helpers/validator/custom-validators/position-on-sprite.js +0 -44
  80. package/dist/helpers/validator/custom-validators/reference.custom-validator.d.ts +0 -22
  81. package/dist/helpers/validator/custom-validators/reference.custom-validator.js +0 -123
  82. package/dist/helpers/validator/custom-validators/sprite.custom-validator.d.ts +0 -14
  83. package/dist/helpers/validator/custom-validators/sprite.custom-validator.js +0 -43
  84. package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.d.ts +0 -9
  85. package/dist/helpers/validator/custom-validators/unique-name-group.custom-validator.js +0 -33
  86. package/dist/helpers/validator/custom-validators/unique.custom-validator.d.ts +0 -8
  87. package/dist/helpers/validator/custom-validators/unique.custom-validator.js +0 -20
  88. package/dist/helpers/validator/joi-custom-validators.d.ts +0 -33
  89. package/dist/helpers/validator/joi-custom-validators.js +0 -54
  90. package/dist/helpers/validator/joi-custom-validators.spec.d.ts +0 -1
  91. package/dist/helpers/validator/joi-custom-validators.spec.js +0 -304
  92. package/dist/helpers/validator/validator.d.ts +0 -21
  93. package/dist/helpers/validator/validator.js +0 -74
  94. package/dist/helpers/validator/validator.spec.d.ts +0 -1
  95. package/dist/helpers/validator/validator.spec.js +0 -332
  96. package/dist/helpers/validator/validator.test.d.ts +0 -1
  97. package/dist/helpers/validator/validator.test.js +0 -329
  98. package/dist/pipeline/1-select-definitions-helper.d.ts +0 -20
  99. package/dist/pipeline/1-select-definitions-helper.js +0 -76
  100. package/dist/pipeline/1-select-definitions.helper.d.ts +0 -20
  101. package/dist/pipeline/1-select-definitions.helper.js +0 -80
  102. package/dist/pipeline/1-select-definitions.helper.test.d.ts +0 -1
  103. package/dist/pipeline/1-select-definitions.helper.test.js +0 -141
  104. package/dist/pipeline/1-select-definitions.spec.d.ts +0 -1
  105. package/dist/pipeline/1-select-definitions.spec.js +0 -140
  106. package/dist/pipeline/2-structure-parser.helper.d.ts +0 -11
  107. package/dist/pipeline/2-structure-parser.helper.js +0 -70
  108. package/dist/pipeline/2-structure-parser.helper.spec.d.ts +0 -1
  109. package/dist/pipeline/2-structure-parser.helper.spec.js +0 -280
  110. package/dist/pipeline/2-structure-parser.helper.test.d.ts +0 -1
  111. package/dist/pipeline/2-structure-parser.helper.test.js +0 -281
  112. package/dist/pipeline/3-config.d.ts +0 -9
  113. package/dist/pipeline/3-config.js +0 -36
  114. package/dist/pipeline/_mocks/index.d.ts +0 -13
  115. package/dist/pipeline/_mocks/index.js +0 -52
  116. package/dist/pipeline/parsers/array-parser.d.ts +0 -4
  117. package/dist/pipeline/parsers/array-parser.js +0 -69
  118. package/dist/pipeline/parsers/array-parser.spec.d.ts +0 -1
  119. package/dist/pipeline/parsers/array-parser.spec.js +0 -128
  120. package/dist/pipeline/parsers/array-parser.test.d.ts +0 -1
  121. package/dist/pipeline/parsers/array-parser.test.js +0 -126
  122. package/dist/pipeline/parsers/object-parser.d.ts +0 -4
  123. package/dist/pipeline/parsers/object-parser.js +0 -135
  124. package/dist/pipeline/parsers/object-parser.spec.d.ts +0 -1
  125. package/dist/pipeline/parsers/object-parser.spec.js +0 -179
  126. package/dist/pipeline/parsers/object-parser.test.d.ts +0 -1
  127. package/dist/pipeline/parsers/object-parser.test.js +0 -186
  128. package/dist/pipeline/parsers/primitive-parser.d.ts +0 -7
  129. package/dist/pipeline/parsers/primitive-parser.js +0 -111
  130. package/dist/pipeline/parsers/primitive-parser.spec.d.ts +0 -1
  131. package/dist/pipeline/parsers/primitive-parser.spec.js +0 -79
  132. package/dist/pipeline/parsers/primitive-parser.test.d.ts +0 -1
  133. package/dist/pipeline/parsers/primitive-parser.test.js +0 -85
  134. package/dist/pipeline/raw-data-parser.d.ts +0 -5
  135. package/dist/pipeline/raw-data-parser.js +0 -25
  136. package/dist/pre-made-components/_validators/shape-validators.d.ts +0 -7
  137. package/dist/pre-made-components/_validators/shape-validators.js +0 -37
  138. package/dist/pre-made-components/_validators/sprite-validators.d.ts +0 -7
  139. package/dist/pre-made-components/_validators/sprite-validators.js +0 -43
  140. package/dist/pre-made-components/assets/1-sprite.d.ts +0 -15
  141. package/dist/pre-made-components/assets/1-sprite.js +0 -74
  142. package/dist/pre-made-components/assets/2-sprite-group.d.ts +0 -11
  143. package/dist/pre-made-components/assets/2-sprite-group.js +0 -41
  144. package/dist/pre-made-components/assets/3-font.d.ts +0 -17
  145. package/dist/pre-made-components/assets/3-font.js +0 -71
  146. package/dist/pre-made-components/events/1-event.d.ts +0 -6
  147. package/dist/pre-made-components/events/1-event.js +0 -206
  148. package/dist/pre-made-components/events/1-script.d.ts +0 -8
  149. package/dist/pre-made-components/events/1-script.js +0 -102
  150. package/dist/pre-made-components/events/2-event-test.d.ts +0 -18
  151. package/dist/pre-made-components/events/2-event-test.js +0 -172
  152. package/dist/pre-made-components/events/2-script-test.d.ts +0 -7
  153. package/dist/pre-made-components/events/2-script-test.js +0 -102
  154. package/dist/pre-made-components/events/3-event.d.ts +0 -7
  155. package/dist/pre-made-components/events/3-event.js +0 -100
  156. package/dist/pre-made-components/events/4-event-test.d.ts +0 -7
  157. package/dist/pre-made-components/events/4-event-test.js +0 -89
  158. package/dist/pre-made-components/events/event-setup.d.ts +0 -13
  159. package/dist/pre-made-components/events/event-setup.js +0 -20
  160. package/dist/pre-made-components/events/helpers/quotes-to-tags.helper.d.ts +0 -3
  161. package/dist/pre-made-components/events/helpers/quotes-to-tags.helper.js +0 -24
  162. package/dist/pre-made-components/events/helpers/quotes-to-tags.helper.test.d.ts +0 -1
  163. package/dist/pre-made-components/events/helpers/quotes-to-tags.helper.test.js +0 -39
  164. package/dist/pre-made-components/events/helpers/script-testing.helper.d.ts +0 -33
  165. package/dist/pre-made-components/events/helpers/script-testing.helper.js +0 -79
  166. package/dist/pre-made-components/events/script-setup.d.ts +0 -8
  167. package/dist/pre-made-components/events/script-setup.js +0 -16
  168. package/dist/pre-made-components/events/scripting-setup.d.ts +0 -33
  169. package/dist/pre-made-components/events/scripting-setup.js +0 -97
  170. package/dist/pre-made-components/events/validators.d.ts +0 -6
  171. package/dist/pre-made-components/events/validators.js +0 -96
  172. package/dist/setup.d.ts +0 -1
  173. package/dist/setup.js +0 -10
@@ -1,21 +0,0 @@
1
- import Joi from 'joi';
2
- import { RawDefinition } from '../../framework/interfaces';
3
- export interface GroupDefinition {
4
- name: string;
5
- group: string[];
6
- }
7
- export interface ValidationContext {
8
- readonly rawDefinition: RawDefinition;
9
- failSilently?: boolean;
10
- }
11
- export interface ValidatedItem<T> {
12
- readonly definition: T;
13
- readonly rawDefinition: RawDefinition;
14
- }
15
- export declare class Validator {
16
- static definitionToRawDefintion: Map<any, RawDefinition>;
17
- static getRawDefinitions(componentName: string): RawDefinition[];
18
- static validateAndConvert<T>(componentName: string, schema: Joi.AnySchema): ValidatedItem<T>[];
19
- static validateAndConvertSingular<T>(componentName: string, schema: Joi.AnySchema): ValidatedItem<T> | undefined;
20
- private static validate;
21
- }
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Validator = void 0;
4
- const context_1 = require("../../framework/context");
5
- const raw_definition_helper_1 = require("../raw-definition-helper/raw-definition.helper");
6
- class Validator {
7
- static { this.definitionToRawDefintion = new Map(); }
8
- // Cache the definitions
9
- static getRawDefinitions(componentName) {
10
- return context_1.Context.rawDefinitions.filter(rawDefinition => rawDefinition.componentName === componentName);
11
- }
12
- static validateAndConvert(componentName, schema) {
13
- return this.getRawDefinitions(componentName)
14
- .map(rawDefinition => {
15
- let definition = this.validate(rawDefinition, schema);
16
- this.definitionToRawDefintion.set(definition, rawDefinition);
17
- if (definition) {
18
- return {
19
- definition,
20
- rawDefinition
21
- };
22
- }
23
- })
24
- .filter(validatedItem => validatedItem);
25
- }
26
- static validateAndConvertSingular(componentName, schema) {
27
- let validatedItems = this.validateAndConvert(componentName, schema);
28
- if (validatedItems.length === 0) {
29
- if (context_1.Context.successful) {
30
- let errorLog = {
31
- description: `Singleton definition has no declared entry "${componentName}"`,
32
- location: { line: 0, path: '*' }
33
- };
34
- context_1.Context.addErrorLog(errorLog, 'lowPriority');
35
- }
36
- }
37
- else if (validatedItems.length > 1) {
38
- context_1.Context.rawDefinitions
39
- .filter(rawDefinition => rawDefinition.componentName === componentName)
40
- .forEach(rawDefinition => {
41
- let errorLog = {
42
- description: `Only one definition can be defined for "${componentName}"`,
43
- location: rawDefinition.location
44
- };
45
- context_1.Context.addErrorLog(errorLog, 'lowPriority');
46
- });
47
- }
48
- else {
49
- return validatedItems[0];
50
- }
51
- }
52
- static validate(rawDefinition, schema) {
53
- let context = { rawDefinition, failSilently: false };
54
- let { value, error } = schema.validate(raw_definition_helper_1.RawDefinitionHelper.flatten(rawDefinition), {
55
- abortEarly: false,
56
- context
57
- });
58
- if (error?.details) {
59
- let errors = error.details.reverse().map(errorDetail => ({
60
- description: errorDetail.message,
61
- location: {
62
- line: raw_definition_helper_1.RawDefinitionHelper.findLine(rawDefinition, errorDetail.path),
63
- path: rawDefinition.location.path
64
- }
65
- }));
66
- context_1.Context.addErrorLog(errors.reverse());
67
- }
68
- else if (!context.failSilently) {
69
- return value;
70
- }
71
- }
72
- }
73
- exports.Validator = Validator;
74
- //# sourceMappingURL=validator.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,332 +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
- const joi_1 = __importDefault(require('joi'));
9
- const validator_1 = require('./validator');
10
- const joi_custom_validators_1 = require('./joi-custom-validators');
11
- const mocks_1 = require('../../_mocks/mocks');
12
- const custom_validator_helper_1 = require('./custom-validator-helper/custom-validator.helper');
13
- const context_1 = require('../../framework/context');
14
- const definition_store_1 = require('../../framework/definition-store');
15
- joi_custom_validators_1.JoiCustomValidators.decorate(joi_1.default, { existsSync: path => path !== 'D:/test/false/path.png' });
16
- const ComponentType = 'ASSET';
17
- class Asset {
18
- static {
19
- this.$meta = {
20
- componentName: ComponentType
21
- };
22
- }
23
- async process() {}
24
- }
25
- const TestSchema = joi_1.default.object().keys({
26
- str1: joi_1.default.string().required(),
27
- str2: joi_1.default.string().path().optional()
28
- });
29
- function getSampleRawDefinition(str, pathString) {
30
- let rawDefinition = {
31
- componentName: ComponentType,
32
- location: mocks_1.SampleLocation1,
33
- parsedStructure: {
34
- line: mocks_1.SampleLocation1.line + 1,
35
- rawData: {
36
- str1: {
37
- rawData: str,
38
- line: mocks_1.SampleLocation1.line + 1
39
- },
40
- str2: {
41
- rawData: pathString,
42
- line: mocks_1.SampleLocation1.line + 2
43
- }
44
- }
45
- }
46
- };
47
- return rawDefinition;
48
- }
49
- const SampleNestedRawDefinition = {
50
- componentName: ComponentType,
51
- location: mocks_1.SampleLocation1,
52
- parsedStructure: {
53
- line: mocks_1.SampleLocation1.line + 1,
54
- rawData: {
55
- obj1: {
56
- line: mocks_1.SampleLocation1.line + 1,
57
- rawData: [
58
- {
59
- line: mocks_1.SampleLocation1.line + 2,
60
- rawData: {
61
- obj2: {
62
- line: mocks_1.SampleLocation1.line + 2,
63
- rawData: 'test data'
64
- }
65
- }
66
- }
67
- ]
68
- }
69
- }
70
- }
71
- };
72
- describe('VALIDATOR', () => {
73
- beforeEach(() => {
74
- (0, mocks_1.resetContext)();
75
- custom_validator_helper_1.CustomValidatorHelper['duplicateHelpers'] = new Map();
76
- });
77
- describe('Convert', () => {
78
- test('valid definition', () => {
79
- context_1.Context.rawDefinitions.push(getSampleRawDefinition('str1', 'images/test.png'));
80
- let definitions = validator_1.Validator.validateAndConvert(ComponentType, TestSchema);
81
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
82
- expect(context_1.Context.errorLogs).toStrictEqual([]);
83
- expect(definitions).toStrictEqual([{ str1: 'str1', str2: '.test/images/test.png' }]);
84
- });
85
- test('singular definition', () => {
86
- context_1.Context.rawDefinitions.push(getSampleRawDefinition('str1', 'images/test.png'));
87
- let definitions = validator_1.Validator.validateAndConvert(ComponentType, TestSchema);
88
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
89
- expect(context_1.Context.errorLogs).toStrictEqual([]);
90
- expect(definitions).toStrictEqual([{ str1: 'str1', str2: '.test/images/test.png' }]);
91
- });
92
- test('should allow references in the same namespace', () => {
93
- let rawDefinition1 = {
94
- componentName: ComponentType,
95
- location: mocks_1.SampleLocation1,
96
- parsedStructure: {
97
- line: mocks_1.SampleLocation1.line + 1,
98
- rawData: {
99
- name: {
100
- rawData: 'asset2',
101
- line: mocks_1.SampleLocation1.line + 1
102
- },
103
- ref: {
104
- rawData: 'asset1',
105
- line: mocks_1.SampleLocation1.line + 2
106
- }
107
- }
108
- }
109
- };
110
- let rawDefinition2 = {
111
- componentName: ComponentType,
112
- location: mocks_1.SampleLocation1,
113
- parsedStructure: {
114
- line: mocks_1.SampleLocation1.line + 1,
115
- rawData: {
116
- name: {
117
- rawData: 'asset1',
118
- line: mocks_1.SampleLocation1.line + 1
119
- }
120
- }
121
- }
122
- };
123
- context_1.Context.rawDefinitions.push(rawDefinition1);
124
- context_1.Context.rawDefinitions.push(rawDefinition2);
125
- let schema = joi_1.default.object().keys({
126
- name: joi_1.default.string().required(),
127
- ref: joi_1.default.string().reference(Asset).optional()
128
- });
129
- definition_store_1.DefinitionStore['setRawDefinition'](Asset, 'asset1', rawDefinition2);
130
- let definitions = validator_1.Validator.validateAndConvert(ComponentType, schema);
131
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
132
- expect(context_1.Context.errorLogs).toStrictEqual([]);
133
- expect(definitions).toStrictEqual([
134
- {
135
- name: 'asset2',
136
- ref: 'asset1'
137
- },
138
- {
139
- name: 'asset1'
140
- }
141
- ]);
142
- });
143
- });
144
- describe('Convert Singular', () => {
145
- test('valid definition', () => {
146
- context_1.Context.rawDefinitions.push(getSampleRawDefinition('str1', 'images/test.png'));
147
- let definition = validator_1.Validator.validateAndConvertSingular(ComponentType, TestSchema);
148
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
149
- expect(context_1.Context.errorLogs).toStrictEqual([]);
150
- expect(definition).toStrictEqual({ str1: 'str1', str2: '.test/images/test.png' });
151
- });
152
- test('should log error for no definition', () => {
153
- let definition = validator_1.Validator.validateAndConvertSingular(ComponentType, TestSchema);
154
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
155
- expect(definition).toStrictEqual(undefined);
156
- expect(context_1.Context.errorLogs).toStrictEqual([
157
- {
158
- description: 'Singleton definition has no declared entry "ASSET"',
159
- location: {
160
- line: 0,
161
- path: '*'
162
- }
163
- }
164
- ]);
165
- });
166
- test('should log error for multiple definitions', () => {
167
- context_1.Context.rawDefinitions.push(getSampleRawDefinition('str1', 'images/test.png'));
168
- context_1.Context.rawDefinitions.push(getSampleRawDefinition('str2', 'images/test.png'));
169
- let definition = validator_1.Validator.validateAndConvertSingular(ComponentType, TestSchema);
170
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
171
- expect(definition).toStrictEqual(undefined);
172
- expect(context_1.Context.errorLogs).toStrictEqual([
173
- {
174
- description: 'Only one definition can be defined for "ASSET"',
175
- location: {
176
- line: 2,
177
- path: 'D:/test/file-1.md'
178
- }
179
- },
180
- {
181
- description: 'Only one definition can be defined for "ASSET"',
182
- location: {
183
- line: 2,
184
- path: 'D:/test/file-1.md'
185
- }
186
- }
187
- ]);
188
- });
189
- });
190
- describe('Validate', () => {
191
- test('should handle valid raw definition', () => {
192
- let rawDefinition = getSampleRawDefinition('a', 'images/test.png');
193
- let value = validator_1.Validator['validate'](rawDefinition, TestSchema);
194
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
195
- expect(value).toStrictEqual({ str1: 'a', str2: '.test/images/test.png' });
196
- expect(context_1.Context.errorLogs).toStrictEqual([]);
197
- });
198
- test('should log error for required fields', () => {
199
- let rawDefinition = getSampleRawDefinition(undefined, 'images/test.png');
200
- let value = validator_1.Validator['validate'](rawDefinition, TestSchema);
201
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
202
- expect(value).toStrictEqual(undefined);
203
- expect(context_1.Context.errorLogs).toStrictEqual([
204
- {
205
- description: '"str1" is required',
206
- location: {
207
- line: mocks_1.SampleLocation1.line + 1,
208
- path: mocks_1.SampleLocation1.path
209
- }
210
- }
211
- ]);
212
- });
213
- test('should log error for invalid flag attribute value', () => {
214
- let rawDefinition = getSampleRawDefinition('a', 'wrong text');
215
- let value = validator_1.Validator['validate'](rawDefinition, TestSchema);
216
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
217
- expect(value).toStrictEqual(undefined);
218
- expect(context_1.Context.errorLogs).toStrictEqual([
219
- {
220
- description: `"str2" with value "wrong text" fails to match the required pattern: /^[\\S]+$/`,
221
- location: {
222
- line: mocks_1.SampleLocation1.line + 2,
223
- path: mocks_1.SampleLocation1.path
224
- }
225
- }
226
- ]);
227
- });
228
- test('should log error for non matching pattern', () => {
229
- let schema = joi_1.default.object().keys({
230
- str1: joi_1.default
231
- .string()
232
- .regex(/^[a-z]+([a-zA-Z0-9]+)*$/)
233
- .required(),
234
- str2: joi_1.default
235
- .string()
236
- .regex(/^[a-z]+([a-zA-Z0-9]+)*$/)
237
- .required()
238
- });
239
- let rawDefinition = getSampleRawDefinition('1a', 'wrong string');
240
- let value = validator_1.Validator['validate'](rawDefinition, schema);
241
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
242
- expect(value).toStrictEqual(undefined);
243
- expect(context_1.Context.errorLogs).toStrictEqual([
244
- {
245
- description: `"str1" with value "1a" fails to match the required pattern: /^[a-z]+([a-zA-Z0-9]+)*$/`,
246
- location: {
247
- line: mocks_1.SampleLocation1.line + 1,
248
- path: mocks_1.SampleLocation1.path
249
- }
250
- },
251
- {
252
- description: `"str2" with value "wrong string" fails to match the required pattern: /^[a-z]+([a-zA-Z0-9]+)*$/`,
253
- location: {
254
- line: mocks_1.SampleLocation1.line + 2,
255
- path: mocks_1.SampleLocation1.path
256
- }
257
- }
258
- ]);
259
- });
260
- test('should validate primitive definition', () => {
261
- let rawDefinition = {
262
- componentName: ComponentType,
263
- location: mocks_1.SampleLocation1,
264
- parsedStructure: {
265
- line: mocks_1.SampleLocation1.line + 1,
266
- rawData: 'test'
267
- }
268
- };
269
- let value = validator_1.Validator['validate'](rawDefinition, joi_1.default.string());
270
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
271
- expect(value).toStrictEqual('test');
272
- expect(context_1.Context.errorLogs).toStrictEqual([]);
273
- });
274
- test('should log error for primitive definition', () => {
275
- let rawDefinition = {
276
- componentName: ComponentType,
277
- location: mocks_1.SampleLocation1,
278
- parsedStructure: {
279
- line: mocks_1.SampleLocation1.line + 1,
280
- rawData: 'test'
281
- }
282
- };
283
- let value = validator_1.Validator['validate'](rawDefinition, joi_1.default.string().valid('only'));
284
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
285
- expect(value).toStrictEqual(undefined);
286
- expect(context_1.Context.errorLogs).toStrictEqual([
287
- {
288
- description: '"value" must be [only]',
289
- location: {
290
- line: mocks_1.SampleLocation1.line + 1,
291
- path: mocks_1.SampleLocation1.path
292
- }
293
- }
294
- ]);
295
- });
296
- test('should validate nested object', () => {
297
- let schema = joi_1.default.object().keys({
298
- obj1: joi_1.default.array().items(
299
- joi_1.default.object().keys({
300
- obj2: joi_1.default.string()
301
- })
302
- )
303
- });
304
- let value = validator_1.Validator['validate'](SampleNestedRawDefinition, schema);
305
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
306
- expect(value).toStrictEqual({ obj1: [{ obj2: 'test data' }] });
307
- expect(context_1.Context.errorLogs).toStrictEqual([]);
308
- });
309
- test('should log error for nested object', () => {
310
- let schema = joi_1.default.object().keys({
311
- obj1: joi_1.default.array().items(
312
- joi_1.default.object().keys({
313
- obj2: joi_1.default.string().valid('only')
314
- })
315
- )
316
- });
317
- let value = validator_1.Validator['validate'](SampleNestedRawDefinition, schema);
318
- custom_validator_helper_1.CustomValidatorHelper.logDuplicates();
319
- expect(value).toStrictEqual(undefined);
320
- expect(context_1.Context.errorLogs).toStrictEqual([
321
- {
322
- description: '"obj1[0].obj2" must be [only]',
323
- location: {
324
- line: mocks_1.SampleLocation1.line + 2,
325
- path: 'D:/test/file-1.md'
326
- }
327
- }
328
- ]);
329
- });
330
- });
331
- });
332
- //# sourceMappingURL=validator.spec.js.map
@@ -1 +0,0 @@
1
- export {};