@configura/web-api 1.2.1 → 1.3.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +1 -1
  3. package/dist/CatalogueAPI.d.ts +448 -448
  4. package/dist/CatalogueAPI.js +206 -206
  5. package/dist/CfgProduct.d.ts +116 -116
  6. package/dist/CfgProduct.js +588 -588
  7. package/dist/index.d.ts +15 -15
  8. package/dist/index.js +15 -15
  9. package/dist/material/CfgMaterialMapping.d.ts +7 -7
  10. package/dist/material/CfgMaterialMapping.js +176 -176
  11. package/dist/material/CfgMtrlApplication.d.ts +18 -18
  12. package/dist/material/CfgMtrlApplication.js +43 -43
  13. package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
  14. package/dist/material/CfgMtrlApplicationSource.js +8 -8
  15. package/dist/material/CfgMtrlSource.d.ts +19 -19
  16. package/dist/material/CfgMtrlSource.js +40 -40
  17. package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
  18. package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
  19. package/dist/productConfiguration/CfgFeature.d.ts +134 -134
  20. package/dist/productConfiguration/CfgFeature.js +483 -483
  21. package/dist/productConfiguration/CfgOption.d.ts +112 -112
  22. package/dist/productConfiguration/CfgOption.js +293 -293
  23. package/dist/productConfiguration/CfgProductConfiguration.d.ts +50 -50
  24. package/dist/productConfiguration/CfgProductConfiguration.js +198 -198
  25. package/dist/productConfiguration/filters.d.ts +7 -7
  26. package/dist/productConfiguration/filters.js +29 -29
  27. package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
  28. package/dist/productConfiguration/productParamsGenerator.js +51 -51
  29. package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +9 -9
  30. package/dist/productConfiguration/utilitiesProductConfiguration.js +61 -61
  31. package/dist/productLoader.d.ts +11 -11
  32. package/dist/productLoader.js +41 -41
  33. package/dist/tests/testData/collectorForTest.d.ts +73 -73
  34. package/dist/tests/testData/collectorForTest.js +195 -195
  35. package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
  36. package/dist/tests/testData/dummyProductForTest.js +35 -35
  37. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +32 -32
  38. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +368 -368
  39. package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
  40. package/dist/tests/testData/testDataCachedGetProduct.js +199 -199
  41. package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
  42. package/dist/tests/testData/testDataCachedPostValidate.js +189 -189
  43. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
  44. package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1117 -1117
  45. package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +28 -28
  46. package/dist/tests/testData/testDataProductAggregatedPrice.js +205 -205
  47. package/dist/tests/testData/testDataUpcharge.d.ts +29 -29
  48. package/dist/tests/testData/testDataUpcharge.js +159 -159
  49. package/dist/utilitiesCatalogueData.d.ts +20 -18
  50. package/dist/utilitiesCatalogueData.js +64 -56
  51. package/dist/utilitiesCataloguePermission.d.ts +39 -39
  52. package/dist/utilitiesCataloguePermission.js +84 -84
  53. package/package.json +3 -3
