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

@unrdf/cli

v26.4.10

Published

UNRDF CLI - Command-line Tools for Graph Operations and Context Management

Downloads

894

Readme

@unrdf/cli

RDF ontology to code generation. Transform your RDF knowledge graphs into typed code artifacts—Zod schemas, OpenAPI specs, JSDoc types, GraphQL schemas—using SPARQL queries and Nunjucks templates.

Version: 26.4.9 | Node.js: >=18.0.0

Installation

Global Install (recommended for CLI usage)

# Using pnpm (recommended)
pnpm add -g @unrdf/cli

# Using npm
npm install -g @unrdf/cli

# Using yarn
yarn global add @unrdf/cli

Verify installation:

unrdf --version
# Output: 26.4.9

Project-Local Install

# Install as dev dependency
pnpm add -D @unrdf/cli

# Run via pnpm exec
pnpm exec unrdf sync

# Or add script to package.json
# "scripts": { "sync": "unrdf sync" }

Use Without Installing (npx)

npx @unrdf/cli sync

Note: npx downloads the package each time. For frequent use, global install is faster.

Quick Start

# Install
pnpm add -g @unrdf/cli

# Create configuration
cat > unrdf.toml << 'EOF'
[project]
name = "my-api"
version = "1.0.0"

[ontology]
source = "ontology/schema.ttl"
format = "turtle"

[generation]
output_dir = "lib"

[[generation.rules]]
name = "zod-schemas"
template = "templates/entities.njk"
output_file = "schemas/entities.mjs"
query = """
SELECT ?entityName ?propertyName ?propertyType
WHERE {
  ?entity a rdfs:Class ; rdfs:label ?entityName .
  ?property rdfs:domain ?entity ; rdfs:label ?propertyName ; rdfs:range ?propertyType .
}
ORDER BY ?entityName ?propertyName
"""
EOF

# Create template
mkdir -p templates
cat > templates/entities.njk << 'EOF'
---
to: {{ output_dir }}/schemas/entities.mjs
---
import { z } from 'zod';

{% for entityName, props in sparql_results | groupBy("?entityName") %}
export const {{ entityName | camelCase }}Schema = z.object({
{% for row in props %}
  {{ row["?propertyName"] | camelCase }}: {{ row["?propertyType"] | zodType }},
{% endfor %}
});
{% endfor %}
EOF

# Generate code
unrdf sync

unrdf sync

Ontology-driven code generation. Reads RDF ontologies, executes SPARQL queries, and renders results through Nunjucks templates to generate typed code artifacts.

Configuration (unrdf.toml)

[project]
name = "my-api"
version = "1.0.0"

[ontology]
source = "ontology/schema.ttl"     # RDF file path
format = "turtle"                   # RDF format (auto-detected)
base_iri = "http://example.org/"    # Base IRI for relative URIs

[generation]
output_dir = "lib"                  # Output directory
parallel = false                    # Run rules in parallel

[[generation.rules]]
name = "zod-schemas"                # Rule identifier
template = "templates/zod.njk"      # Nunjucks template
output_file = "schemas.mjs"         # Output file
mode = "overwrite"                  # overwrite | append | skip_existing
query = """
SELECT ?entityName ?propertyName ?propertyType
WHERE {
  ?entity a rdfs:Class ; rdfs:label ?entityName .
  ?property rdfs:domain ?entity ; rdfs:range ?propertyType .
}
"""

Template Features

Filters:

  • Case conversion: camelCase, pascalCase, snakeCase, kebabCase
  • RDF utilities: localName, namespace
  • Type mapping: zodType, jsdocType, zodDefault
  • Data manipulation: groupBy, sortBy, distinctValues, requiredArgs

Hygen Directives (line-based modification):

---
to: src/index.ts
inject: true
after: '^// Auto-generated exports$'
---

Available directives: inject, before, after, append, prepend, lineAt, skipIf

CLI Usage

# Generate code from config
unrdf sync

