@microsoft/msgraph-sdk-core
Version:
Core functionalities for the Microsoft Graph JavaScript SDK
76 lines • 3.12 kB
JavaScript
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/**
* Represents a collection of BatchResponseContent.
*/
export class BatchResponseContentCollection {
/**
* Initializes a new instance of the BatchResponseContentCollection class.
* @param responseContents - An array of BatchResponseContent.
*/
constructor(responseContents) {
/**
* An array of BatchResponseContent.
*/
this.batchResponseContent = [];
this.batchResponseContent = responseContents;
}
/**
* Finds the BatchResponseContent containing the specified request ID.
* @param requestId - The ID of the request.
* @returns The BatchResponseContent containing the request ID, or undefined if not found.
*/
getBatchContentContaining(requestId) {
return this.batchResponseContent.find(batchResponseContent => {
return batchResponseContent.getResponseById(requestId) !== undefined;
});
}
/**
* Gets the BatchResponse by the specified request ID.
* @param requestId - The ID of the request.
* @returns The BatchResponse with the specified request ID, or undefined if not found.
*/
getResponseById(requestId) {
const batchResponseContent = this.getBatchContentContaining(requestId);
if (batchResponseContent) {
return batchResponseContent.getResponseById(requestId);
}
return undefined;
}
/**
* Gets the parsable response by the specified request ID.
* @param requestId - The ID of the request.
* @param parseNodeFactoryRegistry - The registry to create parse nodes.
* @param factory - The factory to create the Parsable instance.
* @returns The parsable response, or undefined if not found.
*/
getParsableResponseById(requestId, parseNodeFactoryRegistry, factory) {
const res = this.getResponseById(requestId);
if (res === null || res === void 0 ? void 0 : res.body) {
const result = parseNodeFactoryRegistry.deserializeFromJson(res.body, factory);
return result;
}
return undefined;
}
/**
* Gets the status codes of all responses.
* @returns A promise that resolves to a map of request IDs to status codes.
*/
async getResponsesStatusCodes() {
const statusCodesArray = await Promise.all(this.batchResponseContent.map(batchResponseContent => {
return batchResponseContent.getResponsesStatusCodes();
}));
const mergedStatusCodes = new Map();
statusCodesArray.forEach(map => {
map.forEach((value, key) => {
mergedStatusCodes.set(key, value);
});
});
return mergedStatusCodes;
}
}
//# sourceMappingURL=BatchResponseContentCollection.js.map