mirror of
https://github.com/softprops/action-gh-release
synced 2026-10-02 17:51:31 +00:00
test(release): add unit tests when searching for a release (#603)
* fix(release): break when draft release is found when a release with the desired tag_name is found, break out of the loop that looks for it. this prevents the case where accidentally overwrite a detected release on successive iterations of the for loop fixes: #602 * include built output * add tests for finding tag from releases add tests for updated functionality to break when we find a release. the logic has been extracted into its own function, to make testing simpler by avoiding over mocking/stubbing of network calls that would create or update a release. the tests that were added use jest's describe/it blocks, but use node's assert function to align with other tests. there isn't any prior art for mocking function calls in the codebase, so for now we use simple promises in "mock" objects that adhere to the Releaser interface * refactor findTagFromReleases purely a sytlistic choice to not have to pre-declare the _release variable, and not have to check using `typeof _release === "string"` when detecting a found release * reset dist/index.js to master * update impl after merge with master * update dist
This commit is contained in:
1 parent
e2b105c98e
commit
6b18c2f260
3 files changed
+287
-13
No files matched your search
Vendored
+1
-1
@@ -1,3 +1,3 @@
|
||||
(()=>{var e={4914:function(e,t,A){"use strict";var s=this&&this.__createBinding||(Object.create?function(e,t,A,s){if(s===undefined)s=A;var r=Object.getOwnPropertyDescriptor(t,A);if(!r||("get"in r?!t.__esModule:r.writable||r.configurable)){r={enumerable:true,get:function(){return t[A]}}}Object.defineProperty(e,s,r)}:function(e,t,A,s){if(s===undefined)s=A;e[s]=t[A]});var r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:true,value:t})}:function(e,t){e["default"]=t});var o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var A in e)if(A!=="default"&&Object.prototype.hasOwnProperty.call(e,A))s(t,e,A);r(t,e);return t};Object.defineProperty(t,"__esModule",{value:true});t.issue=t.issueCommand=void 0;const i=o(A(857));const n=A(302);function issueCommand(e,t,A){const s=new Command(e,t,A);process.stdout.write(s.toString()+i.EOL)}t.issueCommand=issueCommand;function issue(e,t=""){issueCommand(e,{},t)}t.issue=issue;const a="::";class Command{constructor(e,t,A){if(!e){e="missing.command"}this.command=e;this.properties=t;this.message=A}toString(){let e=a+this.command;if(this.properties&&Object.keys(this.properties).length>0){e+=" ";let t=true;for(const A in this.properties){if(this.properties.hasOwnProperty(A)){const s=this.properties[A];if(s){if(t){t=false}else{e+=","}e+=`${A}=${escapeProperty(s)}`}}}}e+=`${a}${escapeData(this.message)}`;return e}}function escapeData(e){return(0,n.toCommandValue)(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function escapeProperty(e){return(0,n.toCommandValue)(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A").replace(/:/g,"%3A").replace(/,/g,"%2C")}},7484:function(e,t,A){"use strict";var s=this&&this.__createBinding||(Object.create?function(e,t,A,s){if(s===undefined)s=A;var r=Object.getOwnPropertyDescriptor(t,A);if(!r||("get"in r?!t.__esModule:r.writable||r.configurable)){r={enumerable:true,get:function(){return t[A]}}}Object.defineProperty(e,s,r)}:function(e,t,A,s){if(s===undefined)s=A;e[s]=t[A]});var r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:true,value:t})}:function(e,t){e["default"]=t});var o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var A in e)if(A!=="default"&&Object.prototype.hasOwnProperty.call(e,A))s(t,e,A);r(t,e);return t};var i=this&&this.__awaiter||function(e,t,A,s){function adopt(e){return e instanceof A?e:new A((function(t){t(e)}))}return new(A||(A=Promise))((function(A,r){function fulfilled(e){try{step(s.next(e))}catch(e){r(e)}}function rejected(e){try{step(s["throw"](e))}catch(e){r(e)}}function step(e){e.done?A(e.value):adopt(e.value).then(fulfilled,rejected)}step((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:true});t.platform=t.toPlatformPath=t.toWin32Path=t.toPosixPath=t.markdownSummary=t.summary=t.getIDToken=t.getState=t.saveState=t.group=t.endGroup=t.startGroup=t.info=t.notice=t.warning=t.error=t.debug=t.isDebug=t.setFailed=t.setCommandEcho=t.setOutput=t.getBooleanInput=t.getMultilineInput=t.getInput=t.addPath=t.setSecret=t.exportVariable=t.ExitCode=void 0;const n=A(4914);const a=A(4753);const c=A(302);const l=o(A(857));const g=o(A(6928));const h=A(5306);var u;(function(e){e[e["Success"]=0]="Success";e[e["Failure"]=1]="Failure"})(u||(t.ExitCode=u={}));function exportVariable(e,t){const A=(0,c.toCommandValue)(t);process.env[e]=A;const s=process.env["GITHUB_ENV"]||"";if(s){return(0,a.issueFileCommand)("ENV",(0,a.prepareKeyValueMessage)(e,t))}(0,n.issueCommand)("set-env",{name:e},A)}t.exportVariable=exportVariable;function setSecret(e){(0,n.issueCommand)("add-mask",{},e)}t.setSecret=setSecret;function addPath(e){const t=process.env["GITHUB_PATH"]||"";if(t){(0,a.issueFileCommand)("PATH",e)}else{(0,n.issueCommand)("add-path",{},e)}process.env["PATH"]=`${e}${g.delimiter}${process.env["PATH"]}`}t.addPath=addPath;function getInput(e,t){const A=process.env[`INPUT_${e.replace(/ /g,"_").toUpperCase()}`]||"";if(t&&t.required&&!A){throw new Error(`Input required and not supplied: ${e}`)}if(t&&t.trimWhitespace===false){return A}return A.trim()}t.getInput=getInput;function getMultilineInput(e,t){const A=getInput(e,t).split("\n").filter((e=>e!==""));if(t&&t.trimWhitespace===false){return A}return A.map((e=>e.trim()))}t.getMultilineInput=getMultilineInput;function getBooleanInput(e,t){const A=["true","True","TRUE"];const s=["false","False","FALSE"];const r=getInput(e,t);if(A.includes(r))return true;if(s.includes(r))return false;throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${e}\n`+`Support boolean input list: \`true | True | TRUE | false | False | FALSE\``)}t.getBooleanInput=getBooleanInput;function setOutput(e,t){const A=process.env["GITHUB_OUTPUT"]||"";if(A){return(0,a.issueFileCommand)("OUTPUT",(0,a.prepareKeyValueMessage)(e,t))}process.stdout.write(l.EOL);(0,n.issueCommand)(Line truncated
|
||||
/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */;const escape=e=>e.replace(/\n/g,"%0A").replace(/\r/g,"%0D").replace(/"/g,"%22");const normalizeLinefeeds=e=>e.replace(/\r?\n|\r/g,"\r\n");const s=[];const r=new Uint8Array([13,10]);g=0;let o=false;for(const[t,i]of e){if(typeof i==="string"){const e=F.encode(A+`; name="${escape(normalizeLinefeeds(t))}"`+`\r\n\r\n${normalizeLinefeeds(i)}\r\n`);s.push(e);g+=e.byteLength}else{const e=F.encode(`${A}; name="${escape(normalizeLinefeeds(t))}"`+(i.name?`; filename="${escape(i.name)}"`:"")+"\r\n"+`Content-Type: ${i.type||"application/octet-stream"}\r\n\r\n`);s.push(e,i,r);if(typeof i.size==="number"){g+=e.byteLength+i.size+r.byteLength}else{o=true}}}const i=F.encode(`--${t}--`);s.push(i);g+=i.byteLength;if(o){g=null}l=e;c=async function*(){for(const e of s){if(e.stream){yield*e.stream()}else{yield e}}};h="multipart/form-data; boundary="+t}else if(i(e)){l=e;g=e.size;if(e.type){h=e.type}}else if(typeof e[Symbol.asyncIterator]==="function"){if(t){throw new TypeError("keepalive")}if(r.isDisturbed(e)||e.locked){throw new TypeError("Response body object should not be disturbed or locked")}s=e instanceof D?e:o(e)}if(typeof l==="string"||r.isBuffer(l)){g=Buffer.byteLength(l)}if(c!=null){let t;s=new D({async start(){t=c(e)[Symbol.asyncIterator]()},async pull(e){const{value:A,done:r}=await t.next();if(r){queueMicrotask((()=>{e.close()}))}else{if(!I(s)){e.enqueue(new Uint8Array(A))}}return e.desiredSize>0},async cancel(e){await t.return()},type:undefined})}const u={stream:s,source:l,length:g};return[u,h]}function safelyExtractBody(e,t=false){if(!D){D=A(3774).ReadableStream}if(e instanceof D){B(!r.isDisturbed(e),"The body has already been consumed.");B(!e.locked,"The stream is locked.")}return extractBody(e,t)}function cloneBody(e){const[t,A]=e.stream.tee();const s=d(A,{transfer:[A]});const[,r]=s.tee();e.stream=t;return{stream:r,length:e.length,source:e.source}}async function*consumeBody(e){if(e){if(y(e)){yield e}else{const t=e.stream;if(r.isDisturbed(t)){throw new TypeError("The body has already been consumed.")}if(t.locked){throw new TypeError("The stream is locked.")}t[C]=true;yield*t}}}function throwIfAborted(e){if(e.aborted){throw new E("The operation was aborted.","AbortError")}}function bodyMixinMethods(e){const t={blob(){return specConsumeBody(this,(e=>{let t=bodyMimeType(this);if(t==="failure"){t=""}else if(t){t=R(t)}return new p([e],{type:t})}),e)},arrayBuffer(){return specConsumeBody(this,(e=>new Uint8Array(e).buffer),e)},text(){return specConsumeBody(this,utf8DecodeBytes,e)},json(){return specConsumeBody(this,parseJSONFromBytes,e)},async formData(){u.brandCheck(this,e);throwIfAborted(this[h]);const t=this.headers.get("Content-Type");if(/multipart\/form-data/.test(t)){const e={};for(const[t,A]of this.headers)e[t.toLowerCase()]=A;const t=new g;let A;try{A=new s({headers:e,preservePath:true})}catch(e){throw new E(`${e}`,"AbortError")}A.on("field",((e,A)=>{t.append(e,A)}));A.on("file",((e,A,s,r,o)=>{const i=[];if(r==="base64"||r.toLowerCase()==="base64"){let r="";A.on("data",(e=>{r+=e.toString().replace(/[\r\n]/gm,"");const t=r.length-r.length%4;i.push(Buffer.from(r.slice(0,t),"base64"));r=r.slice(t)}));A.on("end",(()=>{i.push(Buffer.from(r,"base64"));t.append(e,new S(i,s,{type:o}))}))}else{A.on("data",(e=>{i.push(e)}));A.on("end",(()=>{t.append(e,new S(i,s,{type:o}))}))}}));const r=new Promise(((e,t)=>{A.on("finish",e);A.on("error",(e=>t(new TypeError(e))))}));if(this.body!==null)for await(const e of consumeBody(this[h].body))A.write(e);A.end();await r;return t}else if(/application\/x-www-form-urlencoded/.test(t)){let e;try{let t="";const A=new TextDecoder("utf-8",{ignoreBOM:true});for await(const e of consumeBody(this[h].body)){if(!y(e)){throw new TypeError("Expected Uint8Array chunk")}t+=A.decode(e,{stream:true})}t+=A.decode();e=new URLSearchParams(t)}catch(e){throw Object.assign(new TypeError,{cause:e})}const t=new g;for(const[A,s]of e){t.append(A,s)}return t}else{await Promise.resolve();throwIfAborted(this[h]);throw u.errors.exception({header:`${e.name}.formData`,message:"Could not parse content as FormData."})}}};return t}function mixinBody(e){Object.assign(e.prototype,bodyMixinMethods(e))}async function specConsumeBody(e,t,A){u.brandCheck(e,A);throwIfAborted(e[h]);if(bodyUnusable(e[h].body)){throw new TypeError("Body is unusable")}const s=c();const errorSteps=e=>s.reject(e);const successSteps=e=>{try{s.resolve(t(e))}catch(e){errorSteps(e)}};if(e[h].body==null){successSteps(new Uint8Array);return s.promise}await l(e[h].body,successSteps,errorSteps);return s.promise}function bodyUnusable(e){return e!=null&&(e.stream.locked||r.isDisturbed(e.stream))}function utf8DecodeBytes(e){if(e.length===0){return""}if(e[0]===239&&e[1]===187&&e[2]===191){e=e.subarray(3)}const t=v.decode(e);return t}function parseJSONFromBytes(e){return JSON.parse(utf8DecodeBytes(e))}function bodyMimeType(e){const{headersList:t}=e[h];const A=t.get("content-Line truncated
|
||||
/*! ws. MIT License. Einar Otto Stangvik <einaros@gmail.com> */o[r-4]=this.maskKey[0];o[r-3]=this.maskKey[1];o[r-2]=this.maskKey[2];o[r-1]=this.maskKey[3];o[1]=A;if(A===126){o.writeUInt16BE(t,2)}else if(A===127){o[2]=o[3]=0;o.writeUIntBE(t,4,6)}o[1]|=128;for(let e=0;e<t;e++){o[r+e]=this.frameData[e]^this.maskKey[e%4]}return o}}e.exports={WebsocketFrameSend:WebsocketFrameSend}},3171:(e,t,A)=>{"use strict";const{Writable:s}=A(2203);const r=A(1637);const{parserStates:o,opcodes:i,states:n,emptyBuffer:a}=A(5913);const{kReadyState:c,kSentClose:l,kResponse:g,kReceivedClose:h}=A(2933);const{isValidStatusCode:u,failWebsocketConnection:E,websocketMessageReceived:d}=A(3574);const{WebsocketFrameSend:p}=A(1237);const Q={};Q.ping=r.channel("undici:websocket:ping");Q.pong=r.channel("undici:websocket:pong");class ByteParser extends s{#i=[];#n=0;#a=o.INFO;#c={};#l=[];constructor(e){super();this.ws=e}_write(e,t,A){this.#i.push(e);this.#n+=e.length;this.run(A)}run(e){while(true){if(this.#a===o.INFO){if(this.#n<2){return e()}const t=this.consume(2);this.#c.fin=(t[0]&128)!==0;this.#c.opcode=t[0]&15;this.#c.originalOpcode??=this.#c.opcode;this.#c.fragmented=!this.#c.fin&&this.#c.opcode!==i.CONTINUATION;if(this.#c.fragmented&&this.#c.opcode!==i.BINARY&&this.#c.opcode!==i.TEXT){E(this.ws,"Invalid frame type was fragmented.");return}const A=t[1]&127;if(A<=125){this.#c.payloadLength=A;this.#a=o.READ_DATA}else if(A===126){this.#a=o.PAYLOADLENGTH_16}else if(A===127){this.#a=o.PAYLOADLENGTH_64}if(this.#c.fragmented&&A>125){E(this.ws,"Fragmented frame exceeded 125 bytes.");return}else if((this.#c.opcode===i.PING||this.#c.opcode===i.PONG||this.#c.opcode===i.CLOSE)&&A>125){E(this.ws,"Payload length for control frame exceeded 125 bytes.");return}else if(this.#c.opcode===i.CLOSE){if(A===1){E(this.ws,"Received close frame with a 1-byte body.");return}const e=this.consume(A);this.#c.closeInfo=this.parseCloseBody(false,e);if(!this.ws[l]){const e=Buffer.allocUnsafe(2);e.writeUInt16BE(this.#c.closeInfo.code,0);const t=new p(e);this.ws[g].socket.write(t.createFrame(i.CLOSE),(e=>{if(!e){this.ws[l]=true}}))}this.ws[c]=n.CLOSING;this.ws[h]=true;this.end();return}else if(this.#c.opcode===i.PING){const t=this.consume(A);if(!this.ws[h]){const e=new p(t);this.ws[g].socket.write(e.createFrame(i.PONG));if(Q.ping.hasSubscribers){Q.ping.publish({payload:t})}}this.#a=o.INFO;if(this.#n>0){continue}else{e();return}}else if(this.#c.opcode===i.PONG){const t=this.consume(A);if(Q.pong.hasSubscribers){Q.pong.publish({payload:t})}if(this.#n>0){continue}else{e();return}}}else if(this.#a===o.PAYLOADLENGTH_16){if(this.#n<2){return e()}const t=this.consume(2);this.#c.payloadLength=t.readUInt16BE(0);this.#a=o.READ_DATA}else if(this.#a===o.PAYLOADLENGTH_64){if(this.#n<8){return e()}const t=this.consume(8);const A=t.readUInt32BE(0);if(A>2**31-1){E(this.ws,"Received payload length > 2^31 bytes.");return}const s=t.readUInt32BE(4);this.#c.payloadLength=(A<<8)+s;this.#a=o.READ_DATA}else if(this.#a===o.READ_DATA){if(this.#n<this.#c.payloadLength){return e()}else if(this.#n>=this.#c.payloadLength){const e=this.consume(this.#c.payloadLength);this.#l.push(e);if(!this.#c.fragmented||this.#c.fin&&this.#c.opcode===i.CONTINUATION){const e=Buffer.concat(this.#l);d(this.ws,this.#c.originalOpcode,e);this.#c={};this.#l.length=0}this.#a=o.INFO}}if(this.#n>0){continue}else{e();break}}}consume(e){if(e>this.#n){return null}else if(e===0){return a}if(this.#i[0].length===e){this.#n-=this.#i[0].length;return this.#i.shift()}const t=Buffer.allocUnsafe(e);let A=0;while(A!==e){const s=this.#i[0];const{length:r}=s;if(r+A===e){t.set(this.#i.shift(),A);break}else if(r+A>e){t.set(s.subarray(0,e-A),A);this.#i[0]=s.subarray(e-A);break}else{t.set(this.#i.shift(),A);A+=s.length}}this.#n-=e;return t}parseCloseBody(e,t){let A;if(t.length>=2){A=t.readUInt16BE(0)}if(e){if(!u(A)){return null}return{code:A}}let s=t.subarray(2);if(s[0]===239&&s[1]===187&&s[2]===191){s=s.subarray(3)}if(A!==undefined&&!u(A)){return null}try{s=new TextDecoder("utf-8",{fatal:true}).decode(s)}catch{return null}return{code:A,reason:s}}get closingInfo(){return this.#c.closeInfo}}e.exports={ByteParser:ByteParser}},2933:e=>{"use strict";e.exports={kWebSocketURL:Symbol("url"),kReadyState:Symbol("ready state"),kController:Symbol("controller"),kResponse:Symbol("response"),kBinaryType:Symbol("binary type"),kSentClose:Symbol("sent close"),kReceivedClose:Symbol("received close"),kByteParser:Symbol("byte parser")}},3574:(e,t,A)=>{"use strict";const{kReadyState:s,kController:r,kResponse:o,kBinaryType:i,kWebSocketURL:n}=A(2933);const{states:a,opcodes:c}=A(5913);const{MessageEvent:l,ErrorEvent:g}=A(6255);function isEstablished(e){return e[s]===a.OPEN}function isClosing(e){return e[s]===a.CLOSING}function isClosed(e){return e[s]===a.CLOSED}function fireEvent(e,t,A=Event,s){const r=new A(e,s);t.dispatchEvent(r)}function websocketMessageReceived(e,t,A){if(e[s]!==a.OPEN){return}let r;if(t===c.TEXT){try{r=new TextDecoder("utf-8",{fatal:true}).decode(A)Line truncated
|
||||
/*! ws. MIT License. Einar Otto Stangvik <einaros@gmail.com> */o[r-4]=this.maskKey[0];o[r-3]=this.maskKey[1];o[r-2]=this.maskKey[2];o[r-1]=this.maskKey[3];o[1]=A;if(A===126){o.writeUInt16BE(t,2)}else if(A===127){o[2]=o[3]=0;o.writeUIntBE(t,4,6)}o[1]|=128;for(let e=0;e<t;e++){o[r+e]=this.frameData[e]^this.maskKey[e%4]}return o}}e.exports={WebsocketFrameSend:WebsocketFrameSend}},3171:(e,t,A)=>{"use strict";const{Writable:s}=A(2203);const r=A(1637);const{parserStates:o,opcodes:i,states:n,emptyBuffer:a}=A(5913);const{kReadyState:c,kSentClose:l,kResponse:g,kReceivedClose:h}=A(2933);const{isValidStatusCode:u,failWebsocketConnection:E,websocketMessageReceived:d}=A(3574);const{WebsocketFrameSend:p}=A(1237);const Q={};Q.ping=r.channel("undici:websocket:ping");Q.pong=r.channel("undici:websocket:pong");class ByteParser extends s{#i=[];#n=0;#a=o.INFO;#c={};#l=[];constructor(e){super();this.ws=e}_write(e,t,A){this.#i.push(e);this.#n+=e.length;this.run(A)}run(e){while(true){if(this.#a===o.INFO){if(this.#n<2){return e()}const t=this.consume(2);this.#c.fin=(t[0]&128)!==0;this.#c.opcode=t[0]&15;this.#c.originalOpcode??=this.#c.opcode;this.#c.fragmented=!this.#c.fin&&this.#c.opcode!==i.CONTINUATION;if(this.#c.fragmented&&this.#c.opcode!==i.BINARY&&this.#c.opcode!==i.TEXT){E(this.ws,"Invalid frame type was fragmented.");return}const A=t[1]&127;if(A<=125){this.#c.payloadLength=A;this.#a=o.READ_DATA}else if(A===126){this.#a=o.PAYLOADLENGTH_16}else if(A===127){this.#a=o.PAYLOADLENGTH_64}if(this.#c.fragmented&&A>125){E(this.ws,"Fragmented frame exceeded 125 bytes.");return}else if((this.#c.opcode===i.PING||this.#c.opcode===i.PONG||this.#c.opcode===i.CLOSE)&&A>125){E(this.ws,"Payload length for control frame exceeded 125 bytes.");return}else if(this.#c.opcode===i.CLOSE){if(A===1){E(this.ws,"Received close frame with a 1-byte body.");return}const e=this.consume(A);this.#c.closeInfo=this.parseCloseBody(false,e);if(!this.ws[l]){const e=Buffer.allocUnsafe(2);e.writeUInt16BE(this.#c.closeInfo.code,0);const t=new p(e);this.ws[g].socket.write(t.createFrame(i.CLOSE),(e=>{if(!e){this.ws[l]=true}}))}this.ws[c]=n.CLOSING;this.ws[h]=true;this.end();return}else if(this.#c.opcode===i.PING){const t=this.consume(A);if(!this.ws[h]){const e=new p(t);this.ws[g].socket.write(e.createFrame(i.PONG));if(Q.ping.hasSubscribers){Q.ping.publish({payload:t})}}this.#a=o.INFO;if(this.#n>0){continue}else{e();return}}else if(this.#c.opcode===i.PONG){const t=this.consume(A);if(Q.pong.hasSubscribers){Q.pong.publish({payload:t})}if(this.#n>0){continue}else{e();return}}}else if(this.#a===o.PAYLOADLENGTH_16){if(this.#n<2){return e()}const t=this.consume(2);this.#c.payloadLength=t.readUInt16BE(0);this.#a=o.READ_DATA}else if(this.#a===o.PAYLOADLENGTH_64){if(this.#n<8){return e()}const t=this.consume(8);const A=t.readUInt32BE(0);if(A>2**31-1){E(this.ws,"Received payload length > 2^31 bytes.");return}const s=t.readUInt32BE(4);this.#c.payloadLength=(A<<8)+s;this.#a=o.READ_DATA}else if(this.#a===o.READ_DATA){if(this.#n<this.#c.payloadLength){return e()}else if(this.#n>=this.#c.payloadLength){const e=this.consume(this.#c.payloadLength);this.#l.push(e);if(!this.#c.fragmented||this.#c.fin&&this.#c.opcode===i.CONTINUATION){const e=Buffer.concat(this.#l);d(this.ws,this.#c.originalOpcode,e);this.#c={};this.#l.length=0}this.#a=o.INFO}}if(this.#n>0){continue}else{e();break}}}consume(e){if(e>this.#n){return null}else if(e===0){return a}if(this.#i[0].length===e){this.#n-=this.#i[0].length;return this.#i.shift()}const t=Buffer.allocUnsafe(e);let A=0;while(A!==e){const s=this.#i[0];const{length:r}=s;if(r+A===e){t.set(this.#i.shift(),A);break}else if(r+A>e){t.set(s.subarray(0,e-A),A);this.#i[0]=s.subarray(e-A);break}else{t.set(this.#i.shift(),A);A+=s.length}}this.#n-=e;return t}parseCloseBody(e,t){let A;if(t.length>=2){A=t.readUInt16BE(0)}if(e){if(!u(A)){return null}return{code:A}}let s=t.subarray(2);if(s[0]===239&&s[1]===187&&s[2]===191){s=s.subarray(3)}if(A!==undefined&&!u(A)){return null}try{s=new TextDecoder("utf-8",{fatal:true}).decode(s)}catch{return null}return{code:A,reason:s}}get closingInfo(){return this.#c.closeInfo}}e.exports={ByteParser:ByteParser}},2933:e=>{"use strict";e.exports={kWebSocketURL:Symbol("url"),kReadyState:Symbol("ready state"),kController:Symbol("controller"),kResponse:Symbol("response"),kBinaryType:Symbol("binary type"),kSentClose:Symbol("sent close"),kReceivedClose:Symbol("received close"),kByteParser:Symbol("byte parser")}},3574:(e,t,A)=>{"use strict";const{kReadyState:s,kController:r,kResponse:o,kBinaryType:i,kWebSocketURL:n}=A(2933);const{states:a,opcodes:c}=A(5913);const{MessageEvent:l,ErrorEvent:g}=A(6255);function isEstablished(e){return e[s]===a.OPEN}function isClosing(e){return e[s]===a.CLOSING}function isClosed(e){return e[s]===a.CLOSED}function fireEvent(e,t,A=Event,s){const r=new A(e,s);t.dispatchEvent(r)}function websocketMessageReceived(e,t,A){if(e[s]!==a.OPEN){return}let r;if(t===c.TEXT){try{r=new TextDecoder("utf-8",{fatal:true}).decode(A)Line truncated
|
||||
Reference in new issue
Block a user