@@ -21,18 +21,27 @@ import Session from './session';
21
21
import { Pool } from './internal/pool' ;
22
22
import { connect } from "./internal/connector" ;
23
23
import StreamObserver from './internal/stream-observer' ;
24
+ import { VERSION } from '../../version' ;
24
25
25
26
/**
26
- * A Driver instance is used for mananging {@link Session}s.
27
- * @access public
28
- */
27
+ * A driver maintains one or more {@link Session sessions} with a remote
28
+ * Neo4j instance. Through the {@link Session sessions} you can send statements
29
+ * and retrieve results from the database.
30
+ *
31
+ * Drivers are reasonably expensive to create - you should strive to keep one
32
+ * driver instance around per Neo4j Instance you connect to.
33
+ *
34
+ * @access public
35
+ */
29
36
class Driver {
30
37
/**
38
+ * You should not be calling this directly, instead use {@link driver}.
31
39
* @constructor
32
40
* @param {string } url
33
41
* @param {string } userAgent
34
42
* @param {Object } token
35
43
* @param {Object } config
44
+ * @access private
36
45
*/
37
46
constructor ( url , userAgent = 'neo4j-javascript/0.0' , token = { } , config = { } ) {
38
47
this . _url = url ;
@@ -85,7 +94,16 @@ class Driver {
85
94
}
86
95
87
96
/**
88
- * Create and return new session
97
+ * Acquire a session to communicate with the database. The driver maintains
98
+ * a pool of sessions, so calling this method is normally cheap because you
99
+ * will be pulling a session out of the common pool.
100
+ *
101
+ * This comes with some responsibility - make sure you always call
102
+ * {@link Session#close()} when you are done using a session, and likewise,
103
+ * make sure you don't close your session before you are done using it. Once
104
+ * it is returned to the pool, the session will be reset to a clean state and
105
+ * made available for others to use.
106
+ *
89
107
* @return {Session } new session.
90
108
*/
91
109
session ( ) {
@@ -113,8 +131,9 @@ class Driver {
113
131
}
114
132
115
133
/**
116
- * Close sessions connections
117
- * @return
134
+ * Close all open sessions and other associated resources. You should
135
+ * make sure to use this when you are done with this driver instance.
136
+ * @return undefined
118
137
*/
119
138
close ( ) {
120
139
for ( let sessionId in this . _openSessions ) {
@@ -143,4 +162,63 @@ class _ConnectionStreamObserver extends StreamObserver {
143
162
}
144
163
}
145
164
146
- export default Driver
165
+ let USER_AGENT = "neo4j-javascript/" + VERSION ;
166
+
167
+ /**
168
+ * Construct a new Neo4j Driver. This is your main entry point for this
169
+ * library.
170
+ *
171
+ * ## Configuration
172
+ *
173
+ * This function optionally takes a configuration argument. Available configuration
174
+ * options are as follows:
175
+ *
176
+ * {
177
+ * // Enable TLS encryption. This is on by default in modern NodeJS installs,
178
+ * // but off by default in the Web Bundle and old (<=1.0.0) NodeJS installs
179
+ * // due to technical limitations on those platforms.
180
+ * encrypted: true|false,
181
+ *
182
+ * // Trust strategy to use if encryption is enabled. There is no mode to disable
183
+ * // trust other than disabling encryption altogether. The reason for
184
+ * // this is that if you don't know who you are talking to, it is easy for an
185
+ * // attacker to hijack your encrypted connection, rendering encryption pointless.
186
+ * //
187
+ * // TRUST_ON_FIRST_USE is the default for modern NodeJS deployments, and works
188
+ * // similarly to how `ssl` works - the first time we connect to a new host,
189
+ * // we remember the certificate they use. If the certificate ever changes, we
190
+ * // assume it is an attempt to hijack the connection and require manual intervention.
191
+ * // This means that by default, connections "just work" while still giving you
192
+ * // good encrypted protection.
193
+ * //
194
+ * // TRUST_SIGNED_CERTIFICATES is the classic approach to trust verification -
195
+ * // whenever we establish an encrypted connection, we ensure the host is using
196
+ * // an encryption certificate that is in, or is signed by, a certificate listed
197
+ * // as trusted. In the web bundle, this list of trusted certificates is maintained
198
+ * // by the web browser. In NodeJS, you configure the list with the next config option.
199
+ * trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES",
200
+ *
201
+ * // List of one or more paths to trusted encryption certificates. This only
202
+ * // works in the NodeJS bundle, and only matters if you use "TRUST_SIGNED_CERTIFICATES".
203
+ * // The certificate files should be in regular X.509 PEM format.
204
+ * // For instance, ['./trusted.pem']
205
+ * trustedCertificates: [],
206
+ *
207
+ * // Path to a file where the driver saves hosts it has seen in the past, this is
208
+ * // very similar to the ssl tool's known_hosts file. Each time we connect to a
209
+ * // new host, a hash of their certificate is stored along with the domain name and
210
+ * // port, and this is then used to verify the host certificate does not change.
211
+ * // This setting has no effect unless TRUST_ON_FIRST_USE is enabled.
212
+ * knownHosts:"~/.neo4j/known_hosts",
213
+ * }
214
+ *
215
+ * @param {string } url The URL for the Neo4j database, for instance "bolt://localhost"
216
+ * @param {Map<String,String> } authToken Authentication credentials. See {@link auth} for helpers.
217
+ * @param {Object } config Configuration object. See the configuration section above for details.
218
+ * @returns {Driver }
219
+ */
220
+ function driver ( url , authToken , config = { } ) {
221
+ return new Driver ( url , USER_AGENT , authToken , config ) ;
222
+ }
223
+
224
+ export { Driver , driver }
0 commit comments