@gjermundgaraba/clankerbox-sdk 0.4.1 → 0.12.1

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.
@@ -0,0 +1,289 @@
1
+ import { Context, Duration, Effect, Schema } from "effect";
2
+ import { HttpClient } from "effect/http";
3
+ //#region src/errors.d.ts
4
+ declare const Invalid_base: Schema.Class<Invalid, Schema.TaggedStruct<"Invalid", {
5
+ readonly message: Schema.String;
6
+ }>, import("effect/Cause").YieldableError>;
7
+ /** The request is malformed: a bad ID or name, an undeclared field, a value out of range. */
8
+ declare class Invalid extends Invalid_base {
9
+ get retryable(): boolean;
10
+ }
11
+ declare const NotFound_base: Schema.Class<NotFound, Schema.TaggedStruct<"NotFound", {
12
+ readonly message: Schema.String;
13
+ }>, import("effect/Cause").YieldableError>;
14
+ /** The machine or checkpoint doesn't exist. A `delete` that meets it is done. */
15
+ declare class NotFound extends NotFound_base {
16
+ get retryable(): boolean;
17
+ }
18
+ declare const ConflictKind: Schema.Literals<readonly ["exists", "busy"]>;
19
+ type ConflictKind = typeof ConflictKind.Type;
20
+ declare const Conflict_base: Schema.Class<Conflict, Schema.TaggedStruct<"Conflict", {
21
+ readonly message: Schema.String;
22
+ readonly kind: Schema.Literals<readonly ["exists", "busy"]>;
23
+ }>, import("effect/Cause").YieldableError>;
24
+ /** The name is taken (`exists`), or another action holds the resource (`busy`). */
25
+ declare class Conflict extends Conflict_base {
26
+ get retryable(): boolean;
27
+ }
28
+ declare const Precondition_base: Schema.Class<Precondition, Schema.TaggedStruct<"Precondition", {
29
+ readonly message: Schema.String;
30
+ }>, import("effect/Cause").YieldableError>;
31
+ /** The resource's state doesn't allow the action, or no host offers the requested base. */
32
+ declare class Precondition extends Precondition_base {
33
+ get retryable(): boolean;
34
+ }
35
+ declare const Capacity_base: Schema.Class<Capacity, Schema.TaggedStruct<"Capacity", {
36
+ readonly message: Schema.String;
37
+ }>, import("effect/Cause").YieldableError>;
38
+ /** The host has no room now; room can free up, so a later call may succeed. */
39
+ declare class Capacity extends Capacity_base {
40
+ get retryable(): boolean;
41
+ }
42
+ declare const Unavailable_base: Schema.Class<Unavailable, Schema.TaggedStruct<"Unavailable", {
43
+ readonly message: Schema.String;
44
+ readonly access: Schema.Literals<("read" | "write")[]>;
45
+ }>, import("effect/Cause").YieldableError>;
46
+ /**
47
+ * The client couldn't reach the host, or lost its reply. Only the client library produces
48
+ * it. `access` is the access of the action that met it: a mutation's request may have
49
+ * reached the host and run, so it is never retryable.
50
+ */
51
+ declare class Unavailable extends Unavailable_base {
52
+ get retryable(): boolean;
53
+ }
54
+ declare const Internal_base: Schema.Class<Internal, Schema.TaggedStruct<"Internal", {
55
+ readonly message: Schema.String;
56
+ }>, import("effect/Cause").YieldableError>;
57
+ declare class Internal extends Internal_base {
58
+ get retryable(): boolean;
59
+ }
60
+ /** What a host answers with; every action group declares these. */
61
+ declare const hostErrors: readonly [typeof Invalid, typeof NotFound, typeof Conflict, typeof Precondition, typeof Capacity, typeof Internal];
62
+ type HostError = InstanceType<(typeof hostErrors)[number]>;
63
+ /** What a call through the client library fails with. */
64
+ type ClankerboxError = HostError | Unavailable;
65
+ /** The tag a host records on a failed action: always one of the errors it answers with. */
66
+ declare const HostErrorTag: Schema.Literals<("Capacity" | "Conflict" | "Internal" | "Invalid" | "NotFound" | "Precondition")[]>;
67
+ type HostErrorTag = typeof HostErrorTag.Type;
68
+ /** The tag of any error a call through the client library can fail with. */
69
+ declare const ErrorTag: Schema.Literals<readonly [...("Capacity" | "Conflict" | "Internal" | "Invalid" | "NotFound" | "Precondition")[], "Unavailable"]>;
70
+ type ErrorTag = typeof ErrorTag.Type;
71
+ //#endregion
72
+ //#region src/resources.d.ts
73
+ declare const Runtime: Schema.Literals<readonly ["smolvm", "tart", "boat"]>;
74
+ type Runtime = typeof Runtime.Type;
75
+ /** The mutations that record themselves on a resource's `action`. */
76
+ declare const ActionName: Schema.Literals<readonly ["create", "start", "stop", "delete", "fork", "restore", "capture"]>;
77
+ type ActionName = typeof ActionName.Type;
78
+ /**
79
+ * A resource's last action: `running` while it holds the row, `failed` with its error
80
+ * after a native failure, `done` after a success. The next action replaces it.
81
+ */
82
+ declare const ActionRecord: Schema.Struct<{
83
+ readonly name: Schema.Literals<readonly ["create", "start", "stop", "delete", "fork", "restore", "capture"]>;
84
+ readonly status: Schema.Literals<readonly ["running", "failed", "done"]>;
85
+ readonly error: Schema.optionalKey<Schema.Struct<{
86
+ readonly tag: Schema.Literals<("Capacity" | "Conflict" | "Internal" | "Invalid" | "NotFound" | "Precondition")[]>;
87
+ readonly message: Schema.String;
88
+ }>>;
89
+ }>;
90
+ type ActionRecord = typeof ActionRecord.Type;
91
+ /** Where a machine's guest port 22 is reached. */
92
+ declare const SshEndpoint: Schema.Struct<{
93
+ readonly host: Schema.String;
94
+ readonly port: Schema.Int;
95
+ }>;
96
+ type SshEndpoint = typeof SshEndpoint.Type;
97
+ declare const Machine: Schema.Struct<{
98
+ readonly id: Schema.String;
99
+ readonly runtime: Schema.Literals<readonly ["smolvm", "tart", "boat"]>;
100
+ readonly createdAt: Schema.DateTimeUtcFromString;
101
+ readonly base: Schema.String;
102
+ /** The label the client passed at create, normally its profile's name. */
103
+ readonly profile: Schema.optionalKey<Schema.String>;
104
+ readonly cpu: Schema.Int;
105
+ readonly ramMib: Schema.Int;
106
+ readonly diskGib: Schema.Int;
107
+ /**
108
+ * Read from the runtime, never stored: `missing` when the runtime doesn't have the machine,
109
+ * `unknown` when it couldn't be read.
110
+ */
111
+ readonly state: Schema.Literals<readonly ["running", "stopped", "missing", "unknown"]>;
112
+ readonly action: Schema.Struct<{
113
+ readonly name: Schema.Literals<readonly ["create", "start", "stop", "delete", "fork", "restore", "capture"]>;
114
+ readonly status: Schema.Literals<readonly ["running", "failed", "done"]>;
115
+ readonly error: Schema.optionalKey<Schema.Struct<{
116
+ readonly tag: Schema.Literals<("Capacity" | "Conflict" | "Internal" | "Invalid" | "NotFound" | "Precondition")[]>;
117
+ readonly message: Schema.String;
118
+ }>>;
119
+ }>;
120
+ readonly ssh: Schema.optionalKey<Schema.Struct<{
121
+ readonly host: Schema.String;
122
+ readonly port: Schema.Int;
123
+ }>>;
124
+ /** The guest's SSH host public key, as `<type> <base64>`. */
125
+ readonly hostKey: Schema.optionalKey<Schema.String>;
126
+ }>;
127
+ type Machine = typeof Machine.Type;
128
+ declare const Checkpoint: Schema.Struct<{
129
+ readonly id: Schema.String;
130
+ readonly createdAt: Schema.DateTimeUtcFromString;
131
+ /** The ID of the machine it was captured from. */
132
+ readonly machine: Schema.String;
133
+ /** What it holds, by runtime: `ram` (RAM and disks) on smolvm, `disk` on Tart and boat. */
134
+ readonly kind: Schema.Literals<readonly ["ram", "disk"]>;
135
+ readonly base: Schema.String;
136
+ readonly profile: Schema.optionalKey<Schema.String>;
137
+ readonly cpu: Schema.Int;
138
+ readonly ramMib: Schema.Int;
139
+ readonly diskGib: Schema.Int;
140
+ readonly action: Schema.Struct<{
141
+ readonly name: Schema.Literals<readonly ["create", "start", "stop", "delete", "fork", "restore", "capture"]>;
142
+ readonly status: Schema.Literals<readonly ["running", "failed", "done"]>;
143
+ readonly error: Schema.optionalKey<Schema.Struct<{
144
+ readonly tag: Schema.Literals<("Capacity" | "Conflict" | "Internal" | "Invalid" | "NotFound" | "Precondition")[]>;
145
+ readonly message: Schema.String;
146
+ }>>;
147
+ }>;
148
+ }>;
149
+ type Checkpoint = typeof Checkpoint.Type;
150
+ /** The SDK's version, which is also the version of the clankerbox binaries it ships with. */
151
+ declare const version: string;
152
+ /** A version's major.minor: releases that share it speak the same API. */
153
+ declare const release: (of: string) => string;
154
+ declare const Host: Schema.Struct<{
155
+ readonly id: Schema.String;
156
+ readonly runtime: Schema.Literals<readonly ["smolvm", "tart", "boat"]>;
157
+ /** The clankerbox version the host runs. */
158
+ readonly version: Schema.String;
159
+ /** The runtime's version; for boat, its API version. */
160
+ readonly runtimeVersion: Schema.String;
161
+ readonly bases: Schema.$Array<Schema.String>;
162
+ }>;
163
+ type Host = typeof Host.Type;
164
+ /** A setup script and how long it may run. Nothing logs the script: it can carry secrets. */
165
+ declare const Setup: Schema.Struct<{
166
+ readonly script: Schema.String;
167
+ readonly timeoutSeconds: Schema.Int;
168
+ }>;
169
+ type Setup = typeof Setup.Type;
170
+ /**
171
+ * What a new machine is made from: a base, its sizes, an optional setup script with its
172
+ * timeout, and an optional `profile` label. A profile file fills these in; the host never
173
+ * sees the profile itself.
174
+ */
175
+ declare const MachineSpec: Schema.Struct<{
176
+ base: Schema.String;
177
+ cpu: Schema.Int;
178
+ ramMib: Schema.Int;
179
+ diskGib: Schema.Int;
180
+ setup: Schema.optionalKey<Schema.Struct<{
181
+ readonly script: Schema.String;
182
+ readonly timeoutSeconds: Schema.Int;
183
+ }>>;
184
+ profile: Schema.optionalKey<Schema.String>;
185
+ }>;
186
+ type MachineSpec = typeof MachineSpec.Type;
187
+ /**
188
+ * `machine.create`'s input: the spec and the new machine's full ID. The host checks that the ID
189
+ * names it, so a create never lands under another host's ID.
190
+ */
191
+ declare const CreateRequest: Schema.Struct<{
192
+ readonly base: Schema.String;
193
+ readonly cpu: Schema.Int;
194
+ readonly ramMib: Schema.Int;
195
+ readonly diskGib: Schema.Int;
196
+ readonly setup: Schema.optionalKey<Schema.Struct<{
197
+ readonly script: Schema.String;
198
+ readonly timeoutSeconds: Schema.Int;
199
+ }>>;
200
+ readonly profile: Schema.optionalKey<Schema.String>;
201
+ readonly id: Schema.String;
202
+ }>;
203
+ type CreateRequest = typeof CreateRequest.Type;
204
+ /**
205
+ * A profile file: a client-side file that fills in a create request. `setup.path` is a script
206
+ * file or a recipe directory, relative to the profile file, and comes with its timeout: the
207
+ * profile's author sets it, and there is no default. `host` places the create on that host
208
+ * instead of by base.
209
+ */
210
+ declare const Profile: Schema.Struct<{
211
+ readonly base: Schema.String;
212
+ readonly cpu: Schema.Int;
213
+ readonly ramMib: Schema.Int;
214
+ readonly diskGib: Schema.Int;
215
+ readonly setup: Schema.optionalKey<Schema.Struct<{
216
+ readonly path: Schema.String;
217
+ readonly timeoutSeconds: Schema.Int;
218
+ }>>;
219
+ readonly host: Schema.optionalKey<Schema.String>;
220
+ }>;
221
+ type Profile = typeof Profile.Type;
222
+ declare namespace client_d_exports {
223
+ export { Client, CreateOptions, Gathered, HostEntry, Interface, Options, Unreachable, make };
224
+ }
225
+ /** One host a client talks to. `id` is the host part of every ID it holds. */
226
+ declare const HostEntry: Schema.Struct<{
227
+ readonly id: Schema.String;
228
+ readonly url: Schema.String;
229
+ }>;
230
+ type HostEntry = typeof HostEntry.Type;
231
+ /** A host that didn't answer a fan-out, and why. */
232
+ interface Unreachable {
233
+ readonly host: string;
234
+ readonly error: ClankerboxError;
235
+ }
236
+ /** What a fan-out gathered: every reachable host's answers, and the hosts that didn't answer. */
237
+ interface Gathered<A> {
238
+ readonly answers: ReadonlyArray<A>;
239
+ readonly unreachable: ReadonlyArray<Unreachable>;
240
+ }
241
+ interface Options {
242
+ /**
243
+ * How long to wait for a mutation's reply, unbounded by default: a create with a long setup
244
+ * runs for as long as it takes. It only stops the wait, and a mutation that outlasts it fails
245
+ * like a lost reply.
246
+ */
247
+ readonly timeout?: Duration.Duration | undefined;
248
+ /**
249
+ * How long to wait for a read's reply, `readTimeout` (10 s) by default. A fan-out bounds each
250
+ * host's request on its own, so a host that doesn't answer in time is named among the
251
+ * unreachable.
252
+ */
253
+ readonly readTimeout?: Duration.Duration | undefined;
254
+ }
255
+ interface CreateOptions {
256
+ /** The host to create on, normally a profile's `host`. A full ID in `target` wins over it. */
257
+ readonly host?: string | undefined;
258
+ }
259
+ interface Interface {
260
+ /** Every host, with its bases. */
261
+ readonly hosts: Effect.Effect<Gathered<Host>>;
262
+ readonly machines: Effect.Effect<Gathered<Machine>>;
263
+ readonly checkpoints: Effect.Effect<Gathered<Checkpoint>>;
264
+ readonly machine: (id: string) => Effect.Effect<Machine, ClankerboxError>;
265
+ readonly checkpoint: (id: string) => Effect.Effect<Checkpoint, ClankerboxError>;
266
+ /**
267
+ * Creates a machine. `target` is a full ID, which names its host, or a name: then the
268
+ * options' host, or else the first host in the list that offers the spec's base.
269
+ */
270
+ readonly create: (target: string, spec: MachineSpec, options?: CreateOptions) => Effect.Effect<Machine, ClankerboxError>;
271
+ readonly start: (id: string) => Effect.Effect<Machine, ClankerboxError>;
272
+ readonly stop: (id: string) => Effect.Effect<Machine, ClankerboxError>;
273
+ readonly delete: (id: string) => Effect.Effect<void, ClankerboxError>;
274
+ /** Copies a machine to a new name on its host. */
275
+ readonly fork: (machine: string, name: string) => Effect.Effect<Machine, ClankerboxError>;
276
+ /** Creates a machine named `name` from a checkpoint, on the checkpoint's host. */
277
+ readonly restore: (checkpoint: string, name: string) => Effect.Effect<Machine, ClankerboxError>;
278
+ readonly capture: (machine: string, name: string) => Effect.Effect<Checkpoint, ClankerboxError>;
279
+ readonly deleteCheckpoint: (id: string) => Effect.Effect<void, ClankerboxError>;
280
+ }
281
+ declare const Client_base: Context.ServiceClass<Client, "@gjermundgaraba/clankerbox-sdk/Client", Interface>;
282
+ declare class Client extends Client_base {}
283
+ /**
284
+ * Builds a client over `hosts`, in placement order. Making it sends nothing. An empty list
285
+ * is Invalid, and so is a malformed entry or a host ID that appears twice: IDs route by it.
286
+ */
287
+ declare const make: (hosts: ReadonlyArray<HostEntry>, options?: Options) => Effect.Effect<Interface, Invalid, HttpClient.HttpClient>;
288
+ //#endregion
289
+ export { hostErrors as A, HostError as C, NotFound as D, Invalid as E, Precondition as O, ErrorTag as S, Internal as T, version as _, ActionName as a, Conflict as b, CreateRequest as c, MachineSpec as d, Profile as f, release as g, SshEndpoint as h, client_d_exports as i, Unavailable as k, Host as l, Setup as m, HostEntry as n, ActionRecord as o, Runtime as p, Options as r, Checkpoint as s, Client as t, Machine as u, Capacity as v, HostErrorTag as w, ConflictKind as x, ClankerboxError as y };