UNPKG

@h4ad/serverless-adapter

Version:

Run REST APIs and other web applications using your existing Node.js application framework (NestJS, Express, Koa, Hapi, Fastify and many others), on top of AWS, Azure, Digital Ocean and many other clouds.

7 lines 3.89 kB
"use strict";var c=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var n=(t,e)=>c(t,"name",{value:e,configurable:!0});var w=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},b=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of T(e))!A.call(t,o)&&o!==r&&c(t,o,{get:()=>e[o],enumerable:!(s=E(e,o))||s.enumerable});return t};var C=t=>b(c({},"__esModule",{value:!0}),t);var _={};w(_,{LazyFramework:()=>m});module.exports=C(_);var k=require("http");var v=require("http");function l(t){if(Buffer.isBuffer(t))return t.toString("utf8");if(typeof t=="string")return t;if(t instanceof Uint8Array)return new TextDecoder().decode(t);throw new Error(`response.write() of unexpected type: ${typeof t}`)}n(l,"getString");var S=`\r \r `,L=`0\r \r `,u=Symbol("Response body"),d=Symbol("Response headers");function g(t,e){if(Buffer.isBuffer(e)||typeof e=="string"||e instanceof Uint8Array)t[u].push(Buffer.from(e));else throw new Error(`response.write() of unexpected type: ${typeof e}`)}n(g,"addData");var y=class t extends v.ServerResponse{static{n(this,"ServerlessResponse")}constructor({method:e}){super({method:e}),this[u]=[],this[d]={},this.useChunkedEncodingByDefault=!1,this.chunkedEncoding=!1,this._header="";let r=1,s={_writableState:{},writable:!0,on:i,removeListener:i,destroy:i,cork:i,uncork:i,write:n((o,f,a)=>{if(typeof f=="function"&&(a=f,f=null),this._header===""||this._wroteHeader)this.chunkedEncoding?r>0?r--:o!==L&&(g(this,o),r=3):g(this,o);else{let p=l(o),h=p.indexOf(S);if(h!==-1){let x=p.slice(h+S.length);x&&!this.chunkedEncoding&&g(this,x),this._wroteHeader=!0}}typeof a=="function"&&a()},"write")};this.assignSocket(s)}_header;_headers;_wroteHeader;[u];[d];get headers(){return this[d]}static from(e){let r=new t({method:e.method});return r.statusCode=e.statusCode||0,r[d]=e.headers,r[u]=e.body?[Buffer.from(e.body)]:[],r.end(),r}static body(e){return Buffer.concat(e[u])}static headers(e){let r=e.getHeaders();return Object.assign(r,e[d])}setHeader(e,r){this._wroteHeader?this[d][e]=r:super.setHeader(e,r)}writeHead(e,r,s){let o=typeof r=="string"?s:r,f=Array.isArray(o)?o:[o||{}];for(let a of f)for(let p in a)if(this.setHeader(p,a[p]),!this._wroteHeader)break;return this.callNativeWriteHead(e,r,s)}callNativeWriteHead(e,r,s){return super.writeHead(e,r,s)}};var B=require("http");var Z=Buffer.from(`\r `);var i=n(()=>{},"NO_OP");var H=Symbol("InternalLogger"),I={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:[]},O=n(t=>typeof t=="function"?t():t,"lazyPrint"),P=n(t=>(e,...r)=>console[t](e,...r.map(O)),"print");function R({level:t}={level:"error"}){let e=I[t];if(!e)throw new Error("Invalid log level");let r={[H]:!0,error:i,debug:i,info:i,verbose:i,warn:i};for(let[s,o]of e)r[s]=P(o);return r}n(R,"createDefaultLogger");var be=require("stream");var m=class{constructor(e,r,s=R()){this.framework=e;this.factory=r;this.logger=s;this.delayedFactory=Promise.resolve().then(()=>r()).then(o=>{this.cachedApp=o}).catch(o=>{this.logger.error("SERVERLESS_ADAPTER:LAZY_FRAMEWORK: An error occours during the creation of your app."),this.logger.error(o)})}static{n(this,"LazyFramework")}cachedApp;delayedFactory;sendRequest(e,r,s){if(this.cachedApp)return this.framework.sendRequest(this.cachedApp,r,s);this.delayedFactory.then(()=>this.cachedApp?this.framework.sendRequest(this.cachedApp,r,s):s.emit("error",new Error("SERVERLESS_ADAPTER:LAZY_FRAMEWORK: The instance of the app returned by the factory is not valid, see the logs to learn more.")))}};0&&(module.exports={LazyFramework}); //# sourceMappingURL=index.cjs.map