@forklaunch/ws 0.1.0 → 0.1.3

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/lib/index.d.mts CHANGED
@@ -554,11 +554,13 @@ declare class ForklaunchWebSocket<SV extends AnySchemaValidator, const ES extend
554
554
  * @see {@link EventSchema} for schema structure
555
555
  */
556
556
  declare class ForklaunchWebSocketServer<SV extends AnySchemaValidator, const ES extends EventSchema<SV>> extends WebSocketServer {
557
+ private readonly schemaValidator;
558
+ private readonly eventSchemas;
557
559
  /**
558
560
  * Creates a new ForklaunchWebSocketServer with schema validation.
559
561
  *
560
- * @param _schemaValidator - The schema validator instance (e.g., ZodSchemaValidator)
561
- * @param _eventSchemas - Schema definitions for all WebSocket events
562
+ * @param schemaValidator - The schema validator instance (e.g., ZodSchemaValidator)
563
+ * @param eventSchemas - Schema definitions for all WebSocket events
562
564
  * @param options - Standard WebSocketServer options (port, host, server, etc.)
563
565
  * @param callback - Optional callback invoked when the server starts listening
564
566
  *
@@ -601,7 +603,18 @@ declare class ForklaunchWebSocketServer<SV extends AnySchemaValidator, const ES
601
603
  * });
602
604
  * ```
603
605
  */
604
- constructor(_schemaValidator: SV, _eventSchemas: ES, options?: ConstructorParameters<typeof WebSocketServer>[0], callback?: () => void);
606
+ constructor(schemaValidator: SV, eventSchemas: ES, options?: ConstructorParameters<typeof WebSocketServer>[0], callback?: () => void);
607
+ /**
608
+ * Enhances a plain WebSocket instance with ForklaunchWebSocket functionality.
609
+ *
610
+ * This method:
611
+ * 1. Changes the prototype to ForklaunchWebSocket.prototype to inject all methods
612
+ * 2. Initializes all required properties (schemaValidator, eventSchemas, schemas)
613
+ * 3. Ensures methods like on(), send(), close() etc. work with validation
614
+ *
615
+ * @internal
616
+ */
617
+ private enhanceWebSocket;
605
618
  /**
606
619
  * Registers an event listener for server events.
607
620
  *
package/lib/index.d.ts CHANGED
@@ -554,11 +554,13 @@ declare class ForklaunchWebSocket<SV extends AnySchemaValidator, const ES extend
554
554
  * @see {@link EventSchema} for schema structure
555
555
  */
556
556
  declare class ForklaunchWebSocketServer<SV extends AnySchemaValidator, const ES extends EventSchema<SV>> extends WebSocketServer {
557
+ private readonly schemaValidator;
558
+ private readonly eventSchemas;
557
559
  /**
558
560
  * Creates a new ForklaunchWebSocketServer with schema validation.
559
561
  *
560
- * @param _schemaValidator - The schema validator instance (e.g., ZodSchemaValidator)
561
- * @param _eventSchemas - Schema definitions for all WebSocket events
562
+ * @param schemaValidator - The schema validator instance (e.g., ZodSchemaValidator)
563
+ * @param eventSchemas - Schema definitions for all WebSocket events
562
564
  * @param options - Standard WebSocketServer options (port, host, server, etc.)
563
565
  * @param callback - Optional callback invoked when the server starts listening
564
566
  *
@@ -601,7 +603,18 @@ declare class ForklaunchWebSocketServer<SV extends AnySchemaValidator, const ES
601
603
  * });
602
604
  * ```
603
605
  */
604
- constructor(_schemaValidator: SV, _eventSchemas: ES, options?: ConstructorParameters<typeof WebSocketServer>[0], callback?: () => void);
606
+ constructor(schemaValidator: SV, eventSchemas: ES, options?: ConstructorParameters<typeof WebSocketServer>[0], callback?: () => void);
607
+ /**
608
+ * Enhances a plain WebSocket instance with ForklaunchWebSocket functionality.
609
+ *
610
+ * This method:
611
+ * 1. Changes the prototype to ForklaunchWebSocket.prototype to inject all methods
612
+ * 2. Initializes all required properties (schemaValidator, eventSchemas, schemas)
613
+ * 3. Ensures methods like on(), send(), close() etc. work with validation
614
+ *
615
+ * @internal
616
+ */
617
+ private enhanceWebSocket;
605
618
  /**
606
619
  * Registers an event listener for server events.
607
620
  *
package/lib/index.js CHANGED
@@ -27,8 +27,8 @@ __export(index_exports, {
27
27
  ForklaunchWebSocket: () => ForklaunchWebSocket,
28
28
  ForklaunchWebSocketServer: () => ForklaunchWebSocketServer,
29
29
  OPEN: () => OPEN,
30
- WebSocket: () => import_ws4.WebSocket,
31
- WebSocketServer: () => import_ws4.WebSocketServer,
30
+ WebSocket: () => import_ws5.WebSocket,
31
+ WebSocketServer: () => import_ws5.WebSocketServer,
32
32
  default: () => ForklaunchWebSocket
33
33
  });
34
34
  module.exports = __toCommonJS(index_exports);
@@ -427,13 +427,16 @@ var ForklaunchWebSocket = class extends import_ws2.WebSocket {
427
427
  };
428
428
 
429
429
  // src/webSocketServer.ts
430
- var import_ws3 = require("ws");
431
- var ForklaunchWebSocketServer = class extends import_ws3.WebSocketServer {
430
+ var import_ws3 = require("@forklaunch/core/ws");
431
+ var import_ws4 = require("ws");
432
+ var ForklaunchWebSocketServer = class extends import_ws4.WebSocketServer {
433
+ schemaValidator;
434
+ eventSchemas;
432
435
  /**
433
436
  * Creates a new ForklaunchWebSocketServer with schema validation.
434
437
  *
435
- * @param _schemaValidator - The schema validator instance (e.g., ZodSchemaValidator)
436
- * @param _eventSchemas - Schema definitions for all WebSocket events
438
+ * @param schemaValidator - The schema validator instance (e.g., ZodSchemaValidator)
439
+ * @param eventSchemas - Schema definitions for all WebSocket events
437
440
  * @param options - Standard WebSocketServer options (port, host, server, etc.)
438
441
  * @param callback - Optional callback invoked when the server starts listening
439
442
  *
@@ -476,8 +479,40 @@ var ForklaunchWebSocketServer = class extends import_ws3.WebSocketServer {
476
479
  * });
477
480
  * ```
478
481
  */
479
- constructor(_schemaValidator, _eventSchemas, options, callback) {
482
+ constructor(schemaValidator, eventSchemas, options, callback) {
480
483
  super(options, callback);
484
+ this.schemaValidator = schemaValidator;
485
+ this.eventSchemas = eventSchemas;
486
+ super.on("connection", (ws, request) => {
487
+ const forklaunchWs = this.enhanceWebSocket(ws);
488
+ super.emit("connection", forklaunchWs, request);
489
+ });
490
+ }
491
+ /**
492
+ * Enhances a plain WebSocket instance with ForklaunchWebSocket functionality.
493
+ *
494
+ * This method:
495
+ * 1. Changes the prototype to ForklaunchWebSocket.prototype to inject all methods
496
+ * 2. Initializes all required properties (schemaValidator, eventSchemas, schemas)
497
+ * 3. Ensures methods like on(), send(), close() etc. work with validation
498
+ *
499
+ * @internal
500
+ */
501
+ enhanceWebSocket(ws) {
502
+ Object.setPrototypeOf(ws, ForklaunchWebSocket.prototype);
503
+ const enhancedWs = ws;
504
+ enhancedWs.schemaValidator = this.schemaValidator;
505
+ enhancedWs.eventSchemas = this.eventSchemas;
506
+ const serverEventSchemas = {
507
+ ...this.eventSchemas,
508
+ clientMessages: this.eventSchemas.serverMessages,
509
+ serverMessages: this.eventSchemas.clientMessages
510
+ };
511
+ enhancedWs.schemas = (0, import_ws3.createWebSocketSchemas)(
512
+ this.schemaValidator,
513
+ serverEventSchemas
514
+ );
515
+ return enhancedWs;
481
516
  }
482
517
  on(event, listener) {
483
518
  return super.on(event, listener);
@@ -500,13 +535,13 @@ var ForklaunchWebSocketServer = class extends import_ws3.WebSocketServer {
500
535
  };
501
536
 
502
537
  // index.ts
503
- var import_ws4 = require("ws");
504
538
  var import_ws5 = require("ws");
539
+ var import_ws6 = require("ws");
505
540
  var import_events = require("events");
506
- var CLOSED = import_ws5.WebSocket.CLOSED;
507
- var CLOSING = import_ws5.WebSocket.CLOSING;
508
- var CONNECTING = import_ws5.WebSocket.CONNECTING;
509
- var OPEN = import_ws5.WebSocket.OPEN;
541
+ var CLOSED = import_ws6.WebSocket.CLOSED;
542
+ var CLOSING = import_ws6.WebSocket.CLOSING;
543
+ var CONNECTING = import_ws6.WebSocket.CONNECTING;
544
+ var OPEN = import_ws6.WebSocket.OPEN;
510
545
  // Annotate the CommonJS export names for ESM import in node:
511
546
  0 && (module.exports = {
512
547
  CLOSED,
package/lib/index.mjs CHANGED
@@ -397,13 +397,18 @@ var ForklaunchWebSocket = class extends WebSocket {
397
397
  };
398
398
 
399
399
  // src/webSocketServer.ts
400
+ import {
401
+ createWebSocketSchemas as createWebSocketSchemas2
402
+ } from "@forklaunch/core/ws";
400
403
  import { WebSocketServer } from "ws";
401
404
  var ForklaunchWebSocketServer = class extends WebSocketServer {
405
+ schemaValidator;
406
+ eventSchemas;
402
407
  /**
403
408
  * Creates a new ForklaunchWebSocketServer with schema validation.
404
409
  *
405
- * @param _schemaValidator - The schema validator instance (e.g., ZodSchemaValidator)
406
- * @param _eventSchemas - Schema definitions for all WebSocket events
410
+ * @param schemaValidator - The schema validator instance (e.g., ZodSchemaValidator)
411
+ * @param eventSchemas - Schema definitions for all WebSocket events
407
412
  * @param options - Standard WebSocketServer options (port, host, server, etc.)
408
413
  * @param callback - Optional callback invoked when the server starts listening
409
414
  *
@@ -446,8 +451,40 @@ var ForklaunchWebSocketServer = class extends WebSocketServer {
446
451
  * });
447
452
  * ```
448
453
  */
449
- constructor(_schemaValidator, _eventSchemas, options, callback) {
454
+ constructor(schemaValidator, eventSchemas, options, callback) {
450
455
  super(options, callback);
456
+ this.schemaValidator = schemaValidator;
457
+ this.eventSchemas = eventSchemas;
458
+ super.on("connection", (ws, request) => {
459
+ const forklaunchWs = this.enhanceWebSocket(ws);
460
+ super.emit("connection", forklaunchWs, request);
461
+ });
462
+ }
463
+ /**
464
+ * Enhances a plain WebSocket instance with ForklaunchWebSocket functionality.
465
+ *
466
+ * This method:
467
+ * 1. Changes the prototype to ForklaunchWebSocket.prototype to inject all methods
468
+ * 2. Initializes all required properties (schemaValidator, eventSchemas, schemas)
469
+ * 3. Ensures methods like on(), send(), close() etc. work with validation
470
+ *
471
+ * @internal
472
+ */
473
+ enhanceWebSocket(ws) {
474
+ Object.setPrototypeOf(ws, ForklaunchWebSocket.prototype);
475
+ const enhancedWs = ws;
476
+ enhancedWs.schemaValidator = this.schemaValidator;
477
+ enhancedWs.eventSchemas = this.eventSchemas;
478
+ const serverEventSchemas = {
479
+ ...this.eventSchemas,
480
+ clientMessages: this.eventSchemas.serverMessages,
481
+ serverMessages: this.eventSchemas.clientMessages
482
+ };
483
+ enhancedWs.schemas = createWebSocketSchemas2(
484
+ this.schemaValidator,
485
+ serverEventSchemas
486
+ );
487
+ return enhancedWs;
451
488
  }
452
489
  on(event, listener) {
453
490
  return super.on(event, listener);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/ws",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Typed framework for ws, by ForkLaunch.",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -28,23 +28,23 @@
28
28
  "@asyncapi/parser": "^3.4.0",
29
29
  "@forklaunch/fastmcp-fork": "^1.0.5",
30
30
  "@types/ws": "^8.18.1",
31
- "ws": "^8.18.3",
32
- "@forklaunch/common": "0.6.22",
33
- "@forklaunch/core": "0.16.0",
34
- "@forklaunch/validator": "0.10.22"
31
+ "ws": "^8.19.0",
32
+ "@forklaunch/common": "0.6.24",
33
+ "@forklaunch/core": "0.17.0",
34
+ "@forklaunch/validator": "0.10.24"
35
35
  },
36
36
  "devDependencies": {
37
- "@eslint/js": "^9.38.0",
38
- "@typescript/native-preview": "7.0.0-dev.20251027.1",
37
+ "@eslint/js": "^9.39.2",
38
+ "@typescript/native-preview": "7.0.0-dev.20260118.1",
39
39
  "jest": "^30.2.0",
40
- "prettier": "^3.6.2",
41
- "ts-jest": "^29.4.5",
40
+ "prettier": "^3.8.0",
41
+ "ts-jest": "^29.4.6",
42
42
  "ts-node": "^10.9.2",
43
- "tsup": "^8.5.0",
44
- "typedoc": "^0.28.14",
43
+ "tsup": "^8.5.1",
44
+ "typedoc": "^0.28.16",
45
45
  "typescript": "^5.9.3",
46
- "typescript-eslint": "^8.46.2",
47
- "zod": "^4.1.12"
46
+ "typescript-eslint": "^8.53.0",
47
+ "zod": "^4.3.5"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "tsgo --noEmit && tsup index.ts --format cjs,esm --no-splitting --tsconfig tsconfig.json --outDir lib --dts --clean",