dyo-tools 0.2.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.
Files changed (167) hide show
  1. package/dist/constants.js +4 -4
  2. package/dist/constants.js.map +1 -1
  3. package/dist/core/DTAction.d.ts +10 -0
  4. package/dist/core/DTAction.js +24 -0
  5. package/dist/core/DTAction.js.map +1 -0
  6. package/dist/core/DTBunch.d.ts +6 -7
  7. package/dist/core/DTBunch.js +16 -13
  8. package/dist/core/DTBunch.js.map +1 -1
  9. package/dist/core/DTComponentPhysical.d.ts +6 -4
  10. package/dist/core/DTComponentPhysical.js +6 -0
  11. package/dist/core/DTComponentPhysical.js.map +1 -1
  12. package/dist/core/DTElement.d.ts +5 -0
  13. package/dist/core/DTElement.js +12 -2
  14. package/dist/core/DTElement.js.map +1 -1
  15. package/dist/core/DTManager.d.ts +3 -1
  16. package/dist/core/DTManager.js +24 -14
  17. package/dist/core/DTManager.js.map +1 -1
  18. package/dist/core/DTMaster.d.ts +24 -0
  19. package/dist/core/DTMaster.js +133 -0
  20. package/dist/core/DTMaster.js.map +1 -0
  21. package/dist/core/DTModule.d.ts +14 -0
  22. package/dist/core/DTModule.js +39 -0
  23. package/dist/core/DTModule.js.map +1 -0
  24. package/dist/index.d.ts +5 -1
  25. package/dist/index.js +11 -3
  26. package/dist/index.js.map +1 -1
  27. package/dist/libs/player/DTPlayer.element.d.ts +5 -0
  28. package/dist/libs/player/DTPlayer.element.js +11 -0
  29. package/dist/libs/player/DTPlayer.element.js.map +1 -0
  30. package/dist/libs/player/DTPlayer.manager.d.ts +11 -0
  31. package/dist/libs/player/DTPlayer.manager.js +42 -0
  32. package/dist/libs/player/DTPlayer.manager.js.map +1 -0
  33. package/dist/tsconfig.tsbuildinfo +1 -1
  34. package/dist/types/core.d.ts +103 -0
  35. package/dist/types/core.js +15 -0
  36. package/dist/types/core.js.map +1 -0
  37. package/dist/types/index.d.ts +2 -98
  38. package/dist/types/index.js +16 -12
  39. package/dist/types/index.js.map +1 -1
  40. package/dist/types/player.d.ts +5 -0
  41. package/dist/types/player.js +3 -0
  42. package/dist/types/player.js.map +1 -0
  43. package/docs/assets/highlight.css +29 -29
  44. package/docs/assets/main.js +59 -58
  45. package/docs/assets/navigation.js +1 -0
  46. package/docs/assets/search.js +1 -1
  47. package/docs/assets/style.css +1414 -1367
  48. package/docs/classes/core_DTAction.DYOToolsAction.html +89 -0
  49. package/docs/classes/core_DTBunch.DYOToolsBunch.html +254 -0
  50. package/docs/classes/core_DTComponent.DYOToolsComponent.html +76 -0
  51. package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +110 -0
  52. package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +96 -0
  53. package/docs/classes/core_DTElement.DYOToolsElement.html +135 -0
  54. package/docs/classes/core_DTError.DYOToolsError.html +37 -0
  55. package/docs/classes/core_DTManager.DYOToolsManager.html +237 -0
  56. package/docs/classes/core_DTMaster.DYOToolsMaster.html +150 -0
  57. package/docs/classes/core_DTModule.DYOToolsModule.html +92 -0
  58. package/docs/classes/libs_DYOFinder.DYOFinder.html +34 -0
  59. package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +134 -0
  60. package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +243 -0
  61. package/docs/enums/types_core.FilterOperatorType.html +10 -0
  62. package/docs/hierarchy.html +1 -0
  63. package/docs/index.html +1 -46
  64. package/docs/interfaces/types_core.DTBunchFilters.html +6 -0
  65. package/docs/interfaces/types_core.DTBunchOptions.html +19 -0
  66. package/docs/interfaces/types_core.DTBunchToObject.html +7 -0
  67. package/docs/interfaces/types_core.DTComponentOptions.html +5 -0
  68. package/docs/interfaces/types_core.DTComponentToObject.html +4 -0
  69. package/docs/interfaces/types_core.DTElementToObject.html +7 -0
  70. package/docs/interfaces/types_core.DTManagerFilters.html +6 -0
  71. package/docs/interfaces/types_core.DTManagerOptions.html +8 -0
  72. package/docs/interfaces/types_core.DTManagerToObject.html +5 -0
  73. package/docs/interfaces/types_core.DTMasterToObject.html +8 -0
  74. package/docs/interfaces/types_core.DTModuleToObject.html +6 -0
  75. package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +4 -0
  76. package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +4 -0
  77. package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +5 -0
  78. package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +5 -0
  79. package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +3 -0
  80. package/docs/modules/constants.html +6 -0
  81. package/docs/modules/core_DTAction.html +2 -0
  82. package/docs/modules/core_DTBunch.html +2 -0
  83. package/docs/modules/core_DTComponent.html +2 -0
  84. package/docs/modules/core_DTComponentPhysical.html +2 -0
  85. package/docs/modules/core_DTComponentWithMeta.html +2 -0
  86. package/docs/modules/core_DTElement.html +2 -0
  87. package/docs/modules/core_DTError.html +2 -0
  88. package/docs/modules/core_DTManager.html +2 -0
  89. package/docs/modules/core_DTMaster.html +2 -0
  90. package/docs/modules/core_DTModule.html +2 -0
  91. package/docs/modules/libs_DYOFinder.html +2 -0
  92. package/docs/modules/libs_player_DTPlayer_element.html +2 -0
  93. package/docs/modules/libs_player_DTPlayer_manager.html +2 -0
  94. package/docs/modules/types.html +29 -0
  95. package/docs/modules/types_core.html +28 -0
  96. package/docs/modules/types_player.html +2 -0
  97. package/docs/types/types_core.DTAcceptedMetaData.html +2 -0
  98. package/docs/types/types_core.DTManagerItemType.html +1 -0
  99. package/docs/types/types_core.DTManagerItemsType.html +2 -0
  100. package/docs/types/types_core.DYOFinderComponentType.html +1 -0
  101. package/docs/types/types_core.DYOFinderConfiguration.html +2 -0
  102. package/docs/types/types_core.DYOFinderConfigurationProp.html +1 -0
  103. package/docs/types/types_core.DYOFinderFilterOperator.html +1 -0
  104. package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +1 -0
  105. package/docs/types/types_core.DYOFinderFilters.html +1 -0
  106. package/docs/types/types_core.StandardPrimitiveType.html +2 -0
  107. package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +1 -0
  108. package/docs/variables/constants.bunchDefaultOptions.html +2 -0
  109. package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +1 -0
  110. package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +1 -0
  111. package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +1 -0
  112. package/docs/variables/constants.managerDefaultOptions.html +2 -0
  113. package/package.json +16 -17
  114. package/src/constants.ts +85 -85
  115. package/src/core/DTAction.ts +52 -0
  116. package/src/core/DTBunch.ts +467 -461
  117. package/src/core/DTComponent.ts +225 -225
  118. package/src/core/DTComponentPhysical.ts +53 -39
  119. package/src/core/DTComponentWithMeta.ts +65 -65
  120. package/src/core/DTElement.ts +102 -69
  121. package/src/core/DTError.ts +78 -78
  122. package/src/core/DTManager.ts +465 -446
  123. package/src/core/DTMaster.ts +318 -0
  124. package/src/core/DTModule.ts +90 -0
  125. package/src/index.ts +17 -9
  126. package/src/libs/DYOFinder.ts +175 -175
  127. package/src/libs/player/DTPlayer.element.ts +9 -0
  128. package/src/libs/player/DTPlayer.manager.ts +84 -0
  129. package/src/types/core.ts +169 -0
  130. package/src/types/index.ts +2 -162
  131. package/src/types/player.ts +6 -0
  132. package/test/core/DTAction.double.ts +78 -0
  133. package/test/core/DTAction.spec.ts +76 -0
  134. package/test/core/DTBunch.double.ts +18 -10
  135. package/test/core/DTBunch.spec.ts +70 -68
  136. package/test/core/DTComponentPhysical.double.ts +3 -3
  137. package/test/core/DTComponentPhysical.spec.ts +25 -11
  138. package/test/core/DTElement.double.ts +21 -5
  139. package/test/core/DTElement.spec.ts +52 -8
  140. package/test/core/DTError.double.ts +1 -1
  141. package/test/core/DTManager.double.ts +29 -5
  142. package/test/core/DTManager.spec.ts +80 -17
  143. package/test/core/DTMaster.double.ts +141 -0
  144. package/test/core/DTMaster.spec.ts +584 -0
  145. package/test/core/DTModule.double.ts +80 -0
  146. package/test/core/DTModule.spec.ts +138 -0
  147. package/test/core/copy.spec.ts +20 -4
  148. package/test/{core/DTPlayer.double.ts → libs/player/DTPlayer.element.double.ts} +15 -24
  149. package/test/libs/player/DTPlayer.element.spec.ts +28 -0
  150. package/test/libs/player/DTPlayer.manager.double.ts +92 -0
  151. package/test/libs/player/DTPlayer.manager.spec.ts +178 -0
  152. package/LICENSE +0 -21
  153. package/cucumber.js +0 -9
  154. package/dist/core/DTPlayer.d.ts +0 -8
  155. package/dist/core/DTPlayer.js +0 -30
  156. package/dist/core/DTPlayer.js.map +0 -1
  157. package/e2e/0.2.0/epic1.feature +0 -29
  158. package/e2e/0.2.0/epic2.feature +0 -22
  159. package/e2e/0.2.0/epic3.feature +0 -25
  160. package/e2e/0.2.0/resources/dominion.js +0 -195
  161. package/e2e/0.2.0/resources/utils.js +0 -27
  162. package/e2e/0.2.0/support/steps.js +0 -108
  163. package/e2e/future/epic4.feature +0 -39
  164. package/e2e/future/resources/dominion.js +0 -238
  165. package/e2e/future/resources/utils.js +0 -27
  166. package/src/core/DTPlayer.ts +0 -57
  167. package/test/core/DTPlayer.spec.ts +0 -80
@@ -1,175 +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
- }
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
+ }
@@ -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
+ }