elysia 2.0.0-exp.2 → 2.0.0-exp.21

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 (135) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +2 -0
  2. package/dist/adapter/bun/index.d.ts +2 -25
  3. package/dist/adapter/bun/index.js +18 -12
  4. package/dist/adapter/bun/index.mjs +19 -13
  5. package/dist/adapter/bun/router.js +1 -1
  6. package/dist/adapter/bun/router.mjs +1 -1
  7. package/dist/adapter/constants.d.ts +3 -26
  8. package/dist/adapter/index.d.ts +1 -26
  9. package/dist/adapter/index.js +1 -17
  10. package/dist/adapter/index.mjs +1 -17
  11. package/dist/adapter/types.d.ts +1 -0
  12. package/dist/adapter/utils.d.ts +3 -4
  13. package/dist/adapter/utils.js +83 -81
  14. package/dist/adapter/utils.mjs +82 -80
  15. package/dist/adapter/web-standard/handler.js +6 -3
  16. package/dist/adapter/web-standard/handler.mjs +6 -3
  17. package/dist/adapter/web-standard/index.d.ts +2 -26
  18. package/dist/adapter/web-standard/index.js +12 -1
  19. package/dist/adapter/web-standard/index.mjs +12 -1
  20. package/dist/base.d.ts +38 -68
  21. package/dist/base.js +133 -97
  22. package/dist/base.mjs +133 -97
  23. package/dist/compile/aot.d.ts +22 -1
  24. package/dist/compile/aot.js +22 -0
  25. package/dist/compile/aot.mjs +22 -0
  26. package/dist/compile/handler/index.d.ts +2 -2
  27. package/dist/compile/handler/index.js +85 -456
  28. package/dist/compile/handler/index.mjs +86 -457
  29. package/dist/compile/handler/jit.d.ts +35 -0
  30. package/dist/compile/handler/jit.js +445 -0
  31. package/dist/compile/handler/jit.mjs +443 -0
  32. package/dist/compile/handler/params.js +3 -2
  33. package/dist/compile/handler/params.mjs +4 -3
  34. package/dist/compile/handler/reconstruct.d.ts +13 -0
  35. package/dist/compile/handler/reconstruct.js +29 -0
  36. package/dist/compile/handler/reconstruct.mjs +28 -0
  37. package/dist/compile/handler/utils.d.ts +2 -1
  38. package/dist/compile/handler/utils.js +9 -3
  39. package/dist/compile/handler/utils.mjs +9 -4
  40. package/dist/compile/jit-probe.d.ts +19 -0
  41. package/dist/compile/jit-probe.js +38 -0
  42. package/dist/compile/jit-probe.mjs +36 -0
  43. package/dist/cookie/index.d.ts +4 -3
  44. package/dist/cookie/index.js +2 -1
  45. package/dist/cookie/index.mjs +2 -1
  46. package/dist/cookie/serialize.d.ts +6 -0
  47. package/dist/cookie/serialize.js +28 -0
  48. package/dist/cookie/serialize.mjs +27 -0
  49. package/dist/cookie/utils.d.ts +1 -2
  50. package/dist/cookie/utils.js +2 -23
  51. package/dist/cookie/utils.mjs +5 -25
  52. package/dist/handler/error.js +2 -2
  53. package/dist/handler/error.mjs +3 -3
  54. package/dist/handler/fetch.js +49 -42
  55. package/dist/handler/fetch.mjs +50 -43
  56. package/dist/index.d.ts +13 -8
  57. package/dist/index.js +11 -4
  58. package/dist/index.mjs +7 -6
  59. package/dist/parse-query.js +1 -1
  60. package/dist/parse-query.mjs +1 -1
  61. package/dist/plugin/bun.d.ts +10 -0
  62. package/dist/plugin/bun.js +18 -1
  63. package/dist/plugin/bun.mjs +19 -2
  64. package/dist/plugin/core.d.ts +61 -1
  65. package/dist/plugin/core.js +90 -10
  66. package/dist/plugin/core.mjs +90 -12
  67. package/dist/plugin/esbuild.d.ts +10 -0
  68. package/dist/plugin/esbuild.js +18 -1
  69. package/dist/plugin/esbuild.mjs +19 -2
  70. package/dist/plugin/source.d.ts +38 -1
  71. package/dist/plugin/source.js +104 -13
  72. package/dist/plugin/source.mjs +102 -14
  73. package/dist/plugin/vite.d.ts +7 -0
  74. package/dist/plugin/vite.js +22 -1
  75. package/dist/plugin/vite.mjs +23 -2
  76. package/dist/sucrose.js +23 -10
  77. package/dist/sucrose.mjs +23 -10
  78. package/dist/trace.d.ts +1 -1
  79. package/dist/trace.js +4 -6
  80. package/dist/trace.mjs +4 -6
  81. package/dist/type/bridge.d.ts +9 -8
  82. package/dist/type/coerce.d.ts +20 -2
  83. package/dist/type/coerce.js +110 -0
  84. package/dist/type/coerce.mjs +109 -2
  85. package/dist/type/compat.js +4 -3
  86. package/dist/type/compat.mjs +2 -1
  87. package/dist/type/constants.d.ts +1 -1
  88. package/dist/type/elysia/boolean-string.js +1 -1
  89. package/dist/type/elysia/boolean-string.mjs +1 -1
  90. package/dist/type/elysia/file-type.js +1 -1
  91. package/dist/type/elysia/file-type.mjs +1 -1
  92. package/dist/type/elysia/integer-string.js +1 -1
  93. package/dist/type/elysia/integer-string.mjs +1 -1
  94. package/dist/type/exports.js +29 -2059
  95. package/dist/type/exports.mjs +7 -295
  96. package/dist/type/index.d.ts +6 -2
  97. package/dist/type/index.js +4 -0
  98. package/dist/type/index.mjs +3 -1
  99. package/dist/type/types.d.ts +1 -1
  100. package/dist/type/utils.js +4 -4
  101. package/dist/type/utils.mjs +4 -4
  102. package/dist/type/validator/custom-error.d.ts +10 -0
  103. package/dist/type/validator/custom-error.js +113 -0
  104. package/dist/type/validator/custom-error.mjs +110 -0
  105. package/dist/type/validator/default-precompute.d.ts +22 -0
  106. package/dist/type/validator/default-precompute.js +476 -0
  107. package/dist/type/validator/default-precompute.mjs +465 -0
  108. package/dist/type/validator/frozen-check.d.ts +11 -0
  109. package/dist/type/validator/frozen-check.js +19 -0
  110. package/dist/type/validator/frozen-check.mjs +18 -0
  111. package/dist/type/{validator.d.ts → validator/index.d.ts} +7 -20
  112. package/dist/type/validator/index.js +572 -0
  113. package/dist/type/validator/index.mjs +567 -0
  114. package/dist/type/validator/string-codec-aot.d.ts +9 -0
  115. package/dist/type/validator/string-codec-aot.js +106 -0
  116. package/dist/type/validator/string-codec-aot.mjs +102 -0
  117. package/dist/type/validator/validator-cache.d.ts +21 -0
  118. package/dist/type/validator/validator-cache.js +163 -0
  119. package/dist/type/validator/validator-cache.mjs +161 -0
  120. package/dist/types.d.ts +22 -14
  121. package/dist/universal/file.d.ts +1 -1
  122. package/dist/universal/file.js +35 -29
  123. package/dist/universal/file.mjs +35 -29
  124. package/dist/utils.d.ts +12 -1
  125. package/dist/utils.js +89 -45
  126. package/dist/utils.mjs +88 -46
  127. package/dist/validator/index.d.ts +1 -1
  128. package/dist/validator/index.js +15 -2
  129. package/dist/validator/index.mjs +15 -2
  130. package/dist/validator/route.d.ts +0 -1
  131. package/dist/ws/route.js +47 -24
  132. package/dist/ws/route.mjs +48 -25
  133. package/package.json +10 -4
  134. package/dist/type/validator.js +0 -1033
  135. package/dist/type/validator.mjs +0 -1029
