UNPKG

@treecg/curation

Version:

This library implements a class (Curator) with methods to curate an announcement LDES in LDP.

172 lines (171 loc) 7.51 kB
/*************************************** * Title: Curator * Description: Contains the class with methods to curate an LDES in LDP, creating a curated LDES in LDP * Author: Wout Slabbinck (wout.slabbinck@ugent.be) * Created on 03/12/2021 *****************************************/ import { Session } from "@rubensworks/solid-client-authn-isomorphic"; import { Announce, DataService, DataSet, View } from "@treecg/ldes-announcements/dist/util/Interfaces"; export interface CurationConfig { ldesIRI: string; curatedIRI: string; synchronizedIRI: string; } export declare class Curator { private readonly logger; private ldesIRI; private session; private curatedIRI; private synchronizedIRI; private curatedLDESinSolid; constructor(config: CurationConfig, session: Session); /** * Checks whether the user is logged in * Load the curatedLDES in Solid * Creates the curatedLDES in Solid if it does not exist (requires certain access control permissions on the curated IRI) * Furthermore verifies that the LDES exists as well. * @param privateCuration When true, the curated LDES in LDP is only visible to the webId from the session. (Default: True) * @return {Promise<void>} */ init(privateCuration?: boolean): Promise<void>; /** * Accept a member to the curated LDES. * Also removes the iri from the synced Collection * @param memberIRI * @returns {Promise<Response>} */ accept(memberIRI: string): Promise<Response>; accept(memberIRI: string, member: DataSet | DataService | View, timestamp: number): Promise<Response>; /** * Curation action reject: Which means that a member is removed from the synced collection * @param memberIRI * @param timestamp * @returns {Promise<Response>} */ reject(memberIRI: string, timestamp?: number): Promise<Response>; /** * Fetch the timestamp of an IRI by reading the Last-modified header. * For a member in an LDES, this will be the same as the creation time (as member are immutable * , indicating that they MUST NOT be changed after creation) * @param iri IRI of the LDP Resource * @returns {Promise<number>} */ private getTimestamp; /** * Removes a member from the synced collection stored at the syncedURI * @param memberIRI IRI of the member * @param timestamp timestamp of creation of the member in the LDES in LDP * @returns {Promise<Response>} */ private removeFromSyncedCollection; /** * Synchronize the Synced collection with the LDES in LDP * * The synced collection is a TREE collection with as members the URIs of the LDES in LDP. Each member also has a timestamp. * A synchronize operations looks at the last synced time and adds all members which were added to the LDES to the synced collection. * * @returns {Promise<void>} */ synchronize(): Promise<void>; /** * Extract the member and its metadata from an LDES in LDP. Also extract the announcement itself * Currently, only View, DataSet and DataService can be parsed (interface can be found in LDES-Announcements) * @param announcementIRI * @returns {Promise<{iri: string, type: string, value: View, announcement: Announce} | {iri: string, type: string, value: DataSet, announcement: Announce} | {iri: string, type: string, value: DataService, announcement: Announce}>} */ extractMember(announcementIRI: string): Promise<{ iri: string; type: string; value: View | DataSet | DataService; announcement: Announce; }>; /** * Flow for the first time an LDES in LDP has to be synchronized * * @param LDESRootNode IRI of the LDES in LDP root node * @param syncedRootNode IRI of the root node of the synced collection * @param LDESRootCollectionIRI IRI of the LDES in LDP collection */ private firstTimeSync; /** * Flow for the subsequent times an LDES in LDP has to be synchronized * * @param LDESRootNode IRI of the LDES in LDP root node * @param syncedRootNode IRI of the root node of the synced collection * @param LDESRootCollectionIRI IRI of the LDES in LDP collection * @param syncedStore The store of the synced root node */ private otherTimesSync; private updateCurrentMostRecentRelation; /** * Updates the synced root node with the new relations since last sync time. * Also returns the new relation nodes which members should be added to the synced collection as well. * * @param LDESRootNode * @param syncedStore * @param syncedRootNode * @returns {Promise<string[]>} */ private updateRootNode; /** * Retrieve the URIs of the most recent members of the synced collection. * This method can be further optimised as currently the whole collection is fetched even though a part is wanted * @param amount number of members that are needed * @param startPoint Startpoint in the synced collection * @returns {Promise<{timestamp: number, memberIRI: string}[]>} sorted list (newest members first) */ getRecentMembers(amount: number, startPoint?: number): Promise<{ timestamp: number; memberIRI: string; }[]>; /** * Convert resources in a container of the LDES in LDP to members of the collection and return as a store * @param store store of the LDP Container * @param iri iri of the LDP Container * @param LDESRootCollectionIRI iri of the LDES in LDP EventStream * @returns {Store} */ private extractMembers; /** * Extract the members of a relation node in the LDES in LDP (where the relation node is an LDP Container) * And Put all those members together with their created time in the synchronized collection * @param iri IRI of an LDP container (which is the relation node) * @param LDESCollectionIRI The IRI of the Event Stream (=Collection) of the LDES in LDP * @returns {Promise<void>} */ private synchronizeMembersFromRelation; /** * Using a store containing several relations, calculate the most recent relation * @param syncedStore * @returns {any} */ private calculateMostRecentRelation; /** * Extract a timestamp (ms) from an RDF Literal * @param dateTimeLiteral * @returns {number} */ private extractTimeFromLiteral; /** * Convert a timestamp (ms) to an RDF Literal * @param timestamp * @returns {Literal} */ private timestampToLiteral; /** * Transforms an ldes relation iri to a synchronized relation iri * E.g. ldesIRI is "https://tree.linkeddatafragments.org/announcements/" * and synchronizedIRI is "https://tree.linkeddatafragments.org/datasets/synced/" * Then "https://tree.linkeddatafragments.org/announcements/1636985640000/" becomes * "https://tree.linkeddatafragments.org/datasets/synced/1636985640000" * @param iri * @returns {string} */ private ldesRelationToSyncedRelationIRI; /** * Transforms a synchronized relation iri to an ldes relation iri * @param iri * @returns {string} */ private syncedRelationtoLDESRelationIRI; }