UNPKG

the-moby-effect

Version:
198 lines 7.94 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 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 { SwarmSwarm as SwarmData, SwarmInitRequest, SwarmJoinRequest, SwarmSpec } from "../generated/index.js"; import { DockerError } from "./circular.js"; import { BadRequest, InternalServerError, NotFound } from "./errors.js"; /** @since 1.0.0 */ export class NodeNotPartOfSwarm extends /*#__PURE__*/Schema.ErrorClass("@the-moby-effect/endpoints/NodeNotPartOfSwarm")({ _tag: /*#__PURE__*/Schema.tagDefaultOmit("NodeNotPartOfSwarm"), message: /*#__PURE__*/Schema.optionalKey(Schema.String) }, { identifier: "NodeNotPartOfSwarm", description: "NodeNotPartOfSwarm", httpApiStatus: 503 }) {} /** @since 1.0.0 */ export class NodeAlreadyPartOfSwarm extends /*#__PURE__*/Schema.ErrorClass("@the-moby-effect/endpoints/NodeAlreadyPartOfSwarm")({ _tag: /*#__PURE__*/Schema.tagDefaultOmit("NodeAlreadyPartOfSwarm"), message: /*#__PURE__*/Schema.optionalKey(Schema.String) }, { identifier: "NodeAlreadyPartOfSwarm", description: "NodeAlreadyPartOfSwarm", httpApiStatus: 503 }) {} /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmInspect */ const inspectSwarmEndpoint = /*#__PURE__*/HttpApiEndpoint.get("inspect", "/", { success: SwarmData, // 200 OK error: [NotFound, // 404 No such swarm NodeNotPartOfSwarm, // 503 Node is not part of a swarm InternalServerError] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmInit */ const initSwarmEndpoint = /*#__PURE__*/HttpApiEndpoint.post("init", "/init", { payload: SwarmInitRequest, success: Schema.String, // 200 OK error: [BadRequest, // 400 Bad parameter NodeAlreadyPartOfSwarm, // 503 Node is already part of a swarm InternalServerError] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmJoin */ const joinSwarmEndpoint = /*#__PURE__*/HttpApiEndpoint.post("join", "/join", { payload: SwarmJoinRequest, success: /*#__PURE__*/HttpApiSchema.Empty(200), // 200 OK error: [BadRequest, // 400 Bad parameter NodeAlreadyPartOfSwarm, // 503 Node is already part of a swarm InternalServerError] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmLeave */ const leaveSwarmEndpoint = /*#__PURE__*/HttpApiEndpoint.post("leave", "/leave", { query: { force: /*#__PURE__*/Schema.optional(Schema.Boolean) }, success: /*#__PURE__*/HttpApiSchema.Empty(200), // 200 OK error: [NodeNotPartOfSwarm, // 503 Node is not part of a swarm InternalServerError] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmUpdate */ const updateSwarmEndpoint = /*#__PURE__*/HttpApiEndpoint.post("update", "/update", { query: { version: Schema.BigIntFromString, rotateWorkerToken: /*#__PURE__*/Schema.optional(Schema.Boolean), rotateManagerToken: /*#__PURE__*/Schema.optional(Schema.Boolean), rotateManagerUnlockKey: /*#__PURE__*/Schema.optional(Schema.Boolean) }, payload: SwarmSpec, success: /*#__PURE__*/HttpApiSchema.Empty(200), // 200 OK error: [BadRequest, // 400 Bad parameter NodeNotPartOfSwarm, // 503 Node is not part of a swarm InternalServerError] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmUnlockkey */ const unlockkeySwarmEndpoint = /*#__PURE__*/HttpApiEndpoint.get("unlockkey", "/unlockkey", { success: /*#__PURE__*/Schema.Struct({ UnlockKey: Schema.String }), // 200 OK error: [NodeNotPartOfSwarm, // 503 Node is not part of a swarm InternalServerError] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmUnlock */ const unlockSwarmEndpoint = /*#__PURE__*/HttpApiEndpoint.post("unlock", "/unlock", { payload: /*#__PURE__*/Schema.Struct({ UnlockKey: Schema.String }), success: /*#__PURE__*/HttpApiSchema.Empty(200), // 200 OK error: [NodeNotPartOfSwarm, // 503 Node is not part of a swarm InternalServerError] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm */ const SwarmGroup = /*#__PURE__*/HttpApiGroup.make("swarm").add(inspectSwarmEndpoint, initSwarmEndpoint, joinSwarmEndpoint, leaveSwarmEndpoint, updateSwarmEndpoint, unlockkeySwarmEndpoint, unlockSwarmEndpoint).prefix("/swarm"); /** * Engines can be clustered together in a swarm. Refer to the swarm mode * documentation for more information. * * @since 1.0.0 * @category HttpApi * @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm */ export const SwarmApi = /*#__PURE__*/HttpApi.make("SwarmApi").add(SwarmGroup); /** * Engines can be clustered together in a swarm. Refer to the swarm mode * documentation for more information. * * @since 1.0.0 * @category Services * @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm */ export class Swarm extends /*#__PURE__*/Context.Service()("@the-moby-effect/endpoints/Swarm", { make: /*#__PURE__*/Effect.gen(function* () { const httpClient = yield* HttpClient.HttpClient; const SwarmsError = DockerError.WrapForModule("swarm"); const client = yield* HttpApiClient.group(SwarmApi, { group: "swarm", httpClient }); const inspect_ = () => client.inspect().pipe(Effect.mapError(SwarmsError("inspect"))); const init_ = payload => SwarmInitRequest.makeEffect(payload).pipe(Effect.flatMap(payload => client.init({ payload })), Effect.mapError(SwarmsError("init"))); const join_ = payload => SwarmJoinRequest.makeEffect(payload).pipe(Effect.flatMap(payload => client.join({ payload })), Effect.mapError(SwarmsError("join"))); const leave_ = options => client.leave({ query: { ...options } }).pipe(Effect.mapError(SwarmsError("leave"))); const update_ = (spec, version, rotate) => SwarmSpec.makeEffect(spec).pipe(Effect.flatMap(payload => client.update({ payload, query: { version, ...rotate } })), Effect.mapError(SwarmsError("update"))); const unlockkey_ = () => client.unlockkey().pipe(Effect.mapError(SwarmsError("unlockkey"))); const unlock_ = unlockKey => client.unlock({ payload: { UnlockKey: unlockKey } }).pipe(Effect.mapError(SwarmsError("unlock"))); return { inspect: inspect_, init: init_, join: join_, leave: leave_, update: update_, unlockkey: unlockkey_, unlock: unlock_ }; }) }) {} /** * Engines can be clustered together in a swarm. Refer to the swarm mode * documentation for more information. * * @since 1.0.0 * @category Layers * @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm */ export const SwarmLayer = /*#__PURE__*/Layer.effect(Swarm, Swarm.make); /** * Engines can be clustered together in a swarm. Refer to the swarm mode * documentation for more information. * * @since 1.0.0 * @category Layers * @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm */ export const SwarmLayerLocalSocket = /*#__PURE__*/SwarmLayer.pipe(/*#__PURE__*/Layer.provide(/*#__PURE__*/makeAgnosticHttpClientLayer(/*#__PURE__*/MobyConnectionOptions.socket({ socketPath: "/var/run/docker.sock" })))); //# sourceMappingURL=swarm.js.map