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

vsm-dictionary-cacher

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vsm-dictionary-cacher - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

2

package.json
{
"name": "vsm-dictionary-cacher",
"version": "1.0.4",
"version": "1.0.5",
"description": "Wrapper around a VSM-dictionary, that manages a cache of string-match results",

@@ -5,0 +5,0 @@ "main": "src/VsmDictionaryCacher.js",

@@ -101,6 +101,12 @@ /*

// If a shorter string (for same options) already returned no matches,
// then we can also return 'no matches' now.
// - If a shorter string (for same options) already returned no matches,
// then we do not need to run a query (to the VsmDictionary-subclass).
// - However, there can still be number-matches or exact refTerm-matches,
// for which a substring has a cacheEmpties hit.
// So we still need to call the VsmDictionary-parent-class's
// `addExtraMatchesForString()`, but based on an empty query-result.
if (this._getCacheMOEmptiesPrediction(str, options)) {
return callAsync(cb, null, { items: [] });
return this.addExtraMatchesForString(str, { items: [] }, options,
(err, res) => callAsync(cb, err, res)
);
}

@@ -107,0 +113,0 @@

@@ -13,2 +13,3 @@ const cacher = require('./VsmDictionaryCacher');

var called; // This will be set to 1 if the stub getMatchesFor..() is called.
var calledParent; // Is 1 if stub's parent's addExtraMatchesFor..() is called.
var result; // The stub function will return this, whatever it is set to.

@@ -21,4 +22,11 @@ // (See below).

function makeVsmDictionaryStub(cacheOptions, delay = 0, error = null) {
Dictionary = class VsmDictionaryStub {
class VsmDictionaryStub {
addExtraMatchesForString(str, arr, options, cb) {
setTimeout( () => { calledParent = 1; cb(null, arr); }, 0 );
}
};
class VsmDictionarySubclassStub extends VsmDictionaryStub {
// This stub function would normally *query* an underlying datastore.

@@ -42,3 +50,3 @@ // So if it is called, it means that the function which overrides it

};
CachedDictionary = cacher(Dictionary, cacheOptions);
CachedDictionary = cacher(VsmDictionarySubclassStub, cacheOptions);
dict = new CachedDictionary();

@@ -62,2 +70,3 @@ }

called = 0;
calledParent = 0;
result = { items: ['default'] };

@@ -378,2 +387,15 @@ });

it('still calls `VsmDictionary.addExtraMatchesForString()`, for "1e3", ' +
'after "1e" returned no results', function(cb) {
makeVsmDictionaryStub();
result = _R0;
dict.getMatchesForString('1e', {}, (err, res) => {
calledParent = 0;
dict.getMatchesForString('1e3', {}, (err, res) => {
calledParent.should.equal(1);
cb();
});
});
});
describe('(timing test)', function(cb) {

@@ -380,0 +402,0 @@ // If an `it()`-test throws an error, and it contained a `clock.restore()`,

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