the-moby-effect
Version:
Moby/Docker API client built using effect-ts
77 lines • 3.79 kB
JavaScript
import * as PlatformError from "@effect/platform/Error";
import * as HttpClient from "@effect/platform/HttpClient";
import * as HttpClientRequest from "@effect/platform/HttpClientRequest";
import * as HttpClientResponse from "@effect/platform/HttpClientResponse";
import * as Effect from "effect/Effect";
import * as Function from "effect/Function";
import * as Option from "effect/Option";
import * as Predicate from "effect/Predicate";
import * as Schema from "effect/Schema";
import * as Stream from "effect/Stream";
import { SwarmTask } from "../generated/index.js";
import { maybeAddQueryParameter } from "./common.js";
/**
* @since 1.0.0
* @category Errors
*/
export const TasksErrorTypeId = /*#__PURE__*/Symbol.for("@the-moby-effect/endpoints/TasksError");
/**
* @since 1.0.0
* @category Errors
*/
export const isTasksError = u => Predicate.hasProperty(u, TasksErrorTypeId);
/**
* @since 1.0.0
* @category Errors
*/
export class TasksError extends /*#__PURE__*/PlatformError.TypeIdError(TasksErrorTypeId, "TasksError") {
get message() {
return `${this.method}`;
}
}
/**
* A task is a container running on a swarm. It is the atomic scheduling unit of
* swarm. Swarm mode must be enabled for these endpoints to work.
*
* @since 1.0.0
* @category Tags
* @see https://docs.docker.com/reference/api/engine/latest/#tag/Task
*/
export class Tasks extends /*#__PURE__*/Effect.Service()("@the-moby-effect/endpoints/Tasks", {
accessors: false,
dependencies: [],
effect: /*#__PURE__*/Effect.gen(function* () {
const defaultClient = yield* HttpClient.HttpClient;
const client = defaultClient.pipe(HttpClient.filterStatusOk);
/** @see https://docs.docker.com/reference/api/engine/latest/#tag/Task/operation/TaskList */
const list_ = options => Function.pipe(HttpClientRequest.get("/tasks"), maybeAddQueryParameter("filters", Function.pipe(options?.filters, Option.fromNullable, Option.map(JSON.stringify))), client.execute, Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Array(SwarmTask))), Effect.mapError(cause => new TasksError({
method: "list",
cause
})));
/** @see https://docs.docker.com/reference/api/engine/latest/#tag/Task/operation/TaskInspect */
const inspect_ = id => Function.pipe(HttpClientRequest.get(`/tasks/${encodeURIComponent(id)}`), client.execute, Effect.flatMap(HttpClientResponse.schemaBodyJson(SwarmTask)), Effect.mapError(cause => new TasksError({
method: "inspect",
cause
})));
/** @see https://docs.docker.com/reference/api/engine/latest/#tag/Task/operation/TaskLogs */
const logs_ = (id, options) => Function.pipe(HttpClientRequest.get(`/tasks/${encodeURIComponent(id)}/logs`), maybeAddQueryParameter("details", Option.fromNullable(options?.details)), maybeAddQueryParameter("follow", Option.fromNullable(options?.follow)), maybeAddQueryParameter("stdout", Option.fromNullable(options?.stdout)), maybeAddQueryParameter("stderr", Option.fromNullable(options?.stderr)), maybeAddQueryParameter("since", Option.fromNullable(options?.since)), maybeAddQueryParameter("timestamps", Option.fromNullable(options?.timestamps)), maybeAddQueryParameter("tail", Option.fromNullable(options?.tail)), client.execute, HttpClientResponse.stream, Stream.decodeText(), Stream.mapError(cause => new TasksError({
method: "logs",
cause
})));
return {
list: list_,
inspect: inspect_,
logs: logs_
};
})
}) {}
/**
* A task is a container running on a swarm. It is the atomic scheduling unit of
* swarm. Swarm mode must be enabled for these endpoints to work.
*
* @since 1.0.0
* @category Layers
* @see https://docs.docker.com/reference/api/engine/latest/#tag/Task
*/
export const TasksLayer = Tasks.Default;
//# sourceMappingURL=tasks.js.map