elysia 2.0.0-exp.12 → 2.0.0-exp.14

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 (42) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +2 -0
  2. package/dist/adapter/bun/index.d.ts +1 -1
  3. package/dist/adapter/constants.d.ts +1 -1
  4. package/dist/adapter/index.d.ts +1 -1
  5. package/dist/adapter/utils.d.ts +5 -2
  6. package/dist/adapter/utils.js +3 -4
  7. package/dist/adapter/utils.mjs +1 -2
  8. package/dist/adapter/web-standard/index.d.ts +1 -1
  9. package/dist/base.d.ts +1 -4
  10. package/dist/base.js +11 -6
  11. package/dist/base.mjs +11 -6
  12. package/dist/compile/handler/index.js +1 -1
  13. package/dist/compile/handler/index.mjs +1 -1
  14. package/dist/compile/handler/jit.js +2 -2
  15. package/dist/compile/handler/jit.mjs +2 -2
  16. package/dist/compile/handler/params.js +1 -1
  17. package/dist/compile/handler/params.mjs +1 -1
  18. package/dist/compile/handler/reconstruct.js +1 -1
  19. package/dist/compile/handler/reconstruct.mjs +1 -1
  20. package/dist/cookie/index.d.ts +2 -2
  21. package/dist/error.d.ts +1 -1
  22. package/dist/handler/fetch.js +19 -24
  23. package/dist/handler/fetch.mjs +19 -24
  24. package/dist/index.d.ts +3 -5
  25. package/dist/index.js +0 -4
  26. package/dist/index.mjs +1 -3
  27. package/dist/type/elysia/file-type.d.ts +1 -1
  28. package/dist/type/exports.js +29 -2059
  29. package/dist/type/exports.mjs +7 -295
  30. package/dist/type/types.d.ts +1 -1
  31. package/dist/type/validator/index.d.ts +2 -2
  32. package/dist/types.d.ts +4 -4
  33. package/dist/universal/file.d.ts +8 -8
  34. package/dist/universal/file.js +8 -8
  35. package/dist/universal/file.mjs +8 -8
  36. package/dist/utils.d.ts +1 -1
  37. package/dist/validator/index.d.ts +1 -1
  38. package/dist/validator/index.js +2 -2
  39. package/dist/validator/index.mjs +2 -2
  40. package/dist/ws/route.js +5 -1
  41. package/dist/ws/route.mjs +6 -2
  42. package/package.json +8 -3
@@ -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;
@@ -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 | unknown[] | ArrayBuffer | Record<string, unknown> | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
9
+ default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | 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[]>>;
@@ -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 | unknown[] | ArrayBuffer | Record<string, unknown> | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
8
+ default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | 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 | unknown[] | ArrayBuffer | Record<string, unknown> | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
10
+ default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | 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,13 +12,16 @@ declare function responseToSetHeaders(response: Response, set?: Context['set']):
12
12
  cookie?: Record<string, BaseCookie>;
13
13
  } | {
14
14
  headers: any;
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";
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";
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 function createStreamHandler(_: CreateHandlerParameter): (generator: Generator | AsyncGenerator | ReadableStream, set?: Context["set"], request?: Request, skipFormat?: boolean) => Promise<Response>;
21
+ declare function createStreamHandler({
22
+ mapResponse,
23
+ mapCompactResponse
24
+ }: CreateHandlerParameter): (generator: Generator | AsyncGenerator | ReadableStream, set?: Context["set"], request?: Request, skipFormat?: boolean) => Promise<Response>;
22
25
  declare function streamResponse(response: Response): AsyncGenerator<any, void, any>;
23
26
  declare function handleSet(set: Context['set']): void;
24
27
  declare function mergeHeaders(responseHeaders: Headers, setHeaders: Context['set']['headers']): Headers;
@@ -3,7 +3,6 @@ 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
5
  const require_cookie_serialize = require('../cookie/serialize.js');
6
- const require_adapter_web_standard_handler = require('./web-standard/handler.js');
7
6
 
8
7
  //#region src/adapter/utils.ts
9
8
  const setCookie = "set-cookie";
@@ -121,15 +120,15 @@ function enqueueBinaryChunk(controller, chunk) {
121
120
  }
122
121
  return false;
123
122
  }
