@dads-framework/object-storage 0.0.0-stage → 0.1.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/LICENSE.md +21 -0
- package/README.md +32 -2
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/cloudfront-download-signer.d.ts +15 -0
- package/dist/lib/cloudfront-download-signer.d.ts.map +1 -0
- package/dist/lib/cloudfront-download-signer.js +61 -0
- package/dist/lib/cloudfront-download-signer.js.map +1 -0
- package/dist/lib/create-direct-transfer-storage.d.ts +13 -0
- package/dist/lib/create-direct-transfer-storage.d.ts.map +1 -0
- package/dist/lib/create-direct-transfer-storage.js +17 -0
- package/dist/lib/create-direct-transfer-storage.js.map +1 -0
- package/dist/lib/create-object-storage.d.ts +13 -0
- package/dist/lib/create-object-storage.d.ts.map +1 -0
- package/dist/lib/create-object-storage.js +15 -0
- package/dist/lib/create-object-storage.js.map +1 -0
- package/dist/lib/direct-transfer-storage.d.ts +92 -0
- package/dist/lib/direct-transfer-storage.d.ts.map +1 -0
- package/dist/lib/direct-transfer-storage.js +15 -0
- package/dist/lib/direct-transfer-storage.js.map +1 -0
- package/dist/lib/disk-direct-transfer-storage.d.ts +79 -0
- package/dist/lib/disk-direct-transfer-storage.d.ts.map +1 -0
- package/dist/lib/disk-direct-transfer-storage.js +257 -0
- package/dist/lib/disk-direct-transfer-storage.js.map +1 -0
- package/dist/lib/disk-files.d.ts +67 -0
- package/dist/lib/disk-files.d.ts.map +1 -0
- package/dist/lib/disk-files.js +231 -0
- package/dist/lib/disk-files.js.map +1 -0
- package/dist/lib/disk-object-storage.d.ts +170 -0
- package/dist/lib/disk-object-storage.d.ts.map +1 -0
- package/dist/lib/disk-object-storage.js +382 -0
- package/dist/lib/disk-object-storage.js.map +1 -0
- package/dist/lib/disk-part-links.d.ts +52 -0
- package/dist/lib/disk-part-links.d.ts.map +1 -0
- package/dist/lib/disk-part-links.js +66 -0
- package/dist/lib/disk-part-links.js.map +1 -0
- package/dist/lib/disk-readiness-probe.d.ts +27 -0
- package/dist/lib/disk-readiness-probe.d.ts.map +1 -0
- package/dist/lib/disk-readiness-probe.js +56 -0
- package/dist/lib/disk-readiness-probe.js.map +1 -0
- package/dist/lib/in-memory-direct-transfer-storage.d.ts +48 -0
- package/dist/lib/in-memory-direct-transfer-storage.d.ts.map +1 -0
- package/dist/lib/in-memory-direct-transfer-storage.js +131 -0
- package/dist/lib/in-memory-direct-transfer-storage.js.map +1 -0
- package/dist/lib/logic/attachment-disposition.d.ts +8 -0
- package/dist/lib/logic/attachment-disposition.d.ts.map +1 -0
- package/dist/lib/logic/attachment-disposition.js +12 -0
- package/dist/lib/logic/attachment-disposition.js.map +1 -0
- package/dist/lib/multipart-assembly.d.ts +4 -0
- package/dist/lib/multipart-assembly.d.ts.map +1 -0
- package/dist/lib/multipart-assembly.js +16 -0
- package/dist/lib/multipart-assembly.js.map +1 -0
- package/dist/lib/multipart-image-upload.d.ts +29 -0
- package/dist/lib/multipart-image-upload.d.ts.map +1 -0
- package/dist/lib/multipart-image-upload.js +77 -0
- package/dist/lib/multipart-image-upload.js.map +1 -0
- package/dist/lib/s3-direct-transfer-storage.d.ts +45 -0
- package/dist/lib/s3-direct-transfer-storage.d.ts.map +1 -0
- package/dist/lib/s3-direct-transfer-storage.js +222 -0
- package/dist/lib/s3-direct-transfer-storage.js.map +1 -0
- package/dist/lib/s3-object-storage.d.ts +43 -0
- package/dist/lib/s3-object-storage.d.ts.map +1 -0
- package/dist/lib/s3-object-storage.js +118 -0
- package/dist/lib/s3-object-storage.js.map +1 -0
- package/dist/lib/stale-temp-files.d.ts +25 -0
- package/dist/lib/stale-temp-files.d.ts.map +1 -0
- package/dist/lib/stale-temp-files.js +87 -0
- package/dist/lib/stale-temp-files.js.map +1 -0
- package/dist/object-storage.tsbuildinfo +1 -0
- package/package.json +40 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bryton Cooper
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dads-framework/object-storage
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Put, get, delete, and sign download or single-PUT upload URLs for object bytes. The composition
|
|
4
|
+
root picks the in-memory driver, the S3-compatible driver or the local disk driver
|
|
5
|
+
(`OBJECT_STORAGE_DRIVER`).
|
|
6
|
+
|
|
7
|
+
`DiskObjectStorage` keeps each object at `<root>/objects/<key>` with a SHA-256 sidecar. Writes are
|
|
8
|
+
whole or absent, a disk floor refuses a new file before the volume fills, and signed links are
|
|
9
|
+
path-only and HMAC-signed with a key the box makes (`loadOrCreateDiskSigningKey`).
|
|
10
|
+
|
|
11
|
+
`DirectTransferStorage` is the browser-direct seam on the same bucket:
|
|
12
|
+
server-chosen multipart uploads, presigned part and attachment-download URLs,
|
|
13
|
+
and the reads that verify a finished upload. See
|
|
14
|
+
docs/reference/object-storage.md.
|
|
15
|
+
|
|
16
|
+
The package re-exports the capability and in-memory implementation from
|
|
17
|
+
[`@dads-framework/object-storage-core`](../object-storage-core/README.md).
|
|
18
|
+
The core's conformance suite also runs against the disk and S3 implementations.
|
|
19
|
+
|
|
20
|
+
## Download delivery
|
|
21
|
+
|
|
22
|
+
S3 options can carry one `CloudFrontDownloadSigner`, shared by
|
|
23
|
+
`getSignedUrl` and `presignAttachmentDownload`. Its deployment-owned HTTPS base
|
|
24
|
+
URL includes the public path prefix; callers use returned URLs unchanged. Native
|
|
25
|
+
CloudFront signatures cover the exact object path and optional `download`
|
|
26
|
+
filename query. The signer accepts published keys only, rejects `quarantine/`,
|
|
27
|
+
and limits link validity to one hour. Its clock is injected.
|
|
28
|
+
|
|
29
|
+
Uploads, object verification and server reads retain the configured S3 client.
|
|
30
|
+
Without the download signer, local MinIO and staged AWS environments retain S3
|
|
31
|
+
GET signatures. Browser download buttons navigate to attachment links; they do
|
|
32
|
+
not fetch the file into application memory. Routing, trusted public keys and an
|
|
33
|
+
ACTIVE qualified flat-rate plan must precede production signer cutover.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { InMemoryObjectStorage, ObjectStorage, type SignedUpload, type SignedUploadRequest, type StoredObject, } from "@dads-framework/object-storage-core";
|
|
2
|
+
export { S3ObjectStorage, type S3ObjectStorageOptions, type S3StaticCredentials, } from "./lib/s3-object-storage.js";
|
|
3
|
+
export { DiskObjectStorage, InvalidObjectKey, loadOrCreateDiskSigningKey, SiteDiskLow, type DiskFreeSpace, type DiskObjectStorageLog, type DiskObjectStorageOptions, type DiskSpace, type OpenedSignedDownload, type ReceivedSignedUpload, type SignedDownloadQuery, } from "./lib/disk-object-storage.js";
|
|
4
|
+
export { type PartUploadLinkRequest, type SignedPartUpload, type SignedPartUploadQuery, } from "./lib/disk-part-links.js";
|
|
5
|
+
export { createObjectStorage, type CreateObjectStorageOptions, } from "./lib/create-object-storage.js";
|
|
6
|
+
export { DirectTransferStorage, type MultipartUploadRef, type StoredObjectChecksum, type StoredObjectHead, type UploadedPart, type WriteOnceUploadRequest, } from "./lib/direct-transfer-storage.js";
|
|
7
|
+
export { S3DirectTransferStorage } from "./lib/s3-direct-transfer-storage.js";
|
|
8
|
+
export { InMemoryDirectTransferStorage } from "./lib/in-memory-direct-transfer-storage.js";
|
|
9
|
+
export { DiskDirectTransferStorage, type ReceivedPart, } from "./lib/disk-direct-transfer-storage.js";
|
|
10
|
+
export { createDirectTransferStorage } from "./lib/create-direct-transfer-storage.js";
|
|
11
|
+
export { CloudFrontDownloadSigner, type CloudFrontDownloadSignerOptions, } from "./lib/cloudfront-download-signer.js";
|
|
12
|
+
export { MultipartImageUpload, type ImageMultipartReceipt, } from "./lib/multipart-image-upload.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,YAAY,GAClB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,eAAe,EACf,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,GACzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,0BAA0B,EAC1B,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,GAC3B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,mBAAmB,EACnB,KAAK,0BAA0B,GAChC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,qBAAqB,EACrB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,sBAAsB,GAC5B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,6BAA6B,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,EACL,yBAAyB,EACzB,KAAK,YAAY,GAClB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AAEtF,OAAO,EACL,wBAAwB,EACxB,KAAK,+BAA+B,GACrC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,oBAAoB,EACpB,KAAK,qBAAqB,GAC3B,MAAM,iCAAiC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { InMemoryObjectStorage, ObjectStorage, } from "@dads-framework/object-storage-core";
|
|
2
|
+
export { S3ObjectStorage, } from "./lib/s3-object-storage.js";
|
|
3
|
+
export { DiskObjectStorage, InvalidObjectKey, loadOrCreateDiskSigningKey, SiteDiskLow, } from "./lib/disk-object-storage.js";
|
|
4
|
+
export {} from "./lib/disk-part-links.js";
|
|
5
|
+
export { createObjectStorage, } from "./lib/create-object-storage.js";
|
|
6
|
+
export { DirectTransferStorage, } from "./lib/direct-transfer-storage.js";
|
|
7
|
+
export { S3DirectTransferStorage } from "./lib/s3-direct-transfer-storage.js";
|
|
8
|
+
export { InMemoryDirectTransferStorage } from "./lib/in-memory-direct-transfer-storage.js";
|
|
9
|
+
export { DiskDirectTransferStorage, } from "./lib/disk-direct-transfer-storage.js";
|
|
10
|
+
export { createDirectTransferStorage } from "./lib/create-direct-transfer-storage.js";
|
|
11
|
+
export { CloudFrontDownloadSigner, } from "./lib/cloudfront-download-signer.js";
|
|
12
|
+
export { MultipartImageUpload, } from "./lib/multipart-image-upload.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,aAAa,GAId,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,eAAe,GAGhB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,0BAA0B,EAC1B,WAAW,GAQZ,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAIN,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,mBAAmB,GAEpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,qBAAqB,GAMtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,6BAA6B,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,EACL,yBAAyB,GAE1B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AAEtF,OAAO,EACL,wBAAwB,GAEzB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,oBAAoB,GAErB,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type CloudFrontDownloadSignerOptions = {
|
|
2
|
+
readonly baseUrl: string;
|
|
3
|
+
readonly keyPairId: string;
|
|
4
|
+
readonly privateKey: string;
|
|
5
|
+
readonly now: () => Date;
|
|
6
|
+
};
|
|
7
|
+
/** Native CloudFront signatures cover the exact path and per-viewer filename. */
|
|
8
|
+
export declare class CloudFrontDownloadSigner {
|
|
9
|
+
private readonly options;
|
|
10
|
+
private readonly baseUrl;
|
|
11
|
+
private readonly now;
|
|
12
|
+
constructor(options: CloudFrontDownloadSignerOptions);
|
|
13
|
+
sign(key: string, expiresInSeconds: number, fileName?: string): string;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=cloudfront-download-signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudfront-download-signer.d.ts","sourceRoot":"","sources":["../../src/lib/cloudfront-download-signer.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,+BAA+B,GAAG;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,IAAI,CAAC;CAC1B,CAAC;AAEF,iFAAiF;AACjF,qBAAa,wBAAwB;IAIvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAHpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAa;IAEjC,YAA6B,OAAO,EAAE,+BAA+B,EAuBpE;IAED,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CA+BrE;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getSignedUrl } from "@aws-sdk/cloudfront-signer";
|
|
2
|
+
import { createPrivateKey } from "node:crypto";
|
|
3
|
+
/** Native CloudFront signatures cover the exact path and per-viewer filename. */
|
|
4
|
+
export class CloudFrontDownloadSigner {
|
|
5
|
+
options;
|
|
6
|
+
baseUrl;
|
|
7
|
+
now;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.options = options;
|
|
10
|
+
const base = new URL(options.baseUrl);
|
|
11
|
+
if (base.protocol !== "https:" ||
|
|
12
|
+
base.username ||
|
|
13
|
+
base.password ||
|
|
14
|
+
base.search ||
|
|
15
|
+
base.hash ||
|
|
16
|
+
/[*?]/.test(base.pathname)) {
|
|
17
|
+
throw new Error("CloudFront download base URL must be an HTTPS URL without credentials, query or fragment");
|
|
18
|
+
}
|
|
19
|
+
this.baseUrl = base.href.replace(/\/$/, "");
|
|
20
|
+
const privateKey = createPrivateKey(options.privateKey);
|
|
21
|
+
if (privateKey.asymmetricKeyType !== "rsa" ||
|
|
22
|
+
privateKey.asymmetricKeyDetails?.modulusLength !== 2048) {
|
|
23
|
+
throw new Error("CloudFront signing requires a 2048-bit RSA private key");
|
|
24
|
+
}
|
|
25
|
+
this.now = options.now;
|
|
26
|
+
}
|
|
27
|
+
sign(key, expiresInSeconds, fileName) {
|
|
28
|
+
if (!Number.isInteger(expiresInSeconds) ||
|
|
29
|
+
expiresInSeconds < 1 ||
|
|
30
|
+
expiresInSeconds > 3600) {
|
|
31
|
+
throw new Error("CloudFront download expiry must be between 1 and 3600 seconds");
|
|
32
|
+
}
|
|
33
|
+
if (key
|
|
34
|
+
.split("/")
|
|
35
|
+
.some((part) => part === "" || part === "." || part === "..") ||
|
|
36
|
+
containsForbiddenKeyCharacter(key) ||
|
|
37
|
+
key.startsWith("quarantine/")) {
|
|
38
|
+
throw new Error("Object download key must identify one published object");
|
|
39
|
+
}
|
|
40
|
+
const url = new URL(`${this.baseUrl}/${key.split("/").map(encodeURIComponent).join("/")}`);
|
|
41
|
+
if (fileName !== undefined)
|
|
42
|
+
url.searchParams.set("download", fileName);
|
|
43
|
+
return getSignedUrl({
|
|
44
|
+
url: url.href.replace(/\*/g, "%2A"),
|
|
45
|
+
keyPairId: this.options.keyPairId,
|
|
46
|
+
privateKey: this.options.privateKey,
|
|
47
|
+
dateLessThan: new Date(this.now().getTime() + expiresInSeconds * 1000).toISOString(),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function containsForbiddenKeyCharacter(value) {
|
|
52
|
+
if (/[*?\\]/.test(value))
|
|
53
|
+
return true;
|
|
54
|
+
for (let index = 0; index < value.length; index++) {
|
|
55
|
+
const code = value.charCodeAt(index);
|
|
56
|
+
if (code < 32 || code === 127)
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=cloudfront-download-signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloudfront-download-signer.js","sourceRoot":"","sources":["../../src/lib/cloudfront-download-signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAS/C,iFAAiF;AACjF,MAAM,OAAO,wBAAwB;IAIN,OAAO;IAHnB,OAAO,CAAS;IAChB,GAAG,CAAa;IAEjC,YAA6B,OAAwC;uBAAxC,OAAO;QAClC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACtC,IACE,IAAI,CAAC,QAAQ,KAAK,QAAQ;YAC1B,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,MAAM;YACX,IAAI,CAAC,IAAI;YACT,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,EAC1B,CAAC;YACD,MAAM,IAAI,KAAK,CACb,0FAA0F,CAC3F,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC5C,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACxD,IACE,UAAU,CAAC,iBAAiB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C,UAAU;YACnC,YAAY,EAAE,IAAI,IAAI,CACpB,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,GAAG,gBAAgB,GAAG,IAAI,CAC/C,CAAC,WAAW,EAAE;SAChB,CAAC,CAAC;IACL,CAAC;CACF;AAED,SAAS,6BAA6B,CAAC,KAAa;IAClD,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAClD,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,IAAI,GAAG,EAAE,IAAI,IAAI,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;IAC7C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CreateObjectStorageOptions } from "./create-object-storage.js";
|
|
2
|
+
import type { DirectTransferStorage } from "./direct-transfer-storage.js";
|
|
3
|
+
/**
|
|
4
|
+
* Select the browser-direct transfer driver from the same options as
|
|
5
|
+
* `createObjectStorage`. The memory driver cannot serve a real browser (its
|
|
6
|
+
* URLs are `memory://`); dev slots run MinIO through the `s3` driver. The
|
|
7
|
+
* site's `disk` driver gets its twin, `DiskDirectTransferStorage`, from the
|
|
8
|
+
* composition root, over the same `DiskObjectStorage` instance, so
|
|
9
|
+
* the two share one root, signing key and per-key write queue; called here
|
|
10
|
+
* with `disk`, this answers the empty in-memory one.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createDirectTransferStorage(options: CreateObjectStorageOptions): DirectTransferStorage;
|
|
13
|
+
//# sourceMappingURL=create-direct-transfer-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-direct-transfer-storage.d.ts","sourceRoot":"","sources":["../../src/lib/create-direct-transfer-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAI1E;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,0BAA0B,GAClC,qBAAqB,CAIvB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { InMemoryDirectTransferStorage } from "./in-memory-direct-transfer-storage.js";
|
|
2
|
+
import { S3DirectTransferStorage } from "./s3-direct-transfer-storage.js";
|
|
3
|
+
/**
|
|
4
|
+
* Select the browser-direct transfer driver from the same options as
|
|
5
|
+
* `createObjectStorage`. The memory driver cannot serve a real browser (its
|
|
6
|
+
* URLs are `memory://`); dev slots run MinIO through the `s3` driver. The
|
|
7
|
+
* site's `disk` driver gets its twin, `DiskDirectTransferStorage`, from the
|
|
8
|
+
* composition root, over the same `DiskObjectStorage` instance, so
|
|
9
|
+
* the two share one root, signing key and per-key write queue; called here
|
|
10
|
+
* with `disk`, this answers the empty in-memory one.
|
|
11
|
+
*/
|
|
12
|
+
export function createDirectTransferStorage(options) {
|
|
13
|
+
return options.driver === "s3"
|
|
14
|
+
? new S3DirectTransferStorage(options)
|
|
15
|
+
: new InMemoryDirectTransferStorage();
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=create-direct-transfer-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-direct-transfer-storage.js","sourceRoot":"","sources":["../../src/lib/create-direct-transfer-storage.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E;;;;;;;;GAQG;AACH,MAAM,UAAU,2BAA2B,CACzC,OAAmC;IAEnC,OAAO,OAAO,CAAC,MAAM,KAAK,IAAI;QAC5B,CAAC,CAAC,IAAI,uBAAuB,CAAC,OAAO,CAAC;QACtC,CAAC,CAAC,IAAI,6BAA6B,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type DiskObjectStorageOptions } from "./disk-object-storage.js";
|
|
2
|
+
import { type ObjectStorage } from "@dads-framework/object-storage-core";
|
|
3
|
+
import { type S3ObjectStorageOptions } from "./s3-object-storage.js";
|
|
4
|
+
export type CreateObjectStorageOptions = {
|
|
5
|
+
readonly driver: "memory";
|
|
6
|
+
} | ({
|
|
7
|
+
readonly driver: "s3";
|
|
8
|
+
} & S3ObjectStorageOptions) | ({
|
|
9
|
+
readonly driver: "disk";
|
|
10
|
+
} & DiskObjectStorageOptions);
|
|
11
|
+
/** Select the in-memory, S3-compatible or site disk object-storage driver. */
|
|
12
|
+
export declare function createObjectStorage(options: CreateObjectStorageOptions): ObjectStorage;
|
|
13
|
+
//# sourceMappingURL=create-object-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-object-storage.d.ts","sourceRoot":"","sources":["../../src/lib/create-object-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,0BAA0B,GAClC;IAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAA;CAAE,GAC7B,CAAC;IAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAA;CAAE,GAAG,sBAAsB,CAAC,GACpD,CAAC;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,wBAAwB,CAAC,CAAC;AAE7D,8EAA8E;AAC9E,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,0BAA0B,GAClC,aAAa,CASf"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DiskObjectStorage, } from "./disk-object-storage.js";
|
|
2
|
+
import { InMemoryObjectStorage, } from "@dads-framework/object-storage-core";
|
|
3
|
+
import { S3ObjectStorage, } from "./s3-object-storage.js";
|
|
4
|
+
/** Select the in-memory, S3-compatible or site disk object-storage driver. */
|
|
5
|
+
export function createObjectStorage(options) {
|
|
6
|
+
switch (options.driver) {
|
|
7
|
+
case "s3":
|
|
8
|
+
return new S3ObjectStorage(options);
|
|
9
|
+
case "disk":
|
|
10
|
+
return new DiskObjectStorage(options);
|
|
11
|
+
case "memory":
|
|
12
|
+
return new InMemoryObjectStorage();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=create-object-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-object-storage.js","sourceRoot":"","sources":["../../src/lib/create-object-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAElB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,qBAAqB,GAEtB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,eAAe,GAEhB,MAAM,wBAAwB,CAAC;AAOhC,8EAA8E;AAC9E,MAAM,UAAU,mBAAmB,CACjC,OAAmC;IAEnC,QAAQ,OAAO,CAAC,MAAM,EAAE,CAAC;QACvB,KAAK,IAAI;YACP,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;QACtC,KAAK,MAAM;YACT,OAAO,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACxC,KAAK,QAAQ;YACX,OAAO,IAAI,qBAAqB,EAAE,CAAC;IACvC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage for bytes that travel straight between a browser and the bucket and
|
|
3
|
+
* never pass through the API: the multipart upload lifecycle, the reads that
|
|
4
|
+
* verify a finished upload, and short-lived attachment download links.
|
|
5
|
+
*
|
|
6
|
+
* The server holds every decision. It picks the key, fixes the content type
|
|
7
|
+
* and metadata when the upload opens, signs one part URL at a time, assembles
|
|
8
|
+
* the parts the bucket reports (never a part list a browser sends), and reads
|
|
9
|
+
* the finished object back before anything records it.
|
|
10
|
+
*
|
|
11
|
+
* `ObjectStorage` stays the seam for bytes the API itself holds.
|
|
12
|
+
*/
|
|
13
|
+
import type { SignedUpload } from "@dads-framework/object-storage-core";
|
|
14
|
+
/** One open multipart upload: the server-chosen key and the bucket's upload id. */
|
|
15
|
+
export type MultipartUploadRef = {
|
|
16
|
+
readonly key: string;
|
|
17
|
+
readonly storageUploadId: string;
|
|
18
|
+
};
|
|
19
|
+
/** A part the bucket holds for an open upload. */
|
|
20
|
+
export type UploadedPart = {
|
|
21
|
+
readonly partNumber: number;
|
|
22
|
+
readonly etag: string;
|
|
23
|
+
readonly byteSize: number;
|
|
24
|
+
};
|
|
25
|
+
/** What the bucket reports about a stored object. */
|
|
26
|
+
export type StoredObjectHead = {
|
|
27
|
+
readonly byteSize: number;
|
|
28
|
+
readonly contentType: string;
|
|
29
|
+
readonly metadata: Readonly<Record<string, string>>;
|
|
30
|
+
};
|
|
31
|
+
/** One write-once PUT: the exact bytes (by size and SHA-256) the object must hold. */
|
|
32
|
+
export type WriteOnceUploadRequest = {
|
|
33
|
+
readonly key: string;
|
|
34
|
+
readonly contentType: string;
|
|
35
|
+
readonly byteSize: number;
|
|
36
|
+
/** Lowercase hex SHA-256 of the exact bytes. */
|
|
37
|
+
readonly sha256: string;
|
|
38
|
+
readonly expiresInSeconds: number;
|
|
39
|
+
};
|
|
40
|
+
/** Size and full-object SHA-256 of a stored object; `sha256` is null when the object carries none. */
|
|
41
|
+
export type StoredObjectChecksum = {
|
|
42
|
+
readonly byteSize: number;
|
|
43
|
+
readonly sha256: string | null;
|
|
44
|
+
};
|
|
45
|
+
export declare abstract class DirectTransferStorage {
|
|
46
|
+
/** Opens a multipart upload; the content type and metadata are fixed here, never by the browser. */
|
|
47
|
+
abstract startMultipartUpload(input: {
|
|
48
|
+
readonly key: string;
|
|
49
|
+
readonly contentType: string;
|
|
50
|
+
readonly metadata: Readonly<Record<string, string>>;
|
|
51
|
+
}): Promise<MultipartUploadRef>;
|
|
52
|
+
/** A PUT URL for exactly one part of one open upload. */
|
|
53
|
+
abstract presignUploadPart(input: MultipartUploadRef & {
|
|
54
|
+
readonly partNumber: number;
|
|
55
|
+
/** When supplied, storage accepts exactly this many bytes for the part. */
|
|
56
|
+
readonly byteSize?: number;
|
|
57
|
+
readonly expiresInSeconds: number;
|
|
58
|
+
}): Promise<string>;
|
|
59
|
+
/** The parts the bucket holds, in part order; null once the upload is completed, aborted or unknown. */
|
|
60
|
+
abstract listUploadedParts(upload: MultipartUploadRef): Promise<readonly UploadedPart[] | null>;
|
|
61
|
+
/** Assembles the given parts, in order, into the object at the upload's key. */
|
|
62
|
+
abstract completeMultipartUpload(input: MultipartUploadRef & {
|
|
63
|
+
readonly parts: readonly Pick<UploadedPart, "partNumber" | "etag">[];
|
|
64
|
+
}): Promise<void>;
|
|
65
|
+
/** Discards an open upload's parts; succeeds when the upload is already gone. */
|
|
66
|
+
abstract abortMultipartUpload(upload: MultipartUploadRef): Promise<void>;
|
|
67
|
+
/** Size, type and metadata of a stored object; null when there is none. */
|
|
68
|
+
abstract headObject(key: string): Promise<StoredObjectHead | null>;
|
|
69
|
+
/** The first `byteCount` bytes of a stored object (all of it when shorter); null when there is none. */
|
|
70
|
+
abstract readObjectPrefix(key: string, byteCount: number): Promise<Uint8Array | null>;
|
|
71
|
+
/** A GET URL that downloads the object as an attachment under `fileName`. */
|
|
72
|
+
abstract presignAttachmentDownload(input: {
|
|
73
|
+
readonly key: string;
|
|
74
|
+
readonly fileName: string;
|
|
75
|
+
readonly expiresInSeconds: number;
|
|
76
|
+
}): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Removes a stored object; succeeds when it is already gone. On a versioned
|
|
79
|
+
* bucket this adds a delete marker; a bucket lifecycle rule, not the caller,
|
|
80
|
+
* frees the noncurrent bytes later.
|
|
81
|
+
*/
|
|
82
|
+
abstract deleteObject(key: string): Promise<void>;
|
|
83
|
+
/** One PUT of exactly these bytes, refused by storage if any object already exists at the key. */
|
|
84
|
+
abstract presignWriteOnceUpload(input: WriteOnceUploadRequest): Promise<SignedUpload>;
|
|
85
|
+
/**
|
|
86
|
+
* Size and lowercase hex SHA-256 of a stored object; null when there is
|
|
87
|
+
* none. `sha256` is null when the object has no full-object SHA-256, such as
|
|
88
|
+
* a multipart upload.
|
|
89
|
+
*/
|
|
90
|
+
abstract headObjectChecksum(key: string): Promise<StoredObjectChecksum | null>;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=direct-transfer-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct-transfer-storage.d.ts","sourceRoot":"","sources":["../../src/lib/direct-transfer-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAExE,mFAAmF;AACnF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC,CAAC;AAEF,kDAAkD;AAClD,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,qDAAqD;AACrD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,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CAC9B,KAAK,EAAE,kBAAkB,GAAG;QAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,CAAC,EAAE,CAAC;KACtE,GACA,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,iFAAiF;IACjF,QAAQ,CAAC,oBAAoB,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzE,2EAA2E;IAC3E,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAEnE,wGAAwG;IACxG,QAAQ,CAAC,gBAAgB,CACvB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAE9B,6EAA6E;IAC7E,QAAQ,CAAC,yBAAyB,CAAC,KAAK,EAAE;QACxC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;KACnC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElD,kGAAkG;IAClG,QAAQ,CAAC,sBAAsB,CAC7B,KAAK,EAAE,sBAAsB,GAC5B,OAAO,CAAC,YAAY,CAAC,CAAC;IAEzB;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,CACzB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;CACzC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage for bytes that travel straight between a browser and the bucket and
|
|
3
|
+
* never pass through the API: the multipart upload lifecycle, the reads that
|
|
4
|
+
* verify a finished upload, and short-lived attachment download links.
|
|
5
|
+
*
|
|
6
|
+
* The server holds every decision. It picks the key, fixes the content type
|
|
7
|
+
* and metadata when the upload opens, signs one part URL at a time, assembles
|
|
8
|
+
* the parts the bucket reports (never a part list a browser sends), and reads
|
|
9
|
+
* the finished object back before anything records it.
|
|
10
|
+
*
|
|
11
|
+
* `ObjectStorage` stays the seam for bytes the API itself holds.
|
|
12
|
+
*/
|
|
13
|
+
export class DirectTransferStorage {
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=direct-transfer-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct-transfer-storage.js","sourceRoot":"","sources":["../../src/lib/direct-transfer-storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAwCH,MAAM,OAAgB,qBAAqB;CAqE1C"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { DirectTransferStorage, type MultipartUploadRef, type StoredObjectChecksum, type StoredObjectHead, type UploadedPart, type WriteOnceUploadRequest } from "./direct-transfer-storage.js";
|
|
2
|
+
import { type DiskObjectStorage } from "./disk-object-storage.js";
|
|
3
|
+
import type { SignedPartUploadQuery } from "./disk-part-links.js";
|
|
4
|
+
import type { SignedUpload } from "@dads-framework/object-storage-core";
|
|
5
|
+
/** One part a browser PUT to a signed part link, as the disk now holds it. */
|
|
6
|
+
export type ReceivedPart = {
|
|
7
|
+
readonly key: string;
|
|
8
|
+
readonly partNumber: number;
|
|
9
|
+
readonly etag: string;
|
|
10
|
+
readonly byteSize: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The site's browser-direct twin of {@link DiskObjectStorage}, over
|
|
14
|
+
* the same root and signing key, so the cloud's upload flow runs unchanged
|
|
15
|
+
* at a plant with the internet cut.
|
|
16
|
+
*
|
|
17
|
+
* An open upload is a folder `<root>/multipart/<upload id>/` holding its
|
|
18
|
+
* manifest (key, content type, metadata) and one file per part. A part link
|
|
19
|
+
* is a path-only signed `PUT` on the site's own file route; the route hands
|
|
20
|
+
* the bytes to {@link receivePart}. Completing assembles the parts, in
|
|
21
|
+
* order, through `DiskObjectStorage.put` (temp file, fsync, rename, disk
|
|
22
|
+
* floor), so `DiskObjectStorage.get` reads the object back, and keeps its
|
|
23
|
+
* metadata beside it under `<root>/object-metadata/<key>.json`. Every write
|
|
24
|
+
* is whole or absent and survives a restart: a new instance on the same
|
|
25
|
+
* root sees every open upload and every object.
|
|
26
|
+
*/
|
|
27
|
+
export declare class DiskDirectTransferStorage extends DirectTransferStorage {
|
|
28
|
+
private readonly objects;
|
|
29
|
+
private readonly multipartDirectory;
|
|
30
|
+
private readonly metadataDirectory;
|
|
31
|
+
constructor(objects: DiskObjectStorage);
|
|
32
|
+
startMultipartUpload(input: {
|
|
33
|
+
readonly key: string;
|
|
34
|
+
readonly contentType: string;
|
|
35
|
+
readonly metadata: Readonly<Record<string, string>>;
|
|
36
|
+
}): Promise<MultipartUploadRef>;
|
|
37
|
+
presignUploadPart(input: MultipartUploadRef & {
|
|
38
|
+
readonly partNumber: number;
|
|
39
|
+
readonly byteSize?: number;
|
|
40
|
+
readonly expiresInSeconds: number;
|
|
41
|
+
}): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Stores one part a browser sent to a signed part link. Null, storing
|
|
44
|
+
* nothing, for a bad, expired or changed link, an upload that is no
|
|
45
|
+
* longer open (also when it was aborted while this part was written) or is
|
|
46
|
+
* for another key, or a body whose size differs from the one the link names. Throws `SiteDiskLow` below the disk floor.
|
|
47
|
+
*/
|
|
48
|
+
receivePart(query: SignedPartUploadQuery, body: Uint8Array): Promise<ReceivedPart | null>;
|
|
49
|
+
listUploadedParts(upload: MultipartUploadRef): Promise<readonly UploadedPart[] | null>;
|
|
50
|
+
completeMultipartUpload(input: MultipartUploadRef & {
|
|
51
|
+
readonly parts: readonly Pick<UploadedPart, "partNumber" | "etag">[];
|
|
52
|
+
}): Promise<void>;
|
|
53
|
+
abortMultipartUpload(upload: MultipartUploadRef): Promise<void>;
|
|
54
|
+
headObject(key: string): Promise<StoredObjectHead | null>;
|
|
55
|
+
readObjectPrefix(key: string, byteCount: number): Promise<Uint8Array | null>;
|
|
56
|
+
/** A signed `GET` on the site's own file route; the route answers the stored content type. */
|
|
57
|
+
presignAttachmentDownload(input: {
|
|
58
|
+
readonly key: string;
|
|
59
|
+
readonly fileName: string;
|
|
60
|
+
readonly expiresInSeconds: number;
|
|
61
|
+
}): Promise<string>;
|
|
62
|
+
deleteObject(key: string): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* The disk store's signed single `PUT`. It pins the byte count and the
|
|
65
|
+
* SHA-256, so a second `PUT` to the link can only write the same bytes
|
|
66
|
+
* again: nothing at the key can be replaced by other bytes.
|
|
67
|
+
*/
|
|
68
|
+
presignWriteOnceUpload(input: WriteOnceUploadRequest): Promise<SignedUpload>;
|
|
69
|
+
headObjectChecksum(key: string): Promise<StoredObjectChecksum | null>;
|
|
70
|
+
/** The upload's manifest when it is open and for this key; null otherwise. */
|
|
71
|
+
private readManifest;
|
|
72
|
+
private hasManifest;
|
|
73
|
+
private readMetadata;
|
|
74
|
+
private removeUploadFolder;
|
|
75
|
+
/** Only ever called with an id `STORAGE_UPLOAD_ID` accepts, so it never names a path outside. */
|
|
76
|
+
private uploadFolder;
|
|
77
|
+
private metadataPathOf;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=disk-direct-transfer-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disk-direct-transfer-storage.d.ts","sourceRoot":"","sources":["../../src/lib/disk-direct-transfer-storage.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,qBAAqB,EACrB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC5B,MAAM,8BAA8B,CAAC;AAStC,OAAO,EACL,KAAK,iBAAiB,EAGv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