flat-cache 3.0.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +4 -2
- package/changelog.md +5 -0
- package/package.json +15 -11
- package/src/cache.js +23 -2
- package/src/del.js +13 -0
- package/src/utils.js +44 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# flat-cache
|
|
2
2
|
> A stupidly simple key/value storage using files to persist the data
|
|
3
3
|
|
|
4
|
-
[](https://npmjs.org/package/flat-cache)
|
|
5
|
+
[](https://github.com/jaredwray/flat-cache/actions/workflows/tests.yaml)
|
|
6
|
+
[](https://codecov.io/github/jaredwray/flat-cache)
|
|
7
|
+
[](https://npmjs.com/package/flat-cache)
|
|
6
8
|
|
|
7
9
|
## install
|
|
8
10
|
|
package/changelog.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
# flat-cache - Changelog
|
|
3
|
+
## v3.0.4
|
|
4
|
+
- **Refactoring**
|
|
5
|
+
- add files by name to the list of exported files - [89a2698]( https://github.com/royriojas/flat-cache/commit/89a2698 ), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 02:35:39
|
|
6
|
+
|
|
7
|
+
|
|
3
8
|
## v3.0.3
|
|
4
9
|
- **Bug Fixes**
|
|
5
10
|
- Fix wrong eslint command - [f268e42]( https://github.com/royriojas/flat-cache/commit/f268e42 ), [Roy Riojas](https://github.com/Roy Riojas), 08/11/2020 02:15:04
|
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flat-cache",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "A stupidly simple key/value storage using files to persist some data",
|
|
5
|
-
"repository": "
|
|
5
|
+
"repository": "jaredwray/flat-cache",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": {
|
|
8
|
-
"name": "
|
|
9
|
-
"url": "
|
|
8
|
+
"name": "Jared Wray",
|
|
9
|
+
"url": "https://jaredwray.com"
|
|
10
10
|
},
|
|
11
11
|
"main": "src/cache.js",
|
|
12
12
|
"files": [
|
|
13
|
-
"
|
|
13
|
+
"src/cache.js",
|
|
14
|
+
"src/del.js",
|
|
15
|
+
"src/utils.js"
|
|
14
16
|
],
|
|
15
17
|
"engines": {
|
|
16
|
-
"node": "
|
|
18
|
+
"node": ">=12.0.0"
|
|
17
19
|
},
|
|
18
20
|
"precommit": [
|
|
19
21
|
"npm run verify --silent"
|
|
@@ -35,7 +37,8 @@
|
|
|
35
37
|
"bump-major": "npm run pre-v && npm version major -m 'BLD: Release v%s' && npm run post-v",
|
|
36
38
|
"bump-minor": "npm run pre-v && npm version minor -m 'BLD: Release v%s' && npm run post-v",
|
|
37
39
|
"bump-patch": "npm run pre-v && npm version patch -m 'BLD: Release v%s' && npm run post-v",
|
|
38
|
-
"test:cache": "mocha -R spec test/specs",
|
|
40
|
+
"test:cache": "c8 mocha -R spec test/specs",
|
|
41
|
+
"test:ci:cache": "c8 --reporter=lcov mocha -R spec test/specs",
|
|
39
42
|
"test": "npm run verify --silent",
|
|
40
43
|
"cover": "istanbul cover test/runner.js html text-summary",
|
|
41
44
|
"watch": "watch-run -i -p 'test/specs/**/*.js' istanbul cover test/runner.js html text-summary"
|
|
@@ -61,22 +64,23 @@
|
|
|
61
64
|
"projectName": "flat-cache"
|
|
62
65
|
},
|
|
63
66
|
"devDependencies": {
|
|
64
|
-
"
|
|
67
|
+
"c8": "^8.0.1",
|
|
68
|
+
"chai": "^4.3.7",
|
|
65
69
|
"changelogx": "^5.0.6",
|
|
66
70
|
"eslint": "^7.13.0",
|
|
67
71
|
"eslint-config-prettier": "^6.15.0",
|
|
68
72
|
"eslint-plugin-mocha": "^8.0.0",
|
|
69
73
|
"eslint-plugin-prettier": "^3.1.4",
|
|
70
74
|
"glob-expand": "^0.2.1",
|
|
71
|
-
"
|
|
72
|
-
"mocha": "^8.2.1",
|
|
75
|
+
"mocha": "^10.2.0",
|
|
73
76
|
"precommit": "^1.2.2",
|
|
74
77
|
"prepush": "^3.1.11",
|
|
75
78
|
"prettier": "^2.1.2",
|
|
76
79
|
"watch-run": "^1.2.5"
|
|
77
80
|
},
|
|
78
81
|
"dependencies": {
|
|
79
|
-
"flatted": "^3.
|
|
82
|
+
"flatted": "^3.2.7",
|
|
83
|
+
"keyv": "^4.5.3",
|
|
80
84
|
"rimraf": "^3.0.2"
|
|
81
85
|
}
|
|
82
86
|
}
|
package/src/cache.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
var path = require('path');
|
|
2
2
|
var fs = require('fs');
|
|
3
|
+
var Keyv = require('keyv');
|
|
3
4
|
var utils = require('./utils');
|
|
4
5
|
var del = require('./del');
|
|
5
6
|
var writeJSON = utils.writeJSON;
|
|
@@ -17,8 +18,10 @@ var cache = {
|
|
|
17
18
|
load: function (docId, cacheDir) {
|
|
18
19
|
var me = this;
|
|
19
20
|
|
|
20
|
-
me.
|
|
21
|
-
|
|
21
|
+
me.keyv = new Keyv();
|
|
22
|
+
|
|
23
|
+
me.__visited = {};
|
|
24
|
+
me.__persisted = {};
|
|
22
25
|
me._pathToFile = cacheDir ? path.resolve(cacheDir, docId) : path.resolve(__dirname, '../.cache/', docId);
|
|
23
26
|
|
|
24
27
|
if (fs.existsSync(me._pathToFile)) {
|
|
@@ -26,6 +29,24 @@ var cache = {
|
|
|
26
29
|
}
|
|
27
30
|
},
|
|
28
31
|
|
|
32
|
+
get _persisted() {
|
|
33
|
+
return this.__persisted;
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
set _persisted(value) {
|
|
37
|
+
this.__persisted = value;
|
|
38
|
+
this.keyv.set('persisted', value);
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
get _visited() {
|
|
42
|
+
return this.__visited;
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
set _visited(value) {
|
|
46
|
+
this.__visited = value;
|
|
47
|
+
this.keyv.set('visited', value);
|
|
48
|
+
},
|
|
49
|
+
|
|
29
50
|
/**
|
|
30
51
|
* Load the cache from the provided file
|
|
31
52
|
* @method loadFile
|
package/src/del.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var rimraf = require('rimraf').sync;
|
|
2
|
+
var fs = require('fs');
|
|
3
|
+
|
|
4
|
+
module.exports = function del(file) {
|
|
5
|
+
if (fs.existsSync(file)) {
|
|
6
|
+
//if rimraf doesn't throw then the file has been deleted or didn't exist
|
|
7
|
+
rimraf(file, {
|
|
8
|
+
glob: false,
|
|
9
|
+
});
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
};
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
var flatted = require('flatted');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
tryParse: function (filePath, defaultValue) {
|
|
7
|
+
var result;
|
|
8
|
+
try {
|
|
9
|
+
result = this.readJSON(filePath);
|
|
10
|
+
} catch (ex) {
|
|
11
|
+
result = defaultValue;
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Read json file synchronously using flatted
|
|
18
|
+
*
|
|
19
|
+
* @method readJSON
|
|
20
|
+
* @param {String} filePath Json filepath
|
|
21
|
+
* @returns {*} parse result
|
|
22
|
+
*/
|
|
23
|
+
readJSON: function (filePath) {
|
|
24
|
+
return flatted.parse(
|
|
25
|
+
fs.readFileSync(filePath, {
|
|
26
|
+
encoding: 'utf8',
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Write json file synchronously using circular-json
|
|
33
|
+
*
|
|
34
|
+
* @method writeJSON
|
|
35
|
+
* @param {String} filePath Json filepath
|
|
36
|
+
* @param {*} data Object to serialize
|
|
37
|
+
*/
|
|
38
|
+
writeJSON: function (filePath, data) {
|
|
39
|
+
fs.mkdirSync(path.dirname(filePath), {
|
|
40
|
+
recursive: true,
|
|
41
|
+
});
|
|
42
|
+
fs.writeFileSync(filePath, flatted.stringify(data));
|
|
43
|
+
},
|
|
44
|
+
};
|