@one-paragon/angular-utilities 0.1.17 → 0.1.19

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.
@@ -1,8 +1,8 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Directive, Input, NgModule, Injectable, InjectionToken, Pipe, HostListener, Component, EventEmitter, Output, ContentChildren, Inject, ChangeDetectionStrategy, ViewChild, Injector, ElementRef, Optional } from '@angular/core';
3
- import { shareReplay, switchAll, map, filter, tap, catchError, startWith, switchMap, mergeMap, pluck, last, takeUntil, distinctUntilKeyChanged, delay as delay$1, distinct, first as first$1, distinctUntilChanged, withLatestFrom, mergeAll, scan as scan$1 } from 'rxjs/operators';
3
+ import { shareReplay, switchAll, map, filter, tap, catchError, startWith, switchMap, mergeMap, concatMap, last, takeUntil, distinctUntilKeyChanged, delay as delay$1, distinct, first as first$1, distinctUntilChanged, withLatestFrom, mergeAll, scan as scan$1 } from 'rxjs/operators';
4
4
  import * as i3$3 from 'rxjs';
5
- import { Subject, isObservable, of, ReplaySubject, filter as filter$1, first, map as map$1, Observable, combineLatest, Subscription, startWith as startWith$1, pairwise, concatMap, merge, delay, switchMap as switchMap$1, scan, fromEvent, asyncScheduler, tap as tap$1, BehaviorSubject, takeUntil as takeUntil$1, from } from 'rxjs';
5
+ import { Subject, isObservable, of, ReplaySubject, filter as filter$1, first, map as map$1, Observable, combineLatest, Subscription, startWith as startWith$1, pairwise, concatMap as concatMap$1, merge, delay, switchMap as switchMap$1, scan, fromEvent, asyncScheduler, tap as tap$1, BehaviorSubject, takeUntil as takeUntil$1, from } from 'rxjs';
6
6
  import { ComponentStore } from '@ngrx/component-store';
7
7
  import * as i4$4 from '@angular/material/table';
8
8
  import { MatColumnDef, MatTableDataSource, MatTable, MatTableModule, MatRowDef } from '@angular/material/table';
@@ -86,6 +86,7 @@ var HttpRequestStrategy;
86
86
  HttpRequestStrategy[HttpRequestStrategy["concurrent"] = 1] = "concurrent";
87
87
  HttpRequestStrategy[HttpRequestStrategy["singleUse"] = 2] = "singleUse";
88
88
  HttpRequestStrategy[HttpRequestStrategy["cancelPrevious"] = 3] = "cancelPrevious";
89
+ HttpRequestStrategy[HttpRequestStrategy["sequential"] = 4] = "sequential";
89
90
  })(HttpRequestStrategy || (HttpRequestStrategy = {}));
90
91
 