@@ -1,51 +1,51 @@
1
- import { Observable, SingleArgCallback } from "@configura/web-utilities";
2
- import { Feature, FeatureRef, SelectedOption } from "../CatalogueAPI.js";
3
- import { CfgProduct, _CfgProductInternal } from "../CfgProduct.js";
4
- import { CfgFeature, _CfgFeatureInternal } from "./CfgFeature.js";
5
- import { ProductConfigurationBubbleMode } from "./CfgOption.js";
6
- export declare type ProductConfigurationChangeNotification = {
7
- freshRef: CfgProductConfiguration;
8
- };
9
- export declare class _CfgProductConfigurationInternal {
10
- readonly allRawFeatures: Feature[];
11
- readonly parentProduct: _CfgProductInternal;
12
- readonly rootProduct: _CfgProductInternal;
13
- static _makeUninitialized: (rootFeatureRefs: FeatureRef[], allRawFeatures: Feature[], parentProduct: _CfgProductInternal, rootProduct: _CfgProductInternal) => _CfgProductConfigurationInternal;
14
- private constructor();
15
- readonly key = "~";
16
- private _rootFeatureRefs;
17
- private _features;
18
- readonly changeObservable: Observable<ProductConfigurationChangeNotification>;
19
- get rootFeatureRefs(): FeatureRef[];
20
- get features(): CfgFeature[];
21
- private _notifyAllOfChange;
22
- _freshRefDescendants(): void;
23
- _childHasChanged: (freshRef: CfgFeature, bubbleMode: ProductConfigurationBubbleMode) => Promise<void>;
24
- getApiSelection: () => SelectedOption[];
25
- setApiSelection: (selectedOptions: SelectedOption[], bubbleToRoot: boolean) => Promise<boolean>;
26
- structureCompare: (other: _CfgProductConfigurationInternal, strictOrder?: boolean, descriptionMatch?: boolean) => boolean;
27
- tryMatchSelection: (other: _CfgProductConfigurationInternal, descriptionMatch: boolean | undefined, validate: boolean) => Promise<boolean>;
28
- _getFeaturesWithCode: (code: string) => _CfgFeatureInternal[];
29
- populateFeatures: (rootFeatureRefs: FeatureRef[]) => void;
30
- }
31
- export declare class CfgProductConfiguration {
32
- readonly _internal: _CfgProductConfigurationInternal;
33
- static make: (initSuccess: (c: CfgProductConfiguration) => void, initFail: (error: Error) => void, rootFeatureRefs: FeatureRef[], allRawFeatures: Feature[], apiSelection: SelectedOption[], parentProduct: _CfgProductInternal, rootProduct: _CfgProductInternal) => CfgProductConfiguration;
34
- static _makeNewRefFrom: (internal: _CfgProductConfigurationInternal) => CfgProductConfiguration;
35
- private constructor();
36
- isBackedBySame: (other: CfgProductConfiguration) => boolean;
37
- get parentProduct(): CfgProduct;
38
- get rootProduct(): CfgProduct;
39
- get key(): string;
40
- get allRawFeatures(): Feature[];
41
- get rootFeatureRefs(): FeatureRef[];
42
- get features(): CfgFeature[];
43
- structureCompare: (other: CfgProductConfiguration, strictOrder?: boolean, descriptionMatch?: boolean) => boolean;
44
- tryMatchSelection: (other: CfgProductConfiguration, descriptionMatch?: boolean) => Promise<boolean>;
45
- getApiSelection: () => SelectedOption[];
46
- setApiSelection: (selectedOptions: SelectedOption[]) => Promise<boolean>;
47
- listenForChange: (l: SingleArgCallback<ProductConfigurationChangeNotification>) => void;
48
- stopListenForChange: (l: SingleArgCallback<ProductConfigurationChangeNotification>) => void;
49
- stopAllListenForChange: () => void;
50
- }
1
+ import { Observable, SingleArgCallback } from "@configura/web-utilities";
2
+ import { Feature, FeatureRef, SelectedOption } from "../CatalogueAPI.js";
3
+ import { CfgProduct, _CfgProductInternal } from "../CfgProduct.js";
4
+ import { CfgFeature, _CfgFeatureInternal } from "./CfgFeature.js";
5
+ import { ProductConfigurationBubbleMode } from "./CfgOption.js";
6
+ export declare type ProductConfigurationChangeNotification = {
7
+ freshRef: CfgProductConfiguration;
8
+ };
9
+ export declare class _CfgProductConfigurationInternal {
10
+ readonly allRawFeatures: Feature[];
11
+ readonly parentProduct: _CfgProductInternal;
12
+ readonly rootProduct: _CfgProductInternal;
13
+ static _makeUninitialized: (rootFeatureRefs: FeatureRef[], allRawFeatures: Feature[], parentProduct: _CfgProductInternal, rootProduct: _CfgProductInternal) => _CfgProductConfigurationInternal;
14
+ private constructor();
15
+ readonly key = "~";
16
+ private _rootFeatureRefs;
17
+ private _features;
18
+ readonly changeObservable: Observable<ProductConfigurationChangeNotification>;
19
+ get rootFeatureRefs(): FeatureRef[];
20
+ get features(): CfgFeature[];
21
+ private _notifyAllOfChange;
22
+ _freshRefDescendants(): void;
23
+ _childHasChanged: (freshRef: CfgFeature, bubbleMode: ProductConfigurationBubbleMode) => Promise<void>;
24
+ getApiSelection: () => SelectedOption[];
25
+ setApiSelection: (selectedOptions: SelectedOption[], bubbleToRoot: boolean) => Promise<boolean>;
26
+ structureCompare: (other: _CfgProductConfigurationInternal, strictOrder?: boolean, descriptionMatch?: boolean) => boolean;
27
+ tryMatchSelection: (other: _CfgProductConfigurationInternal, descriptionMatch: boolean | undefined, validate: boolean) => Promise<boolean>;
28
+ _getFeaturesWithCode: (code: string) => _CfgFeatureInternal[];
29
+ populateFeatures: (rootFeatureRefs: FeatureRef[]) => void;
30
+ }
31
+ export declare class CfgProductConfiguration {
32
+ readonly _internal: _CfgProductConfigurationInternal;
33
+ static make: (initSuccess: (c: CfgProductConfiguration) => void, initFail: (error: Error) => void, rootFeatureRefs: FeatureRef[], allRawFeatures: Feature[], apiSelection: SelectedOption[], parentProduct: _CfgProductInternal, rootProduct: _CfgProductInternal) => CfgProductConfiguration;
34
+ static _makeNewRefFrom: (internal: _CfgProductConfigurationInternal) => CfgProductConfiguration;
35
+ private constructor();
36
+ isBackedBySame: (other: CfgProductConfiguration) => boolean;
37
+ get parentProduct(): CfgProduct;
38
+ get rootProduct(): CfgProduct;
39
+ get key(): string;
40
+ get allRawFeatures(): Feature[];
41
+ get rootFeatureRefs(): FeatureRef[];
42
+ get features(): CfgFeature[];
43
+ structureCompare: (other: CfgProductConfiguration, strictOrder?: boolean, descriptionMatch?: boolean) => boolean;
44
+ tryMatchSelection: (other: CfgProductConfiguration, descriptionMatch?: boolean) => Promise<boolean>;
45
+ getApiSelection: () => SelectedOption[];
46
+ setApiSelection: (selectedOptions: SelectedOption[]) => Promise<boolean>;
47
+ listenForChange: (l: SingleArgCallback<ProductConfigurationChangeNotification>) => void;
48
+ stopListenForChange: (l: SingleArgCallback<ProductConfigurationChangeNotification>) => void;
49
+ stopAllListenForChange: () => void;
50
+ }
51
51
  //# sourceMappingURL=CfgProductConfiguration.d.ts.map
