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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@devs-toolbox/repository

v1.0.1

Published

A persisting, in-memory database-like item repository

Downloads

3

Readme

Dev's Toolbox // Repository

A persisting, in-memory database-like item repository

API

Repository.prepare(options)

Given a Repository options object, create a repository, load its data and return the newly created repository.

This is commonly preferred over creating and preparing Repository objects manually.

Options

| Option | Default Value | Description | | ----------- | ------------- | --------------------------------------------------------------------------------------------- | | typeguard | None | An optional typeguard to check data integrity when loading data from an adapter | | defaults | None | A partial object of the model type defining default values when inserting partials | | adapter | None | An interface which provides read and write functions for the repository to persist itself | | idGenerator | uuidV4 | If provided, is called to generate random String IDs |

new Repository(options?)

Create a new repository with the given options. The repository is not populated with data by default. You must manually call .prepare() on it and await its return.

.insertMany(models)

Insert an array of models into the repository

.insert(model)

Insert a single model into the rpeository

.insertPartial(model)

Insert a single model, applying defaults supplied at repository creation time

.remove(modelOrId)

Remove the given model, or remove a model by ID. If an array is provided, all elements in the array are removed.

.removeWhere(descriptor)

Remove models where the given descriptor matches (see "Descriptor" section below)

.update(partialModel)

Given a partial model with its ID attached, update the model in the repository

.updateWhere(descriptor, setValues)

Set the values defined in setValues on models where the descriptor matches.

.upsert(model)

Inserts the model if the repository does not already contain it. Ohterwise, update the model.

.contains(model)

Check if the given model is in the repository

.containsIndex(id)

Check if the given model ID is found in the repository

.findById(id)

Fetch a model by ID

.find(descriptor, options?)

Find models based on a partial description or predicate. Pass true to fetch all models in the repository.

Find Options

| Option | Type | Description | | ------- | ---------------------------------- | ------------------------------------------------ | | skip | number | How many records to skip | | limit | number | The max number of models to fetch | | sort | [keyof Model, "ASC" or "DESC"] | A tuple of what field to sort by and ASC or DESC |

.findOne(descriptor)

Find the first element that matches the descriptor

.truncate()

Remove all models in the repository

.size()

Return the number of models in the repository

.generateId()

Return a new ID from this repository's ID generator function

Descriptor

A descriptor is one of two things:

  • A function which acts like a filter function, taking models and returning true or false
  • A partial object containing keys and values to search for matching models