Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce GqlStatusObject support as notifications to ResultSummary #1194

Merged
merged 43 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8d2ee88
Implement filtering GqlStatusObject in Bot layer
bigmontz May 16, 2024
a80c303
Sync deno
bigmontz May 16, 2024
28917a8
Add Bolt 5.5 to handshake
bigmontz May 16, 2024
6d3ed0f
Implement filtering in core and exposing it throug api
bigmontz May 17, 2024
24f6225
Fix docs
bigmontz May 17, 2024
951a6c8
Sync deno
bigmontz May 17, 2024
c00c24b
Extract Notification to their own file
bigmontz May 20, 2024
b1dc8d6
GqlStatusObject construction using native gql objects
bigmontz May 20, 2024
3fd4e0c
Sync deno
bigmontz May 20, 2024
2ee427e
Small fix
bigmontz May 20, 2024
4760c86
Polyfilling and exposing GqlStatusCode
bigmontz May 20, 2024
1db6c6e
Create gqlStatusObjects from statuses or notifications
bigmontz May 20, 2024
9923c00
Sync deno
bigmontz May 20, 2024
8ff2064
Polyfill notifications
bigmontz May 21, 2024
b18b345
Adjust descriptions and polifylled messages order
bigmontz May 21, 2024
e0e5608
Build notifications from metadata
bigmontz May 21, 2024
a342a84
Tests and fixes around stream status
bigmontz May 22, 2024
433eb46
Testkit support + bug fixing
bigmontz May 23, 2024
eec6885
sync deno
bigmontz May 23, 2024
e47831f
Ordering gqlStatus
bigmontz May 23, 2024
678b12e
sync deno
bigmontz May 23, 2024
6de5a0c
Add default values
bigmontz May 27, 2024
47ca007
Add test for default values
bigmontz May 28, 2024
4caeca6
Implement new defaults and nullability
bigmontz May 30, 2024
e43d31e
Update packages/core/src/driver.ts
bigmontz Jun 4, 2024
01b4020
Small fixes and sync deno
bigmontz Jun 4, 2024
6fcea24
Adjust diagnostic record naming to avoid clashes
bigmontz Jun 7, 2024
a14dfac
fix test
bigmontz Jun 10, 2024
3ef928d
Diagnostic record should only have null values when returned by the
bigmontz Jun 11, 2024
23ecd0e
sync deno
bigmontz Jun 11, 2024
bedf5bb
Apply suggestions from code review
bigmontz Jun 12, 2024
638a990
Update packages/core/test/notification.test.ts
bigmontz Jun 12, 2024
ada9fb2
address comments in the PR
bigmontz Jun 12, 2024
f9b117e
sync deno
bigmontz Jun 12, 2024
f7e4244
Ajust test
bigmontz Jun 12, 2024
4e15f2d
update gqlstatus docs
bigmontz Jun 12, 2024
fa1fe22
sync deno
bigmontz Jun 12, 2024
b5984b3
Adjust diagnostic record serialization
bigmontz Jun 13, 2024
7da3f78
Adjust status_description for warn and info
bigmontz Jun 13, 2024
3d34596
Better type support for DiagnosticRecord
bigmontz Jun 13, 2024
c880682
More unit tests
bigmontz Jun 13, 2024
ac12a3f
Apply suggestions from code review
bigmontz Jun 14, 2024
0dce222
Sync deno
bigmontz Jun 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions packages/bolt-connection/src/bolt/bolt-protocol-v5x5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/**
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import BoltProtocolV5x4 from './bolt-protocol-v5x4'

import transformersFactories from './bolt-protocol-v5x5.transformer'
import Transformer from './transformer'
import RequestMessage from './request-message'
import { LoginObserver, ResultStreamObserver } from './stream-observers'

import { internal } from 'neo4j-driver-core'

const {
constants: { BOLT_PROTOCOL_V5_5, FETCH_ALL }
} = internal

const DEFAULT_DIAGNOSTIC_RECORD = Object.freeze({
OPERATION: '',
OPERATION_CODE: '0',
CURRENT_SCHEMA: '/'
})

export default class BoltProtocol extends BoltProtocolV5x4 {
get version () {
return BOLT_PROTOCOL_V5_5
}

get transformer () {
if (this._transformer === undefined) {
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
}
return this._transformer
}

/**
* Initialize a connection with the server
*
* @param {Object} args The params
* @param {string} args.userAgent The user agent
* @param {any} args.authToken The auth token
* @param {NotificationFilter} args.notificationFilter The notification filters.
* @param {function(error)} args.onError On error callback
* @param {function(onComplete)} args.onComplete On complete callback
* @returns {LoginObserver} The Login observer
*/
initialize ({ userAgent, boltAgent, authToken, notificationFilter, onError, onComplete } = {}) {
const state = {}
const observer = new LoginObserver({
onError: error => this._onLoginError(error, onError),
onCompleted: metadata => {
state.metadata = metadata
return this._onLoginCompleted(metadata)
}
})

this.write(
RequestMessage.hello5x5(userAgent, boltAgent, notificationFilter, this._serversideRouting),
observer,
false
)

return this.logon({
authToken,
onComplete: metadata => onComplete({ ...metadata, ...state.metadata }),
onError,
flush: true
})
}

