Comparing version 1.1.4 to 1.2.0-beta.0
{ | ||
"name": "groq-js", | ||
"version": "1.1.4", | ||
"version": "1.2.0-beta.0", | ||
"keywords": [ | ||
@@ -13,18 +13,40 @@ "sanity", | ||
"sideEffects": false, | ||
"type": "commonjs", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/1.esm.d.ts", | ||
"default": "./dist/1.esm.mjs" | ||
"types": "./dist/index.d.ts", | ||
"source": "./src/1.ts", | ||
"require": "./dist/index.js", | ||
"node": { | ||
"import": "./dist/index.cjs.mjs", | ||
"require": "./dist/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/1.umd.d.ts", | ||
"default": "./dist/1.umd.cjs" | ||
"import": "./dist/index.mjs", | ||
"default": "./dist/index.js" | ||
}, | ||
"./1": { | ||
"types": "./dist/1.d.ts", | ||
"source": "./src/1.ts", | ||
"require": "./dist/1.js", | ||
"node": { | ||
"import": "./dist/1.cjs.mjs", | ||
"require": "./dist/1.js" | ||
}, | ||
"default": "./dist/1.umd.cjs" | ||
"import": "./dist/1.mjs", | ||
"default": "./dist/1.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "./dist/1.umd.cjs", | ||
"types": "./dist/1.umd.d.ts", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"source": "./src/1.ts", | ||
"types": "./dist/index.d.ts", | ||
"typesVersions": { | ||
"*": { | ||
"1": [ | ||
"./dist/1.d.ts" | ||
] | ||
} | ||
}, | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
@@ -37,3 +59,3 @@ "dist", | ||
"prebuild": "npx rimraf dist", | ||
"build": "rollup -c", | ||
"build": "pkg build --strict && pkg --strict", | ||
"prepublishOnly": "npm run build", | ||
@@ -45,2 +67,6 @@ "prettify": "prettier --write .", | ||
}, | ||
"browserslist": [ | ||
"> 0.2% and supports es6-module and supports es6-module-dynamic-import and not dead and not IE 11", | ||
"maintained node versions" | ||
], | ||
"tap": { | ||
@@ -54,10 +80,14 @@ "check-coverage": false, | ||
"devDependencies": { | ||
"@rollup/plugin-typescript": "^8.3.3", | ||
"@sanity/pkg-utils": "^2.1.1", | ||
"@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", | ||
"@typescript-eslint/eslint-plugin": "^5.48.1", | ||
"@typescript-eslint/parser": "^5.48.1", | ||
"esbuild": "^0.14.2", | ||
"esbuild-register": "^3.2.0", | ||
"eslint-config-sanity": "^5.1.0", | ||
"eslint": "^8.31.0", | ||
"eslint-config-prettier": "^8.6.0", | ||
"eslint-config-sanity": "^6.0.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-simple-import-sort": "^8.0.0", | ||
"ndjson": "^2.0.0", | ||
@@ -67,8 +97,5 @@ "prettier": "^2.2.1", | ||
"rimraf": "^3.0.2", | ||
"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" | ||
"typescript": "^4.9.4" | ||
}, | ||
@@ -75,0 +102,0 @@ "engines": { |
25
src/1.ts
@@ -0,2 +1,25 @@ | ||
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 {evaluate} from './evaluator' | ||
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,9 +0,4 @@ | ||
import * as NodeTypes from '../nodeTypes' | ||
import {operators} from './operators' | ||
import {Scope} from './scope' | ||
import {EvaluateOptions, Executor} from './types' | ||
import {ExprNode, FuncCallNode, PipeFuncCallNode} from '../nodeTypes' | ||
import { | ||
DateTime, | ||
FALSE_VALUE, | ||
fromDateTime, | ||
fromJS, | ||
@@ -16,6 +11,9 @@ fromNumber, | ||
} from '../values' | ||
import {operators} from './operators' | ||
import {partialCompare} from './ordering' | ||
import {Scope} from './scope' | ||
import {EvaluateOptions, Executor} from './types' | ||
export function evaluate( | ||
node: NodeTypes.ExprNode, | ||
node: ExprNode, | ||
scope: Scope, | ||
@@ -31,4 +29,4 @@ execute: Executor = evaluate | ||
type ExecutorMap = { | ||
[key in NodeTypes.ExprNode['type']]: ( | ||
node: NarrowNode<NodeTypes.ExprNode, key>, | ||
[key in ExprNode['type']]: ( | ||
node: NarrowNode<ExprNode, key>, | ||
scope: Scope, | ||
@@ -171,7 +169,7 @@ exec: Executor | ||
FuncCall({func, args}: NodeTypes.FuncCallNode, scope: Scope, execute) { | ||
FuncCall({func, args}: FuncCallNode, scope: Scope, execute) { | ||
return func(args, scope, execute) | ||
}, | ||
async PipeFuncCall({func, base, args}: NodeTypes.PipeFuncCallNode, scope: Scope, execute) { | ||
async PipeFuncCall({func, base, args}: PipeFuncCallNode, scope: Scope, execute) { | ||
const baseValue = await execute(base, scope) | ||
@@ -463,3 +461,3 @@ return func(baseValue, args, scope, execute) | ||
export function evaluateQuery( | ||
tree: NodeTypes.ExprNode, | ||
tree: ExprNode, | ||
options: EvaluateOptions = {} | ||
@@ -466,0 +464,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 { | ||
DateTime, | ||
FALSE_VALUE, | ||
fromJS, | ||
fromNumber, | ||
fromPath, | ||
fromString, | ||
getType, | ||
fromNumber, | ||
TRUE_VALUE, | ||
FALSE_VALUE, | ||
NULL_VALUE, | ||
Value, | ||
DateTime, | ||
fromString, | ||
fromPath, | ||
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 { | ||
type GroqFunctionArg = ExprNode | ||
export type GroqFunctionArg = ExprNode | ||
type WithOptions<T> = T & { | ||
@@ -82,2 +82,3 @@ arity?: GroqFunctionArity | ||
// eslint-disable-next-line require-await | ||
global.anywhere = async function anywhere() { | ||
@@ -523,2 +524,3 @@ throw new Error('not implemented') | ||
const delta: FunctionSet = {} | ||
// eslint-disable-next-line require-await | ||
delta.operation = async function (args, scope) { | ||
@@ -573,3 +575,3 @@ const hasBefore = scope.context.before !== null | ||
let n: number | undefined = undefined | ||
let n: number | undefined | ||
for await (const elem of arr) { | ||
@@ -594,3 +596,3 @@ if (elem.type === 'null') continue | ||
let n: number | undefined = undefined | ||
let n: number | undefined | ||
for await (const elem of arr) { | ||
@@ -597,0 +599,0 @@ if (elem.type === 'null') continue |
@@ -0,2 +1,2 @@ | ||
export {tryConstantEvaluate} from './constantEvaluate' | ||
export {evaluateQuery as evaluate} from './evaluate' | ||
export {tryConstantEvaluate} from './constantEvaluate' |
import {OpCall} from '../nodeTypes' | ||
import { | ||
TRUE_VALUE, | ||
FALSE_VALUE, | ||
NULL_VALUE, | ||
fromDateTime, | ||
fromJS, | ||
fromNumber, | ||
Value, | ||
fromString, | ||
fromJS, | ||
fromDateTime, | ||
NULL_VALUE, | ||
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 {NULL_VALUE, Value} from '../values' | ||
import {Value} from '../values' | ||
@@ -3,0 +3,0 @@ export async function portableTextContent(value: Value): Promise<string | null> { |
@@ -1,5 +0,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 * as NodeTypes from '../nodeTypes' | ||
import {ExprNode} from '../nodeTypes' | ||
import {Value} from '../values' | ||
import {Scope} from './scope' | ||
import {Value} from '../values' | ||
export type Executor<N = NodeTypes.ExprNode> = (node: N, scope: Scope) => Value | PromiseLike<Value> | ||
export type Executor<N = ExprNode> = (node: N, scope: Scope) => Value | PromiseLike<Value> | ||
@@ -7,0 +7,0 @@ export interface EvaluateOptions { |
/* eslint-disable camelcase */ | ||
import * as NodeTypes from './nodeTypes' | ||
import {tryConstantEvaluate} from './evaluator' | ||
import {GroqFunctionArity, namespaces, pipeFunctions} from './evaluator/functions' | ||
import {Mark, MarkProcessor, MarkVisitor} from './markProcessor' | ||
import {GroqFunctionArity, namespaces, pipeFunctions} from './evaluator/functions' | ||
import { | ||
ArrayElementNode, | ||
ExprNode, | ||
FuncCallNode, | ||
ObjectAttributeNode, | ||
ObjectSplatNode, | ||
OpCall, | ||
ParentNode, | ||
SelectNode, | ||
} from './nodeTypes' | ||
import {parse as rawParse} from './rawParser' | ||
@@ -13,3 +23,2 @@ import { | ||
} from './traversal' | ||
import {tryConstantEvaluate} from './evaluator' | ||
import {ParseOptions} from './types' | ||
@@ -40,3 +49,3 @@ | ||
const EXPR_BUILDER: MarkVisitor<NodeTypes.ExprNode> = { | ||
const EXPR_BUILDER: MarkVisitor<ExprNode> = { | ||
group(p) { | ||
@@ -66,3 +75,3 @@ const inner = p.process(EXPR_BUILDER) | ||
dblparent(p) { | ||
const next = p.process(EXPR_BUILDER) as NodeTypes.ParentNode | ||
const next = p.process(EXPR_BUILDER) as ParentNode | ||
return { | ||
@@ -197,3 +206,3 @@ type: 'Parent', | ||
const left = p.process(EXPR_BUILDER) | ||
const op = p.processString() as NodeTypes.OpCall | ||
const op = p.processString() as OpCall | ||
const right = p.process(EXPR_BUILDER) | ||
@@ -281,3 +290,3 @@ return { | ||
object(p) { | ||
const attributes: NodeTypes.ObjectAttributeNode[] = [] | ||
const attributes: ObjectAttributeNode[] = [] | ||
while (p.getMark().name !== 'object_end') { | ||
@@ -295,3 +304,3 @@ attributes.push(p.process(OBJECT_BUILDER)) | ||
array(p) { | ||
const elements: NodeTypes.ArrayElementNode[] = [] | ||
const elements: ArrayElementNode[] = [] | ||
while (p.getMark().name !== 'array_end') { | ||
@@ -318,3 +327,3 @@ let isSplat = false | ||
tuple(p) { | ||
const members: NodeTypes.ExprNode[] = [] | ||
const members: ExprNode[] = [] | ||
while (p.getMark().name !== 'tuple_end') { | ||
@@ -339,3 +348,3 @@ members.push(p.process(EXPR_BUILDER)) | ||
if (namespace === 'global' && name === 'select') { | ||
const result: NodeTypes.SelectNode = { | ||
const result: SelectNode = { | ||
type: 'Select', | ||
@@ -366,3 +375,3 @@ alternatives: [], | ||
const args: NodeTypes.ExprNode[] = [] | ||
const args: ExprNode[] = [] | ||
@@ -433,3 +442,3 @@ while (p.getMark().name !== 'func_args_end') { | ||
const name = p.processString() | ||
const args: NodeTypes.ExprNode[] = [] | ||
const args: ExprNode[] = [] | ||
@@ -540,3 +549,3 @@ const oldAllowBoost = p.allowBoost | ||
const OBJECT_BUILDER: MarkVisitor<NodeTypes.ObjectAttributeNode> = { | ||
const OBJECT_BUILDER: MarkVisitor<ObjectAttributeNode> = { | ||
object_expr(p) { | ||
@@ -576,3 +585,3 @@ if (p.getMark().name === 'pair') { | ||
object_splat(p): NodeTypes.ObjectSplatNode { | ||
object_splat(p): ObjectSplatNode { | ||
const value = p.process(EXPR_BUILDER) | ||
@@ -586,3 +595,3 @@ | ||
object_splat_this(): NodeTypes.ObjectSplatNode { | ||
object_splat_this(): ObjectSplatNode { | ||
return { | ||
@@ -668,3 +677,3 @@ type: 'ObjectSplat', | ||
const wrap = (base: NodeTypes.ExprNode): NodeTypes.ExprNode => | ||
const wrap = (base: ExprNode): ExprNode => | ||
attr ? {type: 'AccessAttribute', base, name: attr} : base | ||
@@ -795,3 +804,3 @@ | ||
func_call(p, mark) { | ||
const func = EXPR_BUILDER.func_call(p, mark) as NodeTypes.FuncCallNode | ||
const func = EXPR_BUILDER.func_call(p, mark) as FuncCallNode | ||
if (func.name === 'anywhere' && func.args.length === 1) return null | ||
@@ -835,3 +844,3 @@ | ||
function extractPropertyKey(node: NodeTypes.ExprNode): string { | ||
function extractPropertyKey(node: ExprNode): string { | ||
if (node.type === 'AccessAttribute' && !node.base) { | ||
@@ -889,3 +898,3 @@ return node.name | ||
*/ | ||
export function parse(input: string, options: ParseOptions = {}): NodeTypes.ExprNode { | ||
export function parse(input: string, options: ParseOptions = {}): ExprNode { | ||
const result = rawParse(input) | ||
@@ -892,0 +901,0 @@ if (result.type === 'error') { |
@@ -0,4 +1,4 @@ | ||
export * from './Path' | ||
export * from './StreamValue' | ||
export * from './types' | ||
export * from './utils' | ||
export * from './types' | ||
export * from './StreamValue' | ||
export * from './Path' |
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 {parseRFC3339, formatRFC3339} from './dateHelpers' | ||
import {formatRFC3339, parseRFC3339} from './dateHelpers' | ||
import {Path} from './Path' | ||
@@ -3,0 +3,0 @@ import {StreamValue} from './StreamValue' |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
713359
41
3
19
11505
2