Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ import {
PagedAsyncIterableIterator,
buildPagedAsyncIterator,
} from "../static-helpers/pagingHelpers.js";
import { getBinaryResponseBody } from "../static-helpers/serialization/get-binary-response-body.js";
import { getBinaryStreamResponse } from "../static-helpers/serialization/get-binary-stream-response.js";
import { expandUrlTemplate } from "../static-helpers/urlTemplate.js";
import {
ListNodeFilesOptionalParams,
Expand Down Expand Up @@ -410,9 +410,17 @@ export function _getNodeFileSend(
}

export async function _getNodeFileDeserialize(
result: StreamableMethod,
result: PathUncheckedResponse & GetNodeFileResponse,
): Promise<GetNodeFileResponse> {
return getBinaryResponseBody(result, ["200"], batchErrorDeserializer);
const expectedStatuses = ["200"];
if (!expectedStatuses.includes(result.status)) {
const error = createRestError(result);
error.details = batchErrorDeserializer(result.body);

throw error;
}

return { blobBody: result.blobBody, readableStreamBody: result.readableStreamBody };
}

/** Returns the content of the specified Compute Node file. */
Expand All @@ -424,7 +432,8 @@ export async function getNodeFile(
options: GetNodeFileOptionalParams = { requestOptions: {} },
): Promise<GetNodeFileResponse> {
const streamableMethod = _getNodeFileSend(context, poolId, nodeId, filePath, options);
return _getNodeFileDeserialize(streamableMethod);
const result = await getBinaryStreamResponse(streamableMethod);
return _getNodeFileDeserialize(result);
}

export function _deleteNodeFileSend(
Expand Down Expand Up @@ -822,9 +831,17 @@ export function _getNodeRemoteDesktopFileSend(
}

export async function _getNodeRemoteDesktopFileDeserialize(
result: StreamableMethod,
result: PathUncheckedResponse & GetNodeRemoteDesktopFileResponse,
): Promise<GetNodeRemoteDesktopFileResponse> {
return getBinaryResponseBody(result, ["200"], batchErrorDeserializer);
const expectedStatuses = ["200"];
if (!expectedStatuses.includes(result.status)) {
const error = createRestError(result);
error.details = batchErrorDeserializer(result.body);

throw error;
}

return { blobBody: result.blobBody, readableStreamBody: result.readableStreamBody };
}

/**
Expand All @@ -840,7 +857,8 @@ export async function getNodeRemoteDesktopFile(
options: GetNodeRemoteDesktopFileOptionalParams = { requestOptions: {} },
): Promise<GetNodeRemoteDesktopFileResponse> {
const streamableMethod = _getNodeRemoteDesktopFileSend(context, poolId, nodeId, options);
return _getNodeRemoteDesktopFileDeserialize(streamableMethod);
const result = await getBinaryStreamResponse(streamableMethod);
return _getNodeRemoteDesktopFileDeserialize(result);
}

export function _getNodeRemoteLoginSettingsSend(
Expand Down Expand Up @@ -1655,9 +1673,17 @@ export function _getTaskFileSend(
}

export async function _getTaskFileDeserialize(
result: StreamableMethod,
result: PathUncheckedResponse & GetTaskFileResponse,
): Promise<GetTaskFileResponse> {
return getBinaryResponseBody(result, ["200"], batchErrorDeserializer);
const expectedStatuses = ["200"];
if (!expectedStatuses.includes(result.status)) {
const error = createRestError(result);
error.details = batchErrorDeserializer(result.body);

throw error;
}

return { blobBody: result.blobBody, readableStreamBody: result.readableStreamBody };
}

/** Returns the content of the specified Task file. */
Expand All @@ -1669,7 +1695,8 @@ export async function getTaskFile(
options: GetTaskFileOptionalParams = { requestOptions: {} },
): Promise<GetTaskFileResponse> {
const streamableMethod = _getTaskFileSend(context, jobId, taskId, filePath, options);
return _getTaskFileDeserialize(streamableMethod);
const result = await getBinaryStreamResponse(streamableMethod);
return _getTaskFileDeserialize(result);
}

export function _deleteTaskFileSend(
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { HttpResponse, StreamableMethod } from "@azure-rest/core-client";

/**
* Resolves a StreamableMethod into a binary stream response using browser streaming.
* Returns both the raw HttpResponse (for status/header inspection) and a blobBody Promise.
* Error handling is left to the caller so that generated deserializers can apply
* operation-specific error deserialization (per-status-code details, exception headers, etc.).
*/
export async function getBinaryStreamResponse(
streamableMethod: StreamableMethod
): Promise<
HttpResponse & {
blobBody?: Promise<Blob>;
readableStreamBody?: NodeJS.ReadableStream;
}
> {
const response = await streamableMethod.asBrowserStream();
return {
...response,
blobBody: new Response(response.body).blob(),
readableStreamBody: undefined,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { HttpResponse, StreamableMethod } from "@azure-rest/core-client";

/**
* Resolves a StreamableMethod into a binary stream response using Node.js streaming.
* Returns both the raw HttpResponse (for status/header inspection) and the readable stream body.
* Error handling is left to the caller so that generated deserializers can apply
* operation-specific error deserialization (per-status-code details, exception headers, etc.).
*/
export async function getBinaryStreamResponse(streamableMethod: StreamableMethod): Promise<
HttpResponse & {
blobBody?: Promise<Blob>;
readableStreamBody?: NodeJS.ReadableStream;
}
> {
const response = await streamableMethod.asNodeStream();
return {
...response,
blobBody: undefined,
readableStreamBody: response.body,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
GetAudioTranslationAsPlainTextResponse,
GetAudioTranscriptionAsPlainTextResponse,
} from "../models/models.js";
import { getBinaryResponseBody } from "../static-helpers/serialization/get-binary-response-body.js";
import { getBinaryStreamResponse } from "../static-helpers/serialization/get-binary-stream-response.js";
import { expandUrlTemplate } from "../static-helpers/urlTemplate.js";
import {
GetEmbeddingsOptionalParams,
Expand Down Expand Up @@ -128,9 +128,14 @@ export function _generateSpeechFromTextSend(
}

export async function _generateSpeechFromTextDeserialize(
result: StreamableMethod,
result: PathUncheckedResponse & GenerateSpeechFromTextResponse,
): Promise<GenerateSpeechFromTextResponse> {
return getBinaryResponseBody(result, ["200"]);
const expectedStatuses = ["200"];
if (!expectedStatuses.includes(result.status)) {
throw createRestError(result);
}

return { blobBody: result.blobBody, readableStreamBody: result.readableStreamBody };
}

/** Generates text-to-speech audio from the input text. */
Expand All @@ -141,7 +146,8 @@ export async function generateSpeechFromText(
options: GenerateSpeechFromTextOptionalParams = { requestOptions: {} },
): Promise<GenerateSpeechFromTextResponse> {
const streamableMethod = _generateSpeechFromTextSend(context, deploymentId, body, options);
return _generateSpeechFromTextDeserialize(streamableMethod);
const result = await getBinaryStreamResponse(streamableMethod);
return _generateSpeechFromTextDeserialize(result);
}

export function _getImageGenerationsSend(
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { HttpResponse, StreamableMethod } from "@azure-rest/core-client";

/**
* Resolves a StreamableMethod into a binary stream response using browser streaming.
* Returns both the raw HttpResponse (for status/header inspection) and a blobBody Promise.
* Error handling is left to the caller so that generated deserializers can apply
* operation-specific error deserialization (per-status-code details, exception headers, etc.).
*/
export async function getBinaryStreamResponse(
streamableMethod: StreamableMethod
): Promise<
HttpResponse & {
blobBody?: Promise<Blob>;
readableStreamBody?: NodeJS.ReadableStream;
}
> {
const response = await streamableMethod.asBrowserStream();
return {
...response,
blobBody: new Response(response.body).blob(),
readableStreamBody: undefined,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { HttpResponse, StreamableMethod } from "@azure-rest/core-client";

/**
* Resolves a StreamableMethod into a binary stream response using Node.js streaming.
* Returns both the raw HttpResponse (for status/header inspection) and the readable stream body.
* Error handling is left to the caller so that generated deserializers can apply
* operation-specific error deserialization (per-status-code details, exception headers, etc.).
*/
export async function getBinaryStreamResponse(streamableMethod: StreamableMethod): Promise<
HttpResponse & {
blobBody?: Promise<Blob>;
readableStreamBody?: NodeJS.ReadableStream;
}
> {
const response = await streamableMethod.asNodeStream();
return {
...response,
blobBody: undefined,
readableStreamBody: response.body,
};
}
Loading
Loading