UNPKG

2.03 kBTypeScriptView Raw
1import Resource from './resource';
2declare type Executor = (res: ((value: FollowablePromise) => void), rej: ((reason: any) => any)) => void;
3/**
4 * The FollowablePromise is a Promise that adds the follow and followAll
5 * functions.
6 *
7 * It's really just a thin wrapper around the promise. Note that we're not
8 * extending the built-in Promise object, but proxy it as browsers don't allow
9 * extending the Promise object.
10 */
11export default class FollowablePromise {
12 realPromise: Promise<Resource>;
13 constructor(executor: Executor);
14 /**
15 * The then function maps to a standard then function, as it appears on the
16 * promise.
17 */
18 then(onResolve: (result: any) => Resource | Promise<Resource>, onReject?: (reason: any) => never): Promise<Resource>;
19 /**
20 * The catch function maps to a standard then function, as it appears on the
21 * promise.
22 */
23 catch<T>(onReject: (reason: any) => Promise<T> | T): Promise<Resource | T>;
24 /**
25 * The follow function will wait for this promise to resolve, assume the
26 * resolved value is a Ketting resource and then call 'follow' on it.
27 *
28 * The function returns a Promise that will resolve into the result of that
29 * 'follow' function.
30 *
31 * In practice this means you can chain multiple 'follow' calls.
32 */
33 follow(rel: string, variables?: object): FollowablePromise;
34 /**
35 * The followAll function will wait for this promise to resolve, assume the
36 * resolved value is a Ketting resource and then call 'followAll' on it.
37 *
38 * The function returns a Promise that will resolve into the result of that
39 * 'followAll' function.
40 *
41 * In practice this means you can end a chain of 'follow' calls in the
42 * 'followAll' call.
43 *
44 * It's really the same idea as the follow function, except that you can't
45 * keep on chaining after the followAll, because it resolves in an array of
46 * resources.
47 */
48 followAll(rel: string): Promise<Resource[]>;
49}
50export {};