UNPKG

@dasch-swiss/dsp-js

Version:

JavaScript library that handles API requests to Knora

87 lines 3.48 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); 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. */ var ListNodeV2Cache = /** @class */ (function (_super) { __extends(ListNodeV2Cache, _super); function ListNodeV2Cache(v2Endpoint) { var _this = _super.call(this) || this; _this.v2Endpoint = v2Endpoint; return _this; } /** * 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. */ ListNodeV2Cache.prototype.getNode = function (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 */ ListNodeV2Cache.prototype.reloadCachedItem = function (key) { return this.reloadItem(key); }; ListNodeV2Cache.prototype.getKeyOfItem = function (item) { return item.id; }; ListNodeV2Cache.prototype.requestItemFromKnora = function (key, isDependency) { if (!isDependency) { // not a dependency, get the list node return this.v2Endpoint.list.getNode(key) .pipe(map(function (node) { return [node]; })); } else { // a dependency, get the whole list var list = this.v2Endpoint.list.getList(key); return list.pipe(map(function (rootNode) { // Transform the list into an array of all list nodes var nodes = ListConversionUtil.collectNodes(rootNode); return nodes.map(function (node) { // Remove references to child nodes to make this consistent: // node route does not return children, list route does node.children = []; return node; }); })); } }; ListNodeV2Cache.prototype.getDependenciesOfItem = function (item) { if (item.hasRootNode !== undefined) { // The whole list will be fetched as a dependency // of any given list node return [item.hasRootNode]; } else { return []; } }; return ListNodeV2Cache; }(GenericCache)); export { ListNodeV2Cache }; //# sourceMappingURL=ListNodeV2Cache.js.map