@nestjs-plugins/nestjs-nats-jetstream-transport
Advanced tools
Comparing version 1.4.4 to 2.0.0
import { ClientProxy, ReadPacket, WritePacket } from '@nestjs/microservices'; | ||
import { NatsConnection } from 'nats'; | ||
import { NatsJetStreamClientOptions } from './interfaces/nats-jetstream-client-options.interface'; | ||
import { NatsJetStreamRecord } from './utils/nats-jetstream-record.builder'; | ||
export declare class NatsJetStreamClientProxy extends ClientProxy { | ||
@@ -12,3 +13,3 @@ private options; | ||
protected publish(packet: ReadPacket, callback: (packet: WritePacket) => void): () => void; | ||
protected dispatchEvent(packet: ReadPacket): Promise<any>; | ||
protected dispatchEvent(packet: ReadPacket<NatsJetStreamRecord>): Promise<any>; | ||
} |
@@ -20,2 +20,4 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
const nats_jetstream_record_builder_1 = require("./utils/nats-jetstream-record.builder"); | ||
const nats_request_record_builder_1 = require("./utils/nats-request-record-builder"); | ||
let NatsJetStreamClientProxy = class NatsJetStreamClientProxy extends microservices_1.ClientProxy { | ||
@@ -41,20 +43,40 @@ constructor(options) { | ||
publish(packet, callback) { | ||
const payload = this.codec.encode(packet.data); | ||
const subject = this.normalizePattern(packet.pattern); | ||
this.nc | ||
.request(subject, payload) | ||
.then((msg) => this.codec.decode(msg.data)) | ||
.then((packet) => callback(packet)) | ||
.catch((err) => { | ||
callback({ err }); | ||
}); | ||
return () => null; | ||
if (packet.data instanceof nats_request_record_builder_1.NatsRequestRecord) { | ||
const options = packet.data.options; | ||
const payload = this.codec.encode(packet.data.payload); | ||
this.nc | ||
.request(subject, payload, options) | ||
.then((msg) => this.codec.decode(msg.data)) | ||
.then((packet) => callback(packet)) | ||
.catch((err) => { | ||
callback({ err }); | ||
}); | ||
return () => null; | ||
} | ||
else { | ||
const payload = this.codec.encode(packet.data); | ||
this.nc | ||
.request(subject, payload) | ||
.then((msg) => this.codec.decode(msg.data)) | ||
.then((packet) => callback(packet)) | ||
.catch((err) => { | ||
callback({ err }); | ||
}); | ||
return () => null; | ||
} | ||
} | ||
async dispatchEvent(packet) { | ||
const payload = this.codec.encode(packet.data); | ||
const subject = this.normalizePattern(packet.pattern); | ||
const jetStreamOpts = this.options.jetStreamOption; | ||
const jetStreamPublishOpts = this.options.jetStreamPublishOptions; | ||
const js = this.nc.jetstream(jetStreamOpts); | ||
return js.publish(subject, payload, jetStreamPublishOpts); | ||
if (packet.data instanceof nats_jetstream_record_builder_1.NatsJetStreamRecord) { | ||
const payload = this.codec.encode(packet.data.payload); | ||
const options = packet.data.options; | ||
return js.publish(subject, payload, options); | ||
} | ||
else { | ||
const payload = this.codec.encode(packet.data); | ||
return js.publish(subject, payload); | ||
} | ||
} | ||
@@ -61,0 +83,0 @@ }; |
@@ -12,1 +12,3 @@ export * from './server'; | ||
export * from './nats-jetstream.context'; | ||
export * from './utils/nats-jetstream-record.builder'; | ||
export * from './utils/nats-request-record-builder'; |
@@ -28,2 +28,4 @@ "use strict"; | ||
__exportStar(require("./nats-jetstream.context"), exports); | ||
__exportStar(require("./utils/nats-jetstream-record.builder"), exports); | ||
__exportStar(require("./utils/nats-request-record-builder"), exports); | ||
//# sourceMappingURL=index.js.map |
import { ModuleMetadata } from '@nestjs/common'; | ||
import { ConnectionOptions, JetStreamOptions, JetStreamPublishOptions } from 'nats'; | ||
import { ConnectionOptions, JetStreamOptions } from 'nats'; | ||
import { NatsConnectionOptions } from './nats-connection-options.interface'; | ||
@@ -7,3 +7,2 @@ export interface NatsJetStreamClientOptions { | ||
jetStreamOption?: JetStreamOptions; | ||
jetStreamPublishOptions?: JetStreamPublishOptions; | ||
} | ||
@@ -10,0 +9,0 @@ export interface NatsJetStreamClientAsyncOptions extends Pick<ModuleMetadata, 'imports'> { |
@@ -10,3 +10,3 @@ import { CustomTransportStrategy, Server } from '@nestjs/microservices'; | ||
constructor(options: NatsJetStreamServerOptions); | ||
listen(callback: () => null): Promise<void>; | ||
listen(callback: () => void): Promise<void>; | ||
close(): Promise<void>; | ||
@@ -13,0 +13,0 @@ private bindEventHandlers; |
{ | ||
"name": "@nestjs-plugins/nestjs-nats-jetstream-transport", | ||
"version": "1.4.4", | ||
"version": "2.0.0", | ||
"description": "Nats JetStream Transport for NestJS", | ||
@@ -51,3 +51,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "a9a2ca123d6b5e4eb59af5a34897365b403c076a" | ||
"gitHead": "9436ea4bcb1c1645ed723607696e4a4a746f4dca" | ||
} |
@@ -69,3 +69,2 @@ # ๐ Nats JetStream Transport Module for NestJS | ||
- **jetStreamOptions**: JetStreamOptions | ||
- **jetStreamPublishOptions**: JetStreamPublishOptions | ||
@@ -72,0 +71,0 @@ ### ServerConsumerOptions |
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
180268
46
572
361