Skip to content

Commit 2a6f19e

Browse files
committed
feat: add HashEntryService
1 parent e52a859 commit 2a6f19e

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

packages/chrono/src/use-cases/HashFileUseCase.ts renamed to packages/chrono/src/services/HashEntryService.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import IDrive from '../gateways/IDrive'
55
import IBlobRepository from '../repositories/IBlobRepository'
66
import IObjectRepository from '../repositories/IObjectRepository'
77

8-
interface Params {
9-
path: string
10-
}
11-
12-
export default class HashFileUseCase {
8+
export default class HashEntryService {
139
constructor(
1410
private readonly drive: IDrive,
1511
private readonly objectRepository: IObjectRepository,
@@ -43,7 +39,7 @@ export default class HashFileUseCase {
4339

4440
const isFile = await this.drive.isFile(entryPath)
4541

46-
const result = await this.execute({ path: entryPath })
42+
const result = await this.hashEntry(entryPath)
4743

4844
treeEntries.push({
4945
path: entry,
@@ -57,7 +53,7 @@ export default class HashFileUseCase {
5753
return this.objectRepository.save(tree)
5854
}
5955

60-
public async execute({ path }: Params) {
56+
public async hashEntry(path: string) {
6157
if (!(await this.drive.exists(path))) {
6258
throw new BaseException('File not found')
6359
}

packages/chrono/src/use-cases/HashFileUseCase.spec.ts renamed to packages/chrono/src/use-cases/HashEntryUseCase.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test, expect, describe } from 'vitest'
22
import InMemoryDrive from '../__tests__/InMemoryDrive'
33
import HelperService from '../services/HelperService'
4-
import HashFileUseCase from './HashFileUseCase'
4+
import HashEntryUseCase from './HashEntryUseCase'
55
import InMemoryHash from '../__tests__/InMemoryHash'
66
import LocalObjectRepository from '../repositories/implementations/LocalObjectRepository'
77
import LocalBlobRepository from '../repositories/implementations/LocalBlobRepository'
@@ -11,9 +11,9 @@ const hash = new InMemoryHash()
1111
const objectRepository = new LocalObjectRepository(drive, hash)
1212
const blobRepository = new LocalBlobRepository(drive, hash)
1313

14-
const useCase = new HashFileUseCase(drive, objectRepository, blobRepository)
14+
const useCase = new HashEntryUseCase(drive, objectRepository, blobRepository)
1515

16-
describe('HashFileUseCase', () => {
16+
describe('HashEntryUseCase', () => {
1717
test('should save a file object', async () => {
1818
const messageContent = HelperService.encode('Hello World!')
1919

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import IDrive from '../gateways/IDrive'
2+
import IBlobRepository from '../repositories/IBlobRepository'
3+
import IObjectRepository from '../repositories/IObjectRepository'
4+
import HashEntryService from '../services/HashEntryService'
5+
6+
interface Params {
7+
path: string
8+
}
9+
10+
export default class HashEntryUseCase {
11+
constructor(
12+
private readonly drive: IDrive,
13+
private readonly objectRepository: IObjectRepository,
14+
private readonly blobRepository: IBlobRepository
15+
) {}
16+
17+
public async execute({ path }: Params) {
18+
const service = new HashEntryService(this.drive, this.objectRepository, this.blobRepository)
19+
20+
return await service.hashEntry(path)
21+
}
22+
}

0 commit comments

Comments
 (0)