room-kit 1.0.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/src/index.ts ADDED
@@ -0,0 +1,34 @@
1
+ export { ClientSafeError } from "./types";
2
+ export { createRoomClient } from "./client";
3
+ export { defineRoomType } from "./room";
4
+ export { serveRoomType } from "./server";
5
+
6
+ export type {
7
+ ClientConnectionState,
8
+ ClientSocketLike,
9
+ EventMetaFor,
10
+ JoinRequest,
11
+ JoinedRoom,
12
+ MemberProfileFor,
13
+ PresenceListQuery,
14
+ PresenceFor,
15
+ PresencePageFor,
16
+ PresencePolicy,
17
+ RoomMemberSnapshot,
18
+ RoomClient,
19
+ RoomDefinition,
20
+ RoomEvents,
21
+ RoomProfileFor,
22
+ RoomRpc,
23
+ RoomSchema,
24
+ ServerStateFor,
25
+ RoomServerAdapter,
26
+ RoomServerBroadcastApi,
27
+ RoomServerHandle,
28
+ RoomServerContext,
29
+ RoomServerHandlers,
30
+ RoomSnapshot,
31
+ ServerAdmission,
32
+ ServerSocketLike,
33
+ VisibleMemberFor,
34
+ } from "./types";
package/src/room.ts ADDED
@@ -0,0 +1,32 @@
1
+ import type { RoomDefinition, RoomSchema } from "./types";
2
+
3
+ /**
4
+ * Defines a room type using a type-only schema and runtime options.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const chatRoom = defineRoomType<{
9
+ * joinRequest: { roomId: string; roomKey: string; userName: string };
10
+ * memberProfile: { userId: string; userName: string };
11
+ * roomProfile: { roomId: string; created: string };
12
+ * serverState: { roomKey: string; created: string };
13
+ * events: { message: { text: string } };
14
+ * rpc: { sendMessage: (input: { text: string }) => Promise<void> };
15
+ * }>({
16
+ * name: "chat",
17
+ * presence: "count",
18
+ * });
19
+ * ```
20
+ */
21
+ export function defineRoomType<TSchema extends RoomSchema, TPresence extends "none" | "count" | "list" = "list">(
22
+ options: {
23
+ readonly name: string;
24
+ readonly presence?: TPresence;
25
+ },
26
+ ): RoomDefinition<TSchema, TPresence> {
27
+ return {
28
+ kind: "room",
29
+ name: options.name,
30
+ presence: options.presence ?? "list",
31
+ } as RoomDefinition<TSchema, TPresence>;
32
+ }