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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@logilab/sparqlexplorer-views

v1.4.1

Published

Generic views for SparqlExplorer to display OWL, DC, SKOS

Downloads

17

Readme

Sparql generic views

This repo contains views to display data from several vocabularies in a web browser.

Supported vocabularies are:

  • SKOS Concept
  • SKOS Concept Scheme
  • SchemaPerson
  • FOAF
  • OWL Class
  • DublinCore

Usage

As a dependency

This library is published on NPM and exports the required components.

First add it as a dependency for your project:

npm install @logilab/sparqlexporer-views

If you want to use a specific view (eg: DublinCore), import the right component and pass the required props:

import {DublinCore} from "@logilab/sparqlexporer-views"

export function MyComponent() {
    return (
        <DublinCore
            uri={/* uri */}
            endpoint={/* sparql endpoint */}
            generateUrl={/* how to build urls for navigation to other URIs */}
        />
    )
}

For each view, a helper method is available to check if it can be applied to the URI. The pattern is isXXXApplicable where XXX is the view name.

import {isDublinCoreApplicable} from "@logilab/sparqlexporer-views"

export function MyComponent() {
    const [applicable, setApplicable] = useState<boolean | undefined>();

    useEffect(() => {
        const checkApplicable = async () => {
            setApplicable(await isDublinCoreApplicable(/* uri */, /* endpoint */))
        }
        checkApplicable();
    }, [])

    if (applicable === undefined) {
        return <p>Loading</p>
    }
    if (applicable) {
        return <p>Applicable</p>
    }
    return <p>Not applicable</p>
}

Alternatively, you can loop through all available views and check the applicability for each to render the appropriate view for your URI.

import {SparqlViewConfig, SPARQL_VIEWS} from "@logilab/sparqlexporer-views"


export function MyComponent() {
    const [view, setView] = useState<SparqlViewConfig | undefined | null>();

    useEffect(() => {
        const checkApplicable = async () => {
            const result = await Promise.all(
                SPARQL_VIEWS.map((view) => view.isApplicable(/* uri */, /* endpoint */))
            )
            const validViews = SPARQL_VIEWS.filter((v, i) => result[i])
            if (validViews.length > 0) {
                setView(validViews[0]);
            } else {
                setView(null)
            }
        }
        checkApplicable();
    }, [])

    if (view === undefined) {
        return <p>Loading</p>
    }
    if (view === null) {
        return <p>No view available</p>
    }

    const Component = view.component;

    return (
        <Component 
            uri={/* uri */}
            endpoint={/* sparql endpoint */}
            generateUrl={/* how to build urls for navigation to other URIs */}
        />
    )
}

Served from a server

⚠️ Please note this approach is insecure as it allows loading arbitrary JavaScript at run-time.

The views are also available as JS bundles on a static URL. Navigate to https://open-source.pages.logilab.fr/SemWeb/generic-views/index.vd.json to see the list of available views. For each item in the list, the url key points to the js bundle. You can use @logilab/libview library to simplify this process.

Here is an example fetching all views exposed in index.vd.json ad selecting the first one valid:

import {ViewDescription, ViewWrapper} from '@logilab/libview';

const viewServer = "https://open-source.pages.logilab.fr/SemWeb/generic-views/index.vd.json"
const response = await fetch(viewServer)
if (response.status === 200) {
    const json = await response.json()
    const viewlist =  json.map(
        (viewDescription: ViewDescription) => new ViewWrapper(viewDescription)
    )
    const viewsApplicablities = await Promise.all(
        viewList.map((view) => view.isApplicable(/* uri */, /* endpoint */))
    );
    const validViews = viewlist.filter((v, i) => viewsApplicablities[i])
    const firstView = validViews[0]
    const viewEntryPoint = firstView.getViewEntrypoint()
    viewEntryPoint.renderSparql(/* domElement */, /* uri */, /* endpoint */);
}

Developing

Clone with Mercurial and and install the npm project.

hg clone https://forge.extranet.logilab.fr/open-source/SemWeb/generic-views
npm install

This project does not contain a demo/examples. You will have to install your local version of the library into your project to test the changes.

As explained above, there are 2 ways to serve the library, from a webserver or as a dependency.

As a dependency

The recommended method is to use npm link to install the local library version into your project.

To prevent errors such as this one, the first step is to link the react version from your project into this library. Then you can link this library into your project.

If any of the commands below give you premission issues, do not run the commands as sudo. Instead change the npm globals folder to be in your home directory.

The following example links the library in the sparqlexplorer project clone next to this library.

# From this library root
npm link ../sparqlexplorer/node_modules/react
cd ../sparqlexplorer
npm link ../generic-views

Once the linking process is done, you can start making your changes. To see them in your target project, you will need to compile the project using the build command.

# For a one-off build
npm run build:lib
# To build after each change
npm run build:lib -- --watch

Served from a server

If your project reads the custom views from a dev server, the build commands are slightly different as the project needs to be bundled with webpack.

# First build the project
npm run build
# or rebuild after any change
npm run build:watch
# Then serve the files in a local server
npm run serve

This will deploy a server on http://localhost:8080/. You can then give the http://localhost:8080/index.vd.json url to your app to load the local views.

Contributing

SparlqlExplorer is licensed under AGPLv3, all contributions are welcome!

As the project is on the Logilab code hosting platform, you will need an account to create pull requests and open issues.

Please reach us on our public matrix channel or via email at [email protected] if you want to contribute.