we (web engine): Experimental web browser project to understand the limits of Claude

IndexedDB basic subset #135

open opened by pierrelf.com

Phase 14: Security + Storage#

Implement a basic subset of the IndexedDB API for structured client-side storage.

Background#

IndexedDB provides a transactional, key-value object store in the browser. This issue covers a minimal but functional subset -- enough to support common use cases like caching structured data.

Requirements#

Database lifecycle#

  • indexedDB.open(name, version): open or create a database
  • Fire upgradeneeded event when version increases (this is where object stores are created)
  • Fire success event when the database is ready
  • Fire error event on failure
  • database.close(): close the connection
  • indexedDB.deleteDatabase(name): delete a database

Object stores#

  • database.createObjectStore(name, options): create an object store during upgradeneeded
  • Support keyPath option (property name used as key) and autoIncrement
  • database.deleteObjectStore(name): delete an object store during upgradeneeded
  • transaction.objectStore(name): get a reference to an object store

CRUD operations#

  • objectStore.put(value, key?): insert or update a record
  • objectStore.get(key): retrieve a record by key
  • objectStore.delete(key): delete a record by key
  • objectStore.clear(): delete all records
  • objectStore.count(): return the number of records
  • objectStore.getAll(): return all records

Transactions#

  • database.transaction(storeNames, mode): create a transaction (readonly or readwrite)
  • Transactions auto-commit when all requests are complete
  • Fire complete event on successful commit, abort event on failure
  • transaction.abort(): explicitly abort

Indexes (basic)#

  • objectStore.createIndex(name, keyPath, options): create an index during upgradeneeded
  • Support unique option
  • index.get(key): look up records by indexed property

Storage backend#

  • File-based persistent storage, one directory per origin per database
  • Simple binary format for object store data (key-value pairs)
  • Store in ~/.we/indexeddb///

Security#

  • Databases are partitioned by origin
  • Opaque origins get no IndexedDB access

Integration points#

  • New module: crates/browser/src/indexeddb.rs
  • crates/js: expose indexedDB on the window global, implement IDBDatabase, IDBTransaction, IDBObjectStore, IDBIndex, IDBRequest, IDBCursor interfaces

Acceptance Criteria#

  • Can open, create, and delete databases
  • Object stores support put/get/delete/clear/count/getAll
  • Transactions provide correct readonly/readwrite semantics
  • Auto-commit fires complete event; abort fires abort event
  • Indexes allow querying by non-primary key
  • Data persists across simulated browser restarts
  • Storage is partitioned by origin
  • cargo clippy --workspace -- -D warnings passes
  • cargo test --workspace passes
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mi4toff4w72z