Callidon / sparql-engine

🚂 A framework for building SPARQL query engines in Javascript/Typescript
https://callidon.github.io/sparql-engine
MIT License
99 stars 14 forks source link

Added browser support #77

Open lucafabbian opened 1 year ago

lucafabbian commented 1 year ago

This branch provides an experimental release of sparql-engine for the browser.

The release file is stored under browser/sparqlEngine.js. In the same folder, you will also find an example.html file, a 1:1 porting of the already existing N3 example, which proves that the library works and is usable.

The release file is generated through the rollup.js builder, with a minor hack documented in the rollup.config.mjs configuration file.

I still have to port the sparql-engine test suite to the browser, I'm going to do it as soon as possible.

lucafabbian commented 1 year ago

Hi :)

  1. I did not realize tests were run also against node 10 and 12. Is it really mandatory to support such outdated versions? They already reached their end of life, even considering the LTS. Moreover, it's just for testing. If I understand it right, the actual file will keep the compatibility with those versions. And even if they would not, I do not see why anyone with a node of 5 years ago would be interested in upgrading sparql-engine.

  2. I do not think so. Typescript is not as powerful as Rollup, and many other libraries use them in conjunction. Rollup just works, and it may become even more useful for future tweaks. For example, while I was testing the BIND bug, I had to compile version 7.0, which had issues due to old N3 being not suitable for the browser. However, with just few lines of code, I replaced the misworking file with some manipulation magic and everything went right:

const patchedN3 = // Expose submodules var exports = module.exports = { Lexer: require('./lib/N3Lexer'), Parser: require('./lib/N3Parser'), Writer: require('./lib/N3Writer'), Store: require('./lib/N3Store'), StreamParser: require('./lib/N3StreamParser'), StreamWriter: require('./lib/N3StreamWriter'), Util: require('./lib/N3Util'), }; function n3Patcher() { return { name: 'n3-patcher', resolveId(source, importer) { if (source.endsWith('N3.js')) { return path.resolve(path.dirname(importer), source); } }, load(id) { if (id.endsWith('N3.js')) { return patchedN3; } } }; }


This would be impossible with just Typescript.

3. Can I just gitignore the current `browser/sparqlEngine.js` ? The file should already be available in npm, because the `npm run build` scripts generates it. If you wish, I may also generate a minified version with Terser. However I do not think it's really needed: keep in mind that most setups do include a minification of imported node modules, and even automatic CDN services such as jsdelivr automatically provide a minified version.

If you wish, I may also add an action for building and pushing the result to a gh-pages branch, to allow a live preview on sparql-engine served by Github Pages.