Skip to content

Commit

Permalink
Create includeDeleteEvents to subcribe options (default: true) in ord…
Browse files Browse the repository at this point in the history
…er to make it optional
  • Loading branch information
Sandro committed Dec 10, 2023
1 parent 99a7354 commit 291b9ec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const customSubscription = client.subscribe(
},
{
includeCreateEvents: true,
includeDeleteEvents: true,
subscribeAction: 'subscribe_all',
unsubscribeAction: 'unsubscribe_all',
},
Expand Down
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export type SubscribeOptions = {
subscribeAction?: string,
unsubscribeAction?: string,
includeCreateEvents?: boolean,
includeDeleteEvents?: boolean,
}

export type SubscriptionAction = 'create' | 'update' | 'delete';
Expand Down

0 comments on commit 291b9ec

Please sign in to comment.