-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add batch request content #354
base: main
Are you sure you want to change the base?
Changes from all commits
77fdd32
d148db1
9da9af4
b46c141
dd38118
8957d31
52d363f
8e3338e
1a0664c
8bb57d1
7c3cfff
73fb569
21bbedc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/** | ||
* ------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. | ||
* See License in the project root for license information. | ||
* ------------------------------------------------------------------------------------------- | ||
*/ | ||
|
||
/** | ||
* @module BatchItem | ||
*/ | ||
|
||
/** | ||
* @interface | ||
* Signature represents key value pair object | ||
*/ | ||
import { | ||
Parsable, | ||
ParseNode, | ||
SerializationWriter, | ||
createUntypedNodeFromDiscriminatorValue, | ||
} from "@microsoft/kiota-abstractions"; | ||
|
||
/** | ||
* @interface | ||
* Signature represents payload structure for batch request and response | ||
*/ | ||
export interface BatchItem { | ||
readonly id: string; | ||
method: string; | ||
url: string; | ||
headers?: Record<string, string> | null; | ||
body?: Record<string, any> | null; | ||
dependsOn?: string[]; | ||
} | ||
|
||
/** | ||
* @interface | ||
* Signature represents unwrapped payload structure for batch response | ||
*/ | ||
export interface BatchResponse { | ||
id: string; | ||
headers?: Record<string, string> | null; | ||
body?: ArrayBuffer | null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. once they get a batch response (item?), if the payload is structured/a parsable, how can they get from the body to the deseiralized payload? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is a will be resolved by implementing #354 (comment) ? |
||
status?: number; | ||
} | ||
|
||
/** | ||
* @interface | ||
* Signature representing Batch request body | ||
*/ | ||
export interface BatchRequestCollection { | ||
requests: BatchItem[]; | ||
} | ||
|
||
/** | ||
* @interface | ||
* Signature representing Batch response body | ||
*/ | ||
export interface BatchResponseCollection { | ||
responses: BatchResponse[]; | ||
} | ||
|
||
/** | ||
* Serializes the batch request body | ||
* @param writer | ||
* @param batchRequestBody | ||
*/ | ||
export const serializeBatchRequestBody = ( | ||
writer: SerializationWriter, | ||
batchRequestBody: Partial<BatchRequestCollection> | undefined | null = {}, | ||
): void => { | ||
if (batchRequestBody) { | ||
writer.writeCollectionOfObjectValues("requests", batchRequestBody.requests, serializeBatchItem); | ||
} | ||
}; | ||
|
||
/** | ||
* Serializes the batch item | ||
* @param writer | ||
* @param batchRequestData | ||
*/ | ||
export const serializeBatchItem = ( | ||
writer: SerializationWriter, | ||
batchRequestData: Partial<BatchItem> | undefined | null = {}, | ||
): void => { | ||
if (batchRequestData) { | ||
writer.writeStringValue("id", batchRequestData.id); | ||
writer.writeStringValue("method", batchRequestData.method); | ||
writer.writeStringValue("url", batchRequestData.url); | ||
writer.writeObjectValue("headers", batchRequestData.headers); | ||
writer.writeObjectValue("body", batchRequestData.body); | ||
writer.writeCollectionOfPrimitiveValues("dependsOn", batchRequestData.dependsOn); | ||
} | ||
}; | ||
|
||
/** | ||
* BatchResponseCollection ParsableFactory | ||
* @param _parseNode | ||
*/ | ||
export const createBatchResponseContentFromDiscriminatorValue = ( | ||
_parseNode: ParseNode | undefined, | ||
): ((instance?: Parsable) => Record<string, (node: ParseNode) => void>) => { | ||
return deserializeIntoBatchResponseContent; | ||
}; | ||
|
||
/** | ||
* Deserializes the batch response body | ||
* @param batchResponseBody | ||
*/ | ||
export const deserializeIntoBatchResponseContent = ( | ||
batchResponseBody: Partial<BatchResponseCollection> | undefined = {}, | ||
): Record<string, (node: ParseNode) => void> => { | ||
return { | ||
responses: n => { | ||
batchResponseBody.responses = n.getCollectionOfObjectValues(createBatchResponseFromDiscriminatorValue); | ||
}, | ||
}; | ||
}; | ||
|
||
/** | ||
* BatchItem ParsableFactory | ||
* @param _parseNode | ||
*/ | ||
export const createBatchResponseFromDiscriminatorValue = ( | ||
_parseNode: ParseNode | undefined, | ||
): ((instance?: Parsable) => Record<string, (node: ParseNode) => void>) => { | ||
return deserializeIntoBatchResponse; | ||
}; | ||
|
||
/** | ||
* Deserializes the batch item | ||
* @param batchResponse | ||
*/ | ||
export const deserializeIntoBatchResponse = ( | ||
batchResponse: Partial<BatchResponse> | undefined = {}, | ||
): Record<string, (node: ParseNode) => void> => { | ||
return { | ||
id: n => { | ||
batchResponse.id = n.getStringValue(); | ||
}, | ||
headers: n => { | ||
batchResponse.headers = n.getObjectValue<Record<string, string>>(createUntypedNodeFromDiscriminatorValue); | ||
}, | ||
body: n => { | ||
batchResponse.body = n.getByteArrayValue(); | ||
}, | ||
status: n => { | ||
batchResponse.status = n.getNumberValue(); | ||
}, | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the body is a stream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rkodev please avoid resolving conversation until a consensus has been reached. It makes progress much harder to track reviewers' side.