diff --git a/pkg/notes/adaptor/controller/bookmark.ts b/pkg/notes/adaptor/controller/bookmark.ts index 85c5b983..1f21ca8f 100644 --- a/pkg/notes/adaptor/controller/bookmark.ts +++ b/pkg/notes/adaptor/controller/bookmark.ts @@ -2,7 +2,6 @@ import type { z } from '@hono/zod-openapi'; import { type Option, Result } from '@mikuroxina/mini-fn'; import type { AccountID } from '../../../accounts/model/account.js'; -import type { ID } from '../../../id/type.js'; import type { Bookmark } from '../../model/bookmark.js'; import type { NoteID } from '../../model/note.js'; import type { CreateBookmarkService } from '../../service/createBookmark.js'; @@ -24,7 +23,7 @@ export class BookmarkController { Result.Result> > { const res = await this.createBookmarkService.handle( - noteID as ID, + noteID as NoteID, accountID as AccountID, ); @@ -47,7 +46,7 @@ export class BookmarkController { accountID: string, ): Promise> { const res = await this.fetchBookmarkService.fetchBookmarkByID( - noteID as ID, + noteID as NoteID, accountID as AccountID, ); @@ -69,7 +68,7 @@ export class BookmarkController { accountID: string, ): Promise> { const res = await this.deleteBookmarkService.handle( - noteID as ID, + noteID as NoteID, accountID as AccountID, ); diff --git a/pkg/notes/adaptor/controller/note.ts b/pkg/notes/adaptor/controller/note.ts index e0a4a521..8c22fa02 100644 --- a/pkg/notes/adaptor/controller/note.ts +++ b/pkg/notes/adaptor/controller/note.ts @@ -2,7 +2,6 @@ import { type z } from '@hono/zod-openapi'; import { Option, Result } from '@mikuroxina/mini-fn'; import type { AccountID } from '../../../accounts/model/account.js'; -import type { ID } from '../../../id/type.js'; import type { AccountModule } from '../../../intermodule/account.js'; import type { NoteID, NoteVisibility } from '../../model/note.js'; import type { CreateService } from '../../service/create.js'; @@ -56,7 +55,7 @@ export class NoteController { async getNoteByID( noteID: string, ): Promise>> { - const res = await this.fetchService.fetchNoteByID(noteID as ID); + const res = await this.fetchService.fetchNoteByID(noteID as NoteID); if (Option.isNone(res)) { return Result.err(new Error('Note not found')); } @@ -99,7 +98,7 @@ export class NoteController { contentsWarningComment: string, ): Promise>> { const res = await this.renoteService.handle( - originalNoteID as ID, + originalNoteID as NoteID, content, contentsWarningComment, authorID as AccountID, diff --git a/pkg/notes/adaptor/repository/dummy.ts b/pkg/notes/adaptor/repository/dummy.ts index 100f7725..5f368e8a 100644 --- a/pkg/notes/adaptor/repository/dummy.ts +++ b/pkg/notes/adaptor/repository/dummy.ts @@ -1,7 +1,6 @@ import { Option, Result } from '@mikuroxina/mini-fn'; import type { AccountID } from '../../../accounts/model/account.js'; -import type { ID } from '../../../id/type.js'; import { Bookmark } from '../../model/bookmark.js'; import { type Note, type NoteID } from '../../model/note.js'; import type { @@ -10,7 +9,7 @@ import type { } from '../../model/repository.js'; export class InMemoryNoteRepository implements NoteRepository { - private readonly notes: Map, Note>; + private readonly notes: Map; constructor(notes: Note[] = []) { this.notes = new Map(notes.map((note) => [note.getID(), note])); @@ -21,7 +20,7 @@ export class InMemoryNoteRepository implements NoteRepository { return Result.ok(undefined); } - async deleteByID(id: ID): Promise> { + async deleteByID(id: NoteID): Promise> { const target = await this.findByID(id); if (Option.isNone(target)) { return Result.err(new Error('note not found')); @@ -50,7 +49,7 @@ export class InMemoryNoteRepository implements NoteRepository { ); } - findByID(id: ID): Promise> { + findByID(id: NoteID): Promise> { const res = this.notes.get(id); if (!res) { return Promise.resolve(Option.none()); @@ -60,12 +59,9 @@ export class InMemoryNoteRepository implements NoteRepository { } export class InMemoryBookmarkRepository implements BookmarkRepository { - private readonly bookmarks: Map<[ID, AccountID], Bookmark>; + private readonly bookmarks: Map<[NoteID, AccountID], Bookmark>; - private equalID( - a: [ID, AccountID], - b: [ID, AccountID], - ): boolean { + private equalID(a: [NoteID, AccountID], b: [NoteID, AccountID]): boolean { return a[0] === b[0] && a[1] === b[1]; } @@ -79,7 +75,7 @@ export class InMemoryBookmarkRepository implements BookmarkRepository { } async create(id: { - noteID: ID; + noteID: NoteID; accountID: AccountID; }): Promise> { const bookmark = Bookmark.new(id); @@ -88,7 +84,7 @@ export class InMemoryBookmarkRepository implements BookmarkRepository { } async deleteByID(id: { - noteID: ID; + noteID: NoteID; accountID: AccountID; }): Promise> { const key = Array.from(this.bookmarks.keys()).find((k) => @@ -104,7 +100,7 @@ export class InMemoryBookmarkRepository implements BookmarkRepository { } async findByID(id: { - noteID: ID; + noteID: NoteID; accountID: AccountID; }): Promise> { const bookmark = Array.from(this.bookmarks.entries()).find((v) => diff --git a/pkg/notes/adaptor/repository/prisma.ts b/pkg/notes/adaptor/repository/prisma.ts index b065e4d0..b0a505e4 100644 --- a/pkg/notes/adaptor/repository/prisma.ts +++ b/pkg/notes/adaptor/repository/prisma.ts @@ -3,7 +3,6 @@ import { type Prisma, type PrismaClient } from '@prisma/client'; import type { AccountID } from '../../../accounts/model/account.js'; import type { prismaClient } from '../../../adaptors/prisma.js'; -import type { ID } from '../../../id/type.js'; import { Bookmark } from '../../model/bookmark.js'; import { Note, type NoteID, type NoteVisibility } from '../../model/note.js'; import type { @@ -67,14 +66,14 @@ export class PrismaNoteRepository implements NoteRepository { } }; return Note.reconstruct({ - id: data.id as ID, + id: data.id as NoteID, content: data.text, authorID: data.authorId as AccountID, createdAt: data.createdAt, deletedAt: !data.deletedAt ? Option.none() : Option.some(data.deletedAt), contentsWarningComment: '', originalNoteID: !data.renoteId - ? Option.some(data.renoteId as ID) + ? Option.some(data.renoteId as NoteID) : Option.none(), // ToDo: add SendTo field to schema sendTo: Option.none(), @@ -95,7 +94,7 @@ export class PrismaNoteRepository implements NoteRepository { return Result.ok(undefined); } - async deleteByID(id: ID): Promise> { + async deleteByID(id: NoteID): Promise> { try { // NOTE: logical delete await this.client.note.update({ @@ -135,7 +134,7 @@ export class PrismaNoteRepository implements NoteRepository { } } - async findByID(id: ID): Promise> { + async findByID(id: NoteID): Promise> { try { const res = await this.client.note.findUniqueOrThrow({ where: { @@ -155,7 +154,7 @@ export class PrismaBookmarkRepository implements BookmarkRepository { constructor(private readonly client: PrismaClient) {} async create(id: { - noteID: ID; + noteID: NoteID; accountID: AccountID; }): Promise> { try { @@ -172,7 +171,7 @@ export class PrismaBookmarkRepository implements BookmarkRepository { } async deleteByID(id: { - noteID: ID; + noteID: NoteID; accountID: AccountID; }): Promise> { try { @@ -204,7 +203,7 @@ export class PrismaBookmarkRepository implements BookmarkRepository { return Option.some( res.map((v) => Bookmark.new({ - noteID: v.noteId as ID, + noteID: v.noteId as NoteID, accountID: v.accountId as AccountID, }), ), @@ -215,7 +214,7 @@ export class PrismaBookmarkRepository implements BookmarkRepository { } async findByID(id: { - noteID: ID; + noteID: NoteID; accountID: AccountID; }): Promise> { try { @@ -230,7 +229,7 @@ export class PrismaBookmarkRepository implements BookmarkRepository { }); return Option.some( Bookmark.new({ - noteID: res.noteId as ID, + noteID: res.noteId as NoteID, accountID: res.accountId as AccountID, }), ); diff --git a/pkg/notes/model/bookmark.test.ts b/pkg/notes/model/bookmark.test.ts index 585bbd5f..6546d588 100644 --- a/pkg/notes/model/bookmark.test.ts +++ b/pkg/notes/model/bookmark.test.ts @@ -1,12 +1,11 @@ import { describe, expect, it } from 'vitest'; import type { AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import { Bookmark, type CreateBookmarkArgs } from './bookmark.js'; import { type NoteID } from './note.js'; const exampleInput: CreateBookmarkArgs = { - noteID: '1' as ID, + noteID: '1' as NoteID, accountID: '2' as AccountID, }; diff --git a/pkg/notes/model/bookmark.ts b/pkg/notes/model/bookmark.ts index ef1b8bc1..a18a967e 100644 --- a/pkg/notes/model/bookmark.ts +++ b/pkg/notes/model/bookmark.ts @@ -1,9 +1,8 @@ import type { AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import type { NoteID } from './note.js'; export interface CreateBookmarkArgs { - noteID: ID; + noteID: NoteID; accountID: AccountID; } @@ -17,9 +16,9 @@ export class Bookmark { return new Bookmark(arg); } - private readonly noteID: ID; + private readonly noteID: NoteID; - getNoteID(): ID { + getNoteID(): NoteID { return this.noteID; } diff --git a/pkg/notes/model/note.test.ts b/pkg/notes/model/note.test.ts index a064ea9f..30bcf072 100644 --- a/pkg/notes/model/note.test.ts +++ b/pkg/notes/model/note.test.ts @@ -2,11 +2,10 @@ import { Option } from '@mikuroxina/mini-fn'; import { describe, expect, it } from 'vitest'; import type { AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import { type CreateNoteArgs, Note, type NoteID } from './note.js'; const exampleInput: CreateNoteArgs = { - id: '1' as ID, + id: '1' as NoteID, authorID: '2' as AccountID, content: 'hello world!', createdAt: new Date('2023-09-10T00:00:00.000Z'), diff --git a/pkg/notes/model/note.ts b/pkg/notes/model/note.ts index 5ac4fa9e..39934dec 100644 --- a/pkg/notes/model/note.ts +++ b/pkg/notes/model/note.ts @@ -3,17 +3,17 @@ import { Option } from '@mikuroxina/mini-fn'; import type { AccountID } from '../../accounts/model/account.js'; import type { ID } from '../../id/type.js'; -export type NoteID = string; +export type NoteID = ID; export type NoteVisibility = 'PUBLIC' | 'HOME' | 'FOLLOWERS' | 'DIRECT'; export interface CreateNoteArgs { - id: ID; + id: NoteID; authorID: AccountID; content: string; visibility: NoteVisibility; contentsWarningComment: string; sendTo: Option.Option; - originalNoteID: Option.Option>; + originalNoteID: Option.Option; createdAt: Date; updatedAt: Option.Option; deletedAt: Option.Option; @@ -52,8 +52,8 @@ export class Note { return new Note(arg); } - private readonly id: ID; - getID(): ID { + private readonly id: NoteID; + getID(): NoteID { return this.id; } @@ -82,8 +82,8 @@ export class Note { return this.sendTo; } - private readonly originalNoteID: Option.Option>; - getOriginalNoteID(): Option.Option> { + private readonly originalNoteID: Option.Option; + getOriginalNoteID(): Option.Option { return this.originalNoteID; } diff --git a/pkg/notes/model/repository.ts b/pkg/notes/model/repository.ts index 0e53cec3..9a471ceb 100644 --- a/pkg/notes/model/repository.ts +++ b/pkg/notes/model/repository.ts @@ -1,7 +1,6 @@ import type { Option, Result } from '@mikuroxina/mini-fn'; import type { AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import type { Bookmark } from './bookmark.js'; import type { Note, NoteID } from './note.js'; @@ -11,22 +10,22 @@ export interface NoteRepository { authorID: AccountID, limit: number, ): Promise>; - findByID(id: ID): Promise>; - deleteByID(id: ID): Promise>; + findByID(id: NoteID): Promise>; + deleteByID(id: NoteID): Promise>; } export interface BookmarkRepository { create(id: { - noteID: ID; + noteID: NoteID; accountID: AccountID; }): Promise>; findByID(id: { - noteID: ID; + noteID: NoteID; accountID: AccountID; }): Promise>; findByAccountID(id: AccountID): Promise>; deleteByID(id: { - noteID: ID; + noteID: NoteID; accountID: AccountID; }): Promise>; } diff --git a/pkg/notes/service/create.ts b/pkg/notes/service/create.ts index 50276eb2..6c8d2987 100644 --- a/pkg/notes/service/create.ts +++ b/pkg/notes/service/create.ts @@ -2,7 +2,6 @@ import { Option, Result } from '@mikuroxina/mini-fn'; import type { AccountID } from '../../accounts/model/account.js'; import type { SnowflakeIDGenerator } from '../../id/mod.js'; -import type { ID } from '../../id/type.js'; import { Note, type NoteID, type NoteVisibility } from '../model/note.js'; import type { NoteRepository } from '../model/repository.js'; @@ -14,13 +13,13 @@ export class CreateService { authorID: AccountID, visibility: NoteVisibility, ): Promise> { - const id = this.idGenerator.generate(); + const id = this.idGenerator.generate(); if (Result.isErr(id)) { return id; } try { const note = Note.new({ - id: id[1] as ID, + id: id[1] as NoteID, content: content, contentsWarningComment: contentsWarningComment, createdAt: new Date(), diff --git a/pkg/notes/service/createBookmark.test.ts b/pkg/notes/service/createBookmark.test.ts index 4f3bb970..963a32f5 100644 --- a/pkg/notes/service/createBookmark.test.ts +++ b/pkg/notes/service/createBookmark.test.ts @@ -2,7 +2,6 @@ import { Option, Result } from '@mikuroxina/mini-fn'; import { describe, expect, it } from 'vitest'; import type { AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import { InMemoryBookmarkRepository, InMemoryNoteRepository, @@ -10,15 +9,15 @@ import { import { Note, type NoteID } from '../model/note.js'; import { CreateBookmarkService } from './createBookmark.js'; -const noteID = 'noteID_1' as ID; -const anotherNoteID = 'noteID_2' as ID; +const noteID = 'noteID_1' as NoteID; +const anotherNoteID = 'noteID_2' as NoteID; const accountID = 'accountID_1' as AccountID; const anotherAccountID = 'accountID_2' as AccountID; const bookmarkRepository = new InMemoryBookmarkRepository(); const noteRepository = new InMemoryNoteRepository([ Note.new({ - id: 'noteID_1' as ID, + id: 'noteID_1' as NoteID, authorID: '3' as AccountID, content: 'Hello world', contentsWarningComment: '', @@ -28,7 +27,7 @@ const noteRepository = new InMemoryNoteRepository([ visibility: 'PUBLIC', }), Note.new({ - id: 'noteID_2' as ID, + id: 'noteID_2' as NoteID, authorID: '3' as AccountID, content: 'Another note', contentsWarningComment: '', @@ -64,7 +63,7 @@ describe('CreateBookmarkService', () => { it('fail when note not found', async () => { const res = await createBookmarkService.handle( - 'note_notexist' as ID, + 'note_notexist' as NoteID, accountID, ); expect(Result.isErr(res)).toBe(true); diff --git a/pkg/notes/service/createBookmark.ts b/pkg/notes/service/createBookmark.ts index a89aebd1..dbe89d22 100644 --- a/pkg/notes/service/createBookmark.ts +++ b/pkg/notes/service/createBookmark.ts @@ -1,7 +1,6 @@ import { Option, Result } from '@mikuroxina/mini-fn'; import type { AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import type { Note, NoteID } from '../model/note.js'; import type { BookmarkRepository, @@ -15,7 +14,7 @@ export class CreateBookmarkService { ) {} async handle( - noteID: ID, + noteID: NoteID, accountID: AccountID, ): Promise> { const note = await this.noteRepository.findByID(noteID); diff --git a/pkg/notes/service/deleteBookmark.test.ts b/pkg/notes/service/deleteBookmark.test.ts index 7c34abbf..5dbb75ed 100644 --- a/pkg/notes/service/deleteBookmark.test.ts +++ b/pkg/notes/service/deleteBookmark.test.ts @@ -2,13 +2,12 @@ import { Result } from '@mikuroxina/mini-fn'; import { describe, expect, it } from 'vitest'; import type { AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import { InMemoryBookmarkRepository } from '../adaptor/repository/dummy.js'; import { Bookmark } from '../model/bookmark.js'; import type { NoteID } from '../model/note.js'; import { DeleteBookmarkService } from './deleteBookmark.js'; -const noteID = '1' as ID; +const noteID = '1' as NoteID; const accountID = '1' as AccountID; const bookmarkRepository = new InMemoryBookmarkRepository([ @@ -24,7 +23,7 @@ describe('DeleteBookmarkService', () => { it('should fail to delete bookmark when does not exist bookmark', async () => { const res = await deleteBookmarkService.handle( - 'notExistNoteID' as ID, + 'notExistNoteID' as NoteID, accountID, ); expect(Result.isErr(res)).toBe(true); diff --git a/pkg/notes/service/deleteBookmark.ts b/pkg/notes/service/deleteBookmark.ts index 38f3f843..43061600 100644 --- a/pkg/notes/service/deleteBookmark.ts +++ b/pkg/notes/service/deleteBookmark.ts @@ -1,7 +1,6 @@ import type { Result } from '@mikuroxina/mini-fn'; import type { AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import type { NoteID } from '../model/note.js'; import type { BookmarkRepository } from '../model/repository.js'; @@ -9,7 +8,7 @@ export class DeleteBookmarkService { constructor(private readonly bookmarkRepository: BookmarkRepository) {} async handle( - noteID: ID, + noteID: NoteID, accountID: AccountID, ): Promise> { return await this.bookmarkRepository.deleteByID({ noteID, accountID }); diff --git a/pkg/notes/service/fetch.test.ts b/pkg/notes/service/fetch.test.ts index 08495636..f60f0678 100644 --- a/pkg/notes/service/fetch.test.ts +++ b/pkg/notes/service/fetch.test.ts @@ -3,14 +3,13 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; import { InMemoryAccountRepository } from '../../accounts/adaptor/repository/dummy.js'; import { Account, type AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import { AccountModule } from '../../intermodule/account.js'; import { InMemoryNoteRepository } from '../adaptor/repository/dummy.js'; import { Note, type NoteID } from '../model/note.js'; import { FetchService } from './fetch.js'; const testNote = Note.new({ - id: '1' as ID, + id: '1' as NoteID, authorID: '3' as AccountID, content: 'Hello world', contentsWarningComment: '', @@ -20,7 +19,7 @@ const testNote = Note.new({ visibility: 'PUBLIC', }); const deletedNote = Note.reconstruct({ - id: '2' as ID, + id: '2' as NoteID, authorID: '3' as AccountID, content: 'Hello world', contentsWarningComment: '', @@ -32,7 +31,7 @@ const deletedNote = Note.reconstruct({ updatedAt: Option.none(), }); const frozenUserNote = Note.reconstruct({ - id: '5' as ID, + id: '5' as NoteID, authorID: '4' as AccountID, content: 'Hello world', contentsWarningComment: '', @@ -93,14 +92,14 @@ describe('FetchService', () => { vi.spyOn(accountModule, 'fetchAccount').mockImplementation(async () => { return Result.ok(testAccount); }); - const res = await service.fetchNoteByID('1' as ID); + const res = await service.fetchNoteByID('1' as NoteID); expect(Option.isSome(res)).toBe(true); expect(res[1]).toStrictEqual(testNote); }); it('note not found', async () => { - const res = await service.fetchNoteByID('999' as ID); + const res = await service.fetchNoteByID('999' as NoteID); expect(Option.isNone(res)).toBe(true); }); diff --git a/pkg/notes/service/fetch.ts b/pkg/notes/service/fetch.ts index f1f7f4bf..f0060ba3 100644 --- a/pkg/notes/service/fetch.ts +++ b/pkg/notes/service/fetch.ts @@ -1,6 +1,5 @@ import { Option, Result } from '@mikuroxina/mini-fn'; -import type { ID } from '../../id/type.js'; import type { AccountModule } from '../../intermodule/account.js'; import { type Note, type NoteID } from '../model/note.js'; import type { NoteRepository } from '../model/repository.js'; @@ -11,7 +10,7 @@ export class FetchService { private readonly accountModule: AccountModule, ) {} - async fetchNoteByID(noteID: ID): Promise> { + async fetchNoteByID(noteID: NoteID): Promise> { const note = await this.noteRepository.findByID(noteID); if (Option.isNone(note)) { return Option.none(); diff --git a/pkg/notes/service/fetchBookmark.test.ts b/pkg/notes/service/fetchBookmark.test.ts index f8679fe1..f7bb4f7e 100644 --- a/pkg/notes/service/fetchBookmark.test.ts +++ b/pkg/notes/service/fetchBookmark.test.ts @@ -2,7 +2,6 @@ import { Option } from '@mikuroxina/mini-fn'; import { describe, expect, it } from 'vitest'; import type { AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import { InMemoryBookmarkRepository } from '../adaptor/repository/dummy.js'; import { Bookmark } from '../model/bookmark.js'; import type { NoteID } from '../model/note.js'; @@ -10,15 +9,15 @@ import { FetchBookmarkService } from './fetchBookmark.js'; const bookmarkRepository = new InMemoryBookmarkRepository([ Bookmark.new({ - noteID: '1' as ID, + noteID: '1' as NoteID, accountID: '10' as AccountID, }), Bookmark.new({ - noteID: '2' as ID, + noteID: '2' as NoteID, accountID: '10' as AccountID, }), Bookmark.new({ - noteID: '2' as ID, + noteID: '2' as NoteID, accountID: '20' as AccountID, }), ]); @@ -27,7 +26,7 @@ const fetchBookmarkService = new FetchBookmarkService(bookmarkRepository); describe('FetchBookmarkService', () => { it('should fetch bookmark', async () => { const res = await fetchBookmarkService.fetchBookmarkByID( - '1' as ID, + '1' as NoteID, '10' as AccountID, ); expect(Option.isSome(res)).toBe(true); @@ -43,7 +42,7 @@ describe('FetchBookmarkService', () => { it('bookmark not found', async () => { const res = await fetchBookmarkService.fetchBookmarkByID( - '42' as ID, + '42' as NoteID, '10' as AccountID, ); expect(Option.isNone(res)).toBe(true); diff --git a/pkg/notes/service/fetchBookmark.ts b/pkg/notes/service/fetchBookmark.ts index 75d7b6d0..3572b5d8 100644 --- a/pkg/notes/service/fetchBookmark.ts +++ b/pkg/notes/service/fetchBookmark.ts @@ -1,7 +1,6 @@ import { Option } from '@mikuroxina/mini-fn'; import type { AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import type { Bookmark } from '../model/bookmark.js'; import type { NoteID } from '../model/note.js'; import type { BookmarkRepository } from '../model/repository.js'; @@ -10,7 +9,7 @@ export class FetchBookmarkService { constructor(private readonly bookmarkRepository: BookmarkRepository) {} async fetchBookmarkByID( - noteID: ID, + noteID: NoteID, accountID: AccountID, ): Promise> { const bookmark = await this.bookmarkRepository.findByID({ diff --git a/pkg/notes/service/renote.test.ts b/pkg/notes/service/renote.test.ts index 954066ea..9d88c0b4 100644 --- a/pkg/notes/service/renote.test.ts +++ b/pkg/notes/service/renote.test.ts @@ -3,13 +3,12 @@ import { describe, expect, it, vi } from 'vitest'; import type { AccountID } from '../../accounts/model/account.js'; import { SnowflakeIDGenerator } from '../../id/mod.js'; -import type { ID } from '../../id/type.js'; import { InMemoryNoteRepository } from '../adaptor/repository/dummy.js'; import { Note, type NoteID } from '../model/note.js'; import { RenoteService } from './renote.js'; const originalNote = Note.new({ - id: '2' as ID, + id: '2' as NoteID, authorID: '1' as AccountID, content: 'original note', contentsWarningComment: '', @@ -29,7 +28,7 @@ const service = new RenoteService( describe('RenoteService', () => { it('should create renote', async () => { const renote = await service.handle( - '2' as ID, + '2' as NoteID, 'renote', '', '1' as AccountID, @@ -39,14 +38,14 @@ describe('RenoteService', () => { expect(Result.unwrap(renote).getContent()).toBe('renote'); expect(Result.unwrap(renote).getCwComment()).toBe(''); expect(Result.unwrap(renote).getOriginalNoteID()).toStrictEqual( - Option.some('2' as ID), + Option.some('2' as NoteID), ); expect(Result.unwrap(renote).getVisibility()).toBe('PUBLIC'); }); it('should not create renote with DIRECT visibility', async () => { const res = await service.handle( - '2' as ID, + '2' as NoteID, 'direct renote', '', '1' as AccountID, @@ -58,7 +57,7 @@ describe('RenoteService', () => { it('if original note not found', async () => { const res = await service.handle( - '3' as ID, + '3' as NoteID, 'renote', '', '1' as AccountID, @@ -77,7 +76,7 @@ describe('RenoteService', () => { ); const res = await dummyService.handle( - '3' as ID, + '3' as NoteID, 'renote', '', '1' as AccountID, @@ -93,7 +92,7 @@ describe('RenoteService', () => { ); const res = await service.handle( - '2' as ID, + '2' as NoteID, 'renote', '', '1' as AccountID, diff --git a/pkg/notes/service/renote.ts b/pkg/notes/service/renote.ts index e6b583b7..ebef0f88 100644 --- a/pkg/notes/service/renote.ts +++ b/pkg/notes/service/renote.ts @@ -2,7 +2,6 @@ import { Option, Result } from '@mikuroxina/mini-fn'; import type { AccountID } from '../../accounts/model/account.js'; import type { SnowflakeIDGenerator } from '../../id/mod.js'; -import type { ID } from '../../id/type.js'; import type { NoteID, NoteVisibility } from '../model/note.js'; import { Note } from '../model/note.js'; import type { NoteRepository } from '../model/repository.js'; @@ -14,7 +13,7 @@ export class RenoteService { ) {} async handle( - originalNoteID: ID, + originalNoteID: NoteID, content: string, contentsWarningComment: string, authorID: AccountID, @@ -30,13 +29,13 @@ export class RenoteService { return Result.err(new Error('Original note not found')); } - const id = this.idGenerator.generate(); + const id = this.idGenerator.generate(); if (Result.isErr(id)) { return id; } const renote = Note.new({ - id: Result.unwrap(id) as ID, + id: Result.unwrap(id) as NoteID, authorID: authorID, content: content, contentsWarningComment: contentsWarningComment, diff --git a/pkg/timeline/adaptor/controller/timeline.ts b/pkg/timeline/adaptor/controller/timeline.ts index 0abc9afd..b456497d 100644 --- a/pkg/timeline/adaptor/controller/timeline.ts +++ b/pkg/timeline/adaptor/controller/timeline.ts @@ -5,8 +5,8 @@ import { type Account, type AccountID, } from '../../../accounts/model/account.js'; -import type { ID } from '../../../id/type.js'; import type { AccountModule } from '../../../intermodule/account.js'; +import type { NoteID } from '../../../notes/model/note.js'; import type { AccountTimelineService } from '../../service/account.js'; import type { GetAccountTimelineResponseSchema } from '../validator/timeline.js'; @@ -36,7 +36,7 @@ export class TimelineController { id: fromId as AccountID, hasAttachment, noNsfw, - beforeId: beforeId as ID, + beforeId: beforeId as NoteID, }, ); if (Result.isErr(res)) { diff --git a/pkg/timeline/adaptor/repository/prisma.ts b/pkg/timeline/adaptor/repository/prisma.ts index 3de2bd5b..c2162137 100644 --- a/pkg/timeline/adaptor/repository/prisma.ts +++ b/pkg/timeline/adaptor/repository/prisma.ts @@ -2,7 +2,6 @@ import { Option, Result } from '@mikuroxina/mini-fn'; import type { Prisma, PrismaClient } from '@prisma/client'; import type { AccountID } from '../../../accounts/model/account.js'; -import type { ID } from '../../../id/type.js'; import { Note, type NoteID, @@ -35,14 +34,14 @@ export class PrismaTimelineRepository implements TimelineRepository { } }; return Note.reconstruct({ - id: v.id as ID, + id: v.id as NoteID, content: v.text, authorID: v.authorId as AccountID, createdAt: v.createdAt, deletedAt: !v.deletedAt ? Option.none() : Option.some(v.deletedAt), contentsWarningComment: '', originalNoteID: !v.renoteId - ? Option.some(v.renoteId as ID) + ? Option.some(v.renoteId as NoteID) : Option.none(), // ToDo: add SendTo field to db schema sendTo: Option.none(), diff --git a/pkg/timeline/model/repository.ts b/pkg/timeline/model/repository.ts index a55bc239..9ad9c195 100644 --- a/pkg/timeline/model/repository.ts +++ b/pkg/timeline/model/repository.ts @@ -1,7 +1,6 @@ import { Ether, type Result } from '@mikuroxina/mini-fn'; import type { AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import type { Note, NoteID } from '../../notes/model/note.js'; export interface FetchAccountTimelineFilter { @@ -12,7 +11,7 @@ export interface FetchAccountTimelineFilter { noNsfw: boolean; /** @default undefined * @description if undefined, Retrieved from latest notes */ - beforeId?: ID; + beforeId?: NoteID; } export interface TimelineRepository { diff --git a/pkg/timeline/service/account.test.ts b/pkg/timeline/service/account.test.ts index 17d4ac0b..e94c4722 100644 --- a/pkg/timeline/service/account.test.ts +++ b/pkg/timeline/service/account.test.ts @@ -2,7 +2,6 @@ import { Option, Result } from '@mikuroxina/mini-fn'; import { describe, expect, it, vi } from 'vitest'; import { Account, type AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import { AccountModule, type PartialAccount, @@ -17,7 +16,7 @@ describe('AccountTimelineService', () => { const noteVisibilityService = new NoteVisibilityService(accountModule); const dummyPublicNote = Note.new({ - id: '1' as ID, + id: '1' as NoteID, authorID: '100' as AccountID, content: 'Hello world', contentsWarningComment: '', @@ -27,7 +26,7 @@ describe('AccountTimelineService', () => { visibility: 'PUBLIC', }); const dummyHomeNote = Note.new({ - id: '2' as ID, + id: '2' as NoteID, authorID: '100' as AccountID, content: 'Hello world to Home', contentsWarningComment: '', @@ -37,7 +36,7 @@ describe('AccountTimelineService', () => { visibility: 'HOME', }); const dummyFollowersNote = Note.new({ - id: '3' as ID, + id: '3' as NoteID, authorID: '100' as AccountID, content: 'Hello world to followers', contentsWarningComment: '', @@ -47,7 +46,7 @@ describe('AccountTimelineService', () => { visibility: 'FOLLOWERS', }); const dummyDirectNote = Note.new({ - id: '4' as ID, + id: '4' as NoteID, authorID: '100' as AccountID, content: 'Hello world to direct', contentsWarningComment: '', diff --git a/pkg/timeline/service/noteVisibility.test.ts b/pkg/timeline/service/noteVisibility.test.ts index 7a368e3f..2a72a6a3 100644 --- a/pkg/timeline/service/noteVisibility.test.ts +++ b/pkg/timeline/service/noteVisibility.test.ts @@ -2,7 +2,6 @@ import { Option, Result } from '@mikuroxina/mini-fn'; import { describe, expect, it, vi } from 'vitest'; import { Account, type AccountID } from '../../accounts/model/account.js'; -import type { ID } from '../../id/type.js'; import { AccountModule, type PartialAccount, @@ -15,7 +14,7 @@ describe('NoteVisibilityService', () => { const visibilityService = new NoteVisibilityService(accountModule); const dummyPublicNote = Note.new({ - id: '1' as ID, + id: '1' as NoteID, authorID: '100' as AccountID, content: 'Hello world', contentsWarningComment: '', @@ -25,7 +24,7 @@ describe('NoteVisibilityService', () => { visibility: 'PUBLIC', }); const dummyHomeNote = Note.new({ - id: '2' as ID, + id: '2' as NoteID, authorID: '100' as AccountID, content: 'Hello world to Home', contentsWarningComment: '', @@ -35,7 +34,7 @@ describe('NoteVisibilityService', () => { visibility: 'HOME', }); const dummyFollowersNote = Note.new({ - id: '3' as ID, + id: '3' as NoteID, authorID: '100' as AccountID, content: 'Hello world to followers', contentsWarningComment: '', @@ -45,7 +44,7 @@ describe('NoteVisibilityService', () => { visibility: 'FOLLOWERS', }); const dummyDirectNote = Note.new({ - id: '4' as ID, + id: '4' as NoteID, authorID: '100' as AccountID, content: 'Hello world to direct', contentsWarningComment: '',