UNPKG

@dasch-swiss/dsp-js

Version:
67 lines 2.29 kB
import { map } from 'rxjs'; import { ListConversionUtil } from '../models/v2/lists/list-conversion-util'; import { GenericCache } from './GenericCache'; /** * Caches list nodes obtained from Knora. * As an optimization, the whole list is requested and cached (all of its nodes) once a list node has been rquested. */ export class ListNodeV2Cache extends GenericCache { constructor(v2Endpoint) { super(); this.v2Endpoint = v2Endpoint; } /** * Given a list node IRI, gets it from the cache. * * The root node of a list should not be requested using this method. * This should be left to dependency handling to optimize caching. * * @param nodeIri the IRI of the list node to be returned. */ getNode(nodeIri) { return this.getItem(nodeIri); } /** * Public method to access the reloadItem method * * @param key the id of the information to be returned. * @return the item */ reloadCachedItem(key) { return this.reloadItem(key); } getKeyOfItem(item) { return item.id; } requestItemFromKnora(key, isDependency) { if (!isDependency) { // not a dependency, get the list node return this.v2Endpoint.list.getNode(key).pipe(map((node) => [node])); } else { // a dependency, get the whole list const list = this.v2Endpoint.list.getList(key); return list.pipe(map(rootNode => { // Transform the list into an array of all list nodes const nodes = ListConversionUtil.collectNodes(rootNode); return nodes.map(node => { // Remove references to child nodes to make this consistent: // node route does not return children, list route does node.children = []; return node; }); })); } } getDependenciesOfItem(item) { if (item.hasRootNode !== undefined) { // The whole list will be fetched as a dependency // of any given list node return [item.hasRootNode]; } else { return []; } } } //# sourceMappingURL=ListNodeV2Cache.js.map