zygo-sdk 0.1.3
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 +202 -0
- package/NOTICE +11 -0
- package/README.md +50 -0
- package/package.json +40 -0
- package/src/endpoint.js +71 -0
- package/src/errors.js +205 -0
- package/src/index.d.ts +541 -0
- package/src/index.js +1112 -0
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Type declarations for the Zygo client.
|
|
4
|
+
*
|
|
5
|
+
* Hand-written rather than generated, because the package has no build step:
|
|
6
|
+
* it ships the JavaScript that runs, and a declaration file beside it. That
|
|
7
|
+
* keeps `npm install zygo-sdk` free of a compiler and keeps what you read in the
|
|
8
|
+
* repository identical to what executes. A test (`test/types.test.js`) holds
|
|
9
|
+
* this file to the JavaScript: every export and every client method has to be
|
|
10
|
+
* declared here, so the two cannot drift apart unnoticed.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export declare const DEFAULT_URL: string;
|
|
14
|
+
|
|
15
|
+
export declare class ZygoError extends Error {}
|
|
16
|
+
/** The API could not be reached, or answered with something unreadable. */
|
|
17
|
+
export declare class TransportError extends ZygoError {}
|
|
18
|
+
/** The token was missing, wrong, or not permitted to do this. */
|
|
19
|
+
export declare class AuthError extends ZygoError {}
|
|
20
|
+
/** No function under that name. */
|
|
21
|
+
export declare class NotFound extends ZygoError {}
|
|
22
|
+
/** The sandbox as described could not be resolved. */
|
|
23
|
+
export declare class SpecError extends ZygoError {}
|
|
24
|
+
|
|
25
|
+
/** Backpressure: the request never ran, and retrying is the right answer. */
|
|
26
|
+
export declare class Busy extends ZygoError {
|
|
27
|
+
inFlight: number;
|
|
28
|
+
queued: number;
|
|
29
|
+
limit: number;
|
|
30
|
+
/** Seconds, from the server's `Retry-After`. */
|
|
31
|
+
retryAfter: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The host cannot do this *yet*: a 503, and nothing about the request needs
|
|
36
|
+
* changing. A pool named against a dependency set still building
|
|
37
|
+
* (`code === 'deps_building'`), a zygote that failed to warm
|
|
38
|
+
* (`'warm_failed'`), or an API that is draining. The request never ran, so
|
|
39
|
+
* sending it again is safe; `retries` on the client does that for you.
|
|
40
|
+
*/
|
|
41
|
+
export declare class Unavailable extends ZygoError {
|
|
42
|
+
code: string;
|
|
43
|
+
/** Seconds, from the server's `Retry-After`; 1 when it sent none. */
|
|
44
|
+
retryAfter: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Somebody stopped this request — usually the caller.
|
|
49
|
+
*
|
|
50
|
+
* Deliberately not a {@link Timeout}: "too slow, raise the limit" is the wrong
|
|
51
|
+
* advice for a request somebody stopped on purpose.
|
|
52
|
+
*/
|
|
53
|
+
export declare class Cancelled extends ZygoError {
|
|
54
|
+
requestId: string;
|
|
55
|
+
stdout: string;
|
|
56
|
+
stderr: string;
|
|
57
|
+
metrics: Metrics;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The sandbox stopped reporting this request, and it was killed.
|
|
62
|
+
*
|
|
63
|
+
* Not a {@link Timeout}: the work had budget left, so the thing to look at is
|
|
64
|
+
* the function rather than its `timeout`.
|
|
65
|
+
*/
|
|
66
|
+
export declare class Stuck extends ZygoError {
|
|
67
|
+
requestId: string;
|
|
68
|
+
stdout: string;
|
|
69
|
+
stderr: string;
|
|
70
|
+
metrics: Metrics;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The request exceeded the function's timeout and was killed. */
|
|
74
|
+
export declare class Timeout extends ZygoError {
|
|
75
|
+
stderr: string;
|
|
76
|
+
metrics: Metrics;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The handler threw. */
|
|
80
|
+
export declare class HandlerError extends ZygoError {
|
|
81
|
+
stdout: string;
|
|
82
|
+
stderr: string;
|
|
83
|
+
exitCode: number;
|
|
84
|
+
metrics: Metrics;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface Metrics {
|
|
88
|
+
wallMs: number;
|
|
89
|
+
cpuMs: number;
|
|
90
|
+
peakRssKb: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface Result<T = unknown> {
|
|
94
|
+
/** The handler's own return value. */
|
|
95
|
+
result: T;
|
|
96
|
+
/** The server's id for this request, which {@link Client.cancel} accepts. */
|
|
97
|
+
requestId: string;
|
|
98
|
+
/** The sandbox's `/out` as a tar, when the call asked for it with `out`; otherwise `null`. */
|
|
99
|
+
workspace: Buffer | null;
|
|
100
|
+
/** What this request's process wrote, separately from the zygote's output. */
|
|
101
|
+
stdout: string;
|
|
102
|
+
stderr: string;
|
|
103
|
+
metrics: Metrics;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* One line of a streaming call: a piece of output while the request runs,
|
|
108
|
+
* then exactly one `result` carrying what {@link Client.call} would have
|
|
109
|
+
* returned.
|
|
110
|
+
*/
|
|
111
|
+
export type StreamEvent<T = unknown> =
|
|
112
|
+
| { kind: 'stdout' | 'stderr' | 'progress'; data: string }
|
|
113
|
+
| { kind: 'result'; result: Result<T>; status: number };
|
|
114
|
+
|
|
115
|
+
/** What `health()` answers. `stopping` arrives as an {@link Unavailable} instead. */
|
|
116
|
+
export interface Health {
|
|
117
|
+
ok: boolean;
|
|
118
|
+
status: 'ok' | 'degraded' | string;
|
|
119
|
+
uptime_s: number;
|
|
120
|
+
/** Pools below their `min_warm`, when `status` is `degraded`. */
|
|
121
|
+
below_min_warm?: string[];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* A dependency set: a lockfile built inside an image, once, and mounted into
|
|
126
|
+
* every pool that names its id. `ready` and `building` are `state` as
|
|
127
|
+
* booleans, so a typo in the string is not a condition that is never true.
|
|
128
|
+
*/
|
|
129
|
+
export interface Deps {
|
|
130
|
+
id: string;
|
|
131
|
+
state: 'building' | 'ready' | 'failed' | string;
|
|
132
|
+
ready: boolean;
|
|
133
|
+
building: boolean;
|
|
134
|
+
/** `python` or `node`: which lockfile it was. */
|
|
135
|
+
kind: string;
|
|
136
|
+
image: string;
|
|
137
|
+
/** Why the build failed, when it did. */
|
|
138
|
+
error: string | null;
|
|
139
|
+
/** The build's own output, for a `failed` set. */
|
|
140
|
+
log: string;
|
|
141
|
+
/** The files that were sent, by name. */
|
|
142
|
+
files: Record<string, unknown>;
|
|
143
|
+
/** Tenants that sent these files; empty is the operator's own. */
|
|
144
|
+
tenants: string[];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface FunctionStatus {
|
|
148
|
+
name: string;
|
|
149
|
+
state: string;
|
|
150
|
+
image: string;
|
|
151
|
+
runtime: string;
|
|
152
|
+
rssKb: number;
|
|
153
|
+
importsMs: number;
|
|
154
|
+
requests: number;
|
|
155
|
+
failures: number;
|
|
156
|
+
/** The answer as it arrived, so a field a newer Zygo added is reachable. */
|
|
157
|
+
raw: Record<string, unknown>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface Served {
|
|
161
|
+
name: string;
|
|
162
|
+
/** `started`, `replaced` or `unchanged`. */
|
|
163
|
+
change: string;
|
|
164
|
+
runtime: string;
|
|
165
|
+
rssKb: number;
|
|
166
|
+
importsMs: number;
|
|
167
|
+
warmMs: number;
|
|
168
|
+
warnings: string[];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface RunResult {
|
|
172
|
+
exitCode: number;
|
|
173
|
+
stdout: string;
|
|
174
|
+
stderr: string;
|
|
175
|
+
/** The launcher's deadline killed it. Distinct from `oomKilled`: both are exit 137. */
|
|
176
|
+
timedOut: boolean;
|
|
177
|
+
/** The kernel killed something in the sandbox for running out of memory. */
|
|
178
|
+
oomKilled: boolean;
|
|
179
|
+
/** Peak resident memory of the sandbox, from its cgroup. */
|
|
180
|
+
peakRssKb: number;
|
|
181
|
+
wallMs: number;
|
|
182
|
+
/**
|
|
183
|
+
* Whether the program ran at all. `false` is Zygo failing to build the
|
|
184
|
+
* sandbox — unavailable, not the program's failure; `phase` says how far
|
|
185
|
+
* it got (`plan`, `start`, or `run` when it ran).
|
|
186
|
+
*/
|
|
187
|
+
started: boolean;
|
|
188
|
+
phase: 'plan' | 'start' | 'run' | string;
|
|
189
|
+
readonly ok: boolean;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* One runtime pool: several anonymous zygotes any script can run in.
|
|
194
|
+
*
|
|
195
|
+
* `warm` and `paused` are zygotes that exist; `cold` is the room left between
|
|
196
|
+
* them and `maxWarm`. A pool has no single state — four zygotes of which two
|
|
197
|
+
* are frozen is working and idle at once — so the counts are what is reported.
|
|
198
|
+
*/
|
|
199
|
+
export interface RuntimePool {
|
|
200
|
+
name: string;
|
|
201
|
+
image: string;
|
|
202
|
+
/** What the agent announced, e.g. `python/3.12.4`. */
|
|
203
|
+
runtime: string;
|
|
204
|
+
warm: number;
|
|
205
|
+
paused: number;
|
|
206
|
+
cold: number;
|
|
207
|
+
min_warm: number;
|
|
208
|
+
max_warm: number;
|
|
209
|
+
in_flight: number;
|
|
210
|
+
queued: number;
|
|
211
|
+
requests: number;
|
|
212
|
+
failures: number;
|
|
213
|
+
rss_kb: number;
|
|
214
|
+
uptime_s: number;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* What a tenant may not exceed.
|
|
219
|
+
*
|
|
220
|
+
* Every key only ever narrows: applied as the minimum of itself and whatever
|
|
221
|
+
* the function or pool was declared with.
|
|
222
|
+
*/
|
|
223
|
+
export interface TenantLimits {
|
|
224
|
+
mem?: string;
|
|
225
|
+
cpu?: number;
|
|
226
|
+
pids?: number;
|
|
227
|
+
timeout?: string;
|
|
228
|
+
scratch?: string;
|
|
229
|
+
network?: 'none' | 'egress' | 'full' | 'host';
|
|
230
|
+
allow?: string[];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** One customer of whoever embedded Zygo. */
|
|
234
|
+
export interface Tenant {
|
|
235
|
+
id: string;
|
|
236
|
+
created_ms: number;
|
|
237
|
+
/** Digests of the scripts registered for this tenant. */
|
|
238
|
+
scripts: string[];
|
|
239
|
+
/** What this tenant may not exceed. Absent when nothing was set. */
|
|
240
|
+
limits?: TenantLimits;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* One API token, as the server holds it — never the secret.
|
|
245
|
+
*
|
|
246
|
+
* `tenant` is absent on an operator token, which may create tenants and pools
|
|
247
|
+
* and mint more tokens; a tenant token registers scripts and calls, for its own
|
|
248
|
+
* tenant only.
|
|
249
|
+
*/
|
|
250
|
+
export interface Token {
|
|
251
|
+
id: string;
|
|
252
|
+
/** Absent for an operator token. */
|
|
253
|
+
tenant?: string;
|
|
254
|
+
created_ms: number;
|
|
255
|
+
/** When it was revoked, if it was. A revoked token stops resolving. */
|
|
256
|
+
revoked_ms?: number;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** A script the host holds, named by the SHA-256 of its bytes. */
|
|
260
|
+
export interface Script {
|
|
261
|
+
/** `sha256:…`, which is the script's name everywhere else. */
|
|
262
|
+
sha256: string;
|
|
263
|
+
size: number;
|
|
264
|
+
/**
|
|
265
|
+
* The store already had exactly these bytes. What deduplication looks like
|
|
266
|
+
* from outside: two tenants registering the same script get one file.
|
|
267
|
+
*/
|
|
268
|
+
existed: boolean;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export interface LogEntry {
|
|
272
|
+
seq: number;
|
|
273
|
+
at_ms: number;
|
|
274
|
+
text: string;
|
|
275
|
+
[key: string]: unknown;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface LogPage {
|
|
279
|
+
name: string;
|
|
280
|
+
entries: LogEntry[];
|
|
281
|
+
/** Pass as `after` to continue from here. */
|
|
282
|
+
next: number;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* A sandbox as `sandbox.toml` would describe it. Keys and value syntax are the
|
|
287
|
+
* spec's own, so `mem: '512M'` and `timeout: '30s'` are written as they would
|
|
288
|
+
* be in the file.
|
|
289
|
+
*/
|
|
290
|
+
export interface Layer {
|
|
291
|
+
image?: string;
|
|
292
|
+
cmd?: string[];
|
|
293
|
+
entry?: string;
|
|
294
|
+
requirements?: string;
|
|
295
|
+
system?: string[];
|
|
296
|
+
mem?: string;
|
|
297
|
+
cpu?: number;
|
|
298
|
+
pids?: number;
|
|
299
|
+
timeout?: string;
|
|
300
|
+
scratch?: string;
|
|
301
|
+
nofile?: number;
|
|
302
|
+
network?: 'none' | 'egress' | 'full' | 'host';
|
|
303
|
+
allow?: string[];
|
|
304
|
+
mounts?: string[];
|
|
305
|
+
env?: Record<string, string>;
|
|
306
|
+
secrets?: string[];
|
|
307
|
+
isolation?: 'ns' | 'gvisor' | 'vm';
|
|
308
|
+
seccomp?: string;
|
|
309
|
+
concurrency?: number;
|
|
310
|
+
idle_timeout?: string;
|
|
311
|
+
cold_after?: string;
|
|
312
|
+
workdir?: string;
|
|
313
|
+
user?: string;
|
|
314
|
+
/** `[runtime.<name>]` only: which agent to warm, and how many zygotes. */
|
|
315
|
+
agent?: string | { agent: string };
|
|
316
|
+
min_warm?: number;
|
|
317
|
+
max_warm?: number;
|
|
318
|
+
[key: string]: unknown;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface CallOptions {
|
|
322
|
+
/** Seconds this caller will wait. The function's own timeout still wins. */
|
|
323
|
+
timeout?: number;
|
|
324
|
+
/**
|
|
325
|
+
* A name *you* choose for this request, so that something else can stop it
|
|
326
|
+
* with {@link Client.cancel} before it answers. Reusing a key is allowed and
|
|
327
|
+
* means one cancel stops every call under it.
|
|
328
|
+
*/
|
|
329
|
+
key?: string;
|
|
330
|
+
/** Aborting it sends the cancel for you. A key is generated if none was given. */
|
|
331
|
+
signal?: AbortSignal;
|
|
332
|
+
/** A blob digest from {@link Client.putBlob} to unpack into the sandbox. */
|
|
333
|
+
workspace?: string;
|
|
334
|
+
/** Ask for the sandbox's `/out` back, as `workspace` on the result. */
|
|
335
|
+
out?: boolean;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** What `batch` accepts: only the timeout, since one key cannot name many requests. */
|
|
339
|
+
export interface BatchOptions {
|
|
340
|
+
timeout?: number;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export interface RunScriptOptions {
|
|
344
|
+
/** The function in the script to call. The agent's default when absent. */
|
|
345
|
+
entryPoint?: string;
|
|
346
|
+
timeout?: number;
|
|
347
|
+
key?: string;
|
|
348
|
+
signal?: AbortSignal;
|
|
349
|
+
/**
|
|
350
|
+
* Files to put in the sandbox before the script runs: a blob digest, or an
|
|
351
|
+
* inline description, as the API's `workspace` body field takes it.
|
|
352
|
+
*/
|
|
353
|
+
workspace?: string | Record<string, unknown>;
|
|
354
|
+
out?: boolean;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export interface FunctionHandle<T = unknown> {
|
|
358
|
+
(event?: unknown, options?: CallOptions): Promise<Result<T>>;
|
|
359
|
+
/** The function's name; `name` is taken by every JavaScript function. */
|
|
360
|
+
readonly name_: string;
|
|
361
|
+
batch(events: unknown[], options?: BatchOptions): Promise<Array<Result<T> | ZygoError>>;
|
|
362
|
+
stats(): Promise<FunctionStatus>;
|
|
363
|
+
logs(options?: { after?: number; limit?: number; failed?: boolean }): Promise<LogPage>;
|
|
364
|
+
warm(): Promise<Record<string, unknown>>;
|
|
365
|
+
stop(): Promise<string[]>;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export interface ClientOptions {
|
|
369
|
+
/** Defaults to `ZYGO_API_TOKEN`. Pass `null` for an API with no auth. */
|
|
370
|
+
token?: string | null;
|
|
371
|
+
/** Milliseconds one HTTP exchange may take. Defaults to five minutes. */
|
|
372
|
+
timeout?: number;
|
|
373
|
+
/**
|
|
374
|
+
* How many times a *refused* request — {@link Busy} or {@link Unavailable},
|
|
375
|
+
* both meaning it never ran — is sent again before its error reaches you.
|
|
376
|
+
* Nothing else is retried. Defaults to 0.
|
|
377
|
+
*/
|
|
378
|
+
retries?: number;
|
|
379
|
+
/**
|
|
380
|
+
* Seconds. Each wait is the longer of the server's `Retry-After` and this,
|
|
381
|
+
* doubled per attempt. Defaults to 1.
|
|
382
|
+
*/
|
|
383
|
+
backoff?: number;
|
|
384
|
+
/** Act for one tenant on every call; what {@link Client.forTenant} sets. */
|
|
385
|
+
tenant?: string | null;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export declare class Client {
|
|
389
|
+
constructor(url?: string, options?: ClientOptions);
|
|
390
|
+
readonly endpoint: { url: string; socketPath?: string; host: string; port: number; tls: boolean; isUnix: boolean };
|
|
391
|
+
token: string | null;
|
|
392
|
+
timeout: number;
|
|
393
|
+
retries: number;
|
|
394
|
+
backoff: number;
|
|
395
|
+
|
|
396
|
+
close(): void;
|
|
397
|
+
|
|
398
|
+
version(): Promise<{ version: string; api: number; control: number; deploy: boolean }>;
|
|
399
|
+
/** Needs no token. Throws {@link Unavailable} once the API is stopping. */
|
|
400
|
+
health(): Promise<Health>;
|
|
401
|
+
/**
|
|
402
|
+
* Stop admitting, let what is running finish, then exit. `inFlight` is what
|
|
403
|
+
* was still running when the grace (seconds) ran out. Operator-only, needs
|
|
404
|
+
* deploy rights.
|
|
405
|
+
*/
|
|
406
|
+
drain(grace?: number): Promise<{ drained: boolean; inFlight: number }>;
|
|
407
|
+
functions(): Promise<FunctionStatus[]>;
|
|
408
|
+
stats(name: string): Promise<FunctionStatus>;
|
|
409
|
+
warm(name: string): Promise<Record<string, unknown>>;
|
|
410
|
+
|
|
411
|
+
call<T = unknown>(name: string, event?: unknown, options?: CallOptions): Promise<Result<T>>;
|
|
412
|
+
/**
|
|
413
|
+
* Call a function and yield its output as it is produced. Breaking out of
|
|
414
|
+
* the loop closes the connection but does not cancel the request; pass a
|
|
415
|
+
* `key` or a `signal` for that.
|
|
416
|
+
*/
|
|
417
|
+
stream<T = unknown>(name: string, event?: unknown, options?: CallOptions): AsyncIterable<StreamEvent<T>>;
|
|
418
|
+
/** Run a script in a pool, yielding its output. See {@link stream}. */
|
|
419
|
+
streamScript<T = unknown>(
|
|
420
|
+
runtime: string,
|
|
421
|
+
script: string,
|
|
422
|
+
event?: unknown,
|
|
423
|
+
options?: RunScriptOptions
|
|
424
|
+
): AsyncIterable<StreamEvent<T>>;
|
|
425
|
+
/**
|
|
426
|
+
* Stop a request that is running, by the server's id or the `key` it was
|
|
427
|
+
* called with. `started` says whether the handler had begun. Throws
|
|
428
|
+
* {@link NotFound} when nothing is running under that name.
|
|
429
|
+
*/
|
|
430
|
+
cancel(requestId: string): Promise<{ cancelled: boolean; started: boolean; [key: string]: unknown }>;
|
|
431
|
+
batch<T = unknown>(name: string, events: unknown[], options?: BatchOptions): Promise<Array<Result<T> | ZygoError>>;
|
|
432
|
+
logs(name: string, options?: { after?: number; limit?: number; failed?: boolean }): Promise<LogPage>;
|
|
433
|
+
|
|
434
|
+
/** Needs an API started with `--allow-deploy`. */
|
|
435
|
+
serve(
|
|
436
|
+
name: string,
|
|
437
|
+
layer: Layer,
|
|
438
|
+
options?: { baseDir?: string; secrets?: Record<string, string>; ifChanged?: boolean }
|
|
439
|
+
): Promise<Served>;
|
|
440
|
+
/** Needs an API started with `--allow-deploy`. */
|
|
441
|
+
stop(name: string): Promise<string[]>;
|
|
442
|
+
/** Needs an API started with `--allow-deploy`. */
|
|
443
|
+
run(image: string, cmd?: string[] | null, options?: Layer & { stdin?: string }): Promise<RunResult>;
|
|
444
|
+
|
|
445
|
+
/** Operator-only. */
|
|
446
|
+
createTenant(id: string): Promise<Tenant>;
|
|
447
|
+
/** Operator-only. */
|
|
448
|
+
tenants(): Promise<Tenant[]>;
|
|
449
|
+
/** Operator-only. */
|
|
450
|
+
tenant(id: string): Promise<Tenant>;
|
|
451
|
+
/** Operator-only, and needs an API started with `--allow-deploy`. */
|
|
452
|
+
deleteTenant(id: string): Promise<{ deleted: boolean; removed_scripts: string[]; stopped: string[] }>;
|
|
453
|
+
/** A view of this client that acts for one tenant. */
|
|
454
|
+
forTenant(id: string): Client;
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* What a tenant may not exceed. These only ever narrow; a value above every
|
|
458
|
+
* ceiling the tenant has is a 422. Operator-only, needs deploy rights.
|
|
459
|
+
*/
|
|
460
|
+
setLimits(tenant: string, limits: TenantLimits): Promise<Tenant>;
|
|
461
|
+
|
|
462
|
+
/** Store one of a tenant's secrets. Operator-only, needs deploy rights. */
|
|
463
|
+
putSecret(tenant: string, name: string, value: string): Promise<string[]>;
|
|
464
|
+
/** The **names** a tenant has. A value cannot be read back. */
|
|
465
|
+
secrets(tenant: string): Promise<string[]>;
|
|
466
|
+
/** Forget one. Operator-only, needs deploy rights. */
|
|
467
|
+
deleteSecret(tenant: string, name: string): Promise<string[]>;
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Mint a token and get its secret, once. Operator-only, needs deploy rights.
|
|
471
|
+
*
|
|
472
|
+
* Pass a tenant id for a tenant token, or nothing for an operator token.
|
|
473
|
+
*/
|
|
474
|
+
mintToken(tenant?: string | null): Promise<{ token: Token; secret: string }>;
|
|
475
|
+
/** Every token, revoked ones included. Never a secret. Operator-only. */
|
|
476
|
+
tokens(): Promise<Token[]>;
|
|
477
|
+
/** Revoke one, from the next request onwards. Operator-only. */
|
|
478
|
+
revokeToken(id: string): Promise<{ revoked: boolean; token: Token | null }>;
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Register a runtime pool. `deps` is an id from {@link putDeps}; a pool
|
|
482
|
+
* named against one still building throws {@link Unavailable}. `secrets`
|
|
483
|
+
* names the secrets each call may receive, from the *calling* tenant's
|
|
484
|
+
* store. Needs an API started with `--allow-deploy`.
|
|
485
|
+
*/
|
|
486
|
+
serveRuntime(
|
|
487
|
+
name: string,
|
|
488
|
+
layer: Layer,
|
|
489
|
+
options?: { baseDir?: string; deps?: string; secrets?: string[] }
|
|
490
|
+
): Promise<Record<string, unknown>>;
|
|
491
|
+
runtimes(): Promise<RuntimePool[]>;
|
|
492
|
+
/** Needs an API started with `--allow-deploy`. */
|
|
493
|
+
stopRuntime(name: string): Promise<string[]>;
|
|
494
|
+
runScript<T = unknown>(
|
|
495
|
+
runtime: string,
|
|
496
|
+
script: string,
|
|
497
|
+
event?: unknown,
|
|
498
|
+
options?: RunScriptOptions
|
|
499
|
+
): Promise<Result<T>>;
|
|
500
|
+
|
|
501
|
+
/** Needs an API started with `--allow-deploy`. */
|
|
502
|
+
putScript(source: string): Promise<Script>;
|
|
503
|
+
script(digest: string): Promise<Script>;
|
|
504
|
+
/** Needs an API started with `--allow-deploy`. */
|
|
505
|
+
deleteScript(digest: string): Promise<boolean>;
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Store a tar this host will hold under its digest, to name as `workspace`
|
|
509
|
+
* on calls. The body is the tar itself.
|
|
510
|
+
*/
|
|
511
|
+
putBlob(tar: Uint8Array | ArrayBuffer | string): Promise<Script>;
|
|
512
|
+
/** Whether this host holds a blob, and how big it is. */
|
|
513
|
+
blob(digest: string): Promise<Script>;
|
|
514
|
+
/** Forget a blob. Operator-only: the store is shared by digest. */
|
|
515
|
+
deleteBlob(digest: string): Promise<boolean>;
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Build a dependency set from a lockfile, inside `image`. Answers before
|
|
519
|
+
* the build finishes, with `building` true; poll {@link deps} or name the
|
|
520
|
+
* id on {@link serveRuntime} and retry the {@link Unavailable}.
|
|
521
|
+
*/
|
|
522
|
+
putDeps(image: string, files: Record<string, string | Uint8Array>): Promise<Deps>;
|
|
523
|
+
/** One dependency set with its build log, or every one you can see. */
|
|
524
|
+
deps(id: string): Promise<Deps>;
|
|
525
|
+
deps(): Promise<Deps[]>;
|
|
526
|
+
/** Forget a dependency set. Refused while a pool is built on it. */
|
|
527
|
+
deleteDeps(id: string): Promise<boolean>;
|
|
528
|
+
|
|
529
|
+
fn<T = unknown>(name: string): FunctionHandle<T>;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export declare function connect(url?: string, options?: ClientOptions): Client;
|
|
533
|
+
|
|
534
|
+
export declare function parseEndpoint(text: string): {
|
|
535
|
+
url: string;
|
|
536
|
+
socketPath?: string;
|
|
537
|
+
host: string;
|
|
538
|
+
port: number;
|
|
539
|
+
tls: boolean;
|
|
540
|
+
isUnix: boolean;
|
|
541
|
+
};
|