124
- function createStreamHandler(_) {
123
+ function createStreamHandler({ mapResponse, mapCompactResponse }) {
125
124
  return async (generator, set, request, skipFormat) => {
126
125
  let init = generator.next?.();
127
126
  if (set) handleSet(set);
128
127
  if (init instanceof Promise) init = await init;
129
128
  if (init?.value instanceof ReadableStream) generator = init.value;
130
129
  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);
130
+ if (set) return mapResponse(init.value, set, request);
131
+ return mapCompactResponse(init.value, request);
133
132
  }
134
133
  const isSSE = !skipFormat && (init?.value?.sse ?? generator?.sse ?? set?.headers["content-type"]?.startsWith("text/event-stream"));
135
134
  const format = isSSE ? (data) => `data: ${data}\n\n` : (data) => data;
@@ -2,7 +2,6 @@ import { hasHeaderShorthand, isBun } from "../universal/constants.mjs";
2
2
  import { StatusMap } from "../constants.mjs";
3
3
  import { isNotEmpty, nullObject } from "../utils.mjs";
4
4
  import { serializeCookie } from "../cookie/serialize.mjs";
5
- import { mapCompactResponse, mapResponse } from "./web-standard/handler.mjs";
6
5
 
7
6
  //#region src/adapter/utils.ts
8
7
  const setCookie = "set-cookie";
@@ -120,7 +119,7 @@ function enqueueBinaryChunk(controller, chunk) {
120
119
  }
121
120
  return false;
122
121
  }
