-
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.
BREAKING CHANGE: - Removed support for rxjs v5, minimum version is rxjs v7 - Removed support for Node.js v6, minimum version is v16 - Removed support for proc-that v1, minimum version is v2 - Removed support for old elasticsearch version, minimum version is v7.x
- Loading branch information
Showing
18 changed files
with
425 additions
and
433 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
{ | ||
"extends": ["@smartive/eslint-config"] | ||
} |
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,23 @@ | ||
name: Release npm package | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@main | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18.x' | ||
- run: npm install | ||
- run: npm run build | ||
- name: semantic release | ||
uses: cycjimmy/semantic-release-action@v3 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
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,23 @@ | ||
name: Unit Tests | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: [master, develop] | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [16.x, 18.x] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Run Tests | ||
run: | | ||
npm install | ||
npm test |
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ node_modules | |
.node_repl_history | ||
|
||
# Typescript stuff | ||
build | ||
dist | ||
coverage | ||
|
||
package-lock.json |
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 @@ | ||
dist |
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 @@ | ||
"@smartive/prettier-config" |
This file was deleted.
Oops, something went wrong.
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
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,6 +1,3 @@ | ||
{ | ||
"extends": "./tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "../" | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -2,16 +2,20 @@ | |
"name": "proc-that-elastic-loader", | ||
"version": "0.0.0-development", | ||
"description": "Loader for proc-that. Loads processed items into an elasticsearch index.", | ||
"main": "index.js", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.js", | ||
"scripts": { | ||
"clean": "del-cli ./build ./coverage", | ||
"clean": "del-cli ./dist ./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", | ||
"lint": "npm run lint:ts && npm run prettier", | ||
"lint:fix": "npm run lint:ts:fix && npm run prettier:fix", | ||
"lint:ts": "eslint --max-warnings=-1", | ||
"lint:ts:fix": "eslint --max-warnings=-1 --fix", | ||
"prettier": "prettier --config .prettierrc.json --list-different \"./**/*.{ts,tsx}\"", | ||
"prettier:fix": "prettier --config .prettierrc.json --list-different \"./**/*.{ts,tsx}\" --write", | ||
"test": "npm run lint && npm run clean && jest -c ./jest.json", | ||
"test:watch": "npm run clean && jest -c ./jest.json --watch", | ||
"typedoc": "del-cli ./docs && typedoc --ignoreCompilerErrors --out ./docs --mode file --tsconfig ./config/tsconfig.build.json ./src/", | ||
"semantic-release": "semantic-release" | ||
"test:watch": "npm run clean && jest -c ./jest.json --watch" | ||
}, | ||
"keywords": [ | ||
"etl", | ||
|
@@ -22,7 +26,7 @@ | |
"elasticsearch" | ||
], | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=16" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -32,22 +36,23 @@ | |
"author": "Christoph Bühler <[email protected]>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@smartive/tslint-config": "^2.0.0", | ||
"@types/jest": "^22.0.1", | ||
"del-cli": "^1.1.0", | ||
"jest": "^22.1.1", | ||
"semantic-release": "^12.2.2", | ||
"ts-jest": "^22.0.1", | ||
"tslint": "^5.9.1", | ||
"tsutils": "^2.18.0", | ||
"typedoc": "^0.9.0", | ||
"typescript": "^2.6.2" | ||
"@smartive/eslint-config": "^3.1.1", | ||
"@smartive/prettier-config": "^3.0.0", | ||
"@types/jest": "^29.2.4", | ||
"del-cli": "^5.0.0", | ||
"jest": "^29.3.1", | ||
"semantic-release": "^19.0.5", | ||
"ts-jest": "^29.0.3", | ||
"tslint": "^5.20.1", | ||
"tsutils": "^3.21.0", | ||
"typedoc": "^0.23.23", | ||
"typescript": "^4.9.4" | ||
}, | ||
"dependencies": { | ||
"elasticsearch": "^14.0.0", | ||
"proc-that": "^1.0.2", | ||
"@types/node": "^9.3.0", | ||
"rxjs": "^5.5.6", | ||
"tslib": "^1.8.1" | ||
"@elastic/elasticsearch": "^8.5.0", | ||
"@types/node": "^18.11.17", | ||
"proc-that": "^2.0.0", | ||
"rxjs": "^7.8.0", | ||
"tslib": "^2.4.1" | ||
} | ||
} |
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,62 +1,57 @@ | ||
import { Client, ClientOptions } from '@elastic/elasticsearch'; | ||
import { Loader } from 'proc-that'; | ||
import { Observable } from 'rxjs'; | ||
|
||
import { EMPTY, from, Observable, throwError } from 'rxjs'; | ||
import { Buffer } from './helpers/Buffer'; | ||
|
||
const elasticsearch = require('elasticsearch'); | ||
|
||
class NoIdProvidedError extends Error { | ||
constructor(public object: any) { | ||
super('No id provided by object'); | ||
} | ||
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 = () => 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. | ||
// after the default timeout of 30s is exceeded, you receive a TimeoutError and the whole index process fails. | ||
esConfig.requestTimeout = 1000 * 60 * 5; | ||
} | ||
this.esClient = new elasticsearch.Client(esConfig); | ||
if (esConfig.maxSockets) { | ||
this.buffer = new Buffer(esConfig.maxSockets); | ||
} | ||
private esClient: Client; | ||
private buffer: Buffer<any>; | ||
|
||
constructor( | ||
esConfig: ClientOptions, | ||
private index: string, | ||
private predicate: (obj: any) => boolean = () => true, | ||
private idSelector: (obj: any) => any = (o) => o.id, | ||
bufferSize = 10 | ||
) { | ||
if (!esConfig.requestTimeout) { | ||
// set requestTimeout to 5min. | ||
// reason: when you shoot many index requests to the esClient, elasticsearch buffers your requests. | ||
// after the default timeout of 30s is exceeded, you receive a TimeoutError and the whole index process fails. | ||
esConfig.requestTimeout = 1000 * 60 * 5; | ||
} | ||
|
||
public write(object: any): Observable<any> { | ||
if (!this.predicate(object)) { | ||
return Observable.empty(); | ||
} | ||
this.buffer = new Buffer(bufferSize); | ||
this.esClient = new Client(esConfig); | ||
} | ||
|
||
const id = this.idSelector(object); | ||
public write(object: any): Observable<any> { | ||
if (!this.predicate(object)) { | ||
return EMPTY; | ||
} | ||
|
||
if (id === null || id === undefined) { | ||
return Observable.throw(new NoIdProvidedError(object)); | ||
} | ||
const id = this.idSelector(object); | ||
|
||
const promise = this.buffer | ||
.read() | ||
.then(() => this.esClient.index({ | ||
id, | ||
index: this.index, | ||
type: this.type, | ||
body: object, | ||
})); | ||
if (id === null || id === undefined) { | ||
return throwError(() => new NoIdProvidedError(object)); | ||
} | ||
|
||
this.buffer.write(object); | ||
const promise = this.buffer.read().then(() => | ||
this.esClient.index({ | ||
id, | ||
index: this.index, | ||
body: object, | ||
}) | ||
); | ||
|
||
return Observable.fromPromise(promise); | ||
} | ||
this.buffer.write(object); | ||
|
||
return from(promise); | ||
} | ||
} |
Oops, something went wrong.