@lunora/storage 1.0.0-alpha.7 → 1.0.0-alpha.70

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 CHANGED
@@ -34,7 +34,7 @@
34
34
 
35
35
  ---
36
36
 
37
- R2-backed file storage for Lunora. Wraps a Cloudflare `R2Bucket` binding with a typed API (`upload`/`store`, `download`, `delete`, `list`, `getMetadata`, multipart), worker-signed URLs for app-gated access, and native S3 presigned URLs for direct-to-R2 transfer.
37
+ R2-backed file storage for Lunora. Wraps a Cloudflare `R2Bucket` binding with a typed API (`upload`/`store`, `download`, `head`, `delete`, `list`, `getMetadata`, multipart), worker-signed URLs for app-gated access, and native S3 presigned URLs for direct-to-R2 transfer.
38
38
 
39
39
  Part of the [Lunora](https://github.com/anolilab/lunora) framework — a type-safe, real-time backend on Cloudflare Workers + Durable Objects with a Vite-first DX.
40
40
 
@@ -75,13 +75,15 @@ export default defineApp<Env>()
75
75
  import { action, v } from "@/lunora/_generated/server";
76
76
 
77
77
  // Minting an upload URL is a write capability, so this is an `action`.
78
- // Queries and mutations get a read-only `ctx.storage`; the full surface
79
- // (generateUploadUrl/store/delete/multipart) is action-only.
78
+ // Queries and mutations are TYPED with a read-only `ctx.storage`; the full
79
+ // surface (generateUploadUrl/store/delete/getPresignedUrl) is action-only.
80
+ // Multipart and `list` are on a `createStorage` instance, not on any ctx.
80
81
  export const uploadAvatar = action.input({ contentType: v.string() }).action(async ({ args, ctx }) => {
81
82
  const key = `avatars/${ctx.auth.userId ?? "anonymous"}/profile`;
82
83
 
83
- // Short-lived signed PUT URL — the client uploads straight to R2 through
84
- // your Worker route, with the Content-Type pinned into the signature.
84
+ // Short-lived signed PUT URL — the client uploads to your Worker route,
85
+ // which verifies the signature and writes to R2, with the Content-Type
86
+ // pinned into that signature.
85
87
  const url = await ctx.storage.generateUploadUrl(key, { contentType: args.contentType, expiresInSeconds: 60 });
86
88
 
87
89
  return { key, url };
@@ -95,6 +97,12 @@ import { createStorage } from "@lunora/storage";
95
97
 
96
98
  const storage = createStorage({
97
99
  bucket: env.FILES,
100
+ // Required. The name this bucket is registered under, bound into every signed
101
+ // URL's HMAC (and mirrored as `&bucket=`), so a URL minted for one bucket
102
+ // cannot be replayed against another sharing the signing secret. `"default"`
103
+ // for a single-bucket app; the registered name for anything reached through
104
+ // `createBucketStorage`.
105
+ bucketName: "default",
98
106
  publicBaseUrl: "https://cdn.acme.test",
99
107
  signingSecret: env.STORAGE_SECRET,
100
108
  });
@@ -104,12 +112,12 @@ await storage.upload("uploads/avatar.png", bytes, { contentType: "image/png", ma
104
112
  const url = await storage.getSignedUrl("uploads/avatar.png", { expiresInSeconds: 600 });
105
113
  ```
106
114
 
107
- > This README covers the basics. For the full API, options, and guides, see the **[documentation](https://lunora.sh/docs/addons/storage)**.
115
+ > This README covers the basics. For the full API, options, and guides, see the **[documentation](https://lunora.sh/docs/packages/storage)**.
108
116
 
109
117
  ## Related
110
118
 
111
119
  - [`@lunora/server`](https://www.npmjs.com/package/@lunora/server) — call storage from queries, mutations, and actions.
112
- - [`@lunora/runtime`](https://www.npmjs.com/package/@lunora/runtime) — the Worker runtime that serves gated `GET /storage/:key` routes.
120
+ - [`@lunora/runtime`](https://www.npmjs.com/package/@lunora/runtime) — the Worker runtime your signed-URL route sits in front of. It ships no public storage route of its own: the route that verifies a signed URL and moves the bytes is yours to add (see the `storage` registry item).
113
121
  - [`@lunora/d1`](https://www.npmjs.com/package/@lunora/d1) — store object metadata alongside your data.
114
122
 
115
123
  ## Supported Node.js Versions