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

moleculer-adapter-feathers

v0.2.1

Published

Moleculer service mixin adapting Feathers.js services

Downloads

1

Readme

moleculer-adapter-feathers

Moleculer adapter to import feathers services. That includes:

  • MongoDB
  • Blob store
  • Bookshelf
  • CouchDB
  • Elasticsearch
  • Knex
  • Mongoose
  • NeDB
  • RethinkDB
  • Sequalize
  • Waterline
  • and many others

Install

$ npm install moleculer-adapter-feathers --save

Usage (example with Knex)

const Feathers = require("moleculer-adapter-feathers");
const { ServiceBroker } = require("moleculer");
const feathersKnex = require("feathers-knex");
const knex = require("knex");

const broker = new ServiceBroker();

// Create a DB service via knex for `user` entities
broker.createService({
    name: "users",
    mixins: [Feathers],
    settings: {
        feathers: {
            adapter: feathersKnex,
            options: {
                name: "users",
                Model: new knex({
                    client: "pg",
                    connection: { ... },
                }),
            },
        },
    },
});

broker.start()
// Create a new user
.then(() => broker.call("users.create", {
    username: "john",
    email: "[email protected]",
}))

// Get all users
.then(() => broker.call("users.find").then(console.log));

Settings

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | adapter | Object | Function | required | Feathers Knex service adapter. | | hooks | Object | {} | Object containing before and after hooks. | | options | Object | {} | Options passed to Feathers service adapter. |

Hooks

Hooks work just as they do in Feathers. They are passed down to a service in settings.feathers.hooks.

users.service.js

module.exports = {
    ...
    settings: {
        feathers: {
            adapter: feathersKnex,
            hooks: require('./hooks'),
            options: {
                name: "users",
                Model: new knex({
                    client: "pg",
                    connection: { ... },
                }),
            },
        },
    },
    ...
}

hooks.js

module.exports = {
    before: {
        create: [
            hook => {
                console.log('create hook')
                return hook
            },
        ],
        find: [],
        get: [],
        update: [],
        patch: [],
        remove: [],
    },
    after: {
        create: [],
        find: [],
        get: [],
        update: [],
        patch: [],
        remove: [],
    },
}

Actions

Standard Feathers actions are exposed: create, get, find, update, patch, remove with all the standard Feathers parameters. Actions can be overwritten.

Methods

Feathers service methods can be accessed directly via this.create, this.find and etc.

create

Create an object in a service.

Parameters

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | * | Any | {} | Object to be created. |

Results

Type: Object

Created object (or any other service response).

find

Find objects by a provided query, if any.

Parameters

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | * | Any | {} | Query specified by the service. |

Results

Type: Array[Object]

Array of results.

get

Get object in the service by a provided (unique) ID.

Parameters

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | id | String | Number | required | Object ID. |

Results

Type: Object

Object found by the ID.

patch

Changes the properties of an object.

Parameters

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | id | String | Number | required | Object ID. | | * | Any | {} | Values to be patched. |

Results

Type: Object

Object patched.

update

Overwrites an object's properties.

Parameters

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | id | String | Number | required | Object ID. | | * | Any | {} | Rest of the object. |

Results

Type: Object

Object updated.

remove

Remove object by ID.

Parameters

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | id | String | Number | required | Object ID. |

Results

Type: Object

Object removed.