@@ -1,198 +1,198 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { compareArrays, count, Observable, toError, } from "@configura/web-utilities";
11
- import { CfgProduct } from "../CfgProduct.js";
12
- import { CfgFeature } from "./CfgFeature.js";
13
- import { ProductConfigurationBubbleMode } from "./CfgOption.js";
14
- import { syncCfgFeatures } from "./utilitiesProductConfiguration.js";
15
- /// This class is meant to only be used through CfgProductConfiguration. It should
16
- /// never be instantiated on its own. Normally the internal state of this class
17
- /// should never be directly modified. CfgProductConfiguration is the class that
18
- /// should be used and interacted with.
19
- export class _CfgProductConfigurationInternal {
20
- constructor(allRawFeatures, // Flat packed. All the features that can appear anyplace in the selection tree.
21
- parentProduct, rootProduct) {
22
- this.allRawFeatures = allRawFeatures;
23
- this.parentProduct = parentProduct;
24
- this.rootProduct = rootProduct;
25
- this.key = "~";
26
- this._rootFeatureRefs = [];
27
- this._features = [];
28
- this.changeObservable = new Observable();
29
- this._notifyAllOfChange = (bubbleMode) => __awaiter(this, void 0, void 0, function* () {
30
- if (bubbleMode === ProductConfigurationBubbleMode.Stop) {
31
- return;
32
- }
33
- const freshRef = CfgProductConfiguration._makeNewRefFrom(this);
34
- const parent = this.parentProduct;
35
- this.changeObservable.notifyAll({
36
- freshRef,
37
- });
38
- if (parent === undefined) {
39
- return;
40
- }
41
- yield parent._configurationHasChanged(freshRef, bubbleMode === ProductConfigurationBubbleMode.OneLevel
42
- ? ProductConfigurationBubbleMode.Stop
43
- : bubbleMode);
44
- });
45
- /// Called by child to tell its parent that it has changed.
46
- this._childHasChanged = (freshRef, bubbleMode) => __awaiter(this, void 0, void 0, function* () {
47
- const features = this._features;
48
- const i = features.findIndex((a) => a.isBackedBySame(freshRef));
49
- if (i === -1) {
50
- throw Error("Child feature not found");
51
- }
52
- features[i] = freshRef;
53
- yield this._notifyAllOfChange(bubbleMode);
54
- });
55
- this.getApiSelection = () => this._features.map((f) => {
56
- return { code: "!~!", next: f._internal.getApiSelection() };
57
- });
58
- /// When used internally the notifications are taken care off by the caller,
59
- /// but if set from outside we want notifications to bubble all the way to the root
60
- this.setApiSelection = (selectedOptions, bubbleToRoot) => __awaiter(this, void 0, void 0, function* () {
61
- const featuresLength = this._features.length;
62
- const selectedOptionsLength = selectedOptions.length;
63
- if (featuresLength !== selectedOptionsLength) {
64
- throw new Error(`Wrong selection count. Features on this configuration: ${featuresLength}. Passed feature count: ${selectedOptionsLength}.`);
65
- }
66
- const change = (yield Promise.all(this._features.map((f, i) => f._internal.setApiSelection(selectedOptions[i].next)))).some((b) => b);
67
- if (change) {
68
- yield this._notifyAllOfChange(bubbleToRoot
69
- ? ProductConfigurationBubbleMode.ToRoot
70
- : ProductConfigurationBubbleMode.OneLevel);
71
- }
72
- return change;
73
- });
74
- this.structureCompare = (other, strictOrder = true, descriptionMatch = false) => compareArrays(this.features, other.features, (l, r) => l._internal.structureCompare(r._internal, strictOrder, descriptionMatch), strictOrder);
75
- /// When used internally the notifications are taken care off by the caller,
76
- /// but if set from outside we want notifications to bubble all the way to the root
77
- this.tryMatchSelection = (other, descriptionMatch = false, // Match on case insensitive description, not code
78
- validate) => __awaiter(this, void 0, void 0, function* () {
79
- const thisFeatures = this.features;
80
- const otherFeatures = other.features;
81
- const change = (yield Promise.all(otherFeatures.map((otherF) => (() => __awaiter(this, void 0, void 0, function* () {
82
- if (1 <
83
- count(otherFeatures, (item) => item._internal.keyMatch(otherF._internal, descriptionMatch))) {
84
- console.warn("tryMatchSelection will ignore items with same key");
85
- return false;
86
- }
87
- const toSetFeatures = thisFeatures.filter((f) => f._internal.keyMatch(otherF._internal, descriptionMatch));
88
- if (1 < toSetFeatures.length) {
89
- console.warn("tryMatchSelection will ignore items with same key");
90
- return false;
91
- }
92
- if (toSetFeatures.length === 0) {
93
- return false;
94
- }
95
- return yield toSetFeatures[0]._internal.tryMatchSelection(otherF._internal, descriptionMatch);
96
- }))()))).some((b) => b);
97
- if (change) {
98
- yield this._notifyAllOfChange(validate
99
- ? ProductConfigurationBubbleMode.Validate
100
- : ProductConfigurationBubbleMode.OneLevel);
101
- }
102
- return change;
103
- });
104
- /// Only selected features
105
- this._getFeaturesWithCode = (code) => this._features.reduce((agg, feature) => {
106
- agg.push(...feature._internal._getFeaturesWithCode(code));
107
- return agg;
108
- }, []);
109
- this.populateFeatures = (rootFeatureRefs) => {
110
- this._rootFeatureRefs = rootFeatureRefs;
111
- this._features = syncCfgFeatures(rootFeatureRefs, this._features, this.allRawFeatures, this, this.parentProduct, this.rootProduct);
112
- };
113
- }
114
- get rootFeatureRefs() {
115
- return this._rootFeatureRefs;
116
- }
117
- // The root features at the root of the selection tree.
118
- get features() {
119
- return this._features;
120
- }
121
- _freshRefDescendants() {
122
- const features = this._features;
123
- for (let i = 0; i < features.length; i++) {
124
- const featureInternal = features[i]._internal;
125
- featureInternal._freshRefDescendants();
126
- features[i] = CfgFeature._makeNewRefFrom(featureInternal);
127
- }
128
- }
129
- }
130
- _CfgProductConfigurationInternal._makeUninitialized = (rootFeatureRefs, allRawFeatures, // Flat packed. All the features that can appear anyplace in the selection tree.
131
- parentProduct, rootProduct) => {
132
- const configuration = new _CfgProductConfigurationInternal(allRawFeatures, parentProduct, rootProduct);
133
- configuration.populateFeatures(rootFeatureRefs);
134
- return configuration;
135
- };
136
- export class CfgProductConfiguration {
137
- /// Private constructor and make-method because make new ref requires the constructor to
138
- /// take an internal and we don't want those who instantiate CfgProductConfiguration to
139
- /// have to be aware of the internal.
140
- constructor(_internal) {
141
- this._internal = _internal;
142
- this.isBackedBySame = (other) => this._internal === other._internal;
143
- this.structureCompare = (other, strictOrder = true, descriptionMatch = false) => this._internal.structureCompare(other._internal, strictOrder, descriptionMatch);
144
- /// This method will try to match the selection from another product configuration
145
- /// This method does not propagate its selections.
146
- /// This method will cause validation calls.
147
- this.tryMatchSelection = (other, descriptionMatch = false // Match on case insensitive description, not code
148
- ) => __awaiter(this, void 0, void 0, function* () { return yield this._internal.tryMatchSelection(other._internal, descriptionMatch, true); });
149
- this.getApiSelection = () => this._internal.getApiSelection();
150
- /// This method does not propagate its selections.
151
- /// This method will not cause validation calls. Data is assumed to already be validated.
152
- this.setApiSelection = (selectedOptions) => __awaiter(this, void 0, void 0, function* () { return yield this._internal.setApiSelection(selectedOptions, true); });
153
- this.listenForChange = (l) => this._internal.changeObservable.listen(l);
154
- this.stopListenForChange = (l) => this._internal.changeObservable.stopListen(l);
155
- this.stopAllListenForChange = () => this._internal.changeObservable.stopAllListen();
156
- }
157
- get parentProduct() {
158
- return CfgProduct._makeNewRefFrom(this._internal.parentProduct);
159
- }
160
- get rootProduct() {
161
- return CfgProduct._makeNewRefFrom(this._internal.rootProduct);
162
- }
163
- get key() {
164
- return this._internal.key;
165
- }
166
- /// Every (unprocessed) feature which might be used in this product. This is constant for a
167
- /// product load. What features are actually used is controlled by rootFeatureRefs
168
- /// and what options are selected.
169
- get allRawFeatures() {
170
- return this._internal.allRawFeatures;
171
- }
172
- /// What features are used in the root of this. This can change with new validate calls.
173
- get rootFeatureRefs() {
174
- return this._internal.rootFeatureRefs;
175
- }
176
- /// The root features at the root of the selection tree.
177
- get features() {
178
- return this._internal.features;
179
- }
180
- }
181
- /// This method is semi-async. It will immediately give you a reference to the created
182
- /// CfgProductConfiguration, but is not properly initialized until the initDone-callback
183
- /// has been called.
184
- CfgProductConfiguration.make = (initSuccess, initFail, rootFeatureRefs, allRawFeatures, // Flat packed. All the features that can appear anyplace in the selection tree.
185
- apiSelection, parentProduct, rootProduct) => {
186
- const internal = _CfgProductConfigurationInternal._makeUninitialized(rootFeatureRefs, allRawFeatures, parentProduct, rootProduct);
187
- const external = new CfgProductConfiguration(internal);
188
- // Note the async-callback at the end of the following line. The call is async.
189
- internal
190
- .setApiSelection(apiSelection, false)
191
- .then(() => initSuccess(external))
192
- .catch((e) => initFail(toError(e)));
193
- return external;
194
- };
195
- /// Makes an object wrapping the passed object. This is not a clone method,
196
- /// it is a method to make a new outer reference. Like a shallow copy.
197
- /// We use this to help frameworks that are built around using equals to detect change.
198
- CfgProductConfiguration._makeNewRefFrom = (internal) => new CfgProductConfiguration(internal);
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { compareArrays, count, Observable, toError, } from "@configura/web-utilities";
11
+ import { CfgProduct } from "../CfgProduct.js";
12
+ import { CfgFeature } from "./CfgFeature.js";
13
+ import { ProductConfigurationBubbleMode } from "./CfgOption.js";
14
+ import { syncCfgFeatures } from "./utilitiesProductConfiguration.js";
15
+ /// This class is meant to only be used through CfgProductConfiguration. It should
16
+ /// never be instantiated on its own. Normally the internal state of this class
17
+ /// should never be directly modified. CfgProductConfiguration is the class that
18
+ /// should be used and interacted with.
19
+ export class _CfgProductConfigurationInternal {
20
+ constructor(allRawFeatures, // Flat packed. All the features that can appear anyplace in the selection tree.
21
+ parentProduct, rootProduct) {
22
+ this.allRawFeatures = allRawFeatures;
23
+ this.parentProduct = parentProduct;
24
+ this.rootProduct = rootProduct;
25
+ this.key = "~";
26
+ this._rootFeatureRefs = [];
27
+ this._features = [];
28
+ this.changeObservable = new Observable();
29
+ this._notifyAllOfChange = (bubbleMode) => __awaiter(this, void 0, void 0, function* () {
30
+ if (bubbleMode === ProductConfigurationBubbleMode.Stop) {
31
+ return;
32
+ }
33
+ const freshRef = CfgProductConfiguration._makeNewRefFrom(this);
34
+ const parent = this.parentProduct;
35
+ this.changeObservable.notifyAll({
36
+ freshRef,
37
+ });
38
+ if (parent === undefined) {
39
+ return;
40
+ }
41
+ yield parent._configurationHasChanged(freshRef, bubbleMode === ProductConfigurationBubbleMode.OneLevel
42
+ ? ProductConfigurationBubbleMode.Stop
43
+ : bubbleMode);
44
+ });
45
+ /// Called by child to tell its parent that it has changed.
46
+ this._childHasChanged = (freshRef, bubbleMode) => __awaiter(this, void 0, void 0, function* () {
47
+ const features = this._features;
48
+ const i = features.findIndex((a) => a.isBackedBySame(freshRef));
49
+ if (i === -1) {
50
+ throw Error("Child feature not found");
51
+ }
52
+ features[i] = freshRef;
53
+ yield this._notifyAllOfChange(bubbleMode);
54
+ });
55
+ this.getApiSelection = () => this._features.map((f) => {
56
+ return { code: "!~!", next: f._internal.getApiSelection() };
57
+ });
58
+ /// When used internally the notifications are taken care off by the caller,
59
+ /// but if set from outside we want notifications to bubble all the way to the root
60
+ this.setApiSelection = (selectedOptions, bubbleToRoot) => __awaiter(this, void 0, void 0, function* () {
61
+ const featuresLength = this._features.length;
62
+ const selectedOptionsLength = selectedOptions.length;
63
+ if (featuresLength !== selectedOptionsLength) {
64
+ throw new Error(`Wrong selection count. Features on this configuration: ${featuresLength}. Passed feature count: ${selectedOptionsLength}.`);
65
+ }
66
+ const change = (yield Promise.all(this._features.map((f, i) => f._internal.setApiSelection(selectedOptions[i].next)))).some((b) => b);
67
+ if (change) {
68
+ yield this._notifyAllOfChange(bubbleToRoot
69
+ ? ProductConfigurationBubbleMode.ToRoot
70
+ : ProductConfigurationBubbleMode.OneLevel);
71
+ }
72
+ return change;
73
+ });
74
+ this.structureCompare = (other, strictOrder = true, descriptionMatch = false) => compareArrays(this.features, other.features, (l, r) => l._internal.structureCompare(r._internal, strictOrder, descriptionMatch), strictOrder);
75
+ /// When used internally the notifications are taken care off by the caller,
76
+ /// but if set from outside we want notifications to bubble all the way to the root
77
+ this.tryMatchSelection = (other, descriptionMatch = false, // Match on case insensitive description, not code
78
+ validate) => __awaiter(this, void 0, void 0, function* () {
79
+ const thisFeatures = this.features;
80
+ const otherFeatures = other.features;
81
+ const change = (yield Promise.all(otherFeatures.map((otherF) => (() => __awaiter(this, void 0, void 0, function* () {
82
+ if (1 <
83
+ count(otherFeatures, (item) => item._internal.keyMatch(otherF._internal, descriptionMatch))) {
84
+ console.warn("tryMatchSelection will ignore items with same key");
85
+ return false;
86
+ }
87
+ const toSetFeatures = thisFeatures.filter((f) => f._internal.keyMatch(otherF._internal, descriptionMatch));
88
+ if (1 < toSetFeatures.length) {
89
+ console.warn("tryMatchSelection will ignore items with same key");
90
+ return false;
91
+ }
92
+ if (toSetFeatures.length === 0) {
93
+ return false;
94
+ }
95
+ return yield toSetFeatures[0]._internal.tryMatchSelection(otherF._internal, descriptionMatch);
96
+ }))()))).some((b) => b);
97
+ if (change) {
98
+ yield this._notifyAllOfChange(validate
99
+ ? ProductConfigurationBubbleMode.Validate
100
+ : ProductConfigurationBubbleMode.OneLevel);
101
+ }
102
+ return change;
103
+ });
104
+ /// Only selected features
105
+ this._getFeaturesWithCode = (code) => this._features.reduce((agg, feature) => {
106
+ agg.push(...feature._internal._getFeaturesWithCode(code));
107
+ return agg;
108
+ }, []);
109
+ this.populateFeatures = (rootFeatureRefs) => {
110
+ this._rootFeatureRefs = rootFeatureRefs;
111
+ this._features = syncCfgFeatures(rootFeatureRefs, this._features, this.allRawFeatures, this, this.parentProduct, this.rootProduct);
112
+ };
113
+ }
114
+ get rootFeatureRefs() {
115
+ return this._rootFeatureRefs;
116
+ }
117
+ // The root features at the root of the selection tree.
118
+ get features() {
119
+ return this._features;
120
+ }
121
+ _freshRefDescendants() {
122
+ const features = this._features;
123
+ for (let i = 0; i < features.length; i++) {
124
+ const featureInternal = features[i]._internal;
125
+ featureInternal._freshRefDescendants();
126
+ features[i] = CfgFeature._makeNewRefFrom(featureInternal);
127
+ }
128
+ }
129
+ }
130
+ _CfgProductConfigurationInternal._makeUninitialized = (rootFeatureRefs, allRawFeatures, // Flat packed. All the features that can appear anyplace in the selection tree.
131
+ parentProduct, rootProduct) => {
132
+ const configuration = new _CfgProductConfigurationInternal(allRawFeatures, parentProduct, rootProduct);
133
+ configuration.populateFeatures(rootFeatureRefs);
134
+ return configuration;
135
+ };
136
+ export class CfgProductConfiguration {
137
+ /// Private constructor and make-method because make new ref requires the constructor to
138
+ /// take an internal and we don't want those who instantiate CfgProductConfiguration to
139
+ /// have to be aware of the internal.
140
+ constructor(_internal) {
141
+ this._internal = _internal;
142
+ this.isBackedBySame = (other) => this._internal === other._internal;
143
+ this.structureCompare = (other, strictOrder = true, descriptionMatch = false) => this._internal.structureCompare(other._internal, strictOrder, descriptionMatch);
144
+ /// This method will try to match the selection from another product configuration
145
+ /// This method does not propagate its selections.
146
+ /// This method will cause validation calls.
147
+ this.tryMatchSelection = (other, descriptionMatch = false // Match on case insensitive description, not code
148
+ ) => __awaiter(this, void 0, void 0, function* () { return yield this._internal.tryMatchSelection(other._internal, descriptionMatch, true); });
149
+ this.getApiSelection = () => this._internal.getApiSelection();
150
+ /// This method does not propagate its selections.
151
+ /// This method will not cause validation calls. Data is assumed to already be validated.
152
+ this.setApiSelection = (selectedOptions) => __awaiter(this, void 0, void 0, function* () { return yield this._internal.setApiSelection(selectedOptions, true); });
153
+ this.listenForChange = (l) => this._internal.changeObservable.listen(l);
154
+ this.stopListenForChange = (l) => this._internal.changeObservable.stopListen(l);
155
+ this.stopAllListenForChange = () => this._internal.changeObservable.stopAllListen();
156
+ }
157
+ get parentProduct() {
158
+ return CfgProduct._makeNewRefFrom(this._internal.parentProduct);
159
+ }
160
+ get rootProduct() {
161
+ return CfgProduct._makeNewRefFrom(this._internal.rootProduct);
162
+ }
163
+ get key() {
164
+ return this._internal.key;
165
+ }
166
+ /// Every (unprocessed) feature which might be used in this product. This is constant for a
167
+ /// product load. What features are actually used is controlled by rootFeatureRefs
168
+ /// and what options are selected.
169
+ get allRawFeatures() {
170
+ return this._internal.allRawFeatures;
171
+ }
172
+ /// What features are used in the root of this. This can change with new validate calls.
173
+ get rootFeatureRefs() {
174
+ return this._internal.rootFeatureRefs;
175
+ }
176
+ /// The root features at the root of the selection tree.
177
+ get features() {
178
+ return this._internal.features;
179
+ }
180
+ }
181
+ /// This method is semi-async. It will immediately give you a reference to the created
182
+ /// CfgProductConfiguration, but is not properly initialized until the initDone-callback
183
+ /// has been called.
184
+ CfgProductConfiguration.make = (initSuccess, initFail, rootFeatureRefs, allRawFeatures, // Flat packed. All the features that can appear anyplace in the selection tree.
185
+ apiSelection, parentProduct, rootProduct) => {
186
+ const internal = _CfgProductConfigurationInternal._makeUninitialized(rootFeatureRefs, allRawFeatures, parentProduct, rootProduct);
187
+ const external = new CfgProductConfiguration(internal);
188
+ // Note the async-callback at the end of the following line. The call is async.
189
+ internal
190
+ .setApiSelection(apiSelection, false)
191
+ .then(() => initSuccess(external))
192
+ .catch((e) => initFail(toError(e)));
193
+ return external;
194
+ };
195
+ /// Makes an object wrapping the passed object. This is not a clone method,
196
+ /// it is a method to make a new outer reference. Like a shallow copy.
197
+ /// We use this to help frameworks that are built around using equals to detect change.
198
+ CfgProductConfiguration._makeNewRefFrom = (internal) => new CfgProductConfiguration(internal);
@@ -1,8 +1,8 @@
1
- import { Filters, Matches } from "@configura/web-utilities";
2
- import { CatalogueParams, ProductRef } from "../CatalogueAPI.js";
3
- export declare function applyCatalogueFilters(filters: Filters<CatalogueParams>, catalogues: CatalogueParams[]): [Matches<CatalogueParams>, CatalogueParams[]];
4
- export interface ProductRefParams {
5
- partNr: string;
6
- }
7
- export declare function applyProductRefFilters(filters: Filters<ProductRefParams>, productRefs: ProductRef[]): [Matches<ProductRefParams>, ProductRef[]];
1
+ import { Filters, Matches } from "@configura/web-utilities";
2
+ import { CatalogueParams, ProductRef } from "../CatalogueAPI.js";
3
+ export declare function applyCatalogueFilters(filters: Filters<CatalogueParams>, catalogues: CatalogueParams[]): [Matches<CatalogueParams>, CatalogueParams[]];
4
+ export interface ProductRefParams {
5
+ partNr: string;
6
+ }
7
+ export declare function applyProductRefFilters(filters: Filters<ProductRefParams>, productRefs: ProductRef[]): [Matches<ProductRefParams>, ProductRef[]];
8
8
  //# sourceMappingURL=filters.d.ts.map
