quadstorejs / quadstore

A LevelDB-backed graph database for JS runtimes (Node.js, Deno, browsers, ...) supporting SPARQL queries and the RDF/JS interface.
https://github.com/quadstorejs/quadstore
MIT License
202 stars 14 forks source link

Deno support #139

Closed ProvocaTeach closed 2 years ago

ProvocaTeach commented 3 years ago

Hello, I am opening an issue for supporting Deno via ES module importing out-of-the-box, per discussion in issue #138 at the suggestion of @jacoscaz.

Deno is a runtime for JavaScript created by Ryan Dahl (who also built Node). Benefits of Deno include:

Members of the Quadstore team may have a better idea than I do of how far-off this is. I don’t have a great sense of how much the most popular RDF/JS projects depend on Node. However, Skypack or a similar Deno-friendly CDN may be a good way to provide stopgap support.

Some helpful Deno links:

jacoscaz commented 2 years ago

Thanks to the recent addition of separate ESM vs. CJS builds, partial support for Deno is now available through Skypack in quadstore@11.0.0-beta.5:

import { DataFactory } from 'https://cdn.skypack.dev/rdf-data-factory@1.1.1';
import { Quadstore } from 'https://cdn.skypack.dev/quadstore@11.0.0-beta.4';
import { MemoryLevel } from 'https://cdn.skypack.dev/memory-level@1.0.0';

const backend = new MemoryLevel();
const dataFactory = new DataFactory();
const store = new Quadstore({ backend, dataFactory });

await store.open();
await store.put(dataFactory.quad(
  dataFactory.namedNode('ex://s'),
  dataFactory.namedNode('ex://p'),
  dataFactory.namedNode('ex://o'),
));
const { items } = await store.get({});
console.log(items);
await store.close();

Further work is needed to add support for Deno in quadstore-comunica, thus enabling SPARQL queries in Deno, and likely depends on fixing this upstream issue: https://github.com/RubenVerborgh/SPARQL.js/issues/139 .

jacoscaz commented 2 years ago

Found a temporary workaround by using import maps to replace Skypack's version of sparqljs@3.5.2 with https://gist.github.com/jacoscaz/022c513ca77b0061c5bfee0356ba3b8d , which contains a small fix for the unchecked usage of require.

jacoscaz commented 2 years ago

Closing - will be a part of the upcoming 11.0.0 release!