import { IncrementOptions , DecrementOptions , AppendOptions , PrependOptions , BinaryCollection , } from './binarycollection' ; import binding , { CppReplicaMode , CppSdOpFlag } from './binding' ; import { CppStoreOpType } from './binding' ; import { duraLevelToCppDuraMode , translateCppError } from './bindingutilities' ; import { Connection } from './connection' ; import { CounterResult , ExistsResult , GetReplicaResult , GetResult , LookupInResult , MutateInResult , MutationResult , } from './crudoptypes' ; import { CouchbaseList , CouchbaseMap , CouchbaseQueue , CouchbaseSet , } from './datastructures' ; import { PathNotFoundError } from './errors' ; import { DurabilityLevel , StoreSemantics } from './generaltypes' ; import { Scope } from './scope' ; import { LookupInMacro , LookupInSpec , MutateInSpec } from './sdspecs' ; import { SdUtils } from './sdutils' ; import { StreamableReplicasPromise } from './streamablepromises' ; import { RequestSpan } from './tracing' ; import { Transcoder } from './transcoders' ; import { NodeCallback , PromiseHelper , Cas } from './utilities' ; category export interface GetOptions { /**
     * Specifies a list of fields within the document which should be fetched.
     * This allows for easy retrieval of select fields without incurring the
     * overhead of fetching the whole document.
     */ project ? : string [ ] ; /**
     * Indicates that the expiry of the document should be fetched alongside
     * the data itself.
     */ withExpiry ? : boolean ; /**
     * Specifies an explicit transcoder to use for this specific operation.
     */ transcoder ? : Transcoder ; /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface ExistsOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface InsertOptions { /**
     * Specifies the expiry time for this document, specified in seconds.
     */ expiry ? : number ; /**
     * Specifies the level of synchronous durability for this operation.
     */ durabilityLevel ? : DurabilityLevel ; /**
     * Specifies the number of nodes this operation should be persisted to
     * before it is considered successful.  Note that this option is mutually
     * exclusive of  durabilityLevel .
      durabilityPersistTo ? : number ; /**
     * Specifies the number of nodes this operation should be replicated to
     * before it is considered successful.  Note that this option is mutually
     * exclusive of  durabilityLevel .
      durabilityReplicateTo ? : number ; /**
     * Specifies an explicit transcoder to use for this specific operation.
     */ transcoder ? : Transcoder ; /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface UpsertOptions { /**
     * Specifies the expiry time for this document, specified in seconds.
     */ expiry ? : number ; /**
     * Specifies that any existing expiry on the document should be preserved.
     */ preserveExpiry ? : boolean ; /**
     * Specifies the level of synchronous durability for this operation.
     */ durabilityLevel ? : DurabilityLevel ; /**
     * Specifies the number of nodes this operation should be persisted to
     * before it is considered successful.  Note that this option is mutually
     * exclusive of  durabilityLevel .
      durabilityPersistTo ? : number ; /**
     * Specifies the number of nodes this operation should be replicated to
     * before it is considered successful.  Note that this option is mutually
     * exclusive of  durabilityLevel .
      durabilityReplicateTo ? : number ; /**
     * Specifies an explicit transcoder to use for this specific operation.
     */ transcoder ? : Transcoder ; /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface ReplaceOptions { /**
     * Specifies the expiry time for this document, specified in seconds.
     */ expiry ? : number ; /**
     * Specifies that any existing expiry on the document should be preserved.
     */ preserveExpiry ? : boolean ; /**
     * If specified, indicates that operation should be failed if the CAS
     * has changed from this value, indicating that the document has changed.
     */ cas ? : Cas ; /**
     * Specifies the level of synchronous durability for this operation.
     */ durabilityLevel ? : DurabilityLevel ; /**
     * Specifies the number of nodes this operation should be persisted to
     * before it is considered successful.  Note that this option is mutually
     * exclusive of  durabilityLevel .
      durabilityPersistTo ? : number ; /**
     * Specifies the number of nodes this operation should be replicated to
     * before it is considered successful.  Note that this option is mutually
     * exclusive of  durabilityLevel .
      durabilityReplicateTo ? : number ; /**
     * Specifies an explicit transcoder to use for this specific operation.
     */ transcoder ? : Transcoder ; /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface RemoveOptions { /**
     * If specified, indicates that operation should be failed if the CAS
     * has changed from this value, indicating that the document has changed.
     */ cas ? : Cas ; /**
     * Specifies the level of synchronous durability for this operation.
     */ durabilityLevel ? : DurabilityLevel ; /**
     * Specifies the number of nodes this operation should be persisted to
     * before it is considered successful.  Note that this option is mutually
     * exclusive of  durabilityLevel .
      durabilityPersistTo ? : number ; /**
     * Specifies the number of nodes this operation should be replicated to
     * before it is considered successful.  Note that this option is mutually
     * exclusive of  durabilityLevel .
      durabilityReplicateTo ? : number ; /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface GetAnyReplicaOptions { /**
     * Specifies an explicit transcoder to use for this specific operation.
     */ transcoder ? : Transcoder ; /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface GetAllReplicasOptions { /**
     * Specifies an explicit transcoder to use for this specific operation.
     */ transcoder ? : Transcoder ; /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface TouchOptions { /**
     * Specifies the level of synchronous durability for this operation.
     */ durabilityLevel ? : DurabilityLevel ; /**
     * Specifies the number of nodes this operation should be persisted to
     * before it is considered successful.  Note that this option is mutually
     * exclusive of  durabilityLevel .
      durabilityPersistTo ? : number ; /**
     * Specifies the number of nodes this operation should be replicated to
     * before it is considered successful.  Note that this option is mutually
     * exclusive of  durabilityLevel .
      durabilityReplicateTo ? : number ; /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface GetAndTouchOptions { /**
     * Specifies an explicit transcoder to use for this specific operation.
     */ transcoder ? : Transcoder ; /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface GetAndLockOptions { /**
     * Specifies an explicit transcoder to use for this specific operation.
     */ transcoder ? : Transcoder ; /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface UnlockOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface LookupInOptions { /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; } category export interface MutateInOptions { /**
     * Specifies the expiry time for this document, specified in seconds.
     */ expiry ? : number ; /**
     * Specifies that any existing expiry on the document should be preserved.
     */ preserveExpiry ? : boolean ; /**
     * If specified, indicates that operation should be failed if the CAS
     * has changed from this value, indicating that the document has changed.
     */ cas ? : Cas ; /**
     * Specifies the level of synchronous durability for this operation.
     */ durabilityLevel ? : DurabilityLevel ; /**
     * Specifies the number of nodes this operation should be persisted to
     * before it is considered successful.  Note that this option is mutually
     * exclusive of  durabilityLevel .
      durabilityPersistTo ? : number ; /**
     * Specifies the number of nodes this operation should be replicated to
     * before it is considered successful.  Note that this option is mutually
     * exclusive of  durabilityLevel .
      durabilityReplicateTo ? : number ; /**
     * Specifies the store semantics to use for this operation.
     */ storeSemantics ? : StoreSemantics ; /**
     * The parent tracing span that this operation will be part of.
     */ parentSpan ? : RequestSpan ; /**
     * The timeout for this operation, represented in milliseconds.
     */ timeout ? : number ; deprecated Use  MutateInOptions . storeSemantics instead.
      upsertDocument ? : boolean ; } category export class Collection { internal static get DEFAULT_NAME ( ) : string { return '_default' ; } private _scope : Scope ; private _name : string ; private _conn : Connection ; internal constructor ( scope , collectionName ) { this . _scope = scope ; this . _name = collectionName ; this . _conn = scope . conn ; } internal get conn ( ) : Connection { return this . _conn ; } internal get scope ( ) : Scope { return this . _scope ; } internal get transcoder ( ) : Transcoder { return this . _scope . transcoder ; } /**
     * The name of the collection this Collection object references.
     */ get name ( ) : string { return this . _name ; } private get _lcbScopeColl ( ) : [ string , string ] { const scopeName = this . scope . name || '_default' ; const collectionName = this . name || '_default' ; if ( scopeName === '_default' && collectionName === '_default' ) { return [ '' , '' ] ; } return [ scopeName , collectionName ] ; } param key param options param callback get ( key , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 1 ] ; options = undefined ; } if ( ! options ) { options = { } ; } if ( options . project || options . withExpiry ) { return this . _projectedGet ( key , options , callback ) ; } const transcoder = options . transcoder || this . transcoder ; const parentSpan = options . parentSpan ; const lcbTimeout = options . timeout ? options . timeout * 1000 : undefined ; return PromiseHelper . wrap ( ( wrapCallback ) => { this . _conn . get ( ... this . _lcbScopeColl , key , transcoder , undefined , undefined , parentSpan , lcbTimeout , ( err , cas , value ) => { if ( err ) { return wrapCallback ( err , null ) ; } wrapCallback ( null , new GetResult ( { content : value , cas : cas , } ) ) ; } ) ; } , callback ) ; } private _projectedGet ( key , options , callback ? ) { let expiryStart = - 1 ; let projStart = - 1 ; let paths = [ ] ; let spec = [ ] ; let needReproject = false ; if ( options . withExpiry ) { expiryStart = spec . length ; spec . push ( LookupInSpec . get ( LookupInMacro . Expiry ) ) ; } projStart = spec . length ; if ( ! options . project ) { paths = [ '' ] ; spec . push ( LookupInSpec . get ( '' ) ) ; } else { let projects = options . project ; if ( ! Array . isArray ( projects ) ) { projects = [ projects ] ; } for ( let i = 0 ; i < projects . length ; ++ i ) { paths . push ( projects [ i ] ) ; spec . push ( LookupInSpec . get ( projects [ i ] ) ) ; } } if ( spec . length > 16 ) { spec = spec . splice ( 0 , projStart ) ; spec . push ( LookupInSpec . get ( '' ) ) ; needReproject = true ; } return PromiseHelper . wrapAsync ( async ( ) => { const res = await this . lookupIn ( key , spec , { ... options , parentSpan : options . parentSpan , } ) ; let content = null ; let expiry = undefined ; if ( expiryStart >= 0 ) { const expiryRes = res . content [ expiryStart ] ; expiry = expiryRes . value ; } if ( projStart >= 0 ) { if ( ! needReproject ) { for ( let i = 0 ; i < paths . length ; ++ i ) { const projPath = paths [ i ] ; const projRes = res . content [ projStart + i ] ; if ( ! projRes . error ) { content = SdUtils . insertByPath ( content , projPath , projRes . value ) ; } } } else { content = { } ; const reprojRes = res . content [ projStart ] ; for ( let j = 0 ; j < paths . length ; ++ j ) { const reprojPath = paths [ j ] ; const value = SdUtils . getByPath ( reprojRes . value , reprojPath ) ; content = SdUtils . insertByPath ( content , reprojPath , value ) ; } } } return new GetResult ( { content : content , cas : res . cas , expiryTime : expiry , } ) ; } , callback ) ; } param key param options param callback exists ( key , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 1 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const parentSpan = options . parentSpan ; const lcbTimeout = options . timeout ? options . timeout * 1000 : undefined ; return PromiseHelper . wrap ( ( wrapCallback ) => { this . _conn . exists ( ... this . _lcbScopeColl , key , parentSpan , lcbTimeout , ( err , cas , exists ) => { if ( err ) { return wrapCallback ( err , null ) ; } wrapCallback ( null , new ExistsResult ( { cas , exists , } ) ) ; } ) ; } , callback ) ; } param key param options param callback getAnyReplica ( key , options ? , callback ? ) { return PromiseHelper . wrapAsync ( async ( ) => { const replicas = await this . _getReplica ( binding . LCB_REPLICA_MODE_ANY , key , options ) ; return replicas [ 0 ] ; } , callback ) ; } param key param options param callback getAllReplicas ( key , options ? , callback ? ) { return this . _getReplica ( binding . LCB_REPLICA_MODE_ALL , key , options , callback ) ; } param key param value param options param callback insert ( key , value , options ? , callback ? ) { return this . _store ( binding . LCB_STORE_INSERT , key , value , options , callback ) ; } param key param value param options param callback upsert ( key , value , options ? , callback ? ) { return this . _store ( binding . LCB_STORE_UPSERT , key , value , options , callback ) ; } param key param value param options param callback replace ( key , value , options ? , callback ? ) { return this . _store ( binding . LCB_STORE_REPLACE , key , value , options , callback ) ; } param key param options param callback remove ( key , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 1 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const cas = options . cas || null ; const cppDuraMode = duraLevelToCppDuraMode ( options . durabilityLevel ) ; const persistTo = options . durabilityPersistTo ; const replicateTo = options . durabilityReplicateTo ; const parentSpan = options . parentSpan ; const lcbTimeout = options . timeout ? options . timeout * 1000 : undefined ; return PromiseHelper . wrap ( ( wrapCallback ) => { this . _conn . remove ( ... this . _lcbScopeColl , key , cas , cppDuraMode , persistTo , replicateTo , parentSpan , lcbTimeout , ( err , cas ) => { if ( err ) { return wrapCallback ( err , null ) ; } wrapCallback ( err , new MutationResult ( { cas : cas , } ) ) ; } ) ; } , callback ) ; } param key param expiry param options param callback getAndTouch ( key , expiry , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 2 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const transcoder = options . transcoder || this . transcoder ; const parentSpan = options . parentSpan ; const lcbTimeout = options . timeout ? options . timeout * 1000 : undefined ; return PromiseHelper . wrap ( ( wrapCallback ) => { this . _conn . get ( ... this . _lcbScopeColl , key , transcoder , expiry , undefined , parentSpan , lcbTimeout , ( err , cas , value ) => { if ( err ) { return wrapCallback ( err , null ) ; } wrapCallback ( err , new GetResult ( { content : value , cas : cas , } ) ) ; } ) ; } , callback ) ; } param key param expiry param options param callback touch ( key , expiry , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 2 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const cppDuraMode = duraLevelToCppDuraMode ( options . durabilityLevel ) ; const persistTo = options . durabilityPersistTo ; const replicateTo = options . durabilityReplicateTo ; const parentSpan = options . parentSpan ; const lcbTimeout = options . timeout ? options . timeout * 1000 : undefined ; return PromiseHelper . wrap ( ( wrapCallback ) => { this . _conn . touch ( ... this . _lcbScopeColl , key , expiry , cppDuraMode , persistTo , replicateTo , parentSpan , lcbTimeout , ( err , cas ) => { if ( err ) { return wrapCallback ( err , null ) ; } wrapCallback ( err , new MutationResult ( { cas : cas , } ) ) ; } ) ; } , callback ) ; } param key param lockTime param options param callback getAndLock ( key , lockTime , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 2 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const transcoder = options . transcoder || this . transcoder ; const parentSpan = options . parentSpan ; const lcbTimeout = options . timeout ? options . timeout * 1000 : undefined ; return PromiseHelper . wrap ( ( wrapCallback ) => { this . _conn . get ( ... this . _lcbScopeColl , key , transcoder , undefined , lockTime , parentSpan , lcbTimeout , ( err , cas , value ) => { if ( err ) { return wrapCallback ( err , null ) ; } wrapCallback ( err , new GetResult ( { cas : cas , content : value , } ) ) ; } ) ; } , callback ) ; } param key param cas param options param callback unlock ( key , cas , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 2 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const parentSpan = options . parentSpan ; const lcbTimeout = options . timeout ? options . timeout * 1000 : undefined ; return PromiseHelper . wrap ( ( wrapCallback ) => { this . _conn . unlock ( ... this . _lcbScopeColl , key , cas , parentSpan , lcbTimeout , ( err ) => { if ( err ) { return wrapCallback ( err ) ; } wrapCallback ( null ) ; } ) ; } , callback ) ; } param key param specs param options param callback lookupIn ( key , specs , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 2 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const flags = 0 ; let cmdData = [ ] ; for ( let i = 0 ; i < specs . length ; ++ i ) { cmdData = [ ... cmdData , specs [ i ] . _op , specs [ i ] . _flags , specs [ i ] . _path ] ; } const parentSpan = options . parentSpan ; const lcbTimeout = options . timeout ? options . timeout * 1000 : undefined ; return PromiseHelper . wrap ( ( wrapCallback ) => { this . _conn . lookupIn ( ... this . _lcbScopeColl , key , flags , cmdData , parentSpan , lcbTimeout , ( err , res ) => { if ( res && res . content ) { for ( let i = 0 ; i < res . content . length ; ++ i ) { const itemRes = res . content [ i ] ; itemRes . error = translateCppError ( itemRes . error ) ; if ( itemRes . value && itemRes . value . length > 0 ) { itemRes . value = JSON . parse ( itemRes . value ) ; } else { itemRes . value = null ; } if ( specs [ i ] . _op === binding . LCBX_SDCMD_EXISTS ) { if ( ! itemRes . error ) { itemRes . value = true ; } else if ( itemRes . error instanceof PathNotFoundError ) { itemRes . error = null ; itemRes . value = false ; } } } wrapCallback ( err , new LookupInResult ( { content : res . content , cas : res . cas , } ) ) ; return ; } wrapCallback ( err , null ) ; } ) ; } , callback ) ; } param key param specs param options param callback mutateIn ( key , specs , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 2 ] ; options = undefined ; } if ( ! options ) { options = { } ; } let flags = 0 ; if ( options . storeSemantics === StoreSemantics . Upsert ) { flags |= binding . LCBX_SDFLAG_UPSERT_DOC ; } else if ( options . storeSemantics === StoreSemantics . Replace ) { } else if ( options . storeSemantics === StoreSemantics . Insert ) { flags |= binding . LCBX_SDFLAG_INSERT_DOC ; } else if ( options . upsertDocument ) { flags |= binding . LCBX_SDFLAG_UPSERT_DOC ; } let cmdData = [ ] ; for ( let i = 0 ; i < specs . length ; ++ i ) { cmdData = [ ... cmdData , specs [ i ] . _op , specs [ i ] . _flags , specs [ i ] . _path , specs [ i ] . _data , ] ; } const expiry = options . preserveExpiry ? - 1 : options . expiry ; const cas = options . cas ; const cppDuraMode = duraLevelToCppDuraMode ( options . durabilityLevel ) ; const persistTo = options . durabilityPersistTo ; const replicateTo = options . durabilityReplicateTo ; const parentSpan = options . parentSpan ; const lcbTimeout = options . timeout ? options . timeout * 1000 : undefined ; return PromiseHelper . wrap ( ( wrapCallback ) => { this . _conn . mutateIn ( ... this . _lcbScopeColl , key , expiry , cas , flags , cmdData , cppDuraMode , persistTo , replicateTo , parentSpan , lcbTimeout , ( err , res ) => { if ( res && res . content ) { for ( let i = 0 ; i < res . content . length ; ++ i ) { const itemRes = res . content [ i ] ; if ( itemRes . value && itemRes . value . length > 0 ) { res . content [ i ] = { value : JSON . parse ( itemRes . value ) , } ; } else { res . content [ i ] = null ; } } wrapCallback ( err , new MutateInResult ( { content : res . content , cas : res . cas , } ) ) ; return ; } wrapCallback ( err , null ) ; } ) ; } , callback ) ; } param key list ( key ) { return new CouchbaseList ( this , key ) ; } param key queue ( key ) { return new CouchbaseQueue ( this , key ) ; } param key map ( key ) { return new CouchbaseMap ( this , key ) ; } param key set ( key ) { return new CouchbaseSet ( this , key ) ; } /**
     * Returns a BinaryCollection object reference, allowing access to various
     * binary operations possible against a collection.
     */ binary ( ) { return new BinaryCollection ( this ) ; } private _getReplica ( mode , key , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 2 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const emitter = new StreamableReplicasPromise < GetReplicaResult [ ] , GetReplicaResult > ( ( replicas ) => replicas ) ; const transcoder = options . transcoder || this . transcoder ; const lcbTimeout = options . timeout ? options . timeout * 1000 : undefined ; this . _conn . getReplica ( ... this . _lcbScopeColl , key , transcoder , mode , options . parentSpan , lcbTimeout , ( err , rflags , cas , value ) => { if ( ! err ) { emitter . emit ( 'replica' , new GetReplicaResult ( { content : value , cas : cas , isReplica : true , } ) ) ; } if ( ! ( rflags & binding . LCBX_RESP_F_NONFINAL ) ) { emitter . emit ( 'end' ) ; } } ) ; return PromiseHelper . wrapAsync ( ( ) => emitter , callback ) ; } private _store ( opType , key , value , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 3 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const expiry = options . preserveExpiry ? - 1 : options . expiry ; const cas = options . cas ; const cppDuraMode = duraLevelToCppDuraMode ( options . durabilityLevel ) ; const persistTo = options . durabilityPersistTo ; const replicateTo = options . durabilityReplicateTo ; const transcoder = options . transcoder || this . transcoder ; const parentSpan = options . parentSpan ; const lcbTimeout = options . timeout ? options . timeout * 1000 : undefined ; return PromiseHelper . wrap ( ( wrapCallback ) => { this . _conn . store ( ... this . _lcbScopeColl , key , transcoder , value , expiry , cas , cppDuraMode , persistTo , replicateTo , parentSpan , lcbTimeout , opType , ( err , cas , token ) => { if ( err ) { return wrapCallback ( err , null ) ; } wrapCallback ( err , new MutationResult ( { cas : cas , token : token , } ) ) ; } ) ; } , callback ) ; } private _counter ( key , delta , options ? , callback ? ) { if ( options instanceof Function ) { callback = arguments [ 2 ] ; options = undefined ; } if ( ! options ) { options = { } ; } const initial = options . initial ; const expiry = options . expiry ; const cppDuraMode = duraLevelToCppDuraMode ( options . durabilityLevel ) ; const persistTo = options . durabilityPersistTo ; const replicateTo = options . durabilityReplicateTo ; const parentSpan = options . parentSpan ; const lcbTimeout = options . timeout ? options . timeout * 1000 : undefined ; return PromiseHelper . wrap ( ( wrapCallback ) => { this . _conn . counter ( ... this . _lcbScopeColl , key , delta , initial , expiry , cppDuraMode , persistTo , replicateTo , parentSpan , lcbTimeout , ( err , cas , token , value ) => { if ( err ) { return wrapCallback ( err , null ) ; } wrapCallback ( err , new CounterResult ( { cas : cas , token : token , value : value , } ) ) ; } ) ; } , callback ) ; } internal _binaryIncrement ( key , delta , options ? , callback ? ) { return this . _counter ( key , + delta , options , callback ) ; } internal _binaryDecrement ( key , delta , options ? , callback ? ) { return this . _counter ( key , - delta , options , callback ) ; } internal _binaryAppend ( key , value , options ? , callback ? ) { const bufValue = Buffer . from ( value ) ; return this . _store ( binding . LCB_STORE_APPEND , key , bufValue , options , callback ) ; } internal _binaryPrepend ( key , value , options ? , callback ? ) { const bufValue = Buffer . from ( value ) ; return this . _store ( binding . LCB_STORE_PREPEND , key , bufValue , options , callback ) ; } }