1 | ;
|
2 | /**
|
3 | * -------------------------------------------------------------------------------------------
|
4 | * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
5 | * See License in the project root for license information.
|
6 | * -------------------------------------------------------------------------------------------
|
7 | */
|
8 | Object.defineProperty(exports, "__esModule", { value: true });
|
9 | exports.BatchResponseContent = void 0;
|
10 | var tslib_1 = require("tslib");
|
11 | /**
|
12 | * @class
|
13 | * Class that handles BatchResponseContent
|
14 | */
|
15 | var BatchResponseContent = /** @class */ (function () {
|
16 | /**
|
17 | * @public
|
18 | * @constructor
|
19 | * Creates the BatchResponseContent instance
|
20 | * @param {BatchResponseBody} response - The response body returned for batch request from server
|
21 | * @returns An instance of a BatchResponseContent
|
22 | */
|
23 | function BatchResponseContent(response) {
|
24 | this.responses = new Map();
|
25 | this.update(response);
|
26 | }
|
27 | /**
|
28 | * @private
|
29 | * Creates native Response object from the json representation of it.
|
30 | * @param {KeyValuePairObject} responseJSON - The response json value
|
31 | * @returns The Response Object instance
|
32 | */
|
33 | BatchResponseContent.prototype.createResponseObject = function (responseJSON) {
|
34 | var body = responseJSON.body;
|
35 | var options = {};
|
36 | options.status = responseJSON.status;
|
37 | if (responseJSON.statusText !== undefined) {
|
38 | options.statusText = responseJSON.statusText;
|
39 | }
|
40 | options.headers = responseJSON.headers;
|
41 | if (options.headers !== undefined && options.headers["Content-Type"] !== undefined) {
|
42 | if (options.headers["Content-Type"].split(";")[0] === "application/json") {
|
43 | var bodyString = JSON.stringify(body);
|
44 | return new Response(bodyString, options);
|
45 | }
|
46 | }
|
47 | return new Response(body, options);
|
48 | };
|
49 | /**
|
50 | * @public
|
51 | * Updates the Batch response content instance with given responses.
|
52 | * @param {BatchResponseBody} response - The response json representing batch response message
|
53 | * @returns Nothing
|
54 | */
|
55 | BatchResponseContent.prototype.update = function (response) {
|
56 | this.nextLink = response["@odata.nextLink"];
|
57 | var responses = response.responses;
|
58 | for (var i = 0, l = responses.length; i < l; i++) {
|
59 | this.responses.set(responses[i].id, this.createResponseObject(responses[i]));
|
60 | }
|
61 | };
|
62 | /**
|
63 | * @public
|
64 | * To get the response of a request for a given request id
|
65 | * @param {string} requestId - The request id value
|
66 | * @returns The Response object instance for the particular request
|
67 | */
|
68 | BatchResponseContent.prototype.getResponseById = function (requestId) {
|
69 | return this.responses.get(requestId);
|
70 | };
|
71 | /**
|
72 | * @public
|
73 | * To get all the responses of the batch request
|
74 | * @returns The Map of id and Response objects
|
75 | */
|
76 | BatchResponseContent.prototype.getResponses = function () {
|
77 | return this.responses;
|
78 | };
|
79 | /**
|
80 | * @public
|
81 | * To get the iterator for the responses
|
82 | * @returns The Iterable generator for the response objects
|
83 | */
|
84 | BatchResponseContent.prototype.getResponsesIterator = function () {
|
85 | var iterator, cur;
|
86 | return tslib_1.__generator(this, function (_a) {
|
87 | switch (_a.label) {
|
88 | case 0:
|
89 | iterator = this.responses.entries();
|
90 | cur = iterator.next();
|
91 | _a.label = 1;
|
92 | case 1:
|
93 | if (!!cur.done) return [3 /*break*/, 3];
|
94 | return [4 /*yield*/, cur.value];
|
95 | case 2:
|
96 | _a.sent();
|
97 | cur = iterator.next();
|
98 | return [3 /*break*/, 1];
|
99 | case 3: return [2 /*return*/];
|
100 | }
|
101 | });
|
102 | };
|
103 | return BatchResponseContent;
|
104 | }());
|
105 | exports.BatchResponseContent = BatchResponseContent;
|
106 | //# sourceMappingURL=BatchResponseContent.js.map |
\ | No newline at end of file |