Skip to content

Commit 0d603c8

Browse files
committed
6.0 bolt with vector support passing tests
1 parent 0707d3f commit 0d603c8

File tree

8 files changed

+1851
-153
lines changed

8 files changed

+1851
-153
lines changed

packages/bolt-connection/src/bolt/bolt-protocol-v6x0.transformer.js

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -32,72 +32,84 @@ function createVectorTransformer () {
3232
signature: VECTOR,
3333
isTypeInstance: object => object instanceof Vector,
3434
toStructure: vector => {
35-
const startTime = new Date().getTime()
36-
const dataview = new DataView(vector.typedArray.byteLength)
35+
const dataview = new DataView(new ArrayBuffer(vector.typedArray.byteLength))
3736
let set
3837
let typeMarker
39-
if (vector.type === 'INT8') {
40-
typeMarker = Uint8Array.from([INT_8])
41-
set = dataview.setUint8
42-
} else if (vector.type === 'INT16') {
43-
typeMarker = Uint8Array.from([INT_16])
44-
set = dataview.setUint16
45-
} else if (vector.type === 'INT32') {
46-
typeMarker = Uint8Array.from([INT_32])
47-
set = dataview.setUint32
48-
} else if (vector.type === 'INT64') {
49-
typeMarker = Uint8Array.from([INT_64])
50-
set = dataview.setUint64
51-
} else if (vector.type === 'FLOAT32') {
52-
typeMarker = Uint8Array.from([FLOAT_32])
53-
set = dataview.setFloat32
54-
} else if (vector.type === 'FLOAT64') {
55-
typeMarker = Uint8Array.from([FLOAT_64])
56-
set = dataview.setFloat64
57-
} else {
58-
throw newError('Vector is of unsupported type')
38+
switch (vector.type) {
39+
case 'INT8':
40+
typeMarker = Uint8Array.from([INT_8])
41+
set = dataview.setUint8.bind(dataview)
42+
break
43+
case 'INT16':
44+
typeMarker = Uint8Array.from([INT_16])
45+
set = dataview.setUint16.bind(dataview)
46+
break
47+
case 'INT32':
48+
typeMarker = Uint8Array.from([INT_32])
49+
set = dataview.setUint32.bind(dataview)
50+
break
51+
case 'INT64':
52+
typeMarker = Uint8Array.from([INT_64])
53+
set = dataview.setBigInt64.bind(dataview)
54+
break
55+
case 'FLOAT32':
56+
typeMarker = Uint8Array.from([FLOAT_32])
57+
set = dataview.setFloat32.bind(dataview)
58+
break
59+
case 'FLOAT64':
60+
typeMarker = Uint8Array.from([FLOAT_64])
61+
set = dataview.setFloat64.bind(dataview)
62+
break
63+
default:
64+
throw newError(`Vector is of unsupported type ${vector.type}`)
5965
}
6066
for (let i = 0; i < vector.typedArray.length; i++) {
6167
set(i * vector.typedArray.BYTES_PER_ELEMENT, vector.typedArray[i])
6268
}
63-
const struct = new structure.Structure(VECTOR, [typeMarker, Uint8Array.from(dataview.buffer)])
64-
console.debug(`Packing vector took ${new Date().getTime() - startTime}ms`)
69+
const struct = new structure.Structure(VECTOR, [typeMarker, new Int8Array(dataview.buffer)])
6570
return struct
6671
},
6772
fromStructure: structure => {
6873
const typeMarker = structure.fields[0][0]
69-
const byteArray = structure.fields[1]
70-
const dataview = new DataView(byteArray.length)
71-
let typedArray
74+
const arrayBuffer = structure.fields[1]
75+
const setview = new DataView(new ArrayBuffer(arrayBuffer.byteLength))
76+
const getview = new DataView(arrayBuffer.buffer)
77+
let get
7278
let set
7379
let resultArray
74-
if (typeMarker === INT_8) {
75-
return Int8Array.from(byteArray.buffer)
76-
} if (typeMarker === INT_16) {
77-
typedArray = Int16Array.from(byteArray.buffer)
78-
resultArray = Int16Array.from(dataview.buffer)
79-
set = dataview.setInt16
80-
} if (typeMarker === INT_32) {
81-
typedArray = Int32Array.from(byteArray.buffer)
82-
resultArray = Int32Array.from(dataview.buffer)
83-
set = dataview.setInt32
84-
} if (typeMarker === INT_64) {
85-
typedArray = BigInt64Array.from(byteArray.buffer)
86-
resultArray = BigInt64Array.from(dataview.buffer)
87-
set = dataview.setBigInt64
88-
} if (typeMarker === FLOAT_32) {
89-
typedArray = Float32Array.from(byteArray.buffer)
90-
resultArray = Float32Array.from(dataview.buffer)
91-
set = dataview.setFloat32
92-
} if (typeMarker === FLOAT_64) {
93-
typedArray = Float64Array.from(byteArray.buffer)
94-
resultArray = Float64Array.from(dataview.buffer)
95-
set = dataview.setFloat64
96-
} else {
97-
throw newError('Recieved Vector of unknown type')
80+
switch (typeMarker) {
81+
case INT_8:
82+
return new Vector(Int8Array.from(arrayBuffer))
83+
case INT_16:
84+
resultArray = new Int16Array(setview.buffer)
85+
get = getview.getInt16.bind(getview)
86+
set = setview.setInt16.bind(setview)
87+
break
88+
case INT_32:
89+
resultArray = new Int32Array(setview.buffer)
90+
get = getview.getInt32.bind(getview)
91+
set = setview.setInt32.bind(setview)
92+
break
93+
case INT_64:
94+
resultArray = new BigInt64Array(setview.buffer)
95+
get = getview.getBigInt64.bind(getview)
96+
set = setview.setBigInt64.bind(setview)
97+
break
98+
case FLOAT_32:
99+
resultArray = new Float32Array(setview.buffer)
100+
get = getview.getFloat32.bind(getview)
101+
set = setview.setFloat32.bind(setview)
102+
break
103+
case FLOAT_64:
104+
resultArray = new Float64Array(setview.buffer)
105+
get = getview.getFloat64.bind(getview)
106+
set = setview.setFloat64.bind(setview)
107+
break
108+
default:
109+
throw newError(`Recieved Vector of unknown type ${typeMarker}`)
98110
}
99-
for (let i = 0; i < typedArray.length; i++) {
100-
set(i * typedArray.BYTES_PER_ELEMENT, typedArray[i])
111+
for (let i = 0; i < arrayBuffer.length; i += resultArray.BYTES_PER_ELEMENT) {
112+
set(i, get(i), true)
101113
}
102114
return new Vector(resultArray)
103115
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`#unit BoltProtocolV6x0 .packable() should resultant function not pack graph types (Node) 1`] = `"It is not allowed to pass nodes in query parameters, given: (c:a {a:"b"})"`;
4+
5+
exports[`#unit BoltProtocolV6x0 .packable() should resultant function not pack graph types (Path) 1`] = `"It is not allowed to pass paths in query parameters, given: [object Object]"`;
6+
7+
exports[`#unit BoltProtocolV6x0 .packable() should resultant function not pack graph types (Relationship) 1`] = `"It is not allowed to pass relationships in query parameters, given: (e)-[:a {b:"c"}]->(f)"`;
8+
9+
exports[`#unit BoltProtocolV6x0 .packable() should resultant function not pack graph types (UnboundRelationship) 1`] = `"It is not allowed to pass unbound relationships in query parameters, given: -[:a {b:"c"}]->"`;
10+
11+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Date with less fields) 1`] = `"Wrong struct size for Date, expected 1 but was 0"`;
12+
13+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Date with more fields) 1`] = `"Wrong struct size for Date, expected 1 but was 2"`;
14+
15+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (DateTimeWithZoneId with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 2"`;
16+
17+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (DateTimeWithZoneId with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneId, expected 3 but was 4"`;
18+
19+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with less fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 2"`;
20+
21+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (DateTimeWithZoneOffset with more fields) 1`] = `"Wrong struct size for DateTimeWithZoneOffset, expected 3 but was 4"`;
22+
23+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Duration with less fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 3"`;
24+
25+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Duration with more fields) 1`] = `"Wrong struct size for Duration, expected 4 but was 5"`;
26+
27+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (LocalDateTime with less fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 1"`;
28+
29+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (LocalDateTime with more fields) 1`] = `"Wrong struct size for LocalDateTime, expected 2 but was 3"`;
30+
31+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (LocalTime with less fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 0"`;
32+
33+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (LocalTime with more fields) 1`] = `"Wrong struct size for LocalTime, expected 1 but was 2"`;
34+
35+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Node with less fields) 1`] = `"Wrong struct size for Node, expected 4 but was 3"`;
36+
37+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Node with more fields) 1`] = `"Wrong struct size for Node, expected 4 but was 5"`;
38+
39+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Path with less fields) 1`] = `"Wrong struct size for Path, expected 3 but was 2"`;
40+
41+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Path with more fields) 1`] = `"Wrong struct size for Path, expected 3 but was 4"`;
42+
43+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Point with less fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 2"`;
44+
45+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Point with more fields) 1`] = `"Wrong struct size for Point2D, expected 3 but was 4"`;
46+
47+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Point3D with less fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 3"`;
48+
49+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Point3D with more fields) 1`] = `"Wrong struct size for Point3D, expected 4 but was 5"`;
50+
51+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Relationship with less fields) 1`] = `"Wrong struct size for Relationship, expected 8 but was 5"`;
52+
53+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Relationship with more fields) 1`] = `"Wrong struct size for Relationship, expected 8 but was 9"`;
54+
55+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Time with less fields) 1`] = `"Wrong struct size for Time, expected 2 but was 1"`;
56+
57+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (Time with more fileds) 1`] = `"Wrong struct size for Time, expected 2 but was 3"`;
58+
59+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (UnboundRelationship with less fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 4 but was 3"`;
60+
61+
exports[`#unit BoltProtocolV6x0 .unpack() should not unpack with wrong size (UnboundRelationship with more fields) 1`] = `"Wrong struct size for UnboundRelationship, expected 4 but was 5"`;

0 commit comments

Comments
 (0)