File tree Expand file tree Collapse file tree 5 files changed +77
-3
lines changed Expand file tree Collapse file tree 5 files changed +77
-3
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"root" : true ,
3
- "extends" : " @index-san/eslint-config/ts"
3
+ "extends" : " @index-san/eslint-config/ts" ,
4
+ "overrides" : [
5
+ {
6
+ "files" : [" playground/*.ts" ],
7
+ "rules" : {
8
+ "no-console" : " off"
9
+ }
10
+ }
11
+ ]
4
12
}
Original file line number Diff line number Diff line change @@ -7,6 +7,12 @@ const hash = new PlayHash()
7
7
8
8
const app = new ChronoApp ( drive , hash )
9
9
10
- // app.init()
10
+ async function run ( ) {
11
+ // app.init()
11
12
12
- app . hashFile ( 'message.md' )
13
+ // app.hashFile('message.md')
14
+
15
+ console . log ( await app . catFile ( '1cd0ff195e53a0a31601aae77b23e20e63f6d244' ) )
16
+ }
17
+
18
+ run ( )
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import BlobRepositoryImpl from './repositories/BlobRepositoryImpl'
4
4
import IBlobRepository from './repositories/IBlobRepository'
5
5
import IObjectRepository from './repositories/IObjectRepository'
6
6
import ObjectRepositoryImpl from './repositories/ObjectRepositoryImpl'
7
+ import CatFileUseCase from './use-cases/CatFileUseCase'
7
8
import HashFileUseCase from './use-cases/HashFileUseCase'
8
9
import InitUseCase from './use-cases/InitUseCase'
9
10
@@ -30,4 +31,10 @@ export default class ChronoApp {
30
31
31
32
await useCase . execute ( { path } )
32
33
}
34
+
35
+ public async catFile ( objectHash : string ) {
36
+ const useCase = new CatFileUseCase ( this . objectRepository )
37
+
38
+ return await useCase . execute ( { objectHash } )
39
+ }
33
40
}
Original file line number Diff line number Diff line change
1
+ import { test , expect , describe } from 'vitest'
2
+ import InMemoryDrive from '../__tests__/InMemoryDrive'
3
+ import HelperService from '../services/HelperService'
4
+ import CatFileUseCase from './CatFileUseCase'
5
+ import InMemoryHash from '../__tests__/InMemoryHash'
6
+ import ObjectRepositoryImpl from '../repositories/ObjectRepositoryImpl'
7
+ import ChronoObject from '../entities/ChronoObject'
8
+
9
+ const drive = new InMemoryDrive ( )
10
+ const hash = new InMemoryHash ( )
11
+ const objectRepository = new ObjectRepositoryImpl ( drive , hash )
12
+
13
+ const useCase = new CatFileUseCase ( objectRepository )
14
+
15
+ describe ( 'CatFileUseCase' , ( ) => {
16
+ test ( 'should return chrono object' , async ( ) => {
17
+ await drive . write ( 'message.md' , HelperService . encode ( 'Hello World!' ) )
18
+
19
+ const { objectHash } = await objectRepository . save (
20
+ new ChronoObject ( {
21
+ type : 'blob' ,
22
+ blobHash : '123' ,
23
+ } )
24
+ )
25
+
26
+ const result = await useCase . execute ( { objectHash } )
27
+
28
+ expect ( result ) . toEqual ( {
29
+ type : 'blob' ,
30
+ blobHash : '123' ,
31
+ } )
32
+ } )
33
+ } )
Original file line number Diff line number Diff line change
1
+ import BaseException from '../exceptions/BaseException'
2
+ import IObjectRepository from '../repositories/IObjectRepository'
3
+
4
+ interface CatUseCaseParams {
5
+ objectHash : string
6
+ }
7
+
8
+ export default class CatFileUseCase {
9
+ constructor ( private readonly objectRepository : IObjectRepository ) { }
10
+
11
+ async execute ( { objectHash } : CatUseCaseParams ) {
12
+ const object = await this . objectRepository . find ( objectHash )
13
+
14
+ if ( ! object ) {
15
+ throw new BaseException ( `Object ${ objectHash } not found` )
16
+ }
17
+
18
+ return object
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments