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

@deepr/runtime

v1.1.0

Published

Simple Deepr runtime

Readme

@deepr/runtime

Simple Deepr runtime.

Installation

npm install @deepr/runtime

Example

import {invokeQuery} from '@deepr/runtime';

(async () => {
  // Given the following "root" object:
  const root = {
    async getMovie(id) {
      // Let's pretend we are reading a record from a database
      if (id === 'abc123') {
        return {
          title: 'Inception',
          year: 2010,
          actors: [
            {fullName: 'Leonardo DiCaprio', popularity: 90},
            {fullName: 'Joseph Gordon-Levitt', popularity: 70}
          ]
        };
      }
      throw new Error('Movie not found');
    }
  };

  // Invoking the following query:
  await invokeQuery(root, {
    'getMovie=>movie': {
      '()': ['abc123'],
      '=>': {
        title: true,
        actors: {'[]': [], 'fullName': true}
      }
    }
  });

  // Will return:
  // {
  //   movie: {
  //     title: 'Inception',
  //     actors: [{fullName: 'Leonardo DiCaprio'}, {fullName: 'Joseph Gordon-Levitt'}]
  //   }
  // }
})();

API

invokeQuery(root, query, [options]) => result

Invoke the specified query on root, and return the result of the invocation. If a promise is encountered during the execution, then a promise that resolves with the result is returned.

Example:

const result = await invokeQuery(root, {
  movies: {
    '[]': [],
    'title': true,
    'year': true
  }
});

root

An object from which the query will be evaluated.

Example:

{
  "movies": [
    {
      "title": "Inception",
      "year": 2010
    },
    {
      "title": "The Matrix",
      "year": 1999
    }
  ]
}

query

A Deepr query.

Example:

{
  "movies": {
    "[]": [],
    "title": true,
    "year": true
  }
}

Learn more about Deepr queries here: https://github.com/deeprjs/deepr.

options

An optional object of options.

context

A context that will be passed as the last parameter to all invoked methods.

ignoreKeys

A key or an array of keys to be ignored when executing the query. A key can be specified as a string or a RegExp.

Examples:

  • Using the string 'password' will ignore every key named 'password'.
  • Using the RegExp /^_/ will ignore every key starting with an underscore.
acceptKeys

A key or an array of keys to be accepted regardless if they are ignored using the ignoreKeys option. A key can be specified as a string or a RegExp.

Example:

  • Specifying the string '_id' will accept this key even if the ignoreKeys option includes the RegExp /^_/.
ignoreBuiltInKeys (default: true)

If true (the default), all JavaScript built-in keys will be ignored. This includes object and function built-in keys such as constructor, prototype, apply, caller, __proto__, hasOwnProperty, etc. Even if they are built-in, the keys name and length are considered safe, and therefore accepted.

For obvious security reasons, it is strongly discouraged to disable this option.

authorizer(key, operation) => boolean

A function that is called for each key to authorize any operation.

The function receives a key and an operation which can be either 'get' for reading an attribute or 'call' for invoking a method.

The function must return true to authorize an operation. If false is returned, the evaluation of the query stops immediately, and an error is thrown.

The function can be either synchronous or asynchronous (using async or returning a promise).

Finally, the value of this in the function is the current node of the query being evaluated.

Example:

function authorizer(key, operation) {
  if (key === 'title' && operation === 'get') {
    return true; // Authorize getting the 'title' attribute
  }
  if (key === 'get' && operation === 'call') {
    return true; // Authorize invoking the get() method
  }
  return false; // Decline everything else
}
errorHandler(error) => value

A function that is called when an error is encountered while invoking the query.

If the function throws an error (the received error or any other error), the invocation of the query is stopped and the responsibility for catching the thrown error is transferred to the caller of invokeQuery().

If the function returns a value, the invocation of the query is stopped and the value is injected into the result of the query without failing the execution of invokeQuery().

The value of this in the function is the current node of the query being evaluated.

Example:

function errorHandler(error) {
  return error; // Inject the error into the result of the query
}

License

MIT