UNPKG

tripledoc

Version:

Library to read, create and update documents on a Solid Pod

97 lines (96 loc) 4.55 kB
import { TripleSubject } from './subject'; import { NodeRef } from '.'; /** * @ignore This is documented on use. */ export interface NewSubjectOptions { identifier?: string; identifierPrefix?: string; } export interface TripleDocument { /** * Add a subject — note that it is not written to the Pod until you call [[save]]. * * @param addSubject.options By default, Tripledoc will automatically generate an identifier with * which this Subject can be identified within the Document, and which * is likely to be unique. The `options` parameter has a number of * optional properties. The first, `identifier`, takes a string. If set, * Tripledoc will not automatically generate an identifier. Instead, the * value of this parameter will be used as the Subject's identifier. * The second optional parameter, `identifierPrefix`, is also a string. * If set, it will be prepended before this Subject's identifier, * whether that's autogenerated or not. * @returns A [[TripleSubject]] instance that can be used to define its properties. */ addSubject: (options?: NewSubjectOptions) => TripleSubject; /** * Find a Subject which has the value of `objectRef` for the Predicate `predicateRef`. * * @param findSubject.predicateRef The Predicate that must match for the desired Subject. * @param findSubject.objectRef The Object that must match for the desired Subject. * @returns `null` if no Subject matching `predicateRef` and `objectRef` is found, * a random one of the matching Subjects otherwise. */ findSubject: (predicateRef: NodeRef, objectRef: NodeRef) => TripleSubject | null; /** * Find Subjects which have the value of `objectRef` for the Predicate `predicateRef`. * * @param findSubjects.predicateRef - The Predicate that must match for the desired Subjects. * @param findSubjects.objectRef - The Object that must match for the desired Subjects. * @returns An array with every matching Subject, and an empty array if none match. */ findSubjects: (predicateRef: NodeRef, objectRef: NodeRef) => TripleSubject[]; /** * Given the IRI of a Subject, return an instantiated [[TripleSubject]] representing its values. * * @param getSubject.subjectRef IRI of the Subject to inspect. * @returns Instantiation of the Subject at `subjectRef`, ready for inspection. */ getSubject: (subjectRef: NodeRef) => TripleSubject; /** * Get all Subjects in this Document of a given type. * * @param getSubjectsOfType.typeRef IRI of the type the desired Subjects should be of. * @returns All Subjects in this Document that are of the given type. */ getSubjectsOfType: (typeRef: NodeRef) => TripleSubject[]; /** * @deprecated Replaced by [[getAclRef]] */ getAcl: () => NodeRef | null; /** * @ignore Experimental API, might change in the future to return an instantiated Document */ getAclRef: () => NodeRef | null; /** * @returns The IRI of this Document. */ asNodeRef: () => NodeRef; /** * Persist Subjects in this Document to the Pod. * * @param save.subjects Optional array of specific Subjects within this Document that should be * written to the Pod, i.e. excluding Subjects not in this array. * @return The Subjects that were persisted. */ save: (subjects?: TripleSubject[]) => Promise<TripleSubject[]>; } /** * Initialise a new Turtle document * * Note that this Document will not be created on the Pod until you call [[save]] on it. * * @param ref URL where this document should live * @param statements Initial statements to be included in this document */ export declare function createDocument(ref: NodeRef): TripleDocument; /** * Retrieve a document containing RDF triples * * Note that if you fetch the same document twice, it will be cached; only one * network request will be performed. * * @param documentRef Where the document lives. * @returns Representation of triples in the document at `uri`. */ export declare function fetchDocument(documentRef: NodeRef): Promise<TripleDocument>;