@eleven-am/pondsocket 0.1.213 → 0.1.215

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,34 @@
1
+ import { ChannelEvent, PondPath } from '@eleven-am/pondsocket-common';
2
+ import { WebSocket } from 'ws';
3
+ import { AuthorizationHandler, SocketCache } from '../abstracts/types';
4
+ import { IDistributedBackend } from '../types';
5
+ import { PondChannel } from '../wrappers/pondChannel';
6
+ export declare class EndpointEngine {
7
+ #private;
8
+ readonly path: string;
9
+ constructor(path: string, backend: IDistributedBackend | null, maxMessageSize?: number);
10
+ /**
11
+ * Creates a new channel on a specified path
12
+ */
13
+ createChannel<Path extends string>(path: PondPath<Path>, handler: AuthorizationHandler<Path>): PondChannel;
14
+ /**
15
+ * Gets all connected clients
16
+ */
17
+ getClients(): SocketCache[];
18
+ /**
19
+ * Gets a specific user by client ID
20
+ */
21
+ getUser(clientId: string): SocketCache;
22
+ /**
23
+ * Manages a new WebSocket connection
24
+ */
25
+ manageSocket(cache: SocketCache): void;
26
+ /**
27
+ * Sends a message to a WebSocket
28
+ */
29
+ sendMessage(socket: WebSocket, message: ChannelEvent): void;
30
+ /**
31
+ * Closes one or more client connections
32
+ */
33
+ closeConnection(clientIds: string | string[]): void;
34
+ }
@@ -10,10 +10,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _EndpointEngine_instances, _EndpointEngine_sockets, _EndpointEngine_backend, _EndpointEngine_middleware, _EndpointEngine_lobbyEngines, _EndpointEngine_handleSocketClose, _EndpointEngine_handleMessage, _EndpointEngine_joinChannel, _EndpointEngine_leaveChannel, _EndpointEngine_retrieveChannel, _EndpointEngine_buildError, _EndpointEngine_broadcastMessage, _EndpointEngine_readMessage;
13
+ var _EndpointEngine_instances, _EndpointEngine_sockets, _EndpointEngine_backend, _EndpointEngine_middleware, _EndpointEngine_lobbyEngines, _EndpointEngine_maxMessageSize, _EndpointEngine_handleSocketClose, _EndpointEngine_handleMessage, _EndpointEngine_joinChannel, _EndpointEngine_leaveChannel, _EndpointEngine_retrieveChannel, _EndpointEngine_buildError, _EndpointEngine_broadcastMessage, _EndpointEngine_readMessage;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.EndpointEngine = void 0;
16
16
  const pondsocket_common_1 = require("@eleven-am/pondsocket-common");
17
+ const ws_1 = require("ws");
17
18
  const lobbyEngine_1 = require("./lobbyEngine");
18
19
  const middleware_1 = require("../abstracts/middleware");
19
20
  const joinContext_1 = require("../contexts/joinContext");
@@ -21,17 +22,19 @@ const httpError_1 = require("../errors/httpError");
21
22
  const matcher_1 = require("../matcher/matcher");
22
23
  const pondChannel_1 = require("../wrappers/pondChannel");
