MCPcopy Index your code
hub / github.com/ChinaSiro/claude-code-sourcemap / formData

Function formData

package/cli.js:210–210  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

208\r
209`);if(M.push(G,f,X),typeof f.size==="number")$+=G.byteLength+f.size+X.byteLength;else P=!0}let W=KO8.encode(`--${w}--\r
210`);if(M.push(W),$+=W.byteLength,P)$=null;Y=q,z=async function*(){for(let D of M)if(D.stream)yield*D.stream();else yield D},A=`multipart/form-data; boundary=${w}`}else if(ex7(q)){if(Y=q,$=q.size,q.type)A=q.type}else if(typeof q[Symbol.asyncIterator]==="function"){if(K)throw TypeError("keepalive");if(Bp6.isDisturbed(q)||q.locked)throw TypeError("Response body object should not be disturbed or locked");_=q instanceof ReadableStream?q:YI5(q)}if(typeof Y==="string"||Bp6.isBuffer(Y))$=Buffer.byteLength(Y);if(z!=null){let w;_=new ReadableStream({async start(){w=z(q)[Symbol.asyncIterator]()},async pull(j){let{value:H,done:J}=await w.next();if(J)queueMicrotask(()=>{j.close(),j.byobRequest?.respond(0)});else if(!zI7(_)){let M=new Uint8Array(H);if(M.byteLength)j.enqueue(M)}return j.desiredSize>0},async cancel(j){await w.return()},type:"bytes"})}return[{stream:_,source:Y,length:$},A]}function fI5(q,K=!1){if(q instanceof ReadableStream)X51(!Bp6.isDisturbed(q),"The body has already been consumed."),X51(!q.locked,"The stream is locked.");return AI7(q,K)}function ZI5(q,K){let[_,z]=K.stream.tee();return K.stream=_,{stream:z,length:K.length,source:K.source}}function GI5(q){if(q.aborted)throw new DOMException("The operation was aborted.","AbortError")}function TI5(q){return{blob(){return bD6(this,(_)=>{let z=KI7(this);if(z===null)z="";else if(z)z=PI5(z);return new JI5([_],{type:z})},q)},arrayBuffer(){return bD6(this,(_)=>{return new Uint8Array(_).buffer},q)},text(){return bD6(this,_I7,q)},json(){return bD6(this,kI5,q)},formData(){return bD6(this,(_)=>{let z=KI7(this);if(z!==null)switch(z.essence){case"multipart/form-data":{let Y=WI5(_,z);if(Y==="failure")throw TypeError("Failed to parse body as FormData.");let $=new qI7;return $[xD6]=Y,$}case"application/x-www-form-urlencoded":{let Y=new URLSearchParams(_.toString()),$=new qI7;for(let[A,O]of Y)$.append(A,O);return $}}throw TypeError('Content-Type was not one of "multipart/form-data" or "application/x-www-form-urlencoded".')},q)},bytes(){return bD6(this,(_)=>{return new Uint8Array(_)},q)}}}function vI5(q){Object.assign(q.prototype,TI5(q))}async function bD6(q,K,_){if(HI5.brandCheck(q,_),OI7(q))throw TypeError("Body is unusable: Body has already been read");GI5(q[xD6]);let z=OI5(),Y=(A)=>z.reject(A),$=(A)=>{try{z.resolve(K(A))}catch(O){Y(O)}};if(q[xD6].body==null)return $(Buffer.allocUnsafe(0)),z.promise;return await wI5(q[xD6].body,$,Y),z.promise}function OI7(q){let K=q[xD6].body;return K!=null&&(K.stream.locked||Bp6.isDisturbed(K.stream))}function kI5(q){return JSON.parse(_I7(q))}function KI7(q){let K=q[xD6].headersList,_=jI5(K);if(_==="failure")return null;return _}wI7.exports={extractBody:AI7,safelyExtractBody:fI5,cloneBody:ZI5,mixinBody:vI5,streamRegistry:$I7,hasFinalizationRegistry:YI7,bodyUnusable:OI7}});var TI7=m((cp$,GI7)=>{var z3=U6("node:assert"),K9=Yz(),{channels:jI7}=vD6(),W51=sK1(),{RequestContentLengthMismatchError:S_6,ResponseContentLengthMismatchError:VI5,RequestAbortedError:WI7,HeadersTimeoutError:NI5,HeadersOverflowError:yI5,SocketError:OO8,InformationalError:uD6,BodyTimeoutError:EI5,HTTPParserError:LI5,ResponseExceededMaxSizeError:RI5}=Q$(),{kUrl:DI7,kReset:ek,kClient:G51,kParser:OJ,kBlocking:Up6,kRunning:gZ,kPending:hI5,kSize:HI7,kWriting:re,kQueue:AI,kNoRef:gp6,kKeepAliveDefaultTimeout:SI5,kHostHeader:CI5,kPendingIdx:bI5,kRunningIdx:Nh,kError:yh,kPipelining:$O8,kSocket:mD6,kKeepAliveTimeoutValue:wO8,kMaxHeadersSize:D51,kKeepAliveMaxTimeout:xI5,kKeepAliveTimeoutThreshold:II5,kHeadersTimeout:uI5,kBodyTimeout:mI5,kStrictContentLength:T51,kMaxRequests:JI7,kCounter:pI5,kMaxResponseSize:BI5,kOnError:gI5,kResume:ie,kHTTPContext:fI7}=Jj(),BB=_x7(),FI5=Buffer.alloc(0),_O8=Buffer[Symbol.species],zO8=K9.addListener,UI5=K9.removeAllListeners,f51;async function QI5(){let q=process.env.JEST_WORKER_ID?z51():void 0,K;try{K=await WebAssembly.compile($x7())}catch(_){K=await WebAssembly.compile(q||z51())}return await WebAssembly.instantiate(K,{env:{wasm_on_url:(_,z,Y)=>{return 0},wasm_on_status:(_,z,Y)=>{z3(PP.ptr===_);let $=z-FB+gB.byteOffset;return PP.onStatus(new _O8(gB.buffer,$,Y))||0},wasm_on_message_begin:(_)=>{return z3(PP.ptr===_),PP.onMessageBegin()||0},wasm_on_header_field:(_,z,Y)=>{z3(PP.ptr===_);let $=z-FB+gB.byteOffset;return PP.onHeaderField(new _O8(gB.buffer,$,Y))||0},wasm_on_header_value:(_,z,Y)=>{z3(PP.ptr===_);let $=z-FB+gB.byteOffset;return PP.onHeaderValue(new _O8(gB.buffer,$,Y))||0},wasm_on_headers_complete:(_,z,Y,$)=>{return z3(PP.ptr===_),PP.onHeadersComplete(z,Boolean(Y),Boolean($))||0},wasm_on_body:(_,z,Y)=>{z3(PP.ptr===_);let $=z-FB+gB.byteOffset;return PP.onBody(new _O8(gB.buffer,$,Y))||0},wasm_on_message_complete:(_)=>{return z3(PP.ptr===_),PP.onMessageComplete()||0}}})}var Z51=null,v51=QI5();v51.catch();var PP=null,gB=null,YO8=0,FB=null,dI5=0,Fp6=1,pD6=2|Fp6,AO8=4|Fp6,k51=8|dI5;class ZI7{constructor(q,K,{exports:_}){z3(Number.isFinite(q[D51])&&q[D51]>0),this.llhttp=_,this.ptr=this.llhttp.llhttp_alloc(BB.TYPE.RESPONSE),this.client=q,this.socket=K,this.timeout=null,this.timeoutValue=null,this.timeoutType=null,this.statusCode=null,this.statusText="",this.upgrade=!1,this.headers=[],this.headersSize=0,this.headersMaxSize=q[D51],this.shouldKeepAlive=!1,this.paused=!1,this.resume=this.resume.bind(this),this.bytesRead=0,this.keepAlive="",this.contentLength="",this.connection="",this.maxResponseSize=q[BI5]}setTimeout(q,K){if(q!==this.timeoutValue||K&Fp6^this.timeoutType&Fp6){if(this.timeout)W51.clearTimeout(this.timeout),this.timeout=null;if(q)if(K&Fp6)this.timeout=W51.setFastTimeout(MI7,q,new WeakRef(this));else this.timeout=setTimeout(MI7,q,new WeakRef(this)),this.timeout.unref();this.timeoutValue=q}else if(this.timeout){if(this.timeout.refresh)this.timeout.refresh()}this.timeoutType=K}resume(){if(this.socket.destroyed||!this.paused)return;if(z3(this.ptr!=null),z3(PP==null),this.llhttp.llhttp_resume(this.ptr),z3(this.timeoutType===AO8),this.timeout){if(this.timeout.refresh)this.timeout.refresh()}this.paused=!1,this.execute(this.socket.read()||FI5),this.readMore()}readMore(){while(!this.paused&&this.ptr){let q=this.socket.read();if(q===null)break;this.execute(q)}}execute(q){z3(this.ptr!=null),z3(PP==null),z3(!this.paused);let{socket:K,llhttp:_}=this;if(q.length>YO8){if(FB)_.free(FB);YO8=Math.ceil(q.length/4096)*4096,FB=_.malloc(YO8)}new Uint8Array(_.memory.buffer,FB,YO8).set(q);try{let z;try{gB=q,PP=this,z=_.llhttp_execute(this.ptr,FB,q.length)}catch($){throw $}finally{PP=null,gB=null}let Y=_.llhttp_get_error_pos(this.ptr)-FB;if(z===BB.ERROR.PAUSED_UPGRADE)this.onUpgrade(q.slice(Y));else if(z===BB.ERROR.PAUSED)this.paused=!0,K.unshift(q.slice(Y));else if(z!==BB.ERROR.OK){let $=_.llhttp_get_error_reason(this.ptr),A="";if($){let O=new Uint8Array(_.memory.buffer,$).indexOf(0);A="Response does not match the HTTP/1.1 protocol ("+Buffer.from(_.memory.buffer,$,O).toString()+")"}throw new LI5(A,BB.ERROR[z],q.slice(Y))}}catch(z){K9.destroy(K,z)}}destroy(){z3(this.ptr!=null),z3(PP==null),this.llhttp.llhttp_free(this.ptr),this.ptr=null,this.timeout&&W51.clearTimeout(this.timeout),this.timeout=null,this.timeoutValue=null,this.timeoutType=null,this.paused=!1}onStatus(q){this.statusText=q.toString()}onMessageBegin(){let{socket:q,client:K}=this;if(q.destroyed)return-1;let _=K[AI][K[Nh]];if(!_)return-1;_.onResponseStarted()}onHeaderField(q){let K=this.headers.length;if((K&1)===0)this.headers.push(q);else this.headers[K-1]=Buffer.concat([this.headers[K-1],q]);this.trackHeader(q.length)}onHeaderValue(q){let K=this.headers.length;if((K&1)===1)this.headers.push(q),K+=1;else this.headers[K-1]=Buffer.concat([this.headers[K-1],q]);let _=this.headers[K-2];if(_.length===10){let z=K9.bufferToLowerCasedHeaderName(_);if(z==="keep-alive")this.keepAlive+=q.toString();else if(z==="connection")this.connection+=q.toString()}else if(_.length===14&&K9.bufferToLowerCasedHeaderName(_)==="content-length")this.contentLength+=q.toString();this.trackHeader(q.length)}trackHeader(q){if(this.headersSize+=q,this.headersSize>=this.headersMaxSize)K9.destroy(this.socket,new yI5)}onUpgrade(q){let{upgrade:K,client:_,socket:z,headers:Y,statusCode:$}=this;z3(K),z3(_[mD6]===z),z3(!z.destroyed),z3(!this.paused),z3((Y.length&1)===0);let A=_[AI][_[Nh]];z3(A),z3(A.upgrade||A.method==="CONNECT"),this.statusCode=null,this.statusText="",this.shouldKeepAlive=null,this.headers=[],this.headersSize=0,z.unshift(q),z[OJ].destroy(),z[OJ]=null,z[G51]=null,z[yh]=null,UI5(z),_[mD6]=null,_[fI7]=null,_[AI][_[Nh]++]=null,_.emit("disconnect",_[DI7],[_],new uD6("upgrade"));try{A.onUpgrade($,Y,z)}catch(O){K9.destroy(z,O)}_[ie]()}onHeadersComplete(q,K,_){let{client:z,socket:Y,headers:$,statusText:A}=this;if(Y.destroyed)return-1;let O=z[AI][z[Nh]];if(!O)return-1;if(z3(!this.upgrade),z3(this.statusCode<200),q===100)return K9.destroy(Y,new OO8("bad response",K9.getSocketInfo(Y))),-1;if(K&&!O.upgrade)return K9.destroy(Y,new OO8("bad upgrade",K9.getSocketInfo(Y))),-1;if(z3(this.timeoutType===pD6),this.statusCode=q,this.shouldKeepAlive=_||O.method==="HEAD"&&!Y[ek]&&this.connection.toLowerCase()==="keep-alive",this.statusCode>=200){let j=O.bodyTimeout!=null?O.bodyTimeout:z[mI5];this.setTimeout(j,AO8)}else if(this.timeout){if(this.timeout.refresh)this.timeout.refresh()}if(O.method==="CONNECT")return z3(z[gZ]===1),this.upgrade=!0,2;if(K)return z3(z[gZ]===1),this.upgrade=!0,2;if(z3((this.headers.length&1)===0),this.headers=[],this.headersSize=0,this.shouldKeepAlive&&z[$O8]){let j=this.keepAlive?K9.parseKeepAliveTimeout(this.keepAlive):null;if(j!=null){let H=Math.min(j-z[II5],z[xI5]);if(H<=0)Y[ek]=!0;else z[wO8]=H}else z[wO8]=z[SI5]}else Y[ek]=!0;let w=O.onHeaders(q,$,this.resume,A)===!1;if(O.aborted)return-1;if(O.method==="HEAD")return 1;if(q<200)return 1;if(Y[Up6])Y[Up6]=!1,z[ie]();return w?BB.ERROR.PAUSED:0}onBody(q){let{client:K,socket:_,statusCode:z,maxResponseSize:Y}=this;if(_.destroyed)return-1;let $=K[AI][K[Nh]];if(z3($),z3(this.timeoutType===AO8),this.timeout){if(this.timeout.refresh)this.timeout.refresh()}if(z3(z>=200),Y>-1&&this.bytesRead+q.length>Y)return K9.destroy(_,new RI5),-1;if(this.bytesRead+=q.length,$.onData(q)===!1)return BB.ERROR.PAUSED}onMessageComplete(){let{client:q,socket:K,statusCode:_,upgrade:z,headers:Y,contentLength:$,bytesRead:A,shouldKeepAlive:O}=this;if(K.destroyed&&(!_||O))return-1;if(z)return;z3(_>=100),z3((this.headers.length&1)===0);let w=q[AI][q[Nh]];if(z3(w),this.statusCode=null,this.statusText="",this.bytesRead=0,this.contentLength="",this.keepAlive="",this.connection="",this.headers=[],this.headersSize=0,_<200)return;if(w.method!=="HEAD"&&$&&A!==parseInt($,10))return K9.destroy(K,new VI5),-1;if(w.onComplete(Y),q[AI][q[Nh]++]=null,K[re])return z3(q[gZ]===0),K9.destroy(K,new uD6("reset")),BB.ERROR.PAUSED;else if(!O)return K9.destroy(K,new uD6("reset")),BB.ERROR.PAUSED;else if(K[ek]&&q[gZ]===0)return K9.destroy(K,new uD6("reset")),BB.ERROR.PAUSED;else if(q[$O8]==null||q[$O8]===1)setImmediate(()=>q[ie]());else q[ie]()}}function MI7(q){let{socket:K,timeoutType:_,client:z,paused:Y}=q.deref();if(_===pD6){if(!K[re]||K.writableNeedDrain||z[gZ]>1)z3(!Y,"cannot be paused while waiting for headers"),K9.destroy(K,new NI5)}else if(_===AO8){if(!Y)K9.destroy(K,new EI5)}else if(_===k51)z3(z[gZ]===0&&z[wO8]),K9.destroy(K,new uD6("socket idle timeout"))}async function cI5(q,K){if(q[mD6]=K,!Z51)Z51=await v51,v51=null;K[gp6]=!1,K[re]=!1,K[ek]=!1,K[Up6]=!1,K[OJ]=new ZI7(q,K,Z51),zO8(K,"error",function(z){z3(z.code!=="ERR_TLS_CERT_ALTNAME_INVALID");let Y=this[OJ];if(z.code==="ECONNRESET"&&Y.statusCode&&!Y.shouldKeepAlive){Y.onMessageComplete();return}this[yh]=z,this[G51][gI5](z)}),zO8(K,"readable",function(){let z=this[OJ];if(z)z.readMore()}),zO8(K,"end",function(){let z=this[OJ];if(z.statusCode&&!z.shouldKeepAlive){z.onMessageComplete();return}K9.destroy(this,new OO8("other side closed",K9.getSocketInfo(this)))}),zO8(K,"close",function(){let z=this[G51],Y=this[OJ];if(Y){if(!this[yh]&&Y.statusCode&&!Y.shouldKeepAlive)Y.onMessageComplete();this[OJ].destroy(),this[OJ]=null}let $=this[yh]||new OO8("closed",K9.getSocketInfo(this));if(z[mD6]=null,z[fI7]=null,z.destroyed){z3(z[hI5]===0);let A=z[AI].splice(z[Nh]);for(let O=0;O<A.length;O++){let w=A[O];K9.errorRequest(z,w,$)}}else if(z[gZ]>0&&$.code!=="UND_ERR_INFO"){let A=z[AI][z[Nh]];z[AI][z[Nh]++]=null,K9.errorRequest(z,A,$)}z[bI5]=z[Nh],z3(z[gZ]===0),z.emit("disconnect",z[DI7],[z],$),z[ie]()});let _=!1;return K.on("close",()=>{_=!0}),{version:"h1",defaultPipelining:1,write(...z){return iI5(q,...z)},resume(){lI5(q)},destroy(z,Y){if(_)queueMicrotask(Y);else K.destroy(z).on("close",Y)},get destroyed(){return K.destroyed},busy(z){if(K[re]||K[ek]||K[Up6])return!0;if(z){if(q[gZ]>0&&!z.idempotent)return!0;if(q[gZ]>0&&(z.upgrade||z.method==="CONNECT"))return!0;if(q[gZ]>0&&K9.bodyLength(z.body)!==0&&(K9.isStream(z.body)||K9.isAsyncIterable(z.body)||K9.isFormDataLike(z.body)))return!0}return!1}}}function lI5(q){let K=q[mD6];if(K&&!K.destroyed){if(q[HI7]===0){if(!K[gp6]&&K.unref)K.unref(),K[gp6]=!0}else if(K[gp6]&&K.ref)K.ref(),K[gp6]=!1;if(q[HI7]===0){if(K[OJ].timeoutType!==k51)K[OJ].setTimeout(q[wO8],k51)}else if(q[gZ]>0&&K[OJ].statusCode<200){if(K[OJ].timeoutType!==pD6){let _=q[AI][q[Nh]],z=_.headersTimeout!=null?_.headersTimeout:q[uI5];K[OJ].setTimeout(z,pD6)}}}}function nI5(q){return q!=="GET"&&q!=="HEAD"&&q!=="OPTIONS"&&q!=="TRACE"&&q!=="CONNECT"}function iI5(q,K){let{method:_,path:z,host:Y,upgrade:$,blocking:A,reset:O}=K,{body:w,headers:j,contentLength:H}=K,J=_==="PUT"||_==="POST"||_==="PATCH"||_==="QUERY"||_==="PROPFIND"||_==="PROPPATCH";if(K9.isFormDataLike(w)){if(!f51)f51=ID6().extractBody;let[D,f]=f51(w);if(K.contentType==null)j.push("content-type",f);w=D.stream,H=D.length}else if(K9.isBlobLike(w)&&K.contentType==null&&w.type)j.push("content-type",w.type);if(w&&typeof w.read==="function")w.read(0);let M=K9.bodyLength(w);if(H=M??H,H===null)H=K.contentLength;if(H===0&&!J)H=null;if(nI5(_)&&H>0&&K.contentLength!==null&&K.contentLength!==H){if(q[T51])return K9.errorRequest(q,K,new S_6),!1;process.emitWarning(new S_6)}let X=q[mD6],P=(D)=>{if(K.aborted||K.completed)return;K9.errorRequest(q,K,D||new WI7),K9.destroy(w),K9.destroy(X,new uD6("aborted"))};try{K.onConnect(P)}catch(D){K9.errorRequest(q,K,D)}if(K.aborted)return!1;if(_==="HEAD")X[ek]=!0;if($||_==="CONNECT")X[ek]=!0;if(O!=null)X[ek]=O;if(q[JI7]&&X[pI5]++>=q[JI7])X[ek]=!0;if(A)X[Up6]=!0;let W=`${_} ${z} HTTP/1.1\r
211`;if(typeof Y==="string")W+=`host: ${Y}\r
212`;else W+=q[CI5];if($)W+=`connection: upgrade\r
213upgrade: ${$}\r

Callers

nothing calls this directly

Calls 4

bD6Function · 0.85
KI7Function · 0.85
toStringMethod · 0.65
appendMethod · 0.45

Tested by

no test coverage detected