mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 00:04:48 -07:00
refactor typescript wiring
This commit is contained in:
parent
cea9ae62d8
commit
c62c336a11
286 changed files with 2999 additions and 3053 deletions
|
|
@ -1,11 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_BanFromServer_ext, Command_BanFromServerSchema } from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function banFromServer(minutes: number, userName?: string, address?: string, reason?: string,
|
||||
visibleReason?: string, clientid?: string, removeMessages?: number): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_BanFromServer_ext, create(Command_BanFromServerSchema, {
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_BanFromServer_ext, create(Data.Command_BanFromServerSchema, {
|
||||
minutes, userName, address, reason, visibleReason, clientid, removeMessages
|
||||
}), {
|
||||
onSuccess: () => {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_ForceActivateUser_ext, Command_ForceActivateUserSchema,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function forceActivateUser(usernameToActivate: string, moderatorName: string): void {
|
||||
const cmd = create(Command_ForceActivateUserSchema, { usernameToActivate, moderatorName });
|
||||
webClient.protobuf.sendModeratorCommand(Command_ForceActivateUser_ext, cmd, {
|
||||
const cmd = create(Data.Command_ForceActivateUserSchema, { usernameToActivate, moderatorName });
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_ForceActivateUser_ext, cmd, {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.forceActivateUser(usernameToActivate, moderatorName);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetAdminNotes_ext, Command_GetAdminNotesSchema } from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_GetAdminNotes_ext } from 'generated/proto/response_get_admin_notes_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function getAdminNotes(userName: string): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_GetAdminNotes_ext, create(Command_GetAdminNotesSchema, { userName }), {
|
||||
responseExt: Response_GetAdminNotes_ext,
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_GetAdminNotes_ext, create(Data.Command_GetAdminNotesSchema, { userName }), {
|
||||
responseExt: Data.Response_GetAdminNotes_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.getAdminNotes(userName, response.notes);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetBanHistory_ext, Command_GetBanHistorySchema } from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_BanHistory_ext } from 'generated/proto/response_ban_history_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function getBanHistory(userName: string): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_GetBanHistory_ext, create(Command_GetBanHistorySchema, { userName }), {
|
||||
responseExt: Response_BanHistory_ext,
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_GetBanHistory_ext, create(Data.Command_GetBanHistorySchema, { userName }), {
|
||||
responseExt: Data.Response_BanHistory_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.banHistory(userName, response.banList);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetWarnHistory_ext, Command_GetWarnHistorySchema } from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_WarnHistory_ext } from 'generated/proto/response_warn_history_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function getWarnHistory(userName: string): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_GetWarnHistory_ext, create(Command_GetWarnHistorySchema, { userName }), {
|
||||
responseExt: Response_WarnHistory_ext,
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_GetWarnHistory_ext, create(Data.Command_GetWarnHistorySchema, { userName }), {
|
||||
responseExt: Data.Response_WarnHistory_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.warnHistory(userName, response.warnList);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,14 +1,18 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetWarnList_ext, Command_GetWarnListSchema } from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_WarnList_ext } from 'generated/proto/response_warn_list_pb';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function getWarnList(modName: string, userName: string, userClientid: string): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_GetWarnList_ext, create(Command_GetWarnListSchema, { modName, userName, userClientid }), {
|
||||
responseExt: Response_WarnList_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.warnListOptions([response]);
|
||||
},
|
||||
});
|
||||
webClient.protobuf.sendModeratorCommand(
|
||||
Data.Command_GetWarnList_ext,
|
||||
create(Data.Command_GetWarnListSchema, { modName, userName, userClientid }),
|
||||
{
|
||||
responseExt: Data.Response_WarnList_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.warnListOptions([response]);
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_GrantReplayAccess_ext, Command_GrantReplayAccessSchema,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function grantReplayAccess(replayId: number, moderatorName: string): void {
|
||||
webClient.protobuf.sendModeratorCommand(
|
||||
Command_GrantReplayAccess_ext,
|
||||
create(Command_GrantReplayAccessSchema, { replayId, moderatorName }),
|
||||
Data.Command_GrantReplayAccess_ext,
|
||||
create(Data.Command_GrantReplayAccessSchema, { replayId, moderatorName }),
|
||||
{
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.grantReplayAccess(replayId, moderatorName);
|
||||
|
|
|
|||
|
|
@ -20,24 +20,9 @@ vi.mock('../../persistence', () => ({
|
|||
|
||||
import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
|
||||
import webClient from '../../WebClient';
|
||||
import { Data } from '@app/types';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import {
|
||||
Command_BanFromServer_ext,
|
||||
Command_ForceActivateUser_ext,
|
||||
Command_GetAdminNotes_ext,
|
||||
Command_GetBanHistory_ext,
|
||||
Command_GetWarnHistory_ext,
|
||||
Command_GetWarnList_ext,
|
||||
Command_GrantReplayAccess_ext,
|
||||
Command_UpdateAdminNotes_ext,
|
||||
Command_ViewLogHistory_ext,
|
||||
Command_WarnUser_ext,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
import { Response_GetAdminNotes_ext } from 'generated/proto/response_get_admin_notes_pb';
|
||||
import { Response_BanHistory_ext } from 'generated/proto/response_ban_history_pb';
|
||||
import { Response_WarnHistory_ext } from 'generated/proto/response_warn_history_pb';
|
||||
import { Response_WarnList_ext } from 'generated/proto/response_warn_list_pb';
|
||||
import { Response_ViewLogHistory_ext } from 'generated/proto/response_viewlog_history_pb';
|
||||
|
||||
import { banFromServer } from './banFromServer';
|
||||
import { forceActivateUser } from './forceActivateUser';
|
||||
import { getAdminNotes } from './getAdminNotes';
|
||||
|
|
@ -48,7 +33,7 @@ import { grantReplayAccess } from './grantReplayAccess';
|
|||
import { updateAdminNotes } from './updateAdminNotes';
|
||||
import { viewLogHistory } from './viewLogHistory';
|
||||
import { warnUser } from './warnUser';
|
||||
|
||||
import { create } from '@bufbuild/protobuf';
|
||||
import { Mock } from 'vitest';
|
||||
|
||||
const { invokeOnSuccess } = makeCallbackHelpers(
|
||||
|
|
@ -56,8 +41,6 @@ const { invokeOnSuccess } = makeCallbackHelpers(
|
|||
2
|
||||
);
|
||||
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// banFromServer
|
||||
// ----------------------------------------------------------------
|
||||
|
|
@ -66,7 +49,7 @@ describe('banFromServer', () => {
|
|||
it('calls sendModeratorCommand with Command_BanFromServer', () => {
|
||||
banFromServer(30, 'alice', '1.2.3.4', 'reason', 'visible', 'cid', 1);
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_BanFromServer_ext,
|
||||
Data.Command_BanFromServer_ext,
|
||||
expect.objectContaining({ minutes: 30, userName: 'alice' }),
|
||||
expect.any(Object)
|
||||
);
|
||||
|
|
@ -87,7 +70,7 @@ describe('forceActivateUser', () => {
|
|||
it('calls sendModeratorCommand with Command_ForceActivateUser', () => {
|
||||
forceActivateUser('alice', 'mod1');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_ForceActivateUser_ext, expect.any(Object), expect.any(Object)
|
||||
Data.Command_ForceActivateUser_ext, expect.any(Object), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -106,9 +89,9 @@ describe('getAdminNotes', () => {
|
|||
it('calls sendModeratorCommand with Command_GetAdminNotes', () => {
|
||||
getAdminNotes('alice');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GetAdminNotes_ext,
|
||||
Data.Command_GetAdminNotes_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_GetAdminNotes_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_GetAdminNotes_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -128,9 +111,9 @@ describe('getBanHistory', () => {
|
|||
it('calls sendModeratorCommand with Command_GetBanHistory', () => {
|
||||
getBanHistory('alice');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GetBanHistory_ext,
|
||||
Data.Command_GetBanHistory_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_BanHistory_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_BanHistory_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -150,9 +133,9 @@ describe('getWarnHistory', () => {
|
|||
it('calls sendModeratorCommand with Command_GetWarnHistory', () => {
|
||||
getWarnHistory('alice');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GetWarnHistory_ext,
|
||||
Data.Command_GetWarnHistory_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_WarnHistory_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_WarnHistory_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -172,9 +155,9 @@ describe('getWarnList', () => {
|
|||
it('calls sendModeratorCommand with Command_GetWarnList', () => {
|
||||
getWarnList('mod1', 'alice', 'US');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GetWarnList_ext,
|
||||
Data.Command_GetWarnList_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_WarnList_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_WarnList_ext })
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -194,7 +177,7 @@ describe('grantReplayAccess', () => {
|
|||
it('calls sendModeratorCommand with Command_GrantReplayAccess', () => {
|
||||
grantReplayAccess(10, 'mod1');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GrantReplayAccess_ext, expect.any(Object), expect.any(Object)
|
||||
Data.Command_GrantReplayAccess_ext, expect.any(Object), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -213,7 +196,7 @@ describe('updateAdminNotes', () => {
|
|||
it('calls sendModeratorCommand with Command_UpdateAdminNotes', () => {
|
||||
updateAdminNotes('alice', 'new notes');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_UpdateAdminNotes_ext, expect.any(Object), expect.any(Object)
|
||||
Data.Command_UpdateAdminNotes_ext, expect.any(Object), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -230,16 +213,18 @@ describe('updateAdminNotes', () => {
|
|||
describe('viewLogHistory', () => {
|
||||
|
||||
it('calls sendModeratorCommand with Command_ViewLogHistory', () => {
|
||||
viewLogHistory({ dateRange: 7 } as any);
|
||||
const filters = create(Data.Command_ViewLogHistorySchema, { dateRange: 7 });
|
||||
viewLogHistory(filters);
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_ViewLogHistory_ext,
|
||||
Data.Command_ViewLogHistory_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_ViewLogHistory_ext })
|
||||
expect.objectContaining({ responseExt: Data.Response_ViewLogHistory_ext })
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.viewLogs with logMessage', () => {
|
||||
viewLogHistory({ dateRange: 7 } as any);
|
||||
const filters = create(Data.Command_ViewLogHistorySchema, { dateRange: 7 });
|
||||
viewLogHistory(filters);
|
||||
const resp = { logMessage: ['log1'] };
|
||||
invokeOnSuccess(resp, { responseCode: 0 });
|
||||
expect(ModeratorPersistence.viewLogs).toHaveBeenCalledWith(['log1']);
|
||||
|
|
@ -253,7 +238,7 @@ describe('warnUser', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_WarnUser', () => {
|
||||
warnUser('alice', 'bad behavior', 'cid');
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(Command_WarnUser_ext, expect.any(Object), expect.any(Object));
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(Data.Command_WarnUser_ext, expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.warnUser', () => {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_UpdateAdminNotes_ext, Command_UpdateAdminNotesSchema,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function updateAdminNotes(userName: string, notes: string): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_UpdateAdminNotes_ext, create(Command_UpdateAdminNotesSchema, { userName, notes }), {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.updateAdminNotes(userName, notes);
|
||||
},
|
||||
});
|
||||
webClient.protobuf.sendModeratorCommand(
|
||||
Data.Command_UpdateAdminNotes_ext,
|
||||
create(Data.Command_UpdateAdminNotesSchema, { userName, notes }),
|
||||
{
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.updateAdminNotes(userName, notes);
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ViewLogHistory_ext, Command_ViewLogHistorySchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_ViewLogHistory_ext } from 'generated/proto/response_viewlog_history_pb';
|
||||
import { LogFilters } from 'types';
|
||||
|
||||
export function viewLogHistory(filters: LogFilters): void {
|
||||
webClient.protobuf.sendModeratorCommand(Command_ViewLogHistory_ext, create(Command_ViewLogHistorySchema, filters), {
|
||||
responseExt: Response_ViewLogHistory_ext,
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function viewLogHistory(filters: Data.ViewLogHistoryParams): void {
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_ViewLogHistory_ext, create(Data.Command_ViewLogHistorySchema, filters), {
|
||||
responseExt: Data.Response_ViewLogHistory_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.viewLogs(response.logMessage);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_WarnUser_ext, Command_WarnUserSchema } from 'generated/proto/moderator_commands_pb';
|
||||
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Data } from '@app/types';
|
||||
|
||||
export function warnUser(userName: string, reason: string, clientid?: string, removeMessages?: number): void {
|
||||
const cmd = create(Command_WarnUserSchema, { userName, reason, clientid, removeMessages });
|
||||
webClient.protobuf.sendModeratorCommand(Command_WarnUser_ext, cmd, {
|
||||
const cmd = create(Data.Command_WarnUserSchema, { userName, reason, clientid, removeMessages });
|
||||
webClient.protobuf.sendModeratorCommand(Data.Command_WarnUser_ext, cmd, {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.warnUser(userName);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue