elysia 2.0.0-beta.2 → 2.0.0-beta.4

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 (175) hide show
  1. package/dist/adapter/bun/index.d.ts +1 -1
  2. package/dist/adapter/bun/index.js +320 -56
  3. package/dist/adapter/bun/index.mjs +321 -57
  4. package/dist/adapter/utils.js +51 -30
  5. package/dist/adapter/utils.mjs +52 -31
  6. package/dist/adapter/web-standard/handler.js +5 -2
  7. package/dist/adapter/web-standard/handler.mjs +5 -2
  8. package/dist/base.d.ts +18 -7
  9. package/dist/base.js +213 -101
  10. package/dist/base.mjs +215 -103
  11. package/dist/compile/aot-capture.js +1 -1
  12. package/dist/compile/aot-capture.mjs +1 -1
  13. package/dist/compile/aot.d.ts +5 -4
  14. package/dist/compile/aot.js +17 -9
  15. package/dist/compile/aot.mjs +18 -9
  16. package/dist/compile/handler/descriptor.js +1 -1
  17. package/dist/compile/handler/descriptor.mjs +1 -1
  18. package/dist/compile/handler/frozen-validator.d.ts +4 -1
  19. package/dist/compile/handler/frozen-validator.js +8 -3
  20. package/dist/compile/handler/frozen-validator.mjs +5 -3
  21. package/dist/compile/handler/index.d.ts +2 -2
  22. package/dist/compile/handler/index.js +8 -6
  23. package/dist/compile/handler/index.mjs +8 -6
  24. package/dist/compile/handler/reconstruct.d.ts +1 -1
  25. package/dist/compile/handler/reconstruct.js +4 -3
  26. package/dist/compile/handler/reconstruct.mjs +4 -3
  27. package/dist/compile/handler/utils.js +2 -2
  28. package/dist/compile/handler/utils.mjs +3 -3
  29. package/dist/compile/jit-probe.d.ts +2 -2
  30. package/dist/context.d.ts +1 -1
  31. package/dist/context.js +8 -5
  32. package/dist/context.mjs +8 -5
  33. package/dist/cookie/config.d.ts +1 -0
  34. package/dist/cookie/config.js +3 -2
  35. package/dist/cookie/config.mjs +3 -2
  36. package/dist/cookie/cookie.d.ts +1 -0
  37. package/dist/cookie/cookie.js +6 -5
  38. package/dist/cookie/cookie.mjs +6 -5
  39. package/dist/cookie/crypto.d.ts +8 -7
  40. package/dist/cookie/crypto.js +38 -31
  41. package/dist/cookie/crypto.mjs +38 -32
  42. package/dist/cookie/error.js +1 -2
  43. package/dist/cookie/error.mjs +1 -2
  44. package/dist/cookie/lib.js +5 -1
  45. package/dist/cookie/lib.mjs +5 -1
  46. package/dist/cookie/serialize.js +1 -1
  47. package/dist/cookie/serialize.mjs +1 -1
  48. package/dist/cookie/types.d.ts +10 -0
  49. package/dist/cookie/utils.js +28 -14
  50. package/dist/cookie/utils.mjs +29 -15
  51. package/dist/handler/error.d.ts +23 -12
  52. package/dist/handler/error.js +24 -21
  53. package/dist/handler/error.mjs +20 -21
  54. package/dist/handler/fetch.js +6 -7
  55. package/dist/handler/fetch.mjs +7 -8
  56. package/dist/handler/utils.js +4 -2
  57. package/dist/handler/utils.mjs +5 -3
  58. package/dist/index.js +1 -8
  59. package/dist/package.js +1 -1
  60. package/dist/package.mjs +1 -1
  61. package/dist/plugin/aot/core.d.ts +33 -6
  62. package/dist/plugin/aot/core.js +120 -40
  63. package/dist/plugin/aot/core.mjs +121 -43
  64. package/dist/plugin/aot/esbuild.js +8 -2
  65. package/dist/plugin/aot/esbuild.mjs +9 -3
  66. package/dist/plugin/aot/hooks.d.ts +2 -1
  67. package/dist/plugin/aot/hooks.js +3 -3
  68. package/dist/plugin/aot/hooks.mjs +4 -4
  69. package/dist/plugin/aot/source.d.ts +4 -1
  70. package/dist/plugin/aot/source.js +21 -14
  71. package/dist/plugin/aot/source.mjs +21 -14
  72. package/dist/plugin/aot/worker.js +2 -2
  73. package/dist/plugin/aot/worker.mjs +2 -2
  74. package/dist/route-table.d.ts +3 -0
  75. package/dist/route-table.js +16 -11
  76. package/dist/route-table.mjs +16 -11
  77. package/dist/schema-snapshot.js +17 -22
  78. package/dist/schema-snapshot.mjs +17 -22
  79. package/dist/type/bridge-live.d.ts +1 -1
  80. package/dist/type/bridge-live.js +2 -2
  81. package/dist/type/bridge-live.mjs +2 -2
  82. package/dist/type/bridge.d.ts +1 -1
  83. package/dist/type/coerce-plan.js +3 -4
  84. package/dist/type/coerce-plan.mjs +1 -1
  85. package/dist/type/coerce.d.ts +1 -1
  86. package/dist/type/compat.d.ts +3 -0
  87. package/dist/type/compat.js +32 -14
  88. package/dist/type/compat.mjs +27 -8
  89. package/dist/type/constants.d.ts +1 -1
  90. package/dist/type/elysia/array-buffer.js +2 -3
  91. package/dist/type/elysia/array-buffer.mjs +1 -1
  92. package/dist/type/elysia/array-string.js +7 -4
  93. package/dist/type/elysia/array-string.mjs +9 -5
  94. package/dist/type/elysia/boolean-string.js +2 -3
  95. package/dist/type/elysia/boolean-string.mjs +1 -1
  96. package/dist/type/elysia/boolean.js +4 -3
  97. package/dist/type/elysia/boolean.mjs +4 -2
  98. package/dist/type/elysia/cookie.js +2 -1
  99. package/dist/type/elysia/cookie.mjs +2 -1
  100. package/dist/type/elysia/date.js +7 -7
  101. package/dist/type/elysia/date.mjs +3 -2
  102. package/dist/type/elysia/file-type.d.ts +9 -2
  103. package/dist/type/elysia/file-type.js +16 -1
  104. package/dist/type/elysia/file-type.mjs +16 -2
  105. package/dist/type/elysia/file.js +8 -4
  106. package/dist/type/elysia/file.mjs +8 -3
  107. package/dist/type/elysia/files.js +6 -4
  108. package/dist/type/elysia/files.mjs +5 -2
  109. package/dist/type/elysia/form.js +2 -3
  110. package/dist/type/elysia/form.mjs +3 -3
  111. package/dist/type/elysia/integer-string.js +4 -5
  112. package/dist/type/elysia/integer-string.mjs +3 -3
  113. package/dist/type/elysia/integer.js +4 -3
  114. package/dist/type/elysia/integer.mjs +4 -2
  115. package/dist/type/elysia/maybe-empty.js +3 -4
  116. package/dist/type/elysia/maybe-empty.mjs +1 -1
  117. package/dist/type/elysia/nullable.js +2 -3
  118. package/dist/type/elysia/nullable.mjs +1 -1
  119. package/dist/type/elysia/number.js +4 -3
  120. package/dist/type/elysia/number.mjs +4 -2
  121. package/dist/type/elysia/numeric-enum.js +2 -3
  122. package/dist/type/elysia/numeric-enum.mjs +1 -1
  123. package/dist/type/elysia/numeric.js +5 -5
  124. package/dist/type/elysia/numeric.mjs +3 -2
  125. package/dist/type/elysia/object-string.js +7 -4
  126. package/dist/type/elysia/object-string.mjs +9 -5
  127. package/dist/type/elysia/string.js +4 -3
  128. package/dist/type/elysia/string.mjs +4 -2
  129. package/dist/type/elysia/uint8-array.js +2 -3
  130. package/dist/type/elysia/uint8-array.mjs +1 -1
  131. package/dist/type/elysia/union-enum.js +2 -3
  132. package/dist/type/elysia/union-enum.mjs +1 -1
  133. package/dist/type/elysia/utils.js +2 -3
  134. package/dist/type/elysia/utils.mjs +1 -1
  135. package/dist/type/exports.js +10 -1
  136. package/dist/type/exports.mjs +7 -0
  137. package/dist/type/index.d.ts +9 -1
  138. package/dist/type/index.js +41 -13
  139. package/dist/type/index.mjs +44 -9
  140. package/dist/type/typebox-type-live.d.ts +9 -0
  141. package/dist/type/typebox-type-live.js +31 -0
  142. package/dist/type/typebox-type-live.mjs +16 -0
  143. package/dist/type/typebox-type.d.ts +24 -0
  144. package/dist/type/typebox-type.js +130 -0
  145. package/dist/type/typebox-type.mjs +66 -0
  146. package/dist/type/typebox-value-live.d.ts +9 -0
  147. package/dist/type/typebox-value-live.js +27 -0
  148. package/dist/type/typebox-value-live.mjs +11 -0
  149. package/dist/type/typebox-value.d.ts +30 -0
  150. package/dist/type/typebox-value.js +147 -0
  151. package/dist/type/typebox-value.mjs +62 -0
  152. package/dist/type/validator/custom-error.js +4 -5
  153. package/dist/type/validator/custom-error.mjs +3 -3
  154. package/dist/type/validator/default-precompute.js +4 -5
  155. package/dist/type/validator/default-precompute.mjs +1 -1
  156. package/dist/type/validator/index.d.ts +1 -1
  157. package/dist/type/validator/index.js +51 -42
  158. package/dist/type/validator/index.mjs +33 -23
  159. package/dist/type/validator/validator-cache.d.ts +1 -1
  160. package/dist/type/validator/validator-cache.js +27 -14
  161. package/dist/type/validator/validator-cache.mjs +27 -13
  162. package/dist/universal/constants.d.ts +2 -1
  163. package/dist/universal/constants.js +3 -1
  164. package/dist/universal/constants.mjs +2 -1
  165. package/dist/utils.d.ts +19 -1
  166. package/dist/utils.js +25 -3
  167. package/dist/utils.mjs +19 -3
  168. package/dist/validator/index.js +2 -1
  169. package/dist/validator/index.mjs +2 -1
  170. package/dist/ws/context.d.ts +8 -1
  171. package/dist/ws/context.js +65 -29
  172. package/dist/ws/context.mjs +64 -29
  173. package/dist/ws/route.js +176 -28
  174. package/dist/ws/route.mjs +179 -31
  175. package/package.json +5 -3
