@granito/ngx-hal-client
Version:
A HAL client to be used in Angular projects
67 lines (66 loc) • 2.43 kB
TypeScript
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Type } from '@angular/core';
import { Observable } from 'rxjs';
import { Accessor } from './internal';
interface Link {
href: string;
templated?: boolean;
methods?: string[];
}
/**
* The common base for resource and accessor.
*/
export declare abstract class HalBase {
protected readonly _client: HttpClient;
protected readonly _links: Readonly<Record<string, Link>>;
protected readonly _embedded: Readonly<Record<string, Object>>;
/**
* The URI of `self` link.
*/
get self(): string;
/**
* This property is `true` when either `methods` array does not exist
* in the `self` link or the array exists and contains `POST` string.
* It is `false` otherwise.
*/
get canCreate(): boolean;
/**
* This property is `true` when either `methods` array does not exist
* in the `self` link or the array exists and contains `GET` string.
* It is `false` otherwise.
*/
get canRead(): boolean;
/**
* This property is `true` when either `methods` array does not exist
* in the `self` link or the array exists and contains `DELETE`
* string. It is `false` otherwise.
*/
get canDelete(): boolean;
/**
* @param obj the object used to assign the properties
*/
constructor(obj: Object);
/**
* Create a new resource in the collection identified by `self` link.
* It makes a `POST` call to the URI in `self` link and returns an
* observable for the call. The observable normally emits an accessor
* for the newly created resource or `undefined` if `Location` header
* was not returned by the call.
*
* @param obj the payload for the `POST` method call
* @returns an observable of the resource's accessor
*/
create(obj: any): Observable<Accessor | undefined>;
/**
* Delete the resource identified by `self` link.
*
* @returns an observable that emits next signal on successful delete
*/
delete(): Observable<void>;
protected withSelf<T>(func: (uri: string) => Observable<T>): Observable<T>;
protected accessor(href: string, methods?: string[]): Accessor;
protected instanceOf<T>(type: Type<T>, obj: Object): T;
protected handleError(err: HttpErrorResponse): Observable<never>;
protected can(method: string): boolean;
}
export {};