Skip to content

Commit

Permalink
Used eventTypeFilter and streamNameFilter helper methods in server si…
Browse files Browse the repository at this point in the history
…de filtering samples
  • Loading branch information
oskardudycz committed Dec 28, 2020
1 parent c58bf5c commit 1408dcf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions samples/grpc/nodejs/samples/appending-events/index.js
Expand Up @@ -114,7 +114,7 @@ export async function appendWithConcurrencyCheck(client) {
// endregion append-with-concurrency-check
}

export async function appendWithNoStreamOverridingCredentials(client) {
export async function appendWithNoStreamOverridingCredentials(client) {
const event = jsonEvent({
id: uuid(),
eventType: "some-event",
Expand All @@ -129,7 +129,7 @@ export async function appendWithNoStreamOverridingCredentials(client) {
password: "changeit",
};
await client.appendToStream("some-stream", event, {
credentials
credentials,
});
// endregion overriding-user-credentials
}
}
23 changes: 15 additions & 8 deletions samples/grpc/nodejs/samples/server-side-filtering/index.js
@@ -1,12 +1,16 @@
import { START, STREAM_NAME, EVENT_TYPE } from "@eventstore/db-client";
import {
START,
eventTypeFilter,
streamNameFilter,
} from "@eventstore/db-client";

export async function subscribeToAllExcludeSystemEvents(client) {
// region exclude-system
const excludeSystemEventsRegex = /^[^\$].*/;
const subscription = client
.subscribeToAll({
fromRevision: START,
filter: { filterOn: EVENT_TYPE, regex: excludeSystemEventsRegex },
filter: eventTypeFilter({ regex: excludeSystemEventsRegex }),
})
.on("data", function (resolvedEvent) {
console.log(
Expand All @@ -19,7 +23,7 @@ export async function subscribeToAllExcludeSystemEvents(client) {
export async function subscribeToAllFilteringByEventTypePrefix(client) {
// region event-type-prefix
const prefixes = ["customer-"];
const filter = { filterOn: EVENT_TYPE, prefixes };
const filter = eventTypeFilter({ prefixes });
// endregion event-type-prefix
const subscription = client
.subscribeToAll({
Expand All @@ -32,7 +36,7 @@ export async function subscribeToAllFilteringByEventTypePrefix(client) {
export async function subscribeToAllFilteringByEventTypeRegex(client) {
// region event-type-regex
const regex = /^user|^company/;
const filter = { filterOn: EVENT_TYPE, regex };
const filter = eventTypeFilter({ regex });
// endregion event-type-regex
const subscription = client
.subscribeToAll({
Expand All @@ -45,7 +49,7 @@ export async function subscribeToAllFilteringByEventTypeRegex(client) {
export async function subscribeToAllFilteringByStreamPrefix(client) {
// region stream-prefix
const prefixes = ["user-"];
const filter = { filterOn: STREAM_NAME, prefixes };
const filter = streamNameFilter({ prefixes });
// endregion stream-prefix
const subscription = client
.subscribeToAll({
Expand All @@ -58,7 +62,7 @@ export async function subscribeToAllFilteringByStreamPrefix(client) {
export async function subscribeToAllFilteringByStreamRegex(client) {
// region stream-regex
const regex = /^account|^savings/;
const filter = { filterOn: STREAM_NAME, regex };
const filter = streamNameFilter({ regex });
// endregion stream-regex
const subscription = client
.subscribeToAll({
Expand Down Expand Up @@ -92,11 +96,14 @@ export async function subscribeToAllFilteringByStreamRegex(client) {
export async function subscribeToAllWithCheckpointInterval(client) {
// region checkpoint-with-interval
const excludeSystemEventsRegex = /^[^\$].*/;
const filter = { filterOn: EVENT_TYPE, checkpointIntervalMul: 1000, regex };
const filter = eventTypeFilter({
checkpointIntervalMul: 1000,
regex: excludeSystemEventsRegex,
});
// endregion checkpoint-with-interval
const subscription = client
.subscribeToStream({
filter: { filterOn: STREAM_NAME, regex },
filter: streamNameFilter({ regex }),
})
.on("data", handleEvent);
}
Expand Down

0 comments on commit 1408dcf

Please sign in to comment.