@c8y/ngx-components
Version:
Angular modules for Cumulocity IoT applications
70 lines • 3.31 kB
TypeScript
import { FetchClient } from '@c8y/client';
import { MonoTypeOperatorFunction, Observable } from 'rxjs';
import { ApiCall } from './api.model';
import { RequestStartAndFinish } from './http-handler.model';
import { HttpInterceptor } from './interceptor.model';
import * as i0 from "@angular/core";
export declare class ApiService implements RequestStartAndFinish {
private client;
calls: Observable<ApiCall>;
isLoading$: Observable<boolean>;
private callsSubject;
private interceptors;
private interceptorCounter;
constructor(client: FetchClient);
/**
* Allows to hook into the responses received by the FetchClient.
* This is meant to be used to react on the responses, not for manipulation of the responses.
* @param hookFilter A filter function to filter for specific responses.
* @returns An Observable of the filtered responses.
*/
hookResponse(hookFilter: (call: ApiCall) => boolean): Observable<ApiCall>;
/**
* Allows to hook into the requests performed by the FetchClient.
* This is meant to be used to react on the requests, not for manipulation of the requests.
* @param hookFilter A filter function to filter for specific requests.
* @returns An Observable of the filtered requests.
*/
hookRequest(hookFilter: (call: ApiCall) => boolean): Observable<ApiCall>;
onFinish(call: ApiCall): void;
onStart(call: ApiCall): void;
/**
* Resolves data from an API call response.
* @returns A Promise containing an object with resolved data, method, and URL.
*/
resolveData<T = unknown>(call: ApiCall): Promise<{
data: T;
method: string;
url: string;
}>;
/**
* Can be added to a pipe to exclude any permission call. Permission calls are PUT
* request with only an id in it, to verify if the user has access to this managed object.
* @returns The operator to be added to a pipe.
*/
excludePermissionCall(): MonoTypeOperatorFunction<ApiCall>;
/**
* Allows to intercept requests performed via the FetchClient requests.
* @param interceptor The interceptor to be added.
* @param id An optional unique identifier for the interceptor. The chain of interceptors is ordered by this id. And it can be used to remove the interceptor later on.
* @returns The id of the interceptor (same as provided id if one was provided, otherwise an id will be generated).
*/
addInterceptor(interceptor: HttpInterceptor, id?: string): string;
/**
* Allows to remove a previously added interceptor by it's id.
* @param id The id of the interceptor that should be removed.
* @returns true if an interceptor existed and has been removed, or false if id does not exist.
*/
removeInterceptor(id: string): boolean;
/**
* Checks if an interceptor with a given id exists.
* @param id The id of the interceptor.
* @returns - Returns true if an interceptor with the given id exists, otherwise false.
*/
hasInterceptor(id: string): boolean;
private hookIntoClientFetch;
private createInterceptorChain;
static ɵfac: i0.ɵɵFactoryDeclaration<ApiService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<ApiService>;
}
//# sourceMappingURL=api.service.d.ts.map