UNPKG

1.04 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.11.1
2(function() {
3 var mixin;
4
5 mixin = require('./mixin');
6
7 module.exports = function(client, _opts) {
8 return function(bulk, callback) {
9 var opts;
10 opts = mixin(_opts, {
11 body: bulk
12 });
13 return client.bulk(opts).then(function(res) {
14 var oper, reason, ref, ref1, ref2;
15 if (res != null ? res.errors : void 0) {
16 oper = OPERS.find(function(oper) {
17 var ref;
18 return (ref = res.items[0]) != null ? ref[oper] : void 0;
19 });
20 reason = (ref = res.items[0]) != null ? (ref1 = ref[oper]) != null ? (ref2 = ref1.error) != null ? ref2.reason : void 0 : void 0 : void 0;
21 if (reason) {
22 return callback(new Error(reason));
23 } else {
24 return callback(res);
25 }
26 } else {
27 return callback(null, res);
28 }
29 })["catch"](function(err) {
30 return callback(err);
31 });
32 };
33 };
34
35}).call(this);
36
37//# sourceMappingURL=write-bulk.js.map