Comparing version 8.0.2 to 8.1.0
@@ -271,48 +271,71 @@ 'use strict'; | ||
if (Array.isArray(ids)) { | ||
Hoek.assert(ids.length, 'Cannot pass empty array'); | ||
// (id, changes) | ||
if (!changes) { // (updates) | ||
changes = ids; | ||
ids = changes.map((item) => item.id); | ||
} | ||
else { | ||
if (typeof ids[0] === 'object') { // (updates, options) | ||
const options = changes; | ||
changes = ids; | ||
if (!Array.isArray(ids)) { | ||
Hoek.assert(changes && typeof changes === 'object', 'Invalid changes object'); | ||
return this._update(ids, changes, track); | ||
} | ||
if (options.chunks && | ||
changes.length !== 1) { | ||
if (!ids.length) { | ||
return; | ||
} | ||
// Split items into batches | ||
// (updates) | ||
const batches = []; | ||
let left = changes; | ||
while (left.length) { | ||
batches.push(left.slice(0, options.chunks)); | ||
left = left.slice(options.chunks); | ||
} | ||
if (!changes) { | ||
const updates = ids; | ||
return this._update(updates.map((item) => item.id), updates, track); | ||
} | ||
for (let i = 0; i < batches.length; ++i) { | ||
const batch = batches[i]; | ||
await this._update(batch.map((item) => item.id), batch, track); | ||
} | ||
// ([ids], changes) | ||
return; | ||
} | ||
if (typeof ids[0] !== 'object') { | ||
Hoek.assert(!Array.isArray(changes), 'Changes cannot be an array when ids is an array'); | ||
return this._update(ids, changes, track); | ||
} | ||
ids = changes.map((item) => item.id); | ||
} | ||
else { // (ids, changes) | ||
Hoek.assert(!Array.isArray(changes), 'Changes cannot be an array when ids is an array'); | ||
} | ||
} | ||
// ([updates], options) | ||
const options = changes; | ||
changes = ids; | ||
if (!options.chunks || | ||
changes.length <= options.chunks) { | ||
ids = changes.map((item) => item.id); | ||
return this._update(ids, changes, track); | ||
} | ||
else { // (id, changes) | ||
Hoek.assert(changes && typeof changes === 'object', 'Invalid changes object'); | ||
// Split items into batches | ||
const batches = []; | ||
let left = changes; | ||
while (left.length) { | ||
batches.push(left.slice(0, options.chunks)); | ||
left = left.slice(options.chunks); | ||
} | ||
return this._update(ids, changes, track); | ||
for (let i = 0; i < batches.length; ++i) { | ||
const batch = batches[i]; | ||
await this._update(batch.map((item) => item.id), batch, track); | ||
} | ||
} | ||
static items(ids, changes) { | ||
// (id, changes) | ||
// ([ids], changes) | ||
if (!Array.isArray(ids) || | ||
(ids[0] && typeof ids[0] !== 'object')) { | ||
return [changes]; | ||
} | ||
// ([updates]) | ||
// ([updates], options) | ||
return ids; | ||
} | ||
async _update(ids, changes, track) { | ||
@@ -319,0 +342,0 @@ |
{ | ||
"name": "penseur", | ||
"description": "Lightweight RethinkDB wrapper", | ||
"version": "8.0.2", | ||
"version": "8.1.0", | ||
"author": "Eran Hammer <eran@hammer.io> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "repository": "git://github.com/hueniverse/penseur", |
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
1617
67097