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

rdf-streaming-store

v1.1.5

Published

A read-only RDF/JS store that allows parallel data lookup and insertion.

Downloads

12,309

Readme

RDF Streaming Store

Build status Coverage Status npm version

A read-only RDF/JS store that allows parallel data lookup and insertion. It works in both JavaScript and TypeScript.

Concretely, this means that match() calls happening before import() calls, will still consider those triples that are inserted later, which is done by keeping the response streams of match() open. Only when the end() method is invoked, all response streams will close, and the StreamingStore will be considered immutable.

WARNING: end() MUST be called at some point, otherwise all match streams will remain unended.

If using TypeScript, it is recommended to use this in conjunction with @rdfjs/types.

Installation

$ npm install rdf-streaming-store

or

$ yarn add rdf-streaming-store

This package also works out-of-the-box in browsers via tools such as webpack and browserify.

Usage

A new StreamingStore can be created as follows:

import { StreamingStore } from 'rdf-streaming-store';

const store = new StreamingStore();

Inserting quads

Following the RDF/JS Sink interface, new quads can be added using the import method, which accepts a stream of quads:

const quad = require('rdf-quad');
const streamifyArray = require('streamify-array');

// Somehow create a quad stream
const quadStream = streamifyArray([
  quad('s3', 'p3', 'o3'),
  quad('s4', 'p4', 'o4'),
]);

// Import it into the store
store.import(quadStream);

After inserting your quads, you MUST call end() to make sure that match calls will end their response streams:

store.end();

After calling end(), importing new quads is not allowed.

Finding quads

Following the RDF/JS Source interface, quads can be found using the match method, which returns a stream of quads:

import type * as RDF from '@rdfjs/types';
import { DataFactory } from 'rdf-data-factory';

const DF = new DataFactory();
const returnStream = store.match(undefined, DF.namedNode('p3'), DF.namedNode('o3'), undefined);

returnStream.on('data', (quad: RDF.Quad) => {
  console.log(quad);
});
returnStream.on('error', (error) => {
  console.log(error);
});
returnStream.on('end', () => {
  console.log('Done!');
});

Note that the returnStream will not end until the store.end() has been invoked.

match() can be called before import()

Since match() calls will only end after calling end(), quads that are imported after initiating the match() call, can still be emitted in the created match() stream.

const store = new StreamingStore();
const returnStream = store.match(undefined, DF.namedNode('p3'), DF.namedNode('o3'), undefined);

returnStream.on('data', (quad: RDF.Quad) => {
  console.log(quad);
});
returnStream.on('end', () => {
  console.log('Done!');
});

// At this stage, the store is empty, so no quads will be printed yet

// After importing some quads into the store, the s3-p3-o3 triple will be printed
store.import(streamifyArray([
  quad('s3', 'p3', 'o3'),
  quad('s4', 'p4', 'o4'),
]));

// After importing some more triples, another triple will be printed
store.import(streamifyArray([
  quad('sOther', 'p3', 'o3'),
]));

// Since we mark the store as ended, the returnStream will print `Done!`
store.end();

License

This software is written by Maarten Vandenbrande and Ruben Taelman.

This code is released under the MIT license.