Compare commits
	
		
			6 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 5f0273a973 | ||
|  | 3317e0a8f2 | ||
|  | 61fbf434af | ||
|  | f71e06362b | ||
|  | a5e6b2dd46 | ||
|  | e7bc048a46 | 
							
								
								
									
										13
									
								
								.babelrc
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								.babelrc
									
									
									
									
									
								
							| @@ -1,3 +1,14 @@ | ||||
| { | ||||
|   "stage": 1 | ||||
|   "presets": [ | ||||
|     "stage-1" | ||||
|   ], | ||||
|   "plugins": [ | ||||
|     "transform-object-rest-spread", | ||||
|     "transform-class-properties", | ||||
|     "add-module-exports", | ||||
|     "closure-elimination", | ||||
|     "transform-decorators-legacy", | ||||
|     "transform-es2015-modules-commonjs" | ||||
|   ], | ||||
|   "sourceMaps": true | ||||
| } | ||||
|   | ||||
							
								
								
									
										24
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								package.json
									
									
									
									
									
								
							| @@ -1,19 +1,21 @@ | ||||
| { | ||||
|   "name": "hapi-sequelize-crud", | ||||
|   "version": "2.1.0", | ||||
|   "name": "@getable/hapi-sequelize-crud", | ||||
|   "version": "2.2.0", | ||||
|   "description": "Hapi plugin that automatically generates RESTful API for CRUD", | ||||
|   "main": "build/index.js", | ||||
|   "config": { | ||||
|     "ghooks": { | ||||
|       "pre-commit": "npm run lint && grunt" | ||||
|       "pre-commit": "npm run lint && npm run build" | ||||
|     } | ||||
|   }, | ||||
|   "scripts": { | ||||
|     "lint": "eslint src test", | ||||
|     "test": "echo \"Error: no test specified\" && exit 1" | ||||
|     "test": "echo \"Error: no test specified\" && exit 1", | ||||
|     "build": "scripty", | ||||
|     "watch": "scripty" | ||||
|   }, | ||||
|   "repository": { | ||||
|     "git": "https://github.com/mdibaiee/hapi-sequelize-crud" | ||||
|     "git": "https://github.com/Getable/hapi-sequelize-crud" | ||||
|   }, | ||||
|   "files": [ | ||||
|     "build" | ||||
| @@ -21,14 +23,16 @@ | ||||
|   "author": "Mahdi Dibaiee <mdibaiee@aol.com> (http://dibaiee.ir/)", | ||||
|   "license": "MIT", | ||||
|   "devDependencies": { | ||||
|     "babel": "5.8.3", | ||||
|     "babel-cli": "^6.10.1", | ||||
|     "babel-plugin-add-module-exports": "^0.2.1", | ||||
|     "babel-plugin-closure-elimination": "^1.0.6", | ||||
|     "babel-plugin-transform-decorators-legacy": "^1.3.4", | ||||
|     "babel-plugin-transform-es2015-modules-commonjs": "^6.10.3", | ||||
|     "babel-preset-stage-1": "^6.5.0", | ||||
|     "eslint": "2.10.2", | ||||
|     "eslint-config-pichak": "1.0.1", | ||||
|     "ghooks": "1.0.3", | ||||
|     "grunt": "0.4.5", | ||||
|     "grunt-babel": "5.0.3", | ||||
|     "grunt-contrib-clean": "0.7.0", | ||||
|     "grunt-contrib-watch": "0.6.1" | ||||
|     "scripty": "^1.6.0" | ||||
|   }, | ||||
|   "dependencies": { | ||||
|     "babel": "5.8.3", | ||||
|   | ||||
							
								
								
									
										15
									
								
								scripts/build.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										15
									
								
								scripts/build.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| #!/bin/bash | ||||
| # strict mode http://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||||
| set -euo pipefail | ||||
| IFS=$'\n\t' | ||||
|  | ||||
|  | ||||
| source "scripts/env.sh" | ||||
|  | ||||
| babel="./node_modules/.bin/babel" | ||||
|  | ||||
| build () { | ||||
|   $babel "$SRC_DIR" --out-dir "$OUT_DIR" $@ | ||||
| } | ||||
|  | ||||
| build $@ | ||||
							
								
								
									
										7
									
								
								scripts/env.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								scripts/env.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| #!/bin/bash | ||||
| # strict mode http://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||||
| set -euo pipefail | ||||
| IFS=$'\n\t' | ||||
|  | ||||
| export SRC_DIR="./src" | ||||
| export OUT_DIR="./build" | ||||
							
								
								
									
										6
									
								
								scripts/watch.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								scripts/watch.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| #!/bin/bash | ||||
| # strict mode http://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||||
| set -euo pipefail | ||||
| IFS=$'\n\t' | ||||
|  | ||||
| ./scripts/build.sh --watch | ||||
| @@ -31,6 +31,8 @@ export const list = (server, model) => { | ||||
|       const include = parseInclude(request); | ||||
|       const where = parseWhere(request); | ||||
|  | ||||
|       if (include instanceof Error) return void reply(include); | ||||
|  | ||||
|       const list = await model.findAll({ | ||||
|         where, include, | ||||
|       }); | ||||
|   | ||||
							
								
								
									
										20
									
								
								src/utils.js
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/utils.js
									
									
									
									
									
								
							| @@ -1,18 +1,30 @@ | ||||
| import { omit } from 'lodash'; | ||||
| import { omit, identity } from 'lodash'; | ||||
|  | ||||
| export const parseInclude = request => { | ||||
|   const include = Array.isArray(request.query.include) ? request.query.include | ||||
|                                                        : [request.query.include]; | ||||
|  | ||||
|   const noGetDb = typeof request.getDb !== 'function'; | ||||
|   const noRequestModels = request.models; | ||||
|  | ||||
|   if (noGetDb && noRequestModels) { | ||||
|     return new Error('`request.getDb` or `request.models` are not defined. Be sure to load hapi-sequelize before hapi-sequelize-crud.'); | ||||
|   } | ||||
|  | ||||
|   const {models} = !noGetDb | ||||
|     ? request.getDb() | ||||
|     : request | ||||
|     ; | ||||
|  | ||||
|   return include.map(a => { | ||||
|     if (typeof a === 'string') return request.models[a]; | ||||
|     if (typeof a === 'string') return models[a]; | ||||
|  | ||||
|     if (a && typeof a.model === 'string' && a.model.length) { | ||||
|       a.model = request.models[a.model]; | ||||
|       a.model = models[a.model]; | ||||
|     } | ||||
|  | ||||
|     return a; | ||||
|   }).filter(a => a); | ||||
|   }).filter(identity); | ||||
| }; | ||||
|  | ||||
| export const parseWhere = request => { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user