dyo-tools 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/{dist/index.d.ts → index.d.ts} +1 -0
  2. package/{dist/index.d.ts.map → index.d.ts.map} +1 -1
  3. package/{dist/index.js → index.js} +1 -0
  4. package/package.json +6 -56
  5. package/.c8rc.json +0 -4
  6. package/.eslintignore +0 -2
  7. package/.eslintrc.json +0 -47
  8. package/Makefile +0 -34
  9. package/README.md +0 -0
  10. package/babel.config.js +0 -1
  11. package/docs/.nojekyll +0 -1
  12. package/docs/assets/highlight.css +0 -29
  13. package/docs/assets/main.js +0 -59
  14. package/docs/assets/search.js +0 -1
  15. package/docs/assets/style.css +0 -1414
  16. package/docs/index.html +0 -1
  17. package/integration/data/components/DTHero.ts +0 -42
  18. package/integration/data/components/DTHeroManager.ts +0 -11
  19. package/integration/data/components/DTHeroPlayZone.ts +0 -6
  20. package/integration/data/components/DTHeroPlayerHand.ts +0 -11
  21. package/integration/data/components/index.ts +0 -5
  22. package/integration/data/in/heroIn.helper.ts +0 -8
  23. package/integration/data/in/playerIn.helper.ts +0 -13
  24. package/integration/data/out/heroOut.helper.ts +0 -48
  25. package/integration/endings/synchronisation.ending.ts +0 -25
  26. package/integration/scenes/drawCard.scene.ts +0 -31
  27. package/integration/scenes/empty.scene.ts +0 -6
  28. package/integration/scenes/playCard.scene.ts +0 -23
  29. package/integration/scenes/playerLeave.scene.ts +0 -33
  30. package/integration/stages/baseDix.stage.ts +0 -137
  31. package/integration/stages/syncDix.stage.ts +0 -36
  32. package/integration/tests/scenario1.spec.ts +0 -55
  33. package/integration/types/index.ts +0 -24
  34. package/jest-integration.config.ts +0 -25
  35. package/jest.config.ts +0 -26
  36. package/src/constants.ts +0 -87
  37. package/src/core/DTAction.ts +0 -54
  38. package/src/core/DTBunch.ts +0 -531
  39. package/src/core/DTComponent.ts +0 -258
  40. package/src/core/DTComponentPhysical.ts +0 -88
  41. package/src/core/DTComponentWithMeta.ts +0 -98
  42. package/src/core/DTElement.ts +0 -111
  43. package/src/core/DTError.ts +0 -78
  44. package/src/core/DTManager.ts +0 -555
  45. package/src/core/DTMaster.ts +0 -366
  46. package/src/core/DTModule.ts +0 -96
  47. package/src/index.ts +0 -17
  48. package/src/libs/DYOFinder.ts +0 -175
  49. package/src/libs/dix/DIXModule.module.ts +0 -98
  50. package/src/libs/player/DTPlayer.element.ts +0 -9
  51. package/src/libs/player/DTPlayer.manager.ts +0 -70
  52. package/src/types/core.ts +0 -204
  53. package/src/types/index.ts +0 -2
  54. package/src/types/player.ts +0 -5
  55. package/test/core/DTAction.double.ts +0 -62
  56. package/test/core/DTAction.spec.ts +0 -68
  57. package/test/core/DTBunch.double.ts +0 -175
  58. package/test/core/DTBunch.spec.ts +0 -822
  59. package/test/core/DTComponent.double.ts +0 -179
  60. package/test/core/DTComponent.spec.ts +0 -297
  61. package/test/core/DTComponentPhysical.double.ts +0 -62
  62. package/test/core/DTComponentPhysical.spec.ts +0 -81
  63. package/test/core/DTComponentWithMeta.double.ts +0 -122
  64. package/test/core/DTComponentWithMeta.spec.ts +0 -129
  65. package/test/core/DTElement.double.ts +0 -142
  66. package/test/core/DTElement.spec.ts +0 -123
  67. package/test/core/DTError.double.ts +0 -57
  68. package/test/core/DTError.spec.ts +0 -78
  69. package/test/core/DTManager.double.ts +0 -149
  70. package/test/core/DTManager.spec.ts +0 -874
  71. package/test/core/DTMaster.double.ts +0 -117
  72. package/test/core/DTMaster.spec.ts +0 -537
  73. package/test/core/DTModule.double.ts +0 -67
  74. package/test/core/DTModule.spec.ts +0 -124
  75. package/test/core/copy.spec.ts +0 -222
  76. package/test/libs/DYOFinder.double.ts +0 -152
  77. package/test/libs/DYOFinder.spec.ts +0 -194
  78. package/test/libs/player/DTPlayer.element.double.ts +0 -55
  79. package/test/libs/player/DTPlayer.element.spec.ts +0 -28
  80. package/test/libs/player/DTPlayer.manager.double.ts +0 -92
  81. package/test/libs/player/DTPlayer.manager.spec.ts +0 -178
  82. package/tsconfig.dev.json +0 -19
  83. package/tsconfig.json +0 -18
  84. /package/{dist/constants.d.ts → constants.d.ts} +0 -0
  85. /package/{dist/constants.d.ts.map → constants.d.ts.map} +0 -0
  86. /package/{dist/constants.js → constants.js} +0 -0
  87. /package/{dist/constants.js.map → constants.js.map} +0 -0
  88. /package/{dist/core → core}/DTAction.d.ts +0 -0
  89. /package/{dist/core → core}/DTAction.d.ts.map +0 -0
  90. /package/{dist/core → core}/DTAction.js +0 -0
  91. /package/{dist/core → core}/DTAction.js.map +0 -0
  92. /package/{dist/core → core}/DTBunch.d.ts +0 -0
  93. /package/{dist/core → core}/DTBunch.d.ts.map +0 -0
  94. /package/{dist/core → core}/DTBunch.js +0 -0
  95. /package/{dist/core → core}/DTBunch.js.map +0 -0
  96. /package/{dist/core → core}/DTComponent.d.ts +0 -0
  97. /package/{dist/core → core}/DTComponent.d.ts.map +0 -0
  98. /package/{dist/core → core}/DTComponent.js +0 -0
  99. /package/{dist/core → core}/DTComponent.js.map +0 -0
  100. /package/{dist/core → core}/DTComponentPhysical.d.ts +0 -0
  101. /package/{dist/core → core}/DTComponentPhysical.d.ts.map +0 -0
  102. /package/{dist/core → core}/DTComponentPhysical.js +0 -0
  103. /package/{dist/core → core}/DTComponentPhysical.js.map +0 -0
  104. /package/{dist/core → core}/DTComponentWithMeta.d.ts +0 -0
  105. /package/{dist/core → core}/DTComponentWithMeta.d.ts.map +0 -0
  106. /package/{dist/core → core}/DTComponentWithMeta.js +0 -0
  107. /package/{dist/core → core}/DTComponentWithMeta.js.map +0 -0
  108. /package/{dist/core → core}/DTElement.d.ts +0 -0
  109. /package/{dist/core → core}/DTElement.d.ts.map +0 -0
  110. /package/{dist/core → core}/DTElement.js +0 -0
  111. /package/{dist/core → core}/DTElement.js.map +0 -0
  112. /package/{dist/core → core}/DTError.d.ts +0 -0
  113. /package/{dist/core → core}/DTError.d.ts.map +0 -0
  114. /package/{dist/core → core}/DTError.js +0 -0
  115. /package/{dist/core → core}/DTError.js.map +0 -0
  116. /package/{dist/core → core}/DTManager.d.ts +0 -0
  117. /package/{dist/core → core}/DTManager.d.ts.map +0 -0
  118. /package/{dist/core → core}/DTManager.js +0 -0
  119. /package/{dist/core → core}/DTManager.js.map +0 -0
  120. /package/{dist/core → core}/DTMaster.d.ts +0 -0
  121. /package/{dist/core → core}/DTMaster.d.ts.map +0 -0
  122. /package/{dist/core → core}/DTMaster.js +0 -0
  123. /package/{dist/core → core}/DTMaster.js.map +0 -0
  124. /package/{dist/core → core}/DTModule.d.ts +0 -0
  125. /package/{dist/core → core}/DTModule.d.ts.map +0 -0
  126. /package/{dist/core → core}/DTModule.js +0 -0
  127. /package/{dist/core → core}/DTModule.js.map +0 -0
  128. /package/{dist/index.js.map → index.js.map} +0 -0
  129. /package/{dist/libs → libs}/DYOFinder.d.ts +0 -0
  130. /package/{dist/libs → libs}/DYOFinder.d.ts.map +0 -0
  131. /package/{dist/libs → libs}/DYOFinder.js +0 -0
  132. /package/{dist/libs → libs}/DYOFinder.js.map +0 -0
  133. /package/{dist/libs → libs}/dix/DIXModule.module.d.ts +0 -0
  134. /package/{dist/libs → libs}/dix/DIXModule.module.d.ts.map +0 -0
  135. /package/{dist/libs → libs}/dix/DIXModule.module.js +0 -0
  136. /package/{dist/libs → libs}/player/DTPlayer.element.d.ts +0 -0
  137. /package/{dist/libs → libs}/player/DTPlayer.element.d.ts.map +0 -0
  138. /package/{dist/libs → libs}/player/DTPlayer.element.js +0 -0
  139. /package/{dist/libs → libs}/player/DTPlayer.element.js.map +0 -0
  140. /package/{dist/libs → libs}/player/DTPlayer.manager.d.ts +0 -0
  141. /package/{dist/libs → libs}/player/DTPlayer.manager.d.ts.map +0 -0
  142. /package/{dist/libs → libs}/player/DTPlayer.manager.js +0 -0
  143. /package/{dist/libs → libs}/player/DTPlayer.manager.js.map +0 -0
  144. /package/{dist/tsconfig.dev.tsbuildinfo → tsconfig.dev.tsbuildinfo} +0 -0
  145. /package/{dist/tsconfig.tsbuildinfo → tsconfig.tsbuildinfo} +0 -0
  146. /package/{dist/types → types}/core.d.ts +0 -0
  147. /package/{dist/types → types}/core.d.ts.map +0 -0
  148. /package/{dist/types → types}/core.js +0 -0
  149. /package/{dist/types → types}/core.js.map +0 -0
  150. /package/{dist/types → types}/index.d.ts +0 -0
  151. /package/{dist/types → types}/index.d.ts.map +0 -0
  152. /package/{dist/types → types}/index.js +0 -0
  153. /package/{dist/types → types}/index.js.map +0 -0
  154. /package/{dist/types → types}/player.d.ts +0 -0
  155. /package/{dist/types → types}/player.d.ts.map +0 -0
  156. /package/{dist/types → types}/player.js +0 -0
  157. /package/{dist/types → types}/player.js.map +0 -0
