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