FilesRegister.js
1.99 KB
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
54
55
56
57
58
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var FilesRegister = /** @class */ (function () {
function FilesRegister(dataFactory) {
this.dataFactory = dataFactory;
this.files = {};
this.dataFactory = dataFactory;
}
FilesRegister.prototype.keys = function () {
return Object.keys(this.files);
};
FilesRegister.prototype.add = function (filePath) {
this.files[filePath] = {
mtime: undefined,
data: this.dataFactory(undefined)
};
};
FilesRegister.prototype.remove = function (filePath) {
if (this.has(filePath)) {
delete this.files[filePath];
}
};
FilesRegister.prototype.has = function (filePath) {
return this.files.hasOwnProperty(filePath);
};
FilesRegister.prototype.get = function (filePath) {
if (!this.has(filePath)) {
throw new Error('File "' + filePath + '" not found in register.');
}
return this.files[filePath];
};
FilesRegister.prototype.ensure = function (filePath) {
if (!this.has(filePath)) {
this.add(filePath);
}
};
FilesRegister.prototype.getData = function (filePath) {
return this.get(filePath).data;
};
FilesRegister.prototype.mutateData = function (filePath, mutator) {
this.ensure(filePath);
mutator(this.files[filePath].data);
};
FilesRegister.prototype.getMtime = function (filePath) {
return this.get(filePath).mtime;
};
FilesRegister.prototype.setMtime = function (filePath, mtime) {
this.ensure(filePath);
if (this.files[filePath].mtime !== mtime) {
this.files[filePath].mtime = mtime;
// file has been changed - we have to reset data
this.files[filePath].data = this.dataFactory(this.files[filePath].data);
}
};
return FilesRegister;
}());
exports.FilesRegister = FilesRegister;
//# sourceMappingURL=FilesRegister.js.map