@configura/web-api 1.6.0-iotest.4 → 1.6.0-rc.0

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 (92) hide show
  1. package/.eslintrc.json +18 -0
  2. package/LICENSE +201 -201
  3. package/README.md +1 -1
  4. package/dist/CatalogueAPI.d.ts +507 -511
  5. package/dist/CatalogueAPI.js +280 -273
  6. package/dist/CfgMeasure.d.ts +32 -32
  7. package/dist/CfgMeasure.js +30 -30
  8. package/dist/CfgProduct.d.ts +253 -240
  9. package/dist/CfgProduct.js +733 -668
  10. package/dist/index.d.ts +20 -24
  11. package/dist/index.js +20 -24
  12. package/dist/material/CfgMaterialMapping.d.ts +7 -7
  13. package/dist/material/CfgMaterialMapping.js +181 -181
  14. package/dist/material/CfgMtrlApplication.d.ts +18 -18
  15. package/dist/material/CfgMtrlApplication.js +43 -43
  16. package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
  17. package/dist/material/CfgMtrlApplicationSource.js +8 -8
  18. package/dist/material/CfgMtrlSource.d.ts +19 -19
  19. package/dist/material/CfgMtrlSource.js +40 -40
  20. package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
  21. package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
  22. package/dist/productConfiguration/CfgFeature.d.ts +188 -178
  23. package/dist/productConfiguration/CfgFeature.js +636 -611
  24. package/dist/productConfiguration/CfgOption.d.ts +150 -128
  25. package/dist/productConfiguration/CfgOption.js +426 -394
  26. package/dist/productConfiguration/CfgProductConfiguration.d.ts +120 -121
  27. package/dist/productConfiguration/CfgProductConfiguration.js +309 -306
  28. package/dist/productConfiguration/filters.d.ts +15 -15
  29. package/dist/productConfiguration/filters.js +70 -67
  30. package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
  31. package/dist/productConfiguration/productParamsGenerator.js +51 -51
  32. package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
  33. package/dist/productConfiguration/utilitiesProductConfiguration.js +80 -80
  34. package/dist/productLoader.d.ts +33 -33
  35. package/dist/productLoader.js +49 -49
  36. package/dist/syncGroups/SyncGroupsApplyMode.d.ts +21 -0
  37. package/dist/syncGroups/SyncGroupsApplyMode.js +21 -0
  38. package/dist/syncGroups/SyncGroupsHandler.d.ts +36 -0
  39. package/dist/syncGroups/SyncGroupsHandler.js +349 -0
  40. package/dist/syncGroups/SyncGroupsPathHelper.d.ts +27 -0
  41. package/dist/syncGroups/SyncGroupsPathHelper.js +90 -0
  42. package/dist/syncGroups/SyncGroupsState.d.ts +26 -0
  43. package/dist/syncGroups/SyncGroupsState.js +113 -0
  44. package/dist/syncGroups/SyncGroupsTransaction.d.ts +155 -0
  45. package/dist/syncGroups/SyncGroupsTransaction.js +576 -0
  46. package/dist/tasks/TaskHandler.d.ts +78 -78
  47. package/dist/tasks/TaskHandler.js +276 -265
  48. package/dist/tasks/formats.d.ts +4 -4
  49. package/dist/tasks/formats.js +7 -7
  50. package/dist/tests/testData/collectorForTest.d.ts +73 -73
  51. package/dist/tests/testData/collectorForTest.js +194 -195
  52. package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
  53. package/dist/tests/testData/dummyProductForTest.js +36 -36
  54. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +11 -32
  55. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +277 -348
  56. package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
  57. package/dist/tests/testData/testDataCachedGetProduct.js +185 -196
  58. package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
  59. package/dist/tests/testData/testDataCachedPostValidate.js +183 -183
  60. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
  61. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1099 -1099
  62. package/dist/tests/testData/testDataOptions.d.ts +13 -0
  63. package/dist/tests/testData/testDataOptions.js +60 -0
  64. package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
  65. package/dist/tests/testData/testDataProductAggregatedPrice.js +187 -198
  66. package/dist/tests/testData/testDataUpcharge.d.ts +8 -29
  67. package/dist/tests/testData/testDataUpcharge.js +119 -151
  68. package/dist/utilitiesCatalogueData.d.ts +31 -25
  69. package/dist/utilitiesCatalogueData.js +162 -65
  70. package/dist/utilitiesCataloguePermission.d.ts +37 -39
  71. package/dist/utilitiesCataloguePermission.js +80 -84
  72. package/dist/utilitiesNumericValues.d.ts +24 -24
  73. package/dist/utilitiesNumericValues.js +109 -109
  74. package/package.json +3 -3
  75. package/dist/io/CfgHistoryManager.d.ts +0 -26
  76. package/dist/io/CfgHistoryManager.js +0 -58
  77. package/dist/io/CfgHistoryToCameraConfConnector.d.ts +0 -15
  78. package/dist/io/CfgHistoryToCameraConfConnector.js +0 -58
  79. package/dist/io/CfgHistoryToProdConfConnector.d.ts +0 -14
  80. package/dist/io/CfgHistoryToProdConfConnector.js +0 -24
  81. package/dist/io/CfgIOCameraConfConnector.d.ts +0 -31
  82. package/dist/io/CfgIOCameraConfConnector.js +0 -72
  83. package/dist/io/CfgIOManager.d.ts +0 -29
  84. package/dist/io/CfgIOManager.js +0 -89
  85. package/dist/io/CfgIOProdConfConnector.d.ts +0 -36
  86. package/dist/io/CfgIOProdConfConnector.js +0 -102
  87. package/dist/io/CfgWindowMessageManager.d.ts +0 -13
  88. package/dist/io/CfgWindowMessageManager.js +0 -33
  89. package/dist/io/CfgWindowMessageToCameraConfConnector.d.ts +0 -6
  90. package/dist/io/CfgWindowMessageToCameraConfConnector.js +0 -6
  91. package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +0 -14
  92. package/dist/io/CfgWindowMessageToProdConfConnector.js +0 -17
