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

koa-mongo-rest

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-mongo-rest - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

docs/coverage.html

10

lib/actions.js

@@ -46,3 +46,3 @@ var parse;

newDocument._id = this.params.id;
result = yield model.create(newDocument).exec();
result = yield model.create(newDocument);
return this.body = result;

@@ -96,3 +96,4 @@ } catch (_error) {

});
result = yield model.create(body).exec();
result = yield model.create(body);
this.status = 201;
return this.body = result;

@@ -107,4 +108,5 @@ } catch (_error) {

try {
result = yield model.create(this.request.query).exec();
return this.body = result;
result = yield model.create(this.request.query);
this.body = result;
return this.status = 201;
} catch (_error) {

@@ -111,0 +113,0 @@ error = _error;

@@ -1,15 +0,20 @@

var actions, api, model, routes;
var createModel, generateActions, generateRoutes;
routes = require('./routes');
generateRoutes = require('./routes');
actions = require('./actions');
generateActions = require('./actions');
model = require('./model');
createModel = require('./model');
api = function(app, schema, mongoUrl) {
model = model(schema, mongoUrl);
actions = actions(model);
return routes = routes(app, schema, actions);
module.exports = function(schema, mongoUrl) {
var actions, model;
model = createModel(schema, mongoUrl);
actions = generateActions(model);
model.generateApi = function(app, prefix) {
if (prefix == null) {
prefix = '';
}
return generateRoutes(app, schema, actions, prefix);
};
return model;
};
module.exports = api;

9

lib/model.js

@@ -1,14 +0,13 @@

var model, mongoose;
var createModel, mongoose;
mongoose = require('mongoose');
model = function(schema, mongoUrl) {
module.exports = createModel = function(schema, mongoUrl) {
var DocumentSchema;
mongoose.connect(mongoUrl);
DocumentSchema = new mongoose.Schema(schema.schema, {
collection: schema.collectionName
collection: schema.collectionName,
versionKey: schema.versionKey
});
return mongoose.model(schema.collectionName, DocumentSchema);
};
module.exports = model;

@@ -1,20 +0,21 @@

var routes;
var generateRoutes;
routes = function(app, schema, actions) {
app.get("/" + schema.collectionName + "/find", actions.findAll);
app.get("/" + schema.collectionName + "/find/:id", actions.findById);
app.get("/" + schema.collectionName + "/create", actions.createWithQuery);
app.get("/" + schema.collectionName + "/destroy/:id", actions.deleteById);
app.get("/" + schema.collectionName + "/update/:id", actions.updateByIdWithQuery);
app.get("/" + schema.collectionName + "/replace/:id", actions.replaceByIdWithQuery);
app.get("/" + schema.collectionName, actions.findAll);
app.get("/" + schema.collectionName + "/:id", actions.findById);
app.post("/" + schema.collectionName, actions.create);
app.post("/" + schema.collectionName + "/:id", actions.updateById);
app["delete"]("/" + schema.collectionName + "/:id", actions.deleteById);
app.put("/" + schema.collectionName + "/", actions.create);
app.put("/" + schema.collectionName + "/:id", actions.replaceById);
return app.patch("/" + schema.collectionName + "/:id", actions.updateById);
module.exports = generateRoutes = function(app, schema, actions, prefix) {
if (prefix == null) {
prefix = '';
}
app.get(prefix + ("/" + schema.collectionName + "/find"), actions.findAll);
app.get(prefix + ("/" + schema.collectionName + "/find/:id"), actions.findById);
app.get(prefix + ("/" + schema.collectionName + "/create"), actions.createWithQuery);
app.get(prefix + ("/" + schema.collectionName + "/destroy/:id"), actions.deleteById);
app.get(prefix + ("/" + schema.collectionName + "/update/:id"), actions.updateByIdWithQuery);
app.get(prefix + ("/" + schema.collectionName + "/replace/:id"), actions.replaceByIdWithQuery);
app.get(prefix + ("/" + schema.collectionName), actions.findAll);
app.get(prefix + ("/" + schema.collectionName + "/:id"), actions.findById);
app.post(prefix + ("/" + schema.collectionName), actions.create);
app.post(prefix + ("/" + schema.collectionName + "/:id"), actions.updateById);
app["delete"](prefix + ("/" + schema.collectionName + "/:id"), actions.deleteById);
app.put(prefix + ("/" + schema.collectionName), actions.create);
app.put(prefix + ("/" + schema.collectionName + "/:id"), actions.replaceById);
app.patch(prefix + ("/" + schema.collectionName + "/:id"), actions.updateById);
};
module.exports = routes;
{
"name": "koa-mongo-rest",
"version": "0.0.4",
"version": "0.1.0",
"description": "generate REST API with koa and mongo",
"main": "lib/index.js",
"scripts": {
"test": "mocha"
"test": "mocha --harmony"
},

@@ -32,16 +32,17 @@ "repository": {

"dependencies": {
"mongoose": "~3.8.3",
"co-body": "0.0.1"
"co-body": "0.0.1",
"mongoose": "^3.8.8"
},
"devDependencies": {
"mocha": "~1.17.0",
"grunt": "~0.4.2",
"grunt-contrib-coffee": "git://github.com/t3chnoboy/grunt-contrib-coffee.git",
"grunt-contrib-watch": "~0.5.3",
"grunt-shell": "~0.6.1",
"grunt-concurrent": "~0.4.2",
"koa-router": "~3.0.2",
"koa": "~0.5.0",
"koa-logger": ">=1.1.1"
"co-mocha": "0.0.2",
"coffee-script": "git://github.com/xixixao/coffee-script",
"gulp": "^3.6.0",
"gulp-coffee-es6": "git://github.com/t3chnoboy/gulp-coffee-es6.git",
"gulp-nodemon": "^1.0.2",
"koa": "^0.5.2",
"koa-logger": "^1.2.0",
"koa-router": "^3.1.2",
"should": "^3.2.0-beta1",
"supertest": "^0.10.0"
}
}

@@ -21,3 +21,3 @@ # Koa mongo REST [![NPM version](https://badge.fury.io/js/koa-mongo-rest.png)](http://badge.fury.io/js/koa-mongo-rest) [![Dependency Status](https://gemnasium.com/t3chnoboy/koa-mongo-rest.png)](https://gemnasium.com/t3chnoboy/koa-mongo-rest) [![Build Status](https://travis-ci.org/t3chnoboy/koa-mongo-rest.png?branch=master)](https://travis-ci.org/t3chnoboy/koa-mongo-rest)

```javascript
api = require('koa-mongo-rest');
var createModel = require('koa-mongo-rest');
```

@@ -27,3 +27,3 @@

```javascript
schema = {
var schema = {
schema: {

@@ -43,13 +43,23 @@ email: String,

```javascript
koa = require('koa');
router = require('koa-router');
var koa = require('koa');
var router = require('koa-router');
mongoUrl = process.env.MONGOLAB_URL;
app = koa();
var mongoUrl = '127.0.0.1:27017'
app.use(logger());
var app = koa();
//router is required
app.use(router(app));
api(app, schema, mongoUrl);
//create mongoose model
//you can use it to create custom actions
var model = app.model = createModel(schema, mongoUrl);
//add REST routes to your app. Prefix is optional
model.generateApi(app, '/api');
app.listen(process.env.PORT || 5000);
```
Live [demo](http://watchlist-koa.herokuapp.com/user)
[App consuming api](http://watchlist-webapp.herokuapp.com/#/)

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

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

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