-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
53 lines (47 loc) · 1.96 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import * as readLine from 'readline';
import { QueryController } from "./controllers/QueryController";
import { KVStore } from "./models/KVStore";
import { AttributeRepository } from "./repository/AttributeRepository";
import { DeleteService } from "./services/DeleteService";
import { PutService } from "./services/PutService";
import { SearchService } from "./services/SearchService";
import { DeleteFullKeyStrategy } from "./strategy/delete/DeleteFullKeyStrategy";
import { FullReplacementStrategy } from "./strategy/put/FullReplacementStrategy";
import { SearchKeyValueStrategy } from "./strategy/search/SearchKeyValueStrategy";
import { SearchKeyCommaSeperatedTransformer } from "./strategy/search/transformers/SearchKeyCommaSeperatedTransformer";
let kvStore = new KVStore();
let attributeRepository = new AttributeRepository();
let searchStrategy = new SearchKeyValueStrategy(kvStore);
let searchTransformStrategy = new SearchKeyCommaSeperatedTransformer();
let putStrategy = new FullReplacementStrategy(kvStore, attributeRepository);
let deleteStrategy = new DeleteFullKeyStrategy(kvStore);
let searchService = new SearchService(searchStrategy, searchTransformStrategy);
let putService = new PutService(putStrategy);
let deleteService = new DeleteService(deleteStrategy);
let controller = new QueryController(searchService, putService, deleteService);
// Command Line Input from user
let rl = readLine.createInterface(process.stdin, process.stdout);
rl.prompt();
let commands: string[]= []
function processCommands(commands: string[]){
for(let command of commands){
try {
let response = controller.query(command);
if(response!==''){
console.log(response);
}
} catch (error: any) {
console.log(error.message)
}
}
process.exit(0)
}
rl.on('line', function(line){
if(line === 'exit'){
rl.close();
}
commands.push(line)
rl.prompt()
}).on('close', function(){
processCommands(commands)
})