elysia 2.0.0-exp.27 → 2.0.0-exp.28

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.
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, GlobalHookReturn, GracefulHandler, GuardHookSingleton, GuardLocalHook, HTTPMethod, HookContextSchema, HookContextSingleton, InlineHandler, InlineHandlerNonMacro, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObjectSchema, JoinPath, LocalHook, LocalHookReturn, Macro, MacroSchemaChannel, MacroToContext, MacroToProperty, MapResponse, MaybeArray, MaybePromise, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, NonResolvableMacroKey, ObjectMacroDefs, OptionalHandler, PluginHookReturn, 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";
package/dist/base.js CHANGED
@@ -766,27 +766,29 @@ var Elysia = class Elysia {
766
766
  this.#routerBuilt = false;
767
767
  this.#buildRouter();
768
768
  }
769
- #add(method, path, fn, hook) {
769
+ #add(method, path, hookOrFn, fn, hasHook = fn !== void 0) {
770
770
  if (this["~Prefix"]) path = require_utils.joinPath(this["~Prefix"], path);
771
771
  else if (path && path.charCodeAt(0) !== 47) path = "/" + path;
772
+ const handler = hasHook ? fn : hookOrFn;
773
+ const hook = hasHook ? hookOrFn : void 0;
772
774
  const appHook = this["~hookChain"];
773
775
  (this.#history ??= []).push(appHook ? [
774
776
  method,
775
777
  path,
776
- fn,
778
+ handler,
777
779
  this,
778
780
  hook,
779
781
  appHook
780
782
  ] : hook ? [
781
783
  method,
782
784
  path,
783
- fn,
785
+ handler,
784
786
  this,
785
787
  hook
786
788
  ] : [
787
789
  method,
788
790
  path,
789
- fn,
791
+ handler,
790
792
  this
791
793
  ]);
792
794
  this.#cachedRoutes = void 0;
@@ -838,32 +840,31 @@ var Elysia = class Elysia {
838
840
  return require_type_bridge.Ref(key);
839
841
  }
840
842
  get(path, hookOrFn, fn) {
841
- return fn === void 0 ? this.#add(require_constants.MethodMap.GET, path, hookOrFn) : this.#add(require_constants.MethodMap.GET, path, fn, hookOrFn);
843
+ return this.#add(require_constants.MethodMap.GET, path, hookOrFn, fn);
842
844
  }
843
845
  post(path, hookOrFn, fn) {
844
- return fn === void 0 ? this.#add(require_constants.MethodMap.POST, path, hookOrFn) : this.#add(require_constants.MethodMap.POST, path, fn, hookOrFn);
846
+ return this.#add(require_constants.MethodMap.POST, path, hookOrFn, fn);
845
847
  }
846
848
  put(path, hookOrFn, fn) {
847
- return fn === void 0 ? this.#add(require_constants.MethodMap.PUT, path, hookOrFn) : this.#add(require_constants.MethodMap.PUT, path, fn, hookOrFn);
849
+ return this.#add(require_constants.MethodMap.PUT, path, hookOrFn, fn);
848
850
  }
849
851
  patch(path, hookOrFn, fn) {
850
- return fn === void 0 ? this.#add(require_constants.MethodMap.PATCH, path, hookOrFn) : this.#add(require_constants.MethodMap.PATCH, path, fn, hookOrFn);
852
+ return this.#add(require_constants.MethodMap.PATCH, path, hookOrFn, fn);
851
853
  }
852
854
  delete(path, hookOrFn, fn) {
853
- return fn === void 0 ? this.#add(require_constants.MethodMap.DELETE, path, hookOrFn) : this.#add(require_constants.MethodMap.DELETE, path, fn, hookOrFn);
855
+ return this.#add(require_constants.MethodMap.DELETE, path, hookOrFn, fn);
854
856
  }
855
857
  options(path, hookOrFn, fn) {
856
- return fn === void 0 ? this.#add(require_constants.MethodMap.OPTIONS, path, hookOrFn) : this.#add(require_constants.MethodMap.OPTIONS, path, fn, hookOrFn);
858
+ return this.#add(require_constants.MethodMap.OPTIONS, path, hookOrFn, fn);
857
859
  }
