@nwire/storage
v0.7.1
Published
Nwire — object-storage contract + InMemoryStorage default + storagePlugin. Adapters (S3, filesystem) live in separate packages (@nwire/storage-s3, @nwire/storage-fs).
Readme
@nwire/storage
Object-storage contract — narrow
Storageinterface (put/get/stream/url/list/delete).
What it does
Defines the Storage interface every adapter implements and ships storagePlugin({ storage }) that registers it on the container with lifecycle hooks. The contract is intentionally narrow — what 95% of apps actually need. Adapters that can't honor a method (e.g. fs has no presigned URLs) throw StorageUnsupportedError so callers can branch on capability.
Install
pnpm add @nwire/storageQuick start
import { storagePlugin, InMemoryStorage } from "@nwire/storage";
import { defineApp, defineAction } from "@nwire/forge";
const storage = new InMemoryStorage();
defineApp("my-app", { plugins: [storagePlugin({ storage })] });
defineAction({
name: "uploads.create",
handler: async ({ input }, ctx) => {
const s = ctx.resolve<typeof storage>("storage");
await s.put(input.key, input.bytes, { contentType: input.contentType });
return { url: await s.url(input.key) };
},
});API surface
Storage—put/get/getStream/delete/exists/list/url.storagePlugin({ storage })— register on container; lifecycle-managed.InMemoryStorage— captures bytes in a Map; useful in tests.StorageObjectNotFoundError/StorageUnsupportedError.
When to use
Any app that handles files (uploads, exports, generated reports).
Within nwire-app
For developers using this package as part of the Nwire stack — register it via app.use(...) or it auto-wires when you compose createApp({ modules }).
import { createApp } from "@nwire/forge";
const app = createApp({
/* ...config... */
});
// Adapter/plugin wiring happens here when applicable.