UNPKG

@knora/api

Version:

JavaScript library that handles API requests to Knora

104 lines 5.79 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 api_response_data_1 = require("../../../models/api-response-data"); var endpoint_1 = require("../../endpoint"); var list_info_response_1 = require("../../../models/admin/list-info-response"); var list_node_info_response_1 = require("../../../models/admin/list-node-info-response"); var list_response_1 = require("../../../models/admin/list-response"); var lists_response_1 = require("../../../models/admin/lists-response"); /** * An endpoint for working with Knora lists. */ var ListsEndpoint = /** @class */ (function (_super) { __extends(ListsEndpoint, _super); function ListsEndpoint() { return _super !== null && _super.apply(this, arguments) || this; } /** * Returns a list of lists. */ ListsEndpoint.prototype.getLists = function () { var _this = this; return this.httpGet("").pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, lists_response_1.ListsResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Returns a list of lists in a project. * * @param projectIri The IRI of the project. */ ListsEndpoint.prototype.getListsInProject = function (projectIri) { var _this = this; return this.httpGet("?projectIri=" + encodeURIComponent(projectIri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, lists_response_1.ListsResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Creates a list. * * @param listInfo Information about the list to be created. */ ListsEndpoint.prototype.createList = function (listInfo) { var _this = this; return this.httpPost("", this.jsonConvert.serializeObject(listInfo)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, list_response_1.ListResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Gets a list. * * @param iri The IRI of the list. */ ListsEndpoint.prototype.getList = function (iri) { var _this = this; return this.httpGet("/" + encodeURIComponent(iri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, list_response_1.ListResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Updates information about a list. * * @param listInfo Information about the list to be created. */ ListsEndpoint.prototype.updateListInfo = function (listInfo) { var _this = this; return this.httpPut("/" + encodeURIComponent(listInfo.listIri), this.jsonConvert.serializeObject(listInfo)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, list_info_response_1.ListInfoResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Creates a child node in a list. * * @param node The node to be created. */ ListsEndpoint.prototype.createChildNode = function (node) { var _this = this; return this.httpPost("/" + encodeURIComponent(node.parentNodeIri), this.jsonConvert.serializeObject(node)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, list_node_info_response_1.ListNodeInfoResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Returns information about a list. * * @param iri The IRI of the list. */ ListsEndpoint.prototype.getListInfo = function (iri) { var _this = this; return this.httpGet("/infos/" + encodeURIComponent(iri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, list_info_response_1.ListInfoResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; /** * Returns information about a list node. * * @param iri The IRI of the node. */ ListsEndpoint.prototype.getListNodeInfo = function (iri) { var _this = this; return this.httpGet("/nodes/" + encodeURIComponent(iri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, list_node_info_response_1.ListNodeInfoResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); })); }; return ListsEndpoint; }(endpoint_1.Endpoint)); exports.ListsEndpoint = ListsEndpoint; //# sourceMappingURL=lists-endpoint.js.map