@configura/web-api 2.0.0-alpha.0 → 2.0.0-alpha.3

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 (98) hide show
  1. package/.eslintrc.json +18 -18
  2. package/LICENSE +201 -201
  3. package/README.md +1 -1
  4. package/dist/CatalogueAPI.d.ts +551 -551
  5. package/dist/CatalogueAPI.js +293 -293
  6. package/dist/CfgMeasure.d.ts +32 -32
  7. package/dist/CfgMeasure.js +30 -30
  8. package/dist/CfgProduct.d.ts +268 -268
  9. package/dist/CfgProduct.js +778 -778
  10. package/dist/CfgReferencePathHelper.d.ts +13 -13
  11. package/dist/CfgReferencePathHelper.js +13 -13
  12. package/dist/ConfigurationConverter.d.ts +4 -4
  13. package/dist/ConfigurationConverter.js +72 -72
  14. package/dist/index.d.ts +23 -23
  15. package/dist/index.js +23 -23
  16. package/dist/io/CfgHistoryManager.d.ts +50 -50
  17. package/dist/io/CfgHistoryManager.js +82 -82
  18. package/dist/io/CfgHistoryToProdConfConnector.d.ts +20 -20
  19. package/dist/io/CfgHistoryToProdConfConnector.js +56 -56
  20. package/dist/io/CfgIOManager.d.ts +48 -48
  21. package/dist/io/CfgIOManager.js +115 -115
  22. package/dist/io/CfgIOProdConfConnector.d.ts +52 -52
  23. package/dist/io/CfgIOProdConfConnector.js +141 -141
  24. package/dist/io/CfgObservableStateManager.d.ts +21 -21
  25. package/dist/io/CfgObservableStateManager.js +65 -65
  26. package/dist/io/CfgObservableStateToProdConfConnector.d.ts +14 -14
  27. package/dist/io/CfgObservableStateToProdConfConnector.js +16 -16
  28. package/dist/io/CfgWindowEventManager.d.ts +21 -21
  29. package/dist/io/CfgWindowEventManager.js +38 -38
  30. package/dist/io/CfgWindowMessageManager.d.ts +40 -40
  31. package/dist/io/CfgWindowMessageManager.js +84 -84
  32. package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +16 -16
  33. package/dist/io/CfgWindowMessageToProdConfConnector.js +18 -18
  34. package/dist/io/index.d.ts +8 -8
  35. package/dist/io/index.js +8 -8
  36. package/dist/material/CfgMaterialMapping.d.ts +7 -7
  37. package/dist/material/CfgMaterialMapping.js +181 -181
  38. package/dist/material/CfgMtrlApplication.d.ts +18 -18
  39. package/dist/material/CfgMtrlApplication.js +43 -43
  40. package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
  41. package/dist/material/CfgMtrlApplicationSource.js +8 -8
  42. package/dist/material/CfgMtrlSource.d.ts +19 -19
  43. package/dist/material/CfgMtrlSource.js +40 -40
  44. package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
  45. package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
  46. package/dist/productConfiguration/CfgFeature.d.ts +187 -187
  47. package/dist/productConfiguration/CfgFeature.js +645 -645
  48. package/dist/productConfiguration/CfgOption.d.ts +151 -151
  49. package/dist/productConfiguration/CfgOption.js +416 -416
  50. package/dist/productConfiguration/CfgProductConfiguration.d.ts +117 -117
  51. package/dist/productConfiguration/CfgProductConfiguration.js +307 -307
  52. package/dist/productConfiguration/filters.d.ts +15 -15
  53. package/dist/productConfiguration/filters.js +70 -70
  54. package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
  55. package/dist/productConfiguration/productParamsGenerator.js +51 -51
  56. package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
  57. package/dist/productConfiguration/utilitiesProductConfiguration.js +80 -80
  58. package/dist/productLoader.d.ts +33 -33
  59. package/dist/productLoader.js +49 -49
  60. package/dist/syncGroups/SyncGroupsApplyMode.d.ts +20 -20
  61. package/dist/syncGroups/SyncGroupsApplyMode.js +21 -21
  62. package/dist/syncGroups/SyncGroupsHandler.d.ts +40 -40
  63. package/dist/syncGroups/SyncGroupsHandler.js +359 -359
  64. package/dist/syncGroups/SyncGroupsPathHelper.d.ts +26 -26
  65. package/dist/syncGroups/SyncGroupsPathHelper.js +90 -90
  66. package/dist/syncGroups/SyncGroupsState.d.ts +35 -35
  67. package/dist/syncGroups/SyncGroupsState.js +125 -125
  68. package/dist/syncGroups/SyncGroupsTransaction.d.ts +154 -154
  69. package/dist/syncGroups/SyncGroupsTransaction.js +576 -576
  70. package/dist/tasks/TaskHandler.d.ts +77 -77
  71. package/dist/tasks/TaskHandler.js +275 -275
  72. package/dist/tasks/formats.d.ts +4 -4
  73. package/dist/tasks/formats.js +7 -7
  74. package/dist/tests/testData/collectorForTest.d.ts +73 -73
  75. package/dist/tests/testData/collectorForTest.js +194 -194
  76. package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
  77. package/dist/tests/testData/dummyProductForTest.js +32 -32
  78. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +11 -11
  79. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +277 -277
  80. package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
  81. package/dist/tests/testData/testDataCachedGetProduct.js +185 -185
  82. package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
  83. package/dist/tests/testData/testDataCachedPostValidate.js +183 -183
  84. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
  85. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1099 -1099
  86. package/dist/tests/testData/testDataOptions.d.ts +12 -12
  87. package/dist/tests/testData/testDataOptions.js +60 -60
  88. package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
  89. package/dist/tests/testData/testDataProductAggregatedPrice.js +187 -187
  90. package/dist/tests/testData/testDataUpcharge.d.ts +8 -8
  91. package/dist/tests/testData/testDataUpcharge.js +119 -119
  92. package/dist/utilitiesCatalogueData.d.ts +42 -33
  93. package/dist/utilitiesCatalogueData.js +173 -164
  94. package/dist/utilitiesCataloguePermission.d.ts +38 -32
  95. package/dist/utilitiesCataloguePermission.js +79 -76
  96. package/dist/utilitiesNumericValues.d.ts +24 -24
  97. package/dist/utilitiesNumericValues.js +109 -109
  98. package/package.json +3 -3
