couchbase 4.7.0 → 4.7.2

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.
Files changed (84) hide show
  1. package/CMakeLists.txt +3 -0
  2. package/deps/couchbase-cxx-cache/mozilla-ca-bundle.crt +96 -727
  3. package/deps/couchbase-cxx-cache/mozilla-ca-bundle.sha256 +1 -1
  4. package/deps/couchbase-cxx-client/CMakeLists.txt +3 -1
  5. package/deps/couchbase-cxx-client/README.md +2 -2
  6. package/deps/couchbase-cxx-client/core/error_context/base_error_context.hxx +32 -0
  7. package/deps/couchbase-cxx-client/core/error_context/key_value.cxx +1 -0
  8. package/deps/couchbase-cxx-client/core/error_context/key_value.hxx +23 -0
  9. package/deps/couchbase-cxx-client/core/error_context/key_value_error_context.hxx +35 -0
  10. package/deps/couchbase-cxx-client/core/error_context/subdocument_error_context.hxx +41 -0
  11. package/deps/couchbase-cxx-client/core/impl/binary_collection.cxx +123 -88
  12. package/deps/couchbase-cxx-client/core/impl/collection.cxx +416 -189
  13. package/deps/couchbase-cxx-client/core/impl/error.cxx +29 -4
  14. package/deps/couchbase-cxx-client/core/impl/invoke_with_node_id.hxx +44 -0
  15. package/deps/couchbase-cxx-client/core/impl/node_id.cxx +110 -0
  16. package/deps/couchbase-cxx-client/core/impl/node_id.hxx +40 -0
  17. package/deps/couchbase-cxx-client/core/io/configuration_belongs_to_session.hxx +67 -0
  18. package/deps/couchbase-cxx-client/core/io/http_session_manager.hxx +97 -57
  19. package/deps/couchbase-cxx-client/core/io/mcbp_session.cxx +7 -16
  20. package/deps/couchbase-cxx-client/core/operations/document_get_all_replicas.hxx +14 -4
  21. package/deps/couchbase-cxx-client/core/operations/document_get_projected.cxx +3 -4
  22. package/deps/couchbase-cxx-client/core/operations/document_lookup_in_all_replicas.hxx +4 -0
  23. package/deps/couchbase-cxx-client/core/operations/document_query.cxx +12 -12
  24. package/deps/couchbase-cxx-client/core/operations/management/collection_create.cxx +11 -11
  25. package/deps/couchbase-cxx-client/core/operations/management/collection_drop.cxx +11 -11
  26. package/deps/couchbase-cxx-client/core/operations/management/collection_update.cxx +11 -11
  27. package/deps/couchbase-cxx-client/core/operations/management/error_utils.cxx +9 -6
  28. package/deps/couchbase-cxx-client/core/operations/management/query_index_create.cxx +5 -4
  29. package/deps/couchbase-cxx-client/core/operations/management/query_index_drop.cxx +7 -6
  30. package/deps/couchbase-cxx-client/core/operations/management/scope_create.cxx +12 -13
  31. package/deps/couchbase-cxx-client/core/operations/management/scope_drop.cxx +8 -9
  32. package/deps/couchbase-cxx-client/core/topology/configuration.cxx +21 -0
  33. package/deps/couchbase-cxx-client/core/topology/configuration.hxx +28 -0
  34. package/deps/couchbase-cxx-client/core/utils/contains_string.cxx +61 -0
  35. package/deps/couchbase-cxx-client/core/utils/contains_string.hxx +26 -0
  36. package/deps/couchbase-cxx-client/couchbase/collection.hxx +73 -0
  37. package/deps/couchbase-cxx-client/couchbase/error.hxx +16 -0
  38. package/deps/couchbase-cxx-client/couchbase/node_id.hxx +123 -0
  39. package/deps/couchbase-cxx-client/couchbase/node_id_for_options.hxx +61 -0
  40. package/deps/couchbase-cxx-client/couchbase/node_ids_options.hxx +62 -0
  41. package/deps/couchbase-cxx-client/couchbase/result.hxx +42 -0
  42. package/dist/analyticsexecutor.d.ts +4 -0
  43. package/dist/analyticsexecutor.js +26 -11
  44. package/dist/analyticsindexmanager.js +2 -2
  45. package/dist/binding.d.ts +12 -2
  46. package/dist/bindingutilities.js +8 -5
  47. package/dist/bucket.d.ts +9 -1
  48. package/dist/bucket.js +21 -0
  49. package/dist/cluster.d.ts +10 -1
  50. package/dist/cluster.js +25 -3
  51. package/dist/collection.d.ts +3 -3
  52. package/dist/collection.js +189 -143
  53. package/dist/diagnosticsexecutor.js +2 -2
  54. package/dist/diagnosticstypes.d.ts +36 -0
  55. package/dist/diagnosticstypes.js +22 -1
  56. package/dist/mutationstate.js +1 -1
  57. package/dist/observability.d.ts +5 -1
  58. package/dist/observability.js +11 -3
  59. package/dist/observabilityhandler.d.ts +19 -0
  60. package/dist/observabilityhandler.js +81 -14
  61. package/dist/observabilitytypes.js +19 -42
  62. package/dist/observabilityutilities.js +1 -1
  63. package/dist/oteltracer.d.ts +5 -0
  64. package/dist/oteltracer.js +7 -0
  65. package/dist/queryexecutor.d.ts +9 -0
  66. package/dist/queryexecutor.js +18 -0
  67. package/dist/queryindexmanager.js +15 -0
  68. package/dist/searchexecutor.d.ts +4 -0
  69. package/dist/searchexecutor.js +30 -15
  70. package/dist/thresholdlogging.d.ts +5 -0
  71. package/dist/thresholdlogging.js +7 -0
  72. package/dist/tracing.d.ts +6 -0
  73. package/dist/transactions.js +29 -6
  74. package/dist/version.d.ts +1 -1
  75. package/dist/version.js +1 -1
  76. package/dist/viewexecutor.d.ts +4 -0
  77. package/dist/viewexecutor.js +30 -15
  78. package/dist/waituntilreadyexecutor.d.ts +37 -0
  79. package/dist/waituntilreadyexecutor.js +156 -0
  80. package/package.json +8 -8
  81. package/scripts/prebuilds.js +13 -0
  82. package/src/binding.cpp +1 -1
  83. package/src/connection.hpp +24 -3
  84. package/src/jstocbpp_errors.hpp +6 -0
