elysia 2.0.0-beta.21 → 2.0.0-beta.23

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 (217) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +1 -0
  2. package/dist/adapter/bun/index.d.ts +6 -8
  3. package/dist/adapter/bun/index.js +6 -8
  4. package/dist/adapter/bun/index.mjs +7 -8
  5. package/dist/adapter/constants.mjs +1 -0
  6. package/dist/adapter/default-headers.mjs +1 -0
  7. package/dist/adapter/index.mjs +1 -0
  8. package/dist/adapter/origin.mjs +1 -0
  9. package/dist/adapter/response-ownership.mjs +1 -0
  10. package/dist/adapter/skip-clone.mjs +1 -0
  11. package/dist/adapter/types.mjs +1 -0
  12. package/dist/adapter/utils.d.ts +5 -8
  13. package/dist/adapter/utils.js +24 -18
  14. package/dist/adapter/utils.mjs +25 -18
  15. package/dist/adapter/web-standard/handler.mjs +2 -1
  16. package/dist/adapter/web-standard/index.mjs +1 -0
  17. package/dist/adapter/web-standard/utils.mjs +1 -0
  18. package/dist/base.d.ts +118 -69
  19. package/dist/base.js +214 -194
  20. package/dist/base.mjs +221 -200
  21. package/dist/compile/aot-capture.js +2 -2
  22. package/dist/compile/aot-capture.mjs +4 -3
  23. package/dist/compile/aot-emit.js +7 -8
  24. package/dist/compile/aot-emit.mjs +8 -8
  25. package/dist/compile/aot-reconstruct.mjs +3 -2
  26. package/dist/compile/aot.d.ts +3 -3
  27. package/dist/compile/aot.js +5 -5
  28. package/dist/compile/aot.mjs +6 -5
  29. package/dist/compile/handler/descriptor.d.ts +2 -5
  30. package/dist/compile/handler/descriptor.js +12 -17
  31. package/dist/compile/handler/descriptor.mjs +16 -21
  32. package/dist/compile/handler/frozen-validator.d.ts +2 -2
  33. package/dist/compile/handler/frozen-validator.js +3 -3
  34. package/dist/compile/handler/frozen-validator.mjs +4 -3
  35. package/dist/compile/handler/index.d.ts +3 -1
  36. package/dist/compile/handler/index.js +78 -118
  37. package/dist/compile/handler/index.mjs +84 -125
  38. package/dist/compile/handler/jit.d.ts +12 -12
  39. package/dist/compile/handler/jit.js +60 -43
  40. package/dist/compile/handler/jit.mjs +63 -47
  41. package/dist/compile/handler/params.d.ts +5 -1
  42. package/dist/compile/handler/params.js +14 -5
  43. package/dist/compile/handler/params.mjs +16 -7
  44. package/dist/compile/handler/reconstruct.d.ts +2 -2
  45. package/dist/compile/handler/reconstruct.js +2 -2
  46. package/dist/compile/handler/reconstruct.mjs +3 -2
  47. package/dist/compile/handler/static-clone-resolver.mjs +1 -0
  48. package/dist/compile/handler/utils.d.ts +13 -7
  49. package/dist/compile/handler/utils.js +75 -52
  50. package/dist/compile/handler/utils.mjs +77 -54
  51. package/dist/compile/jit-probe.mjs +1 -0
  52. package/dist/compile/lexer.js +4 -4
  53. package/dist/compile/lexer.mjs +5 -4
  54. package/dist/compile/utils.d.ts +2 -1
  55. package/dist/compile/utils.js +8 -3
  56. package/dist/compile/utils.mjs +8 -3
  57. package/dist/compiled.mjs +1 -0
  58. package/dist/constants.mjs +1 -0
  59. package/dist/context.d.ts +1 -1
  60. package/dist/context.js +1 -0
  61. package/dist/context.mjs +3 -1
  62. package/dist/cookie/config.d.ts +2 -2
  63. package/dist/cookie/config.js +21 -26
  64. package/dist/cookie/config.mjs +22 -26
  65. package/dist/cookie/cookie.mjs +1 -0
  66. package/dist/cookie/crypto.mjs +1 -0
  67. package/dist/cookie/error.mjs +1 -0
  68. package/dist/cookie/lib.mjs +1 -0
  69. package/dist/cookie/serialize.mjs +1 -0
  70. package/dist/cookie/types.mjs +1 -0
  71. package/dist/cookie/utils.d.ts +1 -1
  72. package/dist/cookie/utils.js +64 -45
  73. package/dist/cookie/utils.mjs +66 -46
  74. package/dist/error.d.ts +10 -6
  75. package/dist/error.js +22 -6
  76. package/dist/error.mjs +25 -9
  77. package/dist/generation.mjs +1 -0
  78. package/dist/handler/error.d.ts +12 -15
  79. package/dist/handler/error.js +43 -40
  80. package/dist/handler/error.mjs +45 -41
  81. package/dist/handler/fetch.js +59 -21
  82. package/dist/handler/fetch.mjs +61 -22
  83. package/dist/handler/utils.d.ts +16 -3
  84. package/dist/handler/utils.js +14 -13
  85. package/dist/handler/utils.mjs +16 -15
  86. package/dist/index.d.ts +9 -9
  87. package/dist/index.js +1 -0
  88. package/dist/index.mjs +3 -2
  89. package/dist/memory.mjs +1 -0
  90. package/dist/package.js +1 -1
  91. package/dist/package.mjs +2 -1
  92. package/dist/parse-query.js +76 -76
  93. package/dist/parse-query.mjs +77 -76
  94. package/dist/plugin/aot/bun.mjs +1 -0
  95. package/dist/plugin/aot/core.d.ts +1 -1
  96. package/dist/plugin/aot/core.js +7 -4
  97. package/dist/plugin/aot/core.mjs +8 -5
  98. package/dist/plugin/aot/esbuild.mjs +1 -0
  99. package/dist/plugin/aot/rspack-loader.mjs +1 -0
  100. package/dist/plugin/aot/rspack.mjs +1 -0
  101. package/dist/plugin/aot/treeshake.mjs +1 -0
  102. package/dist/plugin/aot/unplugin.mjs +4 -3
  103. package/dist/plugin/aot/vite.mjs +1 -0
  104. package/dist/plugin/aot/worker.mjs +1 -0
  105. package/dist/plugin/auto-head.mjs +1 -0
  106. package/dist/plugin/trace.mjs +1 -0
  107. package/dist/plugin/websocket.mjs +1 -0
  108. package/dist/route-table.mjs +1 -0
  109. package/dist/schema-snapshot.js +28 -3
  110. package/dist/schema-snapshot.mjs +29 -3
  111. package/dist/sucrose.d.ts +2 -2
  112. package/dist/sucrose.js +11 -11
  113. package/dist/sucrose.mjs +12 -11
  114. package/dist/trace.js +8 -10
  115. package/dist/trace.mjs +10 -11
  116. package/dist/type/bridge-live.d.ts +1 -1
  117. package/dist/type/bridge-live.mjs +1 -0
  118. package/dist/type/bridge.d.ts +1 -1
  119. package/dist/type/bridge.mjs +1 -0
  120. package/dist/type/coerce-plan.mjs +1 -0
  121. package/dist/type/coerce.d.ts +1 -1
  122. package/dist/type/coerce.mjs +1 -0
  123. package/dist/type/compat.mjs +1 -0
  124. package/dist/type/constants.d.ts +1 -1
  125. package/dist/type/constants.mjs +1 -0
  126. package/dist/type/elysia/accelerate.mjs +1 -0
  127. package/dist/type/elysia/array-buffer.d.ts +3 -2
  128. package/dist/type/elysia/array-buffer.js +5 -5
  129. package/dist/type/elysia/array-buffer.mjs +6 -5
  130. package/dist/type/elysia/array-string.mjs +1 -0
  131. package/dist/type/elysia/array.mjs +1 -0
  132. package/dist/type/elysia/boolean-string.mjs +1 -0
  133. package/dist/type/elysia/boolean.mjs +1 -0
  134. package/dist/type/elysia/cookie.mjs +1 -0
  135. package/dist/type/elysia/date.mjs +1 -0
  136. package/dist/type/elysia/file-type.mjs +1 -0
  137. package/dist/type/elysia/file.mjs +1 -0
  138. package/dist/type/elysia/files.mjs +1 -0
  139. package/dist/type/elysia/form.mjs +1 -0
  140. package/dist/type/elysia/integer-string.mjs +1 -0
  141. package/dist/type/elysia/integer.mjs +1 -0
  142. package/dist/type/elysia/intersect.mjs +1 -0
  143. package/dist/type/elysia/json-string.mjs +1 -0
  144. package/dist/type/elysia/keep-config.js +8 -8
  145. package/dist/type/elysia/keep-config.mjs +9 -8
  146. package/dist/type/elysia/maybe-empty.mjs +1 -0
  147. package/dist/type/elysia/no-validate.mjs +1 -0
  148. package/dist/type/elysia/nullable.mjs +1 -0
  149. package/dist/type/elysia/number.mjs +1 -0
  150. package/dist/type/elysia/numeric-enum.d.ts +4 -2
  151. package/dist/type/elysia/numeric-enum.mjs +1 -0
  152. package/dist/type/elysia/numeric.mjs +1 -0
  153. package/dist/type/elysia/object-string.mjs +1 -0
  154. package/dist/type/elysia/object.mjs +1 -0
  155. package/dist/type/elysia/optional.mjs +1 -0
  156. package/dist/type/elysia/problem.mjs +1 -0
  157. package/dist/type/elysia/string.mjs +1 -0
  158. package/dist/type/elysia/uint8-array.d.ts +2 -1
  159. package/dist/type/elysia/uint8-array.js +2 -2
  160. package/dist/type/elysia/uint8-array.mjs +3 -2
  161. package/dist/type/elysia/union-enum.mjs +1 -0
  162. package/dist/type/elysia/union.mjs +1 -0
  163. package/dist/type/elysia/utils.js +3 -3
  164. package/dist/type/elysia/utils.mjs +4 -3
  165. package/dist/type/exports.mjs +1 -0
  166. package/dist/type/index.mjs +2 -1
  167. package/dist/type/shared.mjs +1 -0
  168. package/dist/type/sync-require.mjs +1 -0
  169. package/dist/type/typebox-system-lite.mjs +1 -0
  170. package/dist/type/typebox-system-require.mjs +1 -0
  171. package/dist/type/typebox-type-live.mjs +1 -0
  172. package/dist/type/typebox-value-live.mjs +1 -0
  173. package/dist/type/typebox-value-ops.mjs +1 -0
  174. package/dist/type/typebox-value.mjs +1 -0
  175. package/dist/type/types.d.ts +1 -1
  176. package/dist/type/types.mjs +1 -0
  177. package/dist/type/utils.mjs +1 -0
  178. package/dist/type/validator/clean-safe.mjs +1 -0
  179. package/dist/type/validator/custom-error.js +41 -33
  180. package/dist/type/validator/custom-error.mjs +42 -33
  181. package/dist/type/validator/default-precompute.d.ts +2 -2
  182. package/dist/type/validator/default-precompute.js +10 -11
  183. package/dist/type/validator/default-precompute.mjs +13 -13
  184. package/dist/type/validator/exact-mirror.mjs +1 -0
  185. package/dist/type/validator/frozen-check.js +7 -7
  186. package/dist/type/validator/frozen-check.mjs +8 -7
  187. package/dist/type/validator/index.d.ts +2 -2
  188. package/dist/type/validator/index.js +4 -8
  189. package/dist/type/validator/index.mjs +5 -8
  190. package/dist/type/validator/string-codec-aot.d.ts +1 -1
  191. package/dist/type/validator/string-codec-aot.mjs +1 -0
  192. package/dist/type/validator/validator-cache.js +18 -18
  193. package/dist/type/validator/validator-cache.mjs +19 -18
  194. package/dist/types.d.ts +108 -70
  195. package/dist/types.mjs +1 -0
  196. package/dist/universal/constants.mjs +1 -0
  197. package/dist/universal/file.mjs +1 -0
  198. package/dist/universal/index.mjs +1 -0
  199. package/dist/universal/is-production.mjs +1 -0
  200. package/dist/universal/server.mjs +1 -0
  201. package/dist/utils.d.ts +49 -31
  202. package/dist/utils.js +221 -109
  203. package/dist/utils.mjs +215 -106
  204. package/dist/validator/index.d.ts +3 -3
  205. package/dist/validator/index.js +4 -4
  206. package/dist/validator/index.mjs +5 -4
  207. package/dist/validator/route.d.ts +2 -2
  208. package/dist/validator/route.mjs +1 -0
  209. package/dist/ws/context.js +1 -1
  210. package/dist/ws/context.mjs +2 -1
  211. package/dist/ws/index.mjs +1 -0
  212. package/dist/ws/parser.mjs +1 -0
  213. package/dist/ws/route.js +34 -25
  214. package/dist/ws/route.mjs +40 -30
  215. package/dist/ws/types.d.ts +2 -3
  216. package/dist/ws/types.mjs +1 -0
  217. package/package.json +2 -2
