elysia 2.0.0-beta.21 → 2.0.0-beta.23
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/_virtual/_rolldown/runtime.mjs +1 -0
- package/dist/adapter/bun/index.d.ts +6 -8
- package/dist/adapter/bun/index.js +6 -8
- package/dist/adapter/bun/index.mjs +7 -8
- package/dist/adapter/constants.mjs +1 -0
- package/dist/adapter/default-headers.mjs +1 -0
- package/dist/adapter/index.mjs +1 -0
- package/dist/adapter/origin.mjs +1 -0
- package/dist/adapter/response-ownership.mjs +1 -0
- package/dist/adapter/skip-clone.mjs +1 -0
- package/dist/adapter/types.mjs +1 -0
- package/dist/adapter/utils.d.ts +5 -8
- package/dist/adapter/utils.js +24 -18
- package/dist/adapter/utils.mjs +25 -18
- package/dist/adapter/web-standard/handler.mjs +2 -1
- package/dist/adapter/web-standard/index.mjs +1 -0
- package/dist/adapter/web-standard/utils.mjs +1 -0
- package/dist/base.d.ts +118 -69
- package/dist/base.js +214 -194
- package/dist/base.mjs +221 -200
- package/dist/compile/aot-capture.js +2 -2
- package/dist/compile/aot-capture.mjs +4 -3
- package/dist/compile/aot-emit.js +7 -8
- package/dist/compile/aot-emit.mjs +8 -8
- package/dist/compile/aot-reconstruct.mjs +3 -2
- package/dist/compile/aot.d.ts +3 -3
- package/dist/compile/aot.js +5 -5
- package/dist/compile/aot.mjs +6 -5
- package/dist/compile/handler/descriptor.d.ts +2 -5
- package/dist/compile/handler/descriptor.js +12 -17
- package/dist/compile/handler/descriptor.mjs +16 -21
- package/dist/compile/handler/frozen-validator.d.ts +2 -2
- package/dist/compile/handler/frozen-validator.js +3 -3
- package/dist/compile/handler/frozen-validator.mjs +4 -3
- package/dist/compile/handler/index.d.ts +3 -1
- package/dist/compile/handler/index.js +78 -118
- package/dist/compile/handler/index.mjs +84 -125
- package/dist/compile/handler/jit.d.ts +12 -12
- package/dist/compile/handler/jit.js +60 -43
- package/dist/compile/handler/jit.mjs +63 -47
- package/dist/compile/handler/params.d.ts +5 -1
- package/dist/compile/handler/params.js +14 -5
- package/dist/compile/handler/params.mjs +16 -7
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +2 -2
- package/dist/compile/handler/reconstruct.mjs +3 -2
- package/dist/compile/handler/static-clone-resolver.mjs +1 -0
- package/dist/compile/handler/utils.d.ts +13 -7
- package/dist/compile/handler/utils.js +75 -52
- package/dist/compile/handler/utils.mjs +77 -54
- package/dist/compile/jit-probe.mjs +1 -0
- package/dist/compile/lexer.js +4 -4
- package/dist/compile/lexer.mjs +5 -4
- package/dist/compile/utils.d.ts +2 -1
- package/dist/compile/utils.js +8 -3
- package/dist/compile/utils.mjs +8 -3
- package/dist/compiled.mjs +1 -0
- package/dist/constants.mjs +1 -0
- package/dist/context.d.ts +1 -1
- package/dist/context.js +1 -0
- package/dist/context.mjs +3 -1
- package/dist/cookie/config.d.ts +2 -2
- package/dist/cookie/config.js +21 -26
- package/dist/cookie/config.mjs +22 -26
- package/dist/cookie/cookie.mjs +1 -0
- package/dist/cookie/crypto.mjs +1 -0
- package/dist/cookie/error.mjs +1 -0
- package/dist/cookie/lib.mjs +1 -0
- package/dist/cookie/serialize.mjs +1 -0
- package/dist/cookie/types.mjs +1 -0
- package/dist/cookie/utils.d.ts +1 -1
- package/dist/cookie/utils.js +64 -45
- package/dist/cookie/utils.mjs +66 -46
- package/dist/error.d.ts +10 -6
- package/dist/error.js +22 -6
- package/dist/error.mjs +25 -9
- package/dist/generation.mjs +1 -0
- package/dist/handler/error.d.ts +12 -15
- package/dist/handler/error.js +43 -40
- package/dist/handler/error.mjs +45 -41
- package/dist/handler/fetch.js +59 -21
- package/dist/handler/fetch.mjs +61 -22
- package/dist/handler/utils.d.ts +16 -3
- package/dist/handler/utils.js +14 -13
- package/dist/handler/utils.mjs +16 -15
- package/dist/index.d.ts +9 -9
- package/dist/index.js +1 -0
- package/dist/index.mjs +3 -2
- package/dist/memory.mjs +1 -0
- package/dist/package.js +1 -1
- package/dist/package.mjs +2 -1
- package/dist/parse-query.js +76 -76
- package/dist/parse-query.mjs +77 -76
- package/dist/plugin/aot/bun.mjs +1 -0
- package/dist/plugin/aot/core.d.ts +1 -1
- package/dist/plugin/aot/core.js +7 -4
- package/dist/plugin/aot/core.mjs +8 -5
- package/dist/plugin/aot/esbuild.mjs +1 -0
- package/dist/plugin/aot/rspack-loader.mjs +1 -0
- package/dist/plugin/aot/rspack.mjs +1 -0
- package/dist/plugin/aot/treeshake.mjs +1 -0
- package/dist/plugin/aot/unplugin.mjs +4 -3
- package/dist/plugin/aot/vite.mjs +1 -0
- package/dist/plugin/aot/worker.mjs +1 -0
- package/dist/plugin/auto-head.mjs +1 -0
- package/dist/plugin/trace.mjs +1 -0
- package/dist/plugin/websocket.mjs +1 -0
- package/dist/route-table.mjs +1 -0
- package/dist/schema-snapshot.js +28 -3
- package/dist/schema-snapshot.mjs +29 -3
- package/dist/sucrose.d.ts +2 -2
- package/dist/sucrose.js +11 -11
- package/dist/sucrose.mjs +12 -11
- package/dist/trace.js +8 -10
- package/dist/trace.mjs +10 -11
- package/dist/type/bridge-live.d.ts +1 -1
- package/dist/type/bridge-live.mjs +1 -0
- package/dist/type/bridge.d.ts +1 -1
- package/dist/type/bridge.mjs +1 -0
- package/dist/type/coerce-plan.mjs +1 -0
- package/dist/type/coerce.d.ts +1 -1
- package/dist/type/coerce.mjs +1 -0
- package/dist/type/compat.mjs +1 -0
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/constants.mjs +1 -0
- package/dist/type/elysia/accelerate.mjs +1 -0
- package/dist/type/elysia/array-buffer.d.ts +3 -2
- package/dist/type/elysia/array-buffer.js +5 -5
- package/dist/type/elysia/array-buffer.mjs +6 -5
- package/dist/type/elysia/array-string.mjs +1 -0
- package/dist/type/elysia/array.mjs +1 -0
- package/dist/type/elysia/boolean-string.mjs +1 -0
- package/dist/type/elysia/boolean.mjs +1 -0
- package/dist/type/elysia/cookie.mjs +1 -0
- package/dist/type/elysia/date.mjs +1 -0
- package/dist/type/elysia/file-type.mjs +1 -0
- package/dist/type/elysia/file.mjs +1 -0
- package/dist/type/elysia/files.mjs +1 -0
- package/dist/type/elysia/form.mjs +1 -0
- package/dist/type/elysia/integer-string.mjs +1 -0
- package/dist/type/elysia/integer.mjs +1 -0
- package/dist/type/elysia/intersect.mjs +1 -0
- package/dist/type/elysia/json-string.mjs +1 -0
- package/dist/type/elysia/keep-config.js +8 -8
- package/dist/type/elysia/keep-config.mjs +9 -8
- package/dist/type/elysia/maybe-empty.mjs +1 -0
- package/dist/type/elysia/no-validate.mjs +1 -0
- package/dist/type/elysia/nullable.mjs +1 -0
- package/dist/type/elysia/number.mjs +1 -0
- package/dist/type/elysia/numeric-enum.d.ts +4 -2
- package/dist/type/elysia/numeric-enum.mjs +1 -0
- package/dist/type/elysia/numeric.mjs +1 -0
- package/dist/type/elysia/object-string.mjs +1 -0
- package/dist/type/elysia/object.mjs +1 -0
- package/dist/type/elysia/optional.mjs +1 -0
- package/dist/type/elysia/problem.mjs +1 -0
- package/dist/type/elysia/string.mjs +1 -0
- package/dist/type/elysia/uint8-array.d.ts +2 -1
- package/dist/type/elysia/uint8-array.js +2 -2
- package/dist/type/elysia/uint8-array.mjs +3 -2
- package/dist/type/elysia/union-enum.mjs +1 -0
- package/dist/type/elysia/union.mjs +1 -0
- package/dist/type/elysia/utils.js +3 -3
- package/dist/type/elysia/utils.mjs +4 -3
- package/dist/type/exports.mjs +1 -0
- package/dist/type/index.mjs +2 -1
- package/dist/type/shared.mjs +1 -0
- package/dist/type/sync-require.mjs +1 -0
- package/dist/type/typebox-system-lite.mjs +1 -0
- package/dist/type/typebox-system-require.mjs +1 -0
- package/dist/type/typebox-type-live.mjs +1 -0
- package/dist/type/typebox-value-live.mjs +1 -0
- package/dist/type/typebox-value-ops.mjs +1 -0
- package/dist/type/typebox-value.mjs +1 -0
- package/dist/type/types.d.ts +1 -1
- package/dist/type/types.mjs +1 -0
- package/dist/type/utils.mjs +1 -0
- package/dist/type/validator/clean-safe.mjs +1 -0
- package/dist/type/validator/custom-error.js +41 -33
- package/dist/type/validator/custom-error.mjs +42 -33
- package/dist/type/validator/default-precompute.d.ts +2 -2
- package/dist/type/validator/default-precompute.js +10 -11
- package/dist/type/validator/default-precompute.mjs +13 -13
- package/dist/type/validator/exact-mirror.mjs +1 -0
- package/dist/type/validator/frozen-check.js +7 -7
- package/dist/type/validator/frozen-check.mjs +8 -7
- package/dist/type/validator/index.d.ts +2 -2
- package/dist/type/validator/index.js +4 -8
- package/dist/type/validator/index.mjs +5 -8
- package/dist/type/validator/string-codec-aot.d.ts +1 -1
- package/dist/type/validator/string-codec-aot.mjs +1 -0
- package/dist/type/validator/validator-cache.js +18 -18
- package/dist/type/validator/validator-cache.mjs +19 -18
- package/dist/types.d.ts +108 -70
- package/dist/types.mjs +1 -0
- package/dist/universal/constants.mjs +1 -0
- package/dist/universal/file.mjs +1 -0
- package/dist/universal/index.mjs +1 -0
- package/dist/universal/is-production.mjs +1 -0
- package/dist/universal/server.mjs +1 -0
- package/dist/utils.d.ts +49 -31
- package/dist/utils.js +221 -109
- package/dist/utils.mjs +215 -106
- package/dist/validator/index.d.ts +3 -3
- package/dist/validator/index.js +4 -4
- package/dist/validator/index.mjs +5 -4
- package/dist/validator/route.d.ts +2 -2
- package/dist/validator/route.mjs +1 -0
- package/dist/ws/context.js +1 -1
- package/dist/ws/context.mjs +2 -1
- package/dist/ws/index.mjs +1 -0
- package/dist/ws/parser.mjs +1 -0
- package/dist/ws/route.js +34 -25
- package/dist/ws/route.mjs +40 -30
- package/dist/ws/types.d.ts +2 -3
- package/dist/ws/types.mjs +1 -0
- package/package.json +2 -2
|
@@ -6,7 +6,7 @@ const require_validator_route = require('../../validator/route.js');
|
|
|
6
6
|
const require_compile_handler_frozen_validator = require('./frozen-validator.js');
|
|
7
7
|
|
|
8
8
|
//#region src/compile/handler/reconstruct.ts
|
|
9
|
-
var
|
|
9
|
+
var Reconstruct = class {
|
|
10
10
|
static validator(hook, root, method, path, liveOnly = false) {
|
|
11
11
|
const frozenRoot = require_generation.frozenRootOf(root);
|
|
12
12
|
if (!liveOnly && !require_type_bridge.isBridgeLive()) {
|
|
@@ -49,4 +49,4 @@ var Reconstrct = class {
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
//#endregion
|
|
52
|
-
exports.
|
|
52
|
+
exports.Reconstruct = Reconstruct;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { isBridgeLive } from "../../type/bridge.mjs";
|
|
2
3
|
import { frozenRootOf, resolvedTraceOf, traceCapabilityRequired } from "../../generation.mjs";
|
|
3
4
|
import { compileCookieConfig } from "../../cookie/config.mjs";
|
|
@@ -5,7 +6,7 @@ import { RouteValidator } from "../../validator/route.mjs";
|
|
|
5
6
|
import { buildFrozenRouteValidator, isBridgeNotInitialized } from "./frozen-validator.mjs";
|
|
6
7
|
|
|
7
8
|
//#region src/compile/handler/reconstruct.ts
|
|
8
|
-
var
|
|
9
|
+
var Reconstruct = class {
|
|
9
10
|
static validator(hook, root, method, path, liveOnly = false) {
|
|
10
11
|
const frozenRoot = frozenRootOf(root);
|
|
11
12
|
if (!liveOnly && !isBridgeLive()) {
|
|
@@ -48,4 +49,4 @@ var Reconstrct = class {
|
|
|
48
49
|
};
|
|
49
50
|
|
|
50
51
|
//#endregion
|
|
51
|
-
export {
|
|
52
|
+
export { Reconstruct };
|
|
@@ -20,19 +20,25 @@ declare function hasRequestBody(request: Request): boolean;
|
|
|
20
20
|
* @see `../../adapter/origin` for the provenance channel
|
|
21
21
|
*/
|
|
22
22
|
declare function armEntryAbort(context: any): any;
|
|
23
|
-
declare const mapTransform: (event: MaybeArray<TransformHandler<any, any, undefined, "local">>, rest?: [
|
|
23
|
+
declare const mapTransform: (event: MaybeArray<TransformHandler<any, any, undefined, "local">>, rest?: [mode: AsyncMode, report?: TraceReporter | undefined, arm?: string | undefined] | undefined, abortGuard?: string, tail?: TailMode) => string;
|
|
24
24
|
declare function replaceDeriveContext(context: any, derivative: any): any;
|
|
25
25
|
declare function deriveModes(hooks: Function[], entries?: readonly DeriveEntry[]): (boolean | undefined)[] | undefined;
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* `~deriveEntries` of the `beforeHandle` lists of `parts` joined in order,
|
|
28
|
+
* each occurrence keeping the role its own part gave it; undefined when
|
|
29
|
+
* their own entries joined already do
|
|
30
|
+
*/
|
|
31
|
+
declare function joinDeriveEntries(parts: readonly (Partial<AppHook> | undefined)[]): DeriveEntry[] | undefined;
|
|
32
|
+
declare function mapBeforeHandle(_hooks: AppHook['beforeHandle'] | AppHook['beforeHandle'][0], derive: readonly DeriveEntry[] | undefined, link: Link, mode: AsyncMode, report?: TraceReporter, abortGuard?: string, arm?: string): string;
|
|
27
33
|
type BeforeHandleContext = {
|
|
28
34
|
request: Request;
|
|
29
35
|
'~sig'?: AbortSignal;
|
|
30
36
|
};
|
|
31
37
|
declare function runBeforeHandlePrefix(prefix: CompactBeforeHandlePrefix, context: BeforeHandleContext, abort?: 1): any;
|
|
32
38
|
declare function runBeforeHandlePrefixAsync(prefix: CompactBeforeHandlePrefix, context: BeforeHandleContext, abort?: 1): Promise<any>;
|
|
33
|
-
declare function mapChainHook(_hooks: Function | Function[], prefix: string,
|
|
39
|
+
declare function mapChainHook(_hooks: Function | Function[], prefix: string, mode: AsyncMode, report?: TraceReporter, abortGuard?: string, arm?: string): string;
|
|
34
40
|
declare const mapAfterResponse: (event: MaybeArray<AfterResponseHandler<any, any, undefined, "local">>, rest?: [report?: TraceReporter | undefined] | undefined, abortGuard?: string, tail?: TailMode) => string;
|
|
35
|
-
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,
|
|
41
|
+
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, mode: AsyncMode, arm?: string | undefined] | undefined, abortGuard?: string, tail?: TailMode) => string;
|
|
36
42
|
interface QueryWalkState {
|
|
37
43
|
array: Record<string, 1> | undefined;
|
|
38
44
|
object: Record<string, 1> | undefined;
|
|
@@ -48,9 +54,9 @@ interface TailMode {
|
|
|
48
54
|
sites: string[];
|
|
49
55
|
}
|
|
50
56
|
declare const asyncTail: (mode: AsyncMode) => TailMode | undefined;
|
|
51
|
-
declare function awaitSite(call: string, fn: Function,
|
|
57
|
+
declare function awaitSite(call: string, fn: Function, mode: AsyncMode, target: string, arm?: string): string;
|
|
52
58
|
declare const tailStage: (mode: TailMode, guard?: string) => string;
|
|
53
59
|
declare const tailPlain: (mode: AsyncMode, code: string) => string;
|
|
54
|
-
declare function awaitGuard(fn: Function,
|
|
60
|
+
declare function awaitGuard(fn: Function, mode: AsyncMode, target: string, arm?: string): string;
|
|
55
61
|
//#endregion
|
|
56
|
-
export { AsyncMode, Link, TailMode, TraceReporter, armEntryAbort, asyncTail, awaitGuard, awaitSite, cloneResponse, cloneStaticValue, deriveModes, getQueryParseChannels, hasRequestBody, mapAfterResponse, mapBeforeHandle, mapChainHook, mapError, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync, tailPlain, tailStage };
|
|
62
|
+
export { AsyncMode, Link, TailMode, TraceReporter, armEntryAbort, asyncTail, awaitGuard, awaitSite, cloneResponse, cloneStaticValue, deriveModes, getQueryParseChannels, hasRequestBody, joinDeriveEntries, mapAfterResponse, mapBeforeHandle, mapChainHook, mapError, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync, tailPlain, tailStage };
|
|
@@ -52,11 +52,11 @@ function armEntryAbort(context) {
|
|
|
52
52
|
if (context.request === require_adapter_origin.origin.request) return false;
|
|
53
53
|
return (context["~sig"] = context.request.signal).aborted;
|
|
54
54
|
}
|
|
55
|
-
const
|
|
55
|
+
const traceChild = (report, fn) => report?.resolveChild(fn?.name && typeof fn.name === "string" ? fn.name : "anonymous") ?? noTrace;
|
|
56
56
|
const toArray = (v) => Array.isArray(v) ? v : [v];
|
|
57
|
-
const mapTransform = /* @__PURE__ */ map((i, fn, [
|
|
58
|
-
const t =
|
|
59
|
-
const call =
|
|
57
|
+
const mapTransform = /* @__PURE__ */ map((i, fn, [mode, report, arm]) => {
|
|
58
|
+
const t = traceChild(report, fn);
|
|
59
|
+
const call = mode ? awaitSite(`tf${at(i)}(c)`, fn, mode, "_tf", arm) : `tf${at(i)}(c)\n`;
|
|
60
60
|
return t.begin + call + t.end();
|
|
61
61
|
});
|
|
62
62
|
const deriveKeyCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -76,8 +76,8 @@ function extractDeriveKeys(fn) {
|
|
|
76
76
|
function returnedObjectKeys(src) {
|
|
77
77
|
const tokens = require_compile_lexer.scanTokens(src);
|
|
78
78
|
if (!tokens) return null;
|
|
79
|
-
const
|
|
80
|
-
const
|
|
79
|
+
const isPunct = (i, value) => tokens[i]?.k === "p" && tokens[i].value === value;
|
|
80
|
+
const spaceOnlyAfter = (i) => {
|
|
81
81
|
const token = tokens[i];
|
|
82
82
|
return /^[ \t\n\r]*$/.test(src.slice(token.at + token.value.length + (token.k === "s" ? 2 : 0), tokens[i + 1]?.at));
|
|
83
83
|
};
|
|
@@ -92,12 +92,12 @@ function returnedObjectKeys(src) {
|
|
|
92
92
|
else if (value === "(" || value === "[" || value === "{") depth++;
|
|
93
93
|
else if (value === ")" || value === "]" || value === "}") depth--;
|
|
94
94
|
else if (depth === 0 && value === "=>") {
|
|
95
|
-
if (!
|
|
96
|
-
if (
|
|
97
|
-
if (!
|
|
95
|
+
if (!spaceOnlyAfter(i)) return null;
|
|
96
|
+
if (isPunct(i + 1, "(")) {
|
|
97
|
+
if (!spaceOnlyAfter(i + 1) || !isPunct(i + 2, "{")) return null;
|
|
98
98
|
open = i + 2;
|
|
99
99
|
parens = 1;
|
|
100
|
-
} else if (!
|
|
100
|
+
} else if (!isPunct(i + 1, "{")) return null;
|
|
101
101
|
break;
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -112,15 +112,15 @@ function returnedObjectKeys(src) {
|
|
|
112
112
|
} else if (value.includes("return") && /[^\w$]/.test(value)) return null;
|
|
113
113
|
}
|
|
114
114
|
if (at === -1) return null;
|
|
115
|
-
for (;
|
|
116
|
-
if (!
|
|
115
|
+
for (; spaceOnlyAfter(at) && isPunct(at + 1, "("); at++) parens++;
|
|
116
|
+
if (!spaceOnlyAfter(at) || !isPunct(at + 1, "{")) return null;
|
|
117
117
|
open = at + 1;
|
|
118
118
|
}
|
|
119
119
|
const keys = [];
|
|
120
120
|
let i = open + 1;
|
|
121
|
-
while (!
|
|
121
|
+
while (!isPunct(i, "}")) {
|
|
122
122
|
const key = tokens[i];
|
|
123
|
-
if (!key || (key.k === "s" ? key.value.includes("\\") : key.k !== "i" || !/^[\w$]+$/.test(key.value)) || !
|
|
123
|
+
if (!key || (key.k === "s" ? key.value.includes("\\") : key.k !== "i" || !/^[\w$]+$/.test(key.value)) || !spaceOnlyAfter(i) || !isPunct(i + 1, ":")) return null;
|
|
124
124
|
keys.push(key.value);
|
|
125
125
|
for (depth = 0, i += 2;; i++) {
|
|
126
126
|
const token = tokens[i];
|
|
@@ -136,10 +136,10 @@ function returnedObjectKeys(src) {
|
|
|
136
136
|
depth--;
|
|
137
137
|
} else if (value === "," && depth === 0) break;
|
|
138
138
|
}
|
|
139
|
-
if (
|
|
139
|
+
if (isPunct(i, ",")) i++;
|
|
140
140
|
}
|
|
141
|
-
for (; parens; parens--) if (!
|
|
142
|
-
return i + 1 === tokens.length ||
|
|
141
|
+
for (; parens; parens--) if (!isPunct(++i, ")")) return null;
|
|
142
|
+
return i + 1 === tokens.length || isPunct(i + 1, ";") || isPunct(i + 1, "}") ? keys : null;
|
|
143
143
|
}
|
|
144
144
|
function replaceDeriveContext(context, derivative) {
|
|
145
145
|
const next = Object.create(Object.getPrototypeOf(context));
|
|
@@ -168,34 +168,56 @@ function replaceDeriveContext(context, derivative) {
|
|
|
168
168
|
return next;
|
|
169
169
|
}
|
|
170
170
|
function deriveModes(hooks, entries) {
|
|
171
|
-
|
|
172
|
-
if (entries?.length) {
|
|
173
|
-
queues = /* @__PURE__ */ new Map();
|
|
174
|
-
for (let i = 0; i < entries.length; i++) {
|
|
175
|
-
const entry = entries[i];
|
|
176
|
-
const fn = require_utils.deriveEntryFn(entry);
|
|
177
|
-
const queue = queues.get(fn);
|
|
178
|
-
const mode = require_utils.isMapDeriveEntry(entry);
|
|
179
|
-
if (queue) queue.push(mode);
|
|
180
|
-
else queues.set(fn, [mode]);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
171
|
+
const queues = require_utils.deriveQueues(entries);
|
|
183
172
|
if (!queues) return;
|
|
184
173
|
let found = false;
|
|
185
174
|
const modes = Array(hooks.length);
|
|
186
175
|
for (let i = 0; i < hooks.length; i++) {
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
176
|
+
const entry = queues.get(hooks[i])?.shift();
|
|
177
|
+
if (entry === void 0 || require_utils.isPlainDeriveEntry(entry)) continue;
|
|
178
|
+
modes[i] = require_utils.isMapDeriveEntry(entry);
|
|
190
179
|
found = true;
|
|
191
|
-
modes[i] = queue.shift();
|
|
192
180
|
}
|
|
193
181
|
return found ? modes : void 0;
|
|
194
182
|
}
|
|
195
|
-
|
|
183
|
+
const deriveEntriesOf = (part) => part?.["~deriveEntries"];
|
|
184
|
+
function sharesDerive(part, index, parts) {
|
|
185
|
+
const entries = deriveEntriesOf(part);
|
|
186
|
+
if (entries) for (let i = 0; i < parts.length; i++) {
|
|
187
|
+
const other = parts[i]?.beforeHandle;
|
|
188
|
+
if (i === index || !other) continue;
|
|
189
|
+
for (let j = 0; j < entries.length; j++) {
|
|
190
|
+
const fn = require_utils.deriveEntryFn(entries[j]);
|
|
191
|
+
if (Array.isArray(other) ? other.includes(fn) : other === fn) return true;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* `~deriveEntries` of the `beforeHandle` lists of `parts` joined in order,
|
|
198
|
+
* each occurrence keeping the role its own part gave it; undefined when
|
|
199
|
+
* their own entries joined already do
|
|
200
|
+
*/
|
|
201
|
+
function joinDeriveEntries(parts) {
|
|
202
|
+
if (!parts.some(sharesDerive)) return;
|
|
203
|
+
const hooks = [];
|
|
204
|
+
let at;
|
|
205
|
+
for (const part of parts) {
|
|
206
|
+
const value = part?.beforeHandle;
|
|
207
|
+
if (!value) continue;
|
|
208
|
+
const queues = require_utils.deriveQueues(deriveEntriesOf(part));
|
|
209
|
+
for (const fn of toArray(value)) {
|
|
210
|
+
const entry = queues?.get(fn)?.shift();
|
|
211
|
+
if (entry !== void 0 && !require_utils.isPlainDeriveEntry(entry)) (at ??= [])[hooks.length] = entry;
|
|
212
|
+
hooks.push(fn);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (at) return require_utils.occurrenceDeriveEntries(hooks, at);
|
|
216
|
+
}
|
|
217
|
+
function mapBeforeHandle(_hooks, derive, link, mode, report, abortGuard, arm) {
|
|
196
218
|
const hooks = toArray(_hooks);
|
|
197
219
|
const modes = deriveModes(hooks, derive);
|
|
198
|
-
const tail = asyncTail(
|
|
220
|
+
const tail = asyncTail(mode);
|
|
199
221
|
let code = "";
|
|
200
222
|
let depth = 0;
|
|
201
223
|
let needsEs = false;
|
|
@@ -207,9 +229,9 @@ function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard, arm)
|
|
|
207
229
|
code += `if(${guard}){\n`;
|
|
208
230
|
depth++;
|
|
209
231
|
}
|
|
210
|
-
const t =
|
|
232
|
+
const t = traceChild(report, fn);
|
|
211
233
|
code += t.begin;
|
|
212
|
-
code += awaitSite(`bf${at(i)}(c)`, fn,
|
|
234
|
+
code += awaitSite(`bf${at(i)}(c)`, fn, mode, "tmp", arm);
|
|
213
235
|
if (modes?.[i] !== void 0) {
|
|
214
236
|
needsEs = true;
|
|
215
237
|
link(require_handler_utils.registerDeriveDisposable, "dsp");
|
|
@@ -265,9 +287,9 @@ async function runBeforeHandlePrefixAsync(prefix, context, abort) {
|
|
|
265
287
|
}
|
|
266
288
|
}
|
|
267
289
|
}
|
|
268
|
-
function mapChainHook(_hooks, prefix,
|
|
290
|
+
function mapChainHook(_hooks, prefix, mode, report, abortGuard, arm) {
|
|
269
291
|
const hooks = toArray(_hooks);
|
|
270
|
-
const tail = asyncTail(
|
|
292
|
+
const tail = asyncTail(mode);
|
|
271
293
|
let code = "";
|
|
272
294
|
let depth = 0;
|
|
273
295
|
for (let i = 0; i < hooks.length; i++) {
|
|
@@ -278,25 +300,25 @@ function mapChainHook(_hooks, prefix, isAsync, report, abortGuard, arm) {
|
|
|
278
300
|
code += `if(${guard}){\n`;
|
|
279
301
|
depth++;
|
|
280
302
|
}
|
|
281
|
-
const t =
|
|
303
|
+
const t = traceChild(report, fn);
|
|
282
304
|
code += t.begin;
|
|
283
|
-
code += awaitSite(`${prefix}${at(i)}(c)`, fn,
|
|
305
|
+
code += awaitSite(`${prefix}${at(i)}(c)`, fn, mode, "tmp", arm);
|
|
284
306
|
code += t.end("tmp");
|
|
285
307
|
if (tail) code += "}\n";
|
|
286
308
|
}
|
|
287
309
|
code += "}".repeat(depth);
|
|
288
|
-
code += tailPlain(
|
|
310
|
+
code += tailPlain(mode, `if(tmp!==undefined)_r=c.responseValue=tmp\n`);
|
|
289
311
|
return code;
|
|
290
312
|
}
|
|
291
313
|
const mapAfterResponse = /* @__PURE__ */ map((i, fn, [report]) => {
|
|
292
|
-
const t =
|
|
314
|
+
const t = traceChild(report, fn);
|
|
293
315
|
const call = require_compile_utils.isAsyncFunction(fn) ? `await ar${at(i)}(c)\n` : `let _ar=ar${at(i)}(c)\nif(typeof _ar?.then==='function')await _ar\n`;
|
|
294
316
|
return `try{${t.begin}${call}${t.end()}}catch(_e){${t.end("_e")}console.error(_e)}\n`;
|
|
295
317
|
});
|
|
296
|
-
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign,
|
|
318
|
+
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign, mode, arm]) => {
|
|
297
319
|
link(mapResponse, "rm");
|
|
298
320
|
link(require_handler_error.adoptErrorType, "aet");
|
|
299
|
-
return awaitSite(`er${at(i)}(c)`, fn,
|
|
321
|
+
return awaitSite(`er${at(i)}(c)`, fn, mode, "_r", arm) + "if(_r!==undefined){\nif(_r instanceof Response)c.set.status=_r.status\nelse if(c.set.status===undefined||c.set.status===200)c.set.status=500\n" + schedule + sign + `return _em(c,${map}(aet(_r,e),c.set,c.request,true))\n}\n`;
|
|
300
322
|
});
|
|
301
323
|
function map(map) {
|
|
302
324
|
return function(event, rest, abortGuard, tail) {
|
|
@@ -387,16 +409,16 @@ function getQueryParseChannels(querySchema) {
|
|
|
387
409
|
return result ?? void 0;
|
|
388
410
|
}
|
|
389
411
|
const asyncTail = (mode) => typeof mode === "object" && mode.async ? mode : void 0;
|
|
390
|
-
function awaitSite(call, fn,
|
|
391
|
-
if (typeof
|
|
392
|
-
const k =
|
|
393
|
-
|
|
394
|
-
return
|
|
412
|
+
function awaitSite(call, fn, mode, target, arm = "") {
|
|
413
|
+
if (typeof mode !== "object") return `${target}=${call}\n${awaitGuard(fn, mode, target, arm)}`;
|
|
414
|
+
const k = mode.n++;
|
|
415
|
+
mode.sites.push(`${mode.e ? "e:" : ""}${target}=${call}`);
|
|
416
|
+
return mode.async ? `${target}=_rk===${k}?_y:${call}\nif(_rk===${k}||typeof ${target}?.then==='function'){${arm ? `;${arm}\n` : ""}${target}=await ${target}}\n` : `${target}=${call}\nif(typeof ${target}?.then==='function')return _t(c,${k},${target},${mode.r ? "_r" : "undefined"},${mode.e ? "e" : "undefined"}${mode.live})\n`;
|
|
395
417
|
}
|
|
396
418
|
const tailStage = (mode, guard) => `if(_rk<=${mode.n}${guard ? `&&(_rk===${mode.n}||${guard})` : ""}){\n`;
|
|
397
419
|
const tailPlain = (mode, code) => !code || !asyncTail(mode) ? code : mode.n ? `if(_rk<${mode.n}){\n${code}}\n` : "";
|
|
398
|
-
function awaitGuard(fn,
|
|
399
|
-
if (!
|
|
420
|
+
function awaitGuard(fn, mode, target, arm = "") {
|
|
421
|
+
if (!mode) return "";
|
|
400
422
|
const code = `${arm ? `;${arm}\n` : ""}${target}=await ${target}\n`;
|
|
401
423
|
return require_compile_utils.isAsyncFunction(fn) ? code : `if(typeof ${target}?.then==='function'){${code}}\n`;
|
|
402
424
|
}
|
|
@@ -411,6 +433,7 @@ exports.cloneStaticValue = cloneStaticValue;
|
|
|
411
433
|
exports.deriveModes = deriveModes;
|
|
412
434
|
exports.getQueryParseChannels = getQueryParseChannels;
|
|
413
435
|
exports.hasRequestBody = hasRequestBody;
|
|
436
|
+
exports.joinDeriveEntries = joinDeriveEntries;
|
|
414
437
|
exports.mapAfterResponse = mapAfterResponse;
|
|
415
438
|
exports.mapBeforeHandle = mapBeforeHandle;
|
|
416
439
|
exports.mapChainHook = mapChainHook;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
import { ElysiaFile } from "../../universal/file.mjs";
|
|
2
|
-
import { assignOwn, deriveEntryFn, isMapDeriveEntry } from "../../utils.mjs";
|
|
3
|
+
import { assignOwn, deriveEntryFn, deriveQueues, isMapDeriveEntry, isPlainDeriveEntry, occurrenceDeriveEntries } from "../../utils.mjs";
|
|
3
4
|
import { ELYSIA_TYPES } from "../../type/constants.mjs";
|
|
4
5
|
import { skipClone } from "../../adapter/skip-clone.mjs";
|
|
5
6
|
import { ElysiaStatus } from "../../error.mjs";
|
|
@@ -51,11 +52,11 @@ function armEntryAbort(context) {
|
|
|
51
52
|
if (context.request === origin.request) return false;
|
|
52
53
|
return (context["~sig"] = context.request.signal).aborted;
|
|
53
54
|
}
|
|
54
|
-
const
|
|
55
|
+
const traceChild = (report, fn) => report?.resolveChild(fn?.name && typeof fn.name === "string" ? fn.name : "anonymous") ?? noTrace;
|
|
55
56
|
const toArray = (v) => Array.isArray(v) ? v : [v];
|
|
56
|
-
const mapTransform = /* @__PURE__ */ map((i, fn, [
|
|
57
|
-
const t =
|
|
58
|
-
const call =
|
|
57
|
+
const mapTransform = /* @__PURE__ */ map((i, fn, [mode, report, arm]) => {
|
|
58
|
+
const t = traceChild(report, fn);
|
|
59
|
+
const call = mode ? awaitSite(`tf${at(i)}(c)`, fn, mode, "_tf", arm) : `tf${at(i)}(c)\n`;
|
|
59
60
|
return t.begin + call + t.end();
|
|
60
61
|
});
|
|
61
62
|
const deriveKeyCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -75,8 +76,8 @@ function extractDeriveKeys(fn) {
|
|
|
75
76
|
function returnedObjectKeys(src) {
|
|
76
77
|
const tokens = scanTokens(src);
|
|
77
78
|
if (!tokens) return null;
|
|
78
|
-
const
|
|
79
|
-
const
|
|
79
|
+
const isPunct = (i, value) => tokens[i]?.k === "p" && tokens[i].value === value;
|
|
80
|
+
const spaceOnlyAfter = (i) => {
|
|
80
81
|
const token = tokens[i];
|
|
81
82
|
return /^[ \t\n\r]*$/.test(src.slice(token.at + token.value.length + (token.k === "s" ? 2 : 0), tokens[i + 1]?.at));
|
|
82
83
|
};
|
|
@@ -91,12 +92,12 @@ function returnedObjectKeys(src) {
|
|
|
91
92
|
else if (value === "(" || value === "[" || value === "{") depth++;
|
|
92
93
|
else if (value === ")" || value === "]" || value === "}") depth--;
|
|
93
94
|
else if (depth === 0 && value === "=>") {
|
|
94
|
-
if (!
|
|
95
|
-
if (
|
|
96
|
-
if (!
|
|
95
|
+
if (!spaceOnlyAfter(i)) return null;
|
|
96
|
+
if (isPunct(i + 1, "(")) {
|
|
97
|
+
if (!spaceOnlyAfter(i + 1) || !isPunct(i + 2, "{")) return null;
|
|
97
98
|
open = i + 2;
|
|
98
99
|
parens = 1;
|
|
99
|
-
} else if (!
|
|
100
|
+
} else if (!isPunct(i + 1, "{")) return null;
|
|
100
101
|
break;
|
|
101
102
|
}
|
|
102
103
|
}
|
|
@@ -111,15 +112,15 @@ function returnedObjectKeys(src) {
|
|
|
111
112
|
} else if (value.includes("return") && /[^\w$]/.test(value)) return null;
|
|
112
113
|
}
|
|
113
114
|
if (at === -1) return null;
|
|
114
|
-
for (;
|
|
115
|
-
if (!
|
|
115
|
+
for (; spaceOnlyAfter(at) && isPunct(at + 1, "("); at++) parens++;
|
|
116
|
+
if (!spaceOnlyAfter(at) || !isPunct(at + 1, "{")) return null;
|
|
116
117
|
open = at + 1;
|
|
117
118
|
}
|
|
118
119
|
const keys = [];
|
|
119
120
|
let i = open + 1;
|
|
120
|
-
while (!
|
|
121
|
+
while (!isPunct(i, "}")) {
|
|
121
122
|
const key = tokens[i];
|
|
122
|
-
if (!key || (key.k === "s" ? key.value.includes("\\") : key.k !== "i" || !/^[\w$]+$/.test(key.value)) || !
|
|
123
|
+
if (!key || (key.k === "s" ? key.value.includes("\\") : key.k !== "i" || !/^[\w$]+$/.test(key.value)) || !spaceOnlyAfter(i) || !isPunct(i + 1, ":")) return null;
|
|
123
124
|
keys.push(key.value);
|
|
124
125
|
for (depth = 0, i += 2;; i++) {
|
|
125
126
|
const token = tokens[i];
|
|
@@ -135,10 +136,10 @@ function returnedObjectKeys(src) {
|
|
|
135
136
|
depth--;
|
|
136
137
|
} else if (value === "," && depth === 0) break;
|
|
137
138
|
}
|
|
138
|
-
if (
|
|
139
|
+
if (isPunct(i, ",")) i++;
|
|
139
140
|
}
|
|
140
|
-
for (; parens; parens--) if (!
|
|
141
|
-
return i + 1 === tokens.length ||
|
|
141
|
+
for (; parens; parens--) if (!isPunct(++i, ")")) return null;
|
|
142
|
+
return i + 1 === tokens.length || isPunct(i + 1, ";") || isPunct(i + 1, "}") ? keys : null;
|
|
142
143
|
}
|
|
143
144
|
function replaceDeriveContext(context, derivative) {
|
|
144
145
|
const next = Object.create(Object.getPrototypeOf(context));
|
|
@@ -167,34 +168,56 @@ function replaceDeriveContext(context, derivative) {
|
|
|
167
168
|
return next;
|
|
168
169
|
}
|
|
169
170
|
function deriveModes(hooks, entries) {
|
|
170
|
-
|
|
171
|
-
if (entries?.length) {
|
|
172
|
-
queues = /* @__PURE__ */ new Map();
|
|
173
|
-
for (let i = 0; i < entries.length; i++) {
|
|
174
|
-
const entry = entries[i];
|
|
175
|
-
const fn = deriveEntryFn(entry);
|
|
176
|
-
const queue = queues.get(fn);
|
|
177
|
-
const mode = isMapDeriveEntry(entry);
|
|
178
|
-
if (queue) queue.push(mode);
|
|
179
|
-
else queues.set(fn, [mode]);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
171
|
+
const queues = deriveQueues(entries);
|
|
182
172
|
if (!queues) return;
|
|
183
173
|
let found = false;
|
|
184
174
|
const modes = Array(hooks.length);
|
|
185
175
|
for (let i = 0; i < hooks.length; i++) {
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
176
|
+
const entry = queues.get(hooks[i])?.shift();
|
|
177
|
+
if (entry === void 0 || isPlainDeriveEntry(entry)) continue;
|
|
178
|
+
modes[i] = isMapDeriveEntry(entry);
|
|
189
179
|
found = true;
|
|
190
|
-
modes[i] = queue.shift();
|
|
191
180
|
}
|
|
192
181
|
return found ? modes : void 0;
|
|
193
182
|
}
|
|
194
|
-
|
|
183
|
+
const deriveEntriesOf = (part) => part?.["~deriveEntries"];
|
|
184
|
+
function sharesDerive(part, index, parts) {
|
|
185
|
+
const entries = deriveEntriesOf(part);
|
|
186
|
+
if (entries) for (let i = 0; i < parts.length; i++) {
|
|
187
|
+
const other = parts[i]?.beforeHandle;
|
|
188
|
+
if (i === index || !other) continue;
|
|
189
|
+
for (let j = 0; j < entries.length; j++) {
|
|
190
|
+
const fn = deriveEntryFn(entries[j]);
|
|
191
|
+
if (Array.isArray(other) ? other.includes(fn) : other === fn) return true;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* `~deriveEntries` of the `beforeHandle` lists of `parts` joined in order,
|
|
198
|
+
* each occurrence keeping the role its own part gave it; undefined when
|
|
199
|
+
* their own entries joined already do
|
|
200
|
+
*/
|
|
201
|
+
function joinDeriveEntries(parts) {
|
|
202
|
+
if (!parts.some(sharesDerive)) return;
|
|
203
|
+
const hooks = [];
|
|
204
|
+
let at;
|
|
205
|
+
for (const part of parts) {
|
|
206
|
+
const value = part?.beforeHandle;
|
|
207
|
+
if (!value) continue;
|
|
208
|
+
const queues = deriveQueues(deriveEntriesOf(part));
|
|
209
|
+
for (const fn of toArray(value)) {
|
|
210
|
+
const entry = queues?.get(fn)?.shift();
|
|
211
|
+
if (entry !== void 0 && !isPlainDeriveEntry(entry)) (at ??= [])[hooks.length] = entry;
|
|
212
|
+
hooks.push(fn);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (at) return occurrenceDeriveEntries(hooks, at);
|
|
216
|
+
}
|
|
217
|
+
function mapBeforeHandle(_hooks, derive, link, mode, report, abortGuard, arm) {
|
|
195
218
|
const hooks = toArray(_hooks);
|
|
196
219
|
const modes = deriveModes(hooks, derive);
|
|
197
|
-
const tail = asyncTail(
|
|
220
|
+
const tail = asyncTail(mode);
|
|
198
221
|
let code = "";
|
|
199
222
|
let depth = 0;
|
|
200
223
|
let needsEs = false;
|
|
@@ -206,9 +229,9 @@ function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard, arm)
|
|
|
206
229
|
code += `if(${guard}){\n`;
|
|
207
230
|
depth++;
|
|
208
231
|
}
|
|
209
|
-
const t =
|
|
232
|
+
const t = traceChild(report, fn);
|
|
210
233
|
code += t.begin;
|
|
211
|
-
code += awaitSite(`bf${at(i)}(c)`, fn,
|
|
234
|
+
code += awaitSite(`bf${at(i)}(c)`, fn, mode, "tmp", arm);
|
|
212
235
|
if (modes?.[i] !== void 0) {
|
|
213
236
|
needsEs = true;
|
|
214
237
|
link(registerDeriveDisposable, "dsp");
|
|
@@ -264,9 +287,9 @@ async function runBeforeHandlePrefixAsync(prefix, context, abort) {
|
|
|
264
287
|
}
|
|
265
288
|
}
|
|
266
289
|
}
|
|
267
|
-
function mapChainHook(_hooks, prefix,
|
|
290
|
+
function mapChainHook(_hooks, prefix, mode, report, abortGuard, arm) {
|
|
268
291
|
const hooks = toArray(_hooks);
|
|
269
|
-
const tail = asyncTail(
|
|
292
|
+
const tail = asyncTail(mode);
|
|
270
293
|
let code = "";
|
|
271
294
|
let depth = 0;
|
|
272
295
|
for (let i = 0; i < hooks.length; i++) {
|
|
@@ -277,25 +300,25 @@ function mapChainHook(_hooks, prefix, isAsync, report, abortGuard, arm) {
|
|
|
277
300
|
code += `if(${guard}){\n`;
|
|
278
301
|
depth++;
|
|
279
302
|
}
|
|
280
|
-
const t =
|
|
303
|
+
const t = traceChild(report, fn);
|
|
281
304
|
code += t.begin;
|
|
282
|
-
code += awaitSite(`${prefix}${at(i)}(c)`, fn,
|
|
305
|
+
code += awaitSite(`${prefix}${at(i)}(c)`, fn, mode, "tmp", arm);
|
|
283
306
|
code += t.end("tmp");
|
|
284
307
|
if (tail) code += "}\n";
|
|
285
308
|
}
|
|
286
309
|
code += "}".repeat(depth);
|
|
287
|
-
code += tailPlain(
|
|
310
|
+
code += tailPlain(mode, `if(tmp!==undefined)_r=c.responseValue=tmp\n`);
|
|
288
311
|
return code;
|
|
289
312
|
}
|
|
290
313
|
const mapAfterResponse = /* @__PURE__ */ map((i, fn, [report]) => {
|
|
291
|
-
const t =
|
|
314
|
+
const t = traceChild(report, fn);
|
|
292
315
|
const call = isAsyncFunction(fn) ? `await ar${at(i)}(c)\n` : `let _ar=ar${at(i)}(c)\nif(typeof _ar?.then==='function')await _ar\n`;
|
|
293
316
|
return `try{${t.begin}${call}${t.end()}}catch(_e){${t.end("_e")}console.error(_e)}\n`;
|
|
294
317
|
});
|
|
295
|
-
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign,
|
|
318
|
+
const mapError = /* @__PURE__ */ map((i, fn, [map, link, mapResponse, schedule, sign, mode, arm]) => {
|
|
296
319
|
link(mapResponse, "rm");
|
|
297
320
|
link(adoptErrorType, "aet");
|
|
298
|
-
return awaitSite(`er${at(i)}(c)`, fn,
|
|
321
|
+
return awaitSite(`er${at(i)}(c)`, fn, mode, "_r", arm) + "if(_r!==undefined){\nif(_r instanceof Response)c.set.status=_r.status\nelse if(c.set.status===undefined||c.set.status===200)c.set.status=500\n" + schedule + sign + `return _em(c,${map}(aet(_r,e),c.set,c.request,true))\n}\n`;
|
|
299
322
|
});
|
|
300
323
|
function map(map) {
|
|
301
324
|
return function(event, rest, abortGuard, tail) {
|
|
@@ -386,19 +409,19 @@ function getQueryParseChannels(querySchema) {
|
|
|
386
409
|
return result ?? void 0;
|
|
387
410
|
}
|
|
388
411
|
const asyncTail = (mode) => typeof mode === "object" && mode.async ? mode : void 0;
|
|
389
|
-
function awaitSite(call, fn,
|
|
390
|
-
if (typeof
|
|
391
|
-
const k =
|
|
392
|
-
|
|
393
|
-
return
|
|
412
|
+
function awaitSite(call, fn, mode, target, arm = "") {
|
|
413
|
+
if (typeof mode !== "object") return `${target}=${call}\n${awaitGuard(fn, mode, target, arm)}`;
|
|
414
|
+
const k = mode.n++;
|
|
415
|
+
mode.sites.push(`${mode.e ? "e:" : ""}${target}=${call}`);
|
|
416
|
+
return mode.async ? `${target}=_rk===${k}?_y:${call}\nif(_rk===${k}||typeof ${target}?.then==='function'){${arm ? `;${arm}\n` : ""}${target}=await ${target}}\n` : `${target}=${call}\nif(typeof ${target}?.then==='function')return _t(c,${k},${target},${mode.r ? "_r" : "undefined"},${mode.e ? "e" : "undefined"}${mode.live})\n`;
|
|
394
417
|
}
|
|
395
418
|
const tailStage = (mode, guard) => `if(_rk<=${mode.n}${guard ? `&&(_rk===${mode.n}||${guard})` : ""}){\n`;
|
|
396
419
|
const tailPlain = (mode, code) => !code || !asyncTail(mode) ? code : mode.n ? `if(_rk<${mode.n}){\n${code}}\n` : "";
|
|
397
|
-
function awaitGuard(fn,
|
|
398
|
-
if (!
|
|
420
|
+
function awaitGuard(fn, mode, target, arm = "") {
|
|
421
|
+
if (!mode) return "";
|
|
399
422
|
const code = `${arm ? `;${arm}\n` : ""}${target}=await ${target}\n`;
|
|
400
423
|
return isAsyncFunction(fn) ? code : `if(typeof ${target}?.then==='function'){${code}}\n`;
|
|
401
424
|
}
|
|
402
425
|
|
|
403
426
|
//#endregion
|
|
404
|
-
export { armEntryAbort, asyncTail, awaitGuard, awaitSite, cloneResponse, cloneStaticValue, deriveModes, getQueryParseChannels, hasRequestBody, mapAfterResponse, mapBeforeHandle, mapChainHook, mapError, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync, tailPlain, tailStage };
|
|
427
|
+
export { armEntryAbort, asyncTail, awaitGuard, awaitSite, cloneResponse, cloneStaticValue, deriveModes, getQueryParseChannels, hasRequestBody, joinDeriveEntries, mapAfterResponse, mapBeforeHandle, mapChainHook, mapError, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync, tailPlain, tailStage };
|
package/dist/compile/lexer.js
CHANGED
|
@@ -61,7 +61,7 @@ const prefixKeywords = new Set([
|
|
|
61
61
|
const isSpace = (char) => char === 32 || char >= 9 && char <= 13 || char >= 128 && /\s/.test(String.fromCharCode(char));
|
|
62
62
|
const isIdentifierStart = (char) => char >= 65 && char <= 90 || char >= 97 && char <= 122 || char === 36 || char === 95 || char >= 128 && !isSpace(char);
|
|
63
63
|
const isIdentifierPart = (char) => isIdentifierStart(char) || char >= 48 && char <= 57;
|
|
64
|
-
function
|
|
64
|
+
function opensControlHeader(tokens) {
|
|
65
65
|
let keyword = tokens.length - 1;
|
|
66
66
|
if (keyword > 0 && tokens[keyword].value === "await" && tokens[keyword - 1].value === "for") keyword--;
|
|
67
67
|
if (keyword < 0) return false;
|
|
@@ -75,7 +75,7 @@ function scanTokens(source) {
|
|
|
75
75
|
const tokens = [];
|
|
76
76
|
let index = 0;
|
|
77
77
|
let canEndExpression = false;
|
|
78
|
-
const
|
|
78
|
+
const headerParens = [];
|
|
79
79
|
const skipUnicodeEscape = () => {
|
|
80
80
|
index += 2;
|
|
81
81
|
if (source.charCodeAt(index) === 123) {
|
|
@@ -296,14 +296,14 @@ function scanTokens(source) {
|
|
|
296
296
|
const triple = source.slice(index, index + 3);
|
|
297
297
|
if (triple === "...") value = triple;
|
|
298
298
|
else if (pair === "?." || pair === "=>" || pair === "++" || pair === "--") value = pair;
|
|
299
|
-
if (value === "(")
|
|
299
|
+
if (value === "(") headerParens.push(opensControlHeader(tokens));
|
|
300
300
|
tokens.push({
|
|
301
301
|
k: "p",
|
|
302
302
|
value,
|
|
303
303
|
at: index
|
|
304
304
|
});
|
|
305
305
|
index += value.length;
|
|
306
|
-
if (value !== "++" && value !== "--") canEndExpression = value === ")" && !
|
|
306
|
+
if (value !== "++" && value !== "--") canEndExpression = value === ")" && !headerParens.pop() || value === "]" || value === "}";
|
|
307
307
|
}
|
|
308
308
|
return !templateExpression;
|
|
309
309
|
};
|
package/dist/compile/lexer.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
1
2
|
//#region src/compile/lexer.ts
|
|
2
3
|
function skipString(src, start) {
|
|
3
4
|
const quote = src[start];
|
|
@@ -59,7 +60,7 @@ const prefixKeywords = new Set([
|
|
|
59
60
|
const isSpace = (char) => char === 32 || char >= 9 && char <= 13 || char >= 128 && /\s/.test(String.fromCharCode(char));
|
|
60
61
|
const isIdentifierStart = (char) => char >= 65 && char <= 90 || char >= 97 && char <= 122 || char === 36 || char === 95 || char >= 128 && !isSpace(char);
|
|
61
62
|
const isIdentifierPart = (char) => isIdentifierStart(char) || char >= 48 && char <= 57;
|
|
62
|
-
function
|
|
63
|
+
function opensControlHeader(tokens) {
|
|
63
64
|
let keyword = tokens.length - 1;
|
|
64
65
|
if (keyword > 0 && tokens[keyword].value === "await" && tokens[keyword - 1].value === "for") keyword--;
|
|
65
66
|
if (keyword < 0) return false;
|
|
@@ -73,7 +74,7 @@ function scanTokens(source) {
|
|
|
73
74
|
const tokens = [];
|
|
74
75
|
let index = 0;
|
|
75
76
|
let canEndExpression = false;
|
|
76
|
-
const
|
|
77
|
+
const headerParens = [];
|
|
77
78
|
const skipUnicodeEscape = () => {
|
|
78
79
|
index += 2;
|
|
79
80
|
if (source.charCodeAt(index) === 123) {
|
|
@@ -294,14 +295,14 @@ function scanTokens(source) {
|
|
|
294
295
|
const triple = source.slice(index, index + 3);
|
|
295
296
|
if (triple === "...") value = triple;
|
|
296
297
|
else if (pair === "?." || pair === "=>" || pair === "++" || pair === "--") value = pair;
|
|
297
|
-
if (value === "(")
|
|
298
|
+
if (value === "(") headerParens.push(opensControlHeader(tokens));
|
|
298
299
|
tokens.push({
|
|
299
300
|
k: "p",
|
|
300
301
|
value,
|
|
301
302
|
at: index
|
|
302
303
|
});
|
|
303
304
|
index += value.length;
|
|
304
|
-
if (value !== "++" && value !== "--") canEndExpression = value === ")" && !
|
|
305
|
+
if (value !== "++" && value !== "--") canEndExpression = value === ")" && !headerParens.pop() || value === "]" || value === "}";
|
|
305
306
|
}
|
|
306
307
|
return !templateExpression;
|
|
307
308
|
};
|