@colyseus/shared-types 0.17.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/shared-types/src/Protocol.ts
21
+ var Protocol_exports = {};
22
+ __export(Protocol_exports, {
23
+ CloseCode: () => CloseCode,
24
+ ErrorCode: () => ErrorCode,
25
+ Protocol: () => Protocol
26
+ });
27
+ module.exports = __toCommonJS(Protocol_exports);
28
+ var Protocol = {
29
+ // Room-related (10~19)
30
+ JOIN_ROOM: 10,
31
+ ERROR: 11,
32
+ LEAVE_ROOM: 12,
33
+ ROOM_DATA: 13,
34
+ ROOM_STATE: 14,
35
+ ROOM_STATE_PATCH: 15,
36
+ ROOM_DATA_SCHEMA: 16,
37
+ // DEPRECATED: used to send schema instances via room.send()
38
+ ROOM_DATA_BYTES: 17,
39
+ PING: 18
40
+ };
41
+ var ErrorCode = {
42
+ MATCHMAKE_NO_HANDLER: 520,
43
+ MATCHMAKE_INVALID_CRITERIA: 521,
44
+ MATCHMAKE_INVALID_ROOM_ID: 522,
45
+ MATCHMAKE_UNHANDLED: 523,
46
+ // generic exception during onCreate/onJoin
47
+ MATCHMAKE_EXPIRED: 524,
48
+ // generic exception during onCreate/onJoin
49
+ AUTH_FAILED: 525,
50
+ APPLICATION_ERROR: 526,
51
+ INVALID_PAYLOAD: 4217
52
+ };
53
+ var CloseCode = {
54
+ NORMAL_CLOSURE: 1e3,
55
+ GOING_AWAY: 1001,
56
+ NO_STATUS_RECEIVED: 1005,
57
+ ABNORMAL_CLOSURE: 1006,
58
+ CONSENTED: 4e3,
59
+ SERVER_SHUTDOWN: 4001,
60
+ WITH_ERROR: 4002,
61
+ DEVMODE_RESTART: 4010
62
+ };
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ CloseCode,
66
+ ErrorCode,
67
+ Protocol
68
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/Protocol.ts"],
4
+ "sourcesContent": ["/**\n * Colyseus protocol codes range between 0~100\n * Use codes between 0~127 for lesser throughput (1 byte)\n */\nexport const Protocol = {\n // Room-related (10~19)\n JOIN_ROOM: 10,\n ERROR: 11,\n LEAVE_ROOM: 12,\n ROOM_DATA: 13,\n ROOM_STATE: 14,\n ROOM_STATE_PATCH: 15,\n ROOM_DATA_SCHEMA: 16, // DEPRECATED: used to send schema instances via room.send()\n ROOM_DATA_BYTES: 17,\n PING: 18,\n} as const;\nexport type Protocol = typeof Protocol[keyof typeof Protocol];\n\n/**\n * HTTP MatchMaking Error Codes\n */\nexport const ErrorCode = {\n MATCHMAKE_NO_HANDLER: 520,\n MATCHMAKE_INVALID_CRITERIA: 521,\n MATCHMAKE_INVALID_ROOM_ID: 522,\n MATCHMAKE_UNHANDLED: 523, // generic exception during onCreate/onJoin\n MATCHMAKE_EXPIRED: 524, // generic exception during onCreate/onJoin\n AUTH_FAILED: 525,\n APPLICATION_ERROR: 526,\n\n INVALID_PAYLOAD: 4217,\n} as const;\nexport type ErrorCode = typeof ErrorCode[keyof typeof ErrorCode];\n\n/**\n * WebSocket close codes\n * (See https://github.com/Luka967/websocket-close-codes)\n */\nexport const CloseCode = {\n NORMAL_CLOSURE: 1000,\n GOING_AWAY: 1001,\n NO_STATUS_RECEIVED: 1005,\n ABNORMAL_CLOSURE: 1006,\n\n CONSENTED: 4000,\n SERVER_SHUTDOWN: 4001,\n WITH_ERROR: 4002,\n DEVMODE_RESTART: 4010\n} as const;\nexport type CloseCode = typeof CloseCode[keyof typeof CloseCode];\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,IAAM,WAAW;AAAA;AAAA,EAEtB,WAAW;AAAA,EACX,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,kBAAkB;AAAA;AAAA,EAClB,iBAAiB;AAAA,EACjB,MAAM;AACR;AAMO,IAAM,YAAY;AAAA,EACvB,sBAAsB;AAAA,EACtB,4BAA4B;AAAA,EAC5B,2BAA2B;AAAA,EAC3B,qBAAqB;AAAA;AAAA,EACrB,mBAAmB;AAAA;AAAA,EACnB,aAAa;AAAA,EACb,mBAAmB;AAAA,EAEnB,iBAAiB;AACnB;AAOO,IAAM,YAAY;AAAA,EACvB,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,oBAAoB;AAAA,EACpB,kBAAkB;AAAA,EAElB,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,YAAY;AAAA,EACZ,iBAAiB;AACnB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Colyseus protocol codes range between 0~100
3
+ * Use codes between 0~127 for lesser throughput (1 byte)
4
+ */
5
+ export declare const Protocol: {
6
+ readonly JOIN_ROOM: 10;
7
+ readonly ERROR: 11;
8
+ readonly LEAVE_ROOM: 12;
9
+ readonly ROOM_DATA: 13;
10
+ readonly ROOM_STATE: 14;
11
+ readonly ROOM_STATE_PATCH: 15;
12
+ readonly ROOM_DATA_SCHEMA: 16;
13
+ readonly ROOM_DATA_BYTES: 17;
14
+ readonly PING: 18;
15
+ };
16
+ export type Protocol = typeof Protocol[keyof typeof Protocol];
17
+ /**
18
+ * HTTP MatchMaking Error Codes
19
+ */
20
+ export declare const ErrorCode: {
21
+ readonly MATCHMAKE_NO_HANDLER: 520;
22
+ readonly MATCHMAKE_INVALID_CRITERIA: 521;
23
+ readonly MATCHMAKE_INVALID_ROOM_ID: 522;
24
+ readonly MATCHMAKE_UNHANDLED: 523;
25
+ readonly MATCHMAKE_EXPIRED: 524;
26
+ readonly AUTH_FAILED: 525;
27
+ readonly APPLICATION_ERROR: 526;
28
+ readonly INVALID_PAYLOAD: 4217;
29
+ };
30
+ export type ErrorCode = typeof ErrorCode[keyof typeof ErrorCode];
31
+ /**
32
+ * WebSocket close codes
33
+ * (See https://github.com/Luka967/websocket-close-codes)
34
+ */
35
+ export declare const CloseCode: {
36
+ readonly NORMAL_CLOSURE: 1000;
37
+ readonly GOING_AWAY: 1001;
38
+ readonly NO_STATUS_RECEIVED: 1005;
39
+ readonly ABNORMAL_CLOSURE: 1006;
40
+ readonly CONSENTED: 4000;
41
+ readonly SERVER_SHUTDOWN: 4001;
42
+ readonly WITH_ERROR: 4002;
43
+ readonly DEVMODE_RESTART: 4010;
44
+ };
45
+ export type CloseCode = typeof CloseCode[keyof typeof CloseCode];
@@ -0,0 +1,41 @@
1
+ // packages/shared-types/src/Protocol.ts
2
+ var Protocol = {
3
+ // Room-related (10~19)
4
+ JOIN_ROOM: 10,
5
+ ERROR: 11,
6
+ LEAVE_ROOM: 12,
7
+ ROOM_DATA: 13,
8
+ ROOM_STATE: 14,
9
+ ROOM_STATE_PATCH: 15,
10
+ ROOM_DATA_SCHEMA: 16,
11
+ // DEPRECATED: used to send schema instances via room.send()
12
+ ROOM_DATA_BYTES: 17,
13
+ PING: 18
14
+ };
15
+ var ErrorCode = {
16
+ MATCHMAKE_NO_HANDLER: 520,
17
+ MATCHMAKE_INVALID_CRITERIA: 521,
18
+ MATCHMAKE_INVALID_ROOM_ID: 522,
19
+ MATCHMAKE_UNHANDLED: 523,
20
+ // generic exception during onCreate/onJoin
21
+ MATCHMAKE_EXPIRED: 524,
22
+ // generic exception during onCreate/onJoin
23
+ AUTH_FAILED: 525,
24
+ APPLICATION_ERROR: 526,
25
+ INVALID_PAYLOAD: 4217
26
+ };
27
+ var CloseCode = {
28
+ NORMAL_CLOSURE: 1e3,
29
+ GOING_AWAY: 1001,
30
+ NO_STATUS_RECEIVED: 1005,
31
+ ABNORMAL_CLOSURE: 1006,
32
+ CONSENTED: 4e3,
33
+ SERVER_SHUTDOWN: 4001,
34
+ WITH_ERROR: 4002,
35
+ DEVMODE_RESTART: 4010
36
+ };
37
+ export {
38
+ CloseCode,
39
+ ErrorCode,
40
+ Protocol
41
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/Protocol.ts"],
4
+ "sourcesContent": ["/**\n * Colyseus protocol codes range between 0~100\n * Use codes between 0~127 for lesser throughput (1 byte)\n */\nexport const Protocol = {\n // Room-related (10~19)\n JOIN_ROOM: 10,\n ERROR: 11,\n LEAVE_ROOM: 12,\n ROOM_DATA: 13,\n ROOM_STATE: 14,\n ROOM_STATE_PATCH: 15,\n ROOM_DATA_SCHEMA: 16, // DEPRECATED: used to send schema instances via room.send()\n ROOM_DATA_BYTES: 17,\n PING: 18,\n} as const;\nexport type Protocol = typeof Protocol[keyof typeof Protocol];\n\n/**\n * HTTP MatchMaking Error Codes\n */\nexport const ErrorCode = {\n MATCHMAKE_NO_HANDLER: 520,\n MATCHMAKE_INVALID_CRITERIA: 521,\n MATCHMAKE_INVALID_ROOM_ID: 522,\n MATCHMAKE_UNHANDLED: 523, // generic exception during onCreate/onJoin\n MATCHMAKE_EXPIRED: 524, // generic exception during onCreate/onJoin\n AUTH_FAILED: 525,\n APPLICATION_ERROR: 526,\n\n INVALID_PAYLOAD: 4217,\n} as const;\nexport type ErrorCode = typeof ErrorCode[keyof typeof ErrorCode];\n\n/**\n * WebSocket close codes\n * (See https://github.com/Luka967/websocket-close-codes)\n */\nexport const CloseCode = {\n NORMAL_CLOSURE: 1000,\n GOING_AWAY: 1001,\n NO_STATUS_RECEIVED: 1005,\n ABNORMAL_CLOSURE: 1006,\n\n CONSENTED: 4000,\n SERVER_SHUTDOWN: 4001,\n WITH_ERROR: 4002,\n DEVMODE_RESTART: 4010\n} as const;\nexport type CloseCode = typeof CloseCode[keyof typeof CloseCode];\n"],
5
+ "mappings": ";AAIO,IAAM,WAAW;AAAA;AAAA,EAEtB,WAAW;AAAA,EACX,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,kBAAkB;AAAA;AAAA,EAClB,iBAAiB;AAAA,EACjB,MAAM;AACR;AAMO,IAAM,YAAY;AAAA,EACvB,sBAAsB;AAAA,EACtB,4BAA4B;AAAA,EAC5B,2BAA2B;AAAA,EAC3B,qBAAqB;AAAA;AAAA,EACrB,mBAAmB;AAAA;AAAA,EACnB,aAAa;AAAA,EACb,mBAAmB;AAAA,EAEnB,iBAAiB;AACnB;AAOO,IAAM,YAAY;AAAA,EACvB,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,oBAAoB;AAAA,EACpB,kBAAkB;AAAA,EAElB,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,YAAY;AAAA,EACZ,iBAAiB;AACnB;",
6
+ "names": []
7
+ }
package/build/index.cjs CHANGED
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -15,4 +19,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
15
19
 
16
20
  // packages/shared-types/src/index.ts
17
21
  var index_exports = {};
22
+ __export(index_exports, {
23
+ CloseCode: () => import_Protocol.CloseCode,
24
+ ErrorCode: () => import_Protocol.ErrorCode,
25
+ Protocol: () => import_Protocol.Protocol
26
+ });
18
27
  module.exports = __toCommonJS(index_exports);
28
+ var import_Protocol = require("./Protocol.cjs");
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ CloseCode,
32
+ ErrorCode,
33
+ Protocol
34
+ });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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;",
4
+ "sourcesContent": ["import type { StandardSchemaV1 } from '@standard-schema/spec';\n\n// Re-export StandardSchemaV1 for convenience\nexport type { StandardSchemaV1 };\n\n// Re-export Protocol types\nexport { Protocol, ErrorCode, CloseCode } from './Protocol.js';\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,sBAA+C;",
6
6
  "names": []
7
7
  }
