feathers-memory
Advanced tools
Comparing version 0.3.4 to 0.4.0
{ | ||
"name": "feathers-memory", | ||
"description": "Feathers in memory service", | ||
"version": "0.3.4", | ||
"homepage": "https://feathersjs.com", | ||
"description": "An in memory service store", | ||
"version": "0.4.0", | ||
"homepage": "https://github.com/feathersjs/feathers-memory", | ||
"main": "lib/", | ||
"keywords": [ | ||
"feathers", | ||
"feathers-plugin" | ||
], | ||
"license": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/feathersjs/feathers-memory/blob/master/LICENSE" | ||
} | ||
], | ||
"repository": { | ||
@@ -10,42 +21,44 @@ "type": "git", | ||
}, | ||
"keywords": [ | ||
"services", | ||
"feathers", | ||
"memory" | ||
], | ||
"author": "Feathers <hello@feathersjs.com> (http://feathersjs.com)", | ||
"contributors": [ | ||
"Eric Kryski <e.kryski@gmail.com> (http://erickryski.com)", | ||
"David Luecke <daff@neyeon.de> (http://neyeon.com)" | ||
], | ||
"license": "MIT", | ||
"author": { | ||
"name": "Feathers contributors", | ||
"email": "hello@feathersjs.com", | ||
"url": "https://feathersjs.com" | ||
}, | ||
"contributors": [], | ||
"bugs": { | ||
"url": "https://github.com/feathersjs/feathers-memory/issues" | ||
}, | ||
"main": "lib/memory", | ||
"engines": { | ||
"node": ">= 0.12.0" | ||
}, | ||
"scripts": { | ||
"test": "grunt test", | ||
"start": "grunt" | ||
"prepublish": "npm run compile", | ||
"publish": "git push origin && git push origin --tags", | ||
"release:patch": "npm version patch && npm publish", | ||
"release:minor": "npm version minor && npm publish", | ||
"release:major": "npm version major && npm publish", | ||
"compile": "rm -rf lib/ && babel -d lib/ src/", | ||
"watch": "babel --watch -d lib/ src/", | ||
"jshint": "jshint src/. test/. --config", | ||
"mocha": "mocha test/ --compilers js:babel-core/register", | ||
"test": "npm run jshint && npm run mocha" | ||
}, | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"dependencies": { | ||
"feathers-errors": "^0.2.1", | ||
"lodash": "~2.4.1", | ||
"uberproto": "~1.1.0" | ||
"feathers-errors": "^0.2.5", | ||
"feathers-query-filters": "^1.1.1", | ||
"lodash": "^3.10.1", | ||
"uberproto": "^1.1.2" | ||
}, | ||
"devDependencies": { | ||
"body-parser": "^1.4.3", | ||
"chai": "^1.9.1", | ||
"feathers": "^1.0.0-pre.5", | ||
"grunt": "~0.4.1", | ||
"grunt-cli": "~0.1.7", | ||
"grunt-contrib-jshint": "~0.x", | ||
"grunt-contrib-watch": "~0.5.3", | ||
"grunt-release": "~0.5.1", | ||
"grunt-simple-mocha": "~0.4.0", | ||
"socket.io-client": "^0.9.16", | ||
"supertest": "~0.9.0" | ||
"babel-cli": "^6.1.2", | ||
"babel-core": "^6.1.2", | ||
"babel-preset-es2015": "^6.1.2", | ||
"feathers": "^1.1.1", | ||
"feathers-service-tests": "^0.3.0", | ||
"jshint": "^2.8.0", | ||
"mocha": "^2.3.3" | ||
} | ||
} |
243
README.md
@@ -1,50 +0,63 @@ | ||
# feathers-memory [![Build Status](https://travis-ci.org/feathersjs/feathers-memory.svg?branch=master)](https://travis-ci.org/feathersjs/feathers-memory)[![Code Climate](https://codeclimate.com/github/feathersjs/feathers-memory.png)](https://codeclimate.com/github/feathersjs/feathers-memory) | ||
# feathers-memory | ||
> An in memory CRUD service for [feathers](http://feathersjs.com) | ||
[![Build Status](https://travis-ci.org/feathersjs/feathers-memory.png?branch=master)](https://travis-ci.org/feathersjs/feathers-memory) | ||
## Getting Started | ||
> An in memory CRUD service for Feathers. | ||
Install the module with: `npm install feathers-memory --save` | ||
```js | ||
var feathers = require('feathers'); | ||
var memory = require('feathers-memory')(); | ||
## Installation | ||
app.configure(feathers.rest()).use('/users', memory); | ||
```bash | ||
npm install feathers-memory --save | ||
``` | ||
## Documentation | ||
#### API | ||
## Getting Started | ||
The feathers-memory service follows the same convention as all the other services. Therefore, it provides the following methods: | ||
Creating an in-memory service is this simple: | ||
`find`, `get`, `create`, `update`, `patch`, `remove` and `setup`. | ||
```js | ||
var memoryService = { | ||
find: function(params, callback) {}, | ||
get: function(id, params, callback) {}, | ||
create: function(data, params, callback) {}, | ||
update: function(id, data, params, callback) {}, | ||
patch: function(id, data, params, callback) {}, | ||
remove: function(id, params, callback) {}, | ||
setup: function(app) {} | ||
} | ||
var memory = require('feathers-memory'); | ||
app.use('/todos', memory()); | ||
``` | ||
#### Usage: | ||
This will create a `todos` datastore with the default configuration. | ||
### Complete Example | ||
Here is an example of a Feathers server with a `todos` in-memory service. | ||
```js | ||
var feathers = require('feathers'); | ||
var memory = require('feathers-memory')(); | ||
var app = feathers(); | ||
// server.js | ||
var feathers = require('feathers'), | ||
bodyParser = require('body-parser'), | ||
memory = require('feathers-memory'); | ||
app.configure(feathers.rest()) | ||
.use('/users', memory) | ||
.listen(8080); | ||
// Create a feathers instance. | ||
var app = feathers() | ||
// Setup the public folder. | ||
.use(feathers.static(__dirname + '/public')) | ||
// Enable Socket.io | ||
.configure(feathers.socketio()) | ||
// Enable REST services | ||
.configure(feathers.rest()) | ||
// Turn on JSON parser for REST services | ||
.use(bodyParser.json()) | ||
// Turn on URL-encoded parser for REST services | ||
.use(bodyParser.urlencoded({ extended: true })) | ||
// Connect to the db, create and register a Feathers service. | ||
app.use('/todos', memory()); | ||
// Start the server. | ||
var port = 8080; | ||
app.listen(port, function() { | ||
console.log('Feathers server listening on port ' + port); | ||
}); | ||
``` | ||
#### Extending: | ||
You can run this example by using `node examples/basic` and going to [localhost:8080/todos](http://localhost:8080/todos). You should see an empty array. That's because you don't have any Todos yet but you now have full CRUD for your new todos service. | ||
### Extending | ||
You can also extend any of the feathers services to do something custom. | ||
@@ -54,11 +67,11 @@ | ||
var feathers = require('feathers'); | ||
var memory = require('feathers-memory')(); | ||
var memory = require('feathers-memory'); | ||
var app = feathers(); | ||
var myUserService = memory.extend({ | ||
var myUserService = memory().extend({ | ||
find: function(params, cb){ | ||
// Do something awesome! | ||
console.log('I am extending the find method'); | ||
this._super.apply(this, arguments); | ||
@@ -73,41 +86,165 @@ } | ||
#### Advanced Querying | ||
You are probably also going to want to filter your data. You can do that by passing options via the body or in a query string. Like so: | ||
## Options | ||
The following options can be passed when creating a new memory service: | ||
- `idField` - The name of the id field property. Default is `id` | ||
- `startId` - An id number to start with that will be incremented for new record (default: `0`) | ||
- `store` - An object with id to item assignments to pre-initialize the data store | ||
## Query Parameters | ||
The `find` API allows the use of `$limit`, `$skip`, `$sort`, and `$select` in the query. These special parameters can be passed directly inside the query object: | ||
```js | ||
// Find all recipes that include salt, limit to 10, only include name field. | ||
{"ingredients":"salt", "$limit":10, "$select": { "name" :1 } } // JSON | ||
GET /?ingredients=salt&$limit=10&$select[name]=1 // HTTP | ||
``` | ||
GET /users?name=eric&limit=10&skip=10 | ||
As a result of allowing these to be put directly into the query string, you won't want to use `$limit`, `$skip`, `$sort`, or `$select` as the name of fields in your document schema. | ||
### `$limit` | ||
`$limit` will return only the number of results you specify: | ||
``` | ||
// Retrieves the first two records found where age is 37. | ||
query: { | ||
age: 37, | ||
$limit: 2 | ||
} | ||
``` | ||
__Sort:__ | ||
### `$skip` | ||
`$skip` will skip the specified number of results: | ||
``` | ||
GET /users?sort[]=name&sort[]=age | ||
// Retrieves all except the first two records found where age is 37. | ||
query: { | ||
age: 37, | ||
$skip: 2 | ||
} | ||
``` | ||
__Order:__ | ||
### `$sort` | ||
`$sort` will sort based on the object you provide: | ||
``` | ||
GET /users?order=ascending | ||
// Retrieves all where age is 37, sorted ascending alphabetically by name. | ||
query: { | ||
age: 37, | ||
$sort: { name: 1 } | ||
} | ||
// Retrieves all where age is 37, sorted descending alphabetically by name. | ||
query: { | ||
age: 37, | ||
$sort: { name: -1} | ||
} | ||
``` | ||
__Skip:__ | ||
### `$select` | ||
`$select` support in a query allows you to pick which fields to include or exclude in the results. Note: you can use the include syntax or the exclude syntax, not both together. See the section on [`Projections`](https://github.com/louischatriot/nedb#projections) in the NeDB docs. | ||
``` | ||
GET /users?skip=10 | ||
// Only retrieve name. | ||
query: { | ||
name: 'Alice', | ||
$select: {'name': 1} | ||
} | ||
// Retrieve everything except age. | ||
query: { | ||
name: 'Alice', | ||
$select: {'age': 0} | ||
} | ||
``` | ||
__Limit:__ | ||
## Filter criteria | ||
In addition to sorting and pagination, properties can also be filtered by criteria. Standard criteria can just be added to the query. For example, the following find all users with the name `Alice`: | ||
```js | ||
query: { | ||
name: 'Alice' | ||
} | ||
``` | ||
GET /users?limit=10 | ||
Additionally, the following advanced criteria are supported for each property. | ||
### $in, $nin | ||
Find all records where the property does (`$in`) or does not (`$nin`) contain the given values. For example, the following query finds every user with the name of `Alice` or `Bob`: | ||
```js | ||
query: { | ||
name: { | ||
$in: ['Alice', 'Bob'] | ||
} | ||
} | ||
``` | ||
## Examples | ||
See [examples directory](https://github.com/feathersjs/feathers-memory/tree/master/examples). | ||
### $lt, $lte | ||
## Contributing | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
Find all records where the value is less (`$lt`) or less and equal (`$lte`) to a given value. The following query retrieves all users 25 or younger: | ||
## Release History | ||
```js | ||
query: { | ||
age: { | ||
$lte: 25 | ||
} | ||
} | ||
``` | ||
### $gt, $gte | ||
Find all records where the value is more (`$gt`) or more and equal (`$gte`) to a given value. The following query retrieves all users older than 25: | ||
```js | ||
query: { | ||
age: { | ||
$gt: 25 | ||
} | ||
} | ||
``` | ||
### $ne | ||
Find all records that do not contain the given property value, for example anybody not age 25: | ||
```js | ||
query: { | ||
age: { | ||
$ne: 25 | ||
} | ||
} | ||
``` | ||
### $or | ||
Find all records that match any of the given objects. For example, find all users name Bob or Alice: | ||
```js | ||
query: { | ||
$or: [ | ||
{ name: 'Alice' }, | ||
{ name: 'Bob' } | ||
] | ||
} | ||
``` | ||
## Changelog | ||
__0.4.0__ | ||
- Migrate to new ES6 plugin infrastructure and support all advanced querying mechanisms ([#10](https://github.com/feathersjs/feathers-memory/pull/10)) | ||
__0.3.0__ | ||
@@ -144,3 +281,5 @@ | ||
## License | ||
Copyright (c) 2014 [Eric Kryski](https://github.com/ekryski) | ||
Licensed under the [MIT license](https://github.com/feathersjs/feathers-memory/blob/master/LICENSE-MIT). | ||
Copyright (c) 2015 | ||
Licensed under the [MIT license](LICENSE). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7
283
15269
4
9
168
1
+ Addedfeathers-query-filters@1.5.1(transitive)
+ Addedlodash@3.10.1(transitive)
+ Addeduberproto@1.2.0(transitive)
- Removeduberproto@1.1.2(transitive)
Updatedfeathers-errors@^0.2.5
Updatedlodash@^3.10.1
Updateduberproto@^1.1.2