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

@allbin/entity-logic

Package Overview
Dependencies
Maintainers
3
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@allbin/entity-logic - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

233

lib/index.test.js

@@ -266,3 +266,18 @@ "use strict";

var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([numberOneEntity]);
expect(result).toMatchObject([
undefinedEntity,
booleanFalseEntity,
booleanTrueEntity,
numberOneEntity,
stringWithLengthEntity,
stringWithNoLengthEntity,
dateEpochEntity,
date5MinAgoEntity,
enumEntity,
photoEntity,
arrayEvenNumbersEntity,
arrayOddNumbersEntity,
arrayStringEntityFirst,
arrayStringEntitySecond,
]);
});

@@ -327,3 +342,18 @@ it('correctly executes number.gt conditions', function () {

var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([numberOneEntity]);
expect(result).toMatchObject([
undefinedEntity,
booleanFalseEntity,
booleanTrueEntity,
numberOneEntity,
stringWithLengthEntity,
stringWithNoLengthEntity,
dateEpochEntity,
date5MinAgoEntity,
enumEntity,
photoEntity,
arrayEvenNumbersEntity,
arrayOddNumbersEntity,
arrayStringEntityFirst,
arrayStringEntitySecond,
]);
});

@@ -338,3 +368,18 @@ it('correctly executes number.none_of conditions', function () {

var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([numberZeroEntity]);
expect(result).toMatchObject([
undefinedEntity,
booleanFalseEntity,
booleanTrueEntity,
numberZeroEntity,
stringWithLengthEntity,
stringWithNoLengthEntity,
dateEpochEntity,
date5MinAgoEntity,
enumEntity,
photoEntity,
arrayEvenNumbersEntity,
arrayOddNumbersEntity,
arrayStringEntityFirst,
arrayStringEntitySecond,
]);
});

@@ -406,3 +451,18 @@ it('correctly executes number.any_of conditions', function () {

var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([stringWithNoLengthEntity]);
expect(result).toMatchObject([
undefinedEntity,
booleanFalseEntity,
booleanTrueEntity,
numberOneEntity,
numberZeroEntity,
stringWithNoLengthEntity,
dateEpochEntity,
date5MinAgoEntity,
enumEntity,
photoEntity,
arrayEvenNumbersEntity,
arrayOddNumbersEntity,
arrayStringEntityFirst,
arrayStringEntitySecond,
]);
});

@@ -427,26 +487,56 @@ it('correctly executes string.matches conditions', function () {

var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([stringWithNoLengthEntity]);
expect(result).toMatchObject([
undefinedEntity,
booleanFalseEntity,
booleanTrueEntity,
numberOneEntity,
numberZeroEntity,
stringWithNoLengthEntity,
dateEpochEntity,
date5MinAgoEntity,
enumEntity,
photoEntity,
arrayEvenNumbersEntity,
arrayOddNumbersEntity,
arrayStringEntityFirst,
arrayStringEntitySecond,
]);
});
it('correctly executes string.any_of conditions', function () {
it('correctly executes string.none_of conditions', function () {
var condition = {
field: 'inventory.3',
type: 'string',
operator: 'any_of',
value: ['string', ''],
operator: 'none_of',
value: ['string'],
};
var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([
stringWithLengthEntity,
undefinedEntity,
booleanFalseEntity,
booleanTrueEntity,
numberOneEntity,
numberZeroEntity,
stringWithNoLengthEntity,
dateEpochEntity,
date5MinAgoEntity,
enumEntity,
photoEntity,
arrayEvenNumbersEntity,
arrayOddNumbersEntity,
arrayStringEntityFirst,
arrayStringEntitySecond,
]);
});
it('correctly executes string.none_of conditions', function () {
it('correctly executes string.any_of conditions', function () {
var condition = {
field: 'inventory.3',
type: 'string',
operator: 'none_of',
value: ['string'],
operator: 'any_of',
value: ['string', ''],
};
var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([stringWithNoLengthEntity]);
expect(result).toMatchObject([
stringWithLengthEntity,
stringWithNoLengthEntity,
]);
});

@@ -506,3 +596,19 @@ });

var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([enumEntity]);
expect(result).toMatchObject([
undefinedEntity,
booleanFalseEntity,
booleanTrueEntity,
numberOneEntity,
numberZeroEntity,
stringWithLengthEntity,
stringWithNoLengthEntity,
dateEpochEntity,
date5MinAgoEntity,
enumEntity,
photoEntity,
arrayEvenNumbersEntity,
arrayOddNumbersEntity,
arrayStringEntityFirst,
arrayStringEntitySecond,
]);
});

