elysia 2.0.0-beta.2 → 2.0.0-beta.20

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 (337) 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 +11 -13
  25. package/dist/compile/aot.js +34 -46
  26. package/dist/compile/aot.mjs +35 -45
  27. package/dist/compile/handler/descriptor.d.ts +9 -12
  28. package/dist/compile/handler/descriptor.js +17 -41
  29. package/dist/compile/handler/descriptor.mjs +18 -39
  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 +6 -5
  34. package/dist/compile/handler/index.js +148 -109
  35. package/dist/compile/handler/index.mjs +149 -111
  36. package/dist/compile/handler/jit.d.ts +17 -17
  37. package/dist/compile/handler/jit.js +220 -148
  38. package/dist/compile/handler/jit.mjs +222 -151
  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 +4 -3
  44. package/dist/compile/handler/reconstruct.mjs +4 -3
  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 +1 -0
  66. package/dist/cookie/config.js +9 -9
  67. package/dist/cookie/config.mjs +9 -9
  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 +47 -60
  108. package/dist/plugin/aot/core.js +172 -109
  109. package/dist/plugin/aot/core.mjs +169 -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 +47 -62
  122. package/dist/plugin/aot/source.mjs +48 -63
  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 +29 -47
  139. package/dist/schema-snapshot.mjs +29 -47
  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 +2 -6
  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/constants.d.ts +1 -1
  162. package/dist/type/elysia/array-buffer.d.ts +4 -1
  163. package/dist/type/elysia/array-buffer.js +17 -17
  164. package/dist/type/elysia/array-buffer.mjs +17 -17
  165. package/dist/type/elysia/array-string.js +2 -40
  166. package/dist/type/elysia/array-string.mjs +2 -39
  167. package/dist/type/elysia/array.js +5 -9
  168. package/dist/type/elysia/array.mjs +5 -9
  169. package/dist/type/elysia/boolean-string.js +2 -3
  170. package/dist/type/elysia/boolean-string.mjs +1 -1
  171. package/dist/type/elysia/boolean.js +3 -12
  172. package/dist/type/elysia/boolean.mjs +3 -11
  173. package/dist/type/elysia/cookie.d.ts +3 -4
  174. package/dist/type/elysia/cookie.js +5 -15
  175. package/dist/type/elysia/cookie.mjs +5 -15
  176. package/dist/type/elysia/date.js +13 -20
  177. package/dist/type/elysia/date.mjs +10 -16
  178. package/dist/type/elysia/file-type.d.ts +11 -4
  179. package/dist/type/elysia/file-type.js +17 -2
  180. package/dist/type/elysia/file-type.mjs +17 -3
  181. package/dist/type/elysia/file.d.ts +1 -3
  182. package/dist/type/elysia/file.js +11 -27
  183. package/dist/type/elysia/file.mjs +11 -12
  184. package/dist/type/elysia/files.js +7 -11
  185. package/dist/type/elysia/files.mjs +7 -10
  186. package/dist/type/elysia/form.js +2 -3
  187. package/dist/type/elysia/form.mjs +3 -3
  188. package/dist/type/elysia/integer-string.d.ts +1 -1
  189. package/dist/type/elysia/integer-string.js +4 -30
  190. package/dist/type/elysia/integer-string.mjs +5 -30
  191. package/dist/type/elysia/integer.js +3 -12
  192. package/dist/type/elysia/integer.mjs +3 -11
  193. package/dist/type/elysia/intersect.js +0 -5
  194. package/dist/type/elysia/intersect.mjs +0 -5
  195. package/dist/type/elysia/json-string.d.ts +7 -0
  196. package/dist/type/elysia/json-string.js +47 -0
  197. package/dist/type/elysia/json-string.mjs +46 -0
  198. package/dist/type/elysia/maybe-empty.js +3 -4
  199. package/dist/type/elysia/maybe-empty.mjs +1 -1
  200. package/dist/type/elysia/nullable.js +2 -3
  201. package/dist/type/elysia/nullable.mjs +1 -1
  202. package/dist/type/elysia/number.d.ts +2 -1
  203. package/dist/type/elysia/number.js +19 -11
  204. package/dist/type/elysia/number.mjs +18 -10
  205. package/dist/type/elysia/numeric-enum.d.ts +1 -1
  206. package/dist/type/elysia/numeric-enum.js +4 -5
  207. package/dist/type/elysia/numeric-enum.mjs +3 -3
  208. package/dist/type/elysia/numeric.d.ts +4 -2
  209. package/dist/type/elysia/numeric.js +20 -17
  210. package/dist/type/elysia/numeric.mjs +19 -16
  211. package/dist/type/elysia/object-string.js +2 -37
  212. package/dist/type/elysia/object-string.mjs +2 -36
  213. package/dist/type/elysia/object.js +5 -9
  214. package/dist/type/elysia/object.mjs +5 -9
  215. package/dist/type/elysia/optional.js +8 -8
  216. package/dist/type/elysia/optional.mjs +7 -7
  217. package/dist/type/elysia/problem.d.ts +20 -0
  218. package/dist/type/elysia/problem.js +25 -0
  219. package/dist/type/elysia/problem.mjs +24 -0
  220. package/dist/type/elysia/string.js +4 -3
  221. package/dist/type/elysia/string.mjs +4 -2
  222. package/dist/type/elysia/uint8-array.d.ts +1 -1
  223. package/dist/type/elysia/uint8-array.js +5 -20
  224. package/dist/type/elysia/uint8-array.mjs +5 -19
  225. package/dist/type/elysia/union-enum.js +7 -8
  226. package/dist/type/elysia/union-enum.mjs +6 -6
  227. package/dist/type/elysia/union.js +0 -5
  228. package/dist/type/elysia/union.mjs +0 -5
  229. package/dist/type/elysia/utils.d.ts +2 -4
  230. package/dist/type/elysia/utils.js +10 -21
  231. package/dist/type/elysia/utils.mjs +7 -15
  232. package/dist/type/exports.d.ts +3 -2
  233. package/dist/type/exports.js +13 -2
  234. package/dist/type/exports.mjs +10 -2
  235. package/dist/type/index.d.ts +10 -2
  236. package/dist/type/index.js +52 -15
  237. package/dist/type/index.mjs +55 -11
  238. package/dist/type/shared.d.ts +3 -9
  239. package/dist/type/shared.js +44 -97
  240. package/dist/type/shared.mjs +43 -97
  241. package/dist/type/sync-require.d.ts +11 -0
  242. package/dist/type/sync-require.js +14 -0
  243. package/dist/type/sync-require.mjs +12 -0
  244. package/dist/type/typebox-system-lite.d.ts +2 -0
  245. package/dist/type/typebox-system-lite.js +34 -0
  246. package/dist/type/typebox-system-lite.mjs +3 -0
  247. package/dist/type/typebox-system-require.d.ts +7 -0
  248. package/dist/type/typebox-system-require.js +24 -0
  249. package/dist/type/typebox-system-require.mjs +23 -0
  250. package/dist/type/typebox-type-live.d.ts +11 -0
  251. package/dist/type/typebox-type-live.js +37 -0
  252. package/dist/type/typebox-type-live.mjs +20 -0
  253. package/dist/type/typebox-type.d.ts +26 -0
  254. package/dist/type/typebox-type.js +135 -0
  255. package/dist/type/typebox-type.mjs +70 -0
  256. package/dist/type/typebox-value-live.d.ts +11 -0
  257. package/dist/type/typebox-value-live.js +31 -0
  258. package/dist/type/typebox-value-live.mjs +13 -0
  259. package/dist/type/typebox-value-ops.d.ts +4 -0
  260. package/dist/type/typebox-value-ops.js +90 -0
  261. package/dist/type/typebox-value-ops.mjs +5 -0
  262. package/dist/type/typebox-value-require.d.ts +8 -0
  263. package/dist/type/typebox-value-require.js +28 -0
  264. package/dist/type/typebox-value-require.mjs +25 -0
  265. package/dist/type/typebox-value.d.ts +35 -0
  266. package/dist/type/typebox-value.js +161 -0
  267. package/dist/type/typebox-value.mjs +74 -0
  268. package/dist/type/utils.js +1 -10
  269. package/dist/type/utils.mjs +1 -10
  270. package/dist/type/validator/clean-safe.d.ts +2 -4
  271. package/dist/type/validator/clean-safe.js +15 -11
  272. package/dist/type/validator/clean-safe.mjs +16 -10
  273. package/dist/type/validator/custom-error.js +12 -16
  274. package/dist/type/validator/custom-error.mjs +11 -14
  275. package/dist/type/validator/default-precompute.d.ts +9 -1
  276. package/dist/type/validator/default-precompute.js +40 -77
  277. package/dist/type/validator/default-precompute.mjs +37 -74
  278. package/dist/type/validator/exact-mirror-live.d.ts +8 -0
  279. package/dist/type/validator/exact-mirror-live.js +22 -0
  280. package/dist/type/validator/exact-mirror-live.mjs +17 -0
  281. package/dist/type/validator/exact-mirror-require.d.ts +4 -0
  282. package/dist/type/validator/exact-mirror-require.js +11 -0
  283. package/dist/type/validator/exact-mirror-require.mjs +9 -0
  284. package/dist/type/validator/exact-mirror.js +8 -8
  285. package/dist/type/validator/exact-mirror.mjs +9 -8
  286. package/dist/type/validator/frozen-check.js +5 -6
  287. package/dist/type/validator/frozen-check.mjs +6 -7
  288. package/dist/type/validator/index.d.ts +1 -0
  289. package/dist/type/validator/index.js +169 -166
  290. package/dist/type/validator/index.mjs +162 -158
  291. package/dist/type/validator/string-codec-aot.d.ts +2 -1
  292. package/dist/type/validator/string-codec-aot.js +8 -2
  293. package/dist/type/validator/string-codec-aot.mjs +7 -2
  294. package/dist/type/validator/validator-cache.d.ts +5 -4
  295. package/dist/type/validator/validator-cache.js +41 -24
  296. package/dist/type/validator/validator-cache.mjs +40 -22
  297. package/dist/types.d.ts +261 -94
  298. package/dist/universal/constants.d.ts +2 -1
  299. package/dist/universal/constants.js +3 -1
  300. package/dist/universal/constants.mjs +2 -1
  301. package/dist/universal/env.js +2 -3
  302. package/dist/universal/env.mjs +2 -3
  303. package/dist/universal/file.d.ts +6 -4
  304. package/dist/universal/file.js +11 -16
  305. package/dist/universal/file.mjs +12 -16
  306. package/dist/universal/index.d.ts +2 -2
  307. package/dist/universal/is-production.d.ts +1 -2
  308. package/dist/universal/is-production.js +1 -3
  309. package/dist/universal/is-production.mjs +2 -3
  310. package/dist/universal/server.d.ts +0 -272
  311. package/dist/utils.d.ts +41 -7
  312. package/dist/utils.js +158 -126
  313. package/dist/utils.mjs +147 -126
  314. package/dist/validator/index.d.ts +1 -1
  315. package/dist/validator/index.js +17 -30
  316. package/dist/validator/index.mjs +18 -31
  317. package/dist/validator/route.js +2 -1
  318. package/dist/validator/route.mjs +2 -1
  319. package/dist/ws/context.d.ts +8 -1
  320. package/dist/ws/context.js +68 -44
  321. package/dist/ws/context.mjs +67 -44
  322. package/dist/ws/parser.js +10 -20
  323. package/dist/ws/parser.mjs +10 -20
  324. package/dist/ws/route.d.ts +2 -2
  325. package/dist/ws/route.js +219 -139
  326. package/dist/ws/route.mjs +223 -143
  327. package/dist/ws/types.d.ts +2 -2
  328. package/package.json +23 -49
  329. package/dist/compile/analysis-cache.d.ts +0 -6
  330. package/dist/compile/analysis-cache.js +0 -12
  331. package/dist/compile/analysis-cache.mjs +0 -11
  332. package/dist/cookie/index.d.ts +0 -7
  333. package/dist/cookie/index.js +0 -13
  334. package/dist/cookie/index.mjs +0 -7
  335. package/dist/handler/index.d.ts +0 -2
  336. package/dist/handler/index.js +0 -5
  337. package/dist/handler/index.mjs +0 -3
