elysia 0.5.18 → 0.5.19

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.
@@ -1,20 +1,16 @@
1
1
  /// <reference types="bun-types" />
2
- import type { Elysia, TypedRoute, DEFS, SCHEMA, TypedSchema } from '.';
3
- export interface Context<Route extends TypedRoute = TypedRoute, Store extends Elysia['store'] = Elysia['store']> {
2
+ import type { Elysia, TypedRoute, SCHEMA } from '.';
3
+ export type Context<Route extends TypedRoute = TypedRoute, Store extends Elysia['store'] = Elysia['store']> = {
4
4
  request: Request;
5
5
  headers: undefined extends Route['headers'] ? Record<string, string | null> : Route['headers'];
6
6
  query: undefined extends Route['query'] ? Record<string, unknown> : Route['query'];
7
7
  params: Route['params'];
8
8
  body: Route['body'];
9
9
  store: Store;
10
- [SCHEMA]?: TypedSchema;
11
- [DEFS]?: {
12
- [index: string]: Record<string, unknown>;
13
- };
14
10
  set: {
15
11
  headers: Record<string, string>;
16
12
  status?: number;
17
13
  redirect?: string;
18
14
  };
19
- }
15
+ } & Record<typeof SCHEMA, Route>;
20
16
  export type PreContext<Route extends TypedRoute = TypedRoute, Store extends Elysia['store'] = Elysia['store']> = Omit<Context<Route, Store>, 'query' | 'params' | 'body'>;
@@ -1,17 +1,15 @@
1
1
  /// <reference types="bun-types" />
