@pierre/storage 0.1.3 → 0.2.0

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.js CHANGED
@@ -191,6 +191,9 @@ var CommitBuilderImpl = class {
191
191
  this.options.baseBranch = trimmedBase;
192
192
  }
193
193
  }
194
+ if (this.options.ephemeralBase && !this.options.baseBranch) {
195
+ throw new Error("createCommit ephemeralBase requires baseBranch");
196
+ }
194
197
  }
195
198
  addFile(path, source, options) {
196
199
  this.ensureNotSent();
@@ -284,6 +287,12 @@ var CommitBuilderImpl = class {
284
287
  email: this.options.committer.email
285
288
  };
286
289
  }
290
+ if (this.options.ephemeral) {
291
+ metadata.ephemeral = true;
292
+ }
293
+ if (this.options.ephemeralBase) {
294
+ metadata.ephemeral_base = true;
295
+ }
287
296
  return metadata;
288
297
  }
289
298
  ensureNotSent() {
@@ -307,7 +316,7 @@ var FetchCommitTransport = class {
307
316
  async send(request) {
308
317
  const bodyIterable = buildMessageIterable(request.metadata, request.blobs);
309
318
  const body = toRequestBody(bodyIterable);
310
- const response = await fetch(this.url, {
319
+ const init = {
311
320
  method: "POST",
312
321
  headers: {
313
322
  Authorization: `Bearer ${request.authorization}`,
@@ -316,7 +325,11 @@ var FetchCommitTransport = class {
316
325
  },
317
326
  body,
318
327
  signal: request.signal
319
- });
328
+ };
329
+ if (requiresDuplex(body)) {
330
+ init.duplex = "half";
331
+ }
332
+ const response = await fetch(this.url, init);
320
333
  if (!response.ok) {
321
334
  const { statusMessage, statusLabel, refUpdate } = await parseCommitPackError(response);
322
335
  throw new RefUpdateError(statusMessage, {
@@ -373,6 +386,19 @@ function buildMessageIterable(metadata, blobs) {
373
386
  }
374
387
  };
375
388
  }
389
+ function requiresDuplex(body) {
390
+ if (!body || typeof body !== "object") {
391
+ return false;
392
+ }
393
+ if (typeof body[Symbol.asyncIterator] === "function") {
394
+ return true;
395
+ }
396
+ const readableStreamCtor = globalThis.ReadableStream;
397
+ if (readableStreamCtor && body instanceof readableStreamCtor) {
398
+ return true;
399
+ }
400
+ return false;
401
+ }
376
402
  function buildCommitResult(ack) {
377
403
  const refUpdate = toRefUpdate(ack.result);
378
404
  if (!ack.result.success) {
@@ -564,6 +590,8 @@ function normalizeCommitOptions(options) {
564
590
  commitMessage: options.commitMessage,
565
591
  expectedHeadSha: options.expectedHeadSha,
566
592
  baseBranch: options.baseBranch,
593
+ ephemeral: options.ephemeral === true,
594
+ ephemeralBase: options.ephemeralBase === true,
567
595
  author: options.author,
568
596
  committer: options.committer,
569
597
  signal: options.signal,
@@ -1276,6 +1304,9 @@ var RepoImpl = class {
1276
1304
  if (options.ref) {
1277
1305
  params.ref = options.ref;
1278
1306
  }
1307
+ if (typeof options.ephemeral === "boolean") {
1308
+ params.ephemeral = String(options.ephemeral);
1309
+ }
1279
1310
  return this.api.get({ path: "repos/file", params }, jwt);
1280
1311
  }
1281
1312
  async listFiles(options) {
@@ -1284,8 +1315,17 @@ var RepoImpl = class {
1284
1315
  permissions: ["git:read"],
1285
1316
  ttl
1286
1317
  });
1287
- const params = options?.ref ? { ref: options.ref } : void 0;
1288
- const response = await this.api.get({ path: "repos/files", params }, jwt);
1318
+ const params = {};
1319
+ if (options?.ref) {
1320
+ params.ref = options.ref;
1321
+ }
1322
+ if (typeof options?.ephemeral === "boolean") {
1323
+ params.ephemeral = String(options.ephemeral);
1324
+ }
1325
+ const response = await this.api.get(
1326
+ { path: "repos/files", params: Object.keys(params).length ? params : void 0 },
1327
+ jwt
1328
+ );
1289
1329
  const raw = listFilesResponseSchema.parse(await response.json());
1290
1330
  return { paths: raw.paths, ref: raw.ref };
1291
1331
  }