beginTransaction ({
bookmarks,
txConfig,
database,
mode,
impersonatedUser,
notificationFilter,
beforeError,
afterError,
beforeComplete,
afterComplete
} = {}) {
const observer = new ResultStreamObserver({
server: this._server,
beforeError,
afterError,
beforeComplete,
afterComplete
})
observer.prepareToHandleSingleResponse()

this.write(
RequestMessage.begin5x5({ bookmarks, txConfig, database, mode, impersonatedUser, notificationFilter }),
observer,
true
)

return observer
}

run (
query,
parameters,
{
bookmarks,
txConfig,
database,
mode,
impersonatedUser,
notificationFilter,
beforeKeys,
afterKeys,
beforeError,
afterError,
beforeComplete,
afterComplete,
flush = true,
reactive = false,
fetchSize = FETCH_ALL,
highRecordWatermark = Number.MAX_VALUE,
lowRecordWatermark = Number.MAX_VALUE
} = {}
) {
const observer = new ResultStreamObserver({
server: this._server,
reactive,
fetchSize,
moreFunction: this._requestMore.bind(this),
discardFunction: this._requestDiscard.bind(this),
beforeKeys,
afterKeys,
beforeError,
afterError,
beforeComplete,
afterComplete,
highRecordWatermark,
lowRecordWatermark,
enrichMetadata: BoltProtocol._enrichMetadata
})

const flushRun = reactive
this.write(
RequestMessage.runWithMetadata5x5(query, parameters, {
bookmarks,
txConfig,
database,
mode,
impersonatedUser,
notificationFilter
}),
observer,
flushRun && flush
)

if (!reactive) {
this.write(RequestMessage.pull({ n: fetchSize }), observer, flush)
}

return observer
}

/**
*
* @param {object} metadata
* @returns {object}
*/
static _enrichMetadata (metadata) {
if (Array.isArray(metadata.statuses)) {
metadata.statuses = metadata.statuses.map(status => ({
...status,
diagnostic_record: status.diagnostic_record !== null ? { ...DEFAULT_DIAGNOSTIC_RECORD, ...status.diagnostic_record } : null
bigmontz marked this conversation as resolved.
Show resolved Hide resolved
}))
}

return metadata
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [https://neo4j.com]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import v5x3 from './bolt-protocol-v5x3.transformer'

export default {
...v5x3
}
9 changes: 9 additions & 0 deletions packages/bolt-connection/src/bolt/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import BoltProtocolV5x1 from './bolt-protocol-v5x1'
import BoltProtocolV5x2 from './bolt-protocol-v5x2'
import BoltProtocolV5x3 from './bolt-protocol-v5x3'
import BoltProtocolV5x4 from './bolt-protocol-v5x4'
import BoltProtocolV5x5 from './bolt-protocol-v5x5'
// eslint-disable-next-line no-unused-vars
import { Chunker, Dechunker } from '../channel'
import ResponseHandler from './response-handler'
Expand Down Expand Up @@ -229,6 +230,14 @@ function createProtocol (
log,
onProtocolError,
serversideRouting)
case 5.5:
return new BoltProtocolV5x5(server,
chunker,
packingConfig,
createResponseHandler,
log,
onProtocolError,
serversideRouting)
default:
throw newError('Unknown Bolt protocol version: ' + version)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bolt-connection/src/bolt/handshake.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function parseNegotiatedResponse (buffer, log) {
*/
function newHandshakeBuffer () {
return createHandshakeMessage([
[version(5, 4), version(5, 0)],
[version(5, 5), version(5, 0)],
[version(4, 4), version(4, 2)],
version(4, 1),
version(3, 0)
Expand Down
Loading