dyo-tools 0.2.0 → 0.3.2
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/constants.js +4 -4
- package/dist/constants.js.map +1 -1
- package/dist/core/DTAction.d.ts +10 -0
- package/dist/core/DTAction.js +24 -0
- package/dist/core/DTAction.js.map +1 -0
- package/dist/core/DTBunch.d.ts +6 -7
- package/dist/core/DTBunch.js +17 -14
- package/dist/core/DTBunch.js.map +1 -1
- package/dist/core/DTComponentPhysical.d.ts +7 -4
- package/dist/core/DTComponentPhysical.js +6 -0
- package/dist/core/DTComponentPhysical.js.map +1 -1
- package/dist/core/DTElement.d.ts +5 -0
- package/dist/core/DTElement.js +12 -2
- package/dist/core/DTElement.js.map +1 -1
- package/dist/core/DTManager.d.ts +3 -1
- package/dist/core/DTManager.js +24 -14
- package/dist/core/DTManager.js.map +1 -1
- package/dist/core/DTMaster.d.ts +24 -0
- package/dist/core/DTMaster.js +133 -0
- package/dist/core/DTMaster.js.map +1 -0
- package/dist/core/DTModule.d.ts +14 -0
- package/dist/core/DTModule.js +39 -0
- package/dist/core/DTModule.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/libs/player/DTPlayer.element.d.ts +5 -0
- package/dist/libs/player/DTPlayer.element.js +11 -0
- package/dist/libs/player/DTPlayer.element.js.map +1 -0
- package/dist/libs/player/DTPlayer.manager.d.ts +11 -0
- package/dist/libs/player/DTPlayer.manager.js +42 -0
- package/dist/libs/player/DTPlayer.manager.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/core.d.ts +103 -0
- package/dist/types/core.js +15 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/index.d.ts +2 -98
- package/dist/types/index.js +16 -12
- package/dist/types/index.js.map +1 -1
- package/dist/types/player.d.ts +5 -0
- package/dist/types/player.js +3 -0
- package/dist/types/player.js.map +1 -0
- package/docs/assets/highlight.css +29 -29
- package/docs/assets/main.js +4 -3
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +72 -25
- package/docs/classes/core_DTAction.DYOToolsAction.html +89 -0
- package/docs/classes/core_DTBunch.DYOToolsBunch.html +254 -0
- package/docs/classes/core_DTComponent.DYOToolsComponent.html +76 -0
- package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +110 -0
- package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +96 -0
- package/docs/classes/core_DTElement.DYOToolsElement.html +135 -0
- package/docs/classes/core_DTError.DYOToolsError.html +37 -0
- package/docs/classes/core_DTManager.DYOToolsManager.html +237 -0
- package/docs/classes/core_DTMaster.DYOToolsMaster.html +150 -0
- package/docs/classes/core_DTModule.DYOToolsModule.html +92 -0
- package/docs/classes/libs_DYOFinder.DYOFinder.html +34 -0
- package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +134 -0
- package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +243 -0
- package/docs/enums/types_core.FilterOperatorType.html +10 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +1 -46
- package/docs/interfaces/types_core.DTBunchFilters.html +6 -0
- package/docs/interfaces/types_core.DTBunchOptions.html +19 -0
- package/docs/interfaces/types_core.DTBunchToObject.html +7 -0
- package/docs/interfaces/types_core.DTComponentOptions.html +5 -0
- package/docs/interfaces/types_core.DTComponentToObject.html +4 -0
- package/docs/interfaces/types_core.DTElementToObject.html +7 -0
- package/docs/interfaces/types_core.DTManagerFilters.html +6 -0
- package/docs/interfaces/types_core.DTManagerOptions.html +8 -0
- package/docs/interfaces/types_core.DTManagerToObject.html +5 -0
- package/docs/interfaces/types_core.DTMasterToObject.html +8 -0
- package/docs/interfaces/types_core.DTModuleToObject.html +6 -0
- package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +4 -0
- package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +4 -0
- package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +5 -0
- package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +5 -0
- package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +3 -0
- package/docs/modules/constants.html +6 -0
- package/docs/modules/core_DTAction.html +2 -0
- package/docs/modules/core_DTBunch.html +2 -0
- package/docs/modules/core_DTComponent.html +2 -0
- package/docs/modules/core_DTComponentPhysical.html +2 -0
- package/docs/modules/core_DTComponentWithMeta.html +2 -0
- package/docs/modules/core_DTElement.html +2 -0
- package/docs/modules/core_DTError.html +2 -0
- package/docs/modules/core_DTManager.html +2 -0
- package/docs/modules/core_DTMaster.html +2 -0
- package/docs/modules/core_DTModule.html +2 -0
- package/docs/modules/libs_DYOFinder.html +2 -0
- package/docs/modules/libs_player_DTPlayer_element.html +2 -0
- package/docs/modules/libs_player_DTPlayer_manager.html +2 -0
- package/docs/modules/types.html +29 -0
- package/docs/modules/types_core.html +28 -0
- package/docs/modules/types_player.html +2 -0
- package/docs/types/types_core.DTAcceptedMetaData.html +2 -0
- package/docs/types/types_core.DTManagerItemType.html +1 -0
- package/docs/types/types_core.DTManagerItemsType.html +2 -0
- package/docs/types/types_core.DYOFinderComponentType.html +1 -0
- package/docs/types/types_core.DYOFinderConfiguration.html +2 -0
- package/docs/types/types_core.DYOFinderConfigurationProp.html +1 -0
- package/docs/types/types_core.DYOFinderFilterOperator.html +1 -0
- package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +1 -0
- package/docs/types/types_core.DYOFinderFilters.html +1 -0
- package/docs/types/types_core.StandardPrimitiveType.html +2 -0
- package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +1 -0
- package/docs/variables/constants.bunchDefaultOptions.html +2 -0
- package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +1 -0
- package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +1 -0
- package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +1 -0
- package/docs/variables/constants.managerDefaultOptions.html +2 -0
- package/package.json +16 -17
- package/src/constants.ts +4 -4
- package/src/core/DTAction.ts +52 -0
- package/src/core/DTBunch.ts +36 -30
- package/src/core/DTComponent.ts +1 -1
- package/src/core/DTComponentPhysical.ts +20 -5
- package/src/core/DTElement.ts +35 -2
- package/src/core/DTManager.ts +37 -18
- package/src/core/DTMaster.ts +318 -0
- package/src/core/DTModule.ts +90 -0
- package/src/index.ts +9 -1
- package/src/libs/player/DTPlayer.element.ts +9 -0
- package/src/libs/player/DTPlayer.manager.ts +84 -0
- package/src/types/core.ts +169 -0
- package/src/types/index.ts +2 -162
- package/src/types/player.ts +6 -0
- package/test/core/DTAction.double.ts +78 -0
- package/test/core/DTAction.spec.ts +76 -0
- package/test/core/DTBunch.double.ts +18 -10
- package/test/core/DTBunch.spec.ts +83 -68
- package/test/core/DTComponentPhysical.double.ts +3 -3
- package/test/core/DTComponentPhysical.spec.ts +25 -11
- package/test/core/DTElement.double.ts +21 -5
- package/test/core/DTElement.spec.ts +52 -8
- package/test/core/DTError.double.ts +1 -1
- package/test/core/DTManager.double.ts +29 -5
- package/test/core/DTManager.spec.ts +80 -17
- package/test/core/DTMaster.double.ts +141 -0
- package/test/core/DTMaster.spec.ts +584 -0
- package/test/core/DTModule.double.ts +80 -0
- package/test/core/DTModule.spec.ts +138 -0
- package/test/core/copy.spec.ts +20 -4
- package/test/{core/DTPlayer.double.ts → libs/player/DTPlayer.element.double.ts} +15 -24
- package/test/libs/player/DTPlayer.element.spec.ts +28 -0
- package/test/libs/player/DTPlayer.manager.double.ts +92 -0
- package/test/libs/player/DTPlayer.manager.spec.ts +178 -0
- package/LICENSE +0 -21
- package/cucumber.js +0 -9
- package/dist/core/DTPlayer.d.ts +0 -8
- package/dist/core/DTPlayer.js +0 -30
- package/dist/core/DTPlayer.js.map +0 -1
- package/e2e/0.2.0/epic1.feature +0 -29
- package/e2e/0.2.0/epic2.feature +0 -22
- package/e2e/0.2.0/epic3.feature +0 -25
- package/e2e/0.2.0/resources/dominion.js +0 -195
- package/e2e/0.2.0/resources/utils.js +0 -27
- package/e2e/0.2.0/support/steps.js +0 -108
- package/e2e/future/epic4.feature +0 -39
- package/e2e/future/resources/dominion.js +0 -238
- package/e2e/future/resources/utils.js +0 -27
- package/src/core/DTPlayer.ts +0 -57
- package/test/core/DTPlayer.spec.ts +0 -80
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import DYOToolsComponent from './DTComponent';
|
|
2
|
+
import DYOToolsError from './DTError';
|
|
3
|
+
import DYOToolsManager from './DTManager';
|
|
4
|
+
import DYOToolsAction from './DTAction';
|
|
5
|
+
import DYOToolsModule from './DTModule';
|
|
6
|
+
import { DTMasterToObject } from '../types';
|
|
7
|
+
|
|
8
|
+
export default class DYOToolsMaster extends DYOToolsComponent {
|
|
9
|
+
/**
|
|
10
|
+
* Defining component type to "master".
|
|
11
|
+
*/
|
|
12
|
+
protected _componentType: string = 'master';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* DTManager instances handled by the Master.
|
|
16
|
+
*
|
|
17
|
+
* The property is an object with _id value of the Manager instance as key, and Manager instance as value.
|
|
18
|
+
* @protected
|
|
19
|
+
*/
|
|
20
|
+
protected _managers: Record<string, DYOToolsManager>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* DTAction instances handled by the Master.
|
|
24
|
+
*
|
|
25
|
+
* The property is an object with _id value of the Action instance as key, and Action instance as value.
|
|
26
|
+
* @protected
|
|
27
|
+
*/
|
|
28
|
+
protected _actions: Record<string, DYOToolsAction>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* DTModule instance handled by the Master.
|
|
32
|
+
*
|
|
33
|
+
* The property is an object with _id value of the Module instance as key, and Module instance as value.
|
|
34
|
+
* @protected
|
|
35
|
+
*/
|
|
36
|
+
protected _modules: Record<string, DYOToolsModule>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Applying the parent constructor, and initializing all properties to empty object.
|
|
40
|
+
*
|
|
41
|
+
* @param key
|
|
42
|
+
*/
|
|
43
|
+
constructor(key?: string) {
|
|
44
|
+
super(key);
|
|
45
|
+
|
|
46
|
+
this._managers = {};
|
|
47
|
+
this._actions = {};
|
|
48
|
+
this._modules = {};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Add a DTManager **item** into _managers property.
|
|
53
|
+
*
|
|
54
|
+
* The adding process has the following specifications :
|
|
55
|
+
* * If the added manager has the same _id than existing manager, an error occurred (depending on **errors** option).
|
|
56
|
+
* * If the added manager has the same _key than existing manager, an error occurred (depending on **errors** option).
|
|
57
|
+
* * The Master instance becomes the new context of the added item.
|
|
58
|
+
*
|
|
59
|
+
* @param manager DYOToolsManager instance to add.
|
|
60
|
+
*/
|
|
61
|
+
addManager(manager: DYOToolsManager): void {
|
|
62
|
+
// Id conflict
|
|
63
|
+
if (Object.keys(this._managers).includes(manager.getId())) {
|
|
64
|
+
this.triggerError(new DYOToolsError(
|
|
65
|
+
'id_conflict',
|
|
66
|
+
'Manager with same id already exists in the Master instance',
|
|
67
|
+
this,
|
|
68
|
+
manager,
|
|
69
|
+
));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Key conflict
|
|
74
|
+
if (Object.values(this._managers).find((m) => m.getKey() === manager.getKey())) {
|
|
75
|
+
this.triggerError(new DYOToolsError(
|
|
76
|
+
'key_conflict',
|
|
77
|
+
'Manager with same key already exists in the Master instance',
|
|
78
|
+
this,
|
|
79
|
+
manager,
|
|
80
|
+
));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this._managers[manager.getId()] = manager;
|
|
85
|
+
manager.setContext<DYOToolsMaster>(this);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Return one DTManager instance handled by the Master.
|
|
90
|
+
* It could be selected by _id or _key property of the Manager.
|
|
91
|
+
*
|
|
92
|
+
* @param idOrKey String id or key to select.
|
|
93
|
+
* @returns DYOToolsManager selected Manager instance, or undefined if not found.
|
|
94
|
+
*/
|
|
95
|
+
getManager(idOrKey: string): DYOToolsManager | undefined {
|
|
96
|
+
let managerFound = this._managers[idOrKey];
|
|
97
|
+
|
|
98
|
+
if (!managerFound) {
|
|
99
|
+
managerFound = Object.values(this._managers).find((m) => m.getKey() === idOrKey);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return managerFound;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Remove a handled Manager from the Master instance.
|
|
107
|
+
*
|
|
108
|
+
* @param idOrKey String id or key to select.
|
|
109
|
+
*/
|
|
110
|
+
removeManager(idOrKey: string): void {
|
|
111
|
+
const manager = this.getManager(idOrKey);
|
|
112
|
+
|
|
113
|
+
if (manager) {
|
|
114
|
+
delete this._managers[manager.getId()];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Add a DTAction **item** into _actions property.
|
|
120
|
+
*
|
|
121
|
+
* The adding process has the following specifications :
|
|
122
|
+
* * If the added action has the same _id than existing action, an error occurred (depending on **errors** option).
|
|
123
|
+
* * If the added action has the same _key than existing action, an error occurred (depending on **errors** option).
|
|
124
|
+
* * The Master instance becomes the new context of the added item.
|
|
125
|
+
*
|
|
126
|
+
* @param action DYOToolsAction instance to add.
|
|
127
|
+
*/
|
|
128
|
+
addAction(action: DYOToolsAction): void {
|
|
129
|
+
// Id conflict
|
|
130
|
+
if (Object.keys(this._actions).includes(action.getId())) {
|
|
131
|
+
this.triggerError(new DYOToolsError(
|
|
132
|
+
'id_conflict',
|
|
133
|
+
'Action with same id already exists in the Master instance',
|
|
134
|
+
this,
|
|
135
|
+
action,
|
|
136
|
+
));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Key conflict
|
|
141
|
+
if (Object.values(this._actions).find((m) => m.getKey() === action.getKey())) {
|
|
142
|
+
this.triggerError(new DYOToolsError(
|
|
143
|
+
'key_conflict',
|
|
144
|
+
'Action with same key already exists in the Master instance',
|
|
145
|
+
this,
|
|
146
|
+
action,
|
|
147
|
+
));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
this._actions[action.getId()] = action;
|
|
152
|
+
action.setContext<DYOToolsMaster>(this);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Return one DTAction instance handled by the Master.
|
|
157
|
+
* It could be selected by _id or _key property of the Action.
|
|
158
|
+
*
|
|
159
|
+
* @param idOrKey String id or key to select.
|
|
160
|
+
* @returns DYOToolsAction selected Action instance, or undefined if not found.
|
|
161
|
+
*/
|
|
162
|
+
getAction(idOrKey: string): DYOToolsAction | undefined {
|
|
163
|
+
let actionFound = this._actions[idOrKey];
|
|
164
|
+
|
|
165
|
+
if (!actionFound) {
|
|
166
|
+
actionFound = Object.values(this._actions).find((a) => a.getKey() === idOrKey);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return actionFound;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Remove a handled Action from the Master instance.
|
|
174
|
+
*
|
|
175
|
+
* @param idOrKey String id or key to select.
|
|
176
|
+
*/
|
|
177
|
+
removeAction(idOrKey: string): void {
|
|
178
|
+
const action = this.getAction(idOrKey);
|
|
179
|
+
|
|
180
|
+
if (action) {
|
|
181
|
+
delete this._actions[action.getId()];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Trigger the **execute** process of an action handled by the Master instance.
|
|
187
|
+
* It could be selected by _id or _key property of the Action.
|
|
188
|
+
*
|
|
189
|
+
* @param idOrKey String id or key to select.
|
|
190
|
+
* @param payload Object payload for the action execution.
|
|
191
|
+
* @returns Promise action execution.
|
|
192
|
+
*/
|
|
193
|
+
async executeAction(idOrKey: string, payload: unknown): Promise<void> {
|
|
194
|
+
const action = this.getAction(idOrKey);
|
|
195
|
+
|
|
196
|
+
if (action) {
|
|
197
|
+
await this.getAction(idOrKey).execute(payload);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Add a DTModule **item** into _modules property.
|
|
203
|
+
*
|
|
204
|
+
* The adding process has the following specifications :
|
|
205
|
+
* * If the added module has the same _id than existing module, an error occurred (depending on **errors** option).
|
|
206
|
+
* * If the added module has the same _key than existing module, an error occurred (depending on **errors** option).
|
|
207
|
+
* * The Master instance becomes the new context of the added item.
|
|
208
|
+
*
|
|
209
|
+
* @param module DYOToolsModule instance to add.
|
|
210
|
+
*/
|
|
211
|
+
addModule(module: DYOToolsModule): void {
|
|
212
|
+
// Id conflict
|
|
213
|
+
if (Object.keys(this._modules).includes(module.getId())) {
|
|
214
|
+
this.triggerError(new DYOToolsError(
|
|
215
|
+
'id_conflict',
|
|
216
|
+
'Module with same id already exists in the Master instance',
|
|
217
|
+
this,
|
|
218
|
+
module,
|
|
219
|
+
));
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Key conflict
|
|
224
|
+
if (Object.values(this._modules).find((m) => m.getKey() === module.getKey())) {
|
|
225
|
+
this.triggerError(new DYOToolsError(
|
|
226
|
+
'key_conflict',
|
|
227
|
+
'Module with same key already exists in the Master instance',
|
|
228
|
+
this,
|
|
229
|
+
module,
|
|
230
|
+
));
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
this._modules[module.getId()] = module;
|
|
235
|
+
module.setContext<DYOToolsMaster>(this);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Return one DTModule instance handled by the Master.
|
|
240
|
+
* It could be selected by _id or _key property of the Module.
|
|
241
|
+
*
|
|
242
|
+
* @param idOrKey String id or key to select.
|
|
243
|
+
* @returns DYOToolsModule selected Module instance, or undefined if not found.
|
|
244
|
+
*/
|
|
245
|
+
getModule(idOrKey: string): DYOToolsModule | undefined {
|
|
246
|
+
let moduleFound = this._modules[idOrKey];
|
|
247
|
+
|
|
248
|
+
if (!moduleFound) {
|
|
249
|
+
moduleFound = Object.values(this._modules).find((m) => m.getKey() === idOrKey);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return moduleFound;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Remove a handled Module from the Master instance.
|
|
257
|
+
*
|
|
258
|
+
* @param idOrKey String id or key to select.
|
|
259
|
+
*/
|
|
260
|
+
removeModule(idOrKey: string): void {
|
|
261
|
+
const module = this.getModule(idOrKey);
|
|
262
|
+
|
|
263
|
+
if (module) {
|
|
264
|
+
delete this._modules[module.getId()];
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Return String representation of the Master instance.
|
|
270
|
+
*
|
|
271
|
+
* @returns String representation of the Master.
|
|
272
|
+
*/
|
|
273
|
+
toString(): string {
|
|
274
|
+
const managersLabel = `Managers: ${Object.keys(this._managers).length}`;
|
|
275
|
+
const actionsLabel = `Actions: ${Object.keys(this._actions).length}`;
|
|
276
|
+
const modulesLabel = `Modules: ${Object.keys(this._modules).length}`;
|
|
277
|
+
|
|
278
|
+
return `Component ${this._key} - Type: Master - ${managersLabel} - ${actionsLabel} - ${modulesLabel}`;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Return JSON Object representation of the Master instance.
|
|
283
|
+
*
|
|
284
|
+
* JSON Object returned has the following structure :
|
|
285
|
+
* * **id** : _id property of the Master.
|
|
286
|
+
* * **key** : _key property of the Master.
|
|
287
|
+
* * **type** : _componentType property of the Master.
|
|
288
|
+
* * **managers** : Array of JSON Object representation for each DTManager instance in _managers property of the Master.
|
|
289
|
+
* * **actions** : Array of JSON Object representation for each DTAction instance in _actions property of the Master.
|
|
290
|
+
* * **modules** : Array of JSON Object representation for each DTModule instance in _modules property of the Master.
|
|
291
|
+
*
|
|
292
|
+
* @returns JSON Object representation of the Master.
|
|
293
|
+
*/
|
|
294
|
+
toObject(): DTMasterToObject {
|
|
295
|
+
const toObject: DTMasterToObject = {
|
|
296
|
+
id: this._id,
|
|
297
|
+
key: this._key,
|
|
298
|
+
type: this._componentType,
|
|
299
|
+
managers: [],
|
|
300
|
+
actions: [],
|
|
301
|
+
modules: [],
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
if (Object.keys(this._managers).length) {
|
|
305
|
+
toObject.managers = Object.values(this._managers).map((obj) => obj.toObject());
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (Object.keys(this._actions).length) {
|
|
309
|
+
toObject.actions = Object.values(this._actions).map((obj) => obj.toObject());
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (Object.keys(this._modules).length) {
|
|
313
|
+
toObject.modules = Object.values(this._modules).map((obj) => obj.toObject());
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return toObject;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import DYOToolsComponent from './DTComponent';
|
|
2
|
+
import { DTModuleToObject } from '../types';
|
|
3
|
+
import DYOToolsMaster from './DTMaster';
|
|
4
|
+
|
|
5
|
+
export default class DYOToolsModule extends DYOToolsComponent {
|
|
6
|
+
/**
|
|
7
|
+
* Defining component type to "module".
|
|
8
|
+
*/
|
|
9
|
+
protected _componentType: string = 'module';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Defining if the module is enabled or not.
|
|
13
|
+
* @protected
|
|
14
|
+
*/
|
|
15
|
+
protected _enabled: boolean;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Applying the parent constructor, and initializing _enabled property to true by default.
|
|
19
|
+
*
|
|
20
|
+
* @param key
|
|
21
|
+
*/
|
|
22
|
+
constructor(key?: string) {
|
|
23
|
+
super(key);
|
|
24
|
+
|
|
25
|
+
this._enabled = true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns Master component from context, or undefined.
|
|
30
|
+
*/
|
|
31
|
+
getMaster(): DYOToolsMaster | undefined {
|
|
32
|
+
return this.getContext<DYOToolsMaster>('master');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Getter for the _enabled property.
|
|
37
|
+
*/
|
|
38
|
+
isEnabled(): boolean {
|
|
39
|
+
return this._enabled;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Change _enabled property to true.
|
|
44
|
+
*/
|
|
45
|
+
enable(): void {
|
|
46
|
+
this._enabled = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Change _enabled property to false.
|
|
51
|
+
*/
|
|
52
|
+
disable(): void {
|
|
53
|
+
this._enabled = false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Return String representation of the Module instance.
|
|
58
|
+
*
|
|
59
|
+
* @returns String representation of the Module.
|
|
60
|
+
*/
|
|
61
|
+
toString(): string {
|
|
62
|
+
let extraLabel: string = '';
|
|
63
|
+
|
|
64
|
+
if (!this._enabled) {
|
|
65
|
+
extraLabel = ' - Disabled';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return `Component ${this._key} - Type: Module${extraLabel}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Return JSON Object representation of the Module instance.
|
|
73
|
+
*
|
|
74
|
+
* JSON Object returned has the following structure :
|
|
75
|
+
* * **id** : _id property of the Module.
|
|
76
|
+
* * **key** : _key property of the Module.
|
|
77
|
+
* * **type** : _componentType property of the Module.
|
|
78
|
+
* * **enabled** : _enabled property of the Module.
|
|
79
|
+
*
|
|
80
|
+
* @returns JSON Object representation of the Module.
|
|
81
|
+
*/
|
|
82
|
+
toObject(): DTModuleToObject {
|
|
83
|
+
return {
|
|
84
|
+
id: this._id,
|
|
85
|
+
key: this._key,
|
|
86
|
+
type: this._componentType,
|
|
87
|
+
enabled: this._enabled,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
// All exports
|
|
2
|
+
// CORE
|
|
2
3
|
export { default as DTComponent } from './core/DTComponent';
|
|
3
4
|
export { default as DTComponentWithMeta } from './core/DTComponentWithMeta';
|
|
4
5
|
export { default as DTComponentPhysical } from './core/DTComponentPhysical';
|
|
5
6
|
export { default as DTElement } from './core/DTElement';
|
|
6
7
|
export { default as DTBunch } from './core/DTBunch';
|
|
7
8
|
export { default as DTManager } from './core/DTManager';
|
|
8
|
-
export { default as
|
|
9
|
+
export { default as DTMaster } from './core/DTMaster';
|
|
9
10
|
export { default as DTError } from './core/DTError';
|
|
11
|
+
export { default as DTAction } from './core/DTAction';
|
|
12
|
+
export { default as DTModule } from './core/DTModule';
|
|
13
|
+
|
|
14
|
+
// LIBS
|
|
15
|
+
// PLAYER
|
|
16
|
+
export { default as DTPlayer } from './libs/player/DTPlayer.element';
|
|
17
|
+
export { default as DTPlayerManager } from './libs/player/DTPlayer.manager';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DTAcceptedMetaData } from '../../types';
|
|
2
|
+
import DYOToolsElement from '../../core/DTElement';
|
|
3
|
+
|
|
4
|
+
export default class DYOToolsPlayer<IComponentMeta extends DTAcceptedMetaData = DTAcceptedMetaData> extends DYOToolsElement<IComponentMeta> {
|
|
5
|
+
/**
|
|
6
|
+
* Defining component domain to "player".
|
|
7
|
+
*/
|
|
8
|
+
protected _domain = 'player';
|
|
9
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import DYOToolsManager from '../../core/DTManager';
|
|
2
|
+
import DYOToolsPlayer from './DTPlayer.element';
|
|
3
|
+
import { DTBunchFilters, DTManagerOptions, DTPlayerManagerSimpleConfiguration } from '../../types';
|
|
4
|
+
import { DTPlayer } from '../../index';
|
|
5
|
+
|
|
6
|
+
export default class DYOToolsPlayerManager extends DYOToolsManager<DYOToolsPlayer> {
|
|
7
|
+
/**
|
|
8
|
+
* Defining component domain to "player".
|
|
9
|
+
*/
|
|
10
|
+
protected _domain = 'player';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Applying the parent constructor. The key is **player** by default.
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
* The constructor uses a Configuration JSON Object, with following properties :
|
|
17
|
+
* * **players** : Default player configuration.
|
|
18
|
+
* If **players** is a number, it generates this number of DTPlayer instances and add it to the library.
|
|
19
|
+
* If **players** is an array of DTPlayer instances, it adds these to the library.
|
|
20
|
+
* * **errors** : Set **errors** option of the Manager.
|
|
21
|
+
*
|
|
22
|
+
* @param configuration DTPlayerManagerSimpleConfiguration Optional configuration to apply.
|
|
23
|
+
*/
|
|
24
|
+
constructor(configuration?: DTPlayerManagerSimpleConfiguration) {
|
|
25
|
+
super('player');
|
|
26
|
+
|
|
27
|
+
// Simple Configuration
|
|
28
|
+
const finalConfig = configuration ?? {};
|
|
29
|
+
const finalOptions: DTManagerOptions = this._options;
|
|
30
|
+
if (finalConfig.players) {
|
|
31
|
+
if (typeof finalConfig.players === 'number' && finalConfig.players > 0) {
|
|
32
|
+
let i = 1;
|
|
33
|
+
while (i <= finalConfig.players) {
|
|
34
|
+
const player = new DTPlayer(`player${i}`);
|
|
35
|
+
this._library.add(player);
|
|
36
|
+
i += 1;
|
|
37
|
+
}
|
|
38
|
+
} else if (Array.isArray(finalConfig.players)) {
|
|
39
|
+
this._library.addMany(finalConfig.players);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (finalConfig.errors) {
|
|
44
|
+
finalOptions.errors = finalConfig.errors;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get one DTPlayer instance by id into the library.
|
|
50
|
+
*
|
|
51
|
+
* @param id string _id property of the DTPlayer instance to get.
|
|
52
|
+
*/
|
|
53
|
+
getPlayer(id: string): DYOToolsPlayer {
|
|
54
|
+
return this._library.get(id);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Add one DTPlayer instance into the library.
|
|
59
|
+
*
|
|
60
|
+
* @param player DYOToolsPlayer instance to add.
|
|
61
|
+
*/
|
|
62
|
+
addPlayer(player: DYOToolsPlayer): void {
|
|
63
|
+
this._library.add(player);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Remove one DTPlayer instance by id from the library.
|
|
68
|
+
*
|
|
69
|
+
* @param id string _id property of the DTPlayer instance to remove.
|
|
70
|
+
*/
|
|
71
|
+
removePlayer(id: string): void {
|
|
72
|
+
this._library.remove(id);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Find DTPlayer instances into the Library.
|
|
77
|
+
*
|
|
78
|
+
* @see [find](#find) method for search specifications.
|
|
79
|
+
* @param filters DTBunchFilters filters to apply.
|
|
80
|
+
*/
|
|
81
|
+
findPlayers(filters: Partial<DTBunchFilters>): DYOToolsPlayer[] {
|
|
82
|
+
return this._library.find(filters);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { DTBunch, DTComponent } from '../index';
|
|
2
|
+
import DYOToolsElement from '../core/DTElement';
|
|
3
|
+
|
|
4
|
+
/** Constants Enum * */
|
|
5
|
+
export enum FilterOperatorType {
|
|
6
|
+
EQ = '$eq',
|
|
7
|
+
IN = '$in',
|
|
8
|
+
NIN = '$nin',
|
|
9
|
+
NE = '$ne',
|
|
10
|
+
LTE = '$lte',
|
|
11
|
+
GTE = '$gte',
|
|
12
|
+
CONTAINS = '$contains',
|
|
13
|
+
NCONTAINS = '$ncontains',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Common Types * */
|
|
17
|
+
export type StandardPrimitiveType = string | number | boolean | null | undefined;
|
|
18
|
+
export type StandardPrimitiveTypeWithArray = string | number | boolean | Array<string | number | boolean> | null | undefined;
|
|
19
|
+
|
|
20
|
+
/** DYO Finder interfaces * */
|
|
21
|
+
export type DYOFinderConfiguration = Record<string, DYOFinderConfigurationProp>;
|
|
22
|
+
export type DYOFinderComponentType = DTComponent & {
|
|
23
|
+
getAll: () => DTComponent[],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export interface DYOFinderConfigurationPropDefault {
|
|
27
|
+
operators: FilterOperatorType[],
|
|
28
|
+
getValue: (item: DTComponent, ctx?: DTComponent) => StandardPrimitiveType,
|
|
29
|
+
objectSearch: false,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface DYOFinderConfigurationPropObjectSearch {
|
|
33
|
+
operators: FilterOperatorType[],
|
|
34
|
+
getValue: (item: DTComponent, ctx?: DTComponent) => Record<string, StandardPrimitiveTypeWithArray>,
|
|
35
|
+
objectSearch: true,
|
|
36
|
+
}
|
|
37
|
+
export type DYOFinderConfigurationProp = DYOFinderConfigurationPropDefault | DYOFinderConfigurationPropObjectSearch;
|
|
38
|
+
|
|
39
|
+
export interface DYOFinderFilterOperatorBase {
|
|
40
|
+
[FilterOperatorType.EQ]: StandardPrimitiveType
|
|
41
|
+
[FilterOperatorType.IN]: Array<StandardPrimitiveType>
|
|
42
|
+
[FilterOperatorType.NIN]: Array<StandardPrimitiveType>
|
|
43
|
+
[FilterOperatorType.NE]: StandardPrimitiveType
|
|
44
|
+
}
|
|
45
|
+
export interface DYOFinderFilterOperatorAdvanced {
|
|
46
|
+
[FilterOperatorType.LTE]: number
|
|
47
|
+
[FilterOperatorType.GTE]: number
|
|
48
|
+
[FilterOperatorType.CONTAINS]: StandardPrimitiveType
|
|
49
|
+
[FilterOperatorType.NCONTAINS]: StandardPrimitiveType
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type DYOFinderFilterOperator = DYOFinderFilterOperatorBase & DYOFinderFilterOperatorAdvanced;
|
|
53
|
+
export type DYOFinderFilterOperatorArgument = Partial<DYOFinderFilterOperator | Record<string, Partial<DYOFinderFilterOperator>>>;
|
|
54
|
+
export type DYOFinderFilters = Record<string, DYOFinderFilterOperatorArgument>;
|
|
55
|
+
|
|
56
|
+
/** DTComponent interfaces * */
|
|
57
|
+
/**
|
|
58
|
+
* DTComponent default options configuration.
|
|
59
|
+
*/
|
|
60
|
+
export interface DTComponentOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Default *false*. If *true*, no exception is thrown when an error occurred, a new DTError instance is
|
|
63
|
+
* added to the _errors property array instead. If *false*, throw the exception with a DTError instance.
|
|
64
|
+
*/
|
|
65
|
+
errors: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface DTComponentToObject {
|
|
69
|
+
id: string
|
|
70
|
+
key: string
|
|
71
|
+
type: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** DTComponentWithMeta interfaces * */
|
|
75
|
+
export type DTAcceptedMetaData = Record<
|
|
76
|
+
string,
|
|
77
|
+
StandardPrimitiveTypeWithArray
|
|
78
|
+
>;
|
|
79
|
+
|
|
80
|
+
/** DTElement interfaces * */
|
|
81
|
+
export interface DTElementToObject<IComponentMeta> extends DTComponentToObject {
|
|
82
|
+
owner?: string
|
|
83
|
+
meta?: Partial<IComponentMeta>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** DTBunch interfaces * */
|
|
87
|
+
/**
|
|
88
|
+
* DTBunch option configuration.
|
|
89
|
+
*/
|
|
90
|
+
export interface DTBunchOptions extends DTComponentOptions {
|
|
91
|
+
/**
|
|
92
|
+
* Default *false*. If *true*, an error occurred when adding a new DTElement with the same key of an
|
|
93
|
+
* existing element into the bunch.
|
|
94
|
+
*/
|
|
95
|
+
uniqueKey: boolean
|
|
96
|
+
/**
|
|
97
|
+
* Default *false*. If *true*, when a new DTElement is added at existing index (using **addAtIndex**
|
|
98
|
+
* or **addManyAtIndex** method), this component replaces the old one. If *false*, this component is added at the specified
|
|
99
|
+
* index and other existing component are reindexed with the following index.
|
|
100
|
+
*/
|
|
101
|
+
replaceIndex: boolean
|
|
102
|
+
/**
|
|
103
|
+
* Default *false*. If *true*, when a new DTElement is added, the owner of this element becomes
|
|
104
|
+
* automatically the current bunch owner.
|
|
105
|
+
*/
|
|
106
|
+
inheritOwner: boolean
|
|
107
|
+
/**
|
|
108
|
+
* Default *false*. If *true*, the container is not changed when a new DTElement is added.
|
|
109
|
+
* If *false*, when a new DTElement is added, the container of this element becomes automatically the current bunch instance
|
|
110
|
+
* and the element is removed from the old container Component (if defined).
|
|
111
|
+
*/
|
|
112
|
+
virtualContainer: boolean
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface DTBunchToObject<IComponentMeta> extends DTComponentToObject {
|
|
116
|
+
items: Array<DTElementToObject<DTAcceptedMetaData>>
|
|
117
|
+
owner?: string
|
|
118
|
+
meta?: Partial<IComponentMeta>
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface DTBunchFilters {
|
|
122
|
+
id: Partial<DYOFinderFilterOperatorBase>
|
|
123
|
+
key: Partial<DYOFinderFilterOperatorBase>
|
|
124
|
+
container: Partial<DYOFinderFilterOperatorBase>
|
|
125
|
+
owner: Partial<DYOFinderFilterOperatorBase>
|
|
126
|
+
meta: Record<string, Partial<DYOFinderFilterOperatorBase & DYOFinderFilterOperatorAdvanced>>
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** DTManager interfaces * */
|
|
130
|
+
export type DTManagerItemsType<IBunchItem extends DYOToolsElement<DTAcceptedMetaData>> = Record<string, DTManagerItemType<IBunchItem>>;
|
|
131
|
+
export type DTManagerItemType<IBunchItem extends DYOToolsElement<DTAcceptedMetaData>> = {
|
|
132
|
+
scope: string,
|
|
133
|
+
item: DTBunch<IBunchItem>,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export interface DTManagerFilters extends DYOFinderFilters {
|
|
137
|
+
id: Partial<DYOFinderFilterOperatorBase>
|
|
138
|
+
key: Partial<DYOFinderFilterOperatorBase>
|
|
139
|
+
owner: Partial<DYOFinderFilterOperatorBase>
|
|
140
|
+
scope: Partial<DYOFinderFilterOperatorBase>
|
|
141
|
+
meta: Record<string, Partial<DYOFinderFilterOperatorBase & DYOFinderFilterOperatorAdvanced>>
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* DTManager option configuration.
|
|
146
|
+
*/
|
|
147
|
+
export interface DTManagerOptions extends DTComponentOptions {
|
|
148
|
+
/**
|
|
149
|
+
* Default *false*. If *true*, when a bunch instance is removed from the Manager _items, the process performs also
|
|
150
|
+
* a removal from the Manager Library of all DTElement instances of the bunch.
|
|
151
|
+
*/
|
|
152
|
+
libraryDeletion: boolean,
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface DTManagerToObject extends DTComponentToObject {
|
|
156
|
+
items: Array<DTBunchToObject<DTAcceptedMetaData> & { scope: string }>
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** DTModule interfaces * */
|
|
160
|
+
export interface DTModuleToObject extends DTComponentToObject {
|
|
161
|
+
enabled: boolean
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** DTMaster interfaces * */
|
|
165
|
+
export interface DTMasterToObject extends DTComponentToObject {
|
|
166
|
+
managers: Array<DTManagerToObject>,
|
|
167
|
+
actions: Array<DTComponentToObject>,
|
|
168
|
+
modules: Array<DTModuleToObject>,
|
|
169
|
+
}
|