elysia 2.0.0-exp.1 → 2.0.0-exp.11

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 (195) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +0 -2
  2. package/dist/adapter/bun/index.d.ts +1 -1
  3. package/dist/adapter/bun/index.js +5 -2
  4. package/dist/adapter/bun/index.mjs +5 -2
  5. package/dist/adapter/bun/router.js +2 -2
  6. package/dist/adapter/bun/router.mjs +2 -2
  7. package/dist/adapter/constants.d.ts +1 -1
  8. package/dist/adapter/index.d.ts +1 -1
  9. package/dist/adapter/utils.d.ts +3 -6
  10. package/dist/adapter/utils.js +88 -83
  11. package/dist/adapter/utils.mjs +87 -82
  12. package/dist/adapter/web-standard/handler.js +6 -3
  13. package/dist/adapter/web-standard/handler.mjs +6 -3
  14. package/dist/adapter/web-standard/index.d.ts +1 -1
  15. package/dist/base.d.ts +2 -59
  16. package/dist/base.js +86 -73
  17. package/dist/base.mjs +88 -75
  18. package/dist/compile/aot.d.ts +62 -35
  19. package/dist/compile/aot.js +35 -37
  20. package/dist/compile/aot.mjs +35 -38
  21. package/dist/compile/handler/index.d.ts +5 -3
  22. package/dist/compile/handler/index.js +84 -448
  23. package/dist/compile/handler/index.mjs +85 -450
  24. package/dist/compile/handler/jit.d.ts +35 -0
  25. package/dist/compile/handler/jit.js +445 -0
  26. package/dist/compile/handler/jit.mjs +443 -0
  27. package/dist/compile/handler/params.js +3 -2
  28. package/dist/compile/handler/params.mjs +4 -3
  29. package/dist/compile/handler/reconstruct.d.ts +13 -0
  30. package/dist/compile/handler/reconstruct.js +29 -0
  31. package/dist/compile/handler/reconstruct.mjs +28 -0
  32. package/dist/compile/handler/utils.d.ts +2 -1
  33. package/dist/compile/handler/utils.js +12 -6
  34. package/dist/compile/handler/utils.mjs +12 -7
  35. package/dist/compile/index.d.ts +2 -2
  36. package/dist/compile/index.js +2 -1
  37. package/dist/compile/index.mjs +2 -2
  38. package/dist/compile/jit-probe.d.ts +19 -0
  39. package/dist/compile/jit-probe.js +38 -0
  40. package/dist/compile/jit-probe.mjs +36 -0
  41. package/dist/cookie/config.js +7 -6
  42. package/dist/cookie/config.mjs +7 -6
  43. package/dist/cookie/cookie.js +1 -3
  44. package/dist/cookie/cookie.mjs +1 -3
  45. package/dist/cookie/index.d.ts +2 -1
  46. package/dist/cookie/index.js +2 -1
  47. package/dist/cookie/index.mjs +2 -1
  48. package/dist/cookie/serialize.d.ts +6 -0
  49. package/dist/cookie/serialize.js +28 -0
  50. package/dist/cookie/serialize.mjs +27 -0
  51. package/dist/cookie/utils.d.ts +1 -2
  52. package/dist/cookie/utils.js +7 -26
  53. package/dist/cookie/utils.mjs +10 -28
  54. package/dist/error.d.ts +6 -9
  55. package/dist/error.js +26 -19
  56. package/dist/error.mjs +26 -19
  57. package/dist/handler/error.js +4 -4
  58. package/dist/handler/error.mjs +5 -5
  59. package/dist/handler/fetch.js +58 -17
  60. package/dist/handler/fetch.mjs +59 -18
  61. package/dist/index.d.ts +8 -5
  62. package/dist/index.js +15 -10
  63. package/dist/index.mjs +9 -6
  64. package/dist/parse-query.js +1 -1
  65. package/dist/parse-query.mjs +1 -1
  66. package/dist/plugin/bun.js +37 -4
  67. package/dist/plugin/bun.mjs +37 -5
  68. package/dist/plugin/core.d.ts +69 -2
  69. package/dist/plugin/core.js +90 -10
  70. package/dist/plugin/core.mjs +90 -12
  71. package/dist/plugin/esbuild.js +36 -4
  72. package/dist/plugin/esbuild.mjs +37 -5
  73. package/dist/plugin/source.d.ts +38 -1
  74. package/dist/plugin/source.js +125 -12
  75. package/dist/plugin/source.mjs +123 -13
  76. package/dist/plugin/treeshake.d.ts +10 -0
  77. package/dist/plugin/treeshake.js +63 -0
  78. package/dist/plugin/treeshake.mjs +61 -0
  79. package/dist/plugin/vite.js +22 -2
  80. package/dist/plugin/vite.mjs +23 -3
  81. package/dist/sucrose.js +23 -10
  82. package/dist/sucrose.mjs +23 -10
  83. package/dist/trace.d.ts +1 -1
  84. package/dist/trace.js +5 -7
  85. package/dist/trace.mjs +5 -7
  86. package/dist/type/bridge.d.ts +4 -7
  87. package/dist/type/bridge.js +0 -10
  88. package/dist/type/bridge.mjs +1 -9
  89. package/dist/type/coerce.d.ts +19 -1
  90. package/dist/type/coerce.js +148 -4
  91. package/dist/type/coerce.mjs +147 -6
  92. package/dist/type/compat.js +6 -7
  93. package/dist/type/compat.mjs +7 -8
  94. package/dist/type/constants.d.ts +1 -1
  95. package/dist/type/elysia/array-buffer.js +4 -4
  96. package/dist/type/elysia/array-buffer.mjs +4 -4
  97. package/dist/type/elysia/array-string.d.ts +2 -2
  98. package/dist/type/elysia/array-string.js +5 -5
  99. package/dist/type/elysia/array-string.mjs +6 -6
  100. package/dist/type/elysia/array.js +11 -8
  101. package/dist/type/elysia/array.mjs +11 -8
  102. package/dist/type/elysia/boolean-string.js +4 -4
  103. package/dist/type/elysia/boolean-string.mjs +4 -4
  104. package/dist/type/elysia/boolean.js +2 -2
  105. package/dist/type/elysia/boolean.mjs +2 -2
  106. package/dist/type/elysia/cookie.js +1 -4
  107. package/dist/type/elysia/cookie.mjs +1 -4
  108. package/dist/type/elysia/date.js +11 -10
  109. package/dist/type/elysia/date.mjs +11 -10
  110. package/dist/type/elysia/file-type.js +1 -1
  111. package/dist/type/elysia/file-type.mjs +1 -1
  112. package/dist/type/elysia/file.js +4 -4
  113. package/dist/type/elysia/file.mjs +4 -4
  114. package/dist/type/elysia/files.js +4 -4
  115. package/dist/type/elysia/files.mjs +4 -4
  116. package/dist/type/elysia/form.js +2 -2
  117. package/dist/type/elysia/form.mjs +4 -4
  118. package/dist/type/elysia/integer-string.js +7 -7
  119. package/dist/type/elysia/integer-string.mjs +8 -8
  120. package/dist/type/elysia/integer.js +2 -2
  121. package/dist/type/elysia/integer.mjs +2 -2
  122. package/dist/type/elysia/maybe-empty.d.ts +3 -2
  123. package/dist/type/elysia/maybe-empty.js +4 -4
  124. package/dist/type/elysia/maybe-empty.mjs +4 -4
  125. package/dist/type/elysia/nullable.d.ts +3 -2
  126. package/dist/type/elysia/nullable.js +3 -3
  127. package/dist/type/elysia/nullable.mjs +3 -3
  128. package/dist/type/elysia/number.js +2 -2
  129. package/dist/type/elysia/number.mjs +2 -2
  130. package/dist/type/elysia/numeric-enum.js +3 -3
  131. package/dist/type/elysia/numeric-enum.mjs +3 -3
  132. package/dist/type/elysia/numeric.js +7 -7
  133. package/dist/type/elysia/numeric.mjs +7 -7
  134. package/dist/type/elysia/object-string.d.ts +2 -2
  135. package/dist/type/elysia/object-string.js +5 -5
  136. package/dist/type/elysia/object-string.mjs +6 -6
  137. package/dist/type/elysia/object.js +12 -9
  138. package/dist/type/elysia/object.mjs +12 -9
  139. package/dist/type/elysia/optional.js +12 -5
  140. package/dist/type/elysia/optional.mjs +12 -5
  141. package/dist/type/elysia/string.js +2 -2
  142. package/dist/type/elysia/string.mjs +2 -2
  143. package/dist/type/elysia/uint8-array.js +2 -2
  144. package/dist/type/elysia/uint8-array.mjs +2 -2
  145. package/dist/type/elysia/union-enum.d.ts +3 -2
  146. package/dist/type/elysia/union-enum.js +2 -2
  147. package/dist/type/elysia/union-enum.mjs +2 -2
  148. package/dist/type/elysia/utils.js +4 -8
  149. package/dist/type/elysia/utils.mjs +4 -8
  150. package/dist/type/exports.js +2071 -39
  151. package/dist/type/exports.mjs +307 -17
  152. package/dist/type/index.d.ts +5 -3
  153. package/dist/type/index.js +7 -30
  154. package/dist/type/index.mjs +5 -25
  155. package/dist/type/types.d.ts +1 -1
  156. package/dist/type/utils.js +4 -4
  157. package/dist/type/utils.mjs +4 -4
  158. package/dist/type/validator/custom-error.d.ts +10 -0
  159. package/dist/type/validator/custom-error.js +113 -0
  160. package/dist/type/validator/custom-error.mjs +110 -0
  161. package/dist/type/validator/default-precompute.d.ts +22 -0
  162. package/dist/type/validator/default-precompute.js +476 -0
  163. package/dist/type/validator/default-precompute.mjs +465 -0
  164. package/dist/type/validator/frozen-check.d.ts +11 -0
  165. package/dist/type/validator/frozen-check.js +19 -0
  166. package/dist/type/validator/frozen-check.mjs +18 -0
  167. package/dist/type/{validator.d.ts → validator/index.d.ts} +7 -20
  168. package/dist/type/validator/index.js +572 -0
  169. package/dist/type/validator/index.mjs +567 -0
  170. package/dist/type/validator/string-codec-aot.d.ts +9 -0
  171. package/dist/type/validator/string-codec-aot.js +106 -0
  172. package/dist/type/validator/string-codec-aot.mjs +102 -0
  173. package/dist/type/validator/validator-cache.d.ts +21 -0
  174. package/dist/type/validator/validator-cache.js +163 -0
  175. package/dist/type/validator/validator-cache.mjs +161 -0
  176. package/dist/types.d.ts +6 -0
  177. package/dist/universal/file.d.ts +9 -9
  178. package/dist/universal/file.js +35 -29
  179. package/dist/universal/file.mjs +35 -29
  180. package/dist/utils.d.ts +8 -1
  181. package/dist/utils.js +86 -52
  182. package/dist/utils.mjs +86 -53
  183. package/dist/validator/index.d.ts +1 -1
  184. package/dist/validator/index.js +13 -6
  185. package/dist/validator/index.mjs +13 -6
  186. package/dist/validator/route.d.ts +0 -1
  187. package/dist/validator/route.js +1 -1
  188. package/dist/validator/route.mjs +1 -1
  189. package/dist/ws/context.js +4 -7
  190. package/dist/ws/context.mjs +4 -7
  191. package/dist/ws/route.js +48 -27
  192. package/dist/ws/route.mjs +48 -27
  193. package/package.json +12 -3
  194. package/dist/type/validator.js +0 -667
  195. package/dist/type/validator.mjs +0 -663
