docs: parse raw stream#389
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 59 minutes and 11 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Documentation Updates 1 document(s) were updated by changes in this PR: StreamedListObjects Feature OverviewView Changes@@ -178,7 +178,7 @@
Additionally, the JS SDK provides `executeApiRequest` and `executeStreamedApiRequest` methods on `OpenFgaClient` that can be used to call arbitrary API endpoints that don't yet have dedicated SDK methods. Use `executeApiRequest` for regular endpoints and `executeStreamedApiRequest` for streaming endpoints like `/streamed-list-objects`. These methods act as an escape hatch while still providing SDK benefits like authentication, configuration, retries, and error handling.
-**Example:**
+**Example (Non-Streaming Endpoint):**
```javascript
const response = await fgaClient.executeApiRequest({
operationName: 'CustomEndpoint', // Required: operation name for telemetry
@@ -191,6 +191,40 @@
});
```
+**Example (Streaming Endpoint):**
+
+For streaming endpoints, use `executeStreamedApiRequest` instead of `executeApiRequest`. This returns a raw Node.js readable stream. To parse the newline-delimited JSON (NDJSON) response into individual objects, use the `parseNDJSONStream` helper exported by the SDK:
+
+```javascript
+const { OpenFgaClient, parseNDJSONStream } = require('@openfga/sdk');
+
+const fgaClient = new OpenFgaClient({
+ apiUrl: process.env.FGA_API_URL,
+ storeId: process.env.FGA_STORE_ID,
+});
+
+const streamResponse = await fgaClient.executeStreamedApiRequest({
+ operationName: 'StreamedListObjects',
+ method: 'POST',
+ path: '/stores/{store_id}/streamed-list-objects',
+ pathParams: { store_id: process.env.FGA_STORE_ID },
+ body: {
+ authorization_model_id: process.env.FGA_MODEL_ID,
+ user: 'user:alice',
+ relation: 'reader',
+ type: 'document',
+ },
+});
+
+// executeStreamedApiRequest returns the raw Node.js Readable stream directly.
+// Use parseNDJSONStream to iterate over the parsed JSON objects:
+for await (const item of parseNDJSONStream(streamResponse)) {
+ console.log('Object:', item.object);
+}
+```
+
+Unlike `executeApiRequest` (which wraps the response in a `CallResult` with a `$response` property), `executeStreamedApiRequest` returns the raw stream directly. `parseNDJSONStream` handles chunked data, partial lines, and buffer flushing automatically. It accepts Node.js `Readable` streams, `AsyncIterable`s, or even plain strings and `Buffer`s.
+
### .NET SDK
The .NET SDK provides `ApiExecutor` for calling custom API endpoints, including `/streamed-list-objects`. Use the `ExecuteStreamingAsync` method to stream results as they arrive without pagination limits.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #389 +/- ##
=======================================
Coverage 85.79% 85.79%
=======================================
Files 26 26
Lines 1267 1267
Branches 225 225
=======================================
Hits 1087 1087
Misses 110 110
Partials 70 70 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds README documentation for consuming streaming endpoints via executeStreamedApiRequest, including parsing NDJSON output with the SDK’s parseNDJSONStream helper.
Changes:
- Document how to call a streaming endpoint using
executeStreamedApiRequest. - Add a JavaScript example showing NDJSON parsing with
parseNDJSONStream. - Clarify behavioral differences between
executeApiRequestandexecuteStreamedApiRequest.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
What problem is being solved?
How is it being solved?
What changes are made to solve it?
References
Review Checklist
main