@mnbroatch/boardgame.io 0.0.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.
Files changed (296) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -0
  3. package/ai/package.json +7 -0
  4. package/client/package.json +7 -0
  5. package/core/package.json +7 -0
  6. package/debug/package.json +7 -0
  7. package/dist/boardgameio.es.js +14238 -0
  8. package/dist/boardgameio.js +14277 -0
  9. package/dist/boardgameio.min.js +16 -0
  10. package/dist/cjs/Debug-9d141c06.js +9586 -0
  11. package/dist/cjs/ai-e0e8a768.js +377 -0
  12. package/dist/cjs/ai.js +20 -0
  13. package/dist/cjs/client-76dec77b.js +258 -0
  14. package/dist/cjs/client-a22d7500.js +524 -0
  15. package/dist/cjs/client.js +26 -0
  16. package/dist/cjs/core.js +52 -0
  17. package/dist/cjs/debug.js +18 -0
  18. package/dist/cjs/filter-player-view-bb02e2f6.js +89 -0
  19. package/dist/cjs/initialize-267fcd69.js +61 -0
  20. package/dist/cjs/internal.js +25 -0
  21. package/dist/cjs/master-2904879d.js +320 -0
  22. package/dist/cjs/master.js +18 -0
  23. package/dist/cjs/multiplayer.js +23 -0
  24. package/dist/cjs/plugin-random-7425844d.js +229 -0
  25. package/dist/cjs/plugins.js +59 -0
  26. package/dist/cjs/react-native.js +182 -0
  27. package/dist/cjs/react.js +727 -0
  28. package/dist/cjs/reducer-16eec232.js +1203 -0
  29. package/dist/cjs/server.js +4087 -0
  30. package/dist/cjs/socketio-7a0837eb.js +478 -0
  31. package/dist/cjs/testing.js +30 -0
  32. package/dist/cjs/transport-b1874dfa.js +37 -0
  33. package/dist/cjs/turn-order-b2ff8740.js +1136 -0
  34. package/dist/cjs/util-fcfd8fb8.js +140 -0
  35. package/dist/esm/Debug-0141fe2d.js +9577 -0
  36. package/dist/esm/ai-5c06e761.js +371 -0
  37. package/dist/esm/ai.js +8 -0
  38. package/dist/esm/client-2e653027.js +522 -0
  39. package/dist/esm/client-5f57c3f2.js +255 -0
  40. package/dist/esm/client.js +16 -0
  41. package/dist/esm/core.js +40 -0
  42. package/dist/esm/debug.js +10 -0
  43. package/dist/esm/filter-player-view-2c6cc96f.js +87 -0
  44. package/dist/esm/initialize-11d626ca.js +59 -0
  45. package/dist/esm/internal.js +10 -0
  46. package/dist/esm/master-fa8f2e43.js +318 -0
  47. package/dist/esm/master.js +10 -0
  48. package/dist/esm/multiplayer.js +14 -0
  49. package/dist/esm/plugin-random-087f861e.js +226 -0
  50. package/dist/esm/plugins.js +55 -0
  51. package/dist/esm/react-native.js +173 -0
  52. package/dist/esm/react.js +716 -0
  53. package/dist/esm/reducer-c46da7e5.js +1198 -0
  54. package/dist/esm/socketio-c22ffa65.js +455 -0
  55. package/dist/esm/testing.js +26 -0
  56. package/dist/esm/transport-ce07b771.js +35 -0
  57. package/dist/esm/turn-order-376d315e.js +1091 -0
  58. package/dist/esm/util-b6147cef.js +135 -0
  59. package/dist/types/packages/ai.d.ts +5 -0
  60. package/dist/types/packages/client.d.ts +3 -0
  61. package/dist/types/packages/core.d.ts +5 -0
  62. package/dist/types/packages/debug.d.ts +2 -0
  63. package/dist/types/packages/internal.d.ts +8 -0
  64. package/dist/types/packages/master.d.ts +2 -0
  65. package/dist/types/packages/multiplayer.d.ts +3 -0
  66. package/dist/types/packages/plugins.d.ts +3 -0
  67. package/dist/types/packages/react-native.d.ts +2 -0
  68. package/dist/types/packages/react.d.ts +3 -0
  69. package/dist/types/packages/server.d.ts +6 -0
  70. package/dist/types/packages/testing.d.ts +1 -0
  71. package/dist/types/src/ai/ai.d.ts +53 -0
  72. package/dist/types/src/ai/ai.test.d.ts +1 -0
  73. package/dist/types/src/ai/bot.d.ts +40 -0
  74. package/dist/types/src/ai/mcts-bot.d.ts +60 -0
  75. package/dist/types/src/ai/random-bot.d.ts +27 -0
  76. package/dist/types/src/client/client.d.ts +104 -0
  77. package/dist/types/src/client/client.test.d.ts +1 -0
  78. package/dist/types/src/client/debug/tests/debug.test.d.ts +1 -0
  79. package/dist/types/src/client/manager.d.ts +61 -0
  80. package/dist/types/src/client/react.d.ts +75 -0
  81. package/dist/types/src/client/react.ssr.test.d.ts +4 -0
  82. package/dist/types/src/client/react.test.d.ts +1 -0
  83. package/dist/types/src/client/transport/dummy.d.ts +18 -0
  84. package/dist/types/src/client/transport/local.d.ts +59 -0
  85. package/dist/types/src/client/transport/local.test.d.ts +1 -0
  86. package/dist/types/src/client/transport/socketio.d.ts +45 -0
  87. package/dist/types/src/client/transport/socketio.test.d.ts +1 -0
  88. package/dist/types/src/client/transport/transport.d.ts +50 -0
  89. package/dist/types/src/client/transport/transport.test.d.ts +1 -0
  90. package/dist/types/src/core/action-creators.d.ts +144 -0
  91. package/dist/types/src/core/action-types.d.ts +10 -0
  92. package/dist/types/src/core/backwards-compatibility.d.ts +12 -0
  93. package/dist/types/src/core/constants.d.ts +6 -0
  94. package/dist/types/src/core/errors.d.ts +15 -0
  95. package/dist/types/src/core/flow.d.ts +28 -0
  96. package/dist/types/src/core/flow.test.d.ts +1 -0
  97. package/dist/types/src/core/game-methods.d.ts +9 -0
  98. package/dist/types/src/core/game.d.ts +26 -0
  99. package/dist/types/src/core/game.test.d.ts +1 -0
  100. package/dist/types/src/core/initialize.d.ts +9 -0
  101. package/dist/types/src/core/logger.d.ts +2 -0
  102. package/dist/types/src/core/player-view.d.ts +7 -0
  103. package/dist/types/src/core/player-view.test.d.ts +1 -0
  104. package/dist/types/src/core/reducer.d.ts +155 -0
  105. package/dist/types/src/core/reducer.test.d.ts +1 -0
  106. package/dist/types/src/core/turn-order.d.ts +179 -0
  107. package/dist/types/src/core/turn-order.test.d.ts +8 -0
  108. package/dist/types/src/lobby/client.d.ts +194 -0
  109. package/dist/types/src/lobby/client.test.d.ts +1 -0
  110. package/dist/types/src/lobby/connection.d.ts +44 -0
  111. package/dist/types/src/lobby/connection.test.d.ts +1 -0
  112. package/dist/types/src/lobby/create-match-form.d.ts +26 -0
  113. package/dist/types/src/lobby/login-form.d.ts +23 -0
  114. package/dist/types/src/lobby/match-instance.d.ts +31 -0
  115. package/dist/types/src/lobby/react.d.ts +113 -0
  116. package/dist/types/src/lobby/react.ssr.test.d.ts +4 -0
  117. package/dist/types/src/lobby/react.test.d.ts +1 -0
  118. package/dist/types/src/master/filter-player-view.d.ts +96 -0
  119. package/dist/types/src/master/filter-player-view.test.d.ts +1 -0
  120. package/dist/types/src/master/master.d.ts +94 -0
  121. package/dist/types/src/master/master.test.d.ts +1 -0
  122. package/dist/types/src/plugins/events/events.d.ts +54 -0
  123. package/dist/types/src/plugins/events/events.test.d.ts +1 -0
  124. package/dist/types/src/plugins/main.d.ts +75 -0
  125. package/dist/types/src/plugins/main.test.d.ts +1 -0
  126. package/dist/types/src/plugins/plugin-events.d.ts +5 -0
  127. package/dist/types/src/plugins/plugin-immer.d.ts +7 -0
  128. package/dist/types/src/plugins/plugin-immer.test.d.ts +1 -0
  129. package/dist/types/src/plugins/plugin-log.d.ts +14 -0
  130. package/dist/types/src/plugins/plugin-log.test.d.ts +1 -0
  131. package/dist/types/src/plugins/plugin-player.d.ts +29 -0
  132. package/dist/types/src/plugins/plugin-player.test.d.ts +1 -0
  133. package/dist/types/src/plugins/plugin-random.d.ts +4 -0
  134. package/dist/types/src/plugins/plugin-serializable.d.ts +7 -0
  135. package/dist/types/src/plugins/plugin-serializable.test.d.ts +1 -0
  136. package/dist/types/src/plugins/random/random.alea.d.ts +19 -0
  137. package/dist/types/src/plugins/random/random.d.ts +54 -0
  138. package/dist/types/src/plugins/random/random.test.d.ts +1 -0
  139. package/dist/types/src/server/api.d.ts +13 -0
  140. package/dist/types/src/server/api.test.d.ts +1 -0
  141. package/dist/types/src/server/auth.d.ts +38 -0
  142. package/dist/types/src/server/auth.test.d.ts +1 -0
  143. package/dist/types/src/server/cors.d.ts +4 -0
  144. package/dist/types/src/server/cors.test.d.ts +1 -0
  145. package/dist/types/src/server/db/base.d.ts +192 -0
  146. package/dist/types/src/server/db/flatfile.d.ts +44 -0
  147. package/dist/types/src/server/db/flatfile.test.d.ts +1 -0
  148. package/dist/types/src/server/db/index.d.ts +4 -0
  149. package/dist/types/src/server/db/index.test.d.ts +1 -0
  150. package/dist/types/src/server/db/inmemory.d.ts +43 -0
  151. package/dist/types/src/server/db/inmemory.test.d.ts +1 -0
  152. package/dist/types/src/server/db/localstorage.d.ts +7 -0
  153. package/dist/types/src/server/db/localstorage.test.d.ts +1 -0
  154. package/dist/types/src/server/index.d.ts +68 -0
  155. package/dist/types/src/server/index.test.d.ts +1 -0
  156. package/dist/types/src/server/transport/pubsub/generic-pub-sub.d.ts +6 -0
  157. package/dist/types/src/server/transport/pubsub/in-memory-pub-sub.d.ts +7 -0
  158. package/dist/types/src/server/transport/pubsub/in-memory-pub-sub.test.d.ts +1 -0
  159. package/dist/types/src/server/transport/socketio-simultaneous.test.d.ts +1 -0
  160. package/dist/types/src/server/transport/socketio.d.ts +65 -0
  161. package/dist/types/src/server/transport/socketio.test.d.ts +1 -0
  162. package/dist/types/src/server/util.d.ts +35 -0
  163. package/dist/types/src/testing/mock-random.d.ts +15 -0
  164. package/dist/types/src/testing/mock-random.test.d.ts +1 -0
  165. package/dist/types/src/types.d.ts +387 -0
  166. package/internal/package.json +7 -0
  167. package/master/package.json +7 -0
  168. package/multiplayer/package.json +7 -0
  169. package/package.json +211 -0
  170. package/plugins/package.json +7 -0
  171. package/react/package.json +7 -0
  172. package/react-native/package.json +7 -0
  173. package/server/package.json +6 -0
  174. package/src/ai/ai.test.ts +433 -0
  175. package/src/ai/ai.ts +84 -0
  176. package/src/ai/bot.ts +122 -0
  177. package/src/ai/mcts-bot.ts +331 -0
  178. package/src/ai/random-bot.ts +20 -0
  179. package/src/client/client.test.ts +993 -0
  180. package/src/client/client.ts +588 -0
  181. package/src/client/debug/Debug.svelte +239 -0
  182. package/src/client/debug/Menu.svelte +65 -0
  183. package/src/client/debug/ai/AI.svelte +215 -0
  184. package/src/client/debug/ai/Options.svelte +48 -0
  185. package/src/client/debug/info/Info.svelte +22 -0
  186. package/src/client/debug/info/Item.svelte +24 -0
  187. package/src/client/debug/log/Log.svelte +157 -0
  188. package/src/client/debug/log/LogEvent.svelte +149 -0
  189. package/src/client/debug/log/LogMetadata.svelte +7 -0
  190. package/src/client/debug/log/PhaseMarker.svelte +27 -0
  191. package/src/client/debug/log/TurnMarker.svelte +23 -0
  192. package/src/client/debug/main/ClientSwitcher.svelte +59 -0
  193. package/src/client/debug/main/Controls.svelte +58 -0
  194. package/src/client/debug/main/Hotkey.svelte +84 -0
  195. package/src/client/debug/main/InteractiveFunction.svelte +85 -0
  196. package/src/client/debug/main/Main.svelte +121 -0
  197. package/src/client/debug/main/Move.svelte +68 -0
  198. package/src/client/debug/main/PlayerInfo.svelte +70 -0
  199. package/src/client/debug/mcts/Action.svelte +22 -0
  200. package/src/client/debug/mcts/MCTS.svelte +78 -0
  201. package/src/client/debug/mcts/Table.svelte +98 -0
  202. package/src/client/debug/tests/JSONTree.mock.svelte +3 -0
  203. package/src/client/debug/tests/debug.test.ts +183 -0
  204. package/src/client/debug/utils/shortcuts.js +50 -0
  205. package/src/client/debug/utils/shortcuts.test.js +49 -0
  206. package/src/client/manager.ts +177 -0
  207. package/src/client/react-native.js +136 -0
  208. package/src/client/react-native.test.js +229 -0
  209. package/src/client/react.ssr.test.tsx +24 -0
  210. package/src/client/react.test.tsx +213 -0
  211. package/src/client/react.tsx +192 -0
  212. package/src/client/transport/dummy.ts +19 -0
  213. package/src/client/transport/local.test.ts +353 -0
  214. package/src/client/transport/local.ts +230 -0
  215. package/src/client/transport/socketio.test.ts +328 -0
  216. package/src/client/transport/socketio.ts +210 -0
  217. package/src/client/transport/transport.test.ts +27 -0
  218. package/src/client/transport/transport.ts +95 -0
  219. package/src/core/action-creators.ts +159 -0
  220. package/src/core/action-types.ts +18 -0
  221. package/src/core/backwards-compatibility.ts +23 -0
  222. package/src/core/constants.ts +6 -0
  223. package/src/core/errors.ts +35 -0
  224. package/src/core/flow.test.ts +2433 -0
  225. package/src/core/flow.ts +897 -0
  226. package/src/core/game-methods.ts +9 -0
  227. package/src/core/game.test.ts +286 -0
  228. package/src/core/game.ts +114 -0
  229. package/src/core/initialize.ts +77 -0
  230. package/src/core/logger.test.js +90 -0
  231. package/src/core/logger.ts +18 -0
  232. package/src/core/player-view.test.ts +50 -0
  233. package/src/core/player-view.ts +39 -0
  234. package/src/core/reducer.test.ts +991 -0
  235. package/src/core/reducer.ts +532 -0
  236. package/src/core/turn-order.test.ts +1123 -0
  237. package/src/core/turn-order.ts +473 -0
  238. package/src/lobby/client.test.ts +385 -0
  239. package/src/lobby/client.ts +358 -0
  240. package/src/lobby/connection.test.ts +207 -0
  241. package/src/lobby/connection.ts +162 -0
  242. package/src/lobby/create-match-form.tsx +122 -0
  243. package/src/lobby/login-form.tsx +75 -0
  244. package/src/lobby/match-instance.tsx +135 -0
  245. package/src/lobby/react.ssr.test.tsx +22 -0
  246. package/src/lobby/react.test.tsx +594 -0
  247. package/src/lobby/react.tsx +402 -0
  248. package/src/master/filter-player-view.test.ts +381 -0
  249. package/src/master/filter-player-view.ts +102 -0
  250. package/src/master/master.test.ts +1068 -0
  251. package/src/master/master.ts +492 -0
  252. package/src/plugins/events/events.test.ts +108 -0
  253. package/src/plugins/events/events.ts +209 -0
  254. package/src/plugins/main.test.ts +411 -0
  255. package/src/plugins/main.ts +314 -0
  256. package/src/plugins/plugin-events.ts +40 -0
  257. package/src/plugins/plugin-immer.test.ts +86 -0
  258. package/src/plugins/plugin-immer.ts +37 -0
  259. package/src/plugins/plugin-log.test.ts +37 -0
  260. package/src/plugins/plugin-log.ts +40 -0
  261. package/src/plugins/plugin-player.test.ts +172 -0
  262. package/src/plugins/plugin-player.ts +100 -0
  263. package/src/plugins/plugin-random.ts +40 -0
  264. package/src/plugins/plugin-serializable.test.ts +40 -0
  265. package/src/plugins/plugin-serializable.ts +55 -0
  266. package/src/plugins/random/random.alea.ts +109 -0
  267. package/src/plugins/random/random.test.ts +167 -0
  268. package/src/plugins/random/random.ts +198 -0
  269. package/src/server/api.test.ts +1699 -0
  270. package/src/server/api.ts +527 -0
  271. package/src/server/auth.test.ts +275 -0
  272. package/src/server/auth.ts +89 -0
  273. package/src/server/cors.test.ts +121 -0
  274. package/src/server/cors.ts +7 -0
  275. package/src/server/db/base.ts +296 -0
  276. package/src/server/db/flatfile.test.ts +221 -0
  277. package/src/server/db/flatfile.ts +228 -0
  278. package/src/server/db/index.test.ts +8 -0
  279. package/src/server/db/index.ts +12 -0
  280. package/src/server/db/inmemory.test.ts +143 -0
  281. package/src/server/db/inmemory.ts +143 -0
  282. package/src/server/db/localstorage.test.ts +73 -0
  283. package/src/server/db/localstorage.ts +44 -0
  284. package/src/server/index.test.ts +265 -0
  285. package/src/server/index.ts +175 -0
  286. package/src/server/transport/pubsub/generic-pub-sub.ts +11 -0
  287. package/src/server/transport/pubsub/in-memory-pub-sub.test.ts +47 -0
  288. package/src/server/transport/pubsub/in-memory-pub-sub.ts +28 -0
  289. package/src/server/transport/socketio-simultaneous.test.ts +603 -0
  290. package/src/server/transport/socketio.test.ts +303 -0
  291. package/src/server/transport/socketio.ts +279 -0
  292. package/src/server/util.ts +85 -0
  293. package/src/testing/mock-random.test.ts +45 -0
  294. package/src/testing/mock-random.ts +27 -0
  295. package/src/types.ts +511 -0
  296. package/testing/package.json +7 -0
