Giter VIP home page Giter VIP logo

restify-mongoose's People

Contributors

christophwalcher avatar djensen47 avatar edsadr avatar ismarslomic avatar jmwohl avatar kolbma avatar mancvso avatar mpareja avatar neamar avatar saintedlama avatar tiago-marques avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

restify-mongoose's Issues

remove parseCommaParam function in populate

query = query.populate(parseCommaParam(populate));

My suggestion is to remove the parseCommaParam function because the benefit is greater to use the population function like populate({ path: 'author', select: 'name' })...

Band.
  find({}).
  populate({ path: 'members', select: 'name' }).
  exec(function(error, bands) {
    // Won't work, foreign field `band` is not selected in the projection
  });

Source https://mongoosejs.com/docs/populate.html

NPM Release of v0.2.6

@saintedlama Can you please do NPM release of v0.2.6. I have done all preparation in GitHub, but I dont have access to the NPM package to do the release in NPM.

Documentation request: auth and access control

In many APIs in the wild there are some common requirements which are not mentioned in the README:

  • Authentication: The ability for a user to prove who they are to the server. (Can be stateless, e.g. with JWT.)

  • Access control: The ability for the system to restrict access of some data and operations to certain users.

I do not expect restify-mongoose to provide implementations of these features, but if restify-mongoose can support these behaviours, it would be helpful to see them documented in the README.

For example, something like this could be reassuring, and could increase adoption:

// If you want auth:
// server.use(restify.plugins.authorizationParser());

// If you want access control:
// server.get('/notes', notes.queryVisibleToUser());
// server.get('/notes/:id', checkUserCanView, notes.detail());
// server.post('/notes', checkUserCanAdd, notes.insert());
// server.patch('/notes/:id', checkUserCanModify, notes.insert());
// server.del('/notes/:id', checkUserIsOwner, notes.remove());

I am not sure if the code above would be the most appropriate solution. That's why I'm asking here!

sort and select as options in query configurations

is there any reason why sort and select are only available as part of a request get parameters and cannot be instantiated on the options object initialising the query method?
Could behave just as populate does

Pass the options object to all functions

Right now options is only available for the details and query functions. The filter function, however, seems to be applied to all of the functions except insert.

For consistency, it seems that options should be available on update and delete as well.

If you agree, I can submit a pull request. Just didn't want to do the work if there was a good reason not too.

Page size 100 limit ?

wow, I use this package every day, however recently i got a request that i need to grab more than 100, ex. 1000 or even 5000 records. Is there a way that i can change this behavior quickly without changing source code.

Thank you.

A way to automate mongoose model methods mapping

It would be pretty cool to make restifyMongoose resource support custom model methods and improove restifyMongoose::serve function to automatically generate api endpoint for those methods.
For example:
When we have model...

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const _schema = new Schema({
  title:  String,
  toggle: { type: Boolean, default: false }
});

_schema.methods.switch = function () {
  this.toggle = !this.toggle;
  this.save();
};

var Toggler = mongoose.model('Toggler', _schema);

... it would be great to generate endpoint /Toggler/:id/switch wich will call appropriate method.

Chaining [Discussion]

Like Express, Restify allows chaining on path definitions. It would be great if I could pass a chain of callback functions to the quick mapping.

The use case I have in mind is checking authorization on requests.

I use a plugin handler to do the initial authentication handling. Since not all APIs need to be protected, I have a callback function that I use to "protect" a particular path. The path ends up looking like this.

  var opts = {
    filter: function userFilter(req, res) {
      return {user: req.user.userId};
    }
  }

  var notes = restifyMongoose(Rule, opts);
  server.get('/notes/:id', authenticate, notes.detail());
  server.get('/rules', authenticate, rules.query());

I would prefer to do something like this:

restifyMongoose(models.Note, opts, authenticate, f1, f2, f3).serve('/notes', server);

Just like Restify allows, the constructor would allow you to pass or "chain" as many functions as you need.

Thoughts?

Feature Request: Implement the options.filter with support for async/promises

I don't have the data for the filter in request or response.
There is needed a mongoose query to get this data.
These queries are always async. So I get the result only in a callback or via promise.

No way to return a complete object by the called function:
https://github.com/saintedlama/restify-mongoose/blob/master/index.js#L267
query.where(self.options.filter(req, res));

I've to write a lot of code to get this to work...

This is TypeScript:

function createBookController(req: restify.Request): Promise<restifyMongoose> {
  return controlHelper.dependRequestUser(req)
    .then((user) => {
      const filterobj = { _creator: user._id };
      return createDynfilterFn(filterobj);
    })
    .then((dynfilter) => {
      const bookController = restifyMongoose(Book, {
        filter: dynfilter,
        listProjection: listProjection,
        detailProjection: detailProjection
      });
      log.debug('Created bookController with filter ' + JSON.stringify(dynfilter(undefined, undefined)));
      return bookController;
    });
}

export function query(req: restify.Request, res: restify.Response, next: restify.Next) {
  createBookController(req).then((bookController: restifyMongoose) => {
    bookController.query()(req, res, next);
  });
}

function createDynfilterFn(filterobj: Object): Function {
  const obj = filterobj;
  return (request: restify.Request, response: restify.Response) => {
    return obj;
  };
}

So it would be quite handy if I could give a promise to the filter option.
Or is there another solution?

Allow transformation for insert & update [Discussion]

This is what I'm working on now. Actually, it's done, I just need to write the tests.

Resource.prototype.insert = function (transform) {
  var self = this;
  var emitInsert = emitEvent(self, 'insert');

  return function(req, res, next) {
    if (transform && typeof transform === 'function') {
      transform(req, res);  
    }
    self.Model.create(req.body, function (err, model) {
      if (err) {
        return onError(err, next);
      }

      res.header('Location', req.url + '/' + model._id);
      res.send(200, model);

      emitInsert(model, next);
    });
  };
};

The idea is that sometimes on an insert or update, you need to modify the data that will be saved. Specifically, an authenticated user POSTing a new note shouldn't have to pass in their own id if we already have it on every request. Thus the transform function.

I wanted to run this by you before I finished the tests and submitted a pull request.

self.options.filter is wrong

Whenever occurs the "self.options.filter" it should be changed to "options.filter". If a pull request is needed I'd be glad to suggest it. Please, let me know and thanks for your appreciated work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.