@ngrx/data 15.2.1 → 15.3.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.
@@ -1,8 +1,8 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, InjectionToken, Optional, Inject, ENVIRONMENT_INITIALIZER, inject, makeEnvironmentProviders, NgModule } from '@angular/core';
2
+ import { Injectable, InjectionToken, isDevMode, Optional, Inject, ENVIRONMENT_INITIALIZER, inject, makeEnvironmentProviders, NgModule } from '@angular/core';
3
3
  import { filter, map, delay, timeout, catchError, shareReplay, take, mergeMap, withLatestFrom, concatMap } from 'rxjs/operators';
4
4
  import * as i1 from '@angular/common/http';
5
- import { HttpParams } from '@angular/common/http';
5
+ import { HttpParams, HttpHeaders } from '@angular/common/http';
6
6
  import * as i4 from 'rxjs';
7
7
  import { throwError, of, race, asyncScheduler, merge } from 'rxjs';
8
8
  import { createEntityAdapter } from '@ngrx/entity';
@@ -700,72 +700,106 @@ class DefaultDataService {
700
700
  get name() {
701
701
  return this._name;
702
702
  }
703
- add(entity) {
703
+ add(entity, options) {
704
704
  const entityOrError = entity || new Error(`No "${this.entityName}" entity to add`);
705
- return this.execute('POST', this.entityUrl, entityOrError);
705
+ return this.execute('POST', this.entityUrl, entityOrError, options);
706
706
  }
707
- delete(key) {
707
+ delete(key, options) {
708
708
  let err;
709
709
  if (key == null) {
710
710
  err = new Error(`No "${this.entityName}" key to delete`);
711
711
  }
712
- return this.execute('DELETE', this.entityUrl + key, err).pipe(
712
+ return this.execute('DELETE', this.entityUrl + key, err, options).pipe(
713
713
  // forward the id of deleted entity as the result of the HTTP DELETE
714
714
  map((result) => key));
715
715
  }
716
- getAll() {
717
- return this.execute('GET', this.entitiesUrl);
716
+ getAll(options) {
717
+ return this.execute('GET', this.entitiesUrl, options);
718
718
  }
719
- getById(key) {
719
+ getById(key, options) {
720
720
  let err;
721
721
  if (key == null) {
722
722
  err = new Error(`No "${this.entityName}" key to get`);
723
723
  }
724
- return this.execute('GET', this.entityUrl + key, err);
724
+ return this.execute('GET', this.entityUrl + key, err, options);
725
725
  }
726
- getWithQuery(queryParams) {
726
+ getWithQuery(queryParams, options) {
727
727
  const qParams = typeof queryParams === 'string'
728
728
  ? { fromString: queryParams }
729
729
  : { fromObject: queryParams };
730
730
  const params = new HttpParams(qParams);
731
- return this.execute('GET', this.entitiesUrl, undefined, { params });
731
+ return this.execute('GET', this.entitiesUrl, undefined, { params }, options);
732
732
  }
733
- update(update) {
733
+ update(update, options) {
734
734
  const id = update && update.id;
735
735
  const updateOrError = id == null
736
736
  ? new Error(`No "${this.entityName}" update data or id`)
737
737
  : update.changes;
738
- return this.execute('PUT', this.entityUrl + id, updateOrError);
738
+ return this.execute('PUT', this.entityUrl + id, updateOrError, options);
739
739
  }
740
740
  // Important! Only call if the backend service supports upserts as a POST to the target URL
741
- upsert(entity) {
741
+ upsert(entity, options) {
742
742
  const entityOrError = entity || new Error(`No "${this.entityName}" entity to upsert`);
743
- return this.execute('POST', this.entityUrl, entityOrError);
743
+ return this.execute('POST', this.entityUrl, entityOrError, options);
744
744
  }
745
745
  execute(method, url, data, // data, error, or undefined/null
746
- options) {
747
- const req = { method, url, data, options };
746
+ options, // options or undefined/null
747
+ httpOptions // these override any options passed via options
748
+ ) {
749
+ let ngHttpClientOptions = undefined;
750
+ if (httpOptions) {
751
+ ngHttpClientOptions = {
752
+ headers: httpOptions?.httpHeaders
753
+ ? new HttpHeaders(httpOptions?.httpHeaders)
754
+ : undefined,
755
+ params: httpOptions?.httpParams
756
+ ? new HttpParams(httpOptions?.httpParams)
757
+ : undefined,
758
+ };
759
+ }
760
+ // If any options have been specified, pass them to http client. Note
761
+ // the new http options, if specified, will override any options passed
762
+ // from the deprecated options parameter
763
+ let mergedOptions = undefined;
764
+ if (options || ngHttpClientOptions) {
765
+ if (isDevMode() && options && ngHttpClientOptions) {
766
+ console.warn('@ngrx/data: options.httpParams will be merged with queryParams when both are are provided to getWithQuery(). In the event of a conflict HttpOptions.httpParams will override queryParams`. The queryParams parameter of getWithQuery() will be removed in next major release.');
767
+ }
768
+ mergedOptions = {};
769
+ if (ngHttpClientOptions?.headers) {
770
+ mergedOptions.headers = ngHttpClientOptions?.headers;
771
+ }
772
+ if (ngHttpClientOptions?.params || options?.params) {
773
+ mergedOptions.params = ngHttpClientOptions?.params ?? options?.params;
774
+ }
775
+ }
776
+ const req = {
777
+ method,
778
+ url,
779
+ data,
780
+ options: mergedOptions,
781
+ };
748
782
  if (data instanceof Error) {
749
783
  return this.handleError(req)(data);
750
784
  }
751
785
  let result$;
752
786
  switch (method) {
753
787
  case 'DELETE': {
754
- result$ = this.http.delete(url, options);
788
+ result$ = this.http.delete(url, ngHttpClientOptions);
755
789
  if (this.saveDelay) {
756
790
  result$ = result$.pipe(delay(this.saveDelay));
757
791
  }
758
792
  break;
759
793
  }
760
794
  case 'GET': {
761
- result$ = this.http.get(url, options);
795
+ result$ = this.http.get(url, mergedOptions);
762
796
  if (this.getDelay) {
763
797
  result$ = result$.pipe(delay(this.getDelay));
764
798
  }
765
799
  break;
766
800
  }
767
801
  case 'POST': {
768
- result$ = this.http.post(url, data, options);
802
+ result$ = this.http.post(url, data, ngHttpClientOptions);
769
803
  if (this.saveDelay) {
770
804
  result$ = result$.pipe(delay(this.saveDelay));
771
805
  }
@@ -773,7 +807,7 @@ class DefaultDataService {
773
807
  }
774
808
  // N.B.: It must return an Update<T>
775
809
  case 'PUT': {
776
- result$ = this.http.put(url, data, options);
810
+ result$ = this.http.put(url, data, ngHttpClientOptions);
777
811
  if (this.saveDelay) {
778
812
  result$ = result$.pipe(delay(this.saveDelay));
779
813
  }
@@ -2069,23 +2103,23 @@ class EntityEffects {
2069
2103
  }
2070
2104
  }
2071
2105
  callDataService(action) {
2072
- const { entityName, entityOp, data } = action.payload;
2106
+ const { entityName, entityOp, data, httpOptions } = action.payload;
2073
2107
  const service = this.dataService.getService(entityName);
2074
2108
  switch (entityOp) {
2075
2109
  case EntityOp.QUERY_ALL:
2076
2110
  case EntityOp.QUERY_LOAD:
2077
- return service.getAll();
2111
+ return service.getAll(httpOptions);
2078
2112
  case EntityOp.QUERY_BY_KEY:
2079
- return service.getById(data);
2113
+ return service.getById(data, httpOptions);
2080
2114
  case EntityOp.QUERY_MANY:
2081
- return service.getWithQuery(data);
2115
+ return service.getWithQuery(data, httpOptions);
2082
2116
  case EntityOp.SAVE_ADD_ONE:
2083
- return service.add(data);
2117
+ return service.add(data, httpOptions);
2084
2118
  case EntityOp.SAVE_DELETE_ONE:
2085
- return service.delete(data);
2119
+ return service.delete(data, httpOptions);
2086
2120
  case EntityOp.SAVE_UPDATE_ONE:
2087
2121
  const { id, changes } = data; // data must be Update<T>
2088
- return service.update(data).pipe(map((updatedEntity) => {
2122
+ return service.update(data, httpOptions).pipe(map((updatedEntity) => {
2089
2123
  // Return an Update<T> with updated entity data.
2090
2124
  // If server returned entity data, merge with the changes that were sent
2091
2125
  // and set the 'changed' flag to true.
@@ -2099,7 +2133,7 @@ class EntityEffects {
2099
2133
  return responseData;
2100
2134
  }));
2101
2135
  case EntityOp.SAVE_UPSERT_ONE:
2102
- return service.upsert(data).pipe(map((upsertedEntity) => {
2136
+ return service.upsert(data, httpOptions).pipe(map((upsertedEntity) => {
2103
2137
  const hasData = upsertedEntity && Object.keys(upsertedEntity).length > 0;
2104
2138
  return hasData ? upsertedEntity : data; // ensure a returned entity value.
2105
2139
  }));
@@ -4966,4 +5000,3 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImpor
4966
5000
 
4967
5001
  export { ChangeSetItemFactory, ChangeSetOperation, ChangeType, ClearCollections, CorrelationIdGenerator, DataServiceError, DefaultDataService, DefaultDataServiceConfig, DefaultDataServiceFactory, DefaultHttpUrlGenerator, DefaultLogger, DefaultPersistenceResultHandler, DefaultPluralizer, ENTITY_CACHE_META_REDUCERS, ENTITY_CACHE_NAME, ENTITY_CACHE_NAME_TOKEN, ENTITY_CACHE_SELECTOR_TOKEN, ENTITY_COLLECTION_META_REDUCERS, ENTITY_METADATA_TOKEN, EntityActionFactory, EntityActionGuard, EntityCacheAction, EntityCacheDataService, EntityCacheDispatcher, EntityCacheEffects, EntityCacheReducerFactory, EntityChangeTrackerBase, EntityCollectionCreator, EntityCollectionReducerFactory, EntityCollectionReducerMethods, EntityCollectionReducerMethodsFactory, EntityCollectionReducerRegistry, EntityCollectionServiceBase, EntityCollectionServiceElementsFactory, EntityCollectionServiceFactory, EntityDataModule, EntityDataModuleWithoutEffects, EntityDataService, EntityDefinitionService, EntityDispatcherBase, EntityDispatcherDefaultOptions, EntityDispatcherFactory, EntityEffects, EntityHttpResourceUrls, EntityOp, EntitySelectors$Factory, EntitySelectorsFactory, EntityServices, EntityServicesBase, EntityServicesElements, HttpUrlGenerator, INITIAL_ENTITY_CACHE_STATE, LoadCollections, Logger, MergeQuerySet, MergeStrategy, OP_ERROR, OP_SUCCESS, PLURAL_NAMES_TOKEN, PersistanceCanceled, PersistenceResultHandler, Pluralizer, PropsFilterFnFactory, SaveEntities, SaveEntitiesCancel, SaveEntitiesCanceled, SaveEntitiesError, SaveEntitiesSuccess, SetEntityCache, changeSetItemFactory, createEmptyEntityCollection, createEntityCacheSelector, createEntityDefinition, defaultSelectId, entityCacheSelectorProvider, excludeEmptyChangeSetItems, flattenArgs, getGuid, getGuidComb, guidComparer, makeErrorOp, makeSuccessOp, normalizeRoot, ofEntityOp, ofEntityType, persistOps, provideEntityData, toUpdateFactory, withEffects };
4968
5002
  //# sourceMappingURL=ngrx-data.mjs.map
4969
- //# sourceMappingURL=ngrx-data.mjs.map