@configura/web-api 1.6.1-alpha.5 → 1.6.2-alpha.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 (76) 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 +258 -253
  9. package/dist/CfgProduct.js +747 -731
  10. package/dist/index.d.ts +20 -20
  11. package/dist/index.js +20 -20
  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 -179
  23. package/dist/productConfiguration/CfgFeature.js +636 -617
  24. package/dist/productConfiguration/CfgOption.d.ts +150 -150
  25. package/dist/productConfiguration/CfgOption.js +426 -426
  26. package/dist/productConfiguration/CfgProductConfiguration.d.ts +120 -120
  27. package/dist/productConfiguration/CfgProductConfiguration.js +309 -307
  28. package/dist/productConfiguration/filters.d.ts +15 -15
  29. package/dist/productConfiguration/filters.js +70 -70
  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 +20 -20
  37. package/dist/syncGroups/SyncGroupsApplyMode.js +21 -21
  38. package/dist/syncGroups/SyncGroupsHandler.d.ts +40 -39
  39. package/dist/syncGroups/SyncGroupsHandler.js +358 -352
  40. package/dist/syncGroups/SyncGroupsPathHelper.d.ts +26 -26
  41. package/dist/syncGroups/SyncGroupsPathHelper.js +90 -89
  42. package/dist/syncGroups/SyncGroupsState.d.ts +35 -25
  43. package/dist/syncGroups/SyncGroupsState.js +125 -111
  44. package/dist/syncGroups/SyncGroupsTransaction.d.ts +154 -50
  45. package/dist/syncGroups/SyncGroupsTransaction.js +576 -100
  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 -277
  56. package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
  57. package/dist/tests/testData/testDataCachedGetProduct.js +185 -185
  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 +12 -12
  63. package/dist/tests/testData/testDataOptions.js +60 -60
  64. package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
  65. package/dist/tests/testData/testDataProductAggregatedPrice.js +187 -187
  66. package/dist/tests/testData/testDataUpcharge.d.ts +8 -29
  67. package/dist/tests/testData/testDataUpcharge.js +119 -119
  68. package/dist/utilitiesCatalogueData.d.ts +31 -31
  69. package/dist/utilitiesCatalogueData.js +162 -168
  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/syncGroups/SyncGroupsApplier.d.ts +0 -20
  76. package/dist/syncGroups/SyncGroupsApplier.js +0 -514
