Skip to content

Commit

Permalink
feat: add chainable query interface
Browse files Browse the repository at this point in the history
feat: add #includes() to query class

refactor: move repeatable logic to built in middleware and simplify controller actions

feat: add chainable query interface

refactor: remove half-baked polymorphism
  • Loading branch information
zacharygolba committed Jun 12, 2016
1 parent 425b8de commit 93e3c0a
Show file tree
Hide file tree
Showing 77 changed files with 2,089 additions and 1,647 deletions.
4 changes: 1 addition & 3 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"plugins": [
"syntax-flow",
"syntax-trailing-function-commas",
"transform-decorators-legacy",
"transform-flow-strip-types",
"transform-decorators"
"transform-flow-strip-types"
]
}
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Map": true,
"Set": true,
"Promise": true,
"Proxy": true,
"Symbol": true,
"WeakMap": true,
"Iterable": true,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ With Lux your code from before can now look like this:
```javascript
class PostsController extends Controller {
index(req, res) {
return Post.findAll();
return Post.all();
}
}
```
Expand Down
8 changes: 6 additions & 2 deletions decl/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {

import { Model } from '../src/packages/database';

import type Route from '../src/packages/route';

type params = {
data?: {
id: number | string | Buffer;
Expand All @@ -17,18 +19,20 @@ type params = {
fields: Object;
filter: Object;
id?: number | string | Buffer;
include: Array<string>;
include: Array<string> | Object;
limit: number;
page: number;
sort: string;
sort: string | [string, string];
};

declare module 'http' {
declare class Server extends http$Server {}

declare class IncomingMessage extends http$IncomingMessage {
route?: Route;
params: params;
record?: Model;
method: string;

parsedURL: {
protocol?: string;
Expand Down
11 changes: 2 additions & 9 deletions examples/social-network/.babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{
"presets": [
"es2015",
"stage-1"
],
"plugins": [
"transform-runtime",
"transform-decorators-legacy"
]
}
"presets": ["lux"]
}
6 changes: 1 addition & 5 deletions examples/social-network/app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { Controller } from 'lux-framework';

import authenticate from '../middleware/authenticate';

class ApplicationController extends Controller {
beforeAction = [
authenticate
];

}

export default ApplicationController;
6 changes: 0 additions & 6 deletions examples/social-network/app/controllers/comments.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { Controller } from 'lux-framework';

import setUser from '../middleware/set-user';

class CommentsController extends Controller {
params = [
'message',
'edited'
];

beforeAction = [
setUser
];
}

export default CommentsController;
6 changes: 0 additions & 6 deletions examples/social-network/app/controllers/posts.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { Controller } from 'lux-framework';

import setUser from '../middleware/set-user';

class PostsController extends Controller {
params = [
'body',
'title',
'isPublic'
];

beforeAction = [
setUser
];
}

export default PostsController;
6 changes: 0 additions & 6 deletions examples/social-network/app/controllers/reactions.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { Controller } from 'lux-framework';

import setUser from '../middleware/set-user';

class ReactionsController extends Controller {
params = [
'type'
];

beforeAction = [
setUser
];
}

export default ReactionsController;
47 changes: 1 addition & 46 deletions examples/social-network/app/controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,11 @@
import { Controller, action } from 'lux-framework';

import User from '../models/user';
import { Controller } from 'lux-framework';

class UsersController extends Controller {
params = [
'name',
'email',
'password'
];

@action
async login(req, res) {
const {
session,

params: {
data: {
attributes: {
email,
password
}
}
}
} = req;

const user = await User.authenticate(email, password);

if (user) {
session.set('currentUserId', user.id);
}

return {
data: user
};
}

@action
logout(req, res) {
const {
session,

session: {
isAuthenticated
}
} = req;

if (isAuthenticated) {
session.delete('currentUserId');
}

return isAuthenticated;
}
}

export default UsersController;
4 changes: 2 additions & 2 deletions examples/social-network/app/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Lux from 'lux-framework';
import { Application } from 'lux-framework';

class SocialNetwork extends Lux {
class SocialNetwork extends Application {

}

Expand Down
51 changes: 0 additions & 51 deletions examples/social-network/app/middleware/authenticate.js

This file was deleted.

24 changes: 0 additions & 24 deletions examples/social-network/app/middleware/set-user.js

This file was deleted.

4 changes: 4 additions & 0 deletions examples/social-network/app/models/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class Comment extends Model {
};

static hasMany = {
actions: {
inverse: 'trackable'
},

reactions: {
inverse: 'comment'
}
Expand Down
14 changes: 2 additions & 12 deletions examples/social-network/app/routes.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
export default (route, resource) => {
export default function routes(route, resource) {
resource('comments');
resource('friendships');
resource('posts');
resource('reactions');
resource('users');

route('users/login', {
method: 'POST',
action: 'login'
});

route('users/logout', {
method: 'DELETE',
action: 'logout'
});

route('actions', {
method: 'GET',
action: 'index'
Expand All @@ -34,4 +24,4 @@ export default (route, resource) => {
method: 'GET',
action: 'show'
});
};
}
5 changes: 1 addition & 4 deletions examples/social-network/app/serializers/actions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Serializer } from 'lux-framework';

class ActionsSerializer extends Serializer {
attributes = [
'trackableId',
'trackableType'
];

}

export default ActionsSerializer;
2 changes: 0 additions & 2 deletions examples/social-network/bin/app.js

This file was deleted.

5 changes: 1 addition & 4 deletions examples/social-network/config/environments/development.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export default {
log: true,
domain: 'http://localhost:4000',
sessionKey: 'social-network::development::session',
sessionSecret: 'a6d027382e6c6405674d951fe4e39d50c567020dee231938de063524d339c758'
log: true
};
7 changes: 2 additions & 5 deletions examples/social-network/config/environments/production.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export default {
log: false,
domain: 'http://localhost:4000',
sessionKey: 'social-network::session',
sessionSecret: 'd54dc706d6b7f4f88ddefab178ec8e4370d3ba12d977d8aaff36b782402c207c'
};
log: false
};
7 changes: 2 additions & 5 deletions examples/social-network/config/environments/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export default {
log: true,
domain: 'http://localhost:4000',
sessionKey: 'social-network::test::session',
sessionSecret: 'a893efc5d2677a5aa8dc5adb599f4eee2ea660b426b6c053123eaab28c01ebff'
};
log: false
};
12 changes: 11 additions & 1 deletion examples/social-network/db/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Comment from '../app/models/comment';
import Post from '../app/models/post';
import Reaction from '../app/models/reaction';
import User from '../app/models/user';
import Friendship from '../app/models/friendship';

import range from '../app/utils/range';

Expand All @@ -18,7 +19,7 @@ const {
}
} = faker;

export default async () => {
export default async function seed() {
await Promise.all(
[...range(1, 100)].map(() => {
return User.create({
Expand All @@ -29,6 +30,15 @@ export default async () => {
})
);

await Promise.all(
[...range(1, 100)].map(() => {
return Friendship.create({
userId: randomize([...range(1, 100)]),
friendId: randomize([...range(1, 100)])
});
})
);

await Promise.all(
[...range(1, 100)].map(() => {
return Post.create({
Expand Down
Loading

0 comments on commit 93e3c0a

Please sign in to comment.