Socket
Socket
Sign inDemoInstall

elysia

Package Overview
Dependencies
Maintainers
1
Versions
408
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elysia - npm Package Compare versions

Comparing version 0.4.0-exp-230322.2055 to 0.4.0-rc.0

8

dist/compose.js
import{parse as e}from"fast-querystring";import{createValidationError as r}from"./utils";import{mapEarlyResponse as t,mapResponse as a}from"./handler";import{mapErrorCode as s}from"./error";let n="AsyncFunction",o=e=>e.constructor.name===n;export const composeHandler=({method:c,hooks:l,validator:d,handler:i,handleError:f})=>{let p="try {\n",u="GET"!==c||i.constructor.name===n||l.parse.length||l.afterHandle.find(o)||l.beforeHandle.find(o)||l.transform.find(o);if(u){if(p+=`
let contentType = c.request.headers.get('content-type');
let contentType = c.request.headers.get('content-type');
if (contentType) {
const index = contentType.indexOf(';');
if (index !== -1) contentType = contentType.slice(0, index);
if(contentType.indexOf(';')) {
const index = contentType.indexOf(';');
if (index !== -1) contentType = contentType.slice(0, index);
}
`,l.parse.length){p+=`used = false

@@ -8,0 +10,0 @@ `;for(let e=0;e<l.parse.length;e++){let r=`bo${e}`;p+=`if(!c.request.bodyUsed) {

@@ -5,5 +5,5 @@ /// <reference types="bun-types" />

import type { Context } from './context';
import type { Handler, BeforeRequestHandler, TypedRoute, ElysiaInstance, ElysiaConfig, HTTPMethod, InternalRoute, BodyParser, ErrorHandler, TypedSchema, LocalHook, LocalHandler, LifeCycle, LifeCycleEvent, LifeCycleStore, VoidLifeCycle, AfterRequestHandler, IsAny, OverwritableTypeRoute, MergeSchema, ListenCallback, NoReturnHandler, MaybePromise, IsNever, MergeUnionObjects, TypedRouteToEden, TypedWSRouteToEden } from './types';
import type { ElysiaWSOptions, WSTypedSchema } from './ws';
import type { Handler, BeforeRequestHandler, TypedRoute, ElysiaInstance, ElysiaConfig, HTTPMethod, InternalRoute, BodyParser, ErrorHandler, TypedSchema, LocalHook, LocalHandler, LifeCycle, LifeCycleEvent, LifeCycleStore, VoidLifeCycle, AfterRequestHandler, IsAny, OverwritableTypeRoute, MergeSchema, ListenCallback, NoReturnHandler, MaybePromise, IsNever, MergeUnionObjects, TypedWSRouteToEden, UnwrapSchema, ExtractPath } from './types';
import { type TSchema } from '@sinclair/typebox';
import { ElysiaWSOptions, WSTypedSchema } from './ws';
import type { Permission } from '@elysiajs/fn';

@@ -54,4 +54,37 @@ export default class Elysia<Instance extends ElysiaInstance = ElysiaInstance> {

default: (elysia: Elysia<any>) => MaybePromise<Elysia<LazyLoadElysia>>;
}>): IsNever<LazyLoadElysia> extends false ? Elysia<LazyLoadElysia & Instance> : NewElysia extends Elysia<infer NewInstance> ? IsNever<NewInstance> extends true ? Elysia<Instance> : Elysia<NewInstance & Instance> : NewElysia extends Promise<Elysia<infer NewInstance>> ? Elysia<NewInstance & Instance> : this;
get<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
}>): IsNever<LazyLoadElysia> extends false ? Elysia<{
request: Instance['request'] & LazyLoadElysia['request'];
store: Instance['store'] & LazyLoadElysia['store'];
schema: Instance['schema'] & LazyLoadElysia['schema'];
meta: Instance['meta'] & LazyLoadElysia['meta'];
}> : NewElysia extends Elysia<infer NewInstance> ? IsNever<NewInstance> extends true ? Elysia<Instance> : Elysia<{
request: Instance['request'] & NewInstance['request'];
store: Instance['store'] & NewInstance['store'];
schema: Instance['schema'] & NewInstance['schema'];
meta: Instance['meta'] & NewInstance['meta'];
}> : NewElysia extends Promise<Elysia<infer NewInstance>> ? Elysia<{
request: Instance['request'] & NewInstance['request'];
store: Instance['store'] & NewInstance['store'];
schema: Instance['schema'] & NewInstance['schema'];
meta: Instance['meta'] & NewInstance['meta'];
}> : this;
if<Condition extends boolean, NewElysia extends MaybePromise<Elysia<any>> = Elysia<any>, Params extends Elysia = Elysia<any>, LazyLoadElysia extends never | ElysiaInstance = never>(condition: Condition, run: MaybePromise<(app: Params extends Elysia<infer ParamsInstance> ? IsAny<ParamsInstance> extends true ? this : Params : Params) => MaybePromise<NewElysia>> | Promise<{
default: (elysia: Elysia<any>) => MaybePromise<Elysia<LazyLoadElysia>>;
}>): IsNever<LazyLoadElysia> extends false ? Elysia<{
request: Instance['request'] & LazyLoadElysia['request'];
store: Instance['store'] & LazyLoadElysia['store'];
schema: Instance['schema'] & LazyLoadElysia['schema'];
meta: Instance['meta'] & LazyLoadElysia['meta'];
}> : NewElysia extends Elysia<infer NewInstance> ? IsNever<NewInstance> extends true ? Elysia<Instance> : Elysia<{
request: Instance['request'] & NewInstance['request'];
store: Instance['store'] & NewInstance['store'];
schema: Instance['schema'] & NewInstance['schema'];
meta: Instance['meta'] & NewInstance['meta'];
}> : NewElysia extends Promise<Elysia<infer NewInstance>> ? Elysia<{
request: Instance['request'] & NewInstance['request'];
store: Instance['store'] & NewInstance['store'];
schema: Instance['schema'] & NewInstance['schema'];
meta: Instance['meta'] & NewInstance['meta'];
}> : this;
get<Path extends string, Schema extends TypedSchema<Extract<keyof Instance['meta'][typeof DEFS], string>>, Handler extends LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
request: Instance['request'];

@@ -62,7 +95,17 @@ store: Instance['store'];

[path in Path]: {
[method in 'get']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path, ReturnType<Handler>>;
get: {
body: UnwrapSchema<Schema['body'], Instance['meta'][typeof DEFS]>;
headers: UnwrapSchema<Schema['headers'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
query: UnwrapSchema<Schema['query'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
params: UnwrapSchema<Schema['params'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Path>, string>;
response: Schema['response'] extends TSchema | string ? {
'200': UnwrapSchema<Schema['response'], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : Schema['response'] extends Record<string, TSchema | string> ? {
[key in keyof Schema['response']]: UnwrapSchema<Schema['response'][key], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : ReturnType<Handler>;
};
};
}>>;
}>;
post<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
post<Path extends string, Schema extends TypedSchema<Extract<keyof Instance['meta'][typeof DEFS], string>>, Handler extends LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
request: Instance['request'];

@@ -73,7 +116,17 @@ store: Instance['store'];

[path in Path]: {
[method in 'post']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path, ReturnType<Handler>>;
post: {
body: UnwrapSchema<Schema['body'], Instance['meta'][typeof DEFS]>;
headers: UnwrapSchema<Schema['headers'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
query: UnwrapSchema<Schema['query'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
params: UnwrapSchema<Schema['params'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Path>, string>;
response: Schema['response'] extends TSchema | string ? {
'200': UnwrapSchema<Schema['response'], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : Schema['response'] extends Record<string, TSchema | string> ? {
[key in keyof Schema['response']]: UnwrapSchema<Schema['response'][key], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : ReturnType<Handler>;
};
};
}>>;
}>;
put<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
put<Path extends string, Schema extends TypedSchema<Extract<keyof Instance['meta'][typeof DEFS], string>>, Handler extends LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
request: Instance['request'];

@@ -84,7 +137,17 @@ store: Instance['store'];

[path in Path]: {
[method in 'put']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path, ReturnType<Handler>>;
put: {
body: UnwrapSchema<Schema['body'], Instance['meta'][typeof DEFS]>;
headers: UnwrapSchema<Schema['headers'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
query: UnwrapSchema<Schema['query'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
params: UnwrapSchema<Schema['params'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Path>, string>;
response: Schema['response'] extends TSchema | string ? {
'200': UnwrapSchema<Schema['response'], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : Schema['response'] extends Record<string, TSchema | string> ? {
[key in keyof Schema['response']]: UnwrapSchema<Schema['response'][key], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : ReturnType<Handler>;
};
};
}>>;
}>;
patch<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
patch<Path extends string, Schema extends TypedSchema<Extract<keyof Instance['meta'][typeof DEFS], string>>, Handler extends LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
request: Instance['request'];

@@ -95,7 +158,17 @@ store: Instance['store'];

[path in Path]: {
[method in 'patch']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path, ReturnType<Handler>>;
patch: {
body: UnwrapSchema<Schema['body'], Instance['meta'][typeof DEFS]>;
headers: UnwrapSchema<Schema['headers'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
query: UnwrapSchema<Schema['query'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
params: UnwrapSchema<Schema['params'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Path>, string>;
response: Schema['response'] extends TSchema | string ? {
'200': UnwrapSchema<Schema['response'], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : Schema['response'] extends Record<string, TSchema | string> ? {
[key in keyof Schema['response']]: UnwrapSchema<Schema['response'][key], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : ReturnType<Handler>;
};
};
}>>;
}>;
delete<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
delete<Path extends string, Schema extends TypedSchema<Extract<keyof Instance['meta'][typeof DEFS], string>>, Handler extends LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
request: Instance['request'];

@@ -106,7 +179,17 @@ store: Instance['store'];

[path in Path]: {
[method in 'delete']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path, ReturnType<Handler>>;
delete: {
body: UnwrapSchema<Schema['body'], Instance['meta'][typeof DEFS]>;
headers: UnwrapSchema<Schema['headers'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
query: UnwrapSchema<Schema['query'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
params: UnwrapSchema<Schema['params'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Path>, string>;
response: Schema['response'] extends TSchema | string ? {
'200': UnwrapSchema<Schema['response'], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : Schema['response'] extends Record<string, TSchema | string> ? {
[key in keyof Schema['response']]: UnwrapSchema<Schema['response'][key], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : ReturnType<Handler>;
};
};
}>>;
}>;
options<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
options<Path extends string, Schema extends TypedSchema<Extract<keyof Instance['meta'][typeof DEFS], string>>, Handler extends LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
request: Instance['request'];

@@ -117,7 +200,17 @@ store: Instance['store'];

[path in Path]: {
[method in 'options']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path, ReturnType<Handler>>;
options: {
body: UnwrapSchema<Schema['body'], Instance['meta'][typeof DEFS]>;
headers: UnwrapSchema<Schema['headers'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
query: UnwrapSchema<Schema['query'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
params: UnwrapSchema<Schema['params'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Path>, string>;
response: Schema['response'] extends TSchema | string ? {
'200': UnwrapSchema<Schema['response'], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : Schema['response'] extends Record<string, TSchema | string> ? {
[key in keyof Schema['response']]: UnwrapSchema<Schema['response'][key], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : ReturnType<Handler>;
};
};
}>>;
}>;
all<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
all<Path extends string, Schema extends TypedSchema<Extract<keyof Instance['meta'][typeof DEFS], string>>, Handler extends LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
request: Instance['request'];

@@ -128,7 +221,17 @@ store: Instance['store'];

[path in Path]: {
[method in 'all']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path, ReturnType<Handler>>;
all: {
body: UnwrapSchema<Schema['body'], Instance['meta'][typeof DEFS]>;
headers: UnwrapSchema<Schema['headers'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
query: UnwrapSchema<Schema['query'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
params: UnwrapSchema<Schema['params'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Path>, string>;
response: Schema['response'] extends TSchema | string ? {
'200': UnwrapSchema<Schema['response'], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : Schema['response'] extends Record<string, TSchema | string> ? {
[key in keyof Schema['response']]: UnwrapSchema<Schema['response'][key], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : ReturnType<Handler>;
};
};
}>>;
}>;
head<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
head<Path extends string, Schema extends TypedSchema<Extract<keyof Instance['meta'][typeof DEFS], string>>, Handler extends LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
request: Instance['request'];

@@ -139,7 +242,17 @@ store: Instance['store'];

[path in Path]: {
[method in 'head']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path, ReturnType<Handler>>;
head: {
body: UnwrapSchema<Schema['body'], Instance['meta'][typeof DEFS]>;
headers: UnwrapSchema<Schema['headers'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
query: UnwrapSchema<Schema['query'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
params: UnwrapSchema<Schema['params'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Path>, string>;
response: Schema['response'] extends TSchema | string ? {
'200': UnwrapSchema<Schema['response'], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : Schema['response'] extends Record<string, TSchema | string> ? {
[key in keyof Schema['response']]: UnwrapSchema<Schema['response'][key], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : ReturnType<Handler>;
};
};
}>>;
}>;
trace<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
trace<Path extends string, Schema extends TypedSchema<Extract<keyof Instance['meta'][typeof DEFS], string>>, Handler extends LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
request: Instance['request'];

@@ -150,7 +263,17 @@ store: Instance['store'];

[path in Path]: {
[method in 'trace']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path, ReturnType<Handler>>;
trace: {
body: UnwrapSchema<Schema['body'], Instance['meta'][typeof DEFS]>;
headers: UnwrapSchema<Schema['headers'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
query: UnwrapSchema<Schema['query'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
params: UnwrapSchema<Schema['params'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Path>, string>;
response: Schema['response'] extends TSchema | string ? {
'200': UnwrapSchema<Schema['response'], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : Schema['response'] extends Record<string, TSchema | string> ? {
[key in keyof Schema['response']]: UnwrapSchema<Schema['response'][key], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : ReturnType<Handler>;
};
};
}>>;
}>;
connect<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Path extends string = string, Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
connect<Path extends string, Schema extends TypedSchema<Extract<keyof Instance['meta'][typeof DEFS], string>>, Handler extends LocalHandler<Schema, Instance, Path>>(path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{
request: Instance['request'];

@@ -161,3 +284,13 @@ store: Instance['store'];

[path in Path]: {
[method in 'connect']: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path, ReturnType<Handler>>;
connect: {
body: UnwrapSchema<Schema['body'], Instance['meta'][typeof DEFS]>;
headers: UnwrapSchema<Schema['headers'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
query: UnwrapSchema<Schema['query'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
params: UnwrapSchema<Schema['params'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Path>, string>;
response: Schema['response'] extends TSchema | string ? {
'200': UnwrapSchema<Schema['response'], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : Schema['response'] extends Record<string, TSchema | string> ? {
[key in keyof Schema['response']]: UnwrapSchema<Schema['response'][key], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : ReturnType<Handler>;
};
};

@@ -180,3 +313,13 @@ }>>;

[path in Path]: {
[method in Uppercase<Method>]: TypedRouteToEden<Schema, Instance['meta'][typeof DEFS], Path, ReturnType<Handler>>;
[method in Method]: {
body: UnwrapSchema<Schema['body'], Instance['meta'][typeof DEFS]>;
headers: UnwrapSchema<Schema['headers'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
query: UnwrapSchema<Schema['query'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : undefined;
params: UnwrapSchema<Schema['params'], Instance['meta'][typeof DEFS]> extends infer Result ? Result extends Record<string, any> ? Result : undefined : Record<ExtractPath<Path>, string>;
response: Schema['response'] extends TSchema | string ? {
'200': UnwrapSchema<Schema['response'], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : Schema['response'] extends Record<string, TSchema | string> ? {
[key in keyof Schema['response']]: UnwrapSchema<Schema['response'][key], Instance['meta'][typeof DEFS], ReturnType<Handler>>;
} : ReturnType<Handler>;
};
};

@@ -183,0 +326,0 @@ }>>;

@@ -1,1 +0,1 @@

import{nanoid as e}from"nanoid";import{Raikiri as t}from"raikiri";import{parse as r}from"fast-querystring";import{mapResponse as s,mapEarlyResponse as a}from"./handler";import{SCHEMA as n,EXPOSED as h,DEFS as i,clone as o,mergeHook as u,getSchemaValidator as d,getResponseSchemaValidator as l,mapPathnameAndQueryRegEx as m}from"./utils";import{registerSchemaPath as c}from"./schema";import{mapErrorCode as p,mapErrorStatus as f}from"./error";import{composeHandler as v}from"./compose";export default class g{config;store={};meta={[n]:Object.create(null),[i]:Object.create(null),[h]:Object.create(null)};decorators={[n]:this.meta[n],[i]:this.meta[i],store:this.store};event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],error:[],stop:[]};server=null;$schema=null;router=new t;routes=[];wsRouter;lazyLoadModules=[];constructor(e){this.config={fn:"/~fn",...e}}_addHandler(e,t,r,s){t=t.startsWith("/")?t:`/${t}`,this.routes.push({method:e,path:t,handler:r,hooks:u(o(this.event),s)});let a=this.meta[i],h=d(s?.schema?.body??this.$schema?.body,a),m=d(s?.schema?.headers??this.$schema?.headers,a,!0),p=d(s?.schema?.params??this.$schema?.params,a),f=d(s?.schema?.query??this.$schema?.query,a),g=l(s?.schema?.response??this.$schema?.response,a);c({schema:this.meta[n],contentType:s?.schema?.contentType,hook:s,method:e,path:t,models:this.meta[i]});let y=u(o(this.event),s),b={handle:v({method:e,hooks:y,validator:{body:h,headers:m,params:p,query:f,response:g},handler:r,handleError:this.handleError}),onError:y.error};this.router.add(e,t,b)}onStart(e){return this.event.start.push(e),this}onRequest(e){return this.event.request.push(e),this}onParse(e){return this.event.parse.splice(this.event.parse.length-1,0,e),this}onTransform(e){return this.event.transform.push(e),this}onBeforeHandle(e){return this.event.beforeHandle.push(e),this}onAfterHandle(e){return this.event.afterHandle.push(e),this}onError(e){return this.event.error.push(e),this}onStop(e){return this.event.stop.push(e),this}on(e,t){switch(e){case"start":this.event.start.push(t);break;case"request":this.event.request.push(t);break;case"parse":this.event.parse.push(t);break;case"transform":this.event.transform.push(t);break;case"beforeHandle":this.event.beforeHandle.push(t);break;case"afterHandle":this.event.afterHandle.push(t);break;case"error":this.event.error.push(t);break;case"stop":this.event.stop.push(t)}return this}group(e,t){let r=new g;r.store=this.store;let s=t(r);return s.event.request.length&&(this.event.request=[...this.event.request,...s.event.request]),this.setModel(s.meta[i]),Object.values(r.routes).forEach(({method:t,path:r,handler:a,hooks:n})=>{"/"===r?this._addHandler(t,e,a,u(n,{error:s.event.error})):this._addHandler(t,`${e}${r}`,a,u(n,{error:s.event.error}))}),this}guard(e,t){let r=new g;r.store=this.store;let s=t(r);return s.event.request.length&&(this.event.request=[...this.event.request,...s.event.request]),this.setModel(s.meta[i]),Object.values(r.routes).forEach(({method:t,path:r,handler:s,hooks:a})=>{this._addHandler(t,r,s,u(e,a))}),this}use(e){if(e instanceof Promise)return this.lazyLoadModules.push(e.then(e=>"function"==typeof e?e(this):e.default(this))),this;let t=e(this);return t instanceof Promise?(this.lazyLoadModules.push(t),this):t}get(e,t,r){return this._addHandler("GET",e,t,r),this}post(e,t,r){return this._addHandler("POST",e,t,r),this}put(e,t,r){return this._addHandler("PUT",e,t,r),this}patch(e,t,r){return this._addHandler("PATCH",e,t,r),this}delete(e,t,r){return this._addHandler("DELETE",e,t,r),this}options(e,t,r){return this._addHandler("OPTIONS",e,t,r),this}all(e,t,r){return this._addHandler("ALL",e,t,r),this}head(e,t,r){return this._addHandler("HEAD",e,t,r),this}trace(e,t,r){return this._addHandler("TRACE",e,t,r),this}connect(e,t,r){return this._addHandler("CONNECT",e,t,r),this}ws(t,r){if(!this.wsRouter)throw Error("Can't find WebSocket. Please register WebSocket plugin first by importing 'elysia/ws'");return this.wsRouter.add("subscribe",t,r),this.get(t,t=>{if(!this.server.upgrade(t.request,{headers:"function"==typeof r.headers?r.headers(t):r.headers,data:{...t,id:e(),message:d(r.schema?.body,this.meta[i]),transformMessage:r.transform?Array.isArray(r.transformMessage)?r.transformMessage:[r.transformMessage]:[]}}))return t.set.status=400,"Expected a websocket connection"},{beforeHandle:r.beforeHandle,transform:r.transform,schema:{headers:r.schema?.headers,params:r.schema?.params,query:r.schema?.query}}),this}route(e,t,r,s){return this._addHandler(e,t,r,s),this}state(e,t){return e in this.store||(this.store[e]=t),this}decorate(e,t){return e in this.decorators||(this.decorators[e]=t),this}derive(e){return"AsyncFunction"===e.constructor.name?this.onTransform(async t=>{Object.assign(t,await e(t))}):this.onTransform(t=>{Object.assign(t,e(t))})}fn(e){return this.use(async()=>{let{fn:t}=await import("@elysiajs/fn");return t({app:this,value:e,path:this.config.fn})})}schema(e){let t=this.meta[i];return this.$schema={body:d(e.body,t),headers:d(e?.headers,t,!0),params:d(e?.params,t),query:d(e?.query,t),response:d(e?.response,t)},this}handle=async e=>this.innerHandle(e);innerHandle=e=>{let t=this.decorators;if(t.request=e,t.set={status:200,headers:{}},this.event.request.length)try{for(let e=0;e<this.event.request.length;e++){let r=a(this.event.request[e](t),t.set);if(r)return r}}catch(r){return this.handleError(e,r,t.set)}let s=e.url.match(m),n=this.router.match(e.method,s[1])??this.router.match("ALL",s[1]);return n?(t.params=n.params,s[2]?t.query=r(s[2]):t.query={},n.store.handle(t)):this.handleError(e,Error("NOT_FOUND"),t.set)};handleError=async(e,t,r={headers:{}})=>{for(let a=0;a<this.event.error.length;a++){let n=this.event.error[a]({request:e,code:p(t.message),error:t,set:r});if(n instanceof Promise&&(n=await n),null!=n)return s(n,r)}return new Response("string"==typeof t.cause?t.cause:t.message,{headers:r.headers,status:f(p(t.message))})};listen=(e,t)=>{if(!Bun)throw Error("Bun to run");if("string"==typeof e&&Number.isNaN(e=+e))throw Error("Port must be a numeric value");let r=this.innerHandle,s="object"==typeof e?{...this.config.serve,...e,fetch:r}:{...this.config.serve,port:e,fetch:r},a=`$$Elysia:${s.port}`;globalThis[a]?(this.server=globalThis[a],this.server.reload(s)):globalThis[a]=this.server=Bun.serve(s);for(let e=0;e<this.event.start.length;e++)this.event.start[e](this);return t&&t(this.server),Promise.all(this.lazyLoadModules).then(()=>{this.server.pendingRequests||Bun.gc(!0)}),this};stop=async()=>{if(!this.server)throw Error("Elysia isn't running. Call `app.listen` to start the server.");this.server.stop();for(let e=0;e<this.event.stop.length;e++)await this.event.stop[e](this)};get modules(){return Promise.all(this.lazyLoadModules)}setModel(e){return Object.entries(e).forEach(([e,t])=>{e in this.meta[i]||(this.meta[i][e]=t)}),this}}export{t}from"./custom-types";export{ws}from"./ws";export{SCHEMA,DEFS,EXPOSED,createValidationError,getSchemaValidator,mergeDeep,mergeHook,mergeObjectArray,mapPathnameAndQueryRegEx}from"./utils";export{g as Elysia};
import{nanoid as e}from"nanoid";import{Raikiri as t}from"raikiri";import{parse as r}from"fast-querystring";import{mapResponse as s,mapEarlyResponse as a}from"./handler";import{SCHEMA as h,EXPOSED as n,DEFS as i,clone as o,mergeHook as u,getSchemaValidator as d,getResponseSchemaValidator as l,mapPathnameAndQueryRegEx as c}from"./utils";import{registerSchemaPath as m}from"./schema";import{mapErrorCode as p,mapErrorStatus as f}from"./error";import{composeHandler as v}from"./compose";import{ws as y}from"./ws";export default class g{config;store={};meta={[h]:Object.create(null),[i]:Object.create(null),[n]:Object.create(null)};decorators={[h]:this.meta[h],[i]:this.meta[i],store:this.store};event={start:[],request:[],parse:[],transform:[],beforeHandle:[],afterHandle:[],error:[],stop:[]};server=null;$schema=null;router=new t;routes=[];wsRouter;lazyLoadModules=[];constructor(e){this.config={fn:"/~fn",...e}}_addHandler(e,t,r,s){t=t.startsWith("/")?t:`/${t}`,this.routes.push({method:e,path:t,handler:r,hooks:u({...this.event},s)});let a=this.meta[i],n=d(s?.schema?.body??this.$schema?.body,a),c=d(s?.schema?.headers??this.$schema?.headers,a,!0),p=d(s?.schema?.params??this.$schema?.params,a),f=d(s?.schema?.query??this.$schema?.query,a),y=l(s?.schema?.response??this.$schema?.response,a);m({schema:this.meta[h],contentType:s?.schema?.contentType,hook:s,method:e,path:t,models:this.meta[i]});let g=u(o(this.event),s),b={handle:v({method:e,hooks:g,validator:{body:n,headers:c,params:p,query:f,response:y},handler:r,handleError:this.handleError}),onError:g.error};this.router.add(e,t,b)}onStart(e){return this.event.start.push(e),this}onRequest(e){return this.event.request.push(e),this}onParse(e){return this.event.parse.splice(this.event.parse.length-1,0,e),this}onTransform(e){return this.event.transform.push(e),this}onBeforeHandle(e){return this.event.beforeHandle.push(e),this}onAfterHandle(e){return this.event.afterHandle.push(e),this}onError(e){return this.event.error.push(e),this}onStop(e){return this.event.stop.push(e),this}on(e,t){switch(e){case"start":this.event.start.push(t);break;case"request":this.event.request.push(t);break;case"parse":this.event.parse.push(t);break;case"transform":this.event.transform.push(t);break;case"beforeHandle":this.event.beforeHandle.push(t);break;case"afterHandle":this.event.afterHandle.push(t);break;case"error":this.event.error.push(t);break;case"stop":this.event.stop.push(t)}return this}group(e,t){let r=new g;r.store=this.store,this.wsRouter&&r.use(y());let s=t(r);return s.event.request.length&&(this.event.request=[...this.event.request,...s.event.request]),this.setModel(s.meta[i]),Object.values(r.routes).forEach(({method:t,path:a,handler:h,hooks:n})=>{let i="/"===a?e:`${e}${a}`,o=r.wsRouter?.match("subscribe",i);if(o){let e=r.wsRouter.history.find(([e,t])=>a===t);if(!e)return;return this.ws(i,e[2])}this._addHandler(t,i,h,u(n,{error:s.event.error}))}),r.wsRouter&&this.wsRouter&&r.wsRouter.history.forEach(([t,r,s])=>{"/"===r?this.wsRouter?.add(t,e,s):this.wsRouter?.add(t,`${e}${r}`,s)}),this}guard(e,t){let r=new g;r.store=this.store,this.wsRouter&&r.use(y());let s=t(r);return s.event.request.length&&(this.event.request=[...this.event.request,...s.event.request]),this.setModel(s.meta[i]),Object.values(r.routes).forEach(({method:t,path:s,handler:a,hooks:h})=>{let n=r.wsRouter?.match("subscribe",s);if(n){let e=r.wsRouter.history.find(([e,t])=>s===t);if(!e)return;return this.ws(s,e[2])}this._addHandler(t,s,a,u(e,h))}),r.wsRouter&&this.wsRouter&&r.wsRouter.history.forEach(([e,t,r])=>{this.wsRouter?.add(e,t,r)}),this}use(e){if(e instanceof Promise)return this.lazyLoadModules.push(e.then(e=>"function"==typeof e?e(this):e.default(this))),this;let t=e(this);return t instanceof Promise?(this.lazyLoadModules.push(t),this):t}if(e,t){return e?this.use(t):this}get(e,t,r){return this._addHandler("GET",e,t,r),this}post(e,t,r){return this._addHandler("POST",e,t,r),this}put(e,t,r){return this._addHandler("PUT",e,t,r),this}patch(e,t,r){return this._addHandler("PATCH",e,t,r),this}delete(e,t,r){return this._addHandler("DELETE",e,t,r),this}options(e,t,r){return this._addHandler("OPTIONS",e,t,r),this}all(e,t,r){return this._addHandler("ALL",e,t,r),this}head(e,t,r){return this._addHandler("HEAD",e,t,r),this}trace(e,t,r){return this._addHandler("TRACE",e,t,r),this}connect(e,t,r){return this._addHandler("CONNECT",e,t,r),this}ws(t,r){if(!this.wsRouter)throw Error("Can't find WebSocket. Please register WebSocket plugin first by importing 'elysia/ws'");return this.wsRouter.add("subscribe",t,r),this.get(t,t=>{if(console.log("Got",t.request.url),!this.server?.upgrade(t.request,{headers:"function"==typeof r.headers?r.headers(t):r.headers,data:{...t,id:e(),message:d(r.schema?.body,this.meta[i]),transformMessage:r.transform?Array.isArray(r.transformMessage)?r.transformMessage:[r.transformMessage]:[]}}))return t.set.status=400,"Expected a websocket connection"},{beforeHandle:r.beforeHandle,transform:r.transform,schema:{headers:r.schema?.headers,params:r.schema?.params,query:r.schema?.query}}),this}route(e,t,r,s){return this._addHandler(e,t,r,s),this}state(e,t){return e in this.store||(this.store[e]=t),this}decorate(e,t){return e in this.decorators||(this.decorators[e]=t),this}derive(e){return"AsyncFunction"===e.constructor.name?this.onTransform(async t=>{Object.assign(t,await e(t))}):this.onTransform(t=>{Object.assign(t,e(t))})}fn(e){return this.use(async()=>{let{fn:t}=await import("@elysiajs/fn");return t({app:this,value:e,path:this.config.fn})})}schema(e){let t=this.meta[i];return this.$schema={body:d(e.body,t),headers:d(e?.headers,t,!0),params:d(e?.params,t),query:d(e?.query,t),response:d(e?.response,t)},this}handle=async e=>this.innerHandle(e);innerHandle=e=>{let t=this.decorators;if(t.request=e,t.set={status:200,headers:{}},this.event.request.length)try{for(let e=0;e<this.event.request.length;e++){let r=a(this.event.request[e](t),t.set);if(r)return r}}catch(r){return this.handleError(e,r,t.set)}let s=e.url.match(c),h=this.router.match(e.method,s[1])??this.router.match("ALL",s[1]);return h?(t.params=h.params,s[2]?t.query=r(s[2]):t.query={},h.store.handle(t)):this.handleError(e,Error("NOT_FOUND"),t.set)};handleError=async(e,t,r={headers:{}})=>{for(let a=0;a<this.event.error.length;a++){let h=this.event.error[a]({request:e,code:p(t.message),error:t,set:r});if(h instanceof Promise&&(h=await h),null!=h)return s(h,r)}return new Response("string"==typeof t.cause?t.cause:t.message,{headers:r.headers,status:f(p(t.message))})};listen=(e,t)=>{if(!Bun)throw Error("Bun to run");if("string"==typeof e&&Number.isNaN(e=+e))throw Error("Port must be a numeric value");let r=this.innerHandle,s="object"==typeof e?{...this.config.serve,...e,fetch:r}:{...this.config.serve,port:e,fetch:r},a=`$$Elysia:${s.port}`;globalThis[a]?(this.server=globalThis[a],this.server.reload(s)):globalThis[a]=this.server=Bun.serve(s);for(let e=0;e<this.event.start.length;e++)this.event.start[e](this);return t&&t(this.server),Promise.all(this.lazyLoadModules).then(()=>{this.server.pendingRequests||Bun.gc(!0)}),this};stop=async()=>{if(!this.server)throw Error("Elysia isn't running. Call `app.listen` to start the server.");this.server.stop();for(let e=0;e<this.event.stop.length;e++)await this.event.stop[e](this)};get modules(){return Promise.all(this.lazyLoadModules)}setModel(e){return Object.entries(e).forEach(([e,t])=>{e in this.meta[i]||(this.meta[i][e]=t)}),this}}export{t}from"./custom-types";export{ws}from"./ws";export{SCHEMA,DEFS,EXPOSED,createValidationError,getSchemaValidator,mergeDeep,mergeHook,mergeObjectArray,mapPathnameAndQueryRegEx}from"./utils";export{g as Elysia};

@@ -12,3 +12,3 @@ import { type TSchema } from '@sinclair/typebox';

hook?: LocalHook<import("./types").TypedSchema<string>, import("./types").ElysiaInstance<{
store: Record<string, unknown>;
store: {};
request: {};

@@ -15,0 +15,0 @@ schema: {};

@@ -1,1 +0,1 @@

import{Kind as e}from"@sinclair/typebox";export const toOpenAPIPath=e=>e.split("/").map(e=>e.startsWith(":")?`{${e.slice(1,e.length)}}`:e).join("/");export const mapProperties=(e,t,r)=>{if(void 0===t)return[];if("string"==typeof t){if(t in r)t=r[t];else throw Error(`Can't find model ${t}`)}return Object.entries(t?.properties??[]).map(([r,o])=>({...o,in:e,name:r,type:o?.type,required:t.required?.includes(r)??!1}))};let t=(e,t)=>{let r={};for(let o of e)r[o]={schema:"string"==typeof t?{$ref:`#/components/schemas/${t}`}:{...t}};return r};export const registerSchemaPath=({schema:r,contentType:o=["application/json","multipart/form-data","text/plain"],path:s,method:i,hook:n,models:p})=>{s=toOpenAPIPath(s);let a="string"==typeof o?[o]:o??["application/json"],c=n?.schema?.body,l=n?.schema?.params,m=n?.schema?.headers,f=n?.schema?.query,h=n?.schema?.response;if("object"==typeof h){if(e in h){let{type:e,properties:r,required:o,...s}=h;h={200:{...s,description:s.description,content:t(a,"object"===e||"array"===e?{type:e,properties:r,required:o}:h)}}}else Object.entries(h).forEach(([e,r])=>{if("string"==typeof r){let{type:o,properties:s,required:i,...n}=p[r];h[e]={...n,description:n.description,content:t(a,r)}}else{let{type:o,properties:s,required:i,...n}=r;h[e]={...n,description:n.description,content:t(a,{type:o,properties:s,required:i})}}})}else if("string"==typeof h){let{type:e,properties:r,required:o,...s}=p[h];h={200:{...s,content:t(a,h)}}}let d=[...mapProperties("header",m,p),...mapProperties("path",l,p),...mapProperties("query",f,p)];r[s]={...r[s]?r[s]:{},[i.toLowerCase()]:{...m||l||f||c?{parameters:d}:{},...h?{responses:h}:{},...n?.schema?.detail,...c?{requestBody:{content:t(a,"string"==typeof c?{$ref:`#/components/schemas/${c}`}:c)}}:null}}};
import{Kind as e}from"@sinclair/typebox";import t from"lodash.clonedeep";export const toOpenAPIPath=e=>e.split("/").map(e=>e.startsWith(":")?`{${e.slice(1,e.length)}}`:e).join("/");export const mapProperties=(e,t,r)=>{if(void 0===t)return[];if("string"==typeof t){if(t in r)t=r[t];else throw Error(`Can't find model ${t}`)}return Object.entries(t?.properties??[]).map(([r,o])=>({...o,in:e,name:r,type:o?.type,required:t.required?.includes(r)??!1}))};let r=(e,t)=>{let r={};for(let o of e)r[o]={schema:"string"==typeof t?{$ref:`#/components/schemas/${t}`}:{...t}};return r};export const registerSchemaPath=({schema:o,contentType:s=["application/json","multipart/form-data","text/plain"],path:i,method:n,hook:p,models:a})=>{p&&(p=t(p)),i=toOpenAPIPath(i);let c="string"==typeof s?[s]:s??["application/json"],l=p?.schema?.body,m=p?.schema?.params,f=p?.schema?.headers,h=p?.schema?.query,d=p?.schema?.response;if("object"==typeof d){if(e in d){let{type:e,properties:t,required:o,...s}=d;d={200:{...s,description:s.description,content:r(c,"object"===e||"array"===e?{type:e,properties:t,required:o}:d)}}}else Object.entries(d).forEach(([e,t])=>{if("string"==typeof t){let{type:o,properties:s,required:i,...n}=a[t];d[e]={...n,description:n.description,content:r(c,t)}}else{let{type:o,properties:s,required:i,...n}=t;d[e]={...n,description:n.description,content:r(c,{type:o,properties:s,required:i})}}})}else if("string"==typeof d){let{type:e,properties:t,required:o,...s}=a[d];d={200:{...s,content:r(c,d)}}}let y=[...mapProperties("header",f,a),...mapProperties("path",m,a),...mapProperties("query",h,a)];o[i]={...o[i]?o[i]:{},[n.toLowerCase()]:{...f||m||h||l?{parameters:y}:{},...d?{responses:d}:{},...p?.schema?.detail,...l?{requestBody:{content:r(c,"string"==typeof l?{$ref:`#/components/schemas/${l}`}:l)}}:null}}};

@@ -11,5 +11,3 @@ /// <reference types="bun-types" />

export type ObjectValues<T extends object> = T[keyof T];
export type ElysiaDefaultMeta = Record<typeof SCHEMA, Partial<OpenAPIV3.PathsObject>> & Record<typeof DEFS, {
[x in string]: TSchema;
}> & Record<typeof EXPOSED, Record<string, Record<string, unknown>>>;
export type ElysiaDefaultMeta = Record<typeof SCHEMA, Partial<OpenAPIV3.PathsObject>> & Record<typeof DEFS, Record<string, TSchema>> & Record<typeof EXPOSED, Record<string, Record<string, unknown>>>;
export type ElysiaInstance<Instance extends {

@@ -19,5 +17,5 @@ store?: Record<string, unknown>;

schema?: TypedSchema;
meta?: ElysiaDefaultMeta;
meta?: Record<typeof SCHEMA, Partial<OpenAPIV3.PathsObject>> & Record<typeof DEFS, Record<string, TSchema>> & Record<typeof EXPOSED, Record<string, Record<string, unknown>>>;
} = {
store: Record<string, unknown>;
store: {};
request: {};

@@ -28,4 +26,4 @@ schema: {};

request: Instance['request'];
store: Instance['store'] extends undefined ? {} : Instance['store'];
schema: Instance['schema'] extends undefined ? TypedSchema : Instance['schema'];
store: Instance['store'];
schema: Instance['schema'];
meta: Instance['meta'];

@@ -76,5 +74,3 @@ };

}
export type UnwrapSchema<Schema extends TSchema | undefined | string, Definitions extends ElysiaInstance['meta'][typeof DEFS] = {}, Fallback = unknown> = Schema extends string ? Definitions extends {
[name in Schema]: infer NamedSchema extends TSchema;
} ? Static<NamedSchema> : Fallback : Schema extends TSchema ? Static<NonNullable<Schema>> : Fallback;
export type UnwrapSchema<Schema extends TSchema | undefined | string, Definitions extends ElysiaInstance['meta'][typeof DEFS] = {}, Fallback = unknown> = Schema extends string ? Definitions extends Record<Schema, infer NamedSchema extends TSchema> ? Static<NamedSchema> : Fallback : Schema extends TSchema ? Static<NonNullable<Schema>> : Fallback;
export type TypedSchemaToRoute<Schema extends TypedSchema<any>, Definitions extends ElysiaInstance['meta'][typeof DEFS]> = {

@@ -140,11 +136,15 @@ body: UnwrapSchema<Schema['body'], Definitions>;

};
export type TypedRouteToEden<Schema extends TypedSchema = TypedSchema, Definitions extends TypedSchema<string> = ElysiaInstance['meta'][typeof DEFS], Path extends string = string, Catch = unknown> = TypedSchemaToEden<Schema, Definitions> extends infer Typed extends AnyTypedSchema ? {
body: Typed['body'];
headers: Typed['headers'];
query: Typed['query'];
params: undefined extends Typed['params'] ? Record<ExtractPath<Path>, string> : Typed['params'];
response: undefined extends Typed['response'] ? {
'200': Catch;
} : Typed['response'];
} : never;
export type TypedRouteToEden<Schema extends TypedSchema = TypedSchema, Definitions extends TypedSchema<string> = ElysiaInstance['meta'][typeof DEFS], Path extends string = string, Catch = unknown> = {
body: UnwrapSchema<Schema['body'], Definitions>;
headers: UnwrapSchema<Schema['headers'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
query: UnwrapSchema<Schema['query'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
params: UnwrapSchema<Schema['params'], Definitions> extends infer Result extends Record<string, any> ? Result : Record<ExtractPath<Path>, string>;
response: Schema['response'] extends TSchema | string ? {
'200': UnwrapSchema<Schema['response'], Definitions, Catch>;
} : Schema['response'] extends {
[x in string]: TSchema | string;
} ? {
[key in keyof Schema['response']]: UnwrapSchema<Schema['response'][key], Definitions, Catch>;
} : Catch;
};
export type TypedWSRouteToEden<Schema extends TypedSchema = TypedSchema, Definitions extends TypedSchema<string> = ElysiaInstance['meta'][typeof DEFS], Path extends string = string, Catch = unknown> = TypedSchemaToEden<Schema, Definitions> extends infer Typed extends AnyTypedSchema ? {

@@ -151,0 +151,0 @@ body: Typed['body'];

@@ -21,3 +21,3 @@ /// <reference types="bun-types" />

export declare const ws: (config?: Omit<WebSocketHandler, 'open' | 'message' | 'close' | 'drain'>) => (app: Elysia) => Elysia<{
store: Record<string, unknown>;
store: {};
request: {

@@ -24,0 +24,0 @@ publish: (topic: string, data: string | ArrayBuffer | SharedArrayBuffer | import("bun").ArrayBufferView, compress?: boolean | undefined) => number;

{
"name": "elysia",
"description": "Fast, and friendly Bun web framework",
"version": "0.4.0-exp-230322.2055",
"version": "0.4.0-rc.0",
"type": "module",
"author": {

@@ -94,4 +95,6 @@ "name": "saltyAom",

"dependencies": {
"@types/lodash.clonedeep": "^4.5.7",
"@sinclair/typebox": "0.26.0",
"fast-querystring": "^1.1.1",
"lodash.clonedeep": "^4.5.0",
"nanoid": "^4.0.1",

@@ -98,0 +101,0 @@ "openapi-types": "^12.1.0",

@@ -43,7 +43,9 @@ import { parse as parseQuery } from 'fast-querystring'

fnLiteral += `
let contentType = c.request.headers.get('content-type');
let contentType = c.request.headers.get('content-type');
if (contentType) {
const index = contentType.indexOf(';');
if (index !== -1) contentType = contentType.slice(0, index);
if(contentType.indexOf(';')) {
const index = contentType.indexOf(';');
if (index !== -1) contentType = contentType.slice(0, index);
}
`

@@ -50,0 +52,0 @@

@@ -22,2 +22,7 @@ import type { Serve, Server } from 'bun'

import { composeHandler } from './compose'
import { ws } from './ws'
import type { ElysiaWSContext, ElysiaWSOptions, WSTypedSchema } from './ws'
import type {

@@ -53,7 +58,7 @@ Handler,

TypedRouteToEden,
TypedWSRouteToEden
TypedWSRouteToEden,
UnwrapSchema,
ExtractPath
} from './types'
import { type TSchema } from '@sinclair/typebox'
import { ElysiaWSContext, ElysiaWSOptions, WSTypedSchema } from './ws'
import { composeHandler } from './compose'

@@ -135,3 +140,3 @@ // @ts-ignore

handler,
hooks: mergeHook(clone(this.event), hook as RegisteredHook)
hooks: mergeHook({ ...this.event }, hook as RegisteredHook)
})

@@ -482,2 +487,4 @@

if (this.wsRouter) instance.use(ws())
const sandbox = run(instance)

@@ -494,24 +501,33 @@

Object.values(instance.routes).forEach(
({ method, path, handler, hooks }) => {
if (path === '/')
this._addHandler(
method,
prefix,
handler,
mergeHook(hooks, {
error: sandbox.event.error
})
({ method, path: originalPath, handler, hooks }) => {
const path =
originalPath === '/' ? prefix : `${prefix}${originalPath}`
const hasWsRoute = instance.wsRouter?.match('subscribe', path)
if (hasWsRoute) {
const wsRoute = instance.wsRouter!.history.find(
([_, wsPath]) => originalPath === wsPath
)
else
this._addHandler(
method,
`${prefix}${path}`,
handler,
mergeHook(hooks, {
error: sandbox.event.error
})
)
if (!wsRoute) return
return this.ws(path as any, wsRoute[2] as any)
}
this._addHandler(
method,
path,
handler,
mergeHook(hooks, {
error: sandbox.event.error
})
)
}
)
if (instance.wsRouter && this.wsRouter)
instance.wsRouter.history.forEach(([method, path, handler]) => {
if (path === '/') this.wsRouter?.add(method, prefix, handler)
else this.wsRouter?.add(method, `${prefix}${path}`, handler)
})
return this as any

@@ -562,4 +578,4 @@ }

const instance = new Elysia<any>()
instance.store = this.store
if (this.wsRouter) instance.use(ws())

@@ -578,2 +594,12 @@ const sandbox = run(instance)

({ method, path, handler, hooks: localHook }) => {
const hasWsRoute = instance.wsRouter?.match('subscribe', path)
if (hasWsRoute) {
const wsRoute = instance.wsRouter!.history.find(
([_, wsPath]) => path === wsPath
)
if (!wsRoute) return
return this.ws(path as any, wsRoute[2] as any)
}
this._addHandler(

@@ -588,2 +614,7 @@ method,

if (instance.wsRouter && this.wsRouter)
instance.wsRouter.history.forEach(([method, path, handler]) => {
this.wsRouter?.add(method, path, handler)
})
return this as any

@@ -627,9 +658,24 @@ }

): IsNever<LazyLoadElysia> extends false
? Elysia<LazyLoadElysia & Instance>
? Elysia<{
request: Instance['request'] & LazyLoadElysia['request']
store: Instance['store'] & LazyLoadElysia['store']
schema: Instance['schema'] & LazyLoadElysia['schema']
meta: Instance['meta'] & LazyLoadElysia['meta']
}>
: NewElysia extends Elysia<infer NewInstance>
? IsNever<NewInstance> extends true
? Elysia<Instance>
: Elysia<NewInstance & Instance>
: Elysia<{
request: Instance['request'] & NewInstance['request']
store: Instance['store'] & NewInstance['store']
schema: Instance['schema'] & NewInstance['schema']
meta: Instance['meta'] & NewInstance['meta']
}>
: NewElysia extends Promise<Elysia<infer NewInstance>>
? Elysia<NewInstance & Instance>
? Elysia<{
request: Instance['request'] & NewInstance['request']
store: Instance['store'] & NewInstance['store']
schema: Instance['schema'] & NewInstance['schema']
meta: Instance['meta'] & NewInstance['meta']
}>
: this {

@@ -661,2 +707,53 @@ if (plugin instanceof Promise) {

if<
Condition extends boolean,
NewElysia extends MaybePromise<Elysia<any>> = Elysia<any>,
Params extends Elysia = Elysia<any>,
LazyLoadElysia extends never | ElysiaInstance = never
>(
condition: Condition,
run:
| MaybePromise<
(
app: Params extends Elysia<infer ParamsInstance>
? IsAny<ParamsInstance> extends true
? this
: Params
: Params
) => MaybePromise<NewElysia>
>
| Promise<{
default: (
elysia: Elysia<any>
) => MaybePromise<Elysia<LazyLoadElysia>>
}>
): IsNever<LazyLoadElysia> extends false
? Elysia<{
request: Instance['request'] & LazyLoadElysia['request']
store: Instance['store'] & LazyLoadElysia['store']
schema: Instance['schema'] & LazyLoadElysia['schema']
meta: Instance['meta'] & LazyLoadElysia['meta']
}>
: NewElysia extends Elysia<infer NewInstance>
? IsNever<NewInstance> extends true
? Elysia<Instance>
: Elysia<{
request: Instance['request'] & NewInstance['request']
store: Instance['store'] & NewInstance['store']
schema: Instance['schema'] & NewInstance['schema']
meta: Instance['meta'] & NewInstance['meta']
}>
: NewElysia extends Promise<Elysia<infer NewInstance>>
? Elysia<{
request: Instance['request'] & NewInstance['request']
store: Instance['store'] & NewInstance['store']
schema: Instance['schema'] & NewInstance['schema']
meta: Instance['meta'] & NewInstance['meta']
}>
: this {
if (!condition) return this as any
return this.use(run) as any
}
/**

@@ -681,11 +778,7 @@ * ### get

get<
Path extends string,
Schema extends TypedSchema<
Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>
> = {},
Path extends string = string,
Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<
Schema,
Instance,
Path
>
Extract<keyof Instance['meta'][typeof DEFS], string>
>,
Handler extends LocalHandler<Schema, Instance, Path>
>(

@@ -706,8 +799,54 @@ path: Path,

[path in Path]: {
[method in 'get']: TypedRouteToEden<
Schema,
Instance['meta'][typeof DEFS],
Path,
ReturnType<Handler>
>
get: {
body: UnwrapSchema<
Schema['body'],
Instance['meta'][typeof DEFS]
>
headers: UnwrapSchema<
Schema['headers'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
query: UnwrapSchema<
Schema['query'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
params: UnwrapSchema<
Schema['params'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: Record<ExtractPath<Path>, string>
response: Schema['response'] extends
| TSchema
| string
? {
'200': UnwrapSchema<
Schema['response'],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: Schema['response'] extends Record<
string,
TSchema | string
>
? {
[key in keyof Schema['response']]: UnwrapSchema<
Schema['response'][key],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: ReturnType<Handler>
}
}

@@ -742,11 +881,7 @@ }

post<
Path extends string,
Schema extends TypedSchema<
Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>
> = {},
Path extends string = string,
Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<
Schema,
Instance,
Path
>
Extract<keyof Instance['meta'][typeof DEFS], string>
>,
Handler extends LocalHandler<Schema, Instance, Path>
>(

@@ -767,8 +902,54 @@ path: Path,

[path in Path]: {
[method in 'post']: TypedRouteToEden<
Schema,
Instance['meta'][typeof DEFS],
Path,
ReturnType<Handler>
>
post: {
body: UnwrapSchema<
Schema['body'],
Instance['meta'][typeof DEFS]
>
headers: UnwrapSchema<
Schema['headers'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
query: UnwrapSchema<
Schema['query'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
params: UnwrapSchema<
Schema['params'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: Record<ExtractPath<Path>, string>
response: Schema['response'] extends
| TSchema
| string
? {
'200': UnwrapSchema<
Schema['response'],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: Schema['response'] extends Record<
string,
TSchema | string
>
? {
[key in keyof Schema['response']]: UnwrapSchema<
Schema['response'][key],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: ReturnType<Handler>
}
}

@@ -803,11 +984,7 @@ }

put<
Path extends string,
Schema extends TypedSchema<
Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>
> = {},
Path extends string = string,
Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<
Schema,
Instance,
Path
>
Extract<keyof Instance['meta'][typeof DEFS], string>
>,
Handler extends LocalHandler<Schema, Instance, Path>
>(

@@ -828,8 +1005,54 @@ path: Path,

[path in Path]: {
[method in 'put']: TypedRouteToEden<
Schema,
Instance['meta'][typeof DEFS],
Path,
ReturnType<Handler>
>
put: {
body: UnwrapSchema<
Schema['body'],
Instance['meta'][typeof DEFS]
>
headers: UnwrapSchema<
Schema['headers'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
query: UnwrapSchema<
Schema['query'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
params: UnwrapSchema<
Schema['params'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: Record<ExtractPath<Path>, string>
response: Schema['response'] extends
| TSchema
| string
? {
'200': UnwrapSchema<
Schema['response'],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: Schema['response'] extends Record<
string,
TSchema | string
>
? {
[key in keyof Schema['response']]: UnwrapSchema<
Schema['response'][key],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: ReturnType<Handler>
}
}

@@ -864,11 +1087,7 @@ }

patch<
Path extends string,
Schema extends TypedSchema<
Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>
> = {},
Path extends string = string,
Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<
Schema,
Instance,
Path
>
Extract<keyof Instance['meta'][typeof DEFS], string>
>,
Handler extends LocalHandler<Schema, Instance, Path>
>(

@@ -889,8 +1108,54 @@ path: Path,

[path in Path]: {
[method in 'patch']: TypedRouteToEden<
Schema,
Instance['meta'][typeof DEFS],
Path,
ReturnType<Handler>
>
patch: {
body: UnwrapSchema<
Schema['body'],
Instance['meta'][typeof DEFS]
>
headers: UnwrapSchema<
Schema['headers'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
query: UnwrapSchema<
Schema['query'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
params: UnwrapSchema<
Schema['params'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: Record<ExtractPath<Path>, string>
response: Schema['response'] extends
| TSchema
| string
? {
'200': UnwrapSchema<
Schema['response'],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: Schema['response'] extends Record<
string,
TSchema | string
>
? {
[key in keyof Schema['response']]: UnwrapSchema<
Schema['response'][key],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: ReturnType<Handler>
}
}

@@ -925,11 +1190,7 @@ }

delete<
Path extends string,
Schema extends TypedSchema<
Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>
> = {},
Path extends string = string,
Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<
Schema,
Instance,
Path
>
Extract<keyof Instance['meta'][typeof DEFS], string>
>,
Handler extends LocalHandler<Schema, Instance, Path>
>(

@@ -950,8 +1211,54 @@ path: Path,

[path in Path]: {
[method in 'delete']: TypedRouteToEden<
Schema,
Instance['meta'][typeof DEFS],
Path,
ReturnType<Handler>
>
delete: {
body: UnwrapSchema<
Schema['body'],
Instance['meta'][typeof DEFS]
>
headers: UnwrapSchema<
Schema['headers'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
query: UnwrapSchema<
Schema['query'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
params: UnwrapSchema<
Schema['params'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: Record<ExtractPath<Path>, string>
response: Schema['response'] extends
| TSchema
| string
? {
'200': UnwrapSchema<
Schema['response'],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: Schema['response'] extends Record<
string,
TSchema | string
>
? {
[key in keyof Schema['response']]: UnwrapSchema<
Schema['response'][key],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: ReturnType<Handler>
}
}

@@ -986,11 +1293,7 @@ }

options<
Path extends string,
Schema extends TypedSchema<
Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>
> = {},
Path extends string = string,
Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<
Schema,
Instance,
Path
>
Extract<keyof Instance['meta'][typeof DEFS], string>
>,
Handler extends LocalHandler<Schema, Instance, Path>
>(

@@ -1011,8 +1314,54 @@ path: Path,

[path in Path]: {
[method in 'options']: TypedRouteToEden<
Schema,
Instance['meta'][typeof DEFS],
Path,
ReturnType<Handler>
>
options: {
body: UnwrapSchema<
Schema['body'],
Instance['meta'][typeof DEFS]
>
headers: UnwrapSchema<
Schema['headers'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
query: UnwrapSchema<
Schema['query'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
params: UnwrapSchema<
Schema['params'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: Record<ExtractPath<Path>, string>
response: Schema['response'] extends
| TSchema
| string
? {
'200': UnwrapSchema<
Schema['response'],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: Schema['response'] extends Record<
string,
TSchema | string
>
? {
[key in keyof Schema['response']]: UnwrapSchema<
Schema['response'][key],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: ReturnType<Handler>
}
}

@@ -1042,11 +1391,7 @@ }

all<
Path extends string,
Schema extends TypedSchema<
Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>
> = {},
Path extends string = string,
Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<
Schema,
Instance,
Path
>
Extract<keyof Instance['meta'][typeof DEFS], string>
>,
Handler extends LocalHandler<Schema, Instance, Path>
>(

@@ -1067,8 +1412,54 @@ path: Path,

[path in Path]: {
[method in 'all']: TypedRouteToEden<
Schema,
Instance['meta'][typeof DEFS],
Path,
ReturnType<Handler>
>
all: {
body: UnwrapSchema<
Schema['body'],
Instance['meta'][typeof DEFS]
>
headers: UnwrapSchema<
Schema['headers'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
query: UnwrapSchema<
Schema['query'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
params: UnwrapSchema<
Schema['params'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: Record<ExtractPath<Path>, string>
response: Schema['response'] extends
| TSchema
| string
? {
'200': UnwrapSchema<
Schema['response'],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: Schema['response'] extends Record<
string,
TSchema | string
>
? {
[key in keyof Schema['response']]: UnwrapSchema<
Schema['response'][key],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: ReturnType<Handler>
}
}

@@ -1103,11 +1494,7 @@ }

head<
Path extends string,
Schema extends TypedSchema<
Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>
> = {},
Path extends string = string,
Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<
Schema,
Instance,
Path
>
Extract<keyof Instance['meta'][typeof DEFS], string>
>,
Handler extends LocalHandler<Schema, Instance, Path>
>(

@@ -1128,8 +1515,54 @@ path: Path,

[path in Path]: {
[method in 'head']: TypedRouteToEden<
Schema,
Instance['meta'][typeof DEFS],
Path,
ReturnType<Handler>
>
head: {
body: UnwrapSchema<
Schema['body'],
Instance['meta'][typeof DEFS]
>
headers: UnwrapSchema<
Schema['headers'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
query: UnwrapSchema<
Schema['query'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
params: UnwrapSchema<
Schema['params'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: Record<ExtractPath<Path>, string>
response: Schema['response'] extends
| TSchema
| string
? {
'200': UnwrapSchema<
Schema['response'],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: Schema['response'] extends Record<
string,
TSchema | string
>
? {
[key in keyof Schema['response']]: UnwrapSchema<
Schema['response'][key],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: ReturnType<Handler>
}
}

@@ -1164,11 +1597,7 @@ }

trace<
Path extends string,
Schema extends TypedSchema<
Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>
> = {},
Path extends string = string,
Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<
Schema,
Instance,
Path
>
Extract<keyof Instance['meta'][typeof DEFS], string>
>,
Handler extends LocalHandler<Schema, Instance, Path>
>(

@@ -1189,8 +1618,54 @@ path: Path,

[path in Path]: {
[method in 'trace']: TypedRouteToEden<
Schema,
Instance['meta'][typeof DEFS],
Path,
ReturnType<Handler>
>
trace: {
body: UnwrapSchema<
Schema['body'],
Instance['meta'][typeof DEFS]
>
headers: UnwrapSchema<
Schema['headers'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
query: UnwrapSchema<
Schema['query'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
params: UnwrapSchema<
Schema['params'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: Record<ExtractPath<Path>, string>
response: Schema['response'] extends
| TSchema
| string
? {
'200': UnwrapSchema<
Schema['response'],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: Schema['response'] extends Record<
string,
TSchema | string
>
? {
[key in keyof Schema['response']]: UnwrapSchema<
Schema['response'][key],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: ReturnType<Handler>
}
}

@@ -1225,11 +1700,7 @@ }

connect<
Path extends string,
Schema extends TypedSchema<
Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>
> = {},
Path extends string = string,
Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<
Schema,
Instance,
Path
>
Extract<keyof Instance['meta'][typeof DEFS], string>
>,
Handler extends LocalHandler<Schema, Instance, Path>
>(

@@ -1250,8 +1721,54 @@ path: Path,

[path in Path]: {
[method in 'connect']: TypedRouteToEden<
Schema,
Instance['meta'][typeof DEFS],
Path,
ReturnType<Handler>
>
connect: {
body: UnwrapSchema<
Schema['body'],
Instance['meta'][typeof DEFS]
>
headers: UnwrapSchema<
Schema['headers'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
query: UnwrapSchema<
Schema['query'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
params: UnwrapSchema<
Schema['params'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: Record<ExtractPath<Path>, string>
response: Schema['response'] extends
| TSchema
| string
? {
'200': UnwrapSchema<
Schema['response'],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: Schema['response'] extends Record<
string,
TSchema | string
>
? {
[key in keyof Schema['response']]: UnwrapSchema<
Schema['response'][key],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: ReturnType<Handler>
}
}

@@ -1329,5 +1846,7 @@ }

(context) => {
console.log('Got', context.request.url)
if (
// @ts-ignore
this.server!.upgrade(context.request, {
this.server?.upgrade(context.request, {
headers:

@@ -1417,8 +1936,54 @@ typeof options.headers === 'function'

[path in Path]: {
[method in Uppercase<Method>]: TypedRouteToEden<
Schema,
Instance['meta'][typeof DEFS],
Path,
ReturnType<Handler>
>
[method in Method]: {
body: UnwrapSchema<
Schema['body'],
Instance['meta'][typeof DEFS]
>
headers: UnwrapSchema<
Schema['headers'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
query: UnwrapSchema<
Schema['query'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: undefined
params: UnwrapSchema<
Schema['params'],
Instance['meta'][typeof DEFS]
> extends infer Result
? Result extends Record<string, any>
? Result
: undefined
: Record<ExtractPath<Path>, string>
response: Schema['response'] extends
| TSchema
| string
? {
'200': UnwrapSchema<
Schema['response'],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: Schema['response'] extends Record<
string,
TSchema | string
>
? {
[key in keyof Schema['response']]: UnwrapSchema<
Schema['response'][key],
Instance['meta'][typeof DEFS],
ReturnType<Handler>
>
}
: ReturnType<Handler>
}
}

@@ -1425,0 +1990,0 @@ }

import { Kind, type TSchema } from '@sinclair/typebox'
import type { OpenAPIV3 } from 'openapi-types'
import deepClone from 'lodash.clonedeep'

@@ -75,2 +76,4 @@ import type { HTTPMethod, LocalHook } from './types'

}) => {
if (hook) hook = deepClone(hook)
path = toOpenAPIPath(path)

@@ -77,0 +80,0 @@

@@ -18,3 +18,3 @@ import type { Elysia } from '.'

> &
Record<typeof DEFS, { [x in string]: TSchema }> &
Record<typeof DEFS, Record<string, TSchema>> &
Record<typeof EXPOSED, Record<string, Record<string, unknown>>>

@@ -27,5 +27,7 @@

schema?: TypedSchema
meta?: ElysiaDefaultMeta
meta?: Record<typeof SCHEMA, Partial<OpenAPIV3.PathsObject>> &
Record<typeof DEFS, Record<string, TSchema>> &
Record<typeof EXPOSED, Record<string, Record<string, unknown>>>
} = {
store: Record<string, unknown>
store: {}
request: {}

@@ -39,6 +41,4 @@ schema: {}

request: Instance['request']
store: Instance['store'] extends undefined ? {} : Instance['store']
schema: Instance['schema'] extends undefined
? TypedSchema
: Instance['schema']
store: Instance['store']
schema: Instance['schema']
meta: Instance['meta']

@@ -157,5 +157,3 @@ }

> = Schema extends string
? Definitions extends {
[name in Schema]: infer NamedSchema extends TSchema
}
? Definitions extends Record<Schema, infer NamedSchema extends TSchema>
? Static<NamedSchema>

@@ -307,20 +305,38 @@ : Fallback

Catch = unknown
> = TypedSchemaToEden<
Schema,
Definitions
> extends infer Typed extends AnyTypedSchema
? {
body: Typed['body']
headers: Typed['headers']
query: Typed['query']
params: undefined extends Typed['params']
? Record<ExtractPath<Path>, string>
: Typed['params']
response: undefined extends Typed['response']
? {
'200': Catch
}
: Typed['response']
}
: never
> = {
body: UnwrapSchema<Schema['body'], Definitions>
headers: UnwrapSchema<
Schema['headers'],
Definitions
> extends infer Result extends Record<string, any>
? Result
: undefined
query: UnwrapSchema<
Schema['query'],
Definitions
> extends infer Result extends Record<string, any>
? Result
: undefined
params: UnwrapSchema<
Schema['params'],
Definitions
> extends infer Result extends Record<string, any>
? Result
: Record<ExtractPath<Path>, string>
response: Schema['response'] extends TSchema | string
? {
'200': UnwrapSchema<Schema['response'], Definitions, Catch>
}
: Schema['response'] extends {
[x in string]: TSchema | string
}
? {
[key in keyof Schema['response']]: UnwrapSchema<
Schema['response'][key],
Definitions,
Catch
>
}
: Catch
}

@@ -327,0 +343,0 @@ export type TypedWSRouteToEden<

@@ -1,7 +0,3 @@

import { Kind, TSchema, Type } from '@sinclair/typebox'
import {
TypeCheck,
TypeCompiler,
type ValueError
} from '@sinclair/typebox/compiler'
import { Kind, TSchema } from '@sinclair/typebox'
import { TypeCheck, TypeCompiler } from '@sinclair/typebox/compiler'
import type {

@@ -8,0 +4,0 @@ DeepMergeTwoTypes,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc