Skip to content

Commit 94fdad0

Browse files
committed
Improve documentation
1 parent 8ff27cb commit 94fdad0

28 files changed

+624
-163
lines changed

src/docs.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) 2002-2019 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
/**
21+
* Configuration object containing settings for explicit and auto-commit transactions.
22+
* <p>
23+
* Configuration is supported for:
24+
* <ul>
25+
* <li>queries executed in auto-commit transactions using {@link Session#run} and {@link RxSession#run}</li>
26+
* <li>transactions started by transaction functions using {@link Session#readTransaction}, {@link RxSession#readTransaction},
27+
* {@link Session#writeTransaction} and {@link RxSession#writeTransaction}</li>
28+
* <li>explicit transactions using {@link Session#beginTransaction} and {@link RxSession#beginTransaction}</li>
29+
* </ul>
30+
* @typedef {Object} TransactionConfig
31+
* @property {number} timeout - the transaction timeout in **milliseconds**. Transactions that execute longer than the configured timeout will
32+
* be terminated by the database. This functionality allows to limit query/transaction execution time. Specified timeout overrides the default timeout
33+
* configured in the database using `dbms.transaction.timeout` setting. Value should not represent a duration of zero or negative duration.
34+
* @property {Object} metadata - the transaction metadata. Specified metadata will be attached to the executing transaction and visible in the output of
35+
* `dbms.listQueries` and `dbms.listTransactions` procedures. It will also get logged to the `query.log`. This functionality makes it easier to tag
36+
* transactions and is equivalent to `dbms.setTXMetaData` procedure.
37+
*/

src/driver.js

