Skip to content
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

fix(json-rpc): merge initial-response event into operation response #1110

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Dec 12, 2023

This adds an eventStream serde helper for checking the first event of an event stream.

  • if the type is initial-response, then it is merged into the operation output.
  • if the type is not initial-response, then it is re-emplaced onto the iterator given to the user.

Additionally, for eventStream deser functions, deserialization of the implicit initial-response event is added to the union to avoid ignoring that unmodeled union member.

Note: this behavior is specific to AWS. It should have no effect on JSON eventstreams that do not implement initial-response, but there are also no hooks available to override this behavior in AWS SDK TypeScript codegen at the moment.

If non-AWS users want to have members other than the streaming member for the output, this could also be of use to them.

@kuhe
Copy link
Contributor Author

kuhe commented Dec 12, 2023

diff example for JSv3

modified code for command deser (streaming)

/**
 * deserializeAws_json1_1XYZCommand
 */
export const de_XYZCommand = async (
  output: __HttpResponse,
  context: __SerdeContext & __EventStreamSerdeContext
): Promise<XYZCommandOutput> => {
  if (output.statusCode >= 300) {
    return de_XYZCommandError(output, context);
  }
  const contents = await bufferInitialResponse("streamingMember", de_XYZResponseStream, output, context);
  const response: XYZCommandOutput = {
    $metadata: deserializeMetadata(output),
    ...contents,
  };
  return response;
};

additional code in streaming member deser (de_XYZResponseStream)

    if (event["initial-response"] != null) {
      const ir = await parseBody(event["initial-response"].body, context);
      return {
        "initial-response": map({
           someNonStreamingMember: [, ir.someNonStreamingMember],
        }),
      } as any;
    }

in the above example, someNonStreamingMember is merged into contents which also contains the primary streaming member. Currently, only the streaming member is populated in a streaming operation response structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant