Adapter
An adapter connects Sobj to a storage provider by implementing a set of operations.
📥 Import
ts
import type { SobjAdapter, SobjCapabilities } from 'sobj/adapter'📊 SobjCapabilities
Declares which operations the adapter implements.
ts
interface SobjCapabilities {
copy: boolean
delete: true
get: true
head: true
list: true
multipart: boolean
presign: boolean
put: true
versioning: boolean
}Operations marked true are required for all adapters. Operations typed as boolean are optional — set them to true if the adapter implements them, or false if not.
⚙️ SobjAdapter
A mapped type that produces an object with only the operations the capabilities allow:
ts
type SobjAdapter<C extends SobjCapabilities> = {
[K in keyof C & keyof SobjOperations as C[K] extends true
? K
: never]: SobjOperations[K]
}Only keys where C[K] is true are included.
🛠️ Implementing an adapter
To build a custom connector, implement the typed capabilities and operation methods:
ts
import type { SobjAdapter, SobjCapabilities } from 'sobj/adapter'
const capabilities = {
copy: false,
delete: true,
get: true,
head: true,
list: true,
multipart: false,
presign: false,
put: true,
versioning: false,
} as const satisfies SobjCapabilities
type MyCapabilities = typeof capabilities
const adapter: SobjAdapter<MyCapabilities> = {
async put(key, body, options) {
// ...
return { key }
},
async get(key, options) {
// return null if not found
return null
},
async head(key) {
return null
},
async delete(key) {},
async list(options) {
return { objects: [], prefixes: [], hasMore: false }
},
}🏷️ Sobj type alias
Sobj<C> is an alias for SobjAdapter<C> used as the return type of sobj():
ts
type Sobj<C extends SobjCapabilities> = SobjAdapter<C>🔗 Related
- sobj — the factory function
- Operations — all operation signatures
- Custom adapters — how to build your own adapter