modal 0.3.12 → 0.3.13

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/dist/index.cjs CHANGED
@@ -48,6 +48,7 @@ __export(index_exports, {
48
48
  Sandbox: () => Sandbox2,
49
49
  SandboxFile: () => SandboxFile,
50
50
  Secret: () => Secret,
51
+ Volume: () => Volume,
51
52
  initializeClient: () => initializeClient
52
53
  });
53
54
  module.exports = __toCommonJS(index_exports);
@@ -38079,7 +38080,6 @@ async function fromRegistryInternal(appId, tag, imageRegistryConfig) {
38079
38080
  dockerfileCommands: [`FROM ${tag}`],
38080
38081
  imageRegistryConfig
38081
38082
  },
38082
- namespace: 1 /* DEPLOYMENT_NAMESPACE_WORKSPACE */,
38083
38083
  builderVersion: imageBuilderVersion()
38084
38084
  });
38085
38085
  let result;
@@ -38638,7 +38638,6 @@ var Secret = class _Secret {
38638
38638
  try {
38639
38639
  const resp = await client.secretGetOrCreate({
38640
38640
  deploymentName: name,
38641
- namespace: 1 /* DEPLOYMENT_NAMESPACE_WORKSPACE */,
38642
38641
  environmentName: environmentName(options?.environment),
38643
38642
  requiredKeys: options?.requiredKeys ?? []
38644
38643
  });
@@ -38681,6 +38680,12 @@ var App = class _App {
38681
38680
  `Timeout must be a multiple of 1000ms, got ${options.timeout}`
38682
38681
  );
38683
38682
  }
38683
+ const volumeMounts = options.volumes ? Object.entries(options.volumes).map(([mountPath, volume]) => ({
38684
+ volumeId: volume.volumeId,
38685
+ mountPath,
38686
+ allowBackgroundCommits: true,
38687
+ readOnly: false
38688
+ })) : [];
38684
38689
  const createResp = await client.sandboxCreate({
38685
38690
  appId: this.appId,
38686
38691
  definition: {
@@ -38695,7 +38700,8 @@ var App = class _App {
38695
38700
  // https://modal.com/docs/guide/resources
38696
38701
  milliCpu: Math.round(1e3 * (options.cpu ?? 0.125)),
38697
38702
  memoryMb: options.memory ?? 128
38698
- }
38703
+ },
38704
+ volumeMounts
38699
38705
  }
38700
38706
  });
38701
38707
  return new Sandbox2(createResp.sandboxId);
