fetch-json-cache 0.1.10 → 0.2.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/lib/get.js +1 -1
- package/lib/getSync.js +13 -0
- package/{index.js → lib/index.js} +10 -3
- package/lib/polyfills.js +1 -0
- package/package.json +18 -18
- package/.github/dependabot.yml +0 -11
- package/.github/workflows/main.yml +0 -22
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/getSync.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,10 @@
|
|
|
1
|
+
require('./polyfills')
|
|
1
2
|
var rimraf = require('rimraf');
|
|
2
3
|
|
|
3
|
-
var get = require('./
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var get = require('./get');
|
|
5
|
+
var getSync = require('./getSync');
|
|
6
|
+
var hash = require('./hash');
|
|
7
|
+
var update = require('./update');
|
|
6
8
|
|
|
7
9
|
function Cache(cacheDirectory, options) {
|
|
8
10
|
if (!(this instanceof Cache)) return new Cache(cacheDirectory, options);
|
|
@@ -28,6 +30,11 @@ Cache.prototype.get = function (endpoint, options, callback) {
|
|
|
28
30
|
});
|
|
29
31
|
};
|
|
30
32
|
|
|
33
|
+
Cache.prototype.getSync = function (endpoint, options) {
|
|
34
|
+
// TODO: add async fetching
|
|
35
|
+
return getSync.call(this, endpoint);
|
|
36
|
+
};
|
|
37
|
+
|
|
31
38
|
Cache.prototype.clear = function (callback) {
|
|
32
39
|
var self = this;
|
|
33
40
|
if (typeof callback === 'function')
|
package/lib/polyfills.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require('es6-promise/auto');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fetch-json-cache",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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,35 +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
|
-
"prepublishOnly": "
|
|
23
|
-
"test": "mocha-compat test/spec/**/*.test.js"
|
|
24
|
-
"test:engines": "nvu engines npm test"
|
|
25
|
+
"prepublishOnly": "npm run lint && depcheck",
|
|
26
|
+
"test": "mocha-compat test/spec/**/*.test.js --no-timeouts"
|
|
25
27
|
},
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"
|
|
29
|
+
"es6-promise": "^4.2.8",
|
|
30
|
+
"get-remote": "^0.7.0",
|
|
28
31
|
"mkpath": "^1.0.0",
|
|
29
32
|
"rimraf": "^2.7.1",
|
|
30
33
|
"write-file-atomic": "^1.3.4"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
33
|
-
"
|
|
34
|
-
"depcheck": "^1.4.
|
|
35
|
-
"
|
|
36
|
-
"eslint": "^
|
|
37
|
-
"eslint-config-
|
|
38
|
-
"eslint-
|
|
39
|
-
"eslint-plugin-
|
|
40
|
-
"eslint-plugin-
|
|
41
|
-
"eslint-plugin-promise": "^4.2.1",
|
|
42
|
-
"eslint-plugin-standard": "^4.0.1",
|
|
36
|
+
"@typescript-eslint/parser": "^5.30.7",
|
|
37
|
+
"depcheck": "^1.4.3",
|
|
38
|
+
"eslint": "^8.20.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.4",
|
|
43
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
43
44
|
"fs-access-sync-compat": "^1.0.1",
|
|
44
45
|
"mocha-compat": "^3.5.5",
|
|
45
|
-
"
|
|
46
|
-
"prettier": "^2.4.1"
|
|
46
|
+
"prettier": "^2.7.1"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">=0.8"
|
package/.github/dependabot.yml
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
on:
|
|
3
|
-
- push
|
|
4
|
-
- pull_request
|
|
5
|
-
jobs:
|
|
6
|
-
test:
|
|
7
|
-
name: Node.js ${{ matrix.node-version }} ${{ matrix.os }}
|
|
8
|
-
runs-on: ${{ matrix.os }}
|
|
9
|
-
strategy:
|
|
10
|
-
matrix:
|
|
11
|
-
node: ['latest']
|
|
12
|
-
os: [ubuntu-latest, windows-latest, macOS-latest]
|
|
13
|
-
steps:
|
|
14
|
-
- uses: actions/checkout@v2
|
|
15
|
-
- uses: actions/setup-node@v2.4.1
|
|
16
|
-
with:
|
|
17
|
-
node-version: ${{ matrix.node-version }}
|
|
18
|
-
- run: git config --global user.name "Github Actions"
|
|
19
|
-
- run: git config --global user.email "actions@users.noreply.github.com"
|
|
20
|
-
- run: npm ci
|
|
21
|
-
- run: npm run lint
|
|
22
|
-
- run: npm run test:engines
|