New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.6.28 to 0.7.0

test/fixtures/subcontroller.js

16

CHANGES.md
Baucis Change Log
=================
v0.7.0
------
Add support for hint and comment. Enable them like so:
baucis.rest({
singular: 'fish',
'allow hints': true,
'allow comments': true
});
Note: I decided to be more strict with implementing semver. Minor version will be increasing with each new feature and patch number will be increased with bug fixes and misc. patches.
v0.6.29
-------
Fix issue #86 which caused request.baucis.controller to sometimes be set incorrectly.
v0.6.28

@@ -5,0 +21,0 @@ -------

25

Controller.js

@@ -43,6 +43,2 @@ // __Dependencies__

// Mixins
mixins.middleware.apply(controller);
mixins.swagger.apply(controller);
// Return the array of active verbs

@@ -99,3 +95,7 @@ controller.activeVerbs = function () {

controller.set('findBy', options.findBy || '_id');
controller.set('allow set', options['allow set'] || false);
controller.set('allow pull', options['allow pull'] || false);
controller.set('allow push', options['allow push'] || false);
controller.set('allow comments', options['allow comments'] || false);
controller.set('allow hints', options['allow hints'] || false);

@@ -122,17 +122,6 @@ controller.set('basePath', basePath);

// __Initial Middleware__
// __Mixins__
mixins.middleware.apply(controller);
mixins.swagger.apply(controller);
// Middleware for parsing JSON POST/PUTs
controller.use(express.json());
// Middleware for parsing form POST/PUTs
controller.use(express.urlencoded());
// Initialize baucis state
controller.use(function (request, response, next) {
request.baucis = {};
request.baucis.controller = controller;
next();
});
return controller;

@@ -139,0 +128,0 @@ };

