UNPKG

4.6 kBTypeScriptView Raw
1import Resource from './resource';
2import { LinkVariables } from './link';
3/**
4 * Base interface for both FollowOne and FollowAll
5 */
6declare abstract class FollowPromise<T> implements PromiseLike<T> {
7 protected prefetchEnabled: boolean;
8 protected preferPushEnabled: boolean;
9 protected preferTranscludeEnabled: boolean;
10 protected useHeadEnabled: boolean;
11 constructor();
12 preFetch(): this;
13 preferPush(): this;
14 preferTransclude(): this;
15 /**
16 * Use a HTTP HEAD request to fetch the links.
17 *
18 * This is useful when interacting with servers that embed links in Link
19 * Headers.
20 */
21 useHead(): this;
22 abstract then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
23 abstract catch<TResult1 = T, TResult2 = never>(onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
24}
25/**
26 * The FollowPromise class is what's being returned from follow() functions.
27 *
28 * It's 'PromiseLike', which means you can treat it like a Promise, and it
29 * can be awaited. When used as a Promise, it resolves to the Resource object
30 * that was followed.
31 *
32 * In addition to being a Promise<Resource> stand-in, it also exposes other
33 * functions, namely:
34 *
35 * * `follow()` to allow a user to chain several follow() functions to do
36 * several 'hops' all at once.
37 * * `followAll()`, allowing a user to call `followAll()` at the end of a
38 * chain.
39 */
40export declare class FollowPromiseOne<T = any> extends FollowPromise<Resource<T>> {
41 private resource;
42 private rel;
43 private variables?;
44 constructor(resource: Resource | Promise<Resource>, rel: string, variables?: LinkVariables);
45 /**
46 * This 'then' function behaves like a Promise then() function.
47 *
48 * This method signature is pretty crazy, but trust that it's pretty much
49 * like any then() method on a promise.
50 */
51 then<TResult1 = Resource<T>, TResult2 = never>(onfulfilled?: ((value: Resource<T>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: Error) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
52 /**
53 * This 'catch' function behaves like a Promise catch() function.
54 */
55 catch<TResult1 = any, TResult2 = never>(onrejected?: ((reason: Error) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
56 /**
57 * Implementation of a Promise.finally function
58 */
59 finally<TResult1 = any>(onfinally: () => TResult1 | PromiseLike<TResult1>): Promise<TResult1>;
60 /**
61 * Follow another link immediately after following this link.
62 *
63 * This allows you to follow several hops of links in one go.
64 *
65 * For example: resource.follow('foo').follow('bar');
66 */
67 follow<TNested = any>(rel: string, variables?: LinkVariables): FollowPromiseOne<TNested>;
68 /**
69 * Follows a set of links immediately after following this link.
70 *
71 * For example: resource.follow('foo').followAll('item');
72 */
73 followAll<TNested = any>(rel: string): FollowPromiseMany<TNested>;
74 /**
75 * This function does the actual fetching of the linked
76 * resource.
77 */
78 private fetchLinkedResource;
79}
80/**
81 */
82export declare class FollowPromiseMany<T = any> extends FollowPromise<Resource<T>[]> {
83 private resource;
84 private rel;
85 constructor(resource: Resource | Promise<Resource>, rel: string);
86 /**
87 * This 'then' function behaves like a Promise then() function.
88 */
89 then<TResult1 = Resource<T>[], TResult2 = never>(onfulfilled?: ((value: Resource<T>[]) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: Error) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
90 /**
91 * This 'catch' function behaves like a Promise catch() function.
92 */
93 catch<TResult1 = any, TResult2 = never>(onrejected?: ((reason: Error) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
94 /**
95 * Implementation of a Promise.finally function
96 */
97 finally<TResult1 = any>(onfinally: () => TResult1 | PromiseLike<TResult1>): Promise<TResult1>;
98 /**
99 * This function does the actual fetching, to obtained the url
100 * of the linked resource. It returns the Resource object.
101 */
102 private fetchLinkedResources;
103}
104export {};