From d55e1754b4fb8642e95dda25f55959c1fe0635db Mon Sep 17 00:00:00 2001 From: Robsdedude Date: Thu, 15 Dec 2022 14:19:17 +0100 Subject: [PATCH] TestKit backend: except txMeta as Cypher types (#1039) Signed-off-by: Antonio Barcelos --- .../src/cypher-native-binders.js | 24 +++++++++++-------- .../src/request-handlers-rx.js | 18 +++++++------- .../testkit-backend/src/request-handlers.js | 20 +++++++++------- 3 files changed, 34 insertions(+), 28 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-rx.js b/packages/testkit-backend/src/request-handlers-rx.js index 8a882dfa4..c1561f568 100644 --- a/packages/testkit-backend/src/request-handlers-rx.js +++ b/packages/testkit-backend/src/request-handlers-rx.js @@ -69,13 +69,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 rxResult try { @@ -112,8 +109,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 +186,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 +206,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 3a030f7e4..599a1e0e4 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,10 @@ 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 +273,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 +327,10 @@ 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 =>