@configura/web-api 1.6.0-iotest.2 → 1.6.1-alpha.1

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 (43) hide show
  1. package/dist/CfgProduct.d.ts +29 -10
  2. package/dist/CfgProduct.js +82 -47
  3. package/dist/index.d.ts +2 -4
  4. package/dist/index.js +2 -4
  5. package/dist/productConfiguration/CfgFeature.d.ts +2 -1
  6. package/dist/productConfiguration/CfgFeature.js +27 -8
  7. package/dist/productConfiguration/CfgOption.d.ts +21 -8
  8. package/dist/productConfiguration/CfgOption.js +26 -18
  9. package/dist/productConfiguration/CfgProductConfiguration.d.ts +1 -2
  10. package/dist/productConfiguration/CfgProductConfiguration.js +9 -8
  11. package/dist/syncGroups/SyncGroupsApplier.d.ts +20 -0
  12. package/dist/syncGroups/SyncGroupsApplier.js +520 -0
  13. package/dist/syncGroups/SyncGroupsApplyMode.d.ts +21 -0
  14. package/dist/syncGroups/SyncGroupsApplyMode.js +21 -0
  15. package/dist/syncGroups/SyncGroupsHandler.d.ts +31 -0
  16. package/dist/syncGroups/SyncGroupsHandler.js +71 -0
  17. package/dist/syncGroups/SyncGroupsPathHelper.d.ts +27 -0
  18. package/dist/syncGroups/SyncGroupsPathHelper.js +89 -0
  19. package/dist/syncGroups/SyncGroupsState.d.ts +20 -0
  20. package/dist/syncGroups/SyncGroupsState.js +108 -0
  21. package/dist/syncGroups/SyncGroupsTransaction.d.ts +51 -0
  22. package/dist/syncGroups/SyncGroupsTransaction.js +100 -0
  23. package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +24 -95
  24. package/dist/tests/testData/testDataCachedGetProduct.js +8 -19
  25. package/dist/tests/testData/testDataOptions.d.ts +13 -0
  26. package/dist/tests/testData/testDataOptions.js +60 -0
  27. package/dist/tests/testData/testDataProductAggregatedPrice.js +12 -23
  28. package/dist/tests/testData/testDataUpcharge.js +16 -48
  29. package/dist/utilitiesCatalogueData.d.ts +7 -1
  30. package/dist/utilitiesCatalogueData.js +105 -4
  31. package/package.json +3 -3
  32. package/dist/io/CfgHistoryManager.d.ts +0 -30
  33. package/dist/io/CfgHistoryManager.js +0 -62
  34. package/dist/io/CfgHistoryToProdConfConnector.d.ts +0 -10
  35. package/dist/io/CfgHistoryToProdConfConnector.js +0 -20
  36. package/dist/io/CfgIOManager.d.ts +0 -29
  37. package/dist/io/CfgIOManager.js +0 -89
  38. package/dist/io/CfgIOProdConfConnector.d.ts +0 -33
  39. package/dist/io/CfgIOProdConfConnector.js +0 -100
  40. package/dist/io/CfgWindowMessageManager.d.ts +0 -13
  41. package/dist/io/CfgWindowMessageManager.js +0 -28
  42. package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +0 -13
  43. package/dist/io/CfgWindowMessageToProdConfConnector.js +0 -17
