UNPKG

the-moby-effect

Version:
185 lines 7.18 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 { SwarmConfig, SwarmConfigSpec } from "../generated/index.js"; import { ConfigIdentifier } from "../schemas/id.js"; import { DockerError } from "./circular.js"; import { BadRequest, Conflict, InternalServerError, NotFound } from "./errors.js"; import { NodeNotPartOfSwarm } from "./swarm.js"; /** @since 1.0.0 */ export const ListFilters = /*#__PURE__*/Schema.fromJsonString(/*#__PURE__*/Schema.Struct({ id: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Array(ConfigIdentifier)), name: /*#__PURE__*/Schema.optional(/*#__PURE__*/Schema.Array(Schema.String)), names: /*#__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/Config/operation/ConfigList */ const listConfigsEndpoint = /*#__PURE__*/HttpApiEndpoint.get("list", "/", { query: { filters: /*#__PURE__*/Schema.optional(ListFilters) }, success: /*#__PURE__*/Schema.Array(SwarmConfig), // 200 OK error: [NodeNotPartOfSwarm, // 503 Node is not part of a swarm InternalServerError // 500 Internal Server Error ] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Config/operation/ConfigCreate */ const createConfigEndpoint = /*#__PURE__*/HttpApiEndpoint.post("create", "/create", { payload: SwarmConfigSpec, success: /*#__PURE__*/Schema.Struct({ Id: ConfigIdentifier }).pipe(/*#__PURE__*/Schema.encodeKeys({ Id: "ID" }), /*#__PURE__*/HttpApiSchema.status(201)), // 201 Created error: [Conflict, // 409 Name conflicts with existing object NodeNotPartOfSwarm, // 503 Node is not part of a swarm InternalServerError // 500 Internal Server Error ] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Config/operation/ConfigInspect */ const inspectConfigEndpoint = /*#__PURE__*/HttpApiEndpoint.get("inspect", "/:identifier", { params: { identifier: ConfigIdentifier }, success: SwarmConfig, // 200 OK error: [NotFound, // 404 Config not found NodeNotPartOfSwarm, // 503 Node is not part of a swarm InternalServerError // 500 Internal Server Error ] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Config/operation/ConfigDelete */ const deleteConfigEndpoint = /*#__PURE__*/HttpApiEndpoint.delete("delete", "/:identifier", { params: { identifier: ConfigIdentifier }, success: HttpApiSchema.NoContent, // 204 No Content error: [NotFound, // 404 Config not found NodeNotPartOfSwarm, // 503 Node is not part of a swarm InternalServerError // 500 Internal Server Error ] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Config/operation/ConfigUpdate */ const updateConfigEndpoint = /*#__PURE__*/HttpApiEndpoint.post("update", "/:identifier/update", { params: { identifier: ConfigIdentifier }, query: { version: Schema.BigIntFromString }, payload: SwarmConfigSpec, // Note: Docker API states only Labels can be updated success: /*#__PURE__*/HttpApiSchema.Empty(200), // 200 OK, no response body error: [BadRequest, // 400 Bad parameter NotFound, // 404 Config not found NodeNotPartOfSwarm, // 503 Node is not part of a swarm InternalServerError // 500 Internal Server Error ] }); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/Config */ const ConfigsGroup = /*#__PURE__*/HttpApiGroup.make("configs").add(listConfigsEndpoint, createConfigEndpoint, inspectConfigEndpoint, deleteConfigEndpoint, updateConfigEndpoint).prefix("/configs"); // Prefix for endpoints in this group /** * Configs are application configurations that can be used by services. 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/Config */ export const ConfigsApi = /*#__PURE__*/HttpApi.make("ConfigsApi").add(ConfigsGroup); /** * Configs are application configurations that can be used by services. 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/Config */ export class Configs extends /*#__PURE__*/Context.Service()("@the-moby-effect/endpoints/Configs", { make: /*#__PURE__*/Effect.gen(function* () { const httpClient = yield* HttpClient.HttpClient; const ConfigsError = DockerError.WrapForModule("configs"); const client = yield* HttpApiClient.group(ConfigsApi, { group: "configs", httpClient }); const list_ = filters => client.list({ query: { filters } }).pipe(Effect.mapError(ConfigsError("list"))); const create_ = config => SwarmConfigSpec.makeEffect(config).pipe(Effect.flatMap(payload => client.create({ payload })), Effect.mapError(ConfigsError("create"))); const inspect_ = identifier => client.inspect({ params: { identifier } }).pipe(Effect.mapError(ConfigsError("inspect"))); const delete_ = identifier => client.delete({ params: { identifier } }).pipe(Effect.mapError(ConfigsError("delete"))); const update_ = (identifier, version, config) => SwarmConfigSpec.makeEffect(config).pipe(Effect.flatMap(payload => client.update({ params: { identifier }, query: { version }, payload })), Effect.mapError(ConfigsError("update"))); return { list: list_, create: create_, inspect: inspect_, delete: delete_, update: update_ }; }) }) {} /** * Configs are application configurations that can be used by services. 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/Config */ export const ConfigsLayer = /*#__PURE__*/Layer.effect(Configs, Configs.make); /** * Configs are application configurations that can be used by services. 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/Config */ export const ConfigsLayerLocalSocket = /*#__PURE__*/ConfigsLayer.pipe(/*#__PURE__*/Layer.provide(/*#__PURE__*/makeAgnosticHttpClientLayer(/*#__PURE__*/MobyConnectionOptions.socket({ socketPath: "/var/run/docker.sock" })))); //# sourceMappingURL=configs.js.map