UNPKG

@granito/ngx-hal-client

Version:

A HAL client to be used in Angular projects

64 lines (63 loc) 2.34 kB
import { Type } from '@angular/core'; import { Observable } from 'rxjs'; import { Accessor, HalBase } from './internal'; /** * This type represent parameters for templated links. */ export type Params = Record<string, string | number | boolean>; /** * This class repesents an in-memory instance of a HAL resource. */ export declare class Resource extends HalBase { /** * This property is `true` when either `methods` array does not exist * in the `self` link or the array exists and contains `PUT` string. * It is `false` otherwise. */ get canUpdate(): boolean; /** * Follow the relation link. Returns an accessor for the resource * or `undefined` if no such relation exists. * * @param rel the name of the relation link * @param params parameters for a templated link * @returns an accessor for the linked resource or `undefined` */ follow(rel: string, params?: Params): Accessor | undefined; /** * Refresh the the resource. In other words, read the resource * identified by `self` link. * * @returns an observable of the refreshed resource instance */ read(): Observable<this>; /** * Persit the resource. Uses `PUT` request to send the new resource * state. * * @returns an observable of resource accessor */ update(): Observable<Accessor>; /** * Returns a single embedded resource or `undefined` if no such * embedded exists. If the named resource is an array it returns * the first element. * * @param type the resource type * @param rel the name of the embedded resource * @returns the resource or `undefined` */ get<T extends Resource>(type: Type<T>, rel: string): T | undefined; /** * Returns an embedded array of resources or `undefined` if the named * embedded does not exist. If the named resource is not an array it * wraps the resource in an array. * * @param type the element resource type * @param rel the name of the embedded resource array * @returns the resource array or `undefined` */ getArray<T extends Resource>(type: Type<T>, rel: string): T[] | undefined; protected clone(override?: any): this; protected arrayOf<T extends Resource>(type: Type<T>, values: Object[]): T[]; }