@@ -0,0 +1,520 @@
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.isAborted) {
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
+ // When using SyncGroups we require each and every validate call to validate on the
103
+ // server. Without SyncGroups we let these pass through, because any diversion from
104
+ // what you did chose should be immediately visible. With SyncGroups the end result
105
+ // is the combination of potentially many different validate calls, and so errors
106
+ // could accumulate and what is cause and effect be hard to know.
107
+ if (!revalidationResults.every((r) => r.requestDidValidate) ||
108
+ revalidationResults.every((r) => r.wasAborted)) {
109
+ transaction.abort();
110
+ return false;
111
+ }
112
+ // Apply over again, to settle deeper down. Our theory is that the front of
113
+ // "settled" will move deeper and deeper into the tree.
114
+ yield SyncStateOnto.rootProduct(transaction, undefined);
115
+ // We had productsToValidate, and so there must have been a change
116
+ return true;
117
+ });
118
+ }
119
+ /**
120
+ * Applies the SyncState to the Product and it's AdditionalProducts (sub-products)
121
+ * @param productsToValidate To this all products that will need validation are added
122
+ */
123
+ static product(transaction, product, productsToValidate) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ const promises = [];
126
+ promises.push(SyncStateOnto.features(transaction, getFeaturesFromProduct(product), productsToValidate));
127
+ for (const additionalProduct of getAdditionalProducts(product)) {
128
+ promises.push(SyncStateOnto.product(transaction, additionalProduct, productsToValidate));
129
+ }
130
+ yield Promise.all(promises);
131
+ });
132
+ }
133
+ /**
134
+ * Applies the SyncState to an array of Features
135
+ * @param productsToValidate To this all products that will need validation are added
136
+ */
137
+ static features(transaction, features, productsToValidate) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ yield Promise.all(features.map((feature) => __awaiter(this, void 0, void 0, function* () {
140
+ switch (yield SyncStateOnto.feature(transaction, feature, productsToValidate)) {
141
+ case "stop":
142
+ return;
143
+ case "recurseDown":
144
+ yield SyncStateOnto.options(transaction, getSelectedOptions(feature), productsToValidate);
145
+ return;
146
+ }
147
+ })));
148
+ });
149
+ }
150
+ /**
151
+ * Applies the SyncState to an array of Options
152
+ * @param productsToValidate To this all products that will need validation are added
153
+ */
154
+ static options(transaction, options, productsToValidate) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ yield Promise.all(options.map((option) => {
157
+ return SyncStateOnto.features(transaction, getFeaturesFromOption(option), productsToValidate);
158
+ }));
159
+ });
160
+ }
161
+ /**
162
+ * Applies the SyncState to a Feature
163
+ * @param productsToValidate To this all products that will need validation are added
164
+ * @returns Whether we shall stop recursing down (because we are in a state which we
165
+ * expect to be resolved later), we shall continue recursing down.
166
+ */
167
+ static feature(transaction, featureWithInitial, productsToValidate) {
168
+ return __awaiter(this, void 0, void 0, function* () {
169
+ const feature = featureWithInitial.target;
170
+ const syncCode = SyncGroupsApplier.getSyncCode(feature.syncGroup, "pull");
171
+ if (syncCode === undefined) {
172
+ // Just continue down, features with no sync groups are always settled
173
+ return "recurseDown";
174
+ }
175
+ if (syncCode === false) {
176
+ // Here we only handle pull. Initializing those missing in SyncMap
177
+ // we do later. We wait until we have settled as much as we can with what
178
+ // we have now, to increase chances of the values being written to the
179
+ // SyncState being the right ones.
180
+ return "stop";
181
+ }
182
+ switch (feature.selectionType) {
183
+ case SelectionType.Group:
184
+ return "recurseDown";
185
+ case SelectionType.SelectOne:
186
+ return yield SyncStateOnto.selectOneFeature(transaction, syncCode, featureWithInitial, productsToValidate);
187
+ case SelectionType.SelectMany:
188
+ return yield SyncStateOnto.selectManyFeature(transaction, syncCode, featureWithInitial, productsToValidate);
189
+ }
190
+ });
191
+ }
192
+ /**
193
+ * Decides if the SyncState can be applied to the SelectOne Feature, and then changes
194
+ * the state of the Feature if so.
195
+ * @param syncCode What SyncGroup the Feature belongs to
196
+ * @param productsToValidate To this all products that will need validation are added
197
+ * @returns Whether we shall stop recursing down (because we are in a state which we
198
+ * expect to be resolved later), we shall continue recursing down.
199
+ */
200
+ static selectOneFeature(transaction, syncCode, featureWithInitial, productsToValidate) {
201
+ return __awaiter(this, void 0, void 0, function* () {
202
+ const feature = featureWithInitial.target;
203
+ const featureDidJustComeIntoScope = featureWithInitial.initial === undefined;
204
+ if (transaction.hasSelectOneFeatureBeenAffected(feature)) {
205
+ // This feature has already changed selection once for this transaction. We expect
206
+ // this to happen very rarely, as the algorithm should settle the selection tree
207
+ // further and further out. Nevertheless, this safeguard is needed to avoid infinite
208
+ // looping if for example the server would return the same data over and over.
209
+ return "recurseDown";
210
+ }
211
+ if (!(featureDidJustComeIntoScope || transaction.isSyncGroupAffectedForSelectOne(syncCode))) {
212
+ return "recurseDown";
213
+ }
214
+ const currentSyncGroupValue = transaction.syncState.getForSelectOne(syncCode);
215
+ if (currentSyncGroupValue === undefined) {
216
+ // This branch will have to be settled later. Don't go further down here.
217
+ return "stop";
218
+ }
219
+ const selectedOption = feature.selectedOptions[0];
220
+ if (selectedOption !== undefined && selectedOption.code === currentSyncGroupValue) {
221
+ // Settled, continue
222
+ return "recurseDown";
223
+ }
224
+ const optionToSelect = feature.options.find((o) => o.code === currentSyncGroupValue);
225
+ if (optionToSelect === undefined) {
226
+ // No option which can be selected (keep current value and recurse down)
227
+ return "recurseDown";
228
+ }
229
+ // Update the value. Validations are collected so that we do not
230
+ // send more than necessary. Do not recurse further as we will change
231
+ // the state and so what is selected now won't be selected then.
232
+ yield feature.selectOption(optionToSelect._internal, true, ProductConfigurationBubbleMode.ToRoot);
233
+ transaction.addSelectOneFeatureAffected(feature);
234
+ productsToValidate.add(feature.parentProduct);
235
+ return "stop";
236
+ });
237
+ }
238
+ /**
239
+ * Decides if the SyncState can be applied to Options in the SelectMany Feature, and
240
+ * then changes the state of the Options if so.
241
+ * @param syncCode What SyncGroup the Feature belongs to
242
+ * @param productsToValidate To this all products that will need validation are added
243
+ * @returns Always "stop" as recursion is handled internally. Return for consistency.
244
+ */
245
+ static selectManyFeature(transaction, syncCode, feature, productsToValidate) {
246
+ return __awaiter(this, void 0, void 0, function* () {
247
+ const optionsToContinueDown = [];
248
+ for (const option of getOptions(feature)) {
249
+ switch (yield SyncStateOnto.selectManyOption(transaction, syncCode, option, productsToValidate)) {
250
+ case "stop":
251
+ continue;
252
+ case "recurseDown":
253
+ optionsToContinueDown.push(option);
254
+ continue;
255
+ }
256
+ }
257
+ yield SyncStateOnto.options(transaction, optionsToContinueDown, productsToValidate);
258
+ // stop as the method above handles the recursion down
259
+ return "stop";
260
+ });
261
+ }
262
+ /**
263
+ * Decides if the SyncState can be applied to the SelectMany Option, and then changes
264
+ * the state of the Option if so.
265
+ * @param syncCode What SyncGroup the Feature belongs to
266
+ * @param productsToValidate To this all products that will need validation are added
267
+ * @returns Whether we shall stop recursing down (because we are in a state which we
268
+ * expect to be resolved later), we shall continue recursing down.
269
+ */
270
+ static selectManyOption(transaction, syncCode, optionWithInitial, productsToValidate) {
271
+ return __awaiter(this, void 0, void 0, function* () {
272
+ const option = optionWithInitial.target;
273
+ const featureDidJustComeIntoScope = optionWithInitial.initial === undefined;
274
+ const optionSelected = option.selected;
275
+ const recurseOrStopIfNoChange = optionSelected ? "recurseDown" : "stop";
276
+ if (transaction.hasSelectManyOptionBeenAffected(option)) {
277
+ // This option has already changed selection once for this transaction. We expect
278
+ // this to happen very rarely, as the algorithm should settle the selection tree
279
+ // further and further out. Nevertheless, this safeguard is needed to avoid infinite
280
+ // looping if for example the server would return the same data over and over.
281
+ return recurseOrStopIfNoChange;
282
+ }
283
+ const optionCode = option.code;
284
+ if (!(featureDidJustComeIntoScope ||
285
+ transaction.isSyncGroupAffectedForSelectMany(syncCode, optionCode))) {
286
+ return "recurseDown";
287
+ }
288
+ const syncGroupValueForOption = transaction.syncState.getForSelectMany(syncCode, optionCode);
289
+ if (syncGroupValueForOption === undefined) {
290
+ // The sync group has no opinion on this. If it is selected, just continue down.
291
+ return recurseOrStopIfNoChange;
292
+ }
293
+ if (syncGroupValueForOption === optionSelected) {
294
+ // We are in sync for this option
295
+ return recurseOrStopIfNoChange;
296
+ }
297
+ const feature = option.parent;
298
+ // Update the value. Validations are collected so that we do not
299
+ // send more than necessary. Do not recurse further as we will change
300
+ // the state and so what is selected now won't be selected then.
301
+ yield feature.selectOption(option, syncGroupValueForOption, ProductConfigurationBubbleMode.ToRoot);
302
+ transaction.addSelectManyOptionAffected(option);
303
+ productsToValidate.add(feature.parentProduct);
304
+ return "stop";
305
+ });
306
+ }
307
+ }
308
+ class OntoSyncState {
309
+ /**
310
+ * @returns true if at least one Feature changed it state. This is a bit counter intuitive,
311
+ * but as this method will hand over to productOntoSyncState if it updates the SyncState it
312
+ * can cause the Features to change. And we need to pass that information back to know when
313
+ * to stop
314
+ */
315
+ static rootProduct(transaction) {
316
+ return __awaiter(this, void 0, void 0, function* () {
317
+ if (!(yield OntoSyncState.product(transaction, transaction))) {
318
+ // All done!
319
+ return false;
320
+ }
321
+ return yield SyncStateOnto.rootProduct(transaction, undefined);
322
+ });
323
+ }
324
+ static product(transaction, product) {
325
+ return __awaiter(this, void 0, void 0, function* () {
326
+ let change = false;
327
+ if (yield OntoSyncState.features(transaction, getFeaturesFromProduct(product))) {
328
+ if (transaction.updateMode === SyncGroupsApplyMode.Strict) {
329
+ return true;
330
+ }
331
+ change = true;
332
+ }
333
+ for (const additionalProduct of getAdditionalProducts(product)) {
334
+ if (yield OntoSyncState.product(transaction, additionalProduct)) {
335
+ if (transaction.updateMode === SyncGroupsApplyMode.Strict) {
336
+ return true;
337
+ }
338
+ change = true;
339
+ }
340
+ }
341
+ return change;
342
+ });
343
+ }
344
+ static features(transaction, featureWithInitials) {
345
+ return __awaiter(this, void 0, void 0, function* () {
346
+ let change = false;
347
+ for (const featureWithInitial of featureWithInitials) {
348
+ const feature = featureWithInitial.target;
349
+ switch (feature.selectionType) {
350
+ case SelectionType.SelectOne:
351
+ if (OntoSyncState.selectOneFeature(transaction, feature, false, featureWithInitial.initial === undefined)) {
352
+ change = true;
353
+ }
354
+ break;
355
+ case SelectionType.SelectMany:
356
+ if (OntoSyncState.selectManyFeature(transaction, featureWithInitial)) {
357
+ change = true;
358
+ }
359
+ break;
360
+ }
361
+ if (change && transaction.updateMode === SyncGroupsApplyMode.Strict) {
362
+ return true;
363
+ }
364
+ if (yield OntoSyncState.options(transaction, getSelectedOptions(featureWithInitial))) {
365
+ if (transaction.updateMode === SyncGroupsApplyMode.Strict) {
366
+ return true;
367
+ }
368
+ change = true;
369
+ }
370
+ }
371
+ return change;
372
+ });
373
+ }
374
+ static options(transaction, options) {
375
+ return __awaiter(this, void 0, void 0, function* () {
376
+ let change = false;
377
+ for (const option of options) {
378
+ if (yield OntoSyncState.features(transaction, getFeaturesFromOption(option))) {
379
+ if (transaction.updateMode === SyncGroupsApplyMode.Strict) {
380
+ return true;
381
+ }
382
+ change = true;
383
+ }
384
+ }
385
+ return change;
386
+ });
387
+ }
388
+ static selectOneFeature(transaction, feature, activeSelectionForce, featureDidJustComeIntoScope) {
389
+ const selectionType = feature.selectionType;
390
+ if (selectionType !== SelectionType.SelectOne) {
391
+ throw new Error("can only be used for selectOne");
392
+ }
393
+ const syncCode = SyncGroupsApplier.getSyncCode(feature.syncGroup, "push");
394
+ if (syncCode === undefined || syncCode === false) {
395
+ return false;
396
+ }
397
+ if (transaction.isSyncGroupAffectedForSelectOne(syncCode)) {
398
+ return false;
399
+ }
400
+ const syncState = transaction.syncState;
401
+ const currentSyncGroupOptionCode = syncState.getForSelectOne(syncCode);
402
+ const option = feature.selectedOptions[0];
403
+ if (option === undefined) {
404
+ // Options with no default are never written
405
+ return false;
406
+ }
407
+ if (activeSelectionForce) {
408
+ // To make re-apply happen, even if it actually does not update the sync group
409
+ transaction.addSyncGroupAffectedForSelectOne(syncCode);
410
+ }
411
+ const optionCode = option.code;
412
+ if (optionCode === currentSyncGroupOptionCode) {
413
+ return false;
414
+ }
415
+ // featureDidJustComeIntoScope, in CET there is a feature that if a feature appears which
416
+ // can not be set to the current sync group value, then it will set in the opposite
417
+ // direction. Like if the sync group was empty. To avoid bouncing back and forth we will
418
+ // need to enforce that a sync group can only be updated once per transaction
419
+ if (!(activeSelectionForce ||
420
+ currentSyncGroupOptionCode === undefined ||
421
+ (featureDidJustComeIntoScope &&
422
+ feature.options.every((o) => currentSyncGroupOptionCode !== o.code)))) {
423
+ return false;
424
+ }
425
+ // TODO: Remove
426
+ //syncState.logDebug();
427
+ transaction.addSyncGroupAffectedForSelectOne(syncCode);
428
+ syncState.setForSelectOne(syncCode, optionCode);
429
+ return true;
430
+ }
431
+ static selectManyFeature(transaction, featureWithInitial) {
432
+ let change = false;
433
+ for (const optionWithInitial of getOptions(featureWithInitial)) {
434
+ if (OntoSyncState.selectManyOption(transaction, optionWithInitial.target, false)) {
435
+ if (transaction.updateMode === SyncGroupsApplyMode.Strict) {
436
+ return true;
437
+ }
438
+ change = true;
439
+ }
440
+ }
441
+ return change;
442
+ }
443
+ static selectManyOption(transaction, option, activeSelectionForce) {
444
+ const feature = option.parent;
445
+ if (feature.selectionType !== SelectionType.SelectMany) {
446
+ throw new Error("can only be used for selectMany");
447
+ }
448
+ const syncCode = SyncGroupsApplier.getSyncCode(feature.syncGroup, "push");
449
+ if (syncCode === undefined || syncCode === false) {
450
+ return false;
451
+ }
452
+ const optionCode = option.code;
453
+ if (transaction.isSyncGroupAffectedForSelectMany(syncCode, optionCode)) {
454
+ return false;
455
+ }
456
+ const syncState = transaction.syncState;
457
+ const optionSelected = option.selected;
458
+ const currentSyncGroupValue = syncState.getForSelectMany(syncCode, optionCode);
459
+ if (activeSelectionForce) {
460
+ // To make re-apply happen, even if it actually does not update the sync group
461
+ transaction.addSyncGroupAffectedForSelectMany(syncCode, optionCode);
462
+ }
463
+ // We only initialize if the option is selected or we force.
464
+ // activeSelectionForce = active selection by the user.
465
+ if (!(currentSyncGroupValue === undefined && optionSelected) &&
466
+ !(activeSelectionForce && currentSyncGroupValue !== optionSelected)) {
467
+ return false;
468
+ }
469
+ transaction.addSyncGroupAffectedForSelectMany(syncCode, optionCode);
470
+ syncState.setForSelectMany(syncCode, optionCode, optionSelected);
471
+ return true;
472
+ }
473
+ }
474
+ function getAdditionalProducts(product) {
475
+ const initial = product.initial;
476
+ return product.target.additionalProducts.map((childTarget) => {
477
+ const refKey = childTarget.refKey;
478
+ const childInitial = initial === null || initial === void 0 ? void 0 : initial.additionalProducts.find((p) => refKey === p.refKey);
479
+ return {
480
+ target: childTarget._internal,
481
+ initial: childInitial === null || childInitial === void 0 ? void 0 : childInitial._internal,
482
+ };
483
+ });
484
+ }
485
+ function pairOptions(targets, initials) {
486
+ return targets.map((childTarget) => {
487
+ const key = childTarget.key;
488
+ const childInitial = initials === null || initials === void 0 ? void 0 : initials.find((o) => key === o.key);
489
+ return {
490
+ target: childTarget._internal,
491
+ initial: childInitial === null || childInitial === void 0 ? void 0 : childInitial._internal,
492
+ };
493
+ });
494
+ }
495
+ function getSelectedOptions(feature) {
496
+ var _a;
497
+ return pairOptions(feature.target.selectedOptions, (_a = feature.initial) === null || _a === void 0 ? void 0 : _a.selectedOptions);
498
+ }
499
+ function getOptions(feature) {
500
+ var _a;
501
+ return pairOptions(feature.target.options, (_a = feature.initial) === null || _a === void 0 ? void 0 : _a.options);
502
+ }
503
+ function pairFeatures(targets, initials) {
504
+ return targets.map((childTarget) => {
505
+ const key = childTarget.key;
506
+ const childInitial = initials === null || initials === void 0 ? void 0 : initials.find((f) => key === f.key);
507
+ return {
508
+ target: childTarget._internal,
509
+ initial: childInitial === null || childInitial === void 0 ? void 0 : childInitial._internal,
510
+ };
511
+ });
512
+ }
513
+ function getFeaturesFromProduct(product) {
514
+ var _a;
515
+ return pairFeatures(product.target.configuration.features, (_a = product.initial) === null || _a === void 0 ? void 0 : _a.configuration.features);
516
+ }
517
+ function getFeaturesFromOption(option) {
518
+ var _a;
519
+ return pairFeatures(option.target.features, (_a = option.initial) === null || _a === void 0 ? void 0 : _a.features);
520
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The SyncGroupsApplyMode controls how many SyncGroups can be updated in the SyncState for one
3
+ * run of rootProductOntoSyncState.
4
+ *
5
+ * "Fast" will update any SyncGroup that should be updated before running syncStateOntoRootProduct
6
+ * This way several SyncGroups can be applied in one go before sending the validation calls to the * server, making the whole process faster.
7
+ *
8
+ * The downside of this is that is not exactly how CET (the desktop software) works. CET will
9
+ * instead apply Features to the SyncState as soon as it gets the chance.
10
+ *
11
+ * "Strict" tries to behave exactly as CET. This will potentially generate a lot more validate
12
+ * calls, increasing delay and cost.
13
+ *
14
+ * Strict is the safer option of the two, but we still recommend trying out Fast since it should
15
+ * work fine in most cases.
16
+ */
17
+ export declare enum SyncGroupsApplyMode {
18
+ Strict = "Strict",
19
+ Fast = "Fast"
20
+ }
21
+ //# sourceMappingURL=SyncGroupsApplyMode.d.ts.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The SyncGroupsApplyMode controls how many SyncGroups can be updated in the SyncState for one
3
+ * run of rootProductOntoSyncState.
4
+ *
5
+ * "Fast" will update any SyncGroup that should be updated before running syncStateOntoRootProduct
6
+ * This way several SyncGroups can be applied in one go before sending the validation calls to the * server, making the whole process faster.
7
+ *
8
+ * The downside of this is that is not exactly how CET (the desktop software) works. CET will
9
+ * instead apply Features to the SyncState as soon as it gets the chance.
10
+ *
11
+ * "Strict" tries to behave exactly as CET. This will potentially generate a lot more validate
12
+ * calls, increasing delay and cost.
13
+ *
14
+ * Strict is the safer option of the two, but we still recommend trying out Fast since it should
15
+ * work fine in most cases.
16
+ */
17
+ export var SyncGroupsApplyMode;
18
+ (function (SyncGroupsApplyMode) {
19
+ SyncGroupsApplyMode["Strict"] = "Strict";
20
+ SyncGroupsApplyMode["Fast"] = "Fast";
21
+ })(SyncGroupsApplyMode || (SyncGroupsApplyMode = {}));
@@ -0,0 +1,31 @@
1
+ import { _CfgProductInternal } from "../CfgProduct.js";
2
+ import { ProductLoader } from "../productLoader.js";
3
+ import { SyncGroupsApplyMode } from "./SyncGroupsApplyMode.js";
4
+ import { CfgPath } from "./SyncGroupsPathHelper.js";
5
+ import { SyncGroupsTransaction } from "./SyncGroupsTransaction.js";
6
+ export declare type SyncCode = string;
7
+ export declare type OptionCode = string;
8
+ /**
9
+ * Is used to apply the SyncGroups functionality on the Configuration and the other
10
+ * way around. It also keeps the SyncState.
11
+ */
12
+ export declare class SyncGroupsHandler {
13
+ private _syncState;
14
+ readonly updateMode: SyncGroupsApplyMode;
15
+ private _currentTransaction;
16
+ static make(updateMode?: SyncGroupsApplyMode): SyncGroupsHandler;
17
+ private constructor();
18
+ clone(): SyncGroupsHandler;
19
+ /**
20
+ * Used to initially apply the sync state onto a new product so that it is "in sync"
21
+ */
22
+ init(product: _CfgProductInternal, productLoader: ProductLoader): Promise<void>;
23
+ /**
24
+ * Used when an Option is selected or deselected to apply all consequences of the sync groups.
25
+ * Can cause multiple extra validation calls to the server.
26
+ */
27
+ selectOption(product: _CfgProductInternal, optionPath: CfgPath, on: boolean, productLoader: ProductLoader): Promise<boolean>;
28
+ newTransaction(product: _CfgProductInternal, productLoader: ProductLoader, assumeNoStartProductState: boolean): Promise<SyncGroupsTransaction>;
29
+ applyTransaction(transaction: SyncGroupsTransaction): Promise<void>;
30
+ }
31
+ //# sourceMappingURL=SyncGroupsHandler.d.ts.map
@@ -0,0 +1,71 @@
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 { SyncGroupsApplyMode } from "./SyncGroupsApplyMode.js";
11
+ import { SyncGroupsState } from "./SyncGroupsState.js";
12
+ import { SyncGroupsTransaction } from "./SyncGroupsTransaction.js";
13
+ /**
14
+ * Is used to apply the SyncGroups functionality on the Configuration and the other
15
+ * way around. It also keeps the SyncState.
16
+ */
17
+ export class SyncGroupsHandler {
18
+ constructor(_syncState, updateMode) {
19
+ this._syncState = _syncState;
20
+ this.updateMode = updateMode;
21
+ }
22
+ static make(updateMode = SyncGroupsApplyMode.Strict) {
23
+ return new SyncGroupsHandler(new SyncGroupsState(), updateMode);
24
+ }
25
+ clone() {
26
+ return new SyncGroupsHandler(this._syncState.clone(), this.updateMode);
27
+ }
28
+ /**
29
+ * Used to initially apply the sync state onto a new product so that it is "in sync"
30
+ */
31
+ init(product, productLoader) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const transaction = yield this.newTransaction(product, productLoader, true);
34
+ yield transaction.init();
35
+ yield this.applyTransaction(transaction);
36
+ });
37
+ }
38
+ /**
39
+ * Used when an Option is selected or deselected to apply all consequences of the sync groups.
40
+ * Can cause multiple extra validation calls to the server.
41
+ */
42
+ selectOption(product, optionPath, on, productLoader) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ //todo: should we guarantee that it will use root? Tricky...
45
+ const transaction = yield this.newTransaction(product, productLoader, false);
46
+ const change = yield transaction.selectOption(optionPath, on);
47
+ // We always apply. The change-result above only tells if the configuration
48
+ // has changed. The SyncState may also have changed.
49
+ yield this.applyTransaction(transaction);
50
+ return change;
51
+ });
52
+ }
53
+ newTransaction(product, productLoader, assumeNoStartProductState) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ if (this._currentTransaction !== undefined) {
56
+ this._currentTransaction.abort();
57
+ }
58
+ this._currentTransaction = yield SyncGroupsTransaction.make(this._syncState, this.updateMode, product, productLoader, assumeNoStartProductState);
59
+ return this._currentTransaction;
60
+ });
61
+ }
62
+ applyTransaction(transaction) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ if (transaction.isAborted) {
65
+ return;
66
+ }
67
+ this._syncState.setFrom(transaction.syncState);
68
+ yield transaction.original.copyFrom(transaction.target, false, transaction.productLoader);
69
+ });
70
+ }
71
+ }