Fauna v10 .NET/C# Driver 1.0.1
 
Loading...
Searching...
No Matches
FeedPage.cs
Go to the documentation of this file.
1using System.Text.Json;
3using Fauna.Mapping;
4using Fauna.Types;
5using static Fauna.Core.ResponseFields;
6
7namespace Fauna.Core;
8
13public class FeedPage<T> where T : notnull
14{
18 public List<Event<T>> Events { get; private init; } = [];
19
23 public string Cursor { get; private init; } = null!;
24
28 public bool HasNext { get; private init; }
29
33 public QueryStats Stats { get; private init; }
34
35 internal static FeedPage<T> From(string body, MappingContext ctx)
36 {
37 var json = JsonSerializer.Deserialize<JsonElement>(body);
38
39 var err = GetError(json);
40 if (err != null)
41 {
42 throw new FaunaException(err.Value);
43 }
44
45 return new FeedPage<T>
46 {
47 Cursor = GetCursor(json),
48 Events = GetEvents(json, ctx),
49 Stats = GetStats(json),
50 HasNext = json.TryGetProperty(HasNextFieldName, out var elem) && elem.GetBoolean()
51 };
52 }
53
54 private static List<Event<T>> GetEvents(JsonElement json, MappingContext ctx)
55 {
56 if (!json.TryGetProperty(EventsFieldName, out var elem))
57 {
58 return new List<Event<T>>();
59 }
60
61 var events = elem.EnumerateArray().Select(e => Event<T>.From(e, ctx)).ToList();
62 return events;
63 }
64
65 private static QueryStats GetStats(JsonElement json)
66 {
67 return json.TryGetProperty(StatsFieldName, out var elem) ? elem.Deserialize<QueryStats>() : default;
68 }
69
70 private static string GetCursor(JsonElement json)
71 {
72 return json.TryGetProperty(CursorFieldName, out var elem) ? elem.GetString()! : null!;
73 }
74
75 private static ErrorInfo? GetError(JsonElement json)
76 {
77 return json.TryGetProperty(ErrorFieldName, out var elem) ? elem.Deserialize<ErrorInfo>() : null;
78 }
79}
Represents the response from Fauna Event Feed requests.
Definition FeedPage.cs:14
List< Event< T > > Events
List of Events returned by the Feed.
Definition FeedPage.cs:18
bool HasNext
Indicates if there are more pages for pagination.
Definition FeedPage.cs:28
string Cursor
Cursor returned from the Feed.
Definition FeedPage.cs:23
QueryStats Stats
Stats returned from the Feed.
Definition FeedPage.cs:33
Represents the base exception class for all exceptions specific to Fauna interactions.
A class representing the mapping context to be used during serialization and deserialization.
A class representing an event from an Event Feed or Event Stream.
Definition Event.cs:39
A struct representing stats aggregated across queries.