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,206 +0,0 @@
1
- 'use strict';
2
- var __decorate =
3
- (this && this.__decorate) ||
4
- function (decorators, target, key, desc) {
5
- var c = arguments.length,
6
- r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc,
7
- d;
8
- if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function')
9
- r = Reflect.decorate(decorators, target, key, desc);
10
- else
11
- for (var i = decorators.length - 1; i >= 0; i--)
12
- if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
13
- return c > 3 && r && Object.defineProperty(target, key, r), r;
14
- };
15
- var __importDefault =
16
- (this && this.__importDefault) ||
17
- function (mod) {
18
- return mod && mod.__esModule ? mod : { default: mod };
19
- };
20
- Object.defineProperty(exports, '__esModule', { value: true });
21
- exports.EventComponent = void 0;
22
- const helpers_lib_1 = require('helpers-lib');
23
- const joi_1 = __importDefault(require('joi'));
24
- const definition_component_1 = require('../../decorators/definition-component');
25
- const quotes_to_tags_helper_1 = require('./helpers/quotes-to-tags.helper');
26
- // ---- Conditions ----
27
- const ActionCommandSchema = () =>
28
- joi_1.default.string().custom(value => ({
29
- type: 'command',
30
- value: value
31
- }));
32
- // ---- Branches ----
33
- const JumpToSchema = joi_1.default
34
- .object()
35
- .keys({
36
- jumpTo: joi_1.default.string().lazyReference('EVENT').required()
37
- })
38
- .custom(value => ({
39
- type: 'jumpTo',
40
- value: value.jumpTo
41
- }));
42
- const BranchByConditionSchema = joi_1.default
43
- .object()
44
- .keys({
45
- branchByCondition: joi_1.default
46
- .array()
47
- .items(
48
- joi_1.default.object().keys({
49
- condition: joi_1.default.string().optional(),
50
- actions: joi_1.default.link('#EventActionsSchema').default([]).optional()
51
- })
52
- )
53
- .custom((array, helpers) => {
54
- let length = array.length;
55
- if (length > 1) {
56
- for (let i = 0; i < length - 1; i++) {
57
- if (array[i].condition === undefined) {
58
- throw new Error(`Element at index ${i} must have "condition"`);
59
- }
60
- }
61
- } else if (length === 1) {
62
- if (array[0].condition === undefined) {
63
- throw new Error('Single element must have "condition"');
64
- }
65
- }
66
- return array;
67
- })
68
- })
69
- .custom(value => ({
70
- type: 'branchByCondition',
71
- value: value.branchByCondition
72
- }));
73
- const BranchByPlayerChoiceSchema = joi_1.default
74
- .object()
75
- .keys({
76
- branchByPlayerChoice: joi_1.default.array().items(
77
- joi_1.default.object().keys({
78
- text: joi_1.default.string().min(2).required(),
79
- condition: joi_1.default.string().optional(),
80
- actions: joi_1.default.link('#EventActionsSchema').default([]).optional()
81
- })
82
- )
83
- })
84
- .custom(value => ({
85
- type: 'branchByPlayerChoice',
86
- value: value.branchByPlayerChoice
87
- }));
88
- const BranchByChanceSchema = joi_1.default
89
- .object()
90
- .keys({
91
- branchByChance: joi_1.default.array().items(
92
- joi_1.default.object().keys({
93
- label: joi_1.default.string().required(),
94
- weight: joi_1.default.number().integer().min(1).max(100).required(),
95
- condition: joi_1.default.string().optional(),
96
- actions: joi_1.default.link('#EventActionsSchema').default([]).optional()
97
- })
98
- )
99
- })
100
- .custom(value => ({
101
- type: 'branchByChance',
102
- value: value.branchByChance
103
- }));
104
- // ---- Dialog ----
105
- const DialogSchema = joi_1.default
106
- .object()
107
- .min(1)
108
- .max(1)
109
- .custom(value => {
110
- let keys = Object.keys(value);
111
- if (keys.length !== 1) {
112
- throw new Error('object must have exactly one key/value pair');
113
- }
114
- let key = keys[0];
115
- let text = value[key];
116
- if (typeof text !== 'string') {
117
- throw new Error('value must be a string');
118
- }
119
- text = quotes_to_tags_helper_1.QuotesToTagsHelper.convert(text);
120
- return { type: 'dialog', value: { text, speaker: key } };
121
- });
122
- // ---- Main Schema ----
123
- const ActionsSchema = () =>
124
- joi_1.default
125
- .array()
126
- .items(
127
- joi_1.default
128
- .alternatives()
129
- .conditional(joi_1.default.string(), {
130
- then: ActionCommandSchema()
131
- })
132
- .conditional(joi_1.default.object({ jumpTo: joi_1.default.exist() }).unknown(), {
133
- then: JumpToSchema
134
- })
135
- .conditional(joi_1.default.object({ branchByChance: joi_1.default.exist() }).unknown(), {
136
- then: BranchByChanceSchema
137
- })
138
- .conditional(joi_1.default.object({ branchByCondition: joi_1.default.exist() }).unknown(), {
139
- then: BranchByConditionSchema
140
- })
141
- .conditional(joi_1.default.object({ branchByPlayerChoice: joi_1.default.exist() }).unknown(), {
142
- then: BranchByPlayerChoiceSchema
143
- })
144
- .conditional(joi_1.default.object().min(1).max(1).unknown(), {
145
- then: DialogSchema
146
- })
147
- .error(errors =>
148
- errors.map(error => {
149
- if (error.code === 'alternatives.any') {
150
- let allowedTypes = 'command, jumpTo, branchByCondition, branchByPlayerChoice, branchByChance';
151
- error.message = `${error.local.label} does not match any of the allowed types: ${allowedTypes}`;
152
- }
153
- return error;
154
- })
155
- )
156
- )
157
- .custom(array => {
158
- let commandFoundAfterBranching = false;
159
- let emptyStackRequiresBranchingFound = false;
160
- array.forEach(action => {
161
- if (emptyStackRequiresBranchingFound) {
162
- commandFoundAfterBranching = true;
163
- } else if (
164
- action.type === 'branchByCondition' ||
165
- action.type === 'branchByPlayerChoice' ||
166
- action.type === 'branchByChance'
167
- ) {
168
- emptyStackRequiresBranchingFound = true;
169
- }
170
- });
171
- if (commandFoundAfterBranching) {
172
- throw new Error('There should not be any command after branching.');
173
- } else {
174
- return array;
175
- }
176
- })
177
- .id('EventActionsSchema');
178
- let EventComponent = class EventComponent extends definition_component_1.DefinitionComponent {
179
- async process(definitions, output) {
180
- await output.addFile({
181
- path: '/_premade/events/events.ts',
182
- preText: `import { ScriptDefinition } from "script-engine-lib";`,
183
- variableName: 'EventDefinitions',
184
- variableType: 'Readonly<Record<string, ScriptDefinition>>',
185
- variable: helpers_lib_1.JsonHelper.arrayToObject(definitions, 'id')
186
- });
187
- }
188
- };
189
- exports.EventComponent = EventComponent;
190
- exports.EventComponent = EventComponent = __decorate(
191
- [
192
- (0, definition_component_1.DefinitionComponentDecorator)({
193
- componentName: 'EVENT',
194
- keyName: 'id',
195
- validationSchema: joi_1.default
196
- .object()
197
- .keys({
198
- id: joi_1.default.string().required(),
199
- actions: ActionsSchema().min(1).required()
200
- })
201
- .required()
202
- })
203
- ],
204
- EventComponent
205
- );
206
- //# sourceMappingURL=1-event.js.map
@@ -1,8 +0,0 @@
1
- import { ScriptDefinition } from 'script-engine-lib';
2
- import { DefinitionComponent } from '../../decorators/definition-component';
3
- import { Output } from '../../framework/interfaces';
4
- export type ScriptID = string;
5
- export declare const ScriptNames: Set<string>;
6
- export declare class ScriptComponent extends DefinitionComponent<ScriptDefinition> {
7
- process(definitions: ScriptDefinition[], output: Output): Promise<void>;
8
- }
@@ -1,102 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ScriptComponent = exports.ScriptNames = void 0;
13
- const helpers_lib_1 = require("helpers-lib");
14
- const joi_1 = __importDefault(require("joi"));
15
- const definition_component_1 = require("../../decorators/definition-component");
16
- const validators_1 = require("./validators");
17
- exports.ScriptNames = new Set();
18
- const JumpToScriptSchema = joi_1.default.object()
19
- .keys({
20
- jumpTo: joi_1.default.string().lazyReference('SCRIPT').required()
21
- })
22
- .custom(value => ({
23
- type: 'jumpTo',
24
- value: value.jumpTo
25
- }));
26
- // ---- Main Schema ----
27
- const ScriptActionId = 'ScriptActionsSchema';
28
- const ActionsSchema = () => joi_1.default.array()
29
- .items(joi_1.default.alternatives()
30
- .conditional(joi_1.default.string(), {
31
- then: (0, validators_1.ActionCommandSchema)()
32
- })
33
- .conditional(joi_1.default.object({ jumpTo: joi_1.default.exist() }).unknown(), {
34
- then: JumpToScriptSchema
35
- })
36
- .conditional(joi_1.default.object({ branchByChance: joi_1.default.exist() }).unknown(), {
37
- then: (0, validators_1.BranchByChanceSchema)(ScriptActionId)
38
- })
39
- .conditional(joi_1.default.object({ branchByCondition: joi_1.default.exist() }).unknown(), {
40
- then: (0, validators_1.BranchByConditionSchema)(ScriptActionId)
41
- })
42
- .conditional(joi_1.default.object({ branchByPlayerChoice: joi_1.default.exist() }).unknown(), {
43
- then: joi_1.default.forbidden().messages({
44
- 'any.unknown': 'branchByPlayerChoice is not allowed in scripts'
45
- })
46
- })
47
- .conditional(joi_1.default.object().min(1).max(1).unknown(), {
48
- then: joi_1.default.forbidden().messages({
49
- 'any.unknown': 'dialogs are not allowed in scripts'
50
- })
51
- })
52
- .error(errors => errors.map(error => {
53
- if (error.code === 'alternatives.any') {
54
- let allowedTypes = 'command, jumpToScript, branchByCondition, branchByChance';
55
- error.message = `${error.local.label} does not match any of the allowed types: ${allowedTypes}`;
56
- }
57
- return error;
58
- })))
59
- .custom((array) => {
60
- let commandFoundAfterBranching = false;
61
- let emptyStackRequiresBranchingFound = false;
62
- array.forEach(action => {
63
- if (emptyStackRequiresBranchingFound) {
64
- commandFoundAfterBranching = true;
65
- }
66
- else if (action.type === 'branchByCondition' || action.type === 'branchByChance') {
67
- emptyStackRequiresBranchingFound = true;
68
- }
69
- });
70
- if (commandFoundAfterBranching) {
71
- throw new Error('There should not be any command after branching.');
72
- }
73
- else {
74
- return array;
75
- }
76
- })
77
- .id(ScriptActionId);
78
- let ScriptComponent = class ScriptComponent extends definition_component_1.DefinitionComponent {
79
- async process(definitions, output) {
80
- await output.addFile({
81
- path: '/_premade/script-engine-definitions/scripts.ts',
82
- preText: `import { ScriptDefinition } from "script-engine-lib";`,
83
- variableName: 'ScriptDefinitions',
84
- variableType: 'Readonly<Record<string, ScriptDefinition>>',
85
- variable: helpers_lib_1.JsonHelper.arrayToObject(definitions, 'id')
86
- });
87
- }
88
- };
89
- exports.ScriptComponent = ScriptComponent;
90
- exports.ScriptComponent = ScriptComponent = __decorate([
91
- (0, definition_component_1.DefinitionComponentDecorator)({
92
- componentName: 'SCRIPT',
93
- keyName: 'id',
94
- validationSchema: joi_1.default.object()
95
- .keys({
96
- id: joi_1.default.string().unique(exports.ScriptNames).required(),
97
- actions: ActionsSchema().min(1).required()
98
- })
99
- .required()
100
- })
101
- ], ScriptComponent);
102
- //# sourceMappingURL=1-script.js.map
@@ -1,18 +0,0 @@
1
- import { ScriptTestActionDefinition } from 'script-engine-lib';
2
- import { DefinitionComponent } from '../../decorators/definition-component';
3
- import { Output } from '../../framework/interfaces';
4
- interface EventTestCasesDefinition {
5
- readonly actionsBeforeTesting: readonly ScriptTestActionDefinition[];
6
- }
7
- interface EventTestDefinition {
8
- readonly event: string;
9
- readonly cases: readonly EventTestCasesDefinition[];
10
- }
11
- export declare class EventTestComponent extends DefinitionComponent<EventTestDefinition> {
12
- process(definitions: EventTestDefinition[], output: Output): Promise<void>;
13
- private createEventTestSimulator;
14
- private runTests;
15
- private prepareErrorLog;
16
- private printErrors;
17
- }
18
- export {};
@@ -1,172 +0,0 @@
1
- 'use strict';
2
- var __decorate =
3
- (this && this.__decorate) ||
4
- function (decorators, target, key, desc) {
5
- var c = arguments.length,
6
- r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc,
7
- d;
8
- if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function')
9
- r = Reflect.decorate(decorators, target, key, desc);
10
- else
11
- for (var i = decorators.length - 1; i >= 0; i--)
12
- if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
13
- return c > 3 && r && Object.defineProperty(target, key, r), r;
14
- };
15
- var __importDefault =
16
- (this && this.__importDefault) ||
17
- function (mod) {
18
- return mod && mod.__esModule ? mod : { default: mod };
19
- };
20
- var EventTestComponent_1;
21
- Object.defineProperty(exports, '__esModule', { value: true });
22
- exports.EventTestComponent = void 0;
23
- const helpers_lib_1 = require('helpers-lib');
24
- const joi_1 = __importDefault(require('joi'));
25
- const script_engine_lib_1 = require('script-engine-lib');
26
- const definition_component_1 = require('../../decorators/definition-component');
27
- const definition_store_1 = require('../../framework/definition-store');
28
- const _1_event_1 = require('./1-event');
29
- const event_setup_1 = require('./event-setup');
30
- const CommandEventSchema = joi_1.default.string().custom(value => ({
31
- type: 'command',
32
- value: value
33
- }));
34
- const RunEventSchema = joi_1.default
35
- .object()
36
- .keys({
37
- runEvent: joi_1.default.string().reference(_1_event_1.EventComponent).required()
38
- })
39
- .custom(value => ({
40
- type: 'runEvent',
41
- value: value.runEvent
42
- }));
43
- const EventTestActionSchema = () =>
44
- joi_1.default
45
- .array()
46
- .items(
47
- joi_1.default
48
- .alternatives()
49
- .conditional(joi_1.default.string(), {
50
- then: CommandEventSchema
51
- })
52
- .conditional(joi_1.default.object({ runEvent: joi_1.default.exist() }).unknown(), {
53
- then: RunEventSchema
54
- })
55
- )
56
- .min(1);
57
- let EventTestComponent = (EventTestComponent_1 = class EventTestComponent extends definition_component_1.DefinitionComponent {
58
- async process(definitions, output) {
59
- let eventTestSimulator = this.createEventTestSimulator();
60
- let runtimeErrors = this.runTests(definitions, eventTestSimulator, output);
61
- this.printErrors(runtimeErrors, eventTestSimulator, output);
62
- }
63
- createEventTestSimulator() {
64
- let allScripts = definition_store_1.DefinitionStore.getDefinitions(_1_event_1.EventComponent);
65
- return new script_engine_lib_1.ScriptTestSimulator(allScripts);
66
- }
67
- runTests(testDefinitions, eventTestSimulator, output) {
68
- let errorLogs = [];
69
- testDefinitions.forEach(testDefinition => {
70
- let event = definition_store_1.DefinitionStore.getDefinitionOrFail(_1_event_1.EventComponent, testDefinition.event);
71
- let errorEncountered = false;
72
- testDefinition.cases.forEach((testCase, testCaseIndex) => {
73
- if (!errorEncountered) {
74
- let jsEngine = new helpers_lib_1.JSEngine(new event_setup_1.EventSetup.EventSimulatorFunctionsConstructor(), {});
75
- try {
76
- eventTestSimulator.simulateScript(event, jsEngine, testCase.actionsBeforeTesting);
77
- } catch (e) {
78
- let errorLog = this.prepareErrorLog(e, testDefinition, testCaseIndex, output);
79
- errorLogs.push(errorLog);
80
- errorEncountered = true;
81
- }
82
- }
83
- });
84
- });
85
- return errorLogs;
86
- }
87
- prepareErrorLog(e, testDefinition, testCaseIndex, output) {
88
- if (e instanceof script_engine_lib_1.SimulationError) {
89
- return {
90
- description: e.message,
91
- location: definition_store_1.DefinitionStore.getLocationInFileById(
92
- _1_event_1.EventComponent,
93
- e.location.scriptId,
94
- e.location.path
95
- )
96
- };
97
- } else if (e instanceof script_engine_lib_1.ActionsBeforeTestingError) {
98
- let executedActionLocation = definition_store_1.DefinitionStore.getLocationInFile(EventTestComponent_1, testDefinition, [
99
- 'cases',
100
- `${testCaseIndex}`,
101
- 'actionsBeforeTesting',
102
- `${e.actionIndex}`
103
- ]);
104
- return {
105
- description: e.message,
106
- location: executedActionLocation
107
- };
108
- } else if (e instanceof script_engine_lib_1.BranchingBeforeTestingError) {
109
- let testLocation = definition_store_1.DefinitionStore.getLocationInFile(EventTestComponent_1, testDefinition, []);
110
- let executionHistoryAddition = `Running the test: ${output.convertLocationInFileToLink(testLocation)}\n\n`;
111
- let executionHistoryStart = e.message.indexOf('\n', e.message.indexOf('Execution history')) + 1;
112
- let fullMessage =
113
- e.message.slice(0, executionHistoryStart) + executionHistoryAddition + e.message.slice(executionHistoryStart);
114
- return {
115
- description: fullMessage,
116
- location: definition_store_1.DefinitionStore.getLocationInFileById(
117
- _1_event_1.EventComponent,
118
- e.location.scriptId,
119
- e.location.path
120
- )
121
- };
122
- } else {
123
- throw e;
124
- }
125
- }
126
- printErrors(runtimeErrors, scriptTestSimulator, output) {
127
- if (runtimeErrors.length === 0) {
128
- scriptTestSimulator.getUnvisitedBranchLocations().forEach(location =>
129
- output.addError({
130
- description: `Event branch is not reaced by any of the combinations during the tests.`,
131
- location: definition_store_1.DefinitionStore.getLocationInFileById(
132
- _1_event_1.EventComponent,
133
- location.scriptId,
134
- location.path
135
- )
136
- })
137
- );
138
- }
139
- runtimeErrors.forEach(error => output.addError(error));
140
- }
141
- });
142
- exports.EventTestComponent = EventTestComponent;
143
- exports.EventTestComponent =
144
- EventTestComponent =
145
- EventTestComponent_1 =
146
- __decorate(
147
- [
148
- (0, definition_component_1.DefinitionComponentDecorator)({
149
- componentName: 'EVENT-TEST',
150
- keyName: 'id',
151
- validationSchema: joi_1.default
152
- .object()
153
- .keys({
154
- event: joi_1.default.string().reference(_1_event_1.EventComponent).required(),
155
- cases: joi_1.default
156
- .array()
157
- .items(
158
- joi_1.default
159
- .object()
160
- .keys({
161
- actionsBeforeTesting: EventTestActionSchema().default([]).optional()
162
- })
163
- .required()
164
- )
165
- .required()
166
- })
167
- .required()
168
- })
169
- ],
170
- EventTestComponent
171
- );
172
- //# sourceMappingURL=2-event-test.js.map
@@ -1,7 +0,0 @@
1
- import { DefinitionComponent } from '../../decorators/definition-component';
2
- import { Output } from '../../framework/interfaces';
3
- import { ScriptTestDefinition } from './helpers/script-testing.helper';
4
- export declare class ScriptTestComponent extends DefinitionComponent<ScriptTestDefinition> {
5
- process(definitions: ScriptTestDefinition[], output: Output): Promise<void>;
6
- private getLocationFinder;
7
- }
@@ -1,102 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
- var ScriptTestComponent_1;
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.ScriptTestComponent = void 0;
14
- const joi_1 = __importDefault(require("joi"));
15
- const definition_component_1 = require("../../decorators/definition-component");
16
- const definition_store_1 = require("../../framework/definition-store");
17
- const _1_script_1 = require("./1-script");
18
- const script_testing_helper_1 = require("./helpers/script-testing.helper");
19
- const scripting_setup_1 = require("./scripting-setup");
20
- const CommandEventSchema = joi_1.default.string().custom(value => ({
21
- type: 'command',
22
- value: value
23
- }));
24
- const RunScriptSchema = joi_1.default.object()
25
- .keys({
26
- runScript: joi_1.default.string().reference(_1_script_1.ScriptComponent).required()
27
- })
28
- .custom(value => ({
29
- type: 'runScript',
30
- value: value.runScript
31
- }));
32
- const EventTestActionSchema = () => joi_1.default.array()
33
- .items(joi_1.default.alternatives()
34
- .conditional(joi_1.default.string(), {
35
- then: CommandEventSchema
36
- })
37
- .conditional(joi_1.default.object({ runScript: joi_1.default.exist() }).unknown(), {
38
- then: RunScriptSchema
39
- })
40
- .error(errors => errors.map(error => {
41
- if (error.code === 'alternatives.any') {
42
- let allowedTypes = 'command, runScript';
43
- error.message = `${error.local.label} does not match any of the allowed types: ${allowedTypes}`;
44
- }
45
- return error;
46
- })))
47
- .min(1);
48
- let ScriptTestComponent = ScriptTestComponent_1 = class ScriptTestComponent extends definition_component_1.DefinitionComponent {
49
- async process(definitions, output) {
50
- let allScripts = definition_store_1.DefinitionStore.getDefinitions(_1_script_1.ScriptComponent);
51
- let scriptTestingHelper = new script_testing_helper_1.ScriptTestingHelper(allScripts, scripting_setup_1.ScriptTestingInternal.scriptSimulatorFunctionsConstructor, this.getLocationFinder());
52
- let testCasesFullDefinitions = definitions.map(definition => ({
53
- cases: definition.cases,
54
- script: definition_store_1.DefinitionStore.getDefinitionOrFail(_1_script_1.ScriptComponent, definition.script),
55
- scriptInput: scripting_setup_1.ScriptTestingInternal.getScriptInput(definition.script),
56
- testDefinitionRef: definition
57
- }));
58
- let customTestCasesFullDefinitions = scripting_setup_1.ScriptTestingInternal.getCustomScriptTestCases().map(definition => ({
59
- cases: definition.testDefinition.cases,
60
- script: definition_store_1.DefinitionStore.getDefinitionOrFail(_1_script_1.ScriptComponent, definition.testDefinition.script),
61
- scriptInput: scripting_setup_1.ScriptTestingInternal.getScriptInput(definition.testDefinition.script),
62
- testDefinitionRef: definition.testDefinition,
63
- customMessage: definition.customMessage
64
- }));
65
- let allTestDefinitions = testCasesFullDefinitions.concat(customTestCasesFullDefinitions);
66
- let runtimeErrors = scriptTestingHelper.runTests(allTestDefinitions, output);
67
- scriptTestingHelper.printErrors(runtimeErrors, output);
68
- }
69
- getLocationFinder() {
70
- return {
71
- getLocationOfDefinition: (key, path) => definition_store_1.DefinitionStore.getLocationInFileById(_1_script_1.ScriptComponent, key, path),
72
- getLocationOfTestDefinition: (definition, path) => {
73
- if (scripting_setup_1.ScriptTestingInternal.isCustomScriptTestCase(definition)) {
74
- let errorMessage = `Internal error: custom script test case is failing. Definition: ${JSON.stringify(definition)}, Path: ${JSON.stringify(path)}`;
75
- throw new Error(errorMessage);
76
- }
77
- else {
78
- return definition_store_1.DefinitionStore.getLocationInFile(ScriptTestComponent_1, definition, path);
79
- }
80
- }
81
- };
82
- }
83
- };
84
- exports.ScriptTestComponent = ScriptTestComponent;
85
- exports.ScriptTestComponent = ScriptTestComponent = ScriptTestComponent_1 = __decorate([
86
- (0, definition_component_1.DefinitionComponentDecorator)({
87
- componentName: 'SCRIPT-TEST',
88
- validationSchema: joi_1.default.object()
89
- .keys({
90
- script: joi_1.default.string().reference(_1_script_1.ScriptComponent).required(),
91
- cases: joi_1.default.array()
92
- .items(joi_1.default.object()
93
- .keys({
94
- actionsBeforeTesting: EventTestActionSchema().default([]).optional()
95
- })
96
- .required())
97
- .required()
98
- })
99
- .required()
100
- })
101
- ], ScriptTestComponent);
102
- //# sourceMappingURL=2-script-test.js.map
@@ -1,7 +0,0 @@
1
- import { ScriptDefinition } from 'script-engine-lib';
2
- import { DefinitionComponent } from '../../decorators/definition-component';
3
- import { Output } from '../../framework/interfaces';
4
- export type EventID = string;
5
- export declare class EventComponent extends DefinitionComponent<ScriptDefinition> {
6
- process(definitions: ScriptDefinition[], output: Output): Promise<void>;
7
- }