mirror of
https://github.com/samiyev/puaros.git
synced 2025-12-27 23:06:54 +05:00
Add comprehensive Repository Pattern validation to detect violations and ensure proper domain-infrastructure separation. Features: - ORM type detection in repository interfaces (25+ patterns) - Concrete repository usage detection in use cases - Repository instantiation detection (new Repository()) - Domain language validation for repository methods - Smart violation reporting with fix suggestions Tests: - 31 new tests for repository pattern detection - 292 total tests passing (100% pass rate) - 96.77% statement coverage, 83.82% branch coverage Examples: - 8 example files (4 bad patterns, 4 good patterns) - Demonstrates Clean Architecture and SOLID principles
62 lines
1.1 KiB
TypeScript
62 lines
1.1 KiB
TypeScript
/**
|
|
* ✅ GOOD EXAMPLE: Clean repository interface
|
|
*
|
|
* Repository interface uses only domain types, keeping it persistence-agnostic.
|
|
* ORM implementation details stay in infrastructure layer.
|
|
*/
|
|
|
|
interface IUserRepository {
|
|
findById(id: UserId): Promise<User | null>
|
|
|
|
findByEmail(email: Email): Promise<User | null>
|
|
|
|
save(user: User): Promise<void>
|
|
|
|
delete(id: UserId): Promise<void>
|
|
|
|
findAll(criteria: UserSearchCriteria): Promise<User[]>
|
|
}
|
|
|
|
class UserId {
|
|
constructor(private readonly value: string) {}
|
|
|
|
getValue(): string {
|
|
return this.value
|
|
}
|
|
}
|
|
|
|
class Email {
|
|
constructor(private readonly value: string) {}
|
|
|
|
getValue(): string {
|
|
return this.value
|
|
}
|
|
}
|
|
|
|
class UserSearchCriteria {
|
|
constructor(
|
|
public readonly isActive?: boolean,
|
|
public readonly registeredAfter?: Date,
|
|
) {}
|
|
}
|
|
|
|
class User {
|
|
constructor(
|
|
private readonly id: UserId,
|
|
private email: Email,
|
|
private name: string,
|
|
) {}
|
|
|
|
getId(): UserId {
|
|
return this.id
|
|
}
|
|
|
|
getEmail(): Email {
|
|
return this.email
|
|
}
|
|
|
|
getName(): string {
|
|
return this.name
|
|
}
|
|
}
|