@internetarchive/collection-name-cache
Advanced tools
Comparing version 0.2.7-alpha.1 to 0.2.7-alpha.2
@@ -22,2 +22,8 @@ import type { SearchServiceInterface } from '@internetarchive/search-service'; | ||
preloadIdentifiers(identifiers: string[]): Promise<void>; | ||
/** | ||
* Adds known identifier-title mappings to the cache. | ||
* | ||
* @param identifierTitleMap | ||
*/ | ||
addKnownTitles(identifierTitleMap: Record<string, string>): void; | ||
} | ||
@@ -36,2 +42,4 @@ export declare class CollectionNameCache implements CollectionNameCacheInterface { | ||
preloadIdentifiers(identifiers: string[]): Promise<void>; | ||
/** @inheritdoc */ | ||
addKnownTitles(identifierTitleMap: Record<string, string>): void; | ||
private pendingIdentifierQueue; | ||
@@ -38,0 +46,0 @@ private pendingPromises; |
@@ -66,2 +66,12 @@ export class CollectionNameCache { | ||
} | ||
/** @inheritdoc */ | ||
addKnownTitles(identifierTitleMap) { | ||
Object.entries(identifierTitleMap).forEach(([identifier, title]) => { | ||
const lowercaseIdentifier = identifier.toLowerCase(); | ||
this.collectionNameCache[lowercaseIdentifier] = { | ||
name: title, | ||
lastAccess: Date.now(), | ||
}; | ||
}); | ||
} | ||
async startPendingIdentifierTimer() { | ||
@@ -68,0 +78,0 @@ if (this.fetchTimeout) |
@@ -10,3 +10,3 @@ { | ||
"author": "Internet Archive", | ||
"version": "0.2.7-alpha.1", | ||
"version": "0.2.7-alpha.2", | ||
"main": "dist/index.js", | ||
@@ -13,0 +13,0 @@ "module": "dist/index.js", |
@@ -26,2 +26,9 @@ /* eslint-disable camelcase */ | ||
preloadIdentifiers(identifiers: string[]): Promise<void>; | ||
/** | ||
* Adds known identifier-title mappings to the cache. | ||
* | ||
* @param identifierTitleMap | ||
*/ | ||
addKnownTitles(identifierTitleMap: Record<string, string>): void; | ||
} | ||
@@ -96,2 +103,13 @@ | ||
/** @inheritdoc */ | ||
addKnownTitles(identifierTitleMap: Record<string, string>): void { | ||
Object.entries(identifierTitleMap).forEach(([identifier, title]) => { | ||
const lowercaseIdentifier = identifier.toLowerCase(); | ||
this.collectionNameCache[lowercaseIdentifier] = { | ||
name: title, | ||
lastAccess: Date.now(), | ||
}; | ||
}); | ||
} | ||
private pendingIdentifierQueue: Set<string> = new Set<string>(); | ||
@@ -98,0 +116,0 @@ |
Sorry, the diff of this file is not supported yet
154860
1577