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

@hookcompany/feathers-helpers

v1.1.7

Published

🦅 Helpers to simplify feathers configuration.

Downloads

2

Readme

Feathers Helpers

🦅 Helpers to simplify feathers configuration.

NPM version

Npm Downloads

Getting Started

You can see an example project on this repository: Example

Use npm:

npm install --save @hookcompany/feathers-helpers

Or use yarn:

yarn add @hookcompany/feathers-helpers

Step 1: Services Index

Initially, you have to understand Feathers Helpers has an especific archtecture, which is divided into platforms, in this case app mobile and dashboard.

services/index.js

import feathersHelpers from '@hookcompany/feathers-helpers';
import models from 'models';
import common from './common';
import appMobile from './app-mobile';
import dashboard from './dashboard';

export default app => {
  feathersHelpers(models, { basePath: 'base' })(app)
    .platform(appMobile)
    .platform(dashboard);
};

Step 2: Models

Feathers Helpers only works with feathers-mongoose. So, if you use mongoose and feathers-mongoose, you can create a model like this:

models/user.js

export default {
  model: {
    email: { type: String, unique: true },
    password: { type: String }
  },
  options: {
    timestamps: true
  }
};

And you have to export an object that has the name of models as object attributes.

models/index.js

import product from './product';
import user from './user';

export default { product, user };

The attributes names are importants, because the model will be a feathers-mongoose model service that works like a pure service with all feathers methods to manipulate data. And by default the service path is "/base/model-name" with pluralized model name using pluralize, but you can configure base prefix on options as you can see on step 1.

Step 3: Platform

To configure a platform you only have to specify a prefix to the platform and pass an array of services. The prefix will be on platform services paths.

services/app-mobile/index.js

import products from './products';
import users from './users';
import feeds from './feeds';

export default {
  basePath: '/app-mobile',
  services: [products, users, feeds]
};

Step 4: Service

To configure a service you have to pass a service class, hooks, path and options. About the options, if you pass true in customMethods option you will activate feathers-custom-methods, by default customMethods is false.

services/app-mobile/feeds/index.js

import hooks from './hooks';
import service from './class';

export default {
  service,
  hooks,
  path: '/feeds',
  options: {
    customMethods: true
  }
};

services/app-mobile/feeds/class.js

import { find, get, create, update, patch, remove } from '@hookcompany/feathers-custom-methods';

class Service {
  setup = app => {
    this.app = app;
  }

  @find
  foo = params => {
    return Promise.resolve(args);
  }

  @get
  bar = (id, params) => {
    return Promise.resolve(args);
  }
}

export default options => new Service(options);

services/app-mobile/feeds/hooks.js

import { logger } from 'hooks';

export default {
  before: {
    all: [logger()],
    foo: [logger()],
    bar: [logger()]
  },
  after: {
    all: [logger()],
    foo: [logger()],
    bar: [logger()]
  },
  error: {
    all: [logger()],
    foo: [logger()],
    bar: [logger()]
  }
};

If you don't activate custom methods all will work like feathers normally. And the index will be like this:

services/app-mobile/feeds/index.js

import hooks from './hooks';
import service from './class';

export default {
  service,
  hooks,
  path: '/feeds'
};

Another way to create a service is extending a base service, by the way a base service is a model service which was shown on step 2.

services/app-mobile/products/class.js

import { BaseService } from '@hookcompany/feathers-helpers';

class Service extends BaseService {
  constructor(options) {
    super(options);
  }
}

export default options => new Service(options);

In this situation you have to pass in options the base path of the extended base service, the methods you want to allow and if you want pagination or not.

services/app-mobile/products/index.js

import hooks from './hooks';
import service from './class';

export default {
  service,
  hooks,
  path: '/products',
  options: {
    base: 'base/products',
    methods: ['find', 'create'],
    paginate: true
  }
};

Step 5: Consuming

With custom methods:

localhost:4000/app-mobile/feeds/:customMethod

Without custom methods:

localhost:4000/app-mobile/feeds/