@@ -5,11 +5,8 @@ import { version } from "../package.mjs";
5
5
  //#region src/compile/aot.ts
6
6
  const AOT_MANIFEST_FORMAT = 3;
7
7
  const AOT_ABI = `${version}:${3}`;
8
- const createProgramId = () => ({});
9
8
  const sharedAotFingerprint = Object.freeze({ abi: AOT_ABI });
10
- function createAotFingerprint() {
11
- return sharedAotFingerprint;
12
- }
9
+ const createAotFingerprint = () => sharedAotFingerprint;
13
10
  let activeSession;
14
11
  const newCompilerSession = () => ({ sucroseCache: /* @__PURE__ */ new Map() });
15
12
  function beginCompilerSession(app) {
@@ -40,7 +37,12 @@ function reconstruct() {
40
37
  return reconstructImpl;
41
38
  }
42
39
  let registered;
43
- let claimed = false;
40
+ /**
41
+ * App that consumed this process's manifest, held weakly: it only has to
42
+ * recognise a re-claim by the *same* app, and `assertUncontested` always
43
+ * compares against a live id, so a cleared ref answers as a strong one would
44
+ */
45
+ let claimed;
44
46
  let programs = /* @__PURE__ */ new WeakMap();
45
47
  const programFor = (id) => id ? programs.get(id) : void 0;
46
48
  const fingerprintMismatch = (manifest, actual) => {
@@ -53,14 +55,14 @@ const fingerprintMismatch = (manifest, actual) => {
53
55
  var Compiled = class {
54
56
  static register(manifest) {
55
57
  registered = manifest;
56
- claimed = false;
58
+ claimed = void 0;
57
59
  }
58
60
  static claim(id, fingerprint) {
59
61
  if (!registered || claimed) return false;
60
62
  const manifest = registered;
61
63
  const differences = fingerprintMismatch(manifest, fingerprint);
62
64
  if (differences.length) throw new Error(`[elysia-aot] Registered manifest fingerprint mismatch: ${differences.join("; ")}.`);
63
- claimed = true;
65
+ claimed = new WeakRef(id);
64
66
  registered = void 0;
65
67
  programs.set(id, {
66
68
  ...manifest,
@@ -68,6 +70,10 @@ var Compiled = class {
68
70
  });
69
71
  return true;
70
72
  }
73
+ static assertUncontested(id) {
74
+ if (claimed === void 0 || claimed.deref() === id || isAotBuildEnv()) return;
75
+ throw new Error("[elysia-aot] A second Elysia app built a router in this process. An AOT build seals one app per process.");
76
+ }
71
77
  static get reconstruct() {
72
78
  return reconstructImpl;
73
79
  }
@@ -77,6 +83,9 @@ var Compiled = class {
77
83
  static getHandler(id, method, path) {
78
84
  return programFor(id)?.handlers?.[method]?.[path];
79
85
  }
86
+ static hasProgram(id) {
87
+ return programFor(id) !== void 0;
88
+ }
80
89
  static getValidator(method, path, slot, id) {
81
90
  const program = programFor(id);
82
91
  if (!program) return void 0;
@@ -115,7 +124,7 @@ var Compiled = class {
115
124
  /** @internal test isolation */
116
125
  static clear() {
117
126
  registered = void 0;
118
- claimed = false;
127
+ claimed = void 0;
119
128
  programs = /* @__PURE__ */ new WeakMap();
120
129
  }
121
130
  };
@@ -197,4 +206,4 @@ function setCaptureImpl(impl) {
197
206
  }
198
207
 
199
208
  //#endregion
200
- export { AOT_ABI, AOT_MANIFEST_FORMAT, Capture, Compiled, CompilerState, EMPTY_EXTERNALS, aotActivationError, beginCompilerSession, captureImpl, createAotFingerprint, createProgramId, endCompilerSession, getCompilerSession, reconstruct, setCaptureImpl };
209
+ export { AOT_ABI, AOT_MANIFEST_FORMAT, Capture, Compiled, CompilerState, EMPTY_EXTERNALS, aotActivationError, beginCompilerSession, captureImpl, createAotFingerprint, endCompilerSession, getCompilerSession, reconstruct, setCaptureImpl };
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_utils = require('../../utils.js');
3
+ const require_cookie_crypto = require('../../cookie/crypto.js');
3
4
  const require_compile_aot = require('../aot.js');
4
5
  const require_generation = require('../../generation.js');
5
- const require_cookie_crypto = require('../../cookie/crypto.js');
6
6
  const require_cookie_config = require('../../cookie/config.js');
7
7
  const require_compile_utils = require('../utils.js');
8
8
  const require_compile_jit_probe = require('../jit-probe.js');
@@ -1,7 +1,7 @@
1
1
  import { isNotEmpty } from "../../utils.mjs";
2
+ import { hasSyncHmac } from "../../cookie/crypto.mjs";
2
3
  import { Capture } from "../aot.mjs";
3
4
  import { frozenRootOf, resolvedTraceOf, traceCapabilityRequired } from "../../generation.mjs";
4
- import { hasSyncHmac } from "../../cookie/crypto.mjs";
5
5
  import { compileCookieConfig } from "../../cookie/config.mjs";
6
6
  import { isAsyncFunction, isAsyncLifecycle, mayReturnPromise } from "../utils.mjs";
7
7
  import { JITProbe } from "../jit-probe.mjs";
@@ -32,9 +32,12 @@ interface FrozenRouteValidatorShape {
32
32
  cookie?: FrozenSlotValidator;
33
33
  response?: Record<number, FrozenSlotValidator>;
34
34
  }
35
+ declare const REQUEST_SLOTS: readonly ["body", "headers", "query", "params", "cookie"];
35
36
  declare const isStandardSchema: (schema: unknown) => schema is object & Record<"~standard", unknown>;
36
37
  declare function mergeSchemasAllStandard(schemas: Array<Record<string, unknown>> | undefined): boolean;
38
+ declare function resolveModelRef(schema: unknown, root: AnyElysia): unknown;
37
39
  declare function buildFrozenRouteValidator(hook: AnyLocalHook, root: AnyElysia, method: HTTPMethod, path: string): FrozenRouteValidatorShape | undefined;
40
+ declare const isResponseMap: (schema: unknown) => schema is Record<string, unknown>;
38
41
  declare function isCapturedBridgeFree(c: CapturedValidator, schema: unknown, coerced?: unknown): boolean;
39
42
  //#endregion
40
- export { buildFrozenRouteValidator, isBridgeNotInitialized, isCapturedBridgeFree, isCompactDiagnosable, isCompactWalkable, isStandardSchema, mergeSchemasAllStandard };
43
+ export { REQUEST_SLOTS, buildFrozenRouteValidator, isBridgeNotInitialized, isCapturedBridgeFree, isCompactDiagnosable, isCompactWalkable, isResponseMap, isStandardSchema, mergeSchemasAllStandard, resolveModelRef };
@@ -294,7 +294,9 @@ function buildFrozenRouteValidator(hook, root, method, path) {
294
294
  }
295
295
  const response = hook?.response;
296
296
  if (response) {
297
- const statuses = isResponseMap(response) ? response : { 200: response };
297
+ const resolved = resolveModelRef(response, root);
298
+ if (!resolved) return void 0;
299
+ const statuses = isResponseMap(resolved) ? resolved : { 200: resolved };
298
300
  const responseOut = {};
299
301
  for (const status in statuses) {
300
302
  const raw = statuses[status];
@@ -313,7 +315,7 @@ function buildFrozenRouteValidator(hook, root, method, path) {
313
315
  }
314
316
  return out;
315
317
  }
316
- const isResponseMap = (schema) => !("~kind" in schema || "~elyAcl" in schema || "~standard" in schema);
318
+ const isResponseMap = (schema) => schema !== null && typeof schema === "object" && !("~kind" in schema || "~elyAcl" in schema || "~standard" in schema);
317
319
  const capturedBothMarker = (() => ({}));
318
320
  function isCapturedBridgeFree(c, schema, coerced = schema) {
319
321
  if (typeof schema === "string") return false;
@@ -340,10 +342,13 @@ function isCapturedBridgeFree(c, schema, coerced = schema) {
340
342
  }
341
343
 
342
344
  //#endregion
345
+ exports.REQUEST_SLOTS = REQUEST_SLOTS;
343
346
  exports.buildFrozenRouteValidator = buildFrozenRouteValidator;
344
347
  exports.isBridgeNotInitialized = isBridgeNotInitialized;
345
348
  exports.isCapturedBridgeFree = isCapturedBridgeFree;
346
349
  exports.isCompactDiagnosable = isCompactDiagnosable;
347
350
  exports.isCompactWalkable = isCompactWalkable;
351
+ exports.isResponseMap = isResponseMap;
348
352
  exports.isStandardSchema = isStandardSchema;
349
- exports.mergeSchemasAllStandard = mergeSchemasAllStandard;
353
+ exports.mergeSchemasAllStandard = mergeSchemasAllStandard;
354
+ exports.resolveModelRef = resolveModelRef;
@@ -293,7 +293,9 @@ function buildFrozenRouteValidator(hook, root, method, path) {
293
293
  }
294
294
  const response = hook?.response;
295
295
  if (response) {
296
- const statuses = isResponseMap(response) ? response : { 200: response };
296
+ const resolved = resolveModelRef(response, root);
297
+ if (!resolved) return void 0;
298
+ const statuses = isResponseMap(resolved) ? resolved : { 200: resolved };
297
299
  const responseOut = {};
298
300
  for (const status in statuses) {
299
301
  const raw = statuses[status];
@@ -312,7 +314,7 @@ function buildFrozenRouteValidator(hook, root, method, path) {
312
314
  }
313
315
  return out;
314
316
  }
315
- const isResponseMap = (schema) => !("~kind" in schema || "~elyAcl" in schema || "~standard" in schema);
317
+ const isResponseMap = (schema) => schema !== null && typeof schema === "object" && !("~kind" in schema || "~elyAcl" in schema || "~standard" in schema);
316
318
  const capturedBothMarker = (() => ({}));
317
319
  function isCapturedBridgeFree(c, schema, coerced = schema) {
318
320
  if (typeof schema === "string") return false;
@@ -339,4 +341,4 @@ function isCapturedBridgeFree(c, schema, coerced = schema) {
339
341
  }
340
342
 
341
343
  //#endregion
342
- export { buildFrozenRouteValidator, isBridgeNotInitialized, isCapturedBridgeFree, isCompactDiagnosable, isCompactWalkable, isStandardSchema, mergeSchemasAllStandard };
344
+ export { REQUEST_SLOTS, buildFrozenRouteValidator, isBridgeNotInitialized, isCapturedBridgeFree, isCompactDiagnosable, isCompactWalkable, isResponseMap, isStandardSchema, mergeSchemasAllStandard, resolveModelRef };
@@ -12,8 +12,8 @@ declare function resolveWSLocalHook(scope: AnyElysia, hook: Partial<AnyLocalHook
12
12
  */
13
13
  declare function clearHandlerAnalysisCaches(root: AnyElysia): void;
14
14
  declare const localMacroRoot: (instance: AnyElysia, root: AnyElysia) => AnyElysia;
15
- declare function buildNativeStaticResponse([,, handler, instance, localHook, appHook, inheritedChain, macroScope]: InternalRoute, root: AnyElysia): Response | undefined;
15
+ declare function buildNativeStaticResponse(route: InternalRoute, root: AnyElysia): Response | undefined;
16
16
  declare function composeRouteHook(instance: AnyElysia, localHook: Partial<AnyLocalHook> | undefined, appHook: ChainNode | undefined, inheritedChain: ChainNode | undefined, root: AnyElysia, macroScope?: AnyElysia): AnyLocalHook | undefined;
17
- declare function compileHandler([_method, path, handler, instance, localHook, appHook, inheritedChain, macroScope]: InternalRoute, root: AnyElysia, precomputedStatic?: Response): CompiledHandler;
17
+ declare function compileHandler(route: InternalRoute, root: AnyElysia, precomputedStatic?: Response, liveOnly?: boolean): CompiledHandler;
18
18
  //#endregion
19
19
  export { buildNativeStaticResponse, clearHandlerAnalysisCaches, compileHandler, composeRouteHook, localMacroRoot, resolveLocalHook, resolveWSLocalHook, setCaptureHeaderShorthand };
@@ -198,10 +198,10 @@ function resolveChainNode(root, node) {
198
198
  }
199
199
  return resolved;
200
200
  }
201
- const chainResolver = (root) => {
201
+ function chainResolver(root) {
202
202
  const frozenRoot = require_generation.frozenRootOf(root);
203
203
  return frozenRoot["~ext"]?.macro || frozenRoot["~scopeChildren"] ? (node) => resolveChainNode(root, node) : void 0;
204
- };
204
+ }
205
205
  const localMacroRoot = (instance, root) => instance !== root && instance["~scopeChild"] === true && require_generation.frozenRootOf(instance)["~ext"]?.macro ? instance : root;
206
206
  function composeRootHook(root, inheritedChain) {
207
207
  const resolve = chainResolver(root);
@@ -211,7 +211,8 @@ function composeRootHook(root, inheritedChain) {
211
211
  if (!locals) return inherited;
212
212
  return require_utils.mergeHook(inherited, locals);
213
213
  }
214
- function buildNativeStaticResponse([, , handler, instance, localHook, appHook, inheritedChain, macroScope], root) {
214
+ function buildNativeStaticResponse(route, root) {
215
+ const [, , handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
215
216
  if (typeof handler === "function" || handler instanceof Error || handler instanceof Promise) return;
216
217
  const frozenRoot = require_generation.frozenRootOf(root);
217
218
  const adapter = frozenRoot["~config"]?.adapter ?? require_adapter_constants.defaultAdapter;
@@ -273,13 +274,14 @@ function isContextFreeHandler(handler) {
273
274
  const source = Function.prototype.toString.call(handler);
274
275
  return isBareArrow.test(source) && !isSucroseOpaque.test(source);
275
276
  }
276
- function compileHandler([_method, path, handler, instance, localHook, appHook, inheritedChain, macroScope], root, precomputedStatic) {
277
+ function compileHandler(route, root, precomputedStatic, liveOnly = false) {
278
+ let [_method, path, handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
277
279
  const frozenRoot = require_generation.frozenRootOf(root);
278
280
  const adapter = frozenRoot["~config"]?.adapter ?? require_adapter_constants.defaultAdapter;
279
281
  const method = _method;
280
282
  const mountMeta = typeof handler === "function" ? handler["~mount"] : void 0;
281
283
  if (mountMeta) handler = resolveMountHandler(mountMeta, path);
282
- const reconstructed = require_compile_aot.Compiled.getHandler(frozenRoot["~programId"], method, path);
284
+ const reconstructed = liveOnly ? void 0 : require_compile_aot.Compiled.getHandler(frozenRoot["~programId"], method, path);
283
285
  if (reconstructed && !precomputedStatic && typeof handler === "function" && !frozenRoot["~ext"]?.macro && !require_generation.frozenRootOf(localMacroRoot(macroScope ?? instance, root))["~ext"]?.macro && !reconstructNeedsHookState(reconstructed.a)) return reconstructed.f(handler, ...require_compile_handler_params.resolveHandlerParams(reconstructed.a, {
284
286
  root,
285
287
  parse: adapter.parse,
@@ -300,7 +302,7 @@ function compileHandler([_method, path, handler, instance, localHook, appHook, i
300
302
  toArray("afterResponse", hook);
301
303
  toArray("error", hook);
302
304
  }
303
- const buildValidator = () => hook ? require_compile_handler_reconstruct.Reconstrct.validator(hook, root, method, path) : void 0;
305
+ const buildValidator = () => hook ? require_compile_handler_reconstruct.Reconstrct.validator(hook, root, method, path, liveOnly) : void 0;
304
306
  if (handler instanceof Error) {
305
307
  const error = handler;
306
308
  handler = () => {
@@ -197,10 +197,10 @@ function resolveChainNode(root, node) {
197
197
  }
198
198
  return resolved;
199
199
  }
200
- const chainResolver = (root) => {
200
+ function chainResolver(root) {
201
201
  const frozenRoot = frozenRootOf(root);
202
202
  return frozenRoot["~ext"]?.macro || frozenRoot["~scopeChildren"] ? (node) => resolveChainNode(root, node) : void 0;
203
- };
203
+ }
204
204
  const localMacroRoot = (instance, root) => instance !== root && instance["~scopeChild"] === true && frozenRootOf(instance)["~ext"]?.macro ? instance : root;
205
205
  function composeRootHook(root, inheritedChain) {
206
206
  const resolve = chainResolver(root);
@@ -210,7 +210,8 @@ function composeRootHook(root, inheritedChain) {
210
210
  if (!locals) return inherited;
211
211
  return mergeHook(inherited, locals);
212
212
  }
213
- function buildNativeStaticResponse([, , handler, instance, localHook, appHook, inheritedChain, macroScope], root) {
213
+ function buildNativeStaticResponse(route, root) {
214
+ const [, , handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
214
215
  if (typeof handler === "function" || handler instanceof Error || handler instanceof Promise) return;
215
216
  const frozenRoot = frozenRootOf(root);
216
217
  const adapter = frozenRoot["~config"]?.adapter ?? defaultAdapter;
@@ -272,13 +273,14 @@ function isContextFreeHandler(handler) {
272
273
  const source = Function.prototype.toString.call(handler);
273
274
  return isBareArrow.test(source) && !isSucroseOpaque.test(source);
274
275
  }
275
- function compileHandler([_method, path, handler, instance, localHook, appHook, inheritedChain, macroScope], root, precomputedStatic) {
276
+ function compileHandler(route, root, precomputedStatic, liveOnly = false) {
277
+ let [_method, path, handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
276
278
  const frozenRoot = frozenRootOf(root);
277
279
  const adapter = frozenRoot["~config"]?.adapter ?? defaultAdapter;
278
280
  const method = _method;
279
281
  const mountMeta = typeof handler === "function" ? handler["~mount"] : void 0;
280
282
  if (mountMeta) handler = resolveMountHandler(mountMeta, path);
281
- const reconstructed = Compiled.getHandler(frozenRoot["~programId"], method, path);
283
+ const reconstructed = liveOnly ? void 0 : Compiled.getHandler(frozenRoot["~programId"], method, path);
282
284
  if (reconstructed && !precomputedStatic && typeof handler === "function" && !frozenRoot["~ext"]?.macro && !frozenRootOf(localMacroRoot(macroScope ?? instance, root))["~ext"]?.macro && !reconstructNeedsHookState(reconstructed.a)) return reconstructed.f(handler, ...resolveHandlerParams(reconstructed.a, {
283
285
  root,
284
286
  parse: adapter.parse,
@@ -299,7 +301,7 @@ function compileHandler([_method, path, handler, instance, localHook, appHook, i
299
301
  toArray("afterResponse", hook);
300
302
  toArray("error", hook);
301
303
  }
302
- const buildValidator = () => hook ? Reconstrct.validator(hook, root, method, path) : void 0;
304
+ const buildValidator = () => hook ? Reconstrct.validator(hook, root, method, path, liveOnly) : void 0;
303
305
  if (handler instanceof Error) {
304
306
  const error = handler;
305
307
  handler = () => {
@@ -4,7 +4,7 @@ import { AnyElysia } from "../../base.js";
4
4
 
5
5
  //#region src/compile/handler/reconstruct.d.ts
6
6
  declare abstract class Reconstrct {
7
- static validator(hook: AnyLocalHook, root: AnyElysia, method: HTTPMethod, path: string): any;
7
+ static validator(hook: AnyLocalHook, root: AnyElysia, method: HTTPMethod, path: string, liveOnly?: boolean): any;
8
8
  static cookie(hook: AnyLocalHook, root: AnyElysia): CompiledCookieConfig;
9
9
  static trace(hook: AnyLocalHook, root: AnyElysia): any;
10
10
  }
@@ -7,9 +7,9 @@ const require_compile_handler_frozen_validator = require('./frozen-validator.js'
7
7
 
8
8
  //#region src/compile/handler/reconstruct.ts
9
9
  var Reconstrct = class {
10
- static validator(hook, root, method, path) {
10
+ static validator(hook, root, method, path, liveOnly = false) {
11
11
  const frozenRoot = require_generation.frozenRootOf(root);
12
- if (!require_type_bridge.isBridgeLive()) {
12
+ if (!liveOnly && !require_type_bridge.isBridgeLive()) {
13
13
  const frozen = require_compile_handler_frozen_validator.buildFrozenRouteValidator(hook, root, method, path);
14
14
  if (frozen) return frozen;
15
15
  }
@@ -20,7 +20,7 @@ var Reconstrct = class {
20
20
  normalize: frozenRoot["~config"]?.normalize,
21
21
  sanitize: frozenRoot["~config"]?.sanitize,
22
22
  schemas: hook?.schemas,
23
- aot: {
23
+ aot: liveOnly ? void 0 : {
24
24
  method,
25
25
  path
26
26
  },
@@ -28,6 +28,7 @@ var Reconstrct = class {
28
28
  });
29
29
  } catch (error) {
30
30
  if (!require_compile_handler_frozen_validator.isBridgeNotInitialized(error)) throw error;
31
+ if (liveOnly) throw new Error("Duplicate route must compile JIT but the TypeBox bridge is not initialized", { cause: error });
31
32
  const frozen = require_compile_handler_frozen_validator.buildFrozenRouteValidator(hook, root, method, path);
32
33
  if (frozen) return frozen;
33
34
  throw error;
@@ -6,9 +6,9 @@ import { buildFrozenRouteValidator, isBridgeNotInitialized } from "./frozen-vali
6
6
 
7
7
  //#region src/compile/handler/reconstruct.ts
8
8
  var Reconstrct = class {
9
- static validator(hook, root, method, path) {
9
+ static validator(hook, root, method, path, liveOnly = false) {
10
10
  const frozenRoot = frozenRootOf(root);
11
- if (!isBridgeLive()) {
11
+ if (!liveOnly && !isBridgeLive()) {
12
12
  const frozen = buildFrozenRouteValidator(hook, root, method, path);
13
13
  if (frozen) return frozen;
14
14
  }
@@ -19,7 +19,7 @@ var Reconstrct = class {
19
19
  normalize: frozenRoot["~config"]?.normalize,
20
20
  sanitize: frozenRoot["~config"]?.sanitize,
21
21
  schemas: hook?.schemas,
22
- aot: {
22
+ aot: liveOnly ? void 0 : {
23
23
  method,
24
24
  path
25
25
  },
@@ -27,6 +27,7 @@ var Reconstrct = class {
27
27
  });
28
28
  } catch (error) {
29
29
  if (!isBridgeNotInitialized(error)) throw error;
30
+ if (liveOnly) throw new Error("Duplicate route must compile JIT but the TypeBox bridge is not initialized", { cause: error });
30
31
  const frozen = buildFrozenRouteValidator(hook, root, method, path);
31
32
  if (frozen) return frozen;
32
33
  throw error;
@@ -60,7 +60,7 @@ function extractDeriveKeys(fn) {
60
60
  }
61
61
  function replaceDeriveContext(context, derivative) {
62
62
  const next = Object.create(Object.getPrototypeOf(context));
63
- Object.assign(next, derivative);
63
+ require_utils.assignOwn(next, derivative);
64
64
  next.request = context.request;
65
65
  next["~sig"] = context["~sig"];
66
66
  next["~afterResponse"] = context["~afterResponse"];
@@ -334,7 +334,7 @@ function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard) {
334
334
  code += "if(tmp instanceof es)_r=tmp\nelse if(tmp){if(typeof tmp==='object'||typeof tmp==='function')c=rdc(c,tmp);tmp=undefined}\n";
335
335
  } else {
336
336
  const keys = extractDeriveKeys(fn);
337
- const merge = keys && keys.length ? keys.map((k) => `c[${JSON.stringify(k)}]=tmp[${JSON.stringify(k)}]`).join(";") : "Object.assign(c,tmp)";
337
+ const merge = keys && keys.length && !keys.includes("__proto__") ? keys.map((k) => `c[${JSON.stringify(k)}]=tmp[${JSON.stringify(k)}]`).join(";") : "Object.hasOwn(tmp,'__proto__')?Object.defineProperties(c,Object.getOwnPropertyDescriptors(tmp)):Object.assign(c,tmp)";
338
338
  code += `if(tmp instanceof es)_r=tmp
339
339
  else if(tmp){${merge};tmp=undefined}\n`;
340
340
  }
@@ -1,4 +1,4 @@
1
- import { deriveEntryFn, isMapDeriveEntry } from "../../utils.mjs";
1
+ import { assignOwn, deriveEntryFn, isMapDeriveEntry } from "../../utils.mjs";
2
2
  import { ELYSIA_TYPES } from "../../type/constants.mjs";
3
3
  import { skipClone } from "../../adapter/skip-clone.mjs";
4
4
  import { ElysiaStatus } from "../../error.mjs";
@@ -59,7 +59,7 @@ function extractDeriveKeys(fn) {
59
59
  }
60
60
  function replaceDeriveContext(context, derivative) {
61
61
  const next = Object.create(Object.getPrototypeOf(context));
62
- Object.assign(next, derivative);
62
+ assignOwn(next, derivative);
63
63
  next.request = context.request;
64
64
  next["~sig"] = context["~sig"];
65
65
  next["~afterResponse"] = context["~afterResponse"];
@@ -333,7 +333,7 @@ function mapBeforeHandle(_hooks, derive, link, isAsync, report, abortGuard) {
333
333
  code += "if(tmp instanceof es)_r=tmp\nelse if(tmp){if(typeof tmp==='object'||typeof tmp==='function')c=rdc(c,tmp);tmp=undefined}\n";
334
334
  } else {
335
335
  const keys = extractDeriveKeys(fn);
336
- const merge = keys && keys.length ? keys.map((k) => `c[${JSON.stringify(k)}]=tmp[${JSON.stringify(k)}]`).join(";") : "Object.assign(c,tmp)";
336
+ const merge = keys && keys.length && !keys.includes("__proto__") ? keys.map((k) => `c[${JSON.stringify(k)}]=tmp[${JSON.stringify(k)}]`).join(";") : "Object.hasOwn(tmp,'__proto__')?Object.defineProperties(c,Object.getOwnPropertyDescriptors(tmp)):Object.assign(c,tmp)";
337
337
  code += `if(tmp instanceof es)_r=tmp
338
338
  else if(tmp){${merge};tmp=undefined}\n`;
339
339
  }
@@ -1,8 +1,8 @@
1
1
  //#region src/compile/jit-probe.d.ts
2
2
  /** A handler-JIT entry point the frozen replay can trip over. */
3
- type JITProbeReason = 'sucrose' | 'handler:new-function';
3
+ type JITProbeReason = 'sucrose' | 'handler:new-function' | 'handler:indexed-duplicate';
4
4
  interface JITProbeResult {
5
- /** `sucrose` + the handler `new Function` codegen is unused. */
5
+ /** No route needs sucrose, handler codegen, or indexed duplicate replay. */
6
6
  jit: boolean;
7
7
  reasons: JITProbeReason[];
8
8
  }
package/dist/context.d.ts CHANGED
@@ -9,7 +9,7 @@ import { AnyElysia } from "./base.js";
9
9
 
10
10
  //#region src/context.d.ts
11
11
  declare function createBaseContext(app: AnyElysia): any;
12
- declare function clearContextCache(): void;
12
+ declare function clearContextCache(app?: AnyElysia): void;
13
13
  declare function createContext(app: AnyElysia): new (request: Request) => Context;
14
14
  interface ContextBase<in out Route extends RouteSchema, in out Singleton extends SingletonBase> {
15
15
  server: Server | null;
package/dist/context.js CHANGED
@@ -41,12 +41,15 @@ function createBaseContext(app) {
41
41
  Object.defineProperty(Decorator.prototype, "defer", defer);
42
42
  return Decorator;
43
43
  }
44
- function clearContextCache() {
44
+ function clearContextCache(app) {
45
+ if (app !== void 0) {
46
+ contextCache.delete(app);
47
+ return;
48
+ }
45
49
  contextCache = /* @__PURE__ */ new WeakMap();
46
50
  sharedEmptyDecorator = null;
47
51
  sharedEmptyContext = null;
48
52
  }
49
- const pathValue = Symbol("path");
50
53
  function buildEmptyContext(Base, headers = null, warnPathMutation = false) {
51
54
  const immutableHeaders = headers !== null && Object.isFrozen(headers);
52
55
  let warnedPathMutation = false;
@@ -54,14 +57,14 @@ function buildEmptyContext(Base, headers = null, warnPathMutation = false) {
54
57
  enumerable: true,
55
58
  configurable: true,
56
59
  get() {
57
- return this[pathValue];
60
+ return this["~path"];
58
61
  },
59
62
  set(value) {
60
- if (pathValue in this && !warnedPathMutation) {
63
+ if ("~path" in this && !warnedPathMutation) {
61
64
  warnedPathMutation = true;
62
65
  console.warn("[elysia] context.path is readonly; request-hook rerouting will stop working in a future release.");
63
66
  }
64
- this[pathValue] = value;
67
+ this["~path"] = value;
65
68
  }
66
69
  } : void 0;
67
70
  class Context extends Base {
package/dist/context.mjs CHANGED
@@ -40,12 +40,15 @@ function createBaseContext(app) {
40
40
  Object.defineProperty(Decorator.prototype, "defer", defer);
41
41
  return Decorator;
42
42
  }
43
- function clearContextCache() {
43
+ function clearContextCache(app) {
44
+ if (app !== void 0) {
45
+ contextCache.delete(app);
46
+ return;
47
+ }
44
48
  contextCache = /* @__PURE__ */ new WeakMap();
45
49
  sharedEmptyDecorator = null;
46
50
  sharedEmptyContext = null;
47
51
  }
48
- const pathValue = Symbol("path");
49
52
  function buildEmptyContext(Base, headers = null, warnPathMutation = false) {
50
53
  const immutableHeaders = headers !== null && Object.isFrozen(headers);
51
54
  let warnedPathMutation = false;
@@ -53,14 +56,14 @@ function buildEmptyContext(Base, headers = null, warnPathMutation = false) {
53
56
  enumerable: true,
54
57
  configurable: true,
55
58
  get() {
56
- return this[pathValue];
59
+ return this["~path"];
57
60
  },
58
61
  set(value) {
59
- if (pathValue in this && !warnedPathMutation) {
62
+ if ("~path" in this && !warnedPathMutation) {
60
63
  warnedPathMutation = true;
61
64
  console.warn("[elysia] context.path is readonly; request-hook rerouting will stop working in a future release.");
62
65
  }
63
- this[pathValue] = value;
66
+ this["~path"] = value;
64
67
  }
65
68
  } : void 0;
66
69
  class Context extends Base {
@@ -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;
@@ -31,7 +31,7 @@ function normalizeSign(sign) {
31
31
  if (Array.isArray(sign)) return sign.length ? sign : void 0;
32
32
  return [sign];
33
33
  }
34
- const hasUsableSecret = (secrets) => secrets == null ? false : Array.isArray(secrets) ? secrets.some((s) => s != null) : true;
34
+ const hasUsableSecret = (secrets) => Array.isArray(secrets) ? secrets.some((s) => !!s?.trim()) : !!secrets?.trim();
35
35
  function compileCookieConfig(routeSchema, appConfig) {
36
36
  const routeConfig = routeSchema?.config ?? void 0;
37
37
  const appAttributes = getAttributes(appConfig);
@@ -74,7 +74,8 @@ function compileCookieConfig(routeSchema, appConfig) {
74
74
  globalSignSet: Array.isArray(globalSign) ? new Set(globalSign) : void 0,
75
75
  globalSecrets,
76
76
  hasSign,
77
- verify: appConfig?.verify ?? "lazy"
77
+ verify: appConfig?.verify ?? "lazy",
78
+ legacySignature: (routeConfig?.legacySignature ?? appConfig?.legacySignature) !== false
78
79
  };
79
80
  }
80
81
  function resolveSignSecrets(name, config) {
@@ -30,7 +30,7 @@ function normalizeSign(sign) {
30
30
  if (Array.isArray(sign)) return sign.length ? sign : void 0;
31
31
  return [sign];
32
32
  }
33
- const hasUsableSecret = (secrets) => secrets == null ? false : Array.isArray(secrets) ? secrets.some((s) => s != null) : true;
33
+ const hasUsableSecret = (secrets) => Array.isArray(secrets) ? secrets.some((s) => !!s?.trim()) : !!secrets?.trim();
34
34
  function compileCookieConfig(routeSchema, appConfig) {
35
35
  const routeConfig = routeSchema?.config ?? void 0;
36
36
  const appAttributes = getAttributes(appConfig);
@@ -73,7 +73,8 @@ function compileCookieConfig(routeSchema, appConfig) {
73
73
  globalSignSet: Array.isArray(globalSign) ? new Set(globalSign) : void 0,
74
74
  globalSecrets,
75
75
  hasSign,
76
- verify: appConfig?.verify ?? "lazy"
76
+ verify: appConfig?.verify ?? "lazy",
77
+ legacySignature: (routeConfig?.legacySignature ?? appConfig?.legacySignature) !== false
77
78
  };
78
79
  }
79
80
  function resolveSignSecrets(name, config) {
@@ -10,6 +10,7 @@ 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;
@@ -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
  }
@@ -56,7 +60,7 @@ var Cookie = class {
56
60
  set value(value) {
57
61
  if (this.cookie.value === value && (!value || typeof value !== "object")) return;
58
62
  const j = this.#jar;
59
- if (!(this.#name in j)) j[this.#name] = { ...this.#initial };
63
+ if (!(this.#name in j)) j[this.#name] = Object.assign(require_utils.nullObject(), this.#initial);
60
64
  j[this.#name].value = value;
61
65
  }
62
66
  update(config) {
@@ -66,10 +70,7 @@ var Cookie = class {
66
70
  return this;
67
71
  }
68
72
  set(config) {
69
- const cookie = Object.assign({
70
- ...this.#initial,
71
- value: this.value
72
- }, typeof config === "function" ? config(this.cookie) : config);
73
+ const cookie = Object.assign(require_utils.nullObject(), this.#initial, { value: this.value }, typeof config === "function" ? config(this.cookie) : config);
73
74
  delete cookie["~raw"];
74
75
  this.setCookie = cookie;
75
76
  return this;
@@ -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
  }
@@ -55,7 +59,7 @@ var Cookie = class {
55
59
  set value(value) {
56
60
  if (this.cookie.value === value && (!value || typeof value !== "object")) return;
57
61
  const j = this.#jar;
58
- if (!(this.#name in j)) j[this.#name] = { ...this.#initial };
62
+ if (!(this.#name in j)) j[this.#name] = Object.assign(nullObject(), this.#initial);
59
63
  j[this.#name].value = value;
60
64
  }
61
65
  update(config) {
@@ -65,10 +69,7 @@ var Cookie = class {
65
69
  return this;
66
70
  }
67
71
  set(config) {
68
- const cookie = Object.assign({
69
- ...this.#initial,
70
- value: this.value
71
- }, typeof config === "function" ? config(this.cookie) : config);
72
+ const cookie = Object.assign(nullObject(), this.#initial, { value: this.value }, typeof config === "function" ? config(this.cookie) : config);
72
73
  delete cookie["~raw"];
73
74
  this.setCookie = cookie;
74
75
  return this;