Skip to content

Commit

Permalink
Document the response handling function
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort committed Jan 15, 2021
1 parent e638fc2 commit 76451b9
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,31 @@ export type ResponseProjection<RawResponse, Response> = (
rawResponse: RawResponse
) => { data: Response; errors?: SearchStrategyError[] };

/**
* Turns the {@link DataSearchRequestDescriptor} into a {@link
* DataSearchResponseDescriptor} by decoding or validating and unrolling the
* partial and final responses emitted.
*
* Since the parameters are refs they will be used immediately for the next
* response without the need to recreate the pipeline.
*
*
* @param initialResponseRef - A ref object containing the initial value to
* emit when a new request is handled. *
* @param projectResponseRef - A ref object containing the projection function
* to apply to each response payload. It should validate that the response
* payload is of the type {@link RawResponse} and decode it to a {@link
* Response}.
*
* @return A function that decodes and validates each response payload using
* the arguments given above.
*/
export const handleDataSearchResponse = <
Request extends IKibanaSearchRequest,
RawResponse,
Response,
InitialResponse
>(
// these are ref objects so they can be changed without having to recreate a new pipeline
initialResponseRef: { current: InitialResponse },
projectResponseRef: { current: ResponseProjection<RawResponse, Response> }
) => ({
Expand Down

0 comments on commit 76451b9

Please sign in to comment.