Skip to content

Commit

Permalink
Convert more files to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost91- committed Aug 25, 2023
1 parent af03395 commit 98c164f
Show file tree
Hide file tree
Showing 12 changed files with 622 additions and 391 deletions.
19 changes: 19 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"@types/react-router-dom": "^5.3.3",
"@types/seedrandom": "^3.0.5",
"@types/superagent": "^4.1.15",
"@types/supertest": "^2.0.12",
"@types/uuid": "^9.0.2",
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.5.0",
Expand Down
3 changes: 1 addition & 2 deletions src/game/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {
Suit,
} from '../../utils/cardDefinitions';
import type { Card } from 'reactstrap';
import type { Ctx, DefaultPluginAPIs, FnContext } from 'boardgame.io';
import type { GameState } from '../gameState';
import type { Ctx, DefaultPluginAPIs } from 'boardgame.io';

type DefaultContext = DefaultPluginAPIs & { ctx: Ctx };

Expand Down
7 changes: 5 additions & 2 deletions src/server/ModelFlatFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import type {
FetchFields,
FetchOpts,
} from 'boardgame.io/dist/types/src/server/db/base';
import type { ThreatDragonModel } from '../types/ThreatDragonModel';

interface ModelFetchOpts extends FetchOpts {
model?: boolean;
}

type Model = ThreatDragonModel | { extension: string };

interface ModelFetchFields extends FetchFields {
model: Record<string, unknown>; // TODO: improve
model: Model | null; // TODO: improve
}

type ModelFetchResult<O extends ModelFetchOpts> = Object.Pick<
Expand Down Expand Up @@ -39,7 +42,7 @@ export class ModelFlatFile extends FlatFile {
return result as unknown as ModelFetchResult<O>;
}

async setModel(id: string, model: Record<string, unknown>): Promise<void> {
async setModel(id: string, model: Model | null): Promise<void> {
const key = this.getModelKey(id);
// @ts-expect-error setItem is private, ask boardgame.io to make it protected
return await this.setItem(key, model);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { getDatabase } from '../config';
import { FlatFile } from 'boardgame.io/server';

const env = process.env;

afterEach(() => {
process.env = env;
});

it('returns correct FlatFile database', () => {
process.env = {
DATA_STORE: 'whatever',
};
process.env.DATA_STORE = 'whatever';
const db = getDatabase();
expect(db).toBeInstanceOf(FlatFile);
});
Loading

0 comments on commit 98c164f

Please sign in to comment.