import { HttpClient } from '@angular/common/http'; import { Router } from '@angular/router'; import { Store } from '@ngrx/store'; import { Observable } from "rxjs"; import 'rxjs/add/operator/share'; export declare class ApiHttpService { private httpSvc; private storeSvc; private routerSvc; /** Hold GET requests from an API using the URL as a primary key */ protected cache: { [key: string]: Observable; }; constructor(httpSvc: HttpClient, storeSvc: Store, routerSvc: Router); /** * Make a GET request with simple caching * @param url - The URL location of the webapi * @param updateCache - Refresh the version in the cache */ get(url: string, updateCache?: boolean): Observable; /** * Make a GET request and load the results into the store * @param url - The URL location of the webapi * @param id - The location to put the results in the store * @param updateCache - Refresh the version in the cache */ protected getStore(url: string, apiMap?: IStore.ApiMap, updateCache?: boolean): Observable; /** * Make a POST request and load the results into the store * @param url - The URL location of the endpoint * @param id - The location to put the results in the store * @param data - The data to pass to the server */ protected postStore(url: string, apiMap: IStore.ApiMap, data: any): Observable; /** * Make a PUT request * @param url - The URL location of the webapi * @param data - The data to pass to the server */ protected putStore(url: string, apiMap: IStore.ApiMap, data: any): Observable; /** * Make a DELETE request * @param url - The URL location of the webapi * @param apiMap - The ApiMap object * @param element - The element or collection of elements being deleted */ protected deleteStore(url: string, apiMap: IStore.ApiMap, element: any | any[]): Observable; /** * When an authentication check fails * @param error */ private endSession(error); } export declare namespace IStore { /************************* * App specific interfaces *************************/ /** API Store */ interface api { users?: Mapped<{ user: string; email: string; name: string; phone: string; username: string; website: string; }>; } /** The API Map */ interface ApiMapping { users?: ApiMap; } /** UI Store */ interface ui { modal?: { modalId: string; options: {}; data: any; }; } /************************* * Non-customizable interfaces *************************/ /** The root store which contains the other stores */ interface root { api?: api; ui?: ui; apiStatus?: apiStatus; } /** API status store */ interface apiStatus { [key: string]: ApiStatus; } /** Example pattern for data that is mapped before being passed into the store */ interface Mapped { /** Unaltered source of API response */ src?: T[]; /** A dictionary organized by the primary key */ dict?: { [key: string]: T; }; /** A deduped array arranged into a dictionary by primary key */ uniques?: { [key: string]: T; }; } interface StateStatuses { users?: ApiStatus; } interface ApiStatus { loading?: boolean; loaded?: boolean; loadError?: any; modifying?: boolean; modified?: boolean; modifyError?: any; } /** Maps the relationship between the store and the API. Automates all the interaction. */ interface ApiMap { /** The location of the rest API endpoint */ endpoint?: string; /** The location/property of where to put the API response into the store */ storeProperty?: string; /** A unique ID of each object in the collection. Also supports an array of strings if multiple unique ID's are needed in the event of a single key not being enough. */ uniqueId?: string | string[]; /** A callback function to modify the API response before it is inserted into the store */ map?: any; /** If a map callback function is specified, this is the key for the location of the original unfiltered list of items. This is necessary to update the mapped list in the store without a GET all */ mapSrc?: string; /** Occasionally a unique piece of information needs to be passed to the reducer from the method. This property can have data assigned to pass to the reducer */ data?: any; } interface Rest { storeProp: string; path: string; } }