@pierre/storage 0.1.3 → 0.1.4
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 +19 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commit.ts +27 -2
package/src/commit.ts
CHANGED
|
@@ -275,7 +275,7 @@ export class FetchCommitTransport implements CommitTransport {
|
|
|
275
275
|
const bodyIterable = buildMessageIterable(request.metadata, request.blobs);
|
|
276
276
|
const body = toRequestBody(bodyIterable);
|
|
277
277
|
|
|
278
|
-
const
|
|
278
|
+
const init: RequestInit = {
|
|
279
279
|
method: 'POST',
|
|
280
280
|
headers: {
|
|
281
281
|
Authorization: `Bearer ${request.authorization}`,
|
|
@@ -284,7 +284,13 @@ export class FetchCommitTransport implements CommitTransport {
|
|
|
284
284
|
},
|
|
285
285
|
body: body as any,
|
|
286
286
|
signal: request.signal,
|
|
287
|
-
}
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
if (requiresDuplex(body)) {
|
|
290
|
+
(init as RequestInit & { duplex: 'half' }).duplex = 'half';
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const response = await fetch(this.url, init);
|
|
288
294
|
|
|
289
295
|
if (!response.ok) {
|
|
290
296
|
const { statusMessage, statusLabel, refUpdate } = await parseCommitPackError(response);
|
|
@@ -349,6 +355,25 @@ function buildMessageIterable(
|
|
|
349
355
|
};
|
|
350
356
|
}
|
|
351
357
|
|
|
358
|
+
function requiresDuplex(body: unknown): boolean {
|
|
359
|
+
if (!body || typeof body !== 'object') {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (typeof (body as { [Symbol.asyncIterator]?: unknown })[Symbol.asyncIterator] === 'function') {
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const readableStreamCtor = (globalThis as {
|
|
368
|
+
ReadableStream?: new (...args: unknown[]) => unknown;
|
|
369
|
+
}).ReadableStream;
|
|
370
|
+
if (readableStreamCtor && body instanceof readableStreamCtor) {
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
|
|
352
377
|
function buildCommitResult(ack: CommitPackAck): CommitResult {
|
|
353
378
|
const refUpdate = toRefUpdate(ack.result);
|
|
354
379
|
if (!ack.result.success) {
|