Skip to content

Commit 5d7eda3

Browse files
committed
Add support for old identifiers absence in 5.x protocol
1 parent b7db76d commit 5d7eda3

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class Unpacker extends v2.Unpacker {
3737
this._verifyStructSize('Node', NODE_STRUCT_SIZE, structSize)
3838

3939
return new Node(
40-
this.unpack(buffer), // Identity
40+
_valueOrDefault(this.unpack(buffer), -1), // Identity
4141
this.unpack(buffer), // Labels
4242
this.unpack(buffer), // Properties,
4343
this.unpack(buffer) // ElementId
@@ -48,9 +48,9 @@ export class Unpacker extends v2.Unpacker {
4848
this._verifyStructSize('Relationship', RELATIONSHIP_STRUCT_SIZE, structSize)
4949

5050
return new Relationship(
51-
this.unpack(buffer), // Identity
52-
this.unpack(buffer), // Start Node Identity
53-
this.unpack(buffer), // End Node Identity
51+
_valueOrDefault(this.unpack(buffer), -1), // Identity
52+
_valueOrDefault(this.unpack(buffer), -1), // Start Node Identity
53+
_valueOrDefault(this.unpack(buffer), -1), // End Node Identity
5454
this.unpack(buffer), // Type
5555
this.unpack(buffer), // Properties,
5656
this.unpack(buffer), // ElementId
@@ -67,10 +67,14 @@ export class Unpacker extends v2.Unpacker {
6767
)
6868

6969
return new UnboundRelationship(
70-
this.unpack(buffer), // Identity
70+
_valueOrDefault(this.unpack(buffer), -1), // Identity
7171
this.unpack(buffer), // Type
7272
this.unpack(buffer), // Properties
7373
this.unpack(buffer) // ElementId
7474
)
7575
}
7676
}
77+
78+
function _valueOrDefault(value, defaultValue) {
79+
return value === null ? defaultValue : value
80+
}

packages/bolt-connection/test/packstream/packstream-v5.test.js

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ describe('#unit PackStreamV5', () => {
239239
return [nodeStruct, expectedNode, { disableLosslessIntegers: true, useBigInt: false }]
240240
}
241241

242+
function validWithoutOldIdentifiers() {
243+
const identity = null
244+
const labels = ['a', 'b']
245+
const properties = { 'a': 1, 'b': 2 }
246+
const elementId = 'element_id_1'
247+
const expectedNode = new Node(-1, labels, properties, elementId)
248+
const nodeStruct = new Structure(0x4e, [
249+
identity, labels, properties, elementId
250+
])
251+
return [nodeStruct, expectedNode, { disableLosslessIntegers: true, useBigInt: false }]
252+
}
253+
242254
function validWithInt() {
243255
const identity = int(1)
244256
const labels = ['a', 'b']
@@ -266,7 +278,8 @@ describe('#unit PackStreamV5', () => {
266278
return [
267279
validWithNumber(),
268280
validWithInt(),
269-
validWithBigInt()
281+
validWithBigInt(),
282+
validWithoutOldIdentifiers()
270283
]
271284
}
272285

@@ -297,6 +310,25 @@ describe('#unit PackStreamV5', () => {
297310
return [relStruct, expectedRel, { disableLosslessIntegers: true, useBigInt: false }]
298311
}
299312

313+
function validWithoutOldIdentifiers() {
314+
const identity = null
315+
const start = null
316+
const end = null
317+
const type = 'KNOWS'
318+
const properties = { 'a': 1, 'b': 2 }
319+
const elementId = 'element_id_1'
320+
const startNodeElementId = 'element_id_2'
321+
const endNodeElementId = 'element_id_3'
322+
const expectedRel = new Relationship(
323+
-1, -1, -1, type, properties,
324+
elementId, startNodeElementId, endNodeElementId)
325+
const relStruct = new Structure(0x52, [
326+
identity, start, end, type, properties, elementId,
327+
startNodeElementId, endNodeElementId
328+
])
329+
return [relStruct, expectedRel, { disableLosslessIntegers: true, useBigInt: false }]
330+
}
331+
300332
function validWithInt() {
301333
const identity = int(1)
302334
const start = int(2)
@@ -338,7 +370,8 @@ describe('#unit PackStreamV5', () => {
338370
return [
339371
validWithNumber(),
340372
validWithInt(),
341-
validWithBigInt()
373+
validWithBigInt(),
374+
validWithoutOldIdentifiers()
342375
]
343376
}
344377

@@ -362,6 +395,18 @@ describe('#unit PackStreamV5', () => {
362395
return [struct, expectedUnboundRel, { disableLosslessIntegers: true, useBigInt: false }]
363396
}
364397

398+
function validWithoutOldIdentifiers() {
399+
const identity = null
400+
const type = 'DOESNT_KNOW'
401+
const properties = { 'a': 1, 'b': 2 }
402+
const elementId = 'element_id_1'
403+
const expectedUnboundRel = new UnboundRelationship(-1, type, properties, elementId)
404+
const struct = new Structure(0x72, [
405+
identity, type, properties, elementId
406+
])
407+
return [struct, expectedUnboundRel, { disableLosslessIntegers: true, useBigInt: false }]
408+
}
409+
365410
function validWithInt() {
366411
const identity = int(1)
367412
const type = 'DOESNT_KNOW'
@@ -389,7 +434,8 @@ describe('#unit PackStreamV5', () => {
389434
return [
390435
validWithNumber(),
391436
validWithInt(),
392-
validWithBigInt()
437+
validWithBigInt(),
438+
validWithoutOldIdentifiers()
393439
]
394440
}
395441

0 commit comments

Comments
 (0)