Skip to content

Commit 5ee5d08

Browse files
committed
Introduce driver level Hydration and Dehydration hooks
This hooks enable driver users to globaly map their own data types to Neo4j driver types and vice-versa.
1 parent e191168 commit 5ee5d08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+490
-173
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export default class BoltProtocol {
7474
{ disableLosslessIntegers, useBigInt } = {},
7575
createResponseHandler = () => null,
7676
log,
77-
onProtocolError
77+
onProtocolError,
78+
hydrationHooks,
79+
dehydrationHooks
7880
) {
7981
this._server = server || {}
8082
this._chunker = chunker
@@ -86,11 +88,13 @@ export default class BoltProtocol {
8688
this._fatalError = null
8789
this._lastMessageSignature = null
8890
this._config = { disableLosslessIntegers, useBigInt }
91+
this._hydrationHooks = hydrationHooks
92+
this._dehydrationHooks = dehydrationHooks
8993
}
9094

9195
get transformer () {
9296
if (this._transformer === undefined) {
93-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
97+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
9498
}
9599
return this._transformer
96100
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class BoltProtocol extends BoltProtocolV1 {
3737

3838
get transformer () {
3939
if (this._transformer === undefined) {
40-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
40+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
4141
}
4242
return this._transformer
4343
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default class BoltProtocol extends BoltProtocolV2 {
4848

4949
get transformer () {
5050
if (this._transformer === undefined) {
51-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
51+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
5252
}
5353
return this._transformer
5454
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class BoltProtocol extends BoltProtocolV3 {
4646

4747
get transformer () {
4848
if (this._transformer === undefined) {
49-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
49+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
5050
}
5151
return this._transformer
5252
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export default class BoltProtocol extends BoltProtocolV4 {
4949
createResponseHandler = () => null,
5050
log,
5151
onProtocolError,
52+
hydrationHooks,
53+
dehydrationHooks,
5254
serversideRouting
5355
) {
5456
super(
@@ -57,7 +59,9 @@ export default class BoltProtocol extends BoltProtocolV4 {
5759
packstreamConfig,
5860
createResponseHandler,
5961
log,
60-
onProtocolError
62+
onProtocolError,
63+
hydrationHooks,
64+
dehydrationHooks
6165
)
6266
this._serversideRouting = serversideRouting
6367
}
@@ -68,7 +72,7 @@ export default class BoltProtocol extends BoltProtocolV4 {
6872

6973
get transformer () {
7074
if (this._transformer === undefined) {
71-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
75+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
7276
}
7377
return this._transformer
7478
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class BoltProtocol extends BoltProtocolV41 {
3434

3535
get transformer () {
3636
if (this._transformer === undefined) {
37-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
37+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
3838
}
3939
return this._transformer
4040
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class BoltProtocol extends BoltProtocolV42 {
3939

4040
get transformer () {
4141
if (this._transformer === undefined) {
42-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
42+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
4343
}
4444
return this._transformer
4545
}
@@ -126,6 +126,6 @@ export default class BoltProtocol extends BoltProtocolV42 {
126126
this._transformer = new Transformer(Object.values({
127127
...transformersFactories,
128128
...utcTransformersFactories
129-
}).map(create => create(this._config, this._log)))
129+
}).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
130130
}
131131
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class BoltProtocol extends BoltProtocolV43 {
3939

4040
get transformer () {
4141
if (this._transformer === undefined) {
42-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
42+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
4343
}
4444
return this._transformer
4545
}
@@ -178,6 +178,6 @@ export default class BoltProtocol extends BoltProtocolV43 {
178178
this._transformer = new Transformer(Object.values({
179179
...transformersFactories,
180180
...utcTransformersFactories
181-
}).map(create => create(this._config, this._log)))
181+
}).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
182182
}
183183
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class BoltProtocol extends BoltProtocolV44 {
3737

3838
get transformer () {
3939
if (this._transformer === undefined) {
40-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
40+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
4141
}
4242
return this._transformer
4343
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class BoltProtocol extends BoltProtocolV5x0 {
3737

3838
get transformer () {
3939
if (this._transformer === undefined) {
40-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
40+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
4141
}
4242
return this._transformer
4343
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default class BoltProtocol extends BoltProtocolV5x1 {
3636

3737
get transformer () {
3838
if (this._transformer === undefined) {
39-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
39+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
4040
}
4141
return this._transformer
4242
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default class BoltProtocol extends BoltProtocolV5x2 {
3636

3737
get transformer () {
3838
if (this._transformer === undefined) {
39-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
39+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
4040
}
4141
return this._transformer
4242
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default class BoltProtocol extends BoltProtocolV5x3 {
3636

3737
get transformer () {
3838
if (this._transformer === undefined) {
39-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
39+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)), this._hydrationHooks, this._dehydrationHooks)
4040
}
4141
return this._transformer
4242
}

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

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import ResponseHandler from './response-handler'
4848
* @param {boolean} config.disableLosslessIntegers Disable the lossless integers
4949
* @param {boolean} packstreamConfig.useBigInt if this connection should convert all received integers to native BigInt numbers.
5050
* @param {boolean} config.serversideRouting It's using server side routing
51+
* @param {HydatrationHooks} config.hydrationHooks Hydatration hooks used to map types
52+
* @param {DehydrationHooks} config.dehydrationHooks Hydatration hooks used to map types
5153
*/
5254
export default function create ({
5355
version,
@@ -59,7 +61,9 @@ export default function create ({
5961
serversideRouting,
6062
server, // server info
6163
log,
62-
observer
64+
observer,
65+
hydrationHooks,
66+
dehydrationHooks
6367
} = {}) {
6468
const createResponseHandler = protocol => {
6569
const responseHandler = new ResponseHandler({
@@ -94,7 +98,9 @@ export default function create ({
9498
serversideRouting,
9599
createResponseHandler,
96100
observer.onProtocolError.bind(observer),
97-
log
101+
log,
102+
hydrationHooks,
103+
dehydrationHooks
98104
)
99105
}
100106

@@ -106,7 +112,9 @@ function createProtocol (
106112
serversideRouting,
107113
createResponseHandler,
108114
onProtocolError,
109-
log
115+
log,
116+
hydrationHooks,
117+
dehydrationHooks
110118
) {
111119
switch (version) {
112120
case 1:
@@ -116,7 +124,9 @@ function createProtocol (
116124
packingConfig,
117125
createResponseHandler,
118126
log,
119-
onProtocolError
127+
onProtocolError,
128+
hydrationHooks,
129+
dehydrationHooks
120130
)
121131
case 2:
122132
return new BoltProtocolV2(
@@ -125,7 +135,9 @@ function createProtocol (
125135
packingConfig,
126136
createResponseHandler,
127137
log,
128-
onProtocolError
138+
onProtocolError,
139+
hydrationHooks,
140+
dehydrationHooks
129141
)
130142
case 3:
131143
return new BoltProtocolV3(
@@ -134,7 +146,9 @@ function createProtocol (
134146
packingConfig,
135147
createResponseHandler,
136148
log,
137-
onProtocolError
149+
onProtocolError,
150+
hydrationHooks,
151+
dehydrationHooks
138152
)
139153
case 4.0:
140154
return new BoltProtocolV4x0(
@@ -143,7 +157,9 @@ function createProtocol (
143157
packingConfig,
144158
createResponseHandler,
145159
log,
146-
onProtocolError
160+
onProtocolError,
161+
hydrationHooks,
162+
dehydrationHooks
147163
)
148164
case 4.1:
149165
return new BoltProtocolV4x1(
@@ -153,6 +169,8 @@ function createProtocol (
153169
createResponseHandler,
154170
log,
155171
onProtocolError,
172+
hydrationHooks,
173+
dehydrationHooks,
156174
serversideRouting
157175
)
158176
case 4.2:
@@ -163,6 +181,8 @@ function createProtocol (
163181
createResponseHandler,
164182
log,
165183
onProtocolError,
184+
hydrationHooks,
185+
dehydrationHooks,
166186
serversideRouting
167187
)
168188
case 4.3:
@@ -173,6 +193,8 @@ function createProtocol (
173193
createResponseHandler,
174194
log,
175195
onProtocolError,
196+
hydrationHooks,
197+
dehydrationHooks,
176198
serversideRouting
177199
)
178200
case 4.4:
@@ -183,6 +205,8 @@ function createProtocol (
183205
createResponseHandler,
184206
log,
185207
onProtocolError,
208+
hydrationHooks,
209+
dehydrationHooks,
186210
serversideRouting
187211
)
188212
case 5.0:
@@ -193,6 +217,8 @@ function createProtocol (
193217
createResponseHandler,
194218
log,
195219
onProtocolError,
220+
hydrationHooks,
221+
dehydrationHooks,
196222
serversideRouting
197223
)
198224
case 5.1:
@@ -203,6 +229,8 @@ function createProtocol (
203229
createResponseHandler,
204230
log,
205231
onProtocolError,
232+
hydrationHooks,
233+
dehydrationHooks,
206234
serversideRouting
207235
)
208236
case 5.2:
@@ -213,6 +241,8 @@ function createProtocol (
213241
createResponseHandler,
214242
log,
215243
onProtocolError,
244+
hydrationHooks,
245+
dehydrationHooks,
216246
serversideRouting
217247
)
218248
case 5.3:
@@ -222,6 +252,8 @@ function createProtocol (
222252
createResponseHandler,
223253
log,
224254
onProtocolError,
255+
hydrationHooks,
256+
dehydrationHooks,
225257
serversideRouting)
226258
case 5.4:
227259
return new BoltProtocolV5x4(server,
@@ -230,6 +262,8 @@ function createProtocol (
230262
createResponseHandler,
231263
log,
232264
onProtocolError,
265+
hydrationHooks,
266+
dehydrationHooks,
233267
serversideRouting)
234268
default:
235269
throw newError('Unknown Bolt protocol version: ' + version)

0 commit comments

Comments
 (0)