import { HttpErrorResponse } from '@angular/common/http'; import { Observable } from 'rxjs'; import { BaseModelInterface } from '../../models/base/base-model.model'; import { FileUploadProcessInterface } from '../../models/file/file-upload-process.interface'; import { PaginateInterface } from '../../models/paginate/paginate.interface'; import { DataServiceAbstract } from '../data/data-service.abstract'; import { RemoteDataServiceInterface } from './remote-data-service.interface'; export declare class RemoteDataService> extends DataServiceAbstract implements RemoteDataServiceInterface { /** * Application environment variable from the root application */ private appEnv; /** * Application URL */ url: any; /** * Headers to all requests */ headers: any; /** * Options to all requests */ options: any; /** * Angular HttpClient */ private http; /** * Model's data type */ type: new () => T; constructor(model: T); /** * Set up the HTTP headers what can use every requests. */ setupHeaders(): void; /** * Send HTTP GET request to the API endpoint where can get the all items of requested resource in a PaginateInterface. * PaginateInterface is based on Laravel 6.x's pagination. * * The requested URL will be constructed like this: {environment.apiUrl}/{model.api_endpoint} * * If the ApiUrl is "http://www.yourdomain.com/api" and the API endpoint of the model is "post", then your url will be * "http://www.yourdomain.com/api/post" * * @returns Observable, PaginateInterface with initialized `T` type objects * * @example * constructor( * private myRemoteStorageService: RemoteStorageService, * ) {} * * load() { * this.myRemotStorageService.getAll().subscribe(); * } */ getAll(pageNumber?: number): Observable; /** * Send a HTTP GET request to the API endpoint to get a PaginateInterface object belongs to the model. * * The requested URL will be constructed like this: {environment.apiUrl}/{model.api_endpoint}/{uniqueUri}/{pageNumber} * * If the ApiUrl is "http://www.yourdomain.com/api" and the API endpoint of the model is "post", and you want to get the * 2nd page (and unique Uri is empty - optional) then your url will be * "http://www.yourdomain.com/api/post/?page=2" * * @param pageNumber Number of the page * @param uniqueUrl Optional parameter what'll be put into the URL * @returns Observable, PaginateInterface with initialized `T` type objects * * @example * constructor( * private myRemoteStorageService: RemoteStorageService, * ) {} * * load() { * // pageNumber: 2 * // URL: http://www.yourdomain.com/api/post/?page=2 * this.myRemotStorageService.getPage(pageNumber).subscribe(); * // or * // pageNumber: 2 * // uniqueUri: 'get-page/' * // URL: http://www.yourdomain.com/api/post/get-page/?page=2 * this.myRemotStorageService.getPage(pageNumber, 'get-page/').subscribe(); * } */ getPage(pageNumber: number, uniqueUri?: string): Observable; /** * Send HTTP GET request to the API endpoint where can get the all items of requested resource without PaginateInterface. * In Laravel 6.x you need to create a new resurce in the ResourceRegistrar. * * The requested URL will be constructed like this: {environment.apiUrl}/{model.api_endpoint}/list * * If the ApiUrl is "http://www.yourdomain.com/api" and the API endpoint of the model is "post", then your url will be * "http://www.yourdomain.com/api/post/list" * * @returns Observable, array of initialized `T` type objects * * @example * constructor( * private myRemoteStorageService: RemoteStorageService, * ) {} * * load() { * this.myRemotStorageService.getAllWithoutPaginate().subscribe(); * } */ getAllWithoutPaginate(): Observable; /** * Send HTTP GET request to the API endpoint where can get one instance of requested resource. * * The requested URL will be constructed like this: {environment.apiUrl}/{model.api_endpoint}/{id} * * If the ApiUrl is "http://www.yourdomain.com/api" and the API endpoint of the model is "post" and ID is 42, then your * url will be "http://www.yourdomain.com/api/post/42" * * @param id unique ID of instance * @returns Observable, initialized model of `T` type object * * @example * constructor( * private myRemoteStorageService: RemoteStorageService, * ) {} * * load() { * const id = 42; * this.myRemotStorageService.getOne(id).subscribe(); * } */ getOne(id: number): Observable; /** * Send HTTP GET request to the API endpoint's unique URI * * The requested URL will be constructed like this: {environment.apiUrl}/{uri} * * If the ApiUrl is "http://www.yourdomain.com/api" and the custom URI is "my/custom/uri", then your * url will be "http://www.yourdomain.com/api/my/custom/uri" * * @param uri unique URI string * @returns Observabe, any * * @example * constructor( * private myRemoteStorageService: RemoteStorageService, * ) {} * * load() { * const uri = '/filter/by/user/42'; * this.myRemotStorageService.getUri(uri).subscribe(); * } */ getUri(uri: string): Observable; /** * Send HTTP POST request to the API endpoint's unique URI * * The requested URL will be constructed like this: {environment.apiUrl}/{uri} * * If the ApiUrl is "http://www.yourdomain.com/api" and the custom URI is "my/custom/uri", then your * url will be "http://www.yourdomain.com/api/my/custom/uri" * * @param resource any data * @param uri unique URI string * @returns Observabe, any * * @example * constructor( * private myRemoteStorageService: RemoteStorageService, * ) {} * * load() { * const uri = '/filter/by/user/42'; * this.myRemotStorageService.getUri(uri).subscribe(); * } */ postUri(resource: any, uri: string): Observable; /** * Send HTTP POST or PUT request to the API endpoint to create a new instance or update an existing one. * * Create or update depends on the model has `id` field and it's `0` or not. * If it's undefined, null or `0` there will be run a create (POST request), otherwise update (PUT request). * * Before send the create or update the model will be validated on it's custom validaton rules if defined. * You can read more about validation in BaseModel section. * * If the ApiUrl is "http://www.yourdomain.com/api" and the API endpoint of the model is "post", then your * url will be "http://www.yourdomain.com/api/post" * * @param model resource any kind of JSON object, what API can handle. Of course you should give a living model. * * @returns Observabe, number or boolean, depends on backend's settings. If it's a number, then it's the ID of * the saved instance. * * @example * constructor( * private myRemoteStorageService: RemoteStorageService, * ) {} * * load() { * const myPost = new Post().init(); * this.myRemotStorageService.save(myPost).subscribe(); * } */ save(model: T): Observable; /** * Send HTTP DELETE request to the API endpoint to delete an instance. * * If the ApiUrl is "http://www.yourdomain.com/api" and the API endpoint of the model is "post" with ID 42, then your * url will be "http://www.yourdomain.com/api/post/42" * * @param model a living model, what you want to delete * * @returns Observabe, number with HTTP code of delete result * * @example * constructor( * private myRemoteStorageService: RemoteStorageService, * ) {} * * load() { * const myPost = new Post().init(); * this.myRemotStorageService.delete(myPost).subscribe(); * } */ delete(model: T): Observable; /** * Send HTTP POST request to the API endpoint to delete multiple instances * * If the ApiUrl is "http://www.yourdomain.com/api" and the API endpoint of the model is "post", then your * url will be "http://www.yourdomain.com/api/post/multiple/delete" * * The IDs what you want to delete will be send in the request body as an object with this stucture: * * `{data: [1, 2, 4, 42, 69]}` * * @param models array of models what you want to delete * * @returns Observabe, any * * @example * constructor( * private myRemoteStorageService: RemoteStorageService, * ) {} * * load() { * const posts: Post[] = [new Post().init({id: 42}), new Post.init({id: 69})]; * this.myRemotStorageService.deleteMultiple(posts).subscribe(); * } */ deleteMultiple(models: T[]): Observable<{}>; /** * You can send one or more files to the backend with this function. * * Send files with HTTP POST as form data. * * You can send files with additional datas in the `data` parameter. This is optional parameter, where you can * send addition datas. For example folder ID, file descriptions, etc. It will be stringified befor sending and * will be attached for every file. * * If the ApiUrl is "http://www.yourdomain.com/api" and the API endpoint of the model is "post" and the `uri` is * `file`, then your url will be "http://www.yourdomain.com/api/post/file" * * @param uri the uri where you want to send the file * @param files Set of JavaScript File instances * @param data optional JSON object for additional datas * * @returns Observabe array, contains FileUploadProcessInterface instances. * * @example * // send files to http://www.yourdomain.com/api/post/file URL * constructor( * private myRemoteStorageService: RemoteStorageService, * ) {} * * load() { * const files: Set; * const datas = { * folder_id: 99, * description: 'Lorem ipsum', * }; * this.myRemotStorageService.deleteMultiple('/file', files, datas).subscribe(); * } */ sendFiles(uri: string, id: number, files: Set, data?: any): Observable[]; /** * Handle errors with custom error handlers. * * @param error HTTP Error Response */ handleError: (error: HttpErrorResponse) => Observable; /** * Handle validation error feedback. * * @param err Error message * @param model Model of `T` type */ private handleValidatioErrorFeedback; } //# sourceMappingURL=remote-data.service.d.ts.map