@vercube/ws 0.0.34 → 0.0.36

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 CHANGED
@@ -1,34 +1,40 @@
1
1
  <div align="center">
2
- <a href="https://vercube.dev/"><img src="https://github.com/OskarLebuda/vue-lazy-hydration/raw/main/.github/assets/logo.png?raw=true" alt="Vite logo" width="200"></a>
2
+ <img src="https://raw.githubusercontent.com/vercube/vercube/refs/heads/main/.github/assets/cover.png" width="100%" alt="Vercube - Unleash your server development." />
3
3
  <br>
4
4
  <br>
5
5
 
6
- # Vercube
7
-
8
- Next generation HTTP framework
9
-
10
- <a href="https://www.npmjs.com/package/@vercube/auth">
11
- <img src="https://img.shields.io/npm/v/%40vercube%2Fauth?style=for-the-badge&logo=npm&color=%23767eff" alt="npm"/>
12
- </a>
13
- <a href="https://www.npmjs.com/package/@vercube/auth">
14
- <img src="https://img.shields.io/npm/dm/%40vercube%2Fauth?style=for-the-badge&logo=npm&color=%23767eff" alt="npm"/>
15
- </a>
16
- <a href="https://github.com/vercube/vercube/blob/main/LICENSE" target="_blank">
17
- <img src="https://img.shields.io/npm/l/%40vercube%2Fauth?style=for-the-badge&color=%23767eff" alt="License"/>
18
- </a>
19
- <a href="https://codecov.io/gh/vercube/vercube" target="_blank">
20
- <img src="https://img.shields.io/codecov/c/github/vercube/vercube?style=for-the-badge&color=%23767eff" alt="Coverage"/>
21
- </a>
22
- <br/>
23
- <br/>
6
+ # @vercube/ws
7
+
8
+ ### WebSockets for Vercube apps
9
+
10
+ [![Ask DeepWiki](<https://img.shields.io/badge/ask-deepwiki-%20blue?style=for-the-badge&logo=bookstack&logoColor=rgba(255%2C%20255%2C%20255%2C%200.6)&labelColor=%23000&color=%232f2f2f>)](https://deepwiki.com/vercube/vercube)
11
+ ![NPM Version](<https://img.shields.io/npm/v/%40vercube%2Fws?style=for-the-badge&logo=npm&logoColor=rgba(255%2C%20255%2C%20255%2C%200.6)&labelColor=%23000&color=%232e2e2e&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40vercube%2Fws>)
12
+ ![GitHub License](<https://img.shields.io/github/license/vercube/vercube?style=for-the-badge&logo=gitbook&logoColor=rgba(255%2C%20255%2C%20255%2C%200.6)&labelColor=%23000&color=%232f2f2f>)
13
+ ![Codecov](<https://img.shields.io/codecov/c/github/vercube/vercube?style=for-the-badge&logo=vitest&logoColor=rgba(255%2C%20255%2C%20255%2C%200.6)&labelColor=%23000&color=%232f2f2f>)
14
+
15
+ **Real-time communication with decorators - `@Message` to listen, `@Emit` to respond, `@Broadcast` to send to everyone. Built on [crossws](https://crossws.unjs.io/).**
16
+
17
+ [Website](https://vercube.dev) • [Documentation](https://vercube.dev/docs/getting-started)
18
+
24
19
  </div>
25
20
 
26
- An ultra-efficient JavaScript server framework that runs anywhere - Node.js, Bun, or Deno - with unmatched flexibility and complete configurability for developers who refuse to sacrifice speed or control.
21
+ ## Features
22
+
23
+ - **Decorator-based** - `@Namespace`, `@Message`, `@Emit`, `@Broadcast`
24
+ - **Connection control** - validate who can connect with `@OnConnectionAttempt`
25
+ - **Message validation** - use Zod schemas to validate incoming data
26
+ - **Namespaces** - organize connections into logical groups
27
+
28
+ ## 📦 Installation
29
+
30
+ ```bash
31
+ pnpm add @vercube/ws
32
+ ```
27
33
 
28
- ## <a name="module">Websocket module</a>
34
+ ## 📖 Usage
29
35
 
30
- The Websocket module enables you to set up websocket connections on your application. It offers a collection of decorators that enable you to listen to incoming messages, emit/broadcast messages and more. It works based on namespaces.
36
+ Check out the full [documentation](https://vercube.dev/docs/modules/web-sockets/overview)
31
37
 
32
- ## <a name="documentation">📖 Documentation</a>
38
+ ## 📜 License
33
39
 
34
- Comprehensive documentation is available at [vercube.dev](https://vercube.dev). There you'll find detailed module descriptions, project information, guides, and everything else you need to know about Vercube.
40
+ [MIT](https://github.com/vercube/vercube/blob/main/LICENSE)
package/dist/index.d.mts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { App, BasePlugin, ValidationTypes } from "@vercube/core";
2
- import { Peer } from "crossws";
2
+ import { Message as Message$1, Peer, WSError } from "crossws";
3
3
 
4
4
  //#region src/Decorators/Namespace.d.ts
5
-
6
5
  /**
7
6
  * A decorator function for defining a websocket namespace and accepting websocket connections.
8
7
  *
@@ -122,7 +121,7 @@ declare class WebsocketPlugin<T = unknown> extends BasePlugin<T> {
122
121
  declare namespace WebsocketTypes {
123
122
  enum HandlerAction {
124
123
  CONNECTION = "connection",
125
- MESSAGE = "message",
124
+ MESSAGE = "message"
126
125
  }
127
126
  type HandlerAttributes = {
128
127
  callback: Function;
@@ -176,7 +175,7 @@ declare class WebsocketService {
176
175
  /**
177
176
  * Broadcast a message to all peers in the same namespace (including the sender).
178
177
  *
179
- * @param {Peer} peer - The sender peer (used to determine the namespace).
178
+ * @param {WSPeer} peer - The sender peer (used to determine the namespace).
180
179
  * @param {unknown} message - The message to broadcast.
181
180
  * @returns {void}
182
181
  */
@@ -184,7 +183,7 @@ declare class WebsocketService {
184
183
  /**
185
184
  * Emit a message to a single peer.
186
185
  *
187
- * @param {Peer} peer - The peer to send the message to.
186
+ * @param {WSPeer} peer - The peer to send the message to.
188
187
  * @param {unknown} message - The message to send.
189
188
  * @returns {void}
190
189
  */
@@ -192,7 +191,7 @@ declare class WebsocketService {
192
191
  /**
193
192
  * Broadcast a message to all peers in the same namespace except the sender.
194
193
  *
195
- * @param {Peer} peer - The sender peer (used to determine the namespace).
194
+ * @param {WSPeer} peer - The sender peer (used to determine the namespace).
196
195
  * @param {unknown} message - The message to broadcast.
197
196
  * @returns {void}
198
197
  */
@@ -206,7 +205,7 @@ declare class WebsocketService {
206
205
  /**
207
206
  * Handle an incoming websocket message for a peer.
208
207
  *
209
- * @param {Peer} peer - The peer receiving the message.
208
+ * @param {WSPeer} peer - The peer receiving the message.
210
209
  * @param {Message} rawMessage - The raw websocket message.
211
210
  * @returns {Promise<void>}
212
211
  */
@@ -216,4 +215,4 @@ declare class WebsocketService {
216
215
  //#region src/Symbols/WebsocketSymbols.d.ts
217
216
  declare const $WebsocketService: symbol;
218
217
  //#endregion
219
- export { $WebsocketService, Broadcast, BroadcastOthers, Emit, Message, Namespace, OnConnectionAttempt, WebsocketPlugin, WebsocketService, WebsocketTypes };
218
+ export { $WebsocketService, Broadcast, BroadcastOthers, Emit, Message, Namespace, OnConnectionAttempt, type WSError, type Message$1 as WSMessage, type Peer as WSPeer, WebsocketPlugin, WebsocketService, WebsocketTypes };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { BadRequestError, BasePlugin, HttpServer, ValidationProvider, initializeMetadata, initializeMetadataMethod } from "@vercube/core";
1
+ import { BadRequestError, BasePlugin, HttpServer, ValidationProvider, initializeMetadata, initializeMetadataMethod, safeJsonParse, sanitizeObject } from "@vercube/core";
2
2
  import { BaseDecorator, Identity, Inject, InjectOptional, createDecorator } from "@vercube/di";
3
3
  import { Logger } from "@vercube/logger";
4
4
  import { defineHooks } from "crossws";
@@ -36,7 +36,7 @@ let WebsocketTypes;
36
36
  })(WebsocketTypes || (WebsocketTypes = {}));
37
37
 
38
38
  //#endregion
39
- //#region \0@oxc-project+runtime@0.99.0/helpers/decorate.js
39
+ //#region \0@oxc-project+runtime@0.110.0/helpers/decorate.js
40
40
  function __decorate(decorators, target, key, desc) {
41
41
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
42
42
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -108,7 +108,7 @@ var WebsocketService = class {
108
108
  /**
109
109
  * Broadcast a message to all peers in the same namespace (including the sender).
110
110
  *
111
- * @param {Peer} peer - The sender peer (used to determine the namespace).
111
+ * @param {WSPeer} peer - The sender peer (used to determine the namespace).
112
112
  * @param {unknown} message - The message to broadcast.
113
113
  * @returns {void}
114
114
  */
@@ -122,7 +122,7 @@ var WebsocketService = class {
122
122
  /**
123
123
  * Emit a message to a single peer.
124
124
  *
125
- * @param {Peer} peer - The peer to send the message to.
125
+ * @param {WSPeer} peer - The peer to send the message to.
126
126
  * @param {unknown} message - The message to send.
127
127
  * @returns {void}
128
128
  */
@@ -132,7 +132,7 @@ var WebsocketService = class {
132
132
  /**
133
133
  * Broadcast a message to all peers in the same namespace except the sender.
134
134
  *
135
- * @param {Peer} peer - The sender peer (used to determine the namespace).
135
+ * @param {WSPeer} peer - The sender peer (used to determine the namespace).
136
136
  * @param {unknown} message - The message to broadcast.
137
137
  * @returns {void}
138
138
  */
@@ -153,7 +153,7 @@ var WebsocketService = class {
153
153
  upgrade: async (request) => {
154
154
  const url = new URL(request.url);
155
155
  const namespace = url.pathname;
156
- const parameters = Object.fromEntries(url.searchParams.entries());
156
+ const parameters = sanitizeObject(Object.fromEntries(url.searchParams));
157
157
  if (!!!this.fNamespaces?.[namespace?.toLowerCase()]) {
158
158
  this.gLogger?.warn("WebsocketService::initialize", `Namespace "${namespace}" is not registered. Connection rejected.`);
159
159
  return new Response("Namespace not registered", { status: 403 });
@@ -193,13 +193,13 @@ var WebsocketService = class {
193
193
  /**
194
194
  * Handle an incoming websocket message for a peer.
195
195
  *
196
- * @param {Peer} peer - The peer receiving the message.
196
+ * @param {WSPeer} peer - The peer receiving the message.
197
197
  * @param {Message} rawMessage - The raw websocket message.
198
198
  * @returns {Promise<void>}
199
199
  */
200
200
  async handleMessage(peer, rawMessage) {
201
201
  try {
202
- const msg = JSON.parse(rawMessage.text());
202
+ const msg = safeJsonParse(rawMessage.text());
203
203
  const namespace = peer.namespace?.toLowerCase();
204
204
  const event = msg.event;
205
205
  const data = msg.data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercube/ws",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "description": "Websocket module for Vercube framework",
5
5
  "repository": "@vercube/ws",
6
6
  "license": "MIT",
@@ -18,14 +18,14 @@
18
18
  "README.md"
19
19
  ],
20
20
  "devDependencies": {
21
- "zod": "4.1.13"
21
+ "zod": "4.3.6"
22
22
  },
23
23
  "dependencies": {
24
- "crossws": "0.4.1",
25
- "srvx": "0.9.6",
26
- "@vercube/core": "0.0.34",
27
- "@vercube/di": "0.0.34",
28
- "@vercube/logger": "0.0.34"
24
+ "crossws": "0.4.3",
25
+ "srvx": "0.10.1",
26
+ "@vercube/core": "0.0.36",
27
+ "@vercube/di": "0.0.36",
28
+ "@vercube/logger": "0.0.36"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"