elysia 2.0.0-beta.2 → 2.0.0-beta.21

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 (339) hide show
  1. package/dist/adapter/bun/index.d.ts +18 -2
  2. package/dist/adapter/bun/index.js +467 -110
  3. package/dist/adapter/bun/index.mjs +467 -112
  4. package/dist/adapter/types.d.ts +2 -21
  5. package/dist/adapter/utils.d.ts +14 -3
  6. package/dist/adapter/utils.js +146 -87
  7. package/dist/adapter/utils.mjs +148 -90
  8. package/dist/adapter/web-standard/handler.d.ts +1 -1
  9. package/dist/adapter/web-standard/handler.js +47 -36
  10. package/dist/adapter/web-standard/handler.mjs +48 -37
  11. package/dist/adapter/web-standard/index.js +2 -30
  12. package/dist/adapter/web-standard/index.mjs +2 -30
  13. package/dist/adapter/web-standard/utils.js +5 -18
  14. package/dist/adapter/web-standard/utils.mjs +5 -18
  15. package/dist/base.d.ts +99 -67
  16. package/dist/base.js +678 -510
  17. package/dist/base.mjs +682 -514
  18. package/dist/compile/aot-capture.d.ts +2 -13
  19. package/dist/compile/aot-capture.js +26 -69
  20. package/dist/compile/aot-capture.mjs +28 -67
  21. package/dist/compile/aot-emit.d.ts +9 -7
  22. package/dist/compile/aot-emit.js +42 -19
  23. package/dist/compile/aot-emit.mjs +42 -20
  24. package/dist/compile/aot.d.ts +17 -19
  25. package/dist/compile/aot.js +41 -51
  26. package/dist/compile/aot.mjs +39 -49
  27. package/dist/compile/handler/descriptor.d.ts +9 -12
  28. package/dist/compile/handler/descriptor.js +19 -44
  29. package/dist/compile/handler/descriptor.mjs +20 -42
  30. package/dist/compile/handler/frozen-validator.d.ts +5 -10
  31. package/dist/compile/handler/frozen-validator.js +55 -105
  32. package/dist/compile/handler/frozen-validator.mjs +53 -105
  33. package/dist/compile/handler/index.d.ts +7 -5
  34. package/dist/compile/handler/index.js +270 -111
  35. package/dist/compile/handler/index.mjs +270 -113
  36. package/dist/compile/handler/jit.d.ts +19 -17
  37. package/dist/compile/handler/jit.js +222 -149
  38. package/dist/compile/handler/jit.mjs +224 -152
  39. package/dist/compile/handler/params.d.ts +1 -4
  40. package/dist/compile/handler/params.js +10 -5
  41. package/dist/compile/handler/params.mjs +14 -8
  42. package/dist/compile/handler/reconstruct.d.ts +2 -2
  43. package/dist/compile/handler/reconstruct.js +6 -4
  44. package/dist/compile/handler/reconstruct.mjs +6 -4
  45. package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
  46. package/dist/compile/handler/static-clone-resolver.js +8 -0
  47. package/dist/compile/handler/static-clone-resolver.mjs +7 -0
  48. package/dist/compile/handler/utils.d.ts +22 -11
  49. package/dist/compile/handler/utils.js +159 -253
  50. package/dist/compile/handler/utils.mjs +155 -252
  51. package/dist/compile/jit-probe.d.ts +2 -2
  52. package/dist/compile/jit-probe.js +2 -3
  53. package/dist/compile/jit-probe.mjs +2 -3
  54. package/dist/compile/lexer.d.ts +7 -4
  55. package/dist/compile/lexer.js +268 -6
  56. package/dist/compile/lexer.mjs +268 -4
  57. package/dist/compile/utils.js +7 -4
  58. package/dist/compile/utils.mjs +7 -4
  59. package/dist/compiled.d.ts +0 -1
  60. package/dist/compiled.js +0 -1
  61. package/dist/compiled.mjs +0 -1
  62. package/dist/context.d.ts +14 -4
  63. package/dist/context.js +17 -32
  64. package/dist/context.mjs +19 -34
  65. package/dist/cookie/config.d.ts +7 -2
  66. package/dist/cookie/config.js +76 -16
  67. package/dist/cookie/config.mjs +77 -18
  68. package/dist/cookie/cookie.d.ts +1 -1
  69. package/dist/cookie/cookie.js +8 -10
  70. package/dist/cookie/cookie.mjs +8 -10
  71. package/dist/cookie/crypto.d.ts +8 -7
  72. package/dist/cookie/crypto.js +51 -40
  73. package/dist/cookie/crypto.mjs +51 -41
  74. package/dist/cookie/error.d.ts +1 -2
  75. package/dist/cookie/error.js +6 -4
  76. package/dist/cookie/error.mjs +6 -4
  77. package/dist/cookie/lib.js +7 -2
  78. package/dist/cookie/lib.mjs +7 -2
  79. package/dist/cookie/serialize.js +1 -1
  80. package/dist/cookie/serialize.mjs +1 -1
  81. package/dist/cookie/types.d.ts +10 -0
  82. package/dist/cookie/utils.d.ts +4 -8
  83. package/dist/cookie/utils.js +86 -52
  84. package/dist/cookie/utils.mjs +89 -54
  85. package/dist/error.d.ts +113 -103
  86. package/dist/error.js +181 -117
  87. package/dist/error.mjs +179 -118
  88. package/dist/generation.d.ts +2 -2
  89. package/dist/handler/error.d.ts +26 -15
  90. package/dist/handler/error.js +77 -96
  91. package/dist/handler/error.mjs +74 -97
  92. package/dist/handler/fetch.js +87 -108
  93. package/dist/handler/fetch.mjs +89 -110
  94. package/dist/handler/utils.d.ts +12 -6
  95. package/dist/handler/utils.js +84 -28
  96. package/dist/handler/utils.mjs +80 -28
  97. package/dist/index.d.ts +12 -12
  98. package/dist/index.js +2 -9
  99. package/dist/index.mjs +1 -1
  100. package/dist/memory.js +1 -1
  101. package/dist/memory.mjs +1 -1
  102. package/dist/package.js +1 -1
  103. package/dist/package.mjs +1 -1
  104. package/dist/plugin/aot/bun.d.ts +8 -1
  105. package/dist/plugin/aot/bun.js +16 -9
  106. package/dist/plugin/aot/bun.mjs +17 -10
  107. package/dist/plugin/aot/core.d.ts +52 -60
  108. package/dist/plugin/aot/core.js +208 -109
  109. package/dist/plugin/aot/core.mjs +205 -111
  110. package/dist/plugin/aot/esbuild.js +8 -5
  111. package/dist/plugin/aot/esbuild.mjs +9 -6
  112. package/dist/plugin/aot/hooks.d.ts +6 -17
  113. package/dist/plugin/aot/hooks.js +36 -14
  114. package/dist/plugin/aot/hooks.mjs +37 -16
  115. package/dist/plugin/aot/rspack-loader.d.ts +1 -5
  116. package/dist/plugin/aot/rspack-loader.js +1 -10
  117. package/dist/plugin/aot/rspack-loader.mjs +1 -10
  118. package/dist/plugin/aot/rspack.js +2 -5
  119. package/dist/plugin/aot/rspack.mjs +3 -6
  120. package/dist/plugin/aot/source.d.ts +6 -42
  121. package/dist/plugin/aot/source.js +71 -71
  122. package/dist/plugin/aot/source.mjs +72 -72
  123. package/dist/plugin/aot/treeshake.js +2 -6
  124. package/dist/plugin/aot/treeshake.mjs +2 -6
  125. package/dist/plugin/aot/unplugin.d.ts +1 -4
  126. package/dist/plugin/aot/unplugin.js +4 -13
  127. package/dist/plugin/aot/unplugin.mjs +4 -13
  128. package/dist/plugin/aot/vite.d.ts +2 -6
  129. package/dist/plugin/aot/worker.js +2 -2
  130. package/dist/plugin/aot/worker.mjs +2 -2
  131. package/dist/plugin/auto-head.js +1 -10
  132. package/dist/plugin/auto-head.mjs +1 -10
  133. package/dist/plugin/trace.d.ts +2 -1
  134. package/dist/route-table.d.ts +3 -0
  135. package/dist/route-table.js +16 -11
  136. package/dist/route-table.mjs +16 -11
  137. package/dist/schema-snapshot.d.ts +0 -4
  138. package/dist/schema-snapshot.js +32 -49
  139. package/dist/schema-snapshot.mjs +32 -49
  140. package/dist/sucrose.d.ts +6 -55
  141. package/dist/sucrose.js +103 -731
  142. package/dist/sucrose.mjs +102 -724
  143. package/dist/trace.d.ts +5 -8
  144. package/dist/trace.js +23 -134
  145. package/dist/trace.mjs +24 -135
  146. package/dist/type/bridge-live.d.ts +4 -2
  147. package/dist/type/bridge-live.js +6 -3
  148. package/dist/type/bridge-live.mjs +4 -2
  149. package/dist/type/bridge.d.ts +6 -4
  150. package/dist/type/bridge.js +17 -9
  151. package/dist/type/bridge.mjs +5 -3
  152. package/dist/type/coerce-plan.d.ts +5 -5
  153. package/dist/type/coerce-plan.js +41 -39
  154. package/dist/type/coerce-plan.mjs +43 -39
  155. package/dist/type/coerce.d.ts +3 -7
  156. package/dist/type/coerce.js +18 -75
  157. package/dist/type/coerce.mjs +19 -76
  158. package/dist/type/compat.d.ts +3 -0
  159. package/dist/type/compat.js +23 -14
  160. package/dist/type/compat.mjs +20 -10
  161. package/dist/type/elysia/array-buffer.d.ts +4 -1
  162. package/dist/type/elysia/array-buffer.js +17 -17
  163. package/dist/type/elysia/array-buffer.mjs +17 -17
  164. package/dist/type/elysia/array-string.js +2 -40
  165. package/dist/type/elysia/array-string.mjs +2 -39
  166. package/dist/type/elysia/array.js +5 -9
  167. package/dist/type/elysia/array.mjs +5 -9
  168. package/dist/type/elysia/boolean-string.js +2 -3
  169. package/dist/type/elysia/boolean-string.mjs +1 -1
  170. package/dist/type/elysia/boolean.js +3 -12
  171. package/dist/type/elysia/boolean.mjs +3 -11
  172. package/dist/type/elysia/cookie.d.ts +3 -4
  173. package/dist/type/elysia/cookie.js +5 -15
  174. package/dist/type/elysia/cookie.mjs +5 -15
  175. package/dist/type/elysia/date.js +13 -20
  176. package/dist/type/elysia/date.mjs +10 -16
  177. package/dist/type/elysia/file-type.d.ts +11 -4
  178. package/dist/type/elysia/file-type.js +17 -2
  179. package/dist/type/elysia/file-type.mjs +17 -3
  180. package/dist/type/elysia/file.d.ts +1 -3
  181. package/dist/type/elysia/file.js +11 -27
  182. package/dist/type/elysia/file.mjs +11 -12
  183. package/dist/type/elysia/files.js +7 -11
  184. package/dist/type/elysia/files.mjs +7 -10
  185. package/dist/type/elysia/form.js +2 -3
  186. package/dist/type/elysia/form.mjs +3 -3
  187. package/dist/type/elysia/integer-string.d.ts +1 -1
  188. package/dist/type/elysia/integer-string.js +4 -30
  189. package/dist/type/elysia/integer-string.mjs +5 -30
  190. package/dist/type/elysia/integer.js +3 -12
  191. package/dist/type/elysia/integer.mjs +3 -11
  192. package/dist/type/elysia/intersect.js +0 -5
  193. package/dist/type/elysia/intersect.mjs +0 -5
  194. package/dist/type/elysia/json-string.d.ts +7 -0
  195. package/dist/type/elysia/json-string.js +47 -0
  196. package/dist/type/elysia/json-string.mjs +46 -0
  197. package/dist/type/elysia/keep-config.d.ts +14 -0
  198. package/dist/type/elysia/keep-config.js +62 -0
  199. package/dist/type/elysia/keep-config.mjs +53 -0
  200. package/dist/type/elysia/maybe-empty.js +3 -4
  201. package/dist/type/elysia/maybe-empty.mjs +1 -1
  202. package/dist/type/elysia/nullable.js +2 -3
  203. package/dist/type/elysia/nullable.mjs +1 -1
  204. package/dist/type/elysia/number.d.ts +2 -1
  205. package/dist/type/elysia/number.js +19 -11
  206. package/dist/type/elysia/number.mjs +18 -10
  207. package/dist/type/elysia/numeric-enum.d.ts +1 -1
  208. package/dist/type/elysia/numeric-enum.js +4 -5
  209. package/dist/type/elysia/numeric-enum.mjs +3 -3
  210. package/dist/type/elysia/numeric.d.ts +4 -2
  211. package/dist/type/elysia/numeric.js +20 -17
  212. package/dist/type/elysia/numeric.mjs +19 -16
  213. package/dist/type/elysia/object-string.js +2 -37
  214. package/dist/type/elysia/object-string.mjs +2 -36
  215. package/dist/type/elysia/object.js +5 -9
  216. package/dist/type/elysia/object.mjs +5 -9
  217. package/dist/type/elysia/optional.js +8 -8
  218. package/dist/type/elysia/optional.mjs +7 -7
  219. package/dist/type/elysia/problem.d.ts +20 -0
  220. package/dist/type/elysia/problem.js +25 -0
  221. package/dist/type/elysia/problem.mjs +24 -0
  222. package/dist/type/elysia/string.js +4 -3
  223. package/dist/type/elysia/string.mjs +4 -2
  224. package/dist/type/elysia/uint8-array.d.ts +1 -1
  225. package/dist/type/elysia/uint8-array.js +5 -20
  226. package/dist/type/elysia/uint8-array.mjs +5 -19
  227. package/dist/type/elysia/union-enum.js +7 -8
  228. package/dist/type/elysia/union-enum.mjs +6 -6
  229. package/dist/type/elysia/union.js +0 -5
  230. package/dist/type/elysia/union.mjs +0 -5
  231. package/dist/type/elysia/utils.d.ts +2 -4
  232. package/dist/type/elysia/utils.js +10 -21
  233. package/dist/type/elysia/utils.mjs +7 -15
  234. package/dist/type/exports.d.ts +4 -2
  235. package/dist/type/exports.js +23 -2
  236. package/dist/type/exports.mjs +11 -2
  237. package/dist/type/index.d.ts +10 -2
  238. package/dist/type/index.js +62 -15
  239. package/dist/type/index.mjs +65 -11
  240. package/dist/type/shared.d.ts +3 -9
  241. package/dist/type/shared.js +44 -97
  242. package/dist/type/shared.mjs +43 -97
  243. package/dist/type/sync-require.d.ts +11 -0
  244. package/dist/type/sync-require.js +14 -0
  245. package/dist/type/sync-require.mjs +12 -0
  246. package/dist/type/typebox-system-lite.d.ts +2 -0
  247. package/dist/type/typebox-system-lite.js +34 -0
  248. package/dist/type/typebox-system-lite.mjs +3 -0
  249. package/dist/type/typebox-system-require.d.ts +7 -0
  250. package/dist/type/typebox-system-require.js +24 -0
  251. package/dist/type/typebox-system-require.mjs +23 -0
  252. package/dist/type/typebox-type-live.d.ts +11 -0
  253. package/dist/type/typebox-type-live.js +45 -0
  254. package/dist/type/typebox-type-live.mjs +20 -0
  255. package/dist/type/typebox-type.d.ts +34 -0
  256. package/dist/type/typebox-type.js +199 -0
  257. package/dist/type/typebox-type.mjs +86 -0
  258. package/dist/type/typebox-value-live.d.ts +11 -0
  259. package/dist/type/typebox-value-live.js +31 -0
  260. package/dist/type/typebox-value-live.mjs +13 -0
  261. package/dist/type/typebox-value-ops.d.ts +4 -0
  262. package/dist/type/typebox-value-ops.js +90 -0
  263. package/dist/type/typebox-value-ops.mjs +5 -0
  264. package/dist/type/typebox-value-require.d.ts +8 -0
  265. package/dist/type/typebox-value-require.js +28 -0
  266. package/dist/type/typebox-value-require.mjs +25 -0
  267. package/dist/type/typebox-value.d.ts +35 -0
  268. package/dist/type/typebox-value.js +161 -0
  269. package/dist/type/typebox-value.mjs +74 -0
  270. package/dist/type/utils.js +1 -10
  271. package/dist/type/utils.mjs +1 -10
  272. package/dist/type/validator/clean-safe.d.ts +2 -4
  273. package/dist/type/validator/clean-safe.js +15 -11
  274. package/dist/type/validator/clean-safe.mjs +16 -10
  275. package/dist/type/validator/custom-error.js +12 -16
  276. package/dist/type/validator/custom-error.mjs +11 -14
  277. package/dist/type/validator/default-precompute.d.ts +9 -1
  278. package/dist/type/validator/default-precompute.js +40 -77
  279. package/dist/type/validator/default-precompute.mjs +37 -74
  280. package/dist/type/validator/exact-mirror-live.d.ts +8 -0
  281. package/dist/type/validator/exact-mirror-live.js +22 -0
  282. package/dist/type/validator/exact-mirror-live.mjs +17 -0
  283. package/dist/type/validator/exact-mirror-require.d.ts +4 -0
  284. package/dist/type/validator/exact-mirror-require.js +11 -0
  285. package/dist/type/validator/exact-mirror-require.mjs +9 -0
  286. package/dist/type/validator/exact-mirror.js +8 -8
  287. package/dist/type/validator/exact-mirror.mjs +9 -8
  288. package/dist/type/validator/frozen-check.js +5 -6
  289. package/dist/type/validator/frozen-check.mjs +6 -7
  290. package/dist/type/validator/index.d.ts +1 -0
  291. package/dist/type/validator/index.js +169 -166
  292. package/dist/type/validator/index.mjs +162 -158
  293. package/dist/type/validator/string-codec-aot.d.ts +2 -1
  294. package/dist/type/validator/string-codec-aot.js +8 -2
  295. package/dist/type/validator/string-codec-aot.mjs +7 -2
  296. package/dist/type/validator/validator-cache.d.ts +5 -4
  297. package/dist/type/validator/validator-cache.js +41 -24
  298. package/dist/type/validator/validator-cache.mjs +40 -22
  299. package/dist/types.d.ts +263 -95
  300. package/dist/universal/constants.d.ts +2 -1
  301. package/dist/universal/constants.js +3 -1
  302. package/dist/universal/constants.mjs +2 -1
  303. package/dist/universal/env.js +2 -3
  304. package/dist/universal/env.mjs +2 -3
  305. package/dist/universal/file.d.ts +6 -4
  306. package/dist/universal/file.js +11 -16
  307. package/dist/universal/file.mjs +12 -16
  308. package/dist/universal/index.d.ts +2 -2
  309. package/dist/universal/is-production.d.ts +1 -2
  310. package/dist/universal/is-production.js +1 -3
  311. package/dist/universal/is-production.mjs +2 -3
  312. package/dist/universal/server.d.ts +0 -272
  313. package/dist/utils.d.ts +43 -7
  314. package/dist/utils.js +181 -126
  315. package/dist/utils.mjs +168 -126
  316. package/dist/validator/index.d.ts +1 -1
  317. package/dist/validator/index.js +17 -30
  318. package/dist/validator/index.mjs +18 -31
  319. package/dist/validator/route.js +2 -1
  320. package/dist/validator/route.mjs +2 -1
  321. package/dist/ws/context.d.ts +8 -1
  322. package/dist/ws/context.js +68 -44
  323. package/dist/ws/context.mjs +67 -44
  324. package/dist/ws/parser.js +10 -20
  325. package/dist/ws/parser.mjs +10 -20
  326. package/dist/ws/route.d.ts +2 -2
  327. package/dist/ws/route.js +249 -141
  328. package/dist/ws/route.mjs +254 -146
  329. package/dist/ws/types.d.ts +2 -2
  330. package/package.json +23 -49
  331. package/dist/compile/analysis-cache.d.ts +0 -6
  332. package/dist/compile/analysis-cache.js +0 -12
  333. package/dist/compile/analysis-cache.mjs +0 -11
  334. package/dist/cookie/index.d.ts +0 -7
  335. package/dist/cookie/index.js +0 -13
  336. package/dist/cookie/index.mjs +0 -7
  337. package/dist/handler/index.d.ts +0 -2
  338. package/dist/handler/index.js +0 -5
  339. package/dist/handler/index.mjs +0 -3
