@dads-framework/object-storage 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,13 +10,71 @@ path-only and HMAC-signed with a key the box makes (`loadOrCreateDiskSigningKey`
|
|
|
10
10
|
|
|
11
11
|
`DirectTransferStorage` is the browser-direct seam on the same bucket:
|
|
12
12
|
server-chosen multipart uploads, presigned part and attachment-download URLs,
|
|
13
|
-
and the reads that verify a finished upload.
|
|
14
|
-
docs/reference/object-storage.md.
|
|
13
|
+
and the reads that verify a finished upload.
|
|
15
14
|
|
|
16
15
|
The package re-exports the capability and in-memory implementation from
|
|
17
16
|
[`@dads-framework/object-storage-core`](../object-storage-core/README.md).
|
|
18
17
|
The core's conformance suite also runs against the disk and S3 implementations.
|
|
19
18
|
|
|
19
|
+
## Try it
|
|
20
|
+
|
|
21
|
+
Use a writable temporary directory on a volume with enough free space to
|
|
22
|
+
leave at least 2 GiB or 5% of total capacity, whichever is larger, after the
|
|
23
|
+
write.
|
|
24
|
+
|
|
25
|
+
In a project using Node.js 22 or later, install the example dependencies.
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
npm install @dads-framework/object-storage
|
|
29
|
+
npm install -D tsx
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Save this as `example.mts` and run `npx tsx example.mts`.
|
|
33
|
+
|
|
34
|
+
<!-- dads:check-example -->
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { mkdtemp } from "node:fs/promises";
|
|
38
|
+
import { tmpdir } from "node:os";
|
|
39
|
+
import { join } from "node:path";
|
|
40
|
+
import {
|
|
41
|
+
createObjectStorage,
|
|
42
|
+
loadOrCreateDiskSigningKey,
|
|
43
|
+
} from "@dads-framework/object-storage";
|
|
44
|
+
|
|
45
|
+
const rootDirectory = await mkdtemp(join(tmpdir(), "dads-storage-"));
|
|
46
|
+
const storage = createObjectStorage({
|
|
47
|
+
driver: "disk",
|
|
48
|
+
rootDirectory,
|
|
49
|
+
signingKey: () => loadOrCreateDiskSigningKey(rootDirectory),
|
|
50
|
+
publicPathPrefix: "http://localhost:3000/files",
|
|
51
|
+
clock: () => new Date(),
|
|
52
|
+
log: console,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const key = "reports/daily.txt";
|
|
56
|
+
await storage.put(key, "Ready for review", "text/plain");
|
|
57
|
+
const stored = await storage.get(key);
|
|
58
|
+
if (stored) {
|
|
59
|
+
console.log(stored.contentType, new TextDecoder().decode(stored.body));
|
|
60
|
+
}
|
|
61
|
+
console.log(join(rootDirectory, "objects", key));
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The script prints `text/plain Ready for review` and the path to the written
|
|
65
|
+
file. Open that file to read its contents, then delete the temporary directory
|
|
66
|
+
when finished. The URL prefix configures signed links. This example uses local
|
|
67
|
+
file reads and writes.
|
|
68
|
+
|
|
69
|
+
The starter selects a memory or disk object store at composition time. [`apps/kit-workbench/assembly/local-services.ts`](../../../apps/kit-workbench/assembly/local-services.ts)
|
|
70
|
+
|
|
71
|
+
## Choose a storage path
|
|
72
|
+
|
|
73
|
+
Use `ObjectStorage.put` and `get` for server-owned bytes. For browser uploads,
|
|
74
|
+
create a signed upload with the required size, content type, and checksum.
|
|
75
|
+
Send the browser the returned URL and headers, then verify the stored object
|
|
76
|
+
before associating it with an application record.
|
|
77
|
+
|
|
20
78
|
## Download delivery
|
|
21
79
|
|
|
22
80
|
S3 options can carry one `CloudFrontDownloadSigner`, shared by
|
|
@@ -29,5 +87,5 @@ and limits link validity to one hour. Its clock is injected.
|
|
|
29
87
|
Uploads, object verification and server reads retain the configured S3 client.
|
|
30
88
|
Without the download signer, local MinIO and staged AWS environments retain S3
|
|
31
89
|
GET signatures. Browser download buttons navigate to attachment links; they do
|
|
32
|
-
not fetch the file into application memory.
|
|
33
|
-
|
|
90
|
+
not fetch the file into application memory. Before switching a deployment to the signer, configure CloudFront routing
|
|
91
|
+
and trusted public keys.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dads-framework/object-storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@aws-sdk/client-s3": "^3.1082.0",
|
|
20
20
|
"@aws-sdk/cloudfront-signer": "^3.1149.0",
|
|
21
21
|
"@aws-sdk/s3-request-presigner": "^3.1082.0",
|
|
22
|
-
"@dads-framework/object-storage-core": "0.
|
|
22
|
+
"@dads-framework/object-storage-core": "0.2.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"testcontainers": "^12.0.4",
|