Skip to content

Commit b539be2

Browse files
committed
[DEVEX-222] Made Read options nullable, to precisely know if user provided options or not
1 parent 7815a6f commit b539be2

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

src/KurrentDB.Client/Streams/KurrentDBClient.Read.cs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ public ReadAllStreamResult ReadAllAsync(
2828
ReadDirection = options.Direction switch {
2929
Direction.Backwards => ReadReq.Types.Options.Types.ReadDirection.Backwards,
3030
Direction.Forwards => ReadReq.Types.Options.Types.ReadDirection.Forwards,
31-
_ => throw InvalidOption(options.Direction)
31+
null => ReadReq.Types.Options.Types.ReadDirection.Forwards,
32+
_ => throw InvalidOption(options.Direction.Value)
3233
},
33-
ResolveLinks = options.ResolveLinkTos,
34+
ResolveLinks = options.ResolveLinkTos ?? false,
3435
All = new() {
3536
Position = new() {
36-
CommitPosition = options.Position.CommitPosition,
37-
PreparePosition = options.Position.PreparePosition
37+
CommitPosition = (options.Position ?? Position.Start).CommitPosition,
38+
PreparePosition = (options.Position ?? Position.Start).PreparePosition
3839
}
3940
},
40-
Count = (ulong)options.MaxCount,
41+
Count = (ulong)(options.MaxCount ?? long.MaxValue),
4142
UuidOption = new() { Structured = new() },
4243
ControlOption = new() { Compatibility = 1 },
4344
Filter = GetFilterOptions(options.Filter)
@@ -213,14 +214,15 @@ public ReadStreamResult ReadStreamAsync(
213214
ReadDirection = options.Direction switch {
214215
Direction.Backwards => ReadReq.Types.Options.Types.ReadDirection.Backwards,
215216
Direction.Forwards => ReadReq.Types.Options.Types.ReadDirection.Forwards,
216-
_ => throw InvalidOption(options.Direction)
217+
null => ReadReq.Types.Options.Types.ReadDirection.Forwards,
218+
_ => throw InvalidOption(options.Direction.Value)
217219
},
218-
ResolveLinks = options.ResolveLinkTos,
220+
ResolveLinks = options.ResolveLinkTos ?? false,
219221
Stream = ReadReq.Types.Options.Types.StreamOptions.FromStreamNameAndRevision(
220222
streamName,
221-
options.StreamPosition
223+
options.StreamPosition ?? StreamPosition.Start
222224
),
223-
Count = (ulong)options.MaxCount,
225+
Count = (ulong)(options.MaxCount ?? long.MaxValue),
224226
UuidOption = new() { Structured = new() },
225227
NoFilter = new(),
226228
ControlOption = new() { Compatibility = 1 }
@@ -443,29 +445,29 @@ IMessageSerializer messageSerializer
443445
/// </summary>
444446
public class ReadAllOptions : OperationOptions {
445447
/// <summary>
446-
/// The <see cref="Direction"/> in which to read.
448+
/// The <see cref="Direction"/> in which to read. When not provided Forwards is used.
447449
/// </summary>
448-
public Direction Direction { get; set; } = Direction.Forwards;
450+
public Direction? Direction { get; set; }
449451

450452
/// <summary>
451-
/// The <see cref="Position"/> to start reading from.
453+
/// The <see cref="Position"/> to start reading from. When not provided Start is used.
452454
/// </summary>
453-
public Position Position { get; set; } = Position.Start;
455+
public Position? Position { get; set; }
454456

455457
/// <summary>
456458
/// The <see cref="IEventFilter"/> to apply.
457459
/// </summary>
458460
public IEventFilter? Filter { get; set; }
459461

460462
/// <summary>
461-
/// The number of events to read from the stream.
463+
/// The number of events to read from the stream. When not provided, no limit is set.
462464
/// </summary>
463-
public long MaxCount { get; set; } = long.MaxValue;
465+
public long? MaxCount { get; set; }
464466

465467
/// <summary>
466-
/// Whether to resolve LinkTo events automatically.
468+
/// Whether to resolve LinkTo events automatically. When not provided, false is used.
467469
/// </summary>
468-
public bool ResolveLinkTos { get; set; }
470+
public bool? ResolveLinkTos { get; set; }
469471

470472
/// <summary>
471473
/// Allows to customize or disable the automatic deserialization
@@ -476,7 +478,7 @@ public static ReadAllOptions Get() =>
476478
new ReadAllOptions();
477479

478480
public ReadAllOptions Forwards() {
479-
Direction = Direction.Forwards;
481+
Direction = KurrentDB.Client.Direction.Forwards;
480482

481483
return this;
482484
}
@@ -488,7 +490,7 @@ public ReadAllOptions WithFilter(IEventFilter filter) {
488490
}
489491

490492
public ReadAllOptions Backwards() {
491-
Direction = Direction.Backwards;
493+
Direction = KurrentDB.Client.Direction.Backwards;
492494

493495
return this;
494496
}
@@ -500,10 +502,10 @@ public ReadAllOptions From(Position streamPosition) {
500502
}
501503

502504
public ReadAllOptions FromStart() =>
503-
From(Position.Start);
505+
From(KurrentDB.Client.Position.Start);
504506

505507
public ReadAllOptions FromEnd() =>
506-
From(Position.End);
508+
From(KurrentDB.Client.Position.End);
507509

508510
public ReadAllOptions WithMaxCount(long maxCount) {
509511
MaxCount = maxCount;
@@ -539,22 +541,22 @@ public class ReadStreamOptions : OperationOptions {
539541
/// <summary>
540542
/// The <see cref="Direction"/> in which to read.
541543
/// </summary>
542-
public Direction Direction { get; set; } = Direction.Forwards;
544+
public Direction? Direction { get; set; }
543545

544546
/// <summary>
545547
/// The <see cref="Client.StreamRevision"/> to start reading from.
546548
/// </summary>
547-
public StreamPosition StreamPosition { get; set; } = StreamPosition.Start;
549+
public StreamPosition? StreamPosition { get; set; }
548550

549551
/// <summary>
550552
/// The number of events to read from the stream.
551553
/// </summary>
552-
public long MaxCount { get; set; } = long.MaxValue;
554+
public long? MaxCount { get; set; }
553555

554556
/// <summary>
555557
/// Whether to resolve LinkTo events automatically.
556558
/// </summary>
557-
public bool ResolveLinkTos { get; set; }
559+
public bool? ResolveLinkTos { get; set; }
558560

559561
/// <summary>
560562
/// Allows to customize or disable the automatic deserialization
@@ -565,13 +567,13 @@ public static ReadStreamOptions Get() =>
565567
new ReadStreamOptions();
566568

567569
public ReadStreamOptions Forwards() {
568-
Direction = Direction.Forwards;
570+
Direction = KurrentDB.Client.Direction.Forwards;
569571

570572
return this;
571573
}
572574

573575
public ReadStreamOptions Backwards() {
574-
Direction = Direction.Backwards;
576+
Direction = KurrentDB.Client.Direction.Backwards;
575577

576578
return this;
577579
}
@@ -583,10 +585,10 @@ public ReadStreamOptions From(StreamPosition streamPosition) {
583585
}
584586

585587
public ReadStreamOptions FromStart() =>
586-
From(StreamPosition.Start);
588+
From(KurrentDB.Client.StreamPosition.Start);
587589

588590
public ReadStreamOptions FromEnd() =>
589-
From(StreamPosition.End);
591+
From(KurrentDB.Client.StreamPosition.End);
590592

591593
public ReadStreamOptions WithMaxCount(long maxCount) {
592594
MaxCount = maxCount;

0 commit comments

Comments
 (0)