@@ -1,514 +0,0 @@
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 { CfgProductBubbleMode } from "../CfgProduct.js";
11
- import { SelectionType, } from "../productConfiguration/CfgFeature.js";
12
- import { ProductConfigurationBubbleMode, } from "../productConfiguration/CfgOption.js";
13
- import { SyncGroupsApplyMode } from "./SyncGroupsApplyMode.js";
14
- export class SyncGroupsApplier {
15
- /**
16
- * At load of a new product this is used to move it into a synced state
17
- */
18
- static init(transaction) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- return yield OntoSyncState.rootProduct(transaction);
21
- });
22
- }
23
- /**
24
- * At an active select of an option this is the entry point
25
- */
26
- static selectOption(transaction, option, on) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const feature = option.parent;
29
- const productsToValidate = new Set();
30
- let change = false;
31
- // Here we sort of hand back to normal selecting. This is because after a normal selection has happened
32
- // this can have brought features into scope which should pull or push to the Sync State. (Push if the
33
- // SyncGroup is yet undefined)
34
- // We use BubbleSelected as we can then delay the validation until after we have applied the sync group (if any)
35
- if (yield feature.selectOption(option, on, ProductConfigurationBubbleMode.BubbleSelected)) {
36
- productsToValidate.add(feature.parentProduct);
37
- switch (feature.selectionType) {
38
- case SelectionType.SelectOne:
39
- transaction.addSelectOneFeatureAffected(feature);
40
- break;
41
- case SelectionType.SelectMany:
42
- transaction.addSelectManyOptionAffected(option);
43
- break;
44
- default:
45
- throw new Error("Should not happen");
46
- }
47
- change = true;
48
- }
49
- switch (feature.selectionType) {
50
- case SelectionType.SelectOne:
51
- OntoSyncState.selectOneFeature(transaction, feature, true, false);
52
- break;
53
- case SelectionType.SelectMany:
54
- OntoSyncState.selectManyOption(transaction, option, true);
55
- break;
56
- }
57
- if (yield SyncStateOnto.rootProduct(transaction, productsToValidate)) {
58
- change = true;
59
- }
60
- return change;
61
- });
62
- }
63
- /**
64
- * @returns undefined if the @syncGroup is undefined, false if
65
- * the @mustSupport is not fulfilled or the syncCode if all is ok
66
- */
67
- static getSyncCode(syncGroup, mustSupport) {
68
- if (syncGroup === undefined) {
69
- return undefined;
70
- }
71
- const { syncGroupCode, syncMethod } = syncGroup;
72
- if (syncMethod !== mustSupport && syncMethod !== "twoWay") {
73
- return false;
74
- }
75
- return syncGroupCode;
76
- }
77
- }
78
- class SyncStateOnto {
79
- /**
80
- * Apply current sync groups on those who wants to listen until no more to settle
81
- * @returns true if at least one Feature changed selected Option
82
- */
83
- static rootProduct(transaction, productsToValidate) {
84
- return __awaiter(this, void 0, void 0, function* () {
85
- productsToValidate = productsToValidate !== null && productsToValidate !== void 0 ? productsToValidate : new Set();
86
- yield SyncStateOnto.product(transaction, transaction, productsToValidate);
87
- if (productsToValidate.size === 0) {
88
- // All settled, continue to pullPhase
89
- return yield OntoSyncState.rootProduct(transaction);
90
- }
91
- if (transaction.isClosed) {
92
- // We could exit in more places when the transaction has been aborted,
93
- // but as revalidate is really the only thing that could be expensive /
94
- // time consuming we only check here.
95
- return false;
96
- }
97
- const promises = [];
98
- for (const product of productsToValidate) {
99
- promises.push(product._revalidate(CfgProductBubbleMode.ToRoot, transaction.productLoader));
100
- }
101
- const revalidationResults = yield Promise.all(promises);
102
- if (revalidationResults.every((r) => !r)) {
103
- transaction.close();
104
- return false;
105
- }
106
- // Apply over again, to settle deeper down. Our theory is that the front of
107
- // "settled" will move deeper and deeper into the tree.
108
- yield SyncStateOnto.rootProduct(transaction, undefined);
109
- // We had productsToValidate, and so there must have been a change
110
- return true;
111
- });
112
- }
113
- /**
114
- * Applies the SyncState to the Product and it's AdditionalProducts (sub-products)
115
- * @param productsToValidate To this all products that will need validation are added
116
- */
117
- static product(transaction, product, productsToValidate) {
118
- return __awaiter(this, void 0, void 0, function* () {
119
- const promises = [];
120
- promises.push(SyncStateOnto.features(transaction, getFeaturesFromProduct(product), productsToValidate));
121
- for (const additionalProduct of getAdditionalProducts(product)) {
122
- promises.push(SyncStateOnto.product(transaction, additionalProduct, productsToValidate));
123
- }
124
- yield Promise.all(promises);
125
- });
126
- }
127
- /**
128
- * Applies the SyncState to an array of Features
129
- * @param productsToValidate To this all products that will need validation are added
130
- */
131
- static features(transaction, features, productsToValidate) {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- yield Promise.all(features.map((feature) => __awaiter(this, void 0, void 0, function* () {
134
- switch (yield SyncStateOnto.feature(transaction, feature, productsToValidate)) {
135
- case "stop":
136
- return;
137
- case "recurseDown":
138
- yield SyncStateOnto.options(transaction, getSelectedOptions(feature), productsToValidate);
139
- return;
140
- }
141
- })));
142
- });
143
- }
144
- /**
145
- * Applies the SyncState to an array of Options
146
- * @param productsToValidate To this all products that will need validation are added
147
- */
148
- static options(transaction, options, productsToValidate) {
149
- return __awaiter(this, void 0, void 0, function* () {
150
- yield Promise.all(options.map((option) => {
151
- return SyncStateOnto.features(transaction, getFeaturesFromOption(option), productsToValidate);
152
- }));
153
- });
154
- }
155
- /**
156
- * Applies the SyncState to a Feature
157
- * @param productsToValidate To this all products that will need validation are added
158
- * @returns Whether we shall stop recursing down (because we are in a state which we
159
- * expect to be resolved later), we shall continue recursing down.
160
- */
161
- static feature(transaction, featureWithInitial, productsToValidate) {
162
- return __awaiter(this, void 0, void 0, function* () {
163
- const feature = featureWithInitial.target;
164
- const syncCode = SyncGroupsApplier.getSyncCode(feature.syncGroup, "pull");
165
- if (syncCode === undefined) {
166
- // Just continue down, features with no sync groups are always settled
167
- return "recurseDown";
168
- }
169
- if (syncCode === false) {
170
- // Here we only handle pull. Initializing those missing in SyncMap
171
- // we do later. We wait until we have settled as much as we can with what
172
- // we have now, to increase chances of the values being written to the
173
- // SyncState being the right ones.
174
- return "stop";
175
- }
176
- switch (feature.selectionType) {
177
- case SelectionType.Group:
178
- return "recurseDown";
179
- case SelectionType.SelectOne:
180
- return yield SyncStateOnto.selectOneFeature(transaction, syncCode, featureWithInitial, productsToValidate);
181
- case SelectionType.SelectMany:
182
- return yield SyncStateOnto.selectManyFeature(transaction, syncCode, featureWithInitial, productsToValidate);
183
- }
184
- });
185
- }
186
- /**
187
- * Decides if the SyncState can be applied to the SelectOne Feature, and then changes
188
- * the state of the Feature if so.
189
- * @param syncCode What SyncGroup the Feature belongs to
190
- * @param productsToValidate To this all products that will need validation are added
191
- * @returns Whether we shall stop recursing down (because we are in a state which we
192
- * expect to be resolved later), we shall continue recursing down.
193
- */
194
- static selectOneFeature(transaction, syncCode, featureWithInitial, productsToValidate) {
195
- return __awaiter(this, void 0, void 0, function* () {
196
- const feature = featureWithInitial.target;
197
- const featureDidJustComeIntoScope = featureWithInitial.initial === undefined;
198
- if (transaction.hasSelectOneFeatureBeenAffected(feature)) {
199
- // This feature has already changed selection once for this transaction. We expect
200
- // this to happen very rarely, as the algorithm should settle the selection tree
201
- // further and further out. Nevertheless, this safeguard is needed to avoid infinite
202
- // looping if for example the server would return the same data over and over.
203
- return "recurseDown";
204
- }
205
- if (!(featureDidJustComeIntoScope || transaction.isSyncGroupAffectedForSelectOne(syncCode))) {
206
- return "recurseDown";
207
- }
208
- const currentSyncGroupValue = transaction.syncState.getForSelectOne(syncCode);
209
- if (currentSyncGroupValue === undefined) {
210
- // This branch will have to be settled later. Don't go further down here.
211
- return "stop";
212
- }
213
- const selectedOption = feature.selectedOptions[0];
214
- if (selectedOption !== undefined && selectedOption.code === currentSyncGroupValue) {
215
- // Settled, continue
216
- return "recurseDown";
217
- }
218
- const optionToSelect = feature.options.find((o) => o.code === currentSyncGroupValue);
219
- if (optionToSelect === undefined) {
220
- // No option which can be selected (keep current value and recurse down)
221
- return "recurseDown";
222
- }
223
- // Update the value. Validations are collected so that we do not
224
- // send more than necessary. Do not recurse further as we will change
225
- // the state and so what is selected now won't be selected then.
226
- yield feature.selectOption(optionToSelect._internal, true, ProductConfigurationBubbleMode.ToRoot);
227
- transaction.addSelectOneFeatureAffected(feature);
228
- productsToValidate.add(feature.parentProduct);
229
- return "stop";
230
- });
231
- }
232
- /**
233
- * Decides if the SyncState can be applied to Options in the SelectMany Feature, and
234
- * then changes the state of the Options if so.
235
- * @param syncCode What SyncGroup the Feature belongs to
236
- * @param productsToValidate To this all products that will need validation are added
237
- * @returns Always "stop" as recursion is handled internally. Return for consistency.
238
- */
239
- static selectManyFeature(transaction, syncCode, feature, productsToValidate) {
240
- return __awaiter(this, void 0, void 0, function* () {
241
- const optionsToContinueDown = [];
242
- for (const option of getOptions(feature)) {
243
- switch (yield SyncStateOnto.selectManyOption(transaction, syncCode, option, productsToValidate)) {
244
- case "stop":
245
- continue;
246
- case "recurseDown":
247
- optionsToContinueDown.push(option);
248
- continue;
249
- }
250
- }
251
- yield SyncStateOnto.options(transaction, optionsToContinueDown, productsToValidate);
252
- // stop as the method above handles the recursion down
253
- return "stop";
254
- });
255
- }
256
- /**
257
- * Decides if the SyncState can be applied to the SelectMany Option, and then changes
258
- * the state of the Option if so.
259
- * @param syncCode What SyncGroup the Feature belongs to
260
- * @param productsToValidate To this all products that will need validation are added
261
- * @returns Whether we shall stop recursing down (because we are in a state which we
262
- * expect to be resolved later), we shall continue recursing down.
263
- */
264
- static selectManyOption(transaction, syncCode, optionWithInitial, productsToValidate) {
265
- return __awaiter(this, void 0, void 0, function* () {
266
- const option = optionWithInitial.target;
267
- const featureDidJustComeIntoScope = optionWithInitial.initial === undefined;
268
- const optionSelected = option.selected;
269
- const recurseOrStopIfNoChange = optionSelected ? "recurseDown" : "stop";
270
- if (transaction.hasSelectManyOptionBeenAffected(option)) {
271
- // This option has already changed selection once for this transaction. We expect
272
- // this to happen very rarely, as the algorithm should settle the selection tree
273
- // further and further out. Nevertheless, this safeguard is needed to avoid infinite
274
- // looping if for example the server would return the same data over and over.
275
- return recurseOrStopIfNoChange;
276
- }
277
- const optionCode = option.code;
278
- if (!(featureDidJustComeIntoScope ||
279
- transaction.isSyncGroupAffectedForSelectMany(syncCode, optionCode))) {
280
- return "recurseDown";
281
- }
282
- const syncGroupValueForOption = transaction.syncState.getForSelectMany(syncCode, optionCode);
283
- if (syncGroupValueForOption === undefined) {
284
- // The sync group has no opinion on this. If it is selected, just continue down.
285
- return recurseOrStopIfNoChange;
286
- }
287
- if (syncGroupValueForOption === optionSelected) {
288
- // We are in sync for this option
289
- return recurseOrStopIfNoChange;
290
- }
291
- const feature = option.parent;
292
- // Update the value. Validations are collected so that we do not
293
- // send more than necessary. Do not recurse further as we will change
294
- // the state and so what is selected now won't be selected then.
295
- yield feature.selectOption(option, syncGroupValueForOption, ProductConfigurationBubbleMode.ToRoot);
296
- transaction.addSelectManyOptionAffected(option);
297
- productsToValidate.add(feature.parentProduct);
298
- return "stop";
299
- });
300
- }
301
- }
302
- class OntoSyncState {
303
- /**
304
- * @returns true if at least one Feature changed it state. This is a bit counter intuitive,
305
- * but as this method will hand over to productOntoSyncState if it updates the SyncState it
306
- * can cause the Features to change. And we need to pass that information back to know when
307
- * to stop
308
- */
309
- static rootProduct(transaction) {
310
- return __awaiter(this, void 0, void 0, function* () {
311
- if (!(yield OntoSyncState.product(transaction, transaction))) {
312
- // All done!
313
- return false;
314
- }
315
- return yield SyncStateOnto.rootProduct(transaction, undefined);
316
- });
317
- }
318
- static product(transaction, product) {
319
- return __awaiter(this, void 0, void 0, function* () {
320
- let change = false;
321
- if (yield OntoSyncState.features(transaction, getFeaturesFromProduct(product))) {
322
- if (transaction.updateMode === SyncGroupsApplyMode.Strict) {
323
- return true;
324
- }
325
- change = true;
326
- }
327
- for (const additionalProduct of getAdditionalProducts(product)) {
328
- if (yield OntoSyncState.product(transaction, additionalProduct)) {
329
- if (transaction.updateMode === SyncGroupsApplyMode.Strict) {
330
- return true;
331
- }
332
- change = true;
333
- }
334
- }
335
- return change;
336
- });
337
- }
338
- static features(transaction, featureWithInitials) {
339
- return __awaiter(this, void 0, void 0, function* () {
340
- let change = false;
341
- for (const featureWithInitial of featureWithInitials) {
342
- const feature = featureWithInitial.target;
343
- switch (feature.selectionType) {
344
- case SelectionType.SelectOne:
345
- if (OntoSyncState.selectOneFeature(transaction, feature, false, featureWithInitial.initial === undefined)) {
346
- change = true;
347
- }
348
- break;
349
- case SelectionType.SelectMany:
350
- if (OntoSyncState.selectManyFeature(transaction, featureWithInitial)) {
351
- change = true;
352
- }
353
- break;
354
- }
355
- if (change && transaction.updateMode === SyncGroupsApplyMode.Strict) {
356
- return true;
357
- }
358
- if (yield OntoSyncState.options(transaction, getSelectedOptions(featureWithInitial))) {
359
- if (transaction.updateMode === SyncGroupsApplyMode.Strict) {
360
- return true;
361
- }
362
- change = true;
363
- }
364
- }
365
- return change;
366
- });
367
- }
368
- static options(transaction, options) {
369
- return __awaiter(this, void 0, void 0, function* () {
370
- let change = false;
371
- for (const option of options) {
372
- if (yield OntoSyncState.features(transaction, getFeaturesFromOption(option))) {
373
- if (transaction.updateMode === SyncGroupsApplyMode.Strict) {
374
- return true;
375
- }
376
- change = true;
377
- }
378
- }
379
- return change;
380
- });
381
- }
382
- static selectOneFeature(transaction, feature, activeSelectionForce, featureDidJustComeIntoScope) {
383
- const selectionType = feature.selectionType;
384
- if (selectionType !== SelectionType.SelectOne) {
385
- throw new Error("can only be used for selectOne");
386
- }
387
- const syncCode = SyncGroupsApplier.getSyncCode(feature.syncGroup, "push");
388
- if (syncCode === undefined || syncCode === false) {
389
- return false;
390
- }
391
- if (transaction.isSyncGroupAffectedForSelectOne(syncCode)) {
392
- return false;
393
- }
394
- const syncState = transaction.syncState;
395
- const currentSyncGroupOptionCode = syncState.getForSelectOne(syncCode);
396
- const option = feature.selectedOptions[0];
397
- if (option === undefined) {
398
- // Options with no default are never written
399
- return false;
400
- }
401
- if (activeSelectionForce) {
402
- // To make re-apply happen, even if it actually does not update the sync group
403
- transaction.addSyncGroupAffectedForSelectOne(syncCode);
404
- }
405
- const optionCode = option.code;
406
- if (optionCode === currentSyncGroupOptionCode) {
407
- return false;
408
- }
409
- // featureDidJustComeIntoScope, in CET there is a feature that if a feature appears which
410
- // can not be set to the current sync group value, then it will set in the opposite
411
- // direction. Like if the sync group was empty. To avoid bouncing back and forth we will
412
- // need to enforce that a sync group can only be updated once per transaction
413
- if (!(activeSelectionForce ||
414
- currentSyncGroupOptionCode === undefined ||
415
- (featureDidJustComeIntoScope &&
416
- feature.options.every((o) => currentSyncGroupOptionCode !== o.code)))) {
417
- return false;
418
- }
419
- // TODO: Remove
420
- //syncState.logDebug();
421
- transaction.addSyncGroupAffectedForSelectOne(syncCode);
422
- syncState.setForSelectOne(syncCode, optionCode);
423
- return true;
424
- }
425
- static selectManyFeature(transaction, featureWithInitial) {
426
- let change = false;
427
- for (const optionWithInitial of getOptions(featureWithInitial)) {
428
- if (OntoSyncState.selectManyOption(transaction, optionWithInitial.target, false)) {
429
- if (transaction.updateMode === SyncGroupsApplyMode.Strict) {
430
- return true;
431
- }
432
- change = true;
433
- }
434
- }
435
- return change;
436
- }
437
- static selectManyOption(transaction, option, activeSelectionForce) {
438
- const feature = option.parent;
439
- if (feature.selectionType !== SelectionType.SelectMany) {
440
- throw new Error("can only be used for selectMany");
441
- }
442
- const syncCode = SyncGroupsApplier.getSyncCode(feature.syncGroup, "push");
443
- if (syncCode === undefined || syncCode === false) {
444
- return false;
445
- }
446
- const optionCode = option.code;
447
- if (transaction.isSyncGroupAffectedForSelectMany(syncCode, optionCode)) {
448
- return false;
449
- }
450
- const syncState = transaction.syncState;
451
- const optionSelected = option.selected;
452
- const currentSyncGroupValue = syncState.getForSelectMany(syncCode, optionCode);
453
- if (activeSelectionForce) {
454
- // To make re-apply happen, even if it actually does not update the sync group
455
- transaction.addSyncGroupAffectedForSelectMany(syncCode, optionCode);
456
- }
457
- // We only initialize if the option is selected or we force.
458
- // activeSelectionForce = active selection by the user.
459
- if (!(currentSyncGroupValue === undefined && optionSelected) &&
460
- !(activeSelectionForce && currentSyncGroupValue !== optionSelected)) {
461
- return false;
462
- }
463
- transaction.addSyncGroupAffectedForSelectMany(syncCode, optionCode);
464
- syncState.setForSelectMany(syncCode, optionCode, optionSelected);
465
- return true;
466
- }
467
- }
468
- function getAdditionalProducts(product) {
469
- const initial = product.initial;
470
- return product.target.additionalProducts.map((childTarget) => {
471
- const refKey = childTarget.refKey;
472
- const childInitial = initial === null || initial === void 0 ? void 0 : initial.additionalProducts.find((p) => refKey === p.refKey);
473
- return {
474
- target: childTarget._internal,
475
- initial: childInitial === null || childInitial === void 0 ? void 0 : childInitial._internal,
476
- };
477
- });
478
- }
479
- function pairOptions(targets, initials) {
480
- return targets.map((childTarget) => {
481
- const key = childTarget.key;
482
- const childInitial = initials === null || initials === void 0 ? void 0 : initials.find((o) => key === o.key);
483
- return {
484
- target: childTarget._internal,
485
- initial: childInitial === null || childInitial === void 0 ? void 0 : childInitial._internal,
486
- };
487
- });
488
- }
489
- function getSelectedOptions(feature) {
490
- var _a;
491
- return pairOptions(feature.target.selectedOptions, (_a = feature.initial) === null || _a === void 0 ? void 0 : _a.selectedOptions);
492
- }
493
- function getOptions(feature) {
494
- var _a;
495
- return pairOptions(feature.target.options, (_a = feature.initial) === null || _a === void 0 ? void 0 : _a.options);
496
- }
497
- function pairFeatures(targets, initials) {
498
- return targets.map((childTarget) => {
499
- const key = childTarget.key;
500
- const childInitial = initials === null || initials === void 0 ? void 0 : initials.find((f) => key === f.key);
501
- return {
502
- target: childTarget._internal,
503
- initial: childInitial === null || childInitial === void 0 ? void 0 : childInitial._internal,
504
- };
505
- });
506
- }
507
- function getFeaturesFromProduct(product) {
508
- var _a;
509
- return pairFeatures(product.target.configuration.features, (_a = product.initial) === null || _a === void 0 ? void 0 : _a.configuration.features);
510
- }
511
- function getFeaturesFromOption(option) {
512
- var _a;
513
- return pairFeatures(option.target.features, (_a = option.initial) === null || _a === void 0 ? void 0 : _a.features);
514
- }