Comparing version 1.2.10 to 1.2.11-exp.0
@@ -11,2 +11,2 @@ import type { Context } from '../../context'; | ||
export declare const errorToResponse: (error: Error, set?: Context["set"]) => import("undici-types").Response; | ||
export declare const createStaticHandler: (handle: unknown, hooks: AnyLocalHook, setHeaders?: Context["set"]["headers"]) => (() => Response) | undefined; | ||
export declare const createStaticHandler: (handle: unknown, hooks: Partial<AnyLocalHook>, setHeaders?: Context["set"]["headers"]) => (() => Response) | undefined; |
@@ -34,3 +34,3 @@ "use strict"; | ||
}); | ||
if (hooks.parse.length === 0 && hooks.transform.length === 0 && hooks.beforeHandle.length === 0 && hooks.afterHandle.length === 0) { | ||
if (!hooks.parse?.length && !hooks.transform?.length && !hooks.beforeHandle?.length && !hooks.afterHandle?.length) { | ||
if (!response.headers.has("content-type")) | ||
@@ -37,0 +37,0 @@ response.headers.append("content-type", "text/plain;charset=utf-8"); |
@@ -85,4 +85,5 @@ "use strict"; | ||
app.server = Bun?.serve(serve); | ||
for (let i = 0; i < app.event.start.length; i++) | ||
app.event.start[i].fn(app); | ||
if (app.event.start) | ||
for (let i = 0; i < app.event.start.length; i++) | ||
app.event.start[i].fn(app); | ||
if (callback) callback(app.server); | ||
@@ -93,4 +94,5 @@ process.on("beforeExit", () => { | ||
app.server = null; | ||
for (let i = 0; i < app.event.stop.length; i++) | ||
app.event.stop[i].fn(app); | ||
if (app.event.stop) | ||
for (let i = 0; i < app.event.stop.length; i++) | ||
app.event.stop[i].fn(app); | ||
} | ||
@@ -97,0 +99,0 @@ }); |
@@ -682,3 +682,3 @@ "use strict"; | ||
}); | ||
if (hooks.parse.length === 0 && hooks.transform.length === 0 && hooks.beforeHandle.length === 0 && hooks.afterHandle.length === 0) | ||
if (!hooks.parse?.length && !hooks.transform?.length && !hooks.beforeHandle?.length && !hooks.afterHandle?.length) | ||
return response.clone.bind(response); | ||
@@ -685,0 +685,0 @@ }; |
@@ -82,3 +82,3 @@ "use strict"; | ||
const standardHostname = app.config.handler?.standardHostname ?? true; | ||
const hasTrace = app.event.trace.length > 0; | ||
const hasTrace = !!app.event.trace?.length; | ||
fnLiteral += `const u=r.url,s=u.indexOf('/',${standardHostname ? 11 : 7}),qi=u.indexOf('?', s + 1) | ||
@@ -85,0 +85,0 @@ let p |
@@ -13,8 +13,7 @@ import type { AnyElysia } from '.'; | ||
export declare const isGenerator: (v: Function | HookContainer) => boolean; | ||
export declare const composeHandler: ({ app, path, method, localHook, hooks, validator, handler, allowMeta, inference, asManifest }: { | ||
export declare const composeHandler: ({ app, path, method, hooks, validator, handler, allowMeta, inference, asManifest }: { | ||
app: AnyElysia; | ||
path: string; | ||
method: string; | ||
hooks: LifeCycleStore; | ||
localHook: LifeCycleStore; | ||
hooks: Partial<LifeCycleStore>; | ||
validator: SchemaValidator; | ||
@@ -21,0 +20,0 @@ handler: unknown | Handler<any, any>; |
@@ -100,3 +100,3 @@ "use strict"; | ||
context = "c", | ||
trace, | ||
trace = [], | ||
addFn | ||
@@ -271,3 +271,2 @@ }) => { | ||
method, | ||
localHook, | ||
hooks, | ||
@@ -288,3 +287,3 @@ validator, | ||
}); | ||
if (hooks.parse.length === 0 && hooks.transform.length === 0 && hooks.beforeHandle.length === 0 && hooks.afterHandle.length === 0) { | ||
if (hooks.parse?.length && hooks.transform?.length && hooks.beforeHandle?.length && hooks.afterHandle?.length) { | ||
if (handler instanceof Response) | ||
@@ -299,7 +298,7 @@ return Function( | ||
const handle = isHandleFn ? `handler(c)` : `handler`; | ||
const hasAfterResponse = hooks.afterResponse.length > 0; | ||
const hasTrace = hooks.trace.length > 0; | ||
const hasAfterResponse = !!hooks.afterResponse?.length; | ||
const hasTrace = !!hooks.trace?.length; | ||
let fnLiteral = ""; | ||
inference = (0, import_sucrose.sucrose)( | ||
Object.assign(localHook, { | ||
Object.assign({}, hooks, { | ||
handler | ||
@@ -322,3 +321,3 @@ }), | ||
const hasQuery = inference.query || !!validator.query; | ||
const hasBody = method !== "$INTERNALWS" && method !== "GET" && method !== "HEAD" && (inference.body || !!validator.body || hooks.parse.length); | ||
const hasBody = method !== "$INTERNALWS" && method !== "GET" && method !== "HEAD" && (inference.body || !!validator.body || !!hooks.parse?.length); | ||
if (hasBody) fnLiteral += `let isParsing=false | ||
@@ -506,5 +505,5 @@ `; | ||
const isAsyncHandler = typeof handler === "function" && isAsync(handler); | ||
const saveResponse = hasTrace || hooks.afterResponse.length > 0 ? "c.response= " : ""; | ||
const maybeAsync = hasCookie || hasBody || isAsyncHandler || hooks.parse.length > 0 || hooks.afterHandle.some(isAsync) || hooks.beforeHandle.some(isAsync) || hooks.transform.some(isAsync) || hooks.mapResponse.some(isAsync); | ||
const maybeStream = (typeof handler === "function" ? isGenerator(handler) : false) || hooks.beforeHandle.some(isGenerator) || hooks.afterHandle.some(isGenerator) || hooks.transform.some(isGenerator); | ||
const saveResponse = hasTrace || hooks.afterResponse?.length ? "c.response= " : ""; | ||
const maybeAsync = hasCookie || hasBody || isAsyncHandler || !!hooks.parse?.length || !!hooks.afterHandle?.some(isAsync) || !!hooks.beforeHandle?.some(isAsync) || !!hooks.transform?.some(isAsync) || !!hooks.mapResponse?.some(isAsync); | ||
const maybeStream = (typeof handler === "function" ? isGenerator(handler) : false) || !!hooks.beforeHandle?.some(isGenerator) || !!hooks.afterHandle?.some(isGenerator) || !!hooks.transform?.some(isGenerator); | ||
const hasSet = inference.cookie || inference.set || hasHeaders || hasTrace || validator.response || isHandleFn && hasDefaultHeaders || maybeStream; | ||
@@ -515,7 +514,7 @@ const mapResponseContext = adapter.mapResponseContext ? `,${adapter.mapResponseContext}` : ""; | ||
const parseReporter = report("parse", { | ||
total: hooks.parse.length | ||
total: hooks.parse?.length | ||
}); | ||
if (hasBody) { | ||
const isOptionalBody = isOptional(validator.body); | ||
const hasBodyInference = hooks.parse.length || inference.body || validator.body; | ||
const hasBodyInference = !!hooks.parse?.length || inference.body || validator.body; | ||
if (adapter.parser.declare) fnLiteral += adapter.parser.declare; | ||
@@ -526,3 +525,3 @@ fnLiteral += "\nisParsing=true"; | ||
const reporter = report("parse", { | ||
total: hooks.parse.length | ||
total: hooks.parse?.length | ||
}); | ||
@@ -576,65 +575,66 @@ switch (parser) { | ||
`; | ||
if (hooks.parse.length) fnLiteral += `let used=false | ||
if (hooks.parse?.length) fnLiteral += `let used=false | ||
`; | ||
const reporter = report("parse", { | ||
total: hooks.parse.length | ||
total: hooks.parse?.length | ||
}); | ||
let hasDefaultParser = false; | ||
for (let i = 0; i < hooks.parse.length; i++) { | ||
const name = `bo${i}`; | ||
if (i !== 0) fnLiteral += ` | ||
if (hooks.parse) | ||
for (let i = 0; i < hooks.parse.length; i++) { | ||
const name = `bo${i}`; | ||
if (i !== 0) fnLiteral += ` | ||
if(!used){`; | ||
if (typeof hooks.parse[i].fn === "string") { | ||
const endUnit = reporter.resolveChild( | ||
hooks.parse[i].fn | ||
); | ||
switch (hooks.parse[i].fn) { | ||
case "json": | ||
case "application/json": | ||
hasDefaultParser = true; | ||
fnLiteral += adapter.parser.json(isOptionalBody); | ||
break; | ||
case "text": | ||
case "text/plain": | ||
hasDefaultParser = true; | ||
fnLiteral += adapter.parser.text(isOptionalBody); | ||
break; | ||
case "urlencoded": | ||
case "application/x-www-form-urlencoded": | ||
hasDefaultParser = true; | ||
fnLiteral += adapter.parser.urlencoded(isOptionalBody); | ||
break; | ||
case "arrayBuffer": | ||
case "application/octet-stream": | ||
hasDefaultParser = true; | ||
fnLiteral += adapter.parser.arrayBuffer(isOptionalBody); | ||
break; | ||
case "formdata": | ||
case "multipart/form-data": | ||
hasDefaultParser = true; | ||
fnLiteral += adapter.parser.formData(isOptionalBody); | ||
break; | ||
default: | ||
fnLiteral += `${name}=parser['${hooks.parse[i].fn}'](c,contentType) | ||
if (typeof hooks.parse[i].fn === "string") { | ||
const endUnit = reporter.resolveChild( | ||
hooks.parse[i].fn | ||
); | ||
switch (hooks.parse[i].fn) { | ||
case "json": | ||
case "application/json": | ||
hasDefaultParser = true; | ||
fnLiteral += adapter.parser.json(isOptionalBody); | ||
break; | ||
case "text": | ||
case "text/plain": | ||
hasDefaultParser = true; | ||
fnLiteral += adapter.parser.text(isOptionalBody); | ||
break; | ||
case "urlencoded": | ||
case "application/x-www-form-urlencoded": | ||
hasDefaultParser = true; | ||
fnLiteral += adapter.parser.urlencoded(isOptionalBody); | ||
break; | ||
case "arrayBuffer": | ||
case "application/octet-stream": | ||
hasDefaultParser = true; | ||
fnLiteral += adapter.parser.arrayBuffer(isOptionalBody); | ||
break; | ||
case "formdata": | ||
case "multipart/form-data": | ||
hasDefaultParser = true; | ||
fnLiteral += adapter.parser.formData(isOptionalBody); | ||
break; | ||
default: | ||
fnLiteral += `${name}=parser['${hooks.parse[i].fn}'](c,contentType) | ||
if(${name} instanceof Promise)${name}=await ${name} | ||
if(${name}!==undefined){c.body=${name};used=true} | ||
`; | ||
} | ||
endUnit(); | ||
} else { | ||
const endUnit = reporter.resolveChild( | ||
hooks.parse[i].fn.name | ||
); | ||
fnLiteral += `let ${name}=parse[${i}] | ||
} | ||
endUnit(); | ||
} else { | ||
const endUnit = reporter.resolveChild( | ||
hooks.parse[i].fn.name | ||
); | ||
fnLiteral += `let ${name}=parse[${i}] | ||
${name}=${name}(c,contentType) | ||
if(${name} instanceof Promise)${name}=await ${name} | ||
if(${name}!==undefined){c.body=${name};used=true}`; | ||
endUnit(); | ||
endUnit(); | ||
} | ||
if (i !== 0) fnLiteral += `}`; | ||
if (hasDefaultParser) break; | ||
} | ||
if (i !== 0) fnLiteral += `}`; | ||
if (hasDefaultParser) break; | ||
} | ||
reporter.resolve(); | ||
if (!hasDefaultParser) { | ||
if (hooks.parse.length) | ||
if (hooks.parse?.length) | ||
fnLiteral += ` | ||
@@ -659,3 +659,3 @@ if(!used){ | ||
`; | ||
if (hooks.parse.length) fnLiteral += "}"; | ||
if (hooks.parse?.length) fnLiteral += "}"; | ||
fnLiteral += "}"; | ||
@@ -903,5 +903,5 @@ } | ||
const mapResponseReporter = report("mapResponse", { | ||
total: hooks.mapResponse.length | ||
total: hooks.mapResponse?.length | ||
}); | ||
if (hooks.mapResponse.length) { | ||
if (hooks.mapResponse?.length) { | ||
fnLiteral += `c.response=be | ||
@@ -927,3 +927,3 @@ `; | ||
} | ||
if (hooks?.afterHandle.length) { | ||
if (hooks.afterHandle?.length) { | ||
const handleReporter = report("handle", { | ||
@@ -976,5 +976,5 @@ name: isHandleFn ? handler.name : void 0 | ||
const mapResponseReporter = report("mapResponse", { | ||
total: hooks.mapResponse.length | ||
total: hooks.mapResponse?.length | ||
}); | ||
if (hooks.mapResponse.length) { | ||
if (hooks.mapResponse?.length) { | ||
for (let i = 0; i < hooks.mapResponse.length; i++) { | ||
@@ -1002,3 +1002,3 @@ const mapResponse = hooks.mapResponse[i]; | ||
}); | ||
if (validator.response || hooks.mapResponse.length) { | ||
if (validator.response || hooks.mapResponse?.length) { | ||
fnLiteral += isAsyncHandler ? `let r=await ${handle} | ||
@@ -1011,5 +1011,5 @@ ` : `let r=${handle} | ||
const mapResponseReporter = report("mapResponse", { | ||
total: hooks.mapResponse.length | ||
total: hooks.mapResponse?.length | ||
}); | ||
if (hooks.mapResponse.length) { | ||
if (hooks.mapResponse?.length) { | ||
fnLiteral += "\nc.response=r\n"; | ||
@@ -1046,5 +1046,5 @@ for (let i = 0; i < hooks.mapResponse.length; i++) { | ||
const mapResponseReporter = report("mapResponse", { | ||
total: hooks.mapResponse.length | ||
total: hooks.mapResponse?.length | ||
}); | ||
if (hooks.mapResponse.length) { | ||
if (hooks.mapResponse?.length) { | ||
fnLiteral += "c.response= r\n"; | ||
@@ -1094,3 +1094,3 @@ for (let i = 0; i < hooks.mapResponse.length; i++) { | ||
`; | ||
if (hasTrace) | ||
if (hasTrace && hooks.trace) | ||
for (let i = 0; i < hooks.trace.length; i++) | ||
@@ -1100,5 +1100,5 @@ fnLiteral += `report${i}?.resolve(error);reportChild${i}?.(error) | ||
const errorReporter = report("error", { | ||
total: hooks.error.length | ||
total: hooks.error?.length | ||
}); | ||
if (hooks.error.length) { | ||
if (hooks.error?.length) { | ||
fnLiteral += `c.error=error | ||
@@ -1119,5 +1119,5 @@ if(error instanceof TypeBoxError){c.code="VALIDATION" | ||
const mapResponseReporter = report("mapResponse", { | ||
total: hooks.mapResponse.length | ||
total: hooks.mapResponse?.length | ||
}); | ||
if (hooks.mapResponse.length) { | ||
if (hooks.mapResponse?.length) { | ||
for (let i2 = 0; i2 < hooks.mapResponse.length; i2++) { | ||
@@ -1139,3 +1139,3 @@ const mapResponse = hooks.mapResponse[i2]; | ||
fnLiteral += `if(er){`; | ||
if (hasTrace) { | ||
if (hasTrace && hooks.trace) { | ||
for (let i2 = 0; i2 < hooks.trace.length; i2++) | ||
@@ -1157,5 +1157,5 @@ fnLiteral += `report${i2}.resolve() | ||
const reporter = report("afterResponse", { | ||
total: hooks.afterResponse.length | ||
total: hooks.afterResponse?.length | ||
}); | ||
if (hasAfterResponse) { | ||
if (hasAfterResponse && hooks.afterResponse) { | ||
for (let i = 0; i < hooks.afterResponse.length; i++) { | ||
@@ -1177,7 +1177,7 @@ const endUnit = reporter.resolveChild( | ||
let init = `const {handler,handleError,hooks: {transform,resolve,beforeHandle,afterHandle,mapResponse: onMapResponse,parse,error: handleErrors,afterResponse,trace: _trace},validator,utils: {mapResponse,mapCompactResponse,mapEarlyResponse,parseQuery,parseQueryFromURL,isNotEmpty},error: {NotFoundError,ValidationError,InternalServerError,ParseError},schema,definitions,ERROR_CODE,parseCookie,signCookie,decodeURIComponent,ElysiaCustomStatusResponse,ELYSIA_TRACE,ELYSIA_REQUEST_ID,parser,getServer,` + adapterVariables + `TypeBoxError}=hooks | ||
const trace=_trace.map(x=>typeof x==='function'?x:x.fn) | ||
const trace=_trace?.map(x=>typeof x==='function'?x:x.fn)??[] | ||
return ${maybeAsync ? "async " : ""}function handle(c){`; | ||
if (hooks.beforeHandle.length) init += "let be\n"; | ||
if (hooks.afterHandle.length) init += "let af\n"; | ||
if (hooks.mapResponse.length) init += "let mr\n"; | ||
if (hooks.beforeHandle?.length) init += "let be\n"; | ||
if (hooks.afterHandle?.length) init += "let af\n"; | ||
if (hooks.mapResponse?.length) init += "let mr\n"; | ||
if (allowMeta) init += "c.schema = schema\nc.defs = definitions\n"; | ||
@@ -1275,4 +1275,4 @@ init += fnLiteral + "}"; | ||
const error404 = adapter.error404( | ||
!!app.event.request.length, | ||
!!app.event.error.length | ||
!!app.event.request?.length, | ||
!!app.event.error?.length | ||
); | ||
@@ -1299,3 +1299,3 @@ let fnLiteral = ""; | ||
} | ||
const maybeAsync = app.event.request.some(isAsync); | ||
const maybeAsync = !!app.event.request?.some(isAsync); | ||
const adapterVariables = adapter.inject ? Object.keys(adapter.inject).join(",") + "," : ""; | ||
@@ -1310,17 +1310,17 @@ fnLiteral += ` | ||
const router=app.router.http | ||
const trace=app.event.trace.map(x=>typeof x==='function'?x:x.fn) | ||
const trace=app.event.trace?.map(x=>typeof x==='function'?x:x.fn)??[] | ||
const notFound=new NotFoundError() | ||
const hoc=app.extender.higherOrderFunctions.map(x=>x.fn) | ||
`; | ||
if (app.event.request.length) | ||
if (app.event.request?.length) | ||
fnLiteral += `const onRequest=app.event.request.map(x=>x.fn) | ||
`; | ||
fnLiteral += error404.declare; | ||
if (app.event.trace.length) | ||
if (app.event.trace?.length) | ||
fnLiteral += `const ` + app.event.trace.map((_, i) => `tr${i}=app.event.trace[${i}].fn`).join(",") + "\n"; | ||
fnLiteral += `${maybeAsync ? "async " : ""}function map(${adapter.parameters}){`; | ||
if (app.event.request.length) fnLiteral += `let re | ||
if (app.event.request?.length) fnLiteral += `let re | ||
`; | ||
fnLiteral += adapter.createContext(app); | ||
if (app.event.trace.length) | ||
if (app.event.trace?.length) | ||
fnLiteral += `c[ELYSIA_TRACE]=[` + app.event.trace.map((_, i) => `tr${i}(c)`).join(",") + `] | ||
@@ -1335,5 +1335,5 @@ `; | ||
const reporter = report("request", { | ||
total: app.event.request.length | ||
total: app.event.request?.length | ||
}); | ||
if (app.event.request.length) { | ||
if (app.event.request?.length) { | ||
fnLiteral += `try{`; | ||
@@ -1398,10 +1398,10 @@ for (let i = 0; i < app.event.request.length; i++) { | ||
`; | ||
fnLiteral += `const trace=_trace.map(x=>typeof x==='function'?x:x.fn) | ||
fnLiteral += `const trace=_trace?.map(x=>typeof x==='function'?x:x.fn)??[] | ||
const onMapResponse=[] | ||
for(let i=0;i<_onMapResponse.length;i++)onMapResponse.push(_onMapResponse[i].fn??_onMapResponse[i]) | ||
if(_onMapResponse)for(let i=0;i<_onMapResponse.length;i++)onMapResponse.push(_onMapResponse[i].fn??_onMapResponse[i]) | ||
delete _onMapResponse | ||
const onError=onErrorContainer.map(x=>x.fn) | ||
const res=resContainer.map(x=>x.fn) | ||
return ${app.event.error.find(isAsync) || app.event.mapResponse.find(isAsync) ? "async " : ""}function(context,error,skipGlobal){`; | ||
const hasTrace = app.event.trace.length > 0; | ||
const onError=onErrorContainer?.map(x=>x.fn)??[] | ||
const res=resContainer?.map(x=>x.fn)??[] | ||
return ${app.event.error?.find(isAsync) || app.event.mapResponse?.find(isAsync) ? "async " : ""}function(context,error,skipGlobal){`; | ||
const hasTrace = !!app.event.trace?.length; | ||
fnLiteral += ""; | ||
@@ -1423,10 +1423,11 @@ if (hasTrace) fnLiteral += "const id=context[ELYSIA_REQUEST_ID]\n"; | ||
if (adapter.declare) fnLiteral += adapter.declare; | ||
const saveResponse = hasTrace || hooks.afterResponse.length > 0 || hooks.afterResponse.length > 0 ? "context.response = " : ""; | ||
for (let i = 0; i < app.event.error.length; i++) { | ||
const handler = app.event.error[i]; | ||
const response = `${isAsync(handler) ? "await " : ""}onError[${i}](context) | ||
const saveResponse = hasTrace || !!hooks.afterResponse?.length || !!hooks.afterResponse?.length ? "context.response = " : ""; | ||
if (app.event.error) | ||
for (let i = 0; i < app.event.error.length; i++) { | ||
const handler = app.event.error[i]; | ||
const response = `${isAsync(handler) ? "await " : ""}onError[${i}](context) | ||
`; | ||
fnLiteral += "if(skipGlobal!==true){"; | ||
if ((0, import_sucrose.hasReturn)(handler)) { | ||
fnLiteral += `_r=${response} | ||
fnLiteral += "if(skipGlobal!==true){"; | ||
if ((0, import_sucrose.hasReturn)(handler)) { | ||
fnLiteral += `_r=${response} | ||
if(_r!==undefined){if(_r instanceof Response)return mapResponse(_r,set${adapter.mapResponseContext}) | ||
@@ -1436,22 +1437,22 @@ if(_r instanceof ElysiaCustomStatusResponse){error.status=error.code | ||
`; | ||
const mapResponseReporter2 = report("mapResponse", { | ||
total: hooks.mapResponse.length, | ||
name: "context" | ||
}); | ||
if (hooks.mapResponse.length) { | ||
for (let i2 = 0; i2 < hooks.mapResponse.length; i2++) { | ||
const mapResponse = hooks.mapResponse[i2]; | ||
const endUnit = mapResponseReporter2.resolveChild( | ||
mapResponse.fn.name | ||
); | ||
fnLiteral += `context.response=_r_r=${isAsyncName(mapResponse) ? "await " : ""}onMapResponse[${i2}](context) | ||
const mapResponseReporter2 = report("mapResponse", { | ||
total: hooks.mapResponse?.length, | ||
name: "context" | ||
}); | ||
if (hooks.mapResponse?.length) { | ||
for (let i2 = 0; i2 < hooks.mapResponse.length; i2++) { | ||
const mapResponse = hooks.mapResponse[i2]; | ||
const endUnit = mapResponseReporter2.resolveChild( | ||
mapResponse.fn.name | ||
); | ||
fnLiteral += `context.response=_r_r=${isAsyncName(mapResponse) ? "await " : ""}onMapResponse[${i2}](context) | ||
`; | ||
endUnit(); | ||
endUnit(); | ||
} | ||
} | ||
} | ||
mapResponseReporter2.resolve(); | ||
fnLiteral += `return mapResponse(${saveResponse}_r,set${adapter.mapResponseContext})}`; | ||
} else fnLiteral += response; | ||
fnLiteral += "}"; | ||
} | ||
mapResponseReporter2.resolve(); | ||
fnLiteral += `return mapResponse(${saveResponse}_r,set${adapter.mapResponseContext})}`; | ||
} else fnLiteral += response; | ||
fnLiteral += "}"; | ||
} | ||
fnLiteral += `if(error.constructor.name==="ValidationError"||error.constructor.name==="TransformDecodeError"){if(error.error)error=error.error | ||
@@ -1462,7 +1463,7 @@ set.status=error.status??422 | ||
const mapResponseReporter = report("mapResponse", { | ||
total: hooks.mapResponse.length, | ||
total: hooks.mapResponse?.length, | ||
name: "context" | ||
}); | ||
fnLiteral += "\nif(!context.response)context.response=error.message??error\n"; | ||
if (hooks.mapResponse.length) { | ||
if (hooks.mapResponse?.length) { | ||
fnLiteral += "let mr\n"; | ||
@@ -1469,0 +1470,0 @@ for (let i = 0; i < hooks.mapResponse.length; i++) { |
@@ -8,3 +8,3 @@ import type { AnyElysia } from '.'; | ||
content?: string; | ||
hooks: LifeCycleStore; | ||
hooks: Partial<LifeCycleStore>; | ||
validator?: SchemaValidator; | ||
@@ -11,0 +11,0 @@ }; |
@@ -62,9 +62,10 @@ "use strict"; | ||
try { | ||
for (let i = 0; i < app.event.request.length; i++) { | ||
const onRequest = app.event.request[i].fn; | ||
let response2 = onRequest(context); | ||
if (response2 instanceof Promise) response2 = await response2; | ||
response2 = mapEarlyResponse(response2, set); | ||
if (response2) return context.response = response2; | ||
} | ||
if (app.event.request) | ||
for (let i = 0; i < app.event.request.length; i++) { | ||
const onRequest = app.event.request[i].fn; | ||
let response2 = onRequest(context); | ||
if (response2 instanceof Promise) response2 = await response2; | ||
response2 = mapEarlyResponse(response2, set); | ||
if (response2) return context.response = response2; | ||
} | ||
const handler = app.router.dynamic.find(request.method, path) ?? app.router.dynamic.find("ALL", path); | ||
@@ -107,11 +108,12 @@ if (!handler) throw new import_error.NotFoundError(); | ||
context.contentType = contentType; | ||
for (let i = 0; i < hooks.parse.length; i++) { | ||
const hook = hooks.parse[i].fn; | ||
let temp = hook(context, contentType); | ||
if (temp instanceof Promise) temp = await temp; | ||
if (temp) { | ||
body = temp; | ||
break; | ||
if (hooks.parse) | ||
for (let i = 0; i < hooks.parse.length; i++) { | ||
const hook = hooks.parse[i].fn; | ||
let temp = hook(context, contentType); | ||
if (temp instanceof Promise) temp = await temp; | ||
if (temp) { | ||
body = temp; | ||
break; | ||
} | ||
} | ||
} | ||
delete context.contentType; | ||
@@ -178,11 +180,12 @@ if (body === void 0) { | ||
injectDefaultValues(queryValidator, context.query); | ||
for (let i = 0; i < hooks.transform.length; i++) { | ||
const hook = hooks.transform[i]; | ||
const operation = hook.fn(context); | ||
if (hook.subType === "derive") { | ||
if (operation instanceof Promise) | ||
Object.assign(context, await operation); | ||
else Object.assign(context, operation); | ||
} else if (operation instanceof Promise) await operation; | ||
} | ||
if (hooks.transform) | ||
for (let i = 0; i < hooks.transform.length; i++) { | ||
const hook = hooks.transform[i]; | ||
const operation = hook.fn(context); | ||
if (hook.subType === "derive") { | ||
if (operation instanceof Promise) | ||
Object.assign(context, await operation); | ||
else Object.assign(context, operation); | ||
} else if (operation instanceof Promise) await operation; | ||
} | ||
if (validator) { | ||
@@ -237,22 +240,56 @@ if (headerValidator) { | ||
} | ||
for (let i = 0; i < hooks.beforeHandle.length; i++) { | ||
const hook = hooks.beforeHandle[i]; | ||
let response2 = hook.fn(context); | ||
if (hook.subType === "resolve") { | ||
if (response2 instanceof import_error.ElysiaCustomStatusResponse) { | ||
if (hooks.beforeHandle) | ||
for (let i = 0; i < hooks.beforeHandle.length; i++) { | ||
const hook = hooks.beforeHandle[i]; | ||
let response2 = hook.fn(context); | ||
if (hook.subType === "resolve") { | ||
if (response2 instanceof import_error.ElysiaCustomStatusResponse) { | ||
const result = mapEarlyResponse( | ||
response2, | ||
context.set | ||
); | ||
if (result) | ||
return context.response = result; | ||
} | ||
if (response2 instanceof Promise) | ||
Object.assign(context, await response2); | ||
else Object.assign(context, response2); | ||
continue; | ||
} else if (response2 instanceof Promise) | ||
response2 = await response2; | ||
if (response2 !== void 0) { | ||
; | ||
context.response = response2; | ||
if (hooks.afterHandle) | ||
for (let i2 = 0; i2 < hooks.afterHandle.length; i2++) { | ||
let newResponse = hooks.afterHandle[i2].fn( | ||
context | ||
); | ||
if (newResponse instanceof Promise) | ||
newResponse = await newResponse; | ||
if (newResponse) response2 = newResponse; | ||
} | ||
const result = mapEarlyResponse(response2, context.set); | ||
if (result) | ||
return context.response = result; | ||
if (result) return context.response = result; | ||
} | ||
if (response2 instanceof Promise) | ||
Object.assign(context, await response2); | ||
else Object.assign(context, response2); | ||
continue; | ||
} else if (response2 instanceof Promise) | ||
response2 = await response2; | ||
if (response2 !== void 0) { | ||
} | ||
let response = typeof handle === "function" ? handle(context) : handle; | ||
if (response instanceof Promise) response = await response; | ||
if (hooks.afterHandle) | ||
if (!hooks.afterHandle.length) { | ||
const status = response instanceof import_error.ElysiaCustomStatusResponse ? response.code : set.status ? typeof set.status === "string" ? import_utils.StatusMap[set.status] : set.status : 200; | ||
const responseValidator = validator?.createResponse?.()?.[status]; | ||
if (responseValidator?.Check(response) === false) | ||
throw new import_error.ValidationError( | ||
"response", | ||
responseValidator, | ||
response | ||
); | ||
else if (responseValidator?.Decode) | ||
response = responseValidator.Decode(response); | ||
} else { | ||
; | ||
context.response = response2; | ||
for (let i2 = 0; i2 < hooks.afterHandle.length; i2++) { | ||
let newResponse = hooks.afterHandle[i2].fn( | ||
context.response = response; | ||
for (let i = 0; i < hooks.afterHandle.length; i++) { | ||
let newResponse = hooks.afterHandle[i].fn( | ||
context | ||
@@ -262,48 +299,23 @@ ); | ||
newResponse = await newResponse; | ||
if (newResponse) response2 = newResponse; | ||
} | ||
const result = mapEarlyResponse(response2, context.set); | ||
if (result) return context.response = result; | ||
} | ||
} | ||
let response = typeof handle === "function" ? handle(context) : handle; | ||
if (response instanceof Promise) response = await response; | ||
if (!hooks.afterHandle.length) { | ||
const status = response instanceof import_error.ElysiaCustomStatusResponse ? response.code : set.status ? typeof set.status === "string" ? import_utils.StatusMap[set.status] : set.status : 200; | ||
const responseValidator = validator?.createResponse?.()?.[status]; | ||
if (responseValidator?.Check(response) === false) | ||
throw new import_error.ValidationError( | ||
"response", | ||
responseValidator, | ||
response | ||
); | ||
else if (responseValidator?.Decode) | ||
response = responseValidator.Decode(response); | ||
} else { | ||
; | ||
context.response = response; | ||
for (let i = 0; i < hooks.afterHandle.length; i++) { | ||
let newResponse = hooks.afterHandle[i].fn( | ||
context | ||
); | ||
if (newResponse instanceof Promise) | ||
newResponse = await newResponse; | ||
const result = mapEarlyResponse(newResponse, context.set); | ||
if (result !== void 0) { | ||
const responseValidator = ( | ||
// @ts-expect-error | ||
validator?.response?.[result.status] | ||
const result = mapEarlyResponse( | ||
newResponse, | ||
context.set | ||
); | ||
if (responseValidator?.Check(result) === false) | ||
throw new import_error.ValidationError( | ||
"response", | ||
responseValidator, | ||
result | ||
if (result !== void 0) { | ||
const responseValidator = ( | ||
// @ts-expect-error | ||
validator?.response?.[result.status] | ||
); | ||
else if (responseValidator?.Decode) | ||
response = responseValidator.Decode(response); | ||
return context.response = result; | ||
if (responseValidator?.Check(result) === false) | ||
throw new import_error.ValidationError( | ||
"response", | ||
responseValidator, | ||
result | ||
); | ||
else if (responseValidator?.Decode) | ||
response = responseValidator.Decode(response); | ||
return context.response = result; | ||
} | ||
} | ||
} | ||
} | ||
if (context.set.cookie && cookieMeta?.sign) { | ||
@@ -337,4 +349,5 @@ const secret = !cookieMeta.secrets ? void 0 : typeof cookieMeta.secrets === "string" ? cookieMeta.secrets : cookieMeta.secrets[0]; | ||
} finally { | ||
for (const afterResponse of app.event.afterResponse) | ||
await afterResponse.fn(context); | ||
if (app.event.afterResponse) | ||
for (const afterResponse of app.event.afterResponse) | ||
await afterResponse.fn(context); | ||
} | ||
@@ -348,9 +361,13 @@ }; | ||
errorContext.set = context.set; | ||
for (let i = 0; i < app.event.error.length; i++) { | ||
const hook = app.event.error[i]; | ||
let response = hook.fn(errorContext); | ||
if (response instanceof Promise) response = await response; | ||
if (response !== void 0 && response !== null) | ||
return context.response = mapResponse(response, context.set); | ||
} | ||
if (app.event.error) | ||
for (let i = 0; i < app.event.error.length; i++) { | ||
const hook = app.event.error[i]; | ||
let response = hook.fn(errorContext); | ||
if (response instanceof Promise) response = await response; | ||
if (response !== void 0 && response !== null) | ||
return context.response = mapResponse( | ||
response, | ||
context.set | ||
); | ||
} | ||
return new Response( | ||
@@ -357,0 +374,0 @@ typeof error.cause === "string" ? error.cause : error.message, |
@@ -115,15 +115,3 @@ "use strict"; | ||
}; | ||
this.event = { | ||
start: [], | ||
request: [], | ||
parse: [], | ||
transform: [], | ||
beforeHandle: [], | ||
afterHandle: [], | ||
mapResponse: [], | ||
afterResponse: [], | ||
trace: [], | ||
error: [], | ||
stop: [] | ||
}; | ||
this.event = {}; | ||
this.telemetry = { | ||
@@ -225,3 +213,3 @@ stack: void 0 | ||
this.server = null; | ||
if (this.event.stop.length) | ||
if (this.event.stop?.length) | ||
for (let i = 0; i < this.event.stop.length; i++) | ||
@@ -364,3 +352,3 @@ this.event.stop[i].fn(this); | ||
}) { | ||
localHook = (0, import_utils.localHookToLifeCycleStore)(localHook); | ||
localHook = (0, import_utils.compressHistoryHook)((0, import_utils.localHookToLifeCycleStore)(localHook)); | ||
if (path !== "" && path.charCodeAt(0) !== 47) path = "/" + path; | ||
@@ -518,3 +506,6 @@ if (this.config.prefix && !skipPrefix) path = this.config.prefix + path; | ||
}; | ||
localHook = (0, import_utils2.mergeHook)(localHook, instanceValidator); | ||
localHook = (0, import_utils2.mergeHook)( | ||
localHook, | ||
(0, import_utils.compressHistoryHook)(instanceValidator) | ||
); | ||
if (localHook.tags) { | ||
@@ -533,3 +524,3 @@ if (!localHook.detail) | ||
this.applyMacro(localHook); | ||
const hooks = (0, import_utils2.mergeHook)(this.event, localHook); | ||
const hooks = (0, import_utils.compressHistoryHook)((0, import_utils2.mergeHook)(this.event, localHook)); | ||
if (this.config.aot === false) { | ||
@@ -574,3 +565,2 @@ this.router.dynamic.add(method, path, { | ||
method, | ||
localHook: (0, import_utils2.mergeHook)(localHook), | ||
hooks, | ||
@@ -909,11 +899,15 @@ validator, | ||
case "start": | ||
this.event.start ??= []; | ||
this.event.start.push(fn); | ||
break; | ||
case "request": | ||
this.event.request ??= []; | ||
this.event.request.push(fn); | ||
break; | ||
case "parse": | ||
this.event.parse ??= []; | ||
this.event.parse.push(fn); | ||
break; | ||
case "transform": | ||
this.event.transform ??= []; | ||
this.event.transform.push(fn); | ||
@@ -923,2 +917,3 @@ break; | ||
case "derive": | ||
this.event.transform ??= []; | ||
this.event.transform.push( | ||
@@ -929,2 +924,3 @@ (0, import_utils.fnToContainer)(fn, "derive") | ||
case "beforeHandle": | ||
this.event.beforeHandle ??= []; | ||
this.event.beforeHandle.push(fn); | ||
@@ -935,2 +931,3 @@ break; | ||
case "resolve": | ||
this.event.beforeHandle ??= []; | ||
this.event.beforeHandle.push( | ||
@@ -941,17 +938,23 @@ (0, import_utils.fnToContainer)(fn, "resolve") | ||
case "afterHandle": | ||
this.event.afterHandle ??= []; | ||
this.event.afterHandle.push(fn); | ||
break; | ||
case "mapResponse": | ||
this.event.mapResponse ??= []; | ||
this.event.mapResponse.push(fn); | ||
break; | ||
case "afterResponse": | ||
this.event.afterResponse ??= []; | ||
this.event.afterResponse.push(fn); | ||
break; | ||
case "trace": | ||
this.event.trace ??= []; | ||
this.event.trace.push(fn); | ||
break; | ||
case "error": | ||
this.event.error ??= []; | ||
this.event.error.push(fn); | ||
break; | ||
case "stop": | ||
this.event.stop ??= []; | ||
this.event.stop.push(fn); | ||
@@ -1036,3 +1039,3 @@ break; | ||
this.definitions = (0, import_utils.mergeDeep)(this.definitions, instance.definitions); | ||
if (sandbox.event.request.length) | ||
if (sandbox.event.request?.length) | ||
this.event.request = [ | ||
@@ -1042,3 +1045,3 @@ ...this.event.request || [], | ||
]; | ||
if (sandbox.event.mapResponse.length) | ||
if (sandbox.event.mapResponse?.length) | ||
this.event.mapResponse = [ | ||
@@ -1168,3 +1171,3 @@ ...this.event.mapResponse || [], | ||
sandbox.getServer = () => this.server; | ||
if (sandbox.event.request.length) | ||
if (sandbox.event.request?.length) | ||
this.event.request = [ | ||
@@ -1174,3 +1177,3 @@ ...this.event.request || [], | ||
]; | ||
if (sandbox.event.mapResponse.length) | ||
if (sandbox.event.mapResponse?.length) | ||
this.event.mapResponse = [ | ||
@@ -1389,7 +1392,7 @@ ...this.event.mapResponse || [], | ||
error: plugin.definitions.error, | ||
derive: plugin.event.transform.filter((x) => x?.subType === "derive").map((x) => ({ | ||
derive: plugin.event.transform?.filter((x) => x?.subType === "derive").map((x) => ({ | ||
fn: x.toString(), | ||
stack: new Error().stack ?? "" | ||
})), | ||
resolve: plugin.event.transform.filter((x) => x?.subType === "resolve").map((x) => ({ | ||
resolve: plugin.event.transform?.filter((x) => x?.subType === "resolve").map((x) => ({ | ||
fn: x.toString(), | ||
@@ -1396,0 +1399,0 @@ stack: new Error().stack ?? "" |
@@ -645,4 +645,4 @@ import type { Elysia, AnyElysia } from '.'; | ||
events: { | ||
global: Prettify<LifeCycleStore & RouteSchema>; | ||
local: Prettify<LifeCycleStore & RouteSchema>; | ||
global: Partial<Prettify<LifeCycleStore & RouteSchema>>; | ||
local: Partial<Prettify<LifeCycleStore & RouteSchema>>; | ||
}; | ||
@@ -649,0 +649,0 @@ } |
@@ -15,9 +15,7 @@ import type { BunFile } from 'bun'; | ||
export declare const mergeCookie: <const A extends Object, const B extends Object>(a: A, b: B) => A & B; | ||
export declare const mergeObjectArray: <T extends HookContainer>(a?: T | T[], b?: T | T[]) => T[]; | ||
export declare const mergeObjectArray: <T extends HookContainer>(a?: T | T[], b?: T | T[]) => T[] | undefined; | ||
export declare const primitiveHooks: readonly ["start", "request", "parse", "transform", "resolve", "beforeHandle", "afterHandle", "mapResponse", "afterResponse", "trace", "error", "stop", "body", "headers", "params", "query", "response", "type", "detail"]; | ||
export declare const mergeResponse: (a: InputSchema["response"], b: InputSchema["response"]) => string | TSchema | { | ||
[x: number]: any; | ||
} | undefined; | ||
export declare const mergeResponse: (a: InputSchema["response"], b: InputSchema["response"]) => string | TSchema | Record<number, string | TSchema> | undefined; | ||
export declare const mergeSchemaValidator: (a?: SchemaValidator | null, b?: SchemaValidator | null) => SchemaValidator; | ||
export declare const mergeHook: (a?: LifeCycleStore, b?: AnyLocalHook) => LifeCycleStore; | ||
export declare const mergeHook: (a?: Partial<LifeCycleStore>, b?: AnyLocalHook) => LifeCycleStore; | ||
interface ReplaceSchemaTypeOptions { | ||
@@ -62,3 +60,3 @@ from: TSchema; | ||
export declare const injectChecksum: (checksum: number | undefined, x: MaybeArray<HookContainer> | undefined) => HookContainer | HookContainer[] | undefined; | ||
export declare const mergeLifeCycle: (a: LifeCycleStore, b: LifeCycleStore | AnyLocalHook, checksum?: number) => LifeCycleStore; | ||
export declare const mergeLifeCycle: (a: Partial<LifeCycleStore>, b: Partial<LifeCycleStore | AnyLocalHook>, checksum?: number) => LifeCycleStore; | ||
export declare const asHookType: (fn: HookContainer, inject: LifeCycleType, { skipIfHasType }?: { | ||
@@ -137,4 +135,4 @@ skipIfHasType?: boolean; | ||
export declare const createMacroManager: ({ globalHook, localHook }: { | ||
globalHook: LifeCycleStore; | ||
localHook: AnyLocalHook; | ||
globalHook: Partial<LifeCycleStore>; | ||
localHook: Partial<AnyLocalHook>; | ||
}) => (stackName: keyof LifeCycleStore) => (type: { | ||
@@ -164,3 +162,3 @@ insert?: "before" | "after"; | ||
export declare const localHookToLifeCycleStore: (a: AnyLocalHook) => LifeCycleStore; | ||
export declare const lifeCycleToFn: (a: LifeCycleStore) => AnyLocalHook; | ||
export declare const lifeCycleToFn: (a: Partial<LifeCycleStore>) => AnyLocalHook; | ||
export declare const cloneInference: (inference: Sucrose.Inference) => { | ||
@@ -198,5 +196,7 @@ body: boolean; | ||
*/ | ||
export declare const promoteEvent: (events: (HookContainer | Function)[], as?: "scoped" | "global") => void; | ||
export declare const promoteEvent: (events?: (HookContainer | Function)[], as?: "scoped" | "global") => void; | ||
export declare const getLoosePath: (path: string) => string; | ||
export declare const isNotEmpty: (obj?: Object) => boolean; | ||
export declare const compressHistoryHook: (hook: LifeCycleStore) => Partial<LifeCycleStore>; | ||
export declare const decompressHistoryHook: (hook: Partial<LifeCycleStore>) => LifeCycleStore; | ||
export {}; |
@@ -30,3 +30,5 @@ "use strict"; | ||
coercePrimitiveRoot: () => coercePrimitiveRoot, | ||
compressHistoryHook: () => compressHistoryHook, | ||
createMacroManager: () => createMacroManager, | ||
decompressHistoryHook: () => decompressHistoryHook, | ||
deduplicateChecksum: () => deduplicateChecksum, | ||
@@ -109,3 +111,3 @@ filterGlobalHook: () => filterGlobalHook, | ||
const mergeObjectArray = (a = [], b = []) => { | ||
if (!a) return []; | ||
if (!a) return void 0; | ||
if (!b) return a; | ||
@@ -151,6 +153,5 @@ const array = []; | ||
const isRecordNumber = (x) => typeof x === "object" && Object.keys(x).every(isNumericString); | ||
if (isRecordNumber(a) && isRecordNumber(b)) | ||
return { ...a, ...b }; | ||
if (isRecordNumber(a) && isRecordNumber(b)) return Object.assign(a, b); | ||
else if (a && !isRecordNumber(a) && isRecordNumber(b)) | ||
return { 200: a, ...b }; | ||
return Object.assign({ 200: a }, b); | ||
return b ?? a; | ||
@@ -175,7 +176,3 @@ }; | ||
const mergeHook = (a, b) => { | ||
const { resolve: resolveA, ...restA } = a ?? {}; | ||
const { resolve: resolveB, ...restB } = b ?? {}; | ||
return { | ||
...restA, | ||
...restB, | ||
const hook = Object.assign({}, a, b, { | ||
// Merge local hook first | ||
@@ -210,7 +207,8 @@ // @ts-ignore | ||
mergeObjectArray( | ||
fnToContainer(resolveA, "resolve"), | ||
// @ts-expect-error | ||
fnToContainer(a?.resolve, "resolve"), | ||
a?.beforeHandle | ||
), | ||
mergeObjectArray( | ||
fnToContainer(resolveB, "resolve"), | ||
fnToContainer(b?.resolve, "resolve"), | ||
b?.beforeHandle | ||
@@ -227,3 +225,5 @@ ) | ||
error: mergeObjectArray(a?.error, b?.error) | ||
}; | ||
}); | ||
if (hook.resolve) delete hook.resolve; | ||
return hook; | ||
}; | ||
@@ -702,5 +702,3 @@ const replaceSchemaType = (schema, options, root = true) => { | ||
const mergeLifeCycle = (a, b, checksum2) => { | ||
return { | ||
// ...a, | ||
// ...b, | ||
return Object.assign({}, a, b, { | ||
start: mergeObjectArray( | ||
@@ -761,3 +759,3 @@ a.start, | ||
) | ||
}; | ||
}); | ||
}; | ||
@@ -1081,16 +1079,16 @@ const asHookType = (fn, inject, { skipIfHasType = false } = {}) => { | ||
const lifeCycleToFn = (a) => { | ||
return { | ||
...a, | ||
start: a.start?.map((x) => x.fn), | ||
request: a.request?.map((x) => x.fn), | ||
parse: a.parse?.map((x) => x.fn), | ||
transform: a.transform?.map((x) => x.fn), | ||
beforeHandle: a.beforeHandle?.map((x) => x.fn), | ||
afterHandle: a.afterHandle?.map((x) => x.fn), | ||
afterResponse: a.afterResponse?.map((x) => x.fn), | ||
mapResponse: a.mapResponse?.map((x) => x.fn), | ||
trace: a.trace?.map((x) => x.fn), | ||
error: a.error?.map((x) => x.fn), | ||
stop: a.stop?.map((x) => x.fn) | ||
}; | ||
const hook = {}; | ||
if (a.start?.map) hook.start = a.start.map((x) => x.fn); | ||
if (a.request?.map) hook.request = a.request.map((x) => x.fn); | ||
if (a.parse?.map) hook.parse = a.parse.map((x) => x.fn); | ||
if (a.transform?.map) hook.transform = a.transform.map((x) => x.fn); | ||
if (a.beforeHandle?.map) hook.beforeHandle = a.beforeHandle.map((x) => x.fn); | ||
if (a.afterHandle?.map) hook.afterHandle = a.afterHandle.map((x) => x.fn); | ||
if (a.mapResponse?.map) hook.mapResponse = a.mapResponse.map((x) => x.fn); | ||
if (a.afterResponse?.map) | ||
hook.afterResponse = a.afterResponse.map((x) => x.fn); | ||
if (a.trace?.map) hook.trace = a.trace.map((x) => x.fn); | ||
if (a.error?.map) hook.error = a.error.map((x) => x.fn); | ||
if (a.stop?.map) hook.stop = a.stop.map((x) => x.fn); | ||
return hook; | ||
}; | ||
@@ -1145,2 +1143,3 @@ const cloneInference = (inference) => ({ | ||
const promoteEvent = (events, as = "scoped") => { | ||
if (!events) return; | ||
if (as === "scoped") { | ||
@@ -1164,2 +1163,51 @@ for (const event of events) | ||
}; | ||
const isEmptyHookProperty = (prop) => { | ||
if (Array.isArray(prop)) return prop.length === 0; | ||
return !prop; | ||
}; | ||
const compressHistoryHook = (hook) => { | ||
const history = { ...hook }; | ||
if (isEmptyHookProperty(hook.afterHandle)) delete history.afterHandle; | ||
if (isEmptyHookProperty(hook.afterResponse)) delete history.afterResponse; | ||
if (isEmptyHookProperty(hook.beforeHandle)) delete history.beforeHandle; | ||
if (isEmptyHookProperty(hook.error)) delete history.error; | ||
if (isEmptyHookProperty(hook.mapResponse)) delete history.mapResponse; | ||
if (isEmptyHookProperty(hook.parse)) delete history.parse; | ||
if (isEmptyHookProperty(hook.request)) delete history.request; | ||
if (isEmptyHookProperty(hook.start)) delete history.start; | ||
if (isEmptyHookProperty(hook.stop)) delete history.stop; | ||
if (isEmptyHookProperty(hook.trace)) delete history.trace; | ||
if (isEmptyHookProperty(hook.transform)) delete history.transform; | ||
if (!history.type) delete history.type; | ||
if (history.detail && !Object.keys(history.detail).length) | ||
delete history.detail; | ||
if (!history.body) delete history.body; | ||
if (!history.cookie) delete history.cookie; | ||
if (!history.headers) delete history.headers; | ||
if (!history.query) delete history.query; | ||
if (!history.params) delete history.params; | ||
if (!history.response) delete history.response; | ||
return history; | ||
}; | ||
const decompressHistoryHook = (hook) => { | ||
const history = { ...hook }; | ||
if (!history.afterHandle) history.afterHandle = []; | ||
if (!history.afterResponse) history.afterResponse = []; | ||
if (!history.beforeHandle) history.beforeHandle = []; | ||
if (!history.error) history.error = []; | ||
if (!history.mapResponse) history.mapResponse = []; | ||
if (!history.parse) history.parse = []; | ||
if (!history.request) history.request = []; | ||
if (!history.start) history.start = []; | ||
if (!history.stop) history.stop = []; | ||
if (!history.trace) history.trace = []; | ||
if (!history.transform) history.transform = []; | ||
if (!history.body) history.body = void 0; | ||
if (!history.cookie) history.cookie = void 0; | ||
if (!history.headers) history.headers = void 0; | ||
if (!history.query) history.query = void 0; | ||
if (!history.params) history.params = void 0; | ||
if (!history.response) history.response = void 0; | ||
return history; | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -1176,3 +1224,5 @@ 0 && (module.exports = { | ||
coercePrimitiveRoot, | ||
compressHistoryHook, | ||
createMacroManager, | ||
decompressHistoryHook, | ||
deduplicateChecksum, | ||
@@ -1179,0 +1229,0 @@ filterGlobalHook, |
@@ -13,8 +13,7 @@ import type { AnyElysia } from '.'; | ||
export declare const isGenerator: (v: Function | HookContainer) => boolean; | ||
export declare const composeHandler: ({ app, path, method, localHook, hooks, validator, handler, allowMeta, inference, asManifest }: { | ||
export declare const composeHandler: ({ app, path, method, hooks, validator, handler, allowMeta, inference, asManifest }: { | ||
app: AnyElysia; | ||
path: string; | ||
method: string; | ||
hooks: LifeCycleStore; | ||
localHook: LifeCycleStore; | ||
hooks: Partial<LifeCycleStore>; | ||
validator: SchemaValidator; | ||
@@ -21,0 +20,0 @@ handler: unknown | Handler<any, any>; |
@@ -8,3 +8,3 @@ import type { AnyElysia } from '.'; | ||
content?: string; | ||
hooks: LifeCycleStore; | ||
hooks: Partial<LifeCycleStore>; | ||
validator?: SchemaValidator; | ||
@@ -11,0 +11,0 @@ }; |
@@ -645,4 +645,4 @@ import type { Elysia, AnyElysia } from '.'; | ||
events: { | ||
global: Prettify<LifeCycleStore & RouteSchema>; | ||
local: Prettify<LifeCycleStore & RouteSchema>; | ||
global: Partial<Prettify<LifeCycleStore & RouteSchema>>; | ||
local: Partial<Prettify<LifeCycleStore & RouteSchema>>; | ||
}; | ||
@@ -649,0 +649,0 @@ } |
@@ -15,9 +15,7 @@ import type { BunFile } from 'bun'; | ||
export declare const mergeCookie: <const A extends Object, const B extends Object>(a: A, b: B) => A & B; | ||
export declare const mergeObjectArray: <T extends HookContainer>(a?: T | T[], b?: T | T[]) => T[]; | ||
export declare const mergeObjectArray: <T extends HookContainer>(a?: T | T[], b?: T | T[]) => T[] | undefined; | ||
export declare const primitiveHooks: readonly ["start", "request", "parse", "transform", "resolve", "beforeHandle", "afterHandle", "mapResponse", "afterResponse", "trace", "error", "stop", "body", "headers", "params", "query", "response", "type", "detail"]; | ||
export declare const mergeResponse: (a: InputSchema["response"], b: InputSchema["response"]) => string | TSchema | { | ||
[x: number]: any; | ||
} | undefined; | ||
export declare const mergeResponse: (a: InputSchema["response"], b: InputSchema["response"]) => string | TSchema | Record<number, string | TSchema> | undefined; | ||
export declare const mergeSchemaValidator: (a?: SchemaValidator | null, b?: SchemaValidator | null) => SchemaValidator; | ||
export declare const mergeHook: (a?: LifeCycleStore, b?: AnyLocalHook) => LifeCycleStore; | ||
export declare const mergeHook: (a?: Partial<LifeCycleStore>, b?: AnyLocalHook) => LifeCycleStore; | ||
interface ReplaceSchemaTypeOptions { | ||
@@ -62,3 +60,3 @@ from: TSchema; | ||
export declare const injectChecksum: (checksum: number | undefined, x: MaybeArray<HookContainer> | undefined) => HookContainer | HookContainer[] | undefined; | ||
export declare const mergeLifeCycle: (a: LifeCycleStore, b: LifeCycleStore | AnyLocalHook, checksum?: number) => LifeCycleStore; | ||
export declare const mergeLifeCycle: (a: Partial<LifeCycleStore>, b: Partial<LifeCycleStore | AnyLocalHook>, checksum?: number) => LifeCycleStore; | ||
export declare const asHookType: (fn: HookContainer, inject: LifeCycleType, { skipIfHasType }?: { | ||
@@ -137,4 +135,4 @@ skipIfHasType?: boolean; | ||
export declare const createMacroManager: ({ globalHook, localHook }: { | ||
globalHook: LifeCycleStore; | ||
localHook: AnyLocalHook; | ||
globalHook: Partial<LifeCycleStore>; | ||
localHook: Partial<AnyLocalHook>; | ||
}) => (stackName: keyof LifeCycleStore) => (type: { | ||
@@ -164,3 +162,3 @@ insert?: "before" | "after"; | ||
export declare const localHookToLifeCycleStore: (a: AnyLocalHook) => LifeCycleStore; | ||
export declare const lifeCycleToFn: (a: LifeCycleStore) => AnyLocalHook; | ||
export declare const lifeCycleToFn: (a: Partial<LifeCycleStore>) => AnyLocalHook; | ||
export declare const cloneInference: (inference: Sucrose.Inference) => { | ||
@@ -198,5 +196,7 @@ body: boolean; | ||
*/ | ||
export declare const promoteEvent: (events: (HookContainer | Function)[], as?: "scoped" | "global") => void; | ||
export declare const promoteEvent: (events?: (HookContainer | Function)[], as?: "scoped" | "global") => void; | ||
export declare const getLoosePath: (path: string) => string; | ||
export declare const isNotEmpty: (obj?: Object) => boolean; | ||
export declare const compressHistoryHook: (hook: LifeCycleStore) => Partial<LifeCycleStore>; | ||
export declare const decompressHistoryHook: (hook: Partial<LifeCycleStore>) => LifeCycleStore; | ||
export {}; |
{ | ||
"name": "elysia", | ||
"description": "Ergonomic Framework for Human", | ||
"version": "1.2.10", | ||
"version": "1.2.11-exp.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "saltyAom", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1838876
29784
117
1