All files / lib datasetConverters.ts

100% Statements 13/13
100% Branches 0/0
100% Functions 4/4
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52  2x       2x       6x 6x 6x 6x   6x   6x     6x                                                                
import { Dataset } from "@rdfjs/types";
import { Writer, WriterOptions } from "n3";
// import SerializerJsonld from "@rdfjs/serializer-jsonld";
// import { Readable } from "readable-stream";
 
export async function datasetToString(
  dataset: Dataset,
  options: WriterOptions
): Promise<string> {
  return new Promise<string>((resolve, reject) => {
    const writer = new Writer(options);
    for (const quad of dataset) {
      writer.addQuad(quad);
    }
    writer.end(async (error, parsedString: string) => {
      /* istanbul ignore if */
      if (error) {
        return reject(error);
      }
      return resolve(parsedString);
    });
  });
}
 
// export async function datasetToJsonLd(
//   dataset: Dataset,
//   context: ContextDefinition
// ): Promise<JsonLdDocument> {
//   return new Promise((resolve, reject) => {
//     const serializerJsonld = new SerializerJsonld();
//     const input = new Readable({
//       objectMode: true,
//       read: () => {
//         dataset.forEach((quad) => {
//           input.push(quad);
//         });
//         input.push(null);
//       },
//     });
//     const output = serializerJsonld.import(input);
 
//     output.on("data", (jsonld) => {
//       resolve(jsonld);
//     });
//     /* istanbul ignore next */
//     output.on("error", (err) => {
//       /* istanbul ignore next */
//       reject(err);
//     });
//   });
// }