@veloceapps/sdk 8.0.0-144 → 8.0.0-146

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.
@@ -3,7 +3,7 @@ import { Injectable, InjectionToken, Optional, Inject, NgModule, inject, Directi
3
3
  import { UUID, ConfigurationContextMode, ConfigurationContext, UITemplateType, isDefined, ConfigurationProcessorTypes, EntityUtil, DEFAULT_CURRENCY_ISO_CODE, DEFAULT_CURRENCY_SYMBOL, validateDateFormat, DEFAULT_DATE_FORMAT, DEFAULT_DECIMALS_COUNT, getSupportedDateFormats, DEFAULT_DECIMAL_SEPARATOR, DEFAULT_THOUSANDS_SEPARATOR, DEFAULT_ACTION_CODE_LABELS, parseJsonSafely, ConfigurationMode, ConfigurationTranslatorUtils, ChargeGroupUtils, RuntimeModel, isNotLegacyUIDefinition, SalesforceIdUtils, DEFAULT_TIME_FORMAT, formatNumber } from '@veloceapps/core';
4
4
  import * as i1 from '@veloceapps/api';
5
5
  import { ApiModule } from '@veloceapps/api';
6
- import { BehaviorSubject, switchMap, map as map$1, tap as tap$1, noop, catchError, throwError, of, forkJoin, Subject, filter as filter$1, zip, combineLatest, shareReplay as shareReplay$1, finalize, takeUntil, take as take$1, distinctUntilChanged } from 'rxjs';
6
+ import { BehaviorSubject, switchMap, map as map$1, tap as tap$1, noop, catchError, throwError, of, forkJoin, Subject, filter as filter$1, zip, combineLatest, shareReplay as shareReplay$1, finalize, takeUntil, buffer, debounceTime, share, take as take$1, distinctUntilChanged } from 'rxjs';
7
7
  import { map, filter, tap, switchMap as switchMap$1, skip, take, shareReplay, catchError as catchError$1, finalize as finalize$1, first } from 'rxjs/operators';
8
8
  import { merge, isEmpty, flatten, entries, sortBy, map as map$2, omit, isEqual, cloneDeep, assign, uniqBy, transform, uniq } from 'lodash';
9
9
  import * as i6 from '@veloceapps/components';
@@ -820,13 +820,17 @@ class FlowStateService {
820
820
  this.toastService = toastService;
821
821
  this.customizationService = customizationService;
822
822
  this.NOT_INITIALIZED = Symbol();
823
+ this.EXECUTION_BUFFER_TIME = 100;
823
824
  this.executedFunctions = {};
824
825
  this.stateId$ = new BehaviorSubject(null);
825
826
  this._hasStatefulUnsavedChanges = false;
826
827
  this.processors = {};
827
828
  this.subscriptions = {};
828
829
  this.flowStore = {};
830
+ this.statefulExecutionInProgress$ = new BehaviorSubject(false);
831
+ this.statefulRequestStream$ = new Subject();
829
832
  this.cleanup$ = new Subject();
833
+ this.statefulExecutionRequest$ = this.initBufferedRequest$();
830
834
  /*
831
835
  In stateless mode watch QuoteDraft changes and call executeRequest so that
832
836
  all subscriptions get their updates according to updated QuoteDraft
@@ -1035,7 +1039,7 @@ class FlowStateService {
1035
1039
  this.toastService.add({ severity: ToastType.error, summary: selectorResult.errorMessage });
1036
1040
  }
1037
1041
  const subscription$ = this.subscriptions[requestId]?.data$;
1038
- if (subscription$) {
1042
+ if (subscription$ && subscription$.value !== selectorResult) {
1039
1043
  subscription$.next(selectorResult);
1040
1044
  }
1041
1045
  });
@@ -1070,15 +1074,30 @@ class FlowStateService {
1070
1074
  this.stateId$.next(stateId);
1071
1075
  }));
1072
1076
  }
1073
- executeStateful$(request) {
1074
- if (!this.stateId$.value) {
1075
- throw 'Stateful session is not initialized';
1076
- }
1077
- return this.flowStateApiService.execute(this.stateId$.value, request).pipe(tap$1(() => {
1078
- if (request.actions?.length) {
1079
- this._hasStatefulUnsavedChanges = true;
1077
+ initBufferedRequest$() {
1078
+ return this.statefulRequestStream$.pipe(buffer(this.statefulRequestStream$.pipe(debounceTime(this.EXECUTION_BUFFER_TIME))), switchMap(requests => {
1079
+ if (!this.stateId$.value) {
1080
+ throw 'Stateful session is not initialized';
1080
1081
  }
1081
- }), tap$1(response => this.stateId$.next(response.stateId)));
1082
+ // merge buffered requests
1083
+ const request = {
1084
+ actions: requests.flatMap(({ actions }) => actions).filter(isDefined),
1085
+ selectors: requests
1086
+ .map(({ selectors }) => selectors)
1087
+ .filter(isDefined)
1088
+ .reduce((acc, selectorsMap) => Object.assign(acc, selectorsMap), {}),
1089
+ };
1090
+ this.statefulExecutionInProgress$.next(true);
1091
+ return this.flowStateApiService.execute(this.stateId$.value, request);
1092
+ }), tap$1(({ stateId }) => this.stateId$.next(stateId)), share(), tap$1(() => this.statefulExecutionInProgress$.next(false)));
1093
+ }
1094
+ executeStateful$(request) {
1095
+ return this.statefulExecutionInProgress$.pipe(filter$1(inProgress => !inProgress), take$1(1), switchMap(() =>
1096
+ // make sure stream switches to statefulExecutionRequest$ before pushing an execution request
1097
+ combineLatest([
1098
+ this.statefulExecutionRequest$,
1099
+ of(undefined).pipe(tap$1(() => this.statefulRequestStream$.next(request))),
1100
+ ])), map$1(([response]) => response), take$1(1));
1082
1101
  }
1083
1102
  initStateless$() {
1084
1103
  const { headerId } = this.contextService.resolve();