23
24
  class EndpointEngine {
24
- constructor(path, backend) {
25
+ constructor(path, backend, maxMessageSize = 1024 * 1024) {
25
26
  _EndpointEngine_instances.add(this);
26
27
  this.path = path;
27
28
  _EndpointEngine_sockets.set(this, void 0);
28
29
  _EndpointEngine_backend.set(this, void 0);
29
30
  _EndpointEngine_middleware.set(this, void 0);
30
31
  _EndpointEngine_lobbyEngines.set(this, void 0);
32
+ _EndpointEngine_maxMessageSize.set(this, void 0);
31
33
  __classPrivateFieldSet(this, _EndpointEngine_sockets, new Map(), "f");
32
34
  __classPrivateFieldSet(this, _EndpointEngine_lobbyEngines, new Map(), "f");
33
35
  __classPrivateFieldSet(this, _EndpointEngine_middleware, new middleware_1.Middleware(), "f");
34
36
  __classPrivateFieldSet(this, _EndpointEngine_backend, backend || null, "f");
37
+ __classPrivateFieldSet(this, _EndpointEngine_maxMessageSize, maxMessageSize, "f");
35
38
  }
36
39
  /**
37
40
  * Creates a new channel on a specified path
@@ -79,7 +82,7 @@ class EndpointEngine {
79
82
  __classPrivateFieldGet(this, _EndpointEngine_sockets, "f").set(cache.clientId, cache);
80
83
  cache.socket.on('message', (message) => __classPrivateFieldGet(this, _EndpointEngine_instances, "m", _EndpointEngine_readMessage).call(this, cache, message));
81
84
  cache.socket.on('close', () => __classPrivateFieldGet(this, _EndpointEngine_instances, "m", _EndpointEngine_handleSocketClose).call(this, cache));
82
- cache.socket.on('error', () => __classPrivateFieldGet(this, _EndpointEngine_instances, "m", _EndpointEngine_handleSocketClose).call(this, cache));
85
+ cache.socket.on('error', () => { });
83
86
  const event = {
84
87
  event: pondsocket_common_1.Events.CONNECTION,
85
88
  action: pondsocket_common_1.ServerActions.CONNECT,
@@ -93,7 +96,9 @@ class EndpointEngine {
93
96
  * Sends a message to a WebSocket
94
97
  */
95
98
  sendMessage(socket, message) {
96
- socket.send(JSON.stringify(message));
99
+ if (socket.readyState === ws_1.WebSocket.OPEN) {
100
+ socket.send(JSON.stringify(message));
101
+ }
97
102
  }
98
103
  /**
99
104
  * Closes one or more client connections
@@ -109,13 +114,13 @@ class EndpointEngine {
109
114
  }
110
115
  }
111
116
  exports.EndpointEngine = EndpointEngine;
112
- _EndpointEngine_sockets = new WeakMap(), _EndpointEngine_backend = new WeakMap(), _EndpointEngine_middleware = new WeakMap(), _EndpointEngine_lobbyEngines = new WeakMap(), _EndpointEngine_instances = new WeakSet(), _EndpointEngine_handleSocketClose = function _EndpointEngine_handleSocketClose(cache) {
117
+ _EndpointEngine_sockets = new WeakMap(), _EndpointEngine_backend = new WeakMap(), _EndpointEngine_middleware = new WeakMap(), _EndpointEngine_lobbyEngines = new WeakMap(), _EndpointEngine_maxMessageSize = new WeakMap(), _EndpointEngine_instances = new WeakSet(), _EndpointEngine_handleSocketClose = function _EndpointEngine_handleSocketClose(cache) {
113
118
  try {
114
119
  __classPrivateFieldGet(this, _EndpointEngine_sockets, "f").delete(cache.clientId);
115
120
  cache.subscriptions.forEach((unsubscribe) => unsubscribe());
116
121
  }
117
- catch (e) {
118
- // no-op
122
+ catch (_a) {
123
+ void 0;
119
124
  }
120
125
  }, _EndpointEngine_handleMessage = function _EndpointEngine_handleMessage(cache, message) {
121
126
  switch (message.action) {
@@ -181,6 +186,9 @@ _EndpointEngine_sockets = new WeakMap(), _EndpointEngine_backend = new WeakMap()
181
186
  engine.broadcastMessage(socket.clientId, message);
182
187
  }, _EndpointEngine_readMessage = function _EndpointEngine_readMessage(cache, message) {
183
188
  try {
189
+ if (message.length > __classPrivateFieldGet(this, _EndpointEngine_maxMessageSize, "f")) {
190
+ throw new httpError_1.HttpError(413, `Message size ${message.length} exceeds maximum allowed size of ${__classPrivateFieldGet(this, _EndpointEngine_maxMessageSize, "f")} bytes`);
191
+ }
184
192
  const data = JSON.parse(message);
185
193
  const result = pondsocket_common_1.clientMessageSchema.parse(data);
186
194
  __classPrivateFieldGet(this, _EndpointEngine_instances, "m", _EndpointEngine_handleMessage).call(this, cache, result);
@@ -0,0 +1,54 @@
1
+ import { Event, PondPath } from '@eleven-am/pondsocket-common';
2
+ import { ChannelEngine } from './channelEngine';
3
+ import { EndpointEngine } from './endpointEngine';
4
+ import { Middleware } from '../abstracts/middleware';
5
+ import { BroadcastEvent, EventHandler, LeaveCallback, OutgoingEventHandler } from '../abstracts/types';
6
+ import { OutgoingContext } from '../contexts/outgoingContext';
7
+ import { IDistributedBackend } from '../types';
8
+ import { Channel } from '../wrappers/channel';
9
+ export declare class LobbyEngine {
10
+ #private;
11
+ parent: EndpointEngine;
12
+ leaveCallback: LeaveCallback | undefined;
13
+ readonly middleware: Middleware<BroadcastEvent, ChannelEngine>;
14
+ readonly outgoing: Middleware<OutgoingContext<string>, Event>;
15
+ constructor(parent: EndpointEngine, backend: IDistributedBackend | null);
16
+ /**
17
+ * Sets the callback for when users leave channels
18
+ */
19
+ onLeave(callback: LeaveCallback): void;
20
+ /**
21
+ * Attaches a handler for a specific event pattern
22
+ */
23
+ onEvent<Event extends string>(event: PondPath<Event>, handler: EventHandler<Event>): void;
24
+ /**
25
+ * Attaches a handler for outgoing events
26
+ */
27
+ handleOutgoingEvent<Event extends string>(event: PondPath<Event>, handler: OutgoingEventHandler<Event>): void;
28
+ /**
29
+ * Processes an outgoing event, applying middleware and returning a new event
30
+ * @param event - The channel event to process
31
+ * @param engine - The channel engine handling the event
32
+ * @param userId - The ID of the user sending the event
33
+ * @returns A new ChannelEvent or undefined if blocked
34
+ */
35
+ processOutgoingEvents(event: Event, engine: ChannelEngine, userId: string): Promise<Event | undefined>;
36
+ /**
37
+ * Gets or creates a channel by name
38
+ */
39
+ getOrCreateChannel(channelName: string): ChannelEngine;
40
+ /**
41
+ * Gets a channel by name
42
+ * @throws HttpError if a channel not found
43
+ */
44
+ getChannel(channelName: string): ChannelEngine;
45
+ /**
46
+ * Creates a Channel wrapper from a ChannelEngine
47
+ * Used by the channel engine for the leave callback
48
+ */
49
+ wrapChannel(engine: ChannelEngine): Channel;
50
+ /**
51
+ * Broadcasts an event to all users in a channel
52
+ */
53
+ deleteChannel(channelName: string): void;
54
+ }
@@ -73,7 +73,7 @@ class LobbyEngine {
73
73
  if (payload === undefined || payload === null) {
74
74
  return;
75
75
  }
76
- context.transform(Object.assign(Object.assign({}, chEvent), { payload }));
76
+ context.transform(payload);
77
77
  return next();
78
78
  }));
