elysia 2.0.0-beta.11 → 2.0.0-beta.13
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/adapter/bun/index.js +36 -21
- package/dist/adapter/bun/index.mjs +36 -21
- package/dist/adapter/utils.js +1 -0
- package/dist/adapter/utils.mjs +1 -0
- package/dist/adapter/web-standard/handler.js +8 -2
- package/dist/adapter/web-standard/handler.mjs +8 -2
- package/dist/base.d.ts +5 -0
- package/dist/base.js +109 -4
- package/dist/base.mjs +111 -6
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +5 -27
- package/dist/compile/aot-capture.mjs +6 -24
- package/dist/compile/aot-emit.js +1 -1
- package/dist/compile/aot-emit.mjs +1 -1
- package/dist/compile/aot.d.ts +1 -1
- package/dist/compile/aot.js +2 -2
- package/dist/compile/aot.mjs +2 -2
- package/dist/compile/handler/descriptor.d.ts +4 -8
- package/dist/compile/handler/descriptor.js +8 -21
- package/dist/compile/handler/descriptor.mjs +9 -21
- package/dist/compile/handler/index.d.ts +4 -3
- package/dist/compile/handler/index.js +16 -6
- package/dist/compile/handler/index.mjs +16 -7
- package/dist/compile/handler/jit.js +82 -76
- package/dist/compile/handler/jit.mjs +83 -77
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +3 -4
- package/dist/compile/handler/params.mjs +5 -5
- package/dist/compile/handler/reconstruct.d.ts +1 -1
- package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
- package/dist/compile/handler/static-clone-resolver.js +8 -0
- package/dist/compile/handler/static-clone-resolver.mjs +7 -0
- package/dist/compile/handler/utils.d.ts +7 -7
- package/dist/compile/handler/utils.js +24 -20
- package/dist/compile/handler/utils.mjs +24 -20
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/context.js +3 -21
- package/dist/context.mjs +4 -22
- package/dist/cookie/index.d.ts +1 -2
- package/dist/cookie/index.js +0 -2
- package/dist/cookie/index.mjs +1 -2
- package/dist/cookie/lib.js +2 -1
- package/dist/cookie/lib.mjs +2 -1
- package/dist/cookie/utils.d.ts +3 -7
- package/dist/cookie/utils.js +9 -28
- package/dist/cookie/utils.mjs +11 -29
- package/dist/error.d.ts +40 -83
- package/dist/error.js +18 -19
- package/dist/error.mjs +18 -20
- package/dist/handler/error.js +4 -5
- package/dist/handler/error.mjs +4 -5
- package/dist/handler/fetch.js +31 -17
- package/dist/handler/fetch.mjs +32 -18
- package/dist/handler/utils.d.ts +3 -3
- package/dist/handler/utils.js +28 -17
- package/dist/handler/utils.mjs +28 -17
- package/dist/index.d.ts +3 -3
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/core.d.ts +3 -7
- package/dist/plugin/aot/core.js +8 -18
- package/dist/plugin/aot/core.mjs +9 -17
- package/dist/plugin/aot/hooks.js +5 -1
- package/dist/plugin/aot/hooks.mjs +5 -1
- package/dist/trace.js +23 -10
- package/dist/trace.mjs +23 -10
- package/dist/type/bridge-live.d.ts +3 -2
- package/dist/type/bridge-live.js +4 -2
- package/dist/type/bridge-live.mjs +3 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +9 -1
- package/dist/type/bridge.mjs +3 -1
- package/dist/type/coerce-plan.d.ts +2 -2
- package/dist/type/coerce-plan.js +0 -1
- package/dist/type/coerce-plan.mjs +2 -2
- package/dist/type/compat.js +2 -1
- package/dist/type/compat.mjs +3 -2
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/shared.d.ts +1 -3
- package/dist/type/shared.js +0 -3
- package/dist/type/shared.mjs +1 -3
- package/dist/type/typebox-value-live.d.ts +4 -3
- package/dist/type/typebox-value-live.js +5 -3
- package/dist/type/typebox-value-live.mjs +4 -3
- package/dist/type/typebox-value.d.ts +11 -7
- package/dist/type/typebox-value.js +2 -1
- package/dist/type/typebox-value.mjs +1 -1
- package/dist/type/validator/index.d.ts +1 -1
- package/dist/type/validator/validator-cache.d.ts +1 -1
- package/dist/types.d.ts +10 -17
- package/dist/universal/file.d.ts +1 -3
- package/dist/universal/file.js +0 -2
- package/dist/universal/file.mjs +1 -2
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +2 -3
- package/dist/utils.d.ts +0 -1
- package/package.json +13 -6
|
@@ -9,45 +9,44 @@ import { parseQueryFromURL } from "../../parse-query.mjs";
|
|
|
9
9
|
import { Capture } from "../aot.mjs";
|
|
10
10
|
import { resolvedTraceOf, traceCapabilityRequired } from "../../generation.mjs";
|
|
11
11
|
import { buildCookieJar, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues } from "../../cookie/utils.mjs";
|
|
12
|
-
import { isAsyncFunction } from "../utils.mjs";
|
|
13
12
|
import { emptyResponse, finalizeRouteError, forwardError } from "../../handler/utils.mjs";
|
|
14
13
|
import { fallbackResponse } from "../../handler/error.mjs";
|
|
15
|
-
import { armEntryAbort, cloneResponse, cloneStaticValue, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, runBeforeHandlePrefix, runBeforeHandlePrefixAsync } from "./utils.mjs";
|
|
14
|
+
import { armEntryAbort, awaitGuard, cloneResponse, cloneStaticValue, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, runBeforeHandlePrefix, runBeforeHandlePrefixAsync } from "./utils.mjs";
|
|
16
15
|
import { JITProbe } from "../jit-probe.mjs";
|
|
17
16
|
|
|
18
17
|
//#region src/compile/handler/jit.ts
|
|
19
|
-
const
|
|
18
|
+
const awaitValue = (value, arm = "") => arm ? `await (_av=(${value}),${arm},_av)` : `await ${value}`;
|
|
20
19
|
let captureHeaderShorthand;
|
|
21
20
|
const setCaptureHeaderShorthand = (value) => {
|
|
22
21
|
captureHeaderShorthand = value;
|
|
23
22
|
};
|
|
24
|
-
function builtinParser(adapter, parse, link) {
|
|
23
|
+
function builtinParser(adapter, parse, link, arm) {
|
|
25
24
|
switch (parse) {
|
|
26
25
|
case "formdata":
|
|
27
26
|
case "multipart/form-data":
|
|
28
27
|
link(adapter.formData, "pf");
|
|
29
|
-
return
|
|
28
|
+
return `c.body=${awaitValue("pf(c)", arm)}\n`;
|
|
30
29
|
case "json":
|
|
31
30
|
case "application/json":
|
|
32
31
|
link(adapter.json, "pj");
|
|
33
|
-
return
|
|
32
|
+
return `c.body=${awaitValue("pj(c)", arm)}\n`;
|
|
34
33
|
case "urlencoded":
|
|
35
34
|
case "application/x-www-form-urlencoded":
|
|
36
35
|
link(adapter.urlencoded, "pu");
|
|
37
|
-
return
|
|
36
|
+
return `c.body=${awaitValue("pu(c)", arm)}\n`;
|
|
38
37
|
case "arrayBuffer":
|
|
39
38
|
case "application/octet-stream":
|
|
40
39
|
link(adapter.arrayBuffer, "pa");
|
|
41
|
-
return
|
|
40
|
+
return `c.body=${awaitValue("pa(c)", arm)}\n`;
|
|
42
41
|
case "text":
|
|
43
42
|
case "text/plain":
|
|
44
43
|
link(adapter.text, "pt");
|
|
45
|
-
return
|
|
44
|
+
return `c.body=${awaitValue("pt(c)", arm)}\n`;
|
|
46
45
|
case "none": return "";
|
|
47
46
|
default: throw new Error(`Unsupported content type: ${parse}`);
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
|
-
function parse(adapter, parsers, bodyVali, hasHeaders, link, report) {
|
|
49
|
+
function parse(adapter, parsers, bodyVali, hasHeaders, link, report, arm) {
|
|
51
50
|
if (parsers && typeof parsers === "function") parsers = [parsers];
|
|
52
51
|
if (typeof parsers === "string" || parsers?.length === 1 && typeof parsers[0] === "string") {
|
|
53
52
|
if (parsers.length === 1) parsers = parsers[0];
|
|
@@ -55,7 +54,7 @@ function parse(adapter, parsers, bodyVali, hasHeaders, link, report) {
|
|
|
55
54
|
const child = report?.resolveChild(builtinName);
|
|
56
55
|
const begin = child ? child.begin : "";
|
|
57
56
|
const end = child ? child.end() : "";
|
|
58
|
-
return begin + builtinParser(adapter, parsers, link) + end;
|
|
57
|
+
return begin + builtinParser(adapter, parsers, link, arm) + end;
|
|
59
58
|
}
|
|
60
59
|
let hasFn = false;
|
|
61
60
|
let hasType = false;
|
|
@@ -76,7 +75,7 @@ if(cti!==-1)ct=ct.slice(0,cti)
|
|
|
76
75
|
const child = report?.resolveChild(parser.name || "anonymous");
|
|
77
76
|
if (i) code += "if(!hasBody){";
|
|
78
77
|
if (child) code += child.begin;
|
|
79
|
-
code +=
|
|
78
|
+
code += `_bp=ho.parse[${i}](c,ct)\n` + awaitGuard(parser, true, "_bp", arm) + `c.body=_bp\n`;
|
|
80
79
|
code += "hasBody=c.body!==undefined\n";
|
|
81
80
|
if (child) code += child.end();
|
|
82
81
|
if (i) code += "}\n";
|
|
@@ -85,7 +84,7 @@ if(cti!==-1)ct=ct.slice(0,cti)
|
|
|
85
84
|
const child = report?.resolveChild(parser);
|
|
86
85
|
if (i) code += "if(!hasBody){\n";
|
|
87
86
|
if (child) code += child.begin;
|
|
88
|
-
code += builtinParser(adapter, parser, link);
|
|
87
|
+
code += builtinParser(adapter, parser, link, arm);
|
|
89
88
|
if (child) code += child.end();
|
|
90
89
|
if (i) code += "}\n";
|
|
91
90
|
break;
|
|
@@ -103,7 +102,8 @@ if(cti!==-1)ct=ct.slice(0,cti)
|
|
|
103
102
|
code += `if(ct&&!(${mediaGuard}))throw new es(415,'Unsupported Media Type')\n`;
|
|
104
103
|
link(ElysiaStatus, "es");
|
|
105
104
|
}
|
|
106
|
-
|
|
105
|
+
const value = `c.body=cj?${awaitValue("pj(c)", arm)}:${awaitValue("pd(c,ce,true)", arm)}\n`;
|
|
106
|
+
code += hasFn ? `if(!hasBody&&${guard}){${begin}${value}${end}}\n` : `if(${guard}){${begin}${value}${end}}\n`;
|
|
107
107
|
if (!bodyVali) link(hasRequestBody, "hb");
|
|
108
108
|
link(adapter.json, "pj");
|
|
109
109
|
link(adapter.default, "pd");
|
|
@@ -140,24 +140,24 @@ const fromArgs = (type, isAsync) => `'${type}'${isAsync ? ",true" : ""}`;
|
|
|
140
140
|
const createInlineHandler = (map, h) => ((c) => {
|
|
141
141
|
const r = h(c);
|
|
142
142
|
if (r instanceof Error) throw r;
|
|
143
|
-
if (r
|
|
143
|
+
if (typeof r?.then === "function") return Promise.resolve(r).then((v) => map(forwardError(v), c.request, true));
|
|
144
144
|
return map(r, c.request, true);
|
|
145
145
|
});
|
|
146
146
|
const createInlineHandlerWithSet = (map, h) => ((c) => {
|
|
147
147
|
const r = h(c);
|
|
148
148
|
if (r instanceof Error) throw r;
|
|
149
|
-
if (r
|
|
149
|
+
if (typeof r?.then === "function") return Promise.resolve(r).then((v) => map(forwardError(v), c.set, c.request, true));
|
|
150
150
|
return map(r, c.set, c.request, true);
|
|
151
151
|
});
|
|
152
152
|
const createInlineHandlerWithDefaultHeaders = (map, h) => ((c) => {
|
|
153
153
|
materializeSetHeaders(c.set);
|
|
154
154
|
const r = h(c);
|
|
155
155
|
if (r instanceof Error) throw r;
|
|
156
|
-
if (r
|
|
156
|
+
if (typeof r?.then === "function") return Promise.resolve(r).then((v) => map(forwardError(v), c.set, c.request, true));
|
|
157
157
|
return map(r, c.set, c.request, true);
|
|
158
158
|
});
|
|
159
159
|
function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapter, isHandleFunction, isStaticResponse, isPromiseHandler, state }) {
|
|
160
|
-
const { vali, inference, cookieConfig, beforeHandlePrefix, traceHandlers, tracePhases, hasAnyPhase, traceHandleOn, descriptor: { async: isAsync, responseMode, hasBody, bodyValiIsAsync, headersValiIsAsync, paramsValiIsAsync, queryValiIsAsync, cookieValiIsAsync: cookieValidIsAsync, responseValiAsync, hasCookieSign, syncCookieSign, asyncCookieSign, lazyCookieVerify, hasErrorHook, hasAfterResponse, hasBeforeHandle, hasAfterHandle, hasMapResponse, hasResponseValidator, hasTrace, traceCount, hasLifecycleHook,
|
|
160
|
+
const { vali, inference, cookieConfig, beforeHandlePrefix, traceHandlers, tracePhases, hasAnyPhase, traceHandleOn, descriptor: { async: isAsync, responseMode, hasBody, bodyValiIsAsync, headersValiIsAsync, paramsValiIsAsync, queryValiIsAsync, cookieValiIsAsync: cookieValidIsAsync, responseValiAsync, hasCookieSign, syncCookieSign, asyncCookieSign, lazyCookieVerify, hasErrorHook, hasAfterResponse, hasBeforeHandle, hasAfterHandle, hasMapResponse, hasResponseValidator, hasTrace, traceCount, hasLifecycleHook, syncErrorHook, syncAfterResponse } } = state;
|
|
161
161
|
const hasStaticAfterResponse = !!hook?.afterResponse?.length;
|
|
162
162
|
const hasDynamicAfterResponse = !!inference.afterResponse;
|
|
163
163
|
const seenKeys = new Set(["rt", "fre"]);
|
|
@@ -180,15 +180,10 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
180
180
|
}
|
|
181
181
|
const abortOn = hasLifecycleHook && root["~config"]?.abortSignal !== false;
|
|
182
182
|
const abortPeek = "c['~sig']?.aborted";
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
return suspended ? abortArm : abortPeek;
|
|
188
|
-
};
|
|
189
|
-
const abortCheck = () => abortOn ? `if(${abortExpression()})return emp.clone()\n` : "";
|
|
190
|
-
const abortChainGuard = () => abortOn ? isAsync ? abortArm : abortExpression() : void 0;
|
|
191
|
-
const abortCatch = abortOn ? `if(${abortArm})return emp.clone()\n` : "";
|
|
183
|
+
const arm = abortOn ? "_as??=(c['~sig']??=c.request.signal)" : "";
|
|
184
|
+
const abortCheck = () => abortOn ? `if(${abortPeek})return emp.clone()\n` : "";
|
|
185
|
+
const abortChainGuard = () => abortOn ? abortPeek : void 0;
|
|
186
|
+
const abortCatch = abortOn ? `if((${arm}).aborted)return emp.clone()\n` : "";
|
|
192
187
|
const phaseOn = (phase) => hasTrace && (tracePhases === null || tracePhases.has(phase));
|
|
193
188
|
const beginTrace = (phase, total, name = phase) => {
|
|
194
189
|
if (!phaseOn(phase)) return "";
|
|
@@ -221,7 +216,7 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
221
216
|
};
|
|
222
217
|
const needsStaticClone = !isHandleFunction && !isStaticResponse && !isPromiseHandler && (hasAfterHandle || hasMapResponse) && typeof handler === "object" && handler !== null;
|
|
223
218
|
if (needsStaticClone) link(cloneStaticValue, "scl");
|
|
224
|
-
const callHandler = isHandleFunction ?
|
|
219
|
+
const callHandler = isHandleFunction ? `_r=h(c)\n${awaitGuard(handler, isAsync, "_r", arm)}` : isStaticResponse ? `_r=cr(h)\n` : isPromiseHandler ? `_r=h.then(cr)\n` : needsStaticClone ? `_r=scl(h)\n` : `_r=h\n`;
|
|
225
220
|
let code = `${isAsync ? "async " : ""}function route(c){\n`;
|
|
226
221
|
if (abortOn) {
|
|
227
222
|
link(emptyResponse, "emp");
|
|
@@ -278,7 +273,7 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
278
273
|
if (hasBody) {
|
|
279
274
|
const parseLen = Array.isArray(hook?.parse) ? hook.parse.length : 0;
|
|
280
275
|
if (hasTrace) code += beginTrace("parse", parseLen);
|
|
281
|
-
const parseCode = parse(adapter.parse, hook?.parse, vali?.body, hasHeaders, link, buildReport("parse"));
|
|
276
|
+
const parseCode = parse(adapter.parse, hook?.parse, vali?.body, hasHeaders, link, buildReport("parse"), arm);
|
|
282
277
|
const preserveParseStatus = seenKeys.has("es");
|
|
283
278
|
link(ParseError, "pe");
|
|
284
279
|
code += "try{\n" + parseCode + `}catch(e){${preserveParseStatus ? "if(e instanceof es)throw e\n" : ""}throw new pe(e)}\n`;
|
|
@@ -291,26 +286,34 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
291
286
|
if (transformLen) {
|
|
292
287
|
link(hook.transform, "tf");
|
|
293
288
|
if (isAsync) code += "let _tf\n";
|
|
294
|
-
code += mapTransform(hook.transform, [
|
|
289
|
+
code += mapTransform(hook.transform, [
|
|
290
|
+
isAsync,
|
|
291
|
+
buildReport("transform"),
|
|
292
|
+
arm
|
|
293
|
+
], abortChainGuard());
|
|
295
294
|
}
|
|
296
295
|
code += endTrace("transform");
|
|
297
296
|
if (transformLen) code += abortCheck();
|
|
298
297
|
}
|
|
299
298
|
if (vali?.body) {
|
|
300
299
|
link(vali, "va");
|
|
301
|
-
|
|
300
|
+
const value = `va.body.From(c.body,${fromArgs("body", bodyValiIsAsync)})`;
|
|
301
|
+
code += `c.body=${bodyValiIsAsync ? awaitValue(value, arm) : value}\n`;
|
|
302
302
|
}
|
|
303
303
|
if (vali?.headers) {
|
|
304
304
|
link(vali, "va");
|
|
305
|
-
|
|
305
|
+
const value = `va.headers.From(c.headers,${fromArgs("headers", !!headersValiIsAsync)})`;
|
|
306
|
+
code += `c.headers=${headersValiIsAsync ? awaitValue(value, arm) : value}\n`;
|
|
306
307
|
}
|
|
307
308
|
if (vali?.params) {
|
|
308
309
|
link(vali, "va");
|
|
309
|
-
|
|
310
|
+
const value = `va.params.From(c.params,${fromArgs("params", !!paramsValiIsAsync)})`;
|
|
311
|
+
code += `c.params=${paramsValiIsAsync ? awaitValue(value, arm) : value}\n`;
|
|
310
312
|
}
|
|
311
313
|
if (vali?.query) {
|
|
312
314
|
link(vali, "va");
|
|
313
|
-
|
|
315
|
+
const value = `va.query.From(c.query,${fromArgs("query", !!queryValiIsAsync)})`;
|
|
316
|
+
code += `c.query=${queryValiIsAsync ? awaitValue(value, arm) : value}\n`;
|
|
314
317
|
}
|
|
315
318
|
if (cookieConfig) {
|
|
316
319
|
link(buildCookieJar, "bcj");
|
|
@@ -335,25 +338,30 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
335
338
|
code += `let _ck=pcrsg(${cookieHeaderExpr},cc)\n`;
|
|
336
339
|
} else {
|
|
337
340
|
link(parseCookieRaw, "pcr");
|
|
338
|
-
code += `let _ck
|
|
341
|
+
code += `let _ck=${awaitValue(`pcr(${cookieHeaderExpr},cc)`, arm)}\n`;
|
|
339
342
|
}
|
|
340
343
|
if (vali?.cookie) {
|
|
341
344
|
link(vali, "va");
|
|
342
345
|
const cookieIsOptional = !!(hook?.cookie)?.["~optional"];
|
|
343
|
-
const
|
|
346
|
+
const value = `va.cookie.From(_ck,${fromArgs("cookie", !!cookieValidIsAsync)})`;
|
|
347
|
+
const validateExpr = `_ck=${cookieValidIsAsync ? awaitValue(value, arm) : value}\n`;
|
|
344
348
|
if (cookieIsOptional) code += `if(Object.keys(_ck).length){${validateExpr}}\n`;
|
|
345
349
|
else code += validateExpr;
|
|
346
350
|
}
|
|
347
351
|
code += `c.cookie=bcj(c.set,_ck,cc${deferDecode ? ",undefined,1" : ""})\n`;
|
|
348
352
|
}
|
|
349
353
|
}
|
|
350
|
-
const
|
|
354
|
+
const compactEligible = responseMode === "compact";
|
|
351
355
|
const res = adapter.response;
|
|
352
356
|
const responseMap = res.map;
|
|
353
|
-
const
|
|
357
|
+
const responseCompact = compactEligible ? res.compact : void 0;
|
|
358
|
+
const portableCompact = compactEligible && (Capture.isAotBuildEnv() || Capture.isCapturing());
|
|
359
|
+
const hasSet = !compactEligible || !responseCompact && !portableCompact;
|
|
360
|
+
const map = hasSet ? link(responseMap, "rm") ?? "rm" : link(responseCompact, "rc") ?? "rc";
|
|
361
|
+
if (portableCompact) link(responseMap, "rm");
|
|
362
|
+
const mapValue = (value) => portableCompact ? `(rc?rc(${value},c.request,true):rm(${value},c.set,c.request,true))` : hasSet ? `${map}(${value},c.set,c.request,true)` : `${map}(${value},c.request,true)`;
|
|
354
363
|
if (isStaticResponse || isPromiseHandler) link(cloneResponse, "cr");
|
|
355
|
-
const
|
|
356
|
-
const mapReturn = hasSet ? `rm(${handleInstruction},c.set,c.request,true)\n` : `rc(${handleInstruction},c.request,true)\n`;
|
|
364
|
+
const mapReturn = `${mapValue(isHandleFunction ? "h(c)" : isStaticResponse ? "cr(h)" : isPromiseHandler ? "h.then(cr)" : "h")}\n`;
|
|
357
365
|
if (hasStaticAfterResponse) link(hook.afterResponse, "ar");
|
|
358
366
|
const drainTraceStream = traceHandleOn ? `let _ser\nif(_trs){try{for await(const v of _trs){}}catch(_te){_ser=_te}}\n` : "";
|
|
359
367
|
const resolveHandlePostDrain = traceHandleOn ? (() => {
|
|
@@ -362,11 +370,14 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
362
370
|
return s;
|
|
363
371
|
})() : "";
|
|
364
372
|
const traceNeedsSchedule = traceHandleOn || phaseOn("afterResponse");
|
|
365
|
-
const scheduleAfterResponse = hasAfterResponse || traceNeedsSchedule ? "c._arf=true\nqueueMicrotask(async()=>{if(_stl){try{for await(const v of _stl){}}catch{}}\n" + drainTraceStream + resolveHandlePostDrain + beginTrace("afterResponse", hook?.afterResponse?.length ?? 0) + (hasStaticAfterResponse ? mapAfterResponse(hook.afterResponse, [buildReport("afterResponse")]) : "") + (hasDynamicAfterResponse ? "let _q=c['~afterResponse']\nif(_q){let _l=_q.length\nfor(let _i=0;_i<_l;_i++){try{await _q[_i](c)}catch{}}\n" + (!isProduction() ? `if(_q.length!==_l)console.warn('[elysia] defer() called from inside the afterResponse drain is ignored')\n` : "") + `}\n` : "") + endTrace("afterResponse") + `})\n` : "";
|
|
366
|
-
const dedupSchedule = !!scheduleAfterResponse &&
|
|
373
|
+
const scheduleAfterResponse = hasAfterResponse || traceNeedsSchedule ? "c._arf=true\nqueueMicrotask(async()=>{if(_stl){try{for await(const v of _stl){}}catch{}}\n" + drainTraceStream + resolveHandlePostDrain + beginTrace("afterResponse", hook?.afterResponse?.length ?? 0) + (hasStaticAfterResponse ? mapAfterResponse(hook.afterResponse, [buildReport("afterResponse")]) : "") + (hasDynamicAfterResponse ? "let _q=c['~afterResponse']\nif(_q){let _l=_q.length\nfor(let _i=0;_i<_l;_i++){try{await _q[_i](c)}catch(_e){console.error(_e)}}\n" + (!isProduction() ? `if(_q.length!==_l)console.warn('[elysia] defer() called from inside the afterResponse drain is ignored')\n` : "") + `}\n` : "") + endTrace("afterResponse") + `})\n` : "";
|
|
374
|
+
const dedupSchedule = !!scheduleAfterResponse && !syncAfterResponse && !syncErrorHook;
|
|
367
375
|
const scheduleDecl = dedupSchedule ? `function _sc(){\n${scheduleAfterResponse}}\n` : "";
|
|
368
376
|
const schedule = dedupSchedule ? `_sc()\n` : scheduleAfterResponse;
|
|
369
|
-
const
|
|
377
|
+
const syncScheduleDecl = syncAfterResponse && scheduleAfterResponse ? `function _scf(c,_stl){\n${scheduleAfterResponse}}\n` : "";
|
|
378
|
+
const catchSchedule = dedupSchedule ? `_sc()\n` : syncScheduleDecl ? `_scf(c)\n` : "";
|
|
379
|
+
const freThenSchedule = (arg) => catchSchedule ? `if(c._arf)return fre(rt,c,${arg})\nc._arf=true\nconst _fr=fre(rt,c,${arg})\nreturn typeof _fr?.then==='function'?_fr.then((_v)=>{${catchSchedule}return _v\n}):(${catchSchedule.trim()},_fr)\n` : `return fre(rt,c,${arg})\n`;
|
|
380
|
+
const signPrefix = syncCookieSign ? `scv(c.set.cookie,cc)\n` : asyncCookieSign ? `_sg=scv(c.set.cookie,cc)\nif(_sg){${arm ? `${arm}\n` : ""}await _sg}\n` : "";
|
|
370
381
|
if (syncCookieSign || asyncCookieSign) link(signCookieValues, "scv");
|
|
371
382
|
let factoryHelpers = "";
|
|
372
383
|
if (hasBeforeHandle || hasAfterHandle || hasMapResponse || hasAfterResponse || hasResponseValidator || hasCookieSign || hasTrace) {
|
|
@@ -380,7 +391,7 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
380
391
|
const rbpAbort = abortOn ? ",1" : "";
|
|
381
392
|
if (isAsync) {
|
|
382
393
|
link(runBeforeHandlePrefixAsync, "rbp");
|
|
383
|
-
code += `tmp
|
|
394
|
+
code += `tmp=${awaitValue(`rbp(bp,c${rbpAbort})`, arm)}\n`;
|
|
384
395
|
} else {
|
|
385
396
|
link(runBeforeHandlePrefix, "rbp");
|
|
386
397
|
code += `tmp=rbp(bp,c${rbpAbort})\n`;
|
|
@@ -391,7 +402,7 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
391
402
|
link(hook.beforeHandle, "bf");
|
|
392
403
|
const deriveEntries = hook["~deriveEntries"];
|
|
393
404
|
const chainGuard = abortChainGuard();
|
|
394
|
-
const mapped = mapBeforeHandle(hook.beforeHandle, deriveEntries, link, isAsync, buildReport("beforeHandle"), chainGuard);
|
|
405
|
+
const mapped = mapBeforeHandle(hook.beforeHandle, deriveEntries, link, isAsync, buildReport("beforeHandle"), chainGuard, arm);
|
|
395
406
|
code += beforeHandlePrefix ? `if(${chainGuard ? `!${chainGuard}&&` : ""}_r===undefined){\n${mapped}}\n` : mapped;
|
|
396
407
|
}
|
|
397
408
|
}
|
|
@@ -399,9 +410,7 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
399
410
|
if (hasBeforeHandle) code += abortCheck();
|
|
400
411
|
}
|
|
401
412
|
if (hasAfterResponse || traceHandleOn) link(tee, "tee");
|
|
402
|
-
const
|
|
403
|
-
const teeCount = teeConsumers + 1;
|
|
404
|
-
const teeBlock = teeConsumers > 0 && !syncAfterResponse ? `if(_r&&(_r[Symbol.iterator]||_r[Symbol.asyncIterator])&&typeof _r.next==='function'){\nconst _s=tee(_r,${teeCount})\n_r=_s[0]\n` + (hasAfterResponse ? `_stl=_s[1]\n` : "") + (traceHandleOn ? `_trs=_s[${1 + (hasAfterResponse ? 1 : 0)}]\n` : "") + `}\n` : "";
|
|
413
|
+
const teeBlock = (hasAfterResponse || traceHandleOn) && !syncAfterResponse ? "if(_r&&(_r[Symbol.iterator]||_r[Symbol.asyncIterator])&&typeof _r.next==='function'){\nconst _s=tee(_r,2)\n_r=_s[0]\n" + (traceHandleOn ? `_trs=_s[1]\n` : `_stl=_s[1]\n`) + `}\n` : "";
|
|
405
414
|
if (traceHandleOn) {
|
|
406
415
|
const handleName = handler?.name && typeof handler.name === "string" ? handler.name : "anonymous";
|
|
407
416
|
code += beginTrace("handle", 1, handleName);
|
|
@@ -420,16 +429,13 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
420
429
|
code += abortCheck();
|
|
421
430
|
if (syncAfterResponse) {
|
|
422
431
|
link(forwardError, "fe");
|
|
423
|
-
factoryHelpers +=
|
|
424
|
-
if(_r
|
|
425
|
-
if(_r&&(_r[Symbol.iterator]||_r[Symbol.asyncIterator])&&typeof _r.next==='function'){
|
|
426
|
-
const _s=tee(_r,${teeCount})\nreturn _fin2(c,_s[0],_s[1])\n}\nreturn _fin2(c,_r,undefined)\n}\nfunction _fin2(c,_r,_stl){\nc.responseValue=_r\n` + scheduleAfterResponse + `const _m=${hasSet ? `${map}(_r,c.set,c.request,true)` : `${map}(_r,c.request,true)`}\nreturn typeof _m?.then==='function'?Promise.resolve(_m).catch((_e)=>fre(rt,c,_e)):_m\n}\n`;
|
|
427
|
-
code += "if(_r instanceof Promise)return _r.then(fe).then((_v)=>_fin(c,_v)).catch((_e)=>fre(rt,c,_e))\nreturn _fin(c,_r)\n";
|
|
432
|
+
factoryHelpers += syncScheduleDecl + "function _fin(c,_r){\nif(_r instanceof Error)throw _r\nif(_r&&(_r[Symbol.iterator]||_r[Symbol.asyncIterator])&&typeof _r.next==='function'){\nconst _s=tee(_r,2)\nreturn _fin2(c,_s[0],_s[1])\n}\nreturn _fin2(c,_r,undefined)\n}\nfunction _fin2(c,_r,_stl){\nc.responseValue=_r\n" + (syncScheduleDecl ? `_scf(c,_stl)\n` : scheduleAfterResponse) + `const _m=${mapValue("_r")}\nreturn typeof _m?.then==='function'?Promise.resolve(_m).catch((_e)=>fre(rt,c,_e)):_m\n}\n`;
|
|
433
|
+
code += "if(typeof _r?.then==='function')return Promise.resolve(_r).then(fe).then((_v)=>_fin(c,_v)).catch((_e)=>fre(rt,c,_e))\nreturn _fin(c,_r)\n";
|
|
428
434
|
} else {
|
|
429
435
|
code += `if(_r instanceof Error)throw _r\n`;
|
|
430
436
|
if (!isAsync) {
|
|
431
437
|
link(forwardError, "fe");
|
|
432
|
-
code += `else if(_r
|
|
438
|
+
code += `else if(typeof _r?.then==='function')_r=Promise.resolve(_r).then(fe)\n`;
|
|
433
439
|
}
|
|
434
440
|
if (hasAfterHandle || hasMapResponse || hasAfterResponse || hasTrace) code += `c.responseValue=_r\n`;
|
|
435
441
|
if (hasAfterHandle || hasTrace) {
|
|
@@ -437,7 +443,7 @@ const _s=tee(_r,${teeCount})\nreturn _fin2(c,_s[0],_s[1])\n}\nreturn _fin2(c,_r,
|
|
|
437
443
|
code += beginTrace("afterHandle", afLen);
|
|
438
444
|
if (hasAfterHandle) {
|
|
439
445
|
link(hook.afterHandle, "af");
|
|
440
|
-
code += mapAfterHandle(hook.afterHandle, isAsync, buildReport("afterHandle"), abortChainGuard());
|
|
446
|
+
code += mapAfterHandle(hook.afterHandle, isAsync, buildReport("afterHandle"), abortChainGuard(), arm);
|
|
441
447
|
}
|
|
442
448
|
code += endTrace("afterHandle");
|
|
443
449
|
if (hasAfterHandle) code += abortCheck();
|
|
@@ -447,7 +453,7 @@ const _s=tee(_r,${teeCount})\nreturn _fin2(c,_s[0],_s[1])\n}\nreturn _fin2(c,_r,
|
|
|
447
453
|
code += beginTrace("mapResponse", mrLen);
|
|
448
454
|
if (hasMapResponse) {
|
|
449
455
|
link(hook.mapResponse, "mr");
|
|
450
|
-
code += mapMapResponse(hook.mapResponse, isAsync, buildReport("mapResponse"), abortChainGuard());
|
|
456
|
+
code += mapMapResponse(hook.mapResponse, isAsync, buildReport("mapResponse"), abortChainGuard(), arm);
|
|
451
457
|
}
|
|
452
458
|
code += endTrace("mapResponse");
|
|
453
459
|
if (hasMapResponse) code += abortCheck();
|
|
@@ -455,26 +461,28 @@ const _s=tee(_r,${teeCount})\nreturn _fin2(c,_s[0],_s[1])\n}\nreturn _fin2(c,_r,
|
|
|
455
461
|
if (hasResponseValidator) {
|
|
456
462
|
link(vali, "va");
|
|
457
463
|
link(ElysiaStatus, "es");
|
|
458
|
-
const
|
|
464
|
+
const encodeStatus = responseValiAsync ? `(_vr.mayReturnPromise?_vr.From(_r.response,'response',true):_vr.EncodeFrom(_r.response,'response'))` : `_vr.EncodeFrom(_r.response,'response')`;
|
|
465
|
+
const encodeBody = responseValiAsync ? `(_vr.mayReturnPromise?_vr.From(_r,'response',true):_vr.EncodeFrom(_r,'response'))` : `_vr.EncodeFrom(_r,'response')`;
|
|
459
466
|
code += `if(_r instanceof es){
|
|
460
467
|
const _vr=va.response[_r.status]
|
|
461
|
-
if(_vr)_r.response=${
|
|
468
|
+
if(_vr)_r.response=${responseValiAsync ? awaitValue(encodeStatus, arm) : encodeStatus}\n}else if(!(_r instanceof Response)&&!(_r instanceof ReadableStream)&&typeof _r?.next!=='function'){\nconst _vr=va.response[c.set.status??200]\nif(_vr)_r=${responseValiAsync ? awaitValue(encodeBody, arm) : encodeBody}\n}\n`;
|
|
462
469
|
code += abortCheck();
|
|
463
470
|
}
|
|
464
|
-
|
|
471
|
+
const deferSchedule = !!schedule;
|
|
465
472
|
code += signPrefix;
|
|
466
|
-
const finalMap =
|
|
467
|
-
|
|
473
|
+
const finalMap = mapValue("_r");
|
|
474
|
+
const onMapReject = syncErrorHook ? `(_e)=>_ce(_e,c)` : dedupSchedule ? `(_e)=>{${freThenSchedule("_e")}}` : `(_e)=>fre(rt,c,_e)`;
|
|
475
|
+
if (isAsync) code += deferSchedule ? `const _m=await ${finalMap}\n${schedule}return _m\n` : `return await ${finalMap}\n`;
|
|
468
476
|
else {
|
|
469
477
|
code += `const _m=${finalMap}\n`;
|
|
470
|
-
code +=
|
|
478
|
+
code += deferSchedule ? `if(typeof _m?.then==='function')return Promise.resolve(_m).then((_v)=>{\n${schedule}return _v\n},${onMapReject})\n` + schedule + `return _m\n` : `return typeof _m?.then==='function'?Promise.resolve(_m).catch(${onMapReject}):_m\n`;
|
|
471
479
|
}
|
|
472
480
|
}
|
|
473
481
|
} else if (isHandleFunction) {
|
|
474
482
|
if (!isAsync) link(forwardError, "fe");
|
|
475
|
-
const
|
|
476
|
-
code +=
|
|
477
|
-
code += abortCheck() + `if(_r instanceof Error)throw _r\n` + (isAsync ? `return await ${
|
|
483
|
+
const finalMap = mapValue("_r");
|
|
484
|
+
code += `let ${callHandler}`;
|
|
485
|
+
code += abortCheck() + `if(_r instanceof Error)throw _r\n` + (isAsync ? `return await ${finalMap}\n` : syncErrorHook ? `if(typeof _r?.then==='function')_r=Promise.resolve(_r).then(fe)\nconst _m=${finalMap}\nreturn typeof _m?.then==='function'?Promise.resolve(_m).catch((_e)=>_ce(_e,c)):_m\n` : `if(typeof _r?.then==='function')_r=Promise.resolve(_r).then(fe)\nconst _m=${finalMap}\nreturn typeof _m?.then==='function'?Promise.resolve(_m).catch((_e)=>fre(rt,c,_e)):_m\n`);
|
|
478
486
|
} else code += `const _m=${mapReturn.trim()}\nreturn typeof _m?.then==='function'?Promise.resolve(_m).catch((_e)=>fre(rt,c,_e)):_m\n`;
|
|
479
487
|
if (hasErrorHook || hasTrace) {
|
|
480
488
|
let body = "";
|
|
@@ -487,28 +495,26 @@ if(_vr)_r.response=${awaitStr}${responseValiAsync ? `(_vr.mayReturnPromise?_vr.F
|
|
|
487
495
|
link(fallbackResponse, "fbr");
|
|
488
496
|
const allowUnsafeDetail = !!root["~config"]?.allowUnsafeValidationDetails;
|
|
489
497
|
if (allowUnsafeDetail) link(ValidationError, "verr");
|
|
490
|
-
factoryHelpers += `function _em(c,_r){return typeof _r?.then==='function'?Promise.resolve(_r).catch((_e)=>fre(rt,c,_e)):_r}\nfunction _fbm(_r,_s,_c){return ${map}(_r,_s,_c.request,true)}\n${asyncCookieSign ? "async " : ""}function _efb(e,c){\n` + (asyncCookieSign ? `let _sg\n` : ``) + signPrefix + "return _em(c,fbr(c,e,_fbm))\n}\n";
|
|
498
|
+
factoryHelpers += `function _em(c,_r){return typeof _r?.then==='function'?Promise.resolve(_r).catch((_e)=>fre(rt,c,_e)):_r}\nfunction _fbm(_r,_s,_c){return ${map}(_r,_s,_c.request,true)}\n${asyncCookieSign ? "async " : ""}function _efb(e,c){\n` + (asyncCookieSign ? `let _sg${arm ? ",_as" : ""}\n` : ``) + signPrefix + "return _em(c,fbr(c,e,_fbm))\n}\n";
|
|
491
499
|
body += `c.error=e\n` + (allowUnsafeDetail ? `if(e instanceof verr)e.allowUnsafeValidationDetails=true\n` : ``) + `if(e?.status)c.set.status=e.status
|
|
492
500
|
else if(c.set.status===undefined||c.set.status===200)c.set.status=500
|
|
493
501
|
let _r${hasMapResponse ? ",tmp" : ""}\n` + mapError(hook.error, [
|
|
494
502
|
map,
|
|
495
503
|
link,
|
|
496
|
-
|
|
497
|
-
(hasMapResponse ? `c.responseValue=_r\n` + mapMapResponse(hook.mapResponse, isAsync, void 0,
|
|
504
|
+
responseMap,
|
|
505
|
+
(hasMapResponse ? `c.responseValue=_r\n` + mapMapResponse(hook.mapResponse, isAsync, void 0, abortChainGuard(), arm) : "") + endTrace("error") + abortCatch + schedule,
|
|
498
506
|
signPrefix,
|
|
499
|
-
isAsync
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
body += `return fre(rt,c,e)\n`;
|
|
504
|
-
}
|
|
507
|
+
isAsync,
|
|
508
|
+
arm
|
|
509
|
+
], abortChainGuard()) + endTrace("error") + abortCatch + schedule + `return _efb(e,c)\n`;
|
|
510
|
+
} else body += endTrace("error") + freThenSchedule("e");
|
|
505
511
|
if (syncErrorHook) {
|
|
506
512
|
factoryHelpers += `function _ce(e,c){${abortOn ? "let _as\n" : ""}try{\n${body}}catch(_ee){return fre(rt,c,_ee)}}\n`;
|
|
507
513
|
code += `}catch(e){return _ce(e,c)}\n`;
|
|
508
514
|
} else code += `}catch(e){try{\n${body}}catch(_ee){return fre(rt,c,_ee)}}\n`;
|
|
509
|
-
} else code += `}catch(e){return fre(rt,c,e)}\n`;
|
|
515
|
+
} else code += catchSchedule ? `}catch(e){${freThenSchedule("e")}}\n` : `}catch(e){return fre(rt,c,e)}\n`;
|
|
510
516
|
code += "}";
|
|
511
|
-
code = head + (abortOn && code.includes("_as") ? "let _as\n" : "") + scheduleDecl + code;
|
|
517
|
+
code = head + (abortOn && code.includes("_as") ? "let _as\n" : "") + (code.includes("_av") ? "let _av\n" : "") + scheduleDecl + code;
|
|
512
518
|
if (factoryHelpers) code = `(function(){\n${factoryHelpers}return ${code}})()`;
|
|
513
519
|
const alias = aliasKeys.join(",");
|
|
514
520
|
const fullAlias = alias ? `rt,fre,${alias}` : "rt,fre";
|
|
@@ -520,7 +526,7 @@ let _r${hasMapResponse ? ",tmp" : ""}\n` + mapError(hook.error, [
|
|
|
520
526
|
});
|
|
521
527
|
const isGeneratorHandler = isHandleFunction && handler.constructor.name.endsWith("GeneratorFunction");
|
|
522
528
|
if (!hasTrace && isHandleFunction && !isGeneratorHandler && !inlineUnsafe) {
|
|
523
|
-
if (alias === "rc" || !isAsync && !syncErrorHook && alias === "rc,fe") return createInlineHandler(
|
|
529
|
+
if (alias === "rc" || !isAsync && !syncErrorHook && alias === "rc,fe") return createInlineHandler(responseCompact, handler);
|
|
524
530
|
else if (alias === "rm" || alias === "msh,rm" || !isAsync && !syncErrorHook && (alias === "rm,fe" || alias === "msh,rm,fe")) return responseMode === "set-with-default-headers" && inference.set ? createInlineHandlerWithDefaultHeaders(responseMap, handler) : createInlineHandlerWithSet(responseMap, handler);
|
|
525
531
|
}
|
|
526
532
|
JITProbe.record("handler:new-function");
|
|
@@ -20,9 +20,6 @@ interface HandlerParamContext {
|
|
|
20
20
|
cookieConfig: unknown;
|
|
21
21
|
tracers: unknown;
|
|
22
22
|
}
|
|
23
|
-
type Resolver = (c: HandlerParamContext) => unknown;
|
|
24
|
-
/** @internal exported for test/aot/param-descriptor.test.ts */
|
|
25
|
-
declare const handlerParams: () => Record<string, Resolver>;
|
|
26
23
|
declare function resolveHandlerParams(names: string[], c: HandlerParamContext): unknown[];
|
|
27
24
|
//#endregion
|
|
28
|
-
export {
|
|
25
|
+
export { resolveHandlerParams };
|
|
@@ -7,10 +7,10 @@ const require_cookie_utils = require('../../cookie/utils.js');
|
|
|
7
7
|
const require_handler_utils = require('../../handler/utils.js');
|
|
8
8
|
const require_handler_error = require('../../handler/error.js');
|
|
9
9
|
const require_compile_handler_utils = require('./utils.js');
|
|
10
|
+
const require_compile_handler_static_clone_resolver = require('./static-clone-resolver.js');
|
|
10
11
|
|
|
11
12
|
//#region src/compile/handler/params.ts
|
|
12
13
|
let _handlerParams;
|
|
13
|
-
/** @internal exported for test/aot/param-descriptor.test.ts */
|
|
14
14
|
const handlerParams = () => _handlerParams ??= {
|
|
15
15
|
pf: (c) => c.parse.formData,
|
|
16
16
|
pj: (c) => c.parse.json,
|
|
@@ -23,7 +23,7 @@ const handlerParams = () => _handlerParams ??= {
|
|
|
23
23
|
qa: (c) => require_compile_handler_utils.getQueryParseChannels(c.vali?.query?.schema)?.array,
|
|
24
24
|
qo: (c) => require_compile_handler_utils.getQueryParseChannels(c.vali?.query?.schema)?.object,
|
|
25
25
|
rm: (c) => c.res.map,
|
|
26
|
-
rc: (c) => c.res.compact
|
|
26
|
+
rc: (c) => c.res.compact,
|
|
27
27
|
rid: () => require_utils.requestId,
|
|
28
28
|
pq: () => require_parse_query.parseQueryFromURL,
|
|
29
29
|
pe: () => require_error.ParseError,
|
|
@@ -35,7 +35,7 @@ const handlerParams = () => _handlerParams ??= {
|
|
|
35
35
|
tee: () => require_adapter_utils.tee,
|
|
36
36
|
msh: () => require_adapter_utils.materializeSetHeaders,
|
|
37
37
|
cr: () => require_compile_handler_utils.cloneResponse,
|
|
38
|
-
scl:
|
|
38
|
+
scl: require_compile_handler_static_clone_resolver.staticCloneResolver,
|
|
39
39
|
pcr: () => require_cookie_utils.parseCookieRaw,
|
|
40
40
|
pcrs: () => require_cookie_utils.parseCookieRawSync,
|
|
41
41
|
pcrsg: () => require_cookie_utils.parseCookieRawSigned,
|
|
@@ -75,5 +75,4 @@ function resolveHandlerParams(names, c) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
//#endregion
|
|
78
|
-
exports.handlerParams = handlerParams;
|
|
79
78
|
exports.resolveHandlerParams = resolveHandlerParams;
|
|
@@ -5,11 +5,11 @@ import { parseQueryFromURL } from "../../parse-query.mjs";
|
|
|
5
5
|
import { buildCookieJar, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues } from "../../cookie/utils.mjs";
|
|
6
6
|
import { emptyResponse, finalizeRouteError, forwardError } from "../../handler/utils.mjs";
|
|
7
7
|
import { adoptErrorType, fallbackResponse } from "../../handler/error.mjs";
|
|
8
|
-
import { armEntryAbort, cloneResponse,
|
|
8
|
+
import { armEntryAbort, cloneResponse, getQueryParseChannels, hasRequestBody, replaceDeriveContext, runBeforeHandlePrefix } from "./utils.mjs";
|
|
9
|
+
import { staticCloneResolver } from "./static-clone-resolver.mjs";
|
|
9
10
|
|
|
10
11
|
//#region src/compile/handler/params.ts
|
|
11
12
|
let _handlerParams;
|
|
12
|
-
/** @internal exported for test/aot/param-descriptor.test.ts */
|
|
13
13
|
const handlerParams = () => _handlerParams ??= {
|
|
14
14
|
pf: (c) => c.parse.formData,
|
|
15
15
|
pj: (c) => c.parse.json,
|
|
@@ -22,7 +22,7 @@ const handlerParams = () => _handlerParams ??= {
|
|
|
22
22
|
qa: (c) => getQueryParseChannels(c.vali?.query?.schema)?.array,
|
|
23
23
|
qo: (c) => getQueryParseChannels(c.vali?.query?.schema)?.object,
|
|
24
24
|
rm: (c) => c.res.map,
|
|
25
|
-
rc: (c) => c.res.compact
|
|
25
|
+
rc: (c) => c.res.compact,
|
|
26
26
|
rid: () => requestId,
|
|
27
27
|
pq: () => parseQueryFromURL,
|
|
28
28
|
pe: () => ParseError,
|
|
@@ -34,7 +34,7 @@ const handlerParams = () => _handlerParams ??= {
|
|
|
34
34
|
tee: () => tee,
|
|
35
35
|
msh: () => materializeSetHeaders,
|
|
36
36
|
cr: () => cloneResponse,
|
|
37
|
-
scl:
|
|
37
|
+
scl: staticCloneResolver,
|
|
38
38
|
pcr: () => parseCookieRaw,
|
|
39
39
|
pcrs: () => parseCookieRawSync,
|
|
40
40
|
pcrsg: () => parseCookieRawSigned,
|
|
@@ -74,4 +74,4 @@ function resolveHandlerParams(names, c) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
//#endregion
|
|
77
|
-
export {
|
|
77
|
+
export { resolveHandlerParams };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyLocalHook, HTTPMethod } from "../../types.js";
|
|
2
|
-
import { CompiledCookieConfig } from "../../cookie/config.js";
|
|
3
2
|
import { AnyElysia } from "../../base.js";
|
|
3
|
+
import { CompiledCookieConfig } from "../../cookie/config.js";
|
|
4
4
|
|
|
5
5
|
//#region src/compile/handler/reconstruct.d.ts
|
|
6
6
|
declare abstract class Reconstrct {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_compile_handler_utils = require('./utils.js');
|
|
3
|
+
|
|
4
|
+
//#region src/compile/handler/static-clone-resolver.ts
|
|
5
|
+
const staticCloneResolver = () => require_compile_handler_utils.cloneStaticValue;
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.staticCloneResolver = staticCloneResolver;
|
|
@@ -22,25 +22,25 @@ declare function hasRequestBody(request: Request): boolean;
|
|
|
22
22
|
* @see `../../adapter/origin` for the provenance channel
|
|
23
23
|
*/
|
|
24
24
|
declare function armEntryAbort(context: any): any;
|
|
25
|
-
declare const mapTransform: (event: MaybeArray<TransformHandler<any, any, undefined, "local">>, rest?: [isAsync: boolean, report?: TraceReporter | undefined] | undefined, abortGuard?: string) => string;
|
|
26
|
-
declare function extractDeriveKeys(fn: Function): string[] | null;
|
|
25
|
+
declare const mapTransform: (event: MaybeArray<TransformHandler<any, any, undefined, "local">>, rest?: [isAsync: boolean, report?: TraceReporter | undefined, arm?: string | undefined] | undefined, abortGuard?: string) => string;
|
|
27
26
|
declare function replaceDeriveContext(context: any, derivative: any): any;
|
|
28
27
|
declare function deriveModes(hooks: Function[], entries?: readonly DeriveEntry[]): (boolean | undefined)[] | undefined;
|
|
29
|
-
declare function mapBeforeHandle(_hooks: AppHook['beforeHandle'] | AppHook['beforeHandle'][0], derive: readonly DeriveEntry[] | undefined, link: Link, isAsync: boolean, report?: TraceReporter, abortGuard?: string): string;
|
|
28
|
+
declare function mapBeforeHandle(_hooks: AppHook['beforeHandle'] | AppHook['beforeHandle'][0], derive: readonly DeriveEntry[] | undefined, link: Link, isAsync: boolean, report?: TraceReporter, abortGuard?: string, arm?: string): string;
|
|
30
29
|
type BeforeHandleContext = {
|
|
31
30
|
request: Request;
|
|
32
31
|
'~sig'?: AbortSignal;
|
|
33
32
|
};
|
|
34
33
|
declare function runBeforeHandlePrefix(prefix: CompactBeforeHandlePrefix, context: BeforeHandleContext, abort?: 1): any;
|
|
35
34
|
declare function runBeforeHandlePrefixAsync(prefix: CompactBeforeHandlePrefix, context: BeforeHandleContext, abort?: 1): Promise<any>;
|
|
36
|
-
declare const mapAfterHandle: (_hooks: AppHook["afterHandle"] | AppHook["afterHandle"][0], isAsync: boolean, report?: TraceReporter, abortGuard?: string) => string;
|
|
37
|
-
declare const mapMapResponse: (_hooks: AppHook["mapResponse"] | AppHook["mapResponse"][0], isAsync: boolean, report?: TraceReporter, abortGuard?: string) => string;
|
|
35
|
+
declare const mapAfterHandle: (_hooks: AppHook["afterHandle"] | AppHook["afterHandle"][0], isAsync: boolean, report?: TraceReporter, abortGuard?: string, arm?: string) => string;
|
|
36
|
+
declare const mapMapResponse: (_hooks: AppHook["mapResponse"] | AppHook["mapResponse"][0], isAsync: boolean, report?: TraceReporter, abortGuard?: string, arm?: string) => string;
|
|
38
37
|
declare const mapAfterResponse: (event: MaybeArray<AfterResponseHandler<any, any, undefined, "local">>, rest?: [report?: TraceReporter | undefined] | undefined, abortGuard?: string) => string;
|
|
39
|
-
declare const mapError: (event: MaybeArray<ErrorHandler<any, any, any>>, rest?: [map: string, link: Link, mapResponse: (response: unknown, set: Context["set"], ...params: unknown[]) => unknown, schedule: string, sign: string, isAsync: boolean] | undefined, abortGuard?: string) => string;
|
|
38
|
+
declare const mapError: (event: MaybeArray<ErrorHandler<any, any, any>>, rest?: [map: string, link: Link, mapResponse: (response: unknown, set: Context["set"], ...params: unknown[]) => unknown, schedule: string, sign: string, isAsync: boolean, arm?: string | undefined] | undefined, abortGuard?: string) => string;
|
|
40
39
|
interface QueryWalkState {
|
|
41
40
|
array: Record<string, 1> | undefined;
|
|
42
41
|
object: Record<string, 1> | undefined;
|
|
43
42
|
}
|
|
44
43
|
declare function getQueryParseChannels(querySchema: any): QueryWalkState | undefined;
|
|
44
|
+
declare function awaitGuard(fn: Function, isAsync: boolean, target: string, arm?: string): string;
|
|
45
45
|
//#endregion
|
|
46
|
-
export { Link, TraceReporter, armEntryAbort, cloneResponse, cloneStaticValue, deriveModes, emptyResponse,
|
|
46
|
+
export { Link, TraceReporter, armEntryAbort, awaitGuard, cloneResponse, cloneStaticValue, deriveModes, emptyResponse, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync };
|