91
92
  function isErrorState(state) {
@@ -94,6 +95,9 @@ function isErrorState(state) {
94
95
  function isSuccessState(state) {
95
96
  return state.status === HttpRequestStatus.success;
96
97
  }
98
+ function isSuccessOrErrorState(state) {
99
+ return state.status === HttpRequestStatus.success || state.status === HttpRequestStatus.fail;
100
+ }
97
101
  function createSuccess(body) {
98
102
  return { status: HttpRequestStatus.success, body };
99
103
  }
@@ -395,10 +399,12 @@ class HttpRequestStateStore extends ComponentStore {
395
399
  this.req = req;
396
400
  this.options = options;
397
401
  this.flatteningStrategy = () => {
398
- if (this.options?.strategy !== HttpRequestStrategy.concurrent) {
399
- return switchMap((params) => this.createRequest(...params));
400
- }
401
- return mergeMap((params) => this.createRequest(...params));
402
+ if (this.options?.strategy === HttpRequestStrategy.concurrent)
403
+ return mergeMap((params) => this.createRequest(...params));
404
+ if (this.options?.strategy === HttpRequestStrategy.sequential)
405
+ return concatMap((params) => this.createRequest(...params));
406
+ return switchMap((params) => (params[0] instanceof CancellationToken) ?
407
+ of({ requestParams: params[0], response: { status: HttpRequestStatus.cancelled } }) : this.createRequest(...params));
402
408
  };
403
409
  this.requestEffect = this.effect((obs) => {
404
410
  return (obs).pipe(this.flatteningStrategy(), tap(state => this.setState(state)));
@@ -412,10 +418,11 @@ class HttpRequestStateStore extends ComponentStore {
412
418
  }
413
419
  return this.requestEffect(value);
414
420
  };
415
- this.selectHttpState$ = this.state$.pipe(pluck('response'));
416
- this.selectStatus$ = this.selectHttpState$.pipe(pluck('status'));
421
+ this.selectHttpState$ = this.state$.pipe(map(a => a.response));
422
+ this.selectStatus$ = this.selectHttpState$.pipe(map(a => a.status));
417
423
  this.selectError$ = this.state$.pipe(map(r => r.response), filter(isErrorState), map(state => state.error));
418
424
  this.selectResponse$ = this.state$.pipe(map(r => r.response), filter(isSuccessState), map(state => state.body));
425
+ this.selectSuccessOrError$ = this.state$.pipe(map(r => r.response), filter(isSuccessOrErrorState), map(() => null));
419
426
  this.errorHandled = false;
420
427
  this.on = (srcObservable, func) => {
421
428
  return this.effect((src) => {
@@ -436,12 +443,25 @@ class HttpRequestStateStore extends ComponentStore {
436
443
  this.on(this.selectResponse$, cb);
437
444
  return this;
438
445
  }
446
+ onSuccessOrError(cb) {
447
+ this.on(this.selectSuccessOrError$, cb);
448
+ return this;
449
+ }
439
450
  onSuccessWithRequest(func) {
440
451
  this.onUpdate(({ requestParams, response }) => {
441
452
  if (isSuccessState(response)) {
442
453
  func({ requestParams, body: response.body });
443
454
  }
444
455
  });
456
+ return this;
457
+ }
458
+ onErrorWithRequest(func) {
459
+ this.onUpdate(({ requestParams, response }) => {
460
+ if (isErrorState(response)) {
461
+ func({ requestParams, error: response.error });
462
+ }
463
+ });
464
+ return this;
445
465
  }
446
466
  createRequest(...params) {
447
467
  return this.req(...params).pipe(map(createSuccess), mapError(createFailure), startWith(inProgress), map(state => ({ requestParams: params, response: state })), defaultShareReplay());
@@ -457,7 +477,9 @@ HttpRequestStateStore.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", ve
457
477
  HttpRequestStateStore.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: HttpRequestStateStore, usesInheritance: true, ngImport: i0 });
458
478
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: HttpRequestStateStore, decorators: [{
459
479
  type: Directive
460
- }], ctorParameters: function () { return [{ type: undefined }, { type: undefined }]; } });
480
+ }], ctorParameters: function () { return [{ type: undefined }, { type: undefined }]; } });
481
+ class CancellationToken {
482
+ }
461
483
 
