"use strict";(globalThis.webpackChunk=globalThis.webpackChunk||[]).push([[2],{438(e,t,r){r.r(t),r.d(t,{EventStreamSerde:()=>s});var i=r(177),n=r(244);class s{marshaller;serializer;deserializer;serdeContext;defaultContentType;constructor({marshaller:e,serializer:t,deserializer:r,serdeContext:i,defaultContentType:n}){this.marshaller=e,this.serializer=t,this.deserializer=r,this.serdeContext=i,this.defaultContentType=n}async serializeEventStream({eventStream:e,requestSchema:t,initialRequest:r}){const i=this.marshaller,n=t.getEventStreamMember(),s=t.getMemberSchema(n),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 i=a.flush();yield{[l]:!0,headers:e,body:i}}for await(const t of e)yield t}};return i.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:i,eventType:n,explicitPayloadContentType:a}=this.writeEventBody(t,s,e);return{headers:{":event-type":{type:"string",value:n},":message-type":{type:"string",value:"event"},":content-type":{type:"string",value:a??o},...r},body:i}})}async deserializeEventStream({response:e,responseSchema:t,initialResponseContainer:r}){const i=this.marshaller,s=t.getEventStreamMember(),a=t.getMemberSchema(s).getMemberSchemas(),o=Symbol("initialResponseMarker"),l=i.deserialize(e.body,async e=>{const r=Object.keys(e).find(e=>"__type"!==e)??"",i=e[r].body;if("initial-response"===r){const e=await this.deserializer.read(t,i);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]=i:l.isStringSchema()?s[o]=(this.serdeContext?.utf8Encoder??n.toUtf8)(i):l.isStructSchema()&&(s[o]=await this.deserializer.read(l,i));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===i.byteLength)return{[r]:{}}}return{[r]:await this.deserializer.read(t,i)}}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 n=this.serializer;let s,a=e,o=null;const l={};if(t.getSchema()[4].includes(e)){const i=t.getMemberSchema(e);if(i.isStructSchema()){for(const[t,n]of i.structIterator()){const{eventHeader:i,eventPayload:s}=n.getMergedTraits();if(s)o=t;else if(i){const i=r[e][t];let s="binary";n.isNumericSchema()?s=(-2)**31<=i&&i<=2**31-1?"integer":"long":n.isTimestampSchema()?s="timestamp":n.isStringSchema()?s="string":n.isBooleanSchema()&&(s="boolean"),null!=i&&(l[t]={type:s,value:i},delete r[e][t])}}if(null!==o){const t=i.getMemberSchema(o);t.isBlobSchema()?s="application/octet-stream":t.isStringSchema()&&(s="text/plain"),n.write(t,r[e][o])}else n.write(i,r[e])}else{if(!i.isUnitSchema())throw new Error("@smithy/core/event-streams - non-struct member not supported in event stream union.");n.write(i,{})}}else{const[t,i]=r[e];a=t,n.write(15,i)}const c=n.flush()??new Uint8Array;return{body:"string"==typeof c?(this.serdeContext?.utf8Decoder??i.fromUtf8)(c):c,eventType:a,explicitPayloadContentType:s,additionalHeaders:l}}}},437(e,t,r){r.r(t),r.d(t,{EventStreamSerde:()=>i.EventStreamSerde});var i=r(438)}}]);
//# sourceMappingURL=2.js.map?8782073ca19602592802