1
- using System . Runtime . CompilerServices ;
2
1
using EventStore . Client ;
3
2
using Kurrent . Client . Core . Serialization ;
4
3
@@ -10,10 +9,6 @@ public record StateAtPointInTime<TState>(
10
9
Position ? LastPosition = null
11
10
) where TState : notnull ;
12
11
13
- public record GetStateOptions < TState > where TState : notnull {
14
- public StateAtPointInTime < TState > ? CurrentState { get ; set ; }
15
- }
16
-
17
12
public interface IStateBuilder < TState > where TState : notnull {
18
13
public Task < StateAtPointInTime < TState > > GetAsync (
19
14
IAsyncEnumerable < ResolvedEvent > messages ,
@@ -28,23 +23,6 @@ public interface IState<in TEvent> {
28
23
public void Apply ( TEvent @event ) ;
29
24
}
30
25
31
- public record GetSnapshotOptions {
32
- public string ? StreamName { get ; set ; }
33
-
34
- public string ? SnapshotVersion { get ; set ; }
35
-
36
- public static GetSnapshotOptions ForStream ( string streamName ) =>
37
- new GetSnapshotOptions { StreamName = streamName } ;
38
-
39
- public static GetSnapshotOptions ForAll ( ) =>
40
- new GetSnapshotOptions ( ) ;
41
- }
42
-
43
- public delegate ValueTask < StateAtPointInTime < TState > > GetSnapshot < TState > (
44
- GetSnapshotOptions options ,
45
- CancellationToken ct = default
46
- ) where TState : notnull ;
47
-
48
26
public record StateBuilder < TState > (
49
27
Func < TState , ResolvedEvent , TState > Evolve ,
50
28
Func < TState > GetInitialState
@@ -144,153 +122,3 @@ public static StateBuilder<TState> For<TState>(Func<TState> getInitialState)
144
122
getInitialState
145
123
) ;
146
124
}
147
-
148
- public class GetStreamStateOptions < TState > : ReadStreamOptions where TState : notnull {
149
- public GetSnapshot < TState > ? GetSnapshot { get ; set ; }
150
- }
151
-
152
- public static class KurrentClientGettingStateClientExtensions {
153
- public static async Task < StateAtPointInTime < TState > > GetStateAsync < TState > (
154
- this KurrentClient eventStore ,
155
- string streamName ,
156
- IStateBuilder < TState > stateBuilder ,
157
- GetStreamStateOptions < TState > ? options ,
158
- CancellationToken ct = default
159
- ) where TState : notnull {
160
- StateAtPointInTime < TState > ? stateAtPointInTime = null ;
161
-
162
- options ??= new GetStreamStateOptions < TState > ( ) ;
163
-
164
- if ( options . GetSnapshot != null )
165
- stateAtPointInTime = await options . GetSnapshot (
166
- GetSnapshotOptions . ForStream ( streamName ) ,
167
- ct
168
- ) ;
169
-
170
- options . StreamPosition = stateAtPointInTime ? . LastStreamPosition ?? StreamPosition . Start ;
171
-
172
- return await eventStore . ReadStreamAsync ( streamName , options , ct )
173
- . GetStateAsync ( stateBuilder , ct ) ;
174
- }
175
-
176
- public static async Task < StateAtPointInTime < TState > > GetStateAsync < TState > (
177
- this IAsyncEnumerable < ResolvedEvent > messages ,
178
- TState initialState ,
179
- Func < TState , ResolvedEvent , TState > evolve ,
180
- CancellationToken ct
181
- ) where TState : notnull {
182
- var state = initialState ;
183
-
184
- if ( messages is KurrentClient . ReadStreamResult readStreamResult ) {
185
- if ( await readStreamResult . ReadState . ConfigureAwait ( false ) == ReadState . StreamNotFound )
186
- return new StateAtPointInTime < TState > ( state ) ;
187
- }
188
-
189
- ResolvedEvent ? lastEvent = null ;
190
-
191
- await foreach ( var resolvedEvent in messages . WithCancellation ( ct ) ) {
192
- lastEvent = resolvedEvent ;
193
-
194
- state = evolve ( state , resolvedEvent ) ;
195
- }
196
-
197
- return new StateAtPointInTime < TState > ( state , lastEvent ? . Event . EventNumber , lastEvent ? . Event . Position ) ;
198
- }
199
-
200
- public static Task < StateAtPointInTime < TState > > GetStateAsync < TState > (
201
- this KurrentClient eventStore ,
202
- string streamName ,
203
- IStateBuilder < TState > streamStateBuilder ,
204
- CancellationToken ct = default
205
- ) where TState : notnull =>
206
- eventStore . GetStateAsync ( streamName , streamStateBuilder , new GetStreamStateOptions < TState > ( ) , ct ) ;
207
-
208
- public static Task < StateAtPointInTime < TState > > GetStateAsync < TState , TEvent > (
209
- this KurrentClient eventStore ,
210
- string streamName ,
211
- GetStreamStateOptions < TState > options ,
212
- CancellationToken ct = default
213
- ) where TState : IState < TEvent > , new ( ) =>
214
- eventStore . GetStateAsync (
215
- streamName ,
216
- StateBuilder . For < TState , TEvent > ( ) ,
217
- options ,
218
- ct
219
- ) ;
220
-
221
- public static Task < StateAtPointInTime < TState > > GetStateAsync < TState , TEvent > (
222
- this KurrentClient eventStore ,
223
- string streamName ,
224
- CancellationToken ct = default
225
- ) where TState : IState < TEvent > , new ( ) =>
226
- eventStore . GetStateAsync < TState , TEvent > ( streamName , new GetStreamStateOptions < TState > ( ) , ct ) ;
227
-
228
- public static Task < StateAtPointInTime < TState > > GetStateAsync < TState > (
229
- this KurrentClient eventStore ,
230
- string streamName ,
231
- CancellationToken ct = default
232
- ) where TState : IState < object > , new ( ) =>
233
- eventStore . GetStateAsync < TState , object > ( streamName , new GetStreamStateOptions < TState > ( ) , ct ) ;
234
- }
235
-
236
- public static class KurrentClientGettingStateReadAndSubscribeExtensions {
237
- public static Task < StateAtPointInTime < TState > > GetStateAsync < TState > (
238
- this KurrentClient . ReadStreamResult readStreamResult ,
239
- IStateBuilder < TState > stateBuilder ,
240
- GetStateOptions < TState > options ,
241
- CancellationToken ct = default
242
- ) where TState : notnull =>
243
- stateBuilder . GetAsync ( readStreamResult , options , ct ) ;
244
-
245
- public static Task < StateAtPointInTime < TState > > GetStateAsync < TState > (
246
- this KurrentClient . ReadStreamResult readStreamResult ,
247
- IStateBuilder < TState > stateBuilder ,
248
- CancellationToken ct = default
249
- ) where TState : notnull =>
250
- stateBuilder . GetAsync ( readStreamResult , new GetStateOptions < TState > ( ) , ct ) ;
251
-
252
- public static Task < StateAtPointInTime < TState > > GetStateAsync < TState > (
253
- this KurrentClient . ReadAllStreamResult readAllStreamResult ,
254
- IStateBuilder < TState > stateBuilder ,
255
- GetStateOptions < TState > options ,
256
- CancellationToken ct = default
257
- ) where TState : notnull =>
258
- stateBuilder . GetAsync ( readAllStreamResult , options , ct ) ;
259
-
260
- public static Task < StateAtPointInTime < TState > > GetStateAsync < TState > (
261
- this KurrentClient . ReadAllStreamResult readAllStreamResult ,
262
- IStateBuilder < TState > stateBuilder ,
263
- CancellationToken ct = default
264
- ) where TState : notnull =>
265
- stateBuilder . GetAsync ( readAllStreamResult , new GetStateOptions < TState > ( ) , ct ) ;
266
-
267
- public static Task < StateAtPointInTime < TState > > GetStateAsync < TState > (
268
- this KurrentClient . StreamSubscriptionResult subscriptionResult ,
269
- IStateBuilder < TState > stateBuilder ,
270
- GetStateOptions < TState > options ,
271
- CancellationToken ct = default
272
- ) where TState : notnull =>
273
- stateBuilder . GetAsync ( subscriptionResult , options , ct ) ;
274
-
275
- public static Task < StateAtPointInTime < TState > > GetStateAsync < TState > (
276
- this KurrentClient . StreamSubscriptionResult subscriptionResult ,
277
- IStateBuilder < TState > stateBuilder ,
278
- CancellationToken ct = default
279
- ) where TState : notnull =>
280
- stateBuilder . GetAsync ( subscriptionResult , new GetStateOptions < TState > ( ) , ct ) ;
281
-
282
- public static Task < StateAtPointInTime < TState > > GetStateAsync < TState > (
283
- this KurrentPersistentSubscriptionsClient . PersistentSubscriptionResult subscriptionResult ,
284
- IStateBuilder < TState > stateBuilder ,
285
- GetStateOptions < TState > options ,
286
- CancellationToken ct = default
287
- ) where TState : notnull =>
288
- stateBuilder . GetAsync ( subscriptionResult , options , ct ) ;
289
-
290
- public static Task < StateAtPointInTime < TState > > GetStateAsync < TState > (
291
- this KurrentPersistentSubscriptionsClient . PersistentSubscriptionResult subscriptionResult ,
292
- IStateBuilder < TState > stateBuilder ,
293
- CancellationToken ct = default
294
- ) where TState : notnull =>
295
- stateBuilder . GetAsync ( subscriptionResult , new GetStateOptions < TState > ( ) , ct ) ;
296
- }
0 commit comments