From 3ed87bfdc4d2117cb0943c58b22900f8917a221f Mon Sep 17 00:00:00 2001 From: Robsdedude Date: Wed, 7 Dec 2022 16:29:56 +0100 Subject: [PATCH 1/3] TestKit backend: except txMeta as Cypher types Depends on: * https://github.com/neo4j-drivers/testkit/pull/538 --- .../src/cypher-native-binders.js | 24 +++++++++++-------- .../testkit-backend/src/request-handlers.js | 18 +++++++------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/testkit-backend/src/cypher-native-binders.js b/packages/testkit-backend/src/cypher-native-binders.js index 712685b5b..a0535732f 100644 --- a/packages/testkit-backend/src/cypher-native-binders.js +++ b/packages/testkit-backend/src/cypher-native-binders.js @@ -6,7 +6,10 @@ export default function CypherNativeBinders (neo4j) { function objectToCypher (obj) { return objectMapper(obj, nativeToCypher) } - + function objectToNative (obj) { + return objectMapper(obj, cypherToNative) + } + function objectMemberBitIntToNumber (obj, recursive = false) { return objectMapper(obj, val => { if (typeof val === 'bigint') { @@ -19,7 +22,7 @@ export default function CypherNativeBinders (neo4j) { return val }) } - + function objectMapper (obj, mapper) { if (obj === null || obj === undefined) { return obj @@ -28,7 +31,7 @@ export default function CypherNativeBinders (neo4j) { return { ...acc, [key]: mapper(obj[key]) } }, {}) } - + function nativeToCypher (x) { if (x == null) { return valueResponse('CypherNull', null) @@ -53,7 +56,7 @@ export default function CypherNativeBinders (neo4j) { console.log(err) throw Error(err) } - + function valueResponseOfObject (x) { if (neo4j.isInt(x)) { // TODO: Broken!!! @@ -105,7 +108,7 @@ export default function CypherNativeBinders (neo4j) { }, { nodes: [x.start], relationships: [] } ) - + return { name: 'CypherPath', data: { @@ -114,7 +117,7 @@ export default function CypherNativeBinders (neo4j) { } } } - + if (neo4j.isDate(x)) { return structResponse('CypherDate', { year: x.year, @@ -149,7 +152,7 @@ export default function CypherNativeBinders (neo4j) { nanoseconds: x.nanoseconds }) } - + // If all failed, interpret as a map const map = {} for (const [key, value] of Object.entries(x)) { @@ -157,7 +160,7 @@ export default function CypherNativeBinders (neo4j) { } return valueResponse('CypherMap', map) } - + function structResponse (name, data) { const map = {} for (const [key, value] of Object.entries(data)) { @@ -167,7 +170,7 @@ export default function CypherNativeBinders (neo4j) { } return { name, data: map } } - + function cypherToNative (c) { const { name, @@ -249,9 +252,10 @@ export default function CypherNativeBinders (neo4j) { console.log(err) throw Error(err) } - + this.valueResponse = valueResponse this.objectToCypher = objectToCypher + this.objectToNative = objectToNative this.objectMemberBitIntToNumber = objectMemberBitIntToNumber this.nativeToCypher = nativeToCypher this.cypherToNative = cypherToNative diff --git a/packages/testkit-backend/src/request-handlers.js b/packages/testkit-backend/src/request-handlers.js index 3a030f7e4..10cbd2d97 100644 --- a/packages/testkit-backend/src/request-handlers.js +++ b/packages/testkit-backend/src/request-handlers.js @@ -151,13 +151,10 @@ export function SessionClose (_, context, data, wire) { } export function SessionRun (_, context, data, wire) { - const { sessionId, cypher, params, txMeta: metadata, timeout } = data + const { sessionId, cypher, timeout } = data const session = context.getSession(sessionId) - if (params) { - for (const [key, value] of Object.entries(params)) { - params[key] = context.binder.cypherToNative(value) - } - } + const params = context.binder.objectToNative(data.params) + const metadata = context.binder.objectToNative(data.txMeta) let result try { @@ -230,8 +227,9 @@ export function ResultList (_, context, data, wire) { } export function SessionReadTransaction (_, context, data, wire) { - const { sessionId, txMeta: metadata } = data + const { sessionId } = data const session = context.getSession(sessionId) + const metadata = context.binder.objectToNative(data.txMeta) return session .executeRead( tx => @@ -274,8 +272,9 @@ export function RetryableNegative (_, context, data, wire) { } export function SessionBeginTransaction (_, context, data, wire) { - const { sessionId, txMeta: metadata, timeout } = data + const { sessionId, timeout } = data const session = context.getSession(sessionId) + const metadata = context.binder.objectToNative(data.txMeta) try { return session.beginTransaction({ metadata, timeout }) @@ -327,8 +326,9 @@ export function SessionLastBookmarks (_, context, data, wire) { } export function SessionWriteTransaction (_, context, data, wire) { - const { sessionId, txMeta: metadata } = data + const { sessionId } = data const session = context.getSession(sessionId) + const metadata = context.binder.objectToNative(data.txMeta) return session .executeWrite( tx => From 0b2ea62091f43b0ee00d3f4bb7c4a54c00f191ba Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Thu, 8 Dec 2022 12:33:26 +0100 Subject: [PATCH 2/3] Also deserialize tx metadata in RX backend Signed-off-by: Antonio Barcelos --- .../testkit-backend/src/request-handlers-rx.js | 14 ++++++++++---- packages/testkit-backend/src/request-handlers.js | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/testkit-backend/src/request-handlers-rx.js b/packages/testkit-backend/src/request-handlers-rx.js index 8a882dfa4..1410430a0 100644 --- a/packages/testkit-backend/src/request-handlers-rx.js +++ b/packages/testkit-backend/src/request-handlers-rx.js @@ -69,8 +69,11 @@ export function SessionClose (_, context, data, wire) { } export function SessionRun (_, context, data, wire) { - const { sessionId, cypher, params, txMeta: metadata, timeout } = data + const { sessionId, cypher, timeout } = data const session = context.getSession(sessionId) + const params = context.binder.objectToNative(data.params) + const metadata = context.binder.objectToNative(data.txMeta) + if (params) { for (const [key, value] of Object.entries(params)) { params[key] = context.binder.cypherToNative(value) @@ -112,8 +115,9 @@ export function ResultConsume (_, context, data, wire) { } export function SessionBeginTransaction (_, context, data, wire) { - const { sessionId, txMeta: metadata, timeout } = data + const { sessionId, timeout } = data const session = context.getSession(sessionId) + const metadata = context.binder.objectToNative(data.txMeta) try { return session.beginTransaction({ metadata, timeout }) @@ -188,8 +192,9 @@ export function TransactionClose (_, context, data, wire) { } export function SessionReadTransaction (_, context, data, wire) { - const { sessionId, txMeta: metadata } = data + const { sessionId } = data const session = context.getSession(sessionId) + const metadata = context.binder.objectToNative(data.txMeta) try { return session.executeRead(tx => { @@ -207,8 +212,9 @@ export function SessionReadTransaction (_, context, data, wire) { } export function SessionWriteTransaction (_, context, data, wire) { - const { sessionId, txMeta: metadata } = data + const { sessionId } = data const session = context.getSession(sessionId) + const metadata = context.binder.objectToNative(data.txMeta) try { return session.executeWrite(tx => { diff --git a/packages/testkit-backend/src/request-handlers.js b/packages/testkit-backend/src/request-handlers.js index 10cbd2d97..599a1e0e4 100644 --- a/packages/testkit-backend/src/request-handlers.js +++ b/packages/testkit-backend/src/request-handlers.js @@ -230,6 +230,7 @@ export function SessionReadTransaction (_, context, data, wire) { const { sessionId } = data const session = context.getSession(sessionId) const metadata = context.binder.objectToNative(data.txMeta) + return session .executeRead( tx => @@ -329,6 +330,7 @@ export function SessionWriteTransaction (_, context, data, wire) { const { sessionId } = data const session = context.getSession(sessionId) const metadata = context.binder.objectToNative(data.txMeta) + return session .executeWrite( tx => From eb9b1966f500d1e376263e1564cd30feb0995b71 Mon Sep 17 00:00:00 2001 From: Robsdedude Date: Thu, 8 Dec 2022 14:19:45 +0100 Subject: [PATCH 3/3] Fix double decoding of params Signed-off-by: Antonio Barcelos --- packages/testkit-backend/src/request-handlers-rx.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/testkit-backend/src/request-handlers-rx.js b/packages/testkit-backend/src/request-handlers-rx.js index 1410430a0..c1561f568 100644 --- a/packages/testkit-backend/src/request-handlers-rx.js +++ b/packages/testkit-backend/src/request-handlers-rx.js @@ -74,12 +74,6 @@ export function SessionRun (_, context, data, wire) { const params = context.binder.objectToNative(data.params) const metadata = context.binder.objectToNative(data.txMeta) - if (params) { - for (const [key, value] of Object.entries(params)) { - params[key] = context.binder.cypherToNative(value) - } - } - let rxResult try { rxResult = session.run(cypher, params, { metadata, timeout })