Memory Adapter โ
The @sobj/memory adapter provides an in-memory key-value dictionary mock for Sobj storage operations.
It is ideal for unit tests and local development scripts because it requires zero API keys, registers instantly, and makes no network calls.
๐ฅ Installation โ
Install the package alongside sobj:
pnpm add sobj @sobj/memoryโ๏ธ Initialization โ
Create a memory storage client by calling the memory factory:
import { sobj } from 'sobj'
import { memory } from '@sobj/memory'
const storage = sobj(memory())Once constructed, the storage variable supports all baseline Sobj actions. Because it holds references inside a plain dictionary, files will reset when your Node/Deno/Bun process finishes.
๐ง Configurations โ
The memory factory accepts optional initial records to seed the storage:
const storage = sobj(
memory({
initialObjects: {
'docs/readme.md': 'Initial seeded file content',
},
})
)๐ Capabilities โ
The Memory adapter supports all fundamental Sobj API operations:
| Operation | Supported |
|---|---|
put | โ |
get | โ |
head | โ |
delete | โ |
list | โ |
copy | โ (optional/in-memory simulated) |
presign | โ |
multipart | โ |
versioning | โ |
๐งช Usage Example in Unit Tests โ
Since it handles data in memory, you can mock external cloud storages easily during testing (such as with Vitest, Jest or Bun test):
import { expect, test } from 'vitest'
import { sobj } from 'sobj'
import { memory } from '@sobj/memory'
test('uploads user profile data successfully', async () => {
const storage = sobj(memory())
// Perform actions on your services using Sobj
await storage.put('users/1.json', JSON.stringify({ name: 'Alice' }))
const record = await storage.get('users/1.json')
expect(record).not.toBeNull()
const text = await new Response(record!.body).text()
expect(JSON.parse(text)).toEqual({ name: 'Alice' })
})