Skip to content

Commit

Permalink
Merge pull request #103 from unarxiv/discovery
Browse files Browse the repository at this point in the history
open-source typescript based discovery service
  • Loading branch information
Xiaozhe Yao authored Nov 5, 2018
2 parents da702b5 + 04aed0b commit 153f765
Show file tree
Hide file tree
Showing 16 changed files with 3,910 additions and 0 deletions.
2 changes: 2 additions & 0 deletions discovery/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
1 change: 1 addition & 0 deletions discovery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# README
3,758 changes: 3,758 additions & 0 deletions discovery/package-lock.json

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions discovery/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "cvtron-discovery-node",
"version": "1.0.0",
"description": "The CVTron Discovery Service in Node",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build-server": "tslint --project . && tsc",
"watch-server": "nodemon --watch 'src/**/*' -e ts,tsx --exec 'ts-node' ./src/server.ts"
},
"author": "",
"license": "ISC",
"dependencies": {
"@aws/dynamodb-data-mapper": "^0.7.3",
"@aws/dynamodb-data-mapper-annotations": "^0.7.3",
"@koa/cors": "^2.2.2",
"@types/koa": "^2.0.46",
"@types/koa-bodyparser": "^5.0.1",
"@types/koa-helmet": "^3.1.2",
"@types/koa-router": "^7.0.32",
"@types/koa__cors": "^2.2.3",
"aws-sdk": "^2.348.0",
"koa": "^2.6.1",
"koa-bodyparser": "^4.2.1",
"koa-helmet": "^4.0.0",
"koa-router": "^7.4.0"
},
"devDependencies": {
"@types/node": "^10.12.2",
"nodemon": "^1.18.5",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"typescript": "^3.1.6"
}
}
Empty file.
1 change: 1 addition & 0 deletions discovery/src/controller/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as system } from './system';
Empty file.
8 changes: 8 additions & 0 deletions discovery/src/controller/system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BaseContext } from 'koa';

export default class SystemController {
public static async getSystemStatus(ctx: BaseContext) {
ctx.status = 200;
ctx.body = 'ok';
}
}
Empty file.
3 changes: 3 additions & 0 deletions discovery/src/dynamo/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
* Following will be object manipulations
*/
11 changes: 11 additions & 0 deletions discovery/src/dynamo/dynamo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

/**
* Following is the definition for mapper
*/

import { DataMapper } from '@aws/dynamodb-data-mapper';
import DynamoDB = require('aws-sdk/clients/dynamodb');

const mapper = new DataMapper({
client: new DynamoDB({region: 'us-east-1'})
})
24 changes: 24 additions & 0 deletions discovery/src/dynamo/model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
attribute,
hashKey,
rangeKey,
table,
} from '@aws/dynamodb-data-mapper-annotations';

/**
* Following will be object definitions
*/
@table('cvpm-package')
class Package {
@hashKey()
id: string;

@rangeKey({defaultProvider: () => new Date()})
createdAt: Date;

@attribute()
isSymbol: boolean;

@attribute()
linkedTo: string;
}
9 changes: 9 additions & 0 deletions discovery/src/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Router from 'koa-router';

import controller = require('./controller');

const router = new Router();

router.get('/system/status', controller.system.getSystemStatus);

export { router };
16 changes: 16 additions & 0 deletions discovery/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as cors from '@koa/cors';
import * as Koa from 'koa';
import * as bodyParser from 'koa-bodyparser';
import * as helmet from 'koa-helmet';

import { router } from './routes';

const app = new Koa();

app.use(cors());
app.use(helmet());
app.use(bodyParser());
app.use(router.routes()).use(router.allowedMethods());

app.listen(3000);
console.log('Server is Running on 3000');
13 changes: 13 additions & 0 deletions discovery/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"noImplicitAny": true,
"outDir": "./dist",
"sourceMap": true,
"experimentalDecorators": true
},
"include": [
"./src/**/*"
]
}
29 changes: 29 additions & 0 deletions discovery/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {
"quotemark": [
true,
"single"
],
"no-console": [
false
],
"one-line": [
true,
"check-open-brace",
"check-whitespace"
],
"object-literal-sort-keys": [
false
],
"no-string-literal": false,
"triple-equals": [
false
]
},
"rulesDirectory": []
}

0 comments on commit 153f765

Please sign in to comment.