@colyseus/shared-types 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.
- package/LICENSE +21 -0
- package/README.md +114 -0
- package/build/index.cjs +18 -0
- package/build/index.cjs.map +7 -0
- package/build/index.d.ts +102 -0
- package/build/index.js +2 -0
- package/build/index.js.map +1 -0
- package/build/index.mjs +0 -0
- package/build/index.mjs.map +7 -0
- package/package.json +51 -0
- package/src/index.ts +117 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) 2015-2026 Endel Dreyer
|
|
2
|
+
|
|
3
|
+
MIT License:
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://github.com/colyseus/colyseus">
|
|
3
|
+
<img src="media/logo.svg?raw=true" width="60%" height="300" />
|
|
4
|
+
</a>
|
|
5
|
+
<br>
|
|
6
|
+
<br>
|
|
7
|
+
<a href="https://npmjs.com/package/colyseus">
|
|
8
|
+
<img src="https://img.shields.io/npm/dm/colyseus.svg?style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAHdElNRQfjAgETESWYxR33AAAAtElEQVQoz4WQMQrCQBRE38Z0QoTcwF4Qg1h4BO0sxGOk80iCtViksrIQRRBTewWxMI1mbELYjYu+4rPMDPtn12ChMT3gavb4US5Jym0tcBIta3oDHv4Gwmr7nC4QAxBrCdzM2q6XqUnm9m9r59h7Rc0n2pFv24k4ttGMUXW+sGELTJjSr7QDKuqLS6UKFChVWWuFkZw9Z2AAvAirKT+JTlppIRnd6XgaP4goefI2Shj++OnjB3tBmHYK8z9zAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE5LTAyLTAxVDE4OjE3OjM3KzAxOjAwGQQixQAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOS0wMi0wMVQxODoxNzozNyswMTowMGhZmnkAAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAAElFTkSuQmCC">
|
|
9
|
+
</a>
|
|
10
|
+
<a href="http://chat.colyseus.io">
|
|
11
|
+
<img src="https://img.shields.io/discord/525739117951320081.svg?style=for-the-badge&colorB=7581dc&logo=discord&logoColor=white">
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://github.com/colyseus/colyseus/discussions" title="Discuss Forum">
|
|
14
|
+
<img src="https://img.shields.io/badge/discuss-forum-brightgreen.svg?style=for-the-badge&colorB=0069b8&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAHdElNRQfjAgETDROxCNUzAAABB0lEQVQoz4WRvyvEARjGP193CnWRH+dHQmGwKZtFGcSmxHAL400GN95ktIpV2dzlLzDJgsGgGNRdDAzoQueS/PgY3HXHyT3T+/Y87/s89UANBKXBdoZo5J6L4K1K5ZxHfnjnlQUf3bKvkgy57a0r9hS3cXfMO1kWJMza++tj3Ac7/LY343x1NA9cNmYMwnSS/SP8JVFuSJmr44iFqvtmpjhmhBCrOOazCesq6H4P3bPBjFoIBydOk2bUA17I080Es+wSZ51B4DIA2zgjSpYcEe44Js01G0XjRcCU+y4ZMrDeLmfc9EnVd5M/o0VMeu6nJZxWJivLmhyw1WHTvrr2b4+2OFqra+ALwouTMDcqmjMAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTktMDItMDFUMTg6MTM6MTkrMDE6MDAC9f6fAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE5LTAyLTAxVDE4OjEzOjE5KzAxOjAwc6hGIwAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAAASUVORK5CYII=" alt="Discussion forum" />
|
|
15
|
+
</a>
|
|
16
|
+
<h3>
|
|
17
|
+
Multiplayer Framework for Node.js. <br /><a href="https://docs.colyseus.io/">View documentation</a>
|
|
18
|
+
</h3>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
Colyseus is an Authoritative Multiplayer Framework for Node.js, with SDKs
|
|
22
|
+
available for the Web, Unity, Defold, Haxe, Cocos and Construct3. ([See official SDKs](https://docs.colyseus.io/client/))
|
|
23
|
+
|
|
24
|
+
The project focuses on providing synchronizable data structures for realtime and
|
|
25
|
+
turn-based games, matchmaking, and ease of usage both on the server-side and
|
|
26
|
+
client-side.
|
|
27
|
+
|
|
28
|
+
The mission of the framework is to be a standard netcode & matchmaking solution
|
|
29
|
+
for any kind of project you can think of!
|
|
30
|
+
|
|
31
|
+
## Key features:
|
|
32
|
+
|
|
33
|
+
- WebSocket-based communication
|
|
34
|
+
- Simple API in the server-side and client-side.
|
|
35
|
+
- Automatic state synchronization from server-to-client (delta compressed)
|
|
36
|
+
- Matchmaking clients into game rooms/sessions
|
|
37
|
+
- Scale vertically or horizontally
|
|
38
|
+
|
|
39
|
+
See [public roadmap](https://docs.colyseus.io/roadmap) for version 1.0.
|
|
40
|
+
|
|
41
|
+
# 🚀 Quickstart
|
|
42
|
+
|
|
43
|
+
Create a bare-bones Colyseus server by using `npm create colyseus-app@latest`:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
npm create colyseus-app@latest my-colyseus-server
|
|
47
|
+
cd my-colyseus-server
|
|
48
|
+
npm start
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
# Sponsors
|
|
52
|
+
|
|
53
|
+
The sustainability of the project relies on **Colyseus Cloud** subscriptions and sponsorships. If you are not using Colyseus Cloud, please consider [sponsoring the project](https://github.com/sponsors/endel) 💖
|
|
54
|
+
|
|
55
|
+
<a href="https://cdn.jsdelivr.net/gh/colyseus/.github/sponsorkit/sponsors.svg">
|
|
56
|
+
<img src="https://cdn.jsdelivr.net/gh/colyseus/.github/sponsorkit/sponsors.svg" width="100%" />
|
|
57
|
+
</a>
|
|
58
|
+
|
|
59
|
+
# Contributors ✨
|
|
60
|
+
|
|
61
|
+
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
|
|
62
|
+
|
|
63
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
64
|
+
<!-- prettier-ignore-start -->
|
|
65
|
+
<!-- markdownlint-disable -->
|
|
66
|
+
<table>
|
|
67
|
+
<tr>
|
|
68
|
+
<td align="center"><a href="https://github.com/halftheopposite/"><img src="https://avatars0.githubusercontent.com/u/5473864?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aymeric Chauvin</b></sub></a><br /><a href="#question-halftheopposite" title="Answering Questions">💬</a> <a href="#example-halftheopposite" title="Examples">💡</a></td>
|
|
69
|
+
<td align="center"><a href="https://github.com/brian-hay"><img src="https://avatars2.githubusercontent.com/u/1428000?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Brian Hay</b></sub></a><br /><a href="#content-brian-hay" title="Content">🖋</a></td>
|
|
70
|
+
<td align="center"><a href="https://github.com/damian-pastorini"><img src="https://avatars2.githubusercontent.com/u/1211779?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Damian A. Pastorini</b></sub></a><br /><a href="#question-damian-pastorini" title="Answering Questions">💬</a> <a href="https://github.com/colyseus/colyseus/commits?author=damian-pastorini" title="Documentation">📖</a> <a href="https://github.com/colyseus/colyseus/issues?q=author%3Adamian-pastorini" title="Bug reports">🐛</a></td>
|
|
71
|
+
<td align="center"><a href="https://github.com/Zielak"><img src="https://avatars0.githubusercontent.com/u/625693?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Darek Greenly</b></sub></a><br /><a href="#question-Zielak" title="Answering Questions">💬</a> <a href="https://github.com/colyseus/colyseus/issues?q=author%3AZielak" title="Bug reports">🐛</a> <a href="https://github.com/colyseus/colyseus/commits?author=Zielak" title="Code">💻</a></td>
|
|
72
|
+
<td align="center"><a href="https://github.com/Vidski"><img src="https://avatars.githubusercontent.com/u/36316706?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David Rydwanski</b></sub></a><br /><a href="#question-Vidski" title="Answering Questions">💬</a> <a href="https://github.com/colyseus/colyseus/commits?author=Vidski" title="Code">💻</a></td>
|
|
73
|
+
<td align="center"><a href="https://github.com/drburton"><img src="https://avatars0.githubusercontent.com/u/625595?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dr. Burton</b></sub></a><br /><a href="#mentoring-drburton" title="Mentoring">🧑🏫</a></td>
|
|
74
|
+
<td align="center"><a href="https://twitter.com/endel"><img src="https://avatars3.githubusercontent.com/u/130494?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Endel Dreyer</b></sub></a><br /><a href="https://github.com/colyseus/colyseus/commits?author=endel" title="Code">💻</a> <a href="https://github.com/colyseus/colyseus/commits?author=endel" title="Documentation">📖</a> <a href="#example-endel" title="Examples">💡</a></td>
|
|
75
|
+
</tr>
|
|
76
|
+
<tr>
|
|
77
|
+
<td align="center"><a href="https://github.com/enriqueto"><img src="https://avatars2.githubusercontent.com/u/5557196?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Enriqueto</b></sub></a><br /><a href="#business-enriqueto" title="Business development">💼</a></td>
|
|
78
|
+
<td align="center"><a href="https://github.com/fazriz"><img src="https://avatars0.githubusercontent.com/u/2628698?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Fazri Zubair</b></sub></a><br /><a href="#business-fazriz" title="Business development">💼</a></td>
|
|
79
|
+
<td align="center"><a href="https://twitter.com/Federkun"><img src="https://avatars2.githubusercontent.com/u/21344385?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Federico</b></sub></a><br /><a href="https://github.com/colyseus/colyseus/issues?q=author%3AFederkun" title="Bug reports">🐛</a> <a href="https://github.com/colyseus/colyseus/commits?author=Federkun" title="Code">💻</a></td>
|
|
80
|
+
<td align="center"><a href="https://github.com/mobyjames/"><img src="https://avatars0.githubusercontent.com/u/1327007?v=4?s=100" width="100px;" alt=""/><br /><sub><b>James Jacoby</b></sub></a><br /><a href="#question-mobyjames" title="Answering Questions">💬</a> <a href="#example-mobyjames" title="Examples">💡</a> <a href="#content-mobyjames" title="Content">🖋</a></td>
|
|
81
|
+
<td align="center"><a href="http://wenish.github.io/portfolio/"><img src="https://avatars0.githubusercontent.com/u/18367963?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonas Voland</b></sub></a><br /><a href="#question-Wenish" title="Answering Questions">💬</a> <a href="https://github.com/colyseus/colyseus/issues?q=author%3AWenish" title="Bug reports">🐛</a> <a href="https://github.com/colyseus/colyseus/commits?author=Wenish" title="Code">💻</a> <a href="#ideas-Wenish" title="Ideas, Planning, & Feedback">🤔</a> <a href="#example-Wenish" title="Examples">💡</a></td>
|
|
82
|
+
<td align="center"><a href="http://seiyria.com"><img src="https://avatars0.githubusercontent.com/u/763609?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kyle J. Kemp</b></sub></a><br /><a href="#question-seiyria" title="Answering Questions">💬</a> <a href="https://github.com/colyseus/colyseus/issues?q=author%3Aseiyria" title="Bug reports">🐛</a> <a href="https://github.com/colyseus/colyseus/commits?author=seiyria" title="Code">💻</a> <a href="#ideas-seiyria" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
83
|
+
<td align="center"><a href="https://github.com/LukeWood/"><img src="https://avatars0.githubusercontent.com/u/12191303?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Luke Wood</b></sub></a><br /><a href="#question-LukeWood" title="Answering Questions">💬</a> <a href="https://github.com/colyseus/colyseus/issues?q=author%3ALukeWood" title="Bug reports">🐛</a> <a href="https://github.com/colyseus/colyseus/commits?author=LukeWood" title="Code">💻</a></td>
|
|
84
|
+
</tr>
|
|
85
|
+
<tr>
|
|
86
|
+
<td align="center"><a href="https://github.com/doorbash"><img src="https://avatars2.githubusercontent.com/u/5982526?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Milad Doorbash</b></sub></a><br /><a href="https://github.com/colyseus/colyseus/issues?q=author%3Adoorbash" title="Bug reports">🐛</a> <a href="https://github.com/colyseus/colyseus/commits?author=doorbash" title="Code">💻</a></td>
|
|
87
|
+
<td align="center"><a href="https://github.com/TinyDobbins"><img src="https://avatars2.githubusercontent.com/u/20824844?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nikita Borisov</b></sub></a><br /><a href="https://github.com/colyseus/colyseus/issues?q=author%3ATinyDobbins" title="Bug reports">🐛</a> <a href="https://github.com/colyseus/colyseus/commits?author=TinyDobbins" title="Code">💻</a> <a href="#business-TinyDobbins" title="Business development">💼</a> <a href="#ideas-TinyDobbins" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
88
|
+
<td align="center"><a href="https://acemobe.com/"><img src="https://avatars2.githubusercontent.com/u/232101?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Phil Harvey</b></sub></a><br /><a href="https://github.com/colyseus/colyseus/commits?author=filharvey" title="Documentation">📖</a></td>
|
|
89
|
+
<td align="center"><a href="https://github.com/serjek"><img src="https://avatars2.githubusercontent.com/u/18265157?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sergey</b></sub></a><br /><a href="https://github.com/colyseus/colyseus/issues?q=author%3Aserjek" title="Bug reports">🐛</a> <a href="https://github.com/colyseus/colyseus/commits?author=serjek" title="Code">💻</a></td>
|
|
90
|
+
<td align="center"><a href="https://devlsh.com"><img src="https://avatars0.githubusercontent.com/u/853683?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sophie</b></sub></a><br /><a href="#question-devlsh" title="Answering Questions">💬</a> <a href="https://github.com/colyseus/colyseus/issues?q=author%3Adevlsh" title="Bug reports">🐛</a> <a href="#ideas-devlsh" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
91
|
+
<td align="center"><a href="https://github.com/supertommy"><img src="https://avatars0.githubusercontent.com/u/2236153?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tommy Leung</b></sub></a><br /><a href="#mentoring-supertommy" title="Mentoring">🧑🏫</a></td>
|
|
92
|
+
<td align="center"><a href="https://github.com/digimbyte"><img src="https://avatars2.githubusercontent.com/u/6645396?v=4?s=100" width="100px;" alt=""/><br /><sub><b>digimbyte</b></sub></a><br /><a href="https://github.com/colyseus/colyseus/commits?author=digimbyte" title="Documentation">📖</a></td>
|
|
93
|
+
</tr>
|
|
94
|
+
</table>
|
|
95
|
+
|
|
96
|
+
<!-- markdownlint-restore -->
|
|
97
|
+
<!-- prettier-ignore-end -->
|
|
98
|
+
|
|
99
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
100
|
+
|
|
101
|
+
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification.
|
|
102
|
+
Contributions of any kind are welcome!
|
|
103
|
+
|
|
104
|
+
# Contributing
|
|
105
|
+
|
|
106
|
+
We encourage you to contribute to Colyseus! Please check out the [Contributing
|
|
107
|
+
guide](.github/CONTRIBUTING.md) for guidelines about how to proceed. Join us!
|
|
108
|
+
|
|
109
|
+
Everyone interacting in Colyseus and its sub-projects' codebases, issue trackers
|
|
110
|
+
and chat rooms is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
|
111
|
+
|
|
112
|
+
# License
|
|
113
|
+
|
|
114
|
+
MIT
|
package/build/index.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// packages/shared-types/src/index.ts
|
|
17
|
+
var index_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(index_exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import type { StandardSchemaV1 } from '@standard-schema/spec';\n\n// Re-export StandardSchemaV1 for convenience\nexport type { StandardSchemaV1 };\n\n/**\n * Minimal Room-like interface for SDK type inference.\n * Allows typing SDK methods without depending on @colyseus/core.\n */\nexport interface ServerRoomLike<State = any, Options = any> {\n state: State;\n onJoin: (client: any, options?: Options, auth?: any) => any;\n messages?: Record<string, any>;\n '~client'?: { '~messages'?: Record<string, any> };\n}\n\n/**\n * Seat reservation returned by matchmaking operations.\n */\nexport interface ISeatReservation {\n name: string;\n sessionId: string;\n roomId: string;\n publicAddress?: string;\n processId?: string;\n reconnectionToken?: string;\n devMode?: boolean;\n}\n\n/**\n * Helper types for flexible Room generics on the client SDK.\n * Allows: Room<State>, Room<ServerRoom>, or Room<ServerRoom, State>\n */\nexport type InferState<T, S> = [S] extends [never]\n ? (T extends abstract new (...args: any) => { state: infer ST }\n ? ST // Constructor type (typeof MyRoom): extract state from instance\n : T extends { state: infer ST }\n ? ST // Instance type (MyRoom): extract state directly\n : T) // State type or other: return as-is\n : S;\n\n/**\n * Extract room messages type from a Room constructor or instance type.\n * Supports both constructor types (typeof MyRoom) and instance types (MyRoom)\n */\nexport type ExtractRoomMessages<T> = T extends abstract new (...args: any) => { messages: infer M }\n ? M\n : T extends { messages: infer M }\n ? M\n : {};\n\n/**\n * Extract client-side messages type from a Room constructor or instance type.\n * These are messages that the server can send to the client.\n */\nexport type ExtractRoomClientMessages<T> = T extends abstract new (...args: any) => { '~client': { '~messages': infer M } }\n ? M\n : T extends { '~client': { '~messages': infer M } }\n ? M\n : {};\n\n/**\n * Message handler with automatic type inference from format schema.\n * When a format is provided, the message type is automatically inferred from the schema.\n *\n * @template T - The StandardSchema type for message validation\n * @template Client - The client type (from @colyseus/core Transport)\n * @template This - The Room class context\n */\nexport type MessageHandlerWithFormat<T extends StandardSchemaV1 = any, Client = any, This = any> = {\n format: T;\n handler: (this: This, client: Client, message: StandardSchemaV1.InferOutput<T>) => void;\n};\n\n/**\n * Message handler type that can be either a function or a format handler with validation.\n *\n * @template Client - The client type (from @colyseus/core Transport)\n * @template This - The Room class context\n */\nexport type MessageHandler<Client = any, This = any> =\n | ((this: This, client: Client, message: any) => void)\n | MessageHandlerWithFormat<any, Client, This>;\n\n/**\n * Extract the message payload type from a message handler.\n * Works with both function handlers and format handlers.\n */\nexport type ExtractMessageType<T> =\n T extends { format: infer Format extends StandardSchemaV1; handler: any }\n ? StandardSchemaV1.InferOutput<Format>\n : T extends (this: any, client: any, message: infer Message) => void\n ? Message\n : any;\n\n/**\n * A map of message types to message handlers.\n *\n * @template Room - The Room class type\n * @template Client - The client type\n */\nexport type Messages<Room = any, Client = any> = Record<string, MessageHandler<Client, Room>>;\n\n/**\n * Exposed types for the client-side SDK.\n * Used by defineServer() to expose room and route types to the client.\n *\n * @template RoomTypes - Record of room names to their RegisteredHandler types\n * @template Routes - Router type from @colyseus/better-call\n */\nexport interface SDKTypes<\n RoomTypes extends Record<string, any> = any,\n Routes = any\n> {\n '~rooms': RoomTypes;\n '~routes': Routes;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
export type { StandardSchemaV1 };
|
|
3
|
+
/**
|
|
4
|
+
* Minimal Room-like interface for SDK type inference.
|
|
5
|
+
* Allows typing SDK methods without depending on @colyseus/core.
|
|
6
|
+
*/
|
|
7
|
+
export interface ServerRoomLike<State = any, Options = any> {
|
|
8
|
+
state: State;
|
|
9
|
+
onJoin: (client: any, options?: Options, auth?: any) => any;
|
|
10
|
+
messages?: Record<string, any>;
|
|
11
|
+
'~client'?: {
|
|
12
|
+
'~messages'?: Record<string, any>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Seat reservation returned by matchmaking operations.
|
|
17
|
+
*/
|
|
18
|
+
export interface ISeatReservation {
|
|
19
|
+
name: string;
|
|
20
|
+
sessionId: string;
|
|
21
|
+
roomId: string;
|
|
22
|
+
publicAddress?: string;
|
|
23
|
+
processId?: string;
|
|
24
|
+
reconnectionToken?: string;
|
|
25
|
+
devMode?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Helper types for flexible Room generics on the client SDK.
|
|
29
|
+
* Allows: Room<State>, Room<ServerRoom>, or Room<ServerRoom, State>
|
|
30
|
+
*/
|
|
31
|
+
export type InferState<T, S> = [S] extends [never] ? (T extends abstract new (...args: any) => {
|
|
32
|
+
state: infer ST;
|
|
33
|
+
} ? ST : T extends {
|
|
34
|
+
state: infer ST;
|
|
35
|
+
} ? ST : T) : S;
|
|
36
|
+
/**
|
|
37
|
+
* Extract room messages type from a Room constructor or instance type.
|
|
38
|
+
* Supports both constructor types (typeof MyRoom) and instance types (MyRoom)
|
|
39
|
+
*/
|
|
40
|
+
export type ExtractRoomMessages<T> = T extends abstract new (...args: any) => {
|
|
41
|
+
messages: infer M;
|
|
42
|
+
} ? M : T extends {
|
|
43
|
+
messages: infer M;
|
|
44
|
+
} ? M : {};
|
|
45
|
+
/**
|
|
46
|
+
* Extract client-side messages type from a Room constructor or instance type.
|
|
47
|
+
* These are messages that the server can send to the client.
|
|
48
|
+
*/
|
|
49
|
+
export type ExtractRoomClientMessages<T> = T extends abstract new (...args: any) => {
|
|
50
|
+
'~client': {
|
|
51
|
+
'~messages': infer M;
|
|
52
|
+
};
|
|
53
|
+
} ? M : T extends {
|
|
54
|
+
'~client': {
|
|
55
|
+
'~messages': infer M;
|
|
56
|
+
};
|
|
57
|
+
} ? M : {};
|
|
58
|
+
/**
|
|
59
|
+
* Message handler with automatic type inference from format schema.
|
|
60
|
+
* When a format is provided, the message type is automatically inferred from the schema.
|
|
61
|
+
*
|
|
62
|
+
* @template T - The StandardSchema type for message validation
|
|
63
|
+
* @template Client - The client type (from @colyseus/core Transport)
|
|
64
|
+
* @template This - The Room class context
|
|
65
|
+
*/
|
|
66
|
+
export type MessageHandlerWithFormat<T extends StandardSchemaV1 = any, Client = any, This = any> = {
|
|
67
|
+
format: T;
|
|
68
|
+
handler: (this: This, client: Client, message: StandardSchemaV1.InferOutput<T>) => void;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Message handler type that can be either a function or a format handler with validation.
|
|
72
|
+
*
|
|
73
|
+
* @template Client - The client type (from @colyseus/core Transport)
|
|
74
|
+
* @template This - The Room class context
|
|
75
|
+
*/
|
|
76
|
+
export type MessageHandler<Client = any, This = any> = ((this: This, client: Client, message: any) => void) | MessageHandlerWithFormat<any, Client, This>;
|
|
77
|
+
/**
|
|
78
|
+
* Extract the message payload type from a message handler.
|
|
79
|
+
* Works with both function handlers and format handlers.
|
|
80
|
+
*/
|
|
81
|
+
export type ExtractMessageType<T> = T extends {
|
|
82
|
+
format: infer Format extends StandardSchemaV1;
|
|
83
|
+
handler: any;
|
|
84
|
+
} ? StandardSchemaV1.InferOutput<Format> : T extends (this: any, client: any, message: infer Message) => void ? Message : any;
|
|
85
|
+
/**
|
|
86
|
+
* A map of message types to message handlers.
|
|
87
|
+
*
|
|
88
|
+
* @template Room - The Room class type
|
|
89
|
+
* @template Client - The client type
|
|
90
|
+
*/
|
|
91
|
+
export type Messages<Room = any, Client = any> = Record<string, MessageHandler<Client, Room>>;
|
|
92
|
+
/**
|
|
93
|
+
* Exposed types for the client-side SDK.
|
|
94
|
+
* Used by defineServer() to expose room and route types to the client.
|
|
95
|
+
*
|
|
96
|
+
* @template RoomTypes - Record of room names to their RegisteredHandler types
|
|
97
|
+
* @template Routes - Router type from @colyseus/better-call
|
|
98
|
+
*/
|
|
99
|
+
export interface SDKTypes<RoomTypes extends Record<string, any> = any, Routes = any> {
|
|
100
|
+
'~rooms': RoomTypes;
|
|
101
|
+
'~routes': Routes;
|
|
102
|
+
}
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"","sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\n\n// Re-export StandardSchemaV1 for convenience\nexport type { StandardSchemaV1 };\n\n/**\n * Minimal Room-like interface for SDK type inference.\n * Allows typing SDK methods without depending on @colyseus/core.\n */\nexport interface ServerRoomLike<State = any, Options = any> {\n state: State;\n onJoin: (client: any, options?: Options, auth?: any) => any;\n messages?: Record<string, any>;\n '~client'?: { '~messages'?: Record<string, any> };\n}\n\n/**\n * Seat reservation returned by matchmaking operations.\n */\nexport interface ISeatReservation {\n name: string;\n sessionId: string;\n roomId: string;\n publicAddress?: string;\n processId?: string;\n reconnectionToken?: string;\n devMode?: boolean;\n}\n\n/**\n * Helper types for flexible Room generics on the client SDK.\n * Allows: Room<State>, Room<ServerRoom>, or Room<ServerRoom, State>\n */\nexport type InferState<T, S> = [S] extends [never]\n ? (T extends abstract new (...args: any) => { state: infer ST }\n ? ST // Constructor type (typeof MyRoom): extract state from instance\n : T extends { state: infer ST }\n ? ST // Instance type (MyRoom): extract state directly\n : T) // State type or other: return as-is\n : S;\n\n/**\n * Extract room messages type from a Room constructor or instance type.\n * Supports both constructor types (typeof MyRoom) and instance types (MyRoom)\n */\nexport type ExtractRoomMessages<T> = T extends abstract new (...args: any) => { messages: infer M }\n ? M\n : T extends { messages: infer M }\n ? M\n : {};\n\n/**\n * Extract client-side messages type from a Room constructor or instance type.\n * These are messages that the server can send to the client.\n */\nexport type ExtractRoomClientMessages<T> = T extends abstract new (...args: any) => { '~client': { '~messages': infer M } }\n ? M\n : T extends { '~client': { '~messages': infer M } }\n ? M\n : {};\n\n/**\n * Message handler with automatic type inference from format schema.\n * When a format is provided, the message type is automatically inferred from the schema.\n *\n * @template T - The StandardSchema type for message validation\n * @template Client - The client type (from @colyseus/core Transport)\n * @template This - The Room class context\n */\nexport type MessageHandlerWithFormat<T extends StandardSchemaV1 = any, Client = any, This = any> = {\n format: T;\n handler: (this: This, client: Client, message: StandardSchemaV1.InferOutput<T>) => void;\n};\n\n/**\n * Message handler type that can be either a function or a format handler with validation.\n *\n * @template Client - The client type (from @colyseus/core Transport)\n * @template This - The Room class context\n */\nexport type MessageHandler<Client = any, This = any> =\n | ((this: This, client: Client, message: any) => void)\n | MessageHandlerWithFormat<any, Client, This>;\n\n/**\n * Extract the message payload type from a message handler.\n * Works with both function handlers and format handlers.\n */\nexport type ExtractMessageType<T> =\n T extends { format: infer Format extends StandardSchemaV1; handler: any }\n ? StandardSchemaV1.InferOutput<Format>\n : T extends (this: any, client: any, message: infer Message) => void\n ? Message\n : any;\n\n/**\n * A map of message types to message handlers.\n *\n * @template Room - The Room class type\n * @template Client - The client type\n */\nexport type Messages<Room = any, Client = any> = Record<string, MessageHandler<Client, Room>>;\n\n/**\n * Exposed types for the client-side SDK.\n * Used by defineServer() to expose room and route types to the client.\n *\n * @template RoomTypes - Record of room names to their RegisteredHandler types\n * @template Routes - Router type from @colyseus/better-call\n */\nexport interface SDKTypes<\n RoomTypes extends Record<string, any> = any,\n Routes = any\n> {\n '~rooms': RoomTypes;\n '~routes': Routes;\n}\n"]}
|
package/build/index.mjs
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@colyseus/shared-types",
|
|
3
|
+
"version": "0.17.0",
|
|
4
|
+
"description": "Shared TypeScript types for Colyseus server and client SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"input": "./src/index.ts",
|
|
7
|
+
"main": "./build/index.cjs",
|
|
8
|
+
"module": "./src/index.ts",
|
|
9
|
+
"typings": "./build/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"@source": "./src/index.ts",
|
|
13
|
+
"types": "./build/index.d.ts",
|
|
14
|
+
"import": "./build/index.mjs",
|
|
15
|
+
"require": "./build/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./*": {
|
|
18
|
+
"@source": "./src/*.ts",
|
|
19
|
+
"types": "./build/*.d.ts",
|
|
20
|
+
"import": "./build/*.mjs",
|
|
21
|
+
"require": "./build/*.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"funding": "https://github.com/sponsors/endel",
|
|
25
|
+
"author": "Endel Dreyer",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"keywords": [
|
|
28
|
+
"colyseus",
|
|
29
|
+
"multiplayer",
|
|
30
|
+
"types",
|
|
31
|
+
"typescript"
|
|
32
|
+
],
|
|
33
|
+
"files": [
|
|
34
|
+
"build",
|
|
35
|
+
"src"
|
|
36
|
+
],
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git://github.com/colyseus/colyseus.git"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://colyseus.io/",
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">= 22.x"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@standard-schema/spec": "^1.0.0"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
|
|
3
|
+
// Re-export StandardSchemaV1 for convenience
|
|
4
|
+
export type { StandardSchemaV1 };
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Minimal Room-like interface for SDK type inference.
|
|
8
|
+
* Allows typing SDK methods without depending on @colyseus/core.
|
|
9
|
+
*/
|
|
10
|
+
export interface ServerRoomLike<State = any, Options = any> {
|
|
11
|
+
state: State;
|
|
12
|
+
onJoin: (client: any, options?: Options, auth?: any) => any;
|
|
13
|
+
messages?: Record<string, any>;
|
|
14
|
+
'~client'?: { '~messages'?: Record<string, any> };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Seat reservation returned by matchmaking operations.
|
|
19
|
+
*/
|
|
20
|
+
export interface ISeatReservation {
|
|
21
|
+
name: string;
|
|
22
|
+
sessionId: string;
|
|
23
|
+
roomId: string;
|
|
24
|
+
publicAddress?: string;
|
|
25
|
+
processId?: string;
|
|
26
|
+
reconnectionToken?: string;
|
|
27
|
+
devMode?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Helper types for flexible Room generics on the client SDK.
|
|
32
|
+
* Allows: Room<State>, Room<ServerRoom>, or Room<ServerRoom, State>
|
|
33
|
+
*/
|
|
34
|
+
export type InferState<T, S> = [S] extends [never]
|
|
35
|
+
? (T extends abstract new (...args: any) => { state: infer ST }
|
|
36
|
+
? ST // Constructor type (typeof MyRoom): extract state from instance
|
|
37
|
+
: T extends { state: infer ST }
|
|
38
|
+
? ST // Instance type (MyRoom): extract state directly
|
|
39
|
+
: T) // State type or other: return as-is
|
|
40
|
+
: S;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Extract room messages type from a Room constructor or instance type.
|
|
44
|
+
* Supports both constructor types (typeof MyRoom) and instance types (MyRoom)
|
|
45
|
+
*/
|
|
46
|
+
export type ExtractRoomMessages<T> = T extends abstract new (...args: any) => { messages: infer M }
|
|
47
|
+
? M
|
|
48
|
+
: T extends { messages: infer M }
|
|
49
|
+
? M
|
|
50
|
+
: {};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Extract client-side messages type from a Room constructor or instance type.
|
|
54
|
+
* These are messages that the server can send to the client.
|
|
55
|
+
*/
|
|
56
|
+
export type ExtractRoomClientMessages<T> = T extends abstract new (...args: any) => { '~client': { '~messages': infer M } }
|
|
57
|
+
? M
|
|
58
|
+
: T extends { '~client': { '~messages': infer M } }
|
|
59
|
+
? M
|
|
60
|
+
: {};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Message handler with automatic type inference from format schema.
|
|
64
|
+
* When a format is provided, the message type is automatically inferred from the schema.
|
|
65
|
+
*
|
|
66
|
+
* @template T - The StandardSchema type for message validation
|
|
67
|
+
* @template Client - The client type (from @colyseus/core Transport)
|
|
68
|
+
* @template This - The Room class context
|
|
69
|
+
*/
|
|
70
|
+
export type MessageHandlerWithFormat<T extends StandardSchemaV1 = any, Client = any, This = any> = {
|
|
71
|
+
format: T;
|
|
72
|
+
handler: (this: This, client: Client, message: StandardSchemaV1.InferOutput<T>) => void;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Message handler type that can be either a function or a format handler with validation.
|
|
77
|
+
*
|
|
78
|
+
* @template Client - The client type (from @colyseus/core Transport)
|
|
79
|
+
* @template This - The Room class context
|
|
80
|
+
*/
|
|
81
|
+
export type MessageHandler<Client = any, This = any> =
|
|
82
|
+
| ((this: This, client: Client, message: any) => void)
|
|
83
|
+
| MessageHandlerWithFormat<any, Client, This>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Extract the message payload type from a message handler.
|
|
87
|
+
* Works with both function handlers and format handlers.
|
|
88
|
+
*/
|
|
89
|
+
export type ExtractMessageType<T> =
|
|
90
|
+
T extends { format: infer Format extends StandardSchemaV1; handler: any }
|
|
91
|
+
? StandardSchemaV1.InferOutput<Format>
|
|
92
|
+
: T extends (this: any, client: any, message: infer Message) => void
|
|
93
|
+
? Message
|
|
94
|
+
: any;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A map of message types to message handlers.
|
|
98
|
+
*
|
|
99
|
+
* @template Room - The Room class type
|
|
100
|
+
* @template Client - The client type
|
|
101
|
+
*/
|
|
102
|
+
export type Messages<Room = any, Client = any> = Record<string, MessageHandler<Client, Room>>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Exposed types for the client-side SDK.
|
|
106
|
+
* Used by defineServer() to expose room and route types to the client.
|
|
107
|
+
*
|
|
108
|
+
* @template RoomTypes - Record of room names to their RegisteredHandler types
|
|
109
|
+
* @template Routes - Router type from @colyseus/better-call
|
|
110
|
+
*/
|
|
111
|
+
export interface SDKTypes<
|
|
112
|
+
RoomTypes extends Record<string, any> = any,
|
|
113
|
+
Routes = any
|
|
114
|
+
> {
|
|
115
|
+
'~rooms': RoomTypes;
|
|
116
|
+
'~routes': Routes;
|
|
117
|
+
}
|