@fluojs/websockets 1.0.6 → 1.0.7
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.ko.md +24 -5
- package/README.md +24 -5
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/module.d.ts +1 -1
- package/dist/module.d.ts.map +1 -1
- package/dist/node/node-types.d.ts +2 -2
- package/dist/node/node-types.d.ts.map +1 -1
- package/dist/types.d.ts +18 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
package/README.ko.md
CHANGED
|
@@ -18,9 +18,11 @@ fluo 런타임을 위한 데코레이터 기반 WebSocket 게이트웨이 작성
|
|
|
18
18
|
## 설치
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
npm install @fluojs/websockets
|
|
21
|
+
npm install @fluojs/websockets
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
Root Node.js entrypoint는 패키지가 직접 소유한 `ws` dependency를 사용합니다. 애플리케이션 코드에서 `ws`를 직접 사용하지 않는 한 별도 설치가 필요하지 않습니다.
|
|
25
|
+
|
|
24
26
|
## 사용 시점
|
|
25
27
|
|
|
26
28
|
fluo 애플리케이션에 실시간 WebSocket 기능을 추가할 때 이 패키지를 사용합니다. 연결, 메시지 및 연결 해제 처리를 위한 깔끔한 데코레이터 기반 API를 제공하며, 다양한 런타임(Node.js, Bun, Deno, Cloudflare Workers)을 최고 수준으로 지원합니다.
|
|
@@ -90,9 +92,7 @@ WebSocketModule.forRoot({
|
|
|
90
92
|
},
|
|
91
93
|
upgrade: {
|
|
92
94
|
guard(request) {
|
|
93
|
-
const authorization = request
|
|
94
|
-
? request.headers.get('authorization')
|
|
95
|
-
: request.headers.authorization;
|
|
95
|
+
const authorization = request.headers.authorization;
|
|
96
96
|
|
|
97
97
|
if (authorization !== 'Bearer demo-token') {
|
|
98
98
|
throw new UnauthorizedException('Authentication required.');
|
|
@@ -102,7 +102,24 @@ WebSocketModule.forRoot({
|
|
|
102
102
|
});
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
옵션을 생략하면 `@fluojs/websockets`는 동시 연결 수, inbound payload 크기, pending message buffer, shutdown cleanup에 bounded default를 적용합니다. 기본값은 `maxConnections: 1000`, `maxPayloadBytes: 1 MiB`, `buffer.maxPendingMessagesPerSocket: 256`, `shutdown.timeoutMs: 5000`, Node heartbeat interval `30s`, Node backpressure `maxBufferedAmountBytes: 1 MiB`와 drop behavior입니다. 또한 server-backed Node listener는 `heartbeat.enabled`를 명시적으로 `false`로 두지 않는 한 heartbeat timer를 활성화합니다. Node shutdown은 shutdown이 시작된 뒤 in-flight async upgrade를 거절하고, 애플리케이션 shutdown 시 추적 중인 websocket 클라이언트를 닫고, `shutdown.timeoutMs` 범위 안에서 `@OnDisconnect()` cleanup이 마무리될 수 있도록 bounded 기회를 제공합니다. 공식 fetch-style runtime module(`@fluojs/websockets/bun`, `@fluojs/websockets/deno`, `@fluojs/websockets/cloudflare-workers`)은 `Request` typed upgrade guard를 노출하며, 애플리케이션 shutdown 중 동일한 bounded close와 disconnect cleanup 동작을 제공합니다.
|
|
105
|
+
옵션을 생략하면 `@fluojs/websockets`는 동시 연결 수, inbound payload 크기, pending message buffer, shutdown cleanup에 bounded default를 적용합니다. 기본값은 `maxConnections: 1000`, `maxPayloadBytes: 1 MiB`, `buffer.maxPendingMessagesPerSocket: 256`, `shutdown.timeoutMs: 5000`, Node heartbeat interval `30s`, Node backpressure `maxBufferedAmountBytes: 1 MiB`와 drop behavior입니다. 또한 server-backed Node listener는 `heartbeat.enabled`를 명시적으로 `false`로 두지 않는 한 heartbeat timer를 활성화합니다. Node shutdown은 shutdown이 시작된 뒤 in-flight async upgrade를 거절하고, 애플리케이션 shutdown 시 추적 중인 websocket 클라이언트를 닫고, `shutdown.timeoutMs` 범위 안에서 `@OnDisconnect()` cleanup이 마무리될 수 있도록 bounded 기회를 제공합니다. 해결되지 않은 cleanup은 shutdown을 무기한 막지 않고 해당 timeout 안에서 로그로 남습니다. 공식 fetch-style runtime module(`@fluojs/websockets/bun`, `@fluojs/websockets/deno`, `@fluojs/websockets/cloudflare-workers`)은 `Request` typed upgrade guard를 노출하며, 애플리케이션 shutdown 중 동일한 bounded close와 disconnect cleanup 동작을 제공합니다.
|
|
106
|
+
|
|
107
|
+
Root `@fluojs/websockets` / `@fluojs/websockets/node` guard는 Node의 `IncomingMessage`를 받습니다. Fetch-style subpath는 Web standard `Request`를 받으므로, 재사용 가능한 옵션 객체를 작성할 때는 subpath별 `WebSocketModuleOptions` 타입을 선택하세요.
|
|
108
|
+
|
|
109
|
+
### Room
|
|
110
|
+
`WebSocketRoomService`를 사용하면 gateway 또는 application service가 adapter 내부에 접근하지 않고도 가벼운 room membership state를 유지할 수 있습니다. Runtime lifecycle service는 `joinRoom(socketId, room)`, `leaveRoom(socketId, room)`, `broadcastToRoom(room, event, data)`, `getRooms(socketId)`를 구현합니다. `broadcastToRoom(...)`은 현재 room에 있는 열린 socket에 `{ event, data }` 형태의 JSON frame을 보내며, 전송 전에 설정된 backpressure policy를 적용합니다.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { WebSocketRoomService } from '@fluojs/websockets';
|
|
114
|
+
|
|
115
|
+
class OrderStatusPublisher {
|
|
116
|
+
constructor(private readonly rooms: WebSocketRoomService) {}
|
|
117
|
+
|
|
118
|
+
publish(orderId: string, status: string) {
|
|
119
|
+
this.rooms.broadcastToRoom(`order:${orderId}`, 'order.status', { status });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
106
123
|
|
|
107
124
|
## 바이너리 페이로드
|
|
108
125
|
|
|
@@ -124,6 +141,8 @@ Gateway `@OnMessage()` handler는 지원 런타임 전반에서 하나의 정규
|
|
|
124
141
|
|
|
125
142
|
기본 루트 Node.js alias 대신 런타임을 명시적으로 고정하고 싶다면 런타임별 서브패스를 사용하세요. 루트 `@fluojs/websockets` 진입점은 Node.js 기본 module과 lifecycle-service alias를 유지합니다. Fetch-style 애플리케이션은 게이트웨이 데코레이터와 metadata helper를 선택한 런타임 서브패스에서 import할 수 있으므로 authoring code가 루트 Node.js 기반 진입점을 로드할 필요가 없습니다.
|
|
126
143
|
|
|
144
|
+
Package manifest의 `engines.node >=20.0.0` 선언은 published package와 기본 Node.js entrypoint 기준입니다. Bun, Deno, Cloudflare Workers 지원은 아래 전용 fetch-style subpath를 통해 노출되며, 해당 subpath는 request/handler type을 web-standard로 유지하고 application code가 root Node.js lifecycle-service alias에 의존하지 않게 합니다.
|
|
145
|
+
|
|
127
146
|
각 서브패스는 해당 `*WebSocketModule.forRoot(...)` 진입점, 일치하는 런타임 lifecycle service export, 그리고 공유 gateway authoring primitive인 `WebSocketGateway`, `OnConnect`, `OnMessage`, `OnDisconnect`, `defineWebSocketGatewayMetadata`, `getWebSocketGatewayMetadata`, `defineWebSocketHandlerMetadata`, `getWebSocketHandlerMetadata`, `getWebSocketHandlerMetadataEntries`, `webSocketGatewayMetadataSymbol`, `webSocketHandlerMetadataSymbol`을 제공합니다.
|
|
128
147
|
|
|
129
148
|
| 런타임 | 서브패스 | 모듈 | Lifecycle service |
|
package/README.md
CHANGED
|
@@ -18,9 +18,11 @@ Decorator-based WebSocket gateway authoring for the fluo runtime.
|
|
|
18
18
|
## Installation
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
npm install @fluojs/websockets
|
|
21
|
+
npm install @fluojs/websockets
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
The root Node.js entrypoint uses the package-owned `ws` dependency. Applications do not need to install `ws` separately unless they use it directly in their own code.
|
|
25
|
+
|
|
24
26
|
## When to Use
|
|
25
27
|
|
|
26
28
|
Use this package to add real-time WebSocket capabilities to your fluo application. It provides a clean, decorator-driven API for handling connections, messages, and disconnections, with first-class support for multiple runtimes (Node.js, Bun, Deno, Cloudflare Workers).
|
|
@@ -90,9 +92,7 @@ WebSocketModule.forRoot({
|
|
|
90
92
|
},
|
|
91
93
|
upgrade: {
|
|
92
94
|
guard(request) {
|
|
93
|
-
const authorization = request
|
|
94
|
-
? request.headers.get('authorization')
|
|
95
|
-
: request.headers.authorization;
|
|
95
|
+
const authorization = request.headers.authorization;
|
|
96
96
|
|
|
97
97
|
if (authorization !== 'Bearer demo-token') {
|
|
98
98
|
throw new UnauthorizedException('Authentication required.');
|
|
@@ -102,7 +102,24 @@ WebSocketModule.forRoot({
|
|
|
102
102
|
});
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
When omitted, `@fluojs/websockets` applies bounded defaults for concurrent connections, inbound payload size, pending message buffers, and shutdown cleanup. Default settings are `maxConnections: 1000`, `maxPayloadBytes: 1 MiB`, `buffer.maxPendingMessagesPerSocket: 256`, `shutdown.timeoutMs: 5000`, Node heartbeat interval `30s`, and Node backpressure `maxBufferedAmountBytes: 1 MiB` with drop behavior. Server-backed Node listeners enable heartbeat timers unless you explicitly set `heartbeat.enabled` to `false`. Node shutdown rejects in-flight async upgrades once shutdown begins, will close tracked websocket clients during application shutdown, and gives `@OnDisconnect()` cleanup a bounded chance to finish within `shutdown.timeoutMs
|
|
105
|
+
When omitted, `@fluojs/websockets` applies bounded defaults for concurrent connections, inbound payload size, pending message buffers, and shutdown cleanup. Default settings are `maxConnections: 1000`, `maxPayloadBytes: 1 MiB`, `buffer.maxPendingMessagesPerSocket: 256`, `shutdown.timeoutMs: 5000`, Node heartbeat interval `30s`, and Node backpressure `maxBufferedAmountBytes: 1 MiB` with drop behavior. Server-backed Node listeners enable heartbeat timers unless you explicitly set `heartbeat.enabled` to `false`. Node shutdown rejects in-flight async upgrades once shutdown begins, will close tracked websocket clients during application shutdown, and gives `@OnDisconnect()` cleanup a bounded chance to finish within `shutdown.timeoutMs`; unresolved cleanup is logged and bounded by that timeout instead of blocking shutdown indefinitely. The official fetch-style runtime modules (`@fluojs/websockets/bun`, `@fluojs/websockets/deno`, and `@fluojs/websockets/cloudflare-workers`) expose `Request`-typed upgrade guards and provide the same bounded close and disconnect cleanup behavior during application shutdown.
|
|
106
|
+
|
|
107
|
+
The root `@fluojs/websockets` / `@fluojs/websockets/node` guard receives Node's `IncomingMessage`. Fetch-style subpaths receive a Web-standard `Request`, so choose the subpath-specific `WebSocketModuleOptions` type when authoring reusable option objects.
|
|
108
|
+
|
|
109
|
+
### Rooms
|
|
110
|
+
`WebSocketRoomService` lets gateway or application services keep lightweight room membership state without reaching into adapter internals. Runtime lifecycle services implement `joinRoom(socketId, room)`, `leaveRoom(socketId, room)`, `broadcastToRoom(room, event, data)`, and `getRooms(socketId)`. `broadcastToRoom(...)` sends a JSON frame shaped as `{ event, data }` to currently open sockets in the room and applies the configured backpressure policy before sending.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { WebSocketRoomService } from '@fluojs/websockets';
|
|
114
|
+
|
|
115
|
+
class OrderStatusPublisher {
|
|
116
|
+
constructor(private readonly rooms: WebSocketRoomService) {}
|
|
117
|
+
|
|
118
|
+
publish(orderId: string, status: string) {
|
|
119
|
+
this.rooms.broadcastToRoom(`order:${orderId}`, 'order.status', { status });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
106
123
|
|
|
107
124
|
## Binary Payloads
|
|
108
125
|
|
|
@@ -124,6 +141,8 @@ Gateway `@OnMessage()` handlers receive one normalized payload contract across s
|
|
|
124
141
|
|
|
125
142
|
Use the runtime subpaths when you want an explicit runtime binding instead of the default root Node.js alias. The root `@fluojs/websockets` entrypoint preserves the Node.js default module and lifecycle-service aliases. Fetch-style applications can import gateway decorators and metadata helpers from their selected runtime subpath so authoring code does not need to load the root Node.js-backed entrypoint.
|
|
126
143
|
|
|
144
|
+
The package manifest declares `engines.node >=20.0.0` for the published package and default Node.js entrypoint. Bun, Deno, and Cloudflare Workers support is exposed through the dedicated fetch-style subpaths listed below; those subpaths keep request/handler types web-standard and avoid the root Node.js lifecycle-service alias in application code.
|
|
145
|
+
|
|
127
146
|
Each subpath exposes its `*WebSocketModule.forRoot(...)` entrypoint, the matching runtime lifecycle service export, and the shared gateway authoring primitives: `WebSocketGateway`, `OnConnect`, `OnMessage`, `OnDisconnect`, `defineWebSocketGatewayMetadata`, `getWebSocketGatewayMetadata`, `defineWebSocketHandlerMetadata`, `getWebSocketHandlerMetadata`, `getWebSocketHandlerMetadataEntries`, `webSocketGatewayMetadataSymbol`, and `webSocketHandlerMetadataSymbol`.
|
|
128
147
|
|
|
129
148
|
| Runtime | Subpath | Module | Lifecycle service |
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ export * from './decorators.js';
|
|
|
2
2
|
export * from './metadata.js';
|
|
3
3
|
export * from './module.js';
|
|
4
4
|
export * from './service.js';
|
|
5
|
-
export
|
|
5
|
+
export type { WebSocketEventMap, WebSocketGatewayDescriptor, WebSocketGatewayHandlerDescriptor, WebSocketGatewayHandlerMetadata, WebSocketGatewayHandlerType, WebSocketGatewayMetadata, WebSocketGatewayOptions, WebSocketGatewayServerBackedOptions, WebSocketRoomService, WebSocketUpgradeContext, WebSocketUpgradeRejection, } from './types.js';
|
|
6
|
+
export type { TypedOnMessageHandler, WebSocketGatewayContext, WebSocketModuleOptions, WebSocketUpgradeGuard, } from './node/node-types.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,YAAY,EACV,iBAAiB,EACjB,0BAA0B,EAC1B,iCAAiC,EACjC,+BAA+B,EAC/B,2BAA2B,EAC3B,wBAAwB,EACxB,uBAAuB,EACvB,mCAAmC,EACnC,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/module.d.ts
CHANGED
package/dist/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE;;GAEG;AACH,qBAAa,eAAe;IAC1B;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,sBAA2B,GAAG,UAAU;CAGjE"}
|
|
@@ -16,9 +16,9 @@ export type { WebSocketUpgradeContext, WebSocketUpgradeRejection };
|
|
|
16
16
|
/**
|
|
17
17
|
* Hook that can allow or reject a websocket upgrade before the adapter accepts it.
|
|
18
18
|
*/
|
|
19
|
-
export type WebSocketUpgradeGuard = SharedWebSocketUpgradeGuard<IncomingMessage
|
|
19
|
+
export type WebSocketUpgradeGuard = SharedWebSocketUpgradeGuard<IncomingMessage>;
|
|
20
20
|
/**
|
|
21
21
|
* Runtime options shared by the Node websocket lifecycle service.
|
|
22
22
|
*/
|
|
23
|
-
export type WebSocketModuleOptions = SharedWebSocketModuleOptions<IncomingMessage
|
|
23
|
+
export type WebSocketModuleOptions = SharedWebSocketModuleOptions<IncomingMessage>;
|
|
24
24
|
//# sourceMappingURL=node-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-types.d.ts","sourceRoot":"","sources":["../../src/node/node-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,OAAO,KAAK,EACV,sBAAsB,IAAI,4BAA4B,EACtD,uBAAuB,EACvB,qBAAqB,IAAI,2BAA2B,EACpD,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,MAAM,OAAO,IAAI,CACpG,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,eAAe,KACrB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,eAAe,CAAC;IACzB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,YAAY,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,2BAA2B,CAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"node-types.d.ts","sourceRoot":"","sources":["../../src/node/node-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,OAAO,KAAK,EACV,sBAAsB,IAAI,4BAA4B,EACtD,uBAAuB,EACvB,qBAAqB,IAAI,2BAA2B,EACpD,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,MAAM,OAAO,IAAI,CACpG,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,eAAe,KACrB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,eAAe,CAAC;IACzB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,YAAY,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,2BAA2B,CAAC,eAAe,CAAC,CAAC;AAEjF;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,4BAA4B,CAAC,eAAe,CAAC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import type { IncomingMessage } from 'node:http';
|
|
2
1
|
import type { MetadataPropertyKey, Token } from '@fluojs/core';
|
|
3
|
-
import type { TypedOnMessageHandler as NodeTypedOnMessageHandler, WebSocketGatewayContext as NodeWebSocketGatewayContext } from './node/node-types.js';
|
|
4
2
|
/**
|
|
5
3
|
* Event-name-to-payload map used to type `@OnMessage(...)` handlers.
|
|
6
4
|
*/
|
|
7
5
|
export type WebSocketEventMap = Record<string, unknown>;
|
|
8
6
|
/**
|
|
9
|
-
*
|
|
7
|
+
* Runtime-neutral message handler signature resolved from one {@link WebSocketEventMap} entry.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam TEvents Event-name-to-payload map used by the gateway.
|
|
10
|
+
* @typeParam K Event key handled by this callback.
|
|
11
|
+
* @typeParam TSocket Socket shape surfaced by the selected runtime subpath.
|
|
12
|
+
* @typeParam TRequest Request shape surfaced by the selected runtime subpath.
|
|
10
13
|
*/
|
|
11
|
-
export type TypedOnMessageHandler<TEvents extends WebSocketEventMap, K extends keyof TEvents> =
|
|
14
|
+
export type TypedOnMessageHandler<TEvents extends WebSocketEventMap, K extends keyof TEvents, TSocket = unknown, TRequest = Request> = (payload: TEvents[K], socket: TSocket, request: TRequest) => void | Promise<void>;
|
|
12
15
|
/**
|
|
13
16
|
* Dedicated listener configuration for runtimes that can host a standalone WebSocket server.
|
|
14
17
|
*/
|
|
@@ -86,9 +89,17 @@ export interface WebSocketGatewayDescriptor {
|
|
|
86
89
|
token: Token;
|
|
87
90
|
}
|
|
88
91
|
/**
|
|
89
|
-
* Runtime context passed to gateway handlers
|
|
92
|
+
* Runtime-neutral context passed to gateway handlers.
|
|
93
|
+
*
|
|
94
|
+
* @typeParam TSocket Socket shape surfaced by the selected runtime subpath.
|
|
95
|
+
* @typeParam TRequest Request shape surfaced by the selected runtime subpath.
|
|
90
96
|
*/
|
|
91
|
-
export
|
|
97
|
+
export interface WebSocketGatewayContext<TSocket = unknown, TRequest = Request> {
|
|
98
|
+
/** Request object associated with the accepted websocket upgrade. */
|
|
99
|
+
request: TRequest;
|
|
100
|
+
/** Socket object accepted by the selected runtime. */
|
|
101
|
+
socket: TSocket;
|
|
102
|
+
}
|
|
92
103
|
/**
|
|
93
104
|
* Upgrade-time context shared with pre-upgrade websocket guards.
|
|
94
105
|
*/
|
|
@@ -154,7 +165,7 @@ export interface WebSocketRoomService {
|
|
|
154
165
|
*
|
|
155
166
|
* @typeParam TRequest Request shape received by the runtime-specific pre-upgrade guard.
|
|
156
167
|
*/
|
|
157
|
-
export interface WebSocketModuleOptions<TRequest =
|
|
168
|
+
export interface WebSocketModuleOptions<TRequest = Request> {
|
|
158
169
|
/** Limits that bound connection count and inbound payload size across runtime adapters. */
|
|
159
170
|
limits?: {
|
|
160
171
|
/** Maximum number of concurrently tracked websocket connections before new upgrades are rejected. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExD;;;;;;;GAOG;AACH,MAAM,MAAM,qBAAqB,CAC/B,OAAO,SAAS,iBAAiB,EACjC,CAAC,SAAS,MAAM,OAAO,EACvB,OAAO,GAAG,OAAO,EACjB,QAAQ,GAAG,OAAO,IAChB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEtF;;GAEG;AACH,MAAM,WAAW,mCAAmC;IAClD,mGAAmG;IACnG,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,+EAA+E;IAC/E,YAAY,CAAC,EAAE,mCAAmC,CAAC;CACpD;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAC;IAEb,oFAAoF;IACpF,YAAY,CAAC,EAAE,mCAAmC,CAAC;CACpD;AAED;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C,qEAAqE;IACrE,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,oEAAoE;IACpE,IAAI,EAAE,2BAA2B,CAAC;CACnC;AAED;;GAEG;AACH,MAA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AAC,EAAE,OAAO,GAAG,MAAM,CAAC;KAC3B,CAAC;IACF,MAAM,CAAC,EAAE;QACP,2BAA2B,CAAC,EAAE,MAAM,CAAC;QACrC,cAAc,CAAC,EAAE,OAAO,GAAG,aAAa,GAAG,aAAa,CAAC;KAC1D,CAAC;IACF,SAAS,CAAC,EAAE;QACV,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,QAAQ,CAAC,EAAE;QACT,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH"}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"realtime",
|
|
10
10
|
"upgrade"
|
|
11
11
|
],
|
|
12
|
-
"version": "1.0.
|
|
12
|
+
"version": "1.0.7",
|
|
13
13
|
"private": false,
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"repository": {
|
|
@@ -71,16 +71,16 @@
|
|
|
71
71
|
"ws": "^8.18.3",
|
|
72
72
|
"@fluojs/core": "^1.0.3",
|
|
73
73
|
"@fluojs/di": "^1.1.0",
|
|
74
|
-
"@fluojs/http": "^1.1.
|
|
75
|
-
"@fluojs/runtime": "^1.1.
|
|
74
|
+
"@fluojs/http": "^1.1.2",
|
|
75
|
+
"@fluojs/runtime": "^1.1.8"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/ws": "^8.18.1",
|
|
79
79
|
"vitest": "^3.2.4",
|
|
80
|
-
"@fluojs/platform-bun": "^1.0.6",
|
|
81
80
|
"@fluojs/platform-express": "^1.0.6",
|
|
82
|
-
"@fluojs/platform-
|
|
83
|
-
"@fluojs/
|
|
81
|
+
"@fluojs/platform-bun": "^1.0.7",
|
|
82
|
+
"@fluojs/platform-fastify": "^1.0.8",
|
|
83
|
+
"@fluojs/testing": "^1.0.6"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
86
|
"prebuild": "node ../../tooling/scripts/clean-dist.mjs",
|