the-moby-effect
Version:
Moby/Docker API client built using effect-ts
43 lines • 1.83 kB
JavaScript
import * as Socket from "@effect/platform/Socket";
import * as Effect from "effect/Effect";
import { makeMultiplexedSocket, responseIsMultiplexedResponse } from "./multiplexed.js";
import { makeRawSocket, responseIsRawResponse } from "./raw.js";
/** @internal */
export const hijackResponseUnsafe = response => Effect.flatMap(Effect.promise(() => import("@effect/platform-node/NodeSocket")), nodeSocketLazy => {
const socket = response.original.source.socket;
return nodeSocketLazy.fromDuplex(Effect.sync(() => socket));
});
/** @internal */
export const responseToMultiplexedStreamSocketOrFailUnsafe = response => {
if (!responseIsMultiplexedResponse(response)) {
return Effect.fail(new Socket.SocketGenericError({
reason: "Read",
cause: `Response with content type "${response.headers["content-type"]}" is not a multiplexed streaming socket`
}));
}
return Effect.map(hijackResponseUnsafe(response), makeMultiplexedSocket);
};
/** @internal */
export const responseToRawStreamSocketOrFailUnsafe = response => {
if (!responseIsRawResponse(response)) {
return Effect.fail(new Socket.SocketGenericError({
reason: "Read",
cause: `Response with content type "${response.headers["content-type"]}" is not a raw streaming socket`
}));
}
return Effect.map(hijackResponseUnsafe(response), makeRawSocket);
};
/** @internal */
export const responseToStreamingSocketOrFailUnsafe = response => {
if (responseIsMultiplexedResponse(response)) {
return responseToMultiplexedStreamSocketOrFailUnsafe(response);
}
if (responseIsRawResponse(response)) {
return responseToRawStreamSocketOrFailUnsafe(response);
}
return Effect.fail(new Socket.SocketGenericError({
reason: "Read",
cause: "Response is not a streaming socket"
}));
};
//# sourceMappingURL=hijack.js.map