elysia 1.3.4 → 1.3.6

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.
@@ -134,6 +134,7 @@ var primitiveHooks = [
134
134
  {}
135
135
  );
136
136
  var isBun2 = typeof Bun < "u", hasBunHash = isBun2 && typeof Bun.hash == "function", checksum = (s) => {
137
+ if (hasBunHash) return Bun.hash(s);
137
138
  let h = 9;
138
139
  for (let i = 0; i < s.length; ) h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
139
140
  return h = h ^ h >>> 9;
@@ -2008,14 +2009,14 @@ var allocateIf = (value, condition) => condition ? value : "", createContext = (
2008
2009
  hasTrace && (fnLiteral += `const id=randomId()
2009
2010
  `);
2010
2011
  let isDynamic = /[:*]/.test(route.path), getQi = `const u=request.url,s=u.indexOf('/',${app.config.handler?.standardHostname ?? !0 ? 11 : 7}),qi=u.indexOf('?', s + 1)
2011
- `;
2012
- inference.query && (fnLiteral += getQi);
2013
- let getPath = inference.path ? isDynamic ? "get path(){" + (inference.query ? "" : getQi) + `if(qi===-1)return u.substring(s)
2012
+ `, needsQuery = inference.query || !!route.hooks.query || !!route.standaloneValidators?.find((x) => x.query);
2013
+ needsQuery && (fnLiteral += getQi);
2014
+ let getPath = inference.path ? isDynamic ? "get path(){" + (needsQuery ? "" : getQi) + `if(qi===-1)return u.substring(s)
2014
2015
  return u.substring(s,qi)
2015
2016
  },` : `path:'${route.path}',` : "";
2016
- fnLiteral += allocateIf("const c=", !isInline) + "{request,store," + allocateIf("qi,", inference.query) + allocateIf("params:request.params,", isDynamic) + getPath + allocateIf(
2017
+ fnLiteral += allocateIf("const c=", !isInline) + "{request,store," + allocateIf("qi,", needsQuery) + allocateIf("params:request.params,", isDynamic) + getPath + allocateIf(
2017
2018
  "url:request.url,",
2018
- hasTrace || inference.url || inference.query
2019
+ hasTrace || inference.url || needsQuery
2019
2020
  ) + "redirect,error:status,status,set:{headers:" + (isNotEmpty(defaultHeaders) ? "Object.assign({},app.setHeaders)" : "Object.create(null)") + ",status:200}", inference.server && (fnLiteral += ",get server(){return app.getServer()}"), hasTrace && (fnLiteral += ",[ELYSIA_REQUEST_ID]:id");
2020
2021
  {
2021
2022
  let decoratorsLiteral = "";
@@ -2039,8 +2040,10 @@ return u.substring(s,qi)
2039
2040
  );
2040
2041
  let fnLiteral = "const handler=data.handler,app=data.app,store=data.store,decorator=data.decorator,redirect=data.redirect,route=data.route,mapEarlyResponse=data.mapEarlyResponse," + allocateIf("randomId=data.randomId,", hasTrace) + allocateIf("ELYSIA_REQUEST_ID=data.ELYSIA_REQUEST_ID,", hasTrace) + allocateIf("ELYSIA_TRACE=data.ELYSIA_TRACE,", hasTrace) + allocateIf("trace=data.trace,", hasTrace) + allocateIf("hoc=data.hoc,", hasHoc) + `status=data.status
2041
2042
  `;
2042
- return app.event.request?.length && (fnLiteral += `const onRequest=app.event.request.map(x=>x.fn)
2043
- `), fnLiteral += `${app.event.request?.find(isAsync) ? "async" : ""} function map(request){`, hasTrace || inference.query || app.event.request?.length ? (fnLiteral += createContext(app, route, inference), fnLiteral += createOnRequestHandler(app), fnLiteral += "return handler(c)}") : fnLiteral += `return handler(${createContext(app, route, inference, !0)})}`, fnLiteral += createHoc(app), Function(
2043
+ app.event.request?.length && (fnLiteral += `const onRequest=app.event.request.map(x=>x.fn)
2044
+ `), fnLiteral += `${app.event.request?.find(isAsync) ? "async" : ""} function map(request){`;
2045
+ let needsQuery = inference.query || !!route.hooks.query || !!route.standaloneValidators?.find((x) => x.query);
2046
+ return hasTrace || needsQuery ? (fnLiteral += createContext(app, route, inference), fnLiteral += createOnRequestHandler(app), fnLiteral += "return handler(c)}") : fnLiteral += `return handler(${createContext(app, route, inference, !0)})}`, fnLiteral += createHoc(app), Function(
2044
2047
  "data",
2045
2048
  fnLiteral
2046
2049
  )({
@@ -697,7 +697,7 @@ var createNativeStaticHandler = (handle, hooks, setHeaders = {}) => {
697
697
  return response instanceof Promise ? response.then((response2) => {
698
698
  if (response2)
699
699
  return response2.headers.has("content-type") || response2.headers.append("content-type", "text/plain"), response2.clone();
700
- }) : (response.headers.has("content-type") || response.headers.append("content-type", "text/plain"), response.clone.bind(response));
700
+ }) : (response.headers.has("content-type") || response.headers.append("content-type", "text/plain"), () => response.clone());
701
701
  };
702
702
  export {
703
703
  createNativeStaticHandler
@@ -138,6 +138,7 @@ var primitiveHooks = [
138
138
  {}
139
139
  );
140
140
  var isBun2 = typeof Bun < "u", hasBunHash = isBun2 && typeof Bun.hash == "function", checksum = (s) => {
141
+ if (hasBunHash) return Bun.hash(s);
141
142
  let h = 9;
142
143
  for (let i = 0; i < s.length; ) h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
143
144
  return h = h ^ h >>> 9;
@@ -1184,6 +1185,15 @@ else c.body[key]=value}`;
1184
1185
  }
1185
1186
  }
1186
1187
  },
1188
+ async stop(app, closeActiveConnections) {
1189
+ if (!app.server)
1190
+ throw new Error(
1191
+ "Elysia isn't running. Call `app.listen` to start the server."
1192
+ );
1193
+ if (app.server && (app.server.stop(closeActiveConnections), app.server = null, app.event.stop?.length))
1194
+ for (let i = 0; i < app.event.stop.length; i++)
1195
+ app.event.stop[i].fn(app);
1196
+ },
1187
1197
  composeGeneralHandler: {
1188
1198
  parameters: "r",
1189
1199
  createContext(app) {
@@ -2125,6 +2135,8 @@ var hasProperty = (expectedProperty, _schema) => {
2125
2135
  }, _replaceSchemaType = (schema, options, config) => {
2126
2136
  if (!schema) return schema;
2127
2137
  let root = config.root;
2138
+ if (options.onlyFirstObject && schema.type === "object")
2139
+ return options.to(schema) ?? schema;
2128
2140
  if (options.untilObjectFound && !root && schema.type === "object")
2129
2141
  return schema;
2130
2142
  let fromSymbol = options.from[Kind3];
@@ -2321,17 +2333,20 @@ var hasProperty = (expectedProperty, _schema) => {
2321
2333
  }));
2322
2334
  break;
2323
2335
  }
2324
- return schema;
2336
+ return schema.type === "array" && schema.items && (Array.isArray(schema.items) ? schema.items = schema.items.map(
2337
+ (item) => _replaceSchemaType(item, options, {
2338
+ ...config,
2339
+ root: !1
2340
+ })
2341
+ ) : schema.items = _replaceSchemaType(schema.items, options, {
2342
+ ...config,
2343
+ root: !1
2344
+ })), schema;
2325
2345
  }, createCleaner = (schema) => (value) => {
2326
2346
  if (typeof value == "object")
2327
2347
  try {
2328
2348
  return Value3.Clean(schema, value);
2329
2349
  } catch {
2330
- try {
2331
- return Value3.Clean(schema, value);
2332
- } catch {
2333
- return value;
2334
- }
2335
2350
  }
2336
2351
  return value;
2337
2352
  }, getSchemaValidator = (s, {
@@ -2403,7 +2418,18 @@ var hasProperty = (expectedProperty, _schema) => {
2403
2418
  })
2404
2419
  ]), schema.type === "object" && hasAdditional && (schema.additionalProperties = !1));
2405
2420
  } else
2406
- schema.type === "object" && !("additionalProperties" in schema) && (schema.additionalProperties = additionalProperties);
2421
+ schema.type === "object" && !("additionalProperties" in schema) ? schema.additionalProperties = additionalProperties : schema = replaceSchemaType(schema, {
2422
+ onlyFirstObject: !0,
2423
+ from: t.Object({}),
2424
+ // @ts-ignore
2425
+ to({ properties, ...options }) {
2426
+ if (properties && !("additionalProperties" in schema))
2427
+ return t.Object(properties, {
2428
+ ...options,
2429
+ additionalProperties: !1
2430
+ });
2431
+ }
2432
+ });
2407
2433
  if (dynamic) {
2408
2434
  let validator = {
2409
2435
  schema,
@@ -3068,14 +3094,14 @@ var allocateIf = (value, condition) => condition ? value : "", createContext = (
3068
3094
  hasTrace && (fnLiteral += `const id=randomId()
3069
3095
  `);
3070
3096
  let isDynamic = /[:*]/.test(route.path), getQi = `const u=request.url,s=u.indexOf('/',${app.config.handler?.standardHostname ?? !0 ? 11 : 7}),qi=u.indexOf('?', s + 1)
3071
- `;
3072
- inference.query && (fnLiteral += getQi);
3073
- let getPath = inference.path ? isDynamic ? "get path(){" + (inference.query ? "" : getQi) + `if(qi===-1)return u.substring(s)
3097
+ `, needsQuery = inference.query || !!route.hooks.query || !!route.standaloneValidators?.find((x) => x.query);
3098
+ needsQuery && (fnLiteral += getQi);
3099
+ let getPath = inference.path ? isDynamic ? "get path(){" + (needsQuery ? "" : getQi) + `if(qi===-1)return u.substring(s)
3074
3100
  return u.substring(s,qi)
3075
3101
  },` : `path:'${route.path}',` : "";
3076
- fnLiteral += allocateIf("const c=", !isInline) + "{request,store," + allocateIf("qi,", inference.query) + allocateIf("params:request.params,", isDynamic) + getPath + allocateIf(
3102
+ fnLiteral += allocateIf("const c=", !isInline) + "{request,store," + allocateIf("qi,", needsQuery) + allocateIf("params:request.params,", isDynamic) + getPath + allocateIf(
3077
3103
  "url:request.url,",
3078
- hasTrace || inference.url || inference.query
3104
+ hasTrace || inference.url || needsQuery
3079
3105
  ) + "redirect,error:status,status,set:{headers:" + (isNotEmpty(defaultHeaders) ? "Object.assign({},app.setHeaders)" : "Object.create(null)") + ",status:200}", inference.server && (fnLiteral += ",get server(){return app.getServer()}"), hasTrace && (fnLiteral += ",[ELYSIA_REQUEST_ID]:id");
3080
3106
  {
3081
3107
  let decoratorsLiteral = "";
@@ -3099,8 +3125,10 @@ return u.substring(s,qi)
3099
3125
  );
3100
3126
  let fnLiteral = "const handler=data.handler,app=data.app,store=data.store,decorator=data.decorator,redirect=data.redirect,route=data.route,mapEarlyResponse=data.mapEarlyResponse," + allocateIf("randomId=data.randomId,", hasTrace) + allocateIf("ELYSIA_REQUEST_ID=data.ELYSIA_REQUEST_ID,", hasTrace) + allocateIf("ELYSIA_TRACE=data.ELYSIA_TRACE,", hasTrace) + allocateIf("trace=data.trace,", hasTrace) + allocateIf("hoc=data.hoc,", hasHoc) + `status=data.status
3101
3127
  `;
3102
- return app.event.request?.length && (fnLiteral += `const onRequest=app.event.request.map(x=>x.fn)
3103
- `), fnLiteral += `${app.event.request?.find(isAsync) ? "async" : ""} function map(request){`, hasTrace || inference.query || app.event.request?.length ? (fnLiteral += createContext(app, route, inference), fnLiteral += createOnRequestHandler(app), fnLiteral += "return handler(c)}") : fnLiteral += `return handler(${createContext(app, route, inference, !0)})}`, fnLiteral += createHoc(app), Function(
3128
+ app.event.request?.length && (fnLiteral += `const onRequest=app.event.request.map(x=>x.fn)
3129
+ `), fnLiteral += `${app.event.request?.find(isAsync) ? "async" : ""} function map(request){`;
3130
+ let needsQuery = inference.query || !!route.hooks.query || !!route.standaloneValidators?.find((x) => x.query);
3131
+ return hasTrace || needsQuery ? (fnLiteral += createContext(app, route, inference), fnLiteral += createOnRequestHandler(app), fnLiteral += "return handler(c)}") : fnLiteral += `return handler(${createContext(app, route, inference, !0)})}`, fnLiteral += createHoc(app), Function(
3104
3132
  "data",
3105
3133
  fnLiteral
3106
3134
  )({
@@ -3133,7 +3161,7 @@ var createNativeStaticHandler = (handle, hooks, setHeaders = {}) => {
3133
3161
  return response instanceof Promise ? response.then((response2) => {
3134
3162
  if (response2)
3135
3163
  return response2.headers.has("content-type") || response2.headers.append("content-type", "text/plain"), response2.clone();
3136
- }) : (response.headers.has("content-type") || response.headers.append("content-type", "text/plain"), response.clone.bind(response));
3164
+ }) : (response.headers.has("content-type") || response.headers.append("content-type", "text/plain"), () => response.clone());
3137
3165
  };
3138
3166
 
3139
3167
  // src/ws/index.ts
@@ -3374,12 +3402,12 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
3374
3402
  if (value instanceof Promise) {
3375
3403
  withAsync && (staticRoutes[path] || (staticRoutes[path] = {}), ops.push(
3376
3404
  value.then((awaited) => {
3377
- awaited instanceof Response && (staticRoutes[path][method] = awaited);
3405
+ awaited instanceof Response && (staticRoutes[path][method] = awaited), typeof awaited == "object" && awaited?.toString() === "[object HTMLBundle]" && (staticRoutes[path][method] = awaited);
3378
3406
  })
3379
3407
  ));
3380
3408
  continue;
3381
3409
  }
3382
- value instanceof Response && (staticRoutes[path] || (staticRoutes[path] = {}), staticRoutes[path][method] = value);
3410
+ !(value instanceof Response) && !(typeof value == "object" && value?.toString() === "[object HTMLBundle]") || (staticRoutes[path] || (staticRoutes[path] = {}), staticRoutes[path][method] = value);
3383
3411
  }
3384
3412
  } else {
3385
3413
  if (!route) continue;
@@ -3414,7 +3442,6 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
3414
3442
  ...websocket || {}
3415
3443
  },
3416
3444
  fetch: app.fetch
3417
- // error: outerErrorHandler
3418
3445
  } : {
3419
3446
  development: !isProduction,
3420
3447
  reusePort: !0,
@@ -3434,7 +3461,6 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
3434
3461
  },
3435
3462
  port: options,
3436
3463
  fetch: app.fetch
3437
- // error: outerErrorHandler
3438
3464
  };
3439
3465
  if (app.server = Bun.serve(serve), app.event.start)
3440
3466
  for (let i = 0; i < app.event.start.length; i++)
@@ -3462,6 +3488,15 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
3462
3488
  });
3463
3489
  };
3464
3490
  },
3491
+ async stop(app, closeActiveConnections) {
3492
+ if (!app.server)
3493
+ throw new Error(
3494
+ "Elysia isn't running. Call `app.listen` to start the server."
3495
+ );
3496
+ if (app.server && (app.server.stop(closeActiveConnections), app.server = null, app.event.stop?.length))
3497
+ for (let i = 0; i < app.event.stop.length; i++)
3498
+ app.event.stop[i].fn(app);
3499
+ },
3465
3500
  ws(app, path, options) {
3466
3501
  let { parse: parse2, body, response, ...rest } = options, validateMessage = getSchemaValidator(body, {
3467
3502
  // @ts-expect-error private property
@@ -3497,8 +3532,13 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
3497
3532
  new Headers(set2.headers),
3498
3533
  set2.headers["set-cookie"]
3499
3534
  ));
3500
- let handleResponse3 = createHandleWSResponse(validateResponse), parseMessage = createWSMessageParser(parse2), _id, errorHandlers = [
3501
- ...Array.isArray(options.error) ? options.error : [options.error],
3535
+ let handleResponse3 = createHandleWSResponse(validateResponse), parseMessage = createWSMessageParser(parse2), _id;
3536
+ if (typeof options.beforeHandle == "function") {
3537
+ let result = options.beforeHandle(context);
3538
+ result instanceof Promise && await result;
3539
+ }
3540
+ let errorHandlers = [
3541
+ ...options.error ? Array.isArray(options.error) ? options.error : [options.error] : [],
3502
3542
  ...(app.event.error ?? []).map(
3503
3543
  (x) => typeof x == "function" ? x : x.fn
3504
3544
  )
@@ -3525,9 +3565,9 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
3525
3565
  pong(data) {
3526
3566
  options.pong?.(data);
3527
3567
  },
3528
- open(ws) {
3568
+ open: async (ws) => {
3529
3569
  try {
3530
- handleResponse3(
3570
+ await handleResponse3(
3531
3571
  ws,
3532
3572
  options.open?.(
3533
3573
  new ElysiaWS(ws, context)
@@ -3548,7 +3588,7 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
3548
3588
  ).message
3549
3589
  );
3550
3590
  try {
3551
- handleResponse3(
3591
+ await handleResponse3(
3552
3592
  ws,
3553
3593
  options.message?.(
3554
3594
  new ElysiaWS(
@@ -3563,9 +3603,9 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
3563
3603
  handleErrors(ws, error);
3564
3604
  }
3565
3605
  },
3566
- drain(ws) {
3606
+ drain: async (ws) => {
3567
3607
  try {
3568
- handleResponse3(
3608
+ await handleResponse3(
3569
3609
  ws,
3570
3610
  options.drain?.(
3571
3611
  new ElysiaWS(ws, context)
@@ -3575,9 +3615,9 @@ for(const [k,v] of c.request.headers.entries())c.headers[k]=v
3575
3615
  handleErrors(ws, error);
3576
3616
  }
3577
3617
  },
3578
- close(ws, code, reason) {
3618
+ close: async (ws, code, reason) => {
3579
3619
  try {
3580
- handleResponse3(
3620
+ await handleResponse3(
3581
3621
  ws,
3582
3622
  options.close?.(
3583
3623
  new ElysiaWS(ws, context),
@@ -7,6 +7,21 @@ import type { AnyWSLocalHook } from '../ws/types';
7
7
  export interface ElysiaAdapter {
8
8
  name: string;
9
9
  listen(app: AnyElysia): (options: string | number | Partial<Serve>, callback?: ListenCallback) => void;
10
+ /**
11
+ * Stop server from serving
12
+ *
13
+ * ---
14
+ * @example
15
+ * ```typescript
16
+ * app.stop()
17
+ * ```
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * app.stop(true) // Abruptly any requests inflight
22
+ * ```
23
+ */
24
+ stop(app: AnyElysia, closeActiveConnections?: boolean): Promise<void>;
10
25
  isWebStandard?: boolean;
11
26
  handler: {
12
27
  /**
@@ -918,6 +918,15 @@ else c.body[key]=value}`;
918
918
  }
919
919
  }
920
920
  },
921
+ async stop(app, closeActiveConnections) {
922
+ if (!app.server)
923
+ throw new Error(
924
+ "Elysia isn't running. Call `app.listen` to start the server."
925
+ );
926
+ if (app.server && (app.server.stop(closeActiveConnections), app.server = null, app.event.stop?.length))
927
+ for (let i = 0; i < app.event.stop.length; i++)
928
+ app.event.stop[i].fn(app);
929
+ },
921
930
  composeGeneralHandler: {
922
931
  parameters: "r",
923
932
  createContext(app) {
@@ -161,7 +161,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
161
161
  * })
162
162
  * ```
163
163
  */
164
- onRequest<const Schema extends RouteSchema>(handler: MaybeArray<PreHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>>, {
164
+ onRequest<const Schema extends RouteSchema>(handler: MaybeArray<PreHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], {
165
165
  decorator: Singleton['decorator'];
166
166
  store: Singleton['store'];
167
167
  derive: {};
@@ -186,7 +186,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
186
186
  * })
187
187
  * ```
188
188
  */
189
- onParse<const Schema extends RouteSchema>(parser: MaybeArray<BodyHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath>, {
189
+ onParse<const Schema extends RouteSchema>(parser: MaybeArray<BodyHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], {
190
190
  decorator: Singleton['decorator'];
191
191
  store: Singleton['store'];
192
192
  derive: Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'];
@@ -213,7 +213,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
213
213
  */
214
214
  onParse<const Schema extends RouteSchema, const Type extends LifeCycleType>(options: {
215
215
  as?: Type;
216
- }, parser: MaybeArray<BodyHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & 'global' extends Type ? {
216
+ }, parser: MaybeArray<BodyHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'] & 'global' extends Type ? {
217
217
  params: Record<string, string>;
218
218
  } : 'scoped' extends Type ? {
219
219
  params: Record<string, string>;
@@ -253,7 +253,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
253
253
  * })
254
254
  * ```
255
255
  */
256
- parser<const Parser extends string, const Schema extends RouteSchema, const Handler extends BodyHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath>, {
256
+ parser<const Parser extends string, const Schema extends RouteSchema, const Handler extends BodyHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], {
257
257
  decorator: Singleton['decorator'];
258
258
  store: Singleton['store'];
259
259
  derive: Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'];
@@ -281,7 +281,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
281
281
  * })
282
282
  * ```
283
283
  */
284
- onTransform<const Schema extends RouteSchema>(handler: MaybeArray<TransformHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath>, {
284
+ onTransform<const Schema extends RouteSchema>(handler: MaybeArray<TransformHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], {
285
285
  decorator: Singleton['decorator'];
286
286
  store: Singleton['store'];
287
287
  derive: Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'];
@@ -303,7 +303,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
303
303
  */
304
304
  onTransform<const Schema extends RouteSchema, const Type extends LifeCycleType>(options: {
305
305
  as?: Type;
306
- }, handler: MaybeArray<TransformHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & 'global' extends Type ? {
306
+ }, handler: MaybeArray<TransformHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'] & 'global' extends Type ? {
307
307
  params: Record<string, string>;
308
308
  } : 'scoped' extends Type ? {
309
309
  params: Record<string, string>;
@@ -340,7 +340,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
340
340
  */
341
341
  resolve<const Resolver extends Record<string, unknown> | ElysiaCustomStatusResponse<any, any, any>, const Type extends LifeCycleType>(options: {
342
342
  as?: Type;
343
- }, resolver: (context: Prettify<Context<MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>, BasePath> & 'global' extends Type ? {
343
+ }, resolver: (context: Prettify<Context<MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'] & 'global' extends Type ? {
344
344
  params: Record<string, string>;
345
345
  } : 'scoped' extends Type ? {
346
346
  params: Record<string, string>;
@@ -384,7 +384,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
384
384
  * }
385
385
  * }))
386
386
  */
387
- resolve<const Resolver extends Record<string, unknown> | ElysiaCustomStatusResponse<any, any, any> | void>(resolver: (context: Prettify<Context<MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>, BasePath>, Singleton & {
387
+ resolve<const Resolver extends Record<string, unknown> | ElysiaCustomStatusResponse<any, any, any> | void>(resolver: (context: Prettify<Context<MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], Singleton & {
388
388
  derive: Ephemeral['derive'] & Volatile['derive'];
389
389
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
390
390
  }, BasePath>>) => MaybePromise<Resolver | void>): Elysia<BasePath, Singleton, Definitions, Metadata, Routes, Ephemeral, {
@@ -393,7 +393,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
393
393
  schema: Volatile['schema'];
394
394
  standaloneSchema: Volatile['standaloneSchema'];
395
395
  }>;
396
- mapResolve<const NewResolver extends Record<string, unknown> | ElysiaCustomStatusResponse<any, any, any>>(mapper: (context: Context<MergeSchema<Metadata['schema'], MergeSchema<Ephemeral['schema'], Volatile['schema']>>, Singleton & {
396
+ mapResolve<const NewResolver extends Record<string, unknown> | ElysiaCustomStatusResponse<any, any, any>>(mapper: (context: Context<MergeSchema<Metadata['schema'], MergeSchema<Ephemeral['schema'], Volatile['schema']>> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], Singleton & {
397
397
  derive: Ephemeral['derive'] & Volatile['derive'];
398
398
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
399
399
  }, BasePath>) => MaybePromise<NewResolver | void>): Elysia<BasePath, Singleton, Definitions, Metadata, Routes, Ephemeral, {
@@ -404,7 +404,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
404
404
  }>;
405
405
  mapResolve<const NewResolver extends Record<string, unknown> | ElysiaCustomStatusResponse<any, any, any>, const Type extends LifeCycleType>(options: {
406
406
  as?: Type;
407
- }, mapper: (context: Context<MergeSchema<Metadata['schema'], MergeSchema<Ephemeral['schema'], Volatile['schema']>>, Singleton & ('global' extends Type ? {
407
+ }, mapper: (context: Context<MergeSchema<Metadata['schema'], MergeSchema<Ephemeral['schema'], Volatile['schema']>> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], Singleton & ('global' extends Type ? {
408
408
  derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
409
409
  resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
410
410
  } : 'scoped' extends Type ? {
@@ -448,7 +448,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
448
448
  * })
449
449
  * ```
450
450
  */
451
- onBeforeHandle<const Schema extends RouteSchema>(handler: MaybeArray<OptionalHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath>, Singleton & {
451
+ onBeforeHandle<const Schema extends RouteSchema>(handler: MaybeArray<OptionalHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], Singleton & {
452
452
  derive: Ephemeral['derive'] & Volatile['derive'];
453
453
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
454
454
  }>>): this;
@@ -473,7 +473,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
473
473
  */
474
474
  onBeforeHandle<const Schema extends RouteSchema, const Type extends LifeCycleType>(options: {
475
475
  as?: Type;
476
- }, handler: MaybeArray<OptionalHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & 'global' extends Type ? {
476
+ }, handler: MaybeArray<OptionalHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'] & 'global' extends Type ? {
477
477
  params: Record<string, string>;
478
478
  } : 'scoped' extends Type ? {
479
479
  params: Record<string, string>;
@@ -503,7 +503,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
503
503
  * })
504
504
  * ```
505
505
  */
506
- onAfterHandle<const Schema extends RouteSchema>(handler: MaybeArray<AfterHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath>, Singleton & {
506
+ onAfterHandle<const Schema extends RouteSchema>(handler: MaybeArray<AfterHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], Singleton & {
507
507
  derive: Ephemeral['derive'] & Volatile['derive'];
508
508
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
509
509
  }>>): this;
@@ -525,7 +525,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
525
525
  */
526
526
  onAfterHandle<const Schema extends RouteSchema, const Type extends LifeCycleType>(options: {
527
527
  as?: LifeCycleType;
528
- }, handler: MaybeArray<OptionalHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & 'global' extends Type ? {
528
+ }, handler: MaybeArray<AfterHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'] & 'global' extends Type ? {
529
529
  params: Record<string, string>;
530
530
  } : 'scoped' extends Type ? {
531
531
  params: Record<string, string>;
@@ -555,7 +555,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
555
555
  * })
556
556
  * ```
557
557
  */
558
- mapResponse<const Schema extends RouteSchema>(handler: MaybeArray<MapResponse<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath>, Singleton & {
558
+ mapResponse<const Schema extends RouteSchema>(handler: MaybeArray<MapResponse<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], Singleton & {
559
559
  derive: Ephemeral['derive'] & Volatile['derive'];
560
560
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
561
561
  }>>): this;
@@ -577,7 +577,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
577
577
  */
578
578
  mapResponse<const Schema extends RouteSchema, Type extends LifeCycleType>(options: {
579
579
  as?: Type;
580
- }, handler: MaybeArray<MapResponse<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & 'global' extends Type ? {
580
+ }, handler: MaybeArray<MapResponse<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'] & 'global' extends Type ? {
581
581
  params: Record<string, string>;
582
582
  } : 'scoped' extends Type ? {
583
583
  params: Record<string, string>;
@@ -604,7 +604,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
604
604
  * })
605
605
  * ```
606
606
  */
607
- onAfterResponse<const Schema extends RouteSchema>(handler: MaybeArray<AfterResponseHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath>, Singleton & {
607
+ onAfterResponse<const Schema extends RouteSchema>(handler: MaybeArray<AfterResponseHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], Singleton & {
608
608
  derive: Ephemeral['derive'] & Volatile['derive'];
609
609
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
610
610
  }>>): this;
@@ -624,7 +624,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
624
624
  */
625
625
  onAfterResponse<const Schema extends RouteSchema, const Type extends LifeCycleType>(options: {
626
626
  as?: Type;
627
- }, handler: MaybeArray<AfterResponseHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & 'global' extends Type ? {
627
+ }, handler: MaybeArray<AfterResponseHandler<MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'] & 'global' extends Type ? {
628
628
  params: Record<string, string>;
629
629
  } : 'scoped' extends Type ? {
630
630
  params: Record<string, string>;
@@ -766,7 +766,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
766
766
  * })
767
767
  * ```
768
768
  */
769
- onError<const Schema extends RouteSchema>(handler: MaybeArray<ErrorHandler<Definitions['error'], MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>>, Singleton, Ephemeral, Volatile>>): this;
769
+ onError<const Schema extends RouteSchema>(handler: MaybeArray<ErrorHandler<Definitions['error'], MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], Singleton, Ephemeral, Volatile>>): this;
770
770
  /**
771
771
  * ### Error | Life cycle event
772
772
  * Called when error is thrown during processing request
@@ -783,7 +783,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
783
783
  */
784
784
  onError<const Schema extends RouteSchema, const Scope extends LifeCycleType>(options: {
785
785
  as?: Scope;
786
- }, handler: MaybeArray<ErrorHandler<Definitions['error'], MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>>, Scope extends 'global' ? {
786
+ }, handler: MaybeArray<ErrorHandler<Definitions['error'], MergeSchema<Schema, MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>>> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], Scope extends 'global' ? {
787
787
  store: Singleton['store'];
788
788
  decorator: Singleton['decorator'];
789
789
  derive: Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'];
@@ -894,7 +894,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
894
894
  macroFn: Metadata['macroFn'];
895
895
  parser: Metadata['parser'];
896
896
  }, {}, Ephemeral, Volatile>) => NewElysia): Elysia<BasePath, Singleton, Definitions, Metadata, Prettify<Routes & NewElysia['~Routes']>, Ephemeral, Volatile>;
897
- group<const Prefix extends string, const NewElysia extends AnyElysia, const Input extends InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], JoinPath<BasePath, Prefix>>, Metadata['schema']>, const Resolutions extends MaybeArray<ResolveHandler<Schema, Singleton & {
897
+ group<const Prefix extends string, const NewElysia extends AnyElysia, const Input extends InputSchema<keyof Definitions['typebox'] & string>, const Schema extends MergeSchema<UnwrapRoute<Input, Definitions['typebox'], JoinPath<BasePath, Prefix>>, Metadata['schema']> & Metadata['standaloneSchema'], const Resolutions extends MaybeArray<ResolveHandler<Schema, Singleton & {
898
898
  derive: Ephemeral['derive'] & Volatile['derive'];
899
899
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
900
900
  }>>>(prefix: Prefix, schema: LocalHook<Input, Schema, Singleton & {
@@ -1073,7 +1073,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
1073
1073
  }>>;
1074
1074
  private propagatePromiseModules;
1075
1075
  private _use;
1076
- macro<const NewMacro extends BaseMacroFn>(macro: (route: MacroManager<MergeSchema<Metadata['schema'], MergeSchema<Ephemeral['schema'], Volatile['schema']>>, Singleton & {
1076
+ macro<const NewMacro extends BaseMacroFn>(macro: (route: MacroManager<MergeSchema<Metadata['schema'], MergeSchema<Ephemeral['schema'], Volatile['schema']>> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], Singleton & {
1077
1077
  derive: Partial<Ephemeral['derive'] & Volatile['derive']>;
1078
1078
  resolve: Partial<Ephemeral['resolve'] & Volatile['resolve']>;
1079
1079
  }, Definitions['error']>) => NewMacro): Elysia<BasePath, Singleton, Definitions, {
@@ -1606,7 +1606,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
1606
1606
  * }
1607
1607
  * }))
1608
1608
  */
1609
- derive<const Derivative extends Record<string, unknown> | ElysiaCustomStatusResponse<any, any, any> | void>(transform: (context: Prettify<Context<MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>, BasePath>, Singleton & {
1609
+ derive<const Derivative extends Record<string, unknown> | ElysiaCustomStatusResponse<any, any, any> | void>(transform: (context: Prettify<Context<MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'], Singleton & {
1610
1610
  derive: Ephemeral['derive'] & Volatile['derive'];
1611
1611
  resolve: Ephemeral['resolve'] & Volatile['resolve'];
1612
1612
  }>>) => MaybePromise<Derivative>): Elysia<BasePath, Singleton, Definitions, Metadata, Routes, Ephemeral, {
@@ -1632,7 +1632,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
1632
1632
  */
1633
1633
  derive<const Derivative extends Record<string, unknown> | ElysiaCustomStatusResponse<any, any, any> | void, const Type extends LifeCycleType>(options: {
1634
1634
  as?: Type;
1635
- }, transform: (context: Prettify<Context<MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>, BasePath> & 'global' extends Type ? {
1635
+ }, transform: (context: Prettify<Context<MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>, BasePath> & Metadata['standaloneSchema'] & Ephemeral['standaloneSchema'] & Volatile['standaloneSchema'] & 'global' extends Type ? {
1636
1636
  params: Record<string, string>;
1637
1637
  } : 'scoped' extends Type ? {
1638
1638
  params: Record<string, string>;
@@ -1759,7 +1759,7 @@ export default class Elysia<const in out BasePath extends string = '', const in
1759
1759
  * Custom handle written by adapter
1760
1760
  */
1761
1761
  protected _handle?(...a: unknown[]): unknown;
1762
- protected handleError: (context: Partial<Context<MergeSchema<Metadata["schema"], MergeSchema<Ephemeral["schema"], Volatile["schema"]>>, Singleton & {
1762
+ protected handleError: (context: Partial<Context<MergeSchema<Metadata["schema"], MergeSchema<Ephemeral["schema"], Volatile["schema"]>> & Metadata["standaloneSchema"] & Ephemeral["standaloneSchema"] & Volatile["standaloneSchema"], Singleton & {
1763
1763
  derive: Ephemeral["derive"] & Volatile["derive"];
1764
1764
  resolve: Ephemeral["resolve"] & Volatile["resolve"];
1765
1765
  }, BasePath>> & {
@@ -1802,7 +1802,8 @@ export default class Elysia<const in out BasePath extends string = '', const in
1802
1802
  * app.stop(true) // Abruptly any requests inflight
1803
1803
  * ```
1804
1804
  */
1805
- stop: (closeActiveConnections?: boolean) => Promise<void>;
1805
+ stop: (closeActiveConnections?: boolean) => Promise<this>;
1806
+ [Symbol.dispose]: () => void;
1806
1807
  /**
1807
1808
  * Wait until all lazy loaded modules all load is fully
1808
1809
  */