package/build/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  export type { StandardSchemaV1 };
3
+ export { Protocol, ErrorCode, CloseCode } from './Protocol.js';
3
4
  /**
4
5
  * Minimal Room-like interface for SDK type inference.
5
6
  * Allows typing SDK methods without depending on @colyseus/core.
package/build/index.mjs CHANGED
@@ -0,0 +1,7 @@
1
+ // packages/shared-types/src/index.ts
2
+ import { Protocol, ErrorCode, CloseCode } from "./Protocol.mjs";
3
+ export {
4
+ CloseCode,
5
+ ErrorCode,
6
+ Protocol
7
+ };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
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// Re-export Protocol types\nexport { Protocol, ErrorCode, CloseCode } from './Protocol.js';\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": ";AAMA,SAAS,UAAU,WAAW,iBAAiB;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/shared-types",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "Shared TypeScript types for Colyseus server and client SDK",
5
5
  "type": "module",
6
6
  "input": "./src/index.ts",
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Colyseus protocol codes range between 0~100
3
+ * Use codes between 0~127 for lesser throughput (1 byte)
4
+ */
5
+ export const Protocol = {
6
+ // Room-related (10~19)
7
+ JOIN_ROOM: 10,
8
+ ERROR: 11,
9
+ LEAVE_ROOM: 12,
10
+ ROOM_DATA: 13,
11
+ ROOM_STATE: 14,
12
+ ROOM_STATE_PATCH: 15,
13
+ ROOM_DATA_SCHEMA: 16, // DEPRECATED: used to send schema instances via room.send()
14
+ ROOM_DATA_BYTES: 17,
15
+ PING: 18,
16
+ } as const;
17
+ export type Protocol = typeof Protocol[keyof typeof Protocol];
18
+
19
+ /**
20
+ * HTTP MatchMaking Error Codes
21
+ */
22
+ export const ErrorCode = {
23
+ MATCHMAKE_NO_HANDLER: 520,
24
+ MATCHMAKE_INVALID_CRITERIA: 521,
25
+ MATCHMAKE_INVALID_ROOM_ID: 522,
26
+ MATCHMAKE_UNHANDLED: 523, // generic exception during onCreate/onJoin
27
+ MATCHMAKE_EXPIRED: 524, // generic exception during onCreate/onJoin
28
+ AUTH_FAILED: 525,
29
+ APPLICATION_ERROR: 526,
30
+
31
+ INVALID_PAYLOAD: 4217,
32
+ } as const;
33
+ export type ErrorCode = typeof ErrorCode[keyof typeof ErrorCode];
34
+
35
+ /**
36
+ * WebSocket close codes
37
+ * (See https://github.com/Luka967/websocket-close-codes)
38
+ */
39
+ export const CloseCode = {
40
+ NORMAL_CLOSURE: 1000,
41
+ GOING_AWAY: 1001,
42
+ NO_STATUS_RECEIVED: 1005,
43
+ ABNORMAL_CLOSURE: 1006,
44
+
45
+ CONSENTED: 4000,
46
+ SERVER_SHUTDOWN: 4001,
47
+ WITH_ERROR: 4002,
48
+ DEVMODE_RESTART: 4010
49
+ } as const;
50
+ export type CloseCode = typeof CloseCode[keyof typeof CloseCode];
package/src/index.ts CHANGED
@@ -3,6 +3,9 @@ import type { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  // Re-export StandardSchemaV1 for convenience
4
4
  export type { StandardSchemaV1 };
5
5
 
6
+ // Re-export Protocol types
7
+ export { Protocol, ErrorCode, CloseCode } from './Protocol.js';
8
+
6
9
  /**
7
10
  * Minimal Room-like interface for SDK type inference.
8
11
  * Allows typing SDK methods without depending on @colyseus/core.