From ea535ba3fd3eff10a766d2cdad3a3b1cfe62425b Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Tue, 7 Jun 2022 15:52:42 +0200 Subject: [PATCH 01/18] Decouple Packstream Serialization/De-serialization from Bolt structut hydration The current implementation of the packstream packer and unpacker also includes the creation of the bolt structures. This implementation join twos different concepts in the same object and this doesn't allow the flexibility needed for working with different structure for the same object in the same bolt version, for instance. Decoupling this two layer allows the driver supports the new `utc` feature in a more suitable way. --- .../src/packstream/packstream-v1.js | 80 ++++---- .../src/packstream/packstream-v2.js | 194 ++++++------------ .../src/packstream/packstream-v5.js | 64 ++++-- 3 files changed, 146 insertions(+), 192 deletions(-) diff --git a/packages/bolt-connection/src/packstream/packstream-v1.js b/packages/bolt-connection/src/packstream/packstream-v1.js index 1b77f096a..03667fddb 100644 --- a/packages/bolt-connection/src/packstream/packstream-v1.js +++ b/packages/bolt-connection/src/packstream/packstream-v1.js @@ -85,6 +85,10 @@ class Structure { this.fields = fields } + get size () { + return this.fields.length + } + toString () { let fieldStr = '' for (let i = 0; i < this.fields.length; i++) { @@ -575,61 +579,45 @@ class Unpacker { _unpackStructWithSize (structSize, buffer) { const signature = buffer.readUInt8() - if (signature === NODE) { - return this._unpackNode(structSize, buffer) - } else if (signature === RELATIONSHIP) { - return this._unpackRelationship(structSize, buffer) - } else if (signature === UNBOUND_RELATIONSHIP) { - return this._unpackUnboundRelationship(structSize, buffer) - } else if (signature === PATH) { - return this._unpackPath(structSize, buffer) - } else { - return this._unpackUnknownStruct(signature, structSize, buffer) + const structure = new Structure(signature, []) + for (let i = 0; i < structSize; i++) { + structure.fields.push(this.unpack(buffer)) } + return this._hydrate(structure) } - _unpackNode (structSize, buffer) { - this._verifyStructSize('Node', NODE_STRUCT_SIZE, structSize) + _unpackNode (structure) { + this._verifyStructSize('Node', NODE_STRUCT_SIZE, structure.size) - return new Node( - this.unpack(buffer), // Identity - this.unpack(buffer), // Labels - this.unpack(buffer) // Properties - ) + const [identity, labels, properties] = structure.fields + + return new Node(identity, labels, properties) } - _unpackRelationship (structSize, buffer) { - this._verifyStructSize('Relationship', RELATIONSHIP_STRUCT_SIZE, structSize) + _unpackRelationship (structure) { + this._verifyStructSize('Relationship', RELATIONSHIP_STRUCT_SIZE, structure.size) - return new Relationship( - this.unpack(buffer), // Identity - this.unpack(buffer), // Start Node Identity - this.unpack(buffer), // End Node Identity - this.unpack(buffer), // Type - this.unpack(buffer) // Properties - ) + const [identity, startNodeIdentity, endNodeIdentity, type, properties] = structure.fields + + return new Relationship(identity, startNodeIdentity, endNodeIdentity, type, properties) } - _unpackUnboundRelationship (structSize, buffer) { + _unpackUnboundRelationship (structure) { this._verifyStructSize( 'UnboundRelationship', UNBOUND_RELATIONSHIP_STRUCT_SIZE, - structSize + structure.size ) - return new UnboundRelationship( - this.unpack(buffer), // Identity - this.unpack(buffer), // Type - this.unpack(buffer) // Properties - ) + const [identity, type, properties] = structure.fields + + return new UnboundRelationship(identity, type, properties) } - _unpackPath (structSize, buffer) { - this._verifyStructSize('Path', PATH_STRUCT_SIZE, structSize) + _unpackPath (structure) { + this._verifyStructSize('Path', PATH_STRUCT_SIZE, structure.size) - const nodes = this.unpack(buffer) - const rels = this.unpack(buffer) - const sequence = this.unpack(buffer) + const [nodes, rels, sequence] = structure.fields const segments = [] let prevNode = nodes[0] @@ -668,12 +656,18 @@ class Unpacker { return new Path(nodes[0], nodes[nodes.length - 1], segments) } - _unpackUnknownStruct (signature, structSize, buffer) { - const result = new Structure(signature, []) - for (let i = 0; i < structSize; i++) { - result.fields.push(this.unpack(buffer)) + _hydrate (structure, onUnknowStructure = struct => struct) { + if (structure.signature === NODE) { + return this._unpackNode(structure) + } else if (structure.signature === RELATIONSHIP) { + return this._unpackRelationship(structure) + } else if (structure.signature === UNBOUND_RELATIONSHIP) { + return this._unpackUnboundRelationship(structure) + } else if (structure.signature === PATH) { + return this._unpackPath(structure) + } else { + return onUnknowStructure(structure) } - return result } _verifyStructSize (structName, expectedSize, actualSize) { diff --git a/packages/bolt-connection/src/packstream/packstream-v2.js b/packages/bolt-connection/src/packstream/packstream-v2.js index 7a1f49607..34e580eea 100644 --- a/packages/bolt-connection/src/packstream/packstream-v2.js +++ b/packages/bolt-connection/src/packstream/packstream-v2.js @@ -112,70 +112,32 @@ export class Unpacker extends v1.Unpacker { super(disableLosslessIntegers, useBigInt) } - _unpackUnknownStruct (signature, structSize, buffer) { - if (signature === POINT_2D) { - return unpackPoint2D(this, structSize, buffer) - } else if (signature === POINT_3D) { - return unpackPoint3D(this, structSize, buffer) - } else if (signature === DURATION) { - return unpackDuration(this, structSize, buffer) - } else if (signature === LOCAL_TIME) { - return unpackLocalTime( - this, - structSize, - buffer, - this._disableLosslessIntegers, - this._useBigInt - ) - } else if (signature === TIME) { - return unpackTime( - this, - structSize, - buffer, - this._disableLosslessIntegers, - this._useBigInt - ) - } else if (signature === DATE) { - return unpackDate( - this, - structSize, - buffer, - this._disableLosslessIntegers, - this._useBigInt - ) - } else if (signature === LOCAL_DATE_TIME) { - return unpackLocalDateTime( - this, - structSize, - buffer, - this._disableLosslessIntegers, - this._useBigInt - ) - } else if (signature === DATE_TIME_WITH_ZONE_OFFSET) { - return unpackDateTimeWithZoneOffset( - this, - structSize, - buffer, - this._disableLosslessIntegers, - this._useBigInt - ) - } else if (signature === DATE_TIME_WITH_ZONE_ID) { - return unpackDateTimeWithZoneId( - this, - structSize, - buffer, - this._disableLosslessIntegers, - this._useBigInt - ) - } else { - return super._unpackUnknownStruct( - signature, - structSize, - buffer, - this._disableLosslessIntegers, - this._useBigInt - ) - } + _hydrate (structure, onUnknowStructure = struct => struct) { + const verifyStructSize = this._verifyStructSize.bind(this) + return super._hydrate(structure, struct => { + const signature = struct.signature + if (signature === POINT_2D) { + return unpackPoint2D(verifyStructSize, struct) + } else if (signature === POINT_3D) { + return unpackPoint3D(verifyStructSize, struct) + } else if (signature === DURATION) { + return unpackDuration(verifyStructSize, struct) + } else if (signature === LOCAL_TIME) { + return unpackLocalTime(verifyStructSize, struct, this._disableLosslessIntegers, this._useBigInt) + } else if (signature === TIME) { + return unpackTime(verifyStructSize, struct, this._disableLosslessIntegers, this._useBigInt) + } else if (signature === DATE) { + return unpackDate(verifyStructSize, struct, this._disableLosslessIntegers, this._useBigInt) + } else if (signature === LOCAL_DATE_TIME) { + return unpackLocalDateTime(verifyStructSize, struct, this._disableLosslessIntegers, this._useBigInt) + } else if (signature === DATE_TIME_WITH_ZONE_OFFSET) { + return unpackDateTimeWithZoneOffset(verifyStructSize, struct, this._disableLosslessIntegers, this._useBigInt) + } else if (signature === DATE_TIME_WITH_ZONE_ID) { + return unpackDateTimeWithZoneId(verifyStructSize, struct, this._disableLosslessIntegers, this._useBigInt) + } else { + return onUnknowStructure(struct) + } + }) } } @@ -229,13 +191,14 @@ function packPoint3D (point, packer) { * @param {BaseBuffer} buffer the buffer to unpack from. * @return {Point} the unpacked 2D point value. */ -function unpackPoint2D (unpacker, structSize, buffer) { - unpacker._verifyStructSize('Point2D', POINT_2D_STRUCT_SIZE, structSize) +function unpackPoint2D (verifyStructSize, struct) { + verifyStructSize('Point2D', POINT_2D_STRUCT_SIZE, struct.size) + const [srid, x, y] = struct.fields return new Point( - unpacker.unpack(buffer), // srid - unpacker.unpack(buffer), // x - unpacker.unpack(buffer), // y + srid, + x, + y, undefined // z ) } @@ -247,15 +210,12 @@ function unpackPoint2D (unpacker, structSize, buffer) { * @param {BaseBuffer} buffer the buffer to unpack from. * @return {Point} the unpacked 3D point value. */ -function unpackPoint3D (unpacker, structSize, buffer) { - unpacker._verifyStructSize('Point3D', POINT_3D_STRUCT_SIZE, structSize) +function unpackPoint3D (verifyStructSize, struct) { + verifyStructSize('Point3D', POINT_3D_STRUCT_SIZE, struct.size) - return new Point( - unpacker.unpack(buffer), // srid - unpacker.unpack(buffer), // x - unpacker.unpack(buffer), // y - unpacker.unpack(buffer) // z - ) + const [srid, x, y, z] = struct.fields + + return new Point(srid, x, y, z) } /** @@ -285,13 +245,10 @@ function packDuration (value, packer) { * @param {BaseBuffer} buffer the buffer to unpack from. * @return {Duration} the unpacked duration value. */ -function unpackDuration (unpacker, structSize, buffer) { - unpacker._verifyStructSize('Duration', DURATION_STRUCT_SIZE, structSize) +function unpackDuration (verifyStructSize, struct) { + verifyStructSize('Duration', DURATION_STRUCT_SIZE, struct.size) - const months = unpacker.unpack(buffer) - const days = unpacker.unpack(buffer) - const seconds = unpacker.unpack(buffer) - const nanoseconds = unpacker.unpack(buffer) + const [months, days, seconds, nanoseconds] = struct.fields return new Duration(months, days, seconds, nanoseconds) } @@ -321,17 +278,12 @@ function packLocalTime (value, packer) { * @param {boolean} disableLosslessIntegers if integer properties in the result local time should be native JS numbers. * @return {LocalTime} the unpacked local time value. */ -function unpackLocalTime ( - unpacker, - structSize, - buffer, - disableLosslessIntegers -) { - unpacker._verifyStructSize('LocalTime', LOCAL_TIME_STRUCT_SIZE, structSize) +function unpackLocalTime (verifyStructSize, struct, disableLosslessIntegers, useBigInt) { + verifyStructSize('LocalTime', LOCAL_TIME_STRUCT_SIZE, struct.size) - const nanoOfDay = unpacker.unpackInteger(buffer) + const [nanoOfDay] = struct.fields const result = nanoOfDayToLocalTime(nanoOfDay) - return convertIntegerPropsIfNeeded(result, disableLosslessIntegers) + return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) // check disable lossless } /** @@ -364,17 +316,14 @@ function packTime (value, packer) { * @return {Time} the unpacked time value. */ function unpackTime ( - unpacker, - structSize, - buffer, + verifyStructSize, + struct, disableLosslessIntegers, useBigInt ) { - unpacker._verifyStructSize('Time', TIME_STRUCT_SIZE, structSize) - - const nanoOfDay = unpacker.unpackInteger(buffer) - const offsetSeconds = unpacker.unpackInteger(buffer) + verifyStructSize('Time', TIME_STRUCT_SIZE, struct.size) + const [nanoOfDay, offsetSeconds] = struct.fields const localTime = nanoOfDayToLocalTime(nanoOfDay) const result = new Time( localTime.hour, @@ -407,15 +356,14 @@ function packDate (value, packer) { * @return {Date} the unpacked neo4j date value. */ function unpackDate ( - unpacker, - structSize, - buffer, + verifyStructSize, + struct, disableLosslessIntegers, useBigInt ) { - unpacker._verifyStructSize('Date', DATE_STRUCT_SIZE, structSize) + verifyStructSize('Date', DATE_STRUCT_SIZE, struct.size) - const epochDay = unpacker.unpackInteger(buffer) + const [epochDay] = struct.fields const result = epochDayToDate(epochDay) return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) } @@ -453,20 +401,18 @@ function packLocalDateTime (value, packer) { * @return {LocalDateTime} the unpacked local date time value. */ function unpackLocalDateTime ( - unpacker, - structSize, - buffer, + verifyStructSize, + struct, disableLosslessIntegers, useBigInt ) { - unpacker._verifyStructSize( + verifyStructSize( 'LocalDateTime', LOCAL_DATE_TIME_STRUCT_SIZE, - structSize + struct.size ) - const epochSecond = unpacker.unpackInteger(buffer) - const nano = unpacker.unpackInteger(buffer) + const [epochSecond, nano] = struct.fields const result = epochSecondAndNanoToLocalDateTime(epochSecond, nano) return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) } @@ -519,21 +465,18 @@ function packDateTimeWithZoneOffset (value, packer) { * @return {DateTime} the unpacked date time with zone offset value. */ function unpackDateTimeWithZoneOffset ( - unpacker, - structSize, - buffer, + verifyStructSize, + struct, disableLosslessIntegers, useBigInt ) { - unpacker._verifyStructSize( + verifyStructSize( 'DateTimeWithZoneOffset', DATE_TIME_WITH_ZONE_OFFSET_STRUCT_SIZE, - structSize + struct.size ) - const epochSecond = unpacker.unpackInteger(buffer) - const nano = unpacker.unpackInteger(buffer) - const timeZoneOffsetSeconds = unpacker.unpackInteger(buffer) + const [epochSecond, nano, timeZoneOffsetSeconds] = struct.fields const localDateTime = epochSecondAndNanoToLocalDateTime(epochSecond, nano) const result = new DateTime( @@ -585,21 +528,18 @@ function packDateTimeWithZoneId (value, packer) { * @return {DateTime} the unpacked date time with zone id value. */ function unpackDateTimeWithZoneId ( - unpacker, - structSize, - buffer, + verifyStructSize, + struct, disableLosslessIntegers, useBigInt ) { - unpacker._verifyStructSize( + verifyStructSize( 'DateTimeWithZoneId', DATE_TIME_WITH_ZONE_ID_STRUCT_SIZE, - structSize + struct.size ) - const epochSecond = unpacker.unpackInteger(buffer) - const nano = unpacker.unpackInteger(buffer) - const timeZoneId = unpacker.unpack(buffer) + const [epochSecond, nano, timeZoneId] = struct.fields const localDateTime = epochSecondAndNanoToLocalDateTime(epochSecond, nano) const result = new DateTime( diff --git a/packages/bolt-connection/src/packstream/packstream-v5.js b/packages/bolt-connection/src/packstream/packstream-v5.js index e99731336..dd110f5a8 100644 --- a/packages/bolt-connection/src/packstream/packstream-v5.js +++ b/packages/bolt-connection/src/packstream/packstream-v5.js @@ -54,44 +54,64 @@ export class Unpacker extends v2.Unpacker { } } - _unpackNode (structSize, buffer) { - this._verifyStructSize('Node', NODE_STRUCT_SIZE, structSize) + _unpackNode (structure) { + this._verifyStructSize('Node', NODE_STRUCT_SIZE, structure.size) + + const [identity, lables, properties, elementId] = structure.fields return new Node( - _valueOrDefault(this.unpack(buffer), this._defaultIdentity), // Identity - this.unpack(buffer), // Labels - this.unpack(buffer), // Properties, - this.unpack(buffer) // ElementId + _valueOrDefault(identity, this._defaultIdentity), // Identity + lables, // Labels + properties, // Properties, + elementId // ElementId ) } - _unpackRelationship (structSize, buffer) { - this._verifyStructSize('Relationship', RELATIONSHIP_STRUCT_SIZE, structSize) + _unpackRelationship (structure) { + this._verifyStructSize('Relationship', RELATIONSHIP_STRUCT_SIZE, structure.size) + + const [ + identity, + startNodeIdentity, + endNodeIdentity, + type, + properties, + elementId, + startNodeElementId, + endNodeElementId + ] = structure.fields return new Relationship( - _valueOrDefault(this.unpack(buffer), this._defaultIdentity), // Identity - _valueOrDefault(this.unpack(buffer), this._defaultIdentity), // Start Node Identity - _valueOrDefault(this.unpack(buffer), this._defaultIdentity), // End Node Identity - this.unpack(buffer), // Type - this.unpack(buffer), // Properties, - this.unpack(buffer), // ElementId - this.unpack(buffer), // Start Node Element Id - this.unpack(buffer) // End Node Element Id + _valueOrDefault(identity, this._defaultIdentity), // Identity + _valueOrDefault(startNodeIdentity, this._defaultIdentity), // Start Node Identity + _valueOrDefault(endNodeIdentity, this._defaultIdentity), // End Node Identity + type, + properties, + elementId, + startNodeElementId, + endNodeElementId ) } - _unpackUnboundRelationship (structSize, buffer) { + _unpackUnboundRelationship (structure) { this._verifyStructSize( 'UnboundRelationship', UNBOUND_RELATIONSHIP_STRUCT_SIZE, - structSize + structure.size ) + const [ + identity, + type, + properties, + elementId + ] = structure.fields + return new UnboundRelationship( - _valueOrDefault(this.unpack(buffer), this._defaultIdentity), // Identity - this.unpack(buffer), // Type - this.unpack(buffer), // Properties - this.unpack(buffer) // ElementId + _valueOrDefault(identity, this._defaultIdentity), // Identity + type, + properties, + elementId ) } } From 2c4224944551c62301a7a91217efe2c791129947 Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Tue, 7 Jun 2022 16:22:53 +0200 Subject: [PATCH 02/18] Add de-hytration --- .../src/packstream/packstream-v1.js | 3 +- .../src/packstream/packstream-v2.js | 129 +++++++----------- 2 files changed, 54 insertions(+), 78 deletions(-) diff --git a/packages/bolt-connection/src/packstream/packstream-v1.js b/packages/bolt-connection/src/packstream/packstream-v1.js index 03667fddb..ddcb0dee1 100644 --- a/packages/bolt-connection/src/packstream/packstream-v1.js +++ b/packages/bolt-connection/src/packstream/packstream-v1.js @@ -120,7 +120,8 @@ class Packer { * @param x the value to pack * @returns Function */ - packable (x) { + packable (x, dehydrate = (x) => x) { + x = dehydrate(x) if (x === null) { return () => this._ch.writeUInt8(NULL) } else if (x === true) { diff --git a/packages/bolt-connection/src/packstream/packstream-v2.js b/packages/bolt-connection/src/packstream/packstream-v2.js index 34e580eea..b98669aa6 100644 --- a/packages/bolt-connection/src/packstream/packstream-v2.js +++ b/packages/bolt-connection/src/packstream/packstream-v2.js @@ -81,24 +81,26 @@ export class Packer extends v1.Packer { throw new Error('Bolt V2 should always support byte arrays') } - packable (obj) { - if (isPoint(obj)) { - return () => packPoint(obj, this) - } else if (isDuration(obj)) { - return () => packDuration(obj, this) - } else if (isLocalTime(obj)) { - return () => packLocalTime(obj, this) - } else if (isTime(obj)) { - return () => packTime(obj, this) - } else if (isDate(obj)) { - return () => packDate(obj, this) - } else if (isLocalDateTime(obj)) { - return () => packLocalDateTime(obj, this) - } else if (isDateTime(obj)) { - return () => packDateTime(obj, this) - } else { - return super.packable(obj) - } + packable (obj, dehydrate = (x) => x) { + return super.packable(obj, x => { + if (isPoint(x)) { + return packPoint(x) + } else if (isDuration(x)) { + return packDuration(x) + } else if (isLocalTime(x)) { + return packLocalTime(x) + } else if (isTime(x)) { + return packTime(x) + } else if (isDate(x)) { + return packDate(x) + } else if (isLocalDateTime(x)) { + return packLocalDateTime(x) + } else if (isDateTime(x)) { + return packDateTime(x) + } else { + return dehydrate(x) + } + }) } } @@ -146,12 +148,12 @@ export class Unpacker extends v1.Unpacker { * @param {Point} point the point value to pack. * @param {Packer} packer the packer to use. */ -function packPoint (point, packer) { +function packPoint (point) { const is2DPoint = point.z === null || point.z === undefined if (is2DPoint) { - packPoint2D(point, packer) + packPoint2D(point) } else { - packPoint3D(point, packer) + packPoint3D(point) } } @@ -160,13 +162,13 @@ function packPoint (point, packer) { * @param {Point} point the point value to pack. * @param {Packer} packer the packer to use. */ -function packPoint2D (point, packer) { - const packableStructFields = [ - packer.packable(int(point.srid)), - packer.packable(point.x), - packer.packable(point.y) +function packPoint2D (point) { + const fields = [ + int(point.srid), + point.x, + point.y ] - packer.packStruct(POINT_2D, packableStructFields) + return new v1.Structure(POINT_2D, fields) } /** @@ -174,14 +176,14 @@ function packPoint2D (point, packer) { * @param {Point} point the point value to pack. * @param {Packer} packer the packer to use. */ -function packPoint3D (point, packer) { - const packableStructFields = [ - packer.packable(int(point.srid)), - packer.packable(point.x), - packer.packable(point.y), - packer.packable(point.z) +function packPoint3D (point) { + const fields = [ + int(point.srid), + point.x, + point.y, + point.z ] - packer.packStruct(POINT_3D, packableStructFields) + return new v1.Structure(POINT_3D, fields) } /** @@ -223,19 +225,13 @@ function unpackPoint3D (verifyStructSize, struct) { * @param {Duration} value the duration value to pack. * @param {Packer} packer the packer to use. */ -function packDuration (value, packer) { +function packDuration (value) { const months = int(value.months) const days = int(value.days) const seconds = int(value.seconds) const nanoseconds = int(value.nanoseconds) - const packableStructFields = [ - packer.packable(months), - packer.packable(days), - packer.packable(seconds), - packer.packable(nanoseconds) - ] - packer.packStruct(DURATION, packableStructFields) + return new v1.Structure(DURATION, [months, days, seconds, nanoseconds]) } /** @@ -266,8 +262,7 @@ function packLocalTime (value, packer) { value.nanosecond ) - const packableStructFields = [packer.packable(nanoOfDay)] - packer.packStruct(LOCAL_TIME, packableStructFields) + return new v1.Structure(LOCAL_TIME, [nanoOfDay]) } /** @@ -291,7 +286,7 @@ function unpackLocalTime (verifyStructSize, struct, disableLosslessIntegers, use * @param {Time} value the time value to pack. * @param {Packer} packer the packer to use. */ -function packTime (value, packer) { +function packTime (value) { const nanoOfDay = localTimeToNanoOfDay( value.hour, value.minute, @@ -300,11 +295,7 @@ function packTime (value, packer) { ) const offsetSeconds = int(value.timeZoneOffsetSeconds) - const packableStructFields = [ - packer.packable(nanoOfDay), - packer.packable(offsetSeconds) - ] - packer.packStruct(TIME, packableStructFields) + return new v1.Structure(TIME, [nanoOfDay, offsetSeconds]) } /** @@ -340,11 +331,10 @@ function unpackTime ( * @param {Date} value the date value to pack. * @param {Packer} packer the packer to use. */ -function packDate (value, packer) { +function packDate (value) { const epochDay = dateToEpochDay(value.year, value.month, value.day) - const packableStructFields = [packer.packable(epochDay)] - packer.packStruct(DATE, packableStructFields) + return new v1.Structure(DATE, [epochDay]) } /** @@ -373,7 +363,7 @@ function unpackDate ( * @param {LocalDateTime} value the local date time value to pack. * @param {Packer} packer the packer to use. */ -function packLocalDateTime (value, packer) { +function packLocalDateTime (value) { const epochSecond = localDateTimeToEpochSecond( value.year, value.month, @@ -385,11 +375,7 @@ function packLocalDateTime (value, packer) { ) const nano = int(value.nanosecond) - const packableStructFields = [ - packer.packable(epochSecond), - packer.packable(nano) - ] - packer.packStruct(LOCAL_DATE_TIME, packableStructFields) + return new v1.Structure(LOCAL_DATE_TIME, [epochSecond, nano]) } /** @@ -422,11 +408,11 @@ function unpackLocalDateTime ( * @param {DateTime} value the date time value to pack. * @param {Packer} packer the packer to use. */ -function packDateTime (value, packer) { +function packDateTime (value) { if (value.timeZoneId) { - packDateTimeWithZoneId(value, packer) + packDateTimeWithZoneId(value) } else { - packDateTimeWithZoneOffset(value, packer) + packDateTimeWithZoneOffset(value) } } @@ -435,7 +421,7 @@ function packDateTime (value, packer) { * @param {DateTime} value the date time value to pack. * @param {Packer} packer the packer to use. */ -function packDateTimeWithZoneOffset (value, packer) { +function packDateTimeWithZoneOffset (value) { const epochSecond = localDateTimeToEpochSecond( value.year, value.month, @@ -447,13 +433,7 @@ function packDateTimeWithZoneOffset (value, packer) { ) const nano = int(value.nanosecond) const timeZoneOffsetSeconds = int(value.timeZoneOffsetSeconds) - - const packableStructFields = [ - packer.packable(epochSecond), - packer.packable(nano), - packer.packable(timeZoneOffsetSeconds) - ] - packer.packStruct(DATE_TIME_WITH_ZONE_OFFSET, packableStructFields) + return new v1.Structure(DATE_TIME_WITH_ZONE_OFFSET, [epochSecond, nano, timeZoneOffsetSeconds]) } /** @@ -498,7 +478,7 @@ function unpackDateTimeWithZoneOffset ( * @param {DateTime} value the date time value to pack. * @param {Packer} packer the packer to use. */ -function packDateTimeWithZoneId (value, packer) { +function packDateTimeWithZoneId (value) { const epochSecond = localDateTimeToEpochSecond( value.year, value.month, @@ -511,12 +491,7 @@ function packDateTimeWithZoneId (value, packer) { const nano = int(value.nanosecond) const timeZoneId = value.timeZoneId - const packableStructFields = [ - packer.packable(epochSecond), - packer.packable(nano), - packer.packable(timeZoneId) - ] - packer.packStruct(DATE_TIME_WITH_ZONE_ID, packableStructFields) + return new v1.Structure(DATE_TIME_WITH_ZONE_ID, [epochSecond, nano, timeZoneId]) } /** From 7bad794ac33d06916d26520a32fd903490cd23db Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Tue, 7 Jun 2022 17:22:44 +0200 Subject: [PATCH 03/18] fix packer --- .../src/bolt/bolt-protocol-v1.js | 20 ++++++++++++++++++- packages/bolt-connection/src/bolt/create.js | 2 +- .../src/packstream/packstream-v2.js | 4 ++-- .../bolt-connection/test/bolt/index.test.js | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v1.js b/packages/bolt-connection/src/bolt/bolt-protocol-v1.js index 55eec22e8..579fb4079 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v1.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v1.js @@ -97,6 +97,15 @@ export default class BoltProtocol { return this._packer } + /** + * Creates a packable function out of the provided value + * @param x the value to pack + * @returns Function + */ + packable (x) { + return this._packer.packable(x) + } + /** * Get the unpacker. * @return {Unpacker} the protocol's unpacker. @@ -105,6 +114,15 @@ export default class BoltProtocol { return this._unpacker } + /** + * Unpack a buffer + * @param {Buffer} buf + * @returns {any|null} The unpacked value + */ + unpack (buf) { + return this._unpacker.unpack(buf) + } + /** * Transform metadata received in SUCCESS message before it is passed to the handler. * @param {Object} metadata the received metadata. @@ -361,7 +379,7 @@ export default class BoltProtocol { this.packer().packStruct( message.signature, - message.fields.map(field => this.packer().packable(field)) + message.fields.map(field => this.packable(field)) ) this._chunker.messageBoundary() diff --git a/packages/bolt-connection/src/bolt/create.js b/packages/bolt-connection/src/bolt/create.js index c1e53d006..a3a323cd9 100644 --- a/packages/bolt-connection/src/bolt/create.js +++ b/packages/bolt-connection/src/bolt/create.js @@ -72,7 +72,7 @@ export default function create ({ // setup dechunker to dechunk messages and forward them to the message handler dechunker.onmessage = buf => { - responseHandler.handleResponse(protocol.unpacker().unpack(buf)) + responseHandler.handleResponse(protocol.unpack(buf)) } return responseHandler diff --git a/packages/bolt-connection/src/packstream/packstream-v2.js b/packages/bolt-connection/src/packstream/packstream-v2.js index b98669aa6..8be3d1067 100644 --- a/packages/bolt-connection/src/packstream/packstream-v2.js +++ b/packages/bolt-connection/src/packstream/packstream-v2.js @@ -410,9 +410,9 @@ function unpackLocalDateTime ( */ function packDateTime (value) { if (value.timeZoneId) { - packDateTimeWithZoneId(value) + return packDateTimeWithZoneId(value) } else { - packDateTimeWithZoneOffset(value) + return packDateTimeWithZoneOffset(value) } } diff --git a/packages/bolt-connection/test/bolt/index.test.js b/packages/bolt-connection/test/bolt/index.test.js index e1bc0fd94..cbed93f74 100644 --- a/packages/bolt-connection/test/bolt/index.test.js +++ b/packages/bolt-connection/test/bolt/index.test.js @@ -266,7 +266,7 @@ describe('#unit Bolt', () => { protocol.packer().packStruct( expectedMessage.signature, - expectedMessage.fields.map(field => protocol.packer().packable(field)) + expectedMessage.fields.map(field => protocol.packable(field)) ) params.chunker.messageBoundary() params.chunker.flush() From 67ef8fb457f19f12ce25c111fb30094509d7afbf Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Tue, 7 Jun 2022 18:16:53 +0200 Subject: [PATCH 04/18] fix point packer --- packages/bolt-connection/src/packstream/packstream-v2.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bolt-connection/src/packstream/packstream-v2.js b/packages/bolt-connection/src/packstream/packstream-v2.js index 8be3d1067..569bc667c 100644 --- a/packages/bolt-connection/src/packstream/packstream-v2.js +++ b/packages/bolt-connection/src/packstream/packstream-v2.js @@ -151,9 +151,9 @@ export class Unpacker extends v1.Unpacker { function packPoint (point) { const is2DPoint = point.z === null || point.z === undefined if (is2DPoint) { - packPoint2D(point) + return packPoint2D(point) } else { - packPoint3D(point) + return packPoint3D(point) } } From 0e4cdee577f4f5c0dc809dead541c6eb7e413aac Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Wed, 8 Jun 2022 12:04:38 +0200 Subject: [PATCH 05/18] Extracting type transformation from packstream --- .../src/bolt/bolt-protocol-v1.js | 14 +- .../src/bolt/bolt-protocol-v1.transformer.js | 164 ++++++ .../src/bolt/bolt-protocol-v2.js | 9 + .../src/bolt/bolt-protocol-v2.transformer.js | 365 +++++++++++++ .../src/bolt/bolt-protocol-v3.js | 9 + .../src/bolt/bolt-protocol-v3.transformer.js | 20 + .../src/bolt/bolt-protocol-v4x0.js | 9 + .../bolt/bolt-protocol-v4x0.transformer.js | 20 + .../src/bolt/bolt-protocol-v4x1.js | 10 + .../bolt/bolt-protocol-v4x1.transformer.js | 20 + .../src/bolt/bolt-protocol-v4x2.js | 10 + .../bolt/bolt-protocol-v4x2.transformer.js | 20 + .../src/bolt/bolt-protocol-v4x3.js | 10 + .../bolt/bolt-protocol-v4x3.transformer.js | 20 + .../src/bolt/bolt-protocol-v4x4.js | 10 + .../bolt/bolt-protocol-v4x4.transformer.js | 20 + .../src/bolt/bolt-protocol-v5x0.js | 15 +- .../bolt/bolt-protocol-v5x0.transformer.js | 109 ++++ .../{packstream => bolt}/temporal-factory.js | 0 .../bolt-connection/src/bolt/transformer.js | 66 +++ .../bolt-connection/src/lang/functional.js | 30 + packages/bolt-connection/src/lang/index.js | 20 + .../bolt-connection/src/packstream/index.js | 3 +- .../src/packstream/packstream-v1.js | 252 ++------- .../src/packstream/packstream-v2.js | 514 ------------------ .../src/packstream/structure.js | 59 ++ .../test/bolt/bolt-protocol-v5x0.test.js | 10 +- .../test/packstream/packstream-v5.test.js | 2 +- 28 files changed, 1084 insertions(+), 726 deletions(-) create mode 100644 packages/bolt-connection/src/bolt/bolt-protocol-v1.transformer.js create mode 100644 packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js create mode 100644 packages/bolt-connection/src/bolt/bolt-protocol-v3.transformer.js create mode 100644 packages/bolt-connection/src/bolt/bolt-protocol-v4x0.transformer.js create mode 100644 packages/bolt-connection/src/bolt/bolt-protocol-v4x1.transformer.js create mode 100644 packages/bolt-connection/src/bolt/bolt-protocol-v4x2.transformer.js create mode 100644 packages/bolt-connection/src/bolt/bolt-protocol-v4x3.transformer.js create mode 100644 packages/bolt-connection/src/bolt/bolt-protocol-v4x4.transformer.js create mode 100644 packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js rename packages/bolt-connection/src/{packstream => bolt}/temporal-factory.js (100%) create mode 100644 packages/bolt-connection/src/bolt/transformer.js create mode 100644 packages/bolt-connection/src/lang/functional.js create mode 100644 packages/bolt-connection/src/lang/index.js create mode 100644 packages/bolt-connection/src/packstream/structure.js diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v1.js b/packages/bolt-connection/src/bolt/bolt-protocol-v1.js index 579fb4079..4f8711d98 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v1.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v1.js @@ -33,6 +33,8 @@ import { StreamObserver } from './stream-observers' import { internal } from 'neo4j-driver-core' +import * as transformersFactories from './bolt-protocol-v1.transformer' +import Transformer from './transformer' const { bookmarks: { Bookmarks }, @@ -80,6 +82,14 @@ export default class BoltProtocol { this._onProtocolError = onProtocolError this._fatalError = null this._lastMessageSignature = null + this._config = { disableLosslessIntegers, useBigInt } + } + + get transformer () { + if (this._transformer === undefined) { + this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config))) + } + return this._transformer } /** @@ -103,7 +113,7 @@ export default class BoltProtocol { * @returns Function */ packable (x) { - return this._packer.packable(x) + return this._packer.packable(x, this.transformer.toStructure) } /** @@ -120,7 +130,7 @@ export default class BoltProtocol { * @returns {any|null} The unpacked value */ unpack (buf) { - return this._unpacker.unpack(buf) + return this._unpacker.unpack(buf, this.transformer.fromStructure) } /** diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v1.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v1.transformer.js new file mode 100644 index 000000000..dcffea9af --- /dev/null +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v1.transformer.js @@ -0,0 +1,164 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + Node, + newError, + error, + Relationship, + UnboundRelationship, + Path, + toNumber, + PathSegment +} from 'neo4j-driver-core' + +import { structure } from '../packstream' +import { TypeTransformer } from './transformer' + +const { PROTOCOL_ERROR } = error + +const NODE = 0x4e +const NODE_STRUCT_SIZE = 3 + +const RELATIONSHIP = 0x52 +const RELATIONSHIP_STRUCT_SIZE = 5 + +const UNBOUND_RELATIONSHIP = 0x72 +const UNBOUND_RELATIONSHIP_STRUCT_SIZE = 3 + +const PATH = 0x50 +const PATH_STRUCT_SIZE = 3 + +export function createNodeTransformer () { + return new TypeTransformer({ + signature: NODE, + isTypeInstance: object => object instanceof Node, + toStructure: object => { + throw newError( + `It is not allowed to pass nodes in query parameters, given: ${object}`, + PROTOCOL_ERROR + ) + }, + fromStructure: struct => { + structure.verifyStructSize('Node', NODE_STRUCT_SIZE, struct.size) + + const [identity, labels, properties] = struct.fields + + return new Node(identity, labels, properties) + } + }) +} + +export function createRelationshipTransformer () { + return new TypeTransformer({ + signature: RELATIONSHIP, + isTypeInstance: object => object instanceof Relationship, + toStructure: object => { + throw newError( + `It is not allowed to pass relationships in query parameters, given: ${object}`, + PROTOCOL_ERROR + ) + }, + fromStructure: struct => { + structure.verifyStructSize('Relationship', RELATIONSHIP_STRUCT_SIZE, struct.size) + + const [identity, startNodeIdentity, endNodeIdentity, type, properties] = struct.fields + + return new Relationship(identity, startNodeIdentity, endNodeIdentity, type, properties) + } + }) +} + +export function createUnboundRelationshipTransformer () { + return new TypeTransformer({ + signature: UNBOUND_RELATIONSHIP, + isTypeInstance: object => object instanceof UnboundRelationship, + toStructure: object => { + throw newError( + `It is not allowed to pass unbound relationships in query parameters, given: ${object}`, + PROTOCOL_ERROR + ) + }, + fromStructure: struct => { + structure.verifyStructSize( + 'UnboundRelationship', + UNBOUND_RELATIONSHIP_STRUCT_SIZE, + struct.size + ) + + const [identity, type, properties] = struct.fields + + return new UnboundRelationship(identity, type, properties) + } + }) +} + +export function createPathTransformer () { + return new TypeTransformer({ + signature: PATH, + isTypeInstance: object => object instanceof Path, + toStructure: object => { + throw newError( + `It is not allowed to pass paths in query parameters, given: ${object}`, + PROTOCOL_ERROR + ) + }, + fromStructure: struct => { + structure.verifyStructSize('Path', PATH_STRUCT_SIZE, struct.size) + + const [nodes, rels, sequence] = struct.fields + + const segments = [] + let prevNode = nodes[0] + + for (let i = 0; i < sequence.length; i += 2) { + const nextNode = nodes[sequence[i + 1]] + const relIndex = toNumber(sequence[i]) + let rel + + if (relIndex > 0) { + rel = rels[relIndex - 1] + if (rel instanceof UnboundRelationship) { + // To avoid duplication, relationships in a path do not contain + // information about their start and end nodes, that's instead + // inferred from the path sequence. This is us inferring (and, + // for performance reasons remembering) the start/end of a rel. + rels[relIndex - 1] = rel = rel.bindTo( + prevNode, + nextNode + ) + } + } else { + rel = rels[-relIndex - 1] + if (rel instanceof UnboundRelationship) { + // See above + rels[-relIndex - 1] = rel = rel.bindTo( + nextNode, + prevNode + ) + } + } + // Done hydrating one path segment. + segments.push(new PathSegment(prevNode, rel, nextNode)) + prevNode = nextNode + } + return new Path(nodes[0], nodes[nodes.length - 1], segments) + } + }) +} diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v2.js b/packages/bolt-connection/src/bolt/bolt-protocol-v2.js index 13d007d87..45b8b3244 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v2.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v2.js @@ -19,6 +19,8 @@ import BoltProtocolV1 from './bolt-protocol-v1' import v2 from '../packstream' import { internal } from 'neo4j-driver-core' +import * as transformersFactories from './bolt-protocol-v2.transformer' +import Transformer from './transformer' const { constants: { BOLT_PROTOCOL_V2 } @@ -33,6 +35,13 @@ export default class BoltProtocol extends BoltProtocolV1 { return new v2.Unpacker(disableLosslessIntegers, useBigInt) } + get transformer () { + if (this._transformer === undefined) { + this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config))) + } + return this._transformer + } + get version () { return BOLT_PROTOCOL_V2 } diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js new file mode 100644 index 000000000..ede5ae1af --- /dev/null +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js @@ -0,0 +1,365 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + isPoint, + int, + isDuration, + Duration, + isLocalDateTime, + isLocalTime, + internal, + isTime, + Time, + isDate, + isDateTime, + DateTime, + Point, + isInt +} from 'neo4j-driver-core' + +import { structure } from '../packstream' +import { TypeTransformer } from './transformer' + +import { + epochDayToDate, + nanoOfDayToLocalTime, + epochSecondAndNanoToLocalDateTime +} from './temporal-factory' + +export * from './bolt-protocol-v1.transformer' + +const { + temporalUtil: { + dateToEpochDay, + localDateTimeToEpochSecond, + localTimeToNanoOfDay + } +} = internal + +const POINT_2D = 0x58 +const POINT_2D_STRUCT_SIZE = 3 + +const POINT_3D = 0x59 +const POINT_3D_STRUCT_SIZE = 4 + +const DURATION = 0x45 +const DURATION_STRUCT_SIZE = 4 + +const LOCAL_TIME = 0x74 +const LOCAL_TIME_STRUCT_SIZE = 1 + +const TIME = 0x54 +const TIME_STRUCT_SIZE = 2 + +const DATE = 0x44 +const DATE_STRUCT_SIZE = 1 + +const LOCAL_DATE_TIME = 0x64 +const LOCAL_DATE_TIME_STRUCT_SIZE = 2 + +const DATE_TIME_WITH_ZONE_OFFSET = 0x46 +const DATE_TIME_WITH_ZONE_OFFSET_STRUCT_SIZE = 3 + +const DATE_TIME_WITH_ZONE_ID = 0x66 +const DATE_TIME_WITH_ZONE_ID_STRUCT_SIZE = 3 + +export function createPoint2DTransformer () { + return new TypeTransformer({ + signature: POINT_2D, + isTypeInstance: point => isPoint(point) && (point.z === null || point.z === undefined), + toStructure: point => new structure.Structure(POINT_2D, [ + int(point.srid), + point.x, + point.y + ]), + fromStructure: struct => { + structure.verifyStructSize('Point2D', POINT_2D_STRUCT_SIZE, struct.size) + + const [srid, x, y] = struct.fields + return new Point( + srid, + x, + y, + undefined // z + ) + } + }) +} + +export function createPoint3DTransformer () { + return new TypeTransformer({ + signature: POINT_3D, + isTypeInstance: point => isPoint(point) && point.z !== null && point.z !== undefined, + toStructure: point => new structure.Structure(POINT_3D, [ + int(point.srid), + point.x, + point.y, + point.z + ]), + fromStructure: struct => { + structure.verifyStructSize('Point3D', POINT_3D_STRUCT_SIZE, struct.size) + + const [srid, x, y, z] = struct.fields + return new Point( + srid, + x, + y, + z + ) + } + }) +} + +export function createDurationTransformer () { + return new TypeTransformer({ + signature: DURATION, + isTypeInstance: isDuration, + toStructure: value => { + const months = int(value.months) + const days = int(value.days) + const seconds = int(value.seconds) + const nanoseconds = int(value.nanoseconds) + + return new structure.Structure(DURATION, [months, days, seconds, nanoseconds]) + }, + fromStructure: struct => { + structure.verifyStructSize('Duration', DURATION_STRUCT_SIZE, struct.size) + + const [months, days, seconds, nanoseconds] = struct.fields + + return new Duration(months, days, seconds, nanoseconds) + } + }) +} + +export function createLocalTimeTransformer ({ disableLosslessIntegers, useBigInt }) { + return new TypeTransformer({ + signature: LOCAL_TIME, + isTypeInstance: isLocalTime, + toStructure: value => { + const nanoOfDay = localTimeToNanoOfDay( + value.hour, + value.minute, + value.second, + value.nanosecond + ) + + return new structure.Structure(LOCAL_TIME, [nanoOfDay]) + }, + fromStructure: struct => { + structure.verifyStructSize('LocalTime', LOCAL_TIME_STRUCT_SIZE, struct.size) + + const [nanoOfDay] = struct.fields + const result = nanoOfDayToLocalTime(nanoOfDay) + return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) + } + }) +} + +export function createTimeTransformer ({ disableLosslessIntegers, useBigInt }) { + return new TypeTransformer({ + signature: TIME, + isTypeInstance: isTime, + toStructure: value => { + const nanoOfDay = localTimeToNanoOfDay( + value.hour, + value.minute, + value.second, + value.nanosecond + ) + const offsetSeconds = int(value.timeZoneOffsetSeconds) + + return new structure.Structure(TIME, [nanoOfDay, offsetSeconds]) + }, + fromStructure: struct => { + structure.verifyStructSize('Time', TIME_STRUCT_SIZE, struct.size) + + const [nanoOfDay, offsetSeconds] = struct.fields + const localTime = nanoOfDayToLocalTime(nanoOfDay) + const result = new Time( + localTime.hour, + localTime.minute, + localTime.second, + localTime.nanosecond, + offsetSeconds + ) + return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) + } + }) +} + +export function createDateTransformer ({ disableLosslessIntegers, useBigInt }) { + return new TypeTransformer({ + signature: DATE, + isTypeInstance: isDate, + toStructure: value => { + const epochDay = dateToEpochDay(value.year, value.month, value.day) + + return new structure.Structure(DATE, [epochDay]) + }, + fromStructure: struct => { + structure.verifyStructSize('Date', DATE_STRUCT_SIZE, struct.size) + + const [epochDay] = struct.fields + const result = epochDayToDate(epochDay) + return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) + } + }) +} + +export function createLocalDateTime ({ disableLosslessIntegers, useBigInt }) { + return new TypeTransformer({ + signature: LOCAL_DATE_TIME, + isTypeInstance: isLocalDateTime, + toStructure: value => { + const epochSecond = localDateTimeToEpochSecond( + value.year, + value.month, + value.day, + value.hour, + value.minute, + value.second, + value.nanosecond + ) + const nano = int(value.nanosecond) + + return new structure.Structure(LOCAL_DATE_TIME, [epochSecond, nano]) + }, + fromStructure: struct => { + structure.verifyStructSize( + 'LocalDateTime', + LOCAL_DATE_TIME_STRUCT_SIZE, + struct.size + ) + + const [epochSecond, nano] = struct.fields + const result = epochSecondAndNanoToLocalDateTime(epochSecond, nano) + return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) + } + }) +} + +export function createDateTimeWithZoneId ({ disableLosslessIntegers, useBigInt }) { + return new TypeTransformer({ + signature: DATE_TIME_WITH_ZONE_ID, + isTypeInstance: object => isDateTime(object) && object.timeZoneId != null, + toStructure: value => { + const epochSecond = localDateTimeToEpochSecond( + value.year, + value.month, + value.day, + value.hour, + value.minute, + value.second, + value.nanosecond + ) + const nano = int(value.nanosecond) + const timeZoneId = value.timeZoneId + + return new structure.Structure(DATE_TIME_WITH_ZONE_ID, [epochSecond, nano, timeZoneId]) + }, + fromStructure: struct => { + structure.verifyStructSize( + 'DateTimeWithZoneId', + DATE_TIME_WITH_ZONE_ID_STRUCT_SIZE, + struct.size + ) + + const [epochSecond, nano, timeZoneId] = struct.fields + + const localDateTime = epochSecondAndNanoToLocalDateTime(epochSecond, nano) + const result = new DateTime( + localDateTime.year, + localDateTime.month, + localDateTime.day, + localDateTime.hour, + localDateTime.minute, + localDateTime.second, + localDateTime.nanosecond, + null, + timeZoneId + ) + return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) + } + }) +} + +export function createDateTimeWithOffset ({ disableLosslessIntegers, useBigInt }) { + return new TypeTransformer({ + signature: DATE_TIME_WITH_ZONE_OFFSET, + isTypeInstance: object => isDateTime(object) && object.timeZoneId == null, + toStructure: value => { + const epochSecond = localDateTimeToEpochSecond( + value.year, + value.month, + value.day, + value.hour, + value.minute, + value.second, + value.nanosecond + ) + const nano = int(value.nanosecond) + const timeZoneOffsetSeconds = int(value.timeZoneOffsetSeconds) + return new structure.Structure(DATE_TIME_WITH_ZONE_OFFSET, [epochSecond, nano, timeZoneOffsetSeconds]) + }, + fromStructure: struct => { + struct.verifyStructSize( + 'DateTimeWithZoneOffset', + DATE_TIME_WITH_ZONE_OFFSET_STRUCT_SIZE, + struct.size + ) + + const [epochSecond, nano, timeZoneOffsetSeconds] = struct.fields + + const localDateTime = epochSecondAndNanoToLocalDateTime(epochSecond, nano) + const result = new DateTime( + localDateTime.year, + localDateTime.month, + localDateTime.day, + localDateTime.hour, + localDateTime.minute, + localDateTime.second, + localDateTime.nanosecond, + timeZoneOffsetSeconds, + null + ) + return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) + } + }) +} + +function convertIntegerPropsIfNeeded (obj, disableLosslessIntegers, useBigInt) { + if (!disableLosslessIntegers && !useBigInt) { + return obj + } + + const convert = value => + useBigInt ? value.toBigInt() : value.toNumberOrInfinity() + + const clone = Object.create(Object.getPrototypeOf(obj)) + for (const prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop) === true) { + const value = obj[prop] + clone[prop] = isInt(value) ? convert(value) : value + } + } + Object.freeze(clone) + return clone +} diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v3.js b/packages/bolt-connection/src/bolt/bolt-protocol-v3.js index a4fbe3d66..488845884 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v3.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v3.js @@ -25,6 +25,8 @@ import { ResultStreamObserver, ProcedureRouteObserver } from './stream-observers' +import * as transformersFactories from './bolt-protocol-v3.transformer' +import Transformer from './transformer' import { internal } from 'neo4j-driver-core' const { @@ -44,6 +46,13 @@ export default class BoltProtocol extends BoltProtocolV2 { return BOLT_PROTOCOL_V3 } + get transformer () { + if (this._transformer === undefined) { + this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config))) + } + return this._transformer + } + transformMetadata (metadata) { if ('t_first' in metadata) { // Bolt V3 uses shorter key 't_first' to represent 'result_available_after' diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v3.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v3.transformer.js new file mode 100644 index 000000000..14cf92823 --- /dev/null +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v3.transformer.js @@ -0,0 +1,20 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './bolt-protocol-v2.transformer' diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.js index 834faf415..3a6930bea 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.js @@ -23,6 +23,8 @@ import { ResultStreamObserver, ProcedureRouteObserver } from './stream-observers' +import * as transformersFactories from './bolt-protocol-v4x0.transformer' +import Transformer from './transformer' import { internal } from 'neo4j-driver-core' @@ -42,6 +44,13 @@ export default class BoltProtocol extends BoltProtocolV3 { return BOLT_PROTOCOL_V4_0 } + get transformer () { + if (this._transformer === undefined) { + this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config))) + } + return this._transformer + } + beginTransaction ({ bookmarks, txConfig, diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.transformer.js new file mode 100644 index 000000000..a3995a83c --- /dev/null +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.transformer.js @@ -0,0 +1,20 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './bolt-protocol-v3.transformer' diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.js index 55ad99c8f..c0894397a 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.js @@ -21,6 +21,9 @@ import RequestMessage from './request-message' import { LoginObserver } from './stream-observers' import { internal } from 'neo4j-driver-core' +import * as transformersFactories from './bolt-protocol-v4x1.transformer' +import Transformer from './transformer' + const { constants: { BOLT_PROTOCOL_V4_1 } } = internal @@ -62,6 +65,13 @@ export default class BoltProtocol extends BoltProtocolV4 { return BOLT_PROTOCOL_V4_1 } + get transformer () { + if (this._transformer === undefined) { + this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config))) + } + return this._transformer + } + initialize ({ userAgent, authToken, onError, onComplete } = {}) { const observer = new LoginObserver({ onError: error => this._onLoginError(error, onError), diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.transformer.js new file mode 100644 index 000000000..9ea46a1a5 --- /dev/null +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.transformer.js @@ -0,0 +1,20 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './bolt-protocol-v4x0.transformer' diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.js index 3f1fbd70b..de0050566 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.js @@ -20,6 +20,9 @@ import BoltProtocolV41 from './bolt-protocol-v4x1' import { internal } from 'neo4j-driver-core' +import * as transformersFactories from './bolt-protocol-v4x2.transformer' +import Transformer from './transformer' + const { constants: { BOLT_PROTOCOL_V4_2 } } = internal @@ -28,4 +31,11 @@ export default class BoltProtocol extends BoltProtocolV41 { get version () { return BOLT_PROTOCOL_V4_2 } + + get transformer () { + if (this._transformer === undefined) { + this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config))) + } + return this._transformer + } } diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.transformer.js new file mode 100644 index 000000000..251d5f32f --- /dev/null +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.transformer.js @@ -0,0 +1,20 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './bolt-protocol-v4x1.transformer' diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.js index 379a69249..d4bf22009 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.js @@ -20,6 +20,9 @@ import BoltProtocolV42 from './bolt-protocol-v4x2' import RequestMessage from './request-message' import { RouteObserver } from './stream-observers' +import * as transformersFactories from './bolt-protocol-v4x3.transformer' +import Transformer from './transformer' + import { internal } from 'neo4j-driver-core' const { @@ -32,6 +35,13 @@ export default class BoltProtocol extends BoltProtocolV42 { return BOLT_PROTOCOL_V4_3 } + get transformer () { + if (this._transformer === undefined) { + this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config))) + } + return this._transformer + } + /** * Request routing information * diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.transformer.js new file mode 100644 index 000000000..3849b5670 --- /dev/null +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.transformer.js @@ -0,0 +1,20 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './bolt-protocol-v4x2.transformer' diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.js index 634edbf82..bedc01731 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.js @@ -22,6 +22,9 @@ import { internal } from 'neo4j-driver-core' import RequestMessage from './request-message' import { RouteObserver, ResultStreamObserver } from './stream-observers' +import * as transformersFactories from './bolt-protocol-v4x4.transformer' +import Transformer from './transformer' + const { constants: { BOLT_PROTOCOL_V4_4, FETCH_ALL }, bookmarks: { Bookmarks } @@ -32,6 +35,13 @@ export default class BoltProtocol extends BoltProtocolV43 { return BOLT_PROTOCOL_V4_4 } + get transformer () { + if (this._transformer === undefined) { + this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config))) + } + return this._transformer + } + /** * Request routing information * diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.transformer.js new file mode 100644 index 000000000..b8f9b8872 --- /dev/null +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.transformer.js @@ -0,0 +1,20 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from './bolt-protocol-v4x3.transformer' diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js index c4e3e4d93..bfe6292ce 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js @@ -17,7 +17,9 @@ * limitations under the License. */ import BoltProtocolV44 from './bolt-protocol-v4x4' -import { v5 } from '../packstream' + +import * as transformersFactories from './bolt-protocol-v5x0.transformer' +import Transformer from './transformer' import { internal } from 'neo4j-driver-core' @@ -30,11 +32,10 @@ export default class BoltProtocol extends BoltProtocolV44 { return BOLT_PROTOCOL_V5_0 } - _createPacker (chunker) { - return new v5.Packer(chunker) - } - - _createUnpacker (disableLosslessIntegers, useBigInt) { - return new v5.Unpacker(disableLosslessIntegers, useBigInt) + get transformer () { + if (this._transformer === undefined) { + this._transformer = new Transformer([...transformersFactories].map(create => create(this._config))) + } + return this._transformer } } diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js new file mode 100644 index 000000000..2a794cf19 --- /dev/null +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js @@ -0,0 +1,109 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { structure } from '../packstream' +import { Node, Relationship, UnboundRelationship } from 'neo4j-driver-core' +import * as v4x4 from './bolt-protocol-v4x4.transformer' + +const NODE_STRUCT_SIZE = 4 +const RELATIONSHIP_STRUCT_SIZE = 8 +const UNBOUND_RELATIONSHIP_STRUCT_SIZE = 4 + +function createNodeTransformer (config) { + const node4x4Transformer = v4x4.createNodeTransformer(config) + return node4x4Transformer.extendsWith({ + toStructure: struct => { + structure.verifyStructSize('Node', NODE_STRUCT_SIZE, struct) + + const [identity, lables, properties, elementId] = struct.fields + + return new Node( + identity, + lables, + properties, + elementId + ) + } + }) +} + +function createRelationshipTransformer (config) { + const relationship4x4Transformer = v4x4.createRelationshipTransformer(config) + return relationship4x4Transformer.extendsWith({ + toStructure: struct => { + structure.verifyStructSize('Relationship', RELATIONSHIP_STRUCT_SIZE, structure.size) + + const [ + identity, + startNodeIdentity, + endNodeIdentity, + type, + properties, + elementId, + startNodeElementId, + endNodeElementId + ] = struct.fields + + return new Relationship( + identity, + startNodeIdentity, + endNodeIdentity, + type, + properties, + elementId, + startNodeElementId, + endNodeElementId + ) + } + }) +} + +function createUnboundRelationshipTransformer (config) { + const unboundRelationshipTransformer = v4x4.createUnboundRelationshipTransformer(config) + return unboundRelationshipTransformer.extendsWith({ + toStructure: struct => { + this._verifyStructSize( + 'UnboundRelationship', + UNBOUND_RELATIONSHIP_STRUCT_SIZE, + struct.size + ) + + const [ + identity, + type, + properties, + elementId + ] = struct.fields + + return new UnboundRelationship( + identity, + type, + properties, + elementId + ) + } + }) +} + +module.exports = { + ...v4x4, + createNodeTransformer, + createRelationshipTransformer, + createUnboundRelationshipTransformer +} diff --git a/packages/bolt-connection/src/packstream/temporal-factory.js b/packages/bolt-connection/src/bolt/temporal-factory.js similarity index 100% rename from packages/bolt-connection/src/packstream/temporal-factory.js rename to packages/bolt-connection/src/bolt/temporal-factory.js diff --git a/packages/bolt-connection/src/bolt/transformer.js b/packages/bolt-connection/src/bolt/transformer.js new file mode 100644 index 000000000..050a188b5 --- /dev/null +++ b/packages/bolt-connection/src/bolt/transformer.js @@ -0,0 +1,66 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { structure } from '../packstream' + +export default class Transformer { + constructor (transformers) { + this._transformers = transformers + this._transformersPerSignature = new Map(transformers.map(typeTransformer => [typeTransformer.signature, typeTransformer])) + this.fromStructure = this.fromStructure.bind(this) + this.toStructure = this.toStructure.bind(this) + Object.freeze(this) + } + + fromStructure (struct) { + if (struct instanceof structure.Structure && this._transformersPerSignature.has(struct.signature)) { + const { fromStructure } = this._transformersPerSignature[struct.signature] + return fromStructure(struct) + } + return struct + } + + toStructure (type) { + const transformer = this._transformers.find(({ isTypeInstance }) => isTypeInstance(type)) + if (transformer !== undefined) { + return transformer.toStructure(type) + } + return type + } +} + +export class TypeTransformer { + constructor ({ signature, fromStructure, toStructure, isTypeInstance }) { + this.signature = signature + this.isTypeInstance = isTypeInstance + this.fromStructure = fromStructure + this.toStructure = toStructure + + Object.freeze(this) + } + + extendsWith ({ signature, fromStructure, toStructure, isTypeInstance }) { + return new TypeTransformer({ + signature: signature || this.signature, + fromStructure: fromStructure || this.fromStructure, + toStructure: toStructure || this.toStructure, + isTypeInstance: isTypeInstance || this.isTypeInstance + }) + } +} diff --git a/packages/bolt-connection/src/lang/functional.js b/packages/bolt-connection/src/lang/functional.js new file mode 100644 index 000000000..24aa87184 --- /dev/null +++ b/packages/bolt-connection/src/lang/functional.js @@ -0,0 +1,30 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Identity function. + * + * Identity functions are function which returns the input as output. + * + * @param {any} x + * @returns {any} the x + */ +export function identity (x) { + return x +} diff --git a/packages/bolt-connection/src/lang/index.js b/packages/bolt-connection/src/lang/index.js new file mode 100644 index 000000000..9d565fe8f --- /dev/null +++ b/packages/bolt-connection/src/lang/index.js @@ -0,0 +1,20 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * as functional from './functional' diff --git a/packages/bolt-connection/src/packstream/index.js b/packages/bolt-connection/src/packstream/index.js index 564c32001..371da8003 100644 --- a/packages/bolt-connection/src/packstream/index.js +++ b/packages/bolt-connection/src/packstream/index.js @@ -20,7 +20,8 @@ import * as v1 from './packstream-v1' import * as v2 from './packstream-v2' import * as v5 from './packstream-v5' +import * as structure from './structure' -export { v1, v2, v5 } +export { v1, v2, v5, structure } export default v2 diff --git a/packages/bolt-connection/src/packstream/packstream-v1.js b/packages/bolt-connection/src/packstream/packstream-v1.js index ddcb0dee1..d55895989 100644 --- a/packages/bolt-connection/src/packstream/packstream-v1.js +++ b/packages/bolt-connection/src/packstream/packstream-v1.js @@ -17,18 +17,14 @@ * limitations under the License. */ import { utf8 } from '../channel' +import { functional } from '../lang' +import { Structure } from './structure' import { newError, error, int, isInt, - Integer, - toNumber, - Node, - Path, - PathSegment, - Relationship, - UnboundRelationship + Integer } from 'neo4j-driver-core' const { PROTOCOL_ERROR } = error @@ -60,47 +56,6 @@ const MAP_32 = 0xda const STRUCT_8 = 0xdc const STRUCT_16 = 0xdd -const NODE = 0x4e -const NODE_STRUCT_SIZE = 3 - -const RELATIONSHIP = 0x52 -const RELATIONSHIP_STRUCT_SIZE = 5 - -const UNBOUND_RELATIONSHIP = 0x72 -const UNBOUND_RELATIONSHIP_STRUCT_SIZE = 3 - -const PATH = 0x50 -const PATH_STRUCT_SIZE = 3 - -/** - * A Structure have a signature and fields. - * @access private - */ -class Structure { - /** - * Create new instance - */ - constructor (signature, fields) { - this.signature = signature - this.fields = fields - } - - get size () { - return this.fields.length - } - - toString () { - let fieldStr = '' - for (let i = 0; i < this.fields.length; i++) { - if (i > 0) { - fieldStr += ', ' - } - fieldStr += this.fields[i] - } - return 'Structure(' + this.signature + ', [' + fieldStr + '])' - } -} - /** * Class to pack * @access private @@ -120,8 +75,13 @@ class Packer { * @param x the value to pack * @returns Function */ - packable (x, dehydrate = (x) => x) { - x = dehydrate(x) + packable (x, dehydrate = functional.identity) { + try { + x = dehydrate(x) + } catch (ex) { + return () => ex + } + if (x === null) { return () => this._ch.writeUInt8(NULL) } else if (x === true) { @@ -147,18 +107,6 @@ class Packer { } } else if (isIterable(x)) { return this.packableIterable(x) - } else if (x instanceof Node) { - return this._nonPackableValue( - `It is not allowed to pass nodes in query parameters, given: ${x}` - ) - } else if (x instanceof Relationship) { - return this._nonPackableValue( - `It is not allowed to pass relationships in query parameters, given: ${x}` - ) - } else if (x instanceof Path) { - return this._nonPackableValue( - `It is not allowed to pass paths in query parameters, given: ${x}` - ) } else if (x instanceof Structure) { const packableFields = [] for (let i = 0; i < x.fields.length; i++) { @@ -383,58 +331,63 @@ class Unpacker { this._useBigInt = useBigInt } - unpack (buffer) { - const marker = buffer.readUInt8() - const markerHigh = marker & 0xf0 - const markerLow = marker & 0x0f + unpack (buffer, hydrate = functional.identity) { + const deserialize = () => { + const marker = buffer.readUInt8() + const markerHigh = marker & 0xf0 + const markerLow = marker & 0x0f - if (marker === NULL) { - return null - } + if (marker === NULL) { + return null + } - const boolean = this._unpackBoolean(marker) - if (boolean !== null) { - return boolean - } + const boolean = this._unpackBoolean(marker) + if (boolean !== null) { + return boolean + } - const numberOrInteger = this._unpackNumberOrInteger(marker, buffer) - if (numberOrInteger !== null) { - if (isInt(numberOrInteger)) { - if (this._useBigInt) { - return numberOrInteger.toBigInt() - } else if (this._disableLosslessIntegers) { - return numberOrInteger.toNumberOrInfinity() + const numberOrInteger = this._unpackNumberOrInteger(marker, buffer) + if (numberOrInteger !== null) { + if (isInt(numberOrInteger)) { + if (this._useBigInt) { + return numberOrInteger.toBigInt() + } else if (this._disableLosslessIntegers) { + return numberOrInteger.toNumberOrInfinity() + } } + return numberOrInteger } - return numberOrInteger - } - const string = this._unpackString(marker, markerHigh, markerLow, buffer) - if (string !== null) { - return string - } + const string = this._unpackString(marker, markerHigh, markerLow, buffer) + if (string !== null) { + return string + } - const list = this._unpackList(marker, markerHigh, markerLow, buffer) - if (list !== null) { - return list - } + const list = this._unpackList(marker, markerHigh, markerLow, buffer) + if (list !== null) { + return list + } - const byteArray = this._unpackByteArray(marker, buffer) - if (byteArray !== null) { - return byteArray - } + const byteArray = this._unpackByteArray(marker, buffer) + if (byteArray !== null) { + return byteArray + } - const map = this._unpackMap(marker, markerHigh, markerLow, buffer) - if (map !== null) { - return map - } + const map = this._unpackMap(marker, markerHigh, markerLow, buffer) + if (map !== null) { + return map + } - const struct = this._unpackStruct(marker, markerHigh, markerLow, buffer) - if (struct !== null) { - return struct + const struct = this._unpackStruct(marker, markerHigh, markerLow, buffer) + if (struct !== null) { + return struct + } + + throw newError('Unknown packed value with marker ' + marker.toString(16)) } - throw newError('Unknown packed value with marker ' + marker.toString(16)) + const deserialized = deserialize() + return hydrate(deserialized) } unpackInteger (buffer) { @@ -584,100 +537,7 @@ class Unpacker { for (let i = 0; i < structSize; i++) { structure.fields.push(this.unpack(buffer)) } - return this._hydrate(structure) - } - - _unpackNode (structure) { - this._verifyStructSize('Node', NODE_STRUCT_SIZE, structure.size) - - const [identity, labels, properties] = structure.fields - - return new Node(identity, labels, properties) - } - - _unpackRelationship (structure) { - this._verifyStructSize('Relationship', RELATIONSHIP_STRUCT_SIZE, structure.size) - - const [identity, startNodeIdentity, endNodeIdentity, type, properties] = structure.fields - - return new Relationship(identity, startNodeIdentity, endNodeIdentity, type, properties) - } - - _unpackUnboundRelationship (structure) { - this._verifyStructSize( - 'UnboundRelationship', - UNBOUND_RELATIONSHIP_STRUCT_SIZE, - structure.size - ) - - const [identity, type, properties] = structure.fields - - return new UnboundRelationship(identity, type, properties) - } - - _unpackPath (structure) { - this._verifyStructSize('Path', PATH_STRUCT_SIZE, structure.size) - - const [nodes, rels, sequence] = structure.fields - - const segments = [] - let prevNode = nodes[0] - - for (let i = 0; i < sequence.length; i += 2) { - const nextNode = nodes[sequence[i + 1]] - const relIndex = toNumber(sequence[i]) - let rel - - if (relIndex > 0) { - rel = rels[relIndex - 1] - if (rel instanceof UnboundRelationship) { - // To avoid duplication, relationships in a path do not contain - // information about their start and end nodes, that's instead - // inferred from the path sequence. This is us inferring (and, - // for performance reasons remembering) the start/end of a rel. - rels[relIndex - 1] = rel = rel.bindTo( - prevNode, - nextNode - ) - } - } else { - rel = rels[-relIndex - 1] - if (rel instanceof UnboundRelationship) { - // See above - rels[-relIndex - 1] = rel = rel.bindTo( - nextNode, - prevNode - ) - } - } - // Done hydrating one path segment. - segments.push(new PathSegment(prevNode, rel, nextNode)) - prevNode = nextNode - } - return new Path(nodes[0], nodes[nodes.length - 1], segments) - } - - _hydrate (structure, onUnknowStructure = struct => struct) { - if (structure.signature === NODE) { - return this._unpackNode(structure) - } else if (structure.signature === RELATIONSHIP) { - return this._unpackRelationship(structure) - } else if (structure.signature === UNBOUND_RELATIONSHIP) { - return this._unpackUnboundRelationship(structure) - } else if (structure.signature === PATH) { - return this._unpackPath(structure) - } else { - return onUnknowStructure(structure) - } - } - - _verifyStructSize (structName, expectedSize, actualSize) { - if (expectedSize !== actualSize) { - throw newError( - `Wrong struct size for ${structName}, expected ${expectedSize} but was ${actualSize}`, - PROTOCOL_ERROR - ) - } + return structure } } diff --git a/packages/bolt-connection/src/packstream/packstream-v2.js b/packages/bolt-connection/src/packstream/packstream-v2.js index 569bc667c..bbd3f0da5 100644 --- a/packages/bolt-connection/src/packstream/packstream-v2.js +++ b/packages/bolt-connection/src/packstream/packstream-v2.js @@ -18,90 +18,11 @@ */ import * as v1 from './packstream-v1' -import { - int, - isInt, - isPoint, - Point, - DateTime, - Duration, - isDate, - isDateTime, - isDuration, - isLocalDateTime, - isLocalTime, - isTime, - Time, - internal -} from 'neo4j-driver-core' - -import { - epochDayToDate, - epochSecondAndNanoToLocalDateTime, - nanoOfDayToLocalTime -} from './temporal-factory' - -const { - temporalUtil: { - dateToEpochDay, - localDateTimeToEpochSecond, - localTimeToNanoOfDay - } -} = internal - -const POINT_2D = 0x58 -const POINT_2D_STRUCT_SIZE = 3 - -const POINT_3D = 0x59 -const POINT_3D_STRUCT_SIZE = 4 - -const DURATION = 0x45 -const DURATION_STRUCT_SIZE = 4 - -const LOCAL_TIME = 0x74 -const LOCAL_TIME_STRUCT_SIZE = 1 - -const TIME = 0x54 -const TIME_STRUCT_SIZE = 2 - -const DATE = 0x44 -const DATE_STRUCT_SIZE = 1 - -const LOCAL_DATE_TIME = 0x64 -const LOCAL_DATE_TIME_STRUCT_SIZE = 2 - -const DATE_TIME_WITH_ZONE_OFFSET = 0x46 -const DATE_TIME_WITH_ZONE_OFFSET_STRUCT_SIZE = 3 - -const DATE_TIME_WITH_ZONE_ID = 0x66 -const DATE_TIME_WITH_ZONE_ID_STRUCT_SIZE = 3 export class Packer extends v1.Packer { disableByteArrays () { throw new Error('Bolt V2 should always support byte arrays') } - - packable (obj, dehydrate = (x) => x) { - return super.packable(obj, x => { - if (isPoint(x)) { - return packPoint(x) - } else if (isDuration(x)) { - return packDuration(x) - } else if (isLocalTime(x)) { - return packLocalTime(x) - } else if (isTime(x)) { - return packTime(x) - } else if (isDate(x)) { - return packDate(x) - } else if (isLocalDateTime(x)) { - return packLocalDateTime(x) - } else if (isDateTime(x)) { - return packDateTime(x) - } else { - return dehydrate(x) - } - }) - } } export class Unpacker extends v1.Unpacker { @@ -113,439 +34,4 @@ export class Unpacker extends v1.Unpacker { constructor (disableLosslessIntegers = false, useBigInt = false) { super(disableLosslessIntegers, useBigInt) } - - _hydrate (structure, onUnknowStructure = struct => struct) { - const verifyStructSize = this._verifyStructSize.bind(this) - return super._hydrate(structure, struct => { - const signature = struct.signature - if (signature === POINT_2D) { - return unpackPoint2D(verifyStructSize, struct) - } else if (signature === POINT_3D) { - return unpackPoint3D(verifyStructSize, struct) - } else if (signature === DURATION) { - return unpackDuration(verifyStructSize, struct) - } else if (signature === LOCAL_TIME) { - return unpackLocalTime(verifyStructSize, struct, this._disableLosslessIntegers, this._useBigInt) - } else if (signature === TIME) { - return unpackTime(verifyStructSize, struct, this._disableLosslessIntegers, this._useBigInt) - } else if (signature === DATE) { - return unpackDate(verifyStructSize, struct, this._disableLosslessIntegers, this._useBigInt) - } else if (signature === LOCAL_DATE_TIME) { - return unpackLocalDateTime(verifyStructSize, struct, this._disableLosslessIntegers, this._useBigInt) - } else if (signature === DATE_TIME_WITH_ZONE_OFFSET) { - return unpackDateTimeWithZoneOffset(verifyStructSize, struct, this._disableLosslessIntegers, this._useBigInt) - } else if (signature === DATE_TIME_WITH_ZONE_ID) { - return unpackDateTimeWithZoneId(verifyStructSize, struct, this._disableLosslessIntegers, this._useBigInt) - } else { - return onUnknowStructure(struct) - } - }) - } -} - -/** - * Pack given 2D or 3D point. - * @param {Point} point the point value to pack. - * @param {Packer} packer the packer to use. - */ -function packPoint (point) { - const is2DPoint = point.z === null || point.z === undefined - if (is2DPoint) { - return packPoint2D(point) - } else { - return packPoint3D(point) - } -} - -/** - * Pack given 2D point. - * @param {Point} point the point value to pack. - * @param {Packer} packer the packer to use. - */ -function packPoint2D (point) { - const fields = [ - int(point.srid), - point.x, - point.y - ] - return new v1.Structure(POINT_2D, fields) -} - -/** - * Pack given 3D point. - * @param {Point} point the point value to pack. - * @param {Packer} packer the packer to use. - */ -function packPoint3D (point) { - const fields = [ - int(point.srid), - point.x, - point.y, - point.z - ] - return new v1.Structure(POINT_3D, fields) -} - -/** - * Unpack 2D point value using the given unpacker. - * @param {Unpacker} unpacker the unpacker to use. - * @param {number} structSize the retrieved struct size. - * @param {BaseBuffer} buffer the buffer to unpack from. - * @return {Point} the unpacked 2D point value. - */ -function unpackPoint2D (verifyStructSize, struct) { - verifyStructSize('Point2D', POINT_2D_STRUCT_SIZE, struct.size) - - const [srid, x, y] = struct.fields - return new Point( - srid, - x, - y, - undefined // z - ) -} - -/** - * Unpack 3D point value using the given unpacker. - * @param {Unpacker} unpacker the unpacker to use. - * @param {number} structSize the retrieved struct size. - * @param {BaseBuffer} buffer the buffer to unpack from. - * @return {Point} the unpacked 3D point value. - */ -function unpackPoint3D (verifyStructSize, struct) { - verifyStructSize('Point3D', POINT_3D_STRUCT_SIZE, struct.size) - - const [srid, x, y, z] = struct.fields - - return new Point(srid, x, y, z) -} - -/** - * Pack given duration. - * @param {Duration} value the duration value to pack. - * @param {Packer} packer the packer to use. - */ -function packDuration (value) { - const months = int(value.months) - const days = int(value.days) - const seconds = int(value.seconds) - const nanoseconds = int(value.nanoseconds) - - return new v1.Structure(DURATION, [months, days, seconds, nanoseconds]) -} - -/** - * Unpack duration value using the given unpacker. - * @param {Unpacker} unpacker the unpacker to use. - * @param {number} structSize the retrieved struct size. - * @param {BaseBuffer} buffer the buffer to unpack from. - * @return {Duration} the unpacked duration value. - */ -function unpackDuration (verifyStructSize, struct) { - verifyStructSize('Duration', DURATION_STRUCT_SIZE, struct.size) - - const [months, days, seconds, nanoseconds] = struct.fields - - return new Duration(months, days, seconds, nanoseconds) -} - -/** - * Pack given local time. - * @param {LocalTime} value the local time value to pack. - * @param {Packer} packer the packer to use. - */ -function packLocalTime (value, packer) { - const nanoOfDay = localTimeToNanoOfDay( - value.hour, - value.minute, - value.second, - value.nanosecond - ) - - return new v1.Structure(LOCAL_TIME, [nanoOfDay]) -} - -/** - * Unpack local time value using the given unpacker. - * @param {Unpacker} unpacker the unpacker to use. - * @param {number} structSize the retrieved struct size. - * @param {BaseBuffer} buffer the buffer to unpack from. - * @param {boolean} disableLosslessIntegers if integer properties in the result local time should be native JS numbers. - * @return {LocalTime} the unpacked local time value. - */ -function unpackLocalTime (verifyStructSize, struct, disableLosslessIntegers, useBigInt) { - verifyStructSize('LocalTime', LOCAL_TIME_STRUCT_SIZE, struct.size) - - const [nanoOfDay] = struct.fields - const result = nanoOfDayToLocalTime(nanoOfDay) - return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) // check disable lossless -} - -/** - * Pack given time. - * @param {Time} value the time value to pack. - * @param {Packer} packer the packer to use. - */ -function packTime (value) { - const nanoOfDay = localTimeToNanoOfDay( - value.hour, - value.minute, - value.second, - value.nanosecond - ) - const offsetSeconds = int(value.timeZoneOffsetSeconds) - - return new v1.Structure(TIME, [nanoOfDay, offsetSeconds]) -} - -/** - * Unpack time value using the given unpacker. - * @param {Unpacker} unpacker the unpacker to use. - * @param {number} structSize the retrieved struct size. - * @param {BaseBuffer} buffer the buffer to unpack from. - * @param {boolean} disableLosslessIntegers if integer properties in the result time should be native JS numbers. - * @return {Time} the unpacked time value. - */ -function unpackTime ( - verifyStructSize, - struct, - disableLosslessIntegers, - useBigInt -) { - verifyStructSize('Time', TIME_STRUCT_SIZE, struct.size) - - const [nanoOfDay, offsetSeconds] = struct.fields - const localTime = nanoOfDayToLocalTime(nanoOfDay) - const result = new Time( - localTime.hour, - localTime.minute, - localTime.second, - localTime.nanosecond, - offsetSeconds - ) - return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) -} - -/** - * Pack given neo4j date. - * @param {Date} value the date value to pack. - * @param {Packer} packer the packer to use. - */ -function packDate (value) { - const epochDay = dateToEpochDay(value.year, value.month, value.day) - - return new v1.Structure(DATE, [epochDay]) -} - -/** - * Unpack neo4j date value using the given unpacker. - * @param {Unpacker} unpacker the unpacker to use. - * @param {number} structSize the retrieved struct size. - * @param {BaseBuffer} buffer the buffer to unpack from. - * @param {boolean} disableLosslessIntegers if integer properties in the result date should be native JS numbers. - * @return {Date} the unpacked neo4j date value. - */ -function unpackDate ( - verifyStructSize, - struct, - disableLosslessIntegers, - useBigInt -) { - verifyStructSize('Date', DATE_STRUCT_SIZE, struct.size) - - const [epochDay] = struct.fields - const result = epochDayToDate(epochDay) - return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) -} - -/** - * Pack given local date time. - * @param {LocalDateTime} value the local date time value to pack. - * @param {Packer} packer the packer to use. - */ -function packLocalDateTime (value) { - const epochSecond = localDateTimeToEpochSecond( - value.year, - value.month, - value.day, - value.hour, - value.minute, - value.second, - value.nanosecond - ) - const nano = int(value.nanosecond) - - return new v1.Structure(LOCAL_DATE_TIME, [epochSecond, nano]) -} - -/** - * Unpack local date time value using the given unpacker. - * @param {Unpacker} unpacker the unpacker to use. - * @param {number} structSize the retrieved struct size. - * @param {BaseBuffer} buffer the buffer to unpack from. - * @param {boolean} disableLosslessIntegers if integer properties in the result local date-time should be native JS numbers. - * @return {LocalDateTime} the unpacked local date time value. - */ -function unpackLocalDateTime ( - verifyStructSize, - struct, - disableLosslessIntegers, - useBigInt -) { - verifyStructSize( - 'LocalDateTime', - LOCAL_DATE_TIME_STRUCT_SIZE, - struct.size - ) - - const [epochSecond, nano] = struct.fields - const result = epochSecondAndNanoToLocalDateTime(epochSecond, nano) - return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) -} - -/** - * Pack given date time. - * @param {DateTime} value the date time value to pack. - * @param {Packer} packer the packer to use. - */ -function packDateTime (value) { - if (value.timeZoneId) { - return packDateTimeWithZoneId(value) - } else { - return packDateTimeWithZoneOffset(value) - } -} - -/** - * Pack given date time with zone offset. - * @param {DateTime} value the date time value to pack. - * @param {Packer} packer the packer to use. - */ -function packDateTimeWithZoneOffset (value) { - const epochSecond = localDateTimeToEpochSecond( - value.year, - value.month, - value.day, - value.hour, - value.minute, - value.second, - value.nanosecond - ) - const nano = int(value.nanosecond) - const timeZoneOffsetSeconds = int(value.timeZoneOffsetSeconds) - return new v1.Structure(DATE_TIME_WITH_ZONE_OFFSET, [epochSecond, nano, timeZoneOffsetSeconds]) -} - -/** - * Unpack date time with zone offset value using the given unpacker. - * @param {Unpacker} unpacker the unpacker to use. - * @param {number} structSize the retrieved struct size. - * @param {BaseBuffer} buffer the buffer to unpack from. - * @param {boolean} disableLosslessIntegers if integer properties in the result date-time should be native JS numbers. - * @return {DateTime} the unpacked date time with zone offset value. - */ -function unpackDateTimeWithZoneOffset ( - verifyStructSize, - struct, - disableLosslessIntegers, - useBigInt -) { - verifyStructSize( - 'DateTimeWithZoneOffset', - DATE_TIME_WITH_ZONE_OFFSET_STRUCT_SIZE, - struct.size - ) - - const [epochSecond, nano, timeZoneOffsetSeconds] = struct.fields - - const localDateTime = epochSecondAndNanoToLocalDateTime(epochSecond, nano) - const result = new DateTime( - localDateTime.year, - localDateTime.month, - localDateTime.day, - localDateTime.hour, - localDateTime.minute, - localDateTime.second, - localDateTime.nanosecond, - timeZoneOffsetSeconds, - null - ) - return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) -} - -/** - * Pack given date time with zone id. - * @param {DateTime} value the date time value to pack. - * @param {Packer} packer the packer to use. - */ -function packDateTimeWithZoneId (value) { - const epochSecond = localDateTimeToEpochSecond( - value.year, - value.month, - value.day, - value.hour, - value.minute, - value.second, - value.nanosecond - ) - const nano = int(value.nanosecond) - const timeZoneId = value.timeZoneId - - return new v1.Structure(DATE_TIME_WITH_ZONE_ID, [epochSecond, nano, timeZoneId]) -} - -/** - * Unpack date time with zone id value using the given unpacker. - * @param {Unpacker} unpacker the unpacker to use. - * @param {number} structSize the retrieved struct size. - * @param {BaseBuffer} buffer the buffer to unpack from. - * @param {boolean} disableLosslessIntegers if integer properties in the result date-time should be native JS numbers. - * @return {DateTime} the unpacked date time with zone id value. - */ -function unpackDateTimeWithZoneId ( - verifyStructSize, - struct, - disableLosslessIntegers, - useBigInt -) { - verifyStructSize( - 'DateTimeWithZoneId', - DATE_TIME_WITH_ZONE_ID_STRUCT_SIZE, - struct.size - ) - - const [epochSecond, nano, timeZoneId] = struct.fields - - const localDateTime = epochSecondAndNanoToLocalDateTime(epochSecond, nano) - const result = new DateTime( - localDateTime.year, - localDateTime.month, - localDateTime.day, - localDateTime.hour, - localDateTime.minute, - localDateTime.second, - localDateTime.nanosecond, - null, - timeZoneId - ) - return convertIntegerPropsIfNeeded(result, disableLosslessIntegers, useBigInt) -} - -function convertIntegerPropsIfNeeded (obj, disableLosslessIntegers, useBigInt) { - if (!disableLosslessIntegers && !useBigInt) { - return obj - } - - const convert = value => - useBigInt ? value.toBigInt() : value.toNumberOrInfinity() - - const clone = Object.create(Object.getPrototypeOf(obj)) - for (const prop in obj) { - if (Object.prototype.hasOwnProperty.call(obj, prop) === true) { - const value = obj[prop] - clone[prop] = isInt(value) ? convert(value) : value - } - } - Object.freeze(clone) - return clone } diff --git a/packages/bolt-connection/src/packstream/structure.js b/packages/bolt-connection/src/packstream/structure.js new file mode 100644 index 000000000..d05ab4652 --- /dev/null +++ b/packages/bolt-connection/src/packstream/structure.js @@ -0,0 +1,59 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { newError, PROTOCOL_ERROR } from 'neo4j-driver-core' + +/** + * A Structure have a signature and fields. + */ +export class Structure { + /** + * Create new instance + */ + constructor (signature, fields) { + this.signature = signature + this.fields = fields + } + + get size () { + return this.fields.length + } + + toString () { + let fieldStr = '' + for (let i = 0; i < this.fields.length; i++) { + if (i > 0) { + fieldStr += ', ' + } + fieldStr += this.fields[i] + } + return 'Structure(' + this.signature + ', [' + fieldStr + '])' + } +} + +export function verifyStructSize (structName, expectedSize, actualSize) { + if (expectedSize !== actualSize) { + throw newError( + `Wrong struct size for ${structName}, expected ${expectedSize} but was ${actualSize}`, + PROTOCOL_ERROR + ) + } +} + +export default Structure diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js index 512918bd3..ebb34dd52 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js @@ -19,7 +19,7 @@ import BoltProtocolV5x0 from '../../src/bolt/bolt-protocol-v5x0' import RequestMessage from '../../src/bolt/request-message' -import { v5 } from '../../src/packstream' +import { v2 } from '../../src/packstream' import utils from '../test-utils' import { RouteObserver } from '../../src/bolt/stream-observers' import { internal } from 'neo4j-driver-core' @@ -356,14 +356,14 @@ describe('#unit BoltProtocolV5x0', () => { }) describe('packstream', () => { - it('should configure v5 packer', () => { + it('should configure v2 packer', () => { const protocol = new BoltProtocolV5x0(null, null, false) - expect(protocol.packer()).toBeInstanceOf(v5.Packer) + expect(protocol.packer()).toBeInstanceOf(v2.Packer) }) - it('should configure v5 unpacker', () => { + it('should configure v2 unpacker', () => { const protocol = new BoltProtocolV5x0(null, null, false) - expect(protocol.unpacker()).toBeInstanceOf(v5.Unpacker) + expect(protocol.unpacker()).toBeInstanceOf(v2.Unpacker) }) }) }) diff --git a/packages/bolt-connection/test/packstream/packstream-v5.test.js b/packages/bolt-connection/test/packstream/packstream-v5.test.js index ffb9df042..f1256ce03 100644 --- a/packages/bolt-connection/test/packstream/packstream-v5.test.js +++ b/packages/bolt-connection/test/packstream/packstream-v5.test.js @@ -22,7 +22,7 @@ import { alloc } from '../../src/channel' import { Packer, Unpacker } from '../../src/packstream/packstream-v5' import { Structure } from '../../src/packstream/packstream-v1' -describe('#unit PackStreamV5', () => { +xdescribe('#unit PackStreamV5', () => { it('should pack integers with small numbers', () => { let n, i // test small numbers From 067cdea6bf35047da1d3d484c0b4dc6551180a73 Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Wed, 8 Jun 2022 13:11:49 +0200 Subject: [PATCH 06/18] Add protocol error --- packages/bolt-connection/src/packstream/structure.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/bolt-connection/src/packstream/structure.js b/packages/bolt-connection/src/packstream/structure.js index d05ab4652..4fff7e19d 100644 --- a/packages/bolt-connection/src/packstream/structure.js +++ b/packages/bolt-connection/src/packstream/structure.js @@ -17,7 +17,11 @@ * limitations under the License. */ -import { newError, PROTOCOL_ERROR } from 'neo4j-driver-core' +import { newError, error } from 'neo4j-driver-core' + +const { + PROTOCOL_ERROR +} = error /** * A Structure have a signature and fields. From 03f6e21dd707a88514aafe88ae996db3602263de Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Wed, 8 Jun 2022 13:40:33 +0200 Subject: [PATCH 07/18] Fix transformers export --- .../src/bolt/bolt-protocol-v1.js | 2 +- .../src/bolt/bolt-protocol-v1.transformer.js | 15 ++++++--- .../src/bolt/bolt-protocol-v2.js | 2 +- .../src/bolt/bolt-protocol-v2.transformer.js | 33 +++++++++++++------ .../src/bolt/bolt-protocol-v3.js | 2 +- .../src/bolt/bolt-protocol-v3.transformer.js | 6 +++- .../src/bolt/bolt-protocol-v4x0.js | 2 +- .../bolt/bolt-protocol-v4x0.transformer.js | 6 +++- .../src/bolt/bolt-protocol-v4x1.js | 2 +- .../bolt/bolt-protocol-v4x1.transformer.js | 6 +++- .../src/bolt/bolt-protocol-v4x2.js | 2 +- .../bolt/bolt-protocol-v4x2.transformer.js | 6 +++- .../src/bolt/bolt-protocol-v4x3.js | 2 +- .../bolt/bolt-protocol-v4x3.transformer.js | 6 +++- .../src/bolt/bolt-protocol-v4x4.js | 2 +- .../bolt/bolt-protocol-v4x4.transformer.js | 6 +++- .../src/bolt/bolt-protocol-v5x0.js | 2 +- .../bolt/bolt-protocol-v5x0.transformer.js | 4 +-- 18 files changed, 75 insertions(+), 31 deletions(-) diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v1.js b/packages/bolt-connection/src/bolt/bolt-protocol-v1.js index 4f8711d98..3938cbb7b 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v1.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v1.js @@ -33,7 +33,7 @@ import { StreamObserver } from './stream-observers' import { internal } from 'neo4j-driver-core' -import * as transformersFactories from './bolt-protocol-v1.transformer' +import transformersFactories from './bolt-protocol-v1.transformer' import Transformer from './transformer' const { diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v1.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v1.transformer.js index dcffea9af..c321a99f9 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v1.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v1.transformer.js @@ -45,7 +45,7 @@ const UNBOUND_RELATIONSHIP_STRUCT_SIZE = 3 const PATH = 0x50 const PATH_STRUCT_SIZE = 3 -export function createNodeTransformer () { +function createNodeTransformer () { return new TypeTransformer({ signature: NODE, isTypeInstance: object => object instanceof Node, @@ -65,7 +65,7 @@ export function createNodeTransformer () { }) } -export function createRelationshipTransformer () { +function createRelationshipTransformer () { return new TypeTransformer({ signature: RELATIONSHIP, isTypeInstance: object => object instanceof Relationship, @@ -85,7 +85,7 @@ export function createRelationshipTransformer () { }) } -export function createUnboundRelationshipTransformer () { +function createUnboundRelationshipTransformer () { return new TypeTransformer({ signature: UNBOUND_RELATIONSHIP, isTypeInstance: object => object instanceof UnboundRelationship, @@ -109,7 +109,7 @@ export function createUnboundRelationshipTransformer () { }) } -export function createPathTransformer () { +function createPathTransformer () { return new TypeTransformer({ signature: PATH, isTypeInstance: object => object instanceof Path, @@ -162,3 +162,10 @@ export function createPathTransformer () { } }) } + +export default { + createNodeTransformer, + createRelationshipTransformer, + createUnboundRelationshipTransformer, + createPathTransformer +} diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v2.js b/packages/bolt-connection/src/bolt/bolt-protocol-v2.js index 45b8b3244..4abec0941 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v2.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v2.js @@ -19,7 +19,7 @@ import BoltProtocolV1 from './bolt-protocol-v1' import v2 from '../packstream' import { internal } from 'neo4j-driver-core' -import * as transformersFactories from './bolt-protocol-v2.transformer' +import transformersFactories from './bolt-protocol-v2.transformer' import Transformer from './transformer' const { diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js index ede5ae1af..21db0feab 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js @@ -43,7 +43,7 @@ import { epochSecondAndNanoToLocalDateTime } from './temporal-factory' -export * from './bolt-protocol-v1.transformer' +import v1 from './bolt-protocol-v1.transformer' const { temporalUtil: { @@ -80,7 +80,7 @@ const DATE_TIME_WITH_ZONE_OFFSET_STRUCT_SIZE = 3 const DATE_TIME_WITH_ZONE_ID = 0x66 const DATE_TIME_WITH_ZONE_ID_STRUCT_SIZE = 3 -export function createPoint2DTransformer () { +function createPoint2DTransformer () { return new TypeTransformer({ signature: POINT_2D, isTypeInstance: point => isPoint(point) && (point.z === null || point.z === undefined), @@ -103,7 +103,7 @@ export function createPoint2DTransformer () { }) } -export function createPoint3DTransformer () { +function createPoint3DTransformer () { return new TypeTransformer({ signature: POINT_3D, isTypeInstance: point => isPoint(point) && point.z !== null && point.z !== undefined, @@ -127,7 +127,7 @@ export function createPoint3DTransformer () { }) } -export function createDurationTransformer () { +function createDurationTransformer () { return new TypeTransformer({ signature: DURATION, isTypeInstance: isDuration, @@ -149,7 +149,7 @@ export function createDurationTransformer () { }) } -export function createLocalTimeTransformer ({ disableLosslessIntegers, useBigInt }) { +function createLocalTimeTransformer ({ disableLosslessIntegers, useBigInt }) { return new TypeTransformer({ signature: LOCAL_TIME, isTypeInstance: isLocalTime, @@ -173,7 +173,7 @@ export function createLocalTimeTransformer ({ disableLosslessIntegers, useBigInt }) } -export function createTimeTransformer ({ disableLosslessIntegers, useBigInt }) { +function createTimeTransformer ({ disableLosslessIntegers, useBigInt }) { return new TypeTransformer({ signature: TIME, isTypeInstance: isTime, @@ -205,7 +205,7 @@ export function createTimeTransformer ({ disableLosslessIntegers, useBigInt }) { }) } -export function createDateTransformer ({ disableLosslessIntegers, useBigInt }) { +function createDateTransformer ({ disableLosslessIntegers, useBigInt }) { return new TypeTransformer({ signature: DATE, isTypeInstance: isDate, @@ -224,7 +224,7 @@ export function createDateTransformer ({ disableLosslessIntegers, useBigInt }) { }) } -export function createLocalDateTime ({ disableLosslessIntegers, useBigInt }) { +function createLocalDateTimeTransformer ({ disableLosslessIntegers, useBigInt }) { return new TypeTransformer({ signature: LOCAL_DATE_TIME, isTypeInstance: isLocalDateTime, @@ -256,7 +256,7 @@ export function createLocalDateTime ({ disableLosslessIntegers, useBigInt }) { }) } -export function createDateTimeWithZoneId ({ disableLosslessIntegers, useBigInt }) { +function createDateTimeWithZoneIdTransformer ({ disableLosslessIntegers, useBigInt }) { return new TypeTransformer({ signature: DATE_TIME_WITH_ZONE_ID, isTypeInstance: object => isDateTime(object) && object.timeZoneId != null, @@ -301,7 +301,7 @@ export function createDateTimeWithZoneId ({ disableLosslessIntegers, useBigInt } }) } -export function createDateTimeWithOffset ({ disableLosslessIntegers, useBigInt }) { +function createDateTimeWithOffsetTransformer ({ disableLosslessIntegers, useBigInt }) { return new TypeTransformer({ signature: DATE_TIME_WITH_ZONE_OFFSET, isTypeInstance: object => isDateTime(object) && object.timeZoneId == null, @@ -363,3 +363,16 @@ function convertIntegerPropsIfNeeded (obj, disableLosslessIntegers, useBigInt) { Object.freeze(clone) return clone } + +export default { + ...v1, + createPoint2DTransformer, + createPoint3DTransformer, + createDurationTransformer, + createLocalTimeTransformer, + createTimeTransformer, + createDateTransformer, + createLocalDateTimeTransformer, + createDateTimeWithZoneIdTransformer, + createDateTimeWithOffsetTransformer +} diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v3.js b/packages/bolt-connection/src/bolt/bolt-protocol-v3.js index 488845884..32f0d664b 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v3.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v3.js @@ -25,7 +25,7 @@ import { ResultStreamObserver, ProcedureRouteObserver } from './stream-observers' -import * as transformersFactories from './bolt-protocol-v3.transformer' +import transformersFactories from './bolt-protocol-v3.transformer' import Transformer from './transformer' import { internal } from 'neo4j-driver-core' diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v3.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v3.transformer.js index 14cf92823..979bde7ed 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v3.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v3.transformer.js @@ -17,4 +17,8 @@ * limitations under the License. */ -export * from './bolt-protocol-v2.transformer' +import v2 from './bolt-protocol-v2.transformer' + +export default { + ...v2 +} diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.js index 3a6930bea..102034d51 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.js @@ -23,7 +23,7 @@ import { ResultStreamObserver, ProcedureRouteObserver } from './stream-observers' -import * as transformersFactories from './bolt-protocol-v4x0.transformer' +import transformersFactories from './bolt-protocol-v4x0.transformer' import Transformer from './transformer' import { internal } from 'neo4j-driver-core' diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.transformer.js index a3995a83c..d78652665 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x0.transformer.js @@ -17,4 +17,8 @@ * limitations under the License. */ -export * from './bolt-protocol-v3.transformer' +import v3 from './bolt-protocol-v3.transformer' + +export default { + ...v3 +} diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.js index c0894397a..7ae475765 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.js @@ -21,7 +21,7 @@ import RequestMessage from './request-message' import { LoginObserver } from './stream-observers' import { internal } from 'neo4j-driver-core' -import * as transformersFactories from './bolt-protocol-v4x1.transformer' +import transformersFactories from './bolt-protocol-v4x1.transformer' import Transformer from './transformer' const { diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.transformer.js index 9ea46a1a5..fe770bc40 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x1.transformer.js @@ -17,4 +17,8 @@ * limitations under the License. */ -export * from './bolt-protocol-v4x0.transformer' +import v4x0 from './bolt-protocol-v4x0.transformer' + +export default { + ...v4x0 +} diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.js index de0050566..07378b53a 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.js @@ -20,7 +20,7 @@ import BoltProtocolV41 from './bolt-protocol-v4x1' import { internal } from 'neo4j-driver-core' -import * as transformersFactories from './bolt-protocol-v4x2.transformer' +import transformersFactories from './bolt-protocol-v4x2.transformer' import Transformer from './transformer' const { diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.transformer.js index 251d5f32f..620807597 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x2.transformer.js @@ -17,4 +17,8 @@ * limitations under the License. */ -export * from './bolt-protocol-v4x1.transformer' +import v4x1 from './bolt-protocol-v4x1.transformer' + +export default { + ...v4x1 +} diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.js index d4bf22009..0897c6826 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.js @@ -20,7 +20,7 @@ import BoltProtocolV42 from './bolt-protocol-v4x2' import RequestMessage from './request-message' import { RouteObserver } from './stream-observers' -import * as transformersFactories from './bolt-protocol-v4x3.transformer' +import transformersFactories from './bolt-protocol-v4x3.transformer' import Transformer from './transformer' import { internal } from 'neo4j-driver-core' diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.transformer.js index 3849b5670..e65b50cf8 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x3.transformer.js @@ -17,4 +17,8 @@ * limitations under the License. */ -export * from './bolt-protocol-v4x2.transformer' +import v4x2 from './bolt-protocol-v4x2.transformer' + +export default { + ...v4x2 +} diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.js index bedc01731..6c6e6af6d 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.js @@ -22,7 +22,7 @@ import { internal } from 'neo4j-driver-core' import RequestMessage from './request-message' import { RouteObserver, ResultStreamObserver } from './stream-observers' -import * as transformersFactories from './bolt-protocol-v4x4.transformer' +import transformersFactories from './bolt-protocol-v4x4.transformer' import Transformer from './transformer' const { diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.transformer.js index b8f9b8872..09bb8de90 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v4x4.transformer.js @@ -17,4 +17,8 @@ * limitations under the License. */ -export * from './bolt-protocol-v4x3.transformer' +import v4x3 from './bolt-protocol-v4x3.transformer' + +export default { + ...v4x3 +} diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js index bfe6292ce..eded12d59 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js @@ -18,7 +18,7 @@ */ import BoltProtocolV44 from './bolt-protocol-v4x4' -import * as transformersFactories from './bolt-protocol-v5x0.transformer' +import transformersFactories from './bolt-protocol-v5x0.transformer' import Transformer from './transformer' import { internal } from 'neo4j-driver-core' diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js index 2a794cf19..75f7d14d4 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js @@ -19,7 +19,7 @@ import { structure } from '../packstream' import { Node, Relationship, UnboundRelationship } from 'neo4j-driver-core' -import * as v4x4 from './bolt-protocol-v4x4.transformer' +import v4x4 from './bolt-protocol-v4x4.transformer' const NODE_STRUCT_SIZE = 4 const RELATIONSHIP_STRUCT_SIZE = 8 @@ -101,7 +101,7 @@ function createUnboundRelationshipTransformer (config) { }) } -module.exports = { +export default { ...v4x4, createNodeTransformer, createRelationshipTransformer, From 360830a8fc1d0dfe2dea56390c45677a2c46fb1f Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Wed, 8 Jun 2022 13:53:30 +0200 Subject: [PATCH 08/18] Fix temporal-factory import in tests --- packages/neo4j-driver/test/internal/temporal-factory.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/neo4j-driver/test/internal/temporal-factory.test.js b/packages/neo4j-driver/test/internal/temporal-factory.test.js index faf95b858..d4fc13645 100644 --- a/packages/neo4j-driver/test/internal/temporal-factory.test.js +++ b/packages/neo4j-driver/test/internal/temporal-factory.test.js @@ -18,7 +18,7 @@ */ import { int } from 'neo4j-driver-core' -import * as factory from '../../../bolt-connection/lib/packstream/temporal-factory' +import * as factory from '../../../bolt-connection/lib/bolt/temporal-factory' import { types } from '../../src' describe('#unit temporal-factory', () => { From 49dde1715e9c4821517a37ddac405d7315135751 Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Wed, 8 Jun 2022 17:25:11 +0200 Subject: [PATCH 09/18] Fix hydration/de-hydration --- .../src/bolt/bolt-protocol-v1.js | 8 +- .../src/bolt/bolt-protocol-v5x0.js | 2 +- .../bolt/bolt-protocol-v5x0.transformer.js | 10 +- .../bolt-connection/src/bolt/transformer.js | 2 +- .../src/packstream/packstream-v1.js | 148 +++++++++--------- .../test/bolt/transformer.test.js | 100 ++++++++++++ 6 files changed, 182 insertions(+), 88 deletions(-) create mode 100644 packages/bolt-connection/test/bolt/transformer.test.js diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v1.js b/packages/bolt-connection/src/bolt/bolt-protocol-v1.js index 3938cbb7b..ccb9704e9 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v1.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v1.js @@ -23,7 +23,7 @@ import { } from './bolt-protocol-util' // eslint-disable-next-line no-unused-vars import { Chunker } from '../channel' -import { v1 } from '../packstream' +import { structure, v1 } from '../packstream' import RequestMessage from './request-message' import { LoginObserver, @@ -386,11 +386,9 @@ export default class BoltProtocol { } this._lastMessageSignature = message.signature + const messageStruct = new structure.Structure(message.signature, message.fields) - this.packer().packStruct( - message.signature, - message.fields.map(field => this.packable(field)) - ) + this.packable(messageStruct)() this._chunker.messageBoundary() diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js index eded12d59..f60c43d89 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js @@ -34,7 +34,7 @@ export default class BoltProtocol extends BoltProtocolV44 { get transformer () { if (this._transformer === undefined) { - this._transformer = new Transformer([...transformersFactories].map(create => create(this._config))) + this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config))) } return this._transformer } diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js index 75f7d14d4..a26646f93 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js @@ -28,8 +28,8 @@ const UNBOUND_RELATIONSHIP_STRUCT_SIZE = 4 function createNodeTransformer (config) { const node4x4Transformer = v4x4.createNodeTransformer(config) return node4x4Transformer.extendsWith({ - toStructure: struct => { - structure.verifyStructSize('Node', NODE_STRUCT_SIZE, struct) + fromStructure: struct => { + structure.verifyStructSize('Node', NODE_STRUCT_SIZE, struct.size) const [identity, lables, properties, elementId] = struct.fields @@ -46,8 +46,8 @@ function createNodeTransformer (config) { function createRelationshipTransformer (config) { const relationship4x4Transformer = v4x4.createRelationshipTransformer(config) return relationship4x4Transformer.extendsWith({ - toStructure: struct => { - structure.verifyStructSize('Relationship', RELATIONSHIP_STRUCT_SIZE, structure.size) + fromStructure: struct => { + structure.verifyStructSize('Relationship', RELATIONSHIP_STRUCT_SIZE, struct.size) const [ identity, @@ -77,7 +77,7 @@ function createRelationshipTransformer (config) { function createUnboundRelationshipTransformer (config) { const unboundRelationshipTransformer = v4x4.createUnboundRelationshipTransformer(config) return unboundRelationshipTransformer.extendsWith({ - toStructure: struct => { + fromStructure: struct => { this._verifyStructSize( 'UnboundRelationship', UNBOUND_RELATIONSHIP_STRUCT_SIZE, diff --git a/packages/bolt-connection/src/bolt/transformer.js b/packages/bolt-connection/src/bolt/transformer.js index 050a188b5..24ded07bf 100644 --- a/packages/bolt-connection/src/bolt/transformer.js +++ b/packages/bolt-connection/src/bolt/transformer.js @@ -30,7 +30,7 @@ export default class Transformer { fromStructure (struct) { if (struct instanceof structure.Structure && this._transformersPerSignature.has(struct.signature)) { - const { fromStructure } = this._transformersPerSignature[struct.signature] + const { fromStructure } = this._transformersPerSignature.get(struct.signature) return fromStructure(struct) } return struct diff --git a/packages/bolt-connection/src/packstream/packstream-v1.js b/packages/bolt-connection/src/packstream/packstream-v1.js index d55895989..100d6232b 100644 --- a/packages/bolt-connection/src/packstream/packstream-v1.js +++ b/packages/bolt-connection/src/packstream/packstream-v1.js @@ -75,9 +75,9 @@ class Packer { * @param x the value to pack * @returns Function */ - packable (x, dehydrate = functional.identity) { + packable (x, dehydrateStruct = functional.identity) { try { - x = dehydrate(x) + x = dehydrateStruct(x) } catch (ex) { return () => ex } @@ -102,15 +102,15 @@ class Packer { return () => { this.packListHeader(x.length) for (let i = 0; i < x.length; i++) { - this.packable(x[i] === undefined ? null : x[i])() + this.packable(x[i] === undefined ? null : x[i], dehydrateStruct)() } } } else if (isIterable(x)) { - return this.packableIterable(x) + return this.packableIterable(x, dehydrateStruct) } else if (x instanceof Structure) { const packableFields = [] for (let i = 0; i < x.fields.length; i++) { - packableFields[i] = this.packable(x.fields[i]) + packableFields[i] = this.packable(x.fields[i], dehydrateStruct) } return () => this.packStruct(x.signature, packableFields) } else if (typeof x === 'object') { @@ -128,7 +128,7 @@ class Packer { const key = keys[i] if (x[key] !== undefined) { this.packString(key) - this.packable(x[key])() + this.packable(x[key], dehydrateStruct)() } } } @@ -137,10 +137,10 @@ class Packer { } } - packableIterable (iterable) { + packableIterable (iterable, dehydrateStruct) { try { const array = Array.from(iterable) - return this.packable(array) + return this.packable(array, dehydrateStruct) } catch (e) { // handle errors from iterable to array conversion throw newError(`Cannot pack given iterable, ${e.message}: ${iterable}`) @@ -331,63 +331,58 @@ class Unpacker { this._useBigInt = useBigInt } - unpack (buffer, hydrate = functional.identity) { - const deserialize = () => { - const marker = buffer.readUInt8() - const markerHigh = marker & 0xf0 - const markerLow = marker & 0x0f + unpack (buffer, hydrateStructure = functional.identity) { + const marker = buffer.readUInt8() + const markerHigh = marker & 0xf0 + const markerLow = marker & 0x0f - if (marker === NULL) { - return null - } + if (marker === NULL) { + return null + } - const boolean = this._unpackBoolean(marker) - if (boolean !== null) { - return boolean - } + const boolean = this._unpackBoolean(marker) + if (boolean !== null) { + return boolean + } - const numberOrInteger = this._unpackNumberOrInteger(marker, buffer) - if (numberOrInteger !== null) { - if (isInt(numberOrInteger)) { - if (this._useBigInt) { - return numberOrInteger.toBigInt() - } else if (this._disableLosslessIntegers) { - return numberOrInteger.toNumberOrInfinity() - } + const numberOrInteger = this._unpackNumberOrInteger(marker, buffer) + if (numberOrInteger !== null) { + if (isInt(numberOrInteger)) { + if (this._useBigInt) { + return numberOrInteger.toBigInt() + } else if (this._disableLosslessIntegers) { + return numberOrInteger.toNumberOrInfinity() } - return numberOrInteger - } - - const string = this._unpackString(marker, markerHigh, markerLow, buffer) - if (string !== null) { - return string } + return numberOrInteger + } - const list = this._unpackList(marker, markerHigh, markerLow, buffer) - if (list !== null) { - return list - } + const string = this._unpackString(marker, markerHigh, markerLow, buffer) + if (string !== null) { + return string + } - const byteArray = this._unpackByteArray(marker, buffer) - if (byteArray !== null) { - return byteArray - } + const list = this._unpackList(marker, markerHigh, markerLow, buffer, hydrateStructure) + if (list !== null) { + return list + } - const map = this._unpackMap(marker, markerHigh, markerLow, buffer) - if (map !== null) { - return map - } + const byteArray = this._unpackByteArray(marker, buffer) + if (byteArray !== null) { + return byteArray + } - const struct = this._unpackStruct(marker, markerHigh, markerLow, buffer) - if (struct !== null) { - return struct - } + const map = this._unpackMap(marker, markerHigh, markerLow, buffer, hydrateStructure) + if (map !== null) { + return map + } - throw newError('Unknown packed value with marker ' + marker.toString(16)) + const struct = this._unpackStruct(marker, markerHigh, markerLow, buffer, hydrateStructure) + if (struct !== null) { + return struct } - const deserialized = deserialize() - return hydrate(deserialized) + throw newError('Unknown packed value with marker ' + marker.toString(16)) } unpackInteger (buffer) { @@ -454,24 +449,24 @@ class Unpacker { } } - _unpackList (marker, markerHigh, markerLow, buffer) { + _unpackList (marker, markerHigh, markerLow, buffer, hydrateStructure) { if (markerHigh === TINY_LIST) { - return this._unpackListWithSize(markerLow, buffer) + return this._unpackListWithSize(markerLow, buffer, hydrateStructure) } else if (marker === LIST_8) { - return this._unpackListWithSize(buffer.readUInt8(), buffer) + return this._unpackListWithSize(buffer.readUInt8(), buffer, hydrateStructure) } else if (marker === LIST_16) { - return this._unpackListWithSize(buffer.readUInt16(), buffer) + return this._unpackListWithSize(buffer.readUInt16(), buffer, hydrateStructure) } else if (marker === LIST_32) { - return this._unpackListWithSize(buffer.readUInt32(), buffer) + return this._unpackListWithSize(buffer.readUInt32(), buffer, hydrateStructure) } else { return null } } - _unpackListWithSize (size, buffer) { + _unpackListWithSize (size, buffer, hydrateStructure) { const value = [] for (let i = 0; i < size; i++) { - value.push(this.unpack(buffer)) + value.push(this.unpack(buffer, hydrateStructure)) } return value } @@ -496,48 +491,49 @@ class Unpacker { return value } - _unpackMap (marker, markerHigh, markerLow, buffer) { + _unpackMap (marker, markerHigh, markerLow, buffer, hydrateStructure) { if (markerHigh === TINY_MAP) { - return this._unpackMapWithSize(markerLow, buffer) + return this._unpackMapWithSize(markerLow, buffer, hydrateStructure) } else if (marker === MAP_8) { - return this._unpackMapWithSize(buffer.readUInt8(), buffer) + return this._unpackMapWithSize(buffer.readUInt8(), buffer, hydrateStructure) } else if (marker === MAP_16) { - return this._unpackMapWithSize(buffer.readUInt16(), buffer) + return this._unpackMapWithSize(buffer.readUInt16(), buffer, hydrateStructure) } else if (marker === MAP_32) { - return this._unpackMapWithSize(buffer.readUInt32(), buffer) + return this._unpackMapWithSize(buffer.readUInt32(), buffer, hydrateStructure) } else { return null } } - _unpackMapWithSize (size, buffer) { + _unpackMapWithSize (size, buffer, hydrateStructure) { const value = {} for (let i = 0; i < size; i++) { - const key = this.unpack(buffer) - value[key] = this.unpack(buffer) + const key = this.unpack(buffer, hydrateStructure) + value[key] = this.unpack(buffer, hydrateStructure) } return value } - _unpackStruct (marker, markerHigh, markerLow, buffer) { + _unpackStruct (marker, markerHigh, markerLow, buffer, hydrateStructure) { if (markerHigh === TINY_STRUCT) { - return this._unpackStructWithSize(markerLow, buffer) + return this._unpackStructWithSize(markerLow, buffer, hydrateStructure) } else if (marker === STRUCT_8) { - return this._unpackStructWithSize(buffer.readUInt8(), buffer) + return this._unpackStructWithSize(buffer.readUInt8(), buffer, hydrateStructure) } else if (marker === STRUCT_16) { - return this._unpackStructWithSize(buffer.readUInt16(), buffer) + return this._unpackStructWithSize(buffer.readUInt16(), buffer, hydrateStructure) } else { return null } } - _unpackStructWithSize (structSize, buffer) { + _unpackStructWithSize (structSize, buffer, hydrateStructure) { const signature = buffer.readUInt8() const structure = new Structure(signature, []) for (let i = 0; i < structSize; i++) { - structure.fields.push(this.unpack(buffer)) + structure.fields.push(this.unpack(buffer, hydrateStructure)) } - return structure + + return hydrateStructure(structure) } } @@ -548,4 +544,4 @@ function isIterable (obj) { return typeof obj[Symbol.iterator] === 'function' } -export { Packer, Unpacker, Structure } +export { Packer, Unpacker } diff --git a/packages/bolt-connection/test/bolt/transformer.test.js b/packages/bolt-connection/test/bolt/transformer.test.js new file mode 100644 index 000000000..6858577b4 --- /dev/null +++ b/packages/bolt-connection/test/bolt/transformer.test.js @@ -0,0 +1,100 @@ +/** + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { TypeTransformer } from '../../src/bolt/transformer.js' + +describe('TypeTransformer', () => { + const defaultSignature = 123 + const defaultFromStructure = (struct) => struct + const defaultToStructure = (obj) => obj + const defaultIsTypeInstance = () => true + const createDefaultTransformer = () => { + return new TypeTransformer({ + signature: defaultSignature, + isTypeInstance: defaultIsTypeInstance, + fromStructure: defaultFromStructure, + toStructure: defaultToStructure + }) + } + + describe('constructor', () => { + it('should create the complete object', () => { + const typeTransformer = createDefaultTransformer() + + expect(typeTransformer.signature).toBe(defaultSignature) + expect(typeTransformer.isTypeInstance).toBe(defaultIsTypeInstance) + expect(typeTransformer.fromStructure).toBe(defaultFromStructure) + expect(typeTransformer.toStructure).toBe(defaultToStructure) + }) + }) + + describe('.extendsWith()', () => { + it('should override signature and keep rest of param intact', () => { + const expectedSignature = 124 + + const typeTransformer = createDefaultTransformer() + + const extended = typeTransformer.extendsWith({ signature: expectedSignature }) + + expect(extended.signature).toBe(expectedSignature) + expect(extended.isTypeInstance).toBe(typeTransformer.isTypeInstance) + expect(extended.fromStructure).toBe(typeTransformer.fromStructure) + expect(extended.toStructure).toBe(typeTransformer.toStructure) + }) + + it('should override isTypeInstance and keep rest of param intact', () => { + const expectedIsTypeInstance = () => false + + const typeTransformer = createDefaultTransformer() + + const extended = typeTransformer.extendsWith({ isTypeInstance: expectedIsTypeInstance }) + + expect(extended.isTypeInstance).toBe(expectedIsTypeInstance) + expect(extended.signature).toEqual(typeTransformer.signature) + expect(extended.fromStructure).toBe(typeTransformer.fromStructure) + expect(extended.toStructure).toBe(typeTransformer.toStructure) + }) + + it('should override fromStructure and keep rest of param intact', () => { + const expectedFromStructure = () => false + + const typeTransformer = createDefaultTransformer() + + const extended = typeTransformer.extendsWith({ fromStructure: expectedFromStructure }) + + expect(extended.fromStructure).toBe(expectedFromStructure) + expect(extended.signature).toEqual(typeTransformer.signature) + expect(extended.isTypeInstance).toBe(typeTransformer.isTypeInstance) + expect(extended.toStructure).toBe(typeTransformer.toStructure) + }) + + it('should override toStructure and keep rest of param intact', () => { + const expectedToStructure = () => false + + const typeTransformer = createDefaultTransformer() + + const extended = typeTransformer.extendsWith({ toStructure: expectedToStructure }) + + expect(extended.toStructure).toBe(expectedToStructure) + expect(extended.signature).toEqual(typeTransformer.signature) + expect(extended.fromStructure).toBe(typeTransformer.fromStructure) + expect(extended.isTypeInstance).toBe(typeTransformer.isTypeInstance) + }) + }) +}) From 31c6fe672380aa4eafefeac5d384928b586dbef1 Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Wed, 8 Jun 2022 17:51:46 +0200 Subject: [PATCH 10/18] Fix unbound rel serialization --- .../bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js index a26646f93..d50cca0f9 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js @@ -78,7 +78,7 @@ function createUnboundRelationshipTransformer (config) { const unboundRelationshipTransformer = v4x4.createUnboundRelationshipTransformer(config) return unboundRelationshipTransformer.extendsWith({ fromStructure: struct => { - this._verifyStructSize( + structure.verifyStructSize( 'UnboundRelationship', UNBOUND_RELATIONSHIP_STRUCT_SIZE, struct.size From 5a732be944393230b801ba2c05f42e151fa96c77 Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Wed, 8 Jun 2022 17:52:10 +0200 Subject: [PATCH 11/18] Skipe deprecated tests --- packages/testkit-backend/src/channel/testkit-protocol.js | 2 +- packages/testkit-backend/src/skipped-tests/common.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/testkit-backend/src/channel/testkit-protocol.js b/packages/testkit-backend/src/channel/testkit-protocol.js index e8b1f2d60..f6282c4c7 100644 --- a/packages/testkit-backend/src/channel/testkit-protocol.js +++ b/packages/testkit-backend/src/channel/testkit-protocol.js @@ -61,8 +61,8 @@ export default class Protocol extends EventEmitter { } serializeResponse (response) { - console.log('> writing response', response) const responseStr = stringify(response) + console.log('> writing response', responseStr) return ['#response begin', responseStr, '#response end'].join('\n') + '\n' } diff --git a/packages/testkit-backend/src/skipped-tests/common.js b/packages/testkit-backend/src/skipped-tests/common.js index a6f61fc00..f2fe10fb1 100644 --- a/packages/testkit-backend/src/skipped-tests/common.js +++ b/packages/testkit-backend/src/skipped-tests/common.js @@ -1,6 +1,12 @@ import skip, { ifEquals, ifEndsWith } from './skip' const skippedTests = [ + skip( + 'Testkit implemenation is deprecated', + ifEquals('stub.basic_query.test_basic_query.TestBasicQuery.test_5x0_populates_node_only_element_id'), + ifEquals('stub.basic_query.test_basic_query.TestBasicQuery.test_5x0_populates_path_element_ids_with_only_string'), + ifEquals('stub.basic_query.test_basic_query.TestBasicQuery.test_5x0_populates_rel_only_element_id') + ), skip( 'Skipped because server doesn\'t support protocol 5.0 yet', ifEndsWith('neo4j.test_summary.TestSummary.test_protocol_version_information') From 64eee940c4d6a17dee8751044cc69966828f5b01 Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Thu, 9 Jun 2022 10:18:30 +0200 Subject: [PATCH 12/18] Fix test --- .../test/packstream/packstream-v1.test.js | 3 +- .../test/packstream/packstream-v5.test.js | 1060 +++++++++-------- 2 files changed, 535 insertions(+), 528 deletions(-) diff --git a/packages/bolt-connection/test/packstream/packstream-v1.test.js b/packages/bolt-connection/test/packstream/packstream-v1.test.js index e8e8590b3..038c49bbf 100644 --- a/packages/bolt-connection/test/packstream/packstream-v1.test.js +++ b/packages/bolt-connection/test/packstream/packstream-v1.test.js @@ -19,7 +19,8 @@ import { int, Integer } from 'neo4j-driver-core' import { alloc } from '../../src/channel' -import { Packer, Structure, Unpacker } from '../../src/packstream/packstream-v1' +import { Packer, Unpacker } from '../../src/packstream/packstream-v1' +import { Structure } from '../../src/packstream/structure' describe('#unit PackStreamV1', () => { it('should pack integers with small numbers', () => { diff --git a/packages/bolt-connection/test/packstream/packstream-v5.test.js b/packages/bolt-connection/test/packstream/packstream-v5.test.js index f1256ce03..08c71c41f 100644 --- a/packages/bolt-connection/test/packstream/packstream-v5.test.js +++ b/packages/bolt-connection/test/packstream/packstream-v5.test.js @@ -17,533 +17,539 @@ * limitations under the License. */ -import { int, Integer, Node, Relationship, UnboundRelationship } from 'neo4j-driver-core' -import { alloc } from '../../src/channel' -import { Packer, Unpacker } from '../../src/packstream/packstream-v5' -import { Structure } from '../../src/packstream/packstream-v1' - -xdescribe('#unit PackStreamV5', () => { - it('should pack integers with small numbers', () => { - let n, i - // test small numbers - for (n = -999; n <= 999; n += 1) { - i = int(n) - expect(packAndUnpack(i).toString()).toBe(i.toString()) - expect( - packAndUnpack(i, { disableLosslessIntegers: true }).toString() - ).toBe(i.toString()) - expect(packAndUnpack(i, { useBigInt: true }).toString()).toBe( - i.toString() - ) - } +// import { int, Integer, Node, Relationship, UnboundRelationship } from 'neo4j-driver-core' +// import { alloc } from '../../src/channel' +// import { Packer, Unpacker } from '../../src/packstream/packstream-v5' +// import { Structure } from '../../src/packstream/structure' + +describe('dummy', () => { + it('should export the expected transformers factories', () => { + expect(true).toBe(true) }) - - it('should pack integers with small numbers created with Integer', () => { - let n, i - // test small numbers - for (n = -10; n <= 10; n += 1) { - i = new Integer(n, 0) - expect(packAndUnpack(i).toString()).toBe(i.toString()) - expect( - packAndUnpack(i, { disableLosslessIntegers: true }).toString() - ).toBe(i.toString()) - expect(packAndUnpack(i, { useBigInt: true }).toString()).toBe( - i.toString() - ) - } - }) - - it('should pack integers with positive numbers', () => { - let n, i - // positive numbers - for (n = 16; n <= 16; n += 1) { - i = int(Math.pow(2, n)) - expect(packAndUnpack(i).toString()).toBe(i.toString()) - - const unpackedLossyInteger = packAndUnpack(i, { - disableLosslessIntegers: true - }) - expect(typeof unpackedLossyInteger).toBe('number') - expect(unpackedLossyInteger.toString()).toBe( - i.inSafeRange() ? i.toString() : 'Infinity' - ) - - const bigint = packAndUnpack(i, { useBigInt: true }) - expect(typeof bigint).toBe('bigint') - expect(bigint.toString()).toBe(i.toString()) - } - }) - - it('should pack integer with negative numbers', () => { - let n, i - // negative numbers - for (n = 0; n <= 63; n += 1) { - i = int(-Math.pow(2, n)) - expect(packAndUnpack(i).toString()).toBe(i.toString()) - - const unpackedLossyInteger = packAndUnpack(i, { - disableLosslessIntegers: true - }) - expect(typeof unpackedLossyInteger).toBe('number') - expect(unpackedLossyInteger.toString()).toBe( - i.inSafeRange() ? i.toString() : '-Infinity' - ) - - const bigint = packAndUnpack(i, { useBigInt: true }) - expect(typeof bigint).toBe('bigint') - expect(bigint.toString()).toBe(i.toString()) - } - }) - - it('should pack BigInt with small numbers', () => { - let n, i - // test small numbers - for (n = -999; n <= 999; n += 1) { - i = BigInt(n) - expect(packAndUnpack(i).toString()).toBe(i.toString()) - expect( - packAndUnpack(i, { disableLosslessIntegers: true }).toString() - ).toBe(i.toString()) - expect(packAndUnpack(i, { useBigInt: true }).toString()).toBe( - i.toString() - ) - } - }) - - it('should pack BigInt with positive numbers', () => { - let n, i - // positive numbers - for (n = 16; n <= 16; n += 1) { - i = BigInt(Math.pow(2, n)) - expect(packAndUnpack(i).toString()).toBe(i.toString()) - - const unpackedLossyInteger = packAndUnpack(i, { - disableLosslessIntegers: true - }) - expect(typeof unpackedLossyInteger).toBe('number') - expect(unpackedLossyInteger.toString()).toBe( - int(i).inSafeRange() ? i.toString() : 'Infinity' - ) - - const bigint = packAndUnpack(i, { useBigInt: true }) - expect(typeof bigint).toBe('bigint') - expect(bigint.toString()).toBe(i.toString()) - } - }) - - it('should pack BigInt with negative numbers', () => { - let n, i - // negative numbers - for (n = 0; n <= 63; n += 1) { - i = BigInt(-Math.pow(2, n)) - expect(packAndUnpack(i).toString()).toBe(i.toString()) - - const unpackedLossyInteger = packAndUnpack(i, { - disableLosslessIntegers: true - }) - expect(typeof unpackedLossyInteger).toBe('number') - expect(unpackedLossyInteger.toString()).toBe( - int(i).inSafeRange() ? i.toString() : '-Infinity' - ) - - const bigint = packAndUnpack(i, { useBigInt: true }) - expect(typeof bigint).toBe('bigint') - expect(bigint.toString()).toBe(i.toString()) - } - }) - - it('should pack strings', () => { - expect(packAndUnpack('')).toBe('') - expect(packAndUnpack('abcdefg123567')).toBe('abcdefg123567') - const str = Array(65536 + 1).join('a') // 2 ^ 16 + 1 - expect(packAndUnpack(str, { bufferSize: str.length + 8 })).toBe(str) - }) - - it('should pack structures', () => { - expect(packAndUnpack(new Structure(1, ['Hello, world!!!'])).fields[0]).toBe( - 'Hello, world!!!' - ) - }) - - it('should pack lists', () => { - const list = ['a', 'b'] - const unpacked = packAndUnpack(list) - expect(unpacked[0]).toBe(list[0]) - expect(unpacked[1]).toBe(list[1]) - }) - - it('should pack long lists', () => { - const listLength = 256 - const list = [] - for (let i = 0; i < listLength; i++) { - list.push(null) - } - const unpacked = packAndUnpack(list, { bufferSize: 1400 }) - expect(unpacked[0]).toBe(list[0]) - expect(unpacked[1]).toBe(list[1]) - }) - - it.each( - validNodesAndConfig() - )('should unpack Nodes', (struct, expectedNode, config) => { - const node = packAndUnpack(struct, config) - - expect(node).toEqual(expectedNode) - }) - - it.each( - invalidNodesConfig() - )('should thrown error for unpacking invalid Nodes', (struct) => { - expect(() => packAndUnpack(struct)).toThrow() - }) - - it.each( - validRelationshipsAndConfig() - )('should unpack Relationships', (struct, expectedRelationship, config) => { - const releationship = packAndUnpack(struct, config) - - expect(releationship).toEqual(expectedRelationship) - }) - - it.each( - invalidRelationshipsConfig() - )('should thrown error for unpacking invalid Relationships', (struct) => { - expect(() => packAndUnpack(struct)).toThrow() - }) - - it.each( - validUnboundRelationshipsAndConfig() - )('should unpack UnboundRelationships', (struct, expectedRelationship, config) => { - const releationship = packAndUnpack(struct, config) - - expect(releationship).toEqual(expectedRelationship) - }) - - it.each( - invalidUnboundRelationshipsConfig() - )('should thrown error for unpacking invalid UnboundRelationships', (struct) => { - expect(() => packAndUnpack(struct)).toThrow() - }) - - function validNodesAndConfig () { - function validWithNumber () { - const identity = 1 - const labels = ['a', 'b'] - const properties = { a: 1, b: 2 } - const elementId = 'element_id_1' - const expectedNode = new Node(identity, labels, properties, elementId) - const nodeStruct = new Structure(0x4e, [ - identity, labels, properties, elementId - ]) - return [nodeStruct, expectedNode, { disableLosslessIntegers: true, useBigInt: false }] - } - - function validWithoutOldIdentifiersLossy () { - const identity = null - const labels = ['a', 'b'] - const properties = { a: 1, b: 2 } - const elementId = 'element_id_1' - const expectedNode = new Node(-1, labels, properties, elementId) - const nodeStruct = new Structure(0x4e, [ - identity, labels, properties, elementId - ]) - return [nodeStruct, expectedNode, { disableLosslessIntegers: true, useBigInt: false }] - } - - function validWithoutOldIdentifiersLosslessInteger () { - const identity = null - const labels = ['a', 'b'] - const properties = { a: 1, b: 2 } - const elementId = 'element_id_1' - const expectedNode = new Node(int(-1), labels, properties, elementId) - const nodeStruct = new Structure(0x4e, [ - identity, labels, properties, elementId - ]) - return [nodeStruct, expectedNode, { disableLosslessIntegers: false, useBigInt: false }] - } - - function validWithoutOldIdentifiersBigInt () { - const identity = null - const labels = ['a', 'b'] - const properties = { a: 1, b: 2 } - const elementId = 'element_id_1' - const expectedNode = new Node(BigInt(-1), labels, properties, elementId) - const nodeStruct = new Structure(0x4e, [ - identity, labels, properties, elementId - ]) - return [nodeStruct, expectedNode, { disableLosslessIntegers: false, useBigInt: true }] - } - - function validWithInt () { - const identity = int(1) - const labels = ['a', 'b'] - const properties = { a: int(1), b: int(2) } - const elementId = 'element_id_1' - const expectedNode = new Node(identity, labels, properties, elementId) - const nodeStruct = new Structure(0x4e, [ - identity, labels, properties, elementId - ]) - return [nodeStruct, expectedNode, { disableLosslessIntegers: false, useBigInt: false }] - } - - function validWithBigInt () { - const identity = BigInt(1) - const labels = ['a', 'b'] - const properties = { a: BigInt(1), b: BigInt(2) } - const elementId = 'element_id_1' - const expectedNode = new Node(identity, labels, properties, elementId) - const nodeStruct = new Structure(0x4e, [ - identity, labels, properties, elementId - ]) - return [nodeStruct, expectedNode, { disableLosslessIntegers: false, useBigInt: true }] - } - - return [ - validWithNumber(), - validWithInt(), - validWithBigInt(), - validWithoutOldIdentifiersLossy(), - validWithoutOldIdentifiersLosslessInteger(), - validWithoutOldIdentifiersBigInt() - ] - } - - function invalidNodesConfig () { - return [ - [new Structure(0x4e, [1, ['a', 'b'], { a: 1, b: 2 }])], - [new Structure(0x4e, [1, ['a', 'b'], { a: 1, b: 2 }, 'elementId', 'myId'])] - ] - } - - function validRelationshipsAndConfig () { - function validWithNumber () { - const identity = 1 - const start = 2 - const end = 3 - const type = 'KNOWS' - const properties = { a: 1, b: 2 } - const elementId = 'element_id_1' - const startNodeElementId = 'element_id_2' - const endNodeElementId = 'element_id_3' - const expectedRel = new Relationship( - identity, start, end, type, properties, - elementId, startNodeElementId, endNodeElementId) - const relStruct = new Structure(0x52, [ - identity, start, end, type, properties, elementId, - startNodeElementId, endNodeElementId - ]) - return [relStruct, expectedRel, { disableLosslessIntegers: true, useBigInt: false }] - } - - function validWithoutOldIdentifiersLossy () { - const identity = null - const start = null - const end = null - const type = 'KNOWS' - const properties = { a: 1, b: 2 } - const elementId = 'element_id_1' - const startNodeElementId = 'element_id_2' - const endNodeElementId = 'element_id_3' - const expectedRel = new Relationship( - -1, -1, -1, type, properties, - elementId, startNodeElementId, endNodeElementId) - const relStruct = new Structure(0x52, [ - identity, start, end, type, properties, elementId, - startNodeElementId, endNodeElementId - ]) - return [relStruct, expectedRel, { disableLosslessIntegers: true, useBigInt: false }] - } - - function validWithoutOldIdentifiersLossLess () { - const identity = null - const start = null - const end = null - const type = 'KNOWS' - const properties = { a: 1, b: 2 } - const elementId = 'element_id_1' - const startNodeElementId = 'element_id_2' - const endNodeElementId = 'element_id_3' - const expectedRel = new Relationship( - int(-1), int(-1), int(-1), type, properties, - elementId, startNodeElementId, endNodeElementId) - const relStruct = new Structure(0x52, [ - identity, start, end, type, properties, elementId, - startNodeElementId, endNodeElementId - ]) - return [relStruct, expectedRel, { disableLosslessIntegers: false, useBigInt: false }] - } - - function validWithoutOldIdentifiersBigInt () { - const identity = null - const start = null - const end = null - const type = 'KNOWS' - const properties = { a: 1, b: 2 } - const elementId = 'element_id_1' - const startNodeElementId = 'element_id_2' - const endNodeElementId = 'element_id_3' - const expectedRel = new Relationship( - BigInt(-1), BigInt(-1), BigInt(-1), type, properties, - elementId, startNodeElementId, endNodeElementId) - const relStruct = new Structure(0x52, [ - identity, start, end, type, properties, elementId, - startNodeElementId, endNodeElementId - ]) - return [relStruct, expectedRel, { disableLosslessIntegers: true, useBigInt: true }] - } - - function validWithInt () { - const identity = int(1) - const start = int(2) - const end = int(3) - const type = 'KNOWS' - const properties = { a: int(1), b: int(2) } - const elementId = 'element_id_1' - const startNodeElementId = 'element_id_2' - const endNodeElementId = 'element_id_3' - const expectedRel = new Relationship( - identity, start, end, type, properties, - elementId, startNodeElementId, endNodeElementId) - const relStruct = new Structure(0x52, [ - identity, start, end, type, properties, elementId, - startNodeElementId, endNodeElementId - ]) - return [relStruct, expectedRel, { disableLosslessIntegers: false, useBigInt: false }] - } - - function validWithBigInt () { - const identity = BigInt(1) - const start = BigInt(2) - const end = BigInt(3) - const type = 'KNOWS' - const properties = { a: BigInt(1), b: BigInt(2) } - const elementId = 'element_id_1' - const startNodeElementId = 'element_id_2' - const endNodeElementId = 'element_id_3' - const expectedRel = new Relationship( - identity, start, end, type, properties, - elementId, startNodeElementId, endNodeElementId) - const relStruct = new Structure(0x52, [ - identity, start, end, type, properties, elementId, - startNodeElementId, endNodeElementId - ]) - return [relStruct, expectedRel, { disableLosslessIntegers: false, useBigInt: true }] - } - - return [ - validWithNumber(), - validWithInt(), - validWithBigInt(), - validWithoutOldIdentifiersLossy(), - validWithoutOldIdentifiersLossLess(), - validWithoutOldIdentifiersBigInt() - ] - } - - function invalidRelationshipsConfig () { - return [ - [new Structure(0x52, [1, 2, 3, 'rel', { a: 1, b: 2 }, 'elementId', 'startNodeId'])], - [new Structure(0x52, [1, 2, 3, 'rel', { a: 1, b: 2 }, 'elementId', 'startNodeId', 'endNodeId', 'myId'])] - ] - } - - function validUnboundRelationshipsAndConfig () { - function validWithNumber () { - const identity = 1 - const type = 'DOESNT_KNOW' - const properties = { a: 1, b: 2 } - const elementId = 'element_id_1' - const expectedUnboundRel = new UnboundRelationship(identity, type, properties, elementId) - const struct = new Structure(0x72, [ - identity, type, properties, elementId - ]) - return [struct, expectedUnboundRel, { disableLosslessIntegers: true, useBigInt: false }] - } - - function validWithoutOldIdentifiersLossy () { - const identity = null - const type = 'DOESNT_KNOW' - const properties = { a: 1, b: 2 } - const elementId = 'element_id_1' - const expectedUnboundRel = new UnboundRelationship(-1, type, properties, elementId) - const struct = new Structure(0x72, [ - identity, type, properties, elementId - ]) - return [struct, expectedUnboundRel, { disableLosslessIntegers: true, useBigInt: false }] - } - - function validWithoutOldIdentifiersLossless () { - const identity = null - const type = 'DOESNT_KNOW' - const properties = { a: 1, b: 2 } - const elementId = 'element_id_1' - const expectedUnboundRel = new UnboundRelationship(int(-1), type, properties, elementId) - const struct = new Structure(0x72, [ - identity, type, properties, elementId - ]) - return [struct, expectedUnboundRel, { disableLosslessIntegers: false, useBigInt: false }] - } - - function validWithoutOldIdentifiersBigInt () { - const identity = null - const type = 'DOESNT_KNOW' - const properties = { a: 1, b: 2 } - const elementId = 'element_id_1' - const expectedUnboundRel = new UnboundRelationship(BigInt(-1), type, properties, elementId) - const struct = new Structure(0x72, [ - identity, type, properties, elementId - ]) - return [struct, expectedUnboundRel, { disableLosslessIntegers: false, useBigInt: true }] - } - - function validWithInt () { - const identity = int(1) - const type = 'DOESNT_KNOW' - const properties = { a: int(1), b: int(2) } - const elementId = 'element_id_1' - const expectedUnboundRel = new UnboundRelationship(identity, type, properties, elementId) - const struct = new Structure(0x72, [ - identity, type, properties, elementId - ]) - return [struct, expectedUnboundRel, { disableLosslessIntegers: false, useBigInt: false }] - } - - function validWithBigInt () { - const identity = BigInt(1) - const type = 'DOESNT_KNOW' - const properties = { a: BigInt(1), b: BigInt(2) } - const elementId = 'element_id_1' - const expectedUnboundRel = new UnboundRelationship(identity, type, properties, elementId) - const struct = new Structure(0x72, [ - identity, type, properties, elementId - ]) - return [struct, expectedUnboundRel, { disableLosslessIntegers: false, useBigInt: true }] - } - - return [ - validWithNumber(), - validWithInt(), - validWithBigInt(), - validWithoutOldIdentifiersLossy(), - validWithoutOldIdentifiersLossless(), - validWithoutOldIdentifiersBigInt() - ] - } - - function invalidUnboundRelationshipsConfig () { - return [ - [new Structure(0x72, [1, 'DOESNT_KNOW', { a: 1, b: 2 }])], - [new Structure(0x72, [1, 'DOESNT_KNOW', { a: 1, b: 2 }, 'elementId', 'myId'])] - ] - } }) -function packAndUnpack ( - val, - { bufferSize = 128, disableLosslessIntegers = false, useBigInt = false } = {} -) { - const buffer = alloc(bufferSize) - new Packer(buffer).packable(val)() - buffer.reset() - return new Unpacker(disableLosslessIntegers, useBigInt).unpack(buffer) -} +// xdescribe('#unit PackStreamV5', () => { +// it('should pack integers with small numbers', () => { +// let n, i +// // test small numbers +// for (n = -999; n <= 999; n += 1) { +// i = int(n) +// expect(packAndUnpack(i).toString()).toBe(i.toString()) +// expect( +// packAndUnpack(i, { disableLosslessIntegers: true }).toString() +// ).toBe(i.toString()) +// expect(packAndUnpack(i, { useBigInt: true }).toString()).toBe( +// i.toString() +// ) +// } +// }) + +// it('should pack integers with small numbers created with Integer', () => { +// let n, i +// // test small numbers +// for (n = -10; n <= 10; n += 1) { +// i = new Integer(n, 0) +// expect(packAndUnpack(i).toString()).toBe(i.toString()) +// expect( +// packAndUnpack(i, { disableLosslessIntegers: true }).toString() +// ).toBe(i.toString()) +// expect(packAndUnpack(i, { useBigInt: true }).toString()).toBe( +// i.toString() +// ) +// } +// }) + +// it('should pack integers with positive numbers', () => { +// let n, i +// // positive numbers +// for (n = 16; n <= 16; n += 1) { +// i = int(Math.pow(2, n)) +// expect(packAndUnpack(i).toString()).toBe(i.toString()) + +// const unpackedLossyInteger = packAndUnpack(i, { +// disableLosslessIntegers: true +// }) +// expect(typeof unpackedLossyInteger).toBe('number') +// expect(unpackedLossyInteger.toString()).toBe( +// i.inSafeRange() ? i.toString() : 'Infinity' +// ) + +// const bigint = packAndUnpack(i, { useBigInt: true }) +// expect(typeof bigint).toBe('bigint') +// expect(bigint.toString()).toBe(i.toString()) +// } +// }) + +// it('should pack integer with negative numbers', () => { +// let n, i +// // negative numbers +// for (n = 0; n <= 63; n += 1) { +// i = int(-Math.pow(2, n)) +// expect(packAndUnpack(i).toString()).toBe(i.toString()) + +// const unpackedLossyInteger = packAndUnpack(i, { +// disableLosslessIntegers: true +// }) +// expect(typeof unpackedLossyInteger).toBe('number') +// expect(unpackedLossyInteger.toString()).toBe( +// i.inSafeRange() ? i.toString() : '-Infinity' +// ) + +// const bigint = packAndUnpack(i, { useBigInt: true }) +// expect(typeof bigint).toBe('bigint') +// expect(bigint.toString()).toBe(i.toString()) +// } +// }) + +// it('should pack BigInt with small numbers', () => { +// let n, i +// // test small numbers +// for (n = -999; n <= 999; n += 1) { +// i = BigInt(n) +// expect(packAndUnpack(i).toString()).toBe(i.toString()) +// expect( +// packAndUnpack(i, { disableLosslessIntegers: true }).toString() +// ).toBe(i.toString()) +// expect(packAndUnpack(i, { useBigInt: true }).toString()).toBe( +// i.toString() +// ) +// } +// }) + +// it('should pack BigInt with positive numbers', () => { +// let n, i +// // positive numbers +// for (n = 16; n <= 16; n += 1) { +// i = BigInt(Math.pow(2, n)) +// expect(packAndUnpack(i).toString()).toBe(i.toString()) + +// const unpackedLossyInteger = packAndUnpack(i, { +// disableLosslessIntegers: true +// }) +// expect(typeof unpackedLossyInteger).toBe('number') +// expect(unpackedLossyInteger.toString()).toBe( +// int(i).inSafeRange() ? i.toString() : 'Infinity' +// ) + +// const bigint = packAndUnpack(i, { useBigInt: true }) +// expect(typeof bigint).toBe('bigint') +// expect(bigint.toString()).toBe(i.toString()) +// } +// }) + +// it('should pack BigInt with negative numbers', () => { +// let n, i +// // negative numbers +// for (n = 0; n <= 63; n += 1) { +// i = BigInt(-Math.pow(2, n)) +// expect(packAndUnpack(i).toString()).toBe(i.toString()) + +// const unpackedLossyInteger = packAndUnpack(i, { +// disableLosslessIntegers: true +// }) +// expect(typeof unpackedLossyInteger).toBe('number') +// expect(unpackedLossyInteger.toString()).toBe( +// int(i).inSafeRange() ? i.toString() : '-Infinity' +// ) + +// const bigint = packAndUnpack(i, { useBigInt: true }) +// expect(typeof bigint).toBe('bigint') +// expect(bigint.toString()).toBe(i.toString()) +// } +// }) + +// it('should pack strings', () => { +// expect(packAndUnpack('')).toBe('') +// expect(packAndUnpack('abcdefg123567')).toBe('abcdefg123567') +// const str = Array(65536 + 1).join('a') // 2 ^ 16 + 1 +// expect(packAndUnpack(str, { bufferSize: str.length + 8 })).toBe(str) +// }) + +// it('should pack structures', () => { +// expect(packAndUnpack(new Structure(1, ['Hello, world!!!'])).fields[0]).toBe( +// 'Hello, world!!!' +// ) +// }) + +// it('should pack lists', () => { +// const list = ['a', 'b'] +// const unpacked = packAndUnpack(list) +// expect(unpacked[0]).toBe(list[0]) +// expect(unpacked[1]).toBe(list[1]) +// }) + +// it('should pack long lists', () => { +// const listLength = 256 +// const list = [] +// for (let i = 0; i < listLength; i++) { +// list.push(null) +// } +// const unpacked = packAndUnpack(list, { bufferSize: 1400 }) +// expect(unpacked[0]).toBe(list[0]) +// expect(unpacked[1]).toBe(list[1]) +// }) + +// it.each( +// validNodesAndConfig() +// )('should unpack Nodes', (struct, expectedNode, config) => { +// const node = packAndUnpack(struct, config) + +// expect(node).toEqual(expectedNode) +// }) + +// it.each( +// invalidNodesConfig() +// )('should thrown error for unpacking invalid Nodes', (struct) => { +// expect(() => packAndUnpack(struct)).toThrow() +// }) + +// it.each( +// validRelationshipsAndConfig() +// )('should unpack Relationships', (struct, expectedRelationship, config) => { +// const releationship = packAndUnpack(struct, config) + +// expect(releationship).toEqual(expectedRelationship) +// }) + +// it.each( +// invalidRelationshipsConfig() +// )('should thrown error for unpacking invalid Relationships', (struct) => { +// expect(() => packAndUnpack(struct)).toThrow() +// }) + +// it.each( +// validUnboundRelationshipsAndConfig() +// )('should unpack UnboundRelationships', (struct, expectedRelationship, config) => { +// const releationship = packAndUnpack(struct, config) + +// expect(releationship).toEqual(expectedRelationship) +// }) + +// it.each( +// invalidUnboundRelationshipsConfig() +// )('should thrown error for unpacking invalid UnboundRelationships', (struct) => { +// expect(() => packAndUnpack(struct)).toThrow() +// }) + +// function validNodesAndConfig () { +// function validWithNumber () { +// const identity = 1 +// const labels = ['a', 'b'] +// const properties = { a: 1, b: 2 } +// const elementId = 'element_id_1' +// const expectedNode = new Node(identity, labels, properties, elementId) +// const nodeStruct = new Structure(0x4e, [ +// identity, labels, properties, elementId +// ]) +// return [nodeStruct, expectedNode, { disableLosslessIntegers: true, useBigInt: false }] +// } + +// function validWithoutOldIdentifiersLossy () { +// const identity = null +// const labels = ['a', 'b'] +// const properties = { a: 1, b: 2 } +// const elementId = 'element_id_1' +// const expectedNode = new Node(-1, labels, properties, elementId) +// const nodeStruct = new Structure(0x4e, [ +// identity, labels, properties, elementId +// ]) +// return [nodeStruct, expectedNode, { disableLosslessIntegers: true, useBigInt: false }] +// } + +// function validWithoutOldIdentifiersLosslessInteger () { +// const identity = null +// const labels = ['a', 'b'] +// const properties = { a: 1, b: 2 } +// const elementId = 'element_id_1' +// const expectedNode = new Node(int(-1), labels, properties, elementId) +// const nodeStruct = new Structure(0x4e, [ +// identity, labels, properties, elementId +// ]) +// return [nodeStruct, expectedNode, { disableLosslessIntegers: false, useBigInt: false }] +// } + +// function validWithoutOldIdentifiersBigInt () { +// const identity = null +// const labels = ['a', 'b'] +// const properties = { a: 1, b: 2 } +// const elementId = 'element_id_1' +// const expectedNode = new Node(BigInt(-1), labels, properties, elementId) +// const nodeStruct = new Structure(0x4e, [ +// identity, labels, properties, elementId +// ]) +// return [nodeStruct, expectedNode, { disableLosslessIntegers: false, useBigInt: true }] +// } + +// function validWithInt () { +// const identity = int(1) +// const labels = ['a', 'b'] +// const properties = { a: int(1), b: int(2) } +// const elementId = 'element_id_1' +// const expectedNode = new Node(identity, labels, properties, elementId) +// const nodeStruct = new Structure(0x4e, [ +// identity, labels, properties, elementId +// ]) +// return [nodeStruct, expectedNode, { disableLosslessIntegers: false, useBigInt: false }] +// } + +// function validWithBigInt () { +// const identity = BigInt(1) +// const labels = ['a', 'b'] +// const properties = { a: BigInt(1), b: BigInt(2) } +// const elementId = 'element_id_1' +// const expectedNode = new Node(identity, labels, properties, elementId) +// const nodeStruct = new Structure(0x4e, [ +// identity, labels, properties, elementId +// ]) +// return [nodeStruct, expectedNode, { disableLosslessIntegers: false, useBigInt: true }] +// } + +// return [ +// validWithNumber(), +// validWithInt(), +// validWithBigInt(), +// validWithoutOldIdentifiersLossy(), +// validWithoutOldIdentifiersLosslessInteger(), +// validWithoutOldIdentifiersBigInt() +// ] +// } + +// function invalidNodesConfig () { +// return [ +// [new Structure(0x4e, [1, ['a', 'b'], { a: 1, b: 2 }])], +// [new Structure(0x4e, [1, ['a', 'b'], { a: 1, b: 2 }, 'elementId', 'myId'])] +// ] +// } + +// function validRelationshipsAndConfig () { +// function validWithNumber () { +// const identity = 1 +// const start = 2 +// const end = 3 +// const type = 'KNOWS' +// const properties = { a: 1, b: 2 } +// const elementId = 'element_id_1' +// const startNodeElementId = 'element_id_2' +// const endNodeElementId = 'element_id_3' +// const expectedRel = new Relationship( +// identity, start, end, type, properties, +// elementId, startNodeElementId, endNodeElementId) +// const relStruct = new Structure(0x52, [ +// identity, start, end, type, properties, elementId, +// startNodeElementId, endNodeElementId +// ]) +// return [relStruct, expectedRel, { disableLosslessIntegers: true, useBigInt: false }] +// } + +// function validWithoutOldIdentifiersLossy () { +// const identity = null +// const start = null +// const end = null +// const type = 'KNOWS' +// const properties = { a: 1, b: 2 } +// const elementId = 'element_id_1' +// const startNodeElementId = 'element_id_2' +// const endNodeElementId = 'element_id_3' +// const expectedRel = new Relationship( +// -1, -1, -1, type, properties, +// elementId, startNodeElementId, endNodeElementId) +// const relStruct = new Structure(0x52, [ +// identity, start, end, type, properties, elementId, +// startNodeElementId, endNodeElementId +// ]) +// return [relStruct, expectedRel, { disableLosslessIntegers: true, useBigInt: false }] +// } + +// function validWithoutOldIdentifiersLossLess () { +// const identity = null +// const start = null +// const end = null +// const type = 'KNOWS' +// const properties = { a: 1, b: 2 } +// const elementId = 'element_id_1' +// const startNodeElementId = 'element_id_2' +// const endNodeElementId = 'element_id_3' +// const expectedRel = new Relationship( +// int(-1), int(-1), int(-1), type, properties, +// elementId, startNodeElementId, endNodeElementId) +// const relStruct = new Structure(0x52, [ +// identity, start, end, type, properties, elementId, +// startNodeElementId, endNodeElementId +// ]) +// return [relStruct, expectedRel, { disableLosslessIntegers: false, useBigInt: false }] +// } + +// function validWithoutOldIdentifiersBigInt () { +// const identity = null +// const start = null +// const end = null +// const type = 'KNOWS' +// const properties = { a: 1, b: 2 } +// const elementId = 'element_id_1' +// const startNodeElementId = 'element_id_2' +// const endNodeElementId = 'element_id_3' +// const expectedRel = new Relationship( +// BigInt(-1), BigInt(-1), BigInt(-1), type, properties, +// elementId, startNodeElementId, endNodeElementId) +// const relStruct = new Structure(0x52, [ +// identity, start, end, type, properties, elementId, +// startNodeElementId, endNodeElementId +// ]) +// return [relStruct, expectedRel, { disableLosslessIntegers: true, useBigInt: true }] +// } + +// function validWithInt () { +// const identity = int(1) +// const start = int(2) +// const end = int(3) +// const type = 'KNOWS' +// const properties = { a: int(1), b: int(2) } +// const elementId = 'element_id_1' +// const startNodeElementId = 'element_id_2' +// const endNodeElementId = 'element_id_3' +// const expectedRel = new Relationship( +// identity, start, end, type, properties, +// elementId, startNodeElementId, endNodeElementId) +// const relStruct = new Structure(0x52, [ +// identity, start, end, type, properties, elementId, +// startNodeElementId, endNodeElementId +// ]) +// return [relStruct, expectedRel, { disableLosslessIntegers: false, useBigInt: false }] +// } + +// function validWithBigInt () { +// const identity = BigInt(1) +// const start = BigInt(2) +// const end = BigInt(3) +// const type = 'KNOWS' +// const properties = { a: BigInt(1), b: BigInt(2) } +// const elementId = 'element_id_1' +// const startNodeElementId = 'element_id_2' +// const endNodeElementId = 'element_id_3' +// const expectedRel = new Relationship( +// identity, start, end, type, properties, +// elementId, startNodeElementId, endNodeElementId) +// const relStruct = new Structure(0x52, [ +// identity, start, end, type, properties, elementId, +// startNodeElementId, endNodeElementId +// ]) +// return [relStruct, expectedRel, { disableLosslessIntegers: false, useBigInt: true }] +// } + +// return [ +// validWithNumber(), +// validWithInt(), +// validWithBigInt(), +// validWithoutOldIdentifiersLossy(), +// validWithoutOldIdentifiersLossLess(), +// validWithoutOldIdentifiersBigInt() +// ] +// } + +// function invalidRelationshipsConfig () { +// return [ +// [new Structure(0x52, [1, 2, 3, 'rel', { a: 1, b: 2 }, 'elementId', 'startNodeId'])], +// [new Structure(0x52, [1, 2, 3, 'rel', { a: 1, b: 2 }, 'elementId', 'startNodeId', 'endNodeId', 'myId'])] +// ] +// } + +// function validUnboundRelationshipsAndConfig () { +// function validWithNumber () { +// const identity = 1 +// const type = 'DOESNT_KNOW' +// const properties = { a: 1, b: 2 } +// const elementId = 'element_id_1' +// const expectedUnboundRel = new UnboundRelationship(identity, type, properties, elementId) +// const struct = new Structure(0x72, [ +// identity, type, properties, elementId +// ]) +// return [struct, expectedUnboundRel, { disableLosslessIntegers: true, useBigInt: false }] +// } + +// function validWithoutOldIdentifiersLossy () { +// const identity = null +// const type = 'DOESNT_KNOW' +// const properties = { a: 1, b: 2 } +// const elementId = 'element_id_1' +// const expectedUnboundRel = new UnboundRelationship(-1, type, properties, elementId) +// const struct = new Structure(0x72, [ +// identity, type, properties, elementId +// ]) +// return [struct, expectedUnboundRel, { disableLosslessIntegers: true, useBigInt: false }] +// } + +// function validWithoutOldIdentifiersLossless () { +// const identity = null +// const type = 'DOESNT_KNOW' +// const properties = { a: 1, b: 2 } +// const elementId = 'element_id_1' +// const expectedUnboundRel = new UnboundRelationship(int(-1), type, properties, elementId) +// const struct = new Structure(0x72, [ +// identity, type, properties, elementId +// ]) +// return [struct, expectedUnboundRel, { disableLosslessIntegers: false, useBigInt: false }] +// } + +// function validWithoutOldIdentifiersBigInt () { +// const identity = null +// const type = 'DOESNT_KNOW' +// const properties = { a: 1, b: 2 } +// const elementId = 'element_id_1' +// const expectedUnboundRel = new UnboundRelationship(BigInt(-1), type, properties, elementId) +// const struct = new Structure(0x72, [ +// identity, type, properties, elementId +// ]) +// return [struct, expectedUnboundRel, { disableLosslessIntegers: false, useBigInt: true }] +// } + +// function validWithInt () { +// const identity = int(1) +// const type = 'DOESNT_KNOW' +// const properties = { a: int(1), b: int(2) } +// const elementId = 'element_id_1' +// const expectedUnboundRel = new UnboundRelationship(identity, type, properties, elementId) +// const struct = new Structure(0x72, [ +// identity, type, properties, elementId +// ]) +// return [struct, expectedUnboundRel, { disableLosslessIntegers: false, useBigInt: false }] +// } + +// function validWithBigInt () { +// const identity = BigInt(1) +// const type = 'DOESNT_KNOW' +// const properties = { a: BigInt(1), b: BigInt(2) } +// const elementId = 'element_id_1' +// const expectedUnboundRel = new UnboundRelationship(identity, type, properties, elementId) +// const struct = new Structure(0x72, [ +// identity, type, properties, elementId +// ]) +// return [struct, expectedUnboundRel, { disableLosslessIntegers: false, useBigInt: true }] +// } + +// return [ +// validWithNumber(), +// validWithInt(), +// validWithBigInt(), +// validWithoutOldIdentifiersLossy(), +// validWithoutOldIdentifiersLossless(), +// validWithoutOldIdentifiersBigInt() +// ] +// } + +// function invalidUnboundRelationshipsConfig () { +// return [ +// [new Structure(0x72, [1, 'DOESNT_KNOW', { a: 1, b: 2 }])], +// [new Structure(0x72, [1, 'DOESNT_KNOW', { a: 1, b: 2 }, 'elementId', 'myId'])] +// ] +// } +// }) + +// function packAndUnpack ( +// val, +// { bufferSize = 128, disableLosslessIntegers = false, useBigInt = false } = {} +// ) { +// const buffer = alloc(bufferSize) +// new Packer(buffer).packable(val)() +// buffer.reset() +// return new Unpacker(disableLosslessIntegers, useBigInt).unpack(buffer) +// } From 2584700b87ff95350a4a02f1b3e2d68e8102b2f6 Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Thu, 9 Jun 2022 15:04:59 +0200 Subject: [PATCH 13/18] Add tests for protocol v1 --- .../src/packstream/packstream-v1.js | 2 +- .../bolt-protocol-v1.test.js.snap | 111 +++++++++ .../test/bolt/bolt-protocol-v1.test.js | 227 +++++++++++++++++- 3 files changed, 338 insertions(+), 2 deletions(-) create mode 100644 packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v1.test.js.snap diff --git a/packages/bolt-connection/src/packstream/packstream-v1.js b/packages/bolt-connection/src/packstream/packstream-v1.js index 100d6232b..b71ef43f0 100644 --- a/packages/bolt-connection/src/packstream/packstream-v1.js +++ b/packages/bolt-connection/src/packstream/packstream-v1.js @@ -79,7 +79,7 @@ class Packer { try { x = dehydrateStruct(x) } catch (ex) { - return () => ex + return () => { throw ex } } if (x === null) { diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v1.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v1.test.js.snap new file mode 100644 index 000000000..a842698e4 --- /dev/null +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v1.test.js.snap @@ -0,0 +1,111 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`#unit BoltProtocolV1 .packable() should pack not pack graph types (Node) 1`] = `"It is not allowed to pass nodes in query parameters, given: (c:a {a:\\"b\\"})"`; + +exports[`#unit BoltProtocolV1 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; + +exports[`#unit BoltProtocolV1 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; + +exports[`#unit BoltProtocolV1 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; + +exports[`#unit BoltProtocolV1 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; + +exports[`#unit BoltProtocolV1 .packable() should pack types introduced afterwards as Map (Date) 1`] = ` +Object { + "day": 1, + "month": 1, + "year": 1, +} +`; + +exports[`#unit BoltProtocolV1 .packable() should pack types introduced afterwards as Map (DateTime) 1`] = ` +Object { + "day": 1, + "hour": 1, + "minute": 1, + "month": 1, + "nanosecond": 1, + "second": 1, + "timeZoneOffsetSeconds": 1, + "year": 1, +} +`; + +exports[`#unit BoltProtocolV1 .packable() should pack types introduced afterwards as Map (Duration) 1`] = ` +Object { + "days": 1, + "months": 1, + "nanoseconds": Integer { + "high": 0, + "low": 1, + }, + "seconds": Integer { + "high": 0, + "low": 1, + }, +} +`; + +exports[`#unit BoltProtocolV1 .packable() should pack types introduced afterwards as Map (LocalDateTime) 1`] = ` +Object { + "day": 1, + "hour": 1, + "minute": 1, + "month": 1, + "nanosecond": 1, + "second": 1, + "year": 1, +} +`; + +exports[`#unit BoltProtocolV1 .packable() should pack types introduced afterwards as Map (LocalTime) 1`] = ` +Object { + "hour": 1, + "minute": 1, + "nanosecond": 1, + "second": 1, +} +`; + +exports[`#unit BoltProtocolV1 .packable() should pack types introduced afterwards as Map (Point2D) 1`] = ` +Object { + "srid": 1, + "x": 1, + "y": 1, +} +`; + +exports[`#unit BoltProtocolV1 .packable() should pack types introduced afterwards as Map (Point3D) 1`] = ` +Object { + "srid": 1, + "x": 1, + "y": 1, + "z": 1, +} +`; + +exports[`#unit BoltProtocolV1 .packable() should pack types introduced afterwards as Map (Time) 1`] = ` +Object { + "hour": 1, + "minute": 1, + "nanosecond": 1, + "second": 1, + "timeZoneOffsetSeconds": 1, +} +`; + +exports[`#unit BoltProtocolV1 .unpack() should not unpack graph types with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV1 .unpack() should not unpack graph types with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV1 .unpack() should not unpack graph types with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV1 .unpack() should not unpack graph types with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV1 .unpack() should not unpack graph types with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; + +exports[`#unit BoltProtocolV1 .unpack() should not unpack graph types with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; + +exports[`#unit BoltProtocolV1 .unpack() should not unpack graph types with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV1 .unpack() should not unpack graph types with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js index b11757ed7..08f408955 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js @@ -19,9 +19,11 @@ import BoltProtocolV1 from '../../src/bolt/bolt-protocol-v1' import RequestMessage from '../../src/bolt/request-message' -import { internal } from 'neo4j-driver-core' +import { Date, DateTime, Duration, internal, LocalDateTime, LocalTime, Path, PathSegment, Point, Relationship, Time, UnboundRelationship, Node } from 'neo4j-driver-core' import utils from '../test-utils' import { LoginObserver } from '../../src/bolt/stream-observers' +import { alloc } from '../../src/channel' +import { structure } from '../../src/packstream' const WRITE = 'WRITE' @@ -360,4 +362,227 @@ describe('#unit BoltProtocolV1', () => { expect(observer._highRecordWatermark).toEqual(200) }) }) + + describe('.packable()', () => { + it.each([ + ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], + ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], + ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], + ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ])('should pack not pack graph types (%s)', (_, graphType) => { + const protocol = new BoltProtocolV1( + new utils.MessageRecordingConnection(), + null, + false + ) + + const packable = protocol.packable(graphType) + + expect(packable).toThrowErrorMatchingSnapshot() + }) + + it.each([ + ['Duration', new Duration(1, 1, 1, 1)], + ['LocalTime', new LocalTime(1, 1, 1, 1)], + ['Time', new Time(1, 1, 1, 1, 1)], + ['Date', new Date(1, 1, 1)], + ['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)], + ['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)], + ['Point2D', new Point(1, 1, 1)], + ['Point3D', new Point(1, 1, 1, 1)] + ])('should pack types introduced afterwards as Map (%s)', (_, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV1( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(object) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toMatchSnapshot() + }) + }) + + describe('.unpack()', () => { + it.each([ + [ + 'Node', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }]), + new Node(1, ['a'], { c: 'd' }) + ], + [ + 'Relationship', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }]), + new Relationship(1, 2, 3, '4', { 5: 6 }) + ], + [ + 'UnboundRelationship', + new structure.Structure(0x72, [1, '2', { 3: 4 }]), + new UnboundRelationship(1, '2', { 3: 4 }) + ], + [ + 'Path', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2] + ] + ), + new Path( + new Node(1, ['2'], { 3: '4' }), + new Node(2, ['3'], { 4: '5' }), + [ + new PathSegment( + new Node(1, ['2'], { 3: '4' }), + new Relationship(3, 1, 4, 'rel1', { 4: '5' }), + new Node(4, ['5'], { 6: 7 }) + ), + new PathSegment( + new Node(4, ['5'], { 6: 7 }), + new Relationship(5, 4, 2, 'rel2', { 6: 7 }), + new Node(2, ['3'], { 4: '5' }) + ) + ] + ) + ] + ])('should unpack graph types (%s)', (_, struct, graphObject) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV1( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(graphObject) + }) + + it.each([ + [ + 'Node with less fields', + new structure.Structure(0x4e, [1, ['a']]) + ], + [ + 'Node with more fields', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }, '1']) + ], + [ + 'Relationship with less fields', + new structure.Structure(0x52, [1, 2, 3, '4']) + ], + [ + 'Relationship with more fields', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }, '1', '2', '3']) + ], + [ + 'UnboundRelationship with less fields', + new structure.Structure(0x72, [1, '2']) + ], + [ + 'UnboundRelationship with more fields', + new structure.Structure(0x72, [1, '2', { 3: 4 }, '1']) + ], + [ + 'Path with less fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ] + ] + ) + ], + [ + 'Path with more fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2], + 'a' + ] + ) + ] + ])('should not unpack graph types with wrong size(%s)', (_, struct) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV1( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot() + }) + + it.each([ + ['Point', new structure.Structure(0x58, [1, 2, 3])], + ['Point3D', new structure.Structure(0x59, [1, 2, 3, 4])], + ['Duration', new structure.Structure(0x45, [1, 2, 3, 4])], + ['LocalTime', new structure.Structure(0x74, [1])], + ['Time', new structure.Structure(0x54, [1, 2])], + ['Date', new structure.Structure(0x44, [1])], + ['LocalDateTime', new structure.Structure(0x64, [1, 2])], + ['DateTimeWithZoneOffset', new structure.Structure(0x46, [1, 2, 3])], + ['DateTimeWithZoneId', new structure.Structure(0x66, [1, 2, 'America/Sao Paulo'])] + ])('should unpack future structs as structs (%s)', (_, struct) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV1( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(struct) + }) + }) }) From 253a132678e95169d8db0b6b71a27220e0594cbb Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Thu, 9 Jun 2022 15:39:23 +0200 Subject: [PATCH 14/18] Add tests for protocol v2 --- .../src/bolt/bolt-protocol-v2.transformer.js | 2 +- .../bolt-protocol-v2.test.js.snap | 63 ++++ .../test/bolt/bolt-protocol-v1.test.js | 17 +- .../test/bolt/bolt-protocol-v2.test.js | 355 ++++++++++++++++++ 4 files changed, 435 insertions(+), 2 deletions(-) create mode 100644 packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js index 21db0feab..cb90b8bca 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js @@ -320,7 +320,7 @@ function createDateTimeWithOffsetTransformer ({ disableLosslessIntegers, useBigI return new structure.Structure(DATE_TIME_WITH_ZONE_OFFSET, [epochSecond, nano, timeZoneOffsetSeconds]) }, fromStructure: struct => { - struct.verifyStructSize( + structure.verifyStructSize( 'DateTimeWithZoneOffset', DATE_TIME_WITH_ZONE_OFFSET_STRUCT_SIZE, struct.size diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap new file mode 100644 index 000000000..cba590a5b --- /dev/null +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (Node) 1`] = `"It is not allowed to pass nodes in query parameters, given: (c:a {a:\\"b\\"})"`; + +exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; + +exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; + +exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; + +exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js index 08f408955..941b7fb56 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js @@ -19,7 +19,21 @@ import BoltProtocolV1 from '../../src/bolt/bolt-protocol-v1' import RequestMessage from '../../src/bolt/request-message' -import { Date, DateTime, Duration, internal, LocalDateTime, LocalTime, Path, PathSegment, Point, Relationship, Time, UnboundRelationship, Node } from 'neo4j-driver-core' +import { + Date, + DateTime, + Duration, + internal, + LocalDateTime, + LocalTime, + Path, + PathSegment, + Point, + Relationship, + Time, + UnboundRelationship, + Node +} from 'neo4j-driver-core' import utils from '../test-utils' import { LoginObserver } from '../../src/bolt/stream-observers' import { alloc } from '../../src/channel' @@ -406,6 +420,7 @@ describe('#unit BoltProtocolV1', () => { buffer.reset() const unpacked = protocol.unpack(buffer) + expect(unpacked).toBeInstanceOf(Object) expect(unpacked).toMatchSnapshot() }) }) diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js index 99eb55a28..ed9cea22e 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js @@ -20,6 +20,24 @@ import BoltProtocolV2 from '../../src/bolt/bolt-protocol-v2' import utils from '../test-utils' +import { + Date, + DateTime, + Duration, + LocalDateTime, + LocalTime, + Path, + PathSegment, + Point, + Relationship, + Time, + UnboundRelationship, + Node +} from 'neo4j-driver-core' + +import { alloc } from '../../src/channel' +import { structure } from '../../src/packstream' + describe('#unit BoltProtocolV2', () => { beforeEach(() => { expect.extend(utils.matchers) @@ -111,4 +129,341 @@ describe('#unit BoltProtocolV2', () => { expect(observer._highRecordWatermark).toEqual(200) }) }) + + describe('.packable()', () => { + it.each([ + ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], + ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], + ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], + ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ])('should pack not pack graph types (%s)', (_, graphType) => { + const protocol = new BoltProtocolV2( + new utils.MessageRecordingConnection(), + null, + false + ) + + const packable = protocol.packable(graphType) + + expect(packable).toThrowErrorMatchingSnapshot() + }) + + it.each([ + ['Duration', new Duration(1, 1, 1, 1)], + ['LocalTime', new LocalTime(1, 1, 1, 1)], + ['Time', new Time(1, 1, 1, 1, 1)], + ['Date', new Date(1, 1, 1)], + ['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)], + ['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')], + ['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)], + ['Point2D', new Point(1, 1, 1)], + ['Point3D', new Point(1, 1, 1, 1)] + ])('should pack spatial types and temporal types (%s)', (_, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV2( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(object) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) + + describe('.unpack()', () => { + it.each([ + [ + 'Node', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }]), + new Node(1, ['a'], { c: 'd' }) + ], + [ + 'Relationship', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }]), + new Relationship(1, 2, 3, '4', { 5: 6 }) + ], + [ + 'UnboundRelationship', + new structure.Structure(0x72, [1, '2', { 3: 4 }]), + new UnboundRelationship(1, '2', { 3: 4 }) + ], + [ + 'Path', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2] + ] + ), + new Path( + new Node(1, ['2'], { 3: '4' }), + new Node(2, ['3'], { 4: '5' }), + [ + new PathSegment( + new Node(1, ['2'], { 3: '4' }), + new Relationship(3, 1, 4, 'rel1', { 4: '5' }), + new Node(4, ['5'], { 6: 7 }) + ), + new PathSegment( + new Node(4, ['5'], { 6: 7 }), + new Relationship(5, 4, 2, 'rel2', { 6: 7 }), + new Node(2, ['3'], { 4: '5' }) + ) + ] + ) + ] + ])('should unpack graph types (%s)', (_, struct, graphObject) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV2( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(graphObject) + }) + + it.each([ + [ + 'Node with less fields', + new structure.Structure(0x4e, [1, ['a']]) + ], + [ + 'Node with more fields', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }, '1']) + ], + [ + 'Relationship with less fields', + new structure.Structure(0x52, [1, 2, 3, '4']) + ], + [ + 'Relationship with more fields', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }, '1', '2', '3']) + ], + [ + 'UnboundRelationship with less fields', + new structure.Structure(0x72, [1, '2']) + ], + [ + 'UnboundRelationship with more fields', + new structure.Structure(0x72, [1, '2', { 3: 4 }, '1']) + ], + [ + 'Path with less fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ] + ] + ) + ], + [ + 'Path with more fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2], + 'a' + ] + ) + ], + [ + 'Point with less fields', + new structure.Structure(0x58, [1, 2]) + ], + [ + 'Point with more fields', + new structure.Structure(0x58, [1, 2, 3, 4]) + ], + [ + 'Point3D with less fields', + new structure.Structure(0x59, [1, 2, 3]) + ], + + [ + 'Point3D with more fields', + new structure.Structure(0x59, [1, 2, 3, 4, 6]) + ], + [ + 'Duration with less fields', + new structure.Structure(0x45, [1, 2, 3]) + ], + [ + 'Duration with more fields', + new structure.Structure(0x45, [1, 2, 3, 4, 5]) + ], + [ + 'LocalTime with less fields', + new structure.Structure(0x74, []) + ], + [ + 'LocalTime with more fields', + new structure.Structure(0x74, [1, 2]) + ], + [ + 'Time with less fields', + new structure.Structure(0x54, [1]) + ], + [ + 'Time with more fileds', + new structure.Structure(0x54, [1, 2, 3]) + ], + [ + 'Date with less fields', + new structure.Structure(0x44, []) + ], + [ + 'Date with more fields', + new structure.Structure(0x44, [1, 2]) + ], + [ + 'LocalDateTime with less fields', + new structure.Structure(0x64, [1]) + ], + [ + 'LocalDateTime with more fields', + new structure.Structure(0x64, [1, 2, 3]) + ], + [ + 'DateTimeWithZoneOffset with less fields', + new structure.Structure(0x46, [1, 2]) + ], + [ + 'DateTimeWithZoneOffset with more fields', + new structure.Structure(0x46, [1, 2, 3, 4]) + ], + [ + 'DateTimeWithZoneId with less fields', + new structure.Structure(0x66, [1, 2]) + ], + [ + 'DateTimeWithZoneId with more fields', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) + ] + ])('should not unpack with wrong size(%s)', (_, struct) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV2( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot() + }) + + it.each([ + [ + 'Point', + new structure.Structure(0x58, [1, 2, 3]), + new Point(1, 2, 3) + ], + [ + 'Point3D', + new structure.Structure(0x59, [1, 2, 3, 4]), + new Point(1, 2, 3, 4) + ], + [ + 'Duration', + new structure.Structure(0x45, [1, 2, 3, 4]), + new Duration(1, 2, 3, 4) + ], + [ + 'LocalTime', + new structure.Structure(0x74, [1]), + new LocalTime(0, 0, 0, 1) + ], + [ + 'Time', + new structure.Structure(0x54, [1, 2]), + new Time(0, 0, 0, 1, 2) + ], + [ + 'Date', + new structure.Structure(0x44, [1]), + new Date(1970, 1, 2) + ], + [ + 'LocalDateTime', + new structure.Structure(0x64, [1, 2]), + new LocalDateTime(1970, 1, 1, 0, 0, 1, 2) + ], + [ + 'DateTimeWithZoneOffset', + new structure.Structure(0x46, [1, 2, 3]), + new DateTime(1970, 1, 1, 0, 0, 1, 2, 3) + ], + [ + 'DateTimeWithZoneId', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), + new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') + ] + ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV2( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) }) From 6111c52ae5a1e371c2c6ac333e6db45c139338dd Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Thu, 9 Jun 2022 15:48:05 +0200 Subject: [PATCH 15/18] Add tests for protocol from v3 to v4x4 --- .../bolt-protocol-v3.test.js.snap | 63 ++++ .../bolt-protocol-v4x0.test.js.snap | 63 ++++ .../bolt-protocol-v4x1.test.js.snap | 63 ++++ .../bolt-protocol-v4x2.test.js.snap | 63 ++++ .../bolt-protocol-v4x3.test.js.snap | 63 ++++ .../bolt-protocol-v4x4.test.js.snap | 63 ++++ .../test/bolt/bolt-protocol-v3.test.js | 357 +++++++++++++++++- .../test/bolt/bolt-protocol-v4x0.test.js | 356 ++++++++++++++++- .../test/bolt/bolt-protocol-v4x1.test.js | 356 ++++++++++++++++- .../test/bolt/bolt-protocol-v4x2.test.js | 356 ++++++++++++++++- .../test/bolt/bolt-protocol-v4x3.test.js | 356 ++++++++++++++++- .../test/bolt/bolt-protocol-v4x4.test.js | 356 ++++++++++++++++- 12 files changed, 2509 insertions(+), 6 deletions(-) create mode 100644 packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap create mode 100644 packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap create mode 100644 packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap create mode 100644 packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap create mode 100644 packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap create mode 100644 packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap new file mode 100644 index 000000000..e8cabffd0 --- /dev/null +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`#unit BoltProtocolV3 .packable() should pack not pack graph types (Node) 1`] = `"It is not allowed to pass nodes in query parameters, given: (c:a {a:\\"b\\"})"`; + +exports[`#unit BoltProtocolV3 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; + +exports[`#unit BoltProtocolV3 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; + +exports[`#unit BoltProtocolV3 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; + +exports[`#unit BoltProtocolV3 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap new file mode 100644 index 000000000..179683940 --- /dev/null +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`#unit BoltProtocolV4x0 .packable() should pack not pack graph types (Node) 1`] = `"It is not allowed to pass nodes in query parameters, given: (c:a {a:\\"b\\"})"`; + +exports[`#unit BoltProtocolV4x0 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; + +exports[`#unit BoltProtocolV4x0 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; + +exports[`#unit BoltProtocolV4x0 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; + +exports[`#unit BoltProtocolV4x0 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap new file mode 100644 index 000000000..0a9e6f004 --- /dev/null +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`#unit BoltProtocolV4x1 .packable() should pack not pack graph types (Node) 1`] = `"It is not allowed to pass nodes in query parameters, given: (c:a {a:\\"b\\"})"`; + +exports[`#unit BoltProtocolV4x1 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; + +exports[`#unit BoltProtocolV4x1 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; + +exports[`#unit BoltProtocolV4x1 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; + +exports[`#unit BoltProtocolV4x1 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap new file mode 100644 index 000000000..f32882847 --- /dev/null +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`#unit BoltProtocolV4x2 .packable() should pack not pack graph types (Node) 1`] = `"It is not allowed to pass nodes in query parameters, given: (c:a {a:\\"b\\"})"`; + +exports[`#unit BoltProtocolV4x2 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; + +exports[`#unit BoltProtocolV4x2 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; + +exports[`#unit BoltProtocolV4x2 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; + +exports[`#unit BoltProtocolV4x2 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap new file mode 100644 index 000000000..7340c380b --- /dev/null +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`#unit BoltProtocolV4x3 .packable() should pack not pack graph types (Node) 1`] = `"It is not allowed to pass nodes in query parameters, given: (c:a {a:\\"b\\"})"`; + +exports[`#unit BoltProtocolV4x3 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; + +exports[`#unit BoltProtocolV4x3 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; + +exports[`#unit BoltProtocolV4x3 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; + +exports[`#unit BoltProtocolV4x3 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; + +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"`; + +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"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap new file mode 100644 index 000000000..f8bf09f24 --- /dev/null +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`#unit BoltProtocolV4x4 .packable() should pack not pack graph types (Node) 1`] = `"It is not allowed to pass nodes in query parameters, given: (c:a {a:\\"b\\"})"`; + +exports[`#unit BoltProtocolV4x4 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; + +exports[`#unit BoltProtocolV4x4 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; + +exports[`#unit BoltProtocolV4x4 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; + +exports[`#unit BoltProtocolV4x4 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; + +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"`; + +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"`; diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js index 205ced51a..b285b2cc0 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js @@ -20,12 +20,30 @@ import BoltProtocolV3 from '../../src/bolt/bolt-protocol-v3' import RequestMessage from '../../src/bolt/request-message' import utils from '../test-utils' -import { internal } from 'neo4j-driver-core' import { ProcedureRouteObserver, ResultStreamObserver } from '../../src/bolt/stream-observers' +import { + Date, + DateTime, + Duration, + LocalDateTime, + LocalTime, + Path, + PathSegment, + Point, + Relationship, + Time, + UnboundRelationship, + Node, + internal +} from 'neo4j-driver-core' + +import { alloc } from '../../src/channel' +import { structure } from '../../src/packstream' + const { bookmarks: { Bookmarks }, txConfig: { TxConfig } @@ -316,6 +334,343 @@ describe('#unit BoltProtocolV3', () => { expect(observer._highRecordWatermark).toEqual(200) }) }) + + describe('.packable()', () => { + it.each([ + ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], + ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], + ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], + ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ])('should pack not pack graph types (%s)', (_, graphType) => { + const protocol = new BoltProtocolV3( + new utils.MessageRecordingConnection(), + null, + false + ) + + const packable = protocol.packable(graphType) + + expect(packable).toThrowErrorMatchingSnapshot() + }) + + it.each([ + ['Duration', new Duration(1, 1, 1, 1)], + ['LocalTime', new LocalTime(1, 1, 1, 1)], + ['Time', new Time(1, 1, 1, 1, 1)], + ['Date', new Date(1, 1, 1)], + ['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)], + ['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')], + ['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)], + ['Point2D', new Point(1, 1, 1)], + ['Point3D', new Point(1, 1, 1, 1)] + ])('should pack spatial types and temporal types (%s)', (_, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV3( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(object) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) + + describe('.unpack()', () => { + it.each([ + [ + 'Node', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }]), + new Node(1, ['a'], { c: 'd' }) + ], + [ + 'Relationship', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }]), + new Relationship(1, 2, 3, '4', { 5: 6 }) + ], + [ + 'UnboundRelationship', + new structure.Structure(0x72, [1, '2', { 3: 4 }]), + new UnboundRelationship(1, '2', { 3: 4 }) + ], + [ + 'Path', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2] + ] + ), + new Path( + new Node(1, ['2'], { 3: '4' }), + new Node(2, ['3'], { 4: '5' }), + [ + new PathSegment( + new Node(1, ['2'], { 3: '4' }), + new Relationship(3, 1, 4, 'rel1', { 4: '5' }), + new Node(4, ['5'], { 6: 7 }) + ), + new PathSegment( + new Node(4, ['5'], { 6: 7 }), + new Relationship(5, 4, 2, 'rel2', { 6: 7 }), + new Node(2, ['3'], { 4: '5' }) + ) + ] + ) + ] + ])('should unpack graph types (%s)', (_, struct, graphObject) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV3( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(graphObject) + }) + + it.each([ + [ + 'Node with less fields', + new structure.Structure(0x4e, [1, ['a']]) + ], + [ + 'Node with more fields', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }, '1']) + ], + [ + 'Relationship with less fields', + new structure.Structure(0x52, [1, 2, 3, '4']) + ], + [ + 'Relationship with more fields', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }, '1', '2', '3']) + ], + [ + 'UnboundRelationship with less fields', + new structure.Structure(0x72, [1, '2']) + ], + [ + 'UnboundRelationship with more fields', + new structure.Structure(0x72, [1, '2', { 3: 4 }, '1']) + ], + [ + 'Path with less fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ] + ] + ) + ], + [ + 'Path with more fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2], + 'a' + ] + ) + ], + [ + 'Point with less fields', + new structure.Structure(0x58, [1, 2]) + ], + [ + 'Point with more fields', + new structure.Structure(0x58, [1, 2, 3, 4]) + ], + [ + 'Point3D with less fields', + new structure.Structure(0x59, [1, 2, 3]) + ], + + [ + 'Point3D with more fields', + new structure.Structure(0x59, [1, 2, 3, 4, 6]) + ], + [ + 'Duration with less fields', + new structure.Structure(0x45, [1, 2, 3]) + ], + [ + 'Duration with more fields', + new structure.Structure(0x45, [1, 2, 3, 4, 5]) + ], + [ + 'LocalTime with less fields', + new structure.Structure(0x74, []) + ], + [ + 'LocalTime with more fields', + new structure.Structure(0x74, [1, 2]) + ], + [ + 'Time with less fields', + new structure.Structure(0x54, [1]) + ], + [ + 'Time with more fileds', + new structure.Structure(0x54, [1, 2, 3]) + ], + [ + 'Date with less fields', + new structure.Structure(0x44, []) + ], + [ + 'Date with more fields', + new structure.Structure(0x44, [1, 2]) + ], + [ + 'LocalDateTime with less fields', + new structure.Structure(0x64, [1]) + ], + [ + 'LocalDateTime with more fields', + new structure.Structure(0x64, [1, 2, 3]) + ], + [ + 'DateTimeWithZoneOffset with less fields', + new structure.Structure(0x46, [1, 2]) + ], + [ + 'DateTimeWithZoneOffset with more fields', + new structure.Structure(0x46, [1, 2, 3, 4]) + ], + [ + 'DateTimeWithZoneId with less fields', + new structure.Structure(0x66, [1, 2]) + ], + [ + 'DateTimeWithZoneId with more fields', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) + ] + ])('should not unpack with wrong size(%s)', (_, struct) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV3( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot() + }) + + it.each([ + [ + 'Point', + new structure.Structure(0x58, [1, 2, 3]), + new Point(1, 2, 3) + ], + [ + 'Point3D', + new structure.Structure(0x59, [1, 2, 3, 4]), + new Point(1, 2, 3, 4) + ], + [ + 'Duration', + new structure.Structure(0x45, [1, 2, 3, 4]), + new Duration(1, 2, 3, 4) + ], + [ + 'LocalTime', + new structure.Structure(0x74, [1]), + new LocalTime(0, 0, 0, 1) + ], + [ + 'Time', + new structure.Structure(0x54, [1, 2]), + new Time(0, 0, 0, 1, 2) + ], + [ + 'Date', + new structure.Structure(0x44, [1]), + new Date(1970, 1, 2) + ], + [ + 'LocalDateTime', + new structure.Structure(0x64, [1, 2]), + new LocalDateTime(1970, 1, 1, 0, 0, 1, 2) + ], + [ + 'DateTimeWithZoneOffset', + new structure.Structure(0x46, [1, 2, 3]), + new DateTime(1970, 1, 1, 0, 0, 1, 2, 3) + ], + [ + 'DateTimeWithZoneId', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), + new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') + ] + ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV3( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) }) class SpiedBoltProtocolV3 extends BoltProtocolV3 { diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js index 819eaa932..a0c8486b5 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js @@ -25,7 +25,24 @@ import { ResultStreamObserver } from '../../src/bolt/stream-observers' -import { internal } from 'neo4j-driver-core' +import { + Date, + DateTime, + Duration, + LocalDateTime, + LocalTime, + Path, + PathSegment, + Point, + Relationship, + Time, + UnboundRelationship, + Node, + internal +} from 'neo4j-driver-core' + +import { alloc } from '../../src/channel' +import { structure } from '../../src/packstream' const WRITE = 'WRITE' @@ -235,6 +252,343 @@ describe('#unit BoltProtocolV4x0', () => { expect(observer._highRecordWatermark).toEqual(200) }) }) + + describe('.packable()', () => { + it.each([ + ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], + ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], + ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], + ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ])('should pack not pack graph types (%s)', (_, graphType) => { + const protocol = new BoltProtocolV4x0( + new utils.MessageRecordingConnection(), + null, + false + ) + + const packable = protocol.packable(graphType) + + expect(packable).toThrowErrorMatchingSnapshot() + }) + + it.each([ + ['Duration', new Duration(1, 1, 1, 1)], + ['LocalTime', new LocalTime(1, 1, 1, 1)], + ['Time', new Time(1, 1, 1, 1, 1)], + ['Date', new Date(1, 1, 1)], + ['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)], + ['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')], + ['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)], + ['Point2D', new Point(1, 1, 1)], + ['Point3D', new Point(1, 1, 1, 1)] + ])('should pack spatial types and temporal types (%s)', (_, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x0( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(object) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) + + describe('.unpack()', () => { + it.each([ + [ + 'Node', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }]), + new Node(1, ['a'], { c: 'd' }) + ], + [ + 'Relationship', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }]), + new Relationship(1, 2, 3, '4', { 5: 6 }) + ], + [ + 'UnboundRelationship', + new structure.Structure(0x72, [1, '2', { 3: 4 }]), + new UnboundRelationship(1, '2', { 3: 4 }) + ], + [ + 'Path', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2] + ] + ), + new Path( + new Node(1, ['2'], { 3: '4' }), + new Node(2, ['3'], { 4: '5' }), + [ + new PathSegment( + new Node(1, ['2'], { 3: '4' }), + new Relationship(3, 1, 4, 'rel1', { 4: '5' }), + new Node(4, ['5'], { 6: 7 }) + ), + new PathSegment( + new Node(4, ['5'], { 6: 7 }), + new Relationship(5, 4, 2, 'rel2', { 6: 7 }), + new Node(2, ['3'], { 4: '5' }) + ) + ] + ) + ] + ])('should unpack graph types (%s)', (_, struct, graphObject) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x0( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(graphObject) + }) + + it.each([ + [ + 'Node with less fields', + new structure.Structure(0x4e, [1, ['a']]) + ], + [ + 'Node with more fields', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }, '1']) + ], + [ + 'Relationship with less fields', + new structure.Structure(0x52, [1, 2, 3, '4']) + ], + [ + 'Relationship with more fields', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }, '1', '2', '3']) + ], + [ + 'UnboundRelationship with less fields', + new structure.Structure(0x72, [1, '2']) + ], + [ + 'UnboundRelationship with more fields', + new structure.Structure(0x72, [1, '2', { 3: 4 }, '1']) + ], + [ + 'Path with less fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ] + ] + ) + ], + [ + 'Path with more fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2], + 'a' + ] + ) + ], + [ + 'Point with less fields', + new structure.Structure(0x58, [1, 2]) + ], + [ + 'Point with more fields', + new structure.Structure(0x58, [1, 2, 3, 4]) + ], + [ + 'Point3D with less fields', + new structure.Structure(0x59, [1, 2, 3]) + ], + + [ + 'Point3D with more fields', + new structure.Structure(0x59, [1, 2, 3, 4, 6]) + ], + [ + 'Duration with less fields', + new structure.Structure(0x45, [1, 2, 3]) + ], + [ + 'Duration with more fields', + new structure.Structure(0x45, [1, 2, 3, 4, 5]) + ], + [ + 'LocalTime with less fields', + new structure.Structure(0x74, []) + ], + [ + 'LocalTime with more fields', + new structure.Structure(0x74, [1, 2]) + ], + [ + 'Time with less fields', + new structure.Structure(0x54, [1]) + ], + [ + 'Time with more fileds', + new structure.Structure(0x54, [1, 2, 3]) + ], + [ + 'Date with less fields', + new structure.Structure(0x44, []) + ], + [ + 'Date with more fields', + new structure.Structure(0x44, [1, 2]) + ], + [ + 'LocalDateTime with less fields', + new structure.Structure(0x64, [1]) + ], + [ + 'LocalDateTime with more fields', + new structure.Structure(0x64, [1, 2, 3]) + ], + [ + 'DateTimeWithZoneOffset with less fields', + new structure.Structure(0x46, [1, 2]) + ], + [ + 'DateTimeWithZoneOffset with more fields', + new structure.Structure(0x46, [1, 2, 3, 4]) + ], + [ + 'DateTimeWithZoneId with less fields', + new structure.Structure(0x66, [1, 2]) + ], + [ + 'DateTimeWithZoneId with more fields', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) + ] + ])('should not unpack with wrong size(%s)', (_, struct) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x0( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot() + }) + + it.each([ + [ + 'Point', + new structure.Structure(0x58, [1, 2, 3]), + new Point(1, 2, 3) + ], + [ + 'Point3D', + new structure.Structure(0x59, [1, 2, 3, 4]), + new Point(1, 2, 3, 4) + ], + [ + 'Duration', + new structure.Structure(0x45, [1, 2, 3, 4]), + new Duration(1, 2, 3, 4) + ], + [ + 'LocalTime', + new structure.Structure(0x74, [1]), + new LocalTime(0, 0, 0, 1) + ], + [ + 'Time', + new structure.Structure(0x54, [1, 2]), + new Time(0, 0, 0, 1, 2) + ], + [ + 'Date', + new structure.Structure(0x44, [1]), + new Date(1970, 1, 2) + ], + [ + 'LocalDateTime', + new structure.Structure(0x64, [1, 2]), + new LocalDateTime(1970, 1, 1, 0, 0, 1, 2) + ], + [ + 'DateTimeWithZoneOffset', + new structure.Structure(0x46, [1, 2, 3]), + new DateTime(1970, 1, 1, 0, 0, 1, 2, 3) + ], + [ + 'DateTimeWithZoneId', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), + new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') + ] + ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x0( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) }) class SpiedBoltProtocolV4x0 extends BoltProtocolV4x0 { diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js index 545ea97dd..01c76a880 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js @@ -19,7 +19,24 @@ import BoltProtocolV4x1 from '../../src/bolt/bolt-protocol-v4x1' import utils from '../test-utils' -import { internal } from 'neo4j-driver-core' +import { + Date, + DateTime, + Duration, + LocalDateTime, + LocalTime, + Path, + PathSegment, + Point, + Relationship, + Time, + UnboundRelationship, + Node, + internal +} from 'neo4j-driver-core' + +import { alloc } from '../../src/channel' +import { structure } from '../../src/packstream' const { txConfig: { TxConfig }, @@ -109,4 +126,341 @@ describe('#unit BoltProtocolV4x1', () => { expect(observer._highRecordWatermark).toEqual(200) }) }) + + describe('.packable()', () => { + it.each([ + ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], + ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], + ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], + ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ])('should pack not pack graph types (%s)', (_, graphType) => { + const protocol = new BoltProtocolV4x1( + new utils.MessageRecordingConnection(), + null, + false + ) + + const packable = protocol.packable(graphType) + + expect(packable).toThrowErrorMatchingSnapshot() + }) + + it.each([ + ['Duration', new Duration(1, 1, 1, 1)], + ['LocalTime', new LocalTime(1, 1, 1, 1)], + ['Time', new Time(1, 1, 1, 1, 1)], + ['Date', new Date(1, 1, 1)], + ['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)], + ['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')], + ['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)], + ['Point2D', new Point(1, 1, 1)], + ['Point3D', new Point(1, 1, 1, 1)] + ])('should pack spatial types and temporal types (%s)', (_, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x1( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(object) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) + + describe('.unpack()', () => { + it.each([ + [ + 'Node', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }]), + new Node(1, ['a'], { c: 'd' }) + ], + [ + 'Relationship', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }]), + new Relationship(1, 2, 3, '4', { 5: 6 }) + ], + [ + 'UnboundRelationship', + new structure.Structure(0x72, [1, '2', { 3: 4 }]), + new UnboundRelationship(1, '2', { 3: 4 }) + ], + [ + 'Path', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2] + ] + ), + new Path( + new Node(1, ['2'], { 3: '4' }), + new Node(2, ['3'], { 4: '5' }), + [ + new PathSegment( + new Node(1, ['2'], { 3: '4' }), + new Relationship(3, 1, 4, 'rel1', { 4: '5' }), + new Node(4, ['5'], { 6: 7 }) + ), + new PathSegment( + new Node(4, ['5'], { 6: 7 }), + new Relationship(5, 4, 2, 'rel2', { 6: 7 }), + new Node(2, ['3'], { 4: '5' }) + ) + ] + ) + ] + ])('should unpack graph types (%s)', (_, struct, graphObject) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x1( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(graphObject) + }) + + it.each([ + [ + 'Node with less fields', + new structure.Structure(0x4e, [1, ['a']]) + ], + [ + 'Node with more fields', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }, '1']) + ], + [ + 'Relationship with less fields', + new structure.Structure(0x52, [1, 2, 3, '4']) + ], + [ + 'Relationship with more fields', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }, '1', '2', '3']) + ], + [ + 'UnboundRelationship with less fields', + new structure.Structure(0x72, [1, '2']) + ], + [ + 'UnboundRelationship with more fields', + new structure.Structure(0x72, [1, '2', { 3: 4 }, '1']) + ], + [ + 'Path with less fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ] + ] + ) + ], + [ + 'Path with more fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2], + 'a' + ] + ) + ], + [ + 'Point with less fields', + new structure.Structure(0x58, [1, 2]) + ], + [ + 'Point with more fields', + new structure.Structure(0x58, [1, 2, 3, 4]) + ], + [ + 'Point3D with less fields', + new structure.Structure(0x59, [1, 2, 3]) + ], + + [ + 'Point3D with more fields', + new structure.Structure(0x59, [1, 2, 3, 4, 6]) + ], + [ + 'Duration with less fields', + new structure.Structure(0x45, [1, 2, 3]) + ], + [ + 'Duration with more fields', + new structure.Structure(0x45, [1, 2, 3, 4, 5]) + ], + [ + 'LocalTime with less fields', + new structure.Structure(0x74, []) + ], + [ + 'LocalTime with more fields', + new structure.Structure(0x74, [1, 2]) + ], + [ + 'Time with less fields', + new structure.Structure(0x54, [1]) + ], + [ + 'Time with more fileds', + new structure.Structure(0x54, [1, 2, 3]) + ], + [ + 'Date with less fields', + new structure.Structure(0x44, []) + ], + [ + 'Date with more fields', + new structure.Structure(0x44, [1, 2]) + ], + [ + 'LocalDateTime with less fields', + new structure.Structure(0x64, [1]) + ], + [ + 'LocalDateTime with more fields', + new structure.Structure(0x64, [1, 2, 3]) + ], + [ + 'DateTimeWithZoneOffset with less fields', + new structure.Structure(0x46, [1, 2]) + ], + [ + 'DateTimeWithZoneOffset with more fields', + new structure.Structure(0x46, [1, 2, 3, 4]) + ], + [ + 'DateTimeWithZoneId with less fields', + new structure.Structure(0x66, [1, 2]) + ], + [ + 'DateTimeWithZoneId with more fields', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) + ] + ])('should not unpack with wrong size(%s)', (_, struct) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x1( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot() + }) + + it.each([ + [ + 'Point', + new structure.Structure(0x58, [1, 2, 3]), + new Point(1, 2, 3) + ], + [ + 'Point3D', + new structure.Structure(0x59, [1, 2, 3, 4]), + new Point(1, 2, 3, 4) + ], + [ + 'Duration', + new structure.Structure(0x45, [1, 2, 3, 4]), + new Duration(1, 2, 3, 4) + ], + [ + 'LocalTime', + new structure.Structure(0x74, [1]), + new LocalTime(0, 0, 0, 1) + ], + [ + 'Time', + new structure.Structure(0x54, [1, 2]), + new Time(0, 0, 0, 1, 2) + ], + [ + 'Date', + new structure.Structure(0x44, [1]), + new Date(1970, 1, 2) + ], + [ + 'LocalDateTime', + new structure.Structure(0x64, [1, 2]), + new LocalDateTime(1970, 1, 1, 0, 0, 1, 2) + ], + [ + 'DateTimeWithZoneOffset', + new structure.Structure(0x46, [1, 2, 3]), + new DateTime(1970, 1, 1, 0, 0, 1, 2, 3) + ], + [ + 'DateTimeWithZoneId', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), + new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') + ] + ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x1( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) }) diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js index 6a7604bda..8f8288319 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js @@ -19,7 +19,24 @@ import BoltProtocolV4x2 from '../../src/bolt/bolt-protocol-v4x2' import utils from '../test-utils' -import { internal } from 'neo4j-driver-core' +import { + Date, + DateTime, + Duration, + LocalDateTime, + LocalTime, + Path, + PathSegment, + Point, + Relationship, + Time, + UnboundRelationship, + Node, + internal +} from 'neo4j-driver-core' + +import { alloc } from '../../src/channel' +import { structure } from '../../src/packstream' const { txConfig: { TxConfig }, @@ -108,4 +125,341 @@ describe('#unit BoltProtocolV4x2', () => { expect(observer._highRecordWatermark).toEqual(200) }) }) + + describe('.packable()', () => { + it.each([ + ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], + ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], + ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], + ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ])('should pack not pack graph types (%s)', (_, graphType) => { + const protocol = new BoltProtocolV4x2( + new utils.MessageRecordingConnection(), + null, + false + ) + + const packable = protocol.packable(graphType) + + expect(packable).toThrowErrorMatchingSnapshot() + }) + + it.each([ + ['Duration', new Duration(1, 1, 1, 1)], + ['LocalTime', new LocalTime(1, 1, 1, 1)], + ['Time', new Time(1, 1, 1, 1, 1)], + ['Date', new Date(1, 1, 1)], + ['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)], + ['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')], + ['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)], + ['Point2D', new Point(1, 1, 1)], + ['Point3D', new Point(1, 1, 1, 1)] + ])('should pack spatial types and temporal types (%s)', (_, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x2( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(object) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) + + describe('.unpack()', () => { + it.each([ + [ + 'Node', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }]), + new Node(1, ['a'], { c: 'd' }) + ], + [ + 'Relationship', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }]), + new Relationship(1, 2, 3, '4', { 5: 6 }) + ], + [ + 'UnboundRelationship', + new structure.Structure(0x72, [1, '2', { 3: 4 }]), + new UnboundRelationship(1, '2', { 3: 4 }) + ], + [ + 'Path', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2] + ] + ), + new Path( + new Node(1, ['2'], { 3: '4' }), + new Node(2, ['3'], { 4: '5' }), + [ + new PathSegment( + new Node(1, ['2'], { 3: '4' }), + new Relationship(3, 1, 4, 'rel1', { 4: '5' }), + new Node(4, ['5'], { 6: 7 }) + ), + new PathSegment( + new Node(4, ['5'], { 6: 7 }), + new Relationship(5, 4, 2, 'rel2', { 6: 7 }), + new Node(2, ['3'], { 4: '5' }) + ) + ] + ) + ] + ])('should unpack graph types (%s)', (_, struct, graphObject) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x2( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(graphObject) + }) + + it.each([ + [ + 'Node with less fields', + new structure.Structure(0x4e, [1, ['a']]) + ], + [ + 'Node with more fields', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }, '1']) + ], + [ + 'Relationship with less fields', + new structure.Structure(0x52, [1, 2, 3, '4']) + ], + [ + 'Relationship with more fields', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }, '1', '2', '3']) + ], + [ + 'UnboundRelationship with less fields', + new structure.Structure(0x72, [1, '2']) + ], + [ + 'UnboundRelationship with more fields', + new structure.Structure(0x72, [1, '2', { 3: 4 }, '1']) + ], + [ + 'Path with less fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ] + ] + ) + ], + [ + 'Path with more fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2], + 'a' + ] + ) + ], + [ + 'Point with less fields', + new structure.Structure(0x58, [1, 2]) + ], + [ + 'Point with more fields', + new structure.Structure(0x58, [1, 2, 3, 4]) + ], + [ + 'Point3D with less fields', + new structure.Structure(0x59, [1, 2, 3]) + ], + + [ + 'Point3D with more fields', + new structure.Structure(0x59, [1, 2, 3, 4, 6]) + ], + [ + 'Duration with less fields', + new structure.Structure(0x45, [1, 2, 3]) + ], + [ + 'Duration with more fields', + new structure.Structure(0x45, [1, 2, 3, 4, 5]) + ], + [ + 'LocalTime with less fields', + new structure.Structure(0x74, []) + ], + [ + 'LocalTime with more fields', + new structure.Structure(0x74, [1, 2]) + ], + [ + 'Time with less fields', + new structure.Structure(0x54, [1]) + ], + [ + 'Time with more fileds', + new structure.Structure(0x54, [1, 2, 3]) + ], + [ + 'Date with less fields', + new structure.Structure(0x44, []) + ], + [ + 'Date with more fields', + new structure.Structure(0x44, [1, 2]) + ], + [ + 'LocalDateTime with less fields', + new structure.Structure(0x64, [1]) + ], + [ + 'LocalDateTime with more fields', + new structure.Structure(0x64, [1, 2, 3]) + ], + [ + 'DateTimeWithZoneOffset with less fields', + new structure.Structure(0x46, [1, 2]) + ], + [ + 'DateTimeWithZoneOffset with more fields', + new structure.Structure(0x46, [1, 2, 3, 4]) + ], + [ + 'DateTimeWithZoneId with less fields', + new structure.Structure(0x66, [1, 2]) + ], + [ + 'DateTimeWithZoneId with more fields', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) + ] + ])('should not unpack with wrong size(%s)', (_, struct) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x2( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot() + }) + + it.each([ + [ + 'Point', + new structure.Structure(0x58, [1, 2, 3]), + new Point(1, 2, 3) + ], + [ + 'Point3D', + new structure.Structure(0x59, [1, 2, 3, 4]), + new Point(1, 2, 3, 4) + ], + [ + 'Duration', + new structure.Structure(0x45, [1, 2, 3, 4]), + new Duration(1, 2, 3, 4) + ], + [ + 'LocalTime', + new structure.Structure(0x74, [1]), + new LocalTime(0, 0, 0, 1) + ], + [ + 'Time', + new structure.Structure(0x54, [1, 2]), + new Time(0, 0, 0, 1, 2) + ], + [ + 'Date', + new structure.Structure(0x44, [1]), + new Date(1970, 1, 2) + ], + [ + 'LocalDateTime', + new structure.Structure(0x64, [1, 2]), + new LocalDateTime(1970, 1, 1, 0, 0, 1, 2) + ], + [ + 'DateTimeWithZoneOffset', + new structure.Structure(0x46, [1, 2, 3]), + new DateTime(1970, 1, 1, 0, 0, 1, 2, 3) + ], + [ + 'DateTimeWithZoneId', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), + new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') + ] + ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x2( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) }) diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js index fc3b846b8..508a14470 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js @@ -21,7 +21,24 @@ import BoltProtocolV4x3 from '../../src/bolt/bolt-protocol-v4x3' import RequestMessage from '../../src/bolt/request-message' import utils from '../test-utils' import { RouteObserver } from '../../src/bolt/stream-observers' -import { internal } from 'neo4j-driver-core' +import { + Date, + DateTime, + Duration, + LocalDateTime, + LocalTime, + Path, + PathSegment, + Point, + Relationship, + Time, + UnboundRelationship, + Node, + internal +} from 'neo4j-driver-core' + +import { alloc } from '../../src/channel' +import { structure } from '../../src/packstream' const WRITE = 'WRITE' @@ -320,4 +337,341 @@ describe('#unit BoltProtocolV4x3', () => { expect(observer._highRecordWatermark).toEqual(200) }) }) + + describe('.packable()', () => { + it.each([ + ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], + ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], + ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], + ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ])('should pack not pack graph types (%s)', (_, graphType) => { + const protocol = new BoltProtocolV4x3( + new utils.MessageRecordingConnection(), + null, + false + ) + + const packable = protocol.packable(graphType) + + expect(packable).toThrowErrorMatchingSnapshot() + }) + + it.each([ + ['Duration', new Duration(1, 1, 1, 1)], + ['LocalTime', new LocalTime(1, 1, 1, 1)], + ['Time', new Time(1, 1, 1, 1, 1)], + ['Date', new Date(1, 1, 1)], + ['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)], + ['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')], + ['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)], + ['Point2D', new Point(1, 1, 1)], + ['Point3D', new Point(1, 1, 1, 1)] + ])('should pack spatial types and temporal types (%s)', (_, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x3( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(object) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) + + describe('.unpack()', () => { + it.each([ + [ + 'Node', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }]), + new Node(1, ['a'], { c: 'd' }) + ], + [ + 'Relationship', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }]), + new Relationship(1, 2, 3, '4', { 5: 6 }) + ], + [ + 'UnboundRelationship', + new structure.Structure(0x72, [1, '2', { 3: 4 }]), + new UnboundRelationship(1, '2', { 3: 4 }) + ], + [ + 'Path', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2] + ] + ), + new Path( + new Node(1, ['2'], { 3: '4' }), + new Node(2, ['3'], { 4: '5' }), + [ + new PathSegment( + new Node(1, ['2'], { 3: '4' }), + new Relationship(3, 1, 4, 'rel1', { 4: '5' }), + new Node(4, ['5'], { 6: 7 }) + ), + new PathSegment( + new Node(4, ['5'], { 6: 7 }), + new Relationship(5, 4, 2, 'rel2', { 6: 7 }), + new Node(2, ['3'], { 4: '5' }) + ) + ] + ) + ] + ])('should unpack graph types (%s)', (_, struct, graphObject) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x3( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(graphObject) + }) + + it.each([ + [ + 'Node with less fields', + new structure.Structure(0x4e, [1, ['a']]) + ], + [ + 'Node with more fields', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }, '1']) + ], + [ + 'Relationship with less fields', + new structure.Structure(0x52, [1, 2, 3, '4']) + ], + [ + 'Relationship with more fields', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }, '1', '2', '3']) + ], + [ + 'UnboundRelationship with less fields', + new structure.Structure(0x72, [1, '2']) + ], + [ + 'UnboundRelationship with more fields', + new structure.Structure(0x72, [1, '2', { 3: 4 }, '1']) + ], + [ + 'Path with less fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ] + ] + ) + ], + [ + 'Path with more fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2], + 'a' + ] + ) + ], + [ + 'Point with less fields', + new structure.Structure(0x58, [1, 2]) + ], + [ + 'Point with more fields', + new structure.Structure(0x58, [1, 2, 3, 4]) + ], + [ + 'Point3D with less fields', + new structure.Structure(0x59, [1, 2, 3]) + ], + + [ + 'Point3D with more fields', + new structure.Structure(0x59, [1, 2, 3, 4, 6]) + ], + [ + 'Duration with less fields', + new structure.Structure(0x45, [1, 2, 3]) + ], + [ + 'Duration with more fields', + new structure.Structure(0x45, [1, 2, 3, 4, 5]) + ], + [ + 'LocalTime with less fields', + new structure.Structure(0x74, []) + ], + [ + 'LocalTime with more fields', + new structure.Structure(0x74, [1, 2]) + ], + [ + 'Time with less fields', + new structure.Structure(0x54, [1]) + ], + [ + 'Time with more fileds', + new structure.Structure(0x54, [1, 2, 3]) + ], + [ + 'Date with less fields', + new structure.Structure(0x44, []) + ], + [ + 'Date with more fields', + new structure.Structure(0x44, [1, 2]) + ], + [ + 'LocalDateTime with less fields', + new structure.Structure(0x64, [1]) + ], + [ + 'LocalDateTime with more fields', + new structure.Structure(0x64, [1, 2, 3]) + ], + [ + 'DateTimeWithZoneOffset with less fields', + new structure.Structure(0x46, [1, 2]) + ], + [ + 'DateTimeWithZoneOffset with more fields', + new structure.Structure(0x46, [1, 2, 3, 4]) + ], + [ + 'DateTimeWithZoneId with less fields', + new structure.Structure(0x66, [1, 2]) + ], + [ + 'DateTimeWithZoneId with more fields', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) + ] + ])('should not unpack with wrong size(%s)', (_, struct) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x3( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot() + }) + + it.each([ + [ + 'Point', + new structure.Structure(0x58, [1, 2, 3]), + new Point(1, 2, 3) + ], + [ + 'Point3D', + new structure.Structure(0x59, [1, 2, 3, 4]), + new Point(1, 2, 3, 4) + ], + [ + 'Duration', + new structure.Structure(0x45, [1, 2, 3, 4]), + new Duration(1, 2, 3, 4) + ], + [ + 'LocalTime', + new structure.Structure(0x74, [1]), + new LocalTime(0, 0, 0, 1) + ], + [ + 'Time', + new structure.Structure(0x54, [1, 2]), + new Time(0, 0, 0, 1, 2) + ], + [ + 'Date', + new structure.Structure(0x44, [1]), + new Date(1970, 1, 2) + ], + [ + 'LocalDateTime', + new structure.Structure(0x64, [1, 2]), + new LocalDateTime(1970, 1, 1, 0, 0, 1, 2) + ], + [ + 'DateTimeWithZoneOffset', + new structure.Structure(0x46, [1, 2, 3]), + new DateTime(1970, 1, 1, 0, 0, 1, 2, 3) + ], + [ + 'DateTimeWithZoneId', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), + new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') + ] + ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x3( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) }) diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js index d4f779b16..9c1eeda3e 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js @@ -21,7 +21,24 @@ import BoltProtocolV4x4 from '../../src/bolt/bolt-protocol-v4x4' import RequestMessage from '../../src/bolt/request-message' import utils from '../test-utils' import { RouteObserver } from '../../src/bolt/stream-observers' -import { internal } from 'neo4j-driver-core' +import { + Date, + DateTime, + Duration, + LocalDateTime, + LocalTime, + Path, + PathSegment, + Point, + Relationship, + Time, + UnboundRelationship, + Node, + internal +} from 'neo4j-driver-core' + +import { alloc } from '../../src/channel' +import { structure } from '../../src/packstream' const WRITE = 'WRITE' @@ -353,4 +370,341 @@ describe('#unit BoltProtocolV4x4', () => { expect(observer._highRecordWatermark).toEqual(200) }) }) + + describe('.packable()', () => { + it.each([ + ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], + ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], + ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], + ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ])('should pack not pack graph types (%s)', (_, graphType) => { + const protocol = new BoltProtocolV4x4( + new utils.MessageRecordingConnection(), + null, + false + ) + + const packable = protocol.packable(graphType) + + expect(packable).toThrowErrorMatchingSnapshot() + }) + + it.each([ + ['Duration', new Duration(1, 1, 1, 1)], + ['LocalTime', new LocalTime(1, 1, 1, 1)], + ['Time', new Time(1, 1, 1, 1, 1)], + ['Date', new Date(1, 1, 1)], + ['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)], + ['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')], + ['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)], + ['Point2D', new Point(1, 1, 1)], + ['Point3D', new Point(1, 1, 1, 1)] + ])('should pack spatial types and temporal types (%s)', (_, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x4( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(object) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) + + describe('.unpack()', () => { + it.each([ + [ + 'Node', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }]), + new Node(1, ['a'], { c: 'd' }) + ], + [ + 'Relationship', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }]), + new Relationship(1, 2, 3, '4', { 5: 6 }) + ], + [ + 'UnboundRelationship', + new structure.Structure(0x72, [1, '2', { 3: 4 }]), + new UnboundRelationship(1, '2', { 3: 4 }) + ], + [ + 'Path', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2] + ] + ), + new Path( + new Node(1, ['2'], { 3: '4' }), + new Node(2, ['3'], { 4: '5' }), + [ + new PathSegment( + new Node(1, ['2'], { 3: '4' }), + new Relationship(3, 1, 4, 'rel1', { 4: '5' }), + new Node(4, ['5'], { 6: 7 }) + ), + new PathSegment( + new Node(4, ['5'], { 6: 7 }), + new Relationship(5, 4, 2, 'rel2', { 6: 7 }), + new Node(2, ['3'], { 4: '5' }) + ) + ] + ) + ] + ])('should unpack graph types (%s)', (_, struct, graphObject) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x4( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(graphObject) + }) + + it.each([ + [ + 'Node with less fields', + new structure.Structure(0x4e, [1, ['a']]) + ], + [ + 'Node with more fields', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }, '1']) + ], + [ + 'Relationship with less fields', + new structure.Structure(0x52, [1, 2, 3, '4']) + ], + [ + 'Relationship with more fields', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }, '1', '2', '3']) + ], + [ + 'UnboundRelationship with less fields', + new structure.Structure(0x72, [1, '2']) + ], + [ + 'UnboundRelationship with more fields', + new structure.Structure(0x72, [1, '2', { 3: 4 }, '1']) + ], + [ + 'Path with less fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ] + ] + ) + ], + [ + 'Path with more fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2], + 'a' + ] + ) + ], + [ + 'Point with less fields', + new structure.Structure(0x58, [1, 2]) + ], + [ + 'Point with more fields', + new structure.Structure(0x58, [1, 2, 3, 4]) + ], + [ + 'Point3D with less fields', + new structure.Structure(0x59, [1, 2, 3]) + ], + + [ + 'Point3D with more fields', + new structure.Structure(0x59, [1, 2, 3, 4, 6]) + ], + [ + 'Duration with less fields', + new structure.Structure(0x45, [1, 2, 3]) + ], + [ + 'Duration with more fields', + new structure.Structure(0x45, [1, 2, 3, 4, 5]) + ], + [ + 'LocalTime with less fields', + new structure.Structure(0x74, []) + ], + [ + 'LocalTime with more fields', + new structure.Structure(0x74, [1, 2]) + ], + [ + 'Time with less fields', + new structure.Structure(0x54, [1]) + ], + [ + 'Time with more fileds', + new structure.Structure(0x54, [1, 2, 3]) + ], + [ + 'Date with less fields', + new structure.Structure(0x44, []) + ], + [ + 'Date with more fields', + new structure.Structure(0x44, [1, 2]) + ], + [ + 'LocalDateTime with less fields', + new structure.Structure(0x64, [1]) + ], + [ + 'LocalDateTime with more fields', + new structure.Structure(0x64, [1, 2, 3]) + ], + [ + 'DateTimeWithZoneOffset with less fields', + new structure.Structure(0x46, [1, 2]) + ], + [ + 'DateTimeWithZoneOffset with more fields', + new structure.Structure(0x46, [1, 2, 3, 4]) + ], + [ + 'DateTimeWithZoneId with less fields', + new structure.Structure(0x66, [1, 2]) + ], + [ + 'DateTimeWithZoneId with more fields', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) + ] + ])('should not unpack with wrong size(%s)', (_, struct) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x4( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot() + }) + + it.each([ + [ + 'Point', + new structure.Structure(0x58, [1, 2, 3]), + new Point(1, 2, 3) + ], + [ + 'Point3D', + new structure.Structure(0x59, [1, 2, 3, 4]), + new Point(1, 2, 3, 4) + ], + [ + 'Duration', + new structure.Structure(0x45, [1, 2, 3, 4]), + new Duration(1, 2, 3, 4) + ], + [ + 'LocalTime', + new structure.Structure(0x74, [1]), + new LocalTime(0, 0, 0, 1) + ], + [ + 'Time', + new structure.Structure(0x54, [1, 2]), + new Time(0, 0, 0, 1, 2) + ], + [ + 'Date', + new structure.Structure(0x44, [1]), + new Date(1970, 1, 2) + ], + [ + 'LocalDateTime', + new structure.Structure(0x64, [1, 2]), + new LocalDateTime(1970, 1, 1, 0, 0, 1, 2) + ], + [ + 'DateTimeWithZoneOffset', + new structure.Structure(0x46, [1, 2, 3]), + new DateTime(1970, 1, 1, 0, 0, 1, 2, 3) + ], + [ + 'DateTimeWithZoneId', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), + new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') + ] + ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV4x4( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) }) From 358fd035f40225723968f3441c632d920e3ceb45 Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Thu, 9 Jun 2022 16:22:22 +0200 Subject: [PATCH 16/18] Add protocol tests for 5x0 --- .../bolt-connection/src/packstream/index.js | 3 +- .../src/packstream/packstream-v5.js | 121 ---- .../bolt-protocol-v5x0.test.js.snap | 63 ++ .../test/bolt/bolt-protocol-v5x0.test.js | 357 ++++++++++- .../test/packstream/packstream-v5.test.js | 555 ------------------ 5 files changed, 419 insertions(+), 680 deletions(-) delete mode 100644 packages/bolt-connection/src/packstream/packstream-v5.js create mode 100644 packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap delete mode 100644 packages/bolt-connection/test/packstream/packstream-v5.test.js diff --git a/packages/bolt-connection/src/packstream/index.js b/packages/bolt-connection/src/packstream/index.js index 371da8003..d1ef5caf4 100644 --- a/packages/bolt-connection/src/packstream/index.js +++ b/packages/bolt-connection/src/packstream/index.js @@ -19,9 +19,8 @@ import * as v1 from './packstream-v1' import * as v2 from './packstream-v2' -import * as v5 from './packstream-v5' import * as structure from './structure' -export { v1, v2, v5, structure } +export { v1, v2, structure } export default v2 diff --git a/packages/bolt-connection/src/packstream/packstream-v5.js b/packages/bolt-connection/src/packstream/packstream-v5.js deleted file mode 100644 index dd110f5a8..000000000 --- a/packages/bolt-connection/src/packstream/packstream-v5.js +++ /dev/null @@ -1,121 +0,0 @@ -/** - * Copyright (c) "Neo4j" - * Neo4j Sweden AB [http://neo4j.com] - * - * This file is part of Neo4j. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as v2 from './packstream-v2' -import { - Node, - Relationship, - UnboundRelationship, - int -} from 'neo4j-driver-core' - -const NODE_STRUCT_SIZE = 4 -const RELATIONSHIP_STRUCT_SIZE = 8 -const UNBOUND_RELATIONSHIP_STRUCT_SIZE = 4 - -export class Packer extends v2.Packer { - // This implementation is the same -} - -export class Unpacker extends v2.Unpacker { - /** - * @constructor - * @param {boolean} disableLosslessIntegers if this unpacker should convert all received integers to native JS numbers. - * @param {boolean} useBigInt if this unpacker should convert all received integers to Bigint - */ - constructor (disableLosslessIntegers = false, useBigInt = false) { - super(disableLosslessIntegers, useBigInt) - this._defaultIdentity = this._getDefaultIdentity() - } - - _getDefaultIdentity () { - if (this._useBigInt) { - return BigInt(-1) - } else if (this._disableLosslessIntegers) { - return -1 - } else { - return int(-1) - } - } - - _unpackNode (structure) { - this._verifyStructSize('Node', NODE_STRUCT_SIZE, structure.size) - - const [identity, lables, properties, elementId] = structure.fields - - return new Node( - _valueOrDefault(identity, this._defaultIdentity), // Identity - lables, // Labels - properties, // Properties, - elementId // ElementId - ) - } - - _unpackRelationship (structure) { - this._verifyStructSize('Relationship', RELATIONSHIP_STRUCT_SIZE, structure.size) - - const [ - identity, - startNodeIdentity, - endNodeIdentity, - type, - properties, - elementId, - startNodeElementId, - endNodeElementId - ] = structure.fields - - return new Relationship( - _valueOrDefault(identity, this._defaultIdentity), // Identity - _valueOrDefault(startNodeIdentity, this._defaultIdentity), // Start Node Identity - _valueOrDefault(endNodeIdentity, this._defaultIdentity), // End Node Identity - type, - properties, - elementId, - startNodeElementId, - endNodeElementId - ) - } - - _unpackUnboundRelationship (structure) { - this._verifyStructSize( - 'UnboundRelationship', - UNBOUND_RELATIONSHIP_STRUCT_SIZE, - structure.size - ) - - const [ - identity, - type, - properties, - elementId - ] = structure.fields - - return new UnboundRelationship( - _valueOrDefault(identity, this._defaultIdentity), // Identity - type, - properties, - elementId - ) - } -} - -function _valueOrDefault (value, defaultValue) { - return value === null ? defaultValue : value -} diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap new file mode 100644 index 000000000..0442a0f5f --- /dev/null +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`#unit BoltProtocolV5x0 .packable() should pack not pack graph types (Node) 1`] = `"It is not allowed to pass nodes in query parameters, given: (c:a {a:\\"b\\"})"`; + +exports[`#unit BoltProtocolV5x0 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; + +exports[`#unit BoltProtocolV5x0 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; + +exports[`#unit BoltProtocolV5x0 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; + +exports[`#unit BoltProtocolV5x0 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 8 but was 5"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 8 but was 9"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 4 but was 3"`; + +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 4 but was 5"`; diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js index ebb34dd52..a48adb55a 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js @@ -19,10 +19,26 @@ import BoltProtocolV5x0 from '../../src/bolt/bolt-protocol-v5x0' import RequestMessage from '../../src/bolt/request-message' -import { v2 } from '../../src/packstream' +import { v2, structure } from '../../src/packstream' import utils from '../test-utils' import { RouteObserver } from '../../src/bolt/stream-observers' -import { internal } from 'neo4j-driver-core' +import { + Date, + DateTime, + Duration, + LocalDateTime, + LocalTime, + Path, + PathSegment, + Point, + Relationship, + Time, + UnboundRelationship, + Node, + internal +} from 'neo4j-driver-core' + +import { alloc } from '../../src/channel' const WRITE = 'WRITE' @@ -366,4 +382,341 @@ describe('#unit BoltProtocolV5x0', () => { expect(protocol.unpacker()).toBeInstanceOf(v2.Unpacker) }) }) + + describe('.packable()', () => { + it.each([ + ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], + ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], + ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], + ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ])('should pack not pack graph types (%s)', (_, graphType) => { + const protocol = new BoltProtocolV5x0( + new utils.MessageRecordingConnection(), + null, + false + ) + + const packable = protocol.packable(graphType) + + expect(packable).toThrowErrorMatchingSnapshot() + }) + + it.each([ + ['Duration', new Duration(1, 1, 1, 1)], + ['LocalTime', new LocalTime(1, 1, 1, 1)], + ['Time', new Time(1, 1, 1, 1, 1)], + ['Date', new Date(1, 1, 1)], + ['LocalDateTime', new LocalDateTime(1, 1, 1, 1, 1, 1, 1)], + ['DateTimeWithZoneId', new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, 'America/Sao Paulo')], + ['DateTime', new DateTime(1, 1, 1, 1, 1, 1, 1, 1)], + ['Point2D', new Point(1, 1, 1)], + ['Point3D', new Point(1, 1, 1, 1)] + ])('should pack spatial types and temporal types (%s)', (_, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV5x0( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(object) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) + + describe('.unpack()', () => { + it.each([ + [ + 'Node', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }, 'elementId']), + new Node(1, ['a'], { c: 'd' }, 'elementId') + ], + [ + 'Relationship', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }, 'elementId', 'node1', 'node2']), + new Relationship(1, 2, 3, '4', { 5: 6 }, 'elementId', 'node1', 'node2') + ], + [ + 'UnboundRelationship', + new structure.Structure(0x72, [1, '2', { 3: 4 }, 'elementId']), + new UnboundRelationship(1, '2', { 3: 4 }, 'elementId') + ], + [ + 'Path', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }, 'node1']), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }, 'node2']), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }, 'node3']) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'reltype1', { 4: '5' }, 'rel1', 'node1', 'node2']), + new structure.Structure(0x52, [5, 4, 2, 'reltype2', { 6: 7 }, 'rel2', 'node2', 'node3']) + ], + [1, 1, 2, 2] + ] + ), + new Path( + new Node(1, ['2'], { 3: '4' }, 'node1'), + new Node(2, ['3'], { 4: '5' }, 'node3'), + [ + new PathSegment( + new Node(1, ['2'], { 3: '4' }, 'node1'), + new Relationship(3, 1, 4, 'reltype1', { 4: '5' }, 'rel1', 'node1', 'node2'), + new Node(4, ['5'], { 6: 7 }, 'node2') + ), + new PathSegment( + new Node(4, ['5'], { 6: 7 }, 'node2'), + new Relationship(5, 4, 2, 'reltype2', { 6: 7 }, 'rel2', 'node2', 'node3'), + new Node(2, ['3'], { 4: '5' }, 'node3') + ) + ] + ) + ] + ])('should unpack graph types (%s)', (_, struct, graphObject) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV5x0( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(graphObject) + }) + + it.each([ + [ + 'Node with less fields', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }]) + ], + [ + 'Node with more fields', + new structure.Structure(0x4e, [1, ['a'], { c: 'd' }, '1', 'b']) + ], + [ + 'Relationship with less fields', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }]) + ], + [ + 'Relationship with more fields', + new structure.Structure(0x52, [1, 2, 3, '4', { 5: 6 }, '1', '2', '3', '4']) + ], + [ + 'UnboundRelationship with less fields', + new structure.Structure(0x72, [1, '2', { 3: 4 }]) + ], + [ + 'UnboundRelationship with more fields', + new structure.Structure(0x72, [1, '2', { 3: 4 }, '1', '2']) + ], + [ + 'Path with less fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ] + ] + ) + ], + [ + 'Path with more fields', + new structure.Structure( + 0x50, + [ + [ + new structure.Structure(0x4e, [1, ['2'], { 3: '4' }]), + new structure.Structure(0x4e, [4, ['5'], { 6: 7 }]), + new structure.Structure(0x4e, [2, ['3'], { 4: '5' }]) + ], + [ + new structure.Structure(0x52, [3, 1, 4, 'rel1', { 4: '5' }]), + new structure.Structure(0x52, [5, 4, 2, 'rel2', { 6: 7 }]) + ], + [1, 1, 2, 2], + 'a' + ] + ) + ], + [ + 'Point with less fields', + new structure.Structure(0x58, [1, 2]) + ], + [ + 'Point with more fields', + new structure.Structure(0x58, [1, 2, 3, 4]) + ], + [ + 'Point3D with less fields', + new structure.Structure(0x59, [1, 2, 3]) + ], + + [ + 'Point3D with more fields', + new structure.Structure(0x59, [1, 2, 3, 4, 6]) + ], + [ + 'Duration with less fields', + new structure.Structure(0x45, [1, 2, 3]) + ], + [ + 'Duration with more fields', + new structure.Structure(0x45, [1, 2, 3, 4, 5]) + ], + [ + 'LocalTime with less fields', + new structure.Structure(0x74, []) + ], + [ + 'LocalTime with more fields', + new structure.Structure(0x74, [1, 2]) + ], + [ + 'Time with less fields', + new structure.Structure(0x54, [1]) + ], + [ + 'Time with more fileds', + new structure.Structure(0x54, [1, 2, 3]) + ], + [ + 'Date with less fields', + new structure.Structure(0x44, []) + ], + [ + 'Date with more fields', + new structure.Structure(0x44, [1, 2]) + ], + [ + 'LocalDateTime with less fields', + new structure.Structure(0x64, [1]) + ], + [ + 'LocalDateTime with more fields', + new structure.Structure(0x64, [1, 2, 3]) + ], + [ + 'DateTimeWithZoneOffset with less fields', + new structure.Structure(0x46, [1, 2]) + ], + [ + 'DateTimeWithZoneOffset with more fields', + new structure.Structure(0x46, [1, 2, 3, 4]) + ], + [ + 'DateTimeWithZoneId with less fields', + new structure.Structure(0x66, [1, 2]) + ], + [ + 'DateTimeWithZoneId with more fields', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) + ] + ])('should not unpack with wrong size(%s)', (_, struct) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV5x0( + new utils.MessageRecordingConnection(), + buffer, + false + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + expect(() => protocol.unpack(buffer)).toThrowErrorMatchingSnapshot() + }) + + it.each([ + [ + 'Point', + new structure.Structure(0x58, [1, 2, 3]), + new Point(1, 2, 3) + ], + [ + 'Point3D', + new structure.Structure(0x59, [1, 2, 3, 4]), + new Point(1, 2, 3, 4) + ], + [ + 'Duration', + new structure.Structure(0x45, [1, 2, 3, 4]), + new Duration(1, 2, 3, 4) + ], + [ + 'LocalTime', + new structure.Structure(0x74, [1]), + new LocalTime(0, 0, 0, 1) + ], + [ + 'Time', + new structure.Structure(0x54, [1, 2]), + new Time(0, 0, 0, 1, 2) + ], + [ + 'Date', + new structure.Structure(0x44, [1]), + new Date(1970, 1, 2) + ], + [ + 'LocalDateTime', + new structure.Structure(0x64, [1, 2]), + new LocalDateTime(1970, 1, 1, 0, 0, 1, 2) + ], + [ + 'DateTimeWithZoneOffset', + new structure.Structure(0x46, [1, 2, 3]), + new DateTime(1970, 1, 1, 0, 0, 1, 2, 3) + ], + [ + 'DateTimeWithZoneId', + new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), + new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') + ] + ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + const buffer = alloc(256) + const protocol = new BoltProtocolV5x0( + new utils.MessageRecordingConnection(), + buffer, + { + disableLosslessIntegers: true + } + ) + + const packable = protocol.packable(struct) + + expect(packable).not.toThrow() + + buffer.reset() + + const unpacked = protocol.unpack(buffer) + expect(unpacked).toEqual(object) + }) + }) }) diff --git a/packages/bolt-connection/test/packstream/packstream-v5.test.js b/packages/bolt-connection/test/packstream/packstream-v5.test.js deleted file mode 100644 index 08c71c41f..000000000 --- a/packages/bolt-connection/test/packstream/packstream-v5.test.js +++ /dev/null @@ -1,555 +0,0 @@ -/** - * Copyright (c) "Neo4j" - * Neo4j Sweden AB [http://neo4j.com] - * - * This file is part of Neo4j. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// import { int, Integer, Node, Relationship, UnboundRelationship } from 'neo4j-driver-core' -// import { alloc } from '../../src/channel' -// import { Packer, Unpacker } from '../../src/packstream/packstream-v5' -// import { Structure } from '../../src/packstream/structure' - -describe('dummy', () => { - it('should export the expected transformers factories', () => { - expect(true).toBe(true) - }) -}) - -// xdescribe('#unit PackStreamV5', () => { -// it('should pack integers with small numbers', () => { -// let n, i -// // test small numbers -// for (n = -999; n <= 999; n += 1) { -// i = int(n) -// expect(packAndUnpack(i).toString()).toBe(i.toString()) -// expect( -// packAndUnpack(i, { disableLosslessIntegers: true }).toString() -// ).toBe(i.toString()) -// expect(packAndUnpack(i, { useBigInt: true }).toString()).toBe( -// i.toString() -// ) -// } -// }) - -// it('should pack integers with small numbers created with Integer', () => { -// let n, i -// // test small numbers -// for (n = -10; n <= 10; n += 1) { -// i = new Integer(n, 0) -// expect(packAndUnpack(i).toString()).toBe(i.toString()) -// expect( -// packAndUnpack(i, { disableLosslessIntegers: true }).toString() -// ).toBe(i.toString()) -// expect(packAndUnpack(i, { useBigInt: true }).toString()).toBe( -// i.toString() -// ) -// } -// }) - -// it('should pack integers with positive numbers', () => { -// let n, i -// // positive numbers -// for (n = 16; n <= 16; n += 1) { -// i = int(Math.pow(2, n)) -// expect(packAndUnpack(i).toString()).toBe(i.toString()) - -// const unpackedLossyInteger = packAndUnpack(i, { -// disableLosslessIntegers: true -// }) -// expect(typeof unpackedLossyInteger).toBe('number') -// expect(unpackedLossyInteger.toString()).toBe( -// i.inSafeRange() ? i.toString() : 'Infinity' -// ) - -// const bigint = packAndUnpack(i, { useBigInt: true }) -// expect(typeof bigint).toBe('bigint') -// expect(bigint.toString()).toBe(i.toString()) -// } -// }) - -// it('should pack integer with negative numbers', () => { -// let n, i -// // negative numbers -// for (n = 0; n <= 63; n += 1) { -// i = int(-Math.pow(2, n)) -// expect(packAndUnpack(i).toString()).toBe(i.toString()) - -// const unpackedLossyInteger = packAndUnpack(i, { -// disableLosslessIntegers: true -// }) -// expect(typeof unpackedLossyInteger).toBe('number') -// expect(unpackedLossyInteger.toString()).toBe( -// i.inSafeRange() ? i.toString() : '-Infinity' -// ) - -// const bigint = packAndUnpack(i, { useBigInt: true }) -// expect(typeof bigint).toBe('bigint') -// expect(bigint.toString()).toBe(i.toString()) -// } -// }) - -// it('should pack BigInt with small numbers', () => { -// let n, i -// // test small numbers -// for (n = -999; n <= 999; n += 1) { -// i = BigInt(n) -// expect(packAndUnpack(i).toString()).toBe(i.toString()) -// expect( -// packAndUnpack(i, { disableLosslessIntegers: true }).toString() -// ).toBe(i.toString()) -// expect(packAndUnpack(i, { useBigInt: true }).toString()).toBe( -// i.toString() -// ) -// } -// }) - -// it('should pack BigInt with positive numbers', () => { -// let n, i -// // positive numbers -// for (n = 16; n <= 16; n += 1) { -// i = BigInt(Math.pow(2, n)) -// expect(packAndUnpack(i).toString()).toBe(i.toString()) - -// const unpackedLossyInteger = packAndUnpack(i, { -// disableLosslessIntegers: true -// }) -// expect(typeof unpackedLossyInteger).toBe('number') -// expect(unpackedLossyInteger.toString()).toBe( -// int(i).inSafeRange() ? i.toString() : 'Infinity' -// ) - -// const bigint = packAndUnpack(i, { useBigInt: true }) -// expect(typeof bigint).toBe('bigint') -// expect(bigint.toString()).toBe(i.toString()) -// } -// }) - -// it('should pack BigInt with negative numbers', () => { -// let n, i -// // negative numbers -// for (n = 0; n <= 63; n += 1) { -// i = BigInt(-Math.pow(2, n)) -// expect(packAndUnpack(i).toString()).toBe(i.toString()) - -// const unpackedLossyInteger = packAndUnpack(i, { -// disableLosslessIntegers: true -// }) -// expect(typeof unpackedLossyInteger).toBe('number') -// expect(unpackedLossyInteger.toString()).toBe( -// int(i).inSafeRange() ? i.toString() : '-Infinity' -// ) - -// const bigint = packAndUnpack(i, { useBigInt: true }) -// expect(typeof bigint).toBe('bigint') -// expect(bigint.toString()).toBe(i.toString()) -// } -// }) - -// it('should pack strings', () => { -// expect(packAndUnpack('')).toBe('') -// expect(packAndUnpack('abcdefg123567')).toBe('abcdefg123567') -// const str = Array(65536 + 1).join('a') // 2 ^ 16 + 1 -// expect(packAndUnpack(str, { bufferSize: str.length + 8 })).toBe(str) -// }) - -// it('should pack structures', () => { -// expect(packAndUnpack(new Structure(1, ['Hello, world!!!'])).fields[0]).toBe( -// 'Hello, world!!!' -// ) -// }) - -// it('should pack lists', () => { -// const list = ['a', 'b'] -// const unpacked = packAndUnpack(list) -// expect(unpacked[0]).toBe(list[0]) -// expect(unpacked[1]).toBe(list[1]) -// }) - -// it('should pack long lists', () => { -// const listLength = 256 -// const list = [] -// for (let i = 0; i < listLength; i++) { -// list.push(null) -// } -// const unpacked = packAndUnpack(list, { bufferSize: 1400 }) -// expect(unpacked[0]).toBe(list[0]) -// expect(unpacked[1]).toBe(list[1]) -// }) - -// it.each( -// validNodesAndConfig() -// )('should unpack Nodes', (struct, expectedNode, config) => { -// const node = packAndUnpack(struct, config) - -// expect(node).toEqual(expectedNode) -// }) - -// it.each( -// invalidNodesConfig() -// )('should thrown error for unpacking invalid Nodes', (struct) => { -// expect(() => packAndUnpack(struct)).toThrow() -// }) - -// it.each( -// validRelationshipsAndConfig() -// )('should unpack Relationships', (struct, expectedRelationship, config) => { -// const releationship = packAndUnpack(struct, config) - -// expect(releationship).toEqual(expectedRelationship) -// }) - -// it.each( -// invalidRelationshipsConfig() -// )('should thrown error for unpacking invalid Relationships', (struct) => { -// expect(() => packAndUnpack(struct)).toThrow() -// }) - -// it.each( -// validUnboundRelationshipsAndConfig() -// )('should unpack UnboundRelationships', (struct, expectedRelationship, config) => { -// const releationship = packAndUnpack(struct, config) - -// expect(releationship).toEqual(expectedRelationship) -// }) - -// it.each( -// invalidUnboundRelationshipsConfig() -// )('should thrown error for unpacking invalid UnboundRelationships', (struct) => { -// expect(() => packAndUnpack(struct)).toThrow() -// }) - -// function validNodesAndConfig () { -// function validWithNumber () { -// const identity = 1 -// const labels = ['a', 'b'] -// const properties = { a: 1, b: 2 } -// const elementId = 'element_id_1' -// const expectedNode = new Node(identity, labels, properties, elementId) -// const nodeStruct = new Structure(0x4e, [ -// identity, labels, properties, elementId -// ]) -// return [nodeStruct, expectedNode, { disableLosslessIntegers: true, useBigInt: false }] -// } - -// function validWithoutOldIdentifiersLossy () { -// const identity = null -// const labels = ['a', 'b'] -// const properties = { a: 1, b: 2 } -// const elementId = 'element_id_1' -// const expectedNode = new Node(-1, labels, properties, elementId) -// const nodeStruct = new Structure(0x4e, [ -// identity, labels, properties, elementId -// ]) -// return [nodeStruct, expectedNode, { disableLosslessIntegers: true, useBigInt: false }] -// } - -// function validWithoutOldIdentifiersLosslessInteger () { -// const identity = null -// const labels = ['a', 'b'] -// const properties = { a: 1, b: 2 } -// const elementId = 'element_id_1' -// const expectedNode = new Node(int(-1), labels, properties, elementId) -// const nodeStruct = new Structure(0x4e, [ -// identity, labels, properties, elementId -// ]) -// return [nodeStruct, expectedNode, { disableLosslessIntegers: false, useBigInt: false }] -// } - -// function validWithoutOldIdentifiersBigInt () { -// const identity = null -// const labels = ['a', 'b'] -// const properties = { a: 1, b: 2 } -// const elementId = 'element_id_1' -// const expectedNode = new Node(BigInt(-1), labels, properties, elementId) -// const nodeStruct = new Structure(0x4e, [ -// identity, labels, properties, elementId -// ]) -// return [nodeStruct, expectedNode, { disableLosslessIntegers: false, useBigInt: true }] -// } - -// function validWithInt () { -// const identity = int(1) -// const labels = ['a', 'b'] -// const properties = { a: int(1), b: int(2) } -// const elementId = 'element_id_1' -// const expectedNode = new Node(identity, labels, properties, elementId) -// const nodeStruct = new Structure(0x4e, [ -// identity, labels, properties, elementId -// ]) -// return [nodeStruct, expectedNode, { disableLosslessIntegers: false, useBigInt: false }] -// } - -// function validWithBigInt () { -// const identity = BigInt(1) -// const labels = ['a', 'b'] -// const properties = { a: BigInt(1), b: BigInt(2) } -// const elementId = 'element_id_1' -// const expectedNode = new Node(identity, labels, properties, elementId) -// const nodeStruct = new Structure(0x4e, [ -// identity, labels, properties, elementId -// ]) -// return [nodeStruct, expectedNode, { disableLosslessIntegers: false, useBigInt: true }] -// } - -// return [ -// validWithNumber(), -// validWithInt(), -// validWithBigInt(), -// validWithoutOldIdentifiersLossy(), -// validWithoutOldIdentifiersLosslessInteger(), -// validWithoutOldIdentifiersBigInt() -// ] -// } - -// function invalidNodesConfig () { -// return [ -// [new Structure(0x4e, [1, ['a', 'b'], { a: 1, b: 2 }])], -// [new Structure(0x4e, [1, ['a', 'b'], { a: 1, b: 2 }, 'elementId', 'myId'])] -// ] -// } - -// function validRelationshipsAndConfig () { -// function validWithNumber () { -// const identity = 1 -// const start = 2 -// const end = 3 -// const type = 'KNOWS' -// const properties = { a: 1, b: 2 } -// const elementId = 'element_id_1' -// const startNodeElementId = 'element_id_2' -// const endNodeElementId = 'element_id_3' -// const expectedRel = new Relationship( -// identity, start, end, type, properties, -// elementId, startNodeElementId, endNodeElementId) -// const relStruct = new Structure(0x52, [ -// identity, start, end, type, properties, elementId, -// startNodeElementId, endNodeElementId -// ]) -// return [relStruct, expectedRel, { disableLosslessIntegers: true, useBigInt: false }] -// } - -// function validWithoutOldIdentifiersLossy () { -// const identity = null -// const start = null -// const end = null -// const type = 'KNOWS' -// const properties = { a: 1, b: 2 } -// const elementId = 'element_id_1' -// const startNodeElementId = 'element_id_2' -// const endNodeElementId = 'element_id_3' -// const expectedRel = new Relationship( -// -1, -1, -1, type, properties, -// elementId, startNodeElementId, endNodeElementId) -// const relStruct = new Structure(0x52, [ -// identity, start, end, type, properties, elementId, -// startNodeElementId, endNodeElementId -// ]) -// return [relStruct, expectedRel, { disableLosslessIntegers: true, useBigInt: false }] -// } - -// function validWithoutOldIdentifiersLossLess () { -// const identity = null -// const start = null -// const end = null -// const type = 'KNOWS' -// const properties = { a: 1, b: 2 } -// const elementId = 'element_id_1' -// const startNodeElementId = 'element_id_2' -// const endNodeElementId = 'element_id_3' -// const expectedRel = new Relationship( -// int(-1), int(-1), int(-1), type, properties, -// elementId, startNodeElementId, endNodeElementId) -// const relStruct = new Structure(0x52, [ -// identity, start, end, type, properties, elementId, -// startNodeElementId, endNodeElementId -// ]) -// return [relStruct, expectedRel, { disableLosslessIntegers: false, useBigInt: false }] -// } - -// function validWithoutOldIdentifiersBigInt () { -// const identity = null -// const start = null -// const end = null -// const type = 'KNOWS' -// const properties = { a: 1, b: 2 } -// const elementId = 'element_id_1' -// const startNodeElementId = 'element_id_2' -// const endNodeElementId = 'element_id_3' -// const expectedRel = new Relationship( -// BigInt(-1), BigInt(-1), BigInt(-1), type, properties, -// elementId, startNodeElementId, endNodeElementId) -// const relStruct = new Structure(0x52, [ -// identity, start, end, type, properties, elementId, -// startNodeElementId, endNodeElementId -// ]) -// return [relStruct, expectedRel, { disableLosslessIntegers: true, useBigInt: true }] -// } - -// function validWithInt () { -// const identity = int(1) -// const start = int(2) -// const end = int(3) -// const type = 'KNOWS' -// const properties = { a: int(1), b: int(2) } -// const elementId = 'element_id_1' -// const startNodeElementId = 'element_id_2' -// const endNodeElementId = 'element_id_3' -// const expectedRel = new Relationship( -// identity, start, end, type, properties, -// elementId, startNodeElementId, endNodeElementId) -// const relStruct = new Structure(0x52, [ -// identity, start, end, type, properties, elementId, -// startNodeElementId, endNodeElementId -// ]) -// return [relStruct, expectedRel, { disableLosslessIntegers: false, useBigInt: false }] -// } - -// function validWithBigInt () { -// const identity = BigInt(1) -// const start = BigInt(2) -// const end = BigInt(3) -// const type = 'KNOWS' -// const properties = { a: BigInt(1), b: BigInt(2) } -// const elementId = 'element_id_1' -// const startNodeElementId = 'element_id_2' -// const endNodeElementId = 'element_id_3' -// const expectedRel = new Relationship( -// identity, start, end, type, properties, -// elementId, startNodeElementId, endNodeElementId) -// const relStruct = new Structure(0x52, [ -// identity, start, end, type, properties, elementId, -// startNodeElementId, endNodeElementId -// ]) -// return [relStruct, expectedRel, { disableLosslessIntegers: false, useBigInt: true }] -// } - -// return [ -// validWithNumber(), -// validWithInt(), -// validWithBigInt(), -// validWithoutOldIdentifiersLossy(), -// validWithoutOldIdentifiersLossLess(), -// validWithoutOldIdentifiersBigInt() -// ] -// } - -// function invalidRelationshipsConfig () { -// return [ -// [new Structure(0x52, [1, 2, 3, 'rel', { a: 1, b: 2 }, 'elementId', 'startNodeId'])], -// [new Structure(0x52, [1, 2, 3, 'rel', { a: 1, b: 2 }, 'elementId', 'startNodeId', 'endNodeId', 'myId'])] -// ] -// } - -// function validUnboundRelationshipsAndConfig () { -// function validWithNumber () { -// const identity = 1 -// const type = 'DOESNT_KNOW' -// const properties = { a: 1, b: 2 } -// const elementId = 'element_id_1' -// const expectedUnboundRel = new UnboundRelationship(identity, type, properties, elementId) -// const struct = new Structure(0x72, [ -// identity, type, properties, elementId -// ]) -// return [struct, expectedUnboundRel, { disableLosslessIntegers: true, useBigInt: false }] -// } - -// function validWithoutOldIdentifiersLossy () { -// const identity = null -// const type = 'DOESNT_KNOW' -// const properties = { a: 1, b: 2 } -// const elementId = 'element_id_1' -// const expectedUnboundRel = new UnboundRelationship(-1, type, properties, elementId) -// const struct = new Structure(0x72, [ -// identity, type, properties, elementId -// ]) -// return [struct, expectedUnboundRel, { disableLosslessIntegers: true, useBigInt: false }] -// } - -// function validWithoutOldIdentifiersLossless () { -// const identity = null -// const type = 'DOESNT_KNOW' -// const properties = { a: 1, b: 2 } -// const elementId = 'element_id_1' -// const expectedUnboundRel = new UnboundRelationship(int(-1), type, properties, elementId) -// const struct = new Structure(0x72, [ -// identity, type, properties, elementId -// ]) -// return [struct, expectedUnboundRel, { disableLosslessIntegers: false, useBigInt: false }] -// } - -// function validWithoutOldIdentifiersBigInt () { -// const identity = null -// const type = 'DOESNT_KNOW' -// const properties = { a: 1, b: 2 } -// const elementId = 'element_id_1' -// const expectedUnboundRel = new UnboundRelationship(BigInt(-1), type, properties, elementId) -// const struct = new Structure(0x72, [ -// identity, type, properties, elementId -// ]) -// return [struct, expectedUnboundRel, { disableLosslessIntegers: false, useBigInt: true }] -// } - -// function validWithInt () { -// const identity = int(1) -// const type = 'DOESNT_KNOW' -// const properties = { a: int(1), b: int(2) } -// const elementId = 'element_id_1' -// const expectedUnboundRel = new UnboundRelationship(identity, type, properties, elementId) -// const struct = new Structure(0x72, [ -// identity, type, properties, elementId -// ]) -// return [struct, expectedUnboundRel, { disableLosslessIntegers: false, useBigInt: false }] -// } - -// function validWithBigInt () { -// const identity = BigInt(1) -// const type = 'DOESNT_KNOW' -// const properties = { a: BigInt(1), b: BigInt(2) } -// const elementId = 'element_id_1' -// const expectedUnboundRel = new UnboundRelationship(identity, type, properties, elementId) -// const struct = new Structure(0x72, [ -// identity, type, properties, elementId -// ]) -// return [struct, expectedUnboundRel, { disableLosslessIntegers: false, useBigInt: true }] -// } - -// return [ -// validWithNumber(), -// validWithInt(), -// validWithBigInt(), -// validWithoutOldIdentifiersLossy(), -// validWithoutOldIdentifiersLossless(), -// validWithoutOldIdentifiersBigInt() -// ] -// } - -// function invalidUnboundRelationshipsConfig () { -// return [ -// [new Structure(0x72, [1, 'DOESNT_KNOW', { a: 1, b: 2 }])], -// [new Structure(0x72, [1, 'DOESNT_KNOW', { a: 1, b: 2 }, 'elementId', 'myId'])] -// ] -// } -// }) - -// function packAndUnpack ( -// val, -// { bufferSize = 128, disableLosslessIntegers = false, useBigInt = false } = {} -// ) { -// const buffer = alloc(bufferSize) -// new Packer(buffer).packable(val)() -// buffer.reset() -// return new Unpacker(disableLosslessIntegers, useBigInt).unpack(buffer) -// } From a0a51c873a6090d1d1654aa3b08011bc7bf25d4e Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Thu, 9 Jun 2022 17:04:06 +0200 Subject: [PATCH 17/18] Fix graph types serialization verification issue --- .../test/bolt/__snapshots__/bolt-protocol-v1.test.js.snap | 2 -- .../test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap | 2 -- .../test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap | 2 -- .../test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap | 2 -- .../test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap | 2 -- .../test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap | 2 -- .../test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap | 2 -- .../test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap | 2 -- .../test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap | 2 -- packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js | 3 +-- packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js | 3 +-- packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js | 3 +-- packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js | 3 +-- packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js | 3 +-- packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js | 3 +-- packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js | 3 +-- packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js | 3 +-- packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js | 3 +-- 18 files changed, 9 insertions(+), 36 deletions(-) diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v1.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v1.test.js.snap index a842698e4..960a5e254 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v1.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v1.test.js.snap @@ -4,8 +4,6 @@ exports[`#unit BoltProtocolV1 .packable() should pack not pack graph types (Node exports[`#unit BoltProtocolV1 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; -exports[`#unit BoltProtocolV1 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; - exports[`#unit BoltProtocolV1 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; exports[`#unit BoltProtocolV1 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap index cba590a5b..adb3dfaa4 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap @@ -4,8 +4,6 @@ exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (Node exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; -exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; - exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap index e8cabffd0..3754c427b 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap @@ -4,8 +4,6 @@ exports[`#unit BoltProtocolV3 .packable() should pack not pack graph types (Node exports[`#unit BoltProtocolV3 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; -exports[`#unit BoltProtocolV3 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; - exports[`#unit BoltProtocolV3 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; exports[`#unit BoltProtocolV3 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap index 179683940..78b7fbe9e 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap @@ -4,8 +4,6 @@ exports[`#unit BoltProtocolV4x0 .packable() should pack not pack graph types (No exports[`#unit BoltProtocolV4x0 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; -exports[`#unit BoltProtocolV4x0 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; - exports[`#unit BoltProtocolV4x0 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; exports[`#unit BoltProtocolV4x0 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap index 0a9e6f004..0c4c0217d 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap @@ -4,8 +4,6 @@ exports[`#unit BoltProtocolV4x1 .packable() should pack not pack graph types (No exports[`#unit BoltProtocolV4x1 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; -exports[`#unit BoltProtocolV4x1 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; - exports[`#unit BoltProtocolV4x1 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; exports[`#unit BoltProtocolV4x1 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap index f32882847..07c04de93 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap @@ -4,8 +4,6 @@ exports[`#unit BoltProtocolV4x2 .packable() should pack not pack graph types (No exports[`#unit BoltProtocolV4x2 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; -exports[`#unit BoltProtocolV4x2 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; - exports[`#unit BoltProtocolV4x2 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; exports[`#unit BoltProtocolV4x2 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap index 7340c380b..b713b65ca 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap @@ -4,8 +4,6 @@ exports[`#unit BoltProtocolV4x3 .packable() should pack not pack graph types (No exports[`#unit BoltProtocolV4x3 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; -exports[`#unit BoltProtocolV4x3 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; - exports[`#unit BoltProtocolV4x3 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; exports[`#unit BoltProtocolV4x3 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap index f8bf09f24..ea5ec3e59 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap @@ -4,8 +4,6 @@ exports[`#unit BoltProtocolV4x4 .packable() should pack not pack graph types (No exports[`#unit BoltProtocolV4x4 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; -exports[`#unit BoltProtocolV4x4 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; - exports[`#unit BoltProtocolV4x4 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; exports[`#unit BoltProtocolV4x4 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap index 0442a0f5f..65b80a7dd 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap @@ -4,8 +4,6 @@ exports[`#unit BoltProtocolV5x0 .packable() should pack not pack graph types (No exports[`#unit BoltProtocolV5x0 .packable() should pack not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`; -exports[`#unit BoltProtocolV5x0 .packable() should pack not pack graph types (PathSegment) 1`] = `"Cannot read properties of null (reading 'writeUInt8')"`; - exports[`#unit BoltProtocolV5x0 .packable() should pack not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:\\"c\\"}]->(f)"`; exports[`#unit BoltProtocolV5x0 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js index 941b7fb56..533f0023b 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js @@ -382,8 +382,7 @@ describe('#unit BoltProtocolV1', () => { ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], - ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], - ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])] ])('should pack not pack graph types (%s)', (_, graphType) => { const protocol = new BoltProtocolV1( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js index ed9cea22e..52d8855d2 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js @@ -135,8 +135,7 @@ describe('#unit BoltProtocolV2', () => { ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], - ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], - ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])] ])('should pack not pack graph types (%s)', (_, graphType) => { const protocol = new BoltProtocolV2( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js index b285b2cc0..80bee79b1 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js @@ -340,8 +340,7 @@ describe('#unit BoltProtocolV3', () => { ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], - ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], - ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])] ])('should pack not pack graph types (%s)', (_, graphType) => { const protocol = new BoltProtocolV3( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js index a0c8486b5..17f6b5645 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js @@ -258,8 +258,7 @@ describe('#unit BoltProtocolV4x0', () => { ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], - ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], - ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])] ])('should pack not pack graph types (%s)', (_, graphType) => { const protocol = new BoltProtocolV4x0( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js index 01c76a880..8a881aded 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js @@ -132,8 +132,7 @@ describe('#unit BoltProtocolV4x1', () => { ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], - ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], - ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])] ])('should pack not pack graph types (%s)', (_, graphType) => { const protocol = new BoltProtocolV4x1( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js index 8f8288319..4a7ea23e6 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js @@ -131,8 +131,7 @@ describe('#unit BoltProtocolV4x2', () => { ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], - ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], - ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])] ])('should pack not pack graph types (%s)', (_, graphType) => { const protocol = new BoltProtocolV4x2( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js index 508a14470..0585c460c 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js @@ -343,8 +343,7 @@ describe('#unit BoltProtocolV4x3', () => { ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], - ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], - ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])] ])('should pack not pack graph types (%s)', (_, graphType) => { const protocol = new BoltProtocolV4x3( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js index 9c1eeda3e..eaeed9819 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js @@ -376,8 +376,7 @@ describe('#unit BoltProtocolV4x4', () => { ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], - ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], - ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])] ])('should pack not pack graph types (%s)', (_, graphType) => { const protocol = new BoltProtocolV4x4( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js index a48adb55a..f06870d3a 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js @@ -388,8 +388,7 @@ describe('#unit BoltProtocolV5x0', () => { ['Node', new Node(1, ['a'], { a: 'b' }, 'c')], ['Relationship', new Relationship(1, 2, 3, 'a', { b: 'c' }, 'd', 'e', 'f')], ['UnboundRelationship', new UnboundRelationship(1, 'a', { b: 'c' }, '1')], - ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])], - ['PathSegment', new PathSegment(new Node(1, [], {}), new Relationship(1, 1, 1, '', {}), new Node(1, [], {}))] + ['Path', new Path(new Node(1, [], {}), new Node(2, [], {}), [])] ])('should pack not pack graph types (%s)', (_, graphType) => { const protocol = new BoltProtocolV5x0( new utils.MessageRecordingConnection(), From 161d03feb699513d44c195439136dc6793428ea3 Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Tue, 14 Jun 2022 17:38:32 +0200 Subject: [PATCH 18/18] Docs and cleaning up --- .../src/bolt/bolt-protocol-v1.transformer.js | 16 ++++++ .../src/bolt/bolt-protocol-v2.transformer.js | 54 ++++++++++++++++++ .../bolt/bolt-protocol-v5x0.transformer.js | 15 +++++ .../bolt-connection/src/bolt/transformer.js | 57 +++++++++++++++++++ .../bolt-protocol-v2.test.js.snap | 52 ++++++++--------- .../bolt-protocol-v3.test.js.snap | 52 ++++++++--------- .../bolt-protocol-v4x0.test.js.snap | 52 ++++++++--------- .../bolt-protocol-v4x1.test.js.snap | 52 ++++++++--------- .../bolt-protocol-v4x2.test.js.snap | 52 ++++++++--------- .../bolt-protocol-v4x3.test.js.snap | 52 ++++++++--------- .../bolt-protocol-v4x4.test.js.snap | 52 ++++++++--------- .../bolt-protocol-v5x0.test.js.snap | 52 ++++++++--------- .../test/bolt/bolt-protocol-v2.test.js | 4 +- .../test/bolt/bolt-protocol-v3.test.js | 4 +- .../test/bolt/bolt-protocol-v4x0.test.js | 4 +- .../test/bolt/bolt-protocol-v4x1.test.js | 4 +- .../test/bolt/bolt-protocol-v4x2.test.js | 4 +- .../test/bolt/bolt-protocol-v4x3.test.js | 4 +- .../test/bolt/bolt-protocol-v4x4.test.js | 4 +- .../test/bolt/bolt-protocol-v5x0.test.js | 4 +- 20 files changed, 366 insertions(+), 224 deletions(-) diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v1.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v1.transformer.js index c321a99f9..bc95ee555 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v1.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v1.transformer.js @@ -45,6 +45,10 @@ const UNBOUND_RELATIONSHIP_STRUCT_SIZE = 3 const PATH = 0x50 const PATH_STRUCT_SIZE = 3 +/** + * Creates the Node Transformer + * @returns {TypeTransformer} + */ function createNodeTransformer () { return new TypeTransformer({ signature: NODE, @@ -65,6 +69,10 @@ function createNodeTransformer () { }) } +/** + * Creates the Relationship Transformer + * @returns {TypeTransformer} + */ function createRelationshipTransformer () { return new TypeTransformer({ signature: RELATIONSHIP, @@ -85,6 +93,10 @@ function createRelationshipTransformer () { }) } +/** + * Creates the Unbound Relationship Transformer + * @returns {TypeTransformer} + */ function createUnboundRelationshipTransformer () { return new TypeTransformer({ signature: UNBOUND_RELATIONSHIP, @@ -109,6 +121,10 @@ function createUnboundRelationshipTransformer () { }) } +/** + * Creates the Path Transformer + * @returns {TypeTransformer} + */ function createPathTransformer () { return new TypeTransformer({ signature: PATH, diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js index cb90b8bca..d598925f0 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v2.transformer.js @@ -80,6 +80,10 @@ const DATE_TIME_WITH_ZONE_OFFSET_STRUCT_SIZE = 3 const DATE_TIME_WITH_ZONE_ID = 0x66 const DATE_TIME_WITH_ZONE_ID_STRUCT_SIZE = 3 +/** + * Creates the Point2D Transformer + * @returns {TypeTransformer} + */ function createPoint2DTransformer () { return new TypeTransformer({ signature: POINT_2D, @@ -103,6 +107,10 @@ function createPoint2DTransformer () { }) } +/** + * Creates the Point3D Transformer + * @returns {TypeTransformer} + */ function createPoint3DTransformer () { return new TypeTransformer({ signature: POINT_3D, @@ -127,6 +135,10 @@ function createPoint3DTransformer () { }) } +/** + * Creates the Duration Transformer + * @returns {TypeTransformer} + */ function createDurationTransformer () { return new TypeTransformer({ signature: DURATION, @@ -149,6 +161,13 @@ function createDurationTransformer () { }) } +/** + * Creates the LocalTime Transformer + * @param {Object} param + * @param {boolean} param.disableLosslessIntegers Disables lossless integers + * @param {boolean} param.useBigInt Uses BigInt instead of number or Integer + * @returns {TypeTransformer} + */ function createLocalTimeTransformer ({ disableLosslessIntegers, useBigInt }) { return new TypeTransformer({ signature: LOCAL_TIME, @@ -173,6 +192,13 @@ function createLocalTimeTransformer ({ disableLosslessIntegers, useBigInt }) { }) } +/** + * Creates the Time Transformer + * @param {Object} param + * @param {boolean} param.disableLosslessIntegers Disables lossless integers + * @param {boolean} param.useBigInt Uses BigInt instead of number or Integer + * @returns {TypeTransformer} + */ function createTimeTransformer ({ disableLosslessIntegers, useBigInt }) { return new TypeTransformer({ signature: TIME, @@ -205,6 +231,13 @@ function createTimeTransformer ({ disableLosslessIntegers, useBigInt }) { }) } +/** + * Creates the Date Transformer + * @param {Object} param + * @param {boolean} param.disableLosslessIntegers Disables lossless integers + * @param {boolean} param.useBigInt Uses BigInt instead of number or Integer + * @returns {TypeTransformer} + */ function createDateTransformer ({ disableLosslessIntegers, useBigInt }) { return new TypeTransformer({ signature: DATE, @@ -224,6 +257,13 @@ function createDateTransformer ({ disableLosslessIntegers, useBigInt }) { }) } +/** + * Creates the LocalDateTime Transformer + * @param {Object} param + * @param {boolean} param.disableLosslessIntegers Disables lossless integers + * @param {boolean} param.useBigInt Uses BigInt instead of number or Integer + * @returns {TypeTransformer} + */ function createLocalDateTimeTransformer ({ disableLosslessIntegers, useBigInt }) { return new TypeTransformer({ signature: LOCAL_DATE_TIME, @@ -256,6 +296,13 @@ function createLocalDateTimeTransformer ({ disableLosslessIntegers, useBigInt }) }) } +/** + * Creates the DateTime with ZoneId Transformer + * @param {Object} param + * @param {boolean} param.disableLosslessIntegers Disables lossless integers + * @param {boolean} param.useBigInt Uses BigInt instead of number or Integer + * @returns {TypeTransformer} + */ function createDateTimeWithZoneIdTransformer ({ disableLosslessIntegers, useBigInt }) { return new TypeTransformer({ signature: DATE_TIME_WITH_ZONE_ID, @@ -301,6 +348,13 @@ function createDateTimeWithZoneIdTransformer ({ disableLosslessIntegers, useBigI }) } +/** + * Creates the DateTime with Offset Transformer + * @param {Object} param + * @param {boolean} param.disableLosslessIntegers Disables lossless integers + * @param {boolean} param.useBigInt Uses BigInt instead of number or Integer + * @returns {TypeTransformer} + */ function createDateTimeWithOffsetTransformer ({ disableLosslessIntegers, useBigInt }) { return new TypeTransformer({ signature: DATE_TIME_WITH_ZONE_OFFSET, diff --git a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js index d50cca0f9..148958c08 100644 --- a/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js +++ b/packages/bolt-connection/src/bolt/bolt-protocol-v5x0.transformer.js @@ -25,6 +25,11 @@ const NODE_STRUCT_SIZE = 4 const RELATIONSHIP_STRUCT_SIZE = 8 const UNBOUND_RELATIONSHIP_STRUCT_SIZE = 4 +/** + * Create an extend Node transformer with support to elementId + * @param {any} config + * @returns {TypeTransformer} + */ function createNodeTransformer (config) { const node4x4Transformer = v4x4.createNodeTransformer(config) return node4x4Transformer.extendsWith({ @@ -43,6 +48,11 @@ function createNodeTransformer (config) { }) } +/** + * Create an extend Relationship transformer with support to elementId + * @param {any} config + * @returns {TypeTransformer} + */ function createRelationshipTransformer (config) { const relationship4x4Transformer = v4x4.createRelationshipTransformer(config) return relationship4x4Transformer.extendsWith({ @@ -74,6 +84,11 @@ function createRelationshipTransformer (config) { }) } +/** + * Create an extend Unbound Relationship transformer with support to elementId + * @param {any} config + * @returns {TypeTransformer} + */ function createUnboundRelationshipTransformer (config) { const unboundRelationshipTransformer = v4x4.createUnboundRelationshipTransformer(config) return unboundRelationshipTransformer.extendsWith({ diff --git a/packages/bolt-connection/src/bolt/transformer.js b/packages/bolt-connection/src/bolt/transformer.js index 24ded07bf..485c157dd 100644 --- a/packages/bolt-connection/src/bolt/transformer.js +++ b/packages/bolt-connection/src/bolt/transformer.js @@ -19,7 +19,15 @@ import { structure } from '../packstream' +/** + * Class responsible for applying the expected {@link TypeTransformer} to + * transform the driver types from and to {@link struct.Structure} + */ export default class Transformer { + /** + * Constructor + * @param {TypeTransformer[]} transformers The type transformers + */ constructor (transformers) { this._transformers = transformers this._transformersPerSignature = new Map(transformers.map(typeTransformer => [typeTransformer.signature, typeTransformer])) @@ -28,6 +36,12 @@ export default class Transformer { Object.freeze(this) } + /** + * Transform from structure to specific object + * + * @param {struct.Structure} struct The structure + * @returns {|structure.Structure} The driver object or the structure if the transformer was not found. + */ fromStructure (struct) { if (struct instanceof structure.Structure && this._transformersPerSignature.has(struct.signature)) { const { fromStructure } = this._transformersPerSignature.get(struct.signature) @@ -36,6 +50,11 @@ export default class Transformer { return struct } + /** + * Transform from object to structure + * @param {} type The object to be transoformed in structure + * @returns {|structure.Structure} The structure or the object, if any transformer was found + */ toStructure (type) { const transformer = this._transformers.find(({ isTypeInstance }) => isTypeInstance(type)) if (transformer !== undefined) { @@ -45,7 +64,36 @@ export default class Transformer { } } +/** + * @callback isTypeInstanceFunction + * @param {any} object The object + * @return {boolean} is instance of + */ + +/** + * @callback toStructureFunction + * @param {any} object The object + * @return {structure.Structure} The structure + */ + +/** + * @callback fromStructureFunction + * @param {structure.Structure} struct The structure + * @return {any} The object + */ + +/** + * Class responsible for grouping the properties of a TypeTransformer + */ export class TypeTransformer { + /** + * @param {Object} param + * @param {number} param.signature The signature of the structure + * @param {isTypeInstanceFunction} param.isTypeInstance The function which checks if object is + * instance of the type described by the TypeTransformer + * @param {toStructureFunction} param.toStructure The function which gets the object and converts to structure + * @param {fromStructureFunction} param.fromStructure The function which get the structure and covnverts to object + */ constructor ({ signature, fromStructure, toStructure, isTypeInstance }) { this.signature = signature this.isTypeInstance = isTypeInstance @@ -55,6 +103,15 @@ export class TypeTransformer { Object.freeze(this) } + /** + * @param {Object} param + * @param {number} [param.signature] The signature of the structure + * @param {isTypeInstanceFunction} [param.isTypeInstance] The function which checks if object is + * instance of the type described by the TypeTransformer + * @param {toStructureFunction} [param.toStructure] The function which gets the object and converts to structure + * @param {fromStructureFunction} pparam.fromStructure] The function which get the structure and covnverts to object + * @returns {TypeTransformer} A new type transform extends with new methods + */ extendsWith ({ signature, fromStructure, toStructure, isTypeInstance }) { return new TypeTransformer({ signature: signature || this.signature, diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap index adb3dfaa4..906b29ed0 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v2.test.js.snap @@ -8,54 +8,54 @@ exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (Rela exports[`#unit BoltProtocolV2 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; -exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; +exports[`#unit BoltProtocolV2 .unpack() should not unpack with wrong size (UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap index 3754c427b..966e99a67 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v3.test.js.snap @@ -8,54 +8,54 @@ exports[`#unit BoltProtocolV3 .packable() should pack not pack graph types (Rela exports[`#unit BoltProtocolV3 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; -exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; +exports[`#unit BoltProtocolV3 .unpack() should not unpack with wrong size (UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap index 78b7fbe9e..2372c840a 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x0.test.js.snap @@ -8,54 +8,54 @@ exports[`#unit BoltProtocolV4x0 .packable() should pack not pack graph types (Re exports[`#unit BoltProtocolV4x0 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x0 .unpack() should not unpack with wrong size (UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap index 0c4c0217d..e541c059f 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x1.test.js.snap @@ -8,54 +8,54 @@ exports[`#unit BoltProtocolV4x1 .packable() should pack not pack graph types (Re exports[`#unit BoltProtocolV4x1 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x1 .unpack() should not unpack with wrong size (UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap index 07c04de93..24528c606 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x2.test.js.snap @@ -8,54 +8,54 @@ exports[`#unit BoltProtocolV4x2 .packable() should pack not pack graph types (Re exports[`#unit BoltProtocolV4x2 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x2 .unpack() should not unpack with wrong size (UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 3 but was 4"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap index b713b65ca..f1c9a01ed 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x3.test.js.snap @@ -8,54 +8,54 @@ exports[`#unit BoltProtocolV4x3 .packable() should pack not pack graph types (Re exports[`#unit BoltProtocolV4x3 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; -exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; +exports[`#unit BoltProtocolV4x3 .unpack() should not unpack with wrong size (Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; -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"`; +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"`; -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"`; +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"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap index ea5ec3e59..4068caf7d 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v4x4.test.js.snap @@ -8,54 +8,54 @@ exports[`#unit BoltProtocolV4x4 .packable() should pack not pack graph types (Re exports[`#unit BoltProtocolV4x4 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Node with less fields) 1`] = `"Wrong struct size for Node, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 4"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 5 but was 8"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; -exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; +exports[`#unit BoltProtocolV4x4 .unpack() should not unpack with wrong size (Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; -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"`; +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"`; -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"`; +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"`; diff --git a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap index 65b80a7dd..4d3877736 100644 --- a/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap +++ b/packages/bolt-connection/test/bolt/__snapshots__/bolt-protocol-v5x0.test.js.snap @@ -8,54 +8,54 @@ exports[`#unit BoltProtocolV5x0 .packable() should pack not pack graph types (Re exports[`#unit BoltProtocolV5x0 .packable() should pack not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:\\"c\\"}]->"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Node with less fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Node with less fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Node with more fields) 1`] = `"Wrong struct size for Node, expected 4 but was 5"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 4 but was 5"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Path with less fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Path with more fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 8 but was 5"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 8 but was 5"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 8 but was 9"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 8 but was 9"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 4 but was 3"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 4 but was 3"`; -exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size(UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 4 but was 5"`; +exports[`#unit BoltProtocolV5x0 .unpack() should not unpack with wrong size (UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 4 but was 5"`; diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js index 52d8855d2..94575ea0a 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js @@ -382,7 +382,7 @@ describe('#unit BoltProtocolV2', () => { 'DateTimeWithZoneId with more fields', new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) ] - ])('should not unpack with wrong size(%s)', (_, struct) => { + ])('should not unpack with wrong size (%s)', (_, struct) => { const buffer = alloc(256) const protocol = new BoltProtocolV2( new utils.MessageRecordingConnection(), @@ -445,7 +445,7 @@ describe('#unit BoltProtocolV2', () => { new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') ] - ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + ])('should unpack spatial types and temporal types (%s)', (_, struct, object) => { const buffer = alloc(256) const protocol = new BoltProtocolV2( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js index 80bee79b1..f8a6e914a 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js @@ -587,7 +587,7 @@ describe('#unit BoltProtocolV3', () => { 'DateTimeWithZoneId with more fields', new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) ] - ])('should not unpack with wrong size(%s)', (_, struct) => { + ])('should not unpack with wrong size (%s)', (_, struct) => { const buffer = alloc(256) const protocol = new BoltProtocolV3( new utils.MessageRecordingConnection(), @@ -650,7 +650,7 @@ describe('#unit BoltProtocolV3', () => { new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') ] - ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + ])('should unpack spatial types and temporal types (%s)', (_, struct, object) => { const buffer = alloc(256) const protocol = new BoltProtocolV3( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js index 17f6b5645..d92f36330 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x0.test.js @@ -505,7 +505,7 @@ describe('#unit BoltProtocolV4x0', () => { 'DateTimeWithZoneId with more fields', new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) ] - ])('should not unpack with wrong size(%s)', (_, struct) => { + ])('should not unpack with wrong size (%s)', (_, struct) => { const buffer = alloc(256) const protocol = new BoltProtocolV4x0( new utils.MessageRecordingConnection(), @@ -568,7 +568,7 @@ describe('#unit BoltProtocolV4x0', () => { new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') ] - ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + ])('should unpack spatial types and temporal types (%s)', (_, struct, object) => { const buffer = alloc(256) const protocol = new BoltProtocolV4x0( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js index 8a881aded..48f8ca724 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x1.test.js @@ -379,7 +379,7 @@ describe('#unit BoltProtocolV4x1', () => { 'DateTimeWithZoneId with more fields', new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) ] - ])('should not unpack with wrong size(%s)', (_, struct) => { + ])('should not unpack with wrong size (%s)', (_, struct) => { const buffer = alloc(256) const protocol = new BoltProtocolV4x1( new utils.MessageRecordingConnection(), @@ -442,7 +442,7 @@ describe('#unit BoltProtocolV4x1', () => { new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') ] - ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + ])('should unpack spatial types and temporal types (%s)', (_, struct, object) => { const buffer = alloc(256) const protocol = new BoltProtocolV4x1( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js index 4a7ea23e6..2000283a3 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x2.test.js @@ -378,7 +378,7 @@ describe('#unit BoltProtocolV4x2', () => { 'DateTimeWithZoneId with more fields', new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) ] - ])('should not unpack with wrong size(%s)', (_, struct) => { + ])('should not unpack with wrong size (%s)', (_, struct) => { const buffer = alloc(256) const protocol = new BoltProtocolV4x2( new utils.MessageRecordingConnection(), @@ -441,7 +441,7 @@ describe('#unit BoltProtocolV4x2', () => { new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') ] - ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + ])('should unpack spatial types and temporal types (%s)', (_, struct, object) => { const buffer = alloc(256) const protocol = new BoltProtocolV4x2( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js index 0585c460c..84982df25 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js @@ -590,7 +590,7 @@ describe('#unit BoltProtocolV4x3', () => { 'DateTimeWithZoneId with more fields', new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) ] - ])('should not unpack with wrong size(%s)', (_, struct) => { + ])('should not unpack with wrong size (%s)', (_, struct) => { const buffer = alloc(256) const protocol = new BoltProtocolV4x3( new utils.MessageRecordingConnection(), @@ -653,7 +653,7 @@ describe('#unit BoltProtocolV4x3', () => { new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') ] - ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + ])('should unpack spatial types and temporal types (%s)', (_, struct, object) => { const buffer = alloc(256) const protocol = new BoltProtocolV4x3( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js index eaeed9819..80019513f 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js @@ -623,7 +623,7 @@ describe('#unit BoltProtocolV4x4', () => { 'DateTimeWithZoneId with more fields', new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) ] - ])('should not unpack with wrong size(%s)', (_, struct) => { + ])('should not unpack with wrong size (%s)', (_, struct) => { const buffer = alloc(256) const protocol = new BoltProtocolV4x4( new utils.MessageRecordingConnection(), @@ -686,7 +686,7 @@ describe('#unit BoltProtocolV4x4', () => { new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') ] - ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + ])('should unpack spatial types and temporal types (%s)', (_, struct, object) => { const buffer = alloc(256) const protocol = new BoltProtocolV4x4( new utils.MessageRecordingConnection(), diff --git a/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js b/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js index f06870d3a..a8e22faf3 100644 --- a/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js +++ b/packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js @@ -635,7 +635,7 @@ describe('#unit BoltProtocolV5x0', () => { 'DateTimeWithZoneId with more fields', new structure.Structure(0x66, [1, 2, 'America/Sao Paulo', 'Brasil']) ] - ])('should not unpack with wrong size(%s)', (_, struct) => { + ])('should not unpack with wrong size (%s)', (_, struct) => { const buffer = alloc(256) const protocol = new BoltProtocolV5x0( new utils.MessageRecordingConnection(), @@ -698,7 +698,7 @@ describe('#unit BoltProtocolV5x0', () => { new structure.Structure(0x66, [1, 2, 'America/Sao Paulo']), new DateTime(1970, 1, 1, 0, 0, 1, 2, undefined, 'America/Sao Paulo') ] - ])('should pack spatial types and temporal types (%s)', (_, struct, object) => { + ])('should unpack spatial types and temporal types (%s)', (_, struct, object) => { const buffer = alloc(256) const protocol = new BoltProtocolV5x0( new utils.MessageRecordingConnection(),