462
484
  class HttpRequestStateFactory {
463
485
  constructor() {
@@ -595,7 +617,7 @@ function notNull() {
595
617
  }
596
618
  function delayOn(predicate, delayTime) {
597
619
  return (src) => {
598
- return src.pipe(concatMap(r => {
620
+ return src.pipe(concatMap$1(r => {
599
621
  if (predicate(r)) {
600
622
  return merge(of({ r }), of(null).pipe(delay(delayTime))).pipe(notNull(), map$1(d => d.r));
601
623
  }
@@ -1025,9 +1047,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImpor
1025
1047
  * Turns underscores into spaces
1026
1048
  */
1027
1049
  function spaceCase(value) {
1028
- return value?.replace(/([a-z0-9])([A-Z])|([a-zA-Z0-9])([A-Z])(?=[a-z])|_/g, '$1 $2')
1029
- // uppercase the first character
1030
- .replace(/^./, str => str.toUpperCase());
1050
+ const phrase = value?.replace(/([a-z0-9])([A-Z])|([a-zA-Z0-9])([A-Z])(?=[a-z])|_/g, '$1$3 $2$4');
1051
+ // uppercase the first character of every word
1052
+ return phrase?.replace(/(^| )(\w)/g, x => x.toUpperCase());
1031
1053
  }
1032
1054
 
1033
1055
  class ConditionalClassesDirective {
@@ -4638,5 +4660,5 @@ const shallowEquals = (first, second) => {
4638
4660
  * Generated bundle index. Do not edit.
4639
4661
  */
4640
4662
 
4641
- export { ActionStateSpinnerComponent, ActionStateUiModule, ActionStatus, AppStatusState, ArrayStyle, AutoFocusDirective, ClickEmitterDirective, ClickSubjectDirective, ConditionalClassesDirective, CreateTableBuilder, CustomCellDirective, DateFilterComponent, DialogDirective, DialogService, DialogWrapper, FieldType, FilterChipsComponent, FilterComponent, FilterType, FunctionPipe, GenColDisplayerComponent, GenFilterDisplayerComponent, GeneralTableSettings, GenericTableComponent, GroupByListComponent, HttpErrorStateDirective, HttpInProgressStateDirective, HttpNotStartedStateDirective, HttpRequestModule, HttpRequestStateDirective, HttpRequestStateFactory, HttpRequestStateStore, HttpRequestStatus, HttpRequestStrategy, HttpSuccessStateDirective, MatButtonToggleFilterDirective, MatCheckboxTbFilterDirective, MatOptionTbFilterDirective, MatRadioButtonTbFilterDirective, MatSlideToggleGroupDirective, MatSlideToggleTbFilterDirective, MatTableObservableDataSource, MultiSortDirective, NgrxExtModule, NotPersisitedTableSettings, PaginatorComponent, PesrsistedTableSettings, PhoneNumberPipe, PreventEnterDirective, ResizeColumnDirective, SortDirection, SpaceCasePipe, StopPropagationDirective, StylerDirective, Subjectifier, TableBuilder, TableBuilderModule, TableColumnHeaderSettings, TableContainerComponent, TableCustomFilterDirective, TableCustomFilterDirectiveBase, TableFilterDirective, TableFilterStringContainsDirective, TableWrapperDirective, TableWrapperFooterSettings, TableWrapperHeaderSettings, Target, TbSelectedFilterDirective, TrimWhitespaceDirective, UtilitiesModule, actionStatusReducer, chainRequest, combineArrays, createActionableSelector, createFailure, createSuccess, defaultFilter, defaultShareReplay, delayOn, filterArray, getRequestorBody, getRequestorStatus, getStatusState, httpRequest, httpRequestor, inProgress, initialState, isErrorState, isSuccessState, mapArray, mapError, notNull, notStarted, onWait, onceWhen, previousAndCurrent, selectAll, selectEntities, selectEntity, selectIds, selectTotal, serverStatusTypes, setUpStoreFactory, skipOneWhen, spaceCase, statusAdapter, statusIsSuccessOrInProgress, switchOff, tapError, tapSuccess };
4663
+ export { ActionStateSpinnerComponent, ActionStateUiModule, ActionStatus, AppStatusState, ArrayStyle, AutoFocusDirective, CancellationToken, ClickEmitterDirective, ClickSubjectDirective, ConditionalClassesDirective, CreateTableBuilder, CustomCellDirective, DateFilterComponent, DialogDirective, DialogService, DialogWrapper, FieldType, FilterChipsComponent, FilterComponent, FilterType, FunctionPipe, GenColDisplayerComponent, GenFilterDisplayerComponent, GeneralTableSettings, GenericTableComponent, GroupByListComponent, HttpErrorStateDirective, HttpInProgressStateDirective, HttpNotStartedStateDirective, HttpRequestModule, HttpRequestStateDirective, HttpRequestStateFactory, HttpRequestStateStore, HttpRequestStatus, HttpRequestStrategy, HttpSuccessStateDirective, MatButtonToggleFilterDirective, MatCheckboxTbFilterDirective, MatOptionTbFilterDirective, MatRadioButtonTbFilterDirective, MatSlideToggleGroupDirective, MatSlideToggleTbFilterDirective, MatTableObservableDataSource, MultiSortDirective, NgrxExtModule, NotPersisitedTableSettings, PaginatorComponent, PesrsistedTableSettings, PhoneNumberPipe, PreventEnterDirective, ResizeColumnDirective, SortDirection, SpaceCasePipe, StopPropagationDirective, StylerDirective, Subjectifier, TableBuilder, TableBuilderModule, TableColumnHeaderSettings, TableContainerComponent, TableCustomFilterDirective, TableCustomFilterDirectiveBase, TableFilterDirective, TableFilterStringContainsDirective, TableWrapperDirective, TableWrapperFooterSettings, TableWrapperHeaderSettings, Target, TbSelectedFilterDirective, TrimWhitespaceDirective, UtilitiesModule, actionStatusReducer, chainRequest, combineArrays, createActionableSelector, createFailure, createSuccess, defaultFilter, defaultShareReplay, delayOn, filterArray, getRequestorBody, getRequestorStatus, getStatusState, httpRequest, httpRequestor, inProgress, initialState, isErrorState, isSuccessOrErrorState, isSuccessState, mapArray, mapError, notNull, notStarted, onWait, onceWhen, previousAndCurrent, selectAll, selectEntities, selectEntity, selectIds, selectTotal, serverStatusTypes, setUpStoreFactory, skipOneWhen, spaceCase, statusAdapter, statusIsSuccessOrInProgress, switchOff, tapError, tapSuccess };
4642
4664
  //# sourceMappingURL=one-paragon-angular-utilities.mjs.map