package/dist/index.d.ts CHANGED
@@ -1,25 +1,21 @@
1
- export * from "./CatalogueAPI.js";
2
- export * from "./CfgProduct.js";
3
- export * from "./io/CfgHistoryManager.js";
4
- export * from "./io/CfgHistoryToCameraConfConnector.js";
5
- export * from "./io/CfgHistoryToProdConfConnector.js";
6
- export * from "./io/CfgWindowMessageManager.js";
7
- export * from "./io/CfgWindowMessageToCameraConfConnector.js";
8
- export * from "./io/CfgWindowMessageToProdConfConnector.js";
9
- export * from "./material/CfgMaterialMapping.js";
10
- export * from "./material/CfgMtrlApplication.js";
11
- export * from "./material/CfgMtrlApplicationSource.js";
12
- export * from "./material/CfgMtrlSource.js";
13
- export * from "./material/CfgMtrlSourceWithMetaData.js";
14
- export * from "./productConfiguration/CfgFeature.js";
15
- export * from "./productConfiguration/CfgOption.js";
16
- export * from "./productConfiguration/CfgProductConfiguration.js";
17
- export * from "./productConfiguration/filters.js";
18
- export * from "./productConfiguration/productParamsGenerator.js";
19
- export * from "./productLoader.js";
20
- export * from "./tasks/formats.js";
21
- export * from "./tasks/TaskHandler.js";
22
- export * from "./utilitiesCatalogueData.js";
23
- export * from "./utilitiesCataloguePermission.js";
24
- export * from "./utilitiesNumericValues.js";
1
+ export * from "./CatalogueAPI.js";
2
+ export * from "./CfgProduct.js";
3
+ export * from "./material/CfgMaterialMapping.js";
4
+ export * from "./material/CfgMtrlApplication.js";
5
+ export * from "./material/CfgMtrlApplicationSource.js";
6
+ export * from "./material/CfgMtrlSource.js";
7
+ export * from "./material/CfgMtrlSourceWithMetaData.js";
8
+ export * from "./productConfiguration/CfgFeature.js";
9
+ export * from "./productConfiguration/CfgOption.js";
10
+ export * from "./productConfiguration/CfgProductConfiguration.js";
11
+ export * from "./productConfiguration/filters.js";
12
+ export * from "./productConfiguration/productParamsGenerator.js";
13
+ export * from "./productLoader.js";
14
+ export * from "./syncGroups/SyncGroupsApplyMode.js";
15
+ export * from "./syncGroups/SyncGroupsHandler.js";
16
+ export * from "./tasks/formats.js";
17
+ export * from "./tasks/TaskHandler.js";
18
+ export * from "./utilitiesCatalogueData.js";
19
+ export * from "./utilitiesCataloguePermission.js";
20
+ export * from "./utilitiesNumericValues.js";
25
21
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,24 +1,20 @@
1
- export * from "./CatalogueAPI.js";
2
- export * from "./CfgProduct.js";
3
- export * from "./io/CfgHistoryManager.js";
4
- export * from "./io/CfgHistoryToCameraConfConnector.js";
5
- export * from "./io/CfgHistoryToProdConfConnector.js";
6
- export * from "./io/CfgWindowMessageManager.js";
7
- export * from "./io/CfgWindowMessageToCameraConfConnector.js";
8
- export * from "./io/CfgWindowMessageToProdConfConnector.js";
9
- export * from "./material/CfgMaterialMapping.js";
10
- export * from "./material/CfgMtrlApplication.js";
11
- export * from "./material/CfgMtrlApplicationSource.js";
12
- export * from "./material/CfgMtrlSource.js";
13
- export * from "./material/CfgMtrlSourceWithMetaData.js";
14
- export * from "./productConfiguration/CfgFeature.js";
15
- export * from "./productConfiguration/CfgOption.js";
16
- export * from "./productConfiguration/CfgProductConfiguration.js";
17
- export * from "./productConfiguration/filters.js";
18
- export * from "./productConfiguration/productParamsGenerator.js";
19
- export * from "./productLoader.js";
20
- export * from "./tasks/formats.js";
21
- export * from "./tasks/TaskHandler.js";
22
- export * from "./utilitiesCatalogueData.js";
23
- export * from "./utilitiesCataloguePermission.js";
24
- export * from "./utilitiesNumericValues.js";
1
+ export * from "./CatalogueAPI.js";
2
+ export * from "./CfgProduct.js";
3
+ export * from "./material/CfgMaterialMapping.js";
4
+ export * from "./material/CfgMtrlApplication.js";
5
+ export * from "./material/CfgMtrlApplicationSource.js";
6
+ export * from "./material/CfgMtrlSource.js";
7
+ export * from "./material/CfgMtrlSourceWithMetaData.js";
8
+ export * from "./productConfiguration/CfgFeature.js";
9
+ export * from "./productConfiguration/CfgOption.js";
10
+ export * from "./productConfiguration/CfgProductConfiguration.js";
11
+ export * from "./productConfiguration/filters.js";
12
+ export * from "./productConfiguration/productParamsGenerator.js";
13
+ export * from "./productLoader.js";
14
+ export * from "./syncGroups/SyncGroupsApplyMode.js";
15
+ export * from "./syncGroups/SyncGroupsHandler.js";
16
+ export * from "./tasks/formats.js";
17
+ export * from "./tasks/TaskHandler.js";
18
+ export * from "./utilitiesCatalogueData.js";
19
+ export * from "./utilitiesCataloguePermission.js";
20
+ export * from "./utilitiesNumericValues.js";
@@ -1,8 +1,8 @@
1
- import { CfgProductConfiguration } from "../productConfiguration/CfgProductConfiguration.js";
2
- import { CfgMtrlApplication } from "./CfgMtrlApplication.js";
3
- import { CfgMtrlSourceWithMetaData } from "./CfgMtrlSourceWithMetaData.js";
4
- export declare type CfgMaterialMapping = Map<string, CfgMtrlSourceWithMetaData>;
5
- export declare function aggregateAllMaterialApplications(applicationAreas: CfgMtrlApplication[], productMtrlApplications: CfgMtrlApplication[], productConfiguration: CfgProductConfiguration, debugMtrlApplications?: CfgMtrlApplication[]): CfgMaterialMapping;
6
- export declare function logMtrlSourceWithMetaDataToConsole(mtrlSourceWithMetaData: CfgMtrlSourceWithMetaData): void;
7
- export declare function logMaterialMappingToConsole(areasToMaterials: CfgMaterialMapping): void;
1
+ import { CfgProductConfiguration } from "../productConfiguration/CfgProductConfiguration.js";
2
+ import { CfgMtrlApplication } from "./CfgMtrlApplication.js";
3
+ import { CfgMtrlSourceWithMetaData } from "./CfgMtrlSourceWithMetaData.js";
4
+ export declare type CfgMaterialMapping = Map<string, CfgMtrlSourceWithMetaData>;
5
+ export declare function aggregateAllMaterialApplications(applicationAreas: CfgMtrlApplication[], productMtrlApplications: CfgMtrlApplication[], productConfiguration: CfgProductConfiguration, debugMtrlApplications?: CfgMtrlApplication[]): CfgMaterialMapping;
6
+ export declare function logMtrlSourceWithMetaDataToConsole(mtrlSourceWithMetaData: CfgMtrlSourceWithMetaData): void;
7
+ export declare function logMaterialMappingToConsole(areasToMaterials: CfgMaterialMapping): void;
8
8
  //# sourceMappingURL=CfgMaterialMapping.d.ts.map
