Skip to content

Commit ca5e846

Browse files
Merge pull request #118 from microsoftgraph/PageIterator
Page iterator Implementation
2 parents ad4ec0e + 6dc684e commit ca5e846

13 files changed

+555
-10
lines changed

lib/graph-js-sdk-core.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/graph-js-sdk-web.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/common.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export declare const GRAPH_BASE_URL = "https://graph.microsoft.com/";
77
* @NOTE: This should be kept up to date with the version used in package.json.
88
* If you are changing this please ensure you are also changing it in package.json.
99
*/
10-
export declare const PACKAGE_VERSION = "1.2.0";
10+
export declare const PACKAGE_VERSION = "1.3.0";
1111
/**
1212
* @interface
1313
* Signature that defines callback for an authentication provider

lib/src/common.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/index.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ export declare class Client {
77
}
88
export * from "./GraphRequest";
99
export * from "./common";
10+
export * from "./ResponseType";
1011
export * from "./ResponseHandler";
1112
export * from "./tasks/OneDriveLargeFileUploadTask";
12-
export * from "./ResponseType";
13+
export * from "./tasks/PageIterator";
1314
export * from "./content/BatchRequestContent";
1415
export * from "./content/BatchResponseContent";

lib/src/index.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/tasks/PageIterator.d.ts

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
}

lib/src/tasks/PageIterator.js

+169
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/tasks/PageIterator.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)