Skip to content

Commit

Permalink
Showing 120 changed files with 4,147 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
"es2015",
"stage-1"
],
"plugins": [
"transform-runtime",
"transform-decorators-legacy"
]
}
151 changes: 151 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"ecmaFeatures": {
"modules": true
},
"env": {
"node": true
},
"globals": {
"Map": true,
"Promise": true,
"Symbol": true,
"WeakMap": true,
"before": true,
"describe": true,
"it": true
},
"parser": "babel-eslint",
"rules": {
"strict": 0,
"quotes": [2, "single"],
"comma-dangle": 0,
"no-cond-assign": 1,
"no-console": 0,
"no-constant-condition": 0,
"no-control-regex": 1,
"no-debugger": 1,
"no-dupe-keys": 1,
"no-empty": 0,
"no-empty-character-class": 1,
"no-ex-assign": 1,
"no-extra-boolean-cast": 1,
"no-extra-parens": 0,
"no-extra-semi": 1,
"no-func-assign": 1,
"no-inner-declarations": 0,
"no-invalid-regexp": 1,
"no-negated-in-lhs": 1,
"no-obj-calls": 1,
"no-regex-spaces": 1,
"no-reserved-keys": 0,
"no-sparse-arrays": 1,
"no-unreachable": 1,
"use-isnan": 1,
"valid-jsdoc": 0,
"valid-typeof": 1,

"block-scoped-var": 0,
"complexity": 0,
"consistent-return": 0,
"curly": 1,
"default-case": 0,
"dot-notation": 1,
"eqeqeq": 1,
"guard-for-in": 0,
"no-alert": 1,
"no-caller": 1,
"no-div-regex": 1,
"no-else-return": 0,
"no-eq-null": 0,
"no-eval": 1,
"no-extend-native": 1,
"no-extra-bind": 1,
"no-fallthrough": 1,
"no-floating-decimal": 1,
"no-implied-eval": 1,
"no-labels": 1,
"no-iterator": 1,
"no-lone-blocks": 1,
"no-loop-func": 0,
"no-multi-str": 0,
"no-native-reassign": 0,
"no-new": 1,
"no-new-func": 1,
"no-new-wrappers": 1,
"no-octal": 1,
"no-octal-escape": 1,
"no-proto": 1,
"no-redeclare": 0,
"no-return-assign": 1,
"no-script-url": 1,
"no-self-compare": 1,
"no-sequences": 1,
"no-unused-expressions": 0,
"no-void": 1,
"no-warning-comments": 0,
"no-with": 1,
"radix": 1,
"semi-spacing": 1,
"vars-on-top": 0,
"wrap-iife": 0,
"yoda": 1,

"no-catch-shadow": 1,
"no-delete-var": 1,
"no-label-var": 1,
"no-shadow": 1,
"no-shadow-restricted-names": 1,
"no-undef": 2,
"no-undefined": 0,
"no-undef-init": 1,
"no-unused-vars": [1, {"vars": "all", "args": "none"}],
"no-use-before-define": 0,

"handle-callback-err": 1,
"no-mixed-requires": 1,
"no-new-require": 1,
"no-path-concat": 1,
"no-process-exit": 0,
"no-restricted-modules": 1,
"no-sync": 0,

"key-spacing": 0,
"comma-spacing": 0,
"no-multi-spaces": 0,
"brace-style": 0,
"camelcase": 0,
"consistent-this": [0, "self"],
"eol-last": 1,
"func-names": 0,
"func-style": 0,
"new-cap": 0,
"new-parens": 1,
"no-nested-ternary": 0,
"no-array-constructor": 1,
"no-lonely-if": 0,
"no-new-object": 1,
"no-spaced-func": 1,
"no-ternary": 0,
"no-trailing-spaces": 1,
"no-underscore-dangle": 0,
"no-mixed-spaces-and-tabs": 1,
"quote-props": 0,
"semi": 1,
"sort-vars": 0,
"keyword-spacing": 1,
"space-in-brackets": 0,
"space-in-parens": 0,
"space-infix-ops": 1,
"space-unary-ops": [1, { "words": true, "nonwords": false }],
"max-nested-callbacks": 0,
"one-var": 0,
"wrap-regex": 0,

"max-depth": 0,
"max-len": [1, 80, 4],
"max-params": 0,
"max-statements": 0,
"no-bitwise": 1,
"no-plusplus": 0,
}
}
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist

# dependencies
node_modules/

# misc
*.DS_Store

# logs
log/
*npm-debug.log
17 changes: 17 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# source
/src

# dependencies
/node_modules

# misc
.git
.babelrc
.eslint
*.DS_Store
gulpfile.babel.js
/examples

# logs
/log
npm-debug.log
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Postlight

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
165 changes: 165 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Lux

