modal 0.3.4 → 0.3.6
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/README.md +1 -0
- package/dist/index.d.ts +178 -2
- package/dist/index.js +1391 -74
- package/package.json +10 -1
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# Modal JavaScript Library
|
|
2
2
|
|
|
3
|
+
[](https://modal-labs.github.io/libmodal/)
|
|
3
4
|
[](https://www.npmjs.org/package/modal)
|
|
4
5
|
[](https://github.com/modal-labs/libmodal/actions?query=branch%3Amain)
|
|
5
6
|
[](https://www.npmjs.com/package/modal)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
|
|
2
2
|
|
|
3
|
+
/** A container image, used for starting sandboxes. */
|
|
3
4
|
declare class Image {
|
|
4
5
|
readonly imageId: string;
|
|
6
|
+
/** @ignore */
|
|
5
7
|
constructor(imageId: string);
|
|
6
8
|
}
|
|
7
9
|
|
|
@@ -42,19 +44,33 @@ interface ModalWriteStream<R = any> extends WritableStream<R> {
|
|
|
42
44
|
writeBytes(bytes: Uint8Array): Promise<void>;
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Stdin is always present, but this option allow you to drop stdout or stderr
|
|
49
|
+
* if you don't need them. The default is "pipe", matching Node.js behavior.
|
|
50
|
+
*
|
|
51
|
+
* If behavior is set to "ignore", the output streams will be empty.
|
|
52
|
+
*/
|
|
45
53
|
type StdioBehavior = "pipe" | "ignore";
|
|
54
|
+
/**
|
|
55
|
+
* Specifies the type of data that will be read from the sandbox or container
|
|
56
|
+
* process. "text" means the data will be read as UTF-8 text, while "binary"
|
|
57
|
+
* means the data will be read as raw bytes (Uint8Array).
|
|
58
|
+
*/
|
|
46
59
|
type StreamMode = "text" | "binary";
|
|
60
|
+
/** Options to configure a `Sandbox.exec()` operation. */
|
|
47
61
|
type ExecOptions = {
|
|
48
62
|
mode?: StreamMode;
|
|
49
63
|
stdout?: StdioBehavior;
|
|
50
64
|
stderr?: StdioBehavior;
|
|
51
65
|
};
|
|
66
|
+
/** Sandboxes are secure, isolated containers in Modal that boot in seconds. */
|
|
52
67
|
declare class Sandbox {
|
|
53
68
|
#private;
|
|
54
69
|
readonly sandboxId: string;
|
|
55
70
|
stdin: ModalWriteStream<string>;
|
|
56
71
|
stdout: ModalReadStream<string>;
|
|
57
72
|
stderr: ModalReadStream<string>;
|
|
73
|
+
/** @ignore */
|
|
58
74
|
constructor(sandboxId: string);
|
|
59
75
|
exec(command: string[], options?: ExecOptions & {
|
|
60
76
|
mode?: "text";
|
|
@@ -76,18 +92,37 @@ declare class ContainerProcess<R extends string | Uint8Array = any> {
|
|
|
76
92
|
wait(): Promise<number>;
|
|
77
93
|
}
|
|
78
94
|
|
|
95
|
+
/** Options for functions that find deployed Modal objects. */
|
|
79
96
|
type LookupOptions = {
|
|
80
97
|
environment?: string;
|
|
81
98
|
createIfMissing?: boolean;
|
|
82
99
|
};
|
|
100
|
+
/** Options for deleting a named object. */
|
|
101
|
+
type DeleteOptions = {
|
|
102
|
+
environment?: string;
|
|
103
|
+
};
|
|
104
|
+
/** Options for constructors that create a temporary, nameless object. */
|
|
105
|
+
type EphemeralOptions = {
|
|
106
|
+
environment?: string;
|
|
107
|
+
};
|
|
108
|
+
/** Options for `App.createSandbox()`. */
|
|
83
109
|
type SandboxCreateOptions = {
|
|
110
|
+
/** Reservation of physical CPU cores for the sandbox, can be fractional. */
|
|
84
111
|
cpu?: number;
|
|
112
|
+
/** Reservation of memory in MiB. */
|
|
85
113
|
memory?: number;
|
|
114
|
+
/** Timeout of the sandbox container, defaults to 10 minutes. */
|
|
86
115
|
timeout?: number;
|
|
116
|
+
/**
|
|
117
|
+
* Sequence of program arguments for the main process.
|
|
118
|
+
* Default behavior is to sleep indefinitely until timeout or termination.
|
|
119
|
+
*/
|
|
87
120
|
command?: string[];
|
|
88
121
|
};
|
|
122
|
+
/** Represents a deployed Modal App. */
|
|
89
123
|
declare class App {
|
|
90
124
|
readonly appId: string;
|
|
125
|
+
/** @ignore */
|
|
91
126
|
constructor(appId: string);
|
|
92
127
|
/** Lookup a deployed app by name, or create if it does not exist. */
|
|
93
128
|
static lookup(name: string, options?: LookupOptions): Promise<App>;
|
|
@@ -145,18 +180,47 @@ interface MessageFns<T> {
|
|
|
145
180
|
fromPartial(object: DeepPartial<T>): T;
|
|
146
181
|
}
|
|
147
182
|
|
|
183
|
+
/** Options for `FunctionCall.get()`. */
|
|
184
|
+
type FunctionCallGetOptions = {
|
|
185
|
+
timeout?: number;
|
|
186
|
+
};
|
|
187
|
+
/** Options for `FunctionCall.cancel()`. */
|
|
188
|
+
type FunctionCallCancelOptions = {
|
|
189
|
+
terminateContainers?: boolean;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Represents a Modal FunctionCall. Function Calls are Function invocations with
|
|
193
|
+
* a given input. They can be consumed asynchronously (see `get()`) or cancelled
|
|
194
|
+
* (see `cancel()`).
|
|
195
|
+
*/
|
|
196
|
+
declare class FunctionCall {
|
|
197
|
+
readonly functionCallId: string;
|
|
198
|
+
/** @ignore */
|
|
199
|
+
constructor(functionCallId: string);
|
|
200
|
+
/** Create a new function call from ID. */
|
|
201
|
+
fromId(functionCallId: string): FunctionCall;
|
|
202
|
+
/** Get the result of a function call, optionally waiting with a timeout. */
|
|
203
|
+
get(options?: FunctionCallGetOptions): Promise<any>;
|
|
204
|
+
/** Cancel a running function call. */
|
|
205
|
+
cancel(options?: FunctionCallCancelOptions): Promise<void>;
|
|
206
|
+
}
|
|
207
|
+
|
|
148
208
|
/** Represents a deployed Modal Function, which can be invoked remotely. */
|
|
149
209
|
declare class Function_ {
|
|
210
|
+
#private;
|
|
150
211
|
readonly functionId: string;
|
|
151
212
|
readonly methodName: string | undefined;
|
|
213
|
+
/** @ignore */
|
|
152
214
|
constructor(functionId: string, methodName?: string);
|
|
153
215
|
static lookup(appName: string, name: string, options?: LookupOptions): Promise<Function_>;
|
|
154
216
|
remote(args?: any[], kwargs?: Record<string, any>): Promise<any>;
|
|
217
|
+
spawn(args?: any[], kwargs?: Record<string, any>): Promise<FunctionCall>;
|
|
155
218
|
}
|
|
156
219
|
|
|
157
220
|
/** Represents a deployed Modal Cls. */
|
|
158
221
|
declare class Cls {
|
|
159
222
|
#private;
|
|
223
|
+
/** @ignore */
|
|
160
224
|
constructor(serviceFunctionId: string, schema: ClassParameterSpec[], methodNames: string[]);
|
|
161
225
|
static lookup(appName: string, name: string, options?: LookupOptions): Promise<Cls>;
|
|
162
226
|
/** Create a new instance of the Cls with parameters. */
|
|
@@ -170,7 +234,7 @@ declare class ClsInstance {
|
|
|
170
234
|
}
|
|
171
235
|
|
|
172
236
|
/** Function execution exceeds the allowed time limit. */
|
|
173
|
-
declare class
|
|
237
|
+
declare class FunctionTimeoutError extends Error {
|
|
174
238
|
constructor(message: string);
|
|
175
239
|
}
|
|
176
240
|
/** An error on the Modal server, or a Python exception. */
|
|
@@ -185,5 +249,117 @@ declare class InternalFailure extends Error {
|
|
|
185
249
|
declare class NotFoundError extends Error {
|
|
186
250
|
constructor(message: string);
|
|
187
251
|
}
|
|
252
|
+
/** A request or other operation was invalid. */
|
|
253
|
+
declare class InvalidError extends Error {
|
|
254
|
+
constructor(message: string);
|
|
255
|
+
}
|
|
256
|
+
/** The queue is empty. */
|
|
257
|
+
declare class QueueEmptyError extends Error {
|
|
258
|
+
constructor(message: string);
|
|
259
|
+
}
|
|
260
|
+
/** The queue is full. */
|
|
261
|
+
declare class QueueFullError extends Error {
|
|
262
|
+
constructor(message: string);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Options to configure a `Queue.clear()` operation. */
|
|
266
|
+
type QueueClearOptions = {
|
|
267
|
+
/** Partition to clear, uses default partition if not set. */
|
|
268
|
+
partition?: string;
|
|
269
|
+
/** Set to clear all queue partitions. */
|
|
270
|
+
all?: boolean;
|
|
271
|
+
};
|
|
272
|
+
/** Options to configure a `Queue.get()` or `Queue.getMany()` operation. */
|
|
273
|
+
type QueueGetOptions = {
|
|
274
|
+
/** How long to wait if the queue is empty (default: indefinite). */
|
|
275
|
+
timeout?: number;
|
|
276
|
+
/** Partition to fetch values from, uses default partition if not set. */
|
|
277
|
+
partition?: string;
|
|
278
|
+
};
|
|
279
|
+
/** Options to configure a `Queue.put()` or `Queue.putMany()` operation. */
|
|
280
|
+
type QueuePutOptions = {
|
|
281
|
+
/** How long to wait if the queue is full (default: indefinite). */
|
|
282
|
+
timeout?: number;
|
|
283
|
+
/** Partition to add items to, uses default partition if not set. */
|
|
284
|
+
partition?: string;
|
|
285
|
+
/** TTL for the partition in seconds (default: 1 day). */
|
|
286
|
+
partitionTtl?: number;
|
|
287
|
+
};
|
|
288
|
+
/** Options to configure a `Queue.len()` operation. */
|
|
289
|
+
type QueueLenOptions = {
|
|
290
|
+
/** Partition to compute length, uses default partition if not set. */
|
|
291
|
+
partition?: string;
|
|
292
|
+
/** Return the total length across all partitions. */
|
|
293
|
+
total?: boolean;
|
|
294
|
+
};
|
|
295
|
+
/** Options to configure a `Queue.iterate()` operation. */
|
|
296
|
+
type QueueIterateOptions = {
|
|
297
|
+
/** How long to wait between successive items before exiting iteration (default: 0). */
|
|
298
|
+
itemPollTimeout?: number;
|
|
299
|
+
/** Partition to iterate, uses default partition if not set. */
|
|
300
|
+
partition?: string;
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* Distributed, FIFO queue for data flow in Modal apps.
|
|
304
|
+
*/
|
|
305
|
+
declare class Queue {
|
|
306
|
+
#private;
|
|
307
|
+
readonly queueId: string;
|
|
308
|
+
/** @ignore */
|
|
309
|
+
constructor(queueId: string, ephemeral?: boolean);
|
|
310
|
+
/**
|
|
311
|
+
* Create a nameless, temporary queue.
|
|
312
|
+
* You will need to call `closeEphemeral()` to delete the queue.
|
|
313
|
+
*/
|
|
314
|
+
static ephemeral(options?: EphemeralOptions): Promise<Queue>;
|
|
315
|
+
/** Delete the ephemeral queue. Only usable with `Queue.ephemeral()`. */
|
|
316
|
+
closeEphemeral(): void;
|
|
317
|
+
/**
|
|
318
|
+
* Lookup a queue by name.
|
|
319
|
+
*/
|
|
320
|
+
static lookup(name: string, options?: LookupOptions): Promise<Queue>;
|
|
321
|
+
/** Delete a queue by name. */
|
|
322
|
+
static delete(name: string, options?: DeleteOptions): Promise<void>;
|
|
323
|
+
/**
|
|
324
|
+
* Remove all objects from a queue partition.
|
|
325
|
+
*/
|
|
326
|
+
clear(options?: QueueClearOptions): Promise<void>;
|
|
327
|
+
/**
|
|
328
|
+
* Remove and return the next object from the queue.
|
|
329
|
+
*
|
|
330
|
+
* By default, this will wait until at least one item is present in the queue.
|
|
331
|
+
* If `timeout` is set, raises `QueueEmptyError` if no items are available
|
|
332
|
+
* within that timeout in milliseconds.
|
|
333
|
+
*/
|
|
334
|
+
get(options?: QueueGetOptions): Promise<any | null>;
|
|
335
|
+
/**
|
|
336
|
+
* Remove and return up to `n` objects from the queue.
|
|
337
|
+
*
|
|
338
|
+
* By default, this will wait until at least one item is present in the queue.
|
|
339
|
+
* If `timeout` is set, raises `QueueEmptyError` if no items are available
|
|
340
|
+
* within that timeout in milliseconds.
|
|
341
|
+
*/
|
|
342
|
+
getMany(n: number, options?: QueueGetOptions): Promise<any[]>;
|
|
343
|
+
/**
|
|
344
|
+
* Add an item to the end of the queue.
|
|
345
|
+
*
|
|
346
|
+
* If the queue is full, this will retry with exponential backoff until the
|
|
347
|
+
* provided `timeout` is reached, or indefinitely if `timeout` is not set.
|
|
348
|
+
* Raises `QueueFullError` if the queue is still full after the timeout.
|
|
349
|
+
*/
|
|
350
|
+
put(v: any, options?: QueuePutOptions): Promise<void>;
|
|
351
|
+
/**
|
|
352
|
+
* Add several items to the end of the queue.
|
|
353
|
+
*
|
|
354
|
+
* If the queue is full, this will retry with exponential backoff until the
|
|
355
|
+
* provided `timeout` is reached, or indefinitely if `timeout` is not set.
|
|
356
|
+
* Raises `QueueFullError` if the queue is still full after the timeout.
|
|
357
|
+
*/
|
|
358
|
+
putMany(values: any[], options?: QueuePutOptions): Promise<void>;
|
|
359
|
+
/** Return the number of objects in the queue. */
|
|
360
|
+
len(options?: QueueLenOptions): Promise<number>;
|
|
361
|
+
/** Iterate through items in a queue without mutation. */
|
|
362
|
+
iterate(options?: QueueIterateOptions): AsyncGenerator<any, void, unknown>;
|
|
363
|
+
}
|
|
188
364
|
|
|
189
|
-
export { App, Cls, ClsInstance, Function_, Image, InternalFailure, type LookupOptions, NotFoundError, RemoteError, Sandbox, type SandboxCreateOptions, type StdioBehavior, type StreamMode
|
|
365
|
+
export { App, Cls, ClsInstance, ContainerProcess, type DeleteOptions, type EphemeralOptions, type ExecOptions, FunctionCall, type FunctionCallCancelOptions, type FunctionCallGetOptions, FunctionTimeoutError, Function_, Image, InternalFailure, InvalidError, type LookupOptions, type ModalReadStream, type ModalWriteStream, NotFoundError, Queue, type QueueClearOptions, QueueEmptyError, QueueFullError, type QueueGetOptions, type QueueIterateOptions, type QueueLenOptions, type QueuePutOptions, RemoteError, Sandbox, type SandboxCreateOptions, type StdioBehavior, type StreamMode };
|