@configura/web-api 2.0.0-alpha.2 → 2.0.0-alpha.21

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 (100) hide show
  1. package/.eslintrc.json +5 -18
  2. package/LICENSE +201 -201
  3. package/README.md +1 -1
  4. package/dist/CatalogueAPI.d.ts +597 -551
  5. package/dist/CatalogueAPI.js +328 -293
  6. package/dist/CfgMeasure.d.ts +32 -32
  7. package/dist/CfgMeasure.js +30 -30
  8. package/dist/CfgProduct.d.ts +328 -268
  9. package/dist/CfgProduct.js +934 -778
  10. package/dist/CfgReferencePathHelper.d.ts +26 -13
  11. package/dist/CfgReferencePathHelper.js +26 -13
  12. package/dist/ConfigurationConverter.d.ts +17 -4
  13. package/dist/ConfigurationConverter.js +175 -72
  14. package/dist/index.d.ts +23 -23
  15. package/dist/index.js +23 -23
  16. package/dist/io/CfgHistoryManager.d.ts +83 -50
  17. package/dist/io/CfgHistoryManager.js +144 -82
  18. package/dist/io/CfgHistoryToProdConfConnector.d.ts +21 -20
  19. package/dist/io/CfgHistoryToProdConfConnector.js +50 -56
  20. package/dist/io/CfgIOManager.d.ts +53 -48
  21. package/dist/io/CfgIOManager.js +134 -115
  22. package/dist/io/CfgIOProdConfConnector.d.ts +64 -52
  23. package/dist/io/CfgIOProdConfConnector.js +149 -141
  24. package/dist/io/CfgIOWarningSupplier.d.ts +4 -0
  25. package/dist/io/CfgIOWarningSupplier.js +1 -0
  26. package/dist/io/CfgObservableStateManager.d.ts +25 -21
  27. package/dist/io/CfgObservableStateManager.js +69 -65
  28. package/dist/io/CfgObservableStateToProdConfConnector.d.ts +14 -14
  29. package/dist/io/CfgObservableStateToProdConfConnector.js +16 -16
  30. package/dist/io/CfgWindowEventManager.d.ts +21 -21
  31. package/dist/io/CfgWindowEventManager.js +38 -38
  32. package/dist/io/CfgWindowMessageManager.d.ts +40 -40
  33. package/dist/io/CfgWindowMessageManager.js +91 -84
  34. package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +16 -16
  35. package/dist/io/CfgWindowMessageToProdConfConnector.js +18 -18
  36. package/dist/io/index.d.ts +8 -8
  37. package/dist/io/index.js +8 -8
  38. package/dist/material/CfgMaterialMapping.d.ts +7 -7
  39. package/dist/material/CfgMaterialMapping.js +181 -181
  40. package/dist/material/CfgMtrlApplication.d.ts +18 -18
  41. package/dist/material/CfgMtrlApplication.js +43 -43
  42. package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
  43. package/dist/material/CfgMtrlApplicationSource.js +8 -8
  44. package/dist/material/CfgMtrlSource.d.ts +19 -19
  45. package/dist/material/CfgMtrlSource.js +40 -40
  46. package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
  47. package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
  48. package/dist/productConfiguration/CfgFeature.d.ts +189 -187
  49. package/dist/productConfiguration/CfgFeature.js +658 -645
  50. package/dist/productConfiguration/CfgOption.d.ts +151 -151
  51. package/dist/productConfiguration/CfgOption.js +422 -416
  52. package/dist/productConfiguration/CfgProductConfiguration.d.ts +129 -117
  53. package/dist/productConfiguration/CfgProductConfiguration.js +340 -307
  54. package/dist/productConfiguration/filters.d.ts +15 -15
  55. package/dist/productConfiguration/filters.js +70 -70
  56. package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
  57. package/dist/productConfiguration/productParamsGenerator.js +51 -51
  58. package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
  59. package/dist/productConfiguration/utilitiesProductConfiguration.js +87 -80
  60. package/dist/productLoader.d.ts +33 -33
  61. package/dist/productLoader.js +49 -49
  62. package/dist/syncGroups/SyncGroupsApplyMode.d.ts +20 -20
  63. package/dist/syncGroups/SyncGroupsApplyMode.js +21 -21
  64. package/dist/syncGroups/SyncGroupsHandler.d.ts +47 -40
  65. package/dist/syncGroups/SyncGroupsHandler.js +370 -359
  66. package/dist/syncGroups/SyncGroupsPathHelper.d.ts +26 -26
  67. package/dist/syncGroups/SyncGroupsPathHelper.js +90 -90
  68. package/dist/syncGroups/SyncGroupsState.d.ts +39 -35
  69. package/dist/syncGroups/SyncGroupsState.js +167 -125
  70. package/dist/syncGroups/SyncGroupsTransaction.d.ts +154 -154
  71. package/dist/syncGroups/SyncGroupsTransaction.js +589 -576
  72. package/dist/tasks/TaskHandler.d.ts +77 -77
  73. package/dist/tasks/TaskHandler.js +276 -275
  74. package/dist/tasks/formats.d.ts +4 -4
  75. package/dist/tasks/formats.js +7 -7
  76. package/dist/tests/testData/collectorForTest.d.ts +73 -73
  77. package/dist/tests/testData/collectorForTest.js +194 -194
  78. package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
  79. package/dist/tests/testData/dummyProductForTest.js +32 -32
  80. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +11 -11
  81. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +282 -277
  82. package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
  83. package/dist/tests/testData/testDataCachedGetProduct.js +187 -185
  84. package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
  85. package/dist/tests/testData/testDataCachedPostValidate.js +185 -183
  86. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
  87. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1099 -1099
  88. package/dist/tests/testData/testDataOptions.d.ts +12 -12
  89. package/dist/tests/testData/testDataOptions.js +60 -60
  90. package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
  91. package/dist/tests/testData/testDataProductAggregatedPrice.js +189 -187
  92. package/dist/tests/testData/testDataUpcharge.d.ts +8 -8
  93. package/dist/tests/testData/testDataUpcharge.js +121 -119
  94. package/dist/utilitiesCatalogueData.d.ts +47 -42
  95. package/dist/utilitiesCatalogueData.js +180 -173
  96. package/dist/utilitiesCataloguePermission.d.ts +38 -38
  97. package/dist/utilitiesCataloguePermission.js +79 -79
  98. package/dist/utilitiesNumericValues.d.ts +24 -24
  99. package/dist/utilitiesNumericValues.js +114 -109
  100. package/package.json +3 -3
