Giter VIP home page Giter VIP logo

api-pls's People

Contributors

jamesplease avatar vitaly-t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

vitaly-t

api-pls's Issues

Resource generator

There should be a system for generating a resource. Generation of a resource creates two documents:

  1. a resource definition file. this has validation, for instance.
  2. an initial up/down migration

Eventually, there will also be resource editing. Editing a resource will possibly update the resource definition, and always generate a new migration file.

Map postgres errors

Right now, postgres errors will be reported as generic server errors. I can do better than that. For instance, hitting an endpoint for a resource that doesn't exist in the DB returns the generic error, yet the logged err is:

16:33:01.294Z  WARN JSON-API-Builder: There was an unknown server error. (err.code=42P01)
    error: relation "transaction" does not exist
        at Connection.parseE (/Users/jmeas/webdev/json-api-builder/node_modules/pg/lib/connection.js:539:11)
        at Connection.parseMessage (/Users/jmeas/webdev/json-api-builder/node_modules/pg/lib/connection.js:366:17)
        at TLSSocket.<anonymous> (/Users/jmeas/webdev/json-api-builder/node_modules/pg/lib/connection.js:105:22)
        at emitOne (events.js:96:13)
        at TLSSocket.emit (events.js:188:7)
        at readableAddChunk (_stream_readable.js:176:18)
        at TLSSocket.Readable.push (_stream_readable.js:134:10)
        at TLSWrap.onread (net.js:551:20)

I can use err.code to map these to more human-readable things.

List of postgres errors: https://www.postgresql.org/docs/8.2/static/errcodes-appendix.html

Update root route to follow Endpoints standard

from the endpoints example repo:

{
  "authors": "/v1/authors?include={books,books.chapters,photos}&filter[{id,name,alive,dead,date_of_birth,date_of_death,born_before,born_after}]",
  "books": "/v1/books?include={chapters,firstChapter,series,author,stores,photos}&filter[{author_id,series_id,date_published,published_before,published_after,title}]",
  "chapters": "/v1/chapters?include={book}&filter[{book_id,title,ordering}]",
  "photos": "/v1/photos?include={imageable}",
  "series": "/v1/series?include={books,photos}&filter[{title}]",
  "stores": "/v1/stores?include={books,books.author}"
}

Move away from migration SQL files

The migrations need to be stored in a database, so that someone doesn't need to carry them around on their computer or on a server.

Follow up of #4

Lerna it

This will make the example a better representation of the final API

Resource model validation

I should validate the resource model a little more thoroughly. I can use JSON Schema for this, most likely.

Also, validating the types could be useful. this list of types may help with that.

JSON API Compliance Checklist

This is an incomplete checklist of how incomplete my compliance with JSON API is.

  • attributes (CRUD)
  • meta attributes (CRUD)
  • relations
    • many-to-one
    • many-to-many
    • one-to-one
    • relationship endpoints /v1/:resource/relationships/:related
    • related endpoints /v1/:resource/:related
  • standard errors
  • sparse fieldsets
  • sorting
  • pagination
  • filtering
  • links

Hook up a DB

Careen is great for migrations, but it requires them to be on the disk. I could:

  1. temporarily write them out to the disk for development purposes
  2. wait out to see the resolution of programble/careen#5

Eventually, the migration strings, and their unique IDs, will be stored in the DB that manages the other DB.

Restructure Lerna / possibly move back to single project?

This seems silly, but I may not need Lerna anymore. It was really helpful to get me to think about separating out the example from the tool itself, but now it just seems like the utils are arbitrarily split out from the CLI and the server.

I should either move it all back together, or maybe separate out the CLI from the server.

Think about public API

I'm thinking this lib could be pulled into a project repo, like Moolah. Then you'd write resources / store migrations there to configure the app that the project uses.

Also, instead of having two databases, there can probably just be one DB that stores info about itself. That would keep things simpler.

Add integration tests

I suspect that under-the-hood, things will change quite a bit as I add more features. What I can do to prevent regressions is to write unit tests that just run migrations, then hit endpoints. That way, I can be sure that I'm not introducing bugs into existing features, like editing regular attrs or meta.

Resource dashboard

pls start should start a dashboard for managing resources. it would be a basic crud app

Fix nodemon reboots

Careen is exploding when the app reboots. The error is:

Unhandled rejection error: relation "category" already exists

It's like it's not keeping track of which migrations are being run, or something, because this shouldn't be an issue. I'll have to hop into the DB to see what's being stored.

This may be related to #16

Mock DB support

It could be useful if this tool could also spin up a mock API that's JS-only. This could be useful for:

  1. experimenting with changes before affecting the real db
  2. testing
  3. offline development without needing to set up a local DB

Resolve intermittent careen errors on startup

For some reason, the files that I'm deleting with del are still getting picked up by careen...even after they're gone. I'm not sure what could be causing that...

Careen intermittently errors on startup with the following error:

Unhandled rejection TypeError: Cannot read property '0' of undefined
    at matchesToMigration (/Users/jmeas/webdev/json-api-builder/node_modules/careen/lib/files.js:81:54)
    at /Users/jmeas/webdev/json-api-builder/node_modules/ramda/dist/ramda.js:3865:27
    at /Users/jmeas/webdev/json-api-builder/node_modules/ramda/dist/ramda.js:920:27
    at XWrap.f (/Users/jmeas/webdev/json-api-builder/node_modules/ramda/dist/ramda.js:5350:24)
    at XWrap.@@transducer/step (/Users/jmeas/webdev/json-api-builder/node_modules/ramda/dist/ramda.js:755:25)

Add relationship routes

There are two ways to do this:

  1. Hardcoding the routes in. I can do this because I will know all of the possible relationships from the resource definitions. The downside to this approach is that the route config will become a bit less tidy.

  2. Star routes, then managing finding the routes from within the middleware. This can still use the definitions, but it would keep the route config file more orderly.


There are two types of routes I need to support:

/books/1/relationships/author

/books/1/author

Hidden & encrypted attributes

@tbranyen mentioned the common situation of a User resource that has a password attribute. That attribute is "hidden"; although it exists, it's never returned from a GET and can't be updated with PATCH.

Out of the box, there should be a hidden flag for attributes that provides this exact behavior.


More generally, there should be a system for advanced attributes, including:

  1. hidden attributes (described above)
  2. encrypted attributes (such as passwords)

there may be other use cases.

DB environments

You should be able to specify any number of DBs to connect to. Three common ones would be:

dev, staging, prod

but you could also have one-offs for feature branches, or whatever.

Allow SSL to be optional

I use Postgres.app for local development and it does not have SSL enabled out of the box. It looks like the database config appends ?ssl=true for us, but it would be nice if we could have control over that parameter. Maybe we could include the ssl parameter in our DATABASE_URL variable so that we have control over whether SSL is used in our environments.

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.