Skip to content

Commit 85403c8

Browse files
authored
ResultSummary.server: deprecate property version and introduce property agent as replacement (#728)
The name version is misleading because the information is about the server user agent, not the server version itself.
1 parent 9b16a76 commit 85403c8

File tree

5 files changed

+106
-12
lines changed

5 files changed

+106
-12
lines changed

core/src/result-summary.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ResultSummary<T extends NumberOrInteger = Integer> {
4141
* @param {string} query - The query this summary is for
4242
* @param {Object} parameters - Parameters for the query
4343
* @param {Object} metadata - Query metadata
44-
* @param {number} protocolVersion - Bolt protocol version
44+
* @param {number|undefined} protocolVersion - Bolt Protocol Version
4545
*/
4646
constructor(
4747
query: string,
@@ -449,21 +449,51 @@ class Notification {
449449
* @access public
450450
*/
451451
class ServerInfo {
452-
address: string
453-
version: string
452+
address?: string
453+
version?: string
454454
protocolVersion?: number
455+
agent?: string
455456

456457
/**
457458
* Create a ServerInfo instance
458459
* @constructor
459460
* @param {Object} serverMeta - Object with serverMeta data
460-
* @param {number} protocolVersion - Bolt protocol version
461+
* @param {Object} connectionInfo - Bolt connection info
462+
* @param {number} protocolVersion - Bolt Protocol Version
461463
*/
462-
constructor(serverMeta: any, protocolVersion?: number) {
464+
constructor(serverMeta?: any, protocolVersion?: number) {
463465
if (serverMeta) {
466+
/**
467+
* The server adress
468+
* @type {string}
469+
* @public
470+
*/
464471
this.address = serverMeta.address
472+
/**
473+
* The server version string.
474+
*
475+
* See {@link ServerInfo#protocolVersion} and {@link ServerInfo#agent}
476+
* @type {string}
477+
* @deprecated in 4.3, please use ServerInfo#agent, ServerInfo#protocolVersion, or call the <i>dbms.components</i> procedure instead.
478+
* <b>Method might be removed in the next major release.</b>
479+
480+
* @public
481+
*/
465482
this.version = serverMeta.version
483+
484+
/**
485+
* The server user agent string
486+
* @type {string}
487+
* @public
488+
*/
489+
this.agent = serverMeta.version
466490
}
491+
492+
/**
493+
* The protocol version used by the connection
494+
* @type {number}
495+
* @public
496+
*/
467497
this.protocolVersion = protocolVersion
468498
}
469499
}

core/test/result-summary.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import { ServerInfo } from '../src/result-summary'
21+
22+
describe('ServerInfo', () => {
23+
it.each([
24+
[
25+
{ address: '192.168.0.1', version: 'neo4j' },
26+
4.3,
27+
{
28+
address: '192.168.0.1',
29+
version: 'neo4j',
30+
protocolVersion: 4.3,
31+
agent: 'neo4j'
32+
}
33+
],
34+
[
35+
{ address: '192.168.0.1', version: 'neo4j' },
36+
undefined,
37+
{
38+
address: '192.168.0.1',
39+
version: 'neo4j',
40+
protocolVersion: undefined,
41+
agent: 'neo4j'
42+
}
43+
],
44+
[undefined, 4.3, { protocolVersion: 4.3 }],
45+
[undefined, undefined, {}]
46+
])(
47+
'new ServerInfo(%o, %i) === %j',
48+
(meta, protocolVersion, expectedServerInfo) => {
49+
expect(new ServerInfo(meta, protocolVersion)).toEqual(expectedServerInfo)
50+
}
51+
)
52+
})

test/types/result-summary.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ const line: number = position2.line
9797
const column: number = position2.column
9898

9999
const server: ServerInfo = sum1.server
100-
const address: string = server.address
101-
const version: string = server.version
100+
const address: string | undefined = server.address
101+
const version: string | undefined = server.version
102102

103103
const resultConsumedAfter1: Integer = sum1.resultConsumedAfter
104104
const resultAvailableAfter1: Integer = sum1.resultAvailableAfter

testkit-backend/src/main.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Backend {
6060

6161
this._writeBackendError('Unknown request: ' + name)
6262
console.log('Unknown request: ' + name)
63-
console.log(JSON.stringify(data))
63+
console.log(stringify(data))
6464
}
6565

6666
_writeResponse (name, data) {
@@ -69,7 +69,7 @@ class Backend {
6969
name: name,
7070
data: data
7171
}
72-
response = JSON.stringify(response)
72+
response = stringify(response)
7373
const lines = ['#response begin', response, '#response end']
7474
this._writer(lines)
7575
}
@@ -92,6 +92,12 @@ class Backend {
9292
}
9393
}
9494

95+
function stringify (val) {
96+
return JSON.stringify(val, (_, value) =>
97+
typeof value === 'bigint' ? `${value}n` : value
98+
)
99+
}
100+
95101
function server () {
96102
const server = net.createServer(conn => {
97103
const backend = new Backend({

testkit-backend/src/request-handlers.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export function NewDriver (context, data, { writeResponse }) {
2020
const driver = neo4j.driver(uri, authToken, {
2121
userAgent,
2222
resolver,
23-
useBigInt: true
23+
useBigInt: true,
24+
logging: neo4j.logging.console(process.env.LOG_LEVEL)
2425
})
2526
const id = context.addDriver(driver)
2627
writeResponse('Driver', { id })
@@ -123,7 +124,13 @@ export function ResultConsume (context, data, wire) {
123124
resultObserver
124125
.completitionPromise()
125126
.then(summary => {
126-
wire.writeResponse('Summary', null)
127+
wire.writeResponse('Summary', {
128+
...summary,
129+
serverInfo: {
130+
agent: summary.server.agent,
131+
protocolVersion: summary.server.protocolVersion.toFixed(1)
132+
}
133+
})
127134
})
128135
.catch(e => wire.writeError(e))
129136
}
@@ -192,7 +199,6 @@ export function TransactionCommit (context, data, wire) {
192199
console.log('got some err: ' + JSON.stringify(e))
193200
wire.writeError(e)
194201
})
195-
context.removeTx(id)
196202
}
197203

198204
export function TransactionRollback (context, data, wire) {

0 commit comments

Comments
 (0)