79
79
  }
@@ -0,0 +1,15 @@
1
+ import { PondPresence } from '@eleven-am/pondsocket-common';
2
+ import { InternalChannelEvent } from '../abstracts/types';
3
+ export type PublishCallback = (event: InternalChannelEvent) => void;
4
+ export declare class PresenceEngine {
5
+ #private;
6
+ constructor(channelId: string, publish: PublishCallback);
7
+ get presenceCount(): number;
8
+ trackPresence(userId: string, data: PondPresence): void;
9
+ updatePresence(userId: string, data: PondPresence): void;
10
+ removePresence(userId: string): void;
11
+ upsertPresence(userId: string, data: PondPresence): void;
12
+ getPresence(userId: string): PondPresence | null;
13
+ getAllPresence(): Map<string, PondPresence>;
14
+ close(): void;
15
+ }
@@ -10,102 +10,49 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _PresenceEngine_instances, _PresenceEngine_presenceCache, _PresenceEngine_publisher, _PresenceEngine_channelId, _PresenceEngine_processPresenceAction;
13
+ var _PresenceEngine_instances, _PresenceEngine_presenceCache, _PresenceEngine_publish, _PresenceEngine_channelId, _PresenceEngine_processPresenceAction;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.PresenceEngine = void 0;
16
16
  const pondsocket_common_1 = require("@eleven-am/pondsocket-common");
