Skip to content

Commit 9116eb8

Browse files
rob3000wtrocki
authored andcommitted
Fixed linting errors for spaces. Removed default export for actions to clean up imports
1 parent 976c884 commit 9116eb8

20 files changed

+651
-655
lines changed

.eslintrc.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ module.exports = {
44
"node": true,
55
"mocha": true
66
},
7-
"parser": '@typescript-eslint/parser',
7+
"parser": "@typescript-eslint/parser",
88
"plugins": [
9-
'@typescript-eslint',
9+
"@typescript-eslint",
1010
],
1111
"extends": [
12-
'eslint:recommended',
13-
'plugin:@typescript-eslint/recommended',
12+
"eslint:recommended",
13+
"plugin:@typescript-eslint/recommended",
1414
],
1515
"rules": {
1616
"indent": [
17-
"error",
18-
2
17+
2, 2, {
18+
"SwitchCase": 1
19+
}
1920
],
2021
"linebreak-style": [
2122
"error",
@@ -29,6 +30,7 @@ module.exports = {
2930
"error",
3031
"always"
3132
],
32-
"no-console": 0
33+
"no-console": 0,
34+
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"]
3335
}
3436
};

src/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"use strict";
22

3-
import KStream from "./lib/dsl/KStream"
4-
import KTable from "./lib/dsl/KTable"
5-
import KafkaFactory from "./lib/KafkaFactory"
6-
import KafkaStreams from "./lib/KafkaStreams"
7-
import KStorage from "./lib/KStorage.js"
8-
import KafkaClient from "./lib/client/KafkaClient"
3+
import KStream from "./lib/dsl/KStream";
4+
import KTable from "./lib/dsl/KTable";
5+
import KafkaFactory from "./lib/KafkaFactory";
6+
import KafkaStreams from "./lib/KafkaStreams";
7+
import KStorage from "./lib/KStorage.js";
8+
import KafkaClient from "./lib/client/KafkaClient";
99