@@ -1,141 +1,141 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { convertDtoConfProdToV1 } from "../ConfigurationConverter.js";
11
- export var CfgProdConfMessageVersions;
12
- (function (CfgProdConfMessageVersions) {
13
- CfgProdConfMessageVersions[CfgProdConfMessageVersions["V1dot0"] = 1] = "V1dot0";
14
- CfgProdConfMessageVersions[CfgProdConfMessageVersions["V2dot0"] = 2] = "V2dot0";
15
- })(CfgProdConfMessageVersions || (CfgProdConfMessageVersions = {}));
16
- export const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
17
- /**
18
- * Base class for connecting the product configuration to an IO channel
19
- */
20
- export class CfgIOProdConfConnector {
21
- constructor(_ioManager, _doValidate, _sendVersions, _includeExtendedDataInSend, // Only v2.0
22
- _includeProdParamsInSend // Only v2.0
23
- ) {
24
- this._ioManager = _ioManager;
25
- this._doValidate = _doValidate;
26
- this._sendVersions = _sendVersions;
27
- this._includeExtendedDataInSend = _includeExtendedDataInSend;
28
- this._includeProdParamsInSend = _includeProdParamsInSend;
29
- this._stopListenToMessage = undefined;
30
- this._stopListenToProdConf = undefined;
31
- this.destroy = () => {
32
- var _a, _b;
33
- (_a = this._stopListenToMessage) === null || _a === void 0 ? void 0 : _a.call(this);
34
- (_b = this._stopListenToProdConf) === null || _b === void 0 ? void 0 : _b.call(this);
35
- };
36
- this.setProduct = (product) => __awaiter(this, void 0, void 0, function* () {
37
- var _a, _b;
38
- const currentProduct = this._product;
39
- const newProduct = product;
40
- this._product = newProduct;
41
- // If same product don't do anything at all
42
- if (currentProduct !== undefined &&
43
- newProduct !== undefined &&
44
- currentProduct.isBackedBySame(newProduct)) {
45
- return;
46
- }
47
- if (currentProduct !== undefined) {
48
- (_a = this._stopListenToMessage) === null || _a === void 0 ? void 0 : _a.call(this);
49
- (_b = this._stopListenToProdConf) === null || _b === void 0 ? void 0 : _b.call(this);
50
- }
51
- if (newProduct === undefined) {
52
- return;
53
- }
54
- // We only try to load initial configuration at first load
55
- if (currentProduct === undefined) {
56
- const initialProdConf = this.getInitialProdConf();
57
- if (initialProdConf !== undefined) {
58
- yield newProduct.setDtoConf(initialProdConf, this._doValidate);
59
- }
60
- }
61
- this._send(this.makeSendData(newProduct.getDtoConf(this._includeExtendedDataInSend, this._includeProdParamsInSend), true));
62
- this._stopListenToMessage = this.listenForMessage((messages) => __awaiter(this, void 0, void 0, function* () {
63
- const subMessages = messages.subMessages;
64
- if (subMessages.length === 0) {
65
- console.warn(`${STAGE_PROD_CONF_MESSAGE_KEY} message without any submessages. Unexpected.`);
66
- return;
67
- }
68
- const highestVersionMessage = subMessages
69
- .slice(1)
70
- .reduce((a, c) => (a.version < c.version ? c : a), subMessages[0]);
71
- switch (highestVersionMessage.version) {
72
- case "1.0":
73
- yield newProduct.setApiSelection(highestVersionMessage.conf, this._doValidate);
74
- return;
75
- case "2.0":
76
- yield newProduct.setDtoConf(highestVersionMessage.conf, this._doValidate);
77
- return;
78
- }
79
- throw new Error("Unknown message version");
80
- }));
81
- this._stopListenToProdConf = this.listenForProdConf(newProduct, (conf) => __awaiter(this, void 0, void 0, function* () { return this._send(this.makeSendData(conf, false)); }));
82
- });
83
- this._send = (data) => this._ioManager.send(STAGE_PROD_CONF_MESSAGE_KEY, data);
84
- }
85
- getInitialProdConf() {
86
- return undefined;
87
- }
88
- makeMessage(conf, initial) {
89
- const result = [];
90
- if ((this._sendVersions & CfgProdConfMessageVersions.V1dot0) ===
91
- CfgProdConfMessageVersions.V1dot0) {
92
- const v1 = {
93
- version: "1.0",
94
- conf: convertDtoConfProdToV1(conf, true),
95
- };
96
- result.push(v1);
97
- }
98
- if ((this._sendVersions & CfgProdConfMessageVersions.V2dot0) ===
99
- CfgProdConfMessageVersions.V2dot0) {
100
- const v2 = {
101
- version: "2.0",
102
- conf,
103
- };
104
- result.push(v2);
105
- }
106
- return { subMessages: result, initial };
107
- }
108
- makeMessageListener(callback) {
109
- return (message) => __awaiter(this, void 0, void 0, function* () {
110
- const prodConfMessage = message;
111
- yield callback(prodConfMessage);
112
- });
113
- }
114
- /**
115
- * Register the callback to listen for Product Configuration messages
116
- * @returns A function which when called will cancel listening
117
- */
118
- listenForMessage(callback) {
119
- const ioManager = this._ioManager;
120
- const listener = this.makeMessageListener(callback);
121
- ioManager.listenForMessage(listener, STAGE_PROD_CONF_MESSAGE_KEY);
122
- return () => {
123
- ioManager.stopListenForMessage(listener);
124
- };
125
- }
126
- makeProdConfListener(callback) {
127
- return (n) => {
128
- if (!n.committed) {
129
- return;
130
- }
131
- callback(n.freshRef.getDtoConf(this._includeExtendedDataInSend, this._includeProdParamsInSend));
132
- };
133
- }
134
- listenForProdConf(product, callback) {
135
- const listener = this.makeProdConfListener(callback);
136
- product.listenForChange(listener);
137
- return () => {
138
- product.stopListenForChange(listener);
139
- };
140
- }
141
- }
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { convertDtoConfProdToV1 } from "../ConfigurationConverter.js";
11
+ export var CfgProdConfMessageVersions;
12
+ (function (CfgProdConfMessageVersions) {
13
+ CfgProdConfMessageVersions[CfgProdConfMessageVersions["V1dot0"] = 1] = "V1dot0";
14
+ CfgProdConfMessageVersions[CfgProdConfMessageVersions["V2dot0"] = 2] = "V2dot0";
15
+ })(CfgProdConfMessageVersions || (CfgProdConfMessageVersions = {}));
16
+ export const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
17
+ /**
18
+ * Base class for connecting the product configuration to an IO channel
19
+ */
20
+ export class CfgIOProdConfConnector {
21
+ constructor(_ioManager, _doValidate, _sendVersions, _includeExtendedDataInSend, // Only v2.0
22
+ _includeProdParamsInSend // Only v2.0
23
+ ) {
24
+ this._ioManager = _ioManager;
25
+ this._doValidate = _doValidate;
26
+ this._sendVersions = _sendVersions;
27
+ this._includeExtendedDataInSend = _includeExtendedDataInSend;
28
+ this._includeProdParamsInSend = _includeProdParamsInSend;
29
+ this._stopListenToMessage = undefined;
30
+ this._stopListenToProdConf = undefined;
31
+ this.destroy = () => {
32
+ var _a, _b;
33
+ (_a = this._stopListenToMessage) === null || _a === void 0 ? void 0 : _a.call(this);
34
+ (_b = this._stopListenToProdConf) === null || _b === void 0 ? void 0 : _b.call(this);
35
+ };
36
+ this.setProduct = (product) => __awaiter(this, void 0, void 0, function* () {
37
+ var _a, _b;
38
+ const currentProduct = this._product;
39
+ const newProduct = product;
40
+ this._product = newProduct;
41
+ // If same product don't do anything at all
42
+ if (currentProduct !== undefined &&
43
+ newProduct !== undefined &&
44
+ currentProduct.isBackedBySame(newProduct)) {
45
+ return;
46
+ }
47
+ if (currentProduct !== undefined) {
48
+ (_a = this._stopListenToMessage) === null || _a === void 0 ? void 0 : _a.call(this);
49
+ (_b = this._stopListenToProdConf) === null || _b === void 0 ? void 0 : _b.call(this);
50
+ }
51
+ if (newProduct === undefined) {
52
+ return;
53
+ }
54
+ // We only try to load initial configuration at first load
55
+ if (currentProduct === undefined) {
56
+ const initialProdConf = this.getInitialProdConf();
57
+ if (initialProdConf !== undefined) {
58
+ yield newProduct.setDtoConf(initialProdConf, this._doValidate);
59
+ }
60
+ }
61
+ this._send(this.makeSendData(newProduct.getDtoConf(this._includeExtendedDataInSend, this._includeProdParamsInSend), true));
62
+ this._stopListenToMessage = this.listenForMessage((messages) => __awaiter(this, void 0, void 0, function* () {
63
+ const subMessages = messages.subMessages;
64
+ if (subMessages.length === 0) {
65
+ console.warn(`${STAGE_PROD_CONF_MESSAGE_KEY} message without any submessages. Unexpected.`);
66
+ return;
67
+ }
68
+ const highestVersionMessage = subMessages
69
+ .slice(1)
70
+ .reduce((a, c) => (a.version < c.version ? c : a), subMessages[0]);
71
+ switch (highestVersionMessage.version) {
72
+ case "1.0":
73
+ yield newProduct.setApiSelection(highestVersionMessage.conf, this._doValidate);
74
+ return;
75
+ case "2.0":
76
+ yield newProduct.setDtoConf(highestVersionMessage.conf, this._doValidate);
77
+ return;
78
+ }
79
+ throw new Error("Unknown message version");
80
+ }));
81
+ this._stopListenToProdConf = this.listenForProdConf(newProduct, (conf) => __awaiter(this, void 0, void 0, function* () { return this._send(this.makeSendData(conf, false)); }));
82
+ });
83
+ this._send = (data) => this._ioManager.send(STAGE_PROD_CONF_MESSAGE_KEY, data);
84
+ }
85
+ getInitialProdConf() {
86
+ return undefined;
87
+ }
88
+ makeMessage(conf, initial) {
89
+ const result = [];
90
+ if ((this._sendVersions & CfgProdConfMessageVersions.V1dot0) ===
91
+ CfgProdConfMessageVersions.V1dot0) {
92
+ const v1 = {
93
+ version: "1.0",
94
+ conf: convertDtoConfProdToV1(conf, true),
95
+ };
96
+ result.push(v1);
97
+ }
98
+ if ((this._sendVersions & CfgProdConfMessageVersions.V2dot0) ===
99
+ CfgProdConfMessageVersions.V2dot0) {
100
+ const v2 = {
101
+ version: "2.0",
102
+ conf,
103
+ };
104
+ result.push(v2);
105
+ }
106
+ return { subMessages: result, initial };
107
+ }
108
+ makeMessageListener(callback) {
109
+ return (message) => __awaiter(this, void 0, void 0, function* () {
110
+ const prodConfMessage = message;
111
+ yield callback(prodConfMessage);
112
+ });
113
+ }
114
+ /**
115
+ * Register the callback to listen for Product Configuration messages
116
+ * @returns A function which when called will cancel listening
117
+ */
118
+ listenForMessage(callback) {
119
+ const ioManager = this._ioManager;
120
+ const listener = this.makeMessageListener(callback);
121
+ ioManager.listenForMessage(listener, STAGE_PROD_CONF_MESSAGE_KEY);
122
+ return () => {
123
+ ioManager.stopListenForMessage(listener);
124
+ };
125
+ }
126
+ makeProdConfListener(callback) {
127
+ return (n) => {
128
+ if (!n.committed) {
129
+ return;
130
+ }
131
+ callback(n.freshRef.getDtoConf(this._includeExtendedDataInSend, this._includeProdParamsInSend));
132
+ };
133
+ }
134
+ listenForProdConf(product, callback) {
135
+ const listener = this.makeProdConfListener(callback);
136
+ product.listenForChange(listener);
137
+ return () => {
138
+ product.stopListenForChange(listener);
139
+ };
140
+ }
141
+ }
@@ -1,22 +1,22 @@
1
- import { Observable } from "@configura/web-utilities";
2
- import { CfgIOManager, IOManagerListener } from "./CfgIOManager.js";
3
- export declare class CfgObservableStateManager extends CfgIOManager<unknown> {
4
- private static _instance;
5
- static get instance(): CfgObservableStateManager;
6
- private constructor();
7
- readonly stateObservable: Observable<string>;
8
- private messagesState;
9
- get stateAsString(): string;
10
- set stateAsString(s: string);
11
- listenForStateChange(listener: (v: string) => void): void;
12
- stopListenForStateChange(listener: (v: string) => void): void;
13
- listenForMessage(l: IOManagerListener, messageKey: string): boolean;
14
- /**
15
- * Removes the listener
16
- */
17
- stopListenForMessage(l: IOManagerListener): boolean;
18
- private _stateListenerBound;
19
- private _stateListener;
20
- send(messageKey: string, data: unknown): void;
21
- }
1
+ import { Observable } from "@configura/web-utilities";
2
+ import { CfgIOManager, IOManagerListener } from "./CfgIOManager.js";
3
+ export declare class CfgObservableStateManager extends CfgIOManager<unknown> {
4
+ private static _instance;
5
+ static get instance(): CfgObservableStateManager;
6
+ private constructor();
7
+ readonly stateObservable: Observable<string>;
8
+ private messagesState;
9
+ get stateAsString(): string;
10
+ set stateAsString(s: string);
11
+ listenForStateChange(listener: (v: string) => void): void;
12
+ stopListenForStateChange(listener: (v: string) => void): void;
13
+ listenForMessage(l: IOManagerListener, messageKey: string): boolean;
14
+ /**
15
+ * Removes the listener
16
+ */
17
+ stopListenForMessage(l: IOManagerListener): boolean;
18
+ private _stateListenerBound;
19
+ private _stateListener;
20
+ send(messageKey: string, data: unknown): void;
21
+ }
22
22
  //# sourceMappingURL=CfgObservableStateManager.d.ts.map
