Skip to content

Commit

Permalink
chore: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Val-istar-Guo committed Jan 16, 2024
1 parent 3939cec commit c473a8c
Show file tree
Hide file tree
Showing 47 changed files with 899 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .commitlintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extends:
- '@commitlint/config-conventional'
30 changes: 30 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
root: true,
extends: [
'plugin:@typescript-eslint/recommended',
'@buka/eslint-config/typescript/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
project: ['./tsconfig.json'],
},
env: {
es6: true,
node: true,
browser: true,
},
globals: {
globalThis: true,
NodeJS: true,
BufferEncoding: true,
},
ignorePatterns: ['./dist/**'],
rules: {
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-redundant-type-constituents': 'warn',
},
}
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Bug report
about: Create a report to help us improve
title: 'Bug: '
labels: bug

---
<!-- Please delete unused section -->

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Platform (please complete the following information):**

- Environment: NodeJS <!-- e.g. [-, nodejs, chrome, safari] -->
+ Version: <!-- e.g. [6.1.2] -->

**Additional context**
Add any other context about the problem here.
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/docs_improve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Document improve
about: Improve document quality or improve document content
title: 'Document: '
labels: documentation
---
<!-- Please delete unused section -->

**Is a part of the document confusing? Please describe.**
Document path or hyperlink or github permanent link.
> if use path or hyperlink, plase copy fragment that makes you confused into blockquote
A clear and concise description of why are you confused about this document.


**Is the document missing? Please describe.**
A clear and concise description of what do you want to add to the document.


**Describe your suggestions for improving the documentation**
A clear and concise description of what you suggest.


**Additional context**
Add any other context or screenshots about the feature request here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: 'Feature: '
labels: enhancement

---
<!-- Please delete unused section -->

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
7 changes: 7 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**Close issues**
List the issues solved.(e.g. 'close #xxx, close #xxx and close #xxx')

**Please check if the PR fulfills these requirements**

- [ ] Have you written new tests for your core changes, as applicable?
- [ ] Have you written or modified docs for your core changes, as applicable?
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
on:
push:
branches:
- master
- main
name: Release

permissions:
id-token: write
contents: write
pull-requests: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v4
id: release
with:
token: ${{secrets.GITHUB_TOKEN}}
release-type: node
- uses: actions/checkout@v4
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v3
with:
node-version: 18
if: ${{ steps.release.outputs.release_created }}
- run: corepack pnpm install
if: ${{ steps.release.outputs.release_created }}
- run: npm publish --provenance
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on: push
name: Test
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
- run: corepack pnpm i
- run: corepack pnpm test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
122 changes: 122 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

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

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist
lib
es

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# Lock File
package-lock.json
yarn.lock
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
12 changes: 12 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.github
/.husky
/build
/coverage
/doc
/src
/test

.commitlintrc.yml
.eslintrc.cjs
.gitignore
jest.config.ts
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# @buka/nestjs-kafka

This is a nestJS module implemented using KafkaJS.
That support multiple connections and fits the coding style of nestjs.

## Usage

Import `KafkaModule`:

```typescript
// app.module.js
import { Module } from "@nestjs/common";
import { KafkaModule } from "@buka/nestjs-kafka";

@Module({
imports: [
KafkaModule.forRoot({
name: "my-kafka",
groupId: "my-group-id",
clientId: "my-client-id",
brokers: ["my_kafka_host:9092"],
}),
],
})
export class AppModule {}
```

Add a provider named `AppConsumer` that consume message:

```typescript
// app.consumer.js
@Injectable()
@KafkaConsumer()
export class AppConsumer {
@KafkaConsume("my-topic")
async finishTask(@KafkaMessage() message: string): Promise<void> {
// do something
console.log(message);
}

@KafkaConsume("other-topic", { json: true })
async finishTask(
@KafkaMessage() message: Record<string, any>
): Promise<void> {
// do something
console.log(message);
}
}
```

Append `AppConsumer` to `AppModule`:

```typescript
import { Module } from "@nestjs/common";
import { AppConsumer } from "./app.consumer";

@Module({
imports: [
/* ... */
],
providers: [AppConsumer],
})
export class AppModule {}
```
4 changes: 4 additions & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

tsc -p ./build/tsconfig.lib.json &
tsc -p ./build/tsconfig.es.json
12 changes: 12 additions & 0 deletions build/tsconfig.es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../dist/esm",
"module": "esnext",
"target": "esnext",
"preserveWatchOutput": true,
"resolveJsonModule": false
},
"include": ["../src/**/*.ts"],
"exclude": ["../src/**/*.spec.ts"]
}
Loading

0 comments on commit c473a8c

Please sign in to comment.