@ubs-platform/nest-microservice-setup-util 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "extends": ["../../.eslintrc.base.json"],
3
+ "ignorePatterns": ["!**/*"],
4
+ "overrides": [
5
+ {
6
+ "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
+ "rules": {}
8
+ },
9
+ {
10
+ "files": ["*.ts", "*.tsx"],
11
+ "rules": {}
12
+ },
13
+ {
14
+ "files": ["*.js", "*.jsx"],
15
+ "rules": {}
16
+ },
17
+ {
18
+ "files": ["*.json"],
19
+ "parser": "jsonc-eslint-parser",
20
+ "rules": {
21
+ "@nx/dependency-checks": "error"
22
+ }
23
+ }
24
+ ]
25
+ }
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # nest-microservice-setup-util
2
+
3
+ # NOTICE: Not ready for production usage and builds. I'm working for get runnable.
package/jest.config.ts ADDED
@@ -0,0 +1,11 @@
1
+ /* eslint-disable */
2
+ export default {
3
+ displayName: 'nest-microservice-setup-util',
4
+ preset: '../../jest.preset.js',
5
+ testEnvironment: 'node',
6
+ transform: {
7
+ '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
8
+ },
9
+ moduleFileExtensions: ['ts', 'js', 'html'],
10
+ coverageDirectory: '../../coverage/libs/nest-microservice-setup-util',
11
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@ubs-platform/nest-microservice-setup-util",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "scripts": {
6
+ "build": "tsc",
7
+ "publish": "npm run build && echo 'not yet'"
8
+ },
9
+ "peerDependencies": {
10
+ "@nestjs/microservices": "^10.3.3"
11
+ },
12
+ "dependencies": {
13
+ "tslib": "^2.3.0"
14
+ },
15
+ "devDependencies": {
16
+ "typescript": "~5.3.2",
17
+ "@types/node": "~18.16.9"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ }
22
+ }
package/project.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "nest-microservice-setup-util",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "libs/nest-microservice-setup-util/src",
5
+ "projectType": "library",
6
+ "targets": {
7
+ "build": {
8
+ "executor": "@nx/js:tsc",
9
+ "outputs": ["{options.outputPath}"],
10
+ "options": {
11
+ "outputPath": "dist/libs/nest-microservice-setup-util",
12
+ "tsConfig": "libs/nest-microservice-setup-util/tsconfig.lib.json",
13
+ "packageJson": "libs/nest-microservice-setup-util/package.json",
14
+ "main": "libs/nest-microservice-setup-util/src/index.ts",
15
+ "assets": ["libs/nest-microservice-setup-util/*.md"]
16
+ }
17
+ },
18
+ "publish": {
19
+ "command": "node tools/scripts/publish.mjs nest-microservice-setup-util {args.ver} {args.tag}",
20
+ "dependsOn": ["build"]
21
+ }
22
+ },
23
+ "tags": []
24
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/nest-microservice-setup-util';
@@ -0,0 +1,56 @@
1
+ import { Transport } from '@nestjs/microservices';
2
+ import { randomUUID } from 'crypto';
3
+ export const getMicroserviceConnection = (groupName) => {
4
+ const type = process.env['NX_MICROSERVICE_TYPE'] as 'KAFKA' | 'TCP' | 'RMQ';
5
+
6
+ let microservice: Object | null = null;
7
+ if (type == 'KAFKA') {
8
+ microservice = {
9
+ transport: Transport.KAFKA,
10
+ options: {
11
+ client: {
12
+ clientId: 'users',
13
+ brokers: [`${process.env['NX_KAFKA_URL']}`],
14
+ },
15
+ consumer: {
16
+ groupId: 'tk' + randomUUID(),
17
+ },
18
+ },
19
+ };
20
+ } else if (type == 'RMQ') {
21
+ microservice = {
22
+ transport: Transport.RMQ,
23
+ options: {
24
+ urls: [process.env['NX_RMQ_URL']],
25
+ queue: 'cats_queue',
26
+ queueOptions: {
27
+ durable: false,
28
+ },
29
+ },
30
+ };
31
+ } else {
32
+ microservice = {
33
+ transport: Transport.TCP,
34
+ options: {
35
+ host: process.env['NX_TCP_HOST'],
36
+ port: process.env['NX_TCP_PORT'],
37
+ },
38
+ };
39
+ }
40
+
41
+ // return {
42
+ // transport: Transport.TCP,
43
+ // options: {
44
+ // host: 'localhost',
45
+ // port: 7177,
46
+ // },
47
+ // };
48
+ if (microservice == null) {
49
+ throw 'Microservice type not recognized';
50
+ }
51
+ return microservice;
52
+ };
53
+ // export const UserMicroserviceCommunication =
54
+
55
+ // // More 2 3 kafka clients are needed, comes replication invalid shit error
56
+ // export const UserMicroserviceCommunication =
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs"
5
+ },
6
+ "files": [],
7
+ "include": [],
8
+ "references": [
9
+ {
10
+ "path": "./tsconfig.lib.json"
11
+ },
12
+ {
13
+ "path": "./tsconfig.spec.json"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "outDir": "../../dist/out-tsc",
6
+ "declaration": true,
7
+ "types": ["node"]
8
+ },
9
+ "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
10
+ "include": ["src/**/*.ts"]
11
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"]
7
+ },
8
+ "include": [
9
+ "jest.config.ts",
10
+ "src/**/*.test.ts",
11
+ "src/**/*.spec.ts",
12
+ "src/**/*.d.ts"
13
+ ]
14
+ }