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

penseur

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

penseur - npm Package Compare versions

Comparing version 8.1.1 to 8.3.0

161

lib/criteria.js

@@ -14,3 +14,3 @@ 'use strict';

exports.select = function (criteria, table) {
exports.select = function (criteria, table, options = {}) {

@@ -31,7 +31,7 @@ if (criteria === null) {

return table.raw.filter(internals.compile(criteria));
return table.raw.filter(internals.compile(criteria, null, options));
};
internals.compile = function (criteria, relative) {
internals.compile = function (criteria, relative, options) {

@@ -61,79 +61,103 @@ /*

if (typeof value === 'function') {
// Simple value
// Special rule
if (typeof value !== 'function') {
const condition = (options.match ? row.match(internals.match(value, options.match)) : row.eq(value));
tests.push(condition.default(null));
continue;
}
Hoek.assert(['contains', 'is', 'not', 'or', 'unset'].indexOf(value.type) !== -1, `Unknown criteria value type ${value.type}`);
// Special rule
if (value.type === 'contains') {
Hoek.assert(['contains', 'is', 'not', 'or', 'unset', 'empty', 'match'].indexOf(value.type) !== -1, `Unknown criteria value type ${value.type}`);
// Contains
if (value.type === 'contains') {
if (value.flags.keys ||
!path) {
// Contains
row = row.keys();
if (value.flags.keys ||
!path) {
row = row.keys();
}
if (!Array.isArray(value.value)) {
tests.push(row.contains(value.value));
}
else {
const conditions = [];
for (let j = 0; j < value.value.length; ++j) {
conditions.push(row.contains(value.value[j]));
}
if (!Array.isArray(value.value)) {
tests.push(row.contains(value.value));
tests.push(RethinkDB[value.flags.condition || 'and'].apply(RethinkDB, conditions));
}
}
else if (value.type === 'match') {
// Match
if (!Array.isArray(value.value)) {
tests.push(row.match(internals.match(value.value, value.flags)));
}
else {
const conditions = [];
for (let j = 0; j < value.value.length; ++j) {
conditions.push(row.match(internals.match(value.value[j], value.flags)));
}
else {
const conditions = [];
for (let j = 0; j < value.value.length; ++j) {
conditions.push(row.contains(value.value[j]));
}
tests.push(RethinkDB[value.flags.condition || 'and'].apply(RethinkDB, conditions));
}
tests.push(RethinkDB[value.flags.condition || 'and'].apply(RethinkDB, conditions));
}
else if (value.type === 'or') {
}
else if (value.type === 'or') {
// Or
// Or
const ors = [];
for (let j = 0; j < value.value.length; ++j) {
const orValue = value.value[j];
if (typeof orValue === 'function') {
Hoek.assert(['unset', 'is'].indexOf(orValue.type) !== -1, `Unknown or criteria value type ${orValue.type}`);
if (orValue.type === 'unset') {
ors.push(exports.row(path.slice(0, -1)).hasFields(path[path.length - 1]).not());
}
else {
ors.push(internals.toComparator(row, orValue));
}
const ors = [];
for (let j = 0; j < value.value.length; ++j) {
const orValue = value.value[j];
if (typeof orValue === 'function') {
Hoek.assert(['unset', 'is', 'empty'].indexOf(orValue.type) !== -1, `Unknown or criteria value type ${orValue.type}`);
if (orValue.type === 'unset') {
ors.push(exports.row(path.slice(0, -1)).hasFields(path[path.length - 1]).not());
}
else if (typeof orValue === 'object') {
ors.push(internals.compile(orValue, path));
else if (orValue.type === 'empty') {
ors.push(internals.empty(path));
}
else {
ors.push(row.eq(orValue).default(null));
ors.push(internals.toComparator(row, orValue));
}
}
let test = RethinkDB.or.apply(RethinkDB, ors);
if (value.flags.not) {
test = test.not();
else if (typeof orValue === 'object') {
ors.push(internals.compile(orValue, path, options));
}
else {
ors.push(row.eq(orValue).default(null));
}
}
tests.push(test);
let test = RethinkDB.or.apply(RethinkDB, ors);
if (value.flags.not) {
test = test.not();
}
else if (value.type === 'is') {
// Is
tests.push(test);
}
else if (value.type === 'is') {
tests.push(internals.toComparator(row, value));
}
else {
// Is
// Unset
tests.push(internals.toComparator(row, value));
}
else if (value.type === 'empty') {
tests.push(exports.row(path.slice(0, -1)).hasFields(path[path.length - 1]).not());
}
// empty
tests.push(internals.empty(path));
}
else {
// Simple value
// Unset
tests.push(row.eq(value).default(null));
tests.push(exports.row(path.slice(0, -1)).hasFields(path[path.length - 1]).not());
}

@@ -216,1 +240,36 @@ }

};
internals.match = function (value, options) {
let prefix = '';
let suffix = '';
if (options.insensitive) {
prefix = '(?i)';
}
if (options.start ||
options.exact) {
prefix += '^';
}
if (options.end ||
options.exact) {
suffix = '$';
}
return prefix + value + suffix;
};
internals.empty = function (path) {
const selector = path.reduce((memo, next) => memo(next), exports.row);
return RethinkDB.branch(
selector.typeOf().eq('ARRAY'), selector.isEmpty(),
selector.typeOf().eq('OBJECT'), selector.keys().isEmpty(),
false);
};

@@ -493,2 +493,7 @@ 'use strict';

static match(values, options) {
return internals.special('match', values, options);
}
static not(values) {

@@ -529,2 +534,7 @@

static empty() {
return internals.special('empty');
}
// Criteria or Modifier

@@ -556,11 +566,13 @@

internals.Db.prototype.or = internals.Db.or;
internals.Db.prototype.append = internals.Db.append;
internals.Db.prototype.by = internals.Db.by;
internals.Db.prototype.contains = internals.Db.contains;
internals.Db.prototype.empty = internals.Db.empty;
internals.Db.prototype.increment = internals.Db.increment;
internals.Db.prototype.is = internals.Db.is;
internals.Db.prototype.match = internals.Db.match;
internals.Db.prototype.not = internals.Db.not;
internals.Db.prototype.or = internals.Db.or;
internals.Db.prototype.override = internals.Db.override;
internals.Db.prototype.unset = internals.Db.unset;
internals.Db.prototype.increment = internals.Db.increment;
internals.Db.prototype.append = internals.Db.append;
internals.Db.prototype.override = internals.Db.override;
internals.Db.prototype.is = internals.Db.is;
internals.Db.prototype.by = internals.Db.by;

@@ -567,0 +579,0 @@

@@ -0,0 +0,0 @@ 'use strict';

@@ -145,3 +145,3 @@ 'use strict';

try {
const selection = Criteria.select(criteria, this);
const selection = Criteria.select(criteria, this, options);
return await this._db._run(this._refine(selection, options), track);

@@ -148,0 +148,0 @@ }

@@ -0,0 +0,0 @@ 'use strict';

{
"name": "penseur",
"description": "Lightweight RethinkDB wrapper",
"version": "8.1.1",
"version": "8.3.0",
"author": "Eran Hammer <eran@hammer.io> (http://hueniverse.com)",

@@ -6,0 +6,0 @@ "repository": "git://github.com/hueniverse/penseur",

@@ -192,2 +192,3 @@ # penseur

#### `Db.unset()`
#### `Db.empty()`
#### `Db.increment(value)`

@@ -194,0 +195,0 @@ #### `Db.append(value[, options])`

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