Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cachely

Package Overview
Dependencies
Maintainers
2
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cachely - npm Package Compare versions

Comparing version 2.7.0 to 3.0.0-next.1575672593.fd381846052b82c08d3c45cd3b69d14b690728c1

edition-node-12/index.js

108

edition-browsers/index.js

@@ -1,17 +0,8 @@

'use strict';
/**
Construct our Cachely class, setting the configuration from the options
@param {Object} opts
@param {Number} opts.duration - the milliseconds that the cache should be valid for, defaults to one day
@param {Function} [opts.log] - defaults to `null`, can be a function that receives the arguments: `logLevel`, `...args`
@param {Function} [opts.retrieve] - the method that fetches the new source data, it should return a promise that resolves the result that will be cached
@public
*/
"use strict";
function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -23,34 +14,38 @@

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var Cachely =
/*#__PURE__*/
function () {
function Cachely() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
/** Construct our Cachely class, setting the configuration from the options */
function Cachely(opts) {
_classCallCheck(this, Cachely);
this.duration = opts.duration || require('oneday');
_defineProperty(this, "duration", void 0);
this.log = opts.log || function () {};
_defineProperty(this, "log", void 0);
this.retrieve = opts.retrieve;
_defineProperty(this, "retrieve", void 0);
if (typeof this.retrieve !== 'function') {
_defineProperty(this, "data", void 0);
_defineProperty(this, "refresh", false);
_defineProperty(this, "lastRequested", void 0);
_defineProperty(this, "lastRetrieval", void 0);
_defineProperty(this, "lastUpdated", null);
if (!opts || typeof opts.retrieve !== 'function') {
throw new Error('Cachely requires a retrieve method to be specified that returns a promise');
} // Private properties
}
this.duration = opts.duration || require('oneday');
this.data = null;
this.refresh = false;
this.lastRequested = null;
this.lastRetrieval = null;
this.lastUpdated = null;
this.log = opts.log || function () {};
this.retrieve = opts.retrieve;
}
/**
Creates and returns new instance of the current class
@param {...*} args - the arguments to be forwarded along to the constructor
@return {Object} The new instance.
@static
@public
*/
/** Creates and returns new instance of the current class */

@@ -61,7 +56,3 @@

/**
Determines whether or not the cache is still valid, by returning its current status
@returns {string} - 'valid', 'invalid', 'updating', or 'empty'
@private
*/
/** Determines whether or not the cache is still valid, by returning its current status */
value: function validate() {

@@ -74,6 +65,6 @@ var nowTime = new Date().getTime(); // have we manually invalidated the cache?

} // have we fetched the data yet?
else if (this.lastUpdated) {
else if (this.lastUpdated && this.lastRequested) {
// yes we have, so let's check if it is still valid
// if the current time, minus the cache duration, is than the last time we retrieved the data, then our cache is invalid
return new Date(nowTime - this.duration) < this.lastRequested ? 'valid' : 'invalid';
// if the current time, minus the cache duration, is than the last time we requested the data, then our cache is invalid
return new Date(nowTime - this.duration).getTime() < this.lastRequested ? 'valid' : 'invalid';
} // are we doing the first fetch?

@@ -87,9 +78,4 @@ else if (this.lastRequested) {

}
/**
Invalidates the current cache, so that it is retrieved again.
Only applies to future resolution requets, does not cancel or modify active retrieval requests.
@returns {this}
@chainable
@public
*/
/** Invalidates the current cache, so that it is retrieved again.
Only applies to future resolution requets, does not cancel or modify active retrieval requests. */

@@ -102,7 +88,3 @@ }, {

}
/**
Resolve the cache, if it is valid use the cache's data, otherwise retrieve new data
@returns {Promise<*>}
@public
*/
/** Resolve the cache, if it is valid use the cache's data, otherwise retrieve new data */

@@ -128,3 +110,3 @@ }, {

this.log('debug', 'Cachely must resolve new data');
this.lastRequested = new Date();
this.lastRequested = new Date().getTime();
this.lastUpdated = null;

@@ -138,3 +120,3 @@ this.lastRetrieval = Promise.resolve(this.retrieve());

this.data = _context.sent;
this.lastUpdated = new Date();
this.lastUpdated = new Date().getTime();
_context.next = 21;

@@ -169,8 +151,4 @@ break;

key: "create",
value: function create() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _construct(this, args);
value: function create(opts) {
return new this(opts);
}

@@ -180,5 +158,5 @@ }]);

