elysia 2.0.0-beta.2 → 2.0.0-beta.3

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 (145) hide show
  1. package/dist/adapter/utils.js +3 -3
  2. package/dist/adapter/utils.mjs +4 -4
  3. package/dist/adapter/web-standard/handler.js +5 -2
  4. package/dist/adapter/web-standard/handler.mjs +5 -2
  5. package/dist/base.d.ts +2 -2
  6. package/dist/base.js +42 -27
  7. package/dist/base.mjs +43 -28
  8. package/dist/compile/aot.d.ts +4 -4
  9. package/dist/compile/aot.js +14 -9
  10. package/dist/compile/aot.mjs +15 -9
  11. package/dist/compile/handler/descriptor.js +1 -1
  12. package/dist/compile/handler/descriptor.mjs +1 -1
  13. package/dist/compile/handler/index.d.ts +2 -2
  14. package/dist/compile/handler/index.js +6 -4
  15. package/dist/compile/handler/index.mjs +6 -4
  16. package/dist/compile/handler/utils.js +2 -2
  17. package/dist/compile/handler/utils.mjs +3 -3
  18. package/dist/context.js +3 -4
  19. package/dist/context.mjs +3 -4
  20. package/dist/cookie/config.d.ts +1 -0
  21. package/dist/cookie/config.js +3 -2
  22. package/dist/cookie/config.mjs +3 -2
  23. package/dist/cookie/cookie.d.ts +1 -0
  24. package/dist/cookie/cookie.js +6 -5
  25. package/dist/cookie/cookie.mjs +6 -5
  26. package/dist/cookie/crypto.d.ts +8 -7
  27. package/dist/cookie/crypto.js +38 -31
  28. package/dist/cookie/crypto.mjs +38 -32
  29. package/dist/cookie/error.js +1 -2
  30. package/dist/cookie/error.mjs +1 -2
  31. package/dist/cookie/lib.js +5 -1
  32. package/dist/cookie/lib.mjs +5 -1
  33. package/dist/cookie/serialize.js +1 -1
  34. package/dist/cookie/serialize.mjs +1 -1
  35. package/dist/cookie/types.d.ts +10 -0
  36. package/dist/cookie/utils.js +28 -14
  37. package/dist/cookie/utils.mjs +29 -15
  38. package/dist/handler/error.d.ts +23 -12
  39. package/dist/handler/error.js +24 -21
  40. package/dist/handler/error.mjs +20 -21
  41. package/dist/handler/fetch.js +6 -7
  42. package/dist/handler/fetch.mjs +7 -8
  43. package/dist/handler/utils.js +4 -2
  44. package/dist/handler/utils.mjs +5 -3
  45. package/dist/index.js +1 -8
  46. package/dist/package.js +1 -1
  47. package/dist/package.mjs +1 -1
  48. package/dist/plugin/aot/core.d.ts +22 -1
  49. package/dist/plugin/aot/core.js +35 -3
  50. package/dist/plugin/aot/core.mjs +35 -3
  51. package/dist/route-table.js +12 -10
  52. package/dist/route-table.mjs +12 -10
  53. package/dist/type/bridge-live.d.ts +1 -1
  54. package/dist/type/bridge-live.js +1 -1
  55. package/dist/type/bridge-live.mjs +1 -1
  56. package/dist/type/bridge.d.ts +1 -1
  57. package/dist/type/coerce-plan.js +3 -4
  58. package/dist/type/coerce-plan.mjs +1 -1
  59. package/dist/type/compat.d.ts +3 -0
  60. package/dist/type/compat.js +32 -14
  61. package/dist/type/compat.mjs +27 -8
  62. package/dist/type/elysia/array-buffer.js +2 -3
  63. package/dist/type/elysia/array-buffer.mjs +1 -1
  64. package/dist/type/elysia/array-string.js +7 -4
  65. package/dist/type/elysia/array-string.mjs +9 -5
  66. package/dist/type/elysia/boolean-string.js +2 -3
  67. package/dist/type/elysia/boolean-string.mjs +1 -1
  68. package/dist/type/elysia/boolean.js +4 -3
  69. package/dist/type/elysia/boolean.mjs +4 -2
  70. package/dist/type/elysia/cookie.js +2 -1
  71. package/dist/type/elysia/cookie.mjs +2 -1
  72. package/dist/type/elysia/date.js +7 -7
  73. package/dist/type/elysia/date.mjs +3 -2
  74. package/dist/type/elysia/file-type.d.ts +9 -2
  75. package/dist/type/elysia/file-type.js +16 -1
  76. package/dist/type/elysia/file-type.mjs +16 -2
  77. package/dist/type/elysia/file.js +8 -4
  78. package/dist/type/elysia/file.mjs +8 -3
  79. package/dist/type/elysia/files.js +6 -4
  80. package/dist/type/elysia/files.mjs +5 -2
  81. package/dist/type/elysia/form.js +2 -3
  82. package/dist/type/elysia/form.mjs +3 -3
  83. package/dist/type/elysia/integer-string.js +4 -5
  84. package/dist/type/elysia/integer-string.mjs +3 -3
  85. package/dist/type/elysia/integer.js +4 -3
  86. package/dist/type/elysia/integer.mjs +4 -2
  87. package/dist/type/elysia/maybe-empty.js +3 -4
  88. package/dist/type/elysia/maybe-empty.mjs +1 -1
  89. package/dist/type/elysia/nullable.js +2 -3
  90. package/dist/type/elysia/nullable.mjs +1 -1
  91. package/dist/type/elysia/number.js +4 -3
  92. package/dist/type/elysia/number.mjs +4 -2
  93. package/dist/type/elysia/numeric-enum.js +2 -3
  94. package/dist/type/elysia/numeric-enum.mjs +1 -1
  95. package/dist/type/elysia/numeric.js +5 -5
  96. package/dist/type/elysia/numeric.mjs +3 -2
  97. package/dist/type/elysia/object-string.js +7 -4
  98. package/dist/type/elysia/object-string.mjs +9 -5
  99. package/dist/type/elysia/string.js +4 -3
  100. package/dist/type/elysia/string.mjs +4 -2
  101. package/dist/type/elysia/uint8-array.js +2 -3
  102. package/dist/type/elysia/uint8-array.mjs +1 -1
  103. package/dist/type/elysia/union-enum.js +2 -3
  104. package/dist/type/elysia/union-enum.mjs +1 -1
  105. package/dist/type/elysia/utils.js +2 -3
  106. package/dist/type/elysia/utils.mjs +1 -1
  107. package/dist/type/exports.js +10 -1
  108. package/dist/type/exports.mjs +7 -0
  109. package/dist/type/index.d.ts +9 -1
  110. package/dist/type/index.js +41 -13
  111. package/dist/type/index.mjs +44 -9
  112. package/dist/type/typebox-type-live.d.ts +9 -0
  113. package/dist/type/typebox-type-live.js +31 -0
  114. package/dist/type/typebox-type-live.mjs +16 -0
  115. package/dist/type/typebox-type.d.ts +24 -0
  116. package/dist/type/typebox-type.js +130 -0
  117. package/dist/type/typebox-type.mjs +66 -0
  118. package/dist/type/typebox-value-live.d.ts +9 -0
  119. package/dist/type/typebox-value-live.js +27 -0
  120. package/dist/type/typebox-value-live.mjs +11 -0
  121. package/dist/type/typebox-value.d.ts +30 -0
  122. package/dist/type/typebox-value.js +147 -0
  123. package/dist/type/typebox-value.mjs +62 -0
  124. package/dist/type/validator/custom-error.js +4 -5
  125. package/dist/type/validator/custom-error.mjs +3 -3
  126. package/dist/type/validator/default-precompute.js +4 -5
  127. package/dist/type/validator/default-precompute.mjs +1 -1
  128. package/dist/type/validator/index.js +41 -35
  129. package/dist/type/validator/index.mjs +23 -16
  130. package/dist/type/validator/validator-cache.js +10 -5
  131. package/dist/type/validator/validator-cache.mjs +10 -4
  132. package/dist/universal/constants.d.ts +2 -1
  133. package/dist/universal/constants.js +3 -1
  134. package/dist/universal/constants.mjs +2 -1
  135. package/dist/utils.d.ts +10 -1
  136. package/dist/utils.js +18 -3
  137. package/dist/utils.mjs +14 -3
  138. package/dist/validator/index.js +2 -1
  139. package/dist/validator/index.mjs +2 -1
  140. package/dist/ws/context.d.ts +4 -0
  141. package/dist/ws/context.js +44 -26
  142. package/dist/ws/context.mjs +44 -26
  143. package/dist/ws/route.js +126 -23
  144. package/dist/ws/route.mjs +128 -25
  145. package/package.json +4 -2
