the-moby-effect
Version:
Moby/Docker API client built using effect-ts
107 lines (106 loc) • 6.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isSystemsError = exports.SystemsLayer = exports.SystemsErrorTypeId = exports.SystemsError = exports.Systems = void 0;
var PlatformError = _interopRequireWildcard(require("@effect/platform/Error"));
var HttpClient = _interopRequireWildcard(require("@effect/platform/HttpClient"));
var HttpClientRequest = _interopRequireWildcard(require("@effect/platform/HttpClientRequest"));
var HttpClientResponse = _interopRequireWildcard(require("@effect/platform/HttpClientResponse"));
var Effect = _interopRequireWildcard(require("effect/Effect"));
var Function = _interopRequireWildcard(require("effect/Function"));
var Option = _interopRequireWildcard(require("effect/Option"));
var Predicate = _interopRequireWildcard(require("effect/Predicate"));
var Schema = _interopRequireWildcard(require("effect/Schema"));
var Stream = _interopRequireWildcard(require("effect/Stream"));
var Tuple = _interopRequireWildcard(require("effect/Tuple"));
var _index = require("../generated/index.js");
var _common = require("./common.js");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/**
* @since 1.0.0
* @category Errors
*/
const SystemsErrorTypeId = exports.SystemsErrorTypeId = /*#__PURE__*/Symbol.for("@the-moby-effect/endpoints/SystemsError");
/**
* @since 1.0.0
* @category Errors
*/
const isSystemsError = u => Predicate.hasProperty(u, SystemsErrorTypeId);
/**
* @since 1.0.0
* @category Errors
*/
exports.isSystemsError = isSystemsError;
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
*/
exports.SystemsError = SystemsError;
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(_index.RegistryAuthConfig)(authConfig), Effect.map(body => Tuple.make(HttpClientRequest.post("/auth"), body)), Effect.flatMap(Function.tupled(HttpClientRequest.schemaBodyJson(_index.RegistryAuthConfig))), Effect.flatMap(client.execute), Effect.flatMap(HttpClientResponse.schemaBodyJson(_index.RegistryAuthenticateOKBody)), 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(_index.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(_index.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"), (0, _common.maybeAddQueryParameter)("since", Option.fromNullable(options?.since)), (0, _common.maybeAddQueryParameter)("until", Option.fromNullable(options?.until)), (0, _common.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(_index.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"), (0, _common.maybeAddQueryParameter)("type", Option.fromNullable(options?.type)), client.execute, Effect.flatMap(HttpClientResponse.schemaBodyJson(_index.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
*/
exports.Systems = Systems;
const SystemsLayer = exports.SystemsLayer = Systems.Default;
//# sourceMappingURL=system.js.map