@@ -1,181 +1,181 @@
1
- import { CfgMtrlSourceBuffer, CfgMtrlSourceUrl } from "./CfgMtrlSource.js";
2
- // In this file an "application" is a combination of 0..1 Material (Mtrl) and 0..m AreaTags.
3
- // These can exist on Catalogue-level (Application Areas), Product-level, in the Feature-Options
4
- // tree (Configuration) and for the sake of debugging, locally as debug overrides.
5
- //
6
- // What this file is about is reducing/aggregating/compiling this to a simple map which says that
7
- // Area1 should have material Jeans etc. The code is written to match the behavior in CET.
8
- //
9
- // Side note: There is no connection in material application between products
10
- // in a product with additional products. So there exists no methods for
11
- // aggregating over multiple products at all.
12
- /**
13
- * When there are multiple applications on the same node we need to reduce these to what is
14
- * actually applied. The cases where there multiple applications on the same node affecting the
15
- * same thing are probably user errors i Catalogue Creator. However, Catalogue Creator allows the
16
- * user to let them slip through, so we need to handle them the same way CET does.
17
- */
18
- const reduceApplications = (applications, skipNoMtrl = false) => applications.reduce((acc, application) => {
19
- const { areaTags, mtrl } = application;
20
- // Applications which have a Mtrl but no AreaTags only have meaning on Option nodes. That
21
- // specific case is handled separately, so here we require AreaTags to be set.
22
- if (areaTags === undefined || areaTags.length === 0 || (skipNoMtrl && mtrl === undefined)) {
23
- return acc;
24
- }
25
- const materialSource = mtrl && {
26
- mtrl,
27
- source: application,
28
- overriddenByOption: false,
29
- };
30
- for (const areaTag of areaTags) {
31
- // The rule here is use the first found. This is opposite to the rule when
32
- // aggregating the tree, where the latest one found is applied
33
- if (acc.has(areaTag)) {
34
- continue;
35
- }
36
- acc.set(areaTag, materialSource);
37
- }
38
- return acc;
39
- }, new Map());
40
- export function aggregateAllMaterialApplications(applicationAreas, productMtrlApplications, productConfiguration, debugMtrlApplications = []) {
41
- const areasToMaterials = new Map();
42
- for (const [areaTag, mtrlSource] of reduceApplications(applicationAreas)) {
43
- // When Mtrl is missing there is no fallback to later Applications in the
44
- // same node. This is consistent with CET
45
- if (mtrlSource === undefined) {
46
- continue;
47
- }
48
- areasToMaterials.set(areaTag, mtrlSource);
49
- }
50
- // On Product level there is fallback if Mtrl is missing, so we pass true
51
- // to make it skip over Mtrl-less Applications
52
- for (const [areaTag, mtrlSource] of reduceApplications(productMtrlApplications, true)) {
53
- if (mtrlSource === undefined) {
54
- throw new Error("Should not happen");
55
- }
56
- areasToMaterials.set(areaTag, mtrlSource);
57
- }
58
- // We can not pass areasToMaterials directly to aggregateForFeature. This is because
59
- // an Application with AreaTags but no Mtrl is effectively a "reset". It's like saying
60
- // "no material". But that reset should only work for the stuff that comes from the
61
- // Configuration. So we must make sure we don't touch what we found from Application
62
- // Areas and Product.
63
- const configurationAreasToMaterials = new Map();
64
- for (const feature of productConfiguration.features) {
65
- // Later always beats deeper
66
- aggregateForFeature(feature, configurationAreasToMaterials);
67
- }
68
- for (const [areaTag, mtrlSource] of configurationAreasToMaterials) {
69
- areasToMaterials.set(areaTag, mtrlSource);
70
- }
71
- // Debug Applications we just let bulldozer over everything else.
72
- for (const debugMtrlApplication of debugMtrlApplications) {
73
- const { areaTags, mtrl } = debugMtrlApplication;
74
- if (mtrl === undefined) {
75
- continue;
76
- }
77
- for (const areaTag of areaTags || []) {
78
- areasToMaterials.set(areaTag, {
79
- mtrl: mtrl,
80
- source: debugMtrlApplication,
81
- overriddenByOption: false,
82
- });
83
- }
84
- }
85
- return areasToMaterials;
86
- }
87
- /**
88
- * For this Feature and it's descendants, compile the Applications into the passed areasToMaterials.
89
- */
90
- function aggregateForFeature(feature, areasToMaterials, areasOpenForOverrideInOption = new Set()) {
91
- const featureMtrlApplications = feature._internal.mtrlApplications;
92
- for (const [areaTag, mtrlSource] of reduceApplications(featureMtrlApplications)) {
93
- // As soon as a Feature sets an areaTag that tag is allowed to have its value
94
- // overridden (or set if it didn't have a value from the start) by an option.
95
- // This option has to have an Application with a Mtrl but no AreaTags.
96
- // And it can only be done once - the first option found which fulfills the
97
- // requirements will do the override. The option does not even need to be a
98
- // descendant of the Feature. After this the value is fixed until
99
- // a Feature or an Option comes along with the AreaTag set.
100
- // That will then reset the process, and if it was on a Feature it opens for
101
- // override again.
102
- areasOpenForOverrideInOption.add(areaTag);
103
- if (mtrlSource === undefined) {
104
- areasToMaterials.delete(areaTag);
105
- }
106
- else {
107
- areasToMaterials.set(areaTag, mtrlSource);
108
- }
109
- }
110
- for (const option of feature.selectedOptions) {
111
- aggregateForOption(option, areasToMaterials, areasOpenForOverrideInOption);
112
- }
113
- }
114
- function aggregateForOption(option, areasToMaterials, areasOpenForOverrideInOption) {
115
- const optionMtrlApplications = option._internal.mtrlApplications;
116
- // The last mtrl with no areaTag can be used for areasOpenForOverrideInOption
117
- if (areasOpenForOverrideInOption.size !== 0) {
118
- // Fast backwards loop
119
- let i = optionMtrlApplications.length;
120
- while (i--) {
121
- const optionMtrlApplication = optionMtrlApplications[i];
122
- const { areaTags, mtrl } = optionMtrlApplication;
123
- if ((areaTags !== undefined && areaTags.length !== 0) || mtrl === undefined) {
124
- // Only Applications with a Mtrl but no AreaTags can be used for overrides
125
- continue;
126
- }
127
- const mtrlSource = {
128
- mtrl,
129
- source: optionMtrlApplication,
130
- overriddenByOption: true,
131
- };
132
- for (const areaTag of areasOpenForOverrideInOption) {
133
- areasToMaterials.set(areaTag, mtrlSource);
134
- }
135
- areasOpenForOverrideInOption.clear();
136
- break;
137
- }
138
- }
139
- // reduceApplications will filter out Applications with AreaTags. So there will
140
- // be no overlap between Applications used for Override and Applications used
141
- // for immediately setting.
142
- for (const [areaTag, mtrlSource] of reduceApplications(optionMtrlApplications)) {
143
- if (mtrlSource === undefined) {
144
- // An Application on an Option with no Mtrl opens up for a future option
145
- // to set the Mtrl (the overridden has to be an option with a Mtrl and no Area)
146
- areasOpenForOverrideInOption.add(areaTag);
147
- areasToMaterials.delete(areaTag);
148
- }
149
- else {
150
- areasToMaterials.set(areaTag, mtrlSource);
151
- }
152
- }
153
- for (const feature of option.features || []) {
154
- aggregateForFeature(feature, areasToMaterials, areasOpenForOverrideInOption);
155
- }
156
- }
157
- export function logMtrlSourceWithMetaDataToConsole(mtrlSourceWithMetaData) {
158
- const tableData = {
159
- Source: mtrlSourceWithMetaData.source.source,
160
- OverriddenByOption: mtrlSourceWithMetaData.overriddenByOption ? "Yes" : "No",
161
- };
162
- const mtrl = mtrlSourceWithMetaData.mtrl;
163
- if (mtrl instanceof CfgMtrlSourceUrl) {
164
- tableData["From prop"] = mtrl.urlIsFromProperty;
165
- tableData["url"] = mtrl.url;
166
- }
167
- if (mtrl instanceof CfgMtrlSourceBuffer) {
168
- tableData["FileName"] = mtrl.fileName;
169
- }
170
- console.table(tableData);
171
- }
172
- export function logMaterialMappingToConsole(areasToMaterials) {
173
- const sorted = Array.from(areasToMaterials);
174
- sorted.sort((left, right) => left[0].toLocaleLowerCase().localeCompare(right[0].toLocaleLowerCase()));
175
- for (const areaToMaterial of sorted) {
176
- const [tag, mtrlSourceWithMetaData] = areaToMaterial;
177
- console.groupCollapsed(`"${tag}"`);
178
- logMtrlSourceWithMetaDataToConsole(mtrlSourceWithMetaData);
179
- console.groupEnd();
180
- }
181
- }
1
+ import { CfgMtrlSourceBuffer, CfgMtrlSourceUrl } from "./CfgMtrlSource.js";
2
+ // In this file an "application" is a combination of 0..1 Material (Mtrl) and 0..m AreaTags.
3
+ // These can exist on Catalogue-level (Application Areas), Product-level, in the Feature-Options
4
+ // tree (Configuration) and for the sake of debugging, locally as debug overrides.
5
+ //
6
+ // What this file is about is reducing/aggregating/compiling this to a simple map which says that
7
+ // Area1 should have material Jeans etc. The code is written to match the behavior in CET.
8
+ //
9
+ // Side note: There is no connection in material application between products
10
+ // in a product with additional products. So there exists no methods for
11
+ // aggregating over multiple products at all.
12
+ /**
13
+ * When there are multiple applications on the same node we need to reduce these to what is
14
+ * actually applied. The cases where there multiple applications on the same node affecting the
15
+ * same thing are probably user errors i Catalogue Creator. However, Catalogue Creator allows the
16
+ * user to let them slip through, so we need to handle them the same way CET does.
17
+ */
18
+ const reduceApplications = (applications, skipNoMtrl = false) => applications.reduce((acc, application) => {
19
+ const { areaTags, mtrl } = application;
20
+ // Applications which have a Mtrl but no AreaTags only have meaning on Option nodes. That
21
+ // specific case is handled separately, so here we require AreaTags to be set.
22
+ if (areaTags === undefined || areaTags.length === 0 || (skipNoMtrl && mtrl === undefined)) {
23
+ return acc;
24
+ }
25
+ const materialSource = mtrl && {
26
+ mtrl,
27
+ source: application,
28
+ overriddenByOption: false,
29
+ };
30
+ for (const areaTag of areaTags) {
31
+ // The rule here is use the first found. This is opposite to the rule when
32
+ // aggregating the tree, where the latest one found is applied
33
+ if (acc.has(areaTag)) {
34
+ continue;
35
+ }
36
+ acc.set(areaTag, materialSource);
37
+ }
38
+ return acc;
39
+ }, new Map());
40
+ export function aggregateAllMaterialApplications(applicationAreas, productMtrlApplications, productConfiguration, debugMtrlApplications = []) {
41
+ const areasToMaterials = new Map();
42
+ for (const [areaTag, mtrlSource] of reduceApplications(applicationAreas)) {
43
+ // When Mtrl is missing there is no fallback to later Applications in the
44
+ // same node. This is consistent with CET
45
+ if (mtrlSource === undefined) {
46
+ continue;
47
+ }
48
+ areasToMaterials.set(areaTag, mtrlSource);
49
+ }
50
+ // On Product level there is fallback if Mtrl is missing, so we pass true
51
+ // to make it skip over Mtrl-less Applications
52
+ for (const [areaTag, mtrlSource] of reduceApplications(productMtrlApplications, true)) {
53
+ if (mtrlSource === undefined) {
54
+ throw new Error("Should not happen");
55
+ }
56
+ areasToMaterials.set(areaTag, mtrlSource);
57
+ }
58
+ // We can not pass areasToMaterials directly to aggregateForFeature. This is because
59
+ // an Application with AreaTags but no Mtrl is effectively a "reset". It's like saying
60
+ // "no material". But that reset should only work for the stuff that comes from the
61
+ // Configuration. So we must make sure we don't touch what we found from Application
62
+ // Areas and Product.
63
+ const configurationAreasToMaterials = new Map();
64
+ for (const feature of productConfiguration.features) {
65
+ // Later always beats deeper
66
+ aggregateForFeature(feature, configurationAreasToMaterials);
67
+ }
68
+ for (const [areaTag, mtrlSource] of configurationAreasToMaterials) {
69
+ areasToMaterials.set(areaTag, mtrlSource);
70
+ }
71
+ // Debug Applications we just let bulldozer over everything else.
72
+ for (const debugMtrlApplication of debugMtrlApplications) {
73
+ const { areaTags, mtrl } = debugMtrlApplication;
74
+ if (mtrl === undefined) {
75
+ continue;
76
+ }
77
+ for (const areaTag of areaTags || []) {
78
+ areasToMaterials.set(areaTag, {
79
+ mtrl: mtrl,
80
+ source: debugMtrlApplication,
81
+ overriddenByOption: false,
82
+ });
83
+ }
84
+ }
85
+ return areasToMaterials;
86
+ }
87
+ /**
88
+ * For this Feature and it's descendants, compile the Applications into the passed areasToMaterials.
89
+ */
90
+ function aggregateForFeature(feature, areasToMaterials, areasOpenForOverrideInOption = new Set()) {
91
+ const featureMtrlApplications = feature._internal.mtrlApplications;
92
+ for (const [areaTag, mtrlSource] of reduceApplications(featureMtrlApplications)) {
93
+ // As soon as a Feature sets an areaTag that tag is allowed to have its value
94
+ // overridden (or set if it didn't have a value from the start) by an option.
95
+ // This option has to have an Application with a Mtrl but no AreaTags.
96
+ // And it can only be done once - the first option found which fulfills the
97
+ // requirements will do the override. The option does not even need to be a
98
+ // descendant of the Feature. After this the value is fixed until
99
+ // a Feature or an Option comes along with the AreaTag set.
100
+ // That will then reset the process, and if it was on a Feature it opens for
101
+ // override again.
102
+ areasOpenForOverrideInOption.add(areaTag);
103
+ if (mtrlSource === undefined) {
104
+ areasToMaterials.delete(areaTag);
105
+ }
106
+ else {
107
+ areasToMaterials.set(areaTag, mtrlSource);
108
+ }
109
+ }
110
+ for (const option of feature.selectedOptions) {
111
+ aggregateForOption(option, areasToMaterials, areasOpenForOverrideInOption);
112
+ }
113
+ }
114
+ function aggregateForOption(option, areasToMaterials, areasOpenForOverrideInOption) {
115
+ const optionMtrlApplications = option._internal.mtrlApplications;
116
+ // The last mtrl with no areaTag can be used for areasOpenForOverrideInOption
117
+ if (areasOpenForOverrideInOption.size !== 0) {
118
+ // Fast backwards loop
119
+ let i = optionMtrlApplications.length;
120
+ while (i--) {
121
+ const optionMtrlApplication = optionMtrlApplications[i];
122
+ const { areaTags, mtrl } = optionMtrlApplication;
123
+ if ((areaTags !== undefined && areaTags.length !== 0) || mtrl === undefined) {
124
+ // Only Applications with a Mtrl but no AreaTags can be used for overrides
125
+ continue;
126
+ }
127
+ const mtrlSource = {
128
+ mtrl,
129
+ source: optionMtrlApplication,
130
+ overriddenByOption: true,
131
+ };
132
+ for (const areaTag of areasOpenForOverrideInOption) {
133
+ areasToMaterials.set(areaTag, mtrlSource);
134
+ }
135
+ areasOpenForOverrideInOption.clear();
136
+ break;
137
+ }
138
+ }
139
+ // reduceApplications will filter out Applications with AreaTags. So there will
140
+ // be no overlap between Applications used for Override and Applications used
141
+ // for immediately setting.
142
+ for (const [areaTag, mtrlSource] of reduceApplications(optionMtrlApplications)) {
143
+ if (mtrlSource === undefined) {
144
+ // An Application on an Option with no Mtrl opens up for a future option
145
+ // to set the Mtrl (the overridden has to be an option with a Mtrl and no Area)
146
+ areasOpenForOverrideInOption.add(areaTag);
147
+ areasToMaterials.delete(areaTag);
148
+ }
149
+ else {
150
+ areasToMaterials.set(areaTag, mtrlSource);
151
+ }
152
+ }
153
+ for (const feature of option.features || []) {
154
+ aggregateForFeature(feature, areasToMaterials, areasOpenForOverrideInOption);
155
+ }
156
+ }
157
+ export function logMtrlSourceWithMetaDataToConsole(mtrlSourceWithMetaData) {
158
+ const tableData = {
159
+ Source: mtrlSourceWithMetaData.source.source,
160
+ OverriddenByOption: mtrlSourceWithMetaData.overriddenByOption ? "Yes" : "No",
161
+ };
162
+ const mtrl = mtrlSourceWithMetaData.mtrl;
163
+ if (mtrl instanceof CfgMtrlSourceUrl) {
164
+ tableData["From prop"] = mtrl.urlIsFromProperty;
165
+ tableData["url"] = mtrl.url;
166
+ }
167
+ if (mtrl instanceof CfgMtrlSourceBuffer) {
168
+ tableData["FileName"] = mtrl.fileName;
169
+ }
170
+ console.table(tableData);
171
+ }
172
+ export function logMaterialMappingToConsole(areasToMaterials) {
173
+ const sorted = Array.from(areasToMaterials);
174
+ sorted.sort((left, right) => left[0].toLocaleLowerCase().localeCompare(right[0].toLocaleLowerCase()));
175
+ for (const areaToMaterial of sorted) {
176
+ const [tag, mtrlSourceWithMetaData] = areaToMaterial;
177
+ console.groupCollapsed(`"${tag}"`);
178
+ logMtrlSourceWithMetaDataToConsole(mtrlSourceWithMetaData);
179
+ console.groupEnd();
180
+ }
181
+ }
@@ -1,19 +1,19 @@
1
- import { ApplicationArea, MtrlApplication } from "../CatalogueAPI.js";
2
- import { CfgMtrlApplicationSource } from "./CfgMtrlApplicationSource.js";
3
- import { CfgMtrlSource } from "./CfgMtrlSource.js";
4
- export declare class CfgMtrlApplication {
5
- private _source;
6
- private _areaTags;
7
- private _mtrl;
8
- private _previewUrl;
9
- static fromUrlForDebug(areaTags: string[], url: string): CfgMtrlApplication;
10
- static fromBufferForDebug(areaTags: string[], fileName: string, buffer: ArrayBuffer): CfgMtrlApplication;
11
- private static fromMtrlSourceForDebug;
12
- static fromMtrlLikeApplication(source: CfgMtrlApplicationSource, application: ApplicationArea | MtrlApplication): CfgMtrlApplication;
13
- private constructor();
14
- get source(): CfgMtrlApplicationSource;
15
- get areaTags(): string[] | undefined;
16
- get mtrl(): CfgMtrlSource | undefined;
17
- get previewUrl(): string | undefined;
18
- }
1
+ import { ApplicationArea, MtrlApplication } from "../CatalogueAPI.js";
2
+ import { CfgMtrlApplicationSource } from "./CfgMtrlApplicationSource.js";
3
+ import { CfgMtrlSource } from "./CfgMtrlSource.js";
4
+ export declare class CfgMtrlApplication {
5
+ private _source;
6
+ private _areaTags;
7
+ private _mtrl;
8
+ private _previewUrl;
9
+ static fromUrlForDebug(areaTags: string[], url: string): CfgMtrlApplication;
10
+ static fromBufferForDebug(areaTags: string[], fileName: string, buffer: ArrayBuffer): CfgMtrlApplication;
11
+ private static fromMtrlSourceForDebug;
12
+ static fromMtrlLikeApplication(source: CfgMtrlApplicationSource, application: ApplicationArea | MtrlApplication): CfgMtrlApplication;
13
+ private constructor();
14
+ get source(): CfgMtrlApplicationSource;
15
+ get areaTags(): string[] | undefined;
16
+ get mtrl(): CfgMtrlSource | undefined;
17
+ get previewUrl(): string | undefined;
18
+ }
19
19
  //# sourceMappingURL=CfgMtrlApplication.d.ts.map
