UNPKG

the-moby-effect

Version:
96 lines 5.11 kB
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 * as Tuple from "effect/Tuple"; import { RegistryAuthenticateOKBody as AuthResponse, DiskUsage, EventMessage, RegistryAuthConfig, SystemInfoResponse, SystemVersionResponse } from "../generated/index.js"; import { maybeAddQueryParameter } from "./common.js"; /** * @since 1.0.0 * @category Errors */ export const SystemsErrorTypeId = /*#__PURE__*/Symbol.for("@the-moby-effect/endpoints/SystemsError"); /** * @since 1.0.0 * @category Errors */ export const isSystemsError = u => Predicate.hasProperty(u, SystemsErrorTypeId); /** * @since 1.0.0 * @category Errors */ export class SystemsError extends /*#__PURE__*/PlatformError.TypeIdError(SystemsErrorTypeId, "SystemsError") { get message() { return `${this.method}`; } } /** * @since 1.0.0 * @category Tags * @see https://docs.docker.com/reference/api/engine/latest/#tag/System */ export class Systems extends /*#__PURE__*/Effect.Service()("@the-moby-effect/endpoints/System", { 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/System/operation/SystemAuth */ const auth_ = authConfig => Function.pipe(Schema.decode(RegistryAuthConfig)(authConfig), Effect.map(body => Tuple.make(HttpClientRequest.post("/auth"), body)), Effect.flatMap(Function.tupled(HttpClientRequest.schemaBodyJson(RegistryAuthConfig))), Effect.flatMap(client.execute), Effect.flatMap(HttpClientResponse.schemaBodyJson(AuthResponse)), Effect.mapError(cause => new SystemsError({ method: "auth", cause }))); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/System/operation/SystemInfo */ const info_ = () => Function.pipe(HttpClientRequest.get("/info"), client.execute, Effect.flatMap(HttpClientResponse.schemaBodyJson(SystemInfoResponse)), Effect.mapError(cause => new SystemsError({ method: "info", cause }))); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/System/operation/SystemVersion */ const version_ = () => Function.pipe(HttpClientRequest.get("/version"), client.execute, Effect.flatMap(HttpClientResponse.schemaBodyJson(SystemVersionResponse)), Effect.mapError(cause => new SystemsError({ method: "version", cause }))); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/System/operation/SystemPing */ const ping_ = () => Function.pipe(HttpClientRequest.get("/_ping"), client.execute, Effect.flatMap(response => response.text), Effect.flatMap(Schema.decodeUnknown(Schema.Literal("OK"))), Effect.mapError(cause => new SystemsError({ method: "ping", cause }))); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/System/operation/SystemPingHead */ const pingHead_ = () => Function.pipe(HttpClientRequest.head("/_ping"), client.execute, Effect.asVoid, Effect.mapError(cause => new SystemsError({ method: "pingHead", cause }))); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/System/operation/SystemEvents */ const events_ = options => Function.pipe(HttpClientRequest.get("/events"), maybeAddQueryParameter("since", Option.fromNullable(options?.since)), maybeAddQueryParameter("until", Option.fromNullable(options?.until)), maybeAddQueryParameter("filters", Function.pipe(options?.filters, Option.fromNullable, Option.map(JSON.stringify))), client.execute, HttpClientResponse.stream, Stream.decodeText(), Stream.splitLines, Stream.flatMap(Schema.decode(Schema.parseJson(EventMessage))), Stream.mapError(cause => new SystemsError({ method: "events", cause }))); /** @see https://docs.docker.com/reference/api/engine/latest/#tag/System/operation/SystemDataUsage */ const dataUsage_ = options => Function.pipe(HttpClientRequest.get("/system/df"), maybeAddQueryParameter("type", Option.fromNullable(options?.type)), client.execute, Effect.flatMap(HttpClientResponse.schemaBodyJson(DiskUsage)), Effect.mapError(cause => new SystemsError({ method: "dataUsage", cause }))); return { auth: auth_, info: info_, version: version_, ping: ping_, pingHead: pingHead_, events: events_, dataUsage: dataUsage_ }; }) }) {} /** * @since 1.0.0 * @category Layers * @see https://docs.docker.com/reference/api/engine/latest/#tag/System */ export const SystemsLayer = Systems.Default; //# sourceMappingURL=system.js.map