Skip to content

Commit 7510c9c

Browse files
committed
Patching 4.3 and 4.4 with the UTC fix
1 parent 55df210 commit 7510c9c

File tree

10 files changed

+764
-6
lines changed

10 files changed

+764
-6
lines changed

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
*/
1919
import BoltProtocolV42 from './bolt-protocol-v4x2'
2020
import RequestMessage from './request-message'
21-
import { RouteObserver } from './stream-observers'
21+
import { LoginObserver, RouteObserver } from './stream-observers'
2222

2323
import transformersFactories from './bolt-protocol-v4x3.transformer'
24+
import utcTransformersFactories from './bolt-protocol-v5x0.utc.transformer'
2425
import Transformer from './transformer'
2526

2627
import { internal } from 'neo4j-driver-core'
@@ -75,4 +76,51 @@ export default class BoltProtocol extends BoltProtocolV42 {
7576

7677
return observer
7778
}
79+
80+
/**
81+
* Initialize a connection with the server
82+
*
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
88+
* @returns {LoginObserver} The Login observer
89+
*/
90+
initialize ({ userAgent, authToken, onError, onComplete } = {}) {
91+
const observer = new LoginObserver({
92+
onError: error => this._onLoginError(error, onError),
93+
onCompleted: metadata => {
94+
if (metadata.patch_bolt !== undefined) {
95+
this._applyPatches(metadata.patch_bolt)
96+
}
97+
return this._onLoginCompleted(metadata, onComplete)
98+
}
99+
})
100+
101+
this.write(
102+
RequestMessage.hello(userAgent, authToken, this._serversideRouting, ['utc']),
103+
observer,
104+
true
105+
)
106+
107+
return observer
108+
}
109+
110+
/**
111+
*
112+
* @param {string[]} patches Patches to be applied to the protocol
113+
*/
114+
_applyPatches (patches) {
115+
if (patches.includes('utc')) {
116+
this._applyUtcPatch()
117+
}
118+
}
119+
120+
_applyUtcPatch () {
121+
this._transformer = new Transformer(Object.values({
122+
...transformersFactories,
123+
...utcTransformersFactories
124+
}).map(create => create(this._config, this._log)))
125+
}
78126
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import RequestMessage from './request-message'
2323
import { RouteObserver, ResultStreamObserver } from './stream-observers'
2424

2525
import transformersFactories from './bolt-protocol-v4x4.transformer'
26+
import utcTransformersFactories from './bolt-protocol-v5x0.utc.transformer'
2627
import Transformer from './transformer'
2728

2829
const {
@@ -163,4 +164,11 @@ export default class BoltProtocol extends BoltProtocolV43 {
163164

164165
return observer
165166
}
167+
168+
_applyUtcPatch () {
169+
this._transformer = new Transformer(Object.values({
170+
...transformersFactories,
171+
...utcTransformersFactories
172+
}).map(create => create(this._config, this._log)))
173+
}
166174
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import BoltProtocolV44 from './bolt-protocol-v4x4'
2020

2121
import transformersFactories from './bolt-protocol-v5x0.transformer'
2222
import Transformer from './transformer'
23+
import RequestMessage from './request-message'
24+
import { LoginObserver } from './stream-observers'
2325

2426
import { internal } from 'neo4j-driver-core'
2527

@@ -38,4 +40,29 @@ export default class BoltProtocol extends BoltProtocolV44 {
3840
}
3941
return this._transformer
4042
}
43+
44+
/**
45+
* Initialize a connection with the server
46+
*
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
52+
* @returns {LoginObserver} The Login observer
53+
*/
54+
initialize ({ userAgent, authToken, onError, onComplete } = {}) {
55+
const observer = new LoginObserver({
56+
onError: error => this._onLoginError(error, onError),
57+
onCompleted: metadata => this._onLoginCompleted(metadata, onComplete)
58+
})
59+
60+
this.write(
61+
RequestMessage.hello(userAgent, authToken, this._serversideRouting),
62+
observer,
63+
true
64+
)
65+
66+
return observer
67+
}
4168
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,14 @@ export default class RequestMessage {
106106
* @param {Object} optional server side routing, set to routing context to turn on server side routing (> 4.1)
107107
* @return {RequestMessage} new HELLO message.
108108
*/
109-
static hello (userAgent, authToken, routing = null) {
109+
static hello (userAgent, authToken, routing = null, patchs = null) {
110110
const metadata = Object.assign({ user_agent: userAgent }, authToken)
111111
if (routing) {
112112
metadata.routing = routing
113113
}
114+
if (patchs) {
115+
metadata.patch_bolt = patchs
116+
}
114117
return new RequestMessage(
115118
HELLO,
116119
[metadata],

packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,11 @@ exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Tim
5959
exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`;
6060

6161
exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`;
62+
63+
exports[`#unit BoltProtocolV4x3 utc patch the server accepted the patch should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`;
64+
65+
exports[`#unit BoltProtocolV4x3 utc patch the server accepted the patch should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`;
66+
67+
exports[`#unit BoltProtocolV4x3 utc patch the server accepted the patch should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`;
68+
69+
exports[`#unit BoltProtocolV4x3 utc patch the server accepted the patch should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`;

packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,11 @@ exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Tim
5959
exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`;
6060

6161
exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`;
62+
63+
exports[`#unit BoltProtocolV4x4 utc patch the server accepted the patch should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`;
64+
65+
exports[`#unit BoltProtocolV4x4 utc patch the server accepted the patch should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`;
66+
67+
exports[`#unit BoltProtocolV4x4 utc patch the server accepted the patch should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`;
68+
69+
exports[`#unit BoltProtocolV4x4 utc patch the server accepted the patch should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`;

0 commit comments

Comments
 (0)