return Cachely;
}(); // Export
}();
module.exports = Cachely;
exports.default = Cachely;
module.exports = exports.default;
# History
## v3.0.0 2019 December 7
- Converted to TypeScript
- Updated dependencies, [base files](https://github.com/bevry/base), and [editions](https://editions.bevry.me) using [boundation](https://github.com/bevry/boundation)
## v2.7.0 2019 December 1

@@ -4,0 +9,0 @@

{
"name": "cachely",
"version": "2.7.0",
"version": "3.0.0-next.1575672593.fd381846052b82c08d3c45cd3b69d14b690728c1",
"description": "A tiny wrapper that sits around your request function that caches its data for a specified duration, provides updates as requested rather than polling each interval",

@@ -20,2 +20,3 @@ "homepage": "https://github.com/bevry/cachely",

"---",
"githubsponsors",
"patreon",

@@ -31,2 +32,3 @@ "flattr",

"config": {
"githubSponsorsUsername": "balupton",
"buymeacoffeeUsername": "balupton",

@@ -64,18 +66,27 @@ "cryptoURL": "https://bevry.me/crypto",

{
"description": "esnext source code with require for modules",
"description": "typescript source code with import for modules",
"directory": "source",
"entry": "index.ts",
"tags": [
"typescript",
"import"
],
"engines": false
},
{
"description": "typescript compiled for browsers with import for modules",
"directory": "edition-browsers",
"entry": "index.js",
"tags": [
"javascript",
"esnext",
"require"
"import"
],
"engines": {
"node": "8 || 10 || 12",
"browsers": false
"node": false,
"browsers": "defaults"
}
},
{
"description": "esnext compiled for browsers with require for modules",
"directory": "edition-browsers",
"description": "typescript compiled for node.js 12 with require for modules",
"directory": "edition-node-12",
"entry": "index.js",

@@ -87,39 +98,49 @@ "tags": [

"engines": {
"node": false,
"browsers": "defaults"
"node": "8 || 10 || 12",
"browsers": false
}
}
],
"main": "source/index.js",
"types": "source/index.ts",
"type": "commonjs",
"main": "edition-node-12/index.js",
"browser": "edition-browsers/index.js",
"module": "edition-browsers/index.js",
"dependencies": {
"oneday": "^2.1.0"
"oneday": "^2.2.0"
},
"devDependencies": {
"@babel/cli": "^7.7.4",
"@babel/core": "^7.7.4",
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-proposal-object-rest-spread": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"@babel/plugin-proposal-optional-chaining": "^7.7.5",
"@babel/preset-env": "^7.7.5",
"@babel/preset-typescript": "^7.7.4",
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"assert-helpers": "^5.7.0",
"babel-plugin-add-module-exports": "^1.0.2",
"eslint": "^6.7.2",
"eslint-config-bevry": "^2.1.0",
"eslint-config-bevry": "^2.2.0",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-prettier": "^3.1.1",
"jsdoc": "^3.6.3",
"kava": "^4.2.0",
"minami": "^1.2.3",
"kava": "^4.3.0",
"prettier": "^1.19.1",
"projectz": "^1.13.0",
"projectz": "^1.15.0",
"surge": "^0.21.3",
"typechecker": "^5.1.0",
"valid-directory": "^1.4.0"
"typechecker": "^6.2.0",
"typedoc": "^0.15.3",
"typescript": "^3.7.3",
"valid-directory": "^1.5.0"
},
"scripts": {
"our:clean": "rm -Rf ./docs ./edition* ./es2015 ./es5 ./out ./.next",
"our:compile": "npm run our:compile:edition-browsers",
"our:compile:edition-browsers": "env BABEL_ENV=edition-browsers babel --out-dir ./edition-browsers ./source",
"our:compile": "npm run our:compile:edition-browsers && npm run our:compile:edition-node-12",
"our:compile:edition-browsers": "env BABEL_ENV=edition-browsers babel --extensions \".ts,.tsx\" --out-dir ./edition-browsers ./source",
"our:compile:edition-node-12": "env BABEL_ENV=edition-node-12 babel --extensions \".ts,.tsx\" --out-dir ./edition-node-12 ./source",
"our:deploy": "echo no need for this project",
"our:meta": "npm run our:meta:docs && npm run our:meta:projectz",
"our:meta:docs": "npm run our:meta:docs:jsdoc",
"our:meta:docs:jsdoc": "rm -Rf ./docs && jsdoc --recurse --pedantic --access all --destination ./docs --package ./package.json --readme ./README.md --template ./node_modules/minami ./source && mv ./docs/$npm_package_name/$npm_package_version/* ./docs/ && rm -Rf ./docs/$npm_package_name/$npm_package_version",
"our:meta:docs": "npm run our:meta:docs:typedoc",
"our:meta:docs:typedoc": "rm -Rf ./docs && typedoc --mode file --exclude '**/+(*test*|node_modules)' --excludeExternals --name \"$npm_package_name\" --readme ./README.md --out ./docs ./source",
"our:meta:projectz": "projectz compile",

@@ -135,7 +156,8 @@ "our:release": "npm run our:release:prepare && npm run our:release:check-changelog && npm run our:release:check-dirty && npm run our:release:tag && npm run our:release:push",

"our:test": "npm run our:verify && npm test",
"our:verify": "npm run our:verify:directory && npm run our:verify:eslint && npm run our:verify:prettier",
"our:verify": "npm run our:verify:directory && npm run our:verify:eslint && npm run our:verify:prettier && npm run our:verify:typescript",
"our:verify:directory": "npx valid-directory",
"our:verify:eslint": "eslint --fix --ignore-pattern '**/*.d.ts' --ignore-pattern '**/vendor/' --ignore-pattern '**/node_modules/' --ext .mjs,.js,.jsx,.ts,.tsx ./source",
"our:verify:prettier": "prettier --write ./source/**",
"test": "node ./source/test.js"
"our:verify:typescript": "tsc --noEmit --project tsconfig.json",
"test": "node ./edition-node-12/test.js"
},

@@ -154,3 +176,3 @@ "eslintConfig": {

"edition-browsers": {
"sourceType": "script",
"sourceType": "module",
"presets": [

@@ -163,7 +185,32 @@ [

}
]
],
"@babel/preset-typescript"
],
"plugins": [
"@babel/proposal-object-rest-spread"
"@babel/proposal-object-rest-spread",
"@babel/plugin-proposal-optional-chaining",
"@babel/proposal-class-properties",
"add-module-exports"
]
},
"edition-node-12": {
"sourceType": "module",
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "12"
},
"modules": "commonjs"
}
],
"@babel/preset-typescript"
],
"plugins": [
"@babel/proposal-object-rest-spread",
"@babel/plugin-proposal-optional-chaining",
"@babel/proposal-class-properties",
"add-module-exports"
]
}

