@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,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
+ credentials?: RequestCredentials;
99
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
100
+ integrity?: string;
101
+ keepalive?: boolean;
102
+ mode?: RequestMode;
103
+ priority?: RequestPriority;
104
+ redirect?: RequestRedirect;
105
+ referrer?: string;
106
+ referrerPolicy?: ReferrerPolicy;
107
+ signal?: AbortSignal | null;
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
+ credentials?: RequestCredentials;
123
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
124
+ integrity?: string;
125
+ keepalive?: boolean;
126
+ mode?: RequestMode;
127
+ priority?: RequestPriority;
128
+ redirect?: RequestRedirect;
129
+ referrer?: string;
130
+ referrerPolicy?: ReferrerPolicy;
131
+ signal?: AbortSignal | null;
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
+ credentials?: RequestCredentials;
144
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
145
+ integrity?: string;
146
+ keepalive?: boolean;
147
+ mode?: RequestMode;
148
+ priority?: RequestPriority;
149
+ redirect?: RequestRedirect;
150
+ referrer?: string;
151
+ referrerPolicy?: ReferrerPolicy;
152
+ signal?: AbortSignal | null;
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
+ credentials?: RequestCredentials;
168
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
169
+ integrity?: string;
170
+ keepalive?: boolean;
171
+ mode?: RequestMode;
172
+ priority?: RequestPriority;
173
+ redirect?: RequestRedirect;
174
+ referrer?: string;
175
+ referrerPolicy?: ReferrerPolicy;
176
+ signal?: AbortSignal | null;
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
+ credentials?: RequestCredentials;
189
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
190
+ integrity?: string;
191
+ keepalive?: boolean;
192
+ mode?: RequestMode;
193
+ priority?: RequestPriority;
194
+ redirect?: RequestRedirect;
195
+ referrer?: string;
196
+ referrerPolicy?: ReferrerPolicy;
197
+ signal?: AbortSignal | null;
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
+ credentials?: RequestCredentials;
213
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
214
+ integrity?: string;
215
+ keepalive?: boolean;
216
+ mode?: RequestMode;
217
+ priority?: RequestPriority;
218
+ redirect?: RequestRedirect;
219
+ referrer?: string;
220
+ referrerPolicy?: ReferrerPolicy;
221
+ signal?: AbortSignal | null;
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
+ credentials?: RequestCredentials;
234
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
235
+ integrity?: string;
236
+ keepalive?: boolean;
237
+ mode?: RequestMode;
238
+ priority?: RequestPriority;
239
+ redirect?: RequestRedirect;
240
+ referrer?: string;
241
+ referrerPolicy?: ReferrerPolicy;
242
+ signal?: AbortSignal | null;
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
+ credentials?: RequestCredentials;
258
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
259
+ integrity?: string;
260
+ keepalive?: boolean;
261
+ mode?: RequestMode;
262
+ priority?: RequestPriority;
263
+ redirect?: RequestRedirect;
264
+ referrer?: string;
265
+ referrerPolicy?: ReferrerPolicy;
266
+ signal?: AbortSignal | null;
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
+ credentials?: RequestCredentials;
279
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
280
+ integrity?: string;
281
+ keepalive?: boolean;
282
+ mode?: RequestMode;
283
+ priority?: RequestPriority;
284
+ redirect?: RequestRedirect;
285
+ referrer?: string;
286
+ referrerPolicy?: ReferrerPolicy;
287
+ signal?: AbortSignal | null;
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
+ credentials?: RequestCredentials;
303
+ headers?: HeadersInit & (HeadersInit | CommonHeaders);
304
+ integrity?: string;
305
+ keepalive?: boolean;
306
+ mode?: RequestMode;
307
+ priority?: RequestPriority;
308
+ redirect?: RequestRedirect;
309
+ referrer?: string;
310
+ referrerPolicy?: ReferrerPolicy;
311
+ signal?: AbortSignal | null;
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
+ };
@@ -0,0 +1,17 @@
1
+ type FunctionParameters<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
2
+ export declare class EventEmitter<CallbackSignature extends (...args: any[]) => any> {
3
+ handlers: Array<CallbackSignature>;
4
+ register(cb: CallbackSignature, once?: boolean): this;
5
+ invoke(...args: FunctionParameters<CallbackSignature>): void;
6
+ invokeAsync(...args: FunctionParameters<CallbackSignature>): Promise<any[]>;
7
+ remove(cb: CallbackSignature): void;
8
+ clear(): void;
9
+ }
10
+ export declare function createSignal<CallbackSignature extends (...args: any[]) => void | Promise<any>>(): {
11
+ once: (cb: CallbackSignature) => void;
12
+ remove: (cb: CallbackSignature) => void;
13
+ invoke: (...args: FunctionParameters<CallbackSignature>) => void;
14
+ invokeAsync: (...args: FunctionParameters<CallbackSignature>) => Promise<any[]>;
15
+ clear: () => void;
16
+ } & ((this: any, cb: CallbackSignature) => EventEmitter<CallbackSignature>);
17
+ export {};
@@ -0,0 +1 @@
1
+ export declare function now(): number;
package/lib/debug.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ export declare enum CloseCode {
2
+ NORMAL_CLOSURE = 1000,
3
+ GOING_AWAY = 1001,
4
+ NO_STATUS_RECEIVED = 1005,
5
+ ABNORMAL_CLOSURE = 1006,
6
+ CONSENTED = 4000,
7
+ SERVER_SHUTDOWN = 4001,
8
+ WITH_ERROR = 4002,
9
+ DEVMODE_RESTART = 4010
10
+ }
11
+ export declare class ServerError extends Error {
12
+ code: number;
13
+ constructor(code: number, message: string);
14
+ }
15
+ export declare class AbortError extends Error {
16
+ constructor(message: string);
17
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import './legacy';
2
+ export { ColyseusSDK, Client, MatchMakeError, type JoinOptions, type EndpointSettings, type ClientOptions, type ISeatReservation as SeatReservation } from './Client.ts';
3
+ export { Protocol, ErrorCode } from './Protocol.ts';
4
+ export { Room, type RoomAvailable } from './Room.ts';
5
+ export { Auth, type AuthSettings, type PopupSettings } from "./Auth.ts";
6
+ export { ServerError, CloseCode } from './errors/Errors.ts';
7
+ import { SchemaSerializer, getStateCallbacks } from "./serializer/SchemaSerializer.ts";
8
+ import { registerSerializer } from './serializer/Serializer.ts';
9
+ export { registerSerializer, SchemaSerializer, getStateCallbacks };
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ import type { Serializer } from "./Serializer.ts";
2
+ export declare class NoneSerializer<T = any> implements Serializer<T> {
3
+ setState(rawState: any): void;
4
+ getState(): any;
5
+ patch(patches: any): void;
6
+ teardown(): void;
7
+ handshake(bytes: Uint8Array): void;
8
+ }
@@ -0,0 +1,14 @@
1
+ import { Schema, Decoder, Iterator } from "@colyseus/schema";
2
+ import type { Serializer } from "./Serializer.ts";
3
+ import type { Room } from "../Room.ts";
4
+ export type SchemaConstructor<T = Schema> = new (...args: any[]) => T;
5
+ export declare function getStateCallbacks<T>(room: Room<any, T>): import("@colyseus/schema").SchemaCallbackProxy<T>;
6
+ export declare class SchemaSerializer<T extends Schema = any> implements Serializer<T> {
7
+ state: T;
8
+ decoder: Decoder<T>;
9
+ setState(encodedState: Uint8Array, it?: Iterator): void;
10
+ getState(): T;
11
+ patch(patches: Uint8Array, it?: Iterator): import("@colyseus/schema").DataChange<any, string>[];
12
+ teardown(): void;
13
+ handshake(bytes: Uint8Array, it?: Iterator): void;
14
+ }
@@ -0,0 +1,10 @@
1
+ import type { Iterator } from "@colyseus/schema";
2
+ export interface Serializer<State> {
3
+ setState(data: Uint8Array, it?: Iterator): void;
4
+ getState(): State;
5
+ patch(data: Uint8Array, it?: Iterator): void;
6
+ teardown(): void;
7
+ handshake?(bytes: Uint8Array, it?: any): void;
8
+ }
9
+ export declare function registerSerializer(id: string, serializer: any): void;
10
+ export declare function getSerializer(id: string): any;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Discord Embedded App SDK
3
+ * https://github.com/colyseus/colyseus/issues/707
4
+ *
5
+ * All URLs must go through the local proxy from
6
+ * https://<app_id>.discordsays.com/.proxy/<mapped_url>/...
7
+ *
8
+ * URL Mapping Examples:
9
+ *
10
+ * 1. Using Colyseus Cloud:
11
+ * - /colyseus/{subdomain} -> {subdomain}.colyseus.cloud
12
+ *
13
+ * Example:
14
+ * const client = new Client("https://xxxx.colyseus.cloud");
15
+ *
16
+ * -------------------------------------------------------------
17
+ *
18
+ * 2. Using `cloudflared` tunnel:
19
+ * - /colyseus/ -> <your-cloudflared-url>.trycloudflare.com
20
+ *
21
+ * Example:
22
+ * const client = new Client("https://<your-cloudflared-url>.trycloudflare.com");
23
+ *
24
+ * -------------------------------------------------------------
25
+ *
26
+ * 3. Providing a manual /.proxy/your-mapping:
27
+ * - /your-mapping/ -> your-endpoint.com
28
+ *
29
+ * Example:
30
+ * const client = new Client("/.proxy/your-mapping");
31
+ *
32
+ */
33
+ export declare function discordURLBuilder(url: URL): string;
@@ -0,0 +1,31 @@
1
+ import { HTTP } from "./HTTP.ts";
2
+ export interface AuthSettings {
3
+ path: string;
4
+ key: string;
5
+ }
6
+ export interface PopupSettings {
7
+ prefix: string;
8
+ width: number;
9
+ height: number;
10
+ }
11
+ export interface AuthData {
12
+ user: any;
13
+ token: string;
14
+ }
15
+ export declare class Auth {
16
+ #private;
17
+ settings: AuthSettings;
18
+ protected http: HTTP<any>;
19
+ constructor(http: HTTP<any>);
20
+ set token(token: string);
21
+ get token(): string | undefined;
22
+ onChange(callback: (response: AuthData) => void): () => void;
23
+ getUserData(): Promise<null>;
24
+ registerWithEmailAndPassword(email: string, password: string, options?: any): Promise<null>;
25
+ signInWithEmailAndPassword(email: string, password: string): Promise<null>;
26
+ signInAnonymously(options?: any): Promise<null>;
27
+ sendPasswordResetEmail(email: string): Promise<null>;
28
+ signInWithProvider(providerName: string, settings?: Partial<PopupSettings>): Promise<unknown>;
29
+ signOut(): Promise<void>;
30
+ private emitChange;
31
+ }
@@ -0,0 +1,62 @@
1
+ import type { SDKTypes, Room as ServerRoom } from '@colyseus/core';
2
+ import { Room } from './Room.ts';
3
+ import { SchemaConstructor } from './serializer/SchemaSerializer.ts';
4
+ import { HTTP } from './HTTP.ts';
5
+ import { Auth } from './Auth.ts';
6
+ import { SeatReservation } from './Protocol.ts';
7
+ export type JoinOptions = any;
8
+ export declare class MatchMakeError extends Error {
9
+ code: number;
10
+ constructor(message: string, code: number);
11
+ }
12
+ export interface EndpointSettings {
13
+ hostname: string;
14
+ secure: boolean;
15
+ port?: number;
16
+ pathname?: string;
17
+ searchParams?: string;
18
+ }
19
+ export interface ClientOptions {
20
+ headers?: {
21
+ [id: string]: string;
22
+ };
23
+ urlBuilder?: (url: URL) => string;
24
+ }
25
+ export declare class ColyseusSDK<ServerType extends SDKTypes = any> {
26
+ static VERSION: string;
27
+ http: HTTP<ServerType['~routes']>;
28
+ auth: Auth;
29
+ protected settings: EndpointSettings;
30
+ protected urlBuilder: (url: URL) => string;
31
+ constructor(settings?: string | EndpointSettings, options?: ClientOptions);
32
+ joinOrCreate<R extends keyof ServerType['~rooms']>(roomName: R, options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1], rootSchema?: SchemaConstructor<ServerType>): Promise<Room<ServerType['~rooms'][R]['~room']>>;
33
+ joinOrCreate<RoomType extends typeof ServerRoom>(roomName: string, options?: Parameters<RoomType['prototype']['onJoin']>[1], rootSchema?: SchemaConstructor<RoomType['prototype']['state']>): Promise<Room<RoomType>>;
34
+ joinOrCreate<State = any>(roomName: string, options?: JoinOptions, rootSchema?: SchemaConstructor<State>): Promise<Room<any, State>>;
35
+ create<R extends keyof ServerType['~rooms']>(roomName: R, options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1], rootSchema?: SchemaConstructor<ServerType>): Promise<Room<ServerType['~rooms'][R]['~room']>>;
36
+ create<RoomType extends typeof ServerRoom>(roomName: string, options?: Parameters<RoomType['prototype']['onJoin']>[1], rootSchema?: SchemaConstructor<RoomType['prototype']['state']>): Promise<Room<RoomType>>;
37
+ create<State = any>(roomName: string, options?: JoinOptions, rootSchema?: SchemaConstructor<State>): Promise<Room<any, State>>;
38
+ join<R extends keyof ServerType['~rooms']>(roomName: R, options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1], rootSchema?: SchemaConstructor<ServerType>): Promise<Room<ServerType['~rooms'][R]['~room']>>;
39
+ join<RoomType extends typeof ServerRoom>(roomName: string, options?: Parameters<RoomType['prototype']['onJoin']>[1], rootSchema?: SchemaConstructor<RoomType['prototype']['state']>): Promise<Room<RoomType>>;
40
+ join<State = any>(roomName: string, options?: JoinOptions, rootSchema?: SchemaConstructor<State>): Promise<Room<any, State>>;
41
+ joinById<R extends keyof ServerType['~rooms']>(roomName: R, options?: Parameters<ServerType['~rooms'][R]['~room']['prototype']['onJoin']>[1], rootSchema?: SchemaConstructor<ServerType>): Promise<Room<ServerType['~rooms'][R]['~room']>>;
42
+ joinById<RoomType extends typeof ServerRoom>(roomId: string, options?: Parameters<RoomType['prototype']['onJoin']>[1], rootSchema?: SchemaConstructor<RoomType['prototype']['state']>): Promise<Room<RoomType>>;
43
+ joinById<State = any>(roomId: string, options?: JoinOptions, rootSchema?: SchemaConstructor<State>): Promise<Room<any, State>>;
44
+ /**
45
+ * Re-establish connection with a room this client was previously connected to.
46
+ *
47
+ * @param reconnectionToken The `room.reconnectionToken` from previously connected room.
48
+ * @param rootSchema (optional) Concrete root schema definition
49
+ * @returns Promise<Room>
50
+ */
51
+ reconnect<R extends keyof ServerType['~rooms']>(reconnectionToken: string, roomName?: R): Promise<Room<ServerType['~rooms'][R]['~room']>>;
52
+ reconnect<RoomType extends typeof ServerRoom>(reconnectionToken: string, rootSchema?: SchemaConstructor<RoomType['prototype']['state']>): Promise<Room<RoomType>>;
53
+ reconnect<State = any>(reconnectionToken: string, rootSchema?: SchemaConstructor<State>): Promise<Room<any, State>>;
54
+ consumeSeatReservation<T>(response: SeatReservation, rootSchema?: SchemaConstructor<T>): Promise<Room<any, T>>;
55
+ protected createMatchMakeRequest<T>(method: string, roomName: string, options?: JoinOptions, rootSchema?: SchemaConstructor<T>): Promise<Room<any, T>>;
56
+ protected createRoom<T>(roomName: string, rootSchema?: SchemaConstructor<T>): Room<any, T>;
57
+ protected buildEndpoint(room: any, options?: any, protocol?: string): string;
58
+ protected getHttpEndpoint(segments?: string): string;
59
+ protected getEndpointPort(): string;
60
+ }
61
+ export declare const Client: typeof ColyseusSDK;
62
+ export type Client = InstanceType<typeof ColyseusSDK>;
@@ -0,0 +1,17 @@
1
+ import type { ITransport, ITransportEventMap } from "./transport/ITransport.ts";
2
+ export declare class Connection implements ITransport {
3
+ transport: ITransport;
4
+ events: ITransportEventMap;
5
+ url?: string;
6
+ options?: any;
7
+ constructor(protocol?: string);
8
+ connect(url: string, options?: any): void;
9
+ send(data: Buffer | Uint8Array): void;
10
+ sendUnreliable(data: Buffer | Uint8Array): void;
11
+ reconnect(queryParams: {
12
+ reconnectionToken: string;
13
+ skipHandshake?: boolean;
14
+ }): void;
15
+ close(code?: number, reason?: string): void;
16
+ get isOpen(): boolean;
17
+ }