@colyseus/sdk 0.17.0

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.
Files changed (133) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +27 -0
  3. package/build/cjs/3rd_party/discord.js +56 -0
  4. package/build/cjs/3rd_party/discord.js.map +1 -0
  5. package/build/cjs/Auth.js +156 -0
  6. package/build/cjs/Auth.js.map +1 -0
  7. package/build/cjs/Client.js +282 -0
  8. package/build/cjs/Client.js.map +1 -0
  9. package/build/cjs/Connection.js +48 -0
  10. package/build/cjs/Connection.js.map +1 -0
  11. package/build/cjs/HTTP.js +156 -0
  12. package/build/cjs/HTTP.js.map +1 -0
  13. package/build/cjs/Protocol.js +34 -0
  14. package/build/cjs/Protocol.js.map +1 -0
  15. package/build/cjs/Room.js +357 -0
  16. package/build/cjs/Room.js.map +1 -0
  17. package/build/cjs/Storage.js +98 -0
  18. package/build/cjs/Storage.js.map +1 -0
  19. package/build/cjs/core/nanoevents.js +50 -0
  20. package/build/cjs/core/nanoevents.js.map +1 -0
  21. package/build/cjs/core/signal.js +53 -0
  22. package/build/cjs/core/signal.js.map +1 -0
  23. package/build/cjs/core/utils.js +14 -0
  24. package/build/cjs/core/utils.js.map +1 -0
  25. package/build/cjs/errors/Errors.js +29 -0
  26. package/build/cjs/errors/Errors.js.map +1 -0
  27. package/build/cjs/index.js +43 -0
  28. package/build/cjs/index.js.map +1 -0
  29. package/build/cjs/legacy.js +34 -0
  30. package/build/cjs/legacy.js.map +1 -0
  31. package/build/cjs/serializer/NoneSerializer.js +18 -0
  32. package/build/cjs/serializer/NoneSerializer.js.map +1 -0
  33. package/build/cjs/serializer/SchemaSerializer.js +61 -0
  34. package/build/cjs/serializer/SchemaSerializer.js.map +1 -0
  35. package/build/cjs/serializer/Serializer.js +23 -0
  36. package/build/cjs/serializer/Serializer.js.map +1 -0
  37. package/build/cjs/transport/H3Transport.js +171 -0
  38. package/build/cjs/transport/H3Transport.js.map +1 -0
  39. package/build/cjs/transport/WebSocketTransport.js +50 -0
  40. package/build/cjs/transport/WebSocketTransport.js.map +1 -0
  41. package/build/esm/3rd_party/discord.mjs +53 -0
  42. package/build/esm/3rd_party/discord.mjs.map +1 -0
  43. package/build/esm/Auth.mjs +137 -0
  44. package/build/esm/Auth.mjs.map +1 -0
  45. package/build/esm/Client.mjs +272 -0
  46. package/build/esm/Client.mjs.map +1 -0
  47. package/build/esm/Connection.mjs +49 -0
  48. package/build/esm/Connection.mjs.map +1 -0
  49. package/build/esm/HTTP.mjs +159 -0
  50. package/build/esm/HTTP.mjs.map +1 -0
  51. package/build/esm/Protocol.mjs +34 -0
  52. package/build/esm/Protocol.mjs.map +1 -0
  53. package/build/esm/Room.mjs +355 -0
  54. package/build/esm/Room.mjs.map +1 -0
  55. package/build/esm/Storage.mjs +86 -0
  56. package/build/esm/Storage.mjs.map +1 -0
  57. package/build/esm/core/nanoevents.mjs +46 -0
  58. package/build/esm/core/nanoevents.mjs.map +1 -0
  59. package/build/esm/core/signal.mjs +48 -0
  60. package/build/esm/core/signal.mjs.map +1 -0
  61. package/build/esm/core/utils.mjs +12 -0
  62. package/build/esm/core/utils.mjs.map +1 -0
  63. package/build/esm/errors/Errors.mjs +28 -0
  64. package/build/esm/errors/Errors.mjs.map +1 -0
  65. package/build/esm/index.mjs +22 -0
  66. package/build/esm/index.mjs.map +1 -0
  67. package/build/esm/legacy.mjs +32 -0
  68. package/build/esm/legacy.mjs.map +1 -0
  69. package/build/esm/serializer/NoneSerializer.mjs +16 -0
  70. package/build/esm/serializer/NoneSerializer.mjs.map +1 -0
  71. package/build/esm/serializer/SchemaSerializer.mjs +60 -0
  72. package/build/esm/serializer/SchemaSerializer.mjs.map +1 -0
  73. package/build/esm/serializer/Serializer.mjs +20 -0
  74. package/build/esm/serializer/Serializer.mjs.map +1 -0
  75. package/build/esm/transport/H3Transport.mjs +170 -0
  76. package/build/esm/transport/H3Transport.mjs.map +1 -0
  77. package/build/esm/transport/WebSocketTransport.mjs +51 -0
  78. package/build/esm/transport/WebSocketTransport.mjs.map +1 -0
  79. package/dist/colyseus-cocos-creator.js +9538 -0
  80. package/dist/colyseus-cocos-creator.js.map +1 -0
  81. package/dist/colyseus.js +9537 -0
  82. package/dist/colyseus.js.map +1 -0
  83. package/dist/debug.js +2460 -0
  84. package/dist/debug.js.map +1 -0
  85. package/lib/3rd_party/discord.d.ts +33 -0
  86. package/lib/Auth.d.ts +31 -0
  87. package/lib/Client.d.ts +92 -0
  88. package/lib/Connection.d.ts +17 -0
  89. package/lib/HTTP.d.ts +113 -0
  90. package/lib/HTTP_bkp.d.ts +18 -0
  91. package/lib/Protocol.d.ts +21 -0
  92. package/lib/Room.d.ts +140 -0
  93. package/lib/Storage.d.ts +3 -0
  94. package/lib/core/http_bkp.d.ts +319 -0
  95. package/lib/core/nanoevents.d.ts +27 -0
  96. package/lib/core/signal.d.ts +17 -0
  97. package/lib/core/utils.d.ts +1 -0
  98. package/lib/debug.d.ts +1 -0
  99. package/lib/errors/Errors.d.ts +17 -0
  100. package/lib/index.d.ts +9 -0
  101. package/lib/legacy.d.ts +0 -0
  102. package/lib/serializer/FossilDeltaSerializer.d.ts +0 -0
  103. package/lib/serializer/NoneSerializer.d.ts +8 -0
  104. package/lib/serializer/SchemaSerializer.d.ts +14 -0
  105. package/lib/serializer/Serializer.d.ts +10 -0
  106. package/lib/src/3rd_party/discord.d.ts +33 -0
  107. package/lib/src/Auth.d.ts +31 -0
  108. package/lib/src/Client.d.ts +62 -0
  109. package/lib/src/Connection.d.ts +17 -0
  110. package/lib/src/HTTP.d.ts +113 -0
  111. package/lib/src/HTTP_bkp.d.ts +18 -0
  112. package/lib/src/Protocol.d.ts +28 -0
  113. package/lib/src/Room.d.ts +132 -0
  114. package/lib/src/Storage.d.ts +3 -0
  115. package/lib/src/core/http_bkp.d.ts +319 -0
  116. package/lib/src/core/nanoevents.d.ts +27 -0
  117. package/lib/src/core/signal.d.ts +17 -0
  118. package/lib/src/debug.d.ts +1 -0
  119. package/lib/src/errors/Errors.d.ts +15 -0
  120. package/lib/src/index.d.ts +9 -0
  121. package/lib/src/legacy.d.ts +0 -0
  122. package/lib/src/serializer/FossilDeltaSerializer.d.ts +0 -0
  123. package/lib/src/serializer/NoneSerializer.d.ts +8 -0
  124. package/lib/src/serializer/SchemaSerializer.d.ts +14 -0
  125. package/lib/src/serializer/Serializer.d.ts +11 -0
  126. package/lib/src/transport/H3Transport.d.ts +20 -0
  127. package/lib/src/transport/ITransport.d.ts +16 -0
  128. package/lib/src/transport/WebSocketTransport.d.ts +17 -0
  129. package/lib/transport/H3Transport.d.ts +20 -0
  130. package/lib/transport/ITransport.d.ts +16 -0
  131. package/lib/transport/WebSocketTransport.d.ts +17 -0
  132. package/lib/tsconfig.tsbuildinfo +1 -0
  133. package/package.json +108 -0
