orchestrate
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -9,2 +9,3 @@ // Copyright 2013 Bowery Software, LLC | ||
var request = require('request') | ||
var util = require('util') | ||
var url = require('url') | ||
@@ -77,10 +78,11 @@ var Q = require('kew') | ||
* @param {string} key | ||
* @param {object} params KV get params (with_fields,without_fields) | ||
* @return {Promise} | ||
*/ | ||
Client.prototype.get = function (collection, key, ref) { | ||
Client.prototype.get = function (collection, key, ref, params) { | ||
assert(collection && key, 'Collection and key required.'); | ||
if (!ref) { | ||
return this._get(this.generateApiUrl([collection, key])); | ||
return this._get(this.generateApiUrl([collection, key], params)); | ||
} else { | ||
return this._get(this.generateApiUrl([collection, key, 'refs', ref])); | ||
return this._get(this.generateApiUrl([collection, key, 'refs', ref], params)); | ||
} | ||
@@ -93,3 +95,3 @@ } | ||
* @param {string} collection | ||
* @param {object} params Listing params (startKey,afterKey,beforeKey,endKey) | ||
* @param {object} params Listing params (startKey,afterKey,beforeKey,endKey,with_fields,without_fields) | ||
* @param {string} startKey | ||
@@ -111,3 +113,3 @@ * @param {string} endKey | ||
* @param {string} collection | ||
* @param {object} params Listing params (limit,offset,values) | ||
* @param {object} params Listing params (limit,offset,values,with_fields,without_fields) | ||
* @return {Promise} | ||
@@ -556,2 +558,4 @@ */ | ||
delete query[key] | ||
else if (util.isArray(query[key])) | ||
query[key] = query[key].join(",") | ||
}) | ||
@@ -558,0 +562,0 @@ |
@@ -197,4 +197,38 @@ // Copyright 2013 Bowery Software, LLC | ||
/** | ||
* Enable field-filtering, with a whitelist of field names | ||
* @example | ||
* // adds a whitelist field-filter for the field value.age | ||
* eventBuilder.withFields('value.age'); | ||
* @example | ||
* // adds two whitelist field-filters, for the fields value.name and value.age | ||
* eventBuilder.withFields('value.name', 'value.age'); | ||
* @param {...string} fieldNames Fully-qualified field names to use as whitelist field-filters | ||
* @return {EventBuilder} | ||
*/ | ||
EventBuilder.prototype.withFields = function () { | ||
this.filterWithFields = this.filterWithFields || []; | ||
this.filterWithFields = this.filterWithFields.concat(Array.prototype.slice.call(arguments)); | ||
return this; | ||
} | ||
/** | ||
* Enable field-filtering, with a blacklist of field names | ||
* @example | ||
* // adds a blacklist field-filter for the field value.age | ||
* eventBuilder.withoutFields('value.age'); | ||
* @example | ||
* // adds two blacklist field-filters, for the fields value.name and value.age | ||
* eventBuilder.withoutFields('value.name', 'value.age'); | ||
* @param {...string} fieldNames Fully-qualified field names to use as blacklist field-filters | ||
* @return {EventBuilder} | ||
*/ | ||
EventBuilder.prototype.withoutFields = function () { | ||
this.filterWithoutFields = this.filterWithoutFields || []; | ||
this.filterWithoutFields = this.filterWithoutFields.concat(Array.prototype.slice.call(arguments)); | ||
return this; | ||
} | ||
/** | ||
* Execute event read/write. | ||
@@ -219,2 +253,4 @@ * @param {string} method | ||
if (this.beforeTime) query['beforeEvent'] = this.beforeTime | ||
if (this.filterWithFields) query['with_fields'] = this.filterWithFields | ||
if (this.filterWithoutFields) query['without_fields'] = this.filterWithoutFields | ||
method = 'get' | ||
@@ -221,0 +257,0 @@ } |
@@ -90,4 +90,38 @@ // Copyright 2013 Bowery Software, LLC | ||
/** | ||
* Enable field-filtering, with a whitelist of field names | ||
* @example | ||
* // adds a whitelist field-filter for the field value.age | ||
* graphBuilder.withFields('value.age'); | ||
* @example | ||
* // adds two whitelist field-filters, for the fields value.name and value.age | ||
* graphBuilder.withFields('value.name', 'value.age'); | ||
* @param {...string} fieldNames Fully-qualified field names to use as whitelist field-filters | ||
* @return {GraphBuilder} | ||
*/ | ||
GraphBuilder.prototype.withFields = function () { | ||
this.filterWithFields = this.filterWithFields || []; | ||
this.filterWithFields = this.filterWithFields.concat(Array.prototype.slice.call(arguments)); | ||
return this; | ||
} | ||
/** | ||
* Enable field-filtering, with a blacklist of field names | ||
* @example | ||
* // adds a blacklist field-filter for the field value.age | ||
* graphBuilder.withoutFields('value.age'); | ||
* @example | ||
* // adds two blacklist field-filters, for the fields value.name and value.age | ||
* graphBuilder.withoutFields('value.name', 'value.age'); | ||
* @param {...string} fieldNames Fully-qualified field names to use as blacklist field-filters | ||
* @return {GraphBuilder} | ||
*/ | ||
GraphBuilder.prototype.withoutFields = function () { | ||
this.filterWithoutFields = this.filterWithoutFields || []; | ||
this.filterWithoutFields = this.filterWithoutFields.concat(Array.prototype.slice.call(arguments)); | ||
return this; | ||
} | ||
/** | ||
* Set graph relation. | ||
@@ -224,2 +258,4 @@ * @param {string} kind | ||
if (this.offset_value) query['offset'] = this.offset_value | ||
if (this.filterWithFields) query['with_fields'] = this.filterWithFields | ||
if (this.filterWithoutFields) query['without_fields'] = this.filterWithoutFields | ||
@@ -226,0 +262,0 @@ // Build headers |
@@ -112,4 +112,38 @@ // Copyright 2013 Bowery Software, LLC | ||
/** | ||
* Enable field-filtering, with a whitelist of field names | ||
* @example | ||
* // adds a whitelist field-filter for the field value.age | ||
* searchBuilder.withFields('value.age'); | ||
* @example | ||
* // adds two whitelist field-filters, for the fields value.name and value.age | ||
* searchBuilder.withFields('value.name', 'value.age'); | ||
* @param {...string} fieldNames Fully-qualified field names to use as whitelist field-filters | ||
* @return {SearchBuilder} | ||
*/ | ||
SearchBuilder.prototype.withFields = function () { | ||
this.filterWithFields = this.filterWithFields || []; | ||
this.filterWithFields = this.filterWithFields.concat(Array.prototype.slice.call(arguments)); | ||
return this; | ||
} | ||
/** | ||
* Enable field-filtering, with a blacklist of field names | ||
* @example | ||
* // adds a blacklist field-filter for the field value.age | ||
* searchBuilder.withoutFields('value.age'); | ||
* @example | ||
* // adds two blacklist field-filters, for the fields value.name and value.age | ||
* searchBuilder.withoutFields('value.name', 'value.age'); | ||
* @param {...string} fieldNames Fully-qualified field names to use as blacklist field-filters | ||
* @return {SearchBuilder} | ||
*/ | ||
SearchBuilder.prototype.withoutFields = function () { | ||
this.filterWithoutFields = this.filterWithoutFields || []; | ||
this.filterWithoutFields = this.filterWithoutFields.concat(Array.prototype.slice.call(arguments)); | ||
return this; | ||
} | ||
/** | ||
* Add new aggregate parameter. | ||
@@ -273,3 +307,5 @@ * @param {string} type | ||
sort: this._generateSort(), | ||
aggregate: this._aggregate | ||
aggregate: this._aggregate, | ||
with_fields: this.filterWithFields, | ||
without_fields: this.filterWithoutFields | ||
}) | ||
@@ -287,3 +323,4 @@ | ||
// Module Exports. | ||
module.exports = SearchBuilder |
@@ -28,3 +28,3 @@ { | ||
}, | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"main": "index", | ||
@@ -31,0 +31,0 @@ "tags": [ |
@@ -0,1 +1,4 @@ | ||
- 0.8.0: 2016-02-17 | ||
* Added 'withFields' and 'withoutFields' field-filtering functions to the | ||
SearchBuilder, EventBuilder, and GraphBuilder APIs. | ||
- 0.7.0: 2015-12-23 | ||
@@ -2,0 +5,0 @@ * Add `sortBy` to `SearchBuilder` which should be preferred over `sort` but |
@@ -64,2 +64,82 @@ // Copyright 2014 Orchestrate, Inc. | ||
}); | ||
test('Put/Get roundtrip, with whitelist field filtering', function () { | ||
var op = function(tstamp, data) { | ||
return db.newEventBuilder() | ||
.from(users.collection, users.steve.email) | ||
.type('update') | ||
.time(tstamp) | ||
.ordinal(0) | ||
.data({"text": data, "foo" : "bar", "bing" : "bong", "zip" : "zap"}) | ||
.create(); }; | ||
// Writes are done asynchronously, so there is no guarantee of order; even | ||
// so mix up the invocations just in case we got lucky and the writes were | ||
// properly ordered | ||
var writes = []; | ||
writes.push(op(2, "message2")); | ||
writes.push(op(3, "message3")); | ||
writes.push(op(1, "message1")); | ||
return Q.all(writes) | ||
.then(function (res) { | ||
assert.equal(3, res.length); | ||
for (var i in res) { | ||
assert.equal(201, res[i].statusCode); | ||
} | ||
return db.newEventReader() | ||
.from(users.collection, users.steve.email) | ||
.type('update') | ||
.withFields('value.text') | ||
.list(); | ||
}) | ||
.then(function (res) { | ||
for (var i in res.body.results) { | ||
var timestamp = res.body.results[i].timestamp; | ||
assert.equal('{"text":"message' + timestamp + '"}', JSON.stringify(res.body.results[i].value)); | ||
} | ||
return Q.resolve(res); | ||
}); | ||
}); | ||
test('Put/Get roundtrip, with blacklist field filtering', function () { | ||
var op = function(tstamp, data) { | ||
return db.newEventBuilder() | ||
.from(users.collection, users.steve.email) | ||
.type('update') | ||
.time(tstamp) | ||
.ordinal(0) | ||
.data({"text": data, "foo" : "bar", "bing" : "bong", "zip" : "zap"}) | ||
.create(); }; | ||
// Writes are done asynchronously, so there is no guarantee of order; even | ||
// so mix up the invocations just in case we got lucky and the writes were | ||
// properly ordered | ||
var writes = []; | ||
writes.push(op(2, "message2")); | ||
writes.push(op(3, "message3")); | ||
writes.push(op(1, "message1")); | ||
return Q.all(writes) | ||
.then(function (res) { | ||
assert.equal(3, res.length); | ||
for (var i in res) { | ||
assert.equal(201, res[i].statusCode); | ||
} | ||
return db.newEventReader() | ||
.from(users.collection, users.steve.email) | ||
.type('update') | ||
.withoutFields('value.foo', 'value.bing', 'value.zip') | ||
.list(); | ||
}) | ||
.then(function (res) { | ||
for (var i in res.body.results) { | ||
var timestamp = res.body.results[i].timestamp; | ||
assert.equal('{"text":"message' + timestamp + '"}', JSON.stringify(res.body.results[i].value)); | ||
} | ||
return Q.resolve(res); | ||
}); | ||
}); | ||
}); |
@@ -36,7 +36,30 @@ // Copyright 2014 Orchestrate, Inc. | ||
var listRelations = function(collection, from, kinds) { | ||
return db.newGraphReader() | ||
.get() | ||
.from(collection, from) | ||
.related(kinds); | ||
var listRelations = function(collection, from, kinds, withFields, withoutFields) { | ||
var hasWithFields = typeof(withFields) !== "undefined"; | ||
var hasWithoutFields = typeof(withoutFields) !== "undefined"; | ||
if (hasWithFields && hasWithoutFields) { | ||
return db.newGraphReader() | ||
.get() | ||
.from(collection, from) | ||
.withFields(withFields) | ||
.withoutFields(withoutFields) | ||
.related(kinds); | ||
} else if (hasWithFields) { | ||
return db.newGraphReader() | ||
.get() | ||
.from(collection, from) | ||
.withFields(withFields) | ||
.related(kinds); | ||
} else if (hasWithoutFields) { | ||
return db.newGraphReader() | ||
.get() | ||
.from(collection, from) | ||
.withoutFields(withoutFields) | ||
.related(kinds); | ||
} else { | ||
return db.newGraphReader() | ||
.get() | ||
.from(collection, from) | ||
.related(kinds); | ||
} | ||
}; | ||
@@ -189,2 +212,20 @@ | ||
test('Traverse graph relationship, with whitelist field filtering', function() { | ||
return listRelations(users.collection, users.steve.email, [ 'friend', 'friend' ], 'value.name', null) | ||
.then(function (res) { | ||
assert.equal(200, res.statusCode); | ||
assert.deepEqual({"name":"David Byrd"}, res.body.results[0].value); | ||
return Q.resolve(res); | ||
}); | ||
}); | ||
test('Traverse graph relationship, with blacklist field filtering', function() { | ||
return listRelations(users.collection, users.steve.email, [ 'friend', 'friend' ], null, [ 'value.email', 'value.location', 'value.type', 'value.gender' ]) | ||
.then(function (res) { | ||
assert.equal(200, res.statusCode); | ||
assert.deepEqual({"name":"David Byrd"}, res.body.results[0].value); | ||
return Q.resolve(res); | ||
}); | ||
}); | ||
test('Delete graph relationship', function() { | ||
@@ -191,0 +232,0 @@ return db.newGraphBuilder() |
@@ -37,2 +37,28 @@ // Copyright 2014 Orchestrate, Inc. | ||
test('Put/Get roundtrip, with whitelist field filtering', function () { | ||
return db.put(users.collection, users.steve.email, users.steve) | ||
.then(function (res) { | ||
assert.equal(201, res.statusCode); | ||
return db.get(users.collection, users.steve.email, null, { 'with_fields' : 'value.name' }); | ||
}) | ||
.then(function (res) { | ||
assert.equal(200, res.statusCode); | ||
assert.equal('{"name":"Steve Kaliski"}', JSON.stringify(res.body)); | ||
return Q.resolve(res); | ||
}); | ||
}); | ||
test('Put/Get roundtrip, with blacklist field filtering', function () { | ||
return db.put(users.collection, users.steve.email, users.steve) | ||
.then(function (res) { | ||
assert.equal(201, res.statusCode); | ||
return db.get(users.collection, users.steve.email, null, { 'without_fields' : [ 'value.email', 'value.location', 'value.type', 'value.gender' ] }); | ||
}) | ||
.then(function (res) { | ||
assert.equal(200, res.statusCode); | ||
assert.equal('{"name":"Steve Kaliski"}', JSON.stringify(res.body)); | ||
return Q.resolve(res); | ||
}); | ||
}); | ||
test('Get by ref', function() { | ||
@@ -55,5 +81,7 @@ return db.get(users.collection, users.steve.email, '0eb6642ca3efde45') | ||
assert.equal(200, res.statusCode); | ||
assert.equal(2, res.body.count); | ||
assert.equal(4, res.body.count); | ||
assert.equal("e85762917a99acce", res.body.results[0].path.ref); | ||
assert.equal("0eb6642ca3efde45", res.body.results[1].path.ref); | ||
assert.equal("0eb6642ca3efde45", res.body.results[2].path.ref); | ||
assert.equal("0eb6642ca3efde45", res.body.results[3].path.ref); | ||
return Q.resolve(res); | ||
@@ -60,0 +88,0 @@ }); |
@@ -35,2 +35,26 @@ // Copyright 2014 Orchestrate, Inc. | ||
// Basic search with whitelist field filtering | ||
test('Basic search with whitelist field filtering', function () { | ||
return db.newSearchBuilder() | ||
.collection(users.collection) | ||
.withFields('value.name') | ||
.query('value.name:"Steve Kaliski"') | ||
.then(function (res) { | ||
assert.equal('{"name":"Steve Kaliski"}', JSON.stringify(res.body.results[0].value)); | ||
return Q.resolve(res); | ||
}); | ||
}); | ||
// Basic search with blacklist field filtering | ||
test('Basic search with blacklist field filtering', function () { | ||
return db.newSearchBuilder() | ||
.collection(users.collection) | ||
.withoutFields('value.email', 'value.location', 'value.type', 'value.gender') | ||
.query('value.name:"Steve Kaliski"') | ||
.then(function (res) { | ||
assert.equal('{"name":"Steve Kaliski"}', JSON.stringify(res.body.results[0].value)); | ||
return Q.resolve(res); | ||
}); | ||
}); | ||
// Cross-collection search (find all items in the 'users' collections, via query clause) | ||
@@ -37,0 +61,0 @@ test('Cross-collection search', function () { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
121112
2806