From 291b9ecfdb25fc1b0801aab2a82560dc2942a64b Mon Sep 17 00:00:00 2001 From: Sandro Date: Sat, 9 Dec 2023 22:38:12 -0300 Subject: [PATCH] Create includeDeleteEvents to subcribe options (default: true) in order to make it optional --- README.md | 1 + src/index.ts | 13 +++++++++---- src/interface.ts | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8f80949..b518bed 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ const customSubscription = client.subscribe( }, { includeCreateEvents: true, + includeDeleteEvents: true, subscribeAction: 'subscribe_all', unsubscribeAction: 'unsubscribe_all', }, diff --git a/src/index.ts b/src/index.ts index 4ec7cee..5c60403 100644 --- a/src/index.ts +++ b/src/index.ts @@ -306,6 +306,7 @@ export class DCRFClient implements IStreamingAPI { options = options ?? {}; options.includeCreateEvents = options.includeCreateEvents ?? false; + options.includeDeleteEvents = options.includeDeleteEvents ?? true; options.requestId = options.requestId ?? UUID.generate(); options.subscribeAction = options.subscribeAction ?? "subscribe_instance"; options.unsubscribeAction = @@ -322,10 +323,8 @@ export class DCRFClient implements IStreamingAPI { const requestId = options.requestId; - const createSelector = this.buildSubscribeCreateSelector(stream, requestId); const updateSelector = this.buildSubscribeUpdateSelector(stream, requestId); - const deleteSelector = this.buildSubscribeDeleteSelector(stream, requestId); - + const handler: ( data: typeof updateSelector & { payload: { data: any; action: string } } ) => void = this.buildSubscribeListener(callback); @@ -362,8 +361,14 @@ export class DCRFClient implements IStreamingAPI { }; addListener(updateSelector); - addListener(deleteSelector); + + if (options.includeDeleteEvents) { + const deleteSelector = this.buildSubscribeDeleteSelector(stream, requestId); + addListener(deleteSelector); + } + if (options.includeCreateEvents) { + const createSelector = this.buildSubscribeCreateSelector(stream, requestId); addListener(createSelector); } diff --git a/src/interface.ts b/src/interface.ts index ddf9885..f5a8c7c 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -177,6 +177,7 @@ export type SubscribeOptions = { subscribeAction?: string, unsubscribeAction?: string, includeCreateEvents?: boolean, + includeDeleteEvents?: boolean, } export type SubscriptionAction = 'create' | 'update' | 'delete';