Lines changed: 87 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ class Driver {
6363
/**
6464
* You should not be calling this directly, instead use {@link driver}.
6565
* @constructor
66+
* @protected
6667
* @param {ServerAddress} address
6768
* @param {string} userAgent
68-
* @param {object} authToken
69-
* @param {object} config
70-
* @protected
69+
* @param {Object} authToken
70+
* @param {Object} config
7171
*/
7272
constructor (address, userAgent, authToken = {}, config = {}) {
7373
sanitizeConfig(config)
@@ -89,19 +89,13 @@ class Driver {
8989
this._afterConstruction()
9090
}
9191

92-
/**
93-
* @protected
94-
*/
95-
_afterConstruction () {
96-
this._log.info(
97-
`Direct driver ${this._id} created for server address ${this._address}`
98-
)
99-
}
100-
10192
/**
10293
* Verifies connectivity of this driver by trying to open a connection with the provided driver options.
103-
* @param {string} [database=''] the target database to verify connectivity for.
104-
* @returns {Promise<object>} promise resolved with server info or rejected with error.
94+
*
95+
* @public
96+
* @param {Object} param - The object parameter
97+
* @param {string} param.database - the target database to verify connectivity for.
98+
* @returns {Promise} promise resolved with server info or rejected with error.
10599
*/
106100
verifyConnectivity ({ database = '' } = {}) {
107101
const connectionProvider = this._getOrCreateConnectionProvider()
@@ -120,11 +114,12 @@ class Driver {
120114
* it is closed, the underlying connection will be released to the connection
121115
* pool and made available for others to use.
122116
*
123-
* @param {Object} args -
124-
* @param {string} args.defaultAccessMode='WRITE' - the access mode of this session, allowed values are {@link READ} and {@link WRITE}.
125-
* @param {string|string[]} args.bookmarks - the initial reference or references to some previous
117+
* @public
118+
* @param {Object} param - The object parameter
119+
* @param {string} param.defaultAccessMode=WRITE - the access mode of this session, allowed values are {@link READ} and {@link WRITE}.
120+
* @param {string|string[]} param.bookmarks - the initial reference or references to some previous
126121
* transactions. Value is optional and absence indicates that that the bookmarks do not exist or are unknown.
127-
* @param {string} args.database='' - the database this session will connect to.
122+
* @param {string} param.database - the database this session will operate on.
128123
* @return {Session} new session.
129124
*/
130125
session ({
@@ -140,6 +135,25 @@ class Driver {
140135
})
141136
}
142137

138+
/**
139+
* Acquire a reactive session to communicate with the database. The session will
140+
* borrow connections from the underlying connection pool as required and
141+
* should be considered lightweight and disposable.
142+
*
143+
* This comes with some responsibility - make sure you always call
144+
* {@link close} when you are done using a session, and likewise,
145+
* make sure you don't close your session before you are done using it. Once
146+
* it is closed, the underlying connection will be released to the connection
147+
* pool and made available for others to use.
148+
*
149+
* @public
150+
* @param {Object} param
151+
* @param {string} param.defaultAccessMode=WRITE - the access mode of this session, allowed values are {@link READ} and {@link WRITE}
152+
* @param {string|string[]} param.bookmarks - the initial reference or references to some previous transactions. Value is optional and
153+
* absence indicates that the bookmarks do not exist or are unknown.
154+
* @param {string} param.database - the database this session will operate on.
155+
* @returns {RxSession} new reactive session.
156+
*/
143157
rxSession ({ defaultAccessMode = WRITE, bookmarks, database = '' } = {}) {
144158
return new RxSession({
145159
session: this._newSession({
@@ -152,22 +166,44 @@ class Driver {
152166
})
153167
}
154168

155-
_newSession ({ defaultAccessMode, bookmarkOrBookmarks, database, reactive }) {
156-
const sessionMode = Driver._validateSessionMode(defaultAccessMode)
157-
const connectionProvider = this._getOrCreateConnectionProvider()
158-
const bookmark = bookmarkOrBookmarks
159-
? new Bookmark(bookmarkOrBookmarks)
160-
: Bookmark.empty()
161-
return new Session({
162-
mode: sessionMode,
163-
database,
164-
connectionProvider,
165-
bookmark,
169+
/**
170+
* Close all open sessions and other associated resources. You should
171+
* make sure to use this when you are done with this driver instance.
172+
* @public
173+
*/
174+
close () {
175+
this._log.info(`Driver ${this._id} closing`)
176+
if (this._connectionProvider) {
177+
this._connectionProvider.close()
178+
}
179+
}
180+
181+
/**
182+
* @protected
183+
*/
184+
_afterConstruction () {
185+
this._log.info(
186+
`Direct driver ${this._id} created for server address ${this._address}`
187+
)
188+
}
189+
190+
/**
191+
* @protected
192+
*/
193+
_createConnectionProvider (address, userAgent, authToken) {
194+
return new DirectConnectionProvider({
195+
id: this._id,
166196
config: this._config,
167-
reactive
197+
log: this._log,
198+
address: address,
199+
userAgent: userAgent,
200+
authToken: authToken
168201
})
169202
}
170203

204+
/**
205+
* @protected
206+
*/
171207
static _validateSessionMode (rawMode) {
172208
const mode = rawMode || WRITE
173209
if (mode !== ACCESS_MODE_READ && mode !== ACCESS_MODE_WRITE) {
@@ -176,18 +212,28 @@ class Driver {
176212
return mode
177213
}
178214

179-
// Extension point
180-
_createConnectionProvider (address, userAgent, authToken) {
181-
return new DirectConnectionProvider({
182-
id: this._id,
215+
/**
216+
* @private
217+
*/
218+
_newSession ({ defaultAccessMode, bookmarkOrBookmarks, database, reactive }) {
219+
const sessionMode = Driver._validateSessionMode(defaultAccessMode)
220+
const connectionProvider = this._getOrCreateConnectionProvider()
221+
const bookmark = bookmarkOrBookmarks
222+
? new Bookmark(bookmarkOrBookmarks)
223+
: Bookmark.empty()
224+
return new Session({
225+
mode: sessionMode,
226+
database,
227+
connectionProvider,
228+
bookmark,
183229
config: this._config,
184-
log: this._log,
185-
address: address,
186-
userAgent: userAgent,
187-
authToken: authToken
230+
reactive
188231
})
189232
}
190233

234+
/**
235+
* @private
236+
*/
191237
_getOrCreateConnectionProvider () {
192238
if (!this._connectionProvider) {
193239
this._connectionProvider = this._createConnectionProvider(
@@ -199,18 +245,6 @@ class Driver {
199245

200246
return this._connectionProvider
201247
}
202-
203-
/**
204-
* Close all open sessions and other associated resources. You should
205-
* make sure to use this when you are done with this driver instance.
206-
* @return undefined
207-
*/
208-
close () {
209-
this._log.info(`Driver ${this._id} closing`)
210-
if (this._connectionProvider) {
211-
this._connectionProvider.close()
212-
}
213-
}
214248
}
215249

216250
/**
@@ -231,6 +265,9 @@ function sanitizeConfig (config) {
231265
)
232266
}
233267

268+
/**
269+
* @private
270+
*/
234271
function sanitizeIntValue (rawValue, defaultWhenAbsent) {
235272
const sanitizedValue = parseInt(rawValue, 10)
236273
if (sanitizedValue > 0 || sanitizedValue === 0) {

0 commit comments

Comments
 (0)