@signe/room 2.0.0 → 2.0.1
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.d.ts +121 -14
- package/dist/index.js +298 -97
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/readme.md +18 -10
- package/src/index.ts +2 -1
- package/src/request/cors.ts +54 -0
- package/src/request/response.ts +228 -0
- package/src/server.ts +31 -45
- package/src/world.ts +14 -14
package/dist/index.d.ts
CHANGED
|
@@ -634,6 +634,123 @@ interface RoomOnLeave {
|
|
|
634
634
|
onLeave(user: any, conn: Connection, ctx: ConnectionContext): Promise<any> | null | any;
|
|
635
635
|
}
|
|
636
636
|
|
|
637
|
+
declare class ServerResponse {
|
|
638
|
+
private interceptors;
|
|
639
|
+
private statusCode;
|
|
640
|
+
private responseBody;
|
|
641
|
+
private responseHeaders;
|
|
642
|
+
/**
|
|
643
|
+
* Creates a new ServerResponse instance
|
|
644
|
+
* @param interceptors Array of interceptor functions that can modify the response
|
|
645
|
+
*/
|
|
646
|
+
constructor(interceptors?: ((res: Response) => Promise<Response> | Response)[]);
|
|
647
|
+
/**
|
|
648
|
+
* Sets the status code for the response
|
|
649
|
+
* @param code HTTP status code
|
|
650
|
+
* @returns this instance for chaining
|
|
651
|
+
*/
|
|
652
|
+
status(code: number): ServerResponse;
|
|
653
|
+
/**
|
|
654
|
+
* Sets the response body and returns this instance (chainable method)
|
|
655
|
+
*
|
|
656
|
+
* @param body Response body
|
|
657
|
+
* @returns this instance for chaining
|
|
658
|
+
*/
|
|
659
|
+
body(body: any): ServerResponse;
|
|
660
|
+
/**
|
|
661
|
+
* Adds a header to the response
|
|
662
|
+
* @param name Header name
|
|
663
|
+
* @param value Header value
|
|
664
|
+
* @returns this instance for chaining
|
|
665
|
+
*/
|
|
666
|
+
header(name: string, value: string): ServerResponse;
|
|
667
|
+
/**
|
|
668
|
+
* Adds multiple headers to the response
|
|
669
|
+
* @param headers Object containing headers
|
|
670
|
+
* @returns this instance for chaining
|
|
671
|
+
*/
|
|
672
|
+
setHeaders(headers: Record<string, string>): ServerResponse;
|
|
673
|
+
/**
|
|
674
|
+
* Add an interceptor to the chain
|
|
675
|
+
* @param interceptor Function that takes a Response and returns a modified Response
|
|
676
|
+
* @returns this instance for chaining
|
|
677
|
+
*/
|
|
678
|
+
use(interceptor: (res: Response) => Promise<Response> | Response): ServerResponse;
|
|
679
|
+
/**
|
|
680
|
+
* Builds and returns the Response object after applying all interceptors
|
|
681
|
+
* @returns Promise<Response> The final Response object
|
|
682
|
+
* @private Internal method used by terminal methods
|
|
683
|
+
*/
|
|
684
|
+
private buildResponse;
|
|
685
|
+
/**
|
|
686
|
+
* Sets the response body to the JSON-stringified version of the provided value
|
|
687
|
+
* and sends the response (terminal method)
|
|
688
|
+
*
|
|
689
|
+
* @param body Response body to be JSON stringified
|
|
690
|
+
* @returns Promise<Response> The final Response object
|
|
691
|
+
*/
|
|
692
|
+
json(body: any): Promise<Response>;
|
|
693
|
+
/**
|
|
694
|
+
* Sends the response with the current configuration (terminal method)
|
|
695
|
+
*
|
|
696
|
+
* @param body Optional body to set before sending
|
|
697
|
+
* @returns Promise<Response> The final Response object
|
|
698
|
+
*/
|
|
699
|
+
send(body?: any): Promise<Response>;
|
|
700
|
+
/**
|
|
701
|
+
* Sends a plain text response (terminal method)
|
|
702
|
+
*
|
|
703
|
+
* @param text Text to send
|
|
704
|
+
* @returns Promise<Response> The final Response object
|
|
705
|
+
*/
|
|
706
|
+
text(text: string): Promise<Response>;
|
|
707
|
+
/**
|
|
708
|
+
* Redirects to the specified URL (terminal method)
|
|
709
|
+
*
|
|
710
|
+
* @param url URL to redirect to
|
|
711
|
+
* @param statusCode HTTP status code (default: 302)
|
|
712
|
+
* @returns Promise<Response> The final Response object
|
|
713
|
+
*/
|
|
714
|
+
redirect(url: string, statusCode?: number): Promise<Response>;
|
|
715
|
+
/**
|
|
716
|
+
* Creates a success response with status 200
|
|
717
|
+
* @param body Response body
|
|
718
|
+
* @returns Promise<Response> The final Response object
|
|
719
|
+
*/
|
|
720
|
+
success(body?: any): Promise<Response>;
|
|
721
|
+
/**
|
|
722
|
+
* Creates an error response with status 400
|
|
723
|
+
* @param message Error message
|
|
724
|
+
* @param details Additional error details
|
|
725
|
+
* @returns Promise<Response> The final Response object
|
|
726
|
+
*/
|
|
727
|
+
badRequest(message: string, details?: any): Promise<Response>;
|
|
728
|
+
/**
|
|
729
|
+
* Creates an error response with status 403
|
|
730
|
+
* @param message Error message
|
|
731
|
+
* @returns Promise<Response> The final Response object
|
|
732
|
+
*/
|
|
733
|
+
notPermitted(message?: string): Promise<Response>;
|
|
734
|
+
/**
|
|
735
|
+
* Creates an error response with status 401
|
|
736
|
+
* @param message Error message
|
|
737
|
+
* @returns Promise<Response> The final Response object
|
|
738
|
+
*/
|
|
739
|
+
unauthorized(message?: string): Promise<Response>;
|
|
740
|
+
/**
|
|
741
|
+
* Creates an error response with status 404
|
|
742
|
+
* @param message Error message
|
|
743
|
+
* @returns Promise<Response> The final Response object
|
|
744
|
+
*/
|
|
745
|
+
notFound(message?: string): Promise<Response>;
|
|
746
|
+
/**
|
|
747
|
+
* Creates an error response with status 500
|
|
748
|
+
* @param message Error message
|
|
749
|
+
* @returns Promise<Response> The final Response object
|
|
750
|
+
*/
|
|
751
|
+
serverError(message?: string): Promise<Response>;
|
|
752
|
+
}
|
|
753
|
+
|
|
637
754
|
type BalancingStrategy = 'round-robin' | 'least-connections' | 'random';
|
|
638
755
|
type ShardStatus = 'active' | 'maintenance' | 'draining';
|
|
639
756
|
declare class RoomConfig {
|
|
@@ -666,21 +783,11 @@ declare class WorldRoom implements RoomInterceptorPacket, RoomOnJoin {
|
|
|
666
783
|
interceptorPacket(_: any, obj: any, conn: Connection): any;
|
|
667
784
|
private cleanupInactiveShards;
|
|
668
785
|
registerRoom(req: Request$1): Promise<void>;
|
|
669
|
-
updateShardStats(req: Request$1): Promise<
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
scaleRoom(req: Request$1): Promise<{
|
|
673
|
-
error: string;
|
|
674
|
-
roomId?: undefined;
|
|
675
|
-
currentShardCount?: undefined;
|
|
676
|
-
} | {
|
|
677
|
-
error: string;
|
|
678
|
-
roomId: string;
|
|
679
|
-
currentShardCount: number;
|
|
680
|
-
}>;
|
|
681
|
-
connect(req: Request$1): Promise<Response>;
|
|
786
|
+
updateShardStats(req: Request$1, res: ServerResponse): Promise<Response>;
|
|
787
|
+
scaleRoom(req: Request$1, res: ServerResponse): Promise<Response>;
|
|
788
|
+
connect(req: Request$1, res: ServerResponse): Promise<Response>;
|
|
682
789
|
private findOptimalShard;
|
|
683
790
|
private createShard;
|
|
684
791
|
}
|
|
685
792
|
|
|
686
|
-
export { Action, ClientIo, Guard, MockConnection, Request, type RequestOptions, Room, RoomGuard, type RoomInterceptorPacket, type RoomOnJoin, type RoomOnLeave, type RoomOptions, Server, ServerIo, Shard, type ShardOptions, WorldRoom, request, testRoom };
|
|
793
|
+
export { Action, ClientIo, Guard, MockConnection, Request, type RequestOptions, Room, RoomGuard, type RoomInterceptorPacket, type RoomOnJoin, type RoomOnLeave, type RoomOptions, Server, ServerIo, ServerResponse, Shard, type ShardOptions, WorldRoom, request, testRoom };
|