|
| 1 | +/** |
| 2 | + * @module PageIterator |
| 3 | + */ |
| 4 | +import { Client } from "../index"; |
| 5 | +/** |
| 6 | + * Signature representing PageCollection |
| 7 | + * @property {any[]} value - The collection value |
| 8 | + * @property {string} [@odata.nextLink] - The nextLine value |
| 9 | + * @property {any} Additional - Any number of additional properties (This is to accept the any additional data returned by in the response to the nextLink request) |
| 10 | + */ |
| 11 | +export interface PageCollection { |
| 12 | + value: any[]; |
| 13 | + "@odata.nextLink"?: string; |
| 14 | + "@odata.deltaLink"?: string; |
| 15 | + [Key: string]: any; |
| 16 | +} |
| 17 | +/** |
| 18 | + * Signature representing callback for page iterator |
| 19 | + * @property {Function} callback - The callback function which should return boolean to continue the continue/stop the iteration. |
| 20 | + */ |
| 21 | +export interface PageIteratorCallback { |
| 22 | + (any: any): boolean; |
| 23 | +} |
| 24 | +/** |
| 25 | + * Class for PageIterator |
| 26 | + */ |
| 27 | +export declare class PageIterator { |
| 28 | + /** |
| 29 | + * @private |
| 30 | + * Member holding the GraphClient instance |
| 31 | + */ |
| 32 | + private client; |
| 33 | + /** |
| 34 | + * @private |
| 35 | + * Member holding the page collection |
| 36 | + */ |
| 37 | + private collection; |
| 38 | + /** |
| 39 | + * @private |
| 40 | + * Member variable referring to nextLink of the page collection |
| 41 | + */ |
| 42 | + private nextLink; |
| 43 | + /** |
| 44 | + * @private |
| 45 | + * Member variable referring to deltaLink of the request |
| 46 | + */ |
| 47 | + private deltaLink; |
| 48 | + /** |
| 49 | + * @private |
| 50 | + * Holding callback for Iteration. |
| 51 | + */ |
| 52 | + private callback; |
| 53 | + /** |
| 54 | + * Creates new instance for PageIterator |
| 55 | + * @param {Client} client - The graph client instance |
| 56 | + * @param {PageCollection} pageCollection - The page collection object |
| 57 | + * @param {PageIteratorCallback} callBack - The callback function |
| 58 | + */ |
| 59 | + constructor(client: Client, pageCollection: PageCollection, callback: PageIteratorCallback); |
| 60 | + /** |
| 61 | + * @private |
| 62 | + * Iterates over a collection by enqueuing entries one by one and kicking the callback with the enqueued entry |
| 63 | + * @return A boolean indicating the continue flag to process next page |
| 64 | + */ |
| 65 | + private iterationHelper; |
| 66 | + /** |
| 67 | + * @private |
| 68 | + * @async |
| 69 | + * Helper to make a get request to fetch next page with nextLink url and update the page iterator instance with the returned response |
| 70 | + * @return A promise that resolves to a response data with next page collection |
| 71 | + */ |
| 72 | + private fetchAndUpdateNextPageData; |
| 73 | + /** |
| 74 | + * Getter to get the deltaLink in the current response |
| 75 | + * @return A deltaLink which is being used to make delta requests in future |
| 76 | + */ |
| 77 | + getDeltaLink(): string | undefined; |
| 78 | + /** |
| 79 | + * @async |
| 80 | + * Iterates over the collection and kicks callback for each item on iteration. Fetches next set of data through nextLink and iterates over again |
| 81 | + * This happens until the nextLink is drained out or the user responds with a red flag to continue from callback |
| 82 | + * @return A Promise that resolves to nothing on completion and throws error incase of any discrepancy. |
| 83 | + */ |
| 84 | + iterate(): Promise<any>; |
| 85 | + /** |
| 86 | + * @async |
| 87 | + * This internally calls the iterate method, It's just for more readability. |
| 88 | + * @return A Promise that resolves to nothing on completion and throws error incase of any discrepancy |
| 89 | + */ |
| 90 | + resume(): Promise<any>; |
| 91 | +} |
0 commit comments