the-moby-effect 1.43.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +42 -0
- package/dist/src/agent-helpers.d.ts +59 -0
- package/dist/src/agent-helpers.js +84 -0
- package/dist/src/agent-helpers.js.map +1 -0
- package/dist/src/configs.d.ts +105 -0
- package/dist/src/configs.js +29 -0
- package/dist/src/configs.js.map +1 -0
- package/dist/src/containers.d.ts +611 -0
- package/dist/src/containers.js +82 -0
- package/dist/src/containers.js.map +1 -0
- package/dist/src/custom-helpers.d.ts +23 -0
- package/dist/src/custom-helpers.js +41 -0
- package/dist/src/custom-helpers.js.map +1 -0
- package/dist/src/distribution.d.ts +28 -0
- package/dist/src/distribution.js +21 -0
- package/dist/src/distribution.js.map +1 -0
- package/dist/src/execs.d.ts +69 -0
- package/dist/src/execs.js +26 -0
- package/dist/src/execs.js.map +1 -0
- package/dist/src/images.d.ts +657 -0
- package/dist/src/images.js +61 -0
- package/dist/src/images.js.map +1 -0
- package/dist/src/index.d.ts +38 -0
- package/dist/src/index.js +38 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/networks.d.ts +151 -0
- package/dist/src/networks.js +40 -0
- package/dist/src/networks.js.map +1 -0
- package/dist/src/nodes.d.ts +99 -0
- package/dist/src/nodes.js +27 -0
- package/dist/src/nodes.js.map +1 -0
- package/dist/src/plugins.d.ts +253 -0
- package/dist/src/plugins.js +47 -0
- package/dist/src/plugins.js.map +1 -0
- package/dist/src/request-helpers.d.ts +6 -0
- package/dist/src/request-helpers.js +15 -0
- package/dist/src/request-helpers.js.map +1 -0
- package/dist/src/schemas.d.ts +7279 -0
- package/dist/src/schemas.js +3772 -0
- package/dist/src/schemas.js.map +1 -0
- package/dist/src/secrets.d.ts +100 -0
- package/dist/src/secrets.js +29 -0
- package/dist/src/secrets.js.map +1 -0
- package/dist/src/services.d.ts +185 -0
- package/dist/src/services.js +32 -0
- package/dist/src/services.js.map +1 -0
- package/dist/src/session.d.ts +29 -0
- package/dist/src/session.js +20 -0
- package/dist/src/session.js.map +1 -0
- package/dist/src/swarm.d.ts +80 -0
- package/dist/src/swarm.js +39 -0
- package/dist/src/swarm.js.map +1 -0
- package/dist/src/system.d.ts +100 -0
- package/dist/src/system.js +40 -0
- package/dist/src/system.js.map +1 -0
- package/dist/src/tasks.d.ts +102 -0
- package/dist/src/tasks.js +26 -0
- package/dist/src/tasks.js.map +1 -0
- package/dist/src/volumes.d.ts +143 -0
- package/dist/src/volumes.js +29 -0
- package/dist/src/volumes.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as NodeSocket from "@effect/experimental/Socket/Node";
|
|
2
|
+
import * as NodeHttp from "@effect/platform-node/HttpClient";
|
|
3
|
+
import { Context, Data, Effect, Layer, pipe } from "effect";
|
|
4
|
+
import { MobyConnectionAgent, MobyHttpClientLive, getAgent, } from "./agent-helpers.js";
|
|
5
|
+
import { responseErrorHandler } from "./request-helpers.js";
|
|
6
|
+
export class SessionsError extends Data.TaggedError("SessionsError") {
|
|
7
|
+
}
|
|
8
|
+
const make = Effect.gen(function* (_) {
|
|
9
|
+
const agent = yield* _(MobyConnectionAgent);
|
|
10
|
+
const defaultClient = yield* _(NodeHttp.client.Client);
|
|
11
|
+
const client = defaultClient.pipe(NodeHttp.client.mapRequest(NodeHttp.request.prependUrl(agent.nodeRequestUrl)), NodeHttp.client.filterStatus((status) => status === 101));
|
|
12
|
+
const responseHandler = (method) => responseErrorHandler((message) => new SessionsError({ method, message }));
|
|
13
|
+
const session_ = () => pipe(NodeHttp.request.post("/session"), NodeHttp.request.setHeader("Upgrade", "h2c"), NodeHttp.request.setHeader("Connection", "Upgrade"), client, Effect.map((response) => response.source.socket), Effect.flatMap((socket) => NodeSocket.fromNetSocket(Effect.sync(() => socket))), Effect.catchAll(responseHandler("sessions")));
|
|
14
|
+
return { session: session_ };
|
|
15
|
+
});
|
|
16
|
+
export const Sessions = Context.Tag("the-moby-effect/Sessions");
|
|
17
|
+
export const layer = Layer.effect(Sessions, make).pipe(Layer.provide(MobyHttpClientLive));
|
|
18
|
+
export const fromAgent = (agent) => layer.pipe(Layer.provide(Layer.scoped(MobyConnectionAgent, agent)));
|
|
19
|
+
export const fromConnectionOptions = (connectionOptions) => fromAgent(getAgent(connectionOptions));
|
|
20
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kCAAkC,CAAC;AAC/D,OAAO,KAAK,QAAQ,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAS,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnE,OAAO,EAGH,mBAAmB,EAEnB,kBAAkB,EAClB,QAAQ,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,OAAO,aAAc,SAAQ,IAAI,CAAC,WAAW,CAAC,eAAe,CAGjE;CAAG;AAgBL,MAAM,IAAI,GAA0F,MAAM,CAAC,GAAG,CAC1G,QAAQ,CAAC,EAAE,CAAiB;IACxB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC;IAC5C,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAC7B,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,EAC7E,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,EA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AC,MAAM,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,iBAAwC,EAAE,EAAE,CAC9E,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import * as Schema from "@effect/schema/Schema";
|
|
2
|
+
import { Context, Effect, Layer, Scope } from "effect";
|
|
3
|
+
import { IMobyConnectionAgent, MobyConnectionOptions } from "./agent-helpers.js";
|
|
4
|
+
import { Swarm, SwarmInitRequest, SwarmSpec, SwarmUnlockRequest, UnlockKeyResponse } from "./schemas.js";
|
|
5
|
+
declare const SwarmsError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<Omit<A, keyof import("effect/Equal").Equal>, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" | keyof import("effect/Equal").Equal ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
6
|
+
readonly _tag: "SwarmsError";
|
|
7
|
+
} & Readonly<A>;
|
|
8
|
+
export declare class SwarmsError extends SwarmsError_base<{
|
|
9
|
+
method: string;
|
|
10
|
+
message: string;
|
|
11
|
+
}> {
|
|
12
|
+
}
|
|
13
|
+
export interface SwarmLeaveOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Force leave swarm, even if this is the last manager or that it will break
|
|
16
|
+
* the cluster.
|
|
17
|
+
*/
|
|
18
|
+
readonly force?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface SwarmUpdateOptions {
|
|
21
|
+
readonly body: SwarmSpec;
|
|
22
|
+
/**
|
|
23
|
+
* The version number of the swarm object being updated. This is required to
|
|
24
|
+
* avoid conflicting writes.
|
|
25
|
+
*/
|
|
26
|
+
readonly version: number;
|
|
27
|
+
/** Rotate the worker join token. */
|
|
28
|
+
readonly rotateWorkerToken?: boolean;
|
|
29
|
+
/** Rotate the manager join token. */
|
|
30
|
+
readonly rotateManagerToken?: boolean;
|
|
31
|
+
/** Rotate the manager unlock key. */
|
|
32
|
+
readonly rotateManagerUnlockKey?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface Swarms {
|
|
35
|
+
/** Inspect swarm */
|
|
36
|
+
readonly inspect: () => Effect.Effect<never, SwarmsError, Readonly<Swarm>>;
|
|
37
|
+
/**
|
|
38
|
+
* Initialize a new swarm
|
|
39
|
+
*
|
|
40
|
+
* @param body -
|
|
41
|
+
*/
|
|
42
|
+
readonly init: (options: Schema.Schema.To<typeof SwarmInitRequest.struct>) => Effect.Effect<never, SwarmsError, Readonly<string>>;
|
|
43
|
+
/**
|
|
44
|
+
* Join an existing swarm
|
|
45
|
+
*
|
|
46
|
+
* @param body -
|
|
47
|
+
*/
|
|
48
|
+
readonly join: (options: Schema.Schema.To<typeof SwarmInitRequest.struct>) => Effect.Effect<never, SwarmsError, void>;
|
|
49
|
+
/**
|
|
50
|
+
* Leave a swarm
|
|
51
|
+
*
|
|
52
|
+
* @param force - Force leave swarm, even if this is the last manager or
|
|
53
|
+
* that it will break the cluster.
|
|
54
|
+
*/
|
|
55
|
+
readonly leave: (options: SwarmLeaveOptions) => Effect.Effect<never, SwarmsError, void>;
|
|
56
|
+
/**
|
|
57
|
+
* Update a swarm
|
|
58
|
+
*
|
|
59
|
+
* @param body -
|
|
60
|
+
* @param version - The version number of the swarm object being updated.
|
|
61
|
+
* This is required to avoid conflicting writes.
|
|
62
|
+
* @param rotateWorkerToken - Rotate the worker join token.
|
|
63
|
+
* @param rotateManagerToken - Rotate the manager join token.
|
|
64
|
+
* @param rotateManagerUnlockKey - Rotate the manager unlock key.
|
|
65
|
+
*/
|
|
66
|
+
readonly update: (options: SwarmUpdateOptions) => Effect.Effect<never, SwarmsError, void>;
|
|
67
|
+
/** Get the unlock key */
|
|
68
|
+
readonly unlockkey: () => Effect.Effect<never, SwarmsError, UnlockKeyResponse>;
|
|
69
|
+
/**
|
|
70
|
+
* Unlock a locked manager
|
|
71
|
+
*
|
|
72
|
+
* @param body -
|
|
73
|
+
*/
|
|
74
|
+
readonly unlock: (options: Schema.Schema.To<typeof SwarmUnlockRequest.struct>) => Effect.Effect<never, SwarmsError, void>;
|
|
75
|
+
}
|
|
76
|
+
export declare const Swarms: Context.Tag<Swarms, Swarms>;
|
|
77
|
+
export declare const layer: Layer.Layer<IMobyConnectionAgent, never, Swarms>;
|
|
78
|
+
export declare const fromAgent: (agent: Effect.Effect<Scope.Scope, never, IMobyConnectionAgent>) => Layer.Layer<never, never, Swarms>;
|
|
79
|
+
export declare const fromConnectionOptions: (connectionOptions: MobyConnectionOptions) => Layer.Layer<never, never, Swarms>;
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as NodeHttp from "@effect/platform-node/HttpClient";
|
|
2
|
+
import * as Schema from "@effect/schema/Schema";
|
|
3
|
+
import { Context, Data, Effect, Layer, pipe } from "effect";
|
|
4
|
+
import { MobyConnectionAgent, MobyHttpClientLive, getAgent, } from "./agent-helpers.js";
|
|
5
|
+
import { addQueryParameter, responseErrorHandler } from "./request-helpers.js";
|
|
6
|
+
import { Swarm, SwarmInitRequest, SwarmJoinRequest, SwarmSpec, SwarmUnlockRequest, UnlockKeyResponse, } from "./schemas.js";
|
|
7
|
+
export class SwarmsError extends Data.TaggedError("SwarmsError") {
|
|
8
|
+
}
|
|
9
|
+
const make = Effect.gen(function* (_) {
|
|
10
|
+
const agent = yield* _(MobyConnectionAgent);
|
|
11
|
+
const defaultClient = yield* _(NodeHttp.client.Client);
|
|
12
|
+
const client = defaultClient.pipe(NodeHttp.client.mapRequest(NodeHttp.request.prependUrl(`${agent.nodeRequestUrl}/swarm`)), NodeHttp.client.filterStatusOk);
|
|
13
|
+
const voidClient = client.pipe(NodeHttp.client.transform(Effect.asUnit));
|
|
14
|
+
const SwarmClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(Swarm)));
|
|
15
|
+
const StringClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(Schema.string)));
|
|
16
|
+
const UnlockKeyResponseClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(UnlockKeyResponse)));
|
|
17
|
+
const responseHandler = (method) => responseErrorHandler((message) => new SwarmsError({ method, message }));
|
|
18
|
+
const inspect_ = () => pipe(NodeHttp.request.get("/"), SwarmClient, Effect.catchAll(responseHandler("inspect")));
|
|
19
|
+
const init_ = (options) => pipe(NodeHttp.request.post("/init"), NodeHttp.request.schemaBody(SwarmInitRequest)(new SwarmInitRequest(options)), Effect.flatMap(StringClient), Effect.catchAll(responseHandler("init")));
|
|
20
|
+
const join_ = (options) => pipe(NodeHttp.request.post("/join"), NodeHttp.request.schemaBody(SwarmJoinRequest)(new SwarmJoinRequest(options)), Effect.flatMap(voidClient), Effect.catchAll(responseHandler("join")));
|
|
21
|
+
const leave_ = (options) => pipe(NodeHttp.request.post("/leave"), addQueryParameter("force", options.force), voidClient, Effect.catchAll(responseHandler("leave")));
|
|
22
|
+
const update_ = (options) => pipe(NodeHttp.request.post("/update"), addQueryParameter("version", options.version), addQueryParameter("rotateWorkerToken", options.rotateWorkerToken), addQueryParameter("rotateManagerToken", options.rotateManagerToken), addQueryParameter("rotateManagerUnlockKey", options.rotateManagerUnlockKey), NodeHttp.request.schemaBody(SwarmSpec)(options.body ?? new SwarmSpec({})), Effect.flatMap(voidClient), Effect.catchAll(responseHandler("update")));
|
|
23
|
+
const unlockkey_ = () => pipe(NodeHttp.request.get("/unlockkey"), UnlockKeyResponseClient, Effect.catchAll(responseHandler("unlockkey")));
|
|
24
|
+
const unlock_ = (options) => pipe(NodeHttp.request.post("/unlock"), NodeHttp.request.schemaBody(SwarmUnlockRequest)(new SwarmUnlockRequest(options)), Effect.flatMap(voidClient), Effect.catchAll(responseHandler("unlock")));
|
|
25
|
+
return {
|
|
26
|
+
inspect: inspect_,
|
|
27
|
+
init: init_,
|
|
28
|
+
join: join_,
|
|
29
|
+
leave: leave_,
|
|
30
|
+
update: update_,
|
|
31
|
+
unlockkey: unlockkey_,
|
|
32
|
+
unlock: unlock_,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
export const Swarms = Context.Tag("the-moby-effects");
|
|
36
|
+
export const layer = Layer.effect(Swarms, make).pipe(Layer.provide(MobyHttpClientLive));
|
|
37
|
+
export const fromAgent = (agent) => layer.pipe(Layer.provide(Layer.scoped(MobyConnectionAgent, agent)));
|
|
38
|
+
export const fromConnectionOptions = (connectionOptions) => fromAgent(getAgent(connectionOptions));
|
|
39
|
+
//# sourceMappingURL=swarm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swarm.js","sourceRoot":"","sources":["../../src/swarm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kCAAkC,CAAC;AAC7D,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAS,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnE,OAAO,EAEH,mBAAmB,EAEnB,kBAAkB,EAClB,QAAQ,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EACH,KAAK,EACL,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,iBAAiB,GACpB,MAAM,cAAc,CAAC;AAEtB,MAAM,OAAO,WAAY,SAAQ,IAAI,CAAC,WAAW,CAAC,aAAa,CAG7D;CAAG;AAgFL,MAAM,IAAI,GAAwF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAClH,CAAiB;IAEjB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC;IAC5C,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAA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AAC,CAAC;AAExF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAA8D,EAAE,EAAE,CACxF,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,iBAAwC,EAAE,EAAE,CAC9E,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as Schema from "@effect/schema/Schema";
|
|
2
|
+
import { Context, Effect, Layer, Scope } from "effect";
|
|
3
|
+
import { IMobyConnectionAgent, MobyConnectionOptions } from "./agent-helpers.js";
|
|
4
|
+
import { AuthConfig, EventMessage, SystemAuthResponse, SystemDataUsageResponse, SystemInfo, SystemVersion } from "./schemas.js";
|
|
5
|
+
declare const SystemsError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<Omit<A, keyof import("effect/Equal").Equal>, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" | keyof import("effect/Equal").Equal ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
6
|
+
readonly _tag: "SystemsError";
|
|
7
|
+
} & Readonly<A>;
|
|
8
|
+
export declare class SystemsError extends SystemsError_base<{
|
|
9
|
+
method: string;
|
|
10
|
+
message: string;
|
|
11
|
+
}> {
|
|
12
|
+
}
|
|
13
|
+
export interface SystemEventsOptions {
|
|
14
|
+
/** Show events created since this timestamp then stream new events. */
|
|
15
|
+
readonly since?: string;
|
|
16
|
+
/** Show events created until this timestamp then stop streaming. */
|
|
17
|
+
readonly until?: string;
|
|
18
|
+
/**
|
|
19
|
+
* A JSON encoded value of filters (a `map[string][]string`) to process on
|
|
20
|
+
* the event list. Available filters:
|
|
21
|
+
*
|
|
22
|
+
* - `config=<string>` config name or ID
|
|
23
|
+
* - `container=<string>` container name or ID
|
|
24
|
+
* - `daemon=<string>` daemon name or ID
|
|
25
|
+
* - `event=<string>` event type
|
|
26
|
+
* - `image=<string>` image name or ID
|
|
27
|
+
* - `label=<string>` image or container label
|
|
28
|
+
* - `network=<string>` network name or ID
|
|
29
|
+
* - `node=<string>` node ID
|
|
30
|
+
* - `plugin`=<string> plugin name or ID
|
|
31
|
+
* - `scope`=<string> local or swarm
|
|
32
|
+
* - `secret=<string>` secret name or ID
|
|
33
|
+
* - `service=<string>` service name or ID
|
|
34
|
+
* - `type=<string>` object to filter by, one of `container`, `image`,
|
|
35
|
+
* `volume`, `network`, `daemon`, `plugin`, `node`, `service`, `secret` or
|
|
36
|
+
* `config`
|
|
37
|
+
* - `volume=<string>` volume name
|
|
38
|
+
*/
|
|
39
|
+
readonly filters?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface SystemDataUsageOptions {
|
|
42
|
+
/** Object types, for which to compute and return data. */
|
|
43
|
+
readonly type?: Array<"container" | "image" | "volume" | "build-cache"> | undefined;
|
|
44
|
+
}
|
|
45
|
+
export interface Systems {
|
|
46
|
+
/**
|
|
47
|
+
* Check auth configuration
|
|
48
|
+
*
|
|
49
|
+
* @param authConfig - Authentication to check
|
|
50
|
+
*/
|
|
51
|
+
readonly auth: (options: Schema.Schema.From<typeof AuthConfig.struct>) => Effect.Effect<never, SystemsError, SystemAuthResponse>;
|
|
52
|
+
/** Get system information */
|
|
53
|
+
readonly info: () => Effect.Effect<never, SystemsError, Readonly<SystemInfo>>;
|
|
54
|
+
/** Get version */
|
|
55
|
+
readonly version: () => Effect.Effect<never, SystemsError, Readonly<SystemVersion>>;
|
|
56
|
+
/** Ping */
|
|
57
|
+
readonly ping: () => Effect.Effect<never, SystemsError, Readonly<string>>;
|
|
58
|
+
/** Ping */
|
|
59
|
+
readonly pingHead: () => Effect.Effect<never, SystemsError, void>;
|
|
60
|
+
/**
|
|
61
|
+
* Monitor events
|
|
62
|
+
*
|
|
63
|
+
* @param since - Show events created since this timestamp then stream new
|
|
64
|
+
* events.
|
|
65
|
+
* @param until - Show events created until this timestamp then stop
|
|
66
|
+
* streaming.
|
|
67
|
+
* @param filters - A JSON encoded value of filters (a
|
|
68
|
+
* `map[string][]string`) to process on the event list. Available
|
|
69
|
+
* filters:
|
|
70
|
+
*
|
|
71
|
+
* - `config=<string>` config name or ID
|
|
72
|
+
* - `container=<string>` container name or ID
|
|
73
|
+
* - `daemon=<string>` daemon name or ID
|
|
74
|
+
* - `event=<string>` event type
|
|
75
|
+
* - `image=<string>` image name or ID
|
|
76
|
+
* - `label=<string>` image or container label
|
|
77
|
+
* - `network=<string>` network name or ID
|
|
78
|
+
* - `node=<string>` node ID
|
|
79
|
+
* - `plugin`=<string> plugin name or ID
|
|
80
|
+
* - `scope`=<string> local or swarm
|
|
81
|
+
* - `secret=<string>` secret name or ID
|
|
82
|
+
* - `service=<string>` service name or ID
|
|
83
|
+
* - `type=<string>` object to filter by, one of `container`, `image`,
|
|
84
|
+
* `volume`, `network`, `daemon`, `plugin`, `node`, `service`,
|
|
85
|
+
* `secret` or `config`
|
|
86
|
+
* - `volume=<string>` volume name
|
|
87
|
+
*/
|
|
88
|
+
readonly events: (options: SystemEventsOptions) => Effect.Effect<never, SystemsError, EventMessage>;
|
|
89
|
+
/**
|
|
90
|
+
* Get data usage information
|
|
91
|
+
*
|
|
92
|
+
* @param type - Object types, for which to compute and return data.
|
|
93
|
+
*/
|
|
94
|
+
readonly dataUsage: (options?: SystemDataUsageOptions | undefined) => Effect.Effect<never, SystemsError, SystemDataUsageResponse>;
|
|
95
|
+
}
|
|
96
|
+
export declare const Systems: Context.Tag<Systems, Systems>;
|
|
97
|
+
export declare const layer: Layer.Layer<IMobyConnectionAgent, never, Systems>;
|
|
98
|
+
export declare const fromAgent: (agent: Effect.Effect<Scope.Scope, never, IMobyConnectionAgent>) => Layer.Layer<never, never, Systems>;
|
|
99
|
+
export declare const fromConnectionOptions: (connectionOptions: MobyConnectionOptions) => Layer.Layer<never, never, Systems>;
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as NodeHttp from "@effect/platform-node/HttpClient";
|
|
2
|
+
import { Context, Data, Effect, Layer, pipe } from "effect";
|
|
3
|
+
import { MobyConnectionAgent, MobyHttpClientLive, getAgent, } from "./agent-helpers.js";
|
|
4
|
+
import { addQueryParameter, responseErrorHandler } from "./request-helpers.js";
|
|
5
|
+
import { AuthConfig, EventMessage, SystemAuthResponse, SystemDataUsageResponse, SystemInfo, SystemVersion, } from "./schemas.js";
|
|
6
|
+
export class SystemsError extends Data.TaggedError("SystemsError") {
|
|
7
|
+
}
|
|
8
|
+
const make = Effect.gen(function* (_) {
|
|
9
|
+
const agent = yield* _(MobyConnectionAgent);
|
|
10
|
+
const defaultClient = yield* _(NodeHttp.client.Client);
|
|
11
|
+
const client = defaultClient.pipe(NodeHttp.client.mapRequest(NodeHttp.request.prependUrl(agent.nodeRequestUrl)), NodeHttp.client.filterStatusOk);
|
|
12
|
+
const voidClient = client.pipe(NodeHttp.client.transform(Effect.asUnit));
|
|
13
|
+
const SystemInfoClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(SystemInfo)));
|
|
14
|
+
const SystemAuthResponseClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(SystemAuthResponse)));
|
|
15
|
+
const SystemVersionClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(SystemVersion)));
|
|
16
|
+
const SystemEventsResponseClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(EventMessage)));
|
|
17
|
+
const SystemDataUsageResponseClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(SystemDataUsageResponse)));
|
|
18
|
+
const responseHandler = (method) => responseErrorHandler((message) => new SystemsError({ method, message }));
|
|
19
|
+
const auth_ = (options) => pipe(NodeHttp.request.post("/auth"), NodeHttp.request.schemaBody(AuthConfig)(new AuthConfig(options)), Effect.flatMap(SystemAuthResponseClient), Effect.catchAll(responseHandler("auth")));
|
|
20
|
+
const info_ = () => pipe(NodeHttp.request.get("/info"), SystemInfoClient, Effect.catchAll(responseHandler("info")));
|
|
21
|
+
const version_ = () => pipe(NodeHttp.request.get("/version"), SystemVersionClient, Effect.catchAll(responseHandler("version")));
|
|
22
|
+
const ping_ = () => pipe(NodeHttp.request.get("/_ping"), client, Effect.flatMap((response) => response.text), Effect.catchAll(responseHandler("ping")));
|
|
23
|
+
const pingHead_ = () => pipe(NodeHttp.request.head("/_ping"), voidClient, Effect.catchAll(responseHandler("pingHead")));
|
|
24
|
+
const events_ = (options) => pipe(NodeHttp.request.get("/events"), addQueryParameter("since", options.since), addQueryParameter("until", options.until), addQueryParameter("filters", options.filters), SystemEventsResponseClient, Effect.catchAll(responseHandler("events")));
|
|
25
|
+
const dataUsage_ = (options) => pipe(NodeHttp.request.get("/system/df"), addQueryParameter("type", options?.type), SystemDataUsageResponseClient, Effect.catchAll(responseHandler("dataUsage")));
|
|
26
|
+
return {
|
|
27
|
+
auth: auth_,
|
|
28
|
+
info: info_,
|
|
29
|
+
version: version_,
|
|
30
|
+
ping: ping_,
|
|
31
|
+
pingHead: pingHead_,
|
|
32
|
+
events: events_,
|
|
33
|
+
dataUsage: dataUsage_,
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
export const Systems = Context.Tag("the-moby-effect/Systems");
|
|
37
|
+
export const layer = Layer.effect(Systems, make).pipe(Layer.provide(MobyHttpClientLive));
|
|
38
|
+
export const fromAgent = (agent) => layer.pipe(Layer.provide(Layer.scoped(MobyConnectionAgent, agent)));
|
|
39
|
+
export const fromConnectionOptions = (connectionOptions) => fromAgent(getAgent(connectionOptions));
|
|
40
|
+
//# sourceMappingURL=system.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system.js","sourceRoot":"","sources":["../../src/system.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kCAAkC,CAAC;AAE7D,O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AI,CAAC,EACxC,6BAA6B,EAC7B,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAChD,CAAC;IAEN,OAAO;QACH,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,KAAK;QACX,QAAQ,EAAE,SAAS;QACnB,MAAM,EAAE,OAAO;QACf,SAAS,EAAE,UAAU;KACxB,CAAC;AACN,CAAC,CACJ,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAU,yBAAyB,CAAC,CAAC;AACvE,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAEzF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAA8D,EAAE,EAAE,CACxF,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,iBAAwC,EAAE,EAAE,CAC9E,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Scope, Stream } from "effect";
|
|
2
|
+
import { IMobyConnectionAgent, MobyConnectionOptions } from "./agent-helpers.js";
|
|
3
|
+
import { Task } from "./schemas.js";
|
|
4
|
+
declare const TasksError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<Omit<A, keyof import("effect/Equal").Equal>, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" | keyof import("effect/Equal").Equal ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
5
|
+
readonly _tag: "TasksError";
|
|
6
|
+
} & Readonly<A>;
|
|
7
|
+
export declare class TasksError extends TasksError_base<{
|
|
8
|
+
method: string;
|
|
9
|
+
message: string;
|
|
10
|
+
}> {
|
|
11
|
+
}
|
|
12
|
+
export interface TaskListOptions {
|
|
13
|
+
/**
|
|
14
|
+
* A JSON encoded value of the filters (a `map[string][]string`) to process
|
|
15
|
+
* on the tasks list.
|
|
16
|
+
*
|
|
17
|
+
* Available filters:
|
|
18
|
+
*
|
|
19
|
+
* - `desired-state=(running | shutdown | accepted)`
|
|
20
|
+
* - `id=<task id>`
|
|
21
|
+
* - `label=key` or `label="key=value"`
|
|
22
|
+
* - `name=<task name>`
|
|
23
|
+
* - `node=<node id or name>`
|
|
24
|
+
* - `service=<service name>`
|
|
25
|
+
*/
|
|
26
|
+
readonly filters?: {
|
|
27
|
+
"desired-state"?: ["running" | "shutdown" | "accepted"] | undefined;
|
|
28
|
+
id?: [string] | undefined;
|
|
29
|
+
label?: string[] | undefined;
|
|
30
|
+
name?: [string] | undefined;
|
|
31
|
+
node?: [string] | undefined;
|
|
32
|
+
service?: [string] | undefined;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface TaskInspectOptions {
|
|
36
|
+
/** ID of the task */
|
|
37
|
+
readonly id: string;
|
|
38
|
+
}
|
|
39
|
+
export interface TaskLogsOptions {
|
|
40
|
+
/** ID of the task */
|
|
41
|
+
readonly id: string;
|
|
42
|
+
/** Show task context and extra details provided to logs. */
|
|
43
|
+
readonly details?: boolean;
|
|
44
|
+
/** Keep connection after returning logs. */
|
|
45
|
+
readonly follow?: boolean;
|
|
46
|
+
/** Return logs from `stdout` */
|
|
47
|
+
readonly stdout?: boolean;
|
|
48
|
+
/** Return logs from `stderr` */
|
|
49
|
+
readonly stderr?: boolean;
|
|
50
|
+
/** Only return logs since this time, as a UNIX timestamp */
|
|
51
|
+
readonly since?: number;
|
|
52
|
+
/** Add timestamps to every log line */
|
|
53
|
+
readonly timestamps?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Only return this number of log lines from the end of the logs. Specify as
|
|
56
|
+
* an integer or `all` to output all log lines.
|
|
57
|
+
*/
|
|
58
|
+
readonly tail?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface Tasks {
|
|
61
|
+
/**
|
|
62
|
+
* List tasks
|
|
63
|
+
*
|
|
64
|
+
* @param filters - A JSON encoded value of the filters (a
|
|
65
|
+
* `map[string][]string`) to process on the tasks list.
|
|
66
|
+
*
|
|
67
|
+
* Available filters:
|
|
68
|
+
*
|
|
69
|
+
* - `desired-state=(running | shutdown | accepted)`
|
|
70
|
+
* - `id=<task id>`
|
|
71
|
+
* - `label=key` or `label="key=value"`
|
|
72
|
+
* - `name=<task name>`
|
|
73
|
+
* - `node=<node id or name>`
|
|
74
|
+
* - `service=<service name>`
|
|
75
|
+
*/
|
|
76
|
+
readonly list: (options?: TaskListOptions | undefined) => Effect.Effect<never, TasksError, Readonly<Array<Task>>>;
|
|
77
|
+
/**
|
|
78
|
+
* Inspect a task
|
|
79
|
+
*
|
|
80
|
+
* @param id - ID of the task
|
|
81
|
+
*/
|
|
82
|
+
readonly inspect: (options: TaskInspectOptions) => Effect.Effect<never, TasksError, Readonly<Task>>;
|
|
83
|
+
/**
|
|
84
|
+
* Get task logs
|
|
85
|
+
*
|
|
86
|
+
* @param id - ID of the task
|
|
87
|
+
* @param details - Show task context and extra details provided to logs.
|
|
88
|
+
* @param follow - Keep connection after returning logs.
|
|
89
|
+
* @param stdout - Return logs from `stdout`
|
|
90
|
+
* @param stderr - Return logs from `stderr`
|
|
91
|
+
* @param since - Only return logs since this time, as a UNIX timestamp
|
|
92
|
+
* @param timestamps - Add timestamps to every log line
|
|
93
|
+
* @param tail - Only return this number of log lines from the end of the
|
|
94
|
+
* logs. Specify as an integer or `all` to output all log lines.
|
|
95
|
+
*/
|
|
96
|
+
readonly logs: (options: TaskLogsOptions) => Effect.Effect<never, TasksError, Readonly<Stream.Stream<never, TasksError, string>>>;
|
|
97
|
+
}
|
|
98
|
+
export declare const Tasks: Context.Tag<Tasks, Tasks>;
|
|
99
|
+
export declare const layer: Layer.Layer<IMobyConnectionAgent, never, Tasks>;
|
|
100
|
+
export declare const fromAgent: (agent: Effect.Effect<Scope.Scope, never, IMobyConnectionAgent>) => Layer.Layer<never, never, Tasks>;
|
|
101
|
+
export declare const fromConnectionOptions: (connectionOptions: MobyConnectionOptions) => Layer.Layer<never, never, Tasks>;
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as NodeHttp from "@effect/platform-node/HttpClient";
|
|
2
|
+
import * as Schema from "@effect/schema/Schema";
|
|
3
|
+
import { Context, Data, Effect, Layer, Stream, pipe } from "effect";
|
|
4
|
+
import { MobyConnectionAgent, MobyHttpClientLive, getAgent, } from "./agent-helpers.js";
|
|
5
|
+
import { addQueryParameter, responseErrorHandler, streamErrorHandler } from "./request-helpers.js";
|
|
6
|
+
import { Task } from "./schemas.js";
|
|
7
|
+
export class TasksError extends Data.TaggedError("TasksError") {
|
|
8
|
+
}
|
|
9
|
+
const make = Effect.gen(function* (_) {
|
|
10
|
+
const agent = yield* _(MobyConnectionAgent);
|
|
11
|
+
const defaultClient = yield* _(NodeHttp.client.Client);
|
|
12
|
+
const client = defaultClient.pipe(NodeHttp.client.mapRequest(NodeHttp.request.prependUrl(`${agent.nodeRequestUrl}/tasks`)), NodeHttp.client.filterStatusOk);
|
|
13
|
+
const TasksClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(Schema.array(Task))));
|
|
14
|
+
const TaskClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(Task)));
|
|
15
|
+
const streamHandler = (method) => streamErrorHandler((message) => new TasksError({ method, message }));
|
|
16
|
+
const responseHandler = (method) => responseErrorHandler((message) => new TasksError({ method, message }));
|
|
17
|
+
const list_ = (options) => pipe(NodeHttp.request.get(""), addQueryParameter("filters", JSON.stringify(options?.filters ?? {})), TasksClient, Effect.catchAll(responseHandler("list")));
|
|
18
|
+
const inspect_ = (options) => pipe(NodeHttp.request.get("/{id}".replace("{id}", encodeURIComponent(options.id))), TaskClient, Effect.catchAll(responseHandler("inspect")));
|
|
19
|
+
const logs_ = (options) => pipe(NodeHttp.request.get("/{id}/logs".replace("{id}", encodeURIComponent(options.id))), addQueryParameter("details", options.details), addQueryParameter("follow", options.follow), addQueryParameter("stdout", options.stdout), addQueryParameter("stderr", options.stderr), addQueryParameter("since", options.since), addQueryParameter("timestamps", options.timestamps), addQueryParameter("tail", options.tail), client, Effect.map((response) => response.stream), Effect.map(Stream.decodeText("utf8")), Effect.map(Stream.catchAll(streamHandler("logs"))), Effect.catchAll(responseHandler("logs")));
|
|
20
|
+
return { list: list_, inspect: inspect_, logs: logs_ };
|
|
21
|
+
});
|
|
22
|
+
export const Tasks = Context.Tag("the-moby-effect/Tasks");
|
|
23
|
+
export const layer = Layer.effect(Tasks, make).pipe(Layer.provide(MobyHttpClientLive));
|
|
24
|
+
export const fromAgent = (agent) => layer.pipe(Layer.provide(Layer.scoped(MobyConnectionAgent, agent)));
|
|
25
|
+
export const fromConnectionOptions = (connectionOptions) => fromAgent(getAgent(connectionOptions));
|
|
26
|
+
//# sourceMappingURL=tasks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../src/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kCAAkC,CAAC;AAC7D,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAS,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE3E,OAAO,EAEH,mBAAmB,EAEnB,kBAAkB,EAClB,QAAQ,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC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C,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,EACzC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EACrC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAClD,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAC3C,CAAC;IAEN,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC3D,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAQ,uBAAuB,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAEvF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAA8D,EAAE,EAAE,CACxF,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,iBAAwC,EAAE,EAAE,CAC9E,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import * as Schema from "@effect/schema/Schema";
|
|
2
|
+
import { Context, Effect, Layer, Scope } from "effect";
|
|
3
|
+
import { IMobyConnectionAgent, MobyConnectionOptions } from "./agent-helpers.js";
|
|
4
|
+
import { ClusterVolumeSpec, Volume, VolumeCreateOptions, VolumeListResponse, VolumePruneResponse } from "./schemas.js";
|
|
5
|
+
declare const VolumesError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<Omit<A, keyof import("effect/Equal").Equal>, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" | keyof import("effect/Equal").Equal ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
6
|
+
readonly _tag: "VolumesError";
|
|
7
|
+
} & Readonly<A>;
|
|
8
|
+
export declare class VolumesError extends VolumesError_base<{
|
|
9
|
+
method: string;
|
|
10
|
+
message: string;
|
|
11
|
+
}> {
|
|
12
|
+
}
|
|
13
|
+
export interface VolumeListOptions {
|
|
14
|
+
/**
|
|
15
|
+
* JSON encoded value of the filters (a `map[string][]string`) to process on
|
|
16
|
+
* the volumes list. Available filters:
|
|
17
|
+
*
|
|
18
|
+
* - `dangling=<boolean>` When set to `true` (or `1`), returns all volumes
|
|
19
|
+
* that are not in use by a container. When set to `false` (or `0`), only
|
|
20
|
+
* volumes that are in use by one or more containers are returned.
|
|
21
|
+
* - `driver=<volume-driver-name>` Matches volumes based on their driver.
|
|
22
|
+
* - `label=<key>` or `label=<key>:<value>` Matches volumes based on the
|
|
23
|
+
* presence of a `label` alone or a `label` and a value.
|
|
24
|
+
* - `name=<volume-name>` Matches all or part of a volume name.
|
|
25
|
+
*/
|
|
26
|
+
readonly filters?: {
|
|
27
|
+
label?: string[] | undefined;
|
|
28
|
+
name?: [string] | undefined;
|
|
29
|
+
driver?: [string] | undefined;
|
|
30
|
+
dangling?: ["true" | "false" | "1" | "0"] | undefined;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface VolumeDeleteOptions {
|
|
34
|
+
/** Volume name or ID */
|
|
35
|
+
readonly name: string;
|
|
36
|
+
/** Force the removal of the volume */
|
|
37
|
+
readonly force?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface VolumeInspectOptions {
|
|
40
|
+
/** Volume name or ID */
|
|
41
|
+
readonly name: string;
|
|
42
|
+
}
|
|
43
|
+
export interface VolumeUpdateOptions {
|
|
44
|
+
/** The name or ID of the volume */
|
|
45
|
+
readonly name: string;
|
|
46
|
+
/**
|
|
47
|
+
* The spec of the volume to update. Currently, only Availability may
|
|
48
|
+
* change. All other fields must remain unchanged.
|
|
49
|
+
*/
|
|
50
|
+
readonly spec?: ClusterVolumeSpec;
|
|
51
|
+
/**
|
|
52
|
+
* The version number of the volume being updated. This is required to avoid
|
|
53
|
+
* conflicting writes. Found in the volume's `ClusterVolume` field.
|
|
54
|
+
*/
|
|
55
|
+
readonly version: number;
|
|
56
|
+
}
|
|
57
|
+
export interface VolumePruneOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Filters to process on the prune list, encoded as JSON (a
|
|
60
|
+
* `map[string][]string`).
|
|
61
|
+
*
|
|
62
|
+
* Available filters:
|
|
63
|
+
*
|
|
64
|
+
* - `label` (`label=<key>`, `label=<key>=<value>`, `label!=<key>`, or
|
|
65
|
+
* `label!=<key>=<value>`) Prune volumes with (or without, in case
|
|
66
|
+
* `label!=...` is used) the specified labels.
|
|
67
|
+
* - `all` (`all=true`) - Consider all (local) volumes for pruning and not
|
|
68
|
+
* just anonymous volumes.
|
|
69
|
+
*/
|
|
70
|
+
readonly filters?: {
|
|
71
|
+
label?: string[] | undefined;
|
|
72
|
+
all?: ["true" | "false" | "1" | "0"] | undefined;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export interface Volumes {
|
|
76
|
+
/**
|
|
77
|
+
* List volumes
|
|
78
|
+
*
|
|
79
|
+
* @param filters - JSON encoded value of the filters (a
|
|
80
|
+
* `map[string][]string`) to process on the volumes list. Available
|
|
81
|
+
* filters:
|
|
82
|
+
*
|
|
83
|
+
* - `dangling=<boolean>` When set to `true` (or `1`), returns all volumes
|
|
84
|
+
* that are not in use by a container. When set to `false` (or `0`),
|
|
85
|
+
* only volumes that are in use by one or more containers are
|
|
86
|
+
* returned.
|
|
87
|
+
* - `driver=<volume-driver-name>` Matches volumes based on their driver.
|
|
88
|
+
* - `label=<key>` or `label=<key>:<value>` Matches volumes based on the
|
|
89
|
+
* presence of a `label` alone or a `label` and a value.
|
|
90
|
+
* - `name=<volume-name>` Matches all or part of a volume name.
|
|
91
|
+
*/
|
|
92
|
+
readonly list: (options?: VolumeListOptions | undefined) => Effect.Effect<never, VolumesError, VolumeListResponse>;
|
|
93
|
+
/**
|
|
94
|
+
* Create a volume
|
|
95
|
+
*
|
|
96
|
+
* @param volumeConfig - Volume configuration
|
|
97
|
+
*/
|
|
98
|
+
readonly create: (options: Schema.Schema.To<typeof VolumeCreateOptions.struct>) => Effect.Effect<never, VolumesError, Readonly<Volume>>;
|
|
99
|
+
/**
|
|
100
|
+
* Remove a volume
|
|
101
|
+
*
|
|
102
|
+
* @param name - Volume name or ID
|
|
103
|
+
* @param force - Force the removal of the volume
|
|
104
|
+
*/
|
|
105
|
+
readonly delete: (options: VolumeDeleteOptions) => Effect.Effect<never, VolumesError, void>;
|
|
106
|
+
/**
|
|
107
|
+
* Inspect a volume
|
|
108
|
+
*
|
|
109
|
+
* @param name - Volume name or ID
|
|
110
|
+
*/
|
|
111
|
+
readonly inspect: (options: VolumeInspectOptions) => Effect.Effect<never, VolumesError, Readonly<Volume>>;
|
|
112
|
+
/**
|
|
113
|
+
* "Update a volume. Valid only for Swarm cluster volumes"
|
|
114
|
+
*
|
|
115
|
+
* @param name - The name or ID of the volume
|
|
116
|
+
* @param body - The spec of the volume to update. Currently, only
|
|
117
|
+
* Availability may change. All other fields must remain unchanged.
|
|
118
|
+
* @param version - The version number of the volume being updated. This is
|
|
119
|
+
* required to avoid conflicting writes. Found in the volume's
|
|
120
|
+
* `ClusterVolume` field.
|
|
121
|
+
*/
|
|
122
|
+
readonly update: (options: VolumeUpdateOptions) => Effect.Effect<never, VolumesError, void>;
|
|
123
|
+
/**
|
|
124
|
+
* Delete unused volumes
|
|
125
|
+
*
|
|
126
|
+
* @param filters - Filters to process on the prune list, encoded as JSON (a
|
|
127
|
+
* `map[string][]string`).
|
|
128
|
+
*
|
|
129
|
+
* Available filters:
|
|
130
|
+
*
|
|
131
|
+
* - `label` (`label=<key>`, `label=<key>=<value>`, `label!=<key>`, or
|
|
132
|
+
* `label!=<key>=<value>`) Prune volumes with (or without, in case
|
|
133
|
+
* `label!=...` is used) the specified labels.
|
|
134
|
+
* - `all` (`all=true`) - Consider all (local) volumes for pruning and not
|
|
135
|
+
* just anonymous volumes.
|
|
136
|
+
*/
|
|
137
|
+
readonly prune: (options: VolumePruneOptions) => Effect.Effect<never, VolumesError, VolumePruneResponse>;
|
|
138
|
+
}
|
|
139
|
+
export declare const Volumes: Context.Tag<Volumes, Volumes>;
|
|
140
|
+
export declare const layer: Layer.Layer<IMobyConnectionAgent, never, Volumes>;
|
|
141
|
+
export declare const fromAgent: (agent: Effect.Effect<Scope.Scope, never, IMobyConnectionAgent>) => Layer.Layer<never, never, Volumes>;
|
|
142
|
+
export declare const fromConnectionOptions: (connectionOptions: MobyConnectionOptions) => Layer.Layer<never, never, Volumes>;
|
|
143
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as NodeHttp from "@effect/platform-node/HttpClient";
|
|
2
|
+
import { Context, Data, Effect, Layer, pipe } from "effect";
|
|
3
|
+
import { MobyConnectionAgent, MobyHttpClientLive, getAgent, } from "./agent-helpers.js";
|
|
4
|
+
import { addQueryParameter, responseErrorHandler } from "./request-helpers.js";
|
|
5
|
+
import { ClusterVolumeSpec, Volume, VolumeCreateOptions, VolumeListResponse, VolumePruneResponse } from "./schemas.js";
|
|
6
|
+
export class VolumesError extends Data.TaggedError("VolumesError") {
|
|
7
|
+
}
|
|
8
|
+
const make = Effect.gen(function* (_) {
|
|
9
|
+
const agent = yield* _(MobyConnectionAgent);
|
|
10
|
+
const defaultClient = yield* _(NodeHttp.client.Client);
|
|
11
|
+
const client = defaultClient.pipe(NodeHttp.client.mapRequest(NodeHttp.request.prependUrl(`${agent.nodeRequestUrl}/volumes`)), NodeHttp.client.filterStatusOk);
|
|
12
|
+
const voidClient = client.pipe(NodeHttp.client.transform(Effect.asUnit));
|
|
13
|
+
const VolumeClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(Volume)));
|
|
14
|
+
const VolumeListResponseClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(VolumeListResponse)));
|
|
15
|
+
const VolumePruneResponseClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(VolumePruneResponse)));
|
|
16
|
+
const responseHandler = (method) => responseErrorHandler((message) => new VolumesError({ method, message }));
|
|
17
|
+
const list_ = (options) => pipe(NodeHttp.request.get(""), addQueryParameter("filters", JSON.stringify(options?.filters)), VolumeListResponseClient, Effect.catchAll(responseHandler("list")));
|
|
18
|
+
const create_ = (options) => pipe(NodeHttp.request.post("/create"), NodeHttp.request.schemaBody(VolumeCreateOptions)(new VolumeCreateOptions(options)), Effect.flatMap(VolumeClient), Effect.catchAll(responseHandler("create")));
|
|
19
|
+
const delete_ = (options) => pipe(NodeHttp.request.del("/{name}".replace("{name}", encodeURIComponent(options.name))), addQueryParameter("force", options.force), voidClient, Effect.catchAll(responseHandler("delete")));
|
|
20
|
+
const inspect_ = (options) => pipe(NodeHttp.request.get("/{name}".replace("{name}", encodeURIComponent(options.name))), VolumeClient, Effect.catchAll(responseHandler("inspect")));
|
|
21
|
+
const update_ = (options) => pipe(NodeHttp.request.put("/{name}".replace("{name}", encodeURIComponent(options.name))), addQueryParameter("version", options.version), NodeHttp.request.schemaBody(ClusterVolumeSpec)(options.spec ?? new ClusterVolumeSpec({})), Effect.flatMap(voidClient), Effect.catchAll(responseHandler("update")));
|
|
22
|
+
const prune_ = (options) => pipe(NodeHttp.request.post("/prune"), addQueryParameter("filters", JSON.stringify(options?.filters)), VolumePruneResponseClient, Effect.catchAll(responseHandler("prune")));
|
|
23
|
+
return { list: list_, create: create_, delete: delete_, inspect: inspect_, update: update_, prune: prune_ };
|
|
24
|
+
});
|
|
25
|
+
export const Volumes = Context.Tag("the-moby-effect/Volumes");
|
|
26
|
+
export const layer = Layer.effect(Volumes, make).pipe(Layer.provide(MobyHttpClientLive));
|
|
27
|
+
export const fromAgent = (agent) => layer.pipe(Layer.provide(Layer.scoped(MobyConnectionAgent, agent)));
|
|
28
|
+
export const fromConnectionOptions = (connectionOptions) => fromAgent(getAgent(connectionOptions));
|
|
29
|
+
//# sourceMappingURL=volumes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volumes.js","sourceRoot":"","sources":["../../src/volumes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,kCAAkC,CAAC;AAE7D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAS,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnE,OAAO,EAEH,mBAAmB,EAEnB,kBAAkB,EAClB,QAAQ,GACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEvH,MAAM,OAAO,YAAa,SAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAG/D;CAAG;AA0IL,MAAM,IAAI,GAAyF,MAAM,CAAC,GAAG,CACzG,QAAQ,CAAC,EAAE,CAAiB;IACxB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC;IAC5C,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAC7B,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC,cAAc,UAAU,CAAC,CAAC,EA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