@@ -170,0 +217,0 @@ }

@@ -16,2 +16,3 @@ <!-- TITLE/ -->

<br class="badge-separator" />
<span class="badge-githubsponsors"><a href="https://github.com/sponsors/balupton" title="Donate to this project using GitHub Sponsors"><img src="https://img.shields.io/badge/github-donate-yellow.svg" alt="GitHub Sponsors donate button" /></a></span>
<span class="badge-patreon"><a href="https://patreon.com/bevry" title="Donate to this project using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a></span>

@@ -58,18 +59,7 @@ <span class="badge-flattr"><a href="https://flattr.com/profile/balupton" title="Donate to this project using Flattr"><img src="https://img.shields.io/badge/flattr-donate-yellow.svg" alt="Flattr donate button" /></a></span>

<ul><li><code>cachely</code> aliases <code>cachely/source/index.js</code></li>
<li><code>cachely/source/index.js</code> is esnext source code with require for modules</li>
<li><code>cachely/edition-browsers/index.js</code> is esnext compiled for browsers with require for modules</li></ul>
<ul><li><code>cachely/source/index.ts</code> is typescript source code with import for modules</li>
<li><code>cachely/edition-browsers/index.js</code> is typescript compiled for browsers with import for modules</li>
<li><code>cachely</code> aliases <code>cachely/edition-node-12/index.js</code></li>
<li><code>cachely/edition-node-12/index.js</code> is typescript compiled for node.js 12 with require for modules</li></ul>
<h3><a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a></h3>
This project provides its type information via inline <a href="http://usejsdoc.org" title="JSDoc is an API documentation generator for JavaScript, similar to Javadoc or phpDocumentor">JSDoc Comments</a>. To make use of this in <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a>, set your <code>maxNodeModuleJsDepth</code> compiler option to `5` or thereabouts. You can accomlish this via your `tsconfig.json` file like so:
``` json
{
"compilerOptions": {
"maxNodeModuleJsDepth": 5
}
}
```
<!-- /INSTALL -->

