@rxdi/nats 0.7.240 → 0.7.241

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.
Files changed (75) hide show
  1. package/{src/decorators/index.ts → dist/decorators/index.d.ts} +1 -1
  2. package/dist/decorators/index.js +20 -0
  3. package/dist/decorators/index.js.map +1 -0
  4. package/dist/decorators/nats-call.decorator.d.ts +7 -0
  5. package/dist/decorators/nats-call.decorator.js +32 -0
  6. package/dist/decorators/nats-call.decorator.js.map +1 -0
  7. package/dist/decorators/nats-emit.decorator.d.ts +6 -0
  8. package/dist/decorators/nats-emit.decorator.js +47 -0
  9. package/dist/decorators/nats-emit.decorator.js.map +1 -0
  10. package/dist/decorators/nats-listener.decorator.d.ts +5 -0
  11. package/dist/decorators/nats-listener.decorator.js +28 -0
  12. package/dist/decorators/nats-listener.decorator.js.map +1 -0
  13. package/{src/index.ts → dist/index.d.ts} +1 -2
  14. package/dist/index.js +23 -0
  15. package/dist/index.js.map +1 -0
  16. package/{src/interfaces/index.ts → dist/interfaces/index.d.ts} +1 -1
  17. package/dist/interfaces/index.js +19 -0
  18. package/dist/interfaces/index.js.map +1 -0
  19. package/dist/interfaces/nats-logger.d.ts +20 -0
  20. package/dist/interfaces/nats-logger.js +37 -0
  21. package/dist/interfaces/nats-logger.js.map +1 -0
  22. package/dist/interfaces/nats-module.config.d.ts +54 -0
  23. package/dist/interfaces/nats-module.config.js +10 -0
  24. package/dist/interfaces/nats-module.config.js.map +1 -0
  25. package/dist/nats.module.d.ts +13 -0
  26. package/dist/nats.module.js +92 -0
  27. package/dist/nats.module.js.map +1 -0
  28. package/{src/services/index.ts → dist/services/index.d.ts} +1 -1
  29. package/dist/services/index.js +25 -0
  30. package/dist/services/index.js.map +1 -0
  31. package/dist/services/microservice-registry.service.d.ts +20 -0
  32. package/dist/services/microservice-registry.service.js +60 -0
  33. package/dist/services/microservice-registry.service.js.map +1 -0
  34. package/dist/services/nats-client.service.d.ts +27 -0
  35. package/dist/services/nats-client.service.js +188 -0
  36. package/dist/services/nats-client.service.js.map +1 -0
  37. package/dist/services/nats-listener.host.d.ts +30 -0
  38. package/dist/services/nats-listener.host.js +128 -0
  39. package/dist/services/nats-listener.host.js.map +1 -0
  40. package/dist/services/nats-logger.service.d.ts +11 -0
  41. package/dist/services/nats-logger.service.js +53 -0
  42. package/dist/services/nats-logger.service.js.map +1 -0
  43. package/dist/services/nats-pubsub.class.d.ts +36 -0
  44. package/dist/services/nats-pubsub.class.js +122 -0
  45. package/dist/services/nats-pubsub.class.js.map +1 -0
  46. package/dist/services/nats-pubsub.service.d.ts +19 -0
  47. package/dist/services/nats-pubsub.service.js +101 -0
  48. package/dist/services/nats-pubsub.service.js.map +1 -0
  49. package/dist/services/pubsub-async-iterator.d.ts +21 -0
  50. package/dist/services/pubsub-async-iterator.js +51 -0
  51. package/dist/services/pubsub-async-iterator.js.map +1 -0
  52. package/dist/services/service-discovery.service.d.ts +14 -0
  53. package/dist/services/service-discovery.service.js +70 -0
  54. package/dist/services/service-discovery.service.js.map +1 -0
  55. package/package.json +2 -2
  56. package/src/decorators/nats-call.decorator.ts +0 -42
  57. package/src/decorators/nats-emit.decorator.ts +0 -59
  58. package/src/decorators/nats-listener.decorator.ts +0 -37
  59. package/src/interfaces/nats-logger.ts +0 -41
  60. package/src/interfaces/nats-module.config.spec.ts +0 -210
  61. package/src/interfaces/nats-module.config.ts +0 -61
  62. package/src/nats-decorators.spec.ts +0 -96
  63. package/src/nats-logger.spec.ts +0 -171
  64. package/src/nats.module.ts +0 -86
  65. package/src/services/microservice-registry.service.ts +0 -56
  66. package/src/services/nats-client.service.ts +0 -187
  67. package/src/services/nats-listener.host.ts +0 -132
  68. package/src/services/nats-logger.service.ts +0 -46
  69. package/src/services/nats-pubsub.class.ts +0 -152
  70. package/src/services/nats-pubsub.service.ts +0 -95
  71. package/src/services/pubsub-async-iterator.spec.ts +0 -78
  72. package/src/services/pubsub-async-iterator.ts +0 -61
  73. package/src/services/service-discovery.service.ts +0 -57
  74. package/tsconfig.json +0 -26
  75. package/tslint.json +0 -6
