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

baucis

Package Overview
Dependencies
Maintainers
1
Versions
202
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

baucis - npm Package Compare versions

Comparing version 0.4.5 to 0.4.6

examples/backbone.md

21

index.js

@@ -14,2 +14,3 @@ // Dependencies

var validation = require('./middleware/validation');
var documents = require('./middleware/documents');

@@ -89,14 +90,14 @@ // Module Definition

// Add routes for singular documents
if (options.head !== false) controller.head(basePathWithId, query.head, configure.controller, configure.query, exec.count, send.count);
if (options.get !== false) controller.get(basePathWithId, query.get, configure.controller, configure.query, exec.exec, send.exec);
if (options.post !== false) controller.post(basePathWithId, query.post, configure.controller, configure.query, exec.exec, send.exec);
if (options.put !== false) controller.put(basePathWithId, query.put, configure.controller, configure.query, send.exec);
if (options.del !== false) controller.del(basePathWithId, query.del, configure.controller, configure.query, exec.exec, send.exec);
if (options.head !== false) controller.head(basePathWithId, query.head, configure.controller, configure.query, exec.count, documents.lastModified, documents.send);
if (options.get !== false) controller.get(basePathWithId, query.get, configure.controller, configure.query, exec.exec, documents.lastModified, documents.send);
if (options.post !== false) controller.post(basePathWithId, query.post, configure.controller, configure.query, exec.exec, documents.lastModified, documents.send);
if (options.put !== false) controller.put(basePathWithId, query.put, configure.controller, configure.query, documents.lastModified, documents.send);
if (options.del !== false) controller.del(basePathWithId, query.del, configure.controller, configure.query, exec.exec, documents.lastModified, documents.send);
// Add routes for collections of documents
if (options.head !== false) controller.head(basePath, configure.conditions, query.headCollection, configure.controller, configure.query, exec.count, send.count);
if (options.get !== false) controller.get(basePath, configure.conditions, query.getCollection, configure.controller, configure.query, exec.stream, send.stream);
if (options.post !== false) controller.post(basePath, query.postCollection, send.exec );
if (options.put !== false) controller.put(basePath, query.putCollection, configure.controller, configure.query, exec.exec, send.exec);
if (options.del !== false) controller.del(basePath, configure.conditions, query.delCollection, configure.controller, configure.query, exec.exec, send.exec);
if (options.head !== false) controller.head(basePath, configure.conditions, query.headCollection, configure.controller, configure.query, exec.count, documents.lastModified, documents.send);
if (options.get !== false) controller.get(basePath, configure.conditions, query.getCollection, configure.controller, configure.query, exec.exec, documents.lastModified, documents.send);
if (options.post !== false) controller.post(basePath, query.postCollection, documents.lastModified, documents.send);
if (options.put !== false) controller.put(basePath, query.putCollection, configure.controller, configure.query, exec.exec, documents.lastModified, documents.send);
if (options.del !== false) controller.del(basePath, configure.conditions, query.delCollection, configure.controller, configure.query, exec.exec, documents.lastModified, documents.send);

@@ -103,0 +104,0 @@ // Publish unless told not to

@@ -16,8 +16,22 @@ var middleware = module.exports = {

count: function (request, response, next) {
request.baucis.query.count(function (error, count) {
if (error) return next(error);
request.baucis.count = count;
next();
});
var lastModifiedPath = request.app.get('lastModified');
request.baucis.count = true;
if (lastModifiedPath) {
request.baucis.query.select('-_id ' + lastModifiedPath);
request.baucis.query.exec(function (error, documents) {
if (error) return next(error);
request.baucis.documents = documents;
next();
});
}
else {
request.baucis.query.count(function (error, count) {
if (error) return next(error);
request.baucis.documents = count;
next();
});
}
}
};

@@ -47,6 +47,8 @@ var path = require('path');

},
lastModified: function (request, response, next) {
if (request.baucis.lastModified) response.set('Last-Modified', request.baucis.lastModified);
next();
eTag: function (request, response, next) {
// TODO does Express do this automatically?
// TODO add versioning option for strong Etags
// TODO how does this work with Vary/query options like populate -- do MD5?
response.set('ETag', 'W/"' + request.baucis.model.id + '"');
}
};

@@ -15,2 +15,3 @@ // Private Members