@@ -1,27 +1,27 @@
1
- import { _CfgProductInternal } from "../CfgProduct.js";
2
- import { _CfgFeatureInternal } from "../productConfiguration/CfgFeature.js";
3
- import { _CfgOptionInternal } from "../productConfiguration/CfgOption.js";
4
- import { _CfgProductConfigurationInternal } from "../productConfiguration/CfgProductConfiguration.js";
5
- export declare type CfgPathSegment = string;
6
- /**
7
- * Represents the path to a node in the configuration tree.
8
- *
9
- * The format consists of a number of CfgPathSegments, each of which is currently a string. The
10
- * exact meaning of the strings vary depending on where they are located in the path.
11
- *
12
- * @warning
13
- * The format is strictly internal and can change in later versions of the SDK.
14
- * Data stored in a CfgPath should be thus be considered transient and never stored or transmitted.
15
- */
16
- export declare type CfgPath = CfgPathSegment[];
17
- declare type PathItemType = _CfgProductInternal | _CfgProductConfigurationInternal | _CfgFeatureInternal | _CfgOptionInternal;
18
- export declare class SyncGroupsPathHelper {
19
- static getPath(item: PathItemType): CfgPath;
20
- static getFromPath(path: CfgPath, root: PathItemType): PathItemType;
21
- static getProductFromPath(path: CfgPath, item: _CfgProductInternal): _CfgProductInternal;
22
- static getProductConfigurationFromPath(path: CfgPath, item: _CfgProductInternal): _CfgProductConfigurationInternal;
23
- static getFeatureFromPath(path: CfgPath, item: PathItemType): _CfgFeatureInternal;
24
- static getOptionFromPath(path: CfgPath, item: PathItemType): _CfgOptionInternal;
25
- }
26
- export {};
1
+ import { _CfgProductInternal } from "../CfgProduct.js";
2
+ import { _CfgFeatureInternal } from "../productConfiguration/CfgFeature.js";
3
+ import { _CfgOptionInternal } from "../productConfiguration/CfgOption.js";
4
+ import { _CfgProductConfigurationInternal } from "../productConfiguration/CfgProductConfiguration.js";
5
+ export declare type CfgPathSegment = string;
6
+ /**
7
+ * Represents the path to a node in the configuration tree.
8
+ *
9
+ * The format consists of a number of CfgPathSegments, each of which is currently a string. The
10
+ * exact meaning of the strings vary depending on where they are located in the path.
11
+ *
12
+ * @warning
13
+ * The format is strictly internal and can change in later versions of the SDK.
14
+ * Data stored in a CfgPath should be thus be considered transient and never stored or transmitted.
15
+ */
16
+ export declare type CfgPath = CfgPathSegment[];
17
+ declare type PathItemType = _CfgProductInternal | _CfgProductConfigurationInternal | _CfgFeatureInternal | _CfgOptionInternal;
18
+ export declare class SyncGroupsPathHelper {
19
+ static getPath(item: PathItemType): CfgPath;
20
+ static getFromPath(path: CfgPath, root: PathItemType): PathItemType;
21
+ static getProductFromPath(path: CfgPath, item: _CfgProductInternal): _CfgProductInternal;
22
+ static getProductConfigurationFromPath(path: CfgPath, item: _CfgProductInternal): _CfgProductConfigurationInternal;
23
+ static getFeatureFromPath(path: CfgPath, item: PathItemType): _CfgFeatureInternal;
24
+ static getOptionFromPath(path: CfgPath, item: PathItemType): _CfgOptionInternal;
25
+ }
26
+ export {};
27
27
  //# sourceMappingURL=SyncGroupsPathHelper.d.ts.map