@@ -82,8 +72,8 @@

``` javascript
```javascript
let fetches = 0
const cachely = require('cachely').create({
// The method that will fetch the data
retrieve () {
return new Promise(function (resolve) {
retrieve() {
return new Promise(function(resolve) {
// after a one second delay, return the number of fetches that we have done

@@ -97,3 +87,3 @@ setTimeout(() => resolve(++fetches), 1000)

// Defaults to one day
duration: 2000, // in this example we set it to two seconds
duration: 2000, // in this example we set it to two seconds

@@ -106,14 +96,46 @@ // An optional function that receives debugging log messages

// do an initial fetch of the dat
cachely.resolve().catch(console.error).then(console.log.bind(console, 'after one second as specified in our method, the result data should still be 1:'))
cachely
.resolve()
.catch(console.error)
.then(
console.log.bind(
console,
'after one second as specified in our method, the result data should still be 1:'
)
)
// do a subsequent fetch of the data that will be from the cach
cachely.resolve().catch(console.error).then(console.log.bind(console, 'after a tiny delay this will be from cache, the result data should still be 1:'))
cachely
.resolve()
.catch(console.error)
.then(
console.log.bind(
console,
'after a tiny delay this will be from cache, the result data should still be 1:'
)
)
// wait for the cache to invalidate itself
setTimeout(function () {
setTimeout(function() {
// do an second fetch of the data
cachely.resolve().catch(console.error).then(console.log.bind(console, 'after one second as specified in our method, the result data should be 2, as it was our second fetch:'))
cachely
.resolve()
.catch(console.error)
.then(
console.log.bind(
console,
'after one second as specified in our method, the result data should be 2, as it was our second fetch:'
)
)
// do a subsequent fetch of the data that will be from the cache
cachely.resolve().catch(console.error).then(console.log.bind(console, 'after a tiny delay this will be from cache, the result data should still be 2:'))
cachely
.resolve()
.catch(console.error)
.then(
console.log.bind(
console,
'after a tiny delay this will be from cache, the result data should still be 2:'
)
)

@@ -124,8 +146,23 @@ // peform a manual invalidation

// do a third fetch of the data
cachely.resolve().catch(console.error).then(console.log.bind(console, 'after one second as specified in our method, the result data should be 3, as it was our third fetch:'))
cachely
.resolve()
.catch(console.error)
.then(
console.log.bind(
console,
'after one second as specified in our method, the result data should be 3, as it was our third fetch:'
)
)
// do a subsequent fetch of the data that will be from the cache
cachely.resolve().catch(console.error).then(console.log.bind(console, 'after a tiny delay this will be from cache, the result data should still be 3:'))
cachely
.resolve()
.catch(console.error)
.then(
console.log.bind(
console,
'after a tiny delay this will be from cache, the result data should still be 3:'
)
)
}, 3000)
```

@@ -165,2 +202,3 @@

<span class="badge-githubsponsors"><a href="https://github.com/sponsors/balupton" title="Donate to this project using GitHub Sponsors"><img src="https://img.shields.io/badge/github-donate-yellow.svg" alt="GitHub Sponsors donate button" /></a></span>
<span class="badge-patreon"><a href="https://patreon.com/bevry" title="Donate to this project using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a></span>

@@ -167,0 +205,0 @@ <span class="badge-flattr"><a href="https://flattr.com/profile/balupton" title="Donate to this project using Flattr"><img src="https://img.shields.io/badge/flattr-donate-yellow.svg" alt="Flattr donate button" /></a></span>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc