-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(typescript): support bytes
responses
#5402
base: main
Are you sure you want to change the base?
Conversation
981c41e
to
8125bd2
Compare
/** | ||
* @param {Service.RequestOptions} requestOptions - Request-specific configuration. | ||
*/ | ||
public async download(requestOptions?: Service.RequestOptions): Promise<ArrayBuffer> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated SDKs should be flexible enough to retrieve the bytes as an array buffer (fully in-memory) or using a stream where the whole file isn't in memory.
Instead of returning ArrayBuffer
, maybe we can return a type where the user can decide to get the buffer or stream.
export interface FooBarResponse {
buffer: () => Promise<ArrayBuffer>;
steam: () => Promise<ReadableStream>;
}
At AssemblyAI we did this:
const response = await fetch(redacted_audio_url);
if (!response.ok) {
throw new Error(`Failed to fetch redacted audio: ${response.statusText}`);
}
return {
arrayBuffer: response.arrayBuffer.bind(response),
blob: response.blob.bind(response),
body: response.body,
bodyUsed: response.bodyUsed,
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case Response is the best option, it can be streamed, turned into a buffer, blob, etc
🌿 Preview your docs: https://fern-preview-538aa1ff-0b97-4a61-ab46-9c8b19560a43.docs.buildwithfern.com/learn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great 👏
@@ -1,3 +1,9 @@ | |||
- changelogEntry: | |||
- summary: Upgraces to v53 of the IR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Upgraces" typo
a `Promise<ArrayBuffer>`. This is particularly useful for usecases like text to speech | ||
where you would like to play the audio in the browser. | ||
|
||
Additional this feature ugprade the dependency of the generator to Intermediate Representation v54. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"ugprade" typo
/** | ||
* @param {Service.RequestOptions} requestOptions - Request-specific configuration. | ||
*/ | ||
public async download(requestOptions?: Service.RequestOptions): Promise<ArrayBuffer> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated SDKs should be flexible enough to retrieve the bytes as an array buffer (fully in-memory) or using a stream where the whole file isn't in memory.
Instead of returning ArrayBuffer
, maybe we can return a type where the user can decide to get the buffer or stream.
export interface FooBarResponse {
buffer: () => Promise<ArrayBuffer>;
steam: () => Promise<ReadableStream>;
}
At AssemblyAI we did this:
const response = await fetch(redacted_audio_url);
if (!response.ok) {
throw new Error(`Failed to fetch redacted audio: ${response.statusText}`);
}
return {
arrayBuffer: response.arrayBuffer.bind(response),
blob: response.blob.bind(response),
body: response.body,
bodyUsed: response.bodyUsed,
};
Description
This PR supports
bytes
responses in the TypeScript SDK. Abytes
response is returned as anArrayBuffer
.Changes Made
v54
HttpResponseBody.Bytes
bytes
Fern Definition for bytes download (affects seed)Testing