modal 0.3.2 → 0.3.3

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.
Files changed (2) hide show
  1. package/dist/index.js +48 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -37239,6 +37239,9 @@ var InternalFailure = class extends Error {
37239
37239
  }
37240
37240
  };
37241
37241
 
37242
+ // src/function.ts
37243
+ import { createHash } from "node:crypto";
37244
+
37242
37245
  // src/pickle.ts
37243
37246
  var PickleError = class extends Error {
37244
37247
  constructor(message) {
@@ -37541,6 +37544,7 @@ function loads(buf) {
37541
37544
  }
37542
37545
 
37543
37546
  // src/function.ts
37547
+ var maxObjectSizeBytes = 2 * 1024 * 1024;
37544
37548
  function timeNow() {
37545
37549
  return Date.now() / 1e3;
37546
37550
  }
@@ -37561,20 +37565,24 @@ var Function_ = class _Function_ {
37561
37565
  // Execute a single input into a remote Function.
37562
37566
  async remote(args = [], kwargs = {}) {
37563
37567
  const payload = dumps([args, kwargs]);
37564
- const functionInputs = [
37565
- {
37566
- idx: 0,
37567
- input: {
37568
- args: payload,
37569
- dataFormat: 1 /* DATA_FORMAT_PICKLE */
37570
- }
37571
- }
37572
- ];
37568
+ let argsBlobId = void 0;
37569
+ if (payload.length > maxObjectSizeBytes) {
37570
+ argsBlobId = await blobUpload(payload);
37571
+ }
37573
37572
  const functionMapResponse = await client.functionMap({
37574
37573
  functionId: this.functionId,
37575
37574
  functionCallType: 1 /* FUNCTION_CALL_TYPE_UNARY */,
37576
37575
  functionCallInvocationType: 4 /* FUNCTION_CALL_INVOCATION_TYPE_SYNC */,
37577
- pipelinedInputs: functionInputs
37576
+ pipelinedInputs: [
37577
+ {
37578
+ idx: 0,
37579
+ input: {
37580
+ args: argsBlobId ? void 0 : payload,
37581
+ argsBlobId,
37582
+ dataFormat: 1 /* DATA_FORMAT_PICKLE */
37583
+ }
37584
+ }
37585
+ ]
37578
37586
  });
37579
37587
  while (true) {
37580
37588
  const response = await client.functionGetOutputs({
@@ -37612,7 +37620,36 @@ async function processResult(result, dataFormat) {
37612
37620
  default:
37613
37621
  throw new RemoteError(`Remote error: ${result.exception}`);
37614
37622
  }
37615
- return deserializeDataFormat(result.data, dataFormat);
37623
+ return deserializeDataFormat(data, dataFormat);
37624
+ }
37625
+ async function blobUpload(data) {
37626
+ const contentMd5 = createHash("md5").update(data).digest("base64");
37627
+ const contentSha256 = createHash("sha256").update(data).digest("base64");
37628
+ const resp = await client.blobCreate({
37629
+ contentMd5,
37630
+ contentSha256Base64: contentSha256,
37631
+ contentLength: data.length
37632
+ });
37633
+ if (resp.multipart) {
37634
+ throw new Error(
37635
+ "Function input size exceeds multipart upload threshold, unsupported by this SDK version"
37636
+ );
37637
+ } else if (resp.uploadUrl) {
37638
+ const uploadResp = await fetch(resp.uploadUrl, {
37639
+ method: "PUT",
37640
+ headers: {
37641
+ "Content-Type": "application/octet-stream",
37642
+ "Content-MD5": contentMd5
37643
+ },
37644
+ body: data
37645
+ });
37646
+ if (uploadResp.status < 200 || uploadResp.status >= 300) {
37647
+ throw new Error(`Failed blob upload: ${uploadResp.statusText}`);
37648
+ }
37649
+ return resp.blobId;
37650
+ } else {
37651
+ throw new Error("Missing upload URL in BlobCreate response");
37652
+ }
37616
37653
  }
37617
37654
  async function blobDownload(blobId) {
37618
37655
  const resp = await client.blobGet({ blobId });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modal",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Modal client library for JavaScript",
5
5
  "license": "MIT",
6
6
  "homepage": "https://modal.com/docs",