alcaeus-model
Version:
rdfine models for Alcaeus, Hydra client
78 lines (77 loc) • 3.34 kB
JavaScript
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);
};
import { SupportedPropertyMixin, OperationMixin } from '@rdfine/hydra';
import { property } from '@tpluscode/rdfine';
import TypeCollection from '@tpluscode/rdfine/lib/TypeCollection';
import { hydra, rdfs } from '@tpluscode/rdf-ns-builders';
export function ClassMixin(Base) {
class ClassClass extends Base {
get types() {
return new TypeCollection(this, true);
}
get supportedOperation() {
return [...this.getTypeHierarchy()].reduce((operations, type) => {
return type.__allSupportedOperations.reduce((operations, operation) => {
if (operations.find(current => current.equals(operation))) {
return operations;
}
return [...operations, operation];
}, operations);
}, []);
}
get supportedProperty() {
return [...this.getTypeHierarchy()].reduce((properties, type) => {
return type.__allSupportedProperties.reduce((properties, property) => {
if (properties.find(current => current.property?.equals(property.property))) {
return properties;
}
return [...properties, property];
}, properties);
}, []);
}
*getTypeHierarchy() {
yield this;
for (const superclass of this.__subClassOf) {
for (const type of superclass.getTypeHierarchy()) {
yield type;
}
}
}
}
__decorate([
property.resource({
path: rdfs.subClassOf,
values: 'array',
as: [ClassMixin],
implicitTypes: [rdfs.Class, hydra.Class],
}),
__metadata("design:type", Array)
], ClassClass.prototype, "__subClassOf", void 0);
__decorate([
property.resource({
path: hydra.supportedOperation,
values: 'array',
as: [OperationMixin],
subjectFromAllGraphs: true,
}),
__metadata("design:type", Array)
], ClassClass.prototype, "__allSupportedOperations", void 0);
__decorate([
property.resource({
path: hydra.supportedProperty,
values: 'array',
as: [SupportedPropertyMixin],
subjectFromAllGraphs: true,
}),
__metadata("design:type", Array)
], ClassClass.prototype, "__allSupportedProperties", void 0);
return ClassClass;
}
ClassMixin.appliesTo = hydra.Class;