elysia 1.0.16 → 1.0.17
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 +17 -16
- package/dist/bun/index.js.map +4 -4
- package/dist/cjs/compose.js +20 -19
- package/dist/cjs/index.js +20 -19
- package/dist/compose.mjs +20 -19
- package/dist/index.mjs +20 -19
- package/package.json +1 -1
- package/tsconfig.test.tsbuildinfo +1 -1
package/dist/bun/index.js
CHANGED
|
@@ -54,19 +54,19 @@ var L$=Object.create;var{defineProperty:I1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
54
54
|
${N("sameSite")}
|
|
55
55
|
${N("secure")}
|
|
56
56
|
}`:"undefined";if(e)S+=`\nc.cookie = await parseCookie(c.set, c.headers.cookie, ${_})\n`;else S+=`\nc.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${_})\n`}if(M){let N=[];if(W.query&&W.query.schema.type==="object")N=Object.keys(W.query.schema.properties);else for(let _ of z.queries)if(N.indexOf(_)===-1)N.push(_);if($.config.forceDynamicQuery===!0||z.unknownQueries===!0||!N.length)S+=`if(c.qi !== -1) {
|
|
57
|
-
c.query = parseQuery(c.
|
|
57
|
+
c.query = parseQuery(c.url.slice(c.qi + 1).replace(/\\+/g, ' '))
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
// decodeURIComponent is already done in parseQuery function
|
|
60
|
+
// for(const key of Object.keys(c.query))
|
|
61
|
+
// c.query[key] = decodeURIComponentc.query[key])
|
|
61
62
|
} else c.query = {}`;else S+=`if(c.qi !== -1) {
|
|
62
|
-
let url = c.
|
|
63
|
+
let url = '&' + c.url.slice(c.qi + 1).replace(/\\+/g, ' ')
|
|
63
64
|
|
|
64
65
|
${N.map((_,j)=>`
|
|
65
66
|
${j===0?"let":""} memory = url.indexOf('&${_}=')
|
|
66
|
-
if(memory === -1) memory = url.indexOf('?${_}=')
|
|
67
67
|
let a${j}
|
|
68
68
|
|
|
69
|
-
if(memory !== -1) {
|
|
69
|
+
if (memory !== -1) {
|
|
70
70
|
const start = memory + ${_.length+2}
|
|
71
71
|
memory = url.indexOf('&', start)
|
|
72
72
|
|
|
@@ -186,9 +186,9 @@ var L$=Object.create;var{defineProperty:I1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
186
186
|
mr = onMapResponse[${M0}](c)
|
|
187
187
|
if(mr instanceof Promise) mr = await mr
|
|
188
188
|
if(mr !== undefined) c.response = mr
|
|
189
|
-
}\n`}S+=A,S+="return mapEarlyResponse(be, c.set
|
|
189
|
+
}\n`}S+=A,S+="return mapEarlyResponse(be, c.set)}\n"}}N()}if(X?.afterHandle.length){const N=E("handle",{name:K?Z.name:void 0});if(X.afterHandle.length)S+=G0?`let r = c.response = await ${R};\n`:`let r = c.response = ${R};\n`;else S+=G0?`let r = await ${R};\n`:`let r = ${R};\n`;N();const _=E("afterHandle",{unit:X.afterHandle.length});for(let j=0;j<X.afterHandle.length;j++){const b=X.afterHandle[j],H=E0(b.fn.toString()),v0=E("afterHandle.unit",{name:b.fn.name});if(!H)S+=x(b.fn)?`await afterHandle[${j}](c)\n`:`afterHandle[${j}](c)\n`,v0();else if(S+=x(b.fn)?`af = await afterHandle[${j}](c)\n`:`af = afterHandle[${j}](c)\n`,v0(),W.response)S+="if(af !== undefined) {",_(),S+=x0("af"),S+="c.response = af }";else S+="if(af !== undefined) {",_(),S+="c.response = af}\n"}if(_(),S+="r = c.response\n",W.response)S+=x0();if(S+=A,X.mapResponse.length)for(let j=0;j<X.mapResponse.length;j++)S+=`\nmr = onMapResponse[${j}](c)
|
|
190
190
|
if(mr instanceof Promise) mr = await mr
|
|
191
|
-
if(mr !== undefined) c.response = mr\n`;if(y0)S+="return mapResponse(r, c.set
|
|
191
|
+
if(mr !== undefined) c.response = mr\n`;if(y0)S+="return mapResponse(r, c.set)\n";else S+="return mapCompactResponse(r)\n"}else{const N=E("handle",{name:K?Z.name:void 0});if(W.response||X.mapResponse.length){if(S+=G0?`let r = await ${R};\n`:`let r = ${R};\n`,N(),W.response)S+=x0();if(E("afterHandle")(),X.mapResponse.length){S+="c.response = r";for(let _=0;_<X.mapResponse.length;_++)S+=`\nif(mr === undefined) {
|
|
192
192
|
mr = onMapResponse[${_}](c)
|
|
193
193
|
if(mr instanceof Promise) mr = await mr
|
|
194
194
|
if(mr !== undefined) r = c.response = mr
|
|
@@ -198,24 +198,24 @@ var L$=Object.create;var{defineProperty:I1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
198
198
|
c.set.redirect ||
|
|
199
199
|
c.set.cookie
|
|
200
200
|
)
|
|
201
|
-
return mapResponse(${R}.clone(), c.set
|
|
201
|
+
return mapResponse(${R}.clone(), c.set)
|
|
202
202
|
else
|
|
203
|
-
return ${R}.clone()`:`return ${R}.clone()`,S+="\n";else if(y0)S+="return mapResponse(r, c.set
|
|
203
|
+
return ${R}.clone()`:`return ${R}.clone()`,S+="\n";else if(y0)S+="return mapResponse(r, c.set)\n";else S+="return mapCompactResponse(r)\n"}else if(C.handle||v){if(S+=G0?`let r = await ${R};\n`:`let r = ${R};\n`,N(),E("afterHandle")(),X.mapResponse.length){S+="c.response = r";for(let _=0;_<X.mapResponse.length;_++)S+=`\nif(mr === undefined) {
|
|
204
204
|
mr = onMapResponse[${_}](c)
|
|
205
205
|
if(mr instanceof Promise) mr = await mr
|
|
206
206
|
if(mr !== undefined) r = c.response = mr
|
|
207
|
-
}\n`}if(S+=A,y0)S+="return mapResponse(r, c.set
|
|
207
|
+
}\n`}if(S+=A,y0)S+="return mapResponse(r, c.set)\n";else S+="return mapCompactResponse(r)\n"}else{N();const _=G0?`await ${R}`:R;if(E("afterHandle")(),Z instanceof Response)S+=z.set?`if(
|
|
208
208
|
isNotEmpty(c.set.headers) ||
|
|
209
209
|
c.set.status !== 200 ||
|
|
210
210
|
c.set.redirect ||
|
|
211
211
|
c.set.cookie
|
|
212
212
|
)
|
|
213
|
-
return mapResponse(${R}.clone(), c.set
|
|
213
|
+
return mapResponse(${R}.clone(), c.set)
|
|
214
214
|
else
|
|
215
|
-
return ${R}.clone()`:`return ${R}.clone()`,S+="\n";else if(y0)S+=`return mapResponse(${_}, c.set
|
|
215
|
+
return ${R}.clone()`:`return ${R}.clone()`,S+="\n";else if(y0)S+=`return mapResponse(${_}, c.set)\n`;else S+=`return mapCompactResponse(${_})\n`}}if(U||F){if(S+="\n} catch(error) {",!w1)S+="return (async () => {";S+="const set = c.set\nif (!set.status || set.status < 300) set.status = error?.status || 500\n";const N=E("error",{unit:X.error.length});if(X.error.length){S+=`
|
|
216
216
|
c.error = error
|
|
217
217
|
c.code = error.code ?? error[ERROR_CODE] ?? "UNKNOWN"
|
|
218
|
-
`;for(let _=0;_<X.error.length;_++){const j=`er${_}`,b=E("error.unit",{name:X.error[_].fn.name});if(S+=`\nlet ${j} = handleErrors[${_}](c)\n`,x(X.error[_]))S+=`if (${j} instanceof Promise) ${j} = await ${j}\n`;b(),S+=`${j} = mapEarlyResponse(${j}, set
|
|
218
|
+
`;for(let _=0;_<X.error.length;_++){const j=`er${_}`,b=E("error.unit",{name:X.error[_].fn.name});if(S+=`\nlet ${j} = handleErrors[${_}](c)\n`,x(X.error[_]))S+=`if (${j} instanceof Promise) ${j} = await ${j}\n`;b(),S+=`${j} = mapEarlyResponse(${j}, set)\n`,S+=`if (${j}) {`,S+=`return ${j} }\n`}}if(N(),S+="return handleError(c, error, true)\n\n",!w1)S+="})()";if(S+="}",F||P){S+=" finally { ";const _=E("response",{unit:X.onResponse.length});S+=F,_(),S+="}"}}return S=`const {
|
|
219
219
|
handler,
|
|
220
220
|
handleError,
|
|
221
221
|
hooks: {
|
|
@@ -337,12 +337,13 @@ var L$=Object.create;var{defineProperty:I1,getPrototypeOf:H$,getOwnPropertyNames
|
|
|
337
337
|
request
|
|
338
338
|
)\n`,q(),B+="if(re !== undefined) return re\n";else B+=`${T?"await":""} onRequest[${z}](ctx)\n`,q()}B+=`} catch (error) {
|
|
339
339
|
return app.handleError(ctx, error)
|
|
340
|
-
}`,S(),B+=U,B+="\nctx.qi = qi\n ctx.path = path\
|
|
340
|
+
}`,S(),B+=U,B+="\nctx.qi = qi\n ctx.path = path\nctx.url=url"}else B+=U,B+=`${Z?"const id = +requestId.value++":""}
|
|
341
341
|
const ctx = {
|
|
342
342
|
request,
|
|
343
343
|
store,
|
|
344
344
|
qi,
|
|
345
345
|
path,
|
|
346
|
+
url,
|
|
346
347
|
redirect,
|
|
347
348
|
set: {
|
|
348
349
|
headers: ${Object.keys(X??{}).length?"Object.assign({}, app.setHeaders)":"{}"},
|
|
@@ -438,4 +439,4 @@ if(st${$}.compose) return (stc${$} = st${$}.compose())(ctx)
|
|
|
438
439
|
|
|
439
440
|
return st${$}(ctx)`;var $1=N0(M1(),1);var O1=($)=>async(J)=>{const w=J.url,B=w.indexOf("/",11),X=w.indexOf("?",B+1),W=X===-1?w.substring(B):w.substring(B,X),Z={cookie:{},status:200,headers:{}},Q=Object.assign({},$.singleton.decorator,{set:Z,store:$.singleton.store,request:J,path:W,qi:X});try{for(let z=0;z<$.event.request.length;z++){const M=$.event.request[z].fn;let D=M(Q);if(D instanceof Promise)D=await D;if(D=f(D,Z),D)return D}const Y=$.router.dynamic.find(J.method,W)??$.router.dynamic.find("ALL",W);if(!Y)throw new Q0;const{handle:G,hooks:K,validator:U,content:R}=Y.store;let F;if(J.method!=="GET"&&J.method!=="HEAD")if(R)switch(R){case"application/json":F=await J.json();break;case"text/plain":F=await J.text();break;case"application/x-www-form-urlencoded":F=$1.parse(await J.text());break;case"application/octet-stream":F=await J.arrayBuffer();break;case"multipart/form-data":F={};const z=await J.formData();for(let M of z.keys()){if(F[M])continue;const D=z.getAll(M);if(D.length===1)F[M]=D[0];else F[M]=D}break}else{let z=J.headers.get("content-type");if(z){const M=z.indexOf(";");if(M!==-1)z=z.slice(0,M);Q.contentType=z;for(let D=0;D<K.parse.length;D++){const T=K.parse[D].fn;let q=T(Q,z);if(q instanceof Promise)q=await q;if(q){F=q;break}}if(delete Q.contentType,F===void 0)switch(z){case"application/json":F=await J.json();break;case"text/plain":F=await J.text();break;case"application/x-www-form-urlencoded":F=$1.parse(await J.text());break;case"application/octet-stream":F=await J.arrayBuffer();break;case"multipart/form-data":F={};const D=await J.formData();for(let T of D.keys()){if(F[T])continue;const q=D.getAll(T);if(q.length===1)F[T]=q[0];else F[T]=q}break}}}Q.body=F,Q.params=Y?.params||void 0,Q.query=X===-1?{}:$1.parse(w.substring(X+1)),Q.headers={};for(let[z,M]of J.headers.entries())Q.headers[z]=M;const C=Object.assign({},$.config?.cookie,U?.cookie?.config),P=J.headers.get("cookie");Q.cookie=await p0(Q.set,P,C?{secrets:C.secrets!==void 0?typeof C.secrets==="string"?C.secrets:C.secrets.join(","):void 0,sign:C.sign===!0?!0:C.sign!==void 0?typeof C.sign==="string"?C.sign:C.sign.join(","):void 0}:void 0);for(let z=0;z<K.transform.length;z++){const M=K.transform[z],D=M.fn(Q);if(M.subType==="derive")if(D instanceof Promise)Object.assign(Q,await D);else Object.assign(Q,D);else if(D instanceof Promise)await D}if(U){if(U.headers){const z={};for(let M in J.headers)z[M]=J.headers.get(M);if(U.headers.Check(z)===!1)throw new I("header",U.headers,z)}if(U.params?.Check(Q.params)===!1)throw new I("params",U.params,Q.params);if(U.query?.Check(Q.query)===!1)throw new I("query",U.query,Q.query);if(U.cookie){const z={};for(let[M,D]of Object.entries(Q.cookie))z[M]=D.value;if(U.cookie?.Check(z)===!1)throw new I("cookie",U.cookie,z)}if(U.body?.Check(F)===!1)throw new I("body",U.body,F)}for(let z=0;z<K.beforeHandle.length;z++){let M=K.beforeHandle[z].fn(Q);if(M instanceof Promise)M=await M;if(M!==void 0){Q.response=M;for(let T=0;T<K.afterHandle.length;T++){let q=K.afterHandle[T].fn(Q);if(q instanceof Promise)q=await q;if(q)M=q}const D=f(M,Q.set);if(D)return D}}let S=G(Q);if(S instanceof Promise)S=await S;if(!K.afterHandle.length){const z=U?.response?.[S.status];if(z?.Check(S)===!1)throw new I("response",z,S)}else{Q.response=S;for(let z=0;z<K.afterHandle.length;z++){let M=K.afterHandle[z].fn(Q);if(M instanceof Promise)M=await M;const D=f(M,Q.set);if(D!==void 0){const T=U?.response?.[S.status];if(T?.Check(D)===!1)throw new I("response",T,D);return D}}}if(Q.set.cookie&&C?.sign){const z=!C.secrets?void 0:typeof C.secrets==="string"?C.secrets:C.secrets[0];if(C.sign===!0)for(let[M,D]of Object.entries(Q.set.cookie))Q.set.cookie[M].value=await _0(D.value,"${secret}");else{const M=U?.cookie?.schema?.properties;for(let D of C.sign){if(!(D in M))continue;if(Q.set.cookie[D]?.value)Q.set.cookie[D].value=await _0(Q.set.cookie[D].value,z)}}}return h(S,Q.set)}catch(Y){if(Y.status)Z.status=Y.status;return $.handleError(Q,Y)}finally{for(let Y of $.event.onResponse)await Y.fn(Q)}},C$=($)=>async(J,w)=>{const B=Object.assign(J,{error:w,code:w.code});B.set=J.set;for(let X=0;X<$.event.error.length;X++){let Z=$.event.error[X].fn(B);if(Z instanceof Promise)Z=await Z;if(Z!==void 0&&Z!==null)return h(Z,J.set)}return new Response(typeof w.cause==="string"?w.cause:w.message,{headers:J.set.headers,status:w.status??500})};import{TypeRegistry as O$} from"@sinclair/typebox";import{TypeSystem as D0} from"@sinclair/typebox/system";import{Type as H0,FormatRegistry as o} from"@sinclair/typebox";import{Value as C0} from"@sinclair/typebox/value";var RJ=function($){return $%4===0&&($%100!==0||$%400===0)},A$=function($){const J=_J.exec($);if(!J)return!1;const w=+J[1],B=+J[2],X=+J[3];return B>=1&&B<=12&&X>=1&&X<=(B===2&&RJ(w)?29:jJ[B])},V1=function($){return function J(w){const B=FJ.exec(w);if(!B)return!1;const X=+B[1],W=+B[2],Z=+B[3],Q=B[4],Y=B[5]==="-"?-1:1,G=+(B[6]||0),K=+(B[7]||0);if(G>23||K>59||$&&!Q)return!1;if(X<=23&&W<=59&&Z<60)return!0;const U=W-K*Y,R=X-G*Y-(U<0?1:0);return(R===23||R===-1)&&(U===59||U===-1)&&Z<61}},D$=function($){const J=V1($);return function w(B){const X=B.split(CJ);return X.length===2&&A$(X[0])&&J(X[1])}},NJ=function($){return DJ.test($)&&MJ.test($)},AJ=function($){return M$.lastIndex=0,M$.test($)},VJ=function($){return Number.isInteger($)&&$<=OJ&&$>=PJ},qJ=function($){return Number.isInteger($)},N$=function(){return!0},bJ=function($){if(IJ.test($))return!1;try{return new RegExp($),!0}catch(J){return!1}},J1={date:A$,time:V1(!0),"date-time":D$(!0),"iso-time":V1(!1),"iso-date-time":D$(!1),duration:/^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,uri:NJ,"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,"uri-template":/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,url:/^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,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,hostname:/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/,ipv6:/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,regex:bJ,uuid:/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,"json-pointer":/^(?:\/(?:[^~/]|~0|~1)*)*$/,"json-pointer-uri-fragment":/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,"relative-json-pointer":/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,byte:AJ,int32:{type:"number",validate:VJ},int64:{type:"number",validate:qJ},float:{type:"number",validate:N$},double:{type:"number",validate:N$},password:!0,binary:!0},_J=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,jJ=[0,31,28,31,30,31,30,31,31,30,31,30,31],FJ=/^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i,CJ=/t|\s/i,DJ=/\/|:/,MJ=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,M$=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm,PJ=-2147483648,OJ=2147483647,IJ=/[^\\]\\Z/;import{TypeSystemPolicy as rw,TypeSystem as nw,TypeSystemDuplicateFormat as ow,TypeSystemDuplicateTypeKind as aw} from"@sinclair/typebox/system";import{TypeCompiler as $8,TypeCheck as J8} from"@sinclair/typebox/compiler";var V$=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,q$=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,I$=/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/,TJ=J1.date,EJ=J1["date-time"];if(!o.Has("date"))D0.Format("date",($)=>{const J=$.replace(/"/g,"");if(V$.test(J)||q$.test(J)||I$.test(J)||TJ(J)){const w=new Date(J);if(!Number.isNaN(w.getTime()))return!0}return!1});if(!o.Has("date-time"))D0.Format("date-time",($)=>{const J=$.replace(/"/g,"");if(V$.test(J)||q$.test(J)||I$.test(J)||EJ(J)){const w=new Date(J);if(!Number.isNaN(w.getTime()))return!0}return!1});Object.entries(J1).forEach(($)=>{const[J,w]=$;if(!o.Has(J)){if(w instanceof RegExp)D0.Format(J,(B)=>w.test(B));else if(typeof w==="function")D0.Format(J,w)}});var V=Object.assign({},H0),P$=($)=>{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 $},q1=($,J)=>{if(!(J instanceof Blob))return!1;if($.minSize&&J.size<P$($.minSize))return!1;if($.maxSize&&J.size>P$($.maxSize))return!1;if($.extension)if(typeof $.extension==="string"){if(!J.type.startsWith($.extension))return!1}else{for(let w=0;w<$.extension.length;w++)if(J.type.startsWith($.extension[w]))return!0;return!1}return!0},LJ=O$.Get("Files")??D0.Type("File",q1),HJ=O$.Get("Files")??D0.Type("Files",($,J)=>{if(!Array.isArray(J))return q1($,J);if($.minItems&&J.length<$.minItems)return!1;if($.maxItems&&J.length>$.maxItems)return!1;for(let w=0;w<J.length;w++)if(!q1($,J[w]))return!1;return!0});if(!o.Has("numeric"))o.Set("numeric",($)=>!!$&&!isNaN(+$));if(!o.Has("boolean"))o.Set("boolean",($)=>$==="true"||$==="false");if(!o.Has("ObjectString"))o.Set("ObjectString",($)=>{let J=$.charCodeAt(0);if(J===9||J===10||J===32)J=$.trimStart().charCodeAt(0);if(J!==123&&J!==91)return!1;try{return JSON.parse($),!0}catch{return!1}});var a={Numeric:($)=>{const J=H0.Number($);return V.Transform(V.Union([V.String({format:"numeric",default:0}),V.Number($)],$)).Decode((w)=>{const B=+w;if(isNaN(B))return w;if($&&!C0.Check(J,B))throw new I("property",J,B);return B}).Encode((w)=>w)},Date:($)=>{const J=H0.Date($);return V.Transform(V.Union([H0.Date($),V.String({format:"date",default:(new Date()).toISOString()}),V.String({format:"date-time",default:(new Date()).toISOString()})],$)).Decode((w)=>{if(w instanceof Date)return w;const B=new Date(w);if(!C0.Check(J,B))throw new I("property",J,B);return B}).Encode((w)=>{if(typeof w==="string")return new Date(w);return w})},BooleanString:($)=>{const J=H0.Boolean($);return V.Transform(V.Union([V.String({format:"boolean",default:!1}),V.Boolean($)],$)).Decode((w)=>{if(typeof w==="string")return w==="true";if($&&!C0.Check(J,w))throw new I("property",J,w);return w}).Encode((w)=>w)},ObjectString:($={},J)=>{const w=V.Object($,J),B=JSON.stringify(C0.Create(w));return V.Transform(V.Union([V.String({format:"ObjectString",default:B}),w])).Decode((X)=>{if(typeof X==="string"){try{X=JSON.parse(X)}catch{throw new I("property",w,X)}if(!C0.Check(w,X))throw new I("property",w,X);return X}return X}).Encode((X)=>{if(typeof X==="string")try{X=JSON.parse(X)}catch{throw new I("property",w,X)}if(!C0.Check(w,X))throw new I("property",w,X);return JSON.stringify(X)})},File:LJ,Files:($={})=>V.Transform(HJ($)).Decode((J)=>{if(Array.isArray(J))return J;return[J]}).Encode((J)=>J),Nullable:($)=>V.Union([V.Null(),$]),MaybeEmpty:($)=>V.Union([V.Null(),V.Undefined(),$]),Cookie:($,{domain:J,expires:w,httpOnly:B,maxAge:X,path:W,priority:Z,sameSite:Q,secure:Y,secrets:G,sign:K,...U}={})=>{const R=V.Object($,U);return R.config={domain:J,expires:w,httpOnly:B,maxAge:X,path:W,priority:Z,sameSite:Q,secure:Y,secrets:G,sign:K},R}};V.BooleanString=a.BooleanString;V.ObjectString=a.ObjectString;V.Numeric=a.Numeric;V.File=($={})=>a.File({default:"File",...$,extension:$?.type,type:"string",format:"binary"});V.Files=($={})=>a.Files({...$,elysiaMeta:"Files",default:"Files",extension:$?.type,type:"array",items:{...$,default:"Files",type:"string",format:"binary"}});V.Nullable=($)=>a.Nullable($);V.MaybeEmpty=a.MaybeEmpty;V.Cookie=a.Cookie;V.Date=a.Date;class s{config;server=null;dependencies={};reporter=new x1;_routes={};_types={Prefix:"",Scoped:!1,Singleton:{},Definitions:{},Metadata:{}};_ephemeral={};_volatile={};singleton={decorator:{},store:{},derive:{},resolve:{}};get store(){return this.singleton.store}get decorator(){return this.singleton.decorator}get _scoped(){return this.config.scoped}definitions={type:{},error:{}};extender={macros:[]};validator=null;event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],mapResponse:[],onResponse:[],trace:[],error:[],stop:[]};telemetry={stack:void 0};router={http:new B0,ws:new B0,dynamic:new B0,static:{http:{handlers:[],variables:"",map:{},all:""},ws:{}},history:[]};inference={event:{body:!1,cookie:!1,headers:!1,queries:[],query:!1,set:!1,unknownQueries:!1},trace:{request:!1,parse:!1,transform:!1,handle:!1,beforeHandle:!1,afterHandle:!1,error:!1,context:!1,store:!1,set:!1}};promisedModules=new _1;constructor($){if($?.tags)if(!$.detail)$.detail={tags:$.tags};else $.detail.tags=$.tags;if(this.config={forceErrorEncapsulation:!0,prefix:"",aot:!0,strictPath:!1,global:!1,cookie:{},analytic:!1,...$,experimental:$?.experimental??{},seed:$?.seed===void 0?"":$?.seed},$?.analytic&&($?.name||$?.seed!==void 0))this.telemetry.stack=new Error().stack}getServer(){return this.server}get routes(){return this.router.history}routeTree=new Map;applyMacro($){if(this.extender.macros.length){const J=o1({globalHook:this.event,localHook:$}),w={events:{global:this.event,local:$},onParse:J("parse"),onTransform:J("transform"),onBeforeHandle:J("beforeHandle"),onAfterHandle:J("afterHandle"),onResponse:J("onResponse"),mapResponse:J("mapResponse"),onError:J("error")};for(let B of this.extender.macros)R1(B.fn(w),$)}}add($,J,w,B,{allowMeta:X=!1,skipPrefix:W=!1}={allowMeta:!1,skipPrefix:!1}){if(B=a1(B),J!==""&&J.charCodeAt(0)!==47)J="/"+J;if(this.config.prefix&&!W&&!this.config.scoped)J=this.config.prefix+J;if(B?.type)switch(B.type){case"text":B.type="text/plain";break;case"json":B.type="application/json";break;case"formdata":B.type="multipart/form-data";break;case"urlencoded":B.type="application/x-www-form-urlencoded";break;case"arrayBuffer":B.type="application/octet-stream";break;default:break}const Z=this.definitions.type;let Q,Y,G,K,U,R;const F=!this.config.aot,C={body:B?.body??this.validator?.body,headers:B?.headers??this.validator?.headers,params:B?.params??this.validator?.params,query:B?.query??this.validator?.query,cookie:B?.cookie??this.validator?.cookie,response:B?.response??this.validator?.response},P=()=>C.cookie?l0({validator:C.cookie,defaultConfig:this.config.cookie,config:C.cookie?.config??{},dynamic:F,models:Z}):void 0,S=this.config.normalize,z=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.schema===!0?{body:k(C.body,{dynamic:F,models:Z,normalize:S}),headers:k(C.headers,{dynamic:F,models:Z,additionalProperties:!0}),params:k(C.params,{dynamic:F,models:Z}),query:k(C.query,{dynamic:F,models:Z,normalize:S}),cookie:P(),response:s0(C.response,{dynamic:F,models:Z,normalize:S})}:{get body(){if(Q)return Q;return Q=k(C.body,{dynamic:F,models:Z,normalize:S})},get headers(){if(Y)return Y;return k(C.headers,{dynamic:F,models:Z,additionalProperties:!0})},get params(){if(G)return G;return G=k(C.params,{dynamic:F,models:Z})},get query(){if(K)return K;return K=k(C.query,{dynamic:F,models:Z})},get cookie(){if(U)return U;return U=P()},get response(){if(R)return R;return R=s0(C.response,{dynamic:F,models:Z,normalize:S})}},M=J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(B=u(B,{},{allowMacro:!0}),B.tags)if(!B.detail)B.detail={tags:B.tags};else B.detail.tags=B.tags;if(m(this.config.detail))B.detail=p(Object.assign({},this.config.detail),B.detail);this.applyMacro(B);const D=u(this.event,B);if(this.config.aot===!1){if(this.router.dynamic.add($,J,{validator:z,hooks:D,content:B?.type,handle:w}),this.config.strictPath===!1)this.router.dynamic.add($,M,{validator:z,hooks:D,content:B?.type,handle:w});this.router.history.push({method:$,path:J,composed:null,handler:w,hooks:D});return}let T=void 0;const q=this.config.precompile===!0||typeof this.config.precompile==="object"&&this.config.precompile.compose===!0,e=r0(this.inference),v=q?e0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:z,handler:w,allowMeta:X,appInference:e}):(A)=>{if(T)return T(A);return(T=e0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:z,handler:w,allowMeta:X,appInference:e}))(A)};if(!q)v.compose=()=>{return v.composed=e0({app:this,path:J,method:$,localHook:u(B),hooks:D,validator:z,handler:w,allowMeta:X,appInference:e})};let t=this.router.history.length;if(this.routeTree.has($+J)){if(t=this.router.history.findIndex((A)=>A.path===J&&A.method===$),t!==-1){const A=this.router.history.splice(t,1)[0];if(A&&this.routeTree.has(A?.method+A?.path))this.routeTree.delete(A.method+A.path)}}this.routeTree.set($+J,t),this.router.history.push({method:$,path:J,composed:v,handler:w,hooks:D});const O=this.router.static.http;if($==="$INTERNALWS"){const A=this.config.strictPath?void 0:J.endsWith("/")?J.slice(0,J.length-1):J+"/";if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const $0=O.handlers.length;if(O.handlers.push(v),O.variables+=`const st${$0} = staticRouter.handlers[${$0}]\n`,this.router.static.ws[J]=$0,A)this.router.static.ws[A]=$0}else if(this.router.ws.add("ws",J,v),A)this.router.ws.add("ws",A,v);return}if(J.indexOf(":")===-1&&J.indexOf("*")===-1){const A=O.handlers.length;if(O.handlers.push(v),O.variables+=q?`const st${A} = staticRouter.handlers[${A}]\n`:`let st${A} = staticRouter.handlers[${A}]\nlet stc${A}\n`,!O.map[J])O.map[J]={code:""};if($==="ALL")O.map[J].all=q?`default: return st${A}(ctx)\n`:`default: ${L0(A)}\n`;else O.map[J].code=q?`case '${$}': return st${A}(ctx)\n${O.map[J].code}`:`case '${$}': ${L0(A)}\n${O.map[J].code}`;if(!this.config.strictPath){if(!O.map[M])O.map[M]={code:""};if($==="ALL")O.map[M].all=q?`default: return st${A}(ctx)\n`:`default: ${L0(A)}\n`;else O.map[M].code=q?`case '${$}': return st${A}(ctx)\n${O.map[M].code}`:`case '${$}': ${L0(A)}\n${O.map[M].code}`}}else if(this.router.http.add($,J,v),!this.config.strictPath)this.router.http.add($,J.endsWith("/")?J.slice(0,J.length-1):J+"/",v)}setHeaders;headers($){if(!$)return this;if(!this.setHeaders)this.setHeaders={};return this.setHeaders=p(this.setHeaders,$),this}onStart($){return this.on("start",$),this}onRequest($){return this.on("request",$),this}onParse($,J){if(!J)return this.on("parse",$);return this.on($,"parse",J)}onTransform($,J){if(!J)return this.on("transform",$);return this.on($,"transform",J)}resolve($,J){if(!J)J=$,$={as:"local"};const w={subType:"resolve",fn:J};return this.onBeforeHandle($,w)}mapResolve($,J){if(!J)J=$,$={as:"local"};const w={subType:"resolve",fn:J};return this.onBeforeHandle($,w)}onBeforeHandle($,J){if(!J)return this.on("beforeHandle",$);return this.on($,"beforeHandle",J)}onAfterHandle($,J){if(!J)return this.on("afterHandle",$);return this.on($,"afterHandle",J)}mapResponse($,J){if(!J)return this.on("mapResponse",$);return this.on($,"mapResponse",J)}onResponse($,J){if(!J)return this.on("response",$);return this.on($,"response",J)}trace($,J){if(!J)J=$,$={as:"local"};if(!Array.isArray(J))J=[J];for(let w of J)this.reporter.on("event",g1(()=>this.reporter,this.event.trace.length,w));return this.on($,"trace",J),this}error($,J){switch(typeof $){case"string":return J.prototype[Z0]=$,this.definitions.error[$]=J,this;case"function":return this.definitions.error=$(this.definitions.error),this}for(let[w,B]of Object.entries($))B.prototype[Z0]=w,this.definitions.error[w]=B;return this}onError($,J){if(!J)return this.on("error",$);return this.on($,"error",J)}onStop($){return this.on("stop",$),this}on($,J,w){let B;switch(typeof $){case"string":B=$,w=J;break;case"object":B=J;break}if(B==="response")B="onResponse";if(Array.isArray(w))w=c(w);else if(typeof w==="function")w=[{fn:w}];else w=[w];const X=w;for(let W of X)W.scope=typeof $==="string"?"local":$?.as??"local";if(B==="trace")h1(X.map((W)=>W.fn),this.inference.trace);else m0({[B]:X.map((W)=>W.fn)},this.inference.event);for(let W of X){const Z=n1(W,"global",{skipIfHasType:!0});switch(B){case"start":this.event.start.push(Z);break;case"request":this.event.request.push(Z);break;case"parse":this.event.parse.push(Z);break;case"transform":this.event.transform.push(Z);break;case"beforeHandle":this.event.beforeHandle.push(Z);break;case"afterHandle":this.event.afterHandle.push(Z);break;case"mapResponse":this.event.mapResponse.push(Z);break;case"onResponse":this.event.onResponse.push(Z);break;case"trace":this.event.trace.push(Z);break;case"error":this.event.error.push(Z);break;case"stop":this.event.stop.push(Z);break}}return this}propagate(){const $=(J)=>{for(let w of J)if("scope"in w&&w.scope==="local")w.scope="scoped"};return $(this.event.parse),$(this.event.transform),$(this.event.beforeHandle),$(this.event.afterHandle),$(this.event.mapResponse),$(this.event.onResponse),$(this.event.trace),$(this.event.error),this}group($,J,w){const B=new s({...this.config,prefix:""});B.singleton={...this.singleton},B.definitions={...this.definitions},B.getServer=()=>this.server,B.inference=r0(this.inference);const X=typeof J==="object",W=(X?w:J)(B);if(this.singleton=p(this.singleton,B.singleton),this.definitions=p(this.definitions,B.definitions),W.event.request.length)this.event.request=[...this.event.request||[],...W.event.request||[]];if(W.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...W.event.onResponse||[]];return this.model(W.definitions.type),Object.values(B.router.history).forEach(({method:Z,path:Q,handler:Y,hooks:G})=>{if(Q=(X?"":this.config.prefix)+$+Q,X){const K=J,U=G;this.add(Z,Q,Y,u(K,{...U||{},error:!U.error?W.event.error:Array.isArray(U.error)?[...U.error||{},...W.event.error||{}]:[U.error,...W.event.error||{}]}))}else this.add(Z,Q,Y,u(G,{error:W.event.error}),{skipPrefix:!0})}),this}guard($,J){if(!J){if(typeof $==="object"){if(this.applyMacro($),this.event=i0(this.event,$),this.validator={body:$.body??this.validator?.body,headers:$.headers??this.validator?.headers,params:$.params??this.validator?.params,query:$.query??this.validator?.query,response:$.response??this.validator?.response,cookie:$.cookie??this.validator?.cookie},$.detail)if(this.config.detail)this.config.detail=p(Object.assign({},this.config.detail),$.detail);else this.config.detail=$.detail;if($?.tags)if(!this.config.detail)this.config.detail={tags:$.tags};else this.config.detail.tags=$.tags;return this}return this.guard({},$)}const w=new s({...this.config,prefix:""});w.singleton={...this.singleton},w.definitions={...this.definitions},w.inference=r0(this.inference);const B=J(w);if(this.singleton=p(this.singleton,w.singleton),this.definitions=p(this.definitions,w.definitions),B.getServer=()=>this.server,B.event.request.length)this.event.request=[...this.event.request||[],...B.event.request||[]];if(B.event.onResponse.length)this.event.onResponse=[...this.event.onResponse||[],...B.event.onResponse||[]];return this.model(B.definitions.type),Object.values(w.router.history).forEach(({method:X,path:W,handler:Z,hooks:Q})=>{this.add(X,W,Z,u($,{...Q||{},error:!Q.error?B.event.error:Array.isArray(Q.error)?[...Q.error||{},...B.event.error||[]]:[Q.error,...B.event.error||[]]},{allowMacro:!0}))}),this}use($,J){if(J?.scoped)return this.guard({},(w)=>w.use($));if(Array.isArray($)){let w=this;for(let B of $)w=this.use(B);return w}if($ instanceof Promise)return this.promisedModules.add($.then((w)=>{if(typeof w==="function")return w(this);if(w instanceof s)return this._use(w);if(typeof w.default==="function")return w.default(this);if(w.default instanceof s)return this._use(w.default);throw new Error('Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.')}).then((w)=>w.compile())),this;return this._use($)}_use($){if(typeof $==="function"){const X=$(this);if(X instanceof Promise)return this.promisedModules.add(X.then((W)=>{if(W instanceof s){this.compile();for(let{method:Z,path:Q,handler:Y,hooks:G}of Object.values(W.router.history))this.add(Z,Q,Y,u(G,{error:W.event.error}));return W}if(typeof W==="function")return W(this);if(typeof W.default==="function")return W.default(this);return this._use(W)}).then((W)=>W.compile())),this;return X}if($.promisedModules.size)return this.promisedModules.add($.modules.then(()=>this._use($)).then((X)=>X.compile())),this;const{name:J,seed:w}=$.config;$.getServer=()=>this.getServer(),$.model(this.definitions.type),$.error(this.definitions.error);const B=$.config.scoped;if(B){if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const W=w!==void 0?q0(J+JSON.stringify(w)):0;if(this.dependencies[J].some(({checksum:Z})=>W===Z))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:W,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:W,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton.decorator,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((Z)=>Z.subType==="derive").map((Z)=>({fn:Z.fn.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((Z)=>Z.subType==="derive").map((Z)=>({fn:Z.fn.toString(),stack:new Error().stack??""}))})}$.extender.macros=this.extender.macros.concat($.extender.macros);const X=[];for(let W=0;W<$.extender.macros.length;W++){const Z=this.extender.macros[W];if(X.includes(Z.checksum))$.extender.macros.splice(W,1),W--;X.push(Z.checksum)}if($.onRequest((W)=>{Object.assign(W,this.singleton.decorator),Object.assign(W.store,this.singleton.store)}),$.event.trace.length)$.event.trace.push(...$.event.trace);if(!$.config.prefix)console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance.");if($.event.error.length)$.event.error.push(...this.event.error);if($.config.aot)$.compile();if(B===!0&&$.config.prefix){this.mount($.config.prefix+"/",$.fetch);for(let W of $.router.history)this.routeTree.set(W.method+`${$.config.prefix}${W.path}`,this.router.history.length),this.router.history.push({...W,path:`${$.config.prefix}${W.path}`,hooks:u(W.hooks,{error:this.event.error})})}else{this.mount($.fetch);for(let W of $.router.history)this.routeTree.set(W.method+`${$.config.prefix}${W.path}`,this.router.history.length),this.router.history.push({...W,path:`${$.config.prefix}${W.path}`,hooks:u(W.hooks,{error:this.event.error})})}return this}else{this.headers($.setHeaders),$.reporter=this.reporter;for(let W of $.event.trace)if(W.scope&&W.scope!=="local")this.trace(W);if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const W=w!==void 0?q0(J+JSON.stringify(w)):0;if(!this.dependencies[J].some(({checksum:Z})=>W===Z))this.extender.macros=this.extender.macros.concat($.extender.macros)}else this.extender.macros=this.extender.macros.concat($.extender.macros);const X=[];for(let W=0;W<this.extender.macros.length;W++){const Z=this.extender.macros[W];if(Z.checksum){if(X.includes(Z.checksum))this.extender.macros.splice(W,1),W--;X.push(Z.checksum)}}this.inference={event:{body:this.inference.event.body||$.inference.event.body,cookie:this.inference.event.cookie||$.inference.event.cookie,headers:this.inference.event.headers||$.inference.event.headers,queries:[...this.inference.event.queries,...$.inference.event.queries],query:this.inference.event.query||$.inference.event.query,set:this.inference.event.set||$.inference.event.set,unknownQueries:this.inference.event.unknownQueries||$.inference.event.unknownQueries},trace:{request:this.inference.trace.request||$.inference.trace.request,parse:this.inference.trace.parse||$.inference.trace.parse,transform:this.inference.trace.transform||$.inference.trace.transform,handle:this.inference.trace.handle||$.inference.trace.handle,beforeHandle:this.inference.trace.beforeHandle||$.inference.trace.beforeHandle,afterHandle:this.inference.trace.afterHandle||$.inference.trace.afterHandle,error:this.inference.trace.error||$.inference.trace.error,context:this.inference.trace.context||$.inference.trace.context,store:this.inference.trace.store||$.inference.trace.store,set:this.inference.trace.set||$.inference.trace.set}}}this.decorate($.singleton.decorator),this.state($.singleton.store),this.model($.definitions.type),this.error($.definitions.error);for(let{method:X,path:W,handler:Z,hooks:Q}of Object.values($.router.history))this.add(X,W,Z,u(Q,{error:$.event.error}));if(!B)if(J){if(!(J in this.dependencies))this.dependencies[J]=[];const X=w!==void 0?q0(J+JSON.stringify(w)):0;if(this.dependencies[J].some(({checksum:W})=>X===W))return this;this.dependencies[J].push(!this.config?.analytic?{name:$.config.name,seed:$.config.seed,checksum:X,dependencies:$.dependencies}:{name:$.config.name,seed:$.config.seed,checksum:X,dependencies:$.dependencies,stack:$.telemetry.stack,routes:$.router.history,decorators:$.singleton,store:$.singleton.store,type:$.definitions.type,error:$.definitions.error,derive:$.event.transform.filter((W)=>W?.subType==="derive").map((W)=>({fn:W.toString(),stack:new Error().stack??""})),resolve:$.event.transform.filter((W)=>W?.subType==="resolve").map((W)=>({fn:W.toString(),stack:new Error().stack??""}))}),this.event=i0(this.event,z1($.event),X)}else this.event=i0(this.event,z1($.event));return this}macro($){const J={checksum:q0(JSON.stringify({name:this.config.name,seed:this.config.seed,content:$.toString()})),fn:$};return this.extender.macros.push(J),this}mount($,J){if($ instanceof s||typeof $==="function"||$.length===0||$==="/"){const X=typeof $==="function"?$:$ instanceof s?$.compile().fetch:J instanceof s?J.compile().fetch:J,W=async({request:Z,path:Q})=>X(new Request(U1(Z.url,Q||"/"),Z));return this.all("/*",W,{type:"none"}),this}const w=$.length;if(J instanceof s)J=J.compile().fetch;const B=async({request:X,path:W})=>J(new Request(U1(X.url,W.slice(w)||"/"),X));return this.all($,B,{type:"none"}),this.all($+($.endsWith("/")?"*":"/*"),B,{type:"none"}),this}get($,J,w){return this.add("GET",$,J,w),this}post($,J,w){return this.add("POST",$,J,w),this}put($,J,w){return this.add("PUT",$,J,w),this}patch($,J,w){return this.add("PATCH",$,J,w),this}delete($,J,w){return this.add("DELETE",$,J,w),this}options($,J,w){return this.add("OPTIONS",$,J,w),this}all($,J,w){return this.add("ALL",$,J,w),this}head($,J,w){return this.add("HEAD",$,J,w),this}connect($,J,w){return this.add("CONNECT",$,J,w),this}route($,J,w,B){return this.add($.toUpperCase(),J,w,B,B?.config),this}ws($,J){const w=J.transformMessage?Array.isArray(J.transformMessage)?J.transformMessage:[J.transformMessage]:void 0;let B=null;const X=k(J?.body,{models:this.definitions.type,normalize:this.config.normalize}),W=k(J?.response,{models:this.definitions.type,normalize:this.config.normalize}),Z=(Q)=>{if(typeof Q==="string"){const Y=Q?.charCodeAt(0);if(Y===47||Y===123)try{Q=JSON.parse(Q)}catch{}else if(z0(Q))Q=+Q}if(w?.length)for(let Y=0;Y<w.length;Y++){const G=w[Y](Q);if(G!==void 0)Q=G}return Q};return this.route("$INTERNALWS",$,(Q)=>{const{set:Y,path:G,qi:K,headers:U,query:R,params:F}=Q;if(B===null)B=this.getServer();if(B?.upgrade(Q.request,{headers:typeof J.upgrade==="function"?J.upgrade(Q):J.upgrade,data:{validator:W,open(C){J.open?.(new j0(C,Q))},message:(C,P)=>{const S=Z(P);if(X?.Check(S)===!1)return void C.send(new I("message",X,S).message);J.message?.(new j0(C,Q),S)},drain(C){J.drain?.(new j0(C,Q))},close(C,P,S){J.close?.(new j0(C,Q),P,S)}}}))return;return Y.status=400,"Expected a websocket connection"},{beforeHandle:J.beforeHandle,transform:J.transform,headers:J.headers,params:J.params,query:J.query}),this}state($,J){switch(typeof $){case"object":return this.singleton.store=p(this.singleton.store,$),this;case"function":return this.singleton.store=$(this.singleton.store),this}if(!($ in this.singleton.store))this.singleton.store[$]=J;return this}decorate($,J){switch(typeof $){case"object":return this.singleton.decorator=p(this.singleton.decorator,$),this;case"function":return this.singleton.decorator=$(this.singleton.decorator),this}if(!($ in this.singleton.decorator))this.singleton.decorator[$]=J;return this}derive($,J){if(!J)J=$,$={as:"local"};const w={subType:"derive",fn:J};return this.onTransform($,w)}model($,J){switch(typeof $){case"object":return Object.entries($).forEach(([w,B])=>{if(!(w in this.definitions.type))this.definitions.type[w]=B}),this;case"function":return this.definitions.type=$(this.definitions.type),this}return this.definitions.type[$]=J,this}mapDerive($,J){if(!J)J=$,$={as:"local"};const w={subType:"derive",fn:J};return this.onTransform($,w)}affix($,J,w){if(w==="")return this;const B=["_","-"," "],X=(Y)=>Y[0].toUpperCase()+Y.slice(1),W=$==="prefix"?(Y,G)=>B.includes(Y.at(-1)??"")?Y+G:Y+X(G):B.includes(w.at(-1)??"")?(Y,G)=>G+Y:(Y,G)=>G+X(Y),Z=(Y)=>{const G={};switch(Y){case"decorator":for(let K in this.singleton.decorator)G[W(w,K)]=this.singleton.decorator[K];this.singleton.decorator=G;break;case"state":for(let K in this.singleton.store)G[W(w,K)]=this.singleton.store[K];this.singleton.store=G;break;case"model":for(let K in this.definitions.type)G[W(w,K)]=this.definitions.type[K];this.definitions.type=G;break;case"error":for(let K in this.definitions.error)G[W(w,K)]=this.definitions.error[K];this.definitions.error=G;break}},Q=Array.isArray(J)?J:[J];for(let Y of Q.some((G)=>G==="all")?["decorator","state","model","error"]:Q)Z(Y);return this}prefix($,J){return this.affix("prefix",$,J)}suffix($,J){return this.affix("suffix",$,J)}compile(){if(this.fetch=this.config.aot?A1(this):O1(this),typeof this.server?.reload==="function")this.server.reload({...this.server||{},fetch:this.fetch});return this}handle=async($)=>this.fetch($);fetch=($)=>{return(this.fetch=this.config.aot?A1(this):O1(this))($)};handleError=async($,J)=>(this.handleError=this.config.aot?P1(this):C$(this))($,J);outerErrorHandler=($)=>new Response($.message||$.name||"Error",{status:$?.status??500});listen=($,J)=>{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.compile(),typeof $==="string"){if(!z0($))throw new Error("Port must be a numeric value");$=parseInt($)}const w=this.fetch,B=typeof $==="object"?{development:!I0,reusePort:!0,...this.config.serve||{},...$||{},websocket:{...this.config.websocket||{},...C1||{}},fetch:w,error:this.outerErrorHandler}:{development:!I0,reusePort:!0,...this.config.serve||{},websocket:{...this.config.websocket||{},...C1||{}},port:$,fetch:w,error:this.outerErrorHandler};this.server=Bun?.serve(B);for(let X=0;X<this.event.start.length;X++)this.event.start[X].fn(this);if(J)J(this.server);return process.on("beforeExit",()=>{if(this.server){this.server.stop(),this.server=null;for(let X=0;X<this.event.stop.length;X++)this.event.stop[X].fn(this)}}),this.promisedModules.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){if(this.server.stop(),this.server=null,this.event.stop.length)for(let $=0;$<this.event.stop.length;$++)this.event.stop[$].fn(this)}};get modules(){return Promise.all(this.promisedModules.promises)}}export{V as t,j1 as redirect,L as mergeObjectArray,u as mergeHook,h as mapResponse,f as mapEarlyResponse,n as mapCompactResponse,k as getSchemaValidator,s0 as getResponseSchemaValidator,F1 as error,s as default,I as ValidationError,X0 as StatusMap,a0 as ParseError,Q0 as NotFoundError,t0 as InvertedStatusMap,P0 as InvalidCookieSignature,o0 as InternalServerError,s as Elysia,Z0 as ERROR_CODE,d as ELYSIA_RESPONSE,r as Cookie};
|
|
440
441
|
|
|
441
|
-
//# debugId=
|
|
442
|
+
//# debugId=5F007D31F5BE5FB464756e2164756e21
|