@@ -1,5 +1,6 @@
1
+ import { isResponseParam } from "../../compile/handler/params.mjs";
1
2
  import { REQUEST_SLOTS, isResponseMap, isStandardSchema, mergeSchemasAllStandard, resolveModelRef } from "../../compile/handler/frozen-validator.mjs";
2
- import { composeRouteHook } from "../../compile/handler/index.mjs";
3
+ import { composeRouteHook, runIntrospect } from "../../compile/handler/index.mjs";
3
4
  import { captureArtifacts, compileToSource, replayStubbability } from "./source.mjs";
4
5
  import { createRequire } from "node:module";
5
6
  import { existsSync, readFileSync, realpathSync } from "node:fs";
@@ -140,7 +141,7 @@ const STUB_SOURCES = {
140
141
  source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function compileHandlerJit(){return e()}\nexport function createInlineHandler(){return e()}\nexport function setCaptureHeaderShorthand(){}\n"
141
142
  }, {
142
143
  filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]descriptor\.(m?js|ts)$/,
143
- source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function describeRoute(){return e()}\nexport const routeDescriptors=new WeakMap()\n"
144
+ source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function describeRoute(){return e()}\nexport function releaseAnalysisCaches(){}\nexport const routeDescriptors=new WeakMap()\n"
144
145
  }],
