UNPKG

@o3r/apis-manager

Version:

This module provides services to help you communicate with your APIs. Its responsibility is to provide an API configuration to a service factory so that it could instantiate an API with the right configurations. It contains a default configuration and a m

49 lines 2.3 kB
import type { Api, ApiClient, ApiName } from '@ama-sdk/core'; import { InjectionToken } from '@angular/core'; import { ApiManager } from './api-manager'; import * as i0 from "@angular/core"; /** Type of the Class of an SDK Api */ export type ApiClassType<T extends Api = Api> = (new (client: ApiClient) => T) & ApiName; /** * Initial APIs instantiations */ export declare const INITIAL_APIS_TOKEN: InjectionToken<(Api | ApiClassType<Api>)[]>; export declare class ApiFactoryService { private readonly apiManager; /** Map of loaded APIs */ private loadedApis; constructor(apiManager: ApiManager, apis?: (Api | ApiClassType)[]); /** * Determine if the given parameter is a API class * @param apiClass object to check */ private isApiClass; /** * Retrieve a specific API with loaded configuration * @param apiClass class of the API to retrieve * @param refreshCache Ignore cached API instance and refresh it * @param customApiName override the `apiName` set in the `apiClass` * @note When passing `customApiName` the configuration is expecting to exist else an error is thrown * @note When passing an Api instance that does not match a registered configuration without `customApiName`, the default one will be returned */ getApi<T extends Api>(apiClass: (new (client: ApiClient) => T) & ApiName, refreshCache?: boolean, customApiName?: string): T; /** * Update the Map of loaded APIs. * Note: Can be used to override the a specific API * @param map Map of loaded APIs to update */ updateApiMapping(map: (Api | ApiClassType)[] | Record<string, (Api | ApiClassType)>): void; /** * Clear the cache of loaded APIs * @param apis Whitelist of APIs to clear from the cache, if specified only these apis will be removed from the cache */ clearCache(apis?: (ApiName | string)[]): void; /** * Retrieve the configuration for a specific API * @param api API for which retrieving the configuration */ getConfigFor(api: string | ApiName): ApiClient; static ɵfac: i0.ɵɵFactoryDeclaration<ApiFactoryService, [null, { optional: true; }]>; static ɵprov: i0.ɵɵInjectableDeclaration<ApiFactoryService>; } //# sourceMappingURL=api-factory.service.d.ts.map