"use strict";var T=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var s=(r,e)=>T(r,"name",{value:e,configurable:!0});var $=(r,e)=>{for(var t in e)T(r,t,{get:e[t],enumerable:!0})},G=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of q(e))!Y.call(r,o)&&o!==t&&T(r,o,{get:()=>e[o],enumerable:!(n=M(e,o))||n.enumerable});return r};var z=r=>G(T({},"__esModule",{value:!0}),r);var ye={};$(ye,{BaseHandler:()=>R,DEFAULT_BINARY_CONTENT_TYPES:()=>S,DEFAULT_BINARY_ENCODINGS:()=>v,EmptyResponse:()=>Q,NO_OP:()=>p,ServerlessAdapter:()=>k,ServerlessRequest:()=>c,ServerlessResponse:()=>g,ServerlessStreamResponse:()=>C,buildStripBasePath:()=>le,createDefaultLogger:()=>b,getContentType:()=>I,getCurrentInvoke:()=>J,getDefaultIfUndefined:()=>ae,getEventBodyAsBuffer:()=>Z,getFlattenedHeadersMap:()=>K,getFlattenedHeadersMapAndCookies:()=>re,getMultiValueHeadersMap:()=>ee,getPathWithQueryStringParams:()=>pe,getQueryParamsStringFromRecord:()=>_,getString:()=>h,isBinary:()=>te,isContentEncodingBinary:()=>H,isContentTypeBinary:()=>O,isInternalLogger:()=>ie,isStreamEnded:()=>D,parseHeaders:()=>A,setCurrentInvoke:()=>X,waitForStreamComplete:()=>ue});module.exports=z(ye);var V=require("http");var R=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 c({method:e.method,headers:e.headers,body:e.body,remoteAddress:e.remoteAddress,url:e.path}),n=new g({method:e.method});return[t,n]}};var v=["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"],Q={};var x={context:null,event:null};function J(){return x}s(J,"getCurrentInvoke");function X({event:r,context:e}){x.event=r,x.context=e}s(X,"setCurrentInvoke");function Z(r,e){let t=e?"base64":"utf8",n=Buffer.from(r,t),o=Buffer.byteLength(n,t);return[n,o]}s(Z,"getEventBodyAsBuffer");function K(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(K,"getFlattenedHeadersMap");function ee(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(ee,"getMultiValueHeadersMap");function re(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(re,"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 H(r,e){let t=r["content-encoding"];return t?(Array.isArray(t)||(t=t.split(",")),t.some(n=>e.includes(n.trim()))):!1}s(H,"isContentEncodingBinary");function I(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(I,"getContentType");function O(r,e){let t=I(r);return t?e.includes(t.trim()):!1}s(O,"isContentTypeBinary");function te(r,e){return"isBinary"in e?e.isBinary===!1?!1:e.isBinary(r):H(r,e.contentEncodings)||O(r,e.contentTypes)}s(te,"isBinary");var p=s(()=>{},"NO_OP");var P=Symbol("InternalLogger"),ne={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:[]},oe=s(r=>typeof r=="function"?r():r,"lazyPrint"),se=s(r=>(e,...t)=>console[r](e,...t.map(oe)),"print");function b({level:r}={level:"error"}){let e=ne[r];if(!e)throw new Error("Invalid log level");let t={[P]:!0,error:p,debug:p,info:p,verbose:p,warn:p};for(let[n,o]of e)t[n]=se(o);return t}s(b,"createDefaultLogger");function ie(r){return!!r[P]}s(ie,"isInternalLogger");function ae(r,e){return r===void 0?e:r}s(ae,"getDefaultIfUndefined");function pe(r,e){if(String(e||"").length===0)return r;if(typeof e=="string")return`${r}?${e}`;let t=_(e);return t?`${r}?${t}`:r}s(pe,"getPathWithQueryStringParams");function _(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(_,"getQueryParamsStringFromRecord");var de=s(r=>r,"NOOPBasePath");function le(r){if(!r)return de;let e=r.length;return t=>t.startsWith(r)?t.slice(t.indexOf(r)+e,t.length)||"/":t}s(le,"buildStripBasePath");var Me=require("stream");function D(r){return!!("readableEnded"in r&&r.readableEnded||"writableEnded"in r&&r.writableEnded)}s(D,"isStreamEnded");function ue(r){return D(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(ue,"waitForStreamComplete");var fe=443,c=class extends V.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:fe}),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 N=require("http");function h(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(h,"getString");var F=`\r \r `,ce=`0\r \r `,m=Symbol("Response body"),f=Symbol("Response headers");function w(r,e){if(Buffer.isBuffer(e)||typeof e=="string"||e instanceof Uint8Array)r[m].push(Buffer.from(e));else throw new Error(`response.write() of unexpected type: ${typeof e}`)}s(w,"addData");var g=class r extends N.ServerResponse{static{s(this,"ServerlessResponse")}constructor({method:e}){super({method:e}),this[m]=[],this[f]={},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!==ce&&(w(this,o),t=3):w(this,o);else{let d=h(o),l=d.indexOf(F);if(l!==-1){let u=d.slice(l+F.length);u&&!this.chunkedEncoding&&w(this,u),this._wroteHeader=!0}}typeof a=="function"&&a()}};this.assignSocket(n)}_header;_headers;_wroteHeader;[m];[f];get headers(){return this[f]}static from(e){let t=new r({method:e.method});return t.statusCode=e.statusCode||0,t[f]=e.headers,t[m]=e.body?[Buffer.from(e.body)]:[],t.end(),t}static body(e){return Buffer.concat(e[m])}static headers(e){let t=e.getHeaders();return Object.assign(t,e[f])}setHeader(e,t){this._wroteHeader?this[f][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 W=require("http");var ge=`0\r \r `,he=`\r \r `,me=`\r `,C=class extends W.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=!0,a=0,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})),!i&&o){if(l===ge)return o.end(E),!0;if(a>0)return a--,!0;o.write(l,E),a=3}else if(i){i=!1;let y=h(l),L=y.indexOf(me),U=+y.slice(0,L).split(" ")[1],j=y.slice(L+2,y.indexOf(he)),B=A(j);n.debug("SERVERLESS_ADAPTER:RESPONSE_STREAM:FRAMEWORK_HEADERS",{headers:B}),a=1,o=t(U,B)}return!0}};this.assignSocket(d)}};var k=class r{static{s(this,"ServerlessAdapter")}constructor(e){this.app=e}app;binarySettings={contentEncodings:v,contentTypes:S};respondWithErrors=process.env.NODE_ENV==="development";log=b();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,parseHeaders,setCurrentInvoke,waitForStreamComplete}); //# sourceMappingURL=index.cjs.map