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

feat(nestjs-microservices-registry): init #357

Merged
merged 3 commits into from
Mar 14, 2025
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
28 changes: 28 additions & 0 deletions .pnp.cjs

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

47 changes: 47 additions & 0 deletions packages/nestjs-microservices-registry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@atls/nestjs-microservices-registry",
"version": "0.0.0",
"license": "BSD-3-Clause",
"type": "module",
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
},
"main": "src/index.ts",
"files": [
"dist"
],
"scripts": {
"build": "yarn library build",
"prepack": "yarn run build",
"postpack": "rm -rf dist"
},
"dependencies": {
"fast-hash-code": "2.1.0"
},
"devDependencies": {
"@nestjs/common": "10.4.15",
"@nestjs/core": "10.4.15",
"reflect-metadata": "0.2.2",
"rxjs": "7.8.1"
},
"peerDependencies": {
"@nestjs/common": "^10",
"@nestjs/core": "^10",
"reflect-metadata": "^0.2",
"rxjs": "^7"
},
"publishConfig": {
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"main": "dist/index.js",
"typings": "dist/index.d.ts"
},
"typecheckSkipLibCheck": true
}
2 changes: 2 additions & 0 deletions packages/nestjs-microservices-registry/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './registry/index.js'
export * from './module/index.js'
1 change: 1 addition & 0 deletions packages/nestjs-microservices-registry/src/module/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './microservices-registry.module.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */

import type { DynamicModule } from '@nestjs/common'

import { Module } from '@nestjs/common'
import { fastHashCode as hash } from 'fast-hash-code'

import { MicroservisesRegistry } from '../registry/index.js'

@Module({})
export class MicroservisesRegistryModule {
static register(): DynamicModule {
return {
global: true,
module: MicroservisesRegistryModule,
providers: [
{
provide: MicroservisesRegistry,
useValue: MicroservisesRegistry,
},
],
exports: [
{
provide: MicroservisesRegistry,
useValue: MicroservisesRegistry,
},
],
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
static connect(options: any): DynamicModule {
return {
module: MicroservisesRegistryModule,
providers: [
{
provide: String(hash(JSON.stringify(options))),
useFactory: (registry: typeof MicroservisesRegistry): void => {
registry.add(options)
},
inject: [MicroservisesRegistry],
},
],
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './microservices.registry.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */

import type { INestApplication } from '@nestjs/common'
import type { NestHybridApplicationOptions } from '@nestjs/common'

export class MicroservisesRegistry {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static #instances: Set<any> = new Set()

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public static add(options: any): void {
this.#instances.add(options)
}

public static connect(
app: INestApplication,
hybridAppOptions: NestHybridApplicationOptions = {}
): void {
this.#instances.forEach((options) => app.connectMicroservice(options, hybridAppOptions))
}
}
24 changes: 24 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,23 @@ __metadata:
languageName: unknown
linkType: soft

"@atls/nestjs-microservices-registry@workspace:packages/nestjs-microservices-registry":
version: 0.0.0-use.local
resolution: "@atls/nestjs-microservices-registry@workspace:packages/nestjs-microservices-registry"
dependencies:
"@nestjs/common": "npm:10.4.15"
"@nestjs/core": "npm:10.4.15"
fast-hash-code: "npm:2.1.0"
reflect-metadata: "npm:0.2.2"
rxjs: "npm:7.8.1"
peerDependencies:
"@nestjs/common": ^10
"@nestjs/core": ^10
reflect-metadata: ^0.2
rxjs: ^7
languageName: unknown
linkType: soft

"@atls/nestjs-mikro-orm-config@workspace:packages/nestjs-mikro-orm-config":
version: 0.0.0-use.local
resolution: "@atls/nestjs-mikro-orm-config@workspace:packages/nestjs-mikro-orm-config"
Expand Down Expand Up @@ -11093,6 +11110,13 @@ __metadata:
languageName: node
linkType: hard

"fast-hash-code@npm:2.1.0":
version: 2.1.0
resolution: "fast-hash-code@npm:2.1.0"
checksum: 10c0/36c91672dffed7fb526422d2059b3bc620090a27f724079c3f0fea8c70b613923d2bf09b17c74032cef78cb29f7a698bf0f7457df1518234f1c91835aff78285
languageName: node
linkType: hard

"fast-json-stable-stringify@npm:^2.0.0, fast-json-stable-stringify@npm:^2.1.0":
version: 2.1.0
resolution: "fast-json-stable-stringify@npm:2.1.0"
Expand Down
Loading