spice-couchbase 2.0.17 → 2.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -20,6 +20,10 @@ var {
20
20
 
21
21
  var qs = require("qs");
22
22
 
23
+ var {
24
+ ConflictResolutionType
25
+ } = require("couchbase");
26
+
23
27
  if (!Promise.allSettled) {
24
28
  Promise.allSettled = promises => Promise.all(promises.map((promise, i) => promise.then(value => ({
25
29
  status: "fulfilled",
@@ -50,17 +54,26 @@ module.exports = class Database {
50
54
  this.collection_manager = spice.database.buckets[connection].collections();
51
55
  this.auto_create_collection = auto_create_collection || (collection || spice.config.database.connections[connection].collection) != undefined && (collection || spice.config.database.connections[connection].collection) != "default" && (scope || spice.config.database.connections[connection].scope) != "_default";
52
56
  this.collection_name = collection || spice.config.database.connections[connection].collection || "_default";
57
+ /* console.log(
58
+ "Collection",
59
+ collection,
60
+ spice.config.database.connections[connection].collection,
61
+ this.collection_name
62
+ );*/
63
+
53
64
  this.scope_name = scope || spice.config.database.connections[connection].scope || "_default";
54
65
  this.scope = spice.database.scopes[connection];
55
66
  this.full_text_index = spice.config.database.connections[connection].full_text_index || full_text_index;
56
67
  this.N1qlQuery = couchbase.N1qlQuery;
57
68
  this.SearchQuery = couchbase.SearchQuery;
58
- this.connection = this.scope.collection(this.collection_name);
69
+ this.collection = this.scope.collection(this.collection_name);
59
70
  this.userManager = this.getUserManager(connection);
60
71
 
61
72
  if (this.auto_create_collection) {
62
73
  this.upsertCollection();
63
74
  }
75
+
76
+ this.use_bucket_name = spice.config.database.connections[this.connection_name].scope == undefined;
64
77
  }
65
78
  }
66
79
 
@@ -228,7 +241,7 @@ module.exports = class Database {
228
241
 
229
242
  return _asyncToGenerator(function* () {
230
243
  try {
231
- var response = yield _this8.connection.get(doc_id);
244
+ var response = yield (_this8.use_bucket_name ? _this8.connection : _this8.collection).get(doc_id);
232
245
  return _objectSpread({
233
246
  id: doc_id
234
247
  }, response.content);
@@ -239,56 +252,32 @@ module.exports = class Database {
239
252
  }
240
253
 
241
254
  insert(doc_id, document, expiry) {
242
- var that = this;
243
- return new Promise(
244
- /*#__PURE__*/
245
- function () {
246
- var _ref = _asyncToGenerator(function* (resolve, reject) {
247
- that.connection.insert(doc_id, document, {
248
- expiry: expiry
249
- },
250
- /*#__PURE__*/
251
- function () {
252
- var _ref2 = _asyncToGenerator(function* (err, res) {
253
- if (err) {
254
- reject(err);
255
- } else {
256
- try {
257
- var created = yield that.get(doc_id);
258
- resolve(created);
259
- } catch (e) {
260
- reject(e);
261
- }
262
- }
263
- });
255
+ var _this9 = this;
264
256
 
265
- return function (_x3, _x4) {
266
- return _ref2.apply(this, arguments);
267
- };
268
- }());
257
+ return _asyncToGenerator(function* () {
258
+ console.log("insert", _this9.use_bucket_name, _this9.connection._name, _this9.collection._name);
259
+ yield (_this9.use_bucket_name ? _this9.connection : _this9.collection).insert(doc_id, document, {
260
+ expiry: expiry
269
261
  });
270
-
271
- return function (_x, _x2) {
272
- return _ref.apply(this, arguments);
273
- };
274
- }());
262
+ return yield _this9.get(doc_id);
263
+ })();
275
264
  }
276
265
 
277
266
  touch(doc_id) {
278
- var _this9 = this;
267
+ var _this10 = this;
279
268
 
280
269
  var expiry = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
281
270
  return _asyncToGenerator(function* () {
282
- yield _this9.connection.touch(doc_id, expiry);
283
- return yield that.get(doc_id);
271
+ yield (_this10.use_bucket_name ? _this10.connection : _this10.collection).touch(doc_id, expiry);
272
+ return yield _this10.get(doc_id);
284
273
  })();
285
274
  }
286
275
 
287
276
  count(doc_id, adjustment, initial_value) {
288
- var _this10 = this;
277
+ var _this11 = this;
289
278
 
290
279
  return _asyncToGenerator(function* () {
291
- var res = yield _this10.connection.counter(doc_id, adjustment, {
280
+ var res = yield (_this11.use_bucket_name ? _this11.connection : _this11.collection).counter(doc_id, adjustment, {
292
281
  initial: initial_value
293
282
  });
294
283
  return res.value;
@@ -296,25 +285,25 @@ module.exports = class Database {
296
285
  }
297
286
 
298
287
  update(doc_id, document) {
299
- var _this11 = this;
288
+ var _this12 = this;
300
289
 
301
290
  return _asyncToGenerator(function* () {
302
- var res = yield _this11.connection.replace(doc_id, document);
291
+ var res = yield (_this12.use_bucket_name ? _this12.connection : _this12.collection).replace(doc_id, document);
303
292
  return res.value;
304
293
  })();
305
294
  }
306
295
 
307
296
  delete(doc_id) {
308
- var _this12 = this;
297
+ var _this13 = this;
309
298
 
310
299
  return _asyncToGenerator(function* () {
311
- var res = yield _this12.connection.remove(doc_id);
300
+ var res = yield (_this13.use_bucket_name ? _this13.connection : _this13.collection).remove(doc_id);
312
301
  return res.value;
313
302
  })();
314
303
  }
315
304
 
316
305
  multi_get(keys, keep_type) {
317
- var _this13 = this;
306
+ var _this14 = this;
318
307
 
319
308
  return _asyncToGenerator(function* () {
320
309
  /* var that = this; */
@@ -326,7 +315,7 @@ module.exports = class Database {
326
315
 
327
316
 
328
317
  if (_.isArray(keys) && keys.length > 0) {
329
- var functions = _.map(keys, key => _this13.connection.get(key));
318
+ var functions = _.map(keys, key => (_this14.use_bucket_name ? _this14.connection : _this14.collection).get(key));
330
319
 
331
320
  var returned_all = yield Promise.allSettled(functions);
332
321
 
@@ -353,7 +342,7 @@ module.exports = class Database {
353
342
  return new Promise(
354
343
  /*#__PURE__*/
355
344
  function () {
356
- var _ref3 = _asyncToGenerator(function* (resolve, reject) {
345
+ var _ref = _asyncToGenerator(function* (resolve, reject) {
357
346
  var ViewQuery = couchbase.ViewQuery;
358
347
  var query = ViewQuery.from(design_doc, view);
359
348
 
@@ -380,7 +369,7 @@ module.exports = class Database {
380
369
  that.connection.query(query,
381
370
  /*#__PURE__*/
382
371
  function () {
383
- var _ref4 = _asyncToGenerator(function* (err, results, matrix) {
372
+ var _ref2 = _asyncToGenerator(function* (err, results, matrix) {
384
373
  var return_value = [];
385
374
 
386
375
  if (err) {
@@ -403,26 +392,25 @@ module.exports = class Database {
403
392
  }
404
393
  });
405
394
 
406
- return function (_x7, _x8, _x9) {
407
- return _ref4.apply(this, arguments);
395
+ return function (_x3, _x4, _x5) {
396
+ return _ref2.apply(this, arguments);
408
397
  };
409
398
  }());
410
399
  });
411
400
 
412
- return function (_x5, _x6) {
413
- return _ref3.apply(this, arguments);
401
+ return function (_x, _x2) {
402
+ return _ref.apply(this, arguments);
414
403
  };
415
404
  }());
416
405
  }
417
406
 
418
407
  search(type, columns, query, limit, offset, order_by, do_count, query_scope) {
419
- var _this14 = this;
408
+ var _this15 = this;
420
409
 
421
410
  return _asyncToGenerator(function* () {
422
- var use_bucket_name = !(spice.config.database.connections[_this14.connection_name].scope && spice.config.database.connections[_this14.connection_name].collection);
423
- var is_legacy = _this14.scope_name !== "_default" && _this14.collection_name !== "_default";
411
+ var is_legacy = _this15.scope_name !== "_default" && _this15.collection_name !== "_default";
424
412
  var alias = "_reference";
425
- var bucket = "`".concat(use_bucket_name ? _this14.bucket : _this14.collection_name, "`");
413
+ var bucket = "`".concat(_this15.use_bucket_name ? _this15.bucket : _this15.collection_name, "`");
426
414
 
427
415
  try {
428
416
  //let uses_scopes = this.scope this.scope_name !== "_default";
@@ -464,7 +452,7 @@ module.exports = class Database {
464
452
 
465
453
  var conditions = [];
466
454
 
467
- if (use_bucket_name) {
455
+ if (_this15.use_bucket_name) {
468
456
  conditions.push("type = '".concat(type, "'"));
469
457
  }
470
458
 
@@ -475,7 +463,7 @@ module.exports = class Database {
475
463
  query = front_query + conditions.join(" AND ");
476
464
  count_query = "SELECT count(meta().id) as count FROM ".concat(bucket);
477
465
 
478
- if (use_bucket_name || query) {
466
+ if (_this15.use_bucket_name || query) {
479
467
  count_query += " WHERE ";
480
468
  }
481
469
 
@@ -493,11 +481,11 @@ module.exports = class Database {
493
481
  query = query + " OFFSET " + offset;
494
482
  }
495
483
 
496
- var active_query_space = query_scope || !use_bucket_name ? "scope" : "cluster";
497
- var queries = [_this14.getData(query, active_query_space)];
484
+ var active_query_space = query_scope || !_this15.use_bucket_name ? "scope" : "cluster";
485
+ var queries = [_this15.getData(query, active_query_space)];
498
486
 
499
487
  if (do_count === "true") {
500
- queries.push(_this14.getCount(count_query, active_query_space));
488
+ queries.push(_this15.getCount(count_query, active_query_space));
501
489
  }
502
490
 
503
491
  var responses = yield Promise.all(queries);
@@ -518,7 +506,7 @@ module.exports = class Database {
518
506
  return new Promise(
519
507
  /*#__PURE__*/
520
508
  function () {
521
- var _ref5 = _asyncToGenerator(function* (resolve, reject) {
509
+ var _ref3 = _asyncToGenerator(function* (resolve, reject) {
522
510
  try {
523
511
  var full_query = search_query + " AND type:" + type;
524
512
  var query = that.SearchQuery.new(that.full_text_index || full_text_index, that.SearchQuery.queryString(full_query));
@@ -539,7 +527,7 @@ module.exports = class Database {
539
527
  that.cluster.query(query,
540
528
  /*#__PURE__*/
541
529
  function () {
542
- var _ref6 = _asyncToGenerator(function* (err, results, matrix) {
530
+ var _ref4 = _asyncToGenerator(function* (err, results, matrix) {
543
531
  var return_value = [];
544
532
 
545
533
  if (err) {
@@ -565,8 +553,8 @@ module.exports = class Database {
565
553
  }
566
554
  });
567
555
 
568
- return function (_x12, _x13, _x14) {
569
- return _ref6.apply(this, arguments);
556
+ return function (_x8, _x9, _x10) {
557
+ return _ref4.apply(this, arguments);
570
558
  };
571
559
  }());
572
560
  } catch (e) {
@@ -574,43 +562,43 @@ module.exports = class Database {
574
562
  }
575
563
  });
576
564
 
577
- return function (_x10, _x11) {
578
- return _ref5.apply(this, arguments);
565
+ return function (_x6, _x7) {
566
+ return _ref3.apply(this, arguments);
579
567
  };
580
568
  }());
581
569
  }
582
570
 
583
571
  getCount(count_query_element) {
584
- var _this15 = this;
572
+ var _this16 = this;
585
573
 
586
574
  var query_scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "cluster";
587
575
  return _asyncToGenerator(function* () {
588
- var response = yield _this15.query(count_query_element, query_scope);
576
+ var response = yield _this16.query(count_query_element, query_scope);
589
577
  return response.rows[0].count;
590
578
  })();
591
579
  }
592
580
 
593
581
  getData(query_element) {
594
- var _this16 = this;
582
+ var _this17 = this;
595
583
 
596
584
  var query_scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "cluster";
597
585
  return _asyncToGenerator(function* () {
598
- var response = yield _this16.query(query_element, query_scope);
586
+ var response = yield _this17.query(query_element, query_scope);
599
587
  return response.rows;
600
588
  })();
601
589
  }
602
590
 
603
591
  query(query) {
604
- var _this17 = this;
592
+ var _this18 = this;
605
593
 
606
594
  var query_scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "cluster";
607
595
  return _asyncToGenerator(function* () {
608
- var scope = query_scope || _this17.query_scope;
596
+ var scope = query_scope || _this18.query_scope;
609
597
 
610
598
  if (scope == "cluster") {
611
- return yield _this17.cluster.query(query);
599
+ return yield _this18.cluster.query(query);
612
600
  } else {
613
- return yield _this17.scope.query(query);
601
+ return yield _this18.scope.query(query);
614
602
  }
615
603
  })();
616
604
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-couchbase",
3
- "version": "2.0.17",
3
+ "version": "2.0.20",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -4,6 +4,7 @@ let _ = require("lodash");
4
4
  let couchbase = require("couchbase");
5
5
  const { default: axios } = require("axios");
6
6
  var qs = require("qs");
7
+ const { ConflictResolutionType } = require("couchbase");
7
8
 
8
9
  if (!Promise.allSettled) {
9
10
  Promise.allSettled = (promises) =>
@@ -51,10 +52,17 @@ module.exports = class Database {
51
52
  "default" &&
52
53
  (scope || spice.config.database.connections[connection].scope) !=
53
54
  "_default");
55
+
54
56
  this.collection_name =
55
57
  collection ||
56
58
  spice.config.database.connections[connection].collection ||
57
59
  "_default";
60
+ /* console.log(
61
+ "Collection",
62
+ collection,
63
+ spice.config.database.connections[connection].collection,
64
+ this.collection_name
65
+ );*/
58
66
  this.scope_name =
59
67
  scope ||
60
68
  spice.config.database.connections[connection].scope ||
@@ -65,16 +73,15 @@ module.exports = class Database {
65
73
  full_text_index;
66
74
  this.N1qlQuery = couchbase.N1qlQuery;
67
75
  this.SearchQuery = couchbase.SearchQuery;
68
- this.connection = this.scope.collection(this.collection_name);
76
+ this.collection = this.scope.collection(this.collection_name);
69
77
  this.userManager = this.getUserManager(connection);
70
78
  if (this.auto_create_collection) {
71
79
  this.upsertCollection();
72
80
  }
73
81
 
74
- this.use_bucket_name = !(
75
- spice.config.database.connections[this.connection_name].scope &&
76
- spice.config.database.connections[this.connection_name].collection
77
- );
82
+ this.use_bucket_name =
83
+ spice.config.database.connections[this.connection_name].scope ==
84
+ undefined;
78
85
  }
79
86
  }
80
87
 
@@ -238,6 +245,12 @@ module.exports = class Database {
238
245
  }
239
246
 
240
247
  async insert(doc_id, document, expiry) {
248
+ console.log(
249
+ "insert",
250
+ this.use_bucket_name,
251
+ this.connection._name,
252
+ this.collection._name
253
+ );
241
254
  await (this.use_bucket_name ? this.connection : this.collection).insert(
242
255
  doc_id,
243
256
  document,