858
860
  head(path, hookOrFn, fn) {
859
- return fn === void 0 ? this.#add(require_constants.MethodMap.HEAD, path, hookOrFn) : this.#add(require_constants.MethodMap.HEAD, path, fn, hookOrFn);
861
+ return this.#add(require_constants.MethodMap.HEAD, path, hookOrFn, fn);
860
862
  }
861
863
  method(method, path, hookOrFn, fn) {
862
- return fn === void 0 ? this.#add(method, path, hookOrFn) : this.#add(method, path, fn, hookOrFn);
864
+ return this.#add(method, path, hookOrFn, fn);
863
865
  }
864
866
  all(path, hookOrFn, fn) {
865
- if (fn === void 0) this.#add("*", path, hookOrFn);
866
- else this.#add("*", path, fn, hookOrFn);
867
+ this.#add("*", path, hookOrFn, fn);
867
868
  return this;
868
869
  }
869
870
  ws(path, optionsOrHandler, handler) {
@@ -879,7 +880,7 @@ var Elysia = class Elysia {
879
880
  opts = require_utils.nullObject();
880
881
  opts.message = optionsOrHandler;
881
882
  } else opts = optionsOrHandler;
882
- this.#add("WS", path, void 0, opts);
883
+ this.#add("WS", path, opts, void 0, true);
883
884
  return this;
884
885
  }
885
886
  mount(path, handleOrConfig, config) {
package/dist/base.mjs CHANGED
@@ -763,27 +763,29 @@ var Elysia = class Elysia {
763
763
  this.#routerBuilt = false;
764
764
  this.#buildRouter();
765
765
  }
766
- #add(method, path, fn, hook) {
766
+ #add(method, path, hookOrFn, fn, hasHook = fn !== void 0) {
767
767
  if (this["~Prefix"]) path = joinPath(this["~Prefix"], path);
768
768
  else if (path && path.charCodeAt(0) !== 47) path = "/" + path;
769
+ const handler = hasHook ? fn : hookOrFn;
770
+ const hook = hasHook ? hookOrFn : void 0;
769
771
  const appHook = this["~hookChain"];
770
772
  (this.#history ??= []).push(appHook ? [
771
773
  method,
772
774
  path,
773
- fn,
775
+ handler,
774
776
  this,
775
777
  hook,
776
778
  appHook
777
779
  ] : hook ? [
778
780
  method,
779
781
  path,
780
- fn,
782
+ handler,
781
783
  this,
782
784
  hook
783
785
  ] : [
784
786
  method,
785
787
  path,
786
- fn,
788
+ handler,
787
789
  this
788
790
  ]);
789
791
  this.#cachedRoutes = void 0;
@@ -835,32 +837,31 @@ var Elysia = class Elysia {
835
837
  return Ref(key);
836
838
  }
837
839
  get(path, hookOrFn, fn) {
838
- return fn === void 0 ? this.#add(MethodMap.GET, path, hookOrFn) : this.#add(MethodMap.GET, path, fn, hookOrFn);
840
+ return this.#add(MethodMap.GET, path, hookOrFn, fn);
839
841
  }
840
842
  post(path, hookOrFn, fn) {
841
- return fn === void 0 ? this.#add(MethodMap.POST, path, hookOrFn) : this.#add(MethodMap.POST, path, fn, hookOrFn);
843
+ return this.#add(MethodMap.POST, path, hookOrFn, fn);
842
844
  }
843
845
  put(path, hookOrFn, fn) {
844
- return fn === void 0 ? this.#add(MethodMap.PUT, path, hookOrFn) : this.#add(MethodMap.PUT, path, fn, hookOrFn);
846
+ return this.#add(MethodMap.PUT, path, hookOrFn, fn);
845
847
  }
846
848
  patch(path, hookOrFn, fn) {
847
- return fn === void 0 ? this.#add(MethodMap.PATCH, path, hookOrFn) : this.#add(MethodMap.PATCH, path, fn, hookOrFn);
849
+ return this.#add(MethodMap.PATCH, path, hookOrFn, fn);
848
850
  }
