elysia 0.7.23 → 0.7.24
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/dist/bun/index.js +2 -2
- package/dist/bun/index.js.map +3 -3
- package/dist/cjs/handler.js +11 -0
- package/dist/handler.js +2 -2
- package/package.json +1 -1
package/dist/bun/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var $X=Object.create;var{defineProperty:C8,getPrototypeOf:YX,getOwnPropertyNames
|
|
|
4
4
|
* Copyright(c) 2012-2014 Roman Shtylman
|
|
5
5
|
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
6
6
|
* MIT Licensed
|
|
7
|
-
*/var v$=n9,p$=o9;var h9=Object.prototype.toString,y$=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var u$=Z1(x0(),1),B$=Z1(Y8(),1),q8=Z1(wW(),1);var H8=($)=>$&&typeof $==="object"&&!Array.isArray($),J7=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")||l0(Object.getPrototypeOf($)),U1=($,Y,{skipKeys:W}={})=>{if(H8($)&&H8(Y))for(let[X,Z]of Object.entries(Y)){if(W?.includes(X))continue;if(!H8(Z)){$[X]=Z;continue}if(!(X in $)){$[X]=Z;continue}if(J7(Z)){$[X]=Z;continue}$[X]=U1($[X],Z)}return $},jW=($,Y)=>U1($,Y,{skipKeys:["properties"]}),I0=($,Y)=>{const W=[...Array.isArray($)?$:[$]],X=[];for(let Z of W)if(Z.$elysiaChecksum)X.push(Z.$elysiaChecksum);for(let Z of Array.isArray(Y)?Y:[Y])if(!X.includes(Z?.$elysiaChecksum))W.push(Z);return W},I1=($,Y)=>{return{body:Y?.body??$?.body,headers:Y?.headers??$?.headers,params:Y?.params??$?.params,query:Y?.query??$?.query,response:Y?.response??$?.response,type:$?.type||Y?.type,detail:U1(Y?.detail??{},$?.detail??{}),parse:I0($?.parse??[],Y?.parse??[]),transform:I0($?.transform??[],Y?.transform??[]),beforeHandle:I0($?.beforeHandle??[],Y?.beforeHandle??[]),afterHandle:I0($?.afterHandle??[],Y?.afterHandle??[]),onResponse:I0($?.onResponse??[],Y?.onResponse??[]),trace:I0($?.trace??[],Y?.trace??[]),error:I0($?.error??[],Y?.error??[])}},W1=($,{models:Y={},additionalProperties:W=!1,dynamic:X=!1})=>{if(!$)return;if(typeof $==="string"&&!($ in Y))return;const Z=typeof $==="string"?Y[$]:$;if(Z.type==="object"&&("additionalProperties"in Z)===!1)Z.additionalProperties=W;if(X)return{schema:Z,references:"",checkFunc:()=>{},code:"",Check:(Q)=>B$.Value.Check(Z,Q),Errors:(Q)=>B$.Value.Errors(Z,Q),Code:()=>""};return q8.TypeCompiler.Compile(Z)},N8=($,{models:Y={},additionalProperties:W=!1,dynamic:X=!1})=>{if(!$)return;if(typeof $==="string"&&!($ in Y))return;const Z=typeof $==="string"?Y[$]:$,Q=(z)=>{if(X)return{schema:z,references:"",checkFunc:()=>{},code:"",Check:(A)=>B$.Value.Check(z,A),Errors:(A)=>B$.Value.Errors(z,A),Code:()=>""};return q8.TypeCompiler.Compile(z)};if(u$.Kind in Z){if(("additionalProperties"in Z)===!1)Z.additionalProperties=W;return{200:Q(Z)}}const J={};return Object.keys(Z).forEach((z)=>{const A=Z[+z];if(typeof A==="string"){if(A in Y){const D=Y[A];D.type==="object"&&("additionalProperties"in D),J[+z]=(u$.Kind in D)?Q(D):D}return}if(A.type==="object"&&("additionalProperties"in A)===!1)A.additionalProperties=W;J[+z]=(u$.Kind in A)?Q(A):A}),J},M8=($)=>{let Y=9;for(let W=0;W<$.length;)Y=Math.imul(Y^$.charCodeAt(W++),387420489);return Y=Y^Y>>>9},h$=($,Y,W)=>{const X=(Z)=>{if(W)Z.$elysiaChecksum=W;return Z};return{start:I0($.start,("start"in Y?Y.start??[]:[]).map(X)),request:I0($.request,("request"in Y?Y.request??[]:[]).map(X)),parse:I0($.parse,"parse"in Y?Y?.parse??[]:[]).map(X),transform:I0($.transform,(Y?.transform??[]).map(X)),beforeHandle:I0($.beforeHandle,(Y?.beforeHandle??[]).map(X)),afterHandle:I0($.afterHandle,(Y?.afterHandle??[]).map(X)),onResponse:I0($.onResponse,(Y?.onResponse??[]).map(X)),trace:$.trace,error:I0($.error,(Y?.error??[]).map(X)),stop:I0($.stop,("stop"in Y?Y.stop??[]:[]).map(X))}};var KW=($,Y=!0)=>{if(!$)return $;if(typeof $==="function"){if(Y)$.$elysiaHookType="global";else $.$elysiaHookType=void 0;return $}return $.map((W)=>{if(Y)W.$elysiaHookType="global";else W.$elysiaHookType=void 0;return W})},l1=($)=>{if(!$)return $;if(typeof $==="function")return $.$elysiaHookType==="global"?$:void 0;return $.filter((Y)=>Y.$elysiaHookType==="global")},U8=($)=>{return{...$,type:$?.type,detail:$?.detail,parse:l1($?.parse),transform:l1($?.transform),beforeHandle:l1($?.beforeHandle),afterHandle:l1($?.afterHandle),onResponse:l1($?.onResponse),error:l1($?.error)}},A8={Continue:100,"Switching Protocols":101,Processing:102,"Early Hints":103,OK:200,Created:201,Accepted:202,"Non-Authoritative Information":203,"No Content":204,"Reset Content":205,"Partial Content":206,"Multi-Status":207,"Already Reported":208,"Multiple Choices":300,"Moved Permanently":301,Found:302,"See Other":303,"Not Modified":304,"Temporary Redirect":307,"Permanent Redirect":308,"Bad Request":400,Unauthorized:401,"Payment Required":402,Forbidden:403,"Not Found":404,"Method Not Allowed":405,"Not Acceptable":406,"Proxy Authentication Required":407,"Request Timeout":408,Conflict:409,Gone:410,"Length Required":411,"Precondition Failed":412,"Payload Too Large":413,"URI Too Long":414,"Unsupported Media Type":415,"Range Not Satisfiable":416,"Expectation Failed":417,"I'm a teapot":418,"Misdirected Request":421,"Unprocessable Content":422,Locked:423,"Failed Dependency":424,"Too Early":425,"Upgrade Required":426,"Precondition Required":428,"Too Many Requests":429,"Request Header Fields Too Large":431,"Unavailable For Legal Reasons":451,"Internal Server Error":500,"Not Implemented":501,"Bad Gateway":502,"Service Unavailable":503,"Gateway Timeout":504,"HTTP Version Not Supported":505,"Variant Also Negotiates":506,"Insufficient Storage":507,"Loop Detected":508,"Not Extended":510,"Network Authentication Required":511},t1=async($,Y)=>{if(typeof $!=="string")throw new TypeError("Cookie value must be provided as a string.");if(Y===null)throw new TypeError("Secret key must be provided.");const W=new TextEncoder,X=await crypto.subtle.importKey("raw",W.encode(Y),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),Z=await crypto.subtle.sign("HMAC",X,W.encode($)),Q=Array.from(new Uint8Array(Z)),J=btoa(String.fromCharCode(...Q));return`${$}.${J.replace(/=+$/,"")}`},B8=async($,Y)=>{if(typeof $!=="string")throw new TypeError("Signed cookie string must be provided.");if(Y===null)throw new TypeError("Secret key must be provided.");const W=$.slice(0,$.lastIndexOf("."));return await t1(W,Y)===$?W:!1};class t0{$;Y;name;setter;constructor($,Y={}){this._value=$;this.property=Y}get(){return this._value}get value(){return this._value}set value($){if(typeof $==="object"){if(JSON.stringify(this.value)===JSON.stringify($))return}else if(this.value===$)return;this._value=$,this.sync()}add($){const Y=Object.assign(this.property,typeof $==="function"?$(Object.assign(this.property,this.value)):$);if("value"in Y)this._value=Y.value,delete Y.value;return this.property=Y,this.sync()}set($){const Y=typeof $==="function"?$(Object.assign(this.property,this.value)):$;if("value"in Y)this._value=Y.value,delete Y.value;return this.property=Y,this.sync()}remove($){if(this.value===void 0)return;this.set({domain:$?.domain,expires:new Date(0),maxAge:0,path:$?.path,sameSite:$?.sameSite,secure:$?.secure,value:""})}get domain(){return this.property.domain}set domain($){if(this.property.domain===$)return;this.property.domain=$,this.sync()}get expires(){return this.property.expires}set expires($){if(this.property.expires?.getTime()===$?.getTime())return;this.property.expires=$,this.sync()}get httpOnly(){return this.property.httpOnly}set httpOnly($){if(this.property.domain===$)return;this.property.httpOnly=$,this.sync()}get maxAge(){return this.property.maxAge}set maxAge($){if(this.property.maxAge===$)return;this.property.maxAge=$,this.sync()}get path(){return this.property.path}set path($){if(this.property.path===$)return;this.property.path=$,this.sync()}get priority(){return this.property.priority}set priority($){if(this.property.priority===$)return;this.property.priority=$,this.sync()}get sameSite(){return this.property.sameSite}set sameSite($){if(this.property.sameSite===$)return;this.property.sameSite=$,this.sync()}get secure(){return this.property.secure}set secure($){if(this.property.secure===$)return;this.property.secure=$,this.sync()}toString(){return typeof this.value==="object"?JSON.stringify(this.value):this.value?.toString()??""}sync(){if(!this.name||!this.setter)return this;if(!this.setter.cookie)this.setter.cookie={[this.name]:Object.assign(this.property,{value:this.toString()})};else this.setter.cookie[this.name]=Object.assign(this.property,{value:this.toString()});return this}}var PW=($,Y,W)=>new Proxy($,{get(X,Z){if(Z in X)return X[Z];const Q=new t0(void 0,W?{...W}:void 0);return Q.setter=Y,Q.name=Z,Q},set(X,Z,Q){if(!(Q instanceof t0))return!1;if(!Y.cookie)Y.cookie={};return Q.setter=Y,Q.name=Z,Q.sync(),X[Z]=Q,!0}}),n$=async($,Y,{secret:W,sign:X,...Z}={})=>{if(!Y)return PW({},$,Z);const Q={},J=typeof W==="string";if(X&&X!==!0&&!Array.isArray(X))X=[X];const z=Object.keys(v$(Y));for(let A=0;A<z.length;A++){const D=z[A];let F=v$(Y)[D];if(X===!0||X?.includes(D)){if(!W)throw new Error("No secret is provided to cookie plugin");if(J){if(F=await B8(F,W),F===!1)throw new M$(D)}else{let j=!0;for(let M=0;M<W.length;M++){const P=await B8(F,W[M]);if(P!==!1){F=P,j=!1;break}}if(j)throw new M$(D)}}if(F===void 0)continue;const S=F.charCodeAt(0);if(S===123||S===91)try{const j=new t0(JSON.parse(F));j.setter=$,j.name=D,Q[D]=j;continue}catch{}if(!Number.isNaN(+F))F=+F;else if(F==="true")F=!0;else if(F==="false")F=!1;const b=new t0(F,Z);b.setter=$,b.name=D,Q[D]=b}return PW(Q,$)};var OW="toJSON"in new Headers,l0=($)=>{for(let Y in $)return!0;return!1},SW=($,Y)=>{if(!$||!Array.isArray(Y))return $;$.delete("Set-Cookie");for(let W=0;W<Y.length;W++){const X=Y[W].indexOf("=");$.append("Set-Cookie",`${Y[W].slice(0,X)}=${Y[W].slice(X+1)}`)}return $},LW=($)=>{if(!$||typeof $!=="object"||!l0($))return;const Y=[];for(let[W,X]of Object.entries($)){if(!W||!X)continue;if(Array.isArray(X.value))for(let Z=0;Z<X.value.length;Z++){let Q=X.value[Z];if(Q===void 0||Q===null)continue;if(typeof Q==="object")Q=JSON.stringify(Q);Y.push(p$(W,Q,X))}else{let Z=X.value;if(Z===void 0||Z===null)continue;if(typeof Z==="object")Z=JSON.stringify(Z);Y.push(p$(W,X.value,X))}}if(Y.length===0)return;if(Y.length===1)return Y[0];return Y},A1=($,Y)=>{if($?.$passthrough)$=$[$.$passthrough];if(l0(Y.headers)||Y.status!==200||Y.redirect||Y.cookie){if(typeof Y.status==="string")Y.status=A8[Y.status];if(Y.redirect){if(Y.headers.Location=Y.redirect,!Y.status||Y.status<300||Y.status>=400)Y.status=302}if(Y.cookie&&l0(Y.cookie))Y.headers["Set-Cookie"]=LW(Y.cookie);if(Y.headers["Set-Cookie"]&&Array.isArray(Y.headers["Set-Cookie"]))Y.headers=SW(new Headers(Y.headers),Y.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":case"Blob":return new Response($,{status:Y.status,headers:Y.headers});case"Object":case"Array":return Response.json($,Y);case void 0:if(!$)return new Response("",Y);return Response.json($,Y);case"Response":const W={...Y.headers};if(OW)Y.headers=$.headers.toJSON();else for(let[Z,Q]of $.headers.entries())if(Z in Y.headers)Y.headers[Z]=Q;for(let Z in W)$.headers.append(Z,W[Z]);return $;case"Error":return F$($,Y);case"Promise":return $.then((Z)=>A1(Z,Y));case"Function":return A1($(),Y);case"Number":case"Boolean":return new Response($.toString(),Y);case"Cookie":if($ instanceof t0)return new Response($.value,Y);return new Response($?.toString(),Y);default:const X=JSON.stringify($);if(X.charCodeAt(0)===123){if(!Y.headers["Content-Type"])Y.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),Y)}return new Response(X,Y)}}else switch($?.constructor?.name){case"String":case"Blob":return new Response($);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Error":return F$($,Y);case"Promise":return $.then((X)=>{const Z=j1(X);if(Z!==void 0)return Z;return new Response("")});case"Function":return j1($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof t0)return new Response($.value,Y);return new Response($?.toString(),Y);default:const W=JSON.stringify($);if(W.charCodeAt(0)===123)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}});return new Response(W)}},s0=($,Y)=>{if($===void 0||$===null)return;if($?.$passthrough)$=$[$.$passthrough];if(l0(Y.headers)||Y.status!==200||Y.redirect||Y.cookie){if(typeof Y.status==="string")Y.status=A8[Y.status];if(Y.redirect){if(Y.headers.Location=Y.redirect,!Y.status||Y.status<300||Y.status>=400)Y.status=302}if(Y.cookie&&l0(Y.cookie))Y.headers["Set-Cookie"]=LW(Y.cookie);if(Y.headers["Set-Cookie"]&&Array.isArray(Y.headers["Set-Cookie"]))Y.headers=SW(new Headers(Y.headers),Y.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":case"Blob":return new Response($,Y);case"Object":case"Array":return Response.json($,Y);case"ReadableStream":if(!Y.headers["content-type"]?.startsWith("text/event-stream"))Y.headers["content-type"]="text/event-stream; charset=utf-8";return new Response($,Y);case void 0:if(!$)return;return Response.json($,Y);case"Response":const W=Object.assign({},Y.headers);if(OW)Y.headers=$.headers.toJSON();else for(let[Z,Q]of $.headers.entries())if(!(Z in Y.headers))Y.headers[Z]=Q;for(let Z in W)$.headers.append(Z,W[Z]);if($.status!==Y.status)Y.status=$.status;return $;case"Promise":return $.then((Z)=>{const Q=s0(Z,Y);if(Q!==void 0)return Q;return});case"Error":return F$($,Y);case"Function":return s0($(),Y);case"Number":case"Boolean":return new Response($.toString(),Y);case"Cookie":if($ instanceof t0)return new Response($.value,Y);return new Response($?.toString(),Y);default:const X=JSON.stringify($);if(X.charCodeAt(0)===123){if(!Y.headers["Content-Type"])Y.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),Y)}return new Response(X,Y)}}else switch($?.constructor?.name){case"String":case"Blob":return new Response($);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Promise":return $.then((X)=>{const Z=s0(X,Y);if(Z!==void 0)return Z;return});case"Error":return F$($,Y);case"Function":return j1($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof t0)return new Response($.value,Y);return new Response($?.toString(),Y);default:const W=JSON.stringify($);if(W.charCodeAt(0)===123)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}});return new Response(W)}},j1=($)=>{if($?.$passthrough)$=$[$.$passthrough];switch($?.constructor?.name){case"String":case"Blob":return new Response($);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Error":return F$($);case"Promise":return $.then((W)=>{const X=j1(W);if(X!==void 0)return X;return new Response("")});case"Function":return j1($());case"Number":case"Boolean":return new Response($.toString());default:const Y=JSON.stringify($);if(Y.charCodeAt(0)===123)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}});return new Response(Y)}},F$=($,Y)=>new Response(JSON.stringify({name:$?.name,message:$?.message,cause:$?.cause}),{status:Y?.status!==200?Y?.status??500:500,headers:Y?.headers});var iW=Z1(w8(),1);var B7=(new Headers()).toJSON,mW=new RegExp(" (\\w+) = context","g"),uW={value:0},hW=({hasTrace:$,hasTraceSet:Y=!1,addFn:W,condition:X={}})=>{if(W("\nconst reporter = getReporter()\n"),$)return(Z,{name:Q,attribute:J="",unit:z=0}={})=>{const A=Z.indexOf("."),D=A===-1;if(Z!=="request"&&Z!=="response"&&!X[D?Z:Z.slice(0,A)])return()=>{if(Y&&Z==="afterHandle")W("reporter.emit('event',{id,event:'exit',type:'begin',time:0})"),W("\nawait traceDone\n")};if(D)Q||=Z;else Q||="anonymous";W("\n"+`reporter.emit('event', {
|
|
7
|
+
*/var v$=n9,p$=o9;var h9=Object.prototype.toString,y$=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;var u$=Z1(x0(),1),B$=Z1(Y8(),1),q8=Z1(wW(),1);var H8=($)=>$&&typeof $==="object"&&!Array.isArray($),J7=($)=>typeof $==="function"&&/^\s*class\s+/.test($.toString())||$.toString().startsWith("[object ")||l0(Object.getPrototypeOf($)),U1=($,Y,{skipKeys:W}={})=>{if(H8($)&&H8(Y))for(let[X,Z]of Object.entries(Y)){if(W?.includes(X))continue;if(!H8(Z)){$[X]=Z;continue}if(!(X in $)){$[X]=Z;continue}if(J7(Z)){$[X]=Z;continue}$[X]=U1($[X],Z)}return $},jW=($,Y)=>U1($,Y,{skipKeys:["properties"]}),I0=($,Y)=>{const W=[...Array.isArray($)?$:[$]],X=[];for(let Z of W)if(Z.$elysiaChecksum)X.push(Z.$elysiaChecksum);for(let Z of Array.isArray(Y)?Y:[Y])if(!X.includes(Z?.$elysiaChecksum))W.push(Z);return W},I1=($,Y)=>{return{body:Y?.body??$?.body,headers:Y?.headers??$?.headers,params:Y?.params??$?.params,query:Y?.query??$?.query,response:Y?.response??$?.response,type:$?.type||Y?.type,detail:U1(Y?.detail??{},$?.detail??{}),parse:I0($?.parse??[],Y?.parse??[]),transform:I0($?.transform??[],Y?.transform??[]),beforeHandle:I0($?.beforeHandle??[],Y?.beforeHandle??[]),afterHandle:I0($?.afterHandle??[],Y?.afterHandle??[]),onResponse:I0($?.onResponse??[],Y?.onResponse??[]),trace:I0($?.trace??[],Y?.trace??[]),error:I0($?.error??[],Y?.error??[])}},W1=($,{models:Y={},additionalProperties:W=!1,dynamic:X=!1})=>{if(!$)return;if(typeof $==="string"&&!($ in Y))return;const Z=typeof $==="string"?Y[$]:$;if(Z.type==="object"&&("additionalProperties"in Z)===!1)Z.additionalProperties=W;if(X)return{schema:Z,references:"",checkFunc:()=>{},code:"",Check:(Q)=>B$.Value.Check(Z,Q),Errors:(Q)=>B$.Value.Errors(Z,Q),Code:()=>""};return q8.TypeCompiler.Compile(Z)},N8=($,{models:Y={},additionalProperties:W=!1,dynamic:X=!1})=>{if(!$)return;if(typeof $==="string"&&!($ in Y))return;const Z=typeof $==="string"?Y[$]:$,Q=(z)=>{if(X)return{schema:z,references:"",checkFunc:()=>{},code:"",Check:(A)=>B$.Value.Check(z,A),Errors:(A)=>B$.Value.Errors(z,A),Code:()=>""};return q8.TypeCompiler.Compile(z)};if(u$.Kind in Z){if(("additionalProperties"in Z)===!1)Z.additionalProperties=W;return{200:Q(Z)}}const J={};return Object.keys(Z).forEach((z)=>{const A=Z[+z];if(typeof A==="string"){if(A in Y){const D=Y[A];D.type==="object"&&("additionalProperties"in D),J[+z]=(u$.Kind in D)?Q(D):D}return}if(A.type==="object"&&("additionalProperties"in A)===!1)A.additionalProperties=W;J[+z]=(u$.Kind in A)?Q(A):A}),J},M8=($)=>{let Y=9;for(let W=0;W<$.length;)Y=Math.imul(Y^$.charCodeAt(W++),387420489);return Y=Y^Y>>>9},h$=($,Y,W)=>{const X=(Z)=>{if(W)Z.$elysiaChecksum=W;return Z};return{start:I0($.start,("start"in Y?Y.start??[]:[]).map(X)),request:I0($.request,("request"in Y?Y.request??[]:[]).map(X)),parse:I0($.parse,"parse"in Y?Y?.parse??[]:[]).map(X),transform:I0($.transform,(Y?.transform??[]).map(X)),beforeHandle:I0($.beforeHandle,(Y?.beforeHandle??[]).map(X)),afterHandle:I0($.afterHandle,(Y?.afterHandle??[]).map(X)),onResponse:I0($.onResponse,(Y?.onResponse??[]).map(X)),trace:$.trace,error:I0($.error,(Y?.error??[]).map(X)),stop:I0($.stop,("stop"in Y?Y.stop??[]:[]).map(X))}};var KW=($,Y=!0)=>{if(!$)return $;if(typeof $==="function"){if(Y)$.$elysiaHookType="global";else $.$elysiaHookType=void 0;return $}return $.map((W)=>{if(Y)W.$elysiaHookType="global";else W.$elysiaHookType=void 0;return W})},l1=($)=>{if(!$)return $;if(typeof $==="function")return $.$elysiaHookType==="global"?$:void 0;return $.filter((Y)=>Y.$elysiaHookType==="global")},U8=($)=>{return{...$,type:$?.type,detail:$?.detail,parse:l1($?.parse),transform:l1($?.transform),beforeHandle:l1($?.beforeHandle),afterHandle:l1($?.afterHandle),onResponse:l1($?.onResponse),error:l1($?.error)}},A8={Continue:100,"Switching Protocols":101,Processing:102,"Early Hints":103,OK:200,Created:201,Accepted:202,"Non-Authoritative Information":203,"No Content":204,"Reset Content":205,"Partial Content":206,"Multi-Status":207,"Already Reported":208,"Multiple Choices":300,"Moved Permanently":301,Found:302,"See Other":303,"Not Modified":304,"Temporary Redirect":307,"Permanent Redirect":308,"Bad Request":400,Unauthorized:401,"Payment Required":402,Forbidden:403,"Not Found":404,"Method Not Allowed":405,"Not Acceptable":406,"Proxy Authentication Required":407,"Request Timeout":408,Conflict:409,Gone:410,"Length Required":411,"Precondition Failed":412,"Payload Too Large":413,"URI Too Long":414,"Unsupported Media Type":415,"Range Not Satisfiable":416,"Expectation Failed":417,"I'm a teapot":418,"Misdirected Request":421,"Unprocessable Content":422,Locked:423,"Failed Dependency":424,"Too Early":425,"Upgrade Required":426,"Precondition Required":428,"Too Many Requests":429,"Request Header Fields Too Large":431,"Unavailable For Legal Reasons":451,"Internal Server Error":500,"Not Implemented":501,"Bad Gateway":502,"Service Unavailable":503,"Gateway Timeout":504,"HTTP Version Not Supported":505,"Variant Also Negotiates":506,"Insufficient Storage":507,"Loop Detected":508,"Not Extended":510,"Network Authentication Required":511},t1=async($,Y)=>{if(typeof $!=="string")throw new TypeError("Cookie value must be provided as a string.");if(Y===null)throw new TypeError("Secret key must be provided.");const W=new TextEncoder,X=await crypto.subtle.importKey("raw",W.encode(Y),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),Z=await crypto.subtle.sign("HMAC",X,W.encode($)),Q=Array.from(new Uint8Array(Z)),J=btoa(String.fromCharCode(...Q));return`${$}.${J.replace(/=+$/,"")}`},B8=async($,Y)=>{if(typeof $!=="string")throw new TypeError("Signed cookie string must be provided.");if(Y===null)throw new TypeError("Secret key must be provided.");const W=$.slice(0,$.lastIndexOf("."));return await t1(W,Y)===$?W:!1};class t0{$;Y;name;setter;constructor($,Y={}){this._value=$;this.property=Y}get(){return this._value}get value(){return this._value}set value($){if(typeof $==="object"){if(JSON.stringify(this.value)===JSON.stringify($))return}else if(this.value===$)return;this._value=$,this.sync()}add($){const Y=Object.assign(this.property,typeof $==="function"?$(Object.assign(this.property,this.value)):$);if("value"in Y)this._value=Y.value,delete Y.value;return this.property=Y,this.sync()}set($){const Y=typeof $==="function"?$(Object.assign(this.property,this.value)):$;if("value"in Y)this._value=Y.value,delete Y.value;return this.property=Y,this.sync()}remove($){if(this.value===void 0)return;this.set({domain:$?.domain,expires:new Date(0),maxAge:0,path:$?.path,sameSite:$?.sameSite,secure:$?.secure,value:""})}get domain(){return this.property.domain}set domain($){if(this.property.domain===$)return;this.property.domain=$,this.sync()}get expires(){return this.property.expires}set expires($){if(this.property.expires?.getTime()===$?.getTime())return;this.property.expires=$,this.sync()}get httpOnly(){return this.property.httpOnly}set httpOnly($){if(this.property.domain===$)return;this.property.httpOnly=$,this.sync()}get maxAge(){return this.property.maxAge}set maxAge($){if(this.property.maxAge===$)return;this.property.maxAge=$,this.sync()}get path(){return this.property.path}set path($){if(this.property.path===$)return;this.property.path=$,this.sync()}get priority(){return this.property.priority}set priority($){if(this.property.priority===$)return;this.property.priority=$,this.sync()}get sameSite(){return this.property.sameSite}set sameSite($){if(this.property.sameSite===$)return;this.property.sameSite=$,this.sync()}get secure(){return this.property.secure}set secure($){if(this.property.secure===$)return;this.property.secure=$,this.sync()}toString(){return typeof this.value==="object"?JSON.stringify(this.value):this.value?.toString()??""}sync(){if(!this.name||!this.setter)return this;if(!this.setter.cookie)this.setter.cookie={[this.name]:Object.assign(this.property,{value:this.toString()})};else this.setter.cookie[this.name]=Object.assign(this.property,{value:this.toString()});return this}}var PW=($,Y,W)=>new Proxy($,{get(X,Z){if(Z in X)return X[Z];const Q=new t0(void 0,W?{...W}:void 0);return Q.setter=Y,Q.name=Z,Q},set(X,Z,Q){if(!(Q instanceof t0))return!1;if(!Y.cookie)Y.cookie={};return Q.setter=Y,Q.name=Z,Q.sync(),X[Z]=Q,!0}}),n$=async($,Y,{secret:W,sign:X,...Z}={})=>{if(!Y)return PW({},$,Z);const Q={},J=typeof W==="string";if(X&&X!==!0&&!Array.isArray(X))X=[X];const z=Object.keys(v$(Y));for(let A=0;A<z.length;A++){const D=z[A];let F=v$(Y)[D];if(X===!0||X?.includes(D)){if(!W)throw new Error("No secret is provided to cookie plugin");if(J){if(F=await B8(F,W),F===!1)throw new M$(D)}else{let j=!0;for(let M=0;M<W.length;M++){const P=await B8(F,W[M]);if(P!==!1){F=P,j=!1;break}}if(j)throw new M$(D)}}if(F===void 0)continue;const S=F.charCodeAt(0);if(S===123||S===91)try{const j=new t0(JSON.parse(F));j.setter=$,j.name=D,Q[D]=j;continue}catch{}if(!Number.isNaN(+F))F=+F;else if(F==="true")F=!0;else if(F==="false")F=!1;const b=new t0(F,Z);b.setter=$,b.name=D,Q[D]=b}return PW(Q,$)};var OW="toJSON"in new Headers,l0=($)=>{for(let Y in $)return!0;return!1},SW=($,Y)=>{if(!$||!Array.isArray(Y))return $;$.delete("Set-Cookie");for(let W=0;W<Y.length;W++){const X=Y[W].indexOf("=");$.append("Set-Cookie",`${Y[W].slice(0,X)}=${Y[W].slice(X+1)}`)}return $},LW=($)=>{if(!$||typeof $!=="object"||!l0($))return;const Y=[];for(let[W,X]of Object.entries($)){if(!W||!X)continue;if(Array.isArray(X.value))for(let Z=0;Z<X.value.length;Z++){let Q=X.value[Z];if(Q===void 0||Q===null)continue;if(typeof Q==="object")Q=JSON.stringify(Q);Y.push(p$(W,Q,X))}else{let Z=X.value;if(Z===void 0||Z===null)continue;if(typeof Z==="object")Z=JSON.stringify(Z);Y.push(p$(W,X.value,X))}}if(Y.length===0)return;if(Y.length===1)return Y[0];return Y},A1=($,Y)=>{if($?.$passthrough)$=$[$.$passthrough];if(l0(Y.headers)||Y.status!==200||Y.redirect||Y.cookie){if(typeof Y.status==="string")Y.status=A8[Y.status];if(Y.redirect){if(Y.headers.Location=Y.redirect,!Y.status||Y.status<300||Y.status>=400)Y.status=302}if(Y.cookie&&l0(Y.cookie))Y.headers["Set-Cookie"]=LW(Y.cookie);if(Y.headers["Set-Cookie"]&&Array.isArray(Y.headers["Set-Cookie"]))Y.headers=SW(new Headers(Y.headers),Y.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":case"Blob":return new Response($,{status:Y.status,headers:Y.headers});case"Object":case"Array":return Response.json($,Y);case"ReadableStream":if(!Y.headers["content-type"]?.startsWith("text/event-stream"))Y.headers["content-type"]="text/event-stream; charset=utf-8";return new Response($,Y);case void 0:if(!$)return new Response("",Y);return Response.json($,Y);case"Response":const W={...Y.headers};if(OW)Y.headers=$.headers.toJSON();else for(let[Z,Q]of $.headers.entries())if(Z in Y.headers)Y.headers[Z]=Q;for(let Z in W)$.headers.append(Z,W[Z]);return $;case"Error":return F$($,Y);case"Promise":return $.then((Z)=>A1(Z,Y));case"Function":return A1($(),Y);case"Number":case"Boolean":return new Response($.toString(),Y);case"Cookie":if($ instanceof t0)return new Response($.value,Y);return new Response($?.toString(),Y);default:const X=JSON.stringify($);if(X.charCodeAt(0)===123){if(!Y.headers["Content-Type"])Y.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),Y)}return new Response(X,Y)}}else switch($?.constructor?.name){case"String":case"Blob":return new Response($);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Error":return F$($,Y);case"Promise":return $.then((X)=>{const Z=j1(X);if(Z!==void 0)return Z;return new Response("")});case"Function":return j1($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof t0)return new Response($.value,Y);return new Response($?.toString(),Y);default:const W=JSON.stringify($);if(W.charCodeAt(0)===123)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}});return new Response(W)}},s0=($,Y)=>{if($===void 0||$===null)return;if($?.$passthrough)$=$[$.$passthrough];if(l0(Y.headers)||Y.status!==200||Y.redirect||Y.cookie){if(typeof Y.status==="string")Y.status=A8[Y.status];if(Y.redirect){if(Y.headers.Location=Y.redirect,!Y.status||Y.status<300||Y.status>=400)Y.status=302}if(Y.cookie&&l0(Y.cookie))Y.headers["Set-Cookie"]=LW(Y.cookie);if(Y.headers["Set-Cookie"]&&Array.isArray(Y.headers["Set-Cookie"]))Y.headers=SW(new Headers(Y.headers),Y.headers["Set-Cookie"]);switch($?.constructor?.name){case"String":case"Blob":return new Response($,Y);case"Object":case"Array":return Response.json($,Y);case"ReadableStream":if(!Y.headers["content-type"]?.startsWith("text/event-stream"))Y.headers["content-type"]="text/event-stream; charset=utf-8";return new Response($,Y);case void 0:if(!$)return;return Response.json($,Y);case"Response":const W=Object.assign({},Y.headers);if(OW)Y.headers=$.headers.toJSON();else for(let[Z,Q]of $.headers.entries())if(!(Z in Y.headers))Y.headers[Z]=Q;for(let Z in W)$.headers.append(Z,W[Z]);if($.status!==Y.status)Y.status=$.status;return $;case"Promise":return $.then((Z)=>{const Q=s0(Z,Y);if(Q!==void 0)return Q;return});case"Error":return F$($,Y);case"Function":return s0($(),Y);case"Number":case"Boolean":return new Response($.toString(),Y);case"Cookie":if($ instanceof t0)return new Response($.value,Y);return new Response($?.toString(),Y);default:const X=JSON.stringify($);if(X.charCodeAt(0)===123){if(!Y.headers["Content-Type"])Y.headers["Content-Type"]="application/json";return new Response(JSON.stringify($),Y)}return new Response(X,Y)}}else switch($?.constructor?.name){case"String":case"Blob":return new Response($);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Promise":return $.then((X)=>{const Z=s0(X,Y);if(Z!==void 0)return Z;return});case"Error":return F$($,Y);case"Function":return j1($());case"Number":case"Boolean":return new Response($.toString());case"Cookie":if($ instanceof t0)return new Response($.value,Y);return new Response($?.toString(),Y);default:const W=JSON.stringify($);if(W.charCodeAt(0)===123)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}});return new Response(W)}},j1=($)=>{if($?.$passthrough)$=$[$.$passthrough];switch($?.constructor?.name){case"String":case"Blob":return new Response($);case"Object":case"Array":return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"ReadableStream":return new Response($,{headers:{"Content-Type":"text/event-stream; charset=utf-8"}});case void 0:if(!$)return new Response("");return new Response(JSON.stringify($),{headers:{"content-type":"application/json"}});case"Response":return $;case"Error":return F$($);case"Promise":return $.then((W)=>{const X=j1(W);if(X!==void 0)return X;return new Response("")});case"Function":return j1($());case"Number":case"Boolean":return new Response($.toString());default:const Y=JSON.stringify($);if(Y.charCodeAt(0)===123)return new Response(JSON.stringify($),{headers:{"Content-Type":"application/json"}});return new Response(Y)}},F$=($,Y)=>new Response(JSON.stringify({name:$?.name,message:$?.message,cause:$?.cause}),{status:Y?.status!==200?Y?.status??500:500,headers:Y?.headers});var iW=Z1(w8(),1);var B7=(new Headers()).toJSON,mW=new RegExp(" (\\w+) = context","g"),uW={value:0},hW=({hasTrace:$,hasTraceSet:Y=!1,addFn:W,condition:X={}})=>{if(W("\nconst reporter = getReporter()\n"),$)return(Z,{name:Q,attribute:J="",unit:z=0}={})=>{const A=Z.indexOf("."),D=A===-1;if(Z!=="request"&&Z!=="response"&&!X[D?Z:Z.slice(0,A)])return()=>{if(Y&&Z==="afterHandle")W("reporter.emit('event',{id,event:'exit',type:'begin',time:0})"),W("\nawait traceDone\n")};if(D)Q||=Z;else Q||="anonymous";W("\n"+`reporter.emit('event', {
|
|
8
8
|
id,
|
|
9
9
|
event: '${Z}',
|
|
10
10
|
type: 'begin',
|
|
@@ -316,4 +316,4 @@ ${W}
|
|
|
316
316
|
}
|
|
317
317
|
}`,Function("inject",Y)({app:$,mapResponse:A1,ERROR_CODE:o1})};var c$=Z1(w8(),1);var O8=($)=>async(Y)=>{const W={cookie:{},status:200,headers:{}};let X;if($.decorators)X=$.decorators,X.request=Y,X.set=W,X.store=$.store;else X={set:W,store:$.store,request:Y};const Z=Y.url,Q=Z.indexOf("/",11),J=Z.indexOf("?",Q+1),z=J===-1?Z.substring(Q):Z.substring(Q,J);try{for(let O=0;O<$.event.request.length;O++){const U=$.event.request[O];let w=U(X);if(w instanceof Promise)w=await w;if(w=s0(w,W),w)return w}const A=$.dynamicRouter.find(Y.method,z)??$.dynamicRouter.find("ALL",z);if(!A)throw new L1;const{handle:D,hooks:F,validator:S,content:b}=A.store;let j;if(Y.method!=="GET"&&Y.method!=="HEAD")if(b)switch(b){case"application/json":j=await Y.json();break;case"text/plain":j=await Y.text();break;case"application/x-www-form-urlencoded":j=c$.parse(await Y.text());break;case"application/octet-stream":j=await Y.arrayBuffer();break;case"multipart/form-data":j={};const O=await Y.formData();for(let U of O.keys()){if(j[U])continue;const w=O.getAll(U);if(w.length===1)j[U]=w[0];else j[U]=w}break}else{let O=Y.headers.get("content-type");if(O){const U=O.indexOf(";");if(U!==-1)O=O.slice(0,U);for(let w=0;w<$.event.parse.length;w++){let I=$.event.parse[w](X,O);if(I instanceof Promise)I=await I;if(I){j=I;break}}if(j===void 0)switch(O){case"application/json":j=await Y.json();break;case"text/plain":j=await Y.text();break;case"application/x-www-form-urlencoded":j=c$.parse(await Y.text());break;case"application/octet-stream":j=await Y.arrayBuffer();break;case"multipart/form-data":j={};const w=await Y.formData();for(let I of w.keys()){if(j[I])continue;const R=w.getAll(I);if(R.length===1)j[I]=R[0];else j[I]=R}break}}}X.body=j,X.params=A?.params||void 0,X.query=J===-1?{}:c$.parse(Z.substring(J+1)),X.headers={};for(let[O,U]of Y.headers.entries())X.headers[O]=U;const M=S?.cookie?.schema;X.cookie=await n$(X.set,X.headers.cookie,M?{secret:M.secrets!==void 0?typeof M.secrets==="string"?M.secrets:M.secrets.join(","):void 0,sign:M.sign===!0?!0:M.sign!==void 0?typeof M.sign==="string"?M.sign:M.sign.join(","):void 0}:void 0);for(let O=0;O<F.transform.length;O++){const U=F.transform[O](X);if(F.transform[O].$elysia==="derive")if(U instanceof Promise)Object.assign(X,await U);else Object.assign(X,U);else if(U instanceof Promise)await U}if(S){if(S.headers){const O={};for(let U in Y.headers)O[U]=Y.headers.get(U);if(S.headers.Check(O)===!1)throw new P0("header",S.headers,O)}if(S.params?.Check(X.params)===!1)throw new P0("params",S.params,X.params);if(S.query?.Check(X.query)===!1)throw new P0("query",S.query,X.query);if(S.cookie){const O={};for(let[U,w]of Object.entries(X.cookie))O[U]=w.value;if(S.cookie?.Check(O)===!1)throw new P0("cookie",S.cookie,O)}if(S.body?.Check(j)===!1)throw new P0("body",S.body,j)}for(let O=0;O<F.beforeHandle.length;O++){let U=F.beforeHandle[O](X);if(U instanceof Promise)U=await U;if(U!==void 0){X.response=U;for(let I=0;I<F.afterHandle.length;I++){let R=F.afterHandle[I](X);if(R instanceof Promise)R=await R;if(R)U=R}const w=s0(U,X.set);if(w)return w}}let P=D(X);if(P instanceof Promise)P=await P;if(!F.afterHandle.length){const O=S?.response?.[P.status];if(O?.Check(P)===!1)throw new P0("response",O,P)}else{X.response=P;for(let O=0;O<F.afterHandle.length;O++){let U=F.afterHandle[O](X);if(U instanceof Promise)U=await U;const w=s0(U,X.set);if(w!==void 0){const I=S?.response?.[P.status];if(I?.Check(w)===!1)throw new P0("response",I,w);return w}}}if(X.set.cookie&&M?.sign){const O=!M.secrets?void 0:typeof M.secrets==="string"?M.secrets:M.secrets[0];if(M.sign===!0)for(let[U,w]of Object.entries(X.set.cookie))X.set.cookie[U].value=await t1(w.value,"${secret}");else for(let U of M.sign){if(!(U in M.properties))continue;if(X.set.cookie[U]?.value)X.set.cookie[U].value=await t1(X.set.cookie[U].value,O)}}return A1(P,X.set)}catch(A){if(A.status)W.status=A.status;return $.handleError(X,A)}finally{for(let A of $.event.onResponse)await A(X)}},oW=($)=>async(Y,W)=>{const X=Object.assign(Y,W);X.set=Y.set;for(let Z=0;Z<$.event.error.length;Z++){let Q=$.event.error[Z](X);if(Q instanceof Promise)Q=await Q;if(Q!==void 0&&Q!==null)return A1(Q,Y.set)}return new Response(typeof W.cause==="string"?W.cause:W.message,{headers:Y.set.headers,status:W.status??500})};var G1=Z1(x$(),1),a=Z1(x0(),1);try{G1.TypeSystem.Format("email",($)=>/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test($)),G1.TypeSystem.Format("uuid",($)=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test($)),G1.TypeSystem.Format("date",($)=>!Number.isNaN(new Date($).getTime())),G1.TypeSystem.Format("date-time",($)=>!Number.isNaN(new Date($).getTime()))}catch($){}var cW=($)=>{if(typeof $==="string")switch($.slice(-1)){case"k":return+$.slice(0,$.length-1)*1024;case"m":return+$.slice(0,$.length-1)*1048576;default:return+$}return $},S8=($,Y)=>{if(!(Y instanceof Blob))return!1;if($.minSize&&Y.size<cW($.minSize))return!1;if($.maxSize&&Y.size>cW($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!Y.type.startsWith($.extension))return!1}else{for(let W=0;W<$.extension.length;W++)if(Y.type.startsWith($.extension[W]))return!0;return!1}return!0},j7=G1.TypeSystem.Type("Files",($,Y)=>{if(!Array.isArray(Y))return S8($,Y);if($.minItems&&Y.length<$.minItems)return!1;if($.maxItems&&Y.length>$.maxItems)return!1;for(let W=0;W<Y.length;W++)if(!S8($,Y[W]))return!1;return!0});a.FormatRegistry.Set("numeric",($)=>!isNaN(+$));a.FormatRegistry.Set("ObjectString",($)=>{let Y=$.charCodeAt(0);if(Y===9||Y===10||Y===32)Y=$.trimStart().charCodeAt(0);if(Y!==123&&Y!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var R1={Numeric:($)=>a.Type.Transform(a.Type.Union([a.Type.String({format:"numeric",default:0}),a.Type.Number($)])).Decode((Y)=>{const W=+Y;if(isNaN(W))return Y;return W}).Encode((Y)=>Y),ObjectString:($,Y)=>a.Type.Transform(a.Type.Union([a.Type.String({format:"ObjectString",default:""}),a.Type.Object($,Y)])).Decode((W)=>{if(typeof W==="string")try{return JSON.parse(W)}catch{return W}return W}).Encode((W)=>JSON.stringify(W)),File:G1.TypeSystem.Type("File",S8),Files:($={})=>a.Type.Transform(a.Type.Union([j7($)])).Decode((Y)=>{if(Array.isArray(Y))return Y;return[Y]}).Encode((Y)=>Y),Nullable:($)=>a.Type.Union([a.Type.Null(),$]),MaybeEmpty:($)=>a.Type.Union([a.Type.Null(),a.Type.Undefined(),$]),Cookie:($,Y)=>a.Type.Object($,Y)};a.Type.ObjectString=R1.ObjectString;a.Type.Numeric=R1.Numeric;a.Type.File=($={})=>R1.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});a.Type.Files=($={})=>R1.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});a.Type.Nullable=($)=>R1.Nullable($);a.Type.MaybeEmpty=R1.MaybeEmpty;a.Type.Cookie=R1.Cookie;class l${config;dependencies={};store={};decorators={};definitions={type:{},error:{}};schema={};event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],onResponse:[],trace:[],error:[],stop:[]};reporter=new E8;server=null;getServer(){return this.server}validator=null;router=new K1;wsRouter=new K1;routes=[];staticRouter={handlers:[],variables:"",map:{},all:""};wsPaths={};dynamicRouter=new K1;lazyLoadModules=[];path="";constructor($){this.config={forceErrorEncapsulation:!1,prefix:"",aot:!0,strictPath:!1,scoped:!1,cookie:{},...$,seed:$?.seed===void 0?"":$?.seed}}add($,Y,W,X,{allowMeta:Z=!1,skipPrefix:Q=!1}={allowMeta:!1,skipPrefix:!1}){if(typeof Y==="string")Y=[Y];for(let J of Y){if(J=J===""?J:J.charCodeAt(0)===47?J:`/${J}`,this.config.prefix&&!Q)J=this.config.prefix+J;if(X?.type)switch(X.type){case"text":X.type="text/plain";break;case"json":X.type="application/json";break;case"formdata":X.type="multipart/form-data";break;case"urlencoded":X.type="application/x-www-form-urlencoded";break;case"arrayBuffer":X.type="application/octet-stream";break;default:break}const z=this.definitions.type;let A=W1(X?.cookie??this.validator?.cookie,{dynamic:!this.config.aot,models:z,additionalProperties:!0});if(l0(this.config.cookie??{}))if(A)A.schema=jW(A.schema,this.config.cookie??{});else A=W1(a.Type.Cookie({},this.config.cookie),{dynamic:!this.config.aot,models:z,additionalProperties:!0});const D={body:W1(X?.body??this.validator?.body,{dynamic:!this.config.aot,models:z}),headers:W1(X?.headers??this.validator?.headers,{dynamic:!this.config.aot,models:z,additionalProperties:!0}),params:W1(X?.params??this.validator?.params,{dynamic:!this.config.aot,models:z}),query:W1(X?.query??this.validator?.query,{dynamic:!this.config.aot,models:z}),cookie:A,response:N8(X?.response??this.validator?.response,{dynamic:!this.config.aot,models:z})},F=I1(this.event,X),S=J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(this.config.aot===!1){if(this.dynamicRouter.add($,J,{validator:D,hooks:F,content:X?.type,handle:W}),this.config.strictPath===!1)this.dynamicRouter.add($,S,{validator:D,hooks:F,content:X?.type,handle:W});this.routes.push({method:$,path:J,composed:null,handler:W,hooks:F});return}const b=nW({path:J,method:$,hooks:F,validator:D,handler:W,handleError:this.handleError,onRequest:this.event.request,config:this.config,definitions:Z?this.definitions.type:void 0,schema:Z?this.schema:void 0,getReporter:()=>this.reporter}),j=this.routes.findIndex((M)=>M.path===J&&M.method===$);if(j!==-1)this.routes.splice(j,1);if(this.routes.push({method:$,path:J,composed:b,handler:W,hooks:F}),$==="$INTERNALWS"){const M=this.config.strictPath?void 0:J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const P=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(b),this.staticRouter.variables+=`const st${P} = staticRouter.handlers[${P}]\n`,this.wsPaths[J]=P,M)this.wsPaths[M]=P}else if(this.wsRouter.add("ws",J,b),M)this.wsRouter.add("ws",M,b);return}if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const M=this.staticRouter.handlers.length;if(this.staticRouter.handlers.push(b),this.staticRouter.variables+=`const st${M} = staticRouter.handlers[${M}]\n`,!this.staticRouter.map[J])this.staticRouter.map[J]={code:""};if($==="ALL")this.staticRouter.map[J].all=`default: return st${M}(ctx)\n`;else this.staticRouter.map[J].code=`case '${$}': return st${M}(ctx)\n${this.staticRouter.map[J].code}`;if(!this.config.strictPath){if(!this.staticRouter.map[S])this.staticRouter.map[S]={code:""};if($==="ALL")this.staticRouter.map[S].all=`default: return st${M}(ctx)\n`;else this.staticRouter.map[S].code=`case '${$}': return st${M}(ctx)\n${this.staticRouter.map[S].code}`}}else if(this.router.add($,J,b),!this.config.strictPath)this.router.add($,J.endsWith("/")?J.slice(0,J.length-1):J+"/",b)}}onStart($){return this.on("start",$),this}onRequest($){return this.on("request",$),this}onParse($){return this.on("parse",$),this}onTransform($){return this.on("transform",$),this}onBeforeHandle($){return this.on("beforeHandle",$),this}onAfterHandle($){return this.on("afterHandle",$),this}onResponse($){return this.on("response",$),this}trace($){return this.reporter.on("event",V8(()=>this.reporter,this.event.trace.length,$)),this.on("trace",$),this}addError($,Y){return this.error($,Y)}error($,Y){switch(typeof $){case"string":return Y.prototype[o1]=$,this.definitions.error[$]=Y,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[W,X]of Object.entries($))X.prototype[o1]=W,this.definitions.error[W]=X;return this}onError($){return this.on("error",$),this}onStop($){return this.on("stop",$),this}on($,Y){for(let W of Array.isArray(Y)?Y:[Y])switch(W=KW(W),$){case"start":this.event.start.push(W);break;case"request":this.event.request.push(W);break;case"response":this.event.onResponse.push(W);break;case"parse":this.event.parse.splice(this.event.parse.length-1,0,W);break;case"transform":this.event.transform.push(W);break;case"beforeHandle":this.event.beforeHandle.push(W);break;case"afterHandle":this.event.afterHandle.push(W);break;case"trace":this.event.trace.push(W);break;case"error":this.event.error.push(W);break;case"stop":this.event.stop.push(W);break}return this}group($,Y,W){const X=new l$({...this.config,prefix:""});X.store=this.store;const Z=typeof Y==="object",Q=(Z?W:Y)(X);if(this.decorators=U1(this.decorators,X.decorators),Q.event.request.length)this.event.request=[...this.event.request,...Q.event.request];if(Q.event.onResponse.length)this.event.onResponse=[...this.event.onResponse,...Q.event.onResponse];return this.model(Q.definitions.type),Object.values(X.routes).forEach(({method:J,path:z,handler:A,hooks:D})=>{if(z=(Z?"":this.config.prefix)+$+z,Z){const F=Y,S=D;this.add(J,z,A,I1(F,{...S,error:!S.error?Q.event.error:Array.isArray(S.error)?[...S.error,...Q.event.error]:[S.error,...Q.event.error]}))}else this.add(J,z,A,I1(D,{error:Q.event.error}),{skipPrefix:!0})}),this}guard($,Y){if(!Y)return this.event=h$(this.event,$),this.validator={body:$.body,headers:$.headers,params:$.params,query:$.query,response:$.response},this;const W=new l$;W.store=this.store;const X=Y(W);if(this.decorators=U1(this.decorators,W.decorators),X.event.request.length)this.event.request=[...this.event.request,...X.event.request];if(X.event.onResponse.length)this.event.onResponse=[...this.event.onResponse,...X.event.onResponse];return this.model(X.definitions.type),Object.values(W.routes).forEach(({method:Z,path:Q,handler:J,hooks:z})=>{this.add(Z,Q,J,I1($,{...z,error:!z.error?X.event.error:Array.isArray(z.error)?[...z.error,...X.event.error]:[z.error,...X.event.error]}))}),this}use($){if($ instanceof Promise)return this.lazyLoadModules.push($.then((Y)=>{if(typeof Y==="function")return Y(this);if(typeof Y.default==="function")return Y.default(this);return this._use(Y)}).then((Y)=>Y.compile())),this;else return this._use($);return this}_use($){if(typeof $==="function"){const Z=$(this);if(Z instanceof Promise)return this.lazyLoadModules.push(Z.then((Q)=>{if(typeof Q==="function")return Q(this);if(typeof Q.default==="function")return Q.default(this);return this._use(Q)}).then((Q)=>Q.compile())),this;return Z}const{name:Y,seed:W}=$.config;$.getServer=()=>this.getServer();const X=$.config.scoped;if(X){if(Y){if(!(Y in this.dependencies))this.dependencies[Y]=[];const Q=W!==void 0?M8(Y+JSON.stringify(W)):0;if(this.dependencies[Y].some((J)=>Q===J))return this;this.dependencies[Y].push(Q)}if($.model(this.definitions.type),$.error(this.definitions.error),$.onRequest((Q)=>{Object.assign(Q,this.decorators),Object.assign(Q.store,this.store)}),$.event.trace=[...this.event.trace,...$.event.trace],$.config.aot)$.compile();const Z=this.mount($.fetch);return this.routes=this.routes.concat(Z.routes),this}else{$.reporter=this.reporter;for(let Z of $.event.trace)this.trace(Z)}this.decorate($.decorators),this.state($.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:Z,path:Q,handler:J,hooks:z}of Object.values($.routes))this.add(Z,Q,J,I1(z,{error:$.event.error}));if(!X)if(Y){if(!(Y in this.dependencies))this.dependencies[Y]=[];const Z=W!==void 0?M8(Y+JSON.stringify(W)):0;if(this.dependencies[Y].some((Q)=>Z===Q))return this;this.dependencies[Y].push(Z),this.event=h$(this.event,U8($.event),Z)}else this.event=h$(this.event,U8($.event));return this}mount($,Y){if(typeof $==="function"||$.length===0||$==="/"){const Z=typeof $==="function"?$:Y,Q=async({request:J,path:z})=>Z(new Request("http://a.cc"+z||"/",J));return this.all("/",Q,{type:"none"}),this.all("/*",Q,{type:"none"}),this}const W=$.length,X=async({request:Z,path:Q})=>Y(new Request("http://a.cc"+Q.slice(W)||"/",Z));return this.all($,X,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),X,{type:"none"}),this}get($,Y,W){return this.add("GET",$,Y,W),this}post($,Y,W){return this.add("POST",$,Y,W),this}put($,Y,W){return this.add("PUT",$,Y,W),this}patch($,Y,W){return this.add("PATCH",$,Y,W),this}delete($,Y,W){return this.add("DELETE",$,Y,W),this}options($,Y,W){return this.add("OPTIONS",$,Y,W),this}all($,Y,W){return this.add("ALL",$,Y,W),this}head($,Y,W){return this.add("HEAD",$,Y,W),this}connect($,Y,W){return this.add("CONNECT",$,Y,W),this}ws($,Y){const W=Y.transformMessage?Array.isArray(Y.transformMessage)?Y.transformMessage:[Y.transformMessage]:void 0;let X=null;const Z=W1(Y?.body,{models:this.definitions.type}),Q=W1(Y?.response,{models:this.definitions.type}),J=(z)=>{if(typeof z==="string"){const A=z?.charCodeAt(0);if(A===47||A===123)try{z=JSON.parse(z)}catch{}else if(!Number.isNaN(+z))z=+z}if(W?.length)for(let A=0;A<W.length;A++){const D=W[A](z);if(D!==void 0)z=D}return z};return this.route("$INTERNALWS",$,(z)=>{const{set:A,path:D,qi:F,headers:S,query:b,params:j}=z;if(X===null)X=this.getServer();if(X?.upgrade(z.request,{headers:typeof Y.upgrade==="function"?Y.upgrade(z):Y.upgrade,data:{validator:Q,open(M){Y.open?.(new c1(M,z))},message:(M,P)=>{const O=J(P);if(Z?.Check(O)===!1)return void M.send(new P0("message",Z,O).message);Y.message?.(new c1(M,z),O)},drain(M){Y.drain?.(new c1(M,z))},close(M,P,O){Y.close?.(new c1(M,z),P,O)}}}))return;return A.status=400,"Expected a websocket connection"},{beforeHandle:Y.beforeHandle,transform:Y.transform,headers:Y.headers,params:Y.params,query:Y.query}),this}route($,Y,W,{config:X,...Z}={config:{allowMeta:!1}}){return this.add($,Y,W,Z,X),this}state($,Y){switch(typeof $){case"object":return this.store=U1(this.store,$),this;case"function":return this.store=$(this.store),this}if(!($ in this.store))this.store[$]=Y;return this}decorate($,Y){switch(typeof $){case"object":return this.decorators=U1(this.decorators,$),this;case"function":return this.decorators=$(this.decorators),this}if(!($ in this.decorators))this.decorators[$]=Y;return this}derive($){return $.$elysia="derive",this.onTransform($)}model($,Y){switch(typeof $){case"object":return Object.entries($).forEach(([W,X])=>{if(!(W in this.definitions.type))this.definitions.type[W]=X}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=Y,this}mapDerive($){return $.$elysia="derive",this.onTransform($)}affix($,Y,W){if(W==="")return this;const X=["_","-"," "],Z=(A)=>A[0].toUpperCase()+A.slice(1),Q=$==="prefix"?(A,D)=>X.includes(A.at(-1)??"")?A+D:A+Z(D):X.includes(W.at(-1)??"")?(A,D)=>D+A:(A,D)=>D+Z(A),J=(A)=>{const D={};switch(A){case"decorator":for(let F in this.decorators)D[Q(W,F)]=this.decorators[F];this.decorators=D;break;case"state":for(let F in this.store)D[Q(W,F)]=this.store[F];this.store=D;break;case"model":for(let F in this.definitions.type)D[Q(W,F)]=this.definitions.type[F];this.definitions.type=D;break;case"error":for(let F in this.definitions.error)D[Q(W,F)]=this.definitions.error[F];this.definitions.error=D;break}},z=Array.isArray(Y)?Y:[Y];for(let A of z.some((D)=>D==="all")?["decorator","state","model","error"]:z)J(A);return this}prefix($,Y){return this.affix("prefix",$,Y)}suffix($,Y){return this.affix("suffix",$,Y)}compile(){if(this.fetch=this.config.aot?K8(this):O8(this),typeof this.server?.reload==="function")this.server.reload({...this.server,fetch:this.fetch});return this}handle=async($)=>this.fetch($);fetch=($)=>(this.fetch=this.config.aot?K8(this):O8(this))($);handleError=async($,Y)=>(this.handleError=this.config.aot?P8(this):oW(this))($,Y);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,Y)=>{if(!Bun)throw new Error("Bun to run");if(this.compile(),typeof $==="string"){if($=+$.trim(),Number.isNaN($))throw new Error("Port must be a numeric value")}const W=this.fetch,X=typeof $==="object"?{development:!N$,...this.config.serve,...$,websocket:{...this.config.websocket,...X8},fetch:W,error:this.outerErrorHandler}:{development:!N$,...this.config.serve,websocket:{...this.config.websocket,...X8},port:$,fetch:W,error:this.outerErrorHandler};if(typeof Bun==="undefined")throw new Error(".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch");if(this.server=Bun?.serve(X),this.event.start.length)(async()=>{const Z=Object.assign(this.decorators,{store:this.store,app:this});for(let Q=0;Q<this.event.transform.length;Q++){const J=this.event.transform[Q](Z);if(this.event.transform[Q].$elysia==="derive")if(J instanceof Promise)Object.assign(Z,await J);else Object.assign(Z,J)}for(let Q=0;Q<this.event.start.length;Q++)this.event.start[Q](Z)})();if(Y)Y(this.server);return Promise.all(this.lazyLoadModules).then(()=>{Bun?.gc(!1)}),this};stop=async()=>{if(!this.server)throw new Error("Elysia isn't running. Call `app.listen` to start the server.");if(this.server.stop(),this.event.stop.length)(async()=>{const $=Object.assign(this.decorators,{store:this.store,app:this});for(let Y=0;Y<this.event.transform.length;Y++){const W=this.event.transform[Y]($);if(this.event.transform[Y].$elysia==="derive")if(W instanceof Promise)Object.assign($,await W);else Object.assign($,W)}for(let Y=0;Y<this.event.stop.length;Y++)this.event.stop[Y]($)})()};get modules(){return Promise.all(this.lazyLoadModules)}}var export_t=a.Type;export{export_t as t,I0 as mergeObjectArray,I1 as mergeHook,U1 as mergeDeep,A1 as mapResponse,s0 as mapEarlyResponse,j1 as mapCompactResponse,W1 as getSchemaValidator,N8 as getResponseSchemaValidator,l$ as default,P0 as ValidationError,MW as ParseError,L1 as NotFoundError,M$ as InvalidCookieSignature,d$ as InternalServerError,l$ as Elysia,t0 as Cookie};
|
|
318
318
|
|
|
319
|
-
//# debugId=
|
|
319
|
+
//# debugId=9AAFD332A14356A464756e2164756e21
|