@@ -1,258 +0,0 @@
1
- import { v6 as uuidV6 } from 'uuid';
2
- import DTError from './DTError';
3
- import { DIXObject, DTComponentOptions } from '../types';
4
-
5
- /**
6
- * @template {string} DTComponentOptions
7
- */
8
- export default abstract class DTComponent<
9
- IComponentOptions extends DTComponentOptions = DTComponentOptions,
10
- > {
11
- /**
12
- * Component unique ID. Use uuid v4 generator.
13
- */
14
- protected _id: string;
15
-
16
- /**
17
- * Component specific and accessible label.
18
- * If not provided, the key is set with ID by default.
19
- */
20
- protected _key: string;
21
-
22
- /**
23
- * Component Parent Context.
24
- *
25
- * A component can have only one *context*, and be managed by a parent Component.
26
- */
27
- protected _context?: DTComponent;
28
-
29
- /**
30
- * Higher Level Component category.
31
- *
32
- * Describing component Type, like Element, Bunch, Manager...
33
- */
34
- protected abstract _componentType: string;
35
-
36
- /**
37
- * Second Level Component category.
38
- *
39
- * Describing component Domain, like Card, Dice, Token...
40
- */
41
- protected _domain?: string;
42
-
43
- /**
44
- * Third Level Component category.
45
- *
46
- * Describing component extra type, like Hand, Deck, Trick...
47
- */
48
- protected _subKind?: string;
49
-
50
- /**
51
- * Array of current errors for the Component.
52
- *
53
- * Errors are only available if the **errors** option is enabled.
54
- */
55
- protected _errors: DTError[];
56
-
57
- /**
58
- * Component options configuration.
59
- * Defined by generic type IComponentOptions.
60
- *
61
- * For all component, global option can be :
62
- * * **errors** : 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
- * * **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.
66
- */
67
- protected _options: IComponentOptions;
68
-
69
- /**
70
- * Set automatic unique _id and _key.
71
- *
72
- * @param key Optional Key to set. If not provided, set the _key with the _id value.
73
- * @param options Specific options configuration for the instance. Default empty object.
74
- */
75
- constructor(key?: string, options: Partial<IComponentOptions> = {}) {
76
- const defaultOptions: DTComponentOptions = {
77
- errors: false,
78
- syncId: undefined,
79
- };
80
-
81
- this._options = {
82
- ...defaultOptions,
83
- ...options,
84
- } as IComponentOptions;
85
-
86
- this._id = this._options.syncId ?? uuidV6();
87
- this._key = key || this._id;
88
- this._errors = [];
89
- }
90
-
91
- /**
92
- * Getter for _id property.
93
- */
94
- getId(): string {
95
- return this._id;
96
- }
97
-
98
- /**
99
- * Getter for _key property.
100
- */
101
- getKey(): string {
102
- return this._key;
103
- }
104
-
105
- /**
106
- * Getter for _context property.
107
- *
108
- * @param contextType If provided, the getter parse all component level hierarchy to find the corresponding component
109
- * with **contextType** as _componentType value, and returns it. Return undefined if not found.
110
- *
111
- * @returns Direct parent Component or higher level Component if filtered with **contextType**.
112
- * Returns undefined if context doesn't exist.
113
- */
114
- getContext<IContext extends DTComponent = DTComponent>(contextType?: string): IContext | undefined {
115
- if (this._context) {
116
- if (!contextType || this._context.getComponentType() === contextType) {
117
- return this._context as IContext;
118
- }
119
- return this._context.getContext(contextType);
120
- }
121
- return undefined;
122
- }
123
-
124
- /**
125
- * Setter for _context property.
126
- */
127
- setContext<IContext extends DTComponent = DTComponent>(value: IContext): void {
128
- this._context = value;
129
- }
130
-
131
- /**
132
- * Remove the current context of component.
133
- */
134
- removeContext(): void {
135
- this._context = undefined;
136
- }
137
-
138
- /**
139
- * Getter for _componentType property.
140
- */
141
- getComponentType(): string {
142
- return this._componentType;
143
- }
144
-
145
- /**
146
- * Getter for _domain property.
147
- */
148
- getDomain(): string {
149
- return this._domain;
150
- }
151
-
152
- /**
153
- * Getter for _subKind property.
154
- */
155
- getSubKind(): string {
156
- return this._subKind;
157
- }
158
-
159
- /**
160
- * Getter for _errors property.
161
- *
162
- * Note : Errors are always provided by the higher order component, defined into the _context property.
163
- */
164
- getErrors(): DTError[] {
165
- if (this.getContext()) {
166
- return this.getContext().getErrors();
167
- }
168
- return this._errors;
169
- }
170
-
171
- /**
172
- * Return the last error (most recent) of the current component. Undefined if _errors is empty.
173
- *
174
- * Note : Errors are always provided by the higher order component, defined into the _context property.
175
- */
176
- getLastError(): DTError | undefined {
177
- if (this.getContext()) {
178
- return this.getContext().getLastError();
179
- }
180
- return this._errors.length > 0 ? this._errors[this._errors.length - 1] : undefined;
181
- }
182
-
183
- /**
184
- * Generic method to trigger an error, depending on the **errors** option :
185
- * * if the option is set to *false*, throw the DTError instance passed as an argument.
186
- * * if the option is set to *true*, add DTError instance passed as an argument in the _errors array.
187
- *
188
- * Note : Errors are always stored into the higher order component, defined into the _context property.
189
- *
190
- * @param error DYOToolsError instance to trigger
191
- */
192
- triggerError(error: DTError): void {
193
- const { errors = false } = this._options;
194
- if (this.getContext()) {
195
- this.getContext().triggerError(error);
196
- } else if (!errors) {
197
- throw error;
198
- } else {
199
- this._errors.push(error);
200
- }
201
- }
202
-
203
- /**
204
- * Clear all current errors.
205
- *
206
- * Note : Errors are always stored into the higher order component, defined into the _context property.
207
- */
208
- clearErrors(): void {
209
- if (this.getContext()) {
210
- this.getContext().clearErrors();
211
- }
212
- this._errors = [];
213
- }
214
-
215
- /**
216
- * Getter for _options property.
217
- */
218
- getOptions(): IComponentOptions {
219
- return this._options;
220
- }
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
-
249
- /**
250
- * Abstract method for JSON Object representation of the component and returning it.
251
- */
252
- abstract toObject(): unknown;
253
-
254
- /**
255
- * Abstract method for String representation of the component and returning it.
256
- */
257
- abstract toString(): string;
258
- }
@@ -1,88 +0,0 @@
1
- import { DIXObject, DTAcceptedMetaData, DTComponentOptions } from '../types';
2
- import DTComponentWithMeta from './DTComponentWithMeta';
3
- import DTMaster from './DTMaster';
4
- import DTManager from './DTManager';
5
-
6
- export default abstract class DTComponentPhysical<
7
- IComponentMeta extends DTAcceptedMetaData,
8
- IComponentOptions extends DTComponentOptions = DTComponentOptions,
9
- > extends DTComponentWithMeta<IComponentMeta, IComponentOptions> {
10
- /**
11
- * Owner string representation, if defined.
12
- */
13
- protected _owner?: string;
14
-
15
- /**
16
- * Returns Manager component from context, or undefined.
17
- */
18
- getManager(): DTManager | undefined {
19
- return this.getContext<DTManager>('manager');
20
- }
21
-
22
- /**
23
- * Returns Master component from context, or undefined.
24
- */
25
- getMaster(): DTMaster | undefined {
26
- return this.getContext<DTMaster>('master');
27
- }
28
-
29
- /**
30
- * Getter for _owner property.
31
- */
32
- getOwner(): string {
33
- return this._owner;
34
- }
35
-
36
- /**
37
- * Setter for _owner property.
38
- */
39
- setOwner(value: string): void {
40
- this._owner = value;
41
- }
42
-
43
- /**
44
- * Remove the current owner of element.
45
- */
46
- removeOwner(): void {
47
- this._owner = undefined;
48
- }
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
-
84
- /**
85
- * Abstract method for copying the Component and returning it.
86
- */
87
- abstract copy(): DTComponentPhysical<IComponentMeta, IComponentOptions>;
88
- }
@@ -1,98 +0,0 @@
1
- import DTComponent from './DTComponent';
2
- import { DIXObject, DTAcceptedMetaData, DTComponentOptions } from '../types';
3
-
4
- export default abstract class DTComponentWithMeta<
5
- IComponentMeta extends DTAcceptedMetaData,
6
- IComponentOptions extends DTComponentOptions = DTComponentOptions,
7
- > extends DTComponent<IComponentOptions> {
8
- /**
9
- * Component meta data.
10
- * Defined by generic type IComponentMeta.
11
- * @default {}
12
- */
13
- protected _meta : Partial<IComponentMeta> = {} as Partial<IComponentMeta>;
14
-
15
- /**
16
- * Getter for one meta by key.
17
- *
18
- * @param metaKey Key name of one meta data.
19
- *
20
- * @returns Associated meta **metaKey** value or undefined if not found.
21
- */
22
- getMeta<K extends keyof IComponentMeta>(metaKey : K) : IComponentMeta[K] | undefined {
23
- return this._meta && this._meta[metaKey];
24
- }
25
-
26
- /**
27
- * Setter for one meta by key.
28
- *
29
- * @param metaKey Key name of the meta data to update.
30
- * @param metaValue New value to set into the meta data.
31
- */
32
- setMeta<K extends keyof IComponentMeta>(metaKey : K, metaValue : IComponentMeta[K]) : void {
33
- this._meta[metaKey] = metaValue;
34
- }
35
-
36
- /**
37
- * Returns multiple defined keys values of meta data.
38
- *
39
- * @param metaKeys Array of keys to filter for meta data. If not provided or empty, returns all keys.
40
- *
41
- * @returns Meta data object with **metaKeys** provided keys only.
42
- */
43
- getManyMeta(metaKeys : Array<keyof IComponentMeta> = []) : Partial<IComponentMeta> {
44
- const arrayMeta: Partial<IComponentMeta> = {} as Partial<IComponentMeta>;
45
- if (!metaKeys.length) {
46
- return this._meta;
47
- }
48
-
49
- metaKeys.forEach((key) => {
50
- if (this._meta && this._meta[key]) {
51
- arrayMeta[key] = this._meta[key];
52
- }
53
- });
54
- return arrayMeta;
55
- }
56
-
57
- /**
58
- * Set multiple meta data.
59
- *
60
- * @param metaValues Object of meta data to set, according to the meta data property type.
61
- */
62
- setManyMeta(metaValues : Partial<IComponentMeta>) : void {
63
- this._meta = { ...this._meta, ...metaValues };
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
- }
98
- }
@@ -1,111 +0,0 @@
1
- import { DIXObject, DTAcceptedMetaData, DTElementToObject } from '../types';
2
- import DTComponentPhysical from './DTComponentPhysical';
3
- import DTBunch from './DTBunch';
4
-
5
- export default class DTElement<
6
- IComponentMeta extends DTAcceptedMetaData,
7
- > extends DTComponentPhysical<IComponentMeta> {
8
- /**
9
- * Defining component type to "element".
10
- */
11
- protected _componentType = 'element';
12
-
13
- /**
14
- * Component current **Container**.
15
- *
16
- * A container is a parent component which "contains" the current instance.
17
- * **Context** and **container** are different components, with different purpose.
18
- * For DYOToolsElement instances, a container is a DYOToolsBunch instance.
19
- * @protected
20
- */
21
- protected _container: DTBunch;
22
-
23
- /**
24
- * Getter for _container property.
25
- */
26
- getContainer(): DTBunch | undefined {
27
- return this._container;
28
- }
29
-
30
- /**
31
- * Setter for _container property.
32
- */
33
- setContainer(container: DTBunch): void {
34
- this._container = container;
35
- }
36
-
37
- /**
38
- * Remove the current container of Element instance.
39
- */
40
- removeContainer(): void {
41
- this._container = undefined;
42
- }
43
-
44
- /**
45
- * Create and return a new DTElement instance by applying from current instance :
46
- * - Copy _key property
47
- * - Copy _meta property
48
- *
49
- * @returns New DTElement instance copied.
50
- */
51
- copy(): DTElement<IComponentMeta> {
52
- const copyElement = new DTElement<IComponentMeta>(this._key, this._options);
53
- copyElement.setManyMeta({ ...this.getManyMeta() });
54
-
55
- return copyElement;
56
- }
57
-
58
- /**
59
- * Return JSON Object representation of the Element instance.
60
- *
61
- * JSON Object returned has the following structure :
62
- * * **id** : _id property of the Element.
63
- * * **key** : _key property of the Element.
64
- * * **type** : _componentType property of the Element.
65
- * * **owner** : String representation of the current _owner property of the Element (only if defined).
66
- * * **meta** : JSON Object of all current metadata in _meta property of the Element (only if not empty).
67
- *
68
- * @returns JSON Object representation of the Element.
69
- */
70
- toObject(): DTElementToObject<IComponentMeta> {
71
- const objectElement: DTElementToObject<IComponentMeta> = {
72
- id: this._id,
73
- key: this._key,
74
- type: this._componentType,
75
- };
76
-
77
- if (this._owner) {
78
- objectElement.owner = this._owner.toString();
79
- }
80
-
81
- if (this._meta && Object.keys(this._meta).length > 0) {
82
- objectElement.meta = { ...this.getManyMeta() };
83
- }
84
-
85
- return objectElement;
86
- }
87
-
88
- /**
89
- * Return String representation of the Element instance.
90
- *
91
- * @returns String representation of the Element.
92
- */
93
- toString(): string {
94
- let ownerKey = '';
95
- if (this._owner) {
96
- ownerKey = ` - Owner: ${this._owner}`;
97
- }
98
- const domainLabel = this._domain ? ` ${this._domain}` : '';
99
-
100
- return `Component${domainLabel} ${this._key} - Type: Element${ownerKey}`;
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
- }
111
- }
@@ -1,78 +0,0 @@
1
- import DTComponent from './DTComponent';
2
-
3
- export default class DTError extends Error {
4
- /**
5
- * Error code.
6
- *
7
- * Available error codes are :
8
- * * **id_conflict** : _id property conflict between two DTComponent in the same context.
9
- * * **key_conflict** : _key property conflict between two DTComponent in the same context.
10
- */
11
- protected code: string;
12
-
13
- /**
14
- * Error trigger date.
15
- */
16
- protected timestamp: Date;
17
-
18
- /**
19
- * DTComponent which trigger the error during its current execution process.
20
- */
21
- protected initiator?: DTComponent;
22
-
23
- /**
24
- * DTComponent which is directly involved in the error trigger.
25
- */
26
- protected convicted?: DTComponent;
27
-
28
- /**
29
- * Set all property for a new DTError.
30
- *
31
- * @param code
32
- * @param message
33
- * @param initiator
34
- * @param convicted
35
- */
36
- constructor(code: string, message: string, initiator?: DTComponent, convicted?: DTComponent) {
37
- super(message);
38
- this.code = code;
39
- this.timestamp = new Date();
40
- this.initiator = initiator;
41
- this.convicted = convicted;
42
- }
43
-
44
- /**
45
- * Getter for code property.
46
- */
47
- getCode(): string {
48
- return this.code;
49
- }
50
-
51
- /**
52
- * Getter for message property (inherited from Error).
53
- */
54
- getMessage(): string {
55
- return this.message;
56
- }
57
-
58
- /**
59
- * Getter for timestamp property.
60
- */
61
- getTimestamp(): Date {
62
- return this.timestamp;
63
- }
64
-
65
- /**
66
- * Getter for initiator property.
67
- */
68
- getInitiator(): DTComponent {
69
- return this.initiator;
70
- }
71
-
72
- /**
73
- * Getter for convicted property.
74
- */
75
- getConvicted(): DTComponent {
76
- return this.convicted;
77
- }
78
- }