# Preview without writing
unrdf sync --dry-run

# Run specific rule
unrdf sync --rule zod-schemas

# Verbose output
unrdf sync --verbose

# Watch mode (regenerate on ontology changes)
unrdf sync --watch

Documentation

  • Complete guide: https://github.com/unrdf/unrdf/blob/main/packages/cli/docs/sync-command.md
  • Hygen integration: Line-based file modification, anchor patterns, conditional skips
  • Template reference: All filters, context variables, SPARQL results structure
  • Examples: https://github.com/unrdf/unrdf/tree/main/packages/cli/examples/sync

Other Commands

MCP Server (AI Agent Integration)

unrdf mcp start              # Start MCP server (stdio/SSE)
unrdf mcp status             # Check server status
unrdf mcp inspect            # List tools/resources
unrdf mcp stop               # Stop server
unrdf mcp self-play          # Autonomous tool chaining

Diagnostics

unrdf doctor                  # Health check
unrdf doctor --fix            # Auto-fix issues
unrdf doctor --watch          # Continuous monitoring

Checks: env, system, quality, integration, OTEL, Kubernetes

See https://github.com/unrdf/unrdf/blob/main/packages/cli/docs/doctor-command.md

Graph Operations

unrdf graph create --name <name>
unrdf graph load --graph <name> --file <path>
unrdf graph query --graph <name> --query <sparql>
unrdf graph export --graph <name> --format <format>

Formats: turtle, ntriples, nquads, jsonld, rdfxml, trig

Template Generation (Ad-hoc)

unrdf template generate --template <path> [file]
unrdf template list
unrdf template query

Context Management

unrdf context create --name <name>
unrdf context add --name <name> --prefix <prefix> --namespace <ns>
unrdf context list
unrdf context delete --name <name>

Hook Evaluation

unrdf hook eval --policy <path>
unrdf hook validate --policy <path>

Advanced Topics

CI/CD Integration

# .github/workflows/ontology-sync.yml
name: Ontology Sync
on:
  push:
    paths: ['ontology/**', 'unrdf.toml']
jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: pnpm add -g @unrdf/cli
      - run: unrdf sync
      - run: git add lib/
      - run: git commit -m "chore: sync generated code"

Environment Variables

export UNRDF_DEFAULT_GRAPH=main
export UNRDF_DEFAULT_FORMAT=turtle
export UNRDF_CONFIG_PATH=./unrdf.toml
export UNRDF_FILE_LOCK_RETRY_MS=10
export UNRDF_FILE_LOCK_MAX_RETRIES=50

Automation Scripts

// automation-script.mjs
import { exec } from 'child_process';
import { promisify } from 'util';

const execAsync = promisify(exec);

async function pipeline() {
  await execAsync('unrdf sync');
  await execAsync('unrdf doctor --format json > health.json');
}

pipeline();

Documentation

  • Sync Command: https://github.com/unrdf/unrdf/blob/main/packages/cli/docs/sync-command.md
  • Sync Tutorial: https://github.com/unrdf/unrdf/blob/main/packages/cli/docs/sync-tutorial.md
  • Template Command: https://github.com/unrdf/unrdf/blob/main/packages/cli/docs/template-command.md
  • Doctor Command: https://github.com/unrdf/unrdf/blob/main/packages/cli/docs/doctor-command.md
  • Daemon CLI: https://github.com/unrdf/unrdf/blob/main/packages/cli/docs/daemon-cli.md
  • Quick Start: https://github.com/unrdf/unrdf/blob/main/packages/cli/QUICKSTART-CLI.md

Examples

  • https://github.com/unrdf/unrdf/tree/main/packages/cli/examples/sync/basic.unrdf.toml
  • https://github.com/unrdf/unrdf/tree/main/packages/cli/examples/sync/advanced.unrdf.toml
  • https://github.com/unrdf/unrdf/tree/main/packages/cli/examples/template-pipeline.mjs

Support

License

MIT