elysia 2.0.0-exp.3 → 2.0.0-exp.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/adapter/utils.d.ts +1 -1
  2. package/dist/base.d.ts +1 -1
  3. package/dist/base.js +22 -10
  4. package/dist/base.mjs +22 -10
  5. package/dist/compile/aot.d.ts +18 -1
  6. package/dist/compile/aot.js +19 -0
  7. package/dist/compile/aot.mjs +19 -0
  8. package/dist/compile/handler/index.d.ts +1 -1
  9. package/dist/compile/handler/index.js +16 -437
  10. package/dist/compile/handler/index.mjs +17 -438
  11. package/dist/compile/handler/jit.d.ts +35 -0
  12. package/dist/compile/handler/jit.js +445 -0
  13. package/dist/compile/handler/jit.mjs +443 -0
  14. package/dist/compile/handler/reconstruct.d.ts +13 -0
  15. package/dist/compile/handler/reconstruct.js +29 -0
  16. package/dist/compile/handler/reconstruct.mjs +28 -0
  17. package/dist/compile/jit-probe.d.ts +19 -0
  18. package/dist/compile/jit-probe.js +38 -0
  19. package/dist/compile/jit-probe.mjs +36 -0
  20. package/dist/error.d.ts +1 -1
  21. package/dist/handler/fetch.js +20 -10
  22. package/dist/handler/fetch.mjs +21 -11
  23. package/dist/plugin/bun.js +8 -1
  24. package/dist/plugin/bun.mjs +9 -2
  25. package/dist/plugin/core.d.ts +45 -1
  26. package/dist/plugin/core.js +60 -2
  27. package/dist/plugin/core.mjs +60 -4
  28. package/dist/plugin/esbuild.js +8 -1
  29. package/dist/plugin/esbuild.mjs +9 -2
  30. package/dist/plugin/source.d.ts +38 -1
  31. package/dist/plugin/source.js +96 -9
  32. package/dist/plugin/source.mjs +93 -9
  33. package/dist/plugin/vite.js +12 -1
  34. package/dist/plugin/vite.mjs +13 -2
  35. package/dist/trace.d.ts +1 -1
  36. package/dist/trace.js +4 -6
  37. package/dist/trace.mjs +4 -6
  38. package/dist/type/bridge.d.ts +7 -7
  39. package/dist/type/types.d.ts +1 -1
  40. package/dist/type/validator/default-precompute.d.ts +9 -1
  41. package/dist/type/validator/default-precompute.js +135 -15
  42. package/dist/type/validator/default-precompute.mjs +131 -16
  43. package/dist/type/validator/index.d.ts +2 -2
  44. package/dist/type/validator/index.js +62 -30
  45. package/dist/type/validator/index.mjs +63 -31
  46. package/dist/types.d.ts +1 -1
  47. package/dist/utils.js +6 -8
  48. package/dist/utils.mjs +6 -8
  49. package/package.json +2 -2
@@ -12,7 +12,7 @@ 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;
package/dist/base.d.ts CHANGED
@@ -43,7 +43,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
43
43
  '~map'?: {
44
44
  [method: string]: {
45
45
  [path: string]: CompiledHandler;
46
- };
46
+ } | undefined;
47
47
  };