123
- function createStreamHandler(_) {
122
+ function createStreamHandler({ mapResponse, mapCompactResponse }) {
124
123
  return async (generator, set, request, skipFormat) => {
125
124
  let init = generator.next?.();
126
125
  if (set) handleSet(set);
@@ -5,7 +5,7 @@ import { AnyElysia } from "../../base.js";
5
5
  //#region src/adapter/web-standard/index.d.ts
6
6
  declare const WebStandardAdapter: {
7
7
  parse: {
8
- default: (context: Context, contentType: string) => string | unknown[] | ArrayBuffer | Record<string, unknown> | Promise<unknown[] | Record<string | number | symbol, undefined>> | Promise<ArrayBuffer> | Promise<Record<string, unknown>> | Promise<string> | undefined;
8
+ default: (context: Context, contentType: string) => string | ArrayBuffer | unknown[] | Record<string, unknown> | 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[]>>;
package/dist/base.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ElysiaStatus } from "./error.js";
2
2
  import { TraceHandler } from "./trace.js";
3
+ import { AnySchema } from "./type/types.js";
3
4
  import { ListenCallback, Serve, Server } from "./universal/server.js";
4
5
  import { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, BodyHandler, CompiledHandler, CreateEden, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, DocumentDecoration, ElysiaConfig, ElysiaHandlerToResponseSchemaAmbiguous, EphemeralType, ErrorDefinitionEntry, ErrorHandler, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, GracefulHandler, GuardLocalHook, HTTPMethod, InlineHandler, InlineHandlerNonMacro, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObjectSchema, JoinPath, LocalHook, Macro, MacroToContext, MacroToProperty, MapResponse, MaybeArray, MaybePromise, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, NonResolvableMacroKey, ObjectMacroDefs, OptionalHandler, PreHandler, Prettify, PublicRoute, ResolveRouteErrors, RouteBase, SingletonBase, TransformHandler, UnionResponseStatus, UnwrapRoute, WrapFn } from "./types.js";
5
- import { AnySchema } from "./type/types.js";
6
6
  import { ChainNode } from "./utils.js";
7
7
  import { Context, ErrorContext, LifecycleContext } from "./context.js";
8
8
  import { WSHandlerResponse, WSLocalHook, WSMessageHandler } from "./ws/types.js";
@@ -151,9 +151,6 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
151
151
  }, Definitions, Metadata, Routes, Ephemeral, Volatile>;
152
152
  headers(headers: Record<string, string>): this;
153
153
  request(fn: MaybeArray<PreHandler<{}, Singleton>>): this;
154
- request(scope: 'local', fn: MaybeArray<PreHandler<{}, Singleton>>): this;
155
- request(scope: 'plugin', fn: MaybeArray<PreHandler<{}, Singleton>>): this;
156
- request(scope: 'global', fn: MaybeArray<PreHandler<{}, Singleton>>): this;
157
154
  parse(fn: MaybeArray<BodyHandler<MergeSchema<{}, {}, BasePath>, Singleton & {
158
155
  derive: Ephemeral['derive'] & Volatile['derive'];
159
156
  }>>): this;
package/dist/base.js CHANGED
@@ -5,10 +5,11 @@ const require_constants = require('./constants.js');
5
5
  const require_utils = require('./utils.js');
6
6
  const require_type_bridge = require('./type/bridge.js');
7
7
  const require_universal_env = require('./universal/env.js');
8
+ const require_compile_aot = require('./compile/aot.js');
9
+ const require_compile_handler_index = require('./compile/handler/index.js');
8
10
  const require_ws_route = require('./ws/route.js');
9
11
  const require_adapter_bun_index = require('./adapter/bun/index.js');
10
12
  const require_handler_fetch = require('./handler/fetch.js');
11
- const require_compile_handler_index = require('./compile/handler/index.js');
12
13
  let memoirist = require("memoirist");
13
14
  memoirist = require_runtime.__toESM(memoirist);
14
15
 
@@ -157,8 +158,8 @@ var Elysia = class Elysia {
157
158
  #onBranch(type, scopeOrFn, fn) {
158
159
  return fn ? this.#on(type, fn, scopeOrFn) : this.#on(type, scopeOrFn);
159
160
  }
160
- request(scopeOrFn, fn) {
161
- return this.#onBranch("request", scopeOrFn, fn);
161
+ request(fn) {
162
+ return this.#on("request", fn, "global");
162
163
  }
163
164
  parse(scopeOrFnOrName, fn) {
164
165
  if (fn === void 0 && typeof scopeOrFnOrName === "string") {
@@ -329,9 +330,8 @@ var Elysia = class Elysia {
329
330
  const finalize = () => {
330
331
  const childFlat = require_utils.flattenChain(child["~hookChain"]);
331
332
  const lifted = require_utils.nullObject();
332
- if (childFlat?.request) lifted.request = childFlat.request;
333
333
  if (childFlat?.parse) lifted.parse = childFlat.parse;
334
- if (lifted.request || lifted.parse) this.#pushHook(lifted);
334
+ if (lifted.parse) this.#pushHook(lifted);
335
335
  return child;
336
336
  };
337
337
  if (child.pending) return this.#useAsync(child.modules.then(finalize));
@@ -465,7 +465,8 @@ var Elysia = class Elysia {
465
465
  for (const plugin of app) this.#use(plugin);
466
466
  return this;
467
467
  }
468
- if (app !== this && app.pending) return this.#useAsync(app.modules.then(() => app));
468
+ if (app === this) return this;
469
+ if (app.pending) return this.#useAsync(app.modules.then(() => app));
469
470
  this.#use(app);
470
471
  return this;
471
472
  }
@@ -823,6 +824,10 @@ var Elysia = class Elysia {
823
824
  this["~config"] ??= require_utils.nullObject();
824
825
  this["~config"].precompile = true;
825
826
  this.#routerBuilt = false;
827
+ if (require_compile_aot.Capture.isCapturing()) {
828
+ this.#compiled = void 0;
829
+ this.#fetchFn = void 0;
830
+ }
826
831
  this.fetch;
827
832
  return this;
828
833
  }
package/dist/base.mjs CHANGED
@@ -3,10 +3,11 @@ import { MethodMap, isDynamicRegex, needEncodeRegex } from "./constants.mjs";
3
3
  import { clonePlainDecorators, coalesceStandaloneSchemas, createErrorEventHandler, eventProperties, flattenChain, fnOrigin, fnv1a, getLoosePath, hookToGuard, isEmpty, isNotEmpty, isRecordNumber, joinPath, mapMethodBack, mergeDeep, mergeResponse, nullObject, pushField, replaceUrlPath, schemaProperties } from "./utils.mjs";
4
4
  import { Ref } from "./type/bridge.mjs";
5
5
  import { env } from "./universal/env.mjs";
6
+ import { Capture } from "./compile/aot.mjs";
7
+ import { buildNativeStaticResponse, compileHandler, composeRouteHook } from "./compile/handler/index.mjs";
6
8
  import { buildWSRoute } from "./ws/route.mjs";
7
9
  import { BunAdapter } from "./adapter/bun/index.mjs";
8
10
  import { applyHoc, createFetchHandler } from "./handler/fetch.mjs";
9
- import { buildNativeStaticResponse, compileHandler, composeRouteHook } from "./compile/handler/index.mjs";
10
11
  import Memoirist from "memoirist";
11
12
 
12
13
  //#region src/base.ts
@@ -154,8 +155,8 @@ var Elysia = class Elysia {
154
155
  #onBranch(type, scopeOrFn, fn) {
155
156
  return fn ? this.#on(type, fn, scopeOrFn) : this.#on(type, scopeOrFn);
156
157
  }
157
- request(scopeOrFn, fn) {
158
- return this.#onBranch("request", scopeOrFn, fn);
158
+ request(fn) {
159
+ return this.#on("request", fn, "global");
159
160
  }
160
161
  parse(scopeOrFnOrName, fn) {
161
162
  if (fn === void 0 && typeof scopeOrFnOrName === "string") {
@@ -326,9 +327,8 @@ var Elysia = class Elysia {
326
327
  const finalize = () => {
327
328
  const childFlat = flattenChain(child["~hookChain"]);
328
329
  const lifted = nullObject();
329
- if (childFlat?.request) lifted.request = childFlat.request;
330
330
  if (childFlat?.parse) lifted.parse = childFlat.parse;
331
- if (lifted.request || lifted.parse) this.#pushHook(lifted);
331
+ if (lifted.parse) this.#pushHook(lifted);
332
332
  return child;
333
333
  };
334
334
  if (child.pending) return this.#useAsync(child.modules.then(finalize));
@@ -462,7 +462,8 @@ var Elysia = class Elysia {
462
462
  for (const plugin of app) this.#use(plugin);
463
463
  return this;
464
464
  }
465
- if (app !== this && app.pending) return this.#useAsync(app.modules.then(() => app));
465
+ if (app === this) return this;
466
+ if (app.pending) return this.#useAsync(app.modules.then(() => app));
466
467
  this.#use(app);
467
468
  return this;
468
469
  }
@@ -820,6 +821,10 @@ var Elysia = class Elysia {
820
821
  this["~config"] ??= nullObject();
821
822
  this["~config"].precompile = true;
822
823
  this.#routerBuilt = false;
824
+ if (Capture.isCapturing()) {
825
+ this.#compiled = void 0;
826
+ this.#fetchFn = void 0;
827
+ }
823
828
  this.fetch;
824
829
  return this;
825
830
  }
@@ -1,10 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_utils = require('../../utils.js');
3
3
  const require_compile_aot = require('../aot.js');
4
- const require_adapter_constants = require('../../adapter/constants.js');
5
4
  const require_compile_handler_params = require('./params.js');
6
5
  const require_compile_handler_jit = require('./jit.js');
7
6
  const require_compile_handler_reconstruct = require('./reconstruct.js');
7
+ const require_adapter_constants = require('../../adapter/constants.js');
8
8
 
9
9
  //#region src/compile/handler/index.ts
10
10
  function applyHook(localHook, appHook, rootHook, appHookFresh = false) {
@@ -1,9 +1,9 @@
1
1
  import { cloneHook, eventProperties, flattenChain, flattenChainMemo, fnOrigin, isLocalScope, mapMethodBack, mergeHook, nullObject } from "../../utils.mjs";
2
2
  import { Compiled } from "../aot.mjs";
3
- import { defaultAdapter } from "../../adapter/constants.mjs";
4
3
  import { resolveHandlerParams } from "./params.mjs";
5
4
  import { compileHandlerJit, setCaptureHeaderShorthand } from "./jit.mjs";
6
5
  import { Reconstrct } from "./reconstruct.mjs";
6
+ import { defaultAdapter } from "../../adapter/constants.mjs";
7
7
 
8
8
  //#region src/compile/handler/index.ts
9
9
  function applyHook(localHook, appHook, rootHook, appHookFresh = false) {
@@ -9,10 +9,10 @@ const require_sucrose = require('../../sucrose.js');
9
9
  const require_compile_aot = require('../aot.js');
10
10
  const require_compile_utils = require('../utils.js');
11
11
  const require_compile_handler_utils = require('./utils.js');
12
- const require_handler_utils = require('../../handler/utils.js');
13
- const require_trace = require('../../trace.js');
14
12
  const require_cookie_config = require('../../cookie/config.js');
15
13
  const require_cookie_utils = require('../../cookie/utils.js');
14
+ const require_handler_utils = require('../../handler/utils.js');
15
+ const require_trace = require('../../trace.js');
16
16
  const require_compile_jit_probe = require('../jit-probe.js');
17
17
 
18
18
  //#region src/compile/handler/jit.ts
@@ -8,10 +8,10 @@ import { sucrose } from "../../sucrose.mjs";
8
8
  import { Capture } from "../aot.mjs";
9
9
  import { isAsyncFunction, isAsyncLifecycle, mayReturnPromise } from "../utils.mjs";
10
10
  import { cloneResponse, getQueryParseArgs, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform } from "./utils.mjs";
11
- import { forwardError } from "../../handler/utils.mjs";
12
- import { createTracer } from "../../trace.mjs";
13
11
  import { compileCookieConfig } from "../../cookie/config.mjs";
14
12
  import { buildCookieJar, parseCookieRaw, parseCookieRawSync, signCookieValues } from "../../cookie/utils.mjs";
13
+ import { forwardError } from "../../handler/utils.mjs";
14
+ import { createTracer } from "../../trace.mjs";
15
15
  import { JITProbe } from "../jit-probe.mjs";
16
16
 
17
17
  //#region src/compile/handler/jit.ts
@@ -4,8 +4,8 @@ const require_adapter_utils = require('../../adapter/utils.js');
4
4
  const require_error = require('../../error.js');
5
5
  const require_parse_query = require('../../parse-query.js');
6
6
  const require_compile_handler_utils = require('./utils.js');
7
- const require_handler_utils = require('../../handler/utils.js');
8
7
  const require_cookie_utils = require('../../cookie/utils.js');
8
+ const require_handler_utils = require('../../handler/utils.js');
9
9
 
10
10
  //#region src/compile/handler/params.ts
11
11
  const HANDLER_PARAMS = {
@@ -3,8 +3,8 @@ import { tee } from "../../adapter/utils.mjs";
3
3
  import { ElysiaStatus, ParseError, ValidationError } from "../../error.mjs";
4
4
  import { parseQueryFromURL } from "../../parse-query.mjs";
5
5
  import { cloneResponse, hasRequestBody } from "./utils.mjs";
6
- import { forwardError } from "../../handler/utils.mjs";
7
6
  import { buildCookieJar, parseCookieRaw, parseCookieRawSync, signCookieValues } from "../../cookie/utils.mjs";
7
+ import { forwardError } from "../../handler/utils.mjs";
8
8
 
9
9
  //#region src/compile/handler/params.ts
10
10
  const HANDLER_PARAMS = {
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_validator_route = require('../../validator/route.js');
3
- const require_trace = require('../../trace.js');
4
3
  const require_cookie_config = require('../../cookie/config.js');
4
+ const require_trace = require('../../trace.js');
5
5
 
6
6
  //#region src/compile/handler/reconstruct.ts
7
7
  var Reconstrct = class {
@@ -1,6 +1,6 @@
1
1
  import { RouteValidator } from "../../validator/route.mjs";
2
- import { createTracer } from "../../trace.mjs";
3
2
  import { compileCookieConfig } from "../../cookie/config.mjs";
3
+ import { createTracer } from "../../trace.mjs";
4
4
 
5
5
  //#region src/compile/handler/reconstruct.ts
6
6
  var Reconstrct = class {
@@ -1,5 +1,5 @@
1
- import { CookieOptions } from "./types.js";
1
+ import { BaseCookie, CookieOptions } from "./types.js";
2
2
  import { Cookie } from "./cookie.js";
3
3
  import { serializeCookie } from "./serialize.js";
4
4
  import { createCookieJar, parseCookie, signCookie, unsignCookie } from "./utils.js";
5
- export { Cookie, type CookieOptions, createCookieJar, parseCookie, serializeCookie, signCookie, unsignCookie };
5
+ export { type BaseCookie, Cookie, type CookieOptions, createCookieJar, parseCookie, serializeCookie, signCookie, unsignCookie };
package/dist/error.d.ts CHANGED
@@ -85,7 +85,7 @@ declare class ElysiaStatus<const in out Code extends number | keyof StatusMap, T
85
85
  constructor(code: Code, res: T);
86
86
  get status(): number;
87
87
  }
88
- declare const status: <const Code extends number | keyof StatusMap, const T = (Code extends keyof StatusMapBack ? StatusMapBack[Code] : Code)>(code: Code, response?: T) => ElysiaStatus<Code, T, Code extends "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" ? {
88
+ declare const status: <const Code extends number | keyof StatusMap, const T = (Code extends keyof StatusMapBack ? StatusMapBack[Code] : Code)>(code: Code, response?: T) => ElysiaStatus<Code, T, Code extends "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" ? {
89
89
  readonly Continue: 100;
90
90
  readonly 'Switching Protocols': 101;
91
91
  readonly Processing: 102;
@@ -4,10 +4,10 @@ const require_utils = require('../utils.js');
4
4
  const require_adapter_utils = require('../adapter/utils.js');
5
5
  const require_error = require('../error.js');
6
6
  const require_context = require('../context.js');
7
- const require_adapter_constants = require('../adapter/constants.js');
8
7
  const require_handler_utils = require('./utils.js');
9
- const require_handler_error = require('./error.js');
10
8
  const require_trace = require('../trace.js');
9
+ const require_adapter_constants = require('../adapter/constants.js');
10
+ const require_handler_error = require('./error.js');
11
11
  let deuri = require("deuri");
12
12
 
13
13
  //#region src/handler/fetch.ts
@@ -30,11 +30,17 @@ const decodeParams = (params) => {
30
30
  }
31
31
  return params;
32
32
  };
33
- const catchError = (context, handleError, afterResponse) => (error) => {
33
+ function finalizeError(context, handleError, afterResponse, error) {
34
34
  const resp = handleError(context, error);
35
- afterResponse?.(context);
35
+ if (!afterResponse) return resp;
36
+ if (resp instanceof Promise) return resp.then((r) => {
37
+ afterResponse(context);
38
+ return r;
39
+ });
40
+ afterResponse(context);
36
41
  return resp;
37
- };
42
+ }
43
+ const catchError = (context, handleError, afterResponse) => (error) => finalizeError(context, handleError, afterResponse, error);
38
44
  function findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS) {
39
45
  const path = context.path;
40
46
  if (hasWS) {
@@ -52,7 +58,8 @@ function findRoute(context, request, map, router, hasError, handleError, afterRe
52
58
  return r instanceof Promise ? r.catch(catchError(context, handleError, afterResponse)) : r;
53
59
  }
54
60
  }
55
- } else {
61
+ }
62
+ {
56
63
  const methodMap = map[request.method];
57
64
  let handler = methodMap?.[path];
58
65
  if (!handler) if (!strictPath && path.length > 1 && path.charCodeAt(path.length - 1) === 47) {
@@ -175,9 +182,7 @@ function createFetchHandler(app) {
175
182
  return await findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS);
176
183
  } catch (error) {
177
184
  for (let i = 0; i < traceLength; i++) requestReports[i].resolve(error);
178
- const r = handleError(context, error);
179
- afterResponse?.(context);
180
- return r;
185
+ return finalizeError(context, handleError, afterResponse, error);
181
186
  }
182
187
  };
183
188
  }
@@ -199,9 +204,7 @@ function createFetchHandler(app) {
199
204
  }
200
205
  return findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS);
201
206
  } catch (error) {
202
- const r = handleError(context, error);
203
- afterResponse?.(context);
204
- return r;
207
+ return finalizeError(context, handleError, afterResponse, error);
205
208
  }
206
209
  };
207
210
  return (request) => {
@@ -219,7 +222,7 @@ function createFetchHandler(app) {
219
222
  }
220
223
  return findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS);
221
224
  } catch (error) {
222
- return handleError(context, error);
225
+ return finalizeError(context, handleError, afterResponse, error);
223
226
  }
224
227
  };
225
228
  }
@@ -243,9 +246,7 @@ function createFetchHandler(app) {
243
246
  return r instanceof Promise ? r.catch(catchError(context, handleError, afterResponse)) : r;
244
247
  }
245
248
  } catch (error) {
246
- const r = handleError(context, error);
247
- afterResponse?.(context);
248
- return r;
249
+ return finalizeError(context, handleError, afterResponse, error);
249
250
  }
250
251
  }
251
252
  }
@@ -271,15 +272,9 @@ function createFetchHandler(app) {
271
272
  return r instanceof Promise ? r.catch(catchError(context, handleError, afterResponse)) : r;
272
273
  }
273
274
  } catch (error) {
274
- const r = handleError(context, error);
275
- afterResponse?.(context);
276
- return r;
277
- }
278
- if (hasError) {
279
- const r = handleError(context, new require_error.NotFound());
280
- afterResponse?.(context);
281
- return r;
275
+ return finalizeError(context, handleError, afterResponse, error);
282
276
  }
277
+ if (hasError) return finalizeError(context, handleError, afterResponse, new require_error.NotFound());
283
278
  afterResponse?.(context, 404);
284
279
  return notFound(context);
285
280
  };
@@ -2,10 +2,10 @@ import { flattenChain, isNotEmpty, nullObject, requestId } from "../utils.mjs";
2
2
  import { handleSet } from "../adapter/utils.mjs";
3
3
  import { NotFound } from "../error.mjs";
4
4
  import { createContext } from "../context.mjs";
5
- import { defaultAdapter } from "../adapter/constants.mjs";
6
5
  import { cachedResponse, getAsyncIndexes } from "./utils.mjs";
7
- import { createErrorHandler } from "./error.mjs";
8
6
  import { createTracer } from "../trace.mjs";
7
+ import { defaultAdapter } from "../adapter/constants.mjs";
8
+ import { createErrorHandler } from "./error.mjs";
9
9
  import { decodeComponent } from "deuri";
10
10
 
11
11
  //#region src/handler/fetch.ts
@@ -28,11 +28,17 @@ const decodeParams = (params) => {
28
28
  }
29
29
  return params;
30
30
  };
31
- const catchError = (context, handleError, afterResponse) => (error) => {
31
+ function finalizeError(context, handleError, afterResponse, error) {
32
32
  const resp = handleError(context, error);
33
- afterResponse?.(context);
33
+ if (!afterResponse) return resp;
34
+ if (resp instanceof Promise) return resp.then((r) => {
35
+ afterResponse(context);
36
+ return r;
37
+ });
38
+ afterResponse(context);
34
39
  return resp;
35
- };
40
+ }
41
+ const catchError = (context, handleError, afterResponse) => (error) => finalizeError(context, handleError, afterResponse, error);
36
42
  function findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS) {
37
43
  const path = context.path;
38
44
  if (hasWS) {
@@ -50,7 +56,8 @@ function findRoute(context, request, map, router, hasError, handleError, afterRe
50
56
  return r instanceof Promise ? r.catch(catchError(context, handleError, afterResponse)) : r;
51
57
  }
52
58
  }
53
- } else {
59
+ }
60
+ {
54
61
  const methodMap = map[request.method];
55
62
  let handler = methodMap?.[path];
56
63
  if (!handler) if (!strictPath && path.length > 1 && path.charCodeAt(path.length - 1) === 47) {
@@ -173,9 +180,7 @@ function createFetchHandler(app) {
173
180
  return await findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS);
174
181
  } catch (error) {
175
182
  for (let i = 0; i < traceLength; i++) requestReports[i].resolve(error);
176
- const r = handleError(context, error);
177
- afterResponse?.(context);
178
- return r;
183
+ return finalizeError(context, handleError, afterResponse, error);
179
184
  }
180
185
  };
