-
Notifications
You must be signed in to change notification settings - Fork 232
Page iterator Implementation #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0b7891c
d28fe85
477f3f0
2b92c85
bceb2d9
6dc684e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* @module PageIterator | ||
*/ | ||
import { Client } from "../index"; | ||
/** | ||
* Signature representing PageCollection | ||
* @property {any[]} value - The collection value | ||
* @property {string} [@odata.nextLink] - The nextLine value | ||
* @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) | ||
*/ | ||
export interface PageCollection { | ||
value: any[]; | ||
"@odata.nextLink"?: string; | ||
"@odata.deltaLink"?: string; | ||
[Key: string]: any; | ||
} | ||
/** | ||
* Signature representing callback for page iterator | ||
* @property {Function} callback - The callback function which should return boolean to continue the continue/stop the iteration. | ||
*/ | ||
export interface PageIteratorCallback { | ||
(any: any): boolean; | ||
} | ||
/** | ||
* Class for PageIterator | ||
*/ | ||
export declare class PageIterator { | ||
/** | ||
* @private | ||
* Member holding the GraphClient instance | ||
*/ | ||
private client; | ||
/** | ||
* @private | ||
* Member holding the page collection | ||
*/ | ||
private collection; | ||
/** | ||
* @private | ||
* Member variable referring to nextLink of the page collection | ||
*/ | ||
private nextLink; | ||
/** | ||
* @private | ||
* Member variable referring to deltaLink of the request | ||
*/ | ||
private deltaLink; | ||
/** | ||
* @private | ||
* Holding callback for Iteration. | ||
*/ | ||
private callback; | ||
/** | ||
* Creates new instance for PageIterator | ||
* @param {Client} client - The graph client instance | ||
* @param {PageCollection} pageCollection - The page collection object | ||
* @param {PageIteratorCallback} callBack - The callback function | ||
*/ | ||
constructor(client: Client, pageCollection: PageCollection, callback: PageIteratorCallback); | ||
/** | ||
* @private | ||
* Iterates over a collection by enqueuing entries one by one and kicking the callback with the enqueued entry | ||
* @return A boolean indicating the continue flag to process next page | ||
*/ | ||
private iterationHelper; | ||
/** | ||
* @private | ||
* @async | ||
* Helper to make a get request to fetch next page with nextLink url and update the page iterator instance with the returned response | ||
* @return A promise that resolves to a response data with next page collection | ||
*/ | ||
private fetchAndUpdateNextPageData; | ||
/** | ||
* Getter to get the deltaLink in the current response | ||
* @return A deltaLink which is being used to make delta requests in future | ||
*/ | ||
getDeltaLink(): string | undefined; | ||
/** | ||
* @async | ||
* Iterates over the collection and kicks callback for each item on iteration. Fetches next set of data through nextLink and iterates over again | ||
* This happens until the nextLink is drained out or the user responds with a red flag to continue from callback | ||
* @return A Promise that resolves to nothing on completion and throws error incase of any discrepancy. | ||
*/ | ||
iterate(): Promise<any>; | ||
/** | ||
* @async | ||
* This internally calls the iterate method, It's just for more readability. | ||
* @return A Promise that resolves to nothing on completion and throws error incase of any discrepancy | ||
*/ | ||
resume(): Promise<any>; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.