@@ -7,6 +7,28 @@ import * as Nats from 'nats';
77export const Protocols = {
88nats : {
99 /**
10+ * NATS publish operation for \`user.signedup\`
11+ *
12+ * @param message to publish
13+ * @param nc the NATS client to publish from
14+ * @param codec the serialization codec to use while transmitting the message
15+ * @param options to use while publishing the message
16+ */
17+ publishToUserSignedup: (
18+ message : MessageTypeModule .MessageType , nc : Nats .NatsConnection , codec : any = Nats .JSONCodec (), options ?: Nats .PublishOptions
19+ ): Promise <void > => {
20+ return new Promise <void >(async (resolve , reject ) => {
21+ try {
22+ let dataToSend: any = MessageTypeModule .marshal (message );
23+ dataToSend = codec .encode (dataToSend );
24+ nc .publish (' user.signedup' , dataToSend , options );
25+ resolve ();
26+ } catch (e : any ) {
27+ reject (e );
28+ }
29+ });
30+ } ,
31+ /**
1032 * Callback for when receiving messages
1133 *
1234 * @callback subscribeToUserSignedupCallback
@@ -116,6 +138,28 @@ onDataCallback(undefined, MessageTypeModule.unmarshal(receivedData), msg);
116138 reject (e );
117139 }
118140 });
141+ } ,
142+ /**
143+ * JetStream publish operation for \`user.signedup\`
144+ *
145+ * @param message to publish over jetstream
146+ * @param js the JetStream client to publish from
147+ * @param codec the serialization codec to use while transmitting the message
148+ * @param options to use while publishing the message
149+ */
150+ jetStreamPublishToUserSignedup: (
151+ message: MessageTypeModule.MessageType, js: Nats.JetStreamClient, codec: any = Nats.JSONCodec(), options: Partial<Nats.JetStreamPublishOptions > = { }
152+ ): Promise<void > => {
153+ return new Promise <void >(async (resolve , reject ) => {
154+ try {
155+ let dataToSend: any = MessageTypeModule .marshal (message );
156+ dataToSend = codec .encode (dataToSend );
157+ await js .publish (' user.signedup' , dataToSend , options );
158+ resolve ();
159+ } catch (e : any ) {
160+ reject (e );
161+ }
162+ });
119163}
120164}};"
121165`;
@@ -126,6 +170,28 @@ import * as Nats from 'nats';
126170export const Protocols = {
127171nats : {
128172 /**
173+ * NATS publish operation for \`user.signedup\`
174+ *
175+ * @param message to publish
176+ * @param nc the NATS client to publish from
177+ * @param codec the serialization codec to use while transmitting the message
178+ * @param options to use while publishing the message
179+ */
180+ publishToUserSignedup: (
181+ message : MessageTypeModule .MessageType , nc : Nats .NatsConnection , codec : any = Nats .JSONCodec (), options ?: Nats .PublishOptions
182+ ): Promise <void > => {
183+ return new Promise <void >(async (resolve , reject ) => {
184+ try {
185+ let dataToSend: any = MessageTypeModule .marshal (message );
186+ dataToSend = codec .encode (dataToSend );
187+ nc .publish (' user.signedup' , dataToSend , options );
188+ resolve ();
189+ } catch (e : any ) {
190+ reject (e );
191+ }
192+ });
193+ } ,
194+ /**
129195 * Callback for when receiving messages
130196 *
131197 * @callback subscribeToUserSignedupCallback
@@ -235,6 +301,28 @@ onDataCallback(undefined, MessageTypeModule.unmarshal(receivedData), msg);
235301 reject (e );
236302 }
237303 });
304+ } ,
305+ /**
306+ * JetStream publish operation for \`user.signedup\`
307+ *
308+ * @param message to publish over jetstream
309+ * @param js the JetStream client to publish from
310+ * @param codec the serialization codec to use while transmitting the message
311+ * @param options to use while publishing the message
312+ */
313+ jetStreamPublishToUserSignedup: (
314+ message: MessageTypeModule.MessageType, js: Nats.JetStreamClient, codec: any = Nats.JSONCodec(), options: Partial<Nats.JetStreamPublishOptions > = { }
315+ ): Promise<void > => {
316+ return new Promise <void >(async (resolve , reject ) => {
317+ try {
318+ let dataToSend: any = MessageTypeModule .marshal (message );
319+ dataToSend = codec .encode (dataToSend );
320+ await js .publish (' user.signedup' , dataToSend , options );
321+ resolve ();
322+ } catch (e : any ) {
323+ reject (e );
324+ }
325+ });
238326}
239327}};"
240328`;
@@ -245,6 +333,28 @@ import * as Nats from 'nats';
245333export const Protocols = {
246334nats : {
247335 /**
336+ * NATS publish operation for \`ping\`
337+ *
338+ * @param message to publish
339+ * @param nc the NATS client to publish from
340+ * @param codec the serialization codec to use while transmitting the message
341+ * @param options to use while publishing the message
342+ */
343+ publishToPing: (
344+ message : MessageTypeModule .MessageType , nc : Nats .NatsConnection , codec : any = Nats .JSONCodec (), options ?: Nats .PublishOptions
345+ ): Promise <void > => {
346+ return new Promise <void >(async (resolve , reject ) => {
347+ try {
348+ let dataToSend: any = MessageTypeModule .marshal (message );
349+ dataToSend = codec .encode (dataToSend );
350+ nc .publish (' ping' , dataToSend , options );
351+ resolve ();
352+ } catch (e : any ) {
353+ reject (e );
354+ }
355+ });
356+ } ,
357+ /**
248358 * Callback for when receiving messages
249359 *
250360 * @callback subscribeToPingCallback
@@ -356,47 +466,22 @@ onDataCallback(undefined, MessageTypeModule.unmarshal(receivedData), msg);
356466 });
357467} ,
358468/**
359- * Callback for when receiving the request
360- *
361- * @callback replyToPingCallback
362- * @param err if any error occurred this will be sat
363- * @param requestMessage that was received from the request
364- */
365-
366- /**
367- * Reply for \`ping\`
469+ * JetStream publish operation for \`ping\`
368470 *
369- * @param { replyToPingCallback } onDataCallback to call when the request is received
370- * @param nc the nats client to setup the reply for
371- * @param codec the serialization codec to use when receiving and transmitting reply
372- * @param options when setting up the reply
471+ * @param message to publish over jetstream
472+ * @param js the JetStream client to publish from
473+ * @param codec the serialization codec to use while transmitting the message
474+ * @param options to use while publishing the message
373475 */
374- replyToPing: (
375- onDataCallback: (err?: Error, requestMessage?: MessageTypeModule.MessageType) => MessageTypeModule | Promise<MessageTypeModule >,
376- nc: Nats.NatsConnection,
377- codec: any = Nats.JSONCodec(),
378- options?: Nats.SubscriptionOptions
379- ): Promise<Nats.Subscription > => {
380- return new Promise (async (resolve , reject ) => {
476+ jetStreamPublishToPing: (
477+ message: MessageTypeModule.MessageType, js: Nats.JetStreamClient, codec: any = Nats.JSONCodec(), options: Partial<Nats.JetStreamPublishOptions > = { }
478+ ): Promise<void > => {
479+ return new Promise <void >(async (resolve , reject ) => {
381480 try {
382- let subscription = nc .subscribe (' ping' , options );
383- (async () => {
384- for await (const msg of subscription ) {
385-
386-
387- let receivedData : any = codec .decode (msg .data );
388- const replyMessage = await onDataCallback (undefined , MessageTypeModule .unmarshal (receivedData ) );
389-
390- if (msg .reply ) {
391- let dataToSend : any = replyMessage .marshal ();
481+ let dataToSend: any = MessageTypeModule .marshal (message );
392482dataToSend = codec .encode (dataToSend );
393- msg .respond (dataToSend );
394- } else {
395- onDataCallback (new Error (' Expected request to need a reply, did not..' ))
396- }
397- }
398- })();
399- resolve (subscription );
483+ await js .publish (' ping' , dataToSend , options );
484+ resolve ();
400485 } catch (e : any ) {
401486 reject (e );
402487 }
0 commit comments