Skip to content

Commit 27998ad

Browse files
committed
fixed deno bolt agent
1 parent 0971ccb commit 27998ad

File tree

10 files changed

+69
-45
lines changed

10 files changed

+69
-45
lines changed

packages/bolt-connection/test/bolt/bolt-protocol-v5x2.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,39 @@ describe('#unit BoltProtocolV5x2', () => {
295295
expect(protocol.flushes).toEqual([false, true])
296296
})
297297

298+
it('should set userAgent to bolt agent when userAgent is null', () => {
299+
const recorder = new utils.MessageRecordingConnection()
300+
const protocol = new BoltProtocolV5x2(recorder, null, false)
301+
utils.spyProtocolWrite(protocol)
302+
303+
const clientName = 'js-driver/1.2.3'
304+
const authToken = { username: 'neo4j', password: 'secret' }
305+
306+
const observer = protocol.initialize({ userAgent: null, boltAgent: clientName, authToken })
307+
308+
protocol.verifyMessageCount(2)
309+
expect(protocol.messages[0]).toBeMessage(
310+
RequestMessage.hello5x1(clientName)
311+
)
312+
expect(protocol.messages[1]).toBeMessage(
313+
RequestMessage.logon(authToken)
314+
)
315+
316+
expect(protocol.observers.length).toBe(2)
317+
318+
// hello observer
319+
const helloObserver = protocol.observers[0]
320+
expect(helloObserver).toBeInstanceOf(LoginObserver)
321+
expect(helloObserver).not.toBe(observer)
322+
323+
// login observer
324+
const loginObserver = protocol.observers[1]
325+
expect(loginObserver).toBeInstanceOf(LoginObserver)
326+
expect(loginObserver).toBe(observer)
327+
328+
expect(protocol.flushes).toEqual([false, true])
329+
})
330+
298331
it.each(
299332
[true, false]
300333
)('should logon to the server [flush=%s]', (flush) => {

packages/core/src/internal/bolt-agent/browser/bolt-agent.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19+
/* eslint-disable */
1920
export function fromVersion (version: string): string {
20-
return `neo4j-javascript/${version} (browser)}`
21+
// @ts-ignore: browser code so must be skipped by ts
22+
const APP_VERSION = window.navigator.appVersion
23+
24+
//APP_VERSION looks like 5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
25+
const OS = APP_VERSION.split(" ")[0];
26+
27+
return `neo4j-javascript/${version} ${OS} `
2128
}
29+
/* eslint-enable */

packages/core/src/internal/bolt-agent/deno/bolt-agent.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19+
20+
/* eslint-disable */
1921
export function fromVersion (version: string): string {
20-
return `neo4j-javascript/${version} (browser)`
22+
const HOST_ARCH = Deno.build.arch
23+
const DENO_VERSION = `Deno/${Deno.version.deno}`
24+
const NODE_V8_VERSION = Deno.version.v8
25+
const OS_NAME_VERSION = `${Deno.build.os} ${Deno.osRelease}`
26+
27+
return `neo4j-javascript/${version} (${OS_NAME_VERSION}; ${HOST_ARCH}) ${DENO_VERSION} (v8 ${NODE_V8_VERSION})`
2128
}
29+
/* eslint-enable */

packages/core/src/internal/bolt-agent/node/bolt-agent.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,7 @@ export function fromVersion (version: string): string {
2222
const HOST_ARCH = process.config.variables.host_arch
2323
const NODE_VERSION = 'Node/' + process.versions.node
2424
const NODE_V8_VERSION = process.versions.v8
25+
const OS_NAME_VERSION = `${os.platform()} ${os.release()}`
2526

26-
const osName = mapOs(os.platform())
27-
28-
return `neo4j-javascript/${version} (${osName} ${os.release()}; ${HOST_ARCH}) ${NODE_VERSION} (v8 ${NODE_V8_VERSION})`
29-
}
30-
31-
export function mapOs (osType: string): string {
32-
let osName
33-
if (osType === 'darwin') {
34-
osName = 'MacOS'
35-
} else if (osType === 'win32') {
36-
osName = 'Windows'
37-
} else if (osType === 'linux') {
38-
osName = 'Linux'
39-
} else {
40-
osName = osType
41-
}
42-
43-
return osName
27+
return `neo4j-javascript/${version} (${OS_NAME_VERSION}; ${HOST_ARCH}) ${NODE_VERSION} (v8 ${NODE_V8_VERSION})`
4428
}

packages/core/tsconfig.build.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"extends": "./tsconfig.json",
33
"include": [
44
"src/**/*.ts",
5+
],
6+
"exclude": [
7+
"src/internal/bolt-agent/deno/*.ts"
58
]
69
}

packages/core/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
"include": [
1717
"src/**/*.ts",
1818
"test/**/*.ts"
19-
]
19+
],
2020
}

