@krisanalfa/bunest-adapter 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -18
- package/dist/bun.adapter.d.ts +8 -67
- package/dist/bun.internal.types.d.ts +53 -0
- package/dist/bun.preflight-http-server.d.ts +8 -26
- package/dist/bun.request.d.ts +56 -7
- package/dist/bun.response.d.ts +35 -0
- package/dist/bun.server-instance.d.ts +137 -0
- package/dist/bun.ws-adapter.d.ts +1 -11
- package/dist/index.d.ts +2 -1
- package/dist/index.js +517 -324
- package/dist/index.js.map +11 -10
- package/package.json +17 -7
- package/dist/internal.types.d.ts +0 -8
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { CorsOptions, CorsOptionsDelegate } from '@nestjs/common/interfaces/external/cors-options.interface.js';
|
|
2
|
+
import { RequestMethod } from '@nestjs/common';
|
|
3
|
+
import { Server, ServerWebSocket } from 'bun';
|
|
4
|
+
import { RequestHandler } from '@nestjs/common/interfaces/index.js';
|
|
5
|
+
import { BunStaticAssetsOptions, BunWsClientData, ServerOptions, WsData, WsOptions } from './bun.internal.types.js';
|
|
6
|
+
import { BunMiddlewareEngine } from './bun.middleware-engine.js';
|
|
7
|
+
import { BunRequest } from './bun.request.js';
|
|
8
|
+
import { BunResponse } from './bun.response.js';
|
|
9
|
+
/**
|
|
10
|
+
* BunServerInstance is the actual server instance that handles route registrations,
|
|
11
|
+
* WebSocket functionalities, and the listen method. This class is passed to
|
|
12
|
+
* AbstractHttpAdapter.setInstance() and implements the methods that NestJS expects
|
|
13
|
+
* from an HTTP server instance (similar to Express app or Fastify instance).
|
|
14
|
+
*/
|
|
15
|
+
export declare class BunServerInstance {
|
|
16
|
+
private readonly bunServeOptions;
|
|
17
|
+
private readonly logger;
|
|
18
|
+
private readonly middlewareEngine;
|
|
19
|
+
private useVersioning;
|
|
20
|
+
private readonly routes;
|
|
21
|
+
private readonly routeHandlers;
|
|
22
|
+
private notFoundHandler;
|
|
23
|
+
private readonly wsHandlers;
|
|
24
|
+
private readonly wsMiddlewareEngine;
|
|
25
|
+
private wsOptions;
|
|
26
|
+
private useWs;
|
|
27
|
+
private useWsCors;
|
|
28
|
+
private staticAssetsOptions;
|
|
29
|
+
private httpServer;
|
|
30
|
+
constructor(bunServeOptions: ServerOptions<BunWsClientData>);
|
|
31
|
+
use(maybePath: string | RequestHandler<BunRequest, BunResponse>, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
32
|
+
private createHttpMethodHandler;
|
|
33
|
+
get(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
34
|
+
post(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
35
|
+
put(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
36
|
+
patch(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
37
|
+
delete(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
38
|
+
head(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
39
|
+
options(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
40
|
+
private createUnsupportedMethod;
|
|
41
|
+
all(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
42
|
+
propfind(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
43
|
+
proppatch(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
44
|
+
mkcol(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
45
|
+
copy(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
46
|
+
move(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
47
|
+
lock(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
48
|
+
unlock(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
49
|
+
search(pathOrHandler: unknown, maybeHandler?: RequestHandler<BunRequest, BunResponse>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Start listening on the specified port and hostname.
|
|
52
|
+
* @param port The port number or Unix socket path to listen on.
|
|
53
|
+
* @param hostnameOrCallback The hostname to bind to or the callback function.
|
|
54
|
+
* @param maybeCallback Optional callback to invoke once the server is listening.
|
|
55
|
+
*/
|
|
56
|
+
listen(port: string | number, hostnameOrCallback?: string | (() => void), maybeCallback?: () => void): Promise<Server<unknown>>;
|
|
57
|
+
/**
|
|
58
|
+
* NestJS compatibility methods - stop the server
|
|
59
|
+
*/
|
|
60
|
+
stop(force?: boolean): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Get the address of the server
|
|
63
|
+
*/
|
|
64
|
+
address(): {
|
|
65
|
+
address: string;
|
|
66
|
+
port: number;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Set WebSocket options
|
|
70
|
+
*/
|
|
71
|
+
setWsOptions(options: WsOptions): void;
|
|
72
|
+
/**
|
|
73
|
+
* Register WebSocket open handler
|
|
74
|
+
*/
|
|
75
|
+
registerWsOpenHandler(handler: (ws: ServerWebSocket<unknown>) => void): void;
|
|
76
|
+
/**
|
|
77
|
+
* Register WebSocket message handler
|
|
78
|
+
*/
|
|
79
|
+
registerWsMessageHandler(handler: (ws: ServerWebSocket<unknown>, message: WsData, server: Server<unknown>) => void): void;
|
|
80
|
+
/**
|
|
81
|
+
* Register WebSocket close handler
|
|
82
|
+
*/
|
|
83
|
+
registerWsCloseHandler(handler: (ws: ServerWebSocket<unknown>, code: number, reason: string) => void): void;
|
|
84
|
+
/**
|
|
85
|
+
* Get the underlying Bun server
|
|
86
|
+
*/
|
|
87
|
+
getBunServer(): Server<unknown> | null;
|
|
88
|
+
/**
|
|
89
|
+
* Proxy method for WebSocket server close (BaseWsInstance)
|
|
90
|
+
*/
|
|
91
|
+
close(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Get the middleware engine
|
|
94
|
+
*/
|
|
95
|
+
getMiddlewareEngine(): BunMiddlewareEngine;
|
|
96
|
+
/**
|
|
97
|
+
* Set the not found handler
|
|
98
|
+
*/
|
|
99
|
+
setNotFoundHandler(handler: RequestHandler<BunRequest, BunResponse>): void;
|
|
100
|
+
/**
|
|
101
|
+
* Enable versioning support
|
|
102
|
+
*/
|
|
103
|
+
setUseVersioning(value: boolean): void;
|
|
104
|
+
/**
|
|
105
|
+
* Register body parser middleware
|
|
106
|
+
*/
|
|
107
|
+
registerParserMiddleware(prefix?: string, rawBody?: boolean): void;
|
|
108
|
+
/**
|
|
109
|
+
* Create middleware factory for NestJS
|
|
110
|
+
*/
|
|
111
|
+
createMiddlewareFactory(requestMethod: RequestMethod): (path: string, callback: Function) => void;
|
|
112
|
+
/**
|
|
113
|
+
* Enable CORS middleware
|
|
114
|
+
*/
|
|
115
|
+
enableCors(corsOptions?: CorsOptions | CorsOptionsDelegate<BunRequest>, prefix?: string): void;
|
|
116
|
+
/**
|
|
117
|
+
* Serve static assets
|
|
118
|
+
*/
|
|
119
|
+
useStaticAssets(path: string, options?: BunStaticAssetsOptions): void;
|
|
120
|
+
private static isNumericPort;
|
|
121
|
+
private static omitKeys;
|
|
122
|
+
private isWebSocketUpgradeRequest;
|
|
123
|
+
private provideCorsHeaders;
|
|
124
|
+
private upgradeWebSocket;
|
|
125
|
+
private setupStaticAssetsIfNeeded;
|
|
126
|
+
private setupWebSocketIfNeeded;
|
|
127
|
+
private createServer;
|
|
128
|
+
private delegateRouteHandler;
|
|
129
|
+
private ensureRouteExists;
|
|
130
|
+
private prepareRequestHandler;
|
|
131
|
+
private createRouteFetchHandler;
|
|
132
|
+
private createVersioningHandlers;
|
|
133
|
+
private executeHandlerChain;
|
|
134
|
+
private createChainedHandlerForVersioningResolution;
|
|
135
|
+
private mapRequestMethodToString;
|
|
136
|
+
private parseRouteHandler;
|
|
137
|
+
}
|
package/dist/bun.ws-adapter.d.ts
CHANGED
|
@@ -2,9 +2,8 @@ import { AbstractWsAdapter, BaseWsInstance, MessageMappingProperties } from '@ne
|
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { INestApplicationContext } from '@nestjs/common';
|
|
4
4
|
import { ServerWebSocket } from 'bun';
|
|
5
|
+
import { BunWsClientData, WsData, WsOptions } from './bun.internal.types.js';
|
|
5
6
|
import { BunPreflightHttpServer } from './bun.preflight-http-server.js';
|
|
6
|
-
import { WsOptions } from './internal.types.js';
|
|
7
|
-
export type WsData = string | Buffer | ArrayBuffer | Buffer[];
|
|
8
7
|
export type WsMessageParser<TData = unknown> = (data: WsData) => WsParsedData<TData>;
|
|
9
8
|
export interface WsParsedData<TData = unknown> {
|
|
10
9
|
event: string;
|
|
@@ -13,15 +12,6 @@ export interface WsParsedData<TData = unknown> {
|
|
|
13
12
|
export interface BunWsAdapterOptions extends WsOptions {
|
|
14
13
|
messageParser?: WsMessageParser;
|
|
15
14
|
}
|
|
16
|
-
/** Internal data stored on each WebSocket connection - must match bun.adapter.ts */
|
|
17
|
-
interface BunWsClientData {
|
|
18
|
-
/** Called when a message is received - matches bun.adapter.ts onMessageInternal */
|
|
19
|
-
onMessageInternal?: (message: WsData) => void;
|
|
20
|
-
/** Called when the connection closes - matches bun.adapter.ts onCloseInternal */
|
|
21
|
-
onCloseInternal?: () => void;
|
|
22
|
-
/** Called by NestJS for disconnect handling */
|
|
23
|
-
onDisconnect?: (ws: ServerWebSocket<unknown>) => void;
|
|
24
|
-
}
|
|
25
15
|
type BunWsClient = ServerWebSocket<BunWsClientData> & BaseWsInstance;
|
|
26
16
|
/**
|
|
27
17
|
* High-performance WebSocket adapter for Bun runtime with NestJS.
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './bun.adapter.js';
|
|
|
2
2
|
export * from './bun.request.js';
|
|
3
3
|
export * from './bun.response.js';
|
|
4
4
|
export * from './bun.file.interceptor.js';
|
|
5
|
-
export * from './internal.types.js';
|
|
5
|
+
export * from './bun.internal.types.js';
|
|
6
6
|
export * from './bun.preflight-http-server.js';
|
|
7
|
+
export * from './bun.server-instance.js';
|
|
7
8
|
export * from './bun.ws-adapter.js';
|