npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@schorts/indexed-db-dao

v2.0.0

Published

This module provides a type‑safe, domain‑driven abstraction over IndexedDB persistence. It integrates tightly with the Model, Entity, Criteria, and UnitOfWork constructs from @schorts/shared-kernel, enabling expressive, consistent, and testable offline da

Downloads

1,470

Readme

@schorts/indexed-db-dao

npm version

This module provides a type‑safe, domain‑driven abstraction over IndexedDB persistence. It integrates tightly with the Model, Entity, Criteria, and UnitOfWork constructs from @schorts/shared-kernel, enabling expressive, consistent, and testable offline data access.

Installation

This package has a peer dependency on @schorts/shared-kernel.

npm install @schorts/indexeddb-dao @schorts/shared-kernel

Usage

Here’s a complete example of how to use the IndexedDBDAO to interact with an IndexedDB object store.

1. Define your Entity

Entities map between domain objects and plain primitives for persistence. They must implement toPrimitives() and a static fromPrimitives().

import { Entity as BaseEntity, Model as BaseModel, UUIDValue, EntityRegistry } from "@schorts/shared-kernel";

interface MyEntityModel extends BaseModel {
  name: string;
  aNumber: number;
}

class MyEntity extends BaseEntity<UUIDValue, MyEntityModel> {
  constructor(
    id: UUIDValue,
    public readonly name: string,
    public readonly aNumber: number,
  ) {
    super(id);
  }

  toPrimitives(): MyEntityModel {
    return {
      id: this.id.value,
      name: this.name,
      aNumber: this.aNumber,
    };
  }

  static fromPrimitives<Model extends BaseModel>(model: Model): MyEntity {
    return new MyEntity(
      new UUIDValue(model.id),
      model.name,
      model.aNumber,
    );
  }
}

// Register the entity with a store name
EntityRegistry.register("my-entities", MyEntity);

2. Create a concrete DAO class

IndexedDBDAO is abstract. Extend it for your entity and pass the database name and store name to the constructor.

import { IndexedDBDAO } from "@schorts/indexed-db-dao";

class MyEntityDAO extends IndexedDBDAO<MyEntityModel, MyEntity> {
  constructor() {
    super("MyDatabase", "my-entities");
  }
}

3. Use the DAO for CRUD and Criteria

The DAO supports full CRUD plus Criteria queries for filtering, ordering, limits, and offsets.

import { Criteria, Operator, Direction, UUIDValue } from "@schorts/shared-kernel";
import { v4 } from "uuid";

async function main() {
  const dao = new MyEntityDAO();

  // Create
  const entityId = new UUIDValue(v4());
  const entity = new MyEntity(entityId, "My Offline Entity", 42);
  await dao.create(entity);

  // Query with Criteria
  const criteria = new Criteria()
    .where("name", Operator.EQUAL, "My Offline Entity")
    .orderBy("aNumber", Direction.DESC)
    .limitResults(1);

  const found = await dao.findOneBy(criteria);
  console.log("Found:", found?.toPrimitives());

  // Update
  if (found) {
    const updated = new MyEntity(found.id, "Updated Offline Entity", 100);
    await dao.update(updated);
  }

  // Delete
  if (found) {
    await dao.delete(found);
  }
}

main();

4. Unit of Work

You can group multiple DAO operations into a single transaction using IndexedDBUnitOfWork and a UnitOfWorkRunner.

import { IndexedDBUnitOfWorkRunner } from "@schorts/indexeddb-dao";

const runner = new IndexedDBUnitOfWorkRunner("MyDatabase", ["my-entities"]);

await runner.run(async (uow) => {
  await dao.create(new MyEntity(new UUIDValue(v4()), "Batch Entity", 1), uow);
  await dao.create(new MyEntity(new UUIDValue(v4()), "Batch Entity 2", 2), uow);
  // Both succeed or rollback together
});

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue.

License

This project is licensed under the LGPL‑3.0‑or‑later License.