package/dist/sucrose.js CHANGED
@@ -1,407 +1,27 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_utils = require('./utils.js');
3
3
  const require_compile_aot = require('./compile/aot.js');
4
+ const require_compile_lexer = require('./compile/lexer.js');
4
5
 
5
6
  //#region src/sucrose.ts
6
- /**
7
- * Separate stringified function body and parameter
8
- *
9
- * @example
10
- * ```typescript
11
- * separateFunction('async ({ hello }) => { return hello }') // => ['({ hello })', '{ return hello }']
12
- * ```
13
- */
14
- function separateFunction(code) {
15
- if (code.startsWith("async")) code = code.slice(5);
16
- code = code.trimStart();
17
- let index;
18
- if (code.charCodeAt(0) === 40) {
19
- const parameterEnd = findClosingParenthesis(code, 0);
20
- index = code.indexOf("=>", parameterEnd);
21
- if (index !== -1) {
22
- let body = code.slice(index + 2);
23
- if (body.charCodeAt(0) === 32) body = body.trimStart();
24
- return [code.slice(1, parameterEnd), body];
25
- }
26
- }
27
- if (/^([\w$]+)=>/g.test(code)) {
28
- index = code.indexOf("=>");
29
- if (index !== -1) {
30
- let body = code.slice(index + 2);
31
- if (body.charCodeAt(0) === 32) body = body.trimStart();
32
- return [code.slice(0, index), body];
33
- }
34
- }
35
- if (code.startsWith("function")) {
36
- index = code.indexOf("(");
37
- const end = findClosingParenthesis(code, index);
38
- return [code.slice(index + 1, end), code.slice(end + 2)];
39
- }
40
- const start = code.indexOf("(");
41
- if (start !== -1) {
42
- const sep = code.indexOf("\n", 2);
43
- const parameter = code.slice(0, sep);
44
- const end = parameter.lastIndexOf(")") + 1;
45
- const body = code.slice(sep + 1);
46
- return [parameter.slice(start, end), "{" + body];
47
- }
48
- const x = code.split("\n", 2);
49
- return [x[0], x[1]];
50
- }
51
- function findClosingParenthesis(code, start) {
52
- let deep = 1;
53
- for (let index = start + 1; index < code.length; index++) {
54
- const char = code.charCodeAt(index);
55
- if (char === 40) deep++;
56
- else if (char === 41 && --deep === 0) return index;
57
- }
58
- return start;
59
- }
60
- /**
61
- * Get range between bracket pair
62
- *
63
- * @example
64
- * ```typescript
65
- * bracketPairRange('hello: { world: { a } }, elysia') // [6, 20]
66
- * ```
67
- */
68
- function bracketPairRange(parameter) {
69
- const start = parameter.indexOf("{");
70
- if (start === -1) return [-1, 0];
71
- let end = start + 1;
72
- let deep = 1;
73
- for (; end < parameter.length; end++) {
74
- const char = parameter.charCodeAt(end);
75
- if (char === 123) deep++;
76
- else if (char === 125) deep--;
77
- if (deep === 0) break;
78
- }
79
- if (deep !== 0) return [0, parameter.length];
80
- return [start, end + 1];
81
- }
82
- /**
83
- * Similar to `bracketPairRange` but in reverse order
84
- * Get range between bracket pair from end to beginning
85
- *
86
- * @example
87
- * ```typescript
88
- * bracketPairRange('hello: { world: { a } }, elysia') // [6, 20]
89
- * ```
90
- */
91
- function bracketPairRangeReverse(parameter) {
92
- const end = parameter.lastIndexOf("}");
93
- if (end === -1) return [-1, 0];
94
- let start = end - 1;
95
- let deep = 1;
96
- for (; start >= 0; start--) {
97
- const char = parameter.charCodeAt(start);
98
- if (char === 125) deep++;
99
- else if (char === 123) deep--;
100
- if (deep === 0) break;
101
- }
102
- if (deep !== 0) return [-1, 0];
103
- return [start, end + 1];
104
- }
105
- function removeColonAlias(parameter) {
106
- while (true) {
107
- const start = parameter.indexOf(":");
108
- if (start === -1) break;
109
- let end = start + 1;
110
- while (end < parameter.length) {
111
- const char = parameter.charCodeAt(end);
112
- if (char !== 32 && char !== 9 && char !== 10) break;
113
- end++;
114
- }
115
- while (end < parameter.length) {
116
- const char = parameter.charCodeAt(end);
117
- if (char === 44 || char === 125 || char === 32 || char === 9 || char === 10) break;
118
- end++;
119
- }
120
- parameter = parameter.slice(0, start) + parameter.slice(end);
121
- }
122
- return parameter;
123
- }
124
- /**
125
- * Retrieve only root parameters of a function
126
- *
127
- * @example
128
- * ```typescript
129
- * retrieveRootParameters('({ hello: { world: { a } }, elysia })') // => {
130
- * parameters: ['hello', 'elysia'],
131
- * hasParenthesis: true
132
- * }
133
- * ```
134
- */
135
- function retrieveRootparameters(parameter) {
136
- let hasParenthesis = false;
137
- if (parameter.charCodeAt(0) === 40) parameter = parameter.slice(1, -1);
138
- parameter = parameter.trim();
139
- if (parameter.indexOf("=") !== -1) parameter = removeDefaultParameter(parameter);
140
- if (parameter.charCodeAt(0) === 123) {
141
- hasParenthesis = true;
142
- const [, end] = bracketPairRange(parameter);
143
- parameter = parameter.slice(1, end - 1);
144
- }
145
- parameter = parameter.replace(/\s+/g, "");
146
- const parameters = [];
147
- while (true) {
148
- let [start, end] = bracketPairRange(parameter);
149
- if (start === -1) break;
150
- parameters.push(removeColonAlias(parameter.slice(0, start - 1)));
151
- if (parameter.charCodeAt(end) === 44) end++;
152
- parameter = parameter.slice(end);
153
- }
154
- parameter = removeColonAlias(parameter);
155
- if (parameter) parameters.push(parameter);
156
- const parameterMap = Object.create(null);
157
- for (const p of parameters) {
158
- if (p.indexOf(",") === -1) {
159
- parameterMap[p] = true;
160
- continue;
161
- }
162
- for (const q of p.split(",")) parameterMap[q] = true;
163
- }
164
- return {
165
- hasParenthesis,
166
- parameters: parameterMap
167
- };
168
- }
169
- function findEndIndex(type, content, index) {
170
- let search = index ?? 0;
171
- while (true) {
172
- const found = content.indexOf(type, search);
173
- if (found === -1) return -1;
174
- switch (content.charCodeAt(found + type.length)) {
175
- case 10:
176
- case 9:
177
- case 44:
178
- case 59:
179
- case 32:
180
- case 41:
181
- case 125: return found;
182
- }
183
- search = found + 1;
184
- }
185
- }
186
- /**
187
- * Find alias of variable from function body
188
- *
189
- * @example
190
- * ```typescript
191
- * findAlias('body', '{ const a = body, b = body }') // => ['a', 'b']
192
- * ```
193
- */
194
- function findAlias(type, body, seen = /* @__PURE__ */ new Set()) {
195
- const aliases = [];
196
- let content = body;
197
- const spaced = " = " + type;
198
- const minified = "=" + type;
199
- while (true) {
200
- let matchedLength = spaced.length;
201
- let index = findEndIndex(spaced, content);
202
- if (index === -1) {
203
- index = findEndIndex(minified, content);
204
- matchedLength = minified.length;
205
- }
206
- if (index === -1) {
207
- /**
208
- * Check if pattern is at the end of the string
209
- *
210
- * @example
211
- * ```typescript
212
- * 'const a = body' // true
213
- * ```
214
- **/
215
- let lastIndex = content.indexOf(spaced);
216
- matchedLength = spaced.length;
217
- if (lastIndex === -1) {
218
- lastIndex = content.indexOf(minified);
219
- matchedLength = minified.length;
220
- }
221
- if (lastIndex === -1) break;
222
- if (lastIndex + matchedLength !== content.length) break;
223
- index = lastIndex;
224
- }
225
- const part = content.slice(0, index);
226
- let boundary = -1;
227
- for (let i = part.length - 1; i >= 0; i--) {
228
- const char = part.charCodeAt(i);
229
- if (char === 32 || char === 44 || char === 40 || char === 59 || char === 41 || char === 9 || char === 10) {
230
- boundary = i;
231
- break;
232
- }
233
- }
234
- /**
235
- * aliased variable last character
236
- *
237
- * @example
238
- * ```typescript
239
- * const { hello } = body // } is the last character
240
- * ```
241
- **/
242
- const variable = part.slice(boundary + 1);
243
- if (variable.charCodeAt(variable.length - 1) === 125) {
244
- const [start, end] = bracketPairRangeReverse(part);
245
- aliases.push(removeColonAlias(content.slice(start, end)));
246
- content = content.slice(index + matchedLength);
247
- continue;
248
- }
249
- if (variable && !variable.includes("(")) aliases.push(variable);
250
- content = content.slice(index + matchedLength);
251
- }
252
- for (let i = 0; i < aliases.length; i++) {
253
- const alias = aliases[i];
254
- if (alias.charCodeAt(0) === 123 || seen.has(alias)) continue;
255
- seen.add(alias);
256
- aliases.push(...findAlias(alias, body, seen));
257
- }
258
- return aliases;
259
- }
260
- /**
261
- * Whitespace as JavaScript defines it, which is what `\s` matches: everything
262
- * `String.prototype.trim` removes, not just the three characters that happen to
263
- * appear in LF-formatted source.
264
- */
265
- const isWhitespace = (char) => char === 32 || char >= 9 && char <= 13 || char === 160 || char === 5760 || char >= 8192 && char <= 8202 || char === 8232 || char === 8233 || char === 8239 || char === 8287 || char === 12288 || char === 65279;
266
- /**
267
- * Words that lex as an identifier but are operators, so a `/` after one opens a
268
- * regex instead of dividing. Padded so a lookup cannot match a substring.
269
- */
270
- const operatorKeyword = " typeof void delete in of instanceof new return case do else yield await throw ";
271
- /**
272
- * Skip a regular expression literal, so a `,`, `}` or quote inside it is not
273
- * mistaken for structure.
274
- */
275
- function skipRegexLiteral(parameter, start, regexEnd) {
276
- let previous = start - 1;
277
- while (previous >= 0 && isWhitespace(parameter.charCodeAt(previous))) previous--;
278
- if (previous >= 0) {
279
- const char = parameter.charCodeAt(previous);
280
- if (isIdentifierPart(char)) {
281
- let identifier = previous;
282
- while (identifier >= 0 && isIdentifierPart(parameter.charCodeAt(identifier))) identifier--;
283
- if (parameter.charCodeAt(identifier) === 46 || !operatorKeyword.includes(" " + parameter.slice(identifier + 1, previous + 1) + " ")) return start;
284
- } else if (char === 41 || char === 93 || char === 125 || char === 39 || char === 34 || char === 96 || char === 47 && previous === regexEnd) return start;
285
- }
286
- let inCharacterClass = false;
287
- for (let index = start + 1; index < parameter.length; index++) {
288
- const char = parameter.charCodeAt(index);
289
- if (char === 92) index++;
290
- else if (char === 91) inCharacterClass = true;
291
- else if (char === 93) inCharacterClass = false;
292
- else if (char === 47 && !inCharacterClass) return index;
293
- }
294
- return start;
295
- }
296
- /**
297
- * Find where a default parameter value ends: the first `,` or `}` that is
298
- * outside a string or regex literal and not nested inside `()`, `[]`, or `{}`
299
- *
300
- * Returns -1 when the value runs until the end of the string
301
- */
302
- function findDefaultValueEnd(parameter, start) {
303
- let deep = 0;
304
- let quote = 0;
305
- let regexEnd = -1;
306
- let template;
307
- for (let index = start; index < parameter.length; index++) {
308
- const char = parameter.charCodeAt(index);
309
- if (quote !== 0) {
310
- if (char === 92) index++;
311
- else if (char === quote) quote = 0;
312
- else if (quote === 96 && char === 36 && parameter.charCodeAt(index + 1) === 123) {
313
- (template ??= []).push(deep);
314
- quote = 0;
315
- deep++;
316
- index++;
317
- }
318
- continue;
319
- }
320
- switch (char) {
321
- case 39:
322
- case 34:
323
- case 96:
324
- quote = char;
325
- break;
326
- case 47: {
327
- const closing = skipRegexLiteral(parameter, index, regexEnd);
328
- if (closing !== index) regexEnd = closing;
329
- index = closing;
330
- break;
331
- }
332
- case 40:
333
- case 91:
334
- case 123:
335
- deep++;
336
- break;
337
- case 41:
338
- case 93:
339
- if (deep !== 0) deep--;
340
- break;
341
- case 125:
342
- if (deep === 0) return index;
343
- deep--;
344
- if (template !== void 0 && template[template.length - 1] === deep) {
345
- template.pop();
346
- quote = 96;
347
- }
348
- break;
349
- case 44:
350
- if (deep === 0) return index;
351
- break;
352
- }
353
- }
354
- return -1;
355
- }
356
- function removeDefaultParameter(parameter) {
357
- let index = parameter.indexOf("=");
358
- if (index !== -1) {
359
- let kept = "";
360
- let copyFrom = 0;
361
- for (; index < parameter.length; index++) {
362
- if (parameter.charCodeAt(index) !== 61) continue;
363
- kept += parameter.slice(copyFrom, index);
364
- const end = findDefaultValueEnd(parameter, index + 1);
365
- if (end === -1) {
366
- copyFrom = parameter.length;
367
- break;
368
- }
369
- copyFrom = index = end;
370
- }
371
- parameter = kept + parameter.slice(copyFrom);
372
- }
373
- return parameter.split(",").map((i) => i.trim()).join(", ");
374
- }
375
- function markAllAccessed(i) {
376
- i.query = i.headers = i.body = i.cookie = i.set = i.route = true;
377
- i.afterResponse = true;
378
- }
7
+ const allAccessed = Object.freeze({
8
+ query: true,
9
+ headers: true,
10
+ body: true,
11
+ cookie: true,
12
+ set: true,
13
+ route: true,
14
+ afterResponse: true
15
+ });
16
+ const isAllAccessed = (i) => i.query && i.headers && i.body && i.cookie && i.set && i.route && i.afterResponse;
379
17
  const DEFAULT_CACHE_LIMIT = 1024;