packages/neo4j-driver-deno/generate.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ async function copyAndTransform(inDir: string, outDir: string) {
132132
// Special fix for core/internal/bolt-agent/index.js
133133
// Replace the "node boltAgent" with the "deno boltAgent", since Deno supports different APIs
134134
if(inPath.endsWith("bolt-agent/index.ts")){
135-
console.log(inPath)
136-
console.log(contents)
137135
contents = contents.replace(
138136
`export * from './node/index.ts'`,
139137
`export * from './deno/index.ts'`,
@@ -143,8 +141,6 @@ async function copyAndTransform(inDir: string, outDir: string) {
143141
// Special fix for bolt-connection/channel/index.js and core/internal/bolt-agent/index.js
144142
// Replace the "node channel" with the "deno channel", since Deno supports different APIs
145143
if (inPath.endsWith("channel/index.js")) {
146-
console.log(inPath)
147-
console.log(contents)
148144
contents = contents.replace(
149145
`export * from './node/index.js'`,
150146
`export * from './deno/index.js'`,

packages/neo4j-driver-deno/lib/core/internal/bolt-agent/browser/bolt-agent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
* limitations under the License.
1818
*/
1919
export function fromVersion (version: string): string {
20+
window.navagator
21+
2022
return `neo4j-javascript/${version} (browser)}`
2123
}

packages/neo4j-driver-deno/lib/core/internal/bolt-agent/deno/bolt-agent.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19+
1920
export function fromVersion (version: string): string {
20-
return `neo4j-javascript/${version} (browser)`
21+
const HOST_ARCH = Deno.build.arch
22+
const DENO_VERSION = 'Deno/' + Deno.version.deno
23+
const NODE_V8_VERSION = Deno.version.v8
24+
const OS_NAME_VERSION = `${Deno.build.os} ${Deno.osRelease}`
25+
26+
return `neo4j-javascript/${version} (${OS_NAME_VERSION}; ${HOST_ARCH}) ${DENO_VERSION} (v8 ${NODE_V8_VERSION})`
2127
}

packages/neo4j-driver-deno/lib/core/internal/bolt-agent/node/bolt-agent.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,7 @@ export function fromVersion (version: string): string {
2222
const HOST_ARCH = process.config.variables.host_arch
2323
const NODE_VERSION = 'Node/' + process.versions.node
2424
const NODE_V8_VERSION = process.versions.v8
25+
const OS_NAME_VERSION = `${os.platform()} ${os.release()}`
2526

26-
const osName = mapOs(os.platform())
27-
28-
return `neo4j-javascript/${version} (${osName} ${os.release()}; ${HOST_ARCH}) ${NODE_VERSION} (v8 ${NODE_V8_VERSION})`
29-
}
30-
31-
export function mapOs (osType: string): string {
32-
let osName
33-
if (osType === 'darwin') {
34-
osName = 'MacOS'
35-
} else if (osType === 'win32') {
36-
osName = 'Windows'
37-
} else if (osType === 'linux') {
38-
osName = 'Linux'
39-
} else {
40-
osName = osType
41-
}
42-
43-
return osName
44-
}
27+
return `neo4j-javascript/${version} (${OS_NAME_VERSION}; ${HOST_ARCH}) ${NODE_VERSION} (v8 ${NODE_V8_VERSION})`
28+
}

0 commit comments

Comments
 (0)