elysia 1.3.1 → 1.3.2-exp.0

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 (53) hide show
  1. package/dist/adapter/bun/compose.mjs +5 -0
  2. package/dist/adapter/bun/handler-native.mjs +5 -0
  3. package/dist/adapter/bun/handler.mjs +5 -0
  4. package/dist/adapter/bun/index.mjs +56 -23
  5. package/dist/adapter/utils.mjs +5 -0
  6. package/dist/adapter/web-standard/handler.mjs +5 -0
  7. package/dist/adapter/web-standard/index.mjs +5 -0
  8. package/dist/bun/index.d.ts +11 -7
  9. package/dist/bun/index.js +5 -5
  10. package/dist/bun/index.js.map +6 -6
  11. package/dist/cjs/adapter/bun/compose.js +5 -0
  12. package/dist/cjs/adapter/bun/handler-native.js +5 -0
  13. package/dist/cjs/adapter/bun/handler.js +5 -0
  14. package/dist/cjs/adapter/bun/index.js +56 -23
  15. package/dist/cjs/adapter/utils.js +5 -0
  16. package/dist/cjs/adapter/web-standard/handler.js +5 -0
  17. package/dist/cjs/adapter/web-standard/index.js +5 -0
  18. package/dist/cjs/compose.js +5 -1
  19. package/dist/cjs/context.d.ts +1 -1
  20. package/dist/cjs/cookies.d.ts +2 -2
  21. package/dist/cjs/cookies.js +5 -0
  22. package/dist/cjs/dynamic-handle.js +5 -0
  23. package/dist/cjs/error.d.ts +1 -1
  24. package/dist/cjs/error.js +5 -0
  25. package/dist/cjs/index.d.ts +11 -7
  26. package/dist/cjs/index.js +68 -30
  27. package/dist/cjs/schema.js +5 -0
  28. package/dist/cjs/sucrose.js +5 -0
  29. package/dist/cjs/trace.js +8 -1
  30. package/dist/cjs/type-system/index.js +5 -0
  31. package/dist/cjs/type-system/utils.js +5 -0
  32. package/dist/cjs/utils.d.ts +1 -0
  33. package/dist/cjs/utils.js +7 -1
  34. package/dist/cjs/ws/index.js +5 -0
  35. package/dist/compose.mjs +5 -1
  36. package/dist/context.d.ts +1 -1
  37. package/dist/cookies.d.ts +2 -2
  38. package/dist/cookies.mjs +5 -0
  39. package/dist/dynamic-handle.mjs +5 -0
  40. package/dist/error.d.ts +1 -1
  41. package/dist/error.mjs +5 -0
  42. package/dist/index.d.ts +11 -7
  43. package/dist/index.mjs +68 -30
  44. package/dist/schema.mjs +5 -0
  45. package/dist/sucrose.mjs +5 -0
  46. package/dist/trace.mjs +8 -1
  47. package/dist/type-system/index.mjs +5 -0
  48. package/dist/type-system/utils.mjs +5 -0
  49. package/dist/utils.d.ts +1 -0
  50. package/dist/utils.mjs +6 -1
  51. package/dist/ws/index.mjs +5 -0
  52. package/package.json +2 -2
  53. package/bunfig.toml +0 -2
@@ -225,6 +225,11 @@ var isNotEmpty = (obj) => {
225
225
  for (let x in obj) return !0;
226
226
  return !1;
227
227
  };
228
+ var supportPerMethodInlineHandler = (() => {
229
+ if (typeof Bun > "u") return !0;
230
+ let semver = Bun.version.split(".");
231
+ return !(+semver[0] < 1 || +semver[1] < 2 || +semver[2] < 14);
232
+ })();
228
233
 
229
234
  // src/sucrose.ts
