@@ -19,10 +19,6 @@ class Connection extends EventEmitter {
19
19
constructor ( stream , options ) {
20
20
super ( options ) ;
21
21
22
- if ( typeof options . generation === 'undefined' ) {
23
- throw new TypeError ( 'connection requires a pool generation' ) ;
24
- }
25
-
26
22
this . id = options . id ;
27
23
this . address = streamIdentifier ( stream ) ;
28
24
this . bson = options . bson ;
@@ -61,7 +57,7 @@ class Connection extends EventEmitter {
61
57
}
62
58
63
59
get generation ( ) {
64
- return this [ kGeneration ] ;
60
+ return this [ kGeneration ] || 0 ;
65
61
}
66
62
67
63
get idleTime ( ) {
@@ -102,19 +98,47 @@ class Connection extends EventEmitter {
102
98
} ) ;
103
99
}
104
100
101
+ // Wire protocol methods
105
102
command ( ns , cmd , options , callback ) {
106
- // NOTE: The wire protocol methods will eventually be migrated to this class, but for now
107
- // we need to pretend we _are_ a server.
108
- const server = {
109
- description : this . description ,
110
- s : {
111
- bson : this . bson ,
112
- pool : { write : write . bind ( this ) }
113
- }
114
- } ;
103
+ wp . command ( makeServerTrampoline ( this ) , ns , cmd , options , callback ) ;
104
+ }
115
105
116
- wp . command ( server , ns , cmd , options , callback ) ;
106
+ query ( ns , cmd , cursorState , options , callback ) {
107
+ wp . query ( makeServerTrampoline ( this ) , ns , cmd , cursorState , options , callback ) ;
117
108
}
109
+
110
+ getMore ( ns , cursorState , batchSize , options , callback ) {
111
+ wp . getMore ( makeServerTrampoline ( this ) , ns , cursorState , batchSize , options , callback ) ;
112
+ }
113
+
114
+ killCursors ( ns , cursorState , callback ) {
115
+ wp . killCursors ( makeServerTrampoline ( this ) , ns , cursorState , callback ) ;
116
+ }
117
+
118
+ insert ( ns , ops , options , callback ) {
119
+ wp . insert ( makeServerTrampoline ( this ) , ns , ops , options , callback ) ;
120
+ }
121
+
122
+ update ( ns , ops , options , callback ) {
123
+ wp . update ( makeServerTrampoline ( this ) , ns , ops , options , callback ) ;
124
+ }
125
+
126
+ remove ( ns , ops , options , callback ) {
127
+ wp . remove ( makeServerTrampoline ( this ) , ns , ops , options , callback ) ;
128
+ }
129
+ }
130
+
131
+ /// This lets us emulate a legacy `Server` instance so we can work with the existing wire
132
+ /// protocol methods. Eventually, the operation executor will return a `Connection` to execute
133
+ /// against.
134
+ function makeServerTrampoline ( server ) {
135
+ return {
136
+ description : server . description ,
137
+ s : {
138
+ bson : server . bson ,
139
+ pool : { write : write . bind ( server ) }
140
+ }
141
+ } ;
118
142
}
119
143
120
144
function messageHandler ( conn ) {
0 commit comments