"use strict";(globalThis.webpackChunk=globalThis.webpackChunk||[]).push([[2],{434(e,t,r){r.r(t),r.d(t,{EventStreamSerde:()=>s});var n=r(176),i=r(243);class s{marshaller;serializer;deserializer;serdeContext;defaultContentType;constructor({marshaller:e,serializer:t,deserializer:r,serdeContext:n,defaultContentType:i}){this.marshaller=e,this.serializer=t,this.deserializer=r,this.serdeContext=n,this.defaultContentType=i}async serializeEventStream({eventStream:e,requestSchema:t,initialRequest:r}){const n=this.marshaller,i=t.getEventStreamMember(),s=t.getMemberSchema(i),a=this.serializer,o=this.defaultContentType,l=Symbol("initialRequestMarker"),c={async*[Symbol.asyncIterator](){if(r){const e={":event-type":{type:"string",value:"initial-request"},":message-type":{type:"string",value:"event"},":content-type":{type:"string",value:o}};a.write(t,r);const n=a.flush();yield{[l]:!0,headers:e,body:n}}for await(const t of e)yield t}};return n.serialize(c,e=>{if(e[l])return{headers:e.headers,body:e.body};const t=Object.keys(e).find(e=>"__type"!==e)??"",{additionalHeaders:r,body:n,eventType:i,explicitPayloadContentType:a}=this.writeEventBody(t,s,e);return{headers:{":event-type":{type:"string",value:i},":message-type":{type:"string",value:"event"},":content-type":{type:"string",value:a??o},...r},body:n}})}async deserializeEventStream({response:e,responseSchema:t,initialResponseContainer:r}){const n=this.marshaller,s=t.getEventStreamMember(),a=t.getMemberSchema(s).getMemberSchemas(),o=Symbol("initialResponseMarker"),l=n.deserialize(e.body,async e=>{const r=Object.keys(e).find(e=>"__type"!==e)??"",n=e[r].body;if("initial-response"===r){const e=await this.deserializer.read(t,n);return delete e[s],{[o]:!0,...e}}if(r in a){const t=a[r];if(t.isStructSchema()){const s={};let a=!1;for(const[o,l]of t.structIterator()){const{eventHeader:t,eventPayload:c}=l.getMergedTraits();if(a=a||Boolean(t||c),c)l.isBlobSchema()?s[o]=n:l.isStringSchema()?s[o]=(this.serdeContext?.utf8Encoder??i.toUtf8)(n):l.isStructSchema()&&(s[o]=await this.deserializer.read(l,n));else if(t){const t=e[r].headers[o]?.value;null!=t&&(l.isNumericSchema()?s[o]=t&&"object"==typeof t&&"bytes"in t?BigInt(t.toString()):Number(t):s[o]=t)}}if(a)return{[r]:s};if(0===n.byteLength)return{[r]:{}}}return{[r]:await this.deserializer.read(t,n)}}return{$unknown:e}}),c=l[Symbol.asyncIterator](),d=await c.next();if(d.done)return l;if(d.value?.[o]){if(!t)throw new Error("@smithy::core/protocols - initial-response event encountered in event stream but no response schema given.");for(const[e,t]of Object.entries(d.value))r[e]=t}return{async*[Symbol.asyncIterator](){for(d?.value?.[o]||(yield d.value);;){const{done:e,value:t}=await c.next();if(e)break;yield t}}}}writeEventBody(e,t,r){const i=this.serializer;let s,a=e,o=null;const l={};if(t.getSchema()[4].includes(e)){const n=t.getMemberSchema(e);if(!n.isStructSchema())throw new Error("@smithy/core/event-streams - non-struct member not supported in event stream union.");for(const[t,i]of n.structIterator()){const{eventHeader:n,eventPayload:s}=i.getMergedTraits();if(s)o=t;else if(n){const n=r[e][t];let s="binary";i.isNumericSchema()?s=(-2)**31<=n&&n<=2**31-1?"integer":"long":i.isTimestampSchema()?s="timestamp":i.isStringSchema()?s="string":i.isBooleanSchema()&&(s="boolean"),null!=n&&(l[t]={type:s,value:n},delete r[e][t])}}if(null!==o){const t=n.getMemberSchema(o);t.isBlobSchema()?s="application/octet-stream":t.isStringSchema()&&(s="text/plain"),i.write(t,r[e][o])}else i.write(n,r[e])}else{const[t,n]=r[e];a=t,i.write(15,n)}const c=i.flush();return{body:"string"==typeof c?(this.serdeContext?.utf8Decoder??n.fromUtf8)(c):c,eventType:a,explicitPayloadContentType:s,additionalHeaders:l}}}},433(e,t,r){r.r(t),r.d(t,{EventStreamSerde:()=>n.EventStreamSerde});var n=r(434)}}]);
//# sourceMappingURL=2.js.map?77387006a133d2b3ad99