Skip to content

Commit

Permalink
remove namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolodavis committed Mar 18, 2020
1 parent 7b70cab commit 8c80785
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/master/master.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from './master';
import { error } from '../core/logger';
import { Server } from '../types';
import { StorageAPI } from '../server/db/base';
import * as StorageAPI from '../server/db/base';

jest.mock('../core/logger', () => ({
info: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion src/master/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
LogEntry,
PlayerID,
} from '../types';
import { StorageAPI } from '../server/db/base';
import * as StorageAPI from '../server/db/base';

export const getPlayerMetadata = (
gameMetadata: Server.GameMetadata,
Expand Down
2 changes: 1 addition & 1 deletion src/server/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import request from 'supertest';

import { addApiToServer, createApiServer } from './api';
import { Game } from '../core/game';
import { StorageAPI } from './db/base';
import * as StorageAPI from './db/base';

jest.setTimeout(2000000000);

Expand Down
2 changes: 1 addition & 1 deletion src/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const uuid = require('shortid').generate;
const cors = require('@koa/cors');

import { InitializeGame } from '../core/initialize';
import { StorageAPI } from './db/base';
import * as StorageAPI from './db/base';

const getNamespacedGameID = (gameID: string, gameName: string) =>
`${gameName}:${gameID}`;
Expand Down
196 changes: 97 additions & 99 deletions src/server/db/base.ts
Original file line number Diff line number Diff line change
@@ -1,107 +1,105 @@
import { State, Server } from '../../types';

export namespace StorageAPI {
export enum Type {
SYNC = 0,
ASYNC = 1,
}
export enum Type {
SYNC = 0,
ASYNC = 1,
}

export abstract class Async {
export abstract class Async {
/* istanbul ignore next */
type() {
/* istanbul ignore next */
type() {
/* istanbul ignore next */
return Type.ASYNC;
}

/**
* Connect.
*/
abstract connect();

/**
* Update the game state.
*/
abstract setState(gameID: string, state: State): Promise<void>;

/**
* Read the latest game state.
*/
abstract getState(gameID: string): Promise<State>;

/**
* Check if a particular game id exists.
*/
abstract has(gameID: string): Promise<boolean>;

/**
* Update the game metadata.
*/
abstract setMetadata(
gameID: string,
metadata: Server.GameMetadata
): Promise<void>;

/**
* Fetch the game metadata.
*/
abstract getMetadata(gameID: string): Promise<Server.GameMetadata>;

/**
* Remove the game state.
*/
abstract remove(gameID: string): Promise<void>;

/**
* Return all games.
*/
abstract list(): Promise<string[]>;
return Type.ASYNC;
}

export abstract class Sync {
type() {
return Type.SYNC;
}

/**
* Connect.
*/
connect() {
return;
}

/**
* Update the game state.
*/
abstract setState(gameID: string, state: State): void;

/**
* Read the latest game state.
*/
abstract getState(gameID: string): State;

/**
* Check if a particular game id exists.
*/
abstract has(gameID: string): boolean;

/**
* Update the game metadata.
*/
abstract setMetadata(gameID: string, metadata: Server.GameMetadata): void;

/**
* Fetch the game metadata.
*/
abstract getMetadata(gameID: string): Server.GameMetadata;

/**
* Remove the game state.
*/
abstract remove(gameID: string): void;

/**
* Return all games.
*/
abstract list(): Array<string>;
/**
* Connect.
*/
abstract connect();

/**
* Update the game state.
*/
abstract setState(gameID: string, state: State): Promise<void>;

/**
* Read the latest game state.
*/
abstract getState(gameID: string): Promise<State>;

/**
* Check if a particular game id exists.
*/
abstract has(gameID: string): Promise<boolean>;

/**
* Update the game metadata.
*/
abstract setMetadata(
gameID: string,
metadata: Server.GameMetadata
): Promise<void>;

/**
* Fetch the game metadata.
*/
abstract getMetadata(gameID: string): Promise<Server.GameMetadata>;

/**
* Remove the game state.
*/
abstract remove(gameID: string): Promise<void>;

/**
* Return all games.
*/
abstract list(): Promise<string[]>;
}

export abstract class Sync {
type() {
return Type.SYNC;
}

/**
* Connect.
*/
connect() {
return;
}

/**
* Update the game state.
*/
abstract setState(gameID: string, state: State): void;

/**
* Read the latest game state.
*/
abstract getState(gameID: string): State;

/**
* Check if a particular game id exists.
*/
abstract has(gameID: string): boolean;

/**
* Update the game metadata.
*/
abstract setMetadata(gameID: string, metadata: Server.GameMetadata): void;

/**
* Fetch the game metadata.
*/
abstract getMetadata(gameID: string): Server.GameMetadata;

/**
* Remove the game state.
*/
abstract remove(gameID: string): void;

/**
* Return all games.
*/
abstract list(): Array<string>;
}
2 changes: 1 addition & 1 deletion src/server/db/flatfile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StorageAPI } from './base';
import * as StorageAPI from './base';
import { State, Server } from '../../types';

/*
Expand Down
2 changes: 1 addition & 1 deletion src/server/db/inmemory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { State, Server } from '../../types';
import { StorageAPI } from './base';
import * as StorageAPI from './base';

/*
* Copyright 2017 The boardgame.io Authors
Expand Down

0 comments on commit 8c80785

Please sign in to comment.