@signe/room 2.10.0 → 3.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/chunk-EUXUH3YW.js +15 -0
  3. package/dist/chunk-EUXUH3YW.js.map +1 -0
  4. package/dist/cloudflare/index.d.ts +71 -0
  5. package/dist/cloudflare/index.js +320 -0
  6. package/dist/cloudflare/index.js.map +1 -0
  7. package/dist/index.d.ts +66 -187
  8. package/dist/index.js +727 -106
  9. package/dist/index.js.map +1 -1
  10. package/dist/node/index.d.ts +164 -0
  11. package/dist/node/index.js +786 -0
  12. package/dist/node/index.js.map +1 -0
  13. package/dist/party-dNs-hqkq.d.ts +175 -0
  14. package/examples/cloudflare/README.md +62 -0
  15. package/examples/cloudflare/node_modules/.bin/tsc +17 -0
  16. package/examples/cloudflare/node_modules/.bin/tsserver +17 -0
  17. package/examples/cloudflare/node_modules/.bin/wrangler +17 -0
  18. package/examples/cloudflare/node_modules/.bin/wrangler2 +17 -0
  19. package/examples/cloudflare/package.json +24 -0
  20. package/examples/cloudflare/public/index.html +443 -0
  21. package/examples/cloudflare/src/index.ts +28 -0
  22. package/examples/cloudflare/src/room.ts +44 -0
  23. package/examples/cloudflare/tsconfig.json +10 -0
  24. package/examples/cloudflare/wrangler.jsonc +25 -0
  25. package/examples/node/README.md +57 -0
  26. package/examples/node/node_modules/.bin/tsc +17 -0
  27. package/examples/node/node_modules/.bin/tsserver +17 -0
  28. package/examples/node/node_modules/.bin/tsx +17 -0
  29. package/examples/node/package.json +23 -0
  30. package/examples/node/public/index.html +443 -0
  31. package/examples/node/room.ts +44 -0
  32. package/examples/node/server.sqlite.ts +52 -0
  33. package/examples/node/server.ts +51 -0
  34. package/examples/node/tsconfig.json +10 -0
  35. package/examples/node-game/README.md +66 -0
  36. package/examples/node-game/package.json +23 -0
  37. package/examples/node-game/public/index.html +705 -0
  38. package/examples/node-game/room.ts +145 -0
  39. package/examples/node-game/server.sqlite.ts +54 -0
  40. package/examples/node-game/server.ts +53 -0
  41. package/examples/node-game/tsconfig.json +10 -0
  42. package/examples/node-shard/README.md +32 -0
  43. package/examples/node-shard/dev.ts +39 -0
  44. package/examples/node-shard/package.json +24 -0
  45. package/examples/node-shard/public/index.html +777 -0
  46. package/examples/node-shard/room-server.ts +68 -0
  47. package/examples/node-shard/room.ts +105 -0
  48. package/examples/node-shard/shared.ts +6 -0
  49. package/examples/node-shard/tsconfig.json +14 -0
  50. package/examples/node-shard/world-server.ts +169 -0
  51. package/package.json +14 -5
  52. package/readme.md +371 -4
  53. package/src/cloudflare/index.ts +474 -0
  54. package/src/jwt.ts +1 -5
  55. package/src/mock.ts +29 -7
  56. package/src/node/index.ts +1112 -0
  57. package/src/server.ts +600 -51
  58. package/src/session.guard.ts +6 -2
  59. package/src/shard.ts +91 -23
  60. package/src/storage.ts +29 -5
  61. package/src/testing.ts +4 -3
  62. package/src/types/party.ts +4 -1
  63. package/src/world.guard.ts +23 -4
  64. package/src/world.ts +121 -21
  65. package/examples/game/.vscode/launch.json +0 -11
  66. package/examples/game/.vscode/settings.json +0 -11
  67. package/examples/game/README.md +0 -40
  68. package/examples/game/app/client.tsx +0 -15
  69. package/examples/game/app/components/Admin.tsx +0 -1089
  70. package/examples/game/app/components/Room.tsx +0 -162
  71. package/examples/game/app/styles.css +0 -31
  72. package/examples/game/package-lock.json +0 -225
  73. package/examples/game/package.json +0 -20
  74. package/examples/game/party/game.room.ts +0 -32
  75. package/examples/game/party/server.ts +0 -10
  76. package/examples/game/party/shard.ts +0 -5
  77. package/examples/game/partykit.json +0 -14
  78. package/examples/game/public/favicon.ico +0 -0
  79. package/examples/game/public/index.html +0 -27
  80. package/examples/game/public/normalize.css +0 -351
  81. package/examples/game/shared/room.schema.ts +0 -14
  82. package/examples/game/tsconfig.json +0 -109