230
235
  var separateFunction = (code) => {
@@ -100,6 +100,11 @@ var isNotEmpty = (obj) => {
100
100
  for (let x in obj) return !0;
101
101
  return !1;
102
102
  };
103
+ var supportPerMethodInlineHandler = (() => {
104
+ if (typeof Bun > "u") return !0;
105
+ let semver = Bun.version.split(".");
106
+ return !(+semver[0] < 1 || +semver[1] < 2 || +semver[2] < 14);
107
+ })();
103
108
 
104
109
  // src/error.ts
105
110
  import { Value } from "@sinclair/typebox/value";
@@ -100,6 +100,11 @@ var isNotEmpty = (obj) => {
100
100
  for (let x in obj) return !0;
101
101
  return !1;
102
102
  };
103
+ var supportPerMethodInlineHandler = (() => {
104
+ if (typeof Bun > "u") return !0;
105
+ let semver = Bun.version.split(".");
106
+ return !(+semver[0] < 1 || +semver[1] < 2 || +semver[2] < 14);
107
+ })();
103
108
 
104
109
  // src/error.ts
105
110
  import { Value } from "@sinclair/typebox/value";
@@ -243,6 +243,11 @@ var isNotEmpty = (obj) => {
243
243
  for (let x in obj) return !0;
244
244
  return !1;
245
245
  };
246
+ var supportPerMethodInlineHandler = (() => {
247
+ if (typeof Bun > "u") return !0;
248
+ let semver = Bun.version.split(".");
249
+ return !(+semver[0] < 1 || +semver[1] < 2 || +semver[2] < 14);
250
+ })();
246
251
 
247
252
  // src/error.ts
248
253
  import { Value } from "@sinclair/typebox/value";
@@ -3348,21 +3353,51 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
3348
3353
  throw new Error("Port must be a numeric value");
3349
3354
  options = parseInt(options);
3350
3355
  }
3351
- let staticRoutes = {};
3352
- for (let [path, route] of Object.entries(app.router.response))
3353
- route && !(route instanceof Promise) && (staticRoutes[path] = route);
3354
- let serve = typeof options == "object" ? {
3356
+ let createStaticRoute = (iterator, { withAsync = !1 } = {}) => {
3357
+ let staticRoutes = {}, ops = [];
3358
+ for (let [path, route] of Object.entries(iterator))
3359
+ if (supportPerMethodInlineHandler) {
3360
+ if (!route) continue;
3361
+ for (let [method, value] of Object.entries(route))
3362
+ if (!(!value || !(method in supportedMethods))) {
3363
+ if (value instanceof Promise) {
3364
+ withAsync && (staticRoutes[path] || (staticRoutes[path] = {}), ops.push(
3365
+ value.then((awaited) => {
3366
+ awaited instanceof Response && (staticRoutes[path][method] = awaited);
3367
+ })
3368
+ ));
3369
+ continue;
3370
+ }
3371
+ value instanceof Response && (staticRoutes[path] || (staticRoutes[path] = {}), staticRoutes[path][method] = value);
3372
+ }
3373
+ } else {
3374
+ if (!route) continue;
3375
+ if (route instanceof Promise) {
3376
+ withAsync && (staticRoutes[path] || (staticRoutes[path] = {}), ops.push(
3377
+ route.then((awaited) => {
3378
+ awaited instanceof Response && (staticRoutes[path] = awaited);
3379
+ })
3380
+ ));
3381
+ continue;
3382
+ }
3383
+ if (!(route instanceof Response)) continue;
3384
+ staticRoutes[path] = route;
3385
+ }
3386
+ return withAsync ? Promise.all(ops).then(() => staticRoutes) : staticRoutes;
3387
+ }, serve = typeof options == "object" ? {
3355
3388
  development: !isProduction,
3356
3389
  reusePort: !0,
3357
3390
  ...app.config.serve || {},
3358
3391
  ...options || {},
3359
3392
  // @ts-ignore
3360
- routes: {
3361
- ...staticRoutes,
3362
- ...mapRoutes(app),
3363
- // @ts-expect-error
3364
- ...app.config.serve?.routes
3365
- },
3393
+ routes: mergeRoutes(
3394
+ mergeRoutes(
3395
+ createStaticRoute(app.router.response),
3396
+ mapRoutes(app)
3397
+ ),
3398
+ // @ts-expect-error private property
3399
+ app.config.serve?.routes
3400
+ ),
3366
3401
  websocket: {
3367
3402
  ...app.config.websocket || {},
3368
3403
  ...websocket || {}
@@ -3375,7 +3410,10 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
3375
3410
  ...app.config.serve || {},
3376
3411
  // @ts-ignore
3377
3412
  routes: mergeRoutes(
3378
- mergeRoutes(staticRoutes, mapRoutes(app)),
3413
+ mergeRoutes(
3414
+ createStaticRoute(app.router.response),
3415
+ mapRoutes(app)
3416
+ ),
3379
3417
  // @ts-expect-error private property
3380
3418
  app.config.serve?.routes
3381
3419
  ),
@@ -3395,26 +3433,21 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
3395
3433
  for (let i = 0; i < app.event.stop.length; i++)
3396
3434
  app.event.stop[i].fn(app);
3397
3435
  }), app.promisedModules.then(async () => {
3398
- Bun?.gc(!1);
3399
- let staticRoutes2 = {}, asyncStaticRoutes = [], asyncStaticRoutesPath = [];
3400
- for (let [path, route] of Object.entries(app.router.response))
3401
- route instanceof Promise ? (asyncStaticRoutes.push(route), asyncStaticRoutesPath.push(path)) : route && (staticRoutes2[path] = route);
3402
- if (!app.server && !isNotEmpty(asyncStaticRoutes)) return;
3403
- let promises = await Promise.all(asyncStaticRoutes);
3404
- for (let i = 0; i < promises.length; i++) {
3405
- let route = promises[i], path = asyncStaticRoutesPath[i];
3406
- route && (staticRoutes2[path] = route);
3407
- }
3408
3436
  app.server?.reload({
3409
3437
  ...serve,
3410
3438
  fetch: app.fetch,
3411
3439
  // @ts-ignore
3412
3440
  routes: mergeRoutes(
3413
- mergeRoutes(staticRoutes2, mapRoutes(app)),
3441
+ mergeRoutes(
3442
+ await createStaticRoute(app.router.response, {
3443
+ withAsync: !0
3444
+ }),
3445
+ mapRoutes(app)
3446
+ ),
3414
3447
  // @ts-expect-error private property
3415
3448
  app.config.serve?.routes
3416
3449
  )
3417
- });
3450
+ }), Bun?.gc(!1);
3418
3451
  });