@@ -527,20 +633,52 @@ it('correctly executes enum.matches conditions', function () {

var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([enumEntity]);
expect(result).toMatchObject([
undefinedEntity,
booleanFalseEntity,
booleanTrueEntity,
numberOneEntity,
numberZeroEntity,
stringWithLengthEntity,
stringWithNoLengthEntity,
dateEpochEntity,
date5MinAgoEntity,
enumEntity,
photoEntity,
arrayEvenNumbersEntity,
arrayOddNumbersEntity,
arrayStringEntityFirst,
arrayStringEntitySecond,
]);
});
it('correctly executes enum.any_of conditions', function () {
it('correctly executes enum.none_of conditions', function () {
var condition = {
field: 'inventory.6',
type: 'enum',
operator: 'any_of',
value: ['alternative1'],
operator: 'none_of',
value: ['alternative2'],
};
var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([enumEntity]);
expect(result).toMatchObject([
undefinedEntity,
booleanFalseEntity,
booleanTrueEntity,
numberOneEntity,
numberZeroEntity,
stringWithLengthEntity,
stringWithNoLengthEntity,
dateEpochEntity,
date5MinAgoEntity,
enumEntity,
photoEntity,
arrayEvenNumbersEntity,
arrayOddNumbersEntity,
arrayStringEntityFirst,
arrayStringEntitySecond,
]);
});
it('correctly executes enum.none_of conditions', function () {
it('correctly executes enum.any_of conditions', function () {
var condition = {
field: 'inventory.6',
type: 'enum',
operator: 'none_of',
value: ['alternative2'],
operator: 'any_of',
value: ['alternative1'],
};

@@ -622,3 +760,18 @@ var result = entityLogic.execute(entities, [condition]);

var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([dateEpochEntity]);
expect(result).toMatchObject([
undefinedEntity,
booleanFalseEntity,
booleanTrueEntity,
numberOneEntity,
numberZeroEntity,
stringWithLengthEntity,
stringWithNoLengthEntity,
dateEpochEntity,
enumEntity,
photoEntity,
arrayEvenNumbersEntity,
arrayOddNumbersEntity,
arrayStringEntityFirst,
arrayStringEntitySecond,
]);
});

@@ -705,3 +858,18 @@ });

var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([arrayEvenNumbersEntity]);
expect(result).toMatchObject([
undefinedEntity,
booleanFalseEntity,
booleanTrueEntity,
numberOneEntity,
numberZeroEntity,
stringWithLengthEntity,
stringWithNoLengthEntity,
dateEpochEntity,
date5MinAgoEntity,
enumEntity,
photoEntity,
arrayEvenNumbersEntity,
arrayStringEntityFirst,
arrayStringEntitySecond,
]);
});

@@ -773,3 +941,18 @@ it('correctly executes array:number.any_of conditions', function () {

var result = entityLogic.execute(entities, [condition]);
expect(result).toMatchObject([arrayStringEntitySecond]);
expect(result).toMatchObject([
undefinedEntity,
booleanFalseEntity,
booleanTrueEntity,
numberOneEntity,
numberZeroEntity,
stringWithLengthEntity,
stringWithNoLengthEntity,
dateEpochEntity,
date5MinAgoEntity,
enumEntity,
photoEntity,
arrayEvenNumbersEntity,
arrayOddNumbersEntity,
arrayStringEntitySecond,
]);
});

