fetch-json-cache 0.1.9 → 0.1.12
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/lib/get.js +1 -1
- package/lib/getAsync.js +13 -0
- package/{index.js → lib/index.js} +9 -3
- package/package.json +17 -15
package/lib/get.js
CHANGED
|
@@ -20,7 +20,7 @@ module.exports = function getCache(endpoint, callback) {
|
|
|
20
20
|
get(endpoint).head(function (err, res) {
|
|
21
21
|
// not accessible
|
|
22
22
|
if (err) {
|
|
23
|
-
if (err.code === 'ENOTFOUND' || err.message.indexOf(
|
|
23
|
+
if (err.code === 'ENOTFOUND' || err.message.indexOf('routines:SSL23_GET_SERVER_HELLO') >= 0) return callback(null, record.body);
|
|
24
24
|
return callback(err);
|
|
25
25
|
}
|
|
26
26
|
if (res.headers.etag === record.headers.etag) return callback(null, record.body);
|
package/lib/getAsync.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
|
|
4
|
+
module.exports = function getCacheAsync(endpoint) {
|
|
5
|
+
var fullPath = path.join(this.cacheDirectory, this.options.hash(endpoint) + '.json');
|
|
6
|
+
try {
|
|
7
|
+
var contents = fs.readFileSync(fullPath, 'utf8');
|
|
8
|
+
var record = JSON.parse(contents.toString());
|
|
9
|
+
return record.body;
|
|
10
|
+
} catch (err) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
var rimraf = require('rimraf');
|
|
2
2
|
|
|
3
|
-
var get = require('./
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var get = require('./get');
|
|
4
|
+
var getAsync = require('./getAsync');
|
|
5
|
+
var hash = require('./hash');
|
|
6
|
+
var update = require('./update');
|
|
6
7
|
|
|
7
8
|
function Cache(cacheDirectory, options) {
|
|
8
9
|
if (!(this instanceof Cache)) return new Cache(cacheDirectory, options);
|
|
@@ -28,6 +29,11 @@ Cache.prototype.get = function (endpoint, options, callback) {
|
|
|
28
29
|
});
|
|
29
30
|
};
|
|
30
31
|
|
|
32
|
+
Cache.prototype.getAsync = function (endpoint, options) {
|
|
33
|
+
// TODO: add async fetching
|
|
34
|
+
return getAsync.call(this, endpoint);
|
|
35
|
+
};
|
|
36
|
+
|
|
31
37
|
Cache.prototype.clear = function (callback) {
|
|
32
38
|
var self = this;
|
|
33
39
|
if (typeof callback === 'function')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fetch-json-cache",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Caches fetched json. Updates when etag changes and is uses cache regardless if endpoint unreachable. Uses write-file-atomic for safe updates",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"every",
|
|
@@ -15,33 +15,35 @@
|
|
|
15
15
|
},
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"author": "Kevin Malakoff <kmalakoff@gmail.com> (https://github.com/kmalakoff)",
|
|
18
|
-
"main": "index.js",
|
|
18
|
+
"main": "lib/index.js",
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
19
22
|
"scripts": {
|
|
20
23
|
"format": "prettier --write .",
|
|
21
24
|
"lint": "eslint .",
|
|
22
25
|
"prepublishOnly": "dtd \"npm run lint\" \"depcheck\"",
|
|
23
|
-
"test": "mocha-compat test/spec/**/*.test.js"
|
|
26
|
+
"test": "mocha-compat test/spec/**/*.test.js --no-timeouts"
|
|
24
27
|
},
|
|
25
28
|
"dependencies": {
|
|
26
|
-
"get-remote": "^0.6.
|
|
29
|
+
"get-remote": "^0.6.3",
|
|
27
30
|
"mkpath": "^1.0.0",
|
|
28
31
|
"rimraf": "^2.7.1",
|
|
29
32
|
"write-file-atomic": "^1.3.4"
|
|
30
33
|
},
|
|
31
34
|
"devDependencies": {
|
|
32
|
-
"
|
|
33
|
-
"depcheck": "^1.4.
|
|
34
|
-
"dis-dat": "^0.1.
|
|
35
|
-
"eslint": "^
|
|
36
|
-
"eslint-config-prettier": "^
|
|
37
|
-
"eslint-config-standard": "^
|
|
38
|
-
"eslint-plugin-import": "^2.
|
|
39
|
-
"eslint-plugin-
|
|
40
|
-
"eslint-plugin-promise": "^
|
|
41
|
-
"eslint-plugin-standard": "^4.0.1",
|
|
35
|
+
"@typescript-eslint/parser": "^5.30.0",
|
|
36
|
+
"depcheck": "^1.4.3",
|
|
37
|
+
"dis-dat": "^0.1.7",
|
|
38
|
+
"eslint": "^8.18.0",
|
|
39
|
+
"eslint-config-prettier": "^8.5.0",
|
|
40
|
+
"eslint-config-standard": "^17.0.0",
|
|
41
|
+
"eslint-plugin-import": "^2.26.0",
|
|
42
|
+
"eslint-plugin-n": "^15.2.3",
|
|
43
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
42
44
|
"fs-access-sync-compat": "^1.0.1",
|
|
43
45
|
"mocha-compat": "^3.5.5",
|
|
44
|
-
"prettier": "^2.
|
|
46
|
+
"prettier": "^2.7.1"
|
|
45
47
|
},
|
|
46
48
|
"engines": {
|
|
47
49
|
"node": ">=0.8"
|