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 +301 -11
- package/dist/index.d.cts +123 -6
- package/dist/index.d.ts +123 -6
- package/dist/index.js +300 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -36130,7 +36130,7 @@ var ImageListTagsItem = {
|
|
|
36130
36130
|
}
|
|
36131
36131
|
};
|
|
36132
36132
|
function createBaseImageListTagsRequest() {
|
|
36133
|
-
return { environmentName: "", tagPrefix: "", maxObjects: 0, pageToken: "" };
|
|
36133
|
+
return { environmentName: "", tagPrefix: "", maxObjects: 0, pageToken: "", imageId: "" };
|
|
36134
36134
|
}
|
|
36135
36135
|
var ImageListTagsRequest = {
|
|
36136
36136
|
encode(message, writer = new BinaryWriter()) {
|
|
@@ -36146,6 +36146,9 @@ var ImageListTagsRequest = {
|
|
|
36146
36146
|
if (message.pageToken !== "") {
|
|
36147
36147
|
writer.uint32(34).string(message.pageToken);
|
|
36148
36148
|
}
|
|
36149
|
+
if (message.imageId !== "") {
|
|
36150
|
+
writer.uint32(42).string(message.imageId);
|
|
36151
|
+
}
|
|
36149
36152
|
return writer;
|
|
36150
36153
|
},
|
|
36151
36154
|
decode(input, length) {
|
|
@@ -36183,6 +36186,13 @@ var ImageListTagsRequest = {
|
|
|
36183
36186
|
message.pageToken = reader.string();
|
|
36184
36187
|
continue;
|
|
36185
36188
|
}
|
|
36189
|
+
case 5: {
|
|
36190
|
+
if (tag !== 42) {
|
|
36191
|
+
break;
|
|
36192
|
+
}
|
|
36193
|
+
message.imageId = reader.string();
|
|
36194
|
+
continue;
|
|
36195
|
+
}
|
|
36186
36196
|
}
|
|
36187
36197
|
if ((tag & 7) === 4 || tag === 0) {
|
|
36188
36198
|
break;
|
|
@@ -36196,7 +36206,8 @@ var ImageListTagsRequest = {
|
|
|
36196
36206
|
environmentName: isSet5(object.environmentName) ? globalThis.String(object.environmentName) : "",
|
|
36197
36207
|
tagPrefix: isSet5(object.tagPrefix) ? globalThis.String(object.tagPrefix) : "",
|
|
36198
36208
|
maxObjects: isSet5(object.maxObjects) ? globalThis.Number(object.maxObjects) : 0,
|
|
36199
|
-
pageToken: isSet5(object.pageToken) ? globalThis.String(object.pageToken) : ""
|
|
36209
|
+
pageToken: isSet5(object.pageToken) ? globalThis.String(object.pageToken) : "",
|
|
36210
|
+
imageId: isSet5(object.imageId) ? globalThis.String(object.imageId) : ""
|
|
36200
36211
|
};
|
|
36201
36212
|
},
|
|
36202
36213
|
toJSON(message) {
|
|
@@ -36213,6 +36224,9 @@ var ImageListTagsRequest = {
|
|
|
36213
36224
|
if (message.pageToken !== "") {
|
|
36214
36225
|
obj.pageToken = message.pageToken;
|
|
36215
36226
|
}
|
|
36227
|
+
if (message.imageId !== "") {
|
|
36228
|
+
obj.imageId = message.imageId;
|
|
36229
|
+
}
|
|
36216
36230
|
return obj;
|
|
36217
36231
|
},
|
|
36218
36232
|
create(base) {
|
|
@@ -36224,6 +36238,7 @@ var ImageListTagsRequest = {
|
|
|
36224
36238
|
message.tagPrefix = object.tagPrefix ?? "";
|
|
36225
36239
|
message.maxObjects = object.maxObjects ?? 0;
|
|
36226
36240
|
message.pageToken = object.pageToken ?? "";
|
|
36241
|
+
message.imageId = object.imageId ?? "";
|
|
36227
36242
|
return message;
|
|
36228
36243
|
}
|
|
36229
36244
|
};
|
|
@@ -36517,6 +36532,57 @@ var ImageMetadata_PythonPackagesEntry = {
|
|
|
36517
36532
|
return message;
|
|
36518
36533
|
}
|
|
36519
36534
|
};
|
|
36535
|
+
function createBaseImageNameDeleteRequest() {
|
|
36536
|
+
return { tag: "" };
|
|
36537
|
+
}
|
|
36538
|
+
var ImageNameDeleteRequest = {
|
|
36539
|
+
encode(message, writer = new BinaryWriter()) {
|
|
36540
|
+
if (message.tag !== "") {
|
|
36541
|
+
writer.uint32(10).string(message.tag);
|
|
36542
|
+
}
|
|
36543
|
+
return writer;
|
|
36544
|
+
},
|
|
36545
|
+
decode(input, length) {
|
|
36546
|
+
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
|
|
36547
|
+
let end = length === void 0 ? reader.len : reader.pos + length;
|
|
36548
|
+
const message = createBaseImageNameDeleteRequest();
|
|
36549
|
+
while (reader.pos < end) {
|
|
36550
|
+
const tag = reader.uint32();
|
|
36551
|
+
switch (tag >>> 3) {
|
|
36552
|
+
case 1: {
|
|
36553
|
+
if (tag !== 10) {
|
|
36554
|
+
break;
|
|
36555
|
+
}
|
|
36556
|
+
message.tag = reader.string();
|
|
36557
|
+
continue;
|
|
36558
|
+
}
|
|
36559
|
+
}
|
|
36560
|
+
if ((tag & 7) === 4 || tag === 0) {
|
|
36561
|
+
break;
|
|
36562
|
+
}
|
|
36563
|
+
reader.skip(tag & 7);
|
|
36564
|
+
}
|
|
36565
|
+
return message;
|
|
36566
|
+
},
|
|
36567
|
+
fromJSON(object) {
|
|
36568
|
+
return { tag: isSet5(object.tag) ? globalThis.String(object.tag) : "" };
|
|
36569
|
+
},
|
|
36570
|
+
toJSON(message) {
|
|
36571
|
+
const obj = {};
|
|
36572
|
+
if (message.tag !== "") {
|
|
36573
|
+
obj.tag = message.tag;
|
|
36574
|
+
}
|
|
36575
|
+
return obj;
|
|
36576
|
+
},
|
|
36577
|
+
create(base) {
|
|
36578
|
+
return ImageNameDeleteRequest.fromPartial(base ?? {});
|
|
36579
|
+
},
|
|
36580
|
+
fromPartial(object) {
|
|
36581
|
+
const message = createBaseImageNameDeleteRequest();
|
|
36582
|
+
message.tag = object.tag ?? "";
|
|
36583
|
+
return message;
|
|
36584
|
+
}
|
|
36585
|
+
};
|
|
36520
36586
|
function createBaseImagePublishRequest() {
|
|
36521
36587
|
return { imageId: "", tag: "", environmentName: "", allowPublic: false };
|
|
36522
36588
|
}
|
|
@@ -66335,6 +66401,14 @@ var ModalClientDefinition = {
|
|
|
66335
66401
|
responseStream: false,
|
|
66336
66402
|
options: {}
|
|
66337
66403
|
},
|
|
66404
|
+
imageNameDelete: {
|
|
66405
|
+
name: "ImageNameDelete",
|
|
66406
|
+
requestType: ImageNameDeleteRequest,
|
|
66407
|
+
requestStream: false,
|
|
66408
|
+
responseType: Empty,
|
|
66409
|
+
responseStream: false,
|
|
66410
|
+
options: {}
|
|
66411
|
+
},
|
|
66338
66412
|
imagePublish: {
|
|
66339
66413
|
name: "ImagePublish",
|
|
66340
66414
|
requestType: ImagePublishRequest,
|
|
@@ -67536,11 +67610,40 @@ var TimeoutError = class extends Error {
|
|
|
67536
67610
|
this.name = "TimeoutError";
|
|
67537
67611
|
}
|
|
67538
67612
|
};
|
|
67539
|
-
var FunctionTimeoutError = class extends Error {
|
|
67613
|
+
var FunctionTimeoutError = class _FunctionTimeoutError extends Error {
|
|
67540
67614
|
constructor(message) {
|
|
67541
67615
|
super(message);
|
|
67542
67616
|
this.name = "FunctionTimeoutError";
|
|
67543
67617
|
}
|
|
67618
|
+
// Backward compatibility: FunctionCall.get() wait timeouts still match
|
|
67619
|
+
// FunctionTimeoutError, with a deprecation warning.
|
|
67620
|
+
static [Symbol.hasInstance](instance) {
|
|
67621
|
+
if (Function.prototype[Symbol.hasInstance].call(this, instance)) {
|
|
67622
|
+
return true;
|
|
67623
|
+
}
|
|
67624
|
+
if (this === _FunctionTimeoutError && instance instanceof FunctionCallGetTimeoutError) {
|
|
67625
|
+
instance.warnFunctionTimeoutErrorMatch();
|
|
67626
|
+
return true;
|
|
67627
|
+
}
|
|
67628
|
+
return false;
|
|
67629
|
+
}
|
|
67630
|
+
};
|
|
67631
|
+
var warnedFunctionTimeoutErrorMatch = false;
|
|
67632
|
+
var FunctionCallGetTimeoutError = class extends TimeoutError {
|
|
67633
|
+
#logger;
|
|
67634
|
+
constructor(message, logger2) {
|
|
67635
|
+
super(message);
|
|
67636
|
+
this.#logger = logger2;
|
|
67637
|
+
}
|
|
67638
|
+
warnFunctionTimeoutErrorMatch() {
|
|
67639
|
+
if (warnedFunctionTimeoutErrorMatch) {
|
|
67640
|
+
return;
|
|
67641
|
+
}
|
|
67642
|
+
warnedFunctionTimeoutErrorMatch = true;
|
|
67643
|
+
this.#logger.warn(
|
|
67644
|
+
"Matching a FunctionCall.get() timeout with `instanceof FunctionTimeoutError` is deprecated and will stop working in a future release; check `instanceof TimeoutError` first instead."
|
|
67645
|
+
);
|
|
67646
|
+
}
|
|
67544
67647
|
};
|
|
67545
67648
|
var RemoteError = class extends Error {
|
|
67546
67649
|
constructor(message) {
|
|
@@ -68120,12 +68223,14 @@ async function blobDownload(cpClient, blobId) {
|
|
|
68120
68223
|
var outputsTimeoutMs = 55 * 1e3;
|
|
68121
68224
|
var ControlPlaneInvocation = class _ControlPlaneInvocation {
|
|
68122
68225
|
cpClient;
|
|
68226
|
+
logger;
|
|
68123
68227
|
functionCallId;
|
|
68124
68228
|
input;
|
|
68125
68229
|
functionCallJwt;
|
|
68126
68230
|
inputJwt;
|
|
68127
|
-
constructor(cpClient, functionCallId, input, functionCallJwt, inputJwt) {
|
|
68231
|
+
constructor(cpClient, logger2, functionCallId, input, functionCallJwt, inputJwt) {
|
|
68128
68232
|
this.cpClient = cpClient;
|
|
68233
|
+
this.logger = logger2;
|
|
68129
68234
|
this.functionCallId = functionCallId;
|
|
68130
68235
|
this.input = input;
|
|
68131
68236
|
this.functionCallJwt = functionCallJwt;
|
|
@@ -68144,6 +68249,7 @@ var ControlPlaneInvocation = class _ControlPlaneInvocation {
|
|
|
68144
68249
|
});
|
|
68145
68250
|
return new _ControlPlaneInvocation(
|
|
68146
68251
|
client.cpClient,
|
|
68252
|
+
client.logger,
|
|
68147
68253
|
functionMapResponse.functionCallId,
|
|
68148
68254
|
input,
|
|
68149
68255
|
functionMapResponse.functionCallJwt,
|
|
@@ -68151,11 +68257,16 @@ var ControlPlaneInvocation = class _ControlPlaneInvocation {
|
|
|
68151
68257
|
);
|
|
68152
68258
|
}
|
|
68153
68259
|
static fromFunctionCallId(client, functionCallId) {
|
|
68154
|
-
return new _ControlPlaneInvocation(
|
|
68260
|
+
return new _ControlPlaneInvocation(
|
|
68261
|
+
client.cpClient,
|
|
68262
|
+
client.logger,
|
|
68263
|
+
functionCallId
|
|
68264
|
+
);
|
|
68155
68265
|
}
|
|
68156
68266
|
async awaitOutput(timeoutMs, clearOnSuccess = false) {
|
|
68157
68267
|
return await pollFunctionOutput(
|
|
68158
68268
|
this.cpClient,
|
|
68269
|
+
this.logger,
|
|
68159
68270
|
(timeoutMs2) => this.#getOutput(
|
|
68160
68271
|
timeoutMs2,
|
|
68161
68272
|
clearOnSuccess,
|
|
@@ -68195,12 +68306,14 @@ var ControlPlaneInvocation = class _ControlPlaneInvocation {
|
|
|
68195
68306
|
var InputPlaneInvocation = class _InputPlaneInvocation {
|
|
68196
68307
|
cpClient;
|
|
68197
68308
|
ipClient;
|
|
68309
|
+
logger;
|
|
68198
68310
|
functionId;
|
|
68199
68311
|
input;
|
|
68200
68312
|
attemptToken;
|
|
68201
|
-
constructor(cpClient, ipClient, functionId, input, attemptToken) {
|
|
68313
|
+
constructor(cpClient, ipClient, logger2, functionId, input, attemptToken) {
|
|
68202
68314
|
this.cpClient = cpClient;
|
|
68203
68315
|
this.ipClient = ipClient;
|
|
68316
|
+
this.logger = logger2;
|
|
68204
68317
|
this.functionId = functionId;
|
|
68205
68318
|
this.input = input;
|
|
68206
68319
|
this.attemptToken = attemptToken;
|
|
@@ -68218,6 +68331,7 @@ var InputPlaneInvocation = class _InputPlaneInvocation {
|
|
|
68218
68331
|
return new _InputPlaneInvocation(
|
|
68219
68332
|
client.cpClient,
|
|
68220
68333
|
ipClient,
|
|
68334
|
+
client.logger,
|
|
68221
68335
|
functionId,
|
|
68222
68336
|
functionPutInputsItem,
|
|
68223
68337
|
attemptStartResponse.attemptToken
|
|
@@ -68226,6 +68340,7 @@ var InputPlaneInvocation = class _InputPlaneInvocation {
|
|
|
68226
68340
|
async awaitOutput(timeoutMs) {
|
|
68227
68341
|
return await pollFunctionOutput(
|
|
68228
68342
|
this.cpClient,
|
|
68343
|
+
this.logger,
|
|
68229
68344
|
(timeoutMs2) => this.#getOutput(timeoutMs2),
|
|
68230
68345
|
timeoutMs
|
|
68231
68346
|
);
|
|
@@ -68250,7 +68365,7 @@ var InputPlaneInvocation = class _InputPlaneInvocation {
|
|
|
68250
68365
|
function timeNowSeconds() {
|
|
68251
68366
|
return Date.now() / 1e3;
|
|
68252
68367
|
}
|
|
68253
|
-
async function pollFunctionOutput(cpClient, getOutput, timeoutMs) {
|
|
68368
|
+
async function pollFunctionOutput(cpClient, logger2, getOutput, timeoutMs) {
|
|
68254
68369
|
const startTime = Date.now();
|
|
68255
68370
|
let pollTimeoutMs = outputsTimeoutMs;
|
|
68256
68371
|
if (timeoutMs !== void 0) {
|
|
@@ -68265,7 +68380,7 @@ async function pollFunctionOutput(cpClient, getOutput, timeoutMs) {
|
|
|
68265
68380
|
const remainingMs = timeoutMs - (Date.now() - startTime);
|
|
68266
68381
|
if (remainingMs <= 0) {
|
|
68267
68382
|
const message = `Timeout exceeded: ${timeoutMs}ms`;
|
|
68268
|
-
throw new
|
|
68383
|
+
throw new FunctionCallGetTimeoutError(message, logger2);
|
|
68269
68384
|
}
|
|
68270
68385
|
pollTimeoutMs = Math.min(outputsTimeoutMs, remainingMs);
|
|
68271
68386
|
}
|
|
@@ -75868,6 +75983,21 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
75868
75983
|
|
|
75869
75984
|
// src/volume.ts
|
|
75870
75985
|
import { ClientError as ClientError10, Status as Status10 } from "nice-grpc";
|
|
75986
|
+
function volumeFsVersionProto(version) {
|
|
75987
|
+
switch (version) {
|
|
75988
|
+
case void 0:
|
|
75989
|
+
return 0 /* VOLUME_FS_VERSION_UNSPECIFIED */;
|
|
75990
|
+
case 1:
|
|
75991
|
+
return 1 /* VOLUME_FS_VERSION_V1 */;
|
|
75992
|
+
case 2:
|
|
75993
|
+
return 2 /* VOLUME_FS_VERSION_V2 */;
|
|
75994
|
+
default:
|
|
75995
|
+
throw new InvalidError("VolumeFS version must be either 1 or 2");
|
|
75996
|
+
}
|
|
75997
|
+
}
|
|
75998
|
+
function normalizeVolumeFsVersion(version) {
|
|
75999
|
+
return version === 0 /* VOLUME_FS_VERSION_UNSPECIFIED */ ? 1 /* VOLUME_FS_VERSION_V1 */ : version;
|
|
76000
|
+
}
|
|
75871
76001
|
var VolumeService = class {
|
|
75872
76002
|
#client;
|
|
75873
76003
|
constructor(client) {
|
|
@@ -75877,12 +76007,25 @@ var VolumeService = class {
|
|
|
75877
76007
|
* Reference a {@link Volume} by its name.
|
|
75878
76008
|
*/
|
|
75879
76009
|
async fromName(name, params) {
|
|
76010
|
+
const requestedVersion = volumeFsVersionProto(params?.version);
|
|
75880
76011
|
try {
|
|
75881
76012
|
const resp = await this.#client.cpClient.volumeGetOrCreate({
|
|
75882
76013
|
deploymentName: name,
|
|
75883
76014
|
environmentName: this.#client.environmentName(params?.environment),
|
|
75884
|
-
objectCreationType: params?.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : 0 /* OBJECT_CREATION_TYPE_UNSPECIFIED
|
|
76015
|
+
objectCreationType: params?.createIfMissing ? 1 /* OBJECT_CREATION_TYPE_CREATE_IF_MISSING */ : 0 /* OBJECT_CREATION_TYPE_UNSPECIFIED */,
|
|
76016
|
+
version: requestedVersion
|
|
75885
76017
|
});
|
|
76018
|
+
if (params?.version !== void 0) {
|
|
76019
|
+
const actualVersion = normalizeVolumeFsVersion(
|
|
76020
|
+
resp.metadata?.version ?? 0 /* VOLUME_FS_VERSION_UNSPECIFIED */
|
|
76021
|
+
);
|
|
76022
|
+
const normalizedRequestedVersion = normalizeVolumeFsVersion(requestedVersion);
|
|
76023
|
+
if (actualVersion !== normalizedRequestedVersion) {
|
|
76024
|
+
throw new InvalidError(
|
|
76025
|
+
`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.`
|
|
76026
|
+
);
|
|
76027
|
+
}
|
|
76028
|
+
}
|
|
75886
76029
|
this.#client.logger.debug(
|
|
75887
76030
|
"Retrieved Volume",
|
|
75888
76031
|
"volume_id",
|
|
@@ -78916,7 +79059,7 @@ var AuthTokenManager = class {
|
|
|
78916
79059
|
};
|
|
78917
79060
|
|
|
78918
79061
|
// src/version.ts
|
|
78919
|
-
var SDK_VERSION = "0.11.1-dev.
|
|
79062
|
+
var SDK_VERSION = "0.11.1-dev.16";
|
|
78920
79063
|
function getSDKVersion() {
|
|
78921
79064
|
return SDK_VERSION;
|
|
78922
79065
|
}
|
|
@@ -80552,7 +80695,12 @@ var FunctionCall = class {
|
|
|
80552
80695
|
this.#client = client;
|
|
80553
80696
|
this.functionCallId = functionCallId;
|
|
80554
80697
|
}
|
|
80555
|
-
/**
|
|
80698
|
+
/**
|
|
80699
|
+
* Get the result of a FunctionCall, optionally waiting with a timeout.
|
|
80700
|
+
*
|
|
80701
|
+
* @throws {@link TimeoutError} if `timeoutMs` elapses before the Function finishes.
|
|
80702
|
+
* @throws {@link FunctionTimeoutError} if the Function exceeds its execution timeout.
|
|
80703
|
+
*/
|
|
80556
80704
|
async get(params = {}) {
|
|
80557
80705
|
checkForRenamedParams(params, { timeout: "timeoutMs" });
|
|
80558
80706
|
const invocation = ControlPlaneInvocation.fromFunctionCallId(
|
|
@@ -80593,6 +80741,142 @@ var FunctionCall = class {
|
|
|
80593
80741
|
// src/function.ts
|
|
80594
80742
|
import { ClientError as ClientError16, Status as Status16 } from "nice-grpc";
|
|
80595
80743
|
|
|
80744
|
+
// src/metrics.ts
|
|
80745
|
+
function metricsRequest(params) {
|
|
80746
|
+
const until = params.until ?? /* @__PURE__ */ new Date();
|
|
80747
|
+
const since = params.since ?? new Date(until.getTime() - 60 * 60 * 1e3);
|
|
80748
|
+
if (!Number.isFinite(since.getTime()) || !Number.isFinite(until.getTime())) {
|
|
80749
|
+
throw new InvalidError("`since` and `until` must be valid dates.");
|
|
80750
|
+
}
|
|
80751
|
+
if (since >= until) {
|
|
80752
|
+
throw new InvalidError("`since` must be before `until`.");
|
|
80753
|
+
}
|
|
80754
|
+
if (since.getTime() < 0) {
|
|
80755
|
+
throw new InvalidError("`since` must be at or after the Unix epoch.");
|
|
80756
|
+
}
|
|
80757
|
+
if (until.getTime() - since.getTime() > 31 * 24 * 60 * 60 * 1e3) {
|
|
80758
|
+
throw new InvalidError("Metrics time range cannot exceed 31 days.");
|
|
80759
|
+
}
|
|
80760
|
+
if (params.groups !== void 0 && (!Array.isArray(params.groups) || params.groups.some((g) => typeof g !== "string" || !g))) {
|
|
80761
|
+
throw new InvalidError(
|
|
80762
|
+
"`groups` must be an array of nonempty group names."
|
|
80763
|
+
);
|
|
80764
|
+
}
|
|
80765
|
+
const request = FunctionGetMetricsRequest.create({
|
|
80766
|
+
since,
|
|
80767
|
+
until,
|
|
80768
|
+
groups: params.groups ?? [],
|
|
80769
|
+
rollup: params.allVariants ?? false
|
|
80770
|
+
});
|
|
80771
|
+
if (params.bucketSizeSecs !== void 0) {
|
|
80772
|
+
const seconds = params.bucketSizeSecs;
|
|
80773
|
+
if (!Number.isInteger(seconds) || seconds < 60 || seconds > 2 ** 32 - 1) {
|
|
80774
|
+
throw new InvalidError(
|
|
80775
|
+
"`bucketSizeSecs` must be a whole number of seconds, at least one minute."
|
|
80776
|
+
);
|
|
80777
|
+
}
|
|
80778
|
+
if (Math.floor(until.getTime() / (params.bucketSizeSecs * 1e3)) - Math.floor(since.getTime() / (params.bucketSizeSecs * 1e3)) > 500) {
|
|
80779
|
+
throw new InvalidError(
|
|
80780
|
+
"Metrics are limited to 500 points per series; increase `bucketSizeSecs`."
|
|
80781
|
+
);
|
|
80782
|
+
}
|
|
80783
|
+
request.bucketSecs = seconds;
|
|
80784
|
+
}
|
|
80785
|
+
return request;
|
|
80786
|
+
}
|
|
80787
|
+
var FunctionMetricsManager = class {
|
|
80788
|
+
#client;
|
|
80789
|
+
#functionId;
|
|
80790
|
+
/** @hidden */
|
|
80791
|
+
constructor(client, functionId) {
|
|
80792
|
+
this.#client = client;
|
|
80793
|
+
this.#functionId = functionId;
|
|
80794
|
+
}
|
|
80795
|
+
/**
|
|
80796
|
+
* Fetch metric samples, defaulting to all groups over the last hour.
|
|
80797
|
+
*
|
|
80798
|
+
* The maximum range is 31 days, with at most 500 points per series. Omit
|
|
80799
|
+
* bucketSizeSecs to let Modal select a supported width targeting approximately
|
|
80800
|
+
* 100 buckets. Bounds round down to UTC bucket boundaries: data before since
|
|
80801
|
+
* may be included, and the partial bucket at until is excluded.
|
|
80802
|
+
* Missing observations have value null. Use schema() to discover definitions.
|
|
80803
|
+
*
|
|
80804
|
+
* @example
|
|
80805
|
+
* ```typescript
|
|
80806
|
+
* const metrics = await fn.metrics.export({
|
|
80807
|
+
* bucketSizeSecs: 5 * 60,
|
|
80808
|
+
* groups: ["calls"],
|
|
80809
|
+
* });
|
|
80810
|
+
* for (const point of metrics.series["successful_calls_count"].points) {
|
|
80811
|
+
* console.log(point.time, point.value);
|
|
80812
|
+
* }
|
|
80813
|
+
* ```
|
|
80814
|
+
*/
|
|
80815
|
+
async export(params = {}) {
|
|
80816
|
+
const request = metricsRequest(params);
|
|
80817
|
+
request.functionId = this.#functionId;
|
|
80818
|
+
const response = await this.#client.cpClient.functionGetMetrics(request);
|
|
80819
|
+
const series = Object.fromEntries(
|
|
80820
|
+
response.series.map((item) => [
|
|
80821
|
+
item.name,
|
|
80822
|
+
{
|
|
80823
|
+
name: item.name,
|
|
80824
|
+
unit: item.unit,
|
|
80825
|
+
aggregation: item.name.slice(item.name.lastIndexOf("_") + 1),
|
|
80826
|
+
description: item.description,
|
|
80827
|
+
points: item.points.map((point) => ({
|
|
80828
|
+
time: point.timestamp ?? /* @__PURE__ */ new Date(0),
|
|
80829
|
+
value: point.value ?? null
|
|
80830
|
+
}))
|
|
80831
|
+
}
|
|
80832
|
+
])
|
|
80833
|
+
);
|
|
80834
|
+
return {
|
|
80835
|
+
objectId: this.#functionId,
|
|
80836
|
+
since: response.since ?? /* @__PURE__ */ new Date(0),
|
|
80837
|
+
until: response.until ?? /* @__PURE__ */ new Date(0),
|
|
80838
|
+
bucketSizeSecs: response.bucketSecs,
|
|
80839
|
+
pointCount: Object.values(series).reduce(
|
|
80840
|
+
(count, item) => count + item.points.length,
|
|
80841
|
+
0
|
|
80842
|
+
),
|
|
80843
|
+
series
|
|
80844
|
+
};
|
|
80845
|
+
}
|
|
80846
|
+
/**
|
|
80847
|
+
* Return metric definitions keyed by group name, without fetching samples.
|
|
80848
|
+
* Omit groups to return all groups. Each group's definitions include all its
|
|
80849
|
+
* individual series.
|
|
80850
|
+
*/
|
|
80851
|
+
async schema(params = {}) {
|
|
80852
|
+
const window = metricsRequest(params);
|
|
80853
|
+
const response = await this.#client.cpClient.metricsGetInfo(
|
|
80854
|
+
MetricsGetInfoRequest.create({
|
|
80855
|
+
targetType: 1 /* METRICS_TARGET_TYPE_FUNCTION */,
|
|
80856
|
+
since: window.since,
|
|
80857
|
+
until: window.until,
|
|
80858
|
+
groups: window.groups
|
|
80859
|
+
})
|
|
80860
|
+
);
|
|
80861
|
+
const groups = /* @__PURE__ */ new Map();
|
|
80862
|
+
for (const row of response.groups) {
|
|
80863
|
+
let group = groups.get(row.name);
|
|
80864
|
+
if (!group) {
|
|
80865
|
+
group = { name: row.name, definitions: [] };
|
|
80866
|
+
groups.set(row.name, group);
|
|
80867
|
+
}
|
|
80868
|
+
group.definitions.push(
|
|
80869
|
+
...row.metrics.map((metric) => ({
|
|
80870
|
+
name: metric.name,
|
|
80871
|
+
unit: metric.unit,
|
|
80872
|
+
description: metric.description
|
|
80873
|
+
}))
|
|
80874
|
+
);
|
|
80875
|
+
}
|
|
80876
|
+
return Object.fromEntries(groups);
|
|
80877
|
+
}
|
|
80878
|
+
};
|
|
80879
|
+
|
|
80596
80880
|
// src/retries.ts
|
|
80597
80881
|
var Retries = class {
|
|
80598
80882
|
maxRetries;
|
|
@@ -80975,6 +81259,10 @@ var Function_ = class _Function_ {
|
|
|
80975
81259
|
this.#handleMetadata?.appId ?? ""
|
|
80976
81260
|
);
|
|
80977
81261
|
}
|
|
81262
|
+
/** Access metric samples with export() and series definitions with schema(). */
|
|
81263
|
+
get metrics() {
|
|
81264
|
+
return new FunctionMetricsManager(this.#client, this.functionId);
|
|
81265
|
+
}
|
|
80978
81266
|
/** Override the static Function configuration at runtime. */
|
|
80979
81267
|
withOptions(options) {
|
|
80980
81268
|
return new _Function_(
|
|
@@ -81539,6 +81827,7 @@ export {
|
|
|
81539
81827
|
FunctionCallLogsManager,
|
|
81540
81828
|
FunctionCallService,
|
|
81541
81829
|
FunctionLogsManager,
|
|
81830
|
+
FunctionMetricsManager,
|
|
81542
81831
|
FunctionService,
|
|
81543
81832
|
FunctionTimeoutError,
|
|
81544
81833
|
Function_,
|