1.0.3 • Published 2 years ago

@dexagod/rdf-retrieval v1.0.3

Weekly downloads
83
License
MIT
Repository
-
Last release
2 years ago

RDF-Retrieval

This is a javascript library for both Node and the Browser. The library provides functionality for retrieving RDF resources in a format of choice, and for conversions between RDF formats. A custom fetch function can be set (currently only for retrieval of remote resources). This enables retrieval in cases where authentication is required.

Resource retrieval functions

Functionparametersreturn
getResourceAsQuadStreampath (string)Promise\<RDF.Stream<RDF.Quad>>
getResourceAsQuadArraypath (string)Promise\<RDF.Quad[]>
getResourceAsDatasetpath (string)Promise\
getResourceAsStorepath (string)Promise\<N3.Store <RDF.Quad, N3.Quad>>
getResourceAsTextStreampath (string), format? (string)Promise\<NodeJS.ReadableStream>
getResourceAsStringpath (string), format? (string)Promise\

RDF Conversion functions.

The conversion functions are only available for parameters of the type RDF.Stream and RDF.Quad[]

Quad Stream conversions

Functionparametersreturn
quadStreamToQuadArrayRDF.StreamPromise\<RDF.Quad[]>
quadStreamToStoreRDF.StreamPromise\<N3.Store<RDF.Quad, N3.Quad>>
quadStreamToDatasetRDF.StreamPromise\
quadStreamToTextStreamRDF.Stream, format? (string)Promise\<NodeJS.ReadableStream>
quadStreamToStringRDF.Stream, format? (string)Promise\

Quad Array conversions

Functionparametersreturn
quadArrayToQuadStreamRDF.Quad[]Promise\<RDF.Stream<RDF.Quad>>
quadArrayToStoreRDF.Quad[]Promise\<N3.Store<RDF.Quad, N3.Quad>>
quadArrayToDatasetRDF.Quad[]Promise\
quadArrayToTextStreamRDF.Quad[], format? (string)Promise\<NodeJS.ReadableStream>
quadArrayToStringRDF.Quad[], format? (string)Promise\

Setting custom fetch function

A fetch function can be set using

import * as f from "@dexagod/rdf-retrieval"
await f.setFetchFunction(myCustomFetch)

This function allows fetch functions that provide the same interface as the browser fetch function. (and the headers.content_type header should be available for correct parsing of the resource)

Examples

Setting a custom fetch function for solid

import * as f from "@dexagod/rdf-retrieval"
const auth = require('solid-auth-client');
const fetch = auth.fetch

// setting custom fetch function
await f.setFetchFunction(auth.fetch)

// retrieve remote solid resource
const res = await f.getResourceAsString("https://solidpod.inrupt.net/private/myprivateresource.jsonld", "text/turtle")
console.log('Retrieved resource in turtle format: ', res)

Getting the quads of a remote resource

import * as f from "@dexagod/rdf-retrieval"
const quads = await f.getResourceAsQuadArray("https://myWebsite.org/myResource.ttl")

Converting quads into a stream of quads

import * as f from "@dexagod/rdf-retrieval"
const quads = await f.getResourceAsQuadArray("https://myWebsite.org/myResource.ttl")
// conversion
const stream = await quadArrayToQuadStream(quads);

Converting quad stream into a formatted string

import * as f from "@dexagod/rdf-retrieval"
const stream = await f.getResourceAsQuadStream("https://myWebsite.org/myResource.ttl")
// conversion to jsonld string
const string = await quadStreamToString(stream, "application/ld+json");