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/package.json
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dyo-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/types/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
6
14
|
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.json",
|
|
7
16
|
"build:prod": "tsc -p tsconfig.json",
|
|
8
17
|
"build:dev": "tsc -p tsconfig.dev.json",
|
|
9
18
|
"start": "node dist/index.js",
|
|
10
19
|
"lint": "eslint src/ --ext .ts",
|
|
11
20
|
"lint:fix": "eslint src/ --ext .ts --fix",
|
|
12
21
|
"typecheck": "tsc --noEmit -p tsconfig.dev.json",
|
|
13
|
-
"test": "jest",
|
|
14
|
-
"test:
|
|
15
|
-
"test:coverage:
|
|
22
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config=jest.config.ts",
|
|
23
|
+
"test:integration": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config=jest-integration.config.ts",
|
|
24
|
+
"test:coverage:unit": "c8 --temp-directory .coverage/v8 --reports-dir coverage/unit --clean npm run test",
|
|
25
|
+
"test:coverage:integration": "c8 --temp-directory .coverage/v8 --reports-dir coverage/integration --no-clean npm run test:integration",
|
|
26
|
+
"test:coverage": "npm run test:coverage:unit && npm run test:coverage:integration && c8 report --temp-directory .coverage/v8 --reports-dir coverage --reporter=text --reporter=lcov --reporter=html",
|
|
16
27
|
"typedoc": "typedoc --plugin typedoc-plugin-rename-defaults --entryPointStrategy expand ./src --exclude 'src/index.ts'"
|
|
17
28
|
},
|
|
18
29
|
"repository": {
|
|
@@ -29,23 +40,24 @@
|
|
|
29
40
|
},
|
|
30
41
|
"homepage": "https://gitlab.com/dyo-system/dyo-tools#readme",
|
|
31
42
|
"devDependencies": {
|
|
32
|
-
"@babel/preset-env": "^7.
|
|
33
|
-
"@types/jest": "^
|
|
34
|
-
"@types/uuid": "^
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
36
|
-
"@typescript-eslint/parser": "^
|
|
37
|
-
"c8": "^
|
|
38
|
-
"eslint": "^8.
|
|
43
|
+
"@babel/preset-env": "^7.28.5",
|
|
44
|
+
"@types/jest": "^30.0.0",
|
|
45
|
+
"@types/uuid": "^11.0.0",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
47
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
48
|
+
"c8": "^10.1.3",
|
|
49
|
+
"eslint": "^8.57.1",
|
|
39
50
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
40
|
-
"eslint-config-airbnb-typescript": "^
|
|
41
|
-
"eslint-plugin-import": "^2.
|
|
42
|
-
"jest": "^
|
|
43
|
-
"ts-jest": "^29.
|
|
44
|
-
"
|
|
45
|
-
"typedoc
|
|
46
|
-
"
|
|
51
|
+
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
52
|
+
"eslint-plugin-import": "^2.32.0",
|
|
53
|
+
"jest": "^30.2.0",
|
|
54
|
+
"ts-jest": "^29.4.5",
|
|
55
|
+
"ts-node": "^10.9.2",
|
|
56
|
+
"typedoc": "^0.28.15",
|
|
57
|
+
"typedoc-plugin-rename-defaults": "^0.7.3",
|
|
58
|
+
"typescript": "^5.9.3"
|
|
47
59
|
},
|
|
48
60
|
"dependencies": {
|
|
49
|
-
"uuid": "^
|
|
61
|
+
"uuid": "^13.0.0"
|
|
50
62
|
}
|
|
51
63
|
}
|
package/src/constants.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
/** DTBunch constants * */
|
|
15
15
|
export const bunchDefaultOptions: DTBunchOptions = {
|
|
16
16
|
errors: false,
|
|
17
|
+
syncId: undefined,
|
|
17
18
|
uniqueKey: false,
|
|
18
19
|
inheritOwner: false,
|
|
19
20
|
replaceIndex: false,
|
|
@@ -23,6 +24,7 @@ export const bunchDefaultOptions: DTBunchOptions = {
|
|
|
23
24
|
/** DTManager constants * */
|
|
24
25
|
export const managerDefaultOptions: DTManagerOptions = {
|
|
25
26
|
errors: false,
|
|
27
|
+
syncId: undefined,
|
|
26
28
|
libraryDeletion: false,
|
|
27
29
|
};
|
|
28
30
|
|
package/src/core/DTAction.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import DTComponent from './DTComponent';
|
|
2
2
|
import { DTComponentToObject } from '../types';
|
|
3
|
-
import
|
|
3
|
+
import DTMaster from './DTMaster';
|
|
4
4
|
|
|
5
|
-
export default abstract class
|
|
5
|
+
export default abstract class DTAction<Payload = unknown> extends DTComponent {
|
|
6
6
|
/**
|
|
7
7
|
* Defining component type to "action".
|
|
8
8
|
*/
|
|
@@ -11,8 +11,8 @@ export default abstract class DYOToolsAction<Payload = unknown> extends DYOTools
|
|
|
11
11
|
/**
|
|
12
12
|
* Returns Master component from context, or undefined.
|
|
13
13
|
*/
|
|
14
|
-
getMaster():
|
|
15
|
-
return this.getContext<
|
|
14
|
+
getMaster(): DTMaster | undefined {
|
|
15
|
+
return this.getContext<DTMaster>('master');
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -49,4 +49,6 @@ export default abstract class DYOToolsAction<Payload = unknown> extends DYOTools
|
|
|
49
49
|
type: this._componentType,
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
updateFromDix() {}
|
|
52
54
|
}
|
package/src/core/DTBunch.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import DTElement from './DTElement';
|
|
2
|
+
import DTManager from './DTManager';
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
DIXObject,
|
|
5
|
+
DTAcceptedMetaData,
|
|
6
|
+
DTBunchFilters,
|
|
7
|
+
DTBunchOptions,
|
|
8
|
+
DTBunchToObject,
|
|
9
|
+
DYOFinderConfiguration,
|
|
5
10
|
} from '../types';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
11
|
+
import DTError from './DTError';
|
|
12
|
+
import DTComponentPhysical from './DTComponentPhysical';
|
|
8
13
|
import { bunchDefaultOptions as defaultOptions, componentBunchDefaultFinderConfiguration } from '../constants';
|
|
9
14
|
import DYOFinder from '../libs/DYOFinder';
|
|
15
|
+
import DTDIXModule from '../libs/dix/DIXModule.module';
|
|
10
16
|
|
|
11
|
-
export default class
|
|
12
|
-
IBunchItem extends
|
|
17
|
+
export default class DTBunch<
|
|
18
|
+
IBunchItem extends DTElement<DTAcceptedMetaData> = DTElement<DTAcceptedMetaData>,
|
|
13
19
|
IComponentMeta extends DTAcceptedMetaData = DTAcceptedMetaData,
|
|
14
|
-
> extends
|
|
20
|
+
> extends DTComponentPhysical<IComponentMeta, DTBunchOptions> {
|
|
15
21
|
/**
|
|
16
22
|
* Defining component type to "bunch".
|
|
17
23
|
*/
|
|
@@ -139,7 +145,7 @@ export default class DYOToolsBunch<
|
|
|
139
145
|
const existingItem = this.get(item.getId());
|
|
140
146
|
if (existingItem) {
|
|
141
147
|
hasError = true;
|
|
142
|
-
this.triggerError(new
|
|
148
|
+
this.triggerError(new DTError(
|
|
143
149
|
'id_conflict',
|
|
144
150
|
'Element with same id already exists in the bunch',
|
|
145
151
|
this,
|
|
@@ -152,7 +158,7 @@ export default class DYOToolsBunch<
|
|
|
152
158
|
const existingItemByKey = this.find({ key: { $eq: item.getKey() } });
|
|
153
159
|
if (existingItemByKey) {
|
|
154
160
|
hasError = true;
|
|
155
|
-
this.triggerError(new
|
|
161
|
+
this.triggerError(new DTError(
|
|
156
162
|
'key_conflict',
|
|
157
163
|
'Element with same key already exists in the bunch',
|
|
158
164
|
this,
|
|
@@ -178,7 +184,7 @@ export default class DYOToolsBunch<
|
|
|
178
184
|
if (!virtualContainer) {
|
|
179
185
|
const oldContainer = item.getContainer();
|
|
180
186
|
if (oldContainer && oldContainer.getComponentType() === 'bunch') {
|
|
181
|
-
(oldContainer as
|
|
187
|
+
(oldContainer as DTBunch<IBunchItem, DTAcceptedMetaData>).remove(item.getId());
|
|
182
188
|
}
|
|
183
189
|
item.setContainer(this);
|
|
184
190
|
}
|
|
@@ -190,7 +196,7 @@ export default class DYOToolsBunch<
|
|
|
190
196
|
|
|
191
197
|
// Update Manager library
|
|
192
198
|
if (this.getContext('manager')) {
|
|
193
|
-
const manager:
|
|
199
|
+
const manager: DTManager<IBunchItem> = this.getContext('manager') as DTManager<IBunchItem>;
|
|
194
200
|
if (manager.getLibrary().getId() !== this._id && !manager.getLibrary().get(item.getId())) {
|
|
195
201
|
manager.getLibrary().add(item);
|
|
196
202
|
}
|
|
@@ -401,7 +407,7 @@ export default class DYOToolsBunch<
|
|
|
401
407
|
*
|
|
402
408
|
* @returns New DTBunch instance copied.
|
|
403
409
|
*/
|
|
404
|
-
copy():
|
|
410
|
+
copy(): DTBunch<IBunchItem, IComponentMeta> {
|
|
405
411
|
let copyItems;
|
|
406
412
|
if (this._options.virtualContainer) {
|
|
407
413
|
copyItems = this._items;
|
|
@@ -409,7 +415,7 @@ export default class DYOToolsBunch<
|
|
|
409
415
|
copyItems = this._items.length === 0 ? [] : this._items.map((item) => item.copy() as IBunchItem);
|
|
410
416
|
}
|
|
411
417
|
|
|
412
|
-
const copyBunch = new
|
|
418
|
+
const copyBunch = new DTBunch<IBunchItem, IComponentMeta>(this._key, copyItems, this._options);
|
|
413
419
|
copyBunch.setManyMeta({ ...this.getManyMeta() });
|
|
414
420
|
|
|
415
421
|
return copyBunch;
|
|
@@ -464,4 +470,62 @@ export default class DYOToolsBunch<
|
|
|
464
470
|
|
|
465
471
|
return `Component ${this._key} - Type: Bunch${ownerKey} - Items: ${this._items.length}`;
|
|
466
472
|
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Return DIX Object representation of the DTBunch instance.
|
|
476
|
+
*
|
|
477
|
+
* @returns DIX Object representation of the DTBunch.
|
|
478
|
+
*/
|
|
479
|
+
toDIXObject(): Record<string, DIXObject> {
|
|
480
|
+
const parentDixObject = super.toDIXObject();
|
|
481
|
+
const dixObject: DIXObject = {
|
|
482
|
+
...parentDixObject[this._id],
|
|
483
|
+
items: this._items.map((item) => item.getId()),
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
const finalDix = {
|
|
487
|
+
[this._id]: dixObject,
|
|
488
|
+
};
|
|
489
|
+
this._items.forEach((item) => {
|
|
490
|
+
Object.assign(finalDix, item.toDIXObject());
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
return finalDix;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Update the DTBunch instance with a DIX Object.
|
|
498
|
+
*
|
|
499
|
+
* @param dix DIX Object to use for updating.
|
|
500
|
+
*/
|
|
501
|
+
updateFromDix(dix: Record<string, DIXObject>): void {
|
|
502
|
+
const dixObject = dix[this._id];
|
|
503
|
+
const dixModule = this.getMaster()?.getModule('dix') as DTDIXModule;
|
|
504
|
+
|
|
505
|
+
if (dixObject) {
|
|
506
|
+
// Update data
|
|
507
|
+
super.updateFromDix(dix);
|
|
508
|
+
|
|
509
|
+
// Synchronize Elements
|
|
510
|
+
if (dixObject.items && dixModule?.isEnabled()) {
|
|
511
|
+
// Remove items
|
|
512
|
+
this.getAll().forEach((it) => {
|
|
513
|
+
if (!dixObject.items.includes(it.getId())) {
|
|
514
|
+
this.remove(it.getId());
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
// Add and update existing items
|
|
519
|
+
dixObject.items.forEach((itemId) => {
|
|
520
|
+
if (this.get(itemId)) {
|
|
521
|
+
this.get(itemId).updateFromDix(dix);
|
|
522
|
+
} else {
|
|
523
|
+
const newElement = dixModule.syncNewItem(itemId, dix) as IBunchItem;
|
|
524
|
+
this.add(newElement);
|
|
525
|
+
newElement.updateFromDix(dix);
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
467
531
|
}
|
package/src/core/DTComponent.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { DTComponentOptions } from '../types';
|
|
1
|
+
import { v6 as uuidV6 } from 'uuid';
|
|
2
|
+
import DTError from './DTError';
|
|
3
|
+
import { DIXObject, DTComponentOptions } from '../types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @template {string} DTComponentOptions
|
|
7
7
|
*/
|
|
8
|
-
export default abstract class
|
|
8
|
+
export default abstract class DTComponent<
|
|
9
|
+
IComponentOptions extends DTComponentOptions = DTComponentOptions,
|
|
10
|
+
> {
|
|
9
11
|
/**
|
|
10
12
|
* Component unique ID. Use uuid v4 generator.
|
|
11
13
|
*/
|
|
@@ -22,7 +24,7 @@ export default abstract class DYOToolsComponent<IComponentOptions extends DTComp
|
|
|
22
24
|
*
|
|
23
25
|
* A component can have only one *context*, and be managed by a parent Component.
|
|
24
26
|
*/
|
|
25
|
-
protected _context?:
|
|
27
|
+
protected _context?: DTComponent;
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* Higher Level Component category.
|
|
@@ -50,7 +52,7 @@ export default abstract class DYOToolsComponent<IComponentOptions extends DTComp
|
|
|
50
52
|
*
|
|
51
53
|
* Errors are only available if the **errors** option is enabled.
|
|
52
54
|
*/
|
|
53
|
-
protected _errors:
|
|
55
|
+
protected _errors: DTError[];
|
|
54
56
|
|
|
55
57
|
/**
|
|
56
58
|
* Component options configuration.
|
|
@@ -59,6 +61,8 @@ export default abstract class DYOToolsComponent<IComponentOptions extends DTComp
|
|
|
59
61
|
* For all component, global option can be :
|
|
60
62
|
* * **errors** : Default *false*. If *true*, no exception is thrown when an error occurred, a new DTError instance is
|
|
61
63
|
* added to the _errors property array instead. If *false*, throw the exception with a DTError instance.
|
|
64
|
+
* * **syncId** : Default *undefined*. If specified, the string argument passed will be the id of the new DTComponent.
|
|
65
|
+
* Used to synchronize ids between to instances (with the DIX Module). Be careful when using.
|
|
62
66
|
*/
|
|
63
67
|
protected _options: IComponentOptions;
|
|
64
68
|
|
|
@@ -69,17 +73,19 @@ export default abstract class DYOToolsComponent<IComponentOptions extends DTComp
|
|
|
69
73
|
* @param options Specific options configuration for the instance. Default empty object.
|
|
70
74
|
*/
|
|
71
75
|
constructor(key?: string, options: Partial<IComponentOptions> = {}) {
|
|
72
|
-
this._id = uuid.v4();
|
|
73
|
-
this._key = key || this._id;
|
|
74
|
-
this._errors = [];
|
|
75
|
-
|
|
76
76
|
const defaultOptions: DTComponentOptions = {
|
|
77
77
|
errors: false,
|
|
78
|
+
syncId: undefined,
|
|
78
79
|
};
|
|
80
|
+
|
|
79
81
|
this._options = {
|
|
80
82
|
...defaultOptions,
|
|
81
83
|
...options,
|
|
82
84
|
} as IComponentOptions;
|
|
85
|
+
|
|
86
|
+
this._id = this._options.syncId ?? uuidV6();
|
|
87
|
+
this._key = key || this._id;
|
|
88
|
+
this._errors = [];
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
/**
|
|
@@ -105,7 +111,7 @@ export default abstract class DYOToolsComponent<IComponentOptions extends DTComp
|
|
|
105
111
|
* @returns Direct parent Component or higher level Component if filtered with **contextType**.
|
|
106
112
|
* Returns undefined if context doesn't exist.
|
|
107
113
|
*/
|
|
108
|
-
getContext<IContext extends
|
|
114
|
+
getContext<IContext extends DTComponent = DTComponent>(contextType?: string): IContext | undefined {
|
|
109
115
|
if (this._context) {
|
|
110
116
|
if (!contextType || this._context.getComponentType() === contextType) {
|
|
111
117
|
return this._context as IContext;
|
|
@@ -118,7 +124,7 @@ export default abstract class DYOToolsComponent<IComponentOptions extends DTComp
|
|
|
118
124
|
/**
|
|
119
125
|
* Setter for _context property.
|
|
120
126
|
*/
|
|
121
|
-
setContext<IContext extends
|
|
127
|
+
setContext<IContext extends DTComponent = DTComponent>(value: IContext): void {
|
|
122
128
|
this._context = value;
|
|
123
129
|
}
|
|
124
130
|
|
|
@@ -155,7 +161,7 @@ export default abstract class DYOToolsComponent<IComponentOptions extends DTComp
|
|
|
155
161
|
*
|
|
156
162
|
* Note : Errors are always provided by the higher order component, defined into the _context property.
|
|
157
163
|
*/
|
|
158
|
-
getErrors():
|
|
164
|
+
getErrors(): DTError[] {
|
|
159
165
|
if (this.getContext()) {
|
|
160
166
|
return this.getContext().getErrors();
|
|
161
167
|
}
|
|
@@ -167,7 +173,7 @@ export default abstract class DYOToolsComponent<IComponentOptions extends DTComp
|
|
|
167
173
|
*
|
|
168
174
|
* Note : Errors are always provided by the higher order component, defined into the _context property.
|
|
169
175
|
*/
|
|
170
|
-
getLastError():
|
|
176
|
+
getLastError(): DTError | undefined {
|
|
171
177
|
if (this.getContext()) {
|
|
172
178
|
return this.getContext().getLastError();
|
|
173
179
|
}
|
|
@@ -183,7 +189,7 @@ export default abstract class DYOToolsComponent<IComponentOptions extends DTComp
|
|
|
183
189
|
*
|
|
184
190
|
* @param error DYOToolsError instance to trigger
|
|
185
191
|
*/
|
|
186
|
-
triggerError(error:
|
|
192
|
+
triggerError(error: DTError): void {
|
|
187
193
|
const { errors = false } = this._options;
|
|
188
194
|
if (this.getContext()) {
|
|
189
195
|
this.getContext().triggerError(error);
|
|
@@ -213,6 +219,33 @@ export default abstract class DYOToolsComponent<IComponentOptions extends DTComp
|
|
|
213
219
|
return this._options;
|
|
214
220
|
}
|
|
215
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Return DIX Object representation of the DTComponent instance.
|
|
224
|
+
*
|
|
225
|
+
* @returns DIX Object representation of the DTComponent.
|
|
226
|
+
*/
|
|
227
|
+
toDIXObject(): Record<string, DIXObject> {
|
|
228
|
+
const dixOptions = this._options;
|
|
229
|
+
delete dixOptions.syncId;
|
|
230
|
+
|
|
231
|
+
const dixObject: DIXObject = {
|
|
232
|
+
useClass: this.constructor.name,
|
|
233
|
+
key: this._key,
|
|
234
|
+
componentType: this._componentType,
|
|
235
|
+
options: JSON.stringify(this._options),
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
[this._id]: dixObject,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Abstract method to update the component with a DIX Object Format.
|
|
245
|
+
* @param dix DIX Object to use for updating.
|
|
246
|
+
*/
|
|
247
|
+
abstract updateFromDix(dix: Record<string, DIXObject>): void;
|
|
248
|
+
|
|
216
249
|
/**
|
|
217
250
|
* Abstract method for JSON Object representation of the component and returning it.
|
|
218
251
|
*/
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { DTAcceptedMetaData, DTComponentOptions } from '../types';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { DIXObject, DTAcceptedMetaData, DTComponentOptions } from '../types';
|
|
2
|
+
import DTComponentWithMeta from './DTComponentWithMeta';
|
|
3
|
+
import DTMaster from './DTMaster';
|
|
4
|
+
import DTManager from './DTManager';
|
|
5
5
|
|
|
6
|
-
export default abstract class
|
|
6
|
+
export default abstract class DTComponentPhysical<
|
|
7
7
|
IComponentMeta extends DTAcceptedMetaData,
|
|
8
8
|
IComponentOptions extends DTComponentOptions = DTComponentOptions,
|
|
9
|
-
> extends
|
|
9
|
+
> extends DTComponentWithMeta<IComponentMeta, IComponentOptions> {
|
|
10
10
|
/**
|
|
11
11
|
* Owner string representation, if defined.
|
|
12
12
|
*/
|
|
@@ -15,15 +15,15 @@ export default abstract class DYOToolsComponentPhysical<
|
|
|
15
15
|
/**
|
|
16
16
|
* Returns Manager component from context, or undefined.
|
|
17
17
|
*/
|
|
18
|
-
getManager():
|
|
19
|
-
return this.getContext<
|
|
18
|
+
getManager(): DTManager | undefined {
|
|
19
|
+
return this.getContext<DTManager>('manager');
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Returns Master component from context, or undefined.
|
|
24
24
|
*/
|
|
25
|
-
getMaster():
|
|
26
|
-
return this.getContext<
|
|
25
|
+
getMaster(): DTMaster | undefined {
|
|
26
|
+
return this.getContext<DTMaster>('master');
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -47,8 +47,42 @@ export default abstract class DYOToolsComponentPhysical<
|
|
|
47
47
|
this._owner = undefined;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Return DIX Object representation of the DTComponentPhysical instance.
|
|
52
|
+
*
|
|
53
|
+
* @returns DIX Object representation of the DTComponentPhysical.
|
|
54
|
+
*/
|
|
55
|
+
toDIXObject(): Record<string, DIXObject> {
|
|
56
|
+
const parentDixObject = super.toDIXObject();
|
|
57
|
+
const dixObject: DIXObject = {
|
|
58
|
+
...parentDixObject[this._id],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
if (this._owner) {
|
|
62
|
+
dixObject.owner = this._owner;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
[this._id]: dixObject,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Update the DTComponentPhysical instance with a DIX Object.
|
|
72
|
+
*
|
|
73
|
+
* @param dix DIX Object to use for updating.
|
|
74
|
+
*/
|
|
75
|
+
updateFromDix(dix: Record<string, DIXObject>) {
|
|
76
|
+
super.updateFromDix(dix);
|
|
77
|
+
const dixObject = dix[this._id];
|
|
78
|
+
|
|
79
|
+
if (dixObject && dixObject.owner) {
|
|
80
|
+
this._owner = dixObject.owner;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
50
84
|
/**
|
|
51
85
|
* Abstract method for copying the Component and returning it.
|
|
52
86
|
*/
|
|
53
|
-
abstract copy():
|
|
87
|
+
abstract copy(): DTComponentPhysical<IComponentMeta, IComponentOptions>;
|
|
54
88
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DTAcceptedMetaData, DTComponentOptions } from '../types';
|
|
1
|
+
import DTComponent from './DTComponent';
|
|
2
|
+
import { DIXObject, DTAcceptedMetaData, DTComponentOptions } from '../types';
|
|
3
3
|
|
|
4
|
-
export default abstract class
|
|
4
|
+
export default abstract class DTComponentWithMeta<
|
|
5
5
|
IComponentMeta extends DTAcceptedMetaData,
|
|
6
6
|
IComponentOptions extends DTComponentOptions = DTComponentOptions,
|
|
7
|
-
> extends
|
|
7
|
+
> extends DTComponent<IComponentOptions> {
|
|
8
8
|
/**
|
|
9
9
|
* Component meta data.
|
|
10
10
|
* Defined by generic type IComponentMeta.
|
|
@@ -62,4 +62,37 @@ export default abstract class DYOToolsComponentWithMeta<
|
|
|
62
62
|
setManyMeta(metaValues : Partial<IComponentMeta>) : void {
|
|
63
63
|
this._meta = { ...this._meta, ...metaValues };
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Return DIX Object representation of the DTComponentWithMeta instance.
|
|
68
|
+
*
|
|
69
|
+
* @returns DIX Object representation of the DTComponentWithMeta.
|
|
70
|
+
*/
|
|
71
|
+
toDIXObject(): Record<string, DIXObject> {
|
|
72
|
+
const parentDixObject = super.toDIXObject();
|
|
73
|
+
const dixObject: DIXObject = {
|
|
74
|
+
...parentDixObject[this._id],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (Object.keys(this._meta).length > 0) {
|
|
78
|
+
dixObject.meta = JSON.stringify(this._meta);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
[this._id]: dixObject,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Update the DTComponentWithMeta instance with a DIX Object.
|
|
88
|
+
*
|
|
89
|
+
* @param dix DIX Object to use for updating.
|
|
90
|
+
*/
|
|
91
|
+
updateFromDix(dix: Record<string, DIXObject>) {
|
|
92
|
+
const dixObject = dix[this._id];
|
|
93
|
+
|
|
94
|
+
if (dixObject && dixObject.meta) {
|
|
95
|
+
this._meta = JSON.parse(dixObject.meta);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
65
98
|
}
|
package/src/core/DTElement.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { DTAcceptedMetaData, DTElementToObject } from '../types';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { DIXObject, DTAcceptedMetaData, DTElementToObject } from '../types';
|
|
2
|
+
import DTComponentPhysical from './DTComponentPhysical';
|
|
3
|
+
import DTBunch from './DTBunch';
|
|
4
4
|
|
|
5
|
-
export default class
|
|
5
|
+
export default class DTElement<
|
|
6
6
|
IComponentMeta extends DTAcceptedMetaData,
|
|
7
|
-
> extends
|
|
7
|
+
> extends DTComponentPhysical<IComponentMeta> {
|
|
8
8
|
/**
|
|
9
9
|
* Defining component type to "element".
|
|
10
10
|
*/
|
|
@@ -18,19 +18,19 @@ export default class DYOToolsElement<
|
|
|
18
18
|
* For DYOToolsElement instances, a container is a DYOToolsBunch instance.
|
|
19
19
|
* @protected
|
|
20
20
|
*/
|
|
21
|
-
protected _container:
|
|
21
|
+
protected _container: DTBunch;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Getter for _container property.
|
|
25
25
|
*/
|
|
26
|
-
getContainer():
|
|
26
|
+
getContainer(): DTBunch | undefined {
|
|
27
27
|
return this._container;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Setter for _container property.
|
|
32
32
|
*/
|
|
33
|
-
setContainer(container:
|
|
33
|
+
setContainer(container: DTBunch): void {
|
|
34
34
|
this._container = container;
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -48,8 +48,8 @@ export default class DYOToolsElement<
|
|
|
48
48
|
*
|
|
49
49
|
* @returns New DTElement instance copied.
|
|
50
50
|
*/
|
|
51
|
-
copy():
|
|
52
|
-
const copyElement = new
|
|
51
|
+
copy(): DTElement<IComponentMeta> {
|
|
52
|
+
const copyElement = new DTElement<IComponentMeta>(this._key, this._options);
|
|
53
53
|
copyElement.setManyMeta({ ...this.getManyMeta() });
|
|
54
54
|
|
|
55
55
|
return copyElement;
|
|
@@ -99,4 +99,13 @@ export default class DYOToolsElement<
|
|
|
99
99
|
|
|
100
100
|
return `Component${domainLabel} ${this._key} - Type: Element${ownerKey}`;
|
|
101
101
|
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Update the DTBunch instance with a DIX Object.
|
|
105
|
+
*
|
|
106
|
+
* @param dix DIX Object to use for updating.
|
|
107
|
+
*/
|
|
108
|
+
updateFromDix(dix: Record<string, DIXObject>) {
|
|
109
|
+
super.updateFromDix(dix);
|
|
110
|
+
}
|
|
102
111
|
}
|
package/src/core/DTError.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import DTComponent from './DTComponent';
|
|
2
2
|
|
|
3
|
-
export default class
|
|
3
|
+
export default class DTError extends Error {
|
|
4
4
|
/**
|
|
5
5
|
* Error code.
|
|
6
6
|
*
|
|
@@ -18,12 +18,12 @@ export default class DYOToolsError extends Error {
|
|
|
18
18
|
/**
|
|
19
19
|
* DTComponent which trigger the error during its current execution process.
|
|
20
20
|
*/
|
|
21
|
-
protected initiator?:
|
|
21
|
+
protected initiator?: DTComponent;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* DTComponent which is directly involved in the error trigger.
|
|
25
25
|
*/
|
|
26
|
-
protected convicted?:
|
|
26
|
+
protected convicted?: DTComponent;
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Set all property for a new DTError.
|
|
@@ -33,7 +33,7 @@ export default class DYOToolsError extends Error {
|
|
|
33
33
|
* @param initiator
|
|
34
34
|
* @param convicted
|
|
35
35
|
*/
|
|
36
|
-
constructor(code: string, message: string, initiator?:
|
|
36
|
+
constructor(code: string, message: string, initiator?: DTComponent, convicted?: DTComponent) {
|
|
37
37
|
super(message);
|
|
38
38
|
this.code = code;
|
|
39
39
|
this.timestamp = new Date();
|
|
@@ -65,14 +65,14 @@ export default class DYOToolsError extends Error {
|
|
|
65
65
|
/**
|
|
66
66
|
* Getter for initiator property.
|
|
67
67
|
*/
|
|
68
|
-
getInitiator():
|
|
68
|
+
getInitiator(): DTComponent {
|
|
69
69
|
return this.initiator;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* Getter for convicted property.
|
|
74
74
|
*/
|
|
75
|
-
getConvicted():
|
|
75
|
+
getConvicted(): DTComponent {
|
|
76
76
|
return this.convicted;
|
|
77
77
|
}
|
|
78
78
|
}
|