@@ -1,43 +1,43 @@
1
- import { CfgMtrlApplicationSource } from "./CfgMtrlApplicationSource.js";
2
- import { CfgMtrlSourceBuffer, CfgMtrlSourceUrl } from "./CfgMtrlSource.js";
3
- export class CfgMtrlApplication {
4
- constructor(_source, _areaTags, _mtrl, _previewUrl) {
5
- this._source = _source;
6
- this._areaTags = _areaTags;
7
- this._mtrl = _mtrl;
8
- this._previewUrl = _previewUrl;
9
- }
10
- static fromUrlForDebug(areaTags, url) {
11
- return this.fromMtrlSourceForDebug(areaTags, new CfgMtrlSourceUrl(url, "debug"));
12
- }
13
- static fromBufferForDebug(areaTags, fileName, buffer) {
14
- return this.fromMtrlSourceForDebug(areaTags, new CfgMtrlSourceBuffer(fileName, buffer));
15
- }
16
- static fromMtrlSourceForDebug(areaTags, mtrlSource) {
17
- const ts = areaTags.filter((t) => t.trim() !== "");
18
- if (ts.length === 0) {
19
- throw Error("No tags");
20
- }
21
- return new this(CfgMtrlApplicationSource.Debug, areaTags, mtrlSource, undefined);
22
- }
23
- static fromMtrlLikeApplication(source, application) {
24
- const materialUrl = application.material;
25
- const previewUrl = application.preview;
26
- const url = materialUrl || previewUrl;
27
- const urlIsFromProperty = materialUrl ? "material" : "preview";
28
- const mtrl = url ? new CfgMtrlSourceUrl(url, urlIsFromProperty) : undefined;
29
- return new this(source, application.areas, mtrl, previewUrl);
30
- }
31
- get source() {
32
- return this._source;
33
- }
34
- get areaTags() {
35
- return this._areaTags;
36
- }
37
- get mtrl() {
38
- return this._mtrl;
39
- }
40
- get previewUrl() {
41
- return this._previewUrl;
42
- }
43
- }
1
+ import { CfgMtrlApplicationSource } from "./CfgMtrlApplicationSource.js";
2
+ import { CfgMtrlSourceBuffer, CfgMtrlSourceUrl } from "./CfgMtrlSource.js";
3
+ export class CfgMtrlApplication {
4
+ constructor(_source, _areaTags, _mtrl, _previewUrl) {
5
+ this._source = _source;
6
+ this._areaTags = _areaTags;
7
+ this._mtrl = _mtrl;
8
+ this._previewUrl = _previewUrl;
9
+ }
10
+ static fromUrlForDebug(areaTags, url) {
11
+ return this.fromMtrlSourceForDebug(areaTags, new CfgMtrlSourceUrl(url, "debug"));
12
+ }
13
+ static fromBufferForDebug(areaTags, fileName, buffer) {
14
+ return this.fromMtrlSourceForDebug(areaTags, new CfgMtrlSourceBuffer(fileName, buffer));
15
+ }
16
+ static fromMtrlSourceForDebug(areaTags, mtrlSource) {
17
+ const ts = areaTags.filter((t) => t.trim() !== "");
18
+ if (ts.length === 0) {
19
+ throw Error("No tags");
20
+ }
21
+ return new this(CfgMtrlApplicationSource.Debug, areaTags, mtrlSource, undefined);
22
+ }
23
+ static fromMtrlLikeApplication(source, application) {
24
+ const materialUrl = application.material;
25
+ const previewUrl = application.preview;
26
+ const url = materialUrl || previewUrl;
27
+ const urlIsFromProperty = materialUrl ? "material" : "preview";
28
+ const mtrl = url ? new CfgMtrlSourceUrl(url, urlIsFromProperty) : undefined;
29
+ return new this(source, application.areas, mtrl, previewUrl);
30
+ }
31
+ get source() {
32
+ return this._source;
33
+ }
34
+ get areaTags() {
35
+ return this._areaTags;
36
+ }
37
+ get mtrl() {
38
+ return this._mtrl;
39
+ }
40
+ get previewUrl() {
41
+ return this._previewUrl;
42
+ }
43
+ }
@@ -1,8 +1,8 @@
1
- export declare enum CfgMtrlApplicationSource {
2
- ApplicationArea = "ApplicationArea",
3
- Product = "Product",
4
- Feature = "Feature",
5
- Option = "Option",
6
- Debug = "Debug"
7
- }
1
+ export declare enum CfgMtrlApplicationSource {
2
+ ApplicationArea = "ApplicationArea",
3
+ Product = "Product",
4
+ Feature = "Feature",
5
+ Option = "Option",
6
+ Debug = "Debug"
7
+ }
8
8
  //# sourceMappingURL=CfgMtrlApplicationSource.d.ts.map
@@ -1,8 +1,8 @@
1
- export var CfgMtrlApplicationSource;
2
- (function (CfgMtrlApplicationSource) {
3
- CfgMtrlApplicationSource["ApplicationArea"] = "ApplicationArea";
4
- CfgMtrlApplicationSource["Product"] = "Product";
5
- CfgMtrlApplicationSource["Feature"] = "Feature";
6
- CfgMtrlApplicationSource["Option"] = "Option";
7
- CfgMtrlApplicationSource["Debug"] = "Debug";
8
- })(CfgMtrlApplicationSource || (CfgMtrlApplicationSource = {}));
1
+ export var CfgMtrlApplicationSource;
2
+ (function (CfgMtrlApplicationSource) {
3
+ CfgMtrlApplicationSource["ApplicationArea"] = "ApplicationArea";
4
+ CfgMtrlApplicationSource["Product"] = "Product";
5
+ CfgMtrlApplicationSource["Feature"] = "Feature";
6
+ CfgMtrlApplicationSource["Option"] = "Option";
7
+ CfgMtrlApplicationSource["Debug"] = "Debug";
8
+ })(CfgMtrlApplicationSource || (CfgMtrlApplicationSource = {}));