@knora/api
Version:
JavaScript library that handles API requests to Knora
170 lines • 7.53 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 __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var json2typescript_1 = require("json2typescript");
var Constants_1 = require("../../Constants");
var date_time_stamp_converter_1 = require("../../custom-converters/date-time-stamp-converter");
var id_converter_1 = require("../../custom-converters/id-converter");
var uri_converter_1 = require("../../custom-converters/uri-converter");
var read_write_resource_1 = require("../read-write-resource");
var type_guard_1 = require("../type-guard");
var ReadResource = /** @class */ (function (_super) {
__extends(ReadResource, _super);
function ReadResource() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.label = "";
_this.attachedToProject = "";
_this.attachedToUser = "";
_this.hasPermissions = "";
_this.userHasPermission = "";
_this.arkUrl = "";
_this.versionArkUrl = "";
_this.creationDate = "";
_this.lastModificationDateDate = undefined;
_this.properties = {};
_this.incomingReferences = [];
_this.outgoingReferences = [];
return _this;
}
/**
* Gets number of resource properties for this resource.
* Each resource property is counted once,
* regardless of how many values it has (if number of values > 1).
*/
ReadResource.prototype.getNumberOfProperties = function () {
return Object.keys(this.properties).length;
};
/**
* Gets the number of values for a given resource property.
*
* @param property the IRI of the property.
*/
ReadResource.prototype.getNumberOfValues = function (property) {
if (this.properties.hasOwnProperty(property)) {
return this.properties[property].length;
}
else {
return 0;
}
};
/**
* Gets the value type of a given resource property,
* or `false` if cannot be determined.
*
* @param property the IRI of the property.
*/
ReadResource.prototype.getValueType = function (property) {
if (this.entityInfo.properties.hasOwnProperty(property) && this.entityInfo.properties[property].objectType !== undefined) {
return this.entityInfo.properties[property].objectType;
}
else {
return false;
}
};
/**
* Gets all the values for a given resource property.
*
* @param property the IRI of the property.
*/
ReadResource.prototype.getValues = function (property) {
if (this.properties.hasOwnProperty(property)) {
return this.properties[property];
}
else {
return [];
}
};
/**
* Gets an array of string values representing the values of a property.
*
* @param property the IRI of the property.
* @param defaultStr placeholder if there is no string representation of a value.
*/
ReadResource.prototype.getValuesAsStringArray = function (property, defaultStr) {
if (defaultStr === void 0) { defaultStr = "?"; }
var vals = this.getValues(property);
return vals.map(function (val) {
return val.strval === undefined ? defaultStr : val.strval;
});
};
/**
* Gets all the values for a given resource property as instances of the requested type.
* If the value cannot be casted to the requested type, an error is thrown.
*
* @param property the IRI of the property.
* @param valueType the requested type of the value.
*/
ReadResource.prototype.getValuesAs = function (property, valueType) {
return this.getValues(property).map(function (val) {
if (type_guard_1.TypeGuard.typeGuard(val, valueType)) {
return val;
}
else {
throw new Error("Cannot cast to type " + valueType);
}
});
};
__decorate([
json2typescript_1.JsonProperty(Constants_1.Constants.Label, String),
__metadata("design:type", String)
], ReadResource.prototype, "label", void 0);
__decorate([
json2typescript_1.JsonProperty(Constants_1.Constants.AttachedToProject, id_converter_1.IdConverter),
__metadata("design:type", String)
], ReadResource.prototype, "attachedToProject", void 0);
__decorate([
json2typescript_1.JsonProperty(Constants_1.Constants.AttachedToUser, id_converter_1.IdConverter),
__metadata("design:type", String)
], ReadResource.prototype, "attachedToUser", void 0);
__decorate([
json2typescript_1.JsonProperty(Constants_1.Constants.HasPermissions, String),
__metadata("design:type", String)
], ReadResource.prototype, "hasPermissions", void 0);
__decorate([
json2typescript_1.JsonProperty(Constants_1.Constants.UserHasPermission, String),
__metadata("design:type", String)
], ReadResource.prototype, "userHasPermission", void 0);
__decorate([
json2typescript_1.JsonProperty(Constants_1.Constants.ArkUrl, uri_converter_1.UriConverter),
__metadata("design:type", String)
], ReadResource.prototype, "arkUrl", void 0);
__decorate([
json2typescript_1.JsonProperty(Constants_1.Constants.VersionArkUrl, uri_converter_1.UriConverter),
__metadata("design:type", String)
], ReadResource.prototype, "versionArkUrl", void 0);
__decorate([
json2typescript_1.JsonProperty(Constants_1.Constants.CreationDate, date_time_stamp_converter_1.DateTimeStampConverter),
__metadata("design:type", String)
], ReadResource.prototype, "creationDate", void 0);
__decorate([
json2typescript_1.JsonProperty(Constants_1.Constants.LastModificationDate, date_time_stamp_converter_1.DateTimeStampConverter, true),
__metadata("design:type", String)
], ReadResource.prototype, "lastModificationDateDate", void 0);
ReadResource = __decorate([
json2typescript_1.JsonObject("ReadResource")
], ReadResource);
return ReadResource;
}(read_write_resource_1.ReadWriteResource));
exports.ReadResource = ReadResource;
//# sourceMappingURL=read-resource.js.map