Skip to content

Commit

Permalink
Merge pull request #8 from smartive/develop
Browse files Browse the repository at this point in the history
release 2017-07-27
  • Loading branch information
buehler authored Jul 27, 2017
2 parents a43f62d + a746a7a commit 555d3f8
Show file tree
Hide file tree
Showing 20 changed files with 318 additions and 192 deletions.
15 changes: 11 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
node_modules

# Logs
logs
*.log
npm-debug.log*

# Dependency directory
node_modules

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# Typescript stuff
typings
build
docs
coverage

package-lock.json
34 changes: 9 additions & 25 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
build
typings

# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Dependency directory
node_modules

Expand All @@ -26,20 +12,18 @@ node_modules
# Optional REPL history
.node_repl_history


# Typescript stuff
typings
build
docs
coverage
build/
coverage/
config/
tsconfig.json
tslint.json

# Files
# Typescript files (but not the definitions)
*.ts
!*.d.ts
*.js.map
*.spec.js
*.spec.ts
*.spec.d.ts
*.spec.js.map

.travis.yml
# Testfiles
jest.json
test/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
36 changes: 20 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
language: node_js

cache:
directories:
- node_modules

notifications:
email: false

node_js:
- '6'
- '5'
- '4.2'
- '8'
- '6'

script: npm run citest
after_script: npm install coveralls@^2.11.9 && cat ./coverage/lcov.info | coveralls
before_script:
- npm prune

before_deploy:
- npm run bootstrap
- tsc --outDir .
after_success:
- npm install coveralls@^2.11.9 && cat ./coverage/lcov.info | coveralls
- npm i
- npm run build
- npm run semantic-release

deploy:
provider: npm
email: [email protected]
api_key:
secure: NoAP3zXpaw7efTltwCT5v//pWSTsCk1pvMVR02gFimdOI4kc9yr45GUAemmMBKDMPyxqwS2rJHl1A6Wps+P6gz2oMAFyioiK5TZI0qQNTVu9ggD7d1hlCr5Is1WZckblU863YckES6u+HoO0eXFC3iGZnh+1BldbTPR1PA9LWFJPGsZzJsDQRpxOWY6TLKRPlE53QmdclcIc//o4vVCldrCAdKojGlOVKhc03IaWt4i+onCszP81rUYkTTPdE2ODwQZrlbn1D01ojPu8UvPM4REKB90P+C9J/9PL1LR95UjHNPr2+nsa5dmbI2IQhAEudvAKOyBJV27DfZ2AcNNQyXc1e3OnH7zhP3Y19rceTzk0DOXnXKrQbzZEZ9ICnPfxv5PaQ+vOFJB4XkyrrF7LBWqNMRiYywt+vCBRelU7RUepXtO5wcj4TJmXUyB2fESL4W90HtPh1AZNvRPL2dH2DZF3tE2XSnG0MSHbwcrO+9ZUFZ2xBxCNM4WW5VCzH5H9z+ieLYqQmDwjBCgQp52Nw5UnJSmHk72Tlbbzphg4e7e40xH00AIVfLQiBHzEMOyRfZbtvS7cI/1SSMpP/sU+9rFUl5GiavupPVbFnzDUNBltXOk6HSaFtlarafO2llUcAGgxRithYLpjGbD1/4ZU+5NyOR4AFBejj0oq1cDAn7Y=
on:
tags: true
repo: smartive/proc-that-elastic-loader
branches:
except:
- /^v\d+\.\d+\.\d+$/
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- Update node to v6/v8 and upgrade modules


## [v0.4.0]
Expand Down
29 changes: 29 additions & 0 deletions config/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"removeComments": false,
"outDir": "../build",
"rootDir": "../src",
"declaration": true,
"sourceMap": false,
"importHelpers": true,
"strictNullChecks": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"lib": [
"es2015",
"dom"
]
},
"include": [
"../src/**/*"
],
"exclude": [
"../node_modules",
"../build"
]
}
6 changes: 6 additions & 0 deletions config/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "../"
}
}
1 change: 0 additions & 1 deletion index.ts

This file was deleted.

