the-moby-effect
Version:
Moby/Docker API client built using effect-ts
112 lines (111 loc) • 6.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isSwarmsError = exports.SwarmsErrorTypeId = exports.SwarmsError = exports.SwarmLayer = exports.Swarm = 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 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 SwarmsErrorTypeId = exports.SwarmsErrorTypeId = /*#__PURE__*/Symbol.for("@the-moby-effect/endpoints/SwarmsError");
/**
* @since 1.0.0
* @category Errors
*/
const isSwarmsError = u => Predicate.hasProperty(u, SwarmsErrorTypeId);
/**
* @since 1.0.0
* @category Errors
*/
exports.isSwarmsError = isSwarmsError;
class SwarmsError extends /*#__PURE__*/PlatformError.TypeIdError(SwarmsErrorTypeId, "SwarmsError") {
get message() {
return `${this.method}`;
}
}
/**
* Engines can be clustered together in a swarm. Refer to the swarm mode
* documentation for more information.
*
* @since 1.0.0
* @category Tags
* @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm
*/
exports.SwarmsError = SwarmsError;
class Swarm extends /*#__PURE__*/Effect.Service()("@the-moby-effect/endpoints/Swarm", {
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/Swarm/operation/SwarmInspect */
const inspect_ = () => Function.pipe(HttpClientRequest.get("/swarm"), client.execute, Effect.flatMap(HttpClientResponse.schemaBodyJson(_index.Swarm)), Effect.mapError(cause => new SwarmsError({
method: "inspect",
cause
})));
/** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmInit */
const init_ = options => Function.pipe(Schema.decode(_index.SwarmInitRequest)(options), Effect.map(body => Tuple.make(HttpClientRequest.post("/swarm/init"), body)), Effect.flatMap(Function.tupled(HttpClientRequest.schemaBodyJson(_index.SwarmInitRequest))), Effect.flatMap(client.execute), Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.String)), Effect.mapError(cause => new SwarmsError({
method: "init",
cause
})));
/** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmJoin */
const join_ = options => Function.pipe(Schema.decode(_index.SwarmJoinRequest)(options), Effect.map(body => Tuple.make(HttpClientRequest.post("/swarm/join"), body)), Effect.flatMap(Function.tupled(HttpClientRequest.schemaBodyJson(_index.SwarmJoinRequest))), Effect.flatMap(client.execute), Effect.asVoid, Effect.mapError(cause => new SwarmsError({
method: "join",
cause
})));
/** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmLeave */
const leave_ = options => Function.pipe(HttpClientRequest.post("/swarm/leave"), (0, _common.maybeAddQueryParameter)("force", Option.fromNullable(options.force)), client.execute, Effect.asVoid, Effect.mapError(cause => new SwarmsError({
method: "leave",
cause
})));
/** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmUpdate */
const update_ = options => Function.pipe(HttpClientRequest.post("/swarm/update"), (0, _common.maybeAddQueryParameter)("version", Option.some(options.version)), (0, _common.maybeAddQueryParameter)("rotateWorkerToken", Option.fromNullable(options.rotateWorkerToken)), (0, _common.maybeAddQueryParameter)("rotateManagerToken", Option.fromNullable(options.rotateManagerToken)), (0, _common.maybeAddQueryParameter)("rotateManagerUnlockKey", Option.fromNullable(options.rotateManagerUnlockKey)), HttpClientRequest.schemaBodyJson(_index.SwarmSpec)(options.spec), Effect.flatMap(client.execute), Effect.asVoid, Effect.mapError(cause => new SwarmsError({
method: "update",
cause
})));
/** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmUnlockkey */
const unlockkey_ = () => Function.pipe(HttpClientRequest.get("/swarm/unlockkey"), client.execute, Effect.flatMap(HttpClientResponse.schemaBodyJson(_index.SwarmUnlockKeyResponse)), Effect.mapError(cause => new SwarmsError({
method: "unlockkey",
cause
})));
/** @see https://docs.docker.com/reference/api/engine/latest/#tag/Swarm/operation/SwarmUnlock */
const unlock_ = options => Function.pipe(Schema.decode(_index.SwarmUnlockRequest)(options), Effect.map(body => Tuple.make(HttpClientRequest.post("/swarm/unlock"), body)), Effect.flatMap(Function.tupled(HttpClientRequest.schemaBodyJson(_index.SwarmUnlockRequest))), Effect.flatMap(client.execute), Effect.asVoid, Effect.mapError(cause => new SwarmsError({
method: "unlock",
cause
})));
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
*/
exports.Swarm = Swarm;
const SwarmLayer = exports.SwarmLayer = Swarm.Default;
//# sourceMappingURL=swarm.js.map