package/dist/context.js CHANGED
@@ -1,6 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_utils = require('./utils.js');
3
- const require_universal_is_production = require('./universal/is-production.js');
4
3
  const require_error = require('./error.js');
5
4
  const require_adapter_default_headers = require('./adapter/default-headers.js');
6
5
 
@@ -17,58 +16,45 @@ const defer = {
17
16
  return append;
18
17
  }
19
18
  };
20
- function buildEmptyDecorator() {
19
+ function buildDecorator(members) {
21
20
  class Decorator {}
22
- Object.assign(Decorator.prototype, {
23
- status: require_error.status,
24
- redirect: require_utils.redirect
25
- });
21
+ Object.assign(Decorator.prototype, members);
26
22
  Object.defineProperty(Decorator.prototype, "defer", defer);
27
23
  return Decorator;
28
24
  }
25
+ const buildEmptyDecorator = () => buildDecorator({
26
+ status: require_error.status,
27
+ problem: require_error.problem,
28
+ redirect: require_utils.redirect
29
+ });
29
30
  function createBaseContext(app) {
30
31
  const ext = app["~ext"];
31
32
  const decorator = ext?.decorator;
32
33
  const store = ext?.store;
33
34
  if (!decorator && !store) return sharedEmptyDecorator ??= buildEmptyDecorator();
34
- class Decorator {}
35
- Object.assign(Decorator.prototype, {
35
+ return buildDecorator({
36
36
  ...decorator,
37
37
  store,
38
38
  status: require_error.status,
39
+ problem: require_error.problem,
39
40
  redirect: require_utils.redirect
40
41
  });
41
- Object.defineProperty(Decorator.prototype, "defer", defer);
42
- return Decorator;
43
42
  }
44
- function clearContextCache() {
43
+ function clearContextCache(app) {
44
+ if (app !== void 0) {
45
+ contextCache.delete(app);
46
+ return;
47
+ }
45
48
  contextCache = /* @__PURE__ */ new WeakMap();
46
49
  sharedEmptyDecorator = null;
47
50
  sharedEmptyContext = null;
48
51
  }
49
- const pathValue = Symbol("path");
50
- function buildEmptyContext(Base, headers = null, warnPathMutation = false) {
52
+ function buildEmptyContext(Base, headers = null) {
51
53
  const immutableHeaders = headers !== null && Object.isFrozen(headers);
52
- let warnedPathMutation = false;
53
- const pathDescriptor = warnPathMutation ? {
54
- enumerable: true,
55
- configurable: true,
56
- get() {
57
- return this[pathValue];
58
- },
59
- set(value) {
60
- if (pathValue in this && !warnedPathMutation) {
61
- warnedPathMutation = true;
62
- console.warn("[elysia] context.path is readonly; request-hook rerouting will stop working in a future release.");
63
- }
64
- this[pathValue] = value;
65
- }
66
- } : void 0;
67
54
  class Context extends Base {
68
55
  constructor(request) {
69
56
  super();
70
57
  this.request = request;
71
- if (pathDescriptor) Object.defineProperty(this, "path", pathDescriptor);
72
58
  if (immutableHeaders) this.set = {
73
59
  headers,
74
60
  status: void 0,
@@ -88,7 +74,6 @@ function createContext(app) {
88
74
  if (cached) return cached;
89
75
  const ext = app["~ext"];
90
76
  const adapter = app["~config"]?.adapter;
91
- const warnPathMutation = !require_universal_is_production.isProduction() && !!require_utils.flattenChain(app["~hookChain"])?.request?.length;
92
77
  const headers = ext?.headers && require_utils.isNotEmpty(ext.headers) ? Object.assign(require_utils.nullObject(), ext.headers) : null;
93
78
  if (headers && (!adapter || adapter.response.supportsDefaultHeaderSink)) {
94
79
  Object.defineProperty(headers, "\0", { value: headers });
@@ -96,11 +81,11 @@ function createContext(app) {
96
81
  }
97
82
  if (headers === null && !ext?.decorator && !ext?.store) {
98
83
  sharedEmptyDecorator ??= buildEmptyDecorator();
99
- const context = warnPathMutation ? buildEmptyContext(sharedEmptyDecorator, null, true) : sharedEmptyContext ??= buildEmptyContext(sharedEmptyDecorator);
84
+ const context = sharedEmptyContext ??= buildEmptyContext(sharedEmptyDecorator);
100
85
  contextCache.set(app, context);
101
86
  return context;
102
87
  }
103
- const context = buildEmptyContext(createBaseContext(app), headers, warnPathMutation);
88
+ const context = buildEmptyContext(createBaseContext(app), headers);
104
89
  contextCache.set(app, context);
105
90
  return context;
106
91
  }
package/dist/context.mjs CHANGED
@@ -1,6 +1,5 @@
1
- import { flattenChain, isNotEmpty, nullObject, redirect } from "./utils.mjs";
2
- import { isProduction } from "./universal/is-production.mjs";
3
- import { status } from "./error.mjs";
1
+ import { isNotEmpty, nullObject, redirect } from "./utils.mjs";
2
+ import { problem, status } from "./error.mjs";
4
3
  import { defaultHeaders } from "./adapter/default-headers.mjs";
5
4
 
6
5
  //#region src/context.ts
@@ -16,58 +15,45 @@ const defer = {
16
15
  return append;
17
16
  }
18
17
  };
19
- function buildEmptyDecorator() {
18
+ function buildDecorator(members) {
20
19
  class Decorator {}
21
- Object.assign(Decorator.prototype, {
22
- status,
23
- redirect
24
- });
20
+ Object.assign(Decorator.prototype, members);
25
21
  Object.defineProperty(Decorator.prototype, "defer", defer);
26
22
  return Decorator;
27
23
  }
24
+ const buildEmptyDecorator = () => buildDecorator({
25
+ status,
26
+ problem,
27
+ redirect
28
+ });
28
29
  function createBaseContext(app) {
29
30
  const ext = app["~ext"];
30
31
  const decorator = ext?.decorator;
31
32
  const store = ext?.store;
32
33
  if (!decorator && !store) return sharedEmptyDecorator ??= buildEmptyDecorator();
33
- class Decorator {}
34
- Object.assign(Decorator.prototype, {
34
+ return buildDecorator({
35
35
  ...decorator,
36
36
  store,
37
37
  status,
38
+ problem,
38
39
  redirect
39
40
  });
40
- Object.defineProperty(Decorator.prototype, "defer", defer);
41
- return Decorator;
42
41
  }
43
- function clearContextCache() {
42
+ function clearContextCache(app) {
43
+ if (app !== void 0) {
44
+ contextCache.delete(app);
45
+ return;
46
+ }
44
47
  contextCache = /* @__PURE__ */ new WeakMap();
45
48
  sharedEmptyDecorator = null;
46
49
  sharedEmptyContext = null;
47
50
  }
48
- const pathValue = Symbol("path");
49
- function buildEmptyContext(Base, headers = null, warnPathMutation = false) {
51
+ function buildEmptyContext(Base, headers = null) {
50
52
  const immutableHeaders = headers !== null && Object.isFrozen(headers);
51
- let warnedPathMutation = false;
52
- const pathDescriptor = warnPathMutation ? {
53
- enumerable: true,
54
- configurable: true,
55
- get() {
56
- return this[pathValue];
57
- },
58
- set(value) {
59
- if (pathValue in this && !warnedPathMutation) {
60
- warnedPathMutation = true;
61
- console.warn("[elysia] context.path is readonly; request-hook rerouting will stop working in a future release.");
62
- }
63
- this[pathValue] = value;
64
- }
65
- } : void 0;
66
53
  class Context extends Base {
67
54
  constructor(request) {
68
55
  super();
69
56
  this.request = request;
70
- if (pathDescriptor) Object.defineProperty(this, "path", pathDescriptor);
71
57
  if (immutableHeaders) this.set = {
72
58
  headers,
73
59
  status: void 0,
@@ -87,7 +73,6 @@ function createContext(app) {
87
73
  if (cached) return cached;
88
74
  const ext = app["~ext"];
89
75
  const adapter = app["~config"]?.adapter;
90
- const warnPathMutation = !isProduction() && !!flattenChain(app["~hookChain"])?.request?.length;
91
76
  const headers = ext?.headers && isNotEmpty(ext.headers) ? Object.assign(nullObject(), ext.headers) : null;
92
77
  if (headers && (!adapter || adapter.response.supportsDefaultHeaderSink)) {
93
78
  Object.defineProperty(headers, "\0", { value: headers });
@@ -95,11 +80,11 @@ function createContext(app) {
95
80
  }
96
81
  if (headers === null && !ext?.decorator && !ext?.store) {
97
82
  sharedEmptyDecorator ??= buildEmptyDecorator();
98
- const context = warnPathMutation ? buildEmptyContext(sharedEmptyDecorator, null, true) : sharedEmptyContext ??= buildEmptyContext(sharedEmptyDecorator);
83
+ const context = sharedEmptyContext ??= buildEmptyContext(sharedEmptyDecorator);
99
84
  contextCache.set(app, context);
100
85
  return context;
101
86
  }
102
- const context = buildEmptyContext(createBaseContext(app), headers, warnPathMutation);
87
+ const context = buildEmptyContext(createBaseContext(app), headers);
103
88
  contextCache.set(app, context);
104
89
  return context;
105
90
  }
@@ -18,6 +18,7 @@ interface CompiledCookieConfig {
18
18
  globalSecrets: string | null | (string | null)[] | undefined;
19
19
  hasSign: boolean;
20
20
  verify: 'lazy' | 'eager';
21
+ legacySignature: boolean;
21
22
  }
22
23
  declare function compileCookieConfig(routeSchema: AnySchema | undefined, appConfig: AppCookieConfig | undefined): CompiledCookieConfig;
23
24
  declare function resolveSignSecrets(name: string, config: CompiledCookieConfig): CompiledCookieConfig['globalSecrets'] | undefined;
@@ -25,13 +25,7 @@ function getAttributes(source) {
25
25
  }
26
26
  return out;
27
27
  }
28
- function normalizeSign(sign) {
29
- if (sign === void 0) return;
30
- if (sign === true) return true;
31
- if (Array.isArray(sign)) return sign.length ? sign : void 0;
32
- return [sign];
33
- }
34
- const hasUsableSecret = (secrets) => secrets == null ? false : Array.isArray(secrets) ? secrets.some((s) => s != null) : true;
28
+ const hasUsableSecret = (secrets) => Array.isArray(secrets) ? secrets.some((s) => !!s?.trim()) : !!secrets?.trim();
35
29
  function compileCookieConfig(routeSchema, appConfig) {
36
30
  const routeConfig = routeSchema?.config ?? void 0;
37
31
  const appAttributes = getAttributes(appConfig);
@@ -41,7 +35,12 @@ function compileCookieConfig(routeSchema, appConfig) {
41
35
  ...routeAttributes
42
36
  } : appAttributes ?? routeAttributes ?? require_utils.nullObject();
43
37
  if (!defaults.path) defaults.path = "/";
44
- const globalSign = normalizeSign(routeConfig?.sign ?? appConfig?.sign);
38
+ const rawSign = routeConfig?.sign ?? appConfig?.sign;
39
+ let globalSign;
40
+ if (rawSign === void 0) globalSign = void 0;
41
+ else if (rawSign === true) globalSign = true;
42
+ else if (Array.isArray(rawSign)) globalSign = rawSign.length ? rawSign : void 0;
43
+ else globalSign = [rawSign];
45
44
  const globalSecrets = routeConfig?.secrets !== void 0 ? routeConfig.secrets : appConfig?.secrets;
46
45
  const fields = require_utils.nullObject();
47
46
  const properties = routeSchema?.properties;
@@ -74,7 +73,8 @@ function compileCookieConfig(routeSchema, appConfig) {
74
73
  globalSignSet: Array.isArray(globalSign) ? new Set(globalSign) : void 0,
75
74
  globalSecrets,
76
75
  hasSign,
77
- verify: appConfig?.verify ?? "lazy"
76
+ verify: appConfig?.verify ?? "lazy",
77
+ legacySignature: (routeConfig?.legacySignature ?? appConfig?.legacySignature) !== false
78
78
  };
79
79
  }
80
80
  function resolveSignSecrets(name, config) {
@@ -24,13 +24,7 @@ function getAttributes(source) {
24
24
  }
25
25
  return out;
26
26
  }
27
- function normalizeSign(sign) {
28
- if (sign === void 0) return;
29
- if (sign === true) return true;
30
- if (Array.isArray(sign)) return sign.length ? sign : void 0;
31
- return [sign];
32
- }
33
- const hasUsableSecret = (secrets) => secrets == null ? false : Array.isArray(secrets) ? secrets.some((s) => s != null) : true;
27
+ const hasUsableSecret = (secrets) => Array.isArray(secrets) ? secrets.some((s) => !!s?.trim()) : !!secrets?.trim();
34
28
  function compileCookieConfig(routeSchema, appConfig) {
35
29
  const routeConfig = routeSchema?.config ?? void 0;
36
30
  const appAttributes = getAttributes(appConfig);
@@ -40,7 +34,12 @@ function compileCookieConfig(routeSchema, appConfig) {
40
34
  ...routeAttributes
41
35
  } : appAttributes ?? routeAttributes ?? nullObject();
42
36
  if (!defaults.path) defaults.path = "/";
43
- const globalSign = normalizeSign(routeConfig?.sign ?? appConfig?.sign);
37
+ const rawSign = routeConfig?.sign ?? appConfig?.sign;
38
+ let globalSign;
39
+ if (rawSign === void 0) globalSign = void 0;
40
+ else if (rawSign === true) globalSign = true;
41
+ else if (Array.isArray(rawSign)) globalSign = rawSign.length ? rawSign : void 0;
42
+ else globalSign = [rawSign];
44
43
  const globalSecrets = routeConfig?.secrets !== void 0 ? routeConfig.secrets : appConfig?.secrets;
45
44
  const fields = nullObject();
46
45
  const properties = routeSchema?.properties;
@@ -73,7 +72,8 @@ function compileCookieConfig(routeSchema, appConfig) {
73
72
  globalSignSet: Array.isArray(globalSign) ? new Set(globalSign) : void 0,
74
73
  globalSecrets,
75
74
  hasSign,
76
- verify: appConfig?.verify ?? "lazy"
75
+ verify: appConfig?.verify ?? "lazy",
76
+ legacySignature: (routeConfig?.legacySignature ?? appConfig?.legacySignature) !== false
77
77
  };
78
78
  }
79
79
  function resolveSignSecrets(name, config) {
@@ -10,10 +10,10 @@ declare class Cookie<T = any> implements BaseCookie {
10
10
  constructor(name: string, setRef: {
11
11
  cookie?: Record<string, BaseCookie>;
12
12
  }, initial?: Partial<BaseCookie>);
13
+ static isCookie(v: unknown): v is Cookie;
13
14
  get cookie(): BaseCookie;
14
15
  set cookie(jar: BaseCookie);
15
16
  protected get setCookie(): BaseCookie;
16
- protected set setCookie(jar: BaseCookie);
17
17
  get value(): T;
18
18
  set value(value: T);
19
19
  update(config: Updater<Partial<BaseCookie>>): this;
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_utils = require('../utils.js');
2
3
  const require_cookie_crypto = require('./crypto.js');
3
4
 
4
5
  //#region src/cookie/cookie.ts
@@ -23,6 +24,9 @@ var Cookie = class {
23
24
  this.#setRef = setRef;
24
25
  this.#initial = initial;
25
26
  }
27
+ static isCookie(v) {
28
+ return typeof v === "object" && v !== null && #name in v;
29
+ }
26
30
  get #jar() {
27
31
  return this.#setRef.cookie ??= Object.create(null);
28
32
  }
@@ -41,9 +45,6 @@ var Cookie = class {
41
45
  if (entry && "~unsign" in entry) require_cookie_crypto.resolvePendingCookie(entry, this.#name);
42
46
  return entry;
43
47
  }
44
- set setCookie(jar) {
45
- this.cookie = jar;
46
- }
47
48
  get value() {
48
49
  const cookie = this.cookie;
49
50
  const value = cookie.value;
@@ -56,22 +57,19 @@ var Cookie = class {
56
57
  set value(value) {
57
58
  if (this.cookie.value === value && (!value || typeof value !== "object")) return;
58
59
  const j = this.#jar;
59
- if (!(this.#name in j)) j[this.#name] = { ...this.#initial };
60
+ if (!(this.#name in j)) j[this.#name] = Object.assign(require_utils.nullObject(), this.#initial);
60
61
  j[this.#name].value = value;
61
62
  }
62
63
  update(config) {
63
64
  const cookie = Object.assign(this.cookie, typeof config === "function" ? config(this.cookie) : config);
64
65
  delete cookie["~raw"];
65
- this.setCookie = cookie;
66
+ this.cookie = cookie;
66
67
  return this;
67
68
  }
68
69
  set(config) {
69
- const cookie = Object.assign({
70
- ...this.#initial,
71
- value: this.value
72
- }, typeof config === "function" ? config(this.cookie) : config);
70
+ const cookie = Object.assign(require_utils.nullObject(), this.#initial, { value: this.value }, typeof config === "function" ? config(this.cookie) : config);
73
71
  delete cookie["~raw"];
74
- this.setCookie = cookie;
72
+ this.cookie = cookie;
75
73
  return this;
76
74
  }
77
75
  remove() {
@@ -1,3 +1,4 @@
1
+ import { nullObject } from "../utils.mjs";
1
2
  import { resolvePendingCookie } from "./crypto.mjs";
2
3
 
3
4
  //#region src/cookie/cookie.ts
@@ -22,6 +23,9 @@ var Cookie = class {
22
23
  this.#setRef = setRef;
23
24
  this.#initial = initial;
24
25
  }
26
+ static isCookie(v) {
27
+ return typeof v === "object" && v !== null && #name in v;
28
+ }
25
29
  get #jar() {
26
30
  return this.#setRef.cookie ??= Object.create(null);
27
31
  }
@@ -40,9 +44,6 @@ var Cookie = class {
40
44
  if (entry && "~unsign" in entry) resolvePendingCookie(entry, this.#name);
41
45
  return entry;
42
46
  }
43
- set setCookie(jar) {
44
- this.cookie = jar;
45
- }
46
47
  get value() {
47
48
  const cookie = this.cookie;
48
49
  const value = cookie.value;
@@ -55,22 +56,19 @@ var Cookie = class {
55
56
  set value(value) {
56
57
  if (this.cookie.value === value && (!value || typeof value !== "object")) return;
57
58
  const j = this.#jar;
58
- if (!(this.#name in j)) j[this.#name] = { ...this.#initial };
59
+ if (!(this.#name in j)) j[this.#name] = Object.assign(nullObject(), this.#initial);
59
60
  j[this.#name].value = value;
60
61
  }
61
62
  update(config) {
62
63
  const cookie = Object.assign(this.cookie, typeof config === "function" ? config(this.cookie) : config);
63
64
  delete cookie["~raw"];
64
- this.setCookie = cookie;
65
+ this.cookie = cookie;
65
66
  return this;
66
67
  }
67
68
  set(config) {
68
- const cookie = Object.assign({
69
- ...this.#initial,
70
- value: this.value
71
- }, typeof config === "function" ? config(this.cookie) : config);
69
+ const cookie = Object.assign(nullObject(), this.#initial, { value: this.value }, typeof config === "function" ? config(this.cookie) : config);
72
70
  delete cookie["~raw"];
73
- this.setCookie = cookie;
71
+ this.cookie = cookie;
74
72
  return this;
75
73
  }
76
74
  remove() {
@@ -7,14 +7,15 @@ declare const signCookieSyncImpl: (val: string, secret: string) => string;
7
7
  declare const keyCache: Map<string, Promise<CryptoKey>>;
8
8
  declare function importSecretKey(secret: string): Promise<CryptoKey>;
9
9
  declare function signCookieSubtle(val: string, secret: string): Promise<string>;
10
- declare function signCookie(val: string, secret: string | null): Promise<string>;
11
- declare function signCookieSync(val: string, secret: string | null): string;
12
- declare function unsignCookie(input: string, secret: string | null): Promise<string | false>;
13
- declare function unsignCookieSync(input: string, secret: string | null): string | false;
14
- declare function unsignWithSecretsSync(name: string, value: unknown, secrets: string | null | (string | null)[] | undefined): string;
15
- declare function unsignWithSecrets(name: string, value: unknown, secrets: string | null | (string | null)[] | undefined): Promise<string>;
10
+ declare const deriveSignKey: (secret: string, name: string) => string;
11
+ declare function signCookie(val: string, secret: string | null, name?: string): Promise<string>;
12
+ declare function signCookieSync(val: string, secret: string | null, name?: string): string;
13
+ declare function unsignCookie(input: string, secret: string | null, name?: string): Promise<string | false>;
14
+ declare function unsignCookieSync(input: string, secret: string | null, name?: string): string | false;
15
+ declare function unsignWithSecretsSync(name: string, value: unknown, secrets: string | null | (string | null)[] | undefined, legacy?: boolean): string;
16
+ declare function unsignWithSecrets(name: string, value: unknown, secrets: string | null | (string | null)[] | undefined, legacy?: boolean): Promise<string>;
16
17
  declare const rawJsonValue: WeakMap<object, string>;
17
18
  declare function maybeJsonDecode(value: unknown): any;
18
19
  declare function resolvePendingCookie(entry: Record<string, any>, name: string): void;
19
20
  //#endregion
20
- export { hasSyncHmac, hmacProvider, importSecretKey, keyCache, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieBun, signCookieNode, signCookieSubtle, signCookieSync, signCookieSyncImpl, unsignCookie, unsignCookieSync, unsignWithSecrets, unsignWithSecretsSync };
21
+ export { deriveSignKey, hasSyncHmac, hmacProvider, importSecretKey, keyCache, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieBun, signCookieNode, signCookieSubtle, signCookieSync, signCookieSyncImpl, unsignCookie, unsignCookieSync, unsignWithSecrets, unsignWithSecretsSync };
@@ -10,22 +10,17 @@ const algorithm = {
10
10
  };
11
11
  const encoder = new TextEncoder();
12
12
  let _nodeCrypto;
13
- let _nodeCryptoResolved = false;
14
13
  function nodeCrypto() {
15
- if (!_nodeCryptoResolved) {
16
- _nodeCryptoResolved = true;
17
- try {
18
- _nodeCrypto = globalThis.process?.getBuiltinModule?.("node:crypto");
19
- } catch {}
20
- }
14
+ try {
15
+ _nodeCrypto ??= globalThis.process?.getBuiltinModule?.("node:crypto");
16
+ } catch {}
21
17
  return _nodeCrypto;
22
18
  }
23
- const HMAC_PROBE_DIGEST = "bzs6y9cVmkYub8fplSKaOuuqMqJlDwhMypFT/jSdCEk=";
24
19
  const bunCryptoHasher = (() => {
25
20
  const hasher = globalThis.Bun?.CryptoHasher;
26
- if (typeof hasher !== "function") return void 0;
21
+ if (typeof hasher !== "function" || typeof hasher.prototype?.copy !== "function") return void 0;
27
22
  try {
28
- return new hasher("sha256", "elysia").update("probe").digest("base64") === HMAC_PROBE_DIGEST ? hasher : void 0;
23
+ return new hasher("sha256", "elysia").update("probe").digest("base64") === "bzs6y9cVmkYub8fplSKaOuuqMqJlDwhMypFT/jSdCEk=" ? hasher : void 0;
29
24
  } catch {
30
25
  return;
31
26
  }
@@ -37,7 +32,15 @@ function coerceValue(val) {
37
32
  if (typeof val !== "string") return val + "";
38
33
  return val;
39
34
  }
40
- const signCookieBun = (val, secret) => `${val}.${new bunCryptoHasher("sha256", secret).update(val).digest("base64").replace(removeTrailingEquals, "")}`;
35
+ const bunHasherCache = /* @__PURE__ */ new Map();
36
+ const signCookieBun = (val, secret) => {
37
+ let keyed = bunHasherCache.get(secret);
38
+ if (!keyed) {
39
+ if (bunHasherCache.size >= 256) require_utils.evictOldestHalf(bunHasherCache);
40
+ bunHasherCache.set(secret, keyed = new bunCryptoHasher("sha256", secret));
41
+ }
42
+ return `${val}.${keyed.copy().update(val).digest("base64").replace(removeTrailingEquals, "")}`;
43
+ };
41
44
  const signCookieNode = (val, secret) => `${val}.${nodeCrypto().createHmac("sha256", secret).update(val).digest("base64").replace(removeTrailingEquals, "")}`;
42
45
  const signCookieSyncImpl = hmacProvider === "bun" ? signCookieBun : signCookieNode;
43
46
  const keyCache = /* @__PURE__ */ new Map();
@@ -62,19 +65,22 @@ async function signCookieSubtle(val, secret) {
62
65
  const hmacBuffer = await crypto.subtle.sign("HMAC", await importSecretKey(secret), encoder.encode(val));
63
66
  return `${val}.${btoa(String.fromCharCode(...new Uint8Array(hmacBuffer))).replace(removeTrailingEquals, "")}`;
64
67
  }
65
- async function signCookie(val, secret) {
68
+ const deriveSignKey = (secret, name) => `${name.length}\0${name}${secret}`;
69
+ async function signCookie(val, secret, name) {
66
70
  val = coerceValue(val);
67
- if (secret === null || secret === void 0) throw new TypeError("Secret key must be provided");
71
+ if (!secret?.trim()) throw new TypeError("Secret key must be provided");
72
+ if (name !== void 0) secret = deriveSignKey(secret, name);
68
73
  if (hasSyncHmac) return signCookieSyncImpl(val, secret);
69
74
  return signCookieSubtle(val, secret);
70
75
  }
71
- function signCookieSync(val, secret) {
76
+ function signCookieSync(val, secret, name) {
72
77
  val = coerceValue(val);
73
- if (secret === null || secret === void 0) throw new TypeError("Secret key must be provided");
78
+ if (!secret?.trim()) throw new TypeError("Secret key must be provided");
74
79
  if (!hasSyncHmac) throw new Error("signCookieSync called without a sync HMAC available");
80
+ if (name !== void 0) secret = deriveSignKey(secret, name);
75
81
  return signCookieSyncImpl(val, secret);
76
82
  }
77
- async function unsignCookie(input, secret) {
83
+ async function unsignCookie(input, secret, name) {
78
84
  if (typeof input !== "string") throw new TypeError("Signed cookie string must be provided.");
79
85
  const dot = input.lastIndexOf(".");
80
86
  if (dot === -1) {
@@ -82,10 +88,10 @@ async function unsignCookie(input, secret) {
82
88
  return false;
83
89
  }
84
90
  const tentativeValue = input.slice(0, dot);
85
- if (secret === null) return false;
86
- return require_utils.constantTimeEqual(await signCookie(tentativeValue, secret), input) ? tentativeValue : false;
91
+ if (!secret?.trim()) return false;
92
+ return require_utils.constantTimeEqual(await signCookie(tentativeValue, secret, name), input) ? tentativeValue : false;
87
93
  }
88
- function unsignCookieSync(input, secret) {
94
+ function unsignCookieSync(input, secret, name) {
89
95
  if (typeof input !== "string") throw new TypeError("Signed cookie string must be provided.");
90
96
  const dot = input.lastIndexOf(".");
91
97
  if (dot === -1) {
@@ -93,32 +99,36 @@ function unsignCookieSync(input, secret) {
93
99
  return false;
94
100
  }
95
101
  const tentativeValue = input.slice(0, dot);
96
- if (secret === null) return false;
97
- return require_utils.constantTimeEqual(signCookieSync(tentativeValue, secret), input) ? tentativeValue : false;
102
+ if (!secret?.trim()) return false;
103
+ return require_utils.constantTimeEqual(signCookieSync(tentativeValue, secret, name), input) ? tentativeValue : false;
98
104
  }
99
- function unsignWithSecretsSync(name, value, secrets) {
105
+ function unsignWithSecretsSync(name, value, secrets, legacy) {
100
106
  if (typeof value !== "string") throw require_cookie_error.InvalidCookie.signature(name);
101
- if (typeof secrets === "string") {
102
- const temp = unsignCookieSync(value, secrets);
103
- if (temp === false) throw require_cookie_error.InvalidCookie.signature(name);
104
- return temp;
105
- }
106
- if (Array.isArray(secrets)) for (let i = 0; i < secrets.length; i++) {
107
- const temp = unsignCookieSync(value, secrets[i]);
108
- if (temp !== false) return temp;
107
+ for (let pass = 0; pass < 2; pass++) {
108
+ const bound = pass === 0 ? name : void 0;
109
+ if (typeof secrets === "string") {
110
+ const temp = unsignCookieSync(value, secrets, bound);
111
+ if (temp !== false) return temp;
112
+ } else if (Array.isArray(secrets)) for (let i = 0; i < secrets.length; i++) {
113
+ const temp = unsignCookieSync(value, secrets[i], bound);
114
+ if (temp !== false) return temp;
115
+ }
116
+ if (!legacy) break;
109
117
  }
110
118
  throw require_cookie_error.InvalidCookie.signature(name);
111
119
  }
112
- async function unsignWithSecrets(name, value, secrets) {
120
+ async function unsignWithSecrets(name, value, secrets, legacy) {
113
121
  if (typeof value !== "string") throw require_cookie_error.InvalidCookie.signature(name);
114
- if (typeof secrets === "string") {
115
- const temp = await unsignCookie(value, secrets);
116
- if (temp === false) throw require_cookie_error.InvalidCookie.signature(name);
117
- return temp;
118
- }
119
- if (Array.isArray(secrets)) for (let i = 0; i < secrets.length; i++) {
120
- const temp = await unsignCookie(value, secrets[i]);
121
- if (temp !== false) return temp;
122
+ for (let pass = 0; pass < 2; pass++) {
123
+ const bound = pass === 0 ? name : void 0;
124
+ if (typeof secrets === "string") {
125
+ const temp = await unsignCookie(value, secrets, bound);
126
+ if (temp !== false) return temp;
127
+ } else if (Array.isArray(secrets)) for (let i = 0; i < secrets.length; i++) {
128
+ const temp = await unsignCookie(value, secrets[i], bound);
129
+ if (temp !== false) return temp;
130
+ }
131
+ if (!legacy) break;
122
132
  }
123
133
  throw require_cookie_error.InvalidCookie.signature(name);
124
134
  }
@@ -139,7 +149,7 @@ function resolvePendingCookie(entry, name) {
139
149
  const value = entry.value;
140
150
  if (typeof value !== "string") throw require_cookie_error.InvalidCookie.signature(name);
141
151
  if (!hasSyncHmac) throw new Error(`resolvePendingCookie called without sync HMAC. Unreachable under correct lane gating (cookie: "${name}")`);
142
- const resolvedValue = maybeJsonDecode(unsignWithSecretsSync(name, value, entry["~unsign"]));
152
+ const resolvedValue = maybeJsonDecode(unsignWithSecretsSync(name, value, entry["~unsign"], !entry["~strict"]));
143
153
  entry.value = resolvedValue;
144
154
  if (resolvedValue !== null && typeof resolvedValue === "object") {
145
155
  const raw = rawJsonValue.get(resolvedValue);
@@ -149,6 +159,7 @@ function resolvePendingCookie(entry, name) {
149
159
  }
150
160
 
151
161
  //#endregion
162
+ exports.deriveSignKey = deriveSignKey;
152
163
  exports.hasSyncHmac = hasSyncHmac;
153
164
  exports.hmacProvider = hmacProvider;
154
165
  exports.importSecretKey = importSecretKey;