849
851
  delete(path, hookOrFn, fn) {
850
- return fn === void 0 ? this.#add(MethodMap.DELETE, path, hookOrFn) : this.#add(MethodMap.DELETE, path, fn, hookOrFn);
852
+ return this.#add(MethodMap.DELETE, path, hookOrFn, fn);
851
853
  }
852
854
  options(path, hookOrFn, fn) {
853
- return fn === void 0 ? this.#add(MethodMap.OPTIONS, path, hookOrFn) : this.#add(MethodMap.OPTIONS, path, fn, hookOrFn);
855
+ return this.#add(MethodMap.OPTIONS, path, hookOrFn, fn);
854
856
  }
855
857
  head(path, hookOrFn, fn) {
856
- return fn === void 0 ? this.#add(MethodMap.HEAD, path, hookOrFn) : this.#add(MethodMap.HEAD, path, fn, hookOrFn);
858
+ return this.#add(MethodMap.HEAD, path, hookOrFn, fn);
857
859
  }
858
860
  method(method, path, hookOrFn, fn) {
859
- return fn === void 0 ? this.#add(method, path, hookOrFn) : this.#add(method, path, fn, hookOrFn);
861
+ return this.#add(method, path, hookOrFn, fn);
860
862
  }
861
863
  all(path, hookOrFn, fn) {
862
- if (fn === void 0) this.#add("*", path, hookOrFn);
863
- else this.#add("*", path, fn, hookOrFn);
864
+ this.#add("*", path, hookOrFn, fn);
864
865
  return this;
865
866
  }
866
867
  ws(path, optionsOrHandler, handler) {
@@ -876,7 +877,7 @@ var Elysia = class Elysia {
876
877
  opts = nullObject();
877
878
  opts.message = optionsOrHandler;
878
879
  } else opts = optionsOrHandler;
879
- this.#add("WS", path, void 0, opts);
880
+ this.#add("WS", path, opts, void 0, true);
880
881
  return this;
881
882
  }
