@siren-js/core
Version:
Cross-platform library of classes for generating and parsing Siren entities
58 lines (57 loc) • 2.17 kB
TypeScript
import { Action, ActionLike } from './Action';
import { EmbeddedLink } from './EmbeddedLink';
import { Link } from './Link';
import { Extendable, UnknownRecord } from './utils';
export declare type EmbeddedEntityLike<T extends UnknownRecord = UnknownRecord> = Pick<EmbeddedEntity<T>, 'class' | 'links' | 'properties' | 'rel' | 'title'> & {
actions?: ActionLike[];
entities?: (EmbeddedEntityLike | EmbeddedLink)[];
} & Extendable;
/**
* Represents a URI-addressable resource
*/
export declare class EmbeddedEntity<T extends UnknownRecord = UnknownRecord> {
/**
* Available behavior exposed by the `Entity`
*/
actions?: Action[];
/**
* List of strings describing the nature of the `Entity` based on the current representation. Possible values are
* implementation-dependent and should be documented.
*/
class?: string[];
/**
* Related entities represented as embedded links or representations
*/
entities?: (EmbeddedEntity | EmbeddedLink)[];
/**
* Navigation links that communicate ways to navigate outside the entity graph
*/
links?: Link[];
/**
* Key-value pairs describing the state of the `Entity`
*/
properties?: T;
/**
* List of strings describing the relationship of the `EmbeddedEntity` to its parent, per [RFC 8288](https://tools.ietf.org/html/rfc8288).
*/
rel: string[];
/**
* Descriptive text about the `Entity`
*/
title?: string;
[extension: string]: unknown;
/**
* Finds an `Action` in this `Entity` with the given `name`. Returns `undefined` if no `Action` exists with that
* `name`.
*/
findActionByName(name: string): Action | undefined;
/**
* Finds all sub-entities in this `Entity` with the given `rels`. Returns an empty array if no sub-entities match.
*/
findEntitiesByRel(...rels: string[]): (EmbeddedEntity | EmbeddedLink)[];
/**
* Finds all `Link`s in this `Entity` with the given `rels`. Returns an empty array if no `Link`s match.
*/
findLinksByRel(...rels: string[]): Link[];
static of(embeddedEntity: EmbeddedEntityLike): EmbeddedEntity;
}