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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Leo Conforti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# the-moby-effect
|
|
2
|
+
|
|
3
|
+
Moby API client built using [effect-ts](http://effect.website). If you want documentation, please consider reading [The Docker API documentation](https://docs.docker.com/engine/api/latest), it is very well written and there is nothing in this library that wouldn't be in there (plus I would just do a worse job if I tried to write my interpretation of their documentation here). If you are just looking for some examples to get your feet underneath you quickly with effect integration, then I do have some of those [here](./examples/).
|
|
4
|
+
|
|
5
|
+
## Goals
|
|
6
|
+
|
|
7
|
+
- [x] - local unix socket connections
|
|
8
|
+
- [x] - http and https connections
|
|
9
|
+
- [x] - ssh connections
|
|
10
|
+
- [x] - streaming (just like [dockerode](https://github.com/apocas/dockerode), streams are passed directly through to you)
|
|
11
|
+
- [x] - tests, examples, and in-line JSDoc comments based on the moby api documentation
|
|
12
|
+
- [x] - Strong focus on types and typescript support
|
|
13
|
+
- [x] - Support multiple "engines" (docker, podman, ect). If its built on top of [moby](https://github.com/moby/moby) then it _should_ just work, however, __currently only docker is tested against__
|
|
14
|
+
|
|
15
|
+
## Non-Goals
|
|
16
|
+
|
|
17
|
+
- Tighter schema: the moby api schema is pretty loose as it aims to be backwards compatible - almost nothing is explicitly marked as required and object properties are optional by default under the swagger2.0/openapi specification. I have no intention to try to tighten their schema in my project. If the moby schema doesn't explicitly mark it as a required field, then it will be optional.
|
|
18
|
+
|
|
19
|
+
- Version negotiating: either install a specific version for the moby api that you are targeting or just keep your docker install somewhat up-to-date and you should have no problems
|
|
20
|
+
|
|
21
|
+
## Todo/Future
|
|
22
|
+
- Add more examples
|
|
23
|
+
- Maybe add tests against something else other than docker like podman?
|
|
24
|
+
- Patch upstream @effect/platform-node to support just streaming responses, needed for session and container attach endpoints: [upstream pr](https://github.com/Effect-TS/platform/pull/375)
|
|
25
|
+
|
|
26
|
+
## Compatibility
|
|
27
|
+
|
|
28
|
+
the-moby-effect targets the current stable version of the moby api, which is v1.43 at the time of writing. If you are curious what that translates to for docker versions then take a look at [this](https://docs.docker.com/engine/api/#api-version-matrix) api version matrix published by Docker. As stated in the api version matrix, only Docker v24.0 would be officially supported by the-moby-effect, however, we still test against docker v20, v23, v24, and the next release candidate which is v25 (there is no v21 or v22 btw). Here is another note from Docker:
|
|
29
|
+
|
|
30
|
+
"The Docker daemon and client don't necessarily need to be the same version at all times. However, keep the following in mind":
|
|
31
|
+
1. "If the daemon is newer than the client, the client doesn't know about new features or deprecated API endpoints in the daemon" (shouldn't really happen because the-moby-effect will always target the latest stable api version)
|
|
32
|
+
2. "If the client is newer than the daemon, the client can request API endpoints that the daemon doesn't know about" (this could happen, although most of the endpoints are pretty stable at this point so its more like an endpoint parameter might change).
|
|
33
|
+
|
|
34
|
+
The only compatibility issue found so far is that when using the-moby-effect with docker v20 you can not filter or prune volumes using the `all` filter as it was not present at the time. Other than that all functionality appears to still work.
|
|
35
|
+
|
|
36
|
+
## Versioning
|
|
37
|
+
|
|
38
|
+
This package does not follow semantic versioning, instead the major and minor part represents the version of the moby api. All bugfixes, breaking or otherwise, will be released under an incremented patch version.
|
|
39
|
+
|
|
40
|
+
## Contributing and getting help
|
|
41
|
+
|
|
42
|
+
Contributions, suggestions, and questions are welcome! I'll review prs and respond to issues/discussion here on GitHub but if you want more direct and probably quicker communication you can find me in the [effect discord](https://discord.gg/effect-ts) as @leonitous
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import net from "node:net";
|
|
5
|
+
import ssh2 from "ssh2";
|
|
6
|
+
import * as NodeHttp from "@effect/platform-node/HttpClient";
|
|
7
|
+
import { Context, Effect, Layer, Scope } from "effect";
|
|
8
|
+
/** How to connect to your moby/docker instance. */
|
|
9
|
+
export type MobyConnectionOptions = {
|
|
10
|
+
connection: "unix";
|
|
11
|
+
socketPath: string;
|
|
12
|
+
} | {
|
|
13
|
+
connection: "http";
|
|
14
|
+
host: string;
|
|
15
|
+
port: number;
|
|
16
|
+
} | ({
|
|
17
|
+
connection: "ssh";
|
|
18
|
+
remoteSocketPath: string;
|
|
19
|
+
} & ssh2.ConnectConfig) | {
|
|
20
|
+
connection: "https";
|
|
21
|
+
host: string;
|
|
22
|
+
port: number;
|
|
23
|
+
cert: string;
|
|
24
|
+
ca: string;
|
|
25
|
+
key: string;
|
|
26
|
+
passphrase?: string | undefined;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Helper interface to expose the underlying socket from the effect NodeHttp
|
|
30
|
+
* response. Useful for multiplexing the response stream.
|
|
31
|
+
*/
|
|
32
|
+
export interface IExposeSocketOnEffectClientResponse extends NodeHttp.response.ClientResponse {
|
|
33
|
+
source: {
|
|
34
|
+
socket: net.Socket;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Our moby connection needs to be an extension of the effect platform-node
|
|
39
|
+
* httpAgent so that it will still be compatible with all the other
|
|
40
|
+
* platform-node http methods, but it would be nice if it had a few other things
|
|
41
|
+
* as well. The nodeRequestUrl is the url that the node http client will use to
|
|
42
|
+
* make requests. And while we don't need to keep track of the connection
|
|
43
|
+
* options for anything yet, it wouldn't hurt to add them.
|
|
44
|
+
*/
|
|
45
|
+
export interface IMobyConnectionAgent extends NodeHttp.nodeClient.HttpAgent {
|
|
46
|
+
ssh: http.Agent;
|
|
47
|
+
unix: http.Agent;
|
|
48
|
+
nodeRequestUrl: string;
|
|
49
|
+
connectionOptions: MobyConnectionOptions;
|
|
50
|
+
}
|
|
51
|
+
/** Context identifier for our moby connection agent. */
|
|
52
|
+
export declare const MobyConnectionAgent: Context.Tag<IMobyConnectionAgent, IMobyConnectionAgent>;
|
|
53
|
+
export declare const MobyHttpClientLive: Layer.Layer<IMobyConnectionAgent, never, NodeHttp.client.Client.Default>;
|
|
54
|
+
/**
|
|
55
|
+
* Given the moby connection options, it will construct a scoped effect that
|
|
56
|
+
* provides an http connection agent that you should use to connect to your
|
|
57
|
+
* docker instance.
|
|
58
|
+
*/
|
|
59
|
+
export declare const getAgent: (connectionOptions: MobyConnectionOptions) => Effect.Effect<Scope.Scope, never, IMobyConnectionAgent>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
import https from "node:https";
|
|
3
|
+
import ssh2 from "ssh2";
|
|
4
|
+
import * as NodeHttp from "@effect/platform-node/HttpClient";
|
|
5
|
+
import { Context, Effect, Layer, Match, pipe } from "effect";
|
|
6
|
+
/** Context identifier for our moby connection agent. */
|
|
7
|
+
export const MobyConnectionAgent = Context.Tag(Symbol.for("@the-moby-effect/MobyConnectionAgent"));
|
|
8
|
+
export const MobyHttpClientLive = NodeHttp.nodeClient.layerWithoutAgent.pipe(Layer.provide(Layer.effect(NodeHttp.nodeClient.HttpAgent, MobyConnectionAgent)));
|
|
9
|
+
/**
|
|
10
|
+
* An http agent that connect to remote docker instances over ssh.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import http from "node:http";
|
|
14
|
+
*
|
|
15
|
+
* http.get(
|
|
16
|
+
* {
|
|
17
|
+
* path: "/_ping",
|
|
18
|
+
* agent: new SSHAgent(ssh2Options),
|
|
19
|
+
* },
|
|
20
|
+
* (response) => {
|
|
21
|
+
* console.log(response.statusCode);
|
|
22
|
+
* console.dir(response.headers);
|
|
23
|
+
* response.resume();
|
|
24
|
+
* }
|
|
25
|
+
* ).end();
|
|
26
|
+
*/
|
|
27
|
+
class SSHAgent extends http.Agent {
|
|
28
|
+
// The ssh client that will be connecting to the server
|
|
29
|
+
sshClient;
|
|
30
|
+
// How to connect to the remote server and where the docker socket is located.
|
|
31
|
+
connectConfig;
|
|
32
|
+
constructor(ssh2ConnectConfig, agentOptions) {
|
|
33
|
+
super(agentOptions);
|
|
34
|
+
this.sshClient = new ssh2.Client();
|
|
35
|
+
this.connectConfig = ssh2ConnectConfig;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* When creating a new connection, first start by trying to connect to the
|
|
39
|
+
* remote server over ssh. Then, if that was successful, we send a
|
|
40
|
+
* forwardOurStreamLocal request which is an OpenSSH extension that opens a
|
|
41
|
+
* connection to the unix domain socket at socketPath on the remote server
|
|
42
|
+
* and forwards traffic.
|
|
43
|
+
*/
|
|
44
|
+
createConnection(_options, callback) {
|
|
45
|
+
this.sshClient
|
|
46
|
+
.on("ready", () => {
|
|
47
|
+
this.sshClient.openssh_forwardOutStreamLocal(this.connectConfig.remoteSocketPath, (error, stream) => {
|
|
48
|
+
if (error) {
|
|
49
|
+
return callback(error);
|
|
50
|
+
}
|
|
51
|
+
stream.once("close", () => {
|
|
52
|
+
stream.end();
|
|
53
|
+
stream.destroy();
|
|
54
|
+
this.sshClient.end();
|
|
55
|
+
});
|
|
56
|
+
callback(undefined, stream);
|
|
57
|
+
});
|
|
58
|
+
})
|
|
59
|
+
.on("error", (error) => callback(error))
|
|
60
|
+
.connect(this.connectConfig);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Given the moby connection options, it will construct a scoped effect that
|
|
65
|
+
* provides an http connection agent that you should use to connect to your
|
|
66
|
+
* docker instance.
|
|
67
|
+
*/
|
|
68
|
+
export const getAgent = (connectionOptions) => Effect.map(Effect.acquireRelease(Effect.sync(() => pipe(Match.value(connectionOptions), Match.when({ connection: "ssh" }, (options) => new SSHAgent(options)), Match.when({ connection: "unix" }, (options) => new http.Agent({ socketPath: options.socketPath })), Match.when({ connection: "http" }, (options) => new http.Agent({ host: options.host, port: options.port })), Match.when({ connection: "https" }, (options) => new https.Agent({
|
|
69
|
+
ca: options.ca,
|
|
70
|
+
key: options.key,
|
|
71
|
+
cert: options.cert,
|
|
72
|
+
host: options.host,
|
|
73
|
+
port: options.port,
|
|
74
|
+
passphrase: options.passphrase,
|
|
75
|
+
})), Match.exhaustive)), (agent) => Effect.sync(() => agent.destroy())), (agent) => ({
|
|
76
|
+
ssh: agent,
|
|
77
|
+
unix: agent,
|
|
78
|
+
http: agent,
|
|
79
|
+
https: agent,
|
|
80
|
+
connectionOptions: connectionOptions,
|
|
81
|
+
nodeRequestUrl: connectionOptions.connection === "https" ? "https://0.0.0.0" : "http://0.0.0.0",
|
|
82
|
+
[NodeHttp.nodeClient.HttpAgentTypeId]: NodeHttp.nodeClient.HttpAgentTypeId,
|
|
83
|
+
}));
|
|
84
|
+
//# sourceMappingURL=agent-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-helpers.js","sourceRoot":"","sources":["../../src/agent-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,KAAK,QAAQ,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAS,IAAI,EAAE,MAAM,QAAQ,CAAC;AA0CpE,wDAAwD;AACxD,MAAM,CAAC,MAAM,mBAAmB,GAC5B,OAAO,CAAC,GAAG,CAAuB,MAAM,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC,CAAC;AAE1F,MAAM,CAAC,MAAM,kBAAkB,GAC3B,QAAQ,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CACtC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC,CAClF,CAAC;AAEN;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,QAAS,SAAQ,IAAI,CAAC,KAAK;IAC7B,uDAAuD;IACtC,SAAS,CAAc;IAExC,8EAA8E;IAC7D,aAAa,CAAoD;IAElF,YACI,iBAAoE,EACpE,YAA4C;QAE5C,KAAK,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C/F,CAAC,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,QAAQ,CAAC,UAAU,CAAC,eAAe;CAC7E,CAAC,CACL,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
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 { Config, ConfigSpec, IDResponse } from "./schemas.js";
|
|
5
|
+
declare const ConfigsError_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: "ConfigsError";
|
|
7
|
+
} & Readonly<A>;
|
|
8
|
+
export declare class ConfigsError extends ConfigsError_base<{
|
|
9
|
+
method: string;
|
|
10
|
+
message: string;
|
|
11
|
+
}> {
|
|
12
|
+
}
|
|
13
|
+
export interface ConfigListOptions {
|
|
14
|
+
/**
|
|
15
|
+
* A JSON encoded value of the filters (a `map[string][]string`) to process
|
|
16
|
+
* on the configs list.
|
|
17
|
+
*
|
|
18
|
+
* Available filters:
|
|
19
|
+
*
|
|
20
|
+
* - `id=<config id>`
|
|
21
|
+
* - `label=<key> or label=<key>=value`
|
|
22
|
+
* - `name=<config name>`
|
|
23
|
+
* - `names=<config name>`
|
|
24
|
+
*/
|
|
25
|
+
readonly filters?: {
|
|
26
|
+
id?: [string] | undefined;
|
|
27
|
+
label?: string[] | undefined;
|
|
28
|
+
name?: [string] | undefined;
|
|
29
|
+
names?: [string] | undefined;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface ConfigDeleteOptions {
|
|
33
|
+
/** ID of the config */
|
|
34
|
+
readonly id: string;
|
|
35
|
+
}
|
|
36
|
+
export interface ConfigInspectOptions {
|
|
37
|
+
/** ID of the config */
|
|
38
|
+
readonly id: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ConfigUpdateOptions {
|
|
41
|
+
/** The ID or name of the config */
|
|
42
|
+
readonly id: string;
|
|
43
|
+
/**
|
|
44
|
+
* The spec of the config to update. Currently, only the Labels field can be
|
|
45
|
+
* updated. All other fields must remain unchanged from the [ConfigInspect
|
|
46
|
+
* endpoint](#operation/ConfigInspect) response values.
|
|
47
|
+
*/
|
|
48
|
+
readonly spec: Schema.Schema.To<typeof ConfigSpec.struct>;
|
|
49
|
+
/**
|
|
50
|
+
* The version number of the config object being updated. This is required
|
|
51
|
+
* to avoid conflicting writes.
|
|
52
|
+
*/
|
|
53
|
+
readonly version: number;
|
|
54
|
+
}
|
|
55
|
+
export interface Configs {
|
|
56
|
+
/**
|
|
57
|
+
* List configs
|
|
58
|
+
*
|
|
59
|
+
* @param filters - A JSON encoded value of the filters (a
|
|
60
|
+
* `map[string][]string`) to process on the configs list.
|
|
61
|
+
*
|
|
62
|
+
* Available filters:
|
|
63
|
+
*
|
|
64
|
+
* - `id=<config id>`
|
|
65
|
+
* - `label=<key> or label=<key>=value`
|
|
66
|
+
* - `name=<config name>`
|
|
67
|
+
* - `names=<config name>`
|
|
68
|
+
*/
|
|
69
|
+
readonly list: (options?: ConfigListOptions | undefined) => Effect.Effect<never, ConfigsError, Readonly<Array<Config>>>;
|
|
70
|
+
/**
|
|
71
|
+
* Create a config
|
|
72
|
+
*
|
|
73
|
+
* @param body -
|
|
74
|
+
*/
|
|
75
|
+
readonly create: (options: Schema.Schema.To<typeof ConfigSpec.struct>) => Effect.Effect<never, ConfigsError, Readonly<IDResponse>>;
|
|
76
|
+
/**
|
|
77
|
+
* Delete a config
|
|
78
|
+
*
|
|
79
|
+
* @param id - ID of the config
|
|
80
|
+
*/
|
|
81
|
+
readonly delete: (options: ConfigDeleteOptions) => Effect.Effect<never, ConfigsError, void>;
|
|
82
|
+
/**
|
|
83
|
+
* Inspect a config
|
|
84
|
+
*
|
|
85
|
+
* @param id - ID of the config
|
|
86
|
+
*/
|
|
87
|
+
readonly inspect: (options: ConfigInspectOptions) => Effect.Effect<never, ConfigsError, Readonly<Config>>;
|
|
88
|
+
/**
|
|
89
|
+
* Update a Config
|
|
90
|
+
*
|
|
91
|
+
* @param id - The ID or name of the config
|
|
92
|
+
* @param spec - The spec of the config to update. Currently, only the
|
|
93
|
+
* Labels field can be updated. All other fields must remain unchanged
|
|
94
|
+
* from the [ConfigInspect endpoint](#operation/ConfigInspect) response
|
|
95
|
+
* values.
|
|
96
|
+
* @param version - The version number of the config object being updated.
|
|
97
|
+
* This is required to avoid conflicting writes.
|
|
98
|
+
*/
|
|
99
|
+
readonly update: (options: ConfigUpdateOptions) => Effect.Effect<never, ConfigsError, void>;
|
|
100
|
+
}
|
|
101
|
+
export declare const Configs: Context.Tag<Configs, Configs>;
|
|
102
|
+
export declare const layer: Layer.Layer<IMobyConnectionAgent, never, Configs>;
|
|
103
|
+
export declare const fromAgent: (agent: Effect.Effect<Scope.Scope, never, IMobyConnectionAgent>) => Layer.Layer<never, never, Configs>;
|
|
104
|
+
export declare const fromConnectionOptions: (connectionOptions: MobyConnectionOptions) => Layer.Layer<never, never, Configs>;
|
|
105
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { Config, ConfigSpec, IDResponse } from "./schemas.js";
|
|
7
|
+
export class ConfigsError extends Data.TaggedError("ConfigsError") {
|
|
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}/configs`)), NodeHttp.client.filterStatusOk);
|
|
13
|
+
const voidClient = client.pipe(NodeHttp.client.transform(Effect.asUnit));
|
|
14
|
+
const ConfigClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(Config)));
|
|
15
|
+
const IDResponseClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(IDResponse)));
|
|
16
|
+
const ConfigsClient = client.pipe(NodeHttp.client.mapEffect(NodeHttp.response.schemaBodyJson(Schema.array(Config))));
|
|
17
|
+
const responseHandler = (method) => responseErrorHandler((message) => new ConfigsError({ method, message }));
|
|
18
|
+
const list_ = (options) => pipe(NodeHttp.request.get(""), addQueryParameter("filters", JSON.stringify(options?.filters)), ConfigsClient, Effect.catchAll(responseHandler("list")));
|
|
19
|
+
const create_ = (options) => pipe(NodeHttp.request.post("/create"), NodeHttp.request.schemaBody(ConfigSpec)(new ConfigSpec(options)), Effect.flatMap(IDResponseClient), Effect.catchAll(responseHandler("create")));
|
|
20
|
+
const delete_ = (options) => pipe(NodeHttp.request.del("/{id}".replace("{id}", encodeURIComponent(options.id))), voidClient, Effect.catchAll(responseHandler("delete")));
|
|
21
|
+
const inspect_ = (options) => pipe(NodeHttp.request.get("/{id}".replace("{id}", encodeURIComponent(options.id))), ConfigClient, Effect.catchAll(responseHandler("inspect")));
|
|
22
|
+
const update_ = (options) => pipe(NodeHttp.request.post("/{id}/update".replace("{id}", encodeURIComponent(options.id))), addQueryParameter("version", options.version), NodeHttp.request.schemaBody(ConfigSpec)(new ConfigSpec(options.spec)), Effect.flatMap(voidClient), Effect.catchAll(responseHandler("update")));
|
|
23
|
+
return { list: list_, create: create_, delete: delete_, inspect: inspect_, update: update_ };
|
|
24
|
+
});
|
|
25
|
+
export const Configs = Context.Tag("the-moby-effect/Configs");
|
|
26
|
+
export const layer = Layer.effect(Configs, 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=configs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configs.js","sourceRoot":"","sources":["../../src/configs.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,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE9D,MAAM,OAAO,YAAa,SAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAG/D;CAAG;AAuGL,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,EAC1F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