@@ -32,6 +32,7 @@ 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"));
35
36
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
36
37
  value: mod,
37
38
  enumerable: true
@@ -40,4 +41,5 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
40
41
  //#endregion
41
42
 
42
43
  exports.__exportAll = __exportAll;
44
+ exports.__reExport = __reExport;
43
45
  exports.__toESM = __toESM;
@@ -1,30 +1,7 @@
1
- import { ListenCallback, Serve } from "../../universal/server.js";
2
- import { AnyLocalHook, MaybePromise } from "../../types.js";
3
- import { Context } from "../../context.js";
4
1
  import { AnyElysia } from "../../base.js";
2
+ import { ElysiaAdapterOptions } from "../types.js";
5
3
  //#region src/adapter/bun/index.d.ts
6
4
  declare function collectStaticRoutes(app: AnyElysia): readonly [Record<string, Record<string, Response>>, Promise<void>[]] | undefined;
7
- declare const BunAdapter: {
8
- parse: {
9
- default: (context: Context, contentType: string) => string | unknown[] | ArrayBuffer | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
10
- json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
11
- text: (context: Context) => MaybePromise<string>;
12
- urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
13
- arrayBuffer: (context: Context) => MaybePromise<ArrayBuffer>;
14
- formData: (context: Context) => MaybePromise<Record<string, unknown>>;
15
- };
16
- name: string;
17
- runtime: "node" | "deno" | "bun" | "cloudflare-worker" | "browser" | "vercel" | "netlify" | "lambda" | "fastly" | "edge" | "unknown" | (string & {});
18
- isWebStandard: boolean;
19
- listen?(app: AnyElysia, options: string | number | Partial<Serve>, callback?: ListenCallback): void;
20
- stop?(app: AnyElysia, closeActiveConnections?: boolean): Promise<void>;
21
- response: {
22
- map(response: unknown, set: Context["set"], ...params: unknown[]): unknown;
23
- compact?(response: unknown, ...params: unknown[]): unknown;
24
- static?(handle: unknown, hooks: AnyLocalHook, setHeaders?: Context["set"]["headers"], ...params: unknown[]): (() => unknown) | undefined;
25
- nativeStatic?(handle: unknown, hooks: AnyLocalHook, set?: Context["set"]): (() => MaybePromise<Response>) | undefined;
26
- };
27
- fetch?(app: AnyElysia): (request: Request) => MaybePromise<Response>;
28
- };
5
+ declare const BunAdapter: ElysiaAdapterOptions;
29
6
  //#endregion