17
- /**
18
- * Manages user presence for a channel
19
- */
20
17
  class PresenceEngine {
21
- /**
22
- * Creates a new Presence manager
23
- * @param channelId - The ID of the channel this presence belongs to
24
- */
25
- constructor(channelId) {
18
+ constructor(channelId, publish) {
26
19
  _PresenceEngine_instances.add(this);
27
20
  _PresenceEngine_presenceCache.set(this, new Map());
28
- _PresenceEngine_publisher.set(this, new pondsocket_common_1.Subject());
21
+ _PresenceEngine_publish.set(this, void 0);
29
22
  _PresenceEngine_channelId.set(this, void 0);
30
23
  __classPrivateFieldSet(this, _PresenceEngine_channelId, channelId, "f");
24
+ __classPrivateFieldSet(this, _PresenceEngine_publish, publish, "f");
31
25
  }
32
- /**
33
- * Gets the number of users with presence data
34
- */
35
26
  get presenceCount() {
36
27
  return __classPrivateFieldGet(this, _PresenceEngine_presenceCache, "f").size;
37
28
  }
38
- /**
39
- * Track a new user's presence
40
- * @param userId - The ID of the user
41
- * @param data - The presence data
42
- * @returns The generated presence event
43
- */
44
29
  trackPresence(userId, data) {
45
30
  return __classPrivateFieldGet(this, _PresenceEngine_instances, "m", _PresenceEngine_processPresenceAction).call(this, pondsocket_common_1.PresenceEventTypes.JOIN, userId, data);
46
31
  }
47
- /**
48
- * Update an existing user's presence
49
- * @param userId - The ID of the user
50
- * @param data - The updated presence data
51
- * @returns The generated presence event
52
- */
53
32
  updatePresence(userId, data) {
54
33
  return __classPrivateFieldGet(this, _PresenceEngine_instances, "m", _PresenceEngine_processPresenceAction).call(this, pondsocket_common_1.PresenceEventTypes.UPDATE, userId, data);
55
34
  }
56
- /**
57
- * Remove a user's presence
58
- * @param userId - The ID of the user
59
- * @returns The generated presence event
60
- */
61
35
  removePresence(userId) {
62
36
  return __classPrivateFieldGet(this, _PresenceEngine_instances, "m", _PresenceEngine_processPresenceAction).call(this, pondsocket_common_1.PresenceEventTypes.LEAVE, userId, null);
63
37
  }
64
- /**
65
- * Add or update a user's presence
66
- * @param userId - The ID of the user
67
- * @param data - The presence data
68
- * @returns The generated presence event
69
- */
70
38
  upsertPresence(userId, data) {
71
39
  if (__classPrivateFieldGet(this, _PresenceEngine_presenceCache, "f").has(userId)) {
72
40
  return this.updatePresence(userId, data);
73
41
  }
74
42
  return this.trackPresence(userId, data);
75
43
  }
76
- /**
77
- * Get a specific user's presence
78
- * @param userId - The ID of the user
79
- * @returns The user's presence data or null if not found
80
- */
81
44
  getPresence(userId) {
82
45
  return __classPrivateFieldGet(this, _PresenceEngine_presenceCache, "f").get(userId) || null;
83
46
  }
84
- /**
85
- * Get presence data for all users
86
- * @returns A copy of all presence data
87
- */
88
47
  getAllPresence() {
89
48
  return new Map(__classPrivateFieldGet(this, _PresenceEngine_presenceCache, "f"));
90
49
  }
91
- /**
92
- * Subscribe to presence events
93
- * @param callback - The callback to invoke when presence changes
94
- * @returns A function to unsubscribe
95
- */
96
- subscribe(callback) {
97
- return __classPrivateFieldGet(this, _PresenceEngine_publisher, "f").subscribe(callback);
98
- }
99
- /**
100
- * Clear all presence data and close the publisher
101
- */
102
50
  close() {
103
51
  __classPrivateFieldGet(this, _PresenceEngine_presenceCache, "f").clear();
104
- __classPrivateFieldGet(this, _PresenceEngine_publisher, "f").close();
105
52
  }
106
53
  }
107
54
  exports.PresenceEngine = PresenceEngine;
108
- _PresenceEngine_presenceCache = new WeakMap(), _PresenceEngine_publisher = new WeakMap(), _PresenceEngine_channelId = new WeakMap(), _PresenceEngine_instances = new WeakSet(), _PresenceEngine_processPresenceAction = function _PresenceEngine_processPresenceAction(action, userId, data) {
55
+ _PresenceEngine_presenceCache = new WeakMap(), _PresenceEngine_publish = new WeakMap(), _PresenceEngine_channelId = new WeakMap(), _PresenceEngine_instances = new WeakSet(), _PresenceEngine_processPresenceAction = function _PresenceEngine_processPresenceAction(action, userId, data) {
109
56
  if (action === pondsocket_common_1.PresenceEventTypes.JOIN && __classPrivateFieldGet(this, _PresenceEngine_presenceCache, "f").has(userId)) {
110
57
  throw new Error(`User with id ${userId} already exists in the presence cache`);
111
58
  }
@@ -135,5 +82,5 @@ _PresenceEngine_presenceCache = new WeakMap(), _PresenceEngine_publisher = new W
135
82
  presence: total,
136
83
  },
137
84
  };
138
- __classPrivateFieldGet(this, _PresenceEngine_publisher, "f").publish(internalEvent);
85
+ __classPrivateFieldGet(this, _PresenceEngine_publish, "f").call(this, internalEvent);
139
86
  };
