Skip to content

Commit

Permalink
fix: rename intermodule interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
laminne committed Jul 23, 2024
1 parent 14bd412 commit ab313db
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 32 deletions.
37 changes: 19 additions & 18 deletions pkg/intermodule/adaptor/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@ import type { Account, AccountID } from '../../accounts/model/account.js';
import type { FetchService } from '../../accounts/service/fetch.js';
import type { FetchFollowService } from '../../accounts/service/fetchFollow.js';
import type {
AccountModuleInterface,
AccountModuleFacade,
PartialAccount,
} from '../interfaces/account.js';

export class AccountModule implements AccountModuleInterface {
export class AccountModule implements AccountModuleFacade {
constructor(
private readonly fetchService: FetchService,
private readonly fetchFollowService: FetchFollowService,
) {}

async fetchAccount(id: AccountID): Promise<Result.Result<Error, Account>> {
const res = await this.fetchService.fetchAccountByID(id);
if (Result.isErr(res)) {
return res;
}

return res;
return await this.fetchService.fetchAccountByID(id);
}

Check warning on line 18 in pkg/intermodule/adaptor/account.ts

View check run for this annotation

Codecov / codecov/patch

pkg/intermodule/adaptor/account.ts#L17-L18

Added lines #L17 - L18 were not covered by tests

async fetchFollowings(
Expand All @@ -31,18 +26,21 @@ export class AccountModule implements AccountModuleInterface {
}

Check warning on line 26 in pkg/intermodule/adaptor/account.ts

View check run for this annotation

Codecov / codecov/patch

pkg/intermodule/adaptor/account.ts#L21-L26

Added lines #L21 - L26 were not covered by tests

const accounts = await Promise.all(
res[1].map((v) => this.fetchService.fetchAccountByID(v.getTargetID())),
Result.unwrap(res).map((v) =>
this.fetchService.fetchAccountByID(v.getTargetID()),
),
);

Check warning on line 32 in pkg/intermodule/adaptor/account.ts

View check run for this annotation

Codecov / codecov/patch

pkg/intermodule/adaptor/account.ts#L28-L32

Added lines #L28 - L32 were not covered by tests

return Result.ok(
accounts
.filter((v) => Result.isOk(v))
.map((v): PartialAccount => {
const unwrapped = Result.unwrap(v);
return {
id: v[1].getID(),
name: v[1].getName(),
nickname: v[1].getNickname(),
bio: v[1].getBio(),
id: unwrapped.getID(),
name: unwrapped.getName(),
nickname: unwrapped.getNickname(),
bio: unwrapped.getBio(),
};
}),
);
Expand All @@ -57,18 +55,21 @@ export class AccountModule implements AccountModuleInterface {
}

Check warning on line 55 in pkg/intermodule/adaptor/account.ts

View check run for this annotation

Codecov / codecov/patch

pkg/intermodule/adaptor/account.ts#L50-L55

Added lines #L50 - L55 were not covered by tests

const accounts = await Promise.all(
res[1].map((v) => this.fetchService.fetchAccountByID(v.getFromID())),
Result.unwrap(res).map((v) =>
this.fetchService.fetchAccountByID(v.getFromID()),
),
);

Check warning on line 61 in pkg/intermodule/adaptor/account.ts

View check run for this annotation

Codecov / codecov/patch

pkg/intermodule/adaptor/account.ts#L57-L61

Added lines #L57 - L61 were not covered by tests

return Result.ok(
accounts
.filter((v) => Result.isOk(v))
.map((v): PartialAccount => {
const unwrapped = Result.unwrap(v);
return {
id: v[1].getID(),
name: v[1].getName(),
nickname: v[1].getNickname(),
bio: v[1].getBio(),
id: unwrapped.getID(),
name: unwrapped.getName(),
nickname: unwrapped.getNickname(),
bio: unwrapped.getBio(),
};
}),
);
Expand Down
2 changes: 1 addition & 1 deletion pkg/intermodule/interfaces/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface PartialAccount {
bio: string;
}

export interface AccountModuleInterface {
export interface AccountModuleFacade {
fetchAccount(id: AccountID): Promise<Result.Result<Error, Account>>;
fetchFollowings(
id: AccountID,
Expand Down
2 changes: 1 addition & 1 deletion pkg/intermodule/interfaces/timeline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Result } from '@mikuroxina/mini-fn';
import type { Note } from '../../notes/model/note.js';

export interface TimelineModuleInterface {
export interface TimelineModuleFacade {
/*
* @description Push note to timeline
* @param note to be pushed
Expand Down
4 changes: 2 additions & 2 deletions pkg/notes/adaptor/controller/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Option, Result } from '@mikuroxina/mini-fn';

import type { AccountID } from '../../../accounts/model/account.js';
import type { MediumID } from '../../../drive/model/medium.js';
import type { AccountModuleInterface } from '../../../intermodule/interfaces/account.js';
import type { AccountModuleFacade } from '../../../intermodule/interfaces/account.js';
import type { NoteID, NoteVisibility } from '../../model/note.js';
import type { CreateService } from '../../service/create.js';
import type { FetchService } from '../../service/fetch.js';
Expand All @@ -19,7 +19,7 @@ export class NoteController {
private readonly createService: CreateService,
private readonly fetchService: FetchService,
private readonly renoteService: RenoteService,
private readonly accountModule: AccountModuleInterface,
private readonly accountModule: AccountModuleFacade,

Check warning on line 22 in pkg/notes/adaptor/controller/note.ts

View check run for this annotation

Codecov / codecov/patch

pkg/notes/adaptor/controller/note.ts#L22

Added line #L22 was not covered by tests
) {}

async createNote(args: {
Expand Down
4 changes: 2 additions & 2 deletions pkg/notes/service/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Option, Result } from '@mikuroxina/mini-fn';

import type { AccountModuleInterface } from '../../intermodule/interfaces/account.js';
import type { AccountModuleFacade } from '../../intermodule/interfaces/account.js';
import type { Note, NoteID } from '../model/note.js';
import type { NoteRepository } from '../model/repository.js';

export class FetchService {
constructor(
private readonly noteRepository: NoteRepository,
private readonly accountModule: AccountModuleInterface,
private readonly accountModule: AccountModuleFacade,
) {}

async fetchNoteByID(noteID: NoteID): Promise<Option.Option<Note>> {
Expand Down
6 changes: 3 additions & 3 deletions pkg/timeline/adaptor/controller/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { z } from '@hono/zod-openapi';
import { Result } from '@mikuroxina/mini-fn';

import type { Account, AccountID } from '../../../accounts/model/account.js';
import type { AccountModuleInterface } from '../../../intermodule/interfaces/account.js';
import type { AccountModuleFacade } from '../../../intermodule/interfaces/account.js';
import type { NoteID } from '../../../notes/model/note.js';
import type { ListID } from '../../model/list.js';
import type { AccountTimelineService } from '../../service/account.js';
Expand All @@ -15,12 +15,12 @@ import type {

export class TimelineController {
private readonly accountTimelineService: AccountTimelineService;
private readonly accountModule: AccountModuleInterface;
private readonly accountModule: AccountModuleFacade;

Check warning on line 18 in pkg/timeline/adaptor/controller/timeline.ts

View check run for this annotation

Codecov / codecov/patch

pkg/timeline/adaptor/controller/timeline.ts#L18

Added line #L18 was not covered by tests
private readonly createListService: CreateListService;
private readonly deleteListService: DeleteListService;
constructor(args: {
accountTimelineService: AccountTimelineService;
accountModule: AccountModuleInterface;
accountModule: AccountModuleFacade;
createListService: CreateListService;
deleteListService: DeleteListService;
}) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/timeline/service/noteVisibility.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Ether, Option, Result } from '@mikuroxina/mini-fn';

import type { AccountID } from '../../accounts/model/account.js';
import type { AccountModuleInterface } from '../../intermodule/interfaces/account.js';
import type { AccountModuleFacade } from '../../intermodule/interfaces/account.js';
import type { Note } from '../../notes/model/note.js';

export interface NoteVisibilityCheckArgs {
Expand All @@ -11,7 +11,7 @@ export interface NoteVisibilityCheckArgs {
}

export class NoteVisibilityService {
constructor(private readonly accountModule: AccountModuleInterface) {}
constructor(private readonly accountModule: AccountModuleFacade) {}

public async handle(args: NoteVisibilityCheckArgs): Promise<boolean> {
if (args.accountID === args.note.getAuthorID()) {
Expand Down Expand Up @@ -55,6 +55,6 @@ export const noteVisibility = Ether.newEther(
noteVisibilitySymbol,
({ accountModule }) => new NoteVisibilityService(accountModule),
{
accountModule: Ether.newEtherSymbol<AccountModuleInterface>(),
accountModule: Ether.newEtherSymbol<AccountModuleFacade>(),
},
);
4 changes: 2 additions & 2 deletions pkg/timeline/service/push.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Result } from '@mikuroxina/mini-fn';

import type { AccountModuleInterface } from '../../intermodule/interfaces/account.js';
import type { AccountModuleFacade } from '../../intermodule/interfaces/account.js';
import type { Note } from '../../notes/model/note.js';
import type { TimelineNotesCacheRepository } from '../model/repository.js';
import type { NoteVisibilityService } from './noteVisibility.js';

export class PushTimelineService {
constructor(
private readonly accountModule: AccountModuleInterface,
private readonly accountModule: AccountModuleFacade,
private readonly noteVisibility: NoteVisibilityService,
private readonly timelineNotesCacheRepository: TimelineNotesCacheRepository,
) {}
Expand Down

0 comments on commit ab313db

Please sign in to comment.