|
| 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 | +import BoltProtocolV5x2 from './bolt-protocol-v5x2' |
| 20 | + |
| 21 | +import transformersFactories from './bolt-protocol-v5x3.transformer' |
| 22 | +import Transformer from './transformer' |
| 23 | +import RequestMessage from './request-message' |
| 24 | +import { LoginObserver } from './stream-observers' |
| 25 | + |
| 26 | +import { internal } from 'neo4j-driver-core' |
| 27 | + |
| 28 | +const { |
| 29 | + constants: { BOLT_PROTOCOL_V5_3 } |
| 30 | +} = internal |
| 31 | + |
| 32 | +export default class BoltProtocol extends BoltProtocolV5x2 { |
| 33 | + get version () { |
| 34 | + return BOLT_PROTOCOL_V5_3 |
| 35 | + } |
| 36 | + |
| 37 | + get transformer () { |
| 38 | + if (this._transformer === undefined) { |
| 39 | + this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log))) |
| 40 | + } |
| 41 | + return this._transformer |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Initialize a connection with the server |
| 46 | + * |
| 47 | + * @param {Object} args The params |
| 48 | + * @param {string} args.userAgent The user agent |
| 49 | + * @param {any} args.authToken The auth token |
| 50 | + * @param {NotificationFilter} args.notificationFilter The notification filters. |
| 51 | + * @param {function(error)} args.onError On error callback |
| 52 | + * @param {function(onComplete)} args.onComplete On complete callback |
| 53 | + * @returns {LoginObserver} The Login observer |
| 54 | + */ |
| 55 | + initialize ({ userAgent, boltAgent, authToken, notificationFilter, onError, onComplete } = {}) { |
| 56 | + const state = {} |
| 57 | + const observer = new LoginObserver({ |
| 58 | + onError: error => this._onLoginError(error, onError), |
| 59 | + onCompleted: metadata => { |
| 60 | + state.metadata = metadata |
| 61 | + return this._onLoginCompleted(metadata) |
| 62 | + } |
| 63 | + }) |
| 64 | + |
| 65 | + this.write( |
| 66 | + RequestMessage.hello5x3(userAgent, boltAgent, notificationFilter, this._serversideRouting), |
| 67 | + observer, |
| 68 | + false |
| 69 | + ) |
| 70 | + |
| 71 | + return this.logon({ |
| 72 | + authToken, |
| 73 | + onComplete: metadata => onComplete({ ...metadata, ...state.metadata }), |
| 74 | + onError, |
| 75 | + flush: true |
| 76 | + }) |
| 77 | + } |
| 78 | +} |
0 commit comments