orchestrate
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -13,3 +13,3 @@ // Copyright 2013 Bowery Software, LLC | ||
* Set delegate. | ||
* @param {Client} delegate. | ||
* @param {Client} delegate | ||
* @return {Builder} | ||
@@ -34,3 +34,3 @@ */ | ||
* Set write boolean. | ||
* @param {boolean} | ||
* @param {boolean} write | ||
* @return {Builder} | ||
@@ -44,5 +44,3 @@ */ | ||
/** | ||
* Module exports. | ||
*/ | ||
// Module Exports. | ||
module.exports = Builder |
@@ -10,2 +10,3 @@ // Copyright 2013 Bowery Software, LLC | ||
var Q = require('kew') | ||
var assert = require('assert') | ||
var GraphBuilder = require('./graph') | ||
@@ -20,7 +21,6 @@ var EventBuilder = require('./event') | ||
* @constructor | ||
* @param {string} API token. | ||
* @param {string} token | ||
*/ | ||
function Client (token) { | ||
if (!token) throw new Error('API Key required.') | ||
assert(token, 'API key required.') | ||
if (!(this instanceof Client)) { | ||
@@ -31,3 +31,4 @@ return new Client(token) | ||
/** | ||
* @constant {object} http header. | ||
* HTTP Header. | ||
* @type {Object} | ||
*/ | ||
@@ -39,3 +40,5 @@ this.header = { | ||
/** | ||
* @private {string} API token used for HTTP authentication. | ||
* API token used for HTTP Authentication. | ||
* @type {string} | ||
* @protected | ||
*/ | ||
@@ -55,8 +58,8 @@ this._token = token | ||
* Get data from collection by key-value. | ||
* @param {string} collection. | ||
* @param {string} key. | ||
* @param {string} collection | ||
* @param {string} key | ||
* @return {Promise} | ||
*/ | ||
Client.prototype.get = function (collection, key) { | ||
if (!collection || !key) throw new Error('Collection and key required.') | ||
assert(collection && key, 'Collection and key required.') | ||
return this._get(this.generateApiUrl([collection, key])) | ||
@@ -68,9 +71,9 @@ } | ||
* Put data in collection by key-value | ||
* @param {string} collection. | ||
* @param {string} key. | ||
* @param {object} value. | ||
* @param {string} collection | ||
* @param {string} key | ||
* @param {Object} data | ||
* @return {Promise} | ||
*/ | ||
Client.prototype.put = function (collection, key, data) { | ||
if (!collection || !key || !data) throw new Error('Collection, key, and JSON object required.') | ||
assert(collection && key && data, 'Collection, key, and JSON object required.') | ||
return this._put(this.generateApiUrl([collection, key]), data) | ||
@@ -82,8 +85,8 @@ } | ||
* Remove data from collection by key-value. | ||
* @param {string} collection. | ||
* @param {string} key. | ||
* @param {string} collection | ||
* @param {string} key | ||
* @return {Promise} | ||
*/ | ||
Client.prototype.remove = function (collection, key) { | ||
if (!collection || !key) throw new Error('Collection and key required.') | ||
assert(collection && key, 'Collection and key required.') | ||
return this._del(this.generateApiUrl([collection, key])) | ||
@@ -95,8 +98,8 @@ } | ||
* Search collection by key. | ||
* @param {string} collection. | ||
* @param {string} query. | ||
* @param {string} collection | ||
* @param {string} query | ||
* @return {Promise} | ||
*/ | ||
Client.prototype.search = function (collection, query) { | ||
if (!collection || !query) throw new Error('Collection and query required.') | ||
assert(collection && query, 'Collection and query required.') | ||
return this._get(this.generateApiUrl([collection], query)) | ||
@@ -107,2 +110,13 @@ } | ||
/** | ||
* Delete a collection. | ||
* @param {string} collection | ||
* @return {Promise} | ||
*/ | ||
Client.prototype.deleteCollection = function (collection) { | ||
assert(collection, 'Collection required.') | ||
return this._del(this.generateApiUrl([collection]) + '?force=true') | ||
} | ||
/** | ||
* Create new graph builder. | ||
@@ -153,4 +167,5 @@ * @return {GraphBuilder} | ||
* GET request with authentication. | ||
* @private | ||
* @param {string} url | ||
* @return {Promise} | ||
* @protected | ||
*/ | ||
@@ -170,4 +185,6 @@ Client.prototype._get = function (url) { | ||
* PUT request with authentication. | ||
* @private | ||
* @param {string} url | ||
* @param {Object} data | ||
* @return {Promise} | ||
* @protected | ||
*/ | ||
@@ -187,5 +204,6 @@ Client.prototype._put = function (url, data) { | ||
/** | ||
* DELETE request with auth. | ||
* @private | ||
* DELETE request with authentication. | ||
* @param {string} url | ||
* @return {Promise} | ||
* @protected | ||
*/ | ||
@@ -205,5 +223,5 @@ Client.prototype._del = function (url) { | ||
* Generates and formats api url. | ||
* @param {Array<string>} path components. | ||
* @param {string} query string. | ||
* @return {string} url. | ||
* @param {Array.<string>} path | ||
* @param {string} query | ||
* @return {string} | ||
*/ | ||
@@ -218,5 +236,3 @@ Client.prototype.generateApiUrl = function (path, query) { | ||
/** | ||
* Module exports. | ||
*/ | ||
// Module exports. | ||
module.exports = Client |
@@ -8,2 +8,3 @@ // Copyright 2013 Bowery Software, LLC | ||
// Module Dependencies. | ||
var assert = require('assert') | ||
var Builder = require('./builder') | ||
@@ -22,8 +23,8 @@ | ||
* Set event origin. | ||
* @param {string} collection. | ||
* @param {string} key. | ||
* @param {string} collection | ||
* @param {string} key | ||
* @return {EventBuilder} | ||
*/ | ||
EventBuilder.prototype.from = function (collection, key) { | ||
if (!collection || !key) throw new Error('Collection and key required.') | ||
assert(collection && key, 'Collection and key required.') | ||
this.collection = collection | ||
@@ -37,7 +38,7 @@ this.key = key | ||
* Set event type. | ||
* @param {string} type. | ||
* @param {string} type | ||
* @return {EventBuilder} | ||
*/ | ||
EventBuilder.prototype.type = function (type) { | ||
if (!type) throw new Error('Type required.') | ||
assert(type, 'Type required.') | ||
this.type = type | ||
@@ -50,8 +51,34 @@ if (!this.write) return this._execute('get') | ||
/** | ||
* Set time range start. | ||
* @param {number} time | ||
* @return {EventBuilder} | ||
*/ | ||
EventBuilder.prototype.start = function (time) { | ||
assert(!this.write, 'Invalid operation.') | ||
assert(time && typeof time == 'number', 'Time required (number).') | ||
this.startTime = time | ||
return this | ||
} | ||
/** | ||
* Set time range end. | ||
* @param {number} time | ||
* @return {EventBuilder} | ||
*/ | ||
EventBuilder.prototype.end = function (time) { | ||
assert(!this.write, 'Invalid operation.') | ||
assert(time && typeof time == 'number', 'Time required (number).') | ||
this.endTime = time | ||
return this | ||
} | ||
/** | ||
* Set event data. | ||
* @param {Object} data. | ||
* @param {Object} data | ||
* @return {EventBuilder} | ||
*/ | ||
EventBuilder.prototype.data = function (data) { | ||
if (!data) throw new Error('Data required.') | ||
assert(data, 'Data required.') | ||
this.data = data | ||
@@ -64,8 +91,10 @@ return this._execute('put') | ||
* Execute event read/write. | ||
* @private | ||
* @param {string} method. | ||
* @param {string} method | ||
* @return {Object} | ||
* @protected | ||
*/ | ||
EventBuilder.prototype._execute = function (method) { | ||
var pathArgs = [this.collection, this.key, 'events', this.type] | ||
if (this.startTime) pathArgs.push(this.startTime) | ||
if (this.endTime) pathArgs.push(this.endTime) | ||
var url = this.getDelegate() && this.getDelegate().generateApiUrl(pathArgs) | ||
@@ -76,5 +105,3 @@ return this.getDelegate()['_' + method](url, this.data) | ||
/** | ||
* Module exports. | ||
*/ | ||
// Module Exports. | ||
module.exports = EventBuilder |
@@ -8,2 +8,3 @@ // Copyright 2013 Bowery Software, LLC | ||
// Module Dependencies. | ||
var assert = require('assert') | ||
var Builder = require('./builder') | ||
@@ -23,8 +24,8 @@ | ||
* Set graph origin. | ||
* @param {string} collection. | ||
* @param {string} key. | ||
* @param {string} collection | ||
* @param {string} key | ||
* @return {GraphBuilder} | ||
*/ | ||
GraphBuilder.prototype.from = function (collection, key) { | ||
if (!collection || !key) throw new Error('Collection and key required.') | ||
assert(collection && key, 'Collection and key required.') | ||
this.collection = collection | ||
@@ -38,7 +39,7 @@ this.key = key | ||
* Set graph relation. | ||
* @param {string} relation. | ||
* @param {string} kind | ||
* @return {GraphBuilder} | ||
*/ | ||
GraphBuilder.prototype.related = function (kind) { | ||
if (!kind) throw new Error('Kind of relation required.') | ||
assert(kind, 'Kind of relation required.') | ||
this.kind = kind | ||
@@ -52,8 +53,8 @@ if (!this.write) return this._execute('get') | ||
* Set graph destination. | ||
* @param {string} collection. | ||
* @param {string} key. | ||
* @param {string} toCollection | ||
* @param {string} toKey | ||
* @return {Object} | ||
*/ | ||
GraphBuilder.prototype.to = function (toCollection, toKey) { | ||
if (!toCollection || !toKey) throw new Error('toCollection and toKey required.') | ||
assert(toCollection && toKey, 'toCollection and toKey required.') | ||
this.toCollection = toCollection | ||
@@ -67,5 +68,5 @@ this.toKey = toKey | ||
* Execute graph read/write. | ||
* @private | ||
* @param {string} method. | ||
* @param {string} method | ||
* @return {Object} | ||
* @protected | ||
*/ | ||
@@ -82,5 +83,3 @@ GraphBuilder.prototype._execute = function (method) { | ||
/** | ||
* Module Exports. | ||
*/ | ||
// Module Exports. | ||
module.exports = GraphBuilder |
{ | ||
"name": "orchestrate", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"main": "index", | ||
@@ -5,0 +5,0 @@ "tags": [ |
@@ -68,2 +68,14 @@ # orchestrate.js | ||
To remove a value: | ||
```javascript | ||
db.remove('collection', 'key') | ||
.then(function (result) { | ||
}) | ||
.fail(function (err) { | ||
}) | ||
``` | ||
## Search | ||
@@ -121,5 +133,12 @@ | ||
.from('users', 'Steve') | ||
.start(1384534722568) | ||
.end(1384535726540) | ||
.type('update') | ||
``` | ||
Support from time range requests coming. | ||
## Removing a Collection | ||
```javascript | ||
db.deleteCollection('users') | ||
``` | ||
17910
603
143