@@ -0,0 +1,113 @@
1
+ import type { Router, HasRequiredKeys, Prettify, UnionToIntersection, Endpoint, HTTPMethod } from "@colyseus/better-call";
2
+ import { ColyseusSDK } from "./Client.ts";
3
+ type IsAny<T> = 0 extends 1 & T ? true : false;
4
+ type IsAnyOrAnyIndexed<T> = IsAny<T> extends true ? true : (string extends keyof T ? true : (number extends keyof T ? (symbol extends keyof T ? true : false) : false));
5
+ type HasRequired<T extends {
6
+ body?: any;
7
+ query?: any;
8
+ params?: any;
9
+ }> = T["body"] extends object ? HasRequiredKeys<T["body"]> extends true ? true : T["query"] extends object ? HasRequiredKeys<T["query"]> extends true ? true : T["params"] extends object ? HasRequiredKeys<T["params"]> : false : T["params"] extends object ? HasRequiredKeys<T["params"]> : false : T["query"] extends object ? HasRequiredKeys<T["query"]> extends true ? true : T["params"] extends object ? HasRequiredKeys<T["params"]> : false : T["params"] extends object ? HasRequiredKeys<T["params"]> : false;
10
+ type InferContext<T> = T extends (ctx: infer Ctx) => any ? Ctx extends object ? Ctx : never : never;
11
+ type WithRequired<T, K extends keyof any> = Prettify<T & {
12
+ [P in K & keyof T]-?: NonNullable<T[P]>;
13
+ }>;
14
+ type WithoutServerOnly<T extends Record<string, Endpoint>> = {
15
+ [K in keyof T]: T[K] extends Endpoint<any, infer O> ? O extends {
16
+ metadata: {
17
+ SERVER_ONLY: true;
18
+ };
19
+ } ? never : T[K] : T[K];
20
+ };
21
+ type MethodOptions<API, M extends HTTPMethod> = API extends {
22
+ [key: string]: infer T;
23
+ } ? T extends Endpoint<any, infer O> ? O["method"] extends M ? {
24
+ [key in T["path"]]: T;
25
+ } : O["method"] extends M[] ? M extends O["method"][number] ? {
26
+ [key in T["path"]]: T;
27
+ } : {} : O["method"] extends "*" ? {
28
+ [key in T["path"]]: T;
29
+ } : {} : {} : {};
30
+ export type RequiredOptionKeys<C extends {
31
+ body?: any;
32
+ query?: any;
33
+ params?: any;
34
+ }> = (C["body"] extends object ? HasRequiredKeys<C["body"]> extends true ? {
35
+ body: true;
36
+ } : {} : {}) & (C["query"] extends object ? HasRequiredKeys<C["query"]> extends true ? {
37
+ query: true;
38
+ } : {} : {}) & (C["params"] extends object ? HasRequiredKeys<C["params"]> extends true ? {
39
+ params: true;
40
+ } : {} : {});
41
+ type CommonHeaders = {
42
+ accept: "application/json" | "text/plain" | "application/octet-stream";
43
+ "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream";
44
+ authorization: "Bearer" | "Basic";
45
+ };
46
+ type FetchRequestOptions<Body = any, Query extends Record<string, any> = any, Params extends Record<string, any> | Array<string> | undefined = any, Res = any, ExtraOptions extends Record<string, any> = {}> = Prettify<ExtraOptions & Omit<RequestInit, "body"> & {
47
+ /**
48
+ * Headers
49
+ */
50
+ headers?: CommonHeaders | Headers | HeadersInit;
51
+ /**
52
+ * Body
53
+ */
54
+ body?: Body;
55
+ /**
56
+ * Query parameters (key-value pairs)
57
+ */
58
+ query?: Query;
59
+ /**
60
+ * Dynamic parameters.
61
+ *
62
+ * If url is defined as /path/:id, params will be { id: string }
63
+ */
64
+ params?: Params;
65
+ }>;
66
+ type ResponseData<T> = {
67
+ ok: true;
68
+ data: T;
69
+ error: null;
70
+ response: Response;
71
+ headers: Headers;
72
+ status: number;
73
+ statusText: string;
74
+ };
75
+ type ResponseError<E> = {
76
+ ok: false;
77
+ data: null;
78
+ error: Prettify<(E extends Record<string, any> ? E : {
79
+ message?: string;
80
+ }) & {
81
+ code?: string;
82
+ }>;
83
+ response: Response;
84
+ headers: Headers;
85
+ status: number;
86
+ statusText: string;
87
+ };
88
+ type FetchResponse<T, E extends Record<string, unknown> | unknown = unknown, Throw extends boolean = false> = Throw extends true ? T : ResponseData<T> | ResponseError<E>;
89
+ export declare function isJSONSerializable(value: any): boolean;
90
+ export type ResponseType = "json" | "text" | "blob";
91
+ export declare function detectResponseType(request: Response): ResponseType;
92
+ type InferredAPI<R> = R extends {
93
+ endpoints: Record<string, Endpoint>;
94
+ } ? WithoutServerOnly<R["endpoints"]> : WithoutServerOnly<R & Record<string, Endpoint>>;
95
+ export declare class HTTP<R extends Router | Router["endpoints"]> {
96
+ authToken: string | undefined;
97
+ options: FetchRequestOptions;
98
+ private sdk;
99
+ constructor(sdk: ColyseusSDK, baseOptions: FetchRequestOptions);
100
+ private request;
101
+ get<API extends InferredAPI<R> = InferredAPI<R>, OPT extends Prettify<UnionToIntersection<MethodOptions<API, "GET">>> = Prettify<UnionToIntersection<MethodOptions<API, "GET">>>, K extends keyof OPT = keyof OPT, C extends InferContext<OPT[K]> = InferContext<OPT[K]>>(path: IsAnyOrAnyIndexed<R> extends true ? string : (HasRequired<C> extends true ? K : never), options: IsAnyOrAnyIndexed<R> extends true ? FetchRequestOptions<any, any, any> : WithRequired<FetchRequestOptions<C["body"], C["query"], C["params"]>, keyof RequiredOptionKeys<C>>): Promise<FetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
102
+ get<API extends InferredAPI<R> = InferredAPI<R>, OPT extends Prettify<UnionToIntersection<MethodOptions<API, "GET">>> = Prettify<UnionToIntersection<MethodOptions<API, "GET">>>, K extends keyof OPT = keyof OPT, C extends InferContext<OPT[K]> = InferContext<OPT[K]>>(path: IsAnyOrAnyIndexed<R> extends true ? string : (HasRequired<C> extends false ? K : never), options?: IsAnyOrAnyIndexed<R> extends true ? FetchRequestOptions<any, any, any> : FetchRequestOptions<C["body"], C["query"], C["params"]>): Promise<FetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
103
+ post<API extends InferredAPI<R> = InferredAPI<R>, OPT extends Prettify<UnionToIntersection<MethodOptions<API, "POST">>> = Prettify<UnionToIntersection<MethodOptions<API, "POST">>>, K extends keyof OPT = keyof OPT, C extends InferContext<OPT[K]> = InferContext<OPT[K]>>(path: (IsAnyOrAnyIndexed<R> extends true ? string : never) | (IsAny<API> extends true ? string : never) | (HasRequired<C> extends true ? K : never), options: IsAnyOrAnyIndexed<R> extends true ? FetchRequestOptions<any, any, any> : (IsAny<API> extends true ? FetchRequestOptions<any, any, any> : WithRequired<FetchRequestOptions<C["body"], C["query"], C["params"]>, keyof RequiredOptionKeys<C>>)): Promise<FetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
104
+ post<API extends InferredAPI<R> = InferredAPI<R>, OPT extends Prettify<UnionToIntersection<MethodOptions<API, "POST">>> = Prettify<UnionToIntersection<MethodOptions<API, "POST">>>, K extends keyof OPT = keyof OPT, C extends InferContext<OPT[K]> = InferContext<OPT[K]>>(path: (IsAnyOrAnyIndexed<R> extends true ? string : never) | (IsAny<API> extends true ? string : never) | (HasRequired<C> extends false ? K : never), options?: IsAnyOrAnyIndexed<R> extends true ? FetchRequestOptions<any, any, any> : (IsAny<API> extends true ? FetchRequestOptions<any, any, any> : FetchRequestOptions<C["body"], C["query"], C["params"]>)): Promise<FetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
105
+ delete<API extends InferredAPI<R> = InferredAPI<R>, OPT extends Prettify<UnionToIntersection<MethodOptions<API, "DELETE">>> = Prettify<UnionToIntersection<MethodOptions<API, "DELETE">>>, K extends keyof OPT = keyof OPT, C extends InferContext<OPT[K]> = InferContext<OPT[K]>>(path: IsAnyOrAnyIndexed<R> extends true ? string : (HasRequired<C> extends true ? K : never), options: IsAnyOrAnyIndexed<R> extends true ? FetchRequestOptions<any, any, any> : WithRequired<FetchRequestOptions<C["body"], C["query"], C["params"]>, keyof RequiredOptionKeys<C>>): Promise<FetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
106
+ delete<API extends InferredAPI<R> = InferredAPI<R>, OPT extends Prettify<UnionToIntersection<MethodOptions<API, "DELETE">>> = Prettify<UnionToIntersection<MethodOptions<API, "DELETE">>>, K extends keyof OPT = keyof OPT, C extends InferContext<OPT[K]> = InferContext<OPT[K]>>(path: IsAnyOrAnyIndexed<R> extends true ? string : (HasRequired<C> extends false ? K : never), options?: IsAnyOrAnyIndexed<R> extends true ? FetchRequestOptions<any, any, any> : FetchRequestOptions<C["body"], C["query"], C["params"]>): Promise<FetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
107
+ patch<API extends InferredAPI<R> = InferredAPI<R>, OPT extends Prettify<UnionToIntersection<MethodOptions<API, "PATCH">>> = Prettify<UnionToIntersection<MethodOptions<API, "PATCH">>>, K extends keyof OPT = keyof OPT, C extends InferContext<OPT[K]> = InferContext<OPT[K]>>(path: IsAnyOrAnyIndexed<R> extends true ? string : (HasRequired<C> extends true ? K : never), options: IsAnyOrAnyIndexed<R> extends true ? FetchRequestOptions<any, any, any> : WithRequired<FetchRequestOptions<C["body"], C["query"], C["params"]>, keyof RequiredOptionKeys<C>>): Promise<FetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
108
+ patch<API extends InferredAPI<R> = InferredAPI<R>, OPT extends Prettify<UnionToIntersection<MethodOptions<API, "PATCH">>> = Prettify<UnionToIntersection<MethodOptions<API, "PATCH">>>, K extends keyof OPT = keyof OPT, C extends InferContext<OPT[K]> = InferContext<OPT[K]>>(path: IsAnyOrAnyIndexed<R> extends true ? string : (HasRequired<C> extends false ? K : never), options?: IsAnyOrAnyIndexed<R> extends true ? FetchRequestOptions<any, any, any> : FetchRequestOptions<C["body"], C["query"], C["params"]>): Promise<FetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
109
+ put<API extends InferredAPI<R> = InferredAPI<R>, OPT extends Prettify<UnionToIntersection<MethodOptions<API, "PUT">>> = Prettify<UnionToIntersection<MethodOptions<API, "PUT">>>, K extends keyof OPT = keyof OPT, C extends InferContext<OPT[K]> = InferContext<OPT[K]>>(path: IsAnyOrAnyIndexed<R> extends true ? string : (HasRequired<C> extends true ? K : never), options: IsAnyOrAnyIndexed<R> extends true ? FetchRequestOptions<any, any, any> : WithRequired<FetchRequestOptions<C["body"], C["query"], C["params"]>, keyof RequiredOptionKeys<C>>): Promise<FetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
110
+ put<API extends InferredAPI<R> = InferredAPI<R>, OPT extends Prettify<UnionToIntersection<MethodOptions<API, "PUT">>> = Prettify<UnionToIntersection<MethodOptions<API, "PUT">>>, K extends keyof OPT = keyof OPT, C extends InferContext<OPT[K]> = InferContext<OPT[K]>>(path: IsAnyOrAnyIndexed<R> extends true ? string : (HasRequired<C> extends false ? K : never), options?: IsAnyOrAnyIndexed<R> extends true ? FetchRequestOptions<any, any, any> : FetchRequestOptions<C["body"], C["query"], C["params"]>): Promise<FetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
111
+ protected executeRequest<M extends HTTPMethod>(method: M, path: any, requestOptions?: any): Promise<any>;
112
+ }
113
+ export {};
@@ -0,0 +1,18 @@
1
+ import * as httpie from "@colyseus/httpie";
2
+ import { ColyseusSDK } from "./Client.ts";
3
+ export declare class HTTP {
4
+ protected sdk: ColyseusSDK;
5
+ headers: {
6
+ [id: string]: string;
7
+ };
8
+ authToken: string | undefined;
9
+ constructor(sdk: ColyseusSDK, headers?: {
10
+ [id: string]: string;
11
+ });
12
+ get<T = any>(path: string, options?: Partial<httpie.Options>): Promise<httpie.Response<T>>;
13
+ post<T = any>(path: string, options?: Partial<httpie.Options>): Promise<httpie.Response<T>>;
14
+ del<T = any>(path: string, options?: Partial<httpie.Options>): Promise<httpie.Response<T>>;
15
+ put<T = any>(path: string, options?: Partial<httpie.Options>): Promise<httpie.Response<T>>;
16
+ protected request(method: "get" | "post" | "put" | "del", path: string, options?: Partial<httpie.Options>): Promise<httpie.Response>;
17
+ protected getOptions(options: Partial<httpie.Options>): Partial<httpie.Options>;
18
+ }
@@ -0,0 +1,28 @@
1
+ import { RoomAvailable } from "./Room.ts";
2
+ export interface SeatReservation {
3
+ room: RoomAvailable;
4
+ sessionId: string;
5
+ reconnectionToken?: string;
6
+ devMode?: boolean;
7
+ protocol?: string;
8
+ }
9
+ export declare enum Protocol {
10
+ HANDSHAKE = 9,
11
+ JOIN_ROOM = 10,
12
+ ERROR = 11,
13
+ LEAVE_ROOM = 12,
14
+ ROOM_DATA = 13,
15
+ ROOM_STATE = 14,
16
+ ROOM_STATE_PATCH = 15,
17
+ ROOM_DATA_SCHEMA = 16,
18
+ ROOM_DATA_BYTES = 17
19
+ }
20
+ export declare enum ErrorCode {
21
+ MATCHMAKE_NO_HANDLER = 4210,
22
+ MATCHMAKE_INVALID_CRITERIA = 4211,
23
+ MATCHMAKE_INVALID_ROOM_ID = 4212,
24
+ MATCHMAKE_UNHANDLED = 4213,
25
+ MATCHMAKE_EXPIRED = 4214,
26
+ AUTH_FAILED = 4215,
27
+ APPLICATION_ERROR = 4216
28
+ }
@@ -0,0 +1,132 @@
1
+ import { type Room as ServerRoom, type ExtractMessageType } from '@colyseus/core';
2
+ import { Packr } from '@colyseus/msgpackr';
3
+ import { Connection } from './Connection.ts';
4
+ import { Serializer } from './serializer/Serializer.ts';
5
+ import { SchemaConstructor } from './serializer/SchemaSerializer.ts';
6
+ export interface RoomAvailable<Metadata = any> {
7
+ name: string;
8
+ roomId: string;
9
+ clients: number;
10
+ maxClients: number;
11
+ metadata?: Metadata;
12
+ }
13
+ export interface ReconnectionOptions {
14
+ /**
15
+ * The maximum number of reconnection attempts.
16
+ */
17
+ maxRetries: number;
18
+ /**
19
+ * The minimum delay between reconnection attempts.
20
+ */
21
+ minDelay: number;
22
+ /**
23
+ * The maximum delay between reconnection attempts.
24
+ */
25
+ maxDelay: number;
26
+ /**
27
+ * The minimum uptime of the room before reconnection attempts can be made.
28
+ */
29
+ minUptime: number;
30
+ /**
31
+ * The current number of reconnection attempts.
32
+ */
33
+ retryCount: number;
34
+ /**
35
+ * The initial delay between reconnection attempts.
36
+ */
37
+ delay: number;
38
+ /**
39
+ * The function to calculate the delay between reconnection attempts.
40
+ * @param attempt - The current attempt number.
41
+ * @param delay - The initial delay between reconnection attempts.
42
+ * @returns The delay between reconnection attempts.
43
+ */
44
+ backoff: (attempt: number, delay: number) => number;
45
+ /**
46
+ * The maximum number of enqueued messages to buffer.
47
+ */
48
+ maxEnqueuedMessages: number;
49
+ /**
50
+ * Buffer for messages sent while connection is not open.
51
+ * These messages will be sent once the connection is re-established.
52
+ */
53
+ enqueuedMessages: Array<{
54
+ data: Uint8Array;
55
+ }>;
56
+ }
57
+ export declare class Room<RoomType extends typeof ServerRoom = any, State = RoomType['prototype']['state']> {
58
+ roomId: string;
59
+ sessionId: string;
60
+ reconnectionToken: string;
61
+ name: string;
62
+ connection: Connection;
63
+ onStateChange: {
64
+ once: (cb: (state: State) => void) => void;
65
+ remove: (cb: (state: State) => void) => void;
66
+ invoke: (state: State) => void;
67
+ invokeAsync: (state: State) => Promise<any[]>;
68
+ clear: () => void;
69
+ } & ((this: any, cb: (state: State) => void) => import("./core/signal.ts").EventEmitter<(state: State) => void>);
70
+ onError: {
71
+ once: (cb: (code: number, message?: string) => void) => void;
72
+ remove: (cb: (code: number, message?: string) => void) => void;
73
+ invoke: (code: number, message?: string) => void;
74
+ invokeAsync: (code: number, message?: string) => Promise<any[]>;
75
+ clear: () => void;
76
+ } & ((this: any, cb: (code: number, message?: string) => void) => import("./core/signal.ts").EventEmitter<(code: number, message?: string) => void>);
77
+ onLeave: {
78
+ once: (cb: (code: number, reason?: string) => void) => void;
79
+ remove: (cb: (code: number, reason?: string) => void) => void;
80
+ invoke: (code: number, reason?: string) => void;
81
+ invokeAsync: (code: number, reason?: string) => Promise<any[]>;
82
+ clear: () => void;
83
+ } & ((this: any, cb: (code: number, reason?: string) => void) => import("./core/signal.ts").EventEmitter<(code: number, reason?: string) => void>);
84
+ onReconnect: {
85
+ once: (cb: () => void) => void;
86
+ remove: (cb: () => void) => void;
87
+ invoke: () => void;
88
+ invokeAsync: () => Promise<any[]>;
89
+ clear: () => void;
90
+ } & ((this: any, cb: () => void) => import("./core/signal.ts").EventEmitter<() => void>);
91
+ onDrop: {
92
+ once: (cb: (code: number, reason?: string) => void) => void;
93
+ remove: (cb: (code: number, reason?: string) => void) => void;
94
+ invoke: (code: number, reason?: string) => void;
95
+ invokeAsync: (code: number, reason?: string) => Promise<any[]>;
96
+ clear: () => void;
97
+ } & ((this: any, cb: (code: number, reason?: string) => void) => import("./core/signal.ts").EventEmitter<(code: number, reason?: string) => void>);
98
+ protected onJoin: {
99
+ once: (cb: (...args: any[]) => void | Promise<any>) => void;
100
+ remove: (cb: (...args: any[]) => void | Promise<any>) => void;
101
+ invoke: (...args: any[]) => void;
102
+ invokeAsync: (...args: any[]) => Promise<any[]>;
103
+ clear: () => void;
104
+ } & ((this: any, cb: (...args: any[]) => void | Promise<any>) => import("./core/signal.ts").EventEmitter<(...args: any[]) => void | Promise<any>>);
105
+ serializerId: string;
106
+ serializer: Serializer<State>;
107
+ reconnection: ReconnectionOptions;
108
+ protected joinedAtTime: number;
109
+ protected onMessageHandlers: {
110
+ emit(event: string, ...args: any[]): void;
111
+ events: {};
112
+ on(event: string, cb: (...args: any[]) => void): () => void;
113
+ };
114
+ protected packr: Packr;
115
+ constructor(name: string, rootSchema?: SchemaConstructor<State>);
116
+ connect(endpoint: string, options?: any, headers?: any): void;
117
+ leave(consented?: boolean): Promise<number>;
118
+ onMessage<MessageType extends keyof RoomType['prototype']['~client']['~messages']>(message: MessageType, callback: (payload: RoomType['prototype']['~client']['~messages'][MessageType]) => void): any;
119
+ onMessage<T = any>(type: "*", callback: (messageType: string | number, payload: T) => void): any;
120
+ onMessage<T = any>(type: string | number, callback: (payload: T) => void): any;
121
+ send<MessageType extends keyof RoomType['prototype']['messages']>(messageType: MessageType, payload?: ExtractMessageType<RoomType['prototype']['messages'][MessageType]>): any;
122
+ sendUnreliable<T = any>(type: string | number, message?: T): void;
123
+ sendBytes(type: string | number, bytes: Uint8Array): void;
124
+ get state(): State;
125
+ removeAllListeners(): void;
126
+ protected onMessageCallback(event: MessageEvent): void;
127
+ private dispatchMessage;
128
+ private destroy;
129
+ private getMessageHandlerKey;
130
+ private handleReconnection;
131
+ private retryReconnection;
132
+ }
@@ -0,0 +1,3 @@
1
+ export declare function setItem(key: string, value: string): void;
2
+ export declare function removeItem(key: string): void;
3
+ export declare function getItem(key: string, callback: Function): void;
@@ -0,0 +1,319 @@
1
+ import type { Router, HasRequiredKeys, Prettify, UnionToIntersection, Endpoint, HTTPMethod } from "@colyseus/better-call";
2
+ type HasRequired<T extends {
3
+ body?: any;
4
+ query?: any;
5
+ params?: any;
6
+ }> = HasRequiredKeys<T["body"]> extends true ? true : HasRequiredKeys<T["query"]> extends true ? true : HasRequiredKeys<T["params"]> extends true ? true : false;
7
+ type InferContext<T> = T extends (ctx: infer Ctx) => any ? Ctx extends object ? Ctx : never : never;
8
+ type WithRequired<T, K> = T & {
9
+ [P in K extends string ? K : never]-?: T[P extends keyof T ? P : never];
10
+ };
11
+ type WithoutServerOnly<T extends Record<string, Endpoint>> = {
12
+ [K in keyof T]: T[K] extends Endpoint<any, infer O> ? O extends {
13
+ metadata: {
14
+ SERVER_ONLY: true;
15
+ };
16
+ } ? never : T[K] : T[K];
17
+ };
18
+ type MethodOptions<API, M extends HTTPMethod> = API extends {
19
+ [key: string]: infer T;
20
+ } ? T extends Endpoint<any, infer O> ? O["method"] extends M ? {
21
+ [key in T["path"]]: T;
22
+ } : O["method"] extends M[] ? M extends O["method"][number] ? {
23
+ [key in T["path"]]: T;
24
+ } : {} : O["method"] extends "*" ? {
25
+ [key in T["path"]]: T;
26
+ } : {} : {} : {};
27
+ export type RequiredOptionKeys<C extends {
28
+ body?: any;
29
+ query?: any;
30
+ params?: any;
31
+ }> = (undefined extends C["body"] ? {} : {
32
+ body: true;
33
+ }) & (undefined extends C["query"] ? {} : {
34
+ query: true;
35
+ }) & (undefined extends C["params"] ? {} : {
36
+ params: true;
37
+ });
38
+ export interface ClientOptions extends FetchRequestOptions {
39
+ baseURL: string;
40
+ }
41
+ type CommonHeaders = {
42
+ accept: "application/json" | "text/plain" | "application/octet-stream";
43
+ "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream";
44
+ authorization: "Bearer" | "Basic";
45
+ };
46
+ type FetchRequestOptions<Body = any, Query extends Record<string, any> = any, Params extends Record<string, any> | Array<string> | undefined = any, Res = any, ExtraOptions extends Record<string, any> = {}> = Prettify<ExtraOptions & Omit<RequestInit, "body"> & {
47
+ baseURL?: string;
48
+ /**
49
+ * Headers
50
+ */
51
+ headers?: CommonHeaders | Headers | HeadersInit;
52
+ /**
53
+ * Body
54
+ */
55
+ body?: Body;
56
+ /**
57
+ * Query parameters (key-value pairs)
58
+ */
59
+ query?: Query;
60
+ /**
61
+ * Dynamic parameters.
62
+ *
63
+ * If url is defined as /path/:id, params will be { id: string }
64
+ */
65
+ params?: Params;
66
+ }>;
67
+ type ResponseData<T> = {
68
+ ok: true;
69
+ data: T;
70
+ error: null;
71
+ response: Response;
72
+ headers: Headers;
73
+ status: number;
74
+ statusText: string;
75
+ };
76
+ type ResponseError<E> = {
77
+ ok: false;
78
+ data: null;
79
+ error: Prettify<(E extends Record<string, any> ? E : {
80
+ message?: string;
81
+ }) & {
82
+ code?: string;
83
+ }>;
84
+ response: Response;
85
+ headers: Headers;
86
+ status: number;
87
+ statusText: string;
88
+ };
89
+ export declare function isJSONSerializable(value: any): boolean;
90
+ export type ResponseType = "json" | "text" | "blob";
91
+ export declare function detectResponseType(request: Response): ResponseType;
92
+ export declare const createClient: <R extends Router | Router["endpoints"]>(baseOptions: ClientOptions) => {
93
+ get: <OPT extends UnionToIntersection<MethodOptions<WithoutServerOnly<R extends {
94
+ endpoints: Record<string, Endpoint>;
95
+ } ? R["endpoints"] : R>, "GET">> extends infer T ? { [K_1 in keyof T]: T[K_1]; } : never, K extends keyof OPT, C extends InferContext<OPT[K]>>(path: K, ...options: HasRequired<C> extends true ? [WithRequired<{
96
+ cache?: RequestCache;
97
+ method?: string;
98
+ signal?: AbortSignal | null;
99
+ mode?: RequestMode;
100
+ credentials?: RequestCredentials;
101
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
102
+ integrity?: string;
103
+ keepalive?: boolean;
104
+ priority?: RequestPriority;
105
+ redirect?: RequestRedirect;
106
+ referrer?: string;
107
+ referrerPolicy?: ReferrerPolicy;
108
+ window?: null;
109
+ baseURL?: string;
110
+ body?: C["body"];
111
+ query?: C["query"];
112
+ params?: C["params"];
113
+ }, keyof (undefined extends C["body"] ? {} : {
114
+ body: true;
115
+ }) | keyof (undefined extends C["query"] ? {} : {
116
+ query: true;
117
+ }) | keyof (undefined extends C["params"] ? {} : {
118
+ params: true;
119
+ })>] : [{
120
+ cache?: RequestCache;
121
+ method?: string;
122
+ signal?: AbortSignal | null;
123
+ mode?: RequestMode;
124
+ credentials?: RequestCredentials;
125
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
126
+ integrity?: string;
127
+ keepalive?: boolean;
128
+ priority?: RequestPriority;
129
+ redirect?: RequestRedirect;
130
+ referrer?: string;
131
+ referrerPolicy?: ReferrerPolicy;
132
+ window?: null;
133
+ baseURL?: string;
134
+ body?: C["body"];
135
+ query?: C["query"];
136
+ params?: C["params"];
137
+ }?]) => Promise<ResponseError<unknown> | ResponseData<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
138
+ post: <OPT extends UnionToIntersection<MethodOptions<WithoutServerOnly<R extends {
139
+ endpoints: Record<string, Endpoint>;
140
+ } ? R["endpoints"] : R>, "POST">> extends infer T ? { [K_1 in keyof T]: T[K_1]; } : never, K extends keyof OPT, C extends InferContext<OPT[K]>>(path: K, ...options: HasRequired<C> extends true ? [WithRequired<{
141
+ cache?: RequestCache;
142
+ method?: string;
143
+ signal?: AbortSignal | null;
144
+ mode?: RequestMode;
145
+ credentials?: RequestCredentials;
146
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
147
+ integrity?: string;
148
+ keepalive?: boolean;
149
+ priority?: RequestPriority;
150
+ redirect?: RequestRedirect;
151
+ referrer?: string;
152
+ referrerPolicy?: ReferrerPolicy;
153
+ window?: null;
154
+ baseURL?: string;
155
+ body?: C["body"];
156
+ query?: C["query"];
157
+ params?: C["params"];
158
+ }, keyof (undefined extends C["body"] ? {} : {
159
+ body: true;
160
+ }) | keyof (undefined extends C["query"] ? {} : {
161
+ query: true;
162
+ }) | keyof (undefined extends C["params"] ? {} : {
163
+ params: true;
164
+ })>] : [{
165
+ cache?: RequestCache;
166
+ method?: string;
167
+ signal?: AbortSignal | null;
168
+ mode?: RequestMode;
169
+ credentials?: RequestCredentials;
170
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
171
+ integrity?: string;
172
+ keepalive?: boolean;
173
+ priority?: RequestPriority;
174
+ redirect?: RequestRedirect;
175
+ referrer?: string;
176
+ referrerPolicy?: ReferrerPolicy;
177
+ window?: null;
178
+ baseURL?: string;
179
+ body?: C["body"];
180
+ query?: C["query"];
181
+ params?: C["params"];
182
+ }?]) => Promise<ResponseError<unknown> | ResponseData<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
183
+ delete: <OPT extends UnionToIntersection<MethodOptions<WithoutServerOnly<R extends {
184
+ endpoints: Record<string, Endpoint>;
185
+ } ? R["endpoints"] : R>, "DELETE">> extends infer T ? { [K_1 in keyof T]: T[K_1]; } : never, K extends keyof OPT, C extends InferContext<OPT[K]>>(path: K, ...options: HasRequired<C> extends true ? [WithRequired<{
186
+ cache?: RequestCache;
187
+ method?: string;
188
+ signal?: AbortSignal | null;
189
+ mode?: RequestMode;
190
+ credentials?: RequestCredentials;
191
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
192
+ integrity?: string;
193
+ keepalive?: boolean;
194
+ priority?: RequestPriority;
195
+ redirect?: RequestRedirect;
196
+ referrer?: string;
197
+ referrerPolicy?: ReferrerPolicy;
198
+ window?: null;
199
+ baseURL?: string;
200
+ body?: C["body"];
201
+ query?: C["query"];
202
+ params?: C["params"];
203
+ }, keyof (undefined extends C["body"] ? {} : {
204
+ body: true;
205
+ }) | keyof (undefined extends C["query"] ? {} : {
206
+ query: true;
207
+ }) | keyof (undefined extends C["params"] ? {} : {
208
+ params: true;
209
+ })>] : [{
210
+ cache?: RequestCache;
211
+ method?: string;
212
+ signal?: AbortSignal | null;
213
+ mode?: RequestMode;
214
+ credentials?: RequestCredentials;
215
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
216
+ integrity?: string;
217
+ keepalive?: boolean;
218
+ priority?: RequestPriority;
219
+ redirect?: RequestRedirect;
220
+ referrer?: string;
221
+ referrerPolicy?: ReferrerPolicy;
222
+ window?: null;
223
+ baseURL?: string;
224
+ body?: C["body"];
225
+ query?: C["query"];
226
+ params?: C["params"];
227
+ }?]) => Promise<ResponseError<unknown> | ResponseData<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
228
+ patch: <OPT extends UnionToIntersection<MethodOptions<WithoutServerOnly<R extends {
229
+ endpoints: Record<string, Endpoint>;
230
+ } ? R["endpoints"] : R>, "PATCH">> extends infer T ? { [K_1 in keyof T]: T[K_1]; } : never, K extends keyof OPT, C extends InferContext<OPT[K]>>(path: K, ...options: HasRequired<C> extends true ? [WithRequired<{
231
+ cache?: RequestCache;
232
+ method?: string;
233
+ signal?: AbortSignal | null;
234
+ mode?: RequestMode;
235
+ credentials?: RequestCredentials;
236
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
237
+ integrity?: string;
238
+ keepalive?: boolean;
239
+ priority?: RequestPriority;
240
+ redirect?: RequestRedirect;
241
+ referrer?: string;
242
+ referrerPolicy?: ReferrerPolicy;
243
+ window?: null;
244
+ baseURL?: string;
245
+ body?: C["body"];
246
+ query?: C["query"];
247
+ params?: C["params"];
248
+ }, keyof (undefined extends C["body"] ? {} : {
249
+ body: true;
250
+ }) | keyof (undefined extends C["query"] ? {} : {
251
+ query: true;
252
+ }) | keyof (undefined extends C["params"] ? {} : {
253
+ params: true;
254
+ })>] : [{
255
+ cache?: RequestCache;
256
+ method?: string;
257
+ signal?: AbortSignal | null;
258
+ mode?: RequestMode;
259
+ credentials?: RequestCredentials;
260
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
261
+ integrity?: string;
262
+ keepalive?: boolean;
263
+ priority?: RequestPriority;
264
+ redirect?: RequestRedirect;
265
+ referrer?: string;
266
+ referrerPolicy?: ReferrerPolicy;
267
+ window?: null;
268
+ baseURL?: string;
269
+ body?: C["body"];
270
+ query?: C["query"];
271
+ params?: C["params"];
272
+ }?]) => Promise<ResponseError<unknown> | ResponseData<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
273
+ put: <OPT extends UnionToIntersection<MethodOptions<WithoutServerOnly<R extends {
274
+ endpoints: Record<string, Endpoint>;
275
+ } ? R["endpoints"] : R>, "PUT">> extends infer T ? { [K_1 in keyof T]: T[K_1]; } : never, K extends keyof OPT, C extends InferContext<OPT[K]>>(path: K, ...options: HasRequired<C> extends true ? [WithRequired<{
276
+ cache?: RequestCache;
277
+ method?: string;
278
+ signal?: AbortSignal | null;
279
+ mode?: RequestMode;
280
+ credentials?: RequestCredentials;
281
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
282
+ integrity?: string;
283
+ keepalive?: boolean;
284
+ priority?: RequestPriority;
285
+ redirect?: RequestRedirect;
286
+ referrer?: string;
287
+ referrerPolicy?: ReferrerPolicy;
288
+ window?: null;
289
+ baseURL?: string;
290
+ body?: C["body"];
291
+ query?: C["query"];
292
+ params?: C["params"];
293
+ }, keyof (undefined extends C["body"] ? {} : {
294
+ body: true;
295
+ }) | keyof (undefined extends C["query"] ? {} : {
296
+ query: true;
297
+ }) | keyof (undefined extends C["params"] ? {} : {
298
+ params: true;
299
+ })>] : [{
300
+ cache?: RequestCache;
301
+ method?: string;
302
+ signal?: AbortSignal | null;
303
+ mode?: RequestMode;
304
+ credentials?: RequestCredentials;
305
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
306
+ integrity?: string;
307
+ keepalive?: boolean;
308
+ priority?: RequestPriority;
309
+ redirect?: RequestRedirect;
310
+ referrer?: string;
311
+ referrerPolicy?: ReferrerPolicy;
312
+ window?: null;
313
+ baseURL?: string;
314
+ body?: C["body"];
315
+ query?: C["query"];
316
+ params?: C["params"];
317
+ }?]) => Promise<ResponseError<unknown> | ResponseData<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
318
+ };
319
+ export {};
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright 2016 Andrey Sitnik <andrey@sitnik.ru>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ * this software and associated documentation files (the "Software"), to deal in
8
+ * the Software without restriction, including without limitation the rights to
9
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ * the Software, and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+ export declare const createNanoEvents: () => {
24
+ emit(event: string, ...args: any[]): void;
25
+ events: {};
26
+ on(event: string, cb: (...args: any[]) => void): () => void;
27
+ };