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
@@ -6,7 +6,7 @@ const require_plugin_aot_treeshake = require('./treeshake.js');
6
6
  const toPosix = (path) => path.replace(/\\/g, "/");
7
7
  const VIRTUAL = "\0elysia/compiled";
8
8
  const VIRTUAL_TYPE = "\0elysia/type";
9
- const createAotPluginHooks = (entry, options) => {
9
+ const createAotPluginHooks = (entry, options, moduleCondition = require_plugin_aot_core.resolveEntryModuleKind(entry)) => {
10
10
  const entryPath = require_plugin_aot_core.resolveEntry(entry);
11
11
  const entryPosix = toPosix(entryPath);
12
12
  const entryRealPosix = toPosix(require_plugin_aot_core.realPath(entryPath));
@@ -24,7 +24,7 @@ const createAotPluginHooks = (entry, options) => {
24
24
  let isElysiaModule = (_path) => false;
25
25
  return {
26
26
  async buildStart() {
27
- const generated = initial ? await require_plugin_aot_core.generateCompiledArtifacts(entry, options) : await require_plugin_aot_core.generateCompiledArtifactsIsolated(entry, options);
27
+ const generated = initial ? await require_plugin_aot_core.generateCompiledArtifacts(entry, options, moduleCondition) : await require_plugin_aot_core.generateCompiledArtifactsIsolated(entry, options, moduleCondition);
28
28
  initial = false;
29
29
  source = generated.source;
30
30
  stub = generated.stub;
@@ -56,7 +56,7 @@ const createAotPluginHooks = (entry, options) => {
56
56
  if (stub.isProduction && isElysiaModule(cleanId)) out = require_plugin_aot_core.rewriteIsProductionCalls(out);
57
57
  if (isEntry(cleanId)) {
58
58
  entryMatched = true;
59
- out = `import 'elysia/compiled'\n${out}`;
59
+ out = (moduleCondition === "cjs" ? `require('elysia/compiled')\n` : `import 'elysia/compiled'\n`) + out;
60
60
  }
61
61
  return out === code ? void 0 : out;
62
62
  },
@@ -1,11 +1,11 @@
1
- import { ADAPTER_BUN_FILTER, ADAPTER_CONSTANTS_FILTER, ELYSIA_MODULE_FILTER, IS_PRODUCTION_FILTER, NO_STUB, SOURCE_REGEX, STUB_SOURCES, adapterConstantsSource, alignStubExtensions, bunAdapterStubSource, generateCompiledArtifacts, generateCompiledArtifactsIsolated, makeIsElysiaModule, realPath, resolveElysiaRoot, resolveEntry, rewriteIsProductionCalls } from "./core.mjs";
1
+ import { ADAPTER_BUN_FILTER, ADAPTER_CONSTANTS_FILTER, ELYSIA_MODULE_FILTER, IS_PRODUCTION_FILTER, NO_STUB, SOURCE_REGEX, STUB_SOURCES, adapterConstantsSource, alignStubExtensions, bunAdapterStubSource, generateCompiledArtifacts, generateCompiledArtifactsIsolated, makeIsElysiaModule, realPath, resolveElysiaRoot, resolveEntry, resolveEntryModuleKind, rewriteIsProductionCalls } from "./core.mjs";
2
2
  import { rewriteTypeImport } from "./treeshake.mjs";
3
3
 
4
4
  //#region src/plugin/aot/hooks.ts
5
5
  const toPosix = (path) => path.replace(/\\/g, "/");
6
6
  const VIRTUAL = "\0elysia/compiled";
7
7
  const VIRTUAL_TYPE = "\0elysia/type";
8
- const createAotPluginHooks = (entry, options) => {
8
+ const createAotPluginHooks = (entry, options, moduleCondition = resolveEntryModuleKind(entry)) => {
9
9
  const entryPath = resolveEntry(entry);
10
10
  const entryPosix = toPosix(entryPath);
11
11
  const entryRealPosix = toPosix(realPath(entryPath));
@@ -23,7 +23,7 @@ const createAotPluginHooks = (entry, options) => {
23
23
  let isElysiaModule = (_path) => false;
24
24
  return {
25
25
  async buildStart() {
26
- const generated = initial ? await generateCompiledArtifacts(entry, options) : await generateCompiledArtifactsIsolated(entry, options);
26
+ const generated = initial ? await generateCompiledArtifacts(entry, options, moduleCondition) : await generateCompiledArtifactsIsolated(entry, options, moduleCondition);
27
27
  initial = false;
28
28
  source = generated.source;
29
29
  stub = generated.stub;
@@ -55,7 +55,7 @@ const createAotPluginHooks = (entry, options) => {
55
55
  if (stub.isProduction && isElysiaModule(cleanId)) out = rewriteIsProductionCalls(out);
56
56
  if (isEntry(cleanId)) {
57
57
  entryMatched = true;
58
- out = `import 'elysia/compiled'\n${out}`;
58
+ out = (moduleCondition === "cjs" ? `require('elysia/compiled')\n` : `import 'elysia/compiled'\n`) + out;
59
59
  }
60
60
  return out === code ? void 0 : out;
61
61
  },
@@ -4,9 +4,12 @@ import { JITProbeResult } from "../../compile/jit-probe.js";
4
4
 
5
5
  //#region src/plugin/aot/source.d.ts
6
6
  type AotTarget = 'bun' | 'node' | 'workerd';
7
+ type AotModuleCondition = 'esm' | 'cjs';
7
8
  interface CompileToSourceOptions {
8
9
  /** Emit a self-registering fingerprinted program (`Compiled.register(...)`). */
9
10
  register?: boolean;
11
+ /** @internal Package condition used by the entry that owns this manifest. */
12
+ moduleCondition?: AotModuleCondition;
10
13
  /**
11
14
  * Deploy target for build-time-baked codegen consts. Lets you build on one
12
15
  * runtime and deploy to another e.g. build under Bun with
@@ -57,4 +60,4 @@ interface CapturedArtifacts {
57
60
  declare function captureArtifacts(app: AnyElysia, options?: CompileToSourceOptions): Promise<CapturedArtifacts>;
58
61
  declare function replayStubbability(app: AnyElysia, handlers: CapturedHandler[]): JITProbeResult;
59
62
  //#endregion
60
- export { AotTarget, CapturedArtifacts, CompileToSourceOptions, autoGroupSize, captureArtifacts, compileToSource, replayStubbability };
63
+ export { AotModuleCondition, AotTarget, CapturedArtifacts, CompileToSourceOptions, autoGroupSize, captureArtifacts, compileToSource, replayStubbability };
@@ -28,7 +28,7 @@ async function captureArtifacts(app, options) {
28
28
  const handlers = require_compile_aot_capture.endHandlerCapture();
29
29
  const fingerprint = app["~aotFingerprint"] ?? require_compile_aot.createAotFingerprint();
30
30
  return {
31
- source: emitModule(captured, handlers, fingerprint, options),
31
+ source: emitModule(captured, handlers, fingerprint, options, options?.moduleCondition ?? "esm"),
32
32
  validators: captured,
33
33
  handlers,
34
34
  fingerprint
@@ -64,15 +64,21 @@ function replayStubbability(app, handlers) {
64
64
  require_validator_index.Validator.clear();
65
65
  const history = app["~routes"] ?? [];
66
66
  require_compile_jit_probe.JITProbe.begin();
67
+ const exact = /* @__PURE__ */ new Map();
68
+ for (const route of history) {
69
+ const method = route[0];
70
+ if (method === "WS") continue;
71
+ let paths = exact.get(method);
72
+ if (!paths) exact.set(method, paths = /* @__PURE__ */ new Set());
73
+ if (paths.has(route[1])) require_compile_jit_probe.JITProbe.record("handler:indexed-duplicate");
74
+ else paths.add(route[1]);
75
+ }
67
76
  for (const route of history) try {
68
77
  if (route[0] === "WS") continue;
69
78
  require_compile_handler_index.compileHandler(route, app);
70
79
  } catch {
71
- require_compile_jit_probe.JITProbe.end();
72
- return {
73
- jit: false,
74
- reasons: ["handler:new-function"]
75
- };
80
+ require_compile_jit_probe.JITProbe.record("handler:new-function");
81
+ return require_compile_jit_probe.JITProbe.end();
76
82
  }
77
83
  return require_compile_jit_probe.JITProbe.end();
78
84
  } finally {
@@ -198,7 +204,7 @@ function entryParts(c, enc) {
198
204
  }
199
205
  return parts;
200
206
  }
201
- function emitModule(captured, handlers, fingerprint, options) {
207
+ function emitModule(captured, handlers, fingerprint, options, moduleCondition) {
202
208
  const enc = createEntryEncoder();
203
209
  const treeToSource = (tree, slotRef, sink) => {
204
210
  const methods = [];
@@ -394,15 +400,16 @@ function emitModule(captured, handlers, fingerprint, options) {
394
400
  handlerExport += "}\n";
395
401
  const fingerprintExport = options?.register ? `export const fingerprint = ${JSON.stringify(fingerprint)}\n` : "";
396
402
  let body = "// Generated by Elysia build plugin. Do not edit.\n";
397
- if (options?.register) body += `import { Compiled } from ${JSON.stringify(options.registerFrom ?? "elysia")}\n`;
398
- if (options?.register && enc.hasCoercePlan) body += `import { buildCoercedFromPlan } from ${JSON.stringify("elysia/coerce-plan")}\n`;
399
- if (options?.register && captured.length) body += `import { Reconstruct } from ${JSON.stringify(options.reconstructFrom ?? "elysia/reconstruct")}\n`;
403
+ const importNamed = (name, specifier) => moduleCondition === "cjs" ? `const { ${name} } = require(${JSON.stringify(specifier)})\n` : `import { ${name} } from ${JSON.stringify(specifier)}\n`;
404
+ if (options?.register) body += importNamed("Compiled", options.registerFrom ?? "elysia");
405
+ if (options?.register && enc.hasCoercePlan) body += importNamed("buildCoercedFromPlan", "elysia/coerce-plan");
406
+ if (options?.register && captured.length) body += importNamed("Reconstruct", options.reconstructFrom ?? "elysia/reconstruct");
400
407
  const generated = enc.branchDecls + enc.unionDecls + validatorDecls + handlerDecls;
401
408
  const needs = (symbol) => new RegExp(`\\b${symbol}\\b`).test(generated);
402
- if (needs("CheckContext")) body += "import { CheckContext } from 'typebox/schema'\n";
403
- if (needs("Guard")) body += "import { Guard } from 'typebox/guard'\n";
404
- if (needs("Format")) body += "import { Format } from 'typebox/format'\n";
405
- if (needs("Hashing")) body += "import { Hashing } from 'typebox/system'\n";
409
+ if (needs("CheckContext")) body += importNamed("CheckContext", "typebox/schema");
410
+ if (needs("Guard")) body += importNamed("Guard", "typebox/guard");
411
+ if (needs("Format")) body += importNamed("Format", "typebox/format");
412
+ if (needs("Hashing")) body += importNamed("Hashing", "typebox/system");
406
413
  if (options?.register) {
407
414
  body += "\n";
408
415
  if (captured.length) body += "Compiled.reconstruct = Reconstruct\n";
@@ -27,7 +27,7 @@ async function captureArtifacts(app, options) {
27
27
  const handlers = endHandlerCapture();
28
28
  const fingerprint = app["~aotFingerprint"] ?? createAotFingerprint();
29
29
  return {
30
- source: emitModule(captured, handlers, fingerprint, options),
30
+ source: emitModule(captured, handlers, fingerprint, options, options?.moduleCondition ?? "esm"),
31
31
  validators: captured,
32
32
  handlers,
33
33
  fingerprint
@@ -63,15 +63,21 @@ function replayStubbability(app, handlers) {
63
63
  Validator.clear();
64
64
  const history = app["~routes"] ?? [];
65
65
  JITProbe.begin();
66
+ const exact = /* @__PURE__ */ new Map();
67
+ for (const route of history) {
68
+ const method = route[0];
69
+ if (method === "WS") continue;
70
+ let paths = exact.get(method);
71
+ if (!paths) exact.set(method, paths = /* @__PURE__ */ new Set());
72
+ if (paths.has(route[1])) JITProbe.record("handler:indexed-duplicate");
73
+ else paths.add(route[1]);
74
+ }
66
75
  for (const route of history) try {
67
76
  if (route[0] === "WS") continue;
68
77
  compileHandler(route, app);
69
78
  } catch {
70
- JITProbe.end();
71
- return {
72
- jit: false,
73
- reasons: ["handler:new-function"]
74
- };
79
+ JITProbe.record("handler:new-function");
80
+ return JITProbe.end();
75
81
  }
76
82
  return JITProbe.end();
77
83
  } finally {
@@ -197,7 +203,7 @@ function entryParts(c, enc) {
197
203
  }
198
204
  return parts;
199
205
  }
200
- function emitModule(captured, handlers, fingerprint, options) {
206
+ function emitModule(captured, handlers, fingerprint, options, moduleCondition) {
201
207
  const enc = createEntryEncoder();
202
208
  const treeToSource = (tree, slotRef, sink) => {
203
209
  const methods = [];
@@ -393,15 +399,16 @@ function emitModule(captured, handlers, fingerprint, options) {
393
399
  handlerExport += "}\n";
394
400
  const fingerprintExport = options?.register ? `export const fingerprint = ${JSON.stringify(fingerprint)}\n` : "";
395
401
  let body = "// Generated by Elysia build plugin. Do not edit.\n";
396
- if (options?.register) body += `import { Compiled } from ${JSON.stringify(options.registerFrom ?? "elysia")}\n`;
397
- if (options?.register && enc.hasCoercePlan) body += `import { buildCoercedFromPlan } from ${JSON.stringify("elysia/coerce-plan")}\n`;
398
- if (options?.register && captured.length) body += `import { Reconstruct } from ${JSON.stringify(options.reconstructFrom ?? "elysia/reconstruct")}\n`;
402
+ const importNamed = (name, specifier) => moduleCondition === "cjs" ? `const { ${name} } = require(${JSON.stringify(specifier)})\n` : `import { ${name} } from ${JSON.stringify(specifier)}\n`;
403
+ if (options?.register) body += importNamed("Compiled", options.registerFrom ?? "elysia");
404
+ if (options?.register && enc.hasCoercePlan) body += importNamed("buildCoercedFromPlan", "elysia/coerce-plan");
405
+ if (options?.register && captured.length) body += importNamed("Reconstruct", options.reconstructFrom ?? "elysia/reconstruct");
399
406
  const generated = enc.branchDecls + enc.unionDecls + validatorDecls + handlerDecls;
400
407
  const needs = (symbol) => new RegExp(`\\b${symbol}\\b`).test(generated);
401
- if (needs("CheckContext")) body += "import { CheckContext } from 'typebox/schema'\n";
402
- if (needs("Guard")) body += "import { Guard } from 'typebox/guard'\n";
403
- if (needs("Format")) body += "import { Format } from 'typebox/format'\n";
404
- if (needs("Hashing")) body += "import { Hashing } from 'typebox/system'\n";
408
+ if (needs("CheckContext")) body += importNamed("CheckContext", "typebox/schema");
409
+ if (needs("Guard")) body += importNamed("Guard", "typebox/guard");
410
+ if (needs("Format")) body += importNamed("Format", "typebox/format");
411
+ if (needs("Hashing")) body += importNamed("Hashing", "typebox/system");
405
412
  if (options?.register) {
406
413
  body += "\n";
407
414
  if (captured.length) body += "Compiled.reconstruct = Reconstruct\n";
@@ -6,8 +6,8 @@ let node_worker_threads = require("node:worker_threads");
6
6
  //#region src/plugin/aot/worker.ts
7
7
  const port = node_worker_threads.parentPort;
8
8
  if (!port) throw new Error("[elysia-aot] worker requires a parent port");
9
- const { file, options } = node_worker_threads.workerData;
10
- require_plugin_aot_core.generateCompiledArtifacts(file, options).then((artifacts) => port.postMessage({
9
+ const { file, options, moduleCondition } = node_worker_threads.workerData;
10
+ require_plugin_aot_core.generateCompiledArtifacts(file, options, moduleCondition).then((artifacts) => port.postMessage({
11
11
  ok: true,
12
12
  artifacts
13
13
  }), (error) => {
@@ -4,8 +4,8 @@ import { parentPort, workerData } from "node:worker_threads";
4
4
  //#region src/plugin/aot/worker.ts
5
5
  const port = parentPort;
6
6
  if (!port) throw new Error("[elysia-aot] worker requires a parent port");
7
- const { file, options } = workerData;
8
- generateCompiledArtifacts(file, options).then((artifacts) => port.postMessage({
7
+ const { file, options, moduleCondition } = workerData;
8
+ generateCompiledArtifacts(file, options, moduleCondition).then((artifacts) => port.postMessage({
9
9
  ok: true,
10
10
  artifacts
11
11
  }), (error) => {
@@ -7,6 +7,9 @@ declare const RouteFlag: {
7
7
  readonly WS: 1;
8
8
  readonly Dynamic: 2;
9
9
  readonly Encode: 4;
10
+ readonly ExactDuplicate: 8;
11
+ readonly JITCold: 16;
12
+ readonly JITSatisfied: 32;
10
13
  };
11
14
  interface RouteTable {
12
15
  readonly length: number;
@@ -5,7 +5,10 @@ const require_constants = require('./constants.js');
5
5
  const RouteFlag = {
6
6
  WS: 1,
7
7
  Dynamic: 2,
8
- Encode: 4
8
+ Encode: 4,
9
+ ExactDuplicate: 8,
10
+ JITCold: 16,
11
+ JITSatisfied: 32
9
12
  };
10
13
  function buildRouteTable(declaredRoutes) {
11
14
  const length = declaredRoutes.length;
@@ -47,16 +50,18 @@ function buildRouteTable(declaredRoutes) {
47
50
  macroScope
48
51
  };
49
52
  }
50
- const routeRow = (table, id) => [
51
- table.method[id],
52
- table.path[id],
53
- table.handler[id],
54
- table.owner[id],
55
- table.localHook[id],
56
- table.appHook[id],
57
- table.inheritedChain[id],
58
- table.macroScope?.get(id)
59
- ];
53
+ const routeRow = (table, id) => {
54
+ return [
55
+ table.method[id],
56
+ table.path[id],
57
+ table.handler[id],
58
+ table.owner[id],
59
+ table.localHook[id],
60
+ table.appHook[id],
61
+ table.inheritedChain[id],
62
+ table.macroScope?.get(id)
63
+ ];
64
+ };
60
65
 
61
66
  //#endregion
62
67
  exports.RouteFlag = RouteFlag;
@@ -4,7 +4,10 @@ import { needEncodeRegex } from "./constants.mjs";
4
4
  const RouteFlag = {
5
5
  WS: 1,
6
6
  Dynamic: 2,
7
- Encode: 4
7
+ Encode: 4,
8
+ ExactDuplicate: 8,
9
+ JITCold: 16,
10
+ JITSatisfied: 32
8
11
  };
9
12
  function buildRouteTable(declaredRoutes) {
10
13
  const length = declaredRoutes.length;
@@ -46,16 +49,18 @@ function buildRouteTable(declaredRoutes) {
46
49
  macroScope
47
50
  };
48
51
  }
49
- const routeRow = (table, id) => [
50
- table.method[id],
51
- table.path[id],
52
- table.handler[id],
53
- table.owner[id],
54
- table.localHook[id],
55
- table.appHook[id],
56
- table.inheritedChain[id],
57
- table.macroScope?.get(id)
58
- ];
52
+ const routeRow = (table, id) => {
53
+ return [
54
+ table.method[id],
55
+ table.path[id],
56
+ table.handler[id],
57
+ table.owner[id],
58
+ table.localHook[id],
59
+ table.appHook[id],
60
+ table.inheritedChain[id],
61
+ table.macroScope?.get(id)
62
+ ];
63
+ };
59
64
 
60
65
  //#endregion
61
66
  export { RouteFlag, buildRouteTable, routeRow };
@@ -52,8 +52,7 @@ function isImmutableNode(value) {
52
52
  immutableNodes.set(value, immutable);
53
53
  return immutable;
54
54
  }
55
- let freezeClones = false;
56
- function deepCloneSchema(value, seen, canShare = true) {
55
+ function deepCloneSchema(value, freeze, seen, canShare = true) {
57
56
  if (value === null || typeof value !== "object") return value;
58
57
  const cached = seen?.get(value);
59
58
  if (cached) return cached;
@@ -61,8 +60,8 @@ function deepCloneSchema(value, seen, canShare = true) {
61
60
  const out = [];
62
61
  seen ??= /* @__PURE__ */ new Map();
63
62
  seen.set(value, out);
64
- for (let i = 0; i < value.length; i++) out[i] = deepCloneSchema(value[i], seen);
65
- return freezeClones ? Object.freeze(out) : out;
63
+ for (let i = 0; i < value.length; i++) out[i] = deepCloneSchema(value[i], freeze, seen);
64
+ return freeze ? Object.freeze(out) : out;
66
65
  }
67
66
  if (canShare && isImmutableNode(value)) return value;
68
67
  const proto = Object.getPrototypeOf(value);
@@ -84,7 +83,7 @@ function deepCloneSchema(value, seen, canShare = true) {
84
83
  });
85
84
  continue;
86
85
  }
87
- const cloned = deepCloneSchema(property, seen);
86
+ const cloned = deepCloneSchema(property, freeze, seen);
88
87
  if (key === "__proto__") Object.defineProperty(out, key, {
89
88
  value: cloned,
90
89
  enumerable: true,
@@ -97,7 +96,7 @@ function deepCloneSchema(value, seen, canShare = true) {
97
96
  for (let i = 0; i < symbols.length; i++) {
98
97
  const key = symbols[i];
99
98
  const property = value[key];
100
- if (isEnumerable.call(value, key)) out[key] = deepCloneSchema(property, seen);
99
+ if (isEnumerable.call(value, key)) out[key] = deepCloneSchema(property, freeze, seen);
101
100
  else Object.defineProperty(out, key, {
102
101
  value: property,
103
102
  enumerable: false,
@@ -105,7 +104,7 @@ function deepCloneSchema(value, seen, canShare = true) {
105
104
  configurable: true
106
105
  });
107
106
  }
108
- return freezeClones ? Object.freeze(out) : out;
107
+ return freeze ? Object.freeze(out) : out;
109
108
  }
110
109
  const refIds = /* @__PURE__ */ new WeakMap();
111
110
  let nextRefId = 0;
@@ -114,9 +113,8 @@ function refKey(value) {
114
113
  if (id === void 0) refIds.set(value, id = ++nextRefId);
115
114
  return "r" + id + ";";
116
115
  }
117
- let fingerprintBail = false;
118
- const byRefKey = (value) => value !== null && (typeof value === "object" || typeof value === "function") ? refKey(value) : fingerprint(value, void 0);
119
- function fingerprint(value, seen, canShare = true) {
116
+ const byRefKey = (value, state) => value !== null && (typeof value === "object" || typeof value === "function") ? refKey(value) : fingerprint(value, void 0, state);
117
+ function fingerprint(value, seen, state, canShare = true) {
120
118
  if (value === null) return "z;";
121
119
  const type = typeof value;
122
120
  if (type !== "object") switch (type) {
@@ -127,7 +125,7 @@ function fingerprint(value, seen, canShare = true) {
127
125
  case "undefined": return "u;";
128
126
  case "bigint": return "g" + value + ";";
129
127
  default:
130
- fingerprintBail = true;
128
+ state.bail = true;
131
129
  return "y;";
132
130
  }
133
131
  const backReference = seen?.get(value);
@@ -136,7 +134,7 @@ function fingerprint(value, seen, canShare = true) {
136
134
  seen ??= /* @__PURE__ */ new Map();
137
135
  seen.set(value, seen.size);
138
136
  let out = "[";
139
- for (let i = 0; i < value.length; i++) out += fingerprint(value[i], seen);
137
+ for (let i = 0; i < value.length; i++) out += fingerprint(value[i], seen, state);
140
138
  return out + "];";
141
139
  }
142
140
  if (canShare && isImmutableNode(value)) return refKey(value);
@@ -151,9 +149,9 @@ function fingerprint(value, seen, canShare = true) {
151
149
  const key = keys[i];
152
150
  const property = value[key];
153
151
  out += "k" + key.length + ":" + key;
154
- out += !allEnumerable && !isEnumerable.call(value, key) ? "!" + byRefKey(property) : "=" + fingerprint(property, seen);
152
+ out += !allEnumerable && !isEnumerable.call(value, key) ? "!" + byRefKey(property, state) : "=" + fingerprint(property, seen, state);
155
153
  }
156
- if (Object.getOwnPropertySymbols(value).length) fingerprintBail = true;
154
+ if (Object.getOwnPropertySymbols(value).length) state.bail = true;
157
155
  return out + "};";
158
156
  }
159
157
  /**
@@ -169,7 +167,7 @@ function snapshotSchema(schema) {
169
167
  if (existing) return existing;
170
168
  let cloned;
171
169
  try {
172
- cloned = deepCloneSchema(object, void 0, false);
170
+ cloned = deepCloneSchema(object, false, void 0, false);
173
171
  } catch (error) {
174
172
  console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
175
173
  return schema;
@@ -193,11 +191,11 @@ function internSchema(schema, intern) {
193
191
  if (existing) return existing;
194
192
  let key;
195
193
  if (intern) {
196
- fingerprintBail = false;
194
+ const state = { bail: false };
197
195
  try {
198
- key = fingerprint(object, void 0, false);
196
+ key = fingerprint(object, void 0, state, false);
199
197
  } catch {}
200
- if (fingerprintBail) key = void 0;
198
+ if (state.bail) key = void 0;
201
199
  }
202
200
  if (key !== void 0) {
203
201
  const shared = interned.get(key);
@@ -211,14 +209,11 @@ function internSchema(schema, intern) {
211
209
  }
212
210
  }
213
211
  let cloned;
214
- freezeClones = true;
215
212
  try {
216
- cloned = deepCloneSchema(object, void 0, false);
213
+ cloned = deepCloneSchema(object, true, void 0, false);
217
214
  } catch (error) {
218
215
  console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
219
216
  return schema;
220
- } finally {
221
- freezeClones = false;
222
217
  }
223
218
  hookSnapshots.set(object, cloned);
224
219
  produced.add(cloned);
@@ -51,8 +51,7 @@ function isImmutableNode(value) {
51
51
  immutableNodes.set(value, immutable);
52
52
  return immutable;
53
53
  }
54
- let freezeClones = false;
55
- function deepCloneSchema(value, seen, canShare = true) {
54
+ function deepCloneSchema(value, freeze, seen, canShare = true) {
56
55
  if (value === null || typeof value !== "object") return value;
57
56
  const cached = seen?.get(value);
58
57
  if (cached) return cached;
@@ -60,8 +59,8 @@ function deepCloneSchema(value, seen, canShare = true) {
60
59
  const out = [];
61
60
  seen ??= /* @__PURE__ */ new Map();
62
61
  seen.set(value, out);
63
- for (let i = 0; i < value.length; i++) out[i] = deepCloneSchema(value[i], seen);
64
- return freezeClones ? Object.freeze(out) : out;
62
+ for (let i = 0; i < value.length; i++) out[i] = deepCloneSchema(value[i], freeze, seen);
63
+ return freeze ? Object.freeze(out) : out;
65
64
  }
66
65
  if (canShare && isImmutableNode(value)) return value;
67
66
  const proto = Object.getPrototypeOf(value);
@@ -83,7 +82,7 @@ function deepCloneSchema(value, seen, canShare = true) {
83
82
  });
84
83
  continue;
85
84
  }
86
- const cloned = deepCloneSchema(property, seen);
85
+ const cloned = deepCloneSchema(property, freeze, seen);
87
86
  if (key === "__proto__") Object.defineProperty(out, key, {
88
87
  value: cloned,
89
88
  enumerable: true,
@@ -96,7 +95,7 @@ function deepCloneSchema(value, seen, canShare = true) {
96
95
  for (let i = 0; i < symbols.length; i++) {
97
96
  const key = symbols[i];
98
97
  const property = value[key];
99
- if (isEnumerable.call(value, key)) out[key] = deepCloneSchema(property, seen);
98
+ if (isEnumerable.call(value, key)) out[key] = deepCloneSchema(property, freeze, seen);
100
99
  else Object.defineProperty(out, key, {
101
100
  value: property,
102
101
  enumerable: false,
@@ -104,7 +103,7 @@ function deepCloneSchema(value, seen, canShare = true) {
104
103
  configurable: true
105
104
  });
106
105
  }
107
- return freezeClones ? Object.freeze(out) : out;
106
+ return freeze ? Object.freeze(out) : out;
108
107
  }
109
108
  const refIds = /* @__PURE__ */ new WeakMap();
110
109
  let nextRefId = 0;
@@ -113,9 +112,8 @@ function refKey(value) {
113
112
  if (id === void 0) refIds.set(value, id = ++nextRefId);
114
113
  return "r" + id + ";";
115
114
  }
116
- let fingerprintBail = false;
117
- const byRefKey = (value) => value !== null && (typeof value === "object" || typeof value === "function") ? refKey(value) : fingerprint(value, void 0);
118
- function fingerprint(value, seen, canShare = true) {
115
+ const byRefKey = (value, state) => value !== null && (typeof value === "object" || typeof value === "function") ? refKey(value) : fingerprint(value, void 0, state);
116
+ function fingerprint(value, seen, state, canShare = true) {
119
117
  if (value === null) return "z;";
120
118
  const type = typeof value;
121
119
  if (type !== "object") switch (type) {
@@ -126,7 +124,7 @@ function fingerprint(value, seen, canShare = true) {
126
124
  case "undefined": return "u;";
127
125
  case "bigint": return "g" + value + ";";
128
126
  default:
129
- fingerprintBail = true;
127
+ state.bail = true;
130
128
  return "y;";
131
129
  }
132
130
  const backReference = seen?.get(value);
@@ -135,7 +133,7 @@ function fingerprint(value, seen, canShare = true) {
135
133
  seen ??= /* @__PURE__ */ new Map();
136
134
  seen.set(value, seen.size);
137
135
  let out = "[";
138
- for (let i = 0; i < value.length; i++) out += fingerprint(value[i], seen);
136
+ for (let i = 0; i < value.length; i++) out += fingerprint(value[i], seen, state);
139
137
  return out + "];";
140
138
  }
141
139
  if (canShare && isImmutableNode(value)) return refKey(value);
@@ -150,9 +148,9 @@ function fingerprint(value, seen, canShare = true) {
150
148
  const key = keys[i];
151
149
  const property = value[key];
152
150
  out += "k" + key.length + ":" + key;
153
- out += !allEnumerable && !isEnumerable.call(value, key) ? "!" + byRefKey(property) : "=" + fingerprint(property, seen);
151
+ out += !allEnumerable && !isEnumerable.call(value, key) ? "!" + byRefKey(property, state) : "=" + fingerprint(property, seen, state);
154
152
  }
155
- if (Object.getOwnPropertySymbols(value).length) fingerprintBail = true;
153
+ if (Object.getOwnPropertySymbols(value).length) state.bail = true;
156
154
  return out + "};";
157
155
  }
158
156
  /**
@@ -168,7 +166,7 @@ function snapshotSchema(schema) {
168
166
  if (existing) return existing;
169
167
  let cloned;
170
168
  try {
171
- cloned = deepCloneSchema(object, void 0, false);
169
+ cloned = deepCloneSchema(object, false, void 0, false);
172
170
  } catch (error) {
173
171
  console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
174
172
  return schema;
@@ -192,11 +190,11 @@ function internSchema(schema, intern) {
192
190
  if (existing) return existing;
193
191
  let key;
194
192
  if (intern) {
195
- fingerprintBail = false;
193
+ const state = { bail: false };
196
194
  try {
197
- key = fingerprint(object, void 0, false);
195
+ key = fingerprint(object, void 0, state, false);
198
196
  } catch {}
199
- if (fingerprintBail) key = void 0;
197
+ if (state.bail) key = void 0;
200
198
  }
201
199
  if (key !== void 0) {
202
200
  const shared = interned.get(key);
@@ -210,14 +208,11 @@ function internSchema(schema, intern) {
210
208
  }
211
209
  }
212
210
  let cloned;
213
- freezeClones = true;
214
211
  try {
215
- cloned = deepCloneSchema(object, void 0, false);
212
+ cloned = deepCloneSchema(object, true, void 0, false);
216
213
  } catch (error) {
217
214
  console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
218
215
  return schema;
219
- } finally {
220
- freezeClones = false;
221
216
  }
222
217
  hookSnapshots.set(object, cloned);
223
218
  produced.add(cloned);
@@ -5,8 +5,8 @@ import { TypeBoxValidatorCache, mayHaveFileType } from "./validator/validator-ca
5
5
  import { TypeBoxValidator } from "./validator/index.js";
6
6
  import { applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure } from "./coerce.js";
7
7
  import { Ref } from "typebox/type";
8
- import { Compile } from "typebox/compile";
9
8
  import { Check, Clone, Create, Decode, Default, HasCodec } from "typebox/value";
9
+ import { Compile } from "typebox/compile";
10
10
 
11
11
  //#region src/type/bridge-live.d.ts
12
12
  declare function useTypebox(_mod?: Parameters<typeof useTypebox$1>[0]): void;
@@ -5,9 +5,9 @@ const require_type_coerce = require('./coerce.js');
5
5
  const require_type_validator_validator_cache = require('./validator/validator-cache.js');
6
6
  const require_type_validator_index = require('./validator/index.js');
7
7
  const require_type_elysia_intersect = require('./elysia/intersect.js');
8
- let typebox_type = require("typebox/type");
9
- let typebox_compile = require("typebox/compile");
10
8
  let typebox_value = require("typebox/value");
9
+ let typebox_compile = require("typebox/compile");
10
+ let typebox_type = require("typebox/type");
11
11
  let typebox_system = require("typebox/system");
12
12
 
13
13
  //#region src/type/bridge-live.ts
@@ -3,9 +3,9 @@ import { applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, co
3
3
  import { TypeBoxValidatorCache, mayHaveFileType } from "./validator/validator-cache.mjs";
4
4
  import { TypeBoxValidator } from "./validator/index.mjs";
5
5
  import { Intersect } from "./elysia/intersect.mjs";
6
- import { Ref } from "typebox/type";
7
- import { Compile } from "typebox/compile";
8
6
  import { Check, Clone, Create, Decode, Default, HasCodec } from "typebox/value";
7
+ import { Compile } from "typebox/compile";
8
+ import { Ref } from "typebox/type";
9
9
  import { Settings } from "typebox/system";
10
10
 
11
11
  //#region src/type/bridge-live.ts
@@ -4,8 +4,8 @@ import { TypeBoxValidatorCache as TypeBoxValidatorCache$1, mayHaveFileType as ma
4
4
  import { TypeBoxValidator as TypeBoxValidator$1 } from "./validator/index.js";
5
5
  import { applyCoercions as applyCoercions$1, coerceBody as coerceBody$1, coerceFormData as coerceFormData$1, coerceQuery as coerceQuery$1, coerceRoot as coerceRoot$1, coerceStringToStructure as coerceStringToStructure$1 } from "./coerce.js";
6
6
  import { Ref as Ref$1, TAny, TSchema } from "typebox/type";
7
- import { Compile as Compile$1 } from "typebox/compile";
8
7
  import { Check as Check$1, Clone as Clone$1, Create as Create$1, Decode as Decode$2, Default as Default$1, HasCodec as HasCodec$1 } from "typebox/value";
8
+ import { Compile as Compile$1 } from "typebox/compile";
9
9
 
10
10
  //#region src/type/bridge.d.ts
11
11
  interface TypeboxModule {