2
- import type { ServerWebSocket, WebSocketHandler } from 'bun';
3
- import type { Elysia } from '..';
4
- import { type DEFS } from '../utils';
5
- import type { ElysiaWSContext, WSTypedSchema } from './types';
6
- import type { ElysiaInstance, UnwrapSchema } from '../types';
7
- export declare class ElysiaWS<WS extends ElysiaWSContext<any> = ElysiaWSContext, Schema extends WSTypedSchema = WSTypedSchema, Definitions extends ElysiaInstance['meta'][typeof DEFS] = {}> {
2
+ import type { ServerWebSocket, ServerWebSocketSendStatus, WebSocketHandler } from 'bun';
3
+ import type { Elysia, SCHEMA } from '..';
4
+ import type { ElysiaWSContext } from './types';
5
+ export declare class ElysiaWS<WS extends ElysiaWSContext> {
8
6
  raw: WS;
9
7
  data: WS['data'];
10
8
  isSubscribed: WS['isSubscribed'];
11
9
  constructor(ws: WS);
12
- publish(topic: string, data?: UnwrapSchema<Schema['response'], Definitions>, compress?: boolean): this;
13
- publishToSelf(topic: string, data?: UnwrapSchema<Schema['response'], Definitions>, compress?: boolean): this;
14
- send(data: UnwrapSchema<Schema['response'], Definitions>): this;
10
+ publish(topic: string, data?: WS['data'][typeof SCHEMA]['response'], compress?: boolean): this;
11
+ publishToSelf(topic: string, data?: WS['data'][typeof SCHEMA]['response'], compress?: boolean): this;
12
+ send(data: WS['data'][typeof SCHEMA]['response']): this;
15
13
  subscribe(room: string): this;
16
14
  unsubscribe(room: string): this;
17
15
  cork(callback: (ws: ServerWebSocket<any>) => any): this;
@@ -20,9 +18,10 @@ export declare class ElysiaWS<WS extends ElysiaWSContext<any> = ElysiaWSContext,
20
18
  export declare const ws: (config?: Omit<WebSocketHandler, 'open' | 'message' | 'close' | 'drain'>) => (app: Elysia) => Elysia<{
21
19
  store: {};
22
20
  request: {
23
- publish: (topic: string, data: string | ArrayBuffer | SharedArrayBuffer | import("bun").ArrayBufferView, compress?: boolean | undefined) => number;
21
+ publish: WSPublish;
24
22
  };
25
23
  schema: {};
26
- meta: Record<typeof import("..").SCHEMA, {}> & Record<typeof DEFS, {}> & Record<typeof import("..").EXPOSED, {}>;
24
+ meta: Record<typeof SCHEMA, {}> & Record<typeof import("..").DEFS, {}> & Record<typeof import("..").EXPOSED, {}>;
27
25
  }>;
26
+ type WSPublish = (topic: string, data: string | ArrayBufferView | ArrayBuffer | SharedArrayBuffer, compress?: boolean) => ServerWebSocketSendStatus;
28
27
  export type { WSTypedSchema, WebSocketHeaderHandler, WebSocketSchemaToRoute, ElysiaWSContext, ElysiaWSOptions, TransformMessageHandler } from './types';
@@ -1,14 +1,18 @@
1
1
  /// <reference types="bun-types" />
2
2
  import type { ServerWebSocket, WebSocketHandler } from 'bun';
3
- import type { TSchema } from '@sinclair/typebox';
3
+ import type { TObject, TSchema } from '@sinclair/typebox';
4
4
  import type { TypeCheck } from '@sinclair/typebox/compiler';
5
- import type { ElysiaWS } from '.';
6
5
  import type { Context } from '../context';
7
6
  import type { DEFS } from '../utils';
8
- import type { ElysiaInstance, UnwrapSchema, TypedSchema, ExtractPath, WithArray, NoReturnHandler, HookHandler } from '../types';
9
- export type WSTypedSchema<ModelName extends string = string> = Omit<TypedSchema<ModelName>, 'response'> & {
7
+ import type { ElysiaInstance, UnwrapSchema, ExtractPath, WithArray, NoReturnHandler, HookHandler } from '../types';
8
+ import type { ElysiaWS } from '.';
9
+ export interface WSTypedSchema<ModelName extends string = string> {
10
+ body?: TSchema | ModelName;
11
+ headers?: TObject | ModelName;
12
+ query?: TObject | ModelName;
13
+ params?: TObject | ModelName;
10
14
  response?: TSchema | ModelName;
11
- };
15
+ }
12
16
  export type TypedWSSchemaToRoute<Schema extends WSTypedSchema = WSTypedSchema, Definitions extends ElysiaInstance['meta'][typeof DEFS] = {}> = {
13
17
  body: UnwrapSchema<Schema['body'], Definitions>;
14
18
  headers: UnwrapSchema<Schema['headers'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
@@ -17,17 +21,19 @@ export type TypedWSSchemaToRoute<Schema extends WSTypedSchema = WSTypedSchema, D
17
21
  response: UnwrapSchema<Schema['params'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
18
22
  };
19
23
  export type WebSocketSchemaToRoute<Schema extends WSTypedSchema, Definitions extends ElysiaInstance['meta'][typeof DEFS] = {}> = {
20
- body: UnwrapSchema<Schema['body'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
21
- headers: UnwrapSchema<Schema['headers'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
22
- query: UnwrapSchema<Schema['query'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
23
- params: UnwrapSchema<Schema['params'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
24
- response: UnwrapSchema<Schema['response'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
24
+ body: UnwrapSchema<Schema['body'], Definitions, undefined>;
25
+ headers: UnwrapSchema<Schema['headers'], Definitions, undefined>;
26
+ query: UnwrapSchema<Schema['query'], Definitions, undefined>;
27
+ params: UnwrapSchema<Schema['params'], Definitions, undefined>;
28
+ response: UnwrapSchema<Schema['response'], Definitions, undefined>;
25
29
  };
26
30
  export type TransformMessageHandler<Message extends WSTypedSchema['body']> = (message: UnwrapSchema<Message>) => void | UnwrapSchema<Message>;
27
- export type ElysiaWSContext<Schema extends WSTypedSchema = WSTypedSchema, Path extends string = string> = ServerWebSocket<Context<ExtractPath<Path> extends never ? WebSocketSchemaToRoute<Schema> : Omit<WebSocketSchemaToRoute<Schema>, 'params'> & {
28
- query: any;
29
- headers: any;
30
- params: Record<ExtractPath<Path>, string>;
31
+ export type ElysiaWSContext<Schema extends WSTypedSchema<any> = WSTypedSchema<never>, Definitions extends ElysiaInstance['meta'][typeof DEFS] = {}, Path extends string = never> = ServerWebSocket<Context<{
32
+ body: UnwrapSchema<Schema['body'], Definitions, undefined>;
33
+ headers: UnwrapSchema<Schema['headers'], Definitions, undefined>;
34
+ query: UnwrapSchema<Schema['query'], Definitions, undefined>;
35
+ params: ExtractPath<Path> extends infer Params extends string ? Record<Params, string> : UnwrapSchema<Schema['params'], Definitions, undefined>;
36
+ response: UnwrapSchema<Schema['response'], Definitions, undefined>;
31
37
  }> & {
32
38
  id: number;
33
39
  message: TypeCheck<any>;
@@ -40,8 +46,7 @@ export type WebSocketHeaderHandler<Schema extends WSTypedSchema = WSTypedSchema,
40
46
  }, 'params'> & {
41
47
  params: Record<ExtractPath<Path>, string>;
42
48
  }) => HeadersInit;
43
- type PartialWebSocketHandler = Omit<Partial<WebSocketHandler<Context>>, 'open' | 'message' | 'close' | 'drain' | 'publish' | 'publishToSelf'>;
44
- export type ElysiaWSOptions<Path extends string = '', Schema extends WSTypedSchema = {}, Definitions extends ElysiaInstance['meta'][typeof DEFS] = {}> = PartialWebSocketHandler & ElysiaWS<ElysiaWSContext<Schema, Path>, Schema, Definitions> extends infer WS ? Partial<Schema> & {
49
+ export type ElysiaWSOptions<Path extends string, Schema extends WSTypedSchema<any>, Definitions extends ElysiaInstance['meta'][typeof DEFS]> = Omit<Partial<WebSocketHandler<Context>>, 'open' | 'message' | 'close' | 'drain' | 'publish' | 'publishToSelf'> & (ElysiaWS<ElysiaWSContext<Schema, Definitions, Path>> extends infer WS ? Partial<Schema> & {
45
50
  beforeHandle?: WithArray<HookHandler<Schema>>;
46
51
  transform?: WithArray<NoReturnHandler<TypedWSSchemaToRoute<Schema>>>;
47
52
  transformMessage?: WithArray<TransformMessageHandler<Schema['body']>>;
@@ -50,5 +55,4 @@ export type ElysiaWSOptions<Path extends string = '', Schema extends WSTypedSche
50
55
  message?: (ws: WS, message: UnwrapSchema<Schema['body'], Definitions>) => any;
51
56
  close?: (ws: WS, code: number, message: string) => void | Promise<void>;
52
57
  drain?: (ws: WS) => void | Promise<void>;
53
- } : never;
54
- export {};
58
+ } : never);
package/dist/context.d.ts CHANGED
@@ -1,20 +1,16 @@
1
1
  /// <reference types="bun-types" />
2
- import type { Elysia, TypedRoute, DEFS, SCHEMA, TypedSchema } from '.';
3
- export interface Context<Route extends TypedRoute = TypedRoute, Store extends Elysia['store'] = Elysia['store']> {
2
+ import type { Elysia, TypedRoute, SCHEMA } from '.';
3
+ export type Context<Route extends TypedRoute = TypedRoute, Store extends Elysia['store'] = Elysia['store']> = {
4
4
  request: Request;
5
5
  headers: undefined extends Route['headers'] ? Record<string, string | null> : Route['headers'];
6
6
  query: undefined extends Route['query'] ? Record<string, unknown> : Route['query'];
7
7
  params: Route['params'];
8
8
  body: Route['body'];
9
9
  store: Store;
10
- [SCHEMA]?: TypedSchema;
11
- [DEFS]?: {
12
- [index: string]: Record<string, unknown>;
13
- };
14
10
  set: {
15
11
  headers: Record<string, string>;
16
12
  status?: number;
17
13
  redirect?: string;
18
14
  };
19
- }
15
+ } & Record<typeof SCHEMA, Route>;
20
16
  export type PreContext<Route extends TypedRoute = TypedRoute, Store extends Elysia['store'] = Elysia['store']> = Omit<Context<Route, Store>, 'query' | 'params' | 'body'>;
@@ -1,17 +1,15 @@
1
1
  /// <reference types="bun-types" />
2
- import type { ServerWebSocket, WebSocketHandler } from 'bun';
3
- import type { Elysia } from '..';
4
- import { type DEFS } from '../utils';
5
- import type { ElysiaWSContext, WSTypedSchema } from './types';
6
- import type { ElysiaInstance, UnwrapSchema } from '../types';
7
- export declare class ElysiaWS<WS extends ElysiaWSContext<any> = ElysiaWSContext, Schema extends WSTypedSchema = WSTypedSchema, Definitions extends ElysiaInstance['meta'][typeof DEFS] = {}> {
2
+ import type { ServerWebSocket, ServerWebSocketSendStatus, WebSocketHandler } from 'bun';
3
+ import type { Elysia, SCHEMA } from '..';
4
+ import type { ElysiaWSContext } from './types';
5
+ export declare class ElysiaWS<WS extends ElysiaWSContext> {
8
6
  raw: WS;
9
7
  data: WS['data'];
10
8
  isSubscribed: WS['isSubscribed'];
11
9
  constructor(ws: WS);
12
- publish(topic: string, data?: UnwrapSchema<Schema['response'], Definitions>, compress?: boolean): this;
13
- publishToSelf(topic: string, data?: UnwrapSchema<Schema['response'], Definitions>, compress?: boolean): this;
14
- send(data: UnwrapSchema<Schema['response'], Definitions>): this;
10
+ publish(topic: string, data?: WS['data'][typeof SCHEMA]['response'], compress?: boolean): this;
11
+ publishToSelf(topic: string, data?: WS['data'][typeof SCHEMA]['response'], compress?: boolean): this;
12
+ send(data: WS['data'][typeof SCHEMA]['response']): this;
15
13
  subscribe(room: string): this;
16
14
  unsubscribe(room: string): this;
17
15
  cork(callback: (ws: ServerWebSocket<any>) => any): this;
@@ -20,9 +18,10 @@ export declare class ElysiaWS<WS extends ElysiaWSContext<any> = ElysiaWSContext,
20
18
  export declare const ws: (config?: Omit<WebSocketHandler, 'open' | 'message' | 'close' | 'drain'>) => (app: Elysia) => Elysia<{
21
19
  store: {};
22
20
  request: {
23
- publish: (topic: string, data: string | ArrayBuffer | SharedArrayBuffer | import("bun").ArrayBufferView, compress?: boolean | undefined) => number;
21
+ publish: WSPublish;
24
22
  };
25
23
  schema: {};
26
- meta: Record<typeof import("..").SCHEMA, {}> & Record<typeof DEFS, {}> & Record<typeof import("..").EXPOSED, {}>;
24
+ meta: Record<typeof SCHEMA, {}> & Record<typeof import("..").DEFS, {}> & Record<typeof import("..").EXPOSED, {}>;
27
25
  }>;
26
+ type WSPublish = (topic: string, data: string | ArrayBufferView | ArrayBuffer | SharedArrayBuffer, compress?: boolean) => ServerWebSocketSendStatus;
28
27
  export type { WSTypedSchema, WebSocketHeaderHandler, WebSocketSchemaToRoute, ElysiaWSContext, ElysiaWSOptions, TransformMessageHandler } from './types';
@@ -1,14 +1,18 @@
1
1
  /// <reference types="bun-types" />
2
2
  import type { ServerWebSocket, WebSocketHandler } from 'bun';
3
- import type { TSchema } from '@sinclair/typebox';
3
+ import type { TObject, TSchema } from '@sinclair/typebox';
4
4
  import type { TypeCheck } from '@sinclair/typebox/compiler';
5
- import type { ElysiaWS } from '.';
6
5
  import type { Context } from '../context';
7
6
  import type { DEFS } from '../utils';
8
- import type { ElysiaInstance, UnwrapSchema, TypedSchema, ExtractPath, WithArray, NoReturnHandler, HookHandler } from '../types';
9
- export type WSTypedSchema<ModelName extends string = string> = Omit<TypedSchema<ModelName>, 'response'> & {
7
+ import type { ElysiaInstance, UnwrapSchema, ExtractPath, WithArray, NoReturnHandler, HookHandler } from '../types';
8
+ import type { ElysiaWS } from '.';
9
+ export interface WSTypedSchema<ModelName extends string = string> {
10
+ body?: TSchema | ModelName;
11
+ headers?: TObject | ModelName;
12
+ query?: TObject | ModelName;
13
+ params?: TObject | ModelName;
10
14
  response?: TSchema | ModelName;
11
- };
15
+ }
12
16
  export type TypedWSSchemaToRoute<Schema extends WSTypedSchema = WSTypedSchema, Definitions extends ElysiaInstance['meta'][typeof DEFS] = {}> = {
13
17
  body: UnwrapSchema<Schema['body'], Definitions>;
14
18
  headers: UnwrapSchema<Schema['headers'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
@@ -17,17 +21,19 @@ export type TypedWSSchemaToRoute<Schema extends WSTypedSchema = WSTypedSchema, D
17
21
  response: UnwrapSchema<Schema['params'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
18
22
  };
19
23
  export type WebSocketSchemaToRoute<Schema extends WSTypedSchema, Definitions extends ElysiaInstance['meta'][typeof DEFS] = {}> = {
20
- body: UnwrapSchema<Schema['body'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
21
- headers: UnwrapSchema<Schema['headers'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
22
- query: UnwrapSchema<Schema['query'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
23
- params: UnwrapSchema<Schema['params'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
24
- response: UnwrapSchema<Schema['response'], Definitions> extends infer Result extends Record<string, any> ? Result : undefined;
24
+ body: UnwrapSchema<Schema['body'], Definitions, undefined>;
25
+ headers: UnwrapSchema<Schema['headers'], Definitions, undefined>;
26
+ query: UnwrapSchema<Schema['query'], Definitions, undefined>;
27
+ params: UnwrapSchema<Schema['params'], Definitions, undefined>;
28
+ response: UnwrapSchema<Schema['response'], Definitions, undefined>;
25
29
  };
26
30
  export type TransformMessageHandler<Message extends WSTypedSchema['body']> = (message: UnwrapSchema<Message>) => void | UnwrapSchema<Message>;
27
- export type ElysiaWSContext<Schema extends WSTypedSchema = WSTypedSchema, Path extends string = string> = ServerWebSocket<Context<ExtractPath<Path> extends never ? WebSocketSchemaToRoute<Schema> : Omit<WebSocketSchemaToRoute<Schema>, 'params'> & {
28
- query: any;
29
- headers: any;
30
- params: Record<ExtractPath<Path>, string>;
31
+ export type ElysiaWSContext<Schema extends WSTypedSchema<any> = WSTypedSchema<never>, Definitions extends ElysiaInstance['meta'][typeof DEFS] = {}, Path extends string = never> = ServerWebSocket<Context<{
32
+ body: UnwrapSchema<Schema['body'], Definitions, undefined>;
33
+ headers: UnwrapSchema<Schema['headers'], Definitions, undefined>;
34
+ query: UnwrapSchema<Schema['query'], Definitions, undefined>;
35
+ params: ExtractPath<Path> extends infer Params extends string ? Record<Params, string> : UnwrapSchema<Schema['params'], Definitions, undefined>;
36
+ response: UnwrapSchema<Schema['response'], Definitions, undefined>;
31
37
  }> & {
32
38
  id: number;
33
39
  message: TypeCheck<any>;
@@ -40,8 +46,7 @@ export type WebSocketHeaderHandler<Schema extends WSTypedSchema = WSTypedSchema,
40
46
  }, 'params'> & {
41
47
  params: Record<ExtractPath<Path>, string>;
42
48
  }) => HeadersInit;
43
- type PartialWebSocketHandler = Omit<Partial<WebSocketHandler<Context>>, 'open' | 'message' | 'close' | 'drain' | 'publish' | 'publishToSelf'>;
44
- export type ElysiaWSOptions<Path extends string = '', Schema extends WSTypedSchema = {}, Definitions extends ElysiaInstance['meta'][typeof DEFS] = {}> = PartialWebSocketHandler & ElysiaWS<ElysiaWSContext<Schema, Path>, Schema, Definitions> extends infer WS ? Partial<Schema> & {
49
+ export type ElysiaWSOptions<Path extends string, Schema extends WSTypedSchema<any>, Definitions extends ElysiaInstance['meta'][typeof DEFS]> = Omit<Partial<WebSocketHandler<Context>>, 'open' | 'message' | 'close' | 'drain' | 'publish' | 'publishToSelf'> & (ElysiaWS<ElysiaWSContext<Schema, Definitions, Path>> extends infer WS ? Partial<Schema> & {
45
50
  beforeHandle?: WithArray<HookHandler<Schema>>;
46
51
  transform?: WithArray<NoReturnHandler<TypedWSSchemaToRoute<Schema>>>;
47
52
  transformMessage?: WithArray<TransformMessageHandler<Schema['body']>>;
@@ -50,5 +55,4 @@ export type ElysiaWSOptions<Path extends string = '', Schema extends WSTypedSche
50
55
  message?: (ws: WS, message: UnwrapSchema<Schema['body'], Definitions>) => any;
51
56
  close?: (ws: WS, code: number, message: string) => void | Promise<void>;
52
57
  drain?: (ws: WS) => void | Promise<void>;
53
- } : never;
54
- export {};
58
+ } : never);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "elysia",
3
3
  "description": "Fast, and friendly Bun web framework",
4
- "version": "0.5.18",
4
+ "version": "0.5.19",
5
5
  "author": {
6
6
  "name": "saltyAom",
7
7
  "url": "https://github.com/SaltyAom",