181
186
  }
@@ -197,9 +202,7 @@ function createFetchHandler(app) {
197
202
  }
198
203
  return findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS);
199
204
  } catch (error) {
200
- const r = handleError(context, error);
201
- afterResponse?.(context);
202
- return r;
205
+ return finalizeError(context, handleError, afterResponse, error);
203
206
  }
204
207
  };
205
208
  return (request) => {
@@ -217,7 +220,7 @@ function createFetchHandler(app) {
217
220
  }
218
221
  return findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS);
219
222
  } catch (error) {
220
- return handleError(context, error);
223
+ return finalizeError(context, handleError, afterResponse, error);
221
224
  }
222
225
  };
223
226
  }
@@ -241,9 +244,7 @@ function createFetchHandler(app) {
241
244
  return r instanceof Promise ? r.catch(catchError(context, handleError, afterResponse)) : r;
242
245
  }
243
246
  } catch (error) {
244
- const r = handleError(context, error);
245
- afterResponse?.(context);
246
- return r;
247
+ return finalizeError(context, handleError, afterResponse, error);
247
248
  }
248
249
  }
249
250
  }
@@ -269,15 +270,9 @@ function createFetchHandler(app) {
269
270
  return r instanceof Promise ? r.catch(catchError(context, handleError, afterResponse)) : r;
270
271
  }
