UNPKG

ketting

Version:

Opiniated HATEAOS / Rest client.

71 lines (70 loc) 2.17 kB
/// <reference types="node" /> import { State } from './interface'; import { Links } from '../link'; import Client from '../client'; import { Action, ActionInfo } from '../action'; /** * The Base State provides a convenient way to implement a new State type. */ export declare abstract class BaseState<T> implements State<T> { uri: string; data: T; headers: Headers; links: Links; protected embedded: State[]; protected actionInfo: ActionInfo[]; /** * Timestamp of when the State was first generated */ timestamp: number; /** * Reference to main client that created this state */ client: Client; constructor(uri: string, data: T, headers: Headers, links: Links, embedded?: State[], actionInfo?: ActionInfo[]); /** * Content-headers are a subset of HTTP headers that related directly * to the content. The obvious ones are Content-Type. * * This set of headers will be sent by the server along with a GET * response, but will also be sent back to the server in a PUT * request. */ contentHeaders(): Headers; /** * Return an action by name. * * If no name is given, the first action is returned. This is useful for * formats that only supply 1 action, and no name. */ action<TFormData = any>(name?: string): Action<TFormData>; /** * Returns all actions */ actions(): Action[]; /** * Checks if the specified action exists. * * If no name is given, checks if _any_ action exists. */ hasAction(name?: string): boolean; /** * Returns a serialization of the state that can be used in a HTTP * response. * * For example, a JSON object might simply serialize using * JSON.serialize(). */ abstract serializeBody(): Buffer | Blob | string; /** * Certain formats can embed other resources, identified by their * own URI. * * When a format has embedded resources, we will use these to warm * the cache. * * This method returns every embedded resource. */ getEmbedded(): State[]; abstract clone(): State<T>; }