3419
3452
  };
3420
3453
  },
@@ -100,6 +100,11 @@ var isNotEmpty = (obj) => {
100
100
  for (let x in obj) return !0;
101
101
  return !1;
102
102
  };
103
+ var supportPerMethodInlineHandler = (() => {
104
+ if (typeof Bun > "u") return !0;
105
+ let semver = Bun.version.split(".");
106
+ return !(+semver[0] < 1 || +semver[1] < 2 || +semver[2] < 14);
107
+ })();
103
108
 
104
109
  // src/error.ts
105
110
  import { Value } from "@sinclair/typebox/value";
@@ -100,6 +100,11 @@ var isNotEmpty = (obj) => {
100
100
  for (let x in obj) return !0;
101
101
  return !1;
102
102
  };
103
+ var supportPerMethodInlineHandler = (() => {
104
+ if (typeof Bun > "u") return !0;
105
+ let semver = Bun.version.split(".");
106
+ return !(+semver[0] < 1 || +semver[1] < 2 || +semver[2] < 14);
107
+ })();
103
108
 
104
109
  // src/error.ts
105
110
  import { Value } from "@sinclair/typebox/value";
@@ -100,6 +100,11 @@ var isNotEmpty = (obj) => {
100
100
  for (let x in obj) return !0;
101
101
  return !1;
102
102
  };
103
+ var supportPerMethodInlineHandler = (() => {
104
+ if (typeof Bun > "u") return !0;
105
+ let semver = Bun.version.split(".");
106
+ return !(+semver[0] < 1 || +semver[1] < 2 || +semver[2] < 14);
107
+ })();
103
108
 
104
109
  // src/error.ts
105
110
  import { Value } from "@sinclair/typebox/value";
@@ -90,7 +90,11 @@ export default class Elysia<const in out BasePath extends string = '', const in
90
90
  '~dynamic': Memoirist<DynamicHandler> | undefined;
91
91
  readonly dynamic: Memoirist<DynamicHandler>;
92
92
  static: { [path in string]: { [method in string]: number; }; };
93
- response: Record<string, MaybePromise<Response | undefined>>;
93
+ response: {
94
+ [path: string]: MaybePromise<Response | undefined> | {
95
+ [method: string]: MaybePromise<Response | undefined>;
96
+ };
97
+ };
94
98
  history: InternalRoute[];
95
99
  };
96
100
  protected routeTree: Record<string, number>;
