@fluojs/socket.io 1.0.0-beta.1

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.
@@ -0,0 +1,5 @@
1
+ export * from './adapter.js';
2
+ export * from './module.js';
3
+ export { SOCKETIO_ROOM_SERVICE, SOCKETIO_SERVER } from './tokens.js';
4
+ export * from './types.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACrE,cAAc,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './adapter.js';
2
+ export * from './module.js';
3
+ export { SOCKETIO_ROOM_SERVICE, SOCKETIO_SERVER } from './tokens.js';
4
+ export * from './types.js';
@@ -0,0 +1,26 @@
1
+ import { type ModuleType } from '@fluojs/runtime';
2
+ import type { SocketIoModuleOptions } from './types.js';
3
+ /**
4
+ * Root module entry point for registering the Socket.IO gateway adapter.
5
+ */
6
+ export declare class SocketIoModule {
7
+ /**
8
+ * Creates a global module that exposes the raw Socket.IO server and room service tokens.
9
+ *
10
+ * @param options Socket.IO adapter options applied to the lifecycle service for this module instance.
11
+ * @returns A runtime module definition that can be imported into an application module.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { Module } from '@fluojs/core';
16
+ * import { SocketIoModule } from '@fluojs/socket.io';
17
+ *
18
+ * @Module({
19
+ * imports: [SocketIoModule.forRoot()],
20
+ * })
21
+ * export class AppModule {}
22
+ * ```
23
+ */
24
+ static forRoot(options?: SocketIoModuleOptions): ModuleType;
25
+ }
26
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAQhE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAwBxD;;GAEG;AACH,qBAAa,cAAc;IACzB;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,qBAA0B,GAAG,UAAU;CAShE"}
package/dist/module.js ADDED
@@ -0,0 +1,51 @@
1
+ import { defineModule } from '@fluojs/runtime';
2
+ import { SOCKETIO_OPTIONS_INTERNAL } from './options-token.internal.js';
3
+ import { SocketIoLifecycleService } from './adapter.js';
4
+ import { SOCKETIO_ROOM_SERVICE, SOCKETIO_SERVER } from './tokens.js';
5
+ function createSocketIoProviderSet(options = {}) {
6
+ return [{
7
+ provide: SOCKETIO_OPTIONS_INTERNAL,
8
+ useValue: options
9
+ }, {
10
+ provide: SocketIoLifecycleService,
11
+ useClass: SocketIoLifecycleService
12
+ }, {
13
+ provide: SOCKETIO_SERVER,
14
+ useFactory: service => service.getServer(),
15
+ inject: [SocketIoLifecycleService]
16
+ }, {
17
+ provide: SOCKETIO_ROOM_SERVICE,
18
+ useExisting: SocketIoLifecycleService
19
+ }];
20
+ }
21
+
22
+ /**
23
+ * Root module entry point for registering the Socket.IO gateway adapter.
24
+ */
25
+ export class SocketIoModule {
26
+ /**
27
+ * Creates a global module that exposes the raw Socket.IO server and room service tokens.
28
+ *
29
+ * @param options Socket.IO adapter options applied to the lifecycle service for this module instance.
30
+ * @returns A runtime module definition that can be imported into an application module.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { Module } from '@fluojs/core';
35
+ * import { SocketIoModule } from '@fluojs/socket.io';
36
+ *
37
+ * @Module({
38
+ * imports: [SocketIoModule.forRoot()],
39
+ * })
40
+ * export class AppModule {}
41
+ * ```
42
+ */
43
+ static forRoot(options = {}) {
44
+ class SocketIoRuntimeModule extends SocketIoModule {}
45
+ return defineModule(SocketIoRuntimeModule, {
46
+ exports: [SOCKETIO_ROOM_SERVICE, SOCKETIO_SERVER],
47
+ global: true,
48
+ providers: createSocketIoProviderSet(options)
49
+ });
50
+ }
51
+ }
@@ -0,0 +1,7 @@
1
+ import type { Token } from '@fluojs/core';
2
+ import type { SocketIoModuleOptions } from './types.js';
3
+ /**
4
+ * Internal injection token for the Socket.IO module options.
5
+ */
6
+ export declare const SOCKETIO_OPTIONS_INTERNAL: Token<SocketIoModuleOptions>;
7
+ //# sourceMappingURL=options-token.internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options-token.internal.d.ts","sourceRoot":"","sources":["../src/options-token.internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,qBAAqB,CAAuC,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Internal injection token for the Socket.IO module options.
3
+ */
4
+ export const SOCKETIO_OPTIONS_INTERNAL = Symbol.for('fluo.socketio.options');
@@ -0,0 +1,12 @@
1
+ import type { Token } from '@fluojs/core';
2
+ import type { Server } from 'socket.io';
3
+ import type { SocketIoRoomService } from './types.js';
4
+ /**
5
+ * Injection token for the raw Socket.IO `Server` instance managed by {@link SocketIoModule}.
6
+ */
7
+ export declare const SOCKETIO_SERVER: Token<Server>;
8
+ /**
9
+ * Injection token for the high-level room management service exposed by {@link SocketIoModule}.
10
+ */
11
+ export declare const SOCKETIO_ROOM_SERVICE: Token<SocketIoRoomService>;
12
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,MAAM,CAAsC,CAAC;AAEjF;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,mBAAmB,CAA4C,CAAC"}
package/dist/tokens.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Injection token for the raw Socket.IO `Server` instance managed by {@link SocketIoModule}.
3
+ */
4
+ export const SOCKETIO_SERVER = Symbol.for('fluo.socketio.server');
5
+
6
+ /**
7
+ * Injection token for the high-level room management service exposed by {@link SocketIoModule}.
8
+ */
9
+ export const SOCKETIO_ROOM_SERVICE = Symbol.for('fluo.socketio.room-service');
@@ -0,0 +1,124 @@
1
+ import type { IncomingMessage } from 'node:http';
2
+ import type { ServerOptions, Socket } from 'socket.io';
3
+ import type { WebSocketRoomService } from '@fluojs/websockets';
4
+ /**
5
+ * Room management contract exposed by `@fluojs/socket.io` gateways.
6
+ *
7
+ * Extends the generic WebSocket room API with Socket.IO event emission semantics.
8
+ */
9
+ export interface SocketIoRoomService extends WebSocketRoomService {
10
+ /**
11
+ * Emits an event with payload data to every socket in one room.
12
+ *
13
+ * @param room Room identifier that should receive the event.
14
+ * @param event Socket.IO event name emitted to room members.
15
+ * @param data Payload delivered with the event.
16
+ * @param namespacePath Optional namespace path when broadcasting outside the default namespace.
17
+ */
18
+ broadcastToRoom(room: string, event: string, data: unknown, namespacePath?: string): void;
19
+ /**
20
+ * Adds one socket to a room.
21
+ *
22
+ * @param socketId Socket identifier to move into the room.
23
+ * @param room Room identifier to join.
24
+ * @param namespacePath Optional namespace path when targeting a non-default namespace.
25
+ */
26
+ joinRoom(socketId: string, room: string, namespacePath?: string): void;
27
+ /**
28
+ * Removes one socket from a room.
29
+ *
30
+ * @param socketId Socket identifier to remove from the room.
31
+ * @param room Room identifier to leave.
32
+ * @param namespacePath Optional namespace path when targeting a non-default namespace.
33
+ */
34
+ leaveRoom(socketId: string, room: string, namespacePath?: string): void;
35
+ }
36
+ /**
37
+ * Rejection details returned by Socket.IO auth guards when a connection or message should be blocked.
38
+ */
39
+ export interface SocketIoGuardRejection {
40
+ /** Optional structured payload forwarded to `connect_error` or acknowledgement callbacks. */
41
+ data?: unknown;
42
+ /** When `true`, rejected message events disconnect the current socket after the rejection is reported. */
43
+ disconnect?: boolean;
44
+ /** Caller-visible reason reported for the rejected operation. */
45
+ message?: string;
46
+ }
47
+ /**
48
+ * Runtime context passed to Socket.IO connection guards before gateway connect handlers execute.
49
+ */
50
+ export interface SocketIoConnectionGuardContext {
51
+ /** Count of active Socket.IO connections already accepted by this lifecycle service. */
52
+ activeConnectionCount: number;
53
+ /** Namespace path currently being connected, normalized to the Socket.IO gateway path contract. */
54
+ namespacePath: string;
55
+ /** Raw HTTP handshake request exposed by the selected Socket.IO runtime. */
56
+ request: IncomingMessage;
57
+ /** Socket.IO socket instance under evaluation. */
58
+ socket: Socket;
59
+ }
60
+ /**
61
+ * Guard function that can reject one Socket.IO namespace connection before gateway lifecycle hooks run.
62
+ */
63
+ export type SocketIoConnectionGuard = (context: SocketIoConnectionGuardContext) => Promise<boolean | SocketIoGuardRejection | void> | boolean | SocketIoGuardRejection | void;
64
+ /**
65
+ * Runtime context passed to Socket.IO message guards before matched gateway message handlers execute.
66
+ */
67
+ export interface SocketIoMessageGuardContext {
68
+ /** Number of active Socket.IO connections already accepted by this lifecycle service. */
69
+ activeConnectionCount: number;
70
+ /** Socket.IO event name currently being dispatched. */
71
+ event: string;
72
+ /** Namespace path that received the event. */
73
+ namespacePath: string;
74
+ /** Event payload extracted from the Socket.IO argument list. */
75
+ payload: unknown;
76
+ /** Raw HTTP handshake request associated with the current socket. */
77
+ request: IncomingMessage;
78
+ /** Socket.IO socket instance emitting the event. */
79
+ socket: Socket;
80
+ }
81
+ /**
82
+ * Guard function that can reject one inbound Socket.IO event before gateway message handlers execute.
83
+ */
84
+ export type SocketIoMessageGuard = (context: SocketIoMessageGuardContext) => Promise<boolean | SocketIoGuardRejection | void> | boolean | SocketIoGuardRejection | void;
85
+ /**
86
+ * Options accepted by {@link SocketIoModule.forRoot}.
87
+ */
88
+ export interface SocketIoModuleOptions {
89
+ /**
90
+ * Optional auth guards evaluated before namespace connections and inbound message handlers proceed.
91
+ */
92
+ auth?: {
93
+ /** Rejects namespace connections before `@OnConnect()` handlers execute. */
94
+ connection?: SocketIoConnectionGuard;
95
+ /** Rejects inbound events before matching `@OnMessage(...)` handlers execute. */
96
+ message?: SocketIoMessageGuard;
97
+ };
98
+ /**
99
+ * In-memory outbound buffering controls applied before the server flushes messages to sockets.
100
+ */
101
+ buffer?: {
102
+ /** Maximum number of queued outbound messages allowed per socket before overflow handling applies. */
103
+ maxPendingMessagesPerSocket?: number;
104
+ /** Strategy used when one socket exceeds the configured pending message cap. */
105
+ overflowPolicy?: 'close' | 'drop-newest' | 'drop-oldest';
106
+ };
107
+ /** Cross-origin configuration forwarded to the underlying Socket.IO server. */
108
+ cors?: ServerOptions['cors'];
109
+ /**
110
+ * Engine-level bounds forwarded to Socket.IO's underlying Engine.IO server.
111
+ */
112
+ engine?: {
113
+ /** Maximum accepted inbound payload size in bytes before Engine.IO rejects the request or frame. */
114
+ maxHttpBufferSize?: number;
115
+ };
116
+ /** Graceful shutdown controls for draining Socket.IO resources during application close. */
117
+ shutdown?: {
118
+ /** Maximum time to wait for shutdown cleanup before forceful termination. */
119
+ timeoutMs?: number;
120
+ };
121
+ /** Enabled Socket.IO transports such as `websocket` or `polling`. */
122
+ transports?: ServerOptions['transports'];
123
+ }
124
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,E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",
3
+ "description": "Socket.IO v4 gateway adapter for Fluo applications, built on the shared runtime and websocket decorators.",
4
+ "keywords": [
5
+ "fluo",
6
+ "socket.io",
7
+ "websocket",
8
+ "gateway",
9
+ "realtime",
10
+ "platform"
11
+ ],
12
+ "version": "1.0.0-beta.1",
13
+ "private": false,
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/fluojs/fluo.git",
18
+ "directory": "packages/socket.io"
19
+ },
20
+ "engines": {
21
+ "node": ">=20.0.0"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "type": "module",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js"
31
+ }
32
+ },
33
+ "main": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "dependencies": {
39
+ "@socket.io/bun-engine": "^0.1.0",
40
+ "@fluojs/core": "^1.0.0-beta.1",
41
+ "@fluojs/runtime": "^1.0.0-beta.1",
42
+ "@fluojs/http": "^1.0.0-beta.1",
43
+ "@fluojs/websockets": "^1.0.0-beta.1",
44
+ "@fluojs/di": "^1.0.0-beta.1"
45
+ },
46
+ "peerDependencies": {
47
+ "socket.io": "^4.0.0"
48
+ },
49
+ "devDependencies": {
50
+ "socket.io": "^4.8.1",
51
+ "socket.io-client": "^4.8.1",
52
+ "vitest": "^3.2.4",
53
+ "@fluojs/platform-express": "^1.0.0-beta.1",
54
+ "@fluojs/platform-fastify": "^1.0.0-beta.1",
55
+ "@fluojs/platform-nodejs": "^1.0.0-beta.1"
56
+ },
57
+ "scripts": {
58
+ "prebuild": "node ../../tooling/scripts/clean-dist.mjs",
59
+ "build": "pnpm exec babel src --extensions .ts --ignore 'src/**/*.test.ts' --out-dir dist --config-file ../../tooling/babel/babel.config.cjs && pnpm exec tsc -p tsconfig.build.json",
60
+ "typecheck": "pnpm exec tsc -p tsconfig.json --noEmit",
61
+ "test": "pnpm exec vitest run -c vitest.config.ts",
62
+ "test:watch": "pnpm exec vitest -c vitest.config.ts"
63
+ }
64
+ }