@siren-js/core
Version:
Cross-platform library of classes for generating and parsing Siren entities
50 lines (49 loc) • 1.68 kB
TypeScript
import { Field } from './Field';
import { Extendable } from './utils';
export declare type ActionLike = Pick<Action, 'class' | 'fields' | 'href' | 'method' | 'name' | 'title' | 'type'> & Extendable;
/**
* Represents available behavior exposed by an `Entity`.
*/
export declare class Action {
/**
* List of strings describing the nature of the `Action` based on the current representation. Possible values are
* implementation-dependent and should be documented.
*/
class?: string[];
/**
* Input controls of the `Action`.
*/
fields?: Field[];
/**
* URI of the action
*/
href: string;
/**
* Protocol method used when submitting the `Action`. When missing, the default is assumed to be `'GET'`.
*/
method?: string;
/**
* Name identifying the action to be performed. Must be unique within an `Entity`'s `actions`.
*/
name: string;
/**
* Descriptive text about the `Action`.
*/
title?: string;
/**
* Encoding type indicating how `fields` are serialized when submitting the `Action`. When missing, the default is
* assumed to be `'application/x-www-form-urlencoded'`.
*/
type?: string;
[extension: string]: unknown;
/**
* Finds all `Field`s in this `Action` with the given `name`. Returns `undefined` if no `Field` exists with that
* `name`.
*/
findFieldByName(name: string): Field | undefined;
/**
* Finds all `Field`s in this `Action` with the given `classes`. Returns an empty array if no `Field`s match.
*/
findFieldsByClass(...classes: string[]): Field[];
static of(action: ActionLike): Action;
}