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.
Files changed (217) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +1 -0
  2. package/dist/adapter/bun/index.d.ts +6 -8
  3. package/dist/adapter/bun/index.js +6 -8
  4. package/dist/adapter/bun/index.mjs +7 -8
  5. package/dist/adapter/constants.mjs +1 -0
  6. package/dist/adapter/default-headers.mjs +1 -0
  7. package/dist/adapter/index.mjs +1 -0
  8. package/dist/adapter/origin.mjs +1 -0
  9. package/dist/adapter/response-ownership.mjs +1 -0
  10. package/dist/adapter/skip-clone.mjs +1 -0
  11. package/dist/adapter/types.mjs +1 -0
  12. package/dist/adapter/utils.d.ts +5 -8
  13. package/dist/adapter/utils.js +24 -18
  14. package/dist/adapter/utils.mjs +25 -18
  15. package/dist/adapter/web-standard/handler.mjs +2 -1
  16. package/dist/adapter/web-standard/index.mjs +1 -0
  17. package/dist/adapter/web-standard/utils.mjs +1 -0
  18. package/dist/base.d.ts +118 -69
  19. package/dist/base.js +214 -194
  20. package/dist/base.mjs +221 -200
  21. package/dist/compile/aot-capture.js +2 -2
  22. package/dist/compile/aot-capture.mjs +4 -3
  23. package/dist/compile/aot-emit.js +7 -8
  24. package/dist/compile/aot-emit.mjs +8 -8
  25. package/dist/compile/aot-reconstruct.mjs +3 -2
  26. package/dist/compile/aot.d.ts +3 -3
  27. package/dist/compile/aot.js +5 -5
  28. package/dist/compile/aot.mjs +6 -5
  29. package/dist/compile/handler/descriptor.d.ts +2 -5
  30. package/dist/compile/handler/descriptor.js +12 -17
  31. package/dist/compile/handler/descriptor.mjs +16 -21
  32. package/dist/compile/handler/frozen-validator.d.ts +2 -2
  33. package/dist/compile/handler/frozen-validator.js +3 -3
  34. package/dist/compile/handler/frozen-validator.mjs +4 -3
  35. package/dist/compile/handler/index.d.ts +3 -1
  36. package/dist/compile/handler/index.js +78 -118
  37. package/dist/compile/handler/index.mjs +84 -125
  38. package/dist/compile/handler/jit.d.ts +12 -12
  39. package/dist/compile/handler/jit.js +60 -43
  40. package/dist/compile/handler/jit.mjs +63 -47
  41. package/dist/compile/handler/params.d.ts +5 -1
  42. package/dist/compile/handler/params.js +14 -5
  43. package/dist/compile/handler/params.mjs +16 -7
  44. package/dist/compile/handler/reconstruct.d.ts +2 -2
  45. package/dist/compile/handler/reconstruct.js +2 -2
  46. package/dist/compile/handler/reconstruct.mjs +3 -2
  47. package/dist/compile/handler/static-clone-resolver.mjs +1 -0
  48. package/dist/compile/handler/utils.d.ts +13 -7
  49. package/dist/compile/handler/utils.js +75 -52
  50. package/dist/compile/handler/utils.mjs +77 -54
  51. package/dist/compile/jit-probe.mjs +1 -0
  52. package/dist/compile/lexer.js +4 -4
  53. package/dist/compile/lexer.mjs +5 -4
  54. package/dist/compile/utils.d.ts +2 -1
  55. package/dist/compile/utils.js +8 -3
  56. package/dist/compile/utils.mjs +8 -3
  57. package/dist/compiled.mjs +1 -0
  58. package/dist/constants.mjs +1 -0
  59. package/dist/context.d.ts +1 -1
  60. package/dist/context.js +1 -0
  61. package/dist/context.mjs +3 -1
  62. package/dist/cookie/config.d.ts +2 -2
  63. package/dist/cookie/config.js +21 -26
  64. package/dist/cookie/config.mjs +22 -26
  65. package/dist/cookie/cookie.mjs +1 -0
  66. package/dist/cookie/crypto.mjs +1 -0
  67. package/dist/cookie/error.mjs +1 -0
  68. package/dist/cookie/lib.mjs +1 -0
  69. package/dist/cookie/serialize.mjs +1 -0
  70. package/dist/cookie/types.mjs +1 -0
  71. package/dist/cookie/utils.d.ts +1 -1
  72. package/dist/cookie/utils.js +64 -45
  73. package/dist/cookie/utils.mjs +66 -46
  74. package/dist/error.d.ts +10 -6
  75. package/dist/error.js +22 -6
  76. package/dist/error.mjs +25 -9
  77. package/dist/generation.mjs +1 -0
  78. package/dist/handler/error.d.ts +12 -15
  79. package/dist/handler/error.js +43 -40
  80. package/dist/handler/error.mjs +45 -41
  81. package/dist/handler/fetch.js +59 -21
  82. package/dist/handler/fetch.mjs +61 -22
  83. package/dist/handler/utils.d.ts +16 -3
  84. package/dist/handler/utils.js +14 -13
  85. package/dist/handler/utils.mjs +16 -15
  86. package/dist/index.d.ts +9 -9
  87. package/dist/index.js +1 -0
  88. package/dist/index.mjs +3 -2
  89. package/dist/memory.mjs +1 -0
  90. package/dist/package.js +1 -1
  91. package/dist/package.mjs +2 -1
  92. package/dist/parse-query.js +76 -76
  93. package/dist/parse-query.mjs +77 -76
  94. package/dist/plugin/aot/bun.mjs +1 -0
  95. package/dist/plugin/aot/core.d.ts +1 -1
  96. package/dist/plugin/aot/core.js +7 -4
  97. package/dist/plugin/aot/core.mjs +8 -5
  98. package/dist/plugin/aot/esbuild.mjs +1 -0
  99. package/dist/plugin/aot/rspack-loader.mjs +1 -0
  100. package/dist/plugin/aot/rspack.mjs +1 -0
  101. package/dist/plugin/aot/treeshake.mjs +1 -0
  102. package/dist/plugin/aot/unplugin.mjs +4 -3
  103. package/dist/plugin/aot/vite.mjs +1 -0
  104. package/dist/plugin/aot/worker.mjs +1 -0
  105. package/dist/plugin/auto-head.mjs +1 -0
  106. package/dist/plugin/trace.mjs +1 -0
  107. package/dist/plugin/websocket.mjs +1 -0
  108. package/dist/route-table.mjs +1 -0
  109. package/dist/schema-snapshot.js +28 -3
  110. package/dist/schema-snapshot.mjs +29 -3
  111. package/dist/sucrose.d.ts +2 -2
  112. package/dist/sucrose.js +11 -11
  113. package/dist/sucrose.mjs +12 -11
  114. package/dist/trace.js +8 -10
  115. package/dist/trace.mjs +10 -11
  116. package/dist/type/bridge-live.d.ts +1 -1
  117. package/dist/type/bridge-live.mjs +1 -0
  118. package/dist/type/bridge.d.ts +1 -1
  119. package/dist/type/bridge.mjs +1 -0
  120. package/dist/type/coerce-plan.mjs +1 -0
  121. package/dist/type/coerce.d.ts +1 -1
  122. package/dist/type/coerce.mjs +1 -0
  123. package/dist/type/compat.mjs +1 -0
  124. package/dist/type/constants.d.ts +1 -1
  125. package/dist/type/constants.mjs +1 -0
  126. package/dist/type/elysia/accelerate.mjs +1 -0
  127. package/dist/type/elysia/array-buffer.d.ts +3 -2
  128. package/dist/type/elysia/array-buffer.js +5 -5
  129. package/dist/type/elysia/array-buffer.mjs +6 -5
  130. package/dist/type/elysia/array-string.mjs +1 -0
  131. package/dist/type/elysia/array.mjs +1 -0
  132. package/dist/type/elysia/boolean-string.mjs +1 -0
  133. package/dist/type/elysia/boolean.mjs +1 -0
  134. package/dist/type/elysia/cookie.mjs +1 -0
  135. package/dist/type/elysia/date.mjs +1 -0
  136. package/dist/type/elysia/file-type.mjs +1 -0
  137. package/dist/type/elysia/file.mjs +1 -0
  138. package/dist/type/elysia/files.mjs +1 -0
  139. package/dist/type/elysia/form.mjs +1 -0
  140. package/dist/type/elysia/integer-string.mjs +1 -0
  141. package/dist/type/elysia/integer.mjs +1 -0
  142. package/dist/type/elysia/intersect.mjs +1 -0
  143. package/dist/type/elysia/json-string.mjs +1 -0
  144. package/dist/type/elysia/keep-config.js +8 -8
  145. package/dist/type/elysia/keep-config.mjs +9 -8
  146. package/dist/type/elysia/maybe-empty.mjs +1 -0
  147. package/dist/type/elysia/no-validate.mjs +1 -0
  148. package/dist/type/elysia/nullable.mjs +1 -0
  149. package/dist/type/elysia/number.mjs +1 -0
  150. package/dist/type/elysia/numeric-enum.d.ts +4 -2
  151. package/dist/type/elysia/numeric-enum.mjs +1 -0
  152. package/dist/type/elysia/numeric.mjs +1 -0
  153. package/dist/type/elysia/object-string.mjs +1 -0
  154. package/dist/type/elysia/object.mjs +1 -0
  155. package/dist/type/elysia/optional.mjs +1 -0
  156. package/dist/type/elysia/problem.mjs +1 -0
  157. package/dist/type/elysia/string.mjs +1 -0
  158. package/dist/type/elysia/uint8-array.d.ts +2 -1
  159. package/dist/type/elysia/uint8-array.js +2 -2
  160. package/dist/type/elysia/uint8-array.mjs +3 -2
  161. package/dist/type/elysia/union-enum.mjs +1 -0
  162. package/dist/type/elysia/union.mjs +1 -0
  163. package/dist/type/elysia/utils.js +3 -3
  164. package/dist/type/elysia/utils.mjs +4 -3
  165. package/dist/type/exports.mjs +1 -0
  166. package/dist/type/index.mjs +2 -1
  167. package/dist/type/shared.mjs +1 -0
  168. package/dist/type/sync-require.mjs +1 -0
  169. package/dist/type/typebox-system-lite.mjs +1 -0
  170. package/dist/type/typebox-system-require.mjs +1 -0
  171. package/dist/type/typebox-type-live.mjs +1 -0
  172. package/dist/type/typebox-value-live.mjs +1 -0
  173. package/dist/type/typebox-value-ops.mjs +1 -0
  174. package/dist/type/typebox-value.mjs +1 -0
  175. package/dist/type/types.d.ts +1 -1
  176. package/dist/type/types.mjs +1 -0
  177. package/dist/type/utils.mjs +1 -0
  178. package/dist/type/validator/clean-safe.mjs +1 -0
  179. package/dist/type/validator/custom-error.js +41 -33
  180. package/dist/type/validator/custom-error.mjs +42 -33
  181. package/dist/type/validator/default-precompute.d.ts +2 -2
  182. package/dist/type/validator/default-precompute.js +10 -11
  183. package/dist/type/validator/default-precompute.mjs +13 -13
  184. package/dist/type/validator/exact-mirror.mjs +1 -0
  185. package/dist/type/validator/frozen-check.js +7 -7
  186. package/dist/type/validator/frozen-check.mjs +8 -7
  187. package/dist/type/validator/index.d.ts +2 -2
  188. package/dist/type/validator/index.js +4 -8
  189. package/dist/type/validator/index.mjs +5 -8
  190. package/dist/type/validator/string-codec-aot.d.ts +1 -1
  191. package/dist/type/validator/string-codec-aot.mjs +1 -0
  192. package/dist/type/validator/validator-cache.js +18 -18
  193. package/dist/type/validator/validator-cache.mjs +19 -18
  194. package/dist/types.d.ts +108 -70
  195. package/dist/types.mjs +1 -0
  196. package/dist/universal/constants.mjs +1 -0
  197. package/dist/universal/file.mjs +1 -0
  198. package/dist/universal/index.mjs +1 -0
  199. package/dist/universal/is-production.mjs +1 -0
  200. package/dist/universal/server.mjs +1 -0
  201. package/dist/utils.d.ts +49 -31
  202. package/dist/utils.js +221 -109
  203. package/dist/utils.mjs +215 -106
  204. package/dist/validator/index.d.ts +3 -3
  205. package/dist/validator/index.js +4 -4
  206. package/dist/validator/index.mjs +5 -4
  207. package/dist/validator/route.d.ts +2 -2
  208. package/dist/validator/route.mjs +1 -0
  209. package/dist/ws/context.js +1 -1
  210. package/dist/ws/context.mjs +2 -1
  211. package/dist/ws/index.mjs +1 -0
  212. package/dist/ws/parser.mjs +1 -0
  213. package/dist/ws/route.js +34 -25
  214. package/dist/ws/route.mjs +40 -30
  215. package/dist/ws/types.d.ts +2 -3
  216. package/dist/ws/types.mjs +1 -0
  217. 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 Reconstrct = class {
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.Reconstrct = Reconstrct;
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 Reconstrct = class {
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 { Reconstrct };
52
+ export { Reconstruct };
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { cloneStaticValue } from "./utils.mjs";
2
3
 
3
4
  //#region src/compile/handler/static-clone-resolver.ts
@@ -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?: [isAsync: AsyncMode, report?: TraceReporter | undefined, arm?: string | undefined] | undefined, abortGuard?: string, tail?: TailMode) => string;
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
- declare function mapBeforeHandle(_hooks: AppHook['beforeHandle'] | AppHook['beforeHandle'][0], derive: readonly DeriveEntry[] | undefined, link: Link, isAsync: AsyncMode, report?: TraceReporter, abortGuard?: string, arm?: string): string;
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, isAsync: AsyncMode, report?: TraceReporter, abortGuard?: string, arm?: string): 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, isAsync: AsyncMode, arm?: string | undefined] | undefined, abortGuard?: string, tail?: TailMode) => 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, isAsync: AsyncMode, target: string, arm?: string): string;
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, isAsync: AsyncMode, target: string, arm?: string): string;
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 trace = (report, fn) => report?.resolveChild(fn?.name && typeof fn.name === "string" ? fn.name : "anonymous") ?? noTrace;
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, [isAsync, report, arm]) => {
58
- const t = trace(report, fn);
59
- const call = isAsync ? awaitSite(`tf${at(i)}(c)`, fn, isAsync, "_tf", arm) : `tf${at(i)}(c)\n`;
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 is = (i, value) => tokens[i]?.k === "p" && tokens[i].value === value;
80
- const blank = (i) => {
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 (!blank(i)) return null;
96
- if (is(i + 1, "(")) {
97
- if (!blank(i + 1) || !is(i + 2, "{")) return null;
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 (!is(i + 1, "{")) return null;
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 (; blank(at) && is(at + 1, "("); at++) parens++;
116
- if (!blank(at) || !is(at + 1, "{")) return null;
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 (!is(i, "}")) {
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)) || !blank(i) || !is(i + 1, ":")) return null;
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 (is(i, ",")) i++;
139
+ if (isPunct(i, ",")) i++;
140
140
  }