var Model = request.app.get('model');
request.baucis.noBody = true;
request.baucis.query = Model.findOne(getFindCondition(request));

@@ -22,2 +23,3 @@ next();

var Model = request.app.get('model');
request.baucis.noBody = true;
request.baucis.query = Model.find(request.baucis.conditions);

@@ -24,0 +26,0 @@ next();

var path = require('path');
var middleware = module.exports = {
exec: function (request, response, next) {
var ids;
// 404 if document(s) not found or 0 documents removed
if (!request.baucis.documents) return response.send(404);
// If it's a document count (e.g. the result of a DELETE), send it back and short-circuit
if (typeof request.baucis.documents === 'number') {
return response.json(request.baucis.documents);
}
// Otherwise, set the location and send JSON document(s)
if (!Array.isArray(request.baucis.documents)
|| request.baucis.documents.length === 1) {
request.baucis.location = path.join(request.app.get('basePath'), request.baucis.documents.id);
}
else {
ids = request.baucis.documents.map(function (doc) { return doc.id });
request.baucis.location = request.app.get('basePath') + '?conditions={ _id: { $in: [' + ids.join() + '] } }';
}
response.json(request.baucis.documents);
},
count: function (request, response, next) {
// 404 if no matching documents
if (request.baucis.count === 0) return response.send(404);
response.json(request.baucis.count);
},
stream: function (request, response, next) {

@@ -50,6 +22,3 @@ var firstWasProcessed = false;

});
},
promises: function (request, response, next) {
next();
}
}
{
"name": "baucis",
"version": "0.4.5",
"version": "0.4.6",
"main": "index.js",

@@ -5,0 +5,0 @@ "scripts": {

@@ -1,2 +0,2 @@

baucis v0.4.5
baucis v0.4.6
=============

@@ -58,11 +58,23 @@

* GET /api/v1/vegetables — get all or a subset of documents
* GET /api/v1/vegetables/:id — get the addressed document
* PUT /api/v1/vegetables/:id — create or update the addressed document
* POST /api/v1/vegetables — creates new document(s) and sends it/them back
* PUT /api/v1/vegetables/:id — update the addressed document
* DEL /api/v1/vegetables — delete all or a subset of documents
* DEL /api/v1/vegetables/:id — delete the addressed object
* GET /api/v1/vegetables — get all documents
* POST /api/v1/vegetables — creates a new document and sends back its ID
* PUT /api/v1/vegetables — replace all documents with given new documents
* DEL /api/v1/vegetables — delete all documents
RESTful Headers
---------------
* `ETag` is supported natively by Express
* `Last-Modified` can be set by passing `lastModified: 'foo'` to `baucis.rest` in order to set the header field to the value of that path on all requests.
GET requests to the collection return the latest date out of all documents returned by the query.
* `Accept: application/json` is set for all responses.
* The `Allow` header is set automatically, correctly removing HTTP verbs when
those verbs have been disabled with e.g. `put: false`.
* The `Location` HTTP header is set for PUT and POST responses.
* If `relations: true` is passed to `baucis.rest`, the HTTP `Link` header will be set with various links for all responses.
Examples

@@ -193,11 +205,2 @@ --------

RESTful Headers
---------------
* `Accept: application/json` is set for all responses.
* The `Allow` header is set automatically, correctly removing HTTP verbs when
those verbs have been disabled with e.g. `put: false`.
* The `Location` HTTP header is set for PUT and POST responses.
* If `relations: true` is passed to `baucis.rest`, the HTTP `Link` header will be set with various links for all responses.
Controllers

@@ -204,0 +207,0 @@ -----------

@@ -15,3 +15,4 @@ var mongoose = require('mongoose');

var Vegetable = new Schema({
name: { type: String, required: true }
name: { type: String, required: true },
lastModified: { type: Date, required: true, default: Date.now }
});

@@ -22,2 +23,7 @@

Vegetable.pre('save', function (next) {
this.set('lastModified', new Date());
next();
});
Vegetable.pre('save', function (next) {
fixture.preCount += 1;

@@ -31,2 +37,3 @@ next();

singular: 'vegetable',
lastModified: 'lastModified',
all: function (request, response, next) {

@@ -33,0 +40,0 @@ if (request.query.block === "true") return response.send(401);

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