1010
module.exports = {
1111
default: KafkaStreams,

src/lib/KStorage.ts

+84-84
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,94 @@
11
"use strict";
22

3-
import Promise from 'bluebird';
3+
import Promise from "bluebird";
44

55
class KStorage {
66
public options: any;
77
public state: any;
88

9-
/**
10-
* be aware that even though KStorage is built on Promises
11-
* its operations must always be ATOMIC (or ACID) because
12-
* the stream will access them parallel, therefore having
13-
* an async get + async set operation will always yield
14-
* in a large amount of missing get operations followed by
15-
* set operations
16-
*/
17-
constructor(options) {
18-
this.options = options;
19-
this.state = {};
20-
}
21-
22-
/* NOTE: there is no open() method, meaning the functions have to work lazily */
23-
24-
set(key, value) {
25-
this.state[key] = value;
26-
return Promise.resolve(value);
27-
}
28-
29-
setSmaller(key = "min", value) {
30-
31-
if (!this.state[key]) {
32-
this.state[key] = value;
33-
}
34-
35-
if (value < this.state[key]) {
36-
this.state[key] = value;
37-
}
38-
39-
return Promise.resolve(this.state[key]);
40-
}
41-
42-
setGreater(key = "max", value) {
43-
44-
if (!this.state[key]) {
45-
this.state[key] = value;
46-
}
47-
48-
if (value > this.state[key]) {
49-
this.state[key] = value;
50-
}
51-
52-
return Promise.resolve(this.state[key]);
53-
}
54-
55-
increment(key, by = 1) {
56-
if (!this.state[key]) {
57-
this.state[key] = by;
58-
} else {
59-
this.state[key] += by;
60-
}
61-
return Promise.resolve(this.state[key]);
62-
}
63-
64-
sum(key, value) {
65-
return this.increment(key, value);
66-
}
67-
68-
get(key) {
69-
return Promise.resolve(this.state[key]);
70-
}
71-
72-
getState() {
73-
return Promise.resolve(this.state);
74-
}
75-
76-
setState(newState) {
77-
this.state = newState;
78-
return Promise.resolve(true);
79-
}
80-
81-
getMin(key = "min") {
82-
return Promise.resolve(this.state[key]);
83-
}
84-
85-
getMax(key = "max") {
86-
return Promise.resolve(this.state[key]);
87-
}
88-
89-
close() {
90-
return Promise.resolve(true);
91-
}
9+
/**
10+
* be aware that even though KStorage is built on Promises
11+
* its operations must always be ATOMIC (or ACID) because
12+
* the stream will access them parallel, therefore having
13+
* an async get + async set operation will always yield
14+
* in a large amount of missing get operations followed by
15+
* set operations
16+
*/
17+
constructor(options) {
18+
this.options = options;
19+
this.state = {};
20+
}
21+
22+
/* NOTE: there is no open() method, meaning the functions have to work lazily */
23+
24+
set(key, value) {
25+
this.state[key] = value;
26+
return Promise.resolve(value);
27+
}
28+
29+
setSmaller(key = "min", value) {
30+
31+
if (!this.state[key]) {
32+
this.state[key] = value;
33+
}
34+
35+
if (value < this.state[key]) {
36+
this.state[key] = value;
37+
}
38+
39+
return Promise.resolve(this.state[key]);
40+
}
41+
42+
setGreater(key = "max", value) {
43+
44+
if (!this.state[key]) {
45+
this.state[key] = value;
46+
}
47+
48+
if (value > this.state[key]) {
49+
this.state[key] = value;
50+
}
51+
52+
return Promise.resolve(this.state[key]);
53+
}
54+
55+
increment(key, by = 1) {
56+
if (!this.state[key]) {
57+
this.state[key] = by;
58+
} else {
59+
this.state[key] += by;
60+
}
61+
return Promise.resolve(this.state[key]);
62+
}
63+
64+
sum(key, value) {
65+
return this.increment(key, value);
66+
}
67+
68+
get(key) {
69+
return Promise.resolve(this.state[key]);
70+
}
71+
72+
getState() {
73+
return Promise.resolve(this.state);
74+
}
75+
76+
setState(newState) {
77+
this.state = newState;
78+
return Promise.resolve(true);
79+
}
80+
81+
getMin(key = "min") {
82+
return Promise.resolve(this.state[key]);
83+
}
84+
85+
getMax(key = "max") {
86+
return Promise.resolve(this.state[key]);
87+
}
88+
89+
close() {
90+
return Promise.resolve(true);
91+
}
9292
}
9393

9494
export default KStorage;

src/lib/KafkaFactory.ts

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
"use strict";
22

3-
import debugFactory from 'debug';
3+
import debugFactory from "debug";
44
const debug = debugFactory("kafka-streams:kafkafactory");
5-
import JSKafkaClient from './client/JSKafkaClient';
6-
import NativeKafkaClient from './client/NativeKafkaClient';
5+
import JSKafkaClient from "./client/JSKafkaClient";
6+
import NativeKafkaClient from "./client/NativeKafkaClient";
77

88
class KafkaFactory {
99
public config: any;
1010
public batchOptions: any;
1111

12-
/**
12+
/**
1313
* helper for KafkaStreams to wrap
1414
* the setup of Kafka-Client instances
1515
* @param config
1616
* @param batchOptions - optional
1717
*/
18-
constructor(config, batchOptions = undefined) {
18+
constructor(config, batchOptions = undefined) {
1919

20-
if (!config) {
21-
throw new Error("kafka factory constructor expects a configuration object.");
22-
}
20+
if (!config) {
21+
throw new Error("kafka factory constructor expects a configuration object.");
22+
}
2323

24-
this.config = config;
25-
this.batchOptions = batchOptions;
26-
}
24+
this.config = config;
25+
this.batchOptions = batchOptions;
26+
}
2727

28-
getKafkaClient(topic) {
28+
getKafkaClient(topic) {
2929

30-
if (this.config.noptions && typeof this.config.noptions === "object") {
31-
debug("creating new native kafka client");
32-
return new NativeKafkaClient(topic, this.config, this.batchOptions);
33-
}
30+
if (this.config.noptions && typeof this.config.noptions === "object") {
31+
debug("creating new native kafka client");
32+
return new NativeKafkaClient(topic, this.config, this.batchOptions);
33+
}
3434

35-
if (this.batchOptions) {
36-
debug("WARNING: batchOptions are omitted for the JS client.");
37-
}
35+
if (this.batchOptions) {
36+
debug("WARNING: batchOptions are omitted for the JS client.");
37+
}
3838

39-
debug("creating new js kafka client");
40-
return new JSKafkaClient(topic, this.config);
41-
}
39+
debug("creating new js kafka client");
40+
return new JSKafkaClient(topic, this.config);
41+
}
4242
}
4343

4444
export default KafkaFactory;

src/lib/KafkaStreams.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use strict";
22

3-
import { EventEmitter } from 'events';
4-
import KafkaFactory from './KafkaFactory';
5-
import KStream from './dsl/KStream';
6-
import KTable from './dsl/KTable';
7-
import KStorage from './KStorage';
3+
import { EventEmitter } from "events";
4+
import KafkaFactory from "./KafkaFactory";
5+
import KStream from "./dsl/KStream";
6+
import KTable from "./dsl/KTable";
7+
import KStorage from "./KStorage";
88

99
/**
1010
* Stream object factory

src/lib/actions/KeyCount.ts

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
"use strict";
22

3-
import Promise from 'bluebird';
3+
import Promise from "bluebird";
44

55
/**
66
* used to count keys in a stream
77
*/
8-
class KeyCount {
8+
export class KeyCount {
99
public storage: any;
1010
public key: any;
1111
public fieldName: any;
1212

13-
constructor(storage, key, fieldName = "count") {
14-
this.storage = storage;
15-
this.key = key;
16-
this.fieldName = fieldName;
17-
}
13+
constructor(storage, key, fieldName = "count") {
14+
this.storage = storage;
15+
this.key = key;
16+
this.fieldName = fieldName;
17+
}
1818

19-
execute(value) {
19+
execute(value) {
2020

21-
if (!value || typeof value[this.key] === "undefined") {
22-
return Promise.resolve(value);
23-
}
21+
if (!value || typeof value[this.key] === "undefined") {
22+
return Promise.resolve(value);
23+
}
2424

25-
return this.storage.increment(value[this.key]).then(count => {
26-
value[this.fieldName] = count;
27-
return value;
28-
});
29-
}
25+
return this.storage.increment(value[this.key]).then(count => {
26+
value[this.fieldName] = count;
27+
return value;
28+
});
29+
}
3030
}
31-
32-
export default KeyCount;

0 commit comments

Comments
 (0)