Comparing version 7.12.1 to 7.12.2
@@ -30,2 +30,58 @@ 'use strict'; | ||
exports.normalize = function (ids, allowArray) { | ||
if (!Array.isArray(ids)) { | ||
return internals.validate(ids); | ||
} | ||
if (!allowArray) { | ||
return new Error('Array of ids not supported'); | ||
} | ||
if (!ids.length) { | ||
return new Error('Empty array of ids not supported'); | ||
} | ||
const normalized = []; | ||
for (let i = 0; i < ids.length; ++i) { | ||
const id = internals.validate(ids[i]); | ||
if (id instanceof Error) { | ||
return id; | ||
} | ||
normalized.push(id); | ||
} | ||
return normalized; | ||
}; | ||
internals.validate = function (id) { | ||
if (id && | ||
typeof id === 'object') { | ||
if (id.id === undefined) { | ||
return new Error('Invalid object id'); | ||
} | ||
id = id.id; | ||
} | ||
if (id === null || | ||
id === undefined) { | ||
return new Error('Invalid null or undefined id'); | ||
} | ||
if (typeof id === 'string' && | ||
id.length > 127) { | ||
return new Error(`Invalid id length: ${id}`); | ||
} | ||
return id; | ||
}; | ||
exports.compile = function (table, options) { | ||
@@ -111,6 +167,6 @@ | ||
return (b[buf[0]] + b[buf[1]] + b[buf[2]] + b[buf[3]] + '-' + | ||
b[buf[4]] + b[buf[5]] + '-' + | ||
b[buf[6]] + b[buf[7]] + '-' + | ||
b[buf[8]] + b[buf[9]] + '-' + | ||
b[buf[10]] + b[buf[11]] + b[buf[12]] + b[buf[13]] + b[buf[14]] + b[buf[15]]); | ||
b[buf[4]] + b[buf[5]] + '-' + | ||
b[buf[6]] + b[buf[7]] + '-' + | ||
b[buf[8]] + b[buf[9]] + '-' + | ||
b[buf[10]] + b[buf[11]] + b[buf[12]] + b[buf[13]] + b[buf[14]] + b[buf[15]]); | ||
}; | ||
@@ -117,0 +173,0 @@ |
@@ -49,3 +49,3 @@ 'use strict'; | ||
return RethinkDB.expr(pairs)(item('id').coerceTo('string')); | ||
return RethinkDB.expr(pairs)(item(table.primary).coerceTo('string')); | ||
}; | ||
@@ -52,0 +52,0 @@ }; |
@@ -43,3 +43,3 @@ 'use strict'; | ||
get(id, options, callback) { | ||
get(ids, options, callback) { | ||
@@ -51,18 +51,15 @@ if (!callback) { | ||
if (Array.isArray(id)) { | ||
for (let i = 0; i < id.length; ++i) { | ||
if (id[i].toString().length > 127) { | ||
return this._error('get', 'Invalid id length', id, Hoek.nextTick(callback)); | ||
} | ||
} | ||
const diag = { ids, options }; | ||
this._run(this._refine(this.raw.getAll(RethinkDB.args(id)), options), 'get', id, callback); | ||
return; | ||
const batch = Array.isArray(ids); | ||
ids = Id.normalize(ids, true); | ||
if (ids instanceof Error) { | ||
return this._error('get', ids.message, diag, Hoek.nextTick(callback)); | ||
} | ||
if (id.toString().length > 127) { | ||
return this._error('get', 'Invalid id length', id, Hoek.nextTick(callback)); | ||
if (batch) { | ||
return this._run(this._refine(this.raw.getAll(RethinkDB.args(ids)), options), 'get', diag, callback); | ||
} | ||
this._run(this._refine(this.raw.get(id), options), 'get', id, callback); | ||
return this._run(this._refine(this.raw.get(ids), options), 'get', diag, callback); | ||
} | ||
@@ -116,7 +113,9 @@ | ||
if (id.toString().length > 127) { | ||
return this._error('exist', 'Invalid id length', id, Hoek.nextTick(callback)); | ||
const diag = { id }; | ||
id = Id.normalize(id, false); | ||
if (id instanceof Error) { | ||
return this._error('exist', id.message, diag, Hoek.nextTick(callback)); | ||
} | ||
this._run(this.raw.get(id).ne(null), 'exist', id, callback); | ||
this._run(this.raw.get(id).ne(null), 'exist', diag, callback); | ||
} | ||
@@ -222,3 +221,4 @@ | ||
this._run(Criteria.select(criteria, this), 'single', criteria, (err, result) => { | ||
const diag = { criteria }; | ||
this._run(Criteria.select(criteria, this), 'single', diag, (err, result) => { | ||
@@ -234,3 +234,3 @@ if (err) { | ||
if (result.length !== 1) { | ||
return this._error('single', 'Found multiple items', criteria, callback); | ||
return this._error('single', 'Found multiple items', diag, callback); | ||
} | ||
@@ -361,2 +361,4 @@ | ||
const diag = { ids, changes }; | ||
if (Array.isArray(ids)) { | ||
@@ -387,3 +389,3 @@ Hoek.assert(ids.length, 'Cannot pass empty array'); | ||
const each = (batch, next) => this._update(batch.map((item) => item.id), batch, next); | ||
const each = (batch, next) => this._update(batch.map((item) => item.id), batch, diag, next); | ||
return Items.serial(batches, each, (err) => callback(err)); | ||
@@ -403,10 +405,14 @@ } | ||
return this._update(ids, changes, callback); | ||
return this._update(ids, changes, diag, callback); | ||
} | ||
_update(ids, changes, callback) { | ||
_update(ids, changes, diag, callback) { | ||
const diag = { ids, changes }; | ||
const batch = Array.isArray(ids); | ||
ids = Id.normalize(ids, true); | ||
if (ids instanceof Error) { | ||
return this._error('update', ids.message, diag, Hoek.nextTick(callback)); | ||
} | ||
Unique.reserve(this, changes, (batch ? true : ids), (err, postUnique) => { | ||
@@ -442,2 +448,7 @@ | ||
const diag = { id, field, value }; | ||
id = Id.normalize(id, false); | ||
if (id instanceof Error) { | ||
return this._error('next', id.message, diag, Hoek.nextTick(callback)); | ||
} | ||
this._run(this.raw.get(id).update(changes, { returnChanges: true }), 'next', diag, (err, result) => { | ||
@@ -465,3 +476,4 @@ | ||
this._run(selection.delete(), 'remove', criteria, (err, result) => { | ||
const diag = { criteria }; | ||
this._run(selection.delete(), 'remove', diag, (err, result) => { | ||
@@ -475,3 +487,3 @@ if (err) { | ||
return this._error('remove', 'No item found to remove', criteria, callback); | ||
return this._error('remove', 'No item found to remove', diag, callback); | ||
} | ||
@@ -478,0 +490,0 @@ |
{ | ||
"name": "penseur", | ||
"description": "Lightweight RethinkDB wrapper", | ||
"version": "7.12.1", | ||
"version": "7.12.2", | ||
"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
75224
1732