UNPKG

5.06 kBTypeScriptView Raw
1/**
2 * -------------------------------------------------------------------------------------------
3 * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
4 * See License in the project root for license information.
5 * -------------------------------------------------------------------------------------------
6 */
7/**
8 * @module PageIterator
9 */
10import { FetchOptions } from "../IFetchOptions";
11import { Client } from "../index";
12import { MiddlewareOptions } from "../middleware/options/IMiddlewareOptions";
13/**
14 * Signature representing PageCollection
15 * @property {any[]} value - The collection value
16 * @property {string} [@odata.nextLink] - The nextLink value
17 * @property {string} [@odata.deltaLink] - The deltaLink value
18 * @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)
19 */
20export interface PageCollection {
21 value: any[];
22 "@odata.nextLink"?: string;
23 "@odata.deltaLink"?: string;
24 [Key: string]: any;
25}
26/**
27 * Signature to define the request options to be sent during request.
28 * The values of the GraphRequestOptions properties are passed to the Graph Request object.
29 * @property {HeadersInit} headers - the header options for the request
30 * @property {MiddlewareOptions[]} middlewareoptions - The middleware options for the request
31 * @property {FetchOptions} options - The fetch options for the request
32 */
33export interface GraphRequestOptions {
34 headers?: HeadersInit;
35 middlewareOptions?: MiddlewareOptions[];
36 options?: FetchOptions;
37}
38/**
39 * Signature representing callback for page iterator
40 * @property {Function} callback - The callback function which should return boolean to continue the continue/stop the iteration.
41 */
42export type PageIteratorCallback = (data: any) => boolean;
43/**
44 * @class
45 * Class for PageIterator
46 */
47export declare class PageIterator {
48 /**
49 * @private
50 * Member holding the GraphClient instance
51 */
52 private client;
53 /**
54 * @private
55 * Member holding the page collection
56 */
57 private collection;
58 /**
59 * @private
60 * Member variable referring to nextLink of the page collection
61 */
62 private nextLink;
63 /**
64 * @private
65 * Member variable referring to deltaLink of the request
66 */
67 private deltaLink;
68 /**
69 * @private
70 * Holding callback for Iteration.
71 */
72 private callback;
73 /**
74 * @private
75 * Member holding a complete/incomplete status of an iterator
76 */
77 private complete;
78 /**
79 * @private
80 * Information to be added to the request
81 */
82 private requestOptions;
83 /**
84 * @private
85 * Member holding the current position on the collection
86 */
87 private cursor;
88 /**
89 * @public
90 * @constructor
91 * Creates new instance for PageIterator
92 * @param {Client} client - The graph client instance
93 * @param {PageCollection} pageCollection - The page collection object
94 * @param {PageIteratorCallback} callBack - The callback function
95 * @param {GraphRequestOptions} requestOptions - The request options
96 * @returns An instance of a PageIterator
97 */
98 constructor(client: Client, pageCollection: PageCollection, callback: PageIteratorCallback, requestOptions?: GraphRequestOptions);
99 /**
100 * @private
101 * Iterates over a collection by enqueuing entries one by one and kicking the callback with the enqueued entry
102 * @returns A boolean indicating the continue flag to process next page
103 */
104 private iterationHelper;
105 /**
106 * @private
107 * @async
108 * Helper to make a get request to fetch next page with nextLink url and update the page iterator instance with the returned response
109 * @returns A promise that resolves to a response data with next page collection
110 */
111 private fetchAndUpdateNextPageData;
112 /**
113 * @public
114 * Getter to get the deltaLink in the current response
115 * @returns A deltaLink which is being used to make delta requests in future
116 */
117 getDeltaLink(): string | undefined;
118 /**
119 * @public
120 * @async
121 * Iterates over the collection and kicks callback for each item on iteration. Fetches next set of data through nextLink and iterates over again
122 * This happens until the nextLink is drained out or the user responds with a red flag to continue from callback
123 * @returns A Promise that resolves to nothing on completion and throws error incase of any discrepancy.
124 */
125 iterate(): Promise<any>;
126 /**
127 * @public
128 * @async
129 * To resume the iteration
130 * Note: This internally calls the iterate method, It's just for more readability.
131 * @returns A Promise that resolves to nothing on completion and throws error incase of any discrepancy
132 */
133 resume(): Promise<any>;
134 /**
135 * @public
136 * To get the completeness status of the iterator
137 * @returns Boolean indicating the completeness
138 */
139 isComplete(): boolean;
140}