UNPKG

2.48 kBTypeScriptView Raw
1import { LinkHints } from 'hal-types';
2export declare type Link = {
3 /**
4 * Target URI
5 */
6 href: string;
7 /**
8 * Context URI.
9 *
10 * Used to resolve relative URIs
11 */
12 context: string;
13 /**
14 * Relation type
15 */
16 rel: string;
17 /**
18 * Link title
19 */
20 title?: string;
21 /**
22 * Content type hint of the target resource
23 */
24 type?: string;
25 /**
26 * Anchor.
27 *
28 * This describes where the link is linked from, from for example
29 * a fragment in the current document
30 */
31 anchor?: string;
32 /**
33 * Language of the target resource
34 */
35 hreflang?: string;
36 /**
37 * HTML5 media attribute
38 */
39 media?: string;
40 /**
41 * If templated is set to true, the href is a templated URI.
42 */
43 templated?: boolean;
44 /**
45 * Link hints, as defined in draft-nottingham-link-hint
46 */
47 hints?: LinkHints;
48};
49declare type NewLink = Omit<Link, 'context'>;
50/**
51 * Links container, providing an easy way to manage a set of links.
52 */
53export declare class Links {
54 defaultContext: string;
55 private store;
56 constructor(defaultContext: string, links?: Link[] | Links);
57 /**
58 * Adds a link to the list
59 */
60 add(...links: (Link | NewLink)[]): void;
61 add(rel: string, href: string): void;
62 /**
63 * Set a link
64 *
65 * If a link with the provided 'rel' already existed, it will be overwritten.
66 */
67 set(link: Link | NewLink): void;
68 set(rel: string, href: string): void;
69 /**
70 * Return a single link by its 'rel'.
71 *
72 * If the link does not exist, undefined is returned.
73 */
74 get(rel: string): Link | undefined;
75 /**
76 * Delete all links with the given 'rel'.
77 */
78 delete(rel: string): void;
79 /**
80 * Return all links that have a given rel.
81 *
82 * If no links with the rel were found, an empty array is returned.
83 */
84 getMany(rel: string): Link[];
85 /**
86 * Return all links.
87 */
88 getAll(): Link[];
89 /**
90 * Returns true if at least 1 link with the given rel exists.
91 */
92 has(rel: string): boolean;
93}
94/**
95 * The LinkNotFound error gets thrown whenever something tries to follow a
96 * link by its rel, that doesn't exist
97 */
98export declare class LinkNotFound extends Error {
99}
100/**
101 * A key->value map of variables to place in a templated link
102 */
103export declare type LinkVariables = {
104 [key: string]: string | number;
105};
106export {};