@@ -1,90 +1,90 @@
1
- import { assert, assertDefined } from "@configura/web-utilities";
2
- import { _CfgProductInternal } from "../CfgProduct.js";
3
- import { _CfgFeatureInternal } from "../productConfiguration/CfgFeature.js";
4
- import { _CfgOptionInternal } from "../productConfiguration/CfgOption.js";
5
- import { _CfgProductConfigurationInternal } from "../productConfiguration/CfgProductConfiguration.js";
6
- export class SyncGroupsPathHelper {
7
- static getPath(item) {
8
- if (item instanceof _CfgProductInternal) {
9
- const parent = item.parent;
10
- const refKey = item.refKey;
11
- if (parent === undefined || refKey === undefined) {
12
- return [];
13
- }
14
- return [...this.getPath(parent), "p", refKey];
15
- }
16
- if (item instanceof _CfgProductConfigurationInternal) {
17
- return [...this.getPath(item.parentProduct), "c"];
18
- }
19
- if (item instanceof _CfgFeatureInternal) {
20
- return [...this.getPath(item.parent), item.code];
21
- }
22
- if (item instanceof _CfgOptionInternal) {
23
- return [...this.getPath(item.parent), item.code];
24
- }
25
- throw new Error("This should not happen");
26
- }
27
- static getFromPath(path, root) {
28
- path = path.slice();
29
- let item = root;
30
- while (path.length > 0) {
31
- const segment = path.shift();
32
- if (item instanceof _CfgProductInternal) {
33
- switch (segment) {
34
- case "p": {
35
- const refKey = path.shift();
36
- const additional = item.additionalProducts.find((p) => p.refKey === refKey);
37
- assertDefined(additional, `Additional product not found "p, ${refKey !== null && refKey !== void 0 ? refKey : ""}, ${path.join(", ")}"`);
38
- item = additional._internal;
39
- break;
40
- }
41
- case "c":
42
- assert(item instanceof _CfgProductInternal, "Was not product");
43
- item = item.configuration._internal;
44
- break;
45
- default:
46
- throw new Error(`Unexpected path segment "${segment !== null && segment !== void 0 ? segment : ""}"`);
47
- }
48
- }
49
- else if (item instanceof _CfgProductConfigurationInternal) {
50
- const feature = item.features.find((f) => f.code === segment);
51
- assertDefined(feature, `Feature not found "${segment !== null && segment !== void 0 ? segment : ""}", ${path.join(", ")}`);
52
- item = feature._internal;
53
- }
54
- else if (item instanceof _CfgFeatureInternal) {
55
- const option = item.options.find((o) => o.code === segment);
56
- assertDefined(option, `Option not found "${segment !== null && segment !== void 0 ? segment : ""}", ${path.join(", ")}`);
57
- item = option._internal;
58
- }
59
- else if (item instanceof _CfgOptionInternal) {
60
- const feature = item.features.find((o) => o.code === segment);
61
- assertDefined(feature, `Feature not found "${segment !== null && segment !== void 0 ? segment : ""}", ${path.join(", ")}`);
62
- item = feature._internal;
63
- }
64
- else {
65
- throw new Error("This should not happen (unexpected type)");
66
- }
67
- }
68
- return item;
69
- }
70
- static getProductFromPath(path, item) {
71
- const p = this.getFromPath(path, item);
72
- assert(p instanceof _CfgProductInternal, `Path did not lead to a Product`);
73
- return p;
74
- }
75
- static getProductConfigurationFromPath(path, item) {
76
- const c = this.getFromPath(path, item);
77
- assert(c instanceof _CfgProductConfigurationInternal, `Path did not lead to a ProductConfiguration"`);
78
- return c;
79
- }
80
- static getFeatureFromPath(path, item) {
81
- const f = this.getFromPath(path, item);
82
- assert(f instanceof _CfgFeatureInternal, `Path did not lead to a Feature`);
83
- return f;
84
- }
85
- static getOptionFromPath(path, item) {
86
- const o = this.getFromPath(path, item);
87
- assert(o instanceof _CfgOptionInternal, `Path did not lead to a Option`);
88
- return o;
89
- }
90
- }
1
+ import { assert, assertDefined } from "@configura/web-utilities";
2
+ import { _CfgProductInternal } from "../CfgProduct.js";
3
+ import { _CfgFeatureInternal } from "../productConfiguration/CfgFeature.js";
4
+ import { _CfgOptionInternal } from "../productConfiguration/CfgOption.js";
5
+ import { _CfgProductConfigurationInternal } from "../productConfiguration/CfgProductConfiguration.js";
6
+ export class SyncGroupsPathHelper {
7
+ static getPath(item) {
8
+ if (item instanceof _CfgProductInternal) {
9
+ const parent = item.parent;
10
+ const refKey = item.refKey;
11
+ if (parent === undefined || refKey === undefined) {
12
+ return [];
13
+ }
14
+ return [...this.getPath(parent), "p", refKey];
15
+ }
16
+ if (item instanceof _CfgProductConfigurationInternal) {
17
+ return [...this.getPath(item.parentProduct), "c"];
18
+ }
19
+ if (item instanceof _CfgFeatureInternal) {
20
+ return [...this.getPath(item.parent), item.code];
21
+ }
22
+ if (item instanceof _CfgOptionInternal) {
23
+ return [...this.getPath(item.parent), item.code];
24
+ }
25
+ throw new Error("This should not happen");
26
+ }
27
+ static getFromPath(path, root) {
28
+ path = path.slice();
29
+ let item = root;
30
+ while (path.length > 0) {
31
+ const segment = path.shift();
32
+ if (item instanceof _CfgProductInternal) {
33
+ switch (segment) {
34
+ case "p": {
35
+ const refKey = path.shift();
36
+ const additional = item.additionalProducts.find((p) => p.refKey === refKey);
37
+ assertDefined(additional, `Additional product not found "p, ${refKey !== null && refKey !== void 0 ? refKey : ""}, ${path.join(", ")}"`);
38
+ item = additional._internal;
39
+ break;
40
+ }
41
+ case "c":
42
+ assert(item instanceof _CfgProductInternal, "Was not product");
43
+ item = item.configuration._internal;
44
+ break;
45
+ default:
46
+ throw new Error(`Unexpected path segment "${segment !== null && segment !== void 0 ? segment : ""}"`);
47
+ }
48
+ }
49
+ else if (item instanceof _CfgProductConfigurationInternal) {
50
+ const feature = item.features.find((f) => f.code === segment);
51
+ assertDefined(feature, `Feature not found "${segment !== null && segment !== void 0 ? segment : ""}", ${path.join(", ")}`);
52
+ item = feature._internal;
53
+ }
54
+ else if (item instanceof _CfgFeatureInternal) {
55
+ const option = item.options.find((o) => o.code === segment);
56
+ assertDefined(option, `Option not found "${segment !== null && segment !== void 0 ? segment : ""}", ${path.join(", ")}`);
57
+ item = option._internal;
58
+ }
59
+ else if (item instanceof _CfgOptionInternal) {
60
+ const feature = item.features.find((o) => o.code === segment);
61
+ assertDefined(feature, `Feature not found "${segment !== null && segment !== void 0 ? segment : ""}", ${path.join(", ")}`);
62
+ item = feature._internal;
63
+ }
64
+ else {
65
+ throw new Error("This should not happen (unexpected type)");
66
+ }
67
+ }
68
+ return item;
69
+ }
70
+ static getProductFromPath(path, item) {
71
+ const p = this.getFromPath(path, item);
72
+ assert(p instanceof _CfgProductInternal, `Path did not lead to a Product`);
73
+ return p;
74
+ }
75
+ static getProductConfigurationFromPath(path, item) {
76
+ const c = this.getFromPath(path, item);
77
+ assert(c instanceof _CfgProductConfigurationInternal, `Path did not lead to a ProductConfiguration"`);
78
+ return c;
79
+ }
80
+ static getFeatureFromPath(path, item) {
81
+ const f = this.getFromPath(path, item);
82
+ assert(f instanceof _CfgFeatureInternal, `Path did not lead to a Feature`);
83
+ return f;
84
+ }
85
+ static getOptionFromPath(path, item) {
86
+ const o = this.getFromPath(path, item);
87
+ assert(o instanceof _CfgOptionInternal, `Path did not lead to a Option`);
88
+ return o;
89
+ }
90
+ }
@@ -1,36 +1,40 @@
1
- import { OptionCode, SyncCode } from "./SyncGroupsHandler.js";
2
- /**
3
- * The SyncState is used to keep track of the current value of the SyncGroups.
4
- *
5
- * SelectOne and SelectMany uses fully separate states internally since the two types of features
6
- * are synced separately. See SyncGroupsHandler for details.
7
- */
8
- export declare class SyncGroupsState {
9
- private _verboseLogging;
10
- readonly _selectOne: Map<SyncCode, OptionCode>;
11
- readonly _selectMany: Map<SyncCode, Map<OptionCode, boolean>>;
12
- /**
13
- * @param verboseLogging Set to true to get verbose sync state changes logged to the console.
14
- */
15
- constructor(_verboseLogging: boolean);
16
- get verboseLogging(): boolean;
17
- /**
18
- * Set to true to get verbose sync state changes logged to the console.
19
- */
20
- set verboseLogging(v: boolean);
21
- /**
22
- * @returns a deep copy of the SyncGroupState.
23
- */
24
- clone(): SyncGroupsState;
25
- /**
26
- * Replaces the internal state of this SyncGroupState with a deep copy of the one in source.
27
- * @returns the updated SyncGroupState.
28
- */
29
- copyFrom(source: SyncGroupsState): SyncGroupsState;
30
- setForSelectOne(syncCode: SyncCode, optionCode: OptionCode): void;
31
- setForSelectMany(syncCode: SyncCode, optionCode: OptionCode, selected: boolean): void;
32
- getForSelectOne(syncCode: SyncCode): OptionCode | undefined;
33
- getForSelectMany(syncCode: SyncCode, optionCode: OptionCode): boolean | undefined;
34
- log(syncCode?: SyncCode, optionCode?: OptionCode, selected?: boolean): void;
35
- }
1
+ import { DtoSyncGroupState } from "../CatalogueAPI.js";
2
+ import { OptionCode, SyncCode } from "./SyncGroupsHandler.js";
3
+ /**
4
+ * The SyncState is used to keep track of the current value of the SyncGroups.
5
+ *
6
+ * SelectOne and SelectMany uses fully separate states internally since the two types of features
7
+ * are synced separately. See SyncGroupsHandler for details.
8
+ */
9
+ export declare class SyncGroupsState {
10
+ private _verboseLogging;
11
+ readonly _selectOne: Map<SyncCode, OptionCode>;
12
+ readonly _selectMany: Map<SyncCode, Map<OptionCode, boolean>>;
13
+ /**
14
+ * @param verboseLogging Set to true to get verbose sync state changes logged to the console.
15
+ */
16
+ constructor(_verboseLogging: boolean, initial: DtoSyncGroupState | undefined);
17
+ get verboseLogging(): boolean;
18
+ /**
19
+ * Set to true to get verbose sync state changes logged to the console.
20
+ */
21
+ set verboseLogging(v: boolean);
22
+ /**
23
+ * @returns a deep copy of the SyncGroupState.
24
+ */
25
+ clone(): SyncGroupsState;
26
+ /**
27
+ * Replaces the internal state of this SyncGroupState with a deep copy of the one in source.
28
+ * @returns the updated SyncGroupState.
29
+ */
30
+ copyFrom(source: SyncGroupsState): SyncGroupsState;
31
+ setForSelectOne(syncCode: SyncCode, optionCode: OptionCode): void;
32
+ setForSelectMany(syncCode: SyncCode, optionCode: OptionCode, selected: boolean): void;
33
+ getForSelectOne(syncCode: SyncCode): OptionCode | undefined;
34
+ getForSelectMany(syncCode: SyncCode, optionCode: OptionCode): boolean | undefined;
35
+ /** Overrides the current sync state */
36
+ setCompact(s: DtoSyncGroupState): void;
37
+ getCompact(): DtoSyncGroupState;
38
+ log(syncCode?: SyncCode, optionCode?: OptionCode, selected?: boolean): void;
39
+ }
36
40
  //# sourceMappingURL=SyncGroupsState.d.ts.map