@@ -1,162 +0,0 @@
1
- import { useState, useEffect, useRef } from "react";
2
- import { connectionRoom, connectionWorld } from '../../../../../sync/src/client';
3
- import { RoomSchema } from "../../shared/room.schema";
4
- import { effect } from "@signe/reactive";
5
-
6
- export default function Room() {
7
- const [isConnected, setIsConnected] = useState(false);
8
- const [isConnecting, setIsConnecting] = useState(false);
9
- const [error, setError] = useState<string | null>(null);
10
- const [roomId, setRoomId] = useState("game");
11
- const [count, setCount] = useState(0);
12
- const socketRef = useRef<any>(null);
13
- const roomRef = useRef<any>(null);
14
-
15
- const connectToRoom = async () => {
16
- setIsConnecting(true);
17
- setError(null);
18
-
19
- try {
20
- // Initialize room schema
21
- roomRef.current = new RoomSchema();
22
-
23
- // Connect to the room through the World service with auto-creation enabled
24
- socketRef.current = await connectionRoom({
25
- host: 'http://localhost:1999',
26
- id: 'test',
27
- room: roomId,
28
- }, roomRef.current);
29
-
30
- socketRef.current.on('sync', (data) => {
31
- console.log('sync', data);
32
- })
33
-
34
- // Listen for disconnection events
35
- socketRef.current.on('disconnect', () => {
36
- setIsConnected(false);
37
- setError('Disconnected from server');
38
- });
39
-
40
- effect(() => {
41
- if (roomRef.current) {
42
- setCount(roomRef.current.count());
43
- }
44
- });
45
-
46
- setIsConnected(true);
47
- } catch (err) {
48
- console.error('Connection error:', err);
49
- setError(`Failed to connect to the room: ${err instanceof Error ? err.message : String(err)}`);
50
- } finally {
51
- setIsConnecting(false);
52
- }
53
- };
54
-
55
- const disconnectFromRoom = () => {
56
- if (socketRef.current) {
57
- socketRef.current.close();
58
- socketRef.current = null;
59
- }
60
- roomRef.current = null;
61
- setIsConnected(false);
62
- };
63
-
64
- // Clean up on component unmount
65
- useEffect(() => {
66
- return () => {
67
- if (socketRef.current) {
68
- socketRef.current.close();
69
- }
70
- };
71
- }, []);
72
-
73
- // Styles
74
- const buttonStyles = {
75
- backgroundColor: isConnected ? "#f43f5e" : "#2563eb",
76
- borderRadius: "9999px",
77
- border: "none",
78
- color: "white",
79
- fontSize: "0.95rem",
80
- cursor: "pointer",
81
- padding: "1rem 3rem",
82
- margin: "1rem 0rem",
83
- disabled: isConnecting
84
- };
85
-
86
- const inputStyles = {
87
- padding: "0.75rem 1rem",
88
- borderRadius: "0.5rem",
89
- border: "1px solid #ccc",
90
- fontSize: "0.95rem",
91
- width: "100%",
92
- maxWidth: "300px",
93
- margin: "0.5rem 0"
94
- };
95
-
96
- const containerStyles = {
97
- display: "flex",
98
- flexDirection: "column" as "column",
99
- alignItems: "center",
100
- justifyContent: "center",
101
- padding: "2rem",
102
- gap: "1rem"
103
- };
104
-
105
- return (
106
- <div style={containerStyles}>
107
- <h1>Room Connection</h1>
108
-
109
- {error && (
110
- <div style={{ color: "red", margin: "1rem 0" }}>
111
- {error}
112
- </div>
113
- )}
114
-
115
- {!isConnected ? (
116
- <>
117
- <div style={{ marginBottom: "1rem", width: "100%", maxWidth: "300px" }}>
118
- <label htmlFor="roomId" style={{ display: "block", marginBottom: "0.5rem" }}>
119
- Room ID:
120
- </label>
121
- <input
122
- id="roomId"
123
- type="text"
124
- value={roomId}
125
- onChange={(e) => setRoomId(e.target.value)}
126
- style={inputStyles}
127
- placeholder="Enter room ID"
128
- disabled={isConnecting}
129
- />
130
- </div>
131
-
132
- <button
133
- style={buttonStyles}
134
- onClick={connectToRoom}
135
- disabled={isConnecting || !roomId.trim()}
136
- >
137
- {isConnecting ? "Connecting..." : "Connect to Room"}
138
- </button>
139
- </>
140
- ) : (
141
- <>
142
- <div style={{ marginBottom: "1rem" }}>
143
- <span style={{ fontWeight: "bold" }}>Connected to room: </span>
144
- <span>{roomId}</span>
145
- </div>
146
-
147
- <div style={{ marginBottom: "2rem" }}>
148
- <span>Count: {count}</span>
149
- <button className="btn btn-primary" onClick={() => socketRef.current.emit('increment')}>Increment</button>
150
- </div>
151
-
152
- <button
153
- style={buttonStyles}
154
- onClick={disconnectFromRoom}
155
- >
156
- Leave Room
157
- </button>
158
- </>
159
- )}
160
- </div>
161
- );
162
- }
@@ -1,31 +0,0 @@
1
- /*
2
- We've already included normalize.css.
3
-
4
- But we'd like a modern looking boilerplate.
5
- Clean type, sans-serif, and a nice color palette.
6
-
7
- */
8
-
9
- body {
10
- font-family: sans-serif;
11
- font-size: 16px;
12
- line-height: 1.5;
13
- color: #333;
14
- }
15
-
16
- h1,
17
- h2,
18
- h3,
19
- h4,
20
- h5,
21
- h6 {
22
- font-family: sans-serif;
23
- font-weight: 600;
24
- line-height: 1.25;
25
- margin-top: 0;
26
- margin-bottom: 0.5rem;
27
- }
28
-
29
- #app {
30
- padding: 1rem;
31
- }
@@ -1,225 +0,0 @@
1
- {
2
- "name": "game",
3
- "version": "0.0.0",
4
- "lockfileVersion": 3,
5
- "requires": true,
6
- "packages": {
7
- "": {
8
- "name": "game",
9
- "version": "0.0.0",
10
- "dependencies": {
11
- "partysocket": "^1.0.3",
12
- "react": "^18.2.0",
13
- "react-dom": "^18.2.0"
14
- },
15
- "devDependencies": {
16
- "@types/react": "^18.2.66",
17
- "@types/react-dom": "^18.2.22",
18
- "partykit": "^0.0.100",
19
- "typescript": "^5.4.2"
20
- }
21
- },
22
- "../../../../node_modules/.pnpm/@types+react-dom@18.3.0/node_modules/@types/react-dom": {
23
- "version": "18.3.0",
24
- "dev": true,
25
- "license": "MIT",
26
- "dependencies": {
27
- "@types/react": "*"
28
- }
29
- },
30
- "../../../../node_modules/.pnpm/@types+react@18.3.3/node_modules/@types/react": {
31
- "version": "18.3.3",
32
- "dev": true,
33
- "license": "MIT",
34
- "dependencies": {
35
- "@types/prop-types": "*",
36
- "csstype": "^3.0.2"
37
- }
38
- },
39
- "../../../../node_modules/.pnpm/partykit@0.0.100/node_modules/partykit": {
40
- "version": "0.0.100",
41
- "dev": true,
42
- "license": "MIT",
43
- "dependencies": {
44
- "@cloudflare/workers-types": "4.20240314.0",
45
- "clipboardy": "4.0.0",
46
- "esbuild": "0.20.2",
47
- "miniflare": "3.20240304.2",
48
- "yoga-wasm-web": "0.3.3"
49
- },
50
- "bin": {
51
- "partykit": "dist/bin.mjs"
52
- },
53
- "devDependencies": {
54
- "@clerk/clerk-js": "4.70.5",
55
- "@iarna/toml": "^2.2.5",
56
- "@types/gradient-string": "^1.1.5",
57
- "@types/is-ci": "^3.0.4",
58
- "@types/mime": "^3.0.4",
59
- "@types/node": "^20.11.28",
60
- "@types/object-hash": "^3.0.6",
61
- "@types/polka": "^0.5.7",
62
- "@types/prompts": "^2.4.9",
63
- "@types/update-notifier": "^6.0.8",
64
- "@types/ws": "^8.5.10",
65
- "chalk": "^5.3.0",
66
- "chokidar": "^3.6.0",
67
- "commander": "^12.0.0",
68
- "detect-indent": "^7.0.1",
69
- "devtools-protocol": "^0.0.1273771",
70
- "dotenv": "^16.4.5",
71
- "dotenv-cli": "^7.4.1",
72
- "eslint-plugin-react-hooks": "^4.6.0",
73
- "execa": "^8.0.1",
74
- "find-up": "^7.0.0",
75
- "get-port": "^7.0.0",
76
- "gradient-string": "^2.0.2",
77
- "http-terminator": "^3.2.0",
78
- "ink": "4.4.1",
79
- "ink-select-input": "^5.0.0",
80
- "is-ci": "^3.0.1",
81
- "json5": "^2.2.3",
82
- "mime": "^4.0.1",
83
- "object-hash": "^3.0.0",
84
- "open": "^10.1.0",
85
- "p-limit": "^5.0.0",
86
- "p-retry": "^6.2.0",
87
- "prompts": "^2.4.2",
88
- "react": "^18.2.0",
89
- "react-error-boundary": "^4.0.13",
90
- "signal-exit": "^4.1.0",
91
- "source-map": "^0.7.4",
92
- "undici": "^6.9.0",
93
- "update-notifier": "^7.0.0",
94
- "which-pm-runs": "^1.1.0",
95
- "ws": "^8.16.0",
96
- "xdg-app-paths": "^8.3.0",
97
- "zod": "^3.22.4",
98
- "zod-to-json-schema": "^3.22.4",
99
- "zod-validation-error": "^3.0.3"
100
- },
101
- "optionalDependencies": {
102
- "fsevents": "2.3.3"
103
- }
104
- },
105
- "../../../../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom": {
106
- "version": "18.3.1",
107
- "license": "MIT",
108
- "dependencies": {
109
- "loose-envify": "^1.1.0",
110
- "scheduler": "^0.23.2"
111
- },
112
- "peerDependencies": {
113
- "react": "^18.3.1"
114
- }
115
- },
116
- "../../../../node_modules/.pnpm/react@18.3.1/node_modules/react": {
117
- "version": "18.3.1",
118
- "license": "MIT",
119
- "dependencies": {
120
- "loose-envify": "^1.1.0"
121
- },
122
- "engines": {
123
- "node": ">=0.10.0"
124
- }
125
- },
126
- "../../../../node_modules/.pnpm/typescript@5.4.5/node_modules/typescript": {
127
- "version": "5.4.5",
128
- "dev": true,
129
- "license": "Apache-2.0",
130
- "bin": {
131
- "tsc": "bin/tsc",
132
- "tsserver": "bin/tsserver"
133
- },
134
- "devDependencies": {
135
- "@esfx/canceltoken": "^1.0.0",
136
- "@octokit/rest": "^20.0.2",
137
- "@types/chai": "^4.3.11",
138
- "@types/glob": "^8.1.0",
139
- "@types/microsoft__typescript-etw": "^0.1.3",
140
- "@types/minimist": "^1.2.5",
141
- "@types/mocha": "^10.0.6",
142
- "@types/ms": "^0.7.34",
143
- "@types/node": "latest",
144
- "@types/source-map-support": "^0.5.10",
145
- "@types/which": "^3.0.3",
146
- "@typescript-eslint/eslint-plugin": "^6.19.0",
147
- "@typescript-eslint/parser": "^6.19.0",
148
- "@typescript-eslint/utils": "^6.19.0",
149
- "azure-devops-node-api": "^12.3.0",
150
- "c8": "^9.1.0",
151
- "chai": "^4.4.1",
152
- "chalk": "^4.1.2",
153
- "chokidar": "^3.5.3",
154
- "diff": "^5.1.0",
155
- "dprint": "^0.45.0",
156
- "esbuild": "^0.20.0",
157
- "eslint": "^8.56.0",
158
- "eslint-formatter-autolinkable-stylish": "^1.3.0",
159
- "eslint-plugin-local": "^3.1.0",
160
- "eslint-plugin-no-null": "^1.0.2",
161
- "eslint-plugin-simple-import-sort": "^10.0.0",
162
- "fast-xml-parser": "^4.3.3",
163
- "glob": "^10.3.10",
164
- "hereby": "^1.8.9",
165
- "jsonc-parser": "^3.2.0",
166
- "minimist": "^1.2.8",
167
- "mocha": "^10.2.0",
168
- "mocha-fivemat-progress-reporter": "^0.1.0",
169
- "ms": "^2.1.3",
170
- "node-fetch": "^3.3.2",
171
- "playwright": "^1.41.0",
172
- "source-map-support": "^0.5.21",
173
- "tslib": "^2.6.2",
174
- "typescript": "5.4.0-dev.20240119",
175
- "which": "^3.0.1"
176
- },
177
- "engines": {
178
- "node": ">=14.17"
179
- }
180
- },
181
- "node_modules/@types/react": {
182
- "resolved": "../../../../node_modules/.pnpm/@types+react@18.3.3/node_modules/@types/react",
183
- "link": true
184
- },
185
- "node_modules/@types/react-dom": {
186
- "resolved": "../../../../node_modules/.pnpm/@types+react-dom@18.3.0/node_modules/@types/react-dom",
187
- "link": true
188
- },
189
- "node_modules/event-target-shim": {
190
- "version": "6.0.2",
191
- "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-6.0.2.tgz",
192
- "integrity": "sha512-8q3LsZjRezbFZ2PN+uP+Q7pnHUMmAOziU2vA2OwoFaKIXxlxl38IylhSSgUorWu/rf4er67w0ikBqjBFk/pomA==",
193
- "engines": {
194
- "node": ">=10.13.0"
195
- },
196
- "funding": {
197
- "url": "https://github.com/sponsors/mysticatea"
198
- }
199
- },
200
- "node_modules/partykit": {
201
- "resolved": "../../../../node_modules/.pnpm/partykit@0.0.100/node_modules/partykit",
202
- "link": true
203
- },
204
- "node_modules/partysocket": {
205
- "version": "1.0.3",
206
- "resolved": "https://registry.npmjs.org/partysocket/-/partysocket-1.0.3.tgz",
207
- "integrity": "sha512-7sSojS4oCRK1Fe1h+Sa0Za5dwOf+M9VksQlynD8yqwGpLvnO4oxx9ppmOSeh6CJTMbF5gbnvUQKMK525QSBdBw==",
208
- "dependencies": {
209
- "event-target-shim": "^6.0.2"
210
- }
211
- },
212
- "node_modules/react": {
213
- "resolved": "../../../../node_modules/.pnpm/react@18.3.1/node_modules/react",
214
- "link": true
215
- },
216
- "node_modules/react-dom": {
217
- "resolved": "../../../../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom",
218
- "link": true
219
- },
220
- "node_modules/typescript": {
221
- "resolved": "../../../../node_modules/.pnpm/typescript@5.4.5/node_modules/typescript",
222
- "link": true
223
- }
224
- }
225
- }
@@ -1,20 +0,0 @@
1
- {
2
- "name": "game",
3
- "version": "0.0.0",
4
- "private": true,
5
- "scripts": {
6
- "dev": "partykit dev --live",
7
- "deploy": "partykit deploy"
8
- },
9
- "dependencies": {
10
- "partysocket": "^1.0.3",
11
- "react": "^18.2.0",
12
- "react-dom": "^18.2.0"
13
- },
14
- "devDependencies": {
15
- "@types/react": "^18.2.66",
16
- "@types/react-dom": "^18.2.22",
17
- "partykit": "^0.0.100",
18
- "typescript": "^5.4.2"
19
- }
20
- }
@@ -1,32 +0,0 @@
1
- import { Action, Guard, requireSession, Room } from "../../../src";
2
- import { RoomSchema } from "../shared/room.schema";
3
-
4
- @Room({
5
- path: 'game',
6
- sessionExpiryTime: 5000
7
- })
8
- export class GameRoom extends RoomSchema {
9
- @Action('increment')
10
- increment(player) {
11
- this.count.update((count) => count + 1);
12
- player.score.update((score) => score + 1);
13
- this.$sessionTransfer(player.id(), "protected-1");
14
- }
15
-
16
- async onRequest(req: Party.Request, room: any) {
17
- const map = await room.storage.list() as Map<string, any>;
18
- return Object.fromEntries(map);
19
- }
20
- }
21
-
22
- @Room({
23
- path: 'protected-{gameId}',
24
- sessionExpiryTime: 5000,
25
- guards: [requireSession]
26
- })
27
- export class ProtectedRoom extends RoomSchema {
28
- @Action('increment')
29
- increment(player) {
30
- console.log('increment', player);
31
- }
32
- }
@@ -1,10 +0,0 @@
1
- import { Server, WorldRoom } from '../../../src';
2
- import type * as Party from "../../../src/types/party";
3
- import { GameRoom, ProtectedRoom } from "./game.room";
4
-
5
- export default class MainServer extends Server {
6
- rooms = [
7
- GameRoom ,
8
- ProtectedRoom
9
- ]
10
- }
@@ -1,5 +0,0 @@
1
- import { Shard } from '../../../src';
2
-
3
- export default class MyShard extends Shard {
4
-
5
- }
@@ -1,14 +0,0 @@
1
- {
2
- "$schema": "https://www.partykit.io/schema.json",
3
- "name": "signe",
4
- "main": "party/server.ts",
5
- "compatibilityDate": "2025-02-04",
6
- "parties": {
7
- "shard": "party/shard.ts",
8
- "world": "party/server.ts"
9
- },
10
- "serve": {
11
- "path": "public",
12
- "build": "app/client.tsx"
13
- }
14
- }
Binary file
@@ -1,27 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta
6
- name="viewport"
7
- content="width=device-width, initial-scale=1.0, shrink-to-fit=no"
8
- />
9
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
10
- <title>PartyKit: Everything's better with friends!</title>
11
- <!-- Favicon -->
12
- <link rel="icon" href="/favicon.ico" sizes="any" />
13
- <!-- Primary Meta Tags -->
14
- <meta name="title" content="PartyKit" />
15
- <meta name="description" content="Everything's better with friends!" />
16
- <meta name="author" content="PartyKit" />
17
- <!-- Theme Colour -->
18
- <meta name="theme-color" content="#ffffff" />
19
-
20
- <link rel="stylesheet" href="/normalize.css" />
21
- <link rel="stylesheet" href="/dist/client.css" />
22
- </head>
23
- <body>
24
- <div id="app"></div>
25
- <script type="module" src="/dist/client.js"></script>
26
- </body>
27
- </html>