@@ -1,65 +1,65 @@
1
- import { Observable } from "@configura/web-utilities";
2
- import { CfgIOManager } from "./CfgIOManager.js";
3
- export class CfgObservableStateManager extends CfgIOManager {
4
- constructor() {
5
- super();
6
- this.stateObservable = new Observable();
7
- this.messagesState = {};
8
- this._stateListenerBound = this._stateListener.bind(this);
9
- }
10
- static get instance() {
11
- if (this._instance === undefined) {
12
- this._instance = new CfgObservableStateManager();
13
- }
14
- return this._instance;
15
- }
16
- get stateAsString() {
17
- return JSON.stringify(CfgObservableStateManager.makeContainer(this.messagesState), null, 2);
18
- }
19
- set stateAsString(s) {
20
- this.stateObservable.notifyAll(s);
21
- }
22
- listenForStateChange(listener) {
23
- this.stateObservable.listen(listener);
24
- }
25
- stopListenForStateChange(listener) {
26
- this.stateObservable.stopListen(listener);
27
- }
28
- listenForMessage(l, messageKey) {
29
- const hadListeners = this.hasMessageListeners;
30
- const didStartListen = super.listenForMessage(l, messageKey);
31
- if (!hadListeners && didStartListen) {
32
- this.stateObservable.listen(this._stateListenerBound, this);
33
- }
34
- return didStartListen;
35
- }
36
- /**
37
- * Removes the listener
38
- */
39
- stopListenForMessage(l) {
40
- const didStopListen = super.stopListenForMessage(l);
41
- if (didStopListen && !this.hasMessageListeners) {
42
- this.stateObservable.stopListen(this._stateListenerBound);
43
- }
44
- return didStopListen;
45
- }
46
- _stateListener(data) {
47
- let asJson;
48
- try {
49
- asJson = JSON.parse(data);
50
- }
51
- catch (_a) {
52
- throw new Error("Not JSON data");
53
- }
54
- if (!CfgIOManager.isIOContainer(asJson)) {
55
- console.warn("Not a readable IO container");
56
- return;
57
- }
58
- this.messagesState = asJson.messages;
59
- super._containerListener(asJson);
60
- }
61
- send(messageKey, data) {
62
- this.messagesState[messageKey] = data;
63
- this.stateObservable.notifyAll(this.stateAsString, this);
64
- }
65
- }
1
+ import { Observable } from "@configura/web-utilities";
2
+ import { CfgIOManager } from "./CfgIOManager.js";
3
+ export class CfgObservableStateManager extends CfgIOManager {
4
+ constructor() {
5
+ super();
6
+ this.stateObservable = new Observable();
7
+ this.messagesState = {};
8
+ this._stateListenerBound = this._stateListener.bind(this);
9
+ }
10
+ static get instance() {
11
+ if (this._instance === undefined) {
12
+ this._instance = new CfgObservableStateManager();
13
+ }
14
+ return this._instance;
15
+ }
16
+ get stateAsString() {
17
+ return JSON.stringify(CfgObservableStateManager.makeContainer(this.messagesState), null, 2);
18
+ }
19
+ set stateAsString(s) {
20
+ this.stateObservable.notifyAll(s);
21
+ }
22
+ listenForStateChange(listener) {
23
+ this.stateObservable.listen(listener);
24
+ }
25
+ stopListenForStateChange(listener) {
26
+ this.stateObservable.stopListen(listener);
27
+ }
28
+ listenForMessage(l, messageKey) {
29
+ const hadListeners = this.hasMessageListeners;
30
+ const didStartListen = super.listenForMessage(l, messageKey);
31
+ if (!hadListeners && didStartListen) {
32
+ this.stateObservable.listen(this._stateListenerBound, this);
33
+ }
34
+ return didStartListen;
35
+ }
36
+ /**
37
+ * Removes the listener
38
+ */
39
+ stopListenForMessage(l) {
40
+ const didStopListen = super.stopListenForMessage(l);
41
+ if (didStopListen && !this.hasMessageListeners) {
42
+ this.stateObservable.stopListen(this._stateListenerBound);
43
+ }
44
+ return didStopListen;
45
+ }
46
+ _stateListener(data) {
47
+ let asJson;
48
+ try {
49
+ asJson = JSON.parse(data);
50
+ }
51
+ catch (_a) {
52
+ throw new Error("Not JSON data");
53
+ }
54
+ if (!CfgIOManager.isIOContainer(asJson)) {
55
+ console.warn("Not a readable IO container");
56
+ return;
57
+ }
58
+ this.messagesState = asJson.messages;
59
+ super._containerListener(asJson);
60
+ }
61
+ send(messageKey, data) {
62
+ this.messagesState[messageKey] = data;
63
+ this.stateObservable.notifyAll(this.stateAsString, this);
64
+ }
65
+ }
@@ -1,15 +1,15 @@
1
- import { DtoConfProd } from "../CatalogueAPI.js";
2
- import { CfgIOProdConfConnector, CfgProdConfMessage, CfgProdConfMessageVersions } from "./CfgIOProdConfConnector.js";
3
- import { CfgObservableStateManager } from "./CfgObservableStateManager.js";
4
- /**
5
- * Instantiating this will make the observable state update with the product configuration.
6
- * @param doValidate Run server side product validation for incoming
7
- * @param sendVersions What versions of the productConfiguration shall be sent? Multiple can be selected
8
- * @param includeExtendedDataInSend Only for version 2.0. Includes unit and groupCode.
9
- * @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
10
- */
11
- export declare class CfgObservableStateToProdConfConnector extends CfgIOProdConfConnector<CfgProdConfMessage> {
12
- constructor(manager: CfgObservableStateManager, doValidate?: boolean, sendVersions?: CfgProdConfMessageVersions, includeExtendedDataInSend?: boolean, includeProdParamsInSend?: boolean);
13
- protected makeSendData(conf: DtoConfProd, initial: boolean): CfgProdConfMessage;
14
- }
1
+ import { DtoConfProd } from "../CatalogueAPI.js";
2
+ import { CfgIOProdConfConnector, CfgProdConfMessage, CfgProdConfMessageVersions } from "./CfgIOProdConfConnector.js";
3
+ import { CfgObservableStateManager } from "./CfgObservableStateManager.js";
4
+ /**
5
+ * Instantiating this will make the observable state update with the product configuration.
6
+ * @param doValidate Run server side product validation for incoming
7
+ * @param sendVersions What versions of the productConfiguration shall be sent? Multiple can be selected
8
+ * @param includeExtendedDataInSend Only for version 2.0. Includes unit and groupCode.
9
+ * @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
10
+ */
11
+ export declare class CfgObservableStateToProdConfConnector extends CfgIOProdConfConnector<CfgProdConfMessage> {
12
+ constructor(manager: CfgObservableStateManager, doValidate?: boolean, sendVersions?: CfgProdConfMessageVersions, includeExtendedDataInSend?: boolean, includeProdParamsInSend?: boolean);
13
+ protected makeSendData(conf: DtoConfProd, initial: boolean): CfgProdConfMessage;
14
+ }
15
15
  //# sourceMappingURL=CfgObservableStateToProdConfConnector.d.ts.map
