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

thng-query

v0.0.4

Published

DSL for querying EVRYTHNG API

Downloads

1

Readme

thng-query

DSL for working with EVRYTHNG Platform API

tq --key $OPERATOR_KEY 'products tagged embedded where photos~gif'
const tq = require('tq');

tq.setup({
  authorization: process.env.OPERATOR_KEY
});

tq.run('thngs with name Advanced* where identifiers.ser^673')
    .then(console.log)
    .catch(console.error);

Query syntax

Each query consist of stages:

|     fetch stage        |     filter stage         |
'thngs with name Advanced* where identifiers.ser^673'

Each stage is independent from the other in terms of data processing. Think about it as about stream. That also means independent syntax for each one of them.

Stages

Fetch
'target selector'
'quantifier target selector'

quantifier

  • int string (14, 203, 1) target:
  • thng(s)
  • product(s) selector:
  • with name | named
  • with tag | tagged
Filter
'where filterExpression'

filterExpression

  • filterField filterOperator filterValue filterField
  • string path to a property of entity filterOperator
  • = - exact match
  • ~ - inclusion check
  • ^ - starts with
  • $ - ends with filterValue
  • string

Interface

As library

const tq = require('tq');

/**
 * Runs a given query. Throws if any errors during parsing
 * @param {String} query 
 */
tq.run('query');

/**
 * Consumes global settings for tq
 * @param {Settings} settings   
 */
tq.setup({})

As CLI app

# To see all available options
tq --help 
# Will dump output json straight to stdout
tq -k $OPERATOR_KEY 'thngs where properties.online = true'
# Could be used with formatters, like jq
tq -k $OPERATOR_KEY 'products with tag overcomplicated' | jq .

Settings

tq.setup({
  /**
   * Defines if tq will produce 
   * debug output
   * 
   * @type {Boolean}
   */
  debug: false,
  
  /**
   * Defines max depth of query pipeline i.e. max amount of 
   * pipeline repetitions attempted to fulfill output.
   * Imagine, account has 10k thngs, tagged "connected"
   * running a query with settings.perPage=1 against them would attempt
   * to fulfill settings.maxItems (100 by default) which would be actually 
   * capped at 20 by default.
   * 
   * @type {Number}
   */
  depth: 20,
  
  /**
   * Defines how many entities will be queries by fetch stage
   * Ends up as a "perPage" query param on all outgoing requests
   * 
   * @type {Number}
   */
  perPage: 100,
  
  /**
   * Defines how many results at max pipeline will expect
   * 
   * @type {Number}
   */
  maxResults: 100,
  
  /**
   * API Key to use for queries
   * 
   * @see https://developers.evrythng.com/docs/api-key-scopes-and-permissions
   * @type {String} 
   */
  authorization: '',
  
  /**
   * API Url to use
   * 
   * @type {String}
   */
  apiUrl: 'https://api.evrythng.com',
});

Development

# Will complile current grammar and run nearley-test 
# against given expression
npm run debug -- 'thngs where createdAt $ 65'

# Will complile nearley grammar to parser
npm run compile

# Will produce a random string which will be valid
# when feed to the runner
# i.e. "PrOdUCTs    with nAMe j where  YG ~pol"
npm run unparse