19 changes: 19 additions & 0 deletions jest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"collectCoverage": true,
"mapCoverage": true,
"transform": {
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testMatch": [
"**/test/**/*.spec.ts"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
]
}
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "proc-that-elastic-loader",
"version": "0.4.0",
"version": "0.0.0-development",
"description": "Loader for proc-that. Loads processed items into an elasticsearch index.",
"main": "index.js",
"scripts": {
"clean": "rimraf build",
"bootstrap": "npm install && typings install",
"pretest": "npm run bootstrap && npm run clean && tsc",
"test": "mocha --ui bdd --recursive ./build",
"precitest": "npm run bootstrap && npm run clean && tsc",
"citest": "istanbul cover -x \"**/*.spec.*\" _mocha --report lcovonly -- --ui bdd --recursive ./build",
"develop": "npm run clean && tsc -w --sourceMap --pretty"
"clean": "del-cli ./build ./coverage",
"build": "npm run clean && tsc -p ./config/tsconfig.build.json",
"develop": "npm run clean && tsc -p .",
"lint": "tslint -c ./tslint.json -p ./config/tsconfig.build.json",
"test": "npm run lint && npm run clean && jest -c ./jest.json",
"test:watch": "npm run clean && jest -c ./jest.json --watch",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"keywords": [
"etl",
Expand All @@ -21,31 +21,31 @@
"elasticsearch"
],
"engines": {
"node": ">=4.2"
"node": ">=6"
},
"repository": {
"type": "git",
"url": "git@github.com:smartive/proc-that-elastic-loader.git"
"url": "https://github.com/smartive/proc-that-elastic-loader.git"
},
"bugs": "https://github.com/smartive/proc-that-elastic-loader/issues",
"author": "Christoph Bühler <[email protected]>",
"license": "MIT",
"devDependencies": {
"chai": "^3.5.0",
"chai-as-promised": "^5.3.0",
"del-cli": "^0.2.0",
"istanbul": "^0.4.4",
"mocha": "^2.5.3",
"mocha-lcov-reporter": "^1.2.0",
"rimraf": "^2.5.3",
"sinon": "^1.17.4",
"sinon-chai": "^2.8.0",
"typescript": "^1.8.10",
"typings": "^1.3.1"
"@types/jest": "^20.0.5",
"del-cli": "^1.1.0",
"jest": "^20.0.4",
"ts-jest": "^20.0.7",
"tslint": "^5.5.0",
"tslint-config-airbnb": "^5.2.1",
"tsutils": "^2.8.0",
"typescript": "^2.4.2",
"semantic-release": "^6.3.6"
},
"dependencies": {
"elasticsearch": "^11.0.1",
"elasticsearch": "^13.2.0",
"proc-that": "^0.4.0",
"rxjs": "^5.0.0-beta.10"
"@types/node": "^8.0.17",
"rxjs": "^5.4.2",
"tslib": "^1.7.1"
}
}
41 changes: 24 additions & 17 deletions ElasticLoader.ts → src/ElasticLoader.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import {Loader} from 'proc-that';
import {Observable} from 'rxjs';
import {Buffer} from './helpers/Buffer';
import { Loader } from 'proc-that';
import { Observable } from 'rxjs';

let elasticsearch = require('elasticsearch');
import { Buffer } from './helpers/Buffer';

const elasticsearch = require('elasticsearch');

class NoIdProvidedError extends Error {
constructor(private object:any) {
constructor(public object: any) {
super('No id provided by object');
}
}

export class ElasticLoader implements Loader {
private esClient:any;
private buffer:Buffer<any> = new Buffer();

constructor(config:any, private index:string, private type:string, private predicate:(obj:any) => boolean = o => true, private idSelector:(obj:any) => any = o => o.id) {
let esConfig = JSON.parse(JSON.stringify(config));
private esClient: any;
private buffer: Buffer<any> = new Buffer();

constructor(
config: any,
private index: string,
private type: string,
private predicate: (obj: any) => boolean = () => true,
private idSelector: (obj: any) => any = o => o.id,
) {
const esConfig = JSON.parse(JSON.stringify(config));
if (!esConfig.requestTimeout) {
// set requestTimeout to 5min.
// reason: when you shoot many index requests to the esClient, elasticsearch buffers your requests.
Expand All @@ -28,28 +35,28 @@ export class ElasticLoader implements Loader {
}
}

write(object: any): Observable<any> {
public write(object: any): Observable<any> {
if (!this.predicate(object)) {
return Observable.empty();
}

let id = this.idSelector(object);
const id = this.idSelector(object);

if (id === null || id === undefined) {
return Observable.throw(new NoIdProvidedError(object));
}

let promise = this.buffer
const promise = this.buffer
.read()
.then(obj => this.esClient.index({
.then(() => this.esClient.index({
id,
index: this.index,
type: this.type,
id: id,
body: object
body: object,
}));

this.buffer.write(object);

return Observable.fromPromise(promise);
}
}
}
14 changes: 7 additions & 7 deletions helpers/Buffer.ts → src/helpers/Buffer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {EventEmitter} from 'events';
import { EventEmitter } from 'events';

export class BufferSealedError extends Error {
constructor() {
Expand Down Expand Up @@ -43,9 +43,9 @@ export class Buffer<T> extends EventEmitter {
}
}

public read(): Promise<T> {
public read(): Promise<T | undefined> {
if (!this.isEmpty) {
let content = this.content.shift();
const content = this.content.shift();
this.emit('release', content);

if (this.isEmpty) {
Expand All @@ -56,12 +56,12 @@ export class Buffer<T> extends EventEmitter {
return Promise.resolve(content);
}

return new Promise(resolve => {
return new Promise((resolve) => {
this.once('write', () => resolve(this.read()));
});
}

public write(object: T): Promise<T> | Promise<void> {
public write(object: T): Promise<T | undefined> {
if (this.sealed) {
return Promise.reject(new BufferSealedError());
}
Expand All @@ -72,8 +72,8 @@ export class Buffer<T> extends EventEmitter {
return Promise.resolve(object);
}

return new Promise(resolve => {
return new Promise((resolve) => {
this.once('release', () => resolve(this.write(object)));
});
}
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ElasticLoader';
Loading

0 comments on commit 555d3f8

Please sign in to comment.