30
7
  export { BunAdapter, collectStaticRoutes };
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_adapter_index = require('../index.js');
3
+ const require_constants = require('../../constants.js');
3
4
  const require_utils = require('../../utils.js');
4
5
  const require_adapter_web_standard_index = require('../web-standard/index.js');
5
6
  const require_memory = require('../../memory.js');
@@ -7,19 +8,16 @@ const require_ws_route = require('../../ws/route.js');
7
8
 
8
9
  //#region src/adapter/bun/index.ts
9
10
  function collectStaticRoutes(app) {
10
- if (app["~ext"]?.hoc?.length) return;
11
- const hook = require_utils.flattenChain(app["~hookChain"]);
12
- if (hook && (hook?.request?.length || hook?.mapResponse?.length || hook?.afterResponse?.length || hook?.trace?.length)) return;
13
11
  app.fetch;
14
12
  const source = app["~staticResponse"];
15
13
  if (!source) return;
16
14
  const ready = require_utils.nullObject();
17
15
  const pending = [];
18
- for (const rawPath in source) {
19
- const path = encodeURI(rawPath);
20
- const methods = source[rawPath];
21
- for (const method in methods) {
22
- const value = methods[method];
16
+ for (const method in source) {
17
+ const paths = source[method];
18
+ for (let path in paths) {
19
+ const value = paths[path];
20
+ if (require_constants.needEncodeRegex.test(path)) path = encodeURI(path);
23
21
  if (value instanceof Promise) pending.push(value.then((resolved) => {
24
22
  if (resolved instanceof Response) (ready[path] ??= require_utils.nullObject())[method] = resolved;
25
23
  }, (err) => {
@@ -31,19 +29,27 @@ function collectStaticRoutes(app) {
31
29
  return [ready, pending];
32
30
  }
33
31
  const BunAdapter = require_adapter_index.createAdapter({
34
- ...require_adapter_web_standard_index.WebStandardAdapter,
35
32
  name: "bun",
36
33
  runtime: "bun",
34
+ isWebStandard: true,
35
+ parse: require_adapter_web_standard_index.WebStandardAdapter.parse,
36
+ response: require_adapter_web_standard_index.WebStandardAdapter.response,
37
37
  listen(app, options, callback) {
38
38
  const _config = app["~config"]?.serve;
39
- const _options = typeof options === "object" ? options : { port: +options };
39
+ const optionsIsObject = typeof options === "object";
40
+ const _options = optionsIsObject ? options : {
41
+ port: +options,
42
+ fetch: (request, server) => app.fetch(request, server)
43
+ };
44
+ if (optionsIsObject) _options.fetch = (request, server) => app.fetch(request, server);
40
45
  const serve = _config ? {
41
46
  ..._config,
42
47
  ..._options
43
48
  } : _options;
44
- const hasWs = app["~hasWS"];
45
- serve.fetch = (request, server) => app.fetch(request, server);
46
49
  app.server = Bun.serve(serve);
50
+ const onSetup = app["~ext"]?.setup;
51
+ if (onSetup) for (let i = 0; i < onSetup.length; i++) onSetup[i](app);
52
+ const hasWs = app["~hasWS"];
47
53
  if (!hasWs) callback?.(app.server);
48
54
  queueMicrotask(() => {
49
55
  if (!app.pending) serve.fetch = app.fetch;
@@ -1,24 +1,22 @@
1
1
  import { createAdapter } from "../index.mjs";
2
- import { flattenChain, nullObject } from "../../utils.mjs";
2
+ import { needEncodeRegex } from "../../constants.mjs";
3
+ import { nullObject } from "../../utils.mjs";
3
4
  import { WebStandardAdapter } from "../web-standard/index.mjs";
4
5
  import { flushMemory } from "../../memory.mjs";
5
6
  import { buildGlobalWSHandler } from "../../ws/route.mjs";
6
7
 
7
8
  //#region src/adapter/bun/index.ts
8
9
  function collectStaticRoutes(app) {
9
- if (app["~ext"]?.hoc?.length) return;
10
- const hook = flattenChain(app["~hookChain"]);
11
- if (hook && (hook?.request?.length || hook?.mapResponse?.length || hook?.afterResponse?.length || hook?.trace?.length)) return;
12
10
  app.fetch;
13
11
  const source = app["~staticResponse"];
14
12
  if (!source) return;
15
13
  const ready = nullObject();
16
14
  const pending = [];
17
- for (const rawPath in source) {
18
- const path = encodeURI(rawPath);
19
- const methods = source[rawPath];
20
- for (const method in methods) {
21
- const value = methods[method];
15
+ for (const method in source) {
16
+ const paths = source[method];
17
+ for (let path in paths) {
18
+ const value = paths[path];
19
+ if (needEncodeRegex.test(path)) path = encodeURI(path);
22
20
  if (value instanceof Promise) pending.push(value.then((resolved) => {
23
21
  if (resolved instanceof Response) (ready[path] ??= nullObject())[method] = resolved;
24
22
  }, (err) => {
@@ -30,19 +28,27 @@ function collectStaticRoutes(app) {
30
28
  return [ready, pending];
31
29
  }
32
30
  const BunAdapter = createAdapter({
33
- ...WebStandardAdapter,
34
31
  name: "bun",
35
32
  runtime: "bun",
33
+ isWebStandard: true,
34
+ parse: WebStandardAdapter.parse,
35
+ response: WebStandardAdapter.response,
36
36
  listen(app, options, callback) {
37
37
  const _config = app["~config"]?.serve;
38
- const _options = typeof options === "object" ? options : { port: +options };
38
+ const optionsIsObject = typeof options === "object";
39
+ const _options = optionsIsObject ? options : {
40
+ port: +options,
41
+ fetch: (request, server) => app.fetch(request, server)
42
+ };
43
+ if (optionsIsObject) _options.fetch = (request, server) => app.fetch(request, server);
39
44
  const serve = _config ? {
40
45
  ..._config,
41
46
  ..._options
42
47
  } : _options;
43
- const hasWs = app["~hasWS"];
44
- serve.fetch = (request, server) => app.fetch(request, server);
45
48
  app.server = Bun.serve(serve);
49
+ const onSetup = app["~ext"]?.setup;
50
+ if (onSetup) for (let i = 0; i < onSetup.length; i++) onSetup[i](app);
51
+ const hasWs = app["~hasWS"];
46
52
  if (!hasWs) callback?.(app.server);
47
53
  queueMicrotask(() => {
48
54
  if (!app.pending) serve.fetch = app.fetch;
@@ -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();
@@ -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();
@@ -1,29 +1,6 @@
1
- import { ListenCallback, Serve } from "../universal/server.js";
2
- import { AnyLocalHook, MaybePromise } from "../types.js";
3
- import { Context } from "../context.js";
4
- import { AnyElysia } from "../base.js";
1
+ import { ElysiaAdapterOptions } from "./types.js";
2
+
5
3
  //#region src/adapter/constants.d.ts
6
- declare const defaultAdapter: {
7
- parse: {
8
- default: (context: Context, contentType: string) => string | unknown[] | ArrayBuffer | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
9
- json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
10
- text: (context: Context) => MaybePromise<string>;
11
- urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
12
- arrayBuffer: (context: Context) => MaybePromise<ArrayBuffer>;
13
- formData: (context: Context) => MaybePromise<Record<string, unknown>>;
14
- };
15
- name: string;
16
- runtime: "node" | "deno" | "bun" | "cloudflare-worker" | "browser" | "vercel" | "netlify" | "lambda" | "fastly" | "edge" | "unknown" | (string & {});
17
- isWebStandard: boolean;
18
- listen?(app: AnyElysia, options: string | number | Partial<Serve>, callback?: ListenCallback): void;
19
- stop?(app: AnyElysia, closeActiveConnections?: boolean): Promise<void>;
20
- response: {
21
- map(response: unknown, set: Context["set"], ...params: unknown[]): unknown;
22
- compact?(response: unknown, ...params: unknown[]): unknown;
23
- static?(handle: unknown, hooks: AnyLocalHook, setHeaders?: Context["set"]["headers"], ...params: unknown[]): (() => unknown) | undefined;
24
- nativeStatic?(handle: unknown, hooks: AnyLocalHook, set?: Context["set"]): (() => MaybePromise<Response>) | undefined;
25
- };
26
- fetch?(app: AnyElysia): (request: Request) => MaybePromise<Response>;
27
- };
4
+ declare const defaultAdapter: ElysiaAdapterOptions;
28
5
  //#endregion
29
6
  export { defaultAdapter };
@@ -1,32 +1,7 @@
1
- import { ListenCallback, Serve } from "../universal/server.js";
2
1
  import { ElysiaAdapterOptions } from "./types.js";
3
- import { AnyLocalHook, MaybePromise } from "../types.js";
4
- import { Context } from "../context.js";
5
- import { AnyElysia } from "../base.js";
6
2
 
7
3
  //#region src/adapter/index.d.ts
8
- declare function createAdapter(adapter: ElysiaAdapterOptions): {
9
- parse: {
10
- default: (context: Context, contentType: string) => string | unknown[] | ArrayBuffer | Record<string, unknown> | Promise<Record<string, unknown>> | Promise<ArrayBuffer> | Promise<string> | Promise<unknown[] | Record<string | number | symbol, undefined>> | undefined;
11
- json: (context: Context) => MaybePromise<Record<keyof any, undefined> | unknown[]>;
12
- text: (context: Context) => MaybePromise<string>;
13
- urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
14
- arrayBuffer: (context: Context) => MaybePromise<ArrayBuffer>;
15
- formData: (context: Context) => MaybePromise<Record<string, unknown>>;
16
- };
17
- name: string;
18
- runtime: "node" | "deno" | "bun" | "cloudflare-worker" | "browser" | "vercel" | "netlify" | "lambda" | "fastly" | "edge" | "unknown" | (string & {});
19
- isWebStandard: boolean;
20
- listen?(app: AnyElysia, options: string | number | Partial<Serve>, callback?: ListenCallback): void;
21
- stop?(app: AnyElysia, closeActiveConnections?: boolean): Promise<void>;
22
- response: {
23
- map(response: unknown, set: Context["set"], ...params: unknown[]): unknown;
24
- compact?(response: unknown, ...params: unknown[]): unknown;
25
- static?(handle: unknown, hooks: AnyLocalHook, setHeaders?: Context["set"]["headers"], ...params: unknown[]): (() => unknown) | undefined;
26
- nativeStatic?(handle: unknown, hooks: AnyLocalHook, set?: Context["set"]): (() => MaybePromise<Response>) | undefined;
27
- };
28
- fetch?(app: AnyElysia): (request: Request) => MaybePromise<Response>;
29
- };
4
+ declare function createAdapter<const T extends ElysiaAdapterOptions>(adapter: ElysiaAdapterOptions): T;
30
5
  type ElysiaAdapter = ReturnType<typeof createAdapter>;
31
6
  //#endregion
32
7
  export { ElysiaAdapter, type ElysiaAdapterOptions, createAdapter };
@@ -2,23 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  //#region src/adapter/index.ts
4
4
  function createAdapter(adapter) {
5
- return {
6
- ...adapter,
7
- parse: {
8
- ...adapter.parse,
9
- default: ((json, urlencoded, arrayBuffer, formData, text) => (context, contentType) => {
10
- switch (contentType.charCodeAt(12)) {
11
- case 106: return json(context);
12
- case 120:
13
- if (contentType.charCodeAt(13) === 45) return urlencoded(context);
14
- break;
15
- case 111: return arrayBuffer(context);
16
- case 114: return formData(context);
17
- default: if (contentType.charCodeAt(0) === 116) return text(context);
18
- }
19
- })(adapter.parse.json, adapter.parse.urlencoded, adapter.parse.arrayBuffer, adapter.parse.formData, adapter.parse.text)
20
- }
21
- };
5
+ return adapter;
22
6
  }
23
7
 
24
8
  //#endregion
@@ -1,22 +1,6 @@
1
1
  //#region src/adapter/index.ts
2
2
  function createAdapter(adapter) {
3
- return {
4
- ...adapter,
5
- parse: {
6
- ...adapter.parse,
7
- default: ((json, urlencoded, arrayBuffer, formData, text) => (context, contentType) => {
8
- switch (contentType.charCodeAt(12)) {
9
- case 106: return json(context);
10
- case 120:
11
- if (contentType.charCodeAt(13) === 45) return urlencoded(context);
12
- break;
13
- case 111: return arrayBuffer(context);
14
- case 114: return formData(context);
15
- default: if (contentType.charCodeAt(0) === 116) return text(context);
16
- }
17
- })(adapter.parse.json, adapter.parse.urlencoded, adapter.parse.arrayBuffer, adapter.parse.formData, adapter.parse.text)
18
- }
19
- };
3
+ return adapter;
20
4
  }
21
5
 
22
6
  //#endregion
@@ -45,6 +45,7 @@ interface ElysiaAdapterOptions {
45
45
  urlencoded: (context: Context) => MaybePromise<Record<string, string | string[]>>;
46
46
  arrayBuffer: (context: Context) => MaybePromise<ArrayBuffer>;
47
47
  formData: (context: Context) => MaybePromise<Record<string, unknown>>;
48
+ default: (context: Context, contentType: string) => MaybePromise<any>;
48
49
  };
49
50
  response: {
50
51
  /**
@@ -2,7 +2,6 @@ import { StatusMap } from "../constants.js";
2
2
  import { BaseCookie } from "../cookie/types.js";
3
3
  import { HTTPHeaders } from "../types.js";
4
4
  import { Context } from "../context.js";
5
-
6
5
  //#region src/adapter/utils.d.ts
7
6
  declare function handleFile(response: File | Blob, set?: Context['set'], request?: Request): Response;
8
7
  declare function parseSetCookies(headers: Headers, setCookie: string[]): Headers;
@@ -18,15 +17,15 @@ interface CreateHandlerParameter {
18
17
  mapResponse(response: unknown, set: Context['set'], request?: Request): Response;
19
18
  mapCompactResponse(response: unknown, request?: Request): Response;
20
19
  }
21
- declare const createStreamHandler: ({
20
+ declare function createStreamHandler({
22
21
  mapResponse,
23
22
  mapCompactResponse
24
- }: CreateHandlerParameter) => (generator: Generator | AsyncGenerator | ReadableStream, set?: Context["set"], request?: Request, skipFormat?: boolean) => Promise<Response>;
23
+ }: CreateHandlerParameter): (generator: Generator | AsyncGenerator | ReadableStream, set?: Context["set"], request?: Request, skipFormat?: boolean) => Promise<Response>;
25
24
  declare function streamResponse(response: Response): AsyncGenerator<any, void, any>;
26
25
  declare function handleSet(set: Context['set']): void;
27
26
  declare function mergeHeaders(responseHeaders: Headers, setHeaders: Context['set']['headers']): Headers;
28
27
  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;
28
+ declare function createResponseHandler(handler: CreateHandlerParameter): (response: Response, set?: Context["set"], request?: Request) => any;
30
29
  /**
31
30
  * Split async source into `branches` independent iterators
32
31
  *
@@ -2,7 +2,7 @@ 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
6
 
7
7
  //#region src/adapter/utils.ts
8
8
  const setCookie = "set-cookie";
@@ -101,7 +101,7 @@ function responseToSetHeaders(response, set) {
101
101
  } else if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
102
102
  return set;
103
103
  }
104
- const enqueueBinaryChunk = (controller, chunk) => {
104
+ function enqueueBinaryChunk(controller, chunk) {
105
105
  if (chunk instanceof Blob) return chunk.arrayBuffer().then((buffer) => {
106
106
  controller.enqueue(new Uint8Array(buffer));
107
107
  return true;
@@ -119,91 +119,93 @@ const enqueueBinaryChunk = (controller, chunk) => {
119
119
  return true;
120
120
  }
121
121
  return false;
122
- };
123
- const createStreamHandler = ({ mapResponse, mapCompactResponse }) => async (generator, set, request, skipFormat) => {
124
- let init = generator.next?.();
125
- if (set) handleSet(set);
126
- if (init instanceof Promise) init = await init;
127
- if (init?.value instanceof ReadableStream) generator = init.value;
128
- else if (init && (typeof init?.done === "undefined" || init?.done)) {
129
- if (set) return mapResponse(init.value, set, request);
130
- return mapCompactResponse(init.value, request);
131
- }
132
- const isSSE = !skipFormat && (init?.value?.sse ?? generator?.sse ?? set?.headers["content-type"]?.startsWith("text/event-stream"));
133
- const format = isSSE ? (data) => `data: ${data}\n\n` : (data) => data;
134
- const contentType = isSSE ? "text/event-stream" : init?.value && typeof init?.value === "object" ? ArrayBuffer.isView(init.value) ? "application/octet-stream" : "application/json" : "text/plain";
135
- const headers = set?.headers;
136
- if (headers) {
137
- if (!headers["transfer-encoding"]) headers["transfer-encoding"] = "chunked";
138
- if (!headers["content-type"]) headers["content-type"] = contentType;
139
- if (!headers["cache-control"]) headers["cache-control"] = "no-cache";
140
- } else set = {
141
- status: 200,
142
- headers: {
143
- "content-type": contentType,
144
- "transfer-encoding": "chunked",
145
- "cache-control": "no-cache",
146
- connection: "keep-alive"
122
+ }
123
+ function createStreamHandler({ mapResponse, mapCompactResponse }) {
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);
147
132
  }
148
- };
149
- const iterator = typeof generator.next === "function" ? generator : generator[Symbol.asyncIterator]();
150
- let end = false;
151
- return new Response(new ReadableStream({
152
- start(controller) {
153
- request?.signal?.addEventListener("abort", () => {
154
- end = true;
155
- iterator.return?.();
156
- try {
157
- controller.close();
158
- } catch {}
159
- });
160
- if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
161
- if (init.value.toSSE) controller.enqueue(init.value.toSSE());
162
- else if (enqueueBinaryChunk(controller, init.value)) return;
163
- else if (typeof init.value === "object") try {
164
- controller.enqueue(format(JSON.stringify(init.value)));
165
- } catch {
166
- controller.enqueue(format(init.value.toString()));
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"
167
148
  }
168
- else controller.enqueue(format(init.value.toString()));
169
- },
170
- async pull(controller) {
171
- if (end) {
172
- try {
173
- controller.close();
174
- } catch {}
175
- return;
176
- }
177
- try {
178
- const { value: chunk, done } = await iterator.next();
179
- 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?.();
180
157
  try {
181
158
  controller.close();
182
159
  } catch {}
183
- return;
184
- }
185
- if (chunk === void 0 || chunk === null) return;
186
- if (chunk.toSSE) controller.enqueue(chunk.toSSE());
187
- else if (enqueueBinaryChunk(controller, chunk)) return;
188
- else if (typeof chunk === "object") try {
189
- 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)));
190
166
  } catch {
191
- 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;
192
177
  }
193
- else controller.enqueue(format(chunk.toString()));
194
- } catch (error) {
195
- console.warn(error);
196
178
  try {
197
- controller.close();
198
- } 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?.();
199
205
  }
200
- },
201
- cancel() {
202
- end = true;
203
- iterator.return?.();
204
- }
205
- }), set);
206
- };
206
+ }), set);
207
+ };
208
+ }
207
209
  async function* streamResponse(response) {
208
210
  const body = response.body;
209
211
  if (body) yield* body;
@@ -217,7 +219,7 @@ function handleSet(set) {
217
219
  set.headers = flat;
218
220
  }
219
221
  if (set.cookie && require_utils.isNotEmpty(set.cookie)) {
220
- const cookie = require_cookie_utils.serializeCookie(set.cookie);
222
+ const cookie = require_cookie_serialize.serializeCookie(set.cookie);
221
223
  if (cookie) set.headers[setCookie] = cookie;
222
224
  }
223
225
  if (set.headers[setCookie] && Array.isArray(set.headers[setCookie])) set.headers = parseSetCookies(new Headers(set.headers), set.headers[setCookie]);
@@ -241,7 +243,7 @@ function mergeStatus(responseStatus, setStatus) {
241
243
  if (responseStatus === 200) return setStatus;
242
244
  return responseStatus;
243
245
  }
244
- const createResponseHandler = (handler) => {
246
+ function createResponseHandler(handler) {
245
247
  const handleStream = createStreamHandler(handler);
246
248
  return (response, set, request) => {
247
249
  if (set) {
@@ -265,7 +267,7 @@ const createResponseHandler = (handler) => {
265
267
  if (!newResponse.headers.has("content-length") && newResponse.headers.get("transfer-encoding") === "chunked") return handleStream(streamResponse(newResponse), responseToSetHeaders(newResponse, set), request, true);
266
268
  return newResponse;
267
269
  };
268
- };
270
+ }
269
271
  /**
270
272
  * Split async source into `branches` independent iterators
271
273
  *