1 | import Resource from './resource';
|
2 | import { LinkVariables } from './types';
|
3 |
|
4 |
|
5 |
|
6 | declare abstract class Follower<T> implements PromiseLike<T> {
|
7 | protected prefetchEnabled: boolean;
|
8 | preFetch(): this;
|
9 | 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>;
|
10 | abstract catch<TResult1 = T, TResult2 = never>(onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
|
11 | }
|
12 | /**
|
13 | * The Follower class is what's being returned from follow() functions.
|
14 | *
|
15 | * It's 'PromiseLike', which means you can treat it like a Promise, and it
|
16 | * can be awaited. When used as a Promise, it resolves to the Resource object
|
17 | * that was followed.
|
18 | *
|
19 | * In addition to being a Promise<Resource> stand-in, it also exposes other
|
20 | * functions, namely:
|
21 | *
|
22 | * * `follow()` to allow a user to chain several follow() functions to do
|
23 | * several 'hops' all at once.
|
24 | * * `followAll()`, allowing a user to call `followAll()` at the end of a
|
25 | * chain.
|
26 | */
|
27 | export declare class FollowerOne<T = any> extends Follower<Resource<T>> {
|
28 | private resource;
|
29 | private rel;
|
30 | private variables?;
|
31 | constructor(resource: Resource | Promise<Resource>, rel: string, variables?: LinkVariables);
|
32 | /**
|
33 | * This 'then' function behaves like a Promise then() function.
|
34 | *
|
35 | * This method signature is pretty crazy, but trust that it's pretty much
|
36 | * like any then() method on a promise.
|
37 | */
|
38 | 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>;
|
39 | /**
|
40 | * This 'then' function behaves like a Promise then() function.
|
41 | */
|
42 | catch<TResult1 = any, TResult2 = never>(onrejected?: ((reason: Error) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
43 | /**
|
44 | * Follow another link immediately after following this link.
|
45 | *
|
46 | * This allows you to follow several hops of links in one go.
|
47 | *
|
48 | * For example: resource.follow('foo').follow('bar');
|
49 | */
|
50 | follow<TNested = any>(rel: string, variables?: LinkVariables): FollowerOne<TNested>;
|
51 | /**
|
52 | * Follows a set of links immediately after following this link.
|
53 | *
|
54 | * For example: resource.follow('foo').followAll('item');
|
55 | */
|
56 | followAll<TNested = any>(rel: string): Promise<Array<Resource<TNested>>>;
|
57 | /**
|
58 | * This function does the actual fetching, to obtained the url
|
59 | * of the linked resource. It returns the Resource object.
|
60 | */
|
61 | private fetchLinkedResource;
|
62 | }
|
63 | /**
|
64 | */
|
65 | export declare class FollowerMany<T = any> extends Follower<Array<Resource<T>>> {
|
66 | private resource;
|
67 | private rel;
|
68 | constructor(resource: Resource | Promise<Resource>, rel: string);
|
69 | /**
|
70 | * This 'then' function behaves like a Promise then() function.
|
71 | */
|
72 | then<TResult1 = Array<Resource<T>>, TResult2 = never>(onfulfilled?: ((value: Array<Resource<T>>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: Error) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
73 | /**
|
74 | * This 'then' function behaves like a Promise then() function.
|
75 | */
|
76 | catch<TResult1 = any, TResult2 = never>(onrejected?: ((reason: Error) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
77 | /**
|
78 | * This function does the actual fetching, to obtained the url
|
79 | * of the linked resource. It returns the Resource object.
|
80 | */
|
81 | private fetchLinkedResources;
|
82 | }
|
83 | export {};
|
84 |
|
\ | No newline at end of file |