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/.github/workflows/publish.yml +16 -0
- package/LICENSE +21 -0
- package/README.md +262 -0
- package/changelog.md +13 -0
- package/dist/client.d.ts +16 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +317 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/room.d.ts +24 -0
- package/dist/room.d.ts.map +1 -0
- package/dist/room.js +26 -0
- package/dist/room.js.map +1 -0
- package/dist/server.d.ts +27 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +770 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +413 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/example/README.md +43 -0
- package/example/common.ts +41 -0
- package/example/package.json +17 -0
- package/example/public/app.ts +298 -0
- package/example/public/index.html +86 -0
- package/example/public/styles.css +317 -0
- package/example/server.ts +200 -0
- package/jsr.json +13 -0
- package/package.json +42 -0
- package/src/client.ts +433 -0
- package/src/index.ts +34 -0
- package/src/room.ts +32 -0
- package/src/server.ts +1064 -0
- package/src/types.ts +503 -0
- package/test/room.spec.ts +2401 -0
- package/tsconfig.json +20 -0
- package/tsconfig.test.json +9 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/room.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RoomDefinition, RoomSchema } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Defines a room type using a type-only schema and runtime options.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const chatRoom = defineRoomType<{
|
|
8
|
+
* joinRequest: { roomId: string; roomKey: string; userName: string };
|
|
9
|
+
* memberProfile: { userId: string; userName: string };
|
|
10
|
+
* roomProfile: { roomId: string; created: string };
|
|
11
|
+
* serverState: { roomKey: string; created: string };
|
|
12
|
+
* events: { message: { text: string } };
|
|
13
|
+
* rpc: { sendMessage: (input: { text: string }) => Promise<void> };
|
|
14
|
+
* }>({
|
|
15
|
+
* name: "chat",
|
|
16
|
+
* presence: "count",
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function defineRoomType<TSchema extends RoomSchema, TPresence extends "none" | "count" | "list" = "list">(options: {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly presence?: TPresence;
|
|
23
|
+
}): RoomDefinition<TSchema, TPresence>;
|
|
24
|
+
//# sourceMappingURL=room.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room.d.ts","sourceRoot":"","sources":["../src/room.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,UAAU,EAAE,SAAS,SAAS,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,EAC3G,OAAO,EAAE;IACL,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACjC,GACF,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC,CAMpC"}
|
package/dist/room.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines a room type using a type-only schema and runtime options.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const chatRoom = defineRoomType<{
|
|
7
|
+
* joinRequest: { roomId: string; roomKey: string; userName: string };
|
|
8
|
+
* memberProfile: { userId: string; userName: string };
|
|
9
|
+
* roomProfile: { roomId: string; created: string };
|
|
10
|
+
* serverState: { roomKey: string; created: string };
|
|
11
|
+
* events: { message: { text: string } };
|
|
12
|
+
* rpc: { sendMessage: (input: { text: string }) => Promise<void> };
|
|
13
|
+
* }>({
|
|
14
|
+
* name: "chat",
|
|
15
|
+
* presence: "count",
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function defineRoomType(options) {
|
|
20
|
+
return {
|
|
21
|
+
kind: "room",
|
|
22
|
+
name: options.name,
|
|
23
|
+
presence: options.presence ?? "list",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=room.js.map
|
package/dist/room.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room.js","sourceRoot":"","sources":["../src/room.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,cAAc,CAC1B,OAGC;IAED,OAAO;QACH,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,MAAM;KACD,CAAC;AAC5C,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RoomDefinition, RoomServerAdapter, RoomServerHandle, RoomServerHandlers, ServerSocketLike } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Attaches room runtime handlers to a connected server socket.
|
|
4
|
+
*
|
|
5
|
+
* Returns a callable handle that unregisters all listeners for the bound
|
|
6
|
+
* socket, and exposes room introspection helpers.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* io.on("connection", (socket) => {
|
|
11
|
+
* const stop = serveRoomType(socket, chatRoomType, {
|
|
12
|
+
* onAuth: async () => ({ userId: socket.id }),
|
|
13
|
+
* admit: async (join, ctx) => ({
|
|
14
|
+
* roomId: join.roomId,
|
|
15
|
+
* memberId: ctx.auth.userId,
|
|
16
|
+
* memberProfile: { userId: ctx.auth.userId, userName: join.userName },
|
|
17
|
+
* roomProfile: { roomId: join.roomId, created: new Date().toISOString() },
|
|
18
|
+
* }),
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Later if needed:
|
|
22
|
+
* // stop();
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function serveRoomType<TRoom extends RoomDefinition<any>, TAuth = unknown>(socket: ServerSocketLike, _room: TRoom, handlers: RoomServerHandlers<TRoom, TAuth>, adapter?: RoomServerAdapter): RoomServerHandle<TRoom>;
|
|
27
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAUR,cAAc,EAEd,iBAAiB,EAEjB,gBAAgB,EAEhB,kBAAkB,EAElB,gBAAgB,EAInB,MAAM,SAAS,CAAC;AAoCjB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAAC,KAAK,SAAS,cAAc,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,EAC5E,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,EAC1C,OAAO,CAAC,EAAE,iBAAiB,GAC5B,gBAAgB,CAAC,KAAK,CAAC,CAyVzB"}
|