dyo-tools 0.4.0 → 0.4.1

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 (157) hide show
  1. package/{dist/index.d.ts → index.d.ts} +1 -0
  2. package/{dist/index.d.ts.map → index.d.ts.map} +1 -1
  3. package/{dist/index.js → index.js} +1 -0
  4. package/package.json +6 -56
  5. package/.c8rc.json +0 -4
  6. package/.eslintignore +0 -2
  7. package/.eslintrc.json +0 -47
  8. package/Makefile +0 -34
  9. package/README.md +0 -0
  10. package/babel.config.js +0 -1
  11. package/docs/.nojekyll +0 -1
  12. package/docs/assets/highlight.css +0 -29
  13. package/docs/assets/main.js +0 -59
  14. package/docs/assets/search.js +0 -1
  15. package/docs/assets/style.css +0 -1414
  16. package/docs/index.html +0 -1
  17. package/integration/data/components/DTHero.ts +0 -42
  18. package/integration/data/components/DTHeroManager.ts +0 -11
  19. package/integration/data/components/DTHeroPlayZone.ts +0 -6
  20. package/integration/data/components/DTHeroPlayerHand.ts +0 -11
  21. package/integration/data/components/index.ts +0 -5
  22. package/integration/data/in/heroIn.helper.ts +0 -8
  23. package/integration/data/in/playerIn.helper.ts +0 -13
  24. package/integration/data/out/heroOut.helper.ts +0 -48
  25. package/integration/endings/synchronisation.ending.ts +0 -25
  26. package/integration/scenes/drawCard.scene.ts +0 -31
  27. package/integration/scenes/empty.scene.ts +0 -6
  28. package/integration/scenes/playCard.scene.ts +0 -23
  29. package/integration/scenes/playerLeave.scene.ts +0 -33
  30. package/integration/stages/baseDix.stage.ts +0 -137
  31. package/integration/stages/syncDix.stage.ts +0 -36
  32. package/integration/tests/scenario1.spec.ts +0 -55
  33. package/integration/types/index.ts +0 -24
  34. package/jest-integration.config.ts +0 -25
  35. package/jest.config.ts +0 -26
  36. package/src/constants.ts +0 -87
  37. package/src/core/DTAction.ts +0 -54
  38. package/src/core/DTBunch.ts +0 -531
  39. package/src/core/DTComponent.ts +0 -258
  40. package/src/core/DTComponentPhysical.ts +0 -88
  41. package/src/core/DTComponentWithMeta.ts +0 -98
  42. package/src/core/DTElement.ts +0 -111
  43. package/src/core/DTError.ts +0 -78
  44. package/src/core/DTManager.ts +0 -555
  45. package/src/core/DTMaster.ts +0 -366
  46. package/src/core/DTModule.ts +0 -96
  47. package/src/index.ts +0 -17
  48. package/src/libs/DYOFinder.ts +0 -175
  49. package/src/libs/dix/DIXModule.module.ts +0 -98
  50. package/src/libs/player/DTPlayer.element.ts +0 -9
  51. package/src/libs/player/DTPlayer.manager.ts +0 -70
  52. package/src/types/core.ts +0 -204
  53. package/src/types/index.ts +0 -2
  54. package/src/types/player.ts +0 -5
  55. package/test/core/DTAction.double.ts +0 -62
  56. package/test/core/DTAction.spec.ts +0 -68
  57. package/test/core/DTBunch.double.ts +0 -175
  58. package/test/core/DTBunch.spec.ts +0 -822
  59. package/test/core/DTComponent.double.ts +0 -179
  60. package/test/core/DTComponent.spec.ts +0 -297
  61. package/test/core/DTComponentPhysical.double.ts +0 -62
  62. package/test/core/DTComponentPhysical.spec.ts +0 -81
  63. package/test/core/DTComponentWithMeta.double.ts +0 -122
  64. package/test/core/DTComponentWithMeta.spec.ts +0 -129
  65. package/test/core/DTElement.double.ts +0 -142
  66. package/test/core/DTElement.spec.ts +0 -123
  67. package/test/core/DTError.double.ts +0 -57
  68. package/test/core/DTError.spec.ts +0 -78
  69. package/test/core/DTManager.double.ts +0 -149
  70. package/test/core/DTManager.spec.ts +0 -874
  71. package/test/core/DTMaster.double.ts +0 -117
  72. package/test/core/DTMaster.spec.ts +0 -537
  73. package/test/core/DTModule.double.ts +0 -67
  74. package/test/core/DTModule.spec.ts +0 -124
  75. package/test/core/copy.spec.ts +0 -222
  76. package/test/libs/DYOFinder.double.ts +0 -152
  77. package/test/libs/DYOFinder.spec.ts +0 -194
  78. package/test/libs/player/DTPlayer.element.double.ts +0 -55
  79. package/test/libs/player/DTPlayer.element.spec.ts +0 -28
  80. package/test/libs/player/DTPlayer.manager.double.ts +0 -92
  81. package/test/libs/player/DTPlayer.manager.spec.ts +0 -178
  82. package/tsconfig.dev.json +0 -19
  83. package/tsconfig.json +0 -18
  84. /package/{dist/constants.d.ts → constants.d.ts} +0 -0
  85. /package/{dist/constants.d.ts.map → constants.d.ts.map} +0 -0
  86. /package/{dist/constants.js → constants.js} +0 -0
  87. /package/{dist/constants.js.map → constants.js.map} +0 -0
  88. /package/{dist/core → core}/DTAction.d.ts +0 -0
  89. /package/{dist/core → core}/DTAction.d.ts.map +0 -0
  90. /package/{dist/core → core}/DTAction.js +0 -0
  91. /package/{dist/core → core}/DTAction.js.map +0 -0
  92. /package/{dist/core → core}/DTBunch.d.ts +0 -0
  93. /package/{dist/core → core}/DTBunch.d.ts.map +0 -0
  94. /package/{dist/core → core}/DTBunch.js +0 -0
  95. /package/{dist/core → core}/DTBunch.js.map +0 -0
  96. /package/{dist/core → core}/DTComponent.d.ts +0 -0
  97. /package/{dist/core → core}/DTComponent.d.ts.map +0 -0
  98. /package/{dist/core → core}/DTComponent.js +0 -0
  99. /package/{dist/core → core}/DTComponent.js.map +0 -0
  100. /package/{dist/core → core}/DTComponentPhysical.d.ts +0 -0
  101. /package/{dist/core → core}/DTComponentPhysical.d.ts.map +0 -0
  102. /package/{dist/core → core}/DTComponentPhysical.js +0 -0
  103. /package/{dist/core → core}/DTComponentPhysical.js.map +0 -0
  104. /package/{dist/core → core}/DTComponentWithMeta.d.ts +0 -0
  105. /package/{dist/core → core}/DTComponentWithMeta.d.ts.map +0 -0
  106. /package/{dist/core → core}/DTComponentWithMeta.js +0 -0
  107. /package/{dist/core → core}/DTComponentWithMeta.js.map +0 -0
  108. /package/{dist/core → core}/DTElement.d.ts +0 -0
  109. /package/{dist/core → core}/DTElement.d.ts.map +0 -0
  110. /package/{dist/core → core}/DTElement.js +0 -0
  111. /package/{dist/core → core}/DTElement.js.map +0 -0
  112. /package/{dist/core → core}/DTError.d.ts +0 -0
  113. /package/{dist/core → core}/DTError.d.ts.map +0 -0
  114. /package/{dist/core → core}/DTError.js +0 -0
  115. /package/{dist/core → core}/DTError.js.map +0 -0
  116. /package/{dist/core → core}/DTManager.d.ts +0 -0
  117. /package/{dist/core → core}/DTManager.d.ts.map +0 -0
  118. /package/{dist/core → core}/DTManager.js +0 -0
  119. /package/{dist/core → core}/DTManager.js.map +0 -0
  120. /package/{dist/core → core}/DTMaster.d.ts +0 -0
  121. /package/{dist/core → core}/DTMaster.d.ts.map +0 -0
  122. /package/{dist/core → core}/DTMaster.js +0 -0
  123. /package/{dist/core → core}/DTMaster.js.map +0 -0
  124. /package/{dist/core → core}/DTModule.d.ts +0 -0
  125. /package/{dist/core → core}/DTModule.d.ts.map +0 -0
  126. /package/{dist/core → core}/DTModule.js +0 -0
  127. /package/{dist/core → core}/DTModule.js.map +0 -0
  128. /package/{dist/index.js.map → index.js.map} +0 -0
  129. /package/{dist/libs → libs}/DYOFinder.d.ts +0 -0
  130. /package/{dist/libs → libs}/DYOFinder.d.ts.map +0 -0
  131. /package/{dist/libs → libs}/DYOFinder.js +0 -0
  132. /package/{dist/libs → libs}/DYOFinder.js.map +0 -0
  133. /package/{dist/libs → libs}/dix/DIXModule.module.d.ts +0 -0
  134. /package/{dist/libs → libs}/dix/DIXModule.module.d.ts.map +0 -0
  135. /package/{dist/libs → libs}/dix/DIXModule.module.js +0 -0
  136. /package/{dist/libs → libs}/player/DTPlayer.element.d.ts +0 -0
  137. /package/{dist/libs → libs}/player/DTPlayer.element.d.ts.map +0 -0
  138. /package/{dist/libs → libs}/player/DTPlayer.element.js +0 -0
  139. /package/{dist/libs → libs}/player/DTPlayer.element.js.map +0 -0
  140. /package/{dist/libs → libs}/player/DTPlayer.manager.d.ts +0 -0
  141. /package/{dist/libs → libs}/player/DTPlayer.manager.d.ts.map +0 -0
  142. /package/{dist/libs → libs}/player/DTPlayer.manager.js +0 -0
  143. /package/{dist/libs → libs}/player/DTPlayer.manager.js.map +0 -0
  144. /package/{dist/tsconfig.dev.tsbuildinfo → tsconfig.dev.tsbuildinfo} +0 -0
  145. /package/{dist/tsconfig.tsbuildinfo → tsconfig.tsbuildinfo} +0 -0
  146. /package/{dist/types → types}/core.d.ts +0 -0
  147. /package/{dist/types → types}/core.d.ts.map +0 -0
  148. /package/{dist/types → types}/core.js +0 -0
  149. /package/{dist/types → types}/core.js.map +0 -0
  150. /package/{dist/types → types}/index.d.ts +0 -0
  151. /package/{dist/types → types}/index.d.ts.map +0 -0
  152. /package/{dist/types → types}/index.js +0 -0
  153. /package/{dist/types → types}/index.js.map +0 -0
  154. /package/{dist/types → types}/player.d.ts +0 -0
  155. /package/{dist/types → types}/player.d.ts.map +0 -0
  156. /package/{dist/types → types}/player.js +0 -0
  157. /package/{dist/types → types}/player.js.map +0 -0
