dyo-tools 0.1.0 → 0.3.0
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/.c8rc.json +4 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +47 -0
- package/Makefile +34 -0
- package/README.md +0 -7
- package/babel.config.js +1 -0
- package/cucumber-report.html +48 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +63 -0
- package/dist/constants.js.map +1 -0
- 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 +12 -17
- package/dist/core/DTBunch.js +39 -115
- package/dist/core/DTBunch.js.map +1 -1
- package/dist/core/DTComponent.d.ts +13 -5
- package/dist/core/DTComponent.js +39 -1
- package/dist/core/DTComponent.js.map +1 -1
- package/dist/core/DTComponentPhysical.d.ts +12 -0
- package/dist/core/DTComponentPhysical.js +22 -0
- package/dist/core/DTComponentPhysical.js.map +1 -0
- package/dist/core/DTComponentWithMeta.d.ts +2 -2
- package/dist/core/DTComponentWithMeta.js.map +1 -1
- package/dist/core/DTElement.d.ts +7 -7
- package/dist/core/DTElement.js +12 -11
- package/dist/core/DTElement.js.map +1 -1
- package/dist/core/DTManager.d.ts +33 -0
- package/dist/core/DTManager.js +190 -0
- package/dist/core/DTManager.js.map +1 -0
- 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 +7 -1
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/dist/libs/DYOFinder.d.ts +10 -0
- package/dist/libs/DYOFinder.js +96 -0
- package/dist/libs/DYOFinder.js.map +1 -0
- 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 -1321
- 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 -58
- 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/.nojekyll +1 -0
- package/docs/assets/highlight.css +29 -0
- package/docs/assets/main.js +59 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1414 -0
- 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 -0
- 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/jest.config.js +6 -0
- package/package.json +32 -23
- package/src/constants.ts +85 -0
- package/src/core/DTAction.ts +52 -0
- package/src/core/DTBunch.ts +467 -0
- package/src/core/DTComponent.ts +225 -0
- package/src/core/DTComponentPhysical.ts +53 -0
- package/src/core/DTComponentWithMeta.ts +65 -0
- package/src/core/DTElement.ts +102 -0
- package/src/core/DTError.ts +78 -0
- package/src/core/DTManager.ts +465 -0
- package/src/core/DTMaster.ts +318 -0
- package/src/core/DTModule.ts +90 -0
- package/src/index.ts +17 -0
- package/src/libs/DYOFinder.ts +175 -0
- 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 -0
- 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 +261 -0
- package/test/core/DTBunch.spec.ts +897 -0
- package/test/core/DTComponent.double.ts +164 -0
- package/test/core/DTComponent.spec.ts +295 -0
- package/test/core/DTComponentPhysical.double.ts +76 -0
- package/test/core/DTComponentPhysical.spec.ts +78 -0
- package/test/core/DTComponentWithMeta.double.ts +115 -0
- package/test/core/DTComponentWithMeta.spec.ts +124 -0
- package/test/core/DTElement.double.ts +163 -0
- package/test/core/DTElement.spec.ts +146 -0
- package/test/core/DTError.double.ts +92 -0
- package/test/core/DTError.spec.ts +89 -0
- package/test/core/DTManager.double.ts +216 -0
- package/test/core/DTManager.spec.ts +965 -0
- 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 +243 -0
- package/test/libs/DYOFinder.double.ts +152 -0
- package/test/libs/DYOFinder.spec.ts +194 -0
- package/test/libs/player/DTPlayer.element.double.ts +55 -0
- 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/tsconfig.dev.json +22 -0
- package/tsconfig.json +21 -0
- package/dist/core/DTPlayer.d.ts +0 -8
- package/dist/core/DTPlayer.js +0 -30
- package/dist/core/DTPlayer.js.map +0 -1
- package/dist/utils/filters.d.ts +0 -6
- package/dist/utils/filters.js +0 -39
- package/dist/utils/filters.js.map +0 -1
|
@@ -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
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// All exports
|
|
2
|
+
// CORE
|
|
3
|
+
export { default as DTComponent } from './core/DTComponent';
|
|
4
|
+
export { default as DTComponentWithMeta } from './core/DTComponentWithMeta';
|
|
5
|
+
export { default as DTComponentPhysical } from './core/DTComponentPhysical';
|
|
6
|
+
export { default as DTElement } from './core/DTElement';
|
|
7
|
+
export { default as DTBunch } from './core/DTBunch';
|
|
8
|
+
export { default as DTManager } from './core/DTManager';
|
|
9
|
+
export { default as DTMaster } from './core/DTMaster';
|
|
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,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DYOFinderComponentType,
|
|
3
|
+
DYOFinderConfiguration,
|
|
4
|
+
DYOFinderFilterOperator,
|
|
5
|
+
DYOFinderFilters,
|
|
6
|
+
FilterOperatorType,
|
|
7
|
+
StandardPrimitiveType,
|
|
8
|
+
StandardPrimitiveTypeWithArray,
|
|
9
|
+
} from '../types';
|
|
10
|
+
|
|
11
|
+
export default class DYOFinder {
|
|
12
|
+
/**
|
|
13
|
+
* Current DTComponent associated to the Finder.
|
|
14
|
+
*/
|
|
15
|
+
protected _component: DYOFinderComponentType;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Current DYOFinder configuration applied.
|
|
19
|
+
*/
|
|
20
|
+
protected _configuration: DYOFinderConfiguration;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Set _component and _configuration properties.
|
|
24
|
+
*
|
|
25
|
+
* @param component
|
|
26
|
+
* @param configuration
|
|
27
|
+
*/
|
|
28
|
+
constructor(component: DYOFinderComponentType, configuration: DYOFinderConfiguration) {
|
|
29
|
+
this._component = component;
|
|
30
|
+
this._configuration = configuration;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Getter for _component property.
|
|
35
|
+
*/
|
|
36
|
+
getComponent(): DYOFinderComponentType {
|
|
37
|
+
return this._component;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Return an array of DTComponent from *_component* **_items** property filtered with a **filters** argument.
|
|
42
|
+
*
|
|
43
|
+
* Search filters can be applied on properties depending on the current _configuration provided.
|
|
44
|
+
*
|
|
45
|
+
* For each search filter provided, an object of specific operators is applied :
|
|
46
|
+
* * **BASIC OPERATORS**
|
|
47
|
+
* * **$eq** : The property must be strict equal to the filter value.
|
|
48
|
+
* * **$in** : The property must be included into the filter array.
|
|
49
|
+
* * **$nin** : The property must not be included into the filter array.
|
|
50
|
+
* * **$ne** : The property must be different to the filter value.
|
|
51
|
+
* * **EXTENDED OPERATORS** (meta only)
|
|
52
|
+
* * **$lte** : Number property only. The property must be lower or equal than the filter value.
|
|
53
|
+
* * **$gte** : Number property only. The property must be higher or equal than the filter array.
|
|
54
|
+
* * **$contains** : Array property only. The property must contain the filter value.
|
|
55
|
+
* * **$ncontains** : Array property only. The property must not contain the filter value.
|
|
56
|
+
*
|
|
57
|
+
* If many operators and / or many properties are passed into the **filters** argument, the logic operator applied is
|
|
58
|
+
* **AND**.
|
|
59
|
+
*
|
|
60
|
+
* @param filters Filters Object. The format is :
|
|
61
|
+
* { [property_1] : { [operator_1] : filter_value, [operator_2] : filter_value_2, ... }, [property_2] : { ... }, ... }
|
|
62
|
+
*
|
|
63
|
+
* For **objectSearch** properties, you have to pass the object key before the operator :
|
|
64
|
+
* { [property_1]: { [object_key1] : { [operator_1] : filter_value_1, ... }, [object_key2] : { ... }, ... }, ... }
|
|
65
|
+
* @returns Array of DTComponent instance corresponding to the filters. Empty if no filter or invalid ones are passed.
|
|
66
|
+
*/
|
|
67
|
+
execute<ITEM>(filters: DYOFinderFilters): ITEM[] {
|
|
68
|
+
const items = this._component.getAll();
|
|
69
|
+
const filteredItems = [];
|
|
70
|
+
|
|
71
|
+
for (const item of items) {
|
|
72
|
+
let validItem = !!(Object.keys(filters).length);
|
|
73
|
+
|
|
74
|
+
for (const [propKey, configProp] of Object.entries(this._configuration)) {
|
|
75
|
+
if (filters[propKey]) {
|
|
76
|
+
if (configProp.objectSearch) {
|
|
77
|
+
const objectValue = configProp.getValue(item, this.getComponent());
|
|
78
|
+
if (objectValue) {
|
|
79
|
+
for (const [filterK, filterV] of Object.entries(filters[propKey])) {
|
|
80
|
+
const metaValue = Object.prototype.hasOwnProperty.call(objectValue, filterK) ? objectValue[filterK] : undefined;
|
|
81
|
+
if (!this.checkAllValidFiltersForProp(metaValue, filterV, configProp.operators)) {
|
|
82
|
+
validItem = false;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
validItem = false;
|
|
88
|
+
}
|
|
89
|
+
} else if (!this.checkAllValidFiltersForProp(
|
|
90
|
+
(configProp.getValue(item, this.getComponent()) as StandardPrimitiveType),
|
|
91
|
+
filters[propKey],
|
|
92
|
+
configProp.operators,
|
|
93
|
+
)) {
|
|
94
|
+
validItem = false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (validItem) {
|
|
100
|
+
filteredItems.push(item);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return filteredItems;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private checkAllValidFiltersForProp = (
|
|
108
|
+
itemProp: StandardPrimitiveTypeWithArray,
|
|
109
|
+
operators: Partial<DYOFinderFilterOperator>,
|
|
110
|
+
validOperators: FilterOperatorType[],
|
|
111
|
+
) => {
|
|
112
|
+
if (Object.keys(operators).length) {
|
|
113
|
+
for (const operator of Object.keys(operators)) {
|
|
114
|
+
if (!validOperators.includes(operator as FilterOperatorType)
|
|
115
|
+
|| !this.validFiltersForItem(itemProp, operators[operator], operator as FilterOperatorType)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
private validFiltersForItem(
|
|
125
|
+
itemProp: StandardPrimitiveTypeWithArray,
|
|
126
|
+
filter: StandardPrimitiveTypeWithArray,
|
|
127
|
+
operator: FilterOperatorType,
|
|
128
|
+
): boolean {
|
|
129
|
+
// $eq Filter
|
|
130
|
+
if (operator === FilterOperatorType.EQ) {
|
|
131
|
+
return itemProp === filter;
|
|
132
|
+
}
|
|
133
|
+
// $in Filter
|
|
134
|
+
if (operator === FilterOperatorType.IN) {
|
|
135
|
+
return filter ? (filter as Array<StandardPrimitiveType>).includes(itemProp as StandardPrimitiveType) : false;
|
|
136
|
+
}
|
|
137
|
+
// $nin Filter
|
|
138
|
+
if (operator === FilterOperatorType.NIN) {
|
|
139
|
+
return filter ? !(filter as Array<StandardPrimitiveType>).includes(itemProp as StandardPrimitiveType) : false;
|
|
140
|
+
}
|
|
141
|
+
// $ne Filter
|
|
142
|
+
/* c8 ignore next */
|
|
143
|
+
if (operator === FilterOperatorType.NE) {
|
|
144
|
+
return itemProp !== filter;
|
|
145
|
+
}
|
|
146
|
+
// $lte Filter
|
|
147
|
+
if (operator === FilterOperatorType.LTE) {
|
|
148
|
+
if (typeof itemProp === 'number' && typeof filter === 'number') {
|
|
149
|
+
return itemProp <= filter;
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
// $gte Filter
|
|
154
|
+
if (operator === FilterOperatorType.GTE) {
|
|
155
|
+
if (typeof itemProp === 'number' && typeof filter === 'number') {
|
|
156
|
+
return itemProp >= filter;
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
// $contains Filter
|
|
161
|
+
if (operator === FilterOperatorType.CONTAINS) {
|
|
162
|
+
return (itemProp && Array.isArray(itemProp))
|
|
163
|
+
? (itemProp as Array<StandardPrimitiveType>).includes(filter as StandardPrimitiveType)
|
|
164
|
+
: false;
|
|
165
|
+
}
|
|
166
|
+
// $ncontains Filter
|
|
167
|
+
if (operator === FilterOperatorType.NCONTAINS) {
|
|
168
|
+
return (itemProp && Array.isArray(itemProp))
|
|
169
|
+
? !(itemProp as Array<StandardPrimitiveType>).includes(filter as StandardPrimitiveType)
|
|
170
|
+
: false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -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
|
+
}
|