From c8788e0fce8f49805c439d56b49c890959d1f4ae Mon Sep 17 00:00:00 2001 From: Thiago Pinto Date: Thu, 31 May 2018 18:51:36 -0300 Subject: [PATCH] Added typescript definitions --- .eslintignore | 3 +- package-lock.json | 115 +++++++++++++++++++++++++++++++++++++++++++- package.json | 14 ++++-- types/index.d.ts | 15 ++++++ types/tsconfig.json | 15 ++++++ types/tslint.json | 12 +++++ 6 files changed, 168 insertions(+), 6 deletions(-) create mode 100644 types/index.d.ts create mode 100644 types/tsconfig.json create mode 100644 types/tslint.json diff --git a/.eslintignore b/.eslintignore index 3091757..60a166b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ node_modules -coverage \ No newline at end of file +coverage +example \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 96b73f4..e2ac7f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "quintoandar-kafka", - "version": "0.0.5", + "version": "0.0.10", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -34,6 +34,12 @@ "through2": "2.0.3" } }, + "@types/node": { + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.3.0.tgz", + "integrity": "sha512-hWzNviaVFIr1TqcRA8ou49JaSHp+Rfabmnqg2kNvusKqLhPU0rIsGPUj5WJJ7ld4Bb7qdgLmIhLfCD1qS08IVA==", + "dev": true + }, "EventEmitter": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/EventEmitter/-/EventEmitter-1.0.0.tgz", @@ -1293,6 +1299,12 @@ "delayed-stream": "1.0.0" } }, + "commander": { + "version": "2.15.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", + "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", + "dev": true + }, "compare-versions": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-3.1.0.tgz", @@ -8074,6 +8086,101 @@ "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=", "dev": true }, + "tslib": { + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.2.tgz", + "integrity": "sha512-AVP5Xol3WivEr7hnssHDsaM+lVrVXWUvd1cfXTRkTj80b//6g2wIFEH6hZG0muGZRnHGrfttpdzRk3YlBkWjKw==", + "dev": true + }, + "tslint": { + "version": "5.10.0", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.10.0.tgz", + "integrity": "sha1-EeJrzLiK+gLdDZlWyuPUVAtfVMM=", + "dev": true, + "requires": { + "babel-code-frame": "6.26.0", + "builtin-modules": "1.1.1", + "chalk": "2.4.1", + "commander": "2.15.1", + "diff": "3.5.0", + "glob": "7.1.2", + "js-yaml": "3.11.0", + "minimatch": "3.0.4", + "resolve": "1.7.1", + "semver": "5.3.0", + "tslib": "1.9.2", + "tsutils": "2.27.1" + } + }, + "tslint-config-semistandard": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/tslint-config-semistandard/-/tslint-config-semistandard-7.0.0.tgz", + "integrity": "sha512-SMZmVMbHYn6sykthhoNSK39Oxt7b3LdkuXycAxsagp+W7rCBWYowbpwYOJQmeT2a8Vjh6Tz2ifHyraWKB5uArw==", + "dev": true, + "requires": { + "tslint-config-standard": "7.0.0", + "tslint-eslint-rules": "4.1.1" + } + }, + "tslint-config-standard": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/tslint-config-standard/-/tslint-config-standard-7.0.0.tgz", + "integrity": "sha512-QCrLt8WwiRgZpRSgRsk6cExy8/Vipa/5fHespm4Q1ly90EB6Lni04Ub8dkEW10bV3fPN3SkxEwj41ZOe/knCZA==", + "dev": true, + "requires": { + "tslint-eslint-rules": "4.1.1" + } + }, + "tslint-eslint-rules": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/tslint-eslint-rules/-/tslint-eslint-rules-4.1.1.tgz", + "integrity": "sha1-fDDniC8mvCdr/5HSOEl1xp2viLo=", + "dev": true, + "requires": { + "doctrine": "0.7.2", + "tslib": "1.9.2", + "tsutils": "1.9.1" + }, + "dependencies": { + "doctrine": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-0.7.2.tgz", + "integrity": "sha1-fLhgNZujvpDgQLJrcpzkv6ZUxSM=", + "dev": true, + "requires": { + "esutils": "1.1.6", + "isarray": "0.0.1" + } + }, + "esutils": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-1.1.6.tgz", + "integrity": "sha1-wBzKqa5LiXxtDD4hCuUvPHqEQ3U=", + "dev": true + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + }, + "tsutils": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-1.9.1.tgz", + "integrity": "sha1-ufmrROVa+WgYMdXyjQrur1x1DLA=", + "dev": true + } + } + }, + "tsutils": { + "version": "2.27.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.27.1.tgz", + "integrity": "sha512-AE/7uzp32MmaHvNNFES85hhUDHFdFZp6OAiZcd6y4ZKKIg6orJTm8keYWBhIhrJQH3a4LzNKat7ZPXZt5aTf6w==", + "dev": true, + "requires": { + "tslib": "1.9.2" + } + }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -8105,6 +8212,12 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "typescript": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.1.tgz", + "integrity": "sha512-h6pM2f/GDchCFlldnriOhs1QHuwbnmj6/v7499eMHqPeW4V2G0elua2eIc2nu8v2NdHV0Gm+tzX83Hr6nUFjQA==", + "dev": true + }, "uglify-js": { "version": "2.8.29", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", diff --git a/package.json b/package.json index 2cb9da6..3440c09 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "quintoandar-kafka", - "version": "0.0.10", + "version": "0.0.11", "description": "Default Kafka NodeJS lib for QuintoAndar", "main": "src/main.js", + "types": "types/index.d.ts", "dependencies": { "kafka-node": "git+https://github.com/thspinto/kafka-node.git#v2.6.2-rc1", "lodash": "^4.17.10", @@ -10,16 +11,21 @@ "uuid": "^3.2.1" }, "devDependencies": { + "@types/node": "^10.0.0", "EventEmitter": "^1.0.0", "eslint": "^4.7.2", "eslint-config-airbnb-base": "^12.1.0", "eslint-plugin-import": "2.8.0", "jest": "^21.2.1", - "jest-cli": "^22.0.3" + "jest-cli": "^22.0.3", + "tslint": "^5.10.0", + "tslint-config-semistandard": "^7.0.0", + "typescript": "^2.8.3" }, "scripts": { - "test": "jest --config jest.config.json --coverage --forceExit", - "eslint": "eslint ./" + "test": "npm run eslint && jest --config jest.config.json --coverage --forceExit", + "eslint": "eslint ./ && npm run eslint:ts", + "eslint:ts": "tslint --project ./types/tsconfig.json --config ./types/tslint.json && tsc --project types" }, "repository": { "type": "git", diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..4c012f2 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,15 @@ +import { Writable } from 'stream'; +import { ConsumerGroupOptions, KafkaClientOptions, HighLevelConsumerOptions } from 'kafka-node'; + +export { ConsumerGroupOptions, KafkaClientOptions, HighLevelConsumerOptions } from 'kafka-node'; + +export interface KafkaConsumerOptions { + configs: ConsumerGroupOptions; + topics: string[] | string; + handleMessageFn: (message: any) => any; +} +export class KafkaConsumer { + constructor(options: KafkaConsumerOptions); + + init(): void +} \ No newline at end of file diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..09c1be7 --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strict": true, + "noEmit": true, + "forceConsistentCasingInFileNames": true + } +} \ No newline at end of file diff --git a/types/tslint.json b/types/tslint.json new file mode 100644 index 0000000..1181825 --- /dev/null +++ b/types/tslint.json @@ -0,0 +1,12 @@ +{ + "defaultSeverity": "error", + "extends": "tslint-config-semistandard", + "jsRules": {}, + "rules": { + "no-empty": false, + "handle-callback-err": false, + "no-unused-variable": false + }, + "rulesDirectory": [] + } + \ No newline at end of file