A MVC style framework for building highly performant, large scale JSON APIs that anybody who knows the JavaScript language and it's modern features will understand.

\* _Inspired by [Rails](https://github.com/rails/rails/), [Ember](http://emberjs.com/), and [React](https://facebook.github.io/react/)._

**Disclaimer:**

This isn't another wrapper around [Express](http://expressjs.com/) or a framework for building frameworks. This also isn't a replacement for server-side frameworks that render DHTML.

## What?

### Features

* Automatic CRUD actions in controllers
* Automatic pagination, sorting, filtering via query params in controllers
* CLI for eliminating boiler plate
* [JSON API](http://jsonapi.org/) 1.0 compliant out of the box
* Chunked/Streamed JSON responses to client over http
* Optimized database queries based on serialized attributes and associations
* Highly extensible - just write reusable JavaScript functions
* Pairs nicely with client-side JavaScript applications 🍷
* Easy to contribute (source is ~2,000 lines of readable JavaScript)
* Routes are stored and accessed via a `Map` not an `Array`
* Embraces ES2015 and beyond
* Classes
* Modules
* Promises & async/await
* Decorators
* Arrow Functions
* etc.


### Philosophies

##### Minimal API surface area

Lux utilizes JavaScript's standard library rather than creating a ton of functions you'll have to learn and remember.

After your learn how to use it, you'll rarely need to look at the docs.

##### Pure functions are awesome

Or more appropriately somewhat pure functions are awesome.

Serving content is done by returning objects, arrays, or other primitives rather than calling `res.end(/* content */);` and returning nothing.

##### Convention over configuration

[Rails](http://rubyonrails.org/) and [Ember](http://emberjs.com/) are great because they make hard decisions for you and make it possible to submit a PR on your first day at a new company. This is rare with Node server frameworks.


## Why?

Frameworks like Rails are pretty great. You can build amazing applications in a reasonable amount of time without a ton of developers working on a project. They have their limitations though. They can be slow and sometimes hard to scale. Not to mention WebSocket support being so-so.

##### Node to the rescue.

It's fast, it allows the developer to get low level with a relatively simple API, WebSockets are stable and supported out of the box, and last but not least it's just JavaScript.

##### Not so fast (metaphorically speaking).

The last bit there "It's just JavaScript" has actually been somewhat of a double edge sword. This has positioned Node as a "great prototyping tool" or "only used for micro services".

I can somewhat see why people would think that when returning a list of the first 10 records from a SQL database table looks like this:

```javascript
app.get('/posts', (req, res) => {
Post.findAll()
.then(posts => {
res.status(200).json(posts);
}, err => {
console.error(err);
res.status(500).send(err.message);
});
});
```

Could you imagine how ugly that would be if you have implement pagination, filtering, sorting, or better yet formatting the response for JSON API?

Also, where does that code live? What file in what folder would I be able to find that? What pattern do you use for organizing this code?

😲Ok ok give me back Rails I'll worry about performance and scaling later. After all premature optimization is the root of all evil.

##### Problem.resolve();

Shouldn't there be a better way to do this? Can't I just return a promise or a JavaScript primitive instead of basically using the native Node http server API?

Fortunately ES2015+ has introduced great new features to the JavaScript language, especially when it comes to meta programming.

With Lux your code from before can now look like this:

```javascript
class PostsController extends Controller {
@action
index(req, res) {
return this.store.query('post', req.params);
}
}
```

Except CRUD actions are taken care of automatically so it would actually look like this:

```javascript
class PostsController extends Controller {

}
```

It's about time a Node server framework learned something from client-side JS frameworks.


## How?

### Installation

```bash
npm install -g lux-framework
```

### Creating Your First Project

Use the `new` command to create your first project.

```bash
lux new <app-name>
```

### Running

To run your application use the `serve` command.

```bash
cd <app-name>
lux serve
```

For more information checkout out the [Guides](https://github.com/postlight/node-framework/wiki).


## Benchmarks

https://github.com/postlight/lux-benchmarks


## Contributing

### Installation

```bash
git clone https://github.com/postlight/lux
cd lux
npm install
```

### Testing

Coming Soon!


## Useful Links

* [JSON API](http://jsonapi.org/)
* [node-orm2](http://dresende.github.io/node-orm2/)
* [Chai](http://chaijs.com/) / [Mocha](http://mochajs.org/)
2 changes: 2 additions & 0 deletions bin/lux
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node --use_strict
require('../dist/packages/cli');
10 changes: 10 additions & 0 deletions examples/social-network/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
"es2015",
"stage-1"
],
"plugins": [
"transform-runtime",
"transform-decorators-legacy"
]
}
Loading

0 comments on commit 4a193b8

Please sign in to comment.