Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

feathers-memory

Package Overview
Dependencies
Maintainers
2
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feathers-memory - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

15

example/app.js

@@ -1,11 +0,10 @@

var feathers = require('feathers');
var bodyParser = require('body-parser');
var memory = require('../lib');
import feathers from 'feathers';
import bodyParser from 'body-parser';
import rest from 'feathers-rest';
import memory from '../lib';
// Create a feathers instance.
var app = feathers()
// Enable Socket.io
.configure(feathers.socketio())
const app = feathers()
// Enable REST services
.configure(feathers.rest())
.configure(rest())
// Turn on JSON parser for REST services

@@ -28,2 +27,2 @@ .use(bodyParser.json())

console.log('Feathers Todo memory service running on 127.0.0.1:3030');
console.log('Feathers Todo memory service running on 127.0.0.1:3030');
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -38,3 +38,3 @@ Object.defineProperty(exports, "__esModule", {

var Service = (function () {
var Service = function () {
function Service() {

@@ -197,3 +197,3 @@ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

return Service;
})();
}();

@@ -200,0 +200,0 @@ function init(options) {

{
"name": "feathers-memory",
"description": "An in memory service store",
"version": "0.5.1",
"version": "0.5.2",
"homepage": "https://github.com/feathersjs/feathers-memory",

@@ -11,8 +11,3 @@ "main": "lib/",

],
"license": [
{
"type": "MIT",
"url": "https://github.com/feathersjs/feathers-memory/blob/master/LICENSE"
}
],
"license": "MIT",
"repository": {

@@ -44,3 +39,4 @@ "type": "git",

"mocha": "mocha test/ --compilers js:babel-core/register",
"test": "npm run compile && npm run jshint && npm run mocha"
"test": "npm run compile && npm run jshint && npm run mocha && nsp check",
"example": "babel-node example/app.js"
},

@@ -52,4 +48,6 @@ "directories": {

"babel-polyfill": "^6.2.0",
"feathers": "^2.0.0-pre.4",
"feathers-errors": "^1.1.4",
"feathers-query-filters": "^1.1.1",
"feathers-rest": "^1.1.1",
"lodash": "^3.10.1",

@@ -64,15 +62,7 @@ "uberproto": "^1.2.0"

"body-parser": "^1.14.1",
"feathers": "^1.1.1",
"feathers-service-tests": "^0.5.0",
"jshint": "^2.8.0",
"mocha": "^2.3.3"
},
"babel": {
"plugins": [
"add-module-exports"
],
"presets": [
"es2015"
]
"mocha": "^2.3.3",
"nsp": "^2.2.0"
}
}

@@ -14,14 +14,11 @@ # feathers-memory

## Documentation
## Getting Started
Please refer to the [Feathers database adapter documentation](http://docs.feathersjs.com/databases/readme.html) for more details or directly at:
You can create an in-memory service with no options:
- [In Memory](http://docs.feathersjs.com/databases/memory.html) - The detailed documentation for this adapter
- [Extending](http://docs.feathersjs.com/databases/extending.html) - How to extend a database adapter
- [Pagination and Sorting](http://docs.feathersjs.com/databases/pagination.html) - How to use pagination and sorting for the database adapter
- [Querying](http://docs.feathersjs.com/databases/querying.html) - The common adapter querying mechanism
```js
var memory = require('feathers-memory');
app.use('/todos', memory());
```
This will create a `todos` datastore with the default configuration.
## Complete Example

@@ -32,13 +29,11 @@

```js
// app.js
var feathers = require('feathers');
var bodyParser = require('body-parser');
var memory = require('feathers-memory');
import feathers from 'feathers';
import bodyParser from 'body-parser';
import rest from 'feathers-rest';
import memory from '../lib';
// Create a feathers instance.
var app = feathers()
// Enable Socket.io
.configure(feathers.socketio())
const app = feathers()
// Enable REST services
.configure(feathers.rest())
.configure(rest())
// Turn on JSON parser for REST services

@@ -70,276 +65,9 @@ .use(bodyParser.json())

app.listen(port, function() {
console.log('Feathers server listening on port ' + port);
console.log(`Feathers server listening on port ${port}`);
});
```
You can run this example by using `node examples/app` and going to [localhost:3030/todos](http://localhost:3030/todos). You will see the test Todo that we created at the end of that file.
You can run this example by using `npm run example` and going to [localhost:3030/todos](http://localhost:3030/todos). You will see the test Todo that we created at the end of that file.
## Extending
There are several ways to extend the basic CRUD functionality of this service.
_Keep in mind that calling the original service methods will return a Promise that resolves with the value._
### feathers-hooks
The most flexible option is weaving in functionality through [feathers-hooks](https://github.com/feathersjs/feathers-hooks), for example, `createdAt` and `updatedAt` timestamps could be added like this:
```js
var feathers = require('feathers');
var hooks = require('feathers-hooks');
var memory = require('feathers-memory');
var app = feathers()
.configure(hooks())
.use('/todos', memory({
paginate: {
default: 2,
max: 4
}
}));
var stripIds = function() {
delete hook.data.id;
next();
}
var updateTimestamp = function(hook, next) {
hook.data.updatedAt = new Date();
next();
}
app.service('todos').before({
// You can create a single hook like this
create: function(hook, next) {
hook.data.createdAt = new Date();
next();
},
// Or you can chain multiple hooks like this
update: [stripIds, updateTimeStamp]
});
app.listen(3030);
```
### Classes (ES6)
The module also exports a Babel transpiled ES6 class as `Service` that can be directly extended like this:
```js
import { Service } from 'feathers-memory';
class MyService extends Service {
create(data, params) {
data.created_at = new Date();
return super.create(data, params).then(todo);
}
}
app.use('/todos', new MyService({
paginate: {
default: 2,
max: 4
}
}));
```
### Uberproto (ES5)
You can also use `.extend` on a service instance (extension is provided by [Uberproto](https://github.com/daffl/uberproto)):
```js
var myService = memory({
paginate: {
default: 2,
max: 4
}
}).extend({
create: function(data) {
data.created_at = new Date();
return this._super.apply(this, arguments);
}
});
app.use('/todos', myService);
```
**Note:** _this is more for backwards compatibility. We recommend the usage of hooks as they are easier to test, easier to maintain and are more flexible._
## 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
- `paginate` - A pagination object containing a `default` and `max` page size (see below)
## Pagination
When initializing the service you can set the following pagination options in the `paginate` object:
- `default` - Sets the default number of items
- `max` - Sets the maximum allowed number of items per page (even if the `$limit` query parameter is set higher)
When `paginate.default` is set, `find` will return an object (instead of the normal array) in the following form:
```
{
"total": "<total number of records>",
"limit": "<max number of items per page>",
"skip": "<number of skipped items (offset)>",
"data": [/* data */]
}
```
## 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"] } } // JSON
GET /?ingredients=salt&$limit=10&$select[]=name // HTTP
```
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
}
```
### `$skip`
`$skip` will skip the specified number of results:
```
// Retrieves all except the first two records found where age is 37.
query: {
age: 37,
$skip: 2
}
```
### `$sort`
`$sort` will sort based on the object you provide:
```
// 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}
}
```
### `$select`
`$select` support in a query allows you to pick which fields to include or exclude in the results.
```
// Only retrieve name.
query: {
name: 'Alice',
$select: {'name': 1}
}
// Retrieve everything except age.
query: {
name: 'Alice',
$select: {'age': 0}
}
```
## 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'
}
```
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']
}
}
```
### $lt, $lte
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:
```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

@@ -346,0 +74,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc