Skip to content
← Public packages

@kentcdodds/photo-portfolio

A fast, photo-first portfolio site you update by chatting with your agent: galleries, about, contact, and one-step rollback.

FollowFork

Files

memory-storage.ts

23 lines · 602 B · TypeScript
import type { SiteStorage } from '../src/store/site-store.ts'

/** In-memory package storage with the same JSON round-trip the real one does. */
export function memoryStorage() {
	const data = new Map<string, string>()
	const storage: SiteStorage & { keys(): Array<string> } = {
		async get(key) {
			const value = data.get(key)
			return value === undefined ? null : JSON.parse(value)
		},
		async set(key, value) {
			data.set(key, JSON.stringify(value))
			return true
		},
		async delete(key) {
			return data.delete(key)
		},
		keys() {
			return [...data.keys()].sort()
		},
	}
	return storage
}