git ssb

1+

dinoworm ๐Ÿ› / catstack



Commit 7565f0a3a2bb8400488b3acd6395b0306df1c5df

iterate towards a working api

Michael Williams committed on 1/7/2016, 10:39:48 AM
Parent: c8f38fdc12fc63564d14f8dc103917bdbbfcadcd

Files changed

.gitignorechanged
app/api.jschanged
app/todos/models.jsadded
app/todos/service.jsadded
app/db.jsadded
app/services/index.jsdeleted
app/stack/index.jsdeleted
app/stack/services.jsdeleted
config/development.jschanged
package.jsonchanged
.gitignoreView
@@ -1,4 +1,5 @@
11 /node_modules
22 npm-debug.log*
33
44 /build
5+/db*
app/api.jsView
@@ -1,12 +1,28 @@
1+const bulk = require('bulk-require')
12 import feathers from 'feathers'
2-import { mapObjIndexed, reduce, toPairs } from 'ramda'
3+import hooks from 'feathers-hooks'
4+import rest from 'feathers-rest'
5+import bodyParser from 'body-parser'
6+import { map, mapObjIndexed, reduce, toPairs } from 'ramda'
37
4-import services from 'app/services'
5-import config from 'app/config'
8+const services = {
9+ ...map(
10+ (module) => module.service.default,
11+ bulk(__dirname, '*/service.js')
12+ ),
13+ ...map(
14+ (module) => module.services.map(m => m.default),
15+ bulk(__dirname, '*/services/*.js')
16+ )
17+}
618
719 export default function createServer (config) {
820 const app = feathers()
21+ .configure(rest())
22+ .configure(hooks())
23+ .use(bodyParser.json())
24+ .use(bodyParser.urlencoded({ extended: true }))
925
1026 useAll(app, services)
1127
1228 return app
app/todos/models.jsView
@@ -1,0 +1,9 @@
1+import t from 'tcomb'
2+
3+export const Todo = t.struct({
4+ id: t.Number,
5+ text: t.String,
6+ complete: t.Boolean
7+}, 'Todo')
8+
9+export const Todos = t.list(Todo, 'Todos')
app/todos/service.jsView
@@ -1,0 +1,16 @@
1+import knexService from 'feathers-knex'
2+import validate from 'feathers-tcomb'
3+
4+import db from 'app/db'
5+
6+import { Todo } from './models'
7+
8+export default knexService({
9+ Model: db,
10+ name: 'todos'
11+}).extend({
12+ setup: function (app) {
13+ this._super && this._super(app)
14+ validate(app.service('todos'), Todo)
15+ }
16+})
app/db.jsView
@@ -1,0 +1,5 @@
1+import knex from 'knex'
2+
3+import config from 'app/config'
4+
5+export default knex(config.db)
app/services/index.jsView
@@ -1,13 +1,0 @@
1-const bulk = require('bulk-require')
2-import { map } from 'ramda'
3-
4-export default {
5- ...map(
6- (module) => m.service.default,
7- bulk(__dirname, '*/service.js')
8- ),
9- ...map(
10- (module) => module.services.map(m => m.default),
11- bulk(__dirname, '*/services/*.js')
12- )
13-}
app/stack/index.jsView
@@ -1,34 +1,0 @@
1-import feathers from 'feathers'
2-import { mapObjIndexed, reduce, toPairs } from 'ramda'
3-
4-const stackCreators = {
5- services: require('./services'),
6- static: require('./static'),
7- render: require('./render')
8-}
9-
10-export default function createStack(config) {
11- const stacks = createStacks(config)
12-
13- const app = feathers()
14-
15- useAll(app, stacks)
16-
17- return app
18-}
19-
20-function createStacks (config) {
21- return mapObjIndexed(
22- (stackCreator, name) => {
23- return stackCreator(config[name])
24- },
25- stackCreators
26- )
27-}
28-
29-function useAll (app, services) {
30- return reduce((app, [name, service]) => {
31- return app.use(service)
32- }, app, toPairs(services))
33-}
34-
app/stack/services.jsView
config/development.jsView
@@ -1,2 +1,10 @@
1+const join = require('path').join
2+
13 module.exports = {
4+ db: {
5+ client: 'sqlite3',
6+ connection: {
7+ filename: join(__dirname, '..', 'db.sqlite')
8+ }
9+ }
210 }
package.jsonView
@@ -90,8 +90,11 @@
9090 "ecstatic": "^1.4.0",
9191 "envify": "^3.4.0",
9292 "evalify": "^1.0.1",
9393 "feathers": "^1.2.0",
94+ "feathers-hooks": "^0.5.1",
95+ "feathers-rest": "^1.0.0",
96+ "feathers-tcomb": "^1.0.0",
9497 "history": "^1.13.1",
9598 "lnfs-cli": "^1.0.1",
9699 "npm-run-all": "^1.3.2",
97100 "pinkie-promise": "^2.0.0",
@@ -105,7 +108,8 @@
105108 "redux-simple-router": "0.0.10",
106109 "redux-thunk": "^1.0.0",
107110 "send-data": "^8.0.0",
108111 "simple-rc": "^1.0.0",
112+ "tcomb": "^2.5.2",
109113 "uglifyify": "^3.0.1"
110114 }
111115 }

Built with git-ssb-web