@@ -39176,7 +39182,9 @@ var InputPlaneInvocation = class _InputPlaneInvocation {
39176
39182
  static async create(inputPlaneUrl, functionId, input) {
39177
39183
  const functionPutInputsItem = {
39178
39184
  idx: 0,
39179
- input
39185
+ input,
39186
+ r2Failed: false,
39187
+ r2LatencyMs: 0
39180
39188
  };
39181
39189
  const client2 = getOrCreateInputPlaneClient(inputPlaneUrl);
39182
39190
  const attemptStartResponse = await client2.attemptStart({
@@ -39331,7 +39339,6 @@ var Function_ = class _Function_ {
39331
39339
  const resp = await client.functionGet({
39332
39340
  appName,
39333
39341
  objectTag: name,
39334
- namespace: 1 /* DEPLOYMENT_NAMESPACE_WORKSPACE */,
39335
39342
  environmentName: environmentName(options.environment)
39336
39343
  });
39337
39344
  return new _Function_(
@@ -39438,11 +39445,13 @@ var Cls = class _Cls {
39438
39445
  #serviceFunctionId;
39439
39446
  #schema;
39440
39447
  #methodNames;
39448
+ #inputPlaneUrl;
39441
39449
  /** @ignore */
39442
- constructor(serviceFunctionId, schema, methodNames) {
39450
+ constructor(serviceFunctionId, schema, methodNames, inputPlaneUrl) {
39443
39451
  this.#serviceFunctionId = serviceFunctionId;
39444
39452
  this.#schema = schema;
39445
39453
  this.#methodNames = methodNames;
39454
+ this.#inputPlaneUrl = inputPlaneUrl;
39446
39455
  }
39447
39456
  static async lookup(appName, name, options = {}) {
39448
39457
  try {
@@ -39450,7 +39459,6 @@ var Cls = class _Cls {
39450
39459
  const serviceFunction = await client.functionGet({
39451
39460
  appName,
39452
39461
  objectTag: serviceFunctionName,
39453
- namespace: 1 /* DEPLOYMENT_NAMESPACE_WORKSPACE */,
39454
39462
  environmentName: environmentName(options.environment)
39455
39463
  });
39456
39464
  const parameterInfo = serviceFunction.handleMetadata?.classParameterInfo;
@@ -39470,7 +39478,12 @@ var Cls = class _Cls {
39470
39478
  "Cls requires Modal deployments using client v0.67 or later."
39471
39479
  );
39472
39480
  }
39473
- return new _Cls(serviceFunction.functionId, schema, methodNames);
39481
+ return new _Cls(
39482
+ serviceFunction.functionId,
39483
+ schema,
39484
+ methodNames,
39485
+ serviceFunction.handleMetadata?.inputPlaneUrl
39486
+ );
39474
39487
  } catch (err) {
39475
39488
  if (err instanceof import_nice_grpc5.ClientError && err.code === import_nice_grpc5.Status.NOT_FOUND)
39476
39489
  throw new NotFoundError(`Class '${appName}/${name}' not found`);
@@ -39487,7 +39500,7 @@ var Cls = class _Cls {
39487
39500
  }
39488
39501
  const methods = /* @__PURE__ */ new Map();
39489
39502
  for (const name of this.#methodNames) {
39490
- methods.set(name, new Function_(functionId, name));
39503
+ methods.set(name, new Function_(functionId, name, this.#inputPlaneUrl));
39491
39504
  }
39492
39505
  return new ClsInstance(methods);
39493
39506
  }
@@ -39638,7 +39651,6 @@ var Queue = class _Queue {
39638
39651
  const resp = await client.queueGetOrCreate({
39639
39652
  deploymentName: name,
39640
39653
  objectCreationType: options.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : void 0,
39641
- namespace: 1 /* DEPLOYMENT_NAMESPACE_WORKSPACE */,
39642
39654
  environmentName: environmentName(options.environment)
39643
39655
  });
39644
39656
  return new _Queue(resp.queueId);
@@ -39816,6 +39828,30 @@ var Queue = class _Queue {
39816
39828
  }
39817
39829
  }
39818
39830
  };
39831
+
39832
+ // src/volume.ts
39833
+ var import_nice_grpc7 = require("nice-grpc");
39834
+ var Volume = class _Volume {
39835
+ volumeId;
39836
+ /** @ignore */
39837
+ constructor(volumeId) {
39838
+ this.volumeId = volumeId;
39839
+ }
39840
+ static async fromName(name, options) {
39841
+ try {
39842
+ const resp = await client.volumeGetOrCreate({
39843
+ deploymentName: name,
39844
+ environmentName: environmentName(options?.environment),
39845
+ objectCreationType: options?.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : 0 /* OBJECT_CREATION_TYPE_UNSPECIFIED */
39846
+ });
39847
+ return new _Volume(resp.volumeId);
39848
+ } catch (err) {
39849
+ if (err instanceof import_nice_grpc7.ClientError && err.code === import_nice_grpc7.Status.NOT_FOUND)
39850
+ throw new NotFoundError(err.details);
39851
+ throw err;
39852
+ }
39853
+ }
39854
+ };
39819
39855
  // Annotate the CommonJS export names for ESM import in node:
39820
39856
  0 && (module.exports = {
39821
39857
  App,
@@ -39836,5 +39872,6 @@ var Queue = class _Queue {
39836
39872
  Sandbox,
39837
39873
  SandboxFile,
39838
39874
  Secret,
39875
+ Volume,
39839
39876
  initializeClient
39840
39877
  });
package/dist/index.d.cts CHANGED
@@ -200,6 +200,19 @@ declare class Secret {
200
200
  static fromName(name: string, options?: SecretFromNameOptions): Promise<Secret>;
201
201
  }
202
202
 
203
+ /** Options for `Volume.fromName()`. */
204
+ type VolumeFromNameOptions = {
205
+ environment?: string;
206
+ createIfMissing?: boolean;
207
+ };
208
+ /** Volumes provide persistent storage that can be mounted in Modal functions. */
209
+ declare class Volume {
210
+ readonly volumeId: string;
211
+ /** @ignore */
212
+ constructor(volumeId: string);
213
+ static fromName(name: string, options?: VolumeFromNameOptions): Promise<Volume>;
214
+ }
215
+
203
216
  /** Options for functions that find deployed Modal objects. */
204
217
  type LookupOptions = {
205
218
  environment?: string;
@@ -226,6 +239,8 @@ type SandboxCreateOptions = {
226
239
  * Default behavior is to sleep indefinitely until timeout or termination.
227
240
  */
228
241
  command?: string[];
242
+ /** Mount points for Modal Volumes. */
243
+ volumes?: Record<string, Volume>;
229
244
  };
230
245
  /** Represents a deployed Modal App. */
231
246
  declare class App {
@@ -296,7 +311,7 @@ declare class Function_ {
296
311
  declare class Cls {
297
312
  #private;
298
313
  /** @ignore */
299
- constructor(serviceFunctionId: string, schema: ClassParameterSpec[], methodNames: string[]);
314
+ constructor(serviceFunctionId: string, schema: ClassParameterSpec[], methodNames: string[], inputPlaneUrl?: string);
300
315
  static lookup(appName: string, name: string, options?: LookupOptions): Promise<Cls>;
301
316
  /** Create a new instance of the Cls with parameters. */
302
317
  instance(params?: Record<string, any>): Promise<ClsInstance>;
@@ -437,4 +452,4 @@ declare class Queue {
437
452
  iterate(options?: QueueIterateOptions): AsyncGenerator<any, void, unknown>;
438
453
  }
439
454
 
440
- export { App, type ClientOptions, 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, SandboxFile, type SandboxFileMode, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode, initializeClient };
455
+ export { App, type ClientOptions, 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, SandboxFile, type SandboxFileMode, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode, Volume, type VolumeFromNameOptions, initializeClient };
package/dist/index.d.ts CHANGED
@@ -200,6 +200,19 @@ declare class Secret {
200
200
  static fromName(name: string, options?: SecretFromNameOptions): Promise<Secret>;
201
201
  }
202
202
 
203
+ /** Options for `Volume.fromName()`. */
204
+ type VolumeFromNameOptions = {
205
+ environment?: string;
206
+ createIfMissing?: boolean;
207
+ };
208
+ /** Volumes provide persistent storage that can be mounted in Modal functions. */
209
+ declare class Volume {
210
+ readonly volumeId: string;
211
+ /** @ignore */
212
+ constructor(volumeId: string);
213
+ static fromName(name: string, options?: VolumeFromNameOptions): Promise<Volume>;
214
+ }
215
+
203
216
  /** Options for functions that find deployed Modal objects. */
204
217
  type LookupOptions = {
205
218
  environment?: string;
@@ -226,6 +239,8 @@ type SandboxCreateOptions = {
226
239
  * Default behavior is to sleep indefinitely until timeout or termination.
227
240
  */
228
241
  command?: string[];
242
+ /** Mount points for Modal Volumes. */
243
+ volumes?: Record<string, Volume>;
229
244
  };
230
245
  /** Represents a deployed Modal App. */
231
246
  declare class App {
@@ -296,7 +311,7 @@ declare class Function_ {
296
311
  declare class Cls {
297
312
  #private;
298
313
  /** @ignore */
299
- constructor(serviceFunctionId: string, schema: ClassParameterSpec[], methodNames: string[]);
314
+ constructor(serviceFunctionId: string, schema: ClassParameterSpec[], methodNames: string[], inputPlaneUrl?: string);
300
315
  static lookup(appName: string, name: string, options?: LookupOptions): Promise<Cls>;
301
316
  /** Create a new instance of the Cls with parameters. */
302
317
  instance(params?: Record<string, any>): Promise<ClsInstance>;
@@ -437,4 +452,4 @@ declare class Queue {
437
452
  iterate(options?: QueueIterateOptions): AsyncGenerator<any, void, unknown>;
438
453
  }
439
454
 
440
- export { App, type ClientOptions, 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, SandboxFile, type SandboxFileMode, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode, initializeClient };
455
+ export { App, type ClientOptions, 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, SandboxFile, type SandboxFileMode, Secret, type SecretFromNameOptions, type StdioBehavior, type StreamMode, Volume, type VolumeFromNameOptions, initializeClient };
package/dist/index.js CHANGED
@@ -38031,7 +38031,6 @@ async function fromRegistryInternal(appId, tag, imageRegistryConfig) {
38031
38031
  dockerfileCommands: [`FROM ${tag}`],
38032
38032
  imageRegistryConfig
38033
38033
  },
38034
- namespace: 1 /* DEPLOYMENT_NAMESPACE_WORKSPACE */,
38035
38034
  builderVersion: imageBuilderVersion()
38036
38035
  });
38037
38036
  let result;
@@ -38590,7 +38589,6 @@ var Secret = class _Secret {
38590
38589
  try {
38591
38590
  const resp = await client.secretGetOrCreate({
38592
38591
  deploymentName: name,
38593
- namespace: 1 /* DEPLOYMENT_NAMESPACE_WORKSPACE */,
38594
38592
  environmentName: environmentName(options?.environment),
38595
38593
  requiredKeys: options?.requiredKeys ?? []
38596
38594
  });
@@ -38633,6 +38631,12 @@ var App = class _App {
38633
38631
  `Timeout must be a multiple of 1000ms, got ${options.timeout}`
38634
38632
  );
38635
38633
  }
38634
+ const volumeMounts = options.volumes ? Object.entries(options.volumes).map(([mountPath, volume]) => ({
38635
+ volumeId: volume.volumeId,
38636
+ mountPath,
38637
+ allowBackgroundCommits: true,
38638
+ readOnly: false
38639
+ })) : [];
38636
38640
  const createResp = await client.sandboxCreate({
38637
38641
  appId: this.appId,
38638
38642
  definition: {
@@ -38647,7 +38651,8 @@ var App = class _App {
38647
38651
  // https://modal.com/docs/guide/resources
38648
38652
  milliCpu: Math.round(1e3 * (options.cpu ?? 0.125)),
38649
38653
  memoryMb: options.memory ?? 128
38650
- }
38654
+ },
38655
+ volumeMounts
38651
38656
  }
38652
38657
  });
38653
38658
  return new Sandbox2(createResp.sandboxId);
@@ -39128,7 +39133,9 @@ var InputPlaneInvocation = class _InputPlaneInvocation {
39128
39133
  static async create(inputPlaneUrl, functionId, input) {
39129
39134
  const functionPutInputsItem = {
39130
39135
  idx: 0,
39131
- input
39136
+ input,
39137
+ r2Failed: false,
39138
+ r2LatencyMs: 0
39132
39139
  };
39133
39140
  const client2 = getOrCreateInputPlaneClient(inputPlaneUrl);
39134
39141
  const attemptStartResponse = await client2.attemptStart({
@@ -39283,7 +39290,6 @@ var Function_ = class _Function_ {
39283
39290
  const resp = await client.functionGet({
39284
39291
  appName,
39285
39292
  objectTag: name,
39286
- namespace: 1 /* DEPLOYMENT_NAMESPACE_WORKSPACE */,
39287
39293
  environmentName: environmentName(options.environment)
39288
39294
  });
39289
39295
  return new _Function_(
@@ -39390,11 +39396,13 @@ var Cls = class _Cls {
39390
39396
  #serviceFunctionId;
39391
39397
  #schema;
39392
39398
  #methodNames;
39399
+ #inputPlaneUrl;
39393
39400
  /** @ignore */
39394
- constructor(serviceFunctionId, schema, methodNames) {
39401
+ constructor(serviceFunctionId, schema, methodNames, inputPlaneUrl) {
39395
39402
  this.#serviceFunctionId = serviceFunctionId;
39396
39403
  this.#schema = schema;
39397
39404
  this.#methodNames = methodNames;
39405
+ this.#inputPlaneUrl = inputPlaneUrl;
39398
39406
  }
39399
39407
  static async lookup(appName, name, options = {}) {
39400
39408
  try {
@@ -39402,7 +39410,6 @@ var Cls = class _Cls {
39402
39410
  const serviceFunction = await client.functionGet({
39403
39411
  appName,
39404
39412
  objectTag: serviceFunctionName,
39405
- namespace: 1 /* DEPLOYMENT_NAMESPACE_WORKSPACE */,
39406
39413
  environmentName: environmentName(options.environment)
39407
39414
  });
39408
39415
  const parameterInfo = serviceFunction.handleMetadata?.classParameterInfo;
@@ -39422,7 +39429,12 @@ var Cls = class _Cls {
39422
39429
  "Cls requires Modal deployments using client v0.67 or later."
39423
39430
  );
39424
39431
  }
39425
- return new _Cls(serviceFunction.functionId, schema, methodNames);
39432
+ return new _Cls(
39433
+ serviceFunction.functionId,
39434
+ schema,
39435
+ methodNames,
39436
+ serviceFunction.handleMetadata?.inputPlaneUrl
39437
+ );
39426
39438
  } catch (err) {
39427
39439
  if (err instanceof ClientError5 && err.code === Status5.NOT_FOUND)
39428
39440
  throw new NotFoundError(`Class '${appName}/${name}' not found`);
@@ -39439,7 +39451,7 @@ var Cls = class _Cls {
39439
39451
  }
39440
39452
  const methods = /* @__PURE__ */ new Map();
39441
39453
  for (const name of this.#methodNames) {
39442
- methods.set(name, new Function_(functionId, name));
39454
+ methods.set(name, new Function_(functionId, name, this.#inputPlaneUrl));
39443
39455
  }
39444
39456
  return new ClsInstance(methods);
39445
39457
  }
@@ -39590,7 +39602,6 @@ var Queue = class _Queue {
39590
39602
  const resp = await client.queueGetOrCreate({
39591
39603
  deploymentName: name,
39592
39604
  objectCreationType: options.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : void 0,
39593
- namespace: 1 /* DEPLOYMENT_NAMESPACE_WORKSPACE */,
39594
39605
  environmentName: environmentName(options.environment)
39595
39606
  });
39596
39607
  return new _Queue(resp.queueId);
@@ -39768,6 +39779,30 @@ var Queue = class _Queue {
39768
39779
  }
39769
39780
  }
39770
39781
  };
39782
+
39783
+ // src/volume.ts
39784
+ import { ClientError as ClientError7, Status as Status7 } from "nice-grpc";
39785
+ var Volume = class _Volume {
39786
+ volumeId;
39787
+ /** @ignore */
39788
+ constructor(volumeId) {
39789
+ this.volumeId = volumeId;
39790
+ }
39791
+ static async fromName(name, options) {
39792
+ try {
39793
+ const resp = await client.volumeGetOrCreate({
39794
+ deploymentName: name,
39795
+ environmentName: environmentName(options?.environment),
39796
+ objectCreationType: options?.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : 0 /* OBJECT_CREATION_TYPE_UNSPECIFIED */
39797
+ });
39798
+ return new _Volume(resp.volumeId);
39799
+ } catch (err) {
39800
+ if (err instanceof ClientError7 && err.code === Status7.NOT_FOUND)
39801
+ throw new NotFoundError(err.details);
39802
+ throw err;
39803
+ }
39804
+ }
39805
+ };
39771
39806
  export {
39772
39807
  App,
39773
39808
  Cls,
@@ -39787,5 +39822,6 @@ export {
39787
39822
  Sandbox2 as Sandbox,
39788
39823
  SandboxFile,
39789
39824
  Secret,
39825
+ Volume,
39790
39826
  initializeClient
39791
39827
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modal",
3
- "version": "0.3.12",
3
+ "version": "0.3.13",
4
4
  "description": "Modal client library for JavaScript",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://modal.com/docs",