@vercube/ws 0.0.23 → 0.0.24
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 +21 -60
- package/package.json +5 -5
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.90.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
|
*
|
|
@@ -186,15 +154,13 @@ var WebsocketService = class {
|
|
|
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 });
|
|
@@ -257,9 +223,9 @@ var WebsocketService = class {
|
|
|
257
223
|
}
|
|
258
224
|
}
|
|
259
225
|
};
|
|
260
|
-
(
|
|
261
|
-
(
|
|
262
|
-
(
|
|
226
|
+
__decorate([Inject(HttpServer)], WebsocketService.prototype, "gHttpServer", void 0);
|
|
227
|
+
__decorate([InjectOptional(ValidationProvider)], WebsocketService.prototype, "gValidationProvider", void 0);
|
|
228
|
+
__decorate([InjectOptional(Logger)], WebsocketService.prototype, "gLogger", void 0);
|
|
263
229
|
|
|
264
230
|
//#endregion
|
|
265
231
|
//#region src/Symbols/WebsocketSymbols.ts
|
|
@@ -267,7 +233,6 @@ const $WebsocketService = Identity("WebsocketService");
|
|
|
267
233
|
|
|
268
234
|
//#endregion
|
|
269
235
|
//#region src/Decorators/Message.ts
|
|
270
|
-
var import_decorate$4 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
271
236
|
/**
|
|
272
237
|
* A decorator class for listening to websocket messages under
|
|
273
238
|
* a specific event.
|
|
@@ -303,7 +268,7 @@ var MessageDecorator = class extends BaseDecorator {
|
|
|
303
268
|
});
|
|
304
269
|
}
|
|
305
270
|
};
|
|
306
|
-
(
|
|
271
|
+
__decorate([InjectOptional($WebsocketService)], MessageDecorator.prototype, "gWebsocketService", void 0);
|
|
307
272
|
/**
|
|
308
273
|
* A decorator function for listening to websocket messages under a specific event.
|
|
309
274
|
*
|
|
@@ -319,7 +284,6 @@ function Message(params) {
|
|
|
319
284
|
|
|
320
285
|
//#endregion
|
|
321
286
|
//#region src/Decorators/Emit.ts
|
|
322
|
-
var import_decorate$3 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
323
287
|
/**
|
|
324
288
|
* A decorator class for emitting websocket messages to the peer.
|
|
325
289
|
*
|
|
@@ -348,7 +312,7 @@ var EmitDecorator = class extends BaseDecorator {
|
|
|
348
312
|
};
|
|
349
313
|
}
|
|
350
314
|
};
|
|
351
|
-
(
|
|
315
|
+
__decorate([InjectOptional($WebsocketService)], EmitDecorator.prototype, "gWebsocketService", void 0);
|
|
352
316
|
/**
|
|
353
317
|
* A decorator function for emitting websocket messages to the peer.
|
|
354
318
|
*
|
|
@@ -364,7 +328,6 @@ function Emit(event) {
|
|
|
364
328
|
|
|
365
329
|
//#endregion
|
|
366
330
|
//#region src/Decorators/Broadcast.ts
|
|
367
|
-
var import_decorate$2 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
368
331
|
/**
|
|
369
332
|
* A decorator class for broadcasting websocket messages to everyone
|
|
370
333
|
* on the namespace (including the peer).
|
|
@@ -394,7 +357,7 @@ var BroadcastDecorator = class extends BaseDecorator {
|
|
|
394
357
|
};
|
|
395
358
|
}
|
|
396
359
|
};
|
|
397
|
-
(
|
|
360
|
+
__decorate([InjectOptional($WebsocketService)], BroadcastDecorator.prototype, "gWebsocketService", void 0);
|
|
398
361
|
/**
|
|
399
362
|
* A decorator function for broadcasting websocket messages to everyone on the namespace (including the peer).
|
|
400
363
|
*
|
|
@@ -410,7 +373,6 @@ function Broadcast(event) {
|
|
|
410
373
|
|
|
411
374
|
//#endregion
|
|
412
375
|
//#region src/Decorators/BroadcastOthers.ts
|
|
413
|
-
var import_decorate$1 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
414
376
|
/**
|
|
415
377
|
* A decorator class for broadcasting websocket messages to everyone
|
|
416
378
|
* on the namespace (except the peer).
|
|
@@ -441,7 +403,7 @@ var BroadcastOthersDecorator = class extends BaseDecorator {
|
|
|
441
403
|
};
|
|
442
404
|
}
|
|
443
405
|
};
|
|
444
|
-
(
|
|
406
|
+
__decorate([InjectOptional($WebsocketService)], BroadcastOthersDecorator.prototype, "gWebsocketService", void 0);
|
|
445
407
|
/**
|
|
446
408
|
* A decorator function for broadcasting websocket messages to everyone on the namespace (except the peer).
|
|
447
409
|
*
|
|
@@ -457,7 +419,6 @@ function BroadcastOthers(event) {
|
|
|
457
419
|
|
|
458
420
|
//#endregion
|
|
459
421
|
//#region src/Decorators/OnConnectionAttempt.ts
|
|
460
|
-
var import_decorate = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
461
422
|
/**
|
|
462
423
|
* A decorator class for handling websocket connection attempts.
|
|
463
424
|
*
|
|
@@ -492,7 +453,7 @@ var OnConnectionAttemptDecorator = class extends BaseDecorator {
|
|
|
492
453
|
this.gWebsocketService.registerHandler(WebsocketTypes.HandlerAction.CONNECTION, namespace, { callback: originalMethod });
|
|
493
454
|
}
|
|
494
455
|
};
|
|
495
|
-
(
|
|
456
|
+
__decorate([InjectOptional($WebsocketService)], OnConnectionAttemptDecorator.prototype, "gWebsocketService", void 0);
|
|
496
457
|
/**
|
|
497
458
|
* A decorator function for handling websocket connection attempts to a namespace.
|
|
498
459
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercube/ws",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
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.11"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"crossws": "0.4.1",
|
|
25
25
|
"srvx": "0.8.7",
|
|
26
|
-
"@vercube/
|
|
27
|
-
"@vercube/
|
|
28
|
-
"@vercube/di": "0.0.
|
|
26
|
+
"@vercube/core": "0.0.24",
|
|
27
|
+
"@vercube/logger": "0.0.24",
|
|
28
|
+
"@vercube/di": "0.0.24"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|