271
272
  } catch (error) {
272
- const r = handleError(context, error);
273
- afterResponse?.(context);
274
- return r;
275
- }
276
- if (hasError) {
277
- const r = handleError(context, new NotFound());
278
- afterResponse?.(context);
279
- return r;
273
+ return finalizeError(context, handleError, afterResponse, error);
280
274
  }
275
+ if (hasError) return finalizeError(context, handleError, afterResponse, new NotFound());
281
276
  afterResponse?.(context, 404);
282
277
  return notFound(context);
283
278
  };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,7 @@
1
1
  import { StatusMap, StatusMapBack } from "./constants.js";
2
2
  import { ElysiaError, ElysiaStatus, InternalServerError, InvalidCookieSignature, NotFound, ParseError, ValidationError, status, validationDetail } from "./error.js";
3
- import { Cookie } from "./cookie/cookie.js";
4
- import { serializeCookie } from "./cookie/serialize.js";
5
3
  import { ElysiaFile, file } from "./universal/file.js";
6
4
  import { TraceEvent, TraceHandler, TraceListener, TraceProcess, TraceStream } from "./trace.js";
7
- import { env } from "./universal/env.js";
8
- import { SSEPayload } from "./types.js";
9
5
  import { AnySchema, BaseSchema, StandardJSONSchemaV1Like, StandardSchemaV1Like } from "./type/types.js";
