Coder Social home page Coder Social logo

phobosjs / phobos.js Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 364 KB

A small JSON API framework for Mongoose and Express that takes all the annoyance of middleware out of your hands

Home Page: https://phobos.js.org

License: MIT License

JavaScript 100.00%
rest api crud

phobos.js's Introduction

Phobos.js Build Status bitHound Score downloads/month

A small JSON API framework for Mongoose and Express that takes all the annoyance of middleware out of your hands.

Docs

Go to phobos.js.org for documentation.

A note about ES6

The latest branch of phobosjs is written in ES6. If you want to use the last ES5-compatible version, install release 1.0.21.

phobos.js's People

Contributors

mtimofiiv avatar devboell avatar dependabot[bot] avatar

Stargazers

Alexey avatar Alex B avatar Adriaan avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

mgmco

phobos.js's Issues

Scopes don't work as intended

Using a scope like this on a user that has both client and user scope.

show: {
  scope: [ '*', 'owner', 'client', 'admin' ],
  leanQuery: false
}

I'm expecting my API to return client scoped parameters, instead I get * scoped parameters.

hopelesslybroken

Create a JWT generating and handling system

  • Need to expose the ability to create/verify JWTs.
  • Save the pattern so that lookups can be done on given tokens in a uniform way. Probably save them inside PhobosInstance.
  • Validate/invalidate tokens - this means saving them somewhere

Default responders

The default RESTful CRUD actions shouldn't have to be painstakingly redefined in every controller. There should be some defaults that will be used, but they should be overwritable.

Full suite of CI tests

Not an alpha anymore, so need a full test suite. Gonna use Travis CI to run it each time.

Mutations

Build write controls in!

Each resource should have methods for writing to it, sanitizing params and of course verifying the permissions of the user.

If search param is not present as field in a model

There are going to be cases where someone wants to search using a parameter that will require additional logic than just a simple lookup.

Case in point: a through-type association.

phobos.js should first look to see if a field exists, and if it doesn't but it's whitelisted in searchableBy, then it should look for a function to run in the model's static methods.

Cannot read property while deleting a item

When running DELETE on http://localhost:5020/tasks/56b9e60ff6b55a2c279f488a:

TypeError: Cannot read property 'remove' of null
<br> &nbsp; &nbsp;at mutate (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/phobosjs/middleware/mutate.js:35:25)
<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/express/lib/router/layer.js:95:5)
<br> &nbsp; &nbsp;at next (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/express/lib/router/route.js:131:13)
<br> &nbsp; &nbsp;at applyScope (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/phobosjs/middleware/apply-scope.js:30:29)
<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/express/lib/router/layer.js:95:5)
<br> &nbsp; &nbsp;at next (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/express/lib/router/route.js:131:13)
<br> &nbsp; &nbsp;at ownership (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/phobosjs/middleware/ownership.js:19:29)
<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/express/lib/router/layer.js:95:5)
<br> &nbsp; &nbsp;at next (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/express/lib/router/route.js:131:13)
<br> &nbsp; &nbsp;at scopeCatch (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/phobosjs/middleware/scope-catch.js:40:14)
<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/express/lib/router/layer.js:95:5)
<br> &nbsp; &nbsp;at next (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/express/lib/router/route.js:131:13)
<br> &nbsp; &nbsp;at /Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/phobosjs/middleware/query-runner.js:60:28
<br> &nbsp; &nbsp;at Query.&lt;anonymous&gt; (/Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/mongoose/lib/query.js:2149:28)
<br> &nbsp; &nbsp;at /Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/kareem/index.js:177:19
<br> &nbsp; &nbsp;at /Users/Adriaan/MGMco/phobosjs-sampleapp/node_modules/kareem/index.js:109:16

Possible to use phobos.js as express/connect middleware?

I have an existing Express application, and I'd like to try using Phobos to implement a new API in it (e.g. mount it to /new-api/v1/* with app.use or by passing my app object & path to it, etc.). Is this possible/supported? The example I saw ("Getting Started" / bootstrapping) instead required having phobos be responsible for creating the Express app, which is not what I want.

Resource access control

Middleware should grab the resource and filter it through allowed parameters from the scopes manifest.

Break out ORM from app

Right now, module is entirely dependent on MongoDB through Mongoose. It would be nice to also support some popular relational systems like Postgres.

Build mutator into middleware stack

Currently, the Mutator operates separately from the middleware stack. That was to save complexity for the alpha release. But now it's time to re-integrate it into the stack.

Rewrite in ES6

Great thing about node is we don't really need to worry about ES6 compatibility in the browser. The syntax is a lot nicer, so maybe it would be a good idea to do a bit of a rewrite.

Encoder/decoder for JWT

Should make it possible to specify what is stored in the token + store a session ID rather than a user ID to make the framework more secure.

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.