Comparing version 1.13.0 to 1.14.0
{ | ||
"name": "groq-js", | ||
"version": "1.13.0", | ||
"version": "1.14.0", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "sanity", |
@@ -122,3 +122,3 @@ # GROQ-JS<!-- omit in toc --> | ||
```shell | ||
GROQTEST_SUITE_VERSION=v0.1.45 ./test/generate.sh | ||
GROQTEST_SUITE_VERSION=v0.1.46 ./test/generate.sh | ||
``` | ||
@@ -125,0 +125,0 @@ |
@@ -22,2 +22,3 @@ import type {ExprNode} from '../nodeTypes' | ||
import type {Executor} from './types' | ||
import {isEqual} from './equality' | ||
@@ -396,2 +397,27 @@ function hasReference(value: any, pathSet: Set<string>): boolean { | ||
array['intersects'] = async function (args, scope, execute) { | ||
// Intersects returns true if the two arrays have at least one element in common. Only | ||
// primitives are supported; non-primitives are ignored. | ||
const arr1 = await execute(args[0], scope) | ||
if (!arr1.isArray()) { | ||
return NULL_VALUE | ||
} | ||
const arr2 = await execute(args[1], scope) | ||
if (!arr2.isArray()) { | ||
return NULL_VALUE | ||
} | ||
for await (const v1 of arr1) { | ||
for await (const v2 of arr2) { | ||
if (isEqual(v1, v2)) { | ||
return TRUE_VALUE | ||
} | ||
} | ||
} | ||
return FALSE_VALUE | ||
} | ||
array['intersects'].arity = 2 | ||
const pt: FunctionSet = {} | ||
@@ -398,0 +424,0 @@ pt['text'] = async function (args, scope, execute) { |
@@ -842,3 +842,4 @@ /* eslint-disable camelcase */ | ||
node.type === 'AccessElement' || | ||
node.type === 'ArrayCoerce' | ||
node.type === 'ArrayCoerce' || | ||
node.type === 'Group' | ||
) { | ||
@@ -845,0 +846,0 @@ return extractPropertyKey(node.base) |
@@ -83,2 +83,21 @@ /* eslint-disable max-statements */ | ||
case 'array.intersects': { | ||
const arg1 = walk({node: node.args[0], scope}) | ||
const arg2 = walk({node: node.args[1], scope}) | ||
return mapNode(arg1, scope, (arg1) => | ||
mapNode(arg2, scope, (arg2) => { | ||
if (arg1.type !== 'array') { | ||
return {type: 'null'} | ||
} | ||
if (arg2.type !== 'array') { | ||
return {type: 'null'} | ||
} | ||
return {type: 'boolean'} | ||
}), | ||
) | ||
} | ||
case 'global.lower': { | ||
@@ -130,3 +149,10 @@ const arg = walk({node: node.args[0], scope}) | ||
case 'global.defined': { | ||
return {type: 'boolean'} | ||
const arg = walk({node: node.args[0], scope}) | ||
return mapNode(arg, scope, (node) => { | ||
if (node.type === 'unknown') { | ||
return {type: 'boolean'} | ||
} | ||
return {type: 'boolean', value: node.type !== 'null'} | ||
}) | ||
} | ||
@@ -133,0 +159,0 @@ case 'global.path': { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
1032690
13872