10
6
  import { FileTypeDetector, fileType, setFileTypeDetector } from "./type/elysia/file-type.js";
11
7
  import { setupTypebox } from "./type/compat.js";
@@ -13,7 +9,9 @@ import { Capture, Compiled } from "./compile/aot.js";
13
9
  import { MultiValidator, StandardValidator, Validator } from "./validator/index.js";
14
10
  import { TypeBoxValidator } from "./type/validator/index.js";
15
11
  import { TypeSystem, t } from "./type/index.js";
12
+ import { env } from "./universal/env.js";
13
+ import { SSEPayload } from "./types.js";
16
14
  import { form, redirect, sse } from "./utils.js";
17
15
  import { Context, ErrorContext, createBaseContext, createContext } from "./context.js";
18
16
  import { Elysia } from "./base.js";
19
- export { type AnySchema, type BaseSchema, Compiled, type Context, Cookie, Elysia, Elysia as default, ElysiaError, ElysiaFile, ElysiaStatus, type ErrorContext, type FileTypeDetector, InternalServerError, InvalidCookieSignature, Capture as Manifest, MultiValidator, NotFound, ParseError, type SSEPayload, type StandardJSONSchemaV1Like, type StandardSchemaV1Like, StandardValidator, StatusMap, StatusMapBack, type TraceEvent, type TraceHandler, type TraceListener, type TraceProcess, type TraceStream, TypeBoxValidator, TypeSystem, ValidationError, Validator, createBaseContext, createContext, env, file, fileType, form, redirect, serializeCookie, setFileTypeDetector, setupTypebox, sse, status, t, validationDetail };
17
+ export { type AnySchema, type BaseSchema, Compiled, type Context, Elysia, Elysia as default, ElysiaError, ElysiaFile, ElysiaStatus, type ErrorContext, type FileTypeDetector, InternalServerError, InvalidCookieSignature, Capture as Manifest, MultiValidator, NotFound, ParseError, type SSEPayload, type StandardJSONSchemaV1Like, type StandardSchemaV1Like, StandardValidator, StatusMap, StatusMapBack, type TraceEvent, type TraceHandler, type TraceListener, type TraceProcess, type TraceStream, TypeBoxValidator, TypeSystem, ValidationError, Validator, createBaseContext, createContext, env, file, fileType, form, redirect, setFileTypeDetector, setupTypebox, sse, status, t, validationDetail };