380
18
  const globalSourceCache = /* @__PURE__ */ new Map();
381
- function sourceCache() {
382
- const session = require_compile_aot.getCompilerSession();
383
- return session?.external ? session.sucroseCache : globalSourceCache;
384
- }
385
19
  let functionCaches = /* @__PURE__ */ new WeakMap();
386
- function rememberInference(caches, key, cached, content, event, inference) {
387
- if (!cached || cached.content !== content) {
388
- if (caches.size >= DEFAULT_CACHE_LIMIT) require_utils.evictOldestHalf(caches);
389
- caches.set(key, {
390
- content,
391
- inference
392
- });
393
- }
394
- if (typeof event === "function") functionCaches.set(event, inference);
395
- }
396
- function clearCache() {
20
+ function clearSucroseCache() {
397
21
  globalSourceCache.clear();
398
22
  require_compile_aot.getCompilerSession()?.sucroseCache.clear();
399
23
  functionCaches = /* @__PURE__ */ new WeakMap();
400
24
  }
401
- function clearSucroseCache(delay) {
402
- if (delay === null) return;
403
- clearCache();
404
- }
405
25
  const mergeInference = (a, b) => ({
406
26
  body: a.body || b.body,
407
27
  cookie: a.cookie || b.cookie,
@@ -420,245 +40,6 @@ const defaultSucrose = () => ({
420
40
  route: false
421
41
  });
422
42
  const emptyInference = Object.freeze(defaultSucrose());
423
- function push(target, array) {
424
- for (let i = 0; i < array.length; i++) target.push(array[i]);
425
- }
426
- function pushParse(target, array) {
427
- for (let i = 0; i < array.length; i++) if (typeof array[i] === "function") target.push(array[i]);
428
- }
429
- const prefixKeywords = new Set([
430
- "await",
431
- "case",
432
- "delete",
433
- "do",
434
- "else",
435
- "in",
436
- "instanceof",
437
- "new",
438
- "of",
439
- "return",
440
- "throw",
441
- "typeof",
442
- "void",
443
- "yield"
444
- ]);
445
- const isIdentifierStart = (char) => char >= 65 && char <= 90 || char >= 97 && char <= 122 || char === 36 || char === 95 || char >= 128;
446
- const isIdentifierPart = (char) => isIdentifierStart(char) || char >= 48 && char <= 57;
447
- function decodeIdentifier(value) {
448
- if (!value.includes("\\u")) return value;
449
- let decoded = "";
450
- for (let i = 0; i < value.length; i++) {
451
- if (value.charCodeAt(i) !== 92 || value.charCodeAt(i + 1) !== 117) {
452
- decoded += value[i];
453
- continue;
454
- }
455
- i += 2;
456
- let hex;
457
- if (value.charCodeAt(i) === 123) {
458
- const end = value.indexOf("}", i + 1);
459
- if (end === -1) return;
460
- hex = value.slice(i + 1, end);
461
- i = end;
462
- } else {
463
- hex = value.slice(i, i + 4);
464
- if (hex.length !== 4) return;
465
- i += 3;
466
- }
467
- const codePoint = Number.parseInt(hex, 16);
468
- if (!Number.isFinite(codePoint) || codePoint > 1114111) return;
469
- decoded += String.fromCodePoint(codePoint);
470
- }
471
- return decoded;
472
- }
473
- function scanTokens(source) {
474
- const tokens = [];
475
- let index = 0;
476
- let canEndExpression = false;
477
- const scanCode = (templateExpression = false) => {
478
- let templateDepth = 0;
479
- while (index < source.length) {
480
- const char = source.charCodeAt(index);
481
- if (char === 32 || char === 9 || char === 10 || char === 13) {
482
- index++;
483
- continue;
484
- }
485
- if (char === 92 && source.charCodeAt(index + 1) !== 117) return false;
486
- if (char === 47) {
487
- const next = source.charCodeAt(index + 1);
488
- if (next === 47) {
489
- index += 2;
490
- while (index < source.length && source.charCodeAt(index) !== 10 && source.charCodeAt(index) !== 13) index++;
491
- continue;
492
- }
493
- if (next === 42) {
494
- index += 2;
495
- while (index + 1 < source.length && !(source.charCodeAt(index) === 42 && source.charCodeAt(index + 1) === 47)) index++;
496
- if (index + 1 >= source.length) return false;
497
- index += 2;
498
- continue;
499
- }
500
- if (!canEndExpression) {
501
- index++;
502
- let escaped = false;
503
- let characterClass = false;
504
- let closed = false;
505
- while (index < source.length) {
506
- const regexChar = source.charCodeAt(index++);
507
- if (escaped) {
508
- escaped = false;
509
- continue;
510
- }
511
- if (regexChar === 92) {
512
- escaped = true;
513
- continue;
514
- }
515
- if (regexChar === 91) characterClass = true;
516
- else if (regexChar === 93) characterClass = false;
517
- else if (regexChar === 47 && !characterClass) {
518
- closed = true;
519
- break;
520
- } else if (regexChar === 10 || regexChar === 13) return false;
521
- }
522
- if (!closed) return false;
523
- while (isIdentifierPart(source.charCodeAt(index))) index++;
524
- canEndExpression = true;
525
- continue;
526
- }
527
- tokens.push({
528
- k: "p",
529
- value: "/"
530
- });
531
- index++;
532
- canEndExpression = false;
533
- continue;
534
- }
535
- if (char === 34 || char === 39) {
536
- const quote = char;
537
- const start = ++index;
538
- let escaped = false;
539
- while (index < source.length) {
540
- const stringChar = source.charCodeAt(index);
541
- if (escaped) escaped = false;
542
- else if (stringChar === 92) escaped = true;
543
- else if (stringChar === quote) break;
544
- else if (stringChar === 10 || stringChar === 13) return false;
545
- index++;
546
- }
547
- if (index >= source.length) return false;
548
- tokens.push({
549
- k: "s",
550
- value: source.slice(start, index)
551
- });
552
- index++;
553
- canEndExpression = true;
554
- continue;
555
- }
556
- if (char === 96) {
557
- index++;
558
- let closed = false;
559
- while (index < source.length) {
560
- const templateChar = source.charCodeAt(index);
561
- if (templateChar === 92) {
562
- index += 2;
563
- continue;
564
- }
565
- if (templateChar === 96) {
566
- index++;
567
- closed = true;
568
- break;
569
- }
570
- if (templateChar === 36 && source.charCodeAt(index + 1) === 123) {
571
- index += 2;
572
- canEndExpression = false;
573
- if (!scanCode(true)) return false;
574
- continue;
575
- }
576
- index++;
577
- }
578
- if (!closed) return false;
579
- canEndExpression = true;
580
- continue;
581
- }
582
- if (isIdentifierStart(char) || char === 92 && source.charCodeAt(index + 1) === 117) {
583
- const start = index;
584
- if (char === 92) {
585
- index += 2;
586
- if (source.charCodeAt(index) === 123) {
587
- const end = source.indexOf("}", index + 1);
588
- if (end === -1) return false;
589
- index = end + 1;
590
- } else {
591
- for (let digit = 0; digit < 4; digit++) {
592
- const hex = source.charCodeAt(index + digit);
593
- if (!(hex >= 48 && hex <= 57 || hex >= 65 && hex <= 70 || hex >= 97 && hex <= 102)) return false;
594
- }
595
- index += 4;
596
- }
597
- } else index++;
598
- while (index < source.length) {
599
- const identifierChar = source.charCodeAt(index);
600
- if (isIdentifierPart(identifierChar)) {
601
- index++;
602
- continue;
603
- }
604
- if (identifierChar === 92 && source.charCodeAt(index + 1) === 117) {
605
- index += 2;
606
- if (source.charCodeAt(index) === 123) {
607
- const end = source.indexOf("}", index + 1);
608
- if (end === -1) return false;
609
- index = end + 1;
610
- } else {
611
- for (let digit = 0; digit < 4; digit++) {
612
- const hex = source.charCodeAt(index + digit);
613
- if (!(hex >= 48 && hex <= 57 || hex >= 65 && hex <= 70 || hex >= 97 && hex <= 102)) return false;
614
- }
615
- index += 4;
616
- }
617
- continue;
618
- }
619
- break;
620
- }
621
- const value = decodeIdentifier(source.slice(start, index));
622
- if (value === void 0) return false;
623
- tokens.push({
624
- k: "i",
625
- value
626
- });
627
- canEndExpression = !prefixKeywords.has(value);
628
- continue;
629
- }
630
- if (char >= 48 && char <= 57) {
631
- index++;
632
- while (isIdentifierPart(source.charCodeAt(index))) index++;
633
- canEndExpression = true;
634
- continue;
635
- }
636
- if (templateExpression) {
637
- if (char === 123) templateDepth++;
638
- else if (char === 125) {
639
- if (templateDepth === 0) {
640
- index++;
641
- return true;
642
- }
643
- templateDepth--;
644
- }
645
- }
646
- let value = source[index];
647
- const pair = source.slice(index, index + 2);
648
- const triple = source.slice(index, index + 3);
649
- if (triple === "...") value = triple;
650
- else if (pair === "?." || pair === "=>" || pair === "++" || pair === "--") value = pair;
651
- tokens.push({
652
- k: "p",
653
- value
654
- });
655
- index += value.length;
656
- if (value !== "++" && value !== "--") canEndExpression = value === ")" || value === "]" || value === "}";
657
- }
658
- return !templateExpression;
659
- };
660
- return scanCode() ? tokens : void 0;
661
- }
662
43
  const channel = (value) => {
663
44
  switch (value) {
664
45
  case "query":
@@ -670,27 +51,24 @@ const channel = (value) => {
670
51
  case "defer": return "afterResponse";
671
52
  }
672
53
  };
673
- function computedDestructuringChannel(tokens, index) {
54
+ function computedDestructuringChannel(tokens, index, channelOf) {
674
55
  const property = tokens[index + 1];
675
- return property?.k === "s" && !property.value.includes("\\") && tokens[index + 2]?.value === "]" && channel(property.value) || false;
56
+ return property?.k === "s" && !property.value.includes("\\") && tokens[index + 2]?.value === "]" && channelOf(property.value) || false;
676
57
  }
677
- function inferFunction(source) {
678
- const inference = defaultSucrose();
679
- if (!source || source.includes("[native code]") || source.trimStart().startsWith("class")) {
680
- markAllAccessed(inference);
681
- return inference;
682
- }
58
+ /**
59
+ * @internal Which `channelOf`-mapped members of a function's first parameter
60
+ * the function may read, or `null` when any member may be read
61
+ */
62
+ function inferFunction(source, channelOf, strict = false) {
63
+ if (!source || source.includes("[native code]") || source.trimStart().startsWith("class")) return null;
683
64
  let tokens;
684
65
  try {
685
- tokens = scanTokens(source);
66
+ tokens = require_compile_lexer.scanTokens(source);
686
67
  } catch {
687
- markAllAccessed(inference);
688
- return inference;
689
- }
690
- if (!tokens?.length) {
691
- markAllAccessed(inference);
692
- return inference;
68
+ return null;
693
69
  }
70
+ if (!tokens?.length) return null;
71
+ const keys = /* @__PURE__ */ new Set();
694
72
  let arrow = -1;
695
73
  const callableStart = tokens[0].value === "async" ? 1 : 0;
696
74
  if (tokens[callableStart]?.value !== "function") {
@@ -741,10 +119,7 @@ function inferFunction(source) {
741
119
  }
742
120
  break;
743
121
  }
744
- if (parameterStart < 0 || parameterEnd < parameterStart || bodyStart < 0) {
745
- markAllAccessed(inference);
746
- return inference;
747
- }
122
+ if (parameterStart < 0 || parameterEnd < parameterStart || bodyStart < 0) return null;
748
123
  const aliases = /* @__PURE__ */ new Set();
749
124
  const first = tokens[parameterStart];
750
125
  if (parameterStart === parameterEnd) {} else if (first?.k === "i") aliases.add(first.value);
@@ -754,25 +129,25 @@ function inferFunction(source) {
754
129
  const token = tokens[i];
755
130
  if (token.value === "{") depth++;
756
131
  else if (token.value === "}") depth--;
132
+ else if (token.value === "," && depth === 0) break;
757
133
  else if (token.value === "[" && depth === 1 && (tokens[i - 1]?.value === "{" || tokens[i - 1]?.value === ",")) {
758
- const computed = computedDestructuringChannel(tokens, i);
759
- if (computed === false) {
760
- markAllAccessed(inference);
761
- return inference;
762
- }
763
- if (computed) inference[computed] = true;
134
+ const computed = computedDestructuringChannel(tokens, i, channelOf);
135
+ if (computed === false) return null;
136
+ keys.add(computed);
764
137
  } else if (token.value === "..." && depth === 1) {
765
138
  const rest = tokens[i + 1];
766
139
  if (rest?.k === "i") aliases.add(rest.value);
767
140
  } else if (token.k === "i" && depth === 1) {
768
- const key = channel(token.value);
769
- if (key) inference[key] = true;
141
+ if (token.value === "ws" && (tokens[i - 1]?.value === "{" || tokens[i - 1]?.value === ",")) {
142
+ const renamed = tokens[i + 1]?.value === ":" && tokens[i + 2]?.k === "i" ? tokens[i + 2].value : token.value;
143
+ aliases.add(renamed);
144
+ continue;
145
+ }
146
+ const key = channelOf(token.value);
147
+ if (key) keys.add(key);
770
148
  }
771
149
  }
772
- } else {
773
- markAllAccessed(inference);
774
- return inference;
775
- }
150
+ } else return null;
776
151
  const patterns = [];
777
152
  let closedPattern;
778
153
  for (let i = bodyStart; i < tokens.length; i++) {
@@ -789,28 +164,28 @@ function inferFunction(source) {
789
164
  if (patterns.length) {
790
165
  const current = patterns[patterns.length - 1];
791
166
  if (token.value === "[" && (tokens[i - 1]?.value === "{" || tokens[i - 1]?.value === ",")) {
792
- const computed = computedDestructuringChannel(tokens, i);
167
+ const computed = computedDestructuringChannel(tokens, i, channelOf);
793
168
  current[0].add(computed);
794
169
  } else if (token.value === "..." && tokens[i + 1]?.k === "i") current[1] = tokens[i + 1].value;
795
170
  else if (token.k === "i") {
796
- const key = channel(token.value);
171
+ const key = channelOf(token.value);
797
172
  if (key) current[0].add(key);
798
173
  }
799
174
  }
800
175
  if (token.value === "=") {
801
176
  const right = tokens[i + 1];
802
177
  let member = i + 2;
803
- if (tokens[member]?.value === "?.") member++;
804
- if (right?.k === "i" && aliases.has(right.value) && tokens[member]?.value !== "." && tokens[member]?.value !== "[" && tokens[member]?.k !== "i") {
178
+ const optional = tokens[member]?.value === "?.";
179
+ if (optional) member++;
180
+ if (right?.k === "i" && aliases.has(right.value) && tokens[member]?.value !== "." && tokens[member]?.value !== "[" && (tokens[member]?.k !== "i" || strict && !optional)) {
805
181
  const left = tokens[i - 1];
806
- if (left?.k === "i") aliases.add(left.value);
807
- else if (left?.value === "}" && closedPattern) {
182
+ if (left?.k === "i") {
183
+ if (strict) return null;
184
+ aliases.add(left.value);
185
+ } else if (left?.value === "}" && closedPattern) {
808
186
  for (const key of closedPattern[0]) {
809
- if (key === false) {
810
- markAllAccessed(inference);
811
- return inference;
812
- }
813
- inference[key] = true;
187
+ if (key === false) return null;
188
+ keys.add(key);
814
189
  }
815
190
  if (closedPattern[1]) aliases.add(closedPattern[1]);
816
191
  }
@@ -818,64 +193,61 @@ function inferFunction(source) {
818
193
  continue;
819
194
  }
820
195
  if (token.k !== "i") continue;
821
- if (token.value === "arguments" || token.value === "eval") {
822
- markAllAccessed(inference);
823
- break;
824
- }
196
+ if (token.value === "arguments" || token.value === "eval") return null;
825
197
  if (!aliases.has(token.value)) continue;
198
+ if (i + 1 < tokens.length) {
199
+ for (let j = token.at + 1; j < tokens[i + 1].at; j++) if (source.charCodeAt(j) === 96) return null;
200
+ }
826
201
  let next = i + 1;
827
202
  if (tokens[next]?.value === "?.") next++;
828
203
  if (tokens[next]?.value === ".") next++;
829
204
  if (tokens[next]?.k === "i" && next > i + 1) {
830
- const key = channel(tokens[next].value);
831
- if (key) inference[key] = true;
205
+ const key = channelOf(tokens[next].value);
206
+ if (key) keys.add(key);
832
207
  continue;
833
208
  }
834
209
  if (tokens[next]?.value === "[") {
835
210
  const property = tokens[next + 1];
836
- const key = property?.k === "s" && channel(property.value);
837
- if (key && tokens[next + 2]?.value === "]") inference[key] = true;
838
- else markAllAccessed(inference);
839
- if (inference.query && inference.headers && inference.body && inference.cookie && inference.set && inference.route && inference.afterResponse) break;
211
+ const key = property?.k === "s" && channelOf(property.value);
212
+ if (!key || tokens[next + 2]?.value !== "]") return null;
213
+ keys.add(key);
840
214
  continue;
841
215
  }
842
216
  if (tokens[i - 1]?.value === "=" && (tokens[i - 2]?.k === "i" || tokens[i - 2]?.value === "}")) continue;
843
- markAllAccessed(inference);
844
- break;
217
+ return null;
845
218
  }
846
- return inference;
219
+ return keys;
847
220
  }
848
- const eventsBuffer = [];
849
- let eventsBufferInUse = false;
221
+ const lifeCycleEvents = [
222
+ "request",
223
+ "beforeHandle",
224
+ "parse",
225
+ "error",
226
+ "transform",
227
+ "afterHandle",
228
+ "mapResponse",
229
+ "afterResponse"
230
+ ];
850
231
  function sucrose(handler, lifeCycle) {
851
232
  let inference;
852
233
  let merged = false;
853
- const reentrant = eventsBufferInUse;
854
- const events = reentrant ? [] : eventsBuffer;
855
- eventsBufferInUse = true;
856
- try {
857
- if (handler && typeof handler === "function") events.push(handler);
858
- if (lifeCycle) {
859
- if (lifeCycle.request?.length) push(events, lifeCycle.request);
860
- if (lifeCycle.beforeHandle?.length) push(events, lifeCycle.beforeHandle);
861
- if (lifeCycle.parse?.length) pushParse(events, lifeCycle.parse);
862
- if (lifeCycle.error?.length) push(events, lifeCycle.error);
863
- if (lifeCycle.transform?.length) push(events, lifeCycle.transform);
864
- if (lifeCycle.afterHandle?.length) push(events, lifeCycle.afterHandle);
865
- if (lifeCycle.mapResponse?.length) push(events, lifeCycle.mapResponse);
866
- if (lifeCycle.afterResponse?.length) push(events, lifeCycle.afterResponse);
234
+ const events = [];
235
+ if (handler && typeof handler === "function") events.push(handler);
236
+ if (lifeCycle) for (const name of lifeCycleEvents) {
237
+ const array = lifeCycle[name];
238
+ if (array) {
239
+ for (let i = 0; i < array.length; i++) if (name !== "parse" || typeof array[i] === "function") events.push(array[i]);
867
240
  }
868
- const caches = sourceCache();
869
- for (let i = 0; i < events.length; i++) {
870
- const event = events[i];
871
- if (!event) continue;
872
- let inferred = functionCaches.get(event);
873
- if (!inferred) if (typeof event === "function" && Object.hasOwn(event, "toString")) {
874
- const forged = defaultSucrose();
875
- markAllAccessed(forged);
876
- inferred = Object.freeze(forged);
877
- functionCaches.set(event, inferred);
878
- } else {
241
+ }
242
+ const session = require_compile_aot.getCompilerSession();
243
+ const caches = session?.external ? session.sucroseCache : globalSourceCache;
244
+ for (let i = 0; i < events.length; i++) {
245
+ const event = events[i];
246
+ if (!event) continue;
247
+ let inferred = functionCaches.get(event);
248
+ if (!inferred) {
249
+ if (typeof event === "function" && Object.hasOwn(event, "toString")) inferred = allAccessed;
250
+ else {
879
251
  const content = event.toString();
880
252
  const key = require_utils.fnv1a(content);
881
253
  const cached = caches.get(key);
@@ -885,34 +257,34 @@ function sucrose(handler, lifeCycle) {
885
257
  caches.delete(key);
886
258
  caches.set(key, cached);
887
259
  }
888
- if (typeof event === "function") functionCaches.set(event, inferred);
889
260
  } else {
890
- inferred = Object.freeze(inferFunction(content));
891
- rememberInference(caches, key, cached, content, event, inferred);
261
+ const channels = inferFunction(content, channel);
262
+ if (channels) {
263
+ const fresh = defaultSucrose();
264
+ for (const c of channels) fresh[c] = true;
265
+ inferred = Object.freeze(fresh);
266
+ } else inferred = allAccessed;
267
+ if (caches.size >= DEFAULT_CACHE_LIMIT) require_utils.evictOldestHalf(caches);
268
+ caches.set(key, {
269
+ content,
270
+ inference: inferred
271
+ });
892
272
  }
893
273
  }
894
- if (inference) {
895
- inference = mergeInference(inference, inferred);
896
- merged = true;
897
- } else inference = inferred;
898
- if (inference.query && inference.headers && inference.body && inference.cookie && inference.set && inference.route && inference.afterResponse) break;
274
+ if (typeof event === "function") functionCaches.set(event, inferred);
899
275
  }
900
- } finally {
901
- events.length = 0;
902
- eventsBufferInUse = reentrant;
276
+ if (inference) {
277
+ inference = mergeInference(inference, inferred);
278
+ merged = true;
279
+ } else inference = inferred;
280
+ if (isAllAccessed(inference)) break;
903
281
  }
904
282
  if (!inference) return emptyInference;
905
283
  return merged ? Object.freeze(inference) : inference;
906
284
  }
907
285
 
908
286
  //#endregion
909
- exports.bracketPairRange = bracketPairRange;
910
- exports.bracketPairRangeReverse = bracketPairRangeReverse;
911
287
  exports.clearSucroseCache = clearSucroseCache;
912
- exports.findAlias = findAlias;
288
+ exports.inferFunction = inferFunction;
913
289
  exports.mergeInference = mergeInference;
914
- exports.removeColonAlias = removeColonAlias;
915
- exports.removeDefaultParameter = removeDefaultParameter;
916
- exports.retrieveRootparameters = retrieveRootparameters;
917
- exports.separateFunction = separateFunction;
918
290
  exports.sucrose = sucrose;