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

@bitscheme/feathers-seeder

v3.0.3

Published

Straightforward data seeder for FeathersJS services.

Downloads

10

Readme

feathers-seeder

npm build status

Straightforward data seeder for FeathersJS services.

About

FeathersJS is a dynamic application framework that makes it easy to prototype secure real-time Node applications.

It has uniform support for a wide variety of database options, both persistent and in-memory. However, it can often be a pain to bootstrap databases, especially for secure backends where creation permissions are locked down tightly.

feathers-seeder attempts to solve that problem by allowing you to fill your database (specifically feathers-memory) with similar of identical data every time your application is launched.

This can really be useful for projects using feathers-memory, or feathers-nedb to test applications.

Installation

These magic words will do the trick:

npm install --save feathers-seeder

Usage

  1. Configure the seeder.
  2. Call app.seed(). This will return a Promise.

Example:

const app = feathers().configure(hooks());
app
  .configure(seeder(app.get('seeder')))
  .seed()
  .then(() => {
    app.listen(3000);
  });

Configuration

feathers-seeder should be called as a function, with a single configuration object as a parameter.

To enable debug output logging, set the DEBUG env variable accordingly (e.g. DEBUG=*)

All data in the service will be wiped before seeding, unless delete is set to false. It is true by default.

To disable feathers-seeder (i.e. at production), you can simply set the value disabled: true on your configuration object. It is false by default.

You can pass service parameters to each service via a params object. This can be useful for projects that have services locked down via hooks.

This configuration object should contain an array called services. Each object in this array will have a key pointing to the path of a registered Feathers service, and its value will be a configuration detail as follows.

Example:

{
  delete: true,
  disabled: false,
  params: { provider: 'rest' },
  services: [
    {
      path: 'users',
      template: {
        text: "Hello, world!  I am {{name.firstName}}."
      }
    }
  ]
}

Configuration options:

  • count: Number - The number of times to generate objects. If you provide a template or template(s), then count objects adhering to the template(s) will be generated. Default = 1.

  • delete: Boolean - If set to true, then existing data for this service will be deleted before seeding. Overrides global delete setting.

  • disabled: Boolean - Disables seeding for this service.

  • params: Object - Additional parameters to pass to service methods. This is merged with (and supersedes) the global params configuration via Object.assign.

  • path: String - The path to the service to be seeded.

  • randomize: Boolean - (default true) - The seeder will pick a random template to generate the item for the service.

  • template: Object - A template object defining the structure of each object generated. For dynamic data, you can provide:

    • Template strings, as feathers-seeder uses @marak/Faker.js internally
    • Custom parameterless functions

    Example:

    {
      template: {
        username: "{{internet.userName}}",
        password: "{{internet.password}}"
        name: "{{name.firstName}} {{name.lastName}}",
        email: "{{internet.email}}",
        lastLogin: () => moment().subtract(7, 'days').format()
      }
    }
  • templates: Object[] - An array of templates. If the option randomize is true, each time an object is to be generated, a random template will be chosen. Otherwise, all templates will be generated for the service.

  • callback: Function(obj, cb) - You can register a callback each time a database record is created. This allows you to seed nested services. :) Callbacks MUST return a Promise.

{
  services: [
    {
      count: 100,
      path: 'users',
      template: {
        name: '{{name.firstName}} {{name.lastName}}'
      },

      callback(user, seed) {
        console.info(`Happy birthday to ${user.name}!`);

        // Call `seed` with regular service configuration.
        // This will return a Promise.

        return seed({
          path: 'users/:userId/posts',
          params: {
            userId: user._id
          },
          template: {
            text: "It's my birthday! :)"
          }
        });
      }
    }
  ]
}

Example

import feathers from 'feathers';
import hooks from 'feathers-hooks';
import memory from 'feathers-memory';
import seeder from 'feathers-seeder';

const options = {
  services: [
    {
      path: 'users',
      count: 10,
      template: {
        name: '{{name.firstName}} {{name.lastName}}'
      }
    }
  ]
};

const app = feathers()
              .use('/users', memory({ multi: true }))
              .configure(seeder(options));

app.seed().then(() => {
  app.service('users').find().then(users => console.log(users));
});

Thanks

Thank you for using feathers-seeder. If you find any bugs, feel free to report an issue.

Follow me on Twitter: @thosakwe

Or check out my blog.