fetch-json-cache 1.2.52 → 1.2.54
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/dist/cjs/Cache.d.cts +9 -0
- package/dist/cjs/Cache.d.ts +9 -0
- package/dist/cjs/Cache.js +83 -0
- package/dist/cjs/Cache.js.map +1 -0
- package/dist/cjs/get.d.cts +2 -1
- package/dist/cjs/get.d.ts +2 -1
- package/dist/cjs/get.js.map +1 -1
- package/dist/cjs/getSync.d.cts +1 -1
- package/dist/cjs/getSync.d.ts +1 -1
- package/dist/cjs/getSync.js.map +1 -1
- package/dist/cjs/hash.d.cts +1 -1
- package/dist/cjs/hash.d.ts +1 -1
- package/dist/cjs/hash.js.map +1 -1
- package/dist/cjs/index.d.cts +2 -16
- package/dist/cjs/index.d.ts +2 -16
- package/dist/cjs/index.js +15 -67
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types.d.cts +8 -0
- package/dist/cjs/types.d.ts +8 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/Cache.d.ts +9 -0
- package/dist/esm/Cache.js +43 -0
- package/dist/esm/Cache.js.map +1 -0
- package/dist/esm/get.d.ts +2 -1
- package/dist/esm/get.js.map +1 -1
- package/dist/esm/getSync.d.ts +1 -1
- package/dist/esm/getSync.js.map +1 -1
- package/dist/esm/hash.d.ts +1 -1
- package/dist/esm/hash.js.map +1 -1
- package/dist/esm/index.d.ts +2 -16
- package/dist/esm/index.js +2 -43
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.d.ts +8 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CacheOptions, ClearCallback, GetCallback, GetOptions } from './types.ts';
|
|
2
|
+
export default class Cache {
|
|
3
|
+
cachePath: string;
|
|
4
|
+
options: CacheOptions;
|
|
5
|
+
constructor(cachePath: string, options?: CacheOptions);
|
|
6
|
+
get(endpoint: string, options?: GetOptions | GetCallback, callback?: GetCallback): undefined | Promise<object | null>;
|
|
7
|
+
getSync(endpoint: string): object | null;
|
|
8
|
+
clear(callback?: ClearCallback): undefined | Promise<undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CacheOptions, ClearCallback, GetCallback, GetOptions } from './types.ts';
|
|
2
|
+
export default class Cache {
|
|
3
|
+
cachePath: string;
|
|
4
|
+
options: CacheOptions;
|
|
5
|
+
constructor(cachePath: string, options?: CacheOptions);
|
|
6
|
+
get(endpoint: string, options?: GetOptions | GetCallback, callback?: GetCallback): undefined | Promise<object | null>;
|
|
7
|
+
getSync(endpoint: string): object | null;
|
|
8
|
+
clear(callback?: ClearCallback): undefined | Promise<undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Cache;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _rimraf2 = /*#__PURE__*/ _interop_require_default(require("rimraf2"));
|
|
12
|
+
var _getts = /*#__PURE__*/ _interop_require_default(require("./get.js"));
|
|
13
|
+
var _getSyncts = /*#__PURE__*/ _interop_require_default(require("./getSync.js"));
|
|
14
|
+
var _hashts = /*#__PURE__*/ _interop_require_default(require("./hash.js"));
|
|
15
|
+
var _updatets = /*#__PURE__*/ _interop_require_default(require("./update.js"));
|
|
16
|
+
function _class_call_check(instance, Constructor) {
|
|
17
|
+
if (!(instance instanceof Constructor)) {
|
|
18
|
+
throw new TypeError("Cannot call a class as a function");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function _instanceof(left, right) {
|
|
22
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
23
|
+
return !!right[Symbol.hasInstance](left);
|
|
24
|
+
} else {
|
|
25
|
+
return left instanceof right;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function _interop_require_default(obj) {
|
|
29
|
+
return obj && obj.__esModule ? obj : {
|
|
30
|
+
default: obj
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
var Cache = /*#__PURE__*/ function() {
|
|
34
|
+
"use strict";
|
|
35
|
+
function Cache(cachePath) {
|
|
36
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
37
|
+
_class_call_check(this, Cache);
|
|
38
|
+
if (!_instanceof(this, Cache)) throw new Error('Cache needs to be called with new');
|
|
39
|
+
if (!cachePath) throw new Error('Cache needs cachePath');
|
|
40
|
+
this.cachePath = cachePath;
|
|
41
|
+
this.options = options;
|
|
42
|
+
if (!this.options.hash) this.options.hash = _hashts.default;
|
|
43
|
+
}
|
|
44
|
+
var _proto = Cache.prototype;
|
|
45
|
+
_proto.get = function get(endpoint, options, callback) {
|
|
46
|
+
var _this = this;
|
|
47
|
+
if (typeof options === 'function') {
|
|
48
|
+
callback = options;
|
|
49
|
+
options = null;
|
|
50
|
+
}
|
|
51
|
+
options = options || {};
|
|
52
|
+
function worker(endpoint, options, callback) {
|
|
53
|
+
options.force ? _updatets.default.call(this, endpoint, callback) : _getts.default.call(this, endpoint, callback);
|
|
54
|
+
}
|
|
55
|
+
if (typeof callback === 'function') return worker.call(this, endpoint, options, callback);
|
|
56
|
+
return new Promise(function(resolve, reject) {
|
|
57
|
+
return worker.call(_this, endpoint, options, function(err, json) {
|
|
58
|
+
return err ? reject(err) : resolve(json);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
_proto.getSync = function getSync(endpoint) {
|
|
63
|
+
// TODO: add async fetching
|
|
64
|
+
return _getSyncts.default.call(this, endpoint);
|
|
65
|
+
};
|
|
66
|
+
_proto.clear = function clear(callback) {
|
|
67
|
+
var _this = this;
|
|
68
|
+
function worker(callback) {
|
|
69
|
+
// ignore errors since it is fine to delete a directory that doesn't exist from a cache standpoint
|
|
70
|
+
(0, _rimraf2.default)(this.cachePath, {
|
|
71
|
+
disableGlob: true
|
|
72
|
+
}, callback.bind(null, null));
|
|
73
|
+
}
|
|
74
|
+
if (typeof callback === 'function') return worker.call(this, callback);
|
|
75
|
+
return new Promise(function(resolve, reject) {
|
|
76
|
+
return worker.call(_this, function(err) {
|
|
77
|
+
err ? reject(err) : resolve(undefined);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
return Cache;
|
|
82
|
+
}();
|
|
83
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/Cache.ts"],"sourcesContent":["import rimraf2 from 'rimraf2';\n\nimport get from './get.ts';\nimport getSync from './getSync.ts';\nimport hash from './hash.ts';\nimport type { CacheOptions, ClearCallback, GetCallback, GetOptions } from './types.ts';\nimport update from './update.ts';\n\nexport default class Cache {\n cachePath: string;\n options: CacheOptions;\n\n constructor(cachePath: string, options: CacheOptions = {}) {\n if (!(this instanceof Cache)) throw new Error('Cache needs to be called with new');\n if (!cachePath) throw new Error('Cache needs cachePath');\n this.cachePath = cachePath;\n this.options = options;\n if (!this.options.hash) this.options.hash = hash;\n }\n\n get(endpoint: string, options?: GetOptions | GetCallback, callback?: GetCallback): undefined | Promise<object | null> {\n if (typeof options === 'function') {\n callback = options as GetCallback;\n options = null;\n }\n options = options || {};\n\n function worker(endpoint, options, callback) {\n (options as GetOptions).force ? update.call(this, endpoint, callback) : get.call(this, endpoint, callback);\n }\n\n if (typeof callback === 'function') return worker.call(this, endpoint, options, callback) as undefined;\n return new Promise((resolve, reject) => worker.call(this, endpoint, options, (err, json) => (err ? reject(err) : resolve(json))));\n }\n\n getSync(endpoint: string): object | null {\n // TODO: add async fetching\n return getSync.call(this, endpoint);\n }\n\n clear(callback?: ClearCallback): undefined | Promise<undefined> {\n function worker(callback) {\n // ignore errors since it is fine to delete a directory that doesn't exist from a cache standpoint\n rimraf2(this.cachePath, { disableGlob: true }, callback.bind(null, null));\n }\n\n if (typeof callback === 'function') return worker.call(this, callback);\n return new Promise((resolve, reject) =>\n worker.call(this, (err) => {\n err ? reject(err) : resolve(undefined);\n })\n );\n }\n}\n"],"names":["Cache","cachePath","options","Error","hash","get","endpoint","callback","worker","force","update","call","Promise","resolve","reject","err","json","getSync","clear","rimraf2","disableGlob","bind","undefined"],"mappings":";;;;;;;eAQqBA;;;8DARD;4DAEJ;gEACI;6DACH;+DAEE;;;;;;;;;;;;;;;;;;AAEJ,IAAA,AAAMA,sBAAN;;aAAMA,MAIPC,SAAiB;YAAEC,UAAAA,iEAAwB,CAAC;gCAJrCF;QAKjB,IAAI,CAAE,AAAI,YAAJ,IAAI,EALOA,QAKa,MAAM,IAAIG,MAAM;QAC9C,IAAI,CAACF,WAAW,MAAM,IAAIE,MAAM;QAChC,IAAI,CAACF,SAAS,GAAGA;QACjB,IAAI,CAACC,OAAO,GAAGA;QACf,IAAI,CAAC,IAAI,CAACA,OAAO,CAACE,IAAI,EAAE,IAAI,CAACF,OAAO,CAACE,IAAI,GAAGA,eAAI;;iBAT/BJ;IAYnBK,OAAAA,GAaC,GAbDA,SAAAA,IAAIC,QAAgB,EAAEJ,OAAkC,EAAEK,QAAsB;;QAC9E,IAAI,OAAOL,YAAY,YAAY;YACjCK,WAAWL;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QAEtB,SAASM,OAAOF,QAAQ,EAAEJ,OAAO,EAAEK,QAAQ;YACxCL,QAAuBO,KAAK,GAAGC,iBAAM,CAACC,IAAI,CAAC,IAAI,EAAEL,UAAUC,YAAYF,cAAG,CAACM,IAAI,CAAC,IAAI,EAAEL,UAAUC;QACnG;QAEA,IAAI,OAAOA,aAAa,YAAY,OAAOC,OAAOG,IAAI,CAAC,IAAI,EAAEL,UAAUJ,SAASK;QAChF,OAAO,IAAIK,QAAQ,SAACC,SAASC;mBAAWN,OAAOG,IAAI,QAAOL,UAAUJ,SAAS,SAACa,KAAKC;uBAAUD,MAAMD,OAAOC,OAAOF,QAAQG;;;IAC3H;IAEAC,OAAAA,OAGC,GAHDA,SAAAA,QAAQX,QAAgB;QACtB,2BAA2B;QAC3B,OAAOW,kBAAO,CAACN,IAAI,CAAC,IAAI,EAAEL;IAC5B;IAEAY,OAAAA,KAYC,GAZDA,SAAAA,MAAMX,QAAwB;;QAC5B,SAASC,OAAOD,QAAQ;YACtB,kGAAkG;YAClGY,IAAAA,gBAAO,EAAC,IAAI,CAAClB,SAAS,EAAE;gBAAEmB,aAAa;YAAK,GAAGb,SAASc,IAAI,CAAC,MAAM;QACrE;QAEA,IAAI,OAAOd,aAAa,YAAY,OAAOC,OAAOG,IAAI,CAAC,IAAI,EAAEJ;QAC7D,OAAO,IAAIK,QAAQ,SAACC,SAASC;mBAC3BN,OAAOG,IAAI,QAAO,SAACI;gBACjBA,MAAMD,OAAOC,OAAOF,QAAQS;YAC9B;;IAEJ;WA5CmBtB"}
|
package/dist/cjs/get.d.cts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { GetCallback } from './types.ts';
|
|
2
|
+
export default function getCache(endpoint: string, callback: GetCallback): undefined;
|
package/dist/cjs/get.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { GetCallback } from './types.ts';
|
|
2
|
+
export default function getCache(endpoint: string, callback: GetCallback): undefined;
|
package/dist/cjs/get.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/get.ts"],"sourcesContent":["import fs from 'fs';\nimport get from 'get-remote';\nimport path from 'path';\n\nimport update from './update.ts';\n\ninterface GetError {\n code?: string;\n}\n\ninterface GetHeaders {\n etag?: string;\n}\n\nexport default function getCache(endpoint, callback) {\n const fullPath = path.join(this.cachePath, `${this.options.hash(endpoint)}.json`);\n fs.readFile(fullPath, (err, contents) => {\n // doesn't exist so create\n if (err) {\n update.call(this, endpoint, (err, json) => {\n err ? callback(err) : callback(null, json);\n });\n }\n // check existing if etag changed and if so, recache\n else {\n const record = JSON.parse(contents.toString());\n get(endpoint).head((err, res) => {\n // not accessible\n if (err) {\n if ((err as GetError).code === 'ENOTFOUND' || err.message.indexOf('routines:SSL23_GET_SERVER_HELLO') >= 0) return callback(null, record.body);\n return callback(err);\n }\n if ((res.headers as GetHeaders).etag === record.headers.etag) return callback(null, record.body);\n update.call(this, endpoint, (err, json) => {\n err ? callback(err) : callback(null, json);\n });\n });\n }\n });\n}\n"],"names":["getCache","endpoint","callback","fullPath","path","join","cachePath","options","hash","fs","readFile","err","contents","update","call","json","record","JSON","parse","toString","get","head","res","code","message","indexOf","body","headers","etag"],"mappings":";;;;+
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/get.ts"],"sourcesContent":["import fs from 'fs';\nimport get from 'get-remote';\nimport path from 'path';\n\nimport update from './update.ts';\n\ninterface GetError {\n code?: string;\n}\n\ninterface GetHeaders {\n etag?: string;\n}\n\nimport type { GetCallback } from './types.ts';\n\nexport default function getCache(endpoint: string, callback: GetCallback): undefined {\n const fullPath = path.join(this.cachePath, `${this.options.hash(endpoint)}.json`);\n fs.readFile(fullPath, (err, contents) => {\n // doesn't exist so create\n if (err) {\n update.call(this, endpoint, (err, json) => {\n err ? callback(err) : callback(null, json);\n });\n }\n // check existing if etag changed and if so, recache\n else {\n const record = JSON.parse(contents.toString());\n get(endpoint).head((err, res) => {\n // not accessible\n if (err) {\n if ((err as GetError).code === 'ENOTFOUND' || err.message.indexOf('routines:SSL23_GET_SERVER_HELLO') >= 0) return callback(null, record.body);\n return callback(err);\n }\n if ((res.headers as GetHeaders).etag === record.headers.etag) return callback(null, record.body);\n update.call(this, endpoint, (err, json) => {\n err ? callback(err) : callback(null, json);\n });\n });\n }\n });\n}\n"],"names":["getCache","endpoint","callback","fullPath","path","join","cachePath","options","hash","fs","readFile","err","contents","update","call","json","record","JSON","parse","toString","get","head","res","code","message","indexOf","body","headers","etag"],"mappings":";;;;+BAgBA;;;eAAwBA;;;yDAhBT;gEACC;2DACC;+DAEE;;;;;;AAYJ,SAASA,SAASC,QAAgB,EAAEC,QAAqB;;IACtE,IAAMC,WAAWC,aAAI,CAACC,IAAI,CAAC,IAAI,CAACC,SAAS,EAAE,AAAC,GAA8B,OAA5B,IAAI,CAACC,OAAO,CAACC,IAAI,CAACP,WAAU;IAC1EQ,WAAE,CAACC,QAAQ,CAACP,UAAU,SAACQ,KAAKC;QAC1B,0BAA0B;QAC1B,IAAID,KAAK;YACPE,iBAAM,CAACC,IAAI,QAAOb,UAAU,SAACU,KAAKI;gBAChCJ,MAAMT,SAASS,OAAOT,SAAS,MAAMa;YACvC;QACF,OAEK;YACH,IAAMC,SAASC,KAAKC,KAAK,CAACN,SAASO,QAAQ;YAC3CC,IAAAA,kBAAG,EAACnB,UAAUoB,IAAI,CAAC,SAACV,KAAKW;gBACvB,iBAAiB;gBACjB,IAAIX,KAAK;oBACP,IAAI,AAACA,IAAiBY,IAAI,KAAK,eAAeZ,IAAIa,OAAO,CAACC,OAAO,CAAC,sCAAsC,GAAG,OAAOvB,SAAS,MAAMc,OAAOU,IAAI;oBAC5I,OAAOxB,SAASS;gBAClB;gBACA,IAAI,AAACW,IAAIK,OAAO,CAAgBC,IAAI,KAAKZ,OAAOW,OAAO,CAACC,IAAI,EAAE,OAAO1B,SAAS,MAAMc,OAAOU,IAAI;gBAC/Fb,iBAAM,CAACC,IAAI,QAAOb,UAAU,SAACU,KAAKI;oBAChCJ,MAAMT,SAASS,OAAOT,SAAS,MAAMa;gBACvC;YACF;QACF;IACF;AACF"}
|
package/dist/cjs/getSync.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function getCacheAsync(endpoint:
|
|
1
|
+
export default function getCacheAsync(endpoint: string): JSON;
|
package/dist/cjs/getSync.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function getCacheAsync(endpoint:
|
|
1
|
+
export default function getCacheAsync(endpoint: string): JSON;
|
package/dist/cjs/getSync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/getSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nexport default function getCacheAsync(endpoint) {\n const fullPath = path.join(this.cachePath, `${this.options.hash(endpoint)}.json`);\n try {\n const contents = fs.readFileSync(fullPath, 'utf8');\n const record = JSON.parse(contents.toString());\n return record.body;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["getCacheAsync","endpoint","fullPath","path","join","cachePath","options","hash","contents","fs","readFileSync","record","JSON","parse","toString","body","_err"],"mappings":";;;;+BAGA;;;eAAwBA;;;yDAHT;2DACE;;;;;;AAEF,SAASA,cAAcC,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/getSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nexport default function getCacheAsync(endpoint: string): JSON {\n const fullPath = path.join(this.cachePath, `${this.options.hash(endpoint)}.json`);\n try {\n const contents = fs.readFileSync(fullPath, 'utf8');\n const record = JSON.parse(contents.toString());\n return record.body;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["getCacheAsync","endpoint","fullPath","path","join","cachePath","options","hash","contents","fs","readFileSync","record","JSON","parse","toString","body","_err"],"mappings":";;;;+BAGA;;;eAAwBA;;;yDAHT;2DACE;;;;;;AAEF,SAASA,cAAcC,QAAgB;IACpD,IAAMC,WAAWC,aAAI,CAACC,IAAI,CAAC,IAAI,CAACC,SAAS,EAAE,AAAC,GAA8B,OAA5B,IAAI,CAACC,OAAO,CAACC,IAAI,CAACN,WAAU;IAC1E,IAAI;QACF,IAAMO,WAAWC,WAAE,CAACC,YAAY,CAACR,UAAU;QAC3C,IAAMS,SAASC,KAAKC,KAAK,CAACL,SAASM,QAAQ;QAC3C,OAAOH,OAAOI,IAAI;IACpB,EAAE,OAAOC,MAAM;QACb,OAAO;IACT;AACF"}
|
package/dist/cjs/hash.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function hash(data:
|
|
1
|
+
export default function hash(data: string): string;
|
package/dist/cjs/hash.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function hash(data:
|
|
1
|
+
export default function hash(data: string): string;
|
package/dist/cjs/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/hash.ts"],"sourcesContent":["import crypto from 'crypto';\n\nexport default function hash(data) {\n return crypto.createHash('md5').update(data).digest('hex');\n}\n"],"names":["hash","data","crypto","createHash","update","digest"],"mappings":";;;;+BAEA;;;eAAwBA;;;6DAFL;;;;;;AAEJ,SAASA,KAAKC,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/hash.ts"],"sourcesContent":["import crypto from 'crypto';\n\nexport default function hash(data: string): string {\n return crypto.createHash('md5').update(data).digest('hex');\n}\n"],"names":["hash","data","crypto","createHash","update","digest"],"mappings":";;;;+BAEA;;;eAAwBA;;;6DAFL;;;;;;AAEJ,SAASA,KAAKC,IAAY;IACvC,OAAOC,eAAM,CAACC,UAAU,CAAC,OAAOC,MAAM,CAACH,MAAMI,MAAM,CAAC;AACtD"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
export interface GetOptions {
|
|
5
|
-
force?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export type GetCallback = (error?: Error, json?: object) => void;
|
|
8
|
-
export type ClearCallback = (error?: Error) => void;
|
|
9
|
-
export default class Cache {
|
|
10
|
-
cachePath: string;
|
|
11
|
-
options: CacheOptions;
|
|
12
|
-
constructor(cachePath: string, options?: CacheOptions);
|
|
13
|
-
get(endpoint: string, options?: GetOptions | GetCallback, callback?: GetCallback): undefined | Promise<object | null>;
|
|
14
|
-
getSync(endpoint: string): object | null;
|
|
15
|
-
clear(callback?: ClearCallback): undefined | Promise<undefined>;
|
|
16
|
-
}
|
|
1
|
+
export { default } from './Cache.ts';
|
|
2
|
+
export * from './types.ts';
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
export interface GetOptions {
|
|
5
|
-
force?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export type GetCallback = (error?: Error, json?: object) => void;
|
|
8
|
-
export type ClearCallback = (error?: Error) => void;
|
|
9
|
-
export default class Cache {
|
|
10
|
-
cachePath: string;
|
|
11
|
-
options: CacheOptions;
|
|
12
|
-
constructor(cachePath: string, options?: CacheOptions);
|
|
13
|
-
get(endpoint: string, options?: GetOptions | GetCallback, callback?: GetCallback): undefined | Promise<object | null>;
|
|
14
|
-
getSync(endpoint: string): object | null;
|
|
15
|
-
clear(callback?: ClearCallback): undefined | Promise<undefined>;
|
|
16
|
-
}
|
|
1
|
+
export { default } from './Cache.ts';
|
|
2
|
+
export * from './types.ts';
|
package/dist/cjs/index.js
CHANGED
|
@@ -5,79 +5,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
Object.defineProperty(exports, "default", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return
|
|
8
|
+
return _Cachets.default;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return left instanceof right;
|
|
26
|
-
}
|
|
11
|
+
var _Cachets = /*#__PURE__*/ _interop_require_default(require("./Cache.js"));
|
|
12
|
+
_export_star(require("./types.js"), exports);
|
|
13
|
+
function _export_star(from, to) {
|
|
14
|
+
Object.keys(from).forEach(function(k) {
|
|
15
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
16
|
+
Object.defineProperty(to, k, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function() {
|
|
19
|
+
return from[k];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return from;
|
|
27
25
|
}
|
|
28
26
|
function _interop_require_default(obj) {
|
|
29
27
|
return obj && obj.__esModule ? obj : {
|
|
30
28
|
default: obj
|
|
31
29
|
};
|
|
32
30
|
}
|
|
33
|
-
var Cache = /*#__PURE__*/ function() {
|
|
34
|
-
"use strict";
|
|
35
|
-
function Cache(cachePath) {
|
|
36
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
37
|
-
_class_call_check(this, Cache);
|
|
38
|
-
if (!_instanceof(this, Cache)) throw new Error('Cache needs to be called with new');
|
|
39
|
-
if (!cachePath) throw new Error('Cache needs cachePath');
|
|
40
|
-
this.cachePath = cachePath;
|
|
41
|
-
this.options = options;
|
|
42
|
-
if (!this.options.hash) this.options.hash = _hashts.default;
|
|
43
|
-
}
|
|
44
|
-
var _proto = Cache.prototype;
|
|
45
|
-
_proto.get = function get(endpoint, options, callback) {
|
|
46
|
-
var _this = this;
|
|
47
|
-
if (typeof options === 'function') {
|
|
48
|
-
callback = options;
|
|
49
|
-
options = null;
|
|
50
|
-
}
|
|
51
|
-
options = options || {};
|
|
52
|
-
function worker(endpoint, options, callback) {
|
|
53
|
-
options.force ? _updatets.default.call(this, endpoint, callback) : _getts.default.call(this, endpoint, callback);
|
|
54
|
-
}
|
|
55
|
-
if (typeof callback === 'function') return worker.call(this, endpoint, options, callback);
|
|
56
|
-
return new Promise(function(resolve, reject) {
|
|
57
|
-
return worker.call(_this, endpoint, options, function(err, json) {
|
|
58
|
-
return err ? reject(err) : resolve(json);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
_proto.getSync = function getSync(endpoint) {
|
|
63
|
-
// TODO: add async fetching
|
|
64
|
-
return _getSyncts.default.call(this, endpoint);
|
|
65
|
-
};
|
|
66
|
-
_proto.clear = function clear(callback) {
|
|
67
|
-
var _this = this;
|
|
68
|
-
function worker(callback) {
|
|
69
|
-
// ignore errors since it is fine to delete a directory that doesn't exist from a cache standpoint
|
|
70
|
-
(0, _rimraf2.default)(this.cachePath, {
|
|
71
|
-
disableGlob: true
|
|
72
|
-
}, callback.bind(null, null));
|
|
73
|
-
}
|
|
74
|
-
if (typeof callback === 'function') return worker.call(this, callback);
|
|
75
|
-
return new Promise(function(resolve, reject) {
|
|
76
|
-
return worker.call(_this, function(err) {
|
|
77
|
-
err ? reject(err) : resolve(undefined);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
return Cache;
|
|
82
|
-
}();
|
|
83
31
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/index.ts"],"sourcesContent":["export { default } from './Cache.ts';\nexport * from './types.ts';\n"],"names":["default"],"mappings":";;;;+BAASA;;;eAAAA,gBAAO;;;8DAAQ;qBACV"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CacheOptions, ClearCallback, GetCallback, GetOptions } from './types.ts';
|
|
2
|
+
export default class Cache {
|
|
3
|
+
cachePath: string;
|
|
4
|
+
options: CacheOptions;
|
|
5
|
+
constructor(cachePath: string, options?: CacheOptions);
|
|
6
|
+
get(endpoint: string, options?: GetOptions | GetCallback, callback?: GetCallback): undefined | Promise<object | null>;
|
|
7
|
+
getSync(endpoint: string): object | null;
|
|
8
|
+
clear(callback?: ClearCallback): undefined | Promise<undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import rimraf2 from 'rimraf2';
|
|
2
|
+
import get from './get.js';
|
|
3
|
+
import getSync from './getSync.js';
|
|
4
|
+
import hash from './hash.js';
|
|
5
|
+
import update from './update.js';
|
|
6
|
+
let Cache = class Cache {
|
|
7
|
+
get(endpoint, options, callback) {
|
|
8
|
+
if (typeof options === 'function') {
|
|
9
|
+
callback = options;
|
|
10
|
+
options = null;
|
|
11
|
+
}
|
|
12
|
+
options = options || {};
|
|
13
|
+
function worker(endpoint, options, callback) {
|
|
14
|
+
options.force ? update.call(this, endpoint, callback) : get.call(this, endpoint, callback);
|
|
15
|
+
}
|
|
16
|
+
if (typeof callback === 'function') return worker.call(this, endpoint, options, callback);
|
|
17
|
+
return new Promise((resolve, reject)=>worker.call(this, endpoint, options, (err, json)=>err ? reject(err) : resolve(json)));
|
|
18
|
+
}
|
|
19
|
+
getSync(endpoint) {
|
|
20
|
+
// TODO: add async fetching
|
|
21
|
+
return getSync.call(this, endpoint);
|
|
22
|
+
}
|
|
23
|
+
clear(callback) {
|
|
24
|
+
function worker(callback) {
|
|
25
|
+
// ignore errors since it is fine to delete a directory that doesn't exist from a cache standpoint
|
|
26
|
+
rimraf2(this.cachePath, {
|
|
27
|
+
disableGlob: true
|
|
28
|
+
}, callback.bind(null, null));
|
|
29
|
+
}
|
|
30
|
+
if (typeof callback === 'function') return worker.call(this, callback);
|
|
31
|
+
return new Promise((resolve, reject)=>worker.call(this, (err)=>{
|
|
32
|
+
err ? reject(err) : resolve(undefined);
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
constructor(cachePath, options = {}){
|
|
36
|
+
if (!(this instanceof Cache)) throw new Error('Cache needs to be called with new');
|
|
37
|
+
if (!cachePath) throw new Error('Cache needs cachePath');
|
|
38
|
+
this.cachePath = cachePath;
|
|
39
|
+
this.options = options;
|
|
40
|
+
if (!this.options.hash) this.options.hash = hash;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export { Cache as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/Cache.ts"],"sourcesContent":["import rimraf2 from 'rimraf2';\n\nimport get from './get.ts';\nimport getSync from './getSync.ts';\nimport hash from './hash.ts';\nimport type { CacheOptions, ClearCallback, GetCallback, GetOptions } from './types.ts';\nimport update from './update.ts';\n\nexport default class Cache {\n cachePath: string;\n options: CacheOptions;\n\n constructor(cachePath: string, options: CacheOptions = {}) {\n if (!(this instanceof Cache)) throw new Error('Cache needs to be called with new');\n if (!cachePath) throw new Error('Cache needs cachePath');\n this.cachePath = cachePath;\n this.options = options;\n if (!this.options.hash) this.options.hash = hash;\n }\n\n get(endpoint: string, options?: GetOptions | GetCallback, callback?: GetCallback): undefined | Promise<object | null> {\n if (typeof options === 'function') {\n callback = options as GetCallback;\n options = null;\n }\n options = options || {};\n\n function worker(endpoint, options, callback) {\n (options as GetOptions).force ? update.call(this, endpoint, callback) : get.call(this, endpoint, callback);\n }\n\n if (typeof callback === 'function') return worker.call(this, endpoint, options, callback) as undefined;\n return new Promise((resolve, reject) => worker.call(this, endpoint, options, (err, json) => (err ? reject(err) : resolve(json))));\n }\n\n getSync(endpoint: string): object | null {\n // TODO: add async fetching\n return getSync.call(this, endpoint);\n }\n\n clear(callback?: ClearCallback): undefined | Promise<undefined> {\n function worker(callback) {\n // ignore errors since it is fine to delete a directory that doesn't exist from a cache standpoint\n rimraf2(this.cachePath, { disableGlob: true }, callback.bind(null, null));\n }\n\n if (typeof callback === 'function') return worker.call(this, callback);\n return new Promise((resolve, reject) =>\n worker.call(this, (err) => {\n err ? reject(err) : resolve(undefined);\n })\n );\n }\n}\n"],"names":["rimraf2","get","getSync","hash","update","Cache","endpoint","options","callback","worker","force","call","Promise","resolve","reject","err","json","clear","cachePath","disableGlob","bind","undefined","Error"],"mappings":"AAAA,OAAOA,aAAa,UAAU;AAE9B,OAAOC,SAAS,WAAW;AAC3B,OAAOC,aAAa,eAAe;AACnC,OAAOC,UAAU,YAAY;AAE7B,OAAOC,YAAY,cAAc;AAElB,IAAA,AAAMC,QAAN,MAAMA;IAYnBJ,IAAIK,QAAgB,EAAEC,OAAkC,EAAEC,QAAsB,EAAsC;QACpH,IAAI,OAAOD,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QAEtB,SAASE,OAAOH,QAAQ,EAAEC,OAAO,EAAEC,QAAQ;YACxCD,QAAuBG,KAAK,GAAGN,OAAOO,IAAI,CAAC,IAAI,EAAEL,UAAUE,YAAYP,IAAIU,IAAI,CAAC,IAAI,EAAEL,UAAUE;QACnG;QAEA,IAAI,OAAOA,aAAa,YAAY,OAAOC,OAAOE,IAAI,CAAC,IAAI,EAAEL,UAAUC,SAASC;QAChF,OAAO,IAAII,QAAQ,CAACC,SAASC,SAAWL,OAAOE,IAAI,CAAC,IAAI,EAAEL,UAAUC,SAAS,CAACQ,KAAKC,OAAUD,MAAMD,OAAOC,OAAOF,QAAQG;IAC3H;IAEAd,QAAQI,QAAgB,EAAiB;QACvC,2BAA2B;QAC3B,OAAOJ,QAAQS,IAAI,CAAC,IAAI,EAAEL;IAC5B;IAEAW,MAAMT,QAAwB,EAAkC;QAC9D,SAASC,OAAOD,QAAQ;YACtB,kGAAkG;YAClGR,QAAQ,IAAI,CAACkB,SAAS,EAAE;gBAAEC,aAAa;YAAK,GAAGX,SAASY,IAAI,CAAC,MAAM;QACrE;QAEA,IAAI,OAAOZ,aAAa,YAAY,OAAOC,OAAOE,IAAI,CAAC,IAAI,EAAEH;QAC7D,OAAO,IAAII,QAAQ,CAACC,SAASC,SAC3BL,OAAOE,IAAI,CAAC,IAAI,EAAE,CAACI;gBACjBA,MAAMD,OAAOC,OAAOF,QAAQQ;YAC9B;IAEJ;IAxCA,YAAYH,SAAiB,EAAEX,UAAwB,CAAC,CAAC,CAAE;QACzD,IAAI,CAAE,CAAA,IAAI,YAAYF,KAAI,GAAI,MAAM,IAAIiB,MAAM;QAC9C,IAAI,CAACJ,WAAW,MAAM,IAAII,MAAM;QAChC,IAAI,CAACJ,SAAS,GAAGA;QACjB,IAAI,CAACX,OAAO,GAAGA;QACf,IAAI,CAAC,IAAI,CAACA,OAAO,CAACJ,IAAI,EAAE,IAAI,CAACI,OAAO,CAACJ,IAAI,GAAGA;IAC9C;AAmCF;AA7CA,SAAqBE,mBA6CpB"}
|
package/dist/esm/get.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { GetCallback } from './types.ts';
|
|
2
|
+
export default function getCache(endpoint: string, callback: GetCallback): undefined;
|
package/dist/esm/get.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/get.ts"],"sourcesContent":["import fs from 'fs';\nimport get from 'get-remote';\nimport path from 'path';\n\nimport update from './update.ts';\n\ninterface GetError {\n code?: string;\n}\n\ninterface GetHeaders {\n etag?: string;\n}\n\nexport default function getCache(endpoint, callback) {\n const fullPath = path.join(this.cachePath, `${this.options.hash(endpoint)}.json`);\n fs.readFile(fullPath, (err, contents) => {\n // doesn't exist so create\n if (err) {\n update.call(this, endpoint, (err, json) => {\n err ? callback(err) : callback(null, json);\n });\n }\n // check existing if etag changed and if so, recache\n else {\n const record = JSON.parse(contents.toString());\n get(endpoint).head((err, res) => {\n // not accessible\n if (err) {\n if ((err as GetError).code === 'ENOTFOUND' || err.message.indexOf('routines:SSL23_GET_SERVER_HELLO') >= 0) return callback(null, record.body);\n return callback(err);\n }\n if ((res.headers as GetHeaders).etag === record.headers.etag) return callback(null, record.body);\n update.call(this, endpoint, (err, json) => {\n err ? callback(err) : callback(null, json);\n });\n });\n }\n });\n}\n"],"names":["fs","get","path","update","getCache","endpoint","callback","fullPath","join","cachePath","options","hash","readFile","err","contents","call","json","record","JSON","parse","toString","head","res","code","message","indexOf","body","headers","etag"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,SAAS,aAAa;AAC7B,OAAOC,UAAU,OAAO;AAExB,OAAOC,YAAY,cAAc;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/get.ts"],"sourcesContent":["import fs from 'fs';\nimport get from 'get-remote';\nimport path from 'path';\n\nimport update from './update.ts';\n\ninterface GetError {\n code?: string;\n}\n\ninterface GetHeaders {\n etag?: string;\n}\n\nimport type { GetCallback } from './types.ts';\n\nexport default function getCache(endpoint: string, callback: GetCallback): undefined {\n const fullPath = path.join(this.cachePath, `${this.options.hash(endpoint)}.json`);\n fs.readFile(fullPath, (err, contents) => {\n // doesn't exist so create\n if (err) {\n update.call(this, endpoint, (err, json) => {\n err ? callback(err) : callback(null, json);\n });\n }\n // check existing if etag changed and if so, recache\n else {\n const record = JSON.parse(contents.toString());\n get(endpoint).head((err, res) => {\n // not accessible\n if (err) {\n if ((err as GetError).code === 'ENOTFOUND' || err.message.indexOf('routines:SSL23_GET_SERVER_HELLO') >= 0) return callback(null, record.body);\n return callback(err);\n }\n if ((res.headers as GetHeaders).etag === record.headers.etag) return callback(null, record.body);\n update.call(this, endpoint, (err, json) => {\n err ? callback(err) : callback(null, json);\n });\n });\n }\n });\n}\n"],"names":["fs","get","path","update","getCache","endpoint","callback","fullPath","join","cachePath","options","hash","readFile","err","contents","call","json","record","JSON","parse","toString","head","res","code","message","indexOf","body","headers","etag"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,SAAS,aAAa;AAC7B,OAAOC,UAAU,OAAO;AAExB,OAAOC,YAAY,cAAc;AAYjC,eAAe,SAASC,SAASC,QAAgB,EAAEC,QAAqB;IACtE,MAAMC,WAAWL,KAAKM,IAAI,CAAC,IAAI,CAACC,SAAS,EAAE,GAAG,IAAI,CAACC,OAAO,CAACC,IAAI,CAACN,UAAU,KAAK,CAAC;IAChFL,GAAGY,QAAQ,CAACL,UAAU,CAACM,KAAKC;QAC1B,0BAA0B;QAC1B,IAAID,KAAK;YACPV,OAAOY,IAAI,CAAC,IAAI,EAAEV,UAAU,CAACQ,KAAKG;gBAChCH,MAAMP,SAASO,OAAOP,SAAS,MAAMU;YACvC;QACF,OAEK;YACH,MAAMC,SAASC,KAAKC,KAAK,CAACL,SAASM,QAAQ;YAC3CnB,IAAII,UAAUgB,IAAI,CAAC,CAACR,KAAKS;gBACvB,iBAAiB;gBACjB,IAAIT,KAAK;oBACP,IAAI,AAACA,IAAiBU,IAAI,KAAK,eAAeV,IAAIW,OAAO,CAACC,OAAO,CAAC,sCAAsC,GAAG,OAAOnB,SAAS,MAAMW,OAAOS,IAAI;oBAC5I,OAAOpB,SAASO;gBAClB;gBACA,IAAI,AAACS,IAAIK,OAAO,CAAgBC,IAAI,KAAKX,OAAOU,OAAO,CAACC,IAAI,EAAE,OAAOtB,SAAS,MAAMW,OAAOS,IAAI;gBAC/FvB,OAAOY,IAAI,CAAC,IAAI,EAAEV,UAAU,CAACQ,KAAKG;oBAChCH,MAAMP,SAASO,OAAOP,SAAS,MAAMU;gBACvC;YACF;QACF;IACF;AACF"}
|
package/dist/esm/getSync.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function getCacheAsync(endpoint:
|
|
1
|
+
export default function getCacheAsync(endpoint: string): JSON;
|
package/dist/esm/getSync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/getSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nexport default function getCacheAsync(endpoint) {\n const fullPath = path.join(this.cachePath, `${this.options.hash(endpoint)}.json`);\n try {\n const contents = fs.readFileSync(fullPath, 'utf8');\n const record = JSON.parse(contents.toString());\n return record.body;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["fs","path","getCacheAsync","endpoint","fullPath","join","cachePath","options","hash","contents","readFileSync","record","JSON","parse","toString","body","_err"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AAExB,eAAe,SAASC,cAAcC,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/getSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nexport default function getCacheAsync(endpoint: string): JSON {\n const fullPath = path.join(this.cachePath, `${this.options.hash(endpoint)}.json`);\n try {\n const contents = fs.readFileSync(fullPath, 'utf8');\n const record = JSON.parse(contents.toString());\n return record.body;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["fs","path","getCacheAsync","endpoint","fullPath","join","cachePath","options","hash","contents","readFileSync","record","JSON","parse","toString","body","_err"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AAExB,eAAe,SAASC,cAAcC,QAAgB;IACpD,MAAMC,WAAWH,KAAKI,IAAI,CAAC,IAAI,CAACC,SAAS,EAAE,GAAG,IAAI,CAACC,OAAO,CAACC,IAAI,CAACL,UAAU,KAAK,CAAC;IAChF,IAAI;QACF,MAAMM,WAAWT,GAAGU,YAAY,CAACN,UAAU;QAC3C,MAAMO,SAASC,KAAKC,KAAK,CAACJ,SAASK,QAAQ;QAC3C,OAAOH,OAAOI,IAAI;IACpB,EAAE,OAAOC,MAAM;QACb,OAAO;IACT;AACF"}
|
package/dist/esm/hash.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function hash(data:
|
|
1
|
+
export default function hash(data: string): string;
|
package/dist/esm/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/hash.ts"],"sourcesContent":["import crypto from 'crypto';\n\nexport default function hash(data) {\n return crypto.createHash('md5').update(data).digest('hex');\n}\n"],"names":["crypto","hash","data","createHash","update","digest"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAE5B,eAAe,SAASC,KAAKC,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/hash.ts"],"sourcesContent":["import crypto from 'crypto';\n\nexport default function hash(data: string): string {\n return crypto.createHash('md5').update(data).digest('hex');\n}\n"],"names":["crypto","hash","data","createHash","update","digest"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAE5B,eAAe,SAASC,KAAKC,IAAY;IACvC,OAAOF,OAAOG,UAAU,CAAC,OAAOC,MAAM,CAACF,MAAMG,MAAM,CAAC;AACtD"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
export interface GetOptions {
|
|
5
|
-
force?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export type GetCallback = (error?: Error, json?: object) => void;
|
|
8
|
-
export type ClearCallback = (error?: Error) => void;
|
|
9
|
-
export default class Cache {
|
|
10
|
-
cachePath: string;
|
|
11
|
-
options: CacheOptions;
|
|
12
|
-
constructor(cachePath: string, options?: CacheOptions);
|
|
13
|
-
get(endpoint: string, options?: GetOptions | GetCallback, callback?: GetCallback): undefined | Promise<object | null>;
|
|
14
|
-
getSync(endpoint: string): object | null;
|
|
15
|
-
clear(callback?: ClearCallback): undefined | Promise<undefined>;
|
|
16
|
-
}
|
|
1
|
+
export { default } from './Cache.ts';
|
|
2
|
+
export * from './types.ts';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,43 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import getSync from './getSync.js';
|
|
4
|
-
import hash from './hash.js';
|
|
5
|
-
import update from './update.js';
|
|
6
|
-
let Cache = class Cache {
|
|
7
|
-
get(endpoint, options, callback) {
|
|
8
|
-
if (typeof options === 'function') {
|
|
9
|
-
callback = options;
|
|
10
|
-
options = null;
|
|
11
|
-
}
|
|
12
|
-
options = options || {};
|
|
13
|
-
function worker(endpoint, options, callback) {
|
|
14
|
-
options.force ? update.call(this, endpoint, callback) : get.call(this, endpoint, callback);
|
|
15
|
-
}
|
|
16
|
-
if (typeof callback === 'function') return worker.call(this, endpoint, options, callback);
|
|
17
|
-
return new Promise((resolve, reject)=>worker.call(this, endpoint, options, (err, json)=>err ? reject(err) : resolve(json)));
|
|
18
|
-
}
|
|
19
|
-
getSync(endpoint) {
|
|
20
|
-
// TODO: add async fetching
|
|
21
|
-
return getSync.call(this, endpoint);
|
|
22
|
-
}
|
|
23
|
-
clear(callback) {
|
|
24
|
-
function worker(callback) {
|
|
25
|
-
// ignore errors since it is fine to delete a directory that doesn't exist from a cache standpoint
|
|
26
|
-
rimraf2(this.cachePath, {
|
|
27
|
-
disableGlob: true
|
|
28
|
-
}, callback.bind(null, null));
|
|
29
|
-
}
|
|
30
|
-
if (typeof callback === 'function') return worker.call(this, callback);
|
|
31
|
-
return new Promise((resolve, reject)=>worker.call(this, (err)=>{
|
|
32
|
-
err ? reject(err) : resolve(undefined);
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
constructor(cachePath, options = {}){
|
|
36
|
-
if (!(this instanceof Cache)) throw new Error('Cache needs to be called with new');
|
|
37
|
-
if (!cachePath) throw new Error('Cache needs cachePath');
|
|
38
|
-
this.cachePath = cachePath;
|
|
39
|
-
this.options = options;
|
|
40
|
-
if (!this.options.hash) this.options.hash = hash;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
export { Cache as default };
|
|
1
|
+
export { default } from './Cache.js';
|
|
2
|
+
export * from './types.js';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/index.ts"],"sourcesContent":["export { default } from './Cache.ts';\nexport * from './types.ts';\n"],"names":["default"],"mappings":"AAAA,SAASA,OAAO,QAAQ,aAAa;AACrC,cAAc,aAAa"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/fetch-json-cache/src/types.ts"],"sourcesContent":["export interface CacheOptions {\n hash?: (string: string) => string;\n}\n\nexport interface GetOptions {\n force?: boolean;\n}\nexport type GetCallback = (error?: Error, json?: JSON) => undefined;\nexport type ClearCallback = (error?: Error) => undefined;\n"],"names":[],"mappings":"AAQA,WAAyD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fetch-json-cache",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.54",
|
|
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",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"version": "tsds version"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"get-remote": "^2.0.
|
|
39
|
+
"get-remote": "^2.0.3",
|
|
40
40
|
"mkdirp-classic": "^0.5.3",
|
|
41
41
|
"queue-cb": "^1.5.5",
|
|
42
42
|
"rimraf2": "^2.8.2",
|