@@ -1,29 +1,29 @@
1
- import { match, pick } from "@configura/web-utilities";
2
- export function applyCatalogueFilters(filters, catalogues) {
3
- let enterprise = match("enterprise", filters.enterprise, catalogues);
4
- let prdCat = match("prdCat", filters.prdCat, enterprise.matching);
5
- let prdCatVersion = match("prdCatVersion", filters.prdCatVersion, prdCat.matching);
6
- let vendor = match("vendor", filters.vendor, prdCatVersion.matching);
7
- let priceList = match("priceList", filters.priceList, vendor.matching);
8
- let picked = pick(filters.enterprise, priceList.matching);
9
- picked = pick(filters.prdCat, picked);
10
- picked = pick(filters.prdCatVersion, picked);
11
- picked = pick(filters.vendor, picked);
12
- picked = pick(filters.priceList, picked);
13
- const matches = {
14
- enterprise,
15
- prdCat,
16
- prdCatVersion,
17
- priceList,
18
- vendor,
19
- };
20
- return [matches, picked];
21
- }
22
- export function applyProductRefFilters(filters, productRefs) {
23
- const partNr = match("partNr", filters.partNr, productRefs);
24
- const result = pick(filters.partNr, partNr.matching);
25
- const args = {
26
- partNr,
27
- };
28
- return [args, result];
29
- }
1
+ import { match, pick } from "@configura/web-utilities";
2
+ export function applyCatalogueFilters(filters, catalogues) {
3
+ let enterprise = match("enterprise", filters.enterprise, catalogues);
4
+ let prdCat = match("prdCat", filters.prdCat, enterprise.matching);
5
+ let prdCatVersion = match("prdCatVersion", filters.prdCatVersion, prdCat.matching);
6
+ let vendor = match("vendor", filters.vendor, prdCatVersion.matching);
7
+ let priceList = match("priceList", filters.priceList, vendor.matching);
8
+ let picked = pick(filters.enterprise, priceList.matching);
9
+ picked = pick(filters.prdCat, picked);
10
+ picked = pick(filters.prdCatVersion, picked);
11
+ picked = pick(filters.vendor, picked);
12
+ picked = pick(filters.priceList, picked);
13
+ const matches = {
14
+ enterprise,
15
+ prdCat,
16
+ prdCatVersion,
17
+ priceList,
18
+ vendor,
19
+ };
20
+ return [matches, picked];
21
+ }
22
+ export function applyProductRefFilters(filters, productRefs) {
23
+ const partNr = match("partNr", filters.partNr, productRefs);
24
+ const result = pick(filters.partNr, partNr.matching);
25
+ const args = {
26
+ partNr,
27
+ };
28
+ return [args, result];
29
+ }
@@ -1,16 +1,16 @@
1
- import { Filters } from "@configura/web-utilities";
2
- import { ApplicationAreasResponse, CatalogueAPI, CatalogueParams } from "../CatalogueAPI.js";
3
- import { CfgProduct, CfgProductSettings } from "../CfgProduct.js";
4
- import { ProductRefParams } from "./filters.js";
5
- export interface GeneratedProductConfiguration {
6
- applicationAreasResponse: ApplicationAreasResponse;
7
- catalogueCount: number;
8
- catalogueIndex: number;
9
- catalogueParams: CatalogueParams;
10
- getProductDuration: number;
11
- product: CfgProduct;
12
- productCount: number;
13
- productIndex: number;
14
- }
15
- export declare function generateProductConfigurations(api: CatalogueAPI, lang: string, catalogues: CatalogueParams[], filters: Filters<ProductRefParams>, settings?: Partial<CfgProductSettings>): AsyncIterableIterator<GeneratedProductConfiguration | Error>;
1
+ import { Filters } from "@configura/web-utilities";
2
+ import { ApplicationAreasResponse, CatalogueAPI, CatalogueParams } from "../CatalogueAPI.js";
3
+ import { CfgProduct, CfgProductSettings } from "../CfgProduct.js";
4
+ import { ProductRefParams } from "./filters.js";
5
+ export interface GeneratedProductConfiguration {
6
+ applicationAreasResponse: ApplicationAreasResponse;
7
+ catalogueCount: number;
8
+ catalogueIndex: number;
9
+ catalogueParams: CatalogueParams;
10
+ getProductDuration: number;
11
+ product: CfgProduct;
12
+ productCount: number;
13
+ productIndex: number;
14
+ }
15
+ export declare function generateProductConfigurations(api: CatalogueAPI, lang: string, catalogues: CatalogueParams[], filters: Filters<ProductRefParams>, settings?: Partial<CfgProductSettings>): AsyncIterableIterator<GeneratedProductConfiguration | Error>;
16
16
  //# sourceMappingURL=productParamsGenerator.d.ts.map