Storefront is a lightweight, flat-file database with a Prisma-like interface designed specifically for browser environments. It provides a simple, intuitive ORM (Object-Relational Mapping) using the File System Access API to manage data persistently on the user's local disk.
- File System Access API: Real, persistent local storage.
- Prisma-inspired API: Familiar query patterns (
findMany,create,update,delete). - First-class TypeScript: Type-safe queries and results.
- Lightweight: Zero-dependency core.
- Concurrent Safety: Built-in locking for reliable operations.
npm install storefrontCreate a schema.storefront file to define your data models:
user {
name: string
email: string
age: number
}
post {
title: string
content: string
authorId: string
}Generate TypeScript types from your schema:
npx storefront generateimport { StorefrontClient } from 'storefront'
// Define your schema type (usually generated)
type Schema = {
user: {
id: string
name: string
email: string
age: number
}
post: {
id: string
title: string
content: string
authorId: string
}
}
async function init() {
// Request directory access
const dirHandle = await window.showDirectoryPicker()
// Initialize the client
const db = new StorefrontClient<Schema>(dirHandle)
// Create a record
const newUser = await db.model('user').create({
name: 'Josh',
email: 'josh@example.com',
age: 30,
})
// Query with Prisma-like syntax
const users = await db.model('user').findMany({
where: {
age: { gte: 18 }
},
orderBy: { name: 'asc' }
})
}Storefront supports standard ORM operations:
- Filtering:
equals,gt,gte,lt,lte,contains,startsWith,endsWith - Logic:
AND,OR,NOT - Pagination:
take,skip - Sorting:
orderBy
Storefront requires a browser that supports the File System Access API. This is currently available in Chrome, Edge, and other Chromium-based browsers.
MIT