UNPKG

@siren-js/core

Version:

Cross-platform library of classes for generating and parsing Siren entities

55 lines (54 loc) 2.05 kB
import { Action, ActionLike } from './Action'; import { EmbeddedEntity, EmbeddedEntityLike } from './EmbeddedEntity'; import { EmbeddedLink } from './EmbeddedLink'; import { Link } from './Link'; import { Extendable, UnknownRecord } from './utils'; export declare type EntityLike<T extends UnknownRecord = UnknownRecord> = Pick<Entity<T>, 'class' | 'links' | 'properties' | 'title'> & { actions?: ActionLike[]; entities?: (EmbeddedEntityLike | EmbeddedLink)[]; } & Extendable; /** * Represents a URI-addressable resource */ export declare class Entity<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; /** * 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<T extends UnknownRecord = UnknownRecord>(entity: EntityLike): Entity<T>; }