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

jqlgen

v2.2.1

Published

A better way to generate jql

Downloads

34

Readme

The what

When string interpolation jql is not enough, yes I have this problem

The goal

Make it impossible to generate invalid jql with a simple yet complex api

Features

  • ✔️ Simple
  • 🧪 Well tested (I use this myself in my semi big projects)
  • 👌 Follows SQL order by priority info
  • 🤘 Impossible to generate invalid JQL (please open an issue if you found an edge-case)

Quick start 🧙

import { jql } from "jqlgen";

jql({ left: "summary", sign: "=", right: "nice" })
    .and({
        left: "summary",
        sign: "!=",
        right: "look mom, im cool",
    })
    .or(
        jql({ left: "foo", sign: "in", right: [1, 2, 3] }).and({
            left: "bar",
            sign: "!=",
            right: 2,
        })
    )
    .orderBy({ field: "issuekey", type: "asc" })
    .toString();

// ((summary = 'nice') and (summary != 'look mom, im cool') or ((foo in (1,2,3)) and (bar != 2))) order by issuekey asc

Injecting unknown jql statements

For example when you want to integrate unknown jql queries into your own, for example from a Jira filter, there exists a simple function for that

jql().injectExternal("a = 'b' order by summary asc");

This is pretty the same as calling

jql({ left: "a", sign: "=", right: "b" }).orderBy({ field: "summary", type: "asc" });

⚠️ Note: jql validation is out of scope for this package, therefore you are responsible for calling injectExternal with valid jql strings

A note about order by

You can call order by at any level, it gets resolved like this: final string output: [parent] asc/desc, [child-parent] asc/desc, [child-child-parent] asc/desc

It's not the other way around, because jql sorts the first field the last, I will try to maintain sql behavior so I am reversing it

An example

const output = jql()
    .and(jql().orderBy({ field: "child", type: "asc" }))
    .orderBy({ field: "parent", type: "asc" });

expect(output.toString()).toBe("order by parent asc, child asc");

API

declare class JqlGen {
    constructor(statement?: JqlStatement);
    and(statement: JqlGen | JqlStatement): JqlGen;
    or(statement: JqlGen | JqlStatement): JqlGen;
    orderBy(orderByItem: OrderByOperator): JqlGen;
    injectExternal(str: string): JqlGen;
    toString(): string;
}

/** if you're lazy, hey I don't blame you, tiny wrapper to not spam new new new */
declare function jql(statement?: JqlStatement): JqlGen;

Nest as much as you want

Yes, you can go wild like this

const output = jql({
    left: "c",
    sign: "<",
    right: "d",
})
    .and(
        jql({ left: "e", sign: "~", right: "f" }).or(
            jql({ left: "g", sign: ">", right: "h" })
                .and(
                    jql({ left: "i", sign: "=", right: "j" }).or(
                        jql({ left: "k", sign: "!=", right: "l" }).and(
                            jql({ left: "m", sign: "is not", right: "n" }).or(
                                jql({ left: "o", sign: "in", right: ["p", "q", "r"] })
                                    .and(
                                        jql({
                                            left: "s",
                                            sign: "not in",
                                            right: ["t", "u", "v"],
                                        }).or(
                                            jql({ left: "w", sign: "!~", right: "x" }).and(
                                                jql({ left: "y", sign: "was", right: "z" }).or(
                                                    jql({
                                                        left: "aa",
                                                        sign: "was in",
                                                        right: "bb",
                                                    }).and(
                                                        jql({
                                                            left: "cc",
                                                            sign: "was not in",
                                                            right: "dd",
                                                        }).orderBy({
                                                            field: "one",
                                                            type: "desc",
                                                        })
                                                    )
                                                )
                                            )
                                        )
                                    )
                                    .orderBy({
                                        field: "two",
                                        type: "asc",
                                    })
                            )
                        )
                    )
                )
                .orderBy({ field: "three", type: "desc" })
        )
    )
    .toString();

// ((c < 'd') and ((e ~ 'f') or ((g > 'h') and ((i = 'j') or ((k != 'l') and ((m is not 'n') or ((o in ('p','q','r')) and ((s not in ('t','u','v')) or ((w !~ 'x') and ((y was 'z') or ((aa was in 'bb') and (cc was not in 'dd')))))))))))) order by three desc, two asc, one desc

Of course, your app should dynamically generate this stuff