Skip to content

Commit 1d2c25e

Browse files
feat(js): add streaming support for streamedListObjects
Updates JavaScript SDK templates to support the streaming API endpoint for unlimited object retrieval. Templates now handle streaming operations differently using vendor extension conditionals. Templates Modified (7 files): - Add streaming.mustache template with NDJSON parser for Node.js - Update api.mustache to import createStreamingRequestFunction - Update apiInner.mustache with x-fga-streaming vendor extension logic - Uses createStreamingRequestFunction for streaming ops - Returns Promise<any> instead of PromiseResult<T> - Simplified telemetry (method name only) - Update index.mustache to export parseNDJSONStream - Update config.overrides.json with streaming file + feature flag - Add README_calling_api.mustache documentation for Streamed List Objects - Add README_api_endpoints.mustache table entry for streaming endpoint Implementation: - Conditional template logic based on x-fga-streaming vendor extension - Preserves telemetry while returning raw Node.js stream - Aligned with Python SDK template patterns - Fixed error propagation in async iterator adapter - Widened parseNDJSONStream type signature for better DX - Added guard to prevent onEnd processing after error state Generated SDK Verification: - ✅ streaming.ts generated with all error handling fixes - ✅ parseNDJSONStream exported from index.ts - ✅ StreamedListObjectsResponse interface in apiModel.ts - ⚠️ streamedListObjects method uses regular handling (needs x-fga-streaming: true in spec) Dependencies: - Requires x-fga-streaming: true vendor extension in OpenAPI spec (openfga/api) - Without vendor extension, method is generated but uses wrong request handler Related: - Fixes #76 (JavaScript SDK) - Implements openfga/js-sdk#236 - Related PR: openfga/js-sdk#280
1 parent b5fa5ab commit 1d2c25e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

config/clients/js/template/streaming.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const createAsyncIterableFromReadable = (readable: any): AsyncIterable<any> => {
2121
};
2222

2323
const onEnd = () => {
24+
if (error) return; // Don't process end if error already occurred
2425
ended = true;
2526
while (pendings.length > 0) {
2627
const { resolve } = pendings.shift()!;
@@ -34,6 +35,7 @@ const createAsyncIterableFromReadable = (readable: any): AsyncIterable<any> => {
3435
const { reject } = pendings.shift()!;
3536
reject(err);
3637
}
38+
cleanup();
3739
};
3840
3941
readable.on("data", onData);
@@ -49,7 +51,6 @@ const createAsyncIterableFromReadable = (readable: any): AsyncIterable<any> => {
4951
return {
5052
next(): Promise<IteratorResult<any>> {
5153
if (error) {
52-
cleanup();
5354
return Promise.reject(error);
5455
}
5556
if (chunkQueue.length > 0) {

0 commit comments

Comments
 (0)