@@ -35,23 +35,51 @@ // __Module Definition__

},
// Apply various options based on request query parameters
// Apply various options based on request query parameters.
query: function (request, response, next) {
var populate;
var populate = request.query.populate;
var hint = request.query.hint;
var select = request.query.select;
var sort = request.query.sort;
var skip = request.query.skip;
var limit = request.query.limit;
var comment = request.query.comment;
var error = null;
var query = request.baucis.query;
if (request.query.sort) query.sort(request.query.sort);
if (request.query.skip) query.skip(request.query.skip);
if (request.query.limit) query.limit(request.query.limit);
if (request.query.select && request.baucis.query) {
if (request.query.select.indexOf('+') !== -1) {
if (sort) query.sort(sort);
if (skip) query.skip(skip);
if (limit) query.limit(limit);
if (comment) {
if (request.baucis.controller.get('allow comments') === true) {
query.comment(comment);
}
else {
console.warn('Query comment was ignored.');
}
}
if (hint) {
if (request.baucis.controller.get('allow hints') === true) {
if (typeof hint === 'string') hint = JSON.parse(hint);
Object.keys(hint).forEach(function (path) {
hint[path] = Number(hint[path]);
});
query.hint(hint);
}
else {
response.send(403, 'Hints are not enabled for this resource.');
}
}
if (select && request.baucis.query) {
if (select.indexOf('+') !== -1) {
return next(new Error('Including excluded fields is not permitted.'));
}
if (request.baucis.controller.checkBadSelection(request.query.select)) {
if (request.baucis.controller.checkBadSelection(select)) {
return next(new Error('Including excluded fields is not permitted.'));
}
query.select(request.query.select);
query.select(select);
}
if (request.query.populate) {
populate = request.query.populate;
if (populate) {
if (typeof populate === 'string') {

@@ -58,0 +86,0 @@ if (populate.indexOf('{') !== -1) populate = JSON.parse(populate);

// This is a Controller mixin for adding methods to manage middleware creation.
// __Dependencies__
var express = require('express');
var middleware = require('../middleware');

@@ -173,2 +174,18 @@

// __Initialization Middleware__
// Initialize baucis state
activateOverride('request', function (request, response, next) {
if (request.baucis) return next(new Error('Baucis request property already created!'));
request.baucis = {};
request.baucis.controller = controller;
next();
});
// Middleware for parsing JSON POST/PUTs
activateOverride('request', express.json());
// Middleware for parsing form POST/PUTs
activateOverride('request', express.urlencoded());
// __Request-Stage Middleware__

@@ -175,0 +192,0 @@

@@ -5,3 +5,3 @@ {

"homepage": "https://github.com/wprl/baucis",
"version": "0.6.28",
"version": "0.7.0",
"main": "index.js",

@@ -30,3 +30,5 @@ "scripts": {

"mongo",
"rfc2616"
"rfc2616",
"web",
"http"
],

@@ -33,0 +35,0 @@ "dependencies": {

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

baucis v0.6.28
baucis v0.6.29
==============

@@ -8,3 +8,3 @@

Baucis uses [semver](http://semver.org).
Baucis uses [semver](http://semver.org). Each new feature results in a minor version increase, each bug fix in a patch number increase.

@@ -16,10 +16,10 @@ <a href="https://www.gittip.com/wprl/">Donations via gittip.com are appreciated.</a>

Lots of bug fixes and minor enhancements were added during v0.6.x. Baucis now includes over 120 Mocha.js tests!
A [change log](CHANGES.md) has been added with info about each new release. Check there for the latest update notes.
v0.6 has taken a detour into many small improvements and fixes. Your suggestions, bug reports, forks, and patches are welcome!
[Swagger](https://developers.helloreverb.com/swagger/) support has been partially added but is rather inflexible at the moment. More Swagger functionality is planned in the near future.
Additional swagger functionality is still planned before moving on to v0.7.
Want to check it out now? Create your API with the swagger option enabled:
[Swagger](https://developers.helloreverb.com/swagger/) support has been partially added but is rather inflexible at the moment. Want to check it out? Create your API with the swagger option enabled:
app.use('/api/v1', baucis({ swagger: true }));

@@ -112,2 +112,4 @@

| count | May be set to true for GET requests to specify that a count should be returned instead of documents |
| hint | Add an index hint to the query (must be enabled per controller).
| comment | Add a comment to a query (must be enabled per controller).

@@ -206,2 +208,7 @@ It is not permitted to use the `select` query option to select deselected paths. This is to allow a mechanism for hiding fields from client software.

| lastModified | Set the `Last-Modified` HTTP header using the given field. Currently this field must be a `Date`. |
| allow push | *BYPASSES VALIDATION* Allow using X-Baucis-Update-Operator to push to a document's path. |
| allow pull | *BYPASSES VALIDATION* Allow using X-Baucis-Update-Operator to pull from a document's path. |
| allow set | *BYPASSES VALIDATION* Allow using X-Baucis-Update-Operator to set a document's path. |
| allow hints | Allow sending an index hint from the client. |
| allow comments | Allow sending a query comment from the client. |
| head, get, post, put, del | May be set to false to disable those HTTP verbs completely for the controller |

@@ -208,0 +215,0 @@

@@ -30,3 +30,3 @@ var expect = require('expect.js');

if (err) return done(err);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.have.property('length', 3);

@@ -49,3 +49,3 @@ expect(body[1]).to.have.property('color', 'Yellow');

if (err) return done(err);
expect(response.statusCode).to.be(201);
expect(response).to.have.property('statusCode', 201);
expect(body).to.have.property('color', 'Green');

@@ -67,3 +67,3 @@ expect(body).to.have.property('name', 'Gorgonzola');

if (err) return done(err);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.have.property('color', 'White');

@@ -85,3 +85,3 @@ expect(body).to.have.property('name', 'Cheddar');

if (err) return done(err);
expect(response.statusCode).to.be(201);
expect(response).to.have.property('statusCode', 201);
expect(body).to.have.property('_id');

@@ -101,3 +101,3 @@ expect(body).to.have.property('__v');

if (err) return done(err);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.have.property('color', 'White');

@@ -143,3 +143,3 @@ done();

if (err) return done(err);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.be('OK!');

@@ -157,3 +157,3 @@ done();

if (err) return done(err);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.be('XYZ');

@@ -172,3 +172,3 @@ done();

if (err) return done(err);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.eql([ { name: 'Corner' }, { name: 'Westlake' } ]);

@@ -181,3 +181,3 @@ done();

var options = {
url: 'http://localhost:8012/api/v1/stores/123/tools',
url: 'http://localhost:8012/api/v1/stores/123/tools?sort=name',
json: true

@@ -187,3 +187,5 @@ };

if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.have.property('length', 3);
expect(body[0]).to.have.property('name', 'Axe');
done();

@@ -200,3 +202,4 @@ });

if (error) return done(error);
expect(response.statusCode).to.be(201);
expect(response).to.have.property('statusCode', 201);
expect(body).to.have.property('bogus', false);
done();

@@ -213,3 +216,4 @@ });

if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.be(3);
done();

@@ -221,3 +225,3 @@ });

var options = {
url: 'http://localhost:8012/api/v1/stores/123/tools',
url: 'http://localhost:8012/api/v1/stores/123/tools?sort=name',
json: true

@@ -227,3 +231,5 @@ };

if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.have.property('length', 3);
expect(body[0]).to.have.property('name', 'Axe');

@@ -237,3 +243,4 @@ var id = body[0]._id;

if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.have.property('name', 'Axe');
done();

@@ -251,3 +258,3 @@ });

if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);

@@ -261,3 +268,5 @@ var id = body[0]._id;

if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.have.property('name', 'Screwdriver');
expect(body).to.have.property('bogus', false);
done();

@@ -270,3 +279,3 @@ });

var options = {
url: 'http://localhost:8012/api/v1/stores/123/tools',
url: 'http://localhost:8012/api/v1/stores/123/tools?sort=name',
json: true

@@ -276,3 +285,6 @@ };

if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.have.property('length', 3);
expect(body[0]).to.have.property('name', 'Axe');
expect()

@@ -286,3 +298,4 @@ var id = body[0]._id;

if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.be(1);
done();

@@ -295,3 +308,3 @@ });

