Skip to content

Commit 33a8520

Browse files
authored
feat: Streamed List Objects support ( consumer callback ) (#252)
* feat: add OpenAPI generated model and api layer * feat: add OpenAPI generated model and api layer * feat: initialise consumer Callback replace streams * feat: stuff * feat: update example gradle file * feat: config override * fix: remove unnecessary thread spawn * feat: fix exceptions * feat: stream error null checks * Delete STREAMING_OPTIMIZATION.md * feat: add changelog entry * feat: address and accomodate ffeedback: * feat: update build gradle jar version for example * feat: synch examples with dotnet example * feat: use DSL transformer, constants * feat: useDSL transformer, address comments
1 parent d93032f commit 33a8520

File tree

23 files changed

+2298
-0
lines changed

23 files changed

+2298
-0
lines changed

.openapi-generator/FILES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ docs/RelationshipCondition.md
6767
docs/SourceInfo.md
6868
docs/Status.md
6969
docs/Store.md
70+
docs/StreamResultOfStreamedListObjectsResponse.md
71+
docs/StreamedListObjectsResponse.md
7072
docs/Tuple.md
7173
docs/TupleChange.md
7274
docs/TupleKey.md
@@ -155,6 +157,8 @@ src/main/java/dev/openfga/sdk/api/model/RelationshipCondition.java
155157
src/main/java/dev/openfga/sdk/api/model/SourceInfo.java
156158
src/main/java/dev/openfga/sdk/api/model/Status.java
157159
src/main/java/dev/openfga/sdk/api/model/Store.java
160+
src/main/java/dev/openfga/sdk/api/model/StreamResultOfStreamedListObjectsResponse.java
161+
src/main/java/dev/openfga/sdk/api/model/StreamedListObjectsResponse.java
158162
src/main/java/dev/openfga/sdk/api/model/Tuple.java
159163
src/main/java/dev/openfga/sdk/api/model/TupleChange.java
160164
src/main/java/dev/openfga/sdk/api/model/TupleKey.java

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Fixed
1010

1111
- fix: preserve response headers in transaction write operations (#254)
12+
- feat: Add `streamedListObjects` API endpoint with consumer callback support (#252)
1213

1314
## v0.9.2
1415

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,7 @@ try {
11851185
| [**readAuthorizationModel**](docs/OpenFgaApi.md#readauthorizationmodel) | **GET** /stores/{store_id}/authorization-models/{id} | Return a particular version of an authorization model |
11861186
| [**readAuthorizationModels**](docs/OpenFgaApi.md#readauthorizationmodels) | **GET** /stores/{store_id}/authorization-models | Return all the authorization models for a particular store |
11871187
| [**readChanges**](docs/OpenFgaApi.md#readchanges) | **GET** /stores/{store_id}/changes | Return a list of all the tuple changes |
1188+
| [**streamedListObjects**](docs/OpenFgaApi.md#streamedlistobjects) | **POST** /stores/{store_id}/streamed-list-objects | Stream all objects of the given type that the user has a relation with |
11881189
| [**write**](docs/OpenFgaApi.md#write) | **POST** /stores/{store_id}/write | Add or delete tuples from the store |
11891190
| [**writeAssertions**](docs/OpenFgaApi.md#writeassertions) | **PUT** /stores/{store_id}/assertions/{authorization_model_id} | Upsert assertions for an authorization model ID |
11901191
| [**writeAuthorizationModel**](docs/OpenFgaApi.md#writeauthorizationmodel) | **POST** /stores/{store_id}/authorization-models | Create a new authorization model |
@@ -1310,6 +1311,10 @@ try {
13101311

13111312
- [Store](https://github.com/openfga/java-sdk/blob/main/docs/Store.md)
13121313

1314+
- [StreamResultOfStreamedListObjectsResponse](https://github.com/openfga/java-sdk/blob/main/docs/StreamResultOfStreamedListObjectsResponse.md)
1315+
1316+
- [StreamedListObjectsResponse](https://github.com/openfga/java-sdk/blob/main/docs/StreamedListObjectsResponse.md)
1317+
13131318
- [Tuple](https://github.com/openfga/java-sdk/blob/main/docs/Tuple.md)
13141319

13151320
- [TupleChange](https://github.com/openfga/java-sdk/blob/main/docs/TupleChange.md)

docs/OpenFgaApi.md

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ All URIs are relative to *http://localhost*
3232
| [**readAuthorizationModelsWithHttpInfo**](OpenFgaApi.md#readAuthorizationModelsWithHttpInfo) | **GET** /stores/{store_id}/authorization-models | Return all the authorization models for a particular store |
3333
| [**readChanges**](OpenFgaApi.md#readChanges) | **GET** /stores/{store_id}/changes | Return a list of all the tuple changes |
3434
| [**readChangesWithHttpInfo**](OpenFgaApi.md#readChangesWithHttpInfo) | **GET** /stores/{store_id}/changes | Return a list of all the tuple changes |
35+
| [**streamedListObjects**](OpenFgaApi.md#streamedListObjects) | **POST** /stores/{store_id}/streamed-list-objects | Stream all objects of the given type that the user has a relation with |
36+
| [**streamedListObjectsWithHttpInfo**](OpenFgaApi.md#streamedListObjectsWithHttpInfo) | **POST** /stores/{store_id}/streamed-list-objects | Stream all objects of the given type that the user has a relation with |
3537
| [**write**](OpenFgaApi.md#write) | **POST** /stores/{store_id}/write | Add or delete tuples from the store |
3638
| [**writeWithHttpInfo**](OpenFgaApi.md#writeWithHttpInfo) | **POST** /stores/{store_id}/write | Add or delete tuples from the store |
3739
| [**writeAssertions**](OpenFgaApi.md#writeAssertions) | **PUT** /stores/{store_id}/assertions/{authorization_model_id} | Upsert assertions for an authorization model ID |
@@ -2301,6 +2303,167 @@ No authorization required
23012303
| **500** | Request failed due to internal server error. | - |
23022304

23032305

2306+
## streamedListObjects
2307+
2308+
> CompletableFuture<StreamResultOfStreamedListObjectsResponse> streamedListObjects(storeId, body)
2309+
2310+
Stream all objects of the given type that the user has a relation with
2311+
2312+
The Streamed ListObjects API is very similar to the the ListObjects API, with two differences: 1. Instead of collecting all objects before returning a response, it streams them to the client as they are collected. 2. The number of results returned is only limited by the execution timeout specified in the flag OPENFGA_LIST_OBJECTS_DEADLINE.
2313+
2314+
### Example
2315+
2316+
```java
2317+
// Import classes:
2318+
import dev.openfga.sdk.api.client.ApiClient;
2319+
import dev.openfga.sdk.api.client.ApiException;
2320+
import dev.openfga.sdk.api.configuration.Configuration;
2321+
import dev.openfga.sdk.api.client.models.*;
2322+
import dev.openfga.sdk.api.OpenFgaApi;
2323+
import java.util.concurrent.CompletableFuture;
2324+
2325+
public class Example {
2326+
public static void main(String[] args) {
2327+
ApiClient defaultClient = Configuration.getDefaultApiClient();
2328+
defaultClient.setBasePath("http://localhost");
2329+
2330+
OpenFgaApi apiInstance = new OpenFgaApi(defaultClient);
2331+
String storeId = "storeId_example"; // String |
2332+
ListObjectsRequest body = new ListObjectsRequest(); // ListObjectsRequest |
2333+
try {
2334+
CompletableFuture<StreamResultOfStreamedListObjectsResponse> result = apiInstance.streamedListObjects(storeId, body);
2335+
System.out.println(result.get());
2336+
} catch (ApiException e) {
2337+
System.err.println("Exception when calling OpenFgaApi#streamedListObjects");
2338+
System.err.println("Status code: " + e.getCode());
2339+
System.err.println("Reason: " + e.getResponseBody());
2340+
System.err.println("Response headers: " + e.getResponseHeaders());
2341+
e.printStackTrace();
2342+
}
2343+
}
2344+
}
2345+
```
2346+
2347+
### Parameters
2348+
2349+
2350+
| Name | Type | Description | Notes |
2351+
|------------- | ------------- | ------------- | -------------|
2352+
| **storeId** | **String**| | |
2353+
| **body** | [**ListObjectsRequest**](ListObjectsRequest.md)| | |
2354+
2355+
### Return type
2356+
2357+
CompletableFuture<[**StreamResultOfStreamedListObjectsResponse**](StreamResultOfStreamedListObjectsResponse.md)>
2358+
2359+
2360+
### Authorization
2361+
2362+
No authorization required
2363+
2364+
### HTTP request headers
2365+
2366+
- **Content-Type**: application/json
2367+
- **Accept**: application/json
2368+
2369+
### HTTP response details
2370+
| Status code | Description | Response headers |
2371+
|-------------|-------------|------------------|
2372+
| **200** | A successful response.(streaming responses) | - |
2373+
| **400** | Request failed due to invalid input. | - |
2374+
| **401** | Not authenticated. | - |
2375+
| **403** | Forbidden. | - |
2376+
| **404** | Request failed due to incorrect path. | - |
2377+
| **409** | Request was aborted due a transaction conflict. | - |
2378+
| **422** | Request timed out due to excessive request throttling. | - |
2379+
| **500** | Request failed due to internal server error. | - |
2380+
2381+
## streamedListObjectsWithHttpInfo
2382+
2383+
> CompletableFuture<ApiResponse<StreamResultOfStreamedListObjectsResponse>> streamedListObjects streamedListObjectsWithHttpInfo(storeId, body)
2384+
2385+
Stream all objects of the given type that the user has a relation with
2386+
2387+
The Streamed ListObjects API is very similar to the the ListObjects API, with two differences: 1. Instead of collecting all objects before returning a response, it streams them to the client as they are collected. 2. The number of results returned is only limited by the execution timeout specified in the flag OPENFGA_LIST_OBJECTS_DEADLINE.
2388+
2389+
### Example
2390+
2391+
```java
2392+
// Import classes:
2393+
import dev.openfga.sdk.api.client.ApiClient;
2394+
import dev.openfga.sdk.api.client.ApiException;
2395+
import dev.openfga.sdk.api.client.ApiResponse;
2396+
import dev.openfga.sdk.api.configuration.Configuration;
2397+
import dev.openfga.sdk.api.client.models.*;
2398+
import dev.openfga.sdk.api.OpenFgaApi;
2399+
import java.util.concurrent.CompletableFuture;
2400+
2401+
public class Example {
2402+
public static void main(String[] args) {
2403+
ApiClient defaultClient = Configuration.getDefaultApiClient();
2404+
defaultClient.setBasePath("http://localhost");
2405+
2406+
OpenFgaApi apiInstance = new OpenFgaApi(defaultClient);
2407+
String storeId = "storeId_example"; // String |
2408+
ListObjectsRequest body = new ListObjectsRequest(); // ListObjectsRequest |
2409+
try {
2410+
CompletableFuture<ApiResponse<StreamResultOfStreamedListObjectsResponse>> response = apiInstance.streamedListObjectsWithHttpInfo(storeId, body);
2411+
System.out.println("Status code: " + response.get().getStatusCode());
2412+
System.out.println("Response headers: " + response.get().getHeaders());
2413+
System.out.println("Response body: " + response.get().getData());
2414+
} catch (InterruptedException | ExecutionException e) {
2415+
ApiException apiException = (ApiException)e.getCause();
2416+
System.err.println("Exception when calling OpenFgaApi#streamedListObjects");
2417+
System.err.println("Status code: " + apiException.getCode());
2418+
System.err.println("Response headers: " + apiException.getResponseHeaders());
2419+
System.err.println("Reason: " + apiException.getResponseBody());
2420+
e.printStackTrace();
2421+
} catch (ApiException e) {
2422+
System.err.println("Exception when calling OpenFgaApi#streamedListObjects");
2423+
System.err.println("Status code: " + e.getCode());
2424+
System.err.println("Response headers: " + e.getResponseHeaders());
2425+
System.err.println("Reason: " + e.getResponseBody());
2426+
e.printStackTrace();
2427+
}
2428+
}
2429+
}
2430+
```
2431+
2432+
### Parameters
2433+
2434+
2435+
| Name | Type | Description | Notes |
2436+
|------------- | ------------- | ------------- | -------------|
2437+
| **storeId** | **String**| | |
2438+
| **body** | [**ListObjectsRequest**](ListObjectsRequest.md)| | |
2439+
2440+
### Return type
2441+
2442+
CompletableFuture<ApiResponse<[**StreamResultOfStreamedListObjectsResponse**](StreamResultOfStreamedListObjectsResponse.md)>>
2443+
2444+
2445+
### Authorization
2446+
2447+
No authorization required
2448+
2449+
### HTTP request headers
2450+
2451+
- **Content-Type**: application/json
2452+
- **Accept**: application/json
2453+
2454+
### HTTP response details
2455+
| Status code | Description | Response headers |
2456+
|-------------|-------------|------------------|
2457+
| **200** | A successful response.(streaming responses) | - |
2458+
| **400** | Request failed due to invalid input. | - |
2459+
| **401** | Not authenticated. | - |
2460+
| **403** | Forbidden. | - |
2461+
| **404** | Request failed due to incorrect path. | - |
2462+
| **409** | Request was aborted due a transaction conflict. | - |
2463+
| **422** | Request timed out due to excessive request throttling. | - |
2464+
| **500** | Request failed due to internal server error. | - |
2465+
2466+
23042467
## write
23052468

23062469
> CompletableFuture<Object> write(storeId, body)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
# StreamResultOfStreamedListObjectsResponse
4+
5+
6+
## Properties
7+
8+
| Name | Type | Description | Notes |
9+
|------------ | ------------- | ------------- | -------------|
10+
|**result** | [**StreamedListObjectsResponse**](StreamedListObjectsResponse.md) | | [optional] |
11+
|**error** | [**Status**](Status.md) | | [optional] |
12+
13+
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
# StreamedListObjectsResponse
4+
5+
The response for a StreamedListObjects RPC.
6+
7+
## Properties
8+
9+
| Name | Type | Description | Notes |
10+
|------------ | ------------- | ------------- | -------------|
11+
|**_object** | **String** | | |
12+
13+
14+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.PHONY: build run run-openfga
2+
all: build
3+
4+
project_name=.
5+
openfga_version=latest
6+
language=java
7+
8+
build:
9+
./gradlew -P language=$(language) build
10+
11+
run:
12+
./gradlew -P language=$(language) run
13+
14+
run-openfga:
15+
docker pull docker.io/openfga/openfga:${openfga_version} && \
16+
docker run -p 8080:8080 docker.io/openfga/openfga:${openfga_version} run

0 commit comments

Comments
 (0)