@@ -0,0 +1,6 @@
1
+ export declare class HttpError extends Error {
2
+ readonly statusCode: number;
3
+ readonly statusText: string;
4
+ constructor(statusCode: number, message: string);
5
+ static getStatusText(statusCode: number): "Bad Request" | "Unauthorized" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Conflict" | "Payload Too Large" | "Too Many Requests" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "Unknown Error";
6
+ }
@@ -24,6 +24,8 @@ class HttpError extends Error {
24
24
  return 'Not Acceptable';
25
25
  case 409:
26
26
  return 'Conflict';
27
+ case 413:
28
+ return 'Payload Too Large';
27
29
  case 429:
28
30
  return 'Too Many Requests';
29
31
  case 500:
package/index.d.ts CHANGED
@@ -1,5 +1,14 @@
1
- import { PondSocket } from './types';
2
-
3
- export { RedisDistributedBackend } from './types';
4
-
5
- export default PondSocket;
1
+ export { PondSocket } from './server/server';
2
+ export { RedisDistributedBackend } from './abstracts/distributor';
3
+ export { Endpoint } from './wrappers/endpoint';
4
+ export { PondChannel } from './wrappers/pondChannel';
5
+ export { Channel } from './wrappers/channel';
6
+ export { ConnectionContext } from './contexts/connectionContext';
7
+ export { BaseContext } from './contexts/baseContext';
8
+ export { JoinContext } from './contexts/joinContext';
9
+ export { EventContext } from './contexts/eventContext';
10
+ export { OutgoingContext } from './contexts/outgoingContext';
11
+ export { HttpError } from './errors/httpError';
12
+ export type { ConnectionHandler, AuthorizationHandler, EventHandler, OutgoingEventHandler, LeaveCallback, LeaveEvent, NextFunction, } from './abstracts/types';
13
+ export * from './types';
14
+ export * from '@eleven-am/pondsocket-common';
package/index.js CHANGED
@@ -1,7 +1,41 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisDistributedBackend = void 0;
4
- const server_1 = require("./server/server");
17
+ exports.HttpError = exports.OutgoingContext = exports.EventContext = exports.JoinContext = exports.BaseContext = exports.ConnectionContext = exports.Channel = exports.PondChannel = exports.Endpoint = exports.RedisDistributedBackend = exports.PondSocket = void 0;
18
+ var server_1 = require("./server/server");
19
+ Object.defineProperty(exports, "PondSocket", { enumerable: true, get: function () { return server_1.PondSocket; } });
5
20
  var distributor_1 = require("./abstracts/distributor");
6
21
  Object.defineProperty(exports, "RedisDistributedBackend", { enumerable: true, get: function () { return distributor_1.RedisDistributedBackend; } });
7
- exports.default = server_1.PondSocket;
22
+ var endpoint_1 = require("./wrappers/endpoint");
23
+ Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return endpoint_1.Endpoint; } });
24
+ var pondChannel_1 = require("./wrappers/pondChannel");
25
+ Object.defineProperty(exports, "PondChannel", { enumerable: true, get: function () { return pondChannel_1.PondChannel; } });
26
+ var channel_1 = require("./wrappers/channel");
27
+ Object.defineProperty(exports, "Channel", { enumerable: true, get: function () { return channel_1.Channel; } });
28
+ var connectionContext_1 = require("./contexts/connectionContext");
29
+ Object.defineProperty(exports, "ConnectionContext", { enumerable: true, get: function () { return connectionContext_1.ConnectionContext; } });
30
+ var baseContext_1 = require("./contexts/baseContext");
31
+ Object.defineProperty(exports, "BaseContext", { enumerable: true, get: function () { return baseContext_1.BaseContext; } });
32
+ var joinContext_1 = require("./contexts/joinContext");
33
+ Object.defineProperty(exports, "JoinContext", { enumerable: true, get: function () { return joinContext_1.JoinContext; } });
34
+ var eventContext_1 = require("./contexts/eventContext");
35
+ Object.defineProperty(exports, "EventContext", { enumerable: true, get: function () { return eventContext_1.EventContext; } });
36
+ var outgoingContext_1 = require("./contexts/outgoingContext");
37
+ Object.defineProperty(exports, "OutgoingContext", { enumerable: true, get: function () { return outgoingContext_1.OutgoingContext; } });
38
+ var httpError_1 = require("./errors/httpError");
39
+ Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return httpError_1.HttpError; } });
40
+ __exportStar(require("./types"), exports);
41
+ __exportStar(require("@eleven-am/pondsocket-common"), exports);
@@ -0,0 +1,2 @@
1
+ import { EventParams, PondPath } from '@eleven-am/pondsocket-common';
2
+ export declare function parseAddress<Path extends string>(route: PondPath<Path>, address: string): EventParams<Path> | null;
@@ -43,12 +43,12 @@ function getQuery(query) {
43
43
  if (!query) {
44
44
  return {};
45
45
  }
46
- const parts = query.split('&');
47
- return parts.reduce((params, part) => {
48
- const [key, value] = part.split('=');
46
+ const searchParams = new URLSearchParams(query);
47
+ const params = {};
48
+ searchParams.forEach((value, key) => {
49
49
  params[key] = value;
50
- return params;
51
- }, {});
50
+ });
51
+ return params;
52
52
  }
