-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21df85a
commit 49aa8d7
Showing
9 changed files
with
2,176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,4 @@ typings/ | |
|
||
# next.js build output | ||
.next | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
language: node_js | ||
|
||
services: | ||
- docker | ||
|
||
before_install: | ||
- docker pull amazon/dynamodb-local | ||
|
||
node_js: | ||
- stable | ||
|
||
install: | ||
- npm install | ||
|
||
script: | ||
- npm test | ||
|
||
# Send coverage data to Coveralls | ||
after_script: "cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,55 @@ | ||
# entity-service | ||
[![Build Status](https://travis-ci.org/jtviegas/entity-service.svg?branch=master)](https://travis-ci.org/jtviegas/entity-service) | ||
[![Coverage Status](https://coveralls.io/repos/github/jtviegas/entity-service/badge.svg?branch=master)](https://coveralls.io/github/jtviegas/entity-service?branch=master) | ||
|
||
entity-service | ||
========= | ||
|
||
a generic crud service for entities | ||
|
||
![overview][overview] | ||
|
||
|
||
## Installation | ||
|
||
`npm install @jtviegas/entity-service` | ||
|
||
## Usage | ||
|
||
### required environment variables | ||
|
||
- region - aws region ( not mandatory, default: eu-west-1 ) | ||
- AWS_ACCESS_KEY_ID ( mandatory ) | ||
- AWS_SECRET_ACCESS_KEY ( mandatory ) | ||
- DYNDBSTORE_TEST_ENDPOINT ( not mandatory, for testing purposes ) | ||
|
||
### code snippet example | ||
|
||
let service = require('@jtviegas/entity-service'); | ||
let event = { | ||
httpMethod: 'GET' | ||
, pathParameters: { | ||
entity: ENTITY | ||
, app: APP | ||
, env: ENV | ||
} | ||
}; | ||
service.handler(event, context, (e,d)=>{ | ||
if(e) | ||
done(e); | ||
else { | ||
let r=JSON.parse(d.body); | ||
expect(r.length).to.equal(TEST_ITERATIONS); | ||
done(null); | ||
} | ||
}); | ||
|
||
|
||
## Tests | ||
|
||
`npm test` | ||
|
||
## Contributing | ||
|
||
just help yourself and submit a pull request | ||
|
||
[overview]: assets/overview.png "overview" |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const winston = require('winston'); | ||
const ServerError = require('@jtviegas/jscommons').ServerError; | ||
const commons = require('@jtviegas/jscommons').commons; | ||
const store = require('@jtviegas/entity-store'); | ||
const logger = winston.createLogger(commons.getDefaultWinstonConfig()); | ||
|
||
const entityService = { | ||
|
||
handler : (event, context, callback) => { | ||
logger.info("[entityService|handler|in] <= %o", event); | ||
|
||
const done = (err, res) => callback( null, { | ||
statusCode: err ? err.status : 200, | ||
body: err ? err.message : JSON.stringify(res), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Access-Control-Allow-Origin': '*' | ||
}, | ||
}); | ||
|
||
try{ | ||
if( event.httpMethod !== 'GET' ) | ||
throw new ServerError(`Unsupported method "${event.httpMethod}"`, 400); | ||
else { | ||
if( event.pathParameters && event.pathParameters.app && event.pathParameters.entity && event.pathParameters.env ) { | ||
let app = event.pathParameters.app; | ||
let entity = event.pathParameters.entity; | ||
let env = event.pathParameters.env; | ||
|
||
if( event.pathParameters.id ) | ||
store.entityRetrieval(app, env, entity, parseInt(event.pathParameters.id), done); | ||
else | ||
store.entitiesRetrieval(app, env, entity, done); | ||
} | ||
else | ||
throw new ServerError("Unsupported path", 404); | ||
} | ||
} | ||
catch(e){ | ||
logger.error("[entityService|handler] %o", e); | ||
done(e); | ||
} | ||
logger.info("[entityService|handler|out]"); | ||
} | ||
|
||
} | ||
|
||
module.exports = entityService; | ||
|
||
|
||
|
Oops, something went wrong.