spice-couchbase 2.0.42 → 2.0.43

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
@@ -483,19 +483,46 @@ module.exports = class Database {
483
483
  var is_legacy = _this15.scope_name !== "_default" && _this15.collection_name !== "_default";
484
484
  var bucket = "`".concat(_this15.use_bucket_name ? _this15.bucket : _this15.collection_name, "`");
485
485
 
486
- function containsIdWithSpace(str) {
487
- return /(?<=\W|^)(?!`)(?:(?:\w+`?\.)*)(?:\w+`?\.)?id(?<!`)(?!\w)/i.test(str);
488
- }
486
+ function processColumns(columnsStr) {
487
+ // If columns is empty or *, return default
488
+ if (columnsStr === "*" || !columnsStr) {
489
+ return "(".concat(bucket, ").*, META(").concat(bucket, ").id AS id");
490
+ } // Split by comma and process each column
491
+
492
+
493
+ var columnList = columnsStr.split(",").map(col => col.trim());
494
+ var hasId = false;
495
+ var processedColumns = columnList.map(col => {
496
+ // Check if this column is an id field in various formats
497
+ // Patterns: `collection`.`id`, collection.id, `id`, id
498
+ var idPattern = /^(?:`?(\w+)`?\.)?`?id`?$/i;
499
+ var match = col.match(idPattern);
500
+
501
+ if (match) {
502
+ hasId = true; // match[1] contains the collection name if present
503
+
504
+ if (match[1]) {
505
+ // Has collection prefix: `collection`.`id` or collection.id
506
+ return "META(`".concat(match[1], "`).id AS id");
507
+ } else {
508
+ // Just id without collection prefix
509
+ return "META(".concat(bucket, ").id AS id");
510
+ }
511
+ } // Return the column as-is
489
512
 
490
- try {
491
- var fix = ", META(".concat(bucket, ").id AS id");
492
513
 
493
- if (columns === "*" || !columns) {
494
- columns = "(".concat(bucket, ").* ").concat(fix);
495
- } else if (!containsIdWithSpace(columns)) {
496
- columns = "".concat(columns).concat(fix);
514
+ return col;
515
+ }); // If no id column was provided, add it automatically
516
+
517
+ if (!hasId) {
518
+ processedColumns.push("META(".concat(bucket, ").id AS id"));
497
519
  }
498
520
 
521
+ return processedColumns.join(", ");
522
+ }
523
+
524
+ try {
525
+ columns = processColumns(columns);
499
526
  var front_query = "SELECT ".concat(columns, " FROM ").concat(bucket, " ").concat(join);
500
527
  var conditions = [];
501
528
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-couchbase",
3
- "version": "2.0.42",
3
+ "version": "2.0.43",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -268,9 +268,8 @@ module.exports = class Database {
268
268
  async get(doc_id) {
269
269
  try {
270
270
  let response = await (
271
- this.use_bucket_name ?
272
- this.connection
273
- : this.collection).get(doc_id);
271
+ this.use_bucket_name ? this.connection : this.collection
272
+ ).get(doc_id);
274
273
 
275
274
  return { id: doc_id, ...response.content };
276
275
  } catch (e) {
@@ -303,9 +302,8 @@ module.exports = class Database {
303
302
 
304
303
  async count(doc_id, adjustment, initial_value) {
305
304
  let res = await (
306
- this.use_bucket_name ?
307
- this.connection
308
- : this.collection).counter(doc_id, adjustment, {
305
+ this.use_bucket_name ? this.connection : this.collection
306
+ ).counter(doc_id, adjustment, {
309
307
  initial: initial_value,
310
308
  });
311
309
  return res.value;
@@ -313,9 +311,8 @@ module.exports = class Database {
313
311
 
314
312
  async update(doc_id, document, expiry) {
315
313
  let res = await (
316
- this.use_bucket_name ?
317
- this.connection
318
- : this.collection).replace(doc_id, document, {
314
+ this.use_bucket_name ? this.connection : this.collection
315
+ ).replace(doc_id, document, {
319
316
  expiry: expiry,
320
317
  });
321
318
  return res.value;
@@ -323,9 +320,8 @@ module.exports = class Database {
323
320
 
324
321
  async delete(doc_id) {
325
322
  let res = await (
326
- this.use_bucket_name ?
327
- this.connection
328
- : this.collection).remove(doc_id);
323
+ this.use_bucket_name ? this.connection : this.collection
324
+ ).remove(doc_id);
329
325
  return res.value;
330
326
  }
331
327
 
@@ -428,20 +424,48 @@ module.exports = class Database {
428
424
  this.use_bucket_name ? this.bucket : this.collection_name
429
425
  }\``;
430
426
 
431
- function containsIdWithSpace(str) {
432
- return /(?<=\W|^)(?!`)(?:(?:\w+`?\.)*)(?:\w+`?\.)?id(?<!`)(?!\w)/i.test(
433
- str
434
- );
435
- }
427
+ function processColumns(columnsStr) {
428
+ // If columns is empty or *, return default
429
+ if (columnsStr === "*" || !columnsStr) {
430
+ return `(${bucket}).*, META(${bucket}).id AS id`;
431
+ }
436
432
 
437
- try {
438
- const fix = `, META(${bucket}).id AS id`;
433
+ // Split by comma and process each column
434
+ const columnList = columnsStr.split(",").map((col) => col.trim());
435
+ let hasId = false;
436
+
437
+ const processedColumns = columnList.map((col) => {
438
+ // Check if this column is an id field in various formats
439
+ // Patterns: `collection`.`id`, collection.id, `id`, id
440
+ const idPattern = /^(?:`?(\w+)`?\.)?`?id`?$/i;
441
+ const match = col.match(idPattern);
442
+
443
+ if (match) {
444
+ hasId = true;
445
+ // match[1] contains the collection name if present
446
+ if (match[1]) {
447
+ // Has collection prefix: `collection`.`id` or collection.id
448
+ return `META(\`${match[1]}\`).id AS id`;
449
+ } else {
450
+ // Just id without collection prefix
451
+ return `META(${bucket}).id AS id`;
452
+ }
453
+ }
439
454
 
440
- if (columns === "*" || !columns) {
441
- columns = `(${bucket}).* ${fix}`;
442
- } else if (!containsIdWithSpace(columns)) {
443
- columns = `${columns}${fix}`;
455
+ // Return the column as-is
456
+ return col;
457
+ });
458
+
459
+ // If no id column was provided, add it automatically
460
+ if (!hasId) {
461
+ processedColumns.push(`META(${bucket}).id AS id`);
444
462
  }
463
+
464
+ return processedColumns.join(", ");
465
+ }
466
+
467
+ try {
468
+ columns = processColumns(columns);
445
469
  const front_query = `SELECT ${columns} FROM ${bucket} ${join}`;
446
470
  const conditions = [];
447
471