@microsoft/msgraph-sdk-core
Version:
Core functionalities for the Microsoft Graph JavaScript SDK
157 lines • 6.01 kB
TypeScript
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/**
* @module PageIterator
*/
import { Parsable, RequestAdapter, RequestOption, ParsableFactory, ErrorMappings, Headers } from "@microsoft/kiota-abstractions";
/**
* Signature representing PageCollection
* @property {any[]} value - The collection value
* @property {string} [@odata.nextLink] - The nextLink value
* @property {string} [@odata.deltaLink] - The deltaLink 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<T> {
value: T[];
odataNextLink?: string;
odataDeltaLink?: 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 type PageIteratorCallback<T> = (data: T) => boolean;
/**
* Signature to define the request options to be sent during request.
* The values of the GraphRequestOptions properties are passed to the Graph Request object.
* @property {Headers} headers - the header options for the request
* @property {RequestOption[]} options - The middleware options for the request
*/
export interface PagingRequestOptions {
headers?: Headers;
requestOption?: RequestOption[];
}
/**
* @typedef {string} PagingState
* Type representing the state of the iterator
*/
export type PagingState = "NotStarted" | "Paused" | "IntrapageIteration" | "InterpageIteration" | "Delta" | "Complete";
/**
* Class representing a PageIterator to iterate over paginated collections.
* @template T - The type of the items in the collection.
*
* This class provides methods to iterate over a collection of items that are paginated.
* It handles fetching the next set of items when the current page is exhausted.
* The iteration can be paused and resumed, and the state of the iterator can be queried.
*
* The PageIterator uses a callback function to process each item in the collection.
* The callback function should return a boolean indicating whether to continue the iteration.
*
* The PageIterator also supports error handling through error mappings and can be configured
* with custom request options.
*/
export declare class PageIterator<T extends Parsable> {
/**
* @private
* Member holding the GraphClient instance
*/
private readonly requestAdapter;
/**
* @private
* Member holding the current page
*/
private currentPage?;
/**
* @private
* Member holding the current position on the collection
*/
private cursor;
/**
* @private
* Member holding the factory to create the parsable object
*/
private readonly parsableFactory;
/**
* @private
* Member holding the error mappings
*/
private readonly errorMappings;
/**
* @private
* Member holding the callback for iteration
*/
private readonly callback;
/**
* @private
* Member holding the state of the iterator
*/
private pagingState;
/**
* @private
* Member holding the headers for the request
*/
private readonly options?;
/**
* @public
* @constructor
* Creates new instance for PageIterator
* @returns An instance of a PageIterator
* @param requestAdapter - The request adapter
* @param pageResult - The page collection result of T
* @param callback - The callback function to be called on each item
* @param errorMappings - The error mappings
* @param parsableFactory - The factory to create the parsable object collection
* @param options - The request options to configure the request
*/
constructor(requestAdapter: RequestAdapter, pageResult: PageCollection<T>, callback: PageIteratorCallback<T>, parsableFactory: ParsableFactory<PageCollection<T>>, errorMappings: ErrorMappings, options?: PagingRequestOptions);
/**
* @public
* Getter to get the deltaLink in the current response
* @returns A deltaLink which is being used to make delta requests in future
*/
getOdataDeltaLink(): string | undefined;
/**
* @public
* Getter to get the nextLink in the current response
* @returns A nextLink which is being used to make requests in future
*/
getOdataNextLink(): string | undefined;
/**
* @public
* @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
*/
iterate(): Promise<void>;
/**
* @public
* Getter to get the state of the iterator
*/
getPagingState(): PagingState;
/**
* @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
* @returns A promise that resolves to a response data with next page collection
*/
private fetchNextPage;
/**
* @public
* @async
* To resume the iteration
* Note: This internally calls the iterate method, It's just for more readability.
*/
resume(): Promise<void>;
/**
* @private
* Iterates over a collection by enqueuing entries one by one and kicking the callback with the enqueued entry
* @returns A boolean indicating the continue flag to process next page
*/
private enumeratePage;
}
//# sourceMappingURL=PageIterator.d.ts.map