141
- for (; parens; parens--) if (!is(++i, ")")) return null;
142
- return i + 1 === tokens.length || is(i + 1, ";") || is(i + 1, "}") ? keys : null;
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
- let queues;
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 fn = hooks[i];
188
- const queue = queues.get(fn);
189
- if (!queue?.length) continue;
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
- function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard, arm) {
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(isAsync);
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 = trace(report, fn);
232
+ const t = traceChild(report, fn);
211
233
  code += t.begin;
212
- code += awaitSite(`bf${at(i)}(c)`, fn, isAsync, "tmp", arm);
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, isAsync, report, abortGuard, arm) {
290
+ function mapChainHook(_hooks, prefix, mode, report, abortGuard, arm) {
269
291
  const hooks = toArray(_hooks);
270
- const tail = asyncTail(isAsync);
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 = trace(report, fn);
303
+ const t = traceChild(report, fn);
282
304
  code += t.begin;
283
- code += awaitSite(`${prefix}${at(i)}(c)`, fn, isAsync, "tmp", arm);
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(isAsync, `if(tmp!==undefined)_r=c.responseValue=tmp\n`);
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 = trace(report, fn);
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, isAsync, arm]) => {
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, isAsync, "_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`;
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, isAsync, target, arm = "") {
391
- if (typeof isAsync !== "object") return `${target}=${call}\n${awaitGuard(fn, isAsync, target, arm)}`;
392
- const k = isAsync.n++;
393
- isAsync.sites.push(`${isAsync.e ? "e:" : ""}${target}=${call}`);
394
- return isAsync.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},${isAsync.r ? "_r" : "undefined"},${isAsync.e ? "e" : "undefined"}${isAsync.live})\n`;
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, isAsync, target, arm = "") {
399
- if (!isAsync) return "";
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 trace = (report, fn) => report?.resolveChild(fn?.name && typeof fn.name === "string" ? fn.name : "anonymous") ?? noTrace;
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, [isAsync, report, arm]) => {
57
- const t = trace(report, fn);
58
- const call = isAsync ? awaitSite(`tf${at(i)}(c)`, fn, isAsync, "_tf", arm) : `tf${at(i)}(c)\n`;
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 is = (i, value) => tokens[i]?.k === "p" && tokens[i].value === value;
79
- const blank = (i) => {
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 (!blank(i)) return null;
95
- if (is(i + 1, "(")) {
96
- if (!blank(i + 1) || !is(i + 2, "{")) return null;
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 (!is(i + 1, "{")) return null;
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 (; blank(at) && is(at + 1, "("); at++) parens++;
115
- if (!blank(at) || !is(at + 1, "{")) return null;
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 (!is(i, "}")) {
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)) || !blank(i) || !is(i + 1, ":")) return null;
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 (is(i, ",")) i++;
139
+ if (isPunct(i, ",")) i++;
139
140
  }
140
- for (; parens; parens--) if (!is(++i, ")")) return null;
141
- return i + 1 === tokens.length || is(i + 1, ";") || is(i + 1, "}") ? keys : null;
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
- let queues;
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 fn = hooks[i];
187
- const queue = queues.get(fn);
188
- if (!queue?.length) continue;
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
- function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard, arm) {
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(isAsync);
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 = trace(report, fn);
232
+ const t = traceChild(report, fn);
210
233
  code += t.begin;
211
- code += awaitSite(`bf${at(i)}(c)`, fn, isAsync, "tmp", arm);
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, isAsync, report, abortGuard, arm) {
290
+ function mapChainHook(_hooks, prefix, mode, report, abortGuard, arm) {
268
291
  const hooks = toArray(_hooks);
269
- const tail = asyncTail(isAsync);
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 = trace(report, fn);
303
+ const t = traceChild(report, fn);
281
304
  code += t.begin;
282
- code += awaitSite(`${prefix}${at(i)}(c)`, fn, isAsync, "tmp", arm);
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(isAsync, `if(tmp!==undefined)_r=c.responseValue=tmp\n`);
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 = trace(report, fn);
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, isAsync, arm]) => {
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, isAsync, "_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`;
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, isAsync, target, arm = "") {
390
- if (typeof isAsync !== "object") return `${target}=${call}\n${awaitGuard(fn, isAsync, target, arm)}`;
391
- const k = isAsync.n++;
392
- isAsync.sites.push(`${isAsync.e ? "e:" : ""}${target}=${call}`);
393
- return isAsync.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},${isAsync.r ? "_r" : "undefined"},${isAsync.e ? "e" : "undefined"}${isAsync.live})\n`;
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, isAsync, target, arm = "") {
398
- if (!isAsync) return "";
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 };
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  //#region src/compile/jit-probe.ts
2
3
  let armed = false;
3
4
  const reasons = /* @__PURE__ */ new Set();
@@ -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 isHeader(tokens) {
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 headers = [];
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 === "(") headers.push(isHeader(tokens));
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 === ")" && !headers.pop() || value === "]" || value === "}";
306
+ if (value !== "++" && value !== "--") canEndExpression = value === ")" && !headerParens.pop() || value === "]" || value === "}";
307
307
  }
308
308
  return !templateExpression;
309
309
  };
@@ -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 isHeader(tokens) {
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 headers = [];
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 === "(") headers.push(isHeader(tokens));
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 === ")" && !headers.pop() || value === "]" || value === "}";
305
+ if (value !== "++" && value !== "--") canEndExpression = value === ")" && !headerParens.pop() || value === "]" || value === "}";
305
306
  }
306
307
  return !templateExpression;
307
308
  };