@@ -1,16 +1,16 @@
1
- import { CfgIOProdConfConnector, CfgProdConfMessageVersions, } from "./CfgIOProdConfConnector.js";
2
- /**
3
- * Instantiating this will make the observable state update with the product configuration.
4
- * @param doValidate Run server side product validation for incoming
5
- * @param sendVersions What versions of the productConfiguration shall be sent? Multiple can be selected
6
- * @param includeExtendedDataInSend Only for version 2.0. Includes unit and groupCode.
7
- * @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
8
- */
9
- export class CfgObservableStateToProdConfConnector extends CfgIOProdConfConnector {
10
- constructor(manager, doValidate = true, sendVersions = CfgProdConfMessageVersions.V2dot0, includeExtendedDataInSend = false, includeProdParamsInSend = false) {
11
- super(manager, doValidate, sendVersions, includeExtendedDataInSend, includeProdParamsInSend);
12
- }
13
- makeSendData(conf, initial) {
14
- return this.makeMessage(conf, initial);
15
- }
16
- }
1
+ import { CfgIOProdConfConnector, CfgProdConfMessageVersions, } from "./CfgIOProdConfConnector.js";
2
+ /**
3
+ * Instantiating this will make the observable state update with the product configuration.
4
+ * @param doValidate Run server side product validation for incoming
5
+ * @param sendVersions What versions of the productConfiguration shall be sent? Multiple can be selected
6
+ * @param includeExtendedDataInSend Only for version 2.0. Includes unit and groupCode.
7
+ * @param includeProdParamsInSend Only for version 2.0. Includes product params, in both main and additional products.
8
+ */
9
+ export class CfgObservableStateToProdConfConnector extends CfgIOProdConfConnector {
10
+ constructor(manager, doValidate = true, sendVersions = CfgProdConfMessageVersions.V2dot0, includeExtendedDataInSend = false, includeProdParamsInSend = false) {
11
+ super(manager, doValidate, sendVersions, includeExtendedDataInSend, includeProdParamsInSend);
12
+ }
13
+ makeSendData(conf, initial) {
14
+ return this.makeMessage(conf, initial);
15
+ }
16
+ }
@@ -1,22 +1,22 @@
1
- import { CfgIOManager, IOManagerListener } from "./CfgIOManager.js";
2
- /**
3
- * Base class for classes handling input and output in globally shared environments, using
4
- * event listeners on the window object, for example the History API and window.message API.
5
- * These are global resources where data not being handled by Stage can appear.
6
- */
7
- export declare abstract class CfgWindowEventManager<K extends keyof WindowEventMap, S> extends CfgIOManager<S> {
8
- /**
9
- * Listen for the message messageKey being received. This can for example be the history stack
10
- * being popped or a window.message being received.
11
- */
12
- listenForMessage(l: IOManagerListener, messageKey: string): boolean;
13
- /**
14
- * Removes the listener
15
- */
16
- stopListenForMessage(l: IOManagerListener): boolean;
17
- private _windowEventListenerBound;
18
- private _windowEventListener;
19
- protected abstract readonly eventType: K;
20
- protected abstract getDataFromEvent(event: WindowEventMap[K]): unknown;
21
- }
1
+ import { CfgIOManager, IOManagerListener } from "./CfgIOManager.js";
2
+ /**
3
+ * Base class for classes handling input and output in globally shared environments, using
4
+ * event listeners on the window object, for example the History API and window.message API.
5
+ * These are global resources where data not being handled by Stage can appear.
6
+ */
7
+ export declare abstract class CfgWindowEventManager<K extends keyof WindowEventMap, S> extends CfgIOManager<S> {
8
+ /**
9
+ * Listen for the message messageKey being received. This can for example be the history stack
10
+ * being popped or a window.message being received.
11
+ */
12
+ listenForMessage(l: IOManagerListener, messageKey: string): boolean;
13
+ /**
14
+ * Removes the listener
15
+ */
16
+ stopListenForMessage(l: IOManagerListener): boolean;
17
+ private _windowEventListenerBound;
18
+ private _windowEventListener;
19
+ protected abstract readonly eventType: K;
20
+ protected abstract getDataFromEvent(event: WindowEventMap[K]): unknown;
21
+ }
22
22
  //# sourceMappingURL=CfgWindowEventManager.d.ts.map
