@@ -96,7 +96,110 @@ interface DriverConfig {
96
96
trust ?: TrustStrategy
97
97
fetchSize ?: number
98
98
logging ?: LoggingConfig
99
+ }
100
+
101
+ /**
102
+ * The session configuration
103
+ *
104
+ * @interface
105
+ *
106
+ * @param {string } defaultAccessMode=WRITE - The access mode of this session, allowed values are {@link READ} and {@link WRITE}.
107
+ * @param {string|string[] } bookmarks - The initial reference or references to some previous
108
+ * transactions. Value is optional and absence indicates that that the bookmarks do not exist or are unknown.
109
+ * @param {number } fetchSize - The record fetch size of each batch of this session.
110
+ * Use {@link FETCH_ALL} to always pull all records in one batch. This will override the config value set on driver config.
111
+ * @param {string } database - The database this session will operate on.
112
+ * @param {string } impersonatedUser - The username which the user wants to impersonate for the duration of the session.
113
+ * @param {BookmarkManager } [bookmarkManager] = The bookmark manager
114
+ */
115
+ class SessionConfig {
116
+ defaultAccessMode ?: SessionMode
117
+ bookmarks ?: string | string [ ]
118
+ database ?: string
119
+ impersonatedUser ?: string
120
+ fetchSize ?: number
99
121
bookmarkManager ?: BookmarkManager
122
+
123
+ /**
124
+ * @constructor
125
+ * @private
126
+ */
127
+ constructor ( ) {
128
+ /**
129
+ * The access mode of this session, allowed values are {@link READ} and {@link WRITE}.
130
+ * **Default**: {@link WRITE}
131
+ * @type {string }
132
+ */
133
+ this . defaultAccessMode = WRITE
134
+ /**
135
+ * The initial reference or references to some previous
136
+ * transactions. Value is optional and absence indicates that that the bookmarks do not exist or are unknown.
137
+ * @type {string|string[]|undefined }
138
+ */
139
+ this . bookmarks = [ ]
140
+
141
+ /**
142
+ * The database this session will operate on.
143
+ *
144
+ * @type {string|undefined }
145
+ */
146
+ this . database = ''
147
+
148
+ /**
149
+ * The username which the user wants to impersonate for the duration of the session.
150
+ *
151
+ * @type {string|undefined }
152
+ */
153
+ this . impersonatedUser = undefined
154
+
155
+ /**
156
+ * The record fetch size of each batch of this session.
157
+ *
158
+ * Use {@link FETCH_ALL} to always pull all records in one batch. This will override the config value set on driver config.
159
+ *
160
+ * @type {number|undefined }
161
+ */
162
+ this . fetchSize = undefined
163
+ /**
164
+ * Configure a BookmarkManager for the session to use
165
+ *
166
+ * A BookmarkManager is a piece of software responsible for keeping casual consistency between different sessions by sharing bookmarks
167
+ * between the them.
168
+ * Enabling it is done by supplying an BookmarkManager implementation instance to this param.
169
+ * A default implementation could be acquired by calling the factory function {@link bookmarkManager}.
170
+ *
171
+ * **Warning**: Share the same BookmarkManager instance accross all session can have a negative impact
172
+ * on performance since all the queries will wait for the latest changes being propagated across the cluster.
173
+ * For keeping consistency between a group of queries, use {@link Session} for grouping them.
174
+ * For keeping consistency between a group of sessions, use {@link BookmarkManager} instance for groupping them.
175
+ *
176
+ * @example
177
+ * const bookmarkManager = neo4j.bookmarkManager()
178
+ * const linkedSession1 = driver.session({ database:'neo4j', bookmarkManager })
179
+ * const linkedSession2 = driver.session({ database:'neo4j', bookmarkManager })
180
+ * const unlinkedSession = driver.session({ database:'neo4j' })
181
+ *
182
+ * // Creating Driver User
183
+ * const createUserQueryResult = await linkedSession1.run('CREATE (p:Person {name: $name})', { name: 'Driver User'})
184
+ *
185
+ * // Reading Driver User will *NOT* wait of the changes being propagated to the server before RUN the query
186
+ * // So the 'Driver User' person might not exist in the Result
187
+ * const unlinkedReadResult = await unlinkedSession.run('CREATE (p:Person {name: $name}) RETURN p', { name: 'Driver User'})
188
+ *
189
+ * // Reading Driver User will wait of the changes being propagated to the server before RUN the query
190
+ * // So the 'Driver User' person should exist in the Result, unless deleted.
191
+ * const linkedSesssion2 = await linkedSession2.run('CREATE (p:Person {name: $name}) RETURN p', { name: 'Driver User'})
192
+ *
193
+ * await linkedSession1.close()
194
+ * await linkedSession2.close()
195
+ * await unlinkedSession.close()
196
+ *
197
+ * @experimental
198
+ * @type {BookmarkManager|undefined }
199
+ * @since 5.0
200
+ */
201
+ this . bookmarkManager = undefined
202
+ }
100
203
}
101
204
102
205
/**
@@ -285,15 +388,7 @@ class Driver {
285
388
* pool and made available for others to use.
286
389
*
287
390
* @public
288
- * @param {Object } param - The object parameter
289
- * @param {string } param.defaultAccessMode=WRITE - The access mode of this session, allowed values are {@link READ} and {@link WRITE}.
290
- * @param {string|string[] } param.bookmarks - The initial reference or references to some previous
291
- * transactions. Value is optional and absence indicates that that the bookmarks do not exist or are unknown.
292
- * @param {number } param.fetchSize - The record fetch size of each batch of this session.
293
- * Use {@link FETCH_ALL} to always pull all records in one batch. This will override the config value set on driver config.
294
- * @param {string } param.database - The database this session will operate on.
295
- * @param {string } param.impersonatedUser - The username which the user wants to impersonate for the duration of the session.
296
- * @param {boolean } param.ignoreBookmarkManager - Disable the bookmark manager usage in the session.
391
+ * @param {SessionConfig } param - The session configuration
297
392
* @return {Session } new session.
298
393
*/
299
394
session ( {
@@ -302,15 +397,8 @@ class Driver {
302
397
database = '' ,
303
398
impersonatedUser,
304
399
fetchSize,
305
- ignoreBookmarkManager
306
- } : {
307
- defaultAccessMode ?: SessionMode
308
- bookmarks ?: string | string [ ]
309
- database ?: string
310
- impersonatedUser ?: string
311
- fetchSize ?: number
312
- ignoreBookmarkManager ?: boolean
313
- } = { } ) : Session {
400
+ bookmarkManager
401
+ } : SessionConfig = { } ) : Session {
314
402
return this . _newSession ( {
315
403
defaultAccessMode,
316
404
bookmarkOrBookmarks,
@@ -319,7 +407,7 @@ class Driver {
319
407
impersonatedUser,
320
408
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
321
409
fetchSize : validateFetchSizeValue ( fetchSize , this . _config . fetchSize ! ) ,
322
- ignoreBookmarkManager
410
+ bookmarkManager
323
411
} )
324
412
}
325
413
@@ -356,24 +444,22 @@ class Driver {
356
444
reactive,
357
445
impersonatedUser,
358
446
fetchSize,
359
- ignoreBookmarkManager
447
+ bookmarkManager
360
448
} : {
361
449
defaultAccessMode : SessionMode
362
450
bookmarkOrBookmarks ?: string | string [ ]
363
451
database : string
364
452
reactive : boolean
365
453
impersonatedUser ?: string
366
454
fetchSize : number
367
- ignoreBookmarkManager ?: boolean
455
+ bookmarkManager ?: BookmarkManager
368
456
} ) : Session {
369
457
const sessionMode = Session . _validateSessionMode ( defaultAccessMode )
370
458
const connectionProvider = this . _getOrCreateConnectionProvider ( )
371
459
const bookmarks = bookmarkOrBookmarks != null
372
460
? new Bookmarks ( bookmarkOrBookmarks )
373
461
: Bookmarks . empty ( )
374
- const bookmarkManager = ignoreBookmarkManager !== true
375
- ? this . _config . bookmarkManager
376
- : undefined
462
+
377
463
return this . _createSession ( {
378
464
mode : sessionMode ,
379
465
database : database ?? '' ,
@@ -486,7 +572,7 @@ function validateFetchSizeValue (
486
572
/**
487
573
* @private
488
574
*/
489
- function extractConnectionTimeout ( config : any ) : number | null {
575
+ function extractConnectionTimeout ( config : any ) : number | null {
490
576
const configuredTimeout = parseInt ( config . connectionTimeout , 10 )
491
577
if ( configuredTimeout === 0 ) {
492
578
// timeout explicitly configured to 0
@@ -513,5 +599,5 @@ function createHostNameResolver (config: any): ConfiguredCustomResolver {
513
599
}
514
600
515
601
export { Driver , READ , WRITE }
516
-
602
+ export type { SessionConfig }
517
603
export default Driver
0 commit comments