koa-mongo-rest
Advanced tools
Comparing version 0.0.4 to 0.1.0
@@ -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; |
@@ -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
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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
56508
29
197
63
1
10
+ Addedasync@0.9.0(transitive)
+ Addeddebug@0.7.4(transitive)
+ Addedhooks@0.3.2(transitive)
+ Addedkareem@0.0.4(transitive)
+ Addedkerberos@0.0.4(transitive)
+ Addedmongodb@1.4.12(transitive)
+ Addedmongoose@3.9.7(transitive)
+ Addedmpromise@0.5.4(transitive)
+ Addedmquery@1.0.0(transitive)
+ Addedmuri@0.3.1(transitive)
- Removedbluebird@2.10.2(transitive)
- Removeddebug@2.2.0(transitive)
- Removedhooks@0.2.1(transitive)
- Removedkerberos@0.0.11(transitive)
- Removedmongodb@1.4.38(transitive)
- Removedmongoose@3.8.40(transitive)
- Removedmpromise@0.4.3(transitive)
- Removedmquery@1.10.0(transitive)
- Removedms@0.7.1(transitive)
- Removedmuri@1.1.0(transitive)
Updatedmongoose@^3.8.8