Skip to content

Commit 9aea3c5

Browse files
committed
Raise exception when the protocol doesn't support notificationFilter
Also fix naming through the code
1 parent 4aa1ec7 commit 9aea3c5

34 files changed

+451
-59
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
import { newError } from 'neo4j-driver-core'
19+
import { newError, json } from 'neo4j-driver-core'
2020
// eslint-disable-next-line no-unused-vars
2121
import { ResultStreamObserver } from './stream-observers'
2222

@@ -79,4 +79,24 @@ function assertImpersonatedUserIsEmpty (impersonatedUser, onProtocolError = () =
7979
}
8080
}
8181

82-
export { assertDatabaseIsEmpty, assertTxConfigIsEmpty, assertImpersonatedUserIsEmpty }
82+
/**
83+
* Asserts that the passed-in notificationFilter is empty
84+
* @param {NotificationFilter} notificationFilter
85+
* @param {function (err:Error)} onProtocolError Called when it does have notificationFilter user set
86+
* @param {any} observer
87+
*/
88+
function assertNotificationFilterIsEmpty (notificationFilter, onProtocolError = () => {}, observer) {
89+
if (notificationFilter !== undefined) {
90+
const error = newError(
91+
'Driver is connected to a database that does not support user notification filters. ' +
92+
'Please upgrade to Neo4j 5.7.0 or later in order to use this functionality. ' +
93+
`Trying to set notifications to ${json.stringify(notificationFilter)}.`
94+
)
95+
// unsupported API was used, consider this a fatal error for the current connection
96+
onProtocolError(error.message)
97+
observer.onError(error)
98+
throw error
99+
}
100+
}
101+
102+
export { assertDatabaseIsEmpty, assertTxConfigIsEmpty, assertImpersonatedUserIsEmpty, assertNotificationFilterIsEmpty }

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
import {
2020
assertDatabaseIsEmpty,
2121
assertTxConfigIsEmpty,
22-
assertImpersonatedUserIsEmpty
22+
assertImpersonatedUserIsEmpty,
23+
assertNotificationFilterIsEmpty
2324
} from './bolt-protocol-util'
2425
// eslint-disable-next-line no-unused-vars
2526
import { Chunker } from '../channel'
@@ -169,16 +170,20 @@ export default class BoltProtocol {
169170
* @param {Object} param
170171
* @param {string} param.userAgent the user agent.
171172
* @param {Object} param.authToken the authentication token.
173+
* @param {NotificationFilter} param.notificationFilter the notification filter.
172174
* @param {function(err: Error)} param.onError the callback to invoke on error.
173175
* @param {function()} param.onComplete the callback to invoke on completion.
174176
* @returns {StreamObserver} the stream observer that monitors the corresponding server response.
175177
*/
176-
initialize ({ userAgent, authToken, onError, onComplete } = {}) {
178+
initialize ({ userAgent, authToken, notificationFilter, onError, onComplete } = {}) {
177179
const observer = new LoginObserver({
178180
onError: error => this._onLoginError(error, onError),
179181
onCompleted: metadata => this._onLoginCompleted(metadata, onComplete)
180182
})
181183

184+
// passing notification filter on this protocol version throws an error
185+
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
186+
182187
this.write(RequestMessage.init(userAgent, authToken), observer, true)
183188

184189
return observer
@@ -254,6 +259,7 @@ export default class BoltProtocol {
254259
* @param {string} param.database the target database name.
255260
* @param {string} param.mode the access mode.
256261
* @param {string} param.impersonatedUser the impersonated user
262+
* @param {NotificationFilter} param.notificationFilter the notification filter.
257263
* @param {function(err: Error)} param.beforeError the callback to invoke before handling the error.
258264
* @param {function(err: Error)} param.afterError the callback to invoke after handling the error.
259265
* @param {function()} param.beforeComplete the callback to invoke before handling the completion.
@@ -266,6 +272,7 @@ export default class BoltProtocol {
266272
database,
267273
mode,
268274
impersonatedUser,
275+
notificationFilter,
269276
beforeError,
270277
afterError,
271278
beforeComplete,
@@ -280,6 +287,7 @@ export default class BoltProtocol {
280287
database,
281288
mode,
282289
impersonatedUser,
290+
notificationFilter,
283291
beforeError,
284292
afterError,
285293
beforeComplete,
@@ -362,6 +370,7 @@ export default class BoltProtocol {
362370
* @param {TxConfig} param.txConfig the transaction configuration.
363371
* @param {string} param.database the target database name.
364372
* @param {string} param.impersonatedUser the impersonated user
373+
* @param {NotificationFilter} param.notificationFilter the notification filter.
365374
* @param {string} param.mode the access mode.
366375
* @param {function(keys: string[])} param.beforeKeys the callback to invoke before handling the keys.
367376
* @param {function(keys: string[])} param.afterKeys the callback to invoke after handling the keys.
@@ -381,6 +390,7 @@ export default class BoltProtocol {
381390
database,
382391
mode,
383392
impersonatedUser,
393+
notificationFilter,
384394
beforeKeys,
385395
afterKeys,
386396
beforeError,
@@ -410,6 +420,8 @@ export default class BoltProtocol {
410420
assertDatabaseIsEmpty(database, this._onProtocolError, observer)
411421
// passing impersonated user on this protocol version throws an error
412422
assertImpersonatedUserIsEmpty(impersonatedUser, this._onProtocolError, observer)
423+
// passing notification filter on this protocol version throws an error
424+
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
413425

414426
this.write(RequestMessage.run(query, parameters), observer, false)
415427
this.write(RequestMessage.pullAll(), observer, flush)

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
import BoltProtocolV2 from './bolt-protocol-v2'
2020
import RequestMessage from './request-message'
21-
import { assertDatabaseIsEmpty, assertImpersonatedUserIsEmpty } from './bolt-protocol-util'
21+
import { assertDatabaseIsEmpty, assertImpersonatedUserIsEmpty, assertNotificationFilterIsEmpty } from './bolt-protocol-util'
2222
import {
2323
StreamObserver,
2424
LoginObserver,
@@ -69,12 +69,15 @@ export default class BoltProtocol extends BoltProtocolV2 {
6969
return metadata
7070
}
7171

72-
initialize ({ userAgent, authToken, onError, onComplete } = {}) {
72+
initialize ({ userAgent, authToken, notificationFilter, onError, onComplete } = {}) {
7373
const observer = new LoginObserver({
7474
onError: error => this._onLoginError(error, onError),
7575
onCompleted: metadata => this._onLoginCompleted(metadata, authToken, onComplete)
7676
})
7777

78+
// passing notification filter on this protocol version throws an error
79+
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
80+
7881
this.write(RequestMessage.hello(userAgent, authToken), observer, true)
7982

8083
return observer
@@ -89,6 +92,7 @@ export default class BoltProtocol extends BoltProtocolV2 {
8992
txConfig,
9093
database,
9194
impersonatedUser,
95+
notificationFilter,
9296
mode,
9397
beforeError,
9498
afterError,
@@ -108,6 +112,8 @@ export default class BoltProtocol extends BoltProtocolV2 {
108112
assertDatabaseIsEmpty(database, this._onProtocolError, observer)
109113
// passing impersonated user on this protocol version throws an error
110114
assertImpersonatedUserIsEmpty(impersonatedUser, this._onProtocolError, observer)
115+
// passing notification filter on this protocol version throws an error
116+
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
111117

112118
this.write(
113119
RequestMessage.begin({ bookmarks, txConfig, mode }),
@@ -166,6 +172,7 @@ export default class BoltProtocol extends BoltProtocolV2 {
166172
txConfig,
167173
database,
168174
impersonatedUser,
175+
notificationFilter,
169176
mode,
170177
beforeKeys,
171178
afterKeys,
@@ -194,6 +201,8 @@ export default class BoltProtocol extends BoltProtocolV2 {
194201
assertDatabaseIsEmpty(database, this._onProtocolError, observer)
195202
// passing impersonated user on this protocol version throws an error
196203
assertImpersonatedUserIsEmpty(impersonatedUser, this._onProtocolError, observer)
204+
// passing notification filter on this protocol version throws an error
205+
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
197206

198207
this.write(
199208
RequestMessage.runWithMetadata(query, parameters, {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
import BoltProtocolV3 from './bolt-protocol-v3'
2020
import RequestMessage from './request-message'
21-
import { assertImpersonatedUserIsEmpty } from './bolt-protocol-util'
21+
import { assertImpersonatedUserIsEmpty, assertNotificationFilterIsEmpty } from './bolt-protocol-util'
2222
import {
2323
ResultStreamObserver,
2424
ProcedureRouteObserver
@@ -56,6 +56,7 @@ export default class BoltProtocol extends BoltProtocolV3 {
5656
txConfig,
5757
database,
5858
impersonatedUser,
59+
notificationFilter,
5960
mode,
6061
beforeError,
6162
afterError,
@@ -73,6 +74,8 @@ export default class BoltProtocol extends BoltProtocolV3 {
7374

7475
// passing impersonated user on this protocol version throws an error
7576
assertImpersonatedUserIsEmpty(impersonatedUser, this._onProtocolError, observer)
77+
// passing notification filter on this protocol version throws an error
78+
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
7679

7780
this.write(
7881
RequestMessage.begin({ bookmarks, txConfig, database, mode }),
@@ -91,6 +94,7 @@ export default class BoltProtocol extends BoltProtocolV3 {
9194
txConfig,
9295
database,
9396
impersonatedUser,
97+
notificationFilter,
9498
mode,
9599
beforeKeys,
96100
afterKeys,
@@ -123,6 +127,8 @@ export default class BoltProtocol extends BoltProtocolV3 {
123127

124128
// passing impersonated user on this protocol version throws an error
125129
assertImpersonatedUserIsEmpty(impersonatedUser, this._onProtocolError, observer)
130+
// passing notification filter on this protocol version throws an error
131+
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
126132

127133
const flushRun = reactive
128134
this.write(

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import BoltProtocolV4 from './bolt-protocol-v4x0'
2020
import RequestMessage from './request-message'
2121
import { LoginObserver } from './stream-observers'
2222
import { internal } from 'neo4j-driver-core'
23+
import { assertNotificationFilterIsEmpty } from './bolt-protocol-util'
2324

2425
import transformersFactories from './bolt-protocol-v4x1.transformer'
2526
import Transformer from './transformer'
@@ -72,12 +73,15 @@ export default class BoltProtocol extends BoltProtocolV4 {
7273
return this._transformer
7374
}
7475

75-
initialize ({ userAgent, authToken, onError, onComplete } = {}) {
76+
initialize ({ userAgent, authToken, notificationFilter, onError, onComplete } = {}) {
7677
const observer = new LoginObserver({
7778
onError: error => this._onLoginError(error, onError),
7879
onCompleted: metadata => this._onLoginCompleted(metadata, authToken, onComplete)
7980
})
8081

82+
// passing notification filter on this protocol version throws an error
83+
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
84+
8185
this.write(
8286
RequestMessage.hello(userAgent, authToken, this._serversideRouting),
8387
observer,

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import BoltProtocolV42 from './bolt-protocol-v4x2'
2020
import RequestMessage from './request-message'
2121
import { LoginObserver, RouteObserver } from './stream-observers'
22+
import { assertNotificationFilterIsEmpty } from './bolt-protocol-util'
2223

2324
import transformersFactories from './bolt-protocol-v4x3.transformer'
2425
import utcTransformersFactories from './bolt-protocol-v5x0.utc.transformer'
@@ -80,14 +81,15 @@ export default class BoltProtocol extends BoltProtocolV42 {
8081
/**
8182
* Initialize a connection with the server
8283
*
83-
* @param {Object} param0 The params
84-
* @param {string} param0.userAgent The user agent
85-
* @param {any} param0.authToken The auth token
86-
* @param {function(error)} param0.onError On error callback
87-
* @param {function(onComplte)} param0.onComplete On complete callback
84+
* @param {Object} args The params
85+
* @param {string} args.userAgent The user agent
86+
* @param {any} args.authToken The auth token
87+
* @param {NotificationFilter} args.notificationFilter The notification filter.
88+
* @param {function(error)} args.onError On error callback
89+
* @param {function(onComplte)} args.onComplete On complete callback
8890
* @returns {LoginObserver} The Login observer
8991
*/
90-
initialize ({ userAgent, authToken, onError, onComplete } = {}) {
92+
initialize ({ userAgent, authToken, notificationFilter, onError, onComplete } = {}) {
9193
const observer = new LoginObserver({
9294
onError: error => this._onLoginError(error, onError),
9395
onCompleted: metadata => {
@@ -98,6 +100,9 @@ export default class BoltProtocol extends BoltProtocolV42 {
98100
}
99101
})
100102

103+
// passing notification filter on this protocol version throws an error
104+
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
105+
101106
this.write(
102107
RequestMessage.hello(userAgent, authToken, this._serversideRouting, ['utc']),
103108
observer,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import BoltProtocolV43 from './bolt-protocol-v4x3'
2121
import { internal } from 'neo4j-driver-core'
2222
import RequestMessage from './request-message'
2323
import { RouteObserver, ResultStreamObserver } from './stream-observers'
24+
import { assertNotificationFilterIsEmpty } from './bolt-protocol-util'
2425

2526
import transformersFactories from './bolt-protocol-v4x4.transformer'
2627
import utcTransformersFactories from './bolt-protocol-v5x0.utc.transformer'
@@ -87,6 +88,7 @@ export default class BoltProtocol extends BoltProtocolV43 {
8788
database,
8889
mode,
8990
impersonatedUser,
91+
notificationFilter,
9092
beforeKeys,
9193
afterKeys,
9294
beforeError,
@@ -116,6 +118,9 @@ export default class BoltProtocol extends BoltProtocolV43 {
116118
lowRecordWatermark
117119
})
118120

121+
// passing notification filter on this protocol version throws an error
122+
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
123+
119124
const flushRun = reactive
120125
this.write(
121126
RequestMessage.runWithMetadata(query, parameters, {
@@ -142,6 +147,7 @@ export default class BoltProtocol extends BoltProtocolV43 {
142147
database,
143148
mode,
144149
impersonatedUser,
150+
notificationFilter,
145151
beforeError,
146152
afterError,
147153
beforeComplete,
@@ -156,6 +162,9 @@ export default class BoltProtocol extends BoltProtocolV43 {
156162
})
157163
observer.prepareToHandleSingleResponse()
158164

165+
// passing notification filter on this protocol version throws an error
166+
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
167+
159168
this.write(
160169
RequestMessage.begin({ bookmarks, txConfig, database, mode, impersonatedUser }),
161170
observer,

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
import BoltProtocolV44 from './bolt-protocol-v4x4'
2020

21+
import { assertNotificationFilterIsEmpty } from './bolt-protocol-util'
2122
import transformersFactories from './bolt-protocol-v5x0.transformer'
2223
import Transformer from './transformer'
2324
import RequestMessage from './request-message'
@@ -44,19 +45,23 @@ export default class BoltProtocol extends BoltProtocolV44 {
4445
/**
4546
* Initialize a connection with the server
4647
*
47-
* @param {Object} param0 The params
48-
* @param {string} param0.userAgent The user agent
49-
* @param {any} param0.authToken The auth token
50-
* @param {function(error)} param0.onError On error callback
51-
* @param {function(onComplte)} param0.onComplete On complete callback
48+
* @param {Object} args The params
49+
* @param {string} args.userAgent The user agent
50+
* @param {any} args.authToken The auth token
51+
* @param {NotificationFilter} args.notificationFilter The notification filter.
52+
* @param {function(error)} args.onError On error callback
53+
* @param {function(onComplte)} args.onComplete On complete callback
5254
* @returns {LoginObserver} The Login observer
5355
*/
54-
initialize ({ userAgent, authToken, onError, onComplete } = {}) {
56+
initialize ({ userAgent, authToken, notificationFilter, onError, onComplete } = {}) {
5557
const observer = new LoginObserver({
5658
onError: error => this._onLoginError(error, onError),
5759
onCompleted: metadata => this._onLoginCompleted(metadata, authToken, onComplete)
5860
})
5961

62+
// passing notification filter on this protocol version throws an error
63+
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
64+
6065
this.write(
6166
RequestMessage.hello(userAgent, authToken, this._serversideRouting),
6267
observer,

0 commit comments

Comments
 (0)