Comparing version 1.1.4-beta.1 to 1.1.4
MIT License | ||
Copyright (C) 2019 Sanity Inc. | ||
Copyright (C) 2019 Sanity.io | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
{ | ||
"name": "groq-js", | ||
"version": "1.1.4-beta.1", | ||
"version": "1.1.4", | ||
"keywords": [ | ||
"sanity", | ||
"json", | ||
"query", | ||
"groq" | ||
], | ||
"license": "MIT", | ||
"author": "Sanity.io <hello@sanity.io>", | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"source": "./src/1.ts", | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs", | ||
"default": "./dist/index.js" | ||
"import": { | ||
"types": "./dist/1.esm.d.ts", | ||
"default": "./dist/1.esm.mjs" | ||
}, | ||
"require": { | ||
"types": "./dist/1.umd.d.ts", | ||
"default": "./dist/1.umd.cjs" | ||
}, | ||
"default": "./dist/1.umd.cjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"source": "./src/1.ts", | ||
"types": "./dist/index.d.ts", | ||
"main": "./dist/1.umd.cjs", | ||
"types": "./dist/1.umd.d.ts", | ||
"files": [ | ||
@@ -29,18 +36,12 @@ "dist", | ||
"prebuild": "npx rimraf dist", | ||
"build": "pkg build --strict", | ||
"build": "rollup -c", | ||
"prepublishOnly": "npm run build", | ||
"prettify": "prettier --write src/**/*.ts src/*.ts", | ||
"prettify-check": "prettier --check src/**/*.ts src/*.ts", | ||
"prettify": "prettier --write .", | ||
"prettify-check": "prettier --check .", | ||
"test": "tap --no-timeout test/*.test.*", | ||
"test:generate": "./test/generate.sh" | ||
}, | ||
"browserslist": [ | ||
"> 0.2% and supports es6-module and supports es6-module-dynamic-import and not dead and not IE 11", | ||
"maintained node versions" | ||
], | ||
"tap": { | ||
"check-coverage": false, | ||
"node-arg": [ | ||
"--loader", | ||
"esbuild-register/loader", | ||
"-r", | ||
@@ -51,19 +52,20 @@ "esbuild-register" | ||
"devDependencies": { | ||
"@sanity/pkg-utils": "^2.0.3", | ||
"@types/tap": "^15.0.7", | ||
"@typescript-eslint/eslint-plugin": "^5.47.1", | ||
"@typescript-eslint/parser": "^5.47.1", | ||
"esbuild-register": "^3.4.2", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-config-sanity": "^6.0.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-simple-import-sort": "^8.0.0", | ||
"@rollup/plugin-typescript": "^8.3.3", | ||
"@sanity/semantic-release-preset": "^3.0.2", | ||
"@types/tap": "^15.0.5", | ||
"@typescript-eslint/eslint-plugin": "^4.22.1", | ||
"@typescript-eslint/parser": "^4.22.1", | ||
"esbuild": "^0.14.2", | ||
"esbuild-register": "^3.2.0", | ||
"eslint-config-sanity": "^5.1.0", | ||
"ndjson": "^2.0.0", | ||
"np": "^7.6.3", | ||
"prettier": "^2.8.1", | ||
"prettier": "^2.2.1", | ||
"prettier-plugin-packagejson": "^2.3.0", | ||
"rimraf": "^3.0.2", | ||
"semver": "^7.3.8", | ||
"tap": "^16.3.2", | ||
"typescript": "^4.9.4" | ||
"rollup": "^2.75.7", | ||
"rollup-plugin-dts": "^4.2.2", | ||
"semver": "^7.3.5", | ||
"tap": "^15.0.6", | ||
"tslib": "^2.2.0", | ||
"typescript": "^4.2.4" | ||
}, | ||
@@ -70,0 +72,0 @@ "engines": { |
@@ -1,3 +0,8 @@ | ||
# GROQ-JS | ||
# GROQ-JS<!-- omit in toc --> | ||
[![npm stat](https://img.shields.io/npm/dm/groq-js.svg?style=flat-square)](https://npm-stat.com/charts.html?package=groq-js) | ||
[![npm version](https://img.shields.io/npm/v/groq-js.svg?style=flat-square)](https://www.npmjs.com/package/groq-js) | ||
[![gzip size][gzip-badge]][bundlephobia] | ||
[![size][size-badge]][bundlephobia] | ||
GROQ-JS is a JavaScript implementation of [GROQ](https://www.sanity.io/docs/data-store/how-queries-work) which follows the official specification. | ||
@@ -30,4 +35,8 @@ | ||
- [Installation](#installation) | ||
- [Documentation](API.md) | ||
- [Documentation](#documentation) | ||
- [Learn GROQ](#learn-groq) | ||
- [Versioning](#versioning) | ||
- [GROQ](#groq) | ||
- [GROQ-JS](#groq-js-1) | ||
- [Releasing a new version of GROQ-JS](#releasing-a-new-version-of-groq-js) | ||
- [License](#license) | ||
@@ -39,9 +48,13 @@ - [Tests](#tests) | ||
```bash | ||
# NPM | ||
npm i groq-js | ||
``` | ||
# Yarn | ||
```bash | ||
yarn add groq-js | ||
``` | ||
```bash | ||
pnpm install groq-js | ||
``` | ||
## Documentation | ||
@@ -73,25 +86,11 @@ | ||
We use the `np` package to roll out new versions to NPM. You can read up more on the package [here](https://github.com/sindresorhus/np). | ||
Run the ["CI & Release" workflow](https://github.com/sanity-io/groq-js/actions/workflows/test.yml). Make sure to select the main branch and check "Release new version". | ||
Make sure you update the CHANGELOG before releasing a new version. Use the previous updates as guidance for the desired formatting, and remember we use [SemVer](https://semver.org)! | ||
Version will be automatically bumped based on [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) since the last release. | ||
To interactively release the version run the following: | ||
Semantic release will only release on configured branches, so it is safe to run release on any branch. | ||
```bash | ||
npx np --no-release-draft | ||
``` | ||
Note: commits with `chore:` will be ignored. If you want updated dependencies to trigger | ||
a new version, use `fix(deps):` instead. | ||
The `--no-release-draft` flag prevents a GitHub release draft being created. | ||
The above `np` command will: | ||
1. Update the `version` field in `package.json` | ||
2. Publish the new version to NPM | ||
3. Create a Git tag | ||
4. Commit the Git tag and the updated `package.json` to version control, then push the changes upstream | ||
It also peforms some pre-release checks, like running tests and ensuring you're releasing from the `main` branch. | ||
For further context on the package and for instructions on how to bump versions in a non-interactive way [visit the README](https://github.com/sindresorhus/np). | ||
## License | ||
@@ -140,1 +139,5 @@ | ||
``` | ||
[gzip-badge]: https://img.shields.io/bundlephobia/minzip/groq-js?label=gzip%20size&style=flat-square | ||
[size-badge]: https://img.shields.io/bundlephobia/min/groq-js?label=size&style=flat-square | ||
[bundlephobia]: https://bundlephobia.com/package/groq-js |
25
src/1.ts
@@ -0,25 +1,2 @@ | ||
export {parse} from './parser' | ||
export {evaluate} from './evaluator' | ||
export type {GroqFunction, GroqFunctionArg, GroqPipeFunction} from './evaluator/functions' | ||
export type {Scope} from './evaluator/scope' | ||
export type {EvaluateOptions} from './evaluator/types' | ||
export type {Context, Executor} from './evaluator/types' | ||
export * from './nodeTypes' | ||
export {parse} from './parser' | ||
export type {ParseOptions} from './types' | ||
export type { | ||
AnyStaticValue, | ||
ArrayValue, | ||
BooleanValue, | ||
DateTime, | ||
DateTimeValue, | ||
GroqType, | ||
NullValue, | ||
NumberValue, | ||
ObjectValue, | ||
Path, | ||
PathValue, | ||
StaticValue, | ||
StreamValue, | ||
StringValue, | ||
Value, | ||
} from './values' |
import {ExprNode} from '../nodeTypes' | ||
import {NULL_VALUE, Value} from '../values' | ||
import {evaluate} from './evaluate' | ||
import {Scope} from './scope' | ||
import {NULL_VALUE, Value} from '../values' | ||
@@ -6,0 +6,0 @@ function canConstantEvaluate(node: ExprNode): boolean { |
@@ -1,4 +0,9 @@ | ||
import {ExprNode, FuncCallNode, PipeFuncCallNode} from '../nodeTypes' | ||
import * as NodeTypes from '../nodeTypes' | ||
import {operators} from './operators' | ||
import {Scope} from './scope' | ||
import {EvaluateOptions, Executor} from './types' | ||
import { | ||
DateTime, | ||
FALSE_VALUE, | ||
fromDateTime, | ||
fromJS, | ||
@@ -11,9 +16,6 @@ fromNumber, | ||
} from '../values' | ||
import {operators} from './operators' | ||
import {partialCompare} from './ordering' | ||
import {Scope} from './scope' | ||
import {EvaluateOptions, Executor} from './types' | ||
export function evaluate( | ||
node: ExprNode, | ||
node: NodeTypes.ExprNode, | ||
scope: Scope, | ||
@@ -29,4 +31,4 @@ execute: Executor = evaluate | ||
type ExecutorMap = { | ||
[key in ExprNode['type']]: ( | ||
node: NarrowNode<ExprNode, key>, | ||
[key in NodeTypes.ExprNode['type']]: ( | ||
node: NarrowNode<NodeTypes.ExprNode, key>, | ||
scope: Scope, | ||
@@ -169,7 +171,7 @@ exec: Executor | ||
FuncCall({func, args}: FuncCallNode, scope: Scope, execute) { | ||
FuncCall({func, args}: NodeTypes.FuncCallNode, scope: Scope, execute) { | ||
return func(args, scope, execute) | ||
}, | ||
async PipeFuncCall({func, base, args}: PipeFuncCallNode, scope: Scope, execute) { | ||
async PipeFuncCall({func, base, args}: NodeTypes.PipeFuncCallNode, scope: Scope, execute) { | ||
const baseValue = await execute(base, scope) | ||
@@ -461,3 +463,3 @@ return func(baseValue, args, scope, execute) | ||
export function evaluateQuery( | ||
tree: ExprNode, | ||
tree: NodeTypes.ExprNode, | ||
options: EvaluateOptions = {} | ||
@@ -464,0 +466,0 @@ ): Value | PromiseLike<Value> { |
import type {ExprNode} from '../nodeTypes' | ||
import {totalCompare} from './ordering' | ||
import {Scope} from './scope' | ||
import {evaluateScore} from './scoring' | ||
import {Executor} from './types' | ||
import { | ||
getType, | ||
fromNumber, | ||
TRUE_VALUE, | ||
FALSE_VALUE, | ||
NULL_VALUE, | ||
Value, | ||
DateTime, | ||
FALSE_VALUE, | ||
fromJS, | ||
fromNumber, | ||
fromString, | ||
fromPath, | ||
fromString, | ||
getType, | ||
NULL_VALUE, | ||
Path, | ||
fromJS, | ||
StreamValue, | ||
TRUE_VALUE, | ||
Value, | ||
} from '../values' | ||
import {totalCompare} from './ordering' | ||
import {portableTextContent} from './pt' | ||
import {Scope} from './scope' | ||
import {evaluateScore} from './scoring' | ||
import {Executor} from './types' | ||
@@ -61,3 +61,3 @@ function hasReference(value: any, pathSet: Set<string>): boolean { | ||
export type GroqFunctionArg = ExprNode | ||
type GroqFunctionArg = ExprNode | ||
type WithOptions<T> = T & { | ||
@@ -82,3 +82,2 @@ arity?: GroqFunctionArity | ||
// eslint-disable-next-line require-await | ||
global.anywhere = async function anywhere() { | ||
@@ -524,3 +523,2 @@ throw new Error('not implemented') | ||
const delta: FunctionSet = {} | ||
// eslint-disable-next-line require-await | ||
delta.operation = async function (args, scope) { | ||
@@ -575,3 +573,3 @@ const hasBefore = scope.context.before !== null | ||
let n: number | undefined | ||
let n: number | undefined = undefined | ||
for await (const elem of arr) { | ||
@@ -596,3 +594,3 @@ if (elem.type === 'null') continue | ||
let n: number | undefined | ||
let n: number | undefined = undefined | ||
for await (const elem of arr) { | ||
@@ -599,0 +597,0 @@ if (elem.type === 'null') continue |
@@ -0,2 +1,2 @@ | ||
export {evaluateQuery as evaluate} from './evaluate' | ||
export {tryConstantEvaluate} from './constantEvaluate' | ||
export {evaluateQuery as evaluate} from './evaluate' |
import {OpCall} from '../nodeTypes' | ||
import { | ||
TRUE_VALUE, | ||
FALSE_VALUE, | ||
fromDateTime, | ||
fromJS, | ||
NULL_VALUE, | ||
fromNumber, | ||
Value, | ||
fromString, | ||
NULL_VALUE, | ||
fromJS, | ||
fromDateTime, | ||
StreamValue, | ||
TRUE_VALUE, | ||
Value, | ||
} from '../values' | ||
import {isEqual} from './equality' | ||
import {gatherText, matchAnalyzePattern, matchText, matchTokenize, Pattern, Token} from './matching' | ||
import {partialCompare} from './ordering' | ||
import {gatherText, Token, Pattern, matchText, matchTokenize, matchAnalyzePattern} from './matching' | ||
@@ -17,0 +17,0 @@ type GroqOperatorFn = (left: Value, right: Value) => Value | PromiseLike<Value> |
@@ -1,2 +0,2 @@ | ||
import {Value} from '../values' | ||
import {NULL_VALUE, Value} from '../values' | ||
@@ -3,0 +3,0 @@ export async function portableTextContent(value: Value): Promise<string | null> { |
@@ -0,5 +1,5 @@ | ||
import {Executor} from './types' | ||
import {ExprNode} from '../nodeTypes' | ||
import {gatherText, matchPatternRegex, matchTokenize, Token} from './matching' | ||
import {Scope} from './scope' | ||
import {Executor} from './types' | ||
@@ -6,0 +6,0 @@ // BM25 similarity constants |
@@ -1,6 +0,6 @@ | ||
import {ExprNode} from '../nodeTypes' | ||
import * as NodeTypes from '../nodeTypes' | ||
import {Scope} from './scope' | ||
import {Value} from '../values' | ||
import {Scope} from './scope' | ||
export type Executor<N = ExprNode> = (node: N, scope: Scope) => Value | PromiseLike<Value> | ||
export type Executor<N = NodeTypes.ExprNode> = (node: N, scope: Scope) => Value | PromiseLike<Value> | ||
@@ -7,0 +7,0 @@ export interface EvaluateOptions { |
/* eslint-disable camelcase */ | ||
import {tryConstantEvaluate} from './evaluator' | ||
import * as NodeTypes from './nodeTypes' | ||
import {Mark, MarkProcessor, MarkVisitor} from './markProcessor' | ||
import {GroqFunctionArity, namespaces, pipeFunctions} from './evaluator/functions' | ||
import {Mark, MarkProcessor, MarkVisitor} from './markProcessor' | ||
import { | ||
ExprNode, | ||
ParentNode, | ||
OpCall, | ||
ObjectAttributeNode, | ||
ArrayElementNode, | ||
SelectNode, | ||
ObjectSplatNode, | ||
FuncCallNode, | ||
} from './nodeTypes' | ||
import {parse as rawParse} from './rawParser' | ||
@@ -23,2 +13,3 @@ import { | ||
} from './traversal' | ||
import {tryConstantEvaluate} from './evaluator' | ||
import {ParseOptions} from './types' | ||
@@ -49,3 +40,3 @@ | ||
const EXPR_BUILDER: MarkVisitor<ExprNode> = { | ||
const EXPR_BUILDER: MarkVisitor<NodeTypes.ExprNode> = { | ||
group(p) { | ||
@@ -75,3 +66,3 @@ const inner = p.process(EXPR_BUILDER) | ||
dblparent(p) { | ||
const next = p.process(EXPR_BUILDER) as ParentNode | ||
const next = p.process(EXPR_BUILDER) as NodeTypes.ParentNode | ||
return { | ||
@@ -206,3 +197,3 @@ type: 'Parent', | ||
const left = p.process(EXPR_BUILDER) | ||
const op = p.processString() as OpCall | ||
const op = p.processString() as NodeTypes.OpCall | ||
const right = p.process(EXPR_BUILDER) | ||
@@ -290,3 +281,3 @@ return { | ||
object(p) { | ||
const attributes: ObjectAttributeNode[] = [] | ||
const attributes: NodeTypes.ObjectAttributeNode[] = [] | ||
while (p.getMark().name !== 'object_end') { | ||
@@ -304,3 +295,3 @@ attributes.push(p.process(OBJECT_BUILDER)) | ||
array(p) { | ||
const elements: ArrayElementNode[] = [] | ||
const elements: NodeTypes.ArrayElementNode[] = [] | ||
while (p.getMark().name !== 'array_end') { | ||
@@ -327,3 +318,3 @@ let isSplat = false | ||
tuple(p) { | ||
const members: ExprNode[] = [] | ||
const members: NodeTypes.ExprNode[] = [] | ||
while (p.getMark().name !== 'tuple_end') { | ||
@@ -348,3 +339,3 @@ members.push(p.process(EXPR_BUILDER)) | ||
if (namespace === 'global' && name === 'select') { | ||
const result: SelectNode = { | ||
const result: NodeTypes.SelectNode = { | ||
type: 'Select', | ||
@@ -375,3 +366,3 @@ alternatives: [], | ||
const args: ExprNode[] = [] | ||
const args: NodeTypes.ExprNode[] = [] | ||
@@ -442,3 +433,3 @@ while (p.getMark().name !== 'func_args_end') { | ||
const name = p.processString() | ||
const args: ExprNode[] = [] | ||
const args: NodeTypes.ExprNode[] = [] | ||
@@ -549,3 +540,3 @@ const oldAllowBoost = p.allowBoost | ||
const OBJECT_BUILDER: MarkVisitor<ObjectAttributeNode> = { | ||
const OBJECT_BUILDER: MarkVisitor<NodeTypes.ObjectAttributeNode> = { | ||
object_expr(p) { | ||
@@ -585,3 +576,3 @@ if (p.getMark().name === 'pair') { | ||
object_splat(p): ObjectSplatNode { | ||
object_splat(p): NodeTypes.ObjectSplatNode { | ||
const value = p.process(EXPR_BUILDER) | ||
@@ -595,3 +586,3 @@ | ||
object_splat_this(): ObjectSplatNode { | ||
object_splat_this(): NodeTypes.ObjectSplatNode { | ||
return { | ||
@@ -677,3 +668,3 @@ type: 'ObjectSplat', | ||
const wrap = (base: ExprNode): ExprNode => | ||
const wrap = (base: NodeTypes.ExprNode): NodeTypes.ExprNode => | ||
attr ? {type: 'AccessAttribute', base, name: attr} : base | ||
@@ -804,3 +795,3 @@ | ||
func_call(p, mark) { | ||
const func = EXPR_BUILDER.func_call(p, mark) as FuncCallNode | ||
const func = EXPR_BUILDER.func_call(p, mark) as NodeTypes.FuncCallNode | ||
if (func.name === 'anywhere' && func.args.length === 1) return null | ||
@@ -844,3 +835,3 @@ | ||
function extractPropertyKey(node: ExprNode): string { | ||
function extractPropertyKey(node: NodeTypes.ExprNode): string { | ||
if (node.type === 'AccessAttribute' && !node.base) { | ||
@@ -898,3 +889,3 @@ return node.name | ||
*/ | ||
export function parse(input: string, options: ParseOptions = {}): ExprNode { | ||
export function parse(input: string, options: ParseOptions = {}): NodeTypes.ExprNode { | ||
const result = rawParse(input) | ||
@@ -901,0 +892,0 @@ if (result.type === 'error') { |
@@ -0,4 +1,4 @@ | ||
export * from './utils' | ||
export * from './types' | ||
export * from './StreamValue' | ||
export * from './Path' | ||
export * from './StreamValue' | ||
export * from './types' | ||
export * from './utils' |
import type {Path} from './Path' | ||
import type {StaticValue, DateTime} from './utils' | ||
import type {StreamValue} from './StreamValue' | ||
import type {DateTime, StaticValue} from './utils' | ||
@@ -5,0 +5,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import {formatRFC3339, parseRFC3339} from './dateHelpers' | ||
import {parseRFC3339, formatRFC3339} from './dateHelpers' | ||
import {Path} from './Path' | ||
@@ -3,0 +3,0 @@ import {StreamValue} from './StreamValue' |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
14111
1
140
518406
18
33
4
No