0.40.0#709
Merged
Merged
Conversation
BREAKING CHANGES: Previously a custom `uuid` function used by the Lobby API to generate game IDs could be passed in the `lobbyConfig` option on `server.run`. This must now be passed directly to the server:
```js
const server = Server({
uuid: () => 'id',
});
```
### All commits
* Expose API router
* refactor(server): Pass uuid directly to Server and createRouter
* docs(server): Move uuid from lobbyConfig on run to Server options
Co-authored-by: delucis <[email protected]>
* fix(api): Expose gameover metadata in rooms endpoints. This adds the `gameover` metadata, if it exists, to both the all rooms and single room query endpoints. Fixes #665. * Refactor game metadata redacting into a function. Co-authored-by: Chris Swithinbank <[email protected]>
Closes #703 * GameMetadata -> MatchMetadata * rooms -> matches * API exposes `matchID`, make Lobby use that instead of `gameID` or `roomID`. * CreateGame -> CreateMatch * gameID, roomID -> matchID * Document Lobby API endpoints. * nextRoomID -> nextMatchID * Update error messages. * gameList -> matchList * Use "match" wherever it makes sense in lobby code. * Replace "room" with "match" in documentation. * Rename 'game' to 'match' in comments and test names. Co-authored-by: Chris Swithinbank <[email protected]> * doesGameRequireAuthentication -> doesMatchRequireAuthentication * Rename gameID to matchID in database interface functions. Co-authored-by: Chris Swithinbank <[email protected]>
* add createdAt, updatedAt to metadata, add listGames filters * case-insensitive boolean parsing * implement inmemory listGames filter
* feat(server): Create types for Lobby API data Closes #707 This creates types for data returned by the Lobby API and uses them to type the response bodies in the server-side router. * refactor(types): Include min and max players options in Game interface * refactor(lobby): Convert connection class to Typescript * feat(lobby): Create a plain JS LobbyClient LobbyClient is a lightweight wrapper around `fetch` calls to a boardgame.io Lobby API server. Apart from the server’s base URL, it is stateless and serves mainly to allow argument validation and to abstract away a few request details. Unlike plain fetch, requests will throw errors if they don’t return `ok` (i.e. status 2xx). * refactor(lobby): Use new LobbyClient class in React lobby connection * fix(lobby): Include missing import for React types * docs(api): Update Lobby docs to convert game to match more thoroughly * docs: Correct inline documentation block * docs: Update Lobby docs - Add examples with the plain JS client - Move the server config details to the Server doc * feat(lobby): Add support for listMatches filtering to client #740 added the ability to pass query string parameters to the listMatches API endpoint to filter the matches returned. This adds support for building the relevant query string to the lobby client’s listMatches method.
Add `createdAt` and `updatedAt` fields to mock match data
Two tests for gameover & updatedAt in match metadata were mislabelled/mixed up a bit. This tidies up the confusion and in the process improves test coverage.
Member
Author
|
@nicolodavis What do you think about merging this now that you’ve released the 0.39.15 patch? I’ve been thinking it may make sense to release 0.40 without the move signature refactor (#662) or other changes we initially planned. There are already enough significant changes here that it may make sense to break that further work into 0.41. Let me know what you think — I’m also happy to take on the move signature refactor when the time comes if you’d like. Edit: As this updates docs too, I guess we shouldn’t merge this without releasing 0.40 shortly after as well. |
13 tasks
* refactor: Rename `gameID` to `matchID` in clients & transports * docs: Update to replace `gameID` with `matchID` * docs: Update example code to use `matchID` instead of `gameID` * refactor: `gameMetadata` → `matchMetadata` in clients & transports * refactor: `matchMetadata` → `matchData` * refactor(types): `MatchMetadata` → `MatchData`
Contributor
|
Sorry, I forgot to |
nicolodavis
previously approved these changes
Sep 1, 2020
nicolodavis
approved these changes
Sep 1, 2020
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
0.40.0
Contents
Breaking Changes
New Features
Breaking Changes
Matches in the Lobby API (Issue #703, PRs #666, #704)
Until now, the Lobby API has been slightly inconsistent in how it names an instance of a game, sometimes describing this as a “game” sometimes as a “room”. In release 0.40.0, this is standardised to “match”, making it clearer that you can play a game, like Chess or Tic-Tac-Toe, and the specific instance of a game is a match.
Changes
If you are using the provided React Lobby component, you shouldn’t see any breaking changes, but if you are consuming the Lobby REST API directly, you need to be aware of the following changes.
In JSON returned by the
games/{name}endpoint:rooms→matchesroomID→matchID{ - "rooms": [ + "matches": [ { - "roomID": "random-string", + "matchID": "random-string", "players": {} } ] }In JSON returned by the
games/{name}/createendpoint:gameID→matchID{ - "gameID": "random-string" + "matchID": "random-string" }In JSON returned by the
games/{name}/{id}endpoint:roomID→matchID{ - "roomID": "random-string", + "matchID": "random-string", "players": {} }In JSON returned by the
games/{name}/{id}/playAgainendpoint:nextRoomID→nextMatchID{ - "nextRoomID": "random-string" + "nextMatchID": "random-string" }If writing Typescript and using the
Servertypes namespace:Server.GameMetadata→Server.MatchDataMigration Help
If you are writing Typescript, you can import types for the data returned by each of the API endpoints so you can know what shape to expect.
Even better, we now provide a plain Javascript Lobby API client. For example, you can can do
client.listMatches('chess')and get a typed JSON response as in the example above. See under “New Features” below for more details.Match IDs & metadata in clients (Issue #763, PR #765)
Reflecting the changes in the Lobby API, there are some minor changes to options and props in clients.
In React clients:
gameID→matchIDimport { Client } from 'boardgame.io/react'; const App = Client({ game }); export default () => ( - <App gameID="xyz" /> + <App matchID="xyz" /> );In plain JS clients:
gameID→matchIDupdateGameID→updateMatchIDgameMetadata→matchDataimport { Client } from 'boardgame.io/client'; const client = Client({ - gameID: 'xyz', + matchID: 'xyz', }); - client.updateGameID('abc'); + client.updateMatchID('abc'); - const metadata = client.gameMetadata; + const metadata = client.matchData;For React board components, the
gameMetadataprop has been renamed:gameMetadata→matchDataPassing a custom
uuidmethod to the Lobby API (PR #698)By default, boardgame.io uses
shortidto generate match IDs and user credentials. Previously this could be customised by passing your ownuuidmethod when running the server. This now has to be done when the server is instantiated, not at run time:const uuid = () => 'id'; const server = Server({ + uuid, }); server.run({ port: 8000, - uuid, });New Features
Timestamp metadata and match filtering in the Lobby API (Issue #735, PR #740)
Match data now contains
createdAtandupdatedAttimestamps.The REST API also supports a query string to filter matches when listing them. Three queries have been added:
isGameover: allows listing only games that have or have not finishedupdatedBefore: allows filtering games last updated before a specific timeupdatedAfter: allows filtering games last updated after a specific timeAn example query URL might look like:
The actual filtering is performed by the storage backend, so if a storage implementation’s
listGamesmethod hasn’t been updated to support this yet, the API will continue to return unfiltered results.Plain JS Lobby Client (PR #728)
The library now provides a lightweight, stateless wrapper around the Fetch API to simplify requests on the client. This is fully typed, so Typescript users should benefit from a better experience and if there are future API changes, these will be easier to refactor for.
Full documentation will be added to the Lobby docs, but here’s a taste:
Expose the server’s API router (PR #698)
You can now access the Koa router instance used for the Lobby API when creating your server: