Skip to content

Commit

Permalink
Merge branch 'main' into cristiands7/fix/events-api
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiands7 committed Jul 19, 2021
2 parents 3b9a542 + bfc8a1f commit 33ceea5
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 36 deletions.
6 changes: 6 additions & 0 deletions docs/documentation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### v0.45.2

#### Bugfixes

* [[9753c0e](https://github.com/boardgameio/boardgame.io/commit/9753c0e)] fix: Don’t leak `STRIP_TRANSIENTS` action ([#961](https://github.com/boardgameio/boardgame.io/pull/961))

### v0.45.1

#### Breaking Changes
Expand Down
79 changes: 49 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "boardgame.io",
"version": "0.45.1",
"version": "0.45.2",
"description": "library for turn-based games",
"repository": "https://github.com/boardgameio/boardgame.io",
"scripts": {
Expand Down
15 changes: 14 additions & 1 deletion src/client/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
gameEvent,
patch,
} from '../core/action-creators';
import * as Actions from '../core/action-types';
import Debug from './debug/Debug.svelte';
import { error } from '../core/logger';
import type { LogEntry, State, SyncInfo } from '../types';
Expand Down Expand Up @@ -144,7 +145,7 @@ describe('multiplayer', () => {

beforeAll(() => {
client = Client({
game: { moves: { A: () => {} } },
game: { moves: { A: () => {}, Invalid: () => INVALID_MOVE } },
multiplayer: SocketIO({ server: host + ':' + port }),
});
client.start();
Expand Down Expand Up @@ -173,6 +174,18 @@ describe('multiplayer', () => {
expect(client.transport.onAction).toHaveBeenCalled();
});

test('strip transients action not sent to transport', () => {
jest.spyOn(client.transport, 'onAction');
const state = { G: {}, ctx: { phase: '' }, plugins: {} };
const filteredMetadata = [];
client.store.dispatch(sync({ state, filteredMetadata } as SyncInfo));
client.moves.Invalid();
expect(client.transport.onAction).not.toHaveBeenCalledWith(
expect.any(Object),
{ type: Actions.STRIP_TRANSIENTS }
);
});

test('Sends and receives chat messages', () => {
jest.spyOn(client.transport, 'onAction');
client.updatePlayerID('0');
Expand Down
10 changes: 8 additions & 2 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ type ClientAction =
| ActionShape.Sync
| ActionShape.Update
| ActionShape.Patch;
type Action = CredentialedActionShape.Any | ClientAction;
type Action =
| CredentialedActionShape.Any
| ActionShape.StripTransients
| ClientAction;

export interface DebugOpt {
target?: HTMLElement;
Expand Down Expand Up @@ -287,7 +290,10 @@ export class _ClientImpl<G extends any = any> {
const baseState = store.getState();
const result = next(action);

if (!('clientOnly' in action)) {
if (
!('clientOnly' in action) &&
action.type !== Actions.STRIP_TRANSIENTS
) {
this.transport.onAction(baseState, action);
}

Expand Down
12 changes: 12 additions & 0 deletions src/master/master.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ describe('update', () => {
]);
});

test('missing action', async () => {
const { error } = await master.onUpdate(null, 0, 'matchID', '0');
expect(sendAll).not.toHaveBeenCalled();
expect(error).toBe('missing action or action payload');
});

test('missing action payload', async () => {
const { error } = await master.onUpdate({}, 0, 'matchID', '0');
expect(sendAll).not.toHaveBeenCalled();
expect(error).toBe('missing action or action payload');
});

test('invalid matchID', async () => {
await master.onUpdate(action, 0, 'default:unknown', '1');
expect(sendAll).not.toHaveBeenCalled();
Expand Down
4 changes: 4 additions & 0 deletions src/master/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ export class Master {
matchID: string,
playerID: string
): Promise<void | { error: string }> {
if (!credAction || !credAction.payload) {
return { error: 'missing action or action payload' };
}

let metadata: Server.MatchData | undefined;
if (StorageAPI.isSynchronous(this.storageAPI)) {
({ metadata } = this.storageAPI.fetch(matchID, { metadata: true }));
Expand Down
6 changes: 4 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ export namespace ActionShape {
export type Redo = StripCredentials<CredentialedActionShape.Redo>;
// Private type used only for internal error processing.
// Included here to preserve type-checking of reducer inputs.
type _StripTransients = ReturnType<typeof ActionCreators.stripTransients>;
export type StripTransients = ReturnType<
typeof ActionCreators.stripTransients
>;
export type Any =
| MakeMove
| GameEvent
Expand All @@ -443,7 +445,7 @@ export namespace ActionShape {
| Undo
| Redo
| Plugin
| _StripTransients;
| StripTransients;
}

export namespace ActionPayload {
Expand Down

0 comments on commit 33ceea5

Please sign in to comment.