53
53
  function parseAddress(route, address) {
54
54
  if (route instanceof RegExp) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket",
3
- "version": "0.1.213",
3
+ "version": "0.1.215",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
@@ -17,11 +17,10 @@
17
17
  },
18
18
  "scripts": {
19
19
  "test": "jest --coverage --verbose --forceExit --detectOpenHandles --runInBand --bail",
20
- "build": "rimraf dist && tsc && npm run remove",
20
+ "build": "rimraf dist && tsc --project tsconfig.build.json && rm -rf dist/tests",
21
21
  "lint": "eslint --ext .ts src",
22
22
  "lint:fix": "eslint --fix --ext .ts src",
23
- "remove": "rm -r dist/tests && rm dist/distIndex.js",
24
- "copy": "cp src/types.d.ts dist/types.d.ts && cp src/distIndex.ts dist/index.d.ts && cp package.json dist && cp README.md dist && cp LICENSE dist",
23
+ "copy": "cp package.json dist && cp README.md dist && cp LICENSE dist",
25
24
  "push": "npm version patch && npm run copy && cd dist && npm publish && cd ..",
26
25
  "pipeline": "npm run lint:fix && npm run lint && npm run test && npm run build && npm run push"
27
26
  },
@@ -29,37 +28,47 @@
29
28
  "license": "GPL-3.0",
30
29
  "main": "./index.js",
31
30
  "types": "./index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./index.d.ts",
34
+ "default": "./index.js"
35
+ },
36
+ "./types": {
37
+ "types": "./index.d.ts",
38
+ "default": "./index.js"
39
+ }
40
+ },
32
41
  "repository": {
33
42
  "type": "git",
34
43
  "url": "git+https://github.com/Eleven-am/pondSocket.git"
35
44
  },
36
45
  "dependencies": {
37
- "@eleven-am/pondsocket-common": "^0.0.29",
38
- "redis": "^5.8.3",
39
- "ws": "^8.18.3"
46
+ "@eleven-am/pondsocket-common": "^0.0.37",
47
+ "redis": "^5.11.0",
48
+ "ws": "^8.19.0"
40
49
  },
41
50
  "devDependencies": {
42
51
  "@eslint/compat": "^1.4.0",
43
- "@eslint/eslintrc": "^3.3.1",
52
+ "@eslint/eslintrc": "^3.3.4",
44
53
  "@eslint/js": "^9.38.0",
45
54
  "@stylistic/eslint-plugin-ts": "^4.4.1",
46
55
  "@types/jest": "^30.0.0",
47
- "@types/node": "^24.8.1",
56
+ "@types/node": "^25.3.3",
48
57
  "@types/ws": "^8.18.1",
49
- "@typescript-eslint/eslint-plugin": "^8.46.1",
50
- "@typescript-eslint/parser": "^8.46.1",
58
+ "@typescript-eslint/eslint-plugin": "^8.56.1",
59
+ "@typescript-eslint/parser": "^8.56.1",
51
60
  "eslint": "^9.38.0",
52
61
  "eslint-config-prettier": "^10.1.8",
53
62
  "eslint-import-resolver-node": "^0.3.9",
54
63
  "eslint-plugin-file-progress": "^3.0.2",
55
64
  "eslint-plugin-import": "^2.32.0",
56
- "eslint-plugin-prettier": "^5.5.4",
65
+ "eslint-plugin-prettier": "^5.5.5",
57
66
  "globals": "^16.4.0",
58
67
  "jest": "^30.2.0",
59
- "prettier": "^3.6.2",
68
+ "prettier": "^3.8.1",
60
69
  "source-map-support": "^0.5.21",
61
- "supertest": "^7.1.4",
62
- "ts-jest": "^29.4.5",
70
+ "supertest": "^7.2.2",
71
+ "ts-jest": "^29.4.6",
63
72
  "ts-loader": "^9.5.4",
64
73
  "ts-node": "^10.9.2",
65
74
  "tsconfig-paths": "^4.2.0",
@@ -74,12 +83,26 @@
74
83
  "rootDir": "src",
75
84
  "testRegex": ".*\\.test\\.ts$",
76
85
  "transform": {
77
- "^.+\\.(t|j)s$": "ts-jest"
86
+ "^.+\\.(t|j)s$": [
87
+ "ts-jest",
88
+ {
89
+ "diagnostics": false
90
+ }
91
+ ]
78
92
  },
79
93
  "collectCoverageFrom": [
80
- "**/*.(t|j)s"
94
+ "**/*.(t|j)s",
95
+ "!**/*.test.ts",
96
+ "!**/*.d.ts",
97
+ "!**/index.ts",
98
+ "!**/tests/**",
99
+ "!**/types.d.ts",
100
+ "!**/abstracts/distributor.ts"
81
101
  ],
82
102
  "coverageDirectory": "../coverage",
83
- "testEnvironment": "node"
103
+ "testEnvironment": "node",
104
+ "moduleNameMapper": {
105
+ "^@eleven-am/pondsocket-common$": "<rootDir>/../../comnon/dist"
106
+ }
84
107
  }
85
108
  }
@@ -0,0 +1,21 @@
1
+ import { IncomingMessage, Server as HTTPServer } from 'http';
2
+ import { PondPath } from '@eleven-am/pondsocket-common';
3
+ import { ConnectionHandler } from '../abstracts/types';
4
+ import { PondSocketOptions } from '../types';
5
+ import { Endpoint } from '../wrappers/endpoint';
6
+ export declare class PondSocket {
7
+ #private;
8
+ constructor({ server, socketServer, exclusiveServer, distributedBackend, maxMessageSize, heartbeatInterval, }?: PondSocketOptions);
9
+ /**
10
+ * Start listening for connections
11
+ */
12
+ listen(...args: any[]): HTTPServer<typeof IncomingMessage, typeof import("node:http").ServerResponse>;
13
+ /**
14
+ * Close the server
15
+ */
16
+ close(callback?: (err?: Error) => void, timeout?: number): HTTPServer<typeof IncomingMessage, typeof import("node:http").ServerResponse>;
17
+ /**
18
+ * Create a new endpoint
19
+ */
20
+ createEndpoint<Path extends string>(path: PondPath<Path>, handler: ConnectionHandler<Path>): Endpoint;
21
+ }