@@ -156,6 +156,21 @@ interface StubPlan {
156
156
  * least one validator that is not bridge-free, so the bridge is still needed
157
157
  */
158
158
  bridge: boolean;
159
+ /**
160
+ * Re-route `type/typebox-value` -> its statically-imported `-live` mirror
161
+ * (bundlers can't follow the runtime `require`)
162
+ * Every mode except sealed, there the unresolvable `require` is what lets TypeBox collapse
163
+ */
164
+ typeboxValue: boolean;
165
+ /**
166
+ * Re-route `type/typebox-type` -> its `-live` mirror
167
+ * Every mode, sealed included (unlike `typeboxValue`), sealed still executes
168
+ * user `t.*()` at route definition and `typebox/type` is already in the bundle
169
+ * via the virtual `elysia/type` module
170
+ *
171
+ * skipping the rewrite collapses nothing and only buys a startup crash on loader-less runtimes
172
+ */
173
+ typeboxType: boolean;
159
174
  /**
160
175
  * Replace `adapter/constants` with a target-specific stub that hard-selects
161
176
  * either `BunAdapter` or `WebStandardAdapter`, letting the bundler DCE the
@@ -202,7 +217,13 @@ declare const NO_STUB: StubPlan;
202
217
  * is not active, so the bridge must stay wired the ordinary way. No compat
203
218
  * stub, no reroute.
204
219
  */
205
- declare function planFromReport(strip: boolean | 'auto', report: JITProbeResult, hasWS: boolean, mayTrace: boolean, aliases: Set<string>, allBridgeFree: boolean, zeroCapture: boolean, adapterStub?: 'bun' | 'web-standard' | false, productionStub?: boolean): {
220
+ declare function planFromReport(strip: boolean | 'auto', report: JITProbeResult, hasWS: boolean, mayTrace: boolean, aliases: Set<string>, allBridgeFree: boolean, zeroCapture: boolean, adapterStub?: 'bun' | 'web-standard' | false, productionStub?: boolean,
221
+ /**
222
+ * A WS route declares a `cookie` schema. Its upgrade path handles cookies
223
+ * outside the handler JIT, so it emits no `cc` alias — stubbing on that
224
+ * alias alone would hand `src/ws/route.ts` a throwing `parseCookieRaw`
225
+ */
226
+ wsCookie?: boolean): {
206
227
  plan: StubPlan;
207
228
  mode: BridgeMode;
208
229
  };
@@ -29,6 +29,8 @@ const NO_STUB = {
29
29
  sucrose: false,
30
30
  compat: false,
31
31
  bridge: false,
32
+ typeboxValue: false,
33
+ typeboxType: false,
32
34
  adapter: false,
33
35
  isProduction: false
34
36
  };
@@ -49,7 +51,7 @@ const NO_STUB = {
49
51
  * is not active, so the bridge must stay wired the ordinary way. No compat
50
52
  * stub, no reroute.
51
53
  */
52
- function planFromReport(strip, report, hasWS, mayTrace, aliases, allBridgeFree, zeroCapture, adapterStub = false, productionStub = true) {
54
+ function planFromReport(strip, report, hasWS, mayTrace, aliases, allBridgeFree, zeroCapture, adapterStub = false, productionStub = true, wsCookie = false) {
53
55
  const jit = report.jit;
54
56
  if (strip === true && !jit) throw new Error(`[elysia-aot] strip: true requires every route to be covered by the AOT handler manifest, but handler JIT is still reachable (${report.reasons.join(", ") || "unknown"}). Use strip: 'auto' to skip stubbing when the app is not fully precompiled.`);
55
57
  const mode = !jit ? "off" : allBridgeFree ? "sealed" : hasWS && zeroCapture ? "off" : "wired";
@@ -58,11 +60,13 @@ function planFromReport(strip, report, hasWS, mayTrace, aliases, allBridgeFree,
58
60
  jit,
59
61
  ws: !hasWS,
60
62
  reconstruct: jit && !aliases.has("va") && !aliases.has("cc") && !aliases.has("tr"),
61
- cookie: jit && !aliases.has("cc"),
63
+ cookie: jit && !aliases.has("cc") && !wsCookie,
62
64
  trace: !aliases.has("tr") && (jit || !mayTrace),
63
65
  sucrose: jit,
64
66
  compat: mode !== "off",
65
67
  bridge: mode === "wired",
68
+ typeboxValue: mode !== "sealed",
69
+ typeboxType: true,
66
70
  adapter: adapterStub,
67
71
  isProduction: productionStub
68
72
  },
@@ -172,6 +176,14 @@ const STUB_SOURCES = {
172
176
  bridge: [{
173
177
  filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]bridge\.(m?js|ts)$/,
174
178
  source: `export * from './bridge-live'\n`
179
+ }],
180
+ typeboxValue: [{
181
+ filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]typebox-value\.(m?js|ts)$/,
182
+ source: `export * from './typebox-value-live'\n`
183
+ }],
184
+ typeboxType: [{
185
+ filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]typebox-type\.(m?js|ts)$/,
186
+ source: `export * from './typebox-type-live'\n`
175
187
  }]
176
188
  };
177
189
  const alignStubExtensions = (stubSource, targetPath) => {
@@ -379,6 +391,21 @@ function isStandardResponse(response) {
379
391
  if (entries.length === 0) return false;
380
392
  return entries.every((v) => require_compile_handler_frozen_validator.isStandardSchema(v));
381
393
  }
394
+ /**
395
+ * The manifest is one flat `method -> path` table with no per-app namespace,
396
+ * bound to whichever app builds a router first, so a mounted sub-app (a second
397
+ * Elysia building on its own schedule) is not representable
398
+ *
399
+ * refuse at build time rather than ship a coin flip
400
+ */
401
+ const assertNoMount = (app, entry) => {
402
+ const routes = app["~routes"];
403
+ if (!routes) return;
404
+ const mounted = [];
405
+ for (const route of routes) if (route[2]?.["~mount"] && !mounted.includes(route[1])) mounted.push(route[1]);
406
+ if (!mounted.length) return;
407
+ throw new Error(`[elysia-aot] "${entry}" mounts a sub-app (${mounted.join(", ")}). AOT cannot compile a mounted sub-app. Compose with .use() instead of .mount(), or disable AOT plugin`);
408
+ };
382
409
  async function generateCompiledArtifacts(file, options) {
383
410
  const previousAotBuild = process.env.ELYSIA_AOT_BUILD;
384
411
  process.env.ELYSIA_AOT_BUILD = "1";
@@ -394,6 +421,7 @@ async function generateCompiledArtifacts(file, options) {
394
421
  const app = mod.app ?? mod.default;
395
422
  if (!app || typeof app.compile !== "function") throw new Error(`[elysia-aot] "${entry}" must export an Elysia app`);
396
423
  const typedApp = app;
424
+ assertNoMount(typedApp, entry);
397
425
  const sourceOptions = {
398
426
  register: true,
399
427
  registerFrom: options?.registerFrom,
@@ -408,6 +436,8 @@ async function generateCompiledArtifacts(file, options) {
408
436
  source: await require_plugin_aot_source.compileToSource(typedApp, sourceOptions),
409
437
  stub: {
410
438
  ...NO_STUB,
439
+ typeboxValue: true,
440
+ typeboxType: true,
411
441
  adapter: adapterStub,
412
442
  isProduction: productionStub
413
443
  },
@@ -422,9 +452,11 @@ async function generateCompiledArtifacts(file, options) {
422
452
  const mayTrace = !!typedApp["~hasTrace"] || history.some((route) => (route?.[4])?.trace?.length || route?.[2]?.["~mount"]);
423
453
  let expectedSlots = 0;
424
454
  let routesForbidSeal = false;
455
+ let wsCookie = false;
425
456
  for (const route of history) {
426
457
  const [, , , instance, hook, appHook, inheritedChain, macroScope] = route;
427
458
  const hooks = require_compile_handler_index.composeRouteHook(instance, hook, appHook, inheritedChain, typedApp, macroScope);
459
+ if (route[0] === "WS" && (hook?.cookie !== void 0 || hooks?.cookie !== void 0)) wsCookie = true;
428
460
  if (!hooks) continue;
429
461
  let routeHasTypeBoxDirectSlot = false;
430
462
  for (const slot of [
@@ -451,7 +483,7 @@ async function generateCompiledArtifacts(file, options) {
451
483
  }
452
484
  if (typedApp["~config"]?.normalize === "typebox") routesForbidSeal = true;
453
485
  const frozenSlots = artifacts.validators.length;
454
- const { plan: stub, mode } = planFromReport(strip, report, hasWS, mayTrace, aliases, (artifacts.handlers.length > 0 || artifacts.validators.length > 0) && !routesForbidSeal && frozenSlots === expectedSlots && artifacts.validators.every((v) => v.bridgeFree === true), artifacts.handlers.length === 0 && artifacts.validators.length === 0, adapterStub, productionStub);
486
+ const { plan: stub, mode } = planFromReport(strip, report, hasWS, mayTrace, aliases, (artifacts.handlers.length > 0 || artifacts.validators.length > 0) && !routesForbidSeal && frozenSlots === expectedSlots && artifacts.validators.every((v) => v.bridgeFree === true), artifacts.handlers.length === 0 && artifacts.validators.length === 0, adapterStub, productionStub, wsCookie);
455
487
  if (options?.target === "workerd") {
456
488
  if (!report.jit) throw new Error(`[elysia-aot] target 'workerd' but handler JIT is still reachable (${report.reasons.join(", ") || "unknown"}). Every route must be captured into the AOT manifest.`);
457
489
  if (frozenSlots !== expectedSlots) console.warn(`[elysia-aot] target 'workerd': only ${frozenSlots}/${expectedSlots} validator slots were frozen unfrozen slots compile at runtime and will fail on workerd.`);
@@ -27,6 +27,8 @@ const NO_STUB = {
27
27
  sucrose: false,
28
28
  compat: false,
29
29
  bridge: false,
30
+ typeboxValue: false,
31
+ typeboxType: false,
30
32
  adapter: false,
31
33
  isProduction: false
32
34
  };
@@ -47,7 +49,7 @@ const NO_STUB = {
47
49
  * is not active, so the bridge must stay wired the ordinary way. No compat
48
50
  * stub, no reroute.
49
51
  */
50
- function planFromReport(strip, report, hasWS, mayTrace, aliases, allBridgeFree, zeroCapture, adapterStub = false, productionStub = true) {
52
+ function planFromReport(strip, report, hasWS, mayTrace, aliases, allBridgeFree, zeroCapture, adapterStub = false, productionStub = true, wsCookie = false) {
51
53
  const jit = report.jit;
52
54
  if (strip === true && !jit) throw new Error(`[elysia-aot] strip: true requires every route to be covered by the AOT handler manifest, but handler JIT is still reachable (${report.reasons.join(", ") || "unknown"}). Use strip: 'auto' to skip stubbing when the app is not fully precompiled.`);
53
55
  const mode = !jit ? "off" : allBridgeFree ? "sealed" : hasWS && zeroCapture ? "off" : "wired";
@@ -56,11 +58,13 @@ function planFromReport(strip, report, hasWS, mayTrace, aliases, allBridgeFree,
56
58
  jit,
57
59
  ws: !hasWS,
58
60
  reconstruct: jit && !aliases.has("va") && !aliases.has("cc") && !aliases.has("tr"),
59
- cookie: jit && !aliases.has("cc"),
61
+ cookie: jit && !aliases.has("cc") && !wsCookie,
60
62
  trace: !aliases.has("tr") && (jit || !mayTrace),
61
63
  sucrose: jit,
62
64
  compat: mode !== "off",
63
65
  bridge: mode === "wired",
66
+ typeboxValue: mode !== "sealed",
67
+ typeboxType: true,
64
68
  adapter: adapterStub,
65
69
  isProduction: productionStub
66
70
  },
@@ -170,6 +174,14 @@ const STUB_SOURCES = {
170
174
  bridge: [{
171
175
  filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]bridge\.(m?js|ts)$/,
172
176
  source: `export * from './bridge-live'\n`
177
+ }],
178
+ typeboxValue: [{
179
+ filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]typebox-value\.(m?js|ts)$/,
180
+ source: `export * from './typebox-value-live'\n`
181
+ }],
182
+ typeboxType: [{
183
+ filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]typebox-type\.(m?js|ts)$/,
184
+ source: `export * from './typebox-type-live'\n`
173
185
  }]
174
186
  };
175
187
  const alignStubExtensions = (stubSource, targetPath) => {
@@ -377,6 +389,21 @@ function isStandardResponse(response) {
377
389
  if (entries.length === 0) return false;
378
390
  return entries.every((v) => isStandardSchema(v));
379
391
  }
392
+ /**
393
+ * The manifest is one flat `method -> path` table with no per-app namespace,
394
+ * bound to whichever app builds a router first, so a mounted sub-app (a second
395
+ * Elysia building on its own schedule) is not representable
396
+ *
397
+ * refuse at build time rather than ship a coin flip
398
+ */
399
+ const assertNoMount = (app, entry) => {
400
+ const routes = app["~routes"];
401
+ if (!routes) return;
402
+ const mounted = [];
403
+ for (const route of routes) if (route[2]?.["~mount"] && !mounted.includes(route[1])) mounted.push(route[1]);
404
+ if (!mounted.length) return;
405
+ throw new Error(`[elysia-aot] "${entry}" mounts a sub-app (${mounted.join(", ")}). AOT cannot compile a mounted sub-app. Compose with .use() instead of .mount(), or disable AOT plugin`);
406
+ };
380
407
  async function generateCompiledArtifacts(file, options) {
381
408
  const previousAotBuild = process.env.ELYSIA_AOT_BUILD;
382
409
  process.env.ELYSIA_AOT_BUILD = "1";
@@ -392,6 +419,7 @@ async function generateCompiledArtifacts(file, options) {
392
419
  const app = mod.app ?? mod.default;
393
420
  if (!app || typeof app.compile !== "function") throw new Error(`[elysia-aot] "${entry}" must export an Elysia app`);
394
421
  const typedApp = app;
422
+ assertNoMount(typedApp, entry);
395
423
  const sourceOptions = {
396
424
  register: true,
397
425
  registerFrom: options?.registerFrom,
@@ -406,6 +434,8 @@ async function generateCompiledArtifacts(file, options) {
406
434
  source: await compileToSource(typedApp, sourceOptions),
407
435
  stub: {
408
436
  ...NO_STUB,
437
+ typeboxValue: true,
438
+ typeboxType: true,
409
439
  adapter: adapterStub,
410
440
  isProduction: productionStub
411
441
  },
@@ -420,9 +450,11 @@ async function generateCompiledArtifacts(file, options) {
420
450
  const mayTrace = !!typedApp["~hasTrace"] || history.some((route) => (route?.[4])?.trace?.length || route?.[2]?.["~mount"]);
421
451
  let expectedSlots = 0;
422
452
  let routesForbidSeal = false;
453
+ let wsCookie = false;
423
454
  for (const route of history) {
424
455
  const [, , , instance, hook, appHook, inheritedChain, macroScope] = route;
425
456
  const hooks = composeRouteHook(instance, hook, appHook, inheritedChain, typedApp, macroScope);
457
+ if (route[0] === "WS" && (hook?.cookie !== void 0 || hooks?.cookie !== void 0)) wsCookie = true;
426
458
  if (!hooks) continue;
427
459
  let routeHasTypeBoxDirectSlot = false;
428
460
  for (const slot of [
@@ -449,7 +481,7 @@ async function generateCompiledArtifacts(file, options) {
449
481
  }
450
482
  if (typedApp["~config"]?.normalize === "typebox") routesForbidSeal = true;
451
483
  const frozenSlots = artifacts.validators.length;
452
- const { plan: stub, mode } = planFromReport(strip, report, hasWS, mayTrace, aliases, (artifacts.handlers.length > 0 || artifacts.validators.length > 0) && !routesForbidSeal && frozenSlots === expectedSlots && artifacts.validators.every((v) => v.bridgeFree === true), artifacts.handlers.length === 0 && artifacts.validators.length === 0, adapterStub, productionStub);
484
+ const { plan: stub, mode } = planFromReport(strip, report, hasWS, mayTrace, aliases, (artifacts.handlers.length > 0 || artifacts.validators.length > 0) && !routesForbidSeal && frozenSlots === expectedSlots && artifacts.validators.every((v) => v.bridgeFree === true), artifacts.handlers.length === 0 && artifacts.validators.length === 0, adapterStub, productionStub, wsCookie);
453
485
  if (options?.target === "workerd") {
454
486
  if (!report.jit) throw new Error(`[elysia-aot] target 'workerd' but handler JIT is still reachable (${report.reasons.join(", ") || "unknown"}). Every route must be captured into the AOT manifest.`);
455
487
  if (frozenSlots !== expectedSlots) console.warn(`[elysia-aot] target 'workerd': only ${frozenSlots}/${expectedSlots} validator slots were frozen unfrozen slots compile at runtime and will fail on workerd.`);
@@ -47,16 +47,18 @@ function buildRouteTable(declaredRoutes) {
47
47
  macroScope
48
48
  };
49
49
  }
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
- ];
50
+ const routeRow = (table, id) => {
51
+ return [
52
+ table.method[id],
53
+ table.path[id],
54
+ table.handler[id],
55
+ table.owner[id],
56
+ table.localHook[id],
57
+ table.appHook[id],
58
+ table.inheritedChain[id],
59
+ table.macroScope?.get(id)
60
+ ];
61
+ };
60
62
 
61
63
  //#endregion
62
64
  exports.RouteFlag = RouteFlag;
@@ -46,16 +46,18 @@ function buildRouteTable(declaredRoutes) {
46
46
  macroScope
47
47
  };
48
48
  }
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
- ];
49
+ const routeRow = (table, id) => {
50
+ return [
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
+ ];
60
+ };
59
61
 
60
62
  //#endregion
61
63
  export { RouteFlag, buildRouteTable, routeRow };
@@ -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,8 +5,8 @@ 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
8
  let typebox_compile = require("typebox/compile");
9
+ let typebox_type = require("typebox/type");
10
10
  let typebox_value = require("typebox/value");
11
11
  let typebox_system = require("typebox/system");
12
12
 
@@ -3,8 +3,8 @@ 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
6
  import { Compile } from "typebox/compile";
7
+ import { Ref } from "typebox/type";
8
8
  import { Check, Clone, Create, Decode, Default, HasCodec } from "typebox/value";
9
9
  import { Settings } from "typebox/system";
10
10
 
@@ -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 {
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.js');
3
2
  const require_utils = require('../utils.js');
4
3
  const require_type_constants = require('./constants.js');
5
4
  const require_type_shared = require('./shared.js');
5
+ const require_type_typebox_type = require('./typebox-type.js');
6
6
  const require_type_elysia_array = require('./elysia/array.js');
7
7
  const require_type_elysia_string = require('./elysia/string.js');
8
8
  const require_type_elysia_union = require('./elysia/union.js');
@@ -11,7 +11,6 @@ const require_type_elysia_object = require('./elysia/object.js');
11
11
  const require_type_elysia_numeric = require('./elysia/numeric.js');
12
12
  const require_type_elysia_boolean_string = require('./elysia/boolean-string.js');
13
13
  const require_type_elysia_integer_string = require('./elysia/integer-string.js');
14
- let typebox_type = require("typebox/type");
15
14
 
16
15
  //#region src/type/coerce-plan.ts
17
16
  const COERCE_LEAF_CTOR = {
@@ -28,13 +27,13 @@ const icPlaceholder = () => {
28
27
  function ObjectStringShape(property, _options) {
29
28
  const [{ properties, ...constraints }, meta] = require_type_elysia_utils.getMeta(_options ?? require_utils.nullObject());
30
29
  const object = require_type_elysia_object.ObjectType(property, constraints);
31
- const objectString = (0, typebox_type.Decode)((0, typebox_type.Refine)(require_type_elysia_string.StringType(), icPlaceholder, () => "must be an object"), icPlaceholder);
30
+ const objectString = require_type_typebox_type.Decode(require_type_typebox_type.Refine(require_type_elysia_string.StringType(), icPlaceholder, () => "must be an object"), icPlaceholder);
32
31
  return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ObjectString, require_type_elysia_union.Union([object, objectString], meta));
33
32
  }
34
33
  function ArrayStringShape(property, _options) {
35
34
  const [constraints, meta] = require_type_elysia_utils.getMeta(_options ?? require_utils.nullObject());
36
35
  const array = require_type_elysia_array.ArrayType(property, constraints);
37
- const arrayString = (0, typebox_type.Decode)((0, typebox_type.Refine)(require_type_elysia_string.StringType(), icPlaceholder, () => "must be an array"), icPlaceholder);
36
+ const arrayString = require_type_typebox_type.Decode(require_type_typebox_type.Refine(require_type_elysia_string.StringType(), icPlaceholder, () => "must be an array"), icPlaceholder);
38
37
  return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ArrayString, require_type_elysia_union.Union([array, arrayString], meta));
39
38
  }
40
39
  const rebuildObjStrShape = (original, site) => {
@@ -1,6 +1,7 @@
1
1
  import { evictOldestHalf, nullObject } from "../utils.mjs";
2
2
  import { ELYSIA_TYPES } from "./constants.mjs";
3
3
  import { clearCoerceLeafCache, coerceLeafCache, coerceLeafCacheSize } from "./shared.mjs";
4
+ import { Decode, Refine } from "./typebox-type.mjs";
4
5
  import { ArrayType } from "./elysia/array.mjs";
5
6
  import { StringType } from "./elysia/string.mjs";
6
7
  import { Union } from "./elysia/union.mjs";
@@ -9,7 +10,6 @@ import { ObjectType } from "./elysia/object.mjs";
9
10
  import { Numeric } from "./elysia/numeric.mjs";
10
11
  import { BooleanString } from "./elysia/boolean-string.mjs";
11
12
  import { IntegerString } from "./elysia/integer-string.mjs";
12
- import { Decode, Refine } from "typebox/type";
13
13
 
14
14
  //#region src/type/coerce-plan.ts
15
15
  const COERCE_LEAF_CTOR = {
@@ -1,8 +1,11 @@
1
+ import { TypeboxTypeNamespaces } from "./typebox-type.js";
2
+ import { TypeboxNamespaces } from "./typebox-value.js";
1
3
  import { CreateMirror } from "./validator/exact-mirror.js";
2
4
 
3
5
  //#region src/type/compat.d.ts
4
6
  declare function setupTypebox(options?: {
5
7
  exactMirror?: CreateMirror;
8
+ typebox?: Partial<TypeboxNamespaces & TypeboxTypeNamespaces>;
6
9
  }): void;
7
10
  //#endregion
8
11
  export { setupTypebox };
@@ -1,28 +1,46 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.js');
3
2
  const require_type_bridge = require('./bridge.js');
4
3
  const require_type_utils = require('./utils.js');
4
+ const require_type_typebox_type = require('./typebox-type.js');
5
+ const require_type_typebox_value = require('./typebox-value.js');
5
6
  const require_type_coerce = require('./coerce.js');
6
7
  const require_type_validator_exact_mirror = require('./validator/exact-mirror.js');
7
8
  const require_type_validator_validator_cache = require('./validator/validator-cache.js');
8
9
  const require_type_validator_index = require('./validator/index.js');
9
10
  const require_type_elysia_intersect = require('./elysia/intersect.js');
10
- let typebox_type = require("typebox/type");
11
- let typebox_compile = require("typebox/compile");
12
- let typebox_value = require("typebox/value");
13
- let typebox_system = require("typebox/system");
14
11
 
15
12
  //#region src/type/compat.ts
16
13
  let setup = false;
17
14
  function setupTypebox(options) {
18
15
  if (options?.exactMirror) require_type_validator_exact_mirror.setExactMirror(options.exactMirror);
16
+ const typebox = options?.typebox;
17
+ if (typebox) {
18
+ const typeSide = [typebox.type, typebox.system];
19
+ const typeSideProvided = typeSide.filter(Boolean).length;
20
+ if (typeSideProvided > 0 && typeSideProvided < typeSide.length) throw new Error(`setupTypebox({ typebox }) received an incomplete type-side namespace (only '${typebox.type ? "type" : "system"}' was set). 'type' and 'system' must be provided together.`);
21
+ const valueSide = [
22
+ typebox.value,
23
+ typebox.schema,
24
+ typebox.compile
25
+ ];
26
+ const valueSideProvided = valueSide.filter(Boolean).length;
27
+ if (valueSideProvided > 0 && valueSideProvided < valueSide.length) {
28
+ const missing = [
29
+ "value",
30
+ "schema",
31
+ "compile"
32
+ ].filter((key) => !typebox[key]);
33
+ throw new Error(`setupTypebox({ typebox }) received an incomplete value-side namespace (missing '${missing.join("', '")}'). 'value', 'schema', and 'compile' must be provided together.`);
34
+ }
35
+ if (typebox.type && typebox.system) require_type_typebox_type.injectTypeboxType(typebox);
36
+ if (typebox.value && typebox.schema && typebox.compile) require_type_typebox_value.injectTypebox(typebox);
37
+ }
19
38
  if (setup) return;
20
39
  setup = true;
21
- typebox_system.Settings.Set({ unionPrioritySort: false });
22
40
  require_type_bridge.useTypebox({
23
- Compile: typebox_compile.Compile,
24
- Create: typebox_value.Create,
25
- Decode: typebox_value.Decode,
41
+ Compile: require_type_typebox_value.Compile,
42
+ Create: require_type_typebox_value.Create,
43
+ Decode: require_type_typebox_value.Decode,
26
44
  applyCoercions: require_type_coerce.applyCoercions,
27
45
  TypeBoxValidator: require_type_validator_index.TypeBoxValidator,
28
46
  TypeBoxValidatorCache: require_type_validator_validator_cache.TypeBoxValidatorCache,
@@ -33,12 +51,12 @@ function setupTypebox(options) {
33
51
  coerceBody: require_type_coerce.coerceBody,
34
52
  hasTypes: require_type_utils.hasTypes,
35
53
  mayHaveFileType: require_type_validator_validator_cache.mayHaveFileType,
36
- HasCodec: typebox_value.HasCodec,
54
+ HasCodec: require_type_typebox_value.HasCodec,
37
55
  Intersect: require_type_elysia_intersect.Intersect,
38
- Default: typebox_value.Default,
39
- Ref: typebox_type.Ref,
40
- Clone: typebox_value.Clone,
41
- Check: typebox_value.Check
56
+ Default: require_type_typebox_value.Default,
57
+ Ref: require_type_typebox_type.Ref,
58
+ Clone: require_type_typebox_value.Clone,
59
+ Check: require_type_typebox_value.Check
42
60
  });
43
61
  }
44
62
 
@@ -1,26 +1,45 @@
1
1
  import { useTypebox } from "./bridge.mjs";
2
2
  import { hasTypes } from "./utils.mjs";
3
+ import { Ref, injectTypeboxType } from "./typebox-type.mjs";
4
+ import { Check, Clone, Compile, Create, Decode, Default, HasCodec, injectTypebox } from "./typebox-value.mjs";
3
5
  import { applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure } from "./coerce.mjs";
4
6
  import { setExactMirror } from "./validator/exact-mirror.mjs";
5
7
  import { TypeBoxValidatorCache, mayHaveFileType } from "./validator/validator-cache.mjs";
6
8
  import { TypeBoxValidator } from "./validator/index.mjs";
7
- import { Intersect as Intersect$1 } from "./elysia/intersect.mjs";
8
- import { Ref } from "typebox/type";
9
- import { Compile } from "typebox/compile";
10
- import { Check, Clone, Create, Decode as Decode$1, Default, HasCodec } from "typebox/value";
11
- import { Settings } from "typebox/system";
9
+ import { Intersect } from "./elysia/intersect.mjs";
12
10
 
13
11
  //#region src/type/compat.ts
14
12
  let setup = false;
15
13
  function setupTypebox(options) {
16
14
  if (options?.exactMirror) setExactMirror(options.exactMirror);
15
+ const typebox = options?.typebox;
16
+ if (typebox) {
17
+ const typeSide = [typebox.type, typebox.system];
18
+ const typeSideProvided = typeSide.filter(Boolean).length;
19
+ if (typeSideProvided > 0 && typeSideProvided < typeSide.length) throw new Error(`setupTypebox({ typebox }) received an incomplete type-side namespace (only '${typebox.type ? "type" : "system"}' was set). 'type' and 'system' must be provided together.`);
20
+ const valueSide = [
21
+ typebox.value,
22
+ typebox.schema,
23
+ typebox.compile
24
+ ];
25
+ const valueSideProvided = valueSide.filter(Boolean).length;
26
+ if (valueSideProvided > 0 && valueSideProvided < valueSide.length) {
27
+ const missing = [
28
+ "value",
29
+ "schema",
30
+ "compile"
31
+ ].filter((key) => !typebox[key]);
32
+ throw new Error(`setupTypebox({ typebox }) received an incomplete value-side namespace (missing '${missing.join("', '")}'). 'value', 'schema', and 'compile' must be provided together.`);
33
+ }
34
+ if (typebox.type && typebox.system) injectTypeboxType(typebox);
35
+ if (typebox.value && typebox.schema && typebox.compile) injectTypebox(typebox);
36
+ }
17
37
  if (setup) return;
18
38
  setup = true;
19
- Settings.Set({ unionPrioritySort: false });
20
39
  useTypebox({
21
40
  Compile,
22
41
  Create,
23
- Decode: Decode$1,
42
+ Decode,
24
43
  applyCoercions,
25
44
  TypeBoxValidator,
26
45
  TypeBoxValidatorCache,
@@ -32,7 +51,7 @@ function setupTypebox(options) {
32
51
  hasTypes,
33
52
  mayHaveFileType,
34
53
  HasCodec,
35
- Intersect: Intersect$1,
54
+ Intersect,
36
55
  Default,
37
56
  Ref,
38
57
  Clone,
@@ -1,15 +1,14 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../../_virtual/_rolldown/runtime.js');
3
2
  const require_utils = require('../../utils.js');
4
3
  const require_type_constants = require('../constants.js');
4
+ const require_type_typebox_type = require('../typebox-type.js');
5
5
  const require_type_elysia_utils = require('./utils.js');
6
- let typebox_type = require("typebox/type");
7
6
 
8
7
  //#region src/type/elysia/array-buffer.ts
9
8
  let BaseArrayBuffer;
10
9
  let emptyArrayBuffer;
11
10
  function ArrayBufferType(property) {
12
- BaseArrayBuffer ??= (0, typebox_type.Refine)((0, typebox_type.Unsafe)({ "~kind": "ArrayBuffer" }), (value) => value instanceof ArrayBuffer, () => "must be ArrayBuffer");
11
+ BaseArrayBuffer ??= require_type_typebox_type.Refine(require_type_typebox_type.Unsafe({ "~kind": "ArrayBuffer" }), (value) => value instanceof ArrayBuffer, () => "must be ArrayBuffer");
13
12
  if (!property || require_utils.isEmpty(property)) return emptyArrayBuffer ??= Object.freeze(require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ArrayBuffer, BaseArrayBuffer));
14
13
  const refines = [[(value) => value instanceof ArrayBuffer, "must be ArrayBuffer"]];
15
14
  if (property.minByteLength !== void 0) refines.push([(value) => value.byteLength >= property.minByteLength, `Expect byte to be more than ${property.minByteLength}`]);
@@ -1,7 +1,7 @@
1
1
  import { isEmpty } from "../../utils.mjs";
2
2
  import { ELYSIA_TYPES } from "../constants.mjs";
3
+ import { Refine, Unsafe } from "../typebox-type.mjs";
3
4
  import { Refines, cloneSchema, elyType, getMeta } from "./utils.mjs";
4
- import { Refine, Unsafe } from "typebox/type";
5
5
 
6
6
  //#region src/type/elysia/array-buffer.ts
7
7
  let BaseArrayBuffer;
@@ -1,13 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../../_virtual/_rolldown/runtime.js');
3
2
  const require_utils = require('../../utils.js');
4
3
  const require_type_bridge = require('../bridge.js');
5
4
  const require_type_constants = require('../constants.js');
5
+ const require_type_typebox_type = require('../typebox-type.js');
6
6
  const require_type_elysia_array = require('./array.js');
7
7
  const require_type_elysia_string = require('./string.js');
8
8
  const require_type_elysia_union = require('./union.js');
9
9
  const require_type_elysia_utils = require('./utils.js');
10
- let typebox_type = require("typebox/type");
11
10
 
12
11
  //#region src/type/elysia/array-string.ts
13
12
  const MEMO_LIMIT = 8192;
@@ -28,18 +27,22 @@ function ArrayString(property, _options) {
28
27
  };
29
28
  let raw;
30
29
  let parsed;
31
- const arrayString = (0, typebox_type.Decode)((0, typebox_type.Refine)(require_type_elysia_string.StringType(), (value) => {
30
+ const arrayString = require_type_typebox_type.Decode(require_type_typebox_type.Refine(require_type_elysia_string.StringType(), (value) => {
32
31
  if (value.charCodeAt(0) !== 91) return false;
33
32
  if (value === raw) return true;
34
33
  try {
35
34
  const next = JSON.parse(value);
36
- if (!checkInner(next)) return false;
35
+ if (!checkInner(next)) {
36
+ raw = parsed = void 0;
37
+ return false;
38
+ }
37
39
  if (value.length <= MEMO_LIMIT) {
38
40
  raw = value;
39
41
  parsed = next;
40
42
  }
41
43
  return true;
42
44
  } catch {
45
+ raw = parsed = void 0;
43
46
  return false;
44
47
  }
45
48
  }, () => "must be an array"), (value) => {