@@ -1,366 +0,0 @@
1
- import DTComponent from './DTComponent';
2
- import DTError from './DTError';
3
- import DTManager from './DTManager';
4
- import DTAction from './DTAction';
5
- import DTModule from './DTModule';
6
- import { DIXObject, DTComponentOptions, DTMasterToObject } from '../types';
7
- import DTDIXModule from '../libs/dix/DIXModule.module';
8
-
9
- export default class DTMaster extends DTComponent {
10
- /**
11
- * Defining component type to "master".
12
- */
13
- protected _componentType: string = 'master';
14
-
15
- /**
16
- * DTManager instances handled by the Master.
17
- *
18
- * The property is an object with _id value of the Manager instance as key, and Manager instance as value.
19
- * @protected
20
- */
21
- protected _managers: Record<string, DTManager>;
22
-
23
- /**
24
- * DTAction instances handled by the Master.
25
- *
26
- * The property is an object with _id value of the Action instance as key, and Action instance as value.
27
- * @protected
28
- */
29
- protected _actions: Record<string, DTAction>;
30
-
31
- /**
32
- * DTModule instance handled by the Master.
33
- *
34
- * The property is an object with _id value of the Module instance as key, and Module instance as value.
35
- * @protected
36
- */
37
- protected _modules: Record<string, DTModule>;
38
-
39
- /**
40
- * Applying the parent constructor, and initializing all properties to empty object.
41
- *
42
- * @param key
43
- * @param options
44
- */
45
- constructor(key?: string, options: Partial<DTComponentOptions> = {}) {
46
- super(key, options);
47
-
48
- this._managers = {};
49
- this._actions = {};
50
- this._modules = {};
51
- }
52
-
53
- /**
54
- * Add a DTManager **item** into _managers property.
55
- *
56
- * The adding process has the following specifications :
57
- * * If the added manager has the same _id than existing manager, an error occurred (depending on **errors** option).
58
- * * If the added manager has the same _key than existing manager, an error occurred (depending on **errors** option).
59
- * * The Master instance becomes the new context of the added item.
60
- *
61
- * @param manager DYOToolsManager instance to add.
62
- */
63
- addManager(manager: DTManager): void {
64
- // Id conflict
65
- if (Object.keys(this._managers).includes(manager.getId())) {
66
- this.triggerError(new DTError(
67
- 'id_conflict',
68
- 'Manager with same id already exists in the Master instance',
69
- this,
70
- manager,
71
- ));
72
- return;
73
- }
74
-
75
- // Key conflict
76
- if (Object.values(this._managers).find((m) => m.getKey() === manager.getKey())) {
77
- this.triggerError(new DTError(
78
- 'key_conflict',
79
- 'Manager with same key already exists in the Master instance',
80
- this,
81
- manager,
82
- ));
83
- return;
84
- }
85
-
86
- this._managers[manager.getId()] = manager;
87
- manager.setContext<DTMaster>(this);
88
- }
89
-
90
- /**
91
- * Return one DTManager instance handled by the Master.
92
- * It could be selected by _id or _key property of the Manager.
93
- *
94
- * @param idOrKey String id or key to select.
95
- * @returns DYOToolsManager selected Manager instance, or undefined if not found.
96
- */
97
- getManager(idOrKey: string): DTManager | undefined {
98
- let managerFound = this._managers[idOrKey];
99
-
100
- if (!managerFound) {
101
- managerFound = Object.values(this._managers).find((m) => m.getKey() === idOrKey);
102
- }
103
-
104
- return managerFound;
105
- }
106
-
107
- /**
108
- * Remove a handled Manager from the Master instance.
109
- *
110
- * @param idOrKey String id or key to select.
111
- */
112
- removeManager(idOrKey: string): void {
113
- const manager = this.getManager(idOrKey);
114
-
115
- if (manager) {
116
- delete this._managers[manager.getId()];
117
- }
118
- }
119
-
120
- /**
121
- * Add a DTAction **item** into _actions property.
122
- *
123
- * The adding process has the following specifications :
124
- * * If the added action has the same _id than existing action, an error occurred (depending on **errors** option).
125
- * * If the added action has the same _key than existing action, an error occurred (depending on **errors** option).
126
- * * The Master instance becomes the new context of the added item.
127
- *
128
- * @param action DYOToolsAction instance to add.
129
- */
130
- addAction(action: DTAction): void {
131
- // Id conflict
132
- if (Object.keys(this._actions).includes(action.getId())) {
133
- this.triggerError(new DTError(
134
- 'id_conflict',
135
- 'Action with same id already exists in the Master instance',
136
- this,
137
- action,
138
- ));
139
- return;
140
- }
141
-
142
- // Key conflict
143
- if (Object.values(this._actions).find((m) => m.getKey() === action.getKey())) {
144
- this.triggerError(new DTError(
145
- 'key_conflict',
146
- 'Action with same key already exists in the Master instance',
147
- this,
148
- action,
149
- ));
150
- return;
151
- }
152
-
153
- this._actions[action.getId()] = action;
154
- action.setContext<DTMaster>(this);
155
- }
156
-
157
- /**
158
- * Return one DTAction instance handled by the Master.
159
- * It could be selected by _id or _key property of the Action.
160
- *
161
- * @param idOrKey String id or key to select.
162
- * @returns DYOToolsAction selected Action instance, or undefined if not found.
163
- */
164
- getAction(idOrKey: string): DTAction | undefined {
165
- let actionFound = this._actions[idOrKey];
166
-
167
- if (!actionFound) {
168
- actionFound = Object.values(this._actions).find((a) => a.getKey() === idOrKey);
169
- }
170
-
171
- return actionFound;
172
- }
173
-
174
- /**
175
- * Remove a handled Action from the Master instance.
176
- *
177
- * @param idOrKey String id or key to select.
178
- */
179
- removeAction(idOrKey: string): void {
180
- const action = this.getAction(idOrKey);
181
-
182
- if (action) {
183
- delete this._actions[action.getId()];
184
- }
185
- }
186
-
187
- /**
188
- * Trigger the **execute** process of an action handled by the Master instance.
189
- * It could be selected by _id or _key property of the Action.
190
- *
191
- * @param idOrKey String id or key to select.
192
- * @param payload Object payload for the action execution.
193
- * @returns Promise action execution.
194
- */
195
- async executeAction(idOrKey: string, payload: unknown): Promise<void> {
196
- const action = this.getAction(idOrKey);
197
-
198
- if (action) {
199
- await this.getAction(idOrKey).execute(payload);
200
- }
201
- }
202
-
203
- /**
204
- * Add a DTModule **item** into _modules property.
205
- *
206
- * The adding process has the following specifications :
207
- * * If the added module has the same _id than existing module, an error occurred (depending on **errors** option).
208
- * * If the added module has the same _key than existing module, an error occurred (depending on **errors** option).
209
- * * The Master instance becomes the new context of the added item.
210
- *
211
- * @param module DYOToolsModule instance to add.
212
- */
213
- addModule(module: DTModule): void {
214
- // Id conflict
215
- if (Object.keys(this._modules).includes(module.getId())) {
216
- this.triggerError(new DTError(
217
- 'id_conflict',
218
- 'Module with same id already exists in the Master instance',
219
- this,
220
- module,
221
- ));
222
- return;
223
- }
224
-
225
- // Key conflict
226
- if (Object.values(this._modules).find((m) => m.getKey() === module.getKey())) {
227
- this.triggerError(new DTError(
228
- 'key_conflict',
229
- 'Module with same key already exists in the Master instance',
230
- this,
231
- module,
232
- ));
233
- return;
234
- }
235
-
236
- this._modules[module.getId()] = module;
237
- module.setContext<DTMaster>(this);
238
- }
239
-
240
- /**
241
- * Return one DTModule instance handled by the Master.
242
- * It could be selected by _id or _key property of the Module.
243
- *
244
- * @param idOrKey String id or key to select.
245
- * @returns DYOToolsModule selected Module instance, or undefined if not found.
246
- */
247
- getModule(idOrKey: string): DTModule | undefined {
248
- let moduleFound = this._modules[idOrKey];
249
-
250
- if (!moduleFound) {
251
- moduleFound = Object.values(this._modules).find((m) => m.getKey() === idOrKey);
252
- }
253
-
254
- return moduleFound;
255
- }
256
-
257
- /**
258
- * Remove a handled Module from the Master instance.
259
- *
260
- * @param idOrKey String id or key to select.
261
- */
262
- removeModule(idOrKey: string): void {
263
- const module = this.getModule(idOrKey);
264
-
265
- if (module) {
266
- delete this._modules[module.getId()];
267
- }
268
- }
269
-
270
- /**
271
- * Return String representation of the Master instance.
272
- *
273
- * @returns String representation of the Master.
274
- */
275
- toString(): string {
276
- const managersLabel = `Managers: ${Object.keys(this._managers).length}`;
277
- const actionsLabel = `Actions: ${Object.keys(this._actions).length}`;
278
- const modulesLabel = `Modules: ${Object.keys(this._modules).length}`;
279
-
280
- return `Component ${this._key} - Type: Master - ${managersLabel} - ${actionsLabel} - ${modulesLabel}`;
281
- }
282
-
283
- /**
284
- * Return JSON Object representation of the Master instance.
285
- *
286
- * JSON Object returned has the following structure :
287
- * * **id** : _id property of the Master.
288
- * * **key** : _key property of the Master.
289
- * * **type** : _componentType property of the Master.
290
- * * **managers** : Array of JSON Object representation for each DTManager instance in _managers property of the Master.
291
- * * **actions** : Array of JSON Object representation for each DTAction instance in _actions property of the Master.
292
- * * **modules** : Array of JSON Object representation for each DTModule instance in _modules property of the Master.
293
- *
294
- * @returns JSON Object representation of the Master.
295
- */
296
- toObject(): DTMasterToObject {
297
- const toObject: DTMasterToObject = {
298
- id: this._id,
299
- key: this._key,
300
- type: this._componentType,
301
- managers: [],
302
- actions: [],
303
- modules: [],
304
- };
305
-
306
- if (Object.keys(this._managers).length) {
307
- toObject.managers = Object.values(this._managers).map((obj) => obj.toObject());
308
- }
309
-
310
- if (Object.keys(this._actions).length) {
311
- toObject.actions = Object.values(this._actions).map((obj) => obj.toObject());
312
- }
313
-
314
- if (Object.keys(this._modules).length) {
315
- toObject.modules = Object.values(this._modules).map((obj) => obj.toObject());
316
- }
317
-
318
- return toObject;
319
- }
320
-
321
- /**
322
- * Return DIX Object representation of the DTManager instance.
323
- *
324
- * @returns DIX Object representation of the DTManager.
325
- */
326
- toDIXObject(): Record<string, DIXObject> {
327
- const parentDixObject = super.toDIXObject();
328
- const dixObject: DIXObject = {
329
- ...parentDixObject[this._id],
330
- items: Object.keys(this._managers),
331
- };
332
-
333
- const finalDix = {
334
- [this._id]: dixObject,
335
- };
336
- Object.values(this._managers).forEach((item) => {
337
- Object.assign(finalDix, {
338
- ...item.toDIXObject(),
339
- });
340
- });
341
-
342
- return finalDix;
343
- }
344
-
345
- /**
346
- * Update the DTMaster instance with a DIX Object.
347
- *
348
- * @param dix DIX Object to use for updating.
349
- */
350
- updateFromDix(dix: Record<string, DIXObject>): void {
351
- const dixObject = dix[this._id];
352
- const dixModule = this.getModule('dix') as DTDIXModule;
353
- if (dixObject && dixObject.items && dixModule?.isEnabled()) {
354
- // Synchronize Managers
355
- dixObject.items.forEach((itemId) => {
356
- if (this.getManager(itemId)) {
357
- this.getManager(itemId).updateFromDix(dix);
358
- } else {
359
- const newManager = dixModule.syncNewItem(itemId, dix) as DTManager;
360
- this.addManager(newManager);
361
- newManager.updateFromDix(dix);
362
- }
363
- });
364
- }
365
- }
366
- }
@@ -1,96 +0,0 @@
1
- import DTComponent from './DTComponent';
2
- import { DIXObject, DTModuleToObject } from '../types';
3
- import DTMaster from './DTMaster';
4
-
5
- export default class DTModule extends DTComponent {
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(): DTMaster | undefined {
32
- return this.getContext<DTMaster>('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
-
91
- toDIXObject(): Record<string, DIXObject> {
92
- return undefined;
93
- }
94
-
95
- updateFromDix(): void {}
96
- }
package/src/index.ts DELETED
@@ -1,17 +0,0 @@
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';
@@ -1,175 +0,0 @@
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
- }