@@ -776,0 +959,0 @@ it('correctly executes array:string.any_of conditions', function () {

55

lib/operators.js

@@ -64,3 +64,3 @@ "use strict";

func: function (field, val) { return function (entity, prop_val) {
return typeof prop_val === 'number' && prop_val !== val;
return !(typeof prop_val === 'number' && prop_val === val);
}; },

@@ -118,6 +118,7 @@ },

return function (entity, prop_val) {
return typeof min == 'number' &&
return !(typeof min === 'number' &&
typeof max === 'number' &&
typeof prop_val === 'number' &&
(prop_val < min || prop_val > max);
prop_val >= min &&
prop_val <= max);
};

@@ -129,5 +130,5 @@ },

func: function (field, vals) { return function (entity, prop_val) {
return Array.isArray(vals) &&
return !(Array.isArray(vals) &&
typeof prop_val === 'number' &&
!vals.some(function (v) { return v === prop_val; });
vals.some(function (v) { return v === prop_val; }));
}; },

@@ -170,3 +171,3 @@ },

func: function (field, val) { return function (entity, prop_val) {
return typeof prop_val === 'string' && prop_val !== val;
return !(typeof prop_val === 'string' && prop_val === val);
}; },

@@ -185,5 +186,5 @@ },

func: function (field, val) { return function (entity, prop_val) {
return typeof prop_val === 'string' &&
return !(typeof prop_val === 'string' &&
typeof val === 'string' &&
!escapeAndCompileRegex(val).test(prop_val);
escapeAndCompileRegex(val).test(prop_val));
}; },

@@ -194,7 +195,8 @@ },

func: function (field, vals) { return function (entity, prop_val) {
return Array.isArray(vals) &&
return !(Array.isArray(vals) &&
typeof prop_val === 'string' &&
!vals.some(function (v) {
return typeof v === 'string' && v.toLowerCase() === prop_val.toLowerCase();
});
vals.some(function (v) {
return typeof v === 'string' &&
v.toLowerCase() === prop_val.toLowerCase();
}));
}; },

@@ -239,3 +241,3 @@ },

func: function (field, val) { return function (entity, prop_val) {
return typeof prop_val === 'string' && prop_val !== val;
return !(typeof prop_val === 'string' && prop_val === val);
}; },

@@ -254,16 +256,16 @@ },

func: function (field, val) { return function (entity, prop_val) {
return typeof prop_val === 'string' &&
return !(typeof prop_val === 'string' &&
typeof val === 'string' &&
!escapeAndCompileRegex(val).test(prop_val);
escapeAndCompileRegex(val).test(prop_val));
}; },
},
any_of: {
none_of: {
params: ['array:string'],
func: function (field, vals) { return function (entity, prop_val) {
return Array.isArray(vals) &&
return !(Array.isArray(vals) &&
typeof prop_val === 'string' &&
vals.includes(prop_val);
vals.includes(prop_val));
}; },
},
none_of: {
any_of: {
params: ['array:string'],

@@ -273,3 +275,3 @@ func: function (field, vals) { return function (entity, prop_val) {

typeof prop_val === 'string' &&
!vals.includes(prop_val);
vals.includes(prop_val);
}; },

@@ -329,6 +331,7 @@ },

return function (entity, prop_val) {
return luxon_1.DateTime.isDateTime(from) &&
return !(luxon_1.DateTime.isDateTime(from) &&
luxon_1.DateTime.isDateTime(to) &&
luxon_1.DateTime.isDateTime(prop_val) &&
(prop_val < from || prop_val > to);
prop_val >= from &&
prop_val <= to);
};

@@ -376,5 +379,5 @@ },

func: function (field, vals) { return function (entity, prop_vals) {
return Array.isArray(prop_vals) &&
return !(Array.isArray(prop_vals) &&
Array.isArray(vals) &&
!vals.some(function (v) { return prop_vals.includes(v); });
vals.some(function (v) { return prop_vals.includes(v); }));
}; },

@@ -419,5 +422,5 @@ },

func: function (field, vals) { return function (entity, prop_vals) {
return Array.isArray(prop_vals) &&
return !(Array.isArray(prop_vals) &&
Array.isArray(vals) &&
!vals.some(function (v) { return prop_vals.includes(v); });
vals.some(function (v) { return prop_vals.includes(v); }));
}; },

@@ -424,0 +427,0 @@ },

{
"name": "@allbin/entity-logic",
"version": "0.4.0",
"version": "0.5.0",
"description": "Logic solver for mobilix filters",

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

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