UNPKG

@dgayerie/siren

Version:

A lightweight library to easily integrate JSON Hypermedia with Siren format. https://github.com/kevinswiber/siren

140 lines (139 loc) 4.83 kB
export class SirenQuery { constructor(e: any); /** * @private */ private entity; get entities(): QueryBuilder; get links(): QueryBuilder; get entitiesAndLinks(): QueryBuilder; } export class SirenEntity { constructor(e: any, postConstructFn: any); get query(): SirenQuery; hasClass(c: any): any; get class(): any; get title(): any; get type(): any; get properties(): any; /** * For entity and embedded sub entity, returns the href from self link (if existing). * For sub entity, returns the href attribute. */ get href(): any; get rel(): any; property(name: any, defaultValue: any): any; setProperty(name: any, value: any): void; links(param: any): any; hasLink(param: any): boolean; link(param: any): any; setLink(link: any): void; setLinkHref(rel: any, href: any): void; addLink(link: any): void; hasEntity(rel: any, className: any): boolean; entities(rel: any, className: any): any; entity(rel: any, className: any): any; toJSON(): any; [entitySymbol]: any; [postConstructSymbol]: any; [subEntitiesSymbol]: any; } export default siren; declare class QueryBuilder { constructor(listOfElements: any); /** @private */ private listOfElements; /** @private */ private filters; /** * @param {...string} rel */ withRel(...rel: string[]): QueryBuilder; /** * @param {...string} classes */ withClass(...classes: string[]): QueryBuilder; /** * @param {string} type */ ofType(type: string): QueryBuilder; /** * @returns {Array} */ getAll(): any[]; /** * @returns {boolean} */ exists(): boolean; /** * @returns {Object} */ get(): any; } declare const entitySymbol: unique symbol; declare const postConstructSymbol: unique symbol; declare const subEntitiesSymbol: unique symbol; declare namespace siren { const mimeType: string; /** * Returns a siren entity repesenting the object. * * The returned object has methods to explore the entity. * If the object in parameter is already a siren entity, * this function has no effect and returns the object itself. * If the reference in parameter is null or undefined, this * function returns an empty entity (no properties, no link, no embedded entity) * @param {Object} o The object for which to create a siren entity * @param {Function} postConstructFn A post construct function * called after the entity creation (and each embedded entity creation) * @returns {SirenEntity} the siren entity */ function entity(o: any, postConstructFn: Function): SirenEntity; /** * @param {Object} o The object to check * @returns {boolean} true if the object is siren entity */ function isEntity(o: any): boolean; /** * @param {Object} l The link to check * @returns {boolean} true if the object is a link (has href and rel attributes). * An embedded link entity is a link. */ function isLink(l: any): boolean; /** * @param {Object} o The object to check * @returns {boolean} true if the object is siren sub entity (has a rel attribute). */ function isSubEntity(o: any): boolean; /** * @param {Object} o The object to check * @returns {boolean} true if the object is siren sub entity embedded link (has rel and href attributes). */ function isSubEntityEmbeddedLink(o: any): boolean; /** * @param {Object} o A link, a siren entity or a siren sub entity embedded link * @returns {Request} A request object that can be passed to the fetch function. */ function request(o: any): Request; /** * Allows to visit each link (and sub entity embedded link). * * You have the opportunity to update the links (for instance, update href to create an absolute URL). * * @param {Object} e A link, a siren entity or a siren sub entity * @param {Function} visitorFn The visitor function which will receive the link or entity as parameter * @param {boolean} includeSubEntities true if the visit should be recursive and includes the sub entities. */ function visitLinks(e: any, visitorFn: Function, includeSubEntities?: boolean): void; /** * Compares href URI to check if two entities/links are equal. * * For entities, self link is used to extract the reference URI. * For sub embedded entities and links, the href attribute is used to extract reference URI. * * @param {Object} e1 An entity or link * @param {Object} e2 An entity or link * @returns {boolean} true if these entities/links have the same URI */ function same(e1: any, e2: any): boolean; }