@@ -1,38 +1,38 @@
1
- import { CfgIOManager } from "./CfgIOManager.js";
2
- /**
3
- * Base class for classes handling input and output in globally shared environments, using
4
- * event listeners on the window object, for example the History API and window.message API.
5
- * These are global resources where data not being handled by Stage can appear.
6
- */
7
- export class CfgWindowEventManager extends CfgIOManager {
8
- constructor() {
9
- super(...arguments);
10
- this._windowEventListenerBound = this._windowEventListener.bind(this);
11
- }
12
- /**
13
- * Listen for the message messageKey being received. This can for example be the history stack
14
- * being popped or a window.message being received.
15
- */
16
- listenForMessage(l, messageKey) {
17
- const hadListeners = this.hasMessageListeners;
18
- const didStartListen = super.listenForMessage(l, messageKey);
19
- if (!hadListeners && didStartListen) {
20
- window.addEventListener(this.eventType, this._windowEventListenerBound);
21
- }
22
- return didStartListen;
23
- }
24
- /**
25
- * Removes the listener
26
- */
27
- stopListenForMessage(l) {
28
- const didStopListen = super.stopListenForMessage(l);
29
- if (didStopListen && !this.hasMessageListeners) {
30
- window.removeEventListener(this.eventType, this._windowEventListenerBound);
31
- }
32
- return didStopListen;
33
- }
34
- _windowEventListener(event) {
35
- const data = this.getDataFromEvent(event);
36
- super._containerListener(data);
37
- }
38
- }
1
+ import { CfgIOManager } from "./CfgIOManager.js";
2
+ /**
3
+ * Base class for classes handling input and output in globally shared environments, using
4
+ * event listeners on the window object, for example the History API and window.message API.
5
+ * These are global resources where data not being handled by Stage can appear.
6
+ */
7
+ export class CfgWindowEventManager extends CfgIOManager {
8
+ constructor() {
9
+ super(...arguments);
10
+ this._windowEventListenerBound = this._windowEventListener.bind(this);
11
+ }
12
+ /**
13
+ * Listen for the message messageKey being received. This can for example be the history stack
14
+ * being popped or a window.message being received.
15
+ */
16
+ listenForMessage(l, messageKey) {
17
+ const hadListeners = this.hasMessageListeners;
18
+ const didStartListen = super.listenForMessage(l, messageKey);
19
+ if (!hadListeners && didStartListen) {
20
+ window.addEventListener(this.eventType, this._windowEventListenerBound);
21
+ }
22
+ return didStartListen;
23
+ }
24
+ /**
25
+ * Removes the listener
26
+ */
27
+ stopListenForMessage(l) {
28
+ const didStopListen = super.stopListenForMessage(l);
29
+ if (didStopListen && !this.hasMessageListeners) {
30
+ window.removeEventListener(this.eventType, this._windowEventListenerBound);
31
+ }
32
+ return didStopListen;
33
+ }
34
+ _windowEventListener(event) {
35
+ const data = this.getDataFromEvent(event);
36
+ super._containerListener(data);
37
+ }
38
+ }