apply cache changes to root dataservice

This commit is contained in:
Art Lowel
2021-02-05 17:56:59 +01:00
parent 1e94e7a5a9
commit 8c0459241f
2 changed files with 28 additions and 21 deletions

View File

@@ -30,7 +30,7 @@ describe('RootDataService', () => {
it('should call findByHref using the root endpoint', (done) => { it('should call findByHref using the root endpoint', (done) => {
result$.subscribe(() => { result$.subscribe(() => {
expect((service as any).dataService.findByHref).toHaveBeenCalledWith(rootEndpoint, true); expect((service as any).dataService.findByHref).toHaveBeenCalledWith(rootEndpoint, true, true);
done(); done();
}); });
}); });

View File

@@ -65,39 +65,46 @@ export class RootDataService {
/** /**
* Find the {@link Root} object of the REST API * Find the {@link Root} object of the REST API
* @param reRequestOnStale Whether or not the request should automatically be re-requested after * @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* the response becomes stale * no valid cached version. Defaults to true
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved * @param reRequestOnStale Whether or not the request should automatically be re-
* requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
*/ */
findRoot(reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Root>[]): Observable<RemoteData<Root>> { findRoot(useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Root>[]): Observable<RemoteData<Root>> {
return this.dataService.findByHref(this.halService.getRootHref(), reRequestOnStale, ...linksToFollow); return this.dataService.findByHref(this.halService.getRootHref(), useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }
/** /**
* Returns an observable of {@link RemoteData} of an object, based on an href, with a list of * Returns an observable of {@link RemoteData} of an object, based on an href, with a list of
* {@link FollowLinkConfig}, to automatically resolve {@link HALLink}s of the object * {@link FollowLinkConfig}, to automatically resolve {@link HALLink}s of the object
* @param href The url of object we want to retrieve * @param href The url of object we want to retrieve
* @param reRequestOnStale Whether or not the request should automatically be re-requested after * @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* the response becomes stale * no valid cached version. Defaults to true
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s * @param reRequestOnStale Whether or not the request should automatically be re-
* should be automatically resolved * requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
*/ */
findByHref(href: string, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Root>[]): Observable<RemoteData<Root>> { findByHref(href: string | Observable<string>, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Root>[]): Observable<RemoteData<Root>> {
return this.dataService.findByHref(href, reRequestOnStale, ...linksToFollow); return this.dataService.findByHref(href, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }
/** /**
* Returns a list of observables of {@link RemoteData} of objects, based on an href, with a list * Returns a list of observables of {@link RemoteData} of objects, based on an href, with a list
* of {@link FollowLinkConfig}, to automatically resolve {@link HALLink}s of the object * of {@link FollowLinkConfig}, to automatically resolve {@link HALLink}s of the object
* @param href The url of object we want to retrieve * @param href The url of object we want to retrieve
* @param findListOptions Find list options object * @param findListOptions Find list options object
* @param reRequestOnStale Whether or not the request should automatically be re-requested after * @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
* the response becomes stale * no valid cached version. Defaults to true
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s * @param reRequestOnStale Whether or not the request should automatically be re-
* should be automatically resolved * requested after the response becomes stale
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
* {@link HALLink}s should be automatically resolved
*/ */
findAllByHref(href: string, findListOptions: FindListOptions = {}, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Root>[]): Observable<RemoteData<PaginatedList<Root>>> { findAllByHref(href: string | Observable<string>, findListOptions: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Root>[]): Observable<RemoteData<PaginatedList<Root>>> {
return this.dataService.findAllByHref(href, findListOptions, reRequestOnStale, ...linksToFollow); return this.dataService.findAllByHref(href, findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
} }
} }
/* tslint:enable:max-classes-per-file */ /* tslint:enable:max-classes-per-file */