nats-micro
Advanced tools
Comparing version 0.28.6 to 0.28.7
@@ -5,2 +5,4 @@ import { MessageHandler, RequestManyOptions, RequestOptions, SendOptions, Subject, BrokerResponse } from './types/broker.js'; | ||
get name(): string; | ||
connect(): Promise<this>; | ||
disconnect(): Promise<void>; | ||
createInbox(): string; | ||
@@ -7,0 +9,0 @@ on<T>(subject: Subject, listener: MessageHandler<T>): void; |
@@ -9,2 +9,4 @@ import { Broker } from './broker.js'; | ||
constructor(); | ||
connect(): Promise<this>; | ||
disconnect(): Promise<void>; | ||
createInbox(): string; | ||
@@ -11,0 +13,0 @@ on<T>(subject: Subject, listener: MessageHandler<T>, queue?: string): void; |
@@ -42,2 +42,13 @@ "use strict"; | ||
} | ||
connect() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// nothing to do | ||
return this; | ||
}); | ||
} | ||
disconnect() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// nothing to do | ||
}); | ||
} | ||
createInbox() { | ||
@@ -44,0 +55,0 @@ return `_INBOX.${Math.floor(Math.random() * 1e10)}`; |
@@ -18,3 +18,5 @@ import { Discovery } from './discovery.js'; | ||
get config(): Readonly<MicroserviceConfig>; | ||
on(event: 'stop', listener: () => void): void; | ||
on(event: 'close', listener: () => void): void; | ||
off(event: 'stop', listener: () => void): void; | ||
off(event: 'close', listener: () => void): void; | ||
@@ -21,0 +23,0 @@ private emit; |
@@ -22,2 +22,3 @@ "use strict"; | ||
const index_js_1 = require("../utils/index.js"); | ||
const util_1 = require("util"); | ||
class Microservice { | ||
@@ -64,6 +65,12 @@ constructor(broker, config, options) { | ||
on(event, listener) { | ||
this.ee.on(event, listener); | ||
if (event === 'close') | ||
(0, util_1.deprecate)(() => this.on('stop', listener), 'close is deprecated. Use stop instead'); | ||
else | ||
this.ee.on(event, listener); | ||
} | ||
off(event, listener) { | ||
this.ee.off(event, listener); | ||
if (event === 'close') | ||
(0, util_1.deprecate)(() => this.off('stop', listener), 'close is deprecated. Use stop instead'); | ||
else | ||
this.ee.off(event, listener); | ||
} | ||
@@ -132,2 +139,3 @@ emit(event) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.emit('stop'); | ||
this.emit('close'); | ||
@@ -134,0 +142,0 @@ yield this.stop(); |
@@ -5,2 +5,4 @@ import { MessageHandler, RequestManyOptions, RequestOptions, SendOptions, Subject, BrokerResponse } from './types/broker.js'; | ||
get name(): string; | ||
connect(): Promise<this>; | ||
disconnect(): Promise<void>; | ||
createInbox(): string; | ||
@@ -7,0 +9,0 @@ on<T>(subject: Subject, listener: MessageHandler<T>): void; |
@@ -9,2 +9,4 @@ import { Broker } from './broker.js'; | ||
constructor(); | ||
connect(): Promise<this>; | ||
disconnect(): Promise<void>; | ||
createInbox(): string; | ||
@@ -11,0 +13,0 @@ on<T>(subject: Subject, listener: MessageHandler<T>, queue?: string): void; |
@@ -39,2 +39,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
connect() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// nothing to do | ||
return this; | ||
}); | ||
} | ||
disconnect() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// nothing to do | ||
}); | ||
} | ||
createInbox() { | ||
@@ -41,0 +52,0 @@ return `_INBOX.${Math.floor(Math.random() * 1e10)}`; |
@@ -18,3 +18,5 @@ import { Discovery } from './discovery.js'; | ||
get config(): Readonly<MicroserviceConfig>; | ||
on(event: 'stop', listener: () => void): void; | ||
on(event: 'close', listener: () => void): void; | ||
off(event: 'stop', listener: () => void): void; | ||
off(event: 'close', listener: () => void): void; | ||
@@ -21,0 +23,0 @@ private emit; |
@@ -16,2 +16,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { errorToString, attachThreadContext, wrapMethodSafe, } from '../utils/index.js'; | ||
import { deprecate } from 'util'; | ||
export class Microservice { | ||
@@ -58,6 +59,12 @@ constructor(broker, config, options) { | ||
on(event, listener) { | ||
this.ee.on(event, listener); | ||
if (event === 'close') | ||
deprecate(() => this.on('stop', listener), 'close is deprecated. Use stop instead'); | ||
else | ||
this.ee.on(event, listener); | ||
} | ||
off(event, listener) { | ||
this.ee.off(event, listener); | ||
if (event === 'close') | ||
deprecate(() => this.off('stop', listener), 'close is deprecated. Use stop instead'); | ||
else | ||
this.ee.off(event, listener); | ||
} | ||
@@ -126,2 +133,3 @@ emit(event) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.emit('stop'); | ||
this.emit('close'); | ||
@@ -128,0 +136,0 @@ yield this.stop(); |
{ | ||
"name": "nats-micro", | ||
"version": "0.28.6", | ||
"version": "0.28.7", | ||
"description": "NATS micro compatible extra-lightweight microservice library", | ||
@@ -5,0 +5,0 @@ "main": "lib/cjs/index.js", |
# [NATS Microservice Library](#top) | ||
![](https://img.shields.io/badge/Coverage-93%25-83A603.svg?style=flat&prefix=$coverage$) | ||
![](https://img.shields.io/badge/Coverage-92%25-83A603.svg?style=flat&prefix=$coverage$) | ||
@@ -5,0 +5,0 @@ A convenient microservice library based on NATS and compatible with nats-go microservices |
@@ -11,2 +11,5 @@ import { | ||
connect(): Promise<this>; | ||
disconnect(): Promise<void>; | ||
createInbox(): string; | ||
@@ -13,0 +16,0 @@ |
@@ -25,2 +25,11 @@ import { Broker } from './broker.js'; | ||
public async connect(): Promise<this> { | ||
// nothing to do | ||
return this; | ||
} | ||
public async disconnect(): Promise<void> { | ||
// nothing to do | ||
} | ||
createInbox(): string { | ||
@@ -27,0 +36,0 @@ return `_INBOX.${Math.floor(Math.random() * 1e10)}`; |
@@ -14,2 +14,3 @@ import { threadContext } from 'debug-threads-ns'; | ||
} from '../utils/index.js'; | ||
import { deprecate } from 'util'; | ||
@@ -88,11 +89,29 @@ export type MicroserviceOptions = { | ||
public on(event: 'close', listener: () => void): void { | ||
this.ee.on(event, listener); | ||
public on(event: 'stop', listener: () => void): void; | ||
public on(event: 'close', listener: () => void): void; | ||
public on(event: string, listener: () => void): void { | ||
if (event === 'close') | ||
deprecate( | ||
() => this.on('stop', listener), | ||
'close is deprecated. Use stop instead', | ||
); | ||
else | ||
this.ee.on(event, listener); | ||
} | ||
public off(event: 'close', listener: () => void): void { | ||
this.ee.off(event, listener); | ||
public off(event: 'stop', listener: () => void): void; | ||
public off(event: 'close', listener: () => void): void; | ||
public off(event: string, listener: () => void): void { | ||
if (event === 'close') | ||
deprecate( | ||
() => this.off('stop', listener), | ||
'close is deprecated. Use stop instead', | ||
); | ||
else | ||
this.ee.off(event, listener); | ||
} | ||
private emit(event: 'close'): void { | ||
private emit(event: 'stop'): void; | ||
private emit(event: 'close'): void; | ||
private emit(event: string): void { | ||
this.ee.emit(event); | ||
@@ -203,2 +222,3 @@ } | ||
private async handleStop(): Promise<void> { | ||
this.emit('stop'); | ||
this.emit('close'); | ||
@@ -205,0 +225,0 @@ await this.stop(); |
@@ -258,3 +258,3 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
const spy = Sinon.spy(); | ||
service.on('close', spy); | ||
service.on('stop', spy); | ||
@@ -271,4 +271,4 @@ await broker.send(`hello.${service.id}.microservice_stop`, ''); | ||
const spy = Sinon.spy(); | ||
service.on('close', spy); | ||
service.off('close', spy); | ||
service.on('stop', spy); | ||
service.off('stop', spy); | ||
@@ -275,0 +275,0 @@ await broker.send(`hello.${service.id}.microservice_stop`, ''); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
417953
7815