Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Update to new plugin infrastructure (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Dec 3, 2017
1 parent 97baf75 commit 184adf9
Show file tree
Hide file tree
Showing 13 changed files with 500 additions and 2,516 deletions.
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

4 changes: 3 additions & 1 deletion .gitignore
@@ -1,3 +1,5 @@
.DS_Store

# Logs
logs
*.log
Expand Down Expand Up @@ -27,4 +29,4 @@ node_modules
# Users Environment Variables
.lock-wscript

lib/
dist/
6 changes: 2 additions & 4 deletions .istanbul.yml
@@ -1,8 +1,6 @@
verbose: false
instrumentation:
root: src/
excludes:
- lib/
root: ./lib/
include-all-sources: true
reporting:
print: summary
Expand All @@ -14,4 +12,4 @@ reporting:
statements: [50, 80]
lines: [50, 80]
functions: [50, 80]
branches: [50, 80]
branches: [50, 80]
6 changes: 2 additions & 4 deletions .npmignore
@@ -1,12 +1,10 @@
.editorconfig
.npmignore
.jshintrc
.travis.yml
.istanbul.yml
.babelrc
.idea/
src/
.vscode/
test/
!lib/
coverage/
.github/
coverage
13 changes: 0 additions & 13 deletions .travis.yml
Expand Up @@ -3,16 +3,3 @@ language: node_js
node_js:
- node
- '6'
- '4'
addons:
code_climate:
repo_token: fc012e0287a25e3d90ff8bdfe8be939f65910738010d2bdb4afa2b0dbf251684
before_script:
- 'npm install -g codeclimate-test-reporter'
after_script:
- 'codeclimate-test-reporter < coverage/lcov.info'
notifications:
email: false
slack:
rooms:
secure: cmRPgiWsxMHDdD32RCf2mOVKagTAr1kz5VK7mT495zIC1HGIKCp+qVHVir//tfodhH975zKgdAOYy6SjEOMqJkYVUyD7GOG5LDJFrBaaJdT4JSrwQdpD1/NnOsFT1yQxxYr8swZR6vqCRzcdpnndalugxHSdOtvRiUCxK3T/HXA=
90 changes: 52 additions & 38 deletions README.md
Expand Up @@ -3,52 +3,67 @@
[![Greenkeeper badge](https://badges.greenkeeper.io/feathersjs/feathers-memory.svg)](https://greenkeeper.io/)

[![Build Status](https://travis-ci.org/feathersjs/feathers-memory.png?branch=master)](https://travis-ci.org/feathersjs/feathers-memory)
[![Code Climate](https://codeclimate.com/github/feathersjs/feathers-memory/badges/gpa.svg)](https://codeclimate.com/github/feathersjs/feathers-memory)
[![Test Coverage](https://codeclimate.com/github/feathersjs/feathers-memory/badges/coverage.svg)](https://codeclimate.com/github/feathersjs/feathers-memory/coverage)
[![Dependency Status](https://img.shields.io/david/feathersjs/feathers-memory.svg?style=flat-square)](https://david-dm.org/feathersjs/feathers-memory)
[![Download Status](https://img.shields.io/npm/dm/feathers-memory.svg?style=flat-square)](https://www.npmjs.com/package/feathers-memory)
[![Slack Status](http://slack.feathersjs.com/badge.svg)](http://slack.feathersjs.com)

> An in memory CRUD service for Feathers.
A [Feathers](https://feathersjs.com) service adapter for in-memory data storage that works on all platforms.

```bash
$ npm install --save feathers-memory
```

## Installation
> __Important:__ `feathers-memory` implements the [Feathers Common database adapter API](https://docs.feathersjs.com/api/databases/common.html) and [querying syntax](https://docs.feathersjs.com/api/databases/querying.html).
```bash
npm install feathers-memory --save

## API

### `service([options])`

Returns a new service instance initialized with the given options.

```js
const service = require('feathers-memory');

app.use('/messages', service());
app.use('/messages', service({ id, startId, store, events, paginate }));
```

## Documentation
__Options:__

Please refer to the [Feathers database adapter documentation](https://docs.feathersjs.com/api/databases/common.html) for more details or directly at:
- `id` (*optional*, default: `'id'`) - The name of the id field property.
- `startId` (*optional*, default: `0`) - An id number to start with that will be incremented for every new record (unless it is already set).
- `store` (*optional*) - An object with id to item assignments to pre-initialize the data store
- `events` (*optional*) - A list of [custom service events](https://docs.feathersjs.com/api/events.html#custom-events) sent by this service
- `paginate` (*optional*) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size

- [In Memory](https://docs.feathersjs.com/api/databases/memory.html) - The detailed documentation for this adapter
- [Extending](https://docs.feathersjs.com/api/databases/common.html#extending-adapters) - How to extend a database adapter
- [Pagination](https://docs.feathersjs.com/api/databases/common.html#pagination) - How to use pagination
- [Querying and Sorting](https://docs.feathersjs.com/api/databases/querying.html) - The common adapter querying mechanism and sorting for the database adapter

## Complete Example
## Example

Here is an example of a Feathers server with a `messages` in-memory service that supports pagination:

```
$ npm install @feathersjs/feathers @feathersjs/express @feathersjs/socketio @feathersjs/errors feathers-memory
```

In `app.js`:

```js
const feathers = require('feathers');
const bodyParser = require('body-parser');
const rest = require('feathers-rest');
const socketio = require('feathers-socketio');
const memory = require('feathers-memory');
const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const socketio = require('@feathersjs/socketio');

// Create a feathers instance.
const app = feathers()
// Enable REST services
.configure(rest())
// Enable Socket.io services
.configure(socketio())
// Turn on JSON parser for REST services
.use(bodyParser.json())
// Turn on URL-encoded parser for REST services
.use(bodyParser.urlencoded({ extended: true }));
const memory = require('feathers-memory');

// Create an Express compatible Feathers application instance.
const app = express(feathers());
// Turn on JSON parser for REST services
app.use(express.json());
// Turn on URL-encoded parser for REST services
app.use(express.urlencoded({ extended: true }));
// Enable REST services
app.configure(express.rest());
// Enable REST services
app.configure(socketio());
// Create an in-memory Feathers service with a default page size of 2 items
// and a maximum size of 4
app.use('/messages', memory({
Expand All @@ -57,27 +72,26 @@ app.use('/messages', memory({
max: 4
}
}));
// Set up default error handler
app.use(express.errorHandler());

// Create a dummy Message
app.service('messages').create({
text: 'Server message',
read: false
}).then(function(message) {
console.log('Created message', message);
});
text: 'Message created on server'
}).then(message => console.log('Created message', message));

// Start the server.
const port = 3030;

app.listen(port, function() {
console.log(`Feathers server listening on port ${port}`);
app.listen(port, () => {
console.log(`Feathers server listening on port ${port}`)
});
```

You can run this example with `npm start` from the cloned repository and going to [localhost:3030/messages](http://localhost:3030/messages). You will see the test Message that we created at the end of that file.
Run the example with `node app` and go to [localhost:3030/messages](http://localhost:3030/messages).

## License

Copyright (c) 2016
Copyright (c) 2017

Licensed under the [MIT license](LICENSE).
30 changes: 0 additions & 30 deletions example/app.js

This file was deleted.

36 changes: 19 additions & 17 deletions src/index.js → lib/index.js
@@ -1,12 +1,14 @@
import Proto from 'uberproto';
import filter from 'feathers-query-filters';
import errors from 'feathers-errors';
import cloneDeep from 'clone-deep';
import { sorter, select as baseSelect, _ } from 'feathers-commons';
import sift from 'sift';
const Proto = require('uberproto');
const filter = require('feathers-query-filters');
const errors = require('feathers-errors');
const cloneDeep = require('clone-deep');

const select = (...args) => {
const base = baseSelect(...args);
const { sorter, select, _ } = require('feathers-commons');

const sift = require('sift');

const _select = (...args) => {
const base = select(...args);

return function (result) {
return base(cloneDeep(result));
Expand All @@ -32,7 +34,7 @@ class Service {
// a pagination object
_find (params, getFilter = filter) {
const { query, filters } = getFilter(params.query || {});
const map = select(params);
const map = _select(params);
let values = _.values(this.store);

if (this._matcher) {
Expand Down Expand Up @@ -78,7 +80,7 @@ class Service {
get (id, params) {
if (id in this.store) {
return Promise.resolve(this.store[id])
.then(select(params, this.id));
.then(_select(params, this.id));
}

return Promise.reject(
Expand All @@ -92,7 +94,7 @@ class Service {
let current = _.extend({}, data, { [this._id]: id });

return Promise.resolve((this.store[id] = current))
.then(select(params, this.id));
.then(_select(params, this.id));
}

create (data, params) {
Expand All @@ -115,7 +117,7 @@ class Service {
this.store[id] = data;

return Promise.resolve(this.store[id])
.then(select(params, this.id));
.then(_select(params, this.id));
}

return Promise.reject(
Expand All @@ -139,7 +141,7 @@ class Service {
_.extend(this.store[id], _.omit(data, this._id));

return Promise.resolve(this.store[id])
.then(select(params, this.id));
.then(_select(params, this.id));
}

return Promise.reject(
Expand All @@ -166,7 +168,7 @@ class Service {
delete this.store[id];

return Promise.resolve(deleted)
.then(select(params, this.id));
.then(_select(params, this.id));
}

return Promise.reject(
Expand All @@ -187,8 +189,8 @@ class Service {
}
}

export default function init (options) {
module.exports = function init (options) {
return new Service(options);
}
};

init.Service = Service;
module.exports.Service = Service;
1 change: 0 additions & 1 deletion mocha.opts
@@ -1,2 +1 @@
--recursive test/
--compilers js:babel-core/register

0 comments on commit 184adf9

Please sign in to comment.