NFIBrokerage / spear

A sharp EventStoreDB v20+ client backed by Mint :yum:
https://hex.pm/packages/spear
Apache License 2.0
85 stars 14 forks source link

add :filter support to stream!/3 and read_stream/3 #56

Closed the-mikedavis closed 3 years ago

the-mikedavis commented 3 years ago

requires #55 requires https://github.com/EventStore/EventStore/pull/3133

allows one to pass a server-side filter when doing non-subscription stream reads, like so:

iex> Spear.stream!(conn, :all) |> Enum.count
20
iex> Spear.stream!(conn, :all, filter: Spear.Filter.exclude_system_types()) |> Enum.count
0

iex> import Spear.Filter
iex> filter = ~f[$projections-]ps
%Spear.Filter{by: ["$projections-"], checkpoint_after: 1024, on: :stream_name}
iex> Spear.stream!(conn, :all, filter: filter) |> Enum.count
11
iex> Spear.stream!(conn, :all, filter: filter) |> Enum.map(& &1.metadata.stream_name) |> Enum.uniq
["$projections-$all", "$projections-$by_event_type", "$projections-$streams",
 "$projections-$stream_by_category", "$projections-$by_category",
 "$projections-$by_correlation_id"]

iex> forward = Spear.stream!(conn, :all, filter: filter)
iex> backward = Spear.stream!(conn, :all, filter: filter, direction: :backwards, from: :end)
iex> Enum.to_list(forwards) == Enum.reverse(backwards)
true

This allows use to properly implement back-pressure to a filtered :all subscription in Volley.InOrderSubscription.

This feature awaits the next EventStoreDB release.