@@ -1,125 +1,167 @@
1
- /**
2
- * The SyncState is used to keep track of the current value of the SyncGroups.
3
- *
4
- * SelectOne and SelectMany uses fully separate states internally since the two types of features
5
- * are synced separately. See SyncGroupsHandler for details.
6
- */
7
- export class SyncGroupsState {
8
- /**
9
- * @param verboseLogging Set to true to get verbose sync state changes logged to the console.
10
- */
11
- constructor(_verboseLogging) {
12
- this._verboseLogging = _verboseLogging;
13
- this._selectOne = new Map();
14
- this._selectMany = new Map();
15
- }
16
- get verboseLogging() {
17
- return this._verboseLogging;
18
- }
19
- /**
20
- * Set to true to get verbose sync state changes logged to the console.
21
- */
22
- set verboseLogging(v) {
23
- this._verboseLogging = v;
24
- }
25
- /**
26
- * @returns a deep copy of the SyncGroupState.
27
- */
28
- clone() {
29
- return new SyncGroupsState(this._verboseLogging).copyFrom(this);
30
- }
31
- /**
32
- * Replaces the internal state of this SyncGroupState with a deep copy of the one in source.
33
- * @returns the updated SyncGroupState.
34
- */
35
- copyFrom(source) {
36
- this._selectOne.clear();
37
- this._selectMany.clear();
38
- // The Exclude part below ensures that OptionCode is a defined as a primitive.
39
- // eslint-disable-next-line @typescript-eslint/ban-types
40
- let entryOne;
41
- for (entryOne of source._selectOne) {
42
- this._selectOne.set(...entryOne);
43
- }
44
- let entryMany;
45
- for (entryMany of source._selectMany) {
46
- this._selectMany.set(entryMany[0], new Map(entryMany[1]));
47
- }
48
- return this;
49
- }
50
- setForSelectOne(syncCode, optionCode) {
51
- this._selectOne.set(syncCode, optionCode);
52
- this.log(syncCode, optionCode);
53
- }
54
- setForSelectMany(syncCode, optionCode, selected) {
55
- let entry = this._selectMany.get(syncCode);
56
- if (entry === undefined) {
57
- entry = new Map();
58
- this._selectMany.set(syncCode, entry);
59
- }
60
- entry.set(optionCode, selected);
61
- this.log(syncCode, optionCode, selected);
62
- }
63
- getForSelectOne(syncCode) {
64
- return this._selectOne.get(syncCode);
65
- }
66
- getForSelectMany(syncCode, optionCode) {
67
- var _a;
68
- return (_a = this._selectMany.get(syncCode)) === null || _a === void 0 ? void 0 : _a.get(optionCode);
69
- }
70
- log(syncCode, optionCode, selected) {
71
- if (!this._verboseLogging) {
72
- return;
73
- }
74
- const isMany = selected !== undefined;
75
- const selectOne = Array.from(this._selectOne.entries());
76
- const selectMany = Array.from(this._selectMany.entries()).reduce((a, [groupCode, optionCodeToSelected]) => {
77
- for (const [optionCode, selected] of optionCodeToSelected) {
78
- a.push([groupCode, optionCode, selected]);
79
- }
80
- return a;
81
- }, []);
82
- let columnWidth = 1;
83
- selectOne.forEach((e) => {
84
- columnWidth = Math.max(columnWidth, e[0].length);
85
- });
86
- selectMany.forEach((e) => {
87
- columnWidth = Math.max(columnWidth, e[0].length);
88
- });
89
- const padding = Array(columnWidth).join(" ");
90
- const bold = "font-weight: bold";
91
- const styles = [];
92
- let msg = "";
93
- if (syncCode !== undefined && isMany) {
94
- msg += `%c${optionCode !== null && optionCode !== void 0 ? optionCode : ""}%c in %c${syncCode}%c set to %c${selected ? "on" : "off"}`;
95
- styles.push(bold, "", bold, "", bold);
96
- }
97
- else if (syncCode !== undefined && !isMany) {
98
- msg += `%c${syncCode}%c set to %c${optionCode !== null && optionCode !== void 0 ? optionCode : ""}`;
99
- styles.push(bold, "", bold);
100
- }
101
- msg += "\n\n%cSync State (single)";
102
- styles.push(bold);
103
- selectOne.forEach((e) => {
104
- const match = !isMany && syncCode === e[0];
105
- msg += `\n%c${match ? "*" : " "} ${(padding + e[0]).slice(-columnWidth)}: ${e[1]}`;
106
- styles.push(match ? bold : "");
107
- });
108
- if (selectOne.length === 0) {
109
- msg += "\n%c <Empty>";
110
- styles.push("");
111
- }
112
- msg += "\n\n%cSync State (multi)";
113
- styles.push(bold);
114
- selectMany.forEach((e) => {
115
- const match = isMany && syncCode === e[0] && optionCode === e[1];
116
- msg += `\n%c${match ? "*" : " "} ${(padding + e[0]).slice(-columnWidth)}: ${e[2] === true ? "\u2705" : "\u274c"} ${e[1]}`;
117
- styles.push(match ? bold : "");
118
- });
119
- if (selectMany.length === 0) {
120
- msg += "\n%c <Empty>";
121
- styles.push("");
122
- }
123
- console.log(msg, ...styles);
124
- }
125
- }
1
+ /**
2
+ * The SyncState is used to keep track of the current value of the SyncGroups.
3
+ *
4
+ * SelectOne and SelectMany uses fully separate states internally since the two types of features
5
+ * are synced separately. See SyncGroupsHandler for details.
6
+ */
7
+ export class SyncGroupsState {
8
+ /**
9
+ * @param verboseLogging Set to true to get verbose sync state changes logged to the console.
10
+ */
11
+ constructor(_verboseLogging, initial) {
12
+ this._verboseLogging = _verboseLogging;
13
+ this._selectOne = new Map();
14
+ this._selectMany = new Map();
15
+ this.setCompact(initial !== null && initial !== void 0 ? initial : {});
16
+ }
17
+ get verboseLogging() {
18
+ return this._verboseLogging;
19
+ }
20
+ /**
21
+ * Set to true to get verbose sync state changes logged to the console.
22
+ */
23
+ set verboseLogging(v) {
24
+ this._verboseLogging = v;
25
+ }
26
+ /**
27
+ * @returns a deep copy of the SyncGroupState.
28
+ */
29
+ clone() {
30
+ return new SyncGroupsState(this._verboseLogging, this.getCompact());
31
+ }
32
+ /**
33
+ * Replaces the internal state of this SyncGroupState with a deep copy of the one in source.
34
+ * @returns the updated SyncGroupState.
35
+ */
36
+ copyFrom(source) {
37
+ this._selectOne.clear();
38
+ this._selectMany.clear();
39
+ // The Exclude part below ensures that OptionCode is a defined as a primitive.
40
+ // eslint-disable-next-line @typescript-eslint/ban-types
41
+ let entryOne;
42
+ for (entryOne of source._selectOne) {
43
+ this._selectOne.set(...entryOne);
44
+ }
45
+ let entryMany;
46
+ for (entryMany of source._selectMany) {
47
+ this._selectMany.set(entryMany[0], new Map(entryMany[1]));
48
+ }
49
+ return this;
50
+ }
51
+ setForSelectOne(syncCode, optionCode) {
52
+ this._selectOne.set(syncCode, optionCode);
53
+ this.log(syncCode, optionCode);
54
+ }
55
+ setForSelectMany(syncCode, optionCode, selected) {
56
+ let entry = this._selectMany.get(syncCode);
57
+ if (entry === undefined) {
58
+ entry = new Map();
59
+ this._selectMany.set(syncCode, entry);
60
+ }
61
+ entry.set(optionCode, selected);
62
+ this.log(syncCode, optionCode, selected);
63
+ }
64
+ getForSelectOne(syncCode) {
65
+ return this._selectOne.get(syncCode);
66
+ }
67
+ getForSelectMany(syncCode, optionCode) {
68
+ var _a;
69
+ return (_a = this._selectMany.get(syncCode)) === null || _a === void 0 ? void 0 : _a.get(optionCode);
70
+ }
71
+ /** Overrides the current sync state */
72
+ setCompact(s) {
73
+ this._selectOne.clear();
74
+ this._selectMany.clear();
75
+ const { selectOne, selectMany } = s;
76
+ if (selectOne !== undefined) {
77
+ for (const { syncCode, optionCode } of selectOne) {
78
+ this._selectOne.set(syncCode, optionCode);
79
+ }
80
+ }
81
+ if (selectMany !== undefined) {
82
+ for (const { syncCode, optionCode, selected } of selectMany) {
83
+ let entry = this._selectMany.get(syncCode);
84
+ if (entry === undefined) {
85
+ entry = new Map();
86
+ this._selectMany.set(syncCode, entry);
87
+ }
88
+ entry.set(optionCode, selected);
89
+ }
90
+ }
91
+ }
92
+ getCompact() {
93
+ const result = {};
94
+ if (this._selectOne.size !== 0) {
95
+ const resultSelectOne = [];
96
+ for (const [syncCode, optionCode] of this._selectOne) {
97
+ resultSelectOne.push({ syncCode, optionCode });
98
+ }
99
+ result.selectOne = resultSelectOne;
100
+ }
101
+ if (this._selectMany.size !== 0) {
102
+ const resultSelectMany = [];
103
+ for (const [syncCode, optionCodeToSelected] of this._selectMany) {
104
+ for (const [optionCode, selected] of optionCodeToSelected) {
105
+ resultSelectMany.push({ syncCode, optionCode, selected });
106
+ }
107
+ }
108
+ result.selectMany = resultSelectMany;
109
+ }
110
+ return result;
111
+ }
112
+ log(syncCode, optionCode, selected) {
113
+ if (!this._verboseLogging) {
114
+ return;
115
+ }
116
+ const isMany = selected !== undefined;
117
+ const selectOne = Array.from(this._selectOne.entries());
118
+ const selectMany = Array.from(this._selectMany.entries()).reduce((a, [groupCode, optionCodeToSelected]) => {
119
+ for (const [optionCode, selected] of optionCodeToSelected) {
120
+ a.push([groupCode, optionCode, selected]);
121
+ }
122
+ return a;
123
+ }, []);
124
+ let columnWidth = 1;
125
+ selectOne.forEach((e) => {
126
+ columnWidth = Math.max(columnWidth, e[0].length);
127
+ });
128
+ selectMany.forEach((e) => {
129
+ columnWidth = Math.max(columnWidth, e[0].length);
130
+ });
131
+ const padding = Array(columnWidth).join(" ");
132
+ const bold = "font-weight: bold";
133
+ const styles = [];
134
+ let msg = "";
135
+ if (syncCode !== undefined && isMany) {
136
+ msg += `%c${optionCode !== null && optionCode !== void 0 ? optionCode : ""}%c in %c${syncCode}%c set to %c${selected ? "on" : "off"}`;
137
+ styles.push(bold, "", bold, "", bold);
138
+ }
139
+ else if (syncCode !== undefined && !isMany) {
140
+ msg += `%c${syncCode}%c set to %c${optionCode !== null && optionCode !== void 0 ? optionCode : ""}`;
141
+ styles.push(bold, "", bold);
142
+ }
143
+ msg += "\n\n%cSync State (single)";
144
+ styles.push(bold);
145
+ selectOne.forEach((e) => {
146
+ const match = !isMany && syncCode === e[0];
147
+ msg += `\n%c${match ? "*" : " "} ${(padding + e[0]).slice(-columnWidth)}: ${e[1]}`;
148
+ styles.push(match ? bold : "");
149
+ });
150
+ if (selectOne.length === 0) {
151
+ msg += "\n%c <Empty>";
152
+ styles.push("");
153
+ }
154
+ msg += "\n\n%cSync State (multi)";
155
+ styles.push(bold);
156
+ selectMany.forEach((e) => {
157
+ const match = isMany && syncCode === e[0] && optionCode === e[1];
158
+ msg += `\n%c${match ? "*" : " "} ${(padding + e[0]).slice(-columnWidth)}: ${e[2] === true ? "\u2705" : "\u274c"} ${e[1]}`;
159
+ styles.push(match ? bold : "");
160
+ });
161
+ if (selectMany.length === 0) {
162
+ msg += "\n%c <Empty>";
163
+ styles.push("");
164
+ }
165
+ console.log(msg, ...styles);
166
+ }
167
+ }