npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-loader-sparql

v0.1.3

Published

Node.js ESM loader that lets you import SPARQL query files (`.rq`) and update files (`.ru`) directly, returning typed executors from the `sparqlc` compiler.

Readme

node-loader-sparql

Node.js ESM loader that lets you import SPARQL query files (.rq) and update files (.ru) directly, returning typed executors from the sparqlc compiler.

  • Resolves and compiles .rq/.ru on the fly
  • Supports ESM import attributes (e.g., with: { base }) for relative IRI resolution
  • Produces separate module instances per distinct attribute set by encoding attributes in the resolved URL

Install

npm i -D node-loader-sparql sparqlc

Enable the loader

Use Node’s ESM loader registration via --import (Node 20.6+/22+):

node --import node-loader-sparql app.mjs

You can also set an environment variable to apply it to all Node runs:

export NODE_OPTIONS="--import node-loader-sparql"

In test runners such as Mocha, add node-loader-sparql to the require list. This repo’s packages do this in their mocha config.

Importing queries

// Import a SELECT query executor from a .rq file
const { default: selectAll } = await import('./queries/select-all.rq')

// Execute with sparql-http-client
import env from '@zazuko/env'
import type { ParsingClient } from 'sparql-http-client'

const client: ParsingClient = /* ... */
const rows = await selectAll({ env, client })

Updates (.ru) work the same and return void with a ParsingClient:

const { default: insertData } = await import('./queries/insert-data.ru')
await insertData({ env, client })

Base IRI via import attributes

Pass a base IRI to resolve relative IRIs in your query using ESM import attributes:

const { default: q } = await import('./queries/select.rq', {
  with: { base: 'http://example.org/' },
})

This is parsed by the loader and forwarded to sparqlc’s compiler.

Separate module instances per attribute set

By design, Node caches loaded modules by their fully resolved URL. This loader incorporates the import attributes into that URL during its resolve hook. As a result, different attribute sets map to different URLs and therefore different module instances and cache entries.

const a = await import('./q.rq', { with: { base: 'http://ex.org/a/' } })
const b = await import('./q.rq', { with: { base: 'http://ex.org/b/' } })

// a.default !== b.default (separate instances compiled with different bases)

This approach also guarantees re-importing with the same attributes hits the cache consistently.

Notes and caveats

  • Only .rq and .ru files are handled. Other imports are passed through to Node’s default resolver/loader.
  • The attribute set is encoded deterministically in the resolved URL’s query string; avoid putting secrets in attributes.
  • If you need additional attributes in the future, they will be similarly encoded and isolated per distinct set.