Skip to content

Commit

Permalink
feat: support start time in read changes request
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpq committed Feb 6, 2025
1 parent 2061130 commit eac70e1
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ Reads the list of historical relationship tuple writes and deletes.
[API Documentation](https://openfga.dev/api/service#/Relationship%20Tuples/ReadChanges)

```csharp
var body = new ClientReadChangesRequest { Type = "document" };
var startTime = DateTime.Parse("2022-01-01T00:00:00Z");
var body = new ClientReadChangesRequest { Type = "document", StartTime = startTime };
var options = new ClientReadChangesOptions {
PageSize = 10,
ContinuationToken = "...",
Expand Down
6 changes: 4 additions & 2 deletions docs/OpenFgaApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ Name | Type | Description | Notes

<a name="readchanges"></a>
# **ReadChanges**
> ReadChangesResponse ReadChanges (string? type = null, int? pageSize = null, string? continuationToken = null)
> ReadChangesResponse ReadChanges (string? type = null, int? pageSize = null, string? continuationToken = null, DateTime? startTime = null)
Return a list of all the tuple changes

Expand Down Expand Up @@ -1023,11 +1023,12 @@ namespace Example
var type = "type_example"; // string? | (optional)
var pageSize = 56; // int? | (optional)
var continuationToken = "continuationToken_example"; // string? | (optional)
var startTime = DateTime.Parse("2013-10-20T19:20:30+01:00"); // DateTime? | Start date and time of changes to read. Format: ISO 8601 timestamp (e.g., 2022-01-01T00:00:00Z) If a continuation_token is provided along side start_time, the continuation_token will take precedence over start_time. (optional)
try
{
// Return a list of all the tuple changes
ReadChangesResponse response = await openFgaApi.ReadChanges(type, pageSize, continuationToken);
ReadChangesResponse response = await openFgaApi.ReadChanges(type, pageSize, continuationToken, startTime);
Debug.WriteLine(response);
}
catch (ApiException e)
Expand All @@ -1049,6 +1050,7 @@ Name | Type | Description | Notes
**type** | **string?**| | [optional]
**pageSize** | **int?**| | [optional]
**continuationToken** | **string?**| | [optional]
**startTime** | **DateTime?**| Start date and time of changes to read. Format: ISO 8601 timestamp (e.g., 2022-01-01T00:00:00Z) If a continuation_token is provided along side start_time, the continuation_token will take precedence over start_time. | [optional]

### Return type

Expand Down
3 changes: 2 additions & 1 deletion src/OpenFga.Sdk.Test/Api/OpenFgaApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1702,8 +1702,9 @@ public async Task ReadChangesTest() {

var type = "repo";
var pageSize = 25;
var startTime = DateTime.Parse("2022-01-01T00:00:00Z");
var continuationToken = "eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ==";
var response = await openFgaApi.ReadChanges(_storeId, type, pageSize, continuationToken);
var response = await openFgaApi.ReadChanges(_storeId, type, pageSize, continuationToken, startTime);

mockHandler.Protected().Verify(
"SendAsync",
Expand Down
3 changes: 2 additions & 1 deletion src/OpenFga.Sdk.Test/Client/OpenFgaClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,10 @@ public async Task ReadChangesTest() {

var type = "repo";
var pageSize = 25;
var startTime = DateTime.Parse("2022-01-01T00:00:00Z");
var continuationToken =
"eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ==";
var response = await fgaClient.ReadChanges(new ClientReadChangesRequest { Type = type }, new ClientReadChangesOptions {
var response = await fgaClient.ReadChanges(new ClientReadChangesRequest { Type = type, StartTime = startTime }, new ClientReadChangesOptions {
PageSize = pageSize,
ContinuationToken = continuationToken,
});
Expand Down
6 changes: 5 additions & 1 deletion src/OpenFga.Sdk/Api/OpenFgaApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,10 @@ public async Task<ReadAuthorizationModelResponse> ReadAuthorizationModel(string
/// <param name="type"> (optional)</param>
/// <param name="pageSize"> (optional)</param>
/// <param name="continuationToken"> (optional)</param>
/// <param name="startTime">Start date and time of changes to read. Format: ISO 8601 timestamp (e.g., 2022-01-01T00:00:00Z) If a continuation_token is provided along side start_time, the continuation_token will take precedence over start_time. (optional)</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of ReadChangesResponse</returns>
public async Task<ReadChangesResponse> ReadChanges(string storeId, string? type = default(string?), int? pageSize = default(int?), string? continuationToken = default(string?), CancellationToken cancellationToken = default) {
public async Task<ReadChangesResponse> ReadChanges(string storeId, string? type = default(string?), int? pageSize = default(int?), string? continuationToken = default(string?), DateTime? startTime = default(DateTime?), CancellationToken cancellationToken = default) {
var pathParams = new Dictionary<string, string> { };
if (string.IsNullOrWhiteSpace(storeId)) {
throw new FgaRequiredParamError("ReadChanges", "StoreId");
Expand All @@ -446,6 +447,9 @@ public async Task<ReadAuthorizationModelResponse> ReadAuthorizationModel(string
if (continuationToken != null) {
queryParams.Add("continuation_token", continuationToken.ToString());
}
if (startTime != null) {
queryParams.Add("start_time", startTime.ToString());
}

var requestBuilder = new RequestBuilder<Any> {
Method = new HttpMethod("GET"),
Expand Down
4 changes: 2 additions & 2 deletions src/OpenFga.Sdk/Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ public async Task<ReadAuthorizationModelResponse> ReadAuthorizationModel(
* Read Changes - Read the list of historical relationship tuple writes and deletes
*/
public async Task<ReadChangesResponse> ReadChanges(ClientReadChangesRequest? body = default,
IClientReadChangesOptions? options = default,
ClientReadChangesOptions? options = default,
CancellationToken cancellationToken = default) =>
await api.ReadChanges(GetStoreId(options), body?.Type, options?.PageSize, options?.ContinuationToken, cancellationToken);
await api.ReadChanges(GetStoreId(options), body?.Type, options?.PageSize, options?.ContinuationToken, body?.StartTime, cancellationToken);

/**
* Read - Read tuples previously written to the store (does not evaluate)
Expand Down
2 changes: 2 additions & 0 deletions src/OpenFga.Sdk/Client/Model/ClientReadChangesRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ namespace OpenFga.Sdk.Client.Model;

public interface IClientReadChangesRequest {
string Type { get; set; }
DateTime? StartTime { get; set; }
}

public class ClientReadChangesRequest : IClientReadChangesRequest, IEquatable<ClientReadChangesRequest>,
IValidatableObject {
public string Type { get; set; }
public DateTime? StartTime { get; set; }

public bool Equals(ClientReadChangesRequest input) {
if (input == null) {
Expand Down
8 changes: 7 additions & 1 deletion src/OpenFga.Sdk/Model/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,13 @@ public enum ErrorCode {
/// Enum Cancelled for value: cancelled
/// </summary>
[EnumMember(Value = "cancelled")]
Cancelled = 49
Cancelled = 49,

/// <summary>
/// Enum InvalidStartTime for value: invalid_start_time
/// </summary>
[EnumMember(Value = "invalid_start_time")]
InvalidStartTime = 50

}

Expand Down

0 comments on commit eac70e1

Please sign in to comment.