fetch-json-cache 1.2.56 → 1.2.57
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 +3 -3
- package/dist/cjs/Cache.d.ts +3 -3
- package/dist/cjs/Cache.js.map +1 -1
- package/dist/esm/Cache.d.ts +3 -3
- package/dist/esm/Cache.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/Cache.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { CacheOptions, ClearCallback, GetCallback, GetOptions } from './types.ts';
|
|
2
|
-
export default class Cache
|
|
2
|
+
export default class Cache {
|
|
3
3
|
cachePath: string;
|
|
4
4
|
options: CacheOptions;
|
|
5
5
|
constructor(cachePath: string, options?: CacheOptions);
|
|
6
|
-
get(endpoint: string, options?: GetOptions | GetCallback<T>, callback?: GetCallback<T>): undefined | Promise<object | null>;
|
|
7
|
-
getSync(endpoint: string): T | null;
|
|
6
|
+
get<T>(endpoint: string, options?: GetOptions | GetCallback<T>, callback?: GetCallback<T>): undefined | Promise<object | null>;
|
|
7
|
+
getSync<T>(endpoint: string): T | null;
|
|
8
8
|
clear(callback?: ClearCallback): undefined | Promise<undefined>;
|
|
9
9
|
}
|
package/dist/cjs/Cache.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { CacheOptions, ClearCallback, GetCallback, GetOptions } from './types.ts';
|
|
2
|
-
export default class Cache
|
|
2
|
+
export default class Cache {
|
|
3
3
|
cachePath: string;
|
|
4
4
|
options: CacheOptions;
|
|
5
5
|
constructor(cachePath: string, options?: CacheOptions);
|
|
6
|
-
get(endpoint: string, options?: GetOptions | GetCallback<T>, callback?: GetCallback<T>): undefined | Promise<object | null>;
|
|
7
|
-
getSync(endpoint: string): T | null;
|
|
6
|
+
get<T>(endpoint: string, options?: GetOptions | GetCallback<T>, callback?: GetCallback<T>): undefined | Promise<object | null>;
|
|
7
|
+
getSync<T>(endpoint: string): T | null;
|
|
8
8
|
clear(callback?: ClearCallback): undefined | Promise<undefined>;
|
|
9
9
|
}
|
package/dist/cjs/Cache.js.map
CHANGED
|
@@ -1 +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
|
|
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<T>(endpoint: string, options?: GetOptions | GetCallback<T>, callback?: GetCallback<T>): undefined | Promise<object | null> {\n if (typeof options === 'function') {\n callback = options as GetCallback<T>;\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<T>(endpoint: string): T | 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,IAAOC,QAAgB,EAAEJ,OAAqC,EAAEK,QAAyB;;QACvF,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,QAAWX,QAAgB;QACzB,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/esm/Cache.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { CacheOptions, ClearCallback, GetCallback, GetOptions } from './types.ts';
|
|
2
|
-
export default class Cache
|
|
2
|
+
export default class Cache {
|
|
3
3
|
cachePath: string;
|
|
4
4
|
options: CacheOptions;
|
|
5
5
|
constructor(cachePath: string, options?: CacheOptions);
|
|
6
|
-
get(endpoint: string, options?: GetOptions | GetCallback<T>, callback?: GetCallback<T>): undefined | Promise<object | null>;
|
|
7
|
-
getSync(endpoint: string): T | null;
|
|
6
|
+
get<T>(endpoint: string, options?: GetOptions | GetCallback<T>, callback?: GetCallback<T>): undefined | Promise<object | null>;
|
|
7
|
+
getSync<T>(endpoint: string): T | null;
|
|
8
8
|
clear(callback?: ClearCallback): undefined | Promise<undefined>;
|
|
9
9
|
}
|
package/dist/esm/Cache.js.map
CHANGED
|
@@ -1 +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
|
|
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<T>(endpoint: string, options?: GetOptions | GetCallback<T>, callback?: GetCallback<T>): undefined | Promise<object | null> {\n if (typeof options === 'function') {\n callback = options as GetCallback<T>;\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<T>(endpoint: string): T | 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,IAAOK,QAAgB,EAAEC,OAAqC,EAAEC,QAAyB,EAAsC;QAC7H,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,QAAWI,QAAgB,EAAY;QACrC,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/package.json
CHANGED