feat: select a storage provider at runtime - #12
Merged
Conversation
Add `@nestm/storage/files-sdk/provider`, which builds a driver from a provider slug carried as data and imports that provider's adapter — and only that one — on demand. A deployment picks its store with an environment variable and installs a single native SDK instead of hard-coding a driver per backend. The same entry point exposes the provider catalog as pure data so config validation and health checks can read a provider's env contract without loading an adapter. Add `@nestm/storage/files-sdk/fs` for local filesystem storage, mirroring the S3 factory. Its adapter reaches only `node:fs`, so it adds no native SDK. Split the S3 capability set out of `createS3StorageDriver` as `withS3Capabilities`, so the provider factory can keep conditional-copy promotion and the signed policies for the `s3` slug without re-deriving `S3AdapterOptions` from flat provider config. `EnhancedS3Adapter` becomes `S3StorageAdapter` and is now exported.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
@nestm/storageshipped one provider factory:createS3StorageDriver. Any application that wanted to run on GCS, Azure, R2, MinIO, or a plain filesystem had to importfiles-sdk/<provider>itself and wrap the adapter through the bridge — which puts provider SDK types back in the consumer, the exact leak this package exists to prevent.That also means a provider cannot be named at runtime. An application shipping to more than one environment has to hard-code a driver per backend and choose between them with its own switch.
What
@nestm/storage/files-sdk/provider—createProviderStorageDriver({ provider, config, prefix })takes the slug as data and resolves that provider's adapter, and only that one, through a lazy import. A deployment selects its store with an environment variable and installs a single native SDK.configis one flat bag of provider settings (bucket/regionfor an object store,rootfor the filesystem,accountName/containerfor Azure); each provider reads what it needs and ignores the rest, so the shape survives a provider change. The caller's own driver options —prefix,hooks,plugins,readonly,retries— still apply, because the clientloadFilesbuilds is discarded and the bridge builds its own over the resolved adapter.The same entry point exposes the provider catalog as pure data —
listStorageProviders,getStorageProvider,listStorageProviderEnvVars,listStorageProviderSecretEnvVars,isStorageProvider— so startup validation, health checks, and config UIs can read a provider's env contract without loading an adapter. An unknown slug fails closed withINVALID_ARGUMENTbefore anything is imported.@nestm/storage/files-sdk/fs—createFsStorageDriver, mirroring the S3 factory. The adapter reaches onlynode:fs, so unlike every object-store provider it adds no native SDK to an install.@nestm/storage/files-sdk/s3— the S3 capability set is split out ofcreateS3StorageDriveraswithS3Capabilities(base, options), so the provider factory can keep conditional-copy promotion and the signed policies for thes3slug without re-derivingS3AdapterOptionsfrom flat config. The S3-compatible wrappers keep only what they declare themselves.EnhancedS3Adapteris renamedS3StorageAdapterand exported; it was previously private.Notes
createS3StorageDriver— it now composes the extracted helper. Its existing spec passes untouched.files-sdktypes stay inside thefiles-sdkbridge subtree, matching hows3/index.tsalready re-exportsS3AdapterOptions.Verification
pnpm run check(oxlint, prettier, tsc),pnpm run test— 49 unit + 22 e2e,pnpm run verify:pack— build,publint --strict, packed-consumer check. All green.New coverage: filesystem round-trip and prefix scoping, provider resolution by name, driver options reaching the resolved adapter,
readonlyhonored for any provider, thes3slug keeping its capabilities, a provider that declares no conditional copy not claiming one, unknown-slug rejection, and the catalog surface.