@vercube/ws 0.0.23 → 0.0.25
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/dist/index.mjs +23 -63
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1,36 +1,9 @@
|
|
|
1
|
-
import "node:module";
|
|
2
1
|
import { BadRequestError, BasePlugin, HttpServer, ValidationProvider, initializeMetadata, initializeMetadataMethod } from "@vercube/core";
|
|
3
2
|
import { BaseDecorator, Identity, Inject, InjectOptional, createDecorator } from "@vercube/di";
|
|
4
3
|
import { Logger } from "@vercube/logger";
|
|
5
4
|
import { defineHooks } from "crossws";
|
|
6
5
|
import { plugin } from "crossws/server";
|
|
7
6
|
|
|
8
|
-
//#region rolldown:runtime
|
|
9
|
-
var __create = Object.create;
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
14
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
-
var __commonJS = (cb, mod) => function() {
|
|
16
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
17
|
-
};
|
|
18
|
-
var __copyProps = (to, from, except, desc) => {
|
|
19
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
20
|
-
key = keys[i];
|
|
21
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
22
|
-
get: ((k) => from[k]).bind(null, key),
|
|
23
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return to;
|
|
27
|
-
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
29
|
-
value: mod,
|
|
30
|
-
enumerable: true
|
|
31
|
-
}) : target, mod));
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
7
|
//#region src/Decorators/Namespace.ts
|
|
35
8
|
/**
|
|
36
9
|
* A decorator function for defining a websocket namespace and accepting websocket connections.
|
|
@@ -55,29 +28,24 @@ function Namespace(path) {
|
|
|
55
28
|
//#region src/Types/WebsocketTypes.ts
|
|
56
29
|
let WebsocketTypes;
|
|
57
30
|
(function(_WebsocketTypes) {
|
|
58
|
-
|
|
59
|
-
HandlerAction
|
|
60
|
-
HandlerAction
|
|
61
|
-
return HandlerAction
|
|
31
|
+
_WebsocketTypes.HandlerAction = /* @__PURE__ */ function(HandlerAction) {
|
|
32
|
+
HandlerAction["CONNECTION"] = "connection";
|
|
33
|
+
HandlerAction["MESSAGE"] = "message";
|
|
34
|
+
return HandlerAction;
|
|
62
35
|
}({});
|
|
63
|
-
_WebsocketTypes.HandlerAction = HandlerAction;
|
|
64
36
|
})(WebsocketTypes || (WebsocketTypes = {}));
|
|
65
37
|
|
|
66
38
|
//#endregion
|
|
67
|
-
//#region
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
module.exports = __decorate, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
76
|
-
}) });
|
|
39
|
+
//#region \0@oxc-project+runtime@0.94.0/helpers/decorate.js
|
|
40
|
+
function __decorate(decorators, target, key, desc) {
|
|
41
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
43
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
44
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
45
|
+
}
|
|
77
46
|
|
|
78
47
|
//#endregion
|
|
79
48
|
//#region src/Services/WebsocketService.ts
|
|
80
|
-
var import_decorate$5 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
81
49
|
/**
|
|
82
50
|
* WebsocketService class responsible for dealing with Websocket connections.
|
|
83
51
|
*
|
|
@@ -181,20 +149,18 @@ var WebsocketService = class {
|
|
|
181
149
|
* @returns {void}
|
|
182
150
|
*/
|
|
183
151
|
initialize() {
|
|
184
|
-
const
|
|
152
|
+
const serverPlugin = plugin(defineHooks({
|
|
185
153
|
upgrade: async (request) => {
|
|
186
154
|
const url = new URL(request.url);
|
|
187
155
|
const namespace = url.pathname;
|
|
188
156
|
const parameters = Object.fromEntries(url.searchParams.entries());
|
|
189
|
-
|
|
190
|
-
if (!isNamespaceRegistered) {
|
|
157
|
+
if (!!!this.fNamespaces?.[namespace?.toLowerCase()]) {
|
|
191
158
|
this.gLogger?.warn("WebsocketService::initialize", `Namespace "${namespace}" is not registered. Connection rejected.`);
|
|
192
159
|
return new Response("Namespace not registered", { status: 403 });
|
|
193
160
|
}
|
|
194
161
|
const handler = this.fHandlers[WebsocketTypes.HandlerAction.CONNECTION]?.[namespace];
|
|
195
162
|
if (handler) try {
|
|
196
|
-
|
|
197
|
-
if (result === false) return new Response("Unauthorized", { status: 403 });
|
|
163
|
+
if (await handler.callback(parameters, request) === false) return new Response("Unauthorized", { status: 403 });
|
|
198
164
|
} catch (error) {
|
|
199
165
|
if (error instanceof Error) return new Response(error.message, { status: 403 });
|
|
200
166
|
return new Response("Unknown error", { status: 403 });
|
|
@@ -221,8 +187,7 @@ var WebsocketService = class {
|
|
|
221
187
|
error: async (peer, error) => {
|
|
222
188
|
this.gLogger?.error("WebsocketService::initialize", `Error: ${error.message}`, { peer });
|
|
223
189
|
}
|
|
224
|
-
});
|
|
225
|
-
const serverPlugin = plugin(hooks);
|
|
190
|
+
}));
|
|
226
191
|
this.gHttpServer.addPlugin(serverPlugin);
|
|
227
192
|
}
|
|
228
193
|
/**
|
|
@@ -257,9 +222,9 @@ var WebsocketService = class {
|
|
|
257
222
|
}
|
|
258
223
|
}
|
|
259
224
|
};
|
|
260
|
-
(
|
|
261
|
-
(
|
|
262
|
-
(
|
|
225
|
+
__decorate([Inject(HttpServer)], WebsocketService.prototype, "gHttpServer", void 0);
|
|
226
|
+
__decorate([InjectOptional(ValidationProvider)], WebsocketService.prototype, "gValidationProvider", void 0);
|
|
227
|
+
__decorate([InjectOptional(Logger)], WebsocketService.prototype, "gLogger", void 0);
|
|
263
228
|
|
|
264
229
|
//#endregion
|
|
265
230
|
//#region src/Symbols/WebsocketSymbols.ts
|
|
@@ -267,7 +232,6 @@ const $WebsocketService = Identity("WebsocketService");
|
|
|
267
232
|
|
|
268
233
|
//#endregion
|
|
269
234
|
//#region src/Decorators/Message.ts
|
|
270
|
-
var import_decorate$4 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
271
235
|
/**
|
|
272
236
|
* A decorator class for listening to websocket messages under
|
|
273
237
|
* a specific event.
|
|
@@ -303,7 +267,7 @@ var MessageDecorator = class extends BaseDecorator {
|
|
|
303
267
|
});
|
|
304
268
|
}
|
|
305
269
|
};
|
|
306
|
-
(
|
|
270
|
+
__decorate([InjectOptional($WebsocketService)], MessageDecorator.prototype, "gWebsocketService", void 0);
|
|
307
271
|
/**
|
|
308
272
|
* A decorator function for listening to websocket messages under a specific event.
|
|
309
273
|
*
|
|
@@ -319,7 +283,6 @@ function Message(params) {
|
|
|
319
283
|
|
|
320
284
|
//#endregion
|
|
321
285
|
//#region src/Decorators/Emit.ts
|
|
322
|
-
var import_decorate$3 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
323
286
|
/**
|
|
324
287
|
* A decorator class for emitting websocket messages to the peer.
|
|
325
288
|
*
|
|
@@ -348,7 +311,7 @@ var EmitDecorator = class extends BaseDecorator {
|
|
|
348
311
|
};
|
|
349
312
|
}
|
|
350
313
|
};
|
|
351
|
-
(
|
|
314
|
+
__decorate([InjectOptional($WebsocketService)], EmitDecorator.prototype, "gWebsocketService", void 0);
|
|
352
315
|
/**
|
|
353
316
|
* A decorator function for emitting websocket messages to the peer.
|
|
354
317
|
*
|
|
@@ -364,7 +327,6 @@ function Emit(event) {
|
|
|
364
327
|
|
|
365
328
|
//#endregion
|
|
366
329
|
//#region src/Decorators/Broadcast.ts
|
|
367
|
-
var import_decorate$2 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
368
330
|
/**
|
|
369
331
|
* A decorator class for broadcasting websocket messages to everyone
|
|
370
332
|
* on the namespace (including the peer).
|
|
@@ -394,7 +356,7 @@ var BroadcastDecorator = class extends BaseDecorator {
|
|
|
394
356
|
};
|
|
395
357
|
}
|
|
396
358
|
};
|
|
397
|
-
(
|
|
359
|
+
__decorate([InjectOptional($WebsocketService)], BroadcastDecorator.prototype, "gWebsocketService", void 0);
|
|
398
360
|
/**
|
|
399
361
|
* A decorator function for broadcasting websocket messages to everyone on the namespace (including the peer).
|
|
400
362
|
*
|
|
@@ -410,7 +372,6 @@ function Broadcast(event) {
|
|
|
410
372
|
|
|
411
373
|
//#endregion
|
|
412
374
|
//#region src/Decorators/BroadcastOthers.ts
|
|
413
|
-
var import_decorate$1 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
414
375
|
/**
|
|
415
376
|
* A decorator class for broadcasting websocket messages to everyone
|
|
416
377
|
* on the namespace (except the peer).
|
|
@@ -441,7 +402,7 @@ var BroadcastOthersDecorator = class extends BaseDecorator {
|
|
|
441
402
|
};
|
|
442
403
|
}
|
|
443
404
|
};
|
|
444
|
-
(
|
|
405
|
+
__decorate([InjectOptional($WebsocketService)], BroadcastOthersDecorator.prototype, "gWebsocketService", void 0);
|
|
445
406
|
/**
|
|
446
407
|
* A decorator function for broadcasting websocket messages to everyone on the namespace (except the peer).
|
|
447
408
|
*
|
|
@@ -457,7 +418,6 @@ function BroadcastOthers(event) {
|
|
|
457
418
|
|
|
458
419
|
//#endregion
|
|
459
420
|
//#region src/Decorators/OnConnectionAttempt.ts
|
|
460
|
-
var import_decorate = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
461
421
|
/**
|
|
462
422
|
* A decorator class for handling websocket connection attempts.
|
|
463
423
|
*
|
|
@@ -492,7 +452,7 @@ var OnConnectionAttemptDecorator = class extends BaseDecorator {
|
|
|
492
452
|
this.gWebsocketService.registerHandler(WebsocketTypes.HandlerAction.CONNECTION, namespace, { callback: originalMethod });
|
|
493
453
|
}
|
|
494
454
|
};
|
|
495
|
-
(
|
|
455
|
+
__decorate([InjectOptional($WebsocketService)], OnConnectionAttemptDecorator.prototype, "gWebsocketService", void 0);
|
|
496
456
|
/**
|
|
497
457
|
* A decorator function for handling websocket connection attempts to a namespace.
|
|
498
458
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercube/ws",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
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.
|
|
21
|
+
"zod": "4.1.12"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"crossws": "0.4.1",
|
|
25
|
-
"srvx": "0.8.
|
|
26
|
-
"@vercube/logger": "0.0.
|
|
27
|
-
"@vercube/
|
|
28
|
-
"@vercube/
|
|
25
|
+
"srvx": "0.8.15",
|
|
26
|
+
"@vercube/logger": "0.0.25",
|
|
27
|
+
"@vercube/di": "0.0.25",
|
|
28
|
+
"@vercube/core": "0.0.25"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|