UNPKG

5.08 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 declare 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 * Information to be added to the request
80 */
81 private requestOptions;
82 /**
83 * @public
84 * @constructor
85 * Creates new instance for PageIterator
86 * @param {Client} client - The graph client instance
87 * @param {PageCollection} pageCollection - The page collection object
88 * @param {PageIteratorCallback} callBack - The callback function
89 * @param {GraphRequestOptions} requestOptions - The request options
90 * @returns An instance of a PageIterator
91 */
92 constructor(client: Client, pageCollection: PageCollection, callback: PageIteratorCallback, requestOptions?: GraphRequestOptions);
93 /**
94 * @private
95 * Iterates over a collection by enqueuing entries one by one and kicking the callback with the enqueued entry
96 * @returns A boolean indicating the continue flag to process next page
97 */
98 private iterationHelper;
99 /**
100 * @private
101 * @async
102 * Helper to make a get request to fetch next page with nextLink url and update the page iterator instance with the returned response
103 * @returns A promise that resolves to a response data with next page collection
104 */
105 private fetchAndUpdateNextPageData;
106 /**
107 * @public
108 * Getter to get the deltaLink in the current response
109 * @returns A deltaLink which is being used to make delta requests in future
110 */
111 getDeltaLink(): string | undefined;
112 /**
113 * @public
114 * @async
115 * Iterates over the collection and kicks callback for each item on iteration. Fetches next set of data through nextLink and iterates over again
116 * This happens until the nextLink is drained out or the user responds with a red flag to continue from callback
117 * @returns A Promise that resolves to nothing on completion and throws error incase of any discrepancy.
118 */
119 iterate(): Promise<any>;
120 /**
121 * @public
122 * @async
123 * To resume the iteration
124 * Note: This internally calls the iterate method, It's just for more readability.
125 * @returns A Promise that resolves to nothing on completion and throws error incase of any discrepancy
126 */
127 resume(): Promise<any>;
128 /**
129 * @public
130 * To get the completeness status of the iterator
131 * @returns Boolean indicating the completeness
132 */
133 isComplete(): boolean;
134}