Comparing version 8.8.0 to 8.9.0
@@ -568,5 +568,22 @@ 'use strict'; | ||
static append(value, options) { | ||
static append(value, options = {}) { // { single: false, create: false, unique: false } | ||
return internals.special('append', value, options); // { single: false, create: false } | ||
if (options.unique) { // true, false, 'any', 'last', { match, path } | ||
Hoek.assert(options.single || !Array.isArray(value), 'Cannot append multiple values with unique requirements'); | ||
if (typeof options.unique !== 'object') { | ||
options = Object.assign({}, options); // Shallow clone | ||
if (options.unique === true) { | ||
options.unique = { match: 'any' }; // match: any, last | ||
} | ||
else { | ||
options.unique = { match: options.unique }; | ||
} | ||
} | ||
options.unique.match = options.unique.match || 'any'; | ||
} | ||
return internals.special('append', value, options); | ||
} | ||
@@ -573,0 +590,0 @@ |
@@ -26,5 +26,5 @@ 'use strict'; | ||
if (index.options && | ||
index.options.geo && | ||
typeof index.source !== 'function') { | ||
index.options.geo) { | ||
Hoek.assert(typeof index.source !== 'function', 'Cannot use geo index function source'); | ||
indexes.push({ name: index.name, source: index.source || [index.name] }); | ||
@@ -31,0 +31,0 @@ } |
@@ -67,6 +67,9 @@ 'use strict'; | ||
if (typeof changes === 'function' && | ||
changes.type) { | ||
if (typeof changes === 'function') { | ||
if (changes.type === 'unset') { | ||
const { type, value, flags } = changes; | ||
// Unset | ||
if (type === 'unset') { | ||
without.push(internals.select(path)); | ||
@@ -76,39 +79,62 @@ return undefined; | ||
if (changes.type === 'override') { | ||
// Override | ||
if (type === 'override') { | ||
without.push(internals.select(path)); | ||
return internals.wrap(changes.value, without, item, path); | ||
return internals.wrap(value, without, item, path); | ||
} | ||
let row = item(path[0]); | ||
for (let i = 1; i < path.length; ++i) { | ||
row = row(path[i]); | ||
} | ||
// Append | ||
if (changes.type === 'append') { | ||
if (changes.flags.single || | ||
!Array.isArray(changes.value)) { | ||
const current = internals.path(item, path); | ||
let changed = current; | ||
row = row.append(changes.value); | ||
if (type === 'append') { | ||
if (flags.single || | ||
!Array.isArray(value)) { | ||
changed = changed.append(value); | ||
} | ||
else { | ||
for (let i = 0; i < changes.value.length; ++i) { | ||
row = row.append(changes.value[i]); | ||
for (const v of value) { | ||
changed = changed.append(v); | ||
} | ||
} | ||
if (changes.flags.create) { | ||
let check = item; | ||
for (let i = 0; i < path.length - 1; ++i) { | ||
check = check(path[i]); | ||
if (flags.unique) { | ||
let match; | ||
const upath = flags.unique.path; | ||
if (upath) { | ||
const innerValue = Hoek.reach(value, upath); | ||
if (flags.unique.match === 'any') { | ||
match = current.offsetsOf((v) => internals.path(v, upath).eq(innerValue)).count().eq(0); | ||
} | ||
else { | ||
match = internals.path(current, upath).nth(-1).ne(innerValue); | ||
} | ||
} | ||
else { | ||
if (flags.unique.match === 'any') { | ||
match = current.offsetsOf(value).count().eq(0); | ||
} | ||
else { | ||
match = current.nth(-1).ne(value); | ||
} | ||
} | ||
return RethinkDB.branch(check.hasFields(path[path.length - 1]), row, [changes.value]); | ||
changed = RethinkDB.branch(current.count().eq(0), changed, RethinkDB.branch(match, changed, current)); | ||
} | ||
return row; | ||
if (flags.create) { | ||
const check = internals.path(item, path, 1); | ||
changed = RethinkDB.branch(check.hasFields(path[path.length - 1]), changed, [value]); | ||
} | ||
return changed; | ||
} | ||
// type: increment | ||
// Increment | ||
return row.add(changes.value); | ||
return changed.add(value); | ||
} | ||
@@ -144,4 +170,4 @@ | ||
if (Object.keys(changes).length && | ||
!Object.keys(ref).length && | ||
!Array.isArray(ref)) { | ||
!Array.isArray(ref) && | ||
!Object.keys(ref).length) { | ||
@@ -167,1 +193,11 @@ return undefined; | ||
}; | ||
internals.path = function (ref, path, offset = 0) { | ||
for (let i = 0; i < path.length - offset; ++i) { | ||
ref = ref(path[i]); | ||
} | ||
return ref; | ||
}; |
@@ -34,4 +34,3 @@ 'use strict'; | ||
const changes = {}; | ||
keys.forEach((key) => { | ||
for (const key of keys) { | ||
const value = compare[key]; | ||
@@ -45,3 +44,3 @@ if (value === undefined) { // Monitored key not present | ||
return; | ||
continue; | ||
} | ||
@@ -58,3 +57,3 @@ | ||
if (Hoek.deepEqual(base[key], value)) { | ||
return; | ||
continue; | ||
} | ||
@@ -67,3 +66,3 @@ | ||
changes[key] = value; | ||
return; | ||
continue; | ||
} | ||
@@ -77,3 +76,3 @@ } | ||
return; | ||
continue; | ||
} | ||
@@ -84,3 +83,3 @@ | ||
} | ||
}); | ||
} | ||
@@ -87,0 +86,0 @@ if (!Object.keys(changes).length) { |
{ | ||
"name": "penseur", | ||
"description": "Lightweight RethinkDB wrapper", | ||
"version": "8.8.0", | ||
"version": "8.9.0", | ||
"repository": "git://github.com/hueniverse/penseur", | ||
@@ -20,3 +20,3 @@ "main": "lib/index.js", | ||
"code": "5.x.x", | ||
"lab": "16.x.x", | ||
"lab": "18.x.x", | ||
"teamwork": "3.x.x" | ||
@@ -23,0 +23,0 @@ }, |
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
76742
1897