disk 0.8.14 → 0.8.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/README.md +57 -0
- package/dist/cli.js +427 -25
- package/dist/index.cjs +431 -25
- package/dist/index.d.cts +318 -8
- package/dist/index.d.ts +318 -8
- package/dist/index.js +429 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -100,7 +100,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
// src/version.ts
|
|
103
|
-
var VERSION = true ? "0.8.
|
|
103
|
+
var VERSION = true ? "0.8.16" : "0.0.0-dev";
|
|
104
104
|
var USER_AGENT = `archil-js/${VERSION}`;
|
|
105
105
|
|
|
106
106
|
// src/client.ts
|
|
@@ -176,6 +176,8 @@ var Disk = class {
|
|
|
176
176
|
_archilRegion;
|
|
177
177
|
/** Base URL for the S3-compatible API (port 9000 ingress). Empty if unset. */
|
|
178
178
|
_s3BaseUrl;
|
|
179
|
+
/** Lazily-constructed multipart namespace (see {@link multipart}). @internal */
|
|
180
|
+
_multipart;
|
|
179
181
|
/** @internal */
|
|
180
182
|
constructor(data, client, archilRegion, s3BaseUrl) {
|
|
181
183
|
this.id = data.id;
|
|
@@ -378,18 +380,105 @@ var Disk = class {
|
|
|
378
380
|
return await this.headObject(key) !== null;
|
|
379
381
|
}
|
|
380
382
|
/**
|
|
381
|
-
* Write an object to the disk
|
|
382
|
-
*
|
|
383
|
-
*
|
|
383
|
+
* Write an object to the disk via the S3-compatible API. Handles any size:
|
|
384
|
+
* bodies at or below `multipartThreshold` (defaults to `partSize`, i.e.
|
|
385
|
+
* 16 MiB) go through a single PutObject request; larger bodies are uploaded as
|
|
386
|
+
* a multipart upload — split into `partSize` parts, uploaded with bounded
|
|
387
|
+
* `concurrency` (default 4), and assembled. A failed part aborts the upload so
|
|
388
|
+
* nothing is left half-staged. For manual control over the multipart
|
|
389
|
+
* lifecycle, use the {@link multipart} namespace.
|
|
384
390
|
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
391
|
+
* Faster than exec for large files — no container overhead, no command-length
|
|
392
|
+
* limits. Returns the entity tag the server assigned (a multipart upload's tag
|
|
393
|
+
* is S3's `md5(concat(partMd5s))-N` form rather than a plain MD5).
|
|
394
|
+
*
|
|
395
|
+
* @param key Path on the disk (e.g. "reports/2026-01/data.json")
|
|
396
|
+
* @param body Contents as a string, Uint8Array/Buffer, or ArrayBuffer
|
|
397
|
+
* @param options Either a content-type string, or {@link PutObjectOptions}
|
|
398
|
+
* (`contentType`, `multipartThreshold`, `partSize`,
|
|
399
|
+
* `concurrency`). Content type defaults to
|
|
400
|
+
* "application/octet-stream".
|
|
401
|
+
*/
|
|
402
|
+
async putObject(key, body, options) {
|
|
403
|
+
const opts = typeof options === "string" ? { contentType: options } : options ?? {};
|
|
404
|
+
const contentType = opts.contentType ?? "application/octet-stream";
|
|
405
|
+
const partSize = Math.max(opts.partSize ?? DEFAULT_PART_SIZE, MIN_PART_SIZE);
|
|
406
|
+
const threshold = opts.multipartThreshold ?? partSize;
|
|
407
|
+
const bytes = toBytes(body);
|
|
408
|
+
if (bytes.length <= threshold) {
|
|
409
|
+
const resp = await this._s3Request("PUT", key, { body, contentType });
|
|
410
|
+
if (!resp.ok) {
|
|
411
|
+
throw parseS3Error("PutObject", resp.status, resp.statusText, decodeText(resp.body));
|
|
412
|
+
}
|
|
413
|
+
return { etag: resp.headers.get("etag") ?? void 0 };
|
|
414
|
+
}
|
|
415
|
+
return this._putMultipart(
|
|
416
|
+
key,
|
|
417
|
+
bytes,
|
|
418
|
+
contentType,
|
|
419
|
+
partSize,
|
|
420
|
+
Math.max(1, opts.concurrency ?? DEFAULT_UPLOAD_CONCURRENCY)
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Upload a large body through the multipart lifecycle: split into `partSize`
|
|
425
|
+
* parts, upload them with bounded concurrency, then complete — aborting the
|
|
426
|
+
* upload if any part fails so nothing is left half-staged. @internal
|
|
388
427
|
*/
|
|
389
|
-
async
|
|
390
|
-
const
|
|
428
|
+
async _putMultipart(key, bytes, contentType, partSize, concurrency) {
|
|
429
|
+
const effectivePartSize = effectiveUploadPartSize(bytes.length, partSize);
|
|
430
|
+
const mp = this.multipart;
|
|
431
|
+
const upload = await mp.create(key, contentType);
|
|
432
|
+
try {
|
|
433
|
+
const partCount = Math.ceil(bytes.length / effectivePartSize);
|
|
434
|
+
const parts = new Array(partCount);
|
|
435
|
+
let next = 0;
|
|
436
|
+
const worker = async () => {
|
|
437
|
+
for (; ; ) {
|
|
438
|
+
const index = next++;
|
|
439
|
+
if (index >= partCount) return;
|
|
440
|
+
const start = index * effectivePartSize;
|
|
441
|
+
const slice = bytes.subarray(start, Math.min(start + effectivePartSize, bytes.length));
|
|
442
|
+
parts[index] = await mp.uploadPart(key, upload.uploadId, index + 1, slice);
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, partCount) }, worker));
|
|
446
|
+
const done = await mp.complete(key, upload.uploadId, parts);
|
|
447
|
+
return { etag: done.etag };
|
|
448
|
+
} catch (err) {
|
|
449
|
+
await mp.abort(key, upload.uploadId).catch(() => {
|
|
450
|
+
});
|
|
451
|
+
throw err;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Append bytes to an object via the S3-compatible PutObject append extension
|
|
456
|
+
* (`?append=true`). If the object already exists the bytes are appended to it;
|
|
457
|
+
* if it doesn't, it is created. Returns the entity tag of the full object
|
|
458
|
+
* after the append.
|
|
459
|
+
*
|
|
460
|
+
* Each call may append at most 1 MiB — the server rejects a larger body with
|
|
461
|
+
* `EntityTooLarge`. To grow an object past that, append in chunks (or use
|
|
462
|
+
* {@link putObject} for a one-shot large write).
|
|
463
|
+
*
|
|
464
|
+
* Unlike most operations this is NOT auto-retried on a transient error:
|
|
465
|
+
* append isn't idempotent, so retrying a succeeded-but-unacknowledged append
|
|
466
|
+
* would duplicate the bytes. On a transient failure, re-append yourself only
|
|
467
|
+
* after confirming the object's size.
|
|
468
|
+
*
|
|
469
|
+
* @param key Path on the disk (e.g. "logs/app.log")
|
|
470
|
+
* @param body Bytes to append (string, Uint8Array/Buffer, or ArrayBuffer)
|
|
471
|
+
* @param contentType MIME type, applied only when the object is newly created.
|
|
472
|
+
*/
|
|
473
|
+
async appendObject(key, body, contentType = "application/octet-stream") {
|
|
474
|
+
const resp = await this._s3Request("PUT", key, {
|
|
475
|
+
body,
|
|
476
|
+
contentType,
|
|
477
|
+
query: { append: "true" },
|
|
478
|
+
retry: false
|
|
479
|
+
});
|
|
391
480
|
if (!resp.ok) {
|
|
392
|
-
throw parseS3Error("
|
|
481
|
+
throw parseS3Error("AppendObject", resp.status, resp.statusText, decodeText(resp.body));
|
|
393
482
|
}
|
|
394
483
|
return { etag: resp.headers.get("etag") ?? void 0 };
|
|
395
484
|
}
|
|
@@ -482,6 +571,50 @@ var Disk = class {
|
|
|
482
571
|
}
|
|
483
572
|
return parseListObjectsResult(decodeText(resp.body));
|
|
484
573
|
}
|
|
574
|
+
/**
|
|
575
|
+
* Delete up to many objects in a single S3-compatible DeleteObjects request.
|
|
576
|
+
* Unlike {@link deleteObject}, failures are reported per key rather than
|
|
577
|
+
* thrown: the result's `deleted` lists the keys that were removed and
|
|
578
|
+
* `errors` lists the ones that weren't (with the server's code/message). A
|
|
579
|
+
* key that didn't exist still counts as deleted, per S3 semantics.
|
|
580
|
+
*
|
|
581
|
+
* The server caps a single request at 1000 keys; this method transparently
|
|
582
|
+
* splits larger inputs into 1000-key batches and merges the results.
|
|
583
|
+
*
|
|
584
|
+
* @param keys Object keys to delete.
|
|
585
|
+
* @param opts `quiet` suppresses the per-key success list server-side.
|
|
586
|
+
*/
|
|
587
|
+
async deleteObjects(keys, opts = {}) {
|
|
588
|
+
const deleted = [];
|
|
589
|
+
const errors = [];
|
|
590
|
+
for (let i = 0; i < keys.length; i += MAX_DELETE_OBJECTS_PER_REQUEST) {
|
|
591
|
+
const batch = keys.slice(i, i + MAX_DELETE_OBJECTS_PER_REQUEST);
|
|
592
|
+
const xml = buildDeleteObjectsXml(batch, opts.quiet ?? false);
|
|
593
|
+
const resp = await this._s3Request("POST", "", {
|
|
594
|
+
query: { delete: "" },
|
|
595
|
+
body: xml,
|
|
596
|
+
contentType: "application/xml"
|
|
597
|
+
});
|
|
598
|
+
if (!resp.ok) {
|
|
599
|
+
throw parseS3Error("DeleteObjects", resp.status, resp.statusText, decodeText(resp.body));
|
|
600
|
+
}
|
|
601
|
+
const parsed = parseDeleteObjectsResult(decodeText(resp.body));
|
|
602
|
+
deleted.push(...parsed.deleted);
|
|
603
|
+
errors.push(...parsed.errors);
|
|
604
|
+
}
|
|
605
|
+
return { deleted, errors };
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* The advanced, opt-in multipart-upload API. Drive the raw lifecycle
|
|
609
|
+
* yourself — `create` → `uploadPart` → `complete` (or `abort`), plus
|
|
610
|
+
* `listParts` / `listUploads`. Most callers don't need this: {@link putObject}
|
|
611
|
+
* runs the whole lifecycle automatically for large bodies. Reach for it only
|
|
612
|
+
* when you need manual control (e.g. uploading parts from separate processes),
|
|
613
|
+
* and note you then own part-size, memory, and concurrency management.
|
|
614
|
+
*/
|
|
615
|
+
get multipart() {
|
|
616
|
+
return this._multipart ??= new DiskMultipart(this.id, this._s3Request.bind(this));
|
|
617
|
+
}
|
|
485
618
|
/**
|
|
486
619
|
* Send a single request to the disk's S3-compatible endpoint. This reuses the
|
|
487
620
|
* control-plane client purely for its credential and transport — the same
|
|
@@ -506,33 +639,55 @@ var Disk = class {
|
|
|
506
639
|
const trimmedKey = key.replace(/^\//, "");
|
|
507
640
|
const encodedKey = trimmedKey.split("/").map(encodeURIComponent).join("/");
|
|
508
641
|
const path = encodedKey ? `/${this.id}/${encodedKey}` : `/${this.id}`;
|
|
509
|
-
const
|
|
642
|
+
const init = {
|
|
510
643
|
baseUrl: this._s3BaseUrl,
|
|
511
644
|
parseAs: "stream",
|
|
512
645
|
...opts.query ? { params: { query: opts.query } } : {},
|
|
513
646
|
// fetch accepts string / Uint8Array / ArrayBuffer bodies directly; pass it
|
|
514
|
-
// through unchanged (no Node Buffer in the data path).
|
|
647
|
+
// through unchanged (no Node Buffer in the data path). Bodies are fully
|
|
648
|
+
// buffered (never streams), so re-sending one on a retry is safe.
|
|
515
649
|
...opts.body !== void 0 ? { body: opts.body, bodySerializer: (b) => b } : {},
|
|
516
650
|
...opts.contentType ? { headers: { "Content-Type": opts.contentType } } : {}
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
|
|
651
|
+
};
|
|
652
|
+
const hasBody = method === "GET" || method === "POST";
|
|
653
|
+
const maxRetries = opts.retry === false ? 0 : MAX_S3_RETRIES;
|
|
654
|
+
for (let attempt = 0; ; attempt++) {
|
|
655
|
+
let error;
|
|
656
|
+
let response;
|
|
657
|
+
try {
|
|
658
|
+
({ error, response } = await call(path, init));
|
|
659
|
+
} catch (transportError) {
|
|
660
|
+
if (attempt < maxRetries) {
|
|
661
|
+
await sleep(s3RetryDelayMs(attempt));
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
throw transportError;
|
|
665
|
+
}
|
|
666
|
+
if (!response.ok) {
|
|
667
|
+
if (isTransientS3Status(response.status) && attempt < maxRetries) {
|
|
668
|
+
await response.body?.cancel().catch(() => {
|
|
669
|
+
});
|
|
670
|
+
await sleep(s3RetryDelayMs(attempt));
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
const message = typeof error === "string" ? error : error ? JSON.stringify(error) : "";
|
|
674
|
+
return {
|
|
675
|
+
ok: false,
|
|
676
|
+
status: response.status,
|
|
677
|
+
statusText: response.statusText,
|
|
678
|
+
headers: response.headers,
|
|
679
|
+
body: new TextEncoder().encode(message)
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
const bytes = hasBody ? new Uint8Array(await response.arrayBuffer()) : new Uint8Array(0);
|
|
520
683
|
return {
|
|
521
|
-
ok:
|
|
684
|
+
ok: true,
|
|
522
685
|
status: response.status,
|
|
523
686
|
statusText: response.statusText,
|
|
524
687
|
headers: response.headers,
|
|
525
|
-
body:
|
|
688
|
+
body: bytes
|
|
526
689
|
};
|
|
527
690
|
}
|
|
528
|
-
const bytes = method === "GET" ? new Uint8Array(await response.arrayBuffer()) : new Uint8Array(0);
|
|
529
|
-
return {
|
|
530
|
-
ok: true,
|
|
531
|
-
status: response.status,
|
|
532
|
-
statusText: response.statusText,
|
|
533
|
-
headers: response.headers,
|
|
534
|
-
body: bytes
|
|
535
|
-
};
|
|
536
691
|
}
|
|
537
692
|
/**
|
|
538
693
|
* Connect to this disk's data plane via the native ArchilClient.
|
|
@@ -563,6 +718,199 @@ var Disk = class {
|
|
|
563
718
|
});
|
|
564
719
|
}
|
|
565
720
|
};
|
|
721
|
+
var DiskMultipart = class {
|
|
722
|
+
/** @internal */
|
|
723
|
+
constructor(diskId, s3Request) {
|
|
724
|
+
this.diskId = diskId;
|
|
725
|
+
this.s3Request = s3Request;
|
|
726
|
+
}
|
|
727
|
+
diskId;
|
|
728
|
+
s3Request;
|
|
729
|
+
/**
|
|
730
|
+
* Start a multipart upload (CreateMultipartUpload) and return its `uploadId`.
|
|
731
|
+
*
|
|
732
|
+
* @param key Path on the disk the finished object will live at.
|
|
733
|
+
* @param contentType MIME type to store the object with.
|
|
734
|
+
*/
|
|
735
|
+
async create(key, contentType) {
|
|
736
|
+
const resp = await this.s3Request("POST", key, { query: { uploads: "" }, contentType });
|
|
737
|
+
if (!resp.ok) {
|
|
738
|
+
throw parseS3Error("CreateMultipartUpload", resp.status, resp.statusText, decodeText(resp.body));
|
|
739
|
+
}
|
|
740
|
+
const root = parseXml(decodeText(resp.body)).InitiateMultipartUploadResult ?? {};
|
|
741
|
+
const uploadId = optionalString(root.UploadId);
|
|
742
|
+
if (!uploadId) {
|
|
743
|
+
throw new ArchilS3Error({
|
|
744
|
+
operation: "CreateMultipartUpload",
|
|
745
|
+
statusCode: resp.status,
|
|
746
|
+
message: "response did not contain an UploadId",
|
|
747
|
+
raw: decodeText(resp.body)
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
return {
|
|
751
|
+
uploadId,
|
|
752
|
+
key: optionalString(root.Key) ?? key,
|
|
753
|
+
bucket: optionalString(root.Bucket) ?? this.diskId
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Upload one part (UploadPart) and return its entity tag, which you must
|
|
758
|
+
* collect (with its part number) and pass to {@link complete}. Every part
|
|
759
|
+
* except the last must be at least 5 MiB.
|
|
760
|
+
*
|
|
761
|
+
* @param key The upload's object key.
|
|
762
|
+
* @param uploadId The id from {@link create}.
|
|
763
|
+
* @param partNumber 1-based part number (1..=10000).
|
|
764
|
+
* @param body Part contents as a string, Uint8Array/Buffer, or ArrayBuffer.
|
|
765
|
+
*/
|
|
766
|
+
async uploadPart(key, uploadId, partNumber, body) {
|
|
767
|
+
const resp = await this.s3Request("PUT", key, { query: { uploadId, partNumber }, body });
|
|
768
|
+
if (!resp.ok) {
|
|
769
|
+
throw parseS3Error("UploadPart", resp.status, resp.statusText, decodeText(resp.body));
|
|
770
|
+
}
|
|
771
|
+
return { partNumber, etag: resp.headers.get("etag") ?? "" };
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Finish a multipart upload (CompleteMultipartUpload), assembling the listed
|
|
775
|
+
* parts into one object. Parts are sorted by part number before submission
|
|
776
|
+
* (the server requires strictly-increasing order).
|
|
777
|
+
*
|
|
778
|
+
* Unlike the other operations this is NOT auto-retried on a transient error:
|
|
779
|
+
* the gateway isn't idempotent for completion, so a retry after a
|
|
780
|
+
* successful-but-unacknowledged complete would return a spurious NoSuchUpload.
|
|
781
|
+
* On a transient failure, re-drive completion yourself only after confirming
|
|
782
|
+
* the object isn't already present.
|
|
783
|
+
*
|
|
784
|
+
* @param key The upload's object key.
|
|
785
|
+
* @param uploadId The id from {@link create}.
|
|
786
|
+
* @param parts The `{ partNumber, etag }` pairs from {@link uploadPart}.
|
|
787
|
+
*/
|
|
788
|
+
async complete(key, uploadId, parts) {
|
|
789
|
+
const sorted = [...parts].sort((a, b) => a.partNumber - b.partNumber);
|
|
790
|
+
const xml = buildCompleteMultipartUploadXml(sorted);
|
|
791
|
+
const resp = await this.s3Request("POST", key, {
|
|
792
|
+
query: { uploadId },
|
|
793
|
+
body: xml,
|
|
794
|
+
contentType: "application/xml",
|
|
795
|
+
retry: false
|
|
796
|
+
});
|
|
797
|
+
if (!resp.ok) {
|
|
798
|
+
throw parseS3Error("CompleteMultipartUpload", resp.status, resp.statusText, decodeText(resp.body));
|
|
799
|
+
}
|
|
800
|
+
const root = parseXml(decodeText(resp.body)).CompleteMultipartUploadResult ?? {};
|
|
801
|
+
return {
|
|
802
|
+
etag: optionalString(root.ETag),
|
|
803
|
+
location: optionalString(root.Location),
|
|
804
|
+
bucket: optionalString(root.Bucket),
|
|
805
|
+
key: optionalString(root.Key)
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Abort a multipart upload (AbortMultipartUpload), discarding every staged
|
|
810
|
+
* part. Idempotent against an upload that's already gone (404 / NoSuchUpload
|
|
811
|
+
* resolves successfully).
|
|
812
|
+
*
|
|
813
|
+
* @param key The upload's object key.
|
|
814
|
+
* @param uploadId The id from {@link create}.
|
|
815
|
+
*/
|
|
816
|
+
async abort(key, uploadId) {
|
|
817
|
+
const resp = await this.s3Request("DELETE", key, { query: { uploadId } });
|
|
818
|
+
if (!resp.ok && resp.status !== 404) {
|
|
819
|
+
throw parseS3Error("AbortMultipartUpload", resp.status, resp.statusText, decodeText(resp.body));
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* List the parts already uploaded for an in-progress upload (ListParts).
|
|
824
|
+
* Returns a single page; follow `nextPartNumberMarker` (when `isTruncated`)
|
|
825
|
+
* to page through the rest.
|
|
826
|
+
*
|
|
827
|
+
* @param key The upload's object key.
|
|
828
|
+
* @param uploadId The id from {@link create}.
|
|
829
|
+
* @param opts `maxParts` / `partNumberMarker` pagination controls.
|
|
830
|
+
*/
|
|
831
|
+
async listParts(key, uploadId, opts = {}) {
|
|
832
|
+
const query = { uploadId };
|
|
833
|
+
if (opts.maxParts !== void 0) query["max-parts"] = opts.maxParts;
|
|
834
|
+
if (opts.partNumberMarker !== void 0) query["part-number-marker"] = opts.partNumberMarker;
|
|
835
|
+
const resp = await this.s3Request("GET", key, { query });
|
|
836
|
+
if (!resp.ok) {
|
|
837
|
+
throw parseS3Error("ListParts", resp.status, resp.statusText, decodeText(resp.body));
|
|
838
|
+
}
|
|
839
|
+
return parseListPartsResult(decodeText(resp.body));
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* List in-progress multipart uploads on the disk (ListMultipartUploads).
|
|
843
|
+
* Returns a single page; follow `nextKeyMarker` / `nextUploadIdMarker` (when
|
|
844
|
+
* `isTruncated`) for the rest.
|
|
845
|
+
*
|
|
846
|
+
* @param opts Prefix/delimiter filter and pagination markers.
|
|
847
|
+
*/
|
|
848
|
+
async listUploads(opts = {}) {
|
|
849
|
+
const query = { uploads: "" };
|
|
850
|
+
if (opts.prefix !== void 0) query.prefix = opts.prefix;
|
|
851
|
+
if (opts.delimiter !== void 0) query.delimiter = opts.delimiter;
|
|
852
|
+
if (opts.keyMarker !== void 0) query["key-marker"] = opts.keyMarker;
|
|
853
|
+
if (opts.uploadIdMarker !== void 0) query["upload-id-marker"] = opts.uploadIdMarker;
|
|
854
|
+
if (opts.maxUploads !== void 0) query["max-uploads"] = opts.maxUploads;
|
|
855
|
+
const resp = await this.s3Request("GET", "", { query });
|
|
856
|
+
if (!resp.ok) {
|
|
857
|
+
throw parseS3Error("ListMultipartUploads", resp.status, resp.statusText, decodeText(resp.body));
|
|
858
|
+
}
|
|
859
|
+
return parseListMultipartUploadsResult(decodeText(resp.body));
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
var MAX_DELETE_OBJECTS_PER_REQUEST = 1e3;
|
|
863
|
+
var MAX_S3_RETRIES = 3;
|
|
864
|
+
var S3_RETRY_BASE_MS = 100;
|
|
865
|
+
var S3_RETRY_CAP_MS = 2e3;
|
|
866
|
+
function isTransientS3Status(status) {
|
|
867
|
+
return status === 429 || status === 500 || status === 502 || status === 503 || status === 504;
|
|
868
|
+
}
|
|
869
|
+
function s3RetryDelayMs(attempt) {
|
|
870
|
+
const ceiling = Math.min(S3_RETRY_CAP_MS, S3_RETRY_BASE_MS * 2 ** attempt);
|
|
871
|
+
return Math.random() * ceiling;
|
|
872
|
+
}
|
|
873
|
+
function sleep(ms) {
|
|
874
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
875
|
+
}
|
|
876
|
+
var MIN_PART_SIZE = 5 * 1024 * 1024;
|
|
877
|
+
var DEFAULT_PART_SIZE = 16 * 1024 * 1024;
|
|
878
|
+
var DEFAULT_UPLOAD_CONCURRENCY = 4;
|
|
879
|
+
var MAX_PARTS_PER_UPLOAD = 1e4;
|
|
880
|
+
function effectiveUploadPartSize(totalBytes, requestedPartSize) {
|
|
881
|
+
if (Math.ceil(totalBytes / requestedPartSize) <= MAX_PARTS_PER_UPLOAD) {
|
|
882
|
+
return requestedPartSize;
|
|
883
|
+
}
|
|
884
|
+
const MiB = 1024 * 1024;
|
|
885
|
+
const needed = Math.ceil(totalBytes / MAX_PARTS_PER_UPLOAD);
|
|
886
|
+
return Math.ceil(needed / MiB) * MiB;
|
|
887
|
+
}
|
|
888
|
+
function toBytes(body) {
|
|
889
|
+
if (typeof body === "string") return new TextEncoder().encode(body);
|
|
890
|
+
if (body instanceof Uint8Array) return body;
|
|
891
|
+
return new Uint8Array(body);
|
|
892
|
+
}
|
|
893
|
+
function escapeXml(value) {
|
|
894
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
895
|
+
}
|
|
896
|
+
function buildDeleteObjectsXml(keys, quiet) {
|
|
897
|
+
const objects = keys.map((k) => `<Object><Key>${escapeXml(k)}</Key></Object>`).join("");
|
|
898
|
+
const quietTag = quiet ? "<Quiet>true</Quiet>" : "";
|
|
899
|
+
return `<?xml version="1.0" encoding="UTF-8"?><Delete>${objects}${quietTag}</Delete>`;
|
|
900
|
+
}
|
|
901
|
+
function buildCompleteMultipartUploadXml(parts) {
|
|
902
|
+
const body = parts.map(
|
|
903
|
+
(p) => `<Part><PartNumber>${p.partNumber}</PartNumber><ETag>${escapeXml(p.etag)}</ETag></Part>`
|
|
904
|
+
).join("");
|
|
905
|
+
return `<?xml version="1.0" encoding="UTF-8"?><CompleteMultipartUpload>${body}</CompleteMultipartUpload>`;
|
|
906
|
+
}
|
|
907
|
+
function asArray(value) {
|
|
908
|
+
if (value === void 0 || value === null) return [];
|
|
909
|
+
return Array.isArray(value) ? value : [value];
|
|
910
|
+
}
|
|
911
|
+
function optionalNumber(value) {
|
|
912
|
+
return value === void 0 || value === null ? void 0 : Number(value);
|
|
913
|
+
}
|
|
566
914
|
function optionalString(value) {
|
|
567
915
|
return value === void 0 || value === null ? void 0 : String(value);
|
|
568
916
|
}
|
|
@@ -591,6 +939,60 @@ function parseListObjectsResult(xml) {
|
|
|
591
939
|
prefix: optionalString(root.Prefix)
|
|
592
940
|
};
|
|
593
941
|
}
|
|
942
|
+
function xmlIsTruncated(value) {
|
|
943
|
+
return value === "true" || value === true;
|
|
944
|
+
}
|
|
945
|
+
function parseDeleteObjectsResult(xml) {
|
|
946
|
+
const root = parseXml(xml).DeleteResult ?? {};
|
|
947
|
+
const deleted = asArray(root.Deleted).map((d) => optionalString(d.Key)).filter((k) => k !== void 0);
|
|
948
|
+
const errors = asArray(root.Error).map((e) => ({
|
|
949
|
+
key: String(e.Key ?? ""),
|
|
950
|
+
code: optionalString(e.Code),
|
|
951
|
+
message: optionalString(e.Message)
|
|
952
|
+
}));
|
|
953
|
+
return { deleted, errors };
|
|
954
|
+
}
|
|
955
|
+
function parseListPartsResult(xml) {
|
|
956
|
+
const root = parseXml(xml).ListPartsResult ?? {};
|
|
957
|
+
const parts = asArray(root.Part).map((p) => ({
|
|
958
|
+
partNumber: Number(p.PartNumber ?? 0),
|
|
959
|
+
etag: optionalString(p.ETag),
|
|
960
|
+
size: Number(p.Size ?? 0),
|
|
961
|
+
lastModified: optionalDate(p.LastModified)
|
|
962
|
+
}));
|
|
963
|
+
return {
|
|
964
|
+
bucket: optionalString(root.Bucket),
|
|
965
|
+
key: optionalString(root.Key),
|
|
966
|
+
uploadId: optionalString(root.UploadId),
|
|
967
|
+
parts,
|
|
968
|
+
isTruncated: xmlIsTruncated(root.IsTruncated),
|
|
969
|
+
partNumberMarker: Number(root.PartNumberMarker ?? 0),
|
|
970
|
+
nextPartNumberMarker: optionalNumber(root.NextPartNumberMarker),
|
|
971
|
+
maxParts: Number(root.MaxParts ?? parts.length)
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
function parseListMultipartUploadsResult(xml) {
|
|
975
|
+
const root = parseXml(xml).ListMultipartUploadsResult ?? {};
|
|
976
|
+
const uploads = asArray(root.Upload).map((u) => ({
|
|
977
|
+
key: String(u.Key ?? ""),
|
|
978
|
+
uploadId: String(u.UploadId ?? ""),
|
|
979
|
+
initiated: optionalDate(u.Initiated)
|
|
980
|
+
}));
|
|
981
|
+
const commonPrefixes = asArray(root.CommonPrefixes).map((cp) => optionalString(cp.Prefix)).filter((p) => p !== void 0);
|
|
982
|
+
return {
|
|
983
|
+
bucket: optionalString(root.Bucket),
|
|
984
|
+
uploads,
|
|
985
|
+
commonPrefixes,
|
|
986
|
+
isTruncated: xmlIsTruncated(root.IsTruncated),
|
|
987
|
+
keyMarker: optionalString(root.KeyMarker),
|
|
988
|
+
uploadIdMarker: optionalString(root.UploadIdMarker),
|
|
989
|
+
nextKeyMarker: optionalString(root.NextKeyMarker),
|
|
990
|
+
nextUploadIdMarker: optionalString(root.NextUploadIdMarker),
|
|
991
|
+
prefix: optionalString(root.Prefix),
|
|
992
|
+
delimiter: optionalString(root.Delimiter),
|
|
993
|
+
maxUploads: optionalNumber(root.MaxUploads)
|
|
994
|
+
};
|
|
995
|
+
}
|
|
594
996
|
|
|
595
997
|
// src/disks.ts
|
|
596
998
|
var Disks = class {
|
|
@@ -783,6 +1185,7 @@ export {
|
|
|
783
1185
|
ArchilError,
|
|
784
1186
|
ArchilS3Error,
|
|
785
1187
|
Disk,
|
|
1188
|
+
DiskMultipart,
|
|
786
1189
|
Disks,
|
|
787
1190
|
Tokens,
|
|
788
1191
|
USER_AGENT,
|
|
@@ -791,6 +1194,7 @@ export {
|
|
|
791
1194
|
createApiKey,
|
|
792
1195
|
createDisk,
|
|
793
1196
|
deleteApiKey,
|
|
1197
|
+
effectiveUploadPartSize,
|
|
794
1198
|
exec,
|
|
795
1199
|
getDisk,
|
|
796
1200
|
listApiKeys,
|