Skip to content

Commit

Permalink
Fix #302. Remove strict mode which causes issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
panuhorsmalahti committed Jan 19, 2016
1 parent ad3d2a5 commit a8f151f
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 90 deletions.
44 changes: 22 additions & 22 deletions lib/cradle.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ cradle.Connection = function Connection(/* variable args */) {
options = {},
remote,
match,
host,
port,
host,
port,
ca,
agentOptions = {},
auth;
Expand All @@ -64,7 +64,7 @@ cradle.Connection = function Connection(/* variable args */) {
ca = options.ca;
} else {
host = a;

if (match = host.match(/^(.+)\:(\d{2,5})$/)) {
host = match[1];
port = parseInt(match[2]);
Expand Down Expand Up @@ -115,7 +115,7 @@ cradle.Connection = function Connection(/* variable args */) {
this.transport = http;
}
this.agent = new (this.transport.Agent)(agentOptions);

this.agent.maxSockets = this.options.maxSockets;
};

Expand All @@ -128,9 +128,9 @@ cradle.Connection = function Connection(/* variable args */) {
// content
//
// OLDAPI: function (method, path, options, data, headers)
//
//
cradle.Connection.prototype.rawRequest = function (options, callback) {
var promise = new(events.EventEmitter),
var promise = new(events.EventEmitter),
self = this;

// HTTP Headers
Expand All @@ -145,7 +145,7 @@ cradle.Connection.prototype.rawRequest = function (options, callback) {
Object.keys(this.options.headers).forEach(function (header) {
options.headers[header] = self.options.headers[header];
});

if (options.query && Object.keys(options.query).length) {
for (var k in options.query) {
if (typeof(options.query[k]) === 'boolean') {
Expand All @@ -159,8 +159,8 @@ cradle.Connection.prototype.rawRequest = function (options, callback) {
options.agent = this.agent;
options.uri = this._url(options.path);
delete options.path;
options = cradle.merge(this.options.request, options);
options = cradle.merge(this.options.request || {}, options);

return request(options, callback || function () { });
};

Expand Down Expand Up @@ -189,7 +189,7 @@ cradle.Connection.prototype.request = function (options, callback) {

// HTTP Headers
options.headers = options.headers || {};

//
// Handle POST/PUT data. We also convert functions to strings,
// so they can be used in _design documents.
Expand Down Expand Up @@ -231,16 +231,16 @@ cradle.Connection.prototype.request = function (options, callback) {
body.headers.status = res.statusCode;
return callback(new cradle.CouchError(body));
}

try { body = JSON.parse(body) }
catch (err) { }

if (body && body.error) {
cradle.extend(body, { headers: res.headers });
body.headers.status = res.statusCode;
return callback(new cradle.CouchError(body));
}

callback(null, self.options.raw ? body : new cradle.Response(body, res));
});
};
Expand Down Expand Up @@ -274,21 +274,21 @@ cradle.Connection.prototype.activeTasks = function (callback) {
this.request({ path: '/_active_tasks' }, callback);
};
cradle.Connection.prototype.uuids = function (count, callback) {
if (typeof(count) === 'function') {
callback = count;
if (typeof(count) === 'function') {
callback = count;
count = null;
}
this.request({
method: 'GET',
path: '/_uuids',

this.request({
method: 'GET',
path: '/_uuids',
query: count ? { count: count } : {}
}, callback);
};
cradle.Connection.prototype.replicate = function (options, callback) {
this.request({
method: 'POST',
path: '/_replicate',
method: 'POST',
path: '/_replicate',
body: options
}, callback);
};
Expand All @@ -298,7 +298,7 @@ cradle.Connection.prototype._url = function (path) {
if (this.port !== 443 && this.port !== 80) {
url += ':' + this.port;
}

url += path[0] === '/' ? path : ('/' + path);
return url;
}
Expand Down
1 change: 0 additions & 1 deletion lib/cradle/cache.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*jshint node:true */
"use strict";

var Response = require('./response').Response;
//
Expand Down
25 changes: 12 additions & 13 deletions lib/cradle/database/attachments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*jshint node:true */
"use strict";

var querystring = require('querystring'),
Args = require('vargs').Constructor,
Expand All @@ -11,7 +10,7 @@ Database.prototype.getAttachment = function (id, attachmentName, callback) {
// TODO: Update cache?
//
return this.connection.rawRequest({
method: 'GET',
method: 'GET',
path: '/' + [this.name, querystring.escape(id), attachmentName].join('/'),
encoding: null
}, callback);
Expand All @@ -29,15 +28,15 @@ Database.prototype.removeAttachment = function (doc, attachmentName, callback) {
id = doc.id || doc._id;
rev = doc.rev || doc._rev;
}

if (!id) {
error = new(TypeError)("first argument must be a document id");
if (!callback) {
throw error;
}
return callback(error);
}

if (!rev && this.cache.has(id)) {
rev = this.cache.get(id)._rev;
} else if (rev) {
Expand All @@ -59,7 +58,7 @@ Database.prototype.saveAttachment = function (doc, attachment, callback) {
error,
rev,
id;

if (typeof doc === 'string') {
id = doc;
} else {
Expand All @@ -74,15 +73,15 @@ Database.prototype.saveAttachment = function (doc, attachment, callback) {
}
return callback(error);
}

attachmentName = typeof attachment !== 'string' ? attachment.name : attachment;

if (!rev && this.cache.has(id)) {
params = { rev: this.cache.get(id)._rev };
} else if (rev) {
params = { rev: rev.replace(/\"/g, '') };
}

options.method = 'PUT';
options.path = '/' + [this.name, querystring.escape(id), attachmentName].join('/');
options.headers = {
Expand All @@ -95,15 +94,15 @@ Database.prototype.saveAttachment = function (doc, attachment, callback) {
if (attachment.contentLength) {
options.headers['Content-Length'] = attachment.contentLength;
}

if (attachment.body) {
options.body = attachment.body;
}

if (params) {
options.path += ('?' + querystring.stringify(params));
}

return this.connection.rawRequest(options, function (err, res, body) {
if (err) {
return callback(err);
Expand All @@ -121,10 +120,10 @@ Database.prototype.saveAttachment = function (doc, attachment, callback) {
cached._attachments = cached._attachments || {};
cached._attachments[attachmentName] = { stub: true };
}

return callback(null, result);
}

callback(result);
});
};
Expand Down
27 changes: 13 additions & 14 deletions lib/cradle/database/changes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*jshint node:true */
"use strict";

var events = require('events'),
querystring = require('querystring'),
Expand All @@ -9,16 +8,16 @@ var events = require('events'),
Database = require('./index').Database;

Database.prototype.changes = function (options, callback) {
if (typeof(options) === 'function') {
if (typeof(options) === 'function') {
callback = options;
options = {};
options = {};
}

options = options || {};

if (callback) {
return this.query({
method: 'GET',
method: 'GET',
path: '_changes',
query: options
}, callback);
Expand All @@ -32,30 +31,30 @@ Database.prototype.changes = function (options, callback) {

if (!options.db) {
protocol = this.connection.protocol || 'http';

if (this.connection.auth && this.connection.auth.username && this.connection.auth.password) {
auth = this.connection.auth.username + ':' + this.connection.auth.password + '@';
auth = this.connection.auth.username + ':' + this.connection.auth.password + '@';
}

options.db = protocol + '://' + auth + this.connection.host + ':' + this.connection.port + '/' + this.name;
}

feed = new follow.Feed(options);
feed.on('change', function () {
//
// Remark: Support the legacy `data` events.
// Remark: Support the legacy `data` events.
//
if (!responded) {
responded = true;
feed.emit('response', response);
}

response.emit.apply(response, ['data'].concat(Array.prototype.slice.call(arguments)));
});

if (options.follow !== false) {
feed.follow();
}

return feed;
};
3 changes: 1 addition & 2 deletions lib/cradle/database/documents.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*jshint node:true */
"use strict";

var querystring = require('querystring'),
Args = require('vargs').Constructor,
Expand Down Expand Up @@ -37,7 +36,7 @@ Database.prototype.get = function (id, rev) {
if (rev && args.length === 2) {
if (typeof(rev) === 'string') {
options = {
rev: rev
rev: rev
};
} else if (typeof(rev) === 'object') {
options = rev;
Expand Down
13 changes: 6 additions & 7 deletions lib/cradle/database/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*jshint node:true */
"use strict";

var querystring = require('querystring'),
Args = require('vargs').Constructor,
Expand Down Expand Up @@ -54,12 +53,12 @@ Database.prototype.create = function (callback) {
Database.prototype.destroy = function (callback) {
if (arguments.length > 1) {
throw new(Error)("destroy() doesn't take any additional arguments");
}
}

this.query({
method: 'DELETE',
path: '/',
}, callback);
method: 'DELETE',
path: '/',
}, callback);
};

//
Expand All @@ -68,4 +67,4 @@ Database.prototype.destroy = function (callback) {
require('./attachments');
require('./changes');
require('./documents');
require('./views');
require('./views');
1 change: 0 additions & 1 deletion lib/cradle/database/views.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*jshint node:true */
"use strict";

var querystring = require('querystring'),
Args = require('vargs').Constructor,
Expand Down
1 change: 0 additions & 1 deletion lib/cradle/errors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*jshint node:true */
"use strict";

var util = require('util');

Expand Down
1 change: 0 additions & 1 deletion lib/cradle/response.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*jshint node:true */
"use strict";

//
// HTTP response wrapper
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cradle",
"version": "0.7.0",
"version": "0.7.1",
"description": "the high-level, caching, CouchDB library",
"url": "http://cloudhead.io/cradle",
"keywords": [
Expand Down
Loading

0 comments on commit a8f151f

Please sign in to comment.