Skip to content

Commit

Permalink
refactor: added subscription handling through annotations (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwimberger authored Dec 12, 2024
2 parents 1bc47dc + 120de70 commit 1388a0a
Show file tree
Hide file tree
Showing 16 changed files with 388 additions and 266 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Run Build
run: npm i && npx nest build

24 changes: 24 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: e2e
on:
push:
branches: [ 'main' ]
pull_request:
branches: [ 'main' ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Cache node_modules
id: node-modules
uses: actions/cache@v4
with:
path: node_modules
key: node-modules
- name: Run Build
run: npm i && npx nest build && npm run test:e2e

5 changes: 1 addition & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ jobs:
id: node-modules
uses: actions/cache@v4
with:
path: |
node_modules
test-app/node_modules
.yarn/cache
path: node_modules
key: node-modules
- name: Import GPG key
id: import-gpg
Expand Down
24 changes: 23 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:e2e": "jest --config ./test/jest-e2e.json --detectOpenHandles",
"prepack": "npx nest build"
},
"peerDependencies": {
Expand All @@ -44,13 +44,15 @@
"devDependencies": {
"@nestjs/cli": "^10.4.8",
"@nestjs/common": "^10.4.7",
"@nestjs/core": "^10.4.7",
"@nestjs/config": "^3.3.0",
"@nestjs/core": "^10.4.7",
"@nestjs/event-emitter": "^2.1.1",
"@nestjs/testing": "^10.4.7",
"@release-it/conventional-changelog": "^9.0.3",
"@types/express": "^5.0.0",
"@types/jest": "29.5.14",
"@types/node": "^22.9.0",
"aedes": "0.51.3",
"auto-changelog": "^2.5.0",
"prettier": "3.3.3",
"reflect-metadata": "^0.2.2",
Expand All @@ -64,8 +66,7 @@
"tsc-watch": "6.2.1",
"tsconfig-paths": "4.2.0",
"tslint": "6.1.3",
"typescript": "^5.6.3",
"aedes": "^0.51.2"
"typescript": "^5.6.3"
},
"jest": {
"moduleFileExtensions": [
Expand Down
1 change: 0 additions & 1 deletion src/mqtt.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export const MQTT_SUBSCRIBE_OPTIONS = '__mqtt_subscribe_options';
export const MQTT_SUBSCRIBER_PARAMS = '__mqtt_subscriber_params';
export const MQTT_CLIENT_INSTANCE = 'MQTT_CLIENT_INSTANCE';
export const MQTT_OPTION_PROVIDER = 'MQTT_OPTION_PROVIDER';
export const MQTT_LOGGER_PROVIDER = 'MQTT_LOGGER_PROVIDER';
221 changes: 0 additions & 221 deletions src/mqtt.explorer.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/mqtt.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface MqttModuleOptions extends IClientOptions {
*/
share?: string;

topic?: string;
beforeHandle?: (topic: string, payload: Buffer, packet: Packet) => any;
}

Expand Down
6 changes: 4 additions & 2 deletions src/mqtt.module-definition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ConfigurableModuleBuilder } from '@nestjs/common';
import { MqttModuleOptions } from './mqtt.interface';

export const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } =
new ConfigurableModuleBuilder<MqttModuleOptions>().setClassMethodName('forRoot').build();
export const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, ASYNC_OPTIONS_TYPE } =
new ConfigurableModuleBuilder<MqttModuleOptions>({ 'moduleName': 'MqttModule' })
.setClassMethodName('forRoot')
.build();
2 changes: 2 additions & 0 deletions src/mqtt.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import {
} from '@nestjs/common';
import { MqttService } from './mqtt.service';
import { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } from './mqtt.module-definition';
import { DiscoveryModule, DiscoveryService } from '@nestjs/core';

@Global()
@Module({
providers: [MqttService],
imports: [DiscoveryModule],
exports: [MqttService, MODULE_OPTIONS_TOKEN],
})
export class MqttModule extends ConfigurableModuleClass {
Expand Down
Loading

0 comments on commit 1388a0a

Please sign in to comment.