adapterFun('id', function (callback) { ajax({}, {method: 'GET', url: genUrl(host, '')}, function (err, result) { var uuid = (result && result.uuid) ? (result.uuid + host.db) : genDBUrl(host, ''); callback(null, uuid); }); })
ajax(options, { url: genDBUrl(host, ''), method: 'DELETE' }, function (err, resp) { if (err && err.status && err.status !== 404) { return callback(err); } api.emit('destroyed'); api.constructor.emit('destroyed', opts.name); callback(null, resp); });
function ajaxPromise(userOpts, opts) { return new Promise(function (resolve, reject) { ajax(userOpts, opts, function (err, res) { if (err) { return reject(err); } resolve(res); }); }); }
adapterFun('getAttachment', function (docId, attachmentId, opts, callback) { if (typeof opts === 'function') { callback = opts; opts = {}; } var params = opts.rev ? ('?rev=' + opts.rev) : ''; var url = genDBUrl(host, encodeDocId(docId)) + '/' + encodeAttachmentId(attachmentId) + params; ajax(opts, { method: 'GET', url: url, binary: true }, callback); })
setup().then(function() { ajax({}, { method: 'GET', url: genDBUrl(host, '') }, function (err, res) { /* istanbul ignore next */ if (err) { return callback(err); } res.host = genDBUrl(host, ''); callback(null, res); }); }).catch(callback);
adapterFun('removeAttachment', function (docId, attachmentId, rev, callback) { var url = genDBUrl(host, encodeDocId(docId) + '/' + encodeAttachmentId(attachmentId)) + '?rev=' + rev; ajax({}, { method: 'DELETE', url: url }, callback); })
setup().then(function () { return Promise.all(req.docs.map(preprocessAttachments)); }).then(function () { // Update/create the documents ajax(opts, { method: 'POST', url: genDBUrl(host, '_bulk_docs'), body: req }, function (err, results) { if (err) { return callback(err); } results.forEach(function (result) { result.ok = true; // smooths out cloudant not adding this }); callback(null, results); }); }).catch(callback);
xhr = ajax(opts, xhrOpts, callback); }).catch(callback);
adapterFun('compact', function (opts, callback) { if (typeof opts === 'function') { callback = opts; opts = {}; } opts = clone(opts); ajax(opts, { url: genDBUrl(host, '_compact'), method: 'POST' }, function () { function ping() { api.info(function (err, res) { if (!res.compact_running) { callback(null, {ok: true}); } else { setTimeout(ping, opts.interval || 200); } }); } // Ping the http if it's finished compaction ping(); }); })
params.attachments = true; ajax({}, { headers: host.headers, url: genDBUrl(host, '_bulk_get' + paramsToStr(params)),
adapterFun('revsDiff', function (req, opts, callback) { // If no options were given, set the callback to be the second parameter if (typeof opts === 'function') { callback = opts; opts = {}; } // Get the missing document/revision IDs ajax(opts, { method: 'POST', url: genDBUrl(host, '_revs_diff'), body: req }, callback); })
}; ajax({}, opts, callback); })
adapterFun('request', function (options, callback) { options.url = genDBUrl(host, options.url); ajax({}, options, callback); })
ajax(opts, { method: 'DELETE', url: genDBUrl(host, encodeDocId(doc._id)) + '?rev=' + rev