@colyseus/shared-types 0.17.4 → 0.17.6
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/build/Protocol.cjs +1 -0
- package/build/Protocol.cjs.map +2 -2
- package/build/Protocol.d.ts +1 -0
- package/build/Protocol.mjs +1 -0
- package/build/Protocol.mjs.map +2 -2
- package/build/index.cjs.map +1 -1
- package/build/index.d.ts +16 -1
- package/build/index.js.map +1 -1
- package/build/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/Protocol.ts +3 -1
- package/src/index.ts +21 -1
package/build/Protocol.cjs
CHANGED
package/build/Protocol.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 MAY_TRY_RECONNECT: 4010
|
|
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,mBAAmB;AACrB;",
|
|
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 FAILED_TO_RECONNECT: 4003,\n\n MAY_TRY_RECONNECT: 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,qBAAqB;AAAA,EAErB,mBAAmB;AACrB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/Protocol.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export declare const CloseCode: {
|
|
|
40
40
|
readonly CONSENTED: 4000;
|
|
41
41
|
readonly SERVER_SHUTDOWN: 4001;
|
|
42
42
|
readonly WITH_ERROR: 4002;
|
|
43
|
+
readonly FAILED_TO_RECONNECT: 4003;
|
|
43
44
|
readonly MAY_TRY_RECONNECT: 4010;
|
|
44
45
|
};
|
|
45
46
|
export type CloseCode = typeof CloseCode[keyof typeof CloseCode];
|
package/build/Protocol.mjs
CHANGED
package/build/Protocol.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 MAY_TRY_RECONNECT: 4010
|
|
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,mBAAmB;AACrB;",
|
|
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 FAILED_TO_RECONNECT: 4003,\n\n MAY_TRY_RECONNECT: 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,qBAAqB;AAAA,EAErB,mBAAmB;AACrB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/index.cjs.map
CHANGED
|
@@ -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// 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 * Note: onJoin is optional because core Room defines it as optional.\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 * Extract instance type from a constructor type.\n * If T is not a constructor, returns T as-is.\n */\ntype Instantiate<T> = T extends abstract new (...args: any) => infer I ? I : T;\n\n/**\n * Check if a type is a Schema (has ~refId marker).\n * Schema defines ~refId as optional, so we check keyof instead of property presence.\n */\ntype IsSchema<T> = '~refId' extends keyof T ? true : false;\n\n/**\n * Check if ~state phantom property contains a useful type (not object/any/never).\n * Returns true if ~state exists and has meaningful structure.\n */\ntype HasUsefulStatePhantom<T> = T extends { '~state': infer S }\n ? [S] extends [never] ? false // never is not useful\n : unknown extends S ? false // any is not useful\n : S extends object\n ? [keyof S] extends [never] ? false // {} or object with no keys is not useful\n : true\n : false\n : false;\n\n/**\n * Extract state from a Room-like instance type.\n * Priority: useful ~state phantom > Schema state property > return T as-is\n */\ntype ExtractStateFromRoom<T> = T extends { '~state': infer S }\n ? HasUsefulStatePhantom<T> extends true\n ? S // Use ~state if it's useful\n : T extends { state: infer St }\n ? IsSchema<St> extends true ? St : T // Fallback to state if Schema\n : T\n : T extends { state: infer S }\n ? IsSchema<S> extends true ? S : T\n : T;\n\n/**\n * Infer the state type from T, or use explicit S if provided.\n *\n * Supports multiple usage patterns:\n * - Room<MyState>: T is a Schema type, return as-is\n * - Room<MyRoom>: T is a Room instance, extract from ~state or state property\n * - Room<typeof MyRoom>: T is a constructor, instantiate first then extract\n * - Room<T, ExplicitState>: S overrides all inference\n */\nexport type InferState<T, S> = [S] extends [never]\n ? Instantiate<T> extends infer I\n ? IsSchema<I> extends true\n ? I // It's a Schema, return as-is\n : ExtractStateFromRoom<I>\n : never\n : S;\n\n/**\n * Normalizes T for message extraction: returns T if it has ~state (Room type),\n * otherwise returns any (plain state type). This ensures Room<State> is equivalent\n * to Room<any, State> when State doesn't have ~state.\n */\nexport type NormalizeRoomType<T> = Instantiate<T> extends { '~state': any } ? T : any;\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> = Instantiate<T> extends { messages: infer M } ? M : {};\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> = Instantiate<T> extends { '~client': { '~messages': infer M } } ? M : {};\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,
|
|
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 * Note: onJoin is optional because core Room defines it as optional.\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 * Extract instance type from a constructor type.\n * If T is not a constructor, returns T as-is.\n */\ntype Instantiate<T> = T extends abstract new (...args: any) => infer I ? I : T;\n\n/**\n * Check if a type is a Schema (has ~refId marker).\n * Schema defines ~refId as optional, so we check keyof instead of property presence.\n */\ntype IsSchema<T> = '~refId' extends keyof T ? true : false;\n\n/**\n * Check if ~state phantom property contains a useful type (not object/any/never).\n * Returns true if ~state exists and has meaningful structure.\n */\ntype HasUsefulStatePhantom<T> = T extends { '~state': infer S }\n ? [S] extends [never] ? false // never is not useful\n : unknown extends S ? false // any is not useful\n : S extends object\n ? [keyof S] extends [never] ? false // {} or object with no keys is not useful\n : true\n : false\n : false;\n\n/**\n * Extract state from a Room-like instance type.\n * Priority: useful ~state phantom > Schema state property > return T as-is\n */\ntype ExtractStateFromRoom<T> = T extends { '~state': infer S }\n ? HasUsefulStatePhantom<T> extends true\n ? S // Use ~state if it's useful\n : T extends { state: infer St }\n ? IsSchema<St> extends true ? St : T // Fallback to state if Schema\n : T\n : T extends { state: infer S }\n ? IsSchema<S> extends true ? S : T\n : T;\n\n/**\n * Infer the state type from T, or use explicit S if provided.\n *\n * Supports multiple usage patterns:\n * - Room<MyState>: T is a Schema type, return as-is\n * - Room<MyRoom>: T is a Room instance, extract from ~state or state property\n * - Room<typeof MyRoom>: T is a constructor, instantiate first then extract\n * - Room<T, ExplicitState>: S overrides all inference\n */\nexport type InferState<T, S> = [S] extends [never]\n ? Instantiate<T> extends infer I\n ? IsSchema<I> extends true\n ? I // It's a Schema, return as-is\n : ExtractStateFromRoom<I>\n : never\n : S;\n\n/**\n * Normalizes T for message extraction: returns T if it has ~state (Room type),\n * otherwise returns any (plain state type). This ensures Room<State> is equivalent\n * to Room<any, State> when State doesn't have ~state.\n */\nexport type NormalizeRoomType<T> = Instantiate<T> extends { '~state': any } ? T : any;\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> = Instantiate<T> extends { messages: infer M } ? M : {};\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> = Instantiate<T> extends { '~client': { '~messages': infer M } } ? M : {};\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 * Fallback message handler that receives the message type as an additional parameter.\n * Used for \"_\" or \"*\" catch-all handlers.\n *\n * @template Client - The client type\n * @template This - The Room class context\n */\nexport type FallbackMessageHandler<Client = any, This = any> =\n (this: This, client: Client, type: string, message: any) => void;\n\n/**\n * Message handler type including fallback handlers.\n * Used internally to allow \"_\" and \"*\" fallback handlers in the Messages type.\n * @internal\n */\nexport type AnyMessageHandler<Client = any, This = any> =\n | MessageHandler<Client, This>\n | FallbackMessageHandler<Client, This>;\n\n/**\n * A map of message types to message handlers.\n * Supports special \"_\" and \"*\" keys for fallback/catch-all 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, AnyMessageHandler<Client, Room>> & ThisType<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
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,sBAA+C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -115,13 +115,28 @@ export type ExtractMessageType<T> = T extends {
|
|
|
115
115
|
format: infer Format extends StandardSchemaV1;
|
|
116
116
|
handler: any;
|
|
117
117
|
} ? StandardSchemaV1.InferOutput<Format> : T extends (this: any, client: any, message: infer Message) => void ? Message : any;
|
|
118
|
+
/**
|
|
119
|
+
* Fallback message handler that receives the message type as an additional parameter.
|
|
120
|
+
* Used for "_" or "*" catch-all handlers.
|
|
121
|
+
*
|
|
122
|
+
* @template Client - The client type
|
|
123
|
+
* @template This - The Room class context
|
|
124
|
+
*/
|
|
125
|
+
export type FallbackMessageHandler<Client = any, This = any> = (this: This, client: Client, type: string, message: any) => void;
|
|
126
|
+
/**
|
|
127
|
+
* Message handler type including fallback handlers.
|
|
128
|
+
* Used internally to allow "_" and "*" fallback handlers in the Messages type.
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
export type AnyMessageHandler<Client = any, This = any> = MessageHandler<Client, This> | FallbackMessageHandler<Client, This>;
|
|
118
132
|
/**
|
|
119
133
|
* A map of message types to message handlers.
|
|
134
|
+
* Supports special "_" and "*" keys for fallback/catch-all handlers.
|
|
120
135
|
*
|
|
121
136
|
* @template Room - The Room class type
|
|
122
137
|
* @template Client - The client type
|
|
123
138
|
*/
|
|
124
|
-
export type Messages<Room = any, Client = any> = Record<string,
|
|
139
|
+
export type Messages<Room = any, Client = any> = Record<string, AnyMessageHandler<Client, Room>> & ThisType<Room>;
|
|
125
140
|
/**
|
|
126
141
|
* Exposed types for the client-side SDK.
|
|
127
142
|
* Used by defineServer() to expose room and route types to the client.
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,2BAA2B;AAC3B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC","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
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,2BAA2B;AAC3B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC","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 * Note: onJoin is optional because core Room defines it as optional.\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 * Extract instance type from a constructor type.\n * If T is not a constructor, returns T as-is.\n */\ntype Instantiate<T> = T extends abstract new (...args: any) => infer I ? I : T;\n\n/**\n * Check if a type is a Schema (has ~refId marker).\n * Schema defines ~refId as optional, so we check keyof instead of property presence.\n */\ntype IsSchema<T> = '~refId' extends keyof T ? true : false;\n\n/**\n * Check if ~state phantom property contains a useful type (not object/any/never).\n * Returns true if ~state exists and has meaningful structure.\n */\ntype HasUsefulStatePhantom<T> = T extends { '~state': infer S }\n ? [S] extends [never] ? false // never is not useful\n : unknown extends S ? false // any is not useful\n : S extends object\n ? [keyof S] extends [never] ? false // {} or object with no keys is not useful\n : true\n : false\n : false;\n\n/**\n * Extract state from a Room-like instance type.\n * Priority: useful ~state phantom > Schema state property > return T as-is\n */\ntype ExtractStateFromRoom<T> = T extends { '~state': infer S }\n ? HasUsefulStatePhantom<T> extends true\n ? S // Use ~state if it's useful\n : T extends { state: infer St }\n ? IsSchema<St> extends true ? St : T // Fallback to state if Schema\n : T\n : T extends { state: infer S }\n ? IsSchema<S> extends true ? S : T\n : T;\n\n/**\n * Infer the state type from T, or use explicit S if provided.\n *\n * Supports multiple usage patterns:\n * - Room<MyState>: T is a Schema type, return as-is\n * - Room<MyRoom>: T is a Room instance, extract from ~state or state property\n * - Room<typeof MyRoom>: T is a constructor, instantiate first then extract\n * - Room<T, ExplicitState>: S overrides all inference\n */\nexport type InferState<T, S> = [S] extends [never]\n ? Instantiate<T> extends infer I\n ? IsSchema<I> extends true\n ? I // It's a Schema, return as-is\n : ExtractStateFromRoom<I>\n : never\n : S;\n\n/**\n * Normalizes T for message extraction: returns T if it has ~state (Room type),\n * otherwise returns any (plain state type). This ensures Room<State> is equivalent\n * to Room<any, State> when State doesn't have ~state.\n */\nexport type NormalizeRoomType<T> = Instantiate<T> extends { '~state': any } ? T : any;\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> = Instantiate<T> extends { messages: infer M } ? M : {};\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> = Instantiate<T> extends { '~client': { '~messages': infer M } } ? M : {};\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 * Fallback message handler that receives the message type as an additional parameter.\n * Used for \"_\" or \"*\" catch-all handlers.\n *\n * @template Client - The client type\n * @template This - The Room class context\n */\nexport type FallbackMessageHandler<Client = any, This = any> =\n (this: This, client: Client, type: string, message: any) => void;\n\n/**\n * Message handler type including fallback handlers.\n * Used internally to allow \"_\" and \"*\" fallback handlers in the Messages type.\n * @internal\n */\nexport type AnyMessageHandler<Client = any, This = any> =\n | MessageHandler<Client, This>\n | FallbackMessageHandler<Client, This>;\n\n/**\n * A map of message types to message handlers.\n * Supports special \"_\" and \"*\" keys for fallback/catch-all 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, AnyMessageHandler<Client, Room>> & ThisType<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.map
CHANGED
|
@@ -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// 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 * Note: onJoin is optional because core Room defines it as optional.\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 * Extract instance type from a constructor type.\n * If T is not a constructor, returns T as-is.\n */\ntype Instantiate<T> = T extends abstract new (...args: any) => infer I ? I : T;\n\n/**\n * Check if a type is a Schema (has ~refId marker).\n * Schema defines ~refId as optional, so we check keyof instead of property presence.\n */\ntype IsSchema<T> = '~refId' extends keyof T ? true : false;\n\n/**\n * Check if ~state phantom property contains a useful type (not object/any/never).\n * Returns true if ~state exists and has meaningful structure.\n */\ntype HasUsefulStatePhantom<T> = T extends { '~state': infer S }\n ? [S] extends [never] ? false // never is not useful\n : unknown extends S ? false // any is not useful\n : S extends object\n ? [keyof S] extends [never] ? false // {} or object with no keys is not useful\n : true\n : false\n : false;\n\n/**\n * Extract state from a Room-like instance type.\n * Priority: useful ~state phantom > Schema state property > return T as-is\n */\ntype ExtractStateFromRoom<T> = T extends { '~state': infer S }\n ? HasUsefulStatePhantom<T> extends true\n ? S // Use ~state if it's useful\n : T extends { state: infer St }\n ? IsSchema<St> extends true ? St : T // Fallback to state if Schema\n : T\n : T extends { state: infer S }\n ? IsSchema<S> extends true ? S : T\n : T;\n\n/**\n * Infer the state type from T, or use explicit S if provided.\n *\n * Supports multiple usage patterns:\n * - Room<MyState>: T is a Schema type, return as-is\n * - Room<MyRoom>: T is a Room instance, extract from ~state or state property\n * - Room<typeof MyRoom>: T is a constructor, instantiate first then extract\n * - Room<T, ExplicitState>: S overrides all inference\n */\nexport type InferState<T, S> = [S] extends [never]\n ? Instantiate<T> extends infer I\n ? IsSchema<I> extends true\n ? I // It's a Schema, return as-is\n : ExtractStateFromRoom<I>\n : never\n : S;\n\n/**\n * Normalizes T for message extraction: returns T if it has ~state (Room type),\n * otherwise returns any (plain state type). This ensures Room<State> is equivalent\n * to Room<any, State> when State doesn't have ~state.\n */\nexport type NormalizeRoomType<T> = Instantiate<T> extends { '~state': any } ? T : any;\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> = Instantiate<T> extends { messages: infer M } ? M : {};\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> = Instantiate<T> extends { '~client': { '~messages': infer M } } ? M : {};\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,
|
|
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 * Note: onJoin is optional because core Room defines it as optional.\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 * Extract instance type from a constructor type.\n * If T is not a constructor, returns T as-is.\n */\ntype Instantiate<T> = T extends abstract new (...args: any) => infer I ? I : T;\n\n/**\n * Check if a type is a Schema (has ~refId marker).\n * Schema defines ~refId as optional, so we check keyof instead of property presence.\n */\ntype IsSchema<T> = '~refId' extends keyof T ? true : false;\n\n/**\n * Check if ~state phantom property contains a useful type (not object/any/never).\n * Returns true if ~state exists and has meaningful structure.\n */\ntype HasUsefulStatePhantom<T> = T extends { '~state': infer S }\n ? [S] extends [never] ? false // never is not useful\n : unknown extends S ? false // any is not useful\n : S extends object\n ? [keyof S] extends [never] ? false // {} or object with no keys is not useful\n : true\n : false\n : false;\n\n/**\n * Extract state from a Room-like instance type.\n * Priority: useful ~state phantom > Schema state property > return T as-is\n */\ntype ExtractStateFromRoom<T> = T extends { '~state': infer S }\n ? HasUsefulStatePhantom<T> extends true\n ? S // Use ~state if it's useful\n : T extends { state: infer St }\n ? IsSchema<St> extends true ? St : T // Fallback to state if Schema\n : T\n : T extends { state: infer S }\n ? IsSchema<S> extends true ? S : T\n : T;\n\n/**\n * Infer the state type from T, or use explicit S if provided.\n *\n * Supports multiple usage patterns:\n * - Room<MyState>: T is a Schema type, return as-is\n * - Room<MyRoom>: T is a Room instance, extract from ~state or state property\n * - Room<typeof MyRoom>: T is a constructor, instantiate first then extract\n * - Room<T, ExplicitState>: S overrides all inference\n */\nexport type InferState<T, S> = [S] extends [never]\n ? Instantiate<T> extends infer I\n ? IsSchema<I> extends true\n ? I // It's a Schema, return as-is\n : ExtractStateFromRoom<I>\n : never\n : S;\n\n/**\n * Normalizes T for message extraction: returns T if it has ~state (Room type),\n * otherwise returns any (plain state type). This ensures Room<State> is equivalent\n * to Room<any, State> when State doesn't have ~state.\n */\nexport type NormalizeRoomType<T> = Instantiate<T> extends { '~state': any } ? T : any;\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> = Instantiate<T> extends { messages: infer M } ? M : {};\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> = Instantiate<T> extends { '~client': { '~messages': infer M } } ? M : {};\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 * Fallback message handler that receives the message type as an additional parameter.\n * Used for \"_\" or \"*\" catch-all handlers.\n *\n * @template Client - The client type\n * @template This - The Room class context\n */\nexport type FallbackMessageHandler<Client = any, This = any> =\n (this: This, client: Client, type: string, message: any) => void;\n\n/**\n * Message handler type including fallback handlers.\n * Used internally to allow \"_\" and \"*\" fallback handlers in the Messages type.\n * @internal\n */\nexport type AnyMessageHandler<Client = any, This = any> =\n | MessageHandler<Client, This>\n | FallbackMessageHandler<Client, This>;\n\n/**\n * A map of message types to message handlers.\n * Supports special \"_\" and \"*\" keys for fallback/catch-all 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, AnyMessageHandler<Client, Room>> & ThisType<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
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.
|
|
3
|
+
"version": "0.17.6",
|
|
4
4
|
"description": "Shared TypeScript types for Colyseus server and client SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"input": "./src/index.ts",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"vitest": "^3.1.1",
|
|
50
|
-
"@colyseus/core": "^0.17.
|
|
51
|
-
"@colyseus/sdk": "^0.17.
|
|
50
|
+
"@colyseus/core": "^0.17.30",
|
|
51
|
+
"@colyseus/sdk": "^0.17.26"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
package/src/Protocol.ts
CHANGED
|
@@ -45,6 +45,8 @@ export const CloseCode = {
|
|
|
45
45
|
CONSENTED: 4000,
|
|
46
46
|
SERVER_SHUTDOWN: 4001,
|
|
47
47
|
WITH_ERROR: 4002,
|
|
48
|
-
|
|
48
|
+
FAILED_TO_RECONNECT: 4003,
|
|
49
|
+
|
|
50
|
+
MAY_TRY_RECONNECT: 4010,
|
|
49
51
|
} as const;
|
|
50
52
|
export type CloseCode = typeof CloseCode[keyof typeof CloseCode];
|
package/src/index.ts
CHANGED
|
@@ -140,13 +140,33 @@ export type ExtractMessageType<T> =
|
|
|
140
140
|
? Message
|
|
141
141
|
: any;
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Fallback message handler that receives the message type as an additional parameter.
|
|
145
|
+
* Used for "_" or "*" catch-all handlers.
|
|
146
|
+
*
|
|
147
|
+
* @template Client - The client type
|
|
148
|
+
* @template This - The Room class context
|
|
149
|
+
*/
|
|
150
|
+
export type FallbackMessageHandler<Client = any, This = any> =
|
|
151
|
+
(this: This, client: Client, type: string, message: any) => void;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Message handler type including fallback handlers.
|
|
155
|
+
* Used internally to allow "_" and "*" fallback handlers in the Messages type.
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
export type AnyMessageHandler<Client = any, This = any> =
|
|
159
|
+
| MessageHandler<Client, This>
|
|
160
|
+
| FallbackMessageHandler<Client, This>;
|
|
161
|
+
|
|
143
162
|
/**
|
|
144
163
|
* A map of message types to message handlers.
|
|
164
|
+
* Supports special "_" and "*" keys for fallback/catch-all handlers.
|
|
145
165
|
*
|
|
146
166
|
* @template Room - The Room class type
|
|
147
167
|
* @template Client - The client type
|
|
148
168
|
*/
|
|
149
|
-
export type Messages<Room = any, Client = any> = Record<string,
|
|
169
|
+
export type Messages<Room = any, Client = any> = Record<string, AnyMessageHandler<Client, Room>> & ThisType<Room>;
|
|
150
170
|
|
|
151
171
|
/**
|
|
152
172
|
* Exposed types for the client-side SDK.
|