yinzerflow 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +6 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import{createRequire as e$}from"node:module";var r$=Object.create;var{getPrototypeOf:s$,defineProperty:V$,getOwnPropertyNames:a$}=Object;var t$=Object.prototype.hasOwnProperty;var E$=($,D,M)=>{M=$!=null?r$(s$($)):{};let _=D||!$||!$.__esModule?V$(M,"default",{value:$,enumerable:!0}):M;for(let R of a$($))if(!t$.call(_,R))V$(_,R,{get:()=>$[R],enumerable:!0});return _};var H$=($,D)=>()=>(D||$((D={exports:{}}).exports,D),D.exports);var N$=e$(import.meta.url);var C$=H$((g$)=>{var J=g$,{Buffer:W$}=N$("buffer"),$1=N$("os");J.toBuffer=function($,D,M){M=~~M;let _;if(this.isV4Format($))_=D||W$.alloc(M+4),$.split(/\./g).map((R)=>{_[M++]=parseInt(R,10)&255});else if(this.isV6Format($)){let R=$.split(":",8),W;for(W=0;W<R.length;W++){let Y=this.isV4Format(R[W]),Z;if(Y)Z=this.toBuffer(R[W]),R[W]=Z.slice(0,2).toString("hex");if(Z&&++W<8)R.splice(W,0,Z.slice(2,4).toString("hex"))}if(R[0]==="")while(R.length<8)R.unshift("0");else if(R[R.length-1]==="")while(R.length<8)R.push("0");else if(R.length<8){for(W=0;W<R.length&&R[W]!=="";W++);let Y=[W,1];for(W=9-R.length;W>0;W--)Y.push("0");R.splice(...Y)}_=D||W$.alloc(M+16);for(W=0;W<R.length;W++){let Y=parseInt(R[W],16);_[M++]=Y>>8&255,_[M++]=Y&255}}if(!_)throw Error(`Invalid ip address: ${$}`);return _};J.toString=function($,D,M){D=~~D,M=M||$.length-D;let _=[];if(M===4){for(let R=0;R<M;R++)_.push($[D+R]);_=_.join(".")}else if(M===16){for(let R=0;R<M;R+=2)_.push($.readUInt16BE(D+R).toString(16));_=_.join(":"),_=_.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3"),_=_.replace(/:{3,4}/,"::")}return _};var D1=/^(\d{1,3}\.){3,3}\d{1,3}$/,M1=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;J.isV4Format=function($){return D1.test($)};J.isV6Format=function($){return M1.test($)};function c($){if($===4)return"ipv4";if($===6)return"ipv6";return $?$.toLowerCase():"ipv4"}J.fromPrefixLen=function($,D){if($>32)D="ipv6";else D=c(D);let M=4;if(D==="ipv6")M=16;let _=W$.alloc(M);for(let R=0,W=_.length;R<W;++R){let Y=8;if($<8)Y=$;$-=Y,_[R]=~(255>>Y)&255}return J.toString(_)};J.mask=function($,D){$=J.toBuffer($),D=J.toBuffer(D);let M=W$.alloc(Math.max($.length,D.length)),_;if($.length===D.length)for(_=0;_<$.length;_++)M[_]=$[_]&D[_];else if(D.length===4)for(_=0;_<D.length;_++)M[_]=$[$.length-4+_]&D[_];else{for(_=0;_<M.length-6;_++)M[_]=0;M[10]=255,M[11]=255;for(_=0;_<$.length;_++)M[_+12]=$[_]&D[_+12];_+=12}for(;_<M.length;_++)M[_]=0;return J.toString(M)};J.cidr=function($){let D=$.split("/"),M=D[0];if(D.length!==2)throw new Error(`invalid CIDR subnet: ${M}`);let _=J.fromPrefixLen(parseInt(D[1],10));return J.mask(M,_)};J.subnet=function($,D){let M=J.toLong(J.mask($,D)),_=J.toBuffer(D),R=0;for(let Y=0;Y<_.length;Y++)if(_[Y]===255)R+=8;else{let Z=_[Y]&255;while(Z)Z=Z<<1&255,R++}let W=2**(32-R);return{networkAddress:J.fromLong(M),firstAddress:W<=2?J.fromLong(M):J.fromLong(M+1),lastAddress:W<=2?J.fromLong(M+W-1):J.fromLong(M+W-2),broadcastAddress:J.fromLong(M+W-1),subnetMask:D,subnetMaskLength:R,numHosts:W<=2?W:W-2,length:W,contains(Y){return M===J.toLong(J.mask(Y,D))}}};J.cidrSubnet=function($){let D=$.split("/"),M=D[0];if(D.length!==2)throw new Error(`invalid CIDR subnet: ${M}`);let _=J.fromPrefixLen(parseInt(D[1],10));return J.subnet(M,_)};J.not=function($){let D=J.toBuffer($);for(let M=0;M<D.length;M++)D[M]=255^D[M];return J.toString(D)};J.or=function($,D){if($=J.toBuffer($),D=J.toBuffer(D),$.length===D.length){for(let W=0;W<$.length;++W)$[W]|=D[W];return J.toString($)}let M=$,_=D;if(D.length>$.length)M=D,_=$;let R=M.length-_.length;for(let W=R;W<M.length;++W)M[W]|=_[W-R];return J.toString(M)};J.isEqual=function($,D){if($=J.toBuffer($),D=J.toBuffer(D),$.length===D.length){for(let _=0;_<$.length;_++)if($[_]!==D[_])return!1;return!0}if(D.length===4){let _=D;D=$,$=_}for(let _=0;_<10;_++)if(D[_]!==0)return!1;let M=D.readUInt16BE(10);if(M!==0&&M!==65535)return!1;for(let _=0;_<4;_++)if($[_]!==D[_+12])return!1;return!0};J.isPrivate=function($){if(J.isLoopback($))return!0;if(!J.isV6Format($)){let D=J.normalizeToLong($);if(D<0)throw new Error("invalid ipv4 address");$=J.fromLong(D)}return/^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test($)||/^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test($)||/^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test($)||/^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test($)||/^f[cd][0-9a-f]{2}:/i.test($)||/^fe80:/i.test($)||/^::1$/.test($)||/^::$/.test($)};J.isPublic=function($){return!J.isPrivate($)};J.isLoopback=function($){if(!/\./.test($)&&!/:/.test($))$=J.fromLong(Number($));return/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test($)||/^0177\./.test($)||/^0x7f\./i.test($)||/^fe80::1$/i.test($)||/^::1$/.test($)||/^::$/.test($)};J.loopback=function($){if($=c($),$!=="ipv4"&&$!=="ipv6")throw new Error("family must be ipv4 or ipv6");return $==="ipv4"?"127.0.0.1":"fe80::1"};J.address=function($,D){let M=$1.networkInterfaces();if(D=c(D),$&&$!=="private"&&$!=="public"){let R=M[$].filter((W)=>{return c(W.family)===D});if(R.length===0)return;return R[0].address}let _=Object.keys(M).map((R)=>{let W=M[R].filter((Y)=>{if(Y.family=c(Y.family),Y.family!==D||J.isLoopback(Y.address))return!1;if(!$)return!0;return $==="public"?J.isPrivate(Y.address):J.isPublic(Y.address)});return W.length?W[0].address:void 0}).filter(Boolean);return!_.length?J.loopback(D):_[0]};J.toLong=function($){let D=0;return $.split(".").forEach((M)=>{D<<=8,D+=parseInt(M)}),D>>>0};J.fromLong=function($){return`${$>>>24}.${$>>16&255}.${$>>8&255}.${$&255}`};J.normalizeToLong=function($){let D=$.split(".").map((R)=>{if(R.startsWith("0x")||R.startsWith("0X"))return parseInt(R,16);else if(R.startsWith("0")&&R!=="0"&&/^[0-7]+$/.test(R))return parseInt(R,8);else if(/^[1-9]\d*$/.test(R)||R==="0")return parseInt(R,10);else return NaN});if(D.some(isNaN))return-1;let M=0;switch(D.length){case 1:M=D[0];break;case 2:if(D[0]>255||D[1]>16777215)return-1;M=D[0]<<24|D[1]&16777215;break;case 3:if(D[0]>255||D[1]>255||D[2]>65535)return-1;M=D[0]<<24|D[1]<<16|D[2]&65535;break;case 4:if(D.some((R)=>R>255))return-1;M=D[0]<<24|D[1]<<16|D[2]<<8|D[3];break;default:return-1}return M>>>0}});var k$=H$((j$,T$)=>{(function($,D){typeof j$=="object"&&typeof T$!="undefined"?T$.exports=D():typeof define=="function"&&define.amd?define(D):($=typeof globalThis!="undefined"?globalThis:$||self).dayjs=D()})(j$,function(){var $=1000,D=60000,M=3600000,_="millisecond",R="second",W="minute",Y="hour",Z="day",G="week",z="month",C="quarter",K="year",S="date",K$="Invalid Date",p$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,c$=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,n$={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(w){var X=["th","st","nd","rd"],O=w%100;return"["+w+(X[(O-20)%10]||X[O]||X[0])+"]"}},z$=function(w,X,O){var U=String(w);return!U||U.length>=X?w:""+Array(X+1-U.length).join(O)+w},o$={s:z$,z:function(w){var X=-w.utcOffset(),O=Math.abs(X),U=Math.floor(O/60),Q=O%60;return(X<=0?"+":"-")+z$(U,2,"0")+":"+z$(Q,2,"0")},m:function w(X,O){if(X.date()<O.date())return-w(O,X);var U=12*(O.year()-X.year())+(O.month()-X.month()),Q=X.clone().add(U,z),F=O-Q<0,B=X.clone().add(U+(F?-1:1),z);return+(-(U+(O-Q)/(F?Q-B:B-Q))||0)},a:function(w){return w<0?Math.ceil(w)||0:Math.floor(w)},p:function(w){return{M:z,y:K,w:G,d:Z,D:S,h:Y,m:W,s:R,ms:_,Q:C}[w]||String(w||"").toLowerCase().replace(/s$/,"")},u:function(w){return w===void 0}},i="en",v={};v[i]=n$;var A$="$isDayjsObject",w$=function(w){return w instanceof _$||!(!w||!w[A$])},M$=function w(X,O,U){var Q;if(!X)return i;if(typeof X=="string"){var F=X.toLowerCase();v[F]&&(Q=F),O&&(v[F]=O,Q=F);var B=X.split("-");if(!Q&&B.length>1)return w(B[0])}else{var T=X.name;v[T]=X,Q=T}return!U&&Q&&(i=Q),Q||!U&&i},P=function(w,X){if(w$(w))return w.clone();var O=typeof X=="object"?X:{};return O.date=w,O.args=arguments,new _$(O)},j=o$;j.l=M$,j.i=w$,j.w=function(w,X){return P(w,{locale:X.$L,utc:X.$u,x:X.$x,$offset:X.$offset})};var _$=function(){function w(O){this.$L=M$(O.locale,null,!0),this.parse(O),this.$x=this.$x||O.x||{},this[A$]=!0}var X=w.prototype;return X.parse=function(O){this.$d=function(U){var{date:Q,utc:F}=U;if(Q===null)return new Date(NaN);if(j.u(Q))return new Date;if(Q instanceof Date)return new Date(Q);if(typeof Q=="string"&&!/Z$/i.test(Q)){var B=Q.match(p$);if(B){var T=B[2]-1||0,A=(B[7]||"0").substring(0,3);return F?new Date(Date.UTC(B[1],T,B[3]||1,B[4]||0,B[5]||0,B[6]||0,A)):new Date(B[1],T,B[3]||1,B[4]||0,B[5]||0,B[6]||0,A)}}return new Date(Q)}(O),this.init()},X.init=function(){var O=this.$d;this.$y=O.getFullYear(),this.$M=O.getMonth(),this.$D=O.getDate(),this.$W=O.getDay(),this.$H=O.getHours(),this.$m=O.getMinutes(),this.$s=O.getSeconds(),this.$ms=O.getMilliseconds()},X.$utils=function(){return j},X.isValid=function(){return this.$d.toString()!==K$},X.isSame=function(O,U){var Q=P(O);return this.startOf(U)<=Q&&Q<=this.endOf(U)},X.isAfter=function(O,U){return P(O)<this.startOf(U)},X.isBefore=function(O,U){return this.endOf(U)<P(O)},X.$g=function(O,U,Q){return j.u(O)?this[U]:this.set(Q,O)},X.unix=function(){return Math.floor(this.valueOf()/1000)},X.valueOf=function(){return this.$d.getTime()},X.startOf=function(O,U){var Q=this,F=!!j.u(U)||U,B=j.p(O),T=function(y,H){var x=j.w(Q.$u?Date.UTC(Q.$y,H,y):new Date(Q.$y,H,y),Q);return F?x:x.endOf(Z)},A=function(y,H){return j.w(Q.toDate()[y].apply(Q.toDate("s"),(F?[0,0,0,0]:[23,59,59,999]).slice(H)),Q)},V=this.$W,E=this.$M,g=this.$D,k="set"+(this.$u?"UTC":"");switch(B){case K:return F?T(1,0):T(31,11);case z:return F?T(1,E):T(0,E+1);case G:var h=this.$locale().weekStart||0,l=(V<h?V+7:V)-h;return T(F?g-l:g+(6-l),E);case Z:case S:return A(k+"Hours",0);case Y:return A(k+"Minutes",1);case W:return A(k+"Seconds",2);case R:return A(k+"Milliseconds",3);default:return this.clone()}},X.endOf=function(O){return this.startOf(O,!1)},X.$set=function(O,U){var Q,F=j.p(O),B="set"+(this.$u?"UTC":""),T=(Q={},Q[Z]=B+"Date",Q[S]=B+"Date",Q[z]=B+"Month",Q[K]=B+"FullYear",Q[Y]=B+"Hours",Q[W]=B+"Minutes",Q[R]=B+"Seconds",Q[_]=B+"Milliseconds",Q)[F],A=F===Z?this.$D+(U-this.$W):U;if(F===z||F===K){var V=this.clone().set(S,1);V.$d[T](A),V.init(),this.$d=V.set(S,Math.min(this.$D,V.daysInMonth())).$d}else T&&this.$d[T](A);return this.init(),this},X.set=function(O,U){return this.clone().$set(O,U)},X.get=function(O){return this[j.p(O)]()},X.add=function(O,U){var Q,F=this;O=Number(O);var B=j.p(U),T=function(E){var g=P(F);return j.w(g.date(g.date()+Math.round(E*O)),F)};if(B===z)return this.set(z,this.$M+O);if(B===K)return this.set(K,this.$y+O);if(B===Z)return T(1);if(B===G)return T(7);var A=(Q={},Q[W]=D,Q[Y]=M,Q[R]=$,Q)[B]||1,V=this.$d.getTime()+O*A;return j.w(V,this)},X.subtract=function(O,U){return this.add(-1*O,U)},X.format=function(O){var U=this,Q=this.$locale();if(!this.isValid())return Q.invalidDate||K$;var F=O||"YYYY-MM-DDTHH:mm:ssZ",B=j.z(this),T=this.$H,A=this.$m,V=this.$M,E=Q.weekdays,g=Q.months,k=Q.meridiem,h=function(H,x,p,R$){return H&&(H[x]||H(U,F))||p[x].slice(0,R$)},l=function(H){return j.s(T%12||12,H,"0")},y=k||function(H,x,p){var R$=H<12?"AM":"PM";return p?R$.toLowerCase():R$};return F.replace(c$,function(H,x){return x||function(p){switch(p){case"YY":return String(U.$y).slice(-2);case"YYYY":return j.s(U.$y,4,"0");case"M":return V+1;case"MM":return j.s(V+1,2,"0");case"MMM":return h(Q.monthsShort,V,g,3);case"MMMM":return h(g,V);case"D":return U.$D;case"DD":return j.s(U.$D,2,"0");case"d":return String(U.$W);case"dd":return h(Q.weekdaysMin,U.$W,E,2);case"ddd":return h(Q.weekdaysShort,U.$W,E,3);case"dddd":return E[U.$W];case"H":return String(T);case"HH":return j.s(T,2,"0");case"h":return l(1);case"hh":return l(2);case"a":return y(T,A,!0);case"A":return y(T,A,!1);case"m":return String(A);case"mm":return j.s(A,2,"0");case"s":return String(U.$s);case"ss":return j.s(U.$s,2,"0");case"SSS":return j.s(U.$ms,3,"0");case"Z":return B}return null}(H)||B.replace(":","")})},X.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},X.diff=function(O,U,Q){var F,B=this,T=j.p(U),A=P(O),V=(A.utcOffset()-this.utcOffset())*D,E=this-A,g=function(){return j.m(B,A)};switch(T){case K:F=g()/12;break;case z:F=g();break;case C:F=g()/3;break;case G:F=(E-V)/604800000;break;case Z:F=(E-V)/86400000;break;case Y:F=E/M;break;case W:F=E/D;break;case R:F=E/$;break;default:F=E}return Q?F:j.a(F)},X.daysInMonth=function(){return this.endOf(z).$D},X.$locale=function(){return v[this.$L]},X.locale=function(O,U){if(!O)return this.$L;var Q=this.clone(),F=M$(O,U,!0);return F&&(Q.$L=F),Q},X.clone=function(){return j.w(this.$d,this)},X.toDate=function(){return new Date(this.valueOf())},X.toJSON=function(){return this.isValid()?this.toISOString():null},X.toISOString=function(){return this.$d.toISOString()},X.toString=function(){return this.$d.toUTCString()},w}(),P$=_$.prototype;return P.prototype=P$,[["$ms",_],["$s",R],["$m",W],["$H",Y],["$W",Z],["$M",z],["$y",K],["$D",S]].forEach(function(w){P$[w[1]]=function(X){return this.$g(X,w[0],w[1])}}),P.extend=function(w,X){return w.$i||(w(X,_$,P),w.$i=!0),P},P.locale=M$,P.isDayjs=w$,P.unix=function(w){return P(1000*w)},P.en=v[i],P.Ls=v,P.p={},P})});import{HttpMethod as U2,HttpStatus as G2,HttpStatusCode as z2,ContentType as w2}from "yinzerflow/constants/index.js";var l$=E$(C$(),1);import{createServer as x1}from"net";class F${options;constructor($){this.options=$??{}}get parserOptions(){return this.options.parserOptions}get connectionOptions(){return this.options.connectionOptions}get errorHandler(){return this.options.errorHandler}get port(){return this.options.port}getOptions(){return{...this.options}}}import{HttpMethod as _1}from "yinzerflow/constants/http.js";var n=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:_1.GET,..._});import{HttpMethod as R1}from "yinzerflow/constants/http.js";var o=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:R1.POST,..._});import{HttpMethod as W1}from "yinzerflow/constants/http.js";var r=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:W1.PUT,..._});import{HttpMethod as Y1}from "yinzerflow/constants/http.js";var s=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:Y1.DELETE,..._});import{HttpMethod as Z1}from "yinzerflow/constants/http.js";var a=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:Z1.PATCH,..._});import{EventEmitter as O1}from"events";import{RouteRegistryEvent as I}from "yinzerflow/constants/route.js";class t extends O1{_routes=new Map;getRoutes(){return this._routes}hasRoute($,D){let M=this.createRouteKey($,D);return this._routes.has(M)}getRoute($,D){let M=this.createRouteKey($,D);return this._routes.get(M)}createRouteKey($,D){return`${$}:${D}`}validatePath($){if(!$.startsWith("/"))throw new Error(`Route path must start with a slash: ${$}`);if($.includes("//"))throw new Error(`Route path must not contain consecutive slashes: ${$}`);let D=/:\w+/g,M=$.match(D)??[];for(let _ of M)if(_===":")throw new Error(`Route path parameter must have a name: ${$}`)}addRoute($){let{path:D,handler:M,method:_,beforeHandler:R,afterHandler:W}=$;this.validatePath(D);let Y={path:D,method:_,handler:M,beforeHandler:R??void 0,afterHandler:W??void 0},Z=this.createRouteKey(_,D);if(this._routes.has(Z))console.warn(`Route already exists and will be overwritten: ${_} ${D}`);return this._routes.set(Z,Y),this.emit(I.ROUTE_ADDED,Y),this.emit(I.ROUTES_CHANGED),Y}removeRoute($,D){let M=this.createRouteKey($,D),_=this._routes.get(M);if(!_)return!1;let R=this._routes.delete(M);if(R)this.emit(I.ROUTE_REMOVED,_),this.emit(I.ROUTES_CHANGED);return R}addGroup($,D,M){this.validatePath($);let _="";if($==="/")_="";else if($.endsWith("/"))_=$;else _=`${$}/`;for(let R of D){let W=R.path.startsWith("/")?R.path:`/${R.path}`,Y=`${_}${W.substring(1)}`,Z=this.createRouteKey(R.method,Y);this._routes.set(Z,{...R,path:Y,beforeGroup:M?.beforeGroup}),this.emit(I.ROUTE_ADDED,this._routes.get(Z))}this.emit(I.ROUTES_CHANGED)}addRoutes($){for(let D of $){this.validatePath(D.path);let M=this.createRouteKey(D.method,D.path);this._routes.set(M,D),this.emit(I.ROUTE_ADDED,D)}this.emit(I.ROUTES_CHANGED)}clearRoutes(){this._routes.clear(),this.emit(I.ROUTES_CHANGED)}get routeCount(){return this._routes.size}}import{RouteRegistryEvent as f1}from "yinzerflow/constants/route.js";class e{routeRegistry;patternRouteCache=new Map;constructor($){this.routeRegistry=$;this.buildPatternRouteCache()}buildPatternRouteCache(){let $=this.routeRegistry.getRoutes();this.patternRouteCache.clear();for(let[,D]of $)if(D.path.includes(":")){let{method:M}=D,_=this.patternRouteCache.get(M)??[],R=this.createRouteRegex(D.path);_.push({pattern:R,route:D}),this.patternRouteCache.set(M,_)}}createRouteRegex($){let D=$.replace(/:[^/]+/g,"([^/]+)").replace(/(?:[.+*?^$()[\]{}|])/g,"\\$&");return new RegExp(`^${D}$`)}findRoute($,D){return this.routeRegistry.getRoute($,D)}findRouteFromRequest($){let D=$.path!=="/"&&$.path.endsWith("/")?$.path.slice(0,-1):$.path,M=this.findRoute($.method,D);if(M)return M;let _=this.patternRouteCache.get($.method);if(!_)return;for(let{pattern:R,route:W}of _)if(R.test(D))return W;return}extractParamsFromPath($,D){let M={};if(!D.includes(":"))return M;let R=($.split("?")[0]??"").split("/").filter(Boolean),W=D.split("/").filter(Boolean);for(let Y=0;Y<W.length;Y++){let Z=W[Y];if(Z?.startsWith(":")){let G=Z.substring(1);if(Y<R.length){let z=R[Y];if(z)M[G]=decodeURIComponent(z)}}}return M}updatePatternRouteCache(){this.buildPatternRouteCache()}}import{ContentType as h$}from "yinzerflow/constants/http.js";var B$=($,D)=>{let M=$.indexOf(D);if(M===-1)return[$,""];let _=$.slice(0,M),R=$.slice(M+D.length);return[_,R]},Y$=($)=>new TextEncoder().encode($).length;var Z$=($)=>{try{return Q1($)}catch(D){throw new Error(`Invalid YAML: ${D instanceof Error?D.message:String(D)}`)}},Q1=($)=>{let D=Object.create(null),M=$.split(/\r?\n/),_=[{indent:-1,obj:D}],R={};for(let W=0;W<M.length;W++)try{let Y=M[W];if(Y!==void 0)q$(Y,_,W+1,R)}catch(Y){throw new Error(`Line ${W+1}: ${Y instanceof Error?Y.message:String(Y)}`)}return D},q$=($,D,M=0,_={})=>{if(!$||$.trim()===""||$.trim().startsWith("#"))return;let R=$.search(/\S/),W=$.trim();if(D[D.length-1]?.multilineKey){U1($,R,D);return}X1(W,R,D,M,_)},X1=($,D,M,_,R)=>{if($.startsWith("-"))z1($,D,M,_,R);else if($.includes(":"))f$($,D,M,_,R);else if($.startsWith("&"));else if($.startsWith("*"))J1($,M,R)},J1=($,D,M)=>{let _=$.substring(1).trim();if(!(_ in M))throw new Error(`Unknown alias: ${_}`);let R=M[_],W=D[D.length-1];if(!W)return;if(W.isArray&&Array.isArray(W.obj))W.obj.push(R)},U1=($,D,M)=>{let _=M[M.length-1];if(!_||!_.multilineKey)return;if(D<=_.indent){G1(_),q$($,M);return}let R=$.slice(_.indent+2);if(_.multilineValue)_.multilineValue+=`
|
|
1
|
+
import{createRequire as e$}from"node:module";var r$=Object.create;var{getPrototypeOf:s$,defineProperty:V$,getOwnPropertyNames:a$}=Object;var t$=Object.prototype.hasOwnProperty;var E$=($,D,M)=>{M=$!=null?r$(s$($)):{};let _=D||!$||!$.__esModule?V$(M,"default",{value:$,enumerable:!0}):M;for(let R of a$($))if(!t$.call(_,R))V$(_,R,{get:()=>$[R],enumerable:!0});return _};var H$=($,D)=>()=>(D||$((D={exports:{}}).exports,D),D.exports);var N$=e$(import.meta.url);var C$=H$((g$)=>{var J=g$,{Buffer:W$}=N$("buffer"),$1=N$("os");J.toBuffer=function($,D,M){M=~~M;let _;if(this.isV4Format($))_=D||W$.alloc(M+4),$.split(/\./g).map((R)=>{_[M++]=parseInt(R,10)&255});else if(this.isV6Format($)){let R=$.split(":",8),W;for(W=0;W<R.length;W++){let Y=this.isV4Format(R[W]),Z;if(Y)Z=this.toBuffer(R[W]),R[W]=Z.slice(0,2).toString("hex");if(Z&&++W<8)R.splice(W,0,Z.slice(2,4).toString("hex"))}if(R[0]==="")while(R.length<8)R.unshift("0");else if(R[R.length-1]==="")while(R.length<8)R.push("0");else if(R.length<8){for(W=0;W<R.length&&R[W]!=="";W++);let Y=[W,1];for(W=9-R.length;W>0;W--)Y.push("0");R.splice(...Y)}_=D||W$.alloc(M+16);for(W=0;W<R.length;W++){let Y=parseInt(R[W],16);_[M++]=Y>>8&255,_[M++]=Y&255}}if(!_)throw Error(`Invalid ip address: ${$}`);return _};J.toString=function($,D,M){D=~~D,M=M||$.length-D;let _=[];if(M===4){for(let R=0;R<M;R++)_.push($[D+R]);_=_.join(".")}else if(M===16){for(let R=0;R<M;R+=2)_.push($.readUInt16BE(D+R).toString(16));_=_.join(":"),_=_.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3"),_=_.replace(/:{3,4}/,"::")}return _};var D1=/^(\d{1,3}\.){3,3}\d{1,3}$/,M1=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;J.isV4Format=function($){return D1.test($)};J.isV6Format=function($){return M1.test($)};function c($){if($===4)return"ipv4";if($===6)return"ipv6";return $?$.toLowerCase():"ipv4"}J.fromPrefixLen=function($,D){if($>32)D="ipv6";else D=c(D);let M=4;if(D==="ipv6")M=16;let _=W$.alloc(M);for(let R=0,W=_.length;R<W;++R){let Y=8;if($<8)Y=$;$-=Y,_[R]=~(255>>Y)&255}return J.toString(_)};J.mask=function($,D){$=J.toBuffer($),D=J.toBuffer(D);let M=W$.alloc(Math.max($.length,D.length)),_;if($.length===D.length)for(_=0;_<$.length;_++)M[_]=$[_]&D[_];else if(D.length===4)for(_=0;_<D.length;_++)M[_]=$[$.length-4+_]&D[_];else{for(_=0;_<M.length-6;_++)M[_]=0;M[10]=255,M[11]=255;for(_=0;_<$.length;_++)M[_+12]=$[_]&D[_+12];_+=12}for(;_<M.length;_++)M[_]=0;return J.toString(M)};J.cidr=function($){let D=$.split("/"),M=D[0];if(D.length!==2)throw new Error(`invalid CIDR subnet: ${M}`);let _=J.fromPrefixLen(parseInt(D[1],10));return J.mask(M,_)};J.subnet=function($,D){let M=J.toLong(J.mask($,D)),_=J.toBuffer(D),R=0;for(let Y=0;Y<_.length;Y++)if(_[Y]===255)R+=8;else{let Z=_[Y]&255;while(Z)Z=Z<<1&255,R++}let W=2**(32-R);return{networkAddress:J.fromLong(M),firstAddress:W<=2?J.fromLong(M):J.fromLong(M+1),lastAddress:W<=2?J.fromLong(M+W-1):J.fromLong(M+W-2),broadcastAddress:J.fromLong(M+W-1),subnetMask:D,subnetMaskLength:R,numHosts:W<=2?W:W-2,length:W,contains(Y){return M===J.toLong(J.mask(Y,D))}}};J.cidrSubnet=function($){let D=$.split("/"),M=D[0];if(D.length!==2)throw new Error(`invalid CIDR subnet: ${M}`);let _=J.fromPrefixLen(parseInt(D[1],10));return J.subnet(M,_)};J.not=function($){let D=J.toBuffer($);for(let M=0;M<D.length;M++)D[M]=255^D[M];return J.toString(D)};J.or=function($,D){if($=J.toBuffer($),D=J.toBuffer(D),$.length===D.length){for(let W=0;W<$.length;++W)$[W]|=D[W];return J.toString($)}let M=$,_=D;if(D.length>$.length)M=D,_=$;let R=M.length-_.length;for(let W=R;W<M.length;++W)M[W]|=_[W-R];return J.toString(M)};J.isEqual=function($,D){if($=J.toBuffer($),D=J.toBuffer(D),$.length===D.length){for(let _=0;_<$.length;_++)if($[_]!==D[_])return!1;return!0}if(D.length===4){let _=D;D=$,$=_}for(let _=0;_<10;_++)if(D[_]!==0)return!1;let M=D.readUInt16BE(10);if(M!==0&&M!==65535)return!1;for(let _=0;_<4;_++)if($[_]!==D[_+12])return!1;return!0};J.isPrivate=function($){if(J.isLoopback($))return!0;if(!J.isV6Format($)){let D=J.normalizeToLong($);if(D<0)throw new Error("invalid ipv4 address");$=J.fromLong(D)}return/^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test($)||/^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test($)||/^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test($)||/^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test($)||/^f[cd][0-9a-f]{2}:/i.test($)||/^fe80:/i.test($)||/^::1$/.test($)||/^::$/.test($)};J.isPublic=function($){return!J.isPrivate($)};J.isLoopback=function($){if(!/\./.test($)&&!/:/.test($))$=J.fromLong(Number($));return/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test($)||/^0177\./.test($)||/^0x7f\./i.test($)||/^fe80::1$/i.test($)||/^::1$/.test($)||/^::$/.test($)};J.loopback=function($){if($=c($),$!=="ipv4"&&$!=="ipv6")throw new Error("family must be ipv4 or ipv6");return $==="ipv4"?"127.0.0.1":"fe80::1"};J.address=function($,D){let M=$1.networkInterfaces();if(D=c(D),$&&$!=="private"&&$!=="public"){let R=M[$].filter((W)=>{return c(W.family)===D});if(R.length===0)return;return R[0].address}let _=Object.keys(M).map((R)=>{let W=M[R].filter((Y)=>{if(Y.family=c(Y.family),Y.family!==D||J.isLoopback(Y.address))return!1;if(!$)return!0;return $==="public"?J.isPrivate(Y.address):J.isPublic(Y.address)});return W.length?W[0].address:void 0}).filter(Boolean);return!_.length?J.loopback(D):_[0]};J.toLong=function($){let D=0;return $.split(".").forEach((M)=>{D<<=8,D+=parseInt(M)}),D>>>0};J.fromLong=function($){return`${$>>>24}.${$>>16&255}.${$>>8&255}.${$&255}`};J.normalizeToLong=function($){let D=$.split(".").map((R)=>{if(R.startsWith("0x")||R.startsWith("0X"))return parseInt(R,16);else if(R.startsWith("0")&&R!=="0"&&/^[0-7]+$/.test(R))return parseInt(R,8);else if(/^[1-9]\d*$/.test(R)||R==="0")return parseInt(R,10);else return NaN});if(D.some(isNaN))return-1;let M=0;switch(D.length){case 1:M=D[0];break;case 2:if(D[0]>255||D[1]>16777215)return-1;M=D[0]<<24|D[1]&16777215;break;case 3:if(D[0]>255||D[1]>255||D[2]>65535)return-1;M=D[0]<<24|D[1]<<16|D[2]&65535;break;case 4:if(D.some((R)=>R>255))return-1;M=D[0]<<24|D[1]<<16|D[2]<<8|D[3];break;default:return-1}return M>>>0}});var k$=H$((j$,T$)=>{(function($,D){typeof j$=="object"&&typeof T$!="undefined"?T$.exports=D():typeof define=="function"&&define.amd?define(D):($=typeof globalThis!="undefined"?globalThis:$||self).dayjs=D()})(j$,function(){var $=1000,D=60000,M=3600000,_="millisecond",R="second",W="minute",Y="hour",Z="day",G="week",z="month",C="quarter",K="year",S="date",K$="Invalid Date",p$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,c$=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,n$={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(w){var X=["th","st","nd","rd"],O=w%100;return"["+w+(X[(O-20)%10]||X[O]||X[0])+"]"}},z$=function(w,X,O){var U=String(w);return!U||U.length>=X?w:""+Array(X+1-U.length).join(O)+w},o$={s:z$,z:function(w){var X=-w.utcOffset(),O=Math.abs(X),U=Math.floor(O/60),Q=O%60;return(X<=0?"+":"-")+z$(U,2,"0")+":"+z$(Q,2,"0")},m:function w(X,O){if(X.date()<O.date())return-w(O,X);var U=12*(O.year()-X.year())+(O.month()-X.month()),Q=X.clone().add(U,z),F=O-Q<0,B=X.clone().add(U+(F?-1:1),z);return+(-(U+(O-Q)/(F?Q-B:B-Q))||0)},a:function(w){return w<0?Math.ceil(w)||0:Math.floor(w)},p:function(w){return{M:z,y:K,w:G,d:Z,D:S,h:Y,m:W,s:R,ms:_,Q:C}[w]||String(w||"").toLowerCase().replace(/s$/,"")},u:function(w){return w===void 0}},i="en",v={};v[i]=n$;var A$="$isDayjsObject",w$=function(w){return w instanceof _$||!(!w||!w[A$])},M$=function w(X,O,U){var Q;if(!X)return i;if(typeof X=="string"){var F=X.toLowerCase();v[F]&&(Q=F),O&&(v[F]=O,Q=F);var B=X.split("-");if(!Q&&B.length>1)return w(B[0])}else{var T=X.name;v[T]=X,Q=T}return!U&&Q&&(i=Q),Q||!U&&i},P=function(w,X){if(w$(w))return w.clone();var O=typeof X=="object"?X:{};return O.date=w,O.args=arguments,new _$(O)},j=o$;j.l=M$,j.i=w$,j.w=function(w,X){return P(w,{locale:X.$L,utc:X.$u,x:X.$x,$offset:X.$offset})};var _$=function(){function w(O){this.$L=M$(O.locale,null,!0),this.parse(O),this.$x=this.$x||O.x||{},this[A$]=!0}var X=w.prototype;return X.parse=function(O){this.$d=function(U){var{date:Q,utc:F}=U;if(Q===null)return new Date(NaN);if(j.u(Q))return new Date;if(Q instanceof Date)return new Date(Q);if(typeof Q=="string"&&!/Z$/i.test(Q)){var B=Q.match(p$);if(B){var T=B[2]-1||0,A=(B[7]||"0").substring(0,3);return F?new Date(Date.UTC(B[1],T,B[3]||1,B[4]||0,B[5]||0,B[6]||0,A)):new Date(B[1],T,B[3]||1,B[4]||0,B[5]||0,B[6]||0,A)}}return new Date(Q)}(O),this.init()},X.init=function(){var O=this.$d;this.$y=O.getFullYear(),this.$M=O.getMonth(),this.$D=O.getDate(),this.$W=O.getDay(),this.$H=O.getHours(),this.$m=O.getMinutes(),this.$s=O.getSeconds(),this.$ms=O.getMilliseconds()},X.$utils=function(){return j},X.isValid=function(){return this.$d.toString()!==K$},X.isSame=function(O,U){var Q=P(O);return this.startOf(U)<=Q&&Q<=this.endOf(U)},X.isAfter=function(O,U){return P(O)<this.startOf(U)},X.isBefore=function(O,U){return this.endOf(U)<P(O)},X.$g=function(O,U,Q){return j.u(O)?this[U]:this.set(Q,O)},X.unix=function(){return Math.floor(this.valueOf()/1000)},X.valueOf=function(){return this.$d.getTime()},X.startOf=function(O,U){var Q=this,F=!!j.u(U)||U,B=j.p(O),T=function(y,H){var x=j.w(Q.$u?Date.UTC(Q.$y,H,y):new Date(Q.$y,H,y),Q);return F?x:x.endOf(Z)},A=function(y,H){return j.w(Q.toDate()[y].apply(Q.toDate("s"),(F?[0,0,0,0]:[23,59,59,999]).slice(H)),Q)},V=this.$W,E=this.$M,g=this.$D,k="set"+(this.$u?"UTC":"");switch(B){case K:return F?T(1,0):T(31,11);case z:return F?T(1,E):T(0,E+1);case G:var h=this.$locale().weekStart||0,l=(V<h?V+7:V)-h;return T(F?g-l:g+(6-l),E);case Z:case S:return A(k+"Hours",0);case Y:return A(k+"Minutes",1);case W:return A(k+"Seconds",2);case R:return A(k+"Milliseconds",3);default:return this.clone()}},X.endOf=function(O){return this.startOf(O,!1)},X.$set=function(O,U){var Q,F=j.p(O),B="set"+(this.$u?"UTC":""),T=(Q={},Q[Z]=B+"Date",Q[S]=B+"Date",Q[z]=B+"Month",Q[K]=B+"FullYear",Q[Y]=B+"Hours",Q[W]=B+"Minutes",Q[R]=B+"Seconds",Q[_]=B+"Milliseconds",Q)[F],A=F===Z?this.$D+(U-this.$W):U;if(F===z||F===K){var V=this.clone().set(S,1);V.$d[T](A),V.init(),this.$d=V.set(S,Math.min(this.$D,V.daysInMonth())).$d}else T&&this.$d[T](A);return this.init(),this},X.set=function(O,U){return this.clone().$set(O,U)},X.get=function(O){return this[j.p(O)]()},X.add=function(O,U){var Q,F=this;O=Number(O);var B=j.p(U),T=function(E){var g=P(F);return j.w(g.date(g.date()+Math.round(E*O)),F)};if(B===z)return this.set(z,this.$M+O);if(B===K)return this.set(K,this.$y+O);if(B===Z)return T(1);if(B===G)return T(7);var A=(Q={},Q[W]=D,Q[Y]=M,Q[R]=$,Q)[B]||1,V=this.$d.getTime()+O*A;return j.w(V,this)},X.subtract=function(O,U){return this.add(-1*O,U)},X.format=function(O){var U=this,Q=this.$locale();if(!this.isValid())return Q.invalidDate||K$;var F=O||"YYYY-MM-DDTHH:mm:ssZ",B=j.z(this),T=this.$H,A=this.$m,V=this.$M,E=Q.weekdays,g=Q.months,k=Q.meridiem,h=function(H,x,p,R$){return H&&(H[x]||H(U,F))||p[x].slice(0,R$)},l=function(H){return j.s(T%12||12,H,"0")},y=k||function(H,x,p){var R$=H<12?"AM":"PM";return p?R$.toLowerCase():R$};return F.replace(c$,function(H,x){return x||function(p){switch(p){case"YY":return String(U.$y).slice(-2);case"YYYY":return j.s(U.$y,4,"0");case"M":return V+1;case"MM":return j.s(V+1,2,"0");case"MMM":return h(Q.monthsShort,V,g,3);case"MMMM":return h(g,V);case"D":return U.$D;case"DD":return j.s(U.$D,2,"0");case"d":return String(U.$W);case"dd":return h(Q.weekdaysMin,U.$W,E,2);case"ddd":return h(Q.weekdaysShort,U.$W,E,3);case"dddd":return E[U.$W];case"H":return String(T);case"HH":return j.s(T,2,"0");case"h":return l(1);case"hh":return l(2);case"a":return y(T,A,!0);case"A":return y(T,A,!1);case"m":return String(A);case"mm":return j.s(A,2,"0");case"s":return String(U.$s);case"ss":return j.s(U.$s,2,"0");case"SSS":return j.s(U.$ms,3,"0");case"Z":return B}return null}(H)||B.replace(":","")})},X.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},X.diff=function(O,U,Q){var F,B=this,T=j.p(U),A=P(O),V=(A.utcOffset()-this.utcOffset())*D,E=this-A,g=function(){return j.m(B,A)};switch(T){case K:F=g()/12;break;case z:F=g();break;case C:F=g()/3;break;case G:F=(E-V)/604800000;break;case Z:F=(E-V)/86400000;break;case Y:F=E/M;break;case W:F=E/D;break;case R:F=E/$;break;default:F=E}return Q?F:j.a(F)},X.daysInMonth=function(){return this.endOf(z).$D},X.$locale=function(){return v[this.$L]},X.locale=function(O,U){if(!O)return this.$L;var Q=this.clone(),F=M$(O,U,!0);return F&&(Q.$L=F),Q},X.clone=function(){return j.w(this.$d,this)},X.toDate=function(){return new Date(this.valueOf())},X.toJSON=function(){return this.isValid()?this.toISOString():null},X.toISOString=function(){return this.$d.toISOString()},X.toString=function(){return this.$d.toUTCString()},w}(),P$=_$.prototype;return P.prototype=P$,[["$ms",_],["$s",R],["$m",W],["$H",Y],["$W",Z],["$M",z],["$y",K],["$D",S]].forEach(function(w){P$[w[1]]=function(X){return this.$g(X,w[0],w[1])}}),P.extend=function(w,X){return w.$i||(w(X,_$,P),w.$i=!0),P},P.locale=M$,P.isDayjs=w$,P.unix=function(w){return P(1000*w)},P.en=v[i],P.Ls=v,P.p={},P})});import{HttpMethod as U2,HttpStatus as G2,HttpStatusCode as z2,ContentType as w2}from "yinzerflow/constants/index.js";var l$=E$(C$(),1);import{createServer as x1}from"net";class F${options;constructor($){this.options=$??{}}get parserOptions(){return this.options.parserOptions}get connectionOptions(){return this.options.connectionOptions}get errorHandler(){return this.options.errorHandler}get port(){return this.options.port}getOptions(){return{...this.options}}}import{HttpMethod as _1}from "yinzerflow/constants/index.js";var n=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:_1.GET,..._});import{HttpMethod as R1}from "yinzerflow/constants/index.js";var o=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:R1.POST,..._});import{HttpMethod as W1}from "yinzerflow/constants/index.js";var r=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:W1.PUT,..._});import{HttpMethod as Y1}from "yinzerflow/constants/index.js";var s=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:Y1.DELETE,..._});import{HttpMethod as Z1}from "yinzerflow/constants/index.js";var a=($)=>(D,M,_)=>$.addRoute({path:D,handler:M,method:Z1.PATCH,..._});import{EventEmitter as O1}from"events";import{RouteRegistryEvent as I}from "yinzerflow/constants/index.js";class t extends O1{_routes=new Map;getRoutes(){return this._routes}hasRoute($,D){let M=this.createRouteKey($,D);return this._routes.has(M)}getRoute($,D){let M=this.createRouteKey($,D);return this._routes.get(M)}createRouteKey($,D){return`${$}:${D}`}validatePath($){if(!$.startsWith("/"))throw new Error(`Route path must start with a slash: ${$}`);if($.includes("//"))throw new Error(`Route path must not contain consecutive slashes: ${$}`);let D=/:\w+/g,M=$.match(D)??[];for(let _ of M)if(_===":")throw new Error(`Route path parameter must have a name: ${$}`)}addRoute($){let{path:D,handler:M,method:_,beforeHandler:R,afterHandler:W}=$;this.validatePath(D);let Y={path:D,method:_,handler:M,beforeHandler:R??void 0,afterHandler:W??void 0},Z=this.createRouteKey(_,D);if(this._routes.has(Z))console.warn(`Route already exists and will be overwritten: ${_} ${D}`);return this._routes.set(Z,Y),this.emit(I.ROUTE_ADDED,Y),this.emit(I.ROUTES_CHANGED),Y}removeRoute($,D){let M=this.createRouteKey($,D),_=this._routes.get(M);if(!_)return!1;let R=this._routes.delete(M);if(R)this.emit(I.ROUTE_REMOVED,_),this.emit(I.ROUTES_CHANGED);return R}addGroup($,D,M){this.validatePath($);let _="";if($==="/")_="";else if($.endsWith("/"))_=$;else _=`${$}/`;for(let R of D){let W=R.path.startsWith("/")?R.path:`/${R.path}`,Y=`${_}${W.substring(1)}`,Z=this.createRouteKey(R.method,Y);this._routes.set(Z,{...R,path:Y,beforeGroup:M?.beforeGroup}),this.emit(I.ROUTE_ADDED,this._routes.get(Z))}this.emit(I.ROUTES_CHANGED)}addRoutes($){for(let D of $){this.validatePath(D.path);let M=this.createRouteKey(D.method,D.path);this._routes.set(M,D),this.emit(I.ROUTE_ADDED,D)}this.emit(I.ROUTES_CHANGED)}clearRoutes(){this._routes.clear(),this.emit(I.ROUTES_CHANGED)}get routeCount(){return this._routes.size}}import{RouteRegistryEvent as f1}from "yinzerflow/constants/index.js";class e{routeRegistry;patternRouteCache=new Map;constructor($){this.routeRegistry=$;this.buildPatternRouteCache()}buildPatternRouteCache(){let $=this.routeRegistry.getRoutes();this.patternRouteCache.clear();for(let[,D]of $)if(D.path.includes(":")){let{method:M}=D,_=this.patternRouteCache.get(M)??[],R=this.createRouteRegex(D.path);_.push({pattern:R,route:D}),this.patternRouteCache.set(M,_)}}createRouteRegex($){let D=$.replace(/:[^/]+/g,"([^/]+)").replace(/(?:[.+*?^$()[\]{}|])/g,"\\$&");return new RegExp(`^${D}$`)}findRoute($,D){return this.routeRegistry.getRoute($,D)}findRouteFromRequest($){let D=$.path!=="/"&&$.path.endsWith("/")?$.path.slice(0,-1):$.path,M=this.findRoute($.method,D);if(M)return M;let _=this.patternRouteCache.get($.method);if(!_)return;for(let{pattern:R,route:W}of _)if(R.test(D))return W;return}extractParamsFromPath($,D){let M={};if(!D.includes(":"))return M;let R=($.split("?")[0]??"").split("/").filter(Boolean),W=D.split("/").filter(Boolean);for(let Y=0;Y<W.length;Y++){let Z=W[Y];if(Z?.startsWith(":")){let G=Z.substring(1);if(Y<R.length){let z=R[Y];if(z)M[G]=decodeURIComponent(z)}}}return M}updatePatternRouteCache(){this.buildPatternRouteCache()}}import{ContentType as h$}from "yinzerflow/constants/index.js";var B$=($,D)=>{let M=$.indexOf(D);if(M===-1)return[$,""];let _=$.slice(0,M),R=$.slice(M+D.length);return[_,R]},Y$=($)=>new TextEncoder().encode($).length;var Z$=($)=>{try{return Q1($)}catch(D){throw new Error(`Invalid YAML: ${D instanceof Error?D.message:String(D)}`)}},Q1=($)=>{let D=Object.create(null),M=$.split(/\r?\n/),_=[{indent:-1,obj:D}],R={};for(let W=0;W<M.length;W++)try{let Y=M[W];if(Y!==void 0)q$(Y,_,W+1,R)}catch(Y){throw new Error(`Line ${W+1}: ${Y instanceof Error?Y.message:String(Y)}`)}return D},q$=($,D,M=0,_={})=>{if(!$||$.trim()===""||$.trim().startsWith("#"))return;let R=$.search(/\S/),W=$.trim();if(D[D.length-1]?.multilineKey){U1($,R,D);return}X1(W,R,D,M,_)},X1=($,D,M,_,R)=>{if($.startsWith("-"))z1($,D,M,_,R);else if($.includes(":"))f$($,D,M,_,R);else if($.startsWith("&"));else if($.startsWith("*"))J1($,M,R)},J1=($,D,M)=>{let _=$.substring(1).trim();if(!(_ in M))throw new Error(`Unknown alias: ${_}`);let R=M[_],W=D[D.length-1];if(!W)return;if(W.isArray&&Array.isArray(W.obj))W.obj.push(R)},U1=($,D,M)=>{let _=M[M.length-1];if(!_||!_.multilineKey)return;if(D<=_.indent){G1(_),q$($,M);return}let R=$.slice(_.indent+2);if(_.multilineValue)_.multilineValue+=`
|
|
2
2
|
${R}`;else _.multilineValue=R},G1=($)=>{if(typeof $.obj==="object"&&$.obj!==null&&!Array.isArray($.obj)&&$.multilineKey){let D=$.obj,M=$.multilineValue??"",_=$.multilineKey;if($.multilineType==="literal")D[_]=M;else D[_]=M.replace(/\n/g," ")}delete $.multilineKey,delete $.multilineValue,delete $.multilineType},z1=($,D,M,_=0,R={})=>{let W=$.substring(1).trim();v$(M,D);let Y=M[M.length-1];if(!Y)return;if(Y.isArray&&Array.isArray(Y.obj))I$({itemContent:W,indent:D,stack:M,array:Y.obj,lineNumber:_},R);else{if(typeof Y.obj==="object"&&Y.obj!==null&&!Array.isArray(Y.obj)){let{obj:Z,arrayKey:G}=Y;if(G&&G in Z){if(!Array.isArray(Z[G]))Z[G]=[];let z=Z[G];I$({itemContent:W,indent:D,stack:M,array:z,lineNumber:_},R),M.push({indent:D,obj:z,isArray:!0});return}}w1({itemContent:W,indent:D,stack:M,lastStackItem:Y,lineNumber:_},R)}},I$=($,D={})=>{let{itemContent:M,indent:_,stack:R,array:W,lineNumber:Y}=$;if(!W)return;let{processedContent:Z,anchorName:G}=S$(M);if(Z.includes(":")){let z=Object.create(null);if(W.push(z),G)D[G]=z;let[C,K]=Z.split(":",2);if(C)x$({key:C,value:K,indent:_,stack:R,obj:z,lineNumber:Y??0})}else{let z=O$(Z);if(W.push(z),G)D[G]=z}},S$=($)=>{let D=$,M=null;if($.startsWith("&")){let _=$.indexOf(" ");if(_>1)M=$.substring(1,_),D=$.substring(_+1)}return{processedContent:D,anchorName:M}},x$=($)=>{let{key:D,value:M,indent:_,stack:R,obj:W}=$;if(typeof W!=="object"||W===null||Array.isArray(W))return;let Y=W,Z=D.trim(),G=M?.trim()??"";if(G==="")Y[Z]=Object.create(null),R.push({indent:_+2,obj:Y[Z]});else if(G==="|"||G===">"){if(R.length>0){let z=R[R.length-1];if(z)z.multilineKey=Z,z.multilineType=G==="|"?"literal":"folded"}}else Y[Z]=O$(G)},w1=($,D={})=>{let{itemContent:M,indent:_,stack:R,lastStackItem:W}=$;if(!W)return;if(typeof W.obj==="object"&&W.obj!==null&&!Array.isArray(W.obj)){let Y=W.obj,Z=W.arrayKey??"items";Y[Z]=[];let G=Y[Z];F1(M,_,R,G,D)}},F1=($,D,M,_,R)=>{let{processedContent:W,anchorName:Y}=S$($);if(W.includes(":")){let Z=Object.create(null);if(_.push(Z),Y)R[Y]=Z;let[G,z]=W.split(":",2);if(G)x$({key:G,value:z,indent:D,stack:M,obj:Z,lineNumber:0})}else{let Z=O$(W);if(_.push(Z),Y)R[Y]=Z}M.push({indent:D,obj:_,isArray:!0})},f$=($,D,M,_=0,R={})=>{let{processedContent:W,key:Y,value:Z,anchorName:G}=B1($);if(!Y)return;let z=Y.trim(),C=Z?.trim()??"";v$(M,D);let K=M[M.length-1];if(!K)return;if(j1($,D,M,K,_,R))return;if(typeof K.obj!=="object"||K.obj===null||Array.isArray(K.obj))return;let S=K.obj;T1(z,C,W,D,M,S,K,G,R)},B1=($)=>{let D=$,M=null,_=$.indexOf(":");if(_!==-1){let Y=$.substring(0,_).trim(),Z=$.substring(_+1).trim();if(Z.startsWith("&")){let G=Z.indexOf(" ");if(G>1)M=Z.substring(1,G),Z=Z.substring(G+1),D=`${Y}: ${Z}`}}let[R,W]=D.split(":",2);return{processedContent:D,key:R,value:W,anchorName:M}},j1=($,D,M,_,R,W)=>{if(_.isArray)return M.pop(),f$($,D,M,R,W),!0;return!1},T1=($,D,M,_,R,W,Y,Z,G)=>{if(D==="")L1($,M,_,R,W,Z,G);else if(D==="|"||D===">")Y.multilineKey=$,Y.multilineType=D==="|"?"literal":"folded";else{let z=O$(D);if(W[$]=z,Z)G[Z]=z}},L1=($,D,M,_,R,W,Y)=>{if(D.endsWith(":")){if(R[$]=Object.create(null),W)Y[W]=R[$];_.push({indent:M,obj:R[$],arrayKey:$})}else{if(R[$]=Object.create(null),W)Y[W]=R[$];_.push({indent:M,obj:R[$]})}},v$=($,D)=>{while($.length>1){let M=$[$.length-1];if(M&&M.indent>=D)$.pop();else break}},O$=($)=>{if($.startsWith('"')&&$.endsWith('"')||$.startsWith("'")&&$.endsWith("'"))return $.slice(1,-1);if(K1($))return null;let D=A1($);if(D!==void 0)return D;let M=P1($);if(M!==void 0)return M;let _=V1($);if(_ instanceof Date)return _.toISOString();let R=E1($);if(R!==void 0)return R;return $},K1=($)=>$==="null"||$==="~"||$==="",A1=($)=>{let D=$.toLowerCase();if(D==="true")return!0;if(D==="false")return!1;return},P1=($)=>{if($===".inf"||$===".Inf"||$===".INF")return 1/0;if($==="-.inf"||$==="-.Inf"||$==="-.INF")return-1/0;if($===".nan"||$===".NaN"||$===".NAN")return NaN;return},V1=($)=>{if(/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?$/.test($)){let M=new Date($);return isNaN(M.getTime())?$:M}return $},E1=($)=>{if(/^-?\d+(?:\.\d+)?$/.test($))return Number($);if(/^0x[0-9a-fA-F]+$/.test($))return parseInt($,16);if(/^0o[0-7]+$/.test($))return parseInt($.substring(2),8);return};var H1=($)=>{let M=$.split(`\r
|
|
3
3
|
`).find((R)=>R.toLowerCase().startsWith("content-type:"));if(!M)return;return M.slice(M.indexOf(":")+1).trim()},N1=($)=>{let D={name:""},_=$.split(`\r
|
|
4
4
|
`).find((Y)=>Y.toLowerCase().startsWith("content-disposition:"));if(!_)return D;let R=/name="(?<name>[^"]*)"/.exec(_),W=/filename="(?<filename>[^"]*)"/.exec(_);if(R?.groups?.name)D.name=R.groups.name;if(W?.groups?.filename)Object.assign(D,{filename:W.groups.filename});return D},g1=($)=>{let D=$.startsWith(`\r
|
|
5
5
|
`)?$.slice(2):$,M=D.indexOf(`\r
|
|
6
6
|
\r
|
|
7
|
-
`);if(M===-1)return["",""];let _=D.slice(0,M),R=D.slice(M+4).trim();return[_,R]},Q$=($,D)=>{let M={fields:{},files:[]},R=/^--(?<boundary>[^\r\n]+)/.exec($)?.groups?.boundary??null;if(!R)throw new Error("Invalid multipart form data: missing boundary");let W=$.split(`--${R}`).slice(1);for(let Y of W){if(!Y||Y.trim()==="--")continue;let[Z,G]=g1(Y);if(!Z||!G)continue;let z=N1(Z);if(!z.name)continue;if(z.filename)M.files.push(C1({contentDisposition:z,contentSection:G,headersSection:Z,parserOptions:D}));else M.fields[z.name]=G}return M},C1=({contentDisposition:$,contentSection:D,headersSection:M,parserOptions:_})=>{let R=H1(M)??"application/octet-stream",W={filename:$.filename??"",contentType:R,size:Y$(D),content:D};if((R===h$.YAML_APPLICATION||R===h$.YAML_TEXT)&&typeof W.content==="string"){if(_?.yaml?.raw)return W;W.content=Z$(W.content)}return W};var X$=($)=>{try{return JSON.parse($)}catch(D){throw new Error(`Invalid JSON: ${D instanceof Error?D.message:String(D)}`)}};var J$=($)=>$!==null&&typeof $==="object"&&("fields"in $)&&("files"in $)&&Array.isArray($.files)&&typeof $.fields==="object";var y$=($)=>!J$($)&&typeof $==="object";import{ContentType as b$,HttpMethod as m$}from "yinzerflow/constants/
|
|
7
|
+
`);if(M===-1)return["",""];let _=D.slice(0,M),R=D.slice(M+4).trim();return[_,R]},Q$=($,D)=>{let M={fields:{},files:[]},R=/^--(?<boundary>[^\r\n]+)/.exec($)?.groups?.boundary??null;if(!R)throw new Error("Invalid multipart form data: missing boundary");let W=$.split(`--${R}`).slice(1);for(let Y of W){if(!Y||Y.trim()==="--")continue;let[Z,G]=g1(Y);if(!Z||!G)continue;let z=N1(Z);if(!z.name)continue;if(z.filename)M.files.push(C1({contentDisposition:z,contentSection:G,headersSection:Z,parserOptions:D}));else M.fields[z.name]=G}return M},C1=({contentDisposition:$,contentSection:D,headersSection:M,parserOptions:_})=>{let R=H1(M)??"application/octet-stream",W={filename:$.filename??"",contentType:R,size:Y$(D),content:D};if((R===h$.YAML_APPLICATION||R===h$.YAML_TEXT)&&typeof W.content==="string"){if(_?.yaml?.raw)return W;W.content=Z$(W.content)}return W};var X$=($)=>{try{return JSON.parse($)}catch(D){throw new Error(`Invalid JSON: ${D instanceof Error?D.message:String(D)}`)}};var J$=($)=>$!==null&&typeof $==="object"&&("fields"in $)&&("files"in $)&&Array.isArray($.files)&&typeof $.fields==="object";var y$=($)=>!J$($)&&typeof $==="object";import{ContentType as b$,HttpMethod as m$}from "yinzerflow/constants/index.js";class u{protocol;method;path;headers;body;query;params;constructor($,D){let{protocol:M,method:_,path:R,headers:W,body:Y,query:Z,params:G}=this._parseRequest($,D);this.protocol=M,this.method=_,this.path=R,this.headers=W,this.body=Y,this.query=Z,this.params=G}parseParams=($)=>{let D={};if(typeof $.path!=="string")return D;if(typeof this.path!=="string")return D;let M=$.path.match(/:[^/]+/g),_=M?M.map((Z)=>Z.slice(1)):[];if(_.length===0)return D;let R=$.path.replace(/:[^/]+/g,"([^/]+)"),W=new RegExp(`^${R}$`),Y=this.path.match(W);if(!Y)return D;for(let Z=0;Z<_.length;Z++){let G=Y[Z+1],z=_[Z];if(G&&z)D[z]=G}return D};_parseRequest=($,D)=>{if(!$)throw new Error("Invalid request");let[M,_]=B$($,`\r
|
|
8
8
|
`),[R,W,Y]=M.split(" ",3),[Z,G]=B$(_,`\r
|
|
9
9
|
\r
|
|
10
10
|
`),z=this._parseHeaders(Z),C=this._parseQuery(W),K={};if(G&&R!==m$.GET&&R!==m$.HEAD)K=this._parseBody(z,G,D);return{protocol:Y,method:R,path:W,headers:z,body:K,query:C,params:{}}};_parseBody=($,D,M)=>{if(!$["Content-Type"])throw new Error("Missing Content-Type header");let _=$["Content-Type"];if(_===b$.JSON){if(M?.json?.raw)return D;return X$(D)}if(_.includes(b$.MULTIPART))return Q$(D,M);return D};_parseHeaders=($)=>{let D={};if(!$)return D;let _=$.replace(/\r\n|\r|\n/g,`
|
|
11
11
|
`).split(`
|
|
12
|
-
`);for(let R of _){if(!R)continue;let W=R.indexOf(":");if(W===-1)continue;let Y=R.slice(0,W).trim(),Z=R.slice(W+1).trim();if(Y)D[Y]=Z}return D};_parseQuery=($)=>{if(!$)return{};if(!$.includes("?"))return{};let[,D]=$.split("?");if(!D)return{};let M={},_=D.split("&");for(let R of _){let[W,Y]=R.split("=");if(W)M[decodeURIComponent(W)]=Y?decodeURIComponent(Y):""}return M}}var d$=E$(k$(),1);import{ContentType as u$,HttpStatus as L,HttpStatusCode as N}from "yinzerflow/constants/
|
|
12
|
+
`);for(let R of _){if(!R)continue;let W=R.indexOf(":");if(W===-1)continue;let Y=R.slice(0,W).trim(),Z=R.slice(W+1).trim();if(Y)D[Y]=Z}return D};_parseQuery=($)=>{if(!$)return{};if(!$.includes("?"))return{};let[,D]=$.split("?");if(!D)return{};let M={},_=D.split("&");for(let R of _){let[W,Y]=R.split("=");if(W)M[decodeURIComponent(W)]=Y?decodeURIComponent(Y):""}return M}}var d$=E$(k$(),1);import{ContentType as u$,HttpStatus as L,HttpStatusCode as N}from "yinzerflow/constants/index.js";class b{protocol;method;path;status;statusCode;statusText;headers={};body="";_formattedBody="";constructor($){this.method=$.method,this.path=$.path,this.protocol=$.protocol,this.statusCode=N.OK,this.status=L.OK,this.statusText=L.OK,this.headers={Date:d$.default().format("ddd, DD MMM YYYY HH:mm:ss [GMT]"),Connection:"keep-alive","Keep-Alive":"timeout=5, max=1000","Content-Type":u$.JSON,"Content-Length":"0"}}addHeaders($){for(let D of $)this.headers={...this.headers,...D}}removeHeaders($){for(let D of $)delete this.headers[D]}modifyHeader($,D){this.headers[$]=D}setStatus($){let D={[N.OK]:{status:L.OK,text:L.OK},[N.CREATED]:{status:L.CREATED,text:L.CREATED},[N.NO_CONTENT]:{status:L.NO_CONTENT,text:L.NO_CONTENT},[N.BAD_REQUEST]:{status:L.BAD_REQUEST,text:L.BAD_REQUEST},[N.UNAUTHORIZED]:{status:L.UNAUTHORIZED,text:L.UNAUTHORIZED},[N.FORBIDDEN]:{status:L.FORBIDDEN,text:L.FORBIDDEN},[N.NOT_FOUND]:{status:L.NOT_FOUND,text:L.NOT_FOUND},[N.METHOD_NOT_ALLOWED]:{status:L.METHOD_NOT_ALLOWED,text:L.METHOD_NOT_ALLOWED},[N.CONFLICT]:{status:L.CONFLICT,text:L.CONFLICT},[N.UNSUPPORTED_MEDIA_TYPE]:{status:L.UNSUPPORTED_MEDIA_TYPE,text:L.UNSUPPORTED_MEDIA_TYPE},[N.TOO_MANY_REQUESTS]:{status:L.TOO_MANY_REQUESTS,text:L.TOO_MANY_REQUESTS},[N.INTERNAL_SERVER_ERROR]:{status:L.INTERNAL_SERVER_ERROR,text:L.INTERNAL_SERVER_ERROR}},M=D[$]||D[N.OK];this.statusCode=$,this.status=M.status,this.statusText=M.text}setBody($){if(this.body=$,this._formattedBody=this._formatResponseBody($),!this.headers["Content-Type"])this.headers["Content-Type"]=u$.JSON;this.headers["Content-Length"]=String(Y$(this._formattedBody))}formatHttpResponse(){let $=`${this.protocol} ${this.statusCode} ${String(this.status)}`,D=Object.entries(this.headers).map(([M,_])=>`${M}: ${_}`).join(`\r
|
|
13
13
|
`);return`${$}\r
|
|
14
14
|
${D}\r
|
|
15
15
|
\r
|
|
16
|
-
${this._formattedBody}`}_formatResponseBody($){if($===null)return"null";switch(typeof $){case"string":return $;case"object":return JSON.stringify($);default:return String($)}}}class m{request;response;constructor($,D){this.request=$,this.response=D}}import{HttpStatusCode as i$}from "yinzerflow/constants/
|
|
17
|
-
`,D),$.setStatus(i$.INTERNAL_SERVER_ERROR),{success:!1,message:"Internal server error"}};async _sendResponse($,D){await new Promise((M)=>{$.write(D.formatHttpResponse(),()=>M()),$.end()})}async _handleError($,D){let M=new m($,new b($)),_=await Promise.resolve(this.errorHandler(M,D));return M.response.setBody(_),M.response}async _processRequest($,D){let M=new m($,new b($)),_=await this._processHooksChain(D,M);if(_)return _;let R=await Promise.resolve(D.handler(M));return await this.hooksManager.processAfterHandler(D,M),M.response.setBody(R),M.response}async _processHooksChain($,D){let M=await this.hooksManager.processBeforeAll($,D);if(M)return D.response.setBody(M),D.response;let _=await this.hooksManager.processBeforeGroup($,D);if(_)return D.response.setBody(_),D.response;let R=await this.hooksManager.processBeforeHandler($,D);if(R)return D.response.setBody(R),D.response;return}_createNotFoundResponse($){let D=new m($,new b($));return D.response.setStatus(i$.NOT_FOUND),D.response.setBody({success:!1,message:"Not found"}),D.response}}import{EventEmitter as I1}from"events";import{ConnectionEvent as f,DEFAULT_SOCKET_TIMEOUT as q1}from "yinzerflow/constants/
|
|
16
|
+
${this._formattedBody}`}_formatResponseBody($){if($===null)return"null";switch(typeof $){case"string":return $;case"object":return JSON.stringify($);default:return String($)}}}class m{request;response;constructor($,D){this.request=$,this.response=D}}import{HttpStatusCode as i$}from "yinzerflow/constants/index.js";class d{routeFinder;hooksManager;errorHandler;configManager;constructor($,D,M){this.routeFinder=$,this.hooksManager=D,this.configManager=M,this.errorHandler=M.errorHandler??this._defaultErrorHandler}async handleSocketRequest($,D){let M=new u(D.toString(),this.configManager.parserOptions);try{let _=this.routeFinder.findRouteFromRequest(M),R=_?(M.parseParams(_),await this._processRequest(M,_)):this._createNotFoundResponse(M);await this._sendResponse($,R)}catch(_){let R=await this._handleError(M,_);await this._sendResponse($,R)}}_defaultErrorHandler=({response:$},D)=>{return console.error(`Server error:
|
|
17
|
+
`,D),$.setStatus(i$.INTERNAL_SERVER_ERROR),{success:!1,message:"Internal server error"}};async _sendResponse($,D){await new Promise((M)=>{$.write(D.formatHttpResponse(),()=>M()),$.end()})}async _handleError($,D){let M=new m($,new b($)),_=await Promise.resolve(this.errorHandler(M,D));return M.response.setBody(_),M.response}async _processRequest($,D){let M=new m($,new b($)),_=await this._processHooksChain(D,M);if(_)return _;let R=await Promise.resolve(D.handler(M));return await this.hooksManager.processAfterHandler(D,M),M.response.setBody(R),M.response}async _processHooksChain($,D){let M=await this.hooksManager.processBeforeAll($,D);if(M)return D.response.setBody(M),D.response;let _=await this.hooksManager.processBeforeGroup($,D);if(_)return D.response.setBody(_),D.response;let R=await this.hooksManager.processBeforeHandler($,D);if(R)return D.response.setBody(R),D.response;return}_createNotFoundResponse($){let D=new m($,new b($));return D.response.setStatus(i$.NOT_FOUND),D.response.setBody({success:!1,message:"Not found"}),D.response}}import{EventEmitter as I1}from"events";import{ConnectionEvent as f,DEFAULT_SOCKET_TIMEOUT as q1}from "yinzerflow/constants/index.js";class $$ extends I1{_connections=new Set;_server=null;_isListening=!1;_startTime=0;_totalConnections=0;_connectionErrors=0;_socketTimeout;constructor($){super();this._socketTimeout=$??q1}setServer($){if(this._server=$,$)this._totalConnections=0,this._connectionErrors=0}addConnection($,D){try{$.setTimeout(D??this._socketTimeout),this._connections.add($),this._totalConnections++,this.emit(f.CONNECTION_ADDED,$),$.on("close",()=>{this._connections.delete($),this.emit(f.CONNECTION_CLOSED,$)}),$.on("error",(M)=>{this._connectionErrors++,this.emit(f.CONNECTION_ERROR,$,M)}),$.on("timeout",()=>{$.end(`HTTP/1.1 408 Request Timeout\r
|
|
18
18
|
\r
|
|
19
19
|
`),$.destroy()})}catch(M){this._connectionErrors++,this.emit(f.CONNECTION_ERROR,$,M)}}getConnections(){return this._connections}getConnectionCount(){return this._connections.size}setListening($){let D=this._isListening;if(this._isListening=$,$&&!D)this._startTime=Date.now(),this.emit(f.SERVER_STARTED);else if(!$&&D)this.emit(f.SERVER_STOPPED)}isListening(){return this._isListening}getServer(){return this._server}getStats(){return{activeConnections:this._connections.size,totalConnections:this._totalConnections,connectionErrors:this._connectionErrors,uptime:this._isListening?Date.now()-this._startTime:0}}async closeAllConnections($){if(this._connections.size===0){this.emit(f.ALL_CONNECTIONS_CLOSED);return}let D=[...this._connections];if($!==void 0&&$>0){for(let M of D)try{M.end(`HTTP/1.1 503 Service Unavailable\r
|
|
20
20
|
\r
|
|
21
|
-
`)}catch(_){}await new Promise((M)=>{setTimeout(()=>M(),$)})}for(let M of this._connections)try{M.destroy()}catch(_){}this._connections.clear(),this.emit(f.ALL_CONNECTIONS_CLOSED)}}import{EventEmitter as S1}from"events";import{HookManagerEvent as q,HookPhase as U$,PathMatchingPattern as G$}from "yinzerflow/constants/
|
|
21
|
+
`)}catch(_){}await new Promise((M)=>{setTimeout(()=>M(),$)})}for(let M of this._connections)try{M.destroy()}catch(_){}this._connections.clear(),this.emit(f.ALL_CONNECTIONS_CLOSED)}}import{EventEmitter as S1}from"events";import{HookManagerEvent as q,HookPhase as U$,PathMatchingPattern as G$}from "yinzerflow/constants/index.js";class D$ extends S1{hooks=[];pathMatchCache=new Map;add($,D){let M={paths:[],excluded:[],fn:$};if(!D);else if(D.paths===G$.ALL_BUT_EXCLUDED&&Array.isArray(D.excluded))M={paths:G$.ALL_BUT_EXCLUDED,excluded:D.excluded,fn:$};else if(Array.isArray(D.paths))M={paths:D.paths,excluded:D.excluded??[],fn:$};return this.hooks.push(M),this.clearPathMatchCache(),this.emit(q.HOOK_ADDED,M),this}clearPathMatchCache(){this.pathMatchCache.clear()}getHooksForPath($){if(this.pathMatchCache.has($))return this.pathMatchCache.get($)??[];let D=this.hooks.filter((M)=>{if(M.paths===G$.ALL_BUT_EXCLUDED)return!this.isPathExcluded($,M.excluded);if(Array.isArray(M.paths))return this.isPathIncluded($,M.paths)&&!this.isPathExcluded($,M.excluded);return!1});return this.pathMatchCache.set($,D),D}isPathIncluded($,D){if(D.length===0)return!0;return D.some((M)=>{if(M===$)return!0;if(M.endsWith("*")){let _=M.slice(0,-1);return $.startsWith(_)}return!1})}isPathExcluded($,D){return this.isPathIncluded($,D)}async processBeforeAll($,D){if(!this.hooks.length)return;let M=this.getHooksForPath($.path);for(let _ of M)try{let R=await Promise.resolve(_.fn(D));if(this.emit(q.HOOK_EXECUTED,{phase:U$.BEFORE_ALL,path:$.path,result:R?"short-circuit":"continue"}),this.emit(q.BEFORE_ALL_EXECUTED,D,_),R)return R}catch(R){throw console.error(`Hook error for path ${$.path}:`,R),R}return}async processBeforeGroup($,D){if(!$.beforeGroup)return;try{let M=await Promise.resolve($.beforeGroup(D));return this.emit(q.HOOK_EXECUTED,{phase:U$.BEFORE_GROUP,path:$.path,result:M?"short-circuit":"continue"}),this.emit(q.BEFORE_GROUP_EXECUTED,D,$.beforeGroup),M}catch(M){throw console.error(`BeforeGroup hook error for path ${$.path}:`,M),M}}async processBeforeHandler($,D){if(!$.beforeHandler)return;try{let M=await Promise.resolve($.beforeHandler(D));return this.emit(q.HOOK_EXECUTED,{phase:U$.BEFORE_HANDLER,path:$.path,result:M?"short-circuit":"continue"}),this.emit(q.BEFORE_HANDLER_EXECUTED,D,$.beforeHandler),M}catch(M){throw console.error(`BeforeHandler hook error for path ${$.path}:`,M),M}}async processAfterHandler($,D){if(!$.afterHandler)return;try{let M=await Promise.resolve($.afterHandler(D));return this.emit(q.HOOK_EXECUTED,{phase:U$.AFTER_HANDLER,path:$.path,result:M?"modified":"unmodified"}),this.emit(q.AFTER_HANDLER_EXECUTED,D,$.afterHandler),M}catch(M){throw console.error(`AfterHandler hook error for path ${$.path}:`,M),M}}clear(){while(this.hooks.length>0)this.hooks.pop();return this.clearPathMatchCache(),this}get hooksCount(){return this.hooks.length}}class L${routeRegistry=new t;routeFinder=new e(this.routeRegistry);hooksManager=new D$;connectionManager;requestHandler;configManager;_ip=l$.default.address();_port=5000;_gracefulShutdownTimeout=5000;get hooks(){return this.hooksManager}get routes(){return this.routeRegistry}get config(){return this.configManager}constructor($){if($?.port)this._port=$.port;if($?.connectionOptions?.gracefulShutdownTimeout)this._gracefulShutdownTimeout=$.connectionOptions.gracefulShutdownTimeout;this.configManager=new F$($),this.connectionManager=new $$($?.connectionOptions?.socketTimeout),this.requestHandler=new d(this.routeFinder,this.hooksManager,this.configManager),this.routeRegistry.on(f1.ROUTES_CHANGED,()=>{this.routeFinder.updatePatternRouteCache()})}get=n(this.routeRegistry);post=o(this.routeRegistry);put=r(this.routeRegistry);delete=s(this.routeRegistry);patch=a(this.routeRegistry);group($,D,M){this.routeRegistry.addGroup($,D,M)}beforeAll($,D){return this.hooksManager.add($,D),this}async listen(){return new Promise(($)=>{let D=x1().listen(this._port,this._ip);this.connectionManager.setServer(D),D.on("listening",()=>{this.connectionManager.setListening(!0),$()}),D.on("connection",(M)=>{this.connectionManager.addConnection(M),M.on("data",(_)=>{this.requestHandler.handleSocketRequest(M,_).catch((R)=>{console.error("Error handling request:",R)})}),M.on("error",(_)=>{console.error("An error occurred with yinzerflow. Please open an issue on GitHub.",_)})}),D.on("error",(M)=>{console.error("An error occurred with yinzerflow. Please open an issue on GitHub.",M)})})}async close(){if(!this.connectionManager.isListening()||!this.connectionManager.getServer())return;await this.connectionManager.closeAllConnections(this._gracefulShutdownTimeout);let $=this.connectionManager.getServer();if(!$)return;return new Promise((D)=>{$.close(()=>{this.connectionManager.setListening(!1),D()})})}getStatus(){return{isListening:this.connectionManager.isListening(),port:this._port,ip:this._ip}}}export{Z$ as parseYaml,Q$ as parseMultipartFormData,X$ as parseApplicationJson,J$ as isMultipartFormData,y$ as isJsonData,r as addPutRoute,o as addPostRoute,a as addPatchRoute,n as addGetRoute,s as addDeleteRoute,L$ as YinzerFlow,t as RouteRegistry,e as RouteFinder,b as Response,d as RequestHandler,u as Request,z2 as HttpStatusCode,G2 as HttpStatus,U2 as HttpMethod,D$ as HooksManager,m as Context,w2 as ContentType,$$ as ConnectionManager};
|
|
22
22
|
|
|
23
23
|
//# debugId=9AC99442B758E3D664756E2164756E21
|