@@ -180,13 +180,17 @@ class Collection {
180
180
  if (!options) {
181
181
  options = {};
182
182
  }
183
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Get, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
183
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
184
+ ? null
185
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Get, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
184
186
  try {
185
187
  const cppDocId = this._cppDocId(key);
186
- obsReqHandler.setRequestKeyValueAttributes(cppDocId);
188
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId);
187
189
  if (options.project || options.withExpiry) {
188
- options.parentSpan = obsReqHandler.wrappedSpan;
189
- return this._projectedGet(key, options, obsReqHandler, callback);
190
+ // Thread the span through a copy: the options object belongs to the
191
+ // caller, and one reused across requests would otherwise carry a
192
+ // finished request's span into the next call.
193
+ return this._projectedGet(key, { ...options, parentSpan: obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.wrappedSpan }, obsReqHandler, callback);
190
194
  }
191
195
  const transcoder = options.transcoder || this.transcoder;
192
196
  const timeout = options.timeout || this.cluster.kvTimeout;
@@ -198,19 +202,18 @@ class Collection {
198
202
  opaque: 0,
199
203
  }, obsReqHandler);
200
204
  if (err) {
201
- obsReqHandler.endWithError(err);
205
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
202
206
  throw err;
203
207
  }
204
- const content = transcoder.decode(resp.value, resp.flags);
205
- obsReqHandler.end();
206
- return new crudoptypes_1.GetResult({
207
- content: content,
208
+ const toResult = () => new crudoptypes_1.GetResult({
209
+ content: transcoder.decode(resp.value, resp.flags),
208
210
  cas: resp.cas,
209
211
  });
212
+ return obsReqHandler ? obsReqHandler.endAfter(toResult) : toResult();
210
213
  }, callback);
211
214
  }
212
215
  catch (e) {
213
- obsReqHandler.endWithError(e);
216
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
214
217
  throw e;
215
218
  }
216
219
  }
@@ -255,7 +258,7 @@ class Collection {
255
258
  });
256
259
  }
257
260
  catch (e) {
258
- obsReqHandler.endWithError(e);
261
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
259
262
  throw e;
260
263
  }
261
264
  let content = null;
@@ -265,6 +268,7 @@ class Collection {
265
268
  expiry = expiryRes.value;
266
269
  }
