Skip to content

Commit 605b0a4

Browse files
committed
JSCBC-1117: Allow callback when options not provided for all KV operations
Motivation ---------- Key-value operations should support callbacks even when options are not provided. Changes ------- Updated various key-value operations to appropriately handle when only a callback is passed in and options are omitted. Added tests to confirm functionality. Change-Id: Id64137ff7d65962cb679270f565508e87635861c Reviewed-on: https://review.couchbase.org/c/couchnode/+/185160 Tested-by: Jared Casey <jared.casey@couchbase.com> Reviewed-by: Brett Lawson <brett19@gmail.com>
1 parent cbb9330 commit 605b0a4

File tree

2 files changed

+333
-11
lines changed

2 files changed

+333
-11
lines changed

lib/collection.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,10 @@ export class Collection {
889889
options?: GetAnyReplicaOptions,
890890
callback?: NodeCallback<GetReplicaResult>
891891
): Promise<GetReplicaResult> {
892+
if (options instanceof Function) {
893+
callback = arguments[1]
894+
options = undefined
895+
}
892896
return PromiseHelper.wrapAsync(async () => {
893897
const replicas = await this._getReplica(key, false, options)
894898
return replicas[0]
@@ -926,7 +930,7 @@ export class Collection {
926930
callback?: NodeCallback<MutationResult>
927931
): Promise<MutationResult> {
928932
if (options instanceof Function) {
929-
callback = arguments[3]
933+
callback = arguments[2]
930934
options = undefined
931935
}
932936
if (!options) {
@@ -1012,7 +1016,7 @@ export class Collection {
10121016
callback?: NodeCallback<MutationResult>
10131017
): Promise<MutationResult> {
10141018
if (options instanceof Function) {
1015-
callback = arguments[3]
1019+
callback = arguments[2]
10161020
options = undefined
10171021
}
10181022
if (!options) {
@@ -1099,7 +1103,7 @@ export class Collection {
10991103
callback?: NodeCallback<MutationResult>
11001104
): Promise<MutationResult> {
11011105
if (options instanceof Function) {
1102-
callback = arguments[3]
1106+
callback = arguments[2]
11031107
options = undefined
11041108
}
11051109
if (!options) {
@@ -1884,7 +1888,7 @@ export class Collection {
18841888
callback?: NodeCallback<MutationResult>
18851889
): Promise<MutationResult> {
18861890
if (options instanceof Function) {
1887-
callback = arguments[3]
1891+
callback = arguments[2]
18881892
options = undefined
18891893
}
18901894
if (!options) {
@@ -1958,7 +1962,7 @@ export class Collection {
19581962
callback?: NodeCallback<MutationResult>
19591963
): Promise<MutationResult> {
19601964
if (options instanceof Function) {
1961-
callback = arguments[3]
1965+
callback = arguments[2]
19621966
options = undefined
19631967
}
19641968
if (!options) {

0 commit comments

Comments
 (0)