UNPKG

@solid-data-modules/rdflib-utils

Version:

Utility functions for the development of Solid Data Modules for RDFLib.js

45 lines 1.64 kB
import { isNamedNode } from "rdflib"; import { solid } from "../namespaces/index.js"; /** * Used query data from a type index document */ export class TypeIndexQuery { constructor(store, typeIndexDoc) { this.store = store; this.typeIndexDoc = typeIndexDoc; } /** * Look up the instances in the type registration for the given RDF class * @param type - The RDF class to look up * @returns A list of the URIs of the found instances */ queryInstancesForClass(type) { return this.queryRegistrationsForType(type).instances; } getNamedNodes(which, registration) { return this.store .each(registration, solid(which), null, this.typeIndexDoc) .filter((it) => isNamedNode(it)) .map((it) => it); } queryRegistrationsForType(type) { const registrations = this.store.each(null, solid("forClass"), type, this.typeIndexDoc); return registrations .filter((it) => isNamedNode(it)) .map((it) => it) .map((registration) => { return { instances: this.getNamedNodes("instance", registration), instanceContainers: this.getNamedNodes("instanceContainer", registration), }; }) .reduce((acc, current) => ({ instances: [...acc.instances, ...current.instances], instanceContainers: [ ...acc.instanceContainers, ...current.instanceContainers, ], }), { instanceContainers: [], instances: [] }); } } //# sourceMappingURL=TypeIndexQuery.js.map