ketting
Version:
Opiniated HATEAOS / Rest client.
84 lines (83 loc) • 1.82 kB
TypeScript
import { State } from './state';
import Client from './client';
import { Field } from './field';
export interface ActionInfo {
/**
* What url to post the form to.
*/
uri: string;
/**
* Action name.
*
* Some formats call this the 'rel'
*/
name: string | null;
/**
* Form title.
*
* Should be human-friendly.
*/
title?: string;
/**
* The HTTP method to use
*/
method: string;
/**
* The contentType to use for the form submission
*/
contentType: string;
/**
* Returns the list of fields associated to an action
*/
fields: Field[];
}
/**
* An action represents a hypermedia form submission or action.
*/
export interface Action<T extends Record<string, any> = Record<string, any>> extends ActionInfo {
/**
* Execute the action or submit the form.
*/
submit(formData: T): Promise<State>;
}
export declare class SimpleAction<TFormData> implements Action {
/**
* What url to post the form to.
*/
uri: string;
/**
* Action name.
*
* Some formats call this the 'rel'
*/
name: string | null;
/**
* Form title.
*
* Should be human-friendly.
*/
title: string;
/**
* The HTTP method to use
*/
method: string;
/**
* The contentType to use for the form submission
*/
contentType: string;
/**
* Returns the list of fields associated to an action
*/
fields: Field[];
/**
* Reference to client
*/
client: Client;
constructor(client: Client, formInfo: ActionInfo);
/**
* Execute the action or submit the form.
*/
submit(formData: TFormData): Promise<State<any>>;
}
export declare class ActionNotFound extends Error {
}