Skip to content

Commit 0b7891c

Browse files
Page Iterator implemented
1 parent 883fdcc commit 0b7891c

File tree

13 files changed

+523
-10
lines changed

13 files changed

+523
-10
lines changed

lib/graph-js-sdk-core.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/graph-js-sdk-web.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/common.d.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/index.d.ts

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/tasks/PageIterator.d.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
[Key: string]: any;
15+
}
16+
/**
17+
* Signature representing callback for page iterator
18+
* @property {Function} callback - The callback function which should return boolean to continue the continue/stop the iteration.
19+
*/
20+
export interface PageIteratorCallback {
21+
(any: any): boolean;
22+
}
23+
/**
24+
* Class for PageIterator
25+
*/
26+
export declare class PageIterator {
27+
/**
28+
* @private
29+
* Member holding the GraphClient instance
30+
*/
31+
private client;
32+
/**
33+
* @private
34+
* Member holding the page collection
35+
*/
36+
private collection;
37+
/**
38+
* @private
39+
* Member variable referring to nextLink of the page collection
40+
*/
41+
private nextLink;
42+
/**
43+
* @private
44+
* Holding callback for Iteration.
45+
*/
46+
private callback;
47+
/**
48+
* Creates new instance for PageIterator
49+
* @param {Client} client - The graph client instance
50+
* @param {PageCollection} pageCollection - The page collection object
51+
* @param {PageIteratorCallback} callBack - The callback function
52+
*/
53+
constructor(client: Client, pageCollection: PageCollection, callback: PageIteratorCallback);
54+
/**
55+
* Iterates over a collection by enqueuing entries one by one and kicking the callback with the enqueued entry
56+
* @return A boolean indicating the continue flag to process next page
57+
*/
58+
iterationHelper(): boolean;
59+
/**
60+
* @private
61+
* @async
62+
* Helper to make a get request to fetch next page with nextLink url and update the page iterator instance with the returned response
63+
* @return A promise that resolves to a response data with next page collection
64+
*/
65+
private fetchAndUpdateNextPageData;
66+
/**
67+
* @async
68+
* Iterates over the collection and kicks callback for each item on iteration. Fetches next set of data through nextLink and iterates over again
69+
* This happens until the nextLink is drained out or the user responds with a red flag to continue from callback
70+
* @return A Promise that resolves to nothing on completion and throws error incase of any discrepancy.
71+
*/
72+
iterate(): Promise<any>;
73+
/**
74+
* @async
75+
* This internally calls the iterate method, Its juts for more readability.
76+
* @return A Promise that resolves to nothing on completion and throws error incase of any discrepancy
77+
*/
78+
resume(): Promise<any>;
79+
}

lib/src/tasks/PageIterator.js

Lines changed: 159 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/tasks/PageIterator.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)