Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@altangent/graphql-filter-array

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@altangent/graphql-filter-array - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1-1

2

package.json
{
"name": "@altangent/graphql-filter-array",
"version": "1.0.0",
"version": "1.0.1-1",
"description": "Graphql filtering exection to an array of objects",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -23,9 +23,3 @@ let flattenDeep = require('lodash.flattendeep');

let column = columnMap.get(key);
if (!column) {
throw new Error(`${key} is not a supported filter`);
}
let test = filter[key];
return processOp(results, column, test);
return processOp(results, key, filter, columnMap);
}

@@ -45,17 +39,23 @@

function processOp(results, column, test) {
if (Object.keys(test).length > 1) throw new Error('Unsupported filter operation');
function processOp(results, key, filter, columnMap) {
let [target, op] = key.split('_');
let test = filter[key];
if (test._eq) {
return processEq(results, column, test._eq);
let column = columnMap.get(target);
if (!column) {
throw new Error(`${key} is not a supported filter`);
}
if (test._in) {
return processIn(results, column, test._in);
if (op === 'eq') {
return processEq(results, column, test);
}
if (test._like) {
return processLike(results, column, test._like);
if (op === 'in') {
return processIn(results, column, test);
}
if (op === 'like') {
return processLike(results, column, test);
}
throw new Error('Unsupported filter operation');

@@ -62,0 +62,0 @@ }

@@ -22,3 +22,3 @@ const { expect } = require('chai');

it: 'should perform equal filter',
filter: { currencyName: { _eq: 'bitcoin' } },
filter: { currencyName_eq: 'bitcoin' },
expected: [array[0]],

@@ -28,3 +28,3 @@ },

it: 'should perform like filter',
filter: { currencyName: { _like: '%bitcoin%' } },
filter: { currencyName_like: '%bitcoin%' },
expected: [array[0], array[2]],

@@ -34,3 +34,3 @@ },

it: 'should perform in filter',
filter: { currencySymbol: { _in: ['BTC', 'LTC'] } },
filter: { currencySymbol_in: ['BTC', 'LTC'] },
expected: [array[0], array[1]],

@@ -40,3 +40,3 @@ },

it: 'should implicit and multiple filters',
filter: { currencyName: { _like: 'bitcoin%' }, currencySymbol: { _eq: 'BTC' } },
filter: { currencyName_like: 'bitcoin%', currencySymbol_eq: 'BTC' },
expected: [array[0]],

@@ -47,3 +47,3 @@ },

filter: {
_and: [{ currencyName: { _like: 'bitcoin%' } }, { currencySymbol: { _eq: 'BTC' } }],
_and: [{ currencyName_like: 'bitcoin%' }, { currencySymbol_eq: 'BTC' }],
},

@@ -55,3 +55,3 @@ expected: [array[0]],

filter: {
_or: [{ currencyName: { _eq: 'bitcoin' } }, { currencyName: { _eq: 'litecoin' } }],
_or: [{ currencyName_eq: 'bitcoin' }, { currencyName_eq: 'litecoin' }],
},

@@ -63,4 +63,4 @@ expected: [array[0], array[1]],

filter: {
currencyName: { _like: '%coin%' },
_or: [{ currencySymbol: { _eq: 'BTC' } }, { currencySymbol: { _eq: 'LTC' } }],
currencyName_like: '%coin%',
_or: [{ currencySymbol_eq: 'BTC' }, { currencySymbol_eq: 'LTC' }],
},

@@ -73,4 +73,4 @@ expected: [array[0], array[1]],

_and: [
{ _or: [{ currencyName: { _like: 'bit%' } }, { currencyName: { _like: 'lite%' } }] },
{ _or: [{ currencySymbol: { _eq: 'BTC' } }, { currencySymbol: { _eq: 'LTC' } }] },
{ _or: [{ currencyName_like: 'bit%' }, { currencyName_like: 'lite%' }] },
{ _or: [{ currencySymbol_eq: 'BTC' }, { currencySymbol_eq: 'LTC' }] },
],

@@ -95,10 +95,5 @@ },

it('should throw exception when operation is unknown', () => {
let filter = { currencySymbol: { _derp: 'ok' } };
let filter = { currencySymbol_derp: 'ok' };
expect(() => filterArray(array, filter, columnMap)).to.throw('Unsupported filter operation');
});
it('should throw exception when operation has too many keys', () => {
let filter = { currencySymbol: { _eq: 'BTC', _like: 'BTC' } };
expect(() => filterArray(array, filter, columnMap)).to.throw('Unsupported filter operation');
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc