Skip to content

型でドメインモデルを表現する - #92

Draft
Ojoxux wants to merge 1 commit into
stagingfrom
cursor/domain-model-types-e944
Draft

型でドメインモデルを表現する#92
Ojoxux wants to merge 1 commit into
stagingfrom
cursor/domain-model-types-e944

Conversation

@Ojoxux

@Ojoxux Ojoxux commented Jun 29, 2026

Copy link
Copy Markdown
Owner

概要

Branded Typesでドメインモデルを表現し、ID やステータスなどの概念を型レベルで区別できるようにしました。

  • app/types/domain.ts を追加し、UserId / BookId / TagId / SessionIdOAuthProviderBookStatusBookSortOrder を単一定義元に集約
  • DB リポジトリ、セッション、認証、マッパー、API ハンドラー、テストをブランド型に対応
  • OAuthProviderBookStatus の重複定義を解消

確認

  • pnpm typecheck 成功
  • pnpm lint エラーなし(既存 warning のみ)

補足

  • 実行時の挙動は変更していません
  • HTTP パラメータや UUID 生成などの外部境界でのみ as BookId 等のキャストを行い、アプリ内部では型安全性を担保しています
Open in Web Open in Cursor 

- app/types/domain.ts を新規追加
  - Brand<T, B> ユーティリティ型
  - UserId, BookId, TagId, SessionId のブランド型
  - OAuthProvider, BookStatus, BookSortOrder の単一定義元

- 全レイヤーでブランド型を使用
  - DB リポジトリ: UserId/BookId/TagId を引数型に使用
  - セッション: createSession が UserId を受け取り SessionId を返す
  - 認証ミドルウェア: UserId で統一
  - マッパー: crypto.randomUUID() を BookId/TagId にキャスト
  - API ハンドラー: URL パラメータ境界で as BookId 等でキャスト

- 重複を解消
  - OAuthProvider: types/api.ts と schemas/auth.ts で domain から再エクスポート
  - BookStatus: database.ts で domain から再エクスポート、domain/book.ts も同様

- テストヘルパーと全テストファイルをブランド型に対応

Co-authored-by: Jou Okuyama <Ojoxux@users.noreply.github.com>
@Ojoxux Ojoxux changed the title feat: 型でドメインモデルを表現(Branded ID types) 型でドメインモデルを表現する Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants