spice-couchbase 2.0.43 → 2.0.44
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 +55 -11
- package/package.json +2 -2
- package/src/index.js +64 -17
package/build/index.js
CHANGED
|
@@ -299,12 +299,30 @@ module.exports = class Database {
|
|
|
299
299
|
get(doc_id) {
|
|
300
300
|
var _this8 = this;
|
|
301
301
|
|
|
302
|
+
var {
|
|
303
|
+
columns = []
|
|
304
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
302
305
|
return _asyncToGenerator(function* () {
|
|
303
306
|
try {
|
|
304
|
-
var
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
307
|
+
var useLookupIn = columns.length > 0;
|
|
308
|
+
var response = yield useLookupIn ? (_this8.use_bucket_name ? _this8.connection : _this8.collection).lookupIn(doc_id, columns.map(col => couchbase.LookupInSpec.get(col))) : (_this8.use_bucket_name ? _this8.connection : _this8.collection).get(doc_id);
|
|
309
|
+
|
|
310
|
+
if (useLookupIn) {
|
|
311
|
+
// lookupIn returns content array with each spec result
|
|
312
|
+
var value = {
|
|
313
|
+
id: doc_id
|
|
314
|
+
};
|
|
315
|
+
columns.forEach((col, colIndex) => {
|
|
316
|
+
if (response.content && response.content[colIndex]) {
|
|
317
|
+
value[col] = response.content[colIndex].value;
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
return value;
|
|
321
|
+
} else {
|
|
322
|
+
return _objectSpread({
|
|
323
|
+
id: doc_id
|
|
324
|
+
}, response.content);
|
|
325
|
+
}
|
|
308
326
|
} catch (e) {
|
|
309
327
|
console.error(e);
|
|
310
328
|
}
|
|
@@ -368,16 +386,22 @@ module.exports = class Database {
|
|
|
368
386
|
})();
|
|
369
387
|
}
|
|
370
388
|
|
|
371
|
-
multi_get(keys
|
|
389
|
+
multi_get(keys) {
|
|
372
390
|
var _this14 = this;
|
|
373
391
|
|
|
392
|
+
var {
|
|
393
|
+
keep_type = true,
|
|
394
|
+
columns = []
|
|
395
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
374
396
|
return _asyncToGenerator(function* () {
|
|
375
397
|
if (keys.length == 0) {
|
|
376
398
|
return [];
|
|
377
399
|
}
|
|
378
400
|
|
|
379
401
|
if (_.isArray(keys) && keys.length > 0) {
|
|
380
|
-
var
|
|
402
|
+
var useLookupIn = columns.length > 0;
|
|
403
|
+
|
|
404
|
+
var functions = _.map(keys, key => useLookupIn ? (_this14.use_bucket_name ? _this14.connection : _this14.collection).lookupIn(key, columns.map(col => couchbase.LookupInSpec.get(col))) : (_this14.use_bucket_name ? _this14.connection : _this14.collection).get(key));
|
|
381
405
|
|
|
382
406
|
var returned_all = yield Promise.allSettled(functions);
|
|
383
407
|
|
|
@@ -385,16 +409,36 @@ module.exports = class Database {
|
|
|
385
409
|
return returned_obj === null || returned_obj === void 0 ? void 0 : returned_obj.value;
|
|
386
410
|
}));
|
|
387
411
|
|
|
388
|
-
|
|
412
|
+
var final_responses = _.compact(_.map(responses, (res, index) => {
|
|
389
413
|
if (res) {
|
|
390
|
-
|
|
391
|
-
|
|
414
|
+
var value;
|
|
415
|
+
|
|
416
|
+
if (useLookupIn) {
|
|
417
|
+
// lookupIn returns content array with each spec result
|
|
418
|
+
value = {};
|
|
419
|
+
columns.forEach((col, colIndex) => {
|
|
420
|
+
if (res.content && res.content[colIndex]) {
|
|
421
|
+
value[col] = res.content[colIndex].value;
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
} else {
|
|
425
|
+
// regular get returns the full document in value
|
|
426
|
+
value = res.value;
|
|
392
427
|
}
|
|
393
428
|
|
|
394
|
-
|
|
395
|
-
|
|
429
|
+
if (!keep_type && value) {
|
|
430
|
+
delete value.type;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (value) {
|
|
434
|
+
value.id = keys[index];
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return value;
|
|
396
438
|
}
|
|
397
439
|
}));
|
|
440
|
+
|
|
441
|
+
return final_responses;
|
|
398
442
|
} else {
|
|
399
443
|
return [];
|
|
400
444
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spice-couchbase",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.44",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"axios": "^0.26.1",
|
|
13
|
-
"couchbase": "^4.
|
|
13
|
+
"couchbase": "^4.6.0",
|
|
14
14
|
"lodash": "^4.17.15",
|
|
15
15
|
"qs": "^6.10.3"
|
|
16
16
|
},
|
package/src/index.js
CHANGED
|
@@ -265,13 +265,30 @@ module.exports = class Database {
|
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
async get(doc_id) {
|
|
268
|
+
async get(doc_id, { columns = [] } = {}) {
|
|
269
269
|
try {
|
|
270
|
+
const useLookupIn = columns.length > 0;
|
|
270
271
|
let response = await (
|
|
271
|
-
|
|
272
|
-
|
|
272
|
+
useLookupIn ?
|
|
273
|
+
(this.use_bucket_name ? this.connection : this.collection).lookupIn(
|
|
274
|
+
doc_id,
|
|
275
|
+
columns.map((col) => couchbase.LookupInSpec.get(col))
|
|
276
|
+
)
|
|
277
|
+
: (this.use_bucket_name ? this.connection : this.collection).get(doc_id)
|
|
278
|
+
);
|
|
273
279
|
|
|
274
|
-
|
|
280
|
+
if (useLookupIn) {
|
|
281
|
+
// lookupIn returns content array with each spec result
|
|
282
|
+
let value = { id: doc_id };
|
|
283
|
+
columns.forEach((col, colIndex) => {
|
|
284
|
+
if (response.content && response.content[colIndex]) {
|
|
285
|
+
value[col] = response.content[colIndex].value;
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
return value;
|
|
289
|
+
} else {
|
|
290
|
+
return { id: doc_id, ...response.content };
|
|
291
|
+
}
|
|
275
292
|
} catch (e) {
|
|
276
293
|
console.error(e);
|
|
277
294
|
}
|
|
@@ -302,8 +319,9 @@ module.exports = class Database {
|
|
|
302
319
|
|
|
303
320
|
async count(doc_id, adjustment, initial_value) {
|
|
304
321
|
let res = await (
|
|
305
|
-
this.use_bucket_name ?
|
|
306
|
-
|
|
322
|
+
this.use_bucket_name ?
|
|
323
|
+
this.connection
|
|
324
|
+
: this.collection).counter(doc_id, adjustment, {
|
|
307
325
|
initial: initial_value,
|
|
308
326
|
});
|
|
309
327
|
return res.value;
|
|
@@ -311,8 +329,9 @@ module.exports = class Database {
|
|
|
311
329
|
|
|
312
330
|
async update(doc_id, document, expiry) {
|
|
313
331
|
let res = await (
|
|
314
|
-
this.use_bucket_name ?
|
|
315
|
-
|
|
332
|
+
this.use_bucket_name ?
|
|
333
|
+
this.connection
|
|
334
|
+
: this.collection).replace(doc_id, document, {
|
|
316
335
|
expiry: expiry,
|
|
317
336
|
});
|
|
318
337
|
return res.value;
|
|
@@ -320,38 +339,66 @@ module.exports = class Database {
|
|
|
320
339
|
|
|
321
340
|
async delete(doc_id) {
|
|
322
341
|
let res = await (
|
|
323
|
-
this.use_bucket_name ?
|
|
324
|
-
|
|
342
|
+
this.use_bucket_name ?
|
|
343
|
+
this.connection
|
|
344
|
+
: this.collection).remove(doc_id);
|
|
325
345
|
return res.value;
|
|
326
346
|
}
|
|
327
347
|
|
|
328
|
-
async multi_get(keys, keep_type) {
|
|
348
|
+
async multi_get(keys, { keep_type = true, columns = [] } = {}) {
|
|
329
349
|
if (keys.length == 0) {
|
|
330
350
|
return [];
|
|
331
351
|
}
|
|
332
352
|
if (_.isArray(keys) && keys.length > 0) {
|
|
353
|
+
const useLookupIn = columns.length > 0;
|
|
333
354
|
let functions = _.map(keys, (key) =>
|
|
334
|
-
|
|
355
|
+
useLookupIn ?
|
|
356
|
+
(this.use_bucket_name ? this.connection : this.collection).lookupIn(
|
|
357
|
+
key,
|
|
358
|
+
columns.map((col) => couchbase.LookupInSpec.get(col))
|
|
359
|
+
)
|
|
360
|
+
: (this.use_bucket_name ? this.connection : this.collection).get(key)
|
|
335
361
|
);
|
|
336
362
|
let returned_all = await Promise.allSettled(functions);
|
|
337
363
|
|
|
364
|
+
|
|
365
|
+
|
|
338
366
|
let responses = _.flatten(
|
|
339
367
|
_.map(returned_all, (returned_obj) => {
|
|
340
368
|
return returned_obj?.value;
|
|
341
369
|
})
|
|
342
370
|
);
|
|
343
371
|
|
|
344
|
-
|
|
372
|
+
|
|
373
|
+
let final_responses = _.compact(
|
|
345
374
|
_.map(responses, (res, index) => {
|
|
346
375
|
if (res) {
|
|
347
|
-
|
|
348
|
-
|
|
376
|
+
let value;
|
|
377
|
+
if (useLookupIn) {
|
|
378
|
+
// lookupIn returns content array with each spec result
|
|
379
|
+
value = {};
|
|
380
|
+
columns.forEach((col, colIndex) => {
|
|
381
|
+
if (res.content && res.content[colIndex]) {
|
|
382
|
+
value[col] = res.content[colIndex].value;
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
} else {
|
|
386
|
+
// regular get returns the full document in value
|
|
387
|
+
value = res.value;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (!keep_type && value) {
|
|
391
|
+
delete value.type;
|
|
392
|
+
}
|
|
393
|
+
if (value) {
|
|
394
|
+
value.id = keys[index];
|
|
349
395
|
}
|
|
350
|
-
|
|
351
|
-
return res.value;
|
|
396
|
+
return value;
|
|
352
397
|
}
|
|
353
398
|
})
|
|
354
399
|
);
|
|
400
|
+
|
|
401
|
+
return final_responses;
|
|
355
402
|
} else {
|
|
356
403
|
return [];
|
|
357
404
|
}
|