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

@targetprocess/suggestion-context

v0.0.6

Published

Utils to build suggestions for various DSLs

Downloads

51

Readme

Targetprocess DSL suggestion tools

This package exposes several modules which aim to assist with building auto-completion suggestions for Targetprocess DSLs.

It was designed primarily for API v2 DSL (also used in Metrics) and Automation Rules DSL, but can probably be used with other DSLs as well.

It defines several key concepts seen in these DSLs, such as:

  • Types
    • Domain types, e.g. User Story or String
    • Collection types, e.g. Collection of Bugs, as seen on UserStory.Bugs
    • Generic types, e.g. arguments and return types of collection methods like .Where(...)
    • Union types, e.g. (UserStory or Bug), which can be used when several entity types are selected in Metrics editor or Rule Engine UI
  • Field access, e.g. Feature.Name
  • Function call, e.g. IIF(A, B, C) or Bugs.Where
  • Root and nested scopes
    • Root scope defines a type of entity which serves as invisible root of formulas. For example, in Metrics it can also be accessed by special "field" called It.
    • Nested scope, most notable example is "enumerable methods" like .Where or .Select on collections. Inside these methods the scope (also available through It) refers to the element of collection instead of root entity type. This actually resembles a concept of lambdas from your typical programming languages.

Building suggestions

Typically, the process of building auto-completion suggestions for user-input DSL involves traversing some parse tree produced by the parser, where each node has information about its position in the original text.

Let's take a simple incomplete formula text entered by the user, e.g. Feature.Na. We assume that this formula is written for User Story as root entity type. The caret position is located at the end of the text, after Na.

    Field Access (caret is here)
       /      \
    "Na"   Field Access
             /      \
        "Feature"  <Root>

During the traversal the current text caret position is compared with the mentioned positions of parse tree nodes. When we reach some node which matches the caret position (which is the top-level Field Access), we try to infer the information about types around that node.

In our case we can infer that the target type of the expression on which we try to access something starting with "Na" has the type Feature.

Given that, we can then find all fields containing Na substring in their name.

Suggestion context

This module doesn't actually provide anything for parse tree traversal, because this logic varies from one DSL to another, and depends on the used DSL grammar, parser implementation, and suggestion client requirements.

Instead it provides a data structure called SuggestionContext, which allows to keep the parser-agnostic information about the current traversal state, such as the type of the root entity, nesting level, etc.

This context also allows to semi-automatically build other contexts for operations like "field access" or "nested scope of function call".

Usages

You can see the example usage of this package in Metrics Setup UI and Automation Rules UI.

By default, all parsing and analysis errors are logged to console. You can override the library's logger in defaultLoggerFactory, for example to disable all logging:

import { defaultLoggerFactory } from '@targetprocess/suggestion-context'

defaultLoggerFactory.logger = {
  error() {
    // do nothing
  }
}