@ngrx/data 15.2.1 → 15.4.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,109 @@ 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, null, 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, null, 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, null, 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, null, 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, null, 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, null, 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 entityActionHttpClientOptions = undefined;
750
+ if (httpOptions) {
751
+ entityActionHttpClientOptions = {
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
+ // Now we may have:
761
+ // options: containing headers, params, or any other allowed http options already in angular's api
762
+ // entityActionHttpClientOptions: headers and params in angular's api
763
+ // We therefore need to merge these so that the action ones override the
764
+ // existing keys where applicable.
765
+ // If any options have been specified, pass them to http client. Note
766
+ // the new http options, if specified, will override any options passed
767
+ // from the deprecated options parameter
768
+ let mergedOptions = undefined;
769
+ if (options || entityActionHttpClientOptions) {
770
+ if (isDevMode() && options && entityActionHttpClientOptions) {
771
+ 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.');
772
+ }
773
+ mergedOptions = {
774
+ ...options,
775
+ headers: entityActionHttpClientOptions?.headers ?? options?.headers,
776
+ params: entityActionHttpClientOptions?.params ?? options?.params,
777
+ };
778
+ }
779
+ const req = {
780
+ method,
781
+ url,
782
+ data,
783
+ options: mergedOptions,
784
+ };
748
785
  if (data instanceof Error) {
749
786
  return this.handleError(req)(data);
750
787
  }
751
788
  let result$;
752
789
  switch (method) {
753
790
  case 'DELETE': {
754
- result$ = this.http.delete(url, options);
791
+ result$ = this.http.delete(url, mergedOptions);
755
792
  if (this.saveDelay) {
756
793
  result$ = result$.pipe(delay(this.saveDelay));
757
794
  }
758
795
  break;
759
796
  }
760
797
  case 'GET': {
761
- result$ = this.http.get(url, options);
798
+ result$ = this.http.get(url, mergedOptions);
762
799
  if (this.getDelay) {
763
800
  result$ = result$.pipe(delay(this.getDelay));
764
801
  }
765
802
  break;
766
803
  }
767
804
  case 'POST': {
768
- result$ = this.http.post(url, data, options);
805
+ result$ = this.http.post(url, data, mergedOptions);
769
806
  if (this.saveDelay) {
770
807
  result$ = result$.pipe(delay(this.saveDelay));
771
808
  }
@@ -773,7 +810,7 @@ class DefaultDataService {
773
810
  }
774
811
  // N.B.: It must return an Update<T>
775
812
  case 'PUT': {
776
- result$ = this.http.put(url, data, options);
813
+ result$ = this.http.put(url, data, mergedOptions);
777
814
  if (this.saveDelay) {
778
815
  result$ = result$.pipe(delay(this.saveDelay));
779
816
  }
@@ -2069,23 +2106,23 @@ class EntityEffects {
2069
2106
  }
2070
2107
  }
2071
2108
  callDataService(action) {
2072
- const { entityName, entityOp, data } = action.payload;
2109
+ const { entityName, entityOp, data, httpOptions } = action.payload;
2073
2110
  const service = this.dataService.getService(entityName);
2074
2111
  switch (entityOp) {
2075
2112
  case EntityOp.QUERY_ALL:
2076
2113
  case EntityOp.QUERY_LOAD:
2077
- return service.getAll();
2114
+ return service.getAll(httpOptions);
2078
2115
  case EntityOp.QUERY_BY_KEY:
2079
- return service.getById(data);
2116
+ return service.getById(data, httpOptions);
2080
2117
  case EntityOp.QUERY_MANY:
2081
- return service.getWithQuery(data);
2118
+ return service.getWithQuery(data, httpOptions);
2082
2119
  case EntityOp.SAVE_ADD_ONE:
2083
- return service.add(data);
2120
+ return service.add(data, httpOptions);
2084
2121
  case EntityOp.SAVE_DELETE_ONE:
2085
- return service.delete(data);
2122
+ return service.delete(data, httpOptions);
2086
2123
  case EntityOp.SAVE_UPDATE_ONE:
2087
2124
  const { id, changes } = data; // data must be Update<T>
2088
- return service.update(data).pipe(map((updatedEntity) => {
2125
+ return service.update(data, httpOptions).pipe(map((updatedEntity) => {
2089
2126
  // Return an Update<T> with updated entity data.
2090
2127
  // If server returned entity data, merge with the changes that were sent
2091
2128
  // and set the 'changed' flag to true.
@@ -2099,7 +2136,7 @@ class EntityEffects {
2099
2136
  return responseData;
2100
2137
  }));
2101
2138
  case EntityOp.SAVE_UPSERT_ONE:
2102
- return service.upsert(data).pipe(map((upsertedEntity) => {
2139
+ return service.upsert(data, httpOptions).pipe(map((upsertedEntity) => {
2103
2140
  const hasData = upsertedEntity && Object.keys(upsertedEntity).length > 0;
2104
2141
  return hasData ? upsertedEntity : data; // ensure a returned entity value.
2105
2142
  }));
@@ -4966,4 +5003,3 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImpor
4966
5003
 
4967
5004
  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
5005
  //# sourceMappingURL=ngrx-data.mjs.map
4969
- //# sourceMappingURL=ngrx-data.mjs.map