UNPKG

5.7 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 * @interface
9 * Signature representing BatchRequestStep data
10 * @property {string} id - Unique identity for the request, Should not be an empty string
11 * @property {string[]} [dependsOn] - Array of dependencies
12 * @property {Request} request - The Request object
13 */
14export interface BatchRequestStep {
15 id: string;
16 dependsOn?: string[];
17 request: Request;
18}
19/**
20 * @interface
21 * Signature representing single request in a Batching
22 * @extends RequestInit
23 * @see {@link https://github.com/Microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L1337} and {@link https://fetch.spec.whatwg.org/#requestinit}
24 *
25 * @property {string} url - The url value of the request
26 */
27export interface RequestData extends RequestInit {
28 url: string;
29}
30/**
31 * @interface
32 * Signature representing batch request data
33 * @property {string} id - Unique identity for the request, Should not be an empty string
34 * @property {string[]} [dependsOn] - Array of dependencies
35 */
36export interface BatchRequestData extends RequestData {
37 id: string;
38 dependsOn?: string[];
39}
40/**
41 * @interface
42 * Signature representing batch request body
43 * @property {BatchRequestData[]} requests - Array of request data, a json representation of requests for batch
44 */
45export interface BatchRequestBody {
46 requests: BatchRequestData[];
47}
48/**
49 * @class
50 * Class for handling BatchRequestContent
51 */
52export declare class BatchRequestContent {
53 /**
54 * @private
55 * @static
56 * Limit for number of requests {@link - https://developer.microsoft.com/en-us/graph/docs/concepts/known_issues#json-batching}
57 */
58 private static requestLimit;
59 /**
60 * @public
61 * To keep track of requests, key will be id of the request and value will be the request json
62 */
63 requests: Map<string, BatchRequestStep>;
64 /**
65 * @private
66 * @static
67 * Validates the dependency chain of the requests
68 *
69 * Note:
70 * Individual requests can depend on other individual requests. Currently, requests can only depend on a single other request, and must follow one of these three patterns:
71 * 1. Parallel - no individual request states a dependency in the dependsOn property.
72 * 2. Serial - all individual requests depend on the previous individual request.
73 * 3. Same - all individual requests that state a dependency in the dependsOn property, state the same dependency.
74 * As JSON batching matures, these limitations will be removed.
75 * @see {@link https://developer.microsoft.com/en-us/graph/docs/concepts/known_issues#json-batching}
76 *
77 * @param {Map<string, BatchRequestStep>} requests - The map of requests.
78 * @returns The boolean indicating the validation status
79 */
80 private static validateDependencies;
81 /**
82 * @private
83 * @static
84 * @async
85 * Converts Request Object instance to a JSON
86 * @param {IsomorphicRequest} request - The IsomorphicRequest Object instance
87 * @returns A promise that resolves to JSON representation of a request
88 */
89 private static getRequestData;
90 /**
91 * @private
92 * @static
93 * @async
94 * Gets the body of a Request object instance
95 * @param {IsomorphicRequest} request - The IsomorphicRequest object instance
96 * @returns The Promise that resolves to a body value of a Request
97 */
98 private static getRequestBody;
99 /**
100 * @public
101 * @constructor
102 * Constructs a BatchRequestContent instance
103 * @param {BatchRequestStep[]} [requests] - Array of requests value
104 * @returns An instance of a BatchRequestContent
105 */
106 constructor(requests?: BatchRequestStep[]);
107 /**
108 * @public
109 * Adds a request to the batch request content
110 * @param {BatchRequestStep} request - The request value
111 * @returns The id of the added request
112 */
113 addRequest(request: BatchRequestStep): string;
114 /**
115 * @public
116 * Removes request from the batch payload and its dependencies from all dependents
117 * @param {string} requestId - The id of a request that needs to be removed
118 * @returns The boolean indicating removed status
119 */
120 removeRequest(requestId: string): boolean;
121 /**
122 * @public
123 * @async
124 * Serialize content from BatchRequestContent instance
125 * @returns The body content to make batch request
126 */
127 getContent(): Promise<BatchRequestBody>;
128 /**
129 * @public
130 * Adds a dependency for a given dependent request
131 * @param {string} dependentId - The id of the dependent request
132 * @param {string} [dependencyId] - The id of the dependency request, if not specified the preceding request will be considered as a dependency
133 * @returns Nothing
134 */
135 addDependency(dependentId: string, dependencyId?: string): void;
136 /**
137 * @public
138 * Removes a dependency for a given dependent request id
139 * @param {string} dependentId - The id of the dependent request
140 * @param {string} [dependencyId] - The id of the dependency request, if not specified will remove all the dependencies of that request
141 * @returns The boolean indicating removed status
142 */
143 removeDependency(dependentId: string, dependencyId?: string): boolean;
144}