Skip to content
This repository was archived by the owner on Nov 23, 2021. It is now read-only.

Commit 679e113

Browse files
author
Alfonso Garcia
committed
First commit
0 parents  commit 679e113

File tree

9 files changed

+418
-0
lines changed

9 files changed

+418
-0
lines changed

.gitignore

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
# Created by https://www.gitignore.io/api/node
3+
4+
### Node ###
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
10+
# Runtime data
11+
pids
12+
*.pid
13+
*.seed
14+
*.pid.lock
15+
16+
# Directory for instrumented libs generated by jscoverage/JSCover
17+
lib-cov
18+
19+
# Coverage directory used by tools like istanbul
20+
coverage
21+
22+
# nyc test coverage
23+
.nyc_output
24+
25+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26+
.grunt
27+
28+
# node-waf configuration
29+
.lock-wscript
30+
31+
# Compiled binary addons (http://nodejs.org/api/addons.html)
32+
build/Release
33+
34+
# Dependency directories
35+
node_modules
36+
jspm_packages
37+
38+
# Optional npm cache directory
39+
.npm
40+
41+
# Optional eslint cache
42+
.eslintcache
43+
44+
# Optional REPL history
45+
.node_repl_history
46+
47+
# Output of 'npm pack'
48+
*.tgz
49+
50+
###################################
51+
52+
# Visual Studio 2015 cache/options directory
53+
54+
bower_components/
55+
node_modules/
56+
57+
58+
#Exclude tsc generated files
59+
out/
60+
61+
62+
# Elastic Beanstalk Files
63+
64+
.elasticbeanstalk/*
65+
66+
!.elasticbeanstalk/*.cfg.yml
67+
68+
!.elasticbeanstalk/*.global.yml
69+
70+
# Visual Studio Code Settings
71+
.vscode/

adapters/dynamo-adapter.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
let DynamoDB = require('aws-sdk/clients/dynamodb')
2+
3+
let docClient = new DynamoDB.DocumentClient({ endpoint: "http://localhost:8000/", region: "us-west-2" })
4+
5+
export function getItem (table_name: string, id: string) {
6+
7+
}
8+
9+
export function getItems (table_name: string, ids?: Array<Object>) {
10+
// IMPORTANT: scan operation is limited to 1MB of data
11+
let params = {
12+
TableName: table_name
13+
}
14+
/* try {
15+
let res = await docClient.scan(params).promise()
16+
return res.Items
17+
}
18+
catch(err) {
19+
return err
20+
}*/
21+
22+
/*.then((res: any) => {
23+
console.log('promise resolved')
24+
return Promise.resolve(res.Items)
25+
}, (err: Error) => {
26+
console.log('promise rejected')
27+
return Promise.reject(err)
28+
})*/
29+
30+
return docClient.scan(params).promise()
31+
.then((res: any) => {
32+
return res.Items
33+
}, (err: Error) => {
34+
return Promise.reject(err)
35+
})
36+
}
37+
38+
export function putItem (table_name: string, item: Object) {
39+
40+
}
41+
42+
export function putItems (table_name: string, items: Array<Object>) {
43+
44+
}
45+
46+
export function deleteItem (table_name: string, id: string) {
47+
48+
}
49+
50+
export function deleteItems (table_name: string, ids: Array<string>) {
51+
52+
}
53+

data-collector.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import * as _ from 'lodash'
2+
import {getItems} from './adapters/dynamo-adapter'
3+
4+
let promises = {}
5+
let error: string
6+
let solution: any
7+
8+
export default {
9+
// tables: {},
10+
table: function (name: string) {
11+
// console.log(this)
12+
/*try {
13+
this.tables.name = await getItems(name)
14+
} catch (err) {
15+
console.log(err)
16+
}*/
17+
18+
/* getItems(name)
19+
.then((res: Array<Object>) => {
20+
console.log(tables)
21+
tables[name] = res
22+
console.log(tables)
23+
}, (err: Error) => {
24+
console.log(err)
25+
})*/
26+
27+
// promises.push(getItems(name))
28+
29+
promises[name] = getItems(name)
30+
31+
console.log(promises)
32+
return this
33+
},
34+
join: function () {
35+
console.log('join the first 2 tables ' + promises)
36+
if(_.size(promises) < 2)
37+
error = 'Not enough tables'
38+
else {
39+
solution = Promise.all(_.values(promises))
40+
.then((res: Array<Object>) => {
41+
return (_.reduce(res, (result, value) => {
42+
if(_.size(result) < 2)
43+
result.push(value)
44+
return result
45+
}, []))
46+
}, (err: Error) => {
47+
return Promise.reject(err)
48+
})
49+
}
50+
return this
51+
},
52+
then: function (result, reject) {
53+
let promise: Promise<string | Array<Object>>
54+
if(error) {
55+
if(reject) {
56+
promise = reject(error)
57+
}
58+
else {
59+
promise = Promise.reject(error)
60+
}
61+
}
62+
else {
63+
if(result) {
64+
promise = solution
65+
.then((res: any) => {
66+
return result(res)
67+
})
68+
}
69+
else {
70+
promise = result
71+
}
72+
}
73+
error = undefined
74+
solution = undefined
75+
return promise
76+
}
77+
}

index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
import db from './data-collector'
3+
4+
db.table('Music')
5+
/*.then((res: any) => {
6+
return res.join()
7+
}, (err: Error) => {
8+
console.log(err)
9+
})
10+
.then((res: any) => {
11+
console.log
12+
}, (err: Error) => {
13+
console.log(err)
14+
})*/
15+
.table('Configurations')
16+
.join()
17+
.then((res: Array<Object>) => {
18+
console.log(res)
19+
}, (err: Error) => {
20+
console.log(err)
21+
})
22+
23+
24+

mocha.opts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--require ts-node/register
2+
--reporter dot
3+
--watch-extensions tsx,ts
4+
test/**/*.ts

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "data-collector",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"build": "tsc",
7+
"test": "mocha --opts mocha.opts",
8+
"test:auto": "mocha --opts mocha.opts --watch"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"devDependencies": {
13+
"@types/chai": "^3.4.35",
14+
"@types/lodash": "^4.14.53",
15+
"@types/mocha": "^2.2.39",
16+
"@types/node": "^7.0.5",
17+
"aws-sdk": "^2.12.0",
18+
"chai": "^3.5.0"
19+
},
20+
"dependencies": {
21+
"lodash": "^4.17.4"
22+
}
23+
}

test/main.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
import { expect } from 'chai'
3+
import db from '../data-collector'
4+
5+
describe('table', () => {
6+
it('Should return an array', () => {
7+
})
8+
})
9+

tsconfig.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "out",
4+
"target": "es6",
5+
"module": "commonjs",
6+
"noEmitOnError": true,
7+
"noImplicitAny": true,
8+
"strictNullChecks": true,
9+
"experimentalDecorators": true,
10+
"removeComments": true,
11+
"preserveConstEnums": true,
12+
"sourceMap": true,
13+
"typeRoots": [
14+
"node_modules/@types"
15+
]
16+
},
17+
"include": [
18+
"src/**/*",
19+
"test/**/*"
20+
],
21+
"exclude": [
22+
"out",
23+
"node_modules",
24+
"**/*.spec.ts"
25+
]
26+
}

0 commit comments

Comments
 (0)