@knora/api
Version:
JavaScript library that handles API requests to Knora
67 lines • 2.91 kB
JavaScript
;
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_node_v2_1 = require("../../../models/v2/lists/list-node-v2");
var endpoint_1 = require("../../endpoint");
var jsonld = require("jsonld/dist/jsonld.js");
/**
* Handles requests to the lists route of the Knora API.
*/
var ListsEndpoint = /** @class */ (function (_super) {
__extends(ListsEndpoint, _super);
function ListsEndpoint() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Get a specific list node.
*
* @param nodeIri the Ir of the list node to be fetched.
*/
ListsEndpoint.prototype.getNode = function (nodeIri) {
var _this = this;
// TODO: Do not hard-code the URL and http call params, generate this from Knora
return this.httpGet("/node/" + encodeURIComponent(nodeIri)).pipe(operators_1.mergeMap(function (ajaxResponse) {
// TODO: @rosenth Adapt context object
// TODO: adapt getOntologyIriFromEntityIri
return jsonld.compact(ajaxResponse.response, {});
}), operators_1.map(function (res) {
return _this.jsonConvert.deserialize(res, list_node_v2_1.ListNodeV2);
}), operators_1.catchError(function (error) {
return _this.handleError(error);
}));
};
/**
* Get an entire list.
*
* @param rootNodeIri the list's root node Iri.
*/
ListsEndpoint.prototype.getList = function (rootNodeIri) {
var _this = this;
// TODO: Do not hard-code the URL and http call params, generate this from Knora
return this.httpGet("/lists/" + encodeURIComponent(rootNodeIri)).pipe(operators_1.mergeMap(function (ajaxResponse) {
// TODO: @rosenth Adapt context object
// TODO: adapt getOntologyIriFromEntityIri
return jsonld.compact(ajaxResponse.response, {});
}), operators_1.map(function (res) {
return _this.jsonConvert.deserialize(res, list_node_v2_1.ListNodeV2);
}), operators_1.catchError(function (error) {
return _this.handleError(error);
}));
};
return ListsEndpoint;
}(endpoint_1.Endpoint));
exports.ListsEndpoint = ListsEndpoint;
//# sourceMappingURL=lists-endpoint.js.map