Skip to content

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

Merged
merged 6 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/graph-js-sdk-core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/graph-js-sdk-web.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/src/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export declare const GRAPH_BASE_URL = "https://graph.microsoft.com/";
* @NOTE: This should be kept up to date with the version used in package.json.
* If you are changing this please ensure you are also changing it in package.json.
*/
export declare const PACKAGE_VERSION = "1.2.0";
export declare const PACKAGE_VERSION = "1.3.0";
/**
* @interface
* Signature that defines callback for an authentication provider
Expand Down
4 changes: 2 additions & 2 deletions lib/src/common.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ export declare class Client {
}
export * from "./GraphRequest";
export * from "./common";
export * from "./ResponseType";
export * from "./ResponseHandler";
export * from "./tasks/OneDriveLargeFileUploadTask";
export * from "./ResponseType";
export * from "./tasks/PageIterator";
export * from "./content/BatchRequestContent";
export * from "./content/BatchResponseContent";
5 changes: 3 additions & 2 deletions lib/src/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions lib/src/tasks/PageIterator.d.ts
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>;
}
169 changes: 169 additions & 0 deletions lib/src/tasks/PageIterator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/tasks/PageIterator.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading