Skip to content

Commit 7e955e6

Browse files
committed
Add notification filters to Connection.initialize
1 parent 3221e22 commit 7e955e6

File tree

9 files changed

+57
-22
lines changed

9 files changed

+57
-22
lines changed

packages/bolt-connection/src/connection-provider/connection-provider-pooled.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { error, ConnectionProvider, ServerInfo } from 'neo4j-driver-core'
2424
const { SERVICE_UNAVAILABLE } = error
2525
export default class PooledConnectionProvider extends ConnectionProvider {
2626
constructor (
27-
{ id, config, log, userAgent, authToken },
27+
{ id, config, log, userAgent, authToken, notificationFilters },
2828
createChannelConnectionHook = null
2929
) {
3030
super()
@@ -34,6 +34,7 @@ export default class PooledConnectionProvider extends ConnectionProvider {
3434
this._log = log
3535
this._userAgent = userAgent
3636
this._authToken = authToken
37+
this._notificationFilters = notificationFilters
3738
this._createChannelConnection =
3839
createChannelConnectionHook ||
3940
(address => {
@@ -76,7 +77,7 @@ export default class PooledConnectionProvider extends ConnectionProvider {
7677
}
7778
this._openConnections[connection.id] = connection
7879
return connection
79-
.connect(this._userAgent, this._authToken)
80+
.connect(this._userAgent, this._authToken, this._notificationFilters)
8081
.catch(error => {
8182
// let's destroy this connection
8283
this._destroyConnection(connection)

packages/bolt-connection/src/connection/connection-channel.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,27 @@ export default class ChannelConnection extends Connection {
169169
* Send initialization message.
170170
* @param {string} userAgent the user agent for this driver.
171171
* @param {Object} authToken the object containing auth information.
172+
* @param {?string[]} notificationFilters the notification filters.
172173
* @return {Promise<Connection>} promise resolved with the current connection if connection is successful. Rejected promise otherwise.
173174
*/
174-
connect (userAgent, authToken) {
175-
return this._initialize(userAgent, authToken)
175+
connect (userAgent, authToken, notificationFilters) {
176+
return this._initialize(userAgent, authToken, notificationFilters)
176177
}
177178

178179
/**
179180
* Perform protocol-specific initialization which includes authentication.
180181
* @param {string} userAgent the user agent for this driver.
181182
* @param {Object} authToken the object containing auth information.
183+
* @param {?string[]} notificationFilters the notification filters.
182184
* @return {Promise<Connection>} promise resolved with the current connection if initialization is successful. Rejected promise otherwise.
183185
*/
184-
_initialize (userAgent, authToken) {
186+
_initialize (userAgent, authToken, notificationFilters) {
185187
const self = this
186188
return new Promise((resolve, reject) => {
187189
this._protocol.initialize({
188190
userAgent,
189191
authToken,
192+
notificationFilters,
190193
onError: err => reject(err),
191194
onComplete: metadata => {
192195
if (metadata) {
@@ -340,13 +343,14 @@ export default class ChannelConnection extends Connection {
340343
})
341344
}
342345

343-
_reset(observer) {
346+
_reset (observer) {
344347
if (this._reseting) {
345348
if (!this._protocol.isLastMessageReset()) {
346349
this._protocol.reset({
347350
onError: error => {
348351
observer.onError(error)
349-
}, onComplete: () => {
352+
},
353+
onComplete: () => {
350354
observer.onComplete()
351355
}
352356
})
@@ -369,7 +373,8 @@ export default class ChannelConnection extends Connection {
369373
this._protocol.reset({
370374
onError: error => {
371375
notifyFinish(obs => obs.onError(error))
372-
}, onComplete: () => {
376+
},
377+
onComplete: () => {
373378
notifyFinish(obs => obs.onComplete())
374379
}
375380
})

packages/bolt-connection/src/connection/connection-delegate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export default class DelegateConnection extends Connection {
7171
return this._delegate.protocol()
7272
}
7373

74-
connect (userAgent, authToken) {
75-
return this._delegate.connect(userAgent, authToken)
74+
connect (userAgent, authToken, notificationFilters) {
75+
return this._delegate.connect(userAgent, authToken, notificationFilters)
7676
}
7777

7878
write (message, observer, flush) {

packages/bolt-connection/src/connection/connection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ export default class Connection {
7979
* Connect to the target address, negotiate Bolt protocol and send initialization message.
8080
* @param {string} userAgent the user agent for this driver.
8181
* @param {Object} authToken the object containing auth information.
82+
* @param {?string[]} notificationFilters the notification filters.
8283
* @return {Promise<Connection>} promise resolved with the current connection if connection is successful. Rejected promise otherwise.
8384
*/
84-
connect (userAgent, authToken) {
85+
connect (userAgent, authToken, notificationFilters) {
8586
throw new Error('not implemented')
8687
}
8788

packages/bolt-connection/test/connection/connection-channel.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,27 @@ describe('ChannelConnection', () => {
124124
)
125125
}
126126
)
127+
128+
it.each([
129+
undefined,
130+
null,
131+
[],
132+
['*.*', 'WARNING.*']
133+
])('should call protocol.initialize with notification filters when notificationFilters is %o',
134+
async (notificationFilters) => {
135+
const protocol = {
136+
initialize: jest.fn(observer => observer.onComplete({}))
137+
}
138+
const protocolSupplier = () => protocol
139+
const connection = spyOnConnectionChannel({ protocolSupplier })
140+
141+
await connection.connect('userAgent', {}, notificationFilters)
142+
143+
expect(protocol.initialize).toHaveBeenCalledTimes(1)
144+
expect(protocol.initialize).toBeCalledWith(expect.objectContaining({
145+
notificationFilters
146+
}))
147+
})
127148
})
128149

129150
describe('._handleFatalError()', () => {

packages/neo4j-driver-deno/lib/bolt-connection/connection-provider/connection-provider-pooled.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { error, ConnectionProvider, ServerInfo } from '../../core/index.ts'
2424
const { SERVICE_UNAVAILABLE } = error
2525
export default class PooledConnectionProvider extends ConnectionProvider {
2626
constructor (
27-
{ id, config, log, userAgent, authToken },
27+
{ id, config, log, userAgent, authToken, notificationFilters },
2828
createChannelConnectionHook = null
2929
) {
3030
super()
@@ -34,6 +34,7 @@ export default class PooledConnectionProvider extends ConnectionProvider {
3434
this._log = log
3535
this._userAgent = userAgent
3636
this._authToken = authToken
37+
this._notificationFilters = notificationFilters
3738
this._createChannelConnection =
3839
createChannelConnectionHook ||
3940
(address => {
@@ -76,7 +77,7 @@ export default class PooledConnectionProvider extends ConnectionProvider {
7677
}
7778
this._openConnections[connection.id] = connection
7879
return connection
79-
.connect(this._userAgent, this._authToken)
80+
.connect(this._userAgent, this._authToken, this._notificationFilters)
8081
.catch(error => {
8182
// let's destroy this connection
8283
this._destroyConnection(connection)

packages/neo4j-driver-deno/lib/bolt-connection/connection/connection-channel.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,27 @@ export default class ChannelConnection extends Connection {
169169
* Send initialization message.
170170
* @param {string} userAgent the user agent for this driver.
171171
* @param {Object} authToken the object containing auth information.
172+
* @param {?string[]} notificationFilters the notification filters.
172173
* @return {Promise<Connection>} promise resolved with the current connection if connection is successful. Rejected promise otherwise.
173174
*/
174-
connect (userAgent, authToken) {
175-
return this._initialize(userAgent, authToken)
175+
connect (userAgent, authToken, notificationFilters) {
176+
return this._initialize(userAgent, authToken, notificationFilters)
176177
}
177178

178179
/**
179180
* Perform protocol-specific initialization which includes authentication.
180181
* @param {string} userAgent the user agent for this driver.
181182
* @param {Object} authToken the object containing auth information.
183+
* @param {?string[]} notificationFilters the notification filters.
182184
* @return {Promise<Connection>} promise resolved with the current connection if initialization is successful. Rejected promise otherwise.
183185
*/
184-
_initialize (userAgent, authToken) {
186+
_initialize (userAgent, authToken, notificationFilters) {
185187
const self = this
186188
return new Promise((resolve, reject) => {
187189
this._protocol.initialize({
188190
userAgent,
189191
authToken,
192+
notificationFilters,
190193
onError: err => reject(err),
191194
onComplete: metadata => {
192195
if (metadata) {
@@ -340,13 +343,14 @@ export default class ChannelConnection extends Connection {
340343
})
341344
}
342345

343-
_reset(observer) {
346+
_reset (observer) {
344347
if (this._reseting) {
345348
if (!this._protocol.isLastMessageReset()) {
346349
this._protocol.reset({
347350
onError: error => {
348351
observer.onError(error)
349-
}, onComplete: () => {
352+
},
353+
onComplete: () => {
350354
observer.onComplete()
351355
}
352356
})
@@ -369,7 +373,8 @@ export default class ChannelConnection extends Connection {
369373
this._protocol.reset({
370374
onError: error => {
371375
notifyFinish(obs => obs.onError(error))
372-
}, onComplete: () => {
376+
},
377+
onComplete: () => {
373378
notifyFinish(obs => obs.onComplete())
374379
}
375380
})

packages/neo4j-driver-deno/lib/bolt-connection/connection/connection-delegate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export default class DelegateConnection extends Connection {
7171
return this._delegate.protocol()
7272
}
7373

74-
connect (userAgent, authToken) {
75-
return this._delegate.connect(userAgent, authToken)
74+
connect (userAgent, authToken, notificationFilters) {
75+
return this._delegate.connect(userAgent, authToken, notificationFilters)
7676
}
7777

7878
write (message, observer, flush) {

packages/neo4j-driver-deno/lib/bolt-connection/connection/connection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ export default class Connection {
7979
* Connect to the target address, negotiate Bolt protocol and send initialization message.
8080
* @param {string} userAgent the user agent for this driver.
8181
* @param {Object} authToken the object containing auth information.
82+
* @param {?string[]} notificationFilters the notification filters.
8283
* @return {Promise<Connection>} promise resolved with the current connection if connection is successful. Rejected promise otherwise.
8384
*/
84-
connect (userAgent, authToken) {
85+
connect (userAgent, authToken, notificationFilters) {
8586
throw new Error('not implemented')
8687
}
8788

0 commit comments

Comments
 (0)