@@ -1,61 +0,0 @@
1
- import { NatsPubSubInterface } from '../interfaces';
2
-
3
- export class PubSubAsyncIterator<T> implements AsyncIterator<T> {
4
- private subscriptionId: number | null = null;
5
- private listeners: Array<(value: T) => void> = [];
6
- private returnPromise: Promise<{ value: T; done: boolean }>;
7
- private resolveReturn!: (value: { value: T; done: boolean }) => void;
8
- private rejectPromise!: (reason: any) => void;
9
-
10
- constructor(
11
- private pubsub: NatsPubSubInterface,
12
- private triggers: string | string[]
13
- ) {
14
- this.returnPromise = new Promise<{ value: T; done: boolean }>((resolve, reject) => {
15
- this.resolveReturn = resolve;
16
- this.rejectPromise = reject;
17
- });
18
- }
19
-
20
- async next(): Promise<{ value: T; done: boolean }> {
21
- if (!this.subscriptionId) {
22
- const trigger = Array.isArray(this.triggers) ? this.triggers[0] : this.triggers;
23
- this.subscriptionId = await this.pubsub.subscribe(
24
- trigger,
25
- async (message: T) => {
26
- for (const listener of this.listeners) {
27
- listener(message);
28
- }
29
- }
30
- ) as any;
31
- }
32
-
33
- return new Promise<{ value: T; done: boolean }>((resolve) => {
34
- const listener = (value: T) => {
35
- this.listeners = this.listeners.filter((l) => l !== listener);
36
- resolve({ value, done: false });
37
- };
38
- this.listeners.push(listener);
39
- });
40
- }
41
-
42
- async return(): Promise<{ value: T; done: boolean }> {
43
- if (this.subscriptionId) {
44
- await this.pubsub.unsubscribe(this.subscriptionId);
45
- this.subscriptionId = null;
46
- }
47
- return { value: undefined as any, done: true };
48
- }
49
-
50
- async throw?(error?: any): Promise<never> {
51
- if (this.subscriptionId) {
52
- await this.pubsub.unsubscribe(this.subscriptionId);
53
- this.subscriptionId = null;
54
- }
55
- return Promise.reject(error);
56
- }
57
-
58
- [Symbol.asyncIterator](): AsyncIterator<T> {
59
- return this;
60
- }
61
- }
@@ -1,57 +0,0 @@
1
- import { Injectable, Inject, OnInit } from '@rxdi/core';
2
- import { NatsModuleConfiguration, NATS_MODULE_CONFIG } from '../interfaces';
3
-
4
- @Injectable()
5
- export class ServiceDiscoveryService implements OnInit {
6
- private discoveredServers: string[] = [];
7
- private monitorInterval: NodeJS.Timeout | null = null;
8
- private isMonitoring = false;
9
-
10
- constructor(
11
- @Inject(NATS_MODULE_CONFIG) private config: NatsModuleConfiguration
12
- ) {}
13
-
14
- OnInit(): void {}
15
-
16
- async discoverServers(getClient: () => any): Promise<string[]> {
17
- const client = getClient();
18
- if (!client) {
19
- return this.config.servers || [];
20
- }
21
-
22
- try {
23
- const serverInfo: any = client.info();
24
- if (serverInfo && serverInfo.connect_urls) {
25
- this.discoveredServers = serverInfo.connect_urls.map((url: string) => `nats://${url}`);
26
- }
27
- } catch (e) {
28
- console.warn('Service discovery: Could not fetch server info', e);
29
- }
30
-
31
- return this.discoveredServers;
32
- }
33
-
34
- async startMonitoring(getClientFn: () => any, intervalMs = 30000): Promise<void> {
35
- if (this.isMonitoring) return;
36
- this.isMonitoring = true;
37
-
38
- this.monitorInterval = setInterval(async () => {
39
- const client = getClientFn();
40
- if (client) {
41
- await this.discoverServers(() => client);
42
- }
43
- }, intervalMs);
44
- }
45
-
46
- stopMonitoring(): void {
47
- if (this.monitorInterval) {
48
- clearInterval(this.monitorInterval);
49
- this.monitorInterval = null;
50
- this.isMonitoring = false;
51
- }
52
- }
53
-
54
- getDiscoveredServers(): string[] {
55
- return [...this.discoveredServers];
56
- }
57
- }
package/tsconfig.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2018",
4
- "module": "commonjs",
5
- "lib": ["ES2018"],
6
- "declaration": true,
7
- "strict": true,
8
- "noImplicitAny": true,
9
- "strictNullChecks": true,
10
- "noImplicitThis": true,
11
- "alwaysStrict": true,
12
- "noUnusedLocals": false,
13
- "noUnusedParameters": false,
14
- "noImplicitReturns": true,
15
- "noFallthroughCasesInSwitch": false,
16
- "experimentalDecorators": true,
17
- "emitDecoratorMetadata": true,
18
- "outDir": "./dist",
19
- "rootDir": "./src",
20
- "sourceMap": true,
21
- "skipLibCheck": true,
22
- "moduleResolution": "node"
23
- },
24
- "include": ["src/**/*"],
25
- "exclude": ["node_modules", "dist", "**/*.spec.ts"]
26
- }
package/tslint.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "rules": {
3
- "quotemark": [true, "single"],
4
- "no-unused-expression": true
5
- }
6
- }