Skip to content

Commit 72c8474

Browse files
robsdedudebigmontz
authored andcommitted
TestKit backend: except txMeta as Cypher types (neo4j#1039)
Signed-off-by: Antonio Barcelos <antonio.barcelos@neo4j.com>
1 parent 6f5ccf4 commit 72c8474

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

packages/testkit-backend/src/cypher-native-binders.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ export default function CypherNativeBinders (neo4j) {
66
function objectToCypher (obj) {
77
return objectMapper(obj, nativeToCypher)
88
}
9-
9+
function objectToNative (obj) {
10+
return objectMapper(obj, cypherToNative)
11+
}
12+
1013
function objectMemberBitIntToNumber (obj, recursive = false) {
1114
return objectMapper(obj, val => {
1215
if (typeof val === 'bigint') {
@@ -19,7 +22,7 @@ export default function CypherNativeBinders (neo4j) {
1922
return val
2023
})
2124
}
22-
25+
2326
function objectMapper (obj, mapper) {
2427
if (obj === null || obj === undefined) {
2528
return obj
@@ -28,7 +31,7 @@ export default function CypherNativeBinders (neo4j) {
2831
return { ...acc, [key]: mapper(obj[key]) }
2932
}, {})
3033
}
31-
34+
3235
function nativeToCypher (x) {
3336
if (x == null) {
3437
return valueResponse('CypherNull', null)
@@ -53,7 +56,7 @@ export default function CypherNativeBinders (neo4j) {
5356
console.log(err)
5457
throw Error(err)
5558
}
56-
59+
5760
function valueResponseOfObject (x) {
5861
if (neo4j.isInt(x)) {
5962
// TODO: Broken!!!
@@ -105,7 +108,7 @@ export default function CypherNativeBinders (neo4j) {
105108
},
106109
{ nodes: [x.start], relationships: [] }
107110
)
108-
111+
109112
return {
110113
name: 'CypherPath',
111114
data: {
@@ -114,7 +117,7 @@ export default function CypherNativeBinders (neo4j) {
114117
}
115118
}
116119
}
117-
120+
118121
if (neo4j.isDate(x)) {
119122
return structResponse('CypherDate', {
120123
year: x.year,
@@ -149,15 +152,15 @@ export default function CypherNativeBinders (neo4j) {
149152
nanoseconds: x.nanoseconds
150153
})
151154
}
152-
155+
153156
// If all failed, interpret as a map
154157
const map = {}
155158
for (const [key, value] of Object.entries(x)) {
156159
map[key] = nativeToCypher(value)
157160
}
158161
return valueResponse('CypherMap', map)
159162
}
160-
163+
161164
function structResponse (name, data) {
162165
const map = {}
163166
for (const [key, value] of Object.entries(data)) {
@@ -167,7 +170,7 @@ export default function CypherNativeBinders (neo4j) {
167170
}
168171
return { name, data: map }
169172
}
170-
173+
171174
function cypherToNative (c) {
172175
const {
173176
name,
@@ -249,9 +252,10 @@ export default function CypherNativeBinders (neo4j) {
249252
console.log(err)
250253
throw Error(err)
251254
}
252-
255+
253256
this.valueResponse = valueResponse
254257
this.objectToCypher = objectToCypher
258+
this.objectToNative = objectToNative
255259
this.objectMemberBitIntToNumber = objectMemberBitIntToNumber
256260
this.nativeToCypher = nativeToCypher
257261
this.cypherToNative = cypherToNative

packages/testkit-backend/src/request-handlers-rx.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,10 @@ export function SessionClose (_, context, data, wire) {
6969
}
7070

7171
export function SessionRun (_, context, data, wire) {
72-
const { sessionId, cypher, params, txMeta: metadata, timeout } = data
72+
const { sessionId, cypher, timeout } = data
7373
const session = context.getSession(sessionId)
74-
if (params) {
75-
for (const [key, value] of Object.entries(params)) {
76-
params[key] = context.binder.cypherToNative(value)
77-
}
78-
}
74+
const params = context.binder.objectToNative(data.params)
75+
const metadata = context.binder.objectToNative(data.txMeta)
7976

8077
let rxResult
8178
try {
@@ -112,8 +109,9 @@ export function ResultConsume (_, context, data, wire) {
112109
}
113110

114111
export function SessionBeginTransaction (_, context, data, wire) {
115-
const { sessionId, txMeta: metadata, timeout } = data
112+
const { sessionId, timeout } = data
116113
const session = context.getSession(sessionId)
114+
const metadata = context.binder.objectToNative(data.txMeta)
117115

118116
try {
119117
return session.beginTransaction({ metadata, timeout })
@@ -188,8 +186,9 @@ export function TransactionClose (_, context, data, wire) {
188186
}
189187

190188
export function SessionReadTransaction (_, context, data, wire) {
191-
const { sessionId, txMeta: metadata } = data
189+
const { sessionId } = data
192190
const session = context.getSession(sessionId)
191+
const metadata = context.binder.objectToNative(data.txMeta)
193192

194193
try {
195194
return session.executeRead(tx => {
@@ -207,8 +206,9 @@ export function SessionReadTransaction (_, context, data, wire) {
207206
}
208207

209208
export function SessionWriteTransaction (_, context, data, wire) {
210-
const { sessionId, txMeta: metadata } = data
209+
const { sessionId } = data
211210
const session = context.getSession(sessionId)
211+
const metadata = context.binder.objectToNative(data.txMeta)
212212

213213
try {
214214
return session.executeWrite(tx => {

packages/testkit-backend/src/request-handlers.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,10 @@ export function SessionClose (_, context, data, wire) {
151151
}
152152

153153
export function SessionRun (_, context, data, wire) {
154-
const { sessionId, cypher, params, txMeta: metadata, timeout } = data
154+
const { sessionId, cypher, timeout } = data
155155
const session = context.getSession(sessionId)
156-
if (params) {
157-
for (const [key, value] of Object.entries(params)) {
158-
params[key] = context.binder.cypherToNative(value)
159-
}
160-
}
156+
const params = context.binder.objectToNative(data.params)
157+
const metadata = context.binder.objectToNative(data.txMeta)
161158

162159
let result
163160
try {
@@ -230,8 +227,10 @@ export function ResultList (_, context, data, wire) {
230227
}
231228

232229
export function SessionReadTransaction (_, context, data, wire) {
233-
const { sessionId, txMeta: metadata } = data
230+
const { sessionId } = data
234231
const session = context.getSession(sessionId)
232+
const metadata = context.binder.objectToNative(data.txMeta)
233+
235234
return session
236235
.executeRead(
237236
tx =>
@@ -274,8 +273,9 @@ export function RetryableNegative (_, context, data, wire) {
274273
}
275274

276275
export function SessionBeginTransaction (_, context, data, wire) {
277-
const { sessionId, txMeta: metadata, timeout } = data
276+
const { sessionId, timeout } = data
278277
const session = context.getSession(sessionId)
278+
const metadata = context.binder.objectToNative(data.txMeta)
279279

280280
try {
281281
return session.beginTransaction({ metadata, timeout })
@@ -327,8 +327,10 @@ export function SessionLastBookmarks (_, context, data, wire) {
327327
}
328328

329329
export function SessionWriteTransaction (_, context, data, wire) {
330-
const { sessionId, txMeta: metadata } = data
330+
const { sessionId } = data
331331
const session = context.getSession(sessionId)
332+
const metadata = context.binder.objectToNative(data.txMeta)
333+
332334
return session
333335
.executeWrite(
334336
tx =>

0 commit comments

Comments
 (0)