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

@internetarchive/collection-name-cache

Package Overview
Dependencies
Maintainers
15
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@internetarchive/collection-name-cache - npm Package Compare versions

Comparing version 0.0.1-alpha.4 to 0.0.1-alpha.5

7

dist/src/collection-name-cache.d.ts

@@ -26,5 +26,7 @@ import { SearchServiceInterface } from '@internetarchive/search-service';

private cacheTtl;
private defaultLoadDelay;
private loadDelay;
private defaultPruningAge;
private defaultPruningInterval;
private defaultLoadInterval;
private fetchTimeout;
/** @inheritdoc */

@@ -44,6 +46,7 @@ collectionNameFor(identifier: string): Promise<string | null>;

localCache?: LocalCacheInterface;
loadInterval?: number;
loadDelay?: number;
pruneInterval?: number;
pruningAge?: number;
});
private startPendingIdentifierTimer;
private loadFromCache;

@@ -50,0 +53,0 @@ private loadPendingIdentifiers;

@@ -9,5 +9,9 @@ /* eslint-disable camelcase */

this.cacheTtl = 60 * 60 * 24 * 7;
this.defaultLoadDelay = 100; // ms
// we want to let identifiers accumulate in the queue before we start
// loading them from the search service so this is how long we wait until we start loading
this.loadDelay = 100; // ms
this.defaultPruningAge = 1000 * 60 * 60 * 24 * 7;
this.defaultPruningInterval = 1000 * 10;
this.defaultLoadInterval = 250; // ms
this.fetchTimeout = null;
this.pendingIdentifierQueue = new Set();

@@ -20,7 +24,5 @@ this.pendingPromises = {};

this.localCache = options.localCache;
this.pruningAge = (_a = options.pruningAge) !== null && _a !== void 0 ? _a : this.pruningAge;
this.loadDelay = (_a = options.loadDelay) !== null && _a !== void 0 ? _a : this.defaultLoadDelay;
this.pruningAge = (_b = options.pruningAge) !== null && _b !== void 0 ? _b : this.pruningAge;
setInterval(async () => {
await this.loadPendingIdentifiers();
}, (_b = options.loadInterval) !== null && _b !== void 0 ? _b : this.defaultLoadInterval);
setInterval(async () => {
await this.loadFromCache();

@@ -41,2 +43,3 @@ await this.pruneCache();

}
this.startPendingIdentifierTimer();
return new Promise(resolve => {

@@ -63,4 +66,12 @@ var _a;

}
await this.loadPendingIdentifiers();
this.startPendingIdentifierTimer();
}
async startPendingIdentifierTimer() {
if (this.fetchTimeout)
return;
this.fetchTimeout = window.setTimeout(() => {
this.loadPendingIdentifiers();
this.fetchTimeout = null;
}, this.loadDelay);
}
async loadFromCache() {

@@ -67,0 +78,0 @@ if (!this.localCache || this.cacheLoaded)

@@ -12,3 +12,3 @@ import { expect } from '@open-wc/testing';

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 50,
});

@@ -33,3 +33,3 @@ await Promise.all([

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 50,
});

@@ -50,3 +50,3 @@ const results = await Promise.all([

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 50,
});

@@ -67,3 +67,3 @@ const results = await Promise.all([

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 50,
});

@@ -84,3 +84,3 @@ await Promise.all([

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 50,
});

@@ -101,3 +101,3 @@ const results = await Promise.all([

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 25,
});

@@ -109,2 +109,3 @@ await collectionNameFetcher.preloadIdentifiers([

]);
await promisedSleep(50);
// should have loaded here

@@ -129,3 +130,3 @@ expect(mockSearchService.searchCallCount).to.equal(1);

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 25,
});

@@ -137,2 +138,3 @@ await collectionNameFetcher.preloadIdentifiers([

]);
await promisedSleep(50);
// should have loaded here

@@ -150,3 +152,3 @@ expect(mockSearchService.searchCallCount).to.equal(1);

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 25,
});

@@ -158,2 +160,3 @@ await collectionNameFetcher.preloadIdentifiers([

]);
await promisedSleep(50);
// should have loaded here

@@ -165,2 +168,4 @@ expect(mockSearchService.searchCallCount).to.equal(1);

]);
// the query won't fire until the load delay has passed (25ms) so wait for it
await promisedSleep(50);
expect((_a = mockSearchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('identifier:(beep-collection)');

@@ -175,3 +180,3 @@ // no additional call should have been made

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 25,
pruneInterval: 20,

@@ -185,2 +190,3 @@ pruningAge: 75,

]);
await promisedSleep(50);
expect(mockSearchService.searchCallCount).to.equal(1);

@@ -187,0 +193,0 @@ await promisedSleep(50);

@@ -10,3 +10,3 @@ {

"author": "Internet Archive",
"version": "0.0.1-alpha.4",
"version": "0.0.1-alpha.5",
"main": "dist/index.js",

@@ -13,0 +13,0 @@ "module": "dist/index.js",

@@ -46,2 +46,8 @@ /* eslint-disable camelcase */

private defaultLoadDelay = 100; // ms
// we want to let identifiers accumulate in the queue before we start
// loading them from the search service so this is how long we wait until we start loading
private loadDelay = 100; // ms
private defaultPruningAge = 1000 * 60 * 60 * 24 * 7;

@@ -51,3 +57,3 @@

private defaultLoadInterval = 250; // ms
private fetchTimeout: number | null = null;

@@ -66,2 +72,4 @@ /** @inheritdoc */

this.startPendingIdentifierTimer();
return new Promise(resolve => {

@@ -90,3 +98,3 @@ this.pendingIdentifierQueue.add(lowercaseIdentifier);

}
await this.loadPendingIdentifiers();
this.startPendingIdentifierTimer();
}

@@ -114,3 +122,3 @@

localCache?: LocalCacheInterface;
loadInterval?: number;
loadDelay?: number;
pruneInterval?: number;

@@ -121,9 +129,6 @@ pruningAge?: number;

this.localCache = options.localCache;
this.loadDelay = options.loadDelay ?? this.defaultLoadDelay;
this.pruningAge = options.pruningAge ?? this.pruningAge;
setInterval(async () => {
await this.loadPendingIdentifiers();
}, options.loadInterval ?? this.defaultLoadInterval);
setInterval(async () => {
await this.loadFromCache();

@@ -134,2 +139,10 @@ await this.pruneCache();

private async startPendingIdentifierTimer(): Promise<void> {
if (this.fetchTimeout) return;
this.fetchTimeout = window.setTimeout(() => {
this.loadPendingIdentifiers();
this.fetchTimeout = null;
}, this.loadDelay);
}
private async loadFromCache(): Promise<void> {

@@ -136,0 +149,0 @@ if (!this.localCache || this.cacheLoaded) return;

@@ -15,3 +15,3 @@ import { expect } from '@open-wc/testing';

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 50,
});

@@ -41,3 +41,3 @@

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 50,
});

@@ -61,3 +61,3 @@

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 50,
});

@@ -81,3 +81,3 @@

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 50,
});

@@ -102,3 +102,3 @@

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 50,
});

@@ -122,3 +122,3 @@

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 25,
});

@@ -132,2 +132,4 @@

await promisedSleep(50);
// should have loaded here

@@ -156,3 +158,3 @@ expect(mockSearchService.searchCallCount).to.equal(1);

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 25,
});

@@ -166,2 +168,4 @@

await promisedSleep(50);
// should have loaded here

@@ -181,3 +185,3 @@ expect(mockSearchService.searchCallCount).to.equal(1);

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 25,
});

@@ -191,2 +195,4 @@

await promisedSleep(50);
// should have loaded here

@@ -200,2 +206,5 @@ expect(mockSearchService.searchCallCount).to.equal(1);

// the query won't fire until the load delay has passed (25ms) so wait for it
await promisedSleep(50);
expect(mockSearchService.searchParams?.query).to.equal(

@@ -214,3 +223,3 @@ 'identifier:(beep-collection)'

searchService: mockSearchService,
loadInterval: 50,
loadDelay: 25,
pruneInterval: 20,

@@ -226,2 +235,4 @@ pruningAge: 75,

await promisedSleep(50);
expect(mockSearchService.searchCallCount).to.equal(1);

@@ -228,0 +239,0 @@ await promisedSleep(50);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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