@@ -1082,57 +1082,34 @@ export function hasAtomicOperators(doc: Document | Document[]): boolean {
1082
1082
return keys . length > 0 && keys [ 0 ] [ 0 ] === '$' ;
1083
1083
}
1084
1084
1085
- function resolveWriteConcern (
1086
- parent : OperationParent | undefined ,
1087
- options : any
1088
- ) : WriteConcern | undefined {
1089
- const session = options . session ;
1090
- if ( session && session . inTransaction ( ) ) {
1091
- // Users cannot pass a writeConcern to operations in a transaction
1092
- return ;
1093
- }
1094
- return WriteConcern . fromOptions ( options ) || parent ?. writeConcern ;
1095
- }
1096
-
1097
- function resolveReadConcern (
1098
- parent : OperationParent | undefined ,
1099
- options : any
1100
- ) : ReadConcern | undefined {
1101
- const session = options . session ;
1102
- if ( session && session . inTransaction ( ) ) {
1103
- // Users cannot pass a readConcern to operations in a transaction
1104
- return ;
1105
- }
1106
- return ReadConcern . fromOptions ( options ) || parent ?. readConcern ;
1107
- }
1108
-
1109
- function resolveReadPreference (
1110
- parent : OperationParent | undefined ,
1111
- options : any
1112
- ) : ReadPreference | undefined {
1113
- return ReadPreference . fromOptions ( options ) ?? parent ?. readPreference ;
1114
- }
1115
-
1116
- /** @internal Prioritizes options from transaction, then from options, then from parent */
1085
+ /**
1086
+ * Merge inherited properties from parent into options, prioritizing values from options,
1087
+ * then values from parent.
1088
+ * @internal
1089
+ */
1117
1090
export function resolveInheritedOptions < T extends CommandOperationOptions > (
1118
1091
parent : OperationParent | undefined ,
1119
1092
options ?: T
1120
1093
) : T {
1121
1094
const result : T = Object . assign ( { } , options ) ;
1095
+ const session = options ?. session ;
1122
1096
1123
- const readPreference = resolveReadPreference ( parent , result ) ;
1124
- if ( readPreference ) {
1125
- result . readPreference = readPreference ;
1126
- }
1097
+ // Users cannot pass a readConcern/writeConcern to operations in a transaction
1098
+ if ( ! session ?. inTransaction ( ) ) {
1099
+ const readConcern = ReadConcern . fromOptions ( options ) ?? parent ?. readConcern ;
1100
+ if ( readConcern ) {
1101
+ result . readConcern = readConcern ;
1102
+ }
1127
1103
1128
- const readConcern = resolveReadConcern ( parent , result ) ;
1129
- if ( readConcern ) {
1130
- result . readConcern = readConcern ;
1104
+ const writeConcern = WriteConcern . fromOptions ( options ) ?? parent ?. writeConcern ;
1105
+ if ( writeConcern ) {
1106
+ result . writeConcern = writeConcern ;
1107
+ }
1131
1108
}
1132
1109
1133
- const writeConcern = resolveWriteConcern ( parent , result ) ;
1134
- if ( writeConcern ) {
1135
- result . writeConcern = writeConcern ;
1110
+ const readPreference = ReadPreference . fromOptions ( options ) ?? parent ?. readPreference ;
1111
+ if ( readPreference ) {
1112
+ result . readPreference = readPreference ;
1136
1113
}
1137
1114
1138
1115
const bsonOptions = resolveBSONOptions ( result , parent ) ;
0 commit comments