@pithy-sh/storage 0.1.2 → 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/capability.d.ts +45 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +76 -0
- package/dist/config/config.d.ts +27 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +49 -0
- package/dist/data/share.d.ts +27 -0
- package/dist/data/share.d.ts.map +1 -0
- package/dist/data/share.js +28 -0
- package/dist/data/storageObject.d.ts +55 -0
- package/dist/data/storageObject.d.ts.map +1 -0
- package/dist/data/storageObject.js +44 -0
- package/dist/data/tables.d.ts +23 -0
- package/dist/data/tables.d.ts.map +1 -0
- package/dist/data/tables.js +26 -0
- package/dist/error/errors.d.ts +60 -0
- package/dist/error/errors.d.ts.map +1 -0
- package/dist/error/errors.js +89 -0
- package/dist/http/guard.d.ts +20 -0
- package/dist/http/guard.d.ts.map +1 -0
- package/dist/http/guard.js +29 -0
- package/dist/http/handlers.d.ts +232 -0
- package/dist/http/handlers.d.ts.map +1 -0
- package/dist/http/handlers.js +507 -0
- package/dist/http/routes.d.ts +70 -0
- package/dist/http/routes.d.ts.map +1 -0
- package/dist/http/routes.js +135 -0
- package/dist/http/schemas.d.ts +74 -0
- package/dist/http/schemas.d.ts.map +1 -0
- package/dist/http/schemas.js +93 -0
- package/dist/http/serve.d.ts +121 -0
- package/dist/http/serve.d.ts.map +1 -0
- package/dist/http/serve.js +209 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/migrations/0001_objects.d.ts +24 -0
- package/dist/migrations/0001_objects.d.ts.map +1 -0
- package/dist/migrations/0001_objects.js +41 -0
- package/dist/object/cloudflare.d.ts +23 -0
- package/dist/object/cloudflare.d.ts.map +1 -0
- package/dist/object/cloudflare.js +48 -0
- package/dist/object/key.d.ts +29 -0
- package/dist/object/key.d.ts.map +1 -0
- package/dist/object/key.js +37 -0
- package/dist/object/multipart.d.ts +78 -0
- package/dist/object/multipart.d.ts.map +1 -0
- package/dist/object/multipart.js +131 -0
- package/dist/object/store.d.ts +203 -0
- package/dist/object/store.d.ts.map +1 -0
- package/dist/object/store.js +178 -0
- package/dist/provision/provisionStorage.d.ts +139 -0
- package/dist/provision/provisionStorage.d.ts.map +1 -0
- package/dist/provision/provisionStorage.js +112 -0
- package/dist/provision/resolveStorageConfig.d.ts +45 -0
- package/dist/provision/resolveStorageConfig.d.ts.map +1 -0
- package/dist/provision/resolveStorageConfig.js +33 -0
- package/dist/quota/quota.d.ts +127 -0
- package/dist/quota/quota.d.ts.map +1 -0
- package/dist/quota/quota.js +102 -0
- package/dist/secret/registry.d.ts +72 -0
- package/dist/secret/registry.d.ts.map +1 -0
- package/dist/secret/registry.js +84 -0
- package/dist/seeds/example.d.ts +5 -0
- package/dist/seeds/example.d.ts.map +1 -0
- package/dist/seeds/example.js +111 -0
- package/dist/test-utils/liveStorage.d.ts +52 -0
- package/dist/test-utils/liveStorage.d.ts.map +1 -0
- package/dist/test-utils/liveStorage.js +198 -0
- package/dist/version.generated.d.ts +7 -0
- package/dist/version.generated.d.ts.map +1 -0
- package/dist/version.generated.js +9 -0
- package/dist/workflows/retryPolicy.d.ts +39 -0
- package/dist/workflows/retryPolicy.d.ts.map +1 -0
- package/dist/workflows/retryPolicy.js +43 -0
- package/dist/workflows/specs.d.ts +57 -0
- package/dist/workflows/specs.d.ts.map +1 -0
- package/dist/workflows/specs.js +60 -0
- package/dist/workflows/sweep.d.ts +84 -0
- package/dist/workflows/sweep.d.ts.map +1 -0
- package/dist/workflows/sweep.js +145 -0
- package/dist/workflows/worker.d.ts +51 -0
- package/dist/workflows/worker.d.ts.map +1 -0
- package/dist/workflows/worker.js +52 -0
- package/package.json +22 -11
- package/src/version.generated.ts +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* The package entrypoint — the surface `pithy add storage` wires into `pithy.config.ts`.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately narrow: the capability factory and its config, the {@link ObjectStore} seam another
|
|
7
|
+
* capability holds to move bytes (`@pithy-sh/media` is the first), the registry factory that makes a
|
|
8
|
+
* second bucket's credentials resolvable, and the table schemas an adopter reads rows against. Every
|
|
9
|
+
* other module is imported by deep path (`@pithy-sh/storage/src/...`); this is the documented
|
|
10
|
+
* contract, not a barrel over the package.
|
|
11
|
+
*/
|
|
12
|
+
export { isStorageCapability, STORAGE_MIGRATION_ORDER, type StorageCapability, type StorageOptions, storage, } from "./capability";
|
|
13
|
+
export { maxObjectBytes, StorageConfig, type StorageConfigInput, StorageQuota } from "./config/config";
|
|
14
|
+
export { StorageShare } from "./data/share";
|
|
15
|
+
export { StorageObject, StorageObjectStatus, StorageVisibility } from "./data/storageObject";
|
|
16
|
+
export { STORAGE_OBJECTS_TABLE, STORAGE_SHARES_TABLE, type StorageDatabase, storageDatabase } from "./data/tables";
|
|
17
|
+
export { deriveObjectKey, isDerivedObjectKey, OBJECT_KEY_PREFIX } from "./object/key";
|
|
18
|
+
export { collectParts, MultipartPlan, needsMultipart, PartPlan, planMultipart, ReportedPart } from "./object/multipart";
|
|
19
|
+
export { ObjectListing, ObjectMetadata, type ObjectStore, type ObjectStoreOptions, objectStore, type PresignedObjects, } from "./object/store";
|
|
20
|
+
export { R2StorageCredentials, r2CredentialsRegistry, STORAGE_R2_SECRET, storageSecretsRegistry, } from "./secret/registry";
|
|
21
|
+
export { STORAGE_CAPABILITY, StorageSweepParams, storageWorkflows } from "./workflows/specs";
|
|
22
|
+
export { type SweepDeps, type SweepResult, sweepStorage } from "./workflows/sweep";
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,OAAO,GACR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACvG,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC7F,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,KAAK,eAAe,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACnH,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACxH,OAAO,EACL,aAAa,EACb,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,WAAW,EACX,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { StorageObject, StorageObjectStatus, StorageVisibility } from "./data/storageObject.js";
|
|
4
|
+
import { MultipartPlan, PartPlan, ReportedPart, collectParts, needsMultipart, planMultipart } from "./object/multipart.js";
|
|
5
|
+
import { StorageConfig, StorageQuota, maxObjectBytes } from "./config/config.js";
|
|
6
|
+
import { StorageShare } from "./data/share.js";
|
|
7
|
+
import { STORAGE_OBJECTS_TABLE, STORAGE_SHARES_TABLE, storageDatabase } from "./data/tables.js";
|
|
8
|
+
import { R2StorageCredentials, STORAGE_R2_SECRET, r2CredentialsRegistry, storageSecretsRegistry } from "./secret/registry.js";
|
|
9
|
+
import { ObjectListing, ObjectMetadata, objectStore } from "./object/store.js";
|
|
10
|
+
import { OBJECT_KEY_PREFIX, deriveObjectKey, isDerivedObjectKey } from "./object/key.js";
|
|
11
|
+
import { STORAGE_CAPABILITY, StorageSweepParams, storageWorkflows } from "./workflows/specs.js";
|
|
12
|
+
import { STORAGE_MIGRATION_ORDER, isStorageCapability, storage } from "./capability.js";
|
|
13
|
+
import { sweepStorage } from "./workflows/sweep.js";
|
|
14
|
+
export { MultipartPlan, OBJECT_KEY_PREFIX, ObjectListing, ObjectMetadata, PartPlan, R2StorageCredentials, ReportedPart, STORAGE_CAPABILITY, STORAGE_MIGRATION_ORDER, STORAGE_OBJECTS_TABLE, STORAGE_R2_SECRET, STORAGE_SHARES_TABLE, StorageConfig, StorageObject, StorageObjectStatus, StorageQuota, StorageShare, StorageSweepParams, StorageVisibility, collectParts, deriveObjectKey, isDerivedObjectKey, isStorageCapability, maxObjectBytes, needsMultipart, objectStore, planMultipart, r2CredentialsRegistry, storage, storageDatabase, storageSecretsRegistry, storageWorkflows, sweepStorage };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { Migration } from "kysely/migration";
|
|
4
|
+
/**
|
|
5
|
+
* The storage tables: stored objects, and the revocable share links that point at them.
|
|
6
|
+
*
|
|
7
|
+
* camelCase identifiers; `CamelCasePlugin` snake-cases them in the DDL. `down` is the tested inverse,
|
|
8
|
+
* dropping indexes before their tables and the child table before its parent.
|
|
9
|
+
*
|
|
10
|
+
* Three constraints carry weight.
|
|
11
|
+
*
|
|
12
|
+
* `key` is `UNIQUE`. Keys are server-derived UUIDs, so a collision should be impossible — which is
|
|
13
|
+
* exactly why the database should say so. If one ever appears, the insert fails rather than two rows
|
|
14
|
+
* quietly sharing one object's bytes and one deletion orphaning the other.
|
|
15
|
+
*
|
|
16
|
+
* `status` and `visibility` are `CHECK`ed against their enums. The Zod schemas already validate on the
|
|
17
|
+
* way in, but the database is the last line: a hand-run `UPDATE` during an incident cannot leave a row
|
|
18
|
+
* in a state the code has no branch for, and `visibility` in particular is an authorization input.
|
|
19
|
+
*
|
|
20
|
+
* The shares foreign key is `ON DELETE CASCADE`. A share link to a deleted object is not merely stale,
|
|
21
|
+
* it is a dangling authorization; letting the database remove it means no delete path can forget to.
|
|
22
|
+
*/
|
|
23
|
+
export declare const storage_0001_objects: Migration;
|
|
24
|
+
//# sourceMappingURL=0001_objects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"0001_objects.d.ts","sourceRoot":"","sources":["../../src/migrations/0001_objects.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,oBAAoB,EAAE,SA4DlC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { sql } from "kysely";
|
|
4
|
+
//#region src/migrations/0001_objects.ts
|
|
5
|
+
/**
|
|
6
|
+
* The storage tables: stored objects, and the revocable share links that point at them.
|
|
7
|
+
*
|
|
8
|
+
* camelCase identifiers; `CamelCasePlugin` snake-cases them in the DDL. `down` is the tested inverse,
|
|
9
|
+
* dropping indexes before their tables and the child table before its parent.
|
|
10
|
+
*
|
|
11
|
+
* Three constraints carry weight.
|
|
12
|
+
*
|
|
13
|
+
* `key` is `UNIQUE`. Keys are server-derived UUIDs, so a collision should be impossible — which is
|
|
14
|
+
* exactly why the database should say so. If one ever appears, the insert fails rather than two rows
|
|
15
|
+
* quietly sharing one object's bytes and one deletion orphaning the other.
|
|
16
|
+
*
|
|
17
|
+
* `status` and `visibility` are `CHECK`ed against their enums. The Zod schemas already validate on the
|
|
18
|
+
* way in, but the database is the last line: a hand-run `UPDATE` during an incident cannot leave a row
|
|
19
|
+
* in a state the code has no branch for, and `visibility` in particular is an authorization input.
|
|
20
|
+
*
|
|
21
|
+
* The shares foreign key is `ON DELETE CASCADE`. A share link to a deleted object is not merely stale,
|
|
22
|
+
* it is a dangling authorization; letting the database remove it means no delete path can forget to.
|
|
23
|
+
*/
|
|
24
|
+
const storage_0001_objects = {
|
|
25
|
+
up: async (db) => {
|
|
26
|
+
await db.schema.createTable("pithyStorageObjects").addColumn("id", "text", (c) => c.primaryKey()).addColumn("key", "text", (c) => c.notNull().unique()).addColumn("path", "text", (c) => c.notNull()).addColumn("ownerId", "text").addColumn("contentType", "text", (c) => c.notNull()).addColumn("size", "integer").addColumn("visibility", "text", (c) => c.notNull().defaultTo("private")).addColumn("checksum", "text").addColumn("status", "text", (c) => c.notNull().defaultTo("pending")).addColumn("uploadId", "text").addColumn("createdAt", "integer", (c) => c.notNull()).addColumn("updatedAt", "integer", (c) => c.notNull()).addCheckConstraint("pithyStorageObjectsVisibility", sql`visibility IN ('private', 'public')`).addCheckConstraint("pithyStorageObjectsStatus", sql`status IN ('pending', 'stored', 'failed')`).execute();
|
|
27
|
+
await db.schema.createIndex("pithyStorageObjectsOwnerPathIdx").on("pithyStorageObjects").columns(["ownerId", "path"]).execute();
|
|
28
|
+
await db.schema.createIndex("pithyStorageObjectsStatusIdx").on("pithyStorageObjects").columns(["status", "createdAt"]).execute();
|
|
29
|
+
await db.schema.createTable("pithyStorageShares").addColumn("token", "text", (c) => c.primaryKey()).addColumn("objectId", "text", (c) => c.notNull()).addColumn("expiresAt", "integer").addColumn("revokedAt", "integer").addColumn("createdAt", "integer", (c) => c.notNull()).addForeignKeyConstraint("pithyStorageSharesObjectFk", ["objectId"], "pithyStorageObjects", ["id"], (fk) => fk.onDelete("cascade")).execute();
|
|
30
|
+
await db.schema.createIndex("pithyStorageSharesObjectIdx").on("pithyStorageShares").columns(["objectId"]).execute();
|
|
31
|
+
},
|
|
32
|
+
down: async (db) => {
|
|
33
|
+
await db.schema.dropIndex("pithyStorageSharesObjectIdx").execute();
|
|
34
|
+
await db.schema.dropTable("pithyStorageShares").execute();
|
|
35
|
+
await db.schema.dropIndex("pithyStorageObjectsStatusIdx").execute();
|
|
36
|
+
await db.schema.dropIndex("pithyStorageObjectsOwnerPathIdx").execute();
|
|
37
|
+
await db.schema.dropTable("pithyStorageObjects").execute();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { storage_0001_objects };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { CloudflareR2Manager } from "@pithy-sh/cloudflare/src/r2/r2Manager";
|
|
4
|
+
import type { R2StorageCredentials } from "../secret/registry";
|
|
5
|
+
import { type PresignedObjects } from "./store";
|
|
6
|
+
/**
|
|
7
|
+
* The SDK-friction boundary: the one file in this package that touches `@pithy-sh/cloudflare`.
|
|
8
|
+
*
|
|
9
|
+
* `store.ts` declares {@link PresignedObjects} as a structural port and never imports a manager, so
|
|
10
|
+
* the seam stays testable with no SDK and no network, and so the S3 client's shape can change without
|
|
11
|
+
* reaching the store. This adapter is the only thing that knows a `CloudflareR2Manager` exists.
|
|
12
|
+
*
|
|
13
|
+
* Every value crossing back is re-validated with the seam's own Zod objects — the manager's schemas
|
|
14
|
+
* are its contract, not ours, and a shape drift should fail here rather than three layers up.
|
|
15
|
+
*/
|
|
16
|
+
/** Adapt a {@link CloudflareR2Manager} to the {@link PresignedObjects} port. */
|
|
17
|
+
export declare function r2Manager(manager: CloudflareR2Manager): PresignedObjects;
|
|
18
|
+
/**
|
|
19
|
+
* The default port factory: build an R2 manager from the resolved credential bundle and adapt it.
|
|
20
|
+
* This is what `objectStore` calls when no `presigned` seam is injected.
|
|
21
|
+
*/
|
|
22
|
+
export declare function r2Presigned(credentials: R2StorageCredentials): PresignedObjects;
|
|
23
|
+
//# sourceMappingURL=cloudflare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../src/object/cloudflare.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,KAAK,gBAAgB,EAAgB,MAAM,SAAS,CAAC;AAE9D;;;;;;;;;GASG;AAEH,gFAAgF;AAChF,wBAAgB,SAAS,CAAC,OAAO,EAAE,mBAAmB,GAAG,gBAAgB,CAmBxE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,oBAAoB,GAAG,gBAAgB,CAU/E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { UploadedPart } from "./store.js";
|
|
4
|
+
import { CloudflareR2Manager } from "@pithy-sh/cloudflare/src/r2/r2Manager";
|
|
5
|
+
//#region src/object/cloudflare.ts
|
|
6
|
+
/**
|
|
7
|
+
* The SDK-friction boundary: the one file in this package that touches `@pithy-sh/cloudflare`.
|
|
8
|
+
*
|
|
9
|
+
* `store.ts` declares {@link PresignedObjects} as a structural port and never imports a manager, so
|
|
10
|
+
* the seam stays testable with no SDK and no network, and so the S3 client's shape can change without
|
|
11
|
+
* reaching the store. This adapter is the only thing that knows a `CloudflareR2Manager` exists.
|
|
12
|
+
*
|
|
13
|
+
* Every value crossing back is re-validated with the seam's own Zod objects — the manager's schemas
|
|
14
|
+
* are its contract, not ours, and a shape drift should fail here rather than three layers up.
|
|
15
|
+
*/
|
|
16
|
+
/** Adapt a {@link CloudflareR2Manager} to the {@link PresignedObjects} port. */
|
|
17
|
+
function r2Manager(manager) {
|
|
18
|
+
return {
|
|
19
|
+
presignPut: (key, contentType, contentLength, options) => manager.createUploadUrl(key, contentType, contentLength, { expiresIn: options?.expiresIn }),
|
|
20
|
+
presignGet: (key, options) => manager.createDownloadUrl(key, { expiresIn: options?.expiresIn }),
|
|
21
|
+
createMultipartUpload: (key, contentType) => manager.createMultipartUpload(key, contentType),
|
|
22
|
+
presignUploadPart: (key, uploadId, partNumber, options) => manager.presignUploadPart(key, uploadId, partNumber, {
|
|
23
|
+
expiresIn: options?.expiresIn,
|
|
24
|
+
contentLength: options?.contentLength
|
|
25
|
+
}),
|
|
26
|
+
completeMultipartUpload: (key, uploadId, parts) => manager.completeMultipartUpload(key, uploadId, parts),
|
|
27
|
+
abortMultipartUpload: (key, uploadId) => manager.abortMultipartUpload(key, uploadId),
|
|
28
|
+
async listParts(key, uploadId) {
|
|
29
|
+
return (await manager.listParts(key, uploadId)).map((part) => UploadedPart.parse(part));
|
|
30
|
+
},
|
|
31
|
+
copyObject: (sourceKey, destinationKey) => manager.copyObject(sourceKey, destinationKey)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The default port factory: build an R2 manager from the resolved credential bundle and adapt it.
|
|
36
|
+
* This is what `objectStore` calls when no `presigned` seam is injected.
|
|
37
|
+
*/
|
|
38
|
+
function r2Presigned(credentials) {
|
|
39
|
+
return r2Manager(new CloudflareR2Manager({
|
|
40
|
+
apiToken: credentials.apiToken,
|
|
41
|
+
accountId: credentials.accountId,
|
|
42
|
+
accessKeyId: credentials.accessKeyId,
|
|
43
|
+
secretAccessKey: credentials.secretAccessKey,
|
|
44
|
+
bucketName: credentials.bucket
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { r2Manager, r2Presigned };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* Key **policy** for the storage capability. It lives here, apart from {@link ObjectStore}, because
|
|
5
|
+
* the store is *mechanism*: it takes an explicit key and moves bytes, and knows nothing about how
|
|
6
|
+
* that key was chosen. Storage derives `obj/<uuid>`; `@pithy-sh/media` passes `media/<type>/<id>`.
|
|
7
|
+
* Neither package knows the other's scheme, which is exactly what lets media import the seam without
|
|
8
|
+
* inheriting storage's opaque-key decision.
|
|
9
|
+
*
|
|
10
|
+
* Why the key is server-derived and opaque. The client supplies a *logical* path
|
|
11
|
+
* (`invoices/2026/q3.pdf`) that is stored, indexed, and listed from D1; it never reaches R2. So a
|
|
12
|
+
* `../` cannot escape a prefix, two clients cannot collide on a name, and no client-controlled text
|
|
13
|
+
* is ever interpolated into a key. It also sidesteps R2's one-write-per-second-per-key limit by
|
|
14
|
+
* construction: every object gets its own key, so no two writes ever contend for one.
|
|
15
|
+
*/
|
|
16
|
+
/** Every key this capability derives starts here, so a bucket sweep can tell its objects from a co-tenant's. */
|
|
17
|
+
export declare const OBJECT_KEY_PREFIX = "obj/";
|
|
18
|
+
/** R2's hard limit on an object key, in bytes. A derived key is 40 bytes, so this guards pass-through keys only. */
|
|
19
|
+
export declare const MAX_OBJECT_KEY_BYTES = 1024;
|
|
20
|
+
/**
|
|
21
|
+
* A fresh opaque object key. UUIDv4 from the platform CSPRNG — unguessable, so a leaked key is not a
|
|
22
|
+
* directory listing, and unique, so a re-upload never overwrites a live object.
|
|
23
|
+
*/
|
|
24
|
+
export declare function deriveObjectKey(): string;
|
|
25
|
+
/** Whether `key` is one this capability derived. The sweep uses it to leave a co-tenant's objects alone. */
|
|
26
|
+
export declare function isDerivedObjectKey(key: string): boolean;
|
|
27
|
+
/** Whether `key` fits R2's 1,024-**byte** key limit. Measured in bytes, not characters — a key may be UTF-8. */
|
|
28
|
+
export declare function isValidObjectKey(key: string): boolean;
|
|
29
|
+
//# sourceMappingURL=key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key.d.ts","sourceRoot":"","sources":["../../src/object/key.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AAEH,gHAAgH;AAChH,eAAO,MAAM,iBAAiB,SAAS,CAAC;AAExC,oHAAoH;AACpH,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAEzC;;;GAGG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,4GAA4G;AAC5G,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED,gHAAgH;AAChH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
//#region src/object/key.ts
|
|
4
|
+
/**
|
|
5
|
+
* Key **policy** for the storage capability. It lives here, apart from {@link ObjectStore}, because
|
|
6
|
+
* the store is *mechanism*: it takes an explicit key and moves bytes, and knows nothing about how
|
|
7
|
+
* that key was chosen. Storage derives `obj/<uuid>`; `@pithy-sh/media` passes `media/<type>/<id>`.
|
|
8
|
+
* Neither package knows the other's scheme, which is exactly what lets media import the seam without
|
|
9
|
+
* inheriting storage's opaque-key decision.
|
|
10
|
+
*
|
|
11
|
+
* Why the key is server-derived and opaque. The client supplies a *logical* path
|
|
12
|
+
* (`invoices/2026/q3.pdf`) that is stored, indexed, and listed from D1; it never reaches R2. So a
|
|
13
|
+
* `../` cannot escape a prefix, two clients cannot collide on a name, and no client-controlled text
|
|
14
|
+
* is ever interpolated into a key. It also sidesteps R2's one-write-per-second-per-key limit by
|
|
15
|
+
* construction: every object gets its own key, so no two writes ever contend for one.
|
|
16
|
+
*/
|
|
17
|
+
/** Every key this capability derives starts here, so a bucket sweep can tell its objects from a co-tenant's. */
|
|
18
|
+
const OBJECT_KEY_PREFIX = "obj/";
|
|
19
|
+
/** R2's hard limit on an object key, in bytes. A derived key is 40 bytes, so this guards pass-through keys only. */
|
|
20
|
+
const MAX_OBJECT_KEY_BYTES = 1024;
|
|
21
|
+
/**
|
|
22
|
+
* A fresh opaque object key. UUIDv4 from the platform CSPRNG — unguessable, so a leaked key is not a
|
|
23
|
+
* directory listing, and unique, so a re-upload never overwrites a live object.
|
|
24
|
+
*/
|
|
25
|
+
function deriveObjectKey() {
|
|
26
|
+
return `${OBJECT_KEY_PREFIX}${crypto.randomUUID()}`;
|
|
27
|
+
}
|
|
28
|
+
/** Whether `key` is one this capability derived. The sweep uses it to leave a co-tenant's objects alone. */
|
|
29
|
+
function isDerivedObjectKey(key) {
|
|
30
|
+
return key.startsWith(OBJECT_KEY_PREFIX);
|
|
31
|
+
}
|
|
32
|
+
/** Whether `key` fits R2's 1,024-**byte** key limit. Measured in bytes, not characters — a key may be UTF-8. */
|
|
33
|
+
function isValidObjectKey(key) {
|
|
34
|
+
return key.length > 0 && new TextEncoder().encode(key).length <= 1024;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { MAX_OBJECT_KEY_BYTES, OBJECT_KEY_PREFIX, deriveObjectKey, isDerivedObjectKey, isValidObjectKey };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
/**
|
|
5
|
+
* Part orchestration for a multipart upload: how many parts, how big, and how the ETags the client
|
|
6
|
+
* reports back are turned into a completion list R2 will accept.
|
|
7
|
+
*
|
|
8
|
+
* **Why multipart at all.** A single presigned PUT is capped at 5 GiB, and it is not resumable — a
|
|
9
|
+
* dropped connection at 4 GiB starts over. Multipart raises the ceiling and makes a lost client
|
|
10
|
+
* cheap: `GET /storage/:id/parts` re-lists what R2 holds and re-presigns the rest, so the client
|
|
11
|
+
* sends only what is missing. The server holds no transfer state beyond the pending row.
|
|
12
|
+
*
|
|
13
|
+
* **The defaults and the ceiling they imply.** Threshold 100 MiB, part size 64 MiB. R2 allows at
|
|
14
|
+
* most 10,000 parts, so 10,000 × 64 MiB is a documented practical ceiling of ~625 GiB per object.
|
|
15
|
+
* That is well short of R2's own 4.995 TiB object cap (and its 4.995 GiB single-part cap); an
|
|
16
|
+
* adopter storing objects larger than ~625 GiB raises `partSizeBytes` in `pithy.config.ts` and gets
|
|
17
|
+
* a proportionally higher ceiling. The trade is deliberate: a bigger default part size would make
|
|
18
|
+
* every ordinary upload retry more expensive to serve a size almost nobody stores.
|
|
19
|
+
*
|
|
20
|
+
* **The 5 MiB floor** applies to every part but the last, and is S3's rule, not ours — R2 rejects a
|
|
21
|
+
* completion whose non-final part is smaller. Enforcing it here means the failure lands at plan time
|
|
22
|
+
* with a config-shaped message, rather than after the client has spent bandwidth on every part.
|
|
23
|
+
*/
|
|
24
|
+
/** Above this many bytes an upload goes multipart. Below it, one presigned PUT is simpler and cheaper. */
|
|
25
|
+
export declare const DEFAULT_MULTIPART_THRESHOLD_BYTES: number;
|
|
26
|
+
/** Default bytes per part. With R2's 10,000-part cap this sets the ~625 GiB practical object ceiling. */
|
|
27
|
+
export declare const DEFAULT_PART_SIZE_BYTES: number;
|
|
28
|
+
/** S3's floor for every part but the last. R2 rejects a completion that breaks it. */
|
|
29
|
+
export declare const MIN_PART_SIZE_BYTES: number;
|
|
30
|
+
/** R2's per-part ceiling — the same 5 GiB that caps a single-part upload. */
|
|
31
|
+
export declare const MAX_PART_SIZE_BYTES: number;
|
|
32
|
+
/** R2's hard cap on parts in one multipart upload. */
|
|
33
|
+
export declare const MAX_UPLOAD_PARTS = 10000;
|
|
34
|
+
/** One planned part: which number it is, where it starts, and how many bytes it carries. */
|
|
35
|
+
export declare const PartPlan: z.ZodObject<{
|
|
36
|
+
partNumber: z.ZodNumber;
|
|
37
|
+
offset: z.ZodNumber;
|
|
38
|
+
length: z.ZodNumber;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
export type PartPlan = z.output<typeof PartPlan>;
|
|
41
|
+
/** The whole plan for one object: the part size in force and every part it decomposes into. */
|
|
42
|
+
export declare const MultipartPlan: z.ZodObject<{
|
|
43
|
+
partSize: z.ZodNumber;
|
|
44
|
+
partCount: z.ZodNumber;
|
|
45
|
+
parts: z.ZodArray<z.ZodObject<{
|
|
46
|
+
partNumber: z.ZodNumber;
|
|
47
|
+
offset: z.ZodNumber;
|
|
48
|
+
length: z.ZodNumber;
|
|
49
|
+
}, z.core.$strip>>;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
export type MultipartPlan = z.output<typeof MultipartPlan>;
|
|
52
|
+
/** One part as the client reports it back after its PUT: the number it uploaded and the ETag R2 answered with. */
|
|
53
|
+
export declare const ReportedPart: z.ZodObject<{
|
|
54
|
+
partNumber: z.ZodNumber;
|
|
55
|
+
etag: z.ZodString;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
export type ReportedPart = z.output<typeof ReportedPart>;
|
|
58
|
+
/** Whether an upload of `size` bytes should go multipart under `threshold`. */
|
|
59
|
+
export declare function needsMultipart(size: number, threshold?: number): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Split `size` bytes into parts of `partSize`.
|
|
62
|
+
*
|
|
63
|
+
* Throws `storage/multipart_failed` when the plan cannot exist: a part size outside R2's 5 MiB–5 GiB
|
|
64
|
+
* window, or a size that needs more than 10,000 parts. Both are configuration faults surfaced at
|
|
65
|
+
* plan time — before a client has uploaded anything against a plan R2 would refuse to complete.
|
|
66
|
+
*/
|
|
67
|
+
export declare function planMultipart(size: number, partSize?: number): MultipartPlan;
|
|
68
|
+
/**
|
|
69
|
+
* Turn the parts a client reports into the list R2's completion call takes: validated, deduplicated,
|
|
70
|
+
* and ascending.
|
|
71
|
+
*
|
|
72
|
+
* Sorting is not cosmetic — S3 rejects an out-of-order part list, and the order concurrent PUTs
|
|
73
|
+
* finish in is not the order the parts belong in. A gap, a duplicate, or a count that disagrees with
|
|
74
|
+
* the plan is refused here rather than sent to R2, because R2's own rejection arrives as an opaque
|
|
75
|
+
* SDK fault with nothing in it a client could act on.
|
|
76
|
+
*/
|
|
77
|
+
export declare function collectParts(reported: readonly ReportedPart[], expectedCount: number): ReportedPart[];
|
|
78
|
+
//# sourceMappingURL=multipart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipart.d.ts","sourceRoot":"","sources":["../../src/object/multipart.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,0GAA0G;AAC1G,eAAO,MAAM,iCAAiC,QAAoB,CAAC;AAEnE,yGAAyG;AACzG,eAAO,MAAM,uBAAuB,QAAmB,CAAC;AAExD,sFAAsF;AACtF,eAAO,MAAM,mBAAmB,QAAkB,CAAC;AAEnD,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,QAAyB,CAAC;AAE1D,sDAAsD;AACtD,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAEvC,4FAA4F;AAC5F,eAAO,MAAM,QAAQ;;;;iBAMmF,CAAC;AACzG,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEjD,+FAA+F;AAC/F,eAAO,MAAM,aAAa;;;;;;;;iBAMwE,CAAC;AACnG,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;AAE3D,kHAAkH;AAClH,eAAO,MAAM,YAAY;;;iBAK4E,CAAC;AACtG,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAEzD,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAA0C,GAAG,OAAO,CAE3G;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAgC,GAAG,aAAa,CAgCrG;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,EAAE,aAAa,EAAE,MAAM,GAAG,YAAY,EAAE,CAuCrG"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import { StorageMultipartFailedError } from "../error/errors.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region src/object/multipart.ts
|
|
6
|
+
/**
|
|
7
|
+
* Part orchestration for a multipart upload: how many parts, how big, and how the ETags the client
|
|
8
|
+
* reports back are turned into a completion list R2 will accept.
|
|
9
|
+
*
|
|
10
|
+
* **Why multipart at all.** A single presigned PUT is capped at 5 GiB, and it is not resumable — a
|
|
11
|
+
* dropped connection at 4 GiB starts over. Multipart raises the ceiling and makes a lost client
|
|
12
|
+
* cheap: `GET /storage/:id/parts` re-lists what R2 holds and re-presigns the rest, so the client
|
|
13
|
+
* sends only what is missing. The server holds no transfer state beyond the pending row.
|
|
14
|
+
*
|
|
15
|
+
* **The defaults and the ceiling they imply.** Threshold 100 MiB, part size 64 MiB. R2 allows at
|
|
16
|
+
* most 10,000 parts, so 10,000 × 64 MiB is a documented practical ceiling of ~625 GiB per object.
|
|
17
|
+
* That is well short of R2's own 4.995 TiB object cap (and its 4.995 GiB single-part cap); an
|
|
18
|
+
* adopter storing objects larger than ~625 GiB raises `partSizeBytes` in `pithy.config.ts` and gets
|
|
19
|
+
* a proportionally higher ceiling. The trade is deliberate: a bigger default part size would make
|
|
20
|
+
* every ordinary upload retry more expensive to serve a size almost nobody stores.
|
|
21
|
+
*
|
|
22
|
+
* **The 5 MiB floor** applies to every part but the last, and is S3's rule, not ours — R2 rejects a
|
|
23
|
+
* completion whose non-final part is smaller. Enforcing it here means the failure lands at plan time
|
|
24
|
+
* with a config-shaped message, rather than after the client has spent bandwidth on every part.
|
|
25
|
+
*/
|
|
26
|
+
/** Above this many bytes an upload goes multipart. Below it, one presigned PUT is simpler and cheaper. */
|
|
27
|
+
const DEFAULT_MULTIPART_THRESHOLD_BYTES = 104857600;
|
|
28
|
+
/** Default bytes per part. With R2's 10,000-part cap this sets the ~625 GiB practical object ceiling. */
|
|
29
|
+
const DEFAULT_PART_SIZE_BYTES = 67108864;
|
|
30
|
+
/** S3's floor for every part but the last. R2 rejects a completion that breaks it. */
|
|
31
|
+
const MIN_PART_SIZE_BYTES = 5242880;
|
|
32
|
+
/** R2's per-part ceiling — the same 5 GiB that caps a single-part upload. */
|
|
33
|
+
const MAX_PART_SIZE_BYTES = 5368709120;
|
|
34
|
+
/** R2's hard cap on parts in one multipart upload. */
|
|
35
|
+
const MAX_UPLOAD_PARTS = 1e4;
|
|
36
|
+
/** One planned part: which number it is, where it starts, and how many bytes it carries. */
|
|
37
|
+
const PartPlan = z.object({
|
|
38
|
+
partNumber: z.number().int().min(1).describe("The part's 1-based index. R2 requires them contiguous from 1."),
|
|
39
|
+
offset: z.number().int().nonnegative().describe("The part's first byte offset within the whole object."),
|
|
40
|
+
length: z.number().int().positive().describe("The part's byte count. Every part but the last is `partSize`.")
|
|
41
|
+
}).describe("One part of a planned multipart upload — the unit a client uploads and can re-send alone.");
|
|
42
|
+
/** The whole plan for one object: the part size in force and every part it decomposes into. */
|
|
43
|
+
const MultipartPlan = z.object({
|
|
44
|
+
partSize: z.number().int().min(MIN_PART_SIZE_BYTES).describe("Bytes per part, for every part but the last."),
|
|
45
|
+
partCount: z.number().int().min(1).describe("How many parts the object decomposes into."),
|
|
46
|
+
parts: z.array(PartPlan).min(1).describe("Every part, ascending by `partNumber`.")
|
|
47
|
+
}).describe("How one object is split for a multipart upload — the plan a client uploads against.");
|
|
48
|
+
/** One part as the client reports it back after its PUT: the number it uploaded and the ETag R2 answered with. */
|
|
49
|
+
const ReportedPart = z.object({
|
|
50
|
+
partNumber: z.number().int().min(1).max(MAX_UPLOAD_PARTS).describe("The part number this ETag belongs to."),
|
|
51
|
+
etag: z.string().min(1).describe("The `ETag` response header R2 returned for that part, verbatim.")
|
|
52
|
+
}).describe("One completed part, as the client reports it back — the input to completing an upload.");
|
|
53
|
+
/** Whether an upload of `size` bytes should go multipart under `threshold`. */
|
|
54
|
+
function needsMultipart(size, threshold = DEFAULT_MULTIPART_THRESHOLD_BYTES) {
|
|
55
|
+
return size > threshold;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Split `size` bytes into parts of `partSize`.
|
|
59
|
+
*
|
|
60
|
+
* Throws `storage/multipart_failed` when the plan cannot exist: a part size outside R2's 5 MiB–5 GiB
|
|
61
|
+
* window, or a size that needs more than 10,000 parts. Both are configuration faults surfaced at
|
|
62
|
+
* plan time — before a client has uploaded anything against a plan R2 would refuse to complete.
|
|
63
|
+
*/
|
|
64
|
+
function planMultipart(size, partSize = DEFAULT_PART_SIZE_BYTES) {
|
|
65
|
+
if (!Number.isInteger(size) || size <= 0) throw new StorageMultipartFailedError({
|
|
66
|
+
message: "An upload needs a positive size.",
|
|
67
|
+
action: "Declare the file's byte count when you start the upload.",
|
|
68
|
+
detail: `multipart plan requested for size ${size}`
|
|
69
|
+
});
|
|
70
|
+
if (!Number.isInteger(partSize) || partSize < 5242880 || partSize > 5368709120) throw new StorageMultipartFailedError({
|
|
71
|
+
message: "The configured part size is outside what R2 accepts.",
|
|
72
|
+
action: "Set `partSizeBytes` between 5 MiB and 5 GiB in pithy.config.ts.",
|
|
73
|
+
detail: `partSize ${partSize} is outside [${MIN_PART_SIZE_BYTES}, ${MAX_PART_SIZE_BYTES}]`
|
|
74
|
+
});
|
|
75
|
+
const partCount = Math.ceil(size / partSize);
|
|
76
|
+
if (partCount > 1e4) throw new StorageMultipartFailedError({
|
|
77
|
+
message: "That file is too large for the configured part size.",
|
|
78
|
+
action: `Raise \`partSizeBytes\` — R2 allows at most ${MAX_UPLOAD_PARTS} parts per upload.`,
|
|
79
|
+
detail: `size ${size} at partSize ${partSize} needs ${partCount} parts`
|
|
80
|
+
});
|
|
81
|
+
const parts = [];
|
|
82
|
+
for (let index = 0; index < partCount; index += 1) {
|
|
83
|
+
const offset = index * partSize;
|
|
84
|
+
parts.push({
|
|
85
|
+
partNumber: index + 1,
|
|
86
|
+
offset,
|
|
87
|
+
length: Math.min(partSize, size - offset)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
partSize,
|
|
92
|
+
partCount,
|
|
93
|
+
parts
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Turn the parts a client reports into the list R2's completion call takes: validated, deduplicated,
|
|
98
|
+
* and ascending.
|
|
99
|
+
*
|
|
100
|
+
* Sorting is not cosmetic — S3 rejects an out-of-order part list, and the order concurrent PUTs
|
|
101
|
+
* finish in is not the order the parts belong in. A gap, a duplicate, or a count that disagrees with
|
|
102
|
+
* the plan is refused here rather than sent to R2, because R2's own rejection arrives as an opaque
|
|
103
|
+
* SDK fault with nothing in it a client could act on.
|
|
104
|
+
*/
|
|
105
|
+
function collectParts(reported, expectedCount) {
|
|
106
|
+
const parsed = z.array(ReportedPart).safeParse(reported);
|
|
107
|
+
if (!parsed.success) throw new StorageMultipartFailedError({ detail: `reported parts failed validation: ${parsed.error.issues.map((i) => i.code).join(", ")}` });
|
|
108
|
+
const byNumber = /* @__PURE__ */ new Map();
|
|
109
|
+
for (const part of parsed.data) {
|
|
110
|
+
const existing = byNumber.get(part.partNumber);
|
|
111
|
+
if (existing !== void 0 && existing !== part.etag) throw new StorageMultipartFailedError({
|
|
112
|
+
message: "Part list is inconsistent.",
|
|
113
|
+
detail: `part ${part.partNumber} reported twice with different etags`
|
|
114
|
+
});
|
|
115
|
+
byNumber.set(part.partNumber, part.etag);
|
|
116
|
+
}
|
|
117
|
+
if (byNumber.size !== expectedCount) throw new StorageMultipartFailedError({
|
|
118
|
+
message: "The upload is missing parts. GET /storage/<id>/parts, then re-send the parts it reports missing.",
|
|
119
|
+
detail: `expected ${expectedCount} distinct parts, got ${byNumber.size}`
|
|
120
|
+
});
|
|
121
|
+
for (let partNumber = 1; partNumber <= expectedCount; partNumber += 1) if (!byNumber.has(partNumber)) throw new StorageMultipartFailedError({
|
|
122
|
+
message: "The upload is missing parts. GET /storage/<id>/parts, then re-send the parts it reports missing.",
|
|
123
|
+
detail: `part ${partNumber} was never reported`
|
|
124
|
+
});
|
|
125
|
+
return [...byNumber.entries()].map(([partNumber, etag]) => ({
|
|
126
|
+
partNumber,
|
|
127
|
+
etag
|
|
128
|
+
})).sort((a, b) => a.partNumber - b.partNumber);
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
export { DEFAULT_MULTIPART_THRESHOLD_BYTES, DEFAULT_PART_SIZE_BYTES, MAX_PART_SIZE_BYTES, MAX_UPLOAD_PARTS, MIN_PART_SIZE_BYTES, MultipartPlan, PartPlan, ReportedPart, collectParts, needsMultipart, planMultipart };
|