145
146
  ws: [{
146
147
  filter: /[\\/]elysia[\\/](dist|src)[\\/]ws[\\/]route\.(m?js|ts)$/,
@@ -148,7 +149,7 @@ const STUB_SOURCES = {
148
149
  }],
149
150
  reconstruct: [{
150
151
  filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]reconstruct\.(m?js|ts)$/,
151
- source: "const e=()=>{throw new Error(\"[elysia-aot] handler reconstruction was stripped (strip mode) but a route needed it. Rebuild with strip:false.\")}\nexport class Reconstrct {\n static validator(){return e()}\n static cookie(){return e()}\n static trace(){return e()}\n}\n"
152
+ source: "const e=()=>{throw new Error(\"[elysia-aot] handler reconstruction was stripped (strip mode) but a route needed it. Rebuild with strip:false.\")}\nexport class Reconstruct {\n static validator(){return e()}\n static cookie(){return e()}\n static trace(){return e()}\n}\n"
152
153
  }],
153
154
  cookie: [
154
155
  {
@@ -489,7 +490,7 @@ async function generateCompiledArtifacts(file, options, moduleCondition = resolv
489
490
  const artifacts = await captureArtifacts(typedApp, sourceOptions);
490
491
  const report = replayStubbability(typedApp, artifacts.handlers);
491
492
  const aliases = /* @__PURE__ */ new Set();
492
- for (const handler of artifacts.handlers) if (handler.alias) for (const name of handler.alias.split(",")) aliases.add(name);
493
+ for (const handler of artifacts.handlers) if (handler.alias) for (const name of handler.alias.split(",")) aliases.add(isResponseParam(name) ? "va" : name);
493
494
  const history = typedApp["~routes"];
494
495
  const hasWS = !!typedApp["~hasWS"] || history.some((route) => route[0] === "WS");
495
496
  const mayTrace = !!typedApp["~hasTrace"] || history.some((route) => (route?.[4])?.trace?.length || route?.[2]?.["~mount"]);
@@ -515,6 +516,7 @@ async function generateCompiledArtifacts(file, options, moduleCondition = resolv
515
516
  };
516
517
  const [, , , instance, hook, appHook, inheritedChain, macroScope] = route;
517
518
  const hooks = composeRouteHook(instance, hook, appHook, inheritedChain, typedApp, macroScope);
519
+ runIntrospect(hooks);
518
520
  if (method === "WS" && (hook?.cookie !== void 0 || hooks?.cookie !== void 0)) wsCookie = true;
519
521
  if (!hooks) continue;
520
522
  let routeHasTypeBoxDirectSlot = false;
@@ -543,7 +545,8 @@ async function generateCompiledArtifacts(file, options, moduleCondition = resolv
543
545
  }
544
546
  if (typedApp["~config"]?.normalize === "typebox") routesForbidSeal = true;
545
547
  const validatorSlotsMatch = validatorSlotSetsMatch(expectedSlots, artifacts.validators);
546
- const { plan: stub, mode } = planFromReport(strip, report, hasWS, mayTrace, aliases, (artifacts.handlers.some((h) => h.code) || artifacts.validators.length > 0) && !routesForbidSeal && validatorSlotsMatch && artifacts.validators.every((v) => v.bridgeFree === true), !artifacts.handlers.some((h) => h.code) && artifacts.validators.length === 0, adapterStub, productionStub, wsCookie, exactMirror);
548
+ const hasReplayableCapture = artifacts.handlers.some((h) => h.code) || artifacts.validators.length > 0;
549
+ const { plan: stub, mode } = planFromReport(strip, report, hasWS, mayTrace, aliases, hasReplayableCapture && !routesForbidSeal && validatorSlotsMatch && artifacts.validators.every((v) => v.bridgeFree === true), !hasReplayableCapture, adapterStub, productionStub, wsCookie, exactMirror);
547
550
  if (options?.target === "workerd") {
548
551
  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.`);
549
552
  if (!validatorSlotsMatch) console.warn("[elysia-aot] target 'workerd': captured validator slots do not exactly match declared slots; unfrozen slots compile at runtime and will fail on workerd.");
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { resolveEntry, resolveEntryModuleKind } from "./core.mjs";
2
3
  import { createAotPluginHooks, setupAotOnLoad } from "./hooks.mjs";
3
4
  import { dirname } from "node:path";
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  //#region src/plugin/aot/rspack-loader.ts
2
3
  /**
3
4
  * Shared, same-process registry mapping an opaque token -> the plugin instance's
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { resolveEntry, siblingModuleExt } from "./core.mjs";
2
3
  import { createAotPluginHooks } from "./hooks.mjs";
3
4
  import { registerAotHooks, unregisterAotHooks } from "./rspack-loader.mjs";
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { skipString } from "../../compile/lexer.mjs";
2
3
 
3
4
  //#region src/plugin/aot/treeshake.ts
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { createAotPluginHooks } from "./hooks.mjs";
2
3
 
3
4
  //#region src/plugin/aot/unplugin.ts
@@ -19,9 +20,9 @@ const forceManifestSideEffect = (compiler) => {
19
20
  *
20
21
  * const aot = createUnplugin(aotFactory)
21
22
  *
22
- * // webpack.config.js → aot.webpack({ entry: 'src/index.ts' })
23
- * // rollup.config.js → aot.rollup({ entry: 'src/index.ts' })
24
- * // farm.config.ts → aot.farm({ entry: 'src/index.ts' })
23
+ * // webpack.config.js \u2192 aot.webpack({ entry: 'src/index.ts' })
24
+ * // rollup.config.js \u2192 aot.rollup({ entry: 'src/index.ts' })
25
+ * // farm.config.ts \u2192 aot.farm({ entry: 'src/index.ts' })
25
26
  * ```
26
27
  *
27
28
  * For rspack, prefer the native `elysia/plugin/aot/rspack` plugin
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { createAotPluginHooks } from "./hooks.mjs";
2
3
 
3
4
  //#region src/plugin/aot/vite.ts
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { generateCompiledArtifacts } from "./core.mjs";
2
3
  import { parentPort, workerData } from "node:worker_threads";
3
4
 
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  //#region src/plugin/auto-head.ts
2
3
  function toHeadResponse(response) {
3
4
  if (!(response instanceof Response) || response.body === null) return response;
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { Elysia } from "../base.mjs";
2
3
  import { createTracer, unionTracePhases } from "../trace.mjs";
3
4
 
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { fnv1a, nullObject } from "../utils.mjs";
2
3
  import { Elysia } from "../base.mjs";
3
4
  import { accumulateWSOptions, buildGlobalWSHandler, buildWSRoute, resolveWSOptions } from "../ws/route.mjs";
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { needEncodeRegex } from "./constants.mjs";
2
3
 
3
4
  //#region src/route-table.ts
@@ -221,9 +221,34 @@ function snapshotSlots(target, intern) {
221
221
  for (const slot of schemaSlots) if (target[slot] != null) target[slot] = internSchema(target[slot], intern);
222
222
  const response = target.response;
223
223
  if (response != null) if (typeof response === "object" && !("~standard" in response) && isStatusMap(response)) {
224
- const next = {};
225
- for (const status in response) next[status] = internSchema(response[status], intern);
226
- target.response = next;
224
+ let next = {};
225
+ const state = { bail: false };
226
+ let key = "M";
227
+ for (const status in response) {
228
+ const schema = internSchema(response[status], intern);
229
+ Object.defineProperty(next, status, {
230
+ value: schema,
231
+ enumerable: true
232
+ });
233
+ key += status.length + ":" + status + byRefKey(schema, state);
234
+ }
235
+ if (key === "M") target.response = next;
236
+ else {
237
+ if (intern && !state.bail) {
238
+ const shared = interned.get(key);
239
+ if (shared === void 0) {
240
+ if (interned.size >= INTERN_LIMIT) require_utils.evictOldestHalf(interned);
241
+ interned.set(key, next);
242
+ } else {
243
+ if (interned.size >= INTERN_LIMIT) {
244
+ interned.delete(key);
245
+ interned.set(key, shared);
246
+ }
247
+ next = shared;
248
+ }
249
+ }
250
+ target.response = Object.freeze(next);
251
+ }
227
252
  } else target.response = internSchema(response, intern);
228
253
  }
229
254
  function isStatusMap(response) {
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { evictOldestHalf } from "./utils.mjs";
2
3
  import { env } from "./universal/env.mjs";
3
4
 
@@ -220,9 +221,34 @@ function snapshotSlots(target, intern) {
220
221
  for (const slot of schemaSlots) if (target[slot] != null) target[slot] = internSchema(target[slot], intern);
221
222
  const response = target.response;
222
223
  if (response != null) if (typeof response === "object" && !("~standard" in response) && isStatusMap(response)) {
223
- const next = {};
224
- for (const status in response) next[status] = internSchema(response[status], intern);
225
- target.response = next;
224
+ let next = {};
225
+ const state = { bail: false };
226
+ let key = "M";
227
+ for (const status in response) {
228
+ const schema = internSchema(response[status], intern);
229
+ Object.defineProperty(next, status, {
230
+ value: schema,
231
+ enumerable: true
232
+ });
233
+ key += status.length + ":" + status + byRefKey(schema, state);
234
+ }
235
+ if (key === "M") target.response = next;
236
+ else {
237
+ if (intern && !state.bail) {
238
+ const shared = interned.get(key);
239
+ if (shared === void 0) {
240
+ if (interned.size >= INTERN_LIMIT) evictOldestHalf(interned);
241
+ interned.set(key, next);
242
+ } else {
243
+ if (interned.size >= INTERN_LIMIT) {
244
+ interned.delete(key);
245
+ interned.set(key, shared);
246
+ }
247
+ next = shared;
248
+ }
249
+ }
250
+ target.response = Object.freeze(next);
251
+ }
226
252
  } else target.response = internSchema(response, intern);
227
253
  }
228
254
  function isStatusMap(response) {
package/dist/sucrose.d.ts CHANGED
@@ -19,7 +19,7 @@ declare const mergeInference: (a: Sucrose.Inference, b: Sucrose.Inference) => Su
19
19
  * @internal Which `channelOf`-mapped members of a function's first parameter
20
20
  * the function may read, or `null` when any member may be read
21
21
  */
22
- declare function inferFunction<K extends string>(source: string, channelOf: (value: string) => K | undefined, strict?: boolean): Set<K> | null;
22
+ declare function inferParameterReads<K extends string>(source: string, channelOf: (value: string) => K | undefined, strict?: boolean): Set<K> | null;
23
23
  declare function sucrose(handler: Handler | undefined, lifeCycle: Sucrose.LifeCycle | undefined): Sucrose.Inference;
24
24
  //#endregion
25
- export { Sucrose, clearSucroseCache, inferFunction, mergeInference, sucrose };
25
+ export { Sucrose, clearSucroseCache, inferParameterReads, mergeInference, sucrose };
package/dist/sucrose.js CHANGED
@@ -59,7 +59,7 @@ function computedDestructuringChannel(tokens, index, channelOf) {
59
59
  * @internal Which `channelOf`-mapped members of a function's first parameter
60
60
  * the function may read, or `null` when any member may be read
61
61
  */
62
- function inferFunction(source, channelOf, strict = false) {
62
+ function inferParameterReads(source, channelOf, strict = false) {
63
63
  if (!source || source.includes("[native code]") || source.trimStart().startsWith("class")) return null;
64
64
  let tokens;
65
65
  try {
@@ -232,7 +232,7 @@ function sucrose(handler, lifeCycle) {
232
232
  let inference;
233
233
  let merged = false;
234
234
  const events = [];
235
- if (handler && typeof handler === "function") events.push(handler);
235
+ if (typeof handler === "function") events.push(handler);
236
236
  if (lifeCycle) for (const name of lifeCycleEvents) {
237
237
  const array = lifeCycle[name];
238
238
  if (array) {
@@ -240,7 +240,7 @@ function sucrose(handler, lifeCycle) {
240
240
  }
241
241
  }
242
242
  const session = require_compile_aot.getCompilerSession();
243
- const caches = session?.external ? session.sucroseCache : globalSourceCache;
243
+ const sourceCache = session?.external ? session.sucroseCache : globalSourceCache;
244
244
  for (let i = 0; i < events.length; i++) {
245
245
  const event = events[i];
246
246
  if (!event) continue;
@@ -250,22 +250,22 @@ function sucrose(handler, lifeCycle) {
250
250
  else {
251
251
  const content = event.toString();
252
252
  const key = require_utils.fnv1a(content);
253
- const cached = caches.get(key);
253
+ const cached = sourceCache.get(key);
254
254
  if (cached && cached.content === content) {
255
255
  inferred = cached.inference;
256
- if (caches.size >= DEFAULT_CACHE_LIMIT) {
257
- caches.delete(key);
258
- caches.set(key, cached);
256
+ if (sourceCache.size >= DEFAULT_CACHE_LIMIT) {
257
+ sourceCache.delete(key);
258
+ sourceCache.set(key, cached);
259
259
  }
260
260
  } else {
261
- const channels = inferFunction(content, channel);
261
+ const channels = inferParameterReads(content, channel);
262
262
  if (channels) {
263
263
  const fresh = defaultSucrose();
264
264
  for (const c of channels) fresh[c] = true;
265
265
  inferred = Object.freeze(fresh);
266
266
  } else inferred = allAccessed;
267
- if (caches.size >= DEFAULT_CACHE_LIMIT) require_utils.evictOldestHalf(caches);
268
- caches.set(key, {
267
+ if (sourceCache.size >= DEFAULT_CACHE_LIMIT) require_utils.evictOldestHalf(sourceCache);
268
+ sourceCache.set(key, {
269
269
  content,
270
270
  inference: inferred
271
271
  });
@@ -285,6 +285,6 @@ function sucrose(handler, lifeCycle) {
285
285
 
286
286
  //#endregion
287
287
  exports.clearSucroseCache = clearSucroseCache;
288
- exports.inferFunction = inferFunction;
288
+ exports.inferParameterReads = inferParameterReads;
289
289
  exports.mergeInference = mergeInference;
290
290
  exports.sucrose = sucrose;
package/dist/sucrose.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { evictOldestHalf, fnv1a } from "./utils.mjs";
2
3
  import { getCompilerSession } from "./compile/aot.mjs";
3
4
  import { scanTokens } from "./compile/lexer.mjs";
@@ -58,7 +59,7 @@ function computedDestructuringChannel(tokens, index, channelOf) {
58
59
  * @internal Which `channelOf`-mapped members of a function's first parameter
59
60
  * the function may read, or `null` when any member may be read
60
61
  */
61
- function inferFunction(source, channelOf, strict = false) {
62
+ function inferParameterReads(source, channelOf, strict = false) {
62
63
  if (!source || source.includes("[native code]") || source.trimStart().startsWith("class")) return null;
63
64
  let tokens;
64
65
  try {
@@ -231,7 +232,7 @@ function sucrose(handler, lifeCycle) {
231
232
  let inference;
232
233
  let merged = false;
233
234
  const events = [];
234
- if (handler && typeof handler === "function") events.push(handler);
235
+ if (typeof handler === "function") events.push(handler);
235
236
  if (lifeCycle) for (const name of lifeCycleEvents) {
236
237
  const array = lifeCycle[name];
237
238
  if (array) {
@@ -239,7 +240,7 @@ function sucrose(handler, lifeCycle) {
239
240
  }
240
241
  }
241
242
  const session = getCompilerSession();
242
- const caches = session?.external ? session.sucroseCache : globalSourceCache;
243
+ const sourceCache = session?.external ? session.sucroseCache : globalSourceCache;
243
244
  for (let i = 0; i < events.length; i++) {
244
245
  const event = events[i];
245
246
  if (!event) continue;
@@ -249,22 +250,22 @@ function sucrose(handler, lifeCycle) {
249
250
  else {
250
251
  const content = event.toString();
251
252
  const key = fnv1a(content);
252
- const cached = caches.get(key);
253
+ const cached = sourceCache.get(key);
253
254
  if (cached && cached.content === content) {
254
255
  inferred = cached.inference;
255
- if (caches.size >= DEFAULT_CACHE_LIMIT) {
256
- caches.delete(key);
257
- caches.set(key, cached);
256
+ if (sourceCache.size >= DEFAULT_CACHE_LIMIT) {
257
+ sourceCache.delete(key);
258
+ sourceCache.set(key, cached);
258
259
  }
259
260
  } else {
260
- const channels = inferFunction(content, channel);
261
+ const channels = inferParameterReads(content, channel);
261
262
  if (channels) {
262
263
  const fresh = defaultSucrose();
263
264
  for (const c of channels) fresh[c] = true;
264
265
  inferred = Object.freeze(fresh);
265
266
  } else inferred = allAccessed;
266
- if (caches.size >= DEFAULT_CACHE_LIMIT) evictOldestHalf(caches);
267
- caches.set(key, {
267
+ if (sourceCache.size >= DEFAULT_CACHE_LIMIT) evictOldestHalf(sourceCache);
268
+ sourceCache.set(key, {
268
269
  content,
269
270
  inference: inferred
270
271
  });
@@ -283,4 +284,4 @@ function sucrose(handler, lifeCycle) {
283
284
  }
284
285
 
285
286
  //#endregion
286
- export { clearSucroseCache, inferFunction, mergeInference, sucrose };
287
+ export { clearSucroseCache, inferParameterReads, mergeInference, sucrose };
package/dist/trace.js CHANGED
@@ -21,10 +21,8 @@ function scanTracePhases(fn) {
21
21
  if (cached !== void 0) return cached;
22
22
  let result = null;
23
23
  if (fn.length) try {
24
- result = require_sucrose.inferFunction(Function.prototype.toString.call(fn), phaseOf, true);
25
- } catch {
26
- result = null;
27
- }
24
+ result = require_sucrose.inferParameterReads(Function.prototype.toString.call(fn), phaseOf, true);
25
+ } catch {}
28
26
  tracePhaseCache.set(fn, result);
29
27
  return result;
30
28
  }
@@ -39,7 +37,7 @@ function unionTracePhases(handlers) {
39
37
  return union;
40
38
  }
41
39
  /** Prevent rejected trace callbacks from becoming unhandled rejections. */
42
- function fire(result) {
40
+ function logRejection(result) {
43
41
  if (typeof result?.then === "function") result.then(void 0, (error) => console.error(error));
44
42
  }
45
43
  var TraceRecorder = class {
@@ -103,7 +101,7 @@ var TraceRecorder = class {
103
101
  const result = this.#result();
104
102
  resolve(result);
105
103
  const callbacks = this.callbacksBegin;
106
- if (callbacks) for (let i = 0; i < callbacks.length; i++) fire(callbacks[i](result));
104
+ if (callbacks) for (let i = 0; i < callbacks.length; i++) logRejection(callbacks[i](result));
107
105
  }
108
106
  return this;
109
107
  }
@@ -130,7 +128,7 @@ var TraceRecorder = class {
130
128
  return end;
131
129
  }
132
130
  };
133
- for (let i = 0; i < children.length; i++) fire(children[i](result));
131
+ for (let i = 0; i < children.length; i++) logRejection(children[i](result));
134
132
  let resolved = false;
135
133
  return (err = null) => {
136
134
  if (resolved) return;
@@ -144,7 +142,7 @@ var TraceRecorder = class {
144
142
  return endAt - process.begin;
145
143
  }
146
144
  };
147
- for (let i = 0; i < callbacksEnd.length; i++) fire(callbacksEnd[i](detail));
145
+ for (let i = 0; i < callbacksEnd.length; i++) logRejection(callbacksEnd[i](detail));
148
146
  resolveEnd(endAt);
149
147
  resolveError(err);
150
148
  };
@@ -167,7 +165,7 @@ var TraceRecorder = class {
167
165
  return end - begun.begin;
168
166
  }
169
167
  };
170
- for (let i = 0; i < callbacks.length; i++) fire(callbacks[i](detail));
168
+ for (let i = 0; i < callbacks.length; i++) logRejection(callbacks[i](detail));
171
169
  }
172
170
  this.endResolve?.(end);
173
171
  this.errorResolve?.(error);
@@ -269,7 +267,7 @@ var TracerLifecycle = class {
269
267
  const createTracer = (traceListener) => (context) => {
270
268
  const handle = new TracerHandle();
271
269
  handle.rid = context.rid ?? "";
272
- fire(traceListener(new TracerLifecycle(handle, context)));
270
+ logRejection(traceListener(new TracerLifecycle(handle, context)));
273
271
  return handle;
274
272
  };
275
273
 
package/dist/trace.mjs CHANGED
@@ -1,5 +1,6 @@
1
+ // @bun
1
2
  import { traceEvents } from "./constants.mjs";
2
- import { inferFunction } from "./sucrose.mjs";
3
+ import { inferParameterReads } from "./sucrose.mjs";
3
4
 
4
5
  //#region src/trace.ts
5
6
  const phaseGetter = {
@@ -20,10 +21,8 @@ function scanTracePhases(fn) {
20
21
  if (cached !== void 0) return cached;
21
22
  let result = null;
22
23
  if (fn.length) try {
23
- result = inferFunction(Function.prototype.toString.call(fn), phaseOf, true);
24
- } catch {
25
- result = null;
26
- }
24
+ result = inferParameterReads(Function.prototype.toString.call(fn), phaseOf, true);
25
+ } catch {}
27
26
  tracePhaseCache.set(fn, result);
28
27
  return result;
29
28
  }
@@ -38,7 +37,7 @@ function unionTracePhases(handlers) {
38
37
  return union;
39
38
  }
40
39
  /** Prevent rejected trace callbacks from becoming unhandled rejections. */
41
- function fire(result) {
40
+ function logRejection(result) {
42
41
  if (typeof result?.then === "function") result.then(void 0, (error) => console.error(error));
43
42
  }
44
43
  var TraceRecorder = class {
@@ -102,7 +101,7 @@ var TraceRecorder = class {
102
101
  const result = this.#result();
103
102
  resolve(result);
104
103
  const callbacks = this.callbacksBegin;
105
- if (callbacks) for (let i = 0; i < callbacks.length; i++) fire(callbacks[i](result));
104
+ if (callbacks) for (let i = 0; i < callbacks.length; i++) logRejection(callbacks[i](result));
106
105
  }
107
106
  return this;
108
107
  }
@@ -129,7 +128,7 @@ var TraceRecorder = class {
129
128
  return end;
130
129
  }
131
130
  };
132
- for (let i = 0; i < children.length; i++) fire(children[i](result));
131
+ for (let i = 0; i < children.length; i++) logRejection(children[i](result));
133
132
  let resolved = false;
134
133
  return (err = null) => {
135
134
  if (resolved) return;
@@ -143,7 +142,7 @@ var TraceRecorder = class {
143
142
  return endAt - process.begin;
144
143
  }
145
144
  };
146
- for (let i = 0; i < callbacksEnd.length; i++) fire(callbacksEnd[i](detail));
145
+ for (let i = 0; i < callbacksEnd.length; i++) logRejection(callbacksEnd[i](detail));
147
146
  resolveEnd(endAt);
148
147
  resolveError(err);
149
148
  };
@@ -166,7 +165,7 @@ var TraceRecorder = class {
166
165
  return end - begun.begin;
167
166
  }
168
167
  };
169
- for (let i = 0; i < callbacks.length; i++) fire(callbacks[i](detail));
168
+ for (let i = 0; i < callbacks.length; i++) logRejection(callbacks[i](detail));
170
169
  }
171
170
  this.endResolve?.(end);
172
171
  this.errorResolve?.(error);
@@ -268,7 +267,7 @@ var TracerLifecycle = class {
268
267
  const createTracer = (traceListener) => (context) => {
269
268
  const handle = new TracerHandle();
270
269
  handle.rid = context.rid ?? "";
271
- fire(traceListener(new TracerLifecycle(handle, context)));
270
+ logRejection(traceListener(new TracerLifecycle(handle, context)));
272
271
  return handle;
273
272
  };
274
273
 
@@ -1,9 +1,9 @@
1
1
  import { Intersect } from "./elysia/intersect.js";
2
+ import { applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure } from "./coerce.js";
2
3
  import { hasTypes } from "./utils.js";
3
4
  import { useTypebox as useTypebox$1 } from "./bridge.js";
4
5
  import { TypeBoxValidatorCache, mayHaveFileType } from "./validator/validator-cache.js";
5
6
  import { TypeBoxValidator } from "./validator/index.js";
6
- import { applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure } from "./coerce.js";
7
7
  import { Ref } from "typebox/type";
8
8
  import { Check, Clone, Create, Decode, HasCodec } from "typebox/value";
9
9
  import { Compile } from "typebox/compile";
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { hasTypes } from "./utils.mjs";
2
3
  import { applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure } from "./coerce.mjs";
3
4
  import { TypeBoxValidatorCache, mayHaveFileType } from "./validator/validator-cache.mjs";
@@ -1,8 +1,8 @@
1
1
  import { Intersect as Intersect$2 } from "./elysia/intersect.js";
2
+ 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";
2
3
  import { hasTypes as hasTypes$1 } from "./utils.js";
3
4
  import { TypeBoxValidatorCache as TypeBoxValidatorCache$1, mayHaveFileType as mayHaveFileType$1 } from "./validator/validator-cache.js";
4
5
  import { TypeBoxValidator as TypeBoxValidator$1 } from "./validator/index.js";
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
7
  import { Check as Check$1, Clone as Clone$1, Create as Create$1, Decode as Decode$2, HasCodec as HasCodec$1 } from "typebox/value";
8
8
  import { Compile as Compile$1 } from "typebox/compile";
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  //#region src/type/bridge.ts
2
3
  let live;
3
4
  function ensure() {
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { evictOldestHalf, nullObject } from "../utils.mjs";
2
3
  import { ELYSIA_TYPES } from "./constants.mjs";
3
4
  import { clearCoerceLeafCache, coerceLeafCache } from "./shared.mjs";
@@ -30,7 +30,7 @@ declare const coerceQuery: () => CoerceOption[];
30
30
  declare const coerceBody: () => CoerceOption[];
31
31
  declare const coerceFormData: () => CoerceOption[];
32
32
  declare const coerceStringToStructure: () => CoerceOption[];
33
- declare function applyCoercions(schema: BaseSchema | TSchema, coerces: CoerceOption[] | undefined): TSchema | BaseSchema;
33
+ declare function applyCoercions(schema: BaseSchema | TSchema, coerces: CoerceOption[] | undefined): BaseSchema | TSchema;
34
34
  declare function captureCoercePlan(original: any, coerced: any): CoerceNode | null;
35
35
  /** Full rebuild: scalar leaves + ObjectString/ArrayString sites (wired path). */
36
36
  declare const buildCoercedFromPlan: (original: any, plan: CoerceNode, seen?: Set<string>) => any;
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { nullObject } from "../utils.mjs";
2
3
  import { ELYSIA_TYPES, primitiveElysiaTypes } from "./constants.mjs";
3
4
  import { clearCoerceLeafCache, cloneNode, nonAdditionalProperties } from "./shared.mjs";
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  import { useTypebox } from "./bridge.mjs";
2
3
  import { hasTypes } from "./utils.mjs";
3
4
  import { Ref, injectTypeboxType } from "./typebox-type.mjs";
@@ -17,7 +17,7 @@ declare const ELYSIA_TYPES: {
17
17
  readonly NoValidate: 15;
18
18
  };
19
19
  type ELYSIA_TYPES = typeof ELYSIA_TYPES;
20
- declare const primitiveElysiaTypes: Set<1 | 2 | 6 | 3 | 10 | 11 | 13 | 14>;
20
+ declare const primitiveElysiaTypes: Set<2 | 1 | 6 | 3 | 10 | 11 | 13 | 14>;
21
21
  declare const noEnumerable: {
22
22
  readonly enumerable: false;
23
23
  };
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  //#region src/type/constants.ts
2
3
  const ELYSIA_TYPES = {
3
4
  Numeric: 1,
@@ -1,3 +1,4 @@
1
+ // @bun
1
2
  //#region src/type/elysia/accelerate.ts
2
3
  function Accelerate(schema) {
3
4
  const raw = schema.toJSONSchema?.() ?? schema.toJsonSchema?.() ?? schema["~standard"].jsonSchema.input({ target: "draft-2020-12" });
@@ -1,9 +1,10 @@
1
1
  import { ELYSIA_TYPES } from "../constants.js";
2
2
  import { ArrayBufferOptions } from "../types.js";
3
+ import * as _$typebox from "typebox";
3
4
  import { TSchema } from "typebox";
4
5
 
5
6
  //#region src/type/elysia/array-buffer.d.ts
6
- declare function bufferType(tag: ELYSIA_TYPES[keyof ELYSIA_TYPES], base: () => TSchema): (property?: ArrayBufferOptions) => any;
7
- declare function ArrayBufferType(property?: ArrayBufferOptions): any;
7
+ declare function bufferType<S extends TSchema>(tag: ELYSIA_TYPES[keyof ELYSIA_TYPES], createBase: () => S): (property?: ArrayBufferOptions) => Readonly<S>;
8
+ declare function ArrayBufferType(property?: ArrayBufferOptions): Readonly<_$typebox.TRefine<_$typebox.TUnsafe<ArrayBuffer>>>;
8
9
  //#endregion
9
10
  export { ArrayBufferType, bufferType };
@@ -5,16 +5,16 @@ const require_type_typebox_type = require('../typebox-type.js');
5
5
  const require_type_elysia_utils = require('./utils.js');
6
6
 
7
7
  //#region src/type/elysia/array-buffer.ts
8
- function bufferType(tag, base) {
9
- let Base;
8
+ function bufferType(tag, createBase) {
9
+ let base;
10
10
  let empty;
11
11
  return (property) => {
12
- Base ??= base();
13
- if (!property || require_utils.isEmpty(property)) return empty ??= Object.freeze(require_type_elysia_utils.elyType(tag, Base));
12
+ base ??= createBase();
13
+ if (!property || require_utils.isEmpty(property)) return empty ??= Object.freeze(require_type_elysia_utils.elyType(tag, base));
14
14
  const refines = [];
15
15
  if (property.minByteLength !== void 0) refines.push([(value) => value.byteLength >= property.minByteLength, `Expect byte to be more than ${property.minByteLength}`]);
16
16
  if (property.maxByteLength !== void 0) refines.push([(value) => value.byteLength <= property.maxByteLength, `Expect byte to be less than ${property.maxByteLength}`]);
17
- return require_type_elysia_utils.elyType(tag, require_type_elysia_utils.withMeta(require_type_elysia_utils.Refines(Base, refines), property));
17
+ return require_type_elysia_utils.elyType(tag, require_type_elysia_utils.withMeta(require_type_elysia_utils.Refines(base, refines), property));
18
18
  };
19
19
  }
20
20
  const arrayBuffer = /* @__PURE__ */ bufferType(require_type_constants.ELYSIA_TYPES.ArrayBuffer, () => require_type_typebox_type.Refine(require_type_typebox_type.Unsafe({ "~kind": "ArrayBuffer" }), (value) => value instanceof ArrayBuffer, () => "must be ArrayBuffer"));