@@ -0,0 +1,96 @@
1
+ import type { Game, LogEntry, PlayerID } from '../types';
2
+ import type { TransportData, IntermediateTransportData } from './master';
3
+ /** Gets a function that filters the TransportData for a given player and game. */
4
+ export declare const getFilterPlayerView: (game: Game) => (playerID: string | null, payload: IntermediateTransportData) => TransportData;
5
+ /**
6
+ * Redact the log.
7
+ *
8
+ * @param {Array} log - The game log (or deltalog).
9
+ * @param {String} playerID - The playerID that this log is
10
+ * to be sent to.
11
+ */
12
+ export declare function redactLog(log: LogEntry[], playerID: PlayerID | null): {
13
+ action: {
14
+ payload: {
15
+ args: any;
16
+ type: string;
17
+ playerID: string;
18
+ } | {
19
+ args: any;
20
+ type: string;
21
+ playerID: string;
22
+ } | {
23
+ args: any;
24
+ type: any;
25
+ playerID: string;
26
+ } | {
27
+ args: any;
28
+ type: any;
29
+ playerID: string;
30
+ };
31
+ type: "MAKE_MOVE";
32
+ } | {
33
+ payload: {
34
+ args: any;
35
+ type: string;
36
+ playerID: string;
37
+ } | {
38
+ args: any;
39
+ type: string;
40
+ playerID: string;
41
+ } | {
42
+ args: any;
43
+ type: any;
44
+ playerID: string;
45
+ } | {
46
+ args: any;
47
+ type: any;
48
+ playerID: string;
49
+ };
50
+ type: "GAME_EVENT";
51
+ } | {
52
+ payload: {
53
+ args: any;
54
+ type: string;
55
+ playerID: string;
56
+ } | {
57
+ args: any;
58
+ type: string;
59
+ playerID: string;
60
+ } | {
61
+ args: any;
62
+ type: any;
63
+ playerID: string;
64
+ } | {
65
+ args: any;
66
+ type: any;
67
+ playerID: string;
68
+ };
69
+ type: "UNDO";
70
+ } | {
71
+ payload: {
72
+ args: any;
73
+ type: string;
74
+ playerID: string;
75
+ } | {
76
+ args: any;
77
+ type: string;
78
+ playerID: string;
79
+ } | {
80
+ args: any;
81
+ type: any;
82
+ playerID: string;
83
+ } | {
84
+ args: any;
85
+ type: any;
86
+ playerID: string;
87
+ };
88
+ type: "REDO";
89
+ };
90
+ _stateID: number;
91
+ turn: number;
92
+ phase: string;
93
+ automatic?: boolean;
94
+ metadata?: any;
95
+ patch?: import("rfc6902").Operation[];
96
+ }[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,94 @@
1
+ import { ProcessGameConfig } from '../core/game';
2
+ import type { SyncInfo, FilteredMetadata, Game, State, ActionShape, CredentialedActionShape, LogEntry, PlayerID, ChatMessage } from '../types';
3
+ import type { Auth } from '../server/auth';
4
+ import * as StorageAPI from '../server/db/base';
5
+ import type { Operation } from 'rfc6902';
6
+ declare type CallbackFn = (arg: {
7
+ state: State;
8
+ matchID: string;
9
+ action?: ActionShape.Any | CredentialedActionShape.Any;
10
+ }) => void;
11
+ /**
12
+ * Data types that are shared across `TransportData` and `IntermediateTransportData`.
13
+ */
14
+ declare type CommonTransportData = {
15
+ type: 'sync';
16
+ args: [string, SyncInfo];
17
+ } | {
18
+ type: 'matchData';
19
+ args: [string, FilteredMetadata];
20
+ } | {
21
+ type: 'chat';
22
+ args: [string, ChatMessage];
23
+ };
24
+ /**
25
+ * Final shape of data sent by the transport API
26
+ * to be received by clients/client transports.
27
+ */
28
+ export declare type TransportData = {
29
+ type: 'update';
30
+ args: [string, State, LogEntry[]];
31
+ } | {
32
+ type: 'patch';
33
+ args: [string, number, number, Operation[], LogEntry[]];
34
+ } | CommonTransportData;
35
+ /**
36
+ * Data type sent by a master to its transport API. The transport then transforms
37
+ * this into `TransportData` for each individual player it forwards it to.
38
+ */
39
+ export declare type IntermediateTransportData = {
40
+ type: 'update';
41
+ args: [string, State];
42
+ } | {
43
+ type: 'patch';
44
+ args: [string, number, State, State];
45
+ } | CommonTransportData;
46
+ /** API used by a master to emit data to any connected clients/client transports. */
47
+ export interface TransportAPI {
48
+ send: (playerData: {
49
+ playerID: PlayerID;
50
+ } & IntermediateTransportData) => void;
51
+ sendAll: (payload: IntermediateTransportData) => void;
52
+ }
53
+ /**
54
+ * Master
55
+ *
56
+ * Class that runs the game and maintains the authoritative state.
57
+ * It uses the transportAPI to communicate with clients and the
58
+ * storageAPI to communicate with the database.
59
+ */
60
+ export declare class Master {
61
+ game: ReturnType<typeof ProcessGameConfig>;
62
+ storageAPI: StorageAPI.Sync | StorageAPI.Async;
63
+ transportAPI: TransportAPI;
64
+ subscribeCallback: CallbackFn;
65
+ auth?: Auth;
66
+ constructor(game: Game, storageAPI: StorageAPI.Sync | StorageAPI.Async, transportAPI: TransportAPI, auth?: Auth);
67
+ subscribe(fn: CallbackFn): void;
68
+ /**
69
+ * Called on each move / event made by the client.
70
+ * Computes the new value of the game state and returns it
71
+ * along with a deltalog.
72
+ */
73
+ onUpdate(credAction: CredentialedActionShape.Any, stateID: number, matchID: string, playerID: string): Promise<void | {
74
+ error: string;
75
+ }>;
76
+ /**
77
+ * Called when the client connects / reconnects.
78
+ * Returns the latest game state and the entire log.
79
+ */
80
+ onSync(matchID: string, playerID: string | null | undefined, credentials?: string, numPlayers?: number): Promise<void | {
81
+ error: string;
82
+ }>;
83
+ /**
84
+ * Called when a client connects or disconnects.
85
+ * Updates and sends out metadata to reflect the player’s connection status.
86
+ */
87
+ onConnectionChange(matchID: string, playerID: string | null | undefined, credentials: string | undefined, connected: boolean): Promise<void | {
88
+ error: string;
89
+ }>;
90
+ onChatMessage(matchID: string, chatMessage: ChatMessage, credentials: string | undefined): Promise<void | {
91
+ error: string;
92
+ }>;
93
+ }
94
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,54 @@
1
+ import type { State, Ctx, PlayerID, Game, ActivePlayersArg } from '../../types';
2
+ import { GameMethod } from '../../core/game-methods';
3
+ export interface EventsAPI {
4
+ endGame(gameover?: any): void;
5
+ endPhase(): void;
6
+ endStage(): void;
7
+ endTurn(arg?: {
8
+ next: PlayerID;
9
+ }): void;
10
+ pass(arg?: {
11
+ remove: true;
12
+ }): void;
13
+ setActivePlayers(arg: ActivePlayersArg): void;
14
+ setPhase(newPhase: string): void;
15
+ setStage(newStage: string): void;
16
+ }
17
+ export interface PrivateEventsAPI {
18
+ _private: {
19
+ isUsed(): boolean;
20
+ updateTurnContext(ctx: Ctx, methodType: GameMethod | undefined): void;
21
+ unsetCurrentMethod(): void;
22
+ update(state: State): State;
23
+ };
24
+ }
25
+ /**
26
+ * Events
27
+ */
28
+ export declare class Events {
29
+ flow: Game['flow'];
30
+ playerID: PlayerID | undefined;
31
+ dispatch: Array<{
32
+ type: string;
33
+ args: any[];
34
+ phase: string;
35
+ turn: number;
36
+ calledFrom: GameMethod | undefined;
37
+ error: Error;
38
+ }>;
39
+ maxEndedTurnsPerAction: number;
40
+ initialTurn: number;
41
+ currentPhase: string;
42
+ currentTurn: number;
43
+ currentMethod?: GameMethod;
44
+ constructor(flow: Game['flow'], ctx: Ctx, playerID?: PlayerID);
45
+ api(): EventsAPI & PrivateEventsAPI;
46
+ isUsed(): boolean;
47
+ updateTurnContext(ctx: Ctx, methodType: GameMethod | undefined): void;
48
+ unsetCurrentMethod(): void;
49
+ /**
50
+ * Updates ctx with the triggered events.
51
+ * @param {object} state - The state object { G, ctx }.
52
+ */
53
+ update(state: State): State;
54
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
1
+ import type { AnyFn, DefaultPluginAPIs, PartialGameState, State, Game, Plugin, ActionShape, PlayerID } from '../types';
2
+ import type { GameMethod } from '../core/game-methods';
3
+ interface PluginOpts {
4
+ game: Game;
5
+ isClient?: boolean;
6
+ }
7
+ /**
8
+ * Allow plugins to intercept actions and process them.
9
+ */
10
+ export declare const ProcessAction: (state: State, action: ActionShape.Plugin, opts: PluginOpts) => State;
11
+ /**
12
+ * The APIs created by various plugins are stored in the plugins
13
+ * section of the state object:
14
+ *
15
+ * {
16
+ * G: {},
17
+ * ctx: {},
18
+ * plugins: {
19
+ * plugin-a: {
20
+ * data: {}, // this is generated by the plugin at Setup / Flush.
21
+ * api: {}, // this is ephemeral and generated by Enhance.
22
+ * }
23
+ * }
24
+ * }
25
+ *
26
+ * This function retrieves plugin APIs and returns them as an object
27
+ * for consumption as used by move contexts.
28
+ */
29
+ export declare const GetAPIs: ({ plugins }: PartialGameState) => DefaultPluginAPIs;
30
+ /**
31
+ * Applies the provided plugins to the given move / flow function.
32
+ *
33
+ * @param methodToWrap - The move function or hook to apply the plugins to.
34
+ * @param methodType - The type of the move or hook being wrapped.
35
+ * @param plugins - The list of plugins.
36
+ */
37
+ export declare const FnWrap: (methodToWrap: AnyFn, methodType: GameMethod, plugins: Plugin[]) => (context: import("../types").FnContext<any, Record<string, unknown>>, ...args: any[]) => any;
38
+ /**
39
+ * Allows the plugin to generate its initial state.
40
+ */
41
+ export declare const Setup: (state: PartialGameState, opts: PluginOpts) => PartialGameState;
42
+ /**
43
+ * Invokes the plugin before a move or event.
44
+ * The API that the plugin generates is stored inside
45
+ * the `plugins` section of the state (which is subsequently
46
+ * merged into ctx).
47
+ */
48
+ export declare const Enhance: <S extends State<any> | Pick<State<any>, "G" | "ctx" | "plugins">>(state: S, opts: PluginOpts & {
49
+ playerID: PlayerID;
50
+ }) => S;
51
+ /**
52
+ * Allows plugins to indicate if they should not be materialized on the client.
53
+ * This will cause the client to discard the state update and wait for the
54
+ * master instead.
55
+ */
56
+ export declare const NoClient: (state: State, opts: PluginOpts) => boolean;
57
+ /**
58
+ * Update plugin state after move/event & check if plugins consider the update to be valid.
59
+ * @returns Tuple of `[updatedState]` or `[originalState, invalidError]`.
60
+ */
61
+ export declare const FlushAndValidate: (state: State, opts: PluginOpts) => readonly [State<any>] | readonly [State<any>, {
62
+ plugin: string;
63
+ message: string;
64
+ }];
65
+ /**
66
+ * Allows plugins to customize their data for specific players.
67
+ * For example, a plugin may want to share no data with the client, or
68
+ * want to keep some player data secret from opponents.
69
+ */
70
+ export declare const PlayerView: ({ G, ctx, plugins }: State, { game, playerID }: PluginOpts & {
71
+ playerID: PlayerID;
72
+ }) => {
73
+ [pluginName: string]: import("../types").PluginState;
74
+ };
75
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from '../types';
2
+ import type { PrivateEventsAPI, EventsAPI } from './events/events';
3
+ export type { EventsAPI };
4
+ declare const EventsPlugin: Plugin<EventsAPI & PrivateEventsAPI>;
5
+ export default EventsPlugin;
@@ -0,0 +1,7 @@
1
+ import type { Plugin } from '../types';
2
+ /**
3
+ * Plugin that allows using Immer to make immutable changes
4
+ * to G by just mutating it.
5
+ */
6
+ declare const ImmerPlugin: Plugin;
7
+ export default ImmerPlugin;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { Plugin } from '../types';
2
+ interface LogData {
3
+ metadata?: any;
4
+ }
5
+ export interface LogAPI {
6
+ setMetadata(metadata: any): void;
7
+ }
8
+ /**
9
+ * Plugin that makes it possible to add metadata to log entries.
10
+ * During a move, you can set metadata using ctx.log.setMetadata and it will be
11
+ * available on the log entry for that move.
12
+ */
13
+ declare const LogPlugin: Plugin<LogAPI, LogData>;
14
+ export default LogPlugin;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { Plugin, PlayerID } from '../types';
2
+ interface PlayerData<PlayerState extends any = any> {
3
+ players: Record<PlayerID, PlayerState>;
4
+ }
5
+ export interface PlayerAPI<PlayerState extends any = any> {
6
+ state: Record<PlayerID, PlayerState>;
7
+ get(): PlayerState;
8
+ set(value: PlayerState): PlayerState;
9
+ opponent?: {
10
+ get(): PlayerState;
11
+ set(value: PlayerState): PlayerState;
12
+ };
13
+ }
14
+ interface PluginPlayerOpts<PlayerState extends any = any> {
15
+ setup?: (playerID: string) => PlayerState;
16
+ playerView?: (players: Record<PlayerID, PlayerState>, playerID?: string | null) => any;
17
+ }
18
+ export interface PlayerPlugin<PlayerState extends any = any> {
19
+ player: PlayerAPI<PlayerState>;
20
+ }
21
+ /**
22
+ * Plugin that maintains state for each player in G.players.
23
+ * During a turn, G.player will contain the object for the current player.
24
+ * In two player games, G.opponent will contain the object for the other player.
25
+ *
26
+ * @param {function} initPlayerState - Function of type (playerID) => playerState.
27
+ */
28
+ declare const PlayerPlugin: <PlayerState extends unknown = any>({ setup, playerView, }?: PluginPlayerOpts<PlayerState>) => Plugin<PlayerAPI<PlayerState>, PlayerData<PlayerState>, any>;
29
+ export default PlayerPlugin;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from '../types';
2
+ import type { RandomAPI, PrivateRandomAPI, RandomState } from './random/random';
3
+ declare const RandomPlugin: Plugin<RandomAPI & PrivateRandomAPI, RandomState>;
4
+ export default RandomPlugin;
@@ -0,0 +1,7 @@
1
+ import type { Plugin } from '../types';
2
+ /**
3
+ * Plugin that checks whether state is serializable, in order to avoid
4
+ * network serialization bugs.
5
+ */
6
+ declare const SerializablePlugin: Plugin;
7
+ export default SerializablePlugin;
@@ -0,0 +1,19 @@
1
+ export interface AleaState {
2
+ c: number;
3
+ s0: number;
4
+ s1: number;
5
+ s2: number;
6
+ }
7
+ declare class Alea {
8
+ c: number;
9
+ s0: number;
10
+ s1: number;
11
+ s2: number;
12
+ constructor(seed: string | number);
13
+ next(): number;
14
+ }
15
+ declare type PRNG = Alea['next'] & {
16
+ state?: () => AleaState;
17
+ };
18
+ export declare function alea(seed: string | number, state?: AleaState): PRNG;
19
+ export {};
@@ -0,0 +1,54 @@
1
+ import type { AleaState } from './random.alea';
2
+ export interface RandomState {
3
+ seed: string | number;
4
+ prngstate?: AleaState;
5
+ }
6
+ export interface RandomAPI {
7
+ D4(): number;
8
+ D4(diceCount: number): number[];
9
+ D6(): number;
10
+ D6(diceCount: number): number[];
11
+ D10(): number;
12
+ D10(diceCount: number): number[];
13
+ D12(): number;
14
+ D12(diceCount: number): number[];
15
+ D20(): number;
16
+ D20(diceCount: number): number[];
17
+ Die(spotvalue?: number): number;
18
+ Die(spotvalue: number, diceCount: number): number[];
19
+ Number(): number;
20
+ Shuffle<T>(deck: T[]): T[];
21
+ }
22
+ export interface PrivateRandomAPI {
23
+ _private: {
24
+ isUsed(): boolean;
25
+ getState(): RandomState;
26
+ };
27
+ }
28
+ /**
29
+ * Random
30
+ *
31
+ * Calls that require a pseudorandom number generator.
32
+ * Uses a seed from ctx, and also persists the PRNG
33
+ * state in ctx so that moves can stay pure.
34
+ */
35
+ export declare class Random {
36
+ state: RandomState;
37
+ used: boolean;
38
+ /**
39
+ * Generates a new seed from the current date / time.
40
+ */
41
+ static seed(): string;
42
+ /**
43
+ * constructor
44
+ * @param {object} ctx - The ctx object to initialize from.
45
+ */
46
+ constructor(state?: RandomState);
47
+ isUsed(): boolean;
48
+ getState(): RandomState;
49
+ /**
50
+ * Generate a random number.
51
+ */
52
+ _random(): number;
53
+ api(): RandomAPI & PrivateRandomAPI;
54
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ /// <reference types="koa__router" />
2
+ import type { CorsOptions } from 'cors';
3
+ import type Router from '@koa/router';
4
+ import type { Auth } from './auth';
5
+ import type { Server, Game, StorageAPI } from '../types';
6
+ export declare const configureRouter: ({ router, db, auth, games, uuid, }: {
7
+ router: Router<any, Server.AppCtx>;
8
+ auth: Auth;
9
+ games: Game[];
10
+ uuid?: () => string;
11
+ db: StorageAPI.Sync | StorageAPI.Async;
12
+ }) => Router<any, Server.AppCtx>;
13
+ export declare const configureApp: (app: Server.App, router: Router<any, Server.AppCtx>, origins: CorsOptions['origin']) => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,38 @@
1
+ import type { Server, PlayerID } from '../types';
2
+ /**
3
+ * Verifies that a match has metadata and is using credentials.
4
+ */
5
+ export declare const doesMatchRequireAuthentication: (matchData?: Server.MatchData) => boolean;
6
+ /**
7
+ * The default `authenticateCredentials` method.
8
+ * Verifies that the provided credentials match the player’s metadata.
9
+ */
10
+ export declare const areCredentialsAuthentic: Server.AuthenticateCredentials;
11
+ /**
12
+ * Extracts a player’s metadata from the match data object.
13
+ */
14
+ export declare const extractPlayerMetadata: (matchData: Server.MatchData, playerID: PlayerID) => Server.PlayerMetadata;
15
+ /**
16
+ * Class that provides authentication methods to the lobby server & transport.
17
+ */
18
+ export declare class Auth {
19
+ private readonly shouldAuthenticate;
20
+ private readonly authenticate;
21
+ /**
22
+ * Generate credentials string from the Koa context.
23
+ */
24
+ readonly generateCredentials: Server.GenerateCredentials;
25
+ constructor(opts?: {
26
+ authenticateCredentials?: Server.AuthenticateCredentials;
27
+ generateCredentials?: Server.GenerateCredentials;
28
+ });
29
+ /**
30
+ * Resolves to true if the provided credentials are valid for the given
31
+ * metadata and player IDs, or if the match does not require authentication.
32
+ */
33
+ authenticateCredentials({ playerID, credentials, metadata, }: {
34
+ playerID: string;
35
+ credentials: string | undefined;
36
+ metadata: Server.MatchData;
37
+ }): boolean | Promise<boolean>;
38
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare const Origins: {
2
+ LOCALHOST: RegExp;
3
+ LOCALHOST_IN_DEVELOPMENT: boolean | RegExp;
4
+ };
@@ -0,0 +1 @@
1
+ export {};