dyo-tools 0.3.2 → 0.4.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 -4
- package/.eslintignore +1 -1
- package/.eslintrc.json +47 -47
- package/Makefile +34 -34
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +24 -20
- package/dist/constants.js.map +1 -1
- package/dist/core/DTAction.d.ts +6 -4
- package/dist/core/DTAction.d.ts.map +1 -0
- package/dist/core/DTAction.js +3 -6
- package/dist/core/DTAction.js.map +1 -1
- package/dist/core/DTBunch.d.ts +8 -5
- package/dist/core/DTBunch.d.ts.map +1 -0
- package/dist/core/DTBunch.js +53 -19
- package/dist/core/DTBunch.js.map +1 -1
- package/dist/core/DTComponent.d.ts +13 -10
- package/dist/core/DTComponent.d.ts.map +1 -0
- package/dist/core/DTComponent.js +23 -10
- package/dist/core/DTComponent.js.map +1 -1
- package/dist/core/DTComponentPhysical.d.ts +11 -8
- package/dist/core/DTComponentPhysical.d.ts.map +1 -0
- package/dist/core/DTComponentPhysical.js +21 -6
- package/dist/core/DTComponentPhysical.js.map +1 -1
- package/dist/core/DTComponentWithMeta.d.ts +6 -3
- package/dist/core/DTComponentWithMeta.d.ts.map +1 -0
- package/dist/core/DTComponentWithMeta.js +21 -7
- package/dist/core/DTComponentWithMeta.js.map +1 -1
- package/dist/core/DTElement.d.ts +10 -8
- package/dist/core/DTElement.d.ts.map +1 -0
- package/dist/core/DTElement.js +8 -9
- package/dist/core/DTElement.js.map +1 -1
- package/dist/core/DTError.d.ts +8 -7
- package/dist/core/DTError.d.ts.map +1 -0
- package/dist/core/DTError.js +1 -5
- package/dist/core/DTError.js.map +1 -1
- package/dist/core/DTManager.d.ts +17 -14
- package/dist/core/DTManager.d.ts.map +1 -0
- package/dist/core/DTManager.js +84 -26
- package/dist/core/DTManager.js.map +1 -1
- package/dist/core/DTMaster.d.ts +19 -16
- package/dist/core/DTMaster.d.ts.map +1 -0
- package/dist/core/DTMaster.js +48 -31
- package/dist/core/DTMaster.js.map +1 -1
- package/dist/core/DTModule.d.ts +8 -5
- package/dist/core/DTModule.d.ts.map +1 -0
- package/dist/core/DTModule.js +6 -6
- package/dist/core/DTModule.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -28
- package/dist/index.js.map +1 -1
- package/dist/libs/DYOFinder.d.ts +1 -0
- package/dist/libs/DYOFinder.d.ts.map +1 -0
- package/dist/libs/DYOFinder.js +10 -14
- package/dist/libs/DYOFinder.js.map +1 -1
- package/dist/libs/dix/DIXModule.module.d.ts +8 -0
- package/dist/libs/dix/DIXModule.module.d.ts.map +1 -0
- package/dist/libs/dix/DIXModule.module.js +73 -0
- package/dist/libs/player/DTPlayer.element.d.ts +3 -2
- package/dist/libs/player/DTPlayer.element.d.ts.map +1 -0
- package/dist/libs/player/DTPlayer.element.js +2 -6
- package/dist/libs/player/DTPlayer.element.js.map +1 -1
- package/dist/libs/player/DTPlayer.manager.d.ts +8 -7
- package/dist/libs/player/DTPlayer.manager.d.ts.map +1 -0
- package/dist/libs/player/DTPlayer.manager.js +13 -20
- package/dist/libs/player/DTPlayer.manager.js.map +1 -1
- package/dist/tsconfig.dev.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/core.d.ts +40 -12
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +2 -6
- package/dist/types/core.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -19
- package/dist/types/index.js.map +1 -1
- package/dist/types/player.d.ts +1 -1
- package/dist/types/player.d.ts.map +1 -0
- package/dist/types/player.js +1 -3
- package/integration/data/components/DTHero.ts +42 -0
- package/integration/data/components/DTHeroManager.ts +11 -0
- package/integration/data/components/DTHeroPlayZone.ts +6 -0
- package/integration/data/components/DTHeroPlayerHand.ts +11 -0
- package/integration/data/components/index.ts +5 -0
- package/integration/data/in/heroIn.helper.ts +8 -0
- package/integration/data/in/playerIn.helper.ts +13 -0
- package/integration/data/out/heroOut.helper.ts +48 -0
- package/integration/endings/synchronisation.ending.ts +25 -0
- package/integration/scenes/drawCard.scene.ts +31 -0
- package/integration/scenes/empty.scene.ts +6 -0
- package/integration/scenes/playCard.scene.ts +23 -0
- package/integration/scenes/playerLeave.scene.ts +33 -0
- package/integration/stages/baseDix.stage.ts +137 -0
- package/integration/stages/syncDix.stage.ts +36 -0
- package/integration/tests/scenario1.spec.ts +55 -0
- package/integration/types/index.ts +24 -0
- package/jest-integration.config.ts +25 -0
- package/jest.config.ts +26 -0
- package/package.json +31 -19
- package/src/constants.ts +2 -0
- package/src/core/DTAction.ts +7 -5
- package/src/core/DTBunch.ts +78 -14
- package/src/core/DTComponent.ts +48 -15
- package/src/core/DTComponentPhysical.ts +45 -11
- package/src/core/DTComponentWithMeta.ts +37 -4
- package/src/core/DTElement.ts +19 -10
- package/src/core/DTError.ts +7 -7
- package/src/core/DTManager.ts +120 -30
- package/src/core/DTMaster.ts +76 -28
- package/src/core/DTModule.ts +12 -6
- package/src/index.ts +17 -17
- package/src/libs/DYOFinder.ts +175 -175
- package/src/libs/dix/DIXModule.module.ts +98 -0
- package/src/libs/player/DTPlayer.element.ts +2 -2
- package/src/libs/player/DTPlayer.manager.ts +20 -34
- package/src/types/core.ts +39 -4
- package/src/types/index.ts +2 -2
- package/src/types/player.ts +0 -1
- package/test/core/DTAction.double.ts +12 -28
- package/test/core/DTAction.spec.ts +8 -16
- package/test/core/DTBunch.double.ts +49 -135
- package/test/core/DTBunch.spec.ts +157 -245
- package/test/core/DTComponent.double.ts +17 -2
- package/test/core/DTComponent.spec.ts +6 -4
- package/test/core/DTComponentPhysical.double.ts +29 -43
- package/test/core/DTComponentPhysical.spec.ts +22 -19
- package/test/core/DTComponentWithMeta.double.ts +38 -31
- package/test/core/DTComponentWithMeta.spec.ts +23 -18
- package/test/core/DTElement.double.ts +32 -53
- package/test/core/DTElement.spec.ts +15 -38
- package/test/core/DTError.double.ts +18 -53
- package/test/core/DTError.spec.ts +21 -32
- package/test/core/DTManager.double.ts +74 -141
- package/test/core/DTManager.spec.ts +289 -380
- package/test/core/DTMaster.double.ts +56 -80
- package/test/core/DTMaster.spec.ts +185 -232
- package/test/core/DTModule.double.ts +12 -25
- package/test/core/DTModule.spec.ts +14 -28
- package/test/core/copy.spec.ts +9 -30
- package/tsconfig.dev.json +5 -8
- package/tsconfig.json +5 -8
- package/cucumber-report.html +0 -48
- package/docs/assets/navigation.js +0 -1
- package/docs/classes/core_DTAction.DYOToolsAction.html +0 -89
- package/docs/classes/core_DTBunch.DYOToolsBunch.html +0 -254
- package/docs/classes/core_DTComponent.DYOToolsComponent.html +0 -76
- package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +0 -110
- package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +0 -96
- package/docs/classes/core_DTElement.DYOToolsElement.html +0 -135
- package/docs/classes/core_DTError.DYOToolsError.html +0 -37
- package/docs/classes/core_DTManager.DYOToolsManager.html +0 -237
- package/docs/classes/core_DTMaster.DYOToolsMaster.html +0 -150
- package/docs/classes/core_DTModule.DYOToolsModule.html +0 -92
- package/docs/classes/libs_DYOFinder.DYOFinder.html +0 -34
- package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +0 -134
- package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +0 -243
- package/docs/enums/types_core.FilterOperatorType.html +0 -10
- package/docs/hierarchy.html +0 -1
- package/docs/interfaces/types_core.DTBunchFilters.html +0 -6
- package/docs/interfaces/types_core.DTBunchOptions.html +0 -19
- package/docs/interfaces/types_core.DTBunchToObject.html +0 -7
- package/docs/interfaces/types_core.DTComponentOptions.html +0 -5
- package/docs/interfaces/types_core.DTComponentToObject.html +0 -4
- package/docs/interfaces/types_core.DTElementToObject.html +0 -7
- package/docs/interfaces/types_core.DTManagerFilters.html +0 -6
- package/docs/interfaces/types_core.DTManagerOptions.html +0 -8
- package/docs/interfaces/types_core.DTManagerToObject.html +0 -5
- package/docs/interfaces/types_core.DTMasterToObject.html +0 -8
- package/docs/interfaces/types_core.DTModuleToObject.html +0 -6
- package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +0 -4
- package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +0 -4
- package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +0 -5
- package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +0 -5
- package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +0 -3
- package/docs/modules/constants.html +0 -6
- package/docs/modules/core_DTAction.html +0 -2
- package/docs/modules/core_DTBunch.html +0 -2
- package/docs/modules/core_DTComponent.html +0 -2
- package/docs/modules/core_DTComponentPhysical.html +0 -2
- package/docs/modules/core_DTComponentWithMeta.html +0 -2
- package/docs/modules/core_DTElement.html +0 -2
- package/docs/modules/core_DTError.html +0 -2
- package/docs/modules/core_DTManager.html +0 -2
- package/docs/modules/core_DTMaster.html +0 -2
- package/docs/modules/core_DTModule.html +0 -2
- package/docs/modules/libs_DYOFinder.html +0 -2
- package/docs/modules/libs_player_DTPlayer_element.html +0 -2
- package/docs/modules/libs_player_DTPlayer_manager.html +0 -2
- package/docs/modules/types.html +0 -29
- package/docs/modules/types_core.html +0 -28
- package/docs/modules/types_player.html +0 -2
- package/docs/types/types_core.DTAcceptedMetaData.html +0 -2
- package/docs/types/types_core.DTManagerItemType.html +0 -1
- package/docs/types/types_core.DTManagerItemsType.html +0 -2
- package/docs/types/types_core.DYOFinderComponentType.html +0 -1
- package/docs/types/types_core.DYOFinderConfiguration.html +0 -2
- package/docs/types/types_core.DYOFinderConfigurationProp.html +0 -1
- package/docs/types/types_core.DYOFinderFilterOperator.html +0 -1
- package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +0 -1
- package/docs/types/types_core.DYOFinderFilters.html +0 -1
- package/docs/types/types_core.StandardPrimitiveType.html +0 -2
- package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +0 -1
- package/docs/variables/constants.bunchDefaultOptions.html +0 -2
- package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +0 -1
- package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +0 -1
- package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +0 -1
- package/docs/variables/constants.managerDefaultOptions.html +0 -2
- package/jest.config.js +0 -6
package/src/libs/DYOFinder.ts
CHANGED
|
@@ -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,98 @@
|
|
|
1
|
+
import * as CoreComponents from '../../index';
|
|
2
|
+
import { DIXObject } from '../../types';
|
|
3
|
+
|
|
4
|
+
type DTElementClass = new (key: string, options: Record<string, unknown>) => CoreComponents.DTComponent;
|
|
5
|
+
type DTBunchClass = new (key: string, items: unknown[], options: Record<string, unknown>) => CoreComponents.DTComponent;
|
|
6
|
+
type DTManagerClass = new (key: string, items: unknown[], scopes: unknown[], options: Record<string, unknown>) => CoreComponents.DTComponent;
|
|
7
|
+
type DTMasterClass = DTElementClass;
|
|
8
|
+
|
|
9
|
+
export default class DTDIXModule extends CoreComponents.DTModule {
|
|
10
|
+
overrides: Record<string, unknown>;
|
|
11
|
+
|
|
12
|
+
constructor(overrides: Record<string, unknown> = {}) {
|
|
13
|
+
super('dix');
|
|
14
|
+
this.overrides = {
|
|
15
|
+
...CoreComponents,
|
|
16
|
+
...overrides,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
syncNewItem(id: string, dix: Record<string, DIXObject>): CoreComponents.DTComponent | undefined {
|
|
21
|
+
const dixObject = dix[id];
|
|
22
|
+
let instance: CoreComponents.DTComponent | undefined;
|
|
23
|
+
const errorsEnabled = this._options.errors;
|
|
24
|
+
|
|
25
|
+
if (dixObject) {
|
|
26
|
+
switch (dixObject.componentType) {
|
|
27
|
+
case 'bunch':
|
|
28
|
+
try {
|
|
29
|
+
const UseClass = this.overrides[dixObject.useClass] as DTBunchClass;
|
|
30
|
+
instance = new UseClass(dixObject.key, [], { ...(JSON.parse(dixObject.options) ?? {}), syncId: id });
|
|
31
|
+
} catch (err: unknown) {
|
|
32
|
+
if (errorsEnabled) {
|
|
33
|
+
const UseClass = this.overrides.DTBunch as DTBunchClass;
|
|
34
|
+
instance = new UseClass(dixObject.key, [], { ...(JSON.parse(dixObject.options) ?? {}), syncId: id });
|
|
35
|
+
}
|
|
36
|
+
this.triggerError(new CoreComponents.DTError(
|
|
37
|
+
'dix_module_instance_error',
|
|
38
|
+
`Bunch Class ${dixObject.useClass} doesn't exist in DIX Module`,
|
|
39
|
+
this,
|
|
40
|
+
));
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
case 'manager':
|
|
44
|
+
try {
|
|
45
|
+
const UseClass = this.overrides[dixObject.useClass] as DTManagerClass;
|
|
46
|
+
instance = new UseClass(dixObject.key, [], [], { ...(JSON.parse(dixObject.options) ?? {}), syncId: id });
|
|
47
|
+
} catch (err: unknown) {
|
|
48
|
+
if (errorsEnabled) {
|
|
49
|
+
const UseClass = this.overrides.DTManager as DTManagerClass;
|
|
50
|
+
instance = new UseClass(dixObject.key, [], [], { ...(JSON.parse(dixObject.options) ?? {}), syncId: id });
|
|
51
|
+
}
|
|
52
|
+
this.triggerError(new CoreComponents.DTError(
|
|
53
|
+
'dix_module_instance_error',
|
|
54
|
+
`Manager Class ${dixObject.useClass} doesn't exist in DIX Module`,
|
|
55
|
+
this,
|
|
56
|
+
));
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
case 'master':
|
|
60
|
+
try {
|
|
61
|
+
const UseClass = this.overrides[dixObject.useClass] as DTMasterClass;
|
|
62
|
+
instance = new UseClass(dixObject.key, { ...(JSON.parse(dixObject.options) ?? {}), syncId: id });
|
|
63
|
+
} catch (err: unknown) {
|
|
64
|
+
if (errorsEnabled) {
|
|
65
|
+
const UseClass = this.overrides.DTElement as DTMasterClass;
|
|
66
|
+
instance = new UseClass(dixObject.key, { ...(JSON.parse(dixObject.options) ?? {}), syncId: id });
|
|
67
|
+
}
|
|
68
|
+
this.triggerError(new CoreComponents.DTError(
|
|
69
|
+
'dix_module_instance_error',
|
|
70
|
+
`Master Class ${dixObject.useClass} doesn't exist in DIX Module`,
|
|
71
|
+
this,
|
|
72
|
+
));
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
case 'element':
|
|
76
|
+
default:
|
|
77
|
+
try {
|
|
78
|
+
const UseClass = this.overrides[dixObject.useClass] as DTElementClass;
|
|
79
|
+
instance = new UseClass(dixObject.key, { ...(JSON.parse(dixObject.options) ?? {}), syncId: id });
|
|
80
|
+
// console.log('Je test pour : ', instance.getKey(), instance.getId(), instance.getOptions(), id);
|
|
81
|
+
} catch (err: unknown) {
|
|
82
|
+
if (errorsEnabled) {
|
|
83
|
+
const UseClass = this.overrides.DTElement as DTElementClass;
|
|
84
|
+
instance = new UseClass(dixObject.key, { ...(JSON.parse(dixObject.options) ?? {}), syncId: id });
|
|
85
|
+
}
|
|
86
|
+
this.triggerError(new CoreComponents.DTError(
|
|
87
|
+
'dix_module_instance_error',
|
|
88
|
+
`Element Class ${dixObject.useClass} doesn't exist in DIX Module`,
|
|
89
|
+
this,
|
|
90
|
+
));
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return instance;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DTAcceptedMetaData } from '../../types';
|
|
2
|
-
import
|
|
2
|
+
import DTElement from '../../core/DTElement';
|
|
3
3
|
|
|
4
|
-
export default class
|
|
4
|
+
export default class DTPlayer<IComponentMeta extends DTAcceptedMetaData = DTAcceptedMetaData> extends DTElement<IComponentMeta> {
|
|
5
5
|
/**
|
|
6
6
|
* Defining component domain to "player".
|
|
7
7
|
*/
|
|
@@ -1,48 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { DTBunchFilters,
|
|
4
|
-
import { DTPlayer } from '../../index';
|
|
1
|
+
import DTManager from '../../core/DTManager';
|
|
2
|
+
import DTPlayer from './DTPlayer.element';
|
|
3
|
+
import { DTBunchFilters, DTPlayerManagerSimpleConfiguration } from '../../types';
|
|
5
4
|
|
|
6
|
-
export default class
|
|
5
|
+
export default class DTPlayerManager extends DTManager<DTPlayer> {
|
|
7
6
|
/**
|
|
8
7
|
* Defining component domain to "player".
|
|
9
8
|
*/
|
|
10
9
|
protected _domain = 'player';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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) {
|
|
12
|
+
* Simply configure the manager with a configuration JSON Object
|
|
13
|
+
* **players** : Default player configuration.
|
|
14
|
+
* If **players** is a number, it generates this number of DTPlayer instances and add it to the library.
|
|
15
|
+
* If **players** is an array of DTPlayer instances, it adds these to the library.
|
|
16
|
+
*
|
|
17
|
+
* @param configuration DTPlayerManagerSimpleConfiguration Optional configuration to apply.
|
|
18
|
+
*/
|
|
19
|
+
configure(configuration: DTPlayerManagerSimpleConfiguration) {
|
|
20
|
+
if (configuration.players) {
|
|
21
|
+
if (typeof configuration.players === 'number' && configuration.players > 0) {
|
|
32
22
|
let i = 1;
|
|
33
|
-
while (i <=
|
|
23
|
+
while (i <= configuration.players) {
|
|
34
24
|
const player = new DTPlayer(`player${i}`);
|
|
35
25
|
this._library.add(player);
|
|
36
26
|
i += 1;
|
|
37
27
|
}
|
|
38
|
-
} else if (Array.isArray(
|
|
39
|
-
this._library.addMany(
|
|
28
|
+
} else if (Array.isArray(configuration.players)) {
|
|
29
|
+
this._library.addMany(configuration.players);
|
|
40
30
|
}
|
|
41
31
|
}
|
|
42
|
-
|
|
43
|
-
if (finalConfig.errors) {
|
|
44
|
-
finalOptions.errors = finalConfig.errors;
|
|
45
|
-
}
|
|
46
32
|
}
|
|
47
33
|
|
|
48
34
|
/**
|
|
@@ -50,7 +36,7 @@ export default class DYOToolsPlayerManager extends DYOToolsManager<DYOToolsPlaye
|
|
|
50
36
|
*
|
|
51
37
|
* @param id string _id property of the DTPlayer instance to get.
|
|
52
38
|
*/
|
|
53
|
-
getPlayer(id: string):
|
|
39
|
+
getPlayer(id: string): DTPlayer {
|
|
54
40
|
return this._library.get(id);
|
|
55
41
|
}
|
|
56
42
|
|
|
@@ -59,7 +45,7 @@ export default class DYOToolsPlayerManager extends DYOToolsManager<DYOToolsPlaye
|
|
|
59
45
|
*
|
|
60
46
|
* @param player DYOToolsPlayer instance to add.
|
|
61
47
|
*/
|
|
62
|
-
addPlayer(player:
|
|
48
|
+
addPlayer(player: DTPlayer): void {
|
|
63
49
|
this._library.add(player);
|
|
64
50
|
}
|
|
65
51
|
|
|
@@ -78,7 +64,7 @@ export default class DYOToolsPlayerManager extends DYOToolsManager<DYOToolsPlaye
|
|
|
78
64
|
* @see [find](#find) method for search specifications.
|
|
79
65
|
* @param filters DTBunchFilters filters to apply.
|
|
80
66
|
*/
|
|
81
|
-
findPlayers(filters: Partial<DTBunchFilters>):
|
|
67
|
+
findPlayers(filters: Partial<DTBunchFilters>): DTPlayer[] {
|
|
82
68
|
return this._library.find(filters);
|
|
83
69
|
}
|
|
84
70
|
}
|
package/src/types/core.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DTBunch, DTComponent } from '../index';
|
|
2
|
-
import
|
|
2
|
+
import DTElement from '../core/DTElement';
|
|
3
3
|
|
|
4
4
|
/** Constants Enum * */
|
|
5
5
|
export enum FilterOperatorType {
|
|
@@ -62,7 +62,12 @@ export interface DTComponentOptions {
|
|
|
62
62
|
* Default *false*. If *true*, no exception is thrown when an error occurred, a new DTError instance is
|
|
63
63
|
* added to the _errors property array instead. If *false*, throw the exception with a DTError instance.
|
|
64
64
|
*/
|
|
65
|
-
errors: boolean
|
|
65
|
+
errors: boolean,
|
|
66
|
+
/**
|
|
67
|
+
* Default undefined. If specified, the string argument passed will be the id of the new DTComponent.
|
|
68
|
+
* Used to synchronize ids between to instances (with the DIX Module). Be careful when using.
|
|
69
|
+
*/
|
|
70
|
+
syncId: string | undefined
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
export interface DTComponentToObject {
|
|
@@ -71,6 +76,15 @@ export interface DTComponentToObject {
|
|
|
71
76
|
type: string
|
|
72
77
|
}
|
|
73
78
|
|
|
79
|
+
export interface DTComponentToDIXObject {
|
|
80
|
+
key: string
|
|
81
|
+
componentType: string,
|
|
82
|
+
domain?: string
|
|
83
|
+
subKind?: string
|
|
84
|
+
meta?: string
|
|
85
|
+
owner?: string
|
|
86
|
+
}
|
|
87
|
+
|
|
74
88
|
/** DTComponentWithMeta interfaces * */
|
|
75
89
|
export type DTAcceptedMetaData = Record<
|
|
76
90
|
string,
|
|
@@ -126,9 +140,15 @@ export interface DTBunchFilters {
|
|
|
126
140
|
meta: Record<string, Partial<DYOFinderFilterOperatorBase & DYOFinderFilterOperatorAdvanced>>
|
|
127
141
|
}
|
|
128
142
|
|
|
143
|
+
export interface DTBunchToDIXObject extends DTComponentToDIXObject {
|
|
144
|
+
componentType: 'bunch'
|
|
145
|
+
items: string[]
|
|
146
|
+
scope?: string
|
|
147
|
+
}
|
|
148
|
+
|
|
129
149
|
/** DTManager interfaces * */
|
|
130
|
-
export type DTManagerItemsType<IBunchItem extends
|
|
131
|
-
export type DTManagerItemType<IBunchItem extends
|
|
150
|
+
export type DTManagerItemsType<IBunchItem extends DTElement<DTAcceptedMetaData>> = Record<string, DTManagerItemType<IBunchItem>>;
|
|
151
|
+
export type DTManagerItemType<IBunchItem extends DTElement<DTAcceptedMetaData>> = {
|
|
132
152
|
scope: string,
|
|
133
153
|
item: DTBunch<IBunchItem>,
|
|
134
154
|
};
|
|
@@ -167,3 +187,18 @@ export interface DTMasterToObject extends DTComponentToObject {
|
|
|
167
187
|
actions: Array<DTComponentToObject>,
|
|
168
188
|
modules: Array<DTModuleToObject>,
|
|
169
189
|
}
|
|
190
|
+
|
|
191
|
+
/** Final DIX Object typing * */
|
|
192
|
+
export interface DIXObject {
|
|
193
|
+
useClass: string,
|
|
194
|
+
key: string
|
|
195
|
+
componentType: string,
|
|
196
|
+
options: string
|
|
197
|
+
meta?: string
|
|
198
|
+
owner?: string
|
|
199
|
+
items?: string[]
|
|
200
|
+
library?: string
|
|
201
|
+
scope?: string,
|
|
202
|
+
scopes?: string[],
|
|
203
|
+
[key: string]: unknown,
|
|
204
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './core';
|
|
2
|
-
export * from './player';
|
|
1
|
+
export * from './core';
|
|
2
|
+
export * from './player';
|