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

@oddnetworks/oddworks-example-data

v3.0.1

Published

Example data for Oddworks server

Downloads

2

Readme

@oddnetworks/oddworks-example-data

Example seed functions that help populate our example applications with data.

Installation

	$ npm install --save @oddnetworks/oddworks-example-data

Usage

Require the example data package in your script

	const exampleData = require('@oddnetworks/oddworks-example-data');

Functions on the module exampleData will take an oddcast bus, like so:

	const oddcast = require('oddcast');
	const bus = oddcast.bus();

	exampleData.nasa(bus);

These functions return promises.

In reality, these functions can do whatever you like. We use them to send messages on the oddcast bus so that our example data is sent to any observing "stores". Read more about stores in oddworks

Seed Script

In the nasa example, we're loading all the relative JSON files, which each contain a single object, and sending them into our stores.

Note: You don't have to use JSON files here. This data can come from anywhere. Any objects passed to the bus should be in the oddworks entity data format, however.


// note: this function returns a promise
module.exports = bus => {

	// first get an array of all the paths for channels and platforms
	return glob('./+(channel|platform)/*.json', {cwd: __dirname})

		// next, load all the "channel" and "platform" objects
		.then(loadFiles)

		// next, ensure each of those objects are sent to our store(s)
		.then(objects => {
			//...
			// Here we send all objects to the "seedData" method,
			// which will create an array of promises
			// we'll wrap that in Promise.all, to ensure they all run
			// before continuing
			return Promise.all(seedData(bus, objects));
		})

		// next we'll get an array of all the paths for collections,
		// promotions, videos, and views
		.then(() => {
			return glob('./+(collection|promotion|video|view)/*.json', {cwd: __dirname});
		})

		// then load all the "collection", "promotion", "video" and "view" objects
		.then(loadFiles)

		// finally, we'll ensure all of the objects are sent to our store(e)
		.then(objects => {
			// ...
			return Promise.all(seedData(bus, objects))
		});
};

In a nutshell, we're loading all of the channel and platform JSON objects first, then we're loading all the collection, promotion, video, and view JSON objects.

Let's break down the seedData method:

function seedData(bus, objects) {
	// bus is your oddcast bus
	// objects is an array of the objects defined within each JSON file

	// we are going to return an array of promises
	const promises = [];

	// we need to iterate over all the objects and create promises for each
	for(let object of objects) {

		// the searchable variable is set to true if the object.type is one of the searchableTypes
		const searchable = Boolean(searchableTypes.indexOf(object.type) + 1);

		// by default, we use the following pattern:
		let pattern = {role: 'store', cmd: 'set', type: object.type};
		// be sure that your oddcast bus has an observer for this command pattern

		if (searchable) {
			// searchable objects have a different pattern
			pattern = {role: 'catalog', cmd: 'create', searchable: true};
			// be sure that your oddcast bus has an observer for this command pattern
		}

		const payload = {
			version: 1,
			channel: object.channel,
			platform: object.id,
			scope: ['platform']
		};

		// ... console logging omitted - these are convenience methods

		// next, send the command on your oddcast bus
		// sendCommand returns a promise, so we push that to our promises array
		promises.push(bus.sendCommand(pattern, object));
	}

	// finally, return our stored object promises
	return promises;
}

Contributing

Feel free to contribute and create additional sample data/seeds. Please make sure any data is in the public domain.