267
270
  if (projStart >= 0) {
271
+ content = {};
268
272
  if (!needReproject) {
269
273
  for (let i = 0; i < paths.length; ++i) {
270
274
  const projPath = paths[i];
@@ -275,17 +279,19 @@ class Collection {
275
279
  }
276
280
  }
277
281
  else {
278
- content = {};
279
282
  const reprojRes = res.content[projStart];
280
283
  for (let j = 0; j < paths.length; ++j) {
281
284
  const reprojPath = paths[j];
282
285
  const value = sdutils_1.SdUtils.getByPath(reprojRes.value, reprojPath);
286
+ if (value === undefined) {
287
+ continue;
288
+ }
283
289
  content = sdutils_1.SdUtils.insertByPath(content, reprojPath, value);
284
290
  }
285
291
  }
286
292
  }
287
293
  // The parent span is created w/in the get() operation
288
- obsReqHandler.end();
294
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
289
295
  return new crudoptypes_1.GetResult({
290
296
  content: content,
291
297
  cas: res.cas,
@@ -308,11 +314,13 @@ class Collection {
308
314
  if (!options) {
309
315
  options = {};
310
316
  }
311
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Exists, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
317
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
318
+ ? null
319
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Exists, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
312
320
  try {
313
321
  const cppDocId = this._cppDocId(key);
314
322
  const timeout = options.timeout || this.cluster.kvTimeout;
315
- obsReqHandler.setRequestKeyValueAttributes(cppDocId);
323
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId);
316
324
  return utilities_1.PromiseHelper.wrapAsync(async () => {
317
325
  const [err, resp] = await (0, observability_1.wrapObservableBindingCall)(this._conn.exists.bind(this._conn), {
318
326
  id: cppDocId,
@@ -321,10 +329,10 @@ class Collection {
321
329
  timeout,
322
330
  }, obsReqHandler);
323
331
  if (err) {
324
- obsReqHandler.endWithError(err);
332
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
325
333
  throw err;
326
334
  }
327
- obsReqHandler.end();
335
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
328
336
  if (resp.deleted) {
329
337
  return new crudoptypes_1.ExistsResult({
330
338
  cas: undefined,
@@ -338,20 +346,20 @@ class Collection {
338
346
  }, callback);
339
347
  }
340
348
  catch (e) {
341
- obsReqHandler.endWithError(e);
349
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
342
350
  throw e;
343
351
  }
344
352
  }
345
353
  /**
346
354
  * @internal
347
355
  */
348
- _getReplica(key, obsReqHandler, options, callback) {
356
+ _getReplica(key, opType, obsReqHandler, options, callback) {
349
357
  const cppDocId = this._cppDocId(key);
350
- obsReqHandler.setRequestKeyValueAttributes(cppDocId);
358
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId);
351
359
  const emitter = new streamablepromises_1.StreamableReplicasPromise((replicas) => replicas);
352
360
  const transcoder = options.transcoder || this.transcoder;
353
361
  const timeout = options.timeout || this.cluster.kvTimeout;
354
- if (obsReqHandler.opType == observabilitytypes_1.KeyValueOp.GetAllReplicas) {
362
+ if (opType == observabilitytypes_1.KeyValueOp.GetAllReplicas) {
355
363
  utilities_1.PromiseHelper.wrapAsync(async () => {
356
364
  const [err, resp] = await (0, observability_1.wrapObservableBindingCall)(this._conn.getAllReplicas.bind(this._conn), {
357
365
  id: cppDocId,
@@ -359,12 +367,12 @@ class Collection {
359
367
  read_preference: (0, bindingutilities_1.readPreferenceToCpp)(options.readPreference),
360
368
  }, obsReqHandler);
361
369
  if (err) {
362
- obsReqHandler.endWithError(err);
370
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
363
371
  emitter.emit('error', err);
364
372
  emitter.emit('end');
365
373
  return;
366
374
  }
367
- resp.entries.forEach((replica) => {
375
+ for (const replica of resp.entries) {
368
376
  try {
369
377
  const content = transcoder.decode(replica.value, replica.flags);
370
378
  emitter.emit('replica', new crudoptypes_1.GetReplicaResult({
@@ -374,13 +382,13 @@ class Collection {
374
382
  }));
375
383
  }
376
384
  catch (err) {
377
- obsReqHandler.endWithError(err);
385
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
378
386
  emitter.emit('error', err);
379
387
  emitter.emit('end');
380
388
  return;
381
389
  }
382
- });
383
- obsReqHandler.end();
390
+ }
391
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
384
392
  emitter.emit('end');
385
393
  });
386
394
  }
@@ -392,7 +400,7 @@ class Collection {
392
400
  read_preference: (0, bindingutilities_1.readPreferenceToCpp)(options.readPreference),
393
401
  }, obsReqHandler);
394
402
  if (err) {
395
- obsReqHandler.endWithError(err);
403
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
396
404
  emitter.emit('error', err);
397
405
  emitter.emit('end');
398
406
  return;
@@ -406,10 +414,12 @@ class Collection {
406
414
  }));
407
415
  }
408
416
  catch (err) {
409
- obsReqHandler.endWithError(err);
417
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
410
418
  emitter.emit('error', err);
419
+ emitter.emit('end');
420
+ return;
411
421
  }
412
- obsReqHandler.end();
422
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
413
423
  emitter.emit('end');
414
424
  });
415
425
  }
@@ -431,15 +441,17 @@ class Collection {
431
441
  if (!options) {
432
442
  options = {};
433
443
  }
434
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.GetAnyReplica, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
444
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
445
+ ? null
446
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.GetAnyReplica, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
435
447
  try {
436
448
  return utilities_1.PromiseHelper.wrapAsync(async () => {
437
- const replicas = await this._getReplica(key, obsReqHandler, options);
449
+ const replicas = await this._getReplica(key, observabilitytypes_1.KeyValueOp.GetAnyReplica, obsReqHandler, options);
438
450
  return replicas[0];
439
451
  }, callback);
440
452
  }
441
453
  catch (e) {
442
- obsReqHandler.endWithError(e);
454
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
443
455
  throw e;
444
456
  }
445
457
  }
@@ -459,12 +471,14 @@ class Collection {
459
471
  if (!options) {
460
472
  options = {};
461
473
  }
462
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.GetAllReplicas, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
474
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
475
+ ? null
476
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.GetAllReplicas, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
463
477
  try {
464
- return this._getReplica(key, obsReqHandler, options, callback);
478
+ return this._getReplica(key, observabilitytypes_1.KeyValueOp.GetAllReplicas, obsReqHandler, options, callback);
465
479
  }
466
480
  catch (e) {
467
- obsReqHandler.endWithError(e);
481
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
468
482
  throw e;
469
483
  }
470
484
  }
@@ -477,6 +491,7 @@ class Collection {
477
491
  * @param callback A node-style callback to be invoked after execution.
478
492
  */
479
493
  insert(key, value, options, callback) {
494
+ var _a;
480
495
  if (options instanceof Function) {
481
496
  callback = arguments[2];
482
497
  options = undefined;
@@ -484,7 +499,9 @@ class Collection {
484
499
  if (!options) {
485
500
  options = {};
486
501
  }
487
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Insert, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
502
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
503
+ ? null
504
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Insert, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
488
505
  try {
489
506
  const cppDocId = this._cppDocId(key);
490
507
  const cppDurability = (0, bindingutilities_1.durabilityToCpp)(options.durabilityLevel);
@@ -493,10 +510,8 @@ class Collection {
493
510
  const persistTo = options.durabilityPersistTo;
494
511
  const replicateTo = options.durabilityReplicateTo;
495
512
  const timeout = options.timeout || this._mutationTimeout(options.durabilityLevel);
496
- obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
497
- const [bytesBuf, flags] = obsReqHandler.maybeCreateEncodingSpan(() => {
498
- return transcoder.encode(value);
499
- });
513
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
514
+ const [bytesBuf, flags] = (_a = obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.maybeCreateEncodingSpan(() => transcoder.encode(value))) !== null && _a !== void 0 ? _a : transcoder.encode(value);
500
515
  const insertReq = {
501
516
  id: cppDocId,
502
517
  value: bytesBuf,
@@ -525,10 +540,10 @@ class Collection {
525
540
  }, obsReqHandler);
526
541
  }
527
542
  if (err) {
528
- obsReqHandler.endWithError(err);
543
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
529
544
  throw err;
530
545
  }
531
- obsReqHandler.end();
546
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
532
547
  return new crudoptypes_1.MutationResult({
533
548
  cas: resp.cas,
534
549
  token: resp.token,
@@ -536,7 +551,7 @@ class Collection {
536
551
  }, callback);
537
552
  }
538
553
  catch (e) {
539
- obsReqHandler.endWithError(e);
554
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
540
555
  throw e;
541
556
  }
542
557
  }
@@ -550,6 +565,7 @@ class Collection {
550
565
  * @param callback A node-style callback to be invoked after execution.
551
566
  */
552
567
  upsert(key, value, options, callback) {
568
+ var _a;
553
569
  if (options instanceof Function) {
554
570
  callback = arguments[2];
555
571
  options = undefined;
@@ -557,7 +573,9 @@ class Collection {
557
573
  if (!options) {
558
574
  options = {};
559
575
  }
560
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Upsert, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
576
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
577
+ ? null
578
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Upsert, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
561
579
  try {
562
580
  const cppDocId = this._cppDocId(key);
563
581
  const cppDurability = (0, bindingutilities_1.durabilityToCpp)(options.durabilityLevel);
@@ -567,10 +585,8 @@ class Collection {
567
585
  const persistTo = options.durabilityPersistTo;
568
586
  const replicateTo = options.durabilityReplicateTo;
569
587
  const timeout = options.timeout || this._mutationTimeout(options.durabilityLevel);
570
- obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
571
- const [bytesBuf, flags] = obsReqHandler.maybeCreateEncodingSpan(() => {
572
- return transcoder.encode(value);
573
- });
588
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
589
+ const [bytesBuf, flags] = (_a = obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.maybeCreateEncodingSpan(() => transcoder.encode(value))) !== null && _a !== void 0 ? _a : transcoder.encode(value);
574
590
  const upsertReq = {
575
591
  id: cppDocId,
576
592
  value: bytesBuf,
@@ -600,10 +616,10 @@ class Collection {
600
616
  }, obsReqHandler);
601
617
  }
602
618
  if (err) {
603
- obsReqHandler.endWithError(err);
619
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
604
620
  throw err;
605
621
  }
606
- obsReqHandler.end();
622
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
607
623
  return new crudoptypes_1.MutationResult({
608
624
  cas: resp.cas,
609
625
  token: resp.token,
@@ -611,7 +627,7 @@ class Collection {
611
627
  }, callback);
612
628
  }
613
629
  catch (e) {
614
- obsReqHandler.endWithError(e);
630
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
615
631
  throw e;
616
632
  }
617
633
  }
@@ -624,6 +640,7 @@ class Collection {
624
640
  * @param callback A node-style callback to be invoked after execution.
625
641
  */
626
642
  replace(key, value, options, callback) {
643
+ var _a;
627
644
  if (options instanceof Function) {
628
645
  callback = arguments[2];
629
646
  options = undefined;
@@ -631,7 +648,9 @@ class Collection {
631
648
  if (!options) {
632
649
  options = {};
633
650
  }
634
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Replace, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
651
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
652
+ ? null
653
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Replace, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
635
654
  try {
636
655
  const cppDocId = this._cppDocId(key);
637
656
  const cppDurability = (0, bindingutilities_1.durabilityToCpp)(options.durabilityLevel);
@@ -642,10 +661,8 @@ class Collection {
642
661
  const persistTo = options.durabilityPersistTo;
643
662
  const replicateTo = options.durabilityReplicateTo;
644
663
  const timeout = options.timeout || this._mutationTimeout(options.durabilityLevel);
645
- obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
646
- const [bytesBuf, flags] = obsReqHandler.maybeCreateEncodingSpan(() => {
647
- return transcoder.encode(value);
648
- });
664
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
665
+ const [bytesBuf, flags] = (_a = obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.maybeCreateEncodingSpan(() => transcoder.encode(value))) !== null && _a !== void 0 ? _a : transcoder.encode(value);
649
666
  const replaceReq = {
650
667
  id: cppDocId,
651
668
  value: bytesBuf,
@@ -676,10 +693,10 @@ class Collection {
676
693
  }, obsReqHandler);
677
694
  }
678
695
  if (err) {
679
- obsReqHandler.endWithError(err);
696
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
680
697
  throw err;
681
698
  }
682
- obsReqHandler.end();
699
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
683
700
  return new crudoptypes_1.MutationResult({
684
701
  cas: resp.cas,
685
702
  token: resp.token,
@@ -687,7 +704,7 @@ class Collection {
687
704
  }, callback);
688
705
  }
689
706
  catch (e) {
690
- obsReqHandler.endWithError(e);
707
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
691
708
  throw e;
692
709
  }
693
710
  }
@@ -706,7 +723,9 @@ class Collection {
706
723
  if (!options) {
707
724
  options = {};
708
725
  }
709
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Remove, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
726
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
727
+ ? null
728
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Remove, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
710
729
  try {
711
730
  const cppDocId = this._cppDocId(key);
712
731
  const cppDurability = (0, bindingutilities_1.durabilityToCpp)(options.durabilityLevel);
@@ -714,7 +733,7 @@ class Collection {
714
733
  const persistTo = options.durabilityPersistTo;
715
734
  const replicateTo = options.durabilityReplicateTo;
716
735
  const timeout = options.timeout || this._mutationTimeout(options.durabilityLevel);
717
- obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
736
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
718
737
  const removeReq = {
719
738
  id: cppDocId,
720
739
  cas: cas || binding_1.zeroCas,
@@ -741,10 +760,10 @@ class Collection {
741
760
  }, obsReqHandler);
742
761
  }
743
762
  if (err) {
744
- obsReqHandler.endWithError(err);
763
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
745
764
  throw err;
746
765
  }
747
- obsReqHandler.end();
766
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
748
767
  return new crudoptypes_1.MutationResult({
749
768
  cas: resp.cas,
750
769
  token: resp.token,
@@ -752,7 +771,7 @@ class Collection {
752
771
  }, callback);
753
772
  }
754
773
  catch (e) {
755
- obsReqHandler.endWithError(e);
774
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
756
775
  throw e;
757
776
  }
758
777
  }
@@ -778,12 +797,14 @@ class Collection {
778
797
  if (!options) {
779
798
  options = {};
780
799
  }
781
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.GetAndTouch, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
800
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
801
+ ? null
802
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.GetAndTouch, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
782
803
  try {
783
804
  const cppDocId = this._cppDocId(key);
784
805
  const transcoder = options.transcoder || this.transcoder;
785
806
  const timeout = options.timeout || this.cluster.kvTimeout;
786
- obsReqHandler.setRequestKeyValueAttributes(cppDocId);
807
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId);
787
808
  return utilities_1.PromiseHelper.wrapAsync(async () => {
788
809
  const [err, resp] = await (0, observability_1.wrapObservableBindingCall)(this._conn.getAndTouch.bind(this._conn), {
789
810
  id: cppDocId,
@@ -793,19 +814,18 @@ class Collection {
793
814
  opaque: 0,
794
815
  }, obsReqHandler);
795
816
  if (err) {
796
- obsReqHandler.endWithError(err);
817
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
797
818
  throw err;
798
819
  }
799
- const content = transcoder.decode(resp.value, resp.flags);
800
- obsReqHandler.end();
801
- return new crudoptypes_1.GetResult({
802
- content: content,
820
+ const toResult = () => new crudoptypes_1.GetResult({
821
+ content: transcoder.decode(resp.value, resp.flags),
803
822
  cas: resp.cas,
804
823
  });
824
+ return obsReqHandler ? obsReqHandler.endAfter(toResult) : toResult();
805
825
  }, callback);
806
826
  }
807
827
  catch (e) {
808
- obsReqHandler.endWithError(e);
828
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
809
829
  throw e;
810
830
  }
811
831
  }
@@ -830,11 +850,13 @@ class Collection {
830
850
  if (!options) {
831
851
  options = {};
832
852
  }
833
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Touch, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
853
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
854
+ ? null
855
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Touch, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
834
856
  try {
835
857
  const cppDocId = this._cppDocId(key);
836
858
  const timeout = options.timeout || this.cluster.kvTimeout;
837
- obsReqHandler.setRequestKeyValueAttributes(cppDocId);
859
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId);
838
860
  return utilities_1.PromiseHelper.wrapAsync(async () => {
839
861
  const [err, resp] = await (0, observability_1.wrapObservableBindingCall)(this._conn.touch.bind(this._conn), {
840
862
  id: cppDocId,
@@ -844,17 +866,17 @@ class Collection {
844
866
  opaque: 0,
845
867
  }, obsReqHandler);
846
868
  if (err) {
847
- obsReqHandler.endWithError(err);
869
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
848
870
  throw err;
849
871
  }
850
- obsReqHandler.end();
872
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
851
873
  return new crudoptypes_1.MutationResult({
852
874
  cas: resp.cas,
853
875
  });
854
876
  }, callback);
855
877
  }
856
878
  catch (e) {
857
- obsReqHandler.endWithError(e);
879
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
858
880
  throw e;
859
881
  }
860
882
  }
@@ -874,12 +896,14 @@ class Collection {
874
896
  if (!options) {
875
897
  options = {};
876
898
  }
877
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.GetAndLock, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
899
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
900
+ ? null
901
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.GetAndLock, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
878
902
  try {
879
903
  const cppDocId = this._cppDocId(key);
880
904
  const transcoder = options.transcoder || this.transcoder;
881
905
  const timeout = options.timeout || this.cluster.kvTimeout;
882
- obsReqHandler.setRequestKeyValueAttributes(cppDocId);
906
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId);
883
907
  return utilities_1.PromiseHelper.wrapAsync(async () => {
884
908
  const [err, resp] = await (0, observability_1.wrapObservableBindingCall)(this._conn.getAndLock.bind(this._conn), {
885
909
  id: cppDocId,
@@ -889,19 +913,18 @@ class Collection {
889
913
  opaque: 0,
890
914
  }, obsReqHandler);
891
915
  if (err) {
892
- obsReqHandler.endWithError(err);
916
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
893
917
  throw err;
894
918
  }
895
- const content = transcoder.decode(resp.value, resp.flags);
896
- obsReqHandler.end();
897
- return new crudoptypes_1.GetResult({
898
- content: content,
919
+ const toResult = () => new crudoptypes_1.GetResult({
920
+ content: transcoder.decode(resp.value, resp.flags),
899
921
  cas: resp.cas,
900
922
  });
923
+ return obsReqHandler ? obsReqHandler.endAfter(toResult) : toResult();
901
924
  }, callback);
902
925
  }
903
926
  catch (e) {
904
- obsReqHandler.endWithError(e);
927
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
905
928
  throw e;
906
929
  }
907
930
  }
@@ -921,11 +944,13 @@ class Collection {
921
944
  if (!options) {
922
945
  options = {};
923
946
  }
924
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Unlock, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
947
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
948
+ ? null
949
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Unlock, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
925
950
  try {
926
951
  const cppDocId = this._cppDocId(key);
927
952
  const timeout = options.timeout || this.cluster.kvTimeout;
928
- obsReqHandler.setRequestKeyValueAttributes(cppDocId);
953
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId);
929
954
  return utilities_1.PromiseHelper.wrapAsync(async () => {
930
955
  const [err, _] = await (0, observability_1.wrapObservableBindingCall)(this._conn.unlock.bind(this._conn), {
931
956
  id: cppDocId,
@@ -935,14 +960,14 @@ class Collection {
935
960
  opaque: 0,
936
961
  }, obsReqHandler);
937
962
  if (err) {
938
- obsReqHandler.endWithError(err);
963
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
939
964
  throw err;
940
965
  }
941
- obsReqHandler.end();
966
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
942
967
  }, callback);
943
968
  }
944
969
  catch (e) {
945
- obsReqHandler.endWithError(e);
970
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
946
971
  throw e;
947
972
  }
948
973
  }
@@ -1022,7 +1047,7 @@ class Collection {
1022
1047
  */
1023
1048
  scan(scanType, options, callback) {
1024
1049
  if (options instanceof Function) {
1025
- callback = arguments[2];
1050
+ callback = arguments[1];
1026
1051
  options = undefined;
1027
1052
  }
1028
1053
  if (!options) {
@@ -1031,8 +1056,12 @@ class Collection {
1031
1056
  const transcoder = options.transcoder || this.transcoder;
1032
1057
  const timeout = options.timeout || this._kvScanTimeout;
1033
1058
  const idsOnly = options.idsOnly || false;
1034
- const batchByteLimit = options.batchByteLimit || this._scanBatchByteLimit;
1035
- const batchItemLimit = options.batchByteLimit || this._scanBatchItemLimit;
1059
+ const batchByteLimit = typeof options.batchByteLimit !== 'undefined'
1060
+ ? options.batchByteLimit
1061
+ : this._scanBatchByteLimit;
1062
+ const batchItemLimit = typeof options.batchItemLimit !== 'undefined'
1063
+ ? options.batchItemLimit
1064
+ : this._scanBatchItemLimit;
1036
1065
  if (typeof options.concurrency !== 'undefined' && options.concurrency < 1) {
1037
1066
  throw new errors_1.InvalidArgumentError(new Error('Concurrency option must be positive'));
1038
1067
  }
@@ -1067,7 +1096,9 @@ class Collection {
1067
1096
  if (!options) {
1068
1097
  options = {};
1069
1098
  }
1070
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.LookupIn, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1099
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
1100
+ ? null
1101
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.LookupIn, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1071
1102
  try {
1072
1103
  if (specs.length === 0) {
1073
1104
  throw new errors_1.InvalidArgumentError(new Error('At least one lookup spec must be provided.'));
@@ -1084,7 +1115,7 @@ class Collection {
1084
1115
  }
1085
1116
  const timeout = options.timeout || this.cluster.kvTimeout;
1086
1117
  const accessDeleted = options.accessDeleted || false;
1087
- obsReqHandler.setRequestKeyValueAttributes(cppDocId);
1118
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId);
1088
1119
  return utilities_1.PromiseHelper.wrapAsync(async () => {
1089
1120
  const [err, resp] = await (0, observability_1.wrapObservableBindingCall)(this._conn.lookupIn.bind(this._conn), {
1090
1121
  id: cppDocId,
@@ -1095,7 +1126,7 @@ class Collection {
1095
1126
  access_deleted: accessDeleted,
1096
1127
  }, obsReqHandler);
1097
1128
  if (err) {
1098
- obsReqHandler.endWithError(err);
1129
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
1099
1130
  throw err;
1100
1131
  }
1101
1132
  const content = [];
@@ -1114,7 +1145,7 @@ class Collection {
1114
1145
  value,
1115
1146
  }));
1116
1147
  }
1117
- obsReqHandler.end();
1148
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
1118
1149
  return new crudoptypes_1.LookupInResult({
1119
1150
  content: content,
1120
1151
  cas: resp.cas,
@@ -1122,19 +1153,19 @@ class Collection {
1122
1153
  }, callback);
1123
1154
  }
1124
1155
  catch (e) {
1125
- obsReqHandler.endWithError(e);
1156
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
1126
1157
  throw e;
1127
1158
  }
1128
1159
  }
1129
1160
  /**
1130
1161
  * @internal
1131
1162
  */
1132
- _lookupInReplica(key, obsReqHandler, specs, options, callback) {
1163
+ _lookupInReplica(key, opType, obsReqHandler, specs, options, callback) {
1133
1164
  if (specs.length === 0) {
1134
1165
  throw new errors_1.InvalidArgumentError(new Error('At least one lookup spec must be provided.'));
1135
1166
  }
1136
1167
  const cppDocId = this._cppDocId(key);
1137
- obsReqHandler.setRequestKeyValueAttributes(cppDocId);
1168
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId);
1138
1169
  const emitter = new streamablepromises_1.StreamableReplicasPromise((replicas) => replicas);
1139
1170
  const cppSpecs = [];
1140
1171
  for (let i = 0; i < specs.length; ++i) {
@@ -1146,7 +1177,7 @@ class Collection {
1146
1177
  });
1147
1178
  }
1148
1179
  const timeout = options.timeout || this.cluster.kvTimeout;
1149
- if (obsReqHandler.opType == observabilitytypes_1.KeyValueOp.LookupInAllReplicas) {
1180
+ if (opType == observabilitytypes_1.KeyValueOp.LookupInAllReplicas) {
1150
1181
  utilities_1.PromiseHelper.wrapAsync(async () => {
1151
1182
  const [err, resp] = await (0, observability_1.wrapObservableBindingCall)(this._conn.lookupInAllReplicas.bind(this._conn), {
1152
1183
  id: cppDocId,
@@ -1156,7 +1187,7 @@ class Collection {
1156
1187
  access_deleted: false, // only used in core transactions; false otherwise
1157
1188
  }, obsReqHandler);
1158
1189
  if (err) {
1159
- obsReqHandler.endWithError(err);
1190
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
1160
1191
  emitter.emit('error', err);
1161
1192
  emitter.emit('end');
1162
1193
  return;
@@ -1184,7 +1215,7 @@ class Collection {
1184
1215
  isReplica: replica.is_replica,
1185
1216
  }));
1186
1217
  });
1187
- obsReqHandler.end();
1218
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
1188
1219
  emitter.emit('end');
1189
1220
  });
1190
1221
  }
@@ -1198,7 +1229,7 @@ class Collection {
1198
1229
  access_deleted: false, // only used in core transactions; false otherwise
1199
1230
  }, obsReqHandler);
1200
1231
  if (err) {
1201
- obsReqHandler.endWithError(err);
1232
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
1202
1233
  emitter.emit('error', err);
1203
1234
  emitter.emit('end');
1204
1235
  return;
@@ -1224,7 +1255,7 @@ class Collection {
1224
1255
  cas: resp.cas,
1225
1256
  isReplica: resp.is_replica,
1226
1257
  }));
1227
- obsReqHandler.end();
1258
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
1228
1259
  emitter.emit('end');
1229
1260
  });
1230
1261
  }
@@ -1248,15 +1279,17 @@ class Collection {
1248
1279
  if (!options) {
1249
1280
  options = {};
1250
1281
  }
1251
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.LookupInAnyReplica, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1282
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
1283
+ ? null
1284
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.LookupInAnyReplica, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1252
1285
  try {
1253
1286
  return utilities_1.PromiseHelper.wrapAsync(async () => {
1254
- const replicas = await this._lookupInReplica(key, obsReqHandler, specs, options);
1287
+ const replicas = await this._lookupInReplica(key, observabilitytypes_1.KeyValueOp.LookupInAnyReplica, obsReqHandler, specs, options);
1255
1288
  return replicas[0];
1256
1289
  }, callback);
1257
1290
  }
1258
1291
  catch (e) {
1259
- obsReqHandler.endWithError(e);
1292
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
1260
1293
  throw e;
1261
1294
  }
1262
1295
  }
@@ -1278,12 +1311,14 @@ class Collection {
1278
1311
  if (!options) {
1279
1312
  options = {};
1280
1313
  }
1281
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.LookupInAllReplicas, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1314
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
1315
+ ? null
1316
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.LookupInAllReplicas, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1282
1317
  try {
1283
- return this._lookupInReplica(key, obsReqHandler, specs, options, callback);
1318
+ return this._lookupInReplica(key, observabilitytypes_1.KeyValueOp.LookupInAllReplicas, obsReqHandler, specs, options, callback);
1284
1319
  }
1285
1320
  catch (e) {
1286
- obsReqHandler.endWithError(e);
1321
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
1287
1322
  throw e;
1288
1323
  }
1289
1324
  }
@@ -1297,6 +1332,7 @@ class Collection {
1297
1332
  * @param callback A node-style callback to be invoked after execution.
1298
1333
  */
1299
1334
  mutateIn(key, specs, options, callback) {
1335
+ var _a;
1300
1336
  if (options instanceof Function) {
1301
1337
  callback = arguments[2];
1302
1338
  options = undefined;
@@ -1304,7 +1340,9 @@ class Collection {
1304
1340
  if (!options) {
1305
1341
  options = {};
1306
1342
  }
1307
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.MutateIn, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1343
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
1344
+ ? null
1345
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.MutateIn, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1308
1346
  try {
1309
1347
  if (specs.length === 0) {
1310
1348
  throw new errors_1.InvalidArgumentError(new Error('At least one lookup spec must be provided.'));
@@ -1315,10 +1353,10 @@ class Collection {
1315
1353
  for (let i = 0; i < specs.length; ++i) {
1316
1354
  let value = undefined;
1317
1355
  if (specs[i]._data) {
1318
- const [bytesValue, _] = obsReqHandler.maybeAddEncodingSpan(() => {
1356
+ const [bytesValue] = (_a = obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.maybeAddEncodingSpan(() => {
1319
1357
  const encoded = this._subdocEncode(specs[i]._data);
1320
- return [encoded, 0]; // Flags are not needed for subdoc mutations
1321
- });
1358
+ return [encoded, 0];
1359
+ })) !== null && _a !== void 0 ? _a : [this._subdocEncode(specs[i]._data), 0];
1322
1360
  value = bytesValue;
1323
1361
  }
1324
1362
  cppSpecs.push({
@@ -1338,7 +1376,7 @@ class Collection {
1338
1376
  const persistTo = options.durabilityPersistTo;
1339
1377
  const replicateTo = options.durabilityReplicateTo;
1340
1378
  const timeout = options.timeout || this._mutationTimeout(options.durabilityLevel);
1341
- obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
1379
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
1342
1380
  const mutateInReq = {
1343
1381
  id: cppDocId,
1344
1382
  store_semantics: (0, bindingutilities_1.storeSemanticToCpp)(storeSemantics),
@@ -1371,7 +1409,7 @@ class Collection {
1371
1409
  }, obsReqHandler);
1372
1410
  }
1373
1411
  if (err) {
1374
- obsReqHandler.endWithError(err);
1412
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
1375
1413
  throw err;
1376
1414
  }
1377
1415
  const content = [];
@@ -1385,7 +1423,7 @@ class Collection {
1385
1423
  value,
1386
1424
  }));
1387
1425
  }
1388
- obsReqHandler.end();
1426
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
1389
1427
  return new crudoptypes_1.MutateInResult({
1390
1428
  content: content,
1391
1429
  cas: resp.cas,
@@ -1394,7 +1432,7 @@ class Collection {
1394
1432
  }, callback);
1395
1433
  }
1396
1434
  catch (e) {
1397
- obsReqHandler.endWithError(e);
1435
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
1398
1436
  throw e;
1399
1437
  }
1400
1438
  }
@@ -1448,7 +1486,9 @@ class Collection {
1448
1486
  if (!options) {
1449
1487
  options = {};
1450
1488
  }
1451
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Increment, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1489
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
1490
+ ? null
1491
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Increment, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1452
1492
  try {
1453
1493
  const cppDocId = this._cppDocId(key);
1454
1494
  const cppDurability = (0, bindingutilities_1.durabilityToCpp)(options.durabilityLevel);
@@ -1456,8 +1496,8 @@ class Collection {
1456
1496
  const expiry = (0, utilities_1.parseExpiry)(options.expiry);
1457
1497
  const persistTo = options.durabilityPersistTo;
1458
1498
  const replicateTo = options.durabilityReplicateTo;
1459
- const timeout = options.timeout || this.cluster.kvTimeout;
1460
- obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
1499
+ const timeout = options.timeout || this._mutationTimeout(options.durabilityLevel);
1500
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
1461
1501
  const incrementReq = {
1462
1502
  id: cppDocId,
1463
1503
  delta,
@@ -1486,10 +1526,10 @@ class Collection {
1486
1526
  }, obsReqHandler);
1487
1527
  }
1488
1528
  if (err) {
1489
- obsReqHandler.endWithError(err);
1529
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
1490
1530
  throw err;
1491
1531
  }
1492
- obsReqHandler.end();
1532
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
1493
1533
  return new crudoptypes_1.CounterResult({
1494
1534
  cas: resp.cas,
1495
1535
  token: resp.token,
@@ -1498,7 +1538,7 @@ class Collection {
1498
1538
  }, callback);
1499
1539
  }
1500
1540
  catch (e) {
1501
- obsReqHandler.endWithError(e);
1541
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
1502
1542
  throw e;
1503
1543
  }
1504
1544
  }
@@ -1513,7 +1553,9 @@ class Collection {
1513
1553
  if (!options) {
1514
1554
  options = {};
1515
1555
  }
1516
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Decrement, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1556
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
1557
+ ? null
1558
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Decrement, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1517
1559
  try {
1518
1560
  const cppDocId = this._cppDocId(key);
1519
1561
  const cppDurability = (0, bindingutilities_1.durabilityToCpp)(options.durabilityLevel);
@@ -1521,8 +1563,8 @@ class Collection {
1521
1563
  const expiry = (0, utilities_1.parseExpiry)(options.expiry);
1522
1564
  const persistTo = options.durabilityPersistTo;
1523
1565
  const replicateTo = options.durabilityReplicateTo;
1524
- const timeout = options.timeout || this.cluster.kvTimeout;
1525
- obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
1566
+ const timeout = options.timeout || this._mutationTimeout(options.durabilityLevel);
1567
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
1526
1568
  const decrementReq = {
1527
1569
  id: cppDocId,
1528
1570
  delta,
@@ -1551,10 +1593,10 @@ class Collection {
1551
1593
  }, obsReqHandler);
1552
1594
  }
1553
1595
  if (err) {
1554
- obsReqHandler.endWithError(err);
1596
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
1555
1597
  throw err;
1556
1598
  }
1557
- obsReqHandler.end();
1599
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
1558
1600
  return new crudoptypes_1.CounterResult({
1559
1601
  cas: resp.cas,
1560
1602
  token: resp.token,
@@ -1563,7 +1605,7 @@ class Collection {
1563
1605
  }, callback);
1564
1606
  }
1565
1607
  catch (e) {
1566
- obsReqHandler.endWithError(e);
1608
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
1567
1609
  throw e;
1568
1610
  }
1569
1611
  }
@@ -1578,15 +1620,17 @@ class Collection {
1578
1620
  if (!options) {
1579
1621
  options = {};
1580
1622
  }
1581
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Append, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1623
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
1624
+ ? null
1625
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Append, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1582
1626
  try {
1583
1627
  const cppDocId = this._cppDocId(key);
1584
1628
  const cppDurability = (0, bindingutilities_1.durabilityToCpp)(options.durabilityLevel);
1585
1629
  const persistTo = options.durabilityPersistTo;
1586
1630
  const replicateTo = options.durabilityReplicateTo;
1587
1631
  const cas = options.cas;
1588
- const timeout = options.timeout || this.cluster.kvTimeout;
1589
- obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
1632
+ const timeout = options.timeout || this._mutationTimeout(options.durabilityLevel);
1633
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
1590
1634
  if (!Buffer.isBuffer(value)) {
1591
1635
  value = Buffer.from(value);
1592
1636
  }
@@ -1617,10 +1661,10 @@ class Collection {
1617
1661
  }, obsReqHandler);
1618
1662
  }
1619
1663
  if (err) {
1620
- obsReqHandler.endWithError(err);
1664
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
1621
1665
  throw err;
1622
1666
  }
1623
- obsReqHandler.end();
1667
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
1624
1668
  return new crudoptypes_1.MutationResult({
1625
1669
  cas: resp.cas,
1626
1670
  token: resp.token,
@@ -1628,7 +1672,7 @@ class Collection {
1628
1672
  }, callback);
1629
1673
  }
1630
1674
  catch (e) {
1631
- obsReqHandler.endWithError(e);
1675
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
1632
1676
  throw e;
1633
1677
  }
1634
1678
  }
@@ -1643,15 +1687,17 @@ class Collection {
1643
1687
  if (!options) {
1644
1688
  options = {};
1645
1689
  }
1646
- const obsReqHandler = new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Prepend, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1690
+ const obsReqHandler = (0, observabilityhandler_1.isNoopObservabilityInstruments)(this.observabilityInstruments)
1691
+ ? null
1692
+ : new observabilityhandler_1.ObservableRequestHandler(observabilitytypes_1.KeyValueOp.Prepend, this.observabilityInstruments, options === null || options === void 0 ? void 0 : options.parentSpan);
1647
1693
  try {
1648
1694
  const cppDocId = this._cppDocId(key);
1649
1695
  const cppDurability = (0, bindingutilities_1.durabilityToCpp)(options.durabilityLevel);
1650
1696
  const persistTo = options.durabilityPersistTo;
1651
1697
  const replicateTo = options.durabilityReplicateTo;
1652
1698
  const cas = options.cas;
1653
- const timeout = options.timeout || this.cluster.kvTimeout;
1654
- obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
1699
+ const timeout = options.timeout || this._mutationTimeout(options.durabilityLevel);
1700
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.setRequestKeyValueAttributes(cppDocId, cppDurability);
1655
1701
  if (!Buffer.isBuffer(value)) {
1656
1702
  value = Buffer.from(value);
1657
1703
  }
@@ -1682,10 +1728,10 @@ class Collection {
1682
1728
  }, obsReqHandler);
1683
1729
  }
1684
1730
  if (err) {
1685
- obsReqHandler.endWithError(err);
1731
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(err);
1686
1732
  throw err;
1687
1733
  }
1688
- obsReqHandler.end();
1734
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.end();
1689
1735
  return new crudoptypes_1.MutationResult({
1690
1736
  cas: resp.cas,
1691
1737
  token: resp.token,
@@ -1693,7 +1739,7 @@ class Collection {
1693
1739
  }, callback);
1694
1740
  }
1695
1741
  catch (e) {
1696
- obsReqHandler.endWithError(e);
1742
+ obsReqHandler === null || obsReqHandler === void 0 ? void 0 : obsReqHandler.endWithError(e);
1697
1743
  throw e;
1698
1744
  }
1699
1745
  }