UNPKG

siren-types

Version:

A bunch of Siren types defined in TypeScript plus some useful functions

44 lines (43 loc) 2.04 kB
import { Entity, Link, Action, EmbeddedLinkSubEntity, Properties, EmbeddedRepresentationSubEntity, SubEntity } from "./types"; /** * A slight variation on the Siren type where everything is now required. Title * is a special case because I didn't want to use `""` as the default value so I * allow null in that case. For everything else, empty objects and arrays suffice. */ export interface NormalizedEntity<P extends Properties | undefined = undefined> { class: string[]; title: string | null; properties: P; entities: NormalizedSubEntity[]; actions: NormalizedAction[]; links: Link[]; } /** * This function normalizes an existing Siren Entity. * * Note this doesn't normalize properties because we cannot know how to * normalize them. So we just hope they are what we expect. */ export declare function normalize<P extends Properties | undefined = undefined>(e: Entity<P>, defaultProps: P): NormalizedEntity<P>; export declare function normalizeEmbeddedLinkSubEntity(e: EmbeddedLinkSubEntity): NormalizedEmbeddedLinkSubEntity; export declare function normalizeEmbeddedRepresentationSubEntity<P extends Properties | undefined>(e: EmbeddedRepresentationSubEntity<P>): NormalizedEmbeddedRepresentationSubEntity<P>; export declare function normalizeEmbedded<P extends Properties | undefined>(e: SubEntity<P>): NormalizedSubEntity<P>; /** * Normalized forms of the subentity types */ export declare type NormalizedSubEntity<P extends Properties | undefined = undefined> = NormalizedEmbeddedLinkSubEntity | NormalizedEmbeddedRepresentationSubEntity<P>; export interface NormalizedEmbeddedLinkSubEntity { class: string[]; rel: string[]; href: string; type: string; title: string | null; } /** * Normalized version of an embedded representation */ export interface NormalizedEmbeddedRepresentationSubEntity<P> extends NormalizedEntity<P> { rel: string[]; } export declare type NormalizedAction = Required<Action>; export declare function normalizeAction(a: Action): NormalizedAction;