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
@@ -35,20 +35,10 @@ function parseQuery(context) {
35
35
  });
36
36
  }
37
37
  const isPristineNotFound = (context, error) => error instanceof require_error.NotFound && error.response === "Not Found" && !context.set.cookie && !require_utils.isNotEmpty(context.set.headers);
38
- /**
39
- * Adopt the intercepted error's `type` into a problem the hook produced
40
- * without one.
41
- *
42
- * `'about:blank'` is RFC 9457's "unspecified" default, so it's the only value
43
- * worth replacing — an explicit type the handler set always wins.
44
- *
45
- * The result is copied rather than mutated: `.error(Class, value)` wraps a
46
- * non-function into `() => value`, so the very same `ElysiaStatus` is replayed
47
- * on every request and an in-place write would leak across requests
48
- */
38
+ const claimsProblemType = (error) => typeof error?.type === "string" ? !(error instanceof require_error.ValidationError) && error.constructor?.name !== "ValidationError" : error instanceof require_error.HTTPError;
49
39
  function adoptErrorType(result, error) {
50
40
  const body = result?.response;
51
- if (typeof error?.type !== "string" || body?.type !== "about:blank" || result.headers?.["content-type"] !== "application/problem+json") return result;
41
+ if (typeof error?.type !== "string" || !claimsProblemType(error) || body?.type !== "about:blank" || result.headers?.["content-type"] !== "application/problem+json") return result;
52
42
  return new require_error.ElysiaStatus(result.code, {
53
43
  ...body,
54
44
  type: error.type
@@ -78,13 +68,13 @@ const resolveStatus = (status) => typeof status === "string" ? require_constants
78
68
  * Body served by an error that carries a status but no usable body:
79
69
  * its declared `response`, otherwise its message
80
70
  */
81
- const statusFallbackBody = (error, status) => error.response !== void 0 ? error.response : require_universal_is_production.isProduction() && status >= 500 ? "Internal Server Error" : error.message ?? "";
71
+ function statusFallbackBody(error, status) {
72
+ const masked = require_universal_is_production.isProduction() && status >= 500;
73
+ const declared = error.response;
74
+ return declared !== void 0 && !(masked && typeof declared === "object") ? declared : masked ? "Internal Server Error" : error.message ?? "";
75
+ }
82
76
  /**
83
77
  * RFC 9457 problem document carrying `detail` verbatim, mirroring `problem()`.
84
- *
85
- * `detail` is served exactly as annotated — objects included — it is never
86
- * spread into the envelope. `problemBody` only defaults `type` when the key is
87
- * *absent*, so an error without one has to supply `'about:blank'` itself
88
78
  */
89
79
  const problemOf = (self, detail, status) => new require_error.ElysiaStatus(status, require_error.problemBody({
90
80
  type: self.type ?? "about:blank",
@@ -109,7 +99,7 @@ function fallbackErrorResponse(context, error, mapResponse, defaultError) {
109
99
  const self = error;
110
100
  const status = resolveStatus(self.status);
111
101
  const owned = error instanceof require_error.HTTPError;
112
- const claimsProblem = owned || typeof self.type === "string";
102
+ const claimsProblem = claimsProblemType(error);
113
103
  const served = typeof status === "number" ? status : resolveStatus(context.set.status);
114
104
  const failed = (cause) => {
115
105
  context.set.status = 500;
@@ -124,9 +114,13 @@ function fallbackErrorResponse(context, error, mapResponse, defaultError) {
124
114
  if (context.set.status === void 0 || context.set.status === 200) context.set.status = 500;
125
115
  return mapResponse(require_error.internalServerErrorResponse(error), context.set, context);
126
116
  }
127
- return defaultError ? defaultError.clone() : require_error.internalServerErrorResponse(error);
117
+ return mapResponse(defaultError ? defaultError.clone() : require_error.internalServerErrorResponse(error), context.set, context);
118
+ };
119
+ const serveMessage = () => {
120
+ if (!claimsProblem) return legacy();
121
+ mergeHeaders();
122
+ return mapResponse(problemOf(self, statusFallbackBody(error, served), served), context.set, context);
128
123
  };
129
- const serveMessage = () => claimsProblem ? mapResponse(problemOf(self, statusFallbackBody(error, served), served), context.set, context) : legacy();
130
124
  const serveDetail = () => {
131
125
  let detail;
132
126
  try {
@@ -143,6 +137,11 @@ function fallbackErrorResponse(context, error, mapResponse, defaultError) {
143
137
  mergeHeaders();
144
138
  return mapResponse(problemOf(self, detail, served), context.set, context);
145
139
  };
140
+ if (error instanceof require_error.ValidationError) return mapResponse(new require_error.ElysiaStatus(422, require_error.problemBody({
141
+ type: "validation",
142
+ title: "Validation Error",
143
+ status: 422
144
+ }), { "content-type": require_error.PROBLEM_JSON }), context.set, context);
146
145
  if (owned || error instanceof Error && typeof status === "number" && status >= 100 && !(require_universal_is_production.isProduction() && status >= 500)) {
147
146
  let value;
148
147
  try {
@@ -213,5 +212,9 @@ function createErrorHandler(onErrors, mapResponse, defaultError, allowUnsafe = f
213
212
 
214
213
  //#endregion
215
214
  exports.adoptErrorType = adoptErrorType;
215
+ exports.claimsProblemType = claimsProblemType;
216
216
  exports.createErrorHandler = createErrorHandler;
217
- exports.fallbackResponse = fallbackResponse;
217
+ exports.fallbackResponse = fallbackResponse;
218
+ exports.readAnnotation = readAnnotation;
219
+ exports.resolveStatus = resolveStatus;
220
+ exports.statusFallbackBody = statusFallbackBody;
@@ -34,20 +34,10 @@ function parseQuery(context) {
34
34
  });
35
35
  }
36
36
  const isPristineNotFound = (context, error) => error instanceof NotFound && error.response === "Not Found" && !context.set.cookie && !isNotEmpty(context.set.headers);
37
- /**
38
- * Adopt the intercepted error's `type` into a problem the hook produced
39
- * without one.
40
- *
41
- * `'about:blank'` is RFC 9457's "unspecified" default, so it's the only value
42
- * worth replacing — an explicit type the handler set always wins.
43
- *
44
- * The result is copied rather than mutated: `.error(Class, value)` wraps a
45
- * non-function into `() => value`, so the very same `ElysiaStatus` is replayed
46
- * on every request and an in-place write would leak across requests
47
- */
37
+ const claimsProblemType = (error) => typeof error?.type === "string" ? !(error instanceof ValidationError) && error.constructor?.name !== "ValidationError" : error instanceof HTTPError;
48
38
  function adoptErrorType(result, error) {
49
39
  const body = result?.response;
50
- if (typeof error?.type !== "string" || body?.type !== "about:blank" || result.headers?.["content-type"] !== "application/problem+json") return result;
40
+ if (typeof error?.type !== "string" || !claimsProblemType(error) || body?.type !== "about:blank" || result.headers?.["content-type"] !== "application/problem+json") return result;
51
41
  return new ElysiaStatus(result.code, {
52
42
  ...body,
53
43
  type: error.type
@@ -77,13 +67,13 @@ const resolveStatus = (status) => typeof status === "string" ? StatusMap[status]
77
67
  * Body served by an error that carries a status but no usable body:
78
68
  * its declared `response`, otherwise its message
79
69
  */
80
- const statusFallbackBody = (error, status) => error.response !== void 0 ? error.response : isProduction() && status >= 500 ? "Internal Server Error" : error.message ?? "";
70
+ function statusFallbackBody(error, status) {
71
+ const masked = isProduction() && status >= 500;
72
+ const declared = error.response;
73
+ return declared !== void 0 && !(masked && typeof declared === "object") ? declared : masked ? "Internal Server Error" : error.message ?? "";
74
+ }
81
75
  /**
82
76
  * RFC 9457 problem document carrying `detail` verbatim, mirroring `problem()`.
83
- *
84
- * `detail` is served exactly as annotated — objects included — it is never
85
- * spread into the envelope. `problemBody` only defaults `type` when the key is
86
- * *absent*, so an error without one has to supply `'about:blank'` itself
87
77
  */
88
78
  const problemOf = (self, detail, status) => new ElysiaStatus(status, problemBody({
89
79
  type: self.type ?? "about:blank",
@@ -108,7 +98,7 @@ function fallbackErrorResponse(context, error, mapResponse, defaultError) {
108
98
  const self = error;
109
99
  const status = resolveStatus(self.status);
110
100
  const owned = error instanceof HTTPError;
111
- const claimsProblem = owned || typeof self.type === "string";
101
+ const claimsProblem = claimsProblemType(error);
112
102
  const served = typeof status === "number" ? status : resolveStatus(context.set.status);
113
103
  const failed = (cause) => {
114
104
  context.set.status = 500;
@@ -123,9 +113,13 @@ function fallbackErrorResponse(context, error, mapResponse, defaultError) {
123
113
  if (context.set.status === void 0 || context.set.status === 200) context.set.status = 500;
124
114
  return mapResponse(internalServerErrorResponse(error), context.set, context);
125
115
  }
126
- return defaultError ? defaultError.clone() : internalServerErrorResponse(error);
116
+ return mapResponse(defaultError ? defaultError.clone() : internalServerErrorResponse(error), context.set, context);
117
+ };
118
+ const serveMessage = () => {
119
+ if (!claimsProblem) return legacy();
120
+ mergeHeaders();
121
+ return mapResponse(problemOf(self, statusFallbackBody(error, served), served), context.set, context);
127
122
  };
128
- const serveMessage = () => claimsProblem ? mapResponse(problemOf(self, statusFallbackBody(error, served), served), context.set, context) : legacy();
129
123
  const serveDetail = () => {
130
124
  let detail;
131
125
  try {
@@ -142,6 +136,11 @@ function fallbackErrorResponse(context, error, mapResponse, defaultError) {
142
136
  mergeHeaders();
143
137
  return mapResponse(problemOf(self, detail, served), context.set, context);
144
138
  };
139
+ if (error instanceof ValidationError) return mapResponse(new ElysiaStatus(422, problemBody({
140
+ type: "validation",
141
+ title: "Validation Error",
142
+ status: 422
143
+ }), { "content-type": PROBLEM_JSON }), context.set, context);
145
144
  if (owned || error instanceof Error && typeof status === "number" && status >= 100 && !(isProduction() && status >= 500)) {
146
145
  let value;
147
146
  try {
@@ -211,4 +210,4 @@ function createErrorHandler(onErrors, mapResponse, defaultError, allowUnsafe = f
211
210
  }
212
211
 
213
212
  //#endregion
214
- export { adoptErrorType, createErrorHandler, fallbackResponse };
213
+ export { adoptErrorType, claimsProblemType, createErrorHandler, fallbackResponse, readAnnotation, resolveStatus, statusFallbackBody };
@@ -13,8 +13,8 @@ let deuri = require("deuri");
13
13
  deuri = require_runtime.__toESM(deuri);
14
14
 
15
15
  //#region src/handler/fetch.ts
16
- function extractPath(url, context, pathStart) {
17
- const s = url.indexOf("/", pathStart);
16
+ function extractPath(url, context) {
17
+ const s = url.indexOf("/", require_utils.authorityEnd(url));
18
18
  const q = context.qi = url.indexOf("?", s);
19
19
  return context.path = q === -1 ? url.slice(s) : url.substring(s, q);
20
20
  }
@@ -111,7 +111,6 @@ function createFetchHandler(app) {
111
111
  const hasWS = !!app["~hasWS"];
112
112
  const hasDynamicWS = hasWS && !!app["~hasDynamicWS"];
113
113
  const strictPath = !!app["~config"]?.strictPath;
114
- const pathStart = app["~config"]?.handler?.standardHostname === false ? 7 : 11;
115
114
  const hook = require_utils.flattenChain(app["~hookChain"]);
116
115
  const hasError = !!hook?.error;
117
116
  const abortSignal = app["~config"]?.abortSignal !== false;
@@ -217,7 +216,7 @@ function createFetchHandler(app) {
217
216
  const context = new Context(request);
218
217
  require_adapter_utils.materializeSetHeaders(context.set);
219
218
  if (armEager(request, context)) return require_handler_utils.emptyResponse.clone();
220
- extractPath(request.url, context, pathStart);
219
+ extractPath(request.url, context);
221
220
  context.server = server ?? null;
222
221
  context.rid = require_utils.requestId();
223
222
  const traceLength = tracerFactories.length;
@@ -269,7 +268,7 @@ function createFetchHandler(app) {
269
268
  const context = new Context(request);
270
269
  require_adapter_utils.materializeSetHeaders(context.set);
271
270
  if (armEager(request, context)) return require_handler_utils.emptyResponse.clone();
272
- extractPath(request.url, context, pathStart);
271
+ extractPath(request.url, context);
273
272
  context.server = server ?? null;
274
273
  try {
275
274
  for (let i = 0; i < onRequests.length; i++) {
@@ -291,7 +290,7 @@ function createFetchHandler(app) {
291
290
  const context = new Context(request);
292
291
  require_adapter_utils.materializeSetHeaders(context.set);
293
292
  if (armEager(request, context)) return require_handler_utils.emptyResponse.clone();
294
- extractPath(request.url, context, pathStart);
293
+ extractPath(request.url, context);
295
294
  context.server = server ?? null;
296
295
  try {
297
296
  for (let i = 0; i < onRequests.length; i++) {
@@ -315,7 +314,7 @@ function createFetchHandler(app) {
315
314
  }
316
315
  return (request, server) => {
317
316
  const context = new Context(request);
318
- const path = extractPath(request.url, context, pathStart);
317
+ const path = extractPath(request.url, context);
319
318
  context.server = server ?? null;
320
319
  const method = request.method;
321
320
  if (hasWS && method === "GET") {
@@ -1,4 +1,4 @@
1
- import { flattenChain, isNotEmpty, nullObject, requestId } from "../utils.mjs";
1
+ import { authorityEnd, flattenChain, isNotEmpty, nullObject, requestId } from "../utils.mjs";
2
2
  import { isProduction } from "../universal/is-production.mjs";
3
3
  import { NotFound, PROBLEM_JSON, internalServerErrorResponse } from "../error.mjs";
4
4
  import { handleSet, materializeSetHeaders } from "../adapter/utils.mjs";
@@ -10,8 +10,8 @@ import { createContext } from "../context.mjs";
10
10
  import decodeComponent from "deuri";
11
11
 
12
12
  //#region src/handler/fetch.ts
13
- function extractPath(url, context, pathStart) {
14
- const s = url.indexOf("/", pathStart);
13
+ function extractPath(url, context) {
14
+ const s = url.indexOf("/", authorityEnd(url));
15
15
  const q = context.qi = url.indexOf("?", s);
16
16
  return context.path = q === -1 ? url.slice(s) : url.substring(s, q);
17
17
  }
@@ -108,7 +108,6 @@ function createFetchHandler(app) {
108
108
  const hasWS = !!app["~hasWS"];
109
109
  const hasDynamicWS = hasWS && !!app["~hasDynamicWS"];
110
110
  const strictPath = !!app["~config"]?.strictPath;
111
- const pathStart = app["~config"]?.handler?.standardHostname === false ? 7 : 11;
112
111
  const hook = flattenChain(app["~hookChain"]);
113
112
  const hasError = !!hook?.error;
114
113
  const abortSignal = app["~config"]?.abortSignal !== false;
@@ -214,7 +213,7 @@ function createFetchHandler(app) {
214
213
  const context = new Context(request);
215
214
  materializeSetHeaders(context.set);
216
215
  if (armEager(request, context)) return emptyResponse.clone();
217
- extractPath(request.url, context, pathStart);
216
+ extractPath(request.url, context);
218
217
  context.server = server ?? null;
219
218
  context.rid = requestId();
220
219
  const traceLength = tracerFactories.length;
@@ -266,7 +265,7 @@ function createFetchHandler(app) {
266
265
  const context = new Context(request);
267
266
  materializeSetHeaders(context.set);
268
267
  if (armEager(request, context)) return emptyResponse.clone();
269
- extractPath(request.url, context, pathStart);
268
+ extractPath(request.url, context);
270
269
  context.server = server ?? null;
271
270
  try {
272
271
  for (let i = 0; i < onRequests.length; i++) {
@@ -288,7 +287,7 @@ function createFetchHandler(app) {
288
287
  const context = new Context(request);
289
288
  materializeSetHeaders(context.set);
290
289
  if (armEager(request, context)) return emptyResponse.clone();
291
- extractPath(request.url, context, pathStart);
290
+ extractPath(request.url, context);
292
291
  context.server = server ?? null;
293
292
  try {
294
293
  for (let i = 0; i < onRequests.length; i++) {
@@ -312,7 +311,7 @@ function createFetchHandler(app) {
312
311
  }
313
312
  return (request, server) => {
314
313
  const context = new Context(request);
315
- const path = extractPath(request.url, context, pathStart);
314
+ const path = extractPath(request.url, context);
316
315
  context.server = server ?? null;
317
316
  const method = request.method;
318
317
  if (hasWS && method === "GET") {
@@ -1,13 +1,15 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_universal_constants = require('../universal/constants.js');
3
+ const require_universal_env = require('../universal/env.js');
3
4
  const require_error = require('../error.js');
4
5
  const require_compile_utils = require('../compile/utils.js');
5
6
 
6
7
  //#region src/handler/utils.ts
7
- const emptyResponse = require_universal_constants.isCloudflareWorker ? { clone: () => new Response(null) } : new Response(null);
8
+ const isPreallocateResponseUnsafe = require_universal_constants.isCloudflareWorker || require_universal_constants.isFastly || require_universal_env.env.ELYSIA_PREALLOCATE_RESPONSE === "false";
9
+ const emptyResponse = isPreallocateResponseUnsafe ? { clone: () => new Response(null) } : new Response(null);
8
10
  function cachedResponse(body, status, headers) {
9
11
  let cached;
10
- return () => require_universal_constants.isCloudflareWorker ? new Response(body, {
12
+ return () => isPreallocateResponseUnsafe ? new Response(body, {
11
13
  status,
12
14
  headers
13
15
  }) : (cached ??= new Response(body, {
@@ -1,12 +1,14 @@
1
- import { isCloudflareWorker } from "../universal/constants.mjs";
1
+ import { isCloudflareWorker, isFastly } from "../universal/constants.mjs";
2
+ import { env } from "../universal/env.mjs";
2
3
  import { PROBLEM_JSON } from "../error.mjs";
3
4
  import { isAsyncFunction, mayReturnPromise } from "../compile/utils.mjs";
4
5
 
5
6
  //#region src/handler/utils.ts
6
- const emptyResponse = isCloudflareWorker ? { clone: () => new Response(null) } : new Response(null);
7
+ const isPreallocateResponseUnsafe = isCloudflareWorker || isFastly || env.ELYSIA_PREALLOCATE_RESPONSE === "false";
8
+ const emptyResponse = isPreallocateResponseUnsafe ? { clone: () => new Response(null) } : new Response(null);
7
9
  function cachedResponse(body, status, headers) {
8
10
  let cached;
9
- return () => isCloudflareWorker ? new Response(body, {
11
+ return () => isPreallocateResponseUnsafe ? new Response(body, {
10
12
  status,
11
13
  headers
12
14
  }) : (cached ??= new Response(body, {
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.js');
3
2
  const require_constants = require('./constants.js');
4
3
  const require_universal_file = require('./universal/file.js');
5
4
  const require_utils = require('./utils.js');
@@ -15,7 +14,6 @@ const require_base = require('./base.js');
15
14
  const require_type_validator_index = require('./type/validator/index.js');
16
15
  const require_type_compat = require('./type/compat.js');
17
16
  const require_type_index = require('./type/index.js');
18
- let typebox_system = require("typebox/system");
19
17
 
20
18
  //#region src/index.ts
21
19
  var src_default = require_base.Elysia;
@@ -37,12 +35,7 @@ exports.StandardValidator = require_validator_index.StandardValidator;
37
35
  exports.StatusMap = require_constants.StatusMap;
38
36
  exports.StatusMapBack = require_constants.StatusMapBack;
39
37
  exports.TypeBoxValidator = require_type_validator_index.TypeBoxValidator;
40
- Object.defineProperty(exports, 'TypeSystem', {
41
- enumerable: true,
42
- get: function () {
43
- return typebox_system.System;
44
- }
45
- });
38
+ exports.TypeSystem = require_type_index.TypeSystem;
46
39
  exports.ValidationError = require_error.ValidationError;
47
40
  exports.Validator = require_validator_index.Validator;
48
41
  exports.borrow = require_adapter_response_ownership.borrow;
package/dist/package.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  //#region package.json
3
- var version = "2.0.0-beta.2";
3
+ var version = "2.0.0-beta.4";
4
4
 
5
5
  //#endregion
6
6
  Object.defineProperty(exports, 'version', {
package/dist/package.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.0.0-beta.2";
2
+ var version = "2.0.0-beta.4";
3
3
 
4
4
  //#endregion
5
5
  export { version };
@@ -1,5 +1,6 @@
1
+ import { CapturedValidator } from "../../compile/aot.js";
1
2
  import { JITProbeResult } from "../../compile/jit-probe.js";
2
- import { AotTarget } from "./source.js";
3
+ import { AotModuleCondition, AotTarget } from "./source.js";
3
4
 
4
5
  //#region src/plugin/aot/core.d.ts
5
6
  interface ElysiaAotOptions {
@@ -93,6 +94,8 @@ interface ElysiaAotOptions {
93
94
  verbose?: boolean;
94
95
  }
95
96
  declare const resolveEntry: (entry: string) => string;
97
+ /** @internal Resolve the package condition used to evaluate an AOT entry. */
98
+ declare const resolveEntryModuleKind: (entry: string) => "cjs" | "esm";
96
99
  /** Runtime handler-JIT module a strip build can replace with a throwing stub. */
97
100
  interface StubPlan {
98
101
  /** Stub the internal handler codegen module. */
@@ -156,6 +159,21 @@ interface StubPlan {
156
159
  * least one validator that is not bridge-free, so the bridge is still needed
157
160
  */
158
161
  bridge: boolean;
162
+ /**
163
+ * Re-route `type/typebox-value` -> its statically-imported `-live` mirror
164
+ * (bundlers can't follow the runtime `require`)
165
+ * Every mode except sealed, there the unresolvable `require` is what lets TypeBox collapse
166
+ */
167
+ typeboxValue: boolean;
168
+ /**
169
+ * Re-route `type/typebox-type` -> its `-live` mirror
170
+ * Every mode, sealed included (unlike `typeboxValue`), sealed still executes
171
+ * user `t.*()` at route definition and `typebox/type` is already in the bundle
172
+ * via the virtual `elysia/type` module
173
+ *
174
+ * skipping the rewrite collapses nothing and only buys a startup crash on loader-less runtimes
175
+ */
176
+ typeboxType: boolean;
159
177
  /**
160
178
  * Replace `adapter/constants` with a target-specific stub that hard-selects
161
179
  * either `BunAdapter` or `WebStandardAdapter`, letting the bundler DCE the
@@ -202,7 +220,13 @@ declare const NO_STUB: StubPlan;
202
220
  * is not active, so the bridge must stay wired the ordinary way. No compat
203
221
  * stub, no reroute.
204
222
  */
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): {
223
+ 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,
224
+ /**
225
+ * A WS route declares a `cookie` schema. Its upgrade path handles cookies
226
+ * outside the handler JIT, so it emits no `cc` alias — stubbing on that
227
+ * alias alone would hand `src/ws/route.ts` a throwing `parseCookieRaw`
228
+ */
229
+ wsCookie?: boolean): {
206
230
  plan: StubPlan;
207
231
  mode: BridgeMode;
208
232
  };
@@ -258,7 +282,7 @@ declare const OVERRIDE_MAP: Record<string, {
258
282
  leaf: string;
259
283
  export: string;
260
284
  }>;
261
- declare function generateVirtualType(typeSpecifier?: string): Promise<string>;
285
+ declare function generateVirtualType(typeSpecifier?: string, moduleCondition?: AotModuleCondition): Promise<string>;
262
286
  interface CompiledArtifacts {
263
287
  source: string;
264
288
  /** Handler-JIT modules detection proved safe to stub for this app. */
@@ -284,9 +308,12 @@ declare const getAotWorkerDiagnostics: () => {
284
308
  */
285
309
  declare function siblingModuleExt(moduleUrl: string): '.mjs' | '.js' | '.ts';
286
310
  /** @internal Re-evaluate an entry in a disposable worker for watch rebuilds. */
287
- declare function generateCompiledArtifactsIsolated(file: string, options?: ElysiaAotOptions): Promise<CompiledArtifacts>;
288
- declare function generateCompiledArtifacts(file: string, options?: ElysiaAotOptions): Promise<CompiledArtifacts>;
311
+ declare function generateCompiledArtifactsIsolated(file: string, options?: ElysiaAotOptions, moduleCondition?: string): Promise<CompiledArtifacts>;
312
+ type ValidatorSlotIdentity = Pick<CapturedValidator, 'method' | 'path' | 'slot'>;
313
+ /** @internal Exact logical-slot gate used by AOT mode selection. */
314
+ declare function validatorSlotSetsMatch(expected: readonly ValidatorSlotIdentity[], captured: readonly ValidatorSlotIdentity[]): boolean;
315
+ declare function generateCompiledArtifacts(file: string, options?: ElysiaAotOptions, moduleCondition?: string): Promise<CompiledArtifacts>;
289
316
  declare const SOURCE_REGEX: RegExp;
290
317
  declare const realPath: (path: string) => string;
291
318
  //#endregion
292
- export { ADAPTER_BUN_FILTER, ADAPTER_CONSTANTS_FILTER, BridgeMode, CompiledArtifacts, ELYSIA_MODULE_FILTER, ElysiaAotOptions, IS_PRODUCTION_FILTER, NO_STUB, OVERRIDE_MAP, SOURCE_REGEX, STUB_SOURCES, StubPlan, adapterConstantsSource, alignStubExtensions, bunAdapterStubSource, generateCompiledArtifacts, generateCompiledArtifactsIsolated, generateVirtualType, getAotWorkerDiagnostics, makeElysiaModuleFilterRegex, makeIsElysiaModule, planFromReport, realPath, resolveElysiaRoot, resolveEntry, rewriteIsProductionCalls, siblingModuleExt };
319
+ export { ADAPTER_BUN_FILTER, ADAPTER_CONSTANTS_FILTER, BridgeMode, CompiledArtifacts, ELYSIA_MODULE_FILTER, ElysiaAotOptions, IS_PRODUCTION_FILTER, NO_STUB, OVERRIDE_MAP, SOURCE_REGEX, STUB_SOURCES, StubPlan, adapterConstantsSource, alignStubExtensions, bunAdapterStubSource, generateCompiledArtifacts, generateCompiledArtifactsIsolated, generateVirtualType, getAotWorkerDiagnostics, makeElysiaModuleFilterRegex, makeIsElysiaModule, planFromReport, realPath, resolveElysiaRoot, resolveEntry, resolveEntryModuleKind, rewriteIsProductionCalls, siblingModuleExt, validatorSlotSetsMatch };