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