@knora/api
Version:
JavaScript library that handles API requests to Knora
67 lines • 3.22 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 ontology_metadata_1 = require("../../../models/v2/ontologies/ontology-metadata");
var OntologyConversionUtil_1 = require("../../../models/v2/ontologies/OntologyConversionUtil");
var endpoint_1 = require("../../endpoint");
var jsonld = require("jsonld/dist/jsonld.js");
/**
* Handles requests to the ontologies route of the Knora API.
*/
var OntologiesEndpoint = /** @class */ (function (_super) {
__extends(OntologiesEndpoint, _super);
function OntologiesEndpoint() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Requests metadata about all ontologies from Knora.
*/
OntologiesEndpoint.prototype.getOntologiesMetadata = function () {
var _this = this;
// TODO: Do not hard-code the URL and http call params, generate this from Knora
return this.httpGet("/metadata").pipe(operators_1.mergeMap(function (ajaxResponse) {
// TODO: @rosenth Adapt context object
// TODO: adapt getOntologyIriFromEntityIri
return jsonld.compact(ajaxResponse.response, {});
}), operators_1.map(function (jsonldobj) {
return _this.jsonConvert.deserializeObject(jsonldobj, ontology_metadata_1.OntologiesMetadata);
}), operators_1.catchError(function (error) {
return _this.handleError(error);
}));
};
/**
* Requests an ontology from Knora and converts it to a `ReadOntology`.
*
* @param ontologyIri the IRI of the ontology to be requested.
* @return the ontology or an error.
*/
OntologiesEndpoint.prototype.getOntology = function (ontologyIri) {
var _this = this;
// TODO: Do not hard-code the URL and http call params, generate this from Knora
return this.httpGet("/allentities/" + encodeURIComponent(ontologyIri)).pipe(operators_1.mergeMap(function (ajaxResponse) {
// TODO: @rosenth Adapt context object
// TODO: adapt getOntologyIriFromEntityIri
return jsonld.compact(ajaxResponse.response, {});
}), operators_1.map(function (jsonldobj) {
return OntologyConversionUtil_1.OntologyConversionUtil.convertOntology(jsonldobj, _this.jsonConvert, _this.knoraApiConfig);
}), operators_1.catchError(function (error) {
return _this.handleError(error);
}));
};
return OntologiesEndpoint;
}(endpoint_1.Endpoint));
exports.OntologiesEndpoint = OntologiesEndpoint;
//# sourceMappingURL=ontologies-endpoint.js.map