Skip to content

Commit

Permalink
Merge pull request #2 from fabrix-app/v1.1
Browse files Browse the repository at this point in the history
[fix] normalize prefix to standard
  • Loading branch information
scott-wyatt authored Jul 24, 2018
2 parents 0084835 + f6d4512 commit d028e66
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
12 changes: 12 additions & 0 deletions lib/routes.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
export const Routes = {
'/{model}': {
config: {
prefix: 'tapestries.prefix'
},
'POST': 'TapestryController.create'
},
'/{model}/{id?}': {
config: {
prefix: 'tapestries.prefix'
},
'GET': 'TapestryController.find',
'PUT': 'TapestryController.update',
'PATCH': 'TapestryController.update',
'DELETE': 'TapestryController.destroy'
},
'/{parentModel}/{parentId}/{childAttribute}': {
config: {
prefix: 'tapestries.prefix'
},
'POST': 'TapestryController.createAssociation'
},
'/{parentModel}/{parentId}/{childAttribute}/{childId?}': {
config: {
prefix: 'tapestries.prefix'
},
'GET': 'TapestryController.findAssociation',
'PUT': 'TapestryController.updateAssociation',
'DELETE': 'TapestryController.destroyAssociation'
Expand Down
32 changes: 16 additions & 16 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ export const Utils = {
return [...configIgnore, ...defaultIgnore]
},

/**
* Get either the configured spool-tapestries prefix, or use the one set by spool-router if any.
*/
getPrefix(app: FabrixApp) {
let prefix = app.config.get('tapestries.prefix')
if (!prefix) {
prefix = app.config.get('router.prefix') || ''
}
return prefix.toString()
},
// /**
// * Get either the configured spool-tapestries prefix, or use the one set by spool-router if any.
// */
// getPrefix(app: FabrixApp) {
// let prefix = app.config.get('tapestries.prefix')
// if (!prefix) {
// prefix = app.config.get('router.prefix') || ''
// }
// return prefix.toString()
// },
/**
* Compile controller handlers into route objects
*/
Expand All @@ -49,12 +49,12 @@ export const Utils = {
Utils.getControllerIgnore(app)
)

const prefix = Utils.getPrefix(app)
// const prefix = Utils.getPrefix(app)
const routes = {}
Object.keys(controllers).forEach((controllerName: string) => {
controllers[controllerName].methods.forEach(handlerName => {
const route = {}
const path = Utils.getHandlerPath(app, prefix, controllers[controllerName].id, handlerName)
const path = Utils.getHandlerPath(app, controllers[controllerName].id, handlerName)

Utils.getControllerMethods(app).forEach(method => {
route[method] = Utils.getControllerHandler(controllerName, handlerName)
Expand All @@ -71,7 +71,7 @@ export const Utils = {
*/
getModelTapestries (app: FabrixApp): {[key: string]: any} {
const actionsConfig = app.config.get('tapestries.models.actions') || {}
const prefix = Utils.getPrefix(app)
// const prefix = Utils.getPrefix(app)
const routes = {}
Object.keys(Routes).forEach(path => {
Object.keys(Routes[path]).map(m => {
Expand All @@ -81,7 +81,7 @@ export const Utils = {
}
}
})
routes[`${prefix}${path}`] = Routes[path]
routes[`${path}`] = Routes[path]
})
return routes
},
Expand All @@ -103,7 +103,7 @@ export const Utils = {
/**
* Join a list as a path
*/
getHandlerPath (app: FabrixApp, prefix: string, controllerId: string, handlerName: string): string {
return join('/', prefix, controllerId, handlerName)
getHandlerPath (app: FabrixApp, controllerId: string, handlerName: string): string {
return join('/', controllerId, handlerName)
}
}
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fabrix/spool-tapestries",
"version": "1.1.2",
"version": "1.1.3",
"description": "Spool - Tapestries, Easy RESTful Services",
"scripts": {
"build": "tsc -p ./lib/tsconfig.release.json",
Expand Down Expand Up @@ -49,8 +49,8 @@
"lodash": "^4.17.10"
},
"devDependencies": {
"@fabrix/fabrix": "^1.1.1",
"@fabrix/spool-router": "^1.1.2",
"@fabrix/fabrix": "^1.1.2",
"@fabrix/spool-router": "^1.1.3",
"@fabrix/lint": "^1.0.0-alpha.3",
"@types/lodash": "^4.14.109",
"@types/node": "~10.3.4",
Expand All @@ -64,8 +64,8 @@
"typescript": "~2.8.1"
},
"peerDependencies": {
"@fabrix/fabrix": "^1.1.1",
"@fabrix/spool-router": "^1.1.2"
"@fabrix/fabrix": "^1.1.2",
"@fabrix/spool-router": "^1.1.3"
},
"license": "MIT",
"bugs": {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ describe('lib.Util', () => {
describe('#getHandlerPath', () => {
it('should return correct url path for controller handler', () => {
assert.equal(
lib.Utils.getHandlerPath(global.app, '/prefix', 'test', 'test'),
'/prefix/test/test'
lib.Utils.getHandlerPath(global.app, '/prefix', 'test'),
'/prefix/test'
)
})
})
Expand All @@ -21,7 +21,7 @@ describe('lib.Util', () => {
const tapestries = lib.Utils.getControllerTapestries(global.app)
assert.equal(Object.keys(tapestries).length, 1)
// assert(_.find(tapestries, {handler: 'TestController.testHandler'}))
assert(tapestries[global.app.config.get('tapestries.prefix') + '/test/testHandler'])
assert(tapestries['/test/testHandler'])
})

it('should return an empty array if controller tapestry routes are disabled', () => {
Expand Down

0 comments on commit d028e66

Please sign in to comment.