modal 0.3.7 → 0.3.8
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 -1
- package/dist/index.cjs +39574 -0
- package/dist/index.d.cts +380 -0
- package/dist/index.js +180 -118
- package/package.json +2 -2
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
|
|
2
|
+
|
|
3
|
+
declare enum ParameterType {
|
|
4
|
+
PARAM_TYPE_UNSPECIFIED = 0,
|
|
5
|
+
PARAM_TYPE_STRING = 1,
|
|
6
|
+
PARAM_TYPE_INT = 2,
|
|
7
|
+
/** PARAM_TYPE_PICKLE - currently unused */
|
|
8
|
+
PARAM_TYPE_PICKLE = 3,
|
|
9
|
+
PARAM_TYPE_BYTES = 4,
|
|
10
|
+
/** PARAM_TYPE_UNKNOWN - used in schemas to signify unrecognized or un-annotated types */
|
|
11
|
+
PARAM_TYPE_UNKNOWN = 5,
|
|
12
|
+
PARAM_TYPE_LIST = 6,
|
|
13
|
+
PARAM_TYPE_DICT = 7,
|
|
14
|
+
PARAM_TYPE_NONE = 8,
|
|
15
|
+
PARAM_TYPE_BOOL = 9,
|
|
16
|
+
UNRECOGNIZED = -1
|
|
17
|
+
}
|
|
18
|
+
/** TODO: rename into NamedPayloadType or similar */
|
|
19
|
+
interface ClassParameterSpec {
|
|
20
|
+
name: string;
|
|
21
|
+
/** TODO: deprecate - use full_type instead */
|
|
22
|
+
type: ParameterType;
|
|
23
|
+
hasDefault: boolean;
|
|
24
|
+
/** Default *values* are only registered for class parameters */
|
|
25
|
+
stringDefault?: string | undefined;
|
|
26
|
+
intDefault?: number | undefined;
|
|
27
|
+
pickleDefault?: Uint8Array | undefined;
|
|
28
|
+
bytesDefault?: Uint8Array | undefined;
|
|
29
|
+
boolDefault?: boolean | undefined;
|
|
30
|
+
/** supersedes `type` */
|
|
31
|
+
fullType: GenericPayloadType | undefined;
|
|
32
|
+
}
|
|
33
|
+
declare const ClassParameterSpec: MessageFns<ClassParameterSpec>;
|
|
34
|
+
interface GenericPayloadType {
|
|
35
|
+
baseType: ParameterType;
|
|
36
|
+
/** sub-type for generic types like lists */
|
|
37
|
+
subTypes: GenericPayloadType[];
|
|
38
|
+
}
|
|
39
|
+
declare const GenericPayloadType: MessageFns<GenericPayloadType>;
|
|
40
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
41
|
+
type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
42
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
43
|
+
} : Partial<T>;
|
|
44
|
+
interface MessageFns<T> {
|
|
45
|
+
encode(message: T, writer?: BinaryWriter): BinaryWriter;
|
|
46
|
+
decode(input: BinaryReader | Uint8Array, length?: number): T;
|
|
47
|
+
fromJSON(object: any): T;
|
|
48
|
+
toJSON(message: T): unknown;
|
|
49
|
+
create(base?: DeepPartial<T>): T;
|
|
50
|
+
fromPartial(object: DeepPartial<T>): T;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A container image, used for starting sandboxes. */
|
|
54
|
+
declare class Image {
|
|
55
|
+
readonly imageId: string;
|
|
56
|
+
/** @ignore */
|
|
57
|
+
constructor(imageId: string);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Wrapper around `ReadableStream` with convenience functions.
|
|
62
|
+
*
|
|
63
|
+
* The Stream API is a modern standard for asynchronous data streams across
|
|
64
|
+
* network and process boundaries. It allows you to read data in chunks, pipe
|
|
65
|
+
* and transform it, and handle backpressure.
|
|
66
|
+
*
|
|
67
|
+
* This wrapper adds some extra functions like `.readText()` to read the entire
|
|
68
|
+
* stream as a string, or `readBytes()` to read binary data.
|
|
69
|
+
*
|
|
70
|
+
* Background: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API
|
|
71
|
+
*/
|
|
72
|
+
interface ModalReadStream<R = any> extends ReadableStream<R> {
|
|
73
|
+
/** Read the entire stream as a string. */
|
|
74
|
+
readText(): Promise<string>;
|
|
75
|
+
/** Read the entire stream as a byte array. */
|
|
76
|
+
readBytes(): Promise<Uint8Array>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Wrapper around `WritableStream` with convenience functions.
|
|
80
|
+
*
|
|
81
|
+
* The Stream API is a modern standard for asynchronous data streams across
|
|
82
|
+
* network and process boundaries. It allows you to read data in chunks, pipe
|
|
83
|
+
* and transform it, and handle backpressure.
|
|
84
|
+
*
|
|
85
|
+
* This wrapper adds some extra functions like `.writeText()` to write a string
|
|
86
|
+
* to the stream, or `writeBytes()` to write binary data.
|
|
87
|
+
*
|
|
88
|
+
* Background: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API
|
|
89
|
+
*/
|
|
90
|
+
interface ModalWriteStream<R = any> extends WritableStream<R> {
|
|
91
|
+
/** Write a string to the stream. Only if this is a text stream. */
|
|
92
|
+
writeText(text: string): Promise<void>;
|
|
93
|
+
/** Write a byte array to the stream. Only if this is a byte stream. */
|
|
94
|
+
writeBytes(bytes: Uint8Array): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Stdin is always present, but this option allow you to drop stdout or stderr
|
|
99
|
+
* if you don't need them. The default is "pipe", matching Node.js behavior.
|
|
100
|
+
*
|
|
101
|
+
* If behavior is set to "ignore", the output streams will be empty.
|
|
102
|
+
*/
|
|
103
|
+
type StdioBehavior = "pipe" | "ignore";
|
|
104
|
+
/**
|
|
105
|
+
* Specifies the type of data that will be read from the sandbox or container
|
|
106
|
+
* process. "text" means the data will be read as UTF-8 text, while "binary"
|
|
107
|
+
* means the data will be read as raw bytes (Uint8Array).
|
|
108
|
+
*/
|
|
109
|
+
type StreamMode = "text" | "binary";
|
|
110
|
+
/** Options to configure a `Sandbox.exec()` operation. */
|
|
111
|
+
type ExecOptions = {
|
|
112
|
+
mode?: StreamMode;
|
|
113
|
+
stdout?: StdioBehavior;
|
|
114
|
+
stderr?: StdioBehavior;
|
|
115
|
+
};
|
|
116
|
+
/** Sandboxes are secure, isolated containers in Modal that boot in seconds. */
|
|
117
|
+
declare class Sandbox {
|
|
118
|
+
#private;
|
|
119
|
+
readonly sandboxId: string;
|
|
120
|
+
stdin: ModalWriteStream<string>;
|
|
121
|
+
stdout: ModalReadStream<string>;
|
|
122
|
+
stderr: ModalReadStream<string>;
|
|
123
|
+
/** @ignore */
|
|
124
|
+
constructor(sandboxId: string);
|
|
125
|
+
exec(command: string[], options?: ExecOptions & {
|
|
126
|
+
mode?: "text";
|
|
127
|
+
}): Promise<ContainerProcess<string>>;
|
|
128
|
+
exec(command: string[], options: ExecOptions & {
|
|
129
|
+
mode: "binary";
|
|
130
|
+
}): Promise<ContainerProcess<Uint8Array>>;
|
|
131
|
+
terminate(): Promise<void>;
|
|
132
|
+
wait(): Promise<number>;
|
|
133
|
+
}
|
|
134
|
+
declare class ContainerProcess<R extends string | Uint8Array = any> {
|
|
135
|
+
#private;
|
|
136
|
+
stdin: ModalWriteStream<R>;
|
|
137
|
+
stdout: ModalReadStream<R>;
|
|
138
|
+
stderr: ModalReadStream<R>;
|
|
139
|
+
returncode: number | null;
|
|
140
|
+
constructor(execId: string, options?: ExecOptions);
|
|
141
|
+
/** Wait for process completion and return the exit code. */
|
|
142
|
+
wait(): Promise<number>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Options for `Secret.fromName()`. */
|
|
146
|
+
type SecretFromNameOptions = {
|
|
147
|
+
environment?: string;
|
|
148
|
+
requiredKeys?: string[];
|
|
149
|
+
};
|
|
150
|
+
/** Secrets provide a dictionary of environment variables for images. */
|
|
151
|
+
declare class Secret {
|
|
152
|
+
readonly secretId: string;
|
|
153
|
+
/** @ignore */
|
|
154
|
+
constructor(secretId: string);
|
|
155
|
+
/** Reference a Secret by its name. */
|
|
156
|
+
static fromName(name: string, options?: SecretFromNameOptions): Promise<Secret>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Options for functions that find deployed Modal objects. */
|
|
160
|
+
type LookupOptions = {
|
|
161
|
+
environment?: string;
|
|
162
|
+
createIfMissing?: boolean;
|
|
163
|
+
};
|
|
164
|
+
/** Options for deleting a named object. */
|
|
165
|
+
type DeleteOptions = {
|
|
166
|
+
environment?: string;
|
|
167
|
+
};
|
|
168
|
+
/** Options for constructors that create a temporary, nameless object. */
|
|
169
|
+
type EphemeralOptions = {
|
|
170
|
+
environment?: string;
|
|
171
|
+
};
|
|
172
|
+
/** Options for `App.createSandbox()`. */
|
|
173
|
+
type SandboxCreateOptions = {
|
|
174
|
+
/** Reservation of physical CPU cores for the sandbox, can be fractional. */
|
|
175
|
+
cpu?: number;
|
|
176
|
+
/** Reservation of memory in MiB. */
|
|
177
|
+
memory?: number;
|
|
178
|
+
/** Timeout of the sandbox container, defaults to 10 minutes. */
|
|
179
|
+
timeout?: number;
|
|
180
|
+
/**
|
|
181
|
+
* Sequence of program arguments for the main process.
|
|
182
|
+
* Default behavior is to sleep indefinitely until timeout or termination.
|
|
183
|
+
*/
|
|
184
|
+
command?: string[];
|
|
185
|
+
};
|
|
186
|
+
/** Represents a deployed Modal App. */
|
|
187
|
+
declare class App {
|
|
188
|
+
readonly appId: string;
|
|
189
|
+
/** @ignore */
|
|
190
|
+
constructor(appId: string);
|
|
191
|
+
/** Lookup a deployed app by name, or create if it does not exist. */
|
|
192
|
+
static lookup(name: string, options?: LookupOptions): Promise<App>;
|
|
193
|
+
createSandbox(image: Image, options?: SandboxCreateOptions): Promise<Sandbox>;
|
|
194
|
+
imageFromRegistry(tag: string): Promise<Image>;
|
|
195
|
+
imageFromAwsEcr(tag: string, secret: Secret): Promise<Image>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Options for `FunctionCall.get()`. */
|
|
199
|
+
type FunctionCallGetOptions = {
|
|
200
|
+
timeout?: number;
|
|
201
|
+
};
|
|
202
|
+
/** Options for `FunctionCall.cancel()`. */
|
|
203
|
+
type FunctionCallCancelOptions = {
|
|
204
|
+
terminateContainers?: boolean;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Represents a Modal FunctionCall. Function Calls are Function invocations with
|
|
208
|
+
* a given input. They can be consumed asynchronously (see `get()`) or cancelled
|
|
209
|
+
* (see `cancel()`).
|
|
210
|
+
*/
|
|
211
|
+
declare class FunctionCall {
|
|
212
|
+
readonly functionCallId: string;
|
|
213
|
+
/** @ignore */
|
|
214
|
+
constructor(functionCallId: string);
|
|
215
|
+
/** Create a new function call from ID. */
|
|
216
|
+
fromId(functionCallId: string): FunctionCall;
|
|
217
|
+
/** Get the result of a function call, optionally waiting with a timeout. */
|
|
218
|
+
get(options?: FunctionCallGetOptions): Promise<any>;
|
|
219
|
+
/** Cancel a running function call. */
|
|
220
|
+
cancel(options?: FunctionCallCancelOptions): Promise<void>;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Represents a deployed Modal Function, which can be invoked remotely. */
|
|
224
|
+
declare class Function_ {
|
|
225
|
+
#private;
|
|
226
|
+
readonly functionId: string;
|
|
227
|
+
readonly methodName: string | undefined;
|
|
228
|
+
/** @ignore */
|
|
229
|
+
constructor(functionId: string, methodName?: string);
|
|
230
|
+
static lookup(appName: string, name: string, options?: LookupOptions): Promise<Function_>;
|
|
231
|
+
remote(args?: any[], kwargs?: Record<string, any>): Promise<any>;
|
|
232
|
+
spawn(args?: any[], kwargs?: Record<string, any>): Promise<FunctionCall>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Represents a deployed Modal Cls. */
|
|
236
|
+
declare class Cls {
|
|
237
|
+
#private;
|
|
238
|
+
/** @ignore */
|
|
239
|
+
constructor(serviceFunctionId: string, schema: ClassParameterSpec[], methodNames: string[]);
|
|
240
|
+
static lookup(appName: string, name: string, options?: LookupOptions): Promise<Cls>;
|
|
241
|
+
/** Create a new instance of the Cls with parameters. */
|
|
242
|
+
instance(params?: Record<string, any>): Promise<ClsInstance>;
|
|
243
|
+
}
|
|
244
|
+
/** Represents an instance of a deployed Modal Cls, optionally with parameters. */
|
|
245
|
+
declare class ClsInstance {
|
|
246
|
+
#private;
|
|
247
|
+
constructor(methods: Map<string, Function_>);
|
|
248
|
+
method(name: string): Function_;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Function execution exceeds the allowed time limit. */
|
|
252
|
+
declare class FunctionTimeoutError extends Error {
|
|
253
|
+
constructor(message: string);
|
|
254
|
+
}
|
|
255
|
+
/** An error on the Modal server, or a Python exception. */
|
|
256
|
+
declare class RemoteError extends Error {
|
|
257
|
+
constructor(message: string);
|
|
258
|
+
}
|
|
259
|
+
/** A retryable internal error from Modal. */
|
|
260
|
+
declare class InternalFailure extends Error {
|
|
261
|
+
constructor(message: string);
|
|
262
|
+
}
|
|
263
|
+
/** Some resource was not found. */
|
|
264
|
+
declare class NotFoundError extends Error {
|
|
265
|
+
constructor(message: string);
|
|
266
|
+
}
|
|
267
|
+
/** A request or other operation was invalid. */
|
|
268
|
+
declare class InvalidError extends Error {
|
|
269
|
+
constructor(message: string);
|
|
270
|
+
}
|
|
271
|
+
/** The queue is empty. */
|
|
272
|
+
declare class QueueEmptyError extends Error {
|
|
273
|
+
constructor(message: string);
|
|
274
|
+
}
|
|
275
|
+
/** The queue is full. */
|
|
276
|
+
declare class QueueFullError extends Error {
|
|
277
|
+
constructor(message: string);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Options to configure a `Queue.clear()` operation. */
|
|
281
|
+
type QueueClearOptions = {
|
|
282
|
+
/** Partition to clear, uses default partition if not set. */
|
|
283
|
+
partition?: string;
|
|
284
|
+
/** Set to clear all queue partitions. */
|
|
285
|
+
all?: boolean;
|
|
286
|
+
};
|
|
287
|
+
/** Options to configure a `Queue.get()` or `Queue.getMany()` operation. */
|
|
288
|
+
type QueueGetOptions = {
|
|
289
|
+
/** How long to wait if the queue is empty (default: indefinite). */
|
|
290
|
+
timeout?: number;
|
|
291
|
+
/** Partition to fetch values from, uses default partition if not set. */
|
|
292
|
+
partition?: string;
|
|
293
|
+
};
|
|
294
|
+
/** Options to configure a `Queue.put()` or `Queue.putMany()` operation. */
|
|
295
|
+
type QueuePutOptions = {
|
|
296
|
+
/** How long to wait if the queue is full (default: indefinite). */
|
|
297
|
+
timeout?: number;
|
|
298
|
+
/** Partition to add items to, uses default partition if not set. */
|
|
299
|
+
partition?: string;
|
|
300
|
+
/** TTL for the partition in seconds (default: 1 day). */
|
|
301
|
+
partitionTtl?: number;
|
|
302
|
+
};
|
|
303
|
+
/** Options to configure a `Queue.len()` operation. */
|
|
304
|
+
type QueueLenOptions = {
|
|
305
|
+
/** Partition to compute length, uses default partition if not set. */
|
|
306
|
+
partition?: string;
|
|
307
|
+
/** Return the total length across all partitions. */
|
|
308
|
+
total?: boolean;
|
|
309
|
+
};
|
|
310
|
+
/** Options to configure a `Queue.iterate()` operation. */
|
|
311
|
+
type QueueIterateOptions = {
|
|
312
|
+
/** How long to wait between successive items before exiting iteration (default: 0). */
|
|
313
|
+
itemPollTimeout?: number;
|
|
314
|
+
/** Partition to iterate, uses default partition if not set. */
|
|
315
|
+
partition?: string;
|
|
316
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* Distributed, FIFO queue for data flow in Modal apps.
|
|
319
|
+
*/
|
|
320
|
+
declare class Queue {
|
|
321
|
+
#private;
|
|
322
|
+
readonly queueId: string;
|
|
323
|
+
/** @ignore */
|
|
324
|
+
constructor(queueId: string, ephemeral?: boolean);
|
|
325
|
+
/**
|
|
326
|
+
* Create a nameless, temporary queue.
|
|
327
|
+
* You will need to call `closeEphemeral()` to delete the queue.
|
|
328
|
+
*/
|
|
329
|
+
static ephemeral(options?: EphemeralOptions): Promise<Queue>;
|
|
330
|
+
/** Delete the ephemeral queue. Only usable with `Queue.ephemeral()`. */
|
|
331
|
+
closeEphemeral(): void;
|
|
332
|
+
/**
|
|
333
|
+
* Lookup a queue by name.
|
|
334
|
+
*/
|
|
335
|
+
static lookup(name: string, options?: LookupOptions): Promise<Queue>;
|
|
336
|
+
/** Delete a queue by name. */
|
|
337
|
+
static delete(name: string, options?: DeleteOptions): Promise<void>;
|
|
338
|
+
/**
|
|
339
|
+
* Remove all objects from a queue partition.
|
|
340
|
+
*/
|
|
341
|
+
clear(options?: QueueClearOptions): Promise<void>;
|
|
342
|
+
/**
|
|
343
|
+
* Remove and return the next object from the queue.
|
|
344
|
+
*
|
|
345
|
+
* By default, this will wait until at least one item is present in the queue.
|
|
346
|
+
* If `timeout` is set, raises `QueueEmptyError` if no items are available
|
|
347
|
+
* within that timeout in milliseconds.
|
|
348
|
+
*/
|
|
349
|
+
get(options?: QueueGetOptions): Promise<any | null>;
|
|
350
|
+
/**
|
|
351
|
+
* Remove and return up to `n` objects from the queue.
|
|
352
|
+
*
|
|
353
|
+
* By default, this will wait until at least one item is present in the queue.
|
|
354
|
+
* If `timeout` is set, raises `QueueEmptyError` if no items are available
|
|
355
|
+
* within that timeout in milliseconds.
|
|
356
|
+
*/
|
|
357
|
+
getMany(n: number, options?: QueueGetOptions): Promise<any[]>;
|
|
358
|
+
/**
|
|
359
|
+
* Add an item to the end of the queue.
|
|
360
|
+
*
|
|
361
|
+
* If the queue is full, this will retry with exponential backoff until the
|
|
362
|
+
* provided `timeout` is reached, or indefinitely if `timeout` is not set.
|
|
363
|
+
* Raises `QueueFullError` if the queue is still full after the timeout.
|
|
364
|
+
*/
|
|
365
|
+
put(v: any, options?: QueuePutOptions): Promise<void>;
|
|
366
|
+
/**
|
|
367
|
+
* Add several items to the end of the queue.
|
|
368
|
+
*
|
|
369
|
+
* If the queue is full, this will retry with exponential backoff until the
|
|
370
|
+
* provided `timeout` is reached, or indefinitely if `timeout` is not set.
|
|
371
|
+
* Raises `QueueFullError` if the queue is still full after the timeout.
|
|
372
|
+
*/
|
|
373
|
+
putMany(values: any[], options?: QueuePutOptions): Promise<void>;
|
|
374
|
+
/** Return the number of objects in the queue. */
|
|
375
|
+
len(options?: QueueLenOptions): Promise<number>;
|
|
376
|
+
/** Iterate through items in a queue without mutation. */
|
|
377
|
+
iterate(options?: QueueIterateOptions): AsyncGenerator<any, void, unknown>;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
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, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode };
|