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

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 +273 -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 +780 -778
  10. package/dist/CfgReferencePathHelper.d.ts +26 -13
  11. package/dist/CfgReferencePathHelper.js +26 -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 +51 -50
  17. package/dist/io/CfgHistoryManager.js +82 -82
  18. package/dist/io/CfgHistoryToProdConfConnector.d.ts +20 -20
  19. package/dist/io/CfgHistoryToProdConfConnector.js +101 -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 +55 -52
  23. package/dist/io/CfgIOProdConfConnector.js +143 -141
  24. package/dist/io/CfgObservableStateManager.d.ts +25 -21
  25. package/dist/io/CfgObservableStateManager.js +69 -65
  26. package/dist/io/CfgObservableStateToProdConfConnector.d.ts +15 -14
  27. package/dist/io/CfgObservableStateToProdConfConnector.js +17 -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 +87 -84
  32. package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +17 -16
  33. package/dist/io/CfgWindowMessageToProdConfConnector.js +19 -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,21 +1,21 @@
1
- import { DtoConfProd } from "../CatalogueAPI.js";
2
- import { CfgHistoryManager, CfgHistoryManagerSendData } from "./CfgHistoryManager.js";
3
- import { CfgIOProdConfConnector, CfgProdConfMessage } from "./CfgIOProdConfConnector.js";
4
- export declare function dtoConfToString(conf: DtoConfProd): string;
5
- export declare function stringToDtoConf(conf: string): DtoConfProd;
6
- /**
7
- * Instantiating this will make the browser history (and URL) update with the product configuration.
8
- */
9
- export declare class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector<CfgHistoryManagerSendData<CfgProdConfMessage>> {
10
- private readonly _useHistoryPush;
11
- private readonly _qsKey;
12
- /**
13
- * @param _useHistoryPush As opposed to replace. Push makes the web browser navigation buttons navigate configuration changes. Replace just updates the URL.
14
- * @param _qsKey The Query String key for product configuration.
15
- * @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?
16
- */
17
- constructor(manager: CfgHistoryManager, _useHistoryPush: boolean, _qsKey?: string, doValidate?: boolean);
18
- protected getInitialProdConf(): DtoConfProd | undefined;
19
- protected makeSendData(conf: DtoConfProd, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
20
- }
1
+ import { DtoProductConfiguration } from "../CatalogueAPI.js";
2
+ import { CfgHistoryManager, CfgHistoryManagerSendData } from "./CfgHistoryManager.js";
3
+ import { CfgIOProdConfConnector, CfgProdConfMessage } from "./CfgIOProdConfConnector.js";
4
+ export declare const dtoConfToCompactString: (conf: DtoProductConfiguration) => string;
5
+ export declare const compactStringToDtoConf: (versionAndConf: string) => DtoProductConfiguration;
6
+ /**
7
+ * Instantiating this will make the browser history (and URL) update with the product configuration.
8
+ */
9
+ export declare class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector<CfgHistoryManagerSendData<CfgProdConfMessage>> {
10
+ private readonly _useHistoryPush;
11
+ private readonly _qsKey;
12
+ /**
13
+ * @param _useHistoryPush As opposed to replace. Push makes the web browser navigation buttons navigate configuration changes. Replace just updates the URL.
14
+ * @param _qsKey The Query String key for product configuration.
15
+ * @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?
16
+ */
17
+ constructor(manager: CfgHistoryManager, _useHistoryPush: boolean, _qsKey?: string, doValidate?: boolean);
18
+ protected getInitialProdConf(): DtoProductConfiguration | undefined;
19
+ protected makeSendData(conf: DtoProductConfiguration, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
20
+ }
21
21
  //# sourceMappingURL=CfgHistoryToProdConfConnector.d.ts.map
@@ -1,56 +1,101 @@
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 versionedRegex = /^v(\d+)(.+)$/;
4
+ const jsonKeyRegex = /"([^"]+)":/g;
5
+ const swapIntoUrlAdaptedRegex = /[{}"]/g;
6
+ const swapFromUrlAdaptedRegex = /[-~_]/g;
7
+ const shortToLong = new Map();
8
+ const longToShort = new Map();
9
+ // The replacement scheme here assumes this will only be used for keys
10
+ // in DtoProductConfiguration and the knowledge that it contains no one
11
+ // one char keys.
12
+ for (const [long, short] of [
13
+ ["configuration", "c"],
14
+ ["additionalProducts", "a"],
15
+ ["prodParams", "p"],
16
+ ["refKey", "r"],
17
+ ["selected", "s"],
18
+ ["features", "f"],
19
+ ["code", "d"],
20
+ ["options", "o"],
21
+ ["numericValue", "n"],
22
+ ["groupCode", "g"],
23
+ ["unit", "u"],
24
+ ]) {
25
+ shortToLong.set(short, long);
26
+ longToShort.set(long, short);
27
+ }
28
+ /**
29
+ * As certain chars are abundant in JSON but less abundant in the actual data
30
+ * we swap these so that frequent characters do not need to be URL-encoded.
31
+ */
32
+ const jsonStringSwapCharsForUrl = (data) => data.replace(swapIntoUrlAdaptedRegex, (char) => {
33
+ switch (char) {
34
+ case "{":
35
+ return "~";
36
+ case "}":
37
+ return "-";
38
+ case '"':
39
+ return "_";
40
+ default:
41
+ throw new Error(`Unexpected char "${char}" in swap for URL`);
42
+ }
43
+ });
44
+ const jsonStringSwapCharsFromUrl = (data) => data.replace(swapFromUrlAdaptedRegex, (char) => {
45
+ switch (char) {
46
+ case "~":
47
+ return "{";
48
+ case "-":
49
+ return "}";
50
+ case "_":
51
+ return '"';
52
+ default:
53
+ throw new Error(`Unexpected char "${char}" in swap from URL`);
54
+ }
55
+ });
56
+ const compactDtoConfJsonKeys = (data) => data.replace(jsonKeyRegex, (_, key) => { var _a; return `"${(_a = longToShort.get(key)) !== null && _a !== void 0 ? _a : key}":`; });
57
+ const expandDtoConfJsonKeys = (data) => data.replace(jsonKeyRegex, (_, key) => { var _a; return `"${(_a = shortToLong.get(key)) !== null && _a !== void 0 ? _a : key}":`; });
58
+ export const dtoConfToCompactString = (conf) => "v1" + jsonStringSwapCharsForUrl(compactDtoConfJsonKeys(JSON.stringify(conf, undefined, "")));
59
+ export const compactStringToDtoConf = (versionAndConf) => {
60
+ const match = versionedRegex.exec(versionAndConf);
61
+ if (match === null) {
62
+ throw new Error("Could not match version string");
63
+ }
64
+ const [, version, conf] = match;
65
+ if (version !== "1") {
66
+ throw new Error("Unknown packed URL version");
67
+ }
68
+ if (conf === "") {
69
+ throw new Error("No conf found");
70
+ }
71
+ return JSON.parse(expandDtoConfJsonKeys(jsonStringSwapCharsFromUrl(conf)));
72
+ };
73
+ /**
74
+ * Instantiating this will make the browser history (and URL) update with the product configuration.
75
+ */
76
+ export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
77
+ /**
78
+ * @param _useHistoryPush As opposed to replace. Push makes the web browser navigation buttons navigate configuration changes. Replace just updates the URL.
79
+ * @param _qsKey The Query String key for product configuration.
80
+ * @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?
81
+ */
82
+ constructor(manager, _useHistoryPush, _qsKey = STAGE_PROD_CONF_MESSAGE_KEY, doValidate = true) {
83
+ super(manager, doValidate, false, false);
84
+ this._useHistoryPush = _useHistoryPush;
85
+ this._qsKey = _qsKey;
86
+ }
87
+ getInitialProdConf() {
88
+ const s = CfgHistoryManager.currentQsKeyValues().get(this._qsKey);
89
+ if (s === undefined) {
90
+ return undefined;
91
+ }
92
+ return compactStringToDtoConf(s);
93
+ }
94
+ makeSendData(conf, initial) {
95
+ return {
96
+ message: CfgIOProdConfConnector.makeMessage(conf, initial, CfgProdConfMessageVersions.V2dot0),
97
+ qsKeyValues: new Map([[STAGE_PROD_CONF_MESSAGE_KEY, dtoConfToCompactString(conf)]]),
98
+ useHistoryPush: this._useHistoryPush,
99
+ };
100
+ }
101
+ }
@@ -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
@@ -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,56 @@
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, DtoProductConfiguration } from "../CatalogueAPI.js";
2
+ import { CfgProduct, CfgProductChangeNotification } from "../CfgProduct.js";
3
+ import { CfgIOManager } from "./CfgIOManager.js";
4
+ export declare const isCfgProdConfMessage: (data: unknown) => data is CfgProdConfMessageV1 | CfgProdConfMessageV2;
5
+ export declare type CfgProdConfMessageV1 = {
6
+ version: "1.0";
7
+ conf: DtoAdditionalProductConfiguration;
8
+ };
9
+ export declare const isCfgProdConfMessageV1: (data: unknown) => data is CfgProdConfMessageV1;
10
+ export declare type CfgProdConfMessageV2 = {
11
+ version: "2.0";
12
+ conf: DtoProductConfiguration;
13
+ };
14
+ export declare const isCfgProdConfMessageV2: (data: unknown) => data is CfgProdConfMessageV2;
15
+ export declare type CfgProdConfMessage = {
16
+ initial: boolean;
17
+ subMessages: (CfgProdConfMessageV1 | CfgProdConfMessageV2)[];
18
+ };
19
+ export declare const getHighestVersionProdConfMessage: (subMessages: (CfgProdConfMessageV1 | CfgProdConfMessageV2)[]) => CfgProdConfMessageV1 | CfgProdConfMessageV2;
20
+ export declare enum CfgProdConfMessageVersions {
21
+ V1dot0 = 1,
22
+ V2dot0 = 2
23
+ }
24
+ export declare const STAGE_PROD_CONF_MESSAGE_KEY = "stageprodconf";
25
+ declare type ProdConfMessageCallback = (message: CfgProdConfMessage) => Promise<void>;
26
+ declare type ProdConfCallback = (conf: DtoProductConfiguration) => Promise<void>;
27
+ /**
28
+ * Base class for connecting the product configuration to an IO channel
29
+ */
30
+ export declare abstract class CfgIOProdConfConnector<S> {
31
+ private readonly _ioManager;
32
+ private readonly _doValidate;
33
+ private readonly _includeExtendedDataInSend;
34
+ private readonly _includeProdParamsInSend;
35
+ private _product;
36
+ private _stopListenToMessage;
37
+ private _stopListenToProdConf;
38
+ constructor(_ioManager: CfgIOManager<S>, _doValidate: boolean, _includeExtendedDataInSend: boolean, // Only v2.0
39
+ _includeProdParamsInSend: boolean);
40
+ destroy: () => void;
41
+ setProduct: (product: CfgProduct | undefined) => Promise<void>;
42
+ private _send;
43
+ protected getInitialProdConf(): DtoProductConfiguration | undefined;
44
+ protected abstract makeSendData(conf: DtoProductConfiguration, initial: boolean): S;
45
+ static makeMessage(conf: DtoProductConfiguration, initial: boolean, sendVersions: CfgProdConfMessageVersions): CfgProdConfMessage;
46
+ static makeMessageListener(callback: ProdConfMessageCallback): (message: unknown) => Promise<void>;
47
+ /**
48
+ * Register the callback to listen for Product Configuration messages
49
+ * @returns A function which when called will cancel listening
50
+ */
51
+ static listenForMessage<S>(callback: ProdConfMessageCallback, ioManager: CfgIOManager<S>): () => void;
52
+ static makeProdConfListener(callback: ProdConfCallback, includeExtendedDataInSend: boolean, includeProdParamsInSend: boolean): (n: CfgProductChangeNotification) => void;
53
+ static listenForProdConf(product: CfgProduct, callback: ProdConfCallback, includeExtendedDataInSend: boolean, includeProdParamsInSend: boolean): () => void;
54
+ }
55
+ export {};
53
56
  //# sourceMappingURL=CfgIOProdConfConnector.d.ts.map