New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

orchestrate

Package Overview
Dependencies
Maintainers
4
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

orchestrate - npm Package Compare versions

Comparing version 0.4.2 to 0.4.3

test/patch.test.js

46

lib/client.js

@@ -61,2 +61,3 @@ // Copyright 2013 Bowery Software, LLC

Client.ApiProtocol = 'https:'

@@ -151,10 +152,23 @@ /**

* @param {Object} data
* @param {string} match ETag string (optional)
* @param {Object} options - Map with the following possible entries:
* {string} match - the item ref used to check for concurrent update (ie to make
* sure the item was not changed and the patch is applying to
* the right version of the item).
* {boolean} upsert - set to true if this patch should be treated as an
* insert when the item is not present.
*
* @return {Promise}
*/
Client.prototype.merge = function (collection, key, data, match) {
Client.prototype.merge = function (collection, key, data, options) {
assert(collection && key && data, 'Collection, key and JSON object required.')
options = options || {}
if (typeof options === 'string') {
// legacy behavior, 4th arg was the 'match' ref string.
options = {match:options}
}
var match = options.match;
var upsert = options.upsert === true;
var header = {'Content-Type': 'application/merge-patch+json'}
if (typeof match == 'string') header['If-Match'] = this._quote(match)
return this._patch(this.generateApiUrl([collection, key]), data, header)
return this._patch(this.generateApiUrl([collection, key], {upsert:upsert}), data, header)
}

@@ -167,10 +181,24 @@

* @param {[Object]} patchOps array of operations; see http://orchestrate.io/docs/apiref#keyvalue-patch
* @param {string} match ETag string (optional)
* @param {Object} options - Map with the following possible entries:
* {string} match - the item ref used to check for concurrent update (ie to make
* sure the item was not changed and the patch is applying to
* the right version of the item).
* {boolean} upsert - set to true if this patch should be treated as an
* insert when the item is not present.
* @return {Promise}
*/
Client.prototype.patch = function (collection, key, patchOps, match) {
Client.prototype.patch = function (collection, key, patchOps, options) {
assert(collection && key && patchOps, 'Collection, key and JSON object required.')
assert(patchOps.length > 0, 'At least one operation is required in a patch operation.');
options = options || {}
if (typeof options === 'string') {
// legacy behavior, 4th arg was the 'match' ref string.
options = {match:options}
}
var match = options.match;
var upsert = options.upsert === true;
var header = {'Content-Type': 'application/json-patch+json'}
if (typeof match == 'string') header['If-Match'] = this._quote(match)
return this._patch(this.generateApiUrl([collection, key]), patchOps, header)
return this._patch(this.generateApiUrl([collection, key], {upsert:upsert}), patchOps, header)
}

@@ -379,3 +407,2 @@

headers['User-Agent'] = this._userAgent
request({

@@ -443,3 +470,3 @@ method: method,

link.get = function (linkUrl) {
return this._get('https://' + Client.ApiEndPoint + linkUrl)
return this._get(Client.ApiProtocol + '//' + Client.ApiEndPoint + linkUrl)
}.bind(this, link.url)

@@ -501,3 +528,2 @@ }

Client.prototype.generateApiUrl = function (path, query) {
var href = Client.ApiEndPoint
var pathname = ''

@@ -518,3 +544,3 @@

return url.format({
protocol: 'https:',
protocol: Client.ApiProtocol,
host: Client.ApiEndPoint + '/' + Client.ApiVersion,

@@ -521,0 +547,0 @@ pathname: pathname,

@@ -11,3 +11,2 @@ // Copyright 2014 Orchestrate, Inc.

function PatchBuilder (collection, key) {
assert(collection && key, 'Collection and key are required.');
this._collection = collection;

@@ -76,8 +75,11 @@ this._key = key;

* Test equality of a value at the specified JSON document path
* @param {string} path - JSON document path; delimtied by periods or slashes
* @param {string} path - JSON document path; delimited by periods or slashes
* @param {Object} value - Value to compare against
* @param {boolean} negate - true if the test should be negated
*/
PatchBuilder.prototype.test = function (path, value) {
PatchBuilder.prototype.test = function (path, value, negate) {
assert(path, 'Test requires a path parameter.');
this._ops.push({"op": "test", "path": path, "value": value});
var op = {"op": "test", "path": path, "value": value};
if (negate === true) op.negate = true;
this._ops.push(op);
return this;

@@ -87,4 +89,13 @@ };

/**
* Test NON-equality of a value at the specified JSON document path
* @param {string} path - JSON document path; delimited by periods or slashes
* @param {Object} value - Value to compare against
*/
PatchBuilder.prototype.testNot = function (path, value) {
return this.test(path, value, true);
};
/**
* Increase the value at the specified JSON document path by the given number
* @param {string} path - JSON document path; delimtied by periods or slashes
* @param {string} path - JSON document path; delimited by periods or slashes
* @param {Object} value - Number by which to increase the value

@@ -104,12 +115,92 @@ */

/**
* Init the value at the specified JSON document path to the given value
* ONLY if there isn't already a value there.
* @param {string} path - JSON document path; delimited by periods or slashes
* @param {Object} value - Value to initialize the path to (if not present).
*/
PatchBuilder.prototype.init = function (path, value) {
assert(path, 'Init requires a path parameter.');
assert(value !== undefined, 'Init requires a value parameter.');
this._ops.push({"op": "init", "path": path, "value": value});
return this;
};
/**
* Append the given value to an Array at the specified JSON document path.
* If value is an Array, all items in the Array will be appended to the target
* Array. Otherwise, the single value will be appended.
* @param {string} path - JSON document path; delimited by periods or slashes
* @param {Object|Array} value - Value(s) to append to the Array.
*/
PatchBuilder.prototype.append = function (path, value) {
assert(path, 'Append requires a path parameter.');
assert(value !== undefined, 'Append requires a value parameter.');
this._ops.push({"op": "append", "path": path, "value": value});
return this;
};
/**
* Merge the given value with an Object at the specified JSON document path.
* @param {string} path - JSON document path; delimited by periods or slashes
* @param {Object|Array} value - Value to merge in.
*/
PatchBuilder.prototype.merge = function (path, value) {
assert(path, 'Merge requires a path parameter.');
assert(value !== undefined, 'Merge requires a value parameter.');
this._ops.push({"op": "merge", "path": path, "value": value});
return this;
};
/**
* Apply the given value as a patch against an Object at the specified JSON document path.
* @param {string} path - JSON document path; delimited by periods or slashes
* @param {PatchBuilder|Array} value - Patch ops to apply.
* @param {boolean} conditional - true if this nested patch op is conditional,
* meaning the test ops in this nested patch's ops list will only be used
* to determine whether the nested patch will be applied, but will not
* fail the overall patch operation.
*/
PatchBuilder.prototype.patch = function (path, value, conditional) {
assert(path, 'Patch Op requires a path parameter.');
assert(value !== undefined, 'Patch Op requires a value parameter.');
assert(Array.isArray(value) || value instanceof PatchBuilder,
'Patch Op value must be an Array of ops or a PatchBuilder.');
var ops = value._ops || value;
var op = {"op": "patch", "path": path, "value": ops};
if (conditional === true) op.conditional = true;
this._ops.push(op);
return this;
};
/**
* Convenience method for creating a conditional nested patch op. Just calls
* PatchBuilder.prototype.patch with 'true' for the conditional argument.
* @param {string} path - JSON document path; delimited by periods or slashes
* @param {PatchBuilder|Array} value - Patch ops to apply.
*/
PatchBuilder.prototype.patchIf = function (path, value) {
return this.patch(path, value, true);
}
/**
* Make this patch an 'upsert'. If the key does not exist in the collection,
* it will be created as an empty Json Object, then the patch applied.
* Call with true or with no argument to enable upsert. The default behavior
* is non-upsert, where the response will be 404 if trying to patch a key
* that does not exist.
*
* @param {boolean} upsert - true to make this patch an upsert.
*/
PatchBuilder.prototype.upsert = function (upsert) {
this._upsert = upsert !== false;
return this;
}
/**
* return {Promise}
*/
PatchBuilder.prototype.apply = function (match) {
assert(this._ops.length > 0, 'At least one operation is required in a patch operation.');
assert(this.getDelegate(), 'No client delegate assigned');
var pathArgs = [this._collection, this._key];
var url = this.getDelegate().generateApiUrl(pathArgs);
var header = {'Content-Type': 'application/json-patch+json'};
if (typeof match === 'string') header['If-Match'] = this.getDelegate()._quote(match);
return this.getDelegate()._patch(url, this._ops, header);
return this.getDelegate().patch(this._collection, this._key, this._ops,
{match:match,upsert:this._upsert === true})
};

@@ -116,0 +207,0 @@

@@ -101,6 +101,22 @@ // Copyright 2013 Bowery Software, LLC

/**
* Add new 'top_values' aggregate parameter.
* @param {string} path
* @param {number} offset
* @param {number} limit
* @return {SearchBuilder}
*/
SearchBuilder.prototype.top_values = function (path, offset, limit) {
if (typeof(offset) !== "undefined" && typeof(limit) !== "undefined") {
return this.aggregate('top_values', path, "offset", offset, "limit", limit);
}
assert(
typeof(offset) === "undefined" && typeof(limit) === "undefined",
"offset or limit params must be included together, or not at all"
);
return this.aggregate('top_values', path);
}
/**
* Add new 'stats' aggregate parameter.
* @param {string} type
* @param {string} path
* @param {string} value
* @return {SearchBuilder}

@@ -114,5 +130,4 @@ */

* Add new 'range' aggregate parameter.
* @param {string} type
* @param {string} path
* @param {string} value
* @param {array|function} buckets
* @return {SearchBuilder}

@@ -132,5 +147,4 @@ */

* Add new 'distance' aggregate parameter.
* @param {string} type
* @param {string} path
* @param {string} value
* @param {array|function} buckets
* @return {SearchBuilder}

@@ -157,3 +171,2 @@ */

*
* @param {string} type
* @param {string} path

@@ -160,0 +173,0 @@ * @param {string} time

@@ -28,3 +28,3 @@ {

},
"version": "0.4.2",
"version": "0.4.3",
"main": "index",

@@ -31,0 +31,0 @@ "tags": [

@@ -1,1 +0,10 @@

exports.token = process.env.ORCHESTRATE_API_KEY || 'sample_token';
var oio = require('../lib-cov/client');
oio.ApiProtocol = process.env.ORCHESTRATE_API_PROTOCOL || 'https:'
oio.ApiEndPoint = process.env.ORCHESTRATE_API_ENDPOINT || 'api.orchestrate.io'
var token = process.env.ORCHESTRATE_API_KEY || 'sample_token';
module.exports = function() {
return oio(token);
}

@@ -9,4 +9,3 @@ // Copyright 2014 Orchestrate, Inc.

var Q = require('kew');
var token = require('./creds').token;
var db = require('../lib-cov/client')(token);
var db = require('./creds')();
var users = require('./testdata')('event.test');

@@ -13,0 +12,0 @@ var util = require('util');

@@ -8,4 +8,3 @@ // Copyright 2014 Orchestrate, Inc.

var assert = require('assert');
var token = require('./creds').token;
var db = require('../lib-cov/client')(token);
var db = require('./creds')();
var users = require('./testdata')('graph.test');

@@ -12,0 +11,0 @@ var Q = require('kew');

@@ -9,4 +9,3 @@ // Copyright 2014 Orchestrate, Inc.

var assert = require('assert');
var token = require('./creds').token;
var db = require('../lib-cov/client')(token);
var db = require('./creds')();
var users = require('./testdata')('key-value.test');

@@ -178,2 +177,21 @@ var util = require('util');

});
test('Merge as upsert', function(done) {
var key = users.steve.email + '_2';
db.merge(users.collection, key, {type: "consultant"}, {upsert:true})
.then(function (res) {
assert.equal(201, res.statusCode);
return db.get(users.collection, key);
})
.then(function (res) {
assert.equal(200, res.statusCode);
assert.deepEqual({type: "consultant"}, res.body);
done();
})
.fail(function (e) {
done(e);
});
});
});

@@ -8,4 +8,3 @@ // Copyright 2014 Orchestrate, Inc.

var assert = require('assert');
var token = require('./creds').token;
var db = require('../lib-cov/client')(token);
var db = require('./creds')();
var Q = require('kew');

@@ -12,0 +11,0 @@ var util = require('util');

@@ -8,4 +8,3 @@ // Copyright 2014 Orchestrate, Inc.

var assert = require('assert');
var token = require('./creds').token;
var db = require('../lib-cov/client')(token);
var db = require('./creds')();
var users = require('./testdata')('search.test');

@@ -104,2 +103,4 @@ var Q = require('kew');

.aggregate('stats', 'value.name')
.top_values('value.tags')
.top_values('value.categories', 20, 10)
.stats('value.username')

@@ -106,0 +107,0 @@ .range('value.coolness', '*~1:1~2:2~*')

@@ -8,4 +8,3 @@ // Copyright 2014 Orchestrate, Inc.

var Q = require('kew');
var token = require('./creds').token;
var db = require('../lib-cov/client')(token);
var db = require('./creds')();
var util = require('util');

@@ -118,2 +117,3 @@

dels.push(db.remove(collection, obj.steve.email, true))
dels.push(db.remove(collection, obj.steve.email+'_2', true))
dels.push(db.remove(collection, obj.david.email, true))

@@ -120,0 +120,0 @@ dels.push(db.remove(collection, obj.kelsey.email, true))

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