"use strict";var T=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var s=(r,e)=>T(r,"name",{value:e,configurable:!0});var K=(r,e)=>{for(var t in e)T(r,t,{get:e[t],enumerable:!0})},z=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of $(e))!G.call(r,o)&&o!==t&&T(r,o,{get:()=>e[o],enumerable:!(n=Y(e,o))||n.enumerable});return r};var Q=r=>z(T({},"__esModule",{value:!0}),r);var Re={};K(Re,{BaseHandler:()=>v,DEFAULT_BINARY_CONTENT_TYPES:()=>S,DEFAULT_BINARY_ENCODINGS:()=>x,EmptyResponse:()=>J,NO_OP:()=>p,ServerlessAdapter:()=>L,ServerlessRequest:()=>g,ServerlessResponse:()=>h,ServerlessStreamResponse:()=>k,buildStripBasePath:()=>ce,createDefaultLogger:()=>w,getContentType:()=>O,getCurrentInvoke:()=>X,getDefaultIfUndefined:()=>le,getEventBodyAsBuffer:()=>ee,getFlattenedHeadersMap:()=>re,getFlattenedHeadersMapAndCookies:()=>ne,getMultiValueHeadersMap:()=>te,getPathWithQueryStringParams:()=>ue,getQueryParamsStringFromRecord:()=>D,getString:()=>m,isBinary:()=>se,isContentEncodingBinary:()=>I,isContentTypeBinary:()=>P,isInternalLogger:()=>de,isStreamEnded:()=>V,keysToLowercase:()=>oe,parseHeaders:()=>A,setCurrentInvoke:()=>Z,waitForStreamComplete:()=>ge});module.exports=Q(Re);var N=require("http");var v=class{static{s(this,"BaseHandler")}getAdapterByEventAndContext(e,t,n,o){let i=n.filter(a=>a.canHandle(e,t,o));if(i.length===0)throw new Error("SERVERLESS_ADAPTER: Couldn't find adapter to handle this event.");if(i.length>1)throw new Error(`SERVERLESS_ADAPTER: Two or more adapters was resolved by the event, the adapters are: ${n.map(a=>a.getAdapterName()).join(", ")}.`);return i[0]}getServerlessRequestResponseFromAdapterRequest(e){let t=new g({method:e.method,headers:e.headers,body:e.body,remoteAddress:e.remoteAddress,url:e.path}),n=new h({method:e.method});return[t,n]}};var x=["gzip","deflate","br"],S=["image/png","image/jpeg","image/jpg","image/avif","image/bmp","image/x-png","image/gif","image/webp","video/mp4","application/pdf"],J={};var b={context:null,event:null};function X(){return b}s(X,"getCurrentInvoke");function Z({event:r,context:e}){b.event=r,b.context=e}s(Z,"setCurrentInvoke");function ee(r,e){let t=e?"base64":"utf8",n=Buffer.from(r,t),o=Buffer.byteLength(n,t);return[n,o]}s(ee,"getEventBodyAsBuffer");function re(r,e=",",t=!1){return Object.keys(r).reduce((n,o)=>{let i=t?o.toLowerCase():o,a=r[o];return Array.isArray(a)?n[i]=a.join(e):n[i]=(a??"")+"",n},{})}s(re,"getFlattenedHeadersMap");function te(r){return Object.keys(r).reduce((e,t)=>{let n=r[t];return e[t.toLowerCase()]=Array.isArray(n)?n.map(String):[String(n)],e},{})}s(te,"getMultiValueHeadersMap");function ne(r){return Object.keys(r).reduce((e,t)=>{let n=r[t],o=t.toLowerCase();return Array.isArray(n)?o!=="set-cookie"?e.headers[t]=n.join(","):e.cookies.push(...n):o==="set-cookie"&&n!==void 0?e.cookies.push(n??""):e.headers[t]=String(n??""),e},{cookies:[],headers:{}})}s(ne,"getFlattenedHeadersMapAndCookies");function A(r){if(!r)return{};let e={},t=r.trim().split(` `);for(let n=0;n"u"?e[a]=d:Array.isArray(e[a])?e[a].push(d):e[a]=[e[a],d]}return e}s(A,"parseHeaders");function oe(r){let e={};for(let[t,n]of Object.entries(r))e[t.toLowerCase()]=n;return e}s(oe,"keysToLowercase");function I(r,e){let t=r["content-encoding"];return t?(Array.isArray(t)||(t=t.split(",")),t.some(n=>e.includes(n.trim()))):!1}s(I,"isContentEncodingBinary");function O(r){let e=r["content-type"],t=Array.isArray(e)?e[0]||"":e||"";if(!e)return"";let n=t.indexOf(";");return n===-1?t:t.slice(0,n)}s(O,"getContentType");function P(r,e){let t=O(r);return t?e.includes(t.trim()):!1}s(P,"isContentTypeBinary");function se(r,e){return"isBinary"in e?e.isBinary===!1?!1:e.isBinary(r):I(r,e.contentEncodings)||P(r,e.contentTypes)}s(se,"isBinary");var p=s(()=>{},"NO_OP");var _=Symbol("InternalLogger"),ie={debug:[["debug","debug"],["verbose","debug"],["info","info"],["error","error"],["warn","warn"]],verbose:[["verbose","debug"],["info","info"],["error","error"],["warn","warn"]],info:[["info","info"],["error","error"],["warn","warn"]],warn:[["warn","warn"],["error","error"]],error:[["error","error"]],none:[]},ae=s(r=>typeof r=="function"?r():r,"lazyPrint"),pe=s(r=>(e,...t)=>console[r](e,...t.map(ae)),"print");function w({level:r}={level:"error"}){let e=ie[r];if(!e)throw new Error("Invalid log level");let t={[_]:!0,error:p,debug:p,info:p,verbose:p,warn:p};for(let[n,o]of e)t[n]=pe(o);return t}s(w,"createDefaultLogger");function de(r){return!!r[_]}s(de,"isInternalLogger");function le(r,e){return r===void 0?e:r}s(le,"getDefaultIfUndefined");function ue(r,e){if(String(e||"").length===0)return r;if(typeof e=="string")return`${r}?${e}`;let t=D(e);return t?`${r}?${t}`:r}s(ue,"getPathWithQueryStringParams");function D(r){let e=new URLSearchParams,t=Object.entries(r||{});if(t.length===0)return"";for(let[n,o]of t){if(!Array.isArray(o)){e.append(n,o||"");continue}for(let i of o)e.append(n,i)}return e.toString()}s(D,"getQueryParamsStringFromRecord");var fe=s(r=>r,"NOOPBasePath");function ce(r){if(!r)return fe;let e=r.length;return t=>t.startsWith(r)?t.slice(t.indexOf(r)+e,t.length)||"/":t}s(ce,"buildStripBasePath");var Ge=require("stream");function V(r){return!!("readableEnded"in r&&r.readableEnded||"writableEnded"in r&&r.writableEnded)}s(V,"isStreamEnded");function ge(r){return V(r)?Promise.resolve(r):new Promise((e,t)=>{let n=!1;function o(i){n||(n=!0,r.removeListener("error",o),r.removeListener("end",o),r.removeListener("finish",o),i?t(i):e(r))}s(o,"complete"),r.once("error",o),r.once("end",o),r.once("finish",o)})}s(ge,"waitForStreamComplete");var he=443,g=class extends N.IncomingMessage{static{s(this,"ServerlessRequest")}constructor({method:e,url:t,headers:n,body:o,remoteAddress:i}){super({encrypted:!0,readable:!1,remoteAddress:i,address:()=>({port:he}),end:p,destroy:p}),this.statusCode=200,this.statusMessage="OK",this.complete=!0,this.httpVersion="1.1",this.httpVersionMajor=1,this.httpVersionMinor=1,this.method=e,this.headers=n,this.body=o,this.url=t,this.ip=i,this._read=()=>{this.push(o),this.push(null)}}ip;body};var W=require("http");function m(r){if(Buffer.isBuffer(r))return r.toString("utf8");if(typeof r=="string")return r;if(r instanceof Uint8Array)return new TextDecoder().decode(r);throw new Error(`response.write() of unexpected type: ${typeof r}`)}s(m,"getString");var F=`\r \r `,me=`0\r \r `,y=Symbol("Response body"),c=Symbol("Response headers");function C(r,e){if(Buffer.isBuffer(e)||typeof e=="string"||e instanceof Uint8Array)r[y].push(Buffer.from(e));else throw new Error(`response.write() of unexpected type: ${typeof e}`)}s(C,"addData");var h=class r extends W.ServerResponse{static{s(this,"ServerlessResponse")}constructor({method:e}){super({method:e}),this[y]=[],this[c]={},this.useChunkedEncodingByDefault=!1,this.chunkedEncoding=!1,this._header="";let t=1,n={_writableState:{},writable:!0,on:p,removeListener:p,destroy:p,cork:p,uncork:p,write:(o,i,a)=>{if(typeof i=="function"&&(a=i,i=null),this._header===""||this._wroteHeader)this.chunkedEncoding?t>0?t--:o!==me&&(C(this,o),t=3):C(this,o);else{let d=m(o),l=d.indexOf(F);if(l!==-1){let u=d.slice(l+F.length);u&&!this.chunkedEncoding&&C(this,u),this._wroteHeader=!0}}typeof a=="function"&&a()}};this.assignSocket(n)}_header;_headers;_wroteHeader;[y];[c];get headers(){return this[c]}static from(e){let t=new r({method:e.method});return t.statusCode=e.statusCode||0,t[c]=e.headers,t[y]=e.body?[Buffer.from(e.body)]:[],t.end(),t}static body(e){return Buffer.concat(e[y])}static headers(e){let t=e.getHeaders();return Object.assign(t,e[c])}setHeader(e,t){this._wroteHeader?this[c][e]=t:super.setHeader(e,t)}writeHead(e,t,n){let o=typeof t=="string"?n:t,i=Array.isArray(o)?o:[o||{}];for(let a of i)for(let d in a)if(this.setHeader(d,a[d]),!this._wroteHeader)break;return this.callNativeWriteHead(e,t,n)}callNativeWriteHead(e,t,n){return super.writeHead(e,t,n)}};var j=require("http");var ye=Buffer.from(`\r `),U=`0\r \r `,Te=`\r \r `,Ee=`\r `,k=class extends j.ServerResponse{static{s(this,"ServerlessStreamResponse")}constructor({method:e,onReceiveHeaders:t,log:n}){super({method:e}),this.useChunkedEncodingByDefault=!0,this.chunkedEncoding=!0;let o=null,i=!1,a=!1,d={_writableState:{},writable:!0,on:p,removeListener:p,destroy:p,cork:p,uncork:p,write:(l,u,E)=>{if(typeof u=="function"&&(E=u,u=null),n.debug("SERVERLESS_ADAPTER:RESPONSE_STREAM:DATA",()=>({data:Buffer.isBuffer(l)?l.toString("utf8"):l,encoding:u})),!o){let f=m(l),R=f.indexOf(Ee),q=+f.slice(0,R).split(" ")[1],B=f.indexOf(Te),M=f.slice(R+2,B),H=A(M);return n.debug("SERVERLESS_ADAPTER:RESPONSE_STREAM:FRAMEWORK_HEADERS",()=>({headers:H})),o=t(q,H),f.substring(B+4)===U&&o.end(),!0}if(l===U)return o.end(E),!0;if(Buffer.isBuffer(l)&&ye.equals(l)){if(!i)return i=!0,!0;if(i&&a)return i=!1,a=!1,!0}return i&&(a=!0,o.write(l,E)),!0}};this.assignSocket(d)}};var L=class r{static{s(this,"ServerlessAdapter")}constructor(e){this.app=e}app;binarySettings={contentEncodings:x,contentTypes:S};respondWithErrors=process.env.NODE_ENV==="development";log=w();adapters=[];framework;resolver;handler;static new(e){return new r(e)}setHandler(e){if(this.handler)throw new Error("SERVERLESS_ADAPTER: The handler should not set twice.");return this.handler=e,this}setResolver(e){if(this.resolver)throw new Error("SERVERLESS_ADAPTER: The resolver should not set twice.");return this.resolver=e,this}setFramework(e){if(this.framework)throw new Error("SERVERLESS_ADAPTER: The framework should not set twice.");return this.framework=e,this}setLogger(e){return this.log=e,this}setBinarySettings(e){return this.binarySettings={...this.binarySettings,...e},this}setRespondWithErrors(e){return this.respondWithErrors=e,this}addAdapter(e){return this.adapters.push(e),this}build(){if(!this.resolver)throw new Error("SERVERLESS_ADAPTER: Is required to set a resolver before build.");if(!this.framework)throw new Error("SERVERLESS_ADAPTER: Is required to set a framework before build.");if(!this.handler)throw new Error("SERVERLESS_ADAPTER: Is required to set a handler before build.");if(this.adapters.length===0)throw new Error("SERVERLESS_ADAPTER: Is required to set at least one adapter.");return this.handler.getHandler(this.app,this.framework,this.adapters,this.resolver,this.binarySettings,this.respondWithErrors,this.log)}};0&&(module.exports={BaseHandler,DEFAULT_BINARY_CONTENT_TYPES,DEFAULT_BINARY_ENCODINGS,EmptyResponse,NO_OP,ServerlessAdapter,ServerlessRequest,ServerlessResponse,ServerlessStreamResponse,buildStripBasePath,createDefaultLogger,getContentType,getCurrentInvoke,getDefaultIfUndefined,getEventBodyAsBuffer,getFlattenedHeadersMap,getFlattenedHeadersMapAndCookies,getMultiValueHeadersMap,getPathWithQueryStringParams,getQueryParamsStringFromRecord,getString,isBinary,isContentEncodingBinary,isContentTypeBinary,isInternalLogger,isStreamEnded,keysToLowercase,parseHeaders,setCurrentInvoke,waitForStreamComplete}); //# sourceMappingURL=index.cjs.map