Comparing version 0.3.0-rc.1 to 0.3.0-rc.2
@@ -6,3 +6,3 @@ /// <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 } from './types'; | ||
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 TSchema } from '@sinclair/typebox'; | ||
@@ -157,3 +157,10 @@ import { ElysiaWSOptions, WSTypedSchema } from './ws'; | ||
}>; | ||
ws<Path extends string = '', Schema = {}>(path: Path, options: Path extends '' ? never : this extends Elysia<infer Instance> ? ElysiaWSOptions<Path, Schema extends WSTypedSchema ? Schema : WSTypedSchema, Instance['meta'][typeof DEFS]> : never): this extends Elysia<infer Instance> ? Elysia<Instance> : ElysiaInstance; | ||
ws<Path extends string = '', Schema extends TypedSchema = {}>(path: Path, options: Path extends '' ? never : this extends Elysia<infer Instance> ? ElysiaWSOptions<Path, Schema extends WSTypedSchema ? Schema : WSTypedSchema, Instance['meta'][typeof DEFS]> : never): Elysia<{ | ||
request: Instance['request']; | ||
store: Instance['store']; | ||
schema: Instance['schema']; | ||
meta: Instance['meta'] & Record<typeof SCHEMA, Record<Path, { | ||
[method in 'subscribe']: TypedWSRouteToEden<Schema, Instance['meta'][typeof DEFS], Path>; | ||
}>>; | ||
}>; | ||
route<Schema extends TypedSchema<Exclude<keyof Instance['meta'][typeof DEFS], number | symbol>> = {}, Method extends HTTPMethod = HTTPMethod, Path extends string = string, Handler extends LocalHandler<Schema, Instance, Path> = LocalHandler<Schema, Instance, Path>>(method: Method, path: Path, handler: Handler, hook?: LocalHook<Schema, Instance, Path>): Elysia<{ | ||
@@ -160,0 +167,0 @@ request: Instance['request']; |
@@ -143,2 +143,9 @@ /// <reference types="bun-types" /> | ||
} : never; | ||
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 ? { | ||
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'] ? Catch : Typed['response']['200']; | ||
} : never; | ||
export type TypedSchemaToEden<Schema extends TypedSchema, Definitions extends ElysiaInstance['meta'][typeof DEFS]> = { | ||
@@ -145,0 +152,0 @@ body: UnwrapSchema<Schema['body'], Definitions>; |
{ | ||
"name": "elysia", | ||
"description": "Fast, and friendly Bun web framework", | ||
"version": "0.3.0-rc.1", | ||
"version": "0.3.0-rc.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "saltyAom", |
@@ -57,3 +57,4 @@ import type { Serve, Server } from 'bun' | ||
MergeUnionObjects, | ||
TypedRouteToEden | ||
TypedRouteToEden, | ||
TypedWSRouteToEden | ||
} from './types' | ||
@@ -1260,3 +1261,3 @@ import { type TSchema } from '@sinclair/typebox' | ||
*/ | ||
ws<Path extends string = '', Schema = {}>( | ||
ws<Path extends string = '', Schema extends TypedSchema = {}>( | ||
/** | ||
@@ -1275,3 +1276,21 @@ * Path to register websocket to | ||
: never | ||
): this extends Elysia<infer Instance> ? Elysia<Instance> : ElysiaInstance { | ||
): Elysia<{ | ||
request: Instance['request'] | ||
store: Instance['store'] | ||
schema: Instance['schema'] | ||
meta: Instance['meta'] & | ||
Record< | ||
typeof SCHEMA, | ||
Record< | ||
Path, | ||
{ | ||
[method in 'subscribe']: TypedWSRouteToEden< | ||
Schema, | ||
Instance['meta'][typeof DEFS], | ||
Path | ||
> | ||
} | ||
> | ||
> | ||
}> { | ||
if (!this.wsRouter) | ||
@@ -1278,0 +1297,0 @@ throw new Error( |
@@ -322,2 +322,24 @@ import type { Elysia } from '.' | ||
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 | ||
? { | ||
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'] | ||
? Catch | ||
: Typed['response']['200'] | ||
} | ||
: never | ||
export type TypedSchemaToEden< | ||
@@ -324,0 +346,0 @@ Schema extends TypedSchema, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
169048
4448