Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps-dev): replace standard with neostandard #136

Merged
merged 2 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/fastify/fastify-kafka/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-kafka/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/kafka.svg?style=flat)](https://www.npmjs.com/package/@fastify/kafka)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Fastify plugin to interact with [Apache Kafka](http://kafka.apache.org/). Supports Kafka producer and consumer.
To achieve the best performance, the plugin uses [`node-rdkafka`](https://github.com/Blizzard/node-rdkafka).
Expand Down
6 changes: 6 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

module.exports = require('neostandard')({
ignores: require('neostandard').resolveIgnoresFromGitignore(),
ts: true
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"scripts": {
"infra:start": "docker-compose up -d",
"infra:stop": "docker-compose stop",
"lint": "standard",
"lint:fix": "standard --fix",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "tap",
"test:typescript": "tsd"
Expand Down Expand Up @@ -39,7 +39,7 @@
"@types/node": "^22.0.0",
"abstract-logging": "2.0.1",
"fastify": "^5.0.0",
"standard": "^17.1.0",
"neostandard": "^0.11.9",
"tap": "^20.0.3",
"tsd": "^0.31.1"
},
Expand Down
82 changes: 41 additions & 41 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
import { FastifyPluginCallback } from 'fastify';
import { FastifyPluginCallback } from 'fastify'
import {
ConsumerGlobalConfig,
ConsumerTopicConfig,
KafkaConsumer,
Message,
MetadataOptions,
Producer,
ProducerGlobalConfig,
ProducerTopicConfig
} from 'node-rdkafka';
ConsumerGlobalConfig,
ConsumerTopicConfig,
KafkaConsumer,
Message,
MetadataOptions,
Producer,
ProducerGlobalConfig,
ProducerTopicConfig
} from 'node-rdkafka'

declare module 'fastify' {
interface FastifyKafkaMessage extends Pick<Message, 'topic' | 'partition' | 'key'> {
payload: unknown;
}

interface FastifyKafkaProducer {
producer: Producer;
push(message: FastifyKafkaMessage): void;
stop(done: () => void): void;
}

interface FastifyKafkaConsumer extends Pick<KafkaConsumer, 'consume' | 'subscribe'> {
consumer: KafkaConsumer;
stop(done: () => void): void;
}

interface Kafka extends Pick<FastifyKafkaProducer, 'push'>, Pick<FastifyKafkaConsumer, 'consume' | 'subscribe'> {
producer?: FastifyKafkaProducer;
consumer?: FastifyKafkaConsumer;
}
interface FastifyInstance {
kafka: Kafka;
}
interface FastifyKafkaMessage extends Pick<Message, 'topic' | 'partition' | 'key'> {
payload: unknown;
}

interface FastifyKafkaProducer {
producer: Producer;
push(message: FastifyKafkaMessage): void;
stop(done: () => void): void;
}

interface FastifyKafkaConsumer extends Pick<KafkaConsumer, 'consume' | 'subscribe'> {
consumer: KafkaConsumer;
stop(done: () => void): void;
}

interface Kafka extends Pick<FastifyKafkaProducer, 'push'>, Pick<FastifyKafkaConsumer, 'consume' | 'subscribe'> {
producer?: FastifyKafkaProducer;
consumer?: FastifyKafkaConsumer;
}
interface FastifyInstance {
kafka: Kafka;
}
}

type FastifyKafka = FastifyPluginCallback<fastifyKafka.FastifyKafkaOptions>;
type FastifyKafka = FastifyPluginCallback<fastifyKafka.FastifyKafkaOptions>

declare namespace fastifyKafka {
export interface FastifyKafkaOptions {
producer?: ProducerGlobalConfig;
consumer?: ConsumerGlobalConfig;
producerTopicConf?: ProducerTopicConfig;
consumerTopicConf?: ConsumerTopicConfig;
metadataOptions?: MetadataOptions;
}
export interface FastifyKafkaOptions {
producer?: ProducerGlobalConfig;
consumer?: ConsumerGlobalConfig;
producerTopicConf?: ProducerTopicConfig;
consumerTopicConf?: ConsumerTopicConfig;
metadataOptions?: MetadataOptions;
}

export const fastifyKafka: FastifyKafka
export { fastifyKafka as default }
}

declare function fastifyKafka(...params: Parameters<FastifyKafka>): ReturnType<FastifyKafka>
declare function fastifyKafka (...params: Parameters<FastifyKafka>): ReturnType<FastifyKafka>
export = fastifyKafka
46 changes: 23 additions & 23 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import Fastify, { FastifyKafkaConsumer, FastifyKafkaProducer, Kafka } from 'fastify';
import { expectAssignable } from 'tsd';
import fastifyKafka from '..';
import Fastify, { FastifyKafkaConsumer, FastifyKafkaProducer, Kafka } from 'fastify'
import { expectAssignable } from 'tsd'
import fastifyKafka from '..'

const app = Fastify()

app.register(fastifyKafka, {
producer: {
'metadata.broker.list': '127.0.0.1:9092',
dr_cb: true
},
consumer: {
'metadata.broker.list': '127.0.0.1:9092',
'group.id': "new-group-1",
'fetch.wait.max.ms': 10,
'fetch.error.backoff.ms': 50,
},
consumerTopicConf: {
'auto.offset.reset': 'earliest'
},
producerTopicConf: {
"request.timeout.ms": 10
},
metadataOptions: {
timeout: 1000
}
});
producer: {
'metadata.broker.list': '127.0.0.1:9092',
dr_cb: true
},
consumer: {
'metadata.broker.list': '127.0.0.1:9092',
'group.id': 'new-group-1',
'fetch.wait.max.ms': 10,
'fetch.error.backoff.ms': 50,
},
consumerTopicConf: {
'auto.offset.reset': 'earliest'
},
producerTopicConf: {
'request.timeout.ms': 10
},
metadataOptions: {
timeout: 1000
}
})

// Check whether all properties are merged successfully or not
expectAssignable<Kafka>(app.kafka)
Expand Down
Loading