48
48
  '~staticResponse'?: {
49
49
  [path: string]: {
package/dist/base.js CHANGED
@@ -813,13 +813,13 @@ var Elysia = class Elysia {
813
813
  }
814
814
  #initMap() {
815
815
  this["~map"] ??= {
816
- GET: require_utils.nullObject(),
817
- POST: require_utils.nullObject(),
818
- PUT: require_utils.nullObject(),
819
- DELETE: require_utils.nullObject(),
820
- PATCH: require_utils.nullObject(),
821
- HEAD: require_utils.nullObject(),
822
- OPTIONS: require_utils.nullObject()
816
+ GET: void 0,
817
+ POST: void 0,
818
+ PUT: void 0,
819
+ DELETE: void 0,
820
+ PATCH: void 0,
821
+ HEAD: void 0,
822
+ OPTIONS: void 0
823
823
  };
824
824
  }
825
825
  compile() {
@@ -897,6 +897,8 @@ var Elysia = class Elysia {
897
897
  }
898
898
  const wrapHeadHandler = Elysia.#wrapHeadHandler;
899
899
  const strict = !!this["~config"]?.strictPath;
900
+ const routerOptions = strict ? void 0 : { loosePath: true };
901
+ const getRouter = () => this["~router"] ??= new memoirist.default(routerOptions);
900
902
  let explicitPaths;
901
903
  if (!strict && this["~config"]?.distinctPath) {
902
904
  explicitPaths = /* @__PURE__ */ new Map();
@@ -921,7 +923,7 @@ var Elysia = class Elysia {
921
923
  const ws = require_ws_route.buildWSRoute(route, this);
922
924
  const handler = ws[0];
923
925
  const options = ws[1];
924
- if (require_constants.isDynamicRegex.test(path)) (this["~router"] ??= new memoirist.default()).add("WS", path, handler, false);
926
+ if (require_constants.isDynamicRegex.test(path)) getRouter().add("WS", path, handler, false);
925
927
  else {
926
928
  this.#initMap();
927
929
  const wsMap = this["~map"]["WS"] ??= require_utils.nullObject();
@@ -961,8 +963,18 @@ var Elysia = class Elysia {
961
963
  const sharedStatic = maybeStatic && staticResponse instanceof Response ? staticResponse : void 0;
962
964
  const autoHead = enableAutoHead && method === "GET" && !explicitHead?.has(path);
963
965
  const isDynamic = require_constants.isDynamicRegex.test(path);
964
- const registerLoose = !isDynamic && !strict;
966
+ const registerLoose = !isDynamic && !strict && (path.length === 0 || path.charCodeAt(path.length - 1) === 47);
965
967
  const explicitMain = registerLoose ? explicitPaths?.get(method) : void 0;
968
+ if (!isDynamic && !require_constants.needEncodeRegex.test(path) && !registerLoose) {
969
+ const map = methods[method] ??= require_utils.nullObject();
970
+ const handler = this.handler(i, precompile, route, sharedStatic);
971
+ map[path] = handler;
972
+ if (autoHead) {
973
+ const head = methods["HEAD"] ??= require_utils.nullObject();
974
+ head[path] = wrapHeadHandler(handler);
975
+ }
976
+ continue;
977
+ }
966
978
  const variants = [path];
967
979
  if (require_constants.needEncodeRegex.test(path)) {
968
980
  const encoded = encodeURI(path);
@@ -978,7 +990,7 @@ var Elysia = class Elysia {
978
990
  }
979
991
  }
980
992
  if (isDynamic) {
981
- const router = this["~router"] ??= new memoirist.default();
993
+ const router = getRouter();
982
994
  const handler = this.handler(i, precompile, void 0, sharedStatic);
983
995
  const headHandler = autoHead ? wrapHeadHandler(handler) : void 0;
984
996
  for (let p = 0; p < paths.length; p++) {
package/dist/base.mjs CHANGED
@@ -810,13 +810,13 @@ var Elysia = class Elysia {
810
810
  }
811
811
  #initMap() {
812
812
  this["~map"] ??= {
813
- GET: nullObject(),
814
- POST: nullObject(),
815
- PUT: nullObject(),
816
- DELETE: nullObject(),
817
- PATCH: nullObject(),
818
- HEAD: nullObject(),
819
- OPTIONS: nullObject()
813
+ GET: void 0,
814
+ POST: void 0,
815
+ PUT: void 0,
816
+ DELETE: void 0,
817
+ PATCH: void 0,
818
+ HEAD: void 0,
819
+ OPTIONS: void 0
820
820
  };
821
821
  }
822
822
  compile() {
@@ -894,6 +894,8 @@ var Elysia = class Elysia {
894
894
  }
895
895
  const wrapHeadHandler = Elysia.#wrapHeadHandler;
896
896
  const strict = !!this["~config"]?.strictPath;
897
+ const routerOptions = strict ? void 0 : { loosePath: true };
898
+ const getRouter = () => this["~router"] ??= new Memoirist(routerOptions);
897
899
  let explicitPaths;
898
900
  if (!strict && this["~config"]?.distinctPath) {
899
901
  explicitPaths = /* @__PURE__ */ new Map();
@@ -918,7 +920,7 @@ var Elysia = class Elysia {
918
920
  const ws = buildWSRoute(route, this);
919
921
  const handler = ws[0];
920
922
  const options = ws[1];
921
- if (isDynamicRegex.test(path)) (this["~router"] ??= new Memoirist()).add("WS", path, handler, false);
923
+ if (isDynamicRegex.test(path)) getRouter().add("WS", path, handler, false);
922
924
  else {
923
925
  this.#initMap();
924
926
  const wsMap = this["~map"]["WS"] ??= nullObject();
@@ -958,8 +960,18 @@ var Elysia = class Elysia {
958
960
  const sharedStatic = maybeStatic && staticResponse instanceof Response ? staticResponse : void 0;
959
961
  const autoHead = enableAutoHead && method === "GET" && !explicitHead?.has(path);
960
962
  const isDynamic = isDynamicRegex.test(path);
961
- const registerLoose = !isDynamic && !strict;
963
+ const registerLoose = !isDynamic && !strict && (path.length === 0 || path.charCodeAt(path.length - 1) === 47);
962
964
  const explicitMain = registerLoose ? explicitPaths?.get(method) : void 0;
965
+ if (!isDynamic && !needEncodeRegex.test(path) && !registerLoose) {
966
+ const map = methods[method] ??= nullObject();
967
+ const handler = this.handler(i, precompile, route, sharedStatic);
968
+ map[path] = handler;
969
+ if (autoHead) {
970
+ const head = methods["HEAD"] ??= nullObject();
971
+ head[path] = wrapHeadHandler(handler);
972
+ }
973
+ continue;
974
+ }
963
975
  const variants = [path];
964
976
  if (needEncodeRegex.test(path)) {
965
977
  const encoded = encodeURI(path);
@@ -975,7 +987,7 @@ var Elysia = class Elysia {
975
987
  }
976
988
  }
977
989
  if (isDynamic) {
978
- const router = this["~router"] ??= new Memoirist();
990
+ const router = getRouter();
979
991
  const handler = this.handler(i, precompile, void 0, sharedStatic);
980
992
  const headHandler = autoHead ? wrapHeadHandler(handler) : void 0;
981
993
  for (let p = 0; p < paths.length; p++) {
@@ -33,7 +33,10 @@ interface FrozenValidator {
33
33
  r?: 1;
34
34
  ps?: 1;
35
35
  pd?: unknown;
36
+ pn?: 1;
36
37
  pod?: Record<string, unknown>;
38
+ dc?: () => unknown;
39
+ pm?: (value: Record<string, unknown>) => Record<string, unknown>;
37
40
  ce?: Array<{
38
41
  p: string;
39
42
  c: FrozenCheckFactory;
@@ -63,6 +66,13 @@ interface HandlerManifest {
63
66
  [path: string]: FrozenHandler;
64
67
  };
65
68
  }
69
+ interface CompiledSnapshot {
70
+ validators: ValidatorManifest | undefined;
71
+ handlers: HandlerManifest | undefined;
72
+ lazyGroups: Array<() => ValidatorManifest> | undefined;
73
+ lazyGroupOf: Record<string, Record<string, number>> | undefined;
74
+ builtGroups: number[];
75
+ }
66
76
  declare abstract class Compiled {
67
77
  static get handlers(): HandlerManifest | undefined;
68
78
  static set handlers(manifest: HandlerManifest);
@@ -71,6 +81,10 @@ declare abstract class Compiled {
71
81
  static registerLazyValidators(groups: Array<() => ValidatorManifest>, groupOf: Record<string, Record<string, number>>): void;
72
82
  static getValidator(method: string, path: string, slot: ValidatorSlot): FrozenValidator | undefined;
73
83
  static hasValidator(method: string, path: string, slot: ValidatorSlot): boolean;
84
+ /** @internal preserve registry around in-process AOT analysis */
85
+ static snapshot(): CompiledSnapshot;
86
+ /** @internal restore registry after in-process AOT analysis */
87
+ static restore(snapshot: CompiledSnapshot): void;
74
88
  /** @internal test isolation */
75
89
  static clear(): void;
76
90
  }
@@ -145,7 +159,10 @@ interface CapturedValidator {
145
159
  encodeMirror?: CapturedMirror;
146
160
  precomputeSafe?: boolean;
147
161
  precomputedDefault?: unknown;
162
+ precomputeNull?: boolean;
148
163
  precomputedObjectDefault?: Record<string, unknown>;
164
+ defaultCloner?: string;
165
+ objectDefaultMerger?: string;
149
166
  customErrors?: Array<{
150
167
  path: string;
151
168
  identifier: string;
@@ -186,4 +203,4 @@ declare const Capture: {
186
203
  readonly isCapturing: () => boolean;
187
204
  };
188
205
  //#endregion
189
- export { Capture, CapturedHandler, CapturedMirror, CapturedValidator, CheckBuildResult, Compiled, EMPTY_EXTERNALS, FrozenBothFactory, FrozenCheckFactory, FrozenHandler, FrozenMirror, FrozenMirrorFactory, FrozenValidator, HandlerManifest, Source, ValidatorManifest, ValidatorSlot, beginValidatorCapture, collectExternals, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck };
206
+ export { Capture, CapturedHandler, CapturedMirror, CapturedValidator, CheckBuildResult, Compiled, CompiledSnapshot, EMPTY_EXTERNALS, FrozenBothFactory, FrozenCheckFactory, FrozenHandler, FrozenMirror, FrozenMirrorFactory, FrozenValidator, HandlerManifest, Source, ValidatorManifest, ValidatorSlot, beginValidatorCapture, collectExternals, endHandlerCapture, endValidatorCapture, externalsMatch, instantiateFrozenBoth, instantiateFrozenDecodeMirror, instantiateFrozenEncodeMirror, instantiateFrozenMirror, reconstructCheck };
@@ -48,6 +48,25 @@ var Compiled = class {
48
48
  static hasValidator(method, path, slot) {
49
49
  return validators?.[method]?.[path]?.[slot] !== void 0 || lazyGroupOf?.[method]?.[path] !== void 0;
50
50
  }
51
+ /** @internal preserve registry around in-process AOT analysis */
52
+ static snapshot() {
53
+ return {
54
+ validators,
55
+ handlers,
56
+ lazyGroups,
57
+ lazyGroupOf,
58
+ builtGroups: [...builtGroups]
59
+ };
60
+ }
61
+ /** @internal restore registry after in-process AOT analysis */
62
+ static restore(snapshot) {
63
+ validators = snapshot.validators;
64
+ handlers = snapshot.handlers;
65
+ lazyGroups = snapshot.lazyGroups;
66
+ lazyGroupOf = snapshot.lazyGroupOf;
67
+ builtGroups.clear();
68
+ for (const group of snapshot.builtGroups) builtGroups.add(group);
69
+ }
51
70
  /** @internal test isolation */
52
71
  static clear() {
53
72
  validators = void 0;
@@ -47,6 +47,25 @@ var Compiled = class {
47
47
  static hasValidator(method, path, slot) {
48
48
  return validators?.[method]?.[path]?.[slot] !== void 0 || lazyGroupOf?.[method]?.[path] !== void 0;
49
49
  }
50
+ /** @internal preserve registry around in-process AOT analysis */
51
+ static snapshot() {
52
+ return {
53
+ validators,
54
+ handlers,
55
+ lazyGroups,
56
+ lazyGroupOf,
57
+ builtGroups: [...builtGroups]
58
+ };
59
+ }
60
+ /** @internal restore registry after in-process AOT analysis */
61
+ static restore(snapshot) {
62
+ validators = snapshot.validators;
63
+ handlers = snapshot.handlers;
64
+ lazyGroups = snapshot.lazyGroups;
65
+ lazyGroupOf = snapshot.lazyGroupOf;
66
+ builtGroups.clear();
67
+ for (const group of snapshot.builtGroups) builtGroups.add(group);
68
+ }
50
69
  /** @internal test isolation */
51
70
  static clear() {
52
71
  validators = void 0;
@@ -1,9 +1,9 @@
1
1
  import { AnyLocalHook, CompiledHandler, InternalRoute } from "../../types.js";
2
2
  import { ChainNode } from "../../utils.js";
3
3
  import { AnyElysia } from "../../base.js";
4
+ import { setCaptureHeaderShorthand } from "./jit.js";
4
5
 
5
6
  //#region src/compile/handler/index.d.ts
6
- declare const setCaptureHeaderShorthand: (value: boolean | undefined) => void;
7
7
  declare function buildNativeStaticResponse([,, handler, instance, localHook, appHook, inheritedChain]: InternalRoute, root: AnyElysia): Response | Promise<Response> | undefined;
8
8
  declare function composeRouteHook(instance: AnyElysia, localHook: Partial<AnyLocalHook> | undefined, appHook: ChainNode | undefined, inheritedChain: ChainNode | undefined, root: AnyElysia): AnyLocalHook | undefined;
9
9
  declare function compileHandler([_method, path, handler, instance, localHook, appHook, inheritedChain]: InternalRoute, root: AnyElysia, precomputedStatic?: Response): CompiledHandler;