Socket
Socket
Sign inDemoInstall

moleculer-adapter-feathers

Package Overview
Dependencies
72
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    moleculer-adapter-feathers

Moleculer service mixin adapting Feathers.js services


Version published
Weekly downloads
4
increased by300%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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: "john@doe.com",
}))

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

Settings

PropertyTypeDefaultDescription
adapter`ObjectFunction`required
hooksObject{}Object containing before and after hooks.
optionsObject{}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

PropertyTypeDefaultDescription
*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

PropertyTypeDefaultDescription
*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

PropertyTypeDefaultDescription
id`StringNumber`required

Results

Type: Object

Object found by the ID.

patch

Changes the properties of an object.

Parameters

PropertyTypeDefaultDescription
id`StringNumber`required
*Any{}Values to be patched.

Results

Type: Object

Object patched.

update

Overwrites an object's properties.

Parameters

PropertyTypeDefaultDescription
id`StringNumber`required
*Any{}Rest of the object.

Results

Type: Object

Object updated.

remove

Remove object by ID.

Parameters

PropertyTypeDefaultDescription
id`StringNumber`required

Results

Type: Object

Object removed.

Keywords

FAQs

Last updated on 18 Sep 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc