@@ -69,6 +69,7 @@ import {
6969 errorFromCpp ,
7070 mutationStateToCpp ,
7171 persistToToCpp ,
72+ readPreferenceToCpp ,
7273 replicateToToCpp ,
7374 scanTypeToCpp ,
7475 storeSemanticToCpp ,
@@ -112,7 +113,7 @@ import {
112113 DocumentUnretrievableError ,
113114 InvalidArgumentError ,
114115} from './errors.js' ;
115- import { DurabilityLevel , StoreSemantics } from './generaltypes.js' ;
116+ import { DurabilityLevel , ReadPreference , StoreSemantics } from './generaltypes.js' ;
116117import { MutationState } from './mutationstate.js' ;
117118import { CollectionQueryIndexManager } from './queryindexmanager.js' ;
118119import { PrefixScan , RangeScan , SamplingScan } from './rangeScan.js' ;
@@ -289,6 +290,11 @@ export interface GetAnyReplicaOptions<ThrowIfMissing extends boolean = boolean>
289290 * @default true
290291 */
291292 throwIfMissing ?: ThrowIfMissing ;
293+
294+ /**
295+ * Specifies how replica nodes will be filtered.
296+ */
297+ readPreference ?: ReadPreference ;
292298}
293299
294300/**
@@ -304,6 +310,11 @@ export interface GetAllReplicasOptions {
304310 * The timeout for this operation, represented in milliseconds.
305311 */
306312 timeout ?: number ;
313+
314+ /**
315+ * Specifies how replica nodes will be filtered.
316+ */
317+ readPreference ?: ReadPreference ;
307318}
308319
309320/**
@@ -402,6 +413,11 @@ export interface LookupInAnyReplicaOptions<ThrowOnSpecError extends boolean = fa
402413 * @default false
403414 */
404415 throwOnSpecError ?: ThrowOnSpecError ;
416+
417+ /**
418+ * Specifies how replica nodes will be filtered.
419+ */
420+ readPreference ?: ReadPreference ;
405421}
406422
407423/**
@@ -420,6 +436,11 @@ export interface LookupInAllReplicasOptions<ThrowOnSpecError extends boolean = f
420436 * @default false
421437 */
422438 throwOnSpecError ?: ThrowOnSpecError ;
439+
440+ /**
441+ * Specifies how replica nodes will be filtered.
442+ */
443+ readPreference ?: ReadPreference ;
423444}
424445
425446/**
@@ -857,7 +878,11 @@ export class Collection<
857878 private _getReplica (
858879 key : string ,
859880 getAllReplicas : boolean ,
860- options : { transcoder ?: Transcoder ; timeout ?: number }
881+ options : {
882+ transcoder ?: Transcoder ;
883+ timeout ?: number ;
884+ readPreference ?: ReadPreference ;
885+ }
861886 ) : StreamableReplicasPromise <
862887 [ GetReplicaResult < unknown > , ...GetReplicaResult < unknown > [ ] ] ,
863888 GetReplicaResult < unknown >
@@ -872,7 +897,11 @@ export class Collection<
872897 private _getReplica (
873898 key : string ,
874899 getAllReplicas : boolean ,
875- options ?: { transcoder ?: Transcoder ; timeout ?: number }
900+ options ?: {
901+ transcoder ?: Transcoder ;
902+ timeout ?: number ;
903+ readPreference ?: ReadPreference ;
904+ }
876905 ) : StreamableReplicasPromise <
877906 [ GetReplicaResult < unknown > , ...GetReplicaResult < unknown > [ ] ] ,
878907 GetReplicaResult < unknown >
@@ -893,6 +922,7 @@ export class Collection<
893922 const request = {
894923 id : this . getDocId ( key ) ,
895924 timeout : timeout ,
925+ read_preference : readPreferenceToCpp ( options . readPreference ) ,
896926 } ;
897927
898928 const getReplicas = getAllReplicas
@@ -2184,6 +2214,7 @@ export class Collection<
21842214 id : this . getDocId ( key ) ,
21852215 specs : cppSpecs ,
21862216 timeout : timeout ,
2217+ read_preference : readPreferenceToCpp ( options . readPreference ) ,
21872218 } ,
21882219 ( cppErr , res ) => {
21892220 if ( cppErr ) {
0 commit comments