UNPKG

the-moby-effect

Version:
144 lines 5.91 kB
import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Schema from "effect/Schema"; import * as Stream from "effect/Stream"; import * as HttpClient from "effect/unstable/http/HttpClient"; import * as HttpApi from "effect/unstable/httpapi/HttpApi"; import * as HttpApiClient from "effect/unstable/httpapi/HttpApiClient"; import * as HttpApiEndpoint from "effect/unstable/httpapi/HttpApiEndpoint"; import * as HttpApiGroup from "effect/unstable/httpapi/HttpApiGroup"; import * as HttpApiSchema from "effect/unstable/httpapi/HttpApiSchema"; import { MobyConnectionOptions } from "../../MobyConnection.js"; import { makeAgnosticHttpClientLayer } from "../../MobyPlatforms.js"; import { SwarmTask } from "../generated/index.js"; import { DockerError } from "./circular.js"; import { InternalServerError, NotFound, ServiceUnavailable } from "./errors.js"; /** @since 1.0.0 */ export const TaskListFilters = /*#__PURE__*/Schema.fromJsonString(/*#__PURE__*/Schema.Struct({ "desired-state": /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Array(/*#__PURE__*/Schema.Literals(["running", "shutdown", "accepted"]))), id: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Array(Schema.String)), name: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Array(Schema.String)), node: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Array(Schema.String)), service: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Array(Schema.String)), label: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Array(Schema.String)) })); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Task/operation/TaskList */ const listTasksEndpoint = /*#__PURE__*/HttpApiEndpoint.get("list", "/", { query: { filters: /*#__PURE__*/Schema.optional(TaskListFilters) }, success: /*#__PURE__*/Schema.Array(SwarmTask), // 200 OK error: [ServiceUnavailable, // 503 Node is not part of a swarm InternalServerError] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Task/operation/TaskInspect */ const inspectTaskEndpoint = /*#__PURE__*/HttpApiEndpoint.get("inspect", "/:id", { params: { id: Schema.String }, success: SwarmTask, // 200 OK error: [NotFound, // 404 No such task ServiceUnavailable, // 503 Node is not part of a swarm InternalServerError] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Task/operation/TaskLogs */ const logsTaskEndpoint = /*#__PURE__*/HttpApiEndpoint.get("logs", "/:id/logs", { params: { id: Schema.String }, query: { details: /*#__PURE__*/Schema.optional(Schema.Boolean), follow: /*#__PURE__*/Schema.optional(Schema.Boolean), stdout: /*#__PURE__*/Schema.optional(Schema.Boolean), stderr: /*#__PURE__*/Schema.optional(Schema.Boolean), since: /*#__PURE__*/Schema.optional(Schema.Number), timestamps: /*#__PURE__*/Schema.optional(Schema.Boolean), tail: /*#__PURE__*/Schema.optional(Schema.String) }, success: /*#__PURE__*/HttpApiSchema.StreamUint8Array(), // 200 OK (streaming response) error: [NotFound, // 404 No such task ServiceUnavailable, // 503 Node is not part of a swarm InternalServerError] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Task */ const TasksGroup = /*#__PURE__*/HttpApiGroup.make("tasks").add(listTasksEndpoint, inspectTaskEndpoint, logsTaskEndpoint).prefix("/tasks"); /** * 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 HttpApi * @see https://docs.docker.com/reference/api/engine/latest/#tag/Task */ export const TasksApi = /*#__PURE__*/HttpApi.make("TasksApi").add(TasksGroup); /** * 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 Services * @see https://docs.docker.com/reference/api/engine/latest/#tag/Task */ export class Tasks extends /*#__PURE__*/Context.Service()("@the-moby-effect/endpoints/Tasks", { make: /*#__PURE__*/Effect.gen(function* () { const httpClient = yield* HttpClient.HttpClient; const TasksError = DockerError.WrapForModule("tasks"); const client = yield* HttpApiClient.group(TasksApi, { group: "tasks", httpClient }); const list_ = filters => client.list({ query: { filters } }).pipe(Effect.mapError(TasksError("list"))); const inspect_ = id => client.inspect({ params: { id } }).pipe(Effect.mapError(TasksError("inspect"))); const logs_ = (id, options) => client.logs({ params: { id }, query: { ...options } }).pipe(Effect.map(Stream.decodeText()), Effect.map(Stream.splitLines), Effect.map(Stream.mapError(TasksError("logs"))), Effect.mapError(TasksError("logs"))); 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 = /*#__PURE__*/Layer.effect(Tasks, Tasks.make); /** * 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 TasksLayerLocalSocket = /*#__PURE__*/TasksLayer.pipe(/*#__PURE__*/Layer.provide(/*#__PURE__*/makeAgnosticHttpClientLayer(/*#__PURE__*/MobyConnectionOptions.socket({ socketPath: "/var/run/docker.sock" })))); //# sourceMappingURL=tasks.js.map