modal 0.11.1-dev.14 → 0.11.1-dev.16

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
@@ -51,6 +51,7 @@ __export(index_exports, {
51
51
  FunctionCallLogsManager: () => FunctionCallLogsManager,
52
52
  FunctionCallService: () => FunctionCallService,
53
53
  FunctionLogsManager: () => FunctionLogsManager,
54
+ FunctionMetricsManager: () => FunctionMetricsManager,
54
55
  FunctionService: () => FunctionService,
55
56
  FunctionTimeoutError: () => FunctionTimeoutError,
56
57
  Function_: () => Function_,
@@ -36229,7 +36230,7 @@ var ImageListTagsItem = {
36229
36230
  }
36230
36231
  };
36231
36232
  function createBaseImageListTagsRequest() {
36232
- return { environmentName: "", tagPrefix: "", maxObjects: 0, pageToken: "" };
36233
+ return { environmentName: "", tagPrefix: "", maxObjects: 0, pageToken: "", imageId: "" };
36233
36234
  }
36234
36235
  var ImageListTagsRequest = {
36235
36236
  encode(message, writer = new BinaryWriter()) {
@@ -36245,6 +36246,9 @@ var ImageListTagsRequest = {
36245
36246
  if (message.pageToken !== "") {
36246
36247
  writer.uint32(34).string(message.pageToken);
36247
36248
  }
36249
+ if (message.imageId !== "") {
36250
+ writer.uint32(42).string(message.imageId);
36251
+ }
36248
36252
  return writer;
36249
36253
  },
36250
36254
  decode(input, length) {
@@ -36282,6 +36286,13 @@ var ImageListTagsRequest = {
36282
36286
  message.pageToken = reader.string();
36283
36287
  continue;
36284
36288
  }
36289
+ case 5: {
36290
+ if (tag !== 42) {
36291
+ break;
36292
+ }
36293
+ message.imageId = reader.string();
36294
+ continue;
36295
+ }
36285
36296
  }
36286
36297
  if ((tag & 7) === 4 || tag === 0) {
36287
36298
  break;
@@ -36295,7 +36306,8 @@ var ImageListTagsRequest = {
36295
36306
  environmentName: isSet5(object.environmentName) ? globalThis.String(object.environmentName) : "",
36296
36307
  tagPrefix: isSet5(object.tagPrefix) ? globalThis.String(object.tagPrefix) : "",
36297
36308
  maxObjects: isSet5(object.maxObjects) ? globalThis.Number(object.maxObjects) : 0,
36298
- pageToken: isSet5(object.pageToken) ? globalThis.String(object.pageToken) : ""
36309
+ pageToken: isSet5(object.pageToken) ? globalThis.String(object.pageToken) : "",
36310
+ imageId: isSet5(object.imageId) ? globalThis.String(object.imageId) : ""
36299
36311
  };
36300
36312
  },
36301
36313
  toJSON(message) {
@@ -36312,6 +36324,9 @@ var ImageListTagsRequest = {
36312
36324
  if (message.pageToken !== "") {
36313
36325
  obj.pageToken = message.pageToken;
36314
36326
  }
36327
+ if (message.imageId !== "") {
36328
+ obj.imageId = message.imageId;
36329
+ }
36315
36330
  return obj;
36316
36331
  },
36317
36332
  create(base) {
@@ -36323,6 +36338,7 @@ var ImageListTagsRequest = {
36323
36338
  message.tagPrefix = object.tagPrefix ?? "";
36324
36339
  message.maxObjects = object.maxObjects ?? 0;
36325
36340
  message.pageToken = object.pageToken ?? "";
36341
+ message.imageId = object.imageId ?? "";
36326
36342
  return message;
36327
36343
  }
36328
36344
  };
@@ -36616,6 +36632,57 @@ var ImageMetadata_PythonPackagesEntry = {
36616
36632
  return message;
36617
36633
  }
36618
36634
  };
36635
+ function createBaseImageNameDeleteRequest() {
36636
+ return { tag: "" };
36637
+ }
36638
+ var ImageNameDeleteRequest = {
36639
+ encode(message, writer = new BinaryWriter()) {
36640
+ if (message.tag !== "") {
36641
+ writer.uint32(10).string(message.tag);
36642
+ }
36643
+ return writer;
36644
+ },
36645
+ decode(input, length) {
36646
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
36647
+ let end = length === void 0 ? reader.len : reader.pos + length;
36648
+ const message = createBaseImageNameDeleteRequest();
36649
+ while (reader.pos < end) {
36650
+ const tag = reader.uint32();
36651
+ switch (tag >>> 3) {
36652
+ case 1: {
36653
+ if (tag !== 10) {
36654
+ break;
36655
+ }
36656
+ message.tag = reader.string();
36657
+ continue;
36658
+ }
36659
+ }
36660
+ if ((tag & 7) === 4 || tag === 0) {
36661
+ break;
36662
+ }
36663
+ reader.skip(tag & 7);
36664
+ }
36665
+ return message;
36666
+ },
36667
+ fromJSON(object) {
36668
+ return { tag: isSet5(object.tag) ? globalThis.String(object.tag) : "" };
36669
+ },
36670
+ toJSON(message) {
36671
+ const obj = {};
36672
+ if (message.tag !== "") {
36673
+ obj.tag = message.tag;
36674
+ }
36675
+ return obj;
36676
+ },
36677
+ create(base) {
36678
+ return ImageNameDeleteRequest.fromPartial(base ?? {});
36679
+ },
36680
+ fromPartial(object) {
36681
+ const message = createBaseImageNameDeleteRequest();
36682
+ message.tag = object.tag ?? "";
36683
+ return message;
36684
+ }
36685
+ };
36619
36686
  function createBaseImagePublishRequest() {
36620
36687
  return { imageId: "", tag: "", environmentName: "", allowPublic: false };
36621
36688
  }
@@ -66434,6 +66501,14 @@ var ModalClientDefinition = {
66434
66501
  responseStream: false,
66435
66502
  options: {}
66436
66503
  },
66504
+ imageNameDelete: {
66505
+ name: "ImageNameDelete",
66506
+ requestType: ImageNameDeleteRequest,
66507
+ requestStream: false,
66508
+ responseType: Empty,
66509
+ responseStream: false,
66510
+ options: {}
66511
+ },
66437
66512
  imagePublish: {
66438
66513
  name: "ImagePublish",
66439
66514
  requestType: ImagePublishRequest,
@@ -67635,11 +67710,40 @@ var TimeoutError = class extends Error {
67635
67710
  this.name = "TimeoutError";
67636
67711
  }
67637
67712
  };
67638
- var FunctionTimeoutError = class extends Error {
67713
+ var FunctionTimeoutError = class _FunctionTimeoutError extends Error {
67639
67714
  constructor(message) {
67640
67715
  super(message);
67641
67716
  this.name = "FunctionTimeoutError";
67642
67717
  }
67718
+ // Backward compatibility: FunctionCall.get() wait timeouts still match
67719
+ // FunctionTimeoutError, with a deprecation warning.
67720
+ static [Symbol.hasInstance](instance) {
67721
+ if (Function.prototype[Symbol.hasInstance].call(this, instance)) {
67722
+ return true;
67723
+ }
67724
+ if (this === _FunctionTimeoutError && instance instanceof FunctionCallGetTimeoutError) {
67725
+ instance.warnFunctionTimeoutErrorMatch();
67726
+ return true;
67727
+ }
67728
+ return false;
67729
+ }
67730
+ };
67731
+ var warnedFunctionTimeoutErrorMatch = false;
67732
+ var FunctionCallGetTimeoutError = class extends TimeoutError {
67733
+ #logger;
67734
+ constructor(message, logger2) {
67735
+ super(message);
67736
+ this.#logger = logger2;
67737
+ }
67738
+ warnFunctionTimeoutErrorMatch() {
67739
+ if (warnedFunctionTimeoutErrorMatch) {
67740
+ return;
67741
+ }
67742
+ warnedFunctionTimeoutErrorMatch = true;
67743
+ this.#logger.warn(
67744
+ "Matching a FunctionCall.get() timeout with `instanceof FunctionTimeoutError` is deprecated and will stop working in a future release; check `instanceof TimeoutError` first instead."
67745
+ );
67746
+ }
67643
67747
  };
67644
67748
  var RemoteError = class extends Error {
67645
67749
  constructor(message) {
@@ -68219,12 +68323,14 @@ async function blobDownload(cpClient, blobId) {
68219
68323
  var outputsTimeoutMs = 55 * 1e3;
68220
68324
  var ControlPlaneInvocation = class _ControlPlaneInvocation {
68221
68325
  cpClient;
68326
+ logger;
68222
68327
  functionCallId;
68223
68328
  input;
68224
68329
  functionCallJwt;
68225
68330
  inputJwt;
68226
- constructor(cpClient, functionCallId, input, functionCallJwt, inputJwt) {
68331
+ constructor(cpClient, logger2, functionCallId, input, functionCallJwt, inputJwt) {
68227
68332
  this.cpClient = cpClient;
68333
+ this.logger = logger2;
68228
68334
  this.functionCallId = functionCallId;
68229
68335
  this.input = input;
68230
68336
  this.functionCallJwt = functionCallJwt;
@@ -68243,6 +68349,7 @@ var ControlPlaneInvocation = class _ControlPlaneInvocation {
68243
68349
  });
68244
68350
  return new _ControlPlaneInvocation(
68245
68351
  client.cpClient,
68352
+ client.logger,
68246
68353
  functionMapResponse.functionCallId,
68247
68354
  input,
68248
68355
  functionMapResponse.functionCallJwt,
@@ -68250,11 +68357,16 @@ var ControlPlaneInvocation = class _ControlPlaneInvocation {
68250
68357
  );
68251
68358
  }
68252
68359
  static fromFunctionCallId(client, functionCallId) {
68253
- return new _ControlPlaneInvocation(client.cpClient, functionCallId);
68360
+ return new _ControlPlaneInvocation(
68361
+ client.cpClient,
68362
+ client.logger,
68363
+ functionCallId
68364
+ );
68254
68365
  }
68255
68366
  async awaitOutput(timeoutMs, clearOnSuccess = false) {
68256
68367
  return await pollFunctionOutput(
68257
68368
  this.cpClient,
68369
+ this.logger,
68258
68370
  (timeoutMs2) => this.#getOutput(
68259
68371
  timeoutMs2,
68260
68372
  clearOnSuccess,
@@ -68294,12 +68406,14 @@ var ControlPlaneInvocation = class _ControlPlaneInvocation {
68294
68406
  var InputPlaneInvocation = class _InputPlaneInvocation {
68295
68407
  cpClient;
68296
68408
  ipClient;
68409
+ logger;
68297
68410
  functionId;
68298
68411
  input;
68299
68412
  attemptToken;
68300
- constructor(cpClient, ipClient, functionId, input, attemptToken) {
68413
+ constructor(cpClient, ipClient, logger2, functionId, input, attemptToken) {
68301
68414
  this.cpClient = cpClient;
68302
68415
  this.ipClient = ipClient;
68416
+ this.logger = logger2;
68303
68417
  this.functionId = functionId;
68304
68418
  this.input = input;
68305
68419
  this.attemptToken = attemptToken;
@@ -68317,6 +68431,7 @@ var InputPlaneInvocation = class _InputPlaneInvocation {
68317
68431
  return new _InputPlaneInvocation(
68318
68432
  client.cpClient,
68319
68433
  ipClient,
68434
+ client.logger,
68320
68435
  functionId,
68321
68436
  functionPutInputsItem,
68322
68437
  attemptStartResponse.attemptToken
@@ -68325,6 +68440,7 @@ var InputPlaneInvocation = class _InputPlaneInvocation {
68325
68440
  async awaitOutput(timeoutMs) {
68326
68441
  return await pollFunctionOutput(
68327
68442
  this.cpClient,
68443
+ this.logger,
68328
68444
  (timeoutMs2) => this.#getOutput(timeoutMs2),
68329
68445
  timeoutMs
68330
68446
  );
@@ -68349,7 +68465,7 @@ var InputPlaneInvocation = class _InputPlaneInvocation {
68349
68465
  function timeNowSeconds() {
68350
68466
  return Date.now() / 1e3;
68351
68467
  }
68352
- async function pollFunctionOutput(cpClient, getOutput, timeoutMs) {
68468
+ async function pollFunctionOutput(cpClient, logger2, getOutput, timeoutMs) {
68353
68469
  const startTime = Date.now();
68354
68470
  let pollTimeoutMs = outputsTimeoutMs;
68355
68471
  if (timeoutMs !== void 0) {
@@ -68364,7 +68480,7 @@ async function pollFunctionOutput(cpClient, getOutput, timeoutMs) {
68364
68480
  const remainingMs = timeoutMs - (Date.now() - startTime);
68365
68481
  if (remainingMs <= 0) {
68366
68482
  const message = `Timeout exceeded: ${timeoutMs}ms`;
68367
- throw new FunctionTimeoutError(message);
68483
+ throw new FunctionCallGetTimeoutError(message, logger2);
68368
68484
  }
68369
68485
  pollTimeoutMs = Math.min(outputsTimeoutMs, remainingMs);
68370
68486
  }
@@ -75954,6 +76070,21 @@ var import_uuid = require("uuid");
75954
76070
 
75955
76071
  // src/volume.ts
75956
76072
  var import_nice_grpc11 = require("nice-grpc");
76073
+ function volumeFsVersionProto(version) {
76074
+ switch (version) {
76075
+ case void 0:
76076
+ return 0 /* VOLUME_FS_VERSION_UNSPECIFIED */;
76077
+ case 1:
76078
+ return 1 /* VOLUME_FS_VERSION_V1 */;
76079
+ case 2:
76080
+ return 2 /* VOLUME_FS_VERSION_V2 */;
76081
+ default:
76082
+ throw new InvalidError("VolumeFS version must be either 1 or 2");
76083
+ }
76084
+ }
76085
+ function normalizeVolumeFsVersion(version) {
76086
+ return version === 0 /* VOLUME_FS_VERSION_UNSPECIFIED */ ? 1 /* VOLUME_FS_VERSION_V1 */ : version;
76087
+ }
75957
76088
  var VolumeService = class {
75958
76089
  #client;
75959
76090
  constructor(client) {
@@ -75963,12 +76094,25 @@ var VolumeService = class {
75963
76094
  * Reference a {@link Volume} by its name.
75964
76095
  */
75965
76096
  async fromName(name, params) {
76097
+ const requestedVersion = volumeFsVersionProto(params?.version);
75966
76098
  try {
75967
76099
  const resp = await this.#client.cpClient.volumeGetOrCreate({
75968
76100
  deploymentName: name,
75969
76101
  environmentName: this.#client.environmentName(params?.environment),
75970
- objectCreationType: params?.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : 0 /* OBJECT_CREATION_TYPE_UNSPECIFIED */
76102
+ objectCreationType: params?.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : 0 /* OBJECT_CREATION_TYPE_UNSPECIFIED */,
76103
+ version: requestedVersion
75971
76104
  });
76105
+ if (params?.version !== void 0) {
76106
+ const actualVersion = normalizeVolumeFsVersion(
76107
+ resp.metadata?.version ?? 0 /* VOLUME_FS_VERSION_UNSPECIFIED */
76108
+ );
76109
+ const normalizedRequestedVersion = normalizeVolumeFsVersion(requestedVersion);
76110
+ if (actualVersion !== normalizedRequestedVersion) {
76111
+ throw new InvalidError(
76112
+ `Volume '${name}' exists but has version v${actualVersion}, not v${normalizedRequestedVersion} as requested. To access this Volume, either omit the version parameter or use the correct version.`
76113
+ );
76114
+ }
76115
+ }
75972
76116
  this.#client.logger.debug(
75973
76117
  "Retrieved Volume",
75974
76118
  "volume_id",
@@ -79002,7 +79146,7 @@ var AuthTokenManager = class {
79002
79146
  };
79003
79147
 
79004
79148
  // src/version.ts
79005
- var SDK_VERSION = "0.11.1-dev.14";
79149
+ var SDK_VERSION = "0.11.1-dev.16";
79006
79150
  function getSDKVersion() {
79007
79151
  return SDK_VERSION;
79008
79152
  }
@@ -80633,7 +80777,12 @@ var FunctionCall = class {
80633
80777
  this.#client = client;
80634
80778
  this.functionCallId = functionCallId;
80635
80779
  }
80636
- /** Get the result of a FunctionCall, optionally waiting with a timeout. */
80780
+ /**
80781
+ * Get the result of a FunctionCall, optionally waiting with a timeout.
80782
+ *
80783
+ * @throws {@link TimeoutError} if `timeoutMs` elapses before the Function finishes.
80784
+ * @throws {@link FunctionTimeoutError} if the Function exceeds its execution timeout.
80785
+ */
80637
80786
  async get(params = {}) {
80638
80787
  checkForRenamedParams(params, { timeout: "timeoutMs" });
80639
80788
  const invocation = ControlPlaneInvocation.fromFunctionCallId(
@@ -80674,6 +80823,142 @@ var FunctionCall = class {
80674
80823
  // src/function.ts
80675
80824
  var import_nice_grpc17 = require("nice-grpc");
80676
80825
 
80826
+ // src/metrics.ts
80827
+ function metricsRequest(params) {
80828
+ const until = params.until ?? /* @__PURE__ */ new Date();
80829
+ const since = params.since ?? new Date(until.getTime() - 60 * 60 * 1e3);
80830
+ if (!Number.isFinite(since.getTime()) || !Number.isFinite(until.getTime())) {
80831
+ throw new InvalidError("`since` and `until` must be valid dates.");
80832
+ }
80833
+ if (since >= until) {
80834
+ throw new InvalidError("`since` must be before `until`.");
80835
+ }
80836
+ if (since.getTime() < 0) {
80837
+ throw new InvalidError("`since` must be at or after the Unix epoch.");
80838
+ }
80839
+ if (until.getTime() - since.getTime() > 31 * 24 * 60 * 60 * 1e3) {
80840
+ throw new InvalidError("Metrics time range cannot exceed 31 days.");
80841
+ }
80842
+ if (params.groups !== void 0 && (!Array.isArray(params.groups) || params.groups.some((g) => typeof g !== "string" || !g))) {
80843
+ throw new InvalidError(
80844
+ "`groups` must be an array of nonempty group names."
80845
+ );
80846
+ }
80847
+ const request = FunctionGetMetricsRequest.create({
80848
+ since,
80849
+ until,
80850
+ groups: params.groups ?? [],
80851
+ rollup: params.allVariants ?? false
80852
+ });
80853
+ if (params.bucketSizeSecs !== void 0) {
80854
+ const seconds = params.bucketSizeSecs;
80855
+ if (!Number.isInteger(seconds) || seconds < 60 || seconds > 2 ** 32 - 1) {
80856
+ throw new InvalidError(
80857
+ "`bucketSizeSecs` must be a whole number of seconds, at least one minute."
80858
+ );
80859
+ }
80860
+ if (Math.floor(until.getTime() / (params.bucketSizeSecs * 1e3)) - Math.floor(since.getTime() / (params.bucketSizeSecs * 1e3)) > 500) {
80861
+ throw new InvalidError(
80862
+ "Metrics are limited to 500 points per series; increase `bucketSizeSecs`."
80863
+ );
80864
+ }
80865
+ request.bucketSecs = seconds;
80866
+ }
80867
+ return request;
80868
+ }
80869
+ var FunctionMetricsManager = class {
80870
+ #client;
80871
+ #functionId;
80872
+ /** @hidden */
80873
+ constructor(client, functionId) {
80874
+ this.#client = client;
80875
+ this.#functionId = functionId;
80876
+ }
80877
+ /**
80878
+ * Fetch metric samples, defaulting to all groups over the last hour.
80879
+ *
80880
+ * The maximum range is 31 days, with at most 500 points per series. Omit
80881
+ * bucketSizeSecs to let Modal select a supported width targeting approximately
80882
+ * 100 buckets. Bounds round down to UTC bucket boundaries: data before since
80883
+ * may be included, and the partial bucket at until is excluded.
80884
+ * Missing observations have value null. Use schema() to discover definitions.
80885
+ *
80886
+ * @example
80887
+ * ```typescript
80888
+ * const metrics = await fn.metrics.export({
80889
+ * bucketSizeSecs: 5 * 60,
80890
+ * groups: ["calls"],
80891
+ * });
80892
+ * for (const point of metrics.series["successful_calls_count"].points) {
80893
+ * console.log(point.time, point.value);
80894
+ * }
80895
+ * ```
80896
+ */
80897
+ async export(params = {}) {
80898
+ const request = metricsRequest(params);
80899
+ request.functionId = this.#functionId;
80900
+ const response = await this.#client.cpClient.functionGetMetrics(request);
80901
+ const series = Object.fromEntries(
80902
+ response.series.map((item) => [
80903
+ item.name,
80904
+ {
80905
+ name: item.name,
80906
+ unit: item.unit,
80907
+ aggregation: item.name.slice(item.name.lastIndexOf("_") + 1),
80908
+ description: item.description,
80909
+ points: item.points.map((point) => ({
80910
+ time: point.timestamp ?? /* @__PURE__ */ new Date(0),
80911
+ value: point.value ?? null
80912
+ }))
80913
+ }
80914
+ ])
80915
+ );
80916
+ return {
80917
+ objectId: this.#functionId,
80918
+ since: response.since ?? /* @__PURE__ */ new Date(0),
80919
+ until: response.until ?? /* @__PURE__ */ new Date(0),
80920
+ bucketSizeSecs: response.bucketSecs,
80921
+ pointCount: Object.values(series).reduce(
80922
+ (count, item) => count + item.points.length,
80923
+ 0
80924
+ ),
80925
+ series
80926
+ };
80927
+ }
80928
+ /**
80929
+ * Return metric definitions keyed by group name, without fetching samples.
80930
+ * Omit groups to return all groups. Each group's definitions include all its
80931
+ * individual series.
80932
+ */
80933
+ async schema(params = {}) {
80934
+ const window = metricsRequest(params);
80935
+ const response = await this.#client.cpClient.metricsGetInfo(
80936
+ MetricsGetInfoRequest.create({
80937
+ targetType: 1 /* METRICS_TARGET_TYPE_FUNCTION */,
80938
+ since: window.since,
80939
+ until: window.until,
80940
+ groups: window.groups
80941
+ })
80942
+ );
80943
+ const groups = /* @__PURE__ */ new Map();
80944
+ for (const row of response.groups) {
80945
+ let group = groups.get(row.name);
80946
+ if (!group) {
80947
+ group = { name: row.name, definitions: [] };
80948
+ groups.set(row.name, group);
80949
+ }
80950
+ group.definitions.push(
80951
+ ...row.metrics.map((metric) => ({
80952
+ name: metric.name,
80953
+ unit: metric.unit,
80954
+ description: metric.description
80955
+ }))
80956
+ );
80957
+ }
80958
+ return Object.fromEntries(groups);
80959
+ }
80960
+ };
80961
+
80677
80962
  // src/retries.ts
80678
80963
  var Retries = class {
80679
80964
  maxRetries;
@@ -81056,6 +81341,10 @@ var Function_ = class _Function_ {
81056
81341
  this.#handleMetadata?.appId ?? ""
81057
81342
  );
81058
81343
  }
81344
+ /** Access metric samples with export() and series definitions with schema(). */
81345
+ get metrics() {
81346
+ return new FunctionMetricsManager(this.#client, this.functionId);
81347
+ }
81059
81348
  /** Override the static Function configuration at runtime. */
81060
81349
  withOptions(options) {
81061
81350
  return new _Function_(
@@ -81621,6 +81910,7 @@ var ExperimentalOutboundPolicy2 = class _ExperimentalOutboundPolicy {
81621
81910
  FunctionCallLogsManager,
81622
81911
  FunctionCallService,
81623
81912
  FunctionLogsManager,
81913
+ FunctionMetricsManager,
81624
81914
  FunctionService,
81625
81915
  FunctionTimeoutError,
81626
81916
  Function_,