@inrupt/solid-client
    Preparing search index...

    A Parser takes a string and generates Quads.

    By providing an object conforming to the Parser interface, you can handle RDF serialisations other than text/turtle, which @inrupt/solid-client supports by default. This can be useful to retrieve RDF data from sources other than a Solid Pod.

    A Parser has the following properties:

    • onQuad: Registers the callback with which parsed Quads can be provided to @inrupt/solid-client.
    • onError: Registers the callback with which @inrupt/solid-client can be notified of errors parsing the input.
    • onComplete: Registers the callback with which @inrupt/solid-client can be notified that parsing is complete.
    • parse: Accepts the serialised input string and an object containing the input Resource's metadata. The input metadata can be read using functions like [[getSourceUrl]] and [[getContentType]].

    For example, the following defines a parser that reads an RDFa serialisation using the rdfa-streaming-parser library:

    import { RdfaParser } from "rdfa-streaming-parser";

    // ...

    const getRdfaParser = () => {
    const onQuadCallbacks = [];
    const onCompleteCallbacks = [];
    const onErrorCallbacks = [];

    return {
    onQuad: (callback) => onQuadCallbacks.push(callback),
    onError: (callback) => onErrorCallbacks.push(callback),
    onComplete: (callback) => onCompleteCallbacks.push(callback),
    parse: async (source, resourceInfo) => {
    const parser = new RdfaParser({
    baseIRI: getSourceUrl(resourceInfo),
    contentType: getContentType(resourceInfo) ?? "text/html",
    });
    parser.on("data", (quad) => {
    onQuadCallbacks.forEach((callback) => callback(quad));
    });
    parser.on("error", (error) => {
    onErrorCallbacks.forEach((callback) => callback(error));
    });
    parser.write(source);
    parser.end();
    onCompleteCallbacks.forEach((callback) => callback());
    },
    };
    };
    type Parser = {
        onComplete: (onCompleteCallback: () => void) => void;
        onError: (onErrorCallback: (error: unknown) => void) => void;
        onQuad: (onQuadCallback: (quad: Quad) => void) => void;
        parse: (source: string, resourceInfo: WithServerResourceInfo) => void;
    }
    Index

    Properties

    onComplete: (onCompleteCallback: () => void) => void
    onError: (onErrorCallback: (error: unknown) => void) => void
    onQuad: (onQuadCallback: (quad: Quad) => void) => void
    parse: (source: string, resourceInfo: WithServerResourceInfo) => void