@@ -32,7 +32,6 @@ var __copyProps = (to, from, except, desc) => {
32
32
  }
33
33
  return to;
34
34
  };
35
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
36
35
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
37
36
  value: mod,
38
37
  enumerable: true
@@ -41,5 +40,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
41
40
  //#endregion
42
41
 
43
42
  exports.__exportAll = __exportAll;
44
- exports.__reExport = __reExport;
45
43
  exports.__toESM = __toESM;
@@ -6,7 +6,7 @@ import { AnyElysia } from "../../base.js";
6
6
  declare function collectStaticRoutes(app: AnyElysia): readonly [Record<string, Record<string, Response>>, Promise<void>[]] | undefined;
7
7
  declare const BunAdapter: {
8
8
  parse: {
9
- default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
9
+ default: (context: Context, contentType: string) => string | Record<string, unknown> | unknown[] | ArrayBuffer | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
10
10
  json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
11
11
  text: (context: Context) => MaybePromise<string>;
12
12
  urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
@@ -36,13 +36,16 @@ const BunAdapter = require_adapter_index.createAdapter({
36
36
  runtime: "bun",
37
37
  listen(app, options, callback) {
38
38
  const _config = app["~config"]?.serve;
39
- const _options = typeof options === "object" ? options : { port: +options };
39
+ const _options = typeof options === "object" ? options : {
40
+ port: +options,
41
+ fetch: (request, server) => app.fetch(request, server)
42
+ };
40
43
  const serve = _config ? {
41
44
  ..._config,
42
45
  ..._options
43
46
  } : _options;
44
47
  const hasWs = app["~hasWS"];
45
- serve.fetch = (request, server) => app.fetch(request, server);
48
+ if (!serve.fetch) serve.fetch = (request, server) => app.fetch(request, server);
46
49
  app.server = Bun.serve(serve);
47
50
  if (!hasWs) callback?.(app.server);
48
51
  queueMicrotask(() => {
@@ -35,13 +35,16 @@ const BunAdapter = createAdapter({
35
35
  runtime: "bun",
36
36
  listen(app, options, callback) {
37
37
  const _config = app["~config"]?.serve;
38
- const _options = typeof options === "object" ? options : { port: +options };
38
+ const _options = typeof options === "object" ? options : {
39
+ port: +options,
40
+ fetch: (request, server) => app.fetch(request, server)
41
+ };
39
42
  const serve = _config ? {
40
43
  ..._config,
41
44
  ..._options
42
45
  } : _options;
43
46
  const hasWs = app["~hasWS"];
44
- serve.fetch = (request, server) => app.fetch(request, server);
47
+ if (!serve.fetch) serve.fetch = (request, server) => app.fetch(request, server);
45
48
  app.server = Bun.serve(serve);
46
49
  if (!hasWs) callback?.(app.server);
47
50
  queueMicrotask(() => {
@@ -9,7 +9,7 @@ const require_handler_error = require('../../handler/error.js');
9
9
 
10
10
  //#region src/adapter/bun/router.ts
11
11
  function createBunContext(app) {
12
- const headers = app["~ext"]?.headers ? Object.assign(require_utils.nullObject(), structuredClone(app["~ext"].headers)) : null;
12
+ const headers = app["~ext"]?.headers ? Object.assign(require_utils.nullObject(), app["~ext"].headers) : null;
13
13
  return class Context extends require_context.createBaseContext(app) {
14
14
  constructor(request) {
15
15
  super();
@@ -62,13 +62,13 @@ function createPlainHandler(handler, handleError, Context) {
62
62
  }
63
63
  function createRouteMap(app) {
64
64
  const Context = createBunContext(app);
65
+ const handleError = require_handler_error.createErrorHandler(require_utils.flattenChain(app["~hookChain"])?.error, require_adapter_web_standard_index.WebStandardAdapter.response.map, new Response("Not Found", { status: 404 }), app["~config"]?.allowUnsafeValidationDetails);
65
66
  function fetch(request) {
66
67
  return handleError(new Context(request), new require_error.NotFound());
67
68
  }
68
69
  const history = app.history;
69
70
  const length = history?.length ?? 0;
70
71
  if (length === 0) return [{ "/elysia": new Response("hi") }, fetch];
71
- const handleError = require_handler_error.createErrorHandler(require_utils.flattenChain(app["~hookChain"])?.error, require_adapter_web_standard_index.WebStandardAdapter.response.map, new Response("Not Found", { status: 404 }), app["~config"]?.allowUnsafeValidationDetails);
72
72
  const routes = require_utils.nullObject();
73
73
  for (let i = 0; i < length; i++) {
74
74
  const route = history[i];
@@ -8,7 +8,7 @@ import { createErrorHandler } from "../../handler/error.mjs";
8
8
 
9
9
  //#region src/adapter/bun/router.ts
10
10
  function createBunContext(app) {
11
- const headers = app["~ext"]?.headers ? Object.assign(nullObject(), structuredClone(app["~ext"].headers)) : null;
11
+ const headers = app["~ext"]?.headers ? Object.assign(nullObject(), app["~ext"].headers) : null;
12
12
  return class Context extends createBaseContext(app) {
13
13
  constructor(request) {
14
14
  super();
@@ -61,13 +61,13 @@ function createPlainHandler(handler, handleError, Context) {
61
61
  }
62
62
  function createRouteMap(app) {
63
63
  const Context = createBunContext(app);
64
+ const handleError = createErrorHandler(flattenChain(app["~hookChain"])?.error, WebStandardAdapter.response.map, new Response("Not Found", { status: 404 }), app["~config"]?.allowUnsafeValidationDetails);
64
65
  function fetch(request) {
65
66
  return handleError(new Context(request), new NotFound());
66
67
  }
67
68
  const history = app.history;
68
69
  const length = history?.length ?? 0;
69
70
  if (length === 0) return [{ "/elysia": new Response("hi") }, fetch];
70
- const handleError = createErrorHandler(flattenChain(app["~hookChain"])?.error, WebStandardAdapter.response.map, new Response("Not Found", { status: 404 }), app["~config"]?.allowUnsafeValidationDetails);
71
71
  const routes = nullObject();
72
72
  for (let i = 0; i < length; i++) {
73
73
  const route = history[i];
@@ -5,7 +5,7 @@ import { AnyElysia } from "../base.js";
5
5
  //#region src/adapter/constants.d.ts
6
6
  declare const defaultAdapter: {
7
7
  parse: {
8
- default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
8
+ default: (context: Context, contentType: string) => string | Record<string, unknown> | unknown[] | ArrayBuffer | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
9
9
  json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
10
10
  text: (context: Context) => MaybePromise<string>;
11
11
  urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
@@ -7,7 +7,7 @@ import { AnyElysia } from "../base.js";
7
7
  //#region src/adapter/index.d.ts
8
8
  declare function createAdapter(adapter: ElysiaAdapterOptions): {
9
9
  parse: {
10
- default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
10
+ default: (context: Context, contentType: string) => string | Record<string, unknown> | unknown[] | ArrayBuffer | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
11
11
  json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
12
12
  text: (context: Context) => MaybePromise<string>;
13
13
  urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
@@ -12,21 +12,18 @@ declare function responseToSetHeaders(response: Response, set?: Context['set']):
12
12
  cookie?: Record<string, BaseCookie>;
13
13
  } | {
14
14
  headers: any;
15
- status: number | "Bad Request" | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required";
15
+ status: number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Enhance Your Calm" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required";
16
16
  };
17
17
  interface CreateHandlerParameter {
18
18
  mapResponse(response: unknown, set: Context['set'], request?: Request): Response;
19
19
  mapCompactResponse(response: unknown, request?: Request): Response;
20
20
  }
21
- declare const createStreamHandler: ({
22
- mapResponse,
23
- mapCompactResponse
24
- }: CreateHandlerParameter) => (generator: Generator | AsyncGenerator | ReadableStream, set?: Context["set"], request?: Request, skipFormat?: boolean) => Promise<Response>;
21
+ declare function createStreamHandler(_: CreateHandlerParameter): (generator: Generator | AsyncGenerator | ReadableStream, set?: Context["set"], request?: Request, skipFormat?: boolean) => Promise<Response>;
25
22
  declare function streamResponse(response: Response): AsyncGenerator<any, void, any>;
26
23
  declare function handleSet(set: Context['set']): void;
27
24
  declare function mergeHeaders(responseHeaders: Headers, setHeaders: Context['set']['headers']): Headers;
28
25
  declare function mergeStatus(responseStatus: number, setStatus: Context['set']['status']): number | undefined;
29
- declare const createResponseHandler: (handler: CreateHandlerParameter) => (response: Response, set?: Context["set"], request?: Request) => any;
26
+ declare function createResponseHandler(handler: CreateHandlerParameter): (response: Response, set?: Context["set"], request?: Request) => any;
30
27
  /**
31
28
  * Split async source into `branches` independent iterators
32
29
  *
@@ -2,7 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_universal_constants = require('../universal/constants.js');
3
3
  const require_constants = require('../constants.js');
4
4
  const require_utils = require('../utils.js');
5
- const require_cookie_utils = require('../cookie/utils.js');
5
+ const require_cookie_serialize = require('../cookie/serialize.js');
6
+ const require_adapter_web_standard_handler = require('./web-standard/handler.js');
6
7
 
7
8
  //#region src/adapter/utils.ts
8
9
  const setCookie = "set-cookie";
@@ -51,7 +52,7 @@ function handleFile(response, set, request) {
51
52
  if (!set && !size) return new Response(response);
52
53
  if (!set) return new Response(response, { headers: defaultHeader });
53
54
  if (set.headers instanceof Headers) {
54
- for (const key of Object.keys(defaultHeader)) if (key in set.headers) set.headers.append(key, defaultHeader[key]);
55
+ for (const key of Object.keys(defaultHeader)) if (!set.headers.has(key)) set.headers.append(key, defaultHeader[key]);
55
56
  if (immutable) {
56
57
  set.headers.delete("content-length");
57
58
  set.headers.delete("accept-ranges");
@@ -96,10 +97,12 @@ function responseToSetHeaders(response, set) {
96
97
  };
97
98
  for (const [key, value] of response.headers.entries()) set.headers[key] = value;
98
99
  }
99
- if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
100
+ if (set.headers instanceof Headers) {
101
+ if (set.headers.has("content-encoding")) set.headers.delete("content-encoding");
102
+ } else if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
100
103
  return set;
101
104
  }
102
- const enqueueBinaryChunk = (controller, chunk) => {
105
+ function enqueueBinaryChunk(controller, chunk) {
103
106
  if (chunk instanceof Blob) return chunk.arrayBuffer().then((buffer) => {
104
107
  controller.enqueue(new Uint8Array(buffer));
105
108
  return true;
@@ -117,91 +120,93 @@ const enqueueBinaryChunk = (controller, chunk) => {
117
120
  return true;
118
121
  }
119
122
  return false;
120
- };
121
- const createStreamHandler = ({ mapResponse, mapCompactResponse }) => async (generator, set, request, skipFormat) => {
122
- let init = generator.next?.();
123
- if (set) handleSet(set);
124
- if (init instanceof Promise) init = await init;
125
- if (init?.value instanceof ReadableStream) generator = init.value;
126
- else if (init && (typeof init?.done === "undefined" || init?.done)) {
127
- if (set) return mapResponse(init.value, set, request);
128
- return mapCompactResponse(init.value, request);
129
- }
130
- const isSSE = !skipFormat && (init?.value?.sse ?? generator?.sse ?? set?.headers["content-type"]?.startsWith("text/event-stream"));
131
- const format = isSSE ? (data) => `data: ${data}\n\n` : (data) => data;
132
- const contentType = isSSE ? "text/event-stream" : init?.value && typeof init?.value === "object" ? ArrayBuffer.isView(init.value) ? "application/octet-stream" : "application/json" : "text/plain";
133
- const headers = set?.headers;
134
- if (headers) {
135
- if (!headers["transfer-encoding"]) headers["transfer-encoding"] = "chunked";
136
- if (!headers["content-type"]) headers["content-type"] = contentType;
137
- if (!headers["cache-control"]) headers["cache-control"] = "no-cache";
138
- } else set = {
139
- status: 200,
140
- headers: {
141
- "content-type": contentType,
142
- "transfer-encoding": "chunked",
143
- "cache-control": "no-cache",
144
- connection: "keep-alive"
123
+ }
124
+ function createStreamHandler(_) {
125
+ return async (generator, set, request, skipFormat) => {
126
+ let init = generator.next?.();
127
+ if (set) handleSet(set);
128
+ if (init instanceof Promise) init = await init;
129
+ if (init?.value instanceof ReadableStream) generator = init.value;
130
+ else if (init && (typeof init?.done === "undefined" || init?.done)) {
131
+ if (set) return require_adapter_web_standard_handler.mapResponse(init.value, set, request);
132
+ return require_adapter_web_standard_handler.mapCompactResponse(init.value, request);
145
133
  }
146
- };
147
- const iterator = typeof generator.next === "function" ? generator : generator[Symbol.asyncIterator]();
148
- let end = false;
149
- return new Response(new ReadableStream({
150
- start(controller) {
151
- request?.signal?.addEventListener("abort", () => {
152
- end = true;
153
- iterator.return?.();
154
- try {
155
- controller.close();
156
- } catch {}
157
- });
158
- if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
159
- if (init.value.toSSE) controller.enqueue(init.value.toSSE());
160
- else if (enqueueBinaryChunk(controller, init.value)) return;
161
- else if (typeof init.value === "object") try {
162
- controller.enqueue(format(JSON.stringify(init.value)));
163
- } catch {
164
- controller.enqueue(format(init.value.toString()));
165
- }
166
- else controller.enqueue(format(init.value.toString()));
167
- },
168
- async pull(controller) {
169
- if (end) {
170
- try {
171
- controller.close();
172
- } catch {}
173
- return;
134
+ const isSSE = !skipFormat && (init?.value?.sse ?? generator?.sse ?? set?.headers["content-type"]?.startsWith("text/event-stream"));
135
+ const format = isSSE ? (data) => `data: ${data}\n\n` : (data) => data;
136
+ const contentType = isSSE ? "text/event-stream" : init?.value && typeof init?.value === "object" ? ArrayBuffer.isView(init.value) ? "application/octet-stream" : "application/json" : "text/plain";
137
+ const headers = set?.headers;
138
+ if (headers) {
139
+ if (!headers["transfer-encoding"]) headers["transfer-encoding"] = "chunked";
140
+ if (!headers["content-type"]) headers["content-type"] = contentType;
141
+ if (!headers["cache-control"]) headers["cache-control"] = "no-cache";
142
+ } else set = {
143
+ status: 200,
144
+ headers: {
145
+ "content-type": contentType,
146
+ "transfer-encoding": "chunked",
147
+ "cache-control": "no-cache",
148
+ connection: "keep-alive"
174
149
  }
175
- try {
176
- const { value: chunk, done } = await iterator.next();
177
- if (done || end) {
150
+ };
151
+ const iterator = typeof generator.next === "function" ? generator : generator[Symbol.asyncIterator]();
152
+ let end = false;
153
+ return new Response(new ReadableStream({
154
+ start(controller) {
155
+ request?.signal?.addEventListener("abort", () => {
156
+ end = true;
157
+ iterator.return?.();
178
158
  try {
179
159
  controller.close();
180
160
  } catch {}
181
- return;
182
- }
183
- if (chunk === void 0 || chunk === null) return;
184
- if (chunk.toSSE) controller.enqueue(chunk.toSSE());
185
- else if (enqueueBinaryChunk(controller, chunk)) return;
186
- else if (typeof chunk === "object") try {
187
- controller.enqueue(format(JSON.stringify(chunk)));
161
+ });
162
+ if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
163
+ if (init.value.toSSE) controller.enqueue(init.value.toSSE());
164
+ else if (enqueueBinaryChunk(controller, init.value)) return;
165
+ else if (typeof init.value === "object") try {
166
+ controller.enqueue(format(JSON.stringify(init.value)));
188
167
  } catch {
189
- controller.enqueue(format(chunk.toString()));
168
+ controller.enqueue(format(init.value.toString()));
169
+ }
170
+ else controller.enqueue(format(init.value.toString()));
171
+ },
172
+ async pull(controller) {
173
+ if (end) {
174
+ try {
175
+ controller.close();
176
+ } catch {}
177
+ return;
190
178
  }
191
- else controller.enqueue(format(chunk.toString()));
192
- } catch (error) {
193
- console.warn(error);
194
179
  try {
195
- controller.close();
196
- } catch {}
180
+ const { value: chunk, done } = await iterator.next();
181
+ if (done || end) {
182
+ try {
183
+ controller.close();
184
+ } catch {}
185
+ return;
186
+ }
187
+ if (chunk === void 0 || chunk === null) return;
188
+ if (chunk.toSSE) controller.enqueue(chunk.toSSE());
189
+ else if (enqueueBinaryChunk(controller, chunk)) return;
190
+ else if (typeof chunk === "object") try {
191
+ controller.enqueue(format(JSON.stringify(chunk)));
192
+ } catch {
193
+ controller.enqueue(format(chunk.toString()));
194
+ }
195
+ else controller.enqueue(format(chunk.toString()));
196
+ } catch (error) {
197
+ console.warn(error);
198
+ try {
199
+ controller.close();
200
+ } catch {}
201
+ }
202
+ },
203
+ cancel() {
204
+ end = true;
205
+ iterator.return?.();
197
206
  }
198
- },
199
- cancel() {
200
- end = true;
201
- iterator.return?.();
202
- }
203
- }), set);
204
- };
207
+ }), set);
208
+ };
209
+ }
205
210
  async function* streamResponse(response) {
206
211
  const body = response.body;
207
212
  if (body) yield* body;
@@ -215,7 +220,7 @@ function handleSet(set) {
215
220
  set.headers = flat;
216
221
  }
217
222
  if (set.cookie && require_utils.isNotEmpty(set.cookie)) {
218
- const cookie = require_cookie_utils.serializeCookie(set.cookie);
223
+ const cookie = require_cookie_serialize.serializeCookie(set.cookie);
219
224
  if (cookie) set.headers[setCookie] = cookie;
220
225
  }
221
226
  if (set.headers[setCookie] && Array.isArray(set.headers[setCookie])) set.headers = parseSetCookies(new Headers(set.headers), set.headers[setCookie]);
@@ -239,7 +244,7 @@ function mergeStatus(responseStatus, setStatus) {
239
244
  if (responseStatus === 200) return setStatus;
240
245
  return responseStatus;
241
246
  }
242
- const createResponseHandler = (handler) => {
247
+ function createResponseHandler(handler) {
243
248
  const handleStream = createStreamHandler(handler);
244
249
  return (response, set, request) => {
245
250
  if (set) {
@@ -263,7 +268,7 @@ const createResponseHandler = (handler) => {
263
268
  if (!newResponse.headers.has("content-length") && newResponse.headers.get("transfer-encoding") === "chunked") return handleStream(streamResponse(newResponse), responseToSetHeaders(newResponse, set), request, true);
264
269
  return newResponse;
265
270
  };
266
- };
271
+ }
267
272
  /**
268
273
  * Split async source into `branches` independent iterators
269
274
  *
@@ -1,7 +1,8 @@
1
1
  import { hasHeaderShorthand, isBun } from "../universal/constants.mjs";
2
2
  import { StatusMap } from "../constants.mjs";
3
3
  import { isNotEmpty, nullObject } from "../utils.mjs";
4
- import { serializeCookie } from "../cookie/utils.mjs";
4
+ import { serializeCookie } from "../cookie/serialize.mjs";
5
+ import { mapCompactResponse, mapResponse } from "./web-standard/handler.mjs";
5
6
 
6
7
  //#region src/adapter/utils.ts
7
8
  const setCookie = "set-cookie";
@@ -50,7 +51,7 @@ function handleFile(response, set, request) {
50
51
  if (!set && !size) return new Response(response);
51
52
  if (!set) return new Response(response, { headers: defaultHeader });
52
53
  if (set.headers instanceof Headers) {
53
- for (const key of Object.keys(defaultHeader)) if (key in set.headers) set.headers.append(key, defaultHeader[key]);
54
+ for (const key of Object.keys(defaultHeader)) if (!set.headers.has(key)) set.headers.append(key, defaultHeader[key]);
54
55
  if (immutable) {
55
56
  set.headers.delete("content-length");
56
57
  set.headers.delete("accept-ranges");
@@ -95,10 +96,12 @@ function responseToSetHeaders(response, set) {
95
96
  };
96
97
  for (const [key, value] of response.headers.entries()) set.headers[key] = value;
97
98
  }
98
- if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
99
+ if (set.headers instanceof Headers) {
100
+ if (set.headers.has("content-encoding")) set.headers.delete("content-encoding");
101
+ } else if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
99
102
  return set;
100
103
  }
101
- const enqueueBinaryChunk = (controller, chunk) => {
104
+ function enqueueBinaryChunk(controller, chunk) {
102
105
  if (chunk instanceof Blob) return chunk.arrayBuffer().then((buffer) => {
103
106
  controller.enqueue(new Uint8Array(buffer));
104
107
  return true;
@@ -116,91 +119,93 @@ const enqueueBinaryChunk = (controller, chunk) => {
116
119
  return true;
117
120
  }
118
121
  return false;
119
- };
120
- const createStreamHandler = ({ mapResponse, mapCompactResponse }) => async (generator, set, request, skipFormat) => {
121
- let init = generator.next?.();
122
- if (set) handleSet(set);
123
- if (init instanceof Promise) init = await init;
124
- if (init?.value instanceof ReadableStream) generator = init.value;
125
- else if (init && (typeof init?.done === "undefined" || init?.done)) {
126
- if (set) return mapResponse(init.value, set, request);
127
- return mapCompactResponse(init.value, request);
128
- }
129
- const isSSE = !skipFormat && (init?.value?.sse ?? generator?.sse ?? set?.headers["content-type"]?.startsWith("text/event-stream"));
130
- const format = isSSE ? (data) => `data: ${data}\n\n` : (data) => data;
131
- const contentType = isSSE ? "text/event-stream" : init?.value && typeof init?.value === "object" ? ArrayBuffer.isView(init.value) ? "application/octet-stream" : "application/json" : "text/plain";
132
- const headers = set?.headers;
133
- if (headers) {
134
- if (!headers["transfer-encoding"]) headers["transfer-encoding"] = "chunked";
135
- if (!headers["content-type"]) headers["content-type"] = contentType;
136
- if (!headers["cache-control"]) headers["cache-control"] = "no-cache";
137
- } else set = {
138
- status: 200,
139
- headers: {
140
- "content-type": contentType,
141
- "transfer-encoding": "chunked",
142
- "cache-control": "no-cache",
143
- connection: "keep-alive"
122
+ }
123
+ function createStreamHandler(_) {
124
+ return async (generator, set, request, skipFormat) => {
125
+ let init = generator.next?.();
126
+ if (set) handleSet(set);
127
+ if (init instanceof Promise) init = await init;
128
+ if (init?.value instanceof ReadableStream) generator = init.value;
129
+ else if (init && (typeof init?.done === "undefined" || init?.done)) {
130
+ if (set) return mapResponse(init.value, set, request);
131
+ return mapCompactResponse(init.value, request);
144
132
  }
145
- };
146
- const iterator = typeof generator.next === "function" ? generator : generator[Symbol.asyncIterator]();
147
- let end = false;
148
- return new Response(new ReadableStream({
149
- start(controller) {
150
- request?.signal?.addEventListener("abort", () => {
151
- end = true;
152
- iterator.return?.();
153
- try {
154
- controller.close();
155
- } catch {}
156
- });
157
- if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
158
- if (init.value.toSSE) controller.enqueue(init.value.toSSE());
159
- else if (enqueueBinaryChunk(controller, init.value)) return;
160
- else if (typeof init.value === "object") try {
161
- controller.enqueue(format(JSON.stringify(init.value)));
162
- } catch {
163
- controller.enqueue(format(init.value.toString()));
164
- }
165
- else controller.enqueue(format(init.value.toString()));
166
- },
167
- async pull(controller) {
168
- if (end) {
169
- try {
170
- controller.close();
171
- } catch {}
172
- return;
133
+ const isSSE = !skipFormat && (init?.value?.sse ?? generator?.sse ?? set?.headers["content-type"]?.startsWith("text/event-stream"));
134
+ const format = isSSE ? (data) => `data: ${data}\n\n` : (data) => data;
135
+ const contentType = isSSE ? "text/event-stream" : init?.value && typeof init?.value === "object" ? ArrayBuffer.isView(init.value) ? "application/octet-stream" : "application/json" : "text/plain";
136
+ const headers = set?.headers;
137
+ if (headers) {
138
+ if (!headers["transfer-encoding"]) headers["transfer-encoding"] = "chunked";
139
+ if (!headers["content-type"]) headers["content-type"] = contentType;
140
+ if (!headers["cache-control"]) headers["cache-control"] = "no-cache";
141
+ } else set = {
142
+ status: 200,
143
+ headers: {
144
+ "content-type": contentType,
145
+ "transfer-encoding": "chunked",
146
+ "cache-control": "no-cache",
147
+ connection: "keep-alive"
173
148
  }
174
- try {
175
- const { value: chunk, done } = await iterator.next();
176
- if (done || end) {
149
+ };
150
+ const iterator = typeof generator.next === "function" ? generator : generator[Symbol.asyncIterator]();
151
+ let end = false;
152
+ return new Response(new ReadableStream({
153
+ start(controller) {
154
+ request?.signal?.addEventListener("abort", () => {
155
+ end = true;
156
+ iterator.return?.();
177
157
  try {
178
158
  controller.close();
179
159
  } catch {}
180
- return;
181
- }
182
- if (chunk === void 0 || chunk === null) return;
183
- if (chunk.toSSE) controller.enqueue(chunk.toSSE());
184
- else if (enqueueBinaryChunk(controller, chunk)) return;
185
- else if (typeof chunk === "object") try {
186
- controller.enqueue(format(JSON.stringify(chunk)));
160
+ });
161
+ if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
162
+ if (init.value.toSSE) controller.enqueue(init.value.toSSE());
163
+ else if (enqueueBinaryChunk(controller, init.value)) return;
164
+ else if (typeof init.value === "object") try {
165
+ controller.enqueue(format(JSON.stringify(init.value)));
187
166
  } catch {
188
- controller.enqueue(format(chunk.toString()));
167
+ controller.enqueue(format(init.value.toString()));
168
+ }
169
+ else controller.enqueue(format(init.value.toString()));
170
+ },
171
+ async pull(controller) {
172
+ if (end) {
173
+ try {
174
+ controller.close();
175
+ } catch {}
176
+ return;
189
177
  }
190
- else controller.enqueue(format(chunk.toString()));
191
- } catch (error) {
192
- console.warn(error);
193
178
  try {
194
- controller.close();
195
- } catch {}
179
+ const { value: chunk, done } = await iterator.next();
180
+ if (done || end) {
181
+ try {
182
+ controller.close();
183
+ } catch {}
184
+ return;
185
+ }
186
+ if (chunk === void 0 || chunk === null) return;
187
+ if (chunk.toSSE) controller.enqueue(chunk.toSSE());
188
+ else if (enqueueBinaryChunk(controller, chunk)) return;
189
+ else if (typeof chunk === "object") try {
190
+ controller.enqueue(format(JSON.stringify(chunk)));
191
+ } catch {
192
+ controller.enqueue(format(chunk.toString()));
193
+ }
194
+ else controller.enqueue(format(chunk.toString()));
195
+ } catch (error) {
196
+ console.warn(error);
197
+ try {
198
+ controller.close();
199
+ } catch {}
200
+ }
201
+ },
202
+ cancel() {
203
+ end = true;
204
+ iterator.return?.();
196
205
  }
197
- },
198
- cancel() {
199
- end = true;
200
- iterator.return?.();
201
- }
202
- }), set);
203
- };
206
+ }), set);
207
+ };
208
+ }
204
209
  async function* streamResponse(response) {
205
210
  const body = response.body;
206
211
  if (body) yield* body;
@@ -238,7 +243,7 @@ function mergeStatus(responseStatus, setStatus) {
238
243
  if (responseStatus === 200) return setStatus;
239
244
  return responseStatus;
240
245
  }
241
- const createResponseHandler = (handler) => {
246
+ function createResponseHandler(handler) {
242
247
  const handleStream = createStreamHandler(handler);
243
248
  return (response, set, request) => {
244
249
  if (set) {
@@ -262,7 +267,7 @@ const createResponseHandler = (handler) => {
262
267
  if (!newResponse.headers.has("content-length") && newResponse.headers.get("transfer-encoding") === "chunked") return handleStream(streamResponse(newResponse), responseToSetHeaders(newResponse, set), request, true);
263
268
  return newResponse;
264
269
  };
265
- };
270
+ }
266
271
  /**
267
272
  * Split async source into `branches` independent iterators
268
273
  *