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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@subshell/data-repositories

v1.2.0

Published

This library allows you to use convenient repositories backed by Dexie and IndexedDB.

Downloads

908

Readme

@subshell/data-repositories

CI npm version

This is a wrapper around Dexie, which itself is already a wrapper around IndexedDB. This wrapper allows to create repository classes, similar as you might be used to from Java and Spring Data.

Short example of a repository:


/*********************************************************
* Define a class you want to store and a repository class:
*********************************************************/


class Person {    
    @Id() name: string;
    @Unique() identificationNumber: number;
    @Indexed() email: string;
    
    constructor(name: string, identificationNumber: number, email: string) {
        this.name = name;
        this.identificationNumber = identificationNumber;
        this.email = email;
    }
}

class PersonRepository extends AbstractRepository<Person, string> {
    constructor() {
        super(DatabaseAccess.get(PersonRepository.name), Person);
    }
}

/*****************************
* Somewhere else in your code:
*****************************/

const personRepository = new PersonRepository();
const gandalf = new Person("Gandalf", 42, "[email protected]");

// Save the object
personRepository.save(gandalf).subscribe();

// Find the object
personRepository.findById("Gandalf").subscribe(foundGandalf => {
    // do something with it here
});

You can define a field to be the primary key of the repository by adding @Id() to it. If you want a number that is incremental you can use @IncrementalId(). If you want multiple properties to be a compound primary key you can add multiple @CompoundId() decorators to those fields. If you are using @IncrementalId() or @CompoundId() you need to add an additional generic parameter to the repository, e.g.:

In any case you must use one of the @Id(), @CompoundId() or @IncrementalId() decorators in your repository.

/*****************************
* Compound ID:
*****************************/

class Person {
    @CompoundId() firstName: string;
    @CompoundId() lastName: string;
    // ...
}
class PersonRepository extends AbstractRepository<Person, [string, string]> {
    // ...
}

/*****************************
* Incremental ID:
*****************************/
class Person {
    @IncrementalId() identificationNumber: number;
    name: string;
    // ...
}
class PersonRepository extends AbstractRepository<Person, number> {
    // ...
}

To make keys unique you can use @Unique() and to have indexed fields (you can only use those in search queries) you need to use @Indexed(). @CompoundId() fields are not automatically indexed separately, so if you want to be able to query these you need to additionally add the @Indexed() decorator to them.

If you should at a later point upgrade your data model and e.g. add a unique or indexed field, you need to specify the respective database version in the decorator, e.g. @Unique({sinceVersion: 2}). Versions start with 1 so if you update your model it is definitely at least version 2.

Methods you can use on repositories are: save, saveAll, findById, findAll, delete, clear, count.

Additionally, the AbstractRepository and AbstractMappingRepository allow searching using simple property equality checks and predicates with the .search() method. This functionality is very basic and far from what Dexie actually offers. This is currently a low priority TODO but feel free to contribute.

It is recommended to have separate Dexie databases for every repository (due to some issues with Dexie and the versioning across multiple repositories). Use the DatabaseAccess class with care and try not to create those classes with duplicate names unless you know what you do.

The repositories naturally work with RxJS and Observables. Due to the nature of IndexedDB there is no synchronous way to read or write any data.


Take a look at this project from the subshell team. We make Sophora: a content management software for content creation, curation, and distribution. Join our team! | Imprint