@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.
- package/.eslintrc.json +18 -18
- package/LICENSE +201 -201
- package/README.md +1 -1
- package/dist/CatalogueAPI.d.ts +551 -551
- package/dist/CatalogueAPI.js +293 -293
- package/dist/CfgMeasure.d.ts +32 -32
- package/dist/CfgMeasure.js +30 -30
- package/dist/CfgProduct.d.ts +268 -268
- package/dist/CfgProduct.js +778 -778
- package/dist/CfgReferencePathHelper.d.ts +13 -13
- package/dist/CfgReferencePathHelper.js +13 -13
- package/dist/ConfigurationConverter.d.ts +4 -4
- package/dist/ConfigurationConverter.js +72 -72
- package/dist/index.d.ts +23 -23
- package/dist/index.js +23 -23
- package/dist/io/CfgHistoryManager.d.ts +50 -50
- package/dist/io/CfgHistoryManager.js +82 -82
- package/dist/io/CfgHistoryToProdConfConnector.d.ts +20 -20
- package/dist/io/CfgHistoryToProdConfConnector.js +56 -56
- package/dist/io/CfgIOManager.d.ts +48 -48
- package/dist/io/CfgIOManager.js +115 -115
- package/dist/io/CfgIOProdConfConnector.d.ts +52 -52
- package/dist/io/CfgIOProdConfConnector.js +141 -141
- package/dist/io/CfgObservableStateManager.d.ts +21 -21
- package/dist/io/CfgObservableStateManager.js +65 -65
- package/dist/io/CfgObservableStateToProdConfConnector.d.ts +14 -14
- package/dist/io/CfgObservableStateToProdConfConnector.js +16 -16
- package/dist/io/CfgWindowEventManager.d.ts +21 -21
- package/dist/io/CfgWindowEventManager.js +38 -38
- package/dist/io/CfgWindowMessageManager.d.ts +40 -40
- package/dist/io/CfgWindowMessageManager.js +84 -84
- package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +16 -16
- package/dist/io/CfgWindowMessageToProdConfConnector.js +18 -18
- package/dist/io/index.d.ts +8 -8
- package/dist/io/index.js +8 -8
- package/dist/material/CfgMaterialMapping.d.ts +7 -7
- package/dist/material/CfgMaterialMapping.js +181 -181
- package/dist/material/CfgMtrlApplication.d.ts +18 -18
- package/dist/material/CfgMtrlApplication.js +43 -43
- package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
- package/dist/material/CfgMtrlApplicationSource.js +8 -8
- package/dist/material/CfgMtrlSource.d.ts +19 -19
- package/dist/material/CfgMtrlSource.js +40 -40
- package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
- package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
- package/dist/productConfiguration/CfgFeature.d.ts +187 -187
- package/dist/productConfiguration/CfgFeature.js +645 -645
- package/dist/productConfiguration/CfgOption.d.ts +151 -151
- package/dist/productConfiguration/CfgOption.js +416 -416
- package/dist/productConfiguration/CfgProductConfiguration.d.ts +117 -117
- package/dist/productConfiguration/CfgProductConfiguration.js +307 -307
- package/dist/productConfiguration/filters.d.ts +15 -15
- package/dist/productConfiguration/filters.js +70 -70
- package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
- package/dist/productConfiguration/productParamsGenerator.js +51 -51
- package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
- package/dist/productConfiguration/utilitiesProductConfiguration.js +80 -80
- package/dist/productLoader.d.ts +33 -33
- package/dist/productLoader.js +49 -49
- package/dist/syncGroups/SyncGroupsApplyMode.d.ts +20 -20
- package/dist/syncGroups/SyncGroupsApplyMode.js +21 -21
- package/dist/syncGroups/SyncGroupsHandler.d.ts +40 -40
- package/dist/syncGroups/SyncGroupsHandler.js +359 -359
- package/dist/syncGroups/SyncGroupsPathHelper.d.ts +26 -26
- package/dist/syncGroups/SyncGroupsPathHelper.js +90 -90
- package/dist/syncGroups/SyncGroupsState.d.ts +35 -35
- package/dist/syncGroups/SyncGroupsState.js +125 -125
- package/dist/syncGroups/SyncGroupsTransaction.d.ts +154 -154
- package/dist/syncGroups/SyncGroupsTransaction.js +576 -576
- package/dist/tasks/TaskHandler.d.ts +77 -77
- package/dist/tasks/TaskHandler.js +275 -275
- package/dist/tasks/formats.d.ts +4 -4
- package/dist/tasks/formats.js +7 -7
- package/dist/tests/testData/collectorForTest.d.ts +73 -73
- package/dist/tests/testData/collectorForTest.js +194 -194
- package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
- package/dist/tests/testData/dummyProductForTest.js +32 -32
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +11 -11
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +277 -277
- package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
- package/dist/tests/testData/testDataCachedGetProduct.js +185 -185
- package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
- package/dist/tests/testData/testDataCachedPostValidate.js +183 -183
- package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
- package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1099 -1099
- package/dist/tests/testData/testDataOptions.d.ts +12 -12
- package/dist/tests/testData/testDataOptions.js +60 -60
- package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
- package/dist/tests/testData/testDataProductAggregatedPrice.js +187 -187
- package/dist/tests/testData/testDataUpcharge.d.ts +8 -8
- package/dist/tests/testData/testDataUpcharge.js +119 -119
- package/dist/utilitiesCatalogueData.d.ts +42 -33
- package/dist/utilitiesCatalogueData.js +173 -164
- package/dist/utilitiesCataloguePermission.d.ts +38 -32
- package/dist/utilitiesCataloguePermission.js +79 -76
- package/dist/utilitiesNumericValues.d.ts +24 -24
- package/dist/utilitiesNumericValues.js +109 -109
- package/package.json +3 -3
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { CfgHistoryManager } from "./CfgHistoryManager.js";
|
|
2
|
-
import { CfgIOProdConfConnector, CfgProdConfMessageVersions, STAGE_PROD_CONF_MESSAGE_KEY, } from "./CfgIOProdConfConnector.js";
|
|
3
|
-
const jsonKeyRegex = /"([^"]+)":/g;
|
|
4
|
-
const keyMap = [
|
|
5
|
-
["configuration", "cn"],
|
|
6
|
-
["additionalProducts", "as"],
|
|
7
|
-
["prodParams", "pp"],
|
|
8
|
-
["refKey", "rk"],
|
|
9
|
-
["selected", "se"],
|
|
10
|
-
["features", "fs"],
|
|
11
|
-
["code", "cd"],
|
|
12
|
-
["options", "os"],
|
|
13
|
-
["numericValue", "nu"],
|
|
14
|
-
["groupCode", "gc"],
|
|
15
|
-
["unit", "un"],
|
|
16
|
-
];
|
|
17
|
-
// todo: Could be worth making faster
|
|
18
|
-
const toCompact = (key) => { var _a, _b; return (_b = (_a = keyMap.find((i) => i[0] === key)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : key; };
|
|
19
|
-
const toExpanded = (key) => { var _a, _b; return (_b = (_a = keyMap.find((i) => i[1] === key)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : key; };
|
|
20
|
-
export function dtoConfToString(conf) {
|
|
21
|
-
const stringified = JSON.stringify(conf, undefined, "");
|
|
22
|
-
return stringified.replace(jsonKeyRegex, (_, key) => `"${toCompact(key)}":`);
|
|
23
|
-
}
|
|
24
|
-
export function stringToDtoConf(conf) {
|
|
25
|
-
const expandedKeys = conf.replace(jsonKeyRegex, (_, key) => `"${toExpanded(key)}":`);
|
|
26
|
-
return JSON.parse(expandedKeys);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
30
|
-
*/
|
|
31
|
-
export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
|
|
32
|
-
/**
|
|
33
|
-
* @param _useHistoryPush As opposed to replace. Push makes the web browser navigation buttons navigate configuration changes. Replace just updates the URL.
|
|
34
|
-
* @param _qsKey The Query String key for product configuration.
|
|
35
|
-
* @param doValidate When popping from the history stack (navigating in the browser), should a navigate call be sent to the server to verify that the product configuration is still valid?
|
|
36
|
-
*/
|
|
37
|
-
constructor(manager, _useHistoryPush, _qsKey = STAGE_PROD_CONF_MESSAGE_KEY, doValidate = true) {
|
|
38
|
-
super(manager, doValidate, CfgProdConfMessageVersions.V2dot0, false, false);
|
|
39
|
-
this._useHistoryPush = _useHistoryPush;
|
|
40
|
-
this._qsKey = _qsKey;
|
|
41
|
-
}
|
|
42
|
-
getInitialProdConf() {
|
|
43
|
-
const s = CfgHistoryManager.currentQsKeyValues().get(this._qsKey);
|
|
44
|
-
if (s === undefined) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
return stringToDtoConf(s);
|
|
48
|
-
}
|
|
49
|
-
makeSendData(conf, initial) {
|
|
50
|
-
return {
|
|
51
|
-
message: this.makeMessage(conf, initial),
|
|
52
|
-
qsKeyValues: new Map([[STAGE_PROD_CONF_MESSAGE_KEY, dtoConfToString(conf)]]),
|
|
53
|
-
useHistoryPush: this._useHistoryPush,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
import { CfgHistoryManager } from "./CfgHistoryManager.js";
|
|
2
|
+
import { CfgIOProdConfConnector, CfgProdConfMessageVersions, STAGE_PROD_CONF_MESSAGE_KEY, } from "./CfgIOProdConfConnector.js";
|
|
3
|
+
const jsonKeyRegex = /"([^"]+)":/g;
|
|
4
|
+
const keyMap = [
|
|
5
|
+
["configuration", "cn"],
|
|
6
|
+
["additionalProducts", "as"],
|
|
7
|
+
["prodParams", "pp"],
|
|
8
|
+
["refKey", "rk"],
|
|
9
|
+
["selected", "se"],
|
|
10
|
+
["features", "fs"],
|
|
11
|
+
["code", "cd"],
|
|
12
|
+
["options", "os"],
|
|
13
|
+
["numericValue", "nu"],
|
|
14
|
+
["groupCode", "gc"],
|
|
15
|
+
["unit", "un"],
|
|
16
|
+
];
|
|
17
|
+
// todo: Could be worth making faster
|
|
18
|
+
const toCompact = (key) => { var _a, _b; return (_b = (_a = keyMap.find((i) => i[0] === key)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : key; };
|
|
19
|
+
const toExpanded = (key) => { var _a, _b; return (_b = (_a = keyMap.find((i) => i[1] === key)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : key; };
|
|
20
|
+
export function dtoConfToString(conf) {
|
|
21
|
+
const stringified = JSON.stringify(conf, undefined, "");
|
|
22
|
+
return stringified.replace(jsonKeyRegex, (_, key) => `"${toCompact(key)}":`);
|
|
23
|
+
}
|
|
24
|
+
export function stringToDtoConf(conf) {
|
|
25
|
+
const expandedKeys = conf.replace(jsonKeyRegex, (_, key) => `"${toExpanded(key)}":`);
|
|
26
|
+
return JSON.parse(expandedKeys);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
30
|
+
*/
|
|
31
|
+
export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
|
|
32
|
+
/**
|
|
33
|
+
* @param _useHistoryPush As opposed to replace. Push makes the web browser navigation buttons navigate configuration changes. Replace just updates the URL.
|
|
34
|
+
* @param _qsKey The Query String key for product configuration.
|
|
35
|
+
* @param doValidate When popping from the history stack (navigating in the browser), should a navigate call be sent to the server to verify that the product configuration is still valid?
|
|
36
|
+
*/
|
|
37
|
+
constructor(manager, _useHistoryPush, _qsKey = STAGE_PROD_CONF_MESSAGE_KEY, doValidate = true) {
|
|
38
|
+
super(manager, doValidate, CfgProdConfMessageVersions.V2dot0, false, false);
|
|
39
|
+
this._useHistoryPush = _useHistoryPush;
|
|
40
|
+
this._qsKey = _qsKey;
|
|
41
|
+
}
|
|
42
|
+
getInitialProdConf() {
|
|
43
|
+
const s = CfgHistoryManager.currentQsKeyValues().get(this._qsKey);
|
|
44
|
+
if (s === undefined) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
return stringToDtoConf(s);
|
|
48
|
+
}
|
|
49
|
+
makeSendData(conf, initial) {
|
|
50
|
+
return {
|
|
51
|
+
message: this.makeMessage(conf, initial),
|
|
52
|
+
qsKeyValues: new Map([[STAGE_PROD_CONF_MESSAGE_KEY, dtoConfToString(conf)]]),
|
|
53
|
+
useHistoryPush: this._useHistoryPush,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
declare type ConfiguraAttribute = "C0nf1gura";
|
|
2
|
-
declare type ConfiguraShebang = "arug1fn0C";
|
|
3
|
-
declare const CONFIGURA_ATTRIBUTE: ConfiguraAttribute;
|
|
4
|
-
export declare type IOManagerListener = (data: unknown) => Promise<void>;
|
|
5
|
-
/**
|
|
6
|
-
* The container format used when the environment is globally shared with things
|
|
7
|
-
* outside our control. The "shebang" is a magic string that should prevent from a
|
|
8
|
-
* CfgIOContainer being confused with something else.
|
|
9
|
-
*/
|
|
10
|
-
export declare type CfgIOContainer = {
|
|
11
|
-
[CONFIGURA_ATTRIBUTE]: ConfiguraShebang;
|
|
12
|
-
messages: {
|
|
13
|
-
[index: string]: unknown;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Base class for classes handling input and output in globally shared environments.
|
|
18
|
-
*/
|
|
19
|
-
export declare abstract class CfgIOManager<S> {
|
|
20
|
-
/**
|
|
21
|
-
* Listen for the message messageKey being received.
|
|
22
|
-
*/
|
|
23
|
-
listenForMessage(l: IOManagerListener, messageKey: string): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Removes the listener
|
|
26
|
-
*/
|
|
27
|
-
stopListenForMessage(l: IOManagerListener): boolean;
|
|
28
|
-
static isIOContainer: (data: unknown) => data is CfgIOContainer;
|
|
29
|
-
static hasIOContainerMessageKey: (container: CfgIOContainer, messageKey: string) => boolean;
|
|
30
|
-
static getMessageFromIOContainer: (container: unknown, messageKey: string) => unknown;
|
|
31
|
-
static makeContainer: (messages: {
|
|
32
|
-
[index: string]: unknown;
|
|
33
|
-
}) => CfgIOContainer;
|
|
34
|
-
private _receiveInProgress;
|
|
35
|
-
private static _inhibitAllReceive;
|
|
36
|
-
get receiveInProgress(): boolean;
|
|
37
|
-
private _messageListeners;
|
|
38
|
-
private _getIndexOfMessageListener;
|
|
39
|
-
get hasMessageListeners(): boolean;
|
|
40
|
-
protected _containerListener(data: unknown): void;
|
|
41
|
-
/**
|
|
42
|
-
* Send the data with messageKey. This can for example be pushing or
|
|
43
|
-
* replacing on the history stack or sending a message using the
|
|
44
|
-
* window.message API.
|
|
45
|
-
*/
|
|
46
|
-
abstract send(messageKey: string, data: S): void;
|
|
47
|
-
}
|
|
48
|
-
export {};
|
|
1
|
+
declare type ConfiguraAttribute = "C0nf1gura";
|
|
2
|
+
declare type ConfiguraShebang = "arug1fn0C";
|
|
3
|
+
declare const CONFIGURA_ATTRIBUTE: ConfiguraAttribute;
|
|
4
|
+
export declare type IOManagerListener = (data: unknown) => Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* The container format used when the environment is globally shared with things
|
|
7
|
+
* outside our control. The "shebang" is a magic string that should prevent from a
|
|
8
|
+
* CfgIOContainer being confused with something else.
|
|
9
|
+
*/
|
|
10
|
+
export declare type CfgIOContainer = {
|
|
11
|
+
[CONFIGURA_ATTRIBUTE]: ConfiguraShebang;
|
|
12
|
+
messages: {
|
|
13
|
+
[index: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Base class for classes handling input and output in globally shared environments.
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class CfgIOManager<S> {
|
|
20
|
+
/**
|
|
21
|
+
* Listen for the message messageKey being received.
|
|
22
|
+
*/
|
|
23
|
+
listenForMessage(l: IOManagerListener, messageKey: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Removes the listener
|
|
26
|
+
*/
|
|
27
|
+
stopListenForMessage(l: IOManagerListener): boolean;
|
|
28
|
+
static isIOContainer: (data: unknown) => data is CfgIOContainer;
|
|
29
|
+
static hasIOContainerMessageKey: (container: CfgIOContainer, messageKey: string) => boolean;
|
|
30
|
+
static getMessageFromIOContainer: (container: unknown, messageKey: string) => unknown;
|
|
31
|
+
static makeContainer: (messages: {
|
|
32
|
+
[index: string]: unknown;
|
|
33
|
+
}) => CfgIOContainer;
|
|
34
|
+
private _receiveInProgress;
|
|
35
|
+
private static _inhibitAllReceive;
|
|
36
|
+
get receiveInProgress(): boolean;
|
|
37
|
+
private _messageListeners;
|
|
38
|
+
private _getIndexOfMessageListener;
|
|
39
|
+
get hasMessageListeners(): boolean;
|
|
40
|
+
protected _containerListener(data: unknown): void;
|
|
41
|
+
/**
|
|
42
|
+
* Send the data with messageKey. This can for example be pushing or
|
|
43
|
+
* replacing on the history stack or sending a message using the
|
|
44
|
+
* window.message API.
|
|
45
|
+
*/
|
|
46
|
+
abstract send(messageKey: string, data: S): void;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
49
49
|
//# sourceMappingURL=CfgIOManager.d.ts.map
|
package/dist/io/CfgIOManager.js
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
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
|
-
const CONFIGURA_ATTRIBUTE = "C0nf1gura";
|
|
11
|
-
const CONFIGURA_SHEBANG = "arug1fn0C";
|
|
12
|
-
// Support function. Did not manage to check both attribute and value in one step
|
|
13
|
-
const hasConfiguraAttribute = (data) => {
|
|
14
|
-
return typeof data === "object" && data !== null;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Base class for classes handling input and output in globally shared environments.
|
|
18
|
-
*/
|
|
19
|
-
export class CfgIOManager {
|
|
20
|
-
constructor() {
|
|
21
|
-
// A lock to avoid circular write. Asynchronous conditions can make this not be enough.
|
|
22
|
-
// Avoid creating pre-conditions where this can happen.
|
|
23
|
-
this._receiveInProgress = false;
|
|
24
|
-
this._messageListeners = [];
|
|
25
|
-
this._getIndexOfMessageListener = (l) => this._messageListeners.findIndex((item) => l === item.l);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Listen for the message messageKey being received.
|
|
29
|
-
*/
|
|
30
|
-
listenForMessage(l, messageKey) {
|
|
31
|
-
if (this._getIndexOfMessageListener(l) !== -1) {
|
|
32
|
-
console.warn("Tried to add listener twice");
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
this._messageListeners.push({ l, messageKey });
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Removes the listener
|
|
40
|
-
*/
|
|
41
|
-
stopListenForMessage(l) {
|
|
42
|
-
const i = this._getIndexOfMessageListener(l);
|
|
43
|
-
if (i === -1) {
|
|
44
|
-
console.warn("Tried to stopListen on unknown listener");
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
this._messageListeners.splice(i, 1);
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
get receiveInProgress() {
|
|
51
|
-
return this._receiveInProgress;
|
|
52
|
-
}
|
|
53
|
-
get hasMessageListeners() {
|
|
54
|
-
return 0 < this._messageListeners.length;
|
|
55
|
-
}
|
|
56
|
-
_containerListener(data) {
|
|
57
|
-
if (CfgIOManager._inhibitAllReceive) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (!CfgIOManager.isIOContainer(data)) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
CfgIOManager._inhibitAllReceive = true;
|
|
64
|
-
this._receiveInProgress = true;
|
|
65
|
-
// The 15 or so rows below is one of the cases where I believe building a clever
|
|
66
|
-
// data structure of so would probably be worse for performance than just looping
|
|
67
|
-
// as the subscribers are expected to be very few
|
|
68
|
-
const listeners = this._messageListeners;
|
|
69
|
-
const allMessageKeys = listeners.reduce((a, c) => {
|
|
70
|
-
a.add(c.messageKey);
|
|
71
|
-
return a;
|
|
72
|
-
}, new Set());
|
|
73
|
-
const promises = [];
|
|
74
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
for (const messageKey of allMessageKeys) {
|
|
76
|
-
if (!CfgIOManager.hasIOContainerMessageKey(data, messageKey)) {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
const message = CfgIOManager.getMessageFromIOContainer(data, messageKey);
|
|
80
|
-
for (const item of listeners) {
|
|
81
|
-
if (item.messageKey !== messageKey) {
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
// async, not waiting. Might need to change.
|
|
85
|
-
promises.push(item.l(message));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}))();
|
|
89
|
-
Promise.all(promises)
|
|
90
|
-
.then(() => {
|
|
91
|
-
this._receiveInProgress = false;
|
|
92
|
-
CfgIOManager._inhibitAllReceive = false;
|
|
93
|
-
})
|
|
94
|
-
.catch(() => {
|
|
95
|
-
this._receiveInProgress = false;
|
|
96
|
-
CfgIOManager._inhibitAllReceive = false;
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
CfgIOManager.isIOContainer = (data) => hasConfiguraAttribute(data) && data[CONFIGURA_ATTRIBUTE] === CONFIGURA_SHEBANG;
|
|
101
|
-
CfgIOManager.hasIOContainerMessageKey = (container, messageKey) => messageKey in container.messages;
|
|
102
|
-
CfgIOManager.getMessageFromIOContainer = (container, messageKey) => {
|
|
103
|
-
if (!CfgIOManager.isIOContainer(container)) {
|
|
104
|
-
throw new Error("The passed data was not a CfgIOContainer. It is to be expected that such data messages can arrive, so please use isIOContainer function to filter them out before calling this.");
|
|
105
|
-
}
|
|
106
|
-
if (!CfgIOManager.hasIOContainerMessageKey(container, messageKey)) {
|
|
107
|
-
throw new Error(`The passed data did not have the messageKey "${messageKey}". You can test for this using hasIOContainerMessageKey function.`);
|
|
108
|
-
}
|
|
109
|
-
return container.messages[messageKey];
|
|
110
|
-
};
|
|
111
|
-
CfgIOManager.makeContainer = (messages) => ({
|
|
112
|
-
[CONFIGURA_ATTRIBUTE]: CONFIGURA_SHEBANG,
|
|
113
|
-
messages,
|
|
114
|
-
});
|
|
115
|
-
CfgIOManager._inhibitAllReceive = false;
|
|
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
|
+
const CONFIGURA_ATTRIBUTE = "C0nf1gura";
|
|
11
|
+
const CONFIGURA_SHEBANG = "arug1fn0C";
|
|
12
|
+
// Support function. Did not manage to check both attribute and value in one step
|
|
13
|
+
const hasConfiguraAttribute = (data) => {
|
|
14
|
+
return typeof data === "object" && data !== null;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Base class for classes handling input and output in globally shared environments.
|
|
18
|
+
*/
|
|
19
|
+
export class CfgIOManager {
|
|
20
|
+
constructor() {
|
|
21
|
+
// A lock to avoid circular write. Asynchronous conditions can make this not be enough.
|
|
22
|
+
// Avoid creating pre-conditions where this can happen.
|
|
23
|
+
this._receiveInProgress = false;
|
|
24
|
+
this._messageListeners = [];
|
|
25
|
+
this._getIndexOfMessageListener = (l) => this._messageListeners.findIndex((item) => l === item.l);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Listen for the message messageKey being received.
|
|
29
|
+
*/
|
|
30
|
+
listenForMessage(l, messageKey) {
|
|
31
|
+
if (this._getIndexOfMessageListener(l) !== -1) {
|
|
32
|
+
console.warn("Tried to add listener twice");
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
this._messageListeners.push({ l, messageKey });
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Removes the listener
|
|
40
|
+
*/
|
|
41
|
+
stopListenForMessage(l) {
|
|
42
|
+
const i = this._getIndexOfMessageListener(l);
|
|
43
|
+
if (i === -1) {
|
|
44
|
+
console.warn("Tried to stopListen on unknown listener");
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
this._messageListeners.splice(i, 1);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
get receiveInProgress() {
|
|
51
|
+
return this._receiveInProgress;
|
|
52
|
+
}
|
|
53
|
+
get hasMessageListeners() {
|
|
54
|
+
return 0 < this._messageListeners.length;
|
|
55
|
+
}
|
|
56
|
+
_containerListener(data) {
|
|
57
|
+
if (CfgIOManager._inhibitAllReceive) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (!CfgIOManager.isIOContainer(data)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
CfgIOManager._inhibitAllReceive = true;
|
|
64
|
+
this._receiveInProgress = true;
|
|
65
|
+
// The 15 or so rows below is one of the cases where I believe building a clever
|
|
66
|
+
// data structure of so would probably be worse for performance than just looping
|
|
67
|
+
// as the subscribers are expected to be very few
|
|
68
|
+
const listeners = this._messageListeners;
|
|
69
|
+
const allMessageKeys = listeners.reduce((a, c) => {
|
|
70
|
+
a.add(c.messageKey);
|
|
71
|
+
return a;
|
|
72
|
+
}, new Set());
|
|
73
|
+
const promises = [];
|
|
74
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
for (const messageKey of allMessageKeys) {
|
|
76
|
+
if (!CfgIOManager.hasIOContainerMessageKey(data, messageKey)) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const message = CfgIOManager.getMessageFromIOContainer(data, messageKey);
|
|
80
|
+
for (const item of listeners) {
|
|
81
|
+
if (item.messageKey !== messageKey) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
// async, not waiting. Might need to change.
|
|
85
|
+
promises.push(item.l(message));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}))();
|
|
89
|
+
Promise.all(promises)
|
|
90
|
+
.then(() => {
|
|
91
|
+
this._receiveInProgress = false;
|
|
92
|
+
CfgIOManager._inhibitAllReceive = false;
|
|
93
|
+
})
|
|
94
|
+
.catch(() => {
|
|
95
|
+
this._receiveInProgress = false;
|
|
96
|
+
CfgIOManager._inhibitAllReceive = false;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
CfgIOManager.isIOContainer = (data) => hasConfiguraAttribute(data) && data[CONFIGURA_ATTRIBUTE] === CONFIGURA_SHEBANG;
|
|
101
|
+
CfgIOManager.hasIOContainerMessageKey = (container, messageKey) => messageKey in container.messages;
|
|
102
|
+
CfgIOManager.getMessageFromIOContainer = (container, messageKey) => {
|
|
103
|
+
if (!CfgIOManager.isIOContainer(container)) {
|
|
104
|
+
throw new Error("The passed data was not a CfgIOContainer. It is to be expected that such data messages can arrive, so please use isIOContainer function to filter them out before calling this.");
|
|
105
|
+
}
|
|
106
|
+
if (!CfgIOManager.hasIOContainerMessageKey(container, messageKey)) {
|
|
107
|
+
throw new Error(`The passed data did not have the messageKey "${messageKey}". You can test for this using hasIOContainerMessageKey function.`);
|
|
108
|
+
}
|
|
109
|
+
return container.messages[messageKey];
|
|
110
|
+
};
|
|
111
|
+
CfgIOManager.makeContainer = (messages) => ({
|
|
112
|
+
[CONFIGURA_ATTRIBUTE]: CONFIGURA_SHEBANG,
|
|
113
|
+
messages,
|
|
114
|
+
});
|
|
115
|
+
CfgIOManager._inhibitAllReceive = false;
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { DtoAdditionalProductConfiguration, DtoConfProd } from "../CatalogueAPI.js";
|
|
2
|
-
import { CfgProduct, CfgProductChangeNotification } from "../CfgProduct.js";
|
|
3
|
-
import { CfgIOManager } from "./CfgIOManager.js";
|
|
4
|
-
export declare type CfgProdConfMessageV1 = {
|
|
5
|
-
version: "1.0";
|
|
6
|
-
conf: DtoAdditionalProductConfiguration;
|
|
7
|
-
};
|
|
8
|
-
export declare type CfgProdConfMessageV2 = {
|
|
9
|
-
version: "2.0";
|
|
10
|
-
conf: DtoConfProd;
|
|
11
|
-
};
|
|
12
|
-
export declare type CfgProdConfMessage = {
|
|
13
|
-
initial: boolean;
|
|
14
|
-
subMessages: (CfgProdConfMessageV1 | CfgProdConfMessageV2)[];
|
|
15
|
-
};
|
|
16
|
-
export declare enum CfgProdConfMessageVersions {
|
|
17
|
-
V1dot0 = 1,
|
|
18
|
-
V2dot0 = 2
|
|
19
|
-
}
|
|
20
|
-
export declare const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
|
|
21
|
-
declare type ProdConfMessageCallback = (message: CfgProdConfMessage) => Promise<void>;
|
|
22
|
-
declare type ProdConfCallback = (conf: DtoConfProd) => Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Base class for connecting the product configuration to an IO channel
|
|
25
|
-
*/
|
|
26
|
-
export declare abstract class CfgIOProdConfConnector<S> {
|
|
27
|
-
private readonly _ioManager;
|
|
28
|
-
private readonly _doValidate;
|
|
29
|
-
private readonly _sendVersions;
|
|
30
|
-
private readonly _includeExtendedDataInSend;
|
|
31
|
-
private readonly _includeProdParamsInSend;
|
|
32
|
-
private _product;
|
|
33
|
-
private _stopListenToMessage;
|
|
34
|
-
private _stopListenToProdConf;
|
|
35
|
-
constructor(_ioManager: CfgIOManager<S>, _doValidate: boolean, _sendVersions: CfgProdConfMessageVersions, _includeExtendedDataInSend: boolean, // Only v2.0
|
|
36
|
-
_includeProdParamsInSend: boolean);
|
|
37
|
-
destroy: () => void;
|
|
38
|
-
setProduct: (product: CfgProduct | undefined) => Promise<void>;
|
|
39
|
-
private _send;
|
|
40
|
-
protected getInitialProdConf(): DtoConfProd | undefined;
|
|
41
|
-
protected abstract makeSendData(conf: DtoConfProd, initial: boolean): S;
|
|
42
|
-
makeMessage(conf: DtoConfProd, initial: boolean): CfgProdConfMessage;
|
|
43
|
-
makeMessageListener(callback: ProdConfMessageCallback): (message: unknown) => Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Register the callback to listen for Product Configuration messages
|
|
46
|
-
* @returns A function which when called will cancel listening
|
|
47
|
-
*/
|
|
48
|
-
listenForMessage(callback: ProdConfMessageCallback): () => void;
|
|
49
|
-
makeProdConfListener(callback: ProdConfCallback): (n: CfgProductChangeNotification) => void;
|
|
50
|
-
listenForProdConf(product: CfgProduct, callback: ProdConfCallback): () => void;
|
|
51
|
-
}
|
|
52
|
-
export {};
|
|
1
|
+
import { DtoAdditionalProductConfiguration, DtoConfProd } from "../CatalogueAPI.js";
|
|
2
|
+
import { CfgProduct, CfgProductChangeNotification } from "../CfgProduct.js";
|
|
3
|
+
import { CfgIOManager } from "./CfgIOManager.js";
|
|
4
|
+
export declare type CfgProdConfMessageV1 = {
|
|
5
|
+
version: "1.0";
|
|
6
|
+
conf: DtoAdditionalProductConfiguration;
|
|
7
|
+
};
|
|
8
|
+
export declare type CfgProdConfMessageV2 = {
|
|
9
|
+
version: "2.0";
|
|
10
|
+
conf: DtoConfProd;
|
|
11
|
+
};
|
|
12
|
+
export declare type CfgProdConfMessage = {
|
|
13
|
+
initial: boolean;
|
|
14
|
+
subMessages: (CfgProdConfMessageV1 | CfgProdConfMessageV2)[];
|
|
15
|
+
};
|
|
16
|
+
export declare enum CfgProdConfMessageVersions {
|
|
17
|
+
V1dot0 = 1,
|
|
18
|
+
V2dot0 = 2
|
|
19
|
+
}
|
|
20
|
+
export declare const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
|
|
21
|
+
declare type ProdConfMessageCallback = (message: CfgProdConfMessage) => Promise<void>;
|
|
22
|
+
declare type ProdConfCallback = (conf: DtoConfProd) => Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Base class for connecting the product configuration to an IO channel
|
|
25
|
+
*/
|
|
26
|
+
export declare abstract class CfgIOProdConfConnector<S> {
|
|
27
|
+
private readonly _ioManager;
|
|
28
|
+
private readonly _doValidate;
|
|
29
|
+
private readonly _sendVersions;
|
|
30
|
+
private readonly _includeExtendedDataInSend;
|
|
31
|
+
private readonly _includeProdParamsInSend;
|
|
32
|
+
private _product;
|
|
33
|
+
private _stopListenToMessage;
|
|
34
|
+
private _stopListenToProdConf;
|
|
35
|
+
constructor(_ioManager: CfgIOManager<S>, _doValidate: boolean, _sendVersions: CfgProdConfMessageVersions, _includeExtendedDataInSend: boolean, // Only v2.0
|
|
36
|
+
_includeProdParamsInSend: boolean);
|
|
37
|
+
destroy: () => void;
|
|
38
|
+
setProduct: (product: CfgProduct | undefined) => Promise<void>;
|
|
39
|
+
private _send;
|
|
40
|
+
protected getInitialProdConf(): DtoConfProd | undefined;
|
|
41
|
+
protected abstract makeSendData(conf: DtoConfProd, initial: boolean): S;
|
|
42
|
+
makeMessage(conf: DtoConfProd, initial: boolean): CfgProdConfMessage;
|
|
43
|
+
makeMessageListener(callback: ProdConfMessageCallback): (message: unknown) => Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Register the callback to listen for Product Configuration messages
|
|
46
|
+
* @returns A function which when called will cancel listening
|
|
47
|
+
*/
|
|
48
|
+
listenForMessage(callback: ProdConfMessageCallback): () => void;
|
|
49
|
+
makeProdConfListener(callback: ProdConfCallback): (n: CfgProductChangeNotification) => void;
|
|
50
|
+
listenForProdConf(product: CfgProduct, callback: ProdConfCallback): () => void;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
53
53
|
//# sourceMappingURL=CfgIOProdConfConnector.d.ts.map
|