UNPKG

@knora/api

Version:

JavaScript library that handles API requests to Knora

78 lines 3.21 kB
"use strict"; 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var operators_1 = require("rxjs/operators"); var list_conversion_util_1 = require("../models/v2/lists/list-conversion-util"); var GenericCache_1 = require("./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); }; 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(operators_1.map(function (node) { return [node]; })); } else { // a dependency, get the whole list var list = this.v2Endpoint.list.getList(key); return list.pipe(operators_1.map(function (rootNode) { // Transform the list into an array of all list nodes var nodes = list_conversion_util_1.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_1.GenericCache)); exports.ListNodeV2Cache = ListNodeV2Cache; //# sourceMappingURL=ListNodeV2Cache.js.map