@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.cjs CHANGED
@@ -197,6 +197,9 @@ var CommitBuilderImpl = class {
197
197
  this.options.baseBranch = trimmedBase;
198
198
  }
199
199
  }
200
+ if (this.options.ephemeralBase && !this.options.baseBranch) {
201
+ throw new Error("createCommit ephemeralBase requires baseBranch");
202
+ }
200
203
  }
201
204
  addFile(path, source, options) {
202
205
  this.ensureNotSent();
@@ -290,6 +293,12 @@ var CommitBuilderImpl = class {
290
293
  email: this.options.committer.email
291
294
  };
292
295
  }
296
+ if (this.options.ephemeral) {
297
+ metadata.ephemeral = true;
298
+ }
299
+ if (this.options.ephemeralBase) {
300
+ metadata.ephemeral_base = true;
301
+ }
293
302
  return metadata;
294
303
  }
295
304
  ensureNotSent() {
@@ -313,7 +322,7 @@ var FetchCommitTransport = class {
313
322
  async send(request) {
314
323
  const bodyIterable = buildMessageIterable(request.metadata, request.blobs);
315
324
  const body = toRequestBody(bodyIterable);
316
- const response = await fetch(this.url, {
325
+ const init = {
317
326
  method: "POST",
318
327
  headers: {
319
328
  Authorization: `Bearer ${request.authorization}`,
@@ -322,7 +331,11 @@ var FetchCommitTransport = class {
322
331
  },
323
332
  body,
324
333
  signal: request.signal
325
- });
334
+ };
335
+ if (requiresDuplex(body)) {
336
+ init.duplex = "half";
337
+ }
338
+ const response = await fetch(this.url, init);
326
339
  if (!response.ok) {
327
340
  const { statusMessage, statusLabel, refUpdate } = await parseCommitPackError(response);
328
341
  throw new RefUpdateError(statusMessage, {
@@ -379,6 +392,19 @@ function buildMessageIterable(metadata, blobs) {
379
392
  }
380
393
  };
381
394
  }
395
+ function requiresDuplex(body) {
396
+ if (!body || typeof body !== "object") {
397
+ return false;
398
+ }
399
+ if (typeof body[Symbol.asyncIterator] === "function") {
400
+ return true;
401
+ }
402
+ const readableStreamCtor = globalThis.ReadableStream;
403
+ if (readableStreamCtor && body instanceof readableStreamCtor) {
404
+ return true;
405
+ }
406
+ return false;
407
+ }
382
408
  function buildCommitResult(ack) {
383
409
  const refUpdate = toRefUpdate(ack.result);
384
410
  if (!ack.result.success) {
@@ -570,6 +596,8 @@ function normalizeCommitOptions(options) {
570
596
  commitMessage: options.commitMessage,
571
597
  expectedHeadSha: options.expectedHeadSha,
572
598
  baseBranch: options.baseBranch,
599
+ ephemeral: options.ephemeral === true,
600
+ ephemeralBase: options.ephemeralBase === true,
573
601
  author: options.author,
574
602
  committer: options.committer,
575
603
  signal: options.signal,
@@ -1282,6 +1310,9 @@ var RepoImpl = class {
1282
1310
  if (options.ref) {
1283
1311
  params.ref = options.ref;
1284
1312
  }
1313
+ if (typeof options.ephemeral === "boolean") {
1314
+ params.ephemeral = String(options.ephemeral);
1315
+ }
1285
1316
  return this.api.get({ path: "repos/file", params }, jwt);
1286
1317
  }
1287
1318
  async listFiles(options) {
@@ -1290,8 +1321,17 @@ var RepoImpl = class {
1290
1321
  permissions: ["git:read"],
1291
1322
  ttl
1292
1323
  });
1293
- const params = options?.ref ? { ref: options.ref } : void 0;
1294
- const response = await this.api.get({ path: "repos/files", params }, jwt);
1324
+ const params = {};
1325
+ if (options?.ref) {
1326
+ params.ref = options.ref;
1327
+ }
1328
+ if (typeof options?.ephemeral === "boolean") {
1329
+ params.ephemeral = String(options.ephemeral);
1330
+ }
1331
+ const response = await this.api.get(
1332
+ { path: "repos/files", params: Object.keys(params).length ? params : void 0 },
1333
+ jwt
1334
+ );
1295
1335
  const raw = listFilesResponseSchema.parse(await response.json());
1296
1336
  return { paths: raw.paths, ref: raw.ref };
1297
1337
  }