UNPKG

@granito/ngx-hal-client

Version:

A HAL client to be used in Angular projects

126 lines (125 loc) 4.47 kB
import { Type } from '@angular/core'; import { Observable, OperatorFunction } from 'rxjs'; import { Accessor, Collection, Params, Resource } from './internal'; /** * Returns an RxJS operator that makes the source {@link Observable} * complete at the same time as the lifetime {@link Observable}. * * @param lifetime the lifetime observable * @returns a function that transforms the source {@link Observable} */ export declare function completeWith<T>(lifetime: Observable<any>): OperatorFunction<T, T>; /** * Returns an RxJS operator to follow a link on a {@link Resource}. It is * equivalent to * ```ts * map(resource => resource?.follow(rel, params)) * ``` * * @param rel the relation to follow * @param params the parameters to expand the link * @returns a function that transforms the source {@link Observable} */ export declare function follow(rel: string, params?: Params | undefined): OperatorFunction<Resource | null | undefined, Accessor | undefined>; /** * Returns an RxJS operator to create a new resource identified by * an {@link Accessor} or a {@link Resource}. It is equivalent to * ```ts * switchMap(x => of(undefined)) * ``` * if the stream value is `null` or `undefined` and to * ```ts * switchMap(x => x.create(obj)) * ``` * otherwise. * * @param obj the value for the resource * @returns a function that transforms the source {@link Observable} */ export declare function create(obj: any): OperatorFunction<Accessor | Resource | undefined, Accessor | undefined>; /** * Returns an RxJS operator to read a {@link Resource} using an * {@link Accessor}. It is equivalent to * ```ts * switchMap(accessor => of(undefined)) * ``` * if `accessor` is `null` or `undefined` and to * ```ts * switchMap(accessor => accessor.read(type)) * ``` * otherwise. * * @param type the resource type * @returns a function that transforms the source {@link Observable} */ export declare function read<T extends Resource>(type: Type<T>): OperatorFunction<Accessor | null | undefined, T | undefined>; /** * Returns an RxJS operator to read a {@link Collection} of resources * using an {@link Accessor}. It is equivalent to * ```ts * switchMap(accessor => of(undefined)) * ``` * if `accessor` is `null` or `undefined` and to * ```ts * switchMap(accessor => accessor.readCollection(type)) * ``` * otherwise. * * @param type the collection element type * @returns a function that transforms the source {@link Observable} */ export declare function readCollection<T extends Resource>(type: Type<T>): OperatorFunction<Accessor | null | undefined, Collection<T> | undefined>; /** * Returns an RxJS operator to refresh a {@link Resource} or * {@link Collection} of resources. It is equivalent to * ```ts * switchMap(resource => of(undefined)) * ``` * if `resource` is `null` or `undefined` and to * ```ts * switchMap(resource => resource.read()) * ``` * otherwise. * * @returns a function that transforms the source {@link Observable} */ export declare function refresh<T extends Resource>(): OperatorFunction<T | null | undefined, T | undefined>; /** * Returns an RxJS operator to edit and update a {@link Resource}. * It is equivalent to * ```ts * switchMap(resource => of(undefined)) * ``` * if `resource` is `null` or `undefined` and applying edit operation to * the resource and doing * ```ts * switchMap(resource => resource.update()) * ``` * otherwise. * * @param edit the operation to edit the resource * @returns a function that transforms the source {@link Observable} */ export declare function update<T extends Resource>(edit: (resource: Readonly<T>) => T): OperatorFunction<T | undefined, Accessor | undefined>; /** * Returns an RxJS operator to delete a resource identified by * an {@link Accessor} or a {@link Resource}. It is equivalent to * ```ts * switchMap(x => of(undefined)) * ``` * if the stream value is `null` or `undefined` and to * ```ts * switchMap(x => x.delete()) * ``` * otherwise. * * @returns a function that transforms the source {@link Observable} */ export declare function del(): OperatorFunction<Accessor | Resource | undefined, void>; /** * Returns an RxJS operator to filter out `null` and `undefined` items * from the source {@link Observable}. * * @returns a function that transforms the source {@link Observable} */ export declare function defined<T>(): OperatorFunction<T | null | undefined, T extends null | undefined ? never : T>;