3.4 KiB
registry
(no submodules)
Purpose
Module-augments @suaveplan/storage/factory's StorageProviderRegistry and StorageProviderConfig to add the "rackspace-cdn" slot, and exposes registerRackspaceCdnProvider() to bind RackspaceCdnAdapter as the constructor for that slot. Consumers who prefer factory-style instantiation (createStorage({ type: "rackspace-cdn", config })) call registerRackspaceCdnProvider() once at boot and never reference the class directly.
Registration is idempotent — duplicate calls are no-ops, so wiring this into multiple bootstrappers (test fixtures + production startup) is safe.
Features
- TypeScript module augmentation —
createStorage<"rackspace-cdn">now type-checks withRackspaceCdnAdapterOptions. - Idempotent
registerRackspaceCdnProvider()— safe to call from multiple bootstrap paths. - Zero runtime dependencies beyond
@suaveplan/storage/factoryand the localRackspaceCdnAdapterclass.
Usage: Basic
import { registerRackspaceCdnProvider } from "@suaveplan/storage-cdn-rackspace";
import { createStorage } from "@suaveplan/storage/factory";
registerRackspaceCdnProvider();
const storage = createStorage({
type: "rackspace-cdn",
config: {
originBaseUrl: "https://storage101.lon3.clouddrive.com/v1/AUTH_acc/",
edgeBaseUrl: "https://abc.r88.cf6.rackcdn.com/",
username: "u",
apiKey: "k",
container: "myc",
region: "LON",
},
});
Usage: Advanced
import { registerRackspaceCdnProvider } from "@suaveplan/storage-cdn-rackspace";
import { createStorage } from "@suaveplan/storage/factory";
// Bootstrap once per process.
registerRackspaceCdnProvider();
function tenantStorage(tenant: { container: string; region: "LON" | "IAD" }) {
return createStorage({
type: "rackspace-cdn",
config: { ...baseConfig, container: tenant.container, region: tenant.region },
});
}
API Reference
registerRackspaceCdnProvider(): void
Registers RackspaceCdnAdapter against StorageFactory under the "rackspace-cdn" slot when not already registered. Calling it twice is a no-op.
Module augmentation
declare module "@suaveplan/storage/factory" {
interface StorageProviderRegistry { "rackspace-cdn": RackspaceCdnAdapter }
interface StorageProviderConfig { "rackspace-cdn": RackspaceCdnAdapterOptions }
}
This means createStorage<"rackspace-cdn">(...) returns RackspaceCdnAdapter and the config parameter is typed as RackspaceCdnAdapterOptions.
Implementation Notes
- The cast
RackspaceCdnAdapter as unknown as new (config?: unknown) => RackspaceCdnAdapteris required becauseStorageFactory'sProviderCtoris intentionally loose (config?: unknown) — adapter constructors take typed options that don't satisfy the registry's structural shape without the cast. hasStorageProvider("rackspace-cdn")is the idempotency gate. AfterunregisterStorageProvider("rackspace-cdn")orclearStorageProviders(), a subsequentregisterRackspaceCdnProvider()call cleanly re-registers.- The augmentation is pure type-level — there is no runtime cost beyond the one-time
Map.setin the factory. - This module imports
RackspaceCdnAdapterdirectly rather than via the package root barrel to avoid a circular import (the root barrel re-exportsregisterRackspaceCdnProvider).