var options = {
url: 'http://localhost:8012/api/v1/stores/',
url: 'http://localhost:8012/api/v1/stores/?sort=name',
json: true

@@ -301,3 +314,4 @@ };

if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.have.length(2);
done();

@@ -314,3 +328,4 @@ });

if (error) return done(error);
expect(response.statusCode).to.be(201);
expect(response).to.have.property('statusCode', 201);
expect(body).not.to.have.property('bogus');
done();

@@ -325,5 +340,6 @@ });

};
request.get(options, function (error, response, body) {
request.del(options, function (error, response, body) {
if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.be(2);
done();

@@ -340,3 +356,4 @@ });

if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.have.property('name', 'Westlake');
done();

@@ -353,3 +370,4 @@ });

if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.have.property('mercoledi', false);
done();

@@ -366,3 +384,4 @@ });

if (error) return done(error);
expect(response.statusCode).to.be(200);
expect(response).to.have.property('statusCode', 200);
expect(body).to.be(1);
done();

@@ -369,0 +388,0 @@ });

@@ -67,3 +67,5 @@ // __Dependencies__

lastModified: 'lastModified',
relations: true
relations: true,
'allow hints': true,
'allow comments': true
});

@@ -70,0 +72,0 @@

@@ -407,2 +407,79 @@ var expect = require('expect.js');

});
it('should report bad hints', function (done) {
var options = {
url: 'http://localhost:8012/api/v1/vegetables?count=true&hint={ "foogle": 1 }',
json: true
};
request.get(options, function (error, response, body) {
if (error) return done(error);
expect(response).to.have.property('statusCode', 500);
done();
});
});
it('should allow adding index hint', function (done) {
var options = {
url: 'http://localhost:8012/api/v1/vegetables?count=true&hint={ "_id": 1 }',
json: true
};
request.get(options, function (error, response, body) {
if (error) return done(error);
expect(response).to.have.property('statusCode', 200);
expect(body).to.be(8);
done();
});
});
it('should allow adding index hint', function (done) {
var options = {
url: 'http://localhost:8012/api/v1/vegetables?count=true&hint[_id]=1',
json: true
};
request.get(options, function (error, response, body) {
if (error) return done(error);
expect(response).to.have.property('statusCode', 200);
expect(body).to.be(8);
done();
});
});
it('should allow adding a query comment', function (done) {
var options = {
url: 'http://localhost:8012/api/v1/vegetables?count=true&comment=testing testing 123',
json: true
};
request.get(options, function (error, response, body) {
if (error) return done(error);
expect(response).to.have.property('statusCode', 200);
expect(body).to.be(8);
done();
});
});
it('should not allow adding an index hint if not enabled', function (done) {
var options = {
url: 'http://localhost:8012/api/v1/fungi?hint={ "_id": 1 }',
json: true
};
request.get(options, function (error, response, body) {
if (error) return done(error);
expect(response).to.have.property('statusCode', 403);
done();
});
});
it('should ignore query comments if not enabled', function (done) {
var options = {
url: 'http://localhost:8012/api/v1/fungi?comment=testing testing 123',
json: true
};
request.get(options, function (error, response, body) {
if (error) return done(error);
expect(response).to.have.property('statusCode', 200);
done();
});
});
});
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