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

@varasto/query

v3.0.0

Published

Query and bulk operation utilities for Varasto storage

Downloads

10

Readme

@varasto/query

npm

Collection of useful query and bulk operation utilities for Varasto storages that use simple-json-match schemas for finding entries.

Installation

$ npm install --save @varasto/query

Usage

The package provides following functions.

Searching for single entry

find()

find(
  storage: Storage,
  namespace: string,
  schema: Schema
): Promise<JsonObject | undefined>

Searches for an entry from given namespace that matches given schema and returns value of first matching result. If no entry in the namespace matches the schema, undefined is returned instead.

findKey()

findKey(
  storage: Storage,
  namespace: string,
  schema: Schema
): Promise<string | undefined>

Searches for an entry from given namespace that matches given schema and returns key of first matching result. If no entry in the namespace matches the schema, undefined is returned instead.

findEntry()

findEntry(
  storage: Storage,
  namespace: string,
  schema: Schema
): Promise<[string, JsonObject] | undefined>

Searches for an entry from given namespace that matches given schema and returns both key and value of first matching result. If no entry in the namespace matches the schema, undefined is returned instead.

Searching for multiple entries

findAll()

findAll<T extends JsonObject>(
  storage: Storage,
  namespace: string,
  schema: Schema
): AsyncGenerator<T>

Searches for entries from given namespace that match given schema and returns their values. If no entries match the given schema, empty array is returned instead.

findAllKeys()

findAllKeys(
  storage: Storage,
  namespace: string,
  schema: Schema
): AsyncGenerator<string>

Searches for entries from given namespace that match given schema and returns their keys. If no entries match the given schema, empty array is returned instead.

findAllEntries()

findAllEntries<T extends JsonObject>(
  storage: Storage,
  namespace: string,
  schema: Schema
): AsyncGenerator<[string, T]>

Searches for entries from given namespace that match given schema and returns them in an array. If no entries match the given schema, empty array is returned instead.

Partition utilities

partition()

partition<T extends JsonObject>(
  storage: Storage,
  namespace: string,
  schema: Schema
): Promise<[T[], T[]]>

Splits values of entries from given namespace into two arrays depending on whether they match the given schema. Entries that match the schema will be returned first element of returned array, while the remaining entries will be second.

partitionKeys()

partitionKeys(
  storage: Storage,
  namespace: string,
  schema: Schema
): Promise<[string[], string[]]>

Splits keys of entries from given namespace into two arrays depending on whether they match the given schema. Entries that match the schema will be returned first element of returned array, while the remaining entries will be second.

partitionEntries()

partitionEntries<T extends JsonObject>(
  storage: Storage,
  namespace: string,
  schema: Schema
): Promise<[[string, T][], [string, T][]]>

Splits entries from given namespace into two arrays depending on whether they match the given schema. Entries that match the schema will be returned first element of returned array, while the remaining entries will be second.

Bulk operations

updateAll()

updateAll<T extends JsonObject>(
  storage: Storage,
  namespace: string,
  schema: Schema,
  value: Partial<T>
): AsyncGenerator<T>

Performs an bulk update where all entries from given namespace that match the given schema are partially updated with given value. Returns updated values or empty array if no entry matched the given schema.

updateAllEntries()

updateAllEntries<T extends JsonObject>(
  storage: Storage,
  namespace: string,
  schema: Schema,
  value: Partial<T>
): AsyncGenerator<[string, T]>

Performs an bulk update where all entries from given namespace that match the given schema are partially updated with given value. Returns updated entries (key and value) or empty array if no entry matched the given schema.

deleteAll()

deleteAll(
  storage: Storage,
  namespace: string,
  schema: Schema
): Promise<number>

Performs an bulk deletion where all entries from the given namespace that match the given schema are deleted. Returns total number of deleted entries or 0 if no entry matched the given schema.