@@ -1726,13 +1730,13 @@ export default class Elysia<const in out BasePath extends string = '', const in
1726
1730
  error: Type extends 'error' | 'all' ? 'prefix' extends Base ? Word extends `${string}${'_' | '-' | ' '}` ? AddPrefix<Word, Definitions['error']> : AddPrefixCapitalize<Word, Definitions['error']> : AddSuffixCapitalize<Word, Definitions['error']> : Definitions['error'];
1727
1731
  }, Metadata, Routes, Ephemeral, Volatile>;
1728
1732
  prefix<const Type extends 'all' | 'decorator' | 'state' | 'model' | 'error', const Word extends string>(type: Type, word: Word): Elysia<BasePath, {
1729
- decorator: Type extends "decorator" | "all" ? Word extends `${string}-` | `${string} ` | `${string}_` ? AddPrefix<Word, Singleton["decorator"]> : AddPrefixCapitalize<Word, Singleton["decorator"]> : Singleton["decorator"];
1730
- store: Type extends "all" | "state" ? Word extends `${string}-` | `${string} ` | `${string}_` ? AddPrefix<Word, Singleton["store"]> : AddPrefixCapitalize<Word, Singleton["store"]> : Singleton["store"];
1731
- derive: Type extends "decorator" | "all" ? Word extends `${string}-` | `${string} ` | `${string}_` ? AddPrefix<Word, Singleton["derive"]> : AddPrefixCapitalize<Word, Singleton["derive"]> : Singleton["derive"];
1732
- resolve: Type extends "decorator" | "all" ? Word extends `${string}-` | `${string} ` | `${string}_` ? AddPrefix<Word, Singleton["resolve"]> : AddPrefixCapitalize<Word, Singleton["resolve"]> : Singleton["resolve"];
1733
+ decorator: Type extends "decorator" | "all" ? Word extends `${string} ` | `${string}-` | `${string}_` ? AddPrefix<Word, Singleton["decorator"]> : AddPrefixCapitalize<Word, Singleton["decorator"]> : Singleton["decorator"];
1734
+ store: Type extends "all" | "state" ? Word extends `${string} ` | `${string}-` | `${string}_` ? AddPrefix<Word, Singleton["store"]> : AddPrefixCapitalize<Word, Singleton["store"]> : Singleton["store"];
1735
+ derive: Type extends "decorator" | "all" ? Word extends `${string} ` | `${string}-` | `${string}_` ? AddPrefix<Word, Singleton["derive"]> : AddPrefixCapitalize<Word, Singleton["derive"]> : Singleton["derive"];
1736
+ resolve: Type extends "decorator" | "all" ? Word extends `${string} ` | `${string}-` | `${string}_` ? AddPrefix<Word, Singleton["resolve"]> : AddPrefixCapitalize<Word, Singleton["resolve"]> : Singleton["resolve"];
1733
1737
  }, {
1734
- typebox: Type extends "all" | "model" ? Word extends `${string}-` | `${string} ` | `${string}_` ? AddPrefix<Word, Definitions["typebox"]> : AddPrefixCapitalize<Word, Definitions["typebox"]> : Definitions["typebox"];
1735
- error: Type extends "error" | "all" ? Word extends `${string}-` | `${string} ` | `${string}_` ? AddPrefix<Word, Definitions["error"]> : AddPrefixCapitalize<Word, Definitions["error"]> : Definitions["error"];
1738
+ typebox: Type extends "all" | "model" ? Word extends `${string} ` | `${string}-` | `${string}_` ? AddPrefix<Word, Definitions["typebox"]> : AddPrefixCapitalize<Word, Definitions["typebox"]> : Definitions["typebox"];
1739
+ error: Type extends "error" | "all" ? Word extends `${string} ` | `${string}-` | `${string}_` ? AddPrefix<Word, Definitions["error"]> : AddPrefixCapitalize<Word, Definitions["error"]> : Definitions["error"];
1736
1740
  }, Metadata, Routes, Ephemeral, Volatile>;
1737
1741
  suffix<const Type extends 'all' | 'decorator' | 'state' | 'model' | 'error', const Word extends string>(type: Type, word: Word): Elysia<BasePath, {
1738
1742
  decorator: Type extends "decorator" | "all" ? AddSuffixCapitalize<Word, Singleton["decorator"]> : Singleton["decorator"];