Comparing version 1.1.6 to 1.1.7
{ | ||
"name": "groq-js", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"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": [ | ||
@@ -39,3 +61,3 @@ "dist", | ||
"prebuild": "npx rimraf dist", | ||
"build": "rollup -c", | ||
"build": "pkg build --strict && pkg --strict", | ||
"prepublishOnly": "npm run build", | ||
@@ -47,2 +69,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": { | ||
@@ -56,20 +82,21 @@ "check-coverage": false, | ||
"devDependencies": { | ||
"@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", | ||
"@sanity/pkg-utils": "^2.2.5", | ||
"@sanity/semantic-release-preset": "^4.0.0", | ||
"@types/tap": "^15.0.8", | ||
"@typescript-eslint/eslint-plugin": "^5.51.0", | ||
"@typescript-eslint/parser": "^5.51.0", | ||
"esbuild": "^0.17.8", | ||
"esbuild-register": "^3.4.2", | ||
"eslint": "^8.34.0", | ||
"eslint-config-prettier": "^8.6.0", | ||
"eslint-config-sanity": "^6.0.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-simple-import-sort": "^10.0.0", | ||
"ndjson": "^2.0.0", | ||
"prettier": "^2.2.1", | ||
"prettier-plugin-packagejson": "^2.3.0", | ||
"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.9.4" | ||
"prettier": "^2.8.4", | ||
"prettier-plugin-packagejson": "^2.4.3", | ||
"rimraf": "^4.1.2", | ||
"semver": "^7.3.8", | ||
"tap": "^16.3.4", | ||
"typescript": "^4.9.5" | ||
}, | ||
@@ -76,0 +103,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 & { | ||
@@ -80,11 +80,13 @@ arity?: GroqFunctionArity | ||
const global: FunctionSet = {} | ||
// underscored to not collide with environments like jest that give variables named `global` special treatment | ||
const _global: FunctionSet = {} | ||
global.anywhere = async function anywhere() { | ||
// eslint-disable-next-line require-await | ||
_global.anywhere = async function anywhere() { | ||
throw new Error('not implemented') | ||
} | ||
global.anywhere.arity = 1 | ||
_global.anywhere.arity = 1 | ||
global.coalesce = async function coalesce(args, scope, execute) { | ||
_global.coalesce = async function coalesce(args, scope, execute) { | ||
for (const arg of args) { | ||
@@ -99,3 +101,3 @@ const value = await execute(arg, scope) | ||
global.count = async function count(args, scope, execute) { | ||
_global.count = async function count(args, scope, execute) { | ||
const inner = await execute(args[0], scope) | ||
@@ -113,5 +115,5 @@ if (!inner.isArray()) { | ||
} | ||
global.count.arity = 1 | ||
_global.count.arity = 1 | ||
global.dateTime = async function dateTime(args, scope, execute) { | ||
_global.dateTime = async function dateTime(args, scope, execute) { | ||
const val = await execute(args[0], scope) | ||
@@ -126,17 +128,17 @@ if (val.type === 'datetime') { | ||
} | ||
global.dateTime.arity = 1 | ||
_global.dateTime.arity = 1 | ||
global.defined = async function defined(args, scope, execute) { | ||
_global.defined = async function defined(args, scope, execute) { | ||
const inner = await execute(args[0], scope) | ||
return inner.type === 'null' ? FALSE_VALUE : TRUE_VALUE | ||
} | ||
global.defined.arity = 1 | ||
_global.defined.arity = 1 | ||
// eslint-disable-next-line require-await | ||
global.identity = async function identity(args, scope) { | ||
_global.identity = async function identity(args, scope) { | ||
return fromString(scope.context.identity) | ||
} | ||
global.identity.arity = 0 | ||
_global.identity.arity = 0 | ||
global.length = async function length(args, scope, execute) { | ||
_global.length = async function length(args, scope, execute) { | ||
const inner = await execute(args[0], scope) | ||
@@ -159,5 +161,5 @@ | ||
} | ||
global.length.arity = 1 | ||
_global.length.arity = 1 | ||
global.path = async function path(args, scope, execute) { | ||
_global.path = async function path(args, scope, execute) { | ||
const inner = await execute(args[0], scope) | ||
@@ -170,5 +172,5 @@ if (inner.type !== 'string') { | ||
} | ||
global.path.arity = 1 | ||
_global.path.arity = 1 | ||
global.string = async function string(args, scope, execute) { | ||
_global.string = async function string(args, scope, execute) { | ||
const value = await execute(args[0], scope) | ||
@@ -185,5 +187,5 @@ switch (value.type) { | ||
} | ||
global.string.arity = 1 | ||
_global.string.arity = 1 | ||
global.references = async function references(args, scope, execute) { | ||
_global.references = async function references(args, scope, execute) { | ||
const pathSet = new Set<string>() | ||
@@ -210,5 +212,5 @@ for (const arg of args) { | ||
} | ||
global.references.arity = (c) => c >= 1 | ||
_global.references.arity = (c) => c >= 1 | ||
global.round = async function round(args, scope, execute) { | ||
_global.round = async function round(args, scope, execute) { | ||
const value = await execute(args[0], scope) | ||
@@ -240,12 +242,12 @@ if (value.type !== 'number') { | ||
} | ||
global.round.arity = (count) => count >= 1 && count <= 2 | ||
_global.round.arity = (count) => count >= 1 && count <= 2 | ||
// eslint-disable-next-line require-await | ||
global.now = async function now(args, scope) { | ||
_global.now = async function now(args, scope) { | ||
return fromString(scope.context.timestamp.toISOString()) | ||
} | ||
global.now.arity = 0 | ||
_global.now.arity = 0 | ||
// eslint-disable-next-line require-await | ||
global.boost = async function boost() { | ||
_global.boost = async function boost() { | ||
// This should be handled by the scoring function. | ||
@@ -255,3 +257,3 @@ throw new Error('unexpected boost call') | ||
global.boost.arity = 2 | ||
_global.boost.arity = 2 | ||
@@ -303,4 +305,4 @@ const string: FunctionSet = {} | ||
global.lower = string.lower | ||
global.upper = string.upper | ||
_global.lower = string.lower | ||
_global.upper = string.upper | ||
@@ -533,2 +535,3 @@ string.startsWith = async function (args, scope, execute) { | ||
const delta: FunctionSet = {} | ||
// eslint-disable-next-line require-await | ||
delta.operation = async function (args, scope) { | ||
@@ -583,3 +586,3 @@ const hasBefore = scope.context.before !== null | ||
let n: number | undefined = undefined | ||
let n: number | undefined | ||
for await (const elem of arr) { | ||
@@ -604,3 +607,3 @@ if (elem.type === 'null') continue | ||
let n: number | undefined = undefined | ||
let n: number | undefined | ||
for await (const elem of arr) { | ||
@@ -661,3 +664,3 @@ if (elem.type === 'null') continue | ||
export const namespaces: NamespaceSet = { | ||
global, | ||
global: _global, | ||
string, | ||
@@ -664,0 +667,0 @@ array, |
@@ -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' |
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
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
717052
42
19
11520
3