882
883
  mount(path, handleOrConfig, config) {
@@ -1,5 +1,5 @@
1
- import { AnyLocalHook, HTTPMethod } from "../../types.js";
2
1
  import { CapturedValidator, FrozenValidator } from "../aot.js";
2
+ import { AnyLocalHook, HTTPMethod } from "../../types.js";
3
3
  import { AnyElysia } from "../../base.js";
4
4
 
5
5
  //#region src/compile/handler/frozen-validator.d.ts
package/dist/index.d.ts CHANGED
@@ -1,12 +1,9 @@
1
1
  import { StatusMap, StatusMapBack } from "./constants.js";
2
2
  import { ElysiaError, ElysiaStatus, InternalServerError, NotFound, ParseError, Problem, SelectiveStatus, ValidationError, problem, status, validationDetail } from "./error.js";
3
+ import { ElysiaFile, file } from "./universal/file.js";
3
4
  import { BaseCookie, CookieOptions } from "./cookie/types.js";
4
5
  import { Cookie } from "./cookie/cookie.js";
5
6
  import { InvalidCookie } from "./cookie/error.js";
6
- import { ElysiaFile, file } from "./universal/file.js";
7
- import { env } from "./universal/env.js";
8
- import { Server } from "./universal/server.js";
9
- import { HTTPHeaders, InputSchema, Macro, MacroToContext, MacroToProperty, RouteSchema, SSEPayload, UnwrapRoute, UnwrapSchema } from "./types.js";
10
7
  import { AnySchema, BaseSchema, StandardJSONSchemaV1Like, StandardSchemaV1Like } from "./type/types.js";
11
8
  import { TCookieField, TCookieObject } from "./type/elysia/cookie.js";
12
9
  import { FileTypeDetector, fileType, setFileTypeDetector } from "./type/elysia/file-type.js";
@@ -16,6 +13,9 @@ import { Capture, Compiled } from "./compile/aot.js";
16
13
  import { MultiValidator, StandardValidator, Validator } from "./validator/index.js";
17
14
  import { TypeBoxValidator } from "./type/validator/index.js";
18
15
  import { TypeSystem, t } from "./type/index.js";
16
+ import { env } from "./universal/env.js";
17
+ import { Server } from "./universal/server.js";
18
+ import { HTTPHeaders, InputSchema, Macro, MacroToContext, MacroToProperty, RouteSchema, SSEPayload, UnwrapRoute, UnwrapSchema } from "./types.js";
19
19
  import { form, prefix, redirect, sse } from "./utils.js";
20
20
  import { Context, ErrorContext, createBaseContext, createContext } from "./context.js";
21
21
  import { AnyElysia, Elysia } from "./base.js";
@@ -1,5 +1,5 @@
1
- import { MaybeArray, MaybePromise } from "../../types.js";
2
1
  import { FileType, FileUnit } from "../types.js";
2
+ import { MaybeArray, MaybePromise } from "../../types.js";
3
3
 
4
4
  //#region src/type/elysia/file-type.d.ts
5
5
  type FileTypeDetector = (file: File) => MaybePromise<string | {
@@ -1,6 +1,6 @@
1
- import { MaybePromise } from "../../types.js";
2
1
  import { Validator as Validator$1, ValidatorOptions } from "../../validator/index.js";
3
2
  import { TypeBoxValidatorCache } from "./validator-cache.js";
3
+ import { MaybePromise } from "../../types.js";
4
4
  import { Static, StaticDecode, StaticEncode, TAny, TSchema } from "typebox/type";
5
5
  import { Validator } from "typebox/schema";
6
6
  import { TLocalizedValidationError } from "typebox/error";
package/dist/types.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { MethodMap, StatusMapBack } from "./constants.js";
2
2
  import { ElysiaError, ElysiaStatus } from "./error.js";
3
- import { CookieOptions } from "./cookie/types.js";
4
3
  import { ElysiaFile } from "./universal/file.js";
5
4
  import { TraceEvent, TraceListener } from "./trace.js";
6
- import { Serve } from "./universal/server.js";
5
+ import { CookieOptions } from "./cookie/types.js";
7
6
  import { AnySchema, StandardSchemaV1Like, TypeBoxSchema } from "./type/types.js";
7
+ import { Serve } from "./universal/server.js";
8
8
  import { ChainNode } from "./utils.js";
9
9
  import { Context, ErrorContext, LifecycleContext, PreContext } from "./context.js";
10
10
  import { WebSocketHandler } from "./ws/types.js";
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { MethodMap } from "./constants.js";
2
- import { AnyLocalHook, AppHook, ElysiaFormData, EventFn, EventScope, GuardSchemaType, InputSchema, Macro, MaybeArray, Prettify, SSEPayload } from "./types.js";
3
2
  import { AnySchema, StandardSchemaV1Like } from "./type/types.js";
3
+ import { AnyLocalHook, AppHook, ElysiaFormData, EventFn, EventScope, GuardSchemaType, InputSchema, Macro, MaybeArray, Prettify, SSEPayload } from "./types.js";
4
4
  import { Context } from "./context.js";
5
5
 
6
6
  //#region src/utils.d.ts
@@ -1,8 +1,8 @@
1
- import { ElysiaConfig, MaybePromise } from "../types.js";
2
1
  import { AnySchema, StandardSchemaV1Like } from "../type/types.js";
3
2
  import { CoerceOption } from "../type/coerce.js";
4
3
  import { ValidatorSlot } from "../compile/aot.js";
5
4
  import { TypeBoxValidator } from "../type/bridge.js";
5
+ import { ElysiaConfig, MaybePromise } from "../types.js";
6
6
  import { TSchema } from "typebox/type";
7
7
  import { TLocalizedValidationError } from "typebox/error";
8
8
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "elysia",
3
3
  "description": "Ergonomic Framework for Human",
4
- "version": "2.0.0-exp.27",
4
+ "version": "2.0.0-exp.28",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",