1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | class FilesRegister {
|
4 | constructor(dataFactory) {
|
5 | this.dataFactory = dataFactory;
|
6 | this.files = {};
|
7 | this.dataFactory = dataFactory;
|
8 | }
|
9 | keys() {
|
10 | return Object.keys(this.files);
|
11 | }
|
12 | add(filePath) {
|
13 | this.files[filePath] = {
|
14 | mtime: undefined,
|
15 | data: this.dataFactory(undefined)
|
16 | };
|
17 | }
|
18 | remove(filePath) {
|
19 | if (this.has(filePath)) {
|
20 | delete this.files[filePath];
|
21 | }
|
22 | }
|
23 | has(filePath) {
|
24 | return this.files.hasOwnProperty(filePath);
|
25 | }
|
26 | get(filePath) {
|
27 | if (!this.has(filePath)) {
|
28 | throw new Error('File "' + filePath + '" not found in register.');
|
29 | }
|
30 | return this.files[filePath];
|
31 | }
|
32 | ensure(filePath) {
|
33 | if (!this.has(filePath)) {
|
34 | this.add(filePath);
|
35 | }
|
36 | }
|
37 | getData(filePath) {
|
38 | return this.get(filePath).data;
|
39 | }
|
40 | mutateData(filePath, mutator) {
|
41 | this.ensure(filePath);
|
42 | mutator(this.files[filePath].data);
|
43 | }
|
44 | getMtime(filePath) {
|
45 | return this.get(filePath).mtime;
|
46 | }
|
47 | setMtime(filePath, mtime) {
|
48 | this.ensure(filePath);
|
49 | if (this.files[filePath].mtime !== mtime) {
|
50 | this.files[filePath].mtime = mtime;
|
51 |
|
52 | this.files[filePath].data = this.dataFactory(this.files[filePath].data);
|
53 | }
|
54 | }
|
55 | }
|
56 | exports.FilesRegister = FilesRegister;
|
57 |
|
\ | No newline at end of file |