1.7.0 • Published 17 days ago

groq-js v1.7.0

Weekly downloads
4,583
License
MIT
Repository
github
Last release
17 days ago

GROQ-JS

npm stat npm version gzip size size

GROQ-JS is a JavaScript implementation of GROQ which follows the official specification.

import {parse, evaluate} from 'groq-js'

let input = '*[_type == "user"]{name}'

// Returns an ESTree-inspired syntax tree
let tree = parse(input)

let dataset = [
  {_type: 'user', name: 'Michael'},
  {_type: 'company', name: 'Bluth Company'},
]

// Evaluate a tree against a dataset
let value = await evaluate(tree, {dataset})

// Gather everything into one JavaScript object
let result = await value.get()

console.log(result)

Table of contents:

Installation

npm i groq-js
yarn add groq-js
pnpm install groq-js

Documentation

See API.md for the public API.

Learn GROQ

Free egghead GROQ introduction course by John Lindquist

Versioning

GROQ

The GROQ spec version is independent of the groq-js library version. When you import groq-js you need to be explicit on which GROQ version you want to use. The GROQ version is tied to the groq-spec. This allows us to update the library and its API independent of the GROQ version.

GROQ-JS

GROQ-JS follows SemVer. See the changelog for recent changes. This is an "experimental" release and anything may change at any time, but we're trying to keep changes as minimal as possible:

  • The public API of the parser/evaluator will most likely stay the same in future versions.
  • The syntax tree is not considered a public API and may change at any time.
  • This package always implements the latest version of GROQ according to the specification.

Releasing a new version of GROQ-JS

Run the "CI & Release" workflow. Make sure to select the main branch and check "Release new version".

Version will be automatically bumped based on conventional commits since the last release.

Semantic release will only release on configured branches, so it is safe to run release on any branch.

Note: commits with chore: will be ignored. If you want updated dependencies to trigger a new version, use fix(deps): instead.

License

MIT © Sanity.io

Tests

Tests are written in Jest:

# Install dependencies
npm i

# Run tests
npm test

You can also generate tests from the official GROQ test suite:

# Fetch and generate test file:
./test/generate.sh

# Run tests as usual:
npm test

You can generate tests from a specific version:

GROQTEST_SUITE_VERSION=v0.1.33 ./test/generate.sh

or from a file (as generated by the test suite):

GROQTEST_SUITE=suite.ndjson ./test/generate.sh

The test arguments are passed to tap, so you can use arguments, e.g. to run a specific set of tests:

npm test -g "array::join"
1.6.1

17 days ago

1.6.0

17 days ago

1.7.0

17 days ago

1.5.0-canary.3

1 month ago

1.5.0

1 month ago

1.5.0-canary.2

1 month ago

1.5.0-canary.1

2 months ago

1.4.4-canary.1

2 months ago

1.4.3

2 months ago

1.4.2

2 months ago

1.4.1

3 months ago

1.4.0

3 months ago

1.3.0

7 months ago

1.2.0

8 months ago

1.1.12

8 months ago

1.1.11

9 months ago

1.1.10

9 months ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.2.1-beta.0

1 year ago

1.2.1-beta.1

1 year ago

1.2.0-beta.1

1 year ago

1.2.0-beta.0

1 year ago

1.1.1

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.4-beta.1

1 year ago

1.1.4-beta.0

1 year ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.0-1

2 years ago

1.0.0-0

2 years ago

0.4.0-beta.2

2 years ago

0.4.0-beta.0

2 years ago

0.4.0-beta.1

2 years ago

0.3.0-beta.2

3 